zellic-audit
Initial commit
f998fcd
raw
history blame
No virus
98.5 kB
{
"language": "Solidity",
"settings": {
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 100
},
"remappings": [],
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
},
"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/interfaces/IERC2981Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (interfaces/IERC2981.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/introspection/IERC165Upgradeable.sol\";\n\n/**\n * @dev Interface for the NFT Royalty Standard.\n *\n * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal\n * support for royalty payments across all NFT marketplaces and ecosystem participants.\n *\n * _Available since v4.5._\n */\ninterface IERC2981Upgradeable is IERC165Upgradeable {\n /**\n * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of\n * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.\n */\n function royaltyInfo(uint256 tokenId, uint256 salePrice)\n external\n view\n returns (address receiver, uint256 royaltyAmount);\n}\n"
},
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (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. Equivalent to `reinitializer(1)`.\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 * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original\n * initialization step. This is essential to configure modules that are added through upgrades and that require\n * initialization.\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 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 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"
},
"@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20Upgradeable {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
},
"@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/ERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC721Upgradeable.sol\";\nimport \"./IERC721ReceiverUpgradeable.sol\";\nimport \"./extensions/IERC721MetadataUpgradeable.sol\";\nimport \"../../utils/AddressUpgradeable.sol\";\nimport \"../../utils/ContextUpgradeable.sol\";\nimport \"../../utils/StringsUpgradeable.sol\";\nimport \"../../utils/introspection/ERC165Upgradeable.sol\";\nimport \"../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including\n * the Metadata extension, but not including the Enumerable extension, which is available separately as\n * {ERC721Enumerable}.\n */\ncontract ERC721Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721Upgradeable, IERC721MetadataUpgradeable {\n using AddressUpgradeable for address;\n using StringsUpgradeable for uint256;\n\n // Token name\n string private _name;\n\n // Token symbol\n string private _symbol;\n\n // Mapping from token ID to owner address\n mapping(uint256 => address) private _owners;\n\n // Mapping owner address to token count\n mapping(address => uint256) private _balances;\n\n // Mapping from token ID to approved address\n mapping(uint256 => address) private _tokenApprovals;\n\n // Mapping from owner to operator approvals\n mapping(address => mapping(address => bool)) private _operatorApprovals;\n\n /**\n * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.\n */\n function __ERC721_init(string memory name_, string memory symbol_) internal onlyInitializing {\n __ERC721_init_unchained(name_, symbol_);\n }\n\n function __ERC721_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) {\n return\n interfaceId == type(IERC721Upgradeable).interfaceId ||\n interfaceId == type(IERC721MetadataUpgradeable).interfaceId ||\n super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev See {IERC721-balanceOf}.\n */\n function balanceOf(address owner) public view virtual override returns (uint256) {\n require(owner != address(0), \"ERC721: address zero is not a valid owner\");\n return _balances[owner];\n }\n\n /**\n * @dev See {IERC721-ownerOf}.\n */\n function ownerOf(uint256 tokenId) public view virtual override returns (address) {\n address owner = _owners[tokenId];\n require(owner != address(0), \"ERC721: invalid token ID\");\n return owner;\n }\n\n /**\n * @dev See {IERC721Metadata-name}.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev See {IERC721Metadata-symbol}.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev See {IERC721Metadata-tokenURI}.\n */\n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\n _requireMinted(tokenId);\n\n string memory baseURI = _baseURI();\n return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : \"\";\n }\n\n /**\n * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each\n * token will be the concatenation of the `baseURI` and the `tokenId`. Empty\n * by default, can be overridden in child contracts.\n */\n function _baseURI() internal view virtual returns (string memory) {\n return \"\";\n }\n\n /**\n * @dev See {IERC721-approve}.\n */\n function approve(address to, uint256 tokenId) public virtual override {\n address owner = ERC721Upgradeable.ownerOf(tokenId);\n require(to != owner, \"ERC721: approval to current owner\");\n\n require(\n _msgSender() == owner || isApprovedForAll(owner, _msgSender()),\n \"ERC721: approve caller is not token owner nor approved for all\"\n );\n\n _approve(to, tokenId);\n }\n\n /**\n * @dev See {IERC721-getApproved}.\n */\n function getApproved(uint256 tokenId) public view virtual override returns (address) {\n _requireMinted(tokenId);\n\n return _tokenApprovals[tokenId];\n }\n\n /**\n * @dev See {IERC721-setApprovalForAll}.\n */\n function setApprovalForAll(address operator, bool approved) public virtual override {\n _setApprovalForAll(_msgSender(), operator, approved);\n }\n\n /**\n * @dev See {IERC721-isApprovedForAll}.\n */\n function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {\n return _operatorApprovals[owner][operator];\n }\n\n /**\n * @dev See {IERC721-transferFrom}.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public virtual override {\n //solhint-disable-next-line max-line-length\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: caller is not token owner nor approved\");\n\n _transfer(from, to, tokenId);\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public virtual override {\n safeTransferFrom(from, to, tokenId, \"\");\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes memory data\n ) public virtual override {\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: caller is not token owner nor approved\");\n _safeTransfer(from, to, tokenId, data);\n }\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 * `data` is additional data, it has no specified format and it is sent in call to `to`.\n *\n * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.\n * implement alternative mechanisms to perform token transfer, such as signature-based.\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 `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 _safeTransfer(\n address from,\n address to,\n uint256 tokenId,\n bytes memory data\n ) internal virtual {\n _transfer(from, to, tokenId);\n require(_checkOnERC721Received(from, to, tokenId, data), \"ERC721: transfer to non ERC721Receiver implementer\");\n }\n\n /**\n * @dev Returns whether `tokenId` exists.\n *\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\n *\n * Tokens start existing when they are minted (`_mint`),\n * and stop existing when they are burned (`_burn`).\n */\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\n return _owners[tokenId] != address(0);\n }\n\n /**\n * @dev Returns whether `spender` is allowed to manage `tokenId`.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {\n address owner = ERC721Upgradeable.ownerOf(tokenId);\n return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);\n }\n\n /**\n * @dev Safely mints `tokenId` and transfers it to `to`.\n *\n * Requirements:\n *\n * - `tokenId` must not exist.\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 _safeMint(address to, uint256 tokenId) internal virtual {\n _safeMint(to, tokenId, \"\");\n }\n\n /**\n * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is\n * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.\n */\n function _safeMint(\n address to,\n uint256 tokenId,\n bytes memory data\n ) internal virtual {\n _mint(to, tokenId);\n require(\n _checkOnERC721Received(address(0), to, tokenId, data),\n \"ERC721: transfer to non ERC721Receiver implementer\"\n );\n }\n\n /**\n * @dev Mints `tokenId` and transfers it to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible\n *\n * Requirements:\n *\n * - `tokenId` must not exist.\n * - `to` cannot be the zero address.\n *\n * Emits a {Transfer} event.\n */\n function _mint(address to, uint256 tokenId) internal virtual {\n require(to != address(0), \"ERC721: mint to the zero address\");\n require(!_exists(tokenId), \"ERC721: token already minted\");\n\n _beforeTokenTransfer(address(0), to, tokenId);\n\n _balances[to] += 1;\n _owners[tokenId] = to;\n\n emit Transfer(address(0), to, tokenId);\n\n _afterTokenTransfer(address(0), to, tokenId);\n }\n\n /**\n * @dev Destroys `tokenId`.\n * The approval is cleared when the token is burned.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n *\n * Emits a {Transfer} event.\n */\n function _burn(uint256 tokenId) internal virtual {\n address owner = ERC721Upgradeable.ownerOf(tokenId);\n\n _beforeTokenTransfer(owner, address(0), tokenId);\n\n // Clear approvals\n _approve(address(0), tokenId);\n\n _balances[owner] -= 1;\n delete _owners[tokenId];\n\n emit Transfer(owner, address(0), tokenId);\n\n _afterTokenTransfer(owner, address(0), tokenId);\n }\n\n /**\n * @dev Transfers `tokenId` from `from` to `to`.\n * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n *\n * Emits a {Transfer} event.\n */\n function _transfer(\n address from,\n address to,\n uint256 tokenId\n ) internal virtual {\n require(ERC721Upgradeable.ownerOf(tokenId) == from, \"ERC721: transfer from incorrect owner\");\n require(to != address(0), \"ERC721: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, tokenId);\n\n // Clear approvals from the previous owner\n _approve(address(0), tokenId);\n\n _balances[from] -= 1;\n _balances[to] += 1;\n _owners[tokenId] = to;\n\n emit Transfer(from, to, tokenId);\n\n _afterTokenTransfer(from, to, tokenId);\n }\n\n /**\n * @dev Approve `to` to operate on `tokenId`\n *\n * Emits an {Approval} event.\n */\n function _approve(address to, uint256 tokenId) internal virtual {\n _tokenApprovals[tokenId] = to;\n emit Approval(ERC721Upgradeable.ownerOf(tokenId), to, tokenId);\n }\n\n /**\n * @dev Approve `operator` to operate on all of `owner` tokens\n *\n * Emits an {ApprovalForAll} event.\n */\n function _setApprovalForAll(\n address owner,\n address operator,\n bool approved\n ) internal virtual {\n require(owner != operator, \"ERC721: approve to caller\");\n _operatorApprovals[owner][operator] = approved;\n emit ApprovalForAll(owner, operator, approved);\n }\n\n /**\n * @dev Reverts if the `tokenId` has not been minted yet.\n */\n function _requireMinted(uint256 tokenId) internal view virtual {\n require(_exists(tokenId), \"ERC721: invalid token ID\");\n }\n\n /**\n * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.\n * The call is not executed if the target address is not a contract.\n *\n * @param from address representing the previous owner of the given token ID\n * @param to target address that will receive the tokens\n * @param tokenId uint256 ID of the token to be transferred\n * @param data bytes optional data to send along with the call\n * @return bool whether the call correctly returned the expected magic value\n */\n function _checkOnERC721Received(\n address from,\n address to,\n uint256 tokenId,\n bytes memory data\n ) private returns (bool) {\n if (to.isContract()) {\n try IERC721ReceiverUpgradeable(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {\n return retval == IERC721ReceiverUpgradeable.onERC721Received.selector;\n } catch (bytes memory reason) {\n if (reason.length == 0) {\n revert(\"ERC721: transfer to non ERC721Receiver implementer\");\n } else {\n /// @solidity memory-safe-assembly\n assembly {\n revert(add(32, reason), mload(reason))\n }\n }\n }\n } else {\n return true;\n }\n }\n\n /**\n * @dev Hook that is called before any token transfer. This includes minting\n * and burning.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be\n * transferred to `to`.\n * - When `from` is zero, `tokenId` will be minted for `to`.\n * - When `to` is zero, ``from``'s `tokenId` will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 tokenId\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 tokenId\n ) internal virtual {}\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[44] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.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 IERC721ReceiverUpgradeable {\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-upgradeable/token/ERC721/IERC721Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165Upgradeable.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721Upgradeable is IERC165Upgradeable {\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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\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-upgradeable/token/ERC721/extensions/IERC721MetadataUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC721Upgradeable.sol\";\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\n * @dev See https://eips.ethereum.org/EIPS/eip-721\n */\ninterface IERC721MetadataUpgradeable is IERC721Upgradeable {\n /**\n * @dev Returns the token collection name.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the token collection symbol.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n */\n function tokenURI(uint256 tokenId) external view returns (string memory);\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.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 functionCall(target, data, \"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 require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(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 require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason 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 // 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}\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-upgradeable/utils/StringsUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary StringsUpgradeable {\n bytes16 private constant _HEX_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 // Inspired by OraclizeAPI's implementation - MIT licence\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n if (value == 0) {\n return \"0\";\n }\n uint256 temp = value;\n uint256 digits;\n while (temp != 0) {\n digits++;\n temp /= 10;\n }\n bytes memory buffer = new bytes(digits);\n while (value != 0) {\n digits -= 1;\n buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n value /= 10;\n }\n return string(buffer);\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 if (value == 0) {\n return \"0x00\";\n }\n uint256 temp = value;\n uint256 length = 0;\n while (temp != 0) {\n length++;\n temp >>= 8;\n }\n return toHexString(value, length);\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] = _HEX_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"
},
"@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165Upgradeable.sol\";\nimport \"../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {\n function __ERC165_init() internal onlyInitializing {\n }\n\n function __ERC165_init_unchained() internal onlyInitializing {\n }\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165Upgradeable).interfaceId;\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-upgradeable/utils/introspection/IERC165Upgradeable.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 IERC165Upgradeable {\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"
},
"base64-sol/base64.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0;\n\n/// @title Base64\n/// @author Brecht Devos - <brecht@loopring.org>\n/// @notice Provides functions for encoding/decoding base64\nlibrary Base64 {\n string internal constant TABLE_ENCODE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n bytes internal constant TABLE_DECODE = hex\"0000000000000000000000000000000000000000000000000000000000000000\"\n hex\"00000000000000000000003e0000003f3435363738393a3b3c3d000000000000\"\n hex\"00000102030405060708090a0b0c0d0e0f101112131415161718190000000000\"\n hex\"001a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132330000000000\";\n\n function encode(bytes memory data) internal pure returns (string memory) {\n if (data.length == 0) return '';\n\n // load the table into memory\n string memory table = TABLE_ENCODE;\n\n // multiply by 4/3 rounded up\n uint256 encodedLen = 4 * ((data.length + 2) / 3);\n\n // add some extra buffer at the end required for the writing\n string memory result = new string(encodedLen + 32);\n\n assembly {\n // set the actual output length\n mstore(result, encodedLen)\n\n // prepare the lookup table\n let tablePtr := add(table, 1)\n\n // input ptr\n let dataPtr := data\n let endPtr := add(dataPtr, mload(data))\n\n // result ptr, jump over length\n let resultPtr := add(result, 32)\n\n // run over the input, 3 bytes at a time\n for {} lt(dataPtr, endPtr) {}\n {\n // read 3 bytes\n dataPtr := add(dataPtr, 3)\n let input := mload(dataPtr)\n\n // write 4 characters\n mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))\n resultPtr := add(resultPtr, 1)\n mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))\n resultPtr := add(resultPtr, 1)\n mstore8(resultPtr, mload(add(tablePtr, and(shr( 6, input), 0x3F))))\n resultPtr := add(resultPtr, 1)\n mstore8(resultPtr, mload(add(tablePtr, and( input, 0x3F))))\n resultPtr := add(resultPtr, 1)\n }\n\n // padding with '='\n switch mod(mload(data), 3)\n case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) }\n case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) }\n }\n\n return result;\n }\n\n function decode(string memory _data) internal pure returns (bytes memory) {\n bytes memory data = bytes(_data);\n\n if (data.length == 0) return new bytes(0);\n require(data.length % 4 == 0, \"invalid base64 decoder input\");\n\n // load the table into memory\n bytes memory table = TABLE_DECODE;\n\n // every 4 characters represent 3 bytes\n uint256 decodedLen = (data.length / 4) * 3;\n\n // add some extra buffer at the end required for the writing\n bytes memory result = new bytes(decodedLen + 32);\n\n assembly {\n // padding with '='\n let lastBytes := mload(add(data, mload(data)))\n if eq(and(lastBytes, 0xFF), 0x3d) {\n decodedLen := sub(decodedLen, 1)\n if eq(and(lastBytes, 0xFFFF), 0x3d3d) {\n decodedLen := sub(decodedLen, 1)\n }\n }\n\n // set the actual output length\n mstore(result, decodedLen)\n\n // prepare the lookup table\n let tablePtr := add(table, 1)\n\n // input ptr\n let dataPtr := data\n let endPtr := add(dataPtr, mload(data))\n\n // result ptr, jump over length\n let resultPtr := add(result, 32)\n\n // run over the input, 4 characters at a time\n for {} lt(dataPtr, endPtr) {}\n {\n // read 4 characters\n dataPtr := add(dataPtr, 4)\n let input := mload(dataPtr)\n\n // write 3 bytes\n let output := add(\n add(\n shl(18, and(mload(add(tablePtr, and(shr(24, input), 0xFF))), 0xFF)),\n shl(12, and(mload(add(tablePtr, and(shr(16, input), 0xFF))), 0xFF))),\n add(\n shl( 6, and(mload(add(tablePtr, and(shr( 8, input), 0xFF))), 0xFF)),\n and(mload(add(tablePtr, and( input , 0xFF))), 0xFF)\n )\n )\n mstore(resultPtr, shl(232, output))\n resultPtr := add(resultPtr, 3)\n }\n }\n\n return result;\n }\n}\n"
},
"contracts/ExpandedNFT.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\n\n/**\n\n ExpandedNFTs\n\n */\n\npragma solidity ^0.8.15;\n\nimport {ERC721Upgradeable} from \"@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol\";\nimport {IERC2981Upgradeable, IERC165Upgradeable} from \"@openzeppelin/contracts-upgradeable/interfaces/IERC2981Upgradeable.sol\";\nimport {OwnableUpgradeable} from \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport {AddressUpgradeable} from \"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\";\nimport {IERC20Upgradeable} from \"@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol\";\n\nimport {SharedNFTLogic} from \"./SharedNFTLogic.sol\";\nimport {IExpandedNFT} from \"./IExpandedNFT.sol\";\n/**\n This is a smart contract for handling dynamic contract minting.\n\n @dev This allows creators to mint a unique serial drop of an expanded NFT within a custom contract\n @author Zien\n Repository: https://github.com/joinzien/expanded-nft\n*/\ncontract ExpandedNFT is\n ERC721Upgradeable,\n IExpandedNFT,\n IERC2981Upgradeable,\n OwnableUpgradeable\n{\n enum WhoCanMint{ ONLY_OWNER, VIPS, MEMBERS, ANYONE }\n\n enum ExpandedNFTStates{ UNMINTED, MINTED, REDEEM_STARTED, SET_OFFER_TERMS, ACCEPTED_OFFER, PRODUCTION_COMPLETE, REDEEMED }\n \n event PriceChanged(uint256 amount);\n event EditionSold(uint256 price, address owner);\n event WhoCanMintChanged(WhoCanMint minters);\n\n // State change events\n event RedeemStarted(uint256 tokenId, address owner);\n event RedeemAborted(uint256 tokenId, address owner); \n event OfferTermsSet(uint256 tokenId);\n event OfferAccepted(uint256 tokenId);\n event OfferRejected(uint256 tokenId);\n event ProductionComplete(uint256 tokenId);\n event DeliveryAccepted(uint256 tokenId);\n\n struct PerToken { \n // Hashmap of the Edition ID to the current \n ExpandedNFTStates editionState;\n\n // Redemption price\n uint256 editionFee; \n\n // Edition description\n string description;\n\n // Minted\n\n // animation_url field in the metadata\n string animationUrl;\n // Hash for the associated animation\n bytes32 animationHash;\n // Image in the metadata\n string imageUrl;\n // Hash for the associated image\n bytes32 imageHash;\n\n // Redeemed\n\n // animation_url field in the metadata\n string redeemedAnimationUrl;\n // Hash for the associated animation\n bytes32 redeemedAnimationHash;\n // Image in the metadata\n string redeemedImageUrl;\n // Hash for the associated image\n bytes32 redeemedImageHash;\n // Condition report in the metadata\n string conditionReportUrl;\n // Hash for the condition report\n bytes32 conditionReportHash;\n }\n\n struct Pricing { \n // Royalty amount in bps\n uint256 royaltyBPS;\n\n // Split amount to the platforms. the artist in bps\n uint256 splitBPS;\n\n // Price for VIP sales\n uint256 vipSalePrice;\n\n // Price for member sales\n uint256 membersSalePrice; \n\n // Price for VIP sales\n uint256 vipMintLimit;\n\n // Price for member sales\n uint256 membersMintLimit;\n\n // Price for general sales\n uint256 generalMintLimit; \n\n // Addresses allowed to mint edition\n mapping(address => bool) allowedMinters;\n // VIP Addresses allowed to mint edition\n mapping(address => bool) vipAllowedMinters;\n\n // Who can currently mint\n WhoCanMint whoCanMint;\n\n // Mint counts for each address\n mapping(address => uint256) mintCounts; \n }\n\n // metadata\n string public description;\n\n // Artists wallet address\n address private _artistWallet;\n\n // Per Token data\n mapping(uint256 => PerToken) private _perTokenMetadata;\n\n // Total size of the drop that can be minted\n uint256 public dropSize;\n\n uint256 private _loadedMetadata;\n\n // reservation list\n uint256 private _reserveCount;\n mapping(uint256 => address) private _reserveAddress;\n mapping(uint256 => uint256) private _reserveTokenId;\n\n mapping(uint256 => bool) private _tokenClaimed; \n uint256 private _claimCount; \n uint256 private _currentIndex;\n\n Pricing private _pricing;\n\n // Price for general sales\n uint256 public salePrice;\n\n // ERC20 interface for the payment token\n IERC20Upgradeable private _paymentTokenERC20;\n\n // NFT rendering logic contract\n SharedNFTLogic private immutable _sharedNFTLogic;\n\n // Global constructor for factory\n constructor(SharedNFTLogic sharedNFTLogic) {\n _sharedNFTLogic = sharedNFTLogic;\n _pricing.whoCanMint = WhoCanMint.ONLY_OWNER;\n }\n\n /**\n @param _owner wallet addres for the user that owns and can mint the drop, gets royalty and sales payouts and can update the base url if needed.\n @param artistWallet wallet address for thr User that created the drop\n @param _name Name of drop, used in the title as \"$NAME NUMBER/TOTAL\"\n @param _symbol Symbol of the new token contract\n @param _dropSize Number of editions that can be minted in total. \n @dev Function to create a new drop. Can only be called by the allowed creator\n Sets the only allowed minter to the address that creates/owns the drop.\n This can be re-assigned or updated later\n */\n function initialize(\n address _owner,\n address artistWallet,\n string memory _name,\n string memory _symbol,\n uint256 _dropSize\n ) public initializer {\n require(_dropSize > 0, \"Drop size must be > 0\");\n\n __ERC721_init(_name, _symbol);\n __Ownable_init();\n\n // Set ownership to original sender of contract call\n transferOwnership(_owner);\n\n _artistWallet = artistWallet;\n dropSize = _dropSize;\n\n // Set edition id start to be 1 not 0\n _claimCount = 0; \n _currentIndex = 1;\n\n // Set the metadata\n description = _name;\n _loadedMetadata = 0; \n }\n\n /**\n @param _description Description of the edition, used in the description field of the NFT\n @param imageUrl Image URL of the the edition. Strongly encouraged to be used, if necessary, only animation URL can be used. One of animation and image url need to exist in a drop to render the NFT.\n @param imageHash SHA256 of the given image in bytes32 format (0xHASH). If no image is included, the hash can be zero.\n @param animationUrl Animation URL of the edition. Not required, but if omitted image URL needs to be included. This follows the opensea spec for NFTs\n @param animationHash The associated hash of the animation in sha-256 bytes32 format. If animation is omitted the hash can be zero.\n @dev Function to create a new drop. Can only be called by the allowed creator\n Sets the only allowed minter to the address that creates/owns the drop.\n This can be re-assigned or updated later\n */\n function loadMetadataChunk(\n uint256 startOffset,\n uint256 count,\n string[] memory _description,\n string[] memory animationUrl,\n bytes32[] memory animationHash,\n string[] memory imageUrl,\n bytes32[] memory imageHash\n\n ) public {\n require(_description.length == count, \"Data size mismatch\");\n require(animationUrl.length == count, \"Data size mismatch\");\n require(animationHash.length == count, \"Data size mismatch\");\n require(imageUrl.length == count, \"Data size mismatch\");\n require(imageHash.length == count, \"Data size mismatch\");\n\n for (uint i = 0; i < count; i++) {\n uint index = startOffset + i + 1;\n \n _perTokenMetadata[index].description = _description[i];\n _perTokenMetadata[index].imageUrl = imageUrl[i];\n _perTokenMetadata[index].imageHash = imageHash[i];\n _perTokenMetadata[index].animationUrl = animationUrl[i];\n _perTokenMetadata[index].animationHash = animationHash[i];\n\n }\n\n _loadedMetadata += count;\n }\n\n function metadataloaded() public view returns (bool){\n return (_loadedMetadata >= dropSize);\n }\n\n /// @dev returns the number of minted tokens within the drop\n function totalSupply() public view returns (uint256) {\n return _claimCount;\n }\n\n /// @dev returns the royalty BPS\n function getRoyaltyBPS() public view returns (uint256) {\n return _pricing.royaltyBPS;\n }\n\n /// @dev returns the split BPS\n function getSplitBPS() public view returns (uint256) {\n return _pricing.splitBPS;\n }\n\n /// @dev returns the VIP sale price\n function getVIPSalePrice() public view returns (uint256) {\n return _pricing.vipSalePrice;\n }\n\n /// @dev returns the member sale price\n function getMembersSalePrice() public view returns (uint256) {\n return _pricing.membersSalePrice;\n }\n\n /// @dev returns the VIP mint limit\n function getVIPMintLimit() public view returns (uint256) {\n return _pricing.vipMintLimit;\n }\n\n /// @dev returns the member mint limit\n function getMembersMintLimit() public view returns (uint256) {\n return _pricing.membersMintLimit;\n }\n\n /// @dev returns the general mint limit\n function getGeneralMintLimit() public view returns (uint256) {\n return salePrice;\n }\n\n /// @dev returns who can mint\n function getWhoCanMint() public view returns (uint256) {\n return uint256(_pricing.whoCanMint);\n }\n\n /**\n Simple eth-based sales function\n More complex sales functions can be implemented through IExpandedNFT interface\n */\n\n /**\n @dev This allows the user to purchase an edition\n at the given price in the contract.\n */\n\n function purchase() external payable returns (uint256) {\n uint256 currentPrice = _currentSalesPrice();\n emit EditionSold(currentPrice, msg.sender);\n\n address[] memory toMint = new address[](1);\n toMint[0] = msg.sender;\n\n return _mintEditionsBody(toMint); \n }\n\n /**\n @param to address to send the newly minted edition to\n @dev This mints one edition to the given address by an allowed minter on the edition instance.\n */\n function mintEdition(address to) external payable override returns (uint256) {\n address[] memory toMint = new address[](1);\n toMint[0] = to;\n\n return _mintEditionsBody(toMint); \n }\n\n /**\n @param recipients list of addresses to send the newly minted editions to\n @dev This mints multiple editions to the given list of addresses.\n */\n function mintEditions(address[] memory recipients)\n external payable override returns (uint256)\n {\n return _mintEditionsBody(recipients);\n } \n\n /**\n @param recipients list of addresses to send the newly minted editions to\n @dev This mints multiple editions to the given list of addresses.\n */\n function _mintEditionsBody(address[] memory recipients)\n internal returns (uint256)\n {\n require(_loadedMetadata >= dropSize, \"Not all metadata loaded\");\n\n require(_isAllowedToMint(), \"Needs to be an allowed minter\");\n\n uint256 currentPrice = _currentSalesPrice();\n require(currentPrice > 0, \"Not for sale\");\n require(msg.value == (currentPrice * recipients.length), \"Wrong price\");\n\n require((_pricing.mintCounts[msg.sender] + recipients.length - 1) < _currentMintLimit(), \"Exceeded mint limit\");\n\n require(_claimCount + recipients.length <= dropSize, \"Over drop size\");\n\n if (_pricing.whoCanMint == WhoCanMint.VIPS) {\n return _vipMintEditions(recipients);\n }\n\n return _mintEditions(recipients);\n } \n\n /**\n @dev Private function to mint without any access checks.\n Called by the public edition minting functions.\n */\n function _vipMintEditions(address[] memory recipients)\n internal\n returns (uint256)\n {\n address currentMinter = msg.sender;\n\n uint256 unclaimed = 0;\n uint256 firstUnclaimed = _reserveCount;\n\n for (uint256 r = 0; r < _reserveCount; r++) {\n if (_reserveAddress[r] == currentMinter) {\n uint256 id = _reserveTokenId[r];\n\n if (_tokenClaimed[id] != true) {\n if (r < firstUnclaimed) {\n firstUnclaimed = r; \n }\n\n unclaimed++;\n }\n }\n }\n\n require(unclaimed >= recipients.length, \"Can not mint all editions\");\n\n uint256 idToMint = 1;\n\n uint256 reservationCounter = firstUnclaimed;\n for (uint256 i = 0; i < recipients.length; i++) {\n while (_reserveAddress[reservationCounter] != currentMinter) {\n reservationCounter++;\n } \n\n idToMint = _reserveTokenId[reservationCounter];\n\n _mint(recipients[i], idToMint);\n\n _perTokenMetadata[idToMint].editionState = ExpandedNFTStates.MINTED;\n _tokenClaimed[idToMint] = true;\n _pricing.mintCounts[currentMinter]++;\n _claimCount++;\n\n reservationCounter++;\n }\n\n return idToMint; \n } \n\n /**\n @dev Private function to mint without any access checks.\n Called by the public edition minting functions.\n */\n function _mintEditions(address[] memory recipients)\n internal\n returns (uint256)\n {\n address currentMinter = msg.sender;\n \n for (uint256 i = 0; i < recipients.length; i++) {\n while (_tokenClaimed[_currentIndex] == true) {\n _currentIndex++;\n } \n\n _mint(recipients[i], _currentIndex);\n\n _perTokenMetadata[_currentIndex].editionState = ExpandedNFTStates.MINTED;\n _tokenClaimed[_currentIndex] = true;\n _pricing.mintCounts[currentMinter]++;\n _claimCount++;\n }\n\n return _currentIndex; \n } \n\n /**\n @param _royaltyBPS BPS of the royalty set on the contract. Can be 0 for no royalty.\n @param _splitBPS BPS of the royalty set on the contract. Can be 0 for no royalty. \n @param _vipSalePrice Sale price for VIPs\n @param _membersSalePrice SalePrice for Members \n @param _generalSalePrice SalePrice for the general public \n @param _vipMintLimit Mint limit for VIPs\n @param _membersMintLimit Mint limit for Members \n @param _generalMintLimit Mint limit for the general public \n @dev Set various pricing related values\n */\n function setPricing (\n uint256 _royaltyBPS,\n uint256 _splitBPS,\n uint256 _vipSalePrice,\n uint256 _membersSalePrice, \n uint256 _generalSalePrice,\n uint256 _vipMintLimit,\n uint256 _membersMintLimit,\n uint256 _generalMintLimit \n ) external onlyOwner { \n _pricing.royaltyBPS = _royaltyBPS;\n _pricing.splitBPS = _splitBPS;\n\n _pricing.vipSalePrice = _vipSalePrice;\n _pricing.membersSalePrice = _membersSalePrice;\n salePrice = _generalSalePrice;\n\n _pricing.vipMintLimit = _vipMintLimit;\n _pricing.membersMintLimit = _membersMintLimit;\n _pricing.generalMintLimit = _generalMintLimit;\n\n emit PriceChanged(salePrice);\n }\n\n /**\n @dev returns the current ETH sales price\n based on who can currently mint.\n */\n function _currentSalesPrice() internal view returns (uint256){\n if (_pricing.whoCanMint == WhoCanMint.VIPS) {\n return _pricing.vipSalePrice;\n } else if (_pricing.whoCanMint == WhoCanMint.MEMBERS) {\n return _pricing.membersSalePrice;\n } else if (_pricing.whoCanMint == WhoCanMint.ANYONE) {\n return salePrice;\n } \n \n return 0; \n }\n\n /**\n @param wallets A list of wallets\n @param tokenIDs A list of tokenId to reserve \n @dev Set various pricing related values\n */\n function reserve (address[] calldata wallets, uint256[] calldata tokenIDs) \n external onlyOwner { \n for (uint256 i = 0; i < wallets.length; i++) {\n _reserveAddress[_reserveCount] = wallets[i]; \n _reserveTokenId[_reserveCount] = tokenIDs[i]; \n _reserveCount++;\n }\n }\n\n /**\n @dev returns the current loimit on edition that \n can be minted by one wallet\n */\n function _currentMintLimit() internal view returns (uint256){\n if (_pricing.whoCanMint == WhoCanMint.VIPS) {\n return _pricing.vipMintLimit;\n } else if (_pricing.whoCanMint == WhoCanMint.MEMBERS) {\n return _pricing.membersMintLimit;\n } else if (_pricing.whoCanMint == WhoCanMint.ANYONE) {\n return _pricing.generalMintLimit;\n } \n \n return 0; \n }\n\n /**\n @param _salePrice if sale price is 0 sale is stopped, otherwise that amount \n of ETH is needed to start the sale.\n @dev This sets a simple ETH sales price\n Setting a sales price allows users to mint the drop until it sells out.\n For more granular sales, use an external sales contract.\n */\n function setSalePrice(uint256 _salePrice) external onlyOwner {\n salePrice = _salePrice;\n\n _pricing.whoCanMint = WhoCanMint.ANYONE;\n\n emit WhoCanMintChanged(_pricing.whoCanMint);\n emit PriceChanged(salePrice);\n }\n\n /**\n @param _salePrice if sale price is 0 sale is stopped, otherwise that amount \n of ETH is needed to start the sale.\n @dev This sets the VIP ETH sales price\n Setting a sales price allows users to mint the drop until it sells out.\n For more granular sales, use an external sales contract.\n */\n function setVIPSalePrice(uint256 _salePrice) external onlyOwner {\n _pricing.vipSalePrice = _salePrice;\n\n _pricing.whoCanMint = WhoCanMint.VIPS;\n\n emit WhoCanMintChanged(_pricing.whoCanMint);\n emit PriceChanged(salePrice);\n }\n\n /**\n @param _salePrice if sale price is 0 sale is stopped, otherwise that amount \n of ETH is needed to start the sale.\n @dev This sets the members ETH sales price\n Setting a sales price allows users to mint the drop until it sells out.\n For more granular sales, use an external sales contract.\n */\n function setMembersSalePrice(uint256 _salePrice) external onlyOwner {\n _pricing.membersSalePrice = _salePrice;\n\n _pricing.whoCanMint = WhoCanMint.MEMBERS;\n\n emit WhoCanMintChanged(_pricing.whoCanMint);\n emit PriceChanged(salePrice);\n } \n\n\n /**\n @param vipSalePrice if sale price is 0 sale is stopped, otherwise that amount \n of ETH is needed to start the sale.\n @param membersSalePrice if sale price is 0 sale is stopped, otherwise that amount \n of ETH is needed to start the sale.\n @param generalSalePrice if sale price is 0 sale is stopped, otherwise that amount \n of ETH is needed to start the sale. \n @dev This sets the members ETH sales price\n Setting a sales price allows users to mint the drop until it sells out.\n For more granular sales, use an external sales contract.\n */\n function setSalePrices(uint256 vipSalePrice, uint256 membersSalePrice, uint256 generalSalePrice) external onlyOwner {\n _pricing.vipSalePrice = vipSalePrice;\n _pricing.membersSalePrice = membersSalePrice;\n salePrice = generalSalePrice; \n\n emit PriceChanged(salePrice);\n } \n\n /**\n @dev This withdraws ETH from the contract to the contract owner.\n */\n function withdraw() external onlyOwner {\n uint256 currentBalance = address(this).balance;\n if (currentBalance > 0) {\n uint256 platformFee = (currentBalance * _pricing.splitBPS) / 10000;\n uint256 artistFee = currentBalance - platformFee;\n\n AddressUpgradeable.sendValue(payable(owner()), platformFee);\n AddressUpgradeable.sendValue(payable(_artistWallet), artistFee);\n }\n\n if (address(_paymentTokenERC20) != address(0x0)) {\n uint256 currentBalanceERC20 = _paymentTokenERC20.balanceOf(address(this));\n if (currentBalanceERC20 > 0) {\n uint256 platformFee = (currentBalanceERC20 * _pricing.splitBPS) / 10000;\n uint256 artistFee = currentBalanceERC20 - platformFee;\n\n _paymentTokenERC20.transfer(owner(), platformFee);\n _paymentTokenERC20.transfer(_artistWallet, artistFee);\n }\n }\n }\n\n /**\n @dev This helper function checks if the msg.sender is allowed to mint the\n given edition id.\n */\n function _isAllowedToMint() internal view returns (bool) {\n if (_pricing.whoCanMint == WhoCanMint.ANYONE) {\n return true;\n }\n\n if (_pricing.whoCanMint == WhoCanMint.MEMBERS) {\n if (_pricing.vipAllowedMinters[msg.sender]) {\n return true;\n } \n\n if (_pricing.allowedMinters[msg.sender]) {\n return true;\n } \n }\n\n if (_pricing.whoCanMint == WhoCanMint.VIPS) {\n if (_pricing.vipAllowedMinters[msg.sender]) {\n return true;\n } \n }\n\n if (owner() == msg.sender) {\n return true;\n }\n\n return false;\n }\n\n /**\n Simple override for owner interface.\n */\n function owner()\n public\n view\n override(OwnableUpgradeable, IExpandedNFT)\n returns (address)\n {\n return super.owner();\n }\n\n /**\n return the artists wallet address\n */\n function getArtistWallet()\n public\n view\n returns (address)\n {\n return _artistWallet;\n }\n\n /**\n set the artists wallet address\n */\n function setArtistWallet(address wallet)\n public\n onlyOwner\n {\n _artistWallet = wallet;\n } \n\n /**\n return the payment tokens address\n */\n function getPaymentToken()\n public\n view\n returns (address)\n {\n return address(_paymentTokenERC20);\n }\n\n /**\n set a new payment token address\n */\n function setPaymentToken(address paymentToken)\n public\n onlyOwner\n {\n if (address(_paymentTokenERC20) != address(0x0)) {\n require(_paymentTokenERC20.balanceOf(address(this)) == 0, \"token must have 0 balance\");\n }\n\n _paymentTokenERC20 = IERC20Upgradeable(paymentToken);\n } \n\n /**\n @dev Sets the types of users who is allowed to mint.\n */\n function getAllowedMinter() public view returns (WhoCanMint){\n return _pricing.whoCanMint;\n }\n\n /**\n @param minters WhoCanMint enum of minter types\n @dev Sets the types of users who is allowed to mint.\n */\n function setAllowedMinter(WhoCanMint minters) public onlyOwner {\n require(((minters >= WhoCanMint.ONLY_OWNER) && (minters <= WhoCanMint.ANYONE)), \"Needs to be a valid minter type\");\n\n _pricing.whoCanMint = minters;\n emit WhoCanMintChanged(minters);\n }\n\n /**\n @param minter address to set approved minting status for\n @param allowed boolean if that address is allowed to mint\n @dev Sets the approved minting status of the given address.\n This requires that msg.sender is the owner of the given edition id.\n If the ZeroAddress (address(0x0)) is set as a minter,\n anyone will be allowed to mint.\n This setup is similar to setApprovalForAll in the ERC721 spec.\n */\n function setApprovedMinters(uint256 count, address[] calldata minter, bool[] calldata allowed) public onlyOwner {\n for (uint256 i = 0; i < count; i++) {\n _pricing.allowedMinters[minter[i]] = allowed[i];\n }\n }\n\n /**\n @param minter address to set approved minting status for\n @param allowed boolean if that address is allowed to mint\n @dev Sets the approved minting status of the given address.\n This requires that msg.sender is the owner of the given edition id.\n If the ZeroAddress (address(0x0)) is set as a minter,\n anyone will be allowed to mint.\n This setup is similar to setApprovalForAll in the ERC721 spec.\n */\n function setApprovedVIPMinters(uint256 count, address[] calldata minter, bool[] calldata allowed) public onlyOwner {\n for (uint256 i = 0; i < count; i++) {\n _pricing.vipAllowedMinters[minter[i]] = allowed[i];\n }\n }\n\n /**\n @dev Allows for updates of edition urls by the owner of the edition.\n Only URLs can be updated (data-uris are supported), hashes cannot be updated.\n */\n function updateEditionURLs(\n uint256 tokenId,\n string memory imageUrl,\n string memory animationUrl\n ) public onlyOwner {\n _perTokenMetadata[tokenId].imageUrl = imageUrl;\n _perTokenMetadata[tokenId].animationUrl = animationUrl;\n }\n\n /// Returns the number of editions allowed to mint\n function numberCanMint() public view override returns (uint256) {\n return dropSize - _claimCount;\n }\n\n /**\n @param tokenId Token ID to burn\n User burn function for token id \n */\n function burn(uint256 tokenId) public {\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"Not approved\");\n _burn(tokenId);\n }\n\n function redeem(uint256 tokenId) public {\n require(_exists(tokenId), \"No token\");\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"Not approved\");\n\n require((_perTokenMetadata[tokenId].editionState == ExpandedNFTStates.MINTED), \"You currently can not redeem\");\n\n _perTokenMetadata[tokenId].editionState = ExpandedNFTStates.REDEEM_STARTED;\n emit RedeemStarted(tokenId, _msgSender());\n }\n\n function abortRedemption(uint256 tokenId) public {\n require(_exists(tokenId), \"No token\");\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"Not approved\");\n\n require((_perTokenMetadata[tokenId].editionState == ExpandedNFTStates.REDEEM_STARTED), \"You currently can not redeem\");\n\n _perTokenMetadata[tokenId].editionState = ExpandedNFTStates.MINTED;\n emit RedeemAborted(tokenId, _msgSender());\n }\n\n function setOfferTerms(uint256 tokenId, uint256 fee) public onlyOwner {\n require(_exists(tokenId), \"No token\"); \n require((_perTokenMetadata[tokenId].editionState == ExpandedNFTStates.REDEEM_STARTED), \"Wrong state\");\n\n _perTokenMetadata[tokenId].editionState = ExpandedNFTStates.SET_OFFER_TERMS;\n _perTokenMetadata[tokenId].editionFee = fee;\n\n emit OfferTermsSet(tokenId);\n }\n\n function rejectOfferTerms(uint256 tokenId) public {\n require(_exists(tokenId), \"No token\"); \n require(_isApprovedOrOwner(_msgSender(), tokenId), \"Not approved\");\n\n require((_perTokenMetadata[tokenId].editionState == ExpandedNFTStates.SET_OFFER_TERMS), \"You currently can not redeem\");\n\n _perTokenMetadata[tokenId].editionState = ExpandedNFTStates.MINTED;\n\n emit OfferRejected(tokenId);\n }\n\n function acceptOfferTerms(uint256 tokenId, uint256 paymentAmount) external {\n require(_exists(tokenId), \"No token\"); \n require(_isApprovedOrOwner(_msgSender(), tokenId), \"Not approved\");\n\n require((_perTokenMetadata[tokenId].editionState == ExpandedNFTStates.SET_OFFER_TERMS), \"You currently can not redeem\");\n\n require(paymentAmount >= _perTokenMetadata[tokenId].editionFee, \"Wrong price\");\n require(_paymentTokenERC20.allowance(_msgSender(), address(this)) >= _perTokenMetadata[tokenId].editionFee, \"Insufficient allowance\");\n\n bool success = _paymentTokenERC20.transferFrom(_msgSender(), address(this), _perTokenMetadata[tokenId].editionFee);\n require(success, \"Could not transfer token\");\n\n _perTokenMetadata[tokenId].editionState = ExpandedNFTStates.ACCEPTED_OFFER; \n\n emit OfferAccepted(tokenId);\n }\n\n function productionComplete(\n uint256 tokenId,\n string memory _description,\n string memory animationUrl,\n bytes32 animationHash,\n string memory imageUrl,\n bytes32 imageHash, \n string memory conditionReportUrl,\n bytes32 conditionReportHash \n ) public onlyOwner {\n require(_exists(tokenId), \"No token\"); \n require((_perTokenMetadata[tokenId].editionState == ExpandedNFTStates.ACCEPTED_OFFER), \"You currently can not redeem\");\n\n // Set the NFT to display as redeemed\n _perTokenMetadata[tokenId].description = _description;\n _perTokenMetadata[tokenId].redeemedAnimationUrl = animationUrl;\n _perTokenMetadata[tokenId].redeemedAnimationHash = animationHash;\n _perTokenMetadata[tokenId].redeemedImageUrl = imageUrl;\n _perTokenMetadata[tokenId].redeemedImageHash = imageHash;\n _perTokenMetadata[tokenId].conditionReportUrl = conditionReportUrl;\n _perTokenMetadata[tokenId].conditionReportHash = conditionReportHash;\n\n _perTokenMetadata[tokenId].editionState = ExpandedNFTStates.PRODUCTION_COMPLETE;\n\n emit ProductionComplete(tokenId);\n }\n\n function acceptDelivery(uint256 tokenId) public {\n require(_exists(tokenId), \"No token\"); \n require(_isApprovedOrOwner(_msgSender(), tokenId), \"Not approved\");\n\n require((_perTokenMetadata[tokenId].editionState == ExpandedNFTStates.PRODUCTION_COMPLETE), \"You currently can not redeem\");\n\n _perTokenMetadata[tokenId].editionState = ExpandedNFTStates.REDEEMED;\n\n emit OfferRejected(tokenId);\n }\n\n /**\n @dev Get URIs for the condition report\n @return conditionReportUrl, conditionReportHash\n */\n function getConditionReport(uint256 tokenId)\n public\n view\n returns (\n string memory,\n bytes32\n )\n {\n return (_perTokenMetadata[tokenId].conditionReportUrl, _perTokenMetadata[tokenId].conditionReportHash);\n }\n\n /**\n @dev Get royalty information for token\n @param _salePrice Sale price for the token\n */\n function royaltyInfo(uint256, uint256 _salePrice)\n external\n view\n override\n returns (address receiver, uint256 royaltyAmount)\n {\n if (owner() == address(0x0)) {\n return (owner(), 0);\n }\n return (owner(), (_salePrice * _pricing.royaltyBPS) / 10_000);\n }\n\n /**\n @dev Get URIs for edition NFT\n @return _imageUrl, _imageHash, _animationUrl, _animationHash\n */\n function getURIs(uint256 tokenId)\n public\n view\n returns (\n string memory,\n bytes32,\n string memory,\n bytes32\n )\n {\n if (_perTokenMetadata[tokenId].editionState == ExpandedNFTStates.REDEEMED) { \n return (_perTokenMetadata[tokenId].redeemedImageUrl, _perTokenMetadata[tokenId].redeemedImageHash,\n _perTokenMetadata[tokenId].redeemedAnimationUrl, _perTokenMetadata[tokenId].redeemedAnimationHash);\n }\n\n return (_perTokenMetadata[tokenId].imageUrl, _perTokenMetadata[tokenId].imageHash,\n _perTokenMetadata[tokenId].animationUrl, _perTokenMetadata[tokenId].animationHash);\n }\n\n /**\n @dev Get URI for given token id\n @param tokenId token id to get uri for\n @return base64-encoded json metadata object\n */\n function tokenURI(uint256 tokenId)\n public\n view\n override\n returns (string memory)\n {\n require(_exists(tokenId), \"No token\");\n\n if (_perTokenMetadata[tokenId].editionState == ExpandedNFTStates.REDEEMED) {\n return\n _sharedNFTLogic.createMetadataEdition(\n name(),\n _perTokenMetadata[tokenId].description,\n _perTokenMetadata[tokenId].redeemedImageUrl,\n _perTokenMetadata[tokenId].redeemedAnimationUrl,\n tokenId,\n dropSize\n );\n }\n\n return\n _sharedNFTLogic.createMetadataEdition(\n name(),\n _perTokenMetadata[tokenId].description,\n _perTokenMetadata[tokenId].imageUrl,\n _perTokenMetadata[tokenId].animationUrl,\n tokenId,\n dropSize\n );\n }\n\n function supportsInterface(bytes4 interfaceId)\n public\n view\n override(ERC721Upgradeable, IERC165Upgradeable)\n returns (bool)\n {\n return\n type(IERC2981Upgradeable).interfaceId == interfaceId ||\n ERC721Upgradeable.supportsInterface(interfaceId);\n }\n}\n"
},
"contracts/IExpandedNFT.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8.15;\n\ninterface IExpandedNFT {\n function mintEdition(address to) external payable returns (uint256);\n function mintEditions(address[] memory to) external payable returns (uint256);\n function numberCanMint() external view returns (uint256);\n function owner() external view returns (address);\n}\n"
},
"contracts/IPublicSharedMetadata.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity ^0.8.15;\n\n/// Shared public library for on-chain NFT functions\ninterface IPublicSharedMetadata {\n /// @param unencoded bytes to base64-encode\n function base64Encode(bytes memory unencoded)\n external\n pure\n returns (string memory);\n\n /// Encodes the argument json bytes into base64-data uri format\n /// @param json Raw json to base64 and turn into a data-uri\n function encodeMetadataJSON(bytes memory json)\n external\n pure\n returns (string memory);\n\n /// Proxy to openzeppelin's toString function\n /// @param value number to return as a string\n function numberToString(uint256 value)\n external\n pure\n returns (string memory);\n}\n"
},
"contracts/SharedNFTLogic.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity ^0.8.15;\n\nimport {StringsUpgradeable} from \"@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol\";\nimport {Base64} from \"base64-sol/base64.sol\";\nimport {IPublicSharedMetadata} from \"./IPublicSharedMetadata.sol\";\n\n/// Shared NFT logic for rendering metadata associated with editions\n/// @dev Can safely be used for generic base64Encode and numberToString functions\ncontract SharedNFTLogic is IPublicSharedMetadata {\n /// @param unencoded bytes to base64-encode\n function base64Encode(bytes memory unencoded)\n public\n pure\n override\n returns (string memory)\n {\n return Base64.encode(unencoded);\n }\n\n /// Proxy to openzeppelin's toString function\n /// @param value number to return as a string\n function numberToString(uint256 value)\n public\n pure\n override\n returns (string memory)\n {\n return StringsUpgradeable.toString(value);\n }\n\n /// Generate edition metadata from storage information as base64-json blob\n /// Combines the media data and metadata\n /// @param name Name of NFT in metadata\n /// @param description Description of NFT in metadata\n /// @param imageUrl URL of image to render for edition\n /// @param animationUrl URL of animation to render for edition\n /// @param tokenOfEdition Token ID for specific token\n /// @param editionSize Size of entire edition to show\n function createMetadataEdition(\n string memory name,\n string memory description,\n string memory imageUrl,\n string memory animationUrl,\n uint256 tokenOfEdition,\n uint256 editionSize\n ) external pure returns (string memory) {\n string memory _tokenMediaData = tokenMediaData(\n imageUrl,\n animationUrl,\n tokenOfEdition\n );\n bytes memory json = createMetadataJSON(\n name,\n description,\n _tokenMediaData,\n tokenOfEdition,\n editionSize\n );\n return encodeMetadataJSON(json);\n }\n\n /// Function to create the metadata json string for the nft edition\n /// @param name Name of NFT in metadata\n /// @param description Description of NFT in metadata\n /// @param mediaData Data for media to include in json object\n /// @param tokenOfEdition Token ID for specific token\n /// @param editionSize Size of entire edition to show\n function createMetadataJSON(\n string memory name,\n string memory description,\n string memory mediaData,\n uint256 tokenOfEdition,\n uint256 editionSize\n ) public pure returns (bytes memory) {\n bytes memory editionSizeText;\n if (editionSize > 0) {\n editionSizeText = abi.encodePacked(\n \"/\",\n numberToString(editionSize)\n );\n }\n return\n // solhint-disable quotes\n abi.encodePacked(\n '{\"name\": \"',\n name,\n \" \",\n numberToString(tokenOfEdition),\n editionSizeText,\n '\", \"',\n 'description\": \"',\n description,\n '\", \"',\n mediaData,\n 'properties\": {\"number\": ',\n numberToString(tokenOfEdition),\n '}}'\n );\n // solhint-enable quotes\n }\n\n /// Encodes the argument json bytes into base64-data uri format\n /// @param json Raw json to base64 and turn into a data-uri\n function encodeMetadataJSON(bytes memory json)\n public\n pure\n override\n returns (string memory)\n {\n return\n string(\n abi.encodePacked(\n \"data:application/json;base64,\",\n base64Encode(json)\n )\n );\n }\n\n /// Generates edition metadata from storage information as base64-json blob\n /// Combines the media data and metadata\n /// @param imageUrl URL of image to render for edition\n /// @param animationUrl URL of animation to render for edition\n function tokenMediaData(\n string memory imageUrl,\n string memory animationUrl,\n uint256 tokenOfEdition\n ) public pure returns (string memory) {\n bool hasImage = bytes(imageUrl).length > 0;\n bool hasAnimation = bytes(animationUrl).length > 0;\n if (hasImage && hasAnimation) {\n return\n // solhint-disable quotes\n string(\n abi.encodePacked(\n 'image\": \"',\n imageUrl,\n \"?id=\",\n numberToString(tokenOfEdition),\n '\", \"animation_url\": \"',\n animationUrl,\n \"?id=\",\n numberToString(tokenOfEdition),\n '\", \"'\n )\n );\n // solhint-enable quotes\n }\n if (hasImage) {\n return\n // solhint-disable quotes\n string(\n abi.encodePacked(\n 'image\": \"',\n imageUrl,\n \"?id=\",\n numberToString(tokenOfEdition),\n '\", \"'\n )\n );\n // solhint-enable quotes\n }\n if (hasAnimation) {\n return\n // solhint-disable quotes\n string(\n abi.encodePacked(\n 'animation_url\": \"',\n animationUrl,\n \"?id=\",\n numberToString(tokenOfEdition),\n '\", \"'\n )\n );\n // solhint-enable quotes\n }\n\n return \"\";\n }\n}\n"
}
}
}