Skip to content

Commit 8339baa

Browse files
authored
curation: add precision to curation signal shares (#220)
1 parent 068abc3 commit 8339baa

File tree

2 files changed

+51
-64
lines changed

2 files changed

+51
-64
lines changed

contracts/Curation.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ contract Curation is Governed, BancorFormula {
3030
uint256 private constant MAX_PPM = 1000000;
3131

3232
// Amount of shares you get with your minimum token stake
33-
uint256 private constant SHARES_PER_MINIMUM_STAKE = 1;
33+
uint256 private constant SHARES_PER_MINIMUM_STAKE = 1 ether;
3434

3535
// -- State --
3636

test/curation.test.ts

Lines changed: 50 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,17 @@ describe('Curation', () => {
1414
let curation: Curation
1515
let grt: GraphToken
1616

17+
// Test values
18+
const shareAmountFor1000Tokens = toBN('3162277660168379331')
19+
const subgraphDeploymentID = randomHexBytes()
20+
1721
beforeEach(async function() {
1822
// Deploy graph token
1923
grt = await deployment.deployGRT(governor.address, me)
2024

2125
// Deploy curation contract
2226
curation = await deployment.deployCuration(governor.address, grt.address, me)
2327
await curation.connect(governor).setStaking(staking.address)
24-
25-
// Randomize a test ID
26-
this.subgraphDeploymentID = randomHexBytes()
27-
28-
// Test values
29-
this.shareAmountFor1000Tokens = toBN('3')
3028
})
3129

3230
describe('configuration', function() {
@@ -127,38 +125,35 @@ describe('Curation', () => {
127125
})
128126

129127
describe('curation', function() {
128+
const curatorTokens = toGRT('1000')
129+
const tokensToCollect = toGRT('1000')
130+
130131
beforeEach(async function() {
131132
// Give some funds to the curator and approve the curation contract
132-
this.curatorTokens = toGRT('1000')
133-
await grt.connect(governor).mint(curator.address, this.curatorTokens)
134-
await grt.connect(curator).approve(curation.address, this.curatorTokens)
133+
await grt.connect(governor).mint(curator.address, curatorTokens)
134+
await grt.connect(curator).approve(curation.address, curatorTokens)
135135

136136
// Give some funds to the staking contract and approve the curation contract
137-
this.tokensToCollect = toGRT('1000')
138-
await grt.connect(governor).mint(staking.address, this.tokensToCollect)
139-
await grt.connect(staking).approve(curation.address, this.curatorTokens)
137+
await grt.connect(governor).mint(staking.address, tokensToCollect)
138+
await grt.connect(staking).approve(curation.address, curatorTokens)
140139
})
141140

142141
context('> bonding curve', function() {
143-
beforeEach(function() {
144-
this.subgraphDeploymentID = randomHexBytes()
145-
})
146-
147142
it('convert shares to tokens', async function() {
148143
// Curate
149-
await curation.connect(curator).stake(this.subgraphDeploymentID, this.curatorTokens)
144+
await curation.connect(curator).stake(subgraphDeploymentID, curatorTokens)
150145

151146
// Conversion
152-
const shares = (await curation.pools(this.subgraphDeploymentID)).shares
153-
const tokens = await curation.sharesToTokens(this.subgraphDeploymentID, shares)
154-
expect(tokens).to.eq(this.curatorTokens)
147+
const shares = (await curation.pools(subgraphDeploymentID)).shares
148+
const tokens = await curation.sharesToTokens(subgraphDeploymentID, shares)
149+
expect(tokens).to.eq(curatorTokens)
155150
})
156151

157152
it('convert tokens to shares', async function() {
158153
// Conversion
159154
const tokens = toGRT('1000')
160-
const shares = await curation.tokensToShares(this.subgraphDeploymentID, tokens)
161-
expect(shares).to.eq(this.shareAmountFor1000Tokens)
155+
const shares = await curation.tokensToShares(subgraphDeploymentID, tokens)
156+
expect(shares).to.eq(shareAmountFor1000Tokens)
162157
})
163158
})
164159

@@ -168,27 +163,27 @@ describe('Curation', () => {
168163
const curatorTokensBefore = await grt.balanceOf(curator.address)
169164
const curatorSharesBefore = await curation.getCuratorShares(
170165
curator.address,
171-
this.subgraphDeploymentID,
166+
subgraphDeploymentID,
172167
)
173-
const poolBefore = await curation.pools(this.subgraphDeploymentID)
168+
const poolBefore = await curation.pools(subgraphDeploymentID)
174169
const totalBalanceBefore = await grt.balanceOf(curation.address)
175170

176171
// Curate
177172
// Staking the minimum required = 1 share
178173
const tokensToStake = defaults.curation.minimumCurationStake
179-
const sharesToReceive = toBN(1)
180-
const tx = curation.connect(curator).stake(this.subgraphDeploymentID, tokensToStake)
174+
const sharesToReceive = toGRT('1')
175+
const tx = curation.connect(curator).stake(subgraphDeploymentID, tokensToStake)
181176
await expect(tx)
182177
.to.emit(curation, 'Staked')
183-
.withArgs(curator.address, this.subgraphDeploymentID, tokensToStake, sharesToReceive)
178+
.withArgs(curator.address, subgraphDeploymentID, tokensToStake, sharesToReceive)
184179

185180
// After balances
186181
const curatorTokensAfter = await grt.balanceOf(curator.address)
187182
const curatorSharesAfter = await curation.getCuratorShares(
188183
curator.address,
189-
this.subgraphDeploymentID,
184+
subgraphDeploymentID,
190185
)
191-
const poolAfter = await curation.pools(this.subgraphDeploymentID)
186+
const poolAfter = await curation.pools(subgraphDeploymentID)
192187
const totalBalanceAfter = await grt.balanceOf(curation.address)
193188

194189
// Tokens transferred properly
@@ -207,44 +202,41 @@ describe('Curation', () => {
207202

208203
it('reject stake below minimum tokens required', async function() {
209204
const tokensToStake = defaults.curation.minimumCurationStake.sub(toBN(1))
210-
const tx = curation.connect(curator).stake(this.subgraphDeploymentID, tokensToStake)
205+
const tx = curation.connect(curator).stake(subgraphDeploymentID, tokensToStake)
211206
await expect(tx).to.revertedWith('Curation stake is below minimum required')
212207
})
213208

214209
it('reject redeem more than a curator owns', async function() {
215-
const tx = curation.connect(me).redeem(this.subgraphDeploymentID, 1)
210+
const tx = curation.connect(me).redeem(subgraphDeploymentID, 1)
216211
await expect(tx).to.revertedWith('Cannot redeem more shares than you own')
217212
})
218213

219214
it('reject collect tokens distributed as fees to the reserves', async function() {
220215
// Source of tokens must be the staking for this to work
221-
const tx = curation.connect(staking).collect(this.subgraphDeploymentID, this.tokensToCollect)
216+
const tx = curation.connect(staking).collect(subgraphDeploymentID, tokensToCollect)
222217
await expect(tx).to.revertedWith('SubgraphDeployment must be curated to collect fees')
223218
})
224219

225220
context('> when is curated', function() {
226221
beforeEach(async function() {
227-
await curation.connect(curator).stake(this.subgraphDeploymentID, this.curatorTokens)
222+
await curation.connect(curator).stake(subgraphDeploymentID, curatorTokens)
228223
})
229224

230225
it('should create curation with default reserve ratio', async function() {
231226
const defaultReserveRatio = await curation.defaultReserveRatio()
232-
const pool = await curation.pools(this.subgraphDeploymentID)
227+
const pool = await curation.pools(subgraphDeploymentID)
233228
expect(pool.reserveRatio).to.eq(defaultReserveRatio)
234229
})
235230

236231
it('reject redeem zero shares', async function() {
237-
const tx = curation.redeem(this.subgraphDeploymentID, 0)
232+
const tx = curation.redeem(subgraphDeploymentID, 0)
238233
await expect(tx).to.revertedWith('Cannot redeem zero shares')
239234
})
240235

241236
it('should assign the right amount of shares according to bonding curve', async function() {
242237
// Shares should be the ones bought with minimum stake (1) + more shares
243-
const curatorShares = await curation.getCuratorShares(
244-
curator.address,
245-
this.subgraphDeploymentID,
246-
)
247-
expect(curatorShares).to.eq(this.shareAmountFor1000Tokens)
238+
const curatorShares = await curation.getCuratorShares(curator.address, subgraphDeploymentID)
239+
expect(curatorShares).to.eq(shareAmountFor1000Tokens)
248240
})
249241

250242
it('should allow to redeem *partially*', async function() {
@@ -253,26 +245,23 @@ describe('Curation', () => {
253245
const curatorTokensBefore = await grt.balanceOf(curator.address)
254246
const curatorSharesBefore = await curation.getCuratorShares(
255247
curator.address,
256-
this.subgraphDeploymentID,
248+
subgraphDeploymentID,
257249
)
258-
const poolBefore = await curation.pools(this.subgraphDeploymentID)
250+
const poolBefore = await curation.pools(subgraphDeploymentID)
259251
const totalTokensBefore = await grt.balanceOf(curation.address)
260252

261253
// Redeem
262254
const sharesToRedeem = toBN(1) // Curator want to sell 1 share
263-
const tokensToRedeem = await curation.sharesToTokens(
264-
this.subgraphDeploymentID,
265-
sharesToRedeem,
266-
)
255+
const tokensToRedeem = await curation.sharesToTokens(subgraphDeploymentID, sharesToRedeem)
267256
const withdrawalFeePercentage = await curation.withdrawalFeePercentage()
268257
const withdrawalFees = withdrawalFeePercentage.mul(tokensToRedeem).div(toBN(MAX_PPM))
269258

270-
const tx = curation.connect(curator).redeem(this.subgraphDeploymentID, sharesToRedeem)
259+
const tx = curation.connect(curator).redeem(subgraphDeploymentID, sharesToRedeem)
271260
await expect(tx)
272261
.to.emit(curation, 'Redeemed')
273262
.withArgs(
274263
curator.address,
275-
this.subgraphDeploymentID,
264+
subgraphDeploymentID,
276265
tokensToRedeem,
277266
sharesToRedeem,
278267
withdrawalFees,
@@ -283,9 +272,9 @@ describe('Curation', () => {
283272
const curatorTokensAfter = await grt.balanceOf(curator.address)
284273
const curatorSharesAfter = await curation.getCuratorShares(
285274
curator.address,
286-
this.subgraphDeploymentID,
275+
subgraphDeploymentID,
287276
)
288-
const poolAfter = await curation.pools(this.subgraphDeploymentID)
277+
const poolAfter = await curation.pools(subgraphDeploymentID)
289278
const totalTokensAfter = await grt.balanceOf(curation.address)
290279

291280
// Curator balance updated
@@ -306,20 +295,20 @@ describe('Curation', () => {
306295
it('should allow to redeem *fully*', async function() {
307296
// Before balances
308297
const tokenTotalSupplyBefore = await grt.totalSupply()
309-
const poolBefore = await curation.pools(this.subgraphDeploymentID)
298+
const poolBefore = await curation.pools(subgraphDeploymentID)
310299

311300
// Redeem all shares
312301
const sharesToRedeem = poolBefore.shares // we are selling all shares in the subgraph
313302
const tokensToRedeem = poolBefore.tokens // we are withdrawing all funds
314303
const withdrawalFeePercentage = await curation.withdrawalFeePercentage()
315304
const withdrawalFees = withdrawalFeePercentage.mul(tokensToRedeem).div(toBN(MAX_PPM))
316305

317-
const tx = curation.connect(curator).redeem(this.subgraphDeploymentID, sharesToRedeem)
306+
const tx = curation.connect(curator).redeem(subgraphDeploymentID, sharesToRedeem)
318307
await expect(tx)
319308
.to.emit(curation, 'Redeemed')
320309
.withArgs(
321310
curator.address,
322-
this.subgraphDeploymentID,
311+
subgraphDeploymentID,
323312
tokensToRedeem,
324313
sharesToRedeem,
325314
withdrawalFees,
@@ -330,9 +319,9 @@ describe('Curation', () => {
330319
const curatorTokensAfter = await grt.balanceOf(curator.address)
331320
const curatorSharesAfter = await curation.getCuratorShares(
332321
curator.address,
333-
this.subgraphDeploymentID,
322+
subgraphDeploymentID,
334323
)
335-
const poolAfter = await curation.pools(this.subgraphDeploymentID)
324+
const poolAfter = await curation.pools(subgraphDeploymentID)
336325
const totalTokensAfter = await grt.balanceOf(curation.address)
337326

338327
// Curator balance updated
@@ -354,25 +343,23 @@ describe('Curation', () => {
354343
it('should collect tokens distributed as reserves for', async function() {
355344
// Before balances
356345
const totalBalanceBefore = await grt.balanceOf(curation.address)
357-
const poolBefore = await curation.pools(this.subgraphDeploymentID)
346+
const poolBefore = await curation.pools(subgraphDeploymentID)
358347

359348
// Source of tokens must be the staking for this to work
360-
const tx = curation
361-
.connect(staking)
362-
.collect(this.subgraphDeploymentID, this.tokensToCollect)
349+
const tx = curation.connect(staking).collect(subgraphDeploymentID, tokensToCollect)
363350
await expect(tx)
364351
.to.emit(curation, 'Collected')
365-
.withArgs(this.subgraphDeploymentID, this.tokensToCollect)
352+
.withArgs(subgraphDeploymentID, tokensToCollect)
366353

367354
// After balances
368355
const totalBalanceAfter = await grt.balanceOf(curation.address)
369-
const poolAfter = await curation.pools(this.subgraphDeploymentID)
356+
const poolAfter = await curation.pools(subgraphDeploymentID)
370357

371358
// Curation balance updated
372-
expect(poolAfter.tokens).to.eq(poolBefore.tokens.add(this.tokensToCollect))
359+
expect(poolAfter.tokens).to.eq(poolBefore.tokens.add(tokensToCollect))
373360

374361
// Contract balance updated
375-
expect(totalBalanceAfter).to.eq(totalBalanceBefore.add(this.tokensToCollect))
362+
expect(totalBalanceAfter).to.eq(totalBalanceBefore.add(tokensToCollect))
376363
})
377364
})
378365
})

0 commit comments

Comments
 (0)