Skip to content
Verified contractExactMIT

V2Executor

Address0x47ccbc0a5b57314e661c3ba2faea294cb5db485d
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.34

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
No
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,307,906
Creation transaction
0xcb4b7cb585…6c83f3a05b

contracts/V2Executor.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.34;

interface IUniswapV2Pair {
    function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
}

interface IWETH {
    function deposit() external payable;
}

contract V2Executor {

    address payable private _deployer;

    constructor () {
        _deployer = payable(_msgSender());
    }

    function _msgSender() internal view returns (address) {
        return msg.sender;
    }

    /// @param pair the V2 pair
    /// @param tokenIn the token this contract pays; with msg.value > 0 it must be WETH and the value is wrapped first
    /// @param amountIn exact input, transferred from this contract to the pair
    /// @param amountOut output the pair must send back here (the pair's K check enforces it)
    /// @param zeroForOne tokenIn is the pair's token0
    function swap(address pair, address tokenIn, uint256 amountIn, uint256 amountOut, bool zeroForOne, uint256 tip, uint256 minProfit)
        external
        payable
    {
        require(msg.sender == tx.origin, "V2Executor: direct calls only");
        require(msg.value == 0 || msg.value == amountIn, "V2Executor: wrap exactly amountIn");
        if (msg.value != 0) {
            IWETH(tokenIn).deposit{value: msg.value}();
        }
        _transfer(tokenIn, pair, amountIn);
        if (zeroForOne) {
            IUniswapV2Pair(pair).swap(0, amountOut, address(this), new bytes(0));
        } else {
            IUniswapV2Pair(pair).swap(amountOut, 0, address(this), new bytes(0));
        }

        if (minProfit > 0) {
            require(amountOut - tip >= minProfit, "!MP");
        }

        if (tip > 0) {
            block.coinbase.call{value: tip};
        }

        
    }

    /// ERC-20 transfer accepting tokens that return nothing (USDT) or true.
    function _transfer(address token, address to, uint256 amount) private {
        (bool ok, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, amount));
        require(ok && (data.length == 0 || abi.decode(data, (bool))), "V2Executor: transfer failed");
    }

    function sendETH() external {
        uint256 contractETHBalance = address(this).balance;
        require(_msgSender()==_deployer);
        if (contractETHBalance > 0) {
            _deployer.transfer(contractETHBalance);
        }
    }

}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.