11// SPDX-License-Identifier: GPL-3.0-or-later
22pragma solidity 0.8.33 ;
33
4- import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol " ;
5- import { IRecurringCollector } from "@graphprotocol/horizon/contracts/interfaces/IRecurringCollector.sol " ;
4+ import { IGraphPayments } from "@graphprotocol/interfaces/contracts/horizon/IGraphPayments.sol " ;
5+ import { IRecurringCollector } from "@graphprotocol/interfaces/contracts/horizon/IRecurringCollector.sol " ;
6+ import { ISubgraphService } from "@graphprotocol/interfaces/contracts/subgraph-service/ISubgraphService.sol " ;
7+ import { IIndexingAgreement } from "@graphprotocol/interfaces/contracts/subgraph-service/internal/IIndexingAgreement.sol " ;
8+ import { IAllocation } from "@graphprotocol/interfaces/contracts/subgraph-service/internal/IAllocation.sol " ;
69
7- import { ISubgraphService } from "../interfaces/ISubgraphService.sol " ;
810import { AllocationHandler } from "../libraries/AllocationHandler.sol " ;
911import { Directory } from "../utilities/Directory.sol " ;
1012import { Allocation } from "./Allocation.sol " ;
1113import { IndexingAgreementDecoder } from "./IndexingAgreementDecoder.sol " ;
1214
1315library IndexingAgreement {
1416 using IndexingAgreement for StorageManager;
15- using Allocation for Allocation.State;
16- using Allocation for mapping (address => Allocation.State);
17-
18- /// @notice Versions of Indexing Agreement Metadata
19- enum IndexingAgreementVersion {
20- V1
21- }
22-
23- /**
24- * @notice Indexer Agreement Data
25- * @param allocationId The allocation ID
26- * @param version The indexing agreement version
27- */
28- struct State {
29- address allocationId;
30- IndexingAgreementVersion version;
31- }
32-
33- /**
34- * @notice Wrapper for Indexing Agreement and Collector Agreement Data
35- * @dev This struct is used to encapsulate the state of an indexing agreement
36- * @param agreement The indexing agreement state
37- * @param collectorAgreement The collector agreement data
38- */
39- struct AgreementWrapper {
40- State agreement;
41- IRecurringCollector.AgreementData collectorAgreement;
42- }
17+ using Allocation for IAllocation.State;
18+ using Allocation for mapping (address => IAllocation.State);
4319
4420 /**
4521 * @notice Accept Indexing Agreement metadata
@@ -49,7 +25,7 @@ library IndexingAgreement {
4925 */
5026 struct AcceptIndexingAgreementMetadata {
5127 bytes32 subgraphDeploymentId;
52- IndexingAgreementVersion version;
28+ IIndexingAgreement. IndexingAgreementVersion version;
5329 bytes terms;
5430 }
5531
@@ -59,7 +35,7 @@ library IndexingAgreement {
5935 * @param terms The indexing agreement terms
6036 */
6137 struct UpdateIndexingAgreementMetadata {
62- IndexingAgreementVersion version;
38+ IIndexingAgreement. IndexingAgreementVersion version;
6339 bytes terms;
6440 }
6541
@@ -118,7 +94,7 @@ library IndexingAgreement {
11894 * @custom:storage-location erc7201:graphprotocol.subgraph-service.storage.StorageManager.IndexingAgreement
11995 */
12096 struct StorageManager {
121- mapping (bytes16 => State) agreements;
97+ mapping (bytes16 => IIndexingAgreement. State) agreements;
12298 mapping (bytes16 agreementId = > IndexingAgreementTermsV1 data ) termsV1;
12399 mapping (address allocationId = > bytes16 agreementId ) allocationToActiveAgreementId;
124100 }
@@ -188,7 +164,7 @@ library IndexingAgreement {
188164 bytes16 indexed agreementId ,
189165 address allocationId ,
190166 bytes32 subgraphDeploymentId ,
191- IndexingAgreementVersion version ,
167+ IIndexingAgreement. IndexingAgreementVersion version ,
192168 bytes versionTerms
193169 );
194170
@@ -206,15 +182,15 @@ library IndexingAgreement {
206182 address indexed payer ,
207183 bytes16 indexed agreementId ,
208184 address allocationId ,
209- IndexingAgreementVersion version ,
185+ IIndexingAgreement. IndexingAgreementVersion version ,
210186 bytes versionTerms
211187 );
212188
213189 /**
214190 * @notice Thrown when trying to interact with an agreement with an invalid version
215191 * @param version The invalid version
216192 */
217- error IndexingAgreementInvalidVersion (IndexingAgreementVersion version );
193+ error IndexingAgreementInvalidVersion (IIndexingAgreement. IndexingAgreementVersion version );
218194
219195 /**
220196 * @notice Thrown when an agreement is not for the subgraph data service
@@ -301,11 +277,11 @@ library IndexingAgreement {
301277 */
302278 function accept (
303279 StorageManager storage self ,
304- mapping (address allocationId = > Allocation .State allocation ) storage allocations ,
280+ mapping (address allocationId = > IAllocation .State allocation ) storage allocations ,
305281 address allocationId ,
306282 IRecurringCollector.SignedRCA calldata signedRCA
307283 ) external returns (bytes16 ) {
308- Allocation .State memory allocation = _requireValidAllocation (
284+ IAllocation .State memory allocation = _requireValidAllocation (
309285 allocations,
310286 allocationId,
311287 signedRCA.rca.serviceProvider
@@ -328,7 +304,7 @@ library IndexingAgreement {
328304 signedRCA.rca.nonce
329305 );
330306
331- State storage agreement = self.agreements[agreementId];
307+ IIndexingAgreement. State storage agreement = self.agreements[agreementId];
332308
333309 require (agreement.allocationId == address (0 ), IndexingAgreementAlreadyAccepted (agreementId));
334310
@@ -351,7 +327,10 @@ library IndexingAgreement {
351327 agreement.version = metadata.version;
352328 agreement.allocationId = allocationId;
353329
354- require (metadata.version == IndexingAgreementVersion.V1, IndexingAgreementInvalidVersion (metadata.version));
330+ require (
331+ metadata.version == IIndexingAgreement.IndexingAgreementVersion.V1,
332+ IndexingAgreementInvalidVersion (metadata.version)
333+ );
355334 _setTermsV1 (self, agreementId, metadata.terms, signedRCA.rca.maxOngoingTokensPerSecond);
356335
357336 emit IndexingAgreementAccepted (
@@ -388,7 +367,7 @@ library IndexingAgreement {
388367 address indexer ,
389368 IRecurringCollector.SignedRCAU calldata signedRCAU
390369 ) external {
391- AgreementWrapper memory wrapper = _get (self, signedRCAU.rcau.agreementId);
370+ IIndexingAgreement. AgreementWrapper memory wrapper = _get (self, signedRCAU.rcau.agreementId);
392371 require (_isActive (wrapper), IndexingAgreementNotActive (signedRCAU.rcau.agreementId));
393372 require (
394373 wrapper.collectorAgreement.serviceProvider == indexer,
@@ -399,8 +378,14 @@ library IndexingAgreement {
399378 signedRCAU.rcau.metadata
400379 );
401380
402- require (wrapper.agreement.version == IndexingAgreementVersion.V1, "internal: invalid version " );
403- require (metadata.version == IndexingAgreementVersion.V1, IndexingAgreementInvalidVersion (metadata.version));
381+ require (
382+ wrapper.agreement.version == IIndexingAgreement.IndexingAgreementVersion.V1,
383+ "internal: invalid version "
384+ );
385+ require (
386+ metadata.version == IIndexingAgreement.IndexingAgreementVersion.V1,
387+ IndexingAgreementInvalidVersion (metadata.version)
388+ );
404389 _setTermsV1 (
405390 self,
406391 signedRCAU.rcau.agreementId,
@@ -436,7 +421,7 @@ library IndexingAgreement {
436421 * @param agreementId The id of the agreement to cancel
437422 */
438423 function cancel (StorageManager storage self , address indexer , bytes16 agreementId ) external {
439- AgreementWrapper memory wrapper = _get (self, agreementId);
424+ IIndexingAgreement. AgreementWrapper memory wrapper = _get (self, agreementId);
440425 require (_isActive (wrapper), IndexingAgreementNotActive (agreementId));
441426 require (
442427 wrapper.collectorAgreement.serviceProvider == indexer,
@@ -473,7 +458,7 @@ library IndexingAgreement {
473458 return ;
474459 }
475460
476- AgreementWrapper memory wrapper = _get (self, agreementId);
461+ IIndexingAgreement. AgreementWrapper memory wrapper = _get (self, agreementId);
477462 if (! _isActive (wrapper)) {
478463 return ;
479464 }
@@ -504,7 +489,7 @@ library IndexingAgreement {
504489 * @param agreementId The id of the agreement to cancel
505490 */
506491 function cancelByPayer (StorageManager storage self , bytes16 agreementId ) external {
507- AgreementWrapper memory wrapper = _get (self, agreementId);
492+ IIndexingAgreement. AgreementWrapper memory wrapper = _get (self, agreementId);
508493 require (_isActive (wrapper), IndexingAgreementNotActive (agreementId));
509494 require (
510495 _directory ().recurringCollector ().isAuthorized (wrapper.collectorAgreement.payer, msg .sender ),
@@ -540,11 +525,11 @@ library IndexingAgreement {
540525 */
541526 function collect (
542527 StorageManager storage self ,
543- mapping (address allocationId = > Allocation .State allocation ) storage allocations ,
528+ mapping (address allocationId = > IAllocation .State allocation ) storage allocations ,
544529 CollectParams memory params
545530 ) external returns (address , uint256 ) {
546- AgreementWrapper memory wrapper = _get (self, params.agreementId);
547- Allocation .State memory allocation = _requireValidAllocation (
531+ IIndexingAgreement. AgreementWrapper memory wrapper = _get (self, params.agreementId);
532+ IAllocation .State memory allocation = _requireValidAllocation (
548533 allocations,
549534 wrapper.agreement.allocationId,
550535 wrapper.collectorAgreement.serviceProvider
@@ -560,7 +545,7 @@ library IndexingAgreement {
560545 require (_isValid (wrapper) && isCollectable, IndexingAgreementNotCollectable (params.agreementId));
561546
562547 require (
563- wrapper.agreement.version == IndexingAgreementVersion.V1,
548+ wrapper.agreement.version == IIndexingAgreement. IndexingAgreementVersion.V1,
564549 IndexingAgreementInvalidVersion (wrapper.agreement.version)
565550 );
566551
@@ -610,8 +595,11 @@ library IndexingAgreement {
610595 * @param agreementId The id of the indexing agreement
611596 * @return The indexing agreement wrapper containing the agreement state and collector agreement data
612597 */
613- function get (StorageManager storage self , bytes16 agreementId ) external view returns (AgreementWrapper memory ) {
614- AgreementWrapper memory wrapper = _get (self, agreementId);
598+ function get (
599+ StorageManager storage self ,
600+ bytes16 agreementId
601+ ) external view returns (IIndexingAgreement.AgreementWrapper memory ) {
602+ IIndexingAgreement.AgreementWrapper memory wrapper = _get (self, agreementId);
615603 require (wrapper.collectorAgreement.dataService == address (this ), IndexingAgreementNotActive (agreementId));
616604
617605 return wrapper;
@@ -665,7 +653,7 @@ library IndexingAgreement {
665653 function _cancel (
666654 StorageManager storage _manager ,
667655 bytes16 _agreementId ,
668- State memory _agreement ,
656+ IIndexingAgreement. State memory _agreement ,
669657 IRecurringCollector.AgreementData memory _collectorAgreement ,
670658 IRecurringCollector.CancelAgreementBy _cancelBy
671659 ) private {
@@ -698,11 +686,11 @@ library IndexingAgreement {
698686 * @return The allocation state
699687 */
700688 function _requireValidAllocation (
701- mapping (address => Allocation .State) storage _allocations ,
689+ mapping (address => IAllocation .State) storage _allocations ,
702690 address _allocationId ,
703691 address _indexer
704- ) private view returns (Allocation .State memory ) {
705- Allocation .State memory allocation = _allocations.get (_allocationId);
692+ ) private view returns (IAllocation .State memory ) {
693+ IAllocation .State memory allocation = _allocations.get (_allocationId);
706694 require (
707695 allocation.indexer == _indexer,
708696 ISubgraphService.SubgraphServiceAllocationNotAuthorized (_indexer, _allocationId)
@@ -738,7 +726,7 @@ library IndexingAgreement {
738726 * @param wrapper The agreement wrapper containing the indexing agreement and collector agreement data
739727 * @return True if the agreement is active, false otherwise
740728 **/
741- function _isActive (AgreementWrapper memory wrapper ) private view returns (bool ) {
729+ function _isActive (IIndexingAgreement. AgreementWrapper memory wrapper ) private view returns (bool ) {
742730 return _isValid (wrapper) && wrapper.collectorAgreement.state == IRecurringCollector.AgreementState.Accepted;
743731 }
744732
@@ -759,7 +747,7 @@ library IndexingAgreement {
759747 * @param wrapper The agreement wrapper containing the indexing agreement and collector agreement data
760748 * @return True if the agreement is valid, false otherwise
761749 **/
762- function _isValid (AgreementWrapper memory wrapper ) private view returns (bool ) {
750+ function _isValid (IIndexingAgreement. AgreementWrapper memory wrapper ) private view returns (bool ) {
763751 return wrapper.collectorAgreement.dataService == address (this ) && wrapper.agreement.allocationId != address (0 );
764752 }
765753
@@ -778,9 +766,12 @@ library IndexingAgreement {
778766 * @param agreementId The id of the indexing agreement
779767 * @return The indexing agreement wrapper containing the agreement state and collector agreement data
780768 */
781- function _get (StorageManager storage self , bytes16 agreementId ) private view returns (AgreementWrapper memory ) {
769+ function _get (
770+ StorageManager storage self ,
771+ bytes16 agreementId
772+ ) private view returns (IIndexingAgreement.AgreementWrapper memory ) {
782773 return
783- AgreementWrapper ({
774+ IIndexingAgreement. AgreementWrapper ({
784775 agreement: self.agreements[agreementId],
785776 collectorAgreement: _directory ().recurringCollector ().getAgreement (agreementId)
786777 });
0 commit comments