Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xB5AF0C7f3885c1007e6699c357566610291585Cb
Balance 0.000010000 ETH
Nonce 1
Code Size 9401 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

9401 bytes
0x608060405260043610610134575f3560e01c80636352211e116100aa578063a2309ff81161006e578063a2309ff8146103fd578063b88d4fde14610427578063c87b56dd14610443578063cae794e91461047f578063e985e9c5146104a9578063f3993d11146104e557610134565b80636352211e1461030957806370a0823114610345578063902d55a51461038157806395d89b41146103ab578063a22cb465146103d557610134565b806318160ddd116100fc57806318160ddd1461021257806323b872dd1461023c57806328cfbd46146102585780632a55205a1461027457806342842e0e146102b15780634f558e79146102cd57610134565b806301ffc9a714610138578063034601ec1461017457806306fdde0314610190578063081812fc146101ba578063095ea7b3146101f6575b5f80fd5b348015610143575f80fd5b5061015e60048036038101906101599190611ab0565b610501565b60405161016b9190611af5565b60405180910390f35b61018e60048036038101906101899190611ceb565b6105fa565b005b34801561019b575f80fd5b506101a4610621565b6040516101b19190611dd1565b60405180910390f35b3480156101c5575f80fd5b506101e060048036038101906101db9190611df1565b6106b1565b6040516101ed9190611e2b565b60405180910390f35b610210600480360381019061020b9190611e44565b61070a565b005b34801561021d575f80fd5b5061022661071a565b6040516102339190611e91565b60405180910390f35b61025660048036038101906102519190611eaa565b610766565b005b610272600480360381019061026d9190611faa565b6109e8565b005b34801561027f575f80fd5b5061029a60048036038101906102959190612046565b610a02565b6040516102a8929190612084565b60405180910390f35b6102cb60048036038101906102c69190611eaa565b610bdd565b005b3480156102d8575f80fd5b506102f360048036038101906102ee9190611df1565b610bfc565b6040516103009190611af5565b60405180910390f35b348015610314575f80fd5b5061032f600480360381019061032a9190611df1565b610c0d565b60405161033c9190611e2b565b60405180910390f35b348015610350575f80fd5b5061036b600480360381019061036691906120ab565b610c1e565b6040516103789190611e91565b60405180910390f35b34801561038c575f80fd5b50610395610cb2565b6040516103a29190611e91565b60405180910390f35b3480156103b6575f80fd5b506103bf610cb9565b6040516103cc9190611dd1565b60405180910390f35b3480156103e0575f80fd5b506103fb60048036038101906103f69190612100565b610d49565b005b348015610408575f80fd5b50610411610e4f565b60405161041e9190611e91565b60405180910390f35b610441600480360381019061043c919061213e565b610e5d565b005b34801561044e575f80fd5b5061046960048036038101906104649190611df1565b610eae565b6040516104769190611dd1565b60405180910390f35b34801561048a575f80fd5b50610493610f28565b6040516104a09190611e91565b60405180910390f35b3480156104b4575f80fd5b506104cf60048036038101906104ca91906121be565b610f2e565b6040516104dc9190611af5565b60405180910390f35b6104ff60048036038101906104fa9190611ceb565b610fbc565b005b5f6301ffc9a760e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061055b57506380ac58cd60e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b8061058b5750635b5e139f60e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806105f357507f2a55205a000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b9050919050565b61061c610605610fd4565b84848460405180602001604052805f815250610fdb565b505050565b60606004805461063090612229565b80601f016020809104026020016040519081016040528092919081815260200182805461065c90612229565b80156106a75780601f1061067e576101008083540402835291602001916106a7565b820191905f5260205f20905b81548152906001019060200180831161068a57829003601f168201915b5050505050905090565b5f6106bb8261105a565b6106d0576106cf63cf4700e460e01b6110fe565b5b60085f8381526020019081526020015f205f015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b61071682826001611106565b5050565b5f610723611230565b600354600254030390507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610756611234565b1461076357600a54810190505b90565b5f6107708261125b565b90505f8473ffffffffffffffffffffffffffffffffffffffff169050808273ffffffffffffffffffffffffffffffffffffffff16146107ba576107b963a114810060e01b6110fe565b5b5f806107c58561136b565b915091506107f181846107d6610fd4565b73ffffffffffffffffffffffffffffffffffffffff1661138e565b61081c5761080687610801610fd4565b610f2e565b61081b5761081a6359c896be60e01b6110fe565b5b5b610829878787600161139f565b8015610833575f82555b60075f8873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8154600190039190508190555060075f8773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8154600101919050819055506108fb866108d78989886113a5565b7c0200000000000000000000000000000000000000000000000000000000176113cc565b60065f8781526020019081526020015f20819055505f7c0200000000000000000000000000000000000000000000000000000000851603610978575f6001860190505f60065f8381526020019081526020015f205403610976576002548114610975578460065f8381526020019081526020015f20819055505b5b505b5f8673ffffffffffffffffffffffffffffffffffffffff1690508581857fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef5f80a45f81036109d1576109d063ea553b3460e01b6110fe565b5b6109de88888860016113f6565b5050505050505050565b6109fc6109f3610fd4565b85858585610fdb565b50505050565b5f805f60015f8681526020019081526020015f206040518060400160405290815f82015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020015f820160149054906101000a90046bffffffffffffffffffffffff166bffffffffffffffffffffffff166bffffffffffffffffffffffff168152505090505f73ffffffffffffffffffffffffffffffffffffffff16815f015173ffffffffffffffffffffffffffffffffffffffff1603610b8a575f6040518060400160405290815f82015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020015f820160149054906101000a90046bffffffffffffffffffffffff166bffffffffffffffffffffffff166bffffffffffffffffffffffff168152505090505b5f610b936113fc565b6bffffffffffffffffffffffff1682602001516bffffffffffffffffffffffff1686610bbf9190612286565b610bc991906122f4565b9050815f0151819350935050509250929050565b610bf783838360405180602001604052805f815250610e5d565b505050565b5f610c068261105a565b9050919050565b5f610c178261125b565b9050919050565b5f8073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610c6357610c62638f4eb60460e01b6110fe565b5b67ffffffffffffffff60075f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2054169050919050565b620186a081565b606060058054610cc890612229565b80601f0160208091040260200160405190810160405280929190818152602001828054610cf490612229565b8015610d3f5780601f10610d1657610100808354040283529160200191610d3f565b820191905f5260205f20905b815481529060010190602001808311610d2257829003601f168201915b5050505050905090565b8060095f610d55610fd4565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f6101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff16610dfe610fd4565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3183604051610e439190611af5565b60405180910390a35050565b5f610e58611405565b905090565b610e68848484610766565b5f8373ffffffffffffffffffffffffffffffffffffffff163b14610ea857610e928484848461144d565b610ea757610ea663d1a57ed660e01b6110fe565b5b5b50505050565b6060610eb98261105a565b610ece57610ecd63a14c4b5060e01b6110fe565b5b5f610ed7611577565b90505f815103610ef55760405180602001604052805f815250610f20565b80610eff84611607565b604051602001610f1092919061235e565b6040516020818303038152906040525b915050919050565b61138881565b5f60095f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900460ff16905092915050565b610fcf610fc7610fd4565b848484611656565b505050565b5f33905090565b610fe785858585611656565b5f8373ffffffffffffffffffffffffffffffffffffffff163b14611053575f80611010846119d2565b915091505b80821461105057611030868661102a856119e8565b8661144d565b6110455761104463d1a57ed660e01b6110fe565b5b602082019150611015565b50505b5050505050565b5f81611064611230565b116110f857611071611234565b8211156110995761109260065f8481526020019081526020015f20546119f2565b90506110f9565b6002548210156110f7575f5b5f60065f8581526020019081526020015f2054915081036110d157826110ca90612381565b92506110a5565b5f7c01000000000000000000000000000000000000000000000000000000008216149150505b5b5b919050565b805f5260045ffd5b5f61111083610c0d565b905081801561115257508073ffffffffffffffffffffffffffffffffffffffff16611139610fd4565b73ffffffffffffffffffffffffffffffffffffffff1614155b1561117e5761116881611163610fd4565b610f2e565b61117d5761117c63cfb3b94260e01b6110fe565b5b5b8360085f8581526020019081526020015f205f015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550828473ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a450505050565b5f90565b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff905090565b5f81611265611230565b116113555760065f8381526020019081526020015f20549050611286611234565b8211156112ab57611296816119f2565b611366576112aa63df2d9b4260e01b6110fe565b5b5f810361132d5760025482106112cc576112cb63df2d9b4260e01b6110fe565b5b5b60065f836001900393508381526020019081526020015f205490505f810315611328575f7c0100000000000000000000000000000000000000000000000000000000821603156113665761132763df2d9b4260e01b6110fe565b5b6112cd565b5f7c010000000000000000000000000000000000000000000000000000000082160315611366575b61136563df2d9b4260e01b6110fe565b5b919050565b5f805f60085f8581526020019081526020015f2090508092508254915050915091565b5f8382148383141790509392505050565b50505050565b5f8060e883901c905060e86113bb868684611a32565b62ffffff16901b9150509392505050565b5f73ffffffffffffffffffffffffffffffffffffffff83169250814260a01b178317905092915050565b50505050565b5f612710905090565b5f61140e611230565b6002540390507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff61143d611234565b1461144a57600a54810190505b90565b5f8373ffffffffffffffffffffffffffffffffffffffff1663150b7a02611472610fd4565b8786866040518563ffffffff1660e01b815260040161149494939291906123fa565b6020604051808303815f875af19250505080156114cf57506040513d601f19601f820116820180604052508101906114cc9190612458565b60015b611524573d805f81146114fd576040519150601f19603f3d011682016040523d82523d5f602084013e611502565b606091505b505f81510361151c5761151b63d1a57ed660e01b6110fe565b5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614915050949350505050565b6060600b805461158690612229565b80601f01602080910402602001604051908101604052809291908181526020018280546115b290612229565b80156115fd5780601f106115d4576101008083540402835291602001916115fd565b820191905f5260205f20905b8154815290600101906020018083116115e057829003601f168201915b5050505050905090565b606060a060405101806040526020810391505f825281835b60011561164157600184039350600a81066030018453600a810490508061161f575b50828103602084039350808452505050919050565b5f8473ffffffffffffffffffffffffffffffffffffffff1690505f8473ffffffffffffffffffffffffffffffffffffffff1690505f8473ffffffffffffffffffffffffffffffffffffffff1690505f81036116bc576116bb63ea553b3460e01b6110fe565b5b5f6116cb5f8514848614611a3a565b806116dc57506116db8789610f2e565b5b90505f8551036116ef57505050506119cc565b5f60025490505f80611700886119d2565b915091505f805b5f611711856119e8565b90505f81905061172d611722611230565b831083891115611a3a565b156117435761174263df2d9b4260e01b6110fe565b5b5f83146117635783821161176257611761639fc3da3760e01b6110fe565b5b5b5f8290505b5f60065f8381526020019081526020015f20549450840361178f5780600190039050611768565b505f7c01000000000000000000000000000000000000000000000000000000008416146117c7576117c663df2d9b4260e01b6110fe565b5b898373ffffffffffffffffffffffffffffffffffffffff16146117f5576117f463a114810060e01b6110fe565b5b5b5f806118018461136b565b915091506118128c8c86600161139f565b8961183057808d1461182f5761182e6359c896be60e01b6110fe565b5b5b801561183a575f82555b838b8d7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef5f80a48360010193508361187760208a019950896119e8565b146118835750506118ac565b8688036118915750506118ac565b50505f60065f8481526020019081526020015f2054146117f6575b6118c0896118bb8c8c876113a5565b6113cc565b60065f8381526020019081526020015f20819055505f81830390508060075f8d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f82825403925050819055508060075f8c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f82825401925050819055508783146119a6575f60065f8581526020019081526020015f2054036119a5578360065f8581526020019081526020015f20819055505b5b6119b28b8b84846113f6565b600183039450505050828403611707575050505050505050505b50505050565b5f80602083019150825160051b82019050915091565b5f81519050919050565b5f7c0100000000000000000000000000000000000000000000000000000000821673ffffffffffffffffffffffffffffffffffffffff8316119050919050565b5f9392505050565b5f81151583151517905092915050565b5f604051905090565b5f80fd5b5f80fd5b5f7fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b611a8f81611a5b565b8114611a99575f80fd5b50565b5f81359050611aaa81611a86565b92915050565b5f60208284031215611ac557611ac4611a53565b5b5f611ad284828501611a9c565b91505092915050565b5f8115159050919050565b611aef81611adb565b82525050565b5f602082019050611b085f830184611ae6565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f611b3782611b0e565b9050919050565b611b4781611b2d565b8114611b51575f80fd5b50565b5f81359050611b6281611b3e565b92915050565b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b611bb282611b6c565b810181811067ffffffffffffffff82111715611bd157611bd0611b7c565b5b80604052505050565b5f611be3611a4a565b9050611bef8282611ba9565b919050565b5f67ffffffffffffffff821115611c0e57611c0d611b7c565b5b602082029050602081019050919050565b5f80fd5b5f819050919050565b611c3581611c23565b8114611c3f575f80fd5b50565b5f81359050611c5081611c2c565b92915050565b5f611c68611c6384611bf4565b611bda565b90508083825260208201905060208402830185811115611c8b57611c8a611c1f565b5b835b81811015611cb45780611ca08882611c42565b845260208401935050602081019050611c8d565b5050509392505050565b5f82601f830112611cd257611cd1611b68565b5b8135611ce2848260208601611c56565b91505092915050565b5f805f60608486031215611d0257611d01611a53565b5b5f611d0f86828701611b54565b9350506020611d2086828701611b54565b925050604084013567ffffffffffffffff811115611d4157611d40611a57565b5b611d4d86828701611cbe565b9150509250925092565b5f81519050919050565b5f82825260208201905092915050565b5f5b83811015611d8e578082015181840152602081019050611d73565b5f8484015250505050565b5f611da382611d57565b611dad8185611d61565b9350611dbd818560208601611d71565b611dc681611b6c565b840191505092915050565b5f6020820190508181035f830152611de98184611d99565b905092915050565b5f60208284031215611e0657611e05611a53565b5b5f611e1384828501611c42565b91505092915050565b611e2581611b2d565b82525050565b5f602082019050611e3e5f830184611e1c565b92915050565b5f8060408385031215611e5a57611e59611a53565b5b5f611e6785828601611b54565b9250506020611e7885828601611c42565b9150509250929050565b611e8b81611c23565b82525050565b5f602082019050611ea45f830184611e82565b92915050565b5f805f60608486031215611ec157611ec0611a53565b5b5f611ece86828701611b54565b9350506020611edf86828701611b54565b9250506040611ef086828701611c42565b9150509250925092565b5f80fd5b5f67ffffffffffffffff821115611f1857611f17611b7c565b5b611f2182611b6c565b9050602081019050919050565b828183375f83830152505050565b5f611f4e611f4984611efe565b611bda565b905082815260208101848484011115611f6a57611f69611efa565b5b611f75848285611f2e565b509392505050565b5f82601f830112611f9157611f90611b68565b5b8135611fa1848260208601611f3c565b91505092915050565b5f805f8060808587031215611fc257611fc1611a53565b5b5f611fcf87828801611b54565b9450506020611fe087828801611b54565b935050604085013567ffffffffffffffff81111561200157612000611a57565b5b61200d87828801611cbe565b925050606085013567ffffffffffffffff81111561202e5761202d611a57565b5b61203a87828801611f7d565b91505092959194509250565b5f806040838503121561205c5761205b611a53565b5b5f61206985828601611c42565b925050602061207a85828601611c42565b9150509250929050565b5f6040820190506120975f830185611e1c565b6120a46020830184611e82565b9392505050565b5f602082840312156120c0576120bf611a53565b5b5f6120cd84828501611b54565b91505092915050565b6120df81611adb565b81146120e9575f80fd5b50565b5f813590506120fa816120d6565b92915050565b5f806040838503121561211657612115611a53565b5b5f61212385828601611b54565b9250506020612134858286016120ec565b9150509250929050565b5f805f806080858703121561215657612155611a53565b5b5f61216387828801611b54565b945050602061217487828801611b54565b935050604061218587828801611c42565b925050606085013567ffffffffffffffff8111156121a6576121a5611a57565b5b6121b287828801611f7d565b91505092959194509250565b5f80604083850312156121d4576121d3611a53565b5b5f6121e185828601611b54565b92505060206121f285828601611b54565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f600282049050600182168061224057607f821691505b602082108103612253576122526121fc565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61229082611c23565b915061229b83611c23565b92508282026122a981611c23565b915082820484148315176122c0576122bf612259565b5b5092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f6122fe82611c23565b915061230983611c23565b925082612319576123186122c7565b5b828204905092915050565b5f81905092915050565b5f61233882611d57565b6123428185612324565b9350612352818560208601611d71565b80840191505092915050565b5f612369828561232e565b9150612375828461232e565b91508190509392505050565b5f61238b82611c23565b91505f820361239d5761239c612259565b5b600182039050919050565b5f81519050919050565b5f82825260208201905092915050565b5f6123cc826123a8565b6123d681856123b2565b93506123e6818560208601611d71565b6123ef81611b6c565b840191505092915050565b5f60808201905061240d5f830187611e1c565b61241a6020830186611e1c565b6124276040830185611e82565b818103606083015261243981846123c2565b905095945050505050565b5f8151905061245281611a86565b92915050565b5f6020828403121561246d5761246c611a53565b5b5f61247a84828501612444565b9150509291505056fea2646970667358221220cb3b59d8f72b2cb12777f4475b358f900cfde9ef285ab5718307b08dd256913764736f6c63430008150033

