1
1
pragma solidity ^ 0.6.4 ;
2
- pragma experimental ABIEncoderV2;
2
+
3
+ import "@openzeppelin/contracts/math/SafeMath.sol " ;
3
4
4
5
import "./Governed.sol " ;
5
- import "./GraphToken.sol " ;
6
+ import "./ICuration.sol " ;
7
+ import "./IGraphToken.sol " ;
6
8
import "./bancor/BancorFormula.sol " ;
7
- import "@openzeppelin/contracts/math/SafeMath.sol " ;
8
9
9
10
/**
10
11
* @title Curation contract
@@ -14,38 +15,38 @@ import "@openzeppelin/contracts/math/SafeMath.sol";
14
15
* A curators stake goes to a curation pool along with the stakes of other curators,
15
16
* only one pool exists for each subgraph deployment.
16
17
*/
17
- contract Curation is Governed , BancorFormula {
18
+ contract Curation is ICuration , BancorFormula , Governed {
18
19
using SafeMath for uint256 ;
19
20
20
21
// -- Curation --
21
22
22
23
struct CurationPool {
23
- uint256 reserveRatio; // Ratio for the bonding curve
24
24
uint256 tokens; // Tokens stored as reserves for the SubgraphDeployment
25
25
uint256 shares; // Shares issued for the SubgraphDeployment
26
+ uint32 reserveRatio; // Ratio for the bonding curve
26
27
mapping (address => uint256 ) curatorShares; // Mapping of curator => shares
27
28
}
28
29
29
30
// 100% in parts per million
30
- uint256 private constant MAX_PPM = 1000000 ;
31
+ uint32 private constant MAX_PPM = 1000000 ;
31
32
32
33
// Amount of shares you get with your minimum token stake
33
34
uint256 private constant SHARES_PER_MINIMUM_STAKE = 1 ether ;
34
35
35
36
// -- State --
36
37
38
+ // Fee charged when curator withdraw stake
39
+ // Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
40
+ uint32 public withdrawalFeePercentage;
41
+
37
42
// Default reserve ratio to configure curator shares bonding curve
38
43
// Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
39
- uint256 public defaultReserveRatio;
44
+ uint32 public defaultReserveRatio;
40
45
41
46
// Minimum amount allowed to be staked by curators
42
47
// This is the `startPoolBalance` for the bonding curve
43
48
uint256 public minimumCurationStake;
44
49
45
- // Fee charged when curator withdraw stake
46
- // Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
47
- uint256 public withdrawalFeePercentage;
48
-
49
50
// Mapping of subgraphDeploymentID => CurationPool
50
51
// There is only one CurationPool per SubgraphDeployment
51
52
mapping (bytes32 => CurationPool) public pools;
@@ -54,7 +55,7 @@ contract Curation is Governed, BancorFormula {
54
55
address public staking;
55
56
56
57
// Token used for staking
57
- GraphToken public token;
58
+ IGraphToken public token;
58
59
59
60
// -- Events --
60
61
@@ -98,10 +99,10 @@ contract Curation is Governed, BancorFormula {
98
99
constructor (
99
100
address _governor ,
100
101
address _token ,
101
- uint256 _defaultReserveRatio ,
102
+ uint32 _defaultReserveRatio ,
102
103
uint256 _minimumCurationStake
103
104
) public Governed (_governor) {
104
- token = GraphToken (_token);
105
+ token = IGraphToken (_token);
105
106
_setDefaultReserveRatio (_defaultReserveRatio);
106
107
_setMinimumCurationStake (_minimumCurationStake);
107
108
}
@@ -111,15 +112,15 @@ contract Curation is Governed, BancorFormula {
111
112
* @notice Update the default reserver ratio to `_defaultReserveRatio`
112
113
* @param _defaultReserveRatio Reserve ratio (in PPM)
113
114
*/
114
- function setDefaultReserveRatio (uint256 _defaultReserveRatio ) external onlyGovernor {
115
+ function setDefaultReserveRatio (uint32 _defaultReserveRatio ) external override onlyGovernor {
115
116
_setDefaultReserveRatio (_defaultReserveRatio);
116
117
}
117
118
118
119
/**
119
120
* @dev Set the default reserve ratio percentage for a curation pool.
120
121
* @param _defaultReserveRatio Reserve ratio (in PPM)
121
122
*/
122
- function _setDefaultReserveRatio (uint256 _defaultReserveRatio ) private {
123
+ function _setDefaultReserveRatio (uint32 _defaultReserveRatio ) private {
123
124
// Reserve Ratio must be within 0% to 100% (exclusive, in PPM)
124
125
require (_defaultReserveRatio > 0 , "Default reserve ratio must be > 0 " );
125
126
require (
@@ -136,7 +137,7 @@ contract Curation is Governed, BancorFormula {
136
137
* @notice Update the staking contract to `_staking`
137
138
* @param _staking Address of the staking contract
138
139
*/
139
- function setStaking (address _staking ) external onlyGovernor {
140
+ function setStaking (address _staking ) external override onlyGovernor {
140
141
staking = _staking;
141
142
emit ParameterUpdated ("staking " );
142
143
}
@@ -146,7 +147,7 @@ contract Curation is Governed, BancorFormula {
146
147
* @notice Update the minimum stake amount to `_minimumCurationStake`
147
148
* @param _minimumCurationStake Minimum amount of tokens required stake
148
149
*/
149
- function setMinimumCurationStake (uint256 _minimumCurationStake ) external onlyGovernor {
150
+ function setMinimumCurationStake (uint256 _minimumCurationStake ) external override onlyGovernor {
150
151
_setMinimumCurationStake (_minimumCurationStake);
151
152
}
152
153
@@ -164,7 +165,7 @@ contract Curation is Governed, BancorFormula {
164
165
* @dev Set the fee percentage to charge when a curator withdraws stake.
165
166
* @param _percentage Percentage fee charged when withdrawing stake
166
167
*/
167
- function setWithdrawalFeePercentage (uint256 _percentage ) external onlyGovernor {
168
+ function setWithdrawalFeePercentage (uint32 _percentage ) external override onlyGovernor {
168
169
// Must be within 0% to 100% (inclusive)
169
170
require (
170
171
_percentage <= MAX_PPM,
@@ -179,7 +180,7 @@ contract Curation is Governed, BancorFormula {
179
180
* @param _subgraphDeploymentID SubgraphDeployment where funds should be allocated as reserves
180
181
* @param _tokens Amount of Graph Tokens to add to reserves
181
182
*/
182
- function collect (bytes32 _subgraphDeploymentID , uint256 _tokens ) external {
183
+ function collect (bytes32 _subgraphDeploymentID , uint256 _tokens ) external override {
183
184
require (msg .sender == staking, "Caller must be the staking contract " );
184
185
185
186
// Transfer tokens collected from the staking contract to this contract
@@ -197,7 +198,7 @@ contract Curation is Governed, BancorFormula {
197
198
* @param _subgraphDeploymentID SubgraphDeployment where the curator is staking Graph Tokens
198
199
* @param _tokens Amount of Graph Tokens to stake
199
200
*/
200
- function stake (bytes32 _subgraphDeploymentID , uint256 _tokens ) external {
201
+ function stake (bytes32 _subgraphDeploymentID , uint256 _tokens ) external override {
201
202
address curator = msg .sender ;
202
203
203
204
// Need to stake some funds
@@ -219,7 +220,7 @@ contract Curation is Governed, BancorFormula {
219
220
* @param _subgraphDeploymentID SubgraphDeployment the curator is returning shares
220
221
* @param _shares Amount of shares to return
221
222
*/
222
- function redeem (bytes32 _subgraphDeploymentID , uint256 _shares ) external {
223
+ function redeem (bytes32 _subgraphDeploymentID , uint256 _shares ) external override {
223
224
address curator = msg .sender ;
224
225
CurationPool storage curationPool = pools[_subgraphDeploymentID];
225
226
@@ -238,7 +239,7 @@ contract Curation is Governed, BancorFormula {
238
239
}
239
240
240
241
// Calculate withdrawal fees and burn the tokens
241
- uint256 withdrawalFees = percentageOf (withdrawalFeePercentage, tokens);
242
+ uint256 withdrawalFees = uint256 (withdrawalFeePercentage). mul ( tokens). div (MAX_PPM );
242
243
if (withdrawalFees > 0 ) {
243
244
tokens = tokens.sub (withdrawalFees);
244
245
token.burn (withdrawalFees);
@@ -255,7 +256,16 @@ contract Curation is Governed, BancorFormula {
255
256
* @param _subgraphDeploymentID SubgraphDeployment to check if curated
256
257
* @return True if curated
257
258
*/
258
- function isCurated (bytes32 _subgraphDeploymentID ) public view returns (bool ) {
259
+ function isCurated (bytes32 _subgraphDeploymentID ) external override view returns (bool ) {
260
+ return _isCurated (_subgraphDeploymentID);
261
+ }
262
+
263
+ /**
264
+ * @dev Check if any Graph tokens are staked for a SubgraphDeployment.
265
+ * @param _subgraphDeploymentID SubgraphDeployment to check if curated
266
+ * @return True if curated
267
+ */
268
+ function _isCurated (bytes32 _subgraphDeploymentID ) private view returns (bool ) {
259
269
return pools[_subgraphDeploymentID].tokens > 0 ;
260
270
}
261
271
@@ -290,9 +300,9 @@ contract Curation is Governed, BancorFormula {
290
300
CurationPool memory curationPool = pools[_subgraphDeploymentID];
291
301
if (curationPool.tokens == 0 ) {
292
302
curationPool = CurationPool (
293
- defaultReserveRatio,
294
303
minimumCurationStake,
295
- SHARES_PER_MINIMUM_STAKE
304
+ SHARES_PER_MINIMUM_STAKE,
305
+ defaultReserveRatio
296
306
);
297
307
tokens = tokens.sub (curationPool.tokens);
298
308
shares = curationPool.shares;
@@ -393,7 +403,7 @@ contract Curation is Governed, BancorFormula {
393
403
*/
394
404
function _collect (bytes32 _subgraphDeploymentID , uint256 _tokens ) private {
395
405
require (
396
- isCurated (_subgraphDeploymentID),
406
+ _isCurated (_subgraphDeploymentID),
397
407
"SubgraphDeployment must be curated to collect fees "
398
408
);
399
409
@@ -418,7 +428,7 @@ contract Curation is Governed, BancorFormula {
418
428
CurationPool storage curationPool = pools[_subgraphDeploymentID];
419
429
420
430
// If it hasn't been curated before then initialize the curve
421
- if (! isCurated (_subgraphDeploymentID)) {
431
+ if (! _isCurated (_subgraphDeploymentID)) {
422
432
require (_tokens >= minimumCurationStake, "Curation stake is below minimum required " );
423
433
424
434
// Initialize
@@ -430,14 +440,4 @@ contract Curation is Governed, BancorFormula {
430
440
431
441
emit Staked (_curator, _subgraphDeploymentID, _tokens, shares);
432
442
}
433
-
434
- /**
435
- * @dev Calculate the percentage for value in parts per million (PPM)
436
- * @param _ppm Parts per million
437
- * @param _value Value to calculate percentage of
438
- * @return Percentage of value
439
- */
440
- function percentageOf (uint256 _ppm , uint256 _value ) private pure returns (uint256 ) {
441
- return _ppm.mul (_value).div (MAX_PPM);
442
- }
443
443
}
0 commit comments