{ "language": "Solidity", "settings": { "evmVersion": "london", "libraries": {}, "metadata": { "bytecodeHash": "ipfs", "useLiteralContent": true }, "optimizer": { "enabled": true, "runs": 99999 }, "remappings": [], "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } }, "sources": { "@openzeppelin/contracts/utils/Address.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n *\n * _Available since v4.8._\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n if (success) {\n if (returndata.length == 0) {\n // only check isContract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n require(isContract(target), \"Address: call to non-contract\");\n }\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason or using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n function _revert(bytes memory returndata, string memory errorMessage) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n}\n" }, "@openzeppelin/contracts/utils/Context.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n" }, "@openzeppelin/contracts/utils/StorageSlot.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC1967 implementation slot:\n * ```\n * contract ERC1967 {\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(Address.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n}\n" }, "contracts/introspection/interfaces/IERC165.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\n/// @title ERC165 Interface Detection Standard.\n/// @dev See https://eips.ethereum.org/EIPS/eip-165.\n/// @dev Note: The ERC-165 identifier for this interface is 0x01ffc9a7.\ninterface IERC165 {\n /// @notice Returns whether this contract implements a given interface.\n /// @dev Note: This function call must use less than 30 000 gas.\n /// @param interfaceId the interface identifier to test.\n /// @return supported True if the interface is supported, false if `interfaceId` is `0xffffffff` or if the interface is not supported.\n function supportsInterface(bytes4 interfaceId) external view returns (bool supported);\n}\n" }, "contracts/introspection/libraries/InterfaceDetectionStorage.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\nimport {IERC165} from \"./../interfaces/IERC165.sol\";\n\nlibrary InterfaceDetectionStorage {\n struct Layout {\n mapping(bytes4 => bool) supportedInterfaces;\n }\n\n bytes32 internal constant LAYOUT_STORAGE_SLOT = bytes32(uint256(keccak256(\"animoca.core.introspection.InterfaceDetection.storage\")) - 1);\n\n bytes4 internal constant ILLEGAL_INTERFACE_ID = 0xffffffff;\n\n /// @notice Sets or unsets an ERC165 interface.\n /// @dev Reverts if `interfaceId` is `0xffffffff`.\n /// @param interfaceId the interface identifier.\n /// @param supported True to set the interface, false to unset it.\n function setSupportedInterface(Layout storage s, bytes4 interfaceId, bool supported) internal {\n require(interfaceId != ILLEGAL_INTERFACE_ID, \"InterfaceDetection: wrong value\");\n s.supportedInterfaces[interfaceId] = supported;\n }\n\n /// @notice Returns whether this contract implements a given interface.\n /// @dev Note: This function call must use less than 30 000 gas.\n /// @param interfaceId The interface identifier to test.\n /// @return supported True if the interface is supported, false if `interfaceId` is `0xffffffff` or if the interface is not supported.\n function supportsInterface(Layout storage s, bytes4 interfaceId) internal view returns (bool supported) {\n if (interfaceId == ILLEGAL_INTERFACE_ID) {\n return false;\n }\n if (interfaceId == type(IERC165).interfaceId) {\n return true;\n }\n return s.supportedInterfaces[interfaceId];\n }\n\n function layout() internal pure returns (Layout storage s) {\n bytes32 position = LAYOUT_STORAGE_SLOT;\n assembly {\n s.slot := position\n }\n }\n}\n" }, "contracts/metatx/base/ForwarderRegistryContextBase.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\nimport {IForwarderRegistry} from \"./../interfaces/IForwarderRegistry.sol\";\nimport {ERC2771Calldata} from \"./../libraries/ERC2771Calldata.sol\";\n\n/// @title Meta-Transactions Forwarder Registry Context (proxiable version).\n/// @dev This contract is to be used via inheritance in a proxied implementation.\n/// @dev Derived from https://github.com/wighawag/universal-forwarder (MIT licence)\nabstract contract ForwarderRegistryContextBase {\n IForwarderRegistry internal immutable _forwarderRegistry;\n\n constructor(IForwarderRegistry forwarderRegistry) {\n _forwarderRegistry = forwarderRegistry;\n }\n\n /// @notice Returns the message sender depending on the ForwarderRegistry-based meta-transaction context.\n function _msgSender() internal view virtual returns (address) {\n // Optimised path in case of an EOA-initiated direct tx to the contract or a call from a contract not complying with EIP-2771\n // solhint-disable-next-line avoid-tx-origin\n if (msg.sender == tx.origin || msg.data.length < 24) {\n return msg.sender;\n }\n\n address sender = ERC2771Calldata.msgSender();\n\n // Return the EIP-2771 calldata-appended sender address if the message was forwarded by the ForwarderRegistry or an approved forwarder\n if (msg.sender == address(_forwarderRegistry) || _forwarderRegistry.isApprovedForwarder(sender, msg.sender)) {\n return sender;\n }\n\n return msg.sender;\n }\n\n /// @notice Returns the message data depending on the ForwarderRegistry-based meta-transaction context.\n function _msgData() internal view virtual returns (bytes calldata) {\n // Optimised path in case of an EOA-initiated direct tx to the contract or a call from a contract not complying with EIP-2771\n // solhint-disable-next-line avoid-tx-origin\n if (msg.sender == tx.origin || msg.data.length < 24) {\n return msg.data;\n }\n\n // Return the EIP-2771 calldata (minus the appended sender) if the message was forwarded by the ForwarderRegistry or an approved forwarder\n if (msg.sender == address(_forwarderRegistry) || _forwarderRegistry.isApprovedForwarder(ERC2771Calldata.msgSender(), msg.sender)) {\n return ERC2771Calldata.msgData();\n }\n\n return msg.data;\n }\n}\n" }, "contracts/metatx/interfaces/IForwarderRegistry.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\n/// @title Universal Meta-Transactions Forwarder Registry.\n/// @dev Derived from https://github.com/wighawag/universal-forwarder (MIT licence)\ninterface IForwarderRegistry {\n /// @notice Checks whether an account is as an approved meta-transaction forwarder for a sender account.\n /// @param sender The sender account.\n /// @param forwarder The forwarder account.\n /// @return isApproved True if `forwarder` is an approved meta-transaction forwarder for `sender`, false otherwise.\n function isApprovedForwarder(address sender, address forwarder) external view returns (bool isApproved);\n}\n" }, "contracts/metatx/libraries/ERC2771Calldata.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\n/// @dev Derived from https://github.com/OpenZeppelin/openzeppelin-contracts (MIT licence)\n/// @dev See https://eips.ethereum.org/EIPS/eip-2771\nlibrary ERC2771Calldata {\n /// @notice Returns the sender address appended at the end of the calldata, as specified in EIP-2771.\n function msgSender() internal pure returns (address sender) {\n assembly {\n sender := shr(96, calldataload(sub(calldatasize(), 20)))\n }\n }\n\n /// @notice Returns the calldata while omitting the appended sender address, as specified in EIP-2771.\n function msgData() internal pure returns (bytes calldata data) {\n unchecked {\n return msg.data[:msg.data.length - 20];\n }\n }\n}\n" }, "contracts/proxy/libraries/ProxyAdminStorage.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\nimport {StorageSlot} from \"@openzeppelin/contracts/utils/StorageSlot.sol\";\nimport {ProxyInitialization} from \"./ProxyInitialization.sol\";\n\nlibrary ProxyAdminStorage {\n using ProxyAdminStorage for ProxyAdminStorage.Layout;\n\n struct Layout {\n address admin;\n }\n\n // bytes32 public constant PROXYADMIN_STORAGE_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;\n bytes32 internal constant LAYOUT_STORAGE_SLOT = bytes32(uint256(keccak256(\"eip1967.proxy.admin\")) - 1);\n bytes32 internal constant PROXY_INIT_PHASE_SLOT = bytes32(uint256(keccak256(\"eip1967.proxy.admin.phase\")) - 1);\n\n event AdminChanged(address previousAdmin, address newAdmin);\n\n /// @notice Initializes the storage with an initial admin (immutable version).\n /// @dev Note: This function should be called ONLY in the constructor of an immutable (non-proxied) contract.\n /// @dev Reverts if `initialAdmin` is the zero address.\n /// @dev Emits an {AdminChanged} event.\n /// @param initialAdmin The initial payout wallet.\n function constructorInit(Layout storage s, address initialAdmin) internal {\n require(initialAdmin != address(0), \"ProxyAdmin: no initial admin\");\n s.admin = initialAdmin;\n emit AdminChanged(address(0), initialAdmin);\n }\n\n /// @notice Initializes the storage with an initial admin (proxied version).\n /// @notice Sets the proxy initialization phase to `1`.\n /// @dev Note: This function should be called ONLY in the init function of a proxied contract.\n /// @dev Reverts if the proxy initialization phase is set to `1` or above.\n /// @dev Reverts if `initialAdmin` is the zero address.\n /// @dev Emits an {AdminChanged} event.\n /// @param initialAdmin The initial payout wallet.\n function proxyInit(Layout storage s, address initialAdmin) internal {\n ProxyInitialization.setPhase(PROXY_INIT_PHASE_SLOT, 1);\n s.constructorInit(initialAdmin);\n }\n\n /// @notice Sets a new proxy admin.\n /// @dev Reverts if `sender` is not the proxy admin.\n /// @dev Emits an {AdminChanged} event if `newAdmin` is different from the current proxy admin.\n /// @param newAdmin The new proxy admin.\n function changeProxyAdmin(Layout storage s, address sender, address newAdmin) internal {\n address previousAdmin = s.admin;\n require(sender == previousAdmin, \"ProxyAdmin: not the admin\");\n if (previousAdmin != newAdmin) {\n s.admin = newAdmin;\n emit AdminChanged(previousAdmin, newAdmin);\n }\n }\n\n /// @notice Gets the proxy admin.\n /// @return admin The proxy admin\n function proxyAdmin(Layout storage s) internal view returns (address admin) {\n return s.admin;\n }\n\n /// @notice Ensures that an account is the proxy admin.\n /// @dev Reverts if `account` is not the proxy admin.\n /// @param account The account.\n function enforceIsProxyAdmin(Layout storage s, address account) internal view {\n require(account == s.admin, \"ProxyAdmin: not the admin\");\n }\n\n function layout() internal pure returns (Layout storage s) {\n bytes32 position = LAYOUT_STORAGE_SLOT;\n assembly {\n s.slot := position\n }\n }\n}\n" }, "contracts/proxy/libraries/ProxyInitialization.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\nimport {StorageSlot} from \"@openzeppelin/contracts/utils/StorageSlot.sol\";\n\n/// @notice Multiple calls protection for storage-modifying proxy initialization functions.\nlibrary ProxyInitialization {\n /// @notice Sets the initialization phase during a storage-modifying proxy initialization function.\n /// @dev Reverts if `phase` has been reached already.\n /// @param storageSlot the storage slot where `phase` is stored.\n /// @param phase the initialization phase.\n function setPhase(bytes32 storageSlot, uint256 phase) internal {\n StorageSlot.Uint256Slot storage currentVersion = StorageSlot.getUint256Slot(storageSlot);\n require(currentVersion.value < phase, \"Storage: phase reached\");\n currentVersion.value = phase;\n }\n}\n" }, "contracts/token/ERC721/base/ERC721BatchTransferBase.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\nimport {IERC721BatchTransfer} from \"./../interfaces/IERC721BatchTransfer.sol\";\nimport {ERC721Storage} from \"./../libraries/ERC721Storage.sol\";\nimport {Context} from \"@openzeppelin/contracts/utils/Context.sol\";\n\n/// @title ERC721 Non-Fungible Token Standard, optional extension: Batch Transfer (proxiable version).\n/// @dev This contract is to be used via inheritance in a proxied implementation.\n/// @dev Note: This contract requires ERC721 (Non-Fungible Token Standard).\nabstract contract ERC721BatchTransferBase is Context, IERC721BatchTransfer {\n using ERC721Storage for ERC721Storage.Layout;\n\n /// @inheritdoc IERC721BatchTransfer\n function batchTransferFrom(address from, address to, uint256[] calldata tokenIds) external virtual override {\n ERC721Storage.layout().batchTransferFrom(_msgSender(), from, to, tokenIds);\n }\n}\n" }, "contracts/token/ERC721/facets/ERC721BatchTransferFacet.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport {IForwarderRegistry} from \"./../../../metatx/interfaces/IForwarderRegistry.sol\";\nimport {ERC721Storage} from \"./../libraries/ERC721Storage.sol\";\nimport {ProxyAdminStorage} from \"./../../../proxy/libraries/ProxyAdminStorage.sol\";\nimport {ERC721BatchTransferBase} from \"./../base/ERC721BatchTransferBase.sol\";\nimport {Context} from \"@openzeppelin/contracts/utils/Context.sol\";\nimport {ForwarderRegistryContextBase} from \"./../../../metatx/base/ForwarderRegistryContextBase.sol\";\n\n/// @title ERC721 Non-Fungible Token Standard, optional extension: BatchTransfer (facet version).\n/// @dev This contract is to be used as a diamond facet (see ERC2535 Diamond Standard https://eips.ethereum.org/EIPS/eip-2535).\n/// @dev Note: This facet depends on {ProxyAdminFacet}, and {InterfaceDetectionFacet}.\ncontract ERC721BatchTransferFacet is ERC721BatchTransferBase, ForwarderRegistryContextBase {\n using ProxyAdminStorage for ProxyAdminStorage.Layout;\n\n constructor(IForwarderRegistry forwarderRegistry) ForwarderRegistryContextBase(forwarderRegistry) {}\n\n /// @notice Marks the following ERC165 interface(s) as supported: ERC721BatchTransfer.\n /// @dev Reverts if the sender is not the proxy admin.\n function initERC721BatchTransferStorage() external {\n ProxyAdminStorage.layout().enforceIsProxyAdmin(_msgSender());\n ERC721Storage.initERC721BatchTransfer();\n }\n\n /// @inheritdoc ForwarderRegistryContextBase\n function _msgSender() internal view virtual override(Context, ForwarderRegistryContextBase) returns (address) {\n return ForwarderRegistryContextBase._msgSender();\n }\n\n /// @inheritdoc ForwarderRegistryContextBase\n function _msgData() internal view virtual override(Context, ForwarderRegistryContextBase) returns (bytes calldata) {\n return ForwarderRegistryContextBase._msgData();\n }\n}\n" }, "contracts/token/ERC721/interfaces/IERC721.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\n/// @title ERC721 Non-Fungible Token Standard, basic interface (functions).\n/// @dev See https://eips.ethereum.org/EIPS/eip-721\n/// @dev This interface only contains the standard functions. See IERC721Events for the events.\n/// @dev Note: The ERC-165 identifier for this interface is 0x80ac58cd.\ninterface IERC721 {\n /// @notice Sets or unsets an approval to transfer a single token on behalf of its owner.\n /// @dev Note: There can only be one approved address per token at a given time.\n /// @dev Note: A token approval gets reset when this token is transferred, including a self-transfer.\n /// @dev Reverts if `tokenId` does not exist.\n /// @dev Reverts if `to` is the token owner.\n /// @dev Reverts if the sender is not the token owner and has not been approved by the token owner.\n /// @dev Emits an {Approval} event.\n /// @param to The address to approve, or the zero address to remove any existing approval.\n /// @param tokenId The token identifier to give approval for.\n function approve(address to, uint256 tokenId) external;\n\n /// @notice Sets or unsets an approval to transfer all tokens on behalf of their owner.\n /// @dev Reverts if the sender is the same as `operator`.\n /// @dev Emits an {ApprovalForAll} event.\n /// @param operator The address to approve for all tokens.\n /// @param approved True to set an approval for all tokens, false to unset it.\n function setApprovalForAll(address operator, bool approved) external;\n\n /// @notice Unsafely transfers the ownership of a token to a recipient.\n /// @dev Note: Usage of this method is discouraged, use `safeTransferFrom` whenever possible.\n /// @dev Resets the token approval for `tokenId`.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `from` is not the owner of `tokenId`.\n /// @dev Reverts if the sender is not `from` and has not been approved by `from` for `tokenId`.\n /// @dev Emits a {Transfer} event.\n /// @param from The current token owner.\n /// @param to The recipient of the token transfer. Self-transfers are possible.\n /// @param tokenId The identifier of the token to transfer.\n function transferFrom(address from, address to, uint256 tokenId) external;\n\n /// @notice Safely transfers the ownership of a token to a recipient.\n /// @dev Resets the token approval for `tokenId`.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `from` is not the owner of `tokenId`.\n /// @dev Reverts if the sender is not `from` and has not been approved by `from` for `tokenId`.\n /// @dev Reverts if `to` is a contract and the call to {IERC721Receiver-onERC721Received} fails, reverts or is rejected.\n /// @dev Emits a {Transfer} event.\n /// @param from The current token owner.\n /// @param to The recipient of the token transfer.\n /// @param tokenId The identifier of the token to transfer.\n function safeTransferFrom(address from, address to, uint256 tokenId) external;\n\n /// @notice Safely transfers the ownership of a token to a recipient.\n /// @dev Resets the token approval for `tokenId`.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `from` is not the owner of `tokenId`.\n /// @dev Reverts if the sender is not `from` and has not been approved by `from` for `tokenId`.\n /// @dev Reverts if `to` is a contract and the call to {IERC721Receiver-onERC721Received} fails, reverts or is rejected.\n /// @dev Emits a {Transfer} event.\n /// @param from The current token owner.\n /// @param to The recipient of the token transfer.\n /// @param tokenId The identifier of the token to transfer.\n /// @param data Optional data to send along to a receiver contract.\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\n\n /// @notice Gets the balance of an address.\n /// @dev Reverts if `owner` is the zero address.\n /// @param owner The address to query the balance of.\n /// @return balance The amount owned by the owner.\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /// @notice Gets the owner of a token.\n /// @dev Reverts if `tokenId` does not exist.\n /// @param tokenId The token identifier to query the owner of.\n /// @return tokenOwner The owner of the token identifier.\n function ownerOf(uint256 tokenId) external view returns (address tokenOwner);\n\n /// @notice Gets the approved address for a token.\n /// @dev Reverts if `tokenId` does not exist.\n /// @param tokenId The token identifier to query the approval of.\n /// @return approved The approved address for the token identifier, or the zero address if no approval is set.\n function getApproved(uint256 tokenId) external view returns (address approved);\n\n /// @notice Gets whether an operator is approved for all tokens by an owner.\n /// @param owner The address which gives the approval for all tokens.\n /// @param operator The address which receives the approval for all tokens.\n /// @return approvedForAll Whether the operator is approved for all tokens by the owner.\n function isApprovedForAll(address owner, address operator) external view returns (bool approvedForAll);\n}\n" }, "contracts/token/ERC721/interfaces/IERC721BatchTransfer.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\n/// @title ERC721 Non-Fungible Token Standard, optional extension: Batch Transfer.\n/// @dev See https://eips.ethereum.org/EIPS/eip-721\n/// @dev Note: The ERC-165 identifier for this interface is 0xf3993d11.\ninterface IERC721BatchTransfer {\n /// @notice Unsafely transfers a batch of tokens to a recipient.\n /// @dev Resets the token approval for each of `tokenIds`.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if one of `tokenIds` is not owned by `from`.\n /// @dev Reverts if the sender is not `from` and has not been approved by `from` for each of `tokenIds`.\n /// @dev Emits an {IERC721-Transfer} event for each of `tokenIds`.\n /// @param from Current tokens owner.\n /// @param to Address of the new token owner.\n /// @param tokenIds Identifiers of the tokens to transfer.\n function batchTransferFrom(address from, address to, uint256[] calldata tokenIds) external;\n}\n" }, "contracts/token/ERC721/interfaces/IERC721Burnable.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\n/// @title ERC721 Non-Fungible Token Standard, optional extension: Burnable.\n/// @dev See https://eips.ethereum.org/EIPS/eip-721\n/// @dev Note: The ERC-165 identifier for this interface is 0x8b8b4ef5.\ninterface IERC721Burnable {\n /// @notice Burns a token.\n /// @dev Reverts if `tokenId` is not owned by `from`.\n /// @dev Reverts if the sender is not `from` and has not been approved by `from` for `tokenId`.\n /// @dev Emits an {IERC721-Transfer} event with `to` set to the zero address.\n /// @param from The current token owner.\n /// @param tokenId The identifier of the token to burn.\n function burnFrom(address from, uint256 tokenId) external;\n\n /// @notice Burns a batch of tokens.\n /// @dev Reverts if one of `tokenIds` is not owned by `from`.\n /// @dev Reverts if the sender is not `from` and has not been approved by `from` for each of `tokenIds`.\n /// @dev Emits an {IERC721-Transfer} event with `to` set to the zero address for each of `tokenIds`.\n /// @param from The current tokens owner.\n /// @param tokenIds The identifiers of the tokens to burn.\n function batchBurnFrom(address from, uint256[] calldata tokenIds) external;\n}\n" }, "contracts/token/ERC721/interfaces/IERC721Deliverable.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\n/// @title ERC721 Non-Fungible Token Standard, optional extension: Deliverable.\n/// @dev See https://eips.ethereum.org/EIPS/eip-721\n/// @dev Note: The ERC-165 identifier for this interface is 0x9da5e832.\ninterface IERC721Deliverable {\n /// @notice Unsafely mints tokens to multiple recipients.\n /// @dev Reverts if `recipients` and `tokenIds` have different lengths.\n /// @dev Reverts if one of `recipients` is the zero address.\n /// @dev Reverts if one of `tokenIds` already exists.\n /// @dev Emits an {IERC721-Transfer} event from the zero address for each of `recipients` and `tokenIds`.\n /// @param recipients Addresses of the new tokens owners.\n /// @param tokenIds Identifiers of the tokens to mint.\n function deliver(address[] calldata recipients, uint256[] calldata tokenIds) external;\n}\n" }, "contracts/token/ERC721/interfaces/IERC721Mintable.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\n/// @title ERC721 Non-Fungible Token Standard, optional extension: Mintable.\n/// @dev See https://eips.ethereum.org/EIPS/eip-721\n/// @dev Note: The ERC-165 identifier for this interface is 0x8e773e13.\ninterface IERC721Mintable {\n /// @notice Unsafely mints a token.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `tokenId` already exists.\n /// @dev Emits an {IERC721-Transfer} event from the zero address.\n /// @param to Address of the new token owner.\n /// @param tokenId Identifier of the token to mint.\n function mint(address to, uint256 tokenId) external;\n\n /// @notice Safely mints a token.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `tokenId` already exists.\n /// @dev Reverts if `to` is a contract and the call to {IERC721Receiver-onERC721Received} fails, reverts or is rejected.\n /// @dev Emits an {IERC721-Transfer} event from the zero address.\n /// @param to Address of the new token owner.\n /// @param tokenId Identifier of the token to mint.\n /// @param data Optional data to pass along to the receiver call.\n function safeMint(address to, uint256 tokenId, bytes calldata data) external;\n\n /// @notice Unsafely mints a batch of tokens.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if one of `tokenIds` already exists.\n /// @dev Emits an {IERC721-Transfer} event from the zero address for each of `tokenIds`.\n /// @param to Address of the new tokens owner.\n /// @param tokenIds Identifiers of the tokens to mint.\n function batchMint(address to, uint256[] calldata tokenIds) external;\n}\n" }, "contracts/token/ERC721/interfaces/IERC721Receiver.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\n/// @title ERC721 Non-Fungible Token Standard, Tokens Receiver.\n/// @notice Interface for supporting safe transfers from ERC721 contracts.\n/// @dev See https://eips.ethereum.org/EIPS/eip-721\n/// @dev Note: The ERC-165 identifier for this interface is 0x150b7a02.\ninterface IERC721Receiver {\n /// @notice Handles the receipt of an ERC721 token.\n /// @dev Note: This function is called by an ERC721 contract after a safe transfer.\n /// @dev Note: The ERC721 contract address is always the message sender.\n /// @param operator The initiator of the safe transfer.\n /// @param from The previous token owner.\n /// @param tokenId The token identifier.\n /// @param data Optional additional data with no specified format.\n /// @return magicValue `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))` (`0x150b7a02`) to accept, any other value to refuse.\n function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4 magicValue);\n}\n" }, "contracts/token/ERC721/libraries/ERC721Storage.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\nimport {IERC721} from \"./../interfaces/IERC721.sol\";\nimport {IERC721BatchTransfer} from \"./../interfaces/IERC721BatchTransfer.sol\";\nimport {IERC721Mintable} from \"./../interfaces/IERC721Mintable.sol\";\nimport {IERC721Deliverable} from \"./../interfaces/IERC721Deliverable.sol\";\nimport {IERC721Burnable} from \"./../interfaces/IERC721Burnable.sol\";\nimport {IERC721Receiver} from \"./../interfaces/IERC721Receiver.sol\";\nimport {Address} from \"@openzeppelin/contracts/utils/Address.sol\";\nimport {ProxyInitialization} from \"./../../../proxy/libraries/ProxyInitialization.sol\";\nimport {InterfaceDetectionStorage} from \"./../../../introspection/libraries/InterfaceDetectionStorage.sol\";\n\nlibrary ERC721Storage {\n using Address for address;\n using ERC721Storage for ERC721Storage.Layout;\n using InterfaceDetectionStorage for InterfaceDetectionStorage.Layout;\n\n struct Layout {\n mapping(uint256 => uint256) owners;\n mapping(address => uint256) balances;\n mapping(uint256 => address) approvals;\n mapping(address => mapping(address => bool)) operators;\n }\n\n bytes32 internal constant LAYOUT_STORAGE_SLOT = bytes32(uint256(keccak256(\"animoca.token.ERC721.ERC721.storage\")) - 1);\n\n bytes4 internal constant ERC721_RECEIVED = IERC721Receiver.onERC721Received.selector;\n\n // Single token approval flag\n // This bit is set in the owner's value to indicate that there is an approval set for this token\n uint256 internal constant TOKEN_APPROVAL_OWNER_FLAG = 1 << 160;\n\n // Burnt token magic value\n // This magic number is used as the owner's value to indicate that the token has been burnt\n uint256 internal constant BURNT_TOKEN_OWNER_VALUE = 0xdead000000000000000000000000000000000000000000000000000000000000;\n\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n /// @notice Marks the following ERC165 interface(s) as supported: ERC721.\n function init() internal {\n InterfaceDetectionStorage.layout().setSupportedInterface(type(IERC721).interfaceId, true);\n }\n\n /// @notice Marks the following ERC165 interface(s) as supported: ERC721BatchTransfer.\n function initERC721BatchTransfer() internal {\n InterfaceDetectionStorage.layout().setSupportedInterface(type(IERC721BatchTransfer).interfaceId, true);\n }\n\n /// @notice Marks the following ERC165 interface(s) as supported: ERC721Mintable.\n function initERC721Mintable() internal {\n InterfaceDetectionStorage.layout().setSupportedInterface(type(IERC721Mintable).interfaceId, true);\n }\n\n /// @notice Marks the following ERC165 interface(s) as supported: ERC721Deliverable.\n function initERC721Deliverable() internal {\n InterfaceDetectionStorage.layout().setSupportedInterface(type(IERC721Deliverable).interfaceId, true);\n }\n\n /// @notice Marks the following ERC165 interface(s) as supported: ERC721Burnable.\n function initERC721Burnable() internal {\n InterfaceDetectionStorage.layout().setSupportedInterface(type(IERC721Burnable).interfaceId, true);\n }\n\n /// @notice Sets or unsets an approval to transfer a single token on behalf of its owner.\n /// @dev Note: This function implements {ERC721-approve(address,uint256)}.\n /// @dev Reverts if `tokenId` does not exist.\n /// @dev Reverts if `to` is the token owner.\n /// @dev Reverts if `sender` is not the token owner and has not been approved by the token owner.\n /// @dev Emits an {Approval} event.\n /// @param sender The message sender.\n /// @param to The address to approve, or the zero address to remove any existing approval.\n /// @param tokenId The token identifier to give approval for.\n function approve(Layout storage s, address sender, address to, uint256 tokenId) internal {\n uint256 owner = s.owners[tokenId];\n require(_tokenExists(owner), \"ERC721: non-existing token\");\n address ownerAddress = _tokenOwner(owner);\n require(to != ownerAddress, \"ERC721: self-approval\");\n require(_isOperatable(s, ownerAddress, sender), \"ERC721: non-approved sender\");\n if (to == address(0)) {\n if (_tokenHasApproval(owner)) {\n // remove the approval bit if it is present\n s.owners[tokenId] = uint256(uint160(ownerAddress));\n }\n } else {\n uint256 ownerWithApprovalBit = owner | TOKEN_APPROVAL_OWNER_FLAG;\n if (owner != ownerWithApprovalBit) {\n // add the approval bit if it is not present\n s.owners[tokenId] = ownerWithApprovalBit;\n }\n s.approvals[tokenId] = to;\n }\n emit Approval(ownerAddress, to, tokenId);\n }\n\n /// @notice Sets or unsets an approval to transfer all tokens on behalf of their owner.\n /// @dev Note: This function implements {ERC721-setApprovalForAll(address,bool)}.\n /// @dev Reverts if `sender` is the same as `operator`.\n /// @dev Emits an {ApprovalForAll} event.\n /// @param sender The message sender.\n /// @param operator The address to approve for all tokens.\n /// @param approved True to set an approval for all tokens, false to unset it.\n function setApprovalForAll(Layout storage s, address sender, address operator, bool approved) internal {\n require(operator != sender, \"ERC721: self-approval for all\");\n s.operators[sender][operator] = approved;\n emit ApprovalForAll(sender, operator, approved);\n }\n\n /// @notice Unsafely transfers the ownership of a token to a recipient by a sender.\n /// @dev Note: This function implements {ERC721-transferFrom(address,address,uint256)}.\n /// @dev Resets the token approval for `tokenId`.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `from` is not the owner of `tokenId`.\n /// @dev Reverts if `sender` is not `from` and has not been approved by `from` for `tokenId`.\n /// @dev Emits a {Transfer} event.\n /// @param sender The message sender.\n /// @param from The current token owner.\n /// @param to The recipient of the token transfer.\n /// @param tokenId The identifier of the token to transfer.\n function transferFrom(Layout storage s, address sender, address from, address to, uint256 tokenId) internal {\n require(to != address(0), \"ERC721: transfer to address(0)\");\n\n uint256 owner = s.owners[tokenId];\n require(_tokenExists(owner), \"ERC721: non-existing token\");\n require(_tokenOwner(owner) == from, \"ERC721: non-owned token\");\n\n if (!_isOperatable(s, from, sender)) {\n require(_tokenHasApproval(owner) && sender == s.approvals[tokenId], \"ERC721: non-approved sender\");\n }\n\n s.owners[tokenId] = uint256(uint160(to));\n if (from != to) {\n unchecked {\n // cannot underflow as balance is verified through ownership\n --s.balances[from];\n // cannot overflow as supply cannot overflow\n ++s.balances[to];\n }\n }\n\n emit Transfer(from, to, tokenId);\n }\n\n /// @notice Safely transfers the ownership of a token to a recipient by a sender.\n /// @dev Note: This function implements {ERC721-safeTransferFrom(address,address,uint256)}.\n /// @dev Warning: Since a `to` contract can run arbitrary code, developers should be aware of potential re-entrancy attacks.\n /// @dev Resets the token approval for `tokenId`.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `from` is not the owner of `tokenId`.\n /// @dev Reverts if `sender` is not `from` and has not been approved by `from` for `tokenId`.\n /// @dev Reverts if `to` is a contract and the call to {IERC721Receiver-onERC721Received} fails, reverts or is rejected.\n /// @dev Emits a {Transfer} event.\n /// @param sender The message sender.\n /// @param from The current token owner.\n /// @param to The recipient of the token transfer.\n /// @param tokenId The identifier of the token to transfer.\n function safeTransferFrom(Layout storage s, address sender, address from, address to, uint256 tokenId) internal {\n s.transferFrom(sender, from, to, tokenId);\n if (to.isContract()) {\n _callOnERC721Received(sender, from, to, tokenId, \"\");\n }\n }\n\n /// @notice Safely transfers the ownership of a token to a recipient by a sender.\n /// @dev Note: This function implements {ERC721-safeTransferFrom(address,address,uint256,bytes)}.\n /// @dev Warning: Since a `to` contract can run arbitrary code, developers should be aware of potential re-entrancy attacks.\n /// @dev Resets the token approval for `tokenId`.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `from` is not the owner of `tokenId`.\n /// @dev Reverts if the sender is not `from` and has not been approved by `from` for `tokenId`.\n /// @dev Reverts if `to` is a contract and the call to {IERC721Receiver-onERC721Received} fails, reverts or is rejected.\n /// @dev Emits a {Transfer} event.\n /// @param sender The message sender.\n /// @param from The current token owner.\n /// @param to The recipient of the token transfer.\n /// @param tokenId The identifier of the token to transfer.\n /// @param data Optional data to send along to a receiver contract.\n function safeTransferFrom(Layout storage s, address sender, address from, address to, uint256 tokenId, bytes calldata data) internal {\n s.transferFrom(sender, from, to, tokenId);\n if (to.isContract()) {\n _callOnERC721Received(sender, from, to, tokenId, data);\n }\n }\n\n /// @notice Unsafely transfers a batch of tokens to a recipient by a sender.\n /// @dev Note: This function implements {ERC721BatchTransfer-batchTransferFrom(address,address,uint256[])}.\n /// @dev Resets the token approval for each of `tokenIds`.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if one of `tokenIds` is not owned by `from`.\n /// @dev Reverts if the sender is not `from` and has not been approved by `from` for each of `tokenIds`.\n /// @dev Emits a {Transfer} event for each of `tokenIds`.\n /// @param sender The message sender.\n /// @param from Current tokens owner.\n /// @param to Address of the new token owner.\n /// @param tokenIds Identifiers of the tokens to transfer.\n function batchTransferFrom(Layout storage s, address sender, address from, address to, uint256[] calldata tokenIds) internal {\n require(to != address(0), \"ERC721: transfer to address(0)\");\n bool operatable = _isOperatable(s, from, sender);\n\n uint256 length = tokenIds.length;\n unchecked {\n for (uint256 i; i != length; ++i) {\n uint256 tokenId = tokenIds[i];\n uint256 owner = s.owners[tokenId];\n require(_tokenExists(owner), \"ERC721: non-existing token\");\n require(_tokenOwner(owner) == from, \"ERC721: non-owned token\");\n if (!operatable) {\n require(_tokenHasApproval(owner) && sender == s.approvals[tokenId], \"ERC721: non-approved sender\");\n }\n s.owners[tokenId] = uint256(uint160(to));\n emit Transfer(from, to, tokenId);\n }\n\n if (from != to && length != 0) {\n // cannot underflow as balance is verified through ownership\n s.balances[from] -= length;\n // cannot overflow as supply cannot overflow\n s.balances[to] += length;\n }\n }\n }\n\n /// @notice Unsafely mints a token.\n /// @dev Note: This function implements {ERC721Mintable-mint(address,uint256)}.\n /// @dev Note: Either `mint` or `mintOnce` should be used in a given contract, but not both.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `tokenId` already exists.\n /// @dev Emits a {Transfer} event from the zero address.\n /// @param to Address of the new token owner.\n /// @param tokenId Identifier of the token to mint.\n function mint(Layout storage s, address to, uint256 tokenId) internal {\n require(to != address(0), \"ERC721: mint to address(0)\");\n require(!_tokenExists(s.owners[tokenId]), \"ERC721: existing token\");\n\n s.owners[tokenId] = uint256(uint160(to));\n\n unchecked {\n // cannot overflow due to the cost of minting individual tokens\n ++s.balances[to];\n }\n\n emit Transfer(address(0), to, tokenId);\n }\n\n /// @notice Safely mints a token.\n /// @dev Note: This function implements {ERC721Mintable-safeMint(address,uint256,bytes)}.\n /// @dev Note: Either `safeMint` or `safeMintOnce` should be used in a given contract, but not both.\n /// @dev Warning: Since a `to` contract can run arbitrary code, developers should be aware of potential re-entrancy attacks.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `tokenId` already exists.\n /// @dev Reverts if `to` is a contract and the call to {IERC721Receiver-onERC721Received} fails, reverts or is rejected.\n /// @dev Emits a {Transfer} event from the zero address.\n /// @param to Address of the new token owner.\n /// @param tokenId Identifier of the token to mint.\n /// @param data Optional data to pass along to the receiver call.\n function safeMint(Layout storage s, address sender, address to, uint256 tokenId, bytes memory data) internal {\n s.mint(to, tokenId);\n if (to.isContract()) {\n _callOnERC721Received(sender, address(0), to, tokenId, data);\n }\n }\n\n /// @notice Unsafely mints a batch of tokens.\n /// @dev Note: This function implements {ERC721Mintable-batchMint(address,uint256[])}.\n /// @dev Note: Either `batchMint` or `batchMintOnce` should be used in a given contract, but not both.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if one of `tokenIds` already exists.\n /// @dev Emits a {Transfer} event from the zero address for each of `tokenIds`.\n /// @param to Address of the new tokens owner.\n /// @param tokenIds Identifiers of the tokens to mint.\n function batchMint(Layout storage s, address to, uint256[] memory tokenIds) internal {\n require(to != address(0), \"ERC721: mint to address(0)\");\n\n uint256 length = tokenIds.length;\n unchecked {\n for (uint256 i; i != length; ++i) {\n uint256 tokenId = tokenIds[i];\n require(!_tokenExists(s.owners[tokenId]), \"ERC721: existing token\");\n\n s.owners[tokenId] = uint256(uint160(to));\n emit Transfer(address(0), to, tokenId);\n }\n\n s.balances[to] += length;\n }\n }\n\n /// @notice Unsafely mints tokens to multiple recipients.\n /// @dev Note: This function implements {ERC721Deliverable-deliver(address[],uint256[])}.\n /// @dev Note: Either `deliver` or `deliverOnce` should be used in a given contract, but not both.\n /// @dev Reverts if `recipients` and `tokenIds` have different lengths.\n /// @dev Reverts if one of `recipients` is the zero address.\n /// @dev Reverts if one of `tokenIds` already exists.\n /// @dev Emits a {Transfer} event from the zero address for each of `recipients` and `tokenIds`.\n /// @param recipients Addresses of the new tokens owners.\n /// @param tokenIds Identifiers of the tokens to mint.\n function deliver(Layout storage s, address[] memory recipients, uint256[] memory tokenIds) internal {\n uint256 length = recipients.length;\n require(length == tokenIds.length, \"ERC721: inconsistent arrays\");\n unchecked {\n for (uint256 i; i != length; ++i) {\n s.mint(recipients[i], tokenIds[i]);\n }\n }\n }\n\n /// @notice Unsafely mints a token once.\n /// @dev Note: This function implements {ERC721Mintable-mint(address,uint256)}.\n /// @dev Note: Either `mint` or `mintOnce` should be used in a given contract, but not both.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `tokenId` already exists.\n /// @dev Reverts if `tokenId` has been previously burnt.\n /// @dev Emits a {Transfer} event from the zero address.\n /// @param to Address of the new token owner.\n /// @param tokenId Identifier of the token to mint.\n function mintOnce(Layout storage s, address to, uint256 tokenId) internal {\n require(to != address(0), \"ERC721: mint to address(0)\");\n\n uint256 owner = s.owners[tokenId];\n require(!_tokenExists(owner), \"ERC721: existing token\");\n require(!_tokenWasBurnt(owner), \"ERC721: burnt token\");\n\n s.owners[tokenId] = uint256(uint160(to));\n\n unchecked {\n // cannot overflow due to the cost of minting individual tokens\n ++s.balances[to];\n }\n\n emit Transfer(address(0), to, tokenId);\n }\n\n /// @notice Safely mints a token once.\n /// @dev Note: This function implements {ERC721Mintable-safeMint(address,uint256,bytes)}.\n /// @dev Note: Either `safeMint` or `safeMintOnce` should be used in a given contract, but not both.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if `tokenId` already exists.\n /// @dev Reverts if `tokenId` has been previously burnt.\n /// @dev Reverts if `to` is a contract and the call to {IERC721Receiver-onERC721Received} fails, reverts or is rejected.\n /// @dev Emits a {Transfer} event from the zero address.\n /// @param to Address of the new token owner.\n /// @param tokenId Identifier of the token to mint.\n /// @param data Optional data to pass along to the receiver call.\n function safeMintOnce(Layout storage s, address sender, address to, uint256 tokenId, bytes memory data) internal {\n s.mintOnce(to, tokenId);\n if (to.isContract()) {\n _callOnERC721Received(sender, address(0), to, tokenId, data);\n }\n }\n\n /// @notice Unsafely mints a batch of tokens once.\n /// @dev Note: This function implements {ERC721Mintable-batchMint(address,uint256[])}.\n /// @dev Note: Either `batchMint` or `batchMintOnce` should be used in a given contract, but not both.\n /// @dev Reverts if `to` is the zero address.\n /// @dev Reverts if one of `tokenIds` already exists.\n /// @dev Reverts if one of `tokenIds` has been previously burnt.\n /// @dev Emits a {Transfer} event from the zero address for each of `tokenIds`.\n /// @param to Address of the new tokens owner.\n /// @param tokenIds Identifiers of the tokens to mint.\n function batchMintOnce(Layout storage s, address to, uint256[] memory tokenIds) internal {\n require(to != address(0), \"ERC721: mint to address(0)\");\n\n uint256 length = tokenIds.length;\n unchecked {\n for (uint256 i; i != length; ++i) {\n uint256 tokenId = tokenIds[i];\n uint256 owner = s.owners[tokenId];\n require(!_tokenExists(owner), \"ERC721: existing token\");\n require(!_tokenWasBurnt(owner), \"ERC721: burnt token\");\n\n s.owners[tokenId] = uint256(uint160(to));\n\n emit Transfer(address(0), to, tokenId);\n }\n\n s.balances[to] += length;\n }\n }\n\n /// @notice Unsafely mints tokens to multiple recipients once.\n /// @dev Note: This function implements {ERC721Deliverable-deliver(address[],uint256[])}.\n /// @dev Note: Either `deliver` or `deliverOnce` should be used in a given contract, but not both.\n /// @dev Reverts if `recipients` and `tokenIds` have different lengths.\n /// @dev Reverts if one of `recipients` is the zero address.\n /// @dev Reverts if one of `tokenIds` already exists.\n /// @dev Reverts if one of `tokenIds` has been previously burnt.\n /// @dev Emits a {Transfer} event from the zero address for each of `recipients` and `tokenIds`.\n /// @param recipients Addresses of the new tokens owners.\n /// @param tokenIds Identifiers of the tokens to mint.\n function deliverOnce(Layout storage s, address[] memory recipients, uint256[] memory tokenIds) internal {\n uint256 length = recipients.length;\n require(length == tokenIds.length, \"ERC721: inconsistent arrays\");\n unchecked {\n for (uint256 i; i != length; ++i) {\n address to = recipients[i];\n require(to != address(0), \"ERC721: mint to address(0)\");\n\n uint256 tokenId = tokenIds[i];\n uint256 owner = s.owners[tokenId];\n require(!_tokenExists(owner), \"ERC721: existing token\");\n require(!_tokenWasBurnt(owner), \"ERC721: burnt token\");\n\n s.owners[tokenId] = uint256(uint160(to));\n ++s.balances[to];\n\n emit Transfer(address(0), to, tokenId);\n }\n }\n }\n\n /// @notice Burns a token by a sender.\n /// @dev Note: This function implements {ERC721Burnable-burnFrom(address,uint256)}.\n /// @dev Reverts if `tokenId` is not owned by `from`.\n /// @dev Reverts if `sender` is not `from` and has not been approved by `from` for `tokenId`.\n /// @dev Emits a {Transfer} event with `to` set to the zero address.\n /// @param sender The message sender.\n /// @param from The current token owner.\n /// @param tokenId The identifier of the token to burn.\n function burnFrom(Layout storage s, address sender, address from, uint256 tokenId) internal {\n uint256 owner = s.owners[tokenId];\n require(from == _tokenOwner(owner), \"ERC721: non-owned token\");\n\n if (!_isOperatable(s, from, sender)) {\n require(_tokenHasApproval(owner) && sender == s.approvals[tokenId], \"ERC721: non-approved sender\");\n }\n\n s.owners[tokenId] = BURNT_TOKEN_OWNER_VALUE;\n\n unchecked {\n // cannot underflow as balance is verified through TOKEN ownership\n --s.balances[from];\n }\n emit Transfer(from, address(0), tokenId);\n }\n\n /// @notice Burns a batch of tokens by a sender.\n /// @dev Note: This function implements {ERC721Burnable-batchBurnFrom(address,uint256[])}.\n /// @dev Reverts if one of `tokenIds` is not owned by `from`.\n /// @dev Reverts if `sender` is not `from` and has not been approved by `from` for each of `tokenIds`.\n /// @dev Emits a {Transfer} event with `to` set to the zero address for each of `tokenIds`.\n /// @param sender The message sender.\n /// @param from The current tokens owner.\n /// @param tokenIds The identifiers of the tokens to burn.\n function batchBurnFrom(Layout storage s, address sender, address from, uint256[] calldata tokenIds) internal {\n bool operatable = _isOperatable(s, from, sender);\n\n uint256 length = tokenIds.length;\n unchecked {\n for (uint256 i; i != length; ++i) {\n uint256 tokenId = tokenIds[i];\n uint256 owner = s.owners[tokenId];\n require(from == _tokenOwner(owner), \"ERC721: non-owned token\");\n if (!operatable) {\n require(_tokenHasApproval(owner) && sender == s.approvals[tokenId], \"ERC721: non-approved sender\");\n }\n s.owners[tokenId] = BURNT_TOKEN_OWNER_VALUE;\n emit Transfer(from, address(0), tokenId);\n }\n\n if (length != 0) {\n s.balances[from] -= length;\n }\n }\n }\n\n /// @notice Gets the balance of an address.\n /// @dev Note: This function implements {ERC721-balanceOf(address)}.\n /// @dev Reverts if `owner` is the zero address.\n /// @param owner The address to query the balance of.\n /// @return balance The amount owned by the owner.\n function balanceOf(Layout storage s, address owner) internal view returns (uint256 balance) {\n require(owner != address(0), \"ERC721: balance of address(0)\");\n return s.balances[owner];\n }\n\n /// @notice Gets the owner of a token.\n /// @dev Note: This function implements {ERC721-ownerOf(uint256)}.\n /// @dev Reverts if `tokenId` does not exist.\n /// @param tokenId The token identifier to query the owner of.\n /// @return tokenOwner The owner of the token.\n function ownerOf(Layout storage s, uint256 tokenId) internal view returns (address tokenOwner) {\n uint256 owner = s.owners[tokenId];\n require(_tokenExists(owner), \"ERC721: non-existing token\");\n return _tokenOwner(owner);\n }\n\n /// @notice Gets the approved address for a token.\n /// @dev Note: This function implements {ERC721-getApproved(uint256)}.\n /// @dev Reverts if `tokenId` does not exist.\n /// @param tokenId The token identifier to query the approval of.\n /// @return approved The approved address for the token identifier, or the zero address if no approval is set.\n function getApproved(Layout storage s, uint256 tokenId) internal view returns (address approved) {\n uint256 owner = s.owners[tokenId];\n require(_tokenExists(owner), \"ERC721: non-existing token\");\n if (_tokenHasApproval(owner)) {\n return s.approvals[tokenId];\n } else {\n return address(0);\n }\n }\n\n /// @notice Gets whether an operator is approved for all tokens by an owner.\n /// @dev Note: This function implements {ERC721-isApprovedForAll(address,address)}.\n /// @param owner The address which gives the approval for all tokens.\n /// @param operator The address which receives the approval for all tokens.\n /// @return approvedForAll Whether the operator is approved for all tokens by the owner.\n function isApprovedForAll(Layout storage s, address owner, address operator) internal view returns (bool approvedForAll) {\n return s.operators[owner][operator];\n }\n\n /// @notice Gets whether a token was burnt.\n /// @param tokenId The token identifier.\n /// @return tokenWasBurnt Whether the token was burnt.\n function wasBurnt(Layout storage s, uint256 tokenId) internal view returns (bool tokenWasBurnt) {\n return _tokenWasBurnt(s.owners[tokenId]);\n }\n\n function layout() internal pure returns (Layout storage s) {\n bytes32 position = LAYOUT_STORAGE_SLOT;\n assembly {\n s.slot := position\n }\n }\n\n /// @notice Calls {IERC721Receiver-onERC721Received} on a target contract.\n /// @dev Reverts if the call to the target fails, reverts or is rejected.\n /// @param sender The message sender.\n /// @param from Previous token owner.\n /// @param to New token owner.\n /// @param tokenId Identifier of the token transferred.\n /// @param data Optional data to send along with the receiver contract call.\n function _callOnERC721Received(address sender, address from, address to, uint256 tokenId, bytes memory data) private {\n require(IERC721Receiver(to).onERC721Received(sender, from, tokenId, data) == ERC721_RECEIVED, \"ERC721: safe transfer rejected\");\n }\n\n /// @notice Returns whether an account is authorised to make a transfer on behalf of an owner.\n /// @param owner The token owner.\n /// @param account The account to check the operatability of.\n /// @return operatable True if `account` is `owner` or is an operator for `owner`, false otherwise.\n function _isOperatable(Layout storage s, address owner, address account) private view returns (bool operatable) {\n return (owner == account) || s.operators[owner][account];\n }\n\n function _tokenOwner(uint256 owner) private pure returns (address tokenOwner) {\n return address(uint160(owner));\n }\n\n function _tokenExists(uint256 owner) private pure returns (bool tokenExists) {\n return uint160(owner) != 0;\n }\n\n function _tokenWasBurnt(uint256 owner) private pure returns (bool tokenWasBurnt) {\n return owner == BURNT_TOKEN_OWNER_VALUE;\n }\n\n function _tokenHasApproval(uint256 owner) private pure returns (bool tokenHasApproval) {\n return owner & TOKEN_APPROVAL_OWNER_FLAG != 0;\n }\n}\n" } } }