@@ -3,7 +3,8 @@ pragma experimental ABIEncoderV2;
3
3
4
4
/*
5
5
* @title Curation contract
6
- * @notice Allows Curators to signal Subgraphs that are relevant for indexers and earn fees from the Query Market
6
+ * @notice Allows Curators to signal Subgraphs that are relevant for indexers and earn
7
+ * fees from the Query Market
7
8
*/
8
9
9
10
import "./Governed.sol " ;
@@ -40,6 +41,10 @@ contract Curation is Governed, BancorFormula {
40
41
// This is the `startPoolBalance` for the bonding curve
41
42
uint256 public minimumCurationStake;
42
43
44
+ // Fee charged when curator withdraw stake
45
+ // Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
46
+ uint256 public withdrawalFeePercentage;
47
+
43
48
// Mapping of subgraphID => Subgraph
44
49
mapping (bytes32 => Subgraph) public subgraphs;
45
50
@@ -65,12 +70,14 @@ contract Curation is Governed, BancorFormula {
65
70
/**
66
71
* @dev Emitted when `curator` redeemed `shares` for a `subgraphID`.
67
72
* The curator will receive `tokens` according to the value of the bonding curve.
73
+ * An amount of `withdrawalFees` will be collected and burned.
68
74
*/
69
75
event Redeemed (
70
76
address indexed curator ,
71
77
bytes32 indexed subgraphID ,
72
78
uint256 tokens ,
73
- uint256 shares
79
+ uint256 shares ,
80
+ uint256 withdrawalFees
74
81
);
75
82
76
83
/**
@@ -151,6 +158,20 @@ contract Curation is Governed, BancorFormula {
151
158
emit ParameterUpdated ("minimumCurationStake " );
152
159
}
153
160
161
+ /**
162
+ * @dev Set the fee percentage to charge when a curator withdraws stake
163
+ * @param _percentage Percentage fee charged when withdrawing stake
164
+ */
165
+ function setWithdrawalFeePercentage (uint256 _percentage ) external onlyGovernor {
166
+ // Must be within 0% to 100% (inclusive)
167
+ require (
168
+ _percentage <= MAX_PPM,
169
+ "Withdrawal fee percentage must be below or equal to MAX_PPM "
170
+ );
171
+ withdrawalFeePercentage = _percentage;
172
+ emit ParameterUpdated ("withdrawalFeePercentage " );
173
+ }
174
+
154
175
/**
155
176
* @dev Assign Graph Tokens received from staking to the subgraph reserve
156
177
* @param _subgraphID Subgraph where funds should be allocated as reserves
@@ -209,10 +230,17 @@ contract Curation is Governed, BancorFormula {
209
230
delete subgraphs[_subgraphID];
210
231
}
211
232
233
+ // Calculate withdrawal fees and burn the tokens
234
+ uint256 withdrawalFees = percentageOf (withdrawalFeePercentage, tokens);
235
+ if (withdrawalFees > 0 ) {
236
+ tokens = tokens.sub (withdrawalFees);
237
+ token.burn (withdrawalFees);
238
+ }
239
+
212
240
// Return the tokens to the curator
213
241
require (token.transfer (curator, tokens), "Error sending curator tokens " );
214
242
215
- emit Redeemed (curator, _subgraphID, tokens, _shares);
243
+ emit Redeemed (curator, _subgraphID, tokens, _shares, withdrawalFees );
216
244
}
217
245
218
246
/**
@@ -377,4 +405,14 @@ contract Curation is Governed, BancorFormula {
377
405
378
406
emit Staked (_curator, _subgraphID, _tokens, shares);
379
407
}
408
+
409
+ /**
410
+ * @dev Calculate the percentage for value in parts per million (PPM)
411
+ * @param _ppm Parts per million
412
+ * @param _value Value to calculate percentage of
413
+ * @return Percentage of value
414
+ */
415
+ function percentageOf (uint256 _ppm , uint256 _value ) private pure returns (uint256 ) {
416
+ return _ppm.mul (_value).div (MAX_PPM);
417
+ }
380
418
}
0 commit comments