Merge branch 'feature/V2' of github.com:DODOEX/contractV2 into feature/V2
This commit is contained in:
BIN
audit/PeckShield-Audit-DODOV2-v1.0.pdf
Executable file
BIN
audit/PeckShield-Audit-DODOV2-v1.0.pdf
Executable file
Binary file not shown.
@@ -70,61 +70,32 @@ contract CPFunding is CPStorage {
|
||||
function settle() external phaseSettlement preventReentrant {
|
||||
_settle();
|
||||
|
||||
(uint256 poolBase, uint256 poolQuote) = getSettleResult();
|
||||
_UNUSED_QUOTE_ = _QUOTE_TOKEN_.balanceOf(address(this)).sub(poolQuote);
|
||||
_UNUSED_BASE_ = _BASE_TOKEN_.balanceOf(address(this)).sub(poolBase);
|
||||
(uint256 poolBase, uint256 poolQuote, uint256 poolI, uint256 unUsedBase, uint256 unUsedQuote) = getSettleResult();
|
||||
_UNUSED_BASE_ = unUsedBase;
|
||||
_UNUSED_QUOTE_ = unUsedQuote;
|
||||
|
||||
// Try to make midPrice equal to avgPrice
|
||||
// k=1, If quote and base are not balanced, one side must be cut off
|
||||
// DVM truncated quote, but if more quote than base entering the pool, we need set the quote to the base
|
||||
address _poolBaseToken;
|
||||
address _poolQuoteToken;
|
||||
|
||||
// m = avgPrice
|
||||
// i = m (1-quote/(m*base))
|
||||
// if quote = m*base i = 1
|
||||
// if quote > m*base reverse
|
||||
{
|
||||
address _poolBaseToken;
|
||||
address _poolQuoteToken;
|
||||
uint256 _poolI;
|
||||
|
||||
uint256 avgPrice = _UNUSED_BASE_ == 0
|
||||
? _I_
|
||||
: DecimalMath.divCeil(poolQuote, _UNUSED_BASE_);
|
||||
uint256 baseDepth = DecimalMath.mulFloor(avgPrice, poolBase);
|
||||
|
||||
if (poolQuote == 0) {
|
||||
// ask side only DVM
|
||||
_poolBaseToken = address(_BASE_TOKEN_);
|
||||
_poolQuoteToken = address(_QUOTE_TOKEN_);
|
||||
_poolI = _I_;
|
||||
} else if (_UNUSED_BASE_== poolBase) {
|
||||
// standard bonding curve
|
||||
_poolBaseToken = address(_BASE_TOKEN_);
|
||||
_poolQuoteToken = address(_QUOTE_TOKEN_);
|
||||
_poolI = 1;
|
||||
} else if (_UNUSED_BASE_ < poolBase) {
|
||||
// poolI up round
|
||||
_poolBaseToken = address(_BASE_TOKEN_);
|
||||
_poolQuoteToken = address(_QUOTE_TOKEN_);
|
||||
uint256 ratio = DecimalMath.ONE.sub(DecimalMath.divFloor(poolQuote, baseDepth));
|
||||
_poolI = avgPrice.mul(ratio).mul(ratio).divCeil(DecimalMath.ONE2);
|
||||
} else if (_UNUSED_BASE_ > poolBase) {
|
||||
// poolI down round
|
||||
_poolBaseToken = address(_QUOTE_TOKEN_);
|
||||
_poolQuoteToken = address(_BASE_TOKEN_);
|
||||
uint256 ratio = DecimalMath.ONE.sub(DecimalMath.divCeil(baseDepth, poolQuote));
|
||||
_poolI = ratio.mul(ratio).div(avgPrice);
|
||||
}
|
||||
_POOL_ = IDVMFactory(_POOL_FACTORY_).createDODOVendingMachine(
|
||||
_poolBaseToken,
|
||||
_poolQuoteToken,
|
||||
3e15, // 0.3% lp feeRate
|
||||
_poolI,
|
||||
DecimalMath.ONE
|
||||
);
|
||||
_AVG_SETTLED_PRICE_ = avgPrice;
|
||||
if (_UNUSED_BASE_ > poolBase) {
|
||||
_poolBaseToken = address(_QUOTE_TOKEN_);
|
||||
_poolQuoteToken = address(_BASE_TOKEN_);
|
||||
} else {
|
||||
_poolBaseToken = address(_BASE_TOKEN_);
|
||||
_poolQuoteToken = address(_QUOTE_TOKEN_);
|
||||
}
|
||||
|
||||
_POOL_ = IDVMFactory(_POOL_FACTORY_).createDODOVendingMachine(
|
||||
_poolBaseToken,
|
||||
_poolQuoteToken,
|
||||
3e15, // 0.3% lp feeRate
|
||||
poolI,
|
||||
DecimalMath.ONE
|
||||
);
|
||||
|
||||
uint256 avgPrice = unUsedBase == 0 ? _I_ : DecimalMath.divCeil(poolQuote, unUsedBase);
|
||||
_AVG_SETTLED_PRICE_ = avgPrice;
|
||||
|
||||
_transferBaseOut(_POOL_, poolBase);
|
||||
_transferQuoteOut(_POOL_, poolQuote);
|
||||
|
||||
@@ -148,13 +119,43 @@ contract CPFunding is CPStorage {
|
||||
|
||||
// ============ Pricing ============
|
||||
|
||||
function getSettleResult() public view returns (uint256 poolBase, uint256 poolQuote) {
|
||||
function getSettleResult() public view returns (uint256 poolBase, uint256 poolQuote, uint256 poolI, uint256 unUsedBase, uint256 unUsedQuote) {
|
||||
poolQuote = _QUOTE_TOKEN_.balanceOf(address(this));
|
||||
if (poolQuote > _POOL_QUOTE_CAP_) {
|
||||
poolQuote = _POOL_QUOTE_CAP_;
|
||||
}
|
||||
(uint256 soldBase,) = PMMPricing.sellQuoteToken(_getPMMState(), poolQuote);
|
||||
poolBase = _TOTAL_BASE_.sub(soldBase);
|
||||
|
||||
unUsedQuote = _QUOTE_TOKEN_.balanceOf(address(this)).sub(poolQuote);
|
||||
unUsedBase = _BASE_TOKEN_.balanceOf(address(this)).sub(poolBase);
|
||||
|
||||
// Try to make midPrice equal to avgPrice
|
||||
// k=1, If quote and base are not balanced, one side must be cut off
|
||||
// DVM truncated quote, but if more quote than base entering the pool, we need set the quote to the base
|
||||
|
||||
// m = avgPrice
|
||||
// i = m (1-quote/(m*base))
|
||||
// if quote = m*base i = 1
|
||||
// if quote > m*base reverse
|
||||
uint256 avgPrice = unUsedBase == 0 ? _I_ : DecimalMath.divCeil(poolQuote, unUsedBase);
|
||||
uint256 baseDepth = DecimalMath.mulFloor(avgPrice, poolBase);
|
||||
|
||||
if (poolQuote == 0) {
|
||||
// ask side only DVM
|
||||
poolI = _I_;
|
||||
} else if (unUsedBase== poolBase) {
|
||||
// standard bonding curve
|
||||
poolI = 1;
|
||||
} else if (unUsedBase < poolBase) {
|
||||
// poolI up round
|
||||
uint256 ratio = DecimalMath.ONE.sub(DecimalMath.divFloor(poolQuote, baseDepth));
|
||||
poolI = avgPrice.mul(ratio).mul(ratio).divCeil(DecimalMath.ONE2);
|
||||
} else if (unUsedBase > poolBase) {
|
||||
// poolI down round
|
||||
uint256 ratio = DecimalMath.ONE.sub(DecimalMath.divCeil(baseDepth, poolQuote));
|
||||
poolI = ratio.mul(ratio).div(avgPrice);
|
||||
}
|
||||
}
|
||||
|
||||
function _getPMMState() internal view returns (PMMPricing.PMMState memory state) {
|
||||
@@ -169,7 +170,7 @@ contract CPFunding is CPStorage {
|
||||
|
||||
function getExpectedAvgPrice() external view returns (uint256) {
|
||||
require(!_SETTLED_, "ALREADY_SETTLED");
|
||||
(uint256 poolBase, uint256 poolQuote) = getSettleResult();
|
||||
(uint256 poolBase, uint256 poolQuote, , , ) = getSettleResult();
|
||||
return DecimalMath.divCeil(poolQuote, _BASE_TOKEN_.balanceOf(address(this)).sub(poolBase));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ contract DPPTrader is DPPVault {
|
||||
address toToken,
|
||||
uint256 fromAmount,
|
||||
uint256 toAmount,
|
||||
address trader
|
||||
address trader,
|
||||
address receiver
|
||||
);
|
||||
|
||||
event DODOFlashLoan(
|
||||
@@ -67,7 +68,8 @@ contract DPPTrader is DPPVault {
|
||||
address(_QUOTE_TOKEN_),
|
||||
baseInput,
|
||||
receiveQuoteAmount,
|
||||
msg.sender
|
||||
msg.sender,
|
||||
to
|
||||
);
|
||||
}
|
||||
|
||||
@@ -103,7 +105,8 @@ contract DPPTrader is DPPVault {
|
||||
address(_BASE_TOKEN_),
|
||||
quoteInput,
|
||||
receiveBaseAmount,
|
||||
msg.sender
|
||||
msg.sender,
|
||||
to
|
||||
);
|
||||
}
|
||||
|
||||
@@ -152,7 +155,8 @@ contract DPPTrader is DPPVault {
|
||||
address(_BASE_TOKEN_),
|
||||
quoteInput,
|
||||
receiveBaseAmount,
|
||||
msg.sender
|
||||
msg.sender,
|
||||
assetTo
|
||||
);
|
||||
}
|
||||
|
||||
@@ -180,7 +184,8 @@ contract DPPTrader is DPPVault {
|
||||
address(_QUOTE_TOKEN_),
|
||||
baseInput,
|
||||
receiveQuoteAmount,
|
||||
msg.sender
|
||||
msg.sender,
|
||||
assetTo
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ contract DVMTrader is DVMVault {
|
||||
address toToken,
|
||||
uint256 fromAmount,
|
||||
uint256 toAmount,
|
||||
address trader
|
||||
address trader,
|
||||
address receiver
|
||||
);
|
||||
|
||||
event DODOFlashLoan(
|
||||
@@ -56,7 +57,8 @@ contract DVMTrader is DVMVault {
|
||||
address(_QUOTE_TOKEN_),
|
||||
baseInput,
|
||||
receiveQuoteAmount,
|
||||
msg.sender
|
||||
msg.sender,
|
||||
to
|
||||
);
|
||||
}
|
||||
|
||||
@@ -79,7 +81,8 @@ contract DVMTrader is DVMVault {
|
||||
address(_BASE_TOKEN_),
|
||||
quoteInput,
|
||||
receiveBaseAmount,
|
||||
msg.sender
|
||||
msg.sender,
|
||||
to
|
||||
);
|
||||
}
|
||||
|
||||
@@ -116,7 +119,8 @@ contract DVMTrader is DVMVault {
|
||||
address(_BASE_TOKEN_),
|
||||
quoteInput,
|
||||
receiveBaseAmount,
|
||||
msg.sender
|
||||
msg.sender,
|
||||
assetTo
|
||||
);
|
||||
}
|
||||
|
||||
@@ -132,7 +136,8 @@ contract DVMTrader is DVMVault {
|
||||
address(_QUOTE_TOKEN_),
|
||||
baseInput,
|
||||
receiveQuoteAmount,
|
||||
msg.sender
|
||||
msg.sender,
|
||||
assetTo
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ contract DODOIncentive is InitializableOwnable {
|
||||
// ============ Storage ============
|
||||
address public immutable _DODO_TOKEN_;
|
||||
address public _DODO_PROXY_;
|
||||
uint256 public dodoPerBlock = 10 * 10**18;
|
||||
uint256 public dodoPerBlock;
|
||||
uint256 public defaultRate = 10;
|
||||
mapping(address => uint256) public boosts;
|
||||
|
||||
@@ -44,7 +44,6 @@ contract DODOIncentive is InitializableOwnable {
|
||||
// ============ Events ============
|
||||
|
||||
event SetBoost(address token, uint256 boostRate);
|
||||
event SetSwitch(bool isOpen);
|
||||
event SetNewProxy(address dodoProxy);
|
||||
event SetPerReward(uint256 dodoPerBlock);
|
||||
event SetDefaultRate(uint256 defaultRate);
|
||||
@@ -63,6 +62,7 @@ contract DODOIncentive is InitializableOwnable {
|
||||
emit SetBoost(_token, _boostRate);
|
||||
}
|
||||
|
||||
//switch
|
||||
function changePerReward(uint256 _dodoPerBlock) public onlyOwner {
|
||||
_updateTotalReward();
|
||||
dodoPerBlock = _dodoPerBlock;
|
||||
@@ -110,8 +110,8 @@ contract DODOIncentive is InitializableOwnable {
|
||||
}
|
||||
|
||||
function _updateTotalReward() internal {
|
||||
lastRewardBlock = uint32(block.number);
|
||||
totalReward = uint112(_getTotalReward());
|
||||
lastRewardBlock = uint32(block.number);
|
||||
}
|
||||
|
||||
function _update(uint256 _totalReward, uint256 _totalDistribution) internal {
|
||||
@@ -127,7 +127,7 @@ contract DODOIncentive is InitializableOwnable {
|
||||
}
|
||||
|
||||
function _getTotalReward() internal view returns (uint256) {
|
||||
if (block.number < lastRewardBlock || lastRewardBlock == 0) {
|
||||
if (lastRewardBlock == 0) {
|
||||
return totalReward;
|
||||
} else {
|
||||
return totalReward + (block.number - lastRewardBlock) * dodoPerBlock;
|
||||
|
||||
@@ -23,6 +23,7 @@ import {DecimalMath} from "../lib/DecimalMath.sol";
|
||||
import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol";
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
import {IDODOIncentive} from "./DODOIncentive.sol";
|
||||
import {IDODOAdapter} from "./intf/IDODOAdapter.sol";
|
||||
|
||||
/**
|
||||
* @title DODOV2Proxy01
|
||||
@@ -602,76 +603,70 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
|
||||
emit OrderHistory(_fromToken, _toToken, msg.sender, fromTokenAmount, returnAmount);
|
||||
}
|
||||
|
||||
function mixSwapV1(
|
||||
|
||||
function mixSwap(
|
||||
address fromToken,
|
||||
address toToken,
|
||||
uint256 fromTokenAmount,
|
||||
uint256 minReturnAmount,
|
||||
address[] memory mixAdapters,
|
||||
address[] memory mixPairs,
|
||||
uint256[] memory directions,
|
||||
address[] memory portionPath,
|
||||
uint256 directions,
|
||||
bool isIncentive,
|
||||
uint256 deadLine
|
||||
) external override payable judgeExpired(deadLine) returns (uint256 returnAmount) {
|
||||
require(mixPairs.length == directions.length, "DODOV2Proxy01: PARAMS_LENGTH_NOT_MATCH");
|
||||
require(mixPairs.length > 0, "DODOV2Proxy01: PAIRS_EMPTY");
|
||||
require(mixPairs.length == mixAdapters.length, "DODOV2Proxy01: ADAPTER_PAIR_NOT_MATCH");
|
||||
require(minReturnAmount > 0, "DODOV2Proxy01: RETURN_AMOUNT_ZERO");
|
||||
|
||||
uint256 toTokenOriginBalance = IERC20(toToken).universalBalanceOf(msg.sender);
|
||||
|
||||
|
||||
{
|
||||
address _fromToken = fromToken;
|
||||
address _toToken = toToken;
|
||||
_deposit(msg.sender, address(this), _fromToken, fromTokenAmount, _fromToken == _ETH_ADDRESS_);
|
||||
_deposit(msg.sender, mixPairs[0], _fromToken, fromTokenAmount, _fromToken == _ETH_ADDRESS_);
|
||||
}
|
||||
|
||||
for (uint8 i = 0; i < mixPairs.length; i++) {
|
||||
address curPair = mixPairs[i];
|
||||
if (directions[i] == 0) {
|
||||
address curDodoBase = IDODOV1(curPair)._BASE_TOKEN_();
|
||||
uint256 curAmountIn = IERC20(curDodoBase).balanceOf(address(this));
|
||||
IERC20(curDodoBase).universalApproveMax(curPair, curAmountIn);
|
||||
IDODOV1(curPair).sellBaseToken(curAmountIn, 0, "");
|
||||
} else if(directions[i] == 1){
|
||||
address curDodoQuote = IDODOV1(curPair)._QUOTE_TOKEN_();
|
||||
uint256 curAmountIn = IERC20(curDodoQuote).balanceOf(address(this));
|
||||
IERC20(curDodoQuote).universalApproveMax(curPair, curAmountIn);
|
||||
uint256 canBuyBaseAmount = IDODOSellHelper(_DODO_SELL_HELPER_).querySellQuoteToken(
|
||||
curPair,
|
||||
curAmountIn
|
||||
);
|
||||
IDODOV1(curPair).buyBaseToken(canBuyBaseAmount, curAmountIn, "");
|
||||
address assetTo = toToken == _ETH_ADDRESS_ ? address(this): msg.sender;
|
||||
for (uint256 i = 0; i < mixPairs.length; i++) {
|
||||
if (i == mixPairs.length - 1) {
|
||||
if (directions & 1 == 0) {
|
||||
IDODOAdapter(mixAdapters[i]).sellBase(assetTo,mixPairs[i]);
|
||||
} else {
|
||||
IDODOAdapter(mixAdapters[i]).sellQuote(assetTo,mixPairs[i]);
|
||||
}
|
||||
} else {
|
||||
uint256 curAmountIn = IERC20(portionPath[0]).balanceOf(address(this));
|
||||
IERC20(portionPath[0]).universalApproveMax(curPair, curAmountIn);
|
||||
IUni(curPair).swapExactTokensForTokens(curAmountIn,0,portionPath,address(this),deadLine);
|
||||
if (directions& 1 == 0) {
|
||||
IDODOAdapter(mixAdapters[i]).sellBase(mixPairs[i + 1],mixPairs[i]);
|
||||
} else {
|
||||
IDODOAdapter(mixAdapters[i]).sellQuote(mixPairs[i + 1],mixPairs[i]);
|
||||
}
|
||||
}
|
||||
directions = directions >> 1;
|
||||
}
|
||||
|
||||
IERC20(_toToken).universalTransfer(
|
||||
msg.sender,
|
||||
IERC20(_toToken).universalBalanceOf(address(this))
|
||||
);
|
||||
|
||||
// {
|
||||
// uint256 toBalance;
|
||||
// if (_toToken == _ETH_ADDRESS_) {
|
||||
// toBalance = IWETH(_WETH_).balanceOf(address(this));
|
||||
// IWETH(_WETH_).withdraw(toBalance);
|
||||
// } else {
|
||||
// toBalance = IERC20(_toToken).tokenBalanceOf(address(this));
|
||||
// }
|
||||
// IERC20(_toToken).universalTransfer(msg.sender,toBalance);
|
||||
// }
|
||||
if(toToken == _ETH_ADDRESS_) {
|
||||
returnAmount = IWETH(_WETH_).balanceOf(address(this));
|
||||
IWETH(_WETH_).withdraw(returnAmount);
|
||||
msg.sender.transfer(returnAmount);
|
||||
}else {
|
||||
returnAmount = IERC20(toToken).tokenBalanceOf(msg.sender).sub(toTokenOriginBalance);
|
||||
}
|
||||
|
||||
returnAmount = IERC20(_toToken).universalBalanceOf(msg.sender).sub(toTokenOriginBalance);
|
||||
require(returnAmount >= minReturnAmount, "DODOV2Proxy01: Return amount is not enough");
|
||||
|
||||
|
||||
_externalGasReturn();
|
||||
|
||||
|
||||
if(isIncentive) {
|
||||
IDODOIncentive(_DODO_INCENTIVE_).triggerIncentive(_fromToken,_toToken,msg.sender);
|
||||
IDODOIncentive(_DODO_INCENTIVE_).triggerIncentive(fromToken,toToken,msg.sender);
|
||||
}
|
||||
|
||||
emit OrderHistory(_fromToken, _toToken, msg.sender, fromTokenAmount, returnAmount);
|
||||
|
||||
emit OrderHistory(
|
||||
fromToken,
|
||||
toToken,
|
||||
msg.sender,
|
||||
fromTokenAmount,
|
||||
returnAmount
|
||||
);
|
||||
}
|
||||
|
||||
//============ CrowdPooling Functions (create & bid) ============
|
||||
|
||||
52
contracts/SmartRoute/adapter/DODOV1Adapter.sol
Normal file
52
contracts/SmartRoute/adapter/DODOV1Adapter.sol
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {IDODOV1} from "../intf/IDODOV1.sol";
|
||||
import {IDODOSellHelper} from "../helper/DODOSellHelper.sol";
|
||||
import {UniversalERC20} from "../lib/UniversalERC20.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {IDODOAdapter} from "../intf/IDODOAdapter.sol";
|
||||
|
||||
contract DODOV1Adapter is IDODOAdapter {
|
||||
using SafeMath for uint256;
|
||||
using UniversalERC20 for IERC20;
|
||||
|
||||
address public immutable _DODO_SELL_HELPER_;
|
||||
|
||||
constructor(address dodoSellHelper) public {
|
||||
_DODO_SELL_HELPER_ = dodoSellHelper;
|
||||
}
|
||||
|
||||
function sellBase(address to, address pool) external override {
|
||||
address curBase = IDODOV1(pool)._BASE_TOKEN_();
|
||||
uint256 curAmountIn = IERC20(curBase).balanceOf(address(this));
|
||||
IERC20(curBase).universalApproveMax(pool, curAmountIn);
|
||||
IDODOV1(pool).sellBaseToken(curAmountIn, 0, "");
|
||||
if(to == msg.sender) {
|
||||
address curQuote = IDODOV1(pool)._QUOTE_TOKEN_();
|
||||
IERC20(curQuote).transfer(to,IERC20(curQuote).balanceOf(address(this)));
|
||||
}
|
||||
}
|
||||
|
||||
function sellQuote(address to, address pool) external override {
|
||||
address curQuote = IDODOV1(pool)._QUOTE_TOKEN_();
|
||||
uint256 curAmountIn = IERC20(curQuote).balanceOf(address(this));
|
||||
IERC20(curQuote).universalApproveMax(pool, curAmountIn);
|
||||
uint256 canBuyBaseAmount = IDODOSellHelper(_DODO_SELL_HELPER_).querySellQuoteToken(
|
||||
pool,
|
||||
curAmountIn
|
||||
);
|
||||
IDODOV1(pool).buyBaseToken(canBuyBaseAmount, curAmountIn, "");
|
||||
if(to == msg.sender) {
|
||||
address curBase = IDODOV1(pool)._BASE_TOKEN_();
|
||||
IERC20(curBase).transfer(to,IERC20(curBase).balanceOf(address(this)));
|
||||
}
|
||||
}
|
||||
}
|
||||
21
contracts/SmartRoute/adapter/DODOV2Adapter.sol
Normal file
21
contracts/SmartRoute/adapter/DODOV2Adapter.sol
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {IDODOV2} from "../intf/IDODOV2.sol";
|
||||
import {IDODOAdapter} from "../intf/IDODOAdapter.sol";
|
||||
|
||||
contract DODOV2Adapter is IDODOAdapter {
|
||||
function sellBase(address to, address pool) external override {
|
||||
IDODOV2(pool).sellBase(to);
|
||||
}
|
||||
|
||||
function sellQuote(address to, address pool) external override {
|
||||
IDODOV2(pool).sellQuote(to);
|
||||
}
|
||||
}
|
||||
49
contracts/SmartRoute/adapter/UniAdapter.sol
Normal file
49
contracts/SmartRoute/adapter/UniAdapter.sol
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {IDODOAdapter} from "../intf/IDODOAdapter.sol";
|
||||
import {IUni} from "../intf/IUni.sol";
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
|
||||
contract UniAdapter is IDODOAdapter {
|
||||
using SafeMath for uint;
|
||||
|
||||
//fromToken == token0
|
||||
function sellBase(address to, address pool) external override {
|
||||
address baseToken = IUni(pool).token0();
|
||||
(uint reserveIn, uint reserveOut,) = IUni(pool).getReserves();
|
||||
require(reserveIn > 0 && reserveOut > 0, 'UniAdapter: INSUFFICIENT_LIQUIDITY');
|
||||
|
||||
uint balance0 = IERC20(baseToken).balanceOf(pool);
|
||||
uint sellBaseAmount = balance0 - reserveIn;
|
||||
|
||||
uint sellBaseAmountWithFee = sellBaseAmount.mul(997);
|
||||
uint numerator = sellBaseAmountWithFee.mul(reserveOut);
|
||||
uint denominator = reserveIn.mul(1000).add(sellBaseAmountWithFee);
|
||||
uint receiveQuoteAmount = numerator / denominator;
|
||||
IUni(pool).swap(0, receiveQuoteAmount, to, new bytes(0));
|
||||
}
|
||||
|
||||
//fromToken == token1
|
||||
function sellQuote(address to, address pool) external override {
|
||||
address quoteToken = IUni(pool).token1();
|
||||
(uint reserveOut, uint reserveIn,) = IUni(pool).getReserves();
|
||||
require(reserveIn > 0 && reserveOut > 0, 'UniAdapter: INSUFFICIENT_LIQUIDITY');
|
||||
|
||||
uint balance1 = IERC20(quoteToken).balanceOf(pool);
|
||||
uint sellQuoteAmount = balance1 - reserveIn;
|
||||
|
||||
uint sellQuoteAmountWithFee = sellQuoteAmount.mul(997);
|
||||
uint numerator = sellQuoteAmountWithFee.mul(reserveOut);
|
||||
uint denominator = reserveIn.mul(1000).add(sellQuoteAmountWithFee);
|
||||
uint receiveBaseAmount = numerator / denominator;
|
||||
IUni(pool).swap(receiveBaseAmount, 0, to, new bytes(0));
|
||||
}
|
||||
}
|
||||
16
contracts/SmartRoute/intf/IDODOAdapter.sol
Normal file
16
contracts/SmartRoute/intf/IDODOAdapter.sol
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface IDODOAdapter {
|
||||
|
||||
function sellBase(address to, address pool) external;
|
||||
|
||||
function sellQuote(address to, address pool) external;
|
||||
}
|
||||
@@ -138,14 +138,14 @@ interface IDODOV2Proxy01 {
|
||||
uint256 deadLine
|
||||
) external payable returns (uint256 returnAmount);
|
||||
|
||||
function mixSwapV1(
|
||||
function mixSwap(
|
||||
address fromToken,
|
||||
address toToken,
|
||||
uint256 fromTokenAmount,
|
||||
uint256 minReturnAmount,
|
||||
address[] memory mixAdapters,
|
||||
address[] memory mixPairs,
|
||||
uint256[] memory directions,
|
||||
address[] memory portionPath,
|
||||
uint256 directions,
|
||||
bool isIncentive,
|
||||
uint256 deadLine
|
||||
) external payable returns (uint256 returnAmount);
|
||||
|
||||
@@ -9,4 +9,12 @@ interface IUni {
|
||||
address to,
|
||||
uint deadline
|
||||
) external returns (uint[] memory amounts);
|
||||
|
||||
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
|
||||
|
||||
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
|
||||
|
||||
function token0() external view returns (address);
|
||||
|
||||
function token1() external view returns (address);
|
||||
}
|
||||
@@ -16,9 +16,6 @@ contract FeeRateModelLogic is ReentrancyGuard,InitializableOwnable {
|
||||
uint256 public _FEE_RATE_;
|
||||
mapping(address => uint256) feeMapping;
|
||||
|
||||
|
||||
event Log(string str, bool result);
|
||||
|
||||
function setSpecificFeeRate(address trader, uint256 feeRate) external onlyOwner {
|
||||
require(trader != address(0), "INVALID ADDRESS!");
|
||||
feeMapping[trader] = feeRate;
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol";
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
|
||||
//for test update
|
||||
contract FeeRateModelLogicUpdate is ReentrancyGuard ,InitializableOwnable{
|
||||
//DEFAULT
|
||||
uint256 public _FEE_RATE_;
|
||||
mapping(address => uint256) feeMapping;
|
||||
|
||||
|
||||
event Log(string str, bool result);
|
||||
|
||||
function setSpecificFeeRate(address trader, uint256 feeRate) external onlyOwner {
|
||||
require(trader != address(0), "INVALID ADDRESS!");
|
||||
feeMapping[trader] = 0;
|
||||
}
|
||||
|
||||
function setFeeRate(uint256 newFeeRate) external onlyOwner {
|
||||
_FEE_RATE_ = _FEE_RATE_+ newFeeRate;
|
||||
}
|
||||
}
|
||||
@@ -88,3 +88,9 @@ Deploy time: 2021/1/11 上午10:23:58
|
||||
Deploy type: Proxy
|
||||
DODOProxyV2 Address: 0x6ed3fd491F5B10384787B3fb162A72227FaFBf63
|
||||
Set DODOProxyV2 Owner tx: 0x438ba2bfcee92e641a3e48709de31bd0e2fcb9866d30f6d73be837e3b42bd551
|
||||
====================================================
|
||||
network type: bsclive
|
||||
Deploy time: 2021/1/15 上午12:16:50
|
||||
Deploy type: Proxy
|
||||
DODOProxyV2 Address: 0x66EEdd38f757d8F9A0b7B4f47d3f74A09C7a1F37
|
||||
Set DODOProxyV2 Owner tx: 0x832e2f880fc6798d87ea1aa8f56fd8f6cdd14a9dde62278fd5a1716c073dcb7a
|
||||
|
||||
@@ -257,3 +257,23 @@ DODOProxyV2 Address: 0x06B5D7590297F7b0DcEcC5E382938EB562D91e1a
|
||||
Init DODOProxyV2 Tx: 0x1951bece5f30c090c6e6cdd121ddb5cfa17a5ca610e30173ec2e12e8698a6c21
|
||||
DODOApprove Init tx: 0xf3a9ff215e335405086c44d11e377cddeef39cb8b028f011cb6ffc1362c03f6e
|
||||
DODOIncentive ChangeProxy tx: 0xc722cf182f24e03b6ccbc19f261452f1a6019f77b32c4350be8df26c069290f0
|
||||
====================================================
|
||||
network type: kovan
|
||||
Deploy time: 2021/1/15 上午11:29:53
|
||||
Deploy type: V2
|
||||
DvmTemplateAddress: 0xD47B0782EDdAc44Bd2B6a51C949feaE9Af382A51
|
||||
DppTemplateAddress: 0xA0C3C6Ad75fBfaCb490E315BA762A6D20084b5a8
|
||||
CpTemplateAddress: 0x782A2615b4fD7DA26C076eB9F33200510395C739
|
||||
DODOApprove Address: 0x5e56Db19C3f52594876E2A3e1a47d15acD8DC570
|
||||
DODOIncentiveAddress: 0xDcD1d44Bb885e8ce2dc66ffDE8868ABb642eA45a
|
||||
DODOIncentive Init tx: 0x983db721a440e582421d873c7c445844b3d271caccce92bf47e74442cc309d47
|
||||
DvmFactoryAddress: 0x01B7fCc1890Ab90Da33dE2F0dC54aDF3C7501F04
|
||||
Init DvmFactory Tx: 0xaeb84028d484b12594cb796fb8fdb93e48fb0458e0b853afc8589f3eb9cabd11
|
||||
DppFactoryAddress: 0x67c4765D04C3848FFa7967231fc7B7E58f67A887
|
||||
Init DppFactory Tx: 0x5b2ac8ff39586400a4d3f0fdbd1e6e26c0208559362899d018f1859ec5cd2576
|
||||
CpFactoryAddress: 0x671429f12243DE03BF9826ea6cB88c41CF2a2AAA
|
||||
DODOV2RouteHelper Address: 0x0546641b5288942675A36345E25210695d1d4d50
|
||||
DODOProxyV2 Address: 0xA730229607b710cd06AEAad1eDc644Dbb70A5E85
|
||||
Init DODOProxyV2 Tx: 0x70d3a11f506ca6bb54343ad9b92d40e799c146c4acb6c6b8104bac30e5909722
|
||||
DODOApprove Init tx: 0x60bdfcf5a37bcf3568d9e98e3d32acc9289515184305282dd035475c195e0d6e
|
||||
DODOIncentive ChangeProxy tx: 0xf34b766489b5833970e01a412c725ef0ae18043e5c421bdafacca2dfe7cb904a
|
||||
|
||||
@@ -294,3 +294,44 @@ Create DPP: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x156595bAF85D5C29E91d959
|
||||
====================================================
|
||||
network type: kovan
|
||||
Deploy time: 2021/1/13 下午8:37:27
|
||||
====================================================
|
||||
network type: kovan
|
||||
Deploy time: 2021/1/13 下午8:45:21
|
||||
Mock POOL Tx: V2
|
||||
Approve:0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE Tx: 0x713758a969dd87b682fff12535aec26b068cabfac7e623759105e02925108796
|
||||
Approve:0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA Tx: 0xa69a799bc1bad6873a972aee79ac77f53960df61caa69330c712c098e933b079
|
||||
Approve:0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b Tx: 0x58a13285f365d9b0955f10523984758412f9a8776b261e89c5d7e09c7dc9bbee
|
||||
Approve:0x156595bAF85D5C29E91d959889B022d952190A64 Tx: 0xb7db2b7a86e675a9ed8ae9e573f9e33337b79c3dea037c9a9df91ffb2f8cf456
|
||||
Create DVM: 0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE-0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b Pool:0x06FC88aA4598d176e3D936823ea8C62EBb4e9096 Tx: 0xea949b9890895450666a37b7ecaa39a530cbf14d6a64dd7ecec9d02af7ff43a2
|
||||
Create DVM: 0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE-0x156595bAF85D5C29E91d959889B022d952190A64 Pool:0x44Fe35FD06878b4FD1FC85C66C8a8991E96363A8 Tx: 0x1a75e771132f0d77d8eb6ae961d25218508953cbe1f9b47720ee77d4dbb52566
|
||||
Create DVM: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b Pool:0x40e98099713F3b26796d2460df2fd5D0f41d22E6 Tx: 0xeeed9aa66c6ec98fe3ac7d4bff8050fae6afaac98d416006454b645899614dcc
|
||||
Create DVM: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x156595bAF85D5C29E91d959889B022d952190A64 Pool:0x0fa0Fb4230d890f2098A09C125ef8dE4C54ed65A Tx: 0xa36501c62683d11fcc37fe14bb4d5c0b35514c1801cb30ae2439eead9b3f0dfe
|
||||
Create DPP: 0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE-0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b Pool:0x7E70B7d95847c4688fc111aB2A670855bB1F8425 Tx: 0x1b3f3fea46d3d8329c82b6390355e8170a6cbf8492834d7d9f923f915867ad34
|
||||
Create DPP: 0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE-0x156595bAF85D5C29E91d959889B022d952190A64 Pool:0x312593a0045646aF845bA80Ca3995b68B6C37d8F Tx: 0x8959fc0b0ef347734e64668e4150fd1586329aa7e102286588174cc800e5417f
|
||||
Create DPP: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b Pool:0xF3560C11F6683D5A80cDD2A2dDEcb15863f9cE9D Tx: 0x6f4c01c6c99340e966aee06d88a9889512550aafc733259d280edd1a1a816411
|
||||
Create DPP: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x156595bAF85D5C29E91d959889B022d952190A64 Pool:0x9a5905c9027ED43bB08088cee5EEa71342152280 Tx: 0x533f85a0489a1441a2cdd6f82d1b0b0a7110ed833391cf2448ad9f9526ae6fc7
|
||||
====================================================
|
||||
network type: kovan
|
||||
Deploy time: 2021/1/13 下午9:51:04
|
||||
Mock POOL Tx: V2
|
||||
Create DVM: 0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE-0x5eca15b12d959dfcf9c71c59f8b467eb8c6efd0b Pool:0xec6675ba2B9f978EF5bFBEa391b1c42bA74E340A Tx: 0xd417e65c4e437a1e2ea2432c149393869d6d6b8d5de68cd361455395a2441e7b
|
||||
Create DVM: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x5eca15b12d959dfcf9c71c59f8b467eb8c6efd0b Pool:0xF4833EDaEfdBf28e246ade2d82EA7087Bc106C8F Tx: 0xad1ce8f0fbd5b937055f62a0c4e6024ef32cdf40bcbb8033cbeccdbf314ce9c3
|
||||
====================================================
|
||||
network type: kovan
|
||||
Deploy time: 2021/1/15 上午11:38:46
|
||||
====================================================
|
||||
network type: kovan
|
||||
Deploy time: 2021/1/15 下午1:16:41
|
||||
Mock POOL Tx: V2
|
||||
Approve:0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE Tx: 0xe444614656997e88abc7f8a319cbd636b60802c0272233c4784b55de2b4bb8f0
|
||||
Approve:0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA Tx: 0x52bd6229a1202a75dab8f22169054d4d6ed1d661550e92eb4ca63fbcfb04c90f
|
||||
Approve:0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b Tx: 0xb621fd266c2adcb6362f631ceb193016e14dc55f13979ae854fddb19c5b3ad52
|
||||
Approve:0x156595bAF85D5C29E91d959889B022d952190A64 Tx: 0x263259a175711b1b8dad83fd72bbe3b7a6ca9f9eff0b53499e1394a47ada71db
|
||||
Create DVM: 0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE-0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b Pool:0x715f1aE436Db8AFB9Cb1B4fc94010479b80Ef852 Tx: 0x42bd2b2bb8b8cb09d8e115b4e1f289f8de024712caa5faa2189ab999b4accb76
|
||||
Create DVM: 0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE-0x156595bAF85D5C29E91d959889B022d952190A64 Pool:0x375981e1D3350ae0A30e53eD8C3aC004d4D89bDe Tx: 0xa293d0d532038b7ed0e30d7afbfdd3ba3464c8aee20a3f256baee5ed9c5bde66
|
||||
Create DVM: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b Pool:0x8dd53F0ba04C1e3f293D8a8a6a2143205EC4a34c Tx: 0x963cea093acc669f510a4123dbd03ab66a6cda6295e71e860e1c8ea89cdf1363
|
||||
Create DVM: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x156595bAF85D5C29E91d959889B022d952190A64 Pool:0x773B12fdDbD3C41f479601F57DBca99E70f2e0bD Tx: 0xb08223246a75df541511ac9d765bfdc204748f1ee6467ebb8589ebc42c45f185
|
||||
Create DPP: 0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE-0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b Pool:0xeC0fe30c2028b28b90E5e7bfd7AF5B76E6Eed000 Tx: 0x245f55404c3636b40e4c86b0ee22c4bae3a95f908a3bb07409a0e88bc88304df
|
||||
Create DPP: 0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE-0x156595bAF85D5C29E91d959889B022d952190A64 Pool:0x14D4E63d050f235D8bf1Fd3dD3CDc484168FB246 Tx: 0xed71901c2c96d8b9d39839bf47f0efe8caf06fc0e8f6156a989c4d60c0dd927b
|
||||
Create DPP: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b Pool:0x82a777E65d14D462cdb8fE1886115Bbbc1F24039 Tx: 0x10360317368344c2e1519aba4fff57e6c247c0c4d95adeba1aac5c1e917acdbb
|
||||
Create DPP: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x156595bAF85D5C29E91d959889B022d952190A64 Pool:0xBA9b148769BdF0D872439ac31Ff103D487e10f64 Tx: 0x912cf081eb7e8abeae94c3dbb45b745e926d0aec76387ba897dc0e49fc660378
|
||||
|
||||
@@ -32,7 +32,7 @@ module.exports = async (deployer, network, accounts) => {
|
||||
} else if (network == "bsclive") {
|
||||
DODOSellHelperAddress = "0x0F859706AeE7FcF61D5A8939E8CB9dBB6c1EDA33";
|
||||
WETHAddress = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";
|
||||
DODOApproveAddress = "";
|
||||
DODOApproveAddress = "0xa128Ba44B2738A558A1fdC06d6303d52D3Cef8c1";
|
||||
chiAddress = "0x0000000000000000000000000000000000000000";
|
||||
DODOSwapCalcHelperAddress = "0xb0199C2c8ADF1E6c1e41De60A62E993406Cb8C02";
|
||||
ownerAddress = "0x4073f2b9bB95774531b9e23d206a308c614A943a";
|
||||
|
||||
@@ -83,7 +83,7 @@ module.exports = async (deployer, network, accounts) => {
|
||||
|
||||
DvmTemplateAddress = "";
|
||||
DppTemplateAddress = "";
|
||||
DppAdminTemplateAddress = "";
|
||||
DppAdminTemplateAddress = "0xe39E02c4f269c4E235Ca8979a125608644c8924a";
|
||||
CpTemplateAddress = "";
|
||||
//Factory
|
||||
DvmFactoryAddress = "";
|
||||
@@ -367,14 +367,8 @@ module.exports = async (deployer, network, accounts) => {
|
||||
logger.log("DODOIncentive ChangeProxy tx: ", tx.tx);
|
||||
|
||||
//3. Open trade incentive
|
||||
// const provider = new Web3.providers.HttpProvider("https://kovan.infura.io/v3/22d4a3b2df0e47b78d458f43fe50a199");
|
||||
// if (!provider) {
|
||||
// throw new Error(`Unable to find provider for network: ${network}`)
|
||||
// }
|
||||
// const web3 = new Web3(provider)
|
||||
// const blockNum = await web3.eth.getBlockNumber();
|
||||
// var tx = await DODOIncentiveInstance.switchIncentive(blockNum + 1);
|
||||
// logger.log("DODOIncentive OpenSwitch tx: ", tx.tx);
|
||||
var tx = await DODOIncentiveInstance.changePerReward(10);
|
||||
logger.log("DODOIncentive OpenSwitch tx: ", tx.tx);
|
||||
|
||||
//4. Transfer DODO to Trade Incentive
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ const POOL_PARAM = [
|
||||
quoteAddr: "0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b", //USDC
|
||||
lpFeeRate: "0", //0
|
||||
i: "5000000", //5
|
||||
k: "1000000000000000000" //1
|
||||
k: "700000000000000000" //1
|
||||
},
|
||||
{
|
||||
baseAddr: "0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA", //ABC1
|
||||
@@ -64,10 +64,10 @@ module.exports = async (deployer, network, accounts) => {
|
||||
let MintableERC20TemplateAddress = "0xA45a64DAba80757432fA4d654Df12f65f020C13C";
|
||||
let ERC20FactoryAddress = "0xCb1A2f64EfB02803276BFB5a8D511C4D950282a0";
|
||||
|
||||
let DPPFactoryAddress = "0x6D4a70354cd03ae3A8461eDE9A4dAd445a169a6B";
|
||||
let DVMFactoryAddress = "0x0ac46584e4566d5841E7D708Ab4D92Ef191fFe37";
|
||||
let DODOApproveAddress = "0xe51d8085aB43AC8BC98e965b2F7B79b998c23814";
|
||||
let DODOProxyV2Address = "0xB035847e685925647AaA8b9d74e3bFF36f81EBcB";
|
||||
let DPPFactoryAddress = "0x67c4765D04C3848FFa7967231fc7B7E58f67A887";
|
||||
let DVMFactoryAddress = "0x01B7fCc1890Ab90Da33dE2F0dC54aDF3C7501F04";
|
||||
let DODOApproveAddress = "0x5e56Db19C3f52594876E2A3e1a47d15acD8DC570";
|
||||
let DODOProxyV2Address = "0xA730229607b710cd06AEAad1eDc644Dbb70A5E85";
|
||||
|
||||
const provider = new Web3.providers.HttpProvider("https://kovan.infura.io/v3/22d4a3b2df0e47b78d458f43fe50a199");
|
||||
|
||||
@@ -115,18 +115,18 @@ module.exports = async (deployer, network, accounts) => {
|
||||
{//Approve when change DODOApprove Address
|
||||
const token0Addr = "0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE";
|
||||
const token1Addr = "0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA";
|
||||
const token2Addr = "0xFE1133ea03d701C5006b7f065bBf987955E7A67C";
|
||||
const token3Addr = "0x123ee47BaE3F64d422F2FB18ac444B47c1880F4C";
|
||||
const token4Addr = "0x0ab8EF8B19655F32959c83e5fC5cD6536065D28f";
|
||||
const token5Addr = "0x6462794c19e6b4543BEC56200212c7c746bbB9eB";
|
||||
// const token2Addr = "0xFE1133ea03d701C5006b7f065bBf987955E7A67C";
|
||||
// const token3Addr = "0x123ee47BaE3F64d422F2FB18ac444B47c1880F4C";
|
||||
// const token4Addr = "0x0ab8EF8B19655F32959c83e5fC5cD6536065D28f";
|
||||
// const token5Addr = "0x6462794c19e6b4543BEC56200212c7c746bbB9eB";
|
||||
const quote0Addr = "0x43688f367eb83697c3ca5d03c5055b6bd6f6ac4b";
|
||||
const quote1Addr = "0x156595bAF85D5C29E91d959889B022d952190A64";
|
||||
const token0 = await ERC20Template.at(token0Addr);
|
||||
const token1 = await ERC20Template.at(token1Addr);
|
||||
const token2 = await ERC20Template.at(token2Addr);
|
||||
const token3 = await ERC20Template.at(token3Addr);
|
||||
const token4 = await ERC20Template.at(token4Addr);
|
||||
const token5 = await ERC20Template.at(token5Addr);
|
||||
// const token2 = await ERC20Template.at(token2Addr);
|
||||
// const token3 = await ERC20Template.at(token3Addr);
|
||||
// const token4 = await ERC20Template.at(token4Addr);
|
||||
// const token5 = await ERC20Template.at(token5Addr);
|
||||
const quote0 = await ERC20Template.at(quote0Addr);
|
||||
const quote1 = await ERC20Template.at(quote1Addr);
|
||||
|
||||
@@ -134,14 +134,14 @@ module.exports = async (deployer, network, accounts) => {
|
||||
logger.log("Approve:" + token0Addr + " Tx:", tx.tx);
|
||||
tx = await token1.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
logger.log("Approve:" + token1Addr + " Tx:", tx.tx);
|
||||
tx = await token2.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
logger.log("Approve:" + token2Addr + " Tx:", tx.tx);
|
||||
tx = await token3.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
logger.log("Approve:" + token3Addr + " Tx:", tx.tx);
|
||||
tx = await token4.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
logger.log("Approve:" + token4Addr + " Tx:", tx.tx);
|
||||
tx = await token5.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
logger.log("Approve:" + token5Addr + " Tx:", tx.tx);
|
||||
// tx = await token2.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
// logger.log("Approve:" + token2Addr + " Tx:", tx.tx);
|
||||
// tx = await token3.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
// logger.log("Approve:" + token3Addr + " Tx:", tx.tx);
|
||||
// tx = await token4.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
// logger.log("Approve:" + token4Addr + " Tx:", tx.tx);
|
||||
// tx = await token5.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
// logger.log("Approve:" + token5Addr + " Tx:", tx.tx);
|
||||
tx = await quote0.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
logger.log("Approve:" + quote0Addr + " Tx:", tx.tx);
|
||||
tx = await quote1.approve(DODOApproveAddress, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
@@ -154,7 +154,7 @@ module.exports = async (deployer, network, accounts) => {
|
||||
const assetTo = accounts[0];
|
||||
const baseInAmount = web3.utils.toWei("100000", 'ether');
|
||||
const quoteInAmount = web3.utils.toWei("10000", 'mwei');
|
||||
// const quoteInAmount = web3.utils.toWei("0", 'ether');
|
||||
// const quoteInAmount = web3.utils.toWei("0.5", 'ether');
|
||||
const deadline = Math.floor(new Date().getTime() / 1000 + 60 * 10);
|
||||
//DVM Pool
|
||||
for (var i = 0; i < POOL_PARAM.length; i++) {
|
||||
|
||||
@@ -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,
|
||||
[
|
||||
|
||||
@@ -39,9 +39,9 @@ module.exports = {
|
||||
*/
|
||||
deploySwitch: {
|
||||
DEPLOY_V1: false,
|
||||
DEPLOY_V2: true,
|
||||
DEPLOY_V2: false,
|
||||
MOCK_TOKEN: false,
|
||||
MOCK_V2_POOL: false,
|
||||
MOCK_V2_POOL: true,
|
||||
MOCK_V2_SWAP: false,
|
||||
MANUAL_ADD_POOL: false,
|
||||
ROUTER_HELPER: false
|
||||
|
||||
Reference in New Issue
Block a user