fix apdater && add approve proxy

This commit is contained in:
owen05
2021-01-26 17:53:49 +08:00
parent f5704e4803
commit a525e0a839
16 changed files with 1417 additions and 108 deletions

View File

@@ -9,6 +9,7 @@ pragma solidity 0.6.9;
import {IERC20} from "../../intf/IERC20.sol";
import {IDODOV1} from "../intf/IDODOV1.sol";
import {SafeERC20} from "../../lib/SafeERC20.sol";
import {IDODOSellHelper} from "../helper/DODOSellHelper.sol";
import {UniversalERC20} from "../lib/UniversalERC20.sol";
import {SafeMath} from "../../lib/SafeMath.sol";
@@ -26,18 +27,18 @@ contract DODOV1Adapter is IDODOAdapter {
function sellBase(address to, address pool) external override {
address curBase = IDODOV1(pool)._BASE_TOKEN_();
uint256 curAmountIn = IERC20(curBase).balanceOf(address(this));
uint256 curAmountIn = IERC20(curBase).tokenBalanceOf(address(this));
IERC20(curBase).universalApproveMax(pool, curAmountIn);
IDODOV1(pool).sellBaseToken(curAmountIn, 0, "");
if(to != address(this)) {
address curQuote = IDODOV1(pool)._QUOTE_TOKEN_();
IERC20(curQuote).transfer(to,IERC20(curQuote).balanceOf(address(this)));
SafeERC20.safeTransfer(IERC20(curQuote), to, IERC20(curQuote).tokenBalanceOf(address(this)));
}
}
function sellQuote(address to, address pool) external override {
address curQuote = IDODOV1(pool)._QUOTE_TOKEN_();
uint256 curAmountIn = IERC20(curQuote).balanceOf(address(this));
uint256 curAmountIn = IERC20(curQuote).tokenBalanceOf(address(this));
IERC20(curQuote).universalApproveMax(pool, curAmountIn);
uint256 canBuyBaseAmount = IDODOSellHelper(_DODO_SELL_HELPER_).querySellQuoteToken(
pool,
@@ -46,7 +47,7 @@ contract DODOV1Adapter is IDODOAdapter {
IDODOV1(pool).buyBaseToken(canBuyBaseAmount, curAmountIn, "");
if(to != address(this)) {
address curBase = IDODOV1(pool)._BASE_TOKEN_();
IERC20(curBase).transfer(to,IERC20(curBase).balanceOf(address(this)));
SafeERC20.safeTransfer(IERC20(curBase), to, canBuyBaseAmount);
}
}
}