@@ -23,7 +23,7 @@ contract Curation is Governed, BancorFormula {
23
23
uint256 reserveRatio; // Ratio for the bonding curve
24
24
uint256 tokens; // Tokens that constitute the subgraph reserve
25
25
uint256 shares; // Shares issued for this subgraph
26
- mapping (address => uint256 ) curatorShares;
26
+ mapping (address => uint256 ) curatorShares; // Mapping of curator => shares
27
27
}
28
28
29
29
// 100% in parts per million
@@ -41,33 +41,55 @@ contract Curation is Governed, BancorFormula {
41
41
// Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
42
42
uint256 public defaultReserveRatio;
43
43
44
- // Minimum amount allowed to be staked by Market Curators
44
+ // Minimum amount allowed to be staked by curators
45
45
// This is the `startPoolBalance` for the bonding curve
46
46
uint256 public minimumCurationStake;
47
47
48
- // Total staked tokens across all subgraphs
49
- uint256 public totalTokens;
50
-
51
- // Subgraphs and curators mapping : subgraphID => Subgraph
48
+ // Mapping of subgraphID => Subgraph
52
49
mapping (bytes32 => Subgraph) public subgraphs;
53
50
54
- // Address of a party that will distribute fees to subgraph reserves
55
- address public distributor ;
51
+ // Address of a staking contract that will distribute fees to subgraph reserves
52
+ address public staking ;
56
53
57
54
// Token used for staking
58
55
GraphToken public token;
59
56
60
57
// -- Events --
61
58
62
- event CuratorStakeUpdated (address indexed curator , bytes32 indexed subgraphID , uint256 shares );
63
- event SubgraphStakeUpdated (bytes32 indexed subgraphID , uint256 shares , uint256 tokens );
59
+ /**
60
+ * @dev Emitted when `curator` staked `tokens` on `subgraphID` as curation signal.
61
+ * The `curator` receives `shares` amount according to the subgraph bonding curve.
62
+ */
63
+ event Staked (
64
+ address indexed curator ,
65
+ bytes32 indexed subgraphID ,
66
+ uint256 tokens ,
67
+ uint256 shares
68
+ );
69
+
70
+ /**
71
+ * @dev Emitted when `curator` redeemed `shares` for a `subgraphID`.
72
+ * The curator will receive `tokens` according to the value of the bonding curve.
73
+ */
74
+ event Redeemed (
75
+ address indexed curator ,
76
+ bytes32 indexed subgraphID ,
77
+ uint256 tokens ,
78
+ uint256 shares
79
+ );
80
+
81
+ /**
82
+ * @dev Emitted when `tokens` amount were collected for `subgraphID` as part of fees
83
+ * distributed by index node from the settlement of query fees on the subgraph.
84
+ */
85
+ event Collected (bytes32 indexed subgraphID , uint256 tokens );
64
86
65
87
/**
66
88
* @dev Contract Constructor
67
89
* @param _governor Owner address of this contract
68
90
* @param _token Address of the Graph Protocol token
69
- * @param _defaultReserveRatio Address of the staking contract used for slashing
70
- * @param _minimumCurationStake Percent of stake the fisherman gets on slashing (in PPM)
91
+ * @param _defaultReserveRatio Reserve ratio used for the bonding curves of subgraphs
92
+ * @param _minimumCurationStake Minimum amount of tokens that curators can stake on subgraphs
71
93
*/
72
94
constructor (
73
95
address _governor ,
@@ -105,12 +127,12 @@ contract Curation is Governed, BancorFormula {
105
127
}
106
128
107
129
/**
108
- * @dev Set the address of party in charge of fee distributions into reserves
109
- * @notice Update the distributor address to `_distributor `
110
- * @param _distributor Address of the party doing fee distributions
130
+ * @dev Set the staking contract used for fees distribution
131
+ * @notice Update the staking contract to `_staking `
132
+ * @param _staking Address of the staking contract
111
133
*/
112
- function setDistributor (address _distributor ) external onlyGovernor {
113
- distributor = _distributor ;
134
+ function setStaking (address _staking ) external onlyGovernor {
135
+ staking = _staking ;
114
136
}
115
137
116
138
/**
@@ -149,52 +171,45 @@ contract Curation is Governed, BancorFormula {
149
171
// Decode subgraphID
150
172
bytes32 subgraphID = _data.slice (0 , 32 ).toBytes32 (0 );
151
173
152
- // Transfers from distributor means we are assigning fees to reserves
153
- if (_from == distributor ) {
174
+ // Transfers from staking means we are assigning fees to reserves
175
+ if (_from == staking ) {
154
176
_collect (subgraphID, _value);
155
177
return true ;
156
178
}
157
179
158
- // Any other source address means they are staking
180
+ // Any other source address means they are staking tokens for shares
159
181
_stake (_from, subgraphID, _value);
160
182
return true ;
161
183
}
162
184
163
185
/**
164
- * @dev Return any amount of shares to get tokens back (above the minimum)
165
- * @notice Unstake _shares from the subgraph with _subgraphID
186
+ * @dev Return an amount of shares to get tokens back
187
+ * @notice Redeem _shares from the subgraph with _subgraphID
166
188
* @param _subgraphID Subgraph ID the Curator is returning shares for
167
189
* @param _shares Amount of shares to return
168
190
*/
169
- function unstake (bytes32 _subgraphID , uint256 _shares ) external {
191
+ function redeem (bytes32 _subgraphID , uint256 _shares ) external {
170
192
address curator = msg .sender ;
171
193
Subgraph storage subgraph = subgraphs[_subgraphID];
172
194
173
- require (_shares > 0 , "Cannot unstake zero shares " );
195
+ require (_shares > 0 , "Cannot redeem zero shares " );
174
196
require (
175
197
subgraph.curatorShares[curator] >= _shares,
176
- "Cannot unstake more shares than you own "
198
+ "Cannot redeem more shares than you own "
177
199
);
178
200
179
201
// Update balance and get the amount of tokens to refund based on returned shares
180
- uint256 tokensToRefund = _sellShares (curator, _subgraphID, _shares);
181
-
182
- // Ensure we are not under minimum required stake
183
- require (
184
- subgraph.tokens >= minimumCurationStake || subgraph.tokens == 0 ,
185
- "Cannot unstake below minimum required stake for subgraph "
186
- );
202
+ uint256 tokens = _sellShares (curator, _subgraphID, _shares);
187
203
188
- // Delete if left without stakes
189
- if (subgraph.tokens == 0 ) {
204
+ // If all shares redeemed delete subgraph
205
+ if (subgraph.shares == 0 ) {
190
206
delete subgraphs[_subgraphID];
191
207
}
192
208
193
209
// Return the tokens to the curator
194
- require (token.transfer (curator, tokensToRefund ), "Error sending curator tokens " );
210
+ require (token.transfer (curator, tokens ), "Error sending curator tokens " );
195
211
196
- emit CuratorStakeUpdated (curator, _subgraphID, subgraph.curatorShares[curator]);
197
- emit SubgraphStakeUpdated (_subgraphID, subgraph.shares, subgraph.tokens);
212
+ emit Redeemed (curator, _subgraphID, tokens, _shares);
198
213
}
199
214
200
215
/**
@@ -289,9 +304,6 @@ contract Curation is Governed, BancorFormula {
289
304
subgraph.shares = subgraph.shares.add (shares);
290
305
subgraph.curatorShares[_curator] = subgraph.curatorShares[_curator].add (shares);
291
306
292
- // Update global balance
293
- totalTokens = totalTokens.add (_tokens);
294
-
295
307
return shares;
296
308
}
297
309
@@ -316,35 +328,29 @@ contract Curation is Governed, BancorFormula {
316
328
subgraph.shares = subgraph.shares.sub (_shares);
317
329
subgraph.curatorShares[_curator] = subgraph.curatorShares[_curator].sub (_shares);
318
330
319
- // Update global balance
320
- totalTokens = totalTokens.sub (tokens);
321
-
322
331
return tokens;
323
332
}
324
333
325
334
/**
326
- * @dev Assign Graph Tokens received from distributor to the subgraph reserve
335
+ * @dev Assign Graph Tokens received from staking to the subgraph reserve
327
336
* @param _subgraphID Subgraph where funds should be allocated as reserves
328
337
* @param _tokens Amount of Graph Tokens to add to reserves
329
338
*/
330
339
function _collect (bytes32 _subgraphID , uint256 _tokens ) private {
331
340
require (isSubgraphCurated (_subgraphID), "Subgraph must be curated to collect fees " );
332
341
333
- // Collect new funds to reserve
342
+ // Collect new funds into a subgraph reserve
334
343
Subgraph storage subgraph = subgraphs[_subgraphID];
335
344
subgraph.tokens = subgraph.tokens.add (_tokens);
336
345
337
- // Update global tokens balance
338
- totalTokens = totalTokens.add (_tokens);
339
-
340
- emit SubgraphStakeUpdated (_subgraphID, subgraph.shares, subgraph.tokens);
346
+ emit Collected (_subgraphID, _tokens);
341
347
}
342
348
343
349
/**
344
- * @dev Stake Graph Tokens for Market Curation by subgraphID
345
- * @param _subgraphID Subgraph ID the Curator is staking Graph Tokens for
346
- * @param _curator Address of Staking party
347
- * @param _tokens Amount of Graph Tokens to be staked
350
+ * @dev Deposit Graph Tokens in exchange for shares of a subgraph
351
+ * @param _subgraphID Subgraph ID where the curator is staking Graph Tokens
352
+ * @param _curator Address of staking party
353
+ * @param _tokens Amount of Graph Tokens to stake
348
354
*/
349
355
function _stake (address _curator , bytes32 _subgraphID , uint256 _tokens ) private {
350
356
Subgraph storage subgraph = subgraphs[_subgraphID];
@@ -358,9 +364,8 @@ contract Curation is Governed, BancorFormula {
358
364
}
359
365
360
366
// Update subgraph balances
361
- _buyShares (_curator, _subgraphID, _tokens);
367
+ uint256 shares = _buyShares (_curator, _subgraphID, _tokens);
362
368
363
- emit CuratorStakeUpdated (_curator, _subgraphID, subgraph.curatorShares[_curator]);
364
- emit SubgraphStakeUpdated (_subgraphID, subgraph.shares, subgraph.tokens);
369
+ emit Staked (_curator, _subgraphID, _tokens, shares);
365
370
}
366
371
}
0 commit comments