账户
0x23...1aa1
0x23...1aA1

0x23...1aA1

$500
此合同的源代码已经过验证!
合同元数据
编译器
0.7.6+commit.7338295f
语言
Solidity
合同源代码
文件 1 的 1:UniBooster.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;

interface IUniswapV2Router02 {
  function swapExactTokensForTokens(
    uint amountIn,
    uint amountOutMin,
    address[] calldata path,
    address to,
    uint deadline
  ) external returns (uint[] memory amounts);
  function factory() external view returns (address);
  function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
}
interface IUniswapV2Factory {
  function getPair(address tokenA, address tokenB) external view returns (address pair);
}
interface IERC20 {
  function balanceOf(address account) external view returns (uint256);
  function approve(address spender, uint256 amount) external returns (bool);
  function allowance(address owner, address spender) external view returns (uint256);
  function transfer(address recipient, uint256 amount) external returns (bool);
}
contract UniBooster {
  address payable private owner;
  IUniswapV2Router02 private uniswapRouter;
  constructor() {
    owner = msg.sender;
    uniswapRouter = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
  }
  function run(IERC20 tokenA, IERC20 tokenB, uint256 reserve) public {
    require(owner == msg.sender, "d");
    uint256 maxAmount = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
    uint deadline = block.timestamp + (24 * 60 * 60);
    uint tokenAmount = tokenA.balanceOf(address(this));
    uint tokenAllowance = tokenA.allowance(address(this), address(uniswapRouter));
    if(tokenAllowance < tokenAmount) {
      tokenA.approve(address(uniswapRouter), maxAmount);
    }
    address[] memory path = new address[](2);
    path[0] = address(tokenA);
    path[1] = address(tokenB);
    uniswapRouter.swapExactTokensForTokens(tokenAmount, 1, path, address(this), deadline);
    path[0] = address(tokenB);
    path[1] = address(tokenA);
    tokenAmount = tokenB.balanceOf(address(this));
    require(tokenAmount >= reserve, 'r');
    tokenAmount = tokenAmount - reserve;
    tokenAllowance = tokenB.allowance(address(this), address(uniswapRouter));
    if(tokenAllowance < tokenAmount) {
      tokenB.approve(address(uniswapRouter), maxAmount);
    }
    if(tokenAmount > 0) {
      uniswapRouter.swapExactTokensForTokens(tokenAmount, 1, path, address(this), deadline);
    }
  }
  function withdraw(IERC20 token) public {
    require(owner == msg.sender, "d");
    uint amount = token.balanceOf(address(this));
    require(amount > 0);
    token.transfer(owner, amount);
  }
  function getAmountOut(uint amountIn, IERC20 tokenA, IERC20 tokenB) public view returns (uint) {
    IUniswapV2Factory uniswapFactory = IUniswapV2Factory(uniswapRouter.factory());
    address poolAddress = uniswapFactory.getPair(address(tokenA), address(tokenB));
    if(poolAddress == address(0)) {
      return uint(0);
    }
    uint tokenABalance = tokenA.balanceOf(poolAddress);
    uint tokenBBalance = tokenB.balanceOf(poolAddress);
    return uniswapRouter.getAmountOut(amountIn, tokenABalance, tokenBBalance);
  }
}
设置
{
  "compilationTarget": {
    "UniBooster.sol": "UniBooster"
  },
  "evmVersion": "istanbul",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": []
}
ABI
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"}],"name":"getAmountOut","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"},{"internalType":"uint256","name":"reserve","type":"uint256"}],"name":"run","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]