From 0b7730a2c5a514f88ad8f4f270b0a91998d2476d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Migone?= Date: Mon, 24 Feb 2025 17:50:58 -0300 Subject: [PATCH] fix: a few fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Migone --- .../utilities/ProvisionManagerStorage.sol | 14 +++++------ .../internal/IHorizonStakingExtension.sol | 6 +++++ .../contracts/payments/PaymentsEscrow.sol | 1 + .../staking/HorizonStakingExtension.sol | 9 +++++++ .../contracts/SubgraphService.sol | 25 ++++++++++++++++++- .../contracts/SubgraphServiceStorage.sol | 2 +- .../contracts/interfaces/ISubgraphService.sol | 18 +++++++++++++ .../ignition/configs/migrate.default.json5 | 3 +++ .../ignition/configs/protocol.default.json5 | 3 +++ .../configs/protocol.local-network.json5 | 3 +++ .../ignition/modules/SubgraphService.ts | 10 +++++++- .../test/SubgraphBaseTest.t.sol | 5 +++- .../subgraphService/SubgraphService.t.sol | 2 +- 13 files changed, 89 insertions(+), 12 deletions(-) diff --git a/packages/horizon/contracts/data-service/utilities/ProvisionManagerStorage.sol b/packages/horizon/contracts/data-service/utilities/ProvisionManagerStorage.sol index 0732afc9a..de6d99476 100644 --- a/packages/horizon/contracts/data-service/utilities/ProvisionManagerStorage.sol +++ b/packages/horizon/contracts/data-service/utilities/ProvisionManagerStorage.sol @@ -6,26 +6,26 @@ pragma solidity 0.8.27; */ abstract contract ProvisionManagerV1Storage { /// @notice The minimum amount of tokens required to register a provision in the data service - uint256 public minimumProvisionTokens; + uint256 internal minimumProvisionTokens; /// @notice The maximum amount of tokens allowed to register a provision in the data service - uint256 public maximumProvisionTokens; + uint256 internal maximumProvisionTokens; /// @notice The minimum thawing period required to register a provision in the data service - uint64 public minimumThawingPeriod; + uint64 internal minimumThawingPeriod; /// @notice The maximum thawing period allowed to register a provision in the data service - uint64 public maximumThawingPeriod; + uint64 internal maximumThawingPeriod; /// @notice The minimum verifier cut required to register a provision in the data service (in PPM) - uint32 public minimumVerifierCut; + uint32 internal minimumVerifierCut; /// @notice The maximum verifier cut allowed to register a provision in the data service (in PPM) - uint32 public maximumVerifierCut; + uint32 internal maximumVerifierCut; /// @notice How much delegation the service provider can effectively use /// @dev Max calculated as service provider's stake * delegationRatio - uint32 public delegationRatio; + uint32 internal delegationRatio; /// @dev Gap to allow adding variables in future upgrades /// Note that this contract is not upgradeable but might be inherited by an upgradeable contract diff --git a/packages/horizon/contracts/interfaces/internal/IHorizonStakingExtension.sol b/packages/horizon/contracts/interfaces/internal/IHorizonStakingExtension.sol index 8d5031b54..15207679c 100644 --- a/packages/horizon/contracts/interfaces/internal/IHorizonStakingExtension.sol +++ b/packages/horizon/contracts/interfaces/internal/IHorizonStakingExtension.sol @@ -164,4 +164,10 @@ interface IHorizonStakingExtension is IRewardsIssuer { */ // solhint-disable-next-line func-name-mixedcase function __DEPRECATED_getThawingPeriod() external view returns (uint64); + + /** + * @notice Return the address of the subgraph data service. + * @return Address of the subgraph data service + */ + function getSubgraphService() external view returns (address); } diff --git a/packages/horizon/contracts/payments/PaymentsEscrow.sol b/packages/horizon/contracts/payments/PaymentsEscrow.sol index c1de3bce1..7b3e99240 100644 --- a/packages/horizon/contracts/payments/PaymentsEscrow.sol +++ b/packages/horizon/contracts/payments/PaymentsEscrow.sol @@ -55,6 +55,7 @@ contract PaymentsEscrow is Initializable, MulticallUpgradeable, GraphDirectory, ); WITHDRAW_ESCROW_THAWING_PERIOD = withdrawEscrowThawingPeriod; + _disableInitializers(); } /** diff --git a/packages/horizon/contracts/staking/HorizonStakingExtension.sol b/packages/horizon/contracts/staking/HorizonStakingExtension.sol index 8074404f3..6da7baa9c 100644 --- a/packages/horizon/contracts/staking/HorizonStakingExtension.sol +++ b/packages/horizon/contracts/staking/HorizonStakingExtension.sol @@ -283,6 +283,15 @@ contract HorizonStakingExtension is HorizonStakingBase, IHorizonStakingExtension return _serviceProviders[indexer].tokensStaked; } + /** + * @notice Return the address of the subgraph data service. + * @dev TODO: After transition period move to main HorizonStaking contract + * @return Address of the subgraph data service + */ + function getSubgraphService() external view override returns (address) { + return SUBGRAPH_DATA_SERVICE_ADDRESS; + } + /** * @notice Getter that returns if an indexer has any stake. * @param indexer Address of the indexer diff --git a/packages/subgraph-service/contracts/SubgraphService.sol b/packages/subgraph-service/contracts/SubgraphService.sol index eea79b2ea..0846d819e 100644 --- a/packages/subgraph-service/contracts/SubgraphService.sol +++ b/packages/subgraph-service/contracts/SubgraphService.sol @@ -75,16 +75,18 @@ contract SubgraphService is * @notice Initialize the contract * @dev The thawingPeriod and verifierCut ranges are not set here because they are variables * on the DisputeManager. We use the {ProvisionManager} overrideable getters to get the ranges. + * @param owner The owner of the contract * @param minimumProvisionTokens The minimum amount of provisioned tokens required to create an allocation * @param maximumDelegationRatio The maximum delegation ratio allowed for an allocation * @param stakeToFeesRatio The ratio of stake to fees to lock when collecting query fees */ function initialize( + address owner, uint256 minimumProvisionTokens, uint32 maximumDelegationRatio, uint256 stakeToFeesRatio ) external initializer { - __Ownable_init(msg.sender); + __Ownable_init(owner); __Multicall_init(); __DataService_init(); __DataServicePausable_init(); @@ -456,6 +458,27 @@ contract SubgraphService is return _legacyAllocations[allocationId]; } + /** + * @notice See {ISubgraphService.getDisputeManager} + */ + function getDisputeManager() external view override returns (address) { + return address(_disputeManager()); + } + + /** + * @notice See {ISubgraphService.getGraphTallyCollector} + */ + function getGraphTallyCollector() external view override returns (address) { + return address(_graphTallyCollector()); + } + + /** + * @notice See {ISubgraphService.getCuration} + */ + function getCuration() external view override returns (address) { + return address(_curation()); + } + /** * @notice See {ISubgraphService.encodeAllocationProof} */ diff --git a/packages/subgraph-service/contracts/SubgraphServiceStorage.sol b/packages/subgraph-service/contracts/SubgraphServiceStorage.sol index e953dfba0..d5fb24a9b 100644 --- a/packages/subgraph-service/contracts/SubgraphServiceStorage.sol +++ b/packages/subgraph-service/contracts/SubgraphServiceStorage.sol @@ -10,6 +10,6 @@ abstract contract SubgraphServiceV1Storage { ///@notice Multiplier for how many tokens back collected query fees uint256 public stakeToFeesRatio; - /// @notice The cut curators take from query fee payments + /// @notice The cut curators take from query fee payments. In PPM. uint256 public curationFeesCut; } diff --git a/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol b/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol index da04b48ee..a63b6b072 100644 --- a/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol +++ b/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol @@ -247,4 +247,22 @@ interface ISubgraphService is IDataServiceFees { * @return True if the indexer is over-allocated, false otherwise */ function isOverAllocated(address allocationId) external view returns (bool); + + /** + * @notice Gets the address of the dispute manager + * @return The address of the dispute manager + */ + function getDisputeManager() external view returns (address); + + /** + * @notice Gets the address of the graph tally collector + * @return The address of the graph tally collector + */ + function getGraphTallyCollector() external view returns (address); + + /** + * @notice Gets the address of the curation contract + * @return The address of the curation contract + */ + function getCuration() external view returns (address); } diff --git a/packages/subgraph-service/ignition/configs/migrate.default.json5 b/packages/subgraph-service/ignition/configs/migrate.default.json5 index 8f3c78b29..6678781a7 100644 --- a/packages/subgraph-service/ignition/configs/migrate.default.json5 +++ b/packages/subgraph-service/ignition/configs/migrate.default.json5 @@ -2,6 +2,7 @@ "$global": { "governor": "0x72ee30d43Fb5A90B3FE983156C5d2fBE6F6d07B3", "arbitrator": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "pauseGuardian": "0xB0aD33a21b98bCA1761729A105e2E34e27153aAE", // Addresses for contracts deployed in the original Graph Protocol "controllerAddress": "0x9DB3ee191681f092607035d9BDA6e59FbEaCa695", @@ -22,6 +23,8 @@ "minimumProvisionTokens": "100000000000000000000000n", "maximumDelegationRatio": 16, "stakeToFeesRatio": 2, + "maxPOIStaleness": 2419200, // 28 days = 2419200 seconds + "curationCut": 100000, // Addresses for contracts deployed in the original Graph Protocol "curationAddress": "0xDe761f075200E75485F4358978FB4d1dC8644FD5", diff --git a/packages/subgraph-service/ignition/configs/protocol.default.json5 b/packages/subgraph-service/ignition/configs/protocol.default.json5 index 2fd75fcbc..9693a77d2 100644 --- a/packages/subgraph-service/ignition/configs/protocol.default.json5 +++ b/packages/subgraph-service/ignition/configs/protocol.default.json5 @@ -2,6 +2,7 @@ "$global": { "governor": "0x72ee30d43Fb5A90B3FE983156C5d2fBE6F6d07B3", "arbitrator": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "pauseGuardian": "0xB0aD33a21b98bCA1761729A105e2E34e27153aAE", // Must be set for step 2 of the deployment "controllerAddress": "", @@ -22,6 +23,8 @@ "minimumProvisionTokens": "100000000000000000000000n", "maximumDelegationRatio": 16, "stakeToFeesRatio": 2, + "maxPOIStaleness": 2419200, // 28 days = 2419200 seconds + "curationCut": 100000, // Must be set for step 2 of the deployment "subgraphServiceProxyAddress": "", diff --git a/packages/subgraph-service/ignition/configs/protocol.local-network.json5 b/packages/subgraph-service/ignition/configs/protocol.local-network.json5 index 52eade9ba..d43a2eb68 100644 --- a/packages/subgraph-service/ignition/configs/protocol.local-network.json5 +++ b/packages/subgraph-service/ignition/configs/protocol.local-network.json5 @@ -3,6 +3,7 @@ "$global": { "governor": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "arbitrator": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "pauseGuardian": "0xB0aD33a21b98bCA1761729A105e2E34e27153aAE", // Must be set for step 2 of the deployment "controllerAddress": "", @@ -23,6 +24,8 @@ "minimumProvisionTokens": "100000000000000000000000n", "maximumDelegationRatio": 16, "stakeToFeesRatio": 2, + "maxPOIStaleness": 2419200, // 28 days = 2419200 seconds + "curationCut": 100000, // Must be set for step 2 of the deployment "subgraphServiceProxyAddress": "", diff --git a/packages/subgraph-service/ignition/modules/SubgraphService.ts b/packages/subgraph-service/ignition/modules/SubgraphService.ts index a4883a1b0..9e208e826 100644 --- a/packages/subgraph-service/ignition/modules/SubgraphService.ts +++ b/packages/subgraph-service/ignition/modules/SubgraphService.ts @@ -7,7 +7,9 @@ import SubgraphServiceArtifact from '../../build/contracts/contracts/SubgraphSer import TransparentUpgradeableProxyArtifact from '@openzeppelin/contracts/build/contracts/TransparentUpgradeableProxy.json' export default buildModule('SubgraphService', (m) => { + const deployer = m.getAccount(0) const governor = m.getParameter('governor') + const pauseGuardian = m.getParameter('pauseGuardian') const controllerAddress = m.getParameter('controllerAddress') const subgraphServiceProxyAddress = m.getParameter('subgraphServiceProxyAddress') const subgraphServiceProxyAdminAddress = m.getParameter('subgraphServiceProxyAdminAddress') @@ -17,6 +19,8 @@ export default buildModule('SubgraphService', (m) => { const minimumProvisionTokens = m.getParameter('minimumProvisionTokens') const maximumDelegationRatio = m.getParameter('maximumDelegationRatio') const stakeToFeesRatio = m.getParameter('stakeToFeesRatio') + const maxPOIStaleness = m.getParameter('maxPOIStaleness') + const curationCut = m.getParameter('curationCut') const SubgraphServiceProxyAdmin = m.contractAt('ProxyAdmin', ProxyAdminArtifact, subgraphServiceProxyAdminAddress) const SubgraphServiceProxy = m.contractAt('SubgraphServiceProxy', TransparentUpgradeableProxyArtifact, subgraphServiceProxyAddress) @@ -35,13 +39,17 @@ export default buildModule('SubgraphService', (m) => { name: 'SubgraphService', artifact: SubgraphServiceArtifact, initArgs: [ + deployer, minimumProvisionTokens, maximumDelegationRatio, stakeToFeesRatio, ], }) - m.call(SubgraphServiceProxyAdmin, 'transferOwnership', [governor], { after: [SubgraphService] }) + const callSetPauseGuardian = m.call(SubgraphService, 'setPauseGuardian', [pauseGuardian, true]) + const callSetMaxPOIStaleness = m.call(SubgraphService, 'setMaxPOIStaleness', [maxPOIStaleness]) + const callSetCurationCut = m.call(SubgraphService, 'setCurationCut', [curationCut]) + m.call(SubgraphServiceProxyAdmin, 'transferOwnership', [governor], { after: [callSetPauseGuardian, callSetMaxPOIStaleness, callSetCurationCut] }) return { SubgraphService, diff --git a/packages/subgraph-service/test/SubgraphBaseTest.t.sol b/packages/subgraph-service/test/SubgraphBaseTest.t.sol index 7742e6696..bd6ccebe3 100644 --- a/packages/subgraph-service/test/SubgraphBaseTest.t.sol +++ b/packages/subgraph-service/test/SubgraphBaseTest.t.sol @@ -160,7 +160,10 @@ abstract contract SubgraphBaseTest is Utils, Constants { address subgraphServiceProxy = UnsafeUpgrades.deployTransparentProxy( subgraphServiceImplementation, users.governor, - abi.encodeCall(SubgraphService.initialize, (minimumProvisionTokens, delegationRatio, stakeToFeesRatio)) + abi.encodeCall( + SubgraphService.initialize, + (users.deployer, minimumProvisionTokens, delegationRatio, stakeToFeesRatio) + ) ); subgraphService = SubgraphService(subgraphServiceProxy); diff --git a/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol b/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol index c83d43aac..5e399307d 100644 --- a/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol +++ b/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol @@ -434,7 +434,7 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { uint256 tokensAvailable = staking.getTokensAvailable( _indexer, address(subgraphService), - subgraphService.delegationRatio() + subgraphService.getDelegationRatio() ); if (allocation.tokens <= tokensAvailable) { // Indexer isn't over allocated so allocation should still be open