Skip to content

Commit e0ed959

Browse files
f: inject currentEpoch
1 parent 0e203bc commit e0ed959

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

packages/horizon/contracts/utilities/GraphDirectory.sol

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,6 @@ abstract contract GraphDirectory {
131131
);
132132
}
133133

134-
/**
135-
* @notice Get the Epoch Manager contract
136-
* @return The Epoch Manager contract
137-
*/
138-
function graphEpochManager() external view returns (IEpochManager) {
139-
return _graphEpochManager();
140-
}
141-
142134
/**
143135
* @notice Get the Graph Token contract
144136
* @return The Graph Token contract

packages/horizon/test/unit/utilities/GraphDirectoryImplementation.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ contract GraphDirectoryImplementation is GraphDirectory {
4343
return _graphController();
4444
}
4545

46+
function graphEpochManager() external view returns (IEpochManager) {
47+
return _graphEpochManager();
48+
}
49+
4650
function graphRewardsManager() external view returns (IRewardsManager) {
4751
return _graphRewardsManager();
4852
}

packages/subgraph-service/contracts/SubgraphService.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,11 @@ contract SubgraphService is
682682
function _collectIndexingFees(bytes16 _agreementId, bytes memory _data) private returns (uint256) {
683683
(address indexer, uint256 tokensCollected) = IndexingAgreement._getManager().collect(
684684
_allocations,
685-
_agreementId,
686-
_data
685+
IndexingAgreement.CollectParams({
686+
agreementId: _agreementId,
687+
currentEpoch: _graphEpochManager().currentEpoch(),
688+
data: _data
689+
})
687690
);
688691

689692
_releaseAndLockStake(indexer, tokensCollected);

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ library IndexingAgreement {
7474
uint256 tokensPerEntityPerSecond;
7575
}
7676

77+
struct CollectParams {
78+
bytes16 agreementId;
79+
uint256 currentEpoch;
80+
bytes data;
81+
}
82+
7783
bytes32 private constant INDEXING_AGREEMENT_MANAGER_STORAGE_V1_SLOT = keccak256("v1.manager.indexing-agreement");
7884

7985
/**
@@ -323,32 +329,31 @@ library IndexingAgreement {
323329
function collect(
324330
Manager storage self,
325331
mapping(address allocationId => Allocation.State allocation) storage allocations,
326-
bytes16 agreementId,
327-
bytes memory data
332+
CollectParams memory params
328333
) external returns (address, uint256) {
329-
AgreementWrapper memory wrapper = _get(self, agreementId);
334+
AgreementWrapper memory wrapper = _get(self, params.agreementId);
330335
Allocation.State memory allocation = allocations.requireValidAllocation(
331336
wrapper.agreement.allocationId,
332337
wrapper.collectorAgreement.serviceProvider
333338
);
334-
require(_isActive(wrapper), IndexingAgreementNotActive(agreementId));
339+
require(_isActive(wrapper), IndexingAgreementNotActive(params.agreementId));
335340

336341
require(
337342
wrapper.agreement.version == IndexingAgreementVersion.V1,
338343
InvalidIndexingAgreementVersion(wrapper.agreement.version)
339344
);
340345

341-
(uint256 entities, bytes32 poi, uint256 poiEpoch) = Decoder.decodeCollectIndexingFeeDataV1(data);
346+
(uint256 entities, bytes32 poi, uint256 poiEpoch) = Decoder.decodeCollectIndexingFeeDataV1(params.data);
342347

343348
uint256 expectedTokens = (entities == 0 && poi == bytes32(0))
344349
? 0
345-
: _tokensToCollect(self, agreementId, wrapper.collectorAgreement, entities);
350+
: _tokensToCollect(self, params.agreementId, wrapper.collectorAgreement, entities);
346351

347352
uint256 tokensCollected = _directory().recurringCollector().collect(
348353
IGraphPayments.PaymentTypes.IndexingFee,
349354
abi.encode(
350355
IRecurringCollector.CollectParams({
351-
agreementId: agreementId,
356+
agreementId: params.agreementId,
352357
collectionId: bytes32(uint256(uint160(wrapper.agreement.allocationId))),
353358
tokens: expectedTokens,
354359
dataServiceCut: 0
@@ -359,10 +364,10 @@ library IndexingAgreement {
359364
emit IndexingFeesCollectedV1(
360365
wrapper.collectorAgreement.serviceProvider,
361366
wrapper.collectorAgreement.payer,
362-
agreementId,
367+
params.agreementId,
363368
wrapper.agreement.allocationId,
364369
allocation.subgraphDeploymentId,
365-
_graphDirectory().graphEpochManager().currentEpoch(),
370+
params.currentEpoch,
366371
tokensCollected,
367372
entities,
368373
poi,

0 commit comments

Comments
 (0)