ETH Price: $2,433.30 (+0.83%)

Transaction Decoder

Block:
20582486 at Aug-22-2024 06:54:11 AM +UTC
Transaction Fee:
0.000056787799872362 ETH $0.14
Gas Used:
64,103 Gas / 0.885883654 Gwei

Emitted Events:

306 PublicResolver.TextChanged( 0x448bc014f1536726cf8d54ff3d6481ed3cbc683c2591ca204274009afa09b1a1, 0x29d76ad3d622a510cdae93288eef063f141124f74d23bc0ce14f90ffc4ffd08c, 0xd1f86c93d831119ad98fe983e643a7431e4ac992e3ead6e3007f4dd1adf66343, 0000000000000000000000000000000000000000000000000000000000000040, 0000000000000000000000000000000000000000000000000000000000000080, 0000000000000000000000000000000000000000000000000000000000000006, 6176617461720000000000000000000000000000000000000000000000000000, 000000000000000000000000000000000000000000000000000000000000001f, 68747470733a2f2f6575632e6c692f686f6e64616d6f746f72636f2e65746800 )

Account State Difference:

  Address   Before After State Difference Code
0x231b0Ee1...4EB5E8E63
(ENS: Public Resolver)
0x3580dBb2...040f27216
0.031866477096509946 Eth
Nonce: 454
0.031809689296637584 Eth
Nonce: 455
0.000056787799872362
(beaverbuild)
7.913354357944082572 Eth7.913354422047082572 Eth0.000000064103

Execution Trace

