@@ -316,6 +316,7 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
316316 /**
317317 * @dev Calculate current rewards for a given allocation on demand.
318318 * The allocation could be a legacy allocation or a new subgraph service allocation.
319+ * Returns 0 if the allocation is not active.
319320 * @param _allocationID Allocation
320321 * @return Rewards amount for an allocation
321322 */
@@ -326,13 +327,18 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
326327 );
327328
328329 (
330+ bool isActive ,
329331 ,
330332 bytes32 subgraphDeploymentId ,
331333 uint256 tokens ,
332334 uint256 alloAccRewardsPerAllocatedToken ,
333335 uint256 accRewardsPending
334336 ) = IRewardsIssuer (_rewardsIssuer).getAllocationData (_allocationID);
335337
338+ if (! isActive) {
339+ return 0 ;
340+ }
341+
336342 (uint256 accRewardsPerAllocatedToken , ) = getAccRewardsPerAllocatedToken (subgraphDeploymentId);
337343 return
338344 accRewardsPending.add (_calcRewards (tokens, alloAccRewardsPerAllocatedToken, accRewardsPerAllocatedToken));
@@ -372,6 +378,7 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
372378 * This function can only be called by an authorized rewards issuer which are
373379 * the staking contract (for legacy allocations), and the subgraph service (for new allocations).
374380 * This function will mint the necessary tokens to reward based on the inflation calculation.
381+ * Mints 0 tokens if the allocation is not active.
375382 * @param _allocationID Allocation
376383 * @return Assigned rewards amount
377384 */
@@ -383,6 +390,7 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
383390 );
384391
385392 (
393+ bool isActive ,
386394 address indexer ,
387395 bytes32 subgraphDeploymentID ,
388396 uint256 tokens ,
@@ -398,15 +406,18 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
398406 return 0 ;
399407 }
400408
401- // Calculate rewards accrued by this allocation
402- uint256 rewards = accRewardsPending.add (
403- _calcRewards (tokens, accRewardsPerAllocatedToken, updatedAccRewardsPerAllocatedToken)
404- );
405- if (rewards > 0 ) {
406- // Mint directly to rewards issuer for the reward amount
407- // The rewards issuer contract will do bookkeeping of the reward and
408- // assign in proportion to each stakeholder incentive
409- graphToken ().mint (rewardsIssuer, rewards);
409+ uint256 rewards = 0 ;
410+ if (isActive) {
411+ // Calculate rewards accrued by this allocation
412+ rewards = accRewardsPending.add (
413+ _calcRewards (tokens, accRewardsPerAllocatedToken, updatedAccRewardsPerAllocatedToken)
414+ );
415+ if (rewards > 0 ) {
416+ // Mint directly to rewards issuer for the reward amount
417+ // The rewards issuer contract will do bookkeeping of the reward and
418+ // assign in proportion to each stakeholder incentive
419+ graphToken ().mint (rewardsIssuer, rewards);
420+ }
410421 }
411422
412423 emit HorizonRewardsAssigned (indexer, _allocationID, rewards);
0 commit comments