From 01db6e5b8ee8d4fead8eed61ae83824e86201366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Migone?= Date: Mon, 10 Feb 2025 16:25:31 -0300 Subject: [PATCH 1/3] feat: dont issue rewards to allos less than one epoch old MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Migone --- .../contracts/libraries/Allocation.sol | 8 ++- .../contracts/utilities/AllocationManager.sol | 31 +++++++----- .../test/shared/SubgraphServiceShared.t.sol | 49 ++++++++++++------- .../subgraphService/SubgraphService.t.sol | 3 ++ .../subgraphService/allocation/resize.t.sol | 4 ++ .../collect/indexing/indexing.t.sol | 23 +++++++++ 6 files changed, 87 insertions(+), 31 deletions(-) diff --git a/packages/subgraph-service/contracts/libraries/Allocation.sol b/packages/subgraph-service/contracts/libraries/Allocation.sol index 320547f92..ad66b20ff 100644 --- a/packages/subgraph-service/contracts/libraries/Allocation.sol +++ b/packages/subgraph-service/contracts/libraries/Allocation.sol @@ -30,6 +30,8 @@ library Allocation { uint256 accRewardsPerAllocatedToken; // Accumulated rewards that are pending to be claimed due allocation resize uint256 accRewardsPending; + // Epoch when the allocation was created + uint256 createdAtEpoch; } /** @@ -68,7 +70,8 @@ library Allocation { address allocationId, bytes32 subgraphDeploymentId, uint256 tokens, - uint256 accRewardsPerAllocatedToken + uint256 accRewardsPerAllocatedToken, + uint256 createdAtEpoch ) internal returns (State memory) { require(!self[allocationId].exists(), AllocationAlreadyExists(allocationId)); @@ -80,7 +83,8 @@ library Allocation { closedAt: 0, lastPOIPresentedAt: 0, accRewardsPerAllocatedToken: accRewardsPerAllocatedToken, - accRewardsPending: 0 + accRewardsPending: 0, + createdAtEpoch: createdAtEpoch }); self[allocationId] = allocation; diff --git a/packages/subgraph-service/contracts/utilities/AllocationManager.sol b/packages/subgraph-service/contracts/utilities/AllocationManager.sol index 008a65eef..80264af93 100644 --- a/packages/subgraph-service/contracts/utilities/AllocationManager.sol +++ b/packages/subgraph-service/contracts/utilities/AllocationManager.sol @@ -40,12 +40,14 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca * @param allocationId The id of the allocation * @param subgraphDeploymentId The id of the subgraph deployment * @param tokens The amount of tokens allocated + * @param currentEpoch The current epoch */ event AllocationCreated( address indexed indexer, address indexed allocationId, bytes32 indexed subgraphDeploymentId, - uint256 tokens + uint256 tokens, + uint256 currentEpoch ); /** @@ -157,17 +159,14 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca // solhint-disable-next-line func-name-mixedcase function __AllocationManager_init(string memory _name, string memory _version) internal onlyInitializing { __EIP712_init(_name, _version); - __AllocationManager_init_unchained(_name, _version); + __AllocationManager_init_unchained(); } /** * @notice Initializes the contract */ // solhint-disable-next-line func-name-mixedcase - function __AllocationManager_init_unchained( - string memory _name, - string memory _version - ) internal onlyInitializing {} + function __AllocationManager_init_unchained() internal onlyInitializing {} /** * @notice Imports a legacy allocation id into the subgraph service @@ -213,12 +212,15 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca // Ensure allocation id is not reused // need to check both subgraph service (on allocations.create()) and legacy allocations _legacyAllocations.revertIfExists(_graphStaking(), _allocationId); + + uint256 currentEpoch = _graphEpochManager().currentEpoch(); Allocation.State memory allocation = _allocations.create( _indexer, _allocationId, _subgraphDeploymentId, _tokens, - _graphRewardsManager().onSubgraphAllocationUpdate(_subgraphDeploymentId) + _graphRewardsManager().onSubgraphAllocationUpdate(_subgraphDeploymentId), + currentEpoch ); // Check that the indexer has enough tokens available @@ -230,7 +232,7 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca _subgraphAllocatedTokens[allocation.subgraphDeploymentId] + allocation.tokens; - emit AllocationCreated(_indexer, _allocationId, _subgraphDeploymentId, allocation.tokens); + emit AllocationCreated(_indexer, _allocationId, _subgraphDeploymentId, allocation.tokens, currentEpoch); return allocation; } @@ -238,15 +240,20 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca * @notice Present a POI to collect indexing rewards for an allocation * This function will mint indexing rewards using the {RewardsManager} and distribute them to the indexer and delegators. * - * To qualify for indexing rewards: + * Conditions to qualify for indexing rewards: * - POI must be non-zero * - POI must not be stale, i.e: older than `maxPOIStaleness` * - allocation must not be altruistic (allocated tokens = 0) + * - allocation must be open for at least one epoch * * Note that indexers are required to periodically (at most every `maxPOIStaleness`) present POIs to collect rewards. * Rewards will not be issued to stale POIs, which means that indexers are advised to present a zero POI if they are * unable to present a valid one to prevent being locked out of future rewards. * + * Note on allocation duration restriction: this is required to ensure that non protocol chains have a valid block number for + * which to calculate POIs. EBO posts once per epoch typically at each epoch change, so we restrict rewards to allocations + * that have gone through at least one epoch change. + * * Emits a {IndexingRewardsCollected} event. * * @param _allocationId The id of the allocation to collect rewards for @@ -260,10 +267,12 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca Allocation.State memory allocation = _allocations.get(_allocationId); require(allocation.isOpen(), AllocationManagerAllocationClosed(_allocationId)); + uint256 currentEpoch = _graphEpochManager().currentEpoch(); + // Mint indexing rewards if all conditions are met uint256 tokensRewards = (!allocation.isStale(maxPOIStaleness) && !allocation.isAltruistic() && - _poi != bytes32(0)) + _poi != bytes32(0)) && currentEpoch > allocation.createdAtEpoch ? _graphRewardsManager().takeRewards(_allocationId) : 0; @@ -318,7 +327,7 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca tokensIndexerRewards, tokensDelegationRewards, _poi, - _graphEpochManager().currentEpoch() + currentEpoch ); // Check if the indexer is over-allocated and close the allocation if necessary diff --git a/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol b/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol index fa9d420fb..068e492e3 100644 --- a/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol +++ b/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol @@ -11,7 +11,6 @@ import { ISubgraphService } from "../../contracts/interfaces/ISubgraphService.so import { HorizonStakingSharedTest } from "./HorizonStakingShared.t.sol"; abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { - /* * VARIABLES */ @@ -24,7 +23,7 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { * MODIFIERS */ - modifier useIndexer { + modifier useIndexer() { vm.startPrank(users.indexer); _; vm.stopPrank(); @@ -35,7 +34,12 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { vm.assume(tokens < 10_000_000_000 ether); _createProvision(users.indexer, tokens, maxSlashingPercentage, disputePeriod); _register(users.indexer, abi.encode("url", "geoHash", address(0))); - bytes memory data = _createSubgraphAllocationData(users.indexer, subgraphDeployment, allocationIDPrivateKey, tokens); + bytes memory data = _createSubgraphAllocationData( + users.indexer, + subgraphDeployment, + allocationIDPrivateKey, + tokens + ); _startService(users.indexer, data); _; } @@ -43,7 +47,7 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { modifier useDelegation(uint256 tokens) { vm.assume(tokens > MIN_DELEGATION); vm.assume(tokens < 10_000_000_000 ether); - (, address msgSender,) = vm.readCallers(); + (, address msgSender, ) = vm.readCallers(); resetPrank(users.delegator); token.approve(address(staking), tokens); _delegate(users.indexer, address(subgraphService), tokens, 0); @@ -72,10 +76,7 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { ); vm.expectEmit(address(subgraphService)); - emit IDataService.ServiceProviderRegistered( - _indexer, - _data - ); + emit IDataService.ServiceProviderRegistered(_indexer, _data); // Register indexer subgraphService.register(_indexer, _data); @@ -91,14 +92,22 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { } function _startService(address _indexer, bytes memory _data) internal { - (bytes32 subgraphDeploymentId, uint256 tokens, address allocationId,) = abi.decode( + (bytes32 subgraphDeploymentId, uint256 tokens, address allocationId, ) = abi.decode( _data, (bytes32, uint256, address, bytes) ); uint256 previousSubgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens(subgraphDeploymentId); + uint256 currentEpoch = epochManager.currentEpoch(); vm.expectEmit(address(subgraphService)); emit IDataService.ServiceStarted(_indexer, _data); + emit AllocationManager.AllocationCreated( + _indexer, + allocationId, + subgraphDeploymentId, + tokens, + currentEpoch + ); // TODO: improve this uint256 accRewardsPerAllocatedToken = 0; @@ -116,9 +125,10 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { assertEq(allocation.subgraphDeploymentId, subgraphDeploymentId); assertEq(allocation.createdAt, block.timestamp); assertEq(allocation.closedAt, 0); - assertEq(allocation.lastPOIPresentedAt, 0); + assertEq(allocation.lastPOIPresentedAt, 0); assertEq(allocation.accRewardsPerAllocatedToken, accRewardsPerAllocatedToken); assertEq(allocation.accRewardsPending, 0); + assertEq(allocation.createdAtEpoch, currentEpoch); // Check subgraph deployment allocated tokens uint256 subgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens(subgraphDeploymentId); @@ -130,10 +140,17 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { assertTrue(subgraphService.isActiveAllocation(allocationId)); Allocation.State memory allocation = subgraphService.getAllocation(allocationId); - uint256 previousSubgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens(allocation.subgraphDeploymentId); - + uint256 previousSubgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens( + allocation.subgraphDeploymentId + ); + vm.expectEmit(address(subgraphService)); - emit AllocationManager.AllocationClosed(_indexer, allocationId, allocation.subgraphDeploymentId, allocation.tokens); + emit AllocationManager.AllocationClosed( + _indexer, + allocationId, + allocation.subgraphDeploymentId, + allocation.tokens + ); emit IDataService.ServiceStopped(_indexer, _data); // stop allocation @@ -178,10 +195,6 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { function _getIndexer(address _indexer) private view returns (ISubgraphService.Indexer memory) { (uint256 registeredAt, string memory url, string memory geoHash) = subgraphService.indexers(_indexer); - return ISubgraphService.Indexer({ - registeredAt: registeredAt, - url: url, - geoHash: geoHash - }); + return ISubgraphService.Indexer({ registeredAt: registeredAt, url: url, geoHash: geoHash }); } } diff --git a/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol b/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol index 73430c85c..11dcbfe03 100644 --- a/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol +++ b/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol @@ -302,6 +302,9 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { // Calculate the payment collected by the indexer for this transaction paymentCollected = accRewardsPerTokens - allocation.accRewardsPerAllocatedToken; + uint256 currentEpoch = epochManager.currentEpoch(); + paymentCollected = currentEpoch > allocation.createdAtEpoch ? paymentCollected : 0; + uint256 delegatorCut = staking.getDelegationFeeCut( allocation.indexer, address(subgraphService), diff --git a/packages/subgraph-service/test/subgraphService/allocation/resize.t.sol b/packages/subgraph-service/test/subgraphService/allocation/resize.t.sol index 0df994929..ff8c504a9 100644 --- a/packages/subgraph-service/test/subgraphService/allocation/resize.t.sol +++ b/packages/subgraph-service/test/subgraphService/allocation/resize.t.sol @@ -29,6 +29,10 @@ contract SubgraphServiceAllocationResizeTest is SubgraphServiceTest { vm.assume(resizeTokens != tokens); mint(users.indexer, resizeTokens); + + // skip time to ensure allocation gets rewards + vm.roll(block.number + EPOCH_LENGTH); + IGraphPayments.PaymentTypes paymentType = IGraphPayments.PaymentTypes.IndexingRewards; bytes memory data = abi.encode(allocationID, bytes32("POI1")); _collect(users.indexer, paymentType, data); diff --git a/packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol b/packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol index 465f5c8cd..48eb36eb8 100644 --- a/packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol +++ b/packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol @@ -19,6 +19,10 @@ contract SubgraphServiceCollectIndexingTest is SubgraphServiceTest { ) public useIndexer useAllocation(tokens) { IGraphPayments.PaymentTypes paymentType = IGraphPayments.PaymentTypes.IndexingRewards; bytes memory data = abi.encode(allocationID, bytes32("POI")); + + // skip time to ensure allocation gets rewards + vm.roll(block.number + EPOCH_LENGTH); + _collect(users.indexer, paymentType, data); } @@ -34,6 +38,11 @@ contract SubgraphServiceCollectIndexingTest is SubgraphServiceTest { IGraphPayments.PaymentTypes.IndexingRewards, delegationFeeCut ); + + + // skip time to ensure allocation gets rewards + vm.roll(block.number + EPOCH_LENGTH); + IGraphPayments.PaymentTypes paymentType = IGraphPayments.PaymentTypes.IndexingRewards; bytes memory data = abi.encode(allocationID, bytes32("POI")); _collect(users.indexer, paymentType, data); @@ -54,6 +63,10 @@ contract SubgraphServiceCollectIndexingTest is SubgraphServiceTest { // Undelegate resetPrank(users.delegator); staking.undelegate(users.indexer, address(subgraphService), delegationTokens); + + // skip time to ensure allocation gets rewards + vm.roll(block.number + EPOCH_LENGTH); + resetPrank(users.indexer); IGraphPayments.PaymentTypes paymentType = IGraphPayments.PaymentTypes.IndexingRewards; bytes memory data = abi.encode(allocationID, bytes32("POI")); @@ -63,6 +76,9 @@ contract SubgraphServiceCollectIndexingTest is SubgraphServiceTest { function test_SubgraphService_Collect_Indexing_RewardsDestination( uint256 tokens ) public useIndexer useAllocation(tokens) useRewardsDestination { + // skip time to ensure allocation gets rewards + vm.roll(block.number + EPOCH_LENGTH); + IGraphPayments.PaymentTypes paymentType = IGraphPayments.PaymentTypes.IndexingRewards; bytes memory data = abi.encode(allocationID, bytes32("POI")); _collect(users.indexer, paymentType, data); @@ -121,6 +137,9 @@ contract SubgraphServiceCollectIndexingTest is SubgraphServiceTest { // thaw some tokens to become over allocated staking.thaw(users.indexer, address(subgraphService), tokens / 2); + // skip time to ensure allocation gets rewards + vm.roll(block.number + EPOCH_LENGTH); + // this collection should close the allocation IGraphPayments.PaymentTypes paymentType = IGraphPayments.PaymentTypes.IndexingRewards; bytes memory collectData = abi.encode(allocationID, bytes32("POI")); @@ -135,6 +154,10 @@ contract SubgraphServiceCollectIndexingTest is SubgraphServiceTest { address newIndexer = makeAddr("newIndexer"); _createAndStartAllocation(newIndexer, tokens); bytes memory data = abi.encode(allocationID, bytes32("POI")); + + // skip time to ensure allocation gets rewards + vm.roll(block.number + EPOCH_LENGTH); + // Attempt to collect from other indexer's allocation vm.expectRevert( abi.encodeWithSelector(ISubgraphService.SubgraphServiceAllocationNotAuthorized.selector, newIndexer, allocationID) From 7cd08cb52dd5e1e8824034e9c78d13370547073a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Migone?= Date: Mon, 10 Feb 2025 16:49:54 -0300 Subject: [PATCH 2/3] chore: ensure contract size is below 24kB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Migone --- .../contracts/rewards/IRewardsIssuer.sol | 7 ------ .../contracts/rewards/IRewardsManager.sol | 2 +- .../contracts/rewards/RewardsManager.sol | 25 +++++-------------- .../staking/HorizonStakingExtension.sol | 9 ------- .../contracts/SubgraphService.sol | 19 -------------- .../contracts/interfaces/ISubgraphService.sol | 7 ------ packages/subgraph-service/hardhat.config.ts | 9 +++++++ .../test/mocks/MockRewardsManager.sol | 2 +- .../test/shared/SubgraphServiceShared.t.sol | 12 +++------ .../subgraphService/SubgraphService.t.sol | 3 +-- 10 files changed, 22 insertions(+), 73 deletions(-) diff --git a/packages/contracts/contracts/rewards/IRewardsIssuer.sol b/packages/contracts/contracts/rewards/IRewardsIssuer.sol index fe6963fa7..9da18b92b 100644 --- a/packages/contracts/contracts/rewards/IRewardsIssuer.sol +++ b/packages/contracts/contracts/rewards/IRewardsIssuer.sol @@ -31,11 +31,4 @@ interface IRewardsIssuer { * @return Total tokens allocated to subgraph */ function getSubgraphAllocatedTokens(bytes32 _subgraphDeploymentId) external view returns (uint256); - - /** - * @notice Whether or not an allocation is active (i.e open) - * @param _allocationId Allocation Id - * @return Whether or not the allocation is active - */ - function isActiveAllocation(address _allocationId) external view returns (bool); } diff --git a/packages/contracts/contracts/rewards/IRewardsManager.sol b/packages/contracts/contracts/rewards/IRewardsManager.sol index a1f9a3ba6..b31064d1b 100644 --- a/packages/contracts/contracts/rewards/IRewardsManager.sol +++ b/packages/contracts/contracts/rewards/IRewardsManager.sol @@ -39,7 +39,7 @@ interface IRewardsManager { function getAccRewardsPerAllocatedToken(bytes32 _subgraphDeploymentID) external view returns (uint256, uint256); - function getRewards(address _allocationID) external view returns (uint256); + function getRewards(address _rewardsIssuer, address _allocationID) external view returns (uint256); function calcRewards(uint256 _tokens, uint256 _accRewardsPerAllocatedToken) external pure returns (uint256); diff --git a/packages/contracts/contracts/rewards/RewardsManager.sol b/packages/contracts/contracts/rewards/RewardsManager.sol index a02e4518b..72afc3e1a 100644 --- a/packages/contracts/contracts/rewards/RewardsManager.sol +++ b/packages/contracts/contracts/rewards/RewardsManager.sol @@ -322,24 +322,11 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa * @param _allocationID Allocation * @return Rewards amount for an allocation */ - function getRewards(address _allocationID) external view override returns (uint256) { - address rewardsIssuer = address(0); - - // Check both the legacy and new allocations - address[2] memory rewardsIssuers = [address(staking()), address(subgraphService)]; - for (uint256 i = 0; i < rewardsIssuers.length; i++) { - if (rewardsIssuers[i] != address(0)) { - if (IRewardsIssuer(rewardsIssuers[i]).isActiveAllocation(_allocationID)) { - rewardsIssuer = address(rewardsIssuers[i]); - break; - } - } - } - - // Bail if allo does not exist - if (rewardsIssuer == address(0)) { - return 0; - } + function getRewards(address _rewardsIssuer, address _allocationID) external view override returns (uint256) { + require( + _rewardsIssuer == address(staking()) || _rewardsIssuer == address(subgraphService), + "Not a rewards issuer" + ); ( , @@ -347,7 +334,7 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa uint256 tokens, uint256 alloAccRewardsPerAllocatedToken, uint256 accRewardsPending - ) = IRewardsIssuer(rewardsIssuer).getAllocationData(_allocationID); + ) = IRewardsIssuer(_rewardsIssuer).getAllocationData(_allocationID); (uint256 accRewardsPerAllocatedToken, ) = getAccRewardsPerAllocatedToken(subgraphDeploymentId); return diff --git a/packages/horizon/contracts/staking/HorizonStakingExtension.sol b/packages/horizon/contracts/staking/HorizonStakingExtension.sol index afb20855b..8074404f3 100644 --- a/packages/horizon/contracts/staking/HorizonStakingExtension.sol +++ b/packages/horizon/contracts/staking/HorizonStakingExtension.sol @@ -274,15 +274,6 @@ contract HorizonStakingExtension is HorizonStakingBase, IHorizonStakingExtension return __DEPRECATED_subgraphAllocations[subgraphDeploymentID]; } - /** - * @notice Return true if allocation is active. - * @param allocationID Allocation identifier - * @return True if allocation is active - */ - function isActiveAllocation(address allocationID) external view override returns (bool) { - return _getAllocationState(allocationID) == AllocationState.Active; - } - /** * @notice Get the total amount of tokens staked by the indexer. * @param indexer Address of the indexer diff --git a/packages/subgraph-service/contracts/SubgraphService.sol b/packages/subgraph-service/contracts/SubgraphService.sol index db5aae0eb..f43669133 100644 --- a/packages/subgraph-service/contracts/SubgraphService.sol +++ b/packages/subgraph-service/contracts/SubgraphService.sol @@ -449,18 +449,6 @@ contract SubgraphService is return _subgraphAllocatedTokens[subgraphDeploymentId]; } - /** - * @notice Check if an allocation is open - * @dev Implements {IRewardsIssuer.isAllocationActive} - * @dev To be used by the {RewardsManager}. - * - * @param allocationId The allocation Id - * @return Wether or not the allocation is active - */ - function isActiveAllocation(address allocationId) external view override returns (bool) { - return _allocations[allocationId].isOpen(); - } - /** * @notice See {ISubgraphService.getLegacyAllocation} */ @@ -475,13 +463,6 @@ contract SubgraphService is return _encodeAllocationProof(indexer, allocationId); } - /** - * @notice See {ISubgraphService.isStaleAllocation} - */ - function isStaleAllocation(address allocationId) external view override returns (bool) { - return _allocations.get(allocationId).isStale(maxPOIStaleness); - } - /** * @notice See {ISubgraphService.isOverAllocated} */ diff --git a/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol b/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol index 7639ed4fb..da04b48ee 100644 --- a/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol +++ b/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol @@ -241,13 +241,6 @@ interface ISubgraphService is IDataServiceFees { */ function encodeAllocationProof(address indexer, address allocationId) external view returns (bytes32); - /** - * @notice Checks if an allocation is stale - * @param allocationId The id of the allocation - * @return True if the allocation is stale, false otherwise - */ - function isStaleAllocation(address allocationId) external view returns (bool); - /** * @notice Checks if an indexer is over-allocated * @param allocationId The id of the allocation diff --git a/packages/subgraph-service/hardhat.config.ts b/packages/subgraph-service/hardhat.config.ts index 1c80d89a0..8239cb494 100644 --- a/packages/subgraph-service/hardhat.config.ts +++ b/packages/subgraph-service/hardhat.config.ts @@ -17,6 +17,15 @@ if (process.env.BUILD_RUN !== 'true') { const config: HardhatUserConfig = { ...hardhatBaseConfig, + solidity: { + version: '0.8.27', + settings: { + optimizer: { + enabled: true, + runs: 50, + }, + }, + }, graph: { deployments: { ...hardhatBaseConfig.graph?.deployments, diff --git a/packages/subgraph-service/test/mocks/MockRewardsManager.sol b/packages/subgraph-service/test/mocks/MockRewardsManager.sol index 363fbf902..9e0047a89 100644 --- a/packages/subgraph-service/test/mocks/MockRewardsManager.sol +++ b/packages/subgraph-service/test/mocks/MockRewardsManager.sol @@ -61,7 +61,7 @@ contract MockRewardsManager is IRewardsManager { function getAccRewardsPerAllocatedToken(bytes32) external view returns (uint256, uint256) {} - function getRewards(address) external view returns (uint256) {} + function getRewards(address,address) external view returns (uint256) {} function calcRewards(uint256, uint256) external pure returns (uint256) {} diff --git a/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol b/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol index 068e492e3..8a51d3443 100644 --- a/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol +++ b/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol @@ -11,6 +11,8 @@ import { ISubgraphService } from "../../contracts/interfaces/ISubgraphService.so import { HorizonStakingSharedTest } from "./HorizonStakingShared.t.sol"; abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { + using Allocation for Allocation.State; + /* * VARIABLES */ @@ -101,13 +103,7 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { vm.expectEmit(address(subgraphService)); emit IDataService.ServiceStarted(_indexer, _data); - emit AllocationManager.AllocationCreated( - _indexer, - allocationId, - subgraphDeploymentId, - tokens, - currentEpoch - ); + emit AllocationManager.AllocationCreated(_indexer, allocationId, subgraphDeploymentId, tokens, currentEpoch); // TODO: improve this uint256 accRewardsPerAllocatedToken = 0; @@ -137,9 +133,9 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { function _stopService(address _indexer, bytes memory _data) internal { address allocationId = abi.decode(_data, (address)); - assertTrue(subgraphService.isActiveAllocation(allocationId)); Allocation.State memory allocation = subgraphService.getAllocation(allocationId); + assertTrue(allocation.isOpen()); uint256 previousSubgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens( allocation.subgraphDeploymentId ); diff --git a/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol b/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol index 11dcbfe03..1a37fed86 100644 --- a/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol +++ b/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol @@ -149,9 +149,8 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { } function _closeStaleAllocation(address _allocationId) internal { - assertTrue(subgraphService.isActiveAllocation(_allocationId)); - Allocation.State memory allocation = subgraphService.getAllocation(_allocationId); + assertTrue(allocation.isOpen()); uint256 previousSubgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens( allocation.subgraphDeploymentId ); From f6923b9beeb5e766867217e3a4922189b5089f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Migone?= Date: Mon, 10 Feb 2025 17:15:53 -0300 Subject: [PATCH 3/3] test: fix rewards manager tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Migone --- packages/contracts/test/unit/rewards/rewards.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/contracts/test/unit/rewards/rewards.test.ts b/packages/contracts/test/unit/rewards/rewards.test.ts index 7e977a9c0..cff7b0787 100644 --- a/packages/contracts/test/unit/rewards/rewards.test.ts +++ b/packages/contracts/test/unit/rewards/rewards.test.ts @@ -466,7 +466,7 @@ describe('Rewards', () => { await helpers.mine(ISSUANCE_RATE_PERIODS) // Rewards - const contractRewards = await rewardsManager.getRewards(allocationID1) + const contractRewards = await rewardsManager.getRewards(staking.address, allocationID1) // We trust using this function in the test because we tested it // standalone in a previous test @@ -504,12 +504,12 @@ describe('Rewards', () => { await staking.connect(indexer1).closeAllocation(allocationID1, randomHexBytes()) // Rewards - const contractRewards = await rewardsManager.getRewards(allocationID1) + const contractRewards = await rewardsManager.getRewards(staking.address, allocationID1) expect(contractRewards).eq(BigNumber.from(0)) }) it('rewards should be zero if the allocation does not exist', async function () { // Rewards - const contractRewards = await rewardsManager.getRewards(allocationIDNull) + const contractRewards = await rewardsManager.getRewards(staking.address, allocationIDNull) expect(contractRewards).eq(BigNumber.from(0)) }) }) @@ -1026,7 +1026,7 @@ describe('Rewards', () => { await staking.connect(assetHolder).collect(tokensToCollect, allocationID1) // check rewards diff - await rewardsManager.getRewards(allocationID1).then(formatGRT) + await rewardsManager.getRewards(staking.address, allocationID1).then(formatGRT) await helpers.mine() const accrual = await getRewardsAccrual(subgraphs)