@@ -5,16 +5,17 @@ import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGra
55import { IRecurringCollector } from "@graphprotocol/horizon/contracts/interfaces/IRecurringCollector.sol " ;
66import { GraphDirectory } from "@graphprotocol/horizon/contracts/utilities/GraphDirectory.sol " ;
77
8+ import { ISubgraphService } from "../interfaces/ISubgraphService.sol " ;
9+ import { AllocationManager } from "../utilities/AllocationManager.sol " ;
810import { SubgraphService } from "../SubgraphService.sol " ;
911import { Directory } from "../utilities/Directory.sol " ;
1012import { Allocation } from "./Allocation.sol " ;
11- import { SubgraphServiceLib } from "./SubgraphServiceLib.sol " ;
1213import { IndexingAgreementDecoder } from "./IndexingAgreementDecoder.sol " ;
1314
1415library IndexingAgreement {
1516 using IndexingAgreement for StorageManager;
17+ using Allocation for Allocation.State;
1618 using Allocation for mapping (address => Allocation.State);
17- using SubgraphServiceLib for mapping (address => Allocation.State);
1819
1920 /// @notice Versions of Indexing Agreement Metadata
2021 enum IndexingAgreementVersion {
@@ -287,7 +288,8 @@ library IndexingAgreement {
287288 address allocationId ,
288289 IRecurringCollector.SignedRCA calldata signedRCA
289290 ) external {
290- Allocation.State memory allocation = allocations.requireValidAllocation (
291+ Allocation.State memory allocation = _requireValidAllocation (
292+ allocations,
291293 allocationId,
292294 signedRCA.rca.serviceProvider
293295 );
@@ -512,7 +514,8 @@ library IndexingAgreement {
512514 CollectParams memory params
513515 ) external returns (address , uint256 ) {
514516 AgreementWrapper memory wrapper = _get (self, params.agreementId);
515- Allocation.State memory allocation = allocations.requireValidAllocation (
517+ Allocation.State memory allocation = _requireValidAllocation (
518+ allocations,
516519 wrapper.agreement.allocationId,
517520 wrapper.collectorAgreement.serviceProvider
518521 );
@@ -636,6 +639,33 @@ library IndexingAgreement {
636639 _directory ().recurringCollector ().cancel (_agreementId, _cancelBy);
637640 }
638641
642+ /**
643+ * @notice Requires that the allocation is valid and owned by the indexer.
644+ *
645+ * Requirements:
646+ * - Allocation must belong to the indexer
647+ * - Allocation must be open
648+ *
649+ * @param _allocations The mapping of allocation IDs to their states
650+ * @param _allocationId The id of the allocation
651+ * @param _indexer The address of the indexer
652+ * @return The allocation state
653+ */
654+ function _requireValidAllocation (
655+ mapping (address => Allocation.State) storage _allocations ,
656+ address _allocationId ,
657+ address _indexer
658+ ) private view returns (Allocation.State memory ) {
659+ Allocation.State memory allocation = _allocations.get (_allocationId);
660+ require (
661+ allocation.indexer == _indexer,
662+ ISubgraphService.SubgraphServiceAllocationNotAuthorized (_indexer, _allocationId)
663+ );
664+ require (allocation.isOpen (), AllocationManager.AllocationManagerAllocationClosed (_allocationId));
665+
666+ return allocation;
667+ }
668+
639669 /**
640670 * @notice Calculate the number of tokens to collect for an indexing agreement.
641671 *
0 commit comments