Skip to content

Commit 0d1f620

Browse files
committed
feat: rewards v2.2
1 parent 57c37ae commit 0d1f620

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

src/contracts/core/RewardsCoordinator.sol

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,27 @@ contract RewardsCoordinator is
203203
}
204204
}
205205

206+
/// @inheritdoc IRewardsCoordinator
207+
function createOperatorSetRewardsSubmission(
208+
OperatorSet calldata operatorSet,
209+
RewardsSubmission[] calldata rewardsSubmissions
210+
) external onlyWhenNotPaused(PAUSED_OPERATOR_SET_REWARDS_SUBMISSION) checkCanCall(operatorSet.avs) nonReentrant {
211+
require(allocationManager.isOperatorSet(operatorSet), InvalidOperatorSet());
212+
for (uint256 i = 0; i < rewardsSubmissions.length; i++) {
213+
RewardsSubmission calldata rewardsSubmission = rewardsSubmissions[i];
214+
uint256 nonce = submissionNonce[operatorSet.avs];
215+
bytes32 rewardsSubmissionHash = keccak256(abi.encode(operatorSet.avs, nonce, rewardsSubmission));
216+
217+
_validateRewardsSubmission(rewardsSubmission);
218+
219+
isOperatorSetRewardsSubmissionHash[operatorSet.avs][rewardsSubmissionHash] = true;
220+
submissionNonce[operatorSet.avs] = nonce + 1;
221+
222+
emit OperatorSetRewardsSubmissionCreated(msg.sender, rewardsSubmissionHash, operatorSet, nonce, rewardsSubmission);
223+
rewardsSubmission.token.safeTransferFrom(msg.sender, address(this), rewardsSubmission.amount);
224+
}
225+
}
226+
206227
/// @inheritdoc IRewardsCoordinator
207228
function processClaim(
208229
RewardsMerkleClaim calldata claim,

src/contracts/core/RewardsCoordinatorStorage.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ abstract contract RewardsCoordinatorStorage is IRewardsCoordinator {
3232
uint8 internal constant PAUSED_OPERATOR_SET_SPLIT = 8;
3333
/// @dev Index for flag that pauses calling setOperatorSetPerformanceRewardsSubmission
3434
uint8 internal constant PAUSED_OPERATOR_DIRECTED_OPERATOR_SET_REWARDS_SUBMISSION = 9;
35+
/// @dev Index for flag that pauses calling createOperatorSetRewardsSubmission
36+
uint8 internal constant PAUSED_OPERATOR_SET_REWARDS_SUBMISSION = 10;
3537

3638
/// @dev Salt for the earner leaf, meant to distinguish from tokenLeaf since they have the same sized data
3739
uint8 internal constant EARNER_LEAF_SALT = 0;
@@ -130,8 +132,10 @@ abstract contract RewardsCoordinatorStorage is IRewardsCoordinator {
130132
mapping(address avs => mapping(bytes32 hash => bool valid)) public
131133
isOperatorDirectedOperatorSetRewardsSubmissionHash;
132134

133-
// Construction
135+
/// @notice Returns whether a `hash` is a `valid` operator set rewards submission hash for a given `avs`.
136+
mapping(address avs => mapping(bytes32 hash => bool valid)) public isOperatorSetRewardsSubmissionHash;
134137

138+
// Construction
135139
constructor(
136140
IDelegationManager _delegationManager,
137141
IStrategyManager _strategyManager,
@@ -161,5 +165,5 @@ abstract contract RewardsCoordinatorStorage is IRewardsCoordinator {
161165
* variables without shifting down storage in the inheritance chain.
162166
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
163167
*/
164-
uint256[35] private __gap;
168+
uint256[34] private __gap;
165169
}

src/contracts/interfaces/IRewardsCoordinator.sol

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,22 @@ interface IRewardsCoordinatorEvents is IRewardsCoordinatorTypes {
333333
OperatorDirectedRewardsSubmission operatorDirectedRewardsSubmission
334334
);
335335

336+
/**
337+
* @notice Emitted when an AVS creates a valid `OperatorSetRewardsSubmission` for an operator set.
338+
* @param caller The address calling `createOperatorSetRewardsSubmission`.
339+
* @param rewardsSubmissionHash Keccak256 hash of (`avs`, `submissionNonce` and `rewardsSubmission`).
340+
* @param operatorSet The operatorSet on behalf of which the rewards are being submitted.
341+
* @param submissionNonce Current nonce of the avs. Used to generate a unique submission hash.
342+
* @param rewardsSubmission The Rewards Submission. Contains the token, start timestamp, duration, strategies and multipliers.
343+
*/
344+
event OperatorSetRewardsSubmissionCreated(
345+
address indexed caller,
346+
bytes32 indexed rewardsSubmissionHash,
347+
OperatorSet operatorSet,
348+
uint256 submissionNonce,
349+
RewardsSubmission rewardsSubmission
350+
);
351+
336352
/// @notice rewardsUpdater is responsible for submitting DistributionRoots, only owner can set rewardsUpdater
337353
event RewardsUpdaterSet(address indexed oldRewardsUpdater, address indexed newRewardsUpdater);
338354

@@ -515,6 +531,24 @@ interface IRewardsCoordinator is IRewardsCoordinatorErrors, IRewardsCoordinatorE
515531
OperatorDirectedRewardsSubmission[] calldata operatorDirectedRewardsSubmissions
516532
) external;
517533

534+
/**
535+
* @notice Creates a new rewards submission for an operator set, to be split amongst the operators and
536+
* set of stakers delegated to operators. The operators have to allocate slashable stake to the operator set to be rewarded.
537+
* @param operatorSet The operator set for which the rewards are being submitted
538+
* @param rewardsSubmissions The rewards submissions being created
539+
* @dev Expected to be called by the AVS that created the operator set
540+
* @dev The duration of the `rewardsSubmission` cannot exceed `MAX_REWARDS_DURATION`
541+
* @dev The duration of the `rewardsSubmission` cannot be 0 and must be a multiple of `CALCULATION_INTERVAL_SECONDS`
542+
* @dev The tokens are sent to the `RewardsCoordinator` contract
543+
* @dev The `RewardsCoordinator` contract needs a token approval of sum of all `strategies` in the `rewardsSubmissions`, before calling this function
544+
* @dev Strategies must be in ascending order of addresses to check for duplicates
545+
* @dev This function will revert if the `rewardsSubmissions` is malformed.
546+
*/
547+
function createOperatorSetRewardsSubmission(
548+
OperatorSet calldata operatorSet,
549+
RewardsSubmission[] calldata rewardsSubmissions
550+
) external;
551+
518552
/**
519553
* @notice Claim rewards against a given root (read from _distributionRoots[claim.rootIndex]).
520554
* Earnings are cumulative so earners don't have to claim against all distribution roots they have earnings for,

0 commit comments

Comments
 (0)