Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add stakeToFeesRatio to SubgraphService initialize #1027

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions packages/subgraph-service/contracts/SubgraphService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,19 @@ 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();
__AllocationManager_init("SubgraphService", "1.0");

_setProvisionTokensRange(minimumProvisionTokens, type(uint256).max);
_setDelegationRatio(maximumDelegationRatio);
_setStakeToFeesRatio(stakeToFeesRatio);
}

/**
Expand Down Expand Up @@ -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_);
}

/**
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions packages/subgraph-service/test/SubgraphBaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}