Skip to content

Commit

Permalink
remove IPufferModule
Browse files Browse the repository at this point in the history
  • Loading branch information
bxmmm1 committed Dec 18, 2024
1 parent 4d10109 commit 2ed174d
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 324 deletions.
1 change: 0 additions & 1 deletion mainnet-contracts/.solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"compiler-version": ["error", ">=0.8.0 <0.9.0"],
"contract-name-camelcase": "off",
"const-name-snakecase": "off",
"custom-errors": "error",
"func-name-mixedcase": "off",
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 123],
Expand Down
5 changes: 2 additions & 3 deletions mainnet-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
"@openzeppelin/contracts-upgradeable": "5.0.1",
"l2-contracts": "*",
"murky": "https://github.com/dmfxyz/murky.git",
"openzeppelin-foundry-upgrades": "https://github.com/bxmmm1/openzeppelin-foundry-upgrades.git#patch-1",
"rave": "https://github.com/PufferFinance/rave.git#57ce268",
"solidity-stringutils": "https://github.com/Arachnid/solidity-stringutils"
},
"devDependencies": {
"@crytic/properties": "https://github.com/crytic/properties#f1ff61b",
"@prb/test": "0.6.4",
"erc4626-tests": "https://github.com/a16z/erc4626-tests#8b1d7c2",
"forge-std": "github:foundry-rs/forge-std#v1.9.2",
"forge-std": "github:foundry-rs/forge-std#v1.9.4",
"solarray": "github:evmcheb/solarray#a547630",
"solhint": "^5.0.1"
"solhint": "^5.0.3"
},
"homepage": "https://puffer.fi",
"keywords": [
Expand Down
1 change: 0 additions & 1 deletion mainnet-contracts/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ rave-test/=node_modules/rave/test/
murky/=node_modules/murky/src/
l2-contracts/=node_modules/l2-contracts/
mainnet-contracts/=node_modules/mainnet-contracts/
openzeppelin-foundry-upgrades/=node_modules/openzeppelin-foundry-upgrades/src/
solidity-stringutils/=node_modules/solidity-stringutils
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ contract GenerateAccessManagerCalldata2 is Script {
function run(address moduleManager) public pure returns (bytes memory) {
bytes[] memory calldatas = new bytes[](1);

bytes4[] memory daoSelectors = new bytes4[](3);
bytes4[] memory daoSelectors = new bytes4[](2);
daoSelectors[0] = PufferModuleManager.callSetClaimerFor.selector;
daoSelectors[1] = PufferModuleManager.callStartCheckpoint.selector;
daoSelectors[2] = PufferModuleManager.callSetProofSubmitter.selector;
daoSelectors[1] = PufferModuleManager.callSetProofSubmitter.selector;

calldatas[0] = abi.encodeWithSelector(
AccessManager.setTargetFunctionRole.selector, moduleManager, daoSelectors, ROLE_ID_DAO
Expand Down
7 changes: 0 additions & 7 deletions mainnet-contracts/src/L1RewardManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,21 @@ contract L1RewardManager is
{
/**
* @notice The XPUFETH token contract on Ethereum Mainnet
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
IERC20 public immutable XPUFETH;
/**
* @notice The PufferVault contract on Ethereum Mainnet
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
PufferVaultV5 public immutable PUFFER_VAULT;
/**
* @notice The XERC20Lockbox contract on Ethereum Mainnet
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
IXERC20Lockbox public immutable LOCKBOX;
/**
* @notice The Rewards Manager contract on L2
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
address public immutable L2_REWARDS_MANAGER;

/**
* @custom:oz-upgrades-unsafe-allow constructor
*/
constructor(address xPufETH, address lockbox, address pufETH, address l2RewardsManager) {
XPUFETH = IERC20(xPufETH);
LOCKBOX = IXERC20Lockbox(lockbox);
Expand Down
3 changes: 0 additions & 3 deletions mainnet-contracts/src/L1RewardManagerUnsafe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ contract L1RewardManagerUnsafe is
*/
address public immutable L2_REWARDS_MANAGER;

/**
* @custom:oz-upgrades-unsafe-allow constructor
*/
constructor(address xPufETH, address lockbox, address pufETH, address l2RewardsManager) {
XPUFETH = IERC20(xPufETH);
LOCKBOX = IXERC20Lockbox(lockbox);
Expand Down
78 changes: 20 additions & 58 deletions mainnet-contracts/src/PufferModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { IStrategy } from "../src/interface/Eigenlayer-Slashing/IStrategy.sol";
import { IPufferProtocol } from "./interface/IPufferProtocol.sol";
import { IEigenPod } from "../src/interface/Eigenlayer-Slashing/IEigenPod.sol";
import { PufferModuleManager } from "./PufferModuleManager.sol";
import { IPufferModule } from "./interface/IPufferModule.sol";
import { Unauthorized } from "./Errors.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
Expand All @@ -25,54 +24,25 @@ import { IRewardsCoordinator } from "src/interface/Eigenlayer-Slashing/IRewardsC
* @notice PufferModule
* @custom:security-contact security@puffer.fi
*/
contract PufferModule is IPufferModule, Initializable, AccessManagedUpgradeable {
contract PufferModule is Initializable, AccessManagedUpgradeable {
using Address for address;
using Address for address payable;

/**
* @dev Represents the Beacon Chain strategy in EigenLayer
*/
address internal constant _BEACON_CHAIN_STRATEGY = 0xbeaC0eeEeeeeEEeEeEEEEeeEEeEeeeEeeEEBEaC0;

/**
* @dev Upgradeable contract from EigenLayer
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
IEigenPodManager public immutable EIGEN_POD_MANAGER;

/**
* @dev Upgradeable contract from EigenLayer
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
IRewardsCoordinator public immutable EIGEN_REWARDS_COORDINATOR;

/**
* @dev Upgradeable contract from EigenLayer
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
IDelegationManager public immutable EIGEN_DELEGATION_MANAGER;

/**
* @dev Upgradeable PufferProtocol
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
IPufferProtocol public immutable PUFFER_PROTOCOL;

PufferModuleManager public immutable PUFFER_MODULE_MANAGER;
/**
* @dev Upgradeable Puffer Module Manager
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
* @dev Represents the Beacon Chain strategy in EigenLayer
*/
PufferModuleManager public immutable PUFFER_MODULE_MANAGER;

address internal constant _BEACON_CHAIN_STRATEGY = 0xbeaC0eeEeeeeEEeEeEEEEeeEEeEeeeEeeEEBEaC0;
/**
* keccak256(abi.encode(uint256(keccak256("PufferModule.storage")) - 1)) & ~bytes32(uint256(0xff))
*/
bytes32 private constant _PUFFER_MODULE_BASE_STORAGE =
0x501caad7d5b9c1542c99d193b659cbf5c57571609bcfc93d65f1e159821d6200;

/**
* @custom:oz-upgrades-unsafe-allow constructor
*/
constructor(
IPufferProtocol protocol,
address eigenPodManager,
Expand Down Expand Up @@ -127,7 +97,7 @@ contract PufferModule is IPufferModule, Initializable, AccessManagedUpgradeable
receive() external payable { }

/**
* @inheritdoc IPufferModule
* @notice Starts the validator
*/
function callStake(bytes calldata pubKey, bytes calldata signature, bytes32 depositDataRoot)
external
Expand All @@ -139,7 +109,7 @@ contract PufferModule is IPufferModule, Initializable, AccessManagedUpgradeable
}

/**
* @inheritdoc IPufferModule
* @notice Sets the proof submitter on the EigenPod
*/
function setProofSubmitter(address proofSubmitter) external onlyPufferModuleManager {
ModuleStorage storage $ = _getPufferModuleStorage();
Expand All @@ -148,8 +118,7 @@ contract PufferModule is IPufferModule, Initializable, AccessManagedUpgradeable
}

/**
* @inheritdoc IPufferModule
* @dev Restricted to PufferModuleManager
* @notice Queues the withdrawal from EigenLayer for the Beacon Chain strategy
*/
function queueWithdrawals(uint256 shareAmount)
external
Expand All @@ -176,7 +145,7 @@ contract PufferModule is IPufferModule, Initializable, AccessManagedUpgradeable
}

/**
* @inheritdoc IPufferModule
* @notice Completes the queued withdrawals
*/
function completeQueuedWithdrawals(
IDelegationManagerTypes.Withdrawal[] calldata withdrawals,
Expand All @@ -191,16 +160,9 @@ contract PufferModule is IPufferModule, Initializable, AccessManagedUpgradeable
}

/**
* @inheritdoc IPufferModule
* @dev Restricted to PufferModuleManager
*/
function startCheckpoint() external virtual onlyPufferModuleManager {
ModuleStorage storage $ = _getPufferModuleStorage();
$.eigenPod.startCheckpoint({ revertIfNoBalance: true });
}

/**
* @dev Restricted to PufferProtocol
* @notice the `to` with custom `value` and `data`
* @return success the success of the call
* @return returnData the return data of the call
*/
function call(address to, uint256 amount, bytes calldata data)
external
Expand All @@ -213,8 +175,10 @@ contract PufferModule is IPufferModule, Initializable, AccessManagedUpgradeable
}

/**
* @inheritdoc IPufferModule
* @dev Restricted to PufferModuleManager
* @notice Calls the delegateTo function on the EigenLayer delegation manager
* @param operator is the address of the restaking operator
* @param approverSignatureAndExpiry the signature of the delegation approver
* @param approverSalt salt for the signature
*/
function callDelegateTo(
address operator,
Expand All @@ -225,23 +189,21 @@ contract PufferModule is IPufferModule, Initializable, AccessManagedUpgradeable
}

/**
* @inheritdoc IPufferModule
* @dev Restricted to PufferModuleManager
* @notice Calls the undelegate function on the EigenLayer delegation manager
*/
function callUndelegate() external virtual onlyPufferModuleManager returns (bytes32[] memory withdrawalRoot) {
return EIGEN_DELEGATION_MANAGER.undelegate(address(this));
}

/**
* @inheritdoc IPufferModule
* @dev Restricted to PufferModuleManager
* @notice Sets the rewards claimer to `claimer` for the PufferModule
*/
function callSetClaimerFor(address claimer) external virtual onlyPufferModuleManager {
EIGEN_REWARDS_COORDINATOR.setClaimerFor(claimer);
}

/**
* @inheritdoc IPufferModule
* @notice Returns the Withdrawal credentials for that module
*/
function getWithdrawalCredentials() public view returns (bytes memory) {
// Withdrawal credentials for EigenLayer modules are EigenPods
Expand All @@ -250,15 +212,15 @@ contract PufferModule is IPufferModule, Initializable, AccessManagedUpgradeable
}

/**
* @inheritdoc IPufferModule
* @notice Returns the EigenPod address owned by the module
*/
function getEigenPod() external view returns (address) {
ModuleStorage storage $ = _getPufferModuleStorage();
return address($.eigenPod);
}

/**
* @inheritdoc IPufferModule
* @notice Returns the module name
*/
// solhint-disable-next-line func-name-mixedcase
function NAME() external view returns (bytes32) {
Expand Down
50 changes: 21 additions & 29 deletions mainnet-contracts/src/PufferModuleManager.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;

import { IPufferModule } from "./interface/IPufferModule.sol";
import { IPufferProtocol } from "./interface/IPufferProtocol.sol";
import { Unauthorized, InvalidAmount } from "./Errors.sol";
import { IPufferProtocol } from "./interface/IPufferProtocol.sol";
Expand All @@ -19,6 +18,7 @@ import { ISignatureUtils } from "../src/interface/Eigenlayer-Slashing/ISignature
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { RestakingOperator } from "./RestakingOperator.sol";
import { IAllocationManager } from "../src/interface/Eigenlayer-Slashing/IAllocationManager.sol";
import { PufferModule } from "./PufferModule.sol";

/**
* @title PufferModuleManager
Expand Down Expand Up @@ -67,7 +67,7 @@ contract PufferModuleManager is IPufferModuleManager, AccessManagedUpgradeable,
) external virtual restricted {
address moduleAddress = IPufferProtocol(PUFFER_PROTOCOL).getModuleAddress(moduleName);

IPufferModule(moduleAddress).completeQueuedWithdrawals({
PufferModule(payable(moduleAddress)).completeQueuedWithdrawals({
withdrawals: withdrawals,
tokens: tokens,
receiveAsTokens: receiveAsTokens
Expand All @@ -89,20 +89,22 @@ contract PufferModuleManager is IPufferModuleManager, AccessManagedUpgradeable,
* @dev Restricted to the PufferProtocol
* @param moduleName The name of the module
*/
function createNewPufferModule(bytes32 moduleName) external virtual onlyPufferProtocol returns (IPufferModule) {
function createNewPufferModule(bytes32 moduleName) external virtual onlyPufferProtocol returns (PufferModule) {
if (moduleName == bytes32("NO_VALIDATORS")) {
revert ForbiddenModuleName();
}
// This called from the PufferProtocol and the event is emitted there
return IPufferModule(
Create2.deploy({
amount: 0,
salt: moduleName,
bytecode: abi.encodePacked(
type(BeaconProxy).creationCode,
abi.encode(PUFFER_MODULE_BEACON, abi.encodeCall(PufferModule.initialize, (moduleName, authority())))
)
})
return PufferModule(
payable(
Create2.deploy({
amount: 0,
salt: moduleName,
bytecode: abi.encodePacked(
type(BeaconProxy).creationCode,
abi.encode(PUFFER_MODULE_BEACON, abi.encodeCall(PufferModule.initialize, (moduleName, authority())))
)
})
)
);
}

Expand All @@ -119,7 +121,7 @@ contract PufferModuleManager is IPufferModuleManager, AccessManagedUpgradeable,

for (uint256 i = 0; i < modules.length; ++i) {
//solhint-disable-next-line avoid-low-level-calls
(bool success,) = IPufferModule(modules[i]).call(address(this), rewardsAmounts[i], "");
(bool success,) = PufferModule(payable(modules[i])).call(address(this), rewardsAmounts[i], "");
if (!success) {
revert InvalidAmount();
}
Expand All @@ -134,16 +136,16 @@ contract PufferModuleManager is IPufferModuleManager, AccessManagedUpgradeable,
*/
function callQueueWithdrawals(bytes32 moduleName, uint256 sharesAmount) external virtual restricted {
address moduleAddress = IPufferProtocol(PUFFER_PROTOCOL).getModuleAddress(moduleName);
bytes32[] memory withdrawalRoots = IPufferModule(moduleAddress).queueWithdrawals(sharesAmount);
bytes32[] memory withdrawalRoots = PufferModule(payable(moduleAddress)).queueWithdrawals(sharesAmount);
emit WithdrawalsQueued(moduleName, sharesAmount, withdrawalRoots[0]);
}

/**
* @dev Restricted to the DAO
*/
function callSetClaimerFor(address moduleOrReOp, address claimer) external virtual restricted {
// We can cast `moduleOrReOp` to IPufferModule/RestakingOperator, uses the same function signature.
IPufferModule(moduleOrReOp).callSetClaimerFor(claimer);
// We can cast `moduleOrReOp` to PufferModule/RestakingOperator, uses the same function signature.
PufferModule(payable(moduleOrReOp)).callSetClaimerFor(claimer);
emit ClaimerSet({ rewardsReceiver: moduleOrReOp, claimer: claimer });
}

Expand All @@ -152,7 +154,7 @@ contract PufferModuleManager is IPufferModuleManager, AccessManagedUpgradeable,
*/
function callSetProofSubmitter(bytes32 moduleName, address proofSubmitter) external virtual restricted {
address moduleAddress = IPufferProtocol(PUFFER_PROTOCOL).getModuleAddress(moduleName);
IPufferModule(moduleAddress).setProofSubmitter(proofSubmitter);
PufferModule(payable(moduleAddress)).setProofSubmitter(proofSubmitter);
emit ProofSubmitterSet(moduleName, proofSubmitter);
}

Expand Down Expand Up @@ -219,7 +221,7 @@ contract PufferModuleManager is IPufferModuleManager, AccessManagedUpgradeable,
) external virtual restricted {
address moduleAddress = IPufferProtocol(PUFFER_PROTOCOL).getModuleAddress(moduleName);

IPufferModule(moduleAddress).callDelegateTo(operator, approverSignatureAndExpiry, approverSalt);
PufferModule(payable(moduleAddress)).callDelegateTo(operator, approverSignatureAndExpiry, approverSalt);

emit PufferModuleDelegated(moduleName, operator);
}
Expand All @@ -230,7 +232,7 @@ contract PufferModuleManager is IPufferModuleManager, AccessManagedUpgradeable,
function callUndelegate(bytes32 moduleName) external virtual restricted returns (bytes32[] memory withdrawalRoot) {
address moduleAddress = IPufferProtocol(PUFFER_PROTOCOL).getModuleAddress(moduleName);

withdrawalRoot = IPufferModule(moduleAddress).callUndelegate();
withdrawalRoot = PufferModule(payable(moduleAddress)).callUndelegate();

emit PufferModuleUndelegated(moduleName);
}
Expand Down Expand Up @@ -264,16 +266,6 @@ contract PufferModuleManager is IPufferModuleManager, AccessManagedUpgradeable,
emit CustomCallSucceeded(address(restakingOperator), target, customCalldata, response);
}

/**
* @dev Restricted to the DAO
*/
function callStartCheckpoint(address[] calldata moduleAddresses) external virtual restricted {
for (uint256 i = 0; i < moduleAddresses.length; ++i) {
// reverts if supplied with a duplicate module address
IPufferModule(moduleAddresses[i]).startCheckpoint();
}
}

/**
* @dev Restricted to the DAO
*/
Expand Down
Loading

0 comments on commit 2ed174d

Please sign in to comment.