zellic-audit
Initial commit
f998fcd
raw
history blame
147 kB
{
"language": "Solidity",
"sources": {
"@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface VRFCoordinatorV2Interface {\n /**\n * @notice Get configuration relevant for making requests\n * @return minimumRequestConfirmations global min for request confirmations\n * @return maxGasLimit global max for request gas limit\n * @return s_provingKeyHashes list of registered key hashes\n */\n function getRequestConfig()\n external\n view\n returns (\n uint16,\n uint32,\n bytes32[] memory\n );\n\n /**\n * @notice Request a set of random words.\n * @param keyHash - Corresponds to a particular oracle job which uses\n * that key for generating the VRF proof. Different keyHash's have different gas price\n * ceilings, so you can select a specific one to bound your maximum per request cost.\n * @param subId - The ID of the VRF subscription. Must be funded\n * with the minimum subscription balance required for the selected keyHash.\n * @param minimumRequestConfirmations - How many blocks you'd like the\n * oracle to wait before responding to the request. See SECURITY CONSIDERATIONS\n * for why you may want to request more. The acceptable range is\n * [minimumRequestBlockConfirmations, 200].\n * @param callbackGasLimit - How much gas you'd like to receive in your\n * fulfillRandomWords callback. Note that gasleft() inside fulfillRandomWords\n * may be slightly less than this amount because of gas used calling the function\n * (argument decoding etc.), so you may need to request slightly more than you expect\n * to have inside fulfillRandomWords. The acceptable range is\n * [0, maxGasLimit]\n * @param numWords - The number of uint256 random values you'd like to receive\n * in your fulfillRandomWords callback. Note these numbers are expanded in a\n * secure way by the VRFCoordinator from a single random value supplied by the oracle.\n * @return requestId - A unique identifier of the request. Can be used to match\n * a request to a response in fulfillRandomWords.\n */\n function requestRandomWords(\n bytes32 keyHash,\n uint64 subId,\n uint16 minimumRequestConfirmations,\n uint32 callbackGasLimit,\n uint32 numWords\n ) external returns (uint256 requestId);\n\n /**\n * @notice Create a VRF subscription.\n * @return subId - A unique subscription id.\n * @dev You can manage the consumer set dynamically with addConsumer/removeConsumer.\n * @dev Note to fund the subscription, use transferAndCall. For example\n * @dev LINKTOKEN.transferAndCall(\n * @dev address(COORDINATOR),\n * @dev amount,\n * @dev abi.encode(subId));\n */\n function createSubscription() external returns (uint64 subId);\n\n /**\n * @notice Get a VRF subscription.\n * @param subId - ID of the subscription\n * @return balance - LINK balance of the subscription in juels.\n * @return reqCount - number of requests for this subscription, determines fee tier.\n * @return owner - owner of the subscription.\n * @return consumers - list of consumer address which are able to use this subscription.\n */\n function getSubscription(uint64 subId)\n external\n view\n returns (\n uint96 balance,\n uint64 reqCount,\n address owner,\n address[] memory consumers\n );\n\n /**\n * @notice Request subscription owner transfer.\n * @param subId - ID of the subscription\n * @param newOwner - proposed new owner of the subscription\n */\n function requestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external;\n\n /**\n * @notice Request subscription owner transfer.\n * @param subId - ID of the subscription\n * @dev will revert if original owner of subId has\n * not requested that msg.sender become the new owner.\n */\n function acceptSubscriptionOwnerTransfer(uint64 subId) external;\n\n /**\n * @notice Add a consumer to a VRF subscription.\n * @param subId - ID of the subscription\n * @param consumer - New consumer which can use the subscription\n */\n function addConsumer(uint64 subId, address consumer) external;\n\n /**\n * @notice Remove a consumer from a VRF subscription.\n * @param subId - ID of the subscription\n * @param consumer - Consumer to remove from the subscription\n */\n function removeConsumer(uint64 subId, address consumer) external;\n\n /**\n * @notice Cancel a subscription\n * @param subId - ID of the subscription\n * @param to - Where to send the remaining LINK to\n */\n function cancelSubscription(uint64 subId, address to) external;\n\n /*\n * @notice Check to see if there exists a request commitment consumers\n * for all consumers and keyhashes for a given sub.\n * @param subId - ID of the subscription\n * @return true if there exists at least one unfulfilled request for the subscription, false\n * otherwise.\n */\n function pendingRequestExists(uint64 subId) external view returns (bool);\n}\n"
},
"@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/** ****************************************************************************\n * @notice Interface for contracts using VRF randomness\n * *****************************************************************************\n * @dev PURPOSE\n *\n * @dev Reggie the Random Oracle (not his real job) wants to provide randomness\n * @dev to Vera the verifier in such a way that Vera can be sure he's not\n * @dev making his output up to suit himself. Reggie provides Vera a public key\n * @dev to which he knows the secret key. Each time Vera provides a seed to\n * @dev Reggie, he gives back a value which is computed completely\n * @dev deterministically from the seed and the secret key.\n *\n * @dev Reggie provides a proof by which Vera can verify that the output was\n * @dev correctly computed once Reggie tells it to her, but without that proof,\n * @dev the output is indistinguishable to her from a uniform random sample\n * @dev from the output space.\n *\n * @dev The purpose of this contract is to make it easy for unrelated contracts\n * @dev to talk to Vera the verifier about the work Reggie is doing, to provide\n * @dev simple access to a verifiable source of randomness. It ensures 2 things:\n * @dev 1. The fulfillment came from the VRFCoordinator\n * @dev 2. The consumer contract implements fulfillRandomWords.\n * *****************************************************************************\n * @dev USAGE\n *\n * @dev Calling contracts must inherit from VRFConsumerBase, and can\n * @dev initialize VRFConsumerBase's attributes in their constructor as\n * @dev shown:\n *\n * @dev contract VRFConsumer {\n * @dev constructor(<other arguments>, address _vrfCoordinator, address _link)\n * @dev VRFConsumerBase(_vrfCoordinator) public {\n * @dev <initialization with other arguments goes here>\n * @dev }\n * @dev }\n *\n * @dev The oracle will have given you an ID for the VRF keypair they have\n * @dev committed to (let's call it keyHash). Create subscription, fund it\n * @dev and your consumer contract as a consumer of it (see VRFCoordinatorInterface\n * @dev subscription management functions).\n * @dev Call requestRandomWords(keyHash, subId, minimumRequestConfirmations,\n * @dev callbackGasLimit, numWords),\n * @dev see (VRFCoordinatorInterface for a description of the arguments).\n *\n * @dev Once the VRFCoordinator has received and validated the oracle's response\n * @dev to your request, it will call your contract's fulfillRandomWords method.\n *\n * @dev The randomness argument to fulfillRandomWords is a set of random words\n * @dev generated from your requestId and the blockHash of the request.\n *\n * @dev If your contract could have concurrent requests open, you can use the\n * @dev requestId returned from requestRandomWords to track which response is associated\n * @dev with which randomness request.\n * @dev See \"SECURITY CONSIDERATIONS\" for principles to keep in mind,\n * @dev if your contract could have multiple requests in flight simultaneously.\n *\n * @dev Colliding `requestId`s are cryptographically impossible as long as seeds\n * @dev differ.\n *\n * *****************************************************************************\n * @dev SECURITY CONSIDERATIONS\n *\n * @dev A method with the ability to call your fulfillRandomness method directly\n * @dev could spoof a VRF response with any random value, so it's critical that\n * @dev it cannot be directly called by anything other than this base contract\n * @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method).\n *\n * @dev For your users to trust that your contract's random behavior is free\n * @dev from malicious interference, it's best if you can write it so that all\n * @dev behaviors implied by a VRF response are executed *during* your\n * @dev fulfillRandomness method. If your contract must store the response (or\n * @dev anything derived from it) and use it later, you must ensure that any\n * @dev user-significant behavior which depends on that stored value cannot be\n * @dev manipulated by a subsequent VRF request.\n *\n * @dev Similarly, both miners and the VRF oracle itself have some influence\n * @dev over the order in which VRF responses appear on the blockchain, so if\n * @dev your contract could have multiple VRF requests in flight simultaneously,\n * @dev you must ensure that the order in which the VRF responses arrive cannot\n * @dev be used to manipulate your contract's user-significant behavior.\n *\n * @dev Since the block hash of the block which contains the requestRandomness\n * @dev call is mixed into the input to the VRF *last*, a sufficiently powerful\n * @dev miner could, in principle, fork the blockchain to evict the block\n * @dev containing the request, forcing the request to be included in a\n * @dev different block with a different hash, and therefore a different input\n * @dev to the VRF. However, such an attack would incur a substantial economic\n * @dev cost. This cost scales with the number of blocks the VRF oracle waits\n * @dev until it calls responds to a request. It is for this reason that\n * @dev that you can signal to an oracle you'd like them to wait longer before\n * @dev responding to the request (however this is not enforced in the contract\n * @dev and so remains effective only in the case of unmodified oracle software).\n */\nabstract contract VRFConsumerBaseV2 {\n error OnlyCoordinatorCanFulfill(address have, address want);\n address private immutable vrfCoordinator;\n\n /**\n * @param _vrfCoordinator address of VRFCoordinator contract\n */\n constructor(address _vrfCoordinator) {\n vrfCoordinator = _vrfCoordinator;\n }\n\n /**\n * @notice fulfillRandomness handles the VRF response. Your contract must\n * @notice implement it. See \"SECURITY CONSIDERATIONS\" above for important\n * @notice principles to keep in mind when implementing your fulfillRandomness\n * @notice method.\n *\n * @dev VRFConsumerBaseV2 expects its subcontracts to have a method with this\n * @dev signature, and will call it once it has verified the proof\n * @dev associated with the randomness. (It is triggered via a call to\n * @dev rawFulfillRandomness, below.)\n *\n * @param requestId The Id initially returned by requestRandomness\n * @param randomWords the VRF output expanded to the requested number of words\n */\n function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual;\n\n // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF\n // proof. rawFulfillRandomness then calls fulfillRandomness, after validating\n // the origin of the call\n function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external {\n if (msg.sender != vrfCoordinator) {\n revert OnlyCoordinatorCanFulfill(msg.sender, vrfCoordinator);\n }\n fulfillRandomWords(requestId, randomWords);\n }\n}\n"
},
"@openzeppelin/contracts/access/AccessControl.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n Strings.toHexString(account),\n \" is missing role \",\n Strings.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleGranted} event.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleRevoked} event.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n *\n * May emit a {RoleRevoked} event.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * May emit a {RoleGranted} event.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleGranted} event.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleRevoked} event.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n}\n"
},
"@openzeppelin/contracts/access/IAccessControl.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n"
},
"@openzeppelin/contracts/access/Ownable.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/Context.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 Ownable is Context {\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 constructor() {\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"
},
"@openzeppelin/contracts/token/ERC20/ERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\n // decrementing then incrementing.\n _balances[to] += amount;\n }\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n unchecked {\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\n _balances[account] += amount;\n }\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n // Overflow not possible: amount <= accountBalance <= totalSupply.\n _totalSupply -= amount;\n }\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens 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 amount\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, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been 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 _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.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 IERC20 {\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/token/ERC721/ERC721.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/ERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC721.sol\";\nimport \"./IERC721Receiver.sol\";\nimport \"./extensions/IERC721Metadata.sol\";\nimport \"../../utils/Address.sol\";\nimport \"../../utils/Context.sol\";\nimport \"../../utils/Strings.sol\";\nimport \"../../utils/introspection/ERC165.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 ERC721 is Context, ERC165, IERC721, IERC721Metadata {\n using Address for address;\n using Strings 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 constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n return\n interfaceId == type(IERC721).interfaceId ||\n interfaceId == type(IERC721Metadata).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 = _ownerOf(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 = ERC721.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 or 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 or 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 or 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 the owner of the `tokenId`. Does NOT revert if token doesn't exist\n */\n function _ownerOf(uint256 tokenId) internal view virtual returns (address) {\n return _owners[tokenId];\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 _ownerOf(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 = ERC721.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, 1);\n\n // Check that tokenId was not minted by `_beforeTokenTransfer` hook\n require(!_exists(tokenId), \"ERC721: token already minted\");\n\n unchecked {\n // Will not overflow unless all 2**256 token ids are minted to the same owner.\n // Given that tokens are minted one by one, it is impossible in practice that\n // this ever happens. Might change if we allow batch minting.\n // The ERC fails to describe this case.\n _balances[to] += 1;\n }\n\n _owners[tokenId] = to;\n\n emit Transfer(address(0), to, tokenId);\n\n _afterTokenTransfer(address(0), to, tokenId, 1);\n }\n\n /**\n * @dev Destroys `tokenId`.\n * The approval is cleared when the token is burned.\n * This is an internal function that does not check if the sender is authorized to operate on the token.\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 = ERC721.ownerOf(tokenId);\n\n _beforeTokenTransfer(owner, address(0), tokenId, 1);\n\n // Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook\n owner = ERC721.ownerOf(tokenId);\n\n // Clear approvals\n delete _tokenApprovals[tokenId];\n\n unchecked {\n // Cannot overflow, as that would require more tokens to be burned/transferred\n // out than the owner initially received through minting and transferring in.\n _balances[owner] -= 1;\n }\n delete _owners[tokenId];\n\n emit Transfer(owner, address(0), tokenId);\n\n _afterTokenTransfer(owner, address(0), tokenId, 1);\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(ERC721.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, 1);\n\n // Check that tokenId was not transferred by `_beforeTokenTransfer` hook\n require(ERC721.ownerOf(tokenId) == from, \"ERC721: transfer from incorrect owner\");\n\n // Clear approvals from the previous owner\n delete _tokenApprovals[tokenId];\n\n unchecked {\n // `_balances[from]` cannot overflow for the same reason as described in `_burn`:\n // `from`'s balance is the number of token held, which is at least one before the current\n // transfer.\n // `_balances[to]` could overflow in the conditions described in `_mint`. That would require\n // all 2**256 token ids to be minted, which in practice is impossible.\n _balances[from] -= 1;\n _balances[to] += 1;\n }\n _owners[tokenId] = to;\n\n emit Transfer(from, to, tokenId);\n\n _afterTokenTransfer(from, to, tokenId, 1);\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(ERC721.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 IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {\n return retval == IERC721Receiver.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 and burning. If {ERC721Consecutive} is\n * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.\n * - When `from` is zero, the tokens will be minted for `to`.\n * - When `to` is zero, ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n * - `batchSize` is non-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, /* firstTokenId */\n uint256 batchSize\n ) internal virtual {\n if (batchSize > 1) {\n if (from != address(0)) {\n _balances[from] -= batchSize;\n }\n if (to != address(0)) {\n _balances[to] += batchSize;\n }\n }\n }\n\n /**\n * @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is\n * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.\n * - When `from` is zero, the tokens were minted for `to`.\n * - When `to` is zero, ``from``'s tokens were burned.\n * - `from` and `to` are never both zero.\n * - `batchSize` is non-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 firstTokenId,\n uint256 batchSize\n ) internal virtual {}\n}\n"
},
"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.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 \"../IERC721.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 IERC721Metadata is IERC721 {\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/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/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n *\n * _Available since v4.8._\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n if (success) {\n if (returndata.length == 0) {\n // only check isContract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n require(isContract(target), \"Address: call to non-contract\");\n }\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason or using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n function _revert(bytes memory returndata, string memory errorMessage) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
},
"@openzeppelin/contracts/utils/Counters.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title Counters\n * @author Matt Condon (@shrugs)\n * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number\n * of elements in a mapping, issuing ERC721 ids, or counting request ids.\n *\n * Include with `using Counters for Counters.Counter;`\n */\nlibrary Counters {\n struct Counter {\n // This variable should never be directly accessed by users of the library: interactions must be restricted to\n // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add\n // this feature: see https://github.com/ethereum/solidity/issues/4637\n uint256 _value; // default: 0\n }\n\n function current(Counter storage counter) internal view returns (uint256) {\n return counter._value;\n }\n\n function increment(Counter storage counter) internal {\n unchecked {\n counter._value += 1;\n }\n }\n\n function decrement(Counter storage counter) internal {\n uint256 value = counter._value;\n require(value > 0, \"Counter: decrement overflow\");\n unchecked {\n counter._value = value - 1;\n }\n }\n\n function reset(Counter storage counter) internal {\n counter._value = 0;\n }\n}\n"
},
"@openzeppelin/contracts/utils/introspection/ERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.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 ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\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/BlackSquareNFT.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\nimport '@openzeppelin/contracts/token/ERC721/ERC721.sol';\nimport './ERC2981/ERC2981ContractWideRoyalties.sol';\nimport \"@openzeppelin/contracts/utils/Counters.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./Erc721OperatorFilter/IOperatorFilter.sol\";\nimport \"./OBYToken.sol\";\n\n\ncontract BlackSquareNFT is ERC721, Ownable, ERC2981ContractWideRoyalties {\n using Strings for uint256;\n using Counters for Counters.Counter;\n\n uint256 private rewardPerCycle;\n uint256 public totalCycleCount = 0;\n uint256 constant THRESHOLD = 25;\n uint256 constant TOKENS_PER_EDITION = 25;\n uint256 constant MAX_NUMBER_EDITIONS = 58;\n\n address private treasury;\n\n string public openSeaContractURI;\n string public baseURI;\n\n OBYToken obyToken;\n IOperatorFilter operatorFilter;\n Counters.Counter private _editionIds;\n Counters.Counter private _tokenIds;\n\n struct Edition {\n uint256[TOKENS_PER_EDITION] tokens;\n uint256 illuminationTimeStamp;\n uint256 lastUpdateTimestamp;\n uint256 cycle;\n uint256 id;\n string editionThumbnail;\n string illumination;\n }\n\n struct OwnerReward {\n uint256 rewardPaid;\n uint256 rewardStored;\n }\n\n struct CreateEditionStruct {\n uint256[TOKENS_PER_EDITION] tokens;\n uint256 illuminationMoment;\n string editionThumbnail;\n string illumination;\n }\n\n mapping(uint256 => mapping(uint256 => OwnerReward)) private _ownersReward;\n mapping(address => bool) private _eligibles;\n mapping(uint256 => Edition) private _editions;\n mapping(uint256 => uint256) private _editionOfToken;\n mapping(address => uint256) private _totalRewardsClaimed;\n\n event RewardWithdrawn(uint256 amount, address sender);\n event EditionCreated(uint256 editionId);\n\n\n constructor(address obyAddress, address _treasury, uint256 _royaltyValue, string memory _openSeaContractURI, string memory _blackSquareBaseURI,\n uint256 _rewardPerCycle, address _operatorFilter) ERC721(\"BlackSquare\", \"B2\") {\n obyToken = OBYToken(obyAddress);\n operatorFilter = IOperatorFilter(_operatorFilter);\n treasury = _treasury;\n openSeaContractURI = _openSeaContractURI;\n baseURI = _blackSquareBaseURI;\n rewardPerCycle = _rewardPerCycle;\n _setRoyalties(_treasury, _royaltyValue);\n }\n\n modifier onlyEligible() {\n require(owner() == _msgSender() || _eligibles[_msgSender()] == true, \"BlackSquareNFT: caller is not eligible\");\n _;\n }\n\n function _baseURI() internal view virtual override returns (string memory) {\n return baseURI;\n }\n\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override(ERC721, ERC2981)\n returns (bool)\n {\n return super.supportsInterface(interfaceId);\n }\n\n function setContractURI(string memory _contractURI) external onlyOwner {\n openSeaContractURI = _contractURI;\n }\n\n function setBaseURI(string memory _blackSquareBaseURI) external onlyOwner {\n baseURI = _blackSquareBaseURI;\n }\n\n\n function setRewardPerCycle(uint256 _rewardPerCycle) external onlyOwner {\n rewardPerCycle = _rewardPerCycle;\n }\n\n function setRoyalties(address recipient, uint256 value) external onlyOwner {\n _setRoyalties(recipient, value);\n }\n\n function setEligibles(address _eligible) external onlyOwner {\n _eligibles[_eligible] = true;\n\n \n }\n\n function contractURI() public view returns (string memory) {\n return openSeaContractURI;\n }\n\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 tokenId,\n uint256 batchSize\n ) internal virtual override(ERC721) {\n if (\n from != address(0) &&\n to != address(0) &&\n !_mayTransfer(msg.sender, tokenId)\n ) {\n revert(\"ERC721OperatorFilter: illegal operator\");\n }\n super._beforeTokenTransfer(from, to, tokenId, batchSize);\n }\n\n function _mayTransfer(address operator, uint256 tokenId)\n private\n view\n returns (bool)\n {\n IOperatorFilter filter = operatorFilter;\n if (address(filter) == address(0)) return true;\n if (operator == ownerOf(tokenId)) return true;\n return filter.mayTransfer(msg.sender);\n }\n\n function getEditions() public view returns (Edition[] memory) {\n Edition[] memory editions = new Edition[](_editionIds.current() + 1);\n\n for (uint256 editionCounter = 1; editionCounter <= _editionIds.current(); editionCounter++){\n editions[editionCounter] = _editions[editionCounter];\n }\n return editions;\n }\n\n function deleteEdition (uint256 editionId) public onlyOwner {\n delete _editions[editionId];\n }\n\n function createEdition(CreateEditionStruct memory _createEditionStruct) public onlyOwner {\n _editionIds.increment();\n uint256 editionId = _editionIds.current();\n \n\n for (uint256 i = 0; i < _createEditionStruct.tokens.length; i++) {\n _editionOfToken[_createEditionStruct.tokens[i]] = _editionIds.current();\n }\n\n _editions[editionId].tokens = _createEditionStruct.tokens;\n _editions[editionId].illuminationTimeStamp = _createEditionStruct.illuminationMoment;\n _editions[editionId].lastUpdateTimestamp = block.timestamp;\n _editions[editionId].cycle = 1;\n _editions[editionId].id = editionId;\n _editions[editionId].editionThumbnail = _createEditionStruct.editionThumbnail;\n _editions[editionId].illumination = _createEditionStruct.illumination;\n\n emit EditionCreated(editionId);\n }\n\n\n function getCurrentTokenId() external view returns (uint256) {\n return _tokenIds.current();\n }\n\n function getRewardInOBY () public view returns (uint256, uint256) {\n uint256[] memory tokens = getTokensHeldByUser(_msgSender());\n\n require(tokens.length > 0, 'NO BlackSquares held');\n uint256 availableReward = 0;\n\n uint256 paidReward = _totalRewardsClaimed[_msgSender()];\n\n for (uint256 i = 0; i < tokens.length; i++) {\n (uint256 rewardPertoken, ,) = _getAvailableRewardInOby(tokens[i]);\n availableReward += rewardPertoken;\n \n }\n return (availableReward, paidReward);\n }\n\n function claimRewardInOBY () public returns (uint256) {\n uint256[] memory tokens = getTokensHeldByUser(_msgSender());\n\n require(tokens.length > 0, 'NO BlackSquares held');\n uint256 availableReward = 0;\n\n for (uint256 i = 0; i < tokens.length; i++) {\n (uint256 rewardPertoken, uint256 cycle, uint256 rewardStoredPrev) = _getAvailableRewardInOby(tokens[i]);\n availableReward += rewardPertoken;\n\n uint256 tokenId = tokens[i];\n\n uint256 previousCycle = cycle > 1 ? cycle - 1 : 1;\n uint256 rewardPaid = rewardPertoken - rewardStoredPrev;\n\n _ownersReward[tokenId][cycle].rewardPaid += rewardPaid;\n\n _totalRewardsClaimed[_msgSender()] += rewardPertoken;\n _ownersReward[tokenId][cycle].rewardStored = 0;\n if (cycle > 1) {\n _ownersReward[tokenId][previousCycle].rewardStored = 0;\n }\n }\n\n require(availableReward > 0, 'No OBY available to mint');\n\n if (availableReward > 0) {\n obyToken.mint(_msgSender(), availableReward);\n }\n\n emit RewardWithdrawn(availableReward, _msgSender());\n \n return availableReward;\n }\n\n function getTokensHeldByUser(address user) public view returns (uint256[] memory) {\n uint256 balance = balanceOf(user);\n uint256[] memory emptyTokens = new uint256[](0);\n uint256[] memory tokenIds = new uint256[](balance);\n uint256 j = 0;\n\n for (uint256 i = 1; i <= _tokenIds.current(); i++ ) {\n address tokenOwner = ownerOf(i);\n\n if (tokenOwner == user) {\n tokenIds[j] = i;\n j++;\n }\n }\n if (tokenIds.length > 0) {\n return tokenIds;\n } else {\n return emptyTokens;\n }\n }\n\n function mintAndDrop(address[] memory recipients, CreateEditionStruct[] memory _createEditionStruct) public onlyOwner {\n uint256 editionCount = 0;\n\n if(_editionIds.current() <= MAX_NUMBER_EDITIONS) {\n for (uint256 i = 0; i < recipients.length; i++) {\n _tokenIds.increment();\n uint256 currentTokenId = _tokenIds.current();\n\n unchecked {\n _mint(recipients[i], currentTokenId);\n\n if (currentTokenId == 25 || currentTokenId > 25 && currentTokenId % 25 == 0) {\n createEdition(_createEditionStruct[editionCount]);\n editionCount++;\n }\n }\n }\n }\n }\n\n function editEdition(uint256 _editionId, uint256 _illuminationTimeStamp) public onlyEligible returns (uint256) {\n updateStoredReward(_editionId);\n\n _editions[_editionId].illuminationTimeStamp = _illuminationTimeStamp;\n _editions[_editionId].lastUpdateTimestamp = block.timestamp;\n _editions[_editionId].cycle += 1;\n\n totalCycleCount ++;\n\n return _editionId;\n }\n\n function updateStoredReward(uint256 editionId) public onlyEligible {\n uint256 editionCycle = _editions[editionId].cycle;\n for (uint256 tokenId = 0; tokenId < _editions[editionId].tokens.length; tokenId++ ) {\n uint256 currentToken = _editions[editionId].tokens[tokenId];\n\n // Normal update where cycle is > 1, Up to the normal rewardPerPeriod was paid out & There is a stored reward >= 0\n if (_ownersReward[currentToken][editionCycle].rewardPaid <= (rewardPerCycle / 10000) && editionCycle > 1 && _ownersReward[currentToken][editionCycle - 1].rewardStored >= 0) {\n _ownersReward[currentToken][editionCycle].rewardStored = (rewardPerCycle / 10000) - _ownersReward[currentToken][editionCycle].rewardPaid + _ownersReward[currentToken][editionCycle - 1].rewardStored;\n\n // We are in Cycle one, so there is no previously stored reward. Now everything gets stored which is a positive amount or 0\n } else if (_ownersReward[currentToken][editionCycle].rewardPaid <= (rewardPerCycle / 10000) && editionCycle == 1) {\n _ownersReward[currentToken][editionCycle].rewardStored = (rewardPerCycle / 10000) - _ownersReward[currentToken][editionCycle].rewardPaid;\n\n // In case due to some rounding errors etc. RewardPaid > Reward, Only Stored Reward is carried over if Cycle > 1 and Stored Reward is bigger than 0\n } else if (_ownersReward[currentToken][editionCycle].rewardPaid > (rewardPerCycle / 10000) && editionCycle > 1 && _ownersReward[currentToken][editionCycle - 1].rewardStored > 0) {\n _ownersReward[currentToken][editionCycle].rewardStored = _ownersReward[currentToken][editionCycle - 1].rewardStored;\n\n // Handle the Edge Cases\n } else {\n _ownersReward[currentToken][editionCycle].rewardStored = 0;\n }\n \n }\n \n }\n\n function getFirstEditionToSetIlluminationDate() public view returns (uint256) {\n for (uint256 editionCounter = 1; editionCounter <= _editionIds.current(); editionCounter++){\n if (_editions[editionCounter].illuminationTimeStamp < block.timestamp) {\n return editionCounter;\n }\n }\n return 0;\n }\n\n function getAvailableIlluminaCount() public view returns (uint256) {\n uint256 availableIlluminas = totalCycleCount * THRESHOLD;\n for (uint256 editionCounter = 1; editionCounter <= _editionIds.current(); editionCounter++){\n if (_editions[editionCounter].illuminationTimeStamp < block.timestamp) {\n availableIlluminas += THRESHOLD;\n }\n }\n return availableIlluminas;\n }\n\n function setIlluminationTimeStamp(uint256 _editionId, uint256 _illuminationTimeStamp) public onlyOwner {\n _editions[_editionId].illuminationTimeStamp = _illuminationTimeStamp;\n }\n\n function _getAvailableRewardInOby(uint256 tokenId) internal view returns (uint256, uint256, uint256) {\n uint256 editionId = _editionOfToken[tokenId];\n\n require(editionId != 0, 'Token Not associated with any Edition');\n\n uint256 illuminationTimeStamp = _editions[editionId].illuminationTimeStamp;\n uint256 cycle = _editions[editionId].cycle;\n uint256 previousCycle = cycle > 1 ? cycle - 1 : 1;\n uint256 lastUpdateTimestamp = _editions[editionId].lastUpdateTimestamp;\n\n uint256 rewardPaid = _ownersReward[tokenId][cycle].rewardPaid > 0 ? _ownersReward[tokenId][cycle].rewardPaid : 0;\n uint256 rewardStoredPrev = cycle > 1 ? _ownersReward[tokenId][previousCycle].rewardStored : 0;\n\n // We are in the normal distribution Cycle\n if (lastUpdateTimestamp < illuminationTimeStamp && block.timestamp < illuminationTimeStamp && block.timestamp > lastUpdateTimestamp) {\n uint256 rewardPerSecond = rewardPerCycle / (illuminationTimeStamp - lastUpdateTimestamp);\n\n uint256 rewardPayableFromCycle = (((rewardPerSecond) * ((block.timestamp) - lastUpdateTimestamp)) / 10000) - rewardPaid;\n\n uint256 returnableAmount = rewardPayableFromCycle >= 1 ? rewardPayableFromCycle + rewardStoredPrev : rewardStoredPrev;\n\n return (returnableAmount, cycle, rewardStoredPrev);\n // We are outside the normal cycle, during time of Illumina sale\n } else if (lastUpdateTimestamp < illuminationTimeStamp && block.timestamp > illuminationTimeStamp && block.timestamp > lastUpdateTimestamp) {\n\n uint256 returnableAmount = rewardStoredPrev + (rewardPerCycle / 10000) - rewardPaid;\n return (returnableAmount, cycle, rewardStoredPrev);\n // Handle all edge cases\n } else {\n return (rewardStoredPrev, cycle, rewardStoredPrev);\n }\n }\n}\n"
},
"contracts/ERC2981/ERC2981.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport './IERC2981Royalties.sol';\n\n/// @dev This is a contract used to add ERC2981 support to ERC721 and 1155\nabstract contract ERC2981 is ERC165, IERC2981Royalties {\n struct RoyaltyInfo {\n address recipient;\n uint24 amount;\n }\n\n /// @inheritdoc\tERC165\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override\n returns (bool)\n {\n return\n interfaceId == type(IERC2981Royalties).interfaceId ||\n super.supportsInterface(interfaceId);\n }\n}\n"
},
"contracts/ERC2981/ERC2981ContractWideRoyalties.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\nimport '@openzeppelin/contracts/utils/introspection/ERC165.sol';\n\nimport './ERC2981.sol';\n\n/// @dev This is a contract used to add ERC2981 support to ERC721 and 1155\n/// @dev This implementation has the same royalties for each and every tokens\nabstract contract ERC2981ContractWideRoyalties is ERC2981 {\n RoyaltyInfo private _royalties;\n\n /// @dev Sets token royalties\n /// @param recipient recipient of the royalties\n /// @param value percentage (using 2 decimals - 10000 = 100, 0 = 0)\n function _setRoyalties(address recipient, uint256 value) internal {\n require(value <= 10000, 'ERC2981Royalties: Too high');\n _royalties = RoyaltyInfo(recipient, uint24(value));\n }\n\n /// @inheritdoc\tIERC2981Royalties\n function royaltyInfo(uint256, uint256 value)\n external\n view\n override\n returns (address receiver, uint256 royaltyAmount)\n {\n RoyaltyInfo memory royalties = _royalties;\n receiver = royalties.recipient;\n royaltyAmount = (value * royalties.amount) / 10000;\n }\n}\n"
},
"contracts/ERC2981/IERC2981Royalties.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\n/// @title IERC2981Royalties\n/// @dev Interface for the ERC2981 - Token Royalty standard\ninterface IERC2981Royalties {\n /// @notice Called with the sale price to determine how much royalty\n // is owed and to whom.\n /// @param _tokenId - the NFT asset queried for royalty information\n /// @param _value - the sale price of the NFT asset specified by _tokenId\n /// @return _receiver - address of who should be sent the royalty payment\n /// @return _royaltyAmount - the royalty payment amount for value sale price\n function royaltyInfo(uint256 _tokenId, uint256 _value)\n external\n view\n returns (address _receiver, uint256 _royaltyAmount);\n}\n"
},
"contracts/Erc721OperatorFilter/IOperatorFilter.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\ninterface IOperatorFilter {\n function mayTransfer(address operator) external view returns (bool);\n}\n"
},
"contracts/IlluminaNFT_V3.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\nimport '@openzeppelin/contracts/token/ERC721/ERC721.sol';\nimport './ERC2981/ERC2981ContractWideRoyalties.sol';\nimport \"@openzeppelin/contracts/utils/Counters.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport {DefaultOperatorFilterer} from \"./OpenseaOperatorFilter//DefaultOperatorFilterer.sol\";\nimport \"@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol\";\nimport \"@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol\";\nimport \"./BlackSquareNFT.sol\";\nimport \"./OBYToken.sol\";\n\ncontract IlluminaNFT_V3 is ERC721, DefaultOperatorFilterer, Ownable, ERC2981ContractWideRoyalties, VRFConsumerBaseV2 {\n VRFCoordinatorV2Interface COORDINATOR;\n using Counters for Counters.Counter;\n\n uint256 public s_requestId;\n uint256 private min;\n uint256 private max;\n uint256 private illuminaFactor;\n uint256 public illuminationTimeStamp = 0;\n uint256 constant ILLUMINA_BASE_SUPPLY = 20000;\n uint256 constant ILLUMINA_REGULAR_PRICE = 225;\n uint256 constant ILLUMINA_MIN_PRICE = 30;\n uint256 constant THRESHOLD = 25;\n\n uint16 requestConfirmations = 3;\n uint32 numWords = 1;\n uint32 callbackGasLimit = 2500000;\n uint64 s_subscriptionId;\n\n bytes32 keyHash = 0x8af398995b04c28e9951adb9721ef74c74f93e6a478f39e7e0777be13527e7ef;\n address vrfCoordinator = address(0x271682DEB8C4E0901D1a1550aD2e64D568E69909);\n address private treasury;\n\n string private baseURI;\n\n bool public getRandomnessFromOracles;\n bool public editBlacksquareEditions = true;\n bool public simpleMintable = true;\n\n OBYToken obyToken;\n BlackSquareNFT blackSquare;\n Counters.Counter private _tokenIds;\n\n mapping(uint256 => string) private _tokenURIs;\n mapping(address => bool) private _eligibles;\n mapping(uint256 => bool) private _burnedTokens;\n\n event MintToken(uint256 tokenId, address purchaser);\n event BatchMinted();\n\n constructor(address tokenAddress, address _blackSquareAddress, address _treasury, \n uint256 _royaltyValue, uint64 _subscriptionId, string memory _illuminaBaseURI,\n uint256 _minTime, uint256 _maxTime, uint256 _illuminaFactor, bool _getRandomnessFromOracles) VRFConsumerBaseV2(vrfCoordinator) ERC721(\"Illumina\", \"Ill\") {\n COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator);\n obyToken = OBYToken(tokenAddress);\n blackSquare = BlackSquareNFT(_blackSquareAddress);\n treasury = _treasury;\n s_subscriptionId = _subscriptionId;\n baseURI = _illuminaBaseURI;\n min = _minTime;\n max = _maxTime;\n illuminaFactor = _illuminaFactor;\n getRandomnessFromOracles = _getRandomnessFromOracles;\n _setRoyalties(_treasury, _royaltyValue);\n }\n\n modifier onlyEligible() {\n require(owner() == _msgSender() || _eligibles[_msgSender()] == true, \"IlluminaNFT: caller is not eligible\");\n _;\n }\n\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override(ERC721, ERC2981)\n returns (bool)\n {\n return super.supportsInterface(interfaceId);\n }\n\n function setEditBlacksquareEditions (bool _edit) public onlyEligible {\n editBlacksquareEditions = _edit;\n }\n\n function setEligibles(address _eligible, bool _val) public onlyOwner {\n _eligibles[_eligible] = _val;\n }\n\n function setIlluminationTimeStamp(uint256 _illuminationTimeStamp) public onlyEligible {\n illuminationTimeStamp = _illuminationTimeStamp;\n }\n\n function setSimpleMintable(bool _simpleMintable) public onlyEligible {\n simpleMintable = _simpleMintable;\n }\n\n function setRandomnessFromOracles(bool _getRandomnessFromOracles) public onlyOwner {\n getRandomnessFromOracles = _getRandomnessFromOracles;\n }\n\n function setRoyalties(address recipient, uint256 value) external onlyOwner {\n _setRoyalties(recipient, value);\n }\n\n function setKeyHash(bytes32 _keyHash) external onlyOwner {\n keyHash = _keyHash;\n }\n\n function setMin(uint8 _min) external onlyOwner {\n min = _min;\n }\n\n function setMax(uint8 _max) external onlyOwner {\n max = _max;\n }\n\n function setSubscriptionId(uint64 _s_subscriptionId) external onlyOwner {\n s_subscriptionId = _s_subscriptionId;\n }\n\n function setBaseURI(string memory _illuminaBaseURI) external onlyOwner {\n baseURI = _illuminaBaseURI;\n }\n\n function setTokenIpfsHash(uint256 tokenId, string memory ipfsHash) external onlyOwner {\n _tokenURIs[tokenId] = ipfsHash;\n }\n\n function _baseURI() internal view virtual override returns (string memory) {\n return baseURI;\n }\n\n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\n string memory illuminaBaseURI = _baseURI();\n string memory tokenURIHash = _tokenURIs[tokenId];\n return bytes(illuminaBaseURI).length > 0 ? string(abi.encodePacked(illuminaBaseURI, tokenURIHash)) : \"\";\n }\n\n function transferFrom(address from, address to, uint256 tokenId) public override onlyAllowedOperator(from) {\n super.transferFrom(from, to, tokenId);\n }\n\n function safeTransferFrom(address from, address to, uint256 tokenId) public override onlyAllowedOperator(from) {\n super.safeTransferFrom(from, to, tokenId);\n }\n\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data)\n public\n override\n onlyAllowedOperator(from)\n {\n super.safeTransferFrom(from, to, tokenId, data);\n }\n\n function requestRandomWords() internal {\n s_requestId = COORDINATOR.requestRandomWords(\n keyHash,\n s_subscriptionId,\n requestConfirmations,\n callbackGasLimit,\n numWords\n );\n }\n\n function fulfillRandomWords(\n uint256,\n uint256[] memory randomWords\n ) internal override {\n require(randomWords.length > 0, 'OracleContract: No Number delivered');\n uint256 illuminationDate = randomWords[0] % (max - min + 1) + min;\n\n illuminationTimeStamp = illuminationDate;\n }\n\n function getTokensHeldByUser(address user) public view returns (uint256[] memory) {\n uint256 balance = balanceOf(user);\n uint256[] memory emptyTokens = new uint256[](0);\n uint256[] memory tokenIds = new uint256[](balance);\n uint256 j = 0;\n for (uint256 i = 1; i <= _tokenIds.current(); i++ ) {\n if (!_burnedTokens[i]) {\n address tokenOwner = ownerOf(i);\n\n if (tokenOwner == user) {\n tokenIds[j] = i;\n j++;\n }\n }\n }\n return tokenIds.length > 0 ? tokenIds : emptyTokens;\n }\n\n function externalFulfillRequirements(uint256 tokenId, address msgSender) external view onlyEligible {\n fulfillRequirements(tokenId, msgSender);\n }\n\n function externalHandleMint(string memory ipfsHash, uint256 _editionId, address msgSender) external onlyEligible {\n handleMint(ipfsHash, _editionId, msgSender);\n }\n\n function simpleMint(string memory _ipfsHash, uint256 _tokenId) external {\n require(simpleMintable == true, 'No tokens can be minted at the moment');\n fulfillRequirements(_tokenId, _msgSender());\n handleMint(_ipfsHash, 0, _msgSender());\n }\n\n function fulfillRequirements(uint256 tokenId, address msgSender) internal view {\n require(_tokenIds.current() <= ILLUMINA_BASE_SUPPLY, 'Max Amount of Illuminas minted');\n\n require(tokenId == getNextTokenId(), 'Trying to mint Token with incorrect Metadata');\n\n require(blackSquare.getAvailableIlluminaCount() > _tokenIds.current(), 'IlluminaNFT, max mintable number reached');\n (uint256 pricePerToken, ,) = getIlluminaPrice();\n\n bool ok1 = obyToken.checkBalances(pricePerToken, msgSender);\n require(ok1, 'IlluminaNFT, insufficient balances');\n }\n\n function handleMint (string memory ipfsHash, uint256 _editionId, address msgSender) internal {\n _tokenIds.increment();\n\n require(!_exists(_tokenIds.current()), \"IlluminaNFT: Token already exists\");\n (uint256 pricePerToken, ,) = getIlluminaPrice();\n _mint(msgSender, _tokenIds.current());\n\n emit MintToken(_tokenIds.current(), msgSender);\n\n obyToken.burnToken(pricePerToken, msgSender);\n\n _tokenURIs[_tokenIds.current()] = ipfsHash;\n\n if ((_tokenIds.current() == THRESHOLD || (_tokenIds.current() > THRESHOLD && _tokenIds.current() % THRESHOLD == 0))) {\n handleEditionEdit(_editionId);\n }\n }\n\n function handleEditionEdit (uint256 _editionId) internal {\n if (!getRandomnessFromOracles) {\n uint256 randmomNumber = uint256(keccak256(\"wow\")) % (max - min + 1) + min;\n\n uint256 randomnDate = block.timestamp + randmomNumber;\n\n if(editBlacksquareEditions) {\n uint256 editionId = _editionId == 0 ? blackSquare.getFirstEditionToSetIlluminationDate() : _editionId;\n blackSquare.editEdition(editionId, randomnDate);\n } else {\n illuminationTimeStamp = randomnDate;\n }\n } else {\n if(editBlacksquareEditions) {\n requestRandomWords();\n }\n }\n }\n\n function getIlluminaPrice() public view returns (uint256, uint256, uint256) {\n uint256 availableIllumina = blackSquare.getAvailableIlluminaCount();\n\n uint256 soldIllumina = _tokenIds.current();\n\n uint256 vacantIllumina = availableIllumina - soldIllumina;\n\n if (ILLUMINA_REGULAR_PRICE > (vacantIllumina / illuminaFactor)) {\n uint256 residualPrice = ILLUMINA_REGULAR_PRICE - ( vacantIllumina / illuminaFactor );\n\n if (residualPrice > ILLUMINA_MIN_PRICE) {\n return (residualPrice, availableIllumina, vacantIllumina);\n }\n }\n\n return (ILLUMINA_MIN_PRICE, availableIllumina, vacantIllumina);\n }\n\n function getNextTokenId() public view returns (uint256) {\n return blackSquare.getAvailableIlluminaCount() == 0 ? 0 : _tokenIds.current() + 1;\n }\n\n function burnIllumina(address user, uint256 _burnThreshold) public onlyEligible {\n uint256[] memory tokenIds = getTokensHeldByUser(user);\n\n for (uint256 i = 0; i < tokenIds.length; i++ ) {\n if (i < _burnThreshold) {\n uint256 tokenId = tokenIds[i];\n\n super._burn(tokenId);\n\n _burnedTokens[tokenId] = true;\n }\n }\n }\n}"
},
"contracts/OBYToken.sol": {
"content": "//SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\n\n\ncontract OBYToken is ERC20, Ownable {\n mapping(address => bool) private _eligibles;\n\n event Destruction(uint256 amount);\n\n constructor() ERC20(\"OBYToken\", \"OBY\") {}\n\n modifier onlyEligible() {\n require(owner() == _msgSender() || _eligibles[msg.sender], \"OBYToken: caller is not eligible\");\n _;\n }\n\n function setEligibles(address _eligible) public onlyOwner {\n _eligibles[_eligible] = true;\n }\n\n function mint(address account, uint256 amount) external onlyEligible {\n uint256 sendAmount = amount * (10**18);\n _mint(account, sendAmount);\n }\n\n function checkBalances(uint256 tokenPrice, address account) external onlyEligible view returns (bool) {\n if (balanceOf(account) >= tokenPrice) {\n return true;\n }\n return false;\n }\n\n function burnToken(uint256 amount, address account) external onlyEligible {\n uint256 sendAmount = amount * (10**18);\n _burn(account, sendAmount);\n\n emit Destruction(amount);\n }\n\n function getEligibles(address account) public view onlyEligible returns (bool) {\n require (account != address(0), \"OBYToken: address must not be empty\");\n return _eligibles[account];\n }\n}\n"
},
"contracts/OBYTransfer_V2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\nimport '@openzeppelin/contracts/token/ERC721/ERC721.sol';\nimport '@openzeppelin/contracts/token/ERC721/IERC721.sol';\n\nimport \"./OBYToken.sol\";\nimport \"./BlackSquareNFT.sol\";\n\n\ncontract OBYTransfer_V2 {\n using Strings for uint256;\n\n OBYToken obyToken;\n BlackSquareNFT blackSquare;\n\n uint256 constant OBY_PER_CYCLE = 300;\n\n address owner;\n address blacksquareAddress;\n\n bool public claimable;\n\n mapping(uint256 => bool) private _claimedInCycle;\n mapping(address => bool) private _eligibles;\n\n mapping (uint256 => bool) private _claimed;\n\n event RewardWithdrawn(uint256 amount, address sender);\n\n constructor(address _blackSquareAddress, address _obyAddress, bool _claimable) {\n blackSquare = BlackSquareNFT(_blackSquareAddress);\n obyToken = OBYToken(_obyAddress);\n owner = msg.sender;\n claimable = _claimable;\n blacksquareAddress = _blackSquareAddress;\n }\n\n modifier onlyOwner() {\n require(owner == msg.sender, \"OBYTransfer: caller is not eligible\");\n _;\n }\n\n modifier onlyEligible() {\n require(owner == msg.sender || _eligibles[msg.sender ] == true, \"IlluminaNFT: caller is not eligible\");\n _;\n }\n\n function setEligibles(address _eligible) public onlyOwner {\n _eligibles[_eligible] = true;\n }\n\n function setClaimable (bool _claimable) public onlyEligible {\n claimable = _claimable;\n }\n\n function setClaimed (bool _claimable, uint256 _tokenId) public onlyEligible {\n _claimed[_tokenId] = _claimable;\n }\n\n\n function getOwnerOf (uint256 _tokenId) public view returns (address) {\n IERC721 nft = IERC721(blacksquareAddress);\n address tokenOwner = nft.ownerOf(_tokenId);\n\n return tokenOwner;\n }\n\n\n function transferOBYPerToken(uint256 _tokenId) external {\n \n if (getOwnerOf(_tokenId) == msg.sender && !_claimed[_tokenId] && claimable) {\n obyToken.mint(msg.sender, OBY_PER_CYCLE);\n _claimed[_tokenId] = true;\n emit RewardWithdrawn(OBY_PER_CYCLE, msg.sender);\n }\n\n emit RewardWithdrawn(0, msg.sender);\n }\n\n function getAlreadyClaimed(uint256 _tokenId) public view returns (bool) {\n if (_claimed[_tokenId]) {\n bool claimed = _claimed[_tokenId];\n return claimed;\n }\n\n return false;\n \n }\n\n function getTransferableOBYPerToken(uint256 _tokenId) external view returns (uint256) {\n if (getOwnerOf(_tokenId) == msg.sender && !_claimed[_tokenId] && claimable) {\n return OBY_PER_CYCLE;\n }\n return 0;\n }\n\n\n\n function transferOBYForAllTokensHeld() external {\n uint256[] memory tokens = blackSquare.getTokensHeldByUser(msg.sender);\n\n uint256 transferableOBY = 0;\n\n if (tokens.length > 0) {\n\n for (uint256 i = 0; i < tokens.length; i++ ) {\n uint256 tokenId = tokens[i];\n if (getOwnerOf(tokenId) == msg.sender && !_claimed[tokenId] && claimable) {\n transferableOBY += OBY_PER_CYCLE;\n _claimed[tokenId] = true;\n }\n }\n }\n\n if (transferableOBY > 0) {\n obyToken.mint(msg.sender, transferableOBY);\n }\n\n emit RewardWithdrawn(transferableOBY, msg.sender);\n }\n\n function getTransferableOBYForAllTokensHeld() external view returns (uint256) {\n uint256[] memory tokens = blackSquare.getTokensHeldByUser(msg.sender);\n\n uint256 transferableOBY = 0;\n\n if (tokens.length > 0) {\n\n for (uint256 i = 0; i < tokens.length; i++ ) {\n uint256 tokenId = tokens[i];\n if (getOwnerOf(tokenId) == msg.sender && !_claimed[tokenId] && claimable) {\n transferableOBY += OBY_PER_CYCLE;\n }\n }\n }\n return transferableOBY;\n }\n}\n"
},
"contracts/OBYTransfer_V3.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\nimport '@openzeppelin/contracts/token/ERC721/ERC721.sol';\nimport '@openzeppelin/contracts/token/ERC721/IERC721.sol';\n\nimport \"./OBYToken.sol\";\nimport \"./BlackSquareNFT.sol\";\nimport \"./OBYTransfer_V2.sol\";\nimport \"./IlluminaNFT_V3.sol\";\n\n\n\ncontract OBYTransfer_V3 {\n using Strings for uint256;\n\n OBYToken obyToken;\n BlackSquareNFT blackSquare;\n OBYTransfer_V2 obyTransfer_v2;\n IlluminaNFT_V3 illuminaNFT_v3;\n \n uint256 constant OBY_PER_CYCLE = 300;\n uint256 constant TOKEN_PER_EDITION = 25;\n uint256 public maxMintable = 5;\n\n address owner;\n address blacksquareAddress;\n bool public bulkMintable = true;\n bool public claimable;\n\n mapping(uint256 => mapping(uint256 => bool)) private _claimedInCycle;\n mapping(address => bool) private _eligibles;\n\n event RewardWithdrawn(uint256 amount, address sender);\n\n constructor(address _blackSquareAddress, address _obyAddress, bool _claimable, address _obyTransferAddress, address _illuminaNFT_V2) {\n blackSquare = BlackSquareNFT(_blackSquareAddress);\n obyToken = OBYToken(_obyAddress);\n obyTransfer_v2 = OBYTransfer_V2(_obyTransferAddress);\n illuminaNFT_v3 = IlluminaNFT_V3(_illuminaNFT_V2);\n owner = msg.sender;\n claimable = _claimable;\n blacksquareAddress = _blackSquareAddress;\n }\n\n modifier onlyOwner() {\n require(owner == msg.sender, \"OBYTransfer: caller is not eligible\");\n _;\n }\n\n modifier onlyEligible() {\n require(owner == msg.sender || _eligibles[msg.sender ] == true, \"OBYTransfer: caller is not eligible\");\n _;\n }\n\n function setEligibles(address _eligible, bool _val) public onlyOwner {\n _eligibles[_eligible] = _val;\n }\n\n function setClaimable (bool _claimable) public onlyEligible {\n claimable = _claimable;\n }\n\n function setBulkMintAttributes (uint256 _maxMintable, bool _bulkMintable) public onlyEligible {\n maxMintable = _maxMintable;\n bulkMintable =_bulkMintable;\n }\n\n function getOwnerOf (uint256 _tokenId) public view returns (address) {\n IERC721 nft = IERC721(blacksquareAddress);\n address tokenOwner = nft.ownerOf(_tokenId);\n\n return tokenOwner;\n }\n\n function getEditionMapping(uint256 _tokenId) public pure returns (uint256) {\n uint256 multiplier = 10;\n uint256 multipliedEdition = (_tokenId * multiplier) / TOKEN_PER_EDITION;\n\n uint256 editionId = multipliedEdition % multiplier == 0 ? multipliedEdition / multiplier : (multipliedEdition / multiplier) + 1;\n\n return editionId;\n }\n\n function getBlackSquareEditionAttributes (uint256 tokenId) public view returns (uint256, uint256, uint256) {\n BlackSquareNFT.Edition[] memory editions = blackSquare.getEditions();\n uint256 editionId = getEditionMapping(tokenId);\n\n uint256 cycle = editions[editionId].cycle;\n uint256 illuminationTimeStamp = editions[editionId].illuminationTimeStamp;\n\n return (cycle, editionId, illuminationTimeStamp);\n }\n\n function getFirstEditionToBeIlluminated (uint256 _lastEditionToCheck) public view returns (uint256, uint256, uint256) {\n BlackSquareNFT.Edition[] memory editions = blackSquare.getEditions();\n uint256 firstEdition = blackSquare.getFirstEditionToSetIlluminationDate();\n\n uint256 ediontTo = editions[_lastEditionToCheck].id;\n uint256 illu = editions[_lastEditionToCheck].illuminationTimeStamp;\n\n BlackSquareNFT.Edition[] memory returnEditions = new BlackSquareNFT.Edition[](editions.length);\n\n if (firstEdition > 0) {\n \n uint256 l = editions.length;\n for(uint i = 0; i < l; i++) {\n for(uint j = i + 1; j < l ; j++) {\n if(editions[i].illuminationTimeStamp > editions[j].illuminationTimeStamp) {\n BlackSquareNFT.Edition memory temp = editions[i];\n returnEditions[i] = returnEditions[j];\n returnEditions[j] = temp;\n }\n }\n }\n firstEdition = returnEditions[_lastEditionToCheck].id;\n \n }\n return (firstEdition, ediontTo, illu);\n }\n\n function transferOBYPerToken(uint256 _tokenId) external {\n uint256 transferableOby = 0;\n (uint256 cycle, , uint256 illuminationTimeStamp) = getBlackSquareEditionAttributes(_tokenId);\n\n if (cycle > 0 && getOwnerOf(_tokenId) == msg.sender && claimable) {\n\n for (uint256 i = 1; i <= cycle; i++) {\n if (cycle == 1 && !obyTransfer_v2.getAlreadyClaimed(_tokenId) && illuminationTimeStamp < block.timestamp) {\n transferableOby += OBY_PER_CYCLE;\n obyTransfer_v2.setClaimed(false, _tokenId);\n }\n\n if (cycle > 1 && !_claimedInCycle[_tokenId][i] && illuminationTimeStamp < block.timestamp) {\n transferableOby += OBY_PER_CYCLE;\n _claimedInCycle[_tokenId][i] = true;\n }\n }\n\n obyToken.mint(msg.sender, transferableOby);\n\n }\n emit RewardWithdrawn(transferableOby, msg.sender);\n }\n\n \n\n function transferOBYPerCycle() external {\n uint256[] memory tokens = blackSquare.getTokensHeldByUser(msg.sender);\n uint256 transferableOby = 0;\n\n if (claimable) {\n for (uint256 i = 0; i < tokens.length; i++) {\n (uint256 cycle, , uint256 illuminationTimeStamp) = getBlackSquareEditionAttributes(tokens[i]);\n\n if (cycle == 1 && !obyTransfer_v2.getAlreadyClaimed(tokens[i]) && illuminationTimeStamp < block.timestamp) {\n transferableOby += OBY_PER_CYCLE;\n obyTransfer_v2.setClaimed(true, tokens[i]);\n }\n\n if (cycle > 1 && !_claimedInCycle[tokens[i]][cycle] && illuminationTimeStamp < block.timestamp) {\n transferableOby += OBY_PER_CYCLE;\n _claimedInCycle[tokens[i]][cycle] = true;\n }\n }\n }\n\n if (transferableOby > 0) {\n obyToken.mint(msg.sender, transferableOby);\n }\n\n emit RewardWithdrawn(transferableOby, msg.sender);\n }\n\n\n function getAlreadyClaimedInCycle(uint256 _tokenId, uint256 _cycle) public view returns (bool) {\n return _claimedInCycle[_tokenId][_cycle];\n }\n\n\n function getTransferableOBYPerCycle() external view returns (uint256) {\n uint256[] memory tokens = blackSquare.getTokensHeldByUser(msg.sender);\n uint256 transferableOby = 0;\n\n for (uint256 i = 0; i < tokens.length; i++) {\n (uint256 cycle, , uint256 illuminationTimeStamp) = getBlackSquareEditionAttributes(tokens[i]);\n\n if (cycle == 1 && !obyTransfer_v2.getAlreadyClaimed(tokens[i]) && illuminationTimeStamp < block.timestamp) {\n transferableOby += OBY_PER_CYCLE;\n }\n\n if (cycle > 1 && !_claimedInCycle[tokens[i]][cycle] && illuminationTimeStamp < block.timestamp) {\n transferableOby += OBY_PER_CYCLE;\n }\n }\n\n return transferableOby;\n }\n\n function getTransferableOBYPerToken(uint256 _tokenId, bool _checkBeforePurchase) external view returns (uint256) {\n uint256 transferableOby = 0;\n (uint256 cycle, , uint256 illuminationTimeStamp) = getBlackSquareEditionAttributes(_tokenId);\n\n if (cycle > 0 && claimable) {\n\n for (uint256 i = 1; i <= cycle; i++) {\n \n if (cycle == 1 && !obyTransfer_v2.getAlreadyClaimed(_tokenId)) {\n if (_checkBeforePurchase) {\n transferableOby += OBY_PER_CYCLE;\n }\n if (!_checkBeforePurchase && illuminationTimeStamp < block.timestamp) {\n transferableOby += OBY_PER_CYCLE;\n }\n }\n\n if (cycle > 1 && !_claimedInCycle[_tokenId][i]) {\n if (_checkBeforePurchase) {\n transferableOby += OBY_PER_CYCLE;\n }\n if (!_checkBeforePurchase && illuminationTimeStamp < block.timestamp) {\n transferableOby += OBY_PER_CYCLE;\n }\n }\n }\n }\n return transferableOby;\n }\n\n function mintIlluminaInBulk (string[] memory _ipfsHashes, uint256[] memory _tokens, uint256 _lastEditionToCheck) external {\n if (bulkMintable && _ipfsHashes.length == _tokens.length && _tokens.length == maxMintable) {\n (uint256 editionId,,) = getFirstEditionToBeIlluminated(_lastEditionToCheck);\n for (uint256 i = 0; i < _tokens.length; i++) {\n illuminaNFT_v3.externalFulfillRequirements(_tokens[i], msg.sender);\n illuminaNFT_v3.externalHandleMint(_ipfsHashes[i], editionId, msg.sender);\n }\n }\n }\n}"
},
"contracts/OpenseaOperatorFilter/DefaultOperatorFilterer.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\nimport {OperatorFilterer} from \"./OperatorFilterer.sol\";\n\nabstract contract DefaultOperatorFilterer is OperatorFilterer {\n address constant DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);\n\n constructor() OperatorFilterer(DEFAULT_SUBSCRIPTION, true) {}\n}"
},
"contracts/OpenseaOperatorFilter/IOperatorFilterRegistry.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\ninterface IOperatorFilterRegistry {\n function isOperatorAllowed(address registrant, address operator) external view returns (bool);\n function register(address registrant) external;\n function registerAndSubscribe(address registrant, address subscription) external;\n function registerAndCopyEntries(address registrant, address registrantToCopy) external;\n function unregister(address addr) external;\n function updateOperator(address registrant, address operator, bool filtered) external;\n function updateOperators(address registrant, address[] calldata operators, bool filtered) external;\n function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external;\n function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external;\n function subscribe(address registrant, address registrantToSubscribe) external;\n function unsubscribe(address registrant, bool copyExistingEntries) external;\n function subscriptionOf(address addr) external returns (address registrant);\n function subscribers(address registrant) external returns (address[] memory);\n function subscriberAt(address registrant, uint256 index) external returns (address);\n function copyEntriesOf(address registrant, address registrantToCopy) external;\n function isOperatorFiltered(address registrant, address operator) external returns (bool);\n function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool);\n function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool);\n function filteredOperators(address addr) external returns (address[] memory);\n function filteredCodeHashes(address addr) external returns (bytes32[] memory);\n function filteredOperatorAt(address registrant, uint256 index) external returns (address);\n function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32);\n function isRegistered(address addr) external returns (bool);\n function codeHashOf(address addr) external returns (bytes32);\n}"
},
"contracts/OpenseaOperatorFilter/OperatorFilterer.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.7;\n\nimport {IOperatorFilterRegistry} from \"./IOperatorFilterRegistry.sol\";\n\nabstract contract OperatorFilterer {\n error OperatorNotAllowed(address operator);\n\n IOperatorFilterRegistry constant operatorFilterRegistry =\n IOperatorFilterRegistry(0x000000000000AAeB6D7670E522A718067333cd4E);\n\n constructor(address subscriptionOrRegistrantToCopy, bool subscribe) {\n // If an inheriting token contract is deployed to a network without the registry deployed, the modifier\n // will not revert, but the contract will need to be registered with the registry once it is deployed in\n // order for the modifier to filter addresses.\n if (address(operatorFilterRegistry).code.length > 0) {\n if (subscribe) {\n operatorFilterRegistry.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);\n } else {\n if (subscriptionOrRegistrantToCopy != address(0)) {\n operatorFilterRegistry.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);\n } else {\n operatorFilterRegistry.register(address(this));\n }\n }\n }\n }\n\n modifier onlyAllowedOperator(address from) virtual {\n // Check registry code length to facilitate testing in environments without a deployed registry.\n if (address(operatorFilterRegistry).code.length > 0) {\n // Allow spending tokens from addresses with balance\n // Note that this still allows listings and marketplaces with escrow to transfer tokens if transferred\n // from an EOA.\n if (from == msg.sender) {\n _;\n return;\n }\n if (\n !(\n operatorFilterRegistry.isOperatorAllowed(address(this), msg.sender)\n && operatorFilterRegistry.isOperatorAllowed(address(this), from)\n )\n ) {\n revert OperatorNotAllowed(msg.sender);\n }\n }\n _;\n }\n}"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}