From 1ff3f0daf60e80fb6e9f7a0f7a84292ef92e545d Mon Sep 17 00:00:00 2001 From: owen05 Date: Mon, 7 Dec 2020 16:20:59 +0800 Subject: [PATCH] add gas token && deploy kovan script --- contracts/Factory/DPPFactory.sol | 14 +- contracts/Factory/DVMFactory.sol | 10 +- contracts/SmartRoute/DODOV1Proxy01.sol | 69 ++- contracts/SmartRoute/DODOV2Proxy01.sol | 24 +- .../SmartRoute/helper/DODOCalleeHelper.sol | 4 +- contracts/SmartRoute/intf/IChi.sol | 13 + contracts/external/ERC20/ChiToken.sol | 471 ++++++++++++++++++ deploy-detail-v1.5.txt | 3 + deploy-detail-v2.0.txt | 18 + deploy-detail.txt | 0 migrations/2_deploy.js | 156 ------ migrations/2_deploy_v1.5.js | 63 +++ migrations/3_deploy_v2.js | 189 +++++++ test/Route/Route.test.ts | 11 +- test/utils-v1/Contracts.ts | 3 + test/utils-v1/ProxyContextV1.ts | 14 +- truffle-config.js | 11 +- 17 files changed, 862 insertions(+), 211 deletions(-) create mode 100644 contracts/SmartRoute/intf/IChi.sol create mode 100644 contracts/external/ERC20/ChiToken.sol create mode 100644 deploy-detail-v1.5.txt create mode 100644 deploy-detail-v2.0.txt delete mode 100644 deploy-detail.txt delete mode 100644 migrations/2_deploy.js create mode 100644 migrations/2_deploy_v1.5.js create mode 100644 migrations/3_deploy_v2.js diff --git a/contracts/Factory/DPPFactory.sol b/contracts/Factory/DPPFactory.sol index 81f8038..7053668 100644 --- a/contracts/Factory/DPPFactory.sol +++ b/contracts/Factory/DPPFactory.sol @@ -19,14 +19,14 @@ import {IPermissionManager} from "../lib/PermissionManager.sol"; contract DPPFactory is Ownable { // ============ Templates ============ - address public _CLONE_FACTORY_; - address public _DPP_TEMPLATE_; + address public immutable _CLONE_FACTORY_; + address public immutable _DPP_TEMPLATE_; + address public immutable _FEE_RATE_MODEL_TEMPLATE_; + address public immutable _PERMISSION_MANAGER_TEMPLATE_; + address public immutable _DEFAULT_GAS_PRICE_SOURCE_; + address public immutable _VALUE_SOURCE_; + address public immutable _DODO_SMART_APPROVE_; address public _DPP_ADMIN_TEMPLATE_; - address public _FEE_RATE_MODEL_TEMPLATE_; - address public _PERMISSION_MANAGER_TEMPLATE_; - address public _DEFAULT_GAS_PRICE_SOURCE_; - address public _VALUE_SOURCE_; - address public _DODO_SMART_APPROVE_; // ============ Registry ============ diff --git a/contracts/Factory/DVMFactory.sol b/contracts/Factory/DVMFactory.sol index 4bdf96f..3ab3fd0 100644 --- a/contracts/Factory/DVMFactory.sol +++ b/contracts/Factory/DVMFactory.sol @@ -18,12 +18,12 @@ import {IPermissionManager} from "../lib/PermissionManager.sol"; contract DVMFactory is Ownable { // ============ Templates ============ - address public _CLONE_FACTORY_; - address public _DVM_TEMPLATE_; + address public immutable _CLONE_FACTORY_; + address public immutable _DVM_TEMPLATE_; + address public immutable _FEE_RATE_MODEL_TEMPLATE_; + address public immutable _PERMISSION_MANAGER_TEMPLATE_; + address public immutable _DEFAULT_GAS_PRICE_SOURCE_; address public _DVM_ADMIN_TEMPLATE_; - address public _FEE_RATE_MODEL_TEMPLATE_; - address public _PERMISSION_MANAGER_TEMPLATE_; - address public _DEFAULT_GAS_PRICE_SOURCE_; // ============ Registry ============ diff --git a/contracts/SmartRoute/DODOV1Proxy01.sol b/contracts/SmartRoute/DODOV1Proxy01.sol index 8d76e7b..89ae848 100644 --- a/contracts/SmartRoute/DODOV1Proxy01.sol +++ b/contracts/SmartRoute/DODOV1Proxy01.sol @@ -13,20 +13,25 @@ import {SafeMath} from "../lib/SafeMath.sol"; import {IDODOV1} from "./intf/IDODOV1.sol"; import {IDODOSellHelper} from "./helper/DODOSellHelper.sol"; import {IWETH} from "../intf/IWETH.sol"; +import {IChi} from "./intf/IChi.sol"; import {IDODOApprove} from "../intf/IDODOApprove.sol"; import {IDODOV1Proxy01} from "./intf/IDODOV1Proxy01.sol"; import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol"; +import {Ownable} from "../lib/Ownable.sol"; -contract DODOV1Proxy01 is IDODOV1Proxy01, ReentrancyGuard { +contract DODOV1Proxy01 is IDODOV1Proxy01, ReentrancyGuard, Ownable { using SafeMath for uint256; using UniversalERC20 for IERC20; // ============ Storage ============ address constant _ETH_ADDRESS_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; - address public _DODO_APPROVE_; - address public _DODO_SELL_HELPER_; - address payable public _WETH_; + address public immutable _DODO_APPROVE_; + address public immutable _DODO_SELL_HELPER_; + address public immutable _WETH_; + address public immutable _CHI_TOKEN_; + uint8 public _GAS_DODO_MAX_RETURN_ = 0; + uint8 public _GAS_EXTERNAL_RETURN_ = 0; // ============ Events ============ @@ -48,17 +53,24 @@ contract DODOV1Proxy01 is IDODOV1Proxy01, ReentrancyGuard { constructor( address dodoApporve, address dodoSellHelper, - address payable weth + address weth, + address chiToken ) public { _DODO_APPROVE_ = dodoApporve; _DODO_SELL_HELPER_ = dodoSellHelper; _WETH_ = weth; + _CHI_TOKEN_ = chiToken; } fallback() external payable {} receive() external payable {} + function updateGasReturn(uint8 newDodoGasReturn, uint8 newExternalGasReturn) public onlyOwner { + _GAS_DODO_MAX_RETURN_ = newDodoGasReturn; + _GAS_EXTERNAL_RETURN_ = newExternalGasReturn; + } + function dodoSwapV1( address fromToken, address toToken, @@ -67,7 +79,9 @@ contract DODOV1Proxy01 is IDODOV1Proxy01, ReentrancyGuard { address[] memory dodoPairs, uint8[] memory directions, uint256 deadLine - ) external virtual override payable judgeExpired(deadLine) returns (uint256 returnAmount) { + ) external override payable judgeExpired(deadLine) returns (uint256 returnAmount) { + uint256 originGas = gasleft(); + if (fromToken != _ETH_ADDRESS_) { IDODOApprove(_DODO_APPROVE_).claimTokens( fromToken, @@ -108,8 +122,16 @@ contract DODOV1Proxy01 is IDODOV1Proxy01, ReentrancyGuard { require(returnAmount >= minReturnAmount, "DODOV1Proxy01: Return amount is not enough"); IERC20(toToken).universalTransfer(msg.sender, returnAmount); - + emit OrderHistory(fromToken, toToken, msg.sender, fromTokenAmount, returnAmount); + + uint8 _gasDodoMaxReturn = _GAS_DODO_MAX_RETURN_; + if(_gasDodoMaxReturn > 0) { + uint256 calcGasTokenBurn = originGas.sub(gasleft()) / 65000; + uint256 gasTokenBurn = calcGasTokenBurn > _gasDodoMaxReturn ? _gasDodoMaxReturn : calcGasTokenBurn; + if(gasleft() > 27710 + gasTokenBurn * 6080) + IChi(_CHI_TOKEN_).freeUpTo(gasTokenBurn); + } } function externalSwap( @@ -121,35 +143,44 @@ contract DODOV1Proxy01 is IDODOV1Proxy01, ReentrancyGuard { uint256 minReturnAmount, bytes memory callDataConcat, uint256 deadLine - ) external virtual override payable judgeExpired(deadLine) returns (uint256 returnAmount) { - uint256 toTokenOriginBalance = IERC20(toToken).universalBalanceOf(msg.sender); + ) external override payable judgeExpired(deadLine) returns (uint256 returnAmount) { + address _fromToken = fromToken; + address _toToken = toToken; + + uint256 toTokenOriginBalance = IERC20(_toToken).universalBalanceOf(msg.sender); - if (fromToken != _ETH_ADDRESS_) { + if (_fromToken != _ETH_ADDRESS_) { IDODOApprove(_DODO_APPROVE_).claimTokens( - fromToken, + _fromToken, msg.sender, address(this), fromTokenAmount ); - IERC20(fromToken).universalApproveMax(approveTarget, fromTokenAmount); + IERC20(_fromToken).universalApproveMax(approveTarget, fromTokenAmount); } - (bool success, ) = to.call{value: fromToken == _ETH_ADDRESS_ ? msg.value : 0}(callDataConcat); + (bool success, ) = to.call{value: _fromToken == _ETH_ADDRESS_ ? msg.value : 0}(callDataConcat); require(success, "DODOV1Proxy01: Contract Swap execution Failed"); - IERC20(fromToken).universalTransfer( + IERC20(_fromToken).universalTransfer( msg.sender, - IERC20(fromToken).universalBalanceOf(address(this)) + IERC20(_fromToken).universalBalanceOf(address(this)) ); - IERC20(toToken).universalTransfer( + IERC20(_toToken).universalTransfer( msg.sender, - IERC20(toToken).universalBalanceOf(address(this)) + IERC20(_toToken).universalBalanceOf(address(this)) ); - returnAmount = IERC20(toToken).universalBalanceOf(msg.sender).sub(toTokenOriginBalance); + returnAmount = IERC20(_toToken).universalBalanceOf(msg.sender).sub(toTokenOriginBalance); require(returnAmount >= minReturnAmount, "DODOV1Proxy01: Return amount is not enough"); - emit OrderHistory(fromToken, toToken, msg.sender, fromTokenAmount, returnAmount); + emit OrderHistory(_fromToken, _toToken, msg.sender, fromTokenAmount, returnAmount); + + uint8 _gasExternalReturn = _GAS_EXTERNAL_RETURN_; + if(_gasExternalReturn > 0) { + if(gasleft() > 27710 + _gasExternalReturn * 6080) + IChi(_CHI_TOKEN_).freeUpTo(_gasExternalReturn); + } } } diff --git a/contracts/SmartRoute/DODOV2Proxy01.sol b/contracts/SmartRoute/DODOV2Proxy01.sol index 68e0918..87bd0eb 100644 --- a/contracts/SmartRoute/DODOV2Proxy01.sol +++ b/contracts/SmartRoute/DODOV2Proxy01.sol @@ -27,11 +27,11 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { // ============ Storage ============ address constant _ETH_ADDRESS_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; - address payable public _WETH_; - address public _DODO_APPROVE_; - address public _DODO_SELL_HELPER_; - address public _DVM_FACTORY_; - address public _DPP_FACTORY_; + address public immutable _WETH_; + address public immutable _DODO_APPROVE_; + address public immutable _DODO_SELL_HELPER_; + address public immutable _DVM_FACTORY_; + address public immutable _DPP_FACTORY_; // ============ Events ============ @@ -83,7 +83,6 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { uint256 deadLine ) external - virtual override payable preventReentrant @@ -137,7 +136,6 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { uint256 deadLine ) external - virtual override payable preventReentrant @@ -172,7 +170,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { address dvmAddress, uint256 baseInAmount, uint256 quoteInAmount - ) internal virtual view returns (uint256 baseAdjustedInAmount, uint256 quoteAdjustedInAmount) { + ) internal view returns (uint256 baseAdjustedInAmount, uint256 quoteAdjustedInAmount) { (uint256 baseReserve, uint256 quoteReserve) = IDODOV2(dvmAddress).getVaultReserve(); if (quoteReserve == 0 && baseReserve == 0) { baseAdjustedInAmount = baseInAmount; @@ -209,7 +207,6 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { uint256 deadLine ) external - virtual override payable preventReentrant @@ -256,7 +253,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { uint256 quoteOutAmount, uint8 flag, // 0 - ERC20, 1 - baseInETH, 2 - quoteInETH, 3 - baseOutETH, 4 - quoteOutETH uint256 deadLine - ) external virtual override payable preventReentrant judgeExpired(deadLine) { + ) external override payable preventReentrant judgeExpired(deadLine) { _deposit( msg.sender, dppAddress, @@ -297,7 +294,6 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { uint256 deadLine ) external - virtual override payable judgeExpired(deadLine) @@ -345,7 +341,6 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { uint256 deadLine ) external - virtual override judgeExpired(deadLine) returns (uint256 returnAmount) @@ -391,7 +386,6 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { uint256 deadLine ) external - virtual override judgeExpired(deadLine) returns (uint256 returnAmount) @@ -436,7 +430,6 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { uint256 deadLine ) external - virtual override payable judgeExpired(deadLine) @@ -490,7 +483,6 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { uint256 deadLine ) external - virtual override payable judgeExpired(deadLine) @@ -540,7 +532,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard { uint256 quoteMinShares, uint8 flag, // 0 erc20 In 1 baseInETH 2 quoteIn ETH uint256 deadLine - ) external virtual override payable judgeExpired(deadLine) returns(uint256 baseShares, uint256 quoteShares) { + ) external override payable judgeExpired(deadLine) returns(uint256 baseShares, uint256 quoteShares) { address _baseToken = IDODOV1(pair)._BASE_TOKEN_(); address _quoteToken = IDODOV1(pair)._QUOTE_TOKEN_(); diff --git a/contracts/SmartRoute/helper/DODOCalleeHelper.sol b/contracts/SmartRoute/helper/DODOCalleeHelper.sol index a2320f0..1e1f1d3 100644 --- a/contracts/SmartRoute/helper/DODOCalleeHelper.sol +++ b/contracts/SmartRoute/helper/DODOCalleeHelper.sol @@ -15,7 +15,7 @@ import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol"; contract DODOCalleeHelper is ReentrancyGuard { using SafeERC20 for IERC20; - address payable public _WETH_; + address public immutable _WETH_; fallback() external payable { require(msg.sender == _WETH_, "WE_SAVED_YOUR_ETH"); @@ -25,7 +25,7 @@ contract DODOCalleeHelper is ReentrancyGuard { require(msg.sender == _WETH_, "WE_SAVED_YOUR_ETH"); } - constructor(address payable weth) public { + constructor(address weth) public { _WETH_ = weth; } diff --git a/contracts/SmartRoute/intf/IChi.sol b/contracts/SmartRoute/intf/IChi.sol new file mode 100644 index 0000000..0478701 --- /dev/null +++ b/contracts/SmartRoute/intf/IChi.sol @@ -0,0 +1,13 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +pragma solidity 0.6.9; +pragma experimental ABIEncoderV2; + +interface IChi { + function freeUpTo(uint256 value) external returns (uint256); +} diff --git a/contracts/external/ERC20/ChiToken.sol b/contracts/external/ERC20/ChiToken.sol new file mode 100644 index 0000000..6680ce2 --- /dev/null +++ b/contracts/external/ERC20/ChiToken.sol @@ -0,0 +1,471 @@ +/** + *Submitted for verification at Etherscan.io on 2020-05-24 +*/ + +/* + ,╖╗#▒▓▓▓▓▓╣╬╣▓▓▓▓▒#╗╗╓, + ,╗@▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓╗╖ + ╓#▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╝▀╠╠▄╣╝╜"""╙╙▀╝╝╣╬╬╬╬▓▌╖ + ╓▓╣╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▀`╓å▓▓▓╙ ,▄▓▓██▓▓▓▄▄▄▄▄╠╠╙╠▄▄ + ╓@╣╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▌ ê`' *▀▀▀▀▀▀▀▓██████████████▄ + ╔▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╙▀████████████▌ + ╓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╙████████████▌ + ,▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▀ ╗▄█████████████▄ + é╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▌ #╙ ╙▀█████████████▓ + ╣╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▀ ╙▓╬╣▓▄ ╙▀▀███████████µ + ▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▀╣╝╙ ╒▓╬╬╬╬╬╬▓ ╙████████████████µ + ▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▌ ╖╖╖▄▓╬╬╬╬╬╬╬▓ █████████████████µ + ╣╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ,#▓╣╬╬▓╬╬╬╬╬╬╬╬╬╬╬╬▌ ▓█████████████████ + ]╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╓╖ ]╣╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣╨ ██████████████████▌ + ▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▌╖, ╙╠╠▓╬╬╬╬╬╬╬╬╬▓╝╙ ╫███████████████████ + ]╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╝▀╙ ▓████████████████████▌ + ║╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╝▀╙` ▄███████████████████████ + ╟╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓╝▀╙ ,▄█████████████████████████ + ╟╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╝╜` ▄▓████████████████████████████ + ║╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╣▀` ,▄▄▓████████████████████████████████ + ▐╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓╙ ,,,▄╠▓██████████████████████████████▌ + ╣╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓╙╔▒` ╓▄▓████████████████████████████████████████⌐ + ╚╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓╣▓ ▄▓████████████████████████████████████████████ + ▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ▄██████████████████████████████████████████████⌐ + ╣╬╬╬╬╬╬╬╬╬╬╬╬╬╛ ▄███████████████████████████████████████████████▌ + └╣╬╬╬╬╬╬╬╬╬╬╬▓ ▄███████████████████████████████████████████████▌ + └▓╬╬╬╬╬╬╬╬╬╬Γ ]███████████████████████████████████████████████▀ + ╣╬╬╬╬╬╬╬╬╬⌐ ╫████████████████████████████████▀▀▀▀▀▓████████╜ + ╙╬╬╬╬╬╬╬╬⌐ ╟███████████████████████████▀╙ ,▄▓▓▓▓▓████▓ + ╫╬╬╬╬╬╬b ████████████████████████▀` ,Φ▀▀█████████╙ + ╫╬╬╬╬▌╟ ██████████████████▀╓▀─ ▄▓█████████▀ + ╚╣╬▓╣▓ └▀████████████▀` ╓▓█████████▓╙ + ╙╝╬╬▓ .▄▄▓█▀▀▀` ▄▓█████████▀ + ╙▀▓▄ ƒ,▓███████▀▀ + " ╓▓█▓█████▀▀└ + ╓▄▓████▀▀╙└ + + ██████╗██╗ ██╗██╗ ██████╗ █████╗ ███████╗████████╗ ██████╗ ██╗ ██╗███████╗███╗ ██╗ ██████╗ ██╗ ██╗ ██╗██╗███╗ ██╗ ██████╗██╗ ██╗ +██╔════╝██║ ██║██║ ██╔════╝ ██╔══██╗██╔════╝╚══██╔══╝██╔═══██╗██║ ██╔╝██╔════╝████╗ ██║ ██╔══██╗╚██╗ ██╔╝ ███║██║████╗ ██║██╔════╝██║ ██║ +██║ ███████║██║ ██║ ███╗███████║███████╗ ██║ ██║ ██║█████╔╝ █████╗ ██╔██╗ ██║ ██████╔╝ ╚████╔╝ ╚██║██║██╔██╗ ██║██║ ███████║ +██║ ██╔══██║██║ ██║ ██║██╔══██║╚════██║ ██║ ██║ ██║██╔═██╗ ██╔══╝ ██║╚██╗██║ ██╔══██╗ ╚██╔╝ ██║██║██║╚██╗██║██║ ██╔══██║ +╚██████╗██║ ██║██║ ╚██████╔╝██║ ██║███████║ ██║ ╚██████╔╝██║ ██╗███████╗██║ ╚████║ ██████╔╝ ██║ ██║██║██║ ╚████║╚██████╗██║ ██║ + ╚═════╝╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝ ╚═════╝╚═╝ ╚═╝ + + Copyright by 1inch Corporation + https://1inch.exchange + +--- +Deployer wallet address: +0x7E1E3334130355799F833ffec2D731BCa3E68aF6 + +Signed raw transaction for chainId 1: +0xf90d7f808506fc23ac00830bd0fa8080b90d2c608060405234801561001057600080fd5b50610d0c806100206000396000f3fe608060405234801561001057600080fd5b506004361061010b5760003560e01c806370a08231116100a2578063a9059cbb11610071578063a9059cbb14610305578063b0ac19a014610331578063d89135cd1461036a578063d8ccd0f314610372578063dd62ed3e1461038f5761010b565b806370a08231146102b057806395d89b41146102d6578063a0712d68146102de578063a2309ff8146102fd5761010b565b806323b872dd116100de57806323b872dd14610213578063313ce567146102495780635f2e2b45146102675780636366b936146102935761010b565b806306fdde0314610110578063079d229f1461018d578063095ea7b3146101cb57806318160ddd1461020b575b600080fd5b6101186103bd565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561015257818101518382015260200161013a565b50505050905090810190601f16801561017f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101b9600480360360408110156101a357600080fd5b506001600160a01b0381351690602001356103ee565b60408051918252519081900360200190f35b6101f7600480360360408110156101e157600080fd5b506001600160a01b03813516906020013561041f565b604080519115158252519081900360200190f35b6101b9610435565b6101f76004803603606081101561022957600080fd5b506001600160a01b03813581169160208101359091169060400135610453565b6102516104c2565b6040805160ff9092168252519081900360200190f35b6101b96004803603604081101561027d57600080fd5b506001600160a01b0381351690602001356104c7565b6101b9600480360360208110156102a957600080fd5b50356104e2565b6101b9600480360360208110156102c657600080fd5b50356001600160a01b03166104ff565b61011861051a565b6102fb600480360360208110156102f457600080fd5b5035610539565b005b6101b961070d565b6101f76004803603604081101561031b57600080fd5b506001600160a01b038135169060200135610713565b61034e6004803603602081101561034757600080fd5b5035610720565b604080516001600160a01b039092168252519081900360200190f35b6101b961078b565b6101b96004803603602081101561038857600080fd5b5035610791565b6101b9600480360360408110156103a557600080fd5b506001600160a01b03813581169160200135166107aa565b60405180604001604052806015815260200174086d0d2408ec2e6e8ded6cadc40c4f24062d2dcc6d605b1b81525081565b60006104188361041361040985610404886104ff565b6107d5565b61040487336107aa565b6104c7565b9392505050565b600061042c3384846107eb565b50600192915050565b600061044e60035460025461084d90919063ffffffff16565b905090565b600061046084848461088f565b6104b884336104b385604051806060016040528060288152602001610c8b602891396001600160a01b038a166000908152600160209081526040808320338452909152902054919063ffffffff61096116565b6107eb565b5060019392505050565b600081565b60006104d383836109f8565b6104dc82610a59565b50919050565b60006104f96104f483610404336104ff565b610791565b92915050565b6001600160a01b031660009081526020819052604090205490565b6040518060400160405280600381526020016243484960e81b81525081565b6002547f746d4946c0e9f43f4dee607b0ef1fa1c3318585733ff6000526015600bf30000600052602082045b80156106d85781601e600080f55060018201601e600080f55060028201601e600080f55060038201601e600080f55060048201601e600080f55060058201601e600080f55060068201601e600080f55060078201601e600080f55060088201601e600080f55060098201601e600080f550600a8201601e600080f550600b8201601e600080f550600c8201601e600080f550600d8201601e600080f550600e8201601e600080f550600f8201601e600080f55060108201601e600080f55060118201601e600080f55060128201601e600080f55060138201601e600080f55060148201601e600080f55060158201601e600080f55060168201601e600080f55060178201601e600080f55060188201601e600080f55060198201601e600080f550601a8201601e600080f550601b8201601e600080f550601c8201601e600080f550601d8201601e600080f550601e8201601e600080f550601f8201601e600080f5506020919091019060001901610565565b50601f82165b80156106fc5781601e600080f55060019190910190600019016106de565b506107073383610ad1565b60025550565b60025481565b600061042c33848461088f565b604080516001600160f81b03196020808301919091523060601b602183015260358201939093527f3c1644c68e5d6cb380c36d1bf847fdbc0c7ac28030025a2fc5e63cce23c16348605580830191909152825180830390910181526075909101909152805191012090565b60035481565b600061079d3383610b50565b6107a682610a59565b5090565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60008183106107e45781610418565b5090919050565b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b600061041883836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610961565b6108d281604051806060016040528060268152602001610c65602691396001600160a01b038616600090815260208190526040902054919063ffffffff61096116565b6001600160a01b038085166000908152602081905260408082209390935590841681522054610907908263ffffffff610be816565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156109f05760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156109b557818101518382015260200161099d565b50505050905090810190601f1680156109e25780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b610a028282610b50565b610a5582336104b384604051806060016040528060248152602001610cb3602491396001600160a01b0388166000908152600160209081526040808320338452909152902054919063ffffffff61096116565b5050565b60035460005b82811015610aca57610a72818301610720565b6040516001600160a01b039190911690600081818181865af19150503d8060008114610aba576040519150601f19603f3d011682016040523d82523d6000602084013e610abf565b606091505b505050600101610a5f565b5001600355565b6001600160a01b038216600090815260208190526040902054610afa908263ffffffff610be816565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b610b9381604051806060016040528060228152602001610c43602291396001600160a01b038516600090815260208190526040902054919063ffffffff61096116565b6001600160a01b038316600081815260208181526040808320949094558351858152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35050565b600082820183811015610418576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fdfe45524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e20616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220687f814fb4c0b3c6abd66ebdb1f1eabcf69becf92a382c3af453e0b21c3d15b564736f6c6343000608003325a00ed87a047b4e415bd7f8cf7a7ce5a1c204125df1cedc35c7bdcb71bd2a29a35ea02db2490337fa6c425f1b3d74b7b217de8b394adb3f571827629c06dc16364b66 +--- +*/ +// File: @openzeppelin/contracts/math/Math.sol + +pragma solidity ^0.6.0; + +/** + * @dev Standard math utilities missing in the Solidity language. + */ +library Math { + /** + * @dev Returns the largest of two numbers. + */ + function max(uint256 a, uint256 b) internal pure returns (uint256) { + return a >= b ? a : b; + } + + /** + * @dev Returns the smallest of two numbers. + */ + function min(uint256 a, uint256 b) internal pure returns (uint256) { + return a < b ? a : b; + } + + /** + * @dev Returns the average of two numbers. The result is rounded towards + * zero. + */ + function average(uint256 a, uint256 b) internal pure returns (uint256) { + // (a + b) / 2 can overflow, so we distribute + return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); + } +} + +// File: @openzeppelin/contracts/math/SafeMath.sol + +pragma solidity ^0.6.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + // Solidity only automatically asserts when dividing by 0 + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +// File: @openzeppelin/contracts/token/ERC20/IERC20.sol + +pragma solidity ^0.6.0; + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20 { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +// File: contracts/ChiToken.sol + +pragma solidity ^0.6.0; + + + + + +abstract contract ERC20WithoutTotalSupply is IERC20 { + using SafeMath for uint256; + + mapping(address => uint256) private _balances; + mapping(address => mapping(address => uint256)) private _allowances; + + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(msg.sender, recipient, amount); + return true; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(msg.sender, spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function _transfer(address sender, address recipient, uint256 amount) internal { + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + function _approve(address owner, address spender, uint256 amount) internal { + _allowances[owner][spender] = amount; + emit Approval(owner, spender, amount); + } + + function _mint(address account, uint256 amount) internal { + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + function _burn(address account, uint256 amount) internal { + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + emit Transfer(account, address(0), amount); + } + + function _burnFrom(address account, uint256 amount) internal { + _burn(account, amount); + _approve(account, msg.sender, _allowances[account][msg.sender].sub(amount, "ERC20: burn amount exceeds allowance")); + } +} + + +contract ChiToken is IERC20, ERC20WithoutTotalSupply { + string constant public name = "Chi Gastoken by 1inch"; + string constant public symbol = "CHI"; + uint8 constant public decimals = 0; + + uint256 public totalMinted; + uint256 public totalBurned; + + function totalSupply() public view override returns(uint256) { + return totalMinted.sub(totalBurned); + } + + function mint(uint256 value) public { + uint256 offset = totalMinted; + assembly { + mstore(0, 0x746d4946c0e9F43F4Dee607b0eF1fA1c3318585733ff6000526015600bf30000) + + for {let i := div(value, 32)} i {i := sub(i, 1)} { + pop(create2(0, 0, 30, add(offset, 0))) pop(create2(0, 0, 30, add(offset, 1))) + pop(create2(0, 0, 30, add(offset, 2))) pop(create2(0, 0, 30, add(offset, 3))) + pop(create2(0, 0, 30, add(offset, 4))) pop(create2(0, 0, 30, add(offset, 5))) + pop(create2(0, 0, 30, add(offset, 6))) pop(create2(0, 0, 30, add(offset, 7))) + pop(create2(0, 0, 30, add(offset, 8))) pop(create2(0, 0, 30, add(offset, 9))) + pop(create2(0, 0, 30, add(offset, 10))) pop(create2(0, 0, 30, add(offset, 11))) + pop(create2(0, 0, 30, add(offset, 12))) pop(create2(0, 0, 30, add(offset, 13))) + pop(create2(0, 0, 30, add(offset, 14))) pop(create2(0, 0, 30, add(offset, 15))) + pop(create2(0, 0, 30, add(offset, 16))) pop(create2(0, 0, 30, add(offset, 17))) + pop(create2(0, 0, 30, add(offset, 18))) pop(create2(0, 0, 30, add(offset, 19))) + pop(create2(0, 0, 30, add(offset, 20))) pop(create2(0, 0, 30, add(offset, 21))) + pop(create2(0, 0, 30, add(offset, 22))) pop(create2(0, 0, 30, add(offset, 23))) + pop(create2(0, 0, 30, add(offset, 24))) pop(create2(0, 0, 30, add(offset, 25))) + pop(create2(0, 0, 30, add(offset, 26))) pop(create2(0, 0, 30, add(offset, 27))) + pop(create2(0, 0, 30, add(offset, 28))) pop(create2(0, 0, 30, add(offset, 29))) + pop(create2(0, 0, 30, add(offset, 30))) pop(create2(0, 0, 30, add(offset, 31))) + offset := add(offset, 32) + } + + for {let i := and(value, 0x1F)} i {i := sub(i, 1)} { + pop(create2(0, 0, 30, offset)) + offset := add(offset, 1) + } + } + + _mint(msg.sender, value); + totalMinted = offset; + } + + function computeAddress2(uint256 salt) public view returns (address) { + bytes32 _data = keccak256( + abi.encodePacked(bytes1(0xff), address(this), salt, bytes32(0x3c1644c68e5d6cb380c36d1bf847fdbc0c7ac28030025a2fc5e63cce23c16348)) + ); + return address(uint256(_data)); + } + + function _destroyChildren(uint256 value) internal { + uint256 _totalBurned = totalBurned; + for (uint256 i = 0; i < value; i++) { + computeAddress2(_totalBurned + i).call(""); + } + totalBurned = _totalBurned + value; + } + + function free(uint256 value) public returns (uint256) { + _burn(msg.sender, value); + _destroyChildren(value); + return value; + } + + function freeUpTo(uint256 value) public returns (uint256) { + return free(Math.min(value, balanceOf(msg.sender))); + } + + function freeFrom(address from, uint256 value) public returns (uint256) { + _burnFrom(from, value); + _destroyChildren(value); + return value; + } + + function freeFromUpTo(address from, uint256 value) public returns (uint256) { + return freeFrom(from, Math.min(Math.min(value, balanceOf(from)), allowance(from, msg.sender))); + } +} \ No newline at end of file diff --git a/deploy-detail-v1.5.txt b/deploy-detail-v1.5.txt new file mode 100644 index 0000000..12f781a --- /dev/null +++ b/deploy-detail-v1.5.txt @@ -0,0 +1,3 @@ +==================================================== +network type: kovan +Deploy time: 2020/12/7 下午3:15:48 diff --git a/deploy-detail-v2.0.txt b/deploy-detail-v2.0.txt new file mode 100644 index 0000000..6c6cd8a --- /dev/null +++ b/deploy-detail-v2.0.txt @@ -0,0 +1,18 @@ +==================================================== +network type: kovan +Deploy time: 2020/12/7 下午3:15:53 +Deploy type: V2 +CloneFactoryAddress: 0xf7959fe661124C49F96CF30Da33729201aEE1b27 +FeeRateModelTemplateAddress: 0xEF3137780B387313c5889B999D03BdCf9aeEa892 +PermissionManagerTemplateAddress: 0x5D2Da09501d97a7bf0A8F192D2eb2F9Aa80d3241 +ExternalValueTemplateAddress: 0xe0f813951dE2BB012f7Feb981669F9a7b5250A57 +DefaultGasSourceAddress: 0xE0c0df0e0be7ec4f579503304a6C186cA4365407 +DvmTemplateAddress: 0x460Ada67279Ff2ce8c87cb88F99070c6520Aa624 +DvmAdminTemplateAddress: 0xbB9F79f6ac9e577B658E3B2E1340838d8965986B +DppTemplateAddress: 0x577c2cE26B8b5C8b3f7c57826Bf351ac7c21a441 +DppAdminTemplateAddress: 0x402ace5a3e6Aa71FB942d309341F8867afcde302 +DODOCalleeHelperAddress: 0x507EBbb195CF54E0aF147A2b269C08a38EA36989 +DvmFactoryAddress: 0xaeF2cce5678e6e29f7a7C2A6f5d2Ce26df600dc1 +DppFactoryAddress: 0x5935a606383Ba43C61FcE5E632357744a95e9dC3 +DODOProxyV2 Address: 0xD4b15Ab0e1F06373dA7ccd9f01D5e9776674DB9e +DODOApprovce setProxy tx: 0x67c5c5b1883950baec753a99bff5e1c20bfb92f876cdcd03c90ae2aa0053d891 diff --git a/deploy-detail.txt b/deploy-detail.txt deleted file mode 100644 index e69de29..0000000 diff --git a/migrations/2_deploy.js b/migrations/2_deploy.js deleted file mode 100644 index c55dbb9..0000000 --- a/migrations/2_deploy.js +++ /dev/null @@ -1,156 +0,0 @@ -const fs = require("fs"); -const file = fs.createWriteStream("../deploy-detail.txt"); -let logger = new console.Console(file, file); - -// const SmartApprove = artifacts.require("DODOApprove"); -// const SmartSwap = artifacts.require("SmartSwap"); -// const DODOSellHelper = artifacts.require("DODOSellHelper"); -// const TestERC20 = artifacts.require("TestERC20"); -// const NaiveOracle = artifacts.require("NaiveOracle"); -// const DODOZoo = artifacts.require("DODOZoo"); - -const DEPLOY_ROUTE = false; -const DEPLOY_KOVAN_TOKEN = false; - -module.exports = async (deployer, network, accounts) => { - // let DODOSellHelperAddress = ""; - // let DODOZooAddress = ""; - // let WETHAddress = ""; - // let SmartApproveAddress = ""; - // if (network == "kovan") { - // DODOSellHelperAddress = "0xbdEae617F2616b45DCB69B287D52940a76035Fe3"; - // DODOZooAddress = "0x92230e929a2226b29ed3441ae5524886347c60c8"; - // WETHAddress = "0x5eca15b12d959dfcf9c71c59f8b467eb8c6efd0b"; - // SmartApproveAddress = "0x5627b7DEb3055e1e899003FDca0716b32C382084"; - // } else if (network == "live") { - // DODOSellHelperAddress = "0x533da777aedce766ceae696bf90f8541a4ba80eb"; - // DODOZooAddress = "0x3a97247df274a17c59a3bd12735ea3fcdfb49950"; - // WETHAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; - // SmartApproveAddress = "0xe380Ad3181A69BF92133D2feb609867c4adC61eA"; - // } else return; - - // logger.log("===================================================="); - // logger.log("network type: " + network); - // logger.log("Deploy time: " + new Date().toLocaleString()); - - // if (DEPLOY_ROUTE) { - // logger.log("Deploy type: Smart Route"); - // if (SmartApproveAddress == "") { - // await deployer.deploy(SmartApprove); - // SmartApproveAddress = SmartApprove.address; - // } - // if (DODOSellHelperAddress == "") { - // await deployer.deploy(DODOSellHelper); - // DODOSellHelperAddress = DODOSellHelper.address; - // } - // logger.log("SmartApprove Address: ", SmartApproveAddress); - // logger.log("DODOSellHelper Address: ", DODOSellHelperAddress); - // await deployer.deploy( - // SmartSwap, - // SmartApproveAddress, - // DODOSellHelperAddress, - // WETHAddress - // ); - // logger.log("SmartSwap Address: ", SmartSwap.address); - - // // const SmartApproveInstance = await SmartApprove.at(SmartApproveAddress); - // // var tx = await SmartApproveInstance.setSmartSwap(SmartSwap.address); - // // logger.log("SmartApprovce setSmartSwap tx: ", tx.tx); - // } - - // if (DEPLOY_KOVAN_TOKEN) { - // logger.log("Deploy type: Create Tokens and Trading Pairs"); - // await deployer.deploy(TestERC20, "USDC", 6, "USDC"); - // const USDCAddr = TestERC20.address; - // logger.log("USDC Addr: ", USDCAddr); - // await deployer.deploy(TestERC20, "USDT", 6, "USDT"); - // const USDTAddr = TestERC20.address; - // logger.log("USDT Addr: ", USDTAddr); - // await deployer.deploy(TestERC20, "DODO", 18, "DODO"); - // const DODOAddr = TestERC20.address; - // logger.log("DODO Addr: ", DODOAddr); - // await deployer.deploy(TestERC20, "WOO", 18, "WOO"); - // const WooAddr = TestERC20.address; - // logger.log("WOO Addr: ", WooAddr); - // const WETHAddr = WETHAddress; - // logger.log("WETH Addr: ", WETHAddr); - - // let config = { - // lpFeeRate: "2000000000000000", - // mtFeeRate: "1000000000000000", - // k: "100000000000000000", - // gasPriceLimit: "100000000000", - // }; - - // const DODOZooInstance = await DODOZoo.at(DODOZooAddress); - - // //USDT-USDC - // await deployer.deploy(NaiveOracle); - // var USDT_USDC_Oracle = NaiveOracle.address; - // await DODOZooInstance.breedDODO( - // accounts[0], - // USDTAddr, - // USDCAddr, - // USDT_USDC_Oracle, - // config.lpFeeRate, - // config.mtFeeRate, - // config.k, - // config.gasPriceLimit - // ); - // const USDT_USDC_Addr = await DODOZooInstance.getDODO(USDTAddr, USDCAddr); - // logger.log("USDT_USDC_Addr:", USDT_USDC_Addr); - - // // DODO-USDT - // await deployer.deploy(NaiveOracle); - // var DODO_USDT_Oracle = NaiveOracle.address; - // await DODOZooInstance.breedDODO( - // accounts[0], - // DODOAddr, - // USDTAddr, - // DODO_USDT_Oracle, - // config.lpFeeRate, - // config.mtFeeRate, - // config.k, - // config.gasPriceLimit - // ); - // const DODO_USDT_Addr = await DODOZooInstance.getDODO(DODOAddr, USDTAddr); - // logger.log("DODO_USDT_Addr:", DODO_USDT_Addr); - - // // //WETH-USDC - // await deployer.deploy(NaiveOracle); - // var WETH_USDC_Oracle = NaiveOracle.address; - // await DODOZooInstance.breedDODO( - // accounts[0], - // WETHAddr, - // USDCAddr, - // WETH_USDC_Oracle, - // config.lpFeeRate, - // config.mtFeeRate, - // config.k, - // config.gasPriceLimit - // ); - // const WETH_USDC_Addr = await DODOZooInstance.getDODO(WETHAddr, USDCAddr); - // logger.log("WETH_USDC_Addr:", WETH_USDC_Addr); - - // //WOO-USDT - // await deployer.deploy(NaiveOracle); - // var WOO_USDT_Oracle = NaiveOracle.address; - // await DODOZooInstance.breedDODO( - // accounts[0], - // WooAddr, - // USDTAddr, - // WOO_USDT_Oracle, - // config.lpFeeRate, - // config.mtFeeRate, - // config.k, - // config.gasPriceLimit - // ); - // const WOO_USDT_Addr = await DODOZooInstance.getDODO(WooAddr, USDTAddr); - // logger.log("WOO_USDT_Addr:", WOO_USDT_Addr); - - // //TODO:ing enableBaseDeposit enableQuoteDeposit enableTrading - // //TODO:ing apporve pair to token - // //TODO:ing mint to lp - // //TODO:ing deposit to Base && quote pool - // } -}; diff --git a/migrations/2_deploy_v1.5.js b/migrations/2_deploy_v1.5.js new file mode 100644 index 0000000..92c542e --- /dev/null +++ b/migrations/2_deploy_v1.5.js @@ -0,0 +1,63 @@ +const fs = require("fs"); +const file = fs.createWriteStream("../deploy-detail-v1.5.txt", { 'flags': 'a' }); +let logger = new console.Console(file, file); + +const DODOApprove = artifacts.require("DODOApprove"); +const DODOProxyV1 = artifacts.require("DODOV1Proxy01"); +const DODOSellHelper = artifacts.require("DODOSellHelper"); + +const DEPLOY_ROUTE = false; + +module.exports = async (deployer, network, accounts) => { + let DODOSellHelperAddress = ""; + let WETHAddress = ""; + let DODOApproveAddress = ""; + let chiAddress = ""; + if (network == "kovan") { + DODOSellHelperAddress = "0xbdEae617F2616b45DCB69B287D52940a76035Fe3"; + WETHAddress = "0x5eca15b12d959dfcf9c71c59f8b467eb8c6efd0b"; + // DODOApproveAddress = "0xbcf0fC05860b14cB3D62D1d4C7f531Ad2F28E0fE"; + DODOApproveAddress = "0x0C4a80B2e234448E5f6fD86e7eFA733d985004c8"; + chiAddress = "0x0000000000004946c0e9f43f4dee607b0ef1fa1c"; + } else if (network == "live") { + DODOSellHelperAddress = "0x533da777aedce766ceae696bf90f8541a4ba80eb"; + WETHAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; + DODOApproveAddress = "0x4eC851895d85bfa6835241b3157ae10FfFD3BebC"; + chiAddress = "0x0000000000004946c0e9F43F4Dee607b0eF1fA1c"; + } else if (network == "bsclive") { + DODOSellHelperAddress = "0x0F859706AeE7FcF61D5A8939E8CB9dBB6c1EDA33"; + WETHAddress = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; + DODOApproveAddress = "0x19DA73be23Cea6bFA804Ec020041b8F3971BC522"; + chiAddress = "0x0000000000000000000000000000000000000000"; + } else return; + + logger.log("===================================================="); + logger.log("network type: " + network); + logger.log("Deploy time: " + new Date().toLocaleString()); + + if (DEPLOY_ROUTE) { + logger.log("Deploy type: Proxy"); + if (DODOApproveAddress == "") { + await deployer.deploy(DODOApprove); + DODOApproveAddress = DODOApprove.address; + } + if (DODOSellHelperAddress == "") { + 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); + + const DODOApproveInstance = await DODOApprove.at(DODOApproveAddress); + var tx = await DODOApproveInstance.setDODOProxy(DODOProxyV1.address); + logger.log("DODOApprovce setProxy tx: ", tx.tx); + } +}; diff --git a/migrations/3_deploy_v2.js b/migrations/3_deploy_v2.js new file mode 100644 index 0000000..91020c7 --- /dev/null +++ b/migrations/3_deploy_v2.js @@ -0,0 +1,189 @@ +const fs = require("fs"); +const file = fs.createWriteStream("../deploy-detail-v2.0.txt", { 'flags': 'a' }); +let logger = new console.Console(file, file); + +const CloneFactory = artifacts.require("CloneFactory"); +const DvmTemplate = artifacts.require("DVM"); +const DvmAdminTemplate = artifacts.require("DVMAdmin"); +const DppTemplate = artifacts.require("DPP"); +const DppAdminTemplate = artifacts.require("DPPAdmin"); +const FeeRateModelTemplate = artifacts.require("FeeRateModel"); +const PermissionManagerTemplate = artifacts.require("PermissionManager"); +const ExternalValueTemplate = artifacts.require("ExternalValue"); + +const DvmFactory = artifacts.require("DVMFactory"); +const DppFactory = artifacts.require("DPPFactory"); + +const DODOApprove = artifacts.require("DODOApprove"); +const DODOProxyV2 = artifacts.require("DODOV2Proxy01"); +const DODOSellHelper = artifacts.require("DODOSellHelper"); +const DODOCalleeHelper = artifacts.require("DODOCalleeHelper"); + +const DEPLOY_V2 = true; + +module.exports = async (deployer, network, accounts) => { + let DODOSellHelperAddress = ""; + let DODOCalleeHelperAddress = ""; + let WETHAddress = ""; + let DODOApproveAddress = ""; + let chiAddress = ""; + let CloneFactoryAddress = ""; + let FeeRateModelTemplateAddress = ""; + let PermissionManagerTemplateAddress = ""; + let ExternalValueTemplateAddress = ""; + let DefaultGasSourceAddress = ""; + let DvmTemplateAddress = ""; + let DvmAdminTemplateAddress = ""; + let DppTemplateAddress = ""; + let DppAdminTemplateAddress = ""; + let DvmFactoryAddress = ""; + let DppFactoryAddress = ""; + + if (network == "kovan") { + DODOSellHelperAddress = "0xbdEae617F2616b45DCB69B287D52940a76035Fe3"; + WETHAddress = "0x5eca15b12d959dfcf9c71c59f8b467eb8c6efd0b"; + chiAddress = "0x0000000000004946c0e9f43f4dee607b0ef1fa1c"; + DODOApproveAddress = "0x0C4a80B2e234448E5f6fD86e7eFA733d985004c8"; + DODOCalleeHelperAddress = "0x507EBbb195CF54E0aF147A2b269C08a38EA36989"; + //Template + CloneFactoryAddress = "0xf7959fe661124C49F96CF30Da33729201aEE1b27"; + FeeRateModelTemplateAddress = "0xEF3137780B387313c5889B999D03BdCf9aeEa892"; + PermissionManagerTemplateAddress = "0x5D2Da09501d97a7bf0A8F192D2eb2F9Aa80d3241"; + ExternalValueTemplateAddress = "0xe0f813951dE2BB012f7Feb981669F9a7b5250A57"; + DefaultGasSourceAddress = "0xE0c0df0e0be7ec4f579503304a6C186cA4365407"; + DvmTemplateAddress = "0x460Ada67279Ff2ce8c87cb88F99070c6520Aa624"; + DvmAdminTemplateAddress = "0xbB9F79f6ac9e577B658E3B2E1340838d8965986B"; + DppTemplateAddress = "0x577c2cE26B8b5C8b3f7c57826Bf351ac7c21a441"; + DppAdminTemplateAddress = "0x402ace5a3e6Aa71FB942d309341F8867afcde302"; + //Factory + DvmFactoryAddress = "0xaeF2cce5678e6e29f7a7C2A6f5d2Ce26df600dc1"; + DppFactoryAddress = "0x5935a606383Ba43C61FcE5E632357744a95e9dC3"; + } else if (network == "live") { + DODOSellHelperAddress = "0x533da777aedce766ceae696bf90f8541a4ba80eb"; + WETHAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; + chiAddress = "0x0000000000004946c0e9F43F4Dee607b0eF1fA1c"; + DODOApproveAddress = "0x4eC851895d85bfa6835241b3157ae10FfFD3BebC"; + //Tempalte + } else if (network == "bsclive") { + DODOSellHelperAddress = "0x0F859706AeE7FcF61D5A8939E8CB9dBB6c1EDA33"; + WETHAddress = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; + chiAddress = "0x0000000000000000000000000000000000000000"; + DODOApproveAddress = "0x19DA73be23Cea6bFA804Ec020041b8F3971BC522"; + //Template + } else return; + + logger.log("===================================================="); + logger.log("network type: " + network); + logger.log("Deploy time: " + new Date().toLocaleString()); + + if (DEPLOY_V2) { + logger.log("Deploy type: V2"); + if (CloneFactoryAddress == "") { + await deployer.deploy(CloneFactory); + CloneFactoryAddress = CloneFactory.address; + logger.log("CloneFactoryAddress: ", CloneFactoryAddress); + } + if (FeeRateModelTemplateAddress == "") { + await deployer.deploy(FeeRateModelTemplate); + FeeRateModelTemplateAddress = FeeRateModelTemplate.address; + logger.log("FeeRateModelTemplateAddress: ", FeeRateModelTemplateAddress); + } + if (PermissionManagerTemplateAddress == "") { + await deployer.deploy(PermissionManagerTemplate); + PermissionManagerTemplateAddress = PermissionManagerTemplate.address; + logger.log("PermissionManagerTemplateAddress: ", PermissionManagerTemplateAddress); + } + if (ExternalValueTemplateAddress == "") { + await deployer.deploy(ExternalValueTemplate); + ExternalValueTemplateAddress = ExternalValueTemplate.address; + logger.log("ExternalValueTemplateAddress: ", ExternalValueTemplateAddress); + } + if (DefaultGasSourceAddress == "") { + await deployer.deploy(ExternalValueTemplate); + DefaultGasSourceAddress = ExternalValueTemplate.address; + logger.log("DefaultGasSourceAddress: ", DefaultGasSourceAddress); + const defaultGasSourceInstance = await ExternalValueTemplate.at(DefaultGasSourceAddress); + var tx = await defaultGasSourceInstance.init(accounts[0], "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + logger.log("Set default Gas Tx:", tx.tx); + } + if (DvmTemplateAddress == "") { + await deployer.deploy(DvmTemplate); + DvmTemplateAddress = DvmTemplate.address; + logger.log("DvmTemplateAddress: ", DvmTemplateAddress); + } + if (DvmAdminTemplateAddress == "") { + await deployer.deploy(DvmAdminTemplate); + DvmAdminTemplateAddress = DvmAdminTemplate.address; + logger.log("DvmAdminTemplateAddress: ", DvmAdminTemplateAddress); + } + if (DppTemplateAddress == "") { + await deployer.deploy(DppTemplate); + DppTemplateAddress = DppTemplate.address; + logger.log("DppTemplateAddress: ", DppTemplateAddress); + } + if (DppAdminTemplateAddress == "") { + await deployer.deploy(DppAdminTemplate); + DppAdminTemplateAddress = DppAdminTemplate.address; + logger.log("DppAdminTemplateAddress: ", DppAdminTemplateAddress); + } + if (DODOApproveAddress == "") { + await deployer.deploy(DODOApprove); + DODOApproveAddress = DODOApprove.address; + logger.log("DODOApprove Address: ", DODOApproveAddress); + } + if (DODOSellHelperAddress == "") { + await deployer.deploy(DODOSellHelper); + DODOSellHelperAddress = DODOSellHelper.address; + logger.log("DODOSellHelper Address: ", DODOSellHelperAddress); + } + if (DODOCalleeHelperAddress == "") { + await deployer.deploy(DODOCalleeHelper,WETHAddress); + DODOCalleeHelperAddress = DODOCalleeHelper.address; + logger.log("DODOCalleeHelperAddress: ", DODOCalleeHelperAddress); + } + //Factory + if (DvmFactoryAddress == "") { + await deployer.deploy( + DvmFactory, + CloneFactoryAddress, + DvmTemplateAddress, + DvmAdminTemplateAddress, + FeeRateModelTemplateAddress, + PermissionManagerTemplateAddress, + DefaultGasSourceAddress + ); + DvmFactoryAddress = DvmFactory.address; + logger.log("DvmFactoryAddress: ", DvmFactoryAddress); + } + if (DppFactoryAddress == "") { + await deployer.deploy( + DppFactory, + CloneFactoryAddress, + DppTemplateAddress, + DppAdminTemplateAddress, + FeeRateModelTemplateAddress, + PermissionManagerTemplateAddress, + ExternalValueTemplateAddress, + DefaultGasSourceAddress, + DODOApproveAddress + ); + DppFactoryAddress = DppFactory.address; + logger.log("DppFactoryAddress: ", DppFactoryAddress); + } + + //Proxy + await deployer.deploy( + DODOProxyV2, + DvmFactoryAddress, + DppFactoryAddress, + WETHAddress, + DODOApproveAddress, + DODOSellHelperAddress + ); + logger.log("DODOProxyV2 Address: ", DODOProxyV2.address); + + const DODOApproveInstance = await DODOApprove.at(DODOApproveAddress); + var tx = await DODOApproveInstance.setDODOProxy(DODOProxyV2.address); + logger.log("DODOApprovce setProxy tx: ", tx.tx); + } +}; diff --git a/test/Route/Route.test.ts b/test/Route/Route.test.ts index f2e6239..da051f1 100644 --- a/test/Route/Route.test.ts +++ b/test/Route/Route.test.ts @@ -140,13 +140,14 @@ describe("Trader", () => { }); afterEach(async () => { - await ctx.EVM.reset(snapshotId); + // await ctx.EVM.reset(snapshotId); }); describe("route calc test", () => { - it("DODO to USDT directly swap", async () => { + it.only("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() console.log("Before DODO:" + fromWei(b_DODO, 'ether') + "; USDT:" + fromWei(b_USDT, 'mwei')); //approve DODO entry await ctx.DODO.methods.approve(ctx.DODOApprove.options.address, MAX_UINT256).send(ctx.sendParam(trader)) @@ -167,15 +168,17 @@ describe("Trader", () => { }]; await logGas(await calcRoute(ctx, decimalStr('10'), 0.1, routes, pairs), ctx.sendParam(trader), "directly swap") - await logGas(await calcRoute(ctx, decimalStr('10'), 0.1, routes, pairs), ctx.sendParam(trader), "directly swap") - // console.log(tx.events['OrderHistory']); + var tx = await logGas(await calcRoute(ctx, decimalStr('10'), 0.1, routes, pairs), ctx.sendParam(trader), "directly swap") + console.log(tx.transactionHash); var a_DODO = await ctx.DODO.methods.balanceOf(trader).call() var a_USDT = await ctx.USDT.methods.balanceOf(trader).call() console.log("After DODO:" + fromWei(a_DODO, 'ether') + "; USDT:" + fromWei(a_USDT, 'mwei')); console.log("===============================================") var c_DODO = await ctx.DODO.methods.balanceOf(ctx.DODOProxyV1.options.address).call() var c_USDT = await ctx.USDT.methods.balanceOf(ctx.DODOProxyV1.options.address).call() + var c_a_CHI = await ctx.CHI.methods.balanceOf(ctx.DODOProxyV1.options.address).call() console.log("Contract DODO:" + fromWei(c_DODO, 'ether') + "; USDT:" + fromWei(c_USDT, 'mwei')); + console.log("Contract gas Token Before:" + c_b_CHI + " ;After:" + c_a_CHI); // console.log("USDT:" + a_USDT); assert(a_USDT, "1994000"); }); diff --git a/test/utils-v1/Contracts.ts b/test/utils-v1/Contracts.ts index fefa093..48138b6 100644 --- a/test/utils-v1/Contracts.ts +++ b/test/utils-v1/Contracts.ts @@ -31,6 +31,7 @@ const SmartSwap = require(`${jsonPath2}DODOV1Proxy01.json`) const SmartApprove = require(`${jsonPath2}DODOApprove.json`) const DODOSellHelper = require(`${jsonPath2}DODOSellHelper.json`) const WETH = require(`${jsonPath2}WETH9.json`) +const CHI = require(`${jsonPath2}ChiToken.json`) /******/ import { getDefaultWeb3 } from './EVM'; @@ -55,6 +56,7 @@ export const DODO_MINE_READER_NAME = "DODOMineReader" export const SMART_SWAP = "DODOV1Proxy01" export const SMART_APPROVE = "DODOApprove" export const DODO_SELL_HELPER = "DODOSellHelper" +export const CHI_TOKEN = "ChiToken" /******/ var contractMap: { [name: string]: any } = {} @@ -76,6 +78,7 @@ contractMap[DODO_MINE_READER_NAME] = DODOMineReader contractMap[SMART_SWAP] = SmartSwap contractMap[SMART_APPROVE] = SmartApprove contractMap[DODO_SELL_HELPER] = DODOSellHelper +contractMap[CHI_TOKEN] = CHI /******/ interface ContractJson { diff --git a/test/utils-v1/ProxyContextV1.ts b/test/utils-v1/ProxyContextV1.ts index 48ae416..57c9688 100644 --- a/test/utils-v1/ProxyContextV1.ts +++ b/test/utils-v1/ProxyContextV1.ts @@ -62,6 +62,8 @@ export class DODOContext { USDT: Contract; USDC: Contract; WETH: Contract; + CHI: Contract; + GST2: Contract; //pair DODO_USDT: Contract; USDT_USDC: Contract; @@ -220,13 +222,23 @@ export class DODOContext { contracts.SMART_APPROVE ); + //Gas Token + this.CHI = await contracts.newContract( + contracts.CHI_TOKEN + ); + + // await this.CHI.methods.mint(140).send(this.sendParam(this.Deployer)); + this.DODOProxyV1 = await contracts.newContract( contracts.SMART_SWAP, - [this.DODOApprove.options.address, this.DODOSellHelper.options.address, this.WETH.options.address] + [this.DODOApprove.options.address, this.DODOSellHelper.options.address, this.WETH.options.address, this.CHI.options.address] + // [this.DODOApprove.options.address, this.DODOSellHelper.options.address, this.WETH.options.address, "0x0000000000000000000000000000000000000000"] ); 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)); + console.log(log.blueText("[Init dodo context]")); } diff --git a/truffle-config.js b/truffle-config.js index 4108552..582f062 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -68,10 +68,19 @@ module.exports = { return new HDWalletProvider(privKey, "https://mainnet.infura.io/v3/" + infuraId); }, gas: 3000000, - gasPrice: 120000000000, + gasPrice: 45000000000, network_id: 1, skipDryRun: true }, + bsclive: { + provider: function() { + return new HDWalletProvider(privKey, "https://bsc-dataseed1.binance.org"); + }, + network_id: 56, + confirmations: 10, + timeoutBlocks: 200, + skipDryRun: true + }, coverage: { host: "127.0.0.1", port: 6545,