-
Notifications
You must be signed in to change notification settings - Fork 94
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
feat: ecdsa service manager #234
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1981567
feat: add ecdsa service manager
stevennevins c47ae91
feat: split up signature checking from stake regsitry
stevennevins cef2c14
feat(wip): add external calls to stake registry from signature checker
stevennevins 8f577d4
test: setup signature checker unit tests
stevennevins 2660822
Merge branch 'dev' into feat/ecdsa-service-manager
stevennevins c26e039
feat: add ui related function implementations
stevennevins 7f142d9
chore: remove separating signature checker for now
stevennevins fae025b
chore: remove unused test file
stevennevins 0518e6f
docs: add natspec and inherit doc for clarity
stevennevins ce96f47
docs: add more natspec documentation
stevennevins 7689c0c
refactor: update logic to internal functions that are internal and vi…
stevennevins 0e52c3e
docs: add more documentation to the internal functions
stevennevins 8565487
chore: update external functions to also be overrideable
stevennevins 62059d0
Merge branch 'dev' into feat/ecdsa-service-manager
stevennevins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.12; | ||
|
||
import {OwnableUpgradeable} from "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol"; | ||
|
||
import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol"; | ||
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol"; | ||
|
||
import {IServiceManager} from "../interfaces/IServiceManager.sol"; | ||
import {IServiceManagerUI} from "../interfaces/IServiceManagerUI.sol"; | ||
import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol"; | ||
import {IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategy.sol"; | ||
import {IStakeRegistry} from "../interfaces/IStakeRegistry.sol"; | ||
import {IPaymentCoordinator} from "eigenlayer-contracts/src/contracts/interfaces/IPaymentCoordinator.sol"; | ||
import {Quorum} from "../interfaces/IECDSAStakeRegistryEventsAndErrors.sol"; | ||
import {ECDSAStakeRegistry} from "../unaudited/ECDSAStakeRegistry.sol"; | ||
|
||
abstract contract ECDSAServiceManagerBase is | ||
IServiceManager, | ||
OwnableUpgradeable | ||
{ | ||
/// @notice Address of the stake registry contract, which manages registration and stake recording. | ||
address public immutable stakeRegistry; | ||
|
||
/// @notice Address of the AVS directory contract, which manages AVS-related data for registered operators. | ||
address public immutable avsDirectory; | ||
|
||
/// @notice Address of the payment coordinator contract, which handles payment distributions. | ||
address internal immutable paymentCoordinator; | ||
|
||
/// @notice Address of the delegation manager contract, which manages staker delegations to operators. | ||
address internal immutable delegationManager; | ||
/** | ||
* @dev Ensures that the function is only callable by the `stakeRegistry` contract. | ||
* This is used to restrict certain registration and deregistration functionality to the `stakeRegistry` | ||
*/ | ||
modifier onlyStakeRegistry() { | ||
require( | ||
msg.sender == stakeRegistry, | ||
"ECDSAServiceManagerBase.onlyStakeRegistry: caller is not the stakeRegistry" | ||
); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Constructor for ECDSAServiceManagerBase, initializing immutable contract addresses and disabling initializers. | ||
* @param _avsDirectory The address of the AVS directory contract, managing AVS-related data for registered operators. | ||
* @param _stakeRegistry The address of the stake registry contract, managing registration and stake recording. | ||
* @param _paymentCoordinator The address of the payment coordinator contract, handling payment distributions. | ||
* @param _delegationManager The address of the delegation manager contract, managing staker delegations to operators. | ||
*/ | ||
constructor( | ||
address _avsDirectory, | ||
address _stakeRegistry, | ||
address _paymentCoordinator, | ||
address _delegationManager | ||
) { | ||
avsDirectory = _avsDirectory; | ||
stakeRegistry = _stakeRegistry; | ||
paymentCoordinator = _paymentCoordinator; | ||
delegationManager = _delegationManager; | ||
_disableInitializers(); | ||
} | ||
|
||
/** | ||
* @dev Initializes the base service manager by transferring ownership to the initial owner. | ||
* @param initialOwner The address to which the ownership of the contract will be transferred. | ||
*/ | ||
function __ServiceManagerBase_init( | ||
address initialOwner | ||
) internal virtual onlyInitializing { | ||
_transferOwnership(initialOwner); | ||
} | ||
|
||
/// @inheritdoc IServiceManagerUI | ||
function updateAVSMetadataURI( | ||
string memory _metadataURI | ||
) external virtual onlyOwner { | ||
_updateAVSMetadataURI(_metadataURI); | ||
} | ||
|
||
/// @inheritdoc IServiceManager | ||
function payForRange( | ||
IPaymentCoordinator.RangePayment[] calldata rangePayments | ||
) external virtual onlyOwner { | ||
_payForRange(rangePayments); | ||
} | ||
|
||
/// @inheritdoc IServiceManagerUI | ||
function registerOperatorToAVS( | ||
address operator, | ||
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature | ||
) external virtual onlyStakeRegistry { | ||
_registerOperatorToAVS(operator, operatorSignature); | ||
} | ||
|
||
/// @inheritdoc IServiceManagerUI | ||
function deregisterOperatorFromAVS( | ||
address operator | ||
) external virtual onlyStakeRegistry { | ||
_deregisterOperatorFromAVS(operator); | ||
} | ||
|
||
/// @inheritdoc IServiceManagerUI | ||
function getRestakeableStrategies() | ||
external | ||
view | ||
virtual | ||
returns (address[] memory) | ||
{ | ||
return _getRestakeableStrategies(); | ||
} | ||
|
||
/// @inheritdoc IServiceManagerUI | ||
function getOperatorRestakedStrategies( | ||
address _operator | ||
) external view virtual returns (address[] memory) { | ||
return _getOperatorRestakedStrategies(_operator); | ||
} | ||
|
||
/** | ||
* @notice Forwards the call to update AVS metadata URI in the AVSDirectory contract. | ||
* @dev This internal function is a proxy to the `updateAVSMetadataURI` function of the AVSDirectory contract. | ||
* @param _metadataURI The new metadata URI to be set. | ||
*/ | ||
function _updateAVSMetadataURI( | ||
string memory _metadataURI | ||
) internal virtual { | ||
IAVSDirectory(avsDirectory).updateAVSMetadataURI(_metadataURI); | ||
} | ||
|
||
/** | ||
* @notice Forwards the call to register an operator in the AVSDirectory contract. | ||
* @dev This internal function is a proxy to the `registerOperatorToAVS` function of the AVSDirectory contract. | ||
* @param operator The address of the operator to register. | ||
* @param operatorSignature The signature, salt, and expiry details of the operator's registration. | ||
*/ | ||
function _registerOperatorToAVS( | ||
address operator, | ||
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature | ||
) internal virtual { | ||
IAVSDirectory(avsDirectory).registerOperatorToAVS( | ||
operator, | ||
operatorSignature | ||
); | ||
} | ||
|
||
/** | ||
* @notice Forwards the call to deregister an operator from the AVSDirectory contract. | ||
* @dev This internal function is a proxy to the `deregisterOperatorFromAVS` function of the AVSDirectory contract. | ||
* @param operator The address of the operator to deregister. | ||
*/ | ||
function _deregisterOperatorFromAVS(address operator) internal virtual { | ||
IAVSDirectory(avsDirectory).deregisterOperatorFromAVS(operator); | ||
} | ||
|
||
/** | ||
* @notice Processes a batch of range payments by transferring the specified amounts from the sender to this contract and then approving the PaymentCoordinator to use these amounts. | ||
* @dev This function handles the transfer and approval of tokens necessary for range payments. It then delegates the actual payment logic to the PaymentCoordinator contract. | ||
* @param rangePayments An array of `RangePayment` structs, each representing a payment for a specific range. | ||
*/ | ||
function _payForRange( | ||
IPaymentCoordinator.RangePayment[] calldata rangePayments | ||
) internal virtual { | ||
for (uint256 i = 0; i < rangePayments.length; ++i) { | ||
rangePayments[i].token.transferFrom( | ||
msg.sender, | ||
address(this), | ||
rangePayments[i].amount | ||
); | ||
rangePayments[i].token.approve( | ||
paymentCoordinator, | ||
rangePayments[i].amount | ||
); | ||
} | ||
|
||
IPaymentCoordinator(paymentCoordinator).payForRange(rangePayments); | ||
stevennevins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* @notice Retrieves the addresses of all strategies that are part of the current quorum. | ||
* @dev Fetches the quorum configuration from the ECDSAStakeRegistry and extracts the strategy addresses. | ||
* @return strategies An array of addresses representing the strategies in the current quorum. | ||
*/ | ||
function _getRestakeableStrategies() | ||
internal | ||
view | ||
virtual | ||
returns (address[] memory) | ||
{ | ||
Quorum memory quorum = ECDSAStakeRegistry(stakeRegistry).quorum(); | ||
address[] memory strategies = new address[](quorum.strategies.length); | ||
for (uint256 i = 0; i < quorum.strategies.length; i++) { | ||
strategies[i] = address(quorum.strategies[i].strategy); | ||
} | ||
return strategies; | ||
} | ||
|
||
/** | ||
* @notice Retrieves the addresses of strategies where the operator has restaked. | ||
* @dev This function fetches the quorum details from the ECDSAStakeRegistry, retrieves the operator's shares for each strategy, | ||
* and filters out strategies with non-zero shares indicating active restaking by the operator. | ||
* @param _operator The address of the operator whose restaked strategies are to be retrieved. | ||
* @return restakedStrategies An array of addresses of strategies where the operator has active restakes. | ||
*/ | ||
function _getOperatorRestakedStrategies( | ||
address _operator | ||
) internal view virtual returns (address[] memory) { | ||
Quorum memory quorum = ECDSAStakeRegistry(stakeRegistry).quorum(); | ||
uint256 count = quorum.strategies.length; | ||
IStrategy[] memory strategies = new IStrategy[](count); | ||
for (uint256 i; i < count; i++) { | ||
strategies[i] = quorum.strategies[i].strategy; | ||
} | ||
uint256[] memory shares = IDelegationManager(delegationManager) | ||
.getOperatorShares(_operator, strategies); | ||
|
||
address[] memory activeStrategies = new address[](count); | ||
uint256 activeCount; | ||
for (uint256 i; i < count; i++) { | ||
if (shares[i] > 0) { | ||
activeCount++; | ||
} | ||
} | ||
|
||
// Resize the array to fit only the active strategies | ||
address[] memory restakedStrategies = new address[](activeCount); | ||
for (uint256 j = 0; j < count; j++) { | ||
if (shares[j] > 0) { | ||
restakedStrategies[j] = activeStrategies[j]; | ||
} | ||
} | ||
|
||
return restakedStrategies; | ||
} | ||
|
||
// storage gap for upgradeability | ||
// slither-disable-next-line shadowing-state | ||
uint256[50] private __GAP; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont really understand how any of this is ECDSA specific
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming was to signal that it's associated with the ECDSAStakeRegistry