Skip to content

Commit

Permalink
feat: add view functions for allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Sep 12, 2024
1 parent 0e75139 commit e0ccf3e
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 deletions.
3 changes: 3 additions & 0 deletions script/configs/local/deploy_from_scratch.anvil.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@
"OPERATOR_SET_GENESIS_REWARDS_TIMESTAMP": 1720656000,
"OPERATOR_SET_MAX_RETROACTIVE_LENGTH": 2592000
},
"allocationManager": {
"init_paused_status": 0
},
"ethPOSDepositAddress": "0x00000000219ab540356cBB839Cbe05303d7705Fa"
}
31 changes: 29 additions & 2 deletions script/deploy/local/Deploy_From_Scratch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import "forge-std/Test.sol";
// source .env

// # To deploy and verify our contract
// forge script script/deploy/devnet/Deploy_From_Scratch.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --sig "run(string memory configFile)" -- deploy_from_scratch.anvil.config.json
// forge script script/deploy/local/Deploy_From_Scratch.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --sig "run(string memory configFile)" -- deploy_from_scratch.anvil.config.json
contract DeployFromScratch is Script, Test {
Vm cheats = Vm(HEVM_ADDRESS);

Expand Down Expand Up @@ -101,6 +101,9 @@ contract DeployFromScratch is Script, Test {
uint32 REWARDS_COORDINATOR_OPERATOR_SET_GENESIS_REWARDS_TIMESTAMP;
uint32 REWARDS_COORDINATOR_OPERATOR_SET_MAX_RETROACTIVE_LENGTH;

// AllocationManager
uint256 ALLOCATION_MANAGER_INIT_PAUSED_STATUS;

// one week in blocks -- 50400
uint32 STRATEGY_MANAGER_INIT_WITHDRAWAL_DELAY_BLOCKS;
uint256 DELEGATION_WITHDRAWAL_DELAY_BLOCKS;
Expand All @@ -111,7 +114,7 @@ contract DeployFromScratch is Script, Test {
emit log_named_uint("You are deploying on ChainID", chainId);

// READ JSON CONFIG DATA
deployConfigPath = string(bytes(string.concat("script/configs/devnet/", configFileName)));
deployConfigPath = string(bytes(string.concat("script/configs/local/", configFileName)));
string memory config_data = vm.readFile(deployConfigPath);
// bytes memory parsedData = vm.parseJson(config_data);

Expand Down Expand Up @@ -150,6 +153,10 @@ contract DeployFromScratch is Script, Test {
stdJson.readUint(config_data, ".strategyManager.init_withdrawal_delay_blocks")
);

ALLOCATION_MANAGER_INIT_PAUSED_STATUS = uint32(
stdJson.readUint(config_data, ".allocationManager.init_paused_status")
);

// tokens to deploy strategies for
StrategyConfig[] memory strategyConfigs;

Expand Down Expand Up @@ -314,6 +321,17 @@ contract DeployFromScratch is Script, Test {
)
);

eigenLayerProxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(allocationManager))),
address(allocationManagerImplementation),
abi.encodeWithSelector(
AllocationManager.initialize.selector,
executorMultisig,
eigenLayerPauserReg,
ALLOCATION_MANAGER_INIT_PAUSED_STATUS
)
);

