文件 1 的 1:MyContract.sol
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
}
library TransferHelper {
function safeApprove(address token, address to, uint value) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
}
function safeTransfer(address token, address to, uint value) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
}
function safeTransferFrom(address token, address from, address to, uint value) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
}
}
library UniswapV2Library {
using SafeMath for uint;
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
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;
}
}
interface IERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
}
interface IWETH is IERC20{
function deposit() external payable;
function withdraw(uint) external;
}
interface ILGT
{
function free(uint256 amount) external returns (bool success);
function freeFrom(uint256 amount, address owner) external returns (bool success);
}
contract SwappingContract
{
IWETH private constant WETH = IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
ILGT constant private lgt = ILGT(0x000000000000C1CB11D5c062901F32D06248CE48);
address private m_Owner;
constructor() public
{
m_Owner = msg.sender;
}
modifier onlyWhitelisted() {
require(m_Owner == msg.sender, 'NOT ALLOWED');
_;
}
function decodeData(bytes32 aData) internal pure returns (uint64 revertBalanceMin, uint64 minerTip, uint64 amountIn, bytes8 indexTokensPairs)
{
assembly
{
indexTokensPairs := aData
mstore(0x18, aData)
revertBalanceMin := mload(0)
mstore(0x10, aData)
minerTip := mload(0)
mstore(0x8, aData)
amountIn := mload(0)
indexTokensPairs := mload(0x20)
}
}
function swap(
address[] calldata tokensPath,
bytes32 aDigitsData,
address[] calldata pairsPath)
external payable
{
(uint64 revertBalanceMin, uint64 minerTip, uint64 amountIn, bytes8 indexTokensPairs) = decodeData(aDigitsData);
internalSwap(revertBalanceMin, minerTip, amountIn, tokensPath, pairsPath, indexTokensPairs);
}
function internalSwap(uint64 revertBalanceMin, uint64 minerTip, uint64 amountIn, address[] memory tokensPath, address[] memory pairsPath, bytes8 indexTokensPairs) internal
{
uint[] memory totalCalculatedAmounts = getAmountsOut(pairsPath, amountIn, tokensPath);
if((totalCalculatedAmounts[totalCalculatedAmounts.length - 1] >= revertBalanceMin))
{
WETH.transfer(pairsPath[0], amountIn);
for(uint8 i = 1; i < tokensPath.length; ++i)
{
(uint amount0Out, uint amount1Out) = (indexTokensPairs[i] == 0x01) ? (uint(0), totalCalculatedAmounts[i]) : (totalCalculatedAmounts[i], uint(0));
IUniswapV2Pair(pairsPath[i-1]).swap(
amount0Out, amount1Out, (i < tokensPath.length - 1 ? pairsPath[i]: address(this)), new bytes(0));
}
block.coinbase.transfer(minerTip);
if(indexTokensPairs[7] != 0x00)
{
lgt.freeFrom(uint8(indexTokensPairs[7]), msg.sender);
}
}
}
function getAmountsOut(address[] memory pairsPath, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint8 i = 0; i < path.length - 1; i++)
{
(uint reserveIn, uint reserveOut) = getReserves(pairsPath[i], path[i], path[i + 1]);
amounts[i + 1] = UniswapV2Library.getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
function getReserves(address pairAddress, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = UniswapV2Library.sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairAddress).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
function daBani(bool isEth, address _coin, uint256 _amount) onlyWhitelisted external payable
{
if(isEth)
{
msg.sender.transfer(_amount);
}
else
{
if(_coin != address(WETH))
{
TransferHelper.safeApprove(_coin, address(this), _amount);
TransferHelper.safeTransferFrom(
_coin, address(this), msg.sender, _amount
);
}
else
{
WETH.transfer(msg.sender, _amount);
}
}
}
function toggleWrapWETH(bool isWrap, uint256 _amount) onlyWhitelisted external
{
if(isWrap)
{
WETH.deposit{value: _amount}();
WETH.transfer(address(this), _amount);
}
else
{
WETH.withdraw(_amount);
}
}
function fuckMyNow() onlyWhitelisted public
{
selfdestruct(msg.sender);
}
receive() payable external {}
}