From 08539afc31fd3198d8ec7eea716cc935042e5369 Mon Sep 17 00:00:00 2001 From: Maikol <86025070+Maikol@users.noreply.github.com> Date: Sat, 21 Sep 2024 00:39:05 +1000 Subject: [PATCH] fix(SubgraphService): allow collecting rewards when delegation fee cut is 100% (#1038) --- .../contracts/utilities/AllocationManager.sol | 14 ++++++++------ .../collect/indexing/indexing.t.sol | 7 ++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/subgraph-service/contracts/utilities/AllocationManager.sol b/packages/subgraph-service/contracts/utilities/AllocationManager.sol index c555f271c..5bb22cbe2 100644 --- a/packages/subgraph-service/contracts/utilities/AllocationManager.sol +++ b/packages/subgraph-service/contracts/utilities/AllocationManager.sol @@ -303,12 +303,14 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca // Distribute rewards to indexer tokensIndexerRewards = tokensRewards - tokensDelegationRewards; - address rewardsDestination = rewardsDestination[allocation.indexer]; - if (rewardsDestination == address(0)) { - _graphToken().approve(address(_graphStaking()), tokensIndexerRewards); - _graphStaking().stakeToProvision(allocation.indexer, address(this), tokensIndexerRewards); - } else { - _graphToken().pushTokens(rewardsDestination, tokensIndexerRewards); + if (tokensIndexerRewards > 0) { + address rewardsDestination = rewardsDestination[allocation.indexer]; + if (rewardsDestination == address(0)) { + _graphToken().approve(address(_graphStaking()), tokensIndexerRewards); + _graphStaking().stakeToProvision(allocation.indexer, address(this), tokensIndexerRewards); + } else { + _graphToken().pushTokens(rewardsDestination, tokensIndexerRewards); + } } } 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 bff35f574..38e9e7865 100644 --- a/packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol +++ b/packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol @@ -27,8 +27,7 @@ contract SubgraphServiceCollectIndexingTest is SubgraphServiceTest { uint256 delegationTokens, uint256 delegationFeeCut ) public useIndexer useAllocation(tokens) useDelegation(delegationTokens) { - // Collect reverts if delegationFeeCut is 100% - delegationFeeCut = bound(delegationFeeCut, 0, MAX_PPM - 1); + delegationFeeCut = bound(delegationFeeCut, 0, MAX_PPM); _setDelegationFeeCut( users.indexer, address(subgraphService), @@ -45,7 +44,6 @@ contract SubgraphServiceCollectIndexingTest is SubgraphServiceTest { uint256 delegationTokens, uint256 delegationFeeCut ) public useIndexer useAllocation(tokens) useDelegation(delegationTokens) { - // Collect reverts if delegationFeeCut is 100% delegationFeeCut = bound(delegationFeeCut, 0, MAX_PPM); _setDelegationFeeCut( users.indexer, @@ -90,8 +88,7 @@ contract SubgraphServiceCollectIndexingTest is SubgraphServiceTest { uint256 delegationTokens, uint256 delegationFeeCut ) public useIndexer useAllocation(tokens) useDelegation(delegationTokens) { - // Collect reverts if delegationFeeCut is 100% - delegationFeeCut = bound(delegationFeeCut, 0, MAX_PPM - 1); + delegationFeeCut = bound(delegationFeeCut, 0, MAX_PPM); _setDelegationFeeCut( users.indexer, address(subgraphService),