Skip to content

Commit 7cb4a0c

Browse files
f: more NatSpec
1 parent 01c84d7 commit 7cb4a0c

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

packages/subgraph-service/contracts/DisputeManager.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ contract DisputeManager is
523523
* @param _agreementId The agreement id being disputed
524524
* @param _poi The POI being disputed
525525
* @param _entities The number of entities disputed
526+
* @param _blockNumber The block number of the disputed POI
526527
* @return The dispute id
527528
*/
528529
function _createIndexingFeeDisputeV1(

packages/subgraph-service/contracts/SubgraphService.sol

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ contract SubgraphService is
6767
* @param disputeManager The address of the DisputeManager contract
6868
* @param graphTallyCollector The address of the GraphTallyCollector contract
6969
* @param curation The address of the Curation contract
70+
* @param recurringCollector The address of the RecurringCollector contract
7071
*/
7172
constructor(
7273
address graphController,
@@ -394,7 +395,9 @@ contract SubgraphService is
394395
}
395396

396397
/**
398+
* @inheritdoc ISubgraphService
397399
* @notice Accept an indexing agreement.
400+
*
398401
* See {ISubgraphService.acceptIndexingAgreement}.
399402
*
400403
* Requirements:
@@ -428,7 +431,9 @@ contract SubgraphService is
428431
}
429432

430433
/**
434+
* @inheritdoc ISubgraphService
431435
* @notice Update an indexing agreement.
436+
*
432437
* See {IndexingAgreement.update}.
433438
*
434439
* Requirements:
@@ -452,7 +457,9 @@ contract SubgraphService is
452457
}
453458

454459
/**
460+
* @inheritdoc ISubgraphService
455461
* @notice Cancel an indexing agreement by indexer / operator.
462+
*
456463
* See {IndexingAgreement.cancel}.
457464
*
458465
* @dev Can only be canceled on behalf of a valid indexer.
@@ -478,7 +485,9 @@ contract SubgraphService is
478485
}
479486

480487
/**
488+
* @inheritdoc ISubgraphService
481489
* @notice Cancel an indexing agreement by payer / signer.
490+
*
482491
* See {ISubgraphService.cancelIndexingAgreementByPayer}.
483492
*
484493
* Requirements:
@@ -493,6 +502,7 @@ contract SubgraphService is
493502
IndexingAgreement._getStorageManager().cancelByPayer(agreementId);
494503
}
495504

505+
/// @inheritdoc ISubgraphService
496506
function getIndexingAgreement(
497507
bytes16 agreementId
498508
) external view returns (IndexingAgreement.AgreementWrapper memory) {
@@ -554,6 +564,12 @@ contract SubgraphService is
554564
return _isOverAllocated(indexer, _delegationRatio);
555565
}
556566

567+
/**
568+
* @notice Internal function to handle closing an allocation
569+
* @dev This function is called when an allocation is closed, either by the indexer or by a third party
570+
* @param _allocationId The id of the allocation being closed
571+
* @param _stale Whether the allocation is stale or not
572+
*/
557573
function _onCloseAllocation(address _allocationId, bool _stale) internal {
558574
IndexingAgreement._getStorageManager().onCloseAllocation(_allocationId, _stale);
559575
}
@@ -569,6 +585,10 @@ contract SubgraphService is
569585
emit PaymentsDestinationSet(_indexer, _paymentsDestination);
570586
}
571587

588+
/**
589+
* @notice Requires that the indexer is registered
590+
* @param _indexer The address of the indexer
591+
*/
572592
function _requireRegisteredIndexer(address _indexer) internal view {
573593
require(indexers[_indexer].registeredAt != 0, SubgraphServiceIndexerNotRegistered(_indexer));
574594
}
@@ -764,6 +784,13 @@ contract SubgraphService is
764784
emit StakeToFeesRatioSet(_stakeToFeesRatio);
765785
}
766786

