Merge branch 'feature/V2' of github.com:DODOEX/contractV2 into feature/V2
This commit is contained in:
40
contracts/SmartRoute/helper/DODOSwapCalcHelper.sol
Normal file
40
contracts/SmartRoute/helper/DODOSwapCalcHelper.sol
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {IDODOV1} from "../intf/IDODOV1.sol";
|
||||
import {IDODOSellHelper} from "./DODOSellHelper.sol";
|
||||
|
||||
contract DODOSwapCalcHelper {
|
||||
address public immutable _DODO_SELL_HELPER_;
|
||||
|
||||
constructor(address dodoSellHelper) public {
|
||||
_DODO_SELL_HELPER_ = dodoSellHelper;
|
||||
}
|
||||
|
||||
function calcReturnAmountV1(
|
||||
uint256 fromTokenAmount,
|
||||
address[] memory dodoPairs,
|
||||
uint8[] memory directions
|
||||
) external view returns (uint256 returnAmount,uint256[] memory midPrices) {
|
||||
returnAmount = fromTokenAmount;
|
||||
midPrices = new uint256[](dodoPairs.length);
|
||||
for (uint256 i = 0; i < dodoPairs.length; i++) {
|
||||
address curDodoPair = dodoPairs[i];
|
||||
if (directions[i] == 0) {
|
||||
returnAmount = IDODOV1(curDodoPair).querySellBaseToken(returnAmount);
|
||||
} else {
|
||||
returnAmount = IDODOSellHelper(_DODO_SELL_HELPER_).querySellQuoteToken(
|
||||
curDodoPair,
|
||||
returnAmount
|
||||
);
|
||||
}
|
||||
midPrices[i] = IDODOV1(curDodoPair).getMidPrice();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,4 +77,6 @@ interface IDODOV1 {
|
||||
function getExpectedTarget() external view returns (uint256 baseTarget, uint256 quoteTarget);
|
||||
|
||||
function getOraclePrice() external view returns (uint256);
|
||||
|
||||
function getMidPrice() external view returns (uint256 midPrice);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
====================================================
|
||||
network type: kovan
|
||||
Deploy time: 2020/12/7 下午3:15:48
|
||||
Deploy time: 2020/12/9 下午10:11:50
|
||||
DODOSwapCalcHelper Address: 0x096b90D15AB8319f6829C96E7062556b74806988
|
||||
====================================================
|
||||
network type: bsclive
|
||||
Deploy time: 2020/12/9 下午10:14:15
|
||||
DODOSwapCalcHelper Address: 0xED3Ac3335a24331F1704df8CB456C88dCA282782
|
||||
====================================================
|
||||
network type: live
|
||||
Deploy time: 2020/12/9 下午10:16:19
|
||||
DODOSwapCalcHelper Address: 0x22C1a736DBE8200E6DF2f3D8F97c0D5749c1E257
|
||||
|
||||
@@ -5,17 +5,20 @@ let logger = new console.Console(file, file);
|
||||
const DODOApprove = artifacts.require("DODOApprove");
|
||||
const DODOProxyV1 = artifacts.require("DODOV1Proxy01");
|
||||
const DODOSellHelper = artifacts.require("DODOSellHelper");
|
||||
const DODOSwapCalcHelper = artifacts.require("DODOSwapCalcHelper");
|
||||
|
||||
const DEPLOY_ROUTE = false;
|
||||
const DEPLOY_ROUTE = true;
|
||||
|
||||
module.exports = async (deployer, network, accounts) => {
|
||||
let DODOSellHelperAddress = "";
|
||||
let WETHAddress = "";
|
||||
let DODOApproveAddress = "";
|
||||
let chiAddress = "";
|
||||
let DODOSwapCalcHelperAddress = "";
|
||||
if (network == "kovan") {
|
||||
DODOSellHelperAddress = "0xbdEae617F2616b45DCB69B287D52940a76035Fe3";
|
||||
WETHAddress = "0x5eca15b12d959dfcf9c71c59f8b467eb8c6efd0b";
|
||||
DODOSwapCalcHelperAddress = "";
|
||||
// DODOApproveAddress = "0xbcf0fC05860b14cB3D62D1d4C7f531Ad2F28E0fE";
|
||||
DODOApproveAddress = "0x0C4a80B2e234448E5f6fD86e7eFA733d985004c8";
|
||||
chiAddress = "0x0000000000004946c0e9f43f4dee607b0ef1fa1c";
|
||||
@@ -24,19 +27,22 @@ module.exports = async (deployer, network, accounts) => {
|
||||
WETHAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
|
||||
DODOApproveAddress = "0x4eC851895d85bfa6835241b3157ae10FfFD3BebC";
|
||||
chiAddress = "0x0000000000004946c0e9F43F4Dee607b0eF1fA1c";
|
||||
DODOSwapCalcHelperAddress = "";
|
||||
} else if (network == "bsclive") {
|
||||
DODOSellHelperAddress = "0x0F859706AeE7FcF61D5A8939E8CB9dBB6c1EDA33";
|
||||
WETHAddress = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";
|
||||
DODOApproveAddress = "0x19DA73be23Cea6bFA804Ec020041b8F3971BC522";
|
||||
chiAddress = "0x0000000000000000000000000000000000000000";
|
||||
DODOSwapCalcHelperAddress = "";
|
||||
} else return;
|
||||
|
||||
logger.log("====================================================");
|
||||
logger.log("network type: " + network);
|
||||
logger.log("Deploy time: " + new Date().toLocaleString());
|
||||
|
||||
if (DEPLOY_ROUTE) {
|
||||
logger.log("Deploy type: Proxy");
|
||||
|
||||
logger.log("====================================================");
|
||||
logger.log("network type: " + network);
|
||||
logger.log("Deploy time: " + new Date().toLocaleString());
|
||||
|
||||
// logger.log("Deploy type: Proxy");
|
||||
if (DODOApproveAddress == "") {
|
||||
await deployer.deploy(DODOApprove);
|
||||
DODOApproveAddress = DODOApprove.address;
|
||||
@@ -45,19 +51,25 @@ module.exports = async (deployer, network, accounts) => {
|
||||
await deployer.deploy(DODOSellHelper);
|
||||
DODOSellHelperAddress = DODOSellHelper.address;
|
||||
}
|
||||
logger.log("DODOApprove Address: ", DODOApproveAddress);
|
||||
logger.log("DODOSellHelper Address: ", DODOSellHelperAddress);
|
||||
await deployer.deploy(
|
||||
DODOProxyV1,
|
||||
DODOApproveAddress,
|
||||
DODOSellHelperAddress,
|
||||
WETHAddress,
|
||||
chiAddress
|
||||
);
|
||||
logger.log("DODOProxyV1 Address: ", DODOProxyV1.address);
|
||||
if (DODOSwapCalcHelperAddress == "") {
|
||||
await deployer.deploy(DODOSwapCalcHelper, DODOSellHelperAddress);
|
||||
DODOSwapCalcHelperAddress = DODOSwapCalcHelper.address;
|
||||
}
|
||||
// logger.log("DODOApprove Address: ", DODOApproveAddress);
|
||||
// logger.log("DODOSellHelper Address: ", DODOSellHelperAddress);
|
||||
logger.log("DODOSwapCalcHelper Address: ", DODOSwapCalcHelperAddress);
|
||||
|
||||
const DODOApproveInstance = await DODOApprove.at(DODOApproveAddress);
|
||||
var tx = await DODOApproveInstance.setDODOProxy(DODOProxyV1.address);
|
||||
logger.log("DODOApprovce setProxy tx: ", tx.tx);
|
||||
// await deployer.deploy(
|
||||
// DODOProxyV1,
|
||||
// DODOApproveAddress,
|
||||
// DODOSellHelperAddress,
|
||||
// WETHAddress,
|
||||
// chiAddress
|
||||
// );
|
||||
// logger.log("DODOProxyV1 Address: ", DODOProxyV1.address);
|
||||
|
||||
// const DODOApproveInstance = await DODOApprove.at(DODOApproveAddress);
|
||||
// var tx = await DODOApproveInstance.setDODOProxy(DODOProxyV1.address);
|
||||
// logger.log("DODOApprovce setProxy tx: ", tx.tx);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ const DODOProxyV2 = artifacts.require("DODOV2Proxy01");
|
||||
const DODOSellHelper = artifacts.require("DODOSellHelper");
|
||||
const DODOCalleeHelper = artifacts.require("DODOCalleeHelper");
|
||||
|
||||
const DEPLOY_V2 = true;
|
||||
const DEPLOY_V2 = false;
|
||||
|
||||
module.exports = async (deployer, network, accounts) => {
|
||||
let DODOSellHelperAddress = "";
|
||||
@@ -72,11 +72,11 @@ module.exports = async (deployer, network, accounts) => {
|
||||
//Template
|
||||
} else return;
|
||||
|
||||
logger.log("====================================================");
|
||||
logger.log("network type: " + network);
|
||||
logger.log("Deploy time: " + new Date().toLocaleString());
|
||||
|
||||
if (DEPLOY_V2) {
|
||||
logger.log("====================================================");
|
||||
logger.log("network type: " + network);
|
||||
logger.log("Deploy time: " + new Date().toLocaleString());
|
||||
logger.log("Deploy type: V2");
|
||||
if (CloneFactoryAddress == "") {
|
||||
await deployer.deploy(CloneFactory);
|
||||
|
||||
@@ -105,10 +105,19 @@ async function calcRoute(ctx: DODOContext, fromTokenAmount: string, slippage: nu
|
||||
}
|
||||
}
|
||||
|
||||
var [returmAmount, midPrices] = await ctx.DODOSwapCalcHelper.methods.calcReturnAmountV1(
|
||||
fromTokenAmount,
|
||||
dodoPairs,
|
||||
directions,
|
||||
).call();
|
||||
console.log("returnAmount:", returmAmount)
|
||||
console.log("localAmount:", swapAmount)
|
||||
console.log("midPrices:", midPrices)
|
||||
|
||||
|
||||
let toAmount = new BigNumber(swapAmount).multipliedBy(1 - slippage).toFixed(0, BigNumber.ROUND_DOWN)
|
||||
// console.log("minAmount:",toAmount);
|
||||
let deadline = Math.floor(new Date().getTime()/1000 + 60 * 10);
|
||||
let deadline = Math.floor(new Date().getTime() / 1000 + 60 * 10);
|
||||
|
||||
return ctx.DODOProxyV1.methods.dodoSwapV1(
|
||||
routes[0].address,
|
||||
@@ -144,7 +153,7 @@ describe("Trader", () => {
|
||||
});
|
||||
|
||||
describe("route calc test", () => {
|
||||
it.only("DODO to USDT directly swap", async () => {
|
||||
it("DODO to USDT directly swap", async () => {
|
||||
var b_DODO = await ctx.DODO.methods.balanceOf(trader).call()
|
||||
var b_USDT = await ctx.USDT.methods.balanceOf(trader).call()
|
||||
var c_b_CHI = await ctx.CHI.methods.balanceOf(ctx.DODOProxyV1.options.address).call()
|
||||
|
||||
@@ -32,6 +32,7 @@ const SmartApprove = require(`${jsonPath2}DODOApprove.json`)
|
||||
const DODOSellHelper = require(`${jsonPath2}DODOSellHelper.json`)
|
||||
const WETH = require(`${jsonPath2}WETH9.json`)
|
||||
const CHI = require(`${jsonPath2}ChiToken.json`)
|
||||
const DODOSwapCalcHelper = require(`${jsonPath2}DODOSwapCalcHelper.json`)
|
||||
/******/
|
||||
|
||||
import { getDefaultWeb3 } from './EVM';
|
||||
@@ -57,6 +58,7 @@ export const SMART_SWAP = "DODOV1Proxy01"
|
||||
export const SMART_APPROVE = "DODOApprove"
|
||||
export const DODO_SELL_HELPER = "DODOSellHelper"
|
||||
export const CHI_TOKEN = "ChiToken"
|
||||
export const DODO_SWAP_CALC_HELPER = "DODOSwapCalcHelper"
|
||||
/******/
|
||||
|
||||
var contractMap: { [name: string]: any } = {}
|
||||
@@ -79,6 +81,7 @@ contractMap[SMART_SWAP] = SmartSwap
|
||||
contractMap[SMART_APPROVE] = SmartApprove
|
||||
contractMap[DODO_SELL_HELPER] = DODOSellHelper
|
||||
contractMap[CHI_TOKEN] = CHI
|
||||
contractMap[DODO_SWAP_CALC_HELPER] = DODOSwapCalcHelper
|
||||
/******/
|
||||
|
||||
interface ContractJson {
|
||||
|
||||
@@ -74,6 +74,8 @@ export class DODOContext {
|
||||
DODOProxyV1: Contract;
|
||||
DODOApprove: Contract;
|
||||
DODOSellHelper: Contract;
|
||||
//Helper
|
||||
DODOSwapCalcHelper: Contract;
|
||||
|
||||
constructor() { }
|
||||
|
||||
@@ -238,6 +240,10 @@ export class DODOContext {
|
||||
await this.DODOApprove.methods.setDODOProxy(this.DODOProxyV1.options.address).send(this.sendParam(this.Deployer));
|
||||
|
||||
// await this.CHI.methods.transfer(this.DODOProxyV1.options.address,140).send(this.sendParam(this.Deployer));
|
||||
|
||||
this.DODOSwapCalcHelper = await contracts.newContract(
|
||||
contracts.DODO_SWAP_CALC_HELPER,[this.DODOSellHelper.options.address]
|
||||
);
|
||||
|
||||
console.log(log.blueText("[Init dodo context]"));
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ module.exports = {
|
||||
return new HDWalletProvider(privKey, "https://mainnet.infura.io/v3/" + infuraId);
|
||||
},
|
||||
gas: 3000000,
|
||||
gasPrice: 45000000000,
|
||||
gasPrice: 50000000000,
|
||||
network_id: 1,
|
||||
skipDryRun: true
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user