@@ -17,8 +17,17 @@ import "./IRewardsManager.sol";
1717 * towards each subgraph. Then each Subgraph can have multiple Indexers Staked on it. Thus, the
1818 * total rewards for the Subgraph are split up for each Indexer based on much they have Staked on
1919 * that Subgraph.
20+ *
21+ * Note:
22+ * The contract provides getter functions to query the state of accrued rewards:
23+ * - getAccRewardsPerSignal
24+ * - getAccRewardsForSubgraph
25+ * - getAccRewardsPerAllocatedToken
26+ * - getRewards
27+ * These functions may overestimate the actual rewards due to changes in the total supply
28+ * until the actual takeRewards function is called.
2029 */
21- contract RewardsManager is RewardsManagerV1Storage , GraphUpgradeable , IRewardsManager {
30+ contract RewardsManager is RewardsManagerV2Storage , GraphUpgradeable , IRewardsManager {
2231 using SafeMath for uint256 ;
2332
2433 uint256 private constant TOKEN_DECIMALS = 1e18 ;
@@ -66,6 +75,8 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
6675 _setIssuanceRate (_issuanceRate);
6776 }
6877
78+ // -- Config --
79+
6980 /**
7081 * @dev Sets the issuance rate.
7182 * The issuance rate is defined as a percentage increase of the total supply per block.
@@ -105,6 +116,24 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
105116 emit ParameterUpdated ("subgraphAvailabilityOracle " );
106117 }
107118
119+ /**
120+ * @dev Sets the minimum signaled tokens on a subgraph to start accruing rewards.
121+ * @dev Can be set to zero which means that this feature is not being used.
122+ * @param _minimumSubgraphSignal Minimum signaled tokens
123+ */
124+ function setMinimumSubgraphSignal (uint256 _minimumSubgraphSignal ) external override {
125+ // Caller can be the SAO or the governor
126+ require (
127+ msg .sender == address (subgraphAvailabilityOracle) ||
128+ msg .sender == controller.getGovernor (),
129+ "Not authorized "
130+ );
131+ minimumSubgraphSignal = _minimumSubgraphSignal;
132+ emit ParameterUpdated ("minimumSubgraphSignal " );
133+ }
134+
135+ // -- Denylist --
136+
108137 /**
109138 * @dev Denies to claim rewards for a subgraph.
110139 * NOTE: Can only be called by the subgraph availability oracle
@@ -150,11 +179,14 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
150179 /**
151180 * @dev Tells if subgraph is in deny list
152181 * @param _subgraphDeploymentID Subgraph deployment ID to check
182+ * @return Whether the subgraph is denied for claiming rewards or not
153183 */
154184 function isDenied (bytes32 _subgraphDeploymentID ) public view override returns (bool ) {
155185 return denylist[_subgraphDeploymentID] > 0 ;
156186 }
157187
188+ // -- Getters --
189+
158190 /**
159191 * @dev Gets the issuance of rewards per signal since last updated.
160192 *
@@ -205,6 +237,7 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
205237
206238 /**
207239 * @dev Gets the currently accumulated rewards per signal.
240+ * @return Currently accumulated rewards per signal
208241 */
209242 function getAccRewardsPerSignal () public view override returns (uint256 ) {
210243 return accRewardsPerSignal.add (getNewRewardsPerSignal ());
@@ -223,11 +256,16 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
223256 {
224257 Subgraph storage subgraph = subgraphs[_subgraphDeploymentID];
225258
226- uint256 newRewardsPerSignal = getAccRewardsPerSignal ().sub (
227- subgraph.accRewardsPerSignalSnapshot
228- );
259+ // Get tokens signalled on the subgraph
229260 uint256 subgraphSignalledTokens = curation ().getCurationPoolTokens (_subgraphDeploymentID);
230- uint256 newRewards = newRewardsPerSignal.mul (subgraphSignalledTokens).div (TOKEN_DECIMALS);
261+
262+ // Only accrue rewards if over a threshold
263+ uint256 newRewards = (subgraphSignalledTokens >= minimumSubgraphSignal) // Accrue new rewards since last snapshot
264+ ? getAccRewardsPerSignal ()
265+ .sub (subgraph.accRewardsPerSignalSnapshot)
266+ .mul (subgraphSignalledTokens)
267+ .div (TOKEN_DECIMALS)
268+ : 0 ;
231269 return subgraph.accRewardsForSubgraph.add (newRewards);
232270 }
233271
@@ -266,6 +304,8 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
266304 );
267305 }
268306
307+ // -- Updates --
308+
269309 /**
270310 * @dev Updates the accumulated rewards per signal and save checkpoint block number.
271311 * Must be called before `issuanceRate` or `total signalled GRT` changes
0 commit comments