账户
0xc7...7498
0xC7...7498

0xC7...7498

US$0.00
此合同的源代码已经过验证!
合同元数据
编译器
0.6.6+commit.6c089d02
语言
Solidity
合同源代码
文件 1 的 3:SafeMath.sol
pragma solidity >=0.6.6;

// SPDX-License-Identifier: MIT

library SafeMath {

    function add(uint a, uint b) internal pure returns (uint c) {
        c = a + b;
        require(c >= a);
        return c;
    }

    function sub(uint a, uint b) internal pure returns (uint c) {
        require(b <= a);
        c = a - b;
        return c;
    }

    function mul(uint a, uint b) internal pure returns (uint c) {
        c = a * b;
        require(a == 0 || c / a == b);
        return c;
    }

    function div(uint a, uint b) internal pure returns (uint c) {
        require(b > 0);
        c = a / b;
        return c;
    }

}
合同源代码
文件 2 的 3:keeparb.sol
pragma solidity >=0.6.6;
pragma experimental ABIEncoderV2;

import './lib/SafeMath.sol';
import './interfaces/v3pool.sol';



interface IERC20 {
    function balanceOf(address owner) external view returns (uint);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function approve(address spender, uint value) external returns (bool);
}

interface IWETH{
    function deposit() external payable;
    function withdraw(uint wad) external;
}


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


interface vendingmachine{
    function conversionToT(uint256 amount)
        external
        returns (uint256 tAmount, uint256 wrappedRemainder);

    function conversionFromT(uint256 amount)
        external
        returns (uint256 wrappedAmount, uint256 tRemainder);

    function wrap(uint256 amount) external;

    function unwrap(uint256 amount) external;

}



interface v3quoter{
  function quoteExactInputSingle(
        address tokenIn,
        address tokenOut,
        uint24 fee,
        uint256 amountIn,
        uint160 sqrtPriceLimitX96
    ) external returns (uint256 amountOut);
}


interface curvepool{
    function get_dy(uint256 i , uint256 j, uint256 dx) external view returns (uint256 dy);
    function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy) external payable returns (uint256 dy);
}



