Skip to content
Verified contractExactMIT

ZKShieldToken

Address0xecd8a369f41850ec9c2bce6f01033129afc514bb
Balance

0 ETH

 

Transactions

125

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 200 runs
EVM version
paris
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,922,956
Creation transaction
0x8bc2086254…e2c84d64f5

contracts/ZKShieldToken.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @title  ZKShield Token (ZKS)
/// @notice Fixed-supply ERC20 with a fair-launch tax that automatically
///         decays to zero after a configured number of buys.
/// @dev    The contract holds its entire supply at deployment. Liquidity
///         is seeded via `openTrading()` which pairs the full contract
///         balance with the ETH held by this contract.

/* ------------------------------------------------------------ */
/*                           INTERFACES                         */
/* ------------------------------------------------------------ */

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);
}

interface IUniswapV2Factory {
    function createPair(address tokenA, address tokenB) external returns (address pair);
}

interface IUniswapV2Router02 {
    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);

    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;
}

/* ------------------------------------------------------------ */
/*                         BASE CONTRACTS                       */
/* ------------------------------------------------------------ */

abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }
}

abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    constructor() {
        _owner = _msgSender();
        emit OwnershipTransferred(address(0), _owner);
    }

    modifier onlyOwner() {
        require(_owner == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    function owner() public view returns (address) {
        return _owner;
    }

    function renounceOwnership() external virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }
}

abstract contract ReentrancyGuard {
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status = _NOT_ENTERED;

    error ReentrantCall();

    modifier nonReentrant() {
        if (_status == _ENTERED) revert ReentrantCall();
        _status = _ENTERED;
        _;
        _status = _NOT_ENTERED;
    }
}

/* ------------------------------------------------------------ */
/*                             TOKEN                            */
/* ------------------------------------------------------------ */

