文件 1 的 1:Contract.sol
pragma solidity 0.8.27;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
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 Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "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);
function getPair(address tokenA, address tokenB)
external
view
returns (address pair);
}
interface IUniswapV2Pair {
function skim(address to) external;
function sync() external;
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
}
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
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
);
}
contract Contract is Context, IERC20, Ownable {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private _isExcludedFromFee;
address payable private _taxWallet;
uint256 private initialBuyTaxRate = 18;
uint256 private initialSellTaxRate = 18;
uint256 private reducedBuyTaxRate = 0;
uint256 private reducedSellTaxRate = 0;
uint256 private buyTaxReductionThreshold = 18;
uint256 private sellTaxReductionThreshold = 18;
uint256 private swapEnabledThreshold = 18;
uint256 private _buyCount = 0;
uint8 private constant _decimals = 18;
uint256 private constant _tTotal = 1000000000 * 10**_decimals;
string private _name;
string private _symbol;
uint256 public maxTransactionAmount = (_tTotal * 2) / 100;
uint256 public maxWalletAmount = (_tTotal * 2) / 100;
uint256 public swapTokensAtAmount = (_tTotal * 1) / 100;
uint256 public _maxTaxSwap = (_tTotal * 1) / 100;
IUniswapV2Router02 private uniswapV2Router;
address private uniswapV2Pair;
bool private tradingOpen;
bool private inSwap = false;
bool private swapEnabled = false;
uint256 private sellCount = 0;
uint256 private lastSellBlock = 0;
uint8 public maxSellsPerBlock = 3;
bool public sellLimitActive = true;
uint256 public totalSellCount = 0;
uint256 public sellLimitRemovalThreshold = 18;
event MaxTxAmountUpdated(uint256 maxTransactionAmount);
event FeesUpdated(uint256 newBuyFee, uint256 newSellFee);
event SellLimitRemoved();
modifier lockTheSwap() {
inSwap = true;
_;
inSwap = false;
}
constructor(string memory name_, string memory symbol_) payable {
_name = name_;
_symbol = symbol_;
_taxWallet = payable(_msgSender());
_balances[_msgSender()] = (_tTotal * 8.0) / 100;
_balances[address(this)] = (_tTotal * 92.0) / 100;
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[_taxWallet] = true;
emit Transfer(address(0), _msgSender(), (_tTotal * 8.0) / 100);
emit Transfer(address(0), address(this), (_tTotal * 92.0) / 100);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view 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(_msgSender(), 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(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
_approve(sender, _msgSender(), currentAllowance - amount);
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 min(uint256 a, uint256 b) private pure returns (uint256) {
return (a < b) ? a : b;
}
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");
uint256 taxAmount = 0;
if (from != owner() && to != owner()) {
if (!tradingOpen && (from == uniswapV2Pair || to == uniswapV2Pair)) {
require(_isExcludedFromFee[from] || _isExcludedFromFee[to], "Trading not enabled yet");
}
}
if (
from == uniswapV2Pair &&
to != address(uniswapV2Router) &&
!_isExcludedFromFee[to]
) {
require(amount <= maxTransactionAmount, "Exceeds the maxTransactionAmount.");
_buyCount++;
uint256 buyTaxRate = (_buyCount > buyTaxReductionThreshold) ? reducedBuyTaxRate : initialBuyTaxRate;
if (buyTaxRate > 0) {
taxAmount = (amount * buyTaxRate) / 100;
}
require(
balanceOf(to) + amount - taxAmount <= maxWalletAmount,
"Exceeds the maxWalletAmount."
);
}
if (to == uniswapV2Pair && from != address(this) && !_isExcludedFromFee[from]) {
uint256 sellTaxRate = (_buyCount > sellTaxReductionThreshold) ? reducedSellTaxRate : initialSellTaxRate;
if (sellTaxRate > 0) {
taxAmount = (amount * sellTaxRate) / 100;
}
if (sellLimitActive) {
if (block.number > lastSellBlock) {
sellCount = 0;
lastSellBlock = block.number;
}
require(sellCount < maxSellsPerBlock, "Max sells per block reached");
sellCount++;
}
unchecked {
++totalSellCount;
}
if (sellLimitActive && totalSellCount >= sellLimitRemovalThreshold) {
sellLimitActive = false;
emit SellLimitRemoved();
}
}
uint256 contractTokenBalance = balanceOf(address(this));
if (
!inSwap &&
to == uniswapV2Pair &&
swapEnabled &&
contractTokenBalance > swapTokensAtAmount &&
_buyCount > swapEnabledThreshold
) {
uint256 swapAmount = min(amount, _maxTaxSwap);
if (swapAmount > contractTokenBalance) {
swapAmount = contractTokenBalance;
}
swapTokensForEth(swapAmount);
uint256 contractETHBalance = address(this).balance;
if (contractETHBalance > 0) {
sendETHToFee(contractETHBalance);
}
}
if (taxAmount > 0) {
_balances[address(this)] = _balances[address(this)] + taxAmount;
emit Transfer(from, address(this), taxAmount);
}
require(_balances[from] >= amount, "ERC20: transfer amount exceeds balance");
_balances[from] = _balances[from] - amount;
_balances[to] = _balances[to] + amount - taxAmount;
emit Transfer(from, to, amount - taxAmount);
}
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.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function removeLimits() external onlyOwner {
maxTransactionAmount = _tTotal;
maxWalletAmount = _tTotal;
emit MaxTxAmountUpdated(_tTotal);
}
function sendETHToFee(uint256 amount) private {
_taxWallet.transfer(amount);
}
function openTrading() public payable onlyOwner {
require(!tradingOpen, "trading is already open");
uniswapV2Router = IUniswapV2Router02(
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
);
address pair = IUniswapV2Factory(uniswapV2Router.factory())
.getPair(address(this), uniswapV2Router.WETH());
if (pair == address(0)) {
pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(
address(this),
uniswapV2Router.WETH()
);
}
uniswapV2Pair = pair;
_isExcludedFromFee[uniswapV2Pair] = true;
{
(uint112 r0, uint112 r1, ) = IUniswapV2Pair(uniswapV2Pair).getReserves();
uint256 balToken = IERC20(address(this)).balanceOf(uniswapV2Pair);
uint256 balWeth = IERC20(uniswapV2Router.WETH()).balanceOf(uniswapV2Pair);
if (balToken > r0 || balWeth > r1) {
IUniswapV2Pair(uniswapV2Pair).skim(owner());
}
IUniswapV2Pair(uniswapV2Pair).sync();
}
uint256 contractBalance = balanceOf(address(this));
require(contractBalance >= 92, "No tokens in contract");
uint256 tokensForLiquidity = (contractBalance * 87) / 92;
_approve(address(this), address(uniswapV2Router), type(uint256).max);
uniswapV2Router.addLiquidityETH{value: msg.value}(
address(this),
tokensForLiquidity,
0,
0,
owner(),
block.timestamp
);
IUniswapV2Pair(uniswapV2Pair).sync();
swapEnabled = true;
tradingOpen = true;
}
function reduceFee(uint256 _newBuyFee, uint256 _newSellFee) external onlyOwner {
require(_newBuyFee <= 25, "Buy fee cannot exceed 25%");
require(_newSellFee <= 25, "Sell fee cannot exceed 25%");
reducedBuyTaxRate = _newBuyFee;
reducedSellTaxRate = _newSellFee;
emit FeesUpdated(_newBuyFee, _newSellFee);
}
function setSellLimitRemovalThreshold(uint256 newThreshold) external onlyOwner {
require(newThreshold > 0, "Threshold must be > 0");
sellLimitRemovalThreshold = newThreshold;
}
function setMaxSellsPerBlock(uint8 newMax) external onlyOwner {
require(newMax > 0, "Max sells must be > 0");
maxSellsPerBlock = newMax;
}
function setTaxWallet(address payable newTaxWallet) external onlyOwner {
require(newTaxWallet != address(0), "Cannot set zero address");
_taxWallet = newTaxWallet;
_isExcludedFromFee[newTaxWallet] = true;
}
function getCurrentBuyFee() public view returns (uint256) {
return _buyCount < buyTaxReductionThreshold ? initialBuyTaxRate : reducedBuyTaxRate;
}
function getCurrentSellFee() public view returns (uint256) {
return _buyCount < sellTaxReductionThreshold ? initialSellTaxRate : reducedSellTaxRate;
}
function getBuyCount() public view returns (uint256) {
return _buyCount;
}
function getTaxWallet() public view returns (address) {
return _taxWallet;
}
receive() external payable {}
function manualSwap() external onlyOwner {
uint256 tokenBalance = balanceOf(address(this));
if (tokenBalance > 0) {
swapTokensForEth(tokenBalance);
}
uint256 ethBalance = address(this).balance;
if (ethBalance > 0) {
sendETHToFee(ethBalance);
}
}
}