@@ -114,6 +114,15 @@ contract Curation is CurationV1Storage, GraphUpgradeable, ICuration, Governed {
114
114
emit ParameterUpdated ("staking " );
115
115
}
116
116
117
+ /**
118
+ * @dev Set the rewards manager contract.
119
+ * @param _rewardsManager Address of the rewards manager contract
120
+ */
121
+ function setRewardsManager (address _rewardsManager ) external override onlyGovernor {
122
+ rewardsManager = IRewardsManager (_rewardsManager);
123
+ emit ParameterUpdated ("rewardsManager " );
124
+ }
125
+
117
126
/**
118
127
* @dev Set the default reserve ratio percentage for a curation pool.
119
128
* @notice Update the default reserver ratio to `_defaultReserveRatio`
@@ -224,6 +233,9 @@ contract Curation is CurationV1Storage, GraphUpgradeable, ICuration, Governed {
224
233
"Cannot burn more signal than you own "
225
234
);
226
235
236
+ // Trigger update rewards calculation
237
+ _updateRewards (_subgraphDeploymentID);
238
+
227
239
// Update balance and get the amount of tokens to refund based on returned signal
228
240
(uint256 tokens , uint256 withdrawalFees ) = _burnSignal (
229
241
curator,
@@ -278,7 +290,7 @@ contract Curation is CurationV1Storage, GraphUpgradeable, ICuration, Governed {
278
290
/**
279
291
* @dev Get the amount of signal in a curation pool.
280
292
* @param _subgraphDeploymentID Subgraph deployment curation poool
281
- * @return Amount of signal owned by a curator for the subgraph deployment
293
+ * @return Amount of signal minted for the subgraph deployment
282
294
*/
283
295
function getCurationPoolSignal (bytes32 _subgraphDeploymentID )
284
296
public
@@ -292,6 +304,20 @@ contract Curation is CurationV1Storage, GraphUpgradeable, ICuration, Governed {
292
304
return pools[_subgraphDeploymentID].gst.totalSupply ();
293
305
}
294
306
307
+ /**
308
+ * @dev Get the amount of token reserves in a curation pool.
309
+ * @param _subgraphDeploymentID Subgraph deployment curation poool
310
+ * @return Amount of token reserves in the curation pool
311
+ */
312
+ function getCurationPoolTokens (bytes32 _subgraphDeploymentID )
313
+ public
314
+ override
315
+ view
316
+ returns (uint256 )
317
+ {
318
+ return pools[_subgraphDeploymentID].tokens;
319
+ }
320
+
295
321
/**
296
322
* @dev Calculate amount of signal that can be bought with tokens in a curation pool.
297
323
* @param _subgraphDeploymentID Subgraph deployment to mint signal
@@ -374,15 +400,18 @@ contract Curation is CurationV1Storage, GraphUpgradeable, ICuration, Governed {
374
400
bytes32 _subgraphDeploymentID ,
375
401
uint256 _tokens
376
402
) private returns (uint256 ) {
377
- CurationPool storage curationPool = pools[_subgraphDeploymentID];
378
403
uint256 signal = tokensToSignal (_subgraphDeploymentID, _tokens);
379
404
405
+ // Update curation pool
406
+ CurationPool storage curationPool = pools[_subgraphDeploymentID];
380
407
// Update GRT tokens held as reserves
381
408
curationPool.tokens = curationPool.tokens.add (_tokens);
382
-
383
409
// Mint signal to the curator
384
410
curationPool.gst.mint (_curator, signal);
385
411
412
+ // Update the global reserve
413
+ totalTokens = totalTokens.add (_tokens);
414
+
386
415
return signal;
387
416
}
388
417
@@ -398,15 +427,19 @@ contract Curation is CurationV1Storage, GraphUpgradeable, ICuration, Governed {
398
427
bytes32 _subgraphDeploymentID ,
399
428
uint256 _signal
400
429
) private returns (uint256 , uint256 ) {
401
- CurationPool storage curationPool = pools[_subgraphDeploymentID];
402
430
(uint256 tokens , uint256 withdrawalFees ) = signalToTokens (_subgraphDeploymentID, _signal);
431
+ uint256 outTokens = tokens.add (withdrawalFees);
403
432
433
+ // Update curation pool
434
+ CurationPool storage curationPool = pools[_subgraphDeploymentID];
404
435
// Update GRT tokens held as reserves
405
- curationPool.tokens = curationPool.tokens.sub (tokens.add (withdrawalFees));
406
-
436
+ curationPool.tokens = curationPool.tokens.sub (outTokens);
407
437
// Burn signal from curator
408
438
curationPool.gst.burnFrom (_curator, _signal);
409
439
440
+ // Update the global reserve
441
+ totalTokens = totalTokens.sub (outTokens);
442
+
410
443
return (tokens, withdrawalFees);
411
444
}
412
445
@@ -458,10 +491,24 @@ contract Curation is CurationV1Storage, GraphUpgradeable, ICuration, Governed {
458
491
}
459
492
}
460
493
461
- // Update balances
494
+ // Trigger update rewards calculation
495
+ _updateRewards (_subgraphDeploymentID);
496
+
497
+ // Exchange GRT tokens for GST of the subgraph pool
462
498
uint256 signal = _mintSignal (_curator, _subgraphDeploymentID, _tokens);
463
499
464
500
emit Signalled (_curator, _subgraphDeploymentID, _tokens, signal);
465
501
return signal;
466
502
}
503
+
504
+ /**
505
+ * @dev Triggers an update of rewards due to a change in signal.
506
+ * @param _subgraphDeploymentID Subgrapy deployment updated
507
+ */
508
+ function _updateRewards (bytes32 _subgraphDeploymentID ) internal returns (uint256 ) {
509
+ if (address (rewardsManager) != address (0 )) {
510
+ return rewardsManager.onSubgraphSignalUpdate (_subgraphDeploymentID);
511
+ }
512
+ return 0 ;
513
+ }
467
514
}
0 commit comments