Verified Source Code Full Match

Compiler: v0.8.21+commit.d9974bed EVM: shanghai Optimization: No
ERC721A.sol 1583 lines
// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.3.0
// Creator: Chiru Labs

pragma solidity ^0.8.4;

import './IERC721A.sol';

/**
 * @dev Interface of ERC721 token receiver.
 */
interface ERC721A__IERC721Receiver {
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

/**
 * @title ERC721A
 *
 * @dev Implementation of the [ERC721](https://eips.ethereum.org/EIPS/eip-721)
 * Non-Fungible Token Standard, including the Metadata extension.
 * Optimized for lower gas during batch mints.
 *
 * Token IDs are minted in sequential order (e.g. 0, 1, 2, 3, ...)
 * starting from `_startTokenId()`.
 *
 * The `_sequentialUpTo()` function can be overriden to enable spot mints
 * (i.e. non-consecutive mints) for `tokenId`s greater than `_sequentialUpTo()`.
 *
 * Assumptions:
 *
 * - An owner cannot have more than 2**64 - 1 (max value of uint64) of supply.
 * - The maximum token ID cannot exceed 2**256 - 1 (max value of uint256).
 */
contract ERC721A is IERC721A {
    // Bypass for a `--via-ir` bug (https://github.com/chiru-labs/ERC721A/pull/364).
    struct TokenApprovalRef {
        address value;
    }

    // =============================================================
    //                           CONSTANTS
    // =============================================================

    // Mask of an entry in packed address data.
    uint256 private constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;

    // The bit position of `numberMinted` in packed address data.
    uint256 private constant _BITPOS_NUMBER_MINTED = 64;

    // The bit position of `numberBurned` in packed address data.
    uint256 private constant _BITPOS_NUMBER_BURNED = 128;

    // The bit position of `aux` in packed address data.
    uint256 private constant _BITPOS_AUX = 192;

    // Mask of all 256 bits in packed address data except the 64 bits for `aux`.
    uint256 private constant _BITMASK_AUX_COMPLEMENT = (1 << 192) - 1;

    // The bit position of `startTimestamp` in packed ownership.
    uint256 private constant _BITPOS_START_TIMESTAMP = 160;

    // The bit mask of the `burned` bit in packed ownership.
    uint256 private constant _BITMASK_BURNED = 1 << 224;

    // The bit position of the `nextInitialized` bit in packed ownership.
    uint256 private constant _BITPOS_NEXT_INITIALIZED = 225;

    // The bit mask of the `nextInitialized` bit in packed ownership.
    uint256 private constant _BITMASK_NEXT_INITIALIZED = 1 << 225;

    // The bit position of `extraData` in packed ownership.
    uint256 private constant _BITPOS_EXTRA_DATA = 232;

    // Mask of all 256 bits in a packed ownership except the 24 bits for `extraData`.
    uint256 private constant _BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1;

    // The mask of the lower 160 bits for addresses.
    uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;

    // The maximum `quantity` that can be minted with {_mintERC2309}.
    // This limit is to prevent overflows on the address data entries.
    // For a limit of 5000, a total of 3.689e15 calls to {_mintERC2309}
    // is required to cause an overflow, which is unrealistic.
    uint256 private constant _MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;

    // The `Transfer` event signature is given by:
    // `keccak256(bytes("Transfer(address,address,uint256)"))`.
    bytes32 private constant _TRANSFER_EVENT_SIGNATURE =
        0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;

    // =============================================================
    //                            STORAGE
    // =============================================================

    // The next token ID to be minted.
    uint256 private _currentIndex;

    // The number of tokens burned.
    uint256 private _burnCounter;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to ownership details
    // An empty struct value does not necessarily mean the token is unowned.
    // See {_packedOwnershipOf} implementation for details.
    //
    // Bits Layout:
    // - [0..159]   `addr`
    // - [160..223] `startTimestamp`
    // - [224]      `burned`
    // - [225]      `nextInitialized`
    // - [232..255] `extraData`
    mapping(uint256 => uint256) private _packedOwnerships;

    // Mapping owner address to address data.
    //
    // Bits Layout:
    // - [0..63]    `balance`
    // - [64..127]  `numberMinted`
    // - [128..191] `numberBurned`
    // - [192..255] `aux`
    mapping(address => uint256) private _packedAddressData;

    // Mapping from token ID to approved address.
    mapping(uint256 => TokenApprovalRef) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    // The amount of tokens minted above `_sequentialUpTo()`.
    // We call these spot mints (i.e. non-sequential mints).
    uint256 private _spotMinted;

    // =============================================================
    //                          CONSTRUCTOR
    // =============================================================

    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
        _currentIndex = _startTokenId();

        if (_sequentialUpTo() < _startTokenId()) _revert(SequentialUpToTooSmall.selector);
    }

