Skip to content

Commit

Permalink
refactor: move constants + immutables to storage contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
0xClandestine committed Sep 30, 2024
1 parent 643bbcf commit 90c1f7e
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 257 deletions.
46 changes: 1 addition & 45 deletions src/contracts/core/AVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol

import "../permissions/Pausable.sol";
import "../libraries/EIP1271SignatureUtils.sol";
import "../interfaces/IDelegationManager.sol";
import "./AVSDirectoryStorage.sol";

contract AVSDirectory is
Expand All @@ -20,47 +19,6 @@ contract AVSDirectory is
using EnumerableSet for EnumerableSet.Bytes32Set;
using EnumerableSet for EnumerableSet.AddressSet;

// Constants

/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

/// @notice The EIP-712 typehash for the `Registration` struct used by the contract
bytes32 public constant OPERATOR_AVS_REGISTRATION_TYPEHASH =
keccak256("OperatorAVSRegistration(address operator,address avs,bytes32 salt,uint256 expiry)");

/// @notice The EIP-712 typehash for the `OperatorSetRegistration` struct used by the contract
bytes32 public constant OPERATOR_SET_REGISTRATION_TYPEHASH =
keccak256("OperatorSetRegistration(address avs,uint32[] operatorSetIds,bytes32 salt,uint256 expiry)");

/// @notice The EIP-712 typehash for the `OperatorSetMembership` struct used by the contract
bytes32 public constant OPERATOR_SET_FORCE_DEREGISTRATION_TYPEHASH =
keccak256("OperatorSetForceDeregistration(address avs,uint32[] operatorSetIds,bytes32 salt,uint256 expiry)");

/// @notice The EIP-712 typehash for the `MagnitudeAdjustments` struct used by the contract
bytes32 public constant MAGNITUDE_ADJUSTMENT_TYPEHASH = keccak256(
"MagnitudeAdjustments(address operator,MagnitudeAdjustment(address strategy, OperatorSet(address avs, uint32 operatorSetId)[], uint64[] magnitudeDiffs)[],bytes32 salt,uint256 expiry)"
);

/// @dev Index for flag that pauses operator register/deregister to avs when set.
uint8 internal constant PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS = 0;

/// @dev Index for flag that pauses operator register/deregister to operator sets when set.
uint8 internal constant PAUSED_OPERATOR_SET_REGISTRATION_AND_DEREGISTRATION = 1;

// Immutables

/// @notice The DelegationManager contract for EigenLayer
IDelegationManager public immutable delegation;

/// @notice Delay before deallocations are completable and can be added back into freeMagnitude
/// In this window, deallocations still remain slashable by the operatorSet they were allocated to.
uint32 public immutable DEALLOCATION_DELAY;

/// @dev Returns the chain ID from the time the contract was deployed.
uint256 internal immutable ORIGINAL_CHAIN_ID;

