From 0defc8175553574f49bab7127f1cc4fa1dddfd35 Mon Sep 17 00:00:00 2001 From: Miguel de Elias Date: Mon, 16 Sep 2024 17:54:06 -0300 Subject: [PATCH 1/2] chore: add stakeToFeesRatio to SubgraphService initialize --- .../contracts/SubgraphService.sol | 18 ++++++-- .../contracts/interfaces/ISubgraphService.sol | 5 +++ .../test/SubgraphBaseTest.t.sol | 6 +-- .../subgraphService/SubgraphService.t.sol | 6 +++ .../governance/stakeToFeesRatio.t.sol | 43 +++++++++++++++++++ 5 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 packages/subgraph-service/test/subgraphService/governance/stakeToFeesRatio.t.sol diff --git a/packages/subgraph-service/contracts/SubgraphService.sol b/packages/subgraph-service/contracts/SubgraphService.sol index 5023e6160..12a61e15f 100644 --- a/packages/subgraph-service/contracts/SubgraphService.sol +++ b/packages/subgraph-service/contracts/SubgraphService.sol @@ -71,7 +71,11 @@ contract SubgraphService is * @param minimumProvisionTokens The minimum amount of provisioned tokens required to create an allocation * @param maximumDelegationRatio The maximum delegation ratio allowed for an allocation */ - function initialize(uint256 minimumProvisionTokens, uint32 maximumDelegationRatio) external initializer { + function initialize( + uint256 minimumProvisionTokens, + uint32 maximumDelegationRatio, + uint256 stakeToFeesRatio + ) external initializer { __Ownable_init(msg.sender); __DataService_init(); __DataServicePausable_init(); @@ -79,6 +83,7 @@ contract SubgraphService is _setProvisionTokensRange(minimumProvisionTokens, type(uint256).max); _setDelegationRatio(maximumDelegationRatio); + _setStakeToFeesRatio(stakeToFeesRatio); } /** @@ -372,9 +377,8 @@ contract SubgraphService is /** * @notice See {ISubgraphService.setStakeToFeesRatio} */ - function setStakeToFeesRatio(uint256 stakeToFeesRatio_) external override onlyOwner { - stakeToFeesRatio = stakeToFeesRatio_; - emit StakeToFeesRatioSet(stakeToFeesRatio_); + function setStakeToFeesRatio(uint256 stakeToFeesRatio) external override onlyOwner { + _setStakeToFeesRatio(stakeToFeesRatio); } /** @@ -558,4 +562,10 @@ contract SubgraphService is emit QueryFeesCollected(indexer, tokensCollected, tokensCurators); return tokensCollected; } + + function _setStakeToFeesRatio(uint256 _stakeToFeesRatio) private { + require(_stakeToFeesRatio != 0, SubgraphServiceInvalidZeroStakeToFeesRatio()); + stakeToFeesRatio = _stakeToFeesRatio; + emit StakeToFeesRatioSet(_stakeToFeesRatio); + } } diff --git a/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol b/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol index e12554303..b83d672f7 100644 --- a/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol +++ b/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol @@ -122,6 +122,11 @@ interface ISubgraphService is IDataServiceFees { */ error SubgraphServiceAllocationIsAltruistic(address allocationId); + /** + * @notice Thrown when trying to set stake to fees ratio to zero + */ + error SubgraphServiceInvalidZeroStakeToFeesRatio(); + /** * @notice Close a stale allocation * @dev This function can be permissionlessly called when the allocation is stale. diff --git a/packages/subgraph-service/test/SubgraphBaseTest.t.sol b/packages/subgraph-service/test/SubgraphBaseTest.t.sol index d42b66e29..f1aa9b96c 100644 --- a/packages/subgraph-service/test/SubgraphBaseTest.t.sol +++ b/packages/subgraph-service/test/SubgraphBaseTest.t.sol @@ -151,7 +151,7 @@ abstract contract SubgraphBaseTest is Utils, Constants { address subgraphServiceProxy = UnsafeUpgrades.deployTransparentProxy( subgraphServiceImplementation, users.governor, - abi.encodeCall(SubgraphService.initialize, (minimumProvisionTokens, delegationRatio)) + abi.encodeCall(SubgraphService.initialize, (minimumProvisionTokens, delegationRatio, stakeToFeesRatio)) ); subgraphService = SubgraphService(subgraphServiceProxy); @@ -183,10 +183,10 @@ abstract contract SubgraphBaseTest is Utils, Constants { } function setupProtocol() private { + resetPrank(users.deployer); + subgraphService.transferOwnership(users.governor); resetPrank(users.governor); staking.setMaxThawingPeriod(MAX_THAWING_PERIOD); - resetPrank(users.deployer); - subgraphService.setStakeToFeesRatio(stakeToFeesRatio); subgraphService.setMaxPOIStaleness(maxPOIStaleness); subgraphService.setCurationCut(curationCut); } diff --git a/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol b/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol index 05c038680..8f51784bb 100644 --- a/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol +++ b/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol @@ -30,6 +30,12 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { * MODIFIERS */ + modifier useGovernor() { + vm.startPrank(users.governor); + _; + vm.stopPrank(); + } + modifier useOperator() { resetPrank(users.indexer); staking.setOperator(users.operator, address(subgraphService), true); diff --git a/packages/subgraph-service/test/subgraphService/governance/stakeToFeesRatio.t.sol b/packages/subgraph-service/test/subgraphService/governance/stakeToFeesRatio.t.sol new file mode 100644 index 000000000..bfd09073e --- /dev/null +++ b/packages/subgraph-service/test/subgraphService/governance/stakeToFeesRatio.t.sol @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.27; + +import "forge-std/Test.sol"; + +import { ISubgraphService } from "../../../contracts/interfaces/ISubgraphService.sol"; +import { SubgraphServiceTest } from "../SubgraphService.t.sol"; +import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; + +contract DisputeManagerGovernanceArbitratorTest is SubgraphServiceTest { + + /** + * ACTIONS + */ + + function _setStakeToFeesRatio(uint256 _stakeToFeesRatio) internal { + vm.expectEmit(address(subgraphService)); + emit ISubgraphService.StakeToFeesRatioSet(_stakeToFeesRatio); + subgraphService.setStakeToFeesRatio(_stakeToFeesRatio); + assertEq(subgraphService.stakeToFeesRatio(), _stakeToFeesRatio); + } + + /* + * TESTS + */ + + function test_Governance_SetStakeToFeesRatio(uint256 stakeToFeesRatio) public useGovernor { + vm.assume(stakeToFeesRatio > 0); + _setStakeToFeesRatio(stakeToFeesRatio); + } + + function test_Governance_RevertWhen_ZeroValue() public useGovernor { + uint256 stakeToFeesRatio = 0; + vm.expectRevert(abi.encodeWithSelector(ISubgraphService.SubgraphServiceInvalidZeroStakeToFeesRatio.selector)); + subgraphService.setStakeToFeesRatio(stakeToFeesRatio); + } + + function test_Governance_RevertWhen_NotGovernor() public useIndexer { + uint256 stakeToFeesRatio = 2; + vm.expectRevert(abi.encodeWithSelector(OwnableUpgradeable.OwnableUnauthorizedAccount.selector, users.indexer)); + subgraphService.setStakeToFeesRatio(stakeToFeesRatio); + } +} From 2b4dd1fb1b97951b3246fceff6062ac3f9610b50 Mon Sep 17 00:00:00 2001 From: Miguel de Elias Date: Thu, 19 Sep 2024 15:36:29 -0300 Subject: [PATCH 2/2] fix: revert parameter name --- packages/subgraph-service/contracts/SubgraphService.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/subgraph-service/contracts/SubgraphService.sol b/packages/subgraph-service/contracts/SubgraphService.sol index 12a61e15f..49fff030b 100644 --- a/packages/subgraph-service/contracts/SubgraphService.sol +++ b/packages/subgraph-service/contracts/SubgraphService.sol @@ -377,8 +377,8 @@ contract SubgraphService is /** * @notice See {ISubgraphService.setStakeToFeesRatio} */ - function setStakeToFeesRatio(uint256 stakeToFeesRatio) external override onlyOwner { - _setStakeToFeesRatio(stakeToFeesRatio); + function setStakeToFeesRatio(uint256 stakeToFeesRatio_) external override onlyOwner { + _setStakeToFeesRatio(stakeToFeesRatio_); } /**