PublicResolver.setText( node=29D76AD3D622A510CDAE93288EEF063F141124F74D23BC0CE14F90FFC4FFD08C, key=avatar, value=https://euc.li/hondamotorco.eth )
  • ENSRegistryWithFallback.owner( node=29D76AD3D622A510CDAE93288EEF063F141124F74D23BC0CE14F90FFC4FFD08C ) => ( 0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401 )
  • NameWrapper.ownerOf( id=18925436207053863578775869315166837394565661191974357565102542290897778757772 ) => ( owner=0x3580dBb22BA2e1464C332e0b96aEc58040f27216 )
    File 1 of 3: PublicResolver
    // SPDX-License-Identifier: BSD-2-Clause
    pragma solidity ^0.8.4;
    /**
    * @dev A library for working with mutable byte buffers in Solidity.
    *
    * Byte buffers are mutable and expandable, and provide a variety of primitives
    * for appending to them. At any time you can fetch a bytes object containing the
    * current contents of the buffer. The bytes object should not be stored between
    * operations, as it may change due to resizing of the buffer.
    */
    library Buffer {
        /**
        * @dev Represents a mutable buffer. Buffers have a current value (buf) and
        *      a capacity. The capacity may be longer than the current value, in
        *      which case it can be extended without the need to allocate more memory.
        */
        struct buffer {
            bytes buf;
            uint capacity;
        }
        /**
        * @dev Initializes a buffer with an initial capacity.
        * @param buf The buffer to initialize.
        * @param capacity The number of bytes of space to allocate the buffer.
        * @return The buffer, for chaining.
        */
        function init(buffer memory buf, uint capacity) internal pure returns(buffer memory) {
            if (capacity % 32 != 0) {
                capacity += 32 - (capacity % 32);
            }
            // Allocate space for the buffer data
            buf.capacity = capacity;
            assembly {
                let ptr := mload(0x40)
                mstore(buf, ptr)
                mstore(ptr, 0)
                let fpm := add(32, add(ptr, capacity))
                if lt(fpm, ptr) {
                    revert(0, 0)
                }
                mstore(0x40, fpm)
            }
            return buf;
        }
        /**
        * @dev Initializes a new buffer from an existing bytes object.
        *      Changes to the buffer may mutate the original value.
        * @param b The bytes object to initialize the buffer with.
        * @return A new buffer.
        */
        function fromBytes(bytes memory b) internal pure returns(buffer memory) {
            buffer memory buf;
            buf.buf = b;
            buf.capacity = b.length;
            return buf;
        }
        function resize(buffer memory buf, uint capacity) private pure {
            bytes memory oldbuf = buf.buf;
            init(buf, capacity);
            append(buf, oldbuf);
        }
        /**
        * @dev Sets buffer length to 0.
        * @param buf The buffer to truncate.
        * @return The original buffer, for chaining..
        */
        function truncate(buffer memory buf) internal pure returns (buffer memory) {
            assembly {
                let bufptr := mload(buf)
                mstore(bufptr, 0)
            }
            return buf;
        }
        /**
        * @dev Appends len bytes of a byte string to a buffer. Resizes if doing so would exceed
        *      the capacity of the buffer.
        * @param buf The buffer to append to.
        * @param data The data to append.
        * @param len The number of bytes to copy.
        * @return The original buffer, for chaining.
        */
        function append(buffer memory buf, bytes memory data, uint len) internal pure returns(buffer memory) {
            require(len <= data.length);
            uint off = buf.buf.length;
            uint newCapacity = off + len;
            if (newCapacity > buf.capacity) {
                resize(buf, newCapacity * 2);
            }
            uint dest;
            uint src;
            assembly {
                // Memory address of the buffer data
                let bufptr := mload(buf)
                // Length of existing buffer data
                let buflen := mload(bufptr)
                // Start address = buffer address + offset + sizeof(buffer length)
                dest := add(add(bufptr, 32), off)
                // Update buffer length if we're extending it
                if gt(newCapacity, buflen) {
                    mstore(bufptr, newCapacity)
                }
                src := add(data, 32)
            }
            // Copy word-length chunks while possible
            for (; len >= 32; len -= 32) {
                assembly {
                    mstore(dest, mload(src))
                }
                dest += 32;
                src += 32;
            }
            // Copy remaining bytes
            unchecked {
                uint mask = (256 ** (32 - len)) - 1;
                assembly {
                    let srcpart := and(mload(src), not(mask))
                    let destpart := and(mload(dest), mask)
                    mstore(dest, or(destpart, srcpart))
                }
            }
            return buf;
        }
        /**
        * @dev Appends a byte string to a buffer. Resizes if doing so would exceed
        *      the capacity of the buffer.
        * @param buf The buffer to append to.
        * @param data The data to append.
        * @return The original buffer, for chaining.
        */
        function append(buffer memory buf, bytes memory data) internal pure returns (buffer memory) {
            return append(buf, data, data.length);
        }
        /**
        * @dev Appends a byte to the buffer. Resizes if doing so would exceed the
        *      capacity of the buffer.
        * @param buf The buffer to append to.
        * @param data The data to append.
        * @return The original buffer, for chaining.
        */
        function appendUint8(buffer memory buf, uint8 data) internal pure returns(buffer memory) {
            uint off = buf.buf.length;
            uint offPlusOne = off + 1;
            if (off >= buf.capacity) {
                resize(buf, offPlusOne * 2);
            }
            assembly {
                // Memory address of the buffer data
                let bufptr := mload(buf)
                // Address = buffer address + sizeof(buffer length) + off
                let dest := add(add(bufptr, off), 32)
                mstore8(dest, data)
                // Update buffer length if we extended it
                if gt(offPlusOne, mload(bufptr)) {
                    mstore(bufptr, offPlusOne)
                }
            }
            return buf;
        }
        /**
        * @dev Appends len bytes of bytes32 to a buffer. Resizes if doing so would
        *      exceed the capacity of the buffer.
        * @param buf The buffer to append to.
        * @param data The data to append.
        * @param len The number of bytes to write (left-aligned).
        * @return The original buffer, for chaining.
        */
        function append(buffer memory buf, bytes32 data, uint len) private pure returns(buffer memory) {
            uint off = buf.buf.length;
            uint newCapacity = len + off;
            if (newCapacity > buf.capacity) {
                resize(buf, newCapacity * 2);
            }
            unchecked {
                uint mask = (256 ** len) - 1;
                // Right-align data
                data = data >> (8 * (32 - len));
                assembly {
                    // Memory address of the buffer data
                    let bufptr := mload(buf)
                    // Address = buffer address + sizeof(buffer length) + newCapacity
                    let dest := add(bufptr, newCapacity)
                    mstore(dest, or(and(mload(dest), not(mask)), data))
                    // Update buffer length if we extended it
                    if gt(newCapacity, mload(bufptr)) {
                        mstore(bufptr, newCapacity)
                    }
                }
            }
            return buf;
        }
        /**
        * @dev Appends a bytes20 to the buffer. Resizes if doing so would exceed
        *      the capacity of the buffer.
        * @param buf The buffer to append to.
        * @param data The data to append.
        * @return The original buffer, for chhaining.
        */
        function appendBytes20(buffer memory buf, bytes20 data) internal pure returns (buffer memory) {
            return append(buf, bytes32(data), 20);
        }
        /**
        * @dev Appends a bytes32 to the buffer. Resizes if doing so would exceed
        *      the capacity of the buffer.
        * @param buf The buffer to append to.
        * @param data The data to append.
        * @return The original buffer, for chaining.
        */
        function appendBytes32(buffer memory buf, bytes32 data) internal pure returns (buffer memory) {
            return append(buf, data, 32);
        }
        /**
         * @dev Appends a byte to the end of the buffer. Resizes if doing so would
         *      exceed the capacity of the buffer.
         * @param buf The buffer to append to.
         * @param data The data to append.
         * @param len The number of bytes to write (right-aligned).
         * @return The original buffer.
         */
        function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) {
            uint off = buf.buf.length;
            uint newCapacity = len + off;
            if (newCapacity > buf.capacity) {
                resize(buf, newCapacity * 2);
            }
            uint mask = (256 ** len) - 1;
            assembly {
                // Memory address of the buffer data
                let bufptr := mload(buf)
                // Address = buffer address + sizeof(buffer length) + newCapacity
                let dest := add(bufptr, newCapacity)
                mstore(dest, or(and(mload(dest), not(mask)), data))
                // Update buffer length if we extended it
                if gt(newCapacity, mload(bufptr)) {
                    mstore(bufptr, newCapacity)
                }
            }
            return buf;
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)
    pragma solidity ^0.8.0;
    import "../../utils/introspection/IERC165.sol";
    /**
     * @dev Required interface of an ERC1155 compliant contract, as defined in the
     * https://eips.ethereum.org/EIPS/eip-1155[EIP].
     *
     * _Available since v3.1._
     */
    interface IERC1155 is IERC165 {
        /**
         * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
         */
        event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
        /**
         * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
         * transfers.
         */
        event TransferBatch(
            address indexed operator,
            address indexed from,
            address indexed to,
            uint256[] ids,
            uint256[] values
        );
        /**
         * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
         * `approved`.
         */
        event ApprovalForAll(address indexed account, address indexed operator, bool approved);
        /**
         * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
         *
         * If an {URI} event was emitted for `id`, the standard
         * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
         * returned by {IERC1155MetadataURI-uri}.
         */
        event URI(string value, uint256 indexed id);
        /**
         * @dev Returns the amount of tokens of token type `id` owned by `account`.
         *
         * Requirements:
         *
         * - `account` cannot be the zero address.
         */
        function balanceOf(address account, uint256 id) external view returns (uint256);
        /**
         * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
         *
         * Requirements:
         *
         * - `accounts` and `ids` must have the same length.
         */
        function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
            external
            view
            returns (uint256[] memory);
        /**
         * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
         *
         * Emits an {ApprovalForAll} event.
         *
         * Requirements:
         *
         * - `operator` cannot be the caller.
         */
        function setApprovalForAll(address operator, bool approved) external;
        /**
         * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
         *
         * See {setApprovalForAll}.
         */
        function isApprovedForAll(address account, address operator) external view returns (bool);
        /**
         * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
         *
         * Emits a {TransferSingle} event.
         *
         * Requirements:
         *
         * - `to` cannot be the zero address.
         * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
         * - `from` must have a balance of tokens of type `id` of at least `amount`.
         * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
         * acceptance magic value.
         */
        function safeTransferFrom(
            address from,
            address to,
            uint256 id,
            uint256 amount,
            bytes calldata data
        ) external;
        /**
         * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
         *
         * Emits a {TransferBatch} event.
         *
         * Requirements:
         *
         * - `ids` and `amounts` must have the same length.
         * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
         * acceptance magic value.
         */
        function safeBatchTransferFrom(
            address from,
            address to,
            uint256[] calldata ids,
            uint256[] calldata amounts,
            bytes calldata data
        ) external;
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)
    pragma solidity ^0.8.0;
    import "../../utils/introspection/IERC165.sol";
    /**
     * @dev Required interface of an ERC721 compliant contract.
     */
    interface IERC721 is IERC165 {
        /**
         * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
         */
        event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
        /**
         * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
         */
        event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
        /**
         * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
         */
        event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
        /**
         * @dev Returns the number of tokens in ``owner``'s account.
         */
        function balanceOf(address owner) external view returns (uint256 balance);
        /**
         * @dev Returns the owner of the `tokenId` token.
         *
         * Requirements:
         *
         * - `tokenId` must exist.
         */
        function ownerOf(uint256 tokenId) external view returns (address owner);
        /**
         * @dev Safely transfers `tokenId` token from `from` to `to`.
         *
         * Requirements:
         *
         * - `from` cannot be the zero address.
         * - `to` cannot be the zero address.
         * - `tokenId` token must exist and be owned by `from`.
         * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
         * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
         *
         * Emits a {Transfer} event.
         */
        function safeTransferFrom(
            address from,
            address to,
            uint256 tokenId,
            bytes calldata data
        ) external;
        /**
         * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
         * are aware of the ERC721 protocol to prevent tokens from being forever locked.
         *
         * Requirements:
         *
         * - `from` cannot be the zero address.
         * - `to` cannot be the zero address.
         * - `tokenId` token must exist and be owned by `from`.
         * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
         * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
         *
         * Emits a {Transfer} event.
         */
        function safeTransferFrom(
            address from,
            address to,
            uint256 tokenId
        ) external;
        /**
         * @dev Transfers `tokenId` token from `from` to `to`.
         *
         * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
         * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
         * understand this adds an external call which potentially creates a reentrancy vulnerability.
         *
         * Requirements:
         *
         * - `from` cannot be the zero address.
         * - `to` cannot be the zero address.
         * - `tokenId` token must be owned by `from`.
         * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
         *
         * Emits a {Transfer} event.
         */
        function transferFrom(
            address from,
            address to,
            uint256 tokenId
        ) external;
        /**
         * @dev Gives permission to `to` to transfer `tokenId` token to another account.
         * The approval is cleared when the token is transferred.
         *
         * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
         *
         * Requirements:
         *
         * - The caller must own the token or be an approved operator.
         * - `tokenId` must exist.
         *
         * Emits an {Approval} event.
         */
        function approve(address to, uint256 tokenId) external;
        /**
         * @dev Approve or remove `operator` as an operator for the caller.
         * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
         *
         * Requirements:
         *
         * - The `operator` cannot be the caller.
         *
         * Emits an {ApprovalForAll} event.
         */
        function setApprovalForAll(address operator, bool _approved) external;
        /**
         * @dev Returns the account approved for `tokenId` token.
         *
         * Requirements:
         *
         * - `tokenId` must exist.
         */
        function getApproved(uint256 tokenId) external view returns (address operator);
        /**
         * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
         *
         * See {setApprovalForAll}
         */
        function isApprovedForAll(address owner, address operator) external view returns (bool);
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
    pragma solidity ^0.8.0;
    import "./IERC165.sol";
    /**
     * @dev Implementation of the {IERC165} interface.
     *
     * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
     * for the additional interface id that will be supported. For example:
     *
     * ```solidity
     * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
     *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
     * }
     * ```
     *
     * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
     */
    abstract contract ERC165 is IERC165 {
        /**
         * @dev See {IERC165-supportsInterface}.
         */
        function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
            return interfaceId == type(IERC165).interfaceId;
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
    pragma solidity ^0.8.0;
    /**
     * @dev Interface of the ERC165 standard, as defined in the
     * https://eips.ethereum.org/EIPS/eip-165[EIP].
     *
     * Implementers can declare support of contract interfaces, which can then be
     * queried by others ({ERC165Checker}).
     *
     * For an implementation, see {ERC165}.
     */
    interface IERC165 {
        /**
         * @dev Returns true if this contract implements the interface defined by
         * `interfaceId`. See the corresponding
         * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
         * to learn more about how these ids are created.
         *
         * This function call must use less than 30 000 gas.
         */
        function supportsInterface(bytes4 interfaceId) external view returns (bool);
    }
    pragma solidity ^0.8.4;
    library BytesUtils {
        error OffsetOutOfBoundsError(uint256 offset, uint256 length);
        /*
         * @dev Returns the keccak-256 hash of a byte range.
         * @param self The byte string to hash.
         * @param offset The position to start hashing at.
         * @param len The number of bytes to hash.
         * @return The hash of the byte range.
         */
        function keccak(
            bytes memory self,
            uint256 offset,
            uint256 len
        ) internal pure returns (bytes32 ret) {
            require(offset + len <= self.length);
            assembly {
                ret := keccak256(add(add(self, 32), offset), len)
            }
        }
        /*
         * @dev Returns a positive number if `other` comes lexicographically after
         *      `self`, a negative number if it comes before, or zero if the
         *      contents of the two bytes are equal.
         * @param self The first bytes to compare.
         * @param other The second bytes to compare.
         * @return The result of the comparison.
         */
        function compare(
            bytes memory self,
            bytes memory other
        ) internal pure returns (int256) {
            return compare(self, 0, self.length, other, 0, other.length);
        }
        /*
         * @dev Returns a positive number if `other` comes lexicographically after
         *      `self`, a negative number if it comes before, or zero if the
         *      contents of the two bytes are equal. Comparison is done per-rune,
         *      on unicode codepoints.
         * @param self The first bytes to compare.
         * @param offset The offset of self.
         * @param len    The length of self.
         * @param other The second bytes to compare.
         * @param otheroffset The offset of the other string.
         * @param otherlen    The length of the other string.
         * @return The result of the comparison.
         */
        function compare(
            bytes memory self,
            uint256 offset,
            uint256 len,
            bytes memory other,
            uint256 otheroffset,
            uint256 otherlen
        ) internal pure returns (int256) {
            if (offset + len > self.length) {
                revert OffsetOutOfBoundsError(offset + len, self.length);
            }
            if (otheroffset + otherlen > other.length) {
                revert OffsetOutOfBoundsError(otheroffset + otherlen, other.length);
            }
            uint256 shortest = len;
            if (otherlen < len) shortest = otherlen;
            uint256 selfptr;
            uint256 otherptr;
            assembly {
                selfptr := add(self, add(offset, 32))
                otherptr := add(other, add(otheroffset, 32))
            }
            for (uint256 idx = 0; idx < shortest; idx += 32) {
                uint256 a;
                uint256 b;
                assembly {
                    a := mload(selfptr)
                    b := mload(otherptr)
                }
                if (a != b) {
                    // Mask out irrelevant bytes and check again
                    uint256 mask;
                    if (shortest - idx >= 32) {
                        mask = type(uint256).max;
                    } else {
                        mask = ~(2 ** (8 * (idx + 32 - shortest)) - 1);
                    }
                    int256 diff = int256(a & mask) - int256(b & mask);
                    if (diff != 0) return diff;
                }
                selfptr += 32;
                otherptr += 32;
            }
            return int256(len) - int256(otherlen);
        }
        /*
         * @dev Returns true if the two byte ranges are equal.
         * @param self The first byte range to compare.
         * @param offset The offset into the first byte range.
         * @param other The second byte range to compare.
         * @param otherOffset The offset into the second byte range.
         * @param len The number of bytes to compare
         * @return True if the byte ranges are equal, false otherwise.
         */
        function equals(
            bytes memory self,
            uint256 offset,
            bytes memory other,
            uint256 otherOffset,
            uint256 len
        ) internal pure returns (bool) {
            return keccak(self, offset, len) == keccak(other, otherOffset, len);
        }
        /*
         * @dev Returns true if the two byte ranges are equal with offsets.
         * @param self The first byte range to compare.
         * @param offset The offset into the first byte range.
         * @param other The second byte range to compare.
         * @param otherOffset The offset into the second byte range.
         * @return True if the byte ranges are equal, false otherwise.
         */
        function equals(
            bytes memory self,
            uint256 offset,
            bytes memory other,
            uint256 otherOffset
        ) internal pure returns (bool) {
            return
                keccak(self, offset, self.length - offset) ==
                keccak(other, otherOffset, other.length - otherOffset);
        }
        /*
         * @dev Compares a range of 'self' to all of 'other' and returns True iff
         *      they are equal.
         * @param self The first byte range to compare.
         * @param offset The offset into the first byte range.
         * @param other The second byte range to compare.
         * @return True if the byte ranges are equal, false otherwise.
         */
        function equals(
            bytes memory self,
            uint256 offset,
            bytes memory other
        ) internal pure returns (bool) {
            return
                self.length == offset + other.length &&
                equals(self, offset, other, 0, other.length);
        }
        /*
         * @dev Returns true if the two byte ranges are equal.
         * @param self The first byte range to compare.
         * @param other The second byte range to compare.
         * @return True if the byte ranges are equal, false otherwise.
         */
        function equals(
            bytes memory self,
            bytes memory other
        ) internal pure returns (bool) {
            return
                self.length == other.length &&
                equals(self, 0, other, 0, self.length);
        }
        /*
         * @dev Returns the 8-bit number at the specified index of self.
         * @param self The byte string.
         * @param idx The index into the bytes
         * @return The specified 8 bits of the string, interpreted as an integer.
         */
        function readUint8(
            bytes memory self,
            uint256 idx
        ) internal pure returns (uint8 ret) {
            return uint8(self[idx]);
        }
        /*
         * @dev Returns the 16-bit number at the specified index of self.
         * @param self The byte string.
         * @param idx The index into the bytes
         * @return The specified 16 bits of the string, interpreted as an integer.
         */
        function readUint16(
            bytes memory self,
            uint256 idx
        ) internal pure returns (uint16 ret) {
            require(idx + 2 <= self.length);
            assembly {
                ret := and(mload(add(add(self, 2), idx)), 0xFFFF)
            }
        }
        /*
         * @dev Returns the 32-bit number at the specified index of self.
         * @param self The byte string.
         * @param idx The index into the bytes
         * @return The specified 32 bits of the string, interpreted as an integer.
         */
        function readUint32(
            bytes memory self,
            uint256 idx
        ) internal pure returns (uint32 ret) {
            require(idx + 4 <= self.length);
            assembly {
                ret := and(mload(add(add(self, 4), idx)), 0xFFFFFFFF)
            }
        }
        /*
         * @dev Returns the 32 byte value at the specified index of self.
         * @param self The byte string.
         * @param idx The index into the bytes
         * @return The specified 32 bytes of the string.
         */
        function readBytes32(
            bytes memory self,
            uint256 idx
        ) internal pure returns (bytes32 ret) {
            require(idx + 32 <= self.length);
            assembly {
                ret := mload(add(add(self, 32), idx))
            }
        }
        /*
         * @dev Returns the 32 byte value at the specified index of self.
         * @param self The byte string.
         * @param idx The index into the bytes
         * @return The specified 32 bytes of the string.
         */
        function readBytes20(
            bytes memory self,
            uint256 idx
        ) internal pure returns (bytes20 ret) {
            require(idx + 20 <= self.length);
            assembly {
                ret := and(
                    mload(add(add(self, 32), idx)),
                    0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000000
                )
            }
        }
        /*
         * @dev Returns the n byte value at the specified index of self.
         * @param self The byte string.
         * @param idx The index into the bytes.
         * @param len The number of bytes.
         * @return The specified 32 bytes of the string.
         */
        function readBytesN(
            bytes memory self,
            uint256 idx,
            uint256 len
        ) internal pure returns (bytes32 ret) {
            require(len <= 32);
            require(idx + len <= self.length);
            assembly {
                let mask := not(sub(exp(256, sub(32, len)), 1))
                ret := and(mload(add(add(self, 32), idx)), mask)
            }
        }
        function memcpy(uint256 dest, uint256 src, uint256 len) private pure {
            // Copy word-length chunks while possible
            for (; len >= 32; len -= 32) {
                assembly {
                    mstore(dest, mload(src))
                }
                dest += 32;
                src += 32;
            }
            // Copy remaining bytes
            unchecked {
                uint256 mask = (256 ** (32 - len)) - 1;
                assembly {
                    let srcpart := and(mload(src), not(mask))
                    let destpart := and(mload(dest), mask)
                    mstore(dest, or(destpart, srcpart))
                }
            }
        }
        /*
         * @dev Copies a substring into a new byte string.
         * @param self The byte string to copy from.
         * @param offset The offset to start copying at.
         * @param len The number of bytes to copy.
         */
        function substring(
            bytes memory self,
            uint256 offset,
            uint256 len
        ) internal pure returns (bytes memory) {
            require(offset + len <= self.length);
            bytes memory ret = new bytes(len);
            uint256 dest;
            uint256 src;
            assembly {
                dest := add(ret, 32)
                src := add(add(self, 32), offset)
            }
            memcpy(dest, src, len);
            return ret;
        }
        // Maps characters from 0x30 to 0x7A to their base32 values.
        // 0xFF represents invalid characters in that range.
        bytes constant base32HexTable =
            hex"00010203040506070809FFFFFFFFFFFFFF0A0B0C0D0E0F101112131415161718191A1B1C1D1E1FFFFFFFFFFFFFFFFFFFFF0A0B0C0D0E0F101112131415161718191A1B1C1D1E1F";
        /**
         * @dev Decodes unpadded base32 data of up to one word in length.
         * @param self The data to decode.
         * @param off Offset into the string to start at.
         * @param len Number of characters to decode.
         * @return The decoded data, left aligned.
         */
        function base32HexDecodeWord(
            bytes memory self,
            uint256 off,
            uint256 len
        ) internal pure returns (bytes32) {
            require(len <= 52);
            uint256 ret = 0;
            uint8 decoded;
            for (uint256 i = 0; i < len; i++) {
                bytes1 char = self[off + i];
                require(char >= 0x30 && char <= 0x7A);
                decoded = uint8(base32HexTable[uint256(uint8(char)) - 0x30]);
                require(decoded <= 0x20);
                if (i == len - 1) {
                    break;
                }
                ret = (ret << 5) | decoded;
            }
            uint256 bitlen = len * 5;
            if (len % 8 == 0) {
                // Multiple of 8 characters, no padding
                ret = (ret << 5) | decoded;
            } else if (len % 8 == 2) {
                // Two extra characters - 1 byte
                ret = (ret << 3) | (decoded >> 2);
                bitlen -= 2;
            } else if (len % 8 == 4) {
                // Four extra characters - 2 bytes
                ret = (ret << 1) | (decoded >> 4);
                bitlen -= 4;
            } else if (len % 8 == 5) {
                // Five extra characters - 3 bytes
                ret = (ret << 4) | (decoded >> 1);
                bitlen -= 1;
            } else if (len % 8 == 7) {
                // Seven extra characters - 4 bytes
                ret = (ret << 2) | (decoded >> 3);
                bitlen -= 3;
            } else {
                revert();
            }
            return bytes32(ret << (256 - bitlen));
        }
        /**
         * @dev Finds the first occurrence of the byte `needle` in `self`.
         * @param self The string to search
         * @param off The offset to start searching at
         * @param len The number of bytes to search
         * @param needle The byte to search for
         * @return The offset of `needle` in `self`, or 2**256-1 if it was not found.
         */
        function find(
            bytes memory self,
            uint256 off,
            uint256 len,
            bytes1 needle
        ) internal pure returns (uint256) {
            for (uint256 idx = off; idx < off + len; idx++) {
                if (self[idx] == needle) {
                    return idx;
                }
            }
            return type(uint256).max;
        }
    }
    pragma solidity ^0.8.4;
    import "./BytesUtils.sol";
    import "@ensdomains/buffer/contracts/Buffer.sol";
    /**
     * @dev RRUtils is a library that provides utilities for parsing DNS resource records.
     */
    library RRUtils {
        using BytesUtils for *;
        using Buffer for *;
        /**
         * @dev Returns the number of bytes in the DNS name at 'offset' in 'self'.
         * @param self The byte array to read a name from.
         * @param offset The offset to start reading at.
         * @return The length of the DNS name at 'offset', in bytes.
         */
        function nameLength(
            bytes memory self,
            uint256 offset
        ) internal pure returns (uint256) {
            uint256 idx = offset;
            while (true) {
                assert(idx < self.length);
                uint256 labelLen = self.readUint8(idx);
                idx += labelLen + 1;
                if (labelLen == 0) {
                    break;
                }
            }
            return idx - offset;
        }
        /**
         * @dev Returns a DNS format name at the specified offset of self.
         * @param self The byte array to read a name from.
         * @param offset The offset to start reading at.
         * @return ret The name.
         */
        function readName(
            bytes memory self,
            uint256 offset
        ) internal pure returns (bytes memory ret) {
            uint256 len = nameLength(self, offset);
            return self.substring(offset, len);
        }
        /**
         * @dev Returns the number of labels in the DNS name at 'offset' in 'self'.
         * @param self The byte array to read a name from.
         * @param offset The offset to start reading at.
         * @return The number of labels in the DNS name at 'offset', in bytes.
         */
        function labelCount(
            bytes memory self,
            uint256 offset
        ) internal pure returns (uint256) {
            uint256 count = 0;
            while (true) {
                assert(offset < self.length);
                uint256 labelLen = self.readUint8(offset);
                offset += labelLen + 1;
                if (labelLen == 0) {
                    break;
                }
                count += 1;
            }
            return count;
        }
        uint256 constant RRSIG_TYPE = 0;
        uint256 constant RRSIG_ALGORITHM = 2;
        uint256 constant RRSIG_LABELS = 3;
        uint256 constant RRSIG_TTL = 4;
        uint256 constant RRSIG_EXPIRATION = 8;
        uint256 constant RRSIG_INCEPTION = 12;
        uint256 constant RRSIG_KEY_TAG = 16;
        uint256 constant RRSIG_SIGNER_NAME = 18;
        struct SignedSet {
            uint16 typeCovered;
            uint8 algorithm;
            uint8 labels;
            uint32 ttl;
            uint32 expiration;
            uint32 inception;
            uint16 keytag;
            bytes signerName;
            bytes data;
            bytes name;
        }
        function readSignedSet(
            bytes memory data
        ) internal pure returns (SignedSet memory self) {
            self.typeCovered = data.readUint16(RRSIG_TYPE);
            self.algorithm = data.readUint8(RRSIG_ALGORITHM);
            self.labels = data.readUint8(RRSIG_LABELS);
            self.ttl = data.readUint32(RRSIG_TTL);
            self.expiration = data.readUint32(RRSIG_EXPIRATION);
            self.inception = data.readUint32(RRSIG_INCEPTION);
            self.keytag = data.readUint16(RRSIG_KEY_TAG);
            self.signerName = readName(data, RRSIG_SIGNER_NAME);
            self.data = data.substring(
                RRSIG_SIGNER_NAME + self.signerName.length,
                data.length - RRSIG_SIGNER_NAME - self.signerName.length
            );
        }
        function rrs(
            SignedSet memory rrset
        ) internal pure returns (RRIterator memory) {
            return iterateRRs(rrset.data, 0);
        }
        /**
         * @dev An iterator over resource records.
         */
        struct RRIterator {
            bytes data;
            uint256 offset;
            uint16 dnstype;
            uint16 class;
            uint32 ttl;
            uint256 rdataOffset;
            uint256 nextOffset;
        }
        /**
         * @dev Begins iterating over resource records.
         * @param self The byte string to read from.
         * @param offset The offset to start reading at.
         * @return ret An iterator object.
         */
        function iterateRRs(
            bytes memory self,
            uint256 offset
        ) internal pure returns (RRIterator memory ret) {
            ret.data = self;
            ret.nextOffset = offset;
            next(ret);
        }
        /**
         * @dev Returns true iff there are more RRs to iterate.
         * @param iter The iterator to check.
         * @return True iff the iterator has finished.
         */
        function done(RRIterator memory iter) internal pure returns (bool) {
            return iter.offset >= iter.data.length;
        }
        /**
         * @dev Moves the iterator to the next resource record.
         * @param iter The iterator to advance.
         */
        function next(RRIterator memory iter) internal pure {
            iter.offset = iter.nextOffset;
            if (iter.offset >= iter.data.length) {
                return;
            }
            // Skip the name
            uint256 off = iter.offset + nameLength(iter.data, iter.offset);
            // Read type, class, and ttl
            iter.dnstype = iter.data.readUint16(off);
            off += 2;
            iter.class = iter.data.readUint16(off);
            off += 2;
            iter.ttl = iter.data.readUint32(off);
            off += 4;
            // Read the rdata
            uint256 rdataLength = iter.data.readUint16(off);
            off += 2;
            iter.rdataOffset = off;
            iter.nextOffset = off + rdataLength;
        }
        /**
         * @dev Returns the name of the current record.
         * @param iter The iterator.
         * @return A new bytes object containing the owner name from the RR.
         */
        function name(RRIterator memory iter) internal pure returns (bytes memory) {
            return
                iter.data.substring(
                    iter.offset,
                    nameLength(iter.data, iter.offset)
                );
        }
        /**
         * @dev Returns the rdata portion of the current record.
         * @param iter The iterator.
         * @return A new bytes object containing the RR's RDATA.
         */
        function rdata(
            RRIterator memory iter
        ) internal pure returns (bytes memory) {
            return
                iter.data.substring(
                    iter.rdataOffset,
                    iter.nextOffset - iter.rdataOffset
                );
        }
        uint256 constant DNSKEY_FLAGS = 0;
        uint256 constant DNSKEY_PROTOCOL = 2;
        uint256 constant DNSKEY_ALGORITHM = 3;
        uint256 constant DNSKEY_PUBKEY = 4;
        struct DNSKEY {
            uint16 flags;
            uint8 protocol;
            uint8 algorithm;
            bytes publicKey;
        }
        function readDNSKEY(
            bytes memory data,
            uint256 offset,
            uint256 length
        ) internal pure returns (DNSKEY memory self) {
            self.flags = data.readUint16(offset + DNSKEY_FLAGS);
            self.protocol = data.readUint8(offset + DNSKEY_PROTOCOL);
            self.algorithm = data.readUint8(offset + DNSKEY_ALGORITHM);
            self.publicKey = data.substring(
                offset + DNSKEY_PUBKEY,
                length - DNSKEY_PUBKEY
            );
        }
        uint256 constant DS_KEY_TAG = 0;
        uint256 constant DS_ALGORITHM = 2;
        uint256 constant DS_DIGEST_TYPE = 3;
        uint256 constant DS_DIGEST = 4;
        struct DS {
            uint16 keytag;
            uint8 algorithm;
            uint8 digestType;
            bytes digest;
        }
        function readDS(
            bytes memory data,
            uint256 offset,
            uint256 length
        ) internal pure returns (DS memory self) {
            self.keytag = data.readUint16(offset + DS_KEY_TAG);
            self.algorithm = data.readUint8(offset + DS_ALGORITHM);
            self.digestType = data.readUint8(offset + DS_DIGEST_TYPE);
            self.digest = data.substring(offset + DS_DIGEST, length - DS_DIGEST);
        }
        function isSubdomainOf(
            bytes memory self,
            bytes memory other
        ) internal pure returns (bool) {
            uint256 off = 0;
            uint256 counts = labelCount(self, 0);
            uint256 othercounts = labelCount(other, 0);
            while (counts > othercounts) {
                off = progress(self, off);
                counts--;
            }
            return self.equals(off, other, 0);
        }
        function compareNames(
            bytes memory self,
            bytes memory other
        ) internal pure returns (int256) {
            if (self.equals(other)) {
                return 0;
            }
            uint256 off;
            uint256 otheroff;
            uint256 prevoff;
            uint256 otherprevoff;
            uint256 counts = labelCount(self, 0);
            uint256 othercounts = labelCount(other, 0);
            // Keep removing labels from the front of the name until both names are equal length
            while (counts > othercounts) {
                prevoff = off;
                off = progress(self, off);
                counts--;
            }
            while (othercounts > counts) {
                otherprevoff = otheroff;
                otheroff = progress(other, otheroff);
                othercounts--;
            }
            // Compare the last nonequal labels to each other
            while (counts > 0 && !self.equals(off, other, otheroff)) {
                prevoff = off;
                off = progress(self, off);
                otherprevoff = otheroff;
                otheroff = progress(other, otheroff);
                counts -= 1;
            }
            if (off == 0) {
                return -1;
            }
            if (otheroff == 0) {
                return 1;
            }
            return
                self.compare(
                    prevoff + 1,
                    self.readUint8(prevoff),
                    other,
                    otherprevoff + 1,
                    other.readUint8(otherprevoff)
                );
        }
        /**
         * @dev Compares two serial numbers using RFC1982 serial number math.
         */
        function serialNumberGte(
            uint32 i1,
            uint32 i2
        ) internal pure returns (bool) {
            unchecked {
                return int32(i1) - int32(i2) >= 0;
            }
        }
        function progress(
            bytes memory body,
            uint256 off
        ) internal pure returns (uint256) {
            return off + 1 + body.readUint8(off);
        }
        /**
         * @dev Computes the keytag for a chunk of data.
         * @param data The data to compute a keytag for.
         * @return The computed key tag.
         */
        function computeKeytag(bytes memory data) internal pure returns (uint16) {
            /* This function probably deserves some explanation.
             * The DNSSEC keytag function is a checksum that relies on summing up individual bytes
             * from the input string, with some mild bitshifting. Here's a Naive solidity implementation:
             *
             *     function computeKeytag(bytes memory data) internal pure returns (uint16) {
             *         uint ac;
             *         for (uint i = 0; i < data.length; i++) {
             *             ac += i & 1 == 0 ? uint16(data.readUint8(i)) << 8 : data.readUint8(i);
             *         }
             *         return uint16(ac + (ac >> 16));
             *     }
             *
             * The EVM, with its 256 bit words, is exceedingly inefficient at doing byte-by-byte operations;
             * the code above, on reasonable length inputs, consumes over 100k gas. But we can make the EVM's
             * large words work in our favour.
             *
             * The code below works by treating the input as a series of 256 bit words. It first masks out
             * even and odd bytes from each input word, adding them to two separate accumulators `ac1` and `ac2`.
             * The bytes are separated by empty bytes, so as long as no individual sum exceeds 2^16-1, we're
             * effectively summing 16 different numbers with each EVM ADD opcode.
             *
             * Once it's added up all the inputs, it has to add all the 16 bit values in `ac1` and `ac2` together.
             * It does this using the same trick - mask out every other value, shift to align them, add them together.
             * After the first addition on both accumulators, there's enough room to add the two accumulators together,
             * and the remaining sums can be done just on ac1.
             */
            unchecked {
                require(data.length <= 8192, "Long keys not permitted");
                uint256 ac1;
                uint256 ac2;
                for (uint256 i = 0; i < data.length + 31; i += 32) {
                    uint256 word;
                    assembly {
                        word := mload(add(add(data, 32), i))
                    }
                    if (i + 32 > data.length) {
                        uint256 unused = 256 - (data.length - i) * 8;
                        word = (word >> unused) << unused;
                    }
                    ac1 +=
                        (word &
                            0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00) >>
                        8;
                    ac2 += (word &
                        0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF);
                }
                ac1 =
                    (ac1 &
                        0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) +
                    ((ac1 &
                        0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000) >>
                        16);
                ac2 =
                    (ac2 &
                        0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) +
                    ((ac2 &
                        0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000) >>
                        16);
                ac1 = (ac1 << 8) + ac2;
                ac1 =
                    (ac1 &
                        0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) +
                    ((ac1 &
                        0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000) >>
                        32);
                ac1 =
                    (ac1 &
                        0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) +
                    ((ac1 &
                        0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000) >>
                        64);
                ac1 =
                    (ac1 &
                        0x00000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) +
                    (ac1 >> 128);
                ac1 += (ac1 >> 16) & 0xFFFF;
                return uint16(ac1);
            }
        }
    }
    import "../registry/ENS.sol";
    import "./IBaseRegistrar.sol";
    import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
    interface IBaseRegistrar is IERC721 {
        event ControllerAdded(address indexed controller);
        event ControllerRemoved(address indexed controller);
        event NameMigrated(
            uint256 indexed id,
            address indexed owner,
            uint256 expires
        );
        event NameRegistered(
            uint256 indexed id,
            address indexed owner,
            uint256 expires
        );
        event NameRenewed(uint256 indexed id, uint256 expires);
        // Authorises a controller, who can register and renew domains.
        function addController(address controller) external;
        // Revoke controller permission for an address.
        function removeController(address controller) external;
        // Set the resolver for the TLD this registrar manages.
        function setResolver(address resolver) external;
        // Returns the expiration timestamp of the specified label hash.
        function nameExpires(uint256 id) external view returns (uint256);
        // Returns true iff the specified name is available for registration.
        function available(uint256 id) external view returns (bool);
        /**
         * @dev Register a name.
         */
        function register(
            uint256 id,
            address owner,
            uint256 duration
        ) external returns (uint256);
        function renew(uint256 id, uint256 duration) external returns (uint256);
        /**
         * @dev Reclaim ownership of a name in ENS, if you own it in the registrar.
         */
        function reclaim(uint256 id, address owner) external;
    }
    pragma solidity >=0.8.4;
    interface ENS {
        // Logged when the owner of a node assigns a new owner to a subnode.
        event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);
        // Logged when the owner of a node transfers ownership to a new account.
        event Transfer(bytes32 indexed node, address owner);
        // Logged when the resolver for a node changes.
        event NewResolver(bytes32 indexed node, address resolver);
        // Logged when the TTL of a node changes
        event NewTTL(bytes32 indexed node, uint64 ttl);
        // Logged when an operator is added or removed.
        event ApprovalForAll(
            address indexed owner,
            address indexed operator,
            bool approved
        );
        function setRecord(
            bytes32 node,
            address owner,
            address resolver,
            uint64 ttl
        ) external;
        function setSubnodeRecord(
            bytes32 node,
            bytes32 label,
            address owner,
            address resolver,
            uint64 ttl
        ) external;
        function setSubnodeOwner(
            bytes32 node,
            bytes32 label,
            address owner
        ) external returns (bytes32);
        function setResolver(bytes32 node, address resolver) external;
        function setOwner(bytes32 node, address owner) external;
        function setTTL(bytes32 node, uint64 ttl) external;
        function setApprovalForAll(address operator, bool approved) external;
        function owner(bytes32 node) external view returns (address);
        function resolver(bytes32 node) external view returns (address);
        function ttl(bytes32 node) external view returns (uint64);
        function recordExists(bytes32 node) external view returns (bool);
        function isApprovedForAll(
            address owner,
            address operator
        ) external view returns (bool);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.4;
    interface IMulticallable {
        function multicall(
            bytes[] calldata data
        ) external returns (bytes[] memory results);
        function multicallWithNodeCheck(
            bytes32,
            bytes[] calldata data
        ) external returns (bytes[] memory results);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.4;
    import "./IMulticallable.sol";
    import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
    abstract contract Multicallable is IMulticallable, ERC165 {
        function _multicall(
            bytes32 nodehash,
            bytes[] calldata data
        ) internal returns (bytes[] memory results) {
            results = new bytes[](data.length);
            for (uint256 i = 0; i < data.length; i++) {
                if (nodehash != bytes32(0)) {
                    bytes32 txNamehash = bytes32(data[i][4:36]);
                    require(
                        txNamehash == nodehash,
                        "multicall: All records must have a matching namehash"
                    );
                }
                (bool success, bytes memory result) = address(this).delegatecall(
                    data[i]
                );
                require(success);
                results[i] = result;
            }
            return results;
        }
        // This function provides an extra security check when called
        // from priviledged contracts (such as EthRegistrarController)
        // that can set records on behalf of the node owners
        function multicallWithNodeCheck(
            bytes32 nodehash,
            bytes[] calldata data
        ) external returns (bytes[] memory results) {
            return _multicall(nodehash, data);
        }
        function multicall(
            bytes[] calldata data
        ) public override returns (bytes[] memory results) {
            return _multicall(bytes32(0), data);
        }
        function supportsInterface(
            bytes4 interfaceID
        ) public view virtual override returns (bool) {
            return
                interfaceID == type(IMulticallable).interfaceId ||
                super.supportsInterface(interfaceID);
        }
    }
    //SPDX-License-Identifier: MIT
    pragma solidity >=0.8.17 <0.9.0;
    import "../registry/ENS.sol";
    import "./profiles/ABIResolver.sol";
    import "./profiles/AddrResolver.sol";
    import "./profiles/ContentHashResolver.sol";
    import "./profiles/DNSResolver.sol";
    import "./profiles/InterfaceResolver.sol";
    import "./profiles/NameResolver.sol";
    import "./profiles/PubkeyResolver.sol";
    import "./profiles/TextResolver.sol";
    import "./Multicallable.sol";
    import {ReverseClaimer} from "../reverseRegistrar/ReverseClaimer.sol";
    import {INameWrapper} from "../wrapper/INameWrapper.sol";
    /**
     * A simple resolver anyone can use; only allows the owner of a node to set its
     * address.
     */
    contract PublicResolver is
        Multicallable,
        ABIResolver,
        AddrResolver,
        ContentHashResolver,
        DNSResolver,
        InterfaceResolver,
        NameResolver,
        PubkeyResolver,
        TextResolver,
        ReverseClaimer
    {
        ENS immutable ens;
        INameWrapper immutable nameWrapper;
        address immutable trustedETHController;
        address immutable trustedReverseRegistrar;
        /**
         * A mapping of operators. An address that is authorised for an address
         * may make any changes to the name that the owner could, but may not update
         * the set of authorisations.
         * (owner, operator) => approved
         */
        mapping(address => mapping(address => bool)) private _operatorApprovals;
        /**
         * A mapping of delegates. A delegate that is authorised by an owner
         * for a name may make changes to the name's resolver, but may not update
         * the set of token approvals.
         * (owner, name, delegate) => approved
         */
        mapping(address => mapping(bytes32 => mapping(address => bool)))
            private _tokenApprovals;
        // Logged when an operator is added or removed.
        event ApprovalForAll(
            address indexed owner,
            address indexed operator,
            bool approved
        );
        // Logged when a delegate is approved or  an approval is revoked.
        event Approved(
            address owner,
            bytes32 indexed node,
            address indexed delegate,
            bool indexed approved
        );
        constructor(
            ENS _ens,
            INameWrapper wrapperAddress,
            address _trustedETHController,
            address _trustedReverseRegistrar
        ) ReverseClaimer(_ens, msg.sender) {
            ens = _ens;
            nameWrapper = wrapperAddress;
            trustedETHController = _trustedETHController;
            trustedReverseRegistrar = _trustedReverseRegistrar;
        }
        /**
         * @dev See {IERC1155-setApprovalForAll}.
         */
        function setApprovalForAll(address operator, bool approved) external {
            require(
                msg.sender != operator,
                "ERC1155: setting approval status for self"
            );
            _operatorApprovals[msg.sender][operator] = approved;
            emit ApprovalForAll(msg.sender, operator, approved);
        }
        /**
         * @dev See {IERC1155-isApprovedForAll}.
         */
        function isApprovedForAll(
            address account,
            address operator
        ) public view returns (bool) {
            return _operatorApprovals[account][operator];
        }
        /**
         * @dev Approve a delegate to be able to updated records on a node.
         */
        function approve(bytes32 node, address delegate, bool approved) external {
            require(msg.sender != delegate, "Setting delegate status for self");
            _tokenApprovals[msg.sender][node][delegate] = approved;
            emit Approved(msg.sender, node, delegate, approved);
        }
        /**
         * @dev Check to see if the delegate has been approved by the owner for the node.
         */
        function isApprovedFor(
            address owner,
            bytes32 node,
            address delegate
        ) public view returns (bool) {
            return _tokenApprovals[owner][node][delegate];
        }
        function isAuthorised(bytes32 node) internal view override returns (bool) {
            if (
                msg.sender == trustedETHController ||
                msg.sender == trustedReverseRegistrar
            ) {
                return true;
            }
            address owner = ens.owner(node);
            if (owner == address(nameWrapper)) {
                owner = nameWrapper.ownerOf(uint256(node));
            }
            return
                owner == msg.sender ||
                isApprovedForAll(owner, msg.sender) ||
                isApprovedFor(owner, node, msg.sender);
        }
        function supportsInterface(
            bytes4 interfaceID
        )
            public
            view
            override(
                Multicallable,
                ABIResolver,
                AddrResolver,
                ContentHashResolver,
                DNSResolver,
                InterfaceResolver,
                NameResolver,
                PubkeyResolver,
                TextResolver
            )
            returns (bool)
        {
            return super.supportsInterface(interfaceID);
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
    import "./profiles/IVersionableResolver.sol";
    abstract contract ResolverBase is ERC165, IVersionableResolver {
        mapping(bytes32 => uint64) public recordVersions;
        function isAuthorised(bytes32 node) internal view virtual returns (bool);
        modifier authorised(bytes32 node) {
            require(isAuthorised(node));
            _;
        }
        /**
         * Increments the record version associated with an ENS node.
         * May only be called by the owner of that node in the ENS registry.
         * @param node The node to update.
         */
        function clearRecords(bytes32 node) public virtual authorised(node) {
            recordVersions[node]++;
            emit VersionChanged(node, recordVersions[node]);
        }
        function supportsInterface(
            bytes4 interfaceID
        ) public view virtual override returns (bool) {
            return
                interfaceID == type(IVersionableResolver).interfaceId ||
                super.supportsInterface(interfaceID);
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    import "./IABIResolver.sol";
    import "../ResolverBase.sol";
    abstract contract ABIResolver is IABIResolver, ResolverBase {
        mapping(uint64 => mapping(bytes32 => mapping(uint256 => bytes))) versionable_abis;
        /**
         * Sets the ABI associated with an ENS node.
         * Nodes may have one ABI of each content type. To remove an ABI, set it to
         * the empty string.
         * @param node The node to update.
         * @param contentType The content type of the ABI
         * @param data The ABI data.
         */
        function setABI(
            bytes32 node,
            uint256 contentType,
            bytes calldata data
        ) external virtual authorised(node) {
            // Content types must be powers of 2
            require(((contentType - 1) & contentType) == 0);
            versionable_abis[recordVersions[node]][node][contentType] = data;
            emit ABIChanged(node, contentType);
        }
        /**
         * Returns the ABI associated with an ENS node.
         * Defined in EIP205.
         * @param node The ENS node to query
         * @param contentTypes A bitwise OR of the ABI formats accepted by the caller.
         * @return contentType The content type of the return value
         * @return data The ABI data
         */
        function ABI(
            bytes32 node,
            uint256 contentTypes
        ) external view virtual override returns (uint256, bytes memory) {
            mapping(uint256 => bytes) storage abiset = versionable_abis[
                recordVersions[node]
            ][node];
            for (
                uint256 contentType = 1;
                contentType <= contentTypes;
                contentType <<= 1
            ) {
                if (
                    (contentType & contentTypes) != 0 &&
                    abiset[contentType].length > 0
                ) {
                    return (contentType, abiset[contentType]);
                }
            }
            return (0, bytes(""));
        }
        function supportsInterface(
            bytes4 interfaceID
        ) public view virtual override returns (bool) {
            return
                interfaceID == type(IABIResolver).interfaceId ||
                super.supportsInterface(interfaceID);
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    import "../ResolverBase.sol";
    import "./IAddrResolver.sol";
    import "./IAddressResolver.sol";
    abstract contract AddrResolver is
        IAddrResolver,
        IAddressResolver,
        ResolverBase
    {
        uint256 private constant COIN_TYPE_ETH = 60;
        mapping(uint64 => mapping(bytes32 => mapping(uint256 => bytes))) versionable_addresses;
        /**
         * Sets the address associated with an ENS node.
         * May only be called by the owner of that node in the ENS registry.
         * @param node The node to update.
         * @param a The address to set.
         */
        function setAddr(
            bytes32 node,
            address a
        ) external virtual authorised(node) {
            setAddr(node, COIN_TYPE_ETH, addressToBytes(a));
        }
        /**
         * Returns the address associated with an ENS node.
         * @param node The ENS node to query.
         * @return The associated address.
         */
        function addr(
            bytes32 node
        ) public view virtual override returns (address payable) {
            bytes memory a = addr(node, COIN_TYPE_ETH);
            if (a.length == 0) {
                return payable(0);
            }
            return bytesToAddress(a);
        }
        function setAddr(
            bytes32 node,
            uint256 coinType,
            bytes memory a
        ) public virtual authorised(node) {
            emit AddressChanged(node, coinType, a);
            if (coinType == COIN_TYPE_ETH) {
                emit AddrChanged(node, bytesToAddress(a));
            }
            versionable_addresses[recordVersions[node]][node][coinType] = a;
        }
        function addr(
            bytes32 node,
            uint256 coinType
        ) public view virtual override returns (bytes memory) {
            return versionable_addresses[recordVersions[node]][node][coinType];
        }
        function supportsInterface(
            bytes4 interfaceID
        ) public view virtual override returns (bool) {
            return
                interfaceID == type(IAddrResolver).interfaceId ||
                interfaceID == type(IAddressResolver).interfaceId ||
                super.supportsInterface(interfaceID);
        }
        function bytesToAddress(
            bytes memory b
        ) internal pure returns (address payable a) {
            require(b.length == 20);
            assembly {
                a := div(mload(add(b, 32)), exp(256, 12))
            }
        }
        function addressToBytes(address a) internal pure returns (bytes memory b) {
            b = new bytes(20);
            assembly {
                mstore(add(b, 32), mul(a, exp(256, 12)))
            }
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    import "../ResolverBase.sol";
    import "./IContentHashResolver.sol";
    abstract contract ContentHashResolver is IContentHashResolver, ResolverBase {
        mapping(uint64 => mapping(bytes32 => bytes)) versionable_hashes;
        /**
         * Sets the contenthash associated with an ENS node.
         * May only be called by the owner of that node in the ENS registry.
         * @param node The node to update.
         * @param hash The contenthash to set
         */
        function setContenthash(
            bytes32 node,
            bytes calldata hash
        ) external virtual authorised(node) {
            versionable_hashes[recordVersions[node]][node] = hash;
            emit ContenthashChanged(node, hash);
        }
        /**
         * Returns the contenthash associated with an ENS node.
         * @param node The ENS node to query.
         * @return The associated contenthash.
         */
        function contenthash(
            bytes32 node
        ) external view virtual override returns (bytes memory) {
            return versionable_hashes[recordVersions[node]][node];
        }
        function supportsInterface(
            bytes4 interfaceID
        ) public view virtual override returns (bool) {
            return
                interfaceID == type(IContentHashResolver).interfaceId ||
                super.supportsInterface(interfaceID);
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    import "../ResolverBase.sol";
    import "../../dnssec-oracle/RRUtils.sol";
    import "./IDNSRecordResolver.sol";
    import "./IDNSZoneResolver.sol";
    abstract contract DNSResolver is
        IDNSRecordResolver,
        IDNSZoneResolver,
        ResolverBase
    {
        using RRUtils for *;
        using BytesUtils for bytes;
        // Zone hashes for the domains.
        // A zone hash is an EIP-1577 content hash in binary format that should point to a
        // resource containing a single zonefile.
        // node => contenthash
        mapping(uint64 => mapping(bytes32 => bytes)) private versionable_zonehashes;
        // The records themselves.  Stored as binary RRSETs
        // node => version => name => resource => data
        mapping(uint64 => mapping(bytes32 => mapping(bytes32 => mapping(uint16 => bytes))))
            private versionable_records;
        // Count of number of entries for a given name.  Required for DNS resolvers
        // when resolving wildcards.
        // node => version => name => number of records
        mapping(uint64 => mapping(bytes32 => mapping(bytes32 => uint16)))
            private versionable_nameEntriesCount;
        /**
         * Set one or more DNS records.  Records are supplied in wire-format.
         * Records with the same node/name/resource must be supplied one after the
         * other to ensure the data is updated correctly. For example, if the data
         * was supplied:
         *     a.example.com IN A 1.2.3.4
         *     a.example.com IN A 5.6.7.8
         *     www.example.com IN CNAME a.example.com.
         * then this would store the two A records for a.example.com correctly as a
         * single RRSET, however if the data was supplied:
         *     a.example.com IN A 1.2.3.4
         *     www.example.com IN CNAME a.example.com.
         *     a.example.com IN A 5.6.7.8
         * then this would store the first A record, the CNAME, then the second A
         * record which would overwrite the first.
         *
         * @param node the namehash of the node for which to set the records
         * @param data the DNS wire format records to set
         */
        function setDNSRecords(
            bytes32 node,
            bytes calldata data
        ) external virtual authorised(node) {
            uint16 resource = 0;
            uint256 offset = 0;
            bytes memory name;
            bytes memory value;
            bytes32 nameHash;
            uint64 version = recordVersions[node];
            // Iterate over the data to add the resource records
            for (
                RRUtils.RRIterator memory iter = data.iterateRRs(0);
                !iter.done();
                iter.next()
            ) {
                if (resource == 0) {
                    resource = iter.dnstype;
                    name = iter.name();
                    nameHash = keccak256(abi.encodePacked(name));
                    value = bytes(iter.rdata());
                } else {
                    bytes memory newName = iter.name();
                    if (resource != iter.dnstype || !name.equals(newName)) {
                        setDNSRRSet(
                            node,
                            name,
                            resource,
                            data,
                            offset,
                            iter.offset - offset,
                            value.length == 0,
                            version
                        );
                        resource = iter.dnstype;
                        offset = iter.offset;
                        name = newName;
                        nameHash = keccak256(name);
                        value = bytes(iter.rdata());
                    }
                }
            }
            if (name.length > 0) {
                setDNSRRSet(
                    node,
                    name,
                    resource,
                    data,
                    offset,
                    data.length - offset,
                    value.length == 0,
                    version
                );
            }
        }
        /**
         * Obtain a DNS record.
         * @param node the namehash of the node for which to fetch the record
         * @param name the keccak-256 hash of the fully-qualified name for which to fetch the record
         * @param resource the ID of the resource as per https://en.wikipedia.org/wiki/List_of_DNS_record_types
         * @return the DNS record in wire format if present, otherwise empty
         */
        function dnsRecord(
            bytes32 node,
            bytes32 name,
            uint16 resource
        ) public view virtual override returns (bytes memory) {
            return versionable_records[recordVersions[node]][node][name][resource];
        }
        /**
         * Check if a given node has records.
         * @param node the namehash of the node for which to check the records
         * @param name the namehash of the node for which to check the records
         */
        function hasDNSRecords(
            bytes32 node,
            bytes32 name
        ) public view virtual returns (bool) {
            return (versionable_nameEntriesCount[recordVersions[node]][node][
                name
            ] != 0);
        }
        /**
         * setZonehash sets the hash for the zone.
         * May only be called by the owner of that node in the ENS registry.
         * @param node The node to update.
         * @param hash The zonehash to set
         */
        function setZonehash(
            bytes32 node,
            bytes calldata hash
        ) external virtual authorised(node) {
            uint64 currentRecordVersion = recordVersions[node];
            bytes memory oldhash = versionable_zonehashes[currentRecordVersion][
                node
            ];
            versionable_zonehashes[currentRecordVersion][node] = hash;
            emit DNSZonehashChanged(node, oldhash, hash);
        }
        /**
         * zonehash obtains the hash for the zone.
         * @param node The ENS node to query.
         * @return The associated contenthash.
         */
        function zonehash(
            bytes32 node
        ) external view virtual override returns (bytes memory) {
            return versionable_zonehashes[recordVersions[node]][node];
        }
        function supportsInterface(
            bytes4 interfaceID
        ) public view virtual override returns (bool) {
            return
                interfaceID == type(IDNSRecordResolver).interfaceId ||
                interfaceID == type(IDNSZoneResolver).interfaceId ||
                super.supportsInterface(interfaceID);
        }
        function setDNSRRSet(
            bytes32 node,
            bytes memory name,
            uint16 resource,
            bytes memory data,
            uint256 offset,
            uint256 size,
            bool deleteRecord,
            uint64 version
        ) private {
            bytes32 nameHash = keccak256(name);
            bytes memory rrData = data.substring(offset, size);
            if (deleteRecord) {
                if (
                    versionable_records[version][node][nameHash][resource].length !=
                    0
                ) {
                    versionable_nameEntriesCount[version][node][nameHash]--;
                }
                delete (versionable_records[version][node][nameHash][resource]);
                emit DNSRecordDeleted(node, name, resource);
            } else {
                if (
                    versionable_records[version][node][nameHash][resource].length ==
                    0
                ) {
                    versionable_nameEntriesCount[version][node][nameHash]++;
                }
                versionable_records[version][node][nameHash][resource] = rrData;
                emit DNSRecordChanged(node, name, resource, rrData);
            }
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    interface IABIResolver {
        event ABIChanged(bytes32 indexed node, uint256 indexed contentType);
        /**
         * Returns the ABI associated with an ENS node.
         * Defined in EIP205.
         * @param node The ENS node to query
         * @param contentTypes A bitwise OR of the ABI formats accepted by the caller.
         * @return contentType The content type of the return value
         * @return data The ABI data
         */
        function ABI(
            bytes32 node,
            uint256 contentTypes
        ) external view returns (uint256, bytes memory);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    /**
     * Interface for the legacy (ETH-only) addr function.
     */
    interface IAddrResolver {
        event AddrChanged(bytes32 indexed node, address a);
        /**
         * Returns the address associated with an ENS node.
         * @param node The ENS node to query.
         * @return The associated address.
         */
        function addr(bytes32 node) external view returns (address payable);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    /**
     * Interface for the new (multicoin) addr function.
     */
    interface IAddressResolver {
        event AddressChanged(
            bytes32 indexed node,
            uint256 coinType,
            bytes newAddress
        );
        function addr(
            bytes32 node,
            uint256 coinType
        ) external view returns (bytes memory);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    interface IContentHashResolver {
        event ContenthashChanged(bytes32 indexed node, bytes hash);
        /**
         * Returns the contenthash associated with an ENS node.
         * @param node The ENS node to query.
         * @return The associated contenthash.
         */
        function contenthash(bytes32 node) external view returns (bytes memory);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    interface IDNSRecordResolver {
        // DNSRecordChanged is emitted whenever a given node/name/resource's RRSET is updated.
        event DNSRecordChanged(
            bytes32 indexed node,
            bytes name,
            uint16 resource,
            bytes record
        );
        // DNSRecordDeleted is emitted whenever a given node/name/resource's RRSET is deleted.
        event DNSRecordDeleted(bytes32 indexed node, bytes name, uint16 resource);
        /**
         * Obtain a DNS record.
         * @param node the namehash of the node for which to fetch the record
         * @param name the keccak-256 hash of the fully-qualified name for which to fetch the record
         * @param resource the ID of the resource as per https://en.wikipedia.org/wiki/List_of_DNS_record_types
         * @return the DNS record in wire format if present, otherwise empty
         */
        function dnsRecord(
            bytes32 node,
            bytes32 name,
            uint16 resource
        ) external view returns (bytes memory);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    interface IDNSZoneResolver {
        // DNSZonehashChanged is emitted whenever a given node's zone hash is updated.
        event DNSZonehashChanged(
            bytes32 indexed node,
            bytes lastzonehash,
            bytes zonehash
        );
        /**
         * zonehash obtains the hash for the zone.
         * @param node The ENS node to query.
         * @return The associated contenthash.
         */
        function zonehash(bytes32 node) external view returns (bytes memory);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    interface IInterfaceResolver {
        event InterfaceChanged(
            bytes32 indexed node,
            bytes4 indexed interfaceID,
            address implementer
        );
        /**
         * Returns the address of a contract that implements the specified interface for this name.
         * If an implementer has not been set for this interfaceID and name, the resolver will query
         * the contract at `addr()`. If `addr()` is set, a contract exists at that address, and that
         * contract implements EIP165 and returns `true` for the specified interfaceID, its address
         * will be returned.
         * @param node The ENS node to query.
         * @param interfaceID The EIP 165 interface ID to check for.
         * @return The address that implements this interface, or 0 if the interface is unsupported.
         */
        function interfaceImplementer(
            bytes32 node,
            bytes4 interfaceID
        ) external view returns (address);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    interface INameResolver {
        event NameChanged(bytes32 indexed node, string name);
        /**
         * Returns the name associated with an ENS node, for reverse records.
         * Defined in EIP181.
         * @param node The ENS node to query.
         * @return The associated name.
         */
        function name(bytes32 node) external view returns (string memory);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    interface IPubkeyResolver {
        event PubkeyChanged(bytes32 indexed node, bytes32 x, bytes32 y);
        /**
         * Returns the SECP256k1 public key associated with an ENS node.
         * Defined in EIP 619.
         * @param node The ENS node to query
         * @return x The X coordinate of the curve point for the public key.
         * @return y The Y coordinate of the curve point for the public key.
         */
        function pubkey(bytes32 node) external view returns (bytes32 x, bytes32 y);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    interface ITextResolver {
        event TextChanged(
            bytes32 indexed node,
            string indexed indexedKey,
            string key,
            string value
        );
        /**
         * Returns the text data associated with an ENS node and key.
         * @param node The ENS node to query.
         * @param key The text data key to query.
         * @return The associated text data.
         */
        function text(
            bytes32 node,
            string calldata key
        ) external view returns (string memory);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    interface IVersionableResolver {
        event VersionChanged(bytes32 indexed node, uint64 newVersion);
        function recordVersions(bytes32 node) external view returns (uint64);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
    import "../ResolverBase.sol";
    import "./AddrResolver.sol";
    import "./IInterfaceResolver.sol";
    abstract contract InterfaceResolver is IInterfaceResolver, AddrResolver {
        mapping(uint64 => mapping(bytes32 => mapping(bytes4 => address))) versionable_interfaces;
        /**
         * Sets an interface associated with a name.
         * Setting the address to 0 restores the default behaviour of querying the contract at `addr()` for interface support.
         * @param node The node to update.
         * @param interfaceID The EIP 165 interface ID.
         * @param implementer The address of a contract that implements this interface for this node.
         */
        function setInterface(
            bytes32 node,
            bytes4 interfaceID,
            address implementer
        ) external virtual authorised(node) {
            versionable_interfaces[recordVersions[node]][node][
                interfaceID
            ] = implementer;
            emit InterfaceChanged(node, interfaceID, implementer);
        }
        /**
         * Returns the address of a contract that implements the specified interface for this name.
         * If an implementer has not been set for this interfaceID and name, the resolver will query
         * the contract at `addr()`. If `addr()` is set, a contract exists at that address, and that
         * contract implements EIP165 and returns `true` for the specified interfaceID, its address
         * will be returned.
         * @param node The ENS node to query.
         * @param interfaceID The EIP 165 interface ID to check for.
         * @return The address that implements this interface, or 0 if the interface is unsupported.
         */
        function interfaceImplementer(
            bytes32 node,
            bytes4 interfaceID
        ) external view virtual override returns (address) {
            address implementer = versionable_interfaces[recordVersions[node]][
                node
            ][interfaceID];
            if (implementer != address(0)) {
                return implementer;
            }
            address a = addr(node);
            if (a == address(0)) {
                return address(0);
            }
            (bool success, bytes memory returnData) = a.staticcall(
                abi.encodeWithSignature(
                    "supportsInterface(bytes4)",
                    type(IERC165).interfaceId
                )
            );
            if (!success || returnData.length < 32 || returnData[31] == 0) {
                // EIP 165 not supported by target
                return address(0);
            }
            (success, returnData) = a.staticcall(
                abi.encodeWithSignature("supportsInterface(bytes4)", interfaceID)
            );
            if (!success || returnData.length < 32 || returnData[31] == 0) {
                // Specified interface not supported by target
                return address(0);
            }
            return a;
        }
        function supportsInterface(
            bytes4 interfaceID
        ) public view virtual override returns (bool) {
            return
                interfaceID == type(IInterfaceResolver).interfaceId ||
                super.supportsInterface(interfaceID);
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    import "../ResolverBase.sol";
    import "./INameResolver.sol";
    abstract contract NameResolver is INameResolver, ResolverBase {
        mapping(uint64 => mapping(bytes32 => string)) versionable_names;
        /**
         * Sets the name associated with an ENS node, for reverse records.
         * May only be called by the owner of that node in the ENS registry.
         * @param node The node to update.
         */
        function setName(
            bytes32 node,
            string calldata newName
        ) external virtual authorised(node) {
            versionable_names[recordVersions[node]][node] = newName;
            emit NameChanged(node, newName);
        }
        /**
         * Returns the name associated with an ENS node, for reverse records.
         * Defined in EIP181.
         * @param node The ENS node to query.
         * @return The associated name.
         */
        function name(
            bytes32 node
        ) external view virtual override returns (string memory) {
            return versionable_names[recordVersions[node]][node];
        }
        function supportsInterface(
            bytes4 interfaceID
        ) public view virtual override returns (bool) {
            return
                interfaceID == type(INameResolver).interfaceId ||
                super.supportsInterface(interfaceID);
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    import "../ResolverBase.sol";
    import "./IPubkeyResolver.sol";
    abstract contract PubkeyResolver is IPubkeyResolver, ResolverBase {
        struct PublicKey {
            bytes32 x;
            bytes32 y;
        }
        mapping(uint64 => mapping(bytes32 => PublicKey)) versionable_pubkeys;
        /**
         * Sets the SECP256k1 public key associated with an ENS node.
         * @param node The ENS node to query
         * @param x the X coordinate of the curve point for the public key.
         * @param y the Y coordinate of the curve point for the public key.
         */
        function setPubkey(
            bytes32 node,
            bytes32 x,
            bytes32 y
        ) external virtual authorised(node) {
            versionable_pubkeys[recordVersions[node]][node] = PublicKey(x, y);
            emit PubkeyChanged(node, x, y);
        }
        /**
         * Returns the SECP256k1 public key associated with an ENS node.
         * Defined in EIP 619.
         * @param node The ENS node to query
         * @return x The X coordinate of the curve point for the public key.
         * @return y The Y coordinate of the curve point for the public key.
         */
        function pubkey(
            bytes32 node
        ) external view virtual override returns (bytes32 x, bytes32 y) {
            uint64 currentRecordVersion = recordVersions[node];
            return (
                versionable_pubkeys[currentRecordVersion][node].x,
                versionable_pubkeys[currentRecordVersion][node].y
            );
        }
        function supportsInterface(
            bytes4 interfaceID
        ) public view virtual override returns (bool) {
            return
                interfaceID == type(IPubkeyResolver).interfaceId ||
                super.supportsInterface(interfaceID);
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity >=0.8.4;
    import "../ResolverBase.sol";
    import "./ITextResolver.sol";
    abstract contract TextResolver is ITextResolver, ResolverBase {
        mapping(uint64 => mapping(bytes32 => mapping(string => string))) versionable_texts;
        /**
         * Sets the text data associated with an ENS node and key.
         * May only be called by the owner of that node in the ENS registry.
         * @param node The node to update.
         * @param key The key to set.
         * @param value The text data value to set.
         */
        function setText(
            bytes32 node,
            string calldata key,
            string calldata value
        ) external virtual authorised(node) {
            versionable_texts[recordVersions[node]][node][key] = value;
            emit TextChanged(node, key, key, value);
        }
        /**
         * Returns the text data associated with an ENS node and key.
         * @param node The ENS node to query.
         * @param key The text data key to query.
         * @return The associated text data.
         */
        function text(
            bytes32 node,
            string calldata key
        ) external view virtual override returns (string memory) {
            return versionable_texts[recordVersions[node]][node][key];
        }
        function supportsInterface(
            bytes4 interfaceID
        ) public view virtual override returns (bool) {
            return
                interfaceID == type(ITextResolver).interfaceId ||
                super.supportsInterface(interfaceID);
        }
    }
    pragma solidity >=0.8.4;
    interface IReverseRegistrar {
        function setDefaultResolver(address resolver) external;
        function claim(address owner) external returns (bytes32);
        function claimForAddr(
            address addr,
            address owner,
            address resolver
        ) external returns (bytes32);
        function claimWithResolver(
            address owner,
            address resolver
        ) external returns (bytes32);
        function setName(string memory name) external returns (bytes32);
        function setNameForAddr(
            address addr,
            address owner,
            address resolver,
            string memory name
        ) external returns (bytes32);
        function node(address addr) external pure returns (bytes32);
    }
    //SPDX-License-Identifier: MIT
    pragma solidity >=0.8.17 <0.9.0;
    import {ENS} from "../registry/ENS.sol";
    import {IReverseRegistrar} from "../reverseRegistrar/IReverseRegistrar.sol";
    contract ReverseClaimer {
        bytes32 constant ADDR_REVERSE_NODE =
            0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2;
        constructor(ENS ens, address claimant) {
            IReverseRegistrar reverseRegistrar = IReverseRegistrar(
                ens.owner(ADDR_REVERSE_NODE)
            );
            reverseRegistrar.claim(claimant);
        }
    }
    //SPDX-License-Identifier: MIT
    pragma solidity ~0.8.17;
    interface IMetadataService {
        function uri(uint256) external view returns (string memory);
    }
    //SPDX-License-Identifier: MIT
    pragma solidity ~0.8.17;
    import "../registry/ENS.sol";
    import "../ethregistrar/IBaseRegistrar.sol";
    import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
    import "./IMetadataService.sol";
    import "./INameWrapperUpgrade.sol";
    uint32 constant CANNOT_UNWRAP = 1;
    uint32 constant CANNOT_BURN_FUSES = 2;
    uint32 constant CANNOT_TRANSFER = 4;
    uint32 constant CANNOT_SET_RESOLVER = 8;
    uint32 constant CANNOT_SET_TTL = 16;
    uint32 constant CANNOT_CREATE_SUBDOMAIN = 32;
    uint32 constant CANNOT_APPROVE = 64;
    //uint16 reserved for parent controlled fuses from bit 17 to bit 32
    uint32 constant PARENT_CANNOT_CONTROL = 1 << 16;
    uint32 constant IS_DOT_ETH = 1 << 17;
    uint32 constant CAN_EXTEND_EXPIRY = 1 << 18;
    uint32 constant CAN_DO_EVERYTHING = 0;
    uint32 constant PARENT_CONTROLLED_FUSES = 0xFFFF0000;
    // all fuses apart from IS_DOT_ETH
    uint32 constant USER_SETTABLE_FUSES = 0xFFFDFFFF;
    interface INameWrapper is IERC1155 {
        event NameWrapped(
            bytes32 indexed node,
            bytes name,
            address owner,
            uint32 fuses,
            uint64 expiry
        );
        event NameUnwrapped(bytes32 indexed node, address owner);
        event FusesSet(bytes32 indexed node, uint32 fuses);
        event ExpiryExtended(bytes32 indexed node, uint64 expiry);
        function ens() external view returns (ENS);
        function registrar() external view returns (IBaseRegistrar);
        function metadataService() external view returns (IMetadataService);
        function names(bytes32) external view returns (bytes memory);
        function name() external view returns (string memory);
        function upgradeContract() external view returns (INameWrapperUpgrade);
        function supportsInterface(bytes4 interfaceID) external view returns (bool);
        function wrap(
            bytes calldata name,
            address wrappedOwner,
            address resolver
        ) external;
        function wrapETH2LD(
            string calldata label,
            address wrappedOwner,
            uint16 ownerControlledFuses,
            address resolver
        ) external returns (uint64 expires);
        function registerAndWrapETH2LD(
            string calldata label,
            address wrappedOwner,
            uint256 duration,
            address resolver,
            uint16 ownerControlledFuses
        ) external returns (uint256 registrarExpiry);
        function renew(
            uint256 labelHash,
            uint256 duration
        ) external returns (uint256 expires);
        function unwrap(bytes32 node, bytes32 label, address owner) external;
        function unwrapETH2LD(
            bytes32 label,
            address newRegistrant,
            address newController
        ) external;
        function upgrade(bytes calldata name, bytes calldata extraData) external;
        function setFuses(
            bytes32 node,
            uint16 ownerControlledFuses
        ) external returns (uint32 newFuses);
        function setChildFuses(
            bytes32 parentNode,
            bytes32 labelhash,
            uint32 fuses,
            uint64 expiry
        ) external;
        function setSubnodeRecord(
            bytes32 node,
            string calldata label,
            address owner,
            address resolver,
            uint64 ttl,
            uint32 fuses,
            uint64 expiry
        ) external returns (bytes32);
        function setRecord(
            bytes32 node,
            address owner,
            address resolver,
            uint64 ttl
        ) external;
        function setSubnodeOwner(
            bytes32 node,
            string calldata label,
            address newOwner,
            uint32 fuses,
            uint64 expiry
        ) external returns (bytes32);
        function extendExpiry(
            bytes32 node,
            bytes32 labelhash,
            uint64 expiry
        ) external returns (uint64);
        function canModifyName(
            bytes32 node,
            address addr
        ) external view returns (bool);
        function setResolver(bytes32 node, address resolver) external;
        function setTTL(bytes32 node, uint64 ttl) external;
        function ownerOf(uint256 id) external view returns (address owner);
        function approve(address to, uint256 tokenId) external;
        function getApproved(uint256 tokenId) external view returns (address);
        function getData(
            uint256 id
        ) external view returns (address, uint32, uint64);
        function setMetadataService(IMetadataService _metadataService) external;
        function uri(uint256 tokenId) external view returns (string memory);
        function setUpgradeContract(INameWrapperUpgrade _upgradeAddress) external;
        function allFusesBurned(
            bytes32 node,
            uint32 fuseMask
        ) external view returns (bool);
        function isWrapped(bytes32) external view returns (bool);
        function isWrapped(bytes32, bytes32) external view returns (bool);
    }
    //SPDX-License-Identifier: MIT
    pragma solidity ~0.8.17;
    interface INameWrapperUpgrade {
        function wrapFromUpgrade(
            bytes calldata name,
            address wrappedOwner,
            uint32 fuses,
            uint64 expiry,
            address approved,
            bytes calldata extraData
        ) external;
    }
    

    File 2 of 3: ENSRegistryWithFallback
    // File: @ensdomains/ens/contracts/ENS.sol
    
    pragma solidity >=0.4.24;
    
    interface ENS {
    
        // Logged when the owner of a node assigns a new owner to a subnode.
        event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);
    
        // Logged when the owner of a node transfers ownership to a new account.
        event Transfer(bytes32 indexed node, address owner);
    
        // Logged when the resolver for a node changes.
        event NewResolver(bytes32 indexed node, address resolver);
    
        // Logged when the TTL of a node changes
        event NewTTL(bytes32 indexed node, uint64 ttl);
    
        // Logged when an operator is added or removed.
        event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
    
        function setRecord(bytes32 node, address owner, address resolver, uint64 ttl) external;
        function setSubnodeRecord(bytes32 node, bytes32 label, address owner, address resolver, uint64 ttl) external;
        function setSubnodeOwner(bytes32 node, bytes32 label, address owner) external returns(bytes32);
        function setResolver(bytes32 node, address resolver) external;
        function setOwner(bytes32 node, address owner) external;
        function setTTL(bytes32 node, uint64 ttl) external;
        function setApprovalForAll(address operator, bool approved) external;
        function owner(bytes32 node) external view returns (address);
        function resolver(bytes32 node) external view returns (address);
        function ttl(bytes32 node) external view returns (uint64);
        function recordExists(bytes32 node) external view returns (bool);
        function isApprovedForAll(address owner, address operator) external view returns (bool);
    }
    
    // File: @ensdomains/ens/contracts/ENSRegistry.sol
    
    pragma solidity ^0.5.0;
    
    
    /**
     * The ENS registry contract.
     */
    contract ENSRegistry is ENS {
    
        struct Record {
            address owner;
            address resolver;
            uint64 ttl;
        }
    
        mapping (bytes32 => Record) records;
        mapping (address => mapping(address => bool)) operators;
    
        // Permits modifications only by the owner of the specified node.
        modifier authorised(bytes32 node) {
            address owner = records[node].owner;
            require(owner == msg.sender || operators[owner][msg.sender]);
            _;
        }
    
        /**
         * @dev Constructs a new ENS registrar.
         */
        constructor() public {
            records[0x0].owner = msg.sender;
        }
    
        /**
         * @dev Sets the record for a node.
         * @param node The node to update.
         * @param owner The address of the new owner.
         * @param resolver The address of the resolver.
         * @param ttl The TTL in seconds.
         */
        function setRecord(bytes32 node, address owner, address resolver, uint64 ttl) external {
            setOwner(node, owner);
            _setResolverAndTTL(node, resolver, ttl);
        }
    
        /**
         * @dev Sets the record for a subnode.
         * @param node The parent node.
         * @param label The hash of the label specifying the subnode.
         * @param owner The address of the new owner.
         * @param resolver The address of the resolver.
         * @param ttl The TTL in seconds.
         */
        function setSubnodeRecord(bytes32 node, bytes32 label, address owner, address resolver, uint64 ttl) external {
            bytes32 subnode = setSubnodeOwner(node, label, owner);
            _setResolverAndTTL(subnode, resolver, ttl);
        }
    
        /**
         * @dev Transfers ownership of a node to a new address. May only be called by the current owner of the node.
         * @param node The node to transfer ownership of.
         * @param owner The address of the new owner.
         */
        function setOwner(bytes32 node, address owner) public authorised(node) {
            _setOwner(node, owner);
            emit Transfer(node, owner);
        }
    
        /**
         * @dev Transfers ownership of a subnode keccak256(node, label) to a new address. May only be called by the owner of the parent node.
         * @param node The parent node.
         * @param label The hash of the label specifying the subnode.
         * @param owner The address of the new owner.
         */
        function setSubnodeOwner(bytes32 node, bytes32 label, address owner) public authorised(node) returns(bytes32) {
            bytes32 subnode = keccak256(abi.encodePacked(node, label));
            _setOwner(subnode, owner);
            emit NewOwner(node, label, owner);
            return subnode;
        }
    
        /**
         * @dev Sets the resolver address for the specified node.
         * @param node The node to update.
         * @param resolver The address of the resolver.
         */
        function setResolver(bytes32 node, address resolver) public authorised(node) {
            emit NewResolver(node, resolver);
            records[node].resolver = resolver;
        }
    
        /**
         * @dev Sets the TTL for the specified node.
         * @param node The node to update.
         * @param ttl The TTL in seconds.
         */
        function setTTL(bytes32 node, uint64 ttl) public authorised(node) {
            emit NewTTL(node, ttl);
            records[node].ttl = ttl;
        }
    
        /**
         * @dev Enable or disable approval for a third party ("operator") to manage
         *  all of `msg.sender`'s ENS records. Emits the ApprovalForAll event.
         * @param operator Address to add to the set of authorized operators.
         * @param approved True if the operator is approved, false to revoke approval.
         */
        function setApprovalForAll(address operator, bool approved) external {
            operators[msg.sender][operator] = approved;
            emit ApprovalForAll(msg.sender, operator, approved);
        }
    
        /**
         * @dev Returns the address that owns the specified node.
         * @param node The specified node.
         * @return address of the owner.
         */
        function owner(bytes32 node) public view returns (address) {
            address addr = records[node].owner;
            if (addr == address(this)) {
                return address(0x0);
            }
    
            return addr;
        }
    
        /**
         * @dev Returns the address of the resolver for the specified node.
         * @param node The specified node.
         * @return address of the resolver.
         */
        function resolver(bytes32 node) public view returns (address) {
            return records[node].resolver;
        }
    
        /**
         * @dev Returns the TTL of a node, and any records associated with it.
         * @param node The specified node.
         * @return ttl of the node.
         */
        function ttl(bytes32 node) public view returns (uint64) {
            return records[node].ttl;
        }
    
        /**
         * @dev Returns whether a record has been imported to the registry.
         * @param node The specified node.
         * @return Bool if record exists
         */
        function recordExists(bytes32 node) public view returns (bool) {
            return records[node].owner != address(0x0);
        }
    
        /**
         * @dev Query if an address is an authorized operator for another address.
         * @param owner The address that owns the records.
         * @param operator The address that acts on behalf of the owner.
         * @return True if `operator` is an approved operator for `owner`, false otherwise.
         */
        function isApprovedForAll(address owner, address operator) external view returns (bool) {
            return operators[owner][operator];
        }
    
        function _setOwner(bytes32 node, address owner) internal {
            records[node].owner = owner;
        }
    
        function _setResolverAndTTL(bytes32 node, address resolver, uint64 ttl) internal {
            if(resolver != records[node].resolver) {
                records[node].resolver = resolver;
                emit NewResolver(node, resolver);
            }
    
            if(ttl != records[node].ttl) {
                records[node].ttl = ttl;
                emit NewTTL(node, ttl);
            }
        }
    }
    
    // File: @ensdomains/ens/contracts/ENSRegistryWithFallback.sol
    
    pragma solidity ^0.5.0;
    
    
    
    /**
     * The ENS registry contract.
     */
    contract ENSRegistryWithFallback is ENSRegistry {
    
        ENS public old;
    
        /**
         * @dev Constructs a new ENS registrar.
         */
        constructor(ENS _old) public ENSRegistry() {
            old = _old;
        }
    
        /**
         * @dev Returns the address of the resolver for the specified node.
         * @param node The specified node.
         * @return address of the resolver.
         */
        function resolver(bytes32 node) public view returns (address) {
            if (!recordExists(node)) {
                return old.resolver(node);
            }
    
            return super.resolver(node);
        }
    
        /**
         * @dev Returns the address that owns the specified node.
         * @param node The specified node.
         * @return address of the owner.
         */
        function owner(bytes32 node) public view returns (address) {
            if (!recordExists(node)) {
                return old.owner(node);
            }
    
            return super.owner(node);
        }
    
        /**
         * @dev Returns the TTL of a node, and any records associated with it.
         * @param node The specified node.
         * @return ttl of the node.
         */
        function ttl(bytes32 node) public view returns (uint64) {
            if (!recordExists(node)) {
                return old.ttl(node);
            }
    
            return super.ttl(node);
        }
    
        function _setOwner(bytes32 node, address owner) internal {
            address addr = owner;
            if (addr == address(0x0)) {
                addr = address(this);
            }
    
            super._setOwner(node, addr);
        }
    }

    File 3 of 3: NameWrapper
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
    pragma solidity ^0.8.0;
    import "../utils/Context.sol";
    /**
     * @dev Contract module which provides a basic access control mechanism, where
     * there is an account (an owner) that can be granted exclusive access to
     * specific functions.
     *
     * By default, the owner account will be the one that deploys the contract. This
     * can later be changed with {transferOwnership}.
     *
     * This module is used through inheritance. It will make available the modifier
     * `onlyOwner`, which can be applied to your functions to restrict their use to
     * the owner.
     */
    abstract contract Ownable is Context {
        address private _owner;
        event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
        /**
         * @dev Initializes the contract setting the deployer as the initial owner.
         */
        constructor() {
            _transferOwnership(_msgSender());
        }
        /**
         * @dev Throws if called by any account other than the owner.
         */
        modifier onlyOwner() {
            _checkOwner();
            _;
        }
        /**
         * @dev Returns the address of the current owner.
         */
        function owner() public view virtual returns (address) {
            return _owner;
        }
        /**
         * @dev Throws if the sender is not the owner.
         */
        function _checkOwner() internal view virtual {
            require(owner() == _msgSender(), "Ownable: caller is not the owner");
        }
        /**
         * @dev Leaves the contract without owner. It will not be possible to call
         * `onlyOwner` functions anymore. Can only be called by the current owner.
         *
         * NOTE: Renouncing ownership will leave the contract without an owner,
         * thereby removing any functionality that is only available to the owner.
         */
        function renounceOwnership() public virtual onlyOwner {
            _transferOwnership(address(0));
        }
        /**
         * @dev Transfers ownership of the contract to a new account (`newOwner`).
         * Can only be called by the current owner.
         */
        function transferOwnership(address newOwner) public virtual onlyOwner {
            require(newOwner != address(0), "Ownable: new owner is the zero address");
            _transferOwnership(newOwner);
        }
        /**
         * @dev Transfers ownership of the contract to a new account (`newOwner`).
         * Internal function without access restriction.
         */
        function _transferOwnership(address newOwner) internal virtual {
            address oldOwner = _owner;
            _owner = newOwner;
            emit OwnershipTransferred(oldOwner, newOwner);
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)
    pragma solidity ^0.8.0;
    import "../../utils/introspection/IERC165.sol";
    /**
     * @dev Required interface of an ERC1155 compliant contract, as defined in the
     * https://eips.ethereum.org/EIPS/eip-1155[EIP].
     *
     * _Available since v3.1._
     */
    interface IERC1155 is IERC165 {
        /**
         * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
         */
        event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
        /**
         * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
         * transfers.
         */
        event TransferBatch(
            address indexed operator,
            address indexed from,
            address indexed to,
            uint256[] ids,
            uint256[] values
        );
        /**
         * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
         * `approved`.
         */
        event ApprovalForAll(address indexed account, address indexed operator, bool approved);
        /**
         * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
         *
         * If an {URI} event was emitted for `id`, the standard
         * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
         * returned by {IERC1155MetadataURI-uri}.
         */
        event URI(string value, uint256 indexed id);
        /**
         * @dev Returns the amount of tokens of token type `id` owned by `account`.
         *
         * Requirements:
         *
         * - `account` cannot be the zero address.
         */
        function balanceOf(address account, uint256 id) external view returns (uint256);
        /**
         * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
         *
         * Requirements:
         *
         * - `accounts` and `ids` must have the same length.
         */
        function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
            external
            view
            returns (uint256[] memory);
        /**
         * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
         *
         * Emits an {ApprovalForAll} event.
         *
         * Requirements:
         *
         * - `operator` cannot be the caller.
         */
        function setApprovalForAll(address operator, bool approved) external;
        /**
         * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
         *
         * See {setApprovalForAll}.
         */
        function isApprovedForAll(address account, address operator) external view returns (bool);
        /**
         * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
         *
         * Emits a {TransferSingle} event.
         *
         * Requirements:
         *
         * - `to` cannot be the zero address.
         * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
         * - `from` must have a balance of tokens of type `id` of at least `amount`.
         * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
         * acceptance magic value.
         */
        function safeTransferFrom(
            address from,
            address to,
            uint256 id,
            uint256 amount,
            bytes calldata data
        ) external;
        /**
         * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
         *
         * Emits a {TransferBatch} event.
         *
         * Requirements:
         *
         * - `ids` and `amounts` must have the same length.
         * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
         * acceptance magic value.
         */
        function safeBatchTransferFrom(
            address from,
            address to,
            uint256[] calldata ids,
            uint256[] calldata amounts,
            bytes calldata data
        ) external;
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)
    pragma solidity ^0.8.0;
    import "../../utils/introspection/IERC165.sol";
    /**
     * @dev _Available since v3.1._
     */
    interface IERC1155Receiver is IERC165 {
        /**
         * @dev Handles the receipt of a single ERC1155 token type. This function is
         * called at the end of a `safeTransferFrom` after the balance has been updated.
         *
         * NOTE: To accept the transfer, this must return
         * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
         * (i.e. 0xf23a6e61, or its own function selector).
         *
         * @param operator The address which initiated the transfer (i.e. msg.sender)
         * @param from The address which previously owned the token
         * @param id The ID of the token being transferred
         * @param value The amount of tokens being transferred
         * @param data Additional data with no specified format
         * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
         */
        function onERC1155Received(
            address operator,
            address from,
            uint256 id,
            uint256 value,
            bytes calldata data
        ) external returns (bytes4);
        /**
         * @dev Handles the receipt of a multiple ERC1155 token types. This function
         * is called at the end of a `safeBatchTransferFrom` after the balances have
         * been updated.
         *
         * NOTE: To accept the transfer(s), this must return
         * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
         * (i.e. 0xbc197c81, or its own function selector).
         *
         * @param operator The address which initiated the batch transfer (i.e. msg.sender)
         * @param from The address which previously owned the token
         * @param ids An array containing ids of each token being transferred (order and length must match values array)
         * @param values An array containing amounts of each token being transferred (order and length must match ids array)
         * @param data Additional data with no specified format
         * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
         */
        function onERC1155BatchReceived(
            address operator,
            address from,
            uint256[] calldata ids,
            uint256[] calldata values,
            bytes calldata data
        ) external returns (bytes4);
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol)
    pragma solidity ^0.8.0;
    import "../IERC1155.sol";
    /**
     * @dev Interface of the optional ERC1155MetadataExtension interface, as defined
     * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
     *
     * _Available since v3.1._
     */
    interface IERC1155MetadataURI is IERC1155 {
        /**
         * @dev Returns the URI for token type `id`.
         *
         * If the `\\{id\\}` substring is present in the URI, it must be replaced by
         * clients with the actual token type ID.
         */
        function uri(uint256 id) external view returns (string memory);
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
    pragma solidity ^0.8.0;
    /**
     * @dev Interface of the ERC20 standard as defined in the EIP.
     */
    interface IERC20 {
        /**
         * @dev Emitted when `value` tokens are moved from one account (`from`) to
         * another (`to`).
         *
         * Note that `value` may be zero.
         */
        event Transfer(address indexed from, address indexed to, uint256 value);
        /**
         * @dev Emitted when the allowance of a `spender` for an `owner` is set by
         * a call to {approve}. `value` is the new allowance.
         */
        event Approval(address indexed owner, address indexed spender, uint256 value);
        /**
         * @dev Returns the amount of tokens in existence.
         */
        function totalSupply() external view returns (uint256);
        /**
         * @dev Returns the amount of tokens owned by `account`.
         */
        function balanceOf(address account) external view returns (uint256);
        /**
         * @dev Moves `amount` tokens from the caller's account to `to`.
         *
         * Returns a boolean value indicating whether the operation succeeded.
         *
         * Emits a {Transfer} event.
         */
        function transfer(address to, uint256 amount) external returns (bool);
        /**
         * @dev Returns the remaining number of tokens that `spender` will be
         * allowed to spend on behalf of `owner` through {transferFrom}. This is
         * zero by default.
         *
         * This value changes when {approve} or {transferFrom} are called.
         */
        function allowance(address owner, address spender) external view returns (uint256);
        /**
         * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
         *
         * Returns a boolean value indicating whether the operation succeeded.
         *
         * IMPORTANT: Beware that changing an allowance with this method brings the risk
         * that someone may use both the old and the new allowance by unfortunate
         * transaction ordering. One possible solution to mitigate this race
         * condition is to first reduce the spender's allowance to 0 and set the
         * desired value afterwards:
         * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
         *
         * Emits an {Approval} event.
         */
        function approve(address spender, uint256 amount) external returns (bool);
        /**
         * @dev Moves `amount` tokens from `from` to `to` using the
         * allowance mechanism. `amount` is then deducted from the caller's
         * allowance.
         *
         * Returns a boolean value indicating whether the operation succeeded.
         *
         * Emits a {Transfer} event.
         */
        function transferFrom(
            address from,
            address to,
            uint256 amount
        ) external returns (bool);
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)
    pragma solidity ^0.8.0;
    import "../../utils/introspection/IERC165.sol";
    /**
     * @dev Required interface of an ERC721 compliant contract.
     */
    interface IERC721 is IERC165 {
        /**
         * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
         */
        event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
        /**
         * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
         */
        event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
        /**
         * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
         */
        event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
        /**
         * @dev Returns the number of tokens in ``owner``'s account.
         */
        function balanceOf(address owner) external view returns (uint256 balance);
        /**
         * @dev Returns the owner of the `tokenId` token.
         *
         * Requirements:
         *
         * - `tokenId` must exist.
         */
        function ownerOf(uint256 tokenId) external view returns (address owner);
        /**
         * @dev Safely transfers `tokenId` token from `from` to `to`.
         *
         * Requirements:
         *
         * - `from` cannot be the zero address.
         * - `to` cannot be the zero address.
         * - `tokenId` token must exist and be owned by `from`.
         * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
         * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
         *
         * Emits a {Transfer} event.
         */
        function safeTransferFrom(
            address from,
            address to,
            uint256 tokenId,
            bytes calldata data
        ) external;
        /**
         * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
         * are aware of the ERC721 protocol to prevent tokens from being forever locked.
         *
         * Requirements:
         *
         * - `from` cannot be the zero address.
         * - `to` cannot be the zero address.
         * - `tokenId` token must exist and be owned by `from`.
         * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
         * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
         *
         * Emits a {Transfer} event.
         */
        function safeTransferFrom(
            address from,
            address to,
            uint256 tokenId
        ) external;
        /**
         * @dev Transfers `tokenId` token from `from` to `to`.
         *
         * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
         * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
         * understand this adds an external call which potentially creates a reentrancy vulnerability.
         *
         * Requirements:
         *
         * - `from` cannot be the zero address.
         * - `to` cannot be the zero address.
         * - `tokenId` token must be owned by `from`.
         * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
         *
         * Emits a {Transfer} event.
         */
        function transferFrom(
            address from,
            address to,
            uint256 tokenId
        ) external;
        /**
         * @dev Gives permission to `to` to transfer `tokenId` token to another account.
         * The approval is cleared when the token is transferred.
         *
         * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
         *
         * Requirements:
         *
         * - The caller must own the token or be an approved operator.
         * - `tokenId` must exist.
         *
         * Emits an {Approval} event.
         */
        function approve(address to, uint256 tokenId) external;
        /**
         * @dev Approve or remove `operator` as an operator for the caller.
         * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
         *
         * Requirements:
         *
         * - The `operator` cannot be the caller.
         *
         * Emits an {ApprovalForAll} event.
         */
        function setApprovalForAll(address operator, bool _approved) external;
        /**
         * @dev Returns the account approved for `tokenId` token.
         *
         * Requirements:
         *
         * - `tokenId` must exist.
         */
        function getApproved(uint256 tokenId) external view returns (address operator);
        /**
         * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
         *
         * See {setApprovalForAll}
         */
        function isApprovedForAll(address owner, address operator) external view returns (bool);
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
    pragma solidity ^0.8.0;
    /**
     * @title ERC721 token receiver interface
     * @dev Interface for any contract that wants to support safeTransfers
     * from ERC721 asset contracts.
     */
    interface IERC721Receiver {
        /**
         * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
         * by `operator` from `from`, this function is called.
         *
         * It must return its Solidity selector to confirm the token transfer.
         * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
         *
         * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
         */
        function onERC721Received(
            address operator,
            address from,
            uint256 tokenId,
            bytes calldata data
        ) external returns (bytes4);
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
    pragma solidity ^0.8.1;
    /**
     * @dev Collection of functions related to the address type
     */
    library Address {
        /**
         * @dev Returns true if `account` is a contract.
         *
         * [IMPORTANT]
         * ====
         * It is unsafe to assume that an address for which this function returns
         * false is an externally-owned account (EOA) and not a contract.
         *
         * Among others, `isContract` will return false for the following
         * types of addresses:
         *
         *  - an externally-owned account
         *  - a contract in construction
         *  - an address where a contract will be created
         *  - an address where a contract lived, but was destroyed
         * ====
         *
         * [IMPORTANT]
         * ====
         * You shouldn't rely on `isContract` to protect against flash loan attacks!
         *
         * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
         * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
         * constructor.
         * ====
         */
        function isContract(address account) internal view returns (bool) {
            // This method relies on extcodesize/address.code.length, which returns 0
            // for contracts in construction, since the code is only stored at the end
            // of the constructor execution.
            return account.code.length > 0;
        }
        /**
         * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
         * `recipient`, forwarding all available gas and reverting on errors.
         *
         * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
         * of certain opcodes, possibly making contracts go over the 2300 gas limit
         * imposed by `transfer`, making them unable to receive funds via
         * `transfer`. {sendValue} removes this limitation.
         *
         * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
         *
         * IMPORTANT: because control is transferred to `recipient`, care must be
         * taken to not create reentrancy vulnerabilities. Consider using
         * {ReentrancyGuard} or the
         * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
         */
        function sendValue(address payable recipient, uint256 amount) internal {
            require(address(this).balance >= amount, "Address: insufficient balance");
            (bool success, ) = recipient.call{value: amount}("");
            require(success, "Address: unable to send value, recipient may have reverted");
        }
        /**
         * @dev Performs a Solidity function call using a low level `call`. A
         * plain `call` is an unsafe replacement for a function call: use this
         * function instead.
         *
         * If `target` reverts with a revert reason, it is bubbled up by this
         * function (like regular Solidity function calls).
         *
         * Returns the raw returned data. To convert to the expected return value,
         * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
         *
         * Requirements:
         *
         * - `target` must be a contract.
         * - calling `target` with `data` must not revert.
         *
         * _Available since v3.1._
         */
        function functionCall(address target, bytes memory data) internal returns (bytes memory) {
            return functionCallWithValue(target, data, 0, "Address: low-level call failed");
        }
        /**
         * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
         * `errorMessage` as a fallback revert reason when `target` reverts.
         *
         * _Available since v3.1._
         */
        function functionCall(
            address target,
            bytes memory data,
            string memory errorMessage
        ) internal returns (bytes memory) {
            return functionCallWithValue(target, data, 0, errorMessage);
        }
        /**
         * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
         * but also transferring `value` wei to `target`.
         *
         * Requirements:
         *
         * - the calling contract must have an ETH balance of at least `value`.
         * - the called Solidity function must be `payable`.
         *
         * _Available since v3.1._
         */
        function functionCallWithValue(
            address target,
            bytes memory data,
            uint256 value
        ) internal returns (bytes memory) {
            return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
        }
        /**
         * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
         * with `errorMessage` as a fallback revert reason when `target` reverts.
         *
         * _Available since v3.1._
         */
        function functionCallWithValue(
            address target,
            bytes memory data,
            uint256 value,
            string memory errorMessage
        ) internal returns (bytes memory) {
            require(address(this).balance >= value, "Address: insufficient balance for call");
            (bool success, bytes memory returndata) = target.call{value: value}(data);
            return verifyCallResultFromTarget(target, success, returndata, errorMessage);
        }
        /**
         * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
         * but performing a static call.
         *
         * _Available since v3.3._
         */
        function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
            return functionStaticCall(target, data, "Address: low-level static call failed");
        }
        /**
         * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
         * but performing a static call.
         *
         * _Available since v3.3._
         */
        function functionStaticCall(
            address target,
            bytes memory data,
            string memory errorMessage
        ) internal view returns (bytes memory) {
            (bool success, bytes memory returndata) = target.staticcall(data);
            return verifyCallResultFromTarget(target, success, returndata, errorMessage);
        }
        /**
         * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
         * but performing a delegate call.
         *
         * _Available since v3.4._
         */
        function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
            return functionDelegateCall(target, data, "Address: low-level delegate call failed");
        }
        /**
         * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
         * but performing a delegate call.
         *
         * _Available since v3.4._
         */
        function functionDelegateCall(
            address target,
            bytes memory data,
            string memory errorMessage
        ) internal returns (bytes memory) {
            (bool success, bytes memory returndata) = target.delegatecall(data);
            return verifyCallResultFromTarget(target, success, returndata, errorMessage);
        }
        /**
         * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
         * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
         *
         * _Available since v4.8._
         */
        function verifyCallResultFromTarget(
            address target,
            bool success,
            bytes memory returndata,
            string memory errorMessage
        ) internal view returns (bytes memory) {
            if (success) {
                if (returndata.length == 0) {
                    // only check isContract if the call was successful and the return data is empty
                    // otherwise we already know that it was a contract
                    require(isContract(target), "Address: call to non-contract");
                }
                return returndata;
            } else {
                _revert(returndata, errorMessage);
            }
        }
        /**
         * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
         * revert reason or using the provided one.
         *
         * _Available since v4.3._
         */
        function verifyCallResult(
            bool success,
            bytes memory returndata,
            string memory errorMessage
        ) internal pure returns (bytes memory) {
            if (success) {
                return returndata;
            } else {
                _revert(returndata, errorMessage);
            }
        }
        function _revert(bytes memory returndata, string memory errorMessage) private pure {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
    pragma solidity ^0.8.0;
    /**
     * @dev Provides information about the current execution context, including the
     * sender of the transaction and its data. While these are generally available
     * via msg.sender and msg.data, they should not be accessed in such a direct
     * manner, since when dealing with meta-transactions the account sending and
     * paying for execution may not be the actual sender (as far as an application
     * is concerned).
     *
     * This contract is only required for intermediate, library-like contracts.
     */
    abstract contract Context {
        function _msgSender() internal view virtual returns (address) {
            return msg.sender;
        }
        function _msgData() internal view virtual returns (bytes calldata) {
            return msg.data;
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
    pragma solidity ^0.8.0;
    import "./IERC165.sol";
    /**
     * @dev Implementation of the {IERC165} interface.
     *
     * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
     * for the additional interface id that will be supported. For example:
     *
     * ```solidity
     * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
     *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
     * }
     * ```
     *
     * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
     */
    abstract contract ERC165 is IERC165 {
        /**
         * @dev See {IERC165-supportsInterface}.
         */
        function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
            return interfaceId == type(IERC165).interfaceId;
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
    pragma solidity ^0.8.0;
    /**
     * @dev Interface of the ERC165 standard, as defined in the
     * https://eips.ethereum.org/EIPS/eip-165[EIP].
     *
     * Implementers can declare support of contract interfaces, which can then be
     * queried by others ({ERC165Checker}).
     *
     * For an implementation, see {ERC165}.
     */
    interface IERC165 {
        /**
         * @dev Returns true if this contract implements the interface defined by
         * `interfaceId`. See the corresponding
         * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
         * to learn more about how these ids are created.
         *
         * This function call must use less than 30 000 gas.
         */
        function supportsInterface(bytes4 interfaceId) external view returns (bool);
    }
    import "../registry/ENS.sol";
    import "./IBaseRegistrar.sol";
    import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
    interface IBaseRegistrar is IERC721 {
        event ControllerAdded(address indexed controller);
        event ControllerRemoved(address indexed controller);
        event NameMigrated(
            uint256 indexed id,
            address indexed owner,
            uint256 expires
        );
        event NameRegistered(
            uint256 indexed id,
            address indexed owner,
            uint256 expires
        );
        event NameRenewed(uint256 indexed id, uint256 expires);
        // Authorises a controller, who can register and renew domains.
        function addController(address controller) external;
        // Revoke controller permission for an address.
        function removeController(address controller) external;
        // Set the resolver for the TLD this registrar manages.
        function setResolver(address resolver) external;
        // Returns the expiration timestamp of the specified label hash.
        function nameExpires(uint256 id) external view returns (uint256);
        // Returns true iff the specified name is available for registration.
        function available(uint256 id) external view returns (bool);
        /**
         * @dev Register a name.
         */
        function register(
            uint256 id,
            address owner,
            uint256 duration
        ) external returns (uint256);
        function renew(uint256 id, uint256 duration) external returns (uint256);
        /**
         * @dev Reclaim ownership of a name in ENS, if you own it in the registrar.
         */
        function reclaim(uint256 id, address owner) external;
    }
    pragma solidity >=0.8.4;
    interface ENS {
        // Logged when the owner of a node assigns a new owner to a subnode.
        event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);
        // Logged when the owner of a node transfers ownership to a new account.
        event Transfer(bytes32 indexed node, address owner);
        // Logged when the resolver for a node changes.
        event NewResolver(bytes32 indexed node, address resolver);
        // Logged when the TTL of a node changes
        event NewTTL(bytes32 indexed node, uint64 ttl);
        // Logged when an operator is added or removed.
        event ApprovalForAll(
            address indexed owner,
            address indexed operator,
            bool approved
        );
        function setRecord(
            bytes32 node,
            address owner,
            address resolver,
            uint64 ttl
        ) external;
        function setSubnodeRecord(
            bytes32 node,
            bytes32 label,
            address owner,
            address resolver,
            uint64 ttl
        ) external;
        function setSubnodeOwner(
            bytes32 node,
            bytes32 label,
            address owner
        ) external returns (bytes32);
        function setResolver(bytes32 node, address resolver) external;
        function setOwner(bytes32 node, address owner) external;
        function setTTL(bytes32 node, uint64 ttl) external;
        function setApprovalForAll(address operator, bool approved) external;
        function owner(bytes32 node) external view returns (address);
        function resolver(bytes32 node) external view returns (address);
        function ttl(bytes32 node) external view returns (uint64);
        function recordExists(bytes32 node) external view returns (bool);
        function isApprovedForAll(
            address owner,
            address operator
        ) external view returns (bool);
    }
    pragma solidity >=0.8.4;
    interface IReverseRegistrar {
        function setDefaultResolver(address resolver) external;
        function claim(address owner) external returns (bytes32);
        function claimForAddr(
            address addr,
            address owner,
            address resolver
        ) external returns (bytes32);
        function claimWithResolver(
            address owner,
            address resolver
        ) external returns (bytes32);
        function setName(string memory name) external returns (bytes32);
        function setNameForAddr(
            address addr,
            address owner,
            address resolver,
            string memory name
        ) external returns (bytes32);
        function node(address addr) external pure returns (bytes32);
    }
    //SPDX-License-Identifier: MIT
    pragma solidity >=0.8.17 <0.9.0;
    import {ENS} from "../registry/ENS.sol";
    import {IReverseRegistrar} from "../reverseRegistrar/IReverseRegistrar.sol";
    contract ReverseClaimer {
        bytes32 constant ADDR_REVERSE_NODE =
            0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2;
        constructor(ENS ens, address claimant) {
            IReverseRegistrar reverseRegistrar = IReverseRegistrar(
                ens.owner(ADDR_REVERSE_NODE)
            );
            reverseRegistrar.claim(claimant);
        }
    }
    //SPDX-License-Identifier: MIT
    pragma solidity >=0.8.17 <0.9.0;
    import "@openzeppelin/contracts/access/Ownable.sol";
    import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
    /**
        @notice Contract is used to recover ERC20 tokens sent to the contract by mistake.
     */
    contract ERC20Recoverable is Ownable {
        /**
        @notice Recover ERC20 tokens sent to the contract by mistake.
        @dev The contract is Ownable and only the owner can call the recover function.
        @param _to The address to send the tokens to.
    @param _token The address of the ERC20 token to recover
        @param _amount The amount of tokens to recover.
     */
        function recoverFunds(
            address _token,
            address _to,
            uint256 _amount
        ) external onlyOwner {
            IERC20(_token).transfer(_to, _amount);
        }
    }
    //SPDX-License-Identifier: MIT
    pragma solidity ~0.8.17;
    library BytesUtils {
        /*
         * @dev Returns the keccak-256 hash of a byte range.
         * @param self The byte string to hash.
         * @param offset The position to start hashing at.
         * @param len The number of bytes to hash.
         * @return The hash of the byte range.
         */
        function keccak(
            bytes memory self,
            uint256 offset,
            uint256 len
        ) internal pure returns (bytes32 ret) {
            require(offset + len <= self.length);
            assembly {
                ret := keccak256(add(add(self, 32), offset), len)
            }
        }
        /**
         * @dev Returns the ENS namehash of a DNS-encoded name.
         * @param self The DNS-encoded name to hash.
         * @param offset The offset at which to start hashing.
         * @return The namehash of the name.
         */
        function namehash(
            bytes memory self,
            uint256 offset
        ) internal pure returns (bytes32) {
            (bytes32 labelhash, uint256 newOffset) = readLabel(self, offset);
            if (labelhash == bytes32(0)) {
                require(offset == self.length - 1, "namehash: Junk at end of name");
                return bytes32(0);
            }
            return
                keccak256(abi.encodePacked(namehash(self, newOffset), labelhash));
        }
        /**
         * @dev Returns the keccak-256 hash of a DNS-encoded label, and the offset to the start of the next label.
         * @param self The byte string to read a label from.
         * @param idx The index to read a label at.
         * @return labelhash The hash of the label at the specified index, or 0 if it is the last label.
         * @return newIdx The index of the start of the next label.
         */
        function readLabel(
            bytes memory self,
            uint256 idx
        ) internal pure returns (bytes32 labelhash, uint256 newIdx) {
            require(idx < self.length, "readLabel: Index out of bounds");
            uint256 len = uint256(uint8(self[idx]));
            if (len > 0) {
                labelhash = keccak(self, idx + 1, len);
            } else {
                labelhash = bytes32(0);
            }
            newIdx = idx + len + 1;
        }
    }
    //SPDX-License-Identifier: MIT
    pragma solidity ~0.8.17;
    import "@openzeppelin/contracts/access/Ownable.sol";
    contract Controllable is Ownable {
        mapping(address => bool) public controllers;
        event ControllerChanged(address indexed controller, bool active);
        function setController(address controller, bool active) public onlyOwner {
            controllers[controller] = active;
            emit ControllerChanged(controller, active);
        }
        modifier onlyController() {
            require(
                controllers[msg.sender],
                "Controllable: Caller is not a controller"
            );
            _;
        }
    }
    //SPDX-License-Identifier: MIT
    pragma solidity ~0.8.17;
    import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
    import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
    import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
    import "@openzeppelin/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol";
    import "@openzeppelin/contracts/utils/Address.sol";
    /* This contract is a variation on ERC1155 with the additions of _setData, getData and _beforeTransfer and ownerOf. _setData and getData allows the use of the other 96 bits next to the address of the owner for extra data. We use this to store 'fuses' that control permissions that can be burnt. 32 bits are used for the fuses themselves and 64 bits are used for the expiry of the name. When a name has expired, its fuses will be be set back to 0 */
    abstract contract ERC1155Fuse is ERC165, IERC1155, IERC1155MetadataURI {
        using Address for address;
        /**
         * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
         */
        event Approval(
            address indexed owner,
            address indexed approved,
            uint256 indexed tokenId
        );
        mapping(uint256 => uint256) public _tokens;
        // Mapping from owner to operator approvals
        mapping(address => mapping(address => bool)) private _operatorApprovals;
        // Mapping from token ID to approved address
        mapping(uint256 => address) internal _tokenApprovals;
        /**************************************************************************
         * ERC721 methods
         *************************************************************************/
        function ownerOf(uint256 id) public view virtual returns (address) {
            (address owner, , ) = getData(id);
            return owner;
        }
        /**
         * @dev See {IERC721-approve}.
         */
        function approve(address to, uint256 tokenId) public virtual {
            address owner = ownerOf(tokenId);
            require(to != owner, "ERC721: approval to current owner");
            require(
                msg.sender == owner || isApprovedForAll(owner, msg.sender),
                "ERC721: approve caller is not token owner or approved for all"
            );
            _approve(to, tokenId);
        }
        /**
         * @dev See {IERC721-getApproved}.
         */
        function getApproved(
            uint256 tokenId
        ) public view virtual returns (address) {
            return _tokenApprovals[tokenId];
        }
        /**
         * @dev See {IERC165-supportsInterface}.
         */
        function supportsInterface(
            bytes4 interfaceId
        ) public view virtual override(ERC165, IERC165) returns (bool) {
            return
                interfaceId == type(IERC1155).interfaceId ||
                interfaceId == type(IERC1155MetadataURI).interfaceId ||
                super.supportsInterface(interfaceId);
        }
        /**
         * @dev See {IERC1155-balanceOf}.
         *
         * Requirements:
         *
         * - `account` cannot be the zero address.
         */
        function balanceOf(
            address account,
            uint256 id
        ) public view virtual override returns (uint256) {
            require(
                account != address(0),
                "ERC1155: balance query for the zero address"
            );
            address owner = ownerOf(id);
            if (owner == account) {
                return 1;
            }
            return 0;
        }
        /**
         * @dev See {IERC1155-balanceOfBatch}.
         *
         * Requirements:
         *
         * - `accounts` and `ids` must have the same length.
         */
        function balanceOfBatch(
            address[] memory accounts,
            uint256[] memory ids
        ) public view virtual override returns (uint256[] memory) {
            require(
                accounts.length == ids.length,
                "ERC1155: accounts and ids length mismatch"
            );
            uint256[] memory batchBalances = new uint256[](accounts.length);
            for (uint256 i = 0; i < accounts.length; ++i) {
                batchBalances[i] = balanceOf(accounts[i], ids[i]);
            }
            return batchBalances;
        }
        /**
         * @dev See {IERC1155-setApprovalForAll}.
         */
        function setApprovalForAll(
            address operator,
            bool approved
        ) public virtual override {
            require(
                msg.sender != operator,
                "ERC1155: setting approval status for self"
            );
            _operatorApprovals[msg.sender][operator] = approved;
            emit ApprovalForAll(msg.sender, operator, approved);
        }
        /**
         * @dev See {IERC1155-isApprovedForAll}.
         */
        function isApprovedForAll(
            address account,
            address operator
        ) public view virtual override returns (bool) {
            return _operatorApprovals[account][operator];
        }
        /**
         * @dev Returns the Name's owner address and fuses
         */
        function getData(
            uint256 tokenId
        ) public view virtual returns (address owner, uint32 fuses, uint64 expiry) {
            uint256 t = _tokens[tokenId];
            owner = address(uint160(t));
            expiry = uint64(t >> 192);
            fuses = uint32(t >> 160);
        }
        /**
         * @dev See {IERC1155-safeTransferFrom}.
         */
        function safeTransferFrom(
            address from,
            address to,
            uint256 id,
            uint256 amount,
            bytes memory data
        ) public virtual override {
            require(to != address(0), "ERC1155: transfer to the zero address");
            require(
                from == msg.sender || isApprovedForAll(from, msg.sender),
                "ERC1155: caller is not owner nor approved"
            );
            _transfer(from, to, id, amount, data);
        }
        /**
         * @dev See {IERC1155-safeBatchTransferFrom}.
         */
        function safeBatchTransferFrom(
            address from,
            address to,
            uint256[] memory ids,
            uint256[] memory amounts,
            bytes memory data
        ) public virtual override {
            require(
                ids.length == amounts.length,
                "ERC1155: ids and amounts length mismatch"
            );
            require(to != address(0), "ERC1155: transfer to the zero address");
            require(
                from == msg.sender || isApprovedForAll(from, msg.sender),
                "ERC1155: transfer caller is not owner nor approved"
            );
            for (uint256 i = 0; i < ids.length; ++i) {
                uint256 id = ids[i];
                uint256 amount = amounts[i];
                (address oldOwner, uint32 fuses, uint64 expiry) = getData(id);
                _beforeTransfer(id, fuses, expiry);
                require(
                    amount == 1 && oldOwner == from,
                    "ERC1155: insufficient balance for transfer"
                );
                _setData(id, to, fuses, expiry);
            }
            emit TransferBatch(msg.sender, from, to, ids, amounts);
            _doSafeBatchTransferAcceptanceCheck(
                msg.sender,
                from,
                to,
                ids,
                amounts,
                data
            );
        }
        /**************************************************************************
         * Internal/private methods
         *************************************************************************/
        /**
         * @dev Sets the Name's owner address and fuses
         */
        function _setData(
            uint256 tokenId,
            address owner,
            uint32 fuses,
            uint64 expiry
        ) internal virtual {
            _tokens[tokenId] =
                uint256(uint160(owner)) |
                (uint256(fuses) << 160) |
                (uint256(expiry) << 192);
        }
        function _beforeTransfer(
            uint256 id,
            uint32 fuses,
            uint64 expiry
        ) internal virtual;
        function _clearOwnerAndFuses(
            address owner,
            uint32 fuses,
            uint64 expiry
        ) internal virtual returns (address, uint32);
        function _mint(
            bytes32 node,
            address owner,
            uint32 fuses,
            uint64 expiry
        ) internal virtual {
            uint256 tokenId = uint256(node);
            (address oldOwner, uint32 oldFuses, uint64 oldExpiry) = getData(
                uint256(node)
            );
            uint32 parentControlledFuses = (uint32(type(uint16).max) << 16) &
                oldFuses;
            if (oldExpiry > expiry) {
                expiry = oldExpiry;
            }
            if (oldExpiry >= block.timestamp) {
                fuses = fuses | parentControlledFuses;
            }
            require(oldOwner == address(0), "ERC1155: mint of existing token");
            require(owner != address(0), "ERC1155: mint to the zero address");
            require(
                owner != address(this),
                "ERC1155: newOwner cannot be the NameWrapper contract"
            );
            _setData(tokenId, owner, fuses, expiry);
            emit TransferSingle(msg.sender, address(0x0), owner, tokenId, 1);
            _doSafeTransferAcceptanceCheck(
                msg.sender,
                address(0),
                owner,
                tokenId,
                1,
                ""
            );
        }
        function _burn(uint256 tokenId) internal virtual {
            (address oldOwner, uint32 fuses, uint64 expiry) = ERC1155Fuse.getData(
                tokenId
            );
            (, fuses) = _clearOwnerAndFuses(oldOwner, fuses, expiry);
            // Clear approvals
            delete _tokenApprovals[tokenId];
            // Fuses and expiry are kept on burn
            _setData(tokenId, address(0x0), fuses, expiry);
            emit TransferSingle(msg.sender, oldOwner, address(0x0), tokenId, 1);
        }
        function _transfer(
            address from,
            address to,
            uint256 id,
            uint256 amount,
            bytes memory data
        ) internal {
            (address oldOwner, uint32 fuses, uint64 expiry) = getData(id);
            _beforeTransfer(id, fuses, expiry);
            require(
                amount == 1 && oldOwner == from,
                "ERC1155: insufficient balance for transfer"
            );
            if (oldOwner == to) {
                return;
            }
            _setData(id, to, fuses, expiry);
            emit TransferSingle(msg.sender, from, to, id, amount);
            _doSafeTransferAcceptanceCheck(msg.sender, from, to, id, amount, data);
        }
        function _doSafeTransferAcceptanceCheck(
            address operator,
            address from,
            address to,
            uint256 id,
            uint256 amount,
            bytes memory data
        ) private {
            if (to.isContract()) {
                try
                    IERC1155Receiver(to).onERC1155Received(
                        operator,
                        from,
                        id,
                        amount,
                        data
                    )
                returns (bytes4 response) {
                    if (
                        response != IERC1155Receiver(to).onERC1155Received.selector
                    ) {
                        revert("ERC1155: ERC1155Receiver rejected tokens");
                    }
                } catch Error(string memory reason) {
                    revert(reason);
                } catch {
                    revert("ERC1155: transfer to non ERC1155Receiver implementer");
                }
            }
        }
        function _doSafeBatchTransferAcceptanceCheck(
            address operator,
            address from,
            address to,
            uint256[] memory ids,
            uint256[] memory amounts,
            bytes memory data
        ) private {
            if (to.isContract()) {
                try
                    IERC1155Receiver(to).onERC1155BatchReceived(
                        operator,
                        from,
                        ids,
                        amounts,
                        data
                    )
                returns (bytes4 response) {
                    if (
                        response !=
                        IERC1155Receiver(to).onERC1155BatchReceived.selector
                    ) {
                        revert("ERC1155: ERC1155Receiver rejected tokens");
                    }
                } catch Error(string memory reason) {
                    revert(reason);
                } catch {
                    revert("ERC1155: transfer to non ERC1155Receiver implementer");
                }
            }
        }
        /* ERC721 internal functions */
        /**
         * @dev Approve `to` to operate on `tokenId`
         *
         * Emits an {Approval} event.
         */
        function _approve(address to, uint256 tokenId) internal virtual {
            _tokenApprovals[tokenId] = to;
            emit Approval(ownerOf(tokenId), to, tokenId);
        }
    }
    //SPDX-License-Identifier: MIT
    pragma solidity ~0.8.17;
    interface IMetadataService {
        function uri(uint256) external view returns (string memory);
    }
    //SPDX-License-Identifier: MIT
    pragma solidity ~0.8.17;
    import "../registry/ENS.sol";
    import "../ethregistrar/IBaseRegistrar.sol";
    import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
    import "./IMetadataService.sol";
    import "./INameWrapperUpgrade.sol";
    uint32 constant CANNOT_UNWRAP = 1;
    uint32 constant CANNOT_BURN_FUSES = 2;
    uint32 constant CANNOT_TRANSFER = 4;
    uint32 constant CANNOT_SET_RESOLVER = 8;
    uint32 constant CANNOT_SET_TTL = 16;
    uint32 constant CANNOT_CREATE_SUBDOMAIN = 32;
    uint32 constant CANNOT_APPROVE = 64;
    //uint16 reserved for parent controlled fuses from bit 17 to bit 32
    uint32 constant PARENT_CANNOT_CONTROL = 1 << 16;
    uint32 constant IS_DOT_ETH = 1 << 17;
    uint32 constant CAN_EXTEND_EXPIRY = 1 << 18;
    uint32 constant CAN_DO_EVERYTHING = 0;
    uint32 constant PARENT_CONTROLLED_FUSES = 0xFFFF0000;
    // all fuses apart from IS_DOT_ETH
    uint32 constant USER_SETTABLE_FUSES = 0xFFFDFFFF;
    interface INameWrapper is IERC1155 {
        event NameWrapped(
            bytes32 indexed node,
            bytes name,
            address owner,
            uint32 fuses,
            uint64 expiry
        );
        event NameUnwrapped(bytes32 indexed node, address owner);
        event FusesSet(bytes32 indexed node, uint32 fuses);
        event ExpiryExtended(bytes32 indexed node, uint64 expiry);
        function ens() external view returns (ENS);
        function registrar() external view returns (IBaseRegistrar);
        function metadataService() external view returns (IMetadataService);
        function names(bytes32) external view returns (bytes memory);
        function name() external view returns (string memory);
        function upgradeContract() external view returns (INameWrapperUpgrade);
        function supportsInterface(bytes4 interfaceID) external view returns (bool);
        function wrap(
            bytes calldata name,
            address wrappedOwner,
            address resolver
        ) external;
        function wrapETH2LD(
            string calldata label,
            address wrappedOwner,
            uint16 ownerControlledFuses,
            address resolver
        ) external returns (uint64 expires);
        function registerAndWrapETH2LD(
            string calldata label,
            address wrappedOwner,
            uint256 duration,
            address resolver,
            uint16 ownerControlledFuses
        ) external returns (uint256 registrarExpiry);
        function renew(
            uint256 labelHash,
            uint256 duration
        ) external returns (uint256 expires);
        function unwrap(bytes32 node, bytes32 label, address owner) external;
        function unwrapETH2LD(
            bytes32 label,
            address newRegistrant,
            address newController
        ) external;
        function upgrade(bytes calldata name, bytes calldata extraData) external;
        function setFuses(
            bytes32 node,
            uint16 ownerControlledFuses
        ) external returns (uint32 newFuses);
        function setChildFuses(
            bytes32 parentNode,
            bytes32 labelhash,
            uint32 fuses,
            uint64 expiry
        ) external;
        function setSubnodeRecord(
            bytes32 node,
            string calldata label,
            address owner,
            address resolver,
            uint64 ttl,
            uint32 fuses,
            uint64 expiry
        ) external returns (bytes32);
        function setRecord(
            bytes32 node,
            address owner,
            address resolver,
            uint64 ttl
        ) external;
        function setSubnodeOwner(
            bytes32 node,
            string calldata label,
            address newOwner,
            uint32 fuses,
            uint64 expiry
        ) external returns (bytes32);
        function extendExpiry(
            bytes32 node,
            bytes32 labelhash,
            uint64 expiry
        ) external returns (uint64);
        function canModifyName(
            bytes32 node,
            address addr
        ) external view returns (bool);
        function setResolver(bytes32 node, address resolver) external;
        function setTTL(bytes32 node, uint64 ttl) external;
        function ownerOf(uint256 id) external view returns (address owner);
        function approve(address to, uint256 tokenId) external;
        function getApproved(uint256 tokenId) external view returns (address);
        function getData(
            uint256 id
        ) external view returns (address, uint32, uint64);
        function setMetadataService(IMetadataService _metadataService) external;
        function uri(uint256 tokenId) external view returns (string memory);
        function setUpgradeContract(INameWrapperUpgrade _upgradeAddress) external;
        function allFusesBurned(
            bytes32 node,
            uint32 fuseMask
        ) external view returns (bool);
        function isWrapped(bytes32) external view returns (bool);
        function isWrapped(bytes32, bytes32) external view returns (bool);
    }
    //SPDX-License-Identifier: MIT
    pragma solidity ~0.8.17;
    interface INameWrapperUpgrade {
        function wrapFromUpgrade(
            bytes calldata name,
            address wrappedOwner,
            uint32 fuses,
            uint64 expiry,
            address approved,
            bytes calldata extraData
        ) external;
    }
    //SPDX-License-Identifier: MIT
    pragma solidity ~0.8.17;
    import {ERC1155Fuse, IERC165, IERC1155MetadataURI} from "./ERC1155Fuse.sol";
    import {Controllable} from "./Controllable.sol";
    import {INameWrapper, CANNOT_UNWRAP, CANNOT_BURN_FUSES, CANNOT_TRANSFER, CANNOT_SET_RESOLVER, CANNOT_SET_TTL, CANNOT_CREATE_SUBDOMAIN, CANNOT_APPROVE, PARENT_CANNOT_CONTROL, CAN_DO_EVERYTHING, IS_DOT_ETH, CAN_EXTEND_EXPIRY, PARENT_CONTROLLED_FUSES, USER_SETTABLE_FUSES} from "./INameWrapper.sol";
    import {INameWrapperUpgrade} from "./INameWrapperUpgrade.sol";
    import {IMetadataService} from "./IMetadataService.sol";
    import {ENS} from "../registry/ENS.sol";
    import {IReverseRegistrar} from "../reverseRegistrar/IReverseRegistrar.sol";
    import {ReverseClaimer} from "../reverseRegistrar/ReverseClaimer.sol";
    import {IBaseRegistrar} from "../ethregistrar/IBaseRegistrar.sol";
    import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
    import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
    import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
    import {BytesUtils} from "./BytesUtils.sol";
    import {ERC20Recoverable} from "../utils/ERC20Recoverable.sol";
    error Unauthorised(bytes32 node, address addr);
    error IncompatibleParent();
    error IncorrectTokenType();
    error LabelMismatch(bytes32 labelHash, bytes32 expectedLabelhash);
    error LabelTooShort();
    error LabelTooLong(string label);
    error IncorrectTargetOwner(address owner);
    error CannotUpgrade();
    error OperationProhibited(bytes32 node);
    error NameIsNotWrapped();
    error NameIsStillExpired();
    contract NameWrapper is
        Ownable,
        ERC1155Fuse,
        INameWrapper,
        Controllable,
        IERC721Receiver,
        ERC20Recoverable,
        ReverseClaimer
    {
        using BytesUtils for bytes;
        ENS public immutable ens;
        IBaseRegistrar public immutable registrar;
        IMetadataService public metadataService;
        mapping(bytes32 => bytes) public names;
        string public constant name = "NameWrapper";
        uint64 private constant GRACE_PERIOD = 90 days;
        bytes32 private constant ETH_NODE =
            0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;
        bytes32 private constant ETH_LABELHASH =
            0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0;
        bytes32 private constant ROOT_NODE =
            0x0000000000000000000000000000000000000000000000000000000000000000;
        INameWrapperUpgrade public upgradeContract;
        uint64 private constant MAX_EXPIRY = type(uint64).max;
        constructor(
            ENS _ens,
            IBaseRegistrar _registrar,
            IMetadataService _metadataService
        ) ReverseClaimer(_ens, msg.sender) {
            ens = _ens;
            registrar = _registrar;
            metadataService = _metadataService;
            /* Burn PARENT_CANNOT_CONTROL and CANNOT_UNWRAP fuses for ROOT_NODE and ETH_NODE and set expiry to max */
            _setData(
                uint256(ETH_NODE),
                address(0),
                uint32(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP),
                MAX_EXPIRY
            );
            _setData(
                uint256(ROOT_NODE),
                address(0),
                uint32(PARENT_CANNOT_CONTROL | CANNOT_UNWRAP),
                MAX_EXPIRY
            );
            names[ROOT_NODE] = "\\x00";
            names[ETH_NODE] = "\\x03eth\\x00";
        }
        function supportsInterface(
            bytes4 interfaceId
        ) public view virtual override(ERC1155Fuse, INameWrapper) returns (bool) {
            return
                interfaceId == type(INameWrapper).interfaceId ||
                interfaceId == type(IERC721Receiver).interfaceId ||
                super.supportsInterface(interfaceId);
        }
        /* ERC1155 Fuse */
        /**
         * @notice Gets the owner of a name
         * @param id Label as a string of the .eth domain to wrap
         * @return owner The owner of the name
         */
        function ownerOf(
            uint256 id
        ) public view override(ERC1155Fuse, INameWrapper) returns (address owner) {
            return super.ownerOf(id);
        }
        /**
         * @notice Gets the owner of a name
         * @param id Namehash of the name
         * @return operator Approved operator of a name
         */
        function getApproved(
            uint256 id
        )
            public
            view
            override(ERC1155Fuse, INameWrapper)
            returns (address operator)
        {
            address owner = ownerOf(id);
            if (owner == address(0)) {
                return address(0);
            }
            return super.getApproved(id);
        }
        /**
         * @notice Approves an address for a name
         * @param to address to approve
         * @param tokenId name to approve
         */
        function approve(
            address to,
            uint256 tokenId
        ) public override(ERC1155Fuse, INameWrapper) {
            (, uint32 fuses, ) = getData(tokenId);
            if (fuses & CANNOT_APPROVE == CANNOT_APPROVE) {
                revert OperationProhibited(bytes32(tokenId));
            }
            super.approve(to, tokenId);
        }
        /**
         * @notice Gets the data for a name
         * @param id Namehash of the name
         * @return owner Owner of the name
         * @return fuses Fuses of the name
         * @return expiry Expiry of the name
         */
        function getData(
            uint256 id
        )
            public
            view
            override(ERC1155Fuse, INameWrapper)
            returns (address owner, uint32 fuses, uint64 expiry)
        {
            (owner, fuses, expiry) = super.getData(id);
            (owner, fuses) = _clearOwnerAndFuses(owner, fuses, expiry);
        }
        /* Metadata service */
        /**
         * @notice Set the metadata service. Only the owner can do this
         * @param _metadataService The new metadata service
         */
        function setMetadataService(
            IMetadataService _metadataService
        ) public onlyOwner {
            metadataService = _metadataService;
        }
        /**
         * @notice Get the metadata uri
         * @param tokenId The id of the token
         * @return string uri of the metadata service
         */
        function uri(
            uint256 tokenId
        )
            public
            view
            override(INameWrapper, IERC1155MetadataURI)
            returns (string memory)
        {
            return metadataService.uri(tokenId);
        }
        /**
         * @notice Set the address of the upgradeContract of the contract. only admin can do this
         * @dev The default value of upgradeContract is the 0 address. Use the 0 address at any time
         * to make the contract not upgradable.
         * @param _upgradeAddress address of an upgraded contract
         */
        function setUpgradeContract(
            INameWrapperUpgrade _upgradeAddress
        ) public onlyOwner {
            if (address(upgradeContract) != address(0)) {
                registrar.setApprovalForAll(address(upgradeContract), false);
                ens.setApprovalForAll(address(upgradeContract), false);
            }
            upgradeContract = _upgradeAddress;
            if (address(upgradeContract) != address(0)) {
                registrar.setApprovalForAll(address(upgradeContract), true);
                ens.setApprovalForAll(address(upgradeContract), true);
            }
        }
        /**
         * @notice Checks if msg.sender is the owner or operator of the owner of a name
         * @param node namehash of the name to check
         */
        modifier onlyTokenOwner(bytes32 node) {
            if (!canModifyName(node, msg.sender)) {
                revert Unauthorised(node, msg.sender);
            }
            _;
        }
        /**
         * @notice Checks if owner or operator of the owner
         * @param node namehash of the name to check
         * @param addr which address to check permissions for
         * @return whether or not is owner or operator
         */
        function canModifyName(
            bytes32 node,
            address addr
        ) public view returns (bool) {
            (address owner, uint32 fuses, uint64 expiry) = getData(uint256(node));
            return
                (owner == addr || isApprovedForAll(owner, addr)) &&
                !_isETH2LDInGracePeriod(fuses, expiry);
        }
        /**
         * @notice Checks if owner/operator or approved by owner
         * @param node namehash of the name to check
         * @param addr which address to check permissions for
         * @return whether or not is owner/operator or approved
         */
        function canExtendSubnames(
            bytes32 node,
            address addr
        ) public view returns (bool) {
            (address owner, uint32 fuses, uint64 expiry) = getData(uint256(node));
            return
                (owner == addr ||
                    isApprovedForAll(owner, addr) ||
                    getApproved(uint256(node)) == addr) &&
                !_isETH2LDInGracePeriod(fuses, expiry);
        }
        /**
         * @notice Wraps a .eth domain, creating a new token and sending the original ERC721 token to this contract
         * @dev Can be called by the owner of the name on the .eth registrar or an authorised caller on the registrar
         * @param label Label as a string of the .eth domain to wrap
         * @param wrappedOwner Owner of the name in this contract
         * @param ownerControlledFuses Initial owner-controlled fuses to set
         * @param resolver Resolver contract address
         */
        function wrapETH2LD(
            string calldata label,
            address wrappedOwner,
            uint16 ownerControlledFuses,
            address resolver
        ) public returns (uint64 expiry) {
            uint256 tokenId = uint256(keccak256(bytes(label)));
            address registrant = registrar.ownerOf(tokenId);
            if (
                registrant != msg.sender &&
                !registrar.isApprovedForAll(registrant, msg.sender)
            ) {
                revert Unauthorised(
                    _makeNode(ETH_NODE, bytes32(tokenId)),
                    msg.sender
                );
            }
            // transfer the token from the user to this contract
            registrar.transferFrom(registrant, address(this), tokenId);
            // transfer the ens record back to the new owner (this contract)
            registrar.reclaim(tokenId, address(this));
            expiry = uint64(registrar.nameExpires(tokenId)) + GRACE_PERIOD;
            _wrapETH2LD(
                label,
                wrappedOwner,
                ownerControlledFuses,
                expiry,
                resolver
            );
        }
        /**
         * @dev Registers a new .eth second-level domain and wraps it.
         *      Only callable by authorised controllers.
         * @param label The label to register (Eg, 'foo' for 'foo.eth').
         * @param wrappedOwner The owner of the wrapped name.
         * @param duration The duration, in seconds, to register the name for.
         * @param resolver The resolver address to set on the ENS registry (optional).
         * @param ownerControlledFuses Initial owner-controlled fuses to set
         * @return registrarExpiry The expiry date of the new name on the .eth registrar, in seconds since the Unix epoch.
         */
        function registerAndWrapETH2LD(
            string calldata label,
            address wrappedOwner,
            uint256 duration,
            address resolver,
            uint16 ownerControlledFuses
        ) external onlyController returns (uint256 registrarExpiry) {
            uint256 tokenId = uint256(keccak256(bytes(label)));
            registrarExpiry = registrar.register(tokenId, address(this), duration);
            _wrapETH2LD(
                label,
                wrappedOwner,
                ownerControlledFuses,
                uint64(registrarExpiry) + GRACE_PERIOD,
                resolver
            );
        }
        /**
         * @notice Renews a .eth second-level domain.
         * @dev Only callable by authorised controllers.
         * @param tokenId The hash of the label to register (eg, `keccak256('foo')`, for 'foo.eth').
         * @param duration The number of seconds to renew the name for.
         * @return expires The expiry date of the name on the .eth registrar, in seconds since the Unix epoch.
         */
        function renew(
            uint256 tokenId,
            uint256 duration
        ) external onlyController returns (uint256 expires) {
            bytes32 node = _makeNode(ETH_NODE, bytes32(tokenId));
            uint256 registrarExpiry = registrar.renew(tokenId, duration);
            // Do not set anything in wrapper if name is not wrapped
            try registrar.ownerOf(tokenId) returns (address registrarOwner) {
                if (
                    registrarOwner != address(this) ||
                    ens.owner(node) != address(this)
                ) {
                    return registrarExpiry;
                }
            } catch {
                return registrarExpiry;
            }
            // Set expiry in Wrapper
            uint64 expiry = uint64(registrarExpiry) + GRACE_PERIOD;
            // Use super to allow names expired on the wrapper, but not expired on the registrar to renew()
            (address owner, uint32 fuses, ) = super.getData(uint256(node));
            _setData(node, owner, fuses, expiry);
            return registrarExpiry;
        }
        /**
         * @notice Wraps a non .eth domain, of any kind. Could be a DNSSEC name vitalik.xyz or a subdomain
         * @dev Can be called by the owner in the registry or an authorised caller in the registry
         * @param name The name to wrap, in DNS format
         * @param wrappedOwner Owner of the name in this contract
         * @param resolver Resolver contract
         */
        function wrap(
            bytes calldata name,
            address wrappedOwner,
            address resolver
        ) public {
            (bytes32 labelhash, uint256 offset) = name.readLabel(0);
            bytes32 parentNode = name.namehash(offset);
            bytes32 node = _makeNode(parentNode, labelhash);
            names[node] = name;
            if (parentNode == ETH_NODE) {
                revert IncompatibleParent();
            }
            address owner = ens.owner(node);
            if (owner != msg.sender && !ens.isApprovedForAll(owner, msg.sender)) {
                revert Unauthorised(node, msg.sender);
            }
            if (resolver != address(0)) {
                ens.setResolver(node, resolver);
            }
            ens.setOwner(node, address(this));
            _wrap(node, name, wrappedOwner, 0, 0);
        }
        /**
         * @notice Unwraps a .eth domain. e.g. vitalik.eth
         * @dev Can be called by the owner in the wrapper or an authorised caller in the wrapper
         * @param labelhash Labelhash of the .eth domain
         * @param registrant Sets the owner in the .eth registrar to this address
         * @param controller Sets the owner in the registry to this address
         */
        function unwrapETH2LD(
            bytes32 labelhash,
            address registrant,
            address controller
        ) public onlyTokenOwner(_makeNode(ETH_NODE, labelhash)) {
            if (registrant == address(this)) {
                revert IncorrectTargetOwner(registrant);
            }
            _unwrap(_makeNode(ETH_NODE, labelhash), controller);
            registrar.safeTransferFrom(
                address(this),
                registrant,
                uint256(labelhash)
            );
        }
        /**
         * @notice Unwraps a non .eth domain, of any kind. Could be a DNSSEC name vitalik.xyz or a subdomain
         * @dev Can be called by the owner in the wrapper or an authorised caller in the wrapper
         * @param parentNode Parent namehash of the name e.g. vitalik.xyz would be namehash('xyz')
         * @param labelhash Labelhash of the name, e.g. vitalik.xyz would be keccak256('vitalik')
         * @param controller Sets the owner in the registry to this address
         */
        function unwrap(
            bytes32 parentNode,
            bytes32 labelhash,
            address controller
        ) public onlyTokenOwner(_makeNode(parentNode, labelhash)) {
            if (parentNode == ETH_NODE) {
                revert IncompatibleParent();
            }
            if (controller == address(0x0) || controller == address(this)) {
                revert IncorrectTargetOwner(controller);
            }
            _unwrap(_makeNode(parentNode, labelhash), controller);
        }
        /**
         * @notice Sets fuses of a name
         * @param node Namehash of the name
         * @param ownerControlledFuses Owner-controlled fuses to burn
         * @return Old fuses
         */
        function setFuses(
            bytes32 node,
            uint16 ownerControlledFuses
        )
            public
            onlyTokenOwner(node)
            operationAllowed(node, CANNOT_BURN_FUSES)
            returns (uint32)
        {
            // owner protected by onlyTokenOwner
            (address owner, uint32 oldFuses, uint64 expiry) = getData(
                uint256(node)
            );
            _setFuses(node, owner, ownerControlledFuses | oldFuses, expiry, expiry);
            return oldFuses;
        }
        /**
         * @notice Extends expiry for a name
         * @param parentNode Parent namehash of the name e.g. vitalik.xyz would be namehash('xyz')
         * @param labelhash Labelhash of the name, e.g. vitalik.xyz would be keccak256('vitalik')
         * @param expiry When the name will expire in seconds since the Unix epoch
         * @return New expiry
         */
        function extendExpiry(
            bytes32 parentNode,
            bytes32 labelhash,
            uint64 expiry
        ) public returns (uint64) {
            bytes32 node = _makeNode(parentNode, labelhash);
            if (!_isWrapped(node)) {
                revert NameIsNotWrapped();
            }
            // this flag is used later, when checking fuses
            bool canExtendSubname = canExtendSubnames(parentNode, msg.sender);
            // only allow the owner of the name or owner of the parent name
            if (!canExtendSubname && !canModifyName(node, msg.sender)) {
                revert Unauthorised(node, msg.sender);
            }
            (address owner, uint32 fuses, uint64 oldExpiry) = getData(
                uint256(node)
            );
            // Either CAN_EXTEND_EXPIRY must be set, or the caller must have permission to modify the parent name
            if (!canExtendSubname && fuses & CAN_EXTEND_EXPIRY == 0) {
                revert OperationProhibited(node);
            }
            // Max expiry is set to the expiry of the parent
            (, , uint64 maxExpiry) = getData(uint256(parentNode));
            expiry = _normaliseExpiry(expiry, oldExpiry, maxExpiry);
            _setData(node, owner, fuses, expiry);
            emit ExpiryExtended(node, expiry);
            return expiry;
        }
        /**
         * @notice Upgrades a domain of any kind. Could be a .eth name vitalik.eth, a DNSSEC name vitalik.xyz, or a subdomain
         * @dev Can be called by the owner or an authorised caller
         * @param name The name to upgrade, in DNS format
         * @param extraData Extra data to pass to the upgrade contract
         */
        function upgrade(bytes calldata name, bytes calldata extraData) public {
            bytes32 node = name.namehash(0);
            if (address(upgradeContract) == address(0)) {
                revert CannotUpgrade();
            }
            if (!canModifyName(node, msg.sender)) {
                revert Unauthorised(node, msg.sender);
            }
            (address currentOwner, uint32 fuses, uint64 expiry) = getData(
                uint256(node)
            );
            address approved = getApproved(uint256(node));
            _burn(uint256(node));
            upgradeContract.wrapFromUpgrade(
                name,
                currentOwner,
                fuses,
                expiry,
                approved,
                extraData
            );
        }
        /** 
        /* @notice Sets fuses of a name that you own the parent of
         * @param parentNode Parent namehash of the name e.g. vitalik.xyz would be namehash('xyz')
         * @param labelhash Labelhash of the name, e.g. vitalik.xyz would be keccak256('vitalik')
         * @param fuses Fuses to burn
         * @param expiry When the name will expire in seconds since the Unix epoch
         */
        function setChildFuses(
            bytes32 parentNode,
            bytes32 labelhash,
            uint32 fuses,
            uint64 expiry
        ) public {
            bytes32 node = _makeNode(parentNode, labelhash);
            _checkFusesAreSettable(node, fuses);
            (address owner, uint32 oldFuses, uint64 oldExpiry) = getData(
                uint256(node)
            );
            if (owner == address(0) || ens.owner(node) != address(this)) {
                revert NameIsNotWrapped();
            }
            // max expiry is set to the expiry of the parent
            (, uint32 parentFuses, uint64 maxExpiry) = getData(uint256(parentNode));
            if (parentNode == ROOT_NODE) {
                if (!canModifyName(node, msg.sender)) {
                    revert Unauthorised(node, msg.sender);
                }
            } else {
                if (!canModifyName(parentNode, msg.sender)) {
                    revert Unauthorised(parentNode, msg.sender);
                }
            }
            _checkParentFuses(node, fuses, parentFuses);
            expiry = _normaliseExpiry(expiry, oldExpiry, maxExpiry);
            // if PARENT_CANNOT_CONTROL has been burned and fuses have changed
            if (
                oldFuses & PARENT_CANNOT_CONTROL != 0 &&
                oldFuses | fuses != oldFuses
            ) {
                revert OperationProhibited(node);
            }
            fuses |= oldFuses;
            _setFuses(node, owner, fuses, oldExpiry, expiry);
        }
        /**
         * @notice Sets the subdomain owner in the registry and then wraps the subdomain
         * @param parentNode Parent namehash of the subdomain
         * @param label Label of the subdomain as a string
         * @param owner New owner in the wrapper
         * @param fuses Initial fuses for the wrapped subdomain
         * @param expiry When the name will expire in seconds since the Unix epoch
         * @return node Namehash of the subdomain
         */
        function setSubnodeOwner(
            bytes32 parentNode,
            string calldata label,
            address owner,
            uint32 fuses,
            uint64 expiry
        ) public onlyTokenOwner(parentNode) returns (bytes32 node) {
            bytes32 labelhash = keccak256(bytes(label));
            node = _makeNode(parentNode, labelhash);
            _checkCanCallSetSubnodeOwner(parentNode, node);
            _checkFusesAreSettable(node, fuses);
            bytes memory name = _saveLabel(parentNode, node, label);
            expiry = _checkParentFusesAndExpiry(parentNode, node, fuses, expiry);
            if (!_isWrapped(node)) {
                ens.setSubnodeOwner(parentNode, labelhash, address(this));
                _wrap(node, name, owner, fuses, expiry);
            } else {
                _updateName(parentNode, node, label, owner, fuses, expiry);
            }
        }
        /**
         * @notice Sets the subdomain owner in the registry with records and then wraps the subdomain
         * @param parentNode parent namehash of the subdomain
         * @param label label of the subdomain as a string
         * @param owner new owner in the wrapper
         * @param resolver resolver contract in the registry
         * @param ttl ttl in the registry
         * @param fuses initial fuses for the wrapped subdomain
         * @param expiry When the name will expire in seconds since the Unix epoch
         * @return node Namehash of the subdomain
         */
        function setSubnodeRecord(
            bytes32 parentNode,
            string memory label,
            address owner,
            address resolver,
            uint64 ttl,
            uint32 fuses,
            uint64 expiry
        ) public onlyTokenOwner(parentNode) returns (bytes32 node) {
            bytes32 labelhash = keccak256(bytes(label));
            node = _makeNode(parentNode, labelhash);
            _checkCanCallSetSubnodeOwner(parentNode, node);
            _checkFusesAreSettable(node, fuses);
            _saveLabel(parentNode, node, label);
            expiry = _checkParentFusesAndExpiry(parentNode, node, fuses, expiry);
            if (!_isWrapped(node)) {
                ens.setSubnodeRecord(
                    parentNode,
                    labelhash,
                    address(this),
                    resolver,
                    ttl
                );
                _storeNameAndWrap(parentNode, node, label, owner, fuses, expiry);
            } else {
                ens.setSubnodeRecord(
                    parentNode,
                    labelhash,
                    address(this),
                    resolver,
                    ttl
                );
                _updateName(parentNode, node, label, owner, fuses, expiry);
            }
        }
        /**
         * @notice Sets records for the name in the ENS Registry
         * @param node Namehash of the name to set a record for
         * @param owner New owner in the registry
         * @param resolver Resolver contract
         * @param ttl Time to live in the registry
         */
        function setRecord(
            bytes32 node,
            address owner,
            address resolver,
            uint64 ttl
        )
            public
            onlyTokenOwner(node)
            operationAllowed(
                node,
                CANNOT_TRANSFER | CANNOT_SET_RESOLVER | CANNOT_SET_TTL
            )
        {
            ens.setRecord(node, address(this), resolver, ttl);
            if (owner == address(0)) {
                (, uint32 fuses, ) = getData(uint256(node));
                if (fuses & IS_DOT_ETH == IS_DOT_ETH) {
                    revert IncorrectTargetOwner(owner);
                }
                _unwrap(node, address(0));
            } else {
                address oldOwner = ownerOf(uint256(node));
                _transfer(oldOwner, owner, uint256(node), 1, "");
            }
        }
        /**
         * @notice Sets resolver contract in the registry
         * @param node namehash of the name
         * @param resolver the resolver contract
         */
        function setResolver(
            bytes32 node,
            address resolver
        ) public onlyTokenOwner(node) operationAllowed(node, CANNOT_SET_RESOLVER) {
            ens.setResolver(node, resolver);
        }
        /**
         * @notice Sets TTL in the registry
         * @param node Namehash of the name
         * @param ttl TTL in the registry
         */
        function setTTL(
            bytes32 node,
            uint64 ttl
        ) public onlyTokenOwner(node) operationAllowed(node, CANNOT_SET_TTL) {
            ens.setTTL(node, ttl);
        }
        /**
         * @dev Allows an operation only if none of the specified fuses are burned.
         * @param node The namehash of the name to check fuses on.
         * @param fuseMask A bitmask of fuses that must not be burned.
         */
        modifier operationAllowed(bytes32 node, uint32 fuseMask) {
            (, uint32 fuses, ) = getData(uint256(node));
            if (fuses & fuseMask != 0) {
                revert OperationProhibited(node);
            }
            _;
        }
        /**
         * @notice Check whether a name can call setSubnodeOwner/setSubnodeRecord
         * @dev Checks both CANNOT_CREATE_SUBDOMAIN and PARENT_CANNOT_CONTROL and whether not they have been burnt
         *      and checks whether the owner of the subdomain is 0x0 for creating or already exists for
         *      replacing a subdomain. If either conditions are true, then it is possible to call
         *      setSubnodeOwner
         * @param parentNode Namehash of the parent name to check
         * @param subnode Namehash of the subname to check
         */
        function _checkCanCallSetSubnodeOwner(
            bytes32 parentNode,
            bytes32 subnode
        ) internal view {
            (
                address subnodeOwner,
                uint32 subnodeFuses,
                uint64 subnodeExpiry
            ) = getData(uint256(subnode));
            // check if the registry owner is 0 and expired
            // check if the wrapper owner is 0 and expired
            // If either, then check parent fuses for CANNOT_CREATE_SUBDOMAIN
            bool expired = subnodeExpiry < block.timestamp;
            if (
                expired &&
                // protects a name that has been unwrapped with PCC and doesn't allow the parent to take control by recreating it if unexpired
                (subnodeOwner == address(0) ||
                    // protects a name that has been burnt and doesn't allow the parent to take control by recreating it if unexpired
                    ens.owner(subnode) == address(0))
            ) {
                (, uint32 parentFuses, ) = getData(uint256(parentNode));
                if (parentFuses & CANNOT_CREATE_SUBDOMAIN != 0) {
                    revert OperationProhibited(subnode);
                }
            } else {
                if (subnodeFuses & PARENT_CANNOT_CONTROL != 0) {
                    revert OperationProhibited(subnode);
                }
            }
        }
        /**
         * @notice Checks all Fuses in the mask are burned for the node
         * @param node Namehash of the name
         * @param fuseMask The fuses you want to check
         * @return Boolean of whether or not all the selected fuses are burned
         */
        function allFusesBurned(
            bytes32 node,
            uint32 fuseMask
        ) public view returns (bool) {
            (, uint32 fuses, ) = getData(uint256(node));
            return fuses & fuseMask == fuseMask;
        }
        /**
         * @notice Checks if a name is wrapped
         * @param node Namehash of the name
         * @return Boolean of whether or not the name is wrapped
         */
        function isWrapped(bytes32 node) public view returns (bool) {
            bytes memory name = names[node];
            if (name.length == 0) {
                return false;
            }
            (bytes32 labelhash, uint256 offset) = name.readLabel(0);
            bytes32 parentNode = name.namehash(offset);
            return isWrapped(parentNode, labelhash);
        }
        /**
         * @notice Checks if a name is wrapped in a more gas efficient way
         * @param parentNode Namehash of the name
         * @param labelhash Namehash of the name
         * @return Boolean of whether or not the name is wrapped
         */
        function isWrapped(
            bytes32 parentNode,
            bytes32 labelhash
        ) public view returns (bool) {
            bytes32 node = _makeNode(parentNode, labelhash);
            bool wrapped = _isWrapped(node);
            if (parentNode != ETH_NODE) {
                return wrapped;
            }
            try registrar.ownerOf(uint256(labelhash)) returns (address owner) {
                return owner == address(this);
            } catch {
                return false;
            }
        }
        function onERC721Received(
            address to,
            address,
            uint256 tokenId,
            bytes calldata data
        ) public returns (bytes4) {
            //check if it's the eth registrar ERC721
            if (msg.sender != address(registrar)) {
                revert IncorrectTokenType();
            }
            (
                string memory label,
                address owner,
                uint16 ownerControlledFuses,
                address resolver
            ) = abi.decode(data, (string, address, uint16, address));
            bytes32 labelhash = bytes32(tokenId);
            bytes32 labelhashFromData = keccak256(bytes(label));
            if (labelhashFromData != labelhash) {
                revert LabelMismatch(labelhashFromData, labelhash);
            }
            // transfer the ens record back to the new owner (this contract)
            registrar.reclaim(uint256(labelhash), address(this));
            uint64 expiry = uint64(registrar.nameExpires(tokenId)) + GRACE_PERIOD;
            _wrapETH2LD(label, owner, ownerControlledFuses, expiry, resolver);
            return IERC721Receiver(to).onERC721Received.selector;
        }
        /***** Internal functions */
        function _beforeTransfer(
            uint256 id,
            uint32 fuses,
            uint64 expiry
        ) internal override {
            // For this check, treat .eth 2LDs as expiring at the start of the grace period.
            if (fuses & IS_DOT_ETH == IS_DOT_ETH) {
                expiry -= GRACE_PERIOD;
            }
            if (expiry < block.timestamp) {
                // Transferable if the name was not emancipated
                if (fuses & PARENT_CANNOT_CONTROL != 0) {
                    revert("ERC1155: insufficient balance for transfer");
                }
            } else {
                // Transferable if CANNOT_TRANSFER is unburned
                if (fuses & CANNOT_TRANSFER != 0) {
                    revert OperationProhibited(bytes32(id));
                }
            }
            // delete token approval if CANNOT_APPROVE has not been burnt
            if (fuses & CANNOT_APPROVE == 0) {
                delete _tokenApprovals[id];
            }
        }
        function _clearOwnerAndFuses(
            address owner,
            uint32 fuses,
            uint64 expiry
        ) internal view override returns (address, uint32) {
            if (expiry < block.timestamp) {
                if (fuses & PARENT_CANNOT_CONTROL == PARENT_CANNOT_CONTROL) {
                    owner = address(0);
                }
                fuses = 0;
            }
            return (owner, fuses);
        }
        function _makeNode(
            bytes32 node,
            bytes32 labelhash
        ) private pure returns (bytes32) {
            return keccak256(abi.encodePacked(node, labelhash));
        }
        function _addLabel(
            string memory label,
            bytes memory name
        ) internal pure returns (bytes memory ret) {
            if (bytes(label).length < 1) {
                revert LabelTooShort();
            }
            if (bytes(label).length > 255) {
                revert LabelTooLong(label);
            }
            return abi.encodePacked(uint8(bytes(label).length), label, name);
        }
        function _mint(
            bytes32 node,
            address owner,
            uint32 fuses,
            uint64 expiry
        ) internal override {
            _canFusesBeBurned(node, fuses);
            (address oldOwner, , ) = super.getData(uint256(node));
            if (oldOwner != address(0)) {
                // burn and unwrap old token of old owner
                _burn(uint256(node));
                emit NameUnwrapped(node, address(0));
            }
            super._mint(node, owner, fuses, expiry);
        }
        function _wrap(
            bytes32 node,
            bytes memory name,
            address wrappedOwner,
            uint32 fuses,
            uint64 expiry
        ) internal {
            _mint(node, wrappedOwner, fuses, expiry);
            emit NameWrapped(node, name, wrappedOwner, fuses, expiry);
        }
        function _storeNameAndWrap(
            bytes32 parentNode,
            bytes32 node,
            string memory label,
            address owner,
            uint32 fuses,
            uint64 expiry
        ) internal {
            bytes memory name = _addLabel(label, names[parentNode]);
            _wrap(node, name, owner, fuses, expiry);
        }
        function _saveLabel(
            bytes32 parentNode,
            bytes32 node,
            string memory label
        ) internal returns (bytes memory) {
            bytes memory name = _addLabel(label, names[parentNode]);
            names[node] = name;
            return name;
        }
        function _updateName(
            bytes32 parentNode,
            bytes32 node,
            string memory label,
            address owner,
            uint32 fuses,
            uint64 expiry
        ) internal {
            (address oldOwner, uint32 oldFuses, uint64 oldExpiry) = getData(
                uint256(node)
            );
            bytes memory name = _addLabel(label, names[parentNode]);
            if (names[node].length == 0) {
                names[node] = name;
            }
            _setFuses(node, oldOwner, oldFuses | fuses, oldExpiry, expiry);
            if (owner == address(0)) {
                _unwrap(node, address(0));
            } else {
                _transfer(oldOwner, owner, uint256(node), 1, "");
            }
        }
        // wrapper function for stack limit
        function _checkParentFusesAndExpiry(
            bytes32 parentNode,
            bytes32 node,
            uint32 fuses,
            uint64 expiry
        ) internal view returns (uint64) {
            (, , uint64 oldExpiry) = getData(uint256(node));
            (, uint32 parentFuses, uint64 maxExpiry) = getData(uint256(parentNode));
            _checkParentFuses(node, fuses, parentFuses);
            return _normaliseExpiry(expiry, oldExpiry, maxExpiry);
        }
        function _checkParentFuses(
            bytes32 node,
            uint32 fuses,
            uint32 parentFuses
        ) internal pure {
            bool isBurningParentControlledFuses = fuses & PARENT_CONTROLLED_FUSES !=
                0;
            bool parentHasNotBurnedCU = parentFuses & CANNOT_UNWRAP == 0;
            if (isBurningParentControlledFuses && parentHasNotBurnedCU) {
                revert OperationProhibited(node);
            }
        }
        function _normaliseExpiry(
            uint64 expiry,
            uint64 oldExpiry,
            uint64 maxExpiry
        ) private pure returns (uint64) {
            // Expiry cannot be more than maximum allowed
            // .eth names will check registrar, non .eth check parent
            if (expiry > maxExpiry) {
                expiry = maxExpiry;
            }
            // Expiry cannot be less than old expiry
            if (expiry < oldExpiry) {
                expiry = oldExpiry;
            }
            return expiry;
        }
        function _wrapETH2LD(
            string memory label,
            address wrappedOwner,
            uint32 fuses,
            uint64 expiry,
            address resolver
        ) private {
            bytes32 labelhash = keccak256(bytes(label));
            bytes32 node = _makeNode(ETH_NODE, labelhash);
            // hardcode dns-encoded eth string for gas savings
            bytes memory name = _addLabel(label, "\\x03eth\\x00");
            names[node] = name;
            _wrap(
                node,
                name,
                wrappedOwner,
                fuses | PARENT_CANNOT_CONTROL | IS_DOT_ETH,
                expiry
            );
            if (resolver != address(0)) {
                ens.setResolver(node, resolver);
            }
        }
        function _unwrap(bytes32 node, address owner) private {
            if (allFusesBurned(node, CANNOT_UNWRAP)) {
                revert OperationProhibited(node);
            }
            // Burn token and fuse data
            _burn(uint256(node));
            ens.setOwner(node, owner);
            emit NameUnwrapped(node, owner);
        }
        function _setFuses(
            bytes32 node,
            address owner,
            uint32 fuses,
            uint64 oldExpiry,
            uint64 expiry
        ) internal {
            _setData(node, owner, fuses, expiry);
            emit FusesSet(node, fuses);
            if (expiry > oldExpiry) {
                emit ExpiryExtended(node, expiry);
            }
        }
        function _setData(
            bytes32 node,
            address owner,
            uint32 fuses,
            uint64 expiry
        ) internal {
            _canFusesBeBurned(node, fuses);
            super._setData(uint256(node), owner, fuses, expiry);
        }
        function _canFusesBeBurned(bytes32 node, uint32 fuses) internal pure {
            // If a non-parent controlled fuse is being burned, check PCC and CU are burnt
            if (
                fuses & ~PARENT_CONTROLLED_FUSES != 0 &&
                fuses & (PARENT_CANNOT_CONTROL | CANNOT_UNWRAP) !=
                (PARENT_CANNOT_CONTROL | CANNOT_UNWRAP)
            ) {
                revert OperationProhibited(node);
            }
        }
        function _checkFusesAreSettable(bytes32 node, uint32 fuses) internal pure {
            if (fuses | USER_SETTABLE_FUSES != USER_SETTABLE_FUSES) {
                // Cannot directly burn other non-user settable fuses
                revert OperationProhibited(node);
            }
        }
        function _isWrapped(bytes32 node) internal view returns (bool) {
            return
                ownerOf(uint256(node)) != address(0) &&
                ens.owner(node) == address(this);
        }
        function _isETH2LDInGracePeriod(
            uint32 fuses,
            uint64 expiry
        ) internal view returns (bool) {
            return
                fuses & IS_DOT_ETH == IS_DOT_ETH &&
                expiry - GRACE_PERIOD < block.timestamp;
        }
    }