{"sources":{"src/HahaRegistrar.sol":{"content":"// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.28;\r\n\r\nimport {ERC721} from \"@openzeppelin/contracts/token/ERC721/ERC721.sol\";\r\nimport {IERC721} from \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\r\nimport {IERC2981} from \"@openzeppelin/contracts/interfaces/IERC2981.sol\";\r\nimport {IERC165} from \"@openzeppelin/contracts/utils/introspection/IERC165.sol\";\r\nimport {ReentrancyGuard} from \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\r\n\r\nimport {HahaConstants} from \"./libraries/HahaConstants.sol\";\r\nimport {HahaNamehash} from \"./libraries/HahaNamehash.sol\";\r\nimport {HahaAiIdentity} from \"./libraries/HahaAiIdentity.sol\";\r\nimport {IBinanceAiRegistry} from \"./interfaces/IBinanceAiRegistry.sol\";\r\nimport {IHahaRegistry} from \"./interfaces/IHahaRegistry.sol\";\r\nimport {IHahaResolver} from \"./interfaces/IHahaResolver.sol\";\r\nimport {\r\n    IHahaMetadata,\r\n    IHahaNamePolicy,\r\n    IHahaPoints,\r\n    IHahaAgentIdentity\r\n} from \"./interfaces/IHahaProtocol.sol\";\r\n\r\ncontract HahaRegistrar is ERC721, IERC2981, ReentrancyGuard {\r\n\r\n    error InvalidTld(uint8 tld);\r\n    error InvalidCharset();\r\n    error LabelTooLong(uint256 length, uint256 maxLength);\r\n    error LabelTooShort(uint256 length, uint256 minLength);\r\n    error Blacklisted();\r\n    error ReservedName();\r\n    error NotReserved();\r\n    error NameTaken();\r\n    error AiRequired();\r\n    error CooldownActive(uint256 readyAt);\r\n    error NotAdmin();\r\n    error ZeroAddress();\r\n\r\n\r\n    event NameMinted(\r\n        uint256 indexed tokenId,\r\n        address indexed owner,\r\n        uint8 tld,\r\n        bytes32 indexed aiId,\r\n        string label,\r\n        bool reservedMint\r\n    );\r\n\r\n\r\n    struct Name {\r\n        string label;\r\n        uint8 tld;\r\n    }\r\n\r\n    mapping(uint256 tokenId => Name) private _names;\r\n\r\n    mapping(bytes32 aiId => uint256) public lastMintAt;\r\n\r\n\r\n    address public immutable registry;\r\n\r\n    address public immutable resolver;\r\n\r\n    address public immutable metadata;\r\n\r\n    address public immutable points;\r\n\r\n    address public immutable identity;\r\n\r\n    address public immutable policy;\r\n\r\n    address public immutable aiRegistry;\r\n\r\n    address public immutable admin;\r\n\r\n    address public immutable feeReceiver;\r\n\r\n\r\n    modifier onlyAdmin() {\r\n        if (msg.sender != admin) revert NotAdmin();\r\n        _;\r\n    }\r\n\r\n\r\n    constructor(bytes memory cfg) ERC721(\"haha id\", \"HAHAID\") {\r\n        (\r\n            address registry_,\r\n            address resolver_,\r\n            address metadata_,\r\n            address points_,\r\n            address identity_,\r\n            address policy_,\r\n            address aiRegistry_,\r\n            address admin_,\r\n            address feeReceiver_\r\n        ) = abi.decode(cfg, (address, address, address, address, address, address, address, address, address));\r\n\r\n        if (\r\n            registry_ == address(0) || resolver_ == address(0) || metadata_ == address(0)\r\n                || points_ == address(0) || identity_ == address(0) || policy_ == address(0)\r\n                || aiRegistry_ == address(0) || admin_ == address(0) || feeReceiver_ == address(0)\r\n        ) revert ZeroAddress();\r\n\r\n        registry = registry_;\r\n        resolver = resolver_;\r\n        metadata = metadata_;\r\n        points = points_;\r\n        identity = identity_;\r\n        policy = policy_;\r\n        aiRegistry = aiRegistry_;\r\n        admin = admin_;\r\n        feeReceiver = feeReceiver_;\r\n    }\r\n\r\n\r\n    function register(string calldata label, uint8 tld) external nonReentrant {\r\n        if (tld > HahaConstants.TLD_MEME) revert InvalidTld(tld);\r\n        _requireValidLabel(label, HahaConstants.MIN_PUBLIC_LENGTH);\r\n\r\n        if (IHahaNamePolicy(policy).isBlacklisted(label)) revert Blacklisted();\r\n        if (IHahaNamePolicy(policy).isReserved(label)) revert ReservedName();\r\n\r\n        bytes32 node = HahaNamehash.namehash(HahaNamehash.tldNode(tld), HahaNamehash.labelhash(label));\r\n        if (_exists(node)) revert NameTaken();\r\n\r\n        HahaAiIdentity.Result memory ai = HahaAiIdentity.aiIdentityOf(IBinanceAiRegistry(aiRegistry), msg.sender);\r\n        if (!ai.ok) revert AiRequired();\r\n\r\n        uint256 last = lastMintAt[ai.aiId];\r\n        if (last != 0 && block.timestamp < last + HahaConstants.COOLDOWN) {\r\n            revert CooldownActive(last + HahaConstants.COOLDOWN);\r\n        }\r\n        lastMintAt[ai.aiId] = block.timestamp;\r\n\r\n        _mintAndRecord(label, tld, node, msg.sender, ai.aiId, false);\r\n\r\n        IHahaPoints(points).creditMintReward(msg.sender, ai.aiId);\r\n    }\r\n\r\n    function adminMint(string calldata label, uint8 tld, address to) external onlyAdmin nonReentrant {\r\n        if (tld > HahaConstants.TLD_MEME) revert InvalidTld(tld);\r\n        if (to == address(0)) revert ZeroAddress();\r\n        _requireValidLabel(label, 1);\r\n\r\n        if (IHahaNamePolicy(policy).isBlacklisted(label)) revert Blacklisted();\r\n\r\n        uint256 len = bytes(label).length;\r\n        if (len >= HahaConstants.MIN_PUBLIC_LENGTH) {\r\n            if (!IHahaNamePolicy(policy).isReserved(label)) revert NotReserved();\r\n        }\r\n\r\n        bytes32 node = HahaNamehash.namehash(HahaNamehash.tldNode(tld), HahaNamehash.labelhash(label));\r\n        if (_exists(node)) revert NameTaken();\r\n\r\n        _mintAndRecord(label, tld, node, to, bytes32(0), true);\r\n    }\r\n\r\n\r\n    function _update(address to, uint256 tokenId, address auth) internal override returns (address) {\r\n        address from = _ownerOf(tokenId);\r\n        address previous = super._update(to, tokenId, auth);\r\n\r\n        if (from != address(0)) {\r\n            if (to == address(0)) {\r\n                revert ERC721InvalidReceiver(address(0));\r\n            }\r\n            bytes32 node = bytes32(tokenId);\r\n            IHahaRegistry(registry).syncOwner(node, to);\r\n            IHahaResolver(resolver).clearRecords(node);\r\n            IHahaAgentIdentity(identity).deactivate(tokenId);\r\n        }\r\n\r\n        return previous;\r\n    }\r\n\r\n\r\n    function nameParts(uint256 tokenId) external view returns (string memory label, uint8 tld) {\r\n        _requireOwned(tokenId);\r\n        Name storage n = _names[tokenId];\r\n        return (n.label, n.tld);\r\n    }\r\n\r\n    function isMinted(bytes32 node) external view returns (bool) {\r\n        return _exists(node);\r\n    }\r\n\r\n    function nodeOf(string calldata label, uint8 tld) external pure returns (bytes32) {\r\n        if (tld > HahaConstants.TLD_MEME) revert InvalidTld(tld);\r\n        return HahaNamehash.namehash(HahaNamehash.tldNode(tld), HahaNamehash.labelhash(label));\r\n    }\r\n\r\n    function available(string calldata label, uint8 tld) external view returns (bool) {\r\n        if (tld > HahaConstants.TLD_MEME) return false;\r\n        if (!HahaNamehash.isValidLabel(label)) return false;\r\n        if (!HahaNamehash.isLengthInRange(label, 1, HahaConstants.MAX_LABEL_LENGTH)) return false;\r\n        bytes32 node = HahaNamehash.namehash(HahaNamehash.tldNode(tld), HahaNamehash.labelhash(label));\r\n        return !_exists(node);\r\n    }\r\n\r\n    function nextMintAt(bytes32 aiId) external view returns (uint256) {\r\n        uint256 last = lastMintAt[aiId];\r\n        if (last == 0) return 0;\r\n        return last + HahaConstants.COOLDOWN;\r\n    }\r\n\r\n\r\n    function royaltyInfo(uint256, uint256 salePrice) external view returns (address, uint256) {\r\n        return (feeReceiver, (salePrice * HahaConstants.FEE_BPS) / HahaConstants.BPS_DENOMINATOR);\r\n    }\r\n\r\n    function supportsInterface(bytes4 interfaceId) public view override(ERC721, IERC165) returns (bool) {\r\n        return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);\r\n    }\r\n\r\n\r\n    function _requireValidLabel(string calldata label, uint256 minLen) private pure {\r\n        if (!HahaNamehash.isValidLabel(label)) revert InvalidCharset();\r\n        uint256 len = bytes(label).length;\r\n        if (len > HahaConstants.MAX_LABEL_LENGTH) {\r\n            revert LabelTooLong(len, HahaConstants.MAX_LABEL_LENGTH);\r\n        }\r\n        if (len < minLen) revert LabelTooShort(len, minLen);\r\n    }\r\n\r\n    function _mintAndRecord(\r\n        string calldata label,\r\n        uint8 tld,\r\n        bytes32 node,\r\n        address receiver,\r\n        bytes32 aiId,\r\n        bool reservedMint\r\n    ) private {\r\n        uint256 tokenId = uint256(node);\r\n\r\n        _mint(receiver, tokenId);\r\n        _names[tokenId] = Name({label: label, tld: tld});\r\n\r\n        IHahaRegistry(registry).createName(\r\n            HahaNamehash.tldNode(tld), HahaNamehash.labelhash(label), receiver\r\n        );\r\n\r\n        emit NameMinted(tokenId, receiver, tld, aiId, label, reservedMint);\r\n    }\r\n\r\n    function _exists(bytes32 node) private view returns (bool) {\r\n        return _ownerOf(uint256(node)) != address(0);\r\n    }\r\n}\r\n"},"@openzeppelin/contracts/token/ERC721/ERC721.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/ERC721.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\nimport {IERC721} from \"./IERC721.sol\";\r\nimport {IERC721Metadata} from \"./extensions/IERC721Metadata.sol\";\r\nimport {ERC721Utils} from \"./utils/ERC721Utils.sol\";\r\nimport {Context} from \"../../utils/Context.sol\";\r\nimport {Strings} from \"../../utils/Strings.sol\";\r\nimport {IERC165, ERC165} from \"../../utils/introspection/ERC165.sol\";\r\nimport {IERC721Errors} from \"../../interfaces/draft-IERC6093.sol\";\r\n\r\n/**\r\n * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC-721] Non-Fungible Token Standard, including\r\n * the Metadata extension, but not including the Enumerable extension, which is available separately as\r\n * {ERC721Enumerable}.\r\n */\r\nabstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {\r\n    using Strings for uint256;\r\n\r\n    // Token name\r\n    string private _name;\r\n\r\n    // Token symbol\r\n    string private _symbol;\r\n\r\n    mapping(uint256 tokenId => address) private _owners;\r\n\r\n    mapping(address owner => uint256) private _balances;\r\n\r\n    mapping(uint256 tokenId => address) private _tokenApprovals;\r\n\r\n    mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;\r\n\r\n    /**\r\n     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.\r\n     */\r\n    constructor(string memory name_, string memory symbol_) {\r\n        _name = name_;\r\n        _symbol = symbol_;\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC165-supportsInterface}.\r\n     */\r\n    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\r\n        return\r\n            interfaceId == type(IERC721).interfaceId ||\r\n            interfaceId == type(IERC721Metadata).interfaceId ||\r\n            super.supportsInterface(interfaceId);\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721-balanceOf}.\r\n     */\r\n    function balanceOf(address owner) public view virtual returns (uint256) {\r\n        if (owner == address(0)) {\r\n            revert ERC721InvalidOwner(address(0));\r\n        }\r\n        return _balances[owner];\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721-ownerOf}.\r\n     */\r\n    function ownerOf(uint256 tokenId) public view virtual returns (address) {\r\n        return _requireOwned(tokenId);\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721Metadata-name}.\r\n     */\r\n    function name() public view virtual returns (string memory) {\r\n        return _name;\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721Metadata-symbol}.\r\n     */\r\n    function symbol() public view virtual returns (string memory) {\r\n        return _symbol;\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721Metadata-tokenURI}.\r\n     */\r\n    function tokenURI(uint256 tokenId) public view virtual returns (string memory) {\r\n        _requireOwned(tokenId);\r\n\r\n        string memory baseURI = _baseURI();\r\n        return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : \"\";\r\n    }\r\n\r\n    /**\r\n     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each\r\n     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty\r\n     * by default, can be overridden in child contracts.\r\n     */\r\n    function _baseURI() internal view virtual returns (string memory) {\r\n        return \"\";\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721-approve}.\r\n     */\r\n    function approve(address to, uint256 tokenId) public virtual {\r\n        _approve(to, tokenId, _msgSender());\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721-getApproved}.\r\n     */\r\n    function getApproved(uint256 tokenId) public view virtual returns (address) {\r\n        _requireOwned(tokenId);\r\n\r\n        return _getApproved(tokenId);\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721-setApprovalForAll}.\r\n     */\r\n    function setApprovalForAll(address operator, bool approved) public virtual {\r\n        _setApprovalForAll(_msgSender(), operator, approved);\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721-isApprovedForAll}.\r\n     */\r\n    function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {\r\n        return _operatorApprovals[owner][operator];\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721-transferFrom}.\r\n     */\r\n    function transferFrom(address from, address to, uint256 tokenId) public virtual {\r\n        if (to == address(0)) {\r\n            revert ERC721InvalidReceiver(address(0));\r\n        }\r\n        // Setting an \"auth\" arguments enables the `_isAuthorized` check which verifies that the token exists\r\n        // (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.\r\n        address previousOwner = _update(to, tokenId, _msgSender());\r\n        if (previousOwner != from) {\r\n            revert ERC721IncorrectOwner(from, tokenId, previousOwner);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721-safeTransferFrom}.\r\n     */\r\n    function safeTransferFrom(address from, address to, uint256 tokenId) public {\r\n        safeTransferFrom(from, to, tokenId, \"\");\r\n    }\r\n\r\n    /**\r\n     * @dev See {IERC721-safeTransferFrom}.\r\n     */\r\n    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {\r\n        transferFrom(from, to, tokenId);\r\n        ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist\r\n     *\r\n     * IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the\r\n     * core ERC-721 logic MUST be matched with the use of {_increaseBalance} to keep balances\r\n     * consistent with ownership. The invariant to preserve is that for any address `a` the value returned by\r\n     * `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.\r\n     */\r\n    function _ownerOf(uint256 tokenId) internal view virtual returns (address) {\r\n        return _owners[tokenId];\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.\r\n     */\r\n    function _getApproved(uint256 tokenId) internal view virtual returns (address) {\r\n        return _tokenApprovals[tokenId];\r\n    }\r\n\r\n    /**\r\n     * @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in\r\n     * particular (ignoring whether it is owned by `owner`).\r\n     *\r\n     * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this\r\n     * assumption.\r\n     */\r\n    function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {\r\n        return\r\n            spender != address(0) &&\r\n            (owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);\r\n    }\r\n\r\n    /**\r\n     * @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.\r\n     * Reverts if:\r\n     * - `spender` does not have approval from `owner` for `tokenId`.\r\n     * - `spender` does not have approval to manage all of `owner`'s assets.\r\n     *\r\n     * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this\r\n     * assumption.\r\n     */\r\n    function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {\r\n        if (!_isAuthorized(owner, spender, tokenId)) {\r\n            if (owner == address(0)) {\r\n                revert ERC721NonexistentToken(tokenId);\r\n            } else {\r\n                revert ERC721InsufficientApproval(spender, tokenId);\r\n            }\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Unsafe write access to the balances, used by extensions that \"mint\" tokens using an {ownerOf} override.\r\n     *\r\n     * NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that\r\n     * a uint256 would ever overflow from increments when these increments are bounded to uint128 values.\r\n     *\r\n     * WARNING: Increasing an account's balance using this function tends to be paired with an override of the\r\n     * {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership\r\n     * remain consistent with one another.\r\n     */\r\n    function _increaseBalance(address account, uint128 value) internal virtual {\r\n        unchecked {\r\n            _balances[account] += value;\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner\r\n     * (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.\r\n     *\r\n     * The `auth` argument is optional. If the value passed is non 0, then this function will check that\r\n     * `auth` is either the owner of the token, or approved to operate on the token (by the owner).\r\n     *\r\n     * Emits a {Transfer} event.\r\n     *\r\n     * NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.\r\n     */\r\n    function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {\r\n        address from = _ownerOf(tokenId);\r\n\r\n        // Perform (optional) operator check\r\n        if (auth != address(0)) {\r\n            _checkAuthorized(from, auth, tokenId);\r\n        }\r\n\r\n        // Execute the update\r\n        if (from != address(0)) {\r\n            // Clear approval. No need to re-authorize or emit the Approval event\r\n            _approve(address(0), tokenId, address(0), false);\r\n\r\n            unchecked {\r\n                _balances[from] -= 1;\r\n            }\r\n        }\r\n\r\n        if (to != address(0)) {\r\n            unchecked {\r\n                _balances[to] += 1;\r\n            }\r\n        }\r\n\r\n        _owners[tokenId] = to;\r\n\r\n        emit Transfer(from, to, tokenId);\r\n\r\n        return from;\r\n    }\r\n\r\n    /**\r\n     * @dev Mints `tokenId` and transfers it to `to`.\r\n     *\r\n     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `tokenId` must not exist.\r\n     * - `to` cannot be the zero address.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function _mint(address to, uint256 tokenId) internal {\r\n        if (to == address(0)) {\r\n            revert ERC721InvalidReceiver(address(0));\r\n        }\r\n        address previousOwner = _update(to, tokenId, address(0));\r\n        if (previousOwner != address(0)) {\r\n            revert ERC721InvalidSender(address(0));\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `tokenId` must not exist.\r\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function _safeMint(address to, uint256 tokenId) internal {\r\n        _safeMint(to, tokenId, \"\");\r\n    }\r\n\r\n    /**\r\n     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is\r\n     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.\r\n     */\r\n    function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {\r\n        _mint(to, tokenId);\r\n        ERC721Utils.checkOnERC721Received(_msgSender(), address(0), to, tokenId, data);\r\n    }\r\n\r\n    /**\r\n     * @dev Destroys `tokenId`.\r\n     * The approval is cleared when the token is burned.\r\n     * This is an internal function that does not check if the sender is authorized to operate on the token.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `tokenId` must exist.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function _burn(uint256 tokenId) internal {\r\n        address previousOwner = _update(address(0), tokenId, address(0));\r\n        if (previousOwner == address(0)) {\r\n            revert ERC721NonexistentToken(tokenId);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Transfers `tokenId` from `from` to `to`.\r\n     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `to` cannot be the zero address.\r\n     * - `tokenId` token must be owned by `from`.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function _transfer(address from, address to, uint256 tokenId) internal {\r\n        if (to == address(0)) {\r\n            revert ERC721InvalidReceiver(address(0));\r\n        }\r\n        address previousOwner = _update(to, tokenId, address(0));\r\n        if (previousOwner == address(0)) {\r\n            revert ERC721NonexistentToken(tokenId);\r\n        } else if (previousOwner != from) {\r\n            revert ERC721IncorrectOwner(from, tokenId, previousOwner);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients\r\n     * are aware of the ERC-721 standard to prevent tokens from being forever locked.\r\n     *\r\n     * `data` is additional data, it has no specified format and it is sent in call to `to`.\r\n     *\r\n     * This internal function is like {safeTransferFrom} in the sense that it invokes\r\n     * {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.\r\n     * implement alternative mechanisms to perform token transfer, such as signature-based.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `tokenId` token must exist and be owned by `from`.\r\n     * - `to` cannot be the zero address.\r\n     * - `from` cannot be the zero address.\r\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function _safeTransfer(address from, address to, uint256 tokenId) internal {\r\n        _safeTransfer(from, to, tokenId, \"\");\r\n    }\r\n\r\n    /**\r\n     * @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is\r\n     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.\r\n     */\r\n    function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {\r\n        _transfer(from, to, tokenId);\r\n        ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data);\r\n    }\r\n\r\n    /**\r\n     * @dev Approve `to` to operate on `tokenId`\r\n     *\r\n     * The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is\r\n     * either the owner of the token, or approved to operate on all tokens held by this owner.\r\n     *\r\n     * Emits an {Approval} event.\r\n     *\r\n     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\r\n     */\r\n    function _approve(address to, uint256 tokenId, address auth) internal {\r\n        _approve(to, tokenId, auth, true);\r\n    }\r\n\r\n    /**\r\n     * @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not\r\n     * emitted in the context of transfers.\r\n     */\r\n    function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {\r\n        // Avoid reading the owner unless necessary\r\n        if (emitEvent || auth != address(0)) {\r\n            address owner = _requireOwned(tokenId);\r\n\r\n            // We do not use _isAuthorized because single-token approvals should not be able to call approve\r\n            if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {\r\n                revert ERC721InvalidApprover(auth);\r\n            }\r\n\r\n            if (emitEvent) {\r\n                emit Approval(owner, to, tokenId);\r\n            }\r\n        }\r\n\r\n        _tokenApprovals[tokenId] = to;\r\n    }\r\n\r\n    /**\r\n     * @dev Approve `operator` to operate on all of `owner` tokens\r\n     *\r\n     * Requirements:\r\n     * - operator can't be the address zero.\r\n     *\r\n     * Emits an {ApprovalForAll} event.\r\n     */\r\n    function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {\r\n        if (operator == address(0)) {\r\n            revert ERC721InvalidOperator(operator);\r\n        }\r\n        _operatorApprovals[owner][operator] = approved;\r\n        emit ApprovalForAll(owner, operator, approved);\r\n    }\r\n\r\n    /**\r\n     * @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).\r\n     * Returns the owner.\r\n     *\r\n     * Overrides to ownership logic should be done to {_ownerOf}.\r\n     */\r\n    function _requireOwned(uint256 tokenId) internal view returns (address) {\r\n        address owner = _ownerOf(tokenId);\r\n        if (owner == address(0)) {\r\n            revert ERC721NonexistentToken(tokenId);\r\n        }\r\n        return owner;\r\n    }\r\n}\r\n"},"@openzeppelin/contracts/token/ERC721/IERC721.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\nimport {IERC165} from \"../../utils/introspection/IERC165.sol\";\r\n\r\n/**\r\n * @dev Required interface of an ERC-721 compliant contract.\r\n */\r\ninterface IERC721 is IERC165 {\r\n    /**\r\n     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\r\n     */\r\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\r\n\r\n    /**\r\n     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\r\n     */\r\n    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\r\n\r\n    /**\r\n     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\r\n     */\r\n    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\r\n\r\n    /**\r\n     * @dev Returns the number of tokens in ``owner``'s account.\r\n     */\r\n    function balanceOf(address owner) external view returns (uint256 balance);\r\n\r\n    /**\r\n     * @dev Returns the owner of the `tokenId` token.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `tokenId` must exist.\r\n     */\r\n    function ownerOf(uint256 tokenId) external view returns (address owner);\r\n\r\n    /**\r\n     * @dev Safely transfers `tokenId` token from `from` to `to`.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `from` cannot be the zero address.\r\n     * - `to` cannot be the zero address.\r\n     * - `tokenId` token must exist and be owned by `from`.\r\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\r\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\r\n     *   a safe transfer.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\r\n\r\n    /**\r\n     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\r\n     * are aware of the ERC-721 protocol to prevent tokens from being forever locked.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `from` cannot be the zero address.\r\n     * - `to` cannot be the zero address.\r\n     * - `tokenId` token must exist and be owned by `from`.\r\n     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or\r\n     *   {setApprovalForAll}.\r\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\r\n     *   a safe transfer.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function safeTransferFrom(address from, address to, uint256 tokenId) external;\r\n\r\n    /**\r\n     * @dev Transfers `tokenId` token from `from` to `to`.\r\n     *\r\n     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721\r\n     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must\r\n     * understand this adds an external call which potentially creates a reentrancy vulnerability.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `from` cannot be the zero address.\r\n     * - `to` cannot be the zero address.\r\n     * - `tokenId` token must be owned by `from`.\r\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\r\n     *\r\n     * Emits a {Transfer} event.\r\n     */\r\n    function transferFrom(address from, address to, uint256 tokenId) external;\r\n\r\n    /**\r\n     * @dev Gives permission to `to` to transfer `tokenId` token to another account.\r\n     * The approval is cleared when the token is transferred.\r\n     *\r\n     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - The caller must own the token or be an approved operator.\r\n     * - `tokenId` must exist.\r\n     *\r\n     * Emits an {Approval} event.\r\n     */\r\n    function approve(address to, uint256 tokenId) external;\r\n\r\n    /**\r\n     * @dev Approve or remove `operator` as an operator for the caller.\r\n     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - The `operator` cannot be the address zero.\r\n     *\r\n     * Emits an {ApprovalForAll} event.\r\n     */\r\n    function setApprovalForAll(address operator, bool approved) external;\r\n\r\n    /**\r\n     * @dev Returns the account approved for `tokenId` token.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - `tokenId` must exist.\r\n     */\r\n    function getApproved(uint256 tokenId) external view returns (address operator);\r\n\r\n    /**\r\n     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\r\n     *\r\n     * See {setApprovalForAll}\r\n     */\r\n    function isApprovedForAll(address owner, address operator) external view returns (bool);\r\n}\r\n"},"@openzeppelin/contracts/utils/introspection/IERC165.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\n/**\r\n * @dev Interface of the ERC-165 standard, as defined in the\r\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\r\n *\r\n * Implementers can declare support of contract interfaces, which can then be\r\n * queried by others ({ERC165Checker}).\r\n *\r\n * For an implementation, see {ERC165}.\r\n */\r\ninterface IERC165 {\r\n    /**\r\n     * @dev Returns true if this contract implements the interface defined by\r\n     * `interfaceId`. See the corresponding\r\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\r\n     * to learn more about how these ids are created.\r\n     *\r\n     * This function call must use less than 30 000 gas.\r\n     */\r\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\r\n}\r\n"},"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\nimport {IERC721} from \"../IERC721.sol\";\r\n\r\n/**\r\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\r\n * @dev See https://eips.ethereum.org/EIPS/eip-721\r\n */\r\ninterface IERC721Metadata is IERC721 {\r\n    /**\r\n     * @dev Returns the token collection name.\r\n     */\r\n    function name() external view returns (string memory);\r\n\r\n    /**\r\n     * @dev Returns the token collection symbol.\r\n     */\r\n    function symbol() external view returns (string memory);\r\n\r\n    /**\r\n     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\r\n     */\r\n    function tokenURI(uint256 tokenId) external view returns (string memory);\r\n}\r\n"},"@openzeppelin/contracts/token/ERC721/utils/ERC721Utils.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/utils/ERC721Utils.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\nimport {IERC721Receiver} from \"../IERC721Receiver.sol\";\r\nimport {IERC721Errors} from \"../../../interfaces/draft-IERC6093.sol\";\r\n\r\n/**\r\n * @dev Library that provide common ERC-721 utility functions.\r\n *\r\n * See https://eips.ethereum.org/EIPS/eip-721[ERC-721].\r\n *\r\n * _Available since v5.1._\r\n */\r\nlibrary ERC721Utils {\r\n    /**\r\n     * @dev Performs an acceptance check for the provided `operator` by calling {IERC721-onERC721Received}\r\n     * on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`).\r\n     *\r\n     * The acceptance call is not executed and treated as a no-op if the target address doesn't contain code (i.e. an EOA).\r\n     * Otherwise, the recipient must implement {IERC721Receiver-onERC721Received} and return the acceptance magic value to accept\r\n     * the transfer.\r\n     */\r\n    function checkOnERC721Received(\r\n        address operator,\r\n        address from,\r\n        address to,\r\n        uint256 tokenId,\r\n        bytes memory data\r\n    ) internal {\r\n        if (to.code.length > 0) {\r\n            try IERC721Receiver(to).onERC721Received(operator, from, tokenId, data) returns (bytes4 retval) {\r\n                if (retval != IERC721Receiver.onERC721Received.selector) {\r\n                    // Token rejected\r\n                    revert IERC721Errors.ERC721InvalidReceiver(to);\r\n                }\r\n            } catch (bytes memory reason) {\r\n                if (reason.length == 0) {\r\n                    // non-IERC721Receiver implementer\r\n                    revert IERC721Errors.ERC721InvalidReceiver(to);\r\n                } else {\r\n                    assembly (\"memory-safe\") {\r\n                        revert(add(32, reason), mload(reason))\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n"},"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721Receiver.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\n/**\r\n * @title ERC-721 token receiver interface\r\n * @dev Interface for any contract that wants to support safeTransfers\r\n * from ERC-721 asset contracts.\r\n */\r\ninterface IERC721Receiver {\r\n    /**\r\n     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\r\n     * by `operator` from `from`, this function is called.\r\n     *\r\n     * It must return its Solidity selector to confirm the token transfer.\r\n     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be\r\n     * reverted.\r\n     *\r\n     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.\r\n     */\r\n    function onERC721Received(\r\n        address operator,\r\n        address from,\r\n        uint256 tokenId,\r\n        bytes calldata data\r\n    ) external returns (bytes4);\r\n}\r\n"},"@openzeppelin/contracts/interfaces/draft-IERC6093.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)\r\npragma solidity ^0.8.20;\r\n\r\n/**\r\n * @dev Standard ERC-20 Errors\r\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\r\n */\r\ninterface IERC20Errors {\r\n    /**\r\n     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\r\n     * @param sender Address whose tokens are being transferred.\r\n     * @param balance Current balance for the interacting account.\r\n     * @param needed Minimum amount required to perform a transfer.\r\n     */\r\n    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the token `sender`. Used in transfers.\r\n     * @param sender Address whose tokens are being transferred.\r\n     */\r\n    error ERC20InvalidSender(address sender);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the token `receiver`. Used in transfers.\r\n     * @param receiver Address to which tokens are being transferred.\r\n     */\r\n    error ERC20InvalidReceiver(address receiver);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\r\n     * @param spender Address that may be allowed to operate on tokens without being their owner.\r\n     * @param allowance Amount of tokens a `spender` is allowed to operate with.\r\n     * @param needed Minimum amount required to perform a transfer.\r\n     */\r\n    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\r\n     * @param approver Address initiating an approval operation.\r\n     */\r\n    error ERC20InvalidApprover(address approver);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\r\n     * @param spender Address that may be allowed to operate on tokens without being their owner.\r\n     */\r\n    error ERC20InvalidSpender(address spender);\r\n}\r\n\r\n/**\r\n * @dev Standard ERC-721 Errors\r\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.\r\n */\r\ninterface IERC721Errors {\r\n    /**\r\n     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.\r\n     * Used in balance queries.\r\n     * @param owner Address of the current owner of a token.\r\n     */\r\n    error ERC721InvalidOwner(address owner);\r\n\r\n    /**\r\n     * @dev Indicates a `tokenId` whose `owner` is the zero address.\r\n     * @param tokenId Identifier number of a token.\r\n     */\r\n    error ERC721NonexistentToken(uint256 tokenId);\r\n\r\n    /**\r\n     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\r\n     * @param sender Address whose tokens are being transferred.\r\n     * @param tokenId Identifier number of a token.\r\n     * @param owner Address of the current owner of a token.\r\n     */\r\n    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the token `sender`. Used in transfers.\r\n     * @param sender Address whose tokens are being transferred.\r\n     */\r\n    error ERC721InvalidSender(address sender);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the token `receiver`. Used in transfers.\r\n     * @param receiver Address to which tokens are being transferred.\r\n     */\r\n    error ERC721InvalidReceiver(address receiver);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\r\n     * @param operator Address that may be allowed to operate on tokens without being their owner.\r\n     * @param tokenId Identifier number of a token.\r\n     */\r\n    error ERC721InsufficientApproval(address operator, uint256 tokenId);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\r\n     * @param approver Address initiating an approval operation.\r\n     */\r\n    error ERC721InvalidApprover(address approver);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\r\n     * @param operator Address that may be allowed to operate on tokens without being their owner.\r\n     */\r\n    error ERC721InvalidOperator(address operator);\r\n}\r\n\r\n/**\r\n * @dev Standard ERC-1155 Errors\r\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.\r\n */\r\ninterface IERC1155Errors {\r\n    /**\r\n     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\r\n     * @param sender Address whose tokens are being transferred.\r\n     * @param balance Current balance for the interacting account.\r\n     * @param needed Minimum amount required to perform a transfer.\r\n     * @param tokenId Identifier number of a token.\r\n     */\r\n    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the token `sender`. Used in transfers.\r\n     * @param sender Address whose tokens are being transferred.\r\n     */\r\n    error ERC1155InvalidSender(address sender);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the token `receiver`. Used in transfers.\r\n     * @param receiver Address to which tokens are being transferred.\r\n     */\r\n    error ERC1155InvalidReceiver(address receiver);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\r\n     * @param operator Address that may be allowed to operate on tokens without being their owner.\r\n     * @param owner Address of the current owner of a token.\r\n     */\r\n    error ERC1155MissingApprovalForAll(address operator, address owner);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\r\n     * @param approver Address initiating an approval operation.\r\n     */\r\n    error ERC1155InvalidApprover(address approver);\r\n\r\n    /**\r\n     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\r\n     * @param operator Address that may be allowed to operate on tokens without being their owner.\r\n     */\r\n    error ERC1155InvalidOperator(address operator);\r\n\r\n    /**\r\n     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\r\n     * Used in batch transfers.\r\n     * @param idsLength Length of the array of token identifiers\r\n     * @param valuesLength Length of the array of token amounts\r\n     */\r\n    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\r\n}\r\n"},"@openzeppelin/contracts/utils/Context.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\n/**\r\n * @dev Provides information about the current execution context, including the\r\n * sender of the transaction and its data. While these are generally available\r\n * via msg.sender and msg.data, they should not be accessed in such a direct\r\n * manner, since when dealing with meta-transactions the account sending and\r\n * paying for execution may not be the actual sender (as far as an application\r\n * is concerned).\r\n *\r\n * This contract is only required for intermediate, library-like contracts.\r\n */\r\nabstract contract Context {\r\n    function _msgSender() internal view virtual returns (address) {\r\n        return msg.sender;\r\n    }\r\n\r\n    function _msgData() internal view virtual returns (bytes calldata) {\r\n        return msg.data;\r\n    }\r\n\r\n    function _contextSuffixLength() internal view virtual returns (uint256) {\r\n        return 0;\r\n    }\r\n}\r\n"},"@openzeppelin/contracts/utils/Strings.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Strings.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\nimport {Math} from \"./math/Math.sol\";\r\nimport {SignedMath} from \"./math/SignedMath.sol\";\r\n\r\n/**\r\n * @dev String operations.\r\n */\r\nlibrary Strings {\r\n    bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\r\n    uint8 private constant ADDRESS_LENGTH = 20;\r\n\r\n    /**\r\n     * @dev The `value` string doesn't fit in the specified `length`.\r\n     */\r\n    error StringsInsufficientHexLength(uint256 value, uint256 length);\r\n\r\n    /**\r\n     * @dev Converts a `uint256` to its ASCII `string` decimal representation.\r\n     */\r\n    function toString(uint256 value) internal pure returns (string memory) {\r\n        unchecked {\r\n            uint256 length = Math.log10(value) + 1;\r\n            string memory buffer = new string(length);\r\n            uint256 ptr;\r\n            assembly (\"memory-safe\") {\r\n                ptr := add(buffer, add(32, length))\r\n            }\r\n            while (true) {\r\n                ptr--;\r\n                assembly (\"memory-safe\") {\r\n                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\r\n                }\r\n                value /= 10;\r\n                if (value == 0) break;\r\n            }\r\n            return buffer;\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Converts a `int256` to its ASCII `string` decimal representation.\r\n     */\r\n    function toStringSigned(int256 value) internal pure returns (string memory) {\r\n        return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\r\n    }\r\n\r\n    /**\r\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\r\n     */\r\n    function toHexString(uint256 value) internal pure returns (string memory) {\r\n        unchecked {\r\n            return toHexString(value, Math.log256(value) + 1);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\r\n     */\r\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\r\n        uint256 localValue = value;\r\n        bytes memory buffer = new bytes(2 * length + 2);\r\n        buffer[0] = \"0\";\r\n        buffer[1] = \"x\";\r\n        for (uint256 i = 2 * length + 1; i > 1; --i) {\r\n            buffer[i] = HEX_DIGITS[localValue & 0xf];\r\n            localValue >>= 4;\r\n        }\r\n        if (localValue != 0) {\r\n            revert StringsInsufficientHexLength(value, length);\r\n        }\r\n        return string(buffer);\r\n    }\r\n\r\n    /**\r\n     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\r\n     * representation.\r\n     */\r\n    function toHexString(address addr) internal pure returns (string memory) {\r\n        return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\r\n    }\r\n\r\n    /**\r\n     * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal\r\n     * representation, according to EIP-55.\r\n     */\r\n    function toChecksumHexString(address addr) internal pure returns (string memory) {\r\n        bytes memory buffer = bytes(toHexString(addr));\r\n\r\n        // hash the hex part of buffer (skip length + 2 bytes, length 40)\r\n        uint256 hashValue;\r\n        assembly (\"memory-safe\") {\r\n            hashValue := shr(96, keccak256(add(buffer, 0x22), 40))\r\n        }\r\n\r\n        for (uint256 i = 41; i > 1; --i) {\r\n            // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)\r\n            if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {\r\n                // case shift by xoring with 0x20\r\n                buffer[i] ^= 0x20;\r\n            }\r\n            hashValue >>= 4;\r\n        }\r\n        return string(buffer);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns true if the two strings are equal.\r\n     */\r\n    function equal(string memory a, string memory b) internal pure returns (bool) {\r\n        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\r\n    }\r\n}\r\n"},"@openzeppelin/contracts/utils/math/Math.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\nimport {Panic} from \"../Panic.sol\";\r\nimport {SafeCast} from \"./SafeCast.sol\";\r\n\r\n/**\r\n * @dev Standard math utilities missing in the Solidity language.\r\n */\r\nlibrary Math {\r\n    enum Rounding {\r\n        Floor, // Toward negative infinity\r\n        Ceil, // Toward positive infinity\r\n        Trunc, // Toward zero\r\n        Expand // Away from zero\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the addition of two unsigned integers, with an success flag (no overflow).\r\n     */\r\n    function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\r\n        unchecked {\r\n            uint256 c = a + b;\r\n            if (c < a) return (false, 0);\r\n            return (true, c);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).\r\n     */\r\n    function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\r\n        unchecked {\r\n            if (b > a) return (false, 0);\r\n            return (true, a - b);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).\r\n     */\r\n    function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\r\n        unchecked {\r\n            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\r\n            // benefit is lost if 'b' is also tested.\r\n            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\r\n            if (a == 0) return (true, 0);\r\n            uint256 c = a * b;\r\n            if (c / a != b) return (false, 0);\r\n            return (true, c);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).\r\n     */\r\n    function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\r\n        unchecked {\r\n            if (b == 0) return (false, 0);\r\n            return (true, a / b);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).\r\n     */\r\n    function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\r\n        unchecked {\r\n            if (b == 0) return (false, 0);\r\n            return (true, a % b);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\r\n     *\r\n     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\r\n     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\r\n     * one branch when needed, making this function more expensive.\r\n     */\r\n    function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {\r\n        unchecked {\r\n            // branchless ternary works because:\r\n            // b ^ (a ^ b) == a\r\n            // b ^ 0 == b\r\n            return b ^ ((a ^ b) * SafeCast.toUint(condition));\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the largest of two numbers.\r\n     */\r\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        return ternary(a > b, a, b);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the smallest of two numbers.\r\n     */\r\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        return ternary(a < b, a, b);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the average of two numbers. The result is rounded towards\r\n     * zero.\r\n     */\r\n    function average(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        // (a + b) / 2 can overflow.\r\n        return (a & b) + (a ^ b) / 2;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the ceiling of the division of two numbers.\r\n     *\r\n     * This differs from standard division with `/` in that it rounds towards infinity instead\r\n     * of rounding towards zero.\r\n     */\r\n    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        if (b == 0) {\r\n            // Guarantee the same behavior as in a regular Solidity division.\r\n            Panic.panic(Panic.DIVISION_BY_ZERO);\r\n        }\r\n\r\n        // The following calculation ensures accurate ceiling division without overflow.\r\n        // Since a is non-zero, (a - 1) / b will not overflow.\r\n        // The largest possible result occurs when (a - 1) / b is type(uint256).max,\r\n        // but the largest value we can obtain is type(uint256).max - 1, which happens\r\n        // when a = type(uint256).max and b = 1.\r\n        unchecked {\r\n            return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\r\n     * denominator == 0.\r\n     *\r\n     * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\r\n     * Uniswap Labs also under MIT license.\r\n     */\r\n    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\r\n        unchecked {\r\n            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use\r\n            // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\r\n            // variables such that product = prod1 * 2²⁵⁶ + prod0.\r\n            uint256 prod0 = x * y; // Least significant 256 bits of the product\r\n            uint256 prod1; // Most significant 256 bits of the product\r\n            assembly {\r\n                let mm := mulmod(x, y, not(0))\r\n                prod1 := sub(sub(mm, prod0), lt(mm, prod0))\r\n            }\r\n\r\n            // Handle non-overflow cases, 256 by 256 division.\r\n            if (prod1 == 0) {\r\n                // Solidity will revert if denominator == 0, unlike the div opcode on its own.\r\n                // The surrounding unchecked block does not change this fact.\r\n                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\r\n                return prod0 / denominator;\r\n            }\r\n\r\n            // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.\r\n            if (denominator <= prod1) {\r\n                Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));\r\n            }\r\n\r\n            ///////////////////////////////////////////////\r\n            // 512 by 256 division.\r\n            ///////////////////////////////////////////////\r\n\r\n            // Make division exact by subtracting the remainder from [prod1 prod0].\r\n            uint256 remainder;\r\n            assembly {\r\n                // Compute remainder using mulmod.\r\n                remainder := mulmod(x, y, denominator)\r\n\r\n                // Subtract 256 bit number from 512 bit number.\r\n                prod1 := sub(prod1, gt(remainder, prod0))\r\n                prod0 := sub(prod0, remainder)\r\n            }\r\n\r\n            // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\r\n            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\r\n\r\n            uint256 twos = denominator & (0 - denominator);\r\n            assembly {\r\n                // Divide denominator by twos.\r\n                denominator := div(denominator, twos)\r\n\r\n                // Divide [prod1 prod0] by twos.\r\n                prod0 := div(prod0, twos)\r\n\r\n                // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.\r\n                twos := add(div(sub(0, twos), twos), 1)\r\n            }\r\n\r\n            // Shift in bits from prod1 into prod0.\r\n            prod0 |= prod1 * twos;\r\n\r\n            // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such\r\n            // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for\r\n            // four bits. That is, denominator * inv ≡ 1 mod 2⁴.\r\n            uint256 inverse = (3 * denominator) ^ 2;\r\n\r\n            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\r\n            // works in modular arithmetic, doubling the correct bits in each step.\r\n            inverse *= 2 - denominator * inverse; // inverse mod 2⁸\r\n            inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶\r\n            inverse *= 2 - denominator * inverse; // inverse mod 2³²\r\n            inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴\r\n            inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸\r\n            inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶\r\n\r\n            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\r\n            // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is\r\n            // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1\r\n            // is no longer required.\r\n            result = prod0 * inverse;\r\n            return result;\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.\r\n     */\r\n    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\r\n        return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);\r\n    }\r\n\r\n    /**\r\n     * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.\r\n     *\r\n     * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.\r\n     * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.\r\n     *\r\n     * If the input value is not inversible, 0 is returned.\r\n     *\r\n     * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the\r\n     * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.\r\n     */\r\n    function invMod(uint256 a, uint256 n) internal pure returns (uint256) {\r\n        unchecked {\r\n            if (n == 0) return 0;\r\n\r\n            // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)\r\n            // Used to compute integers x and y such that: ax + ny = gcd(a, n).\r\n            // When the gcd is 1, then the inverse of a modulo n exists and it's x.\r\n            // ax + ny = 1\r\n            // ax = 1 + (-y)n\r\n            // ax ≡ 1 (mod n) # x is the inverse of a modulo n\r\n\r\n            // If the remainder is 0 the gcd is n right away.\r\n            uint256 remainder = a % n;\r\n            uint256 gcd = n;\r\n\r\n            // Therefore the initial coefficients are:\r\n            // ax + ny = gcd(a, n) = n\r\n            // 0a + 1n = n\r\n            int256 x = 0;\r\n            int256 y = 1;\r\n\r\n            while (remainder != 0) {\r\n                uint256 quotient = gcd / remainder;\r\n\r\n                (gcd, remainder) = (\r\n                    // The old remainder is the next gcd to try.\r\n                    remainder,\r\n                    // Compute the next remainder.\r\n                    // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd\r\n                    // where gcd is at most n (capped to type(uint256).max)\r\n                    gcd - remainder * quotient\r\n                );\r\n\r\n                (x, y) = (\r\n                    // Increment the coefficient of a.\r\n                    y,\r\n                    // Decrement the coefficient of n.\r\n                    // Can overflow, but the result is casted to uint256 so that the\r\n                    // next value of y is \"wrapped around\" to a value between 0 and n - 1.\r\n                    x - y * int256(quotient)\r\n                );\r\n            }\r\n\r\n            if (gcd != 1) return 0; // No inverse exists.\r\n            return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.\r\n     *\r\n     * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is\r\n     * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that\r\n     * `a**(p-2)` is the modular multiplicative inverse of a in Fp.\r\n     *\r\n     * NOTE: this function does NOT check that `p` is a prime greater than `2`.\r\n     */\r\n    function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {\r\n        unchecked {\r\n            return Math.modExp(a, p - 2, p);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)\r\n     *\r\n     * Requirements:\r\n     * - modulus can't be zero\r\n     * - underlying staticcall to precompile must succeed\r\n     *\r\n     * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make\r\n     * sure the chain you're using it on supports the precompiled contract for modular exponentiation\r\n     * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,\r\n     * the underlying function will succeed given the lack of a revert, but the result may be incorrectly\r\n     * interpreted as 0.\r\n     */\r\n    function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {\r\n        (bool success, uint256 result) = tryModExp(b, e, m);\r\n        if (!success) {\r\n            Panic.panic(Panic.DIVISION_BY_ZERO);\r\n        }\r\n        return result;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).\r\n     * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying\r\n     * to operate modulo 0 or if the underlying precompile reverted.\r\n     *\r\n     * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain\r\n     * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in\r\n     * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack\r\n     * of a revert, but the result may be incorrectly interpreted as 0.\r\n     */\r\n    function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {\r\n        if (m == 0) return (false, 0);\r\n        assembly (\"memory-safe\") {\r\n            let ptr := mload(0x40)\r\n            // | Offset    | Content    | Content (Hex)                                                      |\r\n            // |-----------|------------|--------------------------------------------------------------------|\r\n            // | 0x00:0x1f | size of b  | 0x0000000000000000000000000000000000000000000000000000000000000020 |\r\n            // | 0x20:0x3f | size of e  | 0x0000000000000000000000000000000000000000000000000000000000000020 |\r\n            // | 0x40:0x5f | size of m  | 0x0000000000000000000000000000000000000000000000000000000000000020 |\r\n            // | 0x60:0x7f | value of b | 0x<.............................................................b> |\r\n            // | 0x80:0x9f | value of e | 0x<.............................................................e> |\r\n            // | 0xa0:0xbf | value of m | 0x<.............................................................m> |\r\n            mstore(ptr, 0x20)\r\n            mstore(add(ptr, 0x20), 0x20)\r\n            mstore(add(ptr, 0x40), 0x20)\r\n            mstore(add(ptr, 0x60), b)\r\n            mstore(add(ptr, 0x80), e)\r\n            mstore(add(ptr, 0xa0), m)\r\n\r\n            // Given the result < m, it's guaranteed to fit in 32 bytes,\r\n            // so we can use the memory scratch space located at offset 0.\r\n            success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)\r\n            result := mload(0x00)\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Variant of {modExp} that supports inputs of arbitrary length.\r\n     */\r\n    function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {\r\n        (bool success, bytes memory result) = tryModExp(b, e, m);\r\n        if (!success) {\r\n            Panic.panic(Panic.DIVISION_BY_ZERO);\r\n        }\r\n        return result;\r\n    }\r\n\r\n    /**\r\n     * @dev Variant of {tryModExp} that supports inputs of arbitrary length.\r\n     */\r\n    function tryModExp(\r\n        bytes memory b,\r\n        bytes memory e,\r\n        bytes memory m\r\n    ) internal view returns (bool success, bytes memory result) {\r\n        if (_zeroBytes(m)) return (false, new bytes(0));\r\n\r\n        uint256 mLen = m.length;\r\n\r\n        // Encode call args in result and move the free memory pointer\r\n        result = abi.encodePacked(b.length, e.length, mLen, b, e, m);\r\n\r\n        assembly (\"memory-safe\") {\r\n            let dataPtr := add(result, 0x20)\r\n            // Write result on top of args to avoid allocating extra memory.\r\n            success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)\r\n            // Overwrite the length.\r\n            // result.length > returndatasize() is guaranteed because returndatasize() == m.length\r\n            mstore(result, mLen)\r\n            // Set the memory pointer after the returned data.\r\n            mstore(0x40, add(dataPtr, mLen))\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns whether the provided byte array is zero.\r\n     */\r\n    function _zeroBytes(bytes memory byteArray) private pure returns (bool) {\r\n        for (uint256 i = 0; i < byteArray.length; ++i) {\r\n            if (byteArray[i] != 0) {\r\n                return false;\r\n            }\r\n        }\r\n        return true;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\r\n     * towards zero.\r\n     *\r\n     * This method is based on Newton's method for computing square roots; the algorithm is restricted to only\r\n     * using integer operations.\r\n     */\r\n    function sqrt(uint256 a) internal pure returns (uint256) {\r\n        unchecked {\r\n            // Take care of easy edge cases when a == 0 or a == 1\r\n            if (a <= 1) {\r\n                return a;\r\n            }\r\n\r\n            // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a\r\n            // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between\r\n            // the current value as `ε_n = | x_n - sqrt(a) |`.\r\n            //\r\n            // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root\r\n            // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is\r\n            // bigger than any uint256.\r\n            //\r\n            // By noticing that\r\n            // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`\r\n            // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar\r\n            // to the msb function.\r\n            uint256 aa = a;\r\n            uint256 xn = 1;\r\n\r\n            if (aa >= (1 << 128)) {\r\n                aa >>= 128;\r\n                xn <<= 64;\r\n            }\r\n            if (aa >= (1 << 64)) {\r\n                aa >>= 64;\r\n                xn <<= 32;\r\n            }\r\n            if (aa >= (1 << 32)) {\r\n                aa >>= 32;\r\n                xn <<= 16;\r\n            }\r\n            if (aa >= (1 << 16)) {\r\n                aa >>= 16;\r\n                xn <<= 8;\r\n            }\r\n            if (aa >= (1 << 8)) {\r\n                aa >>= 8;\r\n                xn <<= 4;\r\n            }\r\n            if (aa >= (1 << 4)) {\r\n                aa >>= 4;\r\n                xn <<= 2;\r\n            }\r\n            if (aa >= (1 << 2)) {\r\n                xn <<= 1;\r\n            }\r\n\r\n            // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).\r\n            //\r\n            // We can refine our estimation by noticing that the middle of that interval minimizes the error.\r\n            // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).\r\n            // This is going to be our x_0 (and ε_0)\r\n            xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)\r\n\r\n            // From here, Newton's method give us:\r\n            // x_{n+1} = (x_n + a / x_n) / 2\r\n            //\r\n            // One should note that:\r\n            // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a\r\n            //              = ((x_n² + a) / (2 * x_n))² - a\r\n            //              = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a\r\n            //              = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)\r\n            //              = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)\r\n            //              = (x_n² - a)² / (2 * x_n)²\r\n            //              = ((x_n² - a) / (2 * x_n))²\r\n            //              ≥ 0\r\n            // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n\r\n            //\r\n            // This gives us the proof of quadratic convergence of the sequence:\r\n            // ε_{n+1} = | x_{n+1} - sqrt(a) |\r\n            //         = | (x_n + a / x_n) / 2 - sqrt(a) |\r\n            //         = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |\r\n            //         = | (x_n - sqrt(a))² / (2 * x_n) |\r\n            //         = | ε_n² / (2 * x_n) |\r\n            //         = ε_n² / | (2 * x_n) |\r\n            //\r\n            // For the first iteration, we have a special case where x_0 is known:\r\n            // ε_1 = ε_0² / | (2 * x_0) |\r\n            //     ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))\r\n            //     ≤ 2**(2*e-4) / (3 * 2**(e-1))\r\n            //     ≤ 2**(e-3) / 3\r\n            //     ≤ 2**(e-3-log2(3))\r\n            //     ≤ 2**(e-4.5)\r\n            //\r\n            // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:\r\n            // ε_{n+1} = ε_n² / | (2 * x_n) |\r\n            //         ≤ (2**(e-k))² / (2 * 2**(e-1))\r\n            //         ≤ 2**(2*e-2*k) / 2**e\r\n            //         ≤ 2**(e-2*k)\r\n            xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5)  -- special case, see above\r\n            xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9)    -- general case with k = 4.5\r\n            xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18)   -- general case with k = 9\r\n            xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36)   -- general case with k = 18\r\n            xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72)   -- general case with k = 36\r\n            xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144)  -- general case with k = 72\r\n\r\n            // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision\r\n            // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either\r\n            // sqrt(a) or sqrt(a) + 1.\r\n            return xn - SafeCast.toUint(xn > a / xn);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Calculates sqrt(a), following the selected rounding direction.\r\n     */\r\n    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\r\n        unchecked {\r\n            uint256 result = sqrt(a);\r\n            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Return the log in base 2 of a positive value rounded towards zero.\r\n     * Returns 0 if given 0.\r\n     */\r\n    function log2(uint256 value) internal pure returns (uint256) {\r\n        uint256 result = 0;\r\n        uint256 exp;\r\n        unchecked {\r\n            exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);\r\n            value >>= exp;\r\n            result += exp;\r\n\r\n            exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);\r\n            value >>= exp;\r\n            result += exp;\r\n\r\n            exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);\r\n            value >>= exp;\r\n            result += exp;\r\n\r\n            exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);\r\n            value >>= exp;\r\n            result += exp;\r\n\r\n            exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);\r\n            value >>= exp;\r\n            result += exp;\r\n\r\n            exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);\r\n            value >>= exp;\r\n            result += exp;\r\n\r\n            exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);\r\n            value >>= exp;\r\n            result += exp;\r\n\r\n            result += SafeCast.toUint(value > 1);\r\n        }\r\n        return result;\r\n    }\r\n\r\n    /**\r\n     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\r\n     * Returns 0 if given 0.\r\n     */\r\n    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\r\n        unchecked {\r\n            uint256 result = log2(value);\r\n            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Return the log in base 10 of a positive value rounded towards zero.\r\n     * Returns 0 if given 0.\r\n     */\r\n    function log10(uint256 value) internal pure returns (uint256) {\r\n        uint256 result = 0;\r\n        unchecked {\r\n            if (value >= 10 ** 64) {\r\n                value /= 10 ** 64;\r\n                result += 64;\r\n            }\r\n            if (value >= 10 ** 32) {\r\n                value /= 10 ** 32;\r\n                result += 32;\r\n            }\r\n            if (value >= 10 ** 16) {\r\n                value /= 10 ** 16;\r\n                result += 16;\r\n            }\r\n            if (value >= 10 ** 8) {\r\n                value /= 10 ** 8;\r\n                result += 8;\r\n            }\r\n            if (value >= 10 ** 4) {\r\n                value /= 10 ** 4;\r\n                result += 4;\r\n            }\r\n            if (value >= 10 ** 2) {\r\n                value /= 10 ** 2;\r\n                result += 2;\r\n            }\r\n            if (value >= 10 ** 1) {\r\n                result += 1;\r\n            }\r\n        }\r\n        return result;\r\n    }\r\n\r\n    /**\r\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\r\n     * Returns 0 if given 0.\r\n     */\r\n    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\r\n        unchecked {\r\n            uint256 result = log10(value);\r\n            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Return the log in base 256 of a positive value rounded towards zero.\r\n     * Returns 0 if given 0.\r\n     *\r\n     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\r\n     */\r\n    function log256(uint256 value) internal pure returns (uint256) {\r\n        uint256 result = 0;\r\n        uint256 isGt;\r\n        unchecked {\r\n            isGt = SafeCast.toUint(value > (1 << 128) - 1);\r\n            value >>= isGt * 128;\r\n            result += isGt * 16;\r\n\r\n            isGt = SafeCast.toUint(value > (1 << 64) - 1);\r\n            value >>= isGt * 64;\r\n            result += isGt * 8;\r\n\r\n            isGt = SafeCast.toUint(value > (1 << 32) - 1);\r\n            value >>= isGt * 32;\r\n            result += isGt * 4;\r\n\r\n            isGt = SafeCast.toUint(value > (1 << 16) - 1);\r\n            value >>= isGt * 16;\r\n            result += isGt * 2;\r\n\r\n            result += SafeCast.toUint(value > (1 << 8) - 1);\r\n        }\r\n        return result;\r\n    }\r\n\r\n    /**\r\n     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\r\n     * Returns 0 if given 0.\r\n     */\r\n    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\r\n        unchecked {\r\n            uint256 result = log256(value);\r\n            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\r\n     */\r\n    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\r\n        return uint8(rounding) % 2 == 1;\r\n    }\r\n}\r\n"},"@openzeppelin/contracts/utils/Panic.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\n/**\r\n * @dev Helper library for emitting standardized panic codes.\r\n *\r\n * ```solidity\r\n * contract Example {\r\n *      using Panic for uint256;\r\n *\r\n *      // Use any of the declared internal constants\r\n *      function foo() { Panic.GENERIC.panic(); }\r\n *\r\n *      // Alternatively\r\n *      function foo() { Panic.panic(Panic.GENERIC); }\r\n * }\r\n * ```\r\n *\r\n * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].\r\n *\r\n * _Available since v5.1._\r\n */\r\n// slither-disable-next-line unused-state\r\nlibrary Panic {\r\n    /// @dev generic / unspecified error\r\n    uint256 internal constant GENERIC = 0x00;\r\n    /// @dev used by the assert() builtin\r\n    uint256 internal constant ASSERT = 0x01;\r\n    /// @dev arithmetic underflow or overflow\r\n    uint256 internal constant UNDER_OVERFLOW = 0x11;\r\n    /// @dev division or modulo by zero\r\n    uint256 internal constant DIVISION_BY_ZERO = 0x12;\r\n    /// @dev enum conversion error\r\n    uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;\r\n    /// @dev invalid encoding in storage\r\n    uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;\r\n    /// @dev empty array pop\r\n    uint256 internal constant EMPTY_ARRAY_POP = 0x31;\r\n    /// @dev array out of bounds access\r\n    uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;\r\n    /// @dev resource error (too large allocation or too large array)\r\n    uint256 internal constant RESOURCE_ERROR = 0x41;\r\n    /// @dev calling invalid internal function\r\n    uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;\r\n\r\n    /// @dev Reverts with a panic code. Recommended to use with\r\n    /// the internal constants with predefined codes.\r\n    function panic(uint256 code) internal pure {\r\n        assembly (\"memory-safe\") {\r\n            mstore(0x00, 0x4e487b71)\r\n            mstore(0x20, code)\r\n            revert(0x1c, 0x24)\r\n        }\r\n    }\r\n}\r\n"},"@openzeppelin/contracts/utils/math/SafeCast.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)\r\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\r\n\r\npragma solidity ^0.8.20;\r\n\r\n/**\r\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\r\n * checks.\r\n *\r\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\r\n * easily result in undesired exploitation or bugs, since developers usually\r\n * assume that overflows raise errors. `SafeCast` restores this intuition by\r\n * reverting the transaction when such an operation overflows.\r\n *\r\n * Using this library instead of the unchecked operations eliminates an entire\r\n * class of bugs, so it's recommended to use it always.\r\n */\r\nlibrary SafeCast {\r\n    /**\r\n     * @dev Value doesn't fit in an uint of `bits` size.\r\n     */\r\n    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\r\n\r\n    /**\r\n     * @dev An int value doesn't fit in an uint of `bits` size.\r\n     */\r\n    error SafeCastOverflowedIntToUint(int256 value);\r\n\r\n    /**\r\n     * @dev Value doesn't fit in an int of `bits` size.\r\n     */\r\n    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\r\n\r\n    /**\r\n     * @dev An uint value doesn't fit in an int of `bits` size.\r\n     */\r\n    error SafeCastOverflowedUintToInt(uint256 value);\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint248 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint248).\r\n     *\r\n     * Counterpart to Solidity's `uint248` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 248 bits\r\n     */\r\n    function toUint248(uint256 value) internal pure returns (uint248) {\r\n        if (value > type(uint248).max) {\r\n            revert SafeCastOverflowedUintDowncast(248, value);\r\n        }\r\n        return uint248(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint240 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint240).\r\n     *\r\n     * Counterpart to Solidity's `uint240` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 240 bits\r\n     */\r\n    function toUint240(uint256 value) internal pure returns (uint240) {\r\n        if (value > type(uint240).max) {\r\n            revert SafeCastOverflowedUintDowncast(240, value);\r\n        }\r\n        return uint240(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint232 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint232).\r\n     *\r\n     * Counterpart to Solidity's `uint232` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 232 bits\r\n     */\r\n    function toUint232(uint256 value) internal pure returns (uint232) {\r\n        if (value > type(uint232).max) {\r\n            revert SafeCastOverflowedUintDowncast(232, value);\r\n        }\r\n        return uint232(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint224 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint224).\r\n     *\r\n     * Counterpart to Solidity's `uint224` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 224 bits\r\n     */\r\n    function toUint224(uint256 value) internal pure returns (uint224) {\r\n        if (value > type(uint224).max) {\r\n            revert SafeCastOverflowedUintDowncast(224, value);\r\n        }\r\n        return uint224(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint216 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint216).\r\n     *\r\n     * Counterpart to Solidity's `uint216` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 216 bits\r\n     */\r\n    function toUint216(uint256 value) internal pure returns (uint216) {\r\n        if (value > type(uint216).max) {\r\n            revert SafeCastOverflowedUintDowncast(216, value);\r\n        }\r\n        return uint216(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint208 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint208).\r\n     *\r\n     * Counterpart to Solidity's `uint208` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 208 bits\r\n     */\r\n    function toUint208(uint256 value) internal pure returns (uint208) {\r\n        if (value > type(uint208).max) {\r\n            revert SafeCastOverflowedUintDowncast(208, value);\r\n        }\r\n        return uint208(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint200 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint200).\r\n     *\r\n     * Counterpart to Solidity's `uint200` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 200 bits\r\n     */\r\n    function toUint200(uint256 value) internal pure returns (uint200) {\r\n        if (value > type(uint200).max) {\r\n            revert SafeCastOverflowedUintDowncast(200, value);\r\n        }\r\n        return uint200(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint192 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint192).\r\n     *\r\n     * Counterpart to Solidity's `uint192` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 192 bits\r\n     */\r\n    function toUint192(uint256 value) internal pure returns (uint192) {\r\n        if (value > type(uint192).max) {\r\n            revert SafeCastOverflowedUintDowncast(192, value);\r\n        }\r\n        return uint192(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint184 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint184).\r\n     *\r\n     * Counterpart to Solidity's `uint184` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 184 bits\r\n     */\r\n    function toUint184(uint256 value) internal pure returns (uint184) {\r\n        if (value > type(uint184).max) {\r\n            revert SafeCastOverflowedUintDowncast(184, value);\r\n        }\r\n        return uint184(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint176 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint176).\r\n     *\r\n     * Counterpart to Solidity's `uint176` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 176 bits\r\n     */\r\n    function toUint176(uint256 value) internal pure returns (uint176) {\r\n        if (value > type(uint176).max) {\r\n            revert SafeCastOverflowedUintDowncast(176, value);\r\n        }\r\n        return uint176(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint168 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint168).\r\n     *\r\n     * Counterpart to Solidity's `uint168` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 168 bits\r\n     */\r\n    function toUint168(uint256 value) internal pure returns (uint168) {\r\n        if (value > type(uint168).max) {\r\n            revert SafeCastOverflowedUintDowncast(168, value);\r\n        }\r\n        return uint168(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint160 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint160).\r\n     *\r\n     * Counterpart to Solidity's `uint160` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 160 bits\r\n     */\r\n    function toUint160(uint256 value) internal pure returns (uint160) {\r\n        if (value > type(uint160).max) {\r\n            revert SafeCastOverflowedUintDowncast(160, value);\r\n        }\r\n        return uint160(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint152 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint152).\r\n     *\r\n     * Counterpart to Solidity's `uint152` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 152 bits\r\n     */\r\n    function toUint152(uint256 value) internal pure returns (uint152) {\r\n        if (value > type(uint152).max) {\r\n            revert SafeCastOverflowedUintDowncast(152, value);\r\n        }\r\n        return uint152(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint144 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint144).\r\n     *\r\n     * Counterpart to Solidity's `uint144` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 144 bits\r\n     */\r\n    function toUint144(uint256 value) internal pure returns (uint144) {\r\n        if (value > type(uint144).max) {\r\n            revert SafeCastOverflowedUintDowncast(144, value);\r\n        }\r\n        return uint144(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint136 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint136).\r\n     *\r\n     * Counterpart to Solidity's `uint136` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 136 bits\r\n     */\r\n    function toUint136(uint256 value) internal pure returns (uint136) {\r\n        if (value > type(uint136).max) {\r\n            revert SafeCastOverflowedUintDowncast(136, value);\r\n        }\r\n        return uint136(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint128 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint128).\r\n     *\r\n     * Counterpart to Solidity's `uint128` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 128 bits\r\n     */\r\n    function toUint128(uint256 value) internal pure returns (uint128) {\r\n        if (value > type(uint128).max) {\r\n            revert SafeCastOverflowedUintDowncast(128, value);\r\n        }\r\n        return uint128(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint120 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint120).\r\n     *\r\n     * Counterpart to Solidity's `uint120` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 120 bits\r\n     */\r\n    function toUint120(uint256 value) internal pure returns (uint120) {\r\n        if (value > type(uint120).max) {\r\n            revert SafeCastOverflowedUintDowncast(120, value);\r\n        }\r\n        return uint120(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint112 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint112).\r\n     *\r\n     * Counterpart to Solidity's `uint112` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 112 bits\r\n     */\r\n    function toUint112(uint256 value) internal pure returns (uint112) {\r\n        if (value > type(uint112).max) {\r\n            revert SafeCastOverflowedUintDowncast(112, value);\r\n        }\r\n        return uint112(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint104 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint104).\r\n     *\r\n     * Counterpart to Solidity's `uint104` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 104 bits\r\n     */\r\n    function toUint104(uint256 value) internal pure returns (uint104) {\r\n        if (value > type(uint104).max) {\r\n            revert SafeCastOverflowedUintDowncast(104, value);\r\n        }\r\n        return uint104(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint96 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint96).\r\n     *\r\n     * Counterpart to Solidity's `uint96` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 96 bits\r\n     */\r\n    function toUint96(uint256 value) internal pure returns (uint96) {\r\n        if (value > type(uint96).max) {\r\n            revert SafeCastOverflowedUintDowncast(96, value);\r\n        }\r\n        return uint96(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint88 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint88).\r\n     *\r\n     * Counterpart to Solidity's `uint88` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 88 bits\r\n     */\r\n    function toUint88(uint256 value) internal pure returns (uint88) {\r\n        if (value > type(uint88).max) {\r\n            revert SafeCastOverflowedUintDowncast(88, value);\r\n        }\r\n        return uint88(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint80 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint80).\r\n     *\r\n     * Counterpart to Solidity's `uint80` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 80 bits\r\n     */\r\n    function toUint80(uint256 value) internal pure returns (uint80) {\r\n        if (value > type(uint80).max) {\r\n            revert SafeCastOverflowedUintDowncast(80, value);\r\n        }\r\n        return uint80(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint72 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint72).\r\n     *\r\n     * Counterpart to Solidity's `uint72` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 72 bits\r\n     */\r\n    function toUint72(uint256 value) internal pure returns (uint72) {\r\n        if (value > type(uint72).max) {\r\n            revert SafeCastOverflowedUintDowncast(72, value);\r\n        }\r\n        return uint72(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint64 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint64).\r\n     *\r\n     * Counterpart to Solidity's `uint64` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 64 bits\r\n     */\r\n    function toUint64(uint256 value) internal pure returns (uint64) {\r\n        if (value > type(uint64).max) {\r\n            revert SafeCastOverflowedUintDowncast(64, value);\r\n        }\r\n        return uint64(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint56 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint56).\r\n     *\r\n     * Counterpart to Solidity's `uint56` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 56 bits\r\n     */\r\n    function toUint56(uint256 value) internal pure returns (uint56) {\r\n        if (value > type(uint56).max) {\r\n            revert SafeCastOverflowedUintDowncast(56, value);\r\n        }\r\n        return uint56(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint48 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint48).\r\n     *\r\n     * Counterpart to Solidity's `uint48` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 48 bits\r\n     */\r\n    function toUint48(uint256 value) internal pure returns (uint48) {\r\n        if (value > type(uint48).max) {\r\n            revert SafeCastOverflowedUintDowncast(48, value);\r\n        }\r\n        return uint48(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint40 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint40).\r\n     *\r\n     * Counterpart to Solidity's `uint40` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 40 bits\r\n     */\r\n    function toUint40(uint256 value) internal pure returns (uint40) {\r\n        if (value > type(uint40).max) {\r\n            revert SafeCastOverflowedUintDowncast(40, value);\r\n        }\r\n        return uint40(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint32 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint32).\r\n     *\r\n     * Counterpart to Solidity's `uint32` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 32 bits\r\n     */\r\n    function toUint32(uint256 value) internal pure returns (uint32) {\r\n        if (value > type(uint32).max) {\r\n            revert SafeCastOverflowedUintDowncast(32, value);\r\n        }\r\n        return uint32(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint24 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint24).\r\n     *\r\n     * Counterpart to Solidity's `uint24` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 24 bits\r\n     */\r\n    function toUint24(uint256 value) internal pure returns (uint24) {\r\n        if (value > type(uint24).max) {\r\n            revert SafeCastOverflowedUintDowncast(24, value);\r\n        }\r\n        return uint24(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint16 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint16).\r\n     *\r\n     * Counterpart to Solidity's `uint16` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 16 bits\r\n     */\r\n    function toUint16(uint256 value) internal pure returns (uint16) {\r\n        if (value > type(uint16).max) {\r\n            revert SafeCastOverflowedUintDowncast(16, value);\r\n        }\r\n        return uint16(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted uint8 from uint256, reverting on\r\n     * overflow (when the input is greater than largest uint8).\r\n     *\r\n     * Counterpart to Solidity's `uint8` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 8 bits\r\n     */\r\n    function toUint8(uint256 value) internal pure returns (uint8) {\r\n        if (value > type(uint8).max) {\r\n            revert SafeCastOverflowedUintDowncast(8, value);\r\n        }\r\n        return uint8(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Converts a signed int256 into an unsigned uint256.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must be greater than or equal to 0.\r\n     */\r\n    function toUint256(int256 value) internal pure returns (uint256) {\r\n        if (value < 0) {\r\n            revert SafeCastOverflowedIntToUint(value);\r\n        }\r\n        return uint256(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int248 from int256, reverting on\r\n     * overflow (when the input is less than smallest int248 or\r\n     * greater than largest int248).\r\n     *\r\n     * Counterpart to Solidity's `int248` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 248 bits\r\n     */\r\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\r\n        downcasted = int248(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(248, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int240 from int256, reverting on\r\n     * overflow (when the input is less than smallest int240 or\r\n     * greater than largest int240).\r\n     *\r\n     * Counterpart to Solidity's `int240` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 240 bits\r\n     */\r\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\r\n        downcasted = int240(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(240, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int232 from int256, reverting on\r\n     * overflow (when the input is less than smallest int232 or\r\n     * greater than largest int232).\r\n     *\r\n     * Counterpart to Solidity's `int232` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 232 bits\r\n     */\r\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\r\n        downcasted = int232(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(232, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int224 from int256, reverting on\r\n     * overflow (when the input is less than smallest int224 or\r\n     * greater than largest int224).\r\n     *\r\n     * Counterpart to Solidity's `int224` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 224 bits\r\n     */\r\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\r\n        downcasted = int224(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(224, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int216 from int256, reverting on\r\n     * overflow (when the input is less than smallest int216 or\r\n     * greater than largest int216).\r\n     *\r\n     * Counterpart to Solidity's `int216` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 216 bits\r\n     */\r\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\r\n        downcasted = int216(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(216, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int208 from int256, reverting on\r\n     * overflow (when the input is less than smallest int208 or\r\n     * greater than largest int208).\r\n     *\r\n     * Counterpart to Solidity's `int208` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 208 bits\r\n     */\r\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\r\n        downcasted = int208(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(208, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int200 from int256, reverting on\r\n     * overflow (when the input is less than smallest int200 or\r\n     * greater than largest int200).\r\n     *\r\n     * Counterpart to Solidity's `int200` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 200 bits\r\n     */\r\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\r\n        downcasted = int200(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(200, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int192 from int256, reverting on\r\n     * overflow (when the input is less than smallest int192 or\r\n     * greater than largest int192).\r\n     *\r\n     * Counterpart to Solidity's `int192` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 192 bits\r\n     */\r\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\r\n        downcasted = int192(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(192, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int184 from int256, reverting on\r\n     * overflow (when the input is less than smallest int184 or\r\n     * greater than largest int184).\r\n     *\r\n     * Counterpart to Solidity's `int184` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 184 bits\r\n     */\r\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\r\n        downcasted = int184(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(184, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int176 from int256, reverting on\r\n     * overflow (when the input is less than smallest int176 or\r\n     * greater than largest int176).\r\n     *\r\n     * Counterpart to Solidity's `int176` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 176 bits\r\n     */\r\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\r\n        downcasted = int176(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(176, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int168 from int256, reverting on\r\n     * overflow (when the input is less than smallest int168 or\r\n     * greater than largest int168).\r\n     *\r\n     * Counterpart to Solidity's `int168` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 168 bits\r\n     */\r\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\r\n        downcasted = int168(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(168, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int160 from int256, reverting on\r\n     * overflow (when the input is less than smallest int160 or\r\n     * greater than largest int160).\r\n     *\r\n     * Counterpart to Solidity's `int160` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 160 bits\r\n     */\r\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\r\n        downcasted = int160(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(160, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int152 from int256, reverting on\r\n     * overflow (when the input is less than smallest int152 or\r\n     * greater than largest int152).\r\n     *\r\n     * Counterpart to Solidity's `int152` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 152 bits\r\n     */\r\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\r\n        downcasted = int152(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(152, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int144 from int256, reverting on\r\n     * overflow (when the input is less than smallest int144 or\r\n     * greater than largest int144).\r\n     *\r\n     * Counterpart to Solidity's `int144` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 144 bits\r\n     */\r\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\r\n        downcasted = int144(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(144, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int136 from int256, reverting on\r\n     * overflow (when the input is less than smallest int136 or\r\n     * greater than largest int136).\r\n     *\r\n     * Counterpart to Solidity's `int136` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 136 bits\r\n     */\r\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\r\n        downcasted = int136(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(136, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int128 from int256, reverting on\r\n     * overflow (when the input is less than smallest int128 or\r\n     * greater than largest int128).\r\n     *\r\n     * Counterpart to Solidity's `int128` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 128 bits\r\n     */\r\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\r\n        downcasted = int128(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(128, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int120 from int256, reverting on\r\n     * overflow (when the input is less than smallest int120 or\r\n     * greater than largest int120).\r\n     *\r\n     * Counterpart to Solidity's `int120` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 120 bits\r\n     */\r\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\r\n        downcasted = int120(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(120, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int112 from int256, reverting on\r\n     * overflow (when the input is less than smallest int112 or\r\n     * greater than largest int112).\r\n     *\r\n     * Counterpart to Solidity's `int112` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 112 bits\r\n     */\r\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\r\n        downcasted = int112(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(112, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int104 from int256, reverting on\r\n     * overflow (when the input is less than smallest int104 or\r\n     * greater than largest int104).\r\n     *\r\n     * Counterpart to Solidity's `int104` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 104 bits\r\n     */\r\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\r\n        downcasted = int104(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(104, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int96 from int256, reverting on\r\n     * overflow (when the input is less than smallest int96 or\r\n     * greater than largest int96).\r\n     *\r\n     * Counterpart to Solidity's `int96` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 96 bits\r\n     */\r\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\r\n        downcasted = int96(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(96, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int88 from int256, reverting on\r\n     * overflow (when the input is less than smallest int88 or\r\n     * greater than largest int88).\r\n     *\r\n     * Counterpart to Solidity's `int88` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 88 bits\r\n     */\r\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\r\n        downcasted = int88(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(88, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int80 from int256, reverting on\r\n     * overflow (when the input is less than smallest int80 or\r\n     * greater than largest int80).\r\n     *\r\n     * Counterpart to Solidity's `int80` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 80 bits\r\n     */\r\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\r\n        downcasted = int80(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(80, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int72 from int256, reverting on\r\n     * overflow (when the input is less than smallest int72 or\r\n     * greater than largest int72).\r\n     *\r\n     * Counterpart to Solidity's `int72` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 72 bits\r\n     */\r\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\r\n        downcasted = int72(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(72, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int64 from int256, reverting on\r\n     * overflow (when the input is less than smallest int64 or\r\n     * greater than largest int64).\r\n     *\r\n     * Counterpart to Solidity's `int64` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 64 bits\r\n     */\r\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\r\n        downcasted = int64(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(64, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int56 from int256, reverting on\r\n     * overflow (when the input is less than smallest int56 or\r\n     * greater than largest int56).\r\n     *\r\n     * Counterpart to Solidity's `int56` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 56 bits\r\n     */\r\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\r\n        downcasted = int56(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(56, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int48 from int256, reverting on\r\n     * overflow (when the input is less than smallest int48 or\r\n     * greater than largest int48).\r\n     *\r\n     * Counterpart to Solidity's `int48` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 48 bits\r\n     */\r\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\r\n        downcasted = int48(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(48, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int40 from int256, reverting on\r\n     * overflow (when the input is less than smallest int40 or\r\n     * greater than largest int40).\r\n     *\r\n     * Counterpart to Solidity's `int40` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 40 bits\r\n     */\r\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\r\n        downcasted = int40(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(40, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int32 from int256, reverting on\r\n     * overflow (when the input is less than smallest int32 or\r\n     * greater than largest int32).\r\n     *\r\n     * Counterpart to Solidity's `int32` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 32 bits\r\n     */\r\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\r\n        downcasted = int32(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(32, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int24 from int256, reverting on\r\n     * overflow (when the input is less than smallest int24 or\r\n     * greater than largest int24).\r\n     *\r\n     * Counterpart to Solidity's `int24` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 24 bits\r\n     */\r\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\r\n        downcasted = int24(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(24, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int16 from int256, reverting on\r\n     * overflow (when the input is less than smallest int16 or\r\n     * greater than largest int16).\r\n     *\r\n     * Counterpart to Solidity's `int16` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 16 bits\r\n     */\r\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\r\n        downcasted = int16(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(16, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the downcasted int8 from int256, reverting on\r\n     * overflow (when the input is less than smallest int8 or\r\n     * greater than largest int8).\r\n     *\r\n     * Counterpart to Solidity's `int8` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must fit into 8 bits\r\n     */\r\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\r\n        downcasted = int8(value);\r\n        if (downcasted != value) {\r\n            revert SafeCastOverflowedIntDowncast(8, value);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Converts an unsigned uint256 into a signed int256.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - input must be less than or equal to maxInt256.\r\n     */\r\n    function toInt256(uint256 value) internal pure returns (int256) {\r\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\r\n        if (value > uint256(type(int256).max)) {\r\n            revert SafeCastOverflowedUintToInt(value);\r\n        }\r\n        return int256(value);\r\n    }\r\n\r\n    /**\r\n     * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\r\n     */\r\n    function toUint(bool b) internal pure returns (uint256 u) {\r\n        assembly (\"memory-safe\") {\r\n            u := iszero(iszero(b))\r\n        }\r\n    }\r\n}\r\n"},"@openzeppelin/contracts/utils/math/SignedMath.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\nimport {SafeCast} from \"./SafeCast.sol\";\r\n\r\n/**\r\n * @dev Standard signed math utilities missing in the Solidity language.\r\n */\r\nlibrary SignedMath {\r\n    /**\r\n     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.\r\n     *\r\n     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.\r\n     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute\r\n     * one branch when needed, making this function more expensive.\r\n     */\r\n    function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {\r\n        unchecked {\r\n            // branchless ternary works because:\r\n            // b ^ (a ^ b) == a\r\n            // b ^ 0 == b\r\n            return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the largest of two signed numbers.\r\n     */\r\n    function max(int256 a, int256 b) internal pure returns (int256) {\r\n        return ternary(a > b, a, b);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the smallest of two signed numbers.\r\n     */\r\n    function min(int256 a, int256 b) internal pure returns (int256) {\r\n        return ternary(a < b, a, b);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the average of two signed numbers without overflow.\r\n     * The result is rounded towards zero.\r\n     */\r\n    function average(int256 a, int256 b) internal pure returns (int256) {\r\n        // Formula from the book \"Hacker's Delight\"\r\n        int256 x = (a & b) + ((a ^ b) >> 1);\r\n        return x + (int256(uint256(x) >> 255) & (a ^ b));\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the absolute unsigned value of a signed value.\r\n     */\r\n    function abs(int256 n) internal pure returns (uint256) {\r\n        unchecked {\r\n            // Formula from the \"Bit Twiddling Hacks\" by Sean Eron Anderson.\r\n            // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,\r\n            // taking advantage of the most significant (or \"sign\" bit) in two's complement representation.\r\n            // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,\r\n            // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).\r\n            int256 mask = n >> 255;\r\n\r\n            // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.\r\n            return uint256((n + mask) ^ mask);\r\n        }\r\n    }\r\n}\r\n"},"@openzeppelin/contracts/utils/introspection/ERC165.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\nimport {IERC165} from \"./IERC165.sol\";\r\n\r\n/**\r\n * @dev Implementation of the {IERC165} interface.\r\n *\r\n * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check\r\n * for the additional interface id that will be supported. For example:\r\n *\r\n * ```solidity\r\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\r\n *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\r\n * }\r\n * ```\r\n */\r\nabstract contract ERC165 is IERC165 {\r\n    /**\r\n     * @dev See {IERC165-supportsInterface}.\r\n     */\r\n    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {\r\n        return interfaceId == type(IERC165).interfaceId;\r\n    }\r\n}\r\n"},"@openzeppelin/contracts/interfaces/IERC2981.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC2981.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\r\n\r\n/**\r\n * @dev Interface for the NFT Royalty Standard.\r\n *\r\n * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal\r\n * support for royalty payments across all NFT marketplaces and ecosystem participants.\r\n */\r\ninterface IERC2981 is IERC165 {\r\n    /**\r\n     * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of\r\n     * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.\r\n     *\r\n     * NOTE: ERC-2981 allows setting the royalty to 100% of the price. In that case all the price would be sent to the\r\n     * royalty receiver and 0 tokens to the seller. Contracts dealing with royalty should consider empty transfers.\r\n     */\r\n    function royaltyInfo(\r\n        uint256 tokenId,\r\n        uint256 salePrice\r\n    ) external view returns (address receiver, uint256 royaltyAmount);\r\n}\r\n"},"@openzeppelin/contracts/utils/ReentrancyGuard.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)\r\n\r\npragma solidity ^0.8.20;\r\n\r\n/**\r\n * @dev Contract module that helps prevent reentrant calls to a function.\r\n *\r\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\r\n * available, which can be applied to functions to make sure there are no nested\r\n * (reentrant) calls to them.\r\n *\r\n * Note that because there is a single `nonReentrant` guard, functions marked as\r\n * `nonReentrant` may not call one another. This can be worked around by making\r\n * those functions `private`, and then adding `external` `nonReentrant` entry\r\n * points to them.\r\n *\r\n * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,\r\n * consider using {ReentrancyGuardTransient} instead.\r\n *\r\n * TIP: If you would like to learn more about reentrancy and alternative ways\r\n * to protect against it, check out our blog post\r\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\r\n */\r\nabstract contract ReentrancyGuard {\r\n    // Booleans are more expensive than uint256 or any type that takes up a full\r\n    // word because each write operation emits an extra SLOAD to first read the\r\n    // slot's contents, replace the bits taken up by the boolean, and then write\r\n    // back. This is the compiler's defense against contract upgrades and\r\n    // pointer aliasing, and it cannot be disabled.\r\n\r\n    // The values being non-zero value makes deployment a bit more expensive,\r\n    // but in exchange the refund on every call to nonReentrant will be lower in\r\n    // amount. Since refunds are capped to a percentage of the total\r\n    // transaction's gas, it is best to keep them low in cases like this one, to\r\n    // increase the likelihood of the full refund coming into effect.\r\n    uint256 private constant NOT_ENTERED = 1;\r\n    uint256 private constant ENTERED = 2;\r\n\r\n    uint256 private _status;\r\n\r\n    /**\r\n     * @dev Unauthorized reentrant call.\r\n     */\r\n    error ReentrancyGuardReentrantCall();\r\n\r\n    constructor() {\r\n        _status = NOT_ENTERED;\r\n    }\r\n\r\n    /**\r\n     * @dev Prevents a contract from calling itself, directly or indirectly.\r\n     * Calling a `nonReentrant` function from another `nonReentrant`\r\n     * function is not supported. It is possible to prevent this from happening\r\n     * by making the `nonReentrant` function external, and making it call a\r\n     * `private` function that does the actual work.\r\n     */\r\n    modifier nonReentrant() {\r\n        _nonReentrantBefore();\r\n        _;\r\n        _nonReentrantAfter();\r\n    }\r\n\r\n    function _nonReentrantBefore() private {\r\n        // On the first call to nonReentrant, _status will be NOT_ENTERED\r\n        if (_status == ENTERED) {\r\n            revert ReentrancyGuardReentrantCall();\r\n        }\r\n\r\n        // Any calls to nonReentrant after this point will fail\r\n        _status = ENTERED;\r\n    }\r\n\r\n    function _nonReentrantAfter() private {\r\n        // By storing the original value once again, a refund is triggered (see\r\n        // https://eips.ethereum.org/EIPS/eip-2200)\r\n        _status = NOT_ENTERED;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\r\n     * `nonReentrant` function in the call stack.\r\n     */\r\n    function _reentrancyGuardEntered() internal view returns (bool) {\r\n        return _status == ENTERED;\r\n    }\r\n}\r\n"},"src/libraries/HahaConstants.sol":{"content":"// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.28;\r\n\r\nlibrary HahaConstants {\r\n    uint256 internal constant MIN_PUBLIC_LENGTH = 3;\r\n\r\n    uint256 internal constant MAX_LABEL_LENGTH = 32;\r\n\r\n    uint256 internal constant COOLDOWN = 3600;\r\n\r\n    uint256 internal constant FEE_BPS = 100;\r\n\r\n    uint256 internal constant BPS_DENOMINATOR = 10_000;\r\n\r\n    uint256 internal constant MINT_REWARDS_PER_DAY = 3;\r\n\r\n    uint256 internal constant MAX_POINT_PARAM = 999_999_999;\r\n\r\n    uint256 internal constant MAX_TEXT_KEYS = 16;\r\n\r\n    uint256 internal constant MAX_TEXT_KEY_LENGTH = 64;\r\n\r\n    uint256 internal constant MAX_TEXT_VALUE_LENGTH = 1024;\r\n\r\n    uint256 internal constant MAX_REVIEW_LENGTH = 140;\r\n\r\n    uint256 internal constant MAX_AGENT_URI_LENGTH = 2048;\r\n\r\n    uint256 internal constant BANNED_COUNT = 208;\r\n\r\n    uint256 internal constant RESERVED_COUNT = 61;\r\n\r\n    uint8 internal constant TLD_HAHA = 0;\r\n\r\n    uint8 internal constant TLD_MEME = 1;\r\n\r\n    bytes32 internal constant REASON_CHECKIN = \"CHECKIN\";\r\n\r\n    bytes32 internal constant REASON_MINT = \"MINT\";\r\n\r\n    bytes32 internal constant REASON_FOLLOW = \"FOLLOW\";\r\n\r\n    bytes32 internal constant REASON_RETWEET = \"RETWEET\";\r\n\r\n    bytes32 internal constant REASON_LIKE = \"LIKE\";\r\n\r\n    bytes32 internal constant REASON_COMMENT = \"COMMENT\";\r\n\r\n\r\n    uint256 internal constant MAX_EARNER_POINTS = 100;\r\n\r\n    uint64 internal constant MAX_PER_USER_DAILY = 50;\r\n\r\n    uint256 internal constant MAX_GLOBAL_DAILY_POINTS = 1_000_000;\r\n\r\n    uint256 internal constant MAX_MODULES = 32;\r\n\r\n    uint256 internal constant MAX_SPEND_USER_DAILY = 1_000_000_000;\r\n\r\n    uint256 internal constant MAX_SPEND_GLOBAL_DAILY = 10_000_000_000;\r\n\r\n    uint64 internal constant GAME_ROUNDS_PER_DAY = 3;\r\n\r\n    uint256 internal constant MAX_GAME_SCORE_PER_ROUND = 1000;\r\n\r\n    uint256 internal constant MAX_AGENT_OPERATORS = 8;\r\n\r\n\r\n    uint256 internal constant SUGGESTED_REVIEW_POINTS = 5;\r\n\r\n    uint256 internal constant SUGGESTED_ACTIVATE_POINTS = 20;\r\n\r\n    uint64 internal constant REVIEW_GIVE_DAILY_CAP = 5;\r\n\r\n    uint64 internal constant REVIEW_RECEIVE_DAILY_CAP = 5;\r\n\r\n    uint256 internal constant REVIEW_GLOBAL_DAILY_POINTS = 50_000;\r\n\r\n    uint256 internal constant ACTIVATE_GLOBAL_DAILY_POINTS = 100_000;\r\n\r\n    uint256 internal constant GAME_GLOBAL_DAILY_POINTS = 50_000;\r\n\r\n    bytes32 internal constant ACTION_REVIEW_GIVE = \"REVIEW_GIVE\";\r\n\r\n    bytes32 internal constant ACTION_REVIEW_RECEIVE = \"REVIEW_RECEIVE\";\r\n\r\n    bytes32 internal constant ACTION_ACTIVATE = \"ACTIVATE\";\r\n\r\n    bytes32 internal constant ACTIVATE_ONCE = \"ACTIVATE_ONCE\";\r\n\r\n    uint256 internal constant MAX_STATUS_ACTIONS = 16;\r\n\r\n    function tldString(uint8 tld) internal pure returns (string memory) {\r\n        if (tld == TLD_HAHA) return \"haha\";\r\n        if (tld == TLD_MEME) return \"meme\";\r\n        return \"\";\r\n    }\r\n\r\n    function isBuiltinReason(bytes32 actionId) internal pure returns (bool) {\r\n        return actionId == REASON_CHECKIN || actionId == REASON_MINT || actionId == REASON_FOLLOW\r\n            || actionId == REASON_LIKE || actionId == REASON_RETWEET || actionId == REASON_COMMENT;\r\n    }\r\n}\r\n"},"src/libraries/HahaNamehash.sol":{"content":"// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.28;\r\n\r\nlibrary HahaNamehash {\r\n    bytes32 internal constant ROOT_NODE = bytes32(0);\r\n\r\n    bytes32 internal constant HAHA_NODE = 0xaa5a3a58f7c8841455eecaa0c6a6a0b40ace5681fbb31361a0d45b168179128f;\r\n\r\n    bytes32 internal constant MEME_NODE = 0x74df4ab2564a9f9bb6d4b6b77bf4fc02ac80f07bd9e1776d3967578b3fc36be4;\r\n\r\n    bytes32 private constant _HAHA_CHECK =\r\n        keccak256(abi.encodePacked(ROOT_NODE, keccak256(bytes(\"haha\"))));\r\n    bytes32 private constant _MEME_CHECK =\r\n        keccak256(abi.encodePacked(ROOT_NODE, keccak256(bytes(\"meme\"))));\r\n\r\n    function labelhash(string memory label) internal pure returns (bytes32) {\r\n        return keccak256(bytes(label));\r\n    }\r\n\r\n    function namehash(bytes32 parentNode, bytes32 labelHash) internal pure returns (bytes32) {\r\n        return keccak256(abi.encodePacked(parentNode, labelHash));\r\n    }\r\n\r\n    function tldNode(uint8 tld) internal pure returns (bytes32) {\r\n        if (tld == 0) return HAHA_NODE;\r\n        if (tld == 1) return MEME_NODE;\r\n        return bytes32(0);\r\n    }\r\n\r\n    function isValidLabel(string memory label) internal pure returns (bool) {\r\n        bytes memory b = bytes(label);\r\n        if (b.length == 0) return false;\r\n        unchecked {\r\n            for (uint256 i = 0; i < b.length; ++i) {\r\n                bytes1 c = b[i];\r\n                bool lower = (c >= 0x61 && c <= 0x7a);\r\n                bool digit = (c >= 0x30 && c <= 0x39);\r\n                if (!lower && !digit) return false;\r\n            }\r\n        }\r\n        return true;\r\n    }\r\n\r\n    function isLengthInRange(string memory label, uint256 minLen, uint256 maxLen)\r\n        internal\r\n        pure\r\n        returns (bool)\r\n    {\r\n        uint256 n = bytes(label).length;\r\n        return n >= minLen && n <= maxLen;\r\n    }\r\n\r\n    function fullName(string memory label, uint8 tld) internal pure returns (string memory) {\r\n        return string.concat(label, tld == 0 ? \".haha\" : \".meme\");\r\n    }\r\n}\r\n"},"src/libraries/HahaAiIdentity.sol":{"content":"// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.28;\r\n\r\nimport {IBinanceAiRegistry} from \"../interfaces/IBinanceAiRegistry.sol\";\r\n\r\nlibrary HahaAiIdentity {\r\n    struct Result {\r\n        bytes32 aiId;\r\n        string handle;\r\n        bool ok;\r\n    }\r\n\r\n    function aiIdentityOf(IBinanceAiRegistry aiRegistry, address user)\r\n        internal\r\n        view\r\n        returns (Result memory)\r\n    {\r\n        if (user == address(0) || address(aiRegistry).code.length == 0) {\r\n            return Result({aiId: bytes32(0), handle: \"\", ok: false});\r\n        }\r\n\r\n        string memory handle;\r\n        try aiRegistry.handleOf(user) returns (string memory h) {\r\n            handle = h;\r\n        } catch {\r\n            return Result({aiId: bytes32(0), handle: \"\", ok: false});\r\n        }\r\n        bytes memory handleBytes = bytes(handle);\r\n        if (handleBytes.length == 0) {\r\n            return Result({aiId: bytes32(0), handle: \"\", ok: false});\r\n        }\r\n\r\n        try aiRegistry.ownerOfHandle(handle) returns (address hOwner) {\r\n            if (hOwner != user) {\r\n                return Result({aiId: bytes32(0), handle: handle, ok: false});\r\n            }\r\n        } catch {\r\n            return Result({aiId: bytes32(0), handle: handle, ok: false});\r\n        }\r\n\r\n        bytes32 aiId = keccak256(handleBytes);\r\n\r\n        try aiRegistry.ownerOf(uint256(aiId)) returns (address tOwner) {\r\n            if (tOwner != user) {\r\n                return Result({aiId: aiId, handle: handle, ok: false});\r\n            }\r\n        } catch {\r\n            return Result({aiId: aiId, handle: handle, ok: false});\r\n        }\r\n\r\n        return Result({aiId: aiId, handle: handle, ok: true});\r\n    }\r\n}\r\n"},"src/interfaces/IBinanceAiRegistry.sol":{"content":"// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.28;\r\n\r\ninterface IBinanceAiRegistry {\r\n    function handleOf(address owner) external view returns (string memory handle);\r\n\r\n    function ownerOfHandle(string calldata handle) external view returns (address);\r\n\r\n    function ownerOf(uint256 tokenId) external view returns (address);\r\n\r\n    function balanceOf(address owner) external view returns (uint256);\r\n}\r\n"},"src/interfaces/IHahaRegistry.sol":{"content":"// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.28;\r\n\r\ninterface IHahaRegistry {\r\n    function owner(bytes32 node) external view returns (address);\r\n\r\n    function resolver(bytes32 node) external view returns (address);\r\n\r\n    function recordExists(bytes32 node) external view returns (bool);\r\n\r\n    function bootstrap() external;\r\n\r\n    function createName(bytes32 tldNode, bytes32 labelhash, address nameOwner) external;\r\n\r\n    function syncOwner(bytes32 node, address nameOwner) external;\r\n}\r\n"},"src/interfaces/IHahaResolver.sol":{"content":"// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.28;\r\n\r\ninterface IHahaResolver {\r\n    function addr(bytes32 node) external view returns (address);\r\n\r\n    function setAddr(bytes32 node, address a) external;\r\n\r\n    function text(bytes32 node, string calldata key) external view returns (string memory);\r\n\r\n    function setText(bytes32 node, string calldata key, string calldata value) external;\r\n\r\n    function clearRecords(bytes32 node) external;\r\n\r\n    function setPrimaryName(string calldata label, uint8 tld) external;\r\n\r\n    function clearPrimaryName() external;\r\n\r\n    function primaryNode(address user) external view returns (bytes32);\r\n\r\n    function primaryName(address user) external view returns (string memory fullName);\r\n}\r\n"},"src/interfaces/IHahaProtocol.sol":{"content":"// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.28;\r\n\r\ninterface IHahaRegistrar {\r\n    function nameParts(uint256 tokenId) external view returns (string memory label, uint8 tld);\r\n\r\n    function isMinted(bytes32 node) external view returns (bool);\r\n\r\n    function balanceOf(address owner) external view returns (uint256);\r\n}\r\n\r\ninterface IHahaMetadata {\r\n    function build(string calldata label, uint8 tld) external view returns (string memory);\r\n}\r\n\r\ninterface IHahaNamePolicy {\r\n    function isBlacklisted(string calldata label) external view returns (bool);\r\n\r\n    function isReserved(string calldata label) external view returns (bool);\r\n}\r\n\r\ninterface IHahaPoints {\r\n    function creditMintReward(address user, bytes32 aiId) external returns (uint256 awarded);\r\n\r\n    function balanceOf(bytes32 aiId) external view returns (uint256);\r\n\r\n    function earn(bytes32 actionId, address user, bytes32 uniqueKey) external returns (uint256 awarded);\r\n}\r\n\r\ninterface IHahaGame {\r\n    function pointsContract() external view returns (address);\r\n\r\n    function gameId() external view returns (bytes32);\r\n\r\n    function scoreOf(uint256 sessionId) external view returns (uint256 score, bool settled);\r\n\r\n    function start() external returns (uint256 sessionId);\r\n\r\n    function claim(uint256 sessionId) external returns (uint256 awarded);\r\n}\r\n\r\ninterface IHahaAgentIdentity {\r\n    function deactivate(uint256 nameTokenId) external;\r\n\r\n    function agentOfName(uint256 nameTokenId) external view returns (uint256);\r\n\r\n    function ownerOf(uint256 agentId) external view returns (address);\r\n\r\n    function isActive(uint256 agentId) external view returns (bool);\r\n\r\n    function registrar() external view returns (address);\r\n\r\n    function isAuthorized(uint256 agentId, address account) external view returns (bool);\r\n\r\n    function isAgentOperator(uint256 agentId, address operator) external view returns (bool);\r\n\r\n    function generationOf(uint256 agentId) external view returns (uint64);\r\n\r\n    function nameGeneration(uint256 nameTokenId) external view returns (uint64);\r\n\r\n    function operatorAiIdOf(uint256 agentId) external view returns (bytes32);\r\n}\r\n"}},"abi":[{"type":"constructor","inputs":[{"name":"cfg","type":"bytes","internalType":"bytes"}],"stateMutability":"nonpayable"},{"name":"AiRequired","type":"error","inputs":[]},{"name":"Blacklisted","type":"error","inputs":[]},{"name":"CooldownActive","type":"error","inputs":[{"name":"readyAt","type":"uint256","internalType":"uint256"}]},{"name":"ERC721IncorrectOwner","type":"error","inputs":[{"name":"sender","type":"address","internalType":"address"},{"name":"tokenId","type":"uint256","internalType":"uint256"},{"name":"owner","type":"address","internalType":"address"}]},{"name":"ERC721InsufficientApproval","type":"error","inputs":[{"name":"operator","type":"address","internalType":"address"},{"name":"tokenId","type":"uint256","internalType":"uint256"}]},{"name":"ERC721InvalidApprover","type":"error","inputs":[{"name":"approver","type":"address","internalType":"address"}]},{"name":"ERC721InvalidOperator","type":"error","inputs":[{"name":"operator","type":"address","internalType":"address"}]},{"name":"ERC721InvalidOwner","type":"error","inputs":[{"name":"owner","type":"address","internalType":"address"}]},{"name":"ERC721InvalidReceiver","type":"error","inputs":[{"name":"receiver","type":"address","internalType":"address"}]},{"name":"ERC721InvalidSender","type":"error","inputs":[{"name":"sender","type":"address","internalType":"address"}]},{"name":"ERC721NonexistentToken","type":"error","inputs":[{"name":"tokenId","type":"uint256","internalType":"uint256"}]},{"name":"InvalidCharset","type":"error","inputs":[]},{"name":"InvalidTld","type":"error","inputs":[{"name":"tld","type":"uint8","internalType":"uint8"}]},{"name":"LabelTooLong","type":"error","inputs":[{"name":"length","type":"uint256","internalType":"uint256"},{"name":"maxLength","type":"uint256","internalType":"uint256"}]},{"name":"LabelTooShort","type":"error","inputs":[{"name":"length","type":"uint256","internalType":"uint256"},{"name":"minLength","type":"uint256","internalType":"uint256"}]},{"name":"NameTaken","type":"error","inputs":[]},{"name":"NotAdmin","type":"error","inputs":[]},{"name":"NotReserved","type":"error","inputs":[]},{"name":"ReentrancyGuardReentrantCall","type":"error","inputs":[]},{"name":"ReservedName","type":"error","inputs":[]},{"name":"ZeroAddress","type":"error","inputs":[]},{"name":"Approval","type":"event","inputs":[{"name":"owner","type":"address","indexed":true,"internalType":"address"},{"name":"approved","type":"address","indexed":true,"internalType":"address"},{"name":"tokenId","type":"uint256","indexed":true,"internalType":"uint256"}],"anonymous":false},{"name":"ApprovalForAll","type":"event","inputs":[{"name":"owner","type":"address","indexed":true,"internalType":"address"},{"name":"operator","type":"address","indexed":true,"internalType":"address"},{"name":"approved","type":"bool","indexed":false,"internalType":"bool"}],"anonymous":false},{"name":"NameMinted","type":"event","inputs":[{"name":"tokenId","type":"uint256","indexed":true,"internalType":"uint256"},{"name":"owner","type":"address","indexed":true,"internalType":"address"},{"name":"tld","type":"uint8","indexed":false,"internalType":"uint8"},{"name":"aiId","type":"bytes32","indexed":true,"internalType":"bytes32"},{"name":"label","type":"string","indexed":false,"internalType":"string"},{"name":"reservedMint","type":"bool","indexed":false,"internalType":"bool"}],"anonymous":false},{"name":"Transfer","type":"event","inputs":[{"name":"from","type":"address","indexed":true,"internalType":"address"},{"name":"to","type":"address","indexed":true,"internalType":"address"},{"name":"tokenId","type":"uint256","indexed":true,"internalType":"uint256"}],"anonymous":false},{"name":"admin","type":"function","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"adminMint","type":"function","inputs":[{"name":"label","type":"string","internalType":"string"},{"name":"tld","type":"uint8","internalType":"uint8"},{"name":"to","type":"address","internalType":"address"}],"outputs":[],"stateMutability":"nonpayable"},{"name":"aiRegistry","type":"function","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"approve","type":"function","inputs":[{"name":"to","type":"address","internalType":"address"},{"name":"tokenId","type":"uint256","internalType":"uint256"}],"outputs":[],"stateMutability":"nonpayable"},{"name":"available","type":"function","inputs":[{"name":"label","type":"string","internalType":"string"},{"name":"tld","type":"uint8","internalType":"uint8"}],"outputs":[{"name":"","type":"bool","internalType":"bool"}],"stateMutability":"view"},{"name":"balanceOf","type":"function","inputs":[{"name":"owner","type":"address","internalType":"address"}],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"name":"feeReceiver","type":"function","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"getApproved","type":"function","inputs":[{"name":"tokenId","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"identity","type":"function","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"isApprovedForAll","type":"function","inputs":[{"name":"owner","type":"address","internalType":"address"},{"name":"operator","type":"address","internalType":"address"}],"outputs":[{"name":"","type":"bool","internalType":"bool"}],"stateMutability":"view"},{"name":"isMinted","type":"function","inputs":[{"name":"node","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"bool","internalType":"bool"}],"stateMutability":"view"},{"name":"lastMintAt","type":"function","inputs":[{"name":"aiId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"name":"metadata","type":"function","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"name","type":"function","inputs":[],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"},{"name":"nameParts","type":"function","inputs":[{"name":"tokenId","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"label","type":"string","internalType":"string"},{"name":"tld","type":"uint8","internalType":"uint8"}],"stateMutability":"view"},{"name":"nextMintAt","type":"function","inputs":[{"name":"aiId","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"name":"nodeOf","type":"function","inputs":[{"name":"label","type":"string","internalType":"string"},{"name":"tld","type":"uint8","internalType":"uint8"}],"outputs":[{"name":"","type":"bytes32","internalType":"bytes32"}],"stateMutability":"pure"},{"name":"ownerOf","type":"function","inputs":[{"name":"tokenId","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"points","type":"function","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"policy","type":"function","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"register","type":"function","inputs":[{"name":"label","type":"string","internalType":"string"},{"name":"tld","type":"uint8","internalType":"uint8"}],"outputs":[],"stateMutability":"nonpayable"},{"name":"registry","type":"function","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"resolver","type":"function","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"name":"royaltyInfo","type":"function","inputs":[{"name":"","type":"uint256","internalType":"uint256"},{"name":"salePrice","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"","type":"address","internalType":"address"},{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"name":"safeTransferFrom","type":"function","inputs":[{"name":"from","type":"address","internalType":"address"},{"name":"to","type":"address","internalType":"address"},{"name":"tokenId","type":"uint256","internalType":"uint256"}],"outputs":[],"stateMutability":"nonpayable"},{"name":"safeTransferFrom","type":"function","inputs":[{"name":"from","type":"address","internalType":"address"},{"name":"to","type":"address","internalType":"address"},{"name":"tokenId","type":"uint256","internalType":"uint256"},{"name":"data","type":"bytes","internalType":"bytes"}],"outputs":[],"stateMutability":"nonpayable"},{"name":"setApprovalForAll","type":"function","inputs":[{"name":"operator","type":"address","internalType":"address"},{"name":"approved","type":"bool","internalType":"bool"}],"outputs":[],"stateMutability":"nonpayable"},{"name":"supportsInterface","type":"function","inputs":[{"name":"interfaceId","type":"bytes4","internalType":"bytes4"}],"outputs":[{"name":"","type":"bool","internalType":"bool"}],"stateMutability":"view"},{"name":"symbol","type":"function","inputs":[],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"},{"name":"tokenURI","type":"function","inputs":[{"name":"tokenId","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"},{"name":"transferFrom","type":"function","inputs":[{"name":"from","type":"address","internalType":"address"},{"name":"to","type":"address","internalType":"address"},{"name":"tokenId","type":"uint256","internalType":"uint256"}],"outputs":[],"stateMutability":"nonpayable"}],"matchId":"59662440","creationMatch":"match","runtimeMatch":"match","verifiedAt":"2026-11-21T13:40:13Z","match":"match","chainId":"56","address":"0x43426E37a31AafDaba851858e34B81DC300650F8"}