@@ -60,6 +60,10 @@ library AllocationManagerLib {
60
60
* Emits a {AllocationCreated} event
61
61
*
62
62
* @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
63
67
*/
64
68
function allocate (
65
69
mapping (address allocationId = > Allocation.State allocation ) storage _allocations ,
@@ -103,6 +107,32 @@ library AllocationManagerLib {
103
107
);
104
108
}
105
109
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
+ */
106
136
function presentPOI (
107
137
mapping (address allocationId = > Allocation.State allocation ) storage _allocations ,
108
138
mapping (address indexer = > uint256 tokens ) storage allocationProvisionTracker ,
@@ -195,6 +225,22 @@ library AllocationManagerLib {
195
225
return tokensRewards;
196
226
}
197
227
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
+ */
198
244
function closeAllocation (
199
245
mapping (address allocationId = > Allocation.State allocation ) storage _allocations ,
200
246
mapping (address indexer = > uint256 tokens ) storage allocationProvisionTracker ,
@@ -302,6 +348,22 @@ library AllocationManagerLib {
302
348
return _isOverAllocated (allocationProvisionTracker, graphStaking, _indexer, _delegationRatio);
303
349
}
304
350
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
+ */
305
367
function _closeAllocation (
306
368
mapping (address allocationId = > Allocation.State allocation ) storage _allocations ,
307
369
mapping (address indexer = > uint256 tokens ) storage allocationProvisionTracker ,
@@ -335,6 +397,14 @@ library AllocationManagerLib {
335
397
);
336
398
}
337
399
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
+ */
338
408
function _isOverAllocated (
339
409
mapping (address indexer = > uint256 tokens ) storage allocationProvisionTracker ,
340
410
IHorizonStaking graphStaking ,
0 commit comments