Skip to content

Commit

Permalink
feat: inheritdoc (#775)
Browse files Browse the repository at this point in the history
* feat: inheritdoc

* refactor: natspec/interface improvements

* feat: inheritdoc

* refactor: natspec/interface improvements
  • Loading branch information
0xClandestine authored Oct 2, 2024
1 parent 87daa10 commit 6f43c63
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 356 deletions.
34 changes: 6 additions & 28 deletions src/contracts/core/AVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ contract AVSDirectory is
*
*/

/**
* @notice Called by the AVS's service manager contract to register an operator with the avs.
* @param operator The address of the operator to register.
* @param operatorSignature The signature, salt, and expiry of the operator's signature.
*/
/// @inheritdoc IAVSDirectory
function registerOperatorToAVS(
address operator,
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature
Expand Down Expand Up @@ -107,10 +103,7 @@ contract AVSDirectory is
emit OperatorAVSRegistrationStatusUpdated(operator, msg.sender, OperatorAVSRegistrationStatus.REGISTERED);
}

/**
* @notice Called by an avs to deregister an operator with the avs.
* @param operator The address of the operator to deregister.
*/
/// @inheritdoc IAVSDirectory
function deregisterOperatorFromAVS(address operator)
external
onlyWhenNotPaused(PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS)
Expand All @@ -126,18 +119,12 @@ contract AVSDirectory is
emit OperatorAVSRegistrationStatusUpdated(operator, msg.sender, OperatorAVSRegistrationStatus.UNREGISTERED);
}

/**
* @notice Called by an avs to emit an `AVSMetadataURIUpdated` event indicating the information has updated.
* @param metadataURI The URI for metadata associated with an avs
*/
/// @inheritdoc IAVSDirectory
function updateAVSMetadataURI(string calldata metadataURI) external {
emit AVSMetadataURIUpdated(msg.sender, metadataURI);
}

/**
* @notice Called by an operator to cancel a salt that has been used to register with an AVS.
* @param salt A unique and single use value associated with the approver signature.
*/
/// @inheritdoc IAVSDirectory
function cancelSalt(bytes32 salt) external {
require(!operatorSaltIsSpent[msg.sender][salt], "AVSDirectory.cancelSalt: cannot cancel spent salt");
operatorSaltIsSpent[msg.sender][salt] = true;
Expand All @@ -149,13 +136,7 @@ contract AVSDirectory is
*
*/

/**
* @notice Calculates the digest hash to be signed by an operator to register with an AVS
* @param operator The account registering as an operator
* @param avs The address of the service manager contract for the AVS that the operator is registering to
* @param salt A unique and single use value associated with the approver signature.
* @param expiry Time after which the approver's signature becomes invalid
*/
/// @inheritdoc IAVSDirectory
function calculateOperatorAVSRegistrationDigestHash(
address operator,
address avs,
Expand All @@ -169,10 +150,7 @@ contract AVSDirectory is
return digestHash;
}

/**
* @notice Getter function for the current EIP-712 domain separator for this contract.
* @dev The domain separator will change in the event of a fork that changes the ChainID.
*/
/// @inheritdoc IAVSDirectory
function domainSeparator() public view returns (bytes32) {
if (block.chainid == ORIGINAL_CHAIN_ID) {
return _DOMAIN_SEPARATOR;
Expand Down
193 changes: 26 additions & 167 deletions src/contracts/core/DelegationManager.sol

Large diffs are not rendered by default.

110 changes: 21 additions & 89 deletions src/contracts/core/RewardsCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,7 @@ contract RewardsCoordinator is
*
*/

/**
* @notice Creates a new rewards submission on behalf of an AVS, to be split amongst the
* set of stakers delegated to operators who are registered to the `avs`
* @param rewardsSubmissions The rewards submissions being created
* @dev Expected to be called by the ServiceManager of the AVS on behalf of which the submission is being made
* @dev The duration of the `rewardsSubmission` cannot exceed `MAX_REWARDS_DURATION`
* @dev The tokens are sent to the `RewardsCoordinator` contract
* @dev Strategies must be in ascending order of addresses to check for duplicates
* @dev This function will revert if the `rewardsSubmission` is malformed,
* e.g. if the `strategies` and `weights` arrays are of non-equal lengths
*/
/// @inheritdoc IRewardsCoordinator
function createAVSRewardsSubmission(RewardsSubmission[] calldata rewardsSubmissions)
external
onlyWhenNotPaused(PAUSED_AVS_REWARDS_SUBMISSION)
Expand All @@ -148,12 +138,7 @@ contract RewardsCoordinator is
}
}

/**
* @notice similar to `createAVSRewardsSubmission` except the rewards are split amongst *all* stakers
* rather than just those delegated to operators who are registered to a single avs and is
* a permissioned call based on isRewardsForAllSubmitter mapping.
* @param rewardsSubmissions The rewards submissions being created
*/
/// @inheritdoc IRewardsCoordinator
function createRewardsForAllSubmission(RewardsSubmission[] calldata rewardsSubmissions)
external
onlyWhenNotPaused(PAUSED_REWARDS_FOR_ALL_SUBMISSION)
Expand All @@ -175,13 +160,7 @@ contract RewardsCoordinator is
}
}

