creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    /**\n     * @dev The caller account is not authorized to perform an operation.\n     */\n    error OwnableUnauthorizedAccount(address account);\n\n    /**\n     * @dev The owner is not a valid owner account. (eg. `address(0)`)\n     */\n    error OwnableInvalidOwner(address owner);\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n     */\n    constructor(address initialOwner) {\n        if (initialOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(initialOwner);\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        if (owner() != _msgSender()) {\n            revert OwnableUnauthorizedAccount(_msgSender());\n        }\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        if (newOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
      },
      "@openzeppelin/contracts/interfaces/IERC165.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\n"
      },
      "@openzeppelin/contracts/interfaces/IERC721Receiver.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC721Receiver.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC721Receiver} from \"../token/ERC721/IERC721Receiver.sol\";\n"
      },
      "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n    /**\n     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n     * by `operator` from `from`, this function is called.\n     *\n     * It must return its Solidity selector to confirm the token transfer.\n     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be\n     * reverted.\n     *\n     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.\n     */\n    function onERC721Received(\n        address operator,\n        address from,\n        uint256 tokenId,\n        bytes calldata data\n    ) external returns (bytes4);\n}\n"
      },
      "@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/introspection/IERC165.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
      },
      "@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: MIT\n\npragma solidity ^0.8.11;\n\nimport {IERC721Receiver} from \"@openzeppelin/contracts/interfaces/IERC721Receiver.sol\";\nimport {IERC165} from \"@openzeppelin/contracts/interfaces/IERC165.sol\";\nimport {IERC404} from \"./interfaces/IERC404.sol\";\nimport {DoubleEndedQueue} from \"./lib/DoubleEndedQueue.sol\";\nimport {ERC721Events} from \"./lib/ERC721Events.sol\";\nimport {ERC20Events} from \"./lib/ERC20Events.sol\";\n\nabstract contract ERC404 is IERC404 {\n  using DoubleEndedQueue for DoubleEndedQueue.Uint256Deque;\n\n  /// @dev The queue of ERC-721 tokens stored in the contract.\n  DoubleEndedQueue.Uint256Deque private _storedERC721Ids;\n\n  /// @dev Token name\n  string public name;\n\n  /// @dev Token symbol\n  string public symbol;\n\n  /// @dev Decimals for ERC-20 representation\n  uint8 public immutable decimals =18;\n\n  /// @dev Units for ERC-20 representation\n  uint256 immutable units;\n\n  /// @dev Total supply in ERC-20 representation\n  uint256 public totalSupply;\n\n  /// @dev Current mint counter which also represents the highest\n  ///      minted id, monotonically increasing to ensure accurate ownership\n  uint256 private minted;\n\n  /// @dev Initial chain id for EIP-2612 support\n  uint256 internal immutable _INITIAL_CHAIN_ID;\n\n  /// @dev Initial domain separator for EIP-2612 support\n  bytes32 internal immutable _INITIAL_DOMAIN_SEPARATOR;\n\n  /// @dev Balance of user in ERC-20 representation\n  mapping(address => uint256) public balanceOf;\n\n  /// @dev Allowance of user in ERC-20 representation\n  mapping(address => mapping(address => uint256)) public allowance;\n\n  /// @dev Approval in ERC-721 representaion\n  mapping(uint256 => address) private getApproved;\n\n  /// @dev Approval for all in ERC-721 representation\n  mapping(address => mapping(address => bool)) private isApprovedForAll;\n\n  /// @dev Packed representation of ownerOf and owned indices\n  mapping(uint256 => uint256) internal _ownedData;\n\n  /// @dev Array of owned ids in ERC-721 representation\n  mapping(address => uint256[]) internal _owned;\n\n  /// @dev Addresses that are exempt from ERC-721 transfer, typically for gas savings (pairs, routers, etc)\n  mapping(address => bool) internal _erc721TransferExempt;\n\n  /// @dev EIP-2612 nonces\n  mapping(address => uint256) private nonces;\n\n  /// @dev Address bitmask for packed ownership data\n  uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;\n\n  /// @dev Owned index bitmask for packed ownership data\n  uint256 private constant _BITMASK_OWNED_INDEX = ((1 << 96) - 1) << 160;\n\n  /// @dev Constant for token id encoding\n  uint256 private constant ID_ENCODING_PREFIX = 1 << 255;\n\n  constructor(string memory name_, string memory symbol_) {\n    name = name_;\n    symbol = symbol_;\n\n    // decimals = decimals_;\n    units = 10 ** 18;\n\n    // EIP-2612 initialization\n    _INITIAL_CHAIN_ID = block.chainid;\n    _INITIAL_DOMAIN_SEPARATOR = _computeDomainSeparator();\n  }\n\n  /// @notice Function to find owner of a given ERC-721 token\n  function ownerOf(\n    uint256 id_\n  ) public view virtual returns (address erc721Owner) {\n    erc721Owner = _getOwnerOf(id_);\n\n    if (!_isValidTokenId(id_)) {\n      revert InvalidTokenId();\n    }\n\n    if (erc721Owner == address(0)) {\n      revert NotFound();\n    }\n  }\n\n  function owned(\n    address owner_\n  ) public view virtual returns (uint256[] memory) {\n    return _owned[owner_];\n  }\n\n  function erc721BalanceOf(\n    address owner_\n  ) public view virtual returns (uint256) {\n    return _owned[owner_].length;\n  }\n\n  function erc20BalanceOf(\n    address owner_\n  ) public view virtual returns (uint256) {\n    return balanceOf[owner_];\n  }\n\n  // function erc20TotalSupply() public view virtual returns (uint256) {\n  //   return totalSupply;\n  // }\n\n  // function erc721TotalSupply() public view virtual returns (uint256) {\n  //   return minted;\n  // }\n\n  // function getERC721QueueLength() public view virtual returns (uint256) {\n  //   return _storedERC721Ids.length();\n  // }\n\n  // function getERC721TokensInQueue(\n  //   uint256 start_,\n  //   uint256 count_\n  // ) public view virtual returns (uint256[] memory) {\n  //   uint256[] memory tokensInQueue = new uint256[](count_);\n\n  //   for (uint256 i = start_; i < start_ + count_; ) {\n  //     tokensInQueue[i - start_] = _storedERC721Ids.at(i);\n\n  //     unchecked {\n  //       ++i;\n  //     }\n  //   }\n\n  //   return tokensInQueue;\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 the operator is attempting to approve\n  ///      an ERC-721 if valueOrId_ is a possibly valid ERC-721 token id.\n  ///      Unlike setApprovalForAll, spender_ must be allowed to be 0x0 so\n  ///      that approval can be revoked.\n  function approve(\n    address spender_,\n    uint256 valueOrId_\n  ) public virtual returns (bool) {\n    if (_isValidTokenId(valueOrId_)) {\n      erc721Approve(spender_, valueOrId_);\n    } else {\n      return erc20Approve(spender_, valueOrId_);\n    }\n\n    return true;\n  }\n\n  function erc721Approve(address spender_, uint256 id_) public virtual {\n    // Intention is to approve as ERC-721 token (id).\n    address erc721Owner = _getOwnerOf(id_);\n\n    if (\n      msg.sender != erc721Owner && \n      !isApprovedForAll[erc721Owner][msg.sender]\n    ) {\n      revert Unauthorized();\n    }\n\n    getApproved[id_] = spender_;\n\n    emit ERC721Events.Approval(erc721Owner, spender_, id_);\n  }\n\n  /// @dev Providing type(uint256).max for approval value results in an\n  ///      unlimited approval that is not deducted from on transfers.\n  function erc20Approve(\n    address spender_,\n    uint256 value_\n  ) public virtual returns (bool) {\n    // Prevent granting 0x0 an ERC-20 allowance.\n    if (spender_ == address(0)) {\n      revert InvalidSpender();\n    }\n\n    allowance[msg.sender][spender_] = value_;\n\n    emit ERC20Events.Approval(msg.sender, spender_, value_);\n\n    return true;\n  }\n\n  /// @notice Function for ERC-721 approvals\n  // function setApprovalForAll(\n        // address operator_, \n        // bool approved_) \n        // public virtual {\n  //   // Prevent approvals to 0x0.\n  //   if (operator_ == address(0)) {\n  //     revert InvalidOperator();\n  //   }\n  //   isApprovedForAll[msg.sender][operator_] = approved_;\n  //   emit ERC721Events.ApprovalForAll(msg.sender, operator_, approved_);\n  // }\n\n  /// @notice Function for mixed transfers from an operator that may be different than 'from'.\n  /// @dev This function assumes the operator is attempting to transfer an ERC-721\n  ///      if valueOrId is a possible valid token id.\n  function transferFrom(\n    address from_,\n    address to_,\n    uint256 valueOrId_\n  ) public virtual returns (bool) {\n    if (_isValidTokenId(valueOrId_)) {\n      erc721TransferFrom(from_, to_, valueOrId_);\n    } else {\n      // Intention is to transfer as ERC-20 token (value).\n      return erc20TransferFrom(from_, to_, valueOrId_);\n    }\n\n    return true;\n  }\n\n  /// @notice Function for ERC-721 transfers from.\n  /// @dev This function is recommended for ERC721 transfers.\n  function erc721TransferFrom(\n    address from_,\n    address to_,\n    uint256 id_\n  ) public virtual {\n    // Prevent minting tokens from 0x0.\n    if (from_ == address(0)) {\n      revert InvalidSender();\n    }\n\n    // Prevent burning tokens to 0x0.\n    if (to_ == address(0)) {\n      revert InvalidRecipient();\n    }\n\n    if (from_ != _getOwnerOf(id_)) {\n      revert Unauthorized();\n    }\n\n    // Check that the operator is either the sender or approved for the transfer.\n    if (\n      msg.sender != from_ &&\n      !isApprovedForAll[from_][msg.sender] &&\n      msg.sender != getApproved[id_]\n    ) {\n      revert Unauthorized();\n    }\n\n    // We only need to check ERC-721 transfer exempt status for the recipient\n    // since the sender being ERC-721 transfer exempt means they have already\n    // had their ERC-721s stripped away during the rebalancing process.\n    if (erc721TransferExempt(to_)) {\n      revert RecipientIsERC721TransferExempt();\n    }\n\n    // Transfer 1 * units ERC-20 and 1 ERC-721 token.\n    // ERC-721 transfer exemptions handled above. Can't make it to this point if either is transfer exempt.\n    _transferERC20(from_, to_, units);\n    _transferERC721(from_, to_, id_);\n  }\n\n  /// @notice Function for ERC-20 transfers from.\n  /// @dev This function is recommended for ERC20 transfers\n  function erc20TransferFrom(\n    address from_,\n    address to_,\n    uint256 value_\n  ) public virtual returns (bool) {\n    // Prevent minting tokens from 0x0.\n    if (from_ == address(0)) {\n      revert InvalidSender();\n    }\n\n    // Prevent burning tokens to 0x0.\n    if (to_ == address(0)) {\n      revert InvalidRecipient();\n    }\n\n    uint256 allowed = allowance[from_][msg.sender];\n\n    // Check that the operator has sufficient allowance.\n    if (allowed != type(uint256).max) {\n      allowance[from_][msg.sender] = allowed - value_;\n    }\n\n    // Transferring ERC-20s directly requires the _transferERC20WithERC721 function.\n    // Handles ERC-721 exemptions internally.\n    return _transferERC20WithERC721(from_, to_, value_);\n  }\n\n  /// @notice Function for ERC-20 transfers.\n  /// @dev This function assumes the operator is attempting to transfer as ERC-20\n  ///      given this function is only supported on the ERC-20 interface.\n  ///      Treats even large amounts that are valid ERC-721 ids as ERC-20s.\n  function transfer(\n        address to_, \n        uint256 value_\n  ) public virtual returns (bool) {\n    // Prevent burning tokens to 0x0.\n    if (to_ == address(0)) {\n      revert InvalidRecipient();\n    }\n\n    // Transferring ERC-20s directly requires the _transferERC20WithERC721 function.\n    // Handles ERC-721 exemptions internally.\n    return _transferERC20WithERC721(msg.sender, to_, value_);\n  }\n\n  /// @notice Function for ERC-721 transfers with contract support.\n  /// This function only supports moving valid ERC-721 ids, as it does not exist on the ERC-20\n  /// spec and will revert otherwise.\n  function safeTransferFrom(\n    address from_,\n    address to_,\n    uint256 id_\n  ) public virtual {\n    safeTransferFrom(from_, to_, id_, \"\");\n  }\n\n  /// @notice Function for ERC-721 transfers with contract support and callback data.\n  /// This function only supports moving valid ERC-721 ids, as it does not exist on the\n  /// ERC-20 spec and will revert otherwise.\n  function safeTransferFrom(\n    address from_,\n    address to_,\n    uint256 id_,\n    bytes memory data_\n  ) internal  virtual {\n    if (!_isValidTokenId(id_)) {\n      revert InvalidTokenId();\n    }\n\n    transferFrom(from_, to_, id_);\n\n    if (\n      to_.code.length != 0 &&\n      IERC721Receiver(to_).onERC721Received(\n        msg.sender, \n        from_, \n        id_, \n        data_\n        ) !=\n      IERC721Receiver.onERC721Received.selector\n    ) {\n      revert UnsafeRecipient();\n    }\n  }\n\n  /// @notice Function for EIP-2612 permits (ERC-20 only).\n  /// @dev Providing type(uint256).max for permit value results in an\n  ///      unlimited approval that is not deducted from on transfers.\n  // function permit(\n  //   address owner_,\n  //   address spender_,\n  //   uint256 value_,\n  //   uint256 deadline_,\n  //   uint8 v_,\n  //   bytes32 r_,\n  //   bytes32 s_\n  // ) public virtual {\n  //   if (deadline_ < block.timestamp) {\n  //     revert PermitDeadlineExpired();\n  //   }\n\n  //   // permit cannot be used for ERC-721 token approvals, so ensure\n  //   // the value does not fall within the valid range of ERC-721 token ids.\n  //   if (_isValidTokenId(value_)) {\n  //     revert InvalidApproval();\n  //   }\n\n  //   if (spender_ == address(0)) {\n  //     revert InvalidSpender();\n  //   }\n\n  //   unchecked {\n  //     address recoveredAddress = ecrecover(\n  //       keccak256(\n  //         abi.encodePacked(\n  //           \"\\x19\\x01\",\n  //           DOMAIN_SEPARATOR(),\n  //           keccak256(\n  //             abi.encode(\n  //               keccak256(\n  //                 \"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\"\n  //               ),\n  //               owner_,\n  //               spender_,\n  //               value_,\n  //               nonces[owner_]++,\n  //               deadline_\n  //             )\n  //           )\n  //         )\n  //       ),\n  //       v_,\n  //       r_,\n  //       s_\n  //     );\n\n  //     if (recoveredAddress == address(0) || recoveredAddress != owner_) {\n  //       revert InvalidSigner();\n  //     }\n\n  //     allowance[recoveredAddress][spender_] = value_;\n  //   }\n\n  //   emit ERC20Events.Approval(owner_, spender_, value_);\n  // }\n\n  /// @notice Returns domain initial domain separator, or recomputes if chain id is not equal to initial chain id\n  function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {\n    return\n      block.chainid == _INITIAL_CHAIN_ID\n        ? _INITIAL_DOMAIN_SEPARATOR\n        : _computeDomainSeparator();\n  }\n\n  function supportsInterface(\n    bytes4 interfaceId\n  ) public view virtual returns (bool) {\n    return\n      interfaceId == type(IERC404).interfaceId ||\n      interfaceId == type(IERC165).interfaceId;\n  }\n\n  /// @notice Function for self-exemption\n  // function setSelfERC721TransferExempt(bool state_) public virtual {\n  //   _setERC721TransferExempt(msg.sender, state_);\n  // }\n\n  /// @notice Function to check if address is transfer exempt\n  function erc721TransferExempt(\n    address target_\n  ) public view virtual returns (bool) {\n    return target_ == address(0) || _erc721TransferExempt[target_];\n  }\n\n  /// @notice For a token token id to be considered valid, it just needs\n  ///         to fall within the range of possible token ids, it does not\n  ///         necessarily have to be minted yet.\n  function _isValidTokenId(uint256 id_) internal pure returns (bool) {\n    return id_ > ID_ENCODING_PREFIX && id_ != type(uint256).max;\n  }\n\n  /// @notice Internal function to compute domain separator for EIP-2612 permits\n  function _computeDomainSeparator() internal view virtual returns (bytes32) {\n    return\n      keccak256(\n        abi.encode(\n          keccak256(\n            \"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\"\n          ),\n          keccak256(bytes(name)),\n          keccak256(\"1\"),\n          block.chainid,\n          address(this)\n        )\n      );\n  }\n\n  /// @notice This is the lowest level ERC-20 transfer function, which\n  ///         should be used for both normal ERC-20 transfers as well as minting.\n  /// Note that this function allows transfers to and from 0x0.\n  function _transferERC20(\n    address from_,\n    address to_,\n    uint256 value_\n  ) internal virtual {\n    // Minting is a special case for which we should not check the balance of\n    // the sender, and we should increase the total supply.\n    if (from_ == address(0)) {\n      totalSupply += value_;\n    } else {\n      // Deduct value from sender's balance.\n      balanceOf[from_] -= value_;\n    }\n\n    // Update the recipient's balance.\n    // Can be unchecked because on mint, adding to totalSupply is checked, and on transfer balance deduction is checked.\n    unchecked {\n      balanceOf[to_] += value_;\n    }\n\n    emit ERC20Events.Transfer(from_, to_, value_);\n  }\n\n  /// @notice Consolidated record keeping function for transferring ERC-721s.\n  /// @dev Assign the token to the new owner, and remove from the old owner.\n  /// Note that this function allows transfers to and from 0x0.\n  /// Does not handle ERC-721 exemptions.\n  function _transferERC721(\n    address from_,\n    address to_,\n    uint256 id_\n  ) internal virtual {\n    // If this is not a mint, handle record keeping for transfer from previous owner.\n    if (from_ != address(0)) {\n      // On transfer of an NFT, any previous approval is reset.\n      delete getApproved[id_];\n\n      uint256 updatedId = _owned[from_][_owned[from_].length - 1];\n      if (updatedId != id_) {\n        uint256 updatedIndex = _getOwnedIndex(id_);\n        // update _owned for sender\n        _owned[from_][updatedIndex] = updatedId;\n        // update index for the moved id\n        _setOwnedIndex(updatedId, updatedIndex);\n      }\n\n      // pop\n      _owned[from_].pop();\n    }\n\n    // Check if this is a burn.\n    if (to_ != address(0)) {\n      // If not a burn, update the owner of the token to the new owner.\n      // Update owner of the token to the new owner.\n      _setOwnerOf(id_, to_);\n      // Push token onto the new owner's stack.\n      _owned[to_].push(id_);\n      // Update index for new owner's stack.\n      _setOwnedIndex(id_, _owned[to_].length - 1);\n    } else {\n      // If this is a burn, reset the owner of the token to 0x0 by deleting the token from _ownedData.\n      delete _ownedData[id_];\n    }\n\n    emit ERC721Events.Transfer(from_, to_, id_);\n  }\n\n  /// @notice Internal function for ERC-20 transfers. Also handles any ERC-721 transfers that may be required.\n  // Handles ERC-721 exemptions.\n  function _transferERC20WithERC721(\n    address from_,\n    address to_,\n    uint256 value_\n  ) internal virtual returns (bool) {\n    uint256 erc20BalanceOfSenderBefore = erc20BalanceOf(from_);\n    uint256 erc20BalanceOfReceiverBefore = erc20BalanceOf(to_);\n\n    _transferERC20(from_, to_, value_);\n\n    // Preload for gas savings on branches\n    bool isFromERC721TransferExempt = erc721TransferExempt(from_);\n    bool isToERC721TransferExempt = erc721TransferExempt(to_);\n\n    // Skip _withdrawAndStoreERC721 and/or _retrieveOrMintERC721 for ERC-721 transfer exempt addresses\n    // 1) to save gas\n    // 2) because ERC-721 transfer exempt addresses won't always have/need ERC-721s corresponding to their ERC20s.\n    if (isFromERC721TransferExempt && isToERC721TransferExempt) {\n      // Case 1) Both sender and recipient are ERC-721 transfer exempt. No ERC-721s need to be transferred.\n      // NOOP.\n    } else if (isFromERC721TransferExempt) {\n      // Case 2) The sender is ERC-721 transfer exempt, but the recipient is not. Contract should not attempt\n      //         to transfer ERC-721s from the sender, but the recipient should receive ERC-721s\n      //         from the bank/minted for any whole number increase in their balance.\n      // Only cares about whole number increments.\n      uint256 tokensToRetrieveOrMint = (balanceOf[to_] / units) -\n        (erc20BalanceOfReceiverBefore / units);\n      for (uint256 i = 0; i < tokensToRetrieveOrMint; ) {\n        _retrieveOrMintERC721(to_);\n        unchecked {\n          ++i;\n        }\n      }\n    } else if (isToERC721TransferExempt) {\n      // Case 3) The sender is not ERC-721 transfer exempt, but the recipient is. Contract should attempt\n      //         to withdraw and store ERC-721s from the sender, but the recipient should not\n      //         receive ERC-721s from the bank/minted.\n      // Only cares about whole number increments.\n      uint256 tokensToWithdrawAndStore = (erc20BalanceOfSenderBefore / units) -\n        (balanceOf[from_] / units);\n      for (uint256 i = 0; i < tokensToWithdrawAndStore; ) {\n        _withdrawAndStoreERC721(from_);\n        unchecked {\n          ++i;\n        }\n      }\n    } else {\n      // Case 4) Neither the sender nor the recipient are ERC-721 transfer exempt.\n      // Strategy:\n      // 1. First deal with the whole tokens. These are easy and will just be transferred.\n      // 2. Look at the fractional part of the value:\n      //   a) If it causes the sender to lose a whole token that was represented by an NFT due to a\n      //      fractional part being transferred, withdraw and store an additional NFT from the sender.\n      //   b) If it causes the receiver to gain a whole new token that should be represented by an NFT\n      //      due to receiving a fractional part that completes a whole token, retrieve or mint an NFT to the recevier.\n\n      // Whole tokens worth of ERC-20s get transferred as ERC-721s without any burning/minting.\n      uint256 nftsToTransfer = value_ / units;\n      for (uint256 i = 0; i < nftsToTransfer; ) {\n        // Pop from sender's ERC-721 stack and transfer them (LIFO)\n        uint256 indexOfLastToken = _owned[from_].length - 1;\n        uint256 tokenId = _owned[from_][indexOfLastToken];\n        _transferERC721(from_, to_, tokenId);\n        unchecked {\n          ++i;\n        }\n      }\n\n      // If the transfer changes either the sender or the recipient's holdings from a fractional to a non-fractional\n      // amount (or vice versa), adjust ERC-721s.\n\n      // First check if the send causes the sender to lose a whole token that was represented by an ERC-721\n      // due to a fractional part being transferred.\n      //\n      // Process:\n      // Take the difference between the whole number of tokens before and after the transfer for the sender.\n      // If that difference is greater than the number of ERC-721s transferred (whole units), then there was\n      // an additional ERC-721 lost due to the fractional portion of the transfer.\n      // If this is a self-send and the before and after balances are equal (not always the case but often),\n      // then no ERC-721s will be lost here.\n      if (\n        erc20BalanceOfSenderBefore / units - erc20BalanceOf(from_) / units >\n        nftsToTransfer\n      ) {\n        _withdrawAndStoreERC721(from_);\n      }\n\n      // Then, check if the transfer causes the receiver to gain a whole new token which requires gaining\n      // an additional ERC-721.\n      //\n      // Process:\n      // Take the difference between the whole number of tokens before and after the transfer for the recipient.\n      // If that difference is greater than the number of ERC-721s transferred (whole units), then there was\n      // an additional ERC-721 gained due to the fractional portion of the transfer.\n      // Again, for self-sends where the before and after balances are equal, no ERC-721s will be gained here.\n      if (\n        erc20BalanceOf(to_) / units - erc20BalanceOfReceiverBefore / units >\n        nftsToTransfer\n      ) {\n        _retrieveOrMintERC721(to_);\n      }\n    }\n\n    return true;\n  }\n\n  /// @notice Internal function for ERC20 minting\n  /// @dev This function will allow minting of new ERC20s.\n  ///      If mintCorrespondingERC721s_ is true, and the recipient is not ERC-721 exempt, it will\n  ///      also mint the corresponding ERC721s.\n  /// Handles ERC-721 exemptions.\n  function _mintERC20(address to_, uint256 value_) internal virtual {\n    /// You cannot mint to the zero address (you can't mint and immediately burn in the same transfer).\n    if (to_ == address(0)) {\n      revert InvalidRecipient();\n    }\n\n    if (totalSupply + value_ > ID_ENCODING_PREFIX) {\n      revert MintLimitReached();\n    }\n\n    _transferERC20WithERC721(address(0), to_, value_);\n  }\n\n  /// @notice Internal function for ERC-721 minting and retrieval from the bank.\n  /// @dev This function will allow minting of new ERC-721s up to the total fractional supply. It will\n  ///      first try to pull from the bank, and if the bank is empty, it will mint a new token.\n  /// Does not handle ERC-721 exemptions.\n  function _retrieveOrMintERC721(address to_) internal virtual {\n    if (to_ == address(0)) {\n      revert InvalidRecipient();\n    }\n\n    uint256 id;\n\n    if (!_storedERC721Ids.empty()) {\n      // If there are any tokens in the bank, use those first.\n      // Pop off the end of the queue (FIFO).\n      id = _storedERC721Ids.popBack();\n    } else {\n      // Otherwise, mint a new token, should not be able to go over the total fractional supply.\n      ++minted;\n\n      // Reserve max uint256 for approvals\n      if (minted == type(uint256).max) {\n        revert MintLimitReached();\n      }\n\n      id = ID_ENCODING_PREFIX + minted;\n    }\n\n    address erc721Owner = _getOwnerOf(id);\n\n    // The token should not already belong to anyone besides 0x0 or this contract.\n    // If it does, something is wrong, as this should never happen.\n    if (erc721Owner != address(0)) {\n      revert AlreadyExists();\n    }\n\n    // Transfer the token to the recipient, either transferring from the contract's bank or minting.\n    // Does not handle ERC-721 exemptions.\n    _transferERC721(erc721Owner, to_, id);\n  }\n\n  /// @notice Internal function for ERC-721 deposits to bank (this contract).\n  /// @dev This function will allow depositing of ERC-721s to the bank, which can be retrieved by future minters.\n  // Does not handle ERC-721 exemptions.\n  function _withdrawAndStoreERC721(address from_) internal virtual {\n    if (from_ == address(0)) {\n      revert InvalidSender();\n    }\n\n    // Retrieve the latest token added to the owner's stack (LIFO).\n    uint256 id = _owned[from_][_owned[from_].length - 1];\n\n    // Transfer to 0x0.\n    // Does not handle ERC-721 exemptions.\n    _transferERC721(from_, address(0), id);\n\n    // Record the token in the contract's bank queue.\n    _storedERC721Ids.pushFront(id);\n  }\n\n  /// @notice Initialization function to set pairs / etc, saving gas by avoiding mint / burn on unnecessary targets\n  function _setERC721TransferExempt(\n    address target_,\n    bool state_\n  ) internal virtual {\n    if (target_ == address(0)) {\n      revert NotFound();\n    }\n\n    // Adjust the ERC721 balances of the target to respect exemption rules.\n    // Despite this logic, it is still recommended practice to exempt prior to the target\n    // having an active balance.\n    if (state_) {\n      _clearERC721Balance(target_);\n    } else {\n      _reinstateERC721Balance(target_);\n    }\n\n    _erc721TransferExempt[target_] = state_;\n  }\n\n  /// @notice Function to reinstate balance on exemption removal\n  function _reinstateERC721Balance(address target_) private {\n    uint256 expectedERC721Balance = erc20BalanceOf(target_) / units;\n    uint256 actualERC721Balance = erc721BalanceOf(target_);\n\n    for (uint256 i = 0; i < expectedERC721Balance - actualERC721Balance; ) {\n      // Transfer ERC721 balance in from pool\n      _retrieveOrMintERC721(target_);\n      unchecked {\n        ++i;\n      }\n    }\n  }\n\n  /// @notice Function to clear balance on exemption inclusion\n  function _clearERC721Balance(address target_) private {\n    uint256 erc721Balance = erc721BalanceOf(target_);\n\n    for (uint256 i = 0; i < erc721Balance; ) {\n      // Transfer out ERC721 balance\n      _withdrawAndStoreERC721(target_);\n      unchecked {\n        ++i;\n      }\n    }\n  }\n\n  function _getOwnerOf(\n    uint256 id_\n  ) internal view virtual returns (address ownerOf_) {\n    uint256 data = _ownedData[id_];\n\n    assembly {\n      ownerOf_ := and(data, _BITMASK_ADDRESS)\n    }\n  }\n\n  function _setOwnerOf(uint256 id_, address owner_) internal virtual {\n    uint256 data = _ownedData[id_];\n\n    assembly {\n      data := add(\n        and(data, _BITMASK_OWNED_INDEX),\n        and(owner_, _BITMASK_ADDRESS)\n      )\n    }\n\n    _ownedData[id_] = data;\n  }\n\n  function _getOwnedIndex(\n    uint256 id_\n  ) internal view virtual returns (uint256 ownedIndex_) {\n    uint256 data = _ownedData[id_];\n\n    assembly {\n      ownedIndex_ := shr(160, data)\n    }\n  }\n\n  function _setOwnedIndex(uint256 id_, uint256 index_) internal virtual {\n    uint256 data = _ownedData[id_];\n\n    if (index_ > _BITMASK_OWNED_INDEX >> 160) {\n      revert OwnedIndexOverflow();\n    }\n\n    assembly {\n      data := add(\n        and(data, _BITMASK_ADDRESS),\n        and(shl(160, index_), _BITMASK_OWNED_INDEX)\n      )\n    }\n\n    _ownedData[id_] = data;\n  }\n}\n\n\n"
      },
      "contracts/ERC404Factory.sol": {
        "content": "//SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.11;\n\nimport \"./Pandora.sol\";\n\ncontract ERC404Factory {\n    function deployERC404(\n        string memory _name,\n        string memory _symbol,\n        uint256 maxTotalSupplyERC721_\n    ) public returns (address) {\n        Pandora ERC404Address = new Pandora(\n            _name,\n            _symbol,\n            maxTotalSupplyERC721_,\n            msg.sender\n        );\n        address _ERC404Address = address(ERC404Address);\n        return address(_ERC404Address);\n    }\n}\n"
      },
      "contracts/interfaces/IERC404.sol": {
        "content": "//SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"@openzeppelin/contracts/interfaces/IERC165.sol\";\n\ninterface IERC404 is IERC165 {\n    error NotFound();\n    error InvalidTokenId();\n    error AlreadyExists();\n    error InvalidRecipient();\n    error InvalidSender();\n    error InvalidSpender();\n    error InvalidOperator();\n    error UnsafeRecipient();\n    error RecipientIsERC721TransferExempt();\n    error Unauthorized();\n    error InsufficientAllowance();\n    error PermitDeadlineExpired();\n    error InvalidSigner();\n    error InvalidApproval();\n    error OwnedIndexOverflow();\n    error MintLimitReached();\n\n    function name() external view returns (string memory);\n    function symbol() external view returns (string memory);\n    function decimals() external view returns (uint8);\n    function totalSupply() external view returns (uint256);\n    function balanceOf(address owner_) external view returns (uint256);\n    function erc721BalanceOf(address owner_) external view returns (uint256);\n    function allowance(\n      address owner_,\n      address spender_\n    ) external view returns (uint256);\n    function owned(address owner_) external view returns (uint256[] memory);\n    function ownerOf(uint256 id_) external view returns (address erc721Owner);\n    function tokenURI(uint256 id_) external view returns (string memory);\n    function approve(\n        address spender_,\n        uint256 valueOrId_\n    ) external returns (bool);\n    function erc721Approve(address spender_, uint256 id_) external;\n    function transferFrom(\n        address from_,\n        address to_,\n        uint256 valueOrId_\n    ) external returns (bool);\n    function erc721TransferFrom(\n        address from_,\n        address to_,\n        uint256 id_\n    ) external;\n    function transfer(address to_, uint256 amount_) external returns (bool);\n    function safeTransferFrom(address from_, address to_, uint256 id_) external;\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
      },
      "contracts/lib/DoubleEndedQueue.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/DoubleEndedQueue.sol)\n// Modified by Pandora Labs to support native uint256 operations\npragma solidity ^0.8.20;\n\n/**\n * @dev A sequence of items with the ability to efficiently push and pop items (i.e. insert and remove) on both ends of\n * the sequence (called front and back). Among other access patterns, it can be used to implement efficient LIFO and\n * FIFO queues. Storage use is optimized, and all operations are O(1) constant time. This includes {clear}, given that\n * the existing queue contents are left in storage.\n *\n * The struct is called `Uint256Deque`. This data structure can only be used in storage, and not in memory.\n *\n * ```solidity\n * DoubleEndedQueue.Uint256Deque queue;\n * ```\n */\nlibrary DoubleEndedQueue {\n  /**\n   * @dev An operation (e.g. {front}) couldn't be completed due to the queue being empty.\n   */\n  error QueueEmpty();\n\n  /**\n   * @dev A push operation couldn't be completed due to the queue being full.\n   */\n  error QueueFull();\n\n  /**\n   * @dev An operation (e.g. {at}) couldn't be completed due to an index being out of bounds.\n   */\n  error QueueOutOfBounds();\n\n  /**\n   * @dev Indices are 128 bits so begin and end are packed in a single storage slot for efficient access.\n   *\n   * Struct members have an underscore prefix indicating that they are \"private\" and should not be read or written to\n   * directly. Use the functions provided below instead. Modifying the struct manually may violate assumptions and\n   * lead to unexpected behavior.\n   *\n   * The first item is at data[begin] and the last item is at data[end - 1]. This range can wrap around.\n   */\n  struct Uint256Deque {\n    uint128 _begin;\n    uint128 _end;\n    mapping(uint128 index => uint256) _data;\n  }\n\n  /**\n   * @dev Inserts an item at the end of the queue.\n   *\n   * Reverts with {QueueFull} if the queue is full.\n   */\n  function pushBack(Uint256Deque storage deque, uint256 value) internal {\n    unchecked {\n      uint128 backIndex = deque._end;\n      if (backIndex + 1 == deque._begin) revert QueueFull();\n      deque._data[backIndex] = value;\n      deque._end = backIndex + 1;\n    }\n  }\n\n  /**\n   * @dev Removes the item at the end of the queue and returns it.\n   *\n   * Reverts with {QueueEmpty} if the queue is empty.\n   */\n  function popBack(\n    Uint256Deque storage deque\n  ) internal returns (uint256 value) {\n    unchecked {\n      uint128 backIndex = deque._end;\n      if (backIndex == deque._begin) revert QueueEmpty();\n      --backIndex;\n      value = deque._data[backIndex];\n      delete deque._data[backIndex];\n      deque._end = backIndex;\n    }\n  }\n\n  /**\n   * @dev Inserts an item at the beginning of the queue.\n   *\n   * Reverts with {QueueFull} if the queue is full.\n   */\n  function pushFront(Uint256Deque storage deque, uint256 value) internal {\n    unchecked {\n      uint128 frontIndex = deque._begin - 1;\n      if (frontIndex == deque._end) revert QueueFull();\n      deque._data[frontIndex] = value;\n      deque._begin = frontIndex;\n    }\n  }\n\n  /**\n   * @dev Removes the item at the beginning of the queue and returns it.\n   *\n   * Reverts with `QueueEmpty` if the queue is empty.\n   */\n  function popFront(\n    Uint256Deque storage deque\n  ) internal returns (uint256 value) {\n    unchecked {\n      uint128 frontIndex = deque._begin;\n      if (frontIndex == deque._end) revert QueueEmpty();\n      value = deque._data[frontIndex];\n      delete deque._data[frontIndex];\n      deque._begin = frontIndex + 1;\n    }\n  }\n\n  /**\n   * @dev Returns the item at the beginning of the queue.\n   *\n   * Reverts with `QueueEmpty` if the queue is empty.\n   */\n  function front(\n    Uint256Deque storage deque\n  ) internal view returns (uint256 value) {\n    if (empty(deque)) revert QueueEmpty();\n    return deque._data[deque._begin];\n  }\n\n  /**\n   * @dev Returns the item at the end of the queue.\n   *\n   * Reverts with `QueueEmpty` if the queue is empty.\n   */\n  function back(\n    Uint256Deque storage deque\n  ) internal view returns (uint256 value) {\n    if (empty(deque)) revert QueueEmpty();\n    unchecked {\n      return deque._data[deque._end - 1];\n    }\n  }\n\n  /**\n   * @dev Return the item at a position in the queue given by `index`, with the first item at 0 and last item at\n   * `length(deque) - 1`.\n   *\n   * Reverts with `QueueOutOfBounds` if the index is out of bounds.\n   */\n  function at(\n    Uint256Deque storage deque,\n    uint256 index\n  ) internal view returns (uint256 value) {\n    if (index >= length(deque)) revert QueueOutOfBounds();\n    // By construction, length is a uint128, so the check above ensures that index can be safely downcast to uint128\n    unchecked {\n      return deque._data[deque._begin + uint128(index)];\n    }\n  }\n\n  /**\n   * @dev Resets the queue back to being empty.\n   *\n   * NOTE: The current items are left behind in storage. This does not affect the functioning of the queue, but misses\n   * out on potential gas refunds.\n   */\n  function clear(Uint256Deque storage deque) internal {\n    deque._begin = 0;\n    deque._end = 0;\n  }\n\n  /**\n   * @dev Returns the number of items in the queue.\n   */\n  function length(Uint256Deque storage deque) internal view returns (uint256) {\n    unchecked {\n      return uint256(deque._end - deque._begin);\n    }\n  }\n\n  /**\n   * @dev Returns true if the queue is empty.\n   */\n  function empty(Uint256Deque storage deque) internal view returns (bool) {\n    return deque._end == deque._begin;\n  }\n}\n"
      },
      "contracts/lib/ERC20Events.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary ERC20Events {\n  event Approval(address indexed owner, address indexed spender, uint256 value);\n  event Transfer(address indexed from, address indexed to, uint256 amount);\n}\n"
      },
      "contracts/lib/ERC721Events.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary ERC721Events {\n  event ApprovalForAll(\n    address indexed owner,\n    address indexed operator,\n    bool approved\n  );\n  event Approval(\n    address indexed owner,\n    address indexed spender,\n    uint256 indexed id\n  );\n  event Transfer(address indexed from, address indexed to, uint256 indexed id);\n}\n"
      },
      "contracts/Pandora.sol": {
        "content": "//SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\nimport {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport {Strings} from \"@openzeppelin/contracts/utils/Strings.sol\";\nimport {ERC404} from \"./ERC404.sol\";\ncontract Pandora is Ownable, ERC404 {\n    // string public dataURI;\n    string private baseTokenURI;\n    string private GateWay;\n    constructor(\n        string memory name_,\n        string memory symbol_,\n        uint256 maxTotalSupplyERC721_,\n        address initialOwner_\n    )\n        // address initialMintRecipient_\n        ERC404(name_, symbol_)\n        Ownable(initialOwner_)\n    {\n        // Do not mint the ERC721s to the initial owner, as it's a waste of gas.\n        _setERC721TransferExempt(initialOwner_, true);\n        _mintERC20(initialOwner_, maxTotalSupplyERC721_ * units);\n    }\n\n    function setGateway(\n        string memory _gateway,\n        string memory _tokenURI\n    ) public onlyOwner {\n        GateWay = _gateway;\n        baseTokenURI = _tokenURI;\n    }\n    function tokenURI(uint256 id) public view override returns (string memory) {\n        uint256 tokenId = id - (1 << 255);\n        return\n            bytes(baseTokenURI).length > 0\n                ? string.concat(\n                    baseTokenURI,\n                    string.concat(\n                        Strings.toString(tokenId),\n                        string.concat(\".json/\", GateWay)\n                    )\n                )\n                : \"\";\n    }\n}\n"
      }
    },
    "settings": {
      "evmVersion": "paris",
      "optimizer": {
        "enabled": false,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}