-
Notifications
You must be signed in to change notification settings - Fork 345
/
RewardsCoordinator.sol
602 lines (545 loc) · 27.2 KB
/
RewardsCoordinator.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;
import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../libraries/Merkle.sol";
import "../permissions/Pausable.sol";
import "./RewardsCoordinatorStorage.sol";
/**
* @title RewardsCoordinator
* @author Eigen Labs Inc.
* @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service
* @notice This is the contract for rewards in EigenLayer. The main functionalities of this contract are
* - enabling any ERC20 rewards from AVSs to their operators and stakers for a given time range
* - allowing stakers and operators to claim their earnings including a commission bips for operators
* - allowing the protocol to provide ERC20 tokens to stakers over a specified time range
*/
contract RewardsCoordinator is
Initializable,
OwnableUpgradeable,
Pausable,
ReentrancyGuardUpgradeable,
RewardsCoordinatorStorage
{
using SafeERC20 for IERC20;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 internal constant DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @dev Chain ID at the time of contract deployment
uint256 internal immutable ORIGINAL_CHAIN_ID;
/// @notice The maximum rewards token amount for a single rewards submission, constrained by off-chain calculation
uint256 internal constant MAX_REWARDS_AMOUNT = 1e38 - 1;
/// @dev Index for flag that pauses calling createAVSRewardsSubmission
uint8 internal constant PAUSED_AVS_REWARDS_SUBMISSION = 0;
/// @dev Index for flag that pauses calling createRewardsForAllSubmission
uint8 internal constant PAUSED_REWARDS_FOR_ALL_SUBMISSION = 1;
/// @dev Index for flag that pauses calling processClaim
uint8 internal constant PAUSED_PROCESS_CLAIM = 2;
/// @dev Index for flag that pauses submitRoots and disableRoot
uint8 internal constant PAUSED_SUBMIT_DISABLE_ROOTS = 3;
/// @dev Index for flag that pauses calling rewardAllStakersAndOperators
uint8 internal constant PAUSED_REWARD_ALL_STAKERS_AND_OPERATORS = 4;
/// @dev Salt for the earner leaf, meant to distinguish from tokenLeaf since they have the same sized data
uint8 internal constant EARNER_LEAF_SALT = 0;
/// @dev Salt for the token leaf, meant to distinguish from earnerLeaf since they have the same sized data
uint8 internal constant TOKEN_LEAF_SALT = 1;
/// @notice Canonical, virtual beacon chain ETH strategy
IStrategy public constant beaconChainETHStrategy = IStrategy(0xbeaC0eeEeeeeEEeEeEEEEeeEEeEeeeEeeEEBEaC0);
modifier onlyRewardsUpdater() {
require(msg.sender == rewardsUpdater, "RewardsCoordinator: caller is not the rewardsUpdater");
_;
}
modifier onlyRewardsForAllSubmitter() {
require(
isRewardsForAllSubmitter[msg.sender],
"RewardsCoordinator: caller is not a valid createRewardsForAllSubmission submitter"
);
_;
}
/// @dev Sets the immutable variables for the contract
constructor(
IDelegationManager _delegationManager,
IStrategyManager _strategyManager,
uint32 _CALCULATION_INTERVAL_SECONDS,
uint32 _MAX_REWARDS_DURATION,
uint32 _MAX_RETROACTIVE_LENGTH,
uint32 _MAX_FUTURE_LENGTH,
uint32 __GENESIS_REWARDS_TIMESTAMP
)
RewardsCoordinatorStorage(
_delegationManager,
_strategyManager,
_CALCULATION_INTERVAL_SECONDS,
_MAX_REWARDS_DURATION,
_MAX_RETROACTIVE_LENGTH,
_MAX_FUTURE_LENGTH,
__GENESIS_REWARDS_TIMESTAMP
)
{
_disableInitializers();
ORIGINAL_CHAIN_ID = block.chainid;
}
/**
* @dev Initializes the addresses of the initial owner, pauser registry, rewardsUpdater and
* configures the initial paused status, activationDelay, and globalOperatorCommissionBips.
*/
function initialize(
address initialOwner,
IPauserRegistry _pauserRegistry,
uint256 initialPausedStatus,
address _rewardsUpdater,
uint32 _activationDelay,
uint16 _globalCommissionBips
) external initializer {
_DOMAIN_SEPARATOR = _calculateDomainSeparator();
_initializePauser(_pauserRegistry, initialPausedStatus);
_transferOwnership(initialOwner);
_setRewardsUpdater(_rewardsUpdater);
_setActivationDelay(_activationDelay);
_setGlobalOperatorCommission(_globalCommissionBips);
}
/**
*
* EXTERNAL FUNCTIONS
*
*/
/**
* @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
*/
function createAVSRewardsSubmission(RewardsSubmission[] calldata rewardsSubmissions)
external
onlyWhenNotPaused(PAUSED_AVS_REWARDS_SUBMISSION)
nonReentrant
{
for (uint256 i = 0; i < rewardsSubmissions.length; i++) {
RewardsSubmission calldata rewardsSubmission = rewardsSubmissions[i];
uint256 nonce = submissionNonce[msg.sender];
bytes32 rewardsSubmissionHash = keccak256(abi.encode(msg.sender, nonce, rewardsSubmission));
_validateRewardsSubmission(rewardsSubmission);
isAVSRewardsSubmissionHash[msg.sender][rewardsSubmissionHash] = true;
submissionNonce[msg.sender] = nonce + 1;
emit AVSRewardsSubmissionCreated(msg.sender, nonce, rewardsSubmissionHash, rewardsSubmission);
rewardsSubmission.token.safeTransferFrom(msg.sender, address(this), rewardsSubmission.amount);
}
}
/**
* @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
*/
function createRewardsForAllSubmission(RewardsSubmission[] calldata rewardsSubmissions)
external
onlyWhenNotPaused(PAUSED_REWARDS_FOR_ALL_SUBMISSION)
onlyRewardsForAllSubmitter
nonReentrant
{
for (uint256 i = 0; i < rewardsSubmissions.length; i++) {
RewardsSubmission calldata rewardsSubmission = rewardsSubmissions[i];
uint256 nonce = submissionNonce[msg.sender];
bytes32 rewardsSubmissionForAllHash = keccak256(abi.encode(msg.sender, nonce, rewardsSubmission));
_validateRewardsSubmission(rewardsSubmission);
isRewardsSubmissionForAllHash[msg.sender][rewardsSubmissionForAllHash] = true;
submissionNonce[msg.sender] = nonce + 1;
emit RewardsSubmissionForAllCreated(msg.sender, nonce, rewardsSubmissionForAllHash, rewardsSubmission);
rewardsSubmission.token.safeTransferFrom(msg.sender, address(this), rewardsSubmission.amount);
}
}
/**
* @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
*/
function createRewardsForAllEarners(RewardsSubmission[] calldata rewardsSubmissions)
external
onlyWhenNotPaused(PAUSED_REWARD_ALL_STAKERS_AND_OPERATORS)
onlyRewardsForAllSubmitter
nonReentrant
{
for (uint256 i = 0; i < rewardsSubmissions.length; i++) {
RewardsSubmission calldata rewardsSubmission = rewardsSubmissions[i];
uint256 nonce = submissionNonce[msg.sender];
bytes32 rewardsSubmissionForAllEarnersHash = keccak256(abi.encode(msg.sender, nonce, rewardsSubmission));
_validateRewardsSubmission(rewardsSubmission);
isRewardsSubmissionForAllEarnersHash[msg.sender][rewardsSubmissionForAllEarnersHash] = true;
submissionNonce[msg.sender] = nonce + 1;
emit RewardsSubmissionForAllEarnersCreated(
msg.sender, nonce, rewardsSubmissionForAllEarnersHash, rewardsSubmission
);
rewardsSubmission.token.safeTransferFrom(msg.sender, address(this), rewardsSubmission.amount);
}
}
/**
* @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.
*/
function processClaim(
RewardsMerkleClaim calldata claim,
address recipient
) external onlyWhenNotPaused(PAUSED_PROCESS_CLAIM) nonReentrant {
DistributionRoot memory root = _distributionRoots[claim.rootIndex];
_checkClaim(claim, root);
// If claimerFor earner is not set, claimer is by default the earner. Else set to claimerFor
address earner = claim.earnerLeaf.earner;
address claimer = claimerFor[earner];
if (claimer == address(0)) {
claimer = earner;
}
require(msg.sender == claimer, "RewardsCoordinator.processClaim: caller is not valid claimer");
for (uint256 i = 0; i < claim.tokenIndices.length; i++) {
TokenTreeMerkleLeaf calldata tokenLeaf = claim.tokenLeaves[i];
uint256 currCumulativeClaimed = cumulativeClaimed[earner][tokenLeaf.token];
require(
tokenLeaf.cumulativeEarnings > currCumulativeClaimed,
"RewardsCoordinator.processClaim: cumulativeEarnings must be gt than cumulativeClaimed"
);
// Calculate amount to claim and update cumulativeClaimed
uint256 claimAmount = tokenLeaf.cumulativeEarnings - currCumulativeClaimed;
cumulativeClaimed[earner][tokenLeaf.token] = tokenLeaf.cumulativeEarnings;
tokenLeaf.token.safeTransfer(recipient, claimAmount);
emit RewardsClaimed(root.root, earner, claimer, recipient, tokenLeaf.token, claimAmount);
}
}
/**
* @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
*/
function submitRoot(
bytes32 root,
uint32 rewardsCalculationEndTimestamp
) external onlyWhenNotPaused(PAUSED_SUBMIT_DISABLE_ROOTS) onlyRewardsUpdater {
require(
rewardsCalculationEndTimestamp > currRewardsCalculationEndTimestamp,
"RewardsCoordinator.submitRoot: new root must be for newer calculated period"
);
require(
rewardsCalculationEndTimestamp < block.timestamp,
"RewardsCoordinator.submitRoot: rewardsCalculationEndTimestamp cannot be in the future"
);
uint32 rootIndex = uint32(_distributionRoots.length);
uint32 activatedAt = uint32(block.timestamp) + activationDelay;
_distributionRoots.push(
DistributionRoot({
root: root,
activatedAt: activatedAt,
rewardsCalculationEndTimestamp: rewardsCalculationEndTimestamp,
disabled: false
})
);
currRewardsCalculationEndTimestamp = rewardsCalculationEndTimestamp;
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
*/
function disableRoot(uint32 rootIndex) external onlyWhenNotPaused(PAUSED_SUBMIT_DISABLE_ROOTS) onlyRewardsUpdater {
require(rootIndex < _distributionRoots.length, "RewardsCoordinator.disableRoot: invalid rootIndex");
DistributionRoot storage root = _distributionRoots[rootIndex];
require(!root.disabled, "RewardsCoordinator.disableRoot: root already disabled");
require(block.timestamp < root.activatedAt, "RewardsCoordinator.disableRoot: root already activated");
root.disabled = true;
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`
*/
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
*/
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
*/
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
*/
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
*/
function setRewardsForAllSubmitter(address _submitter, bool _newValue) external onlyOwner {
bool prevValue = isRewardsForAllSubmitter[_submitter];
emit RewardsForAllSubmitterSet(_submitter, prevValue, _newValue);
isRewardsForAllSubmitter[_submitter] = _newValue;
}
/**
*
* INTERNAL FUNCTIONS
*
*/
/**
* @notice Validate a RewardsSubmission. Called from both `createAVSRewardsSubmission` and `createRewardsForAllSubmission`
*/
function _validateRewardsSubmission(RewardsSubmission calldata rewardsSubmission) internal view {
require(
rewardsSubmission.strategiesAndMultipliers.length > 0,
"RewardsCoordinator._validateRewardsSubmission: no strategies set"
);
require(rewardsSubmission.amount > 0, "RewardsCoordinator._validateRewardsSubmission: amount cannot be 0");
require(
rewardsSubmission.amount <= MAX_REWARDS_AMOUNT,
"RewardsCoordinator._validateRewardsSubmission: amount too large"
);
require(
rewardsSubmission.duration <= MAX_REWARDS_DURATION,
"RewardsCoordinator._validateRewardsSubmission: duration exceeds MAX_REWARDS_DURATION"
);
require(
rewardsSubmission.duration % CALCULATION_INTERVAL_SECONDS == 0,
"RewardsCoordinator._validateRewardsSubmission: duration must be a multiple of CALCULATION_INTERVAL_SECONDS"
);
require(
rewardsSubmission.startTimestamp % CALCULATION_INTERVAL_SECONDS == 0,
"RewardsCoordinator._validateRewardsSubmission: startTimestamp must be a multiple of CALCULATION_INTERVAL_SECONDS"
);
require(
block.timestamp - MAX_RETROACTIVE_LENGTH <= rewardsSubmission.startTimestamp
&& GENESIS_REWARDS_TIMESTAMP <= rewardsSubmission.startTimestamp,
"RewardsCoordinator._validateRewardsSubmission: startTimestamp too far in the past"
);
require(
rewardsSubmission.startTimestamp <= block.timestamp + MAX_FUTURE_LENGTH,
"RewardsCoordinator._validateRewardsSubmission: startTimestamp too far in the future"
);
// Require rewardsSubmission is for whitelisted strategy or beaconChainETHStrategy
address currAddress = address(0);
for (uint256 i = 0; i < rewardsSubmission.strategiesAndMultipliers.length; ++i) {
IStrategy strategy = rewardsSubmission.strategiesAndMultipliers[i].strategy;
require(
strategyManager.strategyIsWhitelistedForDeposit(strategy) || strategy == beaconChainETHStrategy,
"RewardsCoordinator._validateRewardsSubmission: invalid strategy considered"
);
require(
currAddress < address(strategy),
"RewardsCoordinator._validateRewardsSubmission: strategies must be in ascending order to handle duplicates"
);
currAddress = address(strategy);
}
}
function _checkClaim(RewardsMerkleClaim calldata claim, DistributionRoot memory root) internal view {
require(!root.disabled, "RewardsCoordinator._checkClaim: root is disabled");
require(block.timestamp >= root.activatedAt, "RewardsCoordinator._checkClaim: root not activated yet");
require(
claim.tokenIndices.length == claim.tokenTreeProofs.length,
"RewardsCoordinator._checkClaim: tokenIndices and tokenProofs length mismatch"
);
require(
claim.tokenTreeProofs.length == claim.tokenLeaves.length,
"RewardsCoordinator._checkClaim: tokenTreeProofs and leaves length mismatch"
);
// Verify inclusion of earners leaf (earner, earnerTokenRoot) in the distribution root
_verifyEarnerClaimProof({
root: root.root,
earnerLeafIndex: claim.earnerIndex,
earnerProof: claim.earnerTreeProof,
earnerLeaf: claim.earnerLeaf
});
// For each of the tokenLeaf proofs, verify inclusion of token tree leaf again the earnerTokenRoot
for (uint256 i = 0; i < claim.tokenIndices.length; ++i) {
_verifyTokenClaimProof({
earnerTokenRoot: claim.earnerLeaf.earnerTokenRoot,
tokenLeafIndex: claim.tokenIndices[i],
tokenProof: claim.tokenTreeProofs[i],
tokenLeaf: claim.tokenLeaves[i]
});
}
}
/**
* @notice verify inclusion of the token claim proof in the earner token root hash (earnerTokenRoot).
* The token leaf comprises of the IERC20 token and cumulativeAmount of earnings.
* @param earnerTokenRoot root hash of the earner token subtree
* @param tokenLeafIndex index of the token leaf
* @param tokenProof proof of the token leaf in the earner token subtree
* @param tokenLeaf token leaf to be verified
*/
function _verifyTokenClaimProof(
bytes32 earnerTokenRoot,
uint32 tokenLeafIndex,
bytes calldata tokenProof,
TokenTreeMerkleLeaf calldata tokenLeaf
) internal pure {
// Validate index size so that there aren't multiple valid indices for the given proof
// index can't be greater than 2**(tokenProof/32)
require(
tokenLeafIndex < (1 << (tokenProof.length / 32)),
"RewardsCoordinator._verifyTokenClaim: invalid tokenLeafIndex"
);
// Verify inclusion of token leaf
bytes32 tokenLeafHash = calculateTokenLeafHash(tokenLeaf);
require(
Merkle.verifyInclusionKeccak({
root: earnerTokenRoot,
index: tokenLeafIndex,
proof: tokenProof,
leaf: tokenLeafHash
}),
"RewardsCoordinator._verifyTokenClaim: invalid token claim proof"
);
}
/**
* @notice verify inclusion of earner claim proof in the distribution root. This verifies
* the inclusion of the earner and earnerTokenRoot hash in the tree. The token claims are proven separately
* against the earnerTokenRoot hash (see _verifyTokenClaimProof). The earner leaf comprises of (earner, earnerTokenRoot)
* @param root distribution root that should be read from storage
* @param earnerLeafIndex index of the earner leaf
* @param earnerProof proof of the earners account root in the merkle tree
* @param earnerLeaf leaf of earner merkle tree containing the earner address and earner's token root hash
*/
function _verifyEarnerClaimProof(
bytes32 root,
uint32 earnerLeafIndex,
bytes calldata earnerProof,
EarnerTreeMerkleLeaf calldata earnerLeaf
) internal pure {
// Validate index size so that there aren't multiple valid indices for the given proof
// index can't be greater than 2**(earnerProof/32)
require(
earnerLeafIndex < (1 << (earnerProof.length / 32)),
"RewardsCoordinator._verifyEarnerClaimProof: invalid earnerLeafIndex"
);
// Verify inclusion of earner leaf
bytes32 earnerLeafHash = calculateEarnerLeafHash(earnerLeaf);
// forgefmt: disable-next-item
require(
Merkle.verifyInclusionKeccak({
root: root,
index: earnerLeafIndex,
proof: earnerProof,
leaf: earnerLeafHash
}),
"RewardsCoordinator._verifyEarnerClaimProof: invalid earner claim proof"
);
}
function _setActivationDelay(uint32 _activationDelay) internal {
emit ActivationDelaySet(activationDelay, _activationDelay);
activationDelay = _activationDelay;
}
function _setGlobalOperatorCommission(uint16 _globalCommissionBips) internal {
emit GlobalCommissionBipsSet(globalOperatorCommissionBips, _globalCommissionBips);
globalOperatorCommissionBips = _globalCommissionBips;
}
function _setRewardsUpdater(address _rewardsUpdater) internal {
emit RewardsUpdaterSet(rewardsUpdater, _rewardsUpdater);
rewardsUpdater = _rewardsUpdater;
}
/**
*
* VIEW FUNCTIONS
*
*/
/// @notice return the hash of the earner's leaf
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
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
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
function operatorCommissionBips(address operator, address avs) external view returns (uint16) {
return globalOperatorCommissionBips;
}
function getDistributionRootsLength() public view returns (uint256) {
return _distributionRoots.length;
}
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
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
function getCurrentClaimableDistributionRoot() external view returns (DistributionRoot memory) {
for (uint256 i = _distributionRoots.length; i > 0; i--) {
DistributionRoot memory root = _distributionRoots[i - 1];
if (!root.disabled && block.timestamp >= root.activatedAt) {
return root;
}
}
}
/// @notice loop through distribution roots from reverse and return hash
function getRootIndexFromHash(bytes32 rootHash) public view returns (uint32) {
for (uint32 i = uint32(_distributionRoots.length); i > 0; i--) {
if (_distributionRoots[i - 1].root == rootHash) {
return i - 1;
}
}
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.
*/
function domainSeparator() public view returns (bytes32) {
if (block.chainid == ORIGINAL_CHAIN_ID) {
return _DOMAIN_SEPARATOR;
} else {
return _calculateDomainSeparator();
}
}
/**
* @dev Recalculates the domain separator when the chainid changes due to a fork.
*/
function _calculateDomainSeparator() internal view returns (bytes32) {
return keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes("EigenLayer")), block.chainid, address(this)));
}
}