/**
*
* INITIALIZING FUNCTIONS
Expand All @@ -74,10 +32,8 @@ contract AVSDirectory is
constructor(
IDelegationManager _delegation,
uint32 _DEALLOCATION_DELAY
) {
) AVSDirectoryStorage(_delegation, _DEALLOCATION_DELAY) {
_disableInitializers();
DEALLOCATION_DELAY = _DEALLOCATION_DELAY;
ORIGINAL_CHAIN_ID = block.chainid;
}

/**
Expand Down
55 changes: 55 additions & 0 deletions src/contracts/core/AVSDirectoryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,55 @@ pragma solidity ^0.8.27;
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import "../interfaces/IAVSDirectory.sol";
import "../interfaces/IDelegationManager.sol";

abstract contract AVSDirectoryStorage is IAVSDirectory {
using EnumerableSet for EnumerableSet.Bytes32Set;
using EnumerableSet for EnumerableSet.AddressSet;

// Constants

/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

/// @notice The EIP-712 typehash for the `Registration` struct used by the contract
bytes32 public constant OPERATOR_AVS_REGISTRATION_TYPEHASH =
keccak256("OperatorAVSRegistration(address operator,address avs,bytes32 salt,uint256 expiry)");

/// @notice The EIP-712 typehash for the `OperatorSetRegistration` struct used by the contract
bytes32 public constant OPERATOR_SET_REGISTRATION_TYPEHASH =
keccak256("OperatorSetRegistration(address avs,uint32[] operatorSetIds,bytes32 salt,uint256 expiry)");

/// @notice The EIP-712 typehash for the `OperatorSetMembership` struct used by the contract
bytes32 public constant OPERATOR_SET_FORCE_DEREGISTRATION_TYPEHASH =
keccak256("OperatorSetForceDeregistration(address avs,uint32[] operatorSetIds,bytes32 salt,uint256 expiry)");

/// @notice The EIP-712 typehash for the `MagnitudeAdjustments` struct used by the contract
bytes32 public constant MAGNITUDE_ADJUSTMENT_TYPEHASH = keccak256(
"MagnitudeAdjustments(address operator,MagnitudeAdjustment(address strategy, OperatorSet(address avs, uint32 operatorSetId)[], uint64[] magnitudeDiffs)[],bytes32 salt,uint256 expiry)"
);

/// @dev Index for flag that pauses operator register/deregister to avs when set.
uint8 internal constant PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS = 0;

/// @dev Index for flag that pauses operator register/deregister to operator sets when set.
uint8 internal constant PAUSED_OPERATOR_SET_REGISTRATION_AND_DEREGISTRATION = 1;

// Immutables

/// @notice The DelegationManager contract for EigenLayer
IDelegationManager public immutable delegation;

/// @notice Delay before deallocations are completable and can be added back into freeMagnitude
/// In this window, deallocations still remain slashable by the operatorSet they were allocated to.
uint32 public immutable DEALLOCATION_DELAY;

/// @dev Returns the chain ID from the time the contract was deployed.
uint256 internal immutable ORIGINAL_CHAIN_ID;

// Mutatables

/**
* @notice Original EIP-712 Domain separator for this contract.
* @dev The domain separator may change in the event of a fork that modifies the ChainID.
Expand Down Expand Up @@ -40,6 +84,17 @@ abstract contract AVSDirectoryStorage is IAVSDirectory {
/// @notice Mapping: operator => avs => operatorSetId => operator registration status
mapping(address => mapping(address => mapping(uint32 => OperatorSetRegistrationStatus))) public operatorSetStatus;

// Construction

constructor(
IDelegationManager _delegation,
uint32 _DEALLOCATION_DELAY
) {
delegation = _delegation;
DEALLOCATION_DELAY = _DEALLOCATION_DELAY;
ORIGINAL_CHAIN_ID = block.chainid;
}

/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
Expand Down
53 changes: 9 additions & 44 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol
import "../permissions/Pausable.sol";
import "../libraries/EIP1271SignatureUtils.sol";
import "../libraries/SlashingLib.sol";
import "../interfaces/IAVSDirectory.sol";
import "../interfaces/IDelegationManager.sol";
import "./AllocationManagerStorage.sol";

contract AllocationManager is
Expand All @@ -21,47 +19,6 @@ contract AllocationManager is
{
using Snapshots for Snapshots.History;

// Constants

/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

/// @notice The EIP-712 typehash for the `MagnitudeAdjustments` struct used by the contract
bytes32 public constant MAGNITUDE_ADJUSTMENT_TYPEHASH = keccak256(
"MagnitudeAdjustments(address operator,MagnitudeAdjustment(address strategy, OperatorSet(address avs, uint32 operatorSetId)[], uint64[] magnitudeDiffs)[],bytes32 salt,uint256 expiry)"
);

/// @dev Index for flag that pauses operator allocations/deallocations when set.
uint8 internal constant PAUSED_STAKE_ALLOCATIONS_AND_DEALLOCATIONS = 0;

/// @dev Index for flag that pauses operator register/deregister to operator sets when set.
uint8 internal constant PAUSED_OPERATOR_SLASHING = 1;

/// @dev BIPS factor for slashable bips
uint256 internal constant BIPS_FACTOR = 10_000;

/// @dev Maximum number of pending updates that can be queued for allocations/deallocations
uint256 internal constant MAX_PENDING_UPDATES = 1;

// Immutables

/// @notice The DelegationManager contract for EigenLayer
IDelegationManager public immutable delegation;

/// @notice The AVSDirectory contract for EigenLayer
IAVSDirectory public immutable avsDirectory;

/// @notice Delay before deallocations are completable and can be added back into freeMagnitude
/// In this window, deallocations still remain slashable by the operatorSet they were allocated to.
uint32 public immutable DEALLOCATION_DELAY;

/// @dev Delay before alloaction delay modifications take effect.
uint32 public immutable ALLOCATION_CONFIGURATION_DELAY; // QUESTION: 21 days?

/// @dev Returns the chain ID from the time the contract was deployed.
uint256 internal immutable ORIGINAL_CHAIN_ID;

/**
*
* INITIALIZING FUNCTIONS
Expand All @@ -77,11 +34,19 @@ contract AllocationManager is
IAVSDirectory _avsDirectory,
uint32 _DEALLOCATION_DELAY,
uint32 _ALLOCATION_CONFIGURATION_DELAY
) {
)
AllocationManagerStorage(
_delegation,
_avsDirectory,
_DEALLOCATION_DELAY,
_ALLOCATION_CONFIGURATION_DELAY
)
{
_disableInitializers();
delegation = _delegation;
avsDirectory = _avsDirectory;
DEALLOCATION_DELAY = _DEALLOCATION_DELAY;
ALLOCATION_CONFIGURATION_DELAY = _ALLOCATION_CONFIGURATION_DELAY;
ORIGINAL_CHAIN_ID = block.chainid;
}

Expand Down
60 changes: 60 additions & 0 deletions src/contracts/core/AllocationManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,56 @@
pragma solidity ^0.8.27;

import "../interfaces/IAllocationManager.sol";
import "../interfaces/IAVSDirectory.sol";
import "../interfaces/IDelegationManager.sol";
import {Snapshots} from "../libraries/Snapshots.sol";

abstract contract AllocationManagerStorage is IAllocationManager {
using Snapshots for Snapshots.History;

// Constants

/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

/// @notice The EIP-712 typehash for the `MagnitudeAdjustments` struct used by the contract
bytes32 public constant MAGNITUDE_ADJUSTMENT_TYPEHASH = keccak256(
"MagnitudeAdjustments(address operator,MagnitudeAdjustment(address strategy, OperatorSet(address avs, uint32 operatorSetId)[], uint64[] magnitudeDiffs)[],bytes32 salt,uint256 expiry)"
);

/// @dev Index for flag that pauses operator allocations/deallocations when set.
uint8 internal constant PAUSED_STAKE_ALLOCATIONS_AND_DEALLOCATIONS = 0;

/// @dev Index for flag that pauses operator register/deregister to operator sets when set.
uint8 internal constant PAUSED_OPERATOR_SLASHING = 1;

/// @dev BIPS factor for slashable bips
uint256 internal constant BIPS_FACTOR = 10_000;

/// @dev Maximum number of pending updates that can be queued for allocations/deallocations
uint256 internal constant MAX_PENDING_UPDATES = 1;

// Immutables

/// @notice The DelegationManager contract for EigenLayer
IDelegationManager public immutable delegation;

/// @notice The AVSDirectory contract for EigenLayer
IAVSDirectory public immutable avsDirectory;

/// @notice Delay before deallocations are completable and can be added back into freeMagnitude
/// In this window, deallocations still remain slashable by the operatorSet they were allocated to.
uint32 public immutable DEALLOCATION_DELAY;

/// @dev Delay before alloaction delay modifications take effect.
uint32 public immutable ALLOCATION_CONFIGURATION_DELAY; // QUESTION: 21 days?

/// @dev Returns the chain ID from the time the contract was deployed.
uint256 internal immutable ORIGINAL_CHAIN_ID;

// Mutatables

/**
* @notice Original EIP-712 Domain separator for this contract.
* @dev The domain separator may change in the event of a fork that modifies the ChainID.
Expand Down Expand Up @@ -37,6 +82,21 @@ abstract contract AllocationManagerStorage is IAllocationManager {
/// This determines how long it takes for allocations to take effect in the future.
mapping(address => AllocationDelayInfo) internal _allocationDelayInfo;

// Construction

constructor(
IDelegationManager _delegation,
IAVSDirectory _avsDirectory,
uint32 _DEALLOCATION_DELAY,
uint32 _ALLOCATION_CONFIGURATION_DELAY
) {
delegation = _delegation;
avsDirectory = _avsDirectory;
DEALLOCATION_DELAY = _DEALLOCATION_DELAY;
ALLOCATION_CONFIGURATION_DELAY = _ALLOCATION_CONFIGURATION_DELAY;
ORIGINAL_CHAIN_ID = block.chainid;
}

/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
Expand Down
76 changes: 9 additions & 67 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol
import "../permissions/Pausable.sol";
import "../libraries/EIP1271SignatureUtils.sol";
import "../libraries/SlashingLib.sol";
import "../interfaces/IStrategyManager.sol";
import "../interfaces/IAVSDirectory.sol";
import "../interfaces/IEigenPodManager.sol";
import "../interfaces/IAllocationManager.sol";
import "./DelegationManagerStorage.sol";

/**
Expand All @@ -32,62 +28,6 @@ contract DelegationManager is
{
using SlashingLib for *;

// Constants

/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

/// @notice The EIP-712 typehash for the `StakerDelegation` struct used by the contract
bytes32 public constant STAKER_DELEGATION_TYPEHASH =
keccak256("StakerDelegation(address staker,address operator,uint256 nonce,uint256 expiry)");

/// @notice The EIP-712 typehash for the `DelegationApproval` struct used by the contract
bytes32 public constant DELEGATION_APPROVAL_TYPEHASH = keccak256(
"DelegationApproval(address delegationApprover,address staker,address operator,bytes32 salt,uint256 expiry)"
);

/// @dev Index for flag that pauses new delegations when set
uint8 internal constant PAUSED_NEW_DELEGATION = 0;

/// @dev Index for flag that pauses queuing new withdrawals when set.
uint8 internal constant PAUSED_ENTER_WITHDRAWAL_QUEUE = 1;

/// @dev Index for flag that pauses completing existing withdrawals when set.
uint8 internal constant PAUSED_EXIT_WITHDRAWAL_QUEUE = 2;

/// @notice The minimum number of blocks to complete a withdrawal of a strategy. 50400 * 12 seconds = 1 week
uint256 public constant LEGACY_MIN_WITHDRAWAL_DELAY_BLOCKS = 50_400;

/// @notice Wed Jan 01 2025 17:00:00 GMT+0000, timestamp used to check whether a pending withdrawal
/// should be processed as legacy M2 or with slashing considered.
uint32 public constant LEGACY_WITHDRAWALS_TIMESTAMP = 1_735_750_800;

/// @notice Canonical, virtual beacon chain ETH strategy
IStrategy public constant beaconChainETHStrategy = IStrategy(0xbeaC0eeEeeeeEEeEeEEEEeeEEeEeeeEeeEEBEaC0);

// Immutables

/// @notice The AVSDirectory contract for EigenLayer
IAVSDirectory public immutable avsDirectory;

// TODO: Switch these to ShareManagers, but this breaks a lot of tests

/// @notice The StrategyManager contract for EigenLayer
IStrategyManager public immutable strategyManager;

/// @notice The EigenPodManager contract for EigenLayer
IEigenPodManager public immutable eigenPodManager;

/// @notice The AllocationManager contract for EigenLayer
IAllocationManager public immutable allocationManager;

/// @notice Minimum withdrawal delay in seconds until all queued withdrawals can be completed.
uint32 public immutable MIN_WITHDRAWAL_DELAY;

/// @dev Chain ID at the time of contract deployment
uint256 internal immutable ORIGINAL_CHAIN_ID;

// @notice Simple permission for functions that are only callable by the StrategyManager contract OR by the EigenPodManagerContract
modifier onlyStrategyManagerOrEigenPodManager() {
require(
Expand All @@ -112,14 +52,16 @@ contract DelegationManager is
IEigenPodManager _eigenPodManager,
IAllocationManager _allocationManager,
uint32 _MIN_WITHDRAWAL_DELAY
) {
)
DelegationManagerStorage(
_avsDirectory,
_strategyManager,
_eigenPodManager,
_allocationManager,
_MIN_WITHDRAWAL_DELAY
)
{
_disableInitializers();
avsDirectory = _avsDirectory;
strategyManager = _strategyManager;
eigenPodManager = _eigenPodManager;
allocationManager = _allocationManager;
MIN_WITHDRAWAL_DELAY = _MIN_WITHDRAWAL_DELAY;
ORIGINAL_CHAIN_ID = block.chainid;
}

/**
Expand Down
Loading

0 comments on commit 90c1f7e

Please sign in to comment.