{ "language": "Solidity", "sources": { "src/contracts/nft/KeepersOptimized.sol": { "content": "// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.14;\r\n\r\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\r\nimport \"@openzeppelin/contracts/utils/Strings.sol\";\r\nimport \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\r\n\r\nimport \"./ERC721A.sol\";\r\n\r\nimport {ASingleAllowlistMerkle} from \"../whitelist/ASingleAllowlistMerkle.sol\";\r\nimport {AMultiFounderslistMerkle} from \"../whitelist/AMultiFounderslistMerkle.sol\";\r\n\r\n// ____ __.\r\n// | |/ _|____ ____ ______ ___________ ______\r\n// | <_/ __ \\_/ __ \\\\____ \\_/ __ \\_ __ \\/ ___/\r\n// | | \\ ___/\\ ___/| |_> > ___/| | \\/\\___ \\\r\n// |____|__ \\___ >\\___ > __/ \\___ >__| /____ >\r\n// \\/ \\/ \\/|__| \\/ \\/\r\n\r\n// Supply Errors\r\nerror ExceedingMaxSupply();\r\n\r\n// Allow-list Errors\r\nerror ExceedingFoundersListEntitlements();\r\nerror ExceedingAllowListMaxMint();\r\n\r\n// Withdrawal Errors\r\nerror ETHTransferFailed();\r\nerror RefundOverpayFailed();\r\n\r\n// Minting Errors\r\nerror MaxMintPerAddressExceeded();\r\n\r\n// Signature Errors\r\nerror HashMismatch();\r\nerror SignatureMismatch();\r\nerror NonceAlreadyUsed();\r\n\r\n// Commit-Reveal errors\r\nerror AlreadyCommitted();\r\nerror NotCommitted();\r\nerror AlreadyRevealed();\r\nerror TooEarlyForReveal();\r\n\r\n// Generic Errors\r\nerror ContractPaused();\r\nerror IncorrectPrice();\r\nerror ContractsNotAllowed();\r\n\r\n/// @title Keepers NFT Contract\r\n/// @author Karmabadger\r\n/// @notice This is the main NFT contract for Keepers.\r\n/// @dev This contract is used to mint NFTs for Keepers.\r\ncontract KeepersOptimized is ERC721A, ASingleAllowlistMerkle, AMultiFounderslistMerkle {\r\n using Strings for uint256;\r\n using ECDSA for bytes32;\r\n\r\n uint256 public constant MAX_SUPPLY = 10000;\r\n \r\n uint256 public mintedReservedSupply;\r\n uint256 public mintedAllowlistSupply;\r\n uint256 public mintedFounderslistSupply;\r\n uint256 public mintedPublicSupply;\r\n\r\n uint256 public publicPrice = 0.2 ether;\r\n \r\n uint256 public constant MAX_MINT_PER_ADDRESS = 3;\r\n uint256 public constant MAX_ALLOW_LIST_MINTS = 2;\r\n\r\n uint256 public futureBlockToUse;\r\n uint256 public tokenIdShift;\r\n\r\n string public baseURI;\r\n string public hiddenURI;\r\n\r\n string public provenanceHash;\r\n\r\n address public signerAddress;\r\n\r\n bool public paused = true;\r\n bool public revealed;\r\n\r\n mapping(bytes32 => bool) public nonceUsed;\r\n\r\n // Aux Storage (64 bits) Layout:\r\n // - [0..1] `allowListMints` (how many allow-list mints a wallet performed, up to 3)\r\n // - [2..17] `foundersListMints` (how many founders-list mints a wallet performs; this probably doesn't NEED 16 bits but we have space)\r\n // - [18..20] `publicMints` (how many public mints by a wallet, up to 5 - allowListMints)\r\n // - [20..63] (unused)\r\n\r\n /// @notice This is the constructor for the Keepers NFT contract.\r\n /// @dev sets the default admin role of the contract.\r\n /// @param _owner the default admin to be set to the contract\r\n constructor(address _owner, bytes32 _allowlistMerkleRoot, bytes32 _foundersListMerkleRoot, address _signer)\r\n ERC721A(\"Keepers\", \"KPR\")\r\n ASingleAllowlistMerkle(_allowlistMerkleRoot)\r\n AMultiFounderslistMerkle(_foundersListMerkleRoot)\r\n {\r\n transferOwnership(_owner);\r\n signerAddress = _signer;\r\n }\r\n\r\n /* Utility Methods */\r\n\r\n function getBits(uint256 _input, uint256 _startBit, uint256 _length) private pure returns (uint256) {\r\n uint256 bitMask = ((1 << _length) - 1) << _startBit;\r\n\r\n uint256 outBits = _input & bitMask;\r\n\r\n return outBits >> _startBit;\r\n }\r\n\r\n function getFoundersListMints(address _minter) public view returns (uint256) {\r\n return getBits(_getAux(_minter), 2, 16);\r\n }\r\n\r\n function getAllowListMints(address _minter) public view returns (uint256) {\r\n return getBits(_getAux(_minter), 0, 2);\r\n }\r\n\r\n function getPublicMints(address _minter) public view returns (uint256) {\r\n return getBits(_getAux(_minter), 18, 3);\r\n }\r\n\r\n /* Pausable */\r\n\r\n function setPaused(bool _state) external payable onlyOwner {\r\n paused = _state;\r\n }\r\n\r\n /* Signatures */\r\n\r\n function setSignerAddress(address _signer) external onlyOwner {\r\n signerAddress = _signer;\r\n }\r\n\r\n /* Pricing */\r\n\r\n function setPublicPrice(uint256 _pubPrice) external onlyOwner {\r\n publicPrice = _pubPrice;\r\n }\r\n\r\n /* ETH Withdrawals */\r\n\r\n function ownerPullETH() external onlyOwner { \r\n (bool success, ) = payable(msg.sender).call{\r\n value: address(this).balance\r\n }(\"\");\r\n if (!success) revert ETHTransferFailed();\r\n }\r\n\r\n /* Minting */\r\n\r\n /// @notice Safely mints NFTs in the reserved supply. Note: These will likely end up hidden on OpenSea\r\n /// @dev Only the Owner can mint reserved NFTs.\r\n /// @param _receiver The address of the receiver\r\n /// @param _amount The quantity to aidrop\r\n function mintReserved(address _receiver, uint256 _amount) external payable mintCompliance(_amount) onlyOwner {\r\n mintedReservedSupply += _amount;\r\n\r\n _mint(_receiver, _amount);\r\n }\r\n\r\n /// @notice Safely mints NFTs from founders list.\r\n /// @dev free\r\n function mintFounderslist(bytes32[] calldata _merkleProof, uint16 _entitlementAmount, uint256 _amount) external mintCompliance(_amount) onlyFounderslisted(_merkleProof, _entitlementAmount) whenNotPaused { \r\n uint256 foundersListMints = getBits(_getAux(msg.sender), 2, 16);\r\n if (foundersListMints + _amount > _entitlementAmount) revert ExceedingFoundersListEntitlements();\r\n\r\n mintedFounderslistSupply += _amount;\r\n _setAux(msg.sender, _getAux(msg.sender) + uint64(_amount << 2));\r\n\r\n _mint(msg.sender, _amount);\r\n }\r\n\r\n /// @notice Safely mints NFTs from allowlist.\r\n /// @dev pays the lowest auction price\r\n function mintAllowlist(bytes32[] calldata _merkleProof, uint256 _amount) external payable mintCompliance(_amount) onlyAllowlisted(_merkleProof) whenNotPaused {\r\n uint256 totalPrice = publicPrice * _amount;\r\n if (msg.value != totalPrice) revert IncorrectPrice();\r\n\r\n uint256 allowListMints = getBits(_getAux(msg.sender), 0, 2);\r\n if (allowListMints + _amount > MAX_ALLOW_LIST_MINTS) revert ExceedingAllowListMaxMint();\r\n\r\n mintedAllowlistSupply += _amount;\r\n _setAux(msg.sender, _getAux(msg.sender) + uint64(_amount));\r\n\r\n _mint(msg.sender, _amount);\r\n }\r\n\r\n /// @notice mint function\r\n /// @param _amount The amount of NFTs to be minted\r\n /**\r\n ** @dev the user has to send at least the current price in ETH to buy the NFTs (extras are refunded).\r\n ** we removed nonReentrant since all external calls are moved to the end.\r\n ** transfer() only forwards 2300 gas units which garantees no reentrancy.\r\n ** the optimized mint() function uses _mint() which does not check ERC721Receiver since we do not allow contracts minting.\r\n ** @dev removed all auction logic, this is now just a flat-rate public mint\r\n */\r\n function mintPublic(uint256 _amount, bytes32 _nonce, bytes32 _hash, uint8 v, bytes32 r, bytes32 s) external payable mintCompliance(_amount) whenNotPaused {\r\n if (tx.origin != msg.sender) revert ContractsNotAllowed();\r\n \r\n // https://docs.openzeppelin.com/contracts/2.x/utilities\r\n if (nonceUsed[_nonce]) revert NonceAlreadyUsed();\r\n\r\n if (_hash != keccak256(\r\n abi.encodePacked(msg.sender, _nonce, address(this))\r\n )) revert HashMismatch();\r\n\r\n bytes32 messageDigest = keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", _hash));\r\n\r\n if (signerAddress != ecrecover(messageDigest, v, r, s)) revert SignatureMismatch();\r\n\r\n nonceUsed[_nonce] = true;\r\n\r\n uint256 totalPrice = publicPrice * _amount;\r\n if (msg.value != totalPrice) revert IncorrectPrice();\r\n\r\n uint256 allowListMints = getBits(_getAux(msg.sender), 0, 2);\r\n uint256 publicMints = getBits(_getAux(msg.sender), 18, 3);\r\n if (allowListMints + publicMints + _amount > MAX_MINT_PER_ADDRESS) revert MaxMintPerAddressExceeded();\r\n\r\n mintedPublicSupply += _amount;\r\n _setAux(msg.sender, _getAux(msg.sender) + uint64(_amount << 18));\r\n\r\n _mint(msg.sender, _amount);\r\n }\r\n\r\n /* Commit-reveal and metadata */\r\n\r\n // Including all of the Metadata logic here now, as ABaseNFTCommitment and OptimizedERC721 were having some collision issues\r\n // https://medium.com/@cryptosecgroup/provably-fair-nft-launches-nftgoblins-commit-reveal-scheme-9aaf240bd4ad\r\n\r\n function commit(string calldata _provenanceHash) external payable onlyOwner {\r\n // Can only commit once\r\n // Note: A reveal has to happen within 256 blocks or this will break\r\n if (futureBlockToUse != 0) revert AlreadyCommitted();\r\n\r\n provenanceHash = _provenanceHash;\r\n futureBlockToUse = block.number + 5;\r\n }\r\n\r\n function reveal() external payable onlyOwner {\r\n if (futureBlockToUse == 0) revert NotCommitted();\r\n\r\n if (block.number < futureBlockToUse) revert TooEarlyForReveal();\r\n\r\n if (revealed) revert AlreadyRevealed();\r\n\r\n tokenIdShift = (uint256(blockhash(futureBlockToUse)) % MAX_SUPPLY) + 1;\r\n\r\n revealed = true;\r\n }\r\n\r\n function setHiddenURI(string memory _hiddenURI) external onlyOwner {\r\n hiddenURI = _hiddenURI;\r\n }\r\n\r\n function setBaseURI(string memory _baseURI) external onlyOwner {\r\n baseURI = _baseURI;\r\n }\r\n\r\n function getBaseURI() external view returns (string memory) {\r\n return baseURI;\r\n }\r\n\r\n function tokenURI(uint256 _tokenId) public view override returns (string memory) {\r\n if (revealed) {\r\n uint256 shiftedTokenId = (_tokenId + tokenIdShift) % MAX_SUPPLY;\r\n\r\n return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, shiftedTokenId.toString(), \".json\")) : \"\";\r\n }\r\n else {\r\n return hiddenURI;\r\n }\r\n }\r\n\r\n /* Modifiers */\r\n\r\n modifier whenNotPaused() {\r\n if (paused) revert ContractPaused();\r\n _;\r\n }\r\n\r\n modifier mintCompliance(uint256 _amount) {\r\n if ((totalSupply() + _amount) > MAX_SUPPLY) revert ExceedingMaxSupply();\r\n _;\r\n }\r\n}" }, "lib/openzeppelin-contracts/contracts/access/Ownable.sol": { "content": "// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\nimport \"../utils/Context.sol\";\r\n\r\n/**\r\n * @dev Contract module which provides a basic access control mechanism, where\r\n * there is an account (an owner) that can be granted exclusive access to\r\n * specific functions.\r\n *\r\n * By default, the owner account will be the one that deploys the contract. This\r\n * can later be changed with {transferOwnership}.\r\n *\r\n * This module is used through inheritance. It will make available the modifier\r\n * `onlyOwner`, which can be applied to your functions to restrict their use to\r\n * the owner.\r\n */\r\nabstract contract Ownable is Context {\r\n address private _owner;\r\n\r\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r\n\r\n /**\r\n * @dev Initializes the contract setting the deployer as the initial owner.\r\n */\r\n constructor() {\r\n _transferOwnership(_msgSender());\r\n }\r\n\r\n /**\r\n * @dev Returns the address of the current owner.\r\n */\r\n function owner() public view virtual returns (address) {\r\n return _owner;\r\n }\r\n\r\n /**\r\n * @dev Throws if called by any account other than the owner.\r\n */\r\n modifier onlyOwner() {\r\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\r\n _;\r\n }\r\n\r\n /**\r\n * @dev Leaves the contract without owner. It will not be possible to call\r\n * `onlyOwner` functions anymore. Can only be called by the current owner.\r\n *\r\n * NOTE: Renouncing ownership will leave the contract without an owner,\r\n * thereby removing any functionality that is only available to the owner.\r\n */\r\n function renounceOwnership() public virtual onlyOwner {\r\n _transferOwnership(address(0));\r\n }\r\n\r\n /**\r\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\r\n * Can only be called by the current owner.\r\n */\r\n function transferOwnership(address newOwner) public virtual onlyOwner {\r\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\r\n _transferOwnership(newOwner);\r\n }\r\n\r\n /**\r\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\r\n * Internal function without access restriction.\r\n */\r\n function _transferOwnership(address newOwner) internal virtual {\r\n address oldOwner = _owner;\r\n _owner = newOwner;\r\n emit OwnershipTransferred(oldOwner, newOwner);\r\n }\r\n}\r\n" }, "lib/openzeppelin-contracts/contracts/utils/Strings.sol": { "content": "// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev String operations.\r\n */\r\nlibrary Strings {\r\n bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\r\n\r\n /**\r\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\r\n */\r\n function toString(uint256 value) internal pure returns (string memory) {\r\n // Inspired by OraclizeAPI's implementation - MIT licence\r\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\r\n\r\n if (value == 0) {\r\n return \"0\";\r\n }\r\n uint256 temp = value;\r\n uint256 digits;\r\n while (temp != 0) {\r\n digits++;\r\n temp /= 10;\r\n }\r\n bytes memory buffer = new bytes(digits);\r\n while (value != 0) {\r\n digits -= 1;\r\n buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\r\n value /= 10;\r\n }\r\n return string(buffer);\r\n }\r\n\r\n /**\r\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\r\n */\r\n function toHexString(uint256 value) internal pure returns (string memory) {\r\n if (value == 0) {\r\n return \"0x00\";\r\n }\r\n uint256 temp = value;\r\n uint256 length = 0;\r\n while (temp != 0) {\r\n length++;\r\n temp >>= 8;\r\n }\r\n return toHexString(value, length);\r\n }\r\n\r\n /**\r\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\r\n */\r\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\r\n bytes memory buffer = new bytes(2 * length + 2);\r\n buffer[0] = \"0\";\r\n buffer[1] = \"x\";\r\n for (uint256 i = 2 * length + 1; i > 1; --i) {\r\n buffer[i] = _HEX_SYMBOLS[value & 0xf];\r\n value >>= 4;\r\n }\r\n require(value == 0, \"Strings: hex length insufficient\");\r\n return string(buffer);\r\n }\r\n}\r\n" }, "lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol": { "content": "// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/ECDSA.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\nimport \"../Strings.sol\";\r\n\r\n/**\r\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\r\n *\r\n * These functions can be used to verify that a message was signed by the holder\r\n * of the private keys of a given address.\r\n */\r\nlibrary ECDSA {\r\n enum RecoverError {\r\n NoError,\r\n InvalidSignature,\r\n InvalidSignatureLength,\r\n InvalidSignatureS,\r\n InvalidSignatureV\r\n }\r\n\r\n function _throwError(RecoverError error) private pure {\r\n if (error == RecoverError.NoError) {\r\n return; // no error: do nothing\r\n } else if (error == RecoverError.InvalidSignature) {\r\n revert(\"ECDSA: invalid signature\");\r\n } else if (error == RecoverError.InvalidSignatureLength) {\r\n revert(\"ECDSA: invalid signature length\");\r\n } else if (error == RecoverError.InvalidSignatureS) {\r\n revert(\"ECDSA: invalid signature 's' value\");\r\n } else if (error == RecoverError.InvalidSignatureV) {\r\n revert(\"ECDSA: invalid signature 'v' value\");\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the address that signed a hashed message (`hash`) with\r\n * `signature` or error string. This address can then be used for verification purposes.\r\n *\r\n * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\r\n * this function rejects them by requiring the `s` value to be in the lower\r\n * half order, and the `v` value to be either 27 or 28.\r\n *\r\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\r\n * verification to be secure: it is possible to craft signatures that\r\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\r\n * this is by receiving a hash of the original message (which may otherwise\r\n * be too long), and then calling {toEthSignedMessageHash} on it.\r\n *\r\n * Documentation for signature generation:\r\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\r\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\r\n *\r\n * _Available since v4.3._\r\n */\r\n function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {\r\n // Check the signature length\r\n // - case 65: r,s,v signature (standard)\r\n // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._\r\n if (signature.length == 65) {\r\n bytes32 r;\r\n bytes32 s;\r\n uint8 v;\r\n // ecrecover takes the signature parameters, and the only way to get them\r\n // currently is to use assembly.\r\n assembly {\r\n r := mload(add(signature, 0x20))\r\n s := mload(add(signature, 0x40))\r\n v := byte(0, mload(add(signature, 0x60)))\r\n }\r\n return tryRecover(hash, v, r, s);\r\n } else if (signature.length == 64) {\r\n bytes32 r;\r\n bytes32 vs;\r\n // ecrecover takes the signature parameters, and the only way to get them\r\n // currently is to use assembly.\r\n assembly {\r\n r := mload(add(signature, 0x20))\r\n vs := mload(add(signature, 0x40))\r\n }\r\n return tryRecover(hash, r, vs);\r\n } else {\r\n return (address(0), RecoverError.InvalidSignatureLength);\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the address that signed a hashed message (`hash`) with\r\n * `signature`. This address can then be used for verification purposes.\r\n *\r\n * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\r\n * this function rejects them by requiring the `s` value to be in the lower\r\n * half order, and the `v` value to be either 27 or 28.\r\n *\r\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\r\n * verification to be secure: it is possible to craft signatures that\r\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\r\n * this is by receiving a hash of the original message (which may otherwise\r\n * be too long), and then calling {toEthSignedMessageHash} on it.\r\n */\r\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\r\n (address recovered, RecoverError error) = tryRecover(hash, signature);\r\n _throwError(error);\r\n return recovered;\r\n }\r\n\r\n /**\r\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\r\n *\r\n * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\r\n *\r\n * _Available since v4.3._\r\n */\r\n function tryRecover(\r\n bytes32 hash,\r\n bytes32 r,\r\n bytes32 vs\r\n ) internal pure returns (address, RecoverError) {\r\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\r\n uint8 v = uint8((uint256(vs) >> 255) + 27);\r\n return tryRecover(hash, v, r, s);\r\n }\r\n\r\n /**\r\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\r\n *\r\n * _Available since v4.2._\r\n */\r\n function recover(\r\n bytes32 hash,\r\n bytes32 r,\r\n bytes32 vs\r\n ) internal pure returns (address) {\r\n (address recovered, RecoverError error) = tryRecover(hash, r, vs);\r\n _throwError(error);\r\n return recovered;\r\n }\r\n\r\n /**\r\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\r\n * `r` and `s` signature fields separately.\r\n *\r\n * _Available since v4.3._\r\n */\r\n function tryRecover(\r\n bytes32 hash,\r\n uint8 v,\r\n bytes32 r,\r\n bytes32 s\r\n ) internal pure returns (address, RecoverError) {\r\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\r\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\r\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\r\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\r\n //\r\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\r\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\r\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\r\n // these malleable signatures as well.\r\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\r\n return (address(0), RecoverError.InvalidSignatureS);\r\n }\r\n if (v != 27 && v != 28) {\r\n return (address(0), RecoverError.InvalidSignatureV);\r\n }\r\n\r\n // If the signature is valid (and not malleable), return the signer address\r\n address signer = ecrecover(hash, v, r, s);\r\n if (signer == address(0)) {\r\n return (address(0), RecoverError.InvalidSignature);\r\n }\r\n\r\n return (signer, RecoverError.NoError);\r\n }\r\n\r\n /**\r\n * @dev Overload of {ECDSA-recover} that receives the `v`,\r\n * `r` and `s` signature fields separately.\r\n */\r\n function recover(\r\n bytes32 hash,\r\n uint8 v,\r\n bytes32 r,\r\n bytes32 s\r\n ) internal pure returns (address) {\r\n (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\r\n _throwError(error);\r\n return recovered;\r\n }\r\n\r\n /**\r\n * @dev Returns an Ethereum Signed Message, created from a `hash`. This\r\n * produces hash corresponding to the one signed with the\r\n * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\r\n * JSON-RPC method as part of EIP-191.\r\n *\r\n * See {recover}.\r\n */\r\n function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {\r\n // 32 is the length in bytes of hash,\r\n // enforced by the type signature above\r\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", hash));\r\n }\r\n\r\n /**\r\n * @dev Returns an Ethereum Signed Message, created from `s`. This\r\n * produces hash corresponding to the one signed with the\r\n * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\r\n * JSON-RPC method as part of EIP-191.\r\n *\r\n * See {recover}.\r\n */\r\n function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\r\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", Strings.toString(s.length), s));\r\n }\r\n\r\n /**\r\n * @dev Returns an Ethereum Signed Typed Data, created from a\r\n * `domainSeparator` and a `structHash`. This produces hash corresponding\r\n * to the one signed with the\r\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]\r\n * JSON-RPC method as part of EIP-712.\r\n *\r\n * See {recover}.\r\n */\r\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {\r\n return keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\r\n }\r\n}\r\n" }, "src/contracts/nft/ERC721A.sol": { "content": "// SPDX-License-Identifier: MIT\r\n// ERC721A Contracts v4.2.3\r\n// Creator: Chiru Labs\r\n\r\npragma solidity ^0.8.4;\r\n\r\nimport './IERC721A.sol';\r\n\r\n/**\r\n * @dev Interface of ERC721 token receiver.\r\n */\r\ninterface ERC721A__IERC721Receiver {\r\n function onERC721Received(\r\n address operator,\r\n address from,\r\n uint256 tokenId,\r\n bytes calldata data\r\n ) external returns (bytes4);\r\n}\r\n\r\n/**\r\n * @title ERC721A\r\n *\r\n * @dev Implementation of the [ERC721](https://eips.ethereum.org/EIPS/eip-721)\r\n * Non-Fungible Token Standard, including the Metadata extension.\r\n * Optimized for lower gas during batch mints.\r\n *\r\n * Token IDs are minted in sequential order (e.g. 0, 1, 2, 3, ...)\r\n * starting from `_startTokenId()`.\r\n *\r\n * Assumptions:\r\n *\r\n * - An owner cannot have more than 2**64 - 1 (max value of uint64) of supply.\r\n * - The maximum token ID cannot exceed 2**256 - 1 (max value of uint256).\r\n */\r\ncontract ERC721A is IERC721A {\r\n // Bypass for a `--via-ir` bug (https://github.com/chiru-labs/ERC721A/pull/364).\r\n struct TokenApprovalRef {\r\n address value;\r\n }\r\n\r\n // =============================================================\r\n // CONSTANTS\r\n // =============================================================\r\n\r\n // Mask of an entry in packed address data.\r\n uint256 private constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;\r\n\r\n // The bit position of `numberMinted` in packed address data.\r\n uint256 private constant _BITPOS_NUMBER_MINTED = 64;\r\n\r\n // The bit position of `numberBurned` in packed address data.\r\n uint256 private constant _BITPOS_NUMBER_BURNED = 128;\r\n\r\n // The bit position of `aux` in packed address data.\r\n uint256 private constant _BITPOS_AUX = 192;\r\n\r\n // Mask of all 256 bits in packed address data except the 64 bits for `aux`.\r\n uint256 private constant _BITMASK_AUX_COMPLEMENT = (1 << 192) - 1;\r\n\r\n // The bit position of `startTimestamp` in packed ownership.\r\n uint256 private constant _BITPOS_START_TIMESTAMP = 160;\r\n\r\n // The bit mask of the `burned` bit in packed ownership.\r\n uint256 private constant _BITMASK_BURNED = 1 << 224;\r\n\r\n // The bit position of the `nextInitialized` bit in packed ownership.\r\n uint256 private constant _BITPOS_NEXT_INITIALIZED = 225;\r\n\r\n // The bit mask of the `nextInitialized` bit in packed ownership.\r\n uint256 private constant _BITMASK_NEXT_INITIALIZED = 1 << 225;\r\n\r\n // The bit position of `extraData` in packed ownership.\r\n uint256 private constant _BITPOS_EXTRA_DATA = 232;\r\n\r\n // Mask of all 256 bits in a packed ownership except the 24 bits for `extraData`.\r\n uint256 private constant _BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1;\r\n\r\n // The mask of the lower 160 bits for addresses.\r\n uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;\r\n\r\n // The maximum `quantity` that can be minted with {_mintERC2309}.\r\n // This limit is to prevent overflows on the address data entries.\r\n // For a limit of 5000, a total of 3.689e15 calls to {_mintERC2309}\r\n // is required to cause an overflow, which is unrealistic.\r\n uint256 private constant _MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;\r\n\r\n // The `Transfer` event signature is given by:\r\n // `keccak256(bytes(\"Transfer(address,address,uint256)\"))`.\r\n bytes32 private constant _TRANSFER_EVENT_SIGNATURE =\r\n 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;\r\n\r\n // =============================================================\r\n // STORAGE\r\n // =============================================================\r\n\r\n // The next token ID to be minted.\r\n uint256 private _currentIndex;\r\n\r\n // The number of tokens burned.\r\n uint256 private _burnCounter;\r\n\r\n // Token name\r\n string private _name;\r\n\r\n // Token symbol\r\n string private _symbol;\r\n\r\n // Mapping from token ID to ownership details\r\n // An empty struct value does not necessarily mean the token is unowned.\r\n // See {_packedOwnershipOf} implementation for details.\r\n //\r\n // Bits Layout:\r\n // - [0..159] `addr`\r\n // - [160..223] `startTimestamp`\r\n // - [224] `burned`\r\n // - [225] `nextInitialized`\r\n // - [232..255] `extraData`\r\n mapping(uint256 => uint256) private _packedOwnerships;\r\n\r\n // Mapping owner address to address data.\r\n //\r\n // Bits Layout:\r\n // - [0..63] `balance`\r\n // - [64..127] `numberMinted`\r\n // - [128..191] `numberBurned`\r\n // - [192..255] `aux`\r\n mapping(address => uint256) private _packedAddressData;\r\n\r\n // Mapping from token ID to approved address.\r\n mapping(uint256 => TokenApprovalRef) private _tokenApprovals;\r\n\r\n // Mapping from owner to operator approvals\r\n mapping(address => mapping(address => bool)) private _operatorApprovals;\r\n\r\n // =============================================================\r\n // CONSTRUCTOR\r\n // =============================================================\r\n\r\n constructor(string memory name_, string memory symbol_) {\r\n _name = name_;\r\n _symbol = symbol_;\r\n _currentIndex = _startTokenId();\r\n }\r\n\r\n // =============================================================\r\n // TOKEN COUNTING OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the starting token ID.\r\n * To change the starting token ID, please override this function.\r\n */\r\n function _startTokenId() internal view virtual returns (uint256) {\r\n return 0;\r\n }\r\n\r\n /**\r\n * @dev Returns the next token ID to be minted.\r\n */\r\n function _nextTokenId() internal view virtual returns (uint256) {\r\n return _currentIndex;\r\n }\r\n\r\n /**\r\n * @dev Returns the total number of tokens in existence.\r\n * Burned tokens will reduce the count.\r\n * To get the total number of tokens minted, please see {_totalMinted}.\r\n */\r\n function totalSupply() public view virtual override returns (uint256) {\r\n // Counter underflow is impossible as _burnCounter cannot be incremented\r\n // more than `_currentIndex - _startTokenId()` times.\r\n unchecked {\r\n return _currentIndex - _burnCounter - _startTokenId();\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the total amount of tokens minted in the contract.\r\n */\r\n function _totalMinted() internal view virtual returns (uint256) {\r\n // Counter underflow is impossible as `_currentIndex` does not decrement,\r\n // and it is initialized to `_startTokenId()`.\r\n unchecked {\r\n return _currentIndex - _startTokenId();\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the total number of tokens burned.\r\n */\r\n function _totalBurned() internal view virtual returns (uint256) {\r\n return _burnCounter;\r\n }\r\n\r\n // =============================================================\r\n // ADDRESS DATA OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the number of tokens in `owner`'s account.\r\n */\r\n function balanceOf(address owner) public view virtual override returns (uint256) {\r\n if (owner == address(0)) revert BalanceQueryForZeroAddress();\r\n return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY;\r\n }\r\n\r\n /**\r\n * Returns the number of tokens minted by `owner`.\r\n */\r\n function _numberMinted(address owner) internal view returns (uint256) {\r\n return (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & _BITMASK_ADDRESS_DATA_ENTRY;\r\n }\r\n\r\n /**\r\n * Returns the number of tokens burned by or on behalf of `owner`.\r\n */\r\n function _numberBurned(address owner) internal view returns (uint256) {\r\n return (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & _BITMASK_ADDRESS_DATA_ENTRY;\r\n }\r\n\r\n /**\r\n * Returns the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).\r\n */\r\n function _getAux(address owner) internal view returns (uint64) {\r\n return uint64(_packedAddressData[owner] >> _BITPOS_AUX);\r\n }\r\n\r\n /**\r\n * Sets the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).\r\n * If there are multiple variables, please pack them into a uint64.\r\n */\r\n function _setAux(address owner, uint64 aux) internal virtual {\r\n uint256 packed = _packedAddressData[owner];\r\n uint256 auxCasted;\r\n // Cast `aux` with assembly to avoid redundant masking.\r\n assembly {\r\n auxCasted := aux\r\n }\r\n packed = (packed & _BITMASK_AUX_COMPLEMENT) | (auxCasted << _BITPOS_AUX);\r\n _packedAddressData[owner] = packed;\r\n }\r\n\r\n // =============================================================\r\n // IERC165\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns true if this contract implements the interface defined by\r\n * `interfaceId`. See the corresponding\r\n * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)\r\n * to learn more about how these ids are created.\r\n *\r\n * This function call must use less than 30000 gas.\r\n */\r\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\r\n // The interface IDs are constants representing the first 4 bytes\r\n // of the XOR of all function selectors in the interface.\r\n // See: [ERC165](https://eips.ethereum.org/EIPS/eip-165)\r\n // (e.g. `bytes4(i.functionA.selector ^ i.functionB.selector ^ ...)`)\r\n return\r\n interfaceId == 0x01ffc9a7 || // ERC165 interface ID for ERC165.\r\n interfaceId == 0x80ac58cd || // ERC165 interface ID for ERC721.\r\n interfaceId == 0x5b5e139f; // ERC165 interface ID for ERC721Metadata.\r\n }\r\n\r\n // =============================================================\r\n // IERC721Metadata\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the token collection name.\r\n */\r\n function name() public view virtual override returns (string memory) {\r\n return _name;\r\n }\r\n\r\n /**\r\n * @dev Returns the token collection symbol.\r\n */\r\n function symbol() public view virtual override returns (string memory) {\r\n return _symbol;\r\n }\r\n\r\n /**\r\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\r\n */\r\n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\r\n if (!_exists(tokenId)) revert URIQueryForNonexistentToken();\r\n\r\n string memory baseURI = _baseURI();\r\n return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : '';\r\n }\r\n\r\n /**\r\n * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each\r\n * token will be the concatenation of the `baseURI` and the `tokenId`. Empty\r\n * by default, it can be overridden in child contracts.\r\n */\r\n function _baseURI() internal view virtual returns (string memory) {\r\n return '';\r\n }\r\n\r\n // =============================================================\r\n // OWNERSHIPS OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the owner of the `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function ownerOf(uint256 tokenId) public view virtual override returns (address) {\r\n return address(uint160(_packedOwnershipOf(tokenId)));\r\n }\r\n\r\n /**\r\n * @dev Gas spent here starts off proportional to the maximum mint batch size.\r\n * It gradually moves to O(1) as tokens get transferred around over time.\r\n */\r\n function _ownershipOf(uint256 tokenId) internal view virtual returns (TokenOwnership memory) {\r\n return _unpackedOwnership(_packedOwnershipOf(tokenId));\r\n }\r\n\r\n /**\r\n * @dev Returns the unpacked `TokenOwnership` struct at `index`.\r\n */\r\n function _ownershipAt(uint256 index) internal view virtual returns (TokenOwnership memory) {\r\n return _unpackedOwnership(_packedOwnerships[index]);\r\n }\r\n\r\n /**\r\n * @dev Initializes the ownership slot minted at `index` for efficiency purposes.\r\n */\r\n function _initializeOwnershipAt(uint256 index) internal virtual {\r\n if (_packedOwnerships[index] == 0) {\r\n _packedOwnerships[index] = _packedOwnershipOf(index);\r\n }\r\n }\r\n\r\n /**\r\n * Returns the packed ownership data of `tokenId`.\r\n */\r\n function _packedOwnershipOf(uint256 tokenId) private view returns (uint256) {\r\n uint256 curr = tokenId;\r\n\r\n unchecked {\r\n if (_startTokenId() <= curr)\r\n if (curr < _currentIndex) {\r\n uint256 packed = _packedOwnerships[curr];\r\n // If not burned.\r\n if (packed & _BITMASK_BURNED == 0) {\r\n // Invariant:\r\n // There will always be an initialized ownership slot\r\n // (i.e. `ownership.addr != address(0) && ownership.burned == false`)\r\n // before an unintialized ownership slot\r\n // (i.e. `ownership.addr == address(0) && ownership.burned == false`)\r\n // Hence, `curr` will not underflow.\r\n //\r\n // We can directly compare the packed value.\r\n // If the address is zero, packed will be zero.\r\n while (packed == 0) {\r\n packed = _packedOwnerships[--curr];\r\n }\r\n return packed;\r\n }\r\n }\r\n }\r\n revert OwnerQueryForNonexistentToken();\r\n }\r\n\r\n /**\r\n * @dev Returns the unpacked `TokenOwnership` struct from `packed`.\r\n */\r\n function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) {\r\n ownership.addr = address(uint160(packed));\r\n ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP);\r\n ownership.burned = packed & _BITMASK_BURNED != 0;\r\n ownership.extraData = uint24(packed >> _BITPOS_EXTRA_DATA);\r\n }\r\n\r\n /**\r\n * @dev Packs ownership data into a single uint256.\r\n */\r\n function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) {\r\n assembly {\r\n // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.\r\n owner := and(owner, _BITMASK_ADDRESS)\r\n // `owner | (block.timestamp << _BITPOS_START_TIMESTAMP) | flags`.\r\n result := or(owner, or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags))\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the `nextInitialized` flag set if `quantity` equals 1.\r\n */\r\n function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) {\r\n // For branchless setting of the `nextInitialized` flag.\r\n assembly {\r\n // `(quantity == 1) << _BITPOS_NEXT_INITIALIZED`.\r\n result := shl(_BITPOS_NEXT_INITIALIZED, eq(quantity, 1))\r\n }\r\n }\r\n\r\n // =============================================================\r\n // APPROVAL OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\r\n * The approval is cleared when the token is transferred.\r\n *\r\n * Only a single account can be approved at a time, so approving the\r\n * zero address clears previous approvals.\r\n *\r\n * Requirements:\r\n *\r\n * - The caller must own the token or be an approved operator.\r\n * - `tokenId` must exist.\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function approve(address to, uint256 tokenId) public payable virtual override {\r\n address owner = ownerOf(tokenId);\r\n\r\n if (_msgSenderERC721A() != owner)\r\n if (!isApprovedForAll(owner, _msgSenderERC721A())) {\r\n revert ApprovalCallerNotOwnerNorApproved();\r\n }\r\n\r\n _tokenApprovals[tokenId].value = to;\r\n emit Approval(owner, to, tokenId);\r\n }\r\n\r\n /**\r\n * @dev Returns the account approved for `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function getApproved(uint256 tokenId) public view virtual override returns (address) {\r\n if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken();\r\n\r\n return _tokenApprovals[tokenId].value;\r\n }\r\n\r\n /**\r\n * @dev Approve or remove `operator` as an operator for the caller.\r\n * Operators can call {transferFrom} or {safeTransferFrom}\r\n * for any token owned by the caller.\r\n *\r\n * Requirements:\r\n *\r\n * - The `operator` cannot be the caller.\r\n *\r\n * Emits an {ApprovalForAll} event.\r\n */\r\n function setApprovalForAll(address operator, bool approved) public virtual override {\r\n _operatorApprovals[_msgSenderERC721A()][operator] = approved;\r\n emit ApprovalForAll(_msgSenderERC721A(), operator, approved);\r\n }\r\n\r\n /**\r\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\r\n *\r\n * See {setApprovalForAll}.\r\n */\r\n function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {\r\n return _operatorApprovals[owner][operator];\r\n }\r\n\r\n /**\r\n * @dev Returns whether `tokenId` exists.\r\n *\r\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\r\n *\r\n * Tokens start existing when they are minted. See {_mint}.\r\n */\r\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\r\n return\r\n _startTokenId() <= tokenId &&\r\n tokenId < _currentIndex && // If within bounds,\r\n _packedOwnerships[tokenId] & _BITMASK_BURNED == 0; // and not burned.\r\n }\r\n\r\n /**\r\n * @dev Returns whether `msgSender` is equal to `approvedAddress` or `owner`.\r\n */\r\n function _isSenderApprovedOrOwner(\r\n address approvedAddress,\r\n address owner,\r\n address msgSender\r\n ) private pure returns (bool result) {\r\n assembly {\r\n // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.\r\n owner := and(owner, _BITMASK_ADDRESS)\r\n // Mask `msgSender` to the lower 160 bits, in case the upper bits somehow aren't clean.\r\n msgSender := and(msgSender, _BITMASK_ADDRESS)\r\n // `msgSender == owner || msgSender == approvedAddress`.\r\n result := or(eq(msgSender, owner), eq(msgSender, approvedAddress))\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the storage slot and value for the approved address of `tokenId`.\r\n */\r\n function _getApprovedSlotAndAddress(uint256 tokenId)\r\n private\r\n view\r\n returns (uint256 approvedAddressSlot, address approvedAddress)\r\n {\r\n TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId];\r\n // The following is equivalent to `approvedAddress = _tokenApprovals[tokenId].value`.\r\n assembly {\r\n approvedAddressSlot := tokenApproval.slot\r\n approvedAddress := sload(approvedAddressSlot)\r\n }\r\n }\r\n\r\n // =============================================================\r\n // TRANSFER OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Transfers `tokenId` from `from` to `to`.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must be owned by `from`.\r\n * - If the caller is not `from`, it must be approved to move this token\r\n * by either {approve} or {setApprovalForAll}.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId\r\n ) public payable virtual override {\r\n uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);\r\n\r\n if (address(uint160(prevOwnershipPacked)) != from) revert TransferFromIncorrectOwner();\r\n\r\n (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);\r\n\r\n // The nested ifs save around 20+ gas over a compound boolean condition.\r\n if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))\r\n if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();\r\n\r\n if (to == address(0)) revert TransferToZeroAddress();\r\n\r\n _beforeTokenTransfers(from, to, tokenId, 1);\r\n\r\n // Clear approvals from the previous owner.\r\n assembly {\r\n if approvedAddress {\r\n // This is equivalent to `delete _tokenApprovals[tokenId]`.\r\n sstore(approvedAddressSlot, 0)\r\n }\r\n }\r\n\r\n // Underflow of the sender's balance is impossible because we check for\r\n // ownership above and the recipient's balance can't realistically overflow.\r\n // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.\r\n unchecked {\r\n // We can directly increment and decrement the balances.\r\n --_packedAddressData[from]; // Updates: `balance -= 1`.\r\n ++_packedAddressData[to]; // Updates: `balance += 1`.\r\n\r\n // Updates:\r\n // - `address` to the next owner.\r\n // - `startTimestamp` to the timestamp of transfering.\r\n // - `burned` to `false`.\r\n // - `nextInitialized` to `true`.\r\n _packedOwnerships[tokenId] = _packOwnershipData(\r\n to,\r\n _BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked)\r\n );\r\n\r\n // If the next slot may not have been initialized (i.e. `nextInitialized == false`) .\r\n if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {\r\n uint256 nextTokenId = tokenId + 1;\r\n // If the next slot's address is zero and not burned (i.e. packed value is zero).\r\n if (_packedOwnerships[nextTokenId] == 0) {\r\n // If the next slot is within bounds.\r\n if (nextTokenId != _currentIndex) {\r\n // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.\r\n _packedOwnerships[nextTokenId] = prevOwnershipPacked;\r\n }\r\n }\r\n }\r\n }\r\n\r\n emit Transfer(from, to, tokenId);\r\n _afterTokenTransfers(from, to, tokenId, 1);\r\n }\r\n\r\n /**\r\n * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\r\n */\r\n function safeTransferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId\r\n ) public payable virtual override {\r\n safeTransferFrom(from, to, tokenId, '');\r\n }\r\n\r\n /**\r\n * @dev Safely transfers `tokenId` token from `from` to `to`.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must exist and be owned by `from`.\r\n * - If the caller is not `from`, it must be approved to move this token\r\n * by either {approve} or {setApprovalForAll}.\r\n * - If `to` refers to a smart contract, it must implement\r\n * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function safeTransferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId,\r\n bytes memory _data\r\n ) public payable virtual override {\r\n transferFrom(from, to, tokenId);\r\n if (to.code.length != 0)\r\n if (!_checkContractOnERC721Received(from, to, tokenId, _data)) {\r\n revert TransferToNonERC721ReceiverImplementer();\r\n }\r\n }\r\n\r\n /**\r\n * @dev Hook that is called before a set of serially-ordered token IDs\r\n * are about to be transferred. This includes minting.\r\n * And also called before burning one token.\r\n *\r\n * `startTokenId` - the first token ID to be transferred.\r\n * `quantity` - the amount to be transferred.\r\n *\r\n * Calling conditions:\r\n *\r\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\r\n * transferred to `to`.\r\n * - When `from` is zero, `tokenId` will be minted for `to`.\r\n * - When `to` is zero, `tokenId` will be burned by `from`.\r\n * - `from` and `to` are never both zero.\r\n */\r\n function _beforeTokenTransfers(\r\n address from,\r\n address to,\r\n uint256 startTokenId,\r\n uint256 quantity\r\n ) internal virtual {}\r\n\r\n /**\r\n * @dev Hook that is called after a set of serially-ordered token IDs\r\n * have been transferred. This includes minting.\r\n * And also called after one token has been burned.\r\n *\r\n * `startTokenId` - the first token ID to be transferred.\r\n * `quantity` - the amount to be transferred.\r\n *\r\n * Calling conditions:\r\n *\r\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been\r\n * transferred to `to`.\r\n * - When `from` is zero, `tokenId` has been minted for `to`.\r\n * - When `to` is zero, `tokenId` has been burned by `from`.\r\n * - `from` and `to` are never both zero.\r\n */\r\n function _afterTokenTransfers(\r\n address from,\r\n address to,\r\n uint256 startTokenId,\r\n uint256 quantity\r\n ) internal virtual {}\r\n\r\n /**\r\n * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target contract.\r\n *\r\n * `from` - Previous owner of the given token ID.\r\n * `to` - Target address that will receive the token.\r\n * `tokenId` - Token ID to be transferred.\r\n * `_data` - Optional data to send along with the call.\r\n *\r\n * Returns whether the call correctly returned the expected magic value.\r\n */\r\n function _checkContractOnERC721Received(\r\n address from,\r\n address to,\r\n uint256 tokenId,\r\n bytes memory _data\r\n ) private returns (bool) {\r\n try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns (\r\n bytes4 retval\r\n ) {\r\n return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector;\r\n } catch (bytes memory reason) {\r\n if (reason.length == 0) {\r\n revert TransferToNonERC721ReceiverImplementer();\r\n } else {\r\n assembly {\r\n revert(add(32, reason), mload(reason))\r\n }\r\n }\r\n }\r\n }\r\n\r\n // =============================================================\r\n // MINT OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Mints `quantity` tokens and transfers them to `to`.\r\n *\r\n * Requirements:\r\n *\r\n * - `to` cannot be the zero address.\r\n * - `quantity` must be greater than 0.\r\n *\r\n * Emits a {Transfer} event for each mint.\r\n */\r\n function _mint(address to, uint256 quantity) internal virtual {\r\n uint256 startTokenId = _currentIndex;\r\n if (quantity == 0) revert MintZeroQuantity();\r\n\r\n _beforeTokenTransfers(address(0), to, startTokenId, quantity);\r\n\r\n // Overflows are incredibly unrealistic.\r\n // `balance` and `numberMinted` have a maximum limit of 2**64.\r\n // `tokenId` has a maximum limit of 2**256.\r\n unchecked {\r\n // Updates:\r\n // - `balance += quantity`.\r\n // - `numberMinted += quantity`.\r\n //\r\n // We can directly add to the `balance` and `numberMinted`.\r\n _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);\r\n\r\n // Updates:\r\n // - `address` to the owner.\r\n // - `startTimestamp` to the timestamp of minting.\r\n // - `burned` to `false`.\r\n // - `nextInitialized` to `quantity == 1`.\r\n _packedOwnerships[startTokenId] = _packOwnershipData(\r\n to,\r\n _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)\r\n );\r\n\r\n uint256 toMasked;\r\n uint256 end = startTokenId + quantity;\r\n\r\n // Use assembly to loop and emit the `Transfer` event for gas savings.\r\n // The duplicated `log4` removes an extra check and reduces stack juggling.\r\n // The assembly, together with the surrounding Solidity code, have been\r\n // delicately arranged to nudge the compiler into producing optimized opcodes.\r\n assembly {\r\n // Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.\r\n toMasked := and(to, _BITMASK_ADDRESS)\r\n // Emit the `Transfer` event.\r\n log4(\r\n 0, // Start of data (0, since no data).\r\n 0, // End of data (0, since no data).\r\n _TRANSFER_EVENT_SIGNATURE, // Signature.\r\n 0, // `address(0)`.\r\n toMasked, // `to`.\r\n startTokenId // `tokenId`.\r\n )\r\n\r\n // The `iszero(eq(,))` check ensures that large values of `quantity`\r\n // that overflows uint256 will make the loop run out of gas.\r\n // The compiler will optimize the `iszero` away for performance.\r\n for {\r\n let tokenId := add(startTokenId, 1)\r\n } iszero(eq(tokenId, end)) {\r\n tokenId := add(tokenId, 1)\r\n } {\r\n // Emit the `Transfer` event. Similar to above.\r\n log4(0, 0, _TRANSFER_EVENT_SIGNATURE, 0, toMasked, tokenId)\r\n }\r\n }\r\n if (toMasked == 0) revert MintToZeroAddress();\r\n\r\n _currentIndex = end;\r\n }\r\n _afterTokenTransfers(address(0), to, startTokenId, quantity);\r\n }\r\n\r\n /**\r\n * @dev Mints `quantity` tokens and transfers them to `to`.\r\n *\r\n * This function is intended for efficient minting only during contract creation.\r\n *\r\n * It emits only one {ConsecutiveTransfer} as defined in\r\n * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309),\r\n * instead of a sequence of {Transfer} event(s).\r\n *\r\n * Calling this function outside of contract creation WILL make your contract\r\n * non-compliant with the ERC721 standard.\r\n * For full ERC721 compliance, substituting ERC721 {Transfer} event(s) with the ERC2309\r\n * {ConsecutiveTransfer} event is only permissible during contract creation.\r\n *\r\n * Requirements:\r\n *\r\n * - `to` cannot be the zero address.\r\n * - `quantity` must be greater than 0.\r\n *\r\n * Emits a {ConsecutiveTransfer} event.\r\n */\r\n function _mintERC2309(address to, uint256 quantity) internal virtual {\r\n uint256 startTokenId = _currentIndex;\r\n if (to == address(0)) revert MintToZeroAddress();\r\n if (quantity == 0) revert MintZeroQuantity();\r\n if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) revert MintERC2309QuantityExceedsLimit();\r\n\r\n _beforeTokenTransfers(address(0), to, startTokenId, quantity);\r\n\r\n // Overflows are unrealistic due to the above check for `quantity` to be below the limit.\r\n unchecked {\r\n // Updates:\r\n // - `balance += quantity`.\r\n // - `numberMinted += quantity`.\r\n //\r\n // We can directly add to the `balance` and `numberMinted`.\r\n _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);\r\n\r\n // Updates:\r\n // - `address` to the owner.\r\n // - `startTimestamp` to the timestamp of minting.\r\n // - `burned` to `false`.\r\n // - `nextInitialized` to `quantity == 1`.\r\n _packedOwnerships[startTokenId] = _packOwnershipData(\r\n to,\r\n _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)\r\n );\r\n\r\n emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to);\r\n\r\n _currentIndex = startTokenId + quantity;\r\n }\r\n _afterTokenTransfers(address(0), to, startTokenId, quantity);\r\n }\r\n\r\n /**\r\n * @dev Safely mints `quantity` tokens and transfers them to `to`.\r\n *\r\n * Requirements:\r\n *\r\n * - If `to` refers to a smart contract, it must implement\r\n * {IERC721Receiver-onERC721Received}, which is called for each safe transfer.\r\n * - `quantity` must be greater than 0.\r\n *\r\n * See {_mint}.\r\n *\r\n * Emits a {Transfer} event for each mint.\r\n */\r\n function _safeMint(\r\n address to,\r\n uint256 quantity,\r\n bytes memory _data\r\n ) internal virtual {\r\n _mint(to, quantity);\r\n\r\n unchecked {\r\n if (to.code.length != 0) {\r\n uint256 end = _currentIndex;\r\n uint256 index = end - quantity;\r\n do {\r\n if (!_checkContractOnERC721Received(address(0), to, index++, _data)) {\r\n revert TransferToNonERC721ReceiverImplementer();\r\n }\r\n } while (index < end);\r\n // Reentrancy protection.\r\n if (_currentIndex != end) revert();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @dev Equivalent to `_safeMint(to, quantity, '')`.\r\n */\r\n function _safeMint(address to, uint256 quantity) internal virtual {\r\n _safeMint(to, quantity, '');\r\n }\r\n\r\n // =============================================================\r\n // BURN OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Equivalent to `_burn(tokenId, false)`.\r\n */\r\n function _burn(uint256 tokenId) internal virtual {\r\n _burn(tokenId, false);\r\n }\r\n\r\n /**\r\n * @dev Destroys `tokenId`.\r\n * The approval is cleared when the token is burned.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _burn(uint256 tokenId, bool approvalCheck) internal virtual {\r\n uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);\r\n\r\n address from = address(uint160(prevOwnershipPacked));\r\n\r\n (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);\r\n\r\n if (approvalCheck) {\r\n // The nested ifs save around 20+ gas over a compound boolean condition.\r\n if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))\r\n if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();\r\n }\r\n\r\n _beforeTokenTransfers(from, address(0), tokenId, 1);\r\n\r\n // Clear approvals from the previous owner.\r\n assembly {\r\n if approvedAddress {\r\n // This is equivalent to `delete _tokenApprovals[tokenId]`.\r\n sstore(approvedAddressSlot, 0)\r\n }\r\n }\r\n\r\n // Underflow of the sender's balance is impossible because we check for\r\n // ownership above and the recipient's balance can't realistically overflow.\r\n // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.\r\n unchecked {\r\n // Updates:\r\n // - `balance -= 1`.\r\n // - `numberBurned += 1`.\r\n //\r\n // We can directly decrement the balance, and increment the number burned.\r\n // This is equivalent to `packed -= 1; packed += 1 << _BITPOS_NUMBER_BURNED;`.\r\n _packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1;\r\n\r\n // Updates:\r\n // - `address` to the last owner.\r\n // - `startTimestamp` to the timestamp of burning.\r\n // - `burned` to `true`.\r\n // - `nextInitialized` to `true`.\r\n _packedOwnerships[tokenId] = _packOwnershipData(\r\n from,\r\n (_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked)\r\n );\r\n\r\n // If the next slot may not have been initialized (i.e. `nextInitialized == false`) .\r\n if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {\r\n uint256 nextTokenId = tokenId + 1;\r\n // If the next slot's address is zero and not burned (i.e. packed value is zero).\r\n if (_packedOwnerships[nextTokenId] == 0) {\r\n // If the next slot is within bounds.\r\n if (nextTokenId != _currentIndex) {\r\n // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.\r\n _packedOwnerships[nextTokenId] = prevOwnershipPacked;\r\n }\r\n }\r\n }\r\n }\r\n\r\n emit Transfer(from, address(0), tokenId);\r\n _afterTokenTransfers(from, address(0), tokenId, 1);\r\n\r\n // Overflow not possible, as _burnCounter cannot be exceed _currentIndex times.\r\n unchecked {\r\n _burnCounter++;\r\n }\r\n }\r\n\r\n // =============================================================\r\n // EXTRA DATA OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Directly sets the extra data for the ownership data `index`.\r\n */\r\n function _setExtraDataAt(uint256 index, uint24 extraData) internal virtual {\r\n uint256 packed = _packedOwnerships[index];\r\n if (packed == 0) revert OwnershipNotInitializedForExtraData();\r\n uint256 extraDataCasted;\r\n // Cast `extraData` with assembly to avoid redundant masking.\r\n assembly {\r\n extraDataCasted := extraData\r\n }\r\n packed = (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << _BITPOS_EXTRA_DATA);\r\n _packedOwnerships[index] = packed;\r\n }\r\n\r\n /**\r\n * @dev Called during each token transfer to set the 24bit `extraData` field.\r\n * Intended to be overridden by the cosumer contract.\r\n *\r\n * `previousExtraData` - the value of `extraData` before transfer.\r\n *\r\n * Calling conditions:\r\n *\r\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\r\n * transferred to `to`.\r\n * - When `from` is zero, `tokenId` will be minted for `to`.\r\n * - When `to` is zero, `tokenId` will be burned by `from`.\r\n * - `from` and `to` are never both zero.\r\n */\r\n function _extraData(\r\n address from,\r\n address to,\r\n uint24 previousExtraData\r\n ) internal view virtual returns (uint24) {}\r\n\r\n /**\r\n * @dev Returns the next extra data for the packed ownership data.\r\n * The returned result is shifted into position.\r\n */\r\n function _nextExtraData(\r\n address from,\r\n address to,\r\n uint256 prevOwnershipPacked\r\n ) private view returns (uint256) {\r\n uint24 extraData = uint24(prevOwnershipPacked >> _BITPOS_EXTRA_DATA);\r\n return uint256(_extraData(from, to, extraData)) << _BITPOS_EXTRA_DATA;\r\n }\r\n\r\n // =============================================================\r\n // OTHER OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the message sender (defaults to `msg.sender`).\r\n *\r\n * If you are writing GSN compatible contracts, you need to override this function.\r\n */\r\n function _msgSenderERC721A() internal view virtual returns (address) {\r\n return msg.sender;\r\n }\r\n\r\n /**\r\n * @dev Converts a uint256 to its ASCII string decimal representation.\r\n */\r\n function _toString(uint256 value) internal pure virtual returns (string memory str) {\r\n assembly {\r\n // The maximum value of a uint256 contains 78 digits (1 byte per digit), but\r\n // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.\r\n // We will need 1 word for the trailing zeros padding, 1 word for the length,\r\n // and 3 words for a maximum of 78 digits. Total: 5 * 0x20 = 0xa0.\r\n let m := add(mload(0x40), 0xa0)\r\n // Update the free memory pointer to allocate.\r\n mstore(0x40, m)\r\n // Assign the `str` to the end.\r\n str := sub(m, 0x20)\r\n // Zeroize the slot after the string.\r\n mstore(str, 0)\r\n\r\n // Cache the end of the memory to calculate the length later.\r\n let end := str\r\n\r\n // We write the string from rightmost digit to leftmost digit.\r\n // The following is essentially a do-while loop that also handles the zero case.\r\n // prettier-ignore\r\n for { let temp := value } 1 {} {\r\n str := sub(str, 1)\r\n // Write the character to the pointer.\r\n // The ASCII index of the '0' character is 48.\r\n mstore8(str, add(48, mod(temp, 10)))\r\n // Keep dividing `temp` until zero.\r\n temp := div(temp, 10)\r\n // prettier-ignore\r\n if iszero(temp) { break }\r\n }\r\n\r\n let length := sub(end, str)\r\n // Move the pointer 32 bytes leftwards to make room for the length.\r\n str := sub(str, 0x20)\r\n // Store the length.\r\n mstore(str, length)\r\n }\r\n }\r\n}" }, "src/contracts/whitelist/ASingleAllowlistMerkle.sol": { "content": "// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.14;\r\n\r\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\r\nimport \"@openzeppelin/contracts/utils/cryptography/MerkleProof.sol\";\r\n\r\nimport \"./WhitelistErrors.sol\";\r\n\r\n/// @title Merkle Proof based whitelist Base Abstract Contract\r\n/// @author karmabadger\r\n/// @notice Uses an address and an amount\r\n/// @dev inherit this contract to use the whitelist functionality\r\nabstract contract ASingleAllowlistMerkle is Ownable {\r\n bytes32 public allowlistMerkleRoot; // root of the merkle tree\r\n\r\n /// @notice constructor\r\n /// @param _merkleRoot the root of the merkle tree\r\n constructor(bytes32 _merkleRoot) {\r\n allowlistMerkleRoot = _merkleRoot;\r\n }\r\n\r\n /// @notice only for whitelisted accounts\r\n /// @dev need a proof to prove that the account is whitelisted with an amount whitelisted. also needs enough allowed amount left to mint\r\n modifier onlyAllowlisted(bytes32[] calldata _merkleProof) {\r\n if (!_isAllowlisted(msg.sender, _merkleProof)) revert InvalidMerkleProof();\r\n _;\r\n }\r\n\r\n /* whitelist admin functions */\r\n /// @notice set the merkle root\r\n /// @dev If the merkle root is changed, the whitelist is reset\r\n /// @param _merkleRoot the root of the merkle tree\r\n function setAllowlistMerkleRoot(bytes32 _merkleRoot) external onlyOwner {\r\n allowlistMerkleRoot = _merkleRoot;\r\n }\r\n\r\n /* whitelist user functions */\r\n /// @notice Check if an account is whitelisted using a merkle proof\r\n /// @dev verifies the merkle proof\r\n /// @param _account the account to check if it is whitelisted\r\n /// @param _merkleProof the merkle proof of for the whitelist\r\n /// @return true if the account is whitelisted\r\n function _isAllowlisted(address _account, bytes32[] calldata _merkleProof)\r\n internal\r\n view\r\n returns (bool)\r\n {\r\n return\r\n MerkleProof.verify(\r\n _merkleProof,\r\n allowlistMerkleRoot,\r\n keccak256(abi.encodePacked(_account))\r\n );\r\n }\r\n\r\n /// @notice Check if an account is whitelisted using a merkle proof\r\n /// @dev verifies the merkle proof\r\n /// @param _account the account to check if it is whitelisted\r\n /// @param _merkleProof the merkle proof of for the whitelist\r\n /// @return true if the account is whitelisted\r\n function isAllowlisted(address _account, bytes32[] calldata _merkleProof)\r\n external\r\n view\r\n returns (bool)\r\n {\r\n return _isAllowlisted(_account, _merkleProof);\r\n }\r\n}\r\n" }, "src/contracts/whitelist/AMultiFounderslistMerkle.sol": { "content": "// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.14;\r\n\r\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\r\nimport \"@openzeppelin/contracts/utils/cryptography/MerkleProof.sol\";\r\n\r\nimport \"./WhitelistErrors.sol\";\r\n\r\n/// @title Merkle Proof based whitelist Base Abstract Contract\r\n/// @author karmabadger\r\n/// @notice Uses an address and an amount\r\n/// @dev inherit this contract to use the whitelist functionality\r\nabstract contract AMultiFounderslistMerkle is Ownable {\r\n bytes32 public founderslistMerkleRoot; // root of the merkle tree\r\n\r\n // mapping(address => uint32) public whitelistMintMintedAmounts; // Whitelist minted amounts for each account.\r\n\r\n /// @notice constructor\r\n /// @param _merkleRoot the root of the merkle tree\r\n constructor(bytes32 _merkleRoot) {\r\n founderslistMerkleRoot = _merkleRoot;\r\n }\r\n\r\n /// @notice only for whitelisted accounts\r\n /// @dev need a proof to prove that the account is whitelisted with an amount whitelisted. also needs enough allowed amount left to mint\r\n modifier onlyFounderslisted(bytes32[] calldata _merkleProof, uint16 _entitlementAmount) {\r\n bytes32 leaf = keccak256(abi.encodePacked(msg.sender, _entitlementAmount));\r\n if (!MerkleProof.verify(_merkleProof, founderslistMerkleRoot, leaf))\r\n revert InvalidMerkleProof();\r\n _;\r\n }\r\n\r\n /* whitelist admin functions */\r\n /// @notice set the merkle root\r\n /// @dev If the merkle root is changed, the whitelist is reset\r\n /// @param _merkleRoot the root of the merkle tree\r\n function setFounderslistMerkleRoot(bytes32 _merkleRoot) external onlyOwner {\r\n founderslistMerkleRoot = _merkleRoot;\r\n }\r\n\r\n /* whitelist user functions */\r\n\r\n /// @notice Check if an account is whitelisted using a merkle proof\r\n /// @dev verifies the merkle proof\r\n /// @param _account the account to check if it is whitelisted\r\n /// @param _entitlementAmount the amount of the account to check if it is whitelisted\r\n /// @param _merkleProof the merkle proof of for the whitelist\r\n /// @return true if the account is whitelisted\r\n function isFounderslisted(\r\n address _account,\r\n uint16 _entitlementAmount,\r\n bytes32[] calldata _merkleProof\r\n ) external view returns (bool) {\r\n bytes32 leaf = keccak256(abi.encodePacked(_account, _entitlementAmount));\r\n return MerkleProof.verify(_merkleProof, founderslistMerkleRoot, leaf);\r\n }\r\n}\r\n" }, "lib/openzeppelin-contracts/contracts/utils/Context.sol": { "content": "// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev Provides information about the current execution context, including the\r\n * sender of the transaction and its data. While these are generally available\r\n * via msg.sender and msg.data, they should not be accessed in such a direct\r\n * manner, since when dealing with meta-transactions the account sending and\r\n * paying for execution may not be the actual sender (as far as an application\r\n * is concerned).\r\n *\r\n * This contract is only required for intermediate, library-like contracts.\r\n */\r\nabstract contract Context {\r\n function _msgSender() internal view virtual returns (address) {\r\n return msg.sender;\r\n }\r\n\r\n function _msgData() internal view virtual returns (bytes calldata) {\r\n return msg.data;\r\n }\r\n}\r\n" }, "src/contracts/nft/IERC721A.sol": { "content": "// SPDX-License-Identifier: MIT\r\n// ERC721A Contracts v4.2.3\r\n// Creator: Chiru Labs\r\n\r\npragma solidity ^0.8.4;\r\n\r\n/**\r\n * @dev Interface of ERC721A.\r\n */\r\ninterface IERC721A {\r\n /**\r\n * The caller must own the token or be an approved operator.\r\n */\r\n error ApprovalCallerNotOwnerNorApproved();\r\n\r\n /**\r\n * The token does not exist.\r\n */\r\n error ApprovalQueryForNonexistentToken();\r\n\r\n /**\r\n * Cannot query the balance for the zero address.\r\n */\r\n error BalanceQueryForZeroAddress();\r\n\r\n /**\r\n * Cannot mint to the zero address.\r\n */\r\n error MintToZeroAddress();\r\n\r\n /**\r\n * The quantity of tokens minted must be more than zero.\r\n */\r\n error MintZeroQuantity();\r\n\r\n /**\r\n * The token does not exist.\r\n */\r\n error OwnerQueryForNonexistentToken();\r\n\r\n /**\r\n * The caller must own the token or be an approved operator.\r\n */\r\n error TransferCallerNotOwnerNorApproved();\r\n\r\n /**\r\n * The token must be owned by `from`.\r\n */\r\n error TransferFromIncorrectOwner();\r\n\r\n /**\r\n * Cannot safely transfer to a contract that does not implement the\r\n * ERC721Receiver interface.\r\n */\r\n error TransferToNonERC721ReceiverImplementer();\r\n\r\n /**\r\n * Cannot transfer to the zero address.\r\n */\r\n error TransferToZeroAddress();\r\n\r\n /**\r\n * The token does not exist.\r\n */\r\n error URIQueryForNonexistentToken();\r\n\r\n /**\r\n * The `quantity` minted with ERC2309 exceeds the safety limit.\r\n */\r\n error MintERC2309QuantityExceedsLimit();\r\n\r\n /**\r\n * The `extraData` cannot be set on an unintialized ownership slot.\r\n */\r\n error OwnershipNotInitializedForExtraData();\r\n\r\n // =============================================================\r\n // STRUCTS\r\n // =============================================================\r\n\r\n struct TokenOwnership {\r\n // The address of the owner.\r\n address addr;\r\n // Stores the start time of ownership with minimal overhead for tokenomics.\r\n uint64 startTimestamp;\r\n // Whether the token has been burned.\r\n bool burned;\r\n // Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.\r\n uint24 extraData;\r\n }\r\n\r\n // =============================================================\r\n // TOKEN COUNTERS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the total number of tokens in existence.\r\n * Burned tokens will reduce the count.\r\n * To get the total number of tokens minted, please see {_totalMinted}.\r\n */\r\n function totalSupply() external view returns (uint256);\r\n\r\n // =============================================================\r\n // IERC165\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns true if this contract implements the interface defined by\r\n * `interfaceId`. See the corresponding\r\n * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)\r\n * to learn more about how these ids are created.\r\n *\r\n * This function call must use less than 30000 gas.\r\n */\r\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\r\n\r\n // =============================================================\r\n // IERC721\r\n // =============================================================\r\n\r\n /**\r\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\r\n */\r\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\r\n\r\n /**\r\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\r\n */\r\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\r\n\r\n /**\r\n * @dev Emitted when `owner` enables or disables\r\n * (`approved`) `operator` to manage all of its assets.\r\n */\r\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\r\n\r\n /**\r\n * @dev Returns the number of tokens in `owner`'s account.\r\n */\r\n function balanceOf(address owner) external view returns (uint256 balance);\r\n\r\n /**\r\n * @dev Returns the owner of the `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function ownerOf(uint256 tokenId) external view returns (address owner);\r\n\r\n /**\r\n * @dev Safely transfers `tokenId` token from `from` to `to`,\r\n * checking first that contract recipients are aware of the ERC721 protocol\r\n * to prevent tokens from being forever locked.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must exist and be owned by `from`.\r\n * - If the caller is not `from`, it must be have been allowed to move\r\n * this token by either {approve} or {setApprovalForAll}.\r\n * - If `to` refers to a smart contract, it must implement\r\n * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function safeTransferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId,\r\n bytes calldata data\r\n ) external payable;\r\n\r\n /**\r\n * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\r\n */\r\n function safeTransferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId\r\n ) external payable;\r\n\r\n /**\r\n * @dev Transfers `tokenId` from `from` to `to`.\r\n *\r\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom}\r\n * whenever possible.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must be owned by `from`.\r\n * - If the caller is not `from`, it must be approved to move this token\r\n * by either {approve} or {setApprovalForAll}.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId\r\n ) external payable;\r\n\r\n /**\r\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\r\n * The approval is cleared when the token is transferred.\r\n *\r\n * Only a single account can be approved at a time, so approving the\r\n * zero address clears previous approvals.\r\n *\r\n * Requirements:\r\n *\r\n * - The caller must own the token or be an approved operator.\r\n * - `tokenId` must exist.\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function approve(address to, uint256 tokenId) external payable;\r\n\r\n /**\r\n * @dev Approve or remove `operator` as an operator for the caller.\r\n * Operators can call {transferFrom} or {safeTransferFrom}\r\n * for any token owned by the caller.\r\n *\r\n * Requirements:\r\n *\r\n * - The `operator` cannot be the caller.\r\n *\r\n * Emits an {ApprovalForAll} event.\r\n */\r\n function setApprovalForAll(address operator, bool _approved) external;\r\n\r\n /**\r\n * @dev Returns the account approved for `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function getApproved(uint256 tokenId) external view returns (address operator);\r\n\r\n /**\r\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\r\n *\r\n * See {setApprovalForAll}.\r\n */\r\n function isApprovedForAll(address owner, address operator) external view returns (bool);\r\n\r\n // =============================================================\r\n // IERC721Metadata\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the token collection name.\r\n */\r\n function name() external view returns (string memory);\r\n\r\n /**\r\n * @dev Returns the token collection symbol.\r\n */\r\n function symbol() external view returns (string memory);\r\n\r\n /**\r\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\r\n */\r\n function tokenURI(uint256 tokenId) external view returns (string memory);\r\n\r\n // =============================================================\r\n // IERC2309\r\n // =============================================================\r\n\r\n /**\r\n * @dev Emitted when tokens in `fromTokenId` to `toTokenId`\r\n * (inclusive) is transferred from `from` to `to`, as defined in the\r\n * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.\r\n *\r\n * See {_mintERC2309} for more details.\r\n */\r\n event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);\r\n}" }, "lib/openzeppelin-contracts/contracts/utils/cryptography/MerkleProof.sol": { "content": "// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/MerkleProof.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev These functions deal with verification of Merkle Trees proofs.\r\n *\r\n * The proofs can be generated using the JavaScript library\r\n * https://github.com/miguelmota/merkletreejs[merkletreejs].\r\n * Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.\r\n *\r\n * See `test/utils/cryptography/MerkleProof.test.js` for some examples.\r\n *\r\n * WARNING: You should avoid using leaf values that are 64 bytes long prior to\r\n * hashing, or use a hash function other than keccak256 for hashing leaves.\r\n * This is because the concatenation of a sorted pair of internal nodes in\r\n * the merkle tree could be reinterpreted as a leaf value.\r\n */\r\nlibrary MerkleProof {\r\n /**\r\n * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree\r\n * defined by `root`. For this, a `proof` must be provided, containing\r\n * sibling hashes on the branch from the leaf to the root of the tree. Each\r\n * pair of leaves and each pair of pre-images are assumed to be sorted.\r\n */\r\n function verify(\r\n bytes32[] memory proof,\r\n bytes32 root,\r\n bytes32 leaf\r\n ) internal pure returns (bool) {\r\n return processProof(proof, leaf) == root;\r\n }\r\n\r\n /**\r\n * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up\r\n * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt\r\n * hash matches the root of the tree. When processing the proof, the pairs\r\n * of leafs & pre-images are assumed to be sorted.\r\n *\r\n * _Available since v4.4._\r\n */\r\n function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {\r\n bytes32 computedHash = leaf;\r\n for (uint256 i = 0; i < proof.length; i++) {\r\n bytes32 proofElement = proof[i];\r\n if (computedHash <= proofElement) {\r\n // Hash(current computed hash + current element of the proof)\r\n computedHash = _efficientHash(computedHash, proofElement);\r\n } else {\r\n // Hash(current element of the proof + current computed hash)\r\n computedHash = _efficientHash(proofElement, computedHash);\r\n }\r\n }\r\n return computedHash;\r\n }\r\n\r\n function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {\r\n assembly {\r\n mstore(0x00, a)\r\n mstore(0x20, b)\r\n value := keccak256(0x00, 0x40)\r\n }\r\n }\r\n}\r\n" }, "src/contracts/whitelist/WhitelistErrors.sol": { "content": "// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.14;\r\n\r\nerror InvalidMerkleProof();\r\nerror WhitelistAlreadyMinted();\r\n" } }, "settings": { "remappings": [ "@cheatcodes/=src/cheatcodes/", "@contracts/=src/contracts/", "@openzeppelin/=lib/openzeppelin-contracts/", "@test/=src/tests/", "ds-note/=lib/ds-warp/lib/ds-note/src/", "ds-test/=lib/ds-test/src/", "ds-warp/=lib/ds-warp/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/" ], "optimizer": { "enabled": false, "runs": 200 }, "metadata": { "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "libraries": {} } }