Skip to content

Commit 4a72cdc

Browse files
f: remove linter warnings
1 parent 612dc73 commit 4a72cdc

File tree

6 files changed

+153
-143
lines changed

6 files changed

+153
-143
lines changed

IndexingPaymentsTodo.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Still pending
22

3-
* Remove linter warnings
43
* Remove extension if I can fit everything in one service?
54
* `require(provision.tokens != 0, DisputeManagerZeroTokens());` - Document or fix?
65
* Check code coverage

packages/horizon/contracts/data-service/libraries/DataServiceFeesLib.sol

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,12 @@ library DataServiceFeesLib {
1010
using ProvisionTracker for mapping(address => uint256);
1111
using LinkedList for LinkedList.List;
1212

13-
/**
14-
* @notice Builds a stake claim ID
15-
* @param serviceProvider The address of the service provider
16-
* @param nonce A nonce of the stake claim
17-
* @return The stake claim ID
18-
*/
19-
function _buildStakeClaimId(address serviceProvider, uint256 nonce) internal view returns (bytes32) {
20-
return keccak256(abi.encodePacked(address(this), serviceProvider, nonce));
21-
}
22-
13+
// @notice Storage structure for the data service fees library
2314
struct Storage {
2415
ProvisionManagerStorage provisionManagerStorage;
2516
}
2617

18+
// @notice Storage structure for the provision manager
2719
struct ProvisionManagerStorage {
2820
uint256 _minimumProvisionTokens;
2921
uint256 _maximumProvisionTokens;
@@ -75,6 +67,12 @@ library DataServiceFeesLib {
7567
emit IDataServiceFees.StakeClaimLocked(_serviceProvider, claimId, _tokens, _unlockTimestamp);
7668
}
7769

70+
/**
71+
* @notice Processes a stake claim, releasing the tokens if the claim has expired.
72+
* @dev This function is used as a callback in the stake claims linked list traversal.
73+
* @return Whether the stake claim is still locked, indicating that the traversal should continue or stop.
74+
* @return The updated accumulator data
75+
*/
7876
function processStakeClaim(
7977
mapping(address serviceProvider => uint256 tokens) storage feesProvisionTracker,
8078
mapping(bytes32 claimId => IDataServiceFees.StakeClaim claim) storage claims,
@@ -100,4 +98,14 @@ library DataServiceFeesLib {
10098
_acc = abi.encode(tokensClaimed + claim.tokens, serviceProvider);
10199
return (false, _acc);
102100
}
101+
102+
/**
103+
* @notice Builds a stake claim ID
104+
* @param serviceProvider The address of the service provider
105+
* @param nonce A nonce of the stake claim
106+
* @return The stake claim ID
107+
*/
108+
function _buildStakeClaimId(address serviceProvider, uint256 nonce) internal view returns (bytes32) {
109+
return keccak256(abi.encodePacked(address(this), serviceProvider, nonce));
110+
}
103111
}

packages/horizon/contracts/data-service/libraries/ProvisionTracker.sol

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ library ProvisionTracker {
2121
*/
2222
error ProvisionTrackerInsufficientTokens(uint256 tokensAvailable, uint256 tokensRequired);
2323

24+
/**
25+
* @notice Checks if a service provider has enough tokens available to lock
26+
* @param self The provision tracker mapping
27+
* @param graphStaking The HorizonStaking contract
28+
* @param serviceProvider The service provider address
29+
* @param delegationRatio A delegation ratio to limit the amount of delegation that's usable
30+
* @return true if the service provider has enough tokens available to lock, false otherwise
31+
*/
32+
function check(
33+
mapping(address => uint256) storage self,
34+
IHorizonStaking graphStaking,
35+
address serviceProvider,
36+
uint32 delegationRatio
37+
) external view returns (bool) {
38+
uint256 tokensAvailable = graphStaking.getTokensAvailable(serviceProvider, address(this), delegationRatio);
39+
return self[serviceProvider] <= tokensAvailable;
40+
}
41+
2442
/**
2543
* @notice Locks tokens for a service provider
2644
* @dev Requirements:
@@ -59,22 +77,4 @@ library ProvisionTracker {
5977
require(self[serviceProvider] >= tokens, ProvisionTrackerInsufficientTokens(self[serviceProvider], tokens));
6078
self[serviceProvider] -= tokens;
6179
}
62-
63-
/**
64-
* @notice Checks if a service provider has enough tokens available to lock
65-
* @param self The provision tracker mapping
66-
* @param graphStaking The HorizonStaking contract
67-
* @param serviceProvider The service provider address
68-
* @param delegationRatio A delegation ratio to limit the amount of delegation that's usable
69-
* @return true if the service provider has enough tokens available to lock, false otherwise
70-
*/
71-
function check(
72-
mapping(address => uint256) storage self,
73-
IHorizonStaking graphStaking,
74-
address serviceProvider,
75-
uint32 delegationRatio
76-
) external view returns (bool) {
77-
uint256 tokensAvailable = graphStaking.getTokensAvailable(serviceProvider, address(this), delegationRatio);
78-
return self[serviceProvider] <= tokensAvailable;
79-
}
8080
}

packages/subgraph-service/contracts/SubgraphService.sol

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ contract SubgraphService is
6060
_;
6161
}
6262

63-
function requireRegisteredIndexer(address indexer) external view {
64-
require(indexers[indexer].registeredAt != 0, SubgraphServiceIndexerNotRegistered(indexer));
65-
}
66-
6763
/**
6864
* @notice Constructor for the SubgraphService contract
6965
* @dev DataService and Directory constructors set a bunch of immutable variables
@@ -104,6 +100,35 @@ contract SubgraphService is
104100
_setStakeToFeesRatio(stakeToFeesRatio_);
105101
}
106102

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+
107132
/**
108133
* @notice
109134
* @dev Implements {IDataService.register}
@@ -393,6 +418,44 @@ contract SubgraphService is
393418
emit CurationCutSet(curationCut);
394419
}
395420

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+
396459
/// @inheritdoc ISubgraphService
397460
function getAllocation(address allocationId) external view override returns (Allocation.State memory) {
398461
return _allocations[allocationId];
@@ -448,6 +511,14 @@ contract SubgraphService is
448511
return _isOverAllocated(indexer, _delegationRatio);
449512
}
450513

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+
451522
/**
452523
* @notice Sets the payments destination for an indexer to receive payments
453524
* @dev Emits a {PaymentsDestinationSet} event
@@ -601,68 +672,6 @@ contract SubgraphService is
601672
return _presentPOI(allocationId, poi_, poiMetadata_, _delegationRatio, paymentsDestination[_indexer]);
602673
}
603674

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-
666675
/**
667676
* @notice Collect Indexing fees
668677
* Stake equal to the amount being collected times the `stakeToFeesRatio` is locked into a stake claim.
@@ -702,6 +711,16 @@ contract SubgraphService is
702711
return tokensCollected;
703712
}
704713

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+
705724
function _releaseAndLockStake(address _indexer, uint256 _tokensCollected) private {
706725
_releaseStake(_indexer, 0);
707726
if (_tokensCollected > 0) {
@@ -714,36 +733,17 @@ contract SubgraphService is
714733
}
715734
}
716735

717-
function getGraphStaking() external view returns (address) {
718-
return address(_graphStaking());
719-
}
720-
721736
/**
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
725742
*/
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]);
748748
}
749749
}

packages/subgraph-service/contracts/interfaces/ISubgraphService.sol

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ interface ISubgraphService is IDataServiceFees {
259259
*/
260260
function setPaymentsDestination(address paymentsDestination) external;
261261

262+
/**
263+
* @notice Accept an indexing agreement.
264+
* @dev Emits a {IndexingAgreement.IndexingAgreementAccepted} event
265+
* @param allocationId The id of the allocation
266+
* @param signedRCA The signed recurring collector agreement (RCA) that the indexer accepts
267+
*/
268+
function acceptIndexingAgreement(address allocationId, IRecurringCollector.SignedRCA calldata signedRCA) external;
269+
262270
/**
263271
* @notice Gets the details of an allocation
264272
* For legacy allocations use {getLegacyAllocation}
@@ -307,9 +315,4 @@ interface ISubgraphService is IDataServiceFees {
307315
* @return The address of the curation contract
308316
*/
309317
function getCuration() external view returns (address);
310-
311-
/**
312-
* @notice Accept an indexing agreement.
313-
*/
314-
function acceptIndexingAgreement(address allocationId, IRecurringCollector.SignedRCA calldata signedRCA) external;
315318
}

0 commit comments

Comments
 (0)