fix uni
This commit is contained in:
@@ -15,20 +15,26 @@ import {UniversalERC20} from "../lib/UniversalERC20.sol";
|
||||
import {SafeERC20} from "../../lib/SafeERC20.sol";
|
||||
import {TickMath} from '../../external/uniswap/TickMath.sol';
|
||||
import {IWETH} from "../../intf/IWETH.sol";
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
import {PoolAddress} from '../../external/uniswap/PoolAddress.sol';
|
||||
|
||||
// to adapter like dodo V1
|
||||
contract UniV3Adapter is IDODOAdapter, IUniswapV3SwapCallback {
|
||||
contract UniV3Adapter is IDODOAdapter, IUniswapV3SwapCallback, InitializableOwnable {
|
||||
using SafeMath for uint;
|
||||
|
||||
// ============ Storage ============
|
||||
|
||||
address constant _ETH_ADDRESS_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
address public immutable _WETH_;
|
||||
address public immutable _V3_FACTORY_;
|
||||
|
||||
constructor (
|
||||
address payable weth
|
||||
address payable weth,
|
||||
address factory
|
||||
) public {
|
||||
_WETH_ = weth;
|
||||
_V3_FACTORY_ = factory;
|
||||
initOwner(msg.sender);
|
||||
}
|
||||
|
||||
function _uniV3Swap(address to, address pool, uint160 sqrtX96, bytes memory data) internal {
|
||||
@@ -37,8 +43,6 @@ contract UniV3Adapter is IDODOAdapter, IUniswapV3SwapCallback {
|
||||
uint256 sellAmount = IERC20(fromToken).balanceOf(address(this));
|
||||
bool zeroForOne = fromToken < toToken;
|
||||
|
||||
// transfer
|
||||
//IERC20(fromToken).transfer(pool, sellAmount);
|
||||
// swap
|
||||
IUniV3(pool).swap(
|
||||
to,
|
||||
@@ -70,6 +74,9 @@ contract UniV3Adapter is IDODOAdapter, IUniswapV3SwapCallback {
|
||||
) external override {
|
||||
require(amount0Delta > 0 || amount1Delta > 0); // swaps entirely within 0-liquidity regions are not supported
|
||||
(address tokenIn, address tokenOut, uint24 fee) = abi.decode(_data, (address, address, uint24));
|
||||
// verifyCallback
|
||||
address poolAddress = PoolAddress.computeAddress(_V3_FACTORY_, PoolAddress.getPoolKey(tokenIn, tokenOut, fee));
|
||||
require(msg.sender == poolAddress || msg.sender == _OWNER_, "not available call address");
|
||||
|
||||
(bool isExactInput, uint256 amountToPay) =
|
||||
amount0Delta > 0
|
||||
|
||||
Reference in New Issue
Block a user