    // =============================================================
    //                   TOKEN COUNTING OPERATIONS
    // =============================================================

    /**
     * @dev Returns the starting token ID for sequential mints.
     *
     * Override this function to change the starting token ID for sequential mints.
     *
     * Note: The value returned must never change after any tokens have been minted.
     */
    function _startTokenId() internal view virtual returns (uint256) {
        return 0;
    }

    /**
     * @dev Returns the maximum token ID (inclusive) for sequential mints.
     *
     * Override this function to return a value less than 2**256 - 1,
     * but greater than `_startTokenId()`, to enable spot (non-sequential) mints.
     *
     * Note: The value returned must never change after any tokens have been minted.
     */
    function _sequentialUpTo() internal view virtual returns (uint256) {
        return type(uint256).max;
    }

    /**
     * @dev Returns the next token ID to be minted.
     */
    function _nextTokenId() internal view virtual returns (uint256) {
        return _currentIndex;
    }

    /**
     * @dev Returns the total number of tokens in existence.
     * Burned tokens will reduce the count.
     * To get the total number of tokens minted, please see {_totalMinted}.
     */
    function totalSupply() public view virtual override returns (uint256 result) {
        // Counter underflow is impossible as `_burnCounter` cannot be incremented
        // more than `_currentIndex + _spotMinted - _startTokenId()` times.
        unchecked {
            // With spot minting, the intermediate `result` can be temporarily negative,
            // and the computation must be unchecked.
            result = _currentIndex - _burnCounter - _startTokenId();
            if (_sequentialUpTo() != type(uint256).max) result += _spotMinted;
        }
    }

    /**
     * @dev Returns the total amount of tokens minted in the contract.
     */
    function _totalMinted() internal view virtual returns (uint256 result) {
        // Counter underflow is impossible as `_currentIndex` does not decrement,
        // and it is initialized to `_startTokenId()`.
        unchecked {
            result = _currentIndex - _startTokenId();
            if (_sequentialUpTo() != type(uint256).max) result += _spotMinted;
        }
    }

    /**
     * @dev Returns the total number of tokens burned.
     */
    function _totalBurned() internal view virtual returns (uint256) {
        return _burnCounter;
    }

    /**
     * @dev Returns the total number of tokens that are spot-minted.
     */
    function _totalSpotMinted() internal view virtual returns (uint256) {
        return _spotMinted;
    }

    // =============================================================
    //                    ADDRESS DATA OPERATIONS
    // =============================================================

