route and wrap and unwrap eth && test
This commit is contained in:
@@ -26,14 +26,14 @@ async function initDODO_USDT(ctx: DODOContext): Promise<void> {
|
||||
await ctx.approvePair(DODO,USDT,DODO_USDT.options.address,lp);
|
||||
await ctx.approvePair(DODO,USDT,DODO_USDT.options.address,trader);
|
||||
|
||||
await ctx.mintToken(DODO,USDT, lp, decimalStr("10000"), mweiStr("1000"));
|
||||
await ctx.mintToken(DODO,USDT,trader, decimalStr("100"), mweiStr("0"));
|
||||
await ctx.mintToken(DODO,USDT, lp, decimalStr("10000000"), mweiStr("1000000"));
|
||||
await ctx.mintToken(DODO,USDT,trader, decimalStr("1000"), mweiStr("0"));
|
||||
|
||||
await DODO_USDT.methods
|
||||
.depositBaseTo(lp, decimalStr("10000"))
|
||||
.depositBaseTo(lp, decimalStr("10000000"))
|
||||
.send(ctx.sendParam(lp));
|
||||
await DODO_USDT.methods
|
||||
.depositQuoteTo(lp, mweiStr("1000"))
|
||||
.depositQuoteTo(lp, mweiStr("1000000"))
|
||||
.send(ctx.sendParam(lp));
|
||||
}
|
||||
|
||||
@@ -47,13 +47,13 @@ async function initUSDT_USDC(ctx: DODOContext): Promise<void> {
|
||||
let USDT_USDC = ctx.USDT_USDC;
|
||||
|
||||
await ctx.approvePair(USDT,USDC,USDT_USDC.options.address,lp);
|
||||
await ctx.mintToken(USDT,USDC,lp, mweiStr("1000"), mweiStr("1000"));
|
||||
await ctx.mintToken(USDT,USDC,lp, mweiStr("1000000"), mweiStr("1000000"));
|
||||
|
||||
await USDT_USDC.methods
|
||||
.depositBaseTo(lp, mweiStr("1000"))
|
||||
.depositBaseTo(lp, mweiStr("1000000"))
|
||||
.send(ctx.sendParam(lp));
|
||||
await USDT_USDC.methods
|
||||
.depositQuoteTo(lp, mweiStr("1000"))
|
||||
.depositQuoteTo(lp, mweiStr("1000000"))
|
||||
.send(ctx.sendParam(lp));
|
||||
}
|
||||
|
||||
@@ -68,13 +68,14 @@ async function initWETH_USDC(ctx: DODOContext): Promise<void> {
|
||||
let WETH_USDC = ctx.WETH_USDC;
|
||||
|
||||
await ctx.approvePair(WETH,USDC,WETH_USDC.options.address,lp);
|
||||
await ctx.mintToken(WETH,USDC,lp, decimalStr("1000"), mweiStr("450000"));
|
||||
await ctx.mintToken(null,USDC,lp, decimalStr("0"), mweiStr("36000"));
|
||||
await WETH.methods.deposit().send(ctx.sendParam(lp,'80'));
|
||||
|
||||
await WETH_USDC.methods
|
||||
.depositBaseTo(lp, decimalStr("1000"))
|
||||
.depositBaseTo(lp, decimalStr("80"))
|
||||
.send(ctx.sendParam(lp));
|
||||
await WETH_USDC.methods
|
||||
.depositQuoteTo(lp, mweiStr("450000"))
|
||||
.depositQuoteTo(lp, mweiStr("36000"))
|
||||
.send(ctx.sendParam(lp));
|
||||
}
|
||||
|
||||
@@ -89,7 +90,11 @@ async function calcRoute(ctx: DODOContext,fromTokenAmount:string,slippage:number
|
||||
let curPair = pairs[i]
|
||||
dodoPairs.push(curPair.pair)
|
||||
let curContact = pairs[i].pairContract
|
||||
if (curPair.base === routes[i].address) {
|
||||
if(routes[i].address == '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE') {
|
||||
directions[i] = 0;
|
||||
swapAmount = await curContact.methods.querySellBaseToken(swapAmount).call();
|
||||
console.log(i + "-swapAmount:",swapAmount);
|
||||
}else if (curPair.base === routes[i].address) {
|
||||
directions[i] = 0;
|
||||
swapAmount = await curContact.methods.querySellBaseToken(swapAmount).call();
|
||||
console.log(i + "-swapAmount:",swapAmount);
|
||||
@@ -257,5 +262,145 @@ describe("Trader", () => {
|
||||
var c_WETH = await ctx.WETH.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
console.log("Contract DODO:" + fromWei(c_DODO,'ether') + "; USDT:" + fromWei(c_USDT,'mwei') + "; USDC:" + fromWei(c_USDC,'mwei') + "; WETH:" + fromWei(c_WETH,'ether'));
|
||||
});
|
||||
|
||||
|
||||
it("ETH to USDT wrap eth and directly swap", async () => {
|
||||
var b_ETH = await ctx.Web3.eth.getBalance(trader)
|
||||
var b_WETH = await ctx.WETH.methods.balanceOf(trader).call()
|
||||
var b_USDC = await ctx.USDC.methods.balanceOf(trader).call()
|
||||
console.log("Before ETH:" + fromWei(b_ETH,'ether') + "; WETH:" + fromWei(b_WETH,'ether') + "; USDC:" + fromWei(b_USDC,'mwei'));
|
||||
var b_w_eth = await ctx.Web3.eth.getBalance(ctx.WETH.options.address)
|
||||
console.log("weth contract Before:" + fromWei(b_w_eth,'ether'))
|
||||
//set route path
|
||||
var routes = [{
|
||||
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||
decimals: 18
|
||||
},{
|
||||
address: ctx.USDC.options.address,
|
||||
decimals: 6
|
||||
}];
|
||||
|
||||
var pairs = [{
|
||||
pair: ctx.WETH_USDC.options.address,
|
||||
base: ctx.WETH.options.address,
|
||||
pairContract: ctx.WETH_USDC
|
||||
}];
|
||||
|
||||
var tx = await logGas(await calcRoute(ctx,decimalStr('1'),0.1,routes,pairs), ctx.sendParam(trader,'1'), "wrap eth and directly swap")
|
||||
var a_ETH = await ctx.Web3.eth.getBalance(trader)
|
||||
var a_WETH = await ctx.WETH.methods.balanceOf(trader).call()
|
||||
var a_USDC = await ctx.USDC.methods.balanceOf(trader).call()
|
||||
console.log("After ETH:" + fromWei(a_ETH,'ether') + "; WETH:" + fromWei(a_WETH,'ether') + "; USDC:" + fromWei(a_USDC,'mwei'));
|
||||
console.log("===============================================")
|
||||
var c_ETH = await ctx.Web3.eth.getBalance(ctx.SmartSwap.options.address)
|
||||
var c_WETH = await ctx.WETH.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
var c_USDT = await ctx.USDT.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
var c_USDC = await ctx.USDC.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
console.log("Contract ETH:" + fromWei(c_ETH,'ether') + "; WETH:" + fromWei(c_WETH,'ether') + "; USDT:" + fromWei(c_USDT,'mwei') + "; USDC:" + fromWei(c_USDC,'mwei'));
|
||||
var a_w_eth = await ctx.Web3.eth.getBalance(ctx.WETH.options.address)
|
||||
console.log("weth contract After:" + fromWei(a_w_eth,'ether'))
|
||||
});
|
||||
|
||||
|
||||
it("ETH to USDT wrap eth and two hops swap", async () => {
|
||||
var b_ETH = await ctx.Web3.eth.getBalance(trader)
|
||||
var b_WETH = await ctx.WETH.methods.balanceOf(trader).call()
|
||||
var b_USDT = await ctx.USDT.methods.balanceOf(trader).call()
|
||||
console.log("Before ETH:" + fromWei(b_ETH,'ether') + "; WETH:" + fromWei(b_WETH,'ether') + "; USDT:" + fromWei(b_USDT,'mwei'));
|
||||
var b_w_eth = await ctx.Web3.eth.getBalance(ctx.WETH.options.address)
|
||||
console.log("weth contract Before:" + fromWei(b_w_eth,'ether'))
|
||||
//set route path
|
||||
var routes = [{
|
||||
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||
decimals: 18
|
||||
},{
|
||||
address: ctx.USDC.options.address,
|
||||
decimals: 6
|
||||
},{
|
||||
address: ctx.USDT.options.address,
|
||||
decimals: 6
|
||||
}];
|
||||
|
||||
var pairs = [{
|
||||
pair: ctx.WETH_USDC.options.address,
|
||||
base: ctx.WETH.options.address,
|
||||
pairContract: ctx.WETH_USDC
|
||||
},{
|
||||
pair: ctx.USDT_USDC.options.address,
|
||||
base: ctx.USDT.options.address,
|
||||
pairContract: ctx.USDT_USDC
|
||||
}];
|
||||
|
||||
var tx = await logGas(await calcRoute(ctx,decimalStr('1'),0.1,routes,pairs), ctx.sendParam(trader,'1'), "wrap eth and tow hops swap")
|
||||
var a_ETH = await ctx.Web3.eth.getBalance(trader)
|
||||
var a_WETH = await ctx.WETH.methods.balanceOf(trader).call()
|
||||
var a_USDT = await ctx.USDT.methods.balanceOf(trader).call()
|
||||
console.log("After ETH:" + fromWei(a_ETH,'ether') + "; WETH:" + fromWei(a_WETH,'ether') + "; USDT:" + fromWei(a_USDT,'mwei'));
|
||||
console.log("===============================================")
|
||||
var c_ETH = await ctx.Web3.eth.getBalance(ctx.SmartSwap.options.address)
|
||||
var c_WETH = await ctx.WETH.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
var c_USDT = await ctx.USDT.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
var c_USDC = await ctx.USDC.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
console.log("Contract ETH:" + fromWei(c_ETH,'ether') + "; WETH:" + fromWei(c_WETH,'ether') + "; USDT:" + fromWei(c_USDT,'mwei') + "; USDC:" + fromWei(c_USDC,'mwei'));
|
||||
var a_w_eth = await ctx.Web3.eth.getBalance(ctx.WETH.options.address)
|
||||
console.log("weth contract After:" + fromWei(a_w_eth,'ether'))
|
||||
});
|
||||
|
||||
|
||||
it("DODO to ETH unwrap eth and three hops swap", async () => {
|
||||
var b_DODO = await ctx.DODO.methods.balanceOf(trader).call()
|
||||
var b_ETH = await ctx.Web3.eth.getBalance(trader)
|
||||
var b_WETH = await ctx.WETH.methods.balanceOf(trader).call()
|
||||
console.log("User Before ETH:" + fromWei(b_ETH,'ether') + "; WETH:" + fromWei(b_WETH,'ether') + "; DODO:" + fromWei(b_DODO,'ether'));
|
||||
var b_w_eth = await ctx.Web3.eth.getBalance(ctx.WETH.options.address)
|
||||
console.log("weth contract Before:" + fromWei(b_w_eth,'ether'))
|
||||
|
||||
//approve DODO entry
|
||||
await ctx.DODO.methods.approve(ctx.SmartApprove.options.address,MAX_UINT256).send(ctx.sendParam(trader))
|
||||
//set route path
|
||||
var routes = [{
|
||||
address: ctx.DODO.options.address,
|
||||
decimals: 18
|
||||
},{
|
||||
address: ctx.USDT.options.address,
|
||||
decimals: 6
|
||||
},{
|
||||
address: ctx.USDC.options.address,
|
||||
decimals: 6
|
||||
},{
|
||||
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||
decimals: 18
|
||||
}];
|
||||
|
||||
var pairs = [{
|
||||
pair: ctx.DODO_USDT.options.address,
|
||||
base: ctx.DODO.options.address,
|
||||
pairContract: ctx.DODO_USDT
|
||||
},{
|
||||
pair: ctx.USDT_USDC.options.address,
|
||||
base: ctx.USDT.options.address,
|
||||
pairContract: ctx.USDT_USDC
|
||||
},{
|
||||
pair: ctx.WETH_USDC.options.address,
|
||||
base: ctx.WETH.options.address,
|
||||
pairContract: ctx.WETH_USDC
|
||||
}];
|
||||
|
||||
var tx = await logGas(await calcRoute(ctx,decimalStr('1000'),0.1,routes,pairs), ctx.sendParam(trader), "unwrap eth and three hops swap")
|
||||
var a_ETH = await ctx.Web3.eth.getBalance(trader)
|
||||
var a_WETH = await ctx.WETH.methods.balanceOf(trader).call()
|
||||
var a_DODO = await ctx.DODO.methods.balanceOf(trader).call()
|
||||
console.log("After ETH:" + fromWei(a_ETH,'ether') + "; WETH:" + fromWei(a_WETH,'ether') + "; DODO:" + fromWei(a_DODO,'ether'));
|
||||
console.log("===============================================")
|
||||
var c_ETH = await ctx.Web3.eth.getBalance(ctx.SmartSwap.options.address)
|
||||
var c_WETH = await ctx.WETH.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
var c_USDT = await ctx.USDT.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
var c_USDC = await ctx.USDC.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
var c_DODO = await ctx.DODO.methods.balanceOf(ctx.SmartSwap.options.address).call()
|
||||
console.log("Contract ETH:" + fromWei(c_ETH,'ether') + "; WETH:" + fromWei(c_WETH,'ether') + "; USDT:" + fromWei(c_USDT,'mwei') + "; USDC:" + fromWei(c_USDC,'mwei') + "; DODO:" + fromWei(c_DODO,"ether"));
|
||||
var w_eth = await ctx.Web3.eth.getBalance(ctx.WETH.options.address)
|
||||
console.log("weth contract After:" + fromWei(w_eth,'ether'))
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user