trade incentive fix && test
This commit is contained in:
@@ -126,19 +126,19 @@ describe("DODOProxyV2.0", () => {
|
||||
await ctx.USDT.methods.balanceOf(addrs[1]).call(),
|
||||
quoteAmount
|
||||
);
|
||||
|
||||
|
||||
|
||||
});
|
||||
it("updateFeeRateModel", async () => {
|
||||
var feeRate = await DVM_DODO_USDT.methods.getUserFeeRate(project).call()
|
||||
assert.equal(
|
||||
feeRate[1],
|
||||
"10000000000000000"
|
||||
feeRate[1], //mtFee
|
||||
"0"
|
||||
);
|
||||
var mtFeeResult0 = await DVM_DODO_USDT.methods.querySellQuote(ctx.Deployer, decimalStr("10")).call()
|
||||
var mtFeeResult0 = await DVM_DODO_USDT.methods.querySellQuote(ctx.Deployer, decimalStr("10")).call()
|
||||
assert.equal(
|
||||
mtFeeResult0[1],
|
||||
"999999999265727652176"
|
||||
"0"
|
||||
);
|
||||
|
||||
var feerateLogicAddress = ctx.MtFeeRateModelLogic.options.address;
|
||||
@@ -151,30 +151,11 @@ describe("DODOProxyV2.0", () => {
|
||||
feeRateSet[1],
|
||||
"30000000000000000"
|
||||
);
|
||||
var mtFeeResult1 = await DVM_DODO_USDT.methods.querySellQuote(ctx.Deployer, decimalStr("10")).call()
|
||||
var mtFeeResult1 = await DVM_DODO_USDT.methods.querySellQuote(ctx.Deployer, decimalStr("10")).call()
|
||||
assert.equal(
|
||||
mtFeeResult1[1],
|
||||
"2999999997797182956530"
|
||||
);
|
||||
|
||||
|
||||
var feerateLogicUpdateAddress = ctx.MtFeeRateModelLogicUpdate.options.address;
|
||||
await logGas(await ctx.mtFeeRateModel.methods.setFeeRate(
|
||||
decimalStr("0.01"),
|
||||
feerateLogicUpdateAddress
|
||||
), ctx.sendParam(ctx.Deployer), "setFeeRateUpdate");
|
||||
var feeRateUpdate = await DVM_DODO_USDT.methods.getUserFeeRate(lp).call()
|
||||
assert.equal(
|
||||
feeRateUpdate[1],
|
||||
"40000000000000000"
|
||||
);
|
||||
var mtFeeResult2 = await DVM_DODO_USDT.methods.querySellQuote(ctx.Deployer, decimalStr("10")).call()
|
||||
assert.equal(
|
||||
mtFeeResult2[1],
|
||||
"3999999997062910608707"
|
||||
);
|
||||
|
||||
|
||||
});
|
||||
|
||||
// it("createDVM - ETH", async () => {
|
||||
@@ -341,7 +322,7 @@ describe("DODOProxyV2.0", () => {
|
||||
// console.log("b_DOOD:" + b_DOOD + " a_DODO:" + a_DOOD);
|
||||
// console.log("b_USDT:" + b_USDT + " a_USDT:" + a_USDT);
|
||||
assert.equal(a_DOOD, decimalStr("500"));
|
||||
assert.equal(a_USDT, "124886061");
|
||||
assert.equal(a_USDT, "126151370");
|
||||
await logGas(await ctx.DODOProxyV2.methods.dodoSwapV2TokenToToken(
|
||||
ctx.DODO.options.address,
|
||||
ctx.USDT.options.address,
|
||||
@@ -379,7 +360,7 @@ describe("DODOProxyV2.0", () => {
|
||||
// console.log("b_DOOD:" + b_DOOD + " a_DODO:" + a_DOOD);
|
||||
// console.log("b_WETH:" + b_WETH + " a_WETH:" + a_WETH);
|
||||
assert.equal(a_DOOD, decimalStr("500"));
|
||||
assert.equal(a_WETH, "160562971834401560");
|
||||
assert.equal(a_WETH, "163816613646287588");
|
||||
await logGas(await ctx.DODOProxyV2.methods.dodoSwapV2TokenToToken(
|
||||
ctx.DODO.options.address,
|
||||
ctx.WETH.options.address,
|
||||
@@ -415,7 +396,7 @@ describe("DODOProxyV2.0", () => {
|
||||
// console.log("b_DOOD:" + b_DOOD + " a_DODO:" + a_DOOD);
|
||||
// console.log("b_WETH:" + b_WETH + " a_WETH:" + a_WETH);
|
||||
// console.log("b_ETH:" + b_ETH + " a_ETH:" + a_ETH);
|
||||
assert.equal(a_DOOD, "2758402621041673925359");
|
||||
assert.equal(a_DOOD, "2814340111190341070680");
|
||||
await logGas(await ctx.DODOProxyV2.methods.dodoSwapV2ETHToToken(
|
||||
ctx.DODO.options.address,
|
||||
1,
|
||||
@@ -447,7 +428,7 @@ describe("DODOProxyV2.0", () => {
|
||||
assert.equal(a_DOOD, decimalStr("1000"));
|
||||
assert.equal(
|
||||
tx.events['OrderHistory'].returnValues['returnAmount'],
|
||||
"317467466094549770"
|
||||
"323865907568573497"
|
||||
)
|
||||
await logGas(await ctx.DODOProxyV2.methods.dodoSwapV2TokenToETH(
|
||||
ctx.DODO.options.address,
|
||||
@@ -481,7 +462,7 @@ describe("DODOProxyV2.0", () => {
|
||||
var a_DOOD = await ctx.DODO.methods.balanceOf(trader).call();
|
||||
var a_WETH = await ctx.WETH.methods.balanceOf(trader).call();
|
||||
assert.equal(a_DOOD, decimalStr("500"));
|
||||
assert.equal(a_WETH, "158791178116238085");
|
||||
assert.equal(a_WETH, "163633965833613187");
|
||||
await logGas(await ctx.DODOProxyV2.methods.dodoSwapV2TokenToToken(
|
||||
ctx.DODO.options.address,
|
||||
ctx.WETH.options.address,
|
||||
|
||||
@@ -76,8 +76,7 @@ async function initCreateDVM(ctx: ProxyContext, token0: string, token1: string,
|
||||
}
|
||||
|
||||
async function initIncentive(ctx: ProxyContext): Promise<void> {
|
||||
var blockNum = await ctx.Web3.eth.getBlockNumber();
|
||||
await ctx.DODOIncentive.methods.switchIncentive(blockNum + 1).send(ctx.sendParam(ctx.Deployer));
|
||||
await ctx.DODOIncentive.methods.changePerReward(decimalStr("10")).send(ctx.sendParam(ctx.Deployer));
|
||||
await ctx.mintTestToken(ctx.DODOIncentive.options.address, ctx.DODO, decimalStr("1000000"));
|
||||
}
|
||||
|
||||
@@ -115,29 +114,23 @@ describe("DODOProxyV2.0", () => {
|
||||
await ctx.DODOIncentive.methods.changePerReward(decimalStr("10")).send(ctx.sendParam(ctx.Deployer));
|
||||
var totalReward = await ctx.DODOIncentive.methods.totalReward().call();
|
||||
var totalDistribution = await ctx.DODOIncentive.methods.totalDistribution().call();
|
||||
var blockNum = await ctx.Web3.eth.getBlockNumber();
|
||||
console.log("Init - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution + "; BlockNumber:" + blockNum);
|
||||
console.log("Init - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution);
|
||||
|
||||
//Aim to increase block
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
blockNum = await ctx.Web3.eth.getBlockNumber();
|
||||
console.log("Close BlockNumber:", blockNum + 1)
|
||||
await ctx.DODOIncentive.methods.switchIncentive(0).send(ctx.sendParam(ctx.Deployer));
|
||||
await ctx.DODOIncentive.methods.changePerReward(0).send(ctx.sendParam(ctx.Deployer));
|
||||
totalReward = await ctx.DODOIncentive.methods.totalReward().call();
|
||||
totalDistribution = await ctx.DODOIncentive.methods.totalDistribution().call();
|
||||
blockNum = await ctx.Web3.eth.getBlockNumber();
|
||||
console.log("Close incentive - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution + "; BlockNumber:" + blockNum);
|
||||
console.log("Close incentive - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution);
|
||||
|
||||
//Aim to increase block
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
|
||||
blockNum = await ctx.Web3.eth.getBlockNumber();
|
||||
await ctx.DODOIncentive.methods.switchIncentive(blockNum + 1).send(ctx.sendParam(ctx.Deployer));
|
||||
console.log("Open BlockNumber:", blockNum + 1)
|
||||
await ctx.DODOIncentive.methods.changePerReward(decimalStr("10")).send(ctx.sendParam(ctx.Deployer));
|
||||
//Aim to increase block
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
@@ -145,8 +138,7 @@ describe("DODOProxyV2.0", () => {
|
||||
await ctx.DODOIncentive.methods.changePerReward(decimalStr("10")).send(ctx.sendParam(ctx.Deployer));
|
||||
totalReward = await ctx.DODOIncentive.methods.totalReward().call();
|
||||
totalDistribution = await ctx.DODOIncentive.methods.totalDistribution().call();
|
||||
blockNum = await ctx.Web3.eth.getBlockNumber();
|
||||
console.log("End incentive - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution + "; BlockNumber:" + blockNum);
|
||||
console.log("End incentive - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution);
|
||||
assert(totalReward, decimalStr("100"));
|
||||
});
|
||||
|
||||
@@ -154,21 +146,17 @@ describe("DODOProxyV2.0", () => {
|
||||
await ctx.DODOIncentive.methods.changePerReward(decimalStr("10")).send(ctx.sendParam(ctx.Deployer));
|
||||
var totalReward = await ctx.DODOIncentive.methods.totalReward().call();
|
||||
var totalDistribution = await ctx.DODOIncentive.methods.totalDistribution().call();
|
||||
var blockNum = await ctx.Web3.eth.getBlockNumber();
|
||||
console.log("Init - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution + "; BlockNumber:" + blockNum);
|
||||
console.log("Init - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution);
|
||||
|
||||
//Aim to increase block
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
|
||||
blockNum = await ctx.Web3.eth.getBlockNumber();
|
||||
console.log("Change BlockNumber:", blockNum + 1)
|
||||
await ctx.DODOIncentive.methods.changePerReward(decimalStr("20")).send(ctx.sendParam(ctx.Deployer));
|
||||
totalReward = await ctx.DODOIncentive.methods.totalReward().call();
|
||||
totalDistribution = await ctx.DODOIncentive.methods.totalDistribution().call();
|
||||
blockNum = await ctx.Web3.eth.getBlockNumber();
|
||||
console.log("change incentive - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution + "; BlockNumber:" + blockNum);
|
||||
console.log("change incentive - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution);
|
||||
|
||||
//Aim to increase block
|
||||
await ctx.mintTestToken(lp, ctx.DODO, decimalStr("1000"));
|
||||
@@ -177,13 +165,12 @@ describe("DODOProxyV2.0", () => {
|
||||
await ctx.DODOIncentive.methods.changePerReward(decimalStr("10")).send(ctx.sendParam(ctx.Deployer));
|
||||
totalReward = await ctx.DODOIncentive.methods.totalReward().call();
|
||||
totalDistribution = await ctx.DODOIncentive.methods.totalDistribution().call();
|
||||
blockNum = await ctx.Web3.eth.getBlockNumber();
|
||||
console.log("End incentive - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution + "; BlockNumber:" + blockNum);
|
||||
console.log("End incentive - Total Reward:" + totalReward + "; Total distribution:" + totalDistribution);
|
||||
|
||||
assert(totalReward, decimalStr("140"));
|
||||
});
|
||||
|
||||
it("tigger - incentive", async () => {
|
||||
it.only("tigger - incentive", async () => {
|
||||
await ctx.mintTestToken(trader, ctx.DODO, decimalStr("2000"));
|
||||
var b_DODO = await ctx.DODO.methods.balanceOf(trader).call()
|
||||
var b_USDT = await ctx.USDT.methods.balanceOf(trader).call()
|
||||
@@ -193,16 +180,11 @@ describe("DODOProxyV2.0", () => {
|
||||
var b_totalDistribution = await ctx.DODOIncentive.methods.totalDistribution().call();
|
||||
console.log("Before Total Reward:" + b_totalReward + "; Total distribution:" + b_totalDistribution)
|
||||
|
||||
var a_DODO = await ctx.DODO.methods.balanceOf(trader).call()
|
||||
var a_USDT = await ctx.USDT.methods.balanceOf(trader).call()
|
||||
console.log("After No Incentive DODO:" + a_DODO + "; USDT:" + a_USDT);
|
||||
|
||||
var dodoPairs = [
|
||||
dpp_DODO_USDT
|
||||
]
|
||||
var directions = 0
|
||||
|
||||
|
||||
await logGas(await ctx.DODOProxyV2.methods.dodoSwapV2TokenToToken(
|
||||
ctx.DODO.options.address,
|
||||
ctx.USDT.options.address,
|
||||
@@ -213,7 +195,7 @@ describe("DODOProxyV2.0", () => {
|
||||
false,
|
||||
Math.floor(new Date().getTime() / 1000 + 60 * 10)
|
||||
), ctx.sendParam(trader), "swap without incentive first");
|
||||
|
||||
|
||||
await logGas(await ctx.DODOProxyV2.methods.dodoSwapV2TokenToToken(
|
||||
ctx.DODO.options.address,
|
||||
ctx.USDT.options.address,
|
||||
|
||||
@@ -82,8 +82,8 @@ export class ProxyContext {
|
||||
var permissionManagerTemplate = await contracts.newContract(contracts.PERMISSION_MANAGER_NAME)
|
||||
var mtFeeRateModelTemplate = await contracts.newContract(contracts.FEE_RATE_MODEL_NAME)
|
||||
this.mtFeeRateModel = mtFeeRateModelTemplate;
|
||||
await mtFeeRateModelTemplate.methods.init(this.Deployer,decimalStr("0.01")).send(this.sendParam(this.Deployer));
|
||||
// await mtFeeRateModelTemplate.methods.init(this.Deployer,decimalStr("0")).send(this.sendParam(this.Deployer));
|
||||
// await mtFeeRateModelTemplate.methods.init(this.Deployer,decimalStr("0.01")).send(this.sendParam(this.Deployer));
|
||||
await mtFeeRateModelTemplate.methods.init(this.Deployer,decimalStr("0")).send(this.sendParam(this.Deployer));
|
||||
|
||||
this.DVMFactory = await contracts.newContract(contracts.DVM_FACTORY_NAME,
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user