文件 3 的 6:IUniswapV2Router01.sol
文件 4 的 6:IUniswapV2Router02.sol
文件 6 的 6:uniswapbuyer2.sol
pragma solidity >0.6.0 <0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
import 'https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router02.sol';
contract UniswapBuyer is Ownable {
uint public weiAmount;
uint public amountOutMin;
address public constant weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
mapping(address => bool) public whiteList;
IUniswapV2Router02 private constant router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
constructor(uint weiAmount_, uint amountOutMin_) Ownable() payable public {
weiAmount = weiAmount_;
amountOutMin = amountOutMin_;
}
receive() external payable {}
function setWhiteList(address[] memory whitelistAddressList_) public onlyOwner {
for (uint i=0; i<whitelistAddressList_.length; i++) {
whiteList[whitelistAddressList_[i]] = true;
}
}
function setWeiAmount(uint weiAmount_) public onlyOwner {
weiAmount = weiAmount_;
}
function setAmountOutMin(uint amountOutMin_) public onlyOwner {
amountOutMin = amountOutMin_;
}
function withdrawEther() public onlyOwner {
msg.sender.transfer(address(this).balance);
}
function withdrawToken(address tokenAddress_) public onlyOwner {
IERC20 tokenContract = IERC20(tokenAddress_);
uint tokenAmount = tokenContract.balanceOf(address(this));
tokenContract.transfer(owner(), tokenAmount);
}
function snipe(address tokenAddress_) public {
require(whiteList[msg.sender], 'Sender is not whitelisted');
address[] memory path = new address[](2);
path[0] = address(weth);
path[1] = address(tokenAddress_);
router.swapExactETHForTokens{value : weiAmount}(amountOutMin, path, owner(), block.timestamp);
}
}
{
"compilationTarget": {
"browser/uniswapbuyer2.sol": "UniswapBuyer"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"uint256","name":"weiAmount_","type":"uint256"},{"internalType":"uint256","name":"amountOutMin_","type":"uint256"}],"stateMutability":"payable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"amountOutMin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOutMin_","type":"uint256"}],"name":"setAmountOutMin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"weiAmount_","type":"uint256"}],"name":"setWeiAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"whitelistAddressList_","type":"address[]"}],"name":"setWhiteList","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress_","type":"address"}],"name":"snipe","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"weiAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whiteList","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawEther","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress_","type":"address"}],"name":"withdrawToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]