add dodo starter tests
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
import { decimalStr, MAX_UINT256 } from '../utils/Converter';
|
import { decimalStr, MAX_UINT256 } from '../utils/Converter';
|
||||||
import { logGas } from '../utils/Log';
|
import { logGas } from '../utils/Log';
|
||||||
import { DODOStarterContext,getDODOStarterContext } from '../utils/DODOStarterContext';
|
import { DODOStarterContext, DODOStarterContextInitConfig} from '../utils/DODOStarterContext';
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import * as contracts from '../utils/Contracts';
|
import * as contracts from '../utils/Contracts';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
@@ -17,30 +17,32 @@ import { StringLiteralLike } from 'typescript';
|
|||||||
const truffleAssert = require('truffle-assertions');
|
const truffleAssert = require('truffle-assertions');
|
||||||
|
|
||||||
let maker: string;
|
let maker: string;
|
||||||
let user: string;
|
let user1: string;
|
||||||
|
let user2: string;
|
||||||
async function init(ctx: NFTPoolContext): Promise<void> {
|
let sellTokenAddress: string;
|
||||||
maker = ctx.SpareAccounts[0];
|
let fundTokenAddress: string;
|
||||||
user = ctx.SpareAccounts[1];
|
let config: DODOStarterContextInitConfig = {
|
||||||
|
// time config
|
||||||
|
bidDuration: new BigNumber(86400),
|
||||||
|
calmDuration: new BigNumber(86400),
|
||||||
|
tokenVestingDuration: new BigNumber(86400),
|
||||||
|
fundVestingDuration: new BigNumber(86400),
|
||||||
|
lpVestingDuration: new BigNumber(86400),
|
||||||
|
// value config
|
||||||
|
lowerPrice: decimalStr("1"),
|
||||||
|
upperPrice: decimalStr("5"),
|
||||||
|
tokenCliffRate: decimalStr("1"),
|
||||||
|
fundCliffRate: decimalStr("1"),
|
||||||
|
lpCliffRate: decimalStr("1"),
|
||||||
|
initialLiquidity: decimalStr("1"),
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createFairFunding(ctx: DODOStarterContext) {
|
async function init(ctx: DODOStarterContext): Promise<void> {
|
||||||
// var tx = await logGas(ctx.DODONFTPoolProxy.methods.createNewNFTPoolV1(
|
maker = ctx.SpareAccounts[0];
|
||||||
// maker,
|
user1 = ctx.SpareAccounts[1];
|
||||||
// ctx.DodoNft.options.address,
|
user2 = ctx.SpareAccounts[2];
|
||||||
// 1,
|
sellTokenAddress = ctx.SellToken.options.address;
|
||||||
// ['Filter01', 'FRAG', 'FRAG'],
|
fundTokenAddress = ctx.FundToken.options.address;
|
||||||
// [decimalStr("10000000"), decimalStr("0.005")],
|
|
||||||
// [true, true, true],
|
|
||||||
// [0, 4, 5, 1],
|
|
||||||
// [decimalStr("1"), decimalStr("0.9"), decimalStr("1"), decimalStr("0.9"), decimalStr("2"), decimalStr("0.9")],
|
|
||||||
// [7]
|
|
||||||
// ), ctx.sendParam(maker), "createNewNFTPoolV1");
|
|
||||||
|
|
||||||
// var newFilterAdmin = tx.events['CreateNFTPool'].returnValues['newFilterAdmin']
|
|
||||||
// var filter = tx.events['CreateNFTPool'].returnValues['filter']
|
|
||||||
|
|
||||||
// return [newFilterAdmin, filter];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("FairFunding", () => {
|
describe("FairFunding", () => {
|
||||||
@@ -48,7 +50,8 @@ describe("FairFunding", () => {
|
|||||||
let ctx: DODOStarterContext;
|
let ctx: DODOStarterContext;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
ctx = await getDODOStarterContext();
|
ctx = new DODOStarterContext();
|
||||||
|
await ctx.init(config);
|
||||||
await init(ctx);
|
await init(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -60,31 +63,188 @@ describe("FairFunding", () => {
|
|||||||
await ctx.EVM.reset(snapshotId);
|
await ctx.EVM.reset(snapshotId);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("FairFunding", () => {
|
describe("Basic Info", () => {
|
||||||
it("Create_FairFunding", async () => {
|
it("get the correct cooling duration", async () => {
|
||||||
// var tx = await logGas(ctx.DODONFTPoolProxy.methods.createNewNFTPoolV1(
|
assert.equal(await ctx.FairFunding.methods._COOLING_DURATION_().call(), 86400);
|
||||||
// maker,
|
|
||||||
// ctx.DodoNft.options.address,
|
|
||||||
// 1,
|
|
||||||
// ['Filter01', 'FRAG', 'FRAG'],
|
|
||||||
// [decimalStr("10000000"), decimalStr("0.005")],
|
|
||||||
// [true, true, true],
|
|
||||||
// [0, 3, 2, 1],
|
|
||||||
// [decimalStr("1"), decimalStr("1.1"), decimalStr("1"), decimalStr("1.1"), decimalStr("2"), decimalStr("1.1")],
|
|
||||||
// [5]
|
|
||||||
// ), ctx.sendParam(maker), "createNewNFTPoolV1");
|
|
||||||
|
|
||||||
// var newFilterAdmin = tx.events['CreateNFTPool'].returnValues['newFilterAdmin']
|
|
||||||
// var filter = tx.events['CreateNFTPool'].returnValues['filter']
|
|
||||||
|
|
||||||
// console.log("newFilterAdmin:", newFilterAdmin)
|
|
||||||
// console.log("filterV1:", filter)
|
|
||||||
|
|
||||||
// assert.equal(
|
|
||||||
// tx.events['CreateNFTPool'].returnValues['filterAdminOwner'],
|
|
||||||
// maker
|
|
||||||
// )
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("get the correct lower limit price", async () => {
|
||||||
|
assert.equal(await ctx.FairFunding.methods._LOWER_LIMIT_PRICE_().call(), decimalStr("1"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("get the correct upper limit price", async () => {
|
||||||
|
assert.equal(await ctx.FairFunding.methods._UPPER_LIMIT_PRICE_().call(), decimalStr("5"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("get the correct _IS_OVERCAP_STOP", async () => {
|
||||||
|
assert.equal(await ctx.FairFunding.methods._IS_OVERCAP_STOP().call(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check if deposit is open", async () => {
|
||||||
|
assert.equal(await ctx.FairFunding.methods.isDepositOpen().call(), true)
|
||||||
|
await ctx.EVM.increaseTime(86400)
|
||||||
|
assert.equal(await ctx.FairFunding.methods.isDepositOpen().call(), false)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check if funding is end", async () => {
|
||||||
|
assert.equal(await ctx.FairFunding.methods.isFundingEnd().call(), false)
|
||||||
|
await ctx.EVM.increaseTime(86400 * 2 + 1)
|
||||||
|
assert.equal(await ctx.FairFunding.methods.isFundingEnd().call(), true)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check if is Settled",async () => {
|
||||||
|
assert.equal(await ctx.FairFunding.methods.isSettled().call(), false)
|
||||||
|
await ctx.EVM.increaseTime(86400 * 2 + 1)
|
||||||
|
await logGas(ctx.FairFunding.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||||
|
assert.equal(await ctx.FairFunding.methods.isSettled().call(), true)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Deposit Funds", () => {
|
||||||
|
it("successfully deposit funds", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("10000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, 3).send(ctx.sendParam(user1));
|
||||||
|
var tx = await logGas(ctx.FairFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
var account = tx.events['DepositFund'].returnValues['account'];
|
||||||
|
var fundAmount = tx.events['DepositFund'].returnValues['fundAmount'];
|
||||||
|
assert.equal(account, user1);
|
||||||
|
assert.equal(fundAmount, 3);
|
||||||
|
})
|
||||||
|
|
||||||
|
it("revert if the deposit is not open", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("10000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, 3).send(ctx.sendParam(user1));
|
||||||
|
await ctx.EVM.increaseTime(86400);
|
||||||
|
await truffleAssert.reverts(ctx.FairFunding.methods.depositFunds(user1).send(ctx.sendParam(user1)), "DEPOSIT_NOT_OPEN")
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Withdraw Funds", () => {
|
||||||
|
it("successfully withdraw funds", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("10000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, 3).send(ctx.sendParam(user1));
|
||||||
|
await logGas(ctx.FairFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.FairFunding.methods.withdrawFunds(user1, 3), ctx.sendParam(user1), "withdrawFunds");
|
||||||
|
var to = tx.events['WithdrawFund'].returnValues['to'];
|
||||||
|
var fundAmount = tx.events['WithdrawFund'].returnValues['fundAmount'];
|
||||||
|
assert.equal(to, user1);
|
||||||
|
assert.equal(fundAmount, 3);
|
||||||
|
})
|
||||||
|
|
||||||
|
it("revert if withdraw too much", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("10000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, 3).send(ctx.sendParam(user1));
|
||||||
|
await logGas(ctx.FairFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
await truffleAssert.reverts(ctx.FairFunding.methods.withdrawFunds(user1, 4).send(ctx.sendParam(user1)), "WITHDRAW_TOO_MUCH")
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Claim Token", () => {
|
||||||
|
it("successfully claim token", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("10000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, 3).send(ctx.sendParam(user1));
|
||||||
|
await logGas(ctx.FairFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
|
||||||
|
await ctx.EVM.increaseTime(86400 * 2 + 1)
|
||||||
|
await logGas(ctx.FairFunding.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.FairFunding.methods.claimToken(user1), ctx.sendParam(user1), "claimToken");
|
||||||
|
var to = tx.events['ClaimToken'].returnValues['to'];
|
||||||
|
var tokenAmount = tx.events['ClaimToken'].returnValues['tokenAmount'];
|
||||||
|
assert.equal(to, user1);
|
||||||
|
assert.equal(tokenAmount, 3);
|
||||||
|
})
|
||||||
|
|
||||||
|
it("revert if not settled", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("10000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, 3).send(ctx.sendParam(user1));
|
||||||
|
await logGas(ctx.FairFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
await truffleAssert.reverts(ctx.FairFunding.methods.claimToken(user1).send(ctx.sendParam(user1)), "NOT_SETTLED")
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Integration", () => {
|
||||||
|
it("case1: user1 deposit 8000, user2 deposit 8000", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("8000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, decimalStr("8000")).send(ctx.sendParam(user1));
|
||||||
|
await logGas(ctx.FairFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
|
||||||
|
await ctx.FundToken.methods.mint(user2, decimalStr("8000")).send(ctx.sendParam(user2));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, decimalStr("8000")).send(ctx.sendParam(user2));
|
||||||
|
await logGas(ctx.FairFunding.methods.depositFunds(user2), ctx.sendParam(user2), "depositFunds");
|
||||||
|
|
||||||
|
await ctx.EVM.increaseTime(86400 * 2 + 1)
|
||||||
|
await logGas(ctx.FairFunding.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.FairFunding.methods.claimToken(user1), ctx.sendParam(user1), "claimToken");
|
||||||
|
var to = tx.events['ClaimToken'].returnValues['to'];
|
||||||
|
var tokenAmount = tx.events['ClaimToken'].returnValues['tokenAmount'];
|
||||||
|
assert.equal(to, user1);
|
||||||
|
assert.equal(tokenAmount, decimalStr("5000"));
|
||||||
|
assert.equal(await ctx.SellToken.methods.balanceOf(user1).call(), decimalStr("5000"));
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.FairFunding.methods.claimToken(user2), ctx.sendParam(user2), "claimToken");
|
||||||
|
var to = tx.events['ClaimToken'].returnValues['to'];
|
||||||
|
var tokenAmount = tx.events['ClaimToken'].returnValues['tokenAmount'];
|
||||||
|
assert.equal(to, user2);
|
||||||
|
assert.equal(tokenAmount, decimalStr("5000"));
|
||||||
|
assert.equal(await ctx.SellToken.methods.balanceOf(user2).call(), decimalStr("5000"));
|
||||||
|
})
|
||||||
|
|
||||||
|
it("case2: user1 deposit 2000, user2 deposit 8000", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("2000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, decimalStr("2000")).send(ctx.sendParam(user1));
|
||||||
|
await logGas(ctx.FairFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
|
||||||
|
await ctx.FundToken.methods.mint(user2, decimalStr("8000")).send(ctx.sendParam(user2));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, decimalStr("8000")).send(ctx.sendParam(user2));
|
||||||
|
await logGas(ctx.FairFunding.methods.depositFunds(user2), ctx.sendParam(user2), "depositFunds");
|
||||||
|
|
||||||
|
await ctx.EVM.increaseTime(86400 * 2 + 1)
|
||||||
|
await logGas(ctx.FairFunding.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.FairFunding.methods.claimToken(user1), ctx.sendParam(user1), "claimToken");
|
||||||
|
var to = tx.events['ClaimToken'].returnValues['to'];
|
||||||
|
var tokenAmount = tx.events['ClaimToken'].returnValues['tokenAmount'];
|
||||||
|
assert.equal(to, user1);
|
||||||
|
assert.equal(tokenAmount, decimalStr("2000"));
|
||||||
|
assert.equal(await ctx.SellToken.methods.balanceOf(user1).call(), decimalStr("2000"));
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.FairFunding.methods.claimToken(user2), ctx.sendParam(user2), "claimToken");
|
||||||
|
var to = tx.events['ClaimToken'].returnValues['to'];
|
||||||
|
var tokenAmount = tx.events['ClaimToken'].returnValues['tokenAmount'];
|
||||||
|
assert.equal(to, user2);
|
||||||
|
assert.equal(tokenAmount, decimalStr("8000"));
|
||||||
|
assert.equal(await ctx.SellToken.methods.balanceOf(user2).call(), decimalStr("8000"));
|
||||||
|
})
|
||||||
|
|
||||||
|
it("case3: user1 deposit 20, user2 deposit 80", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("20")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, decimalStr("20")).send(ctx.sendParam(user1));
|
||||||
|
await logGas(ctx.FairFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
|
||||||
|
await ctx.FundToken.methods.mint(user2, decimalStr("80")).send(ctx.sendParam(user2));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.FairFunding.options.address, decimalStr("80")).send(ctx.sendParam(user2));
|
||||||
|
await logGas(ctx.FairFunding.methods.depositFunds(user2), ctx.sendParam(user2), "depositFunds");
|
||||||
|
|
||||||
|
await ctx.EVM.increaseTime(86400 * 2 + 1)
|
||||||
|
await logGas(ctx.FairFunding.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.FairFunding.methods.claimToken(user1), ctx.sendParam(user1), "claimToken");
|
||||||
|
var to = tx.events['ClaimToken'].returnValues['to'];
|
||||||
|
var tokenAmount = tx.events['ClaimToken'].returnValues['tokenAmount'];
|
||||||
|
assert.equal(to, user1);
|
||||||
|
assert.equal(tokenAmount, decimalStr("20"));
|
||||||
|
assert.equal(await ctx.SellToken.methods.balanceOf(user1).call(), decimalStr("20"));
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.FairFunding.methods.claimToken(user2), ctx.sendParam(user2), "claimToken");
|
||||||
|
var to = tx.events['ClaimToken'].returnValues['to'];
|
||||||
|
var tokenAmount = tx.events['ClaimToken'].returnValues['tokenAmount'];
|
||||||
|
assert.equal(to, user2);
|
||||||
|
assert.equal(tokenAmount, decimalStr("80"));
|
||||||
|
assert.equal(await ctx.SellToken.methods.balanceOf(user2).call(), decimalStr("80"));
|
||||||
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2021 DODO ZOO.
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// import * as assert from 'assert';
|
||||||
|
|
||||||
|
import { decimalStr, MAX_UINT256 } from '../utils/Converter';
|
||||||
|
import { logGas } from '../utils/Log';
|
||||||
|
import { DODOStarterContext, DODOStarterContextInitConfig} from '../utils/DODOStarterContext';
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import * as contracts from '../utils/Contracts';
|
||||||
|
import BigNumber from 'bignumber.js';
|
||||||
|
import { StringLiteralLike } from 'typescript';
|
||||||
|
const truffleAssert = require('truffle-assertions');
|
||||||
|
|
||||||
|
let maker: string;
|
||||||
|
let user1: string;
|
||||||
|
let user2: string;
|
||||||
|
let sellTokenAddress: string;
|
||||||
|
let fundTokenAddress: string;
|
||||||
|
let config: DODOStarterContextInitConfig = {
|
||||||
|
// time config
|
||||||
|
bidDuration: new BigNumber(86400),
|
||||||
|
calmDuration: new BigNumber(86400),
|
||||||
|
tokenVestingDuration: new BigNumber(86400),
|
||||||
|
fundVestingDuration: new BigNumber(86400),
|
||||||
|
lpVestingDuration: new BigNumber(86400),
|
||||||
|
// value config
|
||||||
|
lowerPrice: decimalStr("1"),
|
||||||
|
upperPrice: decimalStr("5"),
|
||||||
|
tokenCliffRate: decimalStr("1"),
|
||||||
|
fundCliffRate: decimalStr("1"),
|
||||||
|
lpCliffRate: decimalStr("1"),
|
||||||
|
initialLiquidity: decimalStr("1"),
|
||||||
|
}
|
||||||
|
|
||||||
|
async function init(ctx: DODOStarterContext): Promise<void> {
|
||||||
|
maker = ctx.SpareAccounts[0];
|
||||||
|
user1 = ctx.SpareAccounts[1];
|
||||||
|
user2 = ctx.SpareAccounts[2];
|
||||||
|
sellTokenAddress = ctx.SellToken.options.address;
|
||||||
|
fundTokenAddress = ctx.FundToken.options.address;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("InstantFunding", () => {
|
||||||
|
let snapshotId: string;
|
||||||
|
let ctx: DODOStarterContext;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
ctx = new DODOStarterContext();
|
||||||
|
await ctx.init(config);
|
||||||
|
await init(ctx);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
snapshotId = await ctx.EVM.snapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await ctx.EVM.reset(snapshotId);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Basic Info", () => {
|
||||||
|
it("get the correct start price", async () => {
|
||||||
|
assert.equal(await ctx.InstantFunding.methods._START_PRICE_().call(), decimalStr("10"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("get the correct end price", async () => {
|
||||||
|
assert.equal(await ctx.InstantFunding.methods._END_PRICE_().call(), decimalStr("1"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check if deposit is open", async () => {
|
||||||
|
assert.equal(await ctx.InstantFunding.methods.isDepositOpen().call(), true)
|
||||||
|
await ctx.EVM.increaseTime(86400 + 1)
|
||||||
|
assert.equal(await ctx.InstantFunding.methods.isDepositOpen().call(), false)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check if funding is end", async () => {
|
||||||
|
assert.equal(await ctx.InstantFunding.methods.isFundingEnd().call(), false)
|
||||||
|
await ctx.EVM.increaseTime(86400 + 1)
|
||||||
|
assert.equal(await ctx.InstantFunding.methods.isFundingEnd().call(), true)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Deposit Funds", () => {
|
||||||
|
it("successfully deposit funds", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("10000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.InstantFunding.options.address, decimalStr("3")).send(ctx.sendParam(user1));
|
||||||
|
var tx = await logGas(ctx.InstantFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
var account = tx.events['DepositFund'].returnValues['account'];
|
||||||
|
var fundAmount = tx.events['DepositFund'].returnValues['fundAmount'];
|
||||||
|
var allocationAmount = tx.events['DepositFund'].returnValues['allocationAmount'];
|
||||||
|
let currentPrice = await ctx.InstantFunding.methods.getCurrentPrice().call();
|
||||||
|
assert.equal(account, user1);
|
||||||
|
assert.equal(fundAmount, decimalStr("3"));
|
||||||
|
assert.equal(allocationAmount, decimalStr(new BigNumber(decimalStr("3")).div(currentPrice).toString()))
|
||||||
|
})
|
||||||
|
|
||||||
|
it("revert if the deposit is not open", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("10000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.InstantFunding.options.address, 3).send(ctx.sendParam(user1));
|
||||||
|
await ctx.EVM.increaseTime(86400);
|
||||||
|
await truffleAssert.reverts(ctx.InstantFunding.methods.depositFunds(user1).send(ctx.sendParam(user1)), "DEPOSIT_NOT_OPEN")
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Claim Token", () => {
|
||||||
|
it("successfully claim token", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("10000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.InstantFunding.options.address, decimalStr("3")).send(ctx.sendParam(user1));
|
||||||
|
await logGas(ctx.InstantFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
let currentPrice = await ctx.InstantFunding.methods.getCurrentPrice().call();
|
||||||
|
|
||||||
|
await ctx.EVM.increaseTime(86400 * 2)
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.InstantFunding.methods.claimToken(user1), ctx.sendParam(user1), "claimToken");
|
||||||
|
var to = tx.events['ClaimToken'].returnValues['to'];
|
||||||
|
var tokenAmount = tx.events['ClaimToken'].returnValues['tokenAmount'];
|
||||||
|
assert.equal(to, user1);
|
||||||
|
assert.equal(tokenAmount, decimalStr(new BigNumber(decimalStr("3")).div(currentPrice).toString()));
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Integration", () => {
|
||||||
|
it("user1 deposit 8000, user2 deposit 5000", async () => {
|
||||||
|
await ctx.FundToken.methods.mint(user1, decimalStr("8000")).send(ctx.sendParam(user1));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.InstantFunding.options.address, decimalStr("8000")).send(ctx.sendParam(user1));
|
||||||
|
await logGas(ctx.InstantFunding.methods.depositFunds(user1), ctx.sendParam(user1), "depositFunds");
|
||||||
|
let currentPrice1 = await ctx.InstantFunding.methods.getCurrentPrice().call();
|
||||||
|
await ctx.FundToken.methods.mint(user2, decimalStr("5000")).send(ctx.sendParam(user2));
|
||||||
|
await ctx.FundToken.methods.transfer(ctx.InstantFunding.options.address, decimalStr("5000")).send(ctx.sendParam(user2));
|
||||||
|
await logGas(ctx.InstantFunding.methods.depositFunds(user2), ctx.sendParam(user2), "depositFunds");
|
||||||
|
let currentPrice2 = await ctx.InstantFunding.methods.getCurrentPrice().call();
|
||||||
|
|
||||||
|
await ctx.EVM.increaseTime(86400 * 2)
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.InstantFunding.methods.claimToken(user1), ctx.sendParam(user1), "claimToken");
|
||||||
|
var to = tx.events['ClaimToken'].returnValues['to'];
|
||||||
|
var tokenAmount = tx.events['ClaimToken'].returnValues['tokenAmount'];
|
||||||
|
let expectTokenAmount1 = decimalStr(new BigNumber(decimalStr("8000")).div(currentPrice1).toString())
|
||||||
|
assert.equal(to, user1);
|
||||||
|
assert.equal(tokenAmount, expectTokenAmount1);
|
||||||
|
assert.equal(await ctx.SellToken.methods.balanceOf(user1).call(), expectTokenAmount1);
|
||||||
|
|
||||||
|
var tx = await logGas(ctx.InstantFunding.methods.claimToken(user2), ctx.sendParam(user2), "claimToken");
|
||||||
|
var to = tx.events['ClaimToken'].returnValues['to'];
|
||||||
|
var tokenAmount = tx.events['ClaimToken'].returnValues['tokenAmount'];
|
||||||
|
let expectTokenAmount2 = decimalStr(new BigNumber(decimalStr("5000")).div(currentPrice1).toString())
|
||||||
|
assert.equal(to, user2);
|
||||||
|
assert.equal(tokenAmount, expectTokenAmount2);
|
||||||
|
assert.equal(await ctx.SellToken.methods.balanceOf(user2).call(), expectTokenAmount2);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,21 @@ BigNumber.config({
|
|||||||
DECIMAL_PLACES: 80,
|
DECIMAL_PLACES: 80,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export interface DODOStarterContextInitConfig {
|
||||||
|
// time config
|
||||||
|
bidDuration: BigNumber;
|
||||||
|
calmDuration: BigNumber;
|
||||||
|
tokenVestingDuration: BigNumber;
|
||||||
|
fundVestingDuration: BigNumber;
|
||||||
|
lpVestingDuration: BigNumber;
|
||||||
|
// value config
|
||||||
|
lowerPrice: string;
|
||||||
|
upperPrice: string;
|
||||||
|
tokenCliffRate: string;
|
||||||
|
fundCliffRate: string;
|
||||||
|
lpCliffRate: string;
|
||||||
|
initialLiquidity: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class DODOStarterContext {
|
export class DODOStarterContext {
|
||||||
EVM: EVM;
|
EVM: EVM;
|
||||||
@@ -26,6 +41,8 @@ export class DODOStarterContext {
|
|||||||
|
|
||||||
//contract
|
//contract
|
||||||
DODOStarterFactory: Contract;
|
DODOStarterFactory: Contract;
|
||||||
|
FairFunding: Contract;
|
||||||
|
InstantFunding: Contract;
|
||||||
|
|
||||||
//account
|
//account
|
||||||
Deployer: string;
|
Deployer: string;
|
||||||
@@ -36,8 +53,7 @@ export class DODOStarterContext {
|
|||||||
SellToken: Contract;
|
SellToken: Contract;
|
||||||
FundToken: Contract;
|
FundToken: Contract;
|
||||||
|
|
||||||
|
async init(config: DODOStarterContextInitConfig) {
|
||||||
async init() {
|
|
||||||
this.EVM = new EVM();
|
this.EVM = new EVM();
|
||||||
this.Web3 = getDefaultWeb3();
|
this.Web3 = getDefaultWeb3();
|
||||||
|
|
||||||
@@ -77,6 +93,99 @@ export class DODOStarterContext {
|
|||||||
)
|
)
|
||||||
|
|
||||||
await this.DODOStarterFactory.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer));
|
await this.DODOStarterFactory.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer));
|
||||||
|
|
||||||
|
await this.SellToken.methods.mint(this.Deployer, decimalStr("10000")).send(this.sendParam(this.Deployer));
|
||||||
|
await this.SellToken.methods.approve(this.DODOStarterFactory.options.address, decimalStr("10000")).send(this.sendParam(this.Deployer));
|
||||||
|
|
||||||
|
let starttime = (await this.Web3.eth.getBlock(await this.Web3.eth.getBlockNumber())).timestamp;
|
||||||
|
|
||||||
|
await this.DODOStarterFactory.methods.createFairFund(
|
||||||
|
[
|
||||||
|
this.Deployer,
|
||||||
|
this.SellToken.options.address,
|
||||||
|
this.FundToken.options.address,
|
||||||
|
"0x0000000000000000000000000000000000000000",
|
||||||
|
"0x0000000000000000000000000000000000000000",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
starttime,
|
||||||
|
config.bidDuration,
|
||||||
|
config.calmDuration,
|
||||||
|
new BigNumber(starttime).plus(config.bidDuration).plus(config.calmDuration).plus(1),
|
||||||
|
config.tokenVestingDuration,
|
||||||
|
new BigNumber(starttime).plus(config.bidDuration).plus(config.calmDuration).plus(1),
|
||||||
|
config.fundVestingDuration,
|
||||||
|
new BigNumber(starttime).plus(config.bidDuration).plus(config.calmDuration).plus(1),
|
||||||
|
config.lpVestingDuration,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
config.lowerPrice,
|
||||||
|
config.upperPrice,
|
||||||
|
config.tokenCliffRate,
|
||||||
|
config.fundCliffRate,
|
||||||
|
config.lpCliffRate,
|
||||||
|
config.initialLiquidity,
|
||||||
|
],
|
||||||
|
decimalStr("10000"),
|
||||||
|
true,
|
||||||
|
).send(this.sendParam(this.Deployer, "0.2"))
|
||||||
|
|
||||||
|
let fairPools = await this.DODOStarterFactory.methods.getFairFundPools(
|
||||||
|
this.SellToken.options.address,
|
||||||
|
this.FundToken.options.address
|
||||||
|
).call();
|
||||||
|
|
||||||
|
console.log(`fair fund pools: ${JSON.stringify(fairPools)}`)
|
||||||
|
|
||||||
|
let fairPool = fairPools.slice(-1)[0];
|
||||||
|
|
||||||
|
this.FairFunding = await contracts.getContractWithAddress(contracts.FAIR_FUNDING, fairPool);
|
||||||
|
|
||||||
|
console.log('start createing instant fund......')
|
||||||
|
await this.SellToken.methods.mint(this.Deployer, decimalStr("10000")).send(this.sendParam(this.Deployer));
|
||||||
|
await this.SellToken.methods.approve(this.DODOStarterFactory.options.address, decimalStr("10000")).send(this.sendParam(this.Deployer));
|
||||||
|
let starttime2 = (await this.Web3.eth.getBlock(await this.Web3.eth.getBlockNumber())).timestamp;
|
||||||
|
await this.DODOStarterFactory.methods.createInstantFund(
|
||||||
|
[
|
||||||
|
this.Deployer,
|
||||||
|
this.SellToken.options.address,
|
||||||
|
this.FundToken.options.address,
|
||||||
|
"0x0000000000000000000000000000000000000000",
|
||||||
|
"0x0000000000000000000000000000000000000000",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
starttime2,
|
||||||
|
config.bidDuration,
|
||||||
|
new BigNumber(starttime2).plus(config.bidDuration).plus(config.calmDuration).plus(1),
|
||||||
|
config.tokenVestingDuration,
|
||||||
|
new BigNumber(starttime2).plus(config.bidDuration).plus(config.calmDuration).plus(1),
|
||||||
|
config.fundVestingDuration,
|
||||||
|
new BigNumber(starttime2).plus(config.bidDuration).plus(config.calmDuration).plus(1),
|
||||||
|
config.lpVestingDuration,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
decimalStr("10"),
|
||||||
|
decimalStr("1"),
|
||||||
|
config.tokenCliffRate,
|
||||||
|
config.fundCliffRate,
|
||||||
|
config.lpCliffRate,
|
||||||
|
config.initialLiquidity,
|
||||||
|
],
|
||||||
|
decimalStr("10000"),
|
||||||
|
).send(this.sendParam(this.Deployer))
|
||||||
|
|
||||||
|
console.log(`finish creating instant pools`)
|
||||||
|
|
||||||
|
let instantPools = await this.DODOStarterFactory.methods.getInstantFundPools(
|
||||||
|
this.SellToken.options.address,
|
||||||
|
this.FundToken.options.address
|
||||||
|
).call();
|
||||||
|
|
||||||
|
console.log(`instant fund pools: ${JSON.stringify(instantPools)}`)
|
||||||
|
|
||||||
|
let instantPool = instantPools.slice(-1)[0];
|
||||||
|
|
||||||
|
this.InstantFunding = await contracts.getContractWithAddress(contracts.INSTANT_FUNDING, instantPool);
|
||||||
|
|
||||||
console.log(log.blueText("[Init DODOStarter context]"));
|
console.log(log.blueText("[Init DODOStarter context]"));
|
||||||
}
|
}
|
||||||
@@ -99,10 +208,4 @@ export class DODOStarterContext {
|
|||||||
.approve(target, MAX_UINT256)
|
.approve(target, MAX_UINT256)
|
||||||
.send(this.sendParam(account));
|
.send(this.sendParam(account));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export async function getDODOStarterContext(): Promise<DODOStarterContext> {
|
|
||||||
var context = new DODOStarterContext();
|
|
||||||
await context.init();
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user