Skip to content

Commit

Permalink
feat: legacy withdrawals and cleanup for DelegationManager (#738)
Browse files Browse the repository at this point in the history
* feat: legacy withdrawals support

* feat: remove thirdpartytransfersforbidden

* chore: fmt core and cleanup
  • Loading branch information
8sunyuan committed Sep 12, 2024
1 parent 4cb7cbc commit 5962a7b
Show file tree
Hide file tree
Showing 25 changed files with 176 additions and 575 deletions.
3 changes: 1 addition & 2 deletions script/deploy/devnet/operatorSets/DeployStrategies.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ contract DeployStrategies is ExistingDeploymentParser {
uint256 batchSize = 100;

IStrategy[] memory strategies = new IStrategy[](batchSize * batches);
bool[] memory falses = new bool[](batchSize);

for (uint256 i = 0; i < batches; i++) {
IStrategy[] memory strategiesJustDeployed = strategyDeployer.createManyStrategies(batchSize);
for (uint256 j = 0; j < batchSize; j++) {
strategies[i * batchSize + j] = strategiesJustDeployed[j];
}
strategyManager.addStrategiesToDepositWhitelist(strategiesJustDeployed, falses);
strategyManager.addStrategiesToDepositWhitelist(strategiesJustDeployed);
}

vm.stopBroadcast();
Expand Down
4 changes: 1 addition & 3 deletions script/deploy/holesky/Eigen_Strategy_Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ contract Eigen_Strategy_Deploy is ExistingDeploymentParser {
function _verifyDeployment() internal {
IStrategy[] memory strategies = new IStrategy[](1);
strategies[0] = eigenStrategy;
bool[] memory thirdPartyTransfersForbiddenValues = new bool[](1);
thirdPartyTransfersForbiddenValues[0] = true;

vm.prank(executorMultisig);
strategyManager.addStrategiesToDepositWhitelist(strategies, thirdPartyTransfersForbiddenValues);
strategyManager.addStrategiesToDepositWhitelist(strategies);

vm.startPrank(msg.sender);
EIGEN.approve(address(strategyManager), type(uint256).max);
Expand Down
4 changes: 1 addition & 3 deletions script/deploy/holesky/M2_Deploy_From_Scratch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ contract M2_Deploy_Holesky_From_Scratch is ExistingDeploymentParser {
uint256 numStrategiesToDeploy = strategiesToDeploy.length;
// whitelist params
IStrategy[] memory strategiesToWhitelist = new IStrategy[](numStrategiesToDeploy);
bool[] memory thirdPartyTransfersForbiddenValues = new bool[](numStrategiesToDeploy);

for (uint256 i = 0; i < numStrategiesToDeploy; i++) {
StrategyUnderlyingTokenConfig memory strategyConfig = strategiesToDeploy[i];
Expand All @@ -193,13 +192,12 @@ contract M2_Deploy_Holesky_From_Scratch is ExistingDeploymentParser {
);

strategiesToWhitelist[i] = strategy;
thirdPartyTransfersForbiddenValues[i] = false;

deployedStrategyArray.push(strategy);
}

// Add strategies to whitelist and set whitelister to STRATEGY_MANAGER_WHITELISTER
strategyManager.addStrategiesToDepositWhitelist(strategiesToWhitelist, thirdPartyTransfersForbiddenValues);
strategyManager.addStrategiesToDepositWhitelist(strategiesToWhitelist);
strategyManager.setStrategyWhitelister(STRATEGY_MANAGER_WHITELISTER);

// Transfer ownership
Expand Down
9 changes: 1 addition & 8 deletions script/utils/ExistingDeploymentParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,7 @@ contract ExistingDeploymentParser is Script, Test {
delegationManager.initialize(
address(0),
eigenLayerPauserReg,
0,
0, // minWithdrawalDelayBLocks
initializeStrategiesToSetDelayBlocks,
initializeWithdrawalDelayBlocks
0
);
// StrategyManager
vm.expectRevert(bytes("Initializable: contract is already initialized"));
Expand Down Expand Up @@ -573,10 +570,6 @@ contract ExistingDeploymentParser is Script, Test {
delegationManager.paused() == DELEGATION_MANAGER_INIT_PAUSED_STATUS,
"delegationManager: init paused status set incorrectly"
);
require(
delegationManager.minWithdrawalDelayBlocks() == DELEGATION_MANAGER_MIN_WITHDRAWAL_DELAY_BLOCKS,
"delegationManager: minWithdrawalDelayBlocks not set correctly"
);
// StrategyManager
require(
strategyManager.pauserRegistry() == eigenLayerPauserReg,
Expand Down
44 changes: 14 additions & 30 deletions src/contracts/core/AVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ contract AVSDirectory is
* @dev Initializes the immutable addresses of the strategy mananger, delegationManager, slasher,
* and eigenpodManager contracts
*/
constructor(
IDelegationManager _delegation
) AVSDirectoryStorage(_delegation) {
constructor(IDelegationManager _delegation) AVSDirectoryStorage(_delegation) {
_disableInitializers();
ORIGINAL_CHAIN_ID = block.chainid;
}
Expand Down Expand Up @@ -72,9 +70,7 @@ contract AVSDirectory is
* @dev msg.sender must be the AVS.
* @dev The AVS may create operator sets before it becomes an operator set AVS.
*/
function createOperatorSets(
uint32[] calldata operatorSetIds
) external {
function createOperatorSets(uint32[] calldata operatorSetIds) external {
for (uint256 i = 0; i < operatorSetIds.length; ++i) {
require(!isOperatorSet[msg.sender][operatorSetIds[i]], InvalidOperatorSet());
isOperatorSet[msg.sender][operatorSetIds[i]] = true;
Expand Down Expand Up @@ -238,9 +234,7 @@ contract AVSDirectory is
*
* @dev Note that the `metadataURI` is *never stored* and is only emitted in the `AVSMetadataURIUpdated` event.
*/
function updateAVSMetadataURI(
string calldata metadataURI
) external override {
function updateAVSMetadataURI(string calldata metadataURI) external override {
emit AVSMetadataURIUpdated(msg.sender, metadataURI);
}

Expand All @@ -249,9 +243,7 @@ contract AVSDirectory is
*
* @param salt A unique and single use value associated with the approver signature.
*/
function cancelSalt(
bytes32 salt
) external override {
function cancelSalt(bytes32 salt) external override {
// Mutate `operatorSaltIsSpent` to `true` to prevent future spending.
operatorSaltIsSpent[msg.sender][salt] = true;
}
Expand Down Expand Up @@ -322,9 +314,11 @@ contract AVSDirectory is
*
* @dev Only used by legacy M2 AVSs that have not integrated with operator sets.
*/
function deregisterOperatorFromAVS(
address operator
) external override onlyWhenNotPaused(PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS) {
function deregisterOperatorFromAVS(address operator)
external
override
onlyWhenNotPaused(PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS)
{
// Assert that operator is registered for the AVS.
require(avsOperatorStatus[msg.sender][operator] == OperatorAVSRegistrationStatus.REGISTERED, InvalidOperator());
// Assert that the AVS is not an operator set AVS.
Expand Down Expand Up @@ -461,19 +455,15 @@ contract AVSDirectory is
* @notice Returns the number of operators registered to an operatorSet.
* @param operatorSet The operatorSet to get the member count for
*/
function getNumOperatorsInOperatorSet(
OperatorSet memory operatorSet
) external view returns (uint256) {
function getNumOperatorsInOperatorSet(OperatorSet memory operatorSet) external view returns (uint256) {
return _operatorSetMembers[_encodeOperatorSet(operatorSet)].length();
}

/**
* @notice Returns the total number of operator sets an operator is registered to.
* @param operator The operator address to query.
*/
function inTotalOperatorSets(
address operator
) external view returns (uint256) {
function inTotalOperatorSets(address operator) external view returns (uint256) {
return _operatorSetsMemberOf[operator].length();
}

Expand Down Expand Up @@ -558,26 +548,20 @@ contract AVSDirectory is
}

/// @notice Returns an EIP-712 encoded hash struct.
function _calculateDigestHash(
bytes32 structHash
) internal view returns (bytes32) {
function _calculateDigestHash(bytes32 structHash) internal view returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", _calculateDomainSeparator(), structHash));
}

/// @dev Returns an `OperatorSet` encoded into a 32-byte value.
/// @param operatorSet The `OperatorSet` to encode.
function _encodeOperatorSet(
OperatorSet memory operatorSet
) internal pure returns (bytes32) {
function _encodeOperatorSet(OperatorSet memory operatorSet) internal pure returns (bytes32) {
return bytes32(abi.encodePacked(operatorSet.avs, uint96(operatorSet.operatorSetId)));
}

/// @dev Returns an `OperatorSet` decoded from an encoded 32-byte value.
/// @param encoded The encoded `OperatorSet` to decode.
/// @dev Assumes `encoded` is encoded via `_encodeOperatorSet(operatorSet)`.
function _decodeOperatorSet(
bytes32 encoded
) internal pure returns (OperatorSet memory) {
function _decodeOperatorSet(bytes32 encoded) internal pure returns (OperatorSet memory) {
return OperatorSet({
avs: address(uint160(uint256(encoded) >> 96)),
operatorSetId: uint32(uint256(encoded) & type(uint96).max)
Expand Down
4 changes: 1 addition & 3 deletions src/contracts/core/AVSDirectoryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ abstract contract AVSDirectoryStorage is IAVSDirectory {
/// @notice Mapping: operator => avs => operatorSetId => operator registration status
mapping(address => mapping(address => mapping(uint32 => OperatorSetRegistrationStatus))) public operatorSetStatus;

constructor(
IDelegationManager _delegation
) {
constructor(IDelegationManager _delegation) {
delegation = _delegation;
}

Expand Down
16 changes: 4 additions & 12 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ contract AllocationManager is
*
* @param salt A unique and single use value associated with the approver signature.
*/
function cancelSalt(
bytes32 salt
) external override {
function cancelSalt(bytes32 salt) external override {
// Mutate `operatorSaltIsSpent` to `true` to prevent future spending.
operatorSaltIsSpent[msg.sender][salt] = true;
}
Expand Down Expand Up @@ -700,26 +698,20 @@ contract AllocationManager is
}

/// @notice Returns an EIP-712 encoded hash struct.
function _calculateDigestHash(
bytes32 structHash
) internal view returns (bytes32) {
function _calculateDigestHash(bytes32 structHash) internal view returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", _calculateDomainSeparator(), structHash));
}

/// @dev Returns an `OperatorSet` encoded into a 32-byte value.
/// @param operatorSet The `OperatorSet` to encode.
function _encodeOperatorSet(
OperatorSet memory operatorSet
) internal pure returns (bytes32) {
function _encodeOperatorSet(OperatorSet memory operatorSet) internal pure returns (bytes32) {
return bytes32(abi.encodePacked(operatorSet.avs, uint96(operatorSet.operatorSetId)));
}

/// @dev Returns an `OperatorSet` decoded from an encoded 32-byte value.
/// @param encoded The encoded `OperatorSet` to decode.
/// @dev Assumes `encoded` is encoded via `_encodeOperatorSet(operatorSet)`.
function _decodeOperatorSet(
bytes32 encoded
) internal pure returns (OperatorSet memory) {
function _decodeOperatorSet(bytes32 encoded) internal pure returns (OperatorSet memory) {
return OperatorSet({
avs: address(uint160(uint256(encoded) >> 96)),
operatorSetId: uint32(uint256(encoded) & type(uint96).max)
Expand Down
Loading

0 comments on commit 5962a7b

Please sign in to comment.