Skip to content

Commit 114725b

Browse files
abarmatdavekay100
andauthored
curation: use curation signal (#246)
Rename to mint / burn verbs and signal as noun Co-authored-by: David Kajpust <[email protected]>
1 parent 7d3fb7b commit 114725b

File tree

8 files changed

+167
-169
lines changed

8 files changed

+167
-169
lines changed

contracts/curation/Curation.sol

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,32 @@ contract Curation is CurationV1Storage, ICuration, Governed {
2222
// 100% in parts per million
2323
uint32 private constant MAX_PPM = 1000000;
2424

25-
// Amount of shares you get with your minimum token stake
26-
uint256 private constant SHARES_PER_MINIMUM_STAKE = 1 ether;
25+
// Amount of signal you get with your minimum token stake
26+
uint256 private constant SIGNAL_PER_MINIMUM_STAKE = 1 ether;
2727

2828
// -- Events --
2929

3030
/**
3131
* @dev Emitted when `curator` staked `tokens` on `subgraphDeploymentID` as curation signal.
32-
* The `curator` receives `shares` amount according to the curation pool bonding curve.
32+
* The `curator` receives `signal` amount according to the curation pool bonding curve.
3333
*/
34-
event Staked(
34+
event Signalled(
3535
address indexed curator,
3636
bytes32 indexed subgraphDeploymentID,
3737
uint256 tokens,
38-
uint256 shares
38+
uint256 signal
3939
);
4040

4141
/**
42-
* @dev Emitted when `curator` redeemed `shares` for a `subgraphDeploymentID`.
42+
* @dev Emitted when `curator` burned `signal` for a `subgraphDeploymentID`.
4343
* The curator will receive `tokens` according to the value of the bonding curve.
4444
* An amount of `withdrawalFees` will be collected and burned.
4545
*/
46-
event Redeemed(
46+
event Burned(
4747
address indexed curator,
4848
bytes32 indexed subgraphDeploymentID,
4949
uint256 tokens,
50-
uint256 shares,
50+
uint256 signal,
5151
uint256 withdrawalFees
5252
);
5353

@@ -176,11 +176,11 @@ contract Curation is CurationV1Storage, ICuration, Governed {
176176
}
177177

178178
/**
179-
* @dev Stake Graph Tokens in exchange for shares of a SubgraphDeployment curation pool.
180-
* @param _subgraphDeploymentID SubgraphDeployment where the curator is staking Graph Tokens
179+
* @dev Stake Graph Tokens in exchange for signal of a SubgraphDeployment curation pool.
180+
* @param _subgraphDeploymentID Subgraph deployment pool from where to mint signal
181181
* @param _tokens Amount of Graph Tokens to stake
182182
*/
183-
function stake(bytes32 _subgraphDeploymentID, uint256 _tokens) external override {
183+
function mint(bytes32 _subgraphDeploymentID, uint256 _tokens) external override {
184184
address curator = msg.sender;
185185

186186
// Need to stake some funds
@@ -193,30 +193,30 @@ contract Curation is CurationV1Storage, ICuration, Governed {
193193
);
194194

195195
// Stake tokens to a curation pool reserve
196-
_stake(curator, _subgraphDeploymentID, _tokens);
196+
_mint(curator, _subgraphDeploymentID, _tokens);
197197
}
198198

199199
/**
200-
* @dev Return an amount of shares to get tokens back.
201-
* @notice Redeem _shares from the SubgraphDeployment curation pool
202-
* @param _subgraphDeploymentID SubgraphDeployment the curator is returning shares
203-
* @param _shares Amount of shares to return
200+
* @dev Return an amount of signal to get tokens back.
201+
* @notice Burn _signal from the SubgraphDeployment curation pool
202+
* @param _subgraphDeploymentID SubgraphDeployment the curator is returning signal
203+
* @param _signal Amount of signal to return
204204
*/
205-
function redeem(bytes32 _subgraphDeploymentID, uint256 _shares) external override {
205+
function burn(bytes32 _subgraphDeploymentID, uint256 _signal) external override {
206206
address curator = msg.sender;
207207
CurationPool storage curationPool = pools[_subgraphDeploymentID];
208208

209-
require(_shares > 0, "Cannot redeem zero shares");
209+
require(_signal > 0, "Cannot burn zero signal");
210210
require(
211-
curationPool.curatorShares[curator] >= _shares,
212-
"Cannot redeem more shares than you own"
211+
curationPool.curatorSignal[curator] >= _signal,
212+
"Cannot burn more signal than you own"
213213
);
214214

215-
// Update balance and get the amount of tokens to refund based on returned shares
216-
uint256 tokens = _sellShares(curator, _subgraphDeploymentID, _shares);
215+
// Update balance and get the amount of tokens to refund based on returned signal
216+
uint256 tokens = _burnSignal(curator, _subgraphDeploymentID, _signal);
217217

218-
// If all shares redeemed delete the curation pool
219-
if (curationPool.shares == 0) {
218+
// If all signal burnt delete the curation pool
219+
if (curationPool.signal == 0) {
220220
delete pools[_subgraphDeploymentID];
221221
}
222222

@@ -230,7 +230,7 @@ contract Curation is CurationV1Storage, ICuration, Governed {
230230
// Return the tokens to the curator
231231
require(token.transfer(curator, tokens), "Error sending curator tokens");
232232

233-
emit Redeemed(curator, _subgraphDeploymentID, tokens, _shares, withdrawalFees);
233+
emit Burned(curator, _subgraphDeploymentID, tokens, _signal, withdrawalFees);
234234
}
235235

236236
/**
@@ -252,141 +252,141 @@ contract Curation is CurationV1Storage, ICuration, Governed {
252252
}
253253

254254
/**
255-
* @dev Get the number of shares a curator has on a curation pool.
256-
* @param _curator Curator owning the shares
257-
* @param _subgraphDeploymentID SubgraphDeployment of issued shares
258-
* @return Number of shares owned by a curator for the SubgraphDeployment
255+
* @dev Get the amount of signal a curator has on a curation pool.
256+
* @param _curator Curator owning signal
257+
* @param _subgraphDeploymentID SubgraphDeployment of issued signal
258+
* @return Amount of signal owned by a curator for the SubgraphDeployment
259259
*/
260-
function getCuratorShares(address _curator, bytes32 _subgraphDeploymentID)
260+
function getCuratorSignal(address _curator, bytes32 _subgraphDeploymentID)
261261
public
262262
view
263263
returns (uint256)
264264
{
265-
return pools[_subgraphDeploymentID].curatorShares[_curator];
265+
return pools[_subgraphDeploymentID].curatorSignal[_curator];
266266
}
267267

268268
/**
269-
* @dev Calculate number of shares that can be bought with tokens in a curation pool.
270-
* @param _subgraphDeploymentID SubgraphDeployment to buy shares
271-
* @param _tokens Amount of tokens used to buy shares
272-
* @return Amount of shares that can be bought
269+
* @dev Calculate amount of signal that can be bought with tokens in a curation pool.
270+
* @param _subgraphDeploymentID Subgraph deployment to mint signal
271+
* @param _tokens Amount of tokens used to mint signal
272+
* @return Amount of signal that can be bought
273273
*/
274-
function tokensToShares(bytes32 _subgraphDeploymentID, uint256 _tokens)
274+
function tokensToSignal(bytes32 _subgraphDeploymentID, uint256 _tokens)
275275
public
276276
view
277277
returns (uint256)
278278
{
279279
// Handle initialization of bonding curve
280280
uint256 tokens = _tokens;
281-
uint256 shares = 0;
281+
uint256 signal = 0;
282282
CurationPool memory curationPool = pools[_subgraphDeploymentID];
283283
if (curationPool.tokens == 0) {
284284
curationPool = CurationPool(
285285
minimumCurationStake,
286-
SHARES_PER_MINIMUM_STAKE,
286+
SIGNAL_PER_MINIMUM_STAKE,
287287
defaultReserveRatio
288288
);
289289
tokens = tokens.sub(curationPool.tokens);
290-
shares = curationPool.shares;
290+
signal = curationPool.signal;
291291
}
292292

293293
return
294294
calculatePurchaseReturn(
295-
curationPool.shares,
295+
curationPool.signal,
296296
curationPool.tokens,
297297
uint32(curationPool.reserveRatio),
298298
tokens
299-
) + shares;
299+
) + signal;
300300
}
301301

302302
/**
303-
* @dev Calculate number of tokens to get when selling shares from a curation pool.
304-
* @param _subgraphDeploymentID SubgraphDeployment to sell shares
305-
* @param _shares Amount of shares to sell
306-
* @return Amount of tokens to get after selling shares
303+
* @dev Calculate number of tokens to get when burning signal from a curation pool.
304+
* @param _subgraphDeploymentID Subgraph deployment to burn signal
305+
* @param _signal Amount of signal to burn
306+
* @return Amount of tokens to get after burning signal
307307
*/
308-
function sharesToTokens(bytes32 _subgraphDeploymentID, uint256 _shares)
308+
function signalToTokens(bytes32 _subgraphDeploymentID, uint256 _signal)
309309
public
310310
view
311311
returns (uint256)
312312
{
313313
CurationPool memory curationPool = pools[_subgraphDeploymentID];
314314
require(
315315
curationPool.tokens > 0,
316-
"SubgraphDeployment must be curated to perform calculations"
316+
"Subgraph deployment must be curated to perform calculations"
317317
);
318318
require(
319-
curationPool.shares >= _shares,
320-
"Shares must be above or equal to shares issued in the curation pool"
319+
curationPool.signal >= _signal,
320+
"Signal must be above or equal to signal issued in the curation pool"
321321
);
322322
return
323323
calculateSaleReturn(
324-
curationPool.shares,
324+
curationPool.signal,
325325
curationPool.tokens,
326326
uint32(curationPool.reserveRatio),
327-
_shares
327+
_signal
328328
);
329329
}
330330

331331
/**
332-
* @dev Update balances after buy of shares and deposit of tokens.
333-
* @param _curator Curator
334-
* @param _subgraphDeploymentID SubgraphDeployment
332+
* @dev Update balances after mint of signal and deposit of tokens.
333+
* @param _curator Curator address
334+
* @param _subgraphDeploymentID Subgraph deployment from where to mint signal
335335
* @param _tokens Amount of tokens
336-
* @return Number of shares bought
336+
* @return Amount of signal bought
337337
*/
338-
function _buyShares(
338+
function _mintSignal(
339339
address _curator,
340340
bytes32 _subgraphDeploymentID,
341341
uint256 _tokens
342342
) private returns (uint256) {
343343
CurationPool storage curationPool = pools[_subgraphDeploymentID];
344-
uint256 shares = tokensToShares(_subgraphDeploymentID, _tokens);
344+
uint256 signal = tokensToSignal(_subgraphDeploymentID, _tokens);
345345

346346
// Update tokens
347347
curationPool.tokens = curationPool.tokens.add(_tokens);
348348

349-
// Update shares
350-
curationPool.shares = curationPool.shares.add(shares);
351-
curationPool.curatorShares[_curator] = curationPool.curatorShares[_curator].add(shares);
349+
// Update signal
350+
curationPool.signal = curationPool.signal.add(signal);
351+
curationPool.curatorSignal[_curator] = curationPool.curatorSignal[_curator].add(signal);
352352

353-
return shares;
353+
return signal;
354354
}
355355

356356
/**
357-
* @dev Update balances after sell of shares and return of tokens.
358-
* @param _curator Curator
359-
* @param _subgraphDeploymentID SubgraphDeployment
360-
* @param _shares Amount of shares
357+
* @dev Update balances after burn of signal and return of tokens.
358+
* @param _curator Curator address
359+
* @param _subgraphDeploymentID Subgraph deployment pool to burn signal
360+
* @param _signal Amount of signal
361361
* @return Number of tokens received
362362
*/
363-
function _sellShares(
363+
function _burnSignal(
364364
address _curator,
365365
bytes32 _subgraphDeploymentID,
366-
uint256 _shares
366+
uint256 _signal
367367
) private returns (uint256) {
368368
CurationPool storage curationPool = pools[_subgraphDeploymentID];
369-
uint256 tokens = sharesToTokens(_subgraphDeploymentID, _shares);
369+
uint256 tokens = signalToTokens(_subgraphDeploymentID, _signal);
370370

371371
// Update tokens
372372
curationPool.tokens = curationPool.tokens.sub(tokens);
373373

374-
// Update shares
375-
curationPool.shares = curationPool.shares.sub(_shares);
376-
curationPool.curatorShares[_curator] = curationPool.curatorShares[_curator].sub(_shares);
374+
// Update signal
375+
curationPool.signal = curationPool.signal.sub(_signal);
376+
curationPool.curatorSignal[_curator] = curationPool.curatorSignal[_curator].sub(_signal);
377377

378378
return tokens;
379379
}
380380

381381
/**
382382
* @dev Assign Graph Tokens received from staking to the curation pool reserve.
383-
* @param _subgraphDeploymentID SubgraphDeployment where funds should be allocated as reserves
383+
* @param _subgraphDeploymentID Subgraph deployment where funds should be allocated as reserves
384384
* @param _tokens Amount of Graph Tokens to add to reserves
385385
*/
386386
function _collect(bytes32 _subgraphDeploymentID, uint256 _tokens) private {
387387
require(
388388
_isCurated(_subgraphDeploymentID),
389-
"SubgraphDeployment must be curated to collect fees"
389+
"Subgraph deployment must be curated to collect fees"
390390
);
391391

392392
// Collect new funds into reserve
@@ -397,12 +397,12 @@ contract Curation is CurationV1Storage, ICuration, Governed {
397397
}
398398

399399
/**
400-
* @dev Deposit Graph Tokens in exchange for shares of a curation pool.
400+
* @dev Deposit Graph Tokens in exchange for signal of a curation pool.
401401
* @param _curator Address of the staking party
402-
* @param _subgraphDeploymentID SubgraphDeployment where the curator is staking tokens
402+
* @param _subgraphDeploymentID Subgraph deployment from where the curator is minting
403403
* @param _tokens Amount of Graph Tokens to stake
404404
*/
405-
function _stake(
405+
function _mint(
406406
address _curator,
407407
bytes32 _subgraphDeploymentID,
408408
uint256 _tokens
@@ -418,8 +418,8 @@ contract Curation is CurationV1Storage, ICuration, Governed {
418418
}
419419

420420
// Update balances
421-
uint256 shares = _buyShares(_curator, _subgraphDeploymentID, _tokens);
421+
uint256 signal = _mintSignal(_curator, _subgraphDeploymentID, _tokens);
422422

423-
emit Staked(_curator, _subgraphDeploymentID, _tokens, shares);
423+
emit Signalled(_curator, _subgraphDeploymentID, _tokens, signal);
424424
}
425425
}

contracts/curation/CurationStorage.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ contract CurationV1Storage is GraphProxyStorage, BancorFormula {
1010

1111
struct CurationPool {
1212
uint256 tokens; // Tokens stored as reserves for the SubgraphDeployment
13-
uint256 shares; // Shares issued for the SubgraphDeployment
13+
uint256 signal; // Signal issued for the SubgraphDeployment
1414
uint32 reserveRatio; // Ratio for the bonding curve
15-
mapping(address => uint256) curatorShares; // Mapping of curator => shares
15+
mapping(address => uint256) curatorSignal; // Mapping of curator => signal
1616
}
1717

1818
// -- State --

contracts/curation/ICuration.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ interface ICuration {
1313

1414
// -- Curation --
1515

16-
function stake(bytes32 _subgraphDeploymentID, uint256 _tokens) external;
16+
function mint(bytes32 _subgraphDeploymentID, uint256 _tokens) external;
1717

18-
function redeem(bytes32 _subgraphDeploymentID, uint256 _shares) external;
18+
function burn(bytes32 _subgraphDeploymentID, uint256 _signal) external;
1919

2020
function collect(bytes32 _subgraphDeploymentID, uint256 _tokens) external;
2121

scripts/contracts/connectedContracts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,20 @@ class ConnectedCuration extends ConnectedContract {
6060
this.configuredWallet,
6161
)
6262

63-
stakeWithDecimals = async (
63+
signalWithDecimals = async (
6464
deploymentID: string,
6565
amount: BigNumberish,
6666
): Promise<ContractTransaction> => {
6767
const amountParseDecimals = utils.parseUnits(amount as string, 18).toString()
68-
return this.contract.stake(deploymentID, amountParseDecimals)
68+
return this.contract.mint(deploymentID, amountParseDecimals)
6969
}
7070

7171
redeemWithDecimals = async (
7272
deploymentID: string,
7373
amount: BigNumberish,
7474
): Promise<ContractTransaction> => {
7575
const amountParseDecimals = utils.parseUnits(amount as string, 18).toString()
76-
return this.contract.redeem(deploymentID, amountParseDecimals)
76+
return this.contract.burn(deploymentID, amountParseDecimals)
7777
}
7878
}
7979

0 commit comments

Comments
 (0)