@@ -5,6 +5,7 @@ import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGra
5
5
import { IGraphToken } from "@graphprotocol/contracts/contracts/token/IGraphToken.sol " ;
6
6
import { IGraphTallyCollector } from "@graphprotocol/horizon/contracts/interfaces/IGraphTallyCollector.sol " ;
7
7
import { IRewardsIssuer } from "@graphprotocol/contracts/contracts/rewards/IRewardsIssuer.sol " ;
8
+ import { IDataService } from "@graphprotocol/horizon/contracts/data-service/interfaces/IDataService.sol " ;
8
9
import { ISubgraphService } from "./interfaces/ISubgraphService.sol " ;
9
10
10
11
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol " ;
@@ -71,15 +72,7 @@ contract SubgraphService is
71
72
_disableInitializers ();
72
73
}
73
74
74
- /**
75
- * @notice Initialize the contract
76
- * @dev The thawingPeriod and verifierCut ranges are not set here because they are variables
77
- * on the DisputeManager. We use the {ProvisionManager} overrideable getters to get the ranges.
78
- * @param owner The owner of the contract
79
- * @param minimumProvisionTokens The minimum amount of provisioned tokens required to create an allocation
80
- * @param maximumDelegationRatio The maximum delegation ratio allowed for an allocation
81
- * @param stakeToFeesRatio The ratio of stake to fees to lock when collecting query fees
82
- */
75
+ /// @inheritdoc ISubgraphService
83
76
function initialize (
84
77
address owner ,
85
78
uint256 minimumProvisionTokens ,
@@ -115,6 +108,7 @@ contract SubgraphService is
115
108
* - address `rewardsDestination`: The address where the indexer wants to receive indexing rewards.
116
109
* Use zero address for automatic reprovisioning to the subgraph service.
117
110
*/
111
+ /// @inheritdoc IDataService
118
112
function register (
119
113
address indexer ,
120
114
bytes calldata data
@@ -150,6 +144,7 @@ contract SubgraphService is
150
144
*
151
145
* @param indexer The address of the indexer to accept the provision for
152
146
*/
147
+ /// @inheritdoc IDataService
153
148
function acceptProvisionPendingParameters (
154
149
address indexer ,
155
150
bytes calldata
@@ -183,6 +178,7 @@ contract SubgraphService is
183
178
* - address `allocationId`: The id of the allocation
184
179
* - bytes `allocationProof`: Signed proof of the allocation id address ownership
185
180
*/
181
+ /// @inheritdoc IDataService
186
182
function startService (
187
183
address indexer ,
188
184
bytes calldata data
@@ -198,7 +194,7 @@ contract SubgraphService is
198
194
data,
199
195
(bytes32 , uint256 , address , bytes )
200
196
);
201
- _allocate (indexer, allocationId, subgraphDeploymentId, tokens, allocationProof, delegationRatio );
197
+ _allocate (indexer, allocationId, subgraphDeploymentId, tokens, allocationProof, _delegationRatio );
202
198
emit ServiceStarted (indexer, data);
203
199
}
204
200
@@ -221,6 +217,7 @@ contract SubgraphService is
221
217
* @param data Encoded data:
222
218
* - address `allocationId`: The id of the allocation
223
219
*/
220
+ /// @inheritdoc IDataService
224
221
function stopService (
225
222
address indexer ,
226
223
bytes calldata data
@@ -253,8 +250,8 @@ contract SubgraphService is
253
250
*
254
251
* @param indexer The address of the indexer
255
252
* @param paymentType The type of payment to collect as defined in {IGraphPayments}
256
- * @param data Encoded data to fulfill the payment. The structure of the data depends on the payment type. See above.
257
253
*/
254
+ /// @inheritdoc IDataService
258
255
function collect (
259
256
address indexer ,
260
257
IGraphPayments.PaymentTypes paymentType ,
@@ -283,7 +280,7 @@ contract SubgraphService is
283
280
_allocations.get (allocationId).indexer == indexer,
284
281
SubgraphServiceAllocationNotAuthorized (indexer, allocationId)
285
282
);
286
- paymentCollected = _collectIndexingRewards (allocationId, poi, delegationRatio );
283
+ paymentCollected = _collectIndexingRewards (allocationId, poi, _delegationRatio );
287
284
} else {
288
285
revert SubgraphServiceInvalidPaymentType (paymentType);
289
286
}
@@ -293,38 +290,26 @@ contract SubgraphService is
293
290
}
294
291
295
292
/**
296
- * @notice Slash an indexer
293
+ * @notice See {IHorizonStaking-slash} for more details.
297
294
* @dev Slashing is delegated to the {DisputeManager} contract which is the only one that can call this
298
295
* function.
299
- *
300
- * See {IHorizonStaking-slash} for more details.
301
- *
302
- * Emits a {ServiceProviderSlashed} event.
303
- *
304
- * @param indexer The address of the indexer to be slashed
305
- * @param data Encoded data:
306
- * - uint256 `tokens`: The amount of tokens to slash
307
- * - uint256 `reward`: The amount of tokens to reward the slasher
308
296
*/
297
+ /// @inheritdoc IDataService
309
298
function slash (address indexer , bytes calldata data ) external override onlyDisputeManager {
310
299
(uint256 tokens , uint256 reward ) = abi.decode (data, (uint256 , uint256 ));
311
300
_graphStaking ().slash (indexer, tokens, reward, address (_disputeManager ()));
312
301
emit ServiceProviderSlashed (indexer, tokens);
313
302
}
314
303
315
- /**
316
- * @notice See {ISubgraphService.closeStaleAllocation}
317
- */
304
+ /// @inheritdoc ISubgraphService
318
305
function closeStaleAllocation (address allocationId ) external override whenNotPaused {
319
306
Allocation.State memory allocation = _allocations.get (allocationId);
320
307
require (allocation.isStale (maxPOIStaleness), SubgraphServiceCannotForceCloseAllocation (allocationId));
321
308
require (! allocation.isAltruistic (), SubgraphServiceAllocationIsAltruistic (allocationId));
322
309
_closeAllocation (allocationId);
323
310
}
324
311
325
- /**
326
- * @notice See {ISubgraphService.resizeAllocation}
327
- */
312
+ /// @inheritdoc ISubgraphService
328
313
function resizeAllocation (
329
314
address indexer ,
330
315
address allocationId ,
@@ -340,12 +325,10 @@ contract SubgraphService is
340
325
_allocations.get (allocationId).indexer == indexer,
341
326
SubgraphServiceAllocationNotAuthorized (indexer, allocationId)
342
327
);
343
- _resizeAllocation (allocationId, tokens, delegationRatio );
328
+ _resizeAllocation (allocationId, tokens, _delegationRatio );
344
329
}
345
330
346
- /**
347
- * @notice See {ISubgraphService.migrateLegacyAllocation}
348
- */
331
+ /// @inheritdoc ISubgraphService
349
332
function migrateLegacyAllocation (
350
333
address indexer ,
351
334
address allocationId ,
@@ -354,79 +337,49 @@ contract SubgraphService is
354
337
_migrateLegacyAllocation (indexer, allocationId, subgraphDeploymentID);
355
338
}
356
339
357
- /**
358
- * @notice See {ISubgraphService.setPauseGuardian}
359
- */
340
+ /// @inheritdoc ISubgraphService
360
341
function setPauseGuardian (address pauseGuardian , bool allowed ) external override onlyOwner {
361
342
_setPauseGuardian (pauseGuardian, allowed);
362
343
}
363
344
364
- /**
365
- * @notice See {ISubgraphService.setRewardsDestination}
366
- */
345
+ /// @inheritdoc ISubgraphService
367
346
function setRewardsDestination (address rewardsDestination ) external override {
368
347
_setRewardsDestination (msg .sender , rewardsDestination);
369
348
}
370
349
371
- /**
372
- * @notice See {ISubgraphService.setMinimumProvisionTokens}
373
- */
350
+ /// @inheritdoc ISubgraphService
374
351
function setMinimumProvisionTokens (uint256 minimumProvisionTokens ) external override onlyOwner {
375
352
_setProvisionTokensRange (minimumProvisionTokens, DEFAULT_MAX_PROVISION_TOKENS);
376
353
}
377
354
378
- /**
379
- * @notice See {ISubgraphService.setDelegationRatio}
380
- */
355
+ /// @inheritdoc ISubgraphService
381
356
function setDelegationRatio (uint32 delegationRatio ) external override onlyOwner {
382
357
_setDelegationRatio (delegationRatio);
383
358
}
384
359
385
- /**
386
- * @notice See {ISubgraphService.setStakeToFeesRatio}
387
- */
360
+ /// @inheritdoc ISubgraphService
388
361
function setStakeToFeesRatio (uint256 stakeToFeesRatio_ ) external override onlyOwner {
389
362
_setStakeToFeesRatio (stakeToFeesRatio_);
390
363
}
391
364
392
- /**
393
- * @notice See {ISubgraphService.setMaxPOIStaleness}
394
- */
365
+ /// @inheritdoc ISubgraphService
395
366
function setMaxPOIStaleness (uint256 maxPOIStaleness ) external override onlyOwner {
396
367
_setMaxPOIStaleness (maxPOIStaleness);
397
368
}
398
369
399
- /**
400
- * @notice See {ISubgraphService.setCurationCut}
401
- */
370
+ /// @inheritdoc ISubgraphService
402
371
function setCurationCut (uint256 curationCut ) external override onlyOwner {
403
372
require (PPMMath.isValidPPM (curationCut), SubgraphServiceInvalidCurationCut (curationCut));
404
373
curationFeesCut = curationCut;
405
374
emit CurationCutSet (curationCut);
406
375
}
407
376
408
- /**
409
- * @notice See {ISubgraphService.getAllocation}
410
- */
377
+ /// @inheritdoc ISubgraphService
411
378
function getAllocation (address allocationId ) external view override returns (Allocation.State memory ) {
412
379
return _allocations[allocationId];
413
380
}
414
381
415
- /**
416
- * @notice Get allocation data to calculate rewards issuance
417
- * @dev Implements {IRewardsIssuer.getAllocationData}
418
- * @dev Note that this is slightly different than {getAllocation}. It returns an
419
- * unstructured subset of the allocation data, which is the minimum required to mint rewards.
420
- *
421
- * Should only be used by the {RewardsManager}.
422
- *
423
- * @param allocationId The allocation Id
424
- * @return indexer The indexer address
425
- * @return subgraphDeploymentId Subgraph deployment id for the allocation
426
- * @return tokens Amount of allocated tokens
427
- * @return accRewardsPerAllocatedToken Rewards snapshot
428
- * @return accRewardsPending Rewards pending to be minted due to allocation resize
429
- */
382
+ /// @inheritdoc IRewardsIssuer
430
383
function getAllocationData (
431
384
address allocationId
432
385
) external view override returns (address , bytes32 , uint256 , uint256 , uint256 ) {
@@ -440,57 +393,39 @@ contract SubgraphService is
440
393
);
441
394
}
442
395
443
- /**
444
- * @notice Return the total amount of tokens allocated to subgraph.
445
- * @dev Implements {IRewardsIssuer.getSubgraphAllocatedTokens}
446
- * @dev To be used by the {RewardsManager}.
447
- * @param subgraphDeploymentId Deployment Id for the subgraph
448
- * @return Total tokens allocated to subgraph
449
- */
396
+ /// @inheritdoc IRewardsIssuer
450
397
function getSubgraphAllocatedTokens (bytes32 subgraphDeploymentId ) external view override returns (uint256 ) {
451
398
return _subgraphAllocatedTokens[subgraphDeploymentId];
452
399
}
453
400
454
- /**
455
- * @notice See {ISubgraphService.getLegacyAllocation}
456
- */
401
+ /// @inheritdoc ISubgraphService
457
402
function getLegacyAllocation (address allocationId ) external view override returns (LegacyAllocation.State memory ) {
458
403
return _legacyAllocations[allocationId];
459
404
}
460
405
461
- /**
462
- * @notice See {ISubgraphService.getDisputeManager}
463
- */
406
+ /// @inheritdoc ISubgraphService
464
407
function getDisputeManager () external view override returns (address ) {
465
408
return address (_disputeManager ());
466
409
}
467
410
468
- /**
469
- * @notice See {ISubgraphService.getGraphTallyCollector}
470
- */
411
+ /// @inheritdoc ISubgraphService
471
412
function getGraphTallyCollector () external view override returns (address ) {
472
413
return address (_graphTallyCollector ());
473
414
}
474
415
475
- /**
476
- * @notice See {ISubgraphService.getCuration}
477
- */
416
+ /// @inheritdoc ISubgraphService
478
417
function getCuration () external view override returns (address ) {
479
418
return address (_curation ());
480
419
}
481
420
482
- /**
483
- * @notice See {ISubgraphService.encodeAllocationProof}
484
- */
421
+ /// @inheritdoc ISubgraphService
485
422
function encodeAllocationProof (address indexer , address allocationId ) external view override returns (bytes32 ) {
486
423
return _encodeAllocationProof (indexer, allocationId);
487
424
}
488
425
489
- /**
490
- * @notice See {ISubgraphService.isOverAllocated}
491
- */
426
+ /// @inheritdoc ISubgraphService
492
427
function isOverAllocated (address indexer ) external view override returns (bool ) {
493
- return _isOverAllocated (indexer, delegationRatio );
428
+ return _isOverAllocated (indexer, _delegationRatio );
494
429
}
495
430
496
431
// -- Data service parameter getters --
@@ -537,6 +472,7 @@ contract SubgraphService is
537
472
* Emits a {QueryFeesCollected} event.
538
473
*
539
474
* @param _signedRav Signed RAV
475
+ * @return feesCollected The amount of fees collected
540
476
*/
541
477
function _collectQueryFees (
542
478
IGraphTallyCollector.SignedRAV memory _signedRav
@@ -591,6 +527,10 @@ contract SubgraphService is
591
527
return tokensCollected;
592
528
}
593
529
530
+ /**
531
+ * @notice Set the stake to fees ratio.
532
+ * @param _stakeToFeesRatio The stake to fees ratio
533
+ */
594
534
function _setStakeToFeesRatio (uint256 _stakeToFeesRatio ) private {
595
535
require (_stakeToFeesRatio != 0 , SubgraphServiceInvalidZeroStakeToFeesRatio ());
596
536
stakeToFeesRatio = _stakeToFeesRatio;
0 commit comments