@@ -30,7 +30,11 @@ contract Staking is IStaking, Governed {
30
30
31
31
// Percentage of fees going to curators
32
32
// Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
33
- uint256 public curationPercentage;
33
+ uint32 public curationPercentage;
34
+
35
+ // Percentage of fees burned as protocol fee
36
+ // Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
37
+ uint32 public protocolPercentage;
34
38
35
39
// Need to pass this period for channel to be finalized
36
40
uint256 public channelDisputeEpochs;
@@ -223,16 +227,27 @@ contract Staking is IStaking, Governed {
223
227
}
224
228
225
229
/**
226
- * @dev Set the curation percentage of indexer fees sent to curators.
227
- * @param _percentage Percentage of indexer fees sent to curators
230
+ * @dev Set the curation percentage of query fees sent to curators.
231
+ * @param _percentage Percentage of query fees sent to curators
228
232
*/
229
- function setCurationPercentage (uint256 _percentage ) external override onlyGovernor {
233
+ function setCurationPercentage (uint32 _percentage ) external override onlyGovernor {
230
234
// Must be within 0% to 100% (inclusive)
231
235
require (_percentage <= MAX_PPM, "Curation percentage must be below or equal to MAX_PPM " );
232
236
curationPercentage = _percentage;
233
237
emit ParameterUpdated ("curationPercentage " );
234
238
}
235
239
240
+ /**
241
+ * @dev Set a protocol percentage to burn when collecting query fees.
242
+ * @param _percentage Percentage of query fees to burn as protocol fee
243
+ */
244
+ function setProtocolPercentage (uint32 _percentage ) external override onlyGovernor {
245
+ // Must be within 0% to 100% (inclusive)
246
+ require (_percentage <= MAX_PPM, "Protocol percentage must be below or equal to MAX_PPM " );
247
+ protocolPercentage = _percentage;
248
+ emit ParameterUpdated ("protocolPercentage " );
249
+ }
250
+
236
251
/**
237
252
* @dev Set the period in epochs that need to pass before fees in rebate pool can be claimed.
238
253
* @param _channelDisputeEpochs Period in epochs
@@ -867,6 +882,8 @@ contract Staking is IStaking, Governed {
867
882
address _from ,
868
883
uint256 _tokens
869
884
) private {
885
+ uint256 rebateFees = _tokens;
886
+
870
887
// Get allocation related to the channel identifier
871
888
Allocation storage alloc = allocations[_channelID];
872
889
AllocationState allocState = _getAllocationState (_channelID);
@@ -877,11 +894,13 @@ contract Staking is IStaking, Governed {
877
894
"Collect: channel must be active or settled "
878
895
);
879
896
880
- // Calculate curation fees only if the subgraph deployment is curated
881
- uint256 curationFees = _collectCurationFees (alloc.subgraphDeploymentID, _tokens);
897
+ // Collect protocol fees to be burned
898
+ uint256 protocolFees = _collectProtocolFees (rebateFees);
899
+ rebateFees = rebateFees.sub (protocolFees);
882
900
883
- // Calculate rebate fees
884
- uint256 rebateFees = _tokens.sub (curationFees);
901
+ // Calculate curation fees only if the subgraph deployment is curated
902
+ uint256 curationFees = _collectCurationFees (alloc.subgraphDeploymentID, rebateFees);
903
+ rebateFees = rebateFees.sub (curationFees);
885
904
886
905
// Collect funds in the allocated channel
887
906
alloc.collectedFees = alloc.collectedFees.add (rebateFees);
@@ -1013,11 +1032,27 @@ contract Staking is IStaking, Governed {
1013
1032
{
1014
1033
bool isCurationEnabled = curationPercentage > 0 && address (curation) != address (0 );
1015
1034
if (isCurationEnabled && curation.isCurated (_subgraphDeploymentID)) {
1016
- return curationPercentage.mul (_tokens).div (MAX_PPM);
1035
+ return uint256 ( curationPercentage) .mul (_tokens).div (MAX_PPM);
1017
1036
}
1018
1037
return 0 ;
1019
1038
}
1020
1039
1040
+ /**
1041
+ * @dev Collect and burn the protocol fees for an amount of tokens.
1042
+ * @param _tokens Total tokens received used to calculate the amount of fees to collect
1043
+ * @return Amount of protocol fees
1044
+ */
1045
+ function _collectProtocolFees (uint256 _tokens ) private returns (uint256 ) {
1046
+ if (protocolPercentage == 0 ) {
1047
+ return 0 ;
1048
+ }
1049
+ uint256 protocolFees = uint256 (protocolPercentage).mul (_tokens).div (MAX_PPM);
1050
+ if (protocolFees > 0 ) {
1051
+ token.burn (protocolFees);
1052
+ }
1053
+ return protocolFees;
1054
+ }
1055
+
1021
1056
/**
1022
1057
* @dev Return the current state of an allocation
1023
1058
* @param _channelID Address used as the allocation channel identifier
0 commit comments