    /**
     * @dev Returns the number of tokens in `owner`'s account.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        if (owner == address(0)) _revert(BalanceQueryForZeroAddress.selector);
        return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY;
    }

    /**
     * Returns the number of tokens minted by `owner`.
     */
    function _numberMinted(address owner) internal view returns (uint256) {
        return (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & _BITMASK_ADDRESS_DATA_ENTRY;
    }

    /**
     * Returns the number of tokens burned by or on behalf of `owner`.
     */
    function _numberBurned(address owner) internal view returns (uint256) {
        return (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & _BITMASK_ADDRESS_DATA_ENTRY;
    }

    /**
     * Returns the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).
     */
    function _getAux(address owner) internal view returns (uint64) {
        return uint64(_packedAddressData[owner] >> _BITPOS_AUX);
    }

    /**
     * Sets the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).
     * If there are multiple variables, please pack them into a uint64.
     */
    function _setAux(address owner, uint64 aux) internal virtual {
        uint256 packed = _packedAddressData[owner];
        uint256 auxCasted;
        // Cast `aux` with assembly to avoid redundant masking.
        assembly {
            auxCasted := aux
        }
        packed = (packed & _BITMASK_AUX_COMPLEMENT) | (auxCasted << _BITPOS_AUX);
        _packedAddressData[owner] = packed;
    }

    // =============================================================
    //                            IERC165
    // =============================================================

    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30000 gas.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        // The interface IDs are constants representing the first 4 bytes
        // of the XOR of all function selectors in the interface.
        // See: [ERC165](https://eips.ethereum.org/EIPS/eip-165)
        // (e.g. `bytes4(i.functionA.selector ^ i.functionB.selector ^ ...)`)
        return
            interfaceId == 0x01ffc9a7 || // ERC165 interface ID for ERC165.
            interfaceId == 0x80ac58cd || // ERC165 interface ID for ERC721.
            interfaceId == 0x5b5e139f; // ERC165 interface ID for ERC721Metadata.
    }

    // =============================================================
    //                        IERC721Metadata
    // =============================================================

    /**
     * @dev Returns the token collection name.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        if (!_exists(tokenId)) _revert(URIQueryForNonexistentToken.selector);

        string memory baseURI = _baseURI();
        return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : '';
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, it can be overridden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return '';
    }

    // =============================================================
    //                     OWNERSHIPS OPERATIONS
    // =============================================================

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        return address(uint160(_packedOwnershipOf(tokenId)));
    }

    /**
     * @dev Gas spent here starts off proportional to the maximum mint batch size.
     * It gradually moves to O(1) as tokens get transferred around over time.
     */
    function _ownershipOf(uint256 tokenId) internal view virtual returns (TokenOwnership memory) {
        return _unpackedOwnership(_packedOwnershipOf(tokenId));
    }

    /**
     * @dev Returns the unpacked `TokenOwnership` struct at `index`.
     */
    function _ownershipAt(uint256 index) internal view virtual returns (TokenOwnership memory) {
        return _unpackedOwnership(_packedOwnerships[index]);
    }

    /**
     * @dev Returns whether the ownership slot at `index` is initialized.
     * An uninitialized slot does not necessarily mean that the slot has no owner.
     */
    function _ownershipIsInitialized(uint256 index) internal view virtual returns (bool) {
        return _packedOwnerships[index] != 0;
    }

    /**
     * @dev Initializes the ownership slot minted at `index` for efficiency purposes.
     */
    function _initializeOwnershipAt(uint256 index) internal virtual {
        if (_packedOwnerships[index] == uint256(0)) {
            _packedOwnerships[index] = _packedOwnershipOf(index);
        }
    }

    /**
     * @dev Returns the packed ownership data of `tokenId`.
     */
    function _packedOwnershipOf(uint256 tokenId) private view returns (uint256 packed) {
        if (_startTokenId() <= tokenId) {
            packed = _packedOwnerships[tokenId];

            if (tokenId > _sequentialUpTo()) {
                if (_packedOwnershipExists(packed)) return packed;
                _revert(OwnerQueryForNonexistentToken.selector);
            }

            // If the data at the starting slot does not exist, start the scan.
            if (packed == uint256(0)) {
                if (tokenId >= _currentIndex) _revert(OwnerQueryForNonexistentToken.selector);
                // Invariant:
                // There will always be an initialized ownership slot
                // (i.e. `ownership.addr != address(0) && ownership.burned == false`)
                // before an unintialized ownership slot
                // (i.e. `ownership.addr == address(0) && ownership.burned == false`)
                // Hence, `tokenId` will not underflow.
                //
                // We can directly compare the packed value.
                // If the address is zero, packed will be zero.
                for (;;) {
                    unchecked {
                        packed = _packedOwnerships[--tokenId];
                    }
                    if (packed == uint256(0)) continue;
                    if (packed & _BITMASK_BURNED == uint256(0)) return packed;
                    // Otherwise, the token is burned, and we must revert.
                    // This handles the case of batch burned tokens, where only the burned bit
                    // of the starting slot is set, and remaining slots are left uninitialized.
                    _revert(OwnerQueryForNonexistentToken.selector);
                }
            }
            // Otherwise, the data exists and we can skip the scan.
            // This is possible because we have already achieved the target condition.
            // This saves 2143 gas on transfers of initialized tokens.
            // If the token is not burned, return `packed`. Otherwise, revert.
            if (packed & _BITMASK_BURNED == uint256(0)) return packed;
        }
        _revert(OwnerQueryForNonexistentToken.selector);
    }

    /**
     * @dev Returns the unpacked `TokenOwnership` struct from `packed`.
     */
    function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) {
        ownership.addr = address(uint160(packed));
        ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP);
        ownership.burned = packed & _BITMASK_BURNED != 0;
        ownership.extraData = uint24(packed >> _BITPOS_EXTRA_DATA);
    }

    /**
     * @dev Packs ownership data into a single uint256.
     */
    function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) {
        assembly {
            // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.
            owner := and(owner, _BITMASK_ADDRESS)
            // `owner | (block.timestamp << _BITPOS_START_TIMESTAMP) | flags`.
            result := or(owner, or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags))
        }
    }

    /**
     * @dev Returns the `nextInitialized` flag set if `quantity` equals 1.
     */
    function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) {
        // For branchless setting of the `nextInitialized` flag.
        assembly {
            // `(quantity == 1) << _BITPOS_NEXT_INITIALIZED`.
            result := shl(_BITPOS_NEXT_INITIALIZED, eq(quantity, 1))
        }
    }

    // =============================================================
    //                      APPROVAL OPERATIONS
    // =============================================================

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account. See {ERC721A-_approve}.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     */
    function approve(address to, uint256 tokenId) public payable virtual override {
        _approve(to, tokenId, true);
    }

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        if (!_exists(tokenId)) _revert(ApprovalQueryForNonexistentToken.selector);

        return _tokenApprovals[tokenId].value;
    }

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom}
     * for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _operatorApprovals[_msgSenderERC721A()][operator] = approved;
        emit ApprovalForAll(_msgSenderERC721A(), operator, approved);
    }

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted. See {_mint}.
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool result) {
        if (_startTokenId() <= tokenId) {
            if (tokenId > _sequentialUpTo()) return _packedOwnershipExists(_packedOwnerships[tokenId]);

            if (tokenId < _currentIndex) {
                uint256 packed;
                while ((packed = _packedOwnerships[tokenId]) == uint256(0)) --tokenId;
                result = packed & _BITMASK_BURNED == uint256(0);
            }
        }
    }

    /**
     * @dev Returns whether `packed` represents a token that exists.
     */
    function _packedOwnershipExists(uint256 packed) private pure returns (bool result) {
        assembly {
            // The following is equivalent to `owner != address(0) && burned == false`.
            // Symbolically tested.
            result := gt(and(packed, _BITMASK_ADDRESS), and(packed, _BITMASK_BURNED))
        }
    }

    /**
     * @dev Returns whether `msgSender` is equal to `approvedAddress` or `owner`.
     */
    function _isSenderApprovedOrOwner(
        uint256 approvedAddressValue,
        uint256 ownerMasked,
        uint256 msgSenderMasked
    ) private pure returns (bool result) {
        assembly {
            result := or(eq(msgSenderMasked, ownerMasked), eq(msgSenderMasked, approvedAddressValue))
        }
    }

    /**
     * @dev Returns the storage slot and value for the approved address of `tokenId` casted to a uint256.
     */
    function _getApprovedSlotAndValue(uint256 tokenId)
        private
        view
        returns (uint256 approvedAddressSlot, uint256 approvedAddressValue)
    {
        TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId];
        // The following is equivalent to `approvedAddressValue = uint160(_tokenApprovals[tokenId].value)`.
        assembly {
            approvedAddressSlot := tokenApproval.slot
            approvedAddressValue := sload(approvedAddressSlot)
        }
    }

    // =============================================================
    //                      TRANSFER OPERATIONS
    // =============================================================

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token
     * by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public payable virtual override {
        uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);
        uint256 fromMasked = uint160(from);

        if (uint160(prevOwnershipPacked) != fromMasked) _revert(TransferFromIncorrectOwner.selector);

        (uint256 approvedAddressSlot, uint256 approvedAddressValue) = _getApprovedSlotAndValue(tokenId);

        // The nested ifs save around 20+ gas over a compound boolean condition.
        if (!_isSenderApprovedOrOwner(approvedAddressValue, fromMasked, uint160(_msgSenderERC721A())))
            if (!isApprovedForAll(from, _msgSenderERC721A())) _revert(TransferCallerNotOwnerNorApproved.selector);

        _beforeTokenTransfers(from, to, tokenId, 1);

        assembly {
            if approvedAddressValue {
                sstore(approvedAddressSlot, 0) // Equivalent to `delete _tokenApprovals[tokenId]`.
            }
        }

        // Underflow of the sender's balance is impossible because we check for
        // ownership above and the recipient's balance can't realistically overflow.
        // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.
        unchecked {
            // We can directly increment and decrement the balances.
            --_packedAddressData[from]; // Updates: `balance -= 1`.
            ++_packedAddressData[to]; // Updates: `balance += 1`.

            // Updates:
            // - `address` to the next owner.
            // - `startTimestamp` to the timestamp of transfering.
            // - `burned` to `false`.
            // - `nextInitialized` to `true`.
            _packedOwnerships[tokenId] = _packOwnershipData(
                to,
                _BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked)
            );

            // If the next slot may not have been initialized (i.e. `nextInitialized == false`) .
            if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == uint256(0)) {
                uint256 nextTokenId = tokenId + 1;
                // If the next slot's address is zero and not burned (i.e. packed value is zero).
                if (_packedOwnerships[nextTokenId] == uint256(0)) {
                    // If the next slot is within bounds.
                    if (nextTokenId != _currentIndex) {
                        // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.
                        _packedOwnerships[nextTokenId] = prevOwnershipPacked;
                    }
                }
            }
        }

        // Mask to the lower 160 bits, in case the upper bits somehow aren't clean.
        uint256 toMasked = uint160(to);
        assembly {
            // Emit the `Transfer` event.
            log4(
                0, // Start of data (0, since no data).
                0, // End of data (0, since no data).
                _TRANSFER_EVENT_SIGNATURE, // Signature.
                fromMasked, // `from`.
                toMasked, // `to`.
                tokenId // `tokenId`.
            )
        }
        if (toMasked == uint256(0)) _revert(TransferToZeroAddress.selector);

        _afterTokenTransfers(from, to, tokenId, 1);
    }

    /**
     * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public payable virtual override {
        safeTransferFrom(from, to, tokenId, '');
    }

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token
     * by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement
     * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) public payable virtual override {
        transferFrom(from, to, tokenId);
        if (to.code.length != 0)
            if (!_checkContractOnERC721Received(from, to, tokenId, _data)) {
                _revert(TransferToNonERC721ReceiverImplementer.selector);
            }
    }

    /**
     * @dev Equivalent to `_batchTransferFrom(from, to, tokenIds)`.
     */
    function _batchTransferFrom(
        address from,
        address to,
        uint256[] memory tokenIds
    ) internal virtual {
        _batchTransferFrom(address(0), from, to, tokenIds);
    }

    /**
     * @dev Transfers `tokenIds` in batch from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenIds` tokens must be owned by `from`.
     * - `tokenIds` must be strictly ascending.
     * - If `by` is not `from`, it must be approved to move these tokens
     * by either {approve} or {setApprovalForAll}.
     *
     * `by` is the address that to check token approval for.
     * If token approval check is not needed, pass in `address(0)` for `by`.
     *
     * Emits a {Transfer} event for each transfer.
     */
    function _batchTransferFrom(
        address by,
        address from,
        address to,
        uint256[] memory tokenIds
    ) internal virtual {
        uint256 byMasked = uint160(by);
        uint256 fromMasked = uint160(from);
        uint256 toMasked = uint160(to);
        // Disallow transfer to zero address.
        if (toMasked == uint256(0)) _revert(TransferToZeroAddress.selector);
        // Whether `by` may transfer the tokens.
        bool mayTransfer = _orERC721A(byMasked == uint256(0), byMasked == fromMasked) || isApprovedForAll(from, by);

        // Early return if `tokenIds` is empty.
        if (tokenIds.length == uint256(0)) return;
        // The next `tokenId` to be minted (i.e. `_nextTokenId()`).
        uint256 end = _currentIndex;
        // Pointer to start and end (exclusive) of `tokenIds`.
        (uint256 ptr, uint256 ptrEnd) = _mdataERC721A(tokenIds);

        uint256 prevTokenId;
        uint256 prevOwnershipPacked;
        unchecked {
            do {
                uint256 tokenId = _mloadERC721A(ptr);
                uint256 miniBatchStart = tokenId;
                // Revert `tokenId` is out of bounds.
                if (_orERC721A(tokenId < _startTokenId(), end <= tokenId))
                    _revert(OwnerQueryForNonexistentToken.selector);
                // Revert if `tokenIds` is not strictly ascending.
                if (prevOwnershipPacked != 0)
                    if (tokenId <= prevTokenId) _revert(TokenIdsNotStrictlyAscending.selector);
                // Scan backwards for an initialized packed ownership slot.
                // ERC721A's invariant guarantees that there will always be an initialized slot as long as
                // the start of the backwards scan falls within `[_startTokenId() .. _nextTokenId())`.
                for (uint256 j = tokenId; (prevOwnershipPacked = _packedOwnerships[j]) == uint256(0); ) --j;
                // If the initialized slot is burned, revert.
                if (prevOwnershipPacked & _BITMASK_BURNED != 0) _revert(OwnerQueryForNonexistentToken.selector);
                // Check that `tokenId` is owned by `from`.
                if (uint160(prevOwnershipPacked) != fromMasked) _revert(TransferFromIncorrectOwner.selector);

                do {
                    (uint256 approvedAddressSlot, uint256 approvedAddressValue) = _getApprovedSlotAndValue(tokenId);
                    _beforeTokenTransfers(address(uint160(fromMasked)), address(uint160(toMasked)), tokenId, 1);
                    // Revert if the sender is not authorized to transfer the token.
                    if (!mayTransfer)
                        if (byMasked != approvedAddressValue) _revert(TransferCallerNotOwnerNorApproved.selector);
                    assembly {
                        if approvedAddressValue {
                            sstore(approvedAddressSlot, 0) // Equivalent to `delete _tokenApprovals[tokenId]`.
                        }
                        // Emit the `Transfer` event.
                        log4(0, 0, _TRANSFER_EVENT_SIGNATURE, fromMasked, toMasked, tokenId)
                    }

                    if (_mloadERC721A(ptr += 0x20) != ++tokenId) break;
                    if (ptr == ptrEnd) break;
                } while (_packedOwnerships[tokenId] == uint256(0));

                // Updates tokenId:
                // - `address` to the next owner.
                // - `startTimestamp` to the timestamp of transferring.
                // - `burned` to `false`.
                // - `nextInitialized` to `false`, as it is optional.
                _packedOwnerships[miniBatchStart] = _packOwnershipData(
                    address(uint160(toMasked)),
                    _nextExtraData(address(uint160(fromMasked)), address(uint160(toMasked)), prevOwnershipPacked)
                );
                uint256 miniBatchLength = tokenId - miniBatchStart;
                // Update the address data.
                _packedAddressData[address(uint160(fromMasked))] -= miniBatchLength;
                _packedAddressData[address(uint160(toMasked))] += miniBatchLength;
                // Initialize the next slot if needed.
                if (tokenId != end)
                    if (_packedOwnerships[tokenId] == uint256(0)) _packedOwnerships[tokenId] = prevOwnershipPacked;
                // Perform the after hook for the batch.
                _afterTokenTransfers(
                    address(uint160(fromMasked)),
                    address(uint160(toMasked)),
                    miniBatchStart,
                    miniBatchLength
                );
                // Set the `prevTokenId` for checking that the `tokenIds` is strictly ascending.
                prevTokenId = tokenId - 1;
            } while (ptr != ptrEnd);
        }
    }

    /**
     * @dev Safely transfers `tokenIds` in batch from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenIds` tokens must be owned by `from`.
     * - If `by` is not `from`, it must be approved to move these tokens
     * by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement
     * {IERC721Receiver-onERC721Received}, which is called for each transferred token.
     *
     * `by` is the address that to check token approval for.
     * If token approval check is not needed, pass in `address(0)` for `by`.
     *
     * Emits a {Transfer} event for each transfer.
     */
    function _safeBatchTransferFrom(
        address by,
        address from,
        address to,
        uint256[] memory tokenIds,
        bytes memory _data
    ) internal virtual {
        _batchTransferFrom(by, from, to, tokenIds);

        unchecked {
            if (to.code.length != 0) {
                for ((uint256 ptr, uint256 ptrEnd) = _mdataERC721A(tokenIds); ptr != ptrEnd; ptr += 0x20) {
                    if (!_checkContractOnERC721Received(from, to, _mloadERC721A(ptr), _data)) {
                        _revert(TransferToNonERC721ReceiverImplementer.selector);
                    }
                }
            }
        }
    }

    /**
     * @dev Hook that is called before a set of serially-ordered token IDs
     * are about to be transferred. This includes minting.
     * And also called before burning one token.
     *
     * `startTokenId` - the first token ID to be transferred.
     * `quantity` - the amount to be transferred.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, `tokenId` will be burned by `from`.
     * - `from` and `to` are never both zero.
     */
    function _beforeTokenTransfers(
        address from,
        address to,
        uint256 startTokenId,
        uint256 quantity
    ) internal virtual {}

    /**
     * @dev Hook that is called after a set of serially-ordered token IDs
     * have been transferred. This includes minting.
     * And also called after one token has been burned.
     *
     * `startTokenId` - the first token ID to be transferred.
     * `quantity` - the amount to be transferred.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been
     * transferred to `to`.
     * - When `from` is zero, `tokenId` has been minted for `to`.
     * - When `to` is zero, `tokenId` has been burned by `from`.
     * - `from` and `to` are never both zero.
     */
    function _afterTokenTransfers(
        address from,
        address to,
        uint256 startTokenId,
        uint256 quantity
    ) internal virtual {}

    /**
     * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target contract.
     *
     * `from` - Previous owner of the given token ID.
     * `to` - Target address that will receive the token.
     * `tokenId` - Token ID to be transferred.
     * `_data` - Optional data to send along with the call.
     *
     * Returns whether the call correctly returned the expected magic value.
     */
    function _checkContractOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) private returns (bool) {
        try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns (
            bytes4 retval
        ) {
            return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector;
        } catch (bytes memory reason) {
            if (reason.length == uint256(0)) {
                _revert(TransferToNonERC721ReceiverImplementer.selector);
            }
            assembly {
                revert(add(32, reason), mload(reason))
            }
        }
    }

    // =============================================================
    //                        MINT OPERATIONS
    // =============================================================

    /**
     * @dev Mints `quantity` tokens and transfers them to `to`.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `quantity` must be greater than 0.
     *
     * Emits a {Transfer} event for each mint.
     */
    function _mint(address to, uint256 quantity) internal virtual {
        uint256 startTokenId = _currentIndex;
        if (quantity == uint256(0)) _revert(MintZeroQuantity.selector);

        _beforeTokenTransfers(address(0), to, startTokenId, quantity);

        // Overflows are incredibly unrealistic.
        // `balance` and `numberMinted` have a maximum limit of 2**64.
        // `tokenId` has a maximum limit of 2**256.
        unchecked {
            // Updates:
            // - `address` to the owner.
            // - `startTimestamp` to the timestamp of minting.
            // - `burned` to `false`.
            // - `nextInitialized` to `quantity == 1`.
            _packedOwnerships[startTokenId] = _packOwnershipData(
                to,
                _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)
            );

            // Updates:
            // - `balance += quantity`.
            // - `numberMinted += quantity`.
            //
            // We can directly add to the `balance` and `numberMinted`.
            _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);

            // Mask to the lower 160 bits, in case the upper bits somehow aren't clean.
            uint256 toMasked = uint160(to);

            if (toMasked == uint256(0)) _revert(MintToZeroAddress.selector);

            uint256 end = startTokenId + quantity;
            uint256 tokenId = startTokenId;

            if (end - 1 > _sequentialUpTo()) _revert(SequentialMintExceedsLimit.selector);

            do {
                assembly {
                    // Emit the `Transfer` event.
                    log4(
                        0, // Start of data (0, since no data).
                        0, // End of data (0, since no data).
                        _TRANSFER_EVENT_SIGNATURE, // Signature.
                        0, // `address(0)`.
                        toMasked, // `to`.
                        tokenId // `tokenId`.
                    )
                }
                // The `!=` check ensures that large values of `quantity`
                // that overflows uint256 will make the loop run out of gas.
            } while (++tokenId != end);

            _currentIndex = end;
        }
        _afterTokenTransfers(address(0), to, startTokenId, quantity);
    }

    /**
     * @dev Mints `quantity` tokens and transfers them to `to`.
     *
     * This function is intended for efficient minting only during contract creation.
     *
     * It emits only one {ConsecutiveTransfer} as defined in
     * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309),
     * instead of a sequence of {Transfer} event(s).
     *
     * Calling this function outside of contract creation WILL make your contract
     * non-compliant with the ERC721 standard.
     * For full ERC721 compliance, substituting ERC721 {Transfer} event(s) with the ERC2309
     * {ConsecutiveTransfer} event is only permissible during contract creation.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `quantity` must be greater than 0.
     *
     * Emits a {ConsecutiveTransfer} event.
     */
    function _mintERC2309(address to, uint256 quantity) internal virtual {
        uint256 startTokenId = _currentIndex;
        if (to == address(0)) _revert(MintToZeroAddress.selector);
        if (quantity == uint256(0)) _revert(MintZeroQuantity.selector);
        if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) _revert(MintERC2309QuantityExceedsLimit.selector);

        _beforeTokenTransfers(address(0), to, startTokenId, quantity);

        // Overflows are unrealistic due to the above check for `quantity` to be below the limit.
        unchecked {
            // Updates:
            // - `balance += quantity`.
            // - `numberMinted += quantity`.
            //
            // We can directly add to the `balance` and `numberMinted`.
            _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);

            // Updates:
            // - `address` to the owner.
            // - `startTimestamp` to the timestamp of minting.
            // - `burned` to `false`.
            // - `nextInitialized` to `quantity == 1`.
            _packedOwnerships[startTokenId] = _packOwnershipData(
                to,
                _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)
            );

            if (startTokenId + quantity - 1 > _sequentialUpTo()) _revert(SequentialMintExceedsLimit.selector);

            emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to);

            _currentIndex = startTokenId + quantity;
        }
        _afterTokenTransfers(address(0), to, startTokenId, quantity);
    }

    /**
     * @dev Safely mints `quantity` tokens and transfers them to `to`.
     *
     * Requirements:
     *
     * - If `to` refers to a smart contract, it must implement
     * {IERC721Receiver-onERC721Received}, which is called for each safe transfer.
     * - `quantity` must be greater than 0.
     *
     * See {_mint}.
     *
     * Emits a {Transfer} event for each mint.
     */
    function _safeMint(
        address to,
        uint256 quantity,
        bytes memory _data
    ) internal virtual {
        _mint(to, quantity);

        unchecked {
            if (to.code.length != 0) {
                uint256 end = _currentIndex;
                uint256 index = end - quantity;
                do {
                    if (!_checkContractOnERC721Received(address(0), to, index++, _data)) {
                        _revert(TransferToNonERC721ReceiverImplementer.selector);
                    }
                } while (index < end);
                // This prevents reentrancy to `_safeMint`.
                // It does not prevent reentrancy to `_safeMintSpot`.
                if (_currentIndex != end) revert();
            }
        }
    }

    /**
     * @dev Equivalent to `_safeMint(to, quantity, '')`.
     */
    function _safeMint(address to, uint256 quantity) internal virtual {
        _safeMint(to, quantity, '');
    }

    /**
     * @dev Mints a single token at `tokenId`.
     *
     * Note: A spot-minted `tokenId` that has been burned can be re-minted again.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` must be greater than `_sequentialUpTo()`.
     * - `tokenId` must not exist.
     *
     * Emits a {Transfer} event for each mint.
     */
    function _mintSpot(address to, uint256 tokenId) internal virtual {
        if (tokenId <= _sequentialUpTo()) _revert(SpotMintTokenIdTooSmall.selector);
        uint256 prevOwnershipPacked = _packedOwnerships[tokenId];
        if (_packedOwnershipExists(prevOwnershipPacked)) _revert(TokenAlreadyExists.selector);

        _beforeTokenTransfers(address(0), to, tokenId, 1);

        // Overflows are incredibly unrealistic.
        // The `numberMinted` for `to` is incremented by 1, and has a max limit of 2**64 - 1.
        // `_spotMinted` is incremented by 1, and has a max limit of 2**256 - 1.
        unchecked {
            // Updates:
            // - `address` to the owner.
            // - `startTimestamp` to the timestamp of minting.
            // - `burned` to `false`.
            // - `nextInitialized` to `true` (as `quantity == 1`).
            _packedOwnerships[tokenId] = _packOwnershipData(
                to,
                _nextInitializedFlag(1) | _nextExtraData(address(0), to, prevOwnershipPacked)
            );

            // Updates:
            // - `balance += 1`.
            // - `numberMinted += 1`.
            //
            // We can directly add to the `balance` and `numberMinted`.
            _packedAddressData[to] += (1 << _BITPOS_NUMBER_MINTED) | 1;

            // Mask to the lower 160 bits, in case the upper bits somehow aren't clean.
            uint256 toMasked = uint160(to);

            if (toMasked == uint256(0)) _revert(MintToZeroAddress.selector);

            assembly {
                // Emit the `Transfer` event.
                log4(
                    0, // Start of data (0, since no data).
                    0, // End of data (0, since no data).
                    _TRANSFER_EVENT_SIGNATURE, // Signature.
                    0, // `address(0)`.
                    toMasked, // `to`.
                    tokenId // `tokenId`.
                )
            }

            ++_spotMinted;
        }

        _afterTokenTransfers(address(0), to, tokenId, 1);
    }

    /**
     * @dev Safely mints a single token at `tokenId`.
     *
     * Note: A spot-minted `tokenId` that has been burned can be re-minted again.
     *
     * Requirements:
     *
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}.
     * - `tokenId` must be greater than `_sequentialUpTo()`.
     * - `tokenId` must not exist.
     *
     * See {_mintSpot}.
     *
     * Emits a {Transfer} event.
     */
    function _safeMintSpot(
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _mintSpot(to, tokenId);

        unchecked {
            if (to.code.length != 0) {
                uint256 currentSpotMinted = _spotMinted;
                if (!_checkContractOnERC721Received(address(0), to, tokenId, _data)) {
                    _revert(TransferToNonERC721ReceiverImplementer.selector);
                }
                // This prevents reentrancy to `_safeMintSpot`.
                // It does not prevent reentrancy to `_safeMint`.
                if (_spotMinted != currentSpotMinted) revert();
            }
        }
    }

    /**
     * @dev Equivalent to `_safeMintSpot(to, tokenId, '')`.
     */
    function _safeMintSpot(address to, uint256 tokenId) internal virtual {
        _safeMintSpot(to, tokenId, '');
    }

    // =============================================================
    //                       APPROVAL OPERATIONS
    // =============================================================

    /**
     * @dev Equivalent to `_approve(to, tokenId, false)`.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _approve(to, tokenId, false);
    }

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the
     * zero address clears previous approvals.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function _approve(
        address to,
        uint256 tokenId,
        bool approvalCheck
    ) internal virtual {
        address owner = ownerOf(tokenId);

        if (approvalCheck && _msgSenderERC721A() != owner)
            if (!isApprovedForAll(owner, _msgSenderERC721A())) {
                _revert(ApprovalCallerNotOwnerNorApproved.selector);
            }

        _tokenApprovals[tokenId].value = to;
        emit Approval(owner, to, tokenId);
    }

    // =============================================================
    //                        BURN OPERATIONS
    // =============================================================

    /**
     * @dev Equivalent to `_burn(tokenId, false)`.
     */
    function _burn(uint256 tokenId) internal virtual {
        _burn(tokenId, false);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId, bool approvalCheck) internal virtual {
        uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);

        uint256 fromMasked = uint160(prevOwnershipPacked);
        address from = address(uint160(fromMasked));

        (uint256 approvedAddressSlot, uint256 approvedAddressValue) = _getApprovedSlotAndValue(tokenId);

        if (approvalCheck) {
            // The nested ifs save around 20+ gas over a compound boolean condition.
            if (!_isSenderApprovedOrOwner(approvedAddressValue, fromMasked, uint160(_msgSenderERC721A())))
                if (!isApprovedForAll(from, _msgSenderERC721A())) _revert(TransferCallerNotOwnerNorApproved.selector);
        }

        _beforeTokenTransfers(from, address(0), tokenId, 1);

        assembly {
            if approvedAddressValue {
                sstore(approvedAddressSlot, 0) // Equivalent to `delete _tokenApprovals[tokenId]`.
            }
        }

      ...

