2020-11-29 23:51:26 +08:00
|
|
|
/*
|
2021-01-08 01:59:35 +08:00
|
|
|
|
2021-01-07 12:52:24 +08:00
|
|
|
Copyright 2020 DODO ZOO.
|
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
2020-11-29 23:51:26 +08:00
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
pragma solidity 0.6.9;
|
|
|
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
|
|
|
|
|
|
import {IDODOV2} from "../intf/IDODOV2.sol";
|
|
|
|
|
import {IERC20} from "../../intf/IERC20.sol";
|
|
|
|
|
import {IWETH} from "../../intf/IWETH.sol";
|
|
|
|
|
import {SafeERC20} from "../../lib/SafeERC20.sol";
|
|
|
|
|
import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
|
|
|
|
|
|
|
|
|
|
contract DODOCalleeHelper is ReentrancyGuard {
|
|
|
|
|
using SafeERC20 for IERC20;
|
2021-01-22 14:00:45 +08:00
|
|
|
address payable public immutable _WETH_;
|
2020-11-29 23:51:26 +08:00
|
|
|
|
|
|
|
|
fallback() external payable {
|
2020-11-30 16:08:11 +08:00
|
|
|
require(msg.sender == _WETH_, "WE_SAVED_YOUR_ETH");
|
2020-11-29 23:51:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
receive() external payable {
|
2020-11-30 16:08:11 +08:00
|
|
|
require(msg.sender == _WETH_, "WE_SAVED_YOUR_ETH");
|
2020-11-29 23:51:26 +08:00
|
|
|
}
|
|
|
|
|
|
2021-01-22 14:00:45 +08:00
|
|
|
constructor(address payable weth) public {
|
2020-12-01 01:47:22 +08:00
|
|
|
_WETH_ = weth;
|
2020-11-29 23:51:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function DVMSellShareCall(
|
|
|
|
|
address payable assetTo,
|
|
|
|
|
uint256,
|
|
|
|
|
uint256 baseAmount,
|
|
|
|
|
uint256 quoteAmount,
|
|
|
|
|
bytes calldata
|
|
|
|
|
) external preventReentrant {
|
|
|
|
|
address _baseToken = IDODOV2(msg.sender)._BASE_TOKEN_();
|
|
|
|
|
address _quoteToken = IDODOV2(msg.sender)._QUOTE_TOKEN_();
|
|
|
|
|
_withdraw(assetTo, _baseToken, baseAmount, _baseToken == _WETH_);
|
|
|
|
|
_withdraw(assetTo, _quoteToken, quoteAmount, _quoteToken == _WETH_);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-08 01:59:35 +08:00
|
|
|
function CPCancelCall(
|
|
|
|
|
address payable assetTo,
|
|
|
|
|
uint256 amount,
|
|
|
|
|
bytes calldata
|
|
|
|
|
)external preventReentrant{
|
|
|
|
|
address _quoteToken = IDODOV2(msg.sender)._QUOTE_TOKEN_();
|
|
|
|
|
_withdraw(assetTo, _quoteToken, amount, _quoteToken == _WETH_);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-08 17:41:36 +08:00
|
|
|
function CPClaimBidCall(
|
|
|
|
|
address payable assetTo,
|
|
|
|
|
uint256 baseAmount,
|
|
|
|
|
uint256 quoteAmount,
|
|
|
|
|
bytes calldata
|
|
|
|
|
) external preventReentrant {
|
|
|
|
|
address _baseToken = IDODOV2(msg.sender)._BASE_TOKEN_();
|
|
|
|
|
address _quoteToken = IDODOV2(msg.sender)._QUOTE_TOKEN_();
|
|
|
|
|
_withdraw(assetTo, _baseToken, baseAmount, _baseToken == _WETH_);
|
|
|
|
|
_withdraw(assetTo, _quoteToken, quoteAmount, _quoteToken == _WETH_);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-29 23:51:26 +08:00
|
|
|
function _withdraw(
|
|
|
|
|
address payable to,
|
|
|
|
|
address token,
|
|
|
|
|
uint256 amount,
|
|
|
|
|
bool isETH
|
|
|
|
|
) internal {
|
|
|
|
|
if (isETH) {
|
|
|
|
|
if (amount > 0) {
|
|
|
|
|
IWETH(_WETH_).withdraw(amount);
|
|
|
|
|
to.transfer(amount);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2021-02-03 13:24:52 +08:00
|
|
|
if (amount > 0) {
|
|
|
|
|
SafeERC20.safeTransfer(IERC20(token), to, amount);
|
|
|
|
|
}
|
2020-11-29 23:51:26 +08:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-30 16:08:11 +08:00
|
|
|
}
|