Address Contract Verified
Address
0x440dAF974BF6C97e9442FfFd022cA554eE94219c
Balance
0 ETH
Nonce
1
Code Size
7890 bytes
Creator
0x21FE3e26...6E37 at tx 0xad6817ea...42391a
Indexed Transactions
0
Contract Bytecode
7890 bytes
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c8063a111985611610097578063c4f3e9d711610066578063c4f3e9d714610259578063e3ddd7791461026c578063e8e337001461027f578063f191c16a1461029257600080fd5b8063a1119856146101de578063ad5c464814610205578063baa2abde1461020d578063c3749ae51461022257600080fd5b80638ada032e116100d35780638ada032e1461017e5780638d5752d6146101a55780639a8fadee146101b85780639f4f9745146101cb57600080fd5b80630a8e060f146100fa5780633e99c1e41461012a57806383e4b89f1461015d575b600080fd5b61010d610108366004611947565b6102b9565b6040516001600160a01b0390911681526020015b60405180910390f35b61013d610138366004611999565b6102ee565b604080516001600160701b03938416815292909116602083015201610121565b61017061016b3660046119bd565b61035e565b604051908152602001610121565b61010d7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6101706101b3366004611a34565b610611565b6101706101c63660046119bd565b610892565b61010d6101d9366004611aa2565b610b73565b61010d7f00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc4581565b61010d610c74565b61022061021b366004611adb565b610cfd565b005b6102497f000000000000000000000000000000000000000000000000000000000000000081565b6040519015158152602001610121565b61010d610267366004611aa2565b61106d565b61010d61027a366004611b4e565b611143565b61022061028d366004611b95565b611281565b61010d7f0000000000000000000000009de8aa7743660e73a481e5647e75050da950453381565b60405162461bcd60e51b8152602060048201526002602482015261049360f41b60448201526000906064015b60405180910390fd5b600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa15801561032f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103539190611c28565b509094909350915050565b6040516370a0823160e01b81526001600160a01b03828116600483015260009182918716906370a0823190602401602060405180830381865afa1580156103a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103cd9190611c6d565b905084600003610446576040516370a0823160e01b81523060048201526001600160a01b038816906370a0823190602401602060405180830381865afa15801561041b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061043f9190611c6d565b945061045d565b61045d335b6001600160a01b0389169030886116b2565b604080516002808252606082018352600092602083019080368337019050509050878160008151811061049257610492611c9c565b60200260200101906001600160a01b031690816001600160a01b03168152505086816001815181106104c6576104c6611c9c565b6001600160a01b0392831660209182029290920101526105099089167f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d8861171f565b604051635c11d79560e01b81526001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d1690635c11d7959061055d908990899086908a904290600401611cb2565b600060405180830381600087803b15801561057757600080fd5b505af115801561058b573d6000803e3d6000fd5b50506040516370a0823160e01b81526001600160a01b0387811660048301528593508a1691506370a0823190602401602060405180830381865afa1580156105d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105fb9190611c6d565b6106059190611d3a565b98975050505050505050565b6040516370a0823160e01b81526001600160a01b03828116600483015260009182918816906370a0823190602401602060405180830381865afa15801561065c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106809190611c6d565b9050846000036106f9576040516370a0823160e01b81523060048201526001600160a01b038916906370a0823190602401602060405180830381865afa1580156106ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f29190611c6d565b945061070e565b61070e6001600160a01b0389163330886116b2565b6107426001600160a01b0389167f00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc458761171f565b6040805160e0810182526001600160a01b038a811682528981166020830190815262ffffff8a811684860190815288841660608601908152608086018c815260a087018c8152600060c0890190815298516304e45aaf60e01b8152975187166004890152945186166024880152915190921660448601529051831660648501525160848401525160a48301529151821660c48201527f00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45909116906304e45aaf9060e4016020604051808303816000875af1158015610824573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108489190611c6d565b506040516370a0823160e01b81526001600160a01b0384811660048301528291908916906370a0823190602401602060405180830381865afa1580156105d7573d6000803e3d6000fd5b6040516370a0823160e01b815230600482015260009081906001600160a01b038816906370a0823190602401602060405180830381865afa1580156108db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108ff9190611c6d565b905084600003610978576040516370a0823160e01b81523060048201526001600160a01b038816906370a0823190602401602060405180830381865afa15801561094d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109719190611c6d565b9450610981565b6109813361044b565b60408051600280825260608201835260009260208301908036833701905050905087816000815181106109b6576109b6611c9c565b60200260200101906001600160a01b031690816001600160a01b03168152505086816001815181106109ea576109ea611c9c565b6001600160a01b039283166020918202929092010152610a2d9089167f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d8861171f565b604051634401edf760e11b81526001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d1690638803dbee90610a819088908a9086908a904290600401611cb2565b6000604051808303816000875af1158015610aa0573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610ac89190810190611d4d565b506040516370a0823160e01b815230600482015260009083906001600160a01b038b16906370a0823190602401602060405180830381865afa158015610b12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b369190611c6d565b610b409190611d3a565b90508015610b5c57610b5c6001600160a01b038a1633836117a9565b610b668188611d3a565b9998505050505050505050565b60007f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bf79190611e1a565b60405163e6a4390560e01b81526001600160a01b0385811660048301528481166024830152919091169063e6a4390590604401602060405180830381865afa158015610c47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c6b9190611e1a565b90505b92915050565b60007f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cd4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cf89190611e1a565b905090565b60007f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d819190611e1a565b60405163e6a4390560e01b81526001600160a01b038a811660048301528981166024830152919091169063e6a4390590604401602060405180830381865afa158015610dd1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610df59190611e1a565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610e3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e639190611c6d565b9050610e7a6001600160a01b03831633308a6116b2565b610eae6001600160a01b0383167f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d8961171f565b604051635d5155ef60e11b81526001600160a01b038a81166004830152898116602483015260448201899052606482018890526084820187905285811660a483015260c482018590527f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d169063baa2abde9060e40160408051808303816000875af1158015610f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f659190611e37565b50506040516370a0823160e01b815230600482015281906001600160a01b038416906370a0823190602401602060405180830381865afa158015610fad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fd19190611c6d565b1115611062576040516370a0823160e01b815230600482015261106290859083906001600160a01b038616906370a0823190602401602060405180830381865afa158015611023573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110479190611c6d565b6110519190611d3a565b6001600160a01b03851691906117a9565b505050505050505050565b60007f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156110cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110f19190611e1a565b6040516364e329cb60e11b81526001600160a01b0385811660048301528481166024830152919091169063c9c65396906044016020604051808303816000875af1158015610c47573d6000803e3d6000fd5b60007f0000000000000000000000009de8aa7743660e73a481e5647e75050da95045336001600160a01b0316634556bd207f00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc456001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111f69190611e1a565b6040516001600160e01b031960e084901b1681526001600160a01b0391821660048201528188166024820152908616604482015262ffffff85166064820152608401602060405180830381865afa158015611255573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112799190611e1a565b949350505050565b6040516370a0823160e01b81523060048201526000906001600160a01b038a16906370a0823190602401602060405180830381865afa1580156112c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112ec9190611c6d565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038a16906370a0823190602401602060405180830381865afa158015611336573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061135a9190611c6d565b90506113716001600160a01b038b1633308b6116b2565b6113866001600160a01b038a1633308a6116b2565b6113ba6001600160a01b038b167f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d8a61171f565b6113ee6001600160a01b038a167f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d8961171f565b60405162e8e33760e81b81526001600160a01b038b811660048301528a81166024830152604482018a9052606482018990526084820188905260a4820187905285811660c483015260e482018590527f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d169063e8e3370090610104016060604051808303816000875af1158015611489573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ad9190611e5b565b50506040516370a0823160e01b81523060048201528391506001600160a01b038c16906370a0823190602401602060405180830381865afa1580156114f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061151a9190611c6d565b11156115ab576040516370a0823160e01b81523060048201526115ab90859084906001600160a01b038e16906370a0823190602401602060405180830381865afa15801561156c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115909190611c6d565b61159a9190611d3a565b6001600160a01b038d1691906117a9565b6040516370a0823160e01b815230600482015281906001600160a01b038b16906370a0823190602401602060405180830381865afa1580156115f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116159190611c6d565b11156116a6576040516370a0823160e01b81523060048201526116a690859083906001600160a01b038d16906370a0823190602401602060405180830381865afa158015611667573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061168b9190611c6d565b6116959190611d3a565b6001600160a01b038c1691906117a9565b50505050505050505050565b6040516001600160a01b0384811660248301528381166044830152606482018390526117199186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506117df565b50505050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa15801561176f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117939190611c6d565b905061171984846117a48585611e89565b611850565b6040516001600160a01b038381166024830152604482018390526117da91859182169063a9059cbb906064016116e7565b505050565b600080602060008451602086016000885af180611802576040513d6000823e3d81fd5b50506000513d9150811561181a578060011415611827565b6001600160a01b0384163b155b1561171957604051635274afe760e01b81526001600160a01b03851660048201526024016102e5565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526118a184826118e0565b611719576040516001600160a01b038481166024830152600060448301526118d691869182169063095ea7b3906064016116e7565b61171984826117df565b6000806000806020600086516020880160008a5af192503d91506000519050828015611925575081156119165780600114611925565b6000866001600160a01b03163b115b9695505050505050565b6001600160a01b038116811461194457600080fd5b50565b60008060006060848603121561195c57600080fd5b83356119678161192f565b925060208401356119778161192f565b91506040840135600281900b811461198e57600080fd5b809150509250925092565b6000602082840312156119ab57600080fd5b81356119b68161192f565b9392505050565b600080600080600060a086880312156119d557600080fd5b85356119e08161192f565b945060208601356119f08161192f565b935060408601359250606086013591506080860135611a0e8161192f565b809150509295509295909350565b803562ffffff81168114611a2f57600080fd5b919050565b60008060008060008060c08789031215611a4d57600080fd5b8635611a588161192f565b95506020870135611a688161192f565b9450611a7660408801611a1c565b9350606087013592506080870135915060a0870135611a948161192f565b809150509295509295509295565b60008060408385031215611ab557600080fd5b8235611ac08161192f565b91506020830135611ad08161192f565b809150509250929050565b600080600080600080600060e0888a031215611af657600080fd5b8735611b018161192f565b96506020880135611b118161192f565b955060408801359450606088013593506080880135925060a0880135611b368161192f565b96999598509396929591949193505060c09091013590565b600080600060608486031215611b6357600080fd5b8335611b6e8161192f565b92506020840135611b7e8161192f565b9150611b8c60408501611a1c565b90509250925092565b600080600080600080600080610100898b031215611bb257600080fd5b8835611bbd8161192f565b97506020890135611bcd8161192f565b965060408901359550606089013594506080890135935060a0890135925060c0890135611bf98161192f565b979a969950949793969295919450919260e001359150565b80516001600160701b0381168114611a2f57600080fd5b600080600060608486031215611c3d57600080fd5b611c4684611c11565b9250611c5460208501611c11565b9150604084015163ffffffff8116811461198e57600080fd5b600060208284031215611c7f57600080fd5b5051919050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600060a0820187835286602084015260a0604084015280865180835260c08501915060208801925060005b81811015611d045783516001600160a01b0316835260209384019390920191600101611cdd565b50506001600160a01b039590951660608401525050608001529392505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610c6e57610c6e611d24565b600060208284031215611d5f57600080fd5b815167ffffffffffffffff811115611d7657600080fd5b8201601f81018413611d8757600080fd5b805167ffffffffffffffff811115611da157611da1611c86565b8060051b604051601f19603f830116810181811067ffffffffffffffff82111715611dce57611dce611c86565b604052918252602081840181019290810187841115611dec57600080fd5b6020850194505b83851015611e0f57845180825260209586019590935001611df3565b509695505050505050565b600060208284031215611e2c57600080fd5b81516119b68161192f565b60008060408385031215611e4a57600080fd5b505080516020909101519092909150565b600080600060608486031215611e7057600080fd5b5050815160208301516040909301519094929350919050565b80820180821115610c6e57610c6e611d2456fea264697066735822122042f4e8e5a538d6b34ff63809c6454c07d6e1eaae7b341ba4db004fafc83a2e8864736f6c634300081c0033
Verified Source Code Full Match
Compiler: v0.8.28+commit.7893614a
EVM: paris
Optimization: Yes (200 runs)
UniswapDexAdapter.sol 187 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.28;
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@uniswap/v3-periphery/contracts/interfaces/IPeripheryImmutableState.sol";
import "../interfaces/IDexAdapter.sol";
import "../interfaces/ISwapRouter02.sol";
import "../interfaces/IUniswapV2Factory.sol";
import "../interfaces/IUniswapV2Pair.sol";
import "../interfaces/IUniswapV2Router02.sol";
import "../interfaces/IV3TwapUtilities.sol";
contract UniswapDexAdapter is IDexAdapter, Context {
using SafeERC20 for IERC20;
IV3TwapUtilities public immutable V3_TWAP_UTILS;
address public immutable override V2_ROUTER;
address public immutable override V3_ROUTER;
bool public immutable override ASYNC_INITIALIZE;
constructor(IV3TwapUtilities _v3TwapUtilities, address _v2Router, address _v3Router, bool _asyncInit) {
V3_TWAP_UTILS = _v3TwapUtilities;
V2_ROUTER = _v2Router;
V3_ROUTER = _v3Router;
ASYNC_INITIALIZE = _asyncInit;
}
function WETH() external view virtual override returns (address) {
return IUniswapV2Router02(V2_ROUTER).WETH();
}
function getV3Pool(address, address, int24) external view virtual override returns (address _p) {
_p;
require(false, "I0");
}
function getV3Pool(address _token0, address _token1, uint24 _poolFee)
external
view
virtual
override
returns (address)
{
return V3_TWAP_UTILS.getV3Pool(IPeripheryImmutableState(V3_ROUTER).factory(), _token0, _token1, _poolFee);
}
function getV2Pool(address _token0, address _token1) external view virtual override returns (address) {
return IUniswapV2Factory(IUniswapV2Router02(V2_ROUTER).factory()).getPair(_token0, _token1);
}
function getReserves(address _pool) external view virtual override returns (uint112 _reserve0, uint112 _reserve1) {
(_reserve0, _reserve1,) = IUniswapV2Pair(_pool).getReserves();
}
function createV2Pool(address _token0, address _token1) external virtual override returns (address) {
return IUniswapV2Factory(IUniswapV2Router02(V2_ROUTER).factory()).createPair(_token0, _token1);
}
function swapV2Single(
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
uint256 _amountOutMin,
address _recipient
) external virtual override returns (uint256 _amountOut) {
uint256 _outBefore = IERC20(_tokenOut).balanceOf(_recipient);
if (_amountIn == 0) {
_amountIn = IERC20(_tokenIn).balanceOf(address(this));
} else {
IERC20(_tokenIn).safeTransferFrom(_msgSender(), address(this), _amountIn);
}
address[] memory _path = new address[](2);
_path[0] = _tokenIn;
_path[1] = _tokenOut;
IERC20(_tokenIn).safeIncreaseAllowance(V2_ROUTER, _amountIn);
IUniswapV2Router02(V2_ROUTER).swapExactTokensForTokensSupportingFeeOnTransferTokens(
_amountIn, _amountOutMin, _path, _recipient, block.timestamp
);
return IERC20(_tokenOut).balanceOf(_recipient) - _outBefore;
}
function swapV2SingleExactOut(
address _tokenIn,
address _tokenOut,
uint256 _amountInMax,
uint256 _amountOut,
address _recipient
) external virtual override returns (uint256 _amountInUsed) {
uint256 _inBefore = IERC20(_tokenIn).balanceOf(address(this));
if (_amountInMax == 0) {
_amountInMax = IERC20(_tokenIn).balanceOf(address(this));
} else {
IERC20(_tokenIn).safeTransferFrom(_msgSender(), address(this), _amountInMax);
}
address[] memory _path = new address[](2);
_path[0] = _tokenIn;
_path[1] = _tokenOut;
IERC20(_tokenIn).safeIncreaseAllowance(V2_ROUTER, _amountInMax);
IUniswapV2Router02(V2_ROUTER).swapTokensForExactTokens(
_amountOut, _amountInMax, _path, _recipient, block.timestamp
);
uint256 _inRemaining = IERC20(_tokenIn).balanceOf(address(this)) - _inBefore;
if (_inRemaining > 0) {
IERC20(_tokenIn).safeTransfer(_msgSender(), _inRemaining);
}
_amountInUsed = _amountInMax - _inRemaining;
}
function swapV3Single(
address _tokenIn,
address _tokenOut,
uint24 _fee,
uint256 _amountIn,
uint256 _amountOutMin,
address _recipient
) external virtual override returns (uint256 _amountOut) {
uint256 _outBefore = IERC20(_tokenOut).balanceOf(_recipient);
if (_amountIn == 0) {
_amountIn = IERC20(_tokenIn).balanceOf(address(this));
} else {
IERC20(_tokenIn).safeTransferFrom(_msgSender(), address(this), _amountIn);
}
IERC20(_tokenIn).safeIncreaseAllowance(V3_ROUTER, _amountIn);
ISwapRouter02(V3_ROUTER).exactInputSingle(
ISwapRouter02.ExactInputSingleParams({
tokenIn: _tokenIn,
tokenOut: _tokenOut,
fee: _fee,
recipient: _recipient,
amountIn: _amountIn,
amountOutMinimum: _amountOutMin,
sqrtPriceLimitX96: 0
})
);
return IERC20(_tokenOut).balanceOf(_recipient) - _outBefore;
}
function addLiquidity(
address _tokenA,
address _tokenB,
uint256 _amountADesired,
uint256 _amountBDesired,
uint256 _amountAMin,
uint256 _amountBMin,
address _to,
uint256 _deadline
) external virtual override {
uint256 _aBefore = IERC20(_tokenA).balanceOf(address(this));
uint256 _bBefore = IERC20(_tokenB).balanceOf(address(this));
IERC20(_tokenA).safeTransferFrom(_msgSender(), address(this), _amountADesired);
IERC20(_tokenB).safeTransferFrom(_msgSender(), address(this), _amountBDesired);
IERC20(_tokenA).safeIncreaseAllowance(V2_ROUTER, _amountADesired);
IERC20(_tokenB).safeIncreaseAllowance(V2_ROUTER, _amountBDesired);
IUniswapV2Router02(V2_ROUTER).addLiquidity(
_tokenA, _tokenB, _amountADesired, _amountBDesired, _amountAMin, _amountBMin, _to, _deadline
);
if (IERC20(_tokenA).balanceOf(address(this)) > _aBefore) {
IERC20(_tokenA).safeTransfer(_to, IERC20(_tokenA).balanceOf(address(this)) - _aBefore);
}
if (IERC20(_tokenB).balanceOf(address(this)) > _bBefore) {
IERC20(_tokenB).safeTransfer(_to, IERC20(_tokenB).balanceOf(address(this)) - _bBefore);
}
}
function removeLiquidity(
address _tokenA,
address _tokenB,
uint256 _liquidity,
uint256 _amountAMin,
uint256 _amountBMin,
address _to,
uint256 _deadline
) external virtual override {
address _pool = IUniswapV2Factory(IUniswapV2Router02(V2_ROUTER).factory()).getPair(_tokenA, _tokenB);
uint256 _lpBefore = IERC20(_pool).balanceOf(address(this));
IERC20(_pool).safeTransferFrom(_msgSender(), address(this), _liquidity);
IERC20(_pool).safeIncreaseAllowance(V2_ROUTER, _liquidity);
IUniswapV2Router02(V2_ROUTER).removeLiquidity(
_tokenA, _tokenB, _liquidity, _amountAMin, _amountBMin, _to, _deadline
);
if (IERC20(_pool).balanceOf(address(this)) > _lpBefore) {
IERC20(_pool).safeTransfer(_to, IERC20(_pool).balanceOf(address(this)) - _lpBefore);
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SafeERC20.sol 198 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
IPeripheryImmutableState.sol 12 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Immutable state
/// @notice Functions that return immutable state of the router
interface IPeripheryImmutableState {
/// @return Returns the address of the Uniswap V3 factory
function factory() external view returns (address);
/// @return Returns the address of WETH9
function WETH9() external view returns (address);
}
IDexAdapter.sol 68 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IDexAdapter {
function ASYNC_INITIALIZE() external view returns (bool);
function V2_ROUTER() external view returns (address);
function V3_ROUTER() external view returns (address);
function WETH() external view returns (address);
function getV3Pool(address _token0, address _token1, int24 _tickSpacing) external view returns (address _pool);
function getV3Pool(address _token0, address _token1, uint24 _poolFee) external view returns (address _pool);
function getV2Pool(address _token0, address _token1) external view returns (address _pool);
function createV2Pool(address _token0, address _token1) external returns (address _pool);
function getReserves(address _pool) external view returns (uint112, uint112);
function swapV2Single(
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
uint256 _amountOutMin,
address _recipient
) external returns (uint256 _amountOut);
function swapV2SingleExactOut(
address _tokenIn,
address _tokenOut,
uint256 _amountInMax,
uint256 _amountOut,
address _recipient
) external returns (uint256 _amountInUsed);
function swapV3Single(
address _tokenIn,
address _tokenOut,
uint24 _fee,
uint256 _amountIn,
uint256 _amountOutMin,
address _recipient
) external returns (uint256 _amountOut);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external;
function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external;
}
ISwapRouter02.sol 25 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.28;
interface ISwapRouter02 {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 amountIn;
uint256 amountOutMinimum;
}
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
}
IUniswapV2Factory.sol 8 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
function getPair(address tokenA, address tokenB) external view returns (address pair);
}
IUniswapV2Pair.sol 10 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IUniswapV2Pair {
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
}
IUniswapV2Router02.sol 50 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IUniswapV2Router02 {
function factory() external view returns (address);
function WETH() external view returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);
function swapETHForExactTokens(uint256 amountOut, address[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
}
IV3TwapUtilities.sol 27 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IV3TwapUtilities {
function getV3Pool(address v3Factory, address token0, address token1) external view returns (address);
function getV3Pool(address v3Factory, address token0, address token1, uint24 poolFee)
external
view
returns (address);
function getV3Pool(address v3Factory, address token0, address token1, int24 tickSpacing)
external
view
returns (address);
function getPoolPriceUSDX96(address pricePool, address nativeStablePool, address WETH9)
external
view
returns (uint256);
function sqrtPriceX96FromPoolAndInterval(address pool) external view returns (uint160);
function sqrtPriceX96FromPoolAndPassedInterval(address pool, uint32 interval) external view returns (uint160);
function priceX96FromSqrtPriceX96(uint160 sqrtPriceX96) external pure returns (uint256);
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Read Contract
ASYNC_INITIALIZE 0xc3749ae5 → bool
V2_ROUTER 0x8ada032e → address
V3_ROUTER 0xa1119856 → address
V3_TWAP_UTILS 0xf191c16a → address
WETH 0xad5c4648 → address
getReserves 0x3e99c1e4 → uint112, uint112
getV2Pool 0x9f4f9745 → address
getV3Pool 0x0a8e060f → address
getV3Pool 0xe3ddd779 → address
Write Contract 6 functions
These functions modify contract state and require a wallet transaction to execute.
addLiquidity 0xe8e33700
address _tokenA
address _tokenB
uint256 _amountADesired
uint256 _amountBDesired
uint256 _amountAMin
uint256 _amountBMin
address _to
uint256 _deadline
createV2Pool 0xc4f3e9d7
address _token0
address _token1
returns: address
removeLiquidity 0xbaa2abde
address _tokenA
address _tokenB
uint256 _liquidity
uint256 _amountAMin
uint256 _amountBMin
address _to
uint256 _deadline
swapV2Single 0x83e4b89f
address _tokenIn
address _tokenOut
uint256 _amountIn
uint256 _amountOutMin
address _recipient
returns: uint256
swapV2SingleExactOut 0x9a8fadee
address _tokenIn
address _tokenOut
uint256 _amountInMax
uint256 _amountOut
address _recipient
returns: uint256
swapV3Single 0x8d5752d6
address _tokenIn
address _tokenOut
uint24 _fee
uint256 _amountIn
uint256 _amountOutMin
address _recipient
returns: uint256
Recent Transactions
No transactions found for this address