diff --git a/packages/subgraph-service/contracts/SubgraphService.sol b/packages/subgraph-service/contracts/SubgraphService.sol index 5023e6160..49fff030b 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); } /** @@ -373,8 +378,7 @@ contract SubgraphService is * @notice See {ISubgraphService.setStakeToFeesRatio} */ function setStakeToFeesRatio(uint256 stakeToFeesRatio_) external override onlyOwner { - stakeToFeesRatio = stakeToFeesRatio_; - emit StakeToFeesRatioSet(stakeToFeesRatio_); + _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); + } +}