// [truncated — 62407 bytes total]
IERC721A.sol 312 lines
// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.3.0
// Creator: Chiru Labs

pragma solidity ^0.8.4;

/**
 * @dev Interface of ERC721A.
 */
interface IERC721A {
    /**
     * The caller must own the token or be an approved operator.
     */
    error ApprovalCallerNotOwnerNorApproved();

    /**
     * The token does not exist.
     */
    error ApprovalQueryForNonexistentToken();

    /**
     * Cannot query the balance for the zero address.
     */
    error BalanceQueryForZeroAddress();

    /**
     * Cannot mint to the zero address.
     */
    error MintToZeroAddress();

    /**
     * The quantity of tokens minted must be more than zero.
     */
    error MintZeroQuantity();

    /**
     * The token does not exist.
     */
    error OwnerQueryForNonexistentToken();

    /**
     * The caller must own the token or be an approved operator.
     */
    error TransferCallerNotOwnerNorApproved();

    /**
     * The token must be owned by `from`.
     */
    error TransferFromIncorrectOwner();

    /**
     * Cannot safely transfer to a contract that does not implement the
     * ERC721Receiver interface.
     */
    error TransferToNonERC721ReceiverImplementer();

    /**
     * Cannot transfer to the zero address.
     */
    error TransferToZeroAddress();

