@@ -17,8 +17,17 @@ import "./IRewardsManager.sol";
17
17
* towards each subgraph. Then each Subgraph can have multiple Indexers Staked on it. Thus, the
18
18
* total rewards for the Subgraph are split up for each Indexer based on much they have Staked on
19
19
* 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.
20
29
*/
21
- contract RewardsManager is RewardsManagerV1Storage , GraphUpgradeable , IRewardsManager {
30
+ contract RewardsManager is RewardsManagerV2Storage , GraphUpgradeable , IRewardsManager {
22
31
using SafeMath for uint256 ;
23
32
24
33
uint256 private constant TOKEN_DECIMALS = 1e18 ;
@@ -66,6 +75,8 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
66
75
_setIssuanceRate (_issuanceRate);
67
76
}
68
77
78
+ // -- Config --
79
+
69
80
/**
70
81
* @dev Sets the issuance rate.
71
82
* 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
105
116
emit ParameterUpdated ("subgraphAvailabilityOracle " );
106
117
}
107
118
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
+
108
137
/**
109
138
* @dev Denies to claim rewards for a subgraph.
110
139
* NOTE: Can only be called by the subgraph availability oracle
@@ -150,11 +179,14 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
150
179
/**
151
180
* @dev Tells if subgraph is in deny list
152
181
* @param _subgraphDeploymentID Subgraph deployment ID to check
182
+ * @return Whether the subgraph is denied for claiming rewards or not
153
183
*/
154
184
function isDenied (bytes32 _subgraphDeploymentID ) public view override returns (bool ) {
155
185
return denylist[_subgraphDeploymentID] > 0 ;
156
186
}
157
187
188
+ // -- Getters --
189
+
158
190
/**
159
191
* @dev Gets the issuance of rewards per signal since last updated.
160
192
*
@@ -205,6 +237,7 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
205
237
206
238
/**
207
239
* @dev Gets the currently accumulated rewards per signal.
240
+ * @return Currently accumulated rewards per signal
208
241
*/
209
242
function getAccRewardsPerSignal () public view override returns (uint256 ) {
210
243
return accRewardsPerSignal.add (getNewRewardsPerSignal ());
@@ -223,11 +256,16 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
223
256
{
224
257
Subgraph storage subgraph = subgraphs[_subgraphDeploymentID];
225
258
226
- uint256 newRewardsPerSignal = getAccRewardsPerSignal ().sub (
227
- subgraph.accRewardsPerSignalSnapshot
228
- );
259
+ // Get tokens signalled on the subgraph
229
260
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 ;
231
269
return subgraph.accRewardsForSubgraph.add (newRewards);
232
270
}
233
271
@@ -266,6 +304,8 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
266
304
);
267
305
}
268
306
307
+ // -- Updates --
308
+
269
309
/**
270
310
* @dev Updates the accumulated rewards per signal and save checkpoint block number.
271
311
* Must be called before `issuanceRate` or `total signalled GRT` changes
0 commit comments