From 7f90be1143e6f80ea762ad3901f043ffefbd2917 Mon Sep 17 00:00:00 2001 From: Yash Patil <40046473+ypatil12@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:08:29 -0500 Subject: [PATCH] feat: add restakeable strategies to service manager for indexing (#113) --- src/ServiceManagerBase.sol | 30 ++++++++++++++++++++++++++++++ src/interfaces/IServiceManager.sol | 8 ++++++++ 2 files changed, 38 insertions(+) diff --git a/src/ServiceManagerBase.sol b/src/ServiceManagerBase.sol index 9c63fa06..2bdf3e07 100644 --- a/src/ServiceManagerBase.sol +++ b/src/ServiceManagerBase.sol @@ -77,6 +77,36 @@ contract ServiceManagerBase is IServiceManager, OwnableUpgradeable { delegationManager.deregisterOperatorFromAVS(operator); } + /** + * @notice Returns the list of strategies that the AVS supports for restaking + * @dev This function is intended to be called off-chain + * @dev No guarantee is made on uniqueness of each element in the returned array. + * The off-chain service should do that validation separately + */ + function getRestakeableStrategies() external view returns (address[] memory) { + uint256 quorumCount = registryCoordinator.quorumCount(); + + if (quorumCount == 0) { + return new address[](0); + } + + uint256 strategyCount; + for(uint256 i = 0; i < quorumCount; i++) { + strategyCount += stakeRegistry.strategyParamsLength(uint8(i)); + } + + address[] memory restakedStrategies = new address[](strategyCount); + uint256 index = 0; + for(uint256 i = 0; i < registryCoordinator.quorumCount(); i++) { + uint256 strategyParamsLength = stakeRegistry.strategyParamsLength(uint8(i)); + for (uint256 j = 0; j < strategyParamsLength; j++) { + restakedStrategies[index] = address(stakeRegistry.strategyParamsByIndex(uint8(i), j).strategy); + index++; + } + } + return restakedStrategies; + } + /** * @notice Returns the list of strategies that the operator has potentially restaked on the AVS * @param operator The address of the operator to get restaked strategies for diff --git a/src/interfaces/IServiceManager.sol b/src/interfaces/IServiceManager.sol index 1367fa41..ca22de58 100644 --- a/src/interfaces/IServiceManager.sol +++ b/src/interfaces/IServiceManager.sol @@ -39,4 +39,12 @@ interface IServiceManager { * of each element in the returned array. The off-chain service should do that validation separately */ function getOperatorRestakedStrategies(address operator) external view returns (address[] memory); + + /** + * @notice Returns the list of strategies that the AVS supports for restaking + * @dev This function is intended to be called off-chain + * @dev No guarantee is made on uniqueness of each element in the returned array. + * The off-chain service should do that validation separately + */ + function getRestakeableStrategies() external view returns (address[] memory); }