annotation && v2proxy add gasreturn and trade incentive && proxyV2 incentive test

This commit is contained in:
owen05
2021-01-08 17:19:23 +08:00
parent 267ad24edc
commit 34d9ccf668
33 changed files with 537 additions and 90 deletions

View File

@@ -14,6 +14,12 @@ import {IPermissionManager} from "../../lib/PermissionManager.sol";
import {IFeeRateModel} from "../../lib/FeeRateModel.sol";
import {SafeMath} from "../../lib/SafeMath.sol";
/**
* @title DODO CrowdPooling
* @author DODO Breeder
*
* @notice CrowdPooling initialization
*/
contract CP is CPVesting {
using SafeMath for uint256;

View File

@@ -20,12 +20,14 @@ import {IDODOCallee} from "../../intf/IDODOCallee.sol";
contract CPFunding is CPStorage {
using SafeERC20 for IERC20;
// ============ Events ============
event Bid(address to, uint256 amount, uint256 fee);
event Cancel(address to,uint256 amount);
// ============ BID & CALM PHASE ============
modifier isBidderAllow(address bidder) {
require(_BIDDER_PERMISSION_.isAllowed(bidder), "BIDDER_NOT_ALLOWED");
_;
@@ -72,9 +74,10 @@ contract CPFunding is CPStorage {
_UNUSED_QUOTE_ = _QUOTE_TOKEN_.balanceOf(address(this)).sub(poolQuote);
_UNUSED_BASE_ = _BASE_TOKEN_.balanceOf(address(this)).sub(poolBase);
// 这里的目的是让midPrice尽量等于avgPrice
// 我们统一设定k=1如果quote和base不平衡就必然要截断一边
// DVM截断了quote所以如果进入池子的quote很多就要把quote设置成DVM的base
// 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
@@ -199,8 +202,6 @@ contract CPFunding is CPStorage {
}
}
// ============ Asset Out ============
function getShares(address user) external view returns (uint256) {
return _SHARES_[user];
}

View File

@@ -18,6 +18,8 @@ import {IERC20} from "../../intf/IERC20.sol";
contract CPStorage is InitializableOwnable, ReentrancyGuard {
using SafeMath for uint256;
// ============ Constant ============
uint256 internal constant _SETTLEMENT_EXPIRE_ = 86400 * 7;
uint256 internal constant _SETTEL_FUND_ = 200 finney;

View File

@@ -27,6 +27,8 @@ contract CPVesting is CPFunding {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// ================ Modifiers ================
modifier afterSettlement() {
require(_SETTLED_, "NOT_SETTLED");
_;

View File

@@ -15,11 +15,6 @@ interface ICP {
uint256[] calldata valueList
) external;
//==============================
//==============================
function bid(address to) external;
function cancel(address assetTo, uint256 amount) external;

View File

@@ -12,6 +12,12 @@ import {IFeeRateModel} from "../../lib/FeeRateModel.sol";
import {IERC20} from "../../intf/IERC20.sol";
import {DPPTrader} from "./DPPTrader.sol";
/**
* @title DODO PrivatePool
* @author DODO Breeder
*
* @notice DODOPrivatePool initialization
*/
contract DPP is DPPTrader {
function init(
address owner,

View File

@@ -12,13 +12,19 @@ import {IDPP} from "../intf/IDPP.sol";
import {IDODOApprove} from "../../intf/IDODOApprove.sol";
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
/**
* @title DPPAdmin
* @author DODO Breeder
*
* @notice Admin of DODOPrivatePool
*/
contract DPPAdmin is InitializableOwnable {
address public _DPP_;
address public _OPERATOR_;
address public _DODO_APPROVE_;
uint256 public _FREEZE_TIMESTAMP_;
modifier notFreezed() {
require(block.timestamp >= _FREEZE_TIMESTAMP_, "ADMIN_FREEZED");
_;
@@ -36,7 +42,6 @@ contract DPPAdmin is InitializableOwnable {
_DODO_APPROVE_ = dodoApprove;
}
//For Rebase Token
function sync() external notFreezed onlyOwner {
IDPP(_DPP_).ratioSync();
}

View File

@@ -16,12 +16,6 @@ import {IFeeRateModel} from "../../lib/FeeRateModel.sol";
import {IERC20} from "../../intf/IERC20.sol";
import {PMMPricing} from "../../lib/PMMPricing.sol";
/**
* @title Storage
* @author DODO Breeder
*
* @notice Local Variables
*/
contract DPPStorage is InitializableOwnable, ReentrancyGuard {
using SafeMath for uint256;

View File

@@ -25,8 +25,6 @@ interface IDPP {
//=========== admin ==========
function ratioSync() external;
//==============================
function retrieve(
address payable to,
address token,

View File

@@ -14,6 +14,12 @@ import {DVMTrader} from "./DVMTrader.sol";
import {DVMFunding} from "./DVMFunding.sol";
import {DVMVault} from "./DVMVault.sol";
/**
* @title DODO VendingMachine
* @author DODO Breeder
*
* @notice DODOVendingMachine initialization
*/
contract DVM is DVMTrader, DVMFunding {
function init(
address maintainer,
@@ -76,6 +82,7 @@ contract DVM is DVMTrader, DVMFunding {
}
// ============ Version Control ============
function version() external pure returns (string memory) {
return "DVM 1.0.0";
}

View File

@@ -40,11 +40,10 @@ contract DVMFunding is DVMVault {
quoteInput = quoteBalance.sub(quoteReserve);
require(baseInput > 0, "NO_BASE_INPUT");
// case 1. initial supply
// 包含了 baseReserve == 0 && quoteReserve == 0 的情况
// 在提币的时候向下取整。因此永远不会出现balance为0但totalsupply不为0的情况
// 但有可能出现reserve>0但totalSupply=0的场景
// Round down when withdrawing. Therefore, never be a situation occuring balance is 0 but totalsupply is not 0
// But May Happenreserve >0 But totalSupply = 0
if (totalSupply == 0) {
// case 1. initial supply
require(baseBalance >= 10**3, "INSUFFICIENT_LIQUIDITY_MINED");
shares = baseBalance; // 以免出现balance很大但shares很小的情况
} else if (baseReserve > 0 && quoteReserve == 0) {

View File

@@ -35,7 +35,7 @@ contract DVMTrader is DVMVault {
uint256 quoteAmount
);
// ============ Execute ============
// ============ Trade Functions ============
function sellBase(address to)
external

View File

@@ -179,6 +179,7 @@ contract DVMVault is DVMStorage {
}
// ============================ Permit ======================================
function permit(
address owner,
address spender,
@@ -205,5 +206,4 @@ contract DVMVault is DVMStorage {
);
_approve(owner, spender, value);
}
// ===========================================================================
}

View File

@@ -15,6 +15,12 @@ import {SafeMath} from "../lib/SafeMath.sol";
import {IERC20} from "../intf/IERC20.sol";
import {DecimalMath} from "../lib/DecimalMath.sol";
/**
* @title CrowdPoolingFacotry
* @author DODO Breeder
*
* @notice Create And Register CP Pools
*/
contract CrowdPoolingFactory is InitializableOwnable {
using SafeMath for uint256;
// ============ Templates ============
@@ -27,6 +33,7 @@ contract CrowdPoolingFactory is InitializableOwnable {
address public _CP_TEMPLATE_;
// ============ Settings =============
uint256 public _CAP_RATIO_ = 50;
uint256 public _FREEZE_DURATION_ = 30 days;
uint256 public _CALM_DURATION_ = 0;
@@ -43,6 +50,7 @@ contract CrowdPoolingFactory is InitializableOwnable {
mapping(address => address[]) public _USER_REGISTRY_;
// ============ modifiers ===========
modifier valueCheck(
address cpAddress,
address baseToken,
@@ -69,8 +77,6 @@ contract CrowdPoolingFactory is InitializableOwnable {
address cp
);
// ============ Functions ============
constructor(
address cloneFactory,
address cpTemplate,
@@ -87,6 +93,8 @@ contract CrowdPoolingFactory is InitializableOwnable {
_DEFAULT_PERMISSION_MANAGER_ = defaultPermissionManager;
}
// ============ Functions ============
function createCrowdPooling() external returns (address newCrowdPooling) {
newCrowdPooling = ICloneFactory(_CLONE_FACTORY_).clone(_CP_TEMPLATE_);
}
@@ -149,6 +157,7 @@ contract CrowdPoolingFactory is InitializableOwnable {
}
// ============ Owner Functions ============
function updateCPTemplate(address _newCPTemplate) external onlyOwner {
_CP_TEMPLATE_ = _newCPTemplate;
}

View File

@@ -14,6 +14,12 @@ import {IFeeRateModel} from "../lib/FeeRateModel.sol";
import {IDPP} from "../DODOPrivatePool/intf/IDPP.sol";
import {IDPPAdmin} from "../DODOPrivatePool/intf/IDPPAdmin.sol";
/**
* @title DODO PrivatePool Factory
* @author DODO Breeder
*
* @notice Create And Register DPP Pools
*/
contract DPPFactory is InitializableOwnable {
// ============ Templates ============
@@ -43,8 +49,6 @@ contract DPPFactory is InitializableOwnable {
event RemoveDPP(address dpp);
// ============ Functions ============
constructor(
address cloneFactory,
address dppTemplate,
@@ -61,6 +65,8 @@ contract DPPFactory is InitializableOwnable {
_DODO_APPROVE_ = dodoApprove;
}
// ============ Functions ============
function createDODOPrivatePool() external returns (address newPrivatePool) {
newPrivatePool = ICloneFactory(_CLONE_FACTORY_).clone(_DPP_TEMPLATE_);
}

View File

@@ -22,6 +22,13 @@ interface IDVMFactory {
) external returns (address newVendingMachine);
}
/**
* @title DODO VendingMachine Factory
* @author DODO Breeder
*
* @notice Create And Register DVM Pools
*/
contract DVMFactory is InitializableOwnable {
// ============ Templates ============

View File

@@ -12,6 +12,13 @@ import {ICloneFactory} from "../lib/CloneFactory.sol";
import {InitializableERC20} from "../external/ERC20/InitializableERC20.sol";
import {InitializableMintableERC20} from "../external/ERC20/InitializableMintableERC20.sol";
/**
* @title DODO ERC20Factory
* @author DODO Breeder
*
* @notice Help user to create erc20 token
*/
contract ERC20Factory {
// ============ Templates ============

View File

@@ -40,10 +40,6 @@ contract DODOIncentive is InitializableOwnable {
uint112 public totalReward;
uint112 public totalDistribution;
constructor(address _dodoToken) public {
_DODO_TOKEN_ = _dodoToken;
}
// ============ Events ============
event SetBoost(address token, uint256 boostRate);
@@ -53,6 +49,10 @@ contract DODOIncentive is InitializableOwnable {
event SetDefaultRate(uint256 defaultRate);
event Incentive(address user,uint256 reward);
constructor(address _dodoToken) public {
_DODO_TOKEN_ = _dodoToken;
}
// ============ Ownable ============
function switchIncentive(uint256 _startBlock) public onlyOwner {
@@ -98,6 +98,7 @@ contract DODOIncentive is InitializableOwnable {
// ============ Incentive function============
function triggerIncentive(address fromToken,address toToken, address assetTo) external {
require(msg.sender == _DODO_PROXY_, "DODOIncentive:Access restricted");
uint256 _startBlock = startBlock;
@@ -106,14 +107,10 @@ contract DODOIncentive is InitializableOwnable {
uint256 curTotalDistribution = totalDistribution;
uint256 fromRate = boosts[fromToken];
uint256 toRate = boosts[toToken];
// uint256 rate = (fromRate >= toRate ? fromRate : toRate).add(defaultRate);
uint256 rate = (fromRate >= toRate ? fromRate : toRate) + defaultRate;
// uint256 _totalReward = uint256(totalReward).add(block.number.sub(uint256(lastRewardBlock)).mul(dodoPerBlock));
uint256 _totalReward = totalReward + (block.number - lastRewardBlock) * dodoPerBlock;
// uint256 reward = _totalReward.sub(curTotalDistribution).mul(rate).div(1000);
uint256 reward = (_totalReward - curTotalDistribution) * rate / 1000;
// uint256 _totalDistribution = curTotalDistribution.add(reward);
uint256 _totalDistribution = curTotalDistribution + reward;
_update(_totalReward,_totalDistribution);
@@ -125,7 +122,6 @@ contract DODOIncentive is InitializableOwnable {
function _update(uint256 _totalReward, uint256 _totalDistribution) internal {
if(_totalReward == 0)
// _totalReward = uint256(totalReward).add(block.number.sub(uint256(lastRewardBlock)).mul(dodoPerBlock));
_totalReward = totalReward + (block.number - lastRewardBlock) * dodoPerBlock;
require(_totalReward < uint112(-1) && _totalDistribution < uint112(-1) && block.number < uint32(-1), "OVERFLOW");
lastRewardBlock = uint32(block.number);

View File

@@ -15,14 +15,21 @@ import {IDODOSellHelper} from "./helper/DODOSellHelper.sol";
import {IERC20} from "../intf/IERC20.sol";
import {IWETH} from "../intf/IWETH.sol";
import {IUni} from "./intf/IUni.sol";
import {IChi} from "./intf/IChi.sol";
import {SafeMath} from "../lib/SafeMath.sol";
import {UniversalERC20} from "./lib/UniversalERC20.sol";
import {SafeERC20} from "../lib/SafeERC20.sol";
import {DecimalMath} from "../lib/DecimalMath.sol";
import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol";
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
import {IDODOIncentive} from "./DODOIncentive.sol";
//TODO: add gas return && trade incentive && replace DODOV1Proxy02
/**
* @title DODOV2Proxy01
* @author DODO Breeder
*
* @notice Entrance of trading in DODO platform
*/
contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable {
using SafeMath for uint256;
using UniversalERC20 for IERC20;
@@ -36,6 +43,10 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
address public immutable _DVM_FACTORY_;
address public immutable _DPP_FACTORY_;
address public immutable _CP_FACTORY_;
address public immutable _DODO_INCENTIVE_;
address public immutable _CHI_TOKEN_;
uint256 public _GAS_DODO_MAX_RETURN_ = 0;
uint256 public _GAS_EXTERNAL_RETURN_ = 0;
mapping (address => bool) public isWhiteListed;
// ============ Events ============
@@ -65,7 +76,9 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
address cpFactory,
address payable weth,
address dodoApprove,
address dodoSellHelper
address dodoSellHelper,
address chiToken,
address dodoIncentive
) public {
_DVM_FACTORY_ = dvmFactory;
_DPP_FACTORY_ = dppFactory;
@@ -73,6 +86,8 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
_WETH_ = weth;
_DODO_APPROVE_ = dodoApprove;
_DODO_SELL_HELPER_ = dodoSellHelper;
_CHI_TOKEN_ = chiToken;
_DODO_INCENTIVE_ = dodoIncentive;
}
function addWhiteList (address contractAddr) public onlyOwner {
@@ -83,6 +98,11 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
isWhiteListed[contractAddr] = false;
}
function updateGasReturn(uint256 newDodoGasReturn, uint256 newExternalGasReturn) public onlyOwner {
_GAS_DODO_MAX_RETURN_ = newDodoGasReturn;
_GAS_EXTERNAL_RETURN_ = newExternalGasReturn;
}
// ============ DVM Functions (create & add liquidity) ============
function createDODOVendingMachine(
@@ -295,6 +315,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
uint256 minReturnAmount,
address[] memory dodoPairs,
uint256 directions,
bool isIncentive,
uint256 deadLine
)
external
@@ -305,6 +326,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
{
require(dodoPairs.length > 0, "DODOV2Proxy01: PAIRS_EMPTY");
require(minReturnAmount > 0, "DODOV2Proxy01: RETURN_AMOUNT_ZERO");
uint256 originGas = gasleft();
uint256 originToTokenBalance = IERC20(toToken).balanceOf(msg.sender);
IWETH(_WETH_).deposit{value: msg.value}();
@@ -329,6 +351,13 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
returnAmount = IERC20(toToken).balanceOf(msg.sender).sub(originToTokenBalance);
require(returnAmount >= minReturnAmount, "DODOV2Proxy01: Return amount is not enough");
_dodoGasReturn(originGas);
if(isIncentive) {
IDODOIncentive(_DODO_INCENTIVE_).triggerIncentive(_ETH_ADDRESS_,toToken,msg.sender);
}
emit OrderHistory(
_ETH_ADDRESS_,
toToken,
@@ -344,6 +373,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
uint256 minReturnAmount,
address[] memory dodoPairs,
uint256 directions,
bool isIncentive,
uint256 deadLine
)
external
@@ -353,6 +383,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
{
require(dodoPairs.length > 0, "DODOV2Proxy01: PAIRS_EMPTY");
require(minReturnAmount > 0, "DODOV2Proxy01: RETURN_AMOUNT_ZERO");
uint256 originGas = gasleft();
IDODOApprove(_DODO_APPROVE_).claimTokens(fromToken, msg.sender, dodoPairs[0], fromTokenAmount);
@@ -376,6 +407,13 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
require(returnAmount >= minReturnAmount, "DODOV2Proxy01: Return amount is not enough");
IWETH(_WETH_).withdraw(returnAmount);
msg.sender.transfer(returnAmount);
_dodoGasReturn(originGas);
if(isIncentive) {
IDODOIncentive(_DODO_INCENTIVE_).triggerIncentive(fromToken,_ETH_ADDRESS_,msg.sender);
}
emit OrderHistory(
fromToken,
_ETH_ADDRESS_,
@@ -392,6 +430,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
uint256 minReturnAmount,
address[] memory dodoPairs,
uint256 directions,
bool isIncentive,
uint256 deadLine
)
external
@@ -401,6 +440,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
{
require(dodoPairs.length > 0, "DODOV2Proxy01: PAIRS_EMPTY");
require(minReturnAmount > 0, "DODOV2Proxy01: RETURN_AMOUNT_ZERO");
uint256 originGas = gasleft();
uint256 originToTokenBalance = IERC20(toToken).balanceOf(msg.sender);
IDODOApprove(_DODO_APPROVE_).claimTokens(fromToken, msg.sender, dodoPairs[0], fromTokenAmount);
@@ -423,6 +463,13 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
}
returnAmount = IERC20(toToken).balanceOf(msg.sender).sub(originToTokenBalance);
require(returnAmount >= minReturnAmount, "DODOV2Proxy01: Return amount is not enough");
_dodoGasReturn(originGas);
if(isIncentive) {
IDODOIncentive(_DODO_INCENTIVE_).triggerIncentive(fromToken,toToken,msg.sender);
}
emit OrderHistory(
fromToken,
toToken,
@@ -440,6 +487,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
uint256 fromTokenAmount,
uint256 minReturnAmount,
bytes memory callDataConcat,
bool isIncentive,
uint256 deadLine
)
external
@@ -474,6 +522,12 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
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);
}
emit OrderHistory(
fromToken,
toToken,
@@ -489,7 +543,8 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
uint256 fromTokenAmount,
uint256 minReturnAmount,
address[] memory dodoPairs,
uint8[] memory directions,
uint256 directions,
bool isIncentive,
uint256 deadLine
)
external
@@ -498,12 +553,18 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
judgeExpired(deadLine)
returns (uint256 returnAmount)
{
require(dodoPairs.length == directions.length, "DODOV2Proxy01: PARAMS_LENGTH_NOT_MATCH");
_deposit(msg.sender, address(this), fromToken, fromTokenAmount, fromToken == _ETH_ADDRESS_);
require(dodoPairs.length > 0, "DODOV2Proxy01: PAIRS_EMPTY");
require(minReturnAmount > 0, "DODOV2Proxy01: RETURN_AMOUNT_ZERO");
uint256 originGas = gasleft();
address _fromToken = fromToken;
address _toToken = toToken;
_deposit(msg.sender, address(this), _fromToken, fromTokenAmount, _fromToken == _ETH_ADDRESS_);
for (uint256 i = 0; i < dodoPairs.length; i++) {
address curDodoPair = dodoPairs[i];
if (directions[i] == 0) {
if (directions & 1 == 0) {
address curDodoBase = IDODOV1(curDodoPair)._BASE_TOKEN_();
uint256 curAmountIn = IERC20(curDodoBase).balanceOf(address(this));
IERC20(curDodoBase).universalApproveMax(curDodoPair, curAmountIn);
@@ -518,19 +579,27 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
);
IDODOV1(curDodoPair).buyBaseToken(canBuyBaseAmount, curAmountIn, "");
}
directions = directions >> 1;
}
if (toToken == _ETH_ADDRESS_) {
if (_toToken == _ETH_ADDRESS_) {
returnAmount = IWETH(_WETH_).balanceOf(address(this));
IWETH(_WETH_).withdraw(returnAmount);
} else {
returnAmount = IERC20(toToken).tokenBalanceOf(address(this));
returnAmount = IERC20(_toToken).tokenBalanceOf(address(this));
}
require(returnAmount >= minReturnAmount, "DODOV2Proxy01: Return amount is not enough");
IERC20(toToken).universalTransfer(msg.sender, returnAmount);
IERC20(_toToken).universalTransfer(msg.sender, returnAmount);
emit OrderHistory(fromToken, toToken, msg.sender, fromTokenAmount, returnAmount);
_dodoGasReturn(originGas);
if(isIncentive) {
IDODOIncentive(_DODO_INCENTIVE_).triggerIncentive(_fromToken,_toToken,msg.sender);
}
emit OrderHistory(_fromToken, _toToken, msg.sender, fromTokenAmount, returnAmount);
}
function mixSwapV1(
@@ -539,11 +608,15 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
uint256 fromTokenAmount,
uint256 minReturnAmount,
address[] memory mixPairs,
uint8[] memory directions,
uint256[] memory directions,
address[] memory portionPath,
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(minReturnAmount > 0, "DODOV2Proxy01: RETURN_AMOUNT_ZERO");
uint256 toTokenOriginBalance = IERC20(toToken).universalBalanceOf(msg.sender);
address _fromToken = fromToken;
@@ -573,11 +646,6 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
}
}
IERC20(_fromToken).universalTransfer(
msg.sender,
IERC20(_fromToken).universalBalanceOf(address(this))
);
IERC20(_toToken).universalTransfer(
msg.sender,
IERC20(_toToken).universalBalanceOf(address(this))
@@ -586,6 +654,11 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
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);
}
emit OrderHistory(_fromToken, _toToken, msg.sender, fromTokenAmount, returnAmount);
}
@@ -696,4 +769,22 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
SafeERC20.safeTransfer(IERC20(token), to, amount);
}
}
function _dodoGasReturn(uint256 originGas) internal {
uint256 _gasDodoMaxReturn = _GAS_DODO_MAX_RETURN_;
if(_gasDodoMaxReturn > 0) {
uint256 calcGasTokenBurn = originGas.sub(gasleft()) / 65000;
uint256 gasTokenBurn = calcGasTokenBurn > _gasDodoMaxReturn ? _gasDodoMaxReturn : calcGasTokenBurn;
if(gasTokenBurn >= 3 && gasleft() > 27710 + gasTokenBurn * 6080)
IChi(_CHI_TOKEN_).freeUpTo(gasTokenBurn);
}
}
function _externalGasReturn() internal {
uint256 _gasExternalReturn = _GAS_EXTERNAL_RETURN_;
if(_gasExternalReturn > 0) {
if(gasleft() > 27710 + _gasExternalReturn * 6080)
IChi(_CHI_TOKEN_).freeUpTo(_gasExternalReturn);
}
}
}

View File

@@ -1,9 +1,3 @@
/**
*Submitted for verification at Etherscan.io on 2020-10-10
*/
// File: contracts/intf/IDODO.sol
/*
Copyright 2020 DODO ZOO.

View File

@@ -8,14 +8,15 @@
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import {IDODOV1Proxy01} from "./IDODOV1Proxy01.sol";
import {IDODOV1Proxy02} from "./IDODOV1Proxy02.sol";
interface IDODOV2Proxy01 is IDODOV1Proxy01 {
interface IDODOV2Proxy01 is IDODOV1Proxy02 {
function dodoSwapV2ETHToToken(
address toToken,
uint256 minReturnAmount,
address[] memory dodoPairs,
uint256 directions,
bool isIncentive,
uint256 deadLine
) external payable returns (uint256 returnAmount);
@@ -25,6 +26,7 @@ interface IDODOV2Proxy01 is IDODOV1Proxy01 {
uint256 minReturnAmount,
address[] memory dodoPairs,
uint256 directions,
bool isIncentive,
uint256 deadLine
) external returns (uint256 returnAmount);
@@ -35,6 +37,7 @@ interface IDODOV2Proxy01 is IDODOV1Proxy01 {
uint256 minReturnAmount,
address[] memory dodoPairs,
uint256 directions,
bool isIncentive,
uint256 deadLine
) external returns (uint256 returnAmount);