文件 1 的 4:ERC20.sol
pragma solidity ^0.8.7;
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
);
}
contract ERC20 is IERC20 {
uint256 internal _totalSupply = 44444444e18;
uint8 constant _decimals = 18;
string _name;
string _symbol;
mapping(address => uint256) internal _balances;
mapping(address => mapping(address => uint256)) internal _allowances;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function name() external view returns (string memory) {
return _name;
}
function symbol() external view returns (string memory) {
return _symbol;
}
function decimals() external pure returns (uint8) {
return _decimals;
}
function totalSupply() external view override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account)
public
view
override
returns (uint256)
{
return _balances[account];
}
function transfer(address recipient, uint256 amount)
external
override
returns (bool)
{
_transfer(msg.sender, recipient, amount);
return true;
}
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
_beforeTokenTransfer(from, to, amount);
uint256 senderBalance = _balances[from];
require(senderBalance >= amount);
unchecked {
_balances[from] = senderBalance - amount;
}
_balances[to] += amount;
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
function allowance(address owner, address spender)
external
view
override
returns (uint256)
{
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount)
external
override
returns (bool)
{
_approve(msg.sender, spender, amount);
return true;
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][msg.sender];
require(currentAllowance >= amount);
unchecked {
_approve(sender, msg.sender, currentAllowance - amount);
}
return true;
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0));
uint256 accountBalance = _balances[account];
require(accountBalance >= amount);
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
文件 2 的 4:IUniswapV2Router02.sol
pragma solidity ^0.8.7;
interface IUniswapV2Router02 {
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
}
文件 3 的 4:TradableErc20.sol
pragma solidity ^0.8.7;
import "./ERC20.sol";
import "./IUniswapV2Router02.sol";
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB)
external
returns (address pair);
}
abstract contract TradableErc20 is ERC20 {
IUniswapV2Router02 internal constant _uniswapV2Router =
IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
address public uniswapV2Pair;
bool public tradingEnable;
mapping(address => bool) public isBot;
mapping(address => bool) _isExcludedFromFee;
bool _inSwap;
uint256 public maxBuy;
uint256 unbanBlock;
uint256 constant unbanBlocksCount = 2;
mapping(address => uint256) sellTimes;
uint256 constant minSellTimer = 30 seconds;
modifier onlyOwner() {
require(isOwner(msg.sender));
_;
}
modifier lockTheSwap() {
_inSwap = true;
_;
_inSwap = false;
}
constructor(string memory name_, string memory symbol_)
ERC20(name_, symbol_)
{
_setMaxBuy(1);
_isExcludedFromFee[address(0)] = true;
}
receive() external payable {}
function makeLiquidity() public onlyOwner {
require(uniswapV2Pair == address(0));
address pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(
address(this),
_uniswapV2Router.WETH()
);
_balances[address(this)] = _totalSupply;
_allowances[address(this)][address(_uniswapV2Router)] = _totalSupply;
_isExcludedFromFee[pair] = true;
_uniswapV2Router.addLiquidityETH{value: address(this).balance}(
address(this),
_totalSupply,
0,
0,
msg.sender,
block.timestamp
);
uniswapV2Pair = pair;
tradingEnable = true;
unbanBlock = block.number + unbanBlocksCount;
}
function autoBanBots() public view returns (bool) {
return block.number < unbanBlock;
}
function _transfer(
address from,
address to,
uint256 amount
) internal override {
require(!isBot[from] && !isBot[to]);
if (from == uniswapV2Pair && !_isExcludedFromFee[to]) {
require(tradingEnable);
bool _autoBanBots = autoBanBots();
if (!_autoBanBots) require(_balances[to] + amount <= maxBuy);
if (_autoBanBots) isBot[to] = true;
amount = _getFeeBuy(amount);
sellTimes[to] = block.timestamp + minSellTimer;
}
if (!_inSwap && uniswapV2Pair != address(0) && to == uniswapV2Pair) {
require(block.timestamp > sellTimes[from]);
amount = _getFeeSell(amount, from);
uint256 contractTokenBalance = balanceOf(address(this));
if (contractTokenBalance > 0) {
uint256 maxContractBalance = (balanceOf(uniswapV2Pair) *
getMaxContractBalancePercent()) / 100;
if (contractTokenBalance > maxContractBalance) {
uint256 burnCount;
unchecked {
burnCount = contractTokenBalance - maxContractBalance;
}
contractTokenBalance = maxContractBalance;
_totalSupply -= amount;
emit Transfer(address(this), address(0), burnCount);
}
uint256 swapCount = contractTokenBalance;
uint256 maxSwapCount = 2 * amount;
if (swapCount > maxSwapCount) swapCount = maxSwapCount;
swapTokensForEth(swapCount);
}
}
super._transfer(from, to, amount);
}
function _getFeeBuy(uint256 amount) private returns (uint256) {
uint256 fee = (amount * 12) / 100;
amount -= fee;
_totalSupply -= fee;
emit Transfer(uniswapV2Pair, address(0), fee);
return amount;
}
function _getFeeSell(uint256 amount, address account)
private
returns (uint256)
{
uint256 fee = (amount * 12) / 100;
amount -= fee;
_balances[address(this)] += fee;
_balances[account] -= fee;
return amount;
}
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = _uniswapV2Router.WETH();
_approve(address(this), address(_uniswapV2Router), tokenAmount);
_uniswapV2Router.swapExactTokensForETH(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function setMaxBuy(uint256 percent) external onlyOwner {
_setMaxBuy(percent);
}
function _setMaxBuy(uint256 percent) internal {
maxBuy = (percent * _totalSupply) / 100;
}
function setBots(address[] memory accounts, bool value) external onlyOwner {
for (uint256 i = 0; i < accounts.length; ++i) {
isBot[accounts[i]] = value;
}
}
function setExcludeFromFee(address[] memory accounts, bool value)
external
onlyOwner
{
for (uint256 i = 0; i < accounts.length; ++i) {
_isExcludedFromFee[accounts[i]] = value;
}
}
function setTradingEnable(bool value) external onlyOwner {
tradingEnable = value;
}
function withdraw() external onlyOwner {
_withdraw(address(this).balance);
}
function _withdraw(uint256 sum) internal virtual;
function isOwner(address account) internal virtual returns (bool);
function getMaxContractBalancePercent() internal virtual returns (uint256);
}
文件 4 的 4:WHACK_A_MUSK.sol
pragma solidity ^0.8.7;
import "./TradableErc20.sol";
contract WHACK_A_MUSK is TradableErc20 {
address _owner;
address _withdrawAddress =
address(0x04483272c443ef37aE2F7E849Be9f50E817DbeE0);
uint256 maxContractLiquidityPercent = 4;
constructor() TradableErc20("WHACK-A-MUSK", "$WHACK") {
_owner = msg.sender;
}
function isOwner(address account) internal view override returns (bool) {
return account == _owner;
}
function transferOwnership(address newOwner) external onlyOwner {
_owner = newOwner;
}
function setMaxContractLiquidityPercent(uint256 newMaxLiquidityPercent)
external
onlyOwner
{
maxContractLiquidityPercent = newMaxLiquidityPercent;
}
function getMaxContractBalancePercent()
internal
view
override
returns (uint256)
{
return maxContractLiquidityPercent;
}
function _withdraw(uint256 sum) internal override {
payable(_withdrawAddress).transfer(sum);
}
}
{
"compilationTarget": {
"contracts/WHACK_A_MUSK.sol": "WHACK_A_MUSK"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"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":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"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":[],"name":"autoBanBots","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isBot","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"makeLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maxBuy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"bool","name":"value","type":"bool"}],"name":"setBots","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"bool","name":"value","type":"bool"}],"name":"setExcludeFromFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"percent","type":"uint256"}],"name":"setMaxBuy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newMaxLiquidityPercent","type":"uint256"}],"name":"setMaxContractLiquidityPercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"value","type":"bool"}],"name":"setTradingEnable","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":"tradingEnable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","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":"uniswapV2Pair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]