787+
/**
788+
* @notice Release stake claims and lock new stake as economic security for fees
789+
* @dev This function releases all expired stake claims and locks new stake as economic security for fees.
790+
* It is called after collecting query fees or indexing fees.
791+
* @param _indexer The address of the indexer
792+
* @param _tokensCollected The amount of tokens collected from fees
793+
*/
767794
function _releaseAndLockStake(address _indexer, uint256 _tokensCollected) private {
768795
_releaseStake(_indexer, 0);
769796
if (_tokensCollected > 0) {

packages/subgraph-service/contracts/interfaces/IDisputeManager.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ interface IDisputeManager {
123123
* @param indexer The indexer address
124124
* @param fisherman The fisherman address
125125
* @param tokens The amount of tokens deposited by the fisherman
126+
* @param payer The address of the payer of the indexing fee
126127
* @param agreementId The agreement id
127128
* @param poi The POI disputed
128129
* @param entities The entities disputed

packages/subgraph-service/contracts/interfaces/ISubgraphService.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ interface ISubgraphService is IDataServiceFees {
290290
/**
291291
* @notice Get the indexing agreement for a given agreement ID.
292292
* @param agreementId The id of the indexing agreement
293+
* @return The indexing agreement details
293294
*/
294295
function getIndexingAgreement(
295296
bytes16 agreementId

packages/subgraph-service/contracts/libraries/AllocationManagerLib.sol

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ library AllocationManagerLib {
6060
* Emits a {AllocationCreated} event
6161
*
6262
* @param _allocations The mapping of allocation ids to allocation states
63+
* @param _legacyAllocations The mapping of legacy allocation ids to legacy allocation states
64+
* @param allocationProvisionTracker The mapping of indexers to their locked tokens
65+
* @param _subgraphAllocatedTokens The mapping of subgraph deployment ids to their allocated tokens
66+
* @param params The parameters for the allocation
6367
*/
6468
function allocate(
6569
mapping(address allocationId => Allocation.State allocation) storage _allocations,
@@ -103,6 +107,32 @@ library AllocationManagerLib {
103107
);
104108
}
105109

110+
/**
111+
* @notice Present a POI to collect indexing rewards for an allocation
112+
* This function will mint indexing rewards using the {RewardsManager} and distribute them to the indexer and delegators.
113+
*
114+
* Conditions to qualify for indexing rewards:
115+
* - POI must be non-zero
116+
* - POI must not be stale, i.e: older than `maxPOIStaleness`
117+
* - allocation must not be altruistic (allocated tokens = 0)
118+
* - allocation must be open for at least one epoch
119+
*
120+
* Note that indexers are required to periodically (at most every `maxPOIStaleness`) present POIs to collect rewards.
121+
* Rewards will not be issued to stale POIs, which means that indexers are advised to present a zero POI if they are
122+
* unable to present a valid one to prevent being locked out of future rewards.
123+
*
124+
* Note on allocation duration restriction: this is required to ensure that non protocol chains have a valid block number for
125+
* which to calculate POIs. EBO posts once per epoch typically at each epoch change, so we restrict rewards to allocations
126+
* that have gone through at least one epoch change.
127+
*
128+
* Emits a {IndexingRewardsCollected} event.
129+
*
130+
* @param _allocations The mapping of allocation ids to allocation states
131+
* @param allocationProvisionTracker The mapping of indexers to their locked tokens
132+
* @param _subgraphAllocatedTokens The mapping of subgraph deployment ids to their allocated tokens
133+
* @param params The parameters for the POI presentation
134+
* @return The amount of tokens collected
135+
*/
106136
function presentPOI(
107137
mapping(address allocationId => Allocation.State allocation) storage _allocations,
108138
mapping(address indexer => uint256 tokens) storage allocationProvisionTracker,
@@ -195,6 +225,22 @@ library AllocationManagerLib {
195225
return tokensRewards;
196226
}
197227

228+
/**
229+
* @notice Close an allocation
230+
* Does not require presenting a POI, use {_collectIndexingRewards} to present a POI and collect rewards
231+
* @dev Note that allocations are nowlong lived. All service payments, including indexing rewards, should be collected periodically
232+
* without the need of closing the allocation. Allocations should only be closed when indexers want to reclaim the allocated
233+
* tokens for other purposes.
234+
*
235+
* Emits a {AllocationClosed} event
236+
*
237+
* @param _allocations The mapping of allocation ids to allocation states
238+
* @param allocationProvisionTracker The mapping of indexers to their locked tokens
239+
* @param _subgraphAllocatedTokens The mapping of subgraph deployment ids to their allocated tokens
240+
* @param graphRewardsManager The rewards manager to handle rewards distribution
241+
* @param _allocationId The id of the allocation to be closed
242+
* @param _forceClosed Whether the allocation was force closed
243+
*/
198244
function closeAllocation(
199245
mapping(address allocationId => Allocation.State allocation) storage _allocations,
200246
mapping(address indexer => uint256 tokens) storage allocationProvisionTracker,
@@ -302,6 +348,22 @@ library AllocationManagerLib {
302348
return _isOverAllocated(allocationProvisionTracker, graphStaking, _indexer, _delegationRatio);
303349
}
304350

351+
/**
352+
* @notice Close an allocation
353+
* Does not require presenting a POI, use {_collectIndexingRewards} to present a POI and collect rewards
354+
* @dev Note that allocations are nowlong lived. All service payments, including indexing rewards, should be collected periodically
355+
* without the need of closing the allocation. Allocations should only be closed when indexers want to reclaim the allocated
356+
* tokens for other purposes.
357+
*
358+
* Emits a {AllocationClosed} event
359+
*
360+
* @param _allocations The mapping of allocation ids to allocation states
361+
* @param allocationProvisionTracker The mapping of indexers to their locked tokens
362+
* @param _subgraphAllocatedTokens The mapping of subgraph deployment ids to their allocated tokens
363+
* @param graphRewardsManager The rewards manager to handle rewards distribution
364+
* @param _allocationId The id of the allocation to be closed
365+
* @param _forceClosed Whether the allocation was force closed
366+
*/
305367
function _closeAllocation(
306368
mapping(address allocationId => Allocation.State allocation) storage _allocations,
307369
mapping(address indexer => uint256 tokens) storage allocationProvisionTracker,
@@ -335,6 +397,14 @@ library AllocationManagerLib {
335397
);
336398
}
337399

400+
/**
401+
* @notice Checks if an allocation is over-allocated
402+
* @param allocationProvisionTracker The mapping of indexers to their locked tokens
403+
* @param graphStaking The Horizon staking contract to check delegation ratios
404+
* @param _indexer The address of the indexer
405+
* @param _delegationRatio The delegation ratio to consider when locking tokens
406+
* @return True if the allocation is over-allocated, false otherwise
407+
*/
338408
function _isOverAllocated(
339409
mapping(address indexer => uint256 tokens) storage allocationProvisionTracker,
340410
IHorizonStaking graphStaking,

0 commit comments

Comments
 (0)