@@ -929,43 +929,47 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
929
929
AllocationState allocState = _getAllocationState (_allocationID);
930
930
require (allocState != AllocationState.Null, "!collect " );
931
931
932
- // Pull tokens to collect from the authorized sender
933
- IGraphToken graphToken = graphToken ();
934
- require (graphToken.transferFrom (msg .sender , address (this ), _tokens), "!transfer " );
935
-
936
932
// Get allocation
937
933
Allocation storage alloc = allocations[_allocationID];
938
- bytes32 subgraphDeploymentID = alloc.subgraphDeploymentID;
939
934
uint256 queryFees = _tokens;
935
+ uint256 curationFees = 0 ;
936
+ bytes32 subgraphDeploymentID = alloc.subgraphDeploymentID;
940
937
941
- // -- Collect protocol tax --
942
- // If the Allocation is not active or closed we are going to charge a 100% protocol tax
943
- uint256 usedProtocolPercentage = (allocState == AllocationState.Active ||
944
- allocState == AllocationState.Closed)
945
- ? protocolPercentage
946
- : MAX_PPM;
947
- uint256 protocolFees = _collectTax (graphToken, queryFees, usedProtocolPercentage);
948
- queryFees = queryFees.sub (protocolFees);
949
-
950
- // -- Collect curation fees --
951
- // Only if the subgraph deployment is curated
952
- uint256 curationFees = _collectCurationFees (
953
- graphToken,
954
- subgraphDeploymentID,
955
- queryFees,
956
- curationPercentage
957
- );
958
- queryFees = queryFees.sub (curationFees);
959
-
960
- // Add funds to the allocation
961
- alloc.collectedFees = alloc.collectedFees.add (queryFees);
962
-
963
- // When allocation is closed redirect funds to the rebate pool
964
- // This way we can keep collecting tokens even after the allocation is closed and
965
- // before it gets to the finalized state.
966
- if (allocState == AllocationState.Closed) {
967
- Rebates.Pool storage rebatePool = rebates[alloc.closedAtEpoch];
968
- rebatePool.fees = rebatePool.fees.add (queryFees);
938
+ // Process query fees only if non-zero amount
939
+ if (queryFees > 0 ) {
940
+ // Pull tokens to collect from the authorized sender
941
+ IGraphToken graphToken = graphToken ();
942
+ require (graphToken.transferFrom (msg .sender , address (this ), _tokens), "!transfer " );
943
+
944
+ // -- Collect protocol tax --
945
+ // If the Allocation is not active or closed we are going to charge a 100% protocol tax
946
+ uint256 usedProtocolPercentage = (allocState == AllocationState.Active ||
947
+ allocState == AllocationState.Closed)
948
+ ? protocolPercentage
949
+ : MAX_PPM;
950
+ uint256 protocolFees = _collectTax (graphToken, queryFees, usedProtocolPercentage);
951
+ queryFees = queryFees.sub (protocolFees);
952
+
953
+ // -- Collect curation fees --
954
+ // Only if the subgraph deployment is curated
955
+ curationFees = _collectCurationFees (
956
+ graphToken,
957
+ subgraphDeploymentID,
958
+ queryFees,
959
+ curationPercentage
960
+ );
961
+ queryFees = queryFees.sub (curationFees);
962
+
963
+ // Add funds to the allocation
964
+ alloc.collectedFees = alloc.collectedFees.add (queryFees);
965
+
966
+ // When allocation is closed redirect funds to the rebate pool
967
+ // This way we can keep collecting tokens even after the allocation is closed and
968
+ // before it gets to the finalized state.
969
+ if (allocState == AllocationState.Closed) {
970
+ Rebates.Pool storage rebatePool = rebates[alloc.closedAtEpoch];
971
+ rebatePool.fees = rebatePool.fees.add (queryFees);
972
+ }
969
973
}
970
974
971
975
emit AllocationCollected (
0 commit comments