/**
* @notice Creates a new rewards submission for all earners across all AVSs.
* Earners in this case indicating all operators and their delegated stakers. Undelegated stake
* is not rewarded from this RewardsSubmission. This interface is only callable
* by the token hopper contract from the Eigen Foundation
* @param rewardsSubmissions The rewards submissions being created
*/
/// @inheritdoc IRewardsCoordinator
function createRewardsForAllEarners(RewardsSubmission[] calldata rewardsSubmissions)
external
onlyWhenNotPaused(PAUSED_REWARD_ALL_STAKERS_AND_OPERATORS)
Expand All @@ -205,18 +184,7 @@ contract RewardsCoordinator is
}
}

/**
* @notice Claim rewards against a given root (read from _distributionRoots[claim.rootIndex]).
* Earnings are cumulative so earners don't have to claim against all distribution roots they have earnings for,
* they can simply claim against the latest root and the contract will calculate the difference between
* their cumulativeEarnings and cumulativeClaimed. This difference is then transferred to recipient address.
* @param claim The RewardsMerkleClaim to be processed.
* Contains the root index, earner, token leaves, and required proofs
* @param recipient The address recipient that receives the ERC20 rewards
* @dev only callable by the valid claimer, that is
* if claimerFor[claim.earner] is address(0) then only the earner can claim, otherwise only
* claimerFor[claim.earner] can claim the rewards.
*/
/// @inheritdoc IRewardsCoordinator
function processClaim(
RewardsMerkleClaim calldata claim,
address recipient
Expand Down Expand Up @@ -248,12 +216,7 @@ contract RewardsCoordinator is
}
}

/**
* @notice Creates a new distribution root. activatedAt is set to block.timestamp + activationDelay
* @param root The merkle root of the distribution
* @param rewardsCalculationEndTimestamp The timestamp until which rewards have been calculated
* @dev Only callable by the rewardsUpdater
*/
/// @inheritdoc IRewardsCoordinator
function submitRoot(
bytes32 root,
uint32 rewardsCalculationEndTimestamp
Expand All @@ -280,10 +243,7 @@ contract RewardsCoordinator is
emit DistributionRootSubmitted(rootIndex, root, rewardsCalculationEndTimestamp, activatedAt);
}

/**
* @notice allow the rewardsUpdater to disable/cancel a pending root submission in case of an error
* @param rootIndex The index of the root to be disabled
*/
/// @inheritdoc IRewardsCoordinator
function disableRoot(uint32 rootIndex) external onlyWhenNotPaused(PAUSED_SUBMIT_DISABLE_ROOTS) onlyRewardsUpdater {
require(rootIndex < _distributionRoots.length, "RewardsCoordinator.disableRoot: invalid rootIndex");
DistributionRoot storage root = _distributionRoots[rootIndex];
Expand All @@ -293,51 +253,30 @@ contract RewardsCoordinator is
emit DistributionRootDisabled(rootIndex);
}

/**
* @notice Sets the address of the entity that can call `processClaim` on behalf of the earner (msg.sender)
* @param claimer The address of the entity that can call `processClaim` on behalf of the earner
* @dev Only callable by the `earner`
*/
/// @inheritdoc IRewardsCoordinator
function setClaimerFor(address claimer) external {
address earner = msg.sender;
address prevClaimer = claimerFor[earner];
claimerFor[earner] = claimer;
emit ClaimerForSet(earner, prevClaimer, claimer);
}

/**
* @notice Sets the delay in timestamp before a posted root can be claimed against
* @dev Only callable by the contract owner
* @param _activationDelay The new value for activationDelay
*/
/// @inheritdoc IRewardsCoordinator
function setActivationDelay(uint32 _activationDelay) external onlyOwner {
_setActivationDelay(_activationDelay);
}

/**
* @notice Sets the global commission for all operators across all avss
* @dev Only callable by the contract owner
* @param _globalCommissionBips The commission for all operators across all avss
*/
/// @inheritdoc IRewardsCoordinator
function setGlobalOperatorCommission(uint16 _globalCommissionBips) external onlyOwner {
_setGlobalOperatorCommission(_globalCommissionBips);
}