contract ZKShieldToken is Context, IERC20, Ownable, ReentrancyGuard {
    /* --- Metadata --- */
    string  private constant NAME         = "ZKShield";
    string  private constant SYMBOL       = "ZKS";
    uint8   private constant DECIMALS     = 18;
    uint256 private constant TOTAL_SUPPLY = 100_000_000 * 10**DECIMALS;

    /* --- Tax schedule (decays automatically as buy count grows) --- */
    uint256 private constant INITIAL_BUY_TAX  = 23;
    uint256 private constant INITIAL_SELL_TAX = 23;
    uint256 private constant FINAL_BUY_TAX    = 0;
    uint256 private constant FINAL_SELL_TAX   = 0;

    /// @dev Buy tax drops from INITIAL_BUY_TAX → FINAL_BUY_TAX once _buyCount exceeds this.
    uint256 private constant REDUCE_BUY_TAX_AFTER  = 23;
    /// @dev Sell tax drops from INITIAL_SELL_TAX → FINAL_SELL_TAX once _buyCount exceeds this.
    uint256 private constant REDUCE_SELL_TAX_AFTER = 23;
    /// @dev Tax-swap to ETH is disabled until _buyCount exceeds this.
    uint256 private constant MIN_BUYS_BEFORE_SWAP  = 23;

    /* --- Uniswap V2 router (mainnet) --- */
    IUniswapV2Router02 private constant UNISWAP_V2_ROUTER =
        IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);

    /* --- Launch limits (relaxed by owner via removeLimits) --- */
    uint256 public maxTxAmount      = 2_000_000 * 10**DECIMALS; // 2%
    uint256 public maxWalletSize    = 2_000_000 * 10**DECIMALS; // 2%
    uint256 public taxSwapThreshold = 2_000_000 * 10**DECIMALS; // 2%
    uint256 public maxTaxSwap       = 2_000_000 * 10**DECIMALS; // 2%

    /* --- ERC20 storage --- */
    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;
    mapping(address => bool) private _isExcludedFromFee;

    /* --- Protocol state --- */
    address payable private immutable _taxWallet;
    address public uniswapV2Pair;

    bool private tradingOpen;
    bool private swapEnabled;
    bool private inSwap;

    uint256 private _buyCount;
    uint256 private _sellCount;
    uint256 private _lastSellBlock;

    /* --- Events --- */
    event TradingOpened(address indexed pair);
    event LimitsRemoved();
    event MaxTxAmountUpdated(uint256 maxTxAmount);

    /* --- Modifiers --- */
    modifier lockTheSwap() {
        inSwap = true;
        _;
        inSwap = false;
    }

    /* --- Constructor --- */
    constructor() payable {
        _taxWallet = payable(_msgSender());

        uint256 ownerAllocation = TOTAL_SUPPLY * 2 / 100; // 2%
        uint256 contractAllocation = TOTAL_SUPPLY - ownerAllocation;

        _balances[owner()] = ownerAllocation;
        _balances[address(this)] = contractAllocation;

        _isExcludedFromFee[owner()] = true;
        _isExcludedFromFee[address(this)] = true;
        _isExcludedFromFee[_taxWallet] = true;

        emit Transfer(address(0), address(this), contractAllocation);
        emit Transfer(address(0), owner(), ownerAllocation);
    }

    receive() external payable {}

    /* ========================================================== */
    /*                     ERC20 METADATA                         */
    /* ========================================================== */

    function name() public view returns (string memory) { return NAME; }
    function symbol() public view returns (string memory) { return SYMBOL; }
    function decimals() public view returns (uint8) { return DECIMALS; }
    function totalSupply() public view override returns (uint256) { return TOTAL_SUPPLY; }

    function balanceOf(address account) external view override returns (uint256) {
        return _balances[account];
    }

    function allowance(address owner_, address spender) external view override returns (uint256) {
        return _allowances[owner_][spender];
    }

    /* ========================================================== */
    /*                    ERC20 STATE CHANGING                    */
    /* ========================================================== */

    function approve(address spender, uint256 amount) external override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    function transfer(address recipient, uint256 amount) external override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    function transferFrom(address sender, address recipient, uint256 amount)
        external
        override
        returns (bool)
    {
        _transfer(sender, recipient, amount);
        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _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);
    }

    /* ========================================================== */
    /*                     CORE TRANSFER LOGIC                    */
    /* ========================================================== */

    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;

        if (from != owner() && to != owner()) {
            // BUY
            if (from == uniswapV2Pair && to != address(UNISWAP_V2_ROUTER) && !_isExcludedFromFee[to]) {
                require(amount <= maxTxAmount, "Exceeds the maxTxAmount");
                require(_balances[to] + amount <= maxWalletSize, "Exceeds the maxWalletSize");
                taxAmount = amount * ((_buyCount > REDUCE_BUY_TAX_AFTER) ? FINAL_BUY_TAX : INITIAL_BUY_TAX) / 100;
                _buyCount++;
            }

            // SELL
            if (to == uniswapV2Pair && from != address(this)) {
                taxAmount = amount * ((_buyCount > REDUCE_SELL_TAX_AFTER) ? FINAL_SELL_TAX : INITIAL_SELL_TAX) / 100;
            }

            // Accumulated-tax swap
            uint256 contractTokenBalance = _balances[address(this)];
            if (
                !inSwap &&
                to == uniswapV2Pair &&
                swapEnabled &&
                contractTokenBalance > taxSwapThreshold &&
                _buyCount > MIN_BUYS_BEFORE_SWAP
            ) {
                if (block.number > _lastSellBlock) {
                    _sellCount = 0;
                }
                require(_sellCount < 3, "Only 3 sells per block");
                _swapTokensForEth(_min(amount, _min(contractTokenBalance, maxTaxSwap)));
                uint256 contractETHBalance = address(this).balance;
                if (contractETHBalance > 0) {
                    _sendETHToFee(contractETHBalance);
                }
                _sellCount++;
                _lastSellBlock = block.number;
            }
        }

        if (taxAmount > 0) {
            _balances[address(this)] += taxAmount;
            emit Transfer(from, address(this), taxAmount);
        }

        _balances[from] -= amount;
        _balances[to]   += amount - taxAmount;
        emit Transfer(from, to, amount - taxAmount);
    }

    function _min(uint256 a, uint256 b) private pure returns (uint256) {
        return a > b ? b : a;
    }

    /* ========================================================== */
    /*                     SWAP / LIQUIDITY                       */
    /* ========================================================== */

    function _swapTokensForEth(uint256 tokenAmount) private lockTheSwap {
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = UNISWAP_V2_ROUTER.WETH();
        _approve(address(this), address(UNISWAP_V2_ROUTER), tokenAmount);
        UNISWAP_V2_ROUTER.swapExactTokensForETHSupportingFeeOnTransferTokens(
            tokenAmount,
            0,
            path,
            address(this),
            block.timestamp
        );
    }

    function _sendETHToFee(uint256 amount) private {
        _taxWallet.transfer(amount);
    }

    /* ========================================================== */
    /*                       ADMIN FUNCTIONS                      */
    /* ========================================================== */

    /// @notice Seeds the Uniswap V2 pool with the full contract balance and all held ETH, then enables trading.
    /// @dev LP tokens are sent to the current owner. Owner should burn them separately.
    function openTrading() external onlyOwner nonReentrant {
        require(!tradingOpen, "trading is already open");

        _approve(address(this), address(UNISWAP_V2_ROUTER), TOTAL_SUPPLY);
        uniswapV2Pair = IUniswapV2Factory(UNISWAP_V2_ROUTER.factory())
            .createPair(address(this), UNISWAP_V2_ROUTER.WETH());

        UNISWAP_V2_ROUTER.addLiquidityETH{value: address(this).balance}(
            address(this),
            _balances[address(this)],
            0,
            0,
            owner(),
            block.timestamp
        );
        IERC20(uniswapV2Pair).approve(address(UNISWAP_V2_ROUTER), type(uint256).max);

        swapEnabled = true;
        tradingOpen = true;

        emit TradingOpened(uniswapV2Pair);
    }

    /// @notice Removes launch-phase transaction and wallet-size limits.
    function removeLimits() external onlyOwner {
        maxTxAmount = TOTAL_SUPPLY;
        maxWalletSize = TOTAL_SUPPLY;
        emit MaxTxAmountUpdated(TOTAL_SUPPLY);
        emit LimitsRemoved();
    }

    /// @notice Forces a swap of the contract's accumulated tax tokens to ETH and forwards proceeds to the tax wallet.
    function manualSwap() external onlyOwner nonReentrant {
        uint256 tokenBalance = _balances[address(this)];
        if (tokenBalance > 0) _swapTokensForEth(tokenBalance);
        uint256 ethBalance = address(this).balance;
        if (ethBalance > 0) _sendETHToFee(ethBalance);
    }

    /// @notice Rescues ETH held by the contract, forwarding it to the tax wallet.
    /// @dev    For recovery if ETH gets stuck from a misconfigured deployment.
    function manualSend() external onlyOwner nonReentrant {
        uint256 ethBalance = address(this).balance;
        require(ethBalance > 0, "no ETH to rescue");
        _sendETHToFee(ethBalance);
    }

    /// @notice Rescues ERC20 tokens held by this contract, forwarding them to the tax wallet.
    /// @param  tokenAddress The ERC20 token to rescue.
    function rescueERC20(address tokenAddress) external onlyOwner nonReentrant {
        IERC20 token = IERC20(tokenAddress);
        uint256 balance = token.balanceOf(address(this));
        require(balance > 0, "no tokens to rescue");
        require(token.transfer(_taxWallet, balance), "transfer failed");
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.