{ "language": "Solidity", "sources": { "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal onlyInitializing {\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal onlyInitializing {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n" }, "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.1) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n * function initialize() initializer public {\n * __ERC20_init(\"MyToken\", \"MTK\");\n * }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n * function initializeV2() reinitializer(2) public {\n * __ERC20Permit_init(\"MyToken\");\n * }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n * _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n * @custom:oz-retyped-from bool\n */\n uint8 private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Triggered when the contract has been initialized or reinitialized.\n */\n event Initialized(uint8 version);\n\n /**\n * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n * `onlyInitializing` functions can be used to initialize parent contracts.\n *\n * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n * constructor.\n *\n * Emits an {Initialized} event.\n */\n modifier initializer() {\n bool isTopLevelCall = !_initializing;\n require(\n (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n \"Initializable: contract is already initialized\"\n );\n _initialized = 1;\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(1);\n }\n }\n\n /**\n * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n * used to initialize parent contracts.\n *\n * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n * are added through upgrades and that require initialization.\n *\n * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n * cannot be nested. If one is invoked in the context of another, execution will revert.\n *\n * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n * a contract, executing them in the right order is up to the developer or operator.\n *\n * WARNING: setting the version to 255 will prevent any future reinitialization.\n *\n * Emits an {Initialized} event.\n */\n modifier reinitializer(uint8 version) {\n require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n _initialized = version;\n _initializing = true;\n _;\n _initializing = false;\n emit Initialized(version);\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} and {reinitializer} modifiers, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n /**\n * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n * through proxies.\n *\n * Emits an {Initialized} event the first time it is successfully executed.\n */\n function _disableInitializers() internal virtual {\n require(!_initializing, \"Initializable: contract is initializing\");\n if (_initialized < type(uint8).max) {\n _initialized = type(uint8).max;\n emit Initialized(type(uint8).max);\n }\n }\n\n /**\n * @dev Returns the highest version that has been initialized. See {reinitializer}.\n */\n function _getInitializedVersion() internal view returns (uint8) {\n return _initialized;\n }\n\n /**\n * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n */\n function _isInitializing() internal view returns (bool) {\n return _initializing;\n }\n}\n" }, "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable {\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 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-upgradeable/utils/ContextUpgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\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 ContextUpgradeable is Initializable {\n function __Context_init() internal onlyInitializing {\n }\n\n function __Context_init_unchained() internal onlyInitializing {\n }\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 /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n" }, "@openzeppelin/contracts/token/ERC1155/IERC1155.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC1155 compliant contract, as defined in the\n * https://eips.ethereum.org/EIPS/eip-1155[EIP].\n *\n * _Available since v3.1._\n */\ninterface IERC1155 is IERC165 {\n /**\n * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.\n */\n event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);\n\n /**\n * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all\n * transfers.\n */\n event TransferBatch(\n address indexed operator,\n address indexed from,\n address indexed to,\n uint256[] ids,\n uint256[] values\n );\n\n /**\n * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to\n * `approved`.\n */\n event ApprovalForAll(address indexed account, address indexed operator, bool approved);\n\n /**\n * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.\n *\n * If an {URI} event was emitted for `id`, the standard\n * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value\n * returned by {IERC1155MetadataURI-uri}.\n */\n event URI(string value, uint256 indexed id);\n\n /**\n * @dev Returns the amount of tokens of token type `id` owned by `account`.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function balanceOf(address account, uint256 id) external view returns (uint256);\n\n /**\n * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.\n *\n * Requirements:\n *\n * - `accounts` and `ids` must have the same length.\n */\n function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)\n external\n view\n returns (uint256[] memory);\n\n /**\n * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,\n *\n * Emits an {ApprovalForAll} event.\n *\n * Requirements:\n *\n * - `operator` cannot be the caller.\n */\n function setApprovalForAll(address operator, bool approved) external;\n\n /**\n * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.\n *\n * See {setApprovalForAll}.\n */\n function isApprovedForAll(address account, address operator) external view returns (bool);\n\n /**\n * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.\n *\n * Emits a {TransferSingle} event.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.\n * - `from` must have a balance of tokens of type `id` of at least `amount`.\n * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the\n * acceptance magic value.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 id,\n uint256 amount,\n bytes calldata data\n ) external;\n\n /**\n * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.\n *\n * Emits a {TransferBatch} event.\n *\n * Requirements:\n *\n * - `ids` and `amounts` must have the same length.\n * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the\n * acceptance magic value.\n */\n function safeBatchTransferFrom(\n address from,\n address to,\n uint256[] calldata ids,\n uint256[] calldata amounts,\n bytes calldata data\n ) external;\n}\n" }, "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev _Available since v3.1._\n */\ninterface IERC1155Receiver is IERC165 {\n /**\n * @dev Handles the receipt of a single ERC1155 token type. This function is\n * called at the end of a `safeTransferFrom` after the balance has been updated.\n *\n * NOTE: To accept the transfer, this must return\n * `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`\n * (i.e. 0xf23a6e61, or its own function selector).\n *\n * @param operator The address which initiated the transfer (i.e. msg.sender)\n * @param from The address which previously owned the token\n * @param id The ID of the token being transferred\n * @param value The amount of tokens being transferred\n * @param data Additional data with no specified format\n * @return `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))` if transfer is allowed\n */\n function onERC1155Received(\n address operator,\n address from,\n uint256 id,\n uint256 value,\n bytes calldata data\n ) external returns (bytes4);\n\n /**\n * @dev Handles the receipt of a multiple ERC1155 token types. This function\n * is called at the end of a `safeBatchTransferFrom` after the balances have\n * been updated.\n *\n * NOTE: To accept the transfer(s), this must return\n * `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n * (i.e. 0xbc197c81, or its own function selector).\n *\n * @param operator The address which initiated the batch transfer (i.e. msg.sender)\n * @param from The address which previously owned the token\n * @param ids An array containing ids of each token being transferred (order and length must match values array)\n * @param values An array containing amounts of each token being transferred (order and length must match ids array)\n * @param data Additional data with no specified format\n * @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))` if transfer is allowed\n */\n function onERC1155BatchReceived(\n address operator,\n address from,\n uint256[] calldata ids,\n uint256[] calldata values,\n bytes calldata data\n ) external returns (bytes4);\n}\n" }, "@openzeppelin/contracts/token/ERC721/IERC721.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n /**\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n */\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n */\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n */\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n /**\n * @dev Returns the number of tokens in ``owner``'s account.\n */\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /**\n * @dev Returns the owner of the `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function ownerOf(uint256 tokenId) external view returns (address owner);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) external;\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Transfers `tokenId` token from `from` to `to`.\n *\n * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721\n * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must\n * understand this adds an external call which potentially creates a reentrancy vulnerability.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n *\n * Emits an {Approval} event.\n */\n function approve(address to, uint256 tokenId) external;\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the caller.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool _approved) external;\n\n /**\n * @dev Returns the account approved for `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function getApproved(uint256 tokenId) external view returns (address operator);\n\n /**\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n *\n * See {setApprovalForAll}\n */\n function isApprovedForAll(address owner, address operator) external view returns (bool);\n}\n" }, "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n /**\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n * by `operator` from `from`, this function is called.\n *\n * It must return its Solidity selector to confirm the token transfer.\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n *\n * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.\n */\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}\n" }, "@openzeppelin/contracts/utils/cryptography/ECDSA.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../Strings.sol\";\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS,\n InvalidSignatureV // Deprecated in v4.8\n }\n\n function _throwError(RecoverError error) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert(\"ECDSA: invalid signature\");\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert(\"ECDSA: invalid signature length\");\n } else if (error == RecoverError.InvalidSignatureS) {\n revert(\"ECDSA: invalid signature 's' value\");\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature` or error string. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n *\n * _Available since v4.3._\n */\n function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n /// @solidity memory-safe-assembly\n assembly {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength);\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, signature);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\n *\n * _Available since v4.3._\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address, RecoverError) {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n *\n * _Available since v4.2._\n */\n function recover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, r, vs);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n *\n * _Available since v4.3._\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address, RecoverError) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n รท 2 + 1, and for v in (302): v โˆˆ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature);\n }\n\n return (signer, RecoverError.NoError);\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n * produces hash corresponding to the one signed with the\n * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n * JSON-RPC method as part of EIP-191.\n *\n * See {recover}.\n */\n function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {\n // 32 is the length in bytes of hash,\n // enforced by the type signature above\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", hash));\n }\n\n /**\n * @dev Returns an Ethereum Signed Message, created from `s`. This\n * produces hash corresponding to the one signed with the\n * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n * JSON-RPC method as part of EIP-191.\n *\n * See {recover}.\n */\n function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", Strings.toString(s.length), s));\n }\n\n /**\n * @dev Returns an Ethereum Signed Typed Data, created from a\n * `domainSeparator` and a `structHash`. This produces hash corresponding\n * to the one signed with the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]\n * JSON-RPC method as part of EIP-712.\n *\n * See {recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n }\n}\n" }, "@openzeppelin/contracts/utils/introspection/IERC165.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" }, "@openzeppelin/contracts/utils/math/Math.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Down, // Toward negative infinity\n Up, // Toward infinity\n Zero // Toward zero\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds up instead\n * of rounding down.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b - 1) / b can overflow on addition, so we distribute.\n return a == 0 ? 0 : (a - 1) / b + 1;\n }\n\n /**\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n * with further edits by Uniswap Labs also under MIT license.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator\n ) internal pure returns (uint256 result) {\n unchecked {\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = prod1 * 2^256 + prod0.\n uint256 prod0; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly {\n let mm := mulmod(x, y, not(0))\n prod0 := mul(x, y)\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n // Handle non-overflow cases, 256 by 256 division.\n if (prod1 == 0) {\n return prod0 / denominator;\n }\n\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\n require(denominator > prod1);\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [prod1 prod0].\n uint256 remainder;\n assembly {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n prod1 := sub(prod1, gt(remainder, prod0))\n prod0 := sub(prod0, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n // See https://cs.stackexchange.com/q/138556/92363.\n\n // Does not overflow because the denominator cannot be zero at this stage in the function.\n uint256 twos = denominator & (~denominator + 1);\n assembly {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [prod1 prod0] by twos.\n prod0 := div(prod0, twos)\n\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from prod1 into prod0.\n prod0 |= prod1 * twos;\n\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv = 1 mod 2^4.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n // in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n // is no longer required.\n result = prod0 * inverse;\n return result;\n }\n }\n\n /**\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator,\n Rounding rounding\n ) internal pure returns (uint256) {\n uint256 result = mulDiv(x, y, denominator);\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n result += 1;\n }\n return result;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n *\n * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n if (a == 0) {\n return 0;\n }\n\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n //\n // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n //\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n // โ†’ `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n // โ†’ `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n //\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n uint256 result = 1 << (log2(a) >> 1);\n\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n // into the expected uint128 result.\n unchecked {\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n return min(result, a / result);\n }\n }\n\n /**\n * @notice Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 2, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 128;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 64;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 32;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 16;\n }\n if (value >> 8 > 0) {\n value >>= 8;\n result += 8;\n }\n if (value >> 4 > 0) {\n value >>= 4;\n result += 4;\n }\n if (value >> 2 > 0) {\n value >>= 2;\n result += 2;\n }\n if (value >> 1 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 10, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10**64) {\n value /= 10**64;\n result += 64;\n }\n if (value >= 10**32) {\n value /= 10**32;\n result += 32;\n }\n if (value >= 10**16) {\n value /= 10**16;\n result += 16;\n }\n if (value >= 10**8) {\n value /= 10**8;\n result += 8;\n }\n if (value >= 10**4) {\n value /= 10**4;\n result += 4;\n }\n if (value >= 10**2) {\n value /= 10**2;\n result += 2;\n }\n if (value >= 10**1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 256, rounded down, of a positive value.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 16;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 8;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 4;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 2;\n }\n if (value >> 8 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\n }\n }\n}\n" }, "@openzeppelin/contracts/utils/Strings.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n /// @solidity memory-safe-assembly\n assembly {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n /// @solidity memory-safe-assembly\n assembly {\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n}\n" }, "contracts/distributors/Distributooor.sol": { "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity 0.8.17;\n\nimport {Strings} from \"@openzeppelin/contracts/utils/Strings.sol\";\nimport {IERC721} from \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\nimport {IERC1155} from \"@openzeppelin/contracts/token/ERC1155/IERC1155.sol\";\nimport {IERC721Receiver} from \"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol\";\nimport {IERC1155Receiver} from \"@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol\";\nimport {Initializable} from \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\nimport {OwnableUpgradeable} from \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport {ECDSA} from \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\nimport {IRaffleChef} from \"../interfaces/IRaffleChef.sol\";\nimport {TypeAndVersion} from \"../interfaces/TypeAndVersion.sol\";\nimport {IRandomiser} from \"../interfaces/IRandomiser.sol\";\nimport {IRandomiserCallback} from \"../interfaces/IRandomiserCallback.sol\";\nimport {IDistributooor} from \"../interfaces/IDistributooor.sol\";\nimport {IDistributooorFactory} from \"../interfaces/IDistributooorFactory.sol\";\n\n// solhint-disable not-rely-on-time\n// solhint-disable no-inline-assembly\n\n/// @title Distributooor\n/// @notice Base contract that implements helpers to consume a raffle from a\n/// {RaffleChef}. Keeps track of participants that have claimed a winning\n/// (and prevents them from claiming twice).\ncontract Distributooor is\n IDistributooor,\n IERC721Receiver,\n IERC1155Receiver,\n IRandomiserCallback,\n TypeAndVersion,\n Initializable,\n OwnableUpgradeable\n{\n using Strings for uint256;\n using Strings for address;\n\n /// @notice Type of prize\n enum PrizeType {\n ERC721,\n ERC1155\n }\n\n address public distributooorFactory;\n /// @notice {RaffleChef} instance to consume\n address public raffleChef;\n /// @notice Raffle ID corresponding to a raffle in {RaffleChef}\n uint256 public raffleId;\n /// @notice Randomiser\n address public randomiser;\n /// @notice Track whether a given leaf (representing a participant) has\n /// claimed or not\n mapping(bytes32 => bool) public hasClaimed;\n\n /// @notice Array of bytes representing prize data\n bytes[] private prizes;\n\n /// @notice Due date (block timestamp) after which the raffle is allowed\n /// to be performed. CANNOT be changed after initialisation.\n uint256 public raffleActivationTimestamp;\n /// @notice The block timestamp after which the owner may reclaim the\n /// prizes from this contract. CANNOT be changed after initialisation.\n uint256 public prizeExpiryTimestamp;\n\n /// @notice Committed merkle root from collector\n bytes32 public merkleRoot;\n /// @notice Commited number of entries from collector\n uint256 public nParticipants;\n /// @notice Committed provenance\n string public provenance;\n\n /// @notice VRF request ID\n uint256 public randRequestId;\n /// @notice Timestamp of last VRF requesst\n uint256 public lastRandRequest;\n\n uint256[37] private __Distributooor_gap;\n\n event Claimed(\n address claimooor,\n uint256 originalIndex,\n uint256 permutedIndex\n );\n\n error ERC721NotReceived(address nftContract, uint256 tokenId);\n error ERC1155NotReceived(\n address nftContract,\n uint256 tokenId,\n uint256 amount\n );\n error InvalidPrizeType(uint8 prizeType);\n error InvalidTimestamp(uint256 timestamp);\n error RaffleActivationPending(uint256 secondsLeft);\n error PrizeExpiryTimestampPending(uint256 secondsLeft);\n error IncorrectSignatureLength(uint256 sigLength);\n error InvalidRandomWords(uint256[] randomWords);\n error RandomnessAlreadySet(\n uint256 existingRandomness,\n uint256 newRandomness\n );\n error UnknownRandomiser(address randomiser);\n error RandomRequestInFlight(uint256 requestId);\n\n constructor() {\n _disableInitializers();\n }\n\n function init(\n address raffleOwner,\n address raffleChef_,\n address randomiser_,\n uint256 raffleActivationTimestamp_,\n uint256 prizeExpiryTimestamp_\n ) public initializer {\n bool isActivationInThePast = raffleActivationTimestamp_ <=\n block.timestamp;\n bool isActivationOnOrAfterExpiry = raffleActivationTimestamp_ >=\n prizeExpiryTimestamp_;\n bool isClaimDurationTooShort = prizeExpiryTimestamp_ -\n raffleActivationTimestamp_ <\n 1 hours;\n if (\n raffleActivationTimestamp_ == 0 ||\n isActivationInThePast ||\n isActivationOnOrAfterExpiry ||\n isClaimDurationTooShort\n ) {\n revert InvalidTimestamp(raffleActivationTimestamp_);\n }\n if (prizeExpiryTimestamp_ == 0) {\n revert InvalidTimestamp(prizeExpiryTimestamp_);\n }\n\n __Ownable_init();\n _transferOwnership(raffleOwner);\n\n // Assumes that the DistributooorFactory is the deployer\n distributooorFactory = _msgSender();\n raffleChef = raffleChef_;\n randomiser = randomiser_;\n raffleActivationTimestamp = raffleActivationTimestamp_;\n prizeExpiryTimestamp = prizeExpiryTimestamp_;\n }\n\n /// @notice See {TypeAndVersion-typeAndVersion}\n function typeAndVersion()\n external\n pure\n virtual\n override\n returns (string memory)\n {\n return \"Distributooor 1.1.0\";\n }\n\n /// @notice {IERC165-supportsInterface}\n function supportsInterface(\n bytes4 interfaceId\n ) public view virtual override returns (bool) {\n return\n interfaceId == type(TypeAndVersion).interfaceId ||\n interfaceId == type(IERC721Receiver).interfaceId ||\n interfaceId == type(IERC1155Receiver).interfaceId;\n }\n\n /// @notice Revert if raffle has not yet been finalised\n modifier onlyCommittedRaffle() {\n uint256 raffleId_ = raffleId;\n require(\n raffleId_ != 0 &&\n IRaffleChef(raffleChef).getRaffleState(raffleId_) ==\n IRaffleChef.RaffleState.Committed,\n \"Raffle is not yet finalised\"\n );\n _;\n }\n\n /// @notice Revert if raffle has not yet reached activation\n modifier onlyAfterActivation() {\n if (!isReadyForActivation()) {\n revert RaffleActivationPending(\n raffleActivationTimestamp - block.timestamp\n );\n }\n _;\n }\n\n /// @notice Revert if raffle has not passed its deadline\n modifier onlyAfterExpiry() {\n if (!isPrizeExpired()) {\n revert PrizeExpiryTimestampPending(\n prizeExpiryTimestamp - block.timestamp\n );\n }\n _;\n }\n\n modifier onlyFactory() {\n if (_msgSender() != distributooorFactory) {\n revert Unauthorised(_msgSender());\n }\n _;\n }\n\n function isReadyForActivation() public view returns (bool) {\n return block.timestamp >= raffleActivationTimestamp;\n }\n\n function isPrizeExpired() public view returns (bool) {\n return block.timestamp >= prizeExpiryTimestamp;\n }\n\n /// @notice Verify that a proof is valid, and that it is part of the set of\n /// winners. Revert otherwise. A winner is defined as an account that\n /// has a shuffled index x' s.t. x' < nWinners\n /// @param leaf The leaf value representing the participant\n /// @param index Index of account in original participants list\n /// @param proof Merkle proof of inclusion of account in original\n /// participants list\n /// @return permuted index\n function _verifyAndRecordClaim(\n bytes32 leaf,\n uint256 index,\n bytes32[] memory proof\n ) internal virtual onlyCommittedRaffle returns (uint256) {\n (bool isWinner, uint256 permutedIndex) = IRaffleChef(raffleChef)\n .verifyRaffleWinner(raffleId, leaf, proof, index);\n // Nullifier identifies a unique entry in the merkle tree\n bytes32 nullifier = keccak256(abi.encode(leaf, index));\n require(isWinner, \"Not a raffle winner\");\n require(!hasClaimed[nullifier], \"Already claimed\");\n hasClaimed[nullifier] = true;\n return permutedIndex;\n }\n\n /// @notice Check if preimage of `leaf` is a winner\n /// @param leaf Hash of entry\n /// @param index Index of account in original participants list\n /// @param proof Merkle proof of inclusion of account in original\n /// participants list\n function check(\n bytes32 leaf,\n uint256 index,\n bytes32[] calldata proof\n )\n external\n view\n onlyCommittedRaffle\n returns (bool isWinner, uint256 permutedIndex)\n {\n (isWinner, permutedIndex) = IRaffleChef(raffleChef).verifyRaffleWinner(\n raffleId,\n leaf,\n proof,\n index\n );\n }\n\n function checkSig(\n address expectedSigner,\n bytes32 messageHash,\n bytes calldata signature\n ) public pure returns (bool, address) {\n // signature should be in the format (r,s,v)\n address recoveredSigner = ECDSA.recover(messageHash, signature);\n bool isValid = expectedSigner == recoveredSigner;\n return (isValid, recoveredSigner);\n }\n\n /// @notice Claim a prize from the contract. The caller must be included in\n /// the Merkle tree of participants.\n /// @param index IndpermutedIndexccount in original participants list\n /// @param proof Merkle proof of inclusion of account in original\n /// participants list\n function claim(\n uint256 index,\n bytes32[] calldata proof\n ) external onlyCommittedRaffle {\n address claimooor = _msgSender();\n bytes32 hashedLeaf = keccak256(abi.encodePacked(claimooor));\n\n uint256 permutedIndex = _verifyAndRecordClaim(hashedLeaf, index, proof);\n\n // Decode the prize & transfer it to claimooor\n bytes memory rawPrize = prizes[permutedIndex];\n PrizeType prizeType = _getPrizeType(rawPrize);\n if (prizeType == PrizeType.ERC721) {\n (address nftContract, uint256 tokenId) = _getERC721Prize(rawPrize);\n IERC721(nftContract).safeTransferFrom(\n address(this),\n claimooor,\n tokenId\n );\n } else if (prizeType == PrizeType.ERC1155) {\n (\n address nftContract,\n uint256 tokenId,\n uint256 amount\n ) = _getERC1155Prize(rawPrize);\n IERC1155(nftContract).safeTransferFrom(\n address(this),\n claimooor,\n tokenId,\n amount,\n bytes(\"\")\n );\n }\n\n emit Claimed(claimooor, index, permutedIndex);\n }\n\n function requestMerkleRoot(\n uint256 chainId,\n address collectooorFactory,\n address collectooor\n ) external onlyAfterActivation onlyOwner {\n IDistributooorFactory(distributooorFactory).requestMerkleRoot(\n chainId,\n collectooorFactory,\n collectooor\n );\n }\n\n /// @notice See {IDistributooor-receiveParticipantsMerkleRoot}\n function receiveParticipantsMerkleRoot(\n uint256 srcChainId,\n address srcCollector,\n uint256 blockNumber,\n bytes32 merkleRoot_,\n uint256 nParticipants_\n ) external onlyAfterActivation onlyFactory {\n if (raffleId != 0 || merkleRoot != 0 || nParticipants != 0) {\n // Only allow merkle root to be received once;\n // otherwise it's already finalised\n revert MerkleRootRejected(merkleRoot_, nParticipants_, blockNumber);\n }\n if (randRequestId != 0 && block.timestamp - lastRandRequest < 1 hours) {\n // Allow retrying a VRF call if 1 hour has passed\n revert RandomRequestInFlight(randRequestId);\n }\n lastRandRequest = block.timestamp;\n\n merkleRoot = merkleRoot_;\n nParticipants = nParticipants_;\n emit MerkleRootReceived(merkleRoot_, nParticipants_, blockNumber);\n\n provenance = string(\n abi.encodePacked(\n srcChainId.toString(),\n \":\",\n srcCollector.toHexString()\n )\n );\n\n // Next step: call VRF\n randRequestId = IRandomiser(randomiser).getRandomNumber(address(this));\n }\n\n /// @notice See {IRandomiserCallback}\n function receiveRandomWords(\n uint256 requestId,\n uint256[] calldata randomWords\n ) external {\n if (_msgSender() != randomiser) {\n revert UnknownRandomiser(_msgSender());\n }\n if (randRequestId != requestId) {\n revert InvalidRequestId(requestId);\n }\n if (merkleRoot == 0 || nParticipants == 0) {\n revert MerkleRootNotReady(requestId);\n }\n if (raffleId != 0) {\n revert AlreadyFinalised(raffleId);\n }\n if (randomWords.length == 0) {\n revert InvalidRandomWords(randomWords);\n }\n\n // Finalise raffle\n bytes32 merkleRoot_ = merkleRoot;\n uint256 nParticipants_ = nParticipants;\n uint256 randomness = randomWords[0];\n string memory provenance_ = provenance;\n uint256 raffleId_ = IRaffleChef(raffleChef).commit(\n merkleRoot_,\n nParticipants_,\n prizes.length,\n provenance_,\n randomness\n );\n raffleId = raffleId_;\n\n emit Finalised(\n raffleId_,\n merkleRoot_,\n nParticipants_,\n randomness,\n provenance_\n );\n }\n\n /// @notice Load a prize into this contract as the nth prize where\n /// n == |prizes|\n function onERC721Received(\n address,\n address,\n uint256 tokenId,\n bytes calldata\n ) external returns (bytes4) {\n _addERC721Prize(_msgSender(), tokenId);\n return this.onERC721Received.selector;\n }\n\n /// @notice Add prize as nth prize if ERC721 token is already loaded into\n /// this contract.\n /// @param nftContract NFT contract address\n /// @param tokenId Token ID of the NFT to accept\n function _addERC721Prize(address nftContract, uint256 tokenId) internal {\n // Ensure that this contract actually has custody of the ERC721\n if (IERC721(nftContract).ownerOf(tokenId) != address(this)) {\n revert ERC721NotReceived(nftContract, tokenId);\n }\n\n // Record prize\n bytes memory prize = abi.encode(\n uint8(PrizeType.ERC721),\n nftContract,\n tokenId\n );\n prizes.push(prize);\n emit ERC721Received(nftContract, tokenId);\n }\n\n /// @notice Load prize(s) into this contract. If amount > 1, then\n /// prizes are inserted sequentially as individual prizes.\n function onERC1155Received(\n address,\n address,\n uint256 id,\n uint256 amount,\n bytes calldata options\n ) external returns (bytes4) {\n bool isSinglePrize;\n if (options.length > 0) {\n isSinglePrize = abi.decode(options, (bool));\n }\n\n if (isSinglePrize) {\n _addERC1155Prize(_msgSender(), id, amount);\n } else {\n for (uint256 i; i < amount; ++i) {\n _addERC1155Prize(_msgSender(), id, 1);\n }\n }\n return this.onERC1155Received.selector;\n }\n\n /// @notice Load prize(s) into this contract. If amount > 1, then\n /// prizes are inserted sequentially as individual prizes.\n function onERC1155BatchReceived(\n address,\n address,\n uint256[] calldata ids,\n uint256[] calldata amounts,\n bytes calldata options\n ) external returns (bytes4) {\n require(ids.length == amounts.length);\n\n bool isSinglePrize;\n if (options.length > 0) {\n isSinglePrize = abi.decode(options, (bool));\n }\n\n for (uint256 i; i < ids.length; ++i) {\n if (isSinglePrize) {\n _addERC1155Prize(_msgSender(), ids[i], amounts[i]);\n } else {\n for (uint256 j; j < amounts[i]; ++j) {\n _addERC1155Prize(_msgSender(), ids[i], 1);\n }\n }\n }\n return this.onERC1155BatchReceived.selector;\n }\n\n /// @notice Add prize as nth prize if ERC1155 token is already loaded into\n /// this contract.\n /// @notice NB: The contract does not check that there is enough ERC1155\n /// tokens to distribute as prizes.\n /// @param nftContract NFT contract address\n /// @param tokenId Token ID of the NFT to accept\n /// @param amount Amount of ERC1155 tokens\n function _addERC1155Prize(\n address nftContract,\n uint256 tokenId,\n uint256 amount\n ) internal {\n // Ensure that this contract actually has custody of the ERC721\n if (IERC1155(nftContract).balanceOf(nftContract, tokenId) >= amount) {\n revert ERC1155NotReceived(nftContract, tokenId, amount);\n }\n\n // Record prize\n bytes memory prize = abi.encode(\n uint8(PrizeType.ERC1155),\n nftContract,\n tokenId,\n amount\n );\n prizes.push(prize);\n emit ERC1155Received(nftContract, tokenId, amount);\n }\n\n /// @notice Add k ERC1155 tokens as the [n+0..n+k)th prizes\n /// @notice NB: The contract does not check that there is enough ERC1155\n /// tokens to distribute as prizes.\n /// @param nftContract NFT contract address\n /// @param tokenId Token ID of the NFT to accept\n /// @param amount Amount of ERC1155 tokens\n function _addERC1155SequentialPrizes(\n address nftContract,\n uint256 tokenId,\n uint256 amount\n ) internal {\n // Ensure that this contract actually has custody of the ERC721\n if (IERC1155(nftContract).balanceOf(nftContract, tokenId) >= amount) {\n revert ERC1155NotReceived(nftContract, tokenId, amount);\n }\n\n // Record prizes\n for (uint256 i; i < amount; ++i) {\n bytes memory prize = abi.encode(\n uint8(PrizeType.ERC1155),\n nftContract,\n tokenId,\n 1\n );\n prizes.push(prize);\n }\n }\n\n function _getPrizeType(\n bytes memory prize\n ) internal pure returns (PrizeType) {\n uint8 rawType;\n assembly {\n rawType := and(mload(add(prize, 0x20)), 0xff)\n }\n if (rawType > 1) {\n revert InvalidPrizeType(rawType);\n }\n return PrizeType(rawType);\n }\n\n function _getERC721Prize(\n bytes memory prize\n ) internal pure returns (address nftContract, uint256 tokenId) {\n (, nftContract, tokenId) = abi.decode(prize, (uint8, address, uint256));\n }\n\n function _getERC1155Prize(\n bytes memory prize\n )\n internal\n pure\n returns (address nftContract, uint256 tokenId, uint256 amount)\n {\n (, nftContract, tokenId, amount) = abi.decode(\n prize,\n (uint8, address, uint256, uint256)\n );\n }\n\n /// @notice Self-explanatory\n function getPrizeCount() public view returns (uint256) {\n return prizes.length;\n }\n\n /// @notice Get a slice of the prize list at the desired offset. The prize\n /// list is represented in raw bytes, with the 0th byte signifying\n /// whether it's an ERC-721 or ERC-1155 prize. See {_getPrizeType},\n /// {_getERC721Prize}, and {_getERC1155Prize} functions for how to\n /// decode each prize.\n /// @param offset Prize index to start slice at (0-based)\n /// @param limit How many prizes to fetch at maximum (may return fewer)\n function getPrizes(\n uint256 offset,\n uint256 limit\n ) public view returns (bytes[] memory prizes_) {\n uint256 len = prizes.length;\n if (len == 0 || offset >= prizes.length) {\n return new bytes[](0);\n }\n limit = offset + limit >= prizes.length\n ? prizes.length - offset\n : limit;\n prizes_ = new bytes[](limit);\n for (uint256 i; i < limit; ++i) {\n prizes_[i] = prizes[offset + i];\n }\n }\n\n /// @notice Withdraw ERC721 after deadline has passed\n function withdrawERC721(\n address nftContract,\n uint256 tokenId\n ) external onlyOwner onlyAfterExpiry {\n IERC721(nftContract).safeTransferFrom(\n address(this),\n _msgSender(),\n tokenId\n );\n emit ERC721Reclaimed(nftContract, tokenId);\n }\n\n /// @notice Withdraw ERC1155 after deadline has passed\n function withdrawERC1155(\n address nftContract,\n uint256 tokenId,\n uint256 amount\n ) external onlyOwner onlyAfterExpiry {\n IERC1155(nftContract).safeTransferFrom(\n address(this),\n _msgSender(),\n tokenId,\n amount,\n bytes(\"\")\n );\n emit ERC1155Reclaimed(nftContract, tokenId, amount);\n }\n}\n" }, "contracts/interfaces/IDistributooor.sol": { "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity 0.8.17;\n\ninterface IDistributooor {\n /// @notice Receive a merkle root from a trusted source.\n /// @param srcChainId Chain ID where the Merkle collector lives\n /// @param srcCollector Contract address of Merkle collector\n /// @param blockNumber Block number at which the Merkle root was calculated\n /// @param merkleRoot Merkle root of participants\n /// @param nParticipants Number of participants in the merkle tree\n function receiveParticipantsMerkleRoot(\n uint256 srcChainId,\n address srcCollector,\n uint256 blockNumber,\n bytes32 merkleRoot,\n uint256 nParticipants\n ) external;\n\n event MerkleRootReceived(\n bytes32 merkleRoot,\n uint256 nParticipants,\n uint256 blockNumber\n );\n\n event ERC721Received(address nftContract, uint256 tokenId);\n event ERC1155Received(address nftContract, uint256 tokenId, uint256 amount);\n event ERC721Reclaimed(address nftContract, uint256 tokenId);\n event ERC1155Reclaimed(\n address nftContract,\n uint256 tokenId,\n uint256 amount\n );\n event Finalised(\n uint256 raffleId,\n bytes32 merkleRoot,\n uint256 nParticipants,\n uint256 randomness,\n string provenance\n );\n\n error Unauthorised(address caller);\n error MerkleRootRejected(\n bytes32 merkleRoot,\n uint256 nParticipants,\n uint256 blockNumber\n );\n error InvalidSignature(\n bytes signature,\n address expectedSigner,\n address recoveredSigner\n );\n error InvalidRequestId(uint256 requestId);\n error MerkleRootNotReady(uint256 requestId);\n error AlreadyFinalised(uint256 raffleId);\n}\n" }, "contracts/interfaces/IDistributooorFactory.sol": { "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity 0.8.17;\n\ninterface IDistributooorFactory {\n enum CrossChainAction {\n ReceiveMerkleRoot\n }\n\n struct ReceiveMerkleRootParams {\n /// @notice Original requester of merkle root\n address requester;\n /// @notice Merkle root collector\n address collectooor;\n uint256 blockNumber;\n bytes32 merkleRoot;\n uint256 nodeCount;\n }\n\n event DistributooorMasterCopyUpdated(\n address oldMasterCopy,\n address newMasterCopy\n );\n event DistributooorDeployed(address distributooor);\n event RaffleChefUpdated(address oldRaffleChef, address newRaffleChef);\n\n error UnknownConsumer(address consumer);\n\n /// @notice Request merkle root from an external collectooor\n function requestMerkleRoot(\n uint256 chainId,\n address collectooorFactory,\n address collectooor\n ) external;\n}\n" }, "contracts/interfaces/IRaffleChef.sol": { "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity 0.8.17;\n\ninterface IRaffleChef {\n event RaffleCreated(uint256 indexed raffleId);\n event RaffleCommitted(uint256 indexed raffleId);\n\n error RaffleNotRolled(uint256 raffleId);\n error InvalidCommitment(\n uint256 raffleId,\n bytes32 merkleRoot,\n uint256 nParticipants,\n uint256 nWinners,\n uint256 randomness,\n string provenance\n );\n error Unauthorised(address unauthorisedUser);\n error StartingRaffleIdTooLow(uint256 raffleId);\n error InvalidProof(bytes32 leaf, bytes32[] proof);\n\n /// @dev Descriptive state of a raffle based on its variables that are set/unset\n enum RaffleState {\n /// @dev Default state\n Unknown,\n /// @dev Done\n Committed\n }\n\n /// @notice Structure of every raffle; presence of certain elements indicate the raffle state\n struct Raffle {\n bytes32 participantsMerkleRoot;\n uint256 nParticipants;\n uint256 nWinners;\n uint256 randomSeed;\n address owner;\n string provenance;\n }\n\n /// @notice Publish a commitment (the merkle root of the finalised participants list, and\n /// the number of winners to draw, and the random seed). Only call this function once\n /// the random seed and list of raffle participants has finished being collected.\n /// @param participantsMerkleRoot Merkle root constructed from finalised participants list\n /// @param nWinners Number of winners to draw\n /// @param provenance IPFS CID of this raffle's provenance including full participants list\n /// @param randomness Random seed for the raffle\n /// @return Raffle ID that can be used to lookup the raffle results, when\n /// the raffle is finalised.\n function commit(\n bytes32 participantsMerkleRoot,\n uint256 nParticipants,\n uint256 nWinners,\n string calldata provenance,\n uint256 randomness\n ) external returns (uint256);\n\n /// @notice Verify that an account is in the winners list for a specific raffle\n /// using a merkle proof and the raffle's previous public commitments. This is\n /// a view-only function that does not record if a winner has already claimed\n /// their win; that is left up to the caller to handle.\n /// @param raffleId ID of the raffle to check against\n /// @param leafHash Hash of the leaf value that represents the participant\n /// @param proof Merkle subproof (hashes)\n /// @param originalIndex Original leaf index in merkle tree, part of merkle proof\n /// @return isWinner true if claiming account is indeed a winner\n /// @return permutedIndex winning (shuffled) index\n function verifyRaffleWinner(\n uint256 raffleId,\n bytes32 leafHash,\n bytes32[] calldata proof,\n uint256 originalIndex\n ) external view returns (bool isWinner, uint256 permutedIndex);\n\n /// @notice Get an existing raffle\n /// @param raffleId ID of raffle to get\n /// @return raffle data, if it exists\n function getRaffle(uint256 raffleId) external view returns (Raffle memory);\n\n /// @notice Get the current state of raffle, given a `raffleId`\n /// @param raffleId ID of raffle to get\n /// @return See {RaffleState} enum\n function getRaffleState(\n uint256 raffleId\n ) external view returns (RaffleState);\n}\n" }, "contracts/interfaces/IRandomiser.sol": { "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity 0.8.17;\n\ninterface IRandomiser {\n function getRandomNumber(\n address callbackContract\n ) external returns (uint256 requestId);\n}\n" }, "contracts/interfaces/IRandomiserCallback.sol": { "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8;\n\ninterface IRandomiserCallback {\n function receiveRandomWords(\n uint256 requestId,\n uint256[] calldata randomWords\n ) external;\n}\n" }, "contracts/interfaces/TypeAndVersion.sol": { "content": "// SPDX-License-Identifier: MIT\n/**\n The MIT License (MIT)\n\n Copyright (c) 2018 SmartContract ChainLink, Ltd.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n*/\n\npragma solidity ^0.8;\n\nabstract contract TypeAndVersion {\n function typeAndVersion() external pure virtual returns (string memory);\n}\n" } }, "settings": { "viaIR": true, "optimizer": { "enabled": true, "runs": 1000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} } }