creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts/utils/math/Math.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n    /**\n     * @dev Muldiv operation overflow.\n     */\n    error MathOverflowedMulDiv();\n\n    enum Rounding {\n        Floor, // Toward negative infinity\n        Ceil, // Toward positive infinity\n        Trunc, // Toward zero\n        Expand // Away from zero\n    }\n\n    /**\n     * @dev Returns the addition of two unsigned integers, with an overflow flag.\n     */\n    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            uint256 c = a + b;\n            if (c < a) return (false, 0);\n            return (true, c);\n        }\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.\n     */\n    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b > a) return (false, 0);\n            return (true, a - b);\n        }\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n     */\n    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n            // benefit is lost if 'b' is also tested.\n            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n            if (a == 0) return (true, 0);\n            uint256 c = a * b;\n            if (c / a != b) return (false, 0);\n            return (true, c);\n        }\n    }\n\n    /**\n     * @dev Returns the division of two unsigned integers, with a division by zero flag.\n     */\n    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b == 0) return (false, 0);\n            return (true, a / b);\n        }\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n     */\n    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b == 0) return (false, 0);\n            return (true, a % b);\n        }\n    }\n\n    /**\n     * @dev Returns the largest of two numbers.\n     */\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two numbers.\n     */\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two numbers. The result is rounded towards\n     * zero.\n     */\n    function average(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b) / 2 can overflow.\n        return (a & b) + (a ^ b) / 2;\n    }\n\n    /**\n     * @dev Returns the ceiling of the division of two numbers.\n     *\n     * This differs from standard division with `/` in that it rounds towards infinity instead\n     * of rounding towards zero.\n     */\n    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n        if (b == 0) {\n            // Guarantee the same behavior as in a regular Solidity division.\n            return a / b;\n        }\n\n        // (a + b - 1) / b can overflow on addition, so we distribute.\n        return a == 0 ? 0 : (a - 1) / b + 1;\n    }\n\n    /**\n     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\n     * denominator == 0.\n     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n     * Uniswap Labs also under MIT license.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n        unchecked {\n            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n            // variables such that product = prod1 * 2^256 + prod0.\n            uint256 prod0 = x * y; // Least significant 256 bits of the product\n            uint256 prod1; // Most significant 256 bits of the product\n            assembly {\n                let mm := mulmod(x, y, not(0))\n                prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n            }\n\n            // Handle non-overflow cases, 256 by 256 division.\n            if (prod1 == 0) {\n                // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n                // The surrounding unchecked block does not change this fact.\n                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n                return prod0 / denominator;\n            }\n\n            // Make sure the result is less than 2^256. Also prevents denominator == 0.\n            if (denominator <= prod1) {\n                revert MathOverflowedMulDiv();\n            }\n\n            ///////////////////////////////////////////////\n            // 512 by 256 division.\n            ///////////////////////////////////////////////\n\n            // Make division exact by subtracting the remainder from [prod1 prod0].\n            uint256 remainder;\n            assembly {\n                // Compute remainder using mulmod.\n                remainder := mulmod(x, y, denominator)\n\n                // Subtract 256 bit number from 512 bit number.\n                prod1 := sub(prod1, gt(remainder, prod0))\n                prod0 := sub(prod0, remainder)\n            }\n\n            // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\n            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n            uint256 twos = denominator & (0 - denominator);\n            assembly {\n                // Divide denominator by twos.\n                denominator := div(denominator, twos)\n\n                // Divide [prod1 prod0] by twos.\n                prod0 := div(prod0, twos)\n\n                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n                twos := add(div(sub(0, twos), twos), 1)\n            }\n\n            // Shift in bits from prod1 into prod0.\n            prod0 |= prod1 * twos;\n\n            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n            // four bits. That is, denominator * inv = 1 mod 2^4.\n            uint256 inverse = (3 * denominator) ^ 2;\n\n            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\n            // works in modular arithmetic, doubling the correct bits in each step.\n            inverse *= 2 - denominator * inverse; // inverse mod 2^8\n            inverse *= 2 - denominator * inverse; // inverse mod 2^16\n            inverse *= 2 - denominator * inverse; // inverse mod 2^32\n            inverse *= 2 - denominator * inverse; // inverse mod 2^64\n            inverse *= 2 - denominator * inverse; // inverse mod 2^128\n            inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n            // is no longer required.\n            result = prod0 * inverse;\n            return result;\n        }\n    }\n\n    /**\n     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n        uint256 result = mulDiv(x, y, denominator);\n        if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {\n            result += 1;\n        }\n        return result;\n    }\n\n    /**\n     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\n     * towards zero.\n     *\n     * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n     */\n    function sqrt(uint256 a) internal pure returns (uint256) {\n        if (a == 0) {\n            return 0;\n        }\n\n        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n        //\n        // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n        //\n        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n        //\n        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n        uint256 result = 1 << (log2(a) >> 1);\n\n        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n        // into the expected uint128 result.\n        unchecked {\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            return min(result, a / result);\n        }\n    }\n\n    /**\n     * @notice Calculates sqrt(a), following the selected rounding direction.\n     */\n    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = sqrt(a);\n            return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 2 of a positive value rounded towards zero.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 128;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 64;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 32;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 16;\n            }\n            if (value >> 8 > 0) {\n                value >>= 8;\n                result += 8;\n            }\n            if (value >> 4 > 0) {\n                value >>= 4;\n                result += 4;\n            }\n            if (value >> 2 > 0) {\n                value >>= 2;\n                result += 2;\n            }\n            if (value >> 1 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log2(value);\n            return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 10 of a positive value rounded towards zero.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >= 10 ** 64) {\n                value /= 10 ** 64;\n                result += 64;\n            }\n            if (value >= 10 ** 32) {\n                value /= 10 ** 32;\n                result += 32;\n            }\n            if (value >= 10 ** 16) {\n                value /= 10 ** 16;\n                result += 16;\n            }\n            if (value >= 10 ** 8) {\n                value /= 10 ** 8;\n                result += 8;\n            }\n            if (value >= 10 ** 4) {\n                value /= 10 ** 4;\n                result += 4;\n            }\n            if (value >= 10 ** 2) {\n                value /= 10 ** 2;\n                result += 2;\n            }\n            if (value >= 10 ** 1) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log10(value);\n            return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 256 of a positive value rounded towards zero.\n     * Returns 0 if given 0.\n     *\n     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n     */\n    function log256(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 16;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 8;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 4;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 2;\n            }\n            if (value >> 8 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log256(value);\n            return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n     */\n    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n        return uint8(rounding) % 2 == 1;\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/math/SignedMath.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n    /**\n     * @dev Returns the largest of two signed numbers.\n     */\n    function max(int256 a, int256 b) internal pure returns (int256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two signed numbers.\n     */\n    function min(int256 a, int256 b) internal pure returns (int256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two signed numbers without overflow.\n     * The result is rounded towards zero.\n     */\n    function average(int256 a, int256 b) internal pure returns (int256) {\n        // Formula from the book \"Hacker's Delight\"\n        int256 x = (a & b) + ((a ^ b) >> 1);\n        return x + (int256(uint256(x) >> 255) & (a ^ b));\n    }\n\n    /**\n     * @dev Returns the absolute unsigned value of a signed value.\n     */\n    function abs(int256 n) internal pure returns (uint256) {\n        unchecked {\n            // must be unchecked in order to support `n = type(int256).min`\n            return uint256(n >= 0 ? n : -n);\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Strings.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./math/Math.sol\";\nimport {SignedMath} from \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n    bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\n    uint8 private constant ADDRESS_LENGTH = 20;\n\n    /**\n     * @dev The `value` string doesn't fit in the specified `length`.\n     */\n    error StringsInsufficientHexLength(uint256 value, uint256 length);\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n     */\n    function toString(uint256 value) internal pure returns (string memory) {\n        unchecked {\n            uint256 length = Math.log10(value) + 1;\n            string memory buffer = new string(length);\n            uint256 ptr;\n            /// @solidity memory-safe-assembly\n            assembly {\n                ptr := add(buffer, add(32, length))\n            }\n            while (true) {\n                ptr--;\n                /// @solidity memory-safe-assembly\n                assembly {\n                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\n                }\n                value /= 10;\n                if (value == 0) break;\n            }\n            return buffer;\n        }\n    }\n\n    /**\n     * @dev Converts a `int256` to its ASCII `string` decimal representation.\n     */\n    function toStringSigned(int256 value) internal pure returns (string memory) {\n        return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n     */\n    function toHexString(uint256 value) internal pure returns (string memory) {\n        unchecked {\n            return toHexString(value, Math.log256(value) + 1);\n        }\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n     */\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n        uint256 localValue = value;\n        bytes memory buffer = new bytes(2 * length + 2);\n        buffer[0] = \"0\";\n        buffer[1] = \"x\";\n        for (uint256 i = 2 * length + 1; i > 1; --i) {\n            buffer[i] = HEX_DIGITS[localValue & 0xf];\n            localValue >>= 4;\n        }\n        if (localValue != 0) {\n            revert StringsInsufficientHexLength(value, length);\n        }\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\n     * representation.\n     */\n    function toHexString(address addr) internal pure returns (string memory) {\n        return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\n    }\n\n    /**\n     * @dev Returns true if the two strings are equal.\n     */\n    function equal(string memory a, string memory b) internal pure returns (bool) {\n        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\n    }\n}\n"
      },
      "contracts/ERC404.sol": {
        "content": "//SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\nabstract contract Ownable {\n    event OwnershipTransferred(address indexed user, address indexed newOwner);\n\n    error Unauthorized();\n    error InvalidOwner();\n\n    address public owner;\n\n    modifier onlyOwner() virtual {\n        if (msg.sender != owner) revert Unauthorized();\n\n        _;\n    }\n\n    constructor(address _owner) {\n        if (_owner == address(0)) revert InvalidOwner();\n\n        owner = _owner;\n\n        emit OwnershipTransferred(address(0), _owner);\n    }\n\n    function transferOwnership(address _owner) public virtual onlyOwner {\n        if (_owner == address(0)) revert InvalidOwner();\n\n        owner = _owner;\n\n        emit OwnershipTransferred(msg.sender, _owner);\n    }\n\n    function revokeOwnership() public virtual onlyOwner {\n        owner = address(0);\n\n        emit OwnershipTransferred(msg.sender, address(0));\n    }\n}\n\nabstract contract ERC721Receiver {\n    function onERC721Received(\n        address,\n        address,\n        uint256,\n        bytes calldata\n    ) external virtual returns (bytes4) {\n        return ERC721Receiver.onERC721Received.selector;\n    }\n}\n\n/// @notice ERC404\n///         A gas-efficient, mixed ERC20 / ERC721 implementation\n///         with native liquidity and fractionalization.\n///\n///         This is an experimental standard designed to integrate\n///         with pre-existing ERC20 / ERC721 support as smoothly as\n///         possible.\n///\n/// @dev    In order to support full functionality of ERC20 and ERC721\n///         supply assumptions are made that slightly constraint usage.\n///         Ensure decimals are sufficiently large (standard 18 recommended)\n///         as ids are effectively encoded in the lowest range of amounts.\n///\n///         NFTs are spent on ERC20 functions in a FILO queue, this is by\n///         design.\n///\nabstract contract ERC404 is Ownable {\n    // Events\n    event ERC20Transfer(\n        address indexed from,\n        address indexed to,\n        uint256 amount\n    );\n    event Approval(\n        address indexed owner,\n        address indexed spender,\n        uint256 amount\n    );\n    event Transfer(\n        address indexed from,\n        address indexed to,\n        uint256 indexed id\n    );\n    event ERC721Approval(\n        address indexed owner,\n        address indexed spender,\n        uint256 indexed id\n    );\n    event ApprovalForAll(\n        address indexed owner,\n        address indexed operator,\n        bool approved\n    );\n\n    // Errors\n    error NotFound();\n    error AlreadyExists();\n    error InvalidRecipient();\n    error InvalidSender();\n    error UnsafeRecipient();\n\n    // Metadata\n    /// @dev Token name\n    string public name;\n\n    /// @dev Token symbol\n    string public symbol;\n\n    /// @dev Decimals for fractional representation\n    uint8 public immutable decimals;\n\n    /// @dev Total supply in fractionalized representation\n    uint256 public immutable totalSupply;\n\n    /// @dev Current mint counter, monotonically increasing to ensure accurate ownership\n    uint256 public minted;\n\n    // Mappings\n    /// @dev Balance of user in fractional representation\n    mapping(address => uint256) public balanceOf;\n\n    /// @dev Allowance of user in fractional representation\n    mapping(address => mapping(address => uint256)) public allowance;\n\n    /// @dev Approval in native representaion\n    mapping(uint256 => address) public getApproved;\n\n    /// @dev Approval for all in native representation\n    mapping(address => mapping(address => bool)) public isApprovedForAll;\n\n    /// @dev Owner of id in native representation\n    mapping(uint256 => address) internal _ownerOf;\n\n    /// @dev Array of owned ids in native representation\n    mapping(address => uint256[]) internal _owned;\n\n    /// @dev Tracks indices for the _owned mapping\n    mapping(uint256 => uint256) internal _ownedIndex;\n\n    /// @dev Addresses whitelisted from minting / burning for gas savings (pairs, routers, etc)\n    mapping(address => bool) public whitelist;\n\n    // Constructor\n    constructor(\n        string memory _name,\n        string memory _symbol,\n        uint8 _decimals,\n        uint256 _totalNativeSupply,\n        address _owner\n    ) Ownable(_owner) {\n        name = _name;\n        symbol = _symbol;\n        decimals = _decimals;\n        totalSupply = _totalNativeSupply * (10 ** decimals);\n    }\n\n    /// @notice Initialization function to set pairs / etc\n    ///         saving gas by avoiding mint / burn on unnecessary targets\n    function setWhitelist(address target, bool state) public onlyOwner {\n        whitelist[target] = state;\n    }\n\n    /// @notice Function to find owner of a given native token\n    function ownerOf(uint256 id) public view virtual returns (address owner) {\n        owner = _ownerOf[id];\n\n        if (owner == address(0)) {\n            revert NotFound();\n        }\n    }\n\n    /// @notice tokenURI must be implemented by child contract\n    function tokenURI(uint256 id) public view virtual returns (string memory);\n\n    /// @notice Function for token approvals\n    /// @dev This function assumes id / native if amount less than or equal to current max id\n    function approve(\n        address spender,\n        uint256 amountOrId\n    ) public virtual returns (bool) {\n        if (amountOrId <= minted && amountOrId > 0) {\n            address owner = _ownerOf[amountOrId];\n\n            if (msg.sender != owner && !isApprovedForAll[owner][msg.sender]) {\n                revert Unauthorized();\n            }\n\n            getApproved[amountOrId] = spender;\n\n            emit Approval(owner, spender, amountOrId);\n        } else {\n            allowance[msg.sender][spender] = amountOrId;\n\n            emit Approval(msg.sender, spender, amountOrId);\n        }\n\n        return true;\n    }\n\n    /// @notice Function native approvals\n    function setApprovalForAll(address operator, bool approved) public virtual {\n        isApprovedForAll[msg.sender][operator] = approved;\n\n        emit ApprovalForAll(msg.sender, operator, approved);\n    }\n\n    /// @notice Function for mixed transfers\n    /// @dev This function assumes id / native if amount less than or equal to current max id\n    function transferFrom(\n        address from,\n        address to,\n        uint256 amountOrId\n    ) public virtual {\n        if (amountOrId <= minted) {\n            if (from != _ownerOf[amountOrId]) {\n                revert InvalidSender();\n            }\n\n            if (to == address(0)) {\n                revert InvalidRecipient();\n            }\n\n            if (\n                msg.sender != from &&\n                !isApprovedForAll[from][msg.sender] &&\n                msg.sender != getApproved[amountOrId]\n            ) {\n                revert Unauthorized();\n            }\n\n            balanceOf[from] -= _getUnit();\n\n            unchecked {\n                balanceOf[to] += _getUnit();\n            }\n\n            _ownerOf[amountOrId] = to;\n            delete getApproved[amountOrId];\n\n            // update _owned for sender\n            uint256 updatedId = _owned[from][_owned[from].length - 1];\n            _owned[from][_ownedIndex[amountOrId]] = updatedId;\n            // pop\n            _owned[from].pop();\n            // update index for the moved id\n            _ownedIndex[updatedId] = _ownedIndex[amountOrId];\n            // push token to to owned\n            _owned[to].push(amountOrId);\n            // update index for to owned\n            _ownedIndex[amountOrId] = _owned[to].length - 1;\n\n            emit Transfer(from, to, amountOrId);\n            emit ERC20Transfer(from, to, _getUnit());\n        } else {\n            uint256 allowed = allowance[from][msg.sender];\n\n            if (allowed != type(uint256).max)\n                allowance[from][msg.sender] = allowed - amountOrId;\n\n            _transfer(from, to, amountOrId);\n        }\n    }\n\n    /// @notice Function for fractional transfers\n    function transfer(\n        address to,\n        uint256 amount\n    ) public virtual returns (bool) {\n        return _transfer(msg.sender, to, amount);\n    }\n\n    /// @notice Function for native transfers with contract support\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 id\n    ) public virtual {\n        transferFrom(from, to, id);\n\n        if (\n            to.code.length != 0 &&\n            ERC721Receiver(to).onERC721Received(msg.sender, from, id, \"\") !=\n            ERC721Receiver.onERC721Received.selector\n        ) {\n            revert UnsafeRecipient();\n        }\n    }\n\n    /// @notice Function for native transfers with contract support and callback data\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 id,\n        bytes calldata data\n    ) public virtual {\n        transferFrom(from, to, id);\n\n        if (\n            to.code.length != 0 &&\n            ERC721Receiver(to).onERC721Received(msg.sender, from, id, data) !=\n            ERC721Receiver.onERC721Received.selector\n        ) {\n            revert UnsafeRecipient();\n        }\n    }\n\n    /// @notice Internal function for fractional transfers\n    function _transfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal returns (bool) {\n        uint256 unit = _getUnit();\n        uint256 balanceBeforeSender = balanceOf[from];\n        uint256 balanceBeforeReceiver = balanceOf[to];\n\n        balanceOf[from] -= amount;\n\n        unchecked {\n            balanceOf[to] += amount;\n        }\n\n        // Skip burn for certain addresses to save gas\n        if (!whitelist[from]) {\n            uint256 tokens_to_burn = (balanceBeforeSender / unit) -\n                (balanceOf[from] / unit);\n            for (uint256 i = 0; i < tokens_to_burn; i++) {\n                _burn(from);\n            }\n        }\n\n        // Skip minting for certain addresses to save gas\n        if (!whitelist[to]) {\n            uint256 tokens_to_mint = (balanceOf[to] / unit) -\n                (balanceBeforeReceiver / unit);\n            for (uint256 i = 0; i < tokens_to_mint; i++) {\n                _mint(to);\n            }\n        }\n\n        emit ERC20Transfer(from, to, amount);\n        return true;\n    }\n\n    // Internal utility logic\n    function _getUnit() internal view returns (uint256) {\n        return 10 ** decimals;\n    }\n\n    function _mint(address to) internal virtual {\n        if (to == address(0)) {\n            revert InvalidRecipient();\n        }\n\n        unchecked {\n            minted++;\n        }\n\n        uint256 id = minted;\n\n        if (_ownerOf[id] != address(0)) {\n            revert AlreadyExists();\n        }\n\n        _ownerOf[id] = to;\n        _owned[to].push(id);\n        _ownedIndex[id] = _owned[to].length - 1;\n\n        emit Transfer(address(0), to, id);\n    }\n\n    function _burn(address from) internal virtual {\n        if (from == address(0)) {\n            revert InvalidSender();\n        }\n\n        uint256 id = _owned[from][_owned[from].length - 1];\n        _owned[from].pop();\n        delete _ownedIndex[id];\n        delete _ownerOf[id];\n        delete getApproved[id];\n\n        emit Transfer(from, address(0), id);\n    }\n\n    function _setNameSymbol(\n        string memory _name,\n        string memory _symbol\n    ) internal {\n        name = _name;\n        symbol = _symbol;\n    }\n}\n"
      },
      "contracts/MyERC404.sol": {
        "content": "//SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {ERC404} from \"./ERC404.sol\";\nimport {Strings} from \"@openzeppelin/contracts/utils/Strings.sol\";\n\ncontract MyERC404 is ERC404 {\n    using Strings for uint256;\n\n    string public dataURI;\n    string public baseTokenURI;\n\n    constructor(address _owner) ERC404(\"MyERC404\", \"ME202\", 18, 10000, _owner) {\n        balanceOf[_owner] = 10000 * 10 ** 18;\n    }\n\n    function setDataURI(string memory _dataURI) public onlyOwner {\n        dataURI = _dataURI;\n    }\n\n    function setTokenURI(string memory _tokenURI) public onlyOwner {\n        baseTokenURI = _tokenURI;\n    }\n\n    function setNameSymbol(\n        string memory _name,\n        string memory _symbol\n    ) public onlyOwner {\n        _setNameSymbol(_name, _symbol);\n    }\n\n    function tokenURI(uint256 id) public view override returns (string memory) {\n        if (bytes(baseTokenURI).length > 0) {\n            return string.concat(baseTokenURI, Strings.toString(id));\n        } else {\n            uint8 seed = uint8(bytes1(keccak256(abi.encodePacked(id))));\n            string memory image;\n            string memory color;\n\n            if (seed <= 100) {\n                image = \"1.png\";\n                color = \"Purple\";\n            } else if (seed <= 160) {\n                image = \"2.png\";\n                color = \"Red\";\n            } else if (seed <= 210) {\n                image = \"3.png\";\n                color = \"Green\";\n            } else if (seed <= 240) {\n                image = \"4.png\";\n                color = \"Blue\";\n            } else if (seed <= 255) {\n                image = \"5.png\";\n                color = \"Orange\";\n            } else if (seed <= 300) {\n                image = \"6.png\";\n                color = \"Lavender\";\n            }\n\n            string memory jsonPreImage = string.concat(\n                string.concat(\n                    string.concat(\n                        '{\"name\": \"My ERC404 #',\n                        Strings.toString(id)\n                    ),\n                    '\",\"description\":\"A collection of circles enabled by ERC404, an experimental token standard.\",\"external_url\":\"\",\"image\":\"'\n                ),\n                string.concat(dataURI, image)\n            );\n            string memory jsonPostImage = string.concat(\n                '\",\"attributes\":[{\"trait_type\":\"Color\",\"value\":\"',\n                color\n            );\n            string memory jsonPostTraits = '\"}]}';\n\n            return\n                string.concat(\n                    \"data:application/json;utf8,\",\n                    string.concat(\n                        string.concat(jsonPreImage, jsonPostImage),\n                        jsonPostTraits\n                    )\n                );\n        }\n    }\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 1000
      },
      "evmVersion": "paris",
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}