/**
* @notice Sets the permissioned `rewardsUpdater` address which can post new roots
* @dev Only callable by the contract owner
* @param _rewardsUpdater The address of the new rewardsUpdater
*/
/// @inheritdoc IRewardsCoordinator
function setRewardsUpdater(address _rewardsUpdater) external onlyOwner {
_setRewardsUpdater(_rewardsUpdater);
}

/**
* @notice Sets the permissioned `rewardsForAllSubmitter` address which can submit createRewardsForAllSubmission
* @dev Only callable by the contract owner
* @param _submitter The address of the rewardsForAllSubmitter
* @param _newValue The new value for isRewardsForAllSubmitter
*/
/// @inheritdoc IRewardsCoordinator
function setRewardsForAllSubmitter(address _submitter, bool _newValue) external onlyOwner {
bool prevValue = isRewardsForAllSubmitter[_submitter];
emit RewardsForAllSubmitterSet(_submitter, prevValue, _newValue);
Expand Down Expand Up @@ -521,44 +460,43 @@ contract RewardsCoordinator is
*
*/

/// @notice return the hash of the earner's leaf
/// @inheritdoc IRewardsCoordinator
function calculateEarnerLeafHash(EarnerTreeMerkleLeaf calldata leaf) public pure returns (bytes32) {
return keccak256(abi.encodePacked(EARNER_LEAF_SALT, leaf.earner, leaf.earnerTokenRoot));
}

/// @notice returns the hash of the earner's token leaf
/// @inheritdoc IRewardsCoordinator
function calculateTokenLeafHash(TokenTreeMerkleLeaf calldata leaf) public pure returns (bytes32) {
return keccak256(abi.encodePacked(TOKEN_LEAF_SALT, leaf.token, leaf.cumulativeEarnings));
}

/// @notice returns 'true' if the claim would currently pass the check in `processClaims`
/// but will revert if not valid
/// @inheritdoc IRewardsCoordinator
function checkClaim(RewardsMerkleClaim calldata claim) public view returns (bool) {
_checkClaim(claim, _distributionRoots[claim.rootIndex]);
return true;
}

/// @notice the commission for a specific operator for a specific avs
/// NOTE: Currently unused and simply returns the globalOperatorCommissionBips value but will be used in future release
/// @inheritdoc IRewardsCoordinator
function operatorCommissionBips(address operator, address avs) external view returns (uint16) {
return globalOperatorCommissionBips;
}

/// @inheritdoc IRewardsCoordinator
function getDistributionRootsLength() public view returns (uint256) {
return _distributionRoots.length;
}

/// @inheritdoc IRewardsCoordinator
function getDistributionRootAtIndex(uint256 index) external view returns (DistributionRoot memory) {
return _distributionRoots[index];
}

/// @notice loop through the distribution roots from reverse and get latest root that is not disabled
/// @inheritdoc IRewardsCoordinator
function getCurrentDistributionRoot() external view returns (DistributionRoot memory) {
return _distributionRoots[_distributionRoots.length - 1];
}

/// @notice loop through the distribution roots from reverse and get latest root that is not disabled and activated
/// i.e. a root that can be claimed against
/// @inheritdoc IRewardsCoordinator
function getCurrentClaimableDistributionRoot() external view returns (DistributionRoot memory) {
for (uint256 i = _distributionRoots.length; i > 0; i--) {
DistributionRoot memory root = _distributionRoots[i - 1];
Expand All @@ -568,7 +506,7 @@ contract RewardsCoordinator is
}
}

/// @notice loop through distribution roots from reverse and return hash
/// @inheritdoc IRewardsCoordinator
function getRootIndexFromHash(bytes32 rootHash) public view returns (uint32) {
for (uint32 i = uint32(_distributionRoots.length); i > 0; i--) {
if (_distributionRoots[i - 1].root == rootHash) {
Expand All @@ -578,13 +516,7 @@ contract RewardsCoordinator is
revert("RewardsCoordinator.getRootIndexFromHash: root not found");
}

/**
* @notice Getter function for the current EIP-712 domain separator for this contract.
*
* @dev The domain separator will change in the event of a fork that changes the ChainID.
* @dev By introducing a domain separator the DApp developers are guaranteed that there can be no signature collision.
* for more detailed information please read EIP-712.
*/
/// @inheritdoc IRewardsCoordinator
function domainSeparator() public view returns (bytes32) {
if (block.chainid == ORIGINAL_CHAIN_ID) {
return _DOMAIN_SEPARATOR;
Expand Down
Loading

0 comments on commit 6f43c63

Please sign in to comment.