Crowd Pooling test
This commit is contained in:
@@ -8,10 +8,10 @@
|
||||
// import * as assert from 'assert';
|
||||
|
||||
import { decimalStr } from '../utils/Converter';
|
||||
// import { logGas } from '../utils/Log';
|
||||
import { logGas } from '../utils/Log';
|
||||
import { CPContext, CPContextInitConfig } from '../utils/CrowdPoolingContext';
|
||||
// import { assert } from 'chai';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { assert } from 'chai';
|
||||
const truffleAssert = require('truffle-assertions');
|
||||
|
||||
let bidder1: string;
|
||||
@@ -32,7 +32,6 @@ describe("Funding", () => {
|
||||
before(async () => {
|
||||
config = {
|
||||
totalBase: decimalStr("10000"),
|
||||
poolBaseReserve: decimalStr("5000"),
|
||||
poolQuoteCap: decimalStr("50000"),
|
||||
ownerQuoteRatio: decimalStr("0.1"),
|
||||
k: decimalStr("0.5"),
|
||||
@@ -59,7 +58,23 @@ describe("Funding", () => {
|
||||
|
||||
it("bid", async () => {
|
||||
await ctx.QUOTE.methods.transfer(ctx.CP.options.address, decimalStr("100")).send(ctx.sendParam(bidder1))
|
||||
await ctx.CP.methods.bid(bidder1).send(ctx.sendParam(bidder1))
|
||||
await logGas(ctx.CP.methods.bid(bidder1), ctx.sendParam(bidder1), "bid")
|
||||
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("99.9"))
|
||||
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("99.9"))
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(), decimalStr("0.1"))
|
||||
|
||||
await ctx.QUOTE.methods.transfer(ctx.CP.options.address, decimalStr("50")).send(ctx.sendParam(bidder2))
|
||||
await ctx.CP.methods.bid(bidder2).send(ctx.sendParam(bidder2))
|
||||
assert.equal(await ctx.CP.methods.getShares(bidder2).call(), decimalStr("49.95"))
|
||||
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("149.85"))
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(), decimalStr("0.15"))
|
||||
|
||||
await ctx.EVM.increaseTime(86400)
|
||||
await logGas(ctx.CP.methods.cancel(bidder1, decimalStr("20")), ctx.sendParam(bidder1), "cancel")
|
||||
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("79.9"))
|
||||
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("129.85"))
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), decimalStr("920"))
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
114
test/CrowdPooling/CPSettle.test.ts
Normal file
114
test/CrowdPooling/CPSettle.test.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
import { decimalStr } from '../utils/Converter';
|
||||
import { logGas } from '../utils/Log';
|
||||
import { CPContext, CPContextInitConfig } from '../utils/CrowdPoolingContext';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { assert } from 'chai';
|
||||
import { DVM_NAME, getContractWithAddress, UNOWNED_DVM_FACTORY_NAME } from '../utils/Contracts';
|
||||
const truffleAssert = require('truffle-assertions');
|
||||
|
||||
let bidder1: string;
|
||||
let bidder2: string;
|
||||
let config: CPContextInitConfig
|
||||
|
||||
async function init(ctx: CPContext): Promise<void> {
|
||||
bidder1 = ctx.SpareAccounts[1]
|
||||
bidder2 = ctx.SpareAccounts[2]
|
||||
await ctx.QUOTE.methods.mint(bidder1, decimalStr("1000")).send(ctx.sendParam(ctx.Deployer))
|
||||
await ctx.QUOTE.methods.mint(bidder2, decimalStr("1000")).send(ctx.sendParam(ctx.Deployer))
|
||||
}
|
||||
|
||||
describe("Funding", () => {
|
||||
let snapshotId: string;
|
||||
let ctx: CPContext;
|
||||
|
||||
before(async () => {
|
||||
config = {
|
||||
totalBase: decimalStr("10000"),
|
||||
poolQuoteCap: decimalStr("50000"),
|
||||
ownerQuoteRatio: decimalStr("0.1"),
|
||||
k: decimalStr("0.5"),
|
||||
i: decimalStr("10"),
|
||||
lpFeeRate: decimalStr("0.002"),
|
||||
bidDuration: new BigNumber(86400),
|
||||
calmDuration: new BigNumber(86400),
|
||||
freezeDuration: new BigNumber(86400),
|
||||
}
|
||||
ctx = new CPContext();
|
||||
await ctx.init(config);
|
||||
await init(ctx);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
snapshotId = await ctx.EVM.snapshot();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await ctx.EVM.reset(snapshotId);
|
||||
});
|
||||
|
||||
describe("settle", () => {
|
||||
|
||||
it("bid not exceed cap", async () => {
|
||||
await ctx.QUOTE.methods.transfer(ctx.CP.options.address, decimalStr("1000")).send(ctx.sendParam(bidder1))
|
||||
await ctx.CP.methods.bid(bidder1).send(ctx.sendParam(bidder1))
|
||||
|
||||
await ctx.EVM.increaseTime(86400 * 2)
|
||||
await truffleAssert.reverts(ctx.CP.methods.bid(bidder1).send(ctx.sendParam(bidder1)), "NOT_PHASE_BID")
|
||||
|
||||
await logGas(ctx.CP.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||
assert.equal(await ctx.CP.methods._SETTLED_().call(), true)
|
||||
|
||||
var poolAddress = await ctx.CP.methods._POOL_().call()
|
||||
var pool = getContractWithAddress(DVM_NAME, poolAddress)
|
||||
|
||||
assert.equal(await pool.methods.getMidPrice().call(), "10050199494025273102")
|
||||
assert.equal(await ctx.CP.methods._AVG_SETTLED_PRICE_().call(), "10050199494025273136")
|
||||
|
||||
assert.equal(await ctx.CP.methods._UNUSED_QUOTE_().call(), "0")
|
||||
assert.equal(await ctx.CP.methods._UNUSED_BASE_().call(), "99401011949453729399")
|
||||
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(ctx.Deployer).call(), "0")
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(poolAddress).call(), "9900598988050546270601")
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(ctx.CP.options.address).call(), "99401011949453729399")
|
||||
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Deployer).call(), decimalStr("99.9"))
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(poolAddress).call(), decimalStr("899.1"))
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), "0")
|
||||
})
|
||||
|
||||
it("bid exceed cap", async () => {
|
||||
await ctx.QUOTE.methods.mint(ctx.CP.options.address, decimalStr("100000")).send(ctx.sendParam(ctx.Deployer))
|
||||
await ctx.CP.methods.bid(bidder1).send(ctx.sendParam(bidder1))
|
||||
|
||||
await ctx.EVM.increaseTime(86400 * 2)
|
||||
|
||||
await logGas(ctx.CP.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||
assert.equal(await ctx.CP.methods._SETTLED_().call(), true)
|
||||
|
||||
var poolAddress = await ctx.CP.methods._POOL_().call()
|
||||
var pool = getContractWithAddress(DVM_NAME, poolAddress)
|
||||
|
||||
assert.equal(await pool.methods.getMidPrice().call(), "13090169943749474216")
|
||||
assert.equal(await ctx.CP.methods._AVG_SETTLED_PRICE_().call(), "13090169943749474242")
|
||||
|
||||
assert.equal(await ctx.CP.methods._UNUSED_QUOTE_().call(), decimalStr("49900"))
|
||||
assert.equal(await ctx.CP.methods._UNUSED_BASE_().call(), "3819660112501051517955")
|
||||
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(ctx.Deployer).call(), "0")
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(poolAddress).call(), "6180339887498948482045")
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(ctx.CP.options.address).call(), "3819660112501051517955")
|
||||
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Deployer).call(), decimalStr("5000"))
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(poolAddress).call(), decimalStr("45000"))
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("49900"))
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
87
test/CrowdPooling/CPSettleReversePool.test.ts
Normal file
87
test/CrowdPooling/CPSettleReversePool.test.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
import { decimalStr } from '../utils/Converter';
|
||||
import { logGas } from '../utils/Log';
|
||||
import { CPContext, CPContextInitConfig } from '../utils/CrowdPoolingContext';
|
||||
import BigNumber from 'bignumber.js';
|
||||
// import { assert } from 'chai';
|
||||
import { DVM_NAME, getContractWithAddress, UNOWNED_DVM_FACTORY_NAME } from '../utils/Contracts';
|
||||
import { assert } from 'chai';
|
||||
const truffleAssert = require('truffle-assertions');
|
||||
|
||||
let bidder1: string;
|
||||
let bidder2: string;
|
||||
let config: CPContextInitConfig
|
||||
|
||||
async function init(ctx: CPContext): Promise<void> {
|
||||
bidder1 = ctx.SpareAccounts[1]
|
||||
bidder2 = ctx.SpareAccounts[2]
|
||||
await ctx.QUOTE.methods.mint(bidder1, decimalStr("1000")).send(ctx.sendParam(ctx.Deployer))
|
||||
await ctx.QUOTE.methods.mint(bidder2, decimalStr("1000")).send(ctx.sendParam(ctx.Deployer))
|
||||
}
|
||||
|
||||
describe("Funding", () => {
|
||||
let snapshotId: string;
|
||||
let ctx: CPContext;
|
||||
|
||||
before(async () => {
|
||||
config = {
|
||||
totalBase: decimalStr("10000"),
|
||||
poolQuoteCap: decimalStr("100000"),
|
||||
ownerQuoteRatio: decimalStr("0.1"),
|
||||
k: decimalStr("0.1"),
|
||||
i: decimalStr("10"),
|
||||
lpFeeRate: decimalStr("0.002"),
|
||||
bidDuration: new BigNumber(86400),
|
||||
calmDuration: new BigNumber(86400),
|
||||
freezeDuration: new BigNumber(86400),
|
||||
}
|
||||
ctx = new CPContext();
|
||||
await ctx.init(config);
|
||||
await init(ctx);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
snapshotId = await ctx.EVM.snapshot();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await ctx.EVM.reset(snapshotId);
|
||||
});
|
||||
|
||||
describe("settle", () => {
|
||||
|
||||
it("bid not exceed cap", async () => {
|
||||
await ctx.QUOTE.methods.mint(ctx.CP.options.address, decimalStr("100000")).send(ctx.sendParam(ctx.Deployer))
|
||||
await ctx.CP.methods.bid(bidder1).send(ctx.sendParam(bidder1))
|
||||
|
||||
await ctx.EVM.increaseTime(86400 * 2)
|
||||
|
||||
await logGas(ctx.CP.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||
assert.equal(await ctx.CP.methods._SETTLED_().call(), true)
|
||||
|
||||
var poolAddress = await ctx.CP.methods._POOL_().call()
|
||||
var pool = getContractWithAddress(DVM_NAME, poolAddress)
|
||||
|
||||
assert.equal(await pool.methods.getMidPrice().call(), "76012678448689469")
|
||||
assert.equal(await ctx.CP.methods._AVG_SETTLED_PRICE_().call(), "13155700080678329720")
|
||||
|
||||
assert.equal(await ctx.CP.methods._UNUSED_QUOTE_().call(), "0")
|
||||
assert.equal(await ctx.CP.methods._UNUSED_BASE_().call(), "7593666577024078089065")
|
||||
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(ctx.Deployer).call(), "0")
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(poolAddress).call(), "2406333422975921910935")
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(ctx.CP.options.address).call(), "7593666577024078089065")
|
||||
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Deployer).call(), decimalStr("9990"))
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(poolAddress).call(), decimalStr("89910"))
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), "0")
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
132
test/CrowdPooling/CPVesting.test.ts
Normal file
132
test/CrowdPooling/CPVesting.test.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
import { decimalStr, MAX_UINT256 } from '../utils/Converter';
|
||||
import { logGas } from '../utils/Log';
|
||||
import { CPContext, CPContextInitConfig } from '../utils/CrowdPoolingContext';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { assert } from 'chai';
|
||||
import { DVM_NAME, getContractWithAddress } from '../utils/Contracts';
|
||||
import { Contract } from 'web3-eth-contract';
|
||||
const truffleAssert = require('truffle-assertions');
|
||||
|
||||
let bidder1: string;
|
||||
let bidder2: string;
|
||||
let config: CPContextInitConfig
|
||||
|
||||
async function init(ctx: CPContext): Promise<void> {
|
||||
bidder1 = ctx.SpareAccounts[1]
|
||||
bidder2 = ctx.SpareAccounts[2]
|
||||
}
|
||||
|
||||
describe("Funding", () => {
|
||||
let snapshotId: string;
|
||||
let ctx: CPContext;
|
||||
|
||||
before(async () => {
|
||||
config = {
|
||||
totalBase: decimalStr("10000"),
|
||||
poolQuoteCap: decimalStr("50000"),
|
||||
ownerQuoteRatio: decimalStr("0.1"),
|
||||
k: decimalStr("0.5"),
|
||||
i: decimalStr("10"),
|
||||
lpFeeRate: decimalStr("0.002"),
|
||||
bidDuration: new BigNumber(86400),
|
||||
calmDuration: new BigNumber(86400),
|
||||
freezeDuration: new BigNumber(86400),
|
||||
}
|
||||
ctx = new CPContext();
|
||||
await ctx.init(config);
|
||||
await init(ctx);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
snapshotId = await ctx.EVM.snapshot();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await ctx.EVM.reset(snapshotId);
|
||||
});
|
||||
|
||||
describe("settle", () => {
|
||||
|
||||
it("bid not exceed cap", async () => {
|
||||
|
||||
await ctx.QUOTE.methods.mint(ctx.CP.options.address, decimalStr("10000")).send(ctx.sendParam(ctx.Deployer))
|
||||
await ctx.CP.methods.bid(bidder1).send(ctx.sendParam(bidder1))
|
||||
await ctx.QUOTE.methods.mint(ctx.CP.options.address, decimalStr("20000")).send(ctx.sendParam(ctx.Deployer))
|
||||
await ctx.CP.methods.bid(bidder2).send(ctx.sendParam(bidder2))
|
||||
|
||||
await ctx.EVM.increaseTime(86400 * 2)
|
||||
|
||||
await logGas(ctx.CP.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(ctx.CP.options.address).call(), "2557555139280633184959")
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), "0")
|
||||
|
||||
await ctx.CP.methods.claimBase().send(ctx.sendParam(bidder1))
|
||||
await ctx.CP.methods.claimQuote().send(ctx.sendParam(bidder1))
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(bidder1).call(), "852518379760211061653")
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), "0")
|
||||
|
||||
await ctx.CP.methods.claimBase().send(ctx.sendParam(bidder2))
|
||||
await ctx.CP.methods.claimQuote().send(ctx.sendParam(bidder2))
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(bidder2).call(), "1705036759520422123306")
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder2).call(), "0")
|
||||
|
||||
})
|
||||
|
||||
it("bid exceed cap", async () => {
|
||||
await ctx.QUOTE.methods.mint(ctx.CP.options.address, decimalStr("30000")).send(ctx.sendParam(ctx.Deployer))
|
||||
await ctx.CP.methods.bid(bidder1).send(ctx.sendParam(bidder1))
|
||||
await ctx.QUOTE.methods.mint(ctx.CP.options.address, decimalStr("60000")).send(ctx.sendParam(ctx.Deployer))
|
||||
await ctx.CP.methods.bid(bidder2).send(ctx.sendParam(bidder2))
|
||||
|
||||
await ctx.EVM.increaseTime(86400 * 2)
|
||||
|
||||
await logGas(ctx.CP.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(ctx.CP.options.address).call(), "3819660112501051517955")
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("39910"))
|
||||
|
||||
await ctx.CP.methods.claimBase().send(ctx.sendParam(bidder1))
|
||||
await ctx.CP.methods.claimQuote().send(ctx.sendParam(bidder1))
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(bidder1).call(), "1273220037500350505985")
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), "13303333333333333333333")
|
||||
|
||||
await ctx.CP.methods.claimBase().send(ctx.sendParam(bidder2))
|
||||
await ctx.CP.methods.claimQuote().send(ctx.sendParam(bidder2))
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(bidder2).call(), "2546440075000701011970")
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder2).call(), "26606666666666666666666")
|
||||
})
|
||||
|
||||
it("withdraw lp token", async () => {
|
||||
await ctx.QUOTE.methods.mint(ctx.CP.options.address, decimalStr("30000")).send(ctx.sendParam(ctx.Deployer))
|
||||
await ctx.CP.methods.bid(bidder1).send(ctx.sendParam(bidder1))
|
||||
await ctx.QUOTE.methods.mint(ctx.CP.options.address, decimalStr("60000")).send(ctx.sendParam(ctx.Deployer))
|
||||
await ctx.CP.methods.bid(bidder2).send(ctx.sendParam(bidder2))
|
||||
|
||||
await ctx.EVM.increaseTime(86400 * 2)
|
||||
await logGas(ctx.CP.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||
await truffleAssert.reverts(ctx.CP.methods.claimLPToken().send(ctx.sendParam(ctx.Deployer)), "FREEZED")
|
||||
|
||||
await ctx.EVM.increaseTime(86400)
|
||||
await ctx.CP.methods.claimLPToken().send(ctx.sendParam(ctx.Deployer))
|
||||
|
||||
var poolAddress = await ctx.CP.methods._POOL_().call()
|
||||
var pool = getContractWithAddress(DVM_NAME, poolAddress)
|
||||
|
||||
await pool.methods.sellShares("6180339887498948482045", bidder1, 0, 0, "0x", MAX_UINT256).send(ctx.sendParam(ctx.Deployer))
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(bidder1).call(), "6180339887498948482045")
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), "45000000000000000000000")
|
||||
|
||||
assert.equal(await ctx.BASE.methods.balanceOf(poolAddress).call(), "0")
|
||||
assert.equal(await ctx.QUOTE.methods.balanceOf(poolAddress).call(), "0")
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
@@ -21,7 +21,6 @@ BigNumber.config({
|
||||
|
||||
export interface CPContextInitConfig {
|
||||
totalBase: string;
|
||||
poolBaseReserve: string;
|
||||
poolQuoteCap: string;
|
||||
ownerQuoteRatio: string;
|
||||
k: string;
|
||||
@@ -105,7 +104,6 @@ export class CPContext {
|
||||
],
|
||||
[
|
||||
config.poolQuoteCap,
|
||||
config.poolBaseReserve,
|
||||
config.ownerQuoteRatio,
|
||||
config.k,
|
||||
config.i
|
||||
|
||||
Reference in New Issue
Block a user