// deploy StrategyBaseTVLLimits contract implementation
baseStrategyImplementation = new StrategyBaseTVLLimits(strategyManager);
// create upgradeable proxies that each point to the implementation and initialize them
Expand Down Expand Up @@ -391,6 +409,8 @@ contract DeployFromScratch is Script, Test {
vm.serializeAddress(deployed_addresses, "delegationManagerImplementation", address(delegationImplementation));
vm.serializeAddress(deployed_addresses, "avsDirectory", address(avsDirectory));
vm.serializeAddress(deployed_addresses, "avsDirectoryImplementation", address(avsDirectoryImplementation));
vm.serializeAddress(deployed_addresses, "allocationManager", address(allocationManager));
vm.serializeAddress(deployed_addresses, "allocationManagerImplementation", address(allocationManagerImplementation));
vm.serializeAddress(deployed_addresses, "strategyManager", address(strategyManager));
vm.serializeAddress(
deployed_addresses,
Expand Down Expand Up @@ -531,6 +551,13 @@ contract DeployFromScratch is Script, Test {
"rewardsCoordinator: implementation set incorrectly"
);

require(
eigenLayerProxyAdmin.getProxyImplementation(
TransparentUpgradeableProxy(payable(address(allocationManager)))
) == address(allocationManagerImplementation),
"allocationManager: implementation set incorrectly"
);

for (uint256 i = 0; i < deployedStrategyArray.length; ++i) {
require(
eigenLayerProxyAdmin.getProxyImplementation(
Expand Down
70 changes: 70 additions & 0 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,76 @@ contract AllocationManager is
return totalMagnitude;
}

/**
* @notice Returns the latest pending allocation of an operator for a given strategy and operatorSets.
* One of the assumptions here is we don't allow more than one pending allocation for an operatorSet at a time.
* If that changes, we would need to change this function to return all pending allocations for an operatorSet.
* @param operator the operator to get the pending allocations for
* @param strategy the strategy to get the pending allocations for
* @param operatorSets the operatorSets to get the pending allocations for
* @return pendingMagnitude the pending allocations for each operatorSet
* @return timestamps the timestamps for each pending allocation
*/
function getPendingAllocations(
address operator,
IStrategy strategy,
OperatorSet[] calldata operatorSets
) external view returns (uint64[] memory, uint32[] memory) {
uint64[] memory pendingMagnitude = new uint64[](operatorSets.length);
uint32[] memory timestamps = new uint32[](operatorSets.length);
for (uint256 i = 0; i < operatorSets.length; ++i) {
// We use latestSnapshot to get the latest pending allocation for an operatorSet.
(bool exists, uint32 key, uint224 value) =
_magnitudeUpdate[operator][strategy][_encodeOperatorSet(operatorSets[i])].latestSnapshot();
if (exists) {
if (key > block.timestamp) {
pendingMagnitude[i] = uint64(value);
timestamps[i] = key;
} else {
pendingMagnitude[i] = 0;
timestamps[i] = 0;
}
}
}
return (pendingMagnitude, timestamps);
}

/**
* @notice Returns the pending deallocations of an operator for a given strategy and operatorSets.
* One of the assumptions here is we don't allow more than one pending deallocation for an operatorSet at a time.
* If that changes, we would need to change this function to return all pending deallocations for an operatorSet.
* @param operator the operator to get the pending deallocations for
* @param strategy the strategy to get the pending deallocations for
* @param operatorSets the operatorSets to get the pending deallocations for
* @return pendingMagnitudeDiff the pending difference in deallocations for each operatorSet
* @return timestamps the timestamps for each pending deallocation
*/
function getPendingDeallocations(
address operator,
IStrategy strategy,
OperatorSet[] calldata operatorSets
) external view returns (uint64[] memory, uint32[] memory) {
uint64[] memory pendingMagnitudeDiff = new uint64[](operatorSets.length);
uint32[] memory timestamps = new uint32[](operatorSets.length);
for (uint256 i = 0; i < operatorSets.length; ++i) {
uint256[] memory indices =
_queuedDeallocationIndices[operator][strategy][_encodeOperatorSet(operatorSets[i])];
uint256 length = indices.length;
uint256 deallocationIndex = indices[length - 1];
PendingFreeMagnitude memory latestPendingMagnitude =
_pendingFreeMagnitude[operator][strategy][deallocationIndex];
if (latestPendingMagnitude.completableTimestamp > block.timestamp) {
pendingMagnitudeDiff[i] = latestPendingMagnitude.magnitudeDiff;
timestamps[i] = latestPendingMagnitude.completableTimestamp;
} else {
// There is no pending deallocation, so we set the pending magnitude and timestamp to 0
pendingMagnitudeDiff[i] = 0;
timestamps[i] = 0;
}
}
return (pendingMagnitudeDiff, timestamps);
}

// /**
// * @notice fetches the minimum slashable shares for a certain operator and operatorSet for a list of strategies
// * from the current timestamp until the given timestamp
Expand Down
32 changes: 32 additions & 0 deletions src/contracts/interfaces/IAllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,38 @@ interface IAllocationManager is ISignatureUtils {
uint16 numToComplete
) external view returns (uint64);

/**
* @notice Returns the pending allocations of an operator for a given strategy and operatorSets
* One of the assumptions here is we don't allow more than one pending allocation for an operatorSet at a time.
* If that changes, we would need to change this function to return all pending allocations for an operatorSet.
* @param operator the operator to get the pending allocations for
* @param strategy the strategy to get the pending allocations for
* @param operatorSets the operatorSets to get the pending allocations for
* @return pendingMagnitude the pending allocations for each operatorSet
* @return timestamps the timestamps for each pending allocation
*/
function getPendingAllocations(
address operator,
IStrategy strategy,
OperatorSet[] calldata operatorSets
) external view returns (uint64[] memory, uint32[] memory);

/**
* @notice Returns the pending deallocations of an operator for a given strategy and operatorSets.
* One of the assumptions here is we don't allow more than one pending deallocation for an operatorSet at a time.
* If that changes, we would need to change this function to return all pending deallocations for an operatorSet.
* @param operator the operator to get the pending deallocations for
* @param strategy the strategy to get the pending deallocations for
* @param operatorSets the operatorSets to get the pending deallocations for
* @return pendingMagnitudeDiff the pending difference in deallocations for each operatorSet
* @return timestamps the timestamps for each pending deallocation
*/
function getPendingDeallocations(
address operator,
IStrategy strategy,
OperatorSet[] calldata operatorSets
) external view returns (uint64[] memory, uint32[] memory);

/**
* @notice operator is slashable by operatorSet if currently registered OR last deregistered within 21 days
* @param operator the operator to check slashability for
Expand Down

0 comments on commit e0ccf3e

Please sign in to comment.