Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: avsd alm refactor #867

Open
wants to merge 6 commits into
base: alex/avsd-alm-refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/forge-std
2 changes: 1 addition & 1 deletion script/deploy/devnet/Upgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract Upgrade is ExistingDeploymentParser {
_parseDeployedContracts("script/output/holesky/pre_preprod_slashing.holesky.json");

vm.startBroadcast();
AVSDirectory newAVSDirectoryImplementation = new AVSDirectory(delegationManager, DEALLOCATION_DELAY);
AVSDirectory newAVSDirectoryImplementation = new AVSDirectory(delegationManager);
eigenLayerProxyAdmin.upgrade(ITransparentUpgradeableProxy(payable(address(avsDirectory))), address(newAVSDirectoryImplementation));
vm.stopBroadcast();

Expand Down
12 changes: 3 additions & 9 deletions script/deploy/devnet/deploy_from_scratch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ contract DeployFromScratch is Script, Test {

delegationImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegation);
avsDirectoryImplementation = new AVSDirectory(delegation, DEALLOCATION_DELAY);
avsDirectoryImplementation = new AVSDirectory(delegation);
eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
eigenPodBeacon,
Expand All @@ -246,13 +246,11 @@ contract DeployFromScratch is Script, Test {
REWARDS_COORDINATOR_MAX_FUTURE_LENGTH,
REWARDS_COORDINATOR_GENESIS_REWARDS_TIMESTAMP
);
allocationManagerImplementation = new AllocationManager(delegation, avsDirectory, DEALLOCATION_DELAY, ALLOCATION_CONFIGURATION_DELAY);
allocationManagerImplementation = new AllocationManager(delegation, DEALLOCATION_DELAY, ALLOCATION_CONFIGURATION_DELAY);
strategyFactoryImplementation = new StrategyFactory(strategyManager);

// Third, upgrade the proxy contracts to use the correct implementation contracts and initialize them.
{
IStrategy[] memory _strategies;
uint256[] memory _withdrawalDelayBlocks;
eigenLayerProxyAdmin.upgradeAndCall(
ITransparentUpgradeableProxy(payable(address(delegation))),
address(delegationImplementation),
Expand Down Expand Up @@ -499,10 +497,6 @@ contract DeployFromScratch is Script, Test {
allocationManagerContract.delegation() == delegation,
"allocationManager: delegation address not set correctly"
);
require(
allocationManagerContract.avsDirectory() == avsDirectory,
"allocationManager: avsDirectory address not set correctly"
);
}

function _verifyImplementationsSetCorrectly() internal view {
Expand Down Expand Up @@ -613,7 +607,7 @@ contract DeployFromScratch is Script, Test {
// require(eigenPodManager.paused() == 30, "eigenPodManager: init paused status set incorrectly");
}

function _verifyInitializationParams() internal {
function _verifyInitializationParams() internal view {
// // one week in blocks -- 50400
// uint32 STRATEGY_MANAGER_INIT_WITHDRAWAL_DELAY_BLOCKS = 7 days / 12 seconds;
// require(strategyManager.withdrawalDelayBlocks() == 7 days / 12 seconds,
Expand Down
4 changes: 2 additions & 2 deletions script/deploy/holesky/M2_Deploy_From_Scratch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ contract M2_Deploy_Holesky_From_Scratch is ExistingDeploymentParser {
);

eigenPodBeacon = new UpgradeableBeacon(address(eigenPodImplementation));
avsDirectoryImplementation = new AVSDirectory(delegationManager, DEALLOCATION_DELAY);
avsDirectoryImplementation = new AVSDirectory(delegationManager);
delegationManagerImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegationManager);
eigenPodManagerImplementation = new EigenPodManager(
Expand All @@ -85,7 +85,7 @@ contract M2_Deploy_Holesky_From_Scratch is ExistingDeploymentParser {
strategyManager,
delegationManager
);
allocationManagerImplementation = new AllocationManager(delegationManager, avsDirectory, DEALLOCATION_DELAY, ALLOCATION_CONFIGURATION_DELAY);
allocationManagerImplementation = new AllocationManager(delegationManager, DEALLOCATION_DELAY, ALLOCATION_CONFIGURATION_DELAY);

// Third, upgrade the proxy contracts to point to the implementations
IStrategy[] memory initializeStrategiesToSetDelayBlocks = new IStrategy[](0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract Upgrade_Testnet_RewardsCoordinator is Deploy_Test_RewardsCoordinator, T
_verifyInitializationParams();
}

function _sanityCheckImplementations(RewardsCoordinator oldRc, RewardsCoordinator newRc) internal {
function _sanityCheckImplementations(RewardsCoordinator oldRc, RewardsCoordinator newRc) internal view {
// Verify configs between both rewardsCoordinatorImplementations
assertEq(
address(oldRc.delegationManager()),
Expand Down
6 changes: 3 additions & 3 deletions script/deploy/local/Deploy_From_Scratch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ contract DeployFromScratch is Script, Test {

delegationImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegation);
avsDirectoryImplementation = new AVSDirectory(delegation, DEALLOCATION_DELAY);
avsDirectoryImplementation = new AVSDirectory(delegation);
eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
eigenPodBeacon,
Expand All @@ -252,7 +252,7 @@ contract DeployFromScratch is Script, Test {
REWARDS_COORDINATOR_MAX_FUTURE_LENGTH,
REWARDS_COORDINATOR_GENESIS_REWARDS_TIMESTAMP
);
allocationManagerImplementation = new AllocationManager(delegation, avsDirectory, DEALLOCATION_DELAY, ALLOCATION_CONFIGURATION_DELAY);
allocationManagerImplementation = new AllocationManager(delegation, DEALLOCATION_DELAY, ALLOCATION_CONFIGURATION_DELAY);

// Third, upgrade the proxy contracts to use the correct implementation contracts and initialize them.
{
Expand Down Expand Up @@ -589,7 +589,7 @@ contract DeployFromScratch is Script, Test {
// require(eigenPodManager.paused() == 30, "eigenPodManager: init paused status set incorrectly");
}

function _verifyInitializationParams() internal {
function _verifyInitializationParams() internal view {
// // one week in blocks -- 50400
// uint32 STRATEGY_MANAGER_INIT_WITHDRAWAL_DELAY_BLOCKS = 7 days / 12 seconds;
// require(strategyManager.withdrawalDelayBlocks() == 7 days / 12 seconds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ contract Upgrade_Mainnet_RewardsCoordinator is ExistingDeploymentParser, Timeloc
_verifyInitializationParams();
}

function _sanityCheckImplementations(RewardsCoordinator oldRc, RewardsCoordinator newRc) internal {
function _sanityCheckImplementations(RewardsCoordinator oldRc, RewardsCoordinator newRc) internal view {
// Verify configs between both rewardsCoordinatorImplementations
assertEq(
address(oldRc.delegationManager()),
Expand Down
2 changes: 0 additions & 2 deletions script/utils/ExistingDeploymentParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,6 @@ contract ExistingDeploymentParser is Script, Test {
);
// DelegationManager
vm.expectRevert(bytes("Initializable: contract is already initialized"));
IStrategy[] memory initializeStrategiesToSetDelayBlocks = new IStrategy[](0);
uint256[] memory initializeWithdrawalDelayBlocks = new uint256[](0);
delegationManager.initialize(
address(0),
eigenLayerPauserReg,
Expand Down
5 changes: 2 additions & 3 deletions src/contracts/core/AVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ contract AVSDirectory is
* and eigenpodManager contracts
*/
constructor(
IDelegationManager _delegation,
uint32 _DEALLOCATION_DELAY
) AVSDirectoryStorage(_delegation, _DEALLOCATION_DELAY) {
IDelegationManager _delegation
) AVSDirectoryStorage(_delegation) {
_disableInitializers();
}

Expand Down
7 changes: 1 addition & 6 deletions src/contracts/core/AVSDirectoryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ abstract contract AVSDirectoryStorage is IAVSDirectory {
/// @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;

// Mutatables

/// @dev Do not remove, deprecated storage.
Expand All @@ -48,9 +44,8 @@ abstract contract AVSDirectoryStorage is IAVSDirectory {

// Construction

constructor(IDelegationManager _delegation, uint32 _DEALLOCATION_DELAY) {
constructor(IDelegationManager _delegation) {
delegation = _delegation;
DEALLOCATION_DELAY = _DEALLOCATION_DELAY;
}

/**
Expand Down
13 changes: 10 additions & 3 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract AllocationManager is
OperatorSet memory operatorSet = OperatorSet(msg.sender, params.operatorSetId);
bool isRegistered = _isRegistered(params.operator, operatorSet);
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
require(isRegistered, InvalidOperator());
require(isRegistered, NotMemberOfSet());

uint256 length = _operatorSetStrategies[operatorSet.key()].length();
IStrategy[] memory strategiesSlashed = new IStrategy[](length);
Expand Down Expand Up @@ -294,7 +294,7 @@ contract AllocationManager is
OperatorSet memory operatorSet = OperatorSet(msg.sender, params[i].operatorSetId);

// Create the operator set, ensuring it does not already exist
require(_operatorSets[msg.sender].add(operatorSet.id) == false, InvalidOperatorSet());
require(_operatorSets[msg.sender].add(operatorSet.id) == true, InvalidOperatorSet());
emit OperatorSetCreated(OperatorSet(msg.sender, operatorSet.id));

// Add strategies to the operator set
Expand Down Expand Up @@ -423,7 +423,7 @@ contract AllocationManager is
/**
* @dev For an operator set, get the operator's effective allocated magnitude.
* If the operator set has a pending deallocation that can be completed at the
* current timestamp, this method returns a view of the allocation as if the deallocation
* current block number, this method returns a view of the allocation as if the deallocation
* was completed.
* @return info the effective allocated and pending magnitude for the operator set, and
* the effective encumbered magnitude for all operator sets belonging to this strategy
Expand Down Expand Up @@ -691,6 +691,13 @@ contract AllocationManager is
return operatorSets;
}

/// @inheritdoc IAllocationManager
function isOperatorSet(
OperatorSet memory operatorSet
) external view returns (bool) {
return _operatorSets[operatorSet.avs].contains(operatorSet.id);
}

/// @inheritdoc IAllocationManager
function getMembers(
OperatorSet memory operatorSet
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/core/AllocationManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ abstract contract AllocationManagerStorage is IAllocationManager {
_maxMagnitudeHistory;

/// @dev For a strategy, contains the amount of magnitude an operator has allocated to operator sets
mapping(address operator => mapping(IStrategy strategy => uint64)) internal encumberedMagnitude;
mapping(address operator => mapping(IStrategy strategy => uint64)) public encumberedMagnitude;

/// @dev For a strategy, keeps an ordered queue of operator sets that have pending deallocations
/// These must be completed in order to free up magnitude for future allocation
Expand Down
6 changes: 3 additions & 3 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ contract DelegationManager is
function completeQueuedWithdrawal(
Withdrawal calldata withdrawal,
IERC20[] calldata tokens,
uint256 middlewareTimesIndex,
uint256, // middlewareTimesIndex
bool receiveAsTokens
) external onlyWhenNotPaused(PAUSED_EXIT_WITHDRAWAL_QUEUE) nonReentrant {
_completeQueuedWithdrawal(withdrawal, tokens, receiveAsTokens);
Expand All @@ -398,7 +398,7 @@ contract DelegationManager is
function completeQueuedWithdrawals(
Withdrawal[] calldata withdrawals,
IERC20[][] calldata tokens,
uint256[] calldata middlewareTimesIndexes,
uint256[] calldata, // middlewareTimesIndexes
bool[] calldata receiveAsTokens
) external onlyWhenNotPaused(PAUSED_EXIT_WITHDRAWAL_QUEUE) nonReentrant {
for (uint256 i = 0; i < withdrawals.length; ++i) {
Expand Down Expand Up @@ -699,7 +699,7 @@ contract DelegationManager is
function _hasNonZeroScalingFactors(
uint64 maxMagnitude,
StakerScalingFactors memory ssf
) internal view returns (bool) {
) internal pure returns (bool) {
return maxMagnitude != 0 && (!ssf.isBeaconChainScalingFactorSet || ssf.beaconChainScalingFactor != 0);
}

Expand Down
5 changes: 4 additions & 1 deletion src/contracts/core/RewardsCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,10 @@ contract RewardsCoordinator is
}

/// @inheritdoc IRewardsCoordinator
function operatorCommissionBips(address operator, address avs) external view returns (uint16) {
function operatorCommissionBips(
address, // operator
address // avs
) external view returns (uint16) {
return globalOperatorCommissionBips;
}

Expand Down
2 changes: 1 addition & 1 deletion src/contracts/interfaces/IAVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ interface IAVSDirectory is IAVSDirectoryEvents, IAVSDirectoryErrors, ISignatureU
/**
* @notice Legacy function called by the AVS's service manager contract
* to register an operator with the AVS. NOTE: this function will be deprecated in a future release
* after the slashing release. New AVSs should use `registerOperatorToOperatorSets` instead.
* after the slashing release. New AVSs should use `registerForOperatorSets` instead.
*
* @param operator The address of the operator to register.
* @param operatorSignature The signature, salt, and expiry of the operator's signature.
Expand Down
9 changes: 8 additions & 1 deletion src/contracts/interfaces/IAllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IAllocationManagerErrors {
error OperatorNotSlashable();
/// @dev Thrown when trying to add an operator to a set they are already a member of
error AlreadyMemberOfSet();
/// @dev Thrown when trying to remove an operator from a set they are not a member of
/// @dev Thrown when trying to slash/remove an operator from a set they are not a member of
error NotMemberOfSet();

/// Operator Set Status
Expand Down Expand Up @@ -464,6 +464,13 @@ interface IAllocationManager is ISignatureUtils, IAllocationManagerErrors, IAllo
address operator
) external view returns (OperatorSet[] memory operatorSets);

/**
* @notice Returns whether the operator set exists
*/
function isOperatorSet(
OperatorSet memory operatorSet
) external view returns (bool);

/**
* @notice Returns all the operators registered to an operator set
* @param operatorSet The operatorSet to query.
Expand Down
11 changes: 9 additions & 2 deletions src/contracts/strategies/StrategyBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,22 @@ contract StrategyBase is Initializable, Pausable, IStrategy {
* @notice Called in the external `deposit` function, before any logic is executed. Expected to be overridden if strategies want such logic.
* @param token The token being deposited
*/
function _beforeDeposit(IERC20 token, uint256 amount) internal virtual {
function _beforeDeposit(
IERC20 token,
uint256 // amount
) internal virtual {
require(token == underlyingToken, OnlyUnderlyingToken());
}

/**
* @notice Called in the external `withdraw` function, before any logic is executed. Expected to be overridden if strategies want such logic.
* @param token The token being withdrawn
*/
function _beforeWithdrawal(address recipient, IERC20 token, uint256 amountShares) internal virtual {
function _beforeWithdrawal(
address, // recipient
IERC20 token,
uint256 // amountShares
) internal virtual {
require(token == underlyingToken, OnlyUnderlyingToken());
}

Expand Down
Loading
Loading