contract keeptarb {
    using SafeMath for uint;
    
    address payable public owner;
    
    address quoter_addr = address(0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6);
    
    v3quoter quoter = v3quoter(quoter_addr);


    constructor() public {
        owner = msg.sender;

        // approve keep and t for the vendingmachine
        IERC20(address(0x85Eee30c52B0b379b046Fb0F85F4f3Dc3009aFEC)).approve(address(0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        IERC20(address(0xCdF7028ceAB81fA0C6971208e83fa7872994beE5)).approve(address(0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);

        // approve t for the curve 

        IERC20(address(0xCdF7028ceAB81fA0C6971208e83fa7872994beE5)).approve(address(0x752eBeb79963cf0732E9c0fec72a49FD1DEfAEAC), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);

        IERC20(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)).approve(address(0x752eBeb79963cf0732E9c0fec72a49FD1DEfAEAC), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);

    }
    
    modifier onlyowner{
        require(msg.sender == owner);
        _;
    }



    receive() external payable {}


    function deposit() payable external{
    }


    function _safeTransfer(address token, address to, uint value) private {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(bytes4(keccak256(bytes('transfer(address,uint256)'))), to, value));
    }
    
    function withdrawtoken(address tokenaddr, uint amount) external onlyowner{
        _safeTransfer(tokenaddr, owner, amount);
    }
    

    function withdrawethamount(uint amount) external onlyowner {
        msg.sender.transfer(amount);
    }

    function approvetoken(address token, address target) external onlyowner{
        IERC20(token).approve(target, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
    }






    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata _data
    ) external {
        (uint256 flag) = abi.decode(_data, (uint256));
        
        if(flag == 0){
            // selling T
            _safeTransfer(0xCdF7028ceAB81fA0C6971208e83fa7872994beE5, msg.sender, uint256(amount1Delta));

        }else{
            // unwrap T
            vendingmachine(address(0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0)).unwrap(uint256(-amount1Delta));

            _safeTransfer(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2), msg.sender, uint256(amount0Delta));

       }

    }





    function uniswapV2Call(address _sender, uint _amount0, uint _amount1, bytes calldata _data) external {
    
        (uint256 sellpath, bool direct, uint256 bestin, uint256 v2out, uint256 v3amount)  = abi.decode(_data, (uint256, bool, uint256, uint256, uint256));


        if(sellpath == 0){
            // sell on v3
            if(direct){

                // wrap keep to T
                vendingmachine(address(0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0)).wrap(v2out);

                // sell T on v3, v3amount is the T in
                v3pool(address(0x286EB8405231A2201FCb75b6e33098A546216C86)).swap(address(this), false, int256(v3amount), 1461446703485210103287273052203988822378723970342 - 1, abi.encode(0));

                // send back weth
                _safeTransfer(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2), msg.sender, bestin);


            }else{

                // buy t on v3 and unwrap to keep
                v3pool(address(0x286EB8405231A2201FCb75b6e33098A546216C86)).swap(address(this), true, int256(bestin), 4295128739 + 1, abi.encode(1));

                _safeTransfer(address(0x85Eee30c52B0b379b046Fb0F85F4f3Dc3009aFEC), msg.sender, v3amount);


            }

        }

        if(sellpath == 1){
            if(direct){
                // wrap keep to T
                vendingmachine(address(0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0)).wrap(v2out);

                // sell T on curve
                curvepool(address(0x752eBeb79963cf0732E9c0fec72a49FD1DEfAEAC)).exchange(1, 0 , v3amount, 0);

                _safeTransfer(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2), msg.sender, bestin);

            }else{

                // IWETH(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)).withdraw(bestin);

                uint256 tamount = curvepool(address(0x752eBeb79963cf0732E9c0fec72a49FD1DEfAEAC)).exchange(0, 1 , bestin, 0);

                // unwrap t
                vendingmachine(address(0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0)).unwrap(tamount);

                // pay back keep
                _safeTransfer(address(0x85Eee30c52B0b379b046Fb0F85F4f3Dc3009aFEC), msg.sender, v3amount);


            }

        }

    }



    function keepv3arb(bool direct, uint256 bestin, uint256 v2out, uint256 amount) public payable{

        require(block.number <= msg.value, "fuck");

        uint256 gasstart = gasleft();

        if(direct){
            // weth -> keep -> t -> weth(v3), amount is the T into v3 pool
            bytes memory data = abi.encode(0, direct, bestin, v2out, amount);
            v2pool(address(0xE6f19dAb7d43317344282F803f8E8d240708174a)).swap(v2out, 0, address(this), data);

        }else{
            // weth -> t(v3) -> keep -> weth, the amount is used for the keep we repay
            bytes memory data = abi.encode(0, direct, bestin, 0, amount);
            v2pool(address(0xE6f19dAb7d43317344282F803f8E8d240708174a)).swap(0, v2out, address(this), data);

        }


        uint256 weth_balance = IERC20(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)).balanceOf(address(this));

        require(weth_balance > tx.gasprice * (gasstart - gasleft()), "i");
        
        IERC20(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)).transfer(msg.sender, weth_balance - 1);


    }




    function keepcurvearb(bool direct, uint256 bestin, uint256 v2out, uint256 amount) public payable{

        require(block.number <= msg.value, "fuck");

        uint256 gasstart = gasleft();

        if(direct){
            // weth -> keep -> t -> eth(curve), amount is the T into v3 pool
            bytes memory data = abi.encode(1, direct, bestin, v2out, amount);
            v2pool(address(0xE6f19dAb7d43317344282F803f8E8d240708174a)).swap(v2out, 0, address(this), data);

        }else{
            // weth -> t(v3) -> keep -> weth, the amount is used for the keep we repay
            bytes memory data = abi.encode(1, direct, bestin, 0, amount);
            v2pool(address(0xE6f19dAb7d43317344282F803f8E8d240708174a)).swap(0, v2out, address(this), data);

        }


        uint256 weth_balance = IERC20(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)).balanceOf(address(this));

        require(weth_balance > tx.gasprice * (gasstart - gasleft()), "i");
        
        IERC20(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)).transfer(msg.sender, weth_balance - 1);


    }





    function v3out(address tokenIn, address tokenOut, uint24 fee, uint256 amountIn) private returns (uint256 amountOut) {
        amountOut = quoter.quoteExactInputSingle(tokenIn, tokenOut, fee, amountIn, 0);
    }


    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
        uint amountInWithFee = amountIn.mul(997);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    } 
  

    function detectarbv3(uint256 lowerbound, uint256 higherbound , uint256 step) public returns(uint256 bestin, uint256 bestprofit, uint256 best_keep_out, uint256 tout, uint256 bestin2, uint256 bestprofit2, uint256 bestv2wethout, uint256 keeprepay){
        bytes memory returnData;
        (, returnData) = address(0xE6f19dAb7d43317344282F803f8E8d240708174a).staticcall(abi.encodeWithSelector(0x0902f1ac));
        (uint r0, uint r1, ) = abi.decode(returnData, (uint,uint,uint)); // gohm fdt


        uint256 weth_in = lowerbound;

        while(weth_in < higherbound){

            uint256 keep_out = getAmountOut(weth_in, r1, r0);

            (uint256 t_out, ) = vendingmachine(address(0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0)).conversionToT(keep_out);

            uint256 v3_weth_out = v3out(address(0xCdF7028ceAB81fA0C6971208e83fa7872994beE5), address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2), 10000, t_out);


            if(v3_weth_out <  weth_in){
                break;
            }

            if(v3_weth_out - weth_in < bestprofit){
                break;
            }else{
                bestprofit = v3_weth_out - weth_in;
                bestin = weth_in;
                tout = t_out;
                best_keep_out = keep_out;
                weth_in = weth_in + step;
            }
        }


        weth_in = lowerbound;


        while(weth_in < higherbound){

            uint256 t_out = v3out(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2), address(0xCdF7028ceAB81fA0C6971208e83fa7872994beE5), 10000, weth_in);

            (uint256 keep_out, ) = vendingmachine(address(0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0)).conversionFromT(t_out);


            uint256 v2_weth_out = getAmountOut(keep_out, r0, r1);


            if(v2_weth_out < weth_in){
                break;
            }

            if(v2_weth_out - weth_in < bestprofit2){
                break;
            }else{
                bestprofit2 = v2_weth_out - weth_in;
                bestin2 = weth_in;
                bestv2wethout = v2_weth_out;
                keeprepay = keep_out;
                weth_in = weth_in + step;
            }
        }



    }






    function detectarbcurve(uint256 lowerbound, uint256 higherbound , uint256 step) public returns(uint256 bestin, uint256 bestprofit, uint256 best_keep_out, uint256 tout, uint256 bestin2, uint256 bestprofit2, uint256 bestv2wethout, uint256 keeprepay){
        bytes memory returnData;
        (, returnData) = address(0xE6f19dAb7d43317344282F803f8E8d240708174a).staticcall(abi.encodeWithSelector(0x0902f1ac));
        (uint r0, uint r1, ) = abi.decode(returnData, (uint,uint,uint)); // gohm fdt


        uint256 weth_in = lowerbound;

        while(weth_in < higherbound){

            uint256 keep_out = getAmountOut(weth_in, r1, r0);

            (uint256 t_out, ) = vendingmachine(address(0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0)).conversionToT(keep_out);


            uint256 curve_eth_out = curvepool(address(0x752eBeb79963cf0732E9c0fec72a49FD1DEfAEAC)).get_dy(1, 0 , t_out);


            if(curve_eth_out <  weth_in){
                break;
            }

            if(curve_eth_out - weth_in < bestprofit){
                break;
            }else{
                bestprofit = curve_eth_out - weth_in;
                bestin = weth_in;
                tout = t_out;
                best_keep_out = keep_out;
                weth_in = weth_in + step;
            }
        }


        weth_in = lowerbound;


        while(weth_in < higherbound){

            uint256 t_out = curvepool(address(0x752eBeb79963cf0732E9c0fec72a49FD1DEfAEAC)).get_dy(0, 1 , weth_in);

            (uint256 keep_out, ) = vendingmachine(address(0xE47c80e8c23f6B4A1aE41c34837a0599D5D16bb0)).conversionFromT(t_out);


            uint256 v2_weth_out = getAmountOut(keep_out, r0, r1);


            if(v2_weth_out < weth_in){
                break;
            }

            if(v2_weth_out - weth_in < bestprofit2){
                break;
            }else{
                bestprofit2 = v2_weth_out - weth_in;
                bestin2 = weth_in;
                bestv2wethout = v2_weth_out;
                keeprepay = keep_out;
                weth_in = weth_in + step;
            }
        }



    }




}
合同源代码
文件 3 的 3:v3pool.sol
pragma solidity =0.6.6;
pragma experimental ABIEncoderV2;

