编译器
0.8.19+commit.7dd6d404
文件 1 的 6:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 6:ERC20.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function decimals() public view virtual override returns (uint8) {
return 18;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
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 _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
文件 3 的 6:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, 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 from,
address to,
uint256 amount
) external returns (bool);
}
文件 4 的 6:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 5 的 6:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 6 的 6:U.sol
pragma solidity ^0.8.19;
import {
ERC20,
IERC20
} from "@openzeppelin/contracts@4.8.3/token/ERC20/ERC20.sol";
import {Ownable} from "@openzeppelin/contracts@4.8.3/access/Ownable.sol";
interface IUniswapV2Router02 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
contract AnonZK is ERC20, Ownable {
error ErrAlreadySetup();
error ErrAlreadyLaunched();
error ErrMaxBalance();
error ErrMaxTx();
error ErrInvalidFees();
error ErrInvalidSwapThreshold();
error ErrAddressZero();
error ErrZeroValue();
error ErrZeroToken();
error ErrTradingNotStarted();
address constant FEE_RECEIVER = 0xC8aFc08747213Da2Ab68373E5B261dd304390270;
uint256 public constant MAX_SUPPLY = 10 * 1e6 ether;
IUniswapV2Router02 public constant UNISWAP_V2_ROUTER =
IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uint256 private constant INITIAL_MAX_TRANSACTION_AMOUNT = 3 * 1e5 ether;
uint256 private constant INITIAL_MAX_WALLET = 3 * 1e5 ether;
uint256 private constant INITIAL_BUY_FEE = 5;
uint256 private constant INITIAL_SELL_FEE = 30;
address public uniswapPair;
mapping(address => bool) private _limitExempted;
mapping(address => bool) private _feeExempted;
uint256 public maxWallet;
uint256 public maxTx;
address public feeReceiver;
uint256 public buyFee;
uint256 public sellFee;
uint256 private _swapThreshold;
bool private _isSwapping;
bool public tradingStarted;
constructor() ERC20("AnonZK", unicode"AZK") {
_limitExempted[tx.origin] = true;
_limitExempted[address(0)] = true;
_limitExempted[address(0xdead)] = true;
_limitExempted[address(this)] = true;
_limitExempted[address(UNISWAP_V2_ROUTER)] = true;
_feeExempted[address(this)] = true;
_feeExempted[tx.origin] = true;
maxWallet = INITIAL_MAX_WALLET;
maxTx = INITIAL_MAX_TRANSACTION_AMOUNT;
buyFee = INITIAL_BUY_FEE;
sellFee = INITIAL_SELL_FEE;
feeReceiver = FEE_RECEIVER;
_swapThreshold = MAX_SUPPLY / 100;
_mint(tx.origin, MAX_SUPPLY);
}
receive() external payable {}
fallback() external payable {}
function _beforeTokenTransfer(address from_, address to_, uint256 amount_) internal view override {
if (!_limitExempted[to_]) {
if (balanceOf(to_) + amount_ > maxWallet) {
revert ErrMaxBalance();
}
}
if (!_limitExempted[from_]) {
if (amount_ > maxTx) {
revert ErrMaxTx();
}
}
if (!tradingStarted) {
if (!_feeExempted[from_] && !_feeExempted[to_]) {
revert ErrTradingNotStarted();
}
}
}
function _transfer(address from_, address to_, uint256 amount_) internal override {
if (to_ == address(0)) revert ErrAddressZero();
if (amount_ == 0) {
super._transfer(from_, to_, 0);
return;
}
if (
!_isSwapping && balanceOf(address(this)) >= _swapThreshold && from_ != uniswapPair && !_feeExempted[from_]
&& !_feeExempted[to_]
) {
_isSwapping = true;
_swap();
_isSwapping = false;
}
uint256 fees = 0;
if (!_isSwapping && !_feeExempted[from_] && !_feeExempted[to_]) {
uint256 _sellTax = sellFee;
uint256 _buyTax = buyFee;
if (to_ == uniswapPair && _sellTax > 0) {
fees = (amount_ * _sellTax) / 100;
super._transfer(from_, address(this), fees);
}
else if (from_ == uniswapPair && _buyTax > 0) {
fees = (amount_ * _buyTax) / 100;
super._transfer(from_, address(this), fees);
}
}
super._transfer(from_, to_, amount_ - fees);
}
function launch(uint256 tokenAmount_) external payable onlyOwner {
if (uniswapPair != address(0)) revert ErrAlreadyLaunched();
if (msg.value == 0) revert ErrZeroValue();
if (tokenAmount_ == 0) revert ErrZeroToken();
_transfer(msg.sender, address(this), tokenAmount_);
IUniswapV2Router02 __router = UNISWAP_V2_ROUTER;
address __uniswapPair = IUniswapV2Factory(__router.factory()).createPair(address(this), __router.WETH());
_limitExempted[__uniswapPair] = true;
_approve(address(this), address(__router), type(uint256).max);
_approve(address(this), address(__uniswapPair), type(uint256).max);
IERC20(__uniswapPair).approve(address(__router), type(uint256).max);
__router.addLiquidityETH{value: address(this).balance}(
address(this), balanceOf(address(this)), 0, 0, owner(), block.timestamp
);
uniswapPair = __uniswapPair;
}
function clearStuck() external onlyOwner {
(bool success,) = payable(msg.sender).call{value: address(this).balance}("");
require(success);
}
function clearStuckToken() external onlyOwner {
_transfer(address(this), msg.sender, balanceOf(address(this)));
}
function setLimitExempted(address addr_, bool exempted_) external onlyOwner {
_limitExempted[addr_] = exempted_;
}
function setFeeExempted(address addr_, bool exempted_) external onlyOwner {
_feeExempted[addr_] = exempted_;
}
function setMaxWallet(uint256 maxWallet_) external onlyOwner {
maxWallet = maxWallet_;
}
function setMaxTx(uint256 maxTx_) external onlyOwner {
maxTx = maxTx_;
}
function setFeeReceiver(address addr_) external onlyOwner {
feeReceiver = addr_;
}
function setFees(uint256 buyFee_, uint256 sellFee_) external onlyOwner {
if (buyFee_ > 100 || sellFee_ > 100) {
revert ErrInvalidFees();
}
sellFee = sellFee_;
buyFee = buyFee_;
}
function setSwapThreshold(uint256 swapThreshold_) external onlyOwner {
uint256 __totalSupply = MAX_SUPPLY;
if (swapThreshold_ < __totalSupply / 1000 || swapThreshold_ > __totalSupply / 20) {
revert ErrInvalidSwapThreshold();
}
_swapThreshold = swapThreshold_;
}
function enableTrading() external onlyOwner {
tradingStarted = true;
}
function _swapTokensForEth(uint256 tokenAmount) private {
IUniswapV2Router02 __swapRouter = UNISWAP_V2_ROUTER;
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = __swapRouter.WETH();
_approve(address(this), address(__swapRouter), tokenAmount);
__swapRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount, 0, path, address(this), block.timestamp
);
}
function _swap() private {
uint256 __contractBalance = balanceOf(address(this));
uint256 __swapThreshold = _swapThreshold;
if (__contractBalance == 0) {
return;
}
uint256 __swapAmount = __contractBalance;
if (__swapAmount > __swapThreshold * 20) {
__swapAmount = __swapThreshold * 20;
}
_swapTokensForEth(__swapAmount);
uint256 __balance = address(this).balance;
(bool success,) = payable(address(feeReceiver)).call{value: __balance}("");
}
}
{
"compilationTarget": {
"contracts/U.sol": "AnonZK"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ErrAddressZero","type":"error"},{"inputs":[],"name":"ErrAlreadyLaunched","type":"error"},{"inputs":[],"name":"ErrAlreadySetup","type":"error"},{"inputs":[],"name":"ErrInvalidFees","type":"error"},{"inputs":[],"name":"ErrInvalidSwapThreshold","type":"error"},{"inputs":[],"name":"ErrMaxBalance","type":"error"},{"inputs":[],"name":"ErrMaxTx","type":"error"},{"inputs":[],"name":"ErrTradingNotStarted","type":"error"},{"inputs":[],"name":"ErrZeroToken","type":"error"},{"inputs":[],"name":"ErrZeroValue","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_V2_ROUTER","outputs":[{"internalType":"contract IUniswapV2Router02","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"buyFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"clearStuck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"clearStuckToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"enableTrading","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenAmount_","type":"uint256"}],"name":"launch","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"maxTx","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxWallet","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"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":[],"name":"sellFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr_","type":"address"},{"internalType":"bool","name":"exempted_","type":"bool"}],"name":"setFeeExempted","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr_","type":"address"}],"name":"setFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"buyFee_","type":"uint256"},{"internalType":"uint256","name":"sellFee_","type":"uint256"}],"name":"setFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr_","type":"address"},{"internalType":"bool","name":"exempted_","type":"bool"}],"name":"setLimitExempted","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"maxTx_","type":"uint256"}],"name":"setMaxTx","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"maxWallet_","type":"uint256"}],"name":"setMaxWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"swapThreshold_","type":"uint256"}],"name":"setSwapThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tradingStarted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"uniswapPair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]