creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "token.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity ^0.8.20;\r\n\r\n/**\r\n * @dev Interface of the ERC-20 standard as defined in the ERC.\r\n */\r\ninterface IERC20 {\r\n    /**\r\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\r\n     * another (`to`).\r\n     *\r\n     * Note that `value` may be zero.\r\n     */\r\n    event Transfer(address indexed from, address indexed to, uint256 value);\r\n\r\n    /**\r\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\r\n     * a call to {approve}. `value` is the new allowance.\r\n     */\r\n    event Approval(address indexed owner, address indexed spender, uint256 value);\r\n\r\n    /**\r\n     * @dev Returns the value of tokens in existence.\r\n     */\r\n    function totalSupply() external view returns (uint256);\r\n\r\n    /**\r\n     * @dev Returns the value of tokens owned by `account`.\r\n     */\r\n    function balanceOf(address account) external view returns (uint256);\r\n\r\n    /**\r\n     * @dev Moves a `value` amount of tokens from the caller's account to `to`.\r\n     *\r\n     * Returns a boolean value indicating whether the operation succeeded.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function transfer(address to, uint256 value) external returns (bool);\r\n\r\n    /**\r\n     * @dev Returns the remaining number of tokens that `spender` will be\r\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\r\n     * zero by default.\r\n     *\r\n     * This value changes when {approve} or {transferFrom} are called.\r\n     */\r\n    function allowance(address owner, address spender) external view returns (uint256);\r\n\r\n    /**\r\n     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\r\n     * caller's tokens.\r\n     *\r\n     * Returns a boolean value indicating whether the operation succeeded.\r\n     *\r\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\r\n     * that someone may use both the old and the new allowance by unfortunate\r\n     * transaction ordering. One possible solution to mitigate this race\r\n     * condition is to first reduce the spender's allowance to 0 and set the\r\n     * desired value afterwards:\r\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\r\n     *\r\n     * Emits an {Approval} event.\r\n     */\r\n    function approve(address spender, uint256 value) external returns (bool);\r\n\r\n    /**\r\n     * @dev Moves a `value` amount of tokens from `from` to `to` using the\r\n     * allowance mechanism. `value` is then deducted from the caller's\r\n     * allowance.\r\n     *\r\n     * Returns a boolean value indicating whether the operation succeeded.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function transferFrom(address from, address to, uint256 value) external returns (bool);\r\n}\r\n\r\n/**\r\n * @dev Provides information about the current execution context, including the\r\n * sender of the transaction and its data. While these are generally available\r\n * via msg.sender and msg.data, they should not be accessed in such a direct\r\n * manner, since when dealing with meta-transactions the account sending and\r\n * paying for execution may not be the actual sender (as far as an application\r\n * is concerned).\r\n *\r\n * This contract is only required for intermediate, library-like contracts.\r\n */\r\nabstract contract Context {\r\n    function _msgSender() internal view virtual returns (address) {\r\n        return msg.sender;\r\n    }\r\n\r\n    function _msgData() internal view virtual returns (bytes calldata) {\r\n        return msg.data;\r\n    }\r\n\r\n    function _contextSuffixLength() internal view virtual returns (uint256) {\r\n        return 0;\r\n    }\r\n}\r\n\r\n/**\r\n * @dev Interface for the optional metadata functions from the ERC-20 standard.\r\n */\r\ninterface IERC20Metadata is IERC20 {\r\n    /**\r\n     * @dev Returns the name of the token.\r\n     */\r\n    function name() external view returns (string memory);\r\n\r\n    /**\r\n     * @dev Returns the symbol of the token.\r\n     */\r\n    function symbol() external view returns (string memory);\r\n\r\n    /**\r\n     * @dev Returns the decimals places of the token.\r\n     */\r\n    function decimals() external view returns (uint8);\r\n}\r\n\r\n/**\r\n * @dev Standard ERC-20 Errors\r\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\r\n */\r\ninterface IERC20Errors {\r\n    /**\r\n     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\r\n     * @param sender Address whose tokens are being transferred.\r\n     * @param balance Current balance for the interacting account.\r\n     * @param needed Minimum amount required to perform a transfer.\r\n     */\r\n    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the token `sender`. Used in transfers.\r\n     * @param sender Address whose tokens are being transferred.\r\n     */\r\n    error ERC20InvalidSender(address sender);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the token `receiver`. Used in transfers.\r\n     * @param receiver Address to which tokens are being transferred.\r\n     */\r\n    error ERC20InvalidReceiver(address receiver);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\r\n     * @param spender Address that may be allowed to operate on tokens without being their owner.\r\n     * @param allowance Amount of tokens a `spender` is allowed to operate with.\r\n     * @param needed Minimum amount required to perform a transfer.\r\n     */\r\n    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\r\n     * @param approver Address initiating an approval operation.\r\n     */\r\n    error ERC20InvalidApprover(address approver);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\r\n     * @param spender Address that may be allowed to operate on tokens without being their owner.\r\n     */\r\n    error ERC20InvalidSpender(address spender);\r\n}\r\n\r\ncontract ReEntrancyGuard {\r\n    bool internal locked;\r\n\r\n    modifier noReentrant() {\r\n        require(!locked, \"No re-entrancy\");\r\n        locked = true;\r\n        _;\r\n        locked = false;\r\n    }\r\n}\r\n\r\ncontract Catoshi is Context, IERC20, IERC20Metadata, IERC20Errors, ReEntrancyGuard {\r\n    mapping(address account => uint256) private _balances;\r\n\r\n    mapping(address account => mapping(address spender => uint256)) private _allowances;\r\n\r\n    uint256 private _totalSupply;\r\n\r\n    string private _name;\r\n    string private _symbol;\r\n\r\n    uint256 public maxSupply = 21000000000000 * 10 ** 18;\r\n    uint256 public initialTokenCount = 500000000 * 10 ** 18;\r\n    uint256 public intervalTime = 10 * 60;\r\n    uint256 public intervalStartTime = 1712016001;\r\n    uint256 public intervalsToHalving = 21000;\r\n    uint256 public halvingsTotal = 33;\r\n    uint256 public pricePerToken = 10 ** 6;\r\n    uint256 public priceAdjustment = 10; // 10 = 10%\r\n    uint256 public acceleratedBurning = 10; // 10 = 0.1%\r\n    uint256 public acceleratedBurningTime = 24 * 60 * 60;\r\n\r\n    uint256 public maxSupplyReachedTime = 0;\r\n    uint256 public lastMinedTime = intervalStartTime;\r\n    uint256 public nowIntervals = 0;\r\n    uint256 public minedTotal = 0;\r\n    uint256 public burnedTotal = 0;\r\n\r\n    constructor() {\r\n        _name = \"Catoshi\";\r\n        _symbol = \"CATO\";\r\n    }\r\n\r\n    function name() public view virtual returns (string memory) {\r\n        return _name;\r\n    }\r\n\r\n    function symbol() public view virtual returns (string memory) {\r\n        return _symbol;\r\n    }\r\n\r\n    function decimals() public view virtual returns (uint8) {\r\n        return 18;\r\n    }\r\n\r\n    function totalSupply() public view virtual returns (uint256) {\r\n        return _totalSupply;\r\n    }\r\n\r\n    function balanceOf(address account) public view virtual returns (uint256) {\r\n        return _balances[account];\r\n    }\r\n\r\n    function transfer(address to, uint256 value) public virtual returns (bool) {\r\n        address owner = _msgSender();\r\n        _transfer(owner, to, value);\r\n        return true;\r\n    }\r\n\r\n    function allowance(address owner, address spender) public view virtual returns (uint256) {\r\n        return _allowances[owner][spender];\r\n    }\r\n\r\n    function approve(address spender, uint256 value) public virtual returns (bool) {\r\n        address owner = _msgSender();\r\n        _approve(owner, spender, value);\r\n        return true;\r\n    }\r\n\r\n    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {\r\n        address spender = _msgSender();\r\n        _spendAllowance(from, spender, value);\r\n        _transfer(from, to, value);\r\n        return true;\r\n    }\r\n    \r\n    function _transfer(address from, address to, uint256 value) internal {\r\n        if (from == address(0)) {\r\n            revert ERC20InvalidSender(address(0));\r\n        }\r\n        if (to == address(0)) {\r\n            revert ERC20InvalidReceiver(address(0));\r\n        }\r\n        _update(from, to, value);\r\n    }\r\n\r\n    function getTokensMinedOnInterval(uint256 intervalsCount) public view returns (uint256) {\r\n        uint256 halvingsCount = intervalsCount / intervalsToHalving;\r\n        if (halvingsCount > halvingsTotal) {\r\n            halvingsCount = halvingsTotal;\r\n        }\r\n        if (halvingsCount == 0) {\r\n            return initialTokenCount * intervalsCount;\r\n        }\r\n\r\n        uint256 totalTokens = 0;\r\n        uint256 nowCount = initialTokenCount;\r\n        totalTokens = nowCount * intervalsToHalving;\r\n        intervalsCount = intervalsCount - intervalsToHalving;\r\n\r\n        for (uint256 i = 1; i <= halvingsCount; i++) {\r\n            nowCount = nowCount / 2;\r\n            if (i == halvingsTotal) {\r\n                totalTokens = totalTokens + nowCount * intervalsCount;\r\n            } else {\r\n                if (intervalsCount < intervalsToHalving) {\r\n                    totalTokens = totalTokens + nowCount * intervalsCount;\r\n                } else {\r\n                    totalTokens = totalTokens + nowCount * intervalsToHalving;\r\n                    intervalsCount = intervalsCount - intervalsToHalving;\r\n                }\r\n            }\r\n        }\r\n\r\n        if (totalTokens > maxSupply) {\r\n            totalTokens = maxSupply;\r\n        }\r\n        return totalTokens;\r\n    }\r\n\r\n    function getBlockTimestamp() public view returns (uint256) {\r\n        return block.timestamp;\r\n    }\r\n\r\n    function getIntervalsCount() public view returns (uint256) {\r\n        return (block.timestamp - lastMinedTime) / intervalTime;\r\n    }\r\n\r\n    function getMiningPriceNow() public view returns (uint256) {\r\n        uint256 intervalsCount = getIntervalsCount();\r\n        uint256 currentPrice = pricePerToken;\r\n\r\n        for (uint256 i = 0; i < intervalsCount; i++) {\r\n            currentPrice = currentPrice * (100 - priceAdjustment) / 100;\r\n            if (currentPrice < 10) {\r\n                currentPrice = 10;\r\n                break;\r\n            }\r\n        }\r\n        return currentPrice;\r\n    }\r\n\r\n    function getAvailableTokens() public view returns (uint256) {\r\n        uint256 intervalsCount = (block.timestamp - lastMinedTime) / intervalTime;\r\n        return getTokensMinedOnInterval(nowIntervals + intervalsCount + 1) - minedTotal;\r\n    }\r\n\r\n    function getMinedTotal() public view returns (uint256) {\r\n        return minedTotal;\r\n    }\r\n\r\n    function getBurnedTotal() public view returns (uint256) {\r\n        return burnedTotal;\r\n    }\r\n\r\n    function mine(address receiverAddress) external payable noReentrant returns (bool) {\r\n        require(block.timestamp >= intervalStartTime, \"Mining not started yet\");\r\n\r\n        uint256 intervalsCount = (block.timestamp - lastMinedTime) / intervalTime;\r\n        require(minedTotal < maxSupply, \"Max supply is reached\");\r\n\r\n        uint256 price = getMiningPriceNow();\r\n        uint256 available = getAvailableTokens();\r\n\r\n        uint256 totalSum = price * available / (10 ** 18);\r\n\r\n        require(msg.value >= totalSum, \"Not wnough ETH sent\");\r\n\r\n        pricePerToken = price * (100 + priceAdjustment) / 100;\r\n        lastMinedTime = block.timestamp;\r\n        nowIntervals = nowIntervals + intervalsCount + 1;\r\n        minedTotal = getTokensMinedOnInterval(nowIntervals);\r\n\r\n        if (minedTotal == maxSupply) {\r\n            maxSupplyReachedTime = block.timestamp;\r\n        }\r\n\r\n        _mint(receiverAddress, available);\r\n        return true;\r\n    }\r\n\r\n    function getBurnReward() public view returns (uint256) {\r\n        uint256 totalAvailableTokens = minedTotal - burnedTotal;\r\n        if (totalAvailableTokens == 0) {\r\n            return 0;\r\n        }\r\n        if (maxSupplyReachedTime == 0) {\r\n            return address(this).balance * (10 ** 18) / totalAvailableTokens;\r\n        } else {\r\n            uint256 burnIntervalsCount = (block.timestamp - maxSupplyReachedTime) / acceleratedBurningTime;\r\n            uint256 reward = address(this).balance * (10 ** 18) / totalAvailableTokens;\r\n            for (uint256 i = 0; i < burnIntervalsCount; i++) {\r\n                reward = reward * (10000 + acceleratedBurning) / 10000;\r\n            }\r\n            return reward;\r\n        }\r\n    }\r\n\r\n    function burn(uint256 burnAmount, address receiverAddress) external noReentrant returns (bool) {\r\n        uint256 totalReward = burnAmount * getBurnReward() / (10 ** 18);\r\n        \r\n        require(burnAmount <= _balances[_msgSender()], \"Not enought tokens\");\r\n\r\n        if (totalReward > address(this).balance) {\r\n            burnAmount = burnAmount * address(this).balance / totalReward;\r\n            totalReward = address(this).balance;\r\n        }\r\n\r\n        burnedTotal = burnedTotal + burnAmount;\r\n        _burn(_msgSender(), burnAmount);\r\n\r\n        (bool sent,) = receiverAddress.call{value: totalReward}(\"\");\r\n        require(sent, \"Failed to send Ether\");\r\n        return true;\r\n    }\r\n\r\n    function getCirculatingSupply() public view returns (uint256) {\r\n        return minedTotal - burnedTotal;\r\n    }\r\n\r\n    function getSupply() public view returns (uint256) {\r\n        return minedTotal + getAvailableTokens() - burnedTotal;\r\n    }\r\n\r\n    /**\r\n     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`\r\n     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding\r\n     * this function.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function _update(address from, address to, uint256 value) internal virtual {\r\n        if (from == address(0)) {\r\n            // Overflow check required: The rest of the code assumes that totalSupply never overflows\r\n            _totalSupply += value;\r\n        } else {\r\n            uint256 fromBalance = _balances[from];\r\n            if (fromBalance < value) {\r\n                revert ERC20InsufficientBalance(from, fromBalance, value);\r\n            }\r\n            unchecked {\r\n                // Overflow not possible: value <= fromBalance <= totalSupply.\r\n                _balances[from] = fromBalance - value;\r\n            }\r\n        }\r\n\r\n        if (to == address(0)) {\r\n            unchecked {\r\n                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.\r\n                _totalSupply -= value;\r\n            }\r\n        } else {\r\n            unchecked {\r\n                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.\r\n                _balances[to] += value;\r\n            }\r\n        }\r\n\r\n        emit Transfer(from, to, value);\r\n    }\r\n\r\n    /**\r\n     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).\r\n     * Relies on the `_update` mechanism\r\n     *\r\n     * Emits a {Transfer} event with `from` set to the zero address.\r\n     *\r\n     * NOTE: This function is not virtual, {_update} should be overridden instead.\r\n     */\r\n    function _mint(address account, uint256 value) internal {\r\n        if (account == address(0)) {\r\n            revert ERC20InvalidReceiver(address(0));\r\n        }\r\n        _update(address(0), account, value);\r\n    }\r\n\r\n    /**\r\n     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.\r\n     * Relies on the `_update` mechanism.\r\n     *\r\n     * Emits a {Transfer} event with `to` set to the zero address.\r\n     *\r\n     * NOTE: This function is not virtual, {_update} should be overridden instead\r\n     */\r\n    function _burn(address account, uint256 value) internal {\r\n        if (account == address(0)) {\r\n            revert ERC20InvalidSender(address(0));\r\n        }\r\n        _update(account, address(0), value);\r\n    }\r\n\r\n    /**\r\n     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.\r\n     *\r\n     * This internal function is equivalent to `approve`, and can be used to\r\n     * e.g. set automatic allowances for certain subsystems, etc.\r\n     *\r\n     * Emits an {Approval} event.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `owner` cannot be the zero address.\r\n     * - `spender` cannot be the zero address.\r\n     *\r\n     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\r\n     */\r\n    function _approve(address owner, address spender, uint256 value) internal {\r\n        _approve(owner, spender, value, true);\r\n    }\r\n\r\n    /**\r\n     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.\r\n     *\r\n     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by\r\n     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any\r\n     * `Approval` event during `transferFrom` operations.\r\n     *\r\n     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to\r\n     * true using the following override:\r\n     *\r\n     * ```solidity\r\n     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {\r\n     *     super._approve(owner, spender, value, true);\r\n     * }\r\n     * ```\r\n     *\r\n     * Requirements are the same as {_approve}.\r\n     */\r\n    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {\r\n        if (owner == address(0)) {\r\n            revert ERC20InvalidApprover(address(0));\r\n        }\r\n        if (spender == address(0)) {\r\n            revert ERC20InvalidSpender(address(0));\r\n        }\r\n        _allowances[owner][spender] = value;\r\n        if (emitEvent) {\r\n            emit Approval(owner, spender, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Updates `owner` s allowance for `spender` based on spent `value`.\r\n     *\r\n     * Does not update the allowance value in case of infinite allowance.\r\n     * Revert if not enough allowance is available.\r\n     *\r\n     * Does not emit an {Approval} event.\r\n     */\r\n    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {\r\n        uint256 currentAllowance = allowance(owner, spender);\r\n        if (currentAllowance != type(uint256).max) {\r\n            if (currentAllowance < value) {\r\n                revert ERC20InsufficientAllowance(spender, currentAllowance, value);\r\n            }\r\n            unchecked {\r\n                _approve(owner, spender, currentAllowance - value, false);\r\n            }\r\n        }\r\n    }\r\n}"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": false,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      }
    }
  }}