    /**
     * The token does not exist.
     */
    error URIQueryForNonexistentToken();

    /**
     * The `quantity` minted with ERC2309 exceeds the safety limit.
     */
    error MintERC2309QuantityExceedsLimit();

    /**
     * The `extraData` cannot be set on an unintialized ownership slot.
     */
    error OwnershipNotInitializedForExtraData();

    /**
     * The `tokenIds` must be strictly ascending.
     */
    error TokenIdsNotStrictlyAscending();

    /**
     * `_sequentialUpTo()` must be greater than `_startTokenId()`.
     */
    error SequentialUpToTooSmall();

    /**
     * The `tokenId` of a sequential mint exceeds `_sequentialUpTo()`.
     */
    error SequentialMintExceedsLimit();

    /**
     * Spot minting requires a `tokenId` greater than `_sequentialUpTo()`.
     */
    error SpotMintTokenIdTooSmall();

    /**
     * Cannot mint over a token that already exists.
     */
    error TokenAlreadyExists();

    /**
     * The feature is not compatible with spot mints.
     */
    error NotCompatibleWithSpotMints();

    // =============================================================
    //                            STRUCTS
    // =============================================================

    struct TokenOwnership {
        // The address of the owner.
        address addr;
        // Stores the start time of ownership with minimal overhead for tokenomics.
        uint64 startTimestamp;
        // Whether the token has been burned.
        bool burned;
        // Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.
        uint24 extraData;
    }

