@@ -60,10 +60,6 @@ contract SubgraphService is
60
60
_;
61
61
}
62
62
63
- function requireRegisteredIndexer (address indexer ) external view {
64
- require (indexers[indexer].registeredAt != 0 , SubgraphServiceIndexerNotRegistered (indexer));
65
- }
66
-
67
63
/**
68
64
* @notice Constructor for the SubgraphService contract
69
65
* @dev DataService and Directory constructors set a bunch of immutable variables
@@ -104,6 +100,35 @@ contract SubgraphService is
104
100
_setStakeToFeesRatio (stakeToFeesRatio_);
105
101
}
106
102
103
+ /**
104
+ * @notice Delegates the call to the SubgraphServiceExtension implementation.
105
+ * @dev This function does not return to its internal call site, it will return directly to the
106
+ * external caller.
107
+ */
108
+ // solhint-disable-next-line payable-fallback, no-complex-fallback
109
+ fallback () external {
110
+ address extImpl = _subgraphServiceExtensionImpl ();
111
+ require (extImpl != address (0 ), "only through proxy " );
112
+
113
+ // solhint-disable-next-line no-inline-assembly
114
+ assembly {
115
+ // copy function selector and any arguments
116
+ calldatacopy (0 , 0 , calldatasize ())
117
+ // execute function call using the extension implementation
118
+ let result := delegatecall (gas (), extImpl, 0 , calldatasize (), 0 , 0 )
119
+ // get any return value
120
+ returndatacopy (0 , 0 , returndatasize ())
121
+ // return any return value or error back to the caller
122
+ switch result
123
+ case 0 {
124
+ revert (0 , returndatasize ())
125
+ }
126
+ default {
127
+ return (0 , returndatasize ())
128
+ }
129
+ }
130
+ }
131
+
107
132
/**
108
133
* @notice
109
134
* @dev Implements {IDataService.register}
@@ -393,6 +418,44 @@ contract SubgraphService is
393
418
emit CurationCutSet (curationCut);
394
419
}
395
420
421
+ /**
422
+ * @notice Accept an indexing agreement.
423
+ * See {ISubgraphService.acceptIndexingAgreement}.
424
+ *
425
+ * Requirements:
426
+ * - The agreement's indexer must be registered
427
+ * - The caller must be authorized by the agreement's indexer
428
+ * - The provision must be valid according to the subgraph service rules
429
+ * - Allocation must belong to the indexer and be open
430
+ * - Agreement must be for this data service
431
+ * - Agreement's subgraph deployment must match the allocation's subgraph deployment
432
+ * - Agreement must not have been accepted before
433
+ * - Allocation must not have an agreement already
434
+ *
435
+ * @dev signedRCA.rca.metadata is an encoding of {IndexingAgreement.AcceptIndexingAgreementMetadata}
436
+ *
437
+ * Emits {IndexingAgreementAccepted} event
438
+ *
439
+ * @param allocationId The id of the allocation
440
+ * @param signedRCA The signed Recurring Collection Agreement
441
+ */
442
+ function acceptIndexingAgreement (
443
+ address allocationId ,
444
+ IRecurringCollector.SignedRCA calldata signedRCA
445
+ )
446
+ external
447
+ whenNotPaused
448
+ onlyAuthorizedForProvision (signedRCA.rca.serviceProvider)
449
+ onlyValidProvision (signedRCA.rca.serviceProvider)
450
+ onlyRegisteredIndexer (signedRCA.rca.serviceProvider)
451
+ {
452
+ IndexingAgreement._getManager ().accept (_allocations, allocationId, signedRCA);
453
+ }
454
+
455
+ function requireRegisteredIndexer (address indexer ) external view {
456
+ require (indexers[indexer].registeredAt != 0 , SubgraphServiceIndexerNotRegistered (indexer));
457
+ }
458
+
396
459
/// @inheritdoc ISubgraphService
397
460
function getAllocation (address allocationId ) external view override returns (Allocation.State memory ) {
398
461
return _allocations[allocationId];
@@ -448,6 +511,14 @@ contract SubgraphService is
448
511
return _isOverAllocated (indexer, _delegationRatio);
449
512
}
450
513
514
+ function getGraphStaking () external view returns (address ) {
515
+ return address (_graphStaking ());
516
+ }
517
+
518
+ function _cancelAllocationIndexingAgreement (address _allocationId ) internal {
519
+ IndexingAgreement._getManager ().cancelForAllocation (_allocationId);
520
+ }
521
+
451
522
/**
452
523
* @notice Sets the payments destination for an indexer to receive payments
453
524
* @dev Emits a {PaymentsDestinationSet} event
@@ -601,68 +672,6 @@ contract SubgraphService is
601
672
return _presentPOI (allocationId, poi_, poiMetadata_, _delegationRatio, paymentsDestination[_indexer]);
602
673
}
603
674
604
- /**
605
- * @notice Set the stake to fees ratio.
606
- * @param _stakeToFeesRatio The stake to fees ratio
607
- */
608
- function _setStakeToFeesRatio (uint256 _stakeToFeesRatio ) private {
609
- require (_stakeToFeesRatio != 0 , SubgraphServiceInvalidZeroStakeToFeesRatio ());
610
- stakeToFeesRatio = _stakeToFeesRatio;
611
- emit StakeToFeesRatioSet (_stakeToFeesRatio);
612
- }
613
-
614
- /**
615
- * @notice Encodes the data for the GraphTallyCollector
616
- * @dev The purpose of this function is just to avoid stack too deep errors
617
- * @param _signedRav The signed RAV
618
- * @param _curationCut The curation cut
619
- * @return The encoded data
620
- */
621
- function _encodeGraphTallyData (
622
- IGraphTallyCollector.SignedRAV memory _signedRav ,
623
- uint256 _curationCut
624
- ) private view returns (bytes memory ) {
625
- return abi.encode (_signedRav, _curationCut, paymentsDestination[_signedRav.rav.serviceProvider]);
626
- }
627
-
628
- function _cancelAllocationIndexingAgreement (address _allocationId ) internal {
629
- IndexingAgreement._getManager ().cancelForAllocation (_allocationId);
630
- }
631
-
632
- /**
633
- * @notice Accept an indexing agreement.
634
- * See {ISubgraphService.acceptIndexingAgreement}.
635
- *
636
- * Requirements:
637
- * - The agreement's indexer must be registered
638
- * - The caller must be authorized by the agreement's indexer
639
- * - The provision must be valid according to the subgraph service rules
640
- * - Allocation must belong to the indexer and be open
641
- * - Agreement must be for this data service
642
- * - Agreement's subgraph deployment must match the allocation's subgraph deployment
643
- * - Agreement must not have been accepted before
644
- * - Allocation must not have an agreement already
645
- *
646
- * @dev signedRCA.rca.metadata is an encoding of {IndexingAgreement.AcceptIndexingAgreementMetadata}
647
- *
648
- * Emits {IndexingAgreementAccepted} event
649
- *
650
- * @param allocationId The id of the allocation
651
- * @param signedRCA The signed Recurring Collection Agreement
652
- */
653
- function acceptIndexingAgreement (
654
- address allocationId ,
655
- IRecurringCollector.SignedRCA calldata signedRCA
656
- )
657
- external
658
- whenNotPaused
659
- onlyAuthorizedForProvision (signedRCA.rca.serviceProvider)
660
- onlyValidProvision (signedRCA.rca.serviceProvider)
661
- onlyRegisteredIndexer (signedRCA.rca.serviceProvider)
662
- {
663
- IndexingAgreement._getManager ().accept (_allocations, allocationId, signedRCA);
664
- }
665
-
666
675
/**
667
676
* @notice Collect Indexing fees
668
677
* Stake equal to the amount being collected times the `stakeToFeesRatio` is locked into a stake claim.
@@ -702,6 +711,16 @@ contract SubgraphService is
702
711
return tokensCollected;
703
712
}
704
713
714
+ /**
715
+ * @notice Set the stake to fees ratio.
716
+ * @param _stakeToFeesRatio The stake to fees ratio
717
+ */
718
+ function _setStakeToFeesRatio (uint256 _stakeToFeesRatio ) private {
719
+ require (_stakeToFeesRatio != 0 , SubgraphServiceInvalidZeroStakeToFeesRatio ());
720
+ stakeToFeesRatio = _stakeToFeesRatio;
721
+ emit StakeToFeesRatioSet (_stakeToFeesRatio);
722
+ }
723
+
705
724
function _releaseAndLockStake (address _indexer , uint256 _tokensCollected ) private {
706
725
_releaseStake (_indexer, 0 );
707
726
if (_tokensCollected > 0 ) {
@@ -714,36 +733,17 @@ contract SubgraphService is
714
733
}
715
734
}
716
735
717
- function getGraphStaking () external view returns (address ) {
718
- return address (_graphStaking ());
719
- }
720
-
721
736
/**
722
- * @notice Delegates the call to the SubgraphServiceExtension implementation.
723
- * @dev This function does not return to its internal call site, it will return directly to the
724
- * external caller.
737
+ * @notice Encodes the data for the GraphTallyCollector
738
+ * @dev The purpose of this function is just to avoid stack too deep errors
739
+ * @param _signedRav The signed RAV
740
+ * @param _curationCut The curation cut
741
+ * @return The encoded data
725
742
*/
726
- // solhint-disable-next-line payable-fallback, no-complex-fallback
727
- fallback () external {
728
- address extImpl = _subgraphServiceExtensionImpl ();
729
- require (extImpl != address (0 ), "only through proxy " );
730
-
731
- // solhint-disable-next-line no-inline-assembly
732
- assembly {
733
- // copy function selector and any arguments
734
- calldatacopy (0 , 0 , calldatasize ())
735
- // execute function call using the extension implementation
736
- let result := delegatecall (gas (), extImpl, 0 , calldatasize (), 0 , 0 )
737
- // get any return value
738
- returndatacopy (0 , 0 , returndatasize ())
739
- // return any return value or error back to the caller
740
- switch result
741
- case 0 {
742
- revert (0 , returndatasize ())
743
- }
744
- default {
745
- return (0 , returndatasize ())
746
- }
747
- }
743
+ function _encodeGraphTallyData (
744
+ IGraphTallyCollector.SignedRAV memory _signedRav ,
745
+ uint256 _curationCut
746
+ ) private view returns (bytes memory ) {
747
+ return abi.encode (_signedRav, _curationCut, paymentsDestination[_signedRav.rav.serviceProvider]);
748
748
}
749
749
}
0 commit comments