@@ -52,9 +52,9 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
52
52
event RewardsDenylistUpdated (bytes32 indexed subgraphDeploymentID , uint256 sinceBlock );
53
53
54
54
/**
55
- * @dev Emitted when a rewards issuer is updated.
55
+ * @dev Emitted when the subgraph service is set
56
56
*/
57
- event RewardsIssuerSet (address indexed rewardsIssuer , bool allowed );
57
+ event SubgraphServiceSet (address indexed oldSubgraphService , address indexed newSubgraphService );
58
58
59
59
// -- Modifiers --
60
60
@@ -121,9 +121,10 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
121
121
emit ParameterUpdated ("minimumSubgraphSignal " );
122
122
}
123
123
124
- function setRewardsIssuer (address _rewardsIssuer , bool _allowed ) external override onlyGovernor {
125
- rewardsIssuers[_rewardsIssuer] = _allowed;
126
- emit RewardsIssuerSet (_rewardsIssuer, _allowed);
124
+ function setSubgraphService (address _subgraphService ) external override onlyGovernor {
125
+ address oldSubgraphService = address (subgraphService);
126
+ subgraphService = IRewardsIssuer (_subgraphService);
127
+ emit SubgraphServiceSet (oldSubgraphService, _subgraphService);
127
128
}
128
129
129
130
// -- Denylist --
@@ -258,7 +259,19 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
258
259
subgraph.accRewardsForSubgraphSnapshot
259
260
);
260
261
261
- uint256 subgraphAllocatedTokens = staking ().getSubgraphAllocatedTokens (_subgraphDeploymentID);
262
+ // There are two contributors to subgraph allocated tokens:
263
+ // - the legacy allocations on the legacy staking contract
264
+ // - the new allocations on the subgraph service
265
+ uint256 subgraphAllocatedTokens = 0 ;
266
+ address [2 ] memory rewardsIssuers = [address (staking ()), address (subgraphService)];
267
+ for (uint256 i = 0 ; i < rewardsIssuers.length ; i++ ) {
268
+ if (rewardsIssuers[i] != address (0 )) {
269
+ subgraphAllocatedTokens += IRewardsIssuer (rewardsIssuers[i]).getSubgraphAllocatedTokens (
270
+ _subgraphDeploymentID
271
+ );
272
+ }
273
+ }
274
+
262
275
if (subgraphAllocatedTokens == 0 ) {
263
276
return (0 , accRewardsForSubgraph);
264
277
}
@@ -321,19 +334,35 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
321
334
322
335
/**
323
336
* @dev Calculate current rewards for a given allocation on demand.
337
+ * The allocation could be a legacy allocation or a new subgraph service allocation.
324
338
* @param _allocationID Allocation
325
339
* @return Rewards amount for an allocation
326
340
*/
327
341
function getRewards (address _allocationID ) external view override returns (uint256 ) {
328
- IStaking.AllocationState allocState = staking ().getAllocationState (_allocationID);
329
- if (allocState != IStakingBase.AllocationState.Active) {
342
+ address rewardsIssuer = address (0 );
343
+
344
+ // Check both the legacy and new allocations
345
+ address [2 ] memory rewardsIssuers = [address (staking ()), address (subgraphService)];
346
+ for (uint256 i = 0 ; i < rewardsIssuers.length ; i++ ) {
347
+ if (rewardsIssuers[i] != address (0 )) {
348
+ if (IRewardsIssuer (rewardsIssuers[i]).isActiveAllocation (_allocationID)) {
349
+ rewardsIssuer = address (rewardsIssuers[i]);
350
+ break ;
351
+ }
352
+ }
353
+ }
354
+
355
+ // Bail if allo does not exist
356
+ if (rewardsIssuer == address (0 )) {
330
357
return 0 ;
331
358
}
332
359
333
- IStaking.Allocation memory alloc = staking ().getAllocation (_allocationID);
360
+ (, bytes32 subgraphDeploymentId , uint256 tokens , uint256 alloAccRewardsPerAllocatedToken ) = IRewardsIssuer (
361
+ rewardsIssuer
362
+ ).getAllocationData (_allocationID);
334
363
335
- (uint256 accRewardsPerAllocatedToken , ) = getAccRewardsPerAllocatedToken (alloc.subgraphDeploymentID );
336
- return _calcRewards (alloc. tokens, alloc.accRewardsPerAllocatedToken , accRewardsPerAllocatedToken);
364
+ (uint256 accRewardsPerAllocatedToken , ) = getAccRewardsPerAllocatedToken (subgraphDeploymentId );
365
+ return _calcRewards (tokens, alloAccRewardsPerAllocatedToken , accRewardsPerAllocatedToken);
337
366
}
338
367
339
368
/**
@@ -354,14 +383,18 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
354
383
355
384
/**
356
385
* @dev Pull rewards from the contract for a particular allocation.
357
- * This function can only be called by the Staking contract.
386
+ * This function can only be called by an authorized rewards issuer which are
387
+ * the staking contract (for legacy allocations), and the subgraph service (for new allocations).
358
388
* This function will mint the necessary tokens to reward based on the inflation calculation.
359
389
* @param _allocationID Allocation
360
390
* @return Assigned rewards amount
361
391
*/
362
392
function takeRewards (address _allocationID ) external override returns (uint256 ) {
363
393
address rewardsIssuer = msg .sender ;
364
- require (rewardsIssuers[rewardsIssuer], "Caller must be a rewards issuer " );
394
+ require (
395
+ rewardsIssuer == address (staking ()) || rewardsIssuer == address (subgraphService),
396
+ "Caller must be a rewards issuer "
397
+ );
365
398
366
399
(
367
400
address indexer ,
0 commit comments