    // =============================================================
    //                         TOKEN COUNTERS
    // =============================================================

    /**
     * @dev Returns the total number of tokens in existence.
     * Burned tokens will reduce the count.
     * To get the total number of tokens minted, please see {_totalMinted}.
     */
    function totalSupply() external view returns (uint256);

    // =============================================================
    //                            IERC165
    // =============================================================

    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);

    // =============================================================
    //                            IERC721
    // =============================================================

    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables
     * (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in `owner`'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`,
     * checking first that contract recipients are aware of the ERC721 protocol
     * to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be have been allowed to move
     * this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement
     * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external payable;

    /**
     * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external payable;

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom}
     * whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token
     * by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external payable;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the
     * zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external payable;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom}
     * for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);

    // =============================================================
    //                        IERC721Metadata
    // =============================================================

    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);

    // =============================================================
    //                           IERC2309
    // =============================================================

    /**
     * @dev Emitted when tokens in `fromTokenId` to `toTokenId`
     * (inclusive) is transferred from `from` to `to`, as defined in the
     * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.
     *
     * See {_mintERC2309} for more details.
     */
    event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);
}
ERC721ABatchTransferable.sol 40 lines
// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs

pragma solidity ^0.8.4;

import '../ERC721A.sol';
import './IERC721ABatchTransferable.sol';

/**
 * @title ERC721ABatchTransferable.
 *
 * @dev ERC721A token optimized for batch transfers.
 */
abstract contract ERC721ABatchTransferable is ERC721A, IERC721ABatchTransferable {
    function batchTransferFrom(
        address from,
        address to,
        uint256[] memory tokenIds
    ) public payable virtual override {
        _batchTransferFrom(_msgSenderERC721A(), from, to, tokenIds);
    }

    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory tokenIds
    ) public payable virtual override {
        _safeBatchTransferFrom(_msgSenderERC721A(), from, to, tokenIds, '');
    }

    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory tokenIds,
        bytes memory _data
    ) public payable virtual override {
        _safeBatchTransferFrom(_msgSenderERC721A(), from, to, tokenIds, _data);
    }
}
IERC721ABatchTransferable.sol 62 lines
// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs

pragma solidity ^0.8.4;

import '../IERC721A.sol';

/**
 * @dev Interface of ERC721ABatchTransferable.
 */
interface IERC721ABatchTransferable is IERC721A {
    /**
     * @dev Transfers `tokenIds` in batch from `from` to `to`. See {ERC721A-_batchTransferFrom}.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenIds` tokens must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move these tokens
     * by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event for each transfer.
     */
    function batchTransferFrom(
        address from,
        address to,
        uint256[] memory tokenIds
    ) external payable;

    /**
     * @dev Equivalent to `safeBatchTransferFrom(from, to, tokenIds, '')`.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory tokenIds
    ) external payable;

    /**
     * @dev Safely transfers `tokenIds` in batch from `from` to `to`. See {ERC721A-_safeBatchTransferFrom}.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenIds` tokens must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move these tokens
     * by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement
     * {IERC721Receiver-onERC721Received}, which is called for each transferred token.
     *
     * Emits a {Transfer} event for each transfer.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory tokenIds,
        bytes memory _data
    ) external payable;
}
IERC2981.sol 23 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC2981.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../utils/introspection/IERC165.sol";

/**
 * @dev Interface for the NFT Royalty Standard.
 *
 * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal
 * support for royalty payments across all NFT marketplaces and ecosystem participants.
 */
interface IERC2981 is IERC165 {
    /**
     * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
     * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
     */
    function royaltyInfo(
        uint256 tokenId,
        uint256 salePrice
    ) external view returns (address receiver, uint256 royaltyAmount);
}
ERC2981.sol 137 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/common/ERC2981.sol)

pragma solidity ^0.8.20;

import {IERC2981} from "../../interfaces/IERC2981.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.
 *
 * Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for
 * specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first.
 *
 * Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the
 * fee is specified in basis points by default.
 *
 * IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
 * https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to
 * voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
 */
