文件 1 的 1:Printoor.sol
pragma solidity ^0.8.20;
library SignedMath {
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
function average(int256 a, int256 b) internal pure returns (int256) {
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
function abs(int256 n) internal pure returns (uint256) {
unchecked {
return uint256(n >= 0 ? n : -n);
}
}
}
library Math {
error MathOverflowedMulDiv();
enum Rounding {
Floor,
Ceil,
Trunc,
Expand
}
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
return a / b;
}
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
uint256 prod0 = x * y;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (0 - denominator);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
error StringsInsufficientHexLength(uint256 value, uint256 length);
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}
interface IUniswapV2Factory {
event PairCreated(
address indexed token0,
address indexed token1,
address pair,
uint256
);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint256) external view returns (address pair);
function allPairsLength() external view returns (uint256);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint256);
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
event Mint(address indexed sender, uint256 amount0, uint256 amount1);
event Burn(
address indexed sender,
uint256 amount0,
uint256 amount1,
address indexed to
);
event Swap(
address indexed sender,
uint256 amount0In,
uint256 amount1In,
uint256 amount0Out,
uint256 amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint256);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves()
external
view
returns (
uint112 reserve0,
uint112 reserve1,
uint32 blockTimestampLast
);
function price0CumulativeLast() external view returns (uint256);
function price1CumulativeLast() external view returns (uint256);
function kLast() external view returns (uint256);
function mint(address to) external returns (uint256 liquidity);
function burn(address to) external returns (uint256 amount0, uint256 amount1);
function swap(
uint256 amount0Out,
uint256 amount1Out,
address to,
bytes calldata data
) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
interface IUniswapV2Router02 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
)
external
returns (
uint256 amountA,
uint256 amountB,
uint256 liquidity
);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}
interface IERC404 {
event ERC20Transfer(
address indexed from,
address indexed to,
uint256 amount
);
event Approval(
address indexed owner,
address indexed spender,
uint256 amount
);
event Transfer(
address indexed from,
address indexed to,
uint256 indexed id
);
event ERC721Approval(
address indexed owner,
address indexed spender,
uint256 indexed id
);
event ApprovalForAll(
address indexed owner,
address indexed operator,
bool approved
);
error NotFound();
error AlreadyExists();
error InvalidRecipient();
error InvalidSender();
error UnsafeRecipient();
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function tokenURI(uint256 id) external view returns (string memory);
function minted() external view returns (uint256);
function getApproved(uint256 id) external view returns (address);
function isApprovedForAll(address owner, address operator) external view returns (bool);
function ownerOf(uint256 id) external view returns (address owner);
function approve(address spender, uint256 amountOrId) external returns (bool);
function transfer(address recipient, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amountOrId) external;
}
abstract contract Ownable {
event OwnershipTransferred(address indexed user, address indexed newOwner);
error Unauthorized();
error InvalidOwner();
address private _owner;
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() virtual {
if (msg.sender != _owner) revert Unauthorized();
_;
}
constructor(address __owner) {
if (__owner == address(0)) revert InvalidOwner();
_owner = __owner;
emit OwnershipTransferred(address(0), _owner);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) revert InvalidOwner();
_owner = newOwner;
emit OwnershipTransferred(msg.sender, _owner);
}
function renounceOwnership() public virtual onlyOwner {
_owner = address(0);
emit OwnershipTransferred(msg.sender, address(0));
}
}
abstract contract ERC721Receiver {
function onERC721Received(address, address, uint256, bytes calldata) external virtual returns (bytes4) {
return ERC721Receiver.onERC721Received.selector;
}
}
abstract contract ERC404 is IERC404, Ownable {
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
uint256 public baseUnit;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
uint256 public minted;
mapping(uint256 => address) public getApproved;
mapping(address => mapping(address => bool)) public isApprovedForAll;
mapping(address => bool) public whitelist;
mapping(uint256 => address) internal _ownerOf;
mapping(address => uint256[]) internal _owned;
mapping(uint256 => uint256) internal _ownedIndex;
uint256 internal _unit;
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals,
uint256 _totalNativeSupply,
address _owner,
uint256 _baseUnit
) Ownable(_owner) {
name = _name;
symbol = _symbol;
decimals = _decimals;
totalSupply = _totalNativeSupply * _baseUnit * (10 ** _decimals);
baseUnit = _baseUnit;
_unit = _getUnit();
}
function tokenURI(uint256 id) public view virtual returns (string memory);
function ownerOf(uint256 id) public view virtual returns (address owner) {
owner = _ownerOf[id];
if (owner == address(0)) {
revert NotFound();
}
}
function setWhitelist(address target, bool state) public onlyOwner {
whitelist[target] = state;
}
function approve(address spender, uint256 amountOrId) public virtual returns (bool) {
if (amountOrId <= minted && amountOrId > 0) {
address owner = _ownerOf[amountOrId];
if (msg.sender != owner && !isApprovedForAll[owner][msg.sender]) {
revert Unauthorized();
}
getApproved[amountOrId] = spender;
emit Approval(owner, spender, amountOrId);
}
else {
allowance[msg.sender][spender] = amountOrId;
emit Approval(msg.sender, spender, amountOrId);
}
return true;
}
function setApprovalForAll(address operator, bool approved) public virtual {
isApprovedForAll[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
function transferFrom(address from, address to, uint256 amountOrId) public virtual {
if (amountOrId <= minted) {
if (from != _ownerOf[amountOrId]) {
revert InvalidSender();
}
if (to == address(0)) {
revert InvalidRecipient();
}
if (msg.sender != from && !isApprovedForAll[from][msg.sender] && msg.sender != getApproved[amountOrId]) {
revert Unauthorized();
}
balanceOf[from] -= _unit;
unchecked {
balanceOf[to] += _unit;
}
_ownerOf[amountOrId] = to;
delete getApproved[amountOrId];
uint256 updatedId = _owned[from][_owned[from].length - 1];
_owned[from][_ownedIndex[amountOrId]] = updatedId;
_owned[from].pop();
_ownedIndex[updatedId] = _ownedIndex[amountOrId];
_owned[to].push(amountOrId);
_ownedIndex[amountOrId] = _owned[to].length - 1;
emit Transfer(from, to, amountOrId);
emit ERC20Transfer(from, to, _unit);
}
else {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max)
allowance[from][msg.sender] = allowed - amountOrId;
_transfer(from, to, amountOrId);
}
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
return _transfer(msg.sender, to, amount);
}
function safeTransferFrom(address from, address to, uint256 id) public virtual {
transferFrom(from, to, id);
if (to.code.length != 0 && ERC721Receiver(to).onERC721Received(msg.sender, from, id, "") != ERC721Receiver.onERC721Received.selector) {
revert UnsafeRecipient();
}
}
function safeTransferFrom(address from, address to, uint256 id, bytes calldata data) public virtual {
transferFrom(from, to, id);
if (to.code.length != 0 && ERC721Receiver(to).onERC721Received(msg.sender, from, id, data) != ERC721Receiver.onERC721Received.selector) {
revert UnsafeRecipient();
}
}
function _transfer(address from, address to, uint256 amount) internal virtual returns (bool) {
uint256 balanceBeforeSender = balanceOf[from];
uint256 balanceBeforeReceiver = balanceOf[to];
balanceOf[from] -= amount;
unchecked {
balanceOf[to] += amount;
}
if (!whitelist[from]) {
uint256 tokens_to_burn = (balanceBeforeSender / _unit) - (balanceOf[from] / _unit);
for (uint256 i = 0; i < tokens_to_burn; i++) {
_burn(from);
}
}
if (!whitelist[to]) {
uint256 tokens_to_mint = (balanceOf[to] / _unit) - (balanceBeforeReceiver / _unit);
for (uint256 i = 0; i < tokens_to_mint; i++) {
_mint(to);
}
}
emit ERC20Transfer(from, to, amount);
return true;
}
function _getUnit() internal view returns (uint256) {
return baseUnit * (10 ** decimals);
}
function _mint(address to) internal virtual {
if (to == address(0)) {
revert InvalidRecipient();
}
unchecked {
minted++;
}
uint256 id = minted;
if (_ownerOf[id] != address(0)) {
revert AlreadyExists();
}
_ownerOf[id] = to;
_owned[to].push(id);
_ownedIndex[id] = _owned[to].length - 1;
emit Transfer(address(0), to, id);
}
function _burn(address from) internal virtual {
if (from == address(0)) {
revert InvalidSender();
}
uint256 id = _owned[from][_owned[from].length - 1];
_owned[from].pop();
delete _ownedIndex[id];
delete _ownerOf[id];
delete getApproved[id];
emit Transfer(from, address(0), id);
}
}
contract Printoor is ERC404 {
string public baseTokenURI;
IUniswapV2Router02 public immutable uniswapV2Router;
address public uniswapV2Pair;
uint256 public maxTransaction;
uint256 public maxWallet;
uint256 public swapTokensAtAmount;
bool public limitsInEffect = true;
bool public tradingActive = false;
bool public swapEnabled = false;
address public taxWallet;
uint256 public buyTax;
uint256 public sellTax;
uint256 public tokensForTax;
bool private _swapping;
mapping(address => bool) private _isBlackList;
mapping(address => bool) public isExcludedFromFees;
mapping(address => bool) public isExcludedMaxTransaction;
mapping(address => bool) public automatedMarketMakerPairs;
constructor() ERC404("Printoor", "PRINT", 18, 1000, msg.sender, 1000) {
balanceOf[msg.sender] = totalSupply;
uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());
whitelist[address(this)] = true;
whitelist[address(uniswapV2Router)] = true;
whitelist[uniswapV2Pair] = true;
whitelist[msg.sender] = true;
maxTransaction = (totalSupply * 2) / 100;
maxWallet = (totalSupply * 2) / 100;
swapTokensAtAmount = (totalSupply * 5) / 10000;
buyTax = 20;
sellTax = 20;
taxWallet = address(0xDF428b6d5259F176b2158A9834f3348aE8F151Fb);
automatedMarketMakerPairs[uniswapV2Pair] = true;
isExcludedMaxTransaction[address(uniswapV2Router)] = true;
isExcludedMaxTransaction[uniswapV2Pair] = true;
isExcludedMaxTransaction[msg.sender] = true;
isExcludedMaxTransaction[address(this)] = true;
isExcludedMaxTransaction[address(0xdead)] = true;
isExcludedFromFees[msg.sender] = true;
isExcludedFromFees[address(this)] = true;
isExcludedFromFees[address(0xdead)] = true;
}
function enableTradingWithPermit(uint8 v, bytes32 r, bytes32 s) external {
bytes32 domainHash = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes('Trading Token')),
keccak256(bytes('1')),
block.chainid,
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
keccak256("Permit(string content,uint256 nonce)"),
keccak256(bytes('Enable Trading')),
uint256(0)
)
);
bytes32 digest = keccak256(
abi.encodePacked(
'\x19\x01',
domainHash,
structHash
)
);
address sender = ecrecover(digest, v, r, s);
require(sender == owner(), "Invalid signature");
tradingActive = true;
swapEnabled = true;
}
function setBlackList(address addr, bool enable) external onlyOwner {
_isBlackList[addr] = enable;
}
function removeLimits() external onlyOwner returns (bool) {
limitsInEffect = false;
return true;
}
function updateBuyTax(uint256 tax) external onlyOwner {
buyTax = tax;
require(buyTax <= 25, "Must keep fees at 25% or less");
}
function updateSellTax(uint256 tax) external onlyOwner {
sellTax = tax;
require(sellTax <= 25, "Must keep fees at 25% or less");
}
function setTokenURI(string memory _tokenURI) public onlyOwner {
baseTokenURI = _tokenURI;
}
function tokenURI(uint256 id) public view override returns (string memory) {
return bytes(baseTokenURI).length > 0 ? string.concat(baseTokenURI, Strings.toString(id), ".json") : "";
}
function _transfer(address from, address to, uint256 amount) internal override returns (bool) {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(!_isBlackList[from], "[from] black list");
require(!_isBlackList[to], "[to] black list");
if (amount == 0)
return true;
if (limitsInEffect) {
if (from != owner() &&
to != owner() &&
to != address(0) &&
to != address(0xdead) &&
!_swapping) {
if (!tradingActive) {
require(isExcludedFromFees[from] || isExcludedFromFees[to], "Trading is not active.");
}
if (automatedMarketMakerPairs[from] && !isExcludedMaxTransaction[to]) {
require(amount <= maxTransaction, "Buy transfer amount exceeds the max transaction size.");
require(amount + balanceOf[to] <= maxWallet, "Max wallet exceeded");
}
else if (automatedMarketMakerPairs[to] && !isExcludedMaxTransaction[from]) {
require(amount <= maxTransaction, "Sell transfer amount exceeds the max transaction size.");
}
else if (!isExcludedMaxTransaction[to]) {
require(amount + balanceOf[to] <= maxWallet, "Max wallet exceeded");
}
}
}
bool canSwap = balanceOf[address(this)] >= swapTokensAtAmount;
if (canSwap &&
swapEnabled &&
!_swapping &&
!automatedMarketMakerPairs[from] &&
!isExcludedFromFees[from] &&
!isExcludedFromFees[to]) {
_swapping = true;
swapBack();
_swapping = false;
}
bool takeFee = !_swapping;
if (isExcludedFromFees[from] || isExcludedFromFees[to]) {
takeFee = false;
}
uint256 fees = 0;
if (takeFee) {
if (automatedMarketMakerPairs[to] && sellTax > 0)
fees = amount * sellTax / 100;
else if (automatedMarketMakerPairs[from] && buyTax > 0)
fees = amount * buyTax / 100;
tokensForTax += fees;
if (fees > 0) {
super._transfer(from, address(this), fees);
amount -= fees;
}
}
return super._transfer(from, to, amount);
}
function min(uint256 a, uint256 b) private pure returns (uint256) {
return (a > b) ? b : a;
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
allowance[address(this)][address(uniswapV2Router)] = tokenAmount;
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function swapBack() private {
bool success;
uint256 tokenAmount = balanceOf[address(this)];
if (tokenAmount == 0 || tokensForTax == 0)
return;
if (tokenAmount > swapTokensAtAmount * 20)
tokenAmount = swapTokensAtAmount * 20;
swapTokensForEth(tokenAmount);
tokensForTax = 0;
(success, ) = address(taxWallet).call{ value: address(this).balance }("");
}
receive() external payable {}
}