编译器
0.8.26+commit.8a97fa7a
文件 1 的 7: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 的 7:ERC20.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./IERC20Metadata.sol";
import "./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 的 7: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 的 7: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 的 7:IUniswapV2Factory.sol
pragma solidity ^0.8.0;
interface IUniswapV2Factory {
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
}
文件 6 的 7:IUniswapV2Router.sol
pragma solidity ^0.8.0;
interface IUniswapV2Router {
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);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function getAmountsOut(uint256 amountIn, address[] memory path) external view returns (uint256[] memory amounts);
function factory() external pure returns (address);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
}
文件 7 的 7:Memecoin.sol
pragma solidity ^0.8.0;
import "./IUniswapV2Router.sol";
import "./IUniswapV2Factory.sol";
import "./ERC20.sol";
contract MemeCoin is ERC20 {
uint256 public constant TOTAL_SUPPLY = 1000000000 * 10**18;
uint256 public constant TOTAL_BUY_TOKENS = 800000000 * 10**18;
uint256 public constant LIQUIDITY_TOKENS = 200000000 * 10**18;
uint256 public constant BUY_PRICE_DIFFERENCE_PERCENT = 1000;
uint256 public constant FEE_PERCENTAGE = 2;
uint256 public constant TARGET_LIQUIDITY = 4 * 10**18;
address payable public constant REVENUE_ACCOUNT = payable(0xCDE357ABBdf15Da7CCE4B51CE70a1d0F08DfB782);
IUniswapV2Router public uniswapRouter;
address public lpAddress;
string public picture;
address public admin;
bool public listed;
uint256 public totalETHBought;
uint256 public totalTokensBought;
uint256 private maxWalletAmount;
uint256 public devTax;
mapping(address => uint256) public contributions;
mapping(address => uint256) public tokens;
constructor(
address _router,
address _admin,
uint256 _maxWalletAmount,
uint256 _devTax,
string memory _name,
string memory _ticker,
string memory _picture
) ERC20(_name, _ticker) {
uniswapRouter = IUniswapV2Router(_router);
if (_maxWalletAmount == 0) {
maxWalletAmount = type(uint256).max;
} else if(_maxWalletAmount == 1){
maxWalletAmount = (TOTAL_SUPPLY * 5) / 1000;
} else if(_maxWalletAmount == 2){
maxWalletAmount = TOTAL_SUPPLY * 1 / 100;
}
require(_maxWalletAmount == 0 || _maxWalletAmount == 1 || _maxWalletAmount == 2,'Invalid Max Wallet Amount');
picture = _picture;
admin = _admin;
devTax = _devTax;
listed = false;
totalETHBought = 0;
_mint(address(this), TOTAL_SUPPLY);
}
function _transfer(address sender, address recipient, uint256 amount) internal override {
uint256 tax;
address _factory = uniswapRouter.factory();
address _weth = uniswapRouter.WETH();
address lpToken = IUniswapV2Factory(_factory).getPair(address(this), _weth);
if(listed){
updateMaxWalletAmount(lpToken,_weth);
if (recipient != admin && recipient != address(lpToken) && recipient != address(0x000000000000000000000000000000000000dEaD)) {
if (devTax > 0) {
tax = amount * devTax / 100;
amount = amount - tax;
super._transfer(sender, admin, tax);
}
require(balanceOf(address(recipient)) + amount <= maxWalletAmount, "Transfer amount exceeds the max wallet amount");
}
super._transfer(sender, recipient, amount);
}else{
if (recipient != admin && recipient != address(this) && recipient != lpToken) {
if (devTax > 0) {
tax = amount * devTax / 100;
amount = amount - tax;
super._transfer(sender, admin, tax);
}
require(balanceOf(address(recipient)) + amount <= maxWalletAmount, "Transfer amount exceeds the max wallet amount");
}
super._transfer(sender, recipient, amount);
}
}
function buyTokens(address buyer,uint256 slippageAmount) external payable {
require(!listed, "Liquidity is already added to Uniswap");
require(msg.value > 0, "Send ETH to buy tokens");
uint256 fee = msg.value * FEE_PERCENTAGE / 100;
uint256 ethAmount = msg.value - fee;
uint256 tokenAmount = calculateTokenAmount(ethAmount);
uint256 currentPrice = tokenAmount/ethAmount;
uint256 finalprice;
if (_getRemainingAmount() == msg.value) {
finalprice = currentPrice;
if(tokenAmount > (TOTAL_BUY_TOKENS - totalTokensBought)){
tokenAmount = TOTAL_BUY_TOKENS - totalTokensBought;
}
}
totalTokensBought += tokenAmount;
contributions[buyer] += ethAmount;
if(finalprice == 0){
require(tokenAmount >= slippageAmount, "Slippage Amount Restriction");
}
if(devTax > 0 && buyer != admin){
uint256 tax = tokenAmount * devTax / 100;
uint256 buyerTokens = tokenAmount - tax;
tokens[buyer] += buyerTokens;
}else{
tokens[buyer] += tokenAmount;
}
totalETHBought += ethAmount;
_transfer(address(this), buyer, tokenAmount);
bool success;
(success, ) = REVENUE_ACCOUNT.call{value: fee}("");
require(success, "Transfer failed");
if (address(this).balance >= TARGET_LIQUIDITY && !listed) {
_addLiquidity();
_burnRemainingTokens();
}
}
function sellTokens(address seller,uint256 tokenAmount) external {
require(!listed, "Liquidity is already added to Uniswap");
require(tokenAmount > 0, "Amount must be greater than 0");
uint256 ethAmount = calculateEthAmount(seller,tokenAmount);
if (balanceOf(address(this)) == tokenAmount) {
ethAmount = address(this).balance;
contributions[seller] = 0;
totalETHBought = 0;
} else {
contributions[seller] -= ethAmount;
totalETHBought -= ethAmount;
}
uint256 fee = ethAmount * FEE_PERCENTAGE / 100;
tokens[seller] -= tokenAmount;
totalTokensBought -= tokenAmount;
_transfer(seller, address(this), tokenAmount);
bool success;
(success, ) = seller.call{value: ethAmount - fee}("");
require(success, "Transfer failed");
(success, ) = REVENUE_ACCOUNT.call{value: fee}("");
require(success, "Transfer failed");
}
function getRemainingAmount() public view returns (uint256) {
require(TARGET_LIQUIDITY > address(this).balance, "Liquidity target exceeded");
return _getRemainingAmount();
}
function slippage(uint256 ethAmount,uint256 slippageAllowance) public view returns(uint256) {
uint256 fee = ethAmount * FEE_PERCENTAGE / 100;
ethAmount = ethAmount - fee;
uint256 slippageAmount = calculateTokenAmount(ethAmount);
if (devTax > 0) {
uint256 tax = slippageAmount * devTax / 100;
slippageAmount = slippageAmount - tax;
}
slippageAllowance = slippageAmount * slippageAllowance / 100;
slippageAmount = slippageAmount - slippageAllowance;
return slippageAmount;
}
function calculateTokenAmount(uint256 ethAmount) public view returns (uint256) {
require(totalETHBought + ethAmount <= TARGET_LIQUIDITY, "Liquidity target exceeded");
uint256 initialTokenPrice = _initialTokenPrice();
uint256 tokenPrice = initialTokenPrice + ((initialTokenPrice * BUY_PRICE_DIFFERENCE_PERCENT / 100) * (totalETHBought + (ethAmount / 6)) / TARGET_LIQUIDITY);
return ethAmount * 10**18 / tokenPrice;
}
function calculateEthAmount(address user,uint256 tokenAmount) public view returns (uint256) {
uint256 userTokens = tokens[user];
require(userTokens >= tokenAmount, "Insufficient user token balance");
return contributions[user] * tokenAmount / userTokens;
}
function _addLiquidity() internal {
listed = true;
_approve(address(this), address(uniswapRouter), LIQUIDITY_TOKENS);
uniswapRouter.addLiquidityETH{ value: address(this).balance }(
address(this),
LIQUIDITY_TOKENS,
0,
0,
address(this),
block.timestamp
);
address _factory = uniswapRouter.factory();
address _weth = uniswapRouter.WETH();
address lpToken = IUniswapV2Factory(_factory).getPair(address(this),_weth);
uint256 amount = IERC20(lpToken).balanceOf(address(this));
IERC20(lpToken).transfer(address(0x000000000000000000000000000000000000dEaD),amount);
}
function _burnRemainingTokens() internal {
uint256 amount = IERC20(address(this)).balanceOf(address(this));
IERC20(address(this)).transfer(address(0x000000000000000000000000000000000000dEaD),amount);
}
function updateMaxWalletAmount(address _lpToken,address _weth) internal {
if(maxWalletAmount == type(uint256).max) return;
uint256 amount = IERC20(_weth).balanceOf(address(_lpToken));
if (amount >= 6 ether) {
maxWalletAmount = type(uint256).max;
}
}
function _getRemainingAmount() internal view returns (uint256) {
return (TARGET_LIQUIDITY - totalETHBought) * 100 / (100 - FEE_PERCENTAGE);
}
function _initialTokenPrice() internal pure returns (uint256){
return TARGET_LIQUIDITY * 10**18 / ((TOTAL_BUY_TOKENS * BUY_PRICE_DIFFERENCE_PERCENT) / 375);
}
}
{
"compilationTarget": {
"Memecoin.sol": "MemeCoin"
},
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_router","type":"address"},{"internalType":"address","name":"_admin","type":"address"},{"internalType":"uint256","name":"_maxWalletAmount","type":"uint256"},{"internalType":"uint256","name":"_devTax","type":"uint256"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_ticker","type":"string"},{"internalType":"string","name":"_picture","type":"string"}],"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":[],"name":"BUY_PRICE_DIFFERENCE_PERCENT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_PERCENTAGE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LIQUIDITY_TOKENS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REVENUE_ACCOUNT","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TARGET_LIQUIDITY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOTAL_BUY_TOKENS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOTAL_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","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":[{"internalType":"address","name":"buyer","type":"address"},{"internalType":"uint256","name":"slippageAmount","type":"uint256"}],"name":"buyTokens","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"calculateEthAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"ethAmount","type":"uint256"}],"name":"calculateTokenAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"contributions","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","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":"devTax","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRemainingAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":[],"name":"listed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"picture","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"seller","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"sellTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"ethAmount","type":"uint256"},{"internalType":"uint256","name":"slippageAllowance","type":"uint256"}],"name":"slippage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"tokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalETHBought","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalTokensBought","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":[],"name":"uniswapRouter","outputs":[{"internalType":"contract IUniswapV2Router","name":"","type":"address"}],"stateMutability":"view","type":"function"}]