abstract contract ERC2981 is IERC2981, ERC165 {
    struct RoyaltyInfo {
        address receiver;
        uint96 royaltyFraction;
    }

    RoyaltyInfo private _defaultRoyaltyInfo;
    mapping(uint256 tokenId => RoyaltyInfo) private _tokenRoyaltyInfo;

    /**
     * @dev The default royalty set is invalid (eg. (numerator / denominator) >= 1).
     */
    error ERC2981InvalidDefaultRoyalty(uint256 numerator, uint256 denominator);

    /**
     * @dev The default royalty receiver is invalid.
     */
    error ERC2981InvalidDefaultRoyaltyReceiver(address receiver);

    /**
     * @dev The royalty set for an specific `tokenId` is invalid (eg. (numerator / denominator) >= 1).
     */
    error ERC2981InvalidTokenRoyalty(uint256 tokenId, uint256 numerator, uint256 denominator);

    /**
     * @dev The royalty receiver for `tokenId` is invalid.
     */
    error ERC2981InvalidTokenRoyaltyReceiver(uint256 tokenId, address receiver);

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
        return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @inheritdoc IERC2981
     */
    function royaltyInfo(uint256 tokenId, uint256 salePrice) public view virtual returns (address, uint256) {
        RoyaltyInfo memory royalty = _tokenRoyaltyInfo[tokenId];

        if (royalty.receiver == address(0)) {
            royalty = _defaultRoyaltyInfo;
        }

        uint256 royaltyAmount = (salePrice * royalty.royaltyFraction) / _feeDenominator();

        return (royalty.receiver, royaltyAmount);
    }

    /**
     * @dev The denominator with which to interpret the fee set in {_setTokenRoyalty} and {_setDefaultRoyalty} as a
     * fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an
     * override.
     */
    function _feeDenominator() internal pure virtual returns (uint96) {
        return 10000;
    }

    /**
     * @dev Sets the royalty information that all ids in this contract will default to.
     *
     * Requirements:
     *
     * - `receiver` cannot be the zero address.
     * - `feeNumerator` cannot be greater than the fee denominator.
     */
    function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual {
        uint256 denominator = _feeDenominator();
        if (feeNumerator > denominator) {
            // Royalty fee will exceed the sale price
            revert ERC2981InvalidDefaultRoyalty(feeNumerator, denominator);
        }
        if (receiver == address(0)) {
            revert ERC2981InvalidDefaultRoyaltyReceiver(address(0));
        }

        _defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);
    }

    /**
     * @dev Removes default royalty information.
     */
    function _deleteDefaultRoyalty() internal virtual {
        delete _defaultRoyaltyInfo;
    }

    /**
     * @dev Sets the royalty information for a specific token id, overriding the global default.
     *
     * Requirements:
     *
     * - `receiver` cannot be the zero address.
     * - `feeNumerator` cannot be greater than the fee denominator.
     */
    function _setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) internal virtual {
        uint256 denominator = _feeDenominator();
        if (feeNumerator > denominator) {
            // Royalty fee will exceed the sale price
            revert ERC2981InvalidTokenRoyalty(tokenId, feeNumerator, denominator);
        }
        if (receiver == address(0)) {
            revert ERC2981InvalidTokenRoyaltyReceiver(tokenId, address(0));
        }

        _tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);
    }

    /**
     * @dev Resets royalty information for the token id back to the global default.
     */
    function _resetTokenRoyalty(uint256 tokenId) internal virtual {
        delete _tokenRoyaltyInfo[tokenId];
    }
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
PatronNFT.sol 108 lines
//               @@@@@@@@@@@@@
//           @@@@@@          @@@@@
//        @@@@                   @@@@
//      @@@@                       @@@@          @@@@@@@     @@@@@@@@     @@@@@       @@@@@      @@      @@    @@@@@@@@         @@@
//     @@@@ @@@@@@@@@@@ @@@@@@@@@@@ @@@@         @@    @@    @@          @@   @@@   @@@   @@     @@@    @@@    @@               @ @
//    @@@@  @@       @@ @@       @@  @@@@        @@    @@    @@         @@          @@     @@    @@@@  @@@@    @@              @@ @@
//   @@ @@  @@   @@  @@ @@   @@  @@  @@ @@       @@@@@@@     @@@@@@@    @@         @@@     @@    @@ @@@@ @@    @@@@@@@         @   @@
//  @@  @@  @@   @@  @@ @@   @@  @@  @@  @@      @@     @@   @@         @@          @@     @@    @@  @@  @@    @@             @@@@@@@
// @@@  @@       @@  @@ @@   @@      @@  @@@     @@     @@   @@         @@     @@   @@     @@    @@      @@    @@            @@     @@
// @@   @@@@@@@@@@@ @@@ @@@  @@@@@@@@@@   @@     @@@@@@@@    @@@@@@@@    @@@@@@@     @@@@@@@     @@      @@    @@@@@@@@      @@     @@
// @@                                     @@
// @@   @@@@@@@@@@@ @@@ @@@  @@@@@@@@@@   @@
// @@   @@       @@  @@ @@   @@      @@   @@     @@@@@@@@     @@@     @@@@@@@@@   @@@@@@@      @@@@@@     @@@    @@
// @@@  @@  @@   @@  @@ @@   @@  @@  @@  @@@     @@     @@    @@@@       @@       @@    @@    @@    @@    @@@@   @@
//  @@  @@  @@   @@  @@ @@   @@  @@  @@  @@      @@     @@   @@  @@      @@       @@    @@   @@      @@   @@ @@  @@
//   @@ @@  @@   @@  @@ @@   @@  @@  @@ @@       @@@@@@@@    @@  @@      @@       @@@@@@@    @@      @@   @@  @@ @@
//    @@@@  @@       @@ @@       @@  @@@@        @@         @@@@@@@@     @@       @@  @@     @@      @@   @@   @@@@
//     @@@@ @@@@@@@@@@@ @@@@@@@@@@@ @@@@         @@         @     @@     @@       @@   @@     @@    @@    @@    @@@
//      @@@@                       @@@@          @@        @@      @@    @@       @@    @@      @@@@      @@     @@
//        @@@@                   @@@@
//           @@@@@@          @@@@@
//               @@@@@@@@@@@@@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

import { ERC721ABatchTransferable } from "ERC721A/extensions/ERC721ABatchTransferable.sol";
import { ERC721A } from "ERC721A/ERC721A.sol";
import { IERC721A } from "ERC721A/ERC721A.sol";
import { ERC2981 } from "@openzeppelin/contracts/token/common/ERC2981.sol";
import { IERC2981 } from "@openzeppelin/contracts/token/common/ERC2981.sol";

contract PatronNFT is ERC2981, ERC721ABatchTransferable {
    uint256 public constant TOTAL_SUPPLY = 100_000;
    // as per https://github.com/chiru-labs/ERC721A/blob/c5bd8e1b1d845e321f35b69872597f308f455019/contracts/ERC721A.sol#L89
    uint256 public constant MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;

    string private baseTokenURI;

    constructor(
        string memory name_,
        string memory symbol_,
        address _mintDestination,
        address _royaltyReceiver,
        uint96 _feeNumerator,
        string memory _baseTokenURI
    ) ERC721A(name_, symbol_) {
        _setDefaultRoyalty(_royaltyReceiver, _feeNumerator);
        baseTokenURI = _baseTokenURI;
        for (uint256 i = 0; i < TOTAL_SUPPLY; i += MAX_MINT_ERC2309_QUANTITY_LIMIT) {
            _mintERC2309(_mintDestination, MAX_MINT_ERC2309_QUANTITY_LIMIT);
        }
    }

    /**
     * @notice Returns whether `tokenId` exists.
     * @param tokenId The ID of the token to check.
     * @return bool True if the token exists, false otherwise.
     * @dev Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     * @dev Tokens start existing when they are minted. See {_mint}.
     */
    function exists(uint256 tokenId) public view returns (bool) {
        return _exists(tokenId);
    }

    /**
     * @dev Returns the total amount of tokens minted in the contract.
     */
    function totalMinted() public view returns (uint256) {
        return _totalMinted();
    }

    /*///////////////////////////////////////////////////////////////
    //                                 Metadata
    ///////////////////////////////////////////////////////////////*/

    /**
     * @notice Overriding the baseURI function as per ERC721A instructions.
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     *      token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     *      by default, it can be overridden in child contracts.
     */
    function _baseURI() internal view override returns (string memory) {
        return baseTokenURI;
    }

    /*///////////////////////////////////////////////////////////////
    //                      Mandatory Overrides
    ///////////////////////////////////////////////////////////////*/

    /**
     * @notice Returns true if this contract implements the interface defined by `interfaceId`.
     * @param interfaceId The interface identifier, as specified in ERC-165.
     * @return bool True if the contract implements `interfaceId` and false otherwise.
     * @dev See the corresponding [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified) to learn more about how these ids are created.
     * @dev This function call must use less than 30000 gas.
     * @dev Natspec and code copied from ERC721A, with the addition of ERC2981 interface.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC2981, ERC721A, IERC721A) returns (bool) {
        // The interface IDs are constants representing the first 4 bytes
        // of the XOR of all function selectors in the interface.
        // See: [ERC165](https://eips.ethereum.org/EIPS/eip-165)
        // (e.g. `bytes4(i.functionA.selector ^ i.functionB.selector ^ ...)`)
        return interfaceId == 0x01ffc9a7 // ERC165 interface ID for ERC165.
            || interfaceId == 0x80ac58cd // ERC165 interface ID for ERC721.
            || interfaceId == 0x5b5e139f // ERC165 interface ID for ERC721Metadata.
            || interfaceId == type(IERC2981).interfaceId; // ERC165 interface ID for ERC2981.
    }
}

Read Contract

MAX_MINT_ERC2309_QUANTITY_LIMIT 0xcae794e9 → uint256
TOTAL_SUPPLY 0x902d55a5 → uint256
balanceOf 0x70a08231 → uint256
exists 0x4f558e79 → bool
getApproved 0x081812fc → address
isApprovedForAll 0xe985e9c5 → bool
name 0x06fdde03 → string
ownerOf 0x6352211e → address
royaltyInfo 0x2a55205a → address, uint256
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenURI 0xc87b56dd → string
totalMinted 0xa2309ff8 → uint256
totalSupply 0x18160ddd → uint256

Write Contract 8 functions

These functions modify contract state and require a wallet transaction to execute.

approve 0x095ea7b3
address to
uint256 tokenId
batchTransferFrom 0xf3993d11
address from
address to
uint256[] tokenIds
safeBatchTransferFrom 0x034601ec
address from
address to
uint256[] tokenIds
safeBatchTransferFrom 0x28cfbd46
address from
address to
uint256[] tokenIds
bytes _data
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes _data
setApprovalForAll 0xa22cb465
address operator
bool approved
transferFrom 0x23b872dd
address from
address to
uint256 tokenId

Recent Transactions

No transactions found for this address