Skip to content

Commit

Permalink
getRestakeableStrategies
Browse files Browse the repository at this point in the history
  • Loading branch information
aroralanuk committed Apr 22, 2024
1 parent 8873f20 commit 2158670
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions solidity/contracts/avs/HyperlaneServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Own
import {ISignatureUtils} from "@eigenlayer/core/interfaces/ISignatureUtils.sol";
import {IAVSDirectory} from "@eigenlayer/core/interfaces/IAVSDirectory.sol";

import {IStakeRegistry} from "@eigenlayer/middleware/interfaces/IStakeRegistry.sol";
import {ECDSAStakeRegistry} from "@eigenlayer/middleware/unaudited/ECDSAStakeRegistry.sol";
import {IServiceManager} from "@eigenlayer/middleware/interfaces/IServiceManager.sol";

contract HyperlaneServiceManager is IServiceManager, OwnableUpgradeable {
IStakeRegistry internal immutable stakeRegistry;
ECDSAStakeRegistry internal immutable stakeRegistry;
IAVSDirectory internal immutable elAvsDirectory;

/// @notice when applied to a function, only allows the ECDSAStakeRegistry to call it
Expand All @@ -22,12 +22,19 @@ contract HyperlaneServiceManager is IServiceManager, OwnableUpgradeable {
_;
}

constructor(IAVSDirectory _avsDirectory, IStakeRegistry _stakeRegistry) {
// ============ Constructor ============

constructor(
IAVSDirectory _avsDirectory,
ECDSAStakeRegistry _stakeRegistry
) {
elAvsDirectory = _avsDirectory;
stakeRegistry = _stakeRegistry;
_disableInitializers();
}

// ============ Public Functions ============

/**
* @notice Updates the metadata URI for the AVS
* @param _metadataURI is the metadata URI for the AVS
Expand Down Expand Up @@ -61,6 +68,8 @@ contract HyperlaneServiceManager is IServiceManager, OwnableUpgradeable {
elAvsDirectory.deregisterOperatorFromAVS(operator);
}

// ============ External Functions ============

/**
* @notice Returns the list of strategies that the AVS supports for restaking
* @dev This function is intended to be called off-chain
Expand All @@ -72,22 +81,50 @@ contract HyperlaneServiceManager is IServiceManager, OwnableUpgradeable {
view
returns (address[] memory)
{
// TODO
return new address[](0);
return _getRestakeableStrategies();
}

/**
* @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
* @dev This function is intended to be called off-chain
* @dev Since ECDSAStakeRegistry only supports one quorum, each operator restakes into all the AVS strategies
* @dev No guarantee is made on uniqueness of each element in the returned array.
* The off-chain service should do that validation separately
*/
function getOperatorRestakedStrategies(
address operator
address /* operator */
) external view returns (address[] memory) {
// TODO
return new address[](0);
return _getRestakeableStrategies();
}

/// @notice Returns the EigenLayer AVSDirectory contract.
function avsDirectory() external view override returns (address) {
return address(elAvsDirectory);
}

// ============ Internal Function ============

function _getRestakeableStrategies()
internal
view
returns (address[] memory)
{
uint256 strategyCount = stakeRegistry.quorum().strategies.length;

if (strategyCount == 0) {
return new address[](0);
}

address[] memory restakedStrategies = new address[](strategyCount);
for (uint256 i = 0; i < strategyCount; i++) {
restakedStrategies[i] = address(
stakeRegistry.quorum().strategies[i].strategy
);
}
return restakedStrategies;
}

// storage gap for upgradeability
// slither-disable-next-line shadowing-state
uint256[50] private __GAP;
Expand Down

0 comments on commit 2158670

Please sign in to comment.