interface v3pool {
  function swap(address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data) external payable returns (int256 amount0, int256 amount1);

    function token0() external view returns (address);

    function token1() external view returns (address);
    
    function fee() external view returns (uint24);

}
设置
{
  "compilationTarget": {
    "contracts/keeparb.sol": "keeptarb"
  },
  "evmVersion": "istanbul",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": []
}
ABI
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"target","type":"address"}],"name":"approvetoken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lowerbound","type":"uint256"},{"internalType":"uint256","name":"higherbound","type":"uint256"},{"internalType":"uint256","name":"step","type":"uint256"}],"name":"detectarbcurve","outputs":[{"internalType":"uint256","name":"bestin","type":"uint256"},{"internalType":"uint256","name":"bestprofit","type":"uint256"},{"internalType":"uint256","name":"best_keep_out","type":"uint256"},{"internalType":"uint256","name":"tout","type":"uint256"},{"internalType":"uint256","name":"bestin2","type":"uint256"},{"internalType":"uint256","name":"bestprofit2","type":"uint256"},{"internalType":"uint256","name":"bestv2wethout","type":"uint256"},{"internalType":"uint256","name":"keeprepay","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lowerbound","type":"uint256"},{"internalType":"uint256","name":"higherbound","type":"uint256"},{"internalType":"uint256","name":"step","type":"uint256"}],"name":"detectarbv3","outputs":[{"internalType":"uint256","name":"bestin","type":"uint256"},{"internalType":"uint256","name":"bestprofit","type":"uint256"},{"internalType":"uint256","name":"best_keep_out","type":"uint256"},{"internalType":"uint256","name":"tout","type":"uint256"},{"internalType":"uint256","name":"bestin2","type":"uint256"},{"internalType":"uint256","name":"bestprofit2","type":"uint256"},{"internalType":"uint256","name":"bestv2wethout","type":"uint256"},{"internalType":"uint256","name":"keeprepay","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"direct","type":"bool"},{"internalType":"uint256","name":"bestin","type":"uint256"},{"internalType":"uint256","name":"v2out","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"keepcurvearb","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bool","name":"direct","type":"bool"},{"internalType":"uint256","name":"bestin","type":"uint256"},{"internalType":"uint256","name":"v2out","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"keepv3arb","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_sender","type":"address"},{"internalType":"uint256","name":"_amount0","type":"uint256"},{"internalType":"uint256","name":"_amount1","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"uniswapV2Call","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawethamount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenaddr","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawtoken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]