File size: 129,425 Bytes
f998fcd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
{
"language": "Solidity",
"sources": {
"/app/contracts/Indelible.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\n\nimport \"erc721a/contracts/ERC721A.sol\";\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/utils/cryptography/MerkleProof.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"solady/src/utils/LibPRNG.sol\";\nimport \"solady/src/utils/Base64.sol\";\nimport {DefaultOperatorFilterer} from \"./DefaultOperatorFilterer.sol\";\nimport \"./SSTORE2.sol\";\nimport \"./DynamicBuffer.sol\";\nimport \"./HelperLib.sol\";\n\ncontract Indelible is ERC721A, DefaultOperatorFilterer, ReentrancyGuard, Ownable {\n using HelperLib for uint;\n using DynamicBuffer for bytes;\n using LibPRNG for *;\n \n struct LinkedTraitDTO {\n uint[] traitA;\n uint[] traitB;\n }\n \n struct TraitDTO {\n string name;\n string mimetype;\n bytes data;\n bool hide;\n bool useExistingData;\n uint existingDataIndex;\n }\n \n struct Trait {\n string name;\n string mimetype;\n bool hide;\n }\n \n struct ContractData {\n string name;\n string description;\n string image;\n string banner;\n string website;\n uint royalties;\n string royaltiesRecipient;\n }\n \n struct WithdrawRecipient {\n string name;\n string imageUrl;\n address recipientAddress;\n uint percentage;\n }\n\n mapping(uint => address[]) private _traitDataPointers;\n mapping(uint => mapping(uint => Trait)) private _traitDetails;\n mapping(uint => bool) private _renderTokenOffChain;\n mapping(uint => mapping(uint => uint[])) private _linkedTraits;\n \n uint private constant DEVELOPER_FEE = 250; // of 10,000 = 2.5%\n uint private constant MAX_BATCH_MINT = 20;\n\n uint[] private primeNumbers = [\n 489283222294688268987820540542047890674696745383853025932409,\n 435971530141217434414644657864363626485043834932240354294471,\n 931147417701026196725981216508189527323460133287836248716671,\n 404644724038849848148120945109420144471824163937039418139293,\n 263743197985470588204349265269345001644610514897601719492623,\n 135419986466399101724740108903015610477591324758987986294397\n ];\n uint[][6] private tiers;\n string[] private layerNames = [unicode\"Accessory\", unicode\"Hands\", unicode\"Eyes\", unicode\"Mouth\", unicode\"Skin\", unicode\"Background\"];\n bool private shouldWrapSVG = true;\n string private backgroundColor = \"transparent\";\n uint private randomSeed;\n bytes32 private merkleRoot = 0;\n string private networkId = \"1\";\n\n bool public isContractSealed;\n uint public maxSupply = 4000;\n uint public maxPerAddress = 2;\n uint public publicMintPrice = 0.0035 ether;\n string public baseURI;\n bool public isPublicMintActive;\n uint public allowListPrice = 0 ether;\n uint public maxPerAllowList = 0;\n bool public isAllowListActive;\n\n ContractData public contractData = ContractData(unicode\"Frog Central\", unicode\"Frog Central - the center for all the enthusiasts who were wishing for generational wealth in the Crypto space, but ended up losing their wages, family, frens and money. We are here to change that. The community frog army that will be built will solve all those problems and sweeps your Ls away. Join the legion, join the army, be a part of the gang and be a member of the Frog Central. Completed tools ready-to-use to get the airdrops: arbi, zk, op. Bot for the giveaways and many more. Together we take over the bear market.\", \"https://indeliblelabs-prod.s3.us-east-2.amazonaws.com/profile/49273eab-7924-4550-8a2d-2998f2d5eeae\", \"https://indeliblelabs-prod.s3.us-east-2.amazonaws.com/banner/49273eab-7924-4550-8a2d-2998f2d5eeae\", \"\", 600, \"0x37d245b218FfD8d546B5d16CC1f95442F70aC6Ec\");\n WithdrawRecipient[] public withdrawRecipients;\n\n constructor() ERC721A(unicode\"Frog Central\", unicode\"FrogCentral\") {\n tiers[0] = [3,3,3,3,3,3,3,3979];\n tiers[1] = [1,1,1,1,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,42,42,42,42,42,42,42,42,42,45,50,50,50,50,50,50,50,55];\n tiers[2] = [2,2,2,2,2,2,2,2,2,2,2,3,3,3,5,5,5,5,5,5,19,19,26,44,45,45,45,46,50,55,55,55,55,70,71,75,77,80,83,88,98,99,109,109,112,112,117,119,122,126,127,140,142,150,158,176,180,190,201,249];\n tiers[3] = [2,11,11,11,11,11,11,77,80,85,111,129,143,170,174,189,200,202,222,248,299,301,350,402,550];\n tiers[4] = [50,100,150,300,300,400,400,400,400,450,525,525];\n tiers[5] = [50,100,300,550,600,700,800,900];\n \n randomSeed = uint(\n keccak256(\n abi.encodePacked(\n tx.gasprice,\n block.number,\n block.timestamp,\n block.difficulty,\n blockhash(block.number - 1),\n msg.sender\n )\n )\n );\n }\n\n modifier whenMintActive() {\n require(isMintActive(), \"Minting is not active\");\n _;\n }\n\n modifier whenUnsealed() {\n require(!isContractSealed, \"Contract is sealed\");\n _;\n }\n\n receive() external payable {\n require(isPublicMintActive, \"Public minting is not active\");\n handleMint(msg.value / publicMintPrice, msg.sender);\n }\n\n function rarityGen(uint randinput, uint rarityTier)\n internal\n view\n returns (uint)\n {\n uint currentLowerBound = 0;\n for (uint i = 0; i < tiers[rarityTier].length; i++) {\n uint thisPercentage = tiers[rarityTier][i];\n if (\n randinput >= currentLowerBound &&\n randinput < currentLowerBound + thisPercentage\n ) return i;\n currentLowerBound = currentLowerBound + thisPercentage;\n }\n\n revert();\n }\n\n function getTokenDataId(uint tokenId) internal view returns (uint) {\n uint[] memory indices = new uint[](maxSupply);\n\n unchecked {\n for (uint i; i < maxSupply; i += 1) {\n indices[i] = i;\n }\n }\n\n LibPRNG.PRNG memory prng;\n prng.seed(randomSeed);\n prng.shuffle(indices);\n\n return indices[tokenId];\n }\n\n function tokenIdToHash(\n uint tokenId\n ) public view returns (string memory) {\n require(_exists(tokenId), \"Invalid token\");\n bytes memory hashBytes = DynamicBuffer.allocate(tiers.length * 4);\n uint tokenDataId = getTokenDataId(tokenId);\n\n uint[] memory hash = new uint[](tiers.length);\n bool[] memory modifiedLayers = new bool[](tiers.length);\n uint traitSeed = randomSeed % maxSupply;\n\n for (uint i = 0; i < tiers.length; i++) {\n uint traitIndex = hash[i];\n if (modifiedLayers[i] == false) {\n uint traitRangePosition = ((tokenDataId + i + traitSeed) * primeNumbers[i]) % maxSupply;\n traitIndex = rarityGen(traitRangePosition, i);\n hash[i] = traitIndex;\n }\n\n if (_linkedTraits[i][traitIndex].length > 0) {\n hash[_linkedTraits[i][traitIndex][0]] = _linkedTraits[i][traitIndex][1];\n modifiedLayers[_linkedTraits[i][traitIndex][0]] = true;\n }\n }\n\n for (uint i = 0; i < hash.length; i++) {\n if (hash[i] < 10) {\n hashBytes.appendSafe(\"00\");\n } else if (hash[i] < 100) {\n hashBytes.appendSafe(\"0\");\n }\n if (hash[i] > 999) {\n hashBytes.appendSafe(\"999\");\n } else {\n hashBytes.appendSafe(bytes(_toString(hash[i])));\n }\n }\n\n return string(hashBytes);\n }\n\n function handleMint(uint count, address recipient) internal whenMintActive returns (uint) {\n uint totalMinted = _totalMinted();\n require(count > 0, \"Invalid token count\");\n require(totalMinted + count <= maxSupply, \"All tokens are gone\");\n\n if (isPublicMintActive) {\n if (msg.sender != owner()) {\n require(_numberMinted(msg.sender) + count <= maxPerAddress, \"Exceeded max mints allowed\");\n require(count * publicMintPrice == msg.value, \"Incorrect amount of ether sent\");\n }\n require(msg.sender == tx.origin, \"EOAs only\");\n }\n\n uint batchCount = count / MAX_BATCH_MINT;\n uint remainder = count % MAX_BATCH_MINT;\n\n for (uint i = 0; i < batchCount; i++) {\n _mint(recipient, MAX_BATCH_MINT);\n }\n\n if (remainder > 0) {\n _mint(recipient, remainder);\n }\n\n return totalMinted;\n }\n\n function mint(uint count, bytes32[] calldata merkleProof)\n external\n payable\n nonReentrant\n whenMintActive\n returns (uint)\n {\n if (!isPublicMintActive && msg.sender != owner()) {\n require(onAllowList(msg.sender, merkleProof), \"Not on allow list\");\n require(_numberMinted(msg.sender) + count <= maxPerAllowList, \"Exceeded max mints allowed\");\n require(count * allowListPrice == msg.value, \"Incorrect amount of ether sent\");\n }\n return handleMint(count, msg.sender);\n }\n\n function airdrop(uint count, address recipient)\n external\n payable\n nonReentrant\n whenMintActive\n returns (uint)\n {\n require(isPublicMintActive || msg.sender == owner(), \"Public minting is not active\");\n return handleMint(count, recipient);\n }\n\n function isMintActive() public view returns (bool) {\n return _totalMinted() < maxSupply && (isPublicMintActive || isAllowListActive || msg.sender == owner());\n }\n\n function hashToSVG(string memory _hash)\n public\n view\n returns (string memory)\n {\n uint thisTraitIndex;\n \n bytes memory svgBytes = DynamicBuffer.allocate(1024 * 128);\n svgBytes.appendSafe('<svg width=\"1200\" height=\"1200\" viewBox=\"0 0 1200 1200\" version=\"1.2\" xmlns=\"http://www.w3.org/2000/svg\" style=\"background-color:');\n svgBytes.appendSafe(\n abi.encodePacked(\n backgroundColor,\n \";background-image:url(\"\n )\n );\n\n for (uint i = 0; i < tiers.length - 1; i++) {\n thisTraitIndex = HelperLib.parseInt(\n HelperLib._substring(_hash, (i * 3), (i * 3) + 3)\n );\n svgBytes.appendSafe(\n abi.encodePacked(\n \"data:\",\n _traitDetails[i][thisTraitIndex].mimetype,\n \";base64,\",\n Base64.encode(SSTORE2.read(_traitDataPointers[i][thisTraitIndex])),\n \"),url(\"\n )\n );\n }\n\n thisTraitIndex = HelperLib.parseInt(\n HelperLib._substring(_hash, (tiers.length * 3) - 3, tiers.length * 3)\n );\n \n svgBytes.appendSafe(\n abi.encodePacked(\n \"data:\",\n _traitDetails[tiers.length - 1][thisTraitIndex].mimetype,\n \";base64,\",\n Base64.encode(SSTORE2.read(_traitDataPointers[tiers.length - 1][thisTraitIndex])),\n ');background-repeat:no-repeat;background-size:contain;background-position:center;image-rendering:-webkit-optimize-contrast;-ms-interpolation-mode:nearest-neighbor;image-rendering:-moz-crisp-edges;image-rendering:pixelated;\"></svg>'\n )\n );\n\n return string(\n abi.encodePacked(\n \"data:image/svg+xml;base64,\",\n Base64.encode(svgBytes)\n )\n );\n }\n\n function hashToMetadata(string memory _hash)\n public\n view\n returns (string memory)\n {\n bytes memory metadataBytes = DynamicBuffer.allocate(1024 * 128);\n metadataBytes.appendSafe(\"[\");\n bool afterFirstTrait;\n\n for (uint i = 0; i < tiers.length; i++) {\n uint thisTraitIndex = HelperLib.parseInt(\n HelperLib._substring(_hash, (i * 3), (i * 3) + 3)\n );\n if (_traitDetails[i][thisTraitIndex].hide == false) {\n if (afterFirstTrait) {\n metadataBytes.appendSafe(\",\");\n }\n metadataBytes.appendSafe(\n abi.encodePacked(\n '{\"trait_type\":\"',\n layerNames[i],\n '\",\"value\":\"',\n _traitDetails[i][thisTraitIndex].name,\n '\"}'\n )\n );\n if (afterFirstTrait == false) {\n afterFirstTrait = true;\n }\n }\n\n if (i == tiers.length - 1) {\n metadataBytes.appendSafe(\"]\");\n }\n }\n\n return string(metadataBytes);\n }\n\n function onAllowList(address addr, bytes32[] calldata merkleProof) public view returns (bool) {\n return MerkleProof.verify(merkleProof, merkleRoot, keccak256(abi.encodePacked(addr)));\n }\n\n function tokenURI(uint tokenId)\n public\n view\n override\n returns (string memory)\n {\n require(_exists(tokenId), \"Invalid token\");\n require(_traitDataPointers[0].length > 0, \"Traits have not been added\");\n\n string memory tokenHash = tokenIdToHash(tokenId);\n\n bytes memory jsonBytes = DynamicBuffer.allocate(1024 * 128);\n\n jsonBytes.appendSafe(\n abi.encodePacked(\n '{\"name\":\"',\n contractData.name,\n \" #\",\n _toString(tokenId),\n '\",\"description\":\"',\n contractData.description,\n '\",'\n )\n );\n\n if (bytes(baseURI).length > 0 && _renderTokenOffChain[tokenId]) {\n jsonBytes.appendSafe(\n abi.encodePacked(\n '\"image\":\"',\n baseURI,\n _toString(tokenId),\n \"?dna=\",\n tokenHash,\n '&networkId=',\n networkId,\n '\",'\n )\n );\n } else {\n string memory svgCode = \"\";\n if (shouldWrapSVG) {\n string memory svgString = hashToSVG(tokenHash);\n svgCode = string(\n abi.encodePacked(\n \"data:image/svg+xml;base64,\",\n Base64.encode(\n abi.encodePacked(\n '<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 1200 1200\" version=\"1.2\" xmlns=\"http://www.w3.org/2000/svg\"><image width=\"1200\" height=\"1200\" href=\"',\n svgString,\n '\"></image></svg>'\n )\n )\n )\n );\n } else {\n svgCode = hashToSVG(tokenHash);\n }\n\n jsonBytes.appendSafe(\n abi.encodePacked(\n '\"image_data\":\"',\n svgCode,\n '\",'\n )\n );\n }\n\n jsonBytes.appendSafe(\n abi.encodePacked(\n '\"attributes\":',\n hashToMetadata(tokenHash),\n \"}\"\n )\n );\n\n return string(\n abi.encodePacked(\n \"data:application/json;base64,\",\n Base64.encode(jsonBytes)\n )\n );\n }\n\n function contractURI()\n public\n view\n returns (string memory)\n {\n return string(\n abi.encodePacked(\n \"data:application/json;base64,\",\n Base64.encode(\n abi.encodePacked(\n '{\"name\":\"',\n contractData.name,\n '\",\"description\":\"',\n contractData.description,\n '\",\"image\":\"',\n contractData.image,\n '\",\"banner\":\"',\n contractData.banner,\n '\",\"external_link\":\"',\n contractData.website,\n '\",\"seller_fee_basis_points\":',\n _toString(contractData.royalties),\n ',\"fee_recipient\":\"',\n contractData.royaltiesRecipient,\n '\"}'\n )\n )\n )\n );\n }\n\n function tokenIdToSVG(uint tokenId)\n public\n view\n returns (string memory)\n {\n return hashToSVG(tokenIdToHash(tokenId));\n }\n\n function traitDetails(uint layerIndex, uint traitIndex)\n public\n view\n returns (Trait memory)\n {\n return _traitDetails[layerIndex][traitIndex];\n }\n\n function traitData(uint layerIndex, uint traitIndex)\n public\n view\n returns (bytes memory)\n {\n return SSTORE2.read(_traitDataPointers[layerIndex][traitIndex]);\n }\n\n function getLinkedTraits(uint layerIndex, uint traitIndex)\n public\n view\n returns (uint[] memory)\n {\n return _linkedTraits[layerIndex][traitIndex];\n }\n\n function addLayer(uint layerIndex, TraitDTO[] memory traits)\n public\n onlyOwner\n whenUnsealed\n {\n require(tiers[layerIndex].length == traits.length, \"Traits length is incorrect\");\n address[] memory dataPointers = new address[](traits.length);\n for (uint i = 0; i < traits.length; i++) {\n if (traits[i].useExistingData) {\n dataPointers[i] = dataPointers[traits[i].existingDataIndex];\n } else {\n dataPointers[i] = SSTORE2.write(traits[i].data);\n }\n _traitDetails[layerIndex][i] = Trait(traits[i].name, traits[i].mimetype, traits[i].hide);\n }\n _traitDataPointers[layerIndex] = dataPointers;\n return;\n }\n\n function addTrait(uint layerIndex, uint traitIndex, TraitDTO memory trait)\n public\n onlyOwner\n whenUnsealed\n {\n _traitDetails[layerIndex][traitIndex] = Trait(trait.name, trait.mimetype, trait.hide);\n address[] memory dataPointers = _traitDataPointers[layerIndex];\n if (trait.useExistingData) {\n dataPointers[traitIndex] = dataPointers[trait.existingDataIndex];\n } else {\n dataPointers[traitIndex] = SSTORE2.write(trait.data);\n }\n _traitDataPointers[layerIndex] = dataPointers;\n return;\n }\n\n function setLinkedTraits(LinkedTraitDTO[] memory linkedTraits)\n public\n onlyOwner\n whenUnsealed\n {\n for (uint i = 0; i < linkedTraits.length; i++) {\n _linkedTraits[linkedTraits[i].traitA[0]][linkedTraits[i].traitA[1]] = [linkedTraits[i].traitB[0],linkedTraits[i].traitB[1]];\n }\n }\n\n function setContractData(ContractData memory data) external onlyOwner whenUnsealed {\n contractData = data;\n }\n\n function setMaxPerAddress(uint max) external onlyOwner {\n maxPerAddress = max;\n }\n\n function setBaseURI(string memory uri) external onlyOwner {\n baseURI = uri;\n }\n\n function setBackgroundColor(string memory color) external onlyOwner whenUnsealed {\n backgroundColor = color;\n }\n\n function setRenderOfTokenId(uint tokenId, bool renderOffChain) external {\n require(msg.sender == ownerOf(tokenId), \"Not token owner\");\n _renderTokenOffChain[tokenId] = renderOffChain;\n }\n\n function setMerkleRoot(bytes32 newMerkleRoot) external onlyOwner {\n merkleRoot = newMerkleRoot;\n }\n\n function setMaxPerAllowList(uint max) external onlyOwner {\n maxPerAllowList = max;\n }\n\n function setAllowListPrice(uint price) external onlyOwner {\n allowListPrice = price;\n }\n\n function toggleAllowListMint() external onlyOwner {\n isAllowListActive = !isAllowListActive;\n }\n\n function toggleOperatorFilter() external onlyOwner {\n isOperatorFilterEnabled = !isOperatorFilterEnabled;\n }\n\n function toggleWrapSVG() external onlyOwner {\n shouldWrapSVG = !shouldWrapSVG;\n }\n\n function togglePublicMint() external onlyOwner {\n isPublicMintActive = !isPublicMintActive;\n }\n\n function sealContract() external whenUnsealed onlyOwner {\n isContractSealed = true;\n }\n\n function withdraw() external onlyOwner nonReentrant {\n uint balance = address(this).balance;\n uint amount = (balance * (10000 - DEVELOPER_FEE)) / 10000;\n uint distAmount = 0;\n uint totalDistributionPercentage = 0;\n\n address payable receiver = payable(owner());\n address payable dev = payable(0xEA208Da933C43857683C04BC76e3FD331D7bfdf7);\n Address.sendValue(dev, balance - amount);\n\n if (withdrawRecipients.length > 0) {\n for (uint i = 0; i < withdrawRecipients.length; i++) {\n totalDistributionPercentage = totalDistributionPercentage + withdrawRecipients[i].percentage;\n address payable currRecepient = payable(withdrawRecipients[i].recipientAddress);\n distAmount = (amount * (10000 - withdrawRecipients[i].percentage)) / 10000;\n\n Address.sendValue(currRecepient, amount - distAmount);\n }\n }\n balance = address(this).balance;\n Address.sendValue(receiver, balance);\n }\n\n function transferFrom(address from, address to, uint tokenId)\n public\n payable\n override\n onlyAllowedOperator(from)\n {\n super.transferFrom(from, to, tokenId);\n }\n\n function safeTransferFrom(address from, address to, uint tokenId)\n public\n payable\n override\n onlyAllowedOperator(from)\n {\n super.safeTransferFrom(from, to, tokenId);\n }\n\n function safeTransferFrom(address from, address to, uint tokenId, bytes memory data)\n public\n payable\n override\n onlyAllowedOperator(from)\n {\n super.safeTransferFrom(from, to, tokenId, data);\n }\n}"
},
"/app/contracts/DefaultOperatorFilterer.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\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}"
},
"/app/contracts/DynamicBuffer.sol": {
"content": "// SPDX-License-Identifier: MIT\n// Copyright (c) 2021 the ethier authors (github.com/divergencetech/ethier)\n\npragma solidity >=0.8.0;\n\n/// @title DynamicBuffer\n/// @author David Huber (@cxkoda) and Simon Fremaux (@dievardump). See also\n/// https://raw.githubusercontent.com/dievardump/solidity-dynamic-buffer\n/// @notice This library is used to allocate a big amount of container memory\n// which will be subsequently filled without needing to reallocate\n/// memory.\n/// @dev First, allocate memory.\n/// Then use `buffer.appendUnchecked(theBytes)` or `appendSafe()` if\n/// bounds checking is required.\nlibrary DynamicBuffer {\n /// @notice Allocates container space for the DynamicBuffer\n /// @param capacity The intended max amount of bytes in the buffer\n /// @return buffer The memory location of the buffer\n /// @dev Allocates `capacity + 0x60` bytes of space\n /// The buffer array starts at the first container data position,\n /// (i.e. `buffer = container + 0x20`)\n function allocate(uint256 capacity)\n internal\n pure\n returns (bytes memory buffer)\n {\n assembly {\n // Get next-free memory address\n let container := mload(0x40)\n\n // Allocate memory by setting a new next-free address\n {\n // Add 2 x 32 bytes in size for the two length fields\n // Add 32 bytes safety space for 32B chunked copy\n let size := add(capacity, 0x60)\n let newNextFree := add(container, size)\n mstore(0x40, newNextFree)\n }\n\n // Set the correct container length\n {\n let length := add(capacity, 0x40)\n mstore(container, length)\n }\n\n // The buffer starts at idx 1 in the container (0 is length)\n buffer := add(container, 0x20)\n\n // Init content with length 0\n mstore(buffer, 0)\n }\n\n return buffer;\n }\n\n /// @notice Appends data to buffer, and update buffer length\n /// @param buffer the buffer to append the data to\n /// @param data the data to append\n /// @dev Does not perform out-of-bound checks (container capacity)\n /// for efficiency.\n function appendUnchecked(bytes memory buffer, bytes memory data)\n internal\n pure\n {\n assembly {\n let length := mload(data)\n for {\n data := add(data, 0x20)\n let dataEnd := add(data, length)\n let copyTo := add(buffer, add(mload(buffer), 0x20))\n } lt(data, dataEnd) {\n data := add(data, 0x20)\n copyTo := add(copyTo, 0x20)\n } {\n // Copy 32B chunks from data to buffer.\n // This may read over data array boundaries and copy invalid\n // bytes, which doesn't matter in the end since we will\n // later set the correct buffer length, and have allocated an\n // additional word to avoid buffer overflow.\n mstore(copyTo, mload(data))\n }\n\n // Update buffer length\n mstore(buffer, add(mload(buffer), length))\n }\n }\n\n /// @notice Appends data to buffer, and update buffer length\n /// @param buffer the buffer to append the data to\n /// @param data the data to append\n /// @dev Performs out-of-bound checks and calls `appendUnchecked`.\n function appendSafe(bytes memory buffer, bytes memory data) internal pure {\n uint256 capacity;\n uint256 length;\n assembly {\n capacity := sub(mload(sub(buffer, 0x20)), 0x40)\n length := mload(buffer)\n }\n\n require(\n length + data.length <= capacity,\n \"DynamicBuffer: Appending out of bounds.\"\n );\n appendUnchecked(buffer, data);\n }\n}"
},
"/app/contracts/HelperLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.14;\n\nlibrary HelperLib {\n function parseInt(string memory _a)\n internal\n pure\n returns (uint8 _parsedInt)\n {\n bytes memory bresult = bytes(_a);\n uint8 mint = 0;\n for (uint8 i = 0; i < bresult.length; i++) {\n if (\n (uint8(uint8(bresult[i])) >= 48) &&\n (uint8(uint8(bresult[i])) <= 57)\n ) {\n mint *= 10;\n mint += uint8(bresult[i]) - 48;\n }\n }\n return mint;\n }\n\n function _substring(\n string memory str,\n uint256 startIndex,\n uint256 endIndex\n ) internal pure returns (string memory) {\n bytes memory strBytes = bytes(str);\n bytes memory result = new bytes(endIndex - startIndex);\n for (uint256 i = startIndex; i < endIndex; i++) {\n result[i - startIndex] = strBytes[i];\n }\n return string(result);\n }\n}"
},
"/app/contracts/IOperatorFilterRegistry.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\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 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}"
},
"/app/contracts/OperatorFilterer.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\n\nimport {IOperatorFilterRegistry} from \"./IOperatorFilterRegistry.sol\";\n\nabstract contract OperatorFilterer {\n error OperatorNotAllowed(address operator);\n\n bool public isOperatorFilterEnabled = true;\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 if filter operator is enabled\n if (!isOperatorFilterEnabled) {\n _;\n return;\n }\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}"
},
"/app/contracts/SSTORE2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"./utils/Bytecode.sol\";\n\n/**\n @title A key-value storage with auto-generated keys for storing chunks of data with a lower write & read cost.\n @author Agustin Aguilar <aa@horizon.io>\n\n Readme: https://github.com/0xsequence/sstore2#readme\n*/\nlibrary SSTORE2 {\n error WriteError();\n\n /**\n @notice Stores `_data` and returns `pointer` as key for later retrieval\n @dev The pointer is a contract address with `_data` as code\n @param _data to be written\n @return pointer Pointer to the written `_data`\n */\n function write(bytes memory _data) internal returns (address pointer) {\n // Append 00 to _data so contract can't be called\n // Build init code\n bytes memory code = Bytecode.creationCodeFor(\n abi.encodePacked(\n hex'00',\n _data\n )\n );\n\n // Deploy contract using create\n assembly { pointer := create(0, add(code, 32), mload(code)) }\n\n // Address MUST be non-zero\n if (pointer == address(0)) revert WriteError();\n }\n\n /**\n @notice Reads the contents of the `_pointer` code as data, skips the first byte \n @dev The function is intended for reading pointers generated by `write`\n @param _pointer to be read\n @return data read from `_pointer` contract\n */\n function read(address _pointer) internal view returns (bytes memory) {\n return Bytecode.codeAt(_pointer, 1, type(uint256).max);\n }\n\n /**\n @notice Reads the contents of the `_pointer` code as data, skips the first byte \n @dev The function is intended for reading pointers generated by `write`\n @param _pointer to be read\n @param _start number of bytes to skip\n @return data read from `_pointer` contract\n */\n function read(address _pointer, uint256 _start) internal view returns (bytes memory) {\n return Bytecode.codeAt(_pointer, _start + 1, type(uint256).max);\n }\n\n /**\n @notice Reads the contents of the `_pointer` code as data, skips the first byte \n @dev The function is intended for reading pointers generated by `write`\n @param _pointer to be read\n @param _start number of bytes to skip\n @param _end index before which to end extraction\n @return data read from `_pointer` contract\n */\n function read(address _pointer, uint256 _start, uint256 _end) internal view returns (bytes memory) {\n return Bytecode.codeAt(_pointer, _start + 1, _end + 1);\n }\n}"
},
"/app/contracts/utils/Bytecode.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n\nlibrary Bytecode {\n error InvalidCodeAtRange(uint256 _size, uint256 _start, uint256 _end);\n\n /**\n @notice Generate a creation code that results on a contract with `_code` as bytecode\n @param _code The returning value of the resulting `creationCode`\n @return creationCode (constructor) for new contract\n */\n function creationCodeFor(bytes memory _code) internal pure returns (bytes memory) {\n /*\n 0x00 0x63 0x63XXXXXX PUSH4 _code.length size\n 0x01 0x80 0x80 DUP1 size size\n 0x02 0x60 0x600e PUSH1 14 14 size size\n 0x03 0x60 0x6000 PUSH1 00 0 14 size size\n 0x04 0x39 0x39 CODECOPY size\n 0x05 0x60 0x6000 PUSH1 00 0 size\n 0x06 0xf3 0xf3 RETURN\n <CODE>\n */\n\n return abi.encodePacked(\n hex\"63\",\n uint32(_code.length),\n hex\"80_60_0E_60_00_39_60_00_F3\",\n _code\n );\n }\n\n /**\n @notice Returns the size of the code on a given address\n @param _addr Address that may or may not contain code\n @return size of the code on the given `_addr`\n */\n function codeSize(address _addr) internal view returns (uint256 size) {\n assembly { size := extcodesize(_addr) }\n }\n\n /**\n @notice Returns the code of a given address\n @dev It will fail if `_end < _start`\n @param _addr Address that may or may not contain code\n @param _start number of bytes of code to skip on read\n @param _end index before which to end extraction\n @return oCode read from `_addr` deployed bytecode\n\n Forked from: https://gist.github.com/KardanovIR/fe98661df9338c842b4a30306d507fbd\n */\n function codeAt(address _addr, uint256 _start, uint256 _end) internal view returns (bytes memory oCode) {\n uint256 csize = codeSize(_addr);\n if (csize == 0) return bytes(\"\");\n\n if (_start > csize) return bytes(\"\");\n if (_end < _start) revert InvalidCodeAtRange(csize, _start, _end); \n\n unchecked {\n uint256 reqSize = _end - _start;\n uint256 maxSize = csize - _start;\n\n uint256 size = maxSize < reqSize ? maxSize : reqSize;\n\n assembly {\n // allocate output byte array - this could also be done without assembly\n // by using o_code = new bytes(size)\n oCode := mload(0x40)\n // new \"memory end\" including padding\n mstore(0x40, add(oCode, and(add(add(size, 0x20), 0x1f), not(0x1f))))\n // store length in memory\n mstore(oCode, size)\n // actually retrieve the code, this needs assembly\n extcodecopy(_addr, add(oCode, 0x20), _start, size)\n }\n }\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/security/ReentrancyGuard.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n constructor() {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be _NOT_ENTERED\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\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/cryptography/MerkleProof.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/MerkleProof.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev These functions deal with verification of Merkle Tree proofs.\n *\n * The tree and the proofs can be generated using our\n * https://github.com/OpenZeppelin/merkle-tree[JavaScript library].\n * You will find a quickstart guide in the readme.\n *\n * WARNING: You should avoid using leaf values that are 64 bytes long prior to\n * hashing, or use a hash function other than keccak256 for hashing leaves.\n * This is because the concatenation of a sorted pair of internal nodes in\n * the merkle tree could be reinterpreted as a leaf value.\n * OpenZeppelin's JavaScript library generates merkle trees that are safe\n * against this attack out of the box.\n */\nlibrary MerkleProof {\n /**\n * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree\n * defined by `root`. For this, a `proof` must be provided, containing\n * sibling hashes on the branch from the leaf to the root of the tree. Each\n * pair of leaves and each pair of pre-images are assumed to be sorted.\n */\n function verify(\n bytes32[] memory proof,\n bytes32 root,\n bytes32 leaf\n ) internal pure returns (bool) {\n return processProof(proof, leaf) == root;\n }\n\n /**\n * @dev Calldata version of {verify}\n *\n * _Available since v4.7._\n */\n function verifyCalldata(\n bytes32[] calldata proof,\n bytes32 root,\n bytes32 leaf\n ) internal pure returns (bool) {\n return processProofCalldata(proof, leaf) == root;\n }\n\n /**\n * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up\n * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt\n * hash matches the root of the tree. When processing the proof, the pairs\n * of leafs & pre-images are assumed to be sorted.\n *\n * _Available since v4.4._\n */\n function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {\n bytes32 computedHash = leaf;\n for (uint256 i = 0; i < proof.length; i++) {\n computedHash = _hashPair(computedHash, proof[i]);\n }\n return computedHash;\n }\n\n /**\n * @dev Calldata version of {processProof}\n *\n * _Available since v4.7._\n */\n function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {\n bytes32 computedHash = leaf;\n for (uint256 i = 0; i < proof.length; i++) {\n computedHash = _hashPair(computedHash, proof[i]);\n }\n return computedHash;\n }\n\n /**\n * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by\n * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.\n *\n * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.\n *\n * _Available since v4.7._\n */\n function multiProofVerify(\n bytes32[] memory proof,\n bool[] memory proofFlags,\n bytes32 root,\n bytes32[] memory leaves\n ) internal pure returns (bool) {\n return processMultiProof(proof, proofFlags, leaves) == root;\n }\n\n /**\n * @dev Calldata version of {multiProofVerify}\n *\n * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.\n *\n * _Available since v4.7._\n */\n function multiProofVerifyCalldata(\n bytes32[] calldata proof,\n bool[] calldata proofFlags,\n bytes32 root,\n bytes32[] memory leaves\n ) internal pure returns (bool) {\n return processMultiProofCalldata(proof, proofFlags, leaves) == root;\n }\n\n /**\n * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction\n * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another\n * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false\n * respectively.\n *\n * CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree\n * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the\n * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).\n *\n * _Available since v4.7._\n */\n function processMultiProof(\n bytes32[] memory proof,\n bool[] memory proofFlags,\n bytes32[] memory leaves\n ) internal pure returns (bytes32 merkleRoot) {\n // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by\n // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the\n // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of\n // the merkle tree.\n uint256 leavesLen = leaves.length;\n uint256 totalHashes = proofFlags.length;\n\n // Check proof validity.\n require(leavesLen + proof.length - 1 == totalHashes, \"MerkleProof: invalid multiproof\");\n\n // The xxxPos values are \"pointers\" to the next value to consume in each array. All accesses are done using\n // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's \"pop\".\n bytes32[] memory hashes = new bytes32[](totalHashes);\n uint256 leafPos = 0;\n uint256 hashPos = 0;\n uint256 proofPos = 0;\n // At each step, we compute the next hash using two values:\n // - a value from the \"main queue\". If not all leaves have been consumed, we get the next leaf, otherwise we\n // get the next hash.\n // - depending on the flag, either another value for the \"main queue\" (merging branches) or an element from the\n // `proof` array.\n for (uint256 i = 0; i < totalHashes; i++) {\n bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];\n bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];\n hashes[i] = _hashPair(a, b);\n }\n\n if (totalHashes > 0) {\n return hashes[totalHashes - 1];\n } else if (leavesLen > 0) {\n return leaves[0];\n } else {\n return proof[0];\n }\n }\n\n /**\n * @dev Calldata version of {processMultiProof}.\n *\n * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.\n *\n * _Available since v4.7._\n */\n function processMultiProofCalldata(\n bytes32[] calldata proof,\n bool[] calldata proofFlags,\n bytes32[] memory leaves\n ) internal pure returns (bytes32 merkleRoot) {\n // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by\n // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the\n // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of\n // the merkle tree.\n uint256 leavesLen = leaves.length;\n uint256 totalHashes = proofFlags.length;\n\n // Check proof validity.\n require(leavesLen + proof.length - 1 == totalHashes, \"MerkleProof: invalid multiproof\");\n\n // The xxxPos values are \"pointers\" to the next value to consume in each array. All accesses are done using\n // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's \"pop\".\n bytes32[] memory hashes = new bytes32[](totalHashes);\n uint256 leafPos = 0;\n uint256 hashPos = 0;\n uint256 proofPos = 0;\n // At each step, we compute the next hash using two values:\n // - a value from the \"main queue\". If not all leaves have been consumed, we get the next leaf, otherwise we\n // get the next hash.\n // - depending on the flag, either another value for the \"main queue\" (merging branches) or an element from the\n // `proof` array.\n for (uint256 i = 0; i < totalHashes; i++) {\n bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];\n bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];\n hashes[i] = _hashPair(a, b);\n }\n\n if (totalHashes > 0) {\n return hashes[totalHashes - 1];\n } else if (leavesLen > 0) {\n return leaves[0];\n } else {\n return proof[0];\n }\n }\n\n function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {\n return a < b ? _efficientHash(a, b) : _efficientHash(b, a);\n }\n\n function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(0x00, a)\n mstore(0x20, b)\n value := keccak256(0x00, 0x40)\n }\n }\n}\n"
},
"erc721a/contracts/ERC721A.sol": {
"content": "// SPDX-License-Identifier: MIT\n// ERC721A Contracts v4.2.3\n// Creator: Chiru Labs\n\npragma solidity ^0.8.4;\n\nimport './IERC721A.sol';\n\n/**\n * @dev Interface of ERC721 token receiver.\n */\ninterface ERC721A__IERC721Receiver {\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}\n\n/**\n * @title ERC721A\n *\n * @dev Implementation of the [ERC721](https://eips.ethereum.org/EIPS/eip-721)\n * Non-Fungible Token Standard, including the Metadata extension.\n * Optimized for lower gas during batch mints.\n *\n * Token IDs are minted in sequential order (e.g. 0, 1, 2, 3, ...)\n * starting from `_startTokenId()`.\n *\n * Assumptions:\n *\n * - An owner cannot have more than 2**64 - 1 (max value of uint64) of supply.\n * - The maximum token ID cannot exceed 2**256 - 1 (max value of uint256).\n */\ncontract ERC721A is IERC721A {\n // Bypass for a `--via-ir` bug (https://github.com/chiru-labs/ERC721A/pull/364).\n struct TokenApprovalRef {\n address value;\n }\n\n // =============================================================\n // CONSTANTS\n // =============================================================\n\n // Mask of an entry in packed address data.\n uint256 private constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;\n\n // The bit position of `numberMinted` in packed address data.\n uint256 private constant _BITPOS_NUMBER_MINTED = 64;\n\n // The bit position of `numberBurned` in packed address data.\n uint256 private constant _BITPOS_NUMBER_BURNED = 128;\n\n // The bit position of `aux` in packed address data.\n uint256 private constant _BITPOS_AUX = 192;\n\n // Mask of all 256 bits in packed address data except the 64 bits for `aux`.\n uint256 private constant _BITMASK_AUX_COMPLEMENT = (1 << 192) - 1;\n\n // The bit position of `startTimestamp` in packed ownership.\n uint256 private constant _BITPOS_START_TIMESTAMP = 160;\n\n // The bit mask of the `burned` bit in packed ownership.\n uint256 private constant _BITMASK_BURNED = 1 << 224;\n\n // The bit position of the `nextInitialized` bit in packed ownership.\n uint256 private constant _BITPOS_NEXT_INITIALIZED = 225;\n\n // The bit mask of the `nextInitialized` bit in packed ownership.\n uint256 private constant _BITMASK_NEXT_INITIALIZED = 1 << 225;\n\n // The bit position of `extraData` in packed ownership.\n uint256 private constant _BITPOS_EXTRA_DATA = 232;\n\n // Mask of all 256 bits in a packed ownership except the 24 bits for `extraData`.\n uint256 private constant _BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1;\n\n // The mask of the lower 160 bits for addresses.\n uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;\n\n // The maximum `quantity` that can be minted with {_mintERC2309}.\n // This limit is to prevent overflows on the address data entries.\n // For a limit of 5000, a total of 3.689e15 calls to {_mintERC2309}\n // is required to cause an overflow, which is unrealistic.\n uint256 private constant _MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;\n\n // The `Transfer` event signature is given by:\n // `keccak256(bytes(\"Transfer(address,address,uint256)\"))`.\n bytes32 private constant _TRANSFER_EVENT_SIGNATURE =\n 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;\n\n // =============================================================\n // STORAGE\n // =============================================================\n\n // The next token ID to be minted.\n uint256 private _currentIndex;\n\n // The number of tokens burned.\n uint256 private _burnCounter;\n\n // Token name\n string private _name;\n\n // Token symbol\n string private _symbol;\n\n // Mapping from token ID to ownership details\n // An empty struct value does not necessarily mean the token is unowned.\n // See {_packedOwnershipOf} implementation for details.\n //\n // Bits Layout:\n // - [0..159] `addr`\n // - [160..223] `startTimestamp`\n // - [224] `burned`\n // - [225] `nextInitialized`\n // - [232..255] `extraData`\n mapping(uint256 => uint256) private _packedOwnerships;\n\n // Mapping owner address to address data.\n //\n // Bits Layout:\n // - [0..63] `balance`\n // - [64..127] `numberMinted`\n // - [128..191] `numberBurned`\n // - [192..255] `aux`\n mapping(address => uint256) private _packedAddressData;\n\n // Mapping from token ID to approved address.\n mapping(uint256 => TokenApprovalRef) private _tokenApprovals;\n\n // Mapping from owner to operator approvals\n mapping(address => mapping(address => bool)) private _operatorApprovals;\n\n // =============================================================\n // CONSTRUCTOR\n // =============================================================\n\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n _currentIndex = _startTokenId();\n }\n\n // =============================================================\n // TOKEN COUNTING OPERATIONS\n // =============================================================\n\n /**\n * @dev Returns the starting token ID.\n * To change the starting token ID, please override this function.\n */\n function _startTokenId() internal view virtual returns (uint256) {\n return 0;\n }\n\n /**\n * @dev Returns the next token ID to be minted.\n */\n function _nextTokenId() internal view virtual returns (uint256) {\n return _currentIndex;\n }\n\n /**\n * @dev Returns the total number of tokens in existence.\n * Burned tokens will reduce the count.\n * To get the total number of tokens minted, please see {_totalMinted}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n // Counter underflow is impossible as _burnCounter cannot be incremented\n // more than `_currentIndex - _startTokenId()` times.\n unchecked {\n return _currentIndex - _burnCounter - _startTokenId();\n }\n }\n\n /**\n * @dev Returns the total amount of tokens minted in the contract.\n */\n function _totalMinted() internal view virtual returns (uint256) {\n // Counter underflow is impossible as `_currentIndex` does not decrement,\n // and it is initialized to `_startTokenId()`.\n unchecked {\n return _currentIndex - _startTokenId();\n }\n }\n\n /**\n * @dev Returns the total number of tokens burned.\n */\n function _totalBurned() internal view virtual returns (uint256) {\n return _burnCounter;\n }\n\n // =============================================================\n // ADDRESS DATA OPERATIONS\n // =============================================================\n\n /**\n * @dev Returns the number of tokens in `owner`'s account.\n */\n function balanceOf(address owner) public view virtual override returns (uint256) {\n if (owner == address(0)) revert BalanceQueryForZeroAddress();\n return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY;\n }\n\n /**\n * Returns the number of tokens minted by `owner`.\n */\n function _numberMinted(address owner) internal view returns (uint256) {\n return (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & _BITMASK_ADDRESS_DATA_ENTRY;\n }\n\n /**\n * Returns the number of tokens burned by or on behalf of `owner`.\n */\n function _numberBurned(address owner) internal view returns (uint256) {\n return (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & _BITMASK_ADDRESS_DATA_ENTRY;\n }\n\n /**\n * Returns the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).\n */\n function _getAux(address owner) internal view returns (uint64) {\n return uint64(_packedAddressData[owner] >> _BITPOS_AUX);\n }\n\n /**\n * Sets the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).\n * If there are multiple variables, please pack them into a uint64.\n */\n function _setAux(address owner, uint64 aux) internal virtual {\n uint256 packed = _packedAddressData[owner];\n uint256 auxCasted;\n // Cast `aux` with assembly to avoid redundant masking.\n assembly {\n auxCasted := aux\n }\n packed = (packed & _BITMASK_AUX_COMPLEMENT) | (auxCasted << _BITPOS_AUX);\n _packedAddressData[owner] = packed;\n }\n\n // =============================================================\n // IERC165\n // =============================================================\n\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30000 gas.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n // The interface IDs are constants representing the first 4 bytes\n // of the XOR of all function selectors in the interface.\n // See: [ERC165](https://eips.ethereum.org/EIPS/eip-165)\n // (e.g. `bytes4(i.functionA.selector ^ i.functionB.selector ^ ...)`)\n return\n interfaceId == 0x01ffc9a7 || // ERC165 interface ID for ERC165.\n interfaceId == 0x80ac58cd || // ERC165 interface ID for ERC721.\n interfaceId == 0x5b5e139f; // ERC165 interface ID for ERC721Metadata.\n }\n\n // =============================================================\n // IERC721Metadata\n // =============================================================\n\n /**\n * @dev Returns the token collection name.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the token collection symbol.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n */\n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\n if (!_exists(tokenId)) revert URIQueryForNonexistentToken();\n\n string memory baseURI = _baseURI();\n return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : '';\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, it can be overridden in child contracts.\n */\n function _baseURI() internal view virtual returns (string memory) {\n return '';\n }\n\n // =============================================================\n // OWNERSHIPS OPERATIONS\n // =============================================================\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) public view virtual override returns (address) {\n return address(uint160(_packedOwnershipOf(tokenId)));\n }\n\n /**\n * @dev Gas spent here starts off proportional to the maximum mint batch size.\n * It gradually moves to O(1) as tokens get transferred around over time.\n */\n function _ownershipOf(uint256 tokenId) internal view virtual returns (TokenOwnership memory) {\n return _unpackedOwnership(_packedOwnershipOf(tokenId));\n }\n\n /**\n * @dev Returns the unpacked `TokenOwnership` struct at `index`.\n */\n function _ownershipAt(uint256 index) internal view virtual returns (TokenOwnership memory) {\n return _unpackedOwnership(_packedOwnerships[index]);\n }\n\n /**\n * @dev Initializes the ownership slot minted at `index` for efficiency purposes.\n */\n function _initializeOwnershipAt(uint256 index) internal virtual {\n if (_packedOwnerships[index] == 0) {\n _packedOwnerships[index] = _packedOwnershipOf(index);\n }\n }\n\n /**\n * Returns the packed ownership data of `tokenId`.\n */\n function _packedOwnershipOf(uint256 tokenId) private view returns (uint256) {\n uint256 curr = tokenId;\n\n unchecked {\n if (_startTokenId() <= curr)\n if (curr < _currentIndex) {\n uint256 packed = _packedOwnerships[curr];\n // If not burned.\n if (packed & _BITMASK_BURNED == 0) {\n // Invariant:\n // There will always be an initialized ownership slot\n // (i.e. `ownership.addr != address(0) && ownership.burned == false`)\n // before an unintialized ownership slot\n // (i.e. `ownership.addr == address(0) && ownership.burned == false`)\n // Hence, `curr` will not underflow.\n //\n // We can directly compare the packed value.\n // If the address is zero, packed will be zero.\n while (packed == 0) {\n packed = _packedOwnerships[--curr];\n }\n return packed;\n }\n }\n }\n revert OwnerQueryForNonexistentToken();\n }\n\n /**\n * @dev Returns the unpacked `TokenOwnership` struct from `packed`.\n */\n function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) {\n ownership.addr = address(uint160(packed));\n ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP);\n ownership.burned = packed & _BITMASK_BURNED != 0;\n ownership.extraData = uint24(packed >> _BITPOS_EXTRA_DATA);\n }\n\n /**\n * @dev Packs ownership data into a single uint256.\n */\n function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) {\n assembly {\n // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.\n owner := and(owner, _BITMASK_ADDRESS)\n // `owner | (block.timestamp << _BITPOS_START_TIMESTAMP) | flags`.\n result := or(owner, or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags))\n }\n }\n\n /**\n * @dev Returns the `nextInitialized` flag set if `quantity` equals 1.\n */\n function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) {\n // For branchless setting of the `nextInitialized` flag.\n assembly {\n // `(quantity == 1) << _BITPOS_NEXT_INITIALIZED`.\n result := shl(_BITPOS_NEXT_INITIALIZED, eq(quantity, 1))\n }\n }\n\n // =============================================================\n // APPROVAL OPERATIONS\n // =============================================================\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\n * 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) public payable virtual override {\n address owner = ownerOf(tokenId);\n\n if (_msgSenderERC721A() != owner)\n if (!isApprovedForAll(owner, _msgSenderERC721A())) {\n revert ApprovalCallerNotOwnerNorApproved();\n }\n\n _tokenApprovals[tokenId].value = to;\n emit Approval(owner, to, tokenId);\n }\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) public view virtual override returns (address) {\n if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken();\n\n return _tokenApprovals[tokenId].value;\n }\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom}\n * 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) public virtual override {\n _operatorApprovals[_msgSenderERC721A()][operator] = approved;\n emit ApprovalForAll(_msgSenderERC721A(), operator, approved);\n }\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) public view virtual override returns (bool) {\n return _operatorApprovals[owner][operator];\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. See {_mint}.\n */\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\n return\n _startTokenId() <= tokenId &&\n tokenId < _currentIndex && // If within bounds,\n _packedOwnerships[tokenId] & _BITMASK_BURNED == 0; // and not burned.\n }\n\n /**\n * @dev Returns whether `msgSender` is equal to `approvedAddress` or `owner`.\n */\n function _isSenderApprovedOrOwner(\n address approvedAddress,\n address owner,\n address msgSender\n ) private pure returns (bool result) {\n assembly {\n // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.\n owner := and(owner, _BITMASK_ADDRESS)\n // Mask `msgSender` to the lower 160 bits, in case the upper bits somehow aren't clean.\n msgSender := and(msgSender, _BITMASK_ADDRESS)\n // `msgSender == owner || msgSender == approvedAddress`.\n result := or(eq(msgSender, owner), eq(msgSender, approvedAddress))\n }\n }\n\n /**\n * @dev Returns the storage slot and value for the approved address of `tokenId`.\n */\n function _getApprovedSlotAndAddress(uint256 tokenId)\n private\n view\n returns (uint256 approvedAddressSlot, address approvedAddress)\n {\n TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId];\n // The following is equivalent to `approvedAddress = _tokenApprovals[tokenId].value`.\n assembly {\n approvedAddressSlot := tokenApproval.slot\n approvedAddress := sload(approvedAddressSlot)\n }\n }\n\n // =============================================================\n // TRANSFER OPERATIONS\n // =============================================================\n\n /**\n * @dev Transfers `tokenId` 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 be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token\n * 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 ) public payable virtual override {\n uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);\n\n if (address(uint160(prevOwnershipPacked)) != from) revert TransferFromIncorrectOwner();\n\n (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);\n\n // The nested ifs save around 20+ gas over a compound boolean condition.\n if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))\n if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();\n\n if (to == address(0)) revert TransferToZeroAddress();\n\n _beforeTokenTransfers(from, to, tokenId, 1);\n\n // Clear approvals from the previous owner.\n assembly {\n if approvedAddress {\n // This is equivalent to `delete _tokenApprovals[tokenId]`.\n sstore(approvedAddressSlot, 0)\n }\n }\n\n // Underflow of the sender's balance is impossible because we check for\n // ownership above and the recipient's balance can't realistically overflow.\n // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.\n unchecked {\n // We can directly increment and decrement the balances.\n --_packedAddressData[from]; // Updates: `balance -= 1`.\n ++_packedAddressData[to]; // Updates: `balance += 1`.\n\n // Updates:\n // - `address` to the next owner.\n // - `startTimestamp` to the timestamp of transfering.\n // - `burned` to `false`.\n // - `nextInitialized` to `true`.\n _packedOwnerships[tokenId] = _packOwnershipData(\n to,\n _BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked)\n );\n\n // If the next slot may not have been initialized (i.e. `nextInitialized == false`) .\n if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {\n uint256 nextTokenId = tokenId + 1;\n // If the next slot's address is zero and not burned (i.e. packed value is zero).\n if (_packedOwnerships[nextTokenId] == 0) {\n // If the next slot is within bounds.\n if (nextTokenId != _currentIndex) {\n // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.\n _packedOwnerships[nextTokenId] = prevOwnershipPacked;\n }\n }\n }\n }\n\n emit Transfer(from, to, tokenId);\n _afterTokenTransfers(from, to, tokenId, 1);\n }\n\n /**\n * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public payable virtual override {\n safeTransferFrom(from, to, tokenId, '');\n }\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\n * by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement\n * {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 memory _data\n ) public payable virtual override {\n transferFrom(from, to, tokenId);\n if (to.code.length != 0)\n if (!_checkContractOnERC721Received(from, to, tokenId, _data)) {\n revert TransferToNonERC721ReceiverImplementer();\n }\n }\n\n /**\n * @dev Hook that is called before a set of serially-ordered token IDs\n * are about to be transferred. This includes minting.\n * And also called before burning one token.\n *\n * `startTokenId` - the first token ID to be transferred.\n * `quantity` - the amount to be transferred.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\n * transferred to `to`.\n * - When `from` is zero, `tokenId` will be minted for `to`.\n * - When `to` is zero, `tokenId` will be burned by `from`.\n * - `from` and `to` are never both zero.\n */\n function _beforeTokenTransfers(\n address from,\n address to,\n uint256 startTokenId,\n uint256 quantity\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after a set of serially-ordered token IDs\n * have been transferred. This includes minting.\n * And also called after one token has been burned.\n *\n * `startTokenId` - the first token ID to be transferred.\n * `quantity` - the amount to be transferred.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been\n * transferred to `to`.\n * - When `from` is zero, `tokenId` has been minted for `to`.\n * - When `to` is zero, `tokenId` has been burned by `from`.\n * - `from` and `to` are never both zero.\n */\n function _afterTokenTransfers(\n address from,\n address to,\n uint256 startTokenId,\n uint256 quantity\n ) internal virtual {}\n\n /**\n * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target contract.\n *\n * `from` - Previous owner of the given token ID.\n * `to` - Target address that will receive the token.\n * `tokenId` - Token ID to be transferred.\n * `_data` - Optional data to send along with the call.\n *\n * Returns whether the call correctly returned the expected magic value.\n */\n function _checkContractOnERC721Received(\n address from,\n address to,\n uint256 tokenId,\n bytes memory _data\n ) private returns (bool) {\n try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns (\n bytes4 retval\n ) {\n return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector;\n } catch (bytes memory reason) {\n if (reason.length == 0) {\n revert TransferToNonERC721ReceiverImplementer();\n } else {\n assembly {\n revert(add(32, reason), mload(reason))\n }\n }\n }\n }\n\n // =============================================================\n // MINT OPERATIONS\n // =============================================================\n\n /**\n * @dev Mints `quantity` tokens and transfers them to `to`.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - `quantity` must be greater than 0.\n *\n * Emits a {Transfer} event for each mint.\n */\n function _mint(address to, uint256 quantity) internal virtual {\n uint256 startTokenId = _currentIndex;\n if (quantity == 0) revert MintZeroQuantity();\n\n _beforeTokenTransfers(address(0), to, startTokenId, quantity);\n\n // Overflows are incredibly unrealistic.\n // `balance` and `numberMinted` have a maximum limit of 2**64.\n // `tokenId` has a maximum limit of 2**256.\n unchecked {\n // Updates:\n // - `balance += quantity`.\n // - `numberMinted += quantity`.\n //\n // We can directly add to the `balance` and `numberMinted`.\n _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);\n\n // Updates:\n // - `address` to the owner.\n // - `startTimestamp` to the timestamp of minting.\n // - `burned` to `false`.\n // - `nextInitialized` to `quantity == 1`.\n _packedOwnerships[startTokenId] = _packOwnershipData(\n to,\n _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)\n );\n\n uint256 toMasked;\n uint256 end = startTokenId + quantity;\n\n // Use assembly to loop and emit the `Transfer` event for gas savings.\n // The duplicated `log4` removes an extra check and reduces stack juggling.\n // The assembly, together with the surrounding Solidity code, have been\n // delicately arranged to nudge the compiler into producing optimized opcodes.\n assembly {\n // Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.\n toMasked := and(to, _BITMASK_ADDRESS)\n // Emit the `Transfer` event.\n log4(\n 0, // Start of data (0, since no data).\n 0, // End of data (0, since no data).\n _TRANSFER_EVENT_SIGNATURE, // Signature.\n 0, // `address(0)`.\n toMasked, // `to`.\n startTokenId // `tokenId`.\n )\n\n // The `iszero(eq(,))` check ensures that large values of `quantity`\n // that overflows uint256 will make the loop run out of gas.\n // The compiler will optimize the `iszero` away for performance.\n for {\n let tokenId := add(startTokenId, 1)\n } iszero(eq(tokenId, end)) {\n tokenId := add(tokenId, 1)\n } {\n // Emit the `Transfer` event. Similar to above.\n log4(0, 0, _TRANSFER_EVENT_SIGNATURE, 0, toMasked, tokenId)\n }\n }\n if (toMasked == 0) revert MintToZeroAddress();\n\n _currentIndex = end;\n }\n _afterTokenTransfers(address(0), to, startTokenId, quantity);\n }\n\n /**\n * @dev Mints `quantity` tokens and transfers them to `to`.\n *\n * This function is intended for efficient minting only during contract creation.\n *\n * It emits only one {ConsecutiveTransfer} as defined in\n * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309),\n * instead of a sequence of {Transfer} event(s).\n *\n * Calling this function outside of contract creation WILL make your contract\n * non-compliant with the ERC721 standard.\n * For full ERC721 compliance, substituting ERC721 {Transfer} event(s) with the ERC2309\n * {ConsecutiveTransfer} event is only permissible during contract creation.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - `quantity` must be greater than 0.\n *\n * Emits a {ConsecutiveTransfer} event.\n */\n function _mintERC2309(address to, uint256 quantity) internal virtual {\n uint256 startTokenId = _currentIndex;\n if (to == address(0)) revert MintToZeroAddress();\n if (quantity == 0) revert MintZeroQuantity();\n if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) revert MintERC2309QuantityExceedsLimit();\n\n _beforeTokenTransfers(address(0), to, startTokenId, quantity);\n\n // Overflows are unrealistic due to the above check for `quantity` to be below the limit.\n unchecked {\n // Updates:\n // - `balance += quantity`.\n // - `numberMinted += quantity`.\n //\n // We can directly add to the `balance` and `numberMinted`.\n _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);\n\n // Updates:\n // - `address` to the owner.\n // - `startTimestamp` to the timestamp of minting.\n // - `burned` to `false`.\n // - `nextInitialized` to `quantity == 1`.\n _packedOwnerships[startTokenId] = _packOwnershipData(\n to,\n _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)\n );\n\n emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to);\n\n _currentIndex = startTokenId + quantity;\n }\n _afterTokenTransfers(address(0), to, startTokenId, quantity);\n }\n\n /**\n * @dev Safely mints `quantity` tokens and transfers them to `to`.\n *\n * Requirements:\n *\n * - If `to` refers to a smart contract, it must implement\n * {IERC721Receiver-onERC721Received}, which is called for each safe transfer.\n * - `quantity` must be greater than 0.\n *\n * See {_mint}.\n *\n * Emits a {Transfer} event for each mint.\n */\n function _safeMint(\n address to,\n uint256 quantity,\n bytes memory _data\n ) internal virtual {\n _mint(to, quantity);\n\n unchecked {\n if (to.code.length != 0) {\n uint256 end = _currentIndex;\n uint256 index = end - quantity;\n do {\n if (!_checkContractOnERC721Received(address(0), to, index++, _data)) {\n revert TransferToNonERC721ReceiverImplementer();\n }\n } while (index < end);\n // Reentrancy protection.\n if (_currentIndex != end) revert();\n }\n }\n }\n\n /**\n * @dev Equivalent to `_safeMint(to, quantity, '')`.\n */\n function _safeMint(address to, uint256 quantity) internal virtual {\n _safeMint(to, quantity, '');\n }\n\n // =============================================================\n // BURN OPERATIONS\n // =============================================================\n\n /**\n * @dev Equivalent to `_burn(tokenId, false)`.\n */\n function _burn(uint256 tokenId) internal virtual {\n _burn(tokenId, false);\n }\n\n /**\n * @dev Destroys `tokenId`.\n * The approval is cleared when the token is burned.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n *\n * Emits a {Transfer} event.\n */\n function _burn(uint256 tokenId, bool approvalCheck) internal virtual {\n uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);\n\n address from = address(uint160(prevOwnershipPacked));\n\n (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);\n\n if (approvalCheck) {\n // The nested ifs save around 20+ gas over a compound boolean condition.\n if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))\n if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();\n }\n\n _beforeTokenTransfers(from, address(0), tokenId, 1);\n\n // Clear approvals from the previous owner.\n assembly {\n if approvedAddress {\n // This is equivalent to `delete _tokenApprovals[tokenId]`.\n sstore(approvedAddressSlot, 0)\n }\n }\n\n // Underflow of the sender's balance is impossible because we check for\n // ownership above and the recipient's balance can't realistically overflow.\n // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.\n unchecked {\n // Updates:\n // - `balance -= 1`.\n // - `numberBurned += 1`.\n //\n // We can directly decrement the balance, and increment the number burned.\n // This is equivalent to `packed -= 1; packed += 1 << _BITPOS_NUMBER_BURNED;`.\n _packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1;\n\n // Updates:\n // - `address` to the last owner.\n // - `startTimestamp` to the timestamp of burning.\n // - `burned` to `true`.\n // - `nextInitialized` to `true`.\n _packedOwnerships[tokenId] = _packOwnershipData(\n from,\n (_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked)\n );\n\n // If the next slot may not have been initialized (i.e. `nextInitialized == false`) .\n if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {\n uint256 nextTokenId = tokenId + 1;\n // If the next slot's address is zero and not burned (i.e. packed value is zero).\n if (_packedOwnerships[nextTokenId] == 0) {\n // If the next slot is within bounds.\n if (nextTokenId != _currentIndex) {\n // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.\n _packedOwnerships[nextTokenId] = prevOwnershipPacked;\n }\n }\n }\n }\n\n emit Transfer(from, address(0), tokenId);\n _afterTokenTransfers(from, address(0), tokenId, 1);\n\n // Overflow not possible, as _burnCounter cannot be exceed _currentIndex times.\n unchecked {\n _burnCounter++;\n }\n }\n\n // =============================================================\n // EXTRA DATA OPERATIONS\n // =============================================================\n\n /**\n * @dev Directly sets the extra data for the ownership data `index`.\n */\n function _setExtraDataAt(uint256 index, uint24 extraData) internal virtual {\n uint256 packed = _packedOwnerships[index];\n if (packed == 0) revert OwnershipNotInitializedForExtraData();\n uint256 extraDataCasted;\n // Cast `extraData` with assembly to avoid redundant masking.\n assembly {\n extraDataCasted := extraData\n }\n packed = (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << _BITPOS_EXTRA_DATA);\n _packedOwnerships[index] = packed;\n }\n\n /**\n * @dev Called during each token transfer to set the 24bit `extraData` field.\n * Intended to be overridden by the cosumer contract.\n *\n * `previousExtraData` - the value of `extraData` before transfer.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\n * transferred to `to`.\n * - When `from` is zero, `tokenId` will be minted for `to`.\n * - When `to` is zero, `tokenId` will be burned by `from`.\n * - `from` and `to` are never both zero.\n */\n function _extraData(\n address from,\n address to,\n uint24 previousExtraData\n ) internal view virtual returns (uint24) {}\n\n /**\n * @dev Returns the next extra data for the packed ownership data.\n * The returned result is shifted into position.\n */\n function _nextExtraData(\n address from,\n address to,\n uint256 prevOwnershipPacked\n ) private view returns (uint256) {\n uint24 extraData = uint24(prevOwnershipPacked >> _BITPOS_EXTRA_DATA);\n return uint256(_extraData(from, to, extraData)) << _BITPOS_EXTRA_DATA;\n }\n\n // =============================================================\n // OTHER OPERATIONS\n // =============================================================\n\n /**\n * @dev Returns the message sender (defaults to `msg.sender`).\n *\n * If you are writing GSN compatible contracts, you need to override this function.\n */\n function _msgSenderERC721A() internal view virtual returns (address) {\n return msg.sender;\n }\n\n /**\n * @dev Converts a uint256 to its ASCII string decimal representation.\n */\n function _toString(uint256 value) internal pure virtual returns (string memory str) {\n assembly {\n // The maximum value of a uint256 contains 78 digits (1 byte per digit), but\n // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.\n // We will need 1 word for the trailing zeros padding, 1 word for the length,\n // and 3 words for a maximum of 78 digits. Total: 5 * 0x20 = 0xa0.\n let m := add(mload(0x40), 0xa0)\n // Update the free memory pointer to allocate.\n mstore(0x40, m)\n // Assign the `str` to the end.\n str := sub(m, 0x20)\n // Zeroize the slot after the string.\n mstore(str, 0)\n\n // Cache the end of the memory to calculate the length later.\n let end := str\n\n // We write the string from rightmost digit to leftmost digit.\n // The following is essentially a do-while loop that also handles the zero case.\n // prettier-ignore\n for { let temp := value } 1 {} {\n str := sub(str, 1)\n // Write the character to the pointer.\n // The ASCII index of the '0' character is 48.\n mstore8(str, add(48, mod(temp, 10)))\n // Keep dividing `temp` until zero.\n temp := div(temp, 10)\n // prettier-ignore\n if iszero(temp) { break }\n }\n\n let length := sub(end, str)\n // Move the pointer 32 bytes leftwards to make room for the length.\n str := sub(str, 0x20)\n // Store the length.\n mstore(str, length)\n }\n }\n}\n"
},
"erc721a/contracts/IERC721A.sol": {
"content": "// SPDX-License-Identifier: MIT\n// ERC721A Contracts v4.2.3\n// Creator: Chiru Labs\n\npragma solidity ^0.8.4;\n\n/**\n * @dev Interface of ERC721A.\n */\ninterface IERC721A {\n /**\n * The caller must own the token or be an approved operator.\n */\n error ApprovalCallerNotOwnerNorApproved();\n\n /**\n * The token does not exist.\n */\n error ApprovalQueryForNonexistentToken();\n\n /**\n * Cannot query the balance for the zero address.\n */\n error BalanceQueryForZeroAddress();\n\n /**\n * Cannot mint to the zero address.\n */\n error MintToZeroAddress();\n\n /**\n * The quantity of tokens minted must be more than zero.\n */\n error MintZeroQuantity();\n\n /**\n * The token does not exist.\n */\n error OwnerQueryForNonexistentToken();\n\n /**\n * The caller must own the token or be an approved operator.\n */\n error TransferCallerNotOwnerNorApproved();\n\n /**\n * The token must be owned by `from`.\n */\n error TransferFromIncorrectOwner();\n\n /**\n * Cannot safely transfer to a contract that does not implement the\n * ERC721Receiver interface.\n */\n error TransferToNonERC721ReceiverImplementer();\n\n /**\n * Cannot transfer to the zero address.\n */\n error TransferToZeroAddress();\n\n /**\n * The token does not exist.\n */\n error URIQueryForNonexistentToken();\n\n /**\n * The `quantity` minted with ERC2309 exceeds the safety limit.\n */\n error MintERC2309QuantityExceedsLimit();\n\n /**\n * The `extraData` cannot be set on an unintialized ownership slot.\n */\n error OwnershipNotInitializedForExtraData();\n\n // =============================================================\n // STRUCTS\n // =============================================================\n\n struct TokenOwnership {\n // The address of the owner.\n address addr;\n // Stores the start time of ownership with minimal overhead for tokenomics.\n uint64 startTimestamp;\n // Whether the token has been burned.\n bool burned;\n // Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.\n uint24 extraData;\n }\n\n // =============================================================\n // TOKEN COUNTERS\n // =============================================================\n\n /**\n * @dev Returns the total number of tokens in existence.\n * Burned tokens will reduce the count.\n * To get the total number of tokens minted, please see {_totalMinted}.\n */\n function totalSupply() external view returns (uint256);\n\n // =============================================================\n // IERC165\n // =============================================================\n\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n\n // =============================================================\n // IERC721\n // =============================================================\n\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\n * (`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 * checking first that contract recipients are aware of the ERC721 protocol\n * 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 be have been allowed to move\n * this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement\n * {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 payable;\n\n /**\n * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external payable;\n\n /**\n * @dev Transfers `tokenId` from `from` to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom}\n * whenever possible.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token\n * 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 payable;\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\n * 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 payable;\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom}\n * 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 // =============================================================\n // IERC721Metadata\n // =============================================================\n\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 // =============================================================\n // IERC2309\n // =============================================================\n\n /**\n * @dev Emitted when tokens in `fromTokenId` to `toTokenId`\n * (inclusive) is transferred from `from` to `to`, as defined in the\n * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.\n *\n * See {_mintERC2309} for more details.\n */\n event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);\n}\n"
},
"solady/src/utils/Base64.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Library to encode strings in Base64.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/Base64.sol)\n/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/Base64.sol)\n/// @author Modified from (https://github.com/Brechtpd/base64/blob/main/base64.sol) by Brecht Devos - <brecht@loopring.org>.\nlibrary Base64 {\n /// @dev Encodes `data` using the base64 encoding described in RFC 4648.\n /// See: https://datatracker.ietf.org/doc/html/rfc4648\n /// @param fileSafe Whether to replace '+' with '-' and '/' with '_'.\n /// @param noPadding Whether to strip away the padding.\n function encode(bytes memory data, bool fileSafe, bool noPadding)\n internal\n pure\n returns (string memory result)\n {\n /// @solidity memory-safe-assembly\n assembly {\n let dataLength := mload(data)\n\n if dataLength {\n // Multiply by 4/3 rounded up.\n // The `shl(2, ...)` is equivalent to multiplying by 4.\n let encodedLength := shl(2, div(add(dataLength, 2), 3))\n\n // Set `result` to point to the start of the free memory.\n result := mload(0x40)\n\n // Store the table into the scratch space.\n // Offsetted by -1 byte so that the `mload` will load the character.\n // We will rewrite the free memory pointer at `0x40` later with\n // the allocated size.\n // The magic constant 0x0230 will translate \"-_\" + \"+/\".\n mstore(0x1f, \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef\")\n mstore(0x3f, sub(\"ghijklmnopqrstuvwxyz0123456789-_\", mul(iszero(fileSafe), 0x0230)))\n\n // Skip the first slot, which stores the length.\n let ptr := add(result, 0x20)\n let end := add(ptr, encodedLength)\n\n // Run over the input, 3 bytes at a time.\n for {} 1 {} {\n data := add(data, 3) // Advance 3 bytes.\n let input := mload(data)\n\n // Write 4 bytes. Optimized for fewer stack operations.\n mstore8(ptr, mload(and(shr(18, input), 0x3F)))\n mstore8(add(ptr, 1), mload(and(shr(12, input), 0x3F)))\n mstore8(add(ptr, 2), mload(and(shr(6, input), 0x3F)))\n mstore8(add(ptr, 3), mload(and(input, 0x3F)))\n\n ptr := add(ptr, 4) // Advance 4 bytes.\n\n if iszero(lt(ptr, end)) { break }\n }\n\n let r := mod(dataLength, 3)\n\n switch noPadding\n case 0 {\n // Offset `ptr` and pad with '='. We can simply write over the end.\n mstore8(sub(ptr, iszero(iszero(r))), 0x3d) // Pad at `ptr - 1` if `r > 0`.\n mstore8(sub(ptr, shl(1, eq(r, 1))), 0x3d) // Pad at `ptr - 2` if `r == 1`.\n // Write the length of the string.\n mstore(result, encodedLength)\n }\n default {\n // Write the length of the string.\n mstore(result, sub(encodedLength, add(iszero(iszero(r)), eq(r, 1))))\n }\n\n // Allocate the memory for the string.\n // Add 31 and mask with `not(31)` to round the\n // free memory pointer up the next multiple of 32.\n mstore(0x40, and(add(end, 31), not(31)))\n }\n }\n }\n\n /// @dev Encodes `data` using the base64 encoding described in RFC 4648.\n /// Equivalent to `encode(data, false, false)`.\n function encode(bytes memory data) internal pure returns (string memory result) {\n result = encode(data, false, false);\n }\n\n /// @dev Encodes `data` using the base64 encoding described in RFC 4648.\n /// Equivalent to `encode(data, fileSafe, false)`.\n function encode(bytes memory data, bool fileSafe)\n internal\n pure\n returns (string memory result)\n {\n result = encode(data, fileSafe, false);\n }\n\n /// @dev Encodes base64 encoded `data`.\n ///\n /// Supports:\n /// - RFC 4648 (both standard and file-safe mode).\n /// - RFC 3501 (63: ',').\n ///\n /// Does not support:\n /// - Line breaks.\n ///\n /// Note: For performance reasons,\n /// this function will NOT revert on invalid `data` inputs.\n /// Outputs for invalid inputs will simply be undefined behaviour.\n /// It is the user's responsibility to ensure that the `data`\n /// is a valid base64 encoded string.\n function decode(string memory data) internal pure returns (bytes memory result) {\n /// @solidity memory-safe-assembly\n assembly {\n let dataLength := mload(data)\n\n if dataLength {\n let end := add(data, dataLength)\n let decodedLength := mul(shr(2, dataLength), 3)\n\n switch and(dataLength, 3)\n case 0 {\n // If padded.\n // forgefmt: disable-next-item\n decodedLength := sub(\n decodedLength,\n add(eq(and(mload(end), 0xFF), 0x3d), eq(and(mload(end), 0xFFFF), 0x3d3d))\n )\n }\n default {\n // If non-padded.\n decodedLength := add(decodedLength, sub(and(dataLength, 3), 1))\n }\n\n result := mload(0x40)\n\n // Write the length of the string.\n mstore(result, decodedLength)\n\n // Skip the first slot, which stores the length.\n let ptr := add(result, 0x20)\n\n // Load the table into the scratch space.\n // Constants are optimized for smaller bytecode with zero gas overhead.\n // `m` also doubles as the mask of the upper 6 bits.\n let m := 0xfc000000fc00686c7074787c8084888c9094989ca0a4a8acb0b4b8bcc0c4c8cc\n mstore(0x5b, m)\n mstore(0x3b, 0x04080c1014181c2024282c3034383c4044484c5054585c6064)\n mstore(0x1a, 0xf8fcf800fcd0d4d8dce0e4e8ecf0f4)\n\n for {} 1 {} {\n // Read 4 bytes.\n data := add(data, 4)\n let input := mload(data)\n\n // Write 3 bytes.\n // forgefmt: disable-next-item\n mstore(ptr, or(\n and(m, mload(byte(28, input))),\n shr(6, or(\n and(m, mload(byte(29, input))),\n shr(6, or(\n and(m, mload(byte(30, input))),\n shr(6, mload(byte(31, input)))\n ))\n ))\n ))\n\n ptr := add(ptr, 3)\n\n if iszero(lt(data, end)) { break }\n }\n\n // Allocate the memory for the string.\n // Add 32 + 31 and mask with `not(31)` to round the\n // free memory pointer up the next multiple of 32.\n mstore(0x40, and(add(add(result, decodedLength), 63), not(31)))\n\n // Restore the zero slot.\n mstore(0x60, 0)\n }\n }\n }\n}\n"
},
"solady/src/utils/LibPRNG.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Library for generating psuedorandom numbers.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibPRNG.sol)\nlibrary LibPRNG {\n /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n /* STRUCTS */\n /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n /// @dev A psuedorandom number state in memory.\n struct PRNG {\n uint256 state;\n }\n\n /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n /* OPERATIONS */\n /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n /// @dev Seeds the `prng` with `state`.\n function seed(PRNG memory prng, uint256 state) internal pure {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(prng, state)\n }\n }\n\n /// @dev Returns the next psuedorandom uint256.\n /// All bits of the returned uint256 pass the NIST Statistical Test Suite.\n function next(PRNG memory prng) internal pure returns (uint256 result) {\n // We simply use `keccak256` for a great balance between\n // runtime gas costs, bytecode size, and statistical properties.\n //\n // A high-quality LCG with a 32-byte state\n // is only about 30% more gas efficient during runtime,\n // but requires a 32-byte multiplier, which can cause bytecode bloat\n // when this function is inlined.\n //\n // Using this method is about 2x more efficient than\n // `nextRandomness = uint256(keccak256(abi.encode(randomness)))`.\n /// @solidity memory-safe-assembly\n assembly {\n result := keccak256(prng, 0x20)\n mstore(prng, result)\n }\n }\n\n /// @dev Returns a psuedorandom uint256, uniformly distributed\n /// between 0 (inclusive) and `upper` (exclusive).\n /// If your modulus is big, this method is recommended\n /// for uniform sampling to avoid modulo bias.\n /// For uniform sampling across all uint256 values,\n /// or for small enough moduli such that the bias is neligible,\n /// use {next} instead.\n function uniform(PRNG memory prng, uint256 upper) internal pure returns (uint256 result) {\n /// @solidity memory-safe-assembly\n assembly {\n for {} 1 {} {\n result := keccak256(prng, 0x20)\n mstore(prng, result)\n if iszero(lt(result, mod(sub(0, upper), upper))) { break }\n }\n result := mod(result, upper)\n }\n }\n\n /// @dev Shuffles the array in-place with Fisher-Yates shuffle.\n function shuffle(PRNG memory prng, uint256[] memory a) internal pure {\n /// @solidity memory-safe-assembly\n assembly {\n let n := mload(a)\n let w := not(0)\n let mask := shr(128, w)\n if n {\n for { a := add(a, 0x20) } 1 {} {\n // We can just directly use `keccak256`, cuz\n // the other approaches don't save much.\n let r := keccak256(prng, 0x20)\n mstore(prng, r)\n\n // Note that there will be a very tiny modulo bias\n // if the length of the array is not a power of 2.\n // For all practical purposes, it is negligible\n // and will not be a fairness or security concern.\n {\n let j := add(a, shl(5, mod(shr(128, r), n)))\n n := add(n, w) // `sub(n, 1)`.\n if iszero(n) { break }\n\n let i := add(a, shl(5, n))\n let t := mload(i)\n mstore(i, mload(j))\n mstore(j, t)\n }\n\n {\n let j := add(a, shl(5, mod(and(r, mask), n)))\n n := add(n, w) // `sub(n, 1)`.\n if iszero(n) { break }\n\n let i := add(a, shl(5, n))\n let t := mload(i)\n mstore(i, mload(j))\n mstore(j, t)\n }\n }\n }\n }\n }\n}\n"
}
},
"settings": {
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": true
}
}
} |