ETH Price: $2,545.22 (-1.45%)

Transaction Decoder

Block:
17481749 at Jun-15-2023 12:31:59 AM +UTC
Transaction Fee:
0.02667862754674717 ETH $67.90
Gas Used:
1,779,454 Gas / 14.992591855 Gwei

Emitted Events:

272 RaidFairy.OwnershipTransferred( previousOwner=0x00000000...000000000, newOwner=[Sender] 0x6666667fed25d883a07d8171e98d078258d0d5a5 )
273 OperatorFilterRegistry.RegistrationUpdated( registrant=RaidFairy, registered=True )
274 OperatorFilterRegistry.SubscriptionUpdated( registrant=RaidFairy, subscription=0x3cc6CddA...f810dCeB6, subscribed=True )

Account State Difference:

  Address   Before After State Difference Code
0x00000000...67333cd4E
0x0A791089...9eDBC3221
0 Eth
Nonce: 0
0 Eth
Nonce: 1
From: 0 To: 40902103214212513139976188289772486924782841183843985200086805571828357184931523775809951804254874961305708480133366688738015549497629269777656205218796522864442713894625109748239733112508912360178163074844174552852077284323911643406447640952793754244603688866346281526005279154861901948686775020168678022168118278061827102324530690432488165735154526088735090128282986437155880412998463384600162379134961921331144946346641926707011214221516856373625157506442068038413100899621535010186030942234355408730613513410702191214203522312045145537477408265445956096056278116444601133724064636556884397251887508097130375690386972800425676210681878714852122505888668521394309021055071809540883427752663686605222090620098591475115569272629195721605645979640663651263252935031792709665738844889491219959992039133883367488324472241067101441758440670750747060055448938641275819396620040747907758258073410347546054102641280542368103827729863659223288889452732234413575033660226398275191927491300688954825826730818293220448174950221614172203866734625945417190983146374474767522842582344123208794319488050186032496035894097700740344727360144278727718940754691171237771185889750688394842328899357402832981391495219860169732173297856847204114693487732164555003746213843032963958041762792541924292119993394077041142404316710816763805306013508256218724418225498206753367808147140784767229376149102941247014778491479278988270238951052659616242549575531173931852323875013499334848401977585248565331241696185483014853165522379467939163564427568610306863727645255220768527557592956338882783337382540902371946219310087277995263372239382522568268012735635673116161948688421518585369410593953670315067966393141870899005339351417804362670690474303936349716313868819651256014445818952120734301789832654720713741478347168961833604454223933617597794419310169707735454182140618424640902118278948069366184073200623098336360600428752136242835911132415983440128593079519919902397173291785895688829746095757587829021048061655511636478110476354667040896288067782684527519644251863217003631228834751581303475054355755929980186847184869106397854338803662931265650280429094387219966040807314204771507021796887592286538512795364654777193376198461225839218783679444603745572616103887473594596304540223420212782041985706687685367312182624606223612346724791512706683518648679291145027599071881309394458543092082344205779189071709086504052909665271604242959728880709560889744509009008057718211026763183969044228963186764471614652906950429773813904427643376806206057200990378900406283105152516216982100592095452315859827914397770664971384383656159144419899264423951429516848028303272706082519837931111108171870256690243338937595605343683171417579323808006625671398682333518902708219217954804649063617576410858606424365717711471937542528543134489347829446921407539665146936714962595020266217851121801928706735884402578630391159025807363614463849504007977183951668167573645738297228333231943516138487945827754965603797598927315280881004818372428205880332333959190154522317292571740091793181774971372268183713414809776729751491433979935866229431765052598030906081837407141244251662980340312192473675730958617845698190924575056917104187793156310303989394362496206815928956126729419891072875861130128449721265880205581501199207581510894373173223665546779511741401036553986620649793291007690274082887219963281865552293852618923817365334817999639243544927866942787166740100699014285171169535412675538221325843914992254976539431620586715136907480858232959786028560143120861325302399271568048408822332595538302004640587474564106492268277300718250307427579564414599440240786116352641363151653142885399171092103226951234581959846506157456723658476416214954123702010884326335449371973888042555174703340965003332249819700555867984651650621985568884124071492281652026074983559229627115614836801122929284279614625233591216473311398237965314575204447072736687619171025793839405007650599520007475916364100764390152055496654314378558090489907656404396465070029520502455736431966308560592734650320423904313056988626520402669275725177727668630693525886895172755713229002167370766945528586164957403769498502357448287301182818477510473342157536546196468900208685544071879421500919928379265646913149514277220904668335873989775109369637541313492890243694490882975547505039359930923376109625672758632363878966299871979496517913492169780678276208233761327220516061496048647002782393453246779979118092599253703476331117906599964800698439775268474507657923034543531629426434846109378422756500868306869797997583043464478389925687772606678647881319267479514082692575829364276140273137413511998953949466217972431576915966691058161019084560197498241088733544153348891317608320041094644477193010036782303559282267727788997071559939578754202666826635373893586515734961878897976948185114959140398557056958427082678631538828569093735831700155597257628910464786111511662345693647186506461400412018631424634270193541562721110346727911155519767736631825184754370206617166053726347904806938549439868868055098498540324648033018437951758509183922497497081356743484712644659878759176103327885922337975839508326045623098671949767586475400415887877251608461984207380312068616893096356240812312221531831258137696349692381332046005827181818536162037604037200323637345172695253207308395954674360719838262385955547302161569038416252906522243399300458452190897509579561234017471159599522745430546244762384655681026031481449039857695557343850253296878897927655716334363799493576548493497237545831916021659514589086660242427502046029227890636560331355539813716116138626584652625310500189636967041913904827042864813823559356622852548417560539337735052568649707892101908471486555144268338015060215921528233662588950467010730445146033274661010456297247373574032488549489425479969571866028709222214023532492844156464645997524874135985204385009504246426288660775693392395879783648538844342532016916985624615510283625957908777969227732198594888654809239685524568223925760206550369134203987710395596798101920720449767904985920603507320401882270357588118167183415066357254016880775445432920245342883554078185344438494975839102608886783493753347868555595938535297452068106555540293481781292833202692308418459749026590669245141889872293850398687329073302520538192727927644271656973185479293862503562907012150523085901658394787549389147624342482261601630650511805729629916363678140953236672849357543275730354927224082348787258957945693301775465705402838709102797597334791527108063112004151561297105157776253946454122255454981728667900778940047201276508665664771577390626899143518063408921153512218767090708420539280018329477846150796764524457857231837128974348257923525105816962365732833554011535307199133045076518771688878532402624042772842183084055773010235291069531879596035057239972950897478154863424707371809278736750251698465398644146768962921277027228510204361908057657707245149159609451439649794285080187850524779810434511586395157636300360449713368684598019774062583862334326202334255108098844624551465321130830549643014666764496941724024922669456125201949050125031717224674194690315926831635240751709699693145526522162563814959145923612928428873014337261008611699086061387356273135095331155047343956869505962909905585662257241964426864867158660084901473576683532684353554700469020213577849677224465335327550454170611808605588828576219372748097594660320763434035128467128663968289768084850718276884329819332783095548100122887179051394397089773749767552431312581337616780710215459175799844337934744316425677250167083473597121334899965057461906938554760599061305267494879395796364595533861528886769627794365128964983195055172000468040264755318493860965863220471494850862827480228427153496487474773937813496074200342229508284293013636436329991191347680686813385830402264797190311330803292032871030492445741452544756268964200723499209811932336480772859953427131494512067915852008501516779080659361301824070925608490954170142274747406359268754997120905389647883840812382367938828807459463837406042025744699999434688675864395613748708798871835903710851273179809962234443159188957283129822725421323813910411401317224369015590168379309225661993262897158486693059289286856688296679600456296338033260432966559825638438464158218345516201149347690629209830705753962867657874319446719725274632847188714871947355485859332061887259682278241956781070675422379047062573898736207490968766572074780110626377293659348938202118966591799023726701686894406272316804152176803866398234265722511085190897984870115856532136489248644518059597027940026466370295748066348709812450499912363304733255824659436488339841149284537244211914732793180639819843697608505921406816790030574556812031833512029956695693025179347365373577011572078618283682987234819004012293852413263939023110483017855005099445354885761975025924506393277398270314222948887262884488616079314628066672152975622935894761065743244459275984087164885602538944040028296085307129870754084376265250498494527229964929850246651225547481643625243953233369538272586441007808638811570001682273940266667028038342277895197669780473094132052135472236571040400455744775004424130918261980744229406629966735860801257266381868611723074129745050131925172055444230360088249866231471184116522309334433999293294938111437087925715409968300194940196271829688204713810169366040776672247423180832449194569239289202991178913193327353232766251275474086971642493086045823453276733831720880388678700255983361223929561055272822004134028642025039328484859892247409604662841757731605095984829081031099155536030624115116352431568645895870824827682165802530214875905240852976590423019591195794244269466413871898314196637323215583384497889480903990597344100777042172314379020514884531394599088713441515713610361042318547861628571470295750690132290196401516572465690838331058805616718872666066886849609483673696646617576481984870101402467612492782363897625253436403479112500941148598518538604857573861741386331192939494460686026443584520924243858212969311378966908123425520804519365030577942647661203788644363647746435564469116280166713484018512421485017286084099007868291039971974022629785454981840715462759016152871731190758068338697918565706752682238855460926208023863180764145927933809762240471085576801479252858394049289969961890232091338385178394826452585293420683584305292052135127584064511191675059094740940804139794056163683240697956938207437002026908660991196513623606847195467966882668325413915660719301587344951295065807495225035679034185365488711061417821029247871276505672156905057708050457142235368458017633163397700130743761607370355902044912859935165046410033135897967976565955753721480063200985965928898349196915398789499795557559345320789687160527689882095966248029633536247832069871817793369332105376999716108495402027984247211877731918141917689282939557328944957471439058431972831967149276446883043311482177142522436782006831674751468985324655024800174243050012920183503463661381617009793177043768945062744137286870320677812076869648921980496945533270962587649957653175571934839246322184961233678019868924440045534524341771488113722338844456733956678043746374335899644205011759369396720981966565412445239960416175432287224118653340737966143168360857424772736018699949747304755441861703209588887619474193871719423332043469271758382910301487021049331507906318675387128394895634012749756830787076678174402562961186693904602272164478606751943883844690306520373591167193555023614146211548337349920715065350615454296129727124725894736658129206810274113375963907921799559336376342271916863054839962499654409415394795517905017415490890871545920595740849986718155452921966495492163846102740844673763151695033900635503529488580915954057534851426191439817898472274351167948104393631739896544967374325141008969342424227896182621626355767836070562550038184786333275848341370863475601559263441740469395704562112866950806634902166367802806272148628612506185004498037812899455773089426252656375934008969579088191407688347331414607702541296784641939949292336943297571090163895306427137653755130059570471288632586699003017432753377002596115915422232781976312315859728514676138202497087979584897679876127668088346936613253871632820876349508021704521047160284290048625617938942586696026448849873138491796508324378655667646133792821711870170794744848538181662150597051303591472711031049657597002950706527659765564115322093682152115076461967519827578988010570789883987636038502785728066165993996048456144999937241702284676743894940641782334255316509065875155003928750862366301026562450258861965585628979608448844014790556354597773222843693279782404522427276121450000036382157367486948786731995429552995511349943111475701075197688221386931924883468287289148757113973072878012368395298775916989111666722516515466906849466737770552267335113937652969023032081885578919593406860241595511714706585679081114367064158091745275409068123261648229573766337350425884696834915820503263426788589015433096798312629807285799017055988722294275336912445167716651897822120650562758767638042452723341941500569717382152206773680695715351177303536176432559543141976040535657980119685054075120702752442403386114231901189168610211253136341280029652608773301532764888233786217228665923718282335972241252875608976617761084341067433539531512986553897681439959657827794250403607959279122678954392420267375545313527936546990049984833574206692103576088379584432802994032189172700927689607261442124119001714121766695975162049045433523929986952111820711862433561697026226708651371518961030002744998427915639998105336742663867766569638261923386278973764425760222311106044327706832146354764468969494325735459928702107457119962510186389507652378906797864424329595357882902902043048970266663086726839705133987232611821178780252466673510595308661160622562345741584818758116374837903613763648027505126667645453171311950854236432101076543132090626813711447413107672577001898150046149771725953152749675040646859054731843615643851736705266626570463666902279457920547836748584137442340473896049794374469325550548329711485619906387999815387198230484162562100689111969574760685400136291370097074973017539196306516932751336001469798447248772240240796032155565121762053299497113367442558077536056190132172002293532942723584547898595716406939090363908530430931787147042219789497686608521920741045313192778894863920386750577018675185159834881251020597694862857574634596297236044052305373562087778355447636486411447949153020452193557752614951660261802700419760643047383371755527685276913729262388320353083312733345820798721772257064980954713483669672737360753062917028417090562064111565879832056258275790872479759471508867565655611399205607574642486896948938339167364193447936169867634215796390676411876255170348799569304236324129707628306266369135660130238824116527712347020292192117402507693019592316215437717620916119086441222719828706222362979270143747030627319930002250245552477991996301881122155002050582330571499401574406605560079863209751476372974553408914911054182490599801313396839140350409482081921886413515448036371353849743476724066662282433193388533170608320661971802753867373725575339817952476899097134093170998589668444837724755437681906270593512371282223635822313830364114712629918800260581892028543534399739149332676463413238818070924993676239341672368724741458610997493268308345882544142332683052320430984357515991116648246623303416320679313974742859444639370936581422823118902349688021514294885744044209997002597004487409250124907629400730630438122094185424557045520371228452973382858401267980962724298877974097268051409935532709122617210732567127636457099768854639549942605720818303064528421206457527905465706388419116639898986844420529090000010354782414750942905665186799786333848568776219857853263163135195640964485051874198011362391383328367707448839432489242526633247009595793857716106045648728699364705467774374099126483941480644084083091028027907536663559196655162911082610739
0x6666667F...258d0d5A5
0.13711663773161288 Eth
Nonce: 16
0.11043801018486571 Eth
Nonce: 17
0.02667862754674717
(builder0x69)
1.340617537133985287 Eth1.341252728402012821 Eth0.000635191268027534

Execution Trace

RaidFairy.61010060( )
  • OperatorFilterRegistry.registerAndSubscribe( registrant=0x0A791089ACf48912a9Cfde00E3A6aFe9eDBC3221, subscription=0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6 )
    File 1 of 2: RaidFairy
    // SPDX-License-Identifier: MIT
    // File: contracts/Fairy/IOperatorFilterRegistry.sol
    
    
    pragma solidity ^0.8.0;
    
    interface IOperatorFilterRegistry {
        function isOperatorAllowed(address registrant, address operator) external view returns (bool);
        function register(address registrant) external;
        function registerAndSubscribe(address registrant, address subscription) external;
        function registerAndCopyEntries(address registrant, address registrantToCopy) external;
        function unregister(address addr) external;
        function updateOperator(address registrant, address operator, bool filtered) external;
        function updateOperators(address registrant, address[] calldata operators, bool filtered) external;
        function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external;
        function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external;
        function subscribe(address registrant, address registrantToSubscribe) external;
        function unsubscribe(address registrant, bool copyExistingEntries) external;
        function subscriptionOf(address addr) external returns (address registrant);
        function subscribers(address registrant) external returns (address[] memory);
        function subscriberAt(address registrant, uint256 index) external returns (address);
        function copyEntriesOf(address registrant, address registrantToCopy) external;
        function isOperatorFiltered(address registrant, address operator) external returns (bool);
        function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool);
        function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool);
        function filteredOperators(address addr) external returns (address[] memory);
        function filteredCodeHashes(address addr) external returns (bytes32[] memory);
        function filteredOperatorAt(address registrant, uint256 index) external returns (address);
        function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32);
        function isRegistered(address addr) external returns (bool);
        function codeHashOf(address addr) external returns (bytes32);
    }
    // File: contracts/Fairy/OperatorFilterer.sol
    
    
    pragma solidity ^0.8.0;
    
    
    /**
     * @title  OperatorFilterer
     * @notice Abstract contract whose constructor automatically registers and optionally subscribes to or copies another
     *         registrant's entries in the OperatorFilterRegistry.
     * @dev    This smart contract is meant to be inherited by token contracts so they can use the following:
     *         - `onlyAllowedOperator` modifier for `transferFrom` and `safeTransferFrom` methods.
     *         - `onlyAllowedOperatorApproval` modifier for `approve` and `setApprovalForAll` methods.
     */
    abstract contract OperatorFilterer {
        error OperatorNotAllowed(address operator);
    
        IOperatorFilterRegistry public constant OPERATOR_FILTER_REGISTRY =
            IOperatorFilterRegistry(0x000000000000AAeB6D7670E522A718067333cd4E);
    
        constructor(address subscriptionOrRegistrantToCopy, bool subscribe) {
            // If an inheriting token contract is deployed to a network without the registry deployed, the modifier
            // will not revert, but the contract will need to be registered with the registry once it is deployed in
            // order for the modifier to filter addresses.
            if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
                if (subscribe) {
                    OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
                } else {
                    if (subscriptionOrRegistrantToCopy != address(0)) {
                        OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
                    } else {
                        OPERATOR_FILTER_REGISTRY.register(address(this));
                    }
                }
            }
        }
    
        modifier onlyAllowedOperator(address from) virtual {
            // Allow spending tokens from addresses with balance
            // Note that this still allows listings and marketplaces with escrow to transfer tokens if transferred
            // from an EOA.
            if (from != msg.sender) {
                _checkFilterOperator(msg.sender);
            }
            _;
        }
    
        modifier onlyAllowedOperatorApproval(address operator) virtual {
            _checkFilterOperator(operator);
            _;
        }
    
        function _checkFilterOperator(address operator) internal view virtual {
            // Check registry code length to facilitate testing in environments without a deployed registry.
            if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
                if (!OPERATOR_FILTER_REGISTRY.isOperatorAllowed(address(this), operator)) {
                    revert OperatorNotAllowed(operator);
                }
            }
        }
    }
    // File: contracts/Fairy/DefaultOperatorFilterer.sol
    
    
    pragma solidity ^0.8.0;
    
    
    /**
     * @title  DefaultOperatorFilterer
     * @notice Inherits from OperatorFilterer and automatically subscribes to the default OpenSea subscription.
     */
    abstract contract DefaultOperatorFilterer is OperatorFilterer {
        address constant DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);
    
        constructor() OperatorFilterer(DEFAULT_SUBSCRIPTION, true) {}
    }
    // File: erc721a/contracts/IERC721A.sol
    
    
    // ERC721A Contracts v4.2.3
    // 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();
    
        // =============================================================
        //                            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);
    }
    
    // File: erc721a/contracts/ERC721A.sol
    
    
    // ERC721A Contracts v4.2.3
    // Creator: Chiru Labs
    
    pragma solidity ^0.8.4;
    
    
    /**
     * @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()`.
     *
     * 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;
    
        // =============================================================
        //                          CONSTRUCTOR
        // =============================================================
    
        constructor(string memory name_, string memory symbol_) {
            _name = name_;
            _symbol = symbol_;
            _currentIndex = _startTokenId();
        }
    
        // =============================================================
        //                   TOKEN COUNTING OPERATIONS
        // =============================================================
    
        /**
         * @dev Returns the starting token ID.
         * To change the starting token ID, please override this function.
         */
        function _startTokenId() internal view virtual returns (uint256) {
            return 0;
        }
    
        /**
         * @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) {
            // Counter underflow is impossible as _burnCounter cannot be incremented
            // more than `_currentIndex - _startTokenId()` times.
            unchecked {
                return _currentIndex - _burnCounter - _startTokenId();
            }
        }
    
        /**
         * @dev Returns the total amount of tokens minted in the contract.
         */
        function _totalMinted() internal view virtual returns (uint256) {
            // Counter underflow is impossible as `_currentIndex` does not decrement,
            // and it is initialized to `_startTokenId()`.
            unchecked {
                return _currentIndex - _startTokenId();
            }
        }
    
        /**
         * @dev Returns the total number of tokens burned.
         */
        function _totalBurned() internal view virtual returns (uint256) {
            return _burnCounter;
        }
    
        // =============================================================
        //                    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();
            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();
    
            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 Initializes the ownership slot minted at `index` for efficiency purposes.
         */
        function _initializeOwnershipAt(uint256 index) internal virtual {
            if (_packedOwnerships[index] == 0) {
                _packedOwnerships[index] = _packedOwnershipOf(index);
            }
        }
    
        /**
         * Returns the packed ownership data of `tokenId`.
         */
        function _packedOwnershipOf(uint256 tokenId) private view returns (uint256) {
            uint256 curr = tokenId;
    
            unchecked {
                if (_startTokenId() <= curr)
                    if (curr < _currentIndex) {
                        uint256 packed = _packedOwnerships[curr];
                        // If not burned.
                        if (packed & _BITMASK_BURNED == 0) {
                            // 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, `curr` will not underflow.
                            //
                            // We can directly compare the packed value.
                            // If the address is zero, packed will be zero.
                            while (packed == 0) {
                                packed = _packedOwnerships[--curr];
                            }
                            return packed;
                        }
                    }
            }
            revert OwnerQueryForNonexistentToken();
        }
    
        /**
         * @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.
         * 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) public payable virtual override {
            address owner = ownerOf(tokenId);
    
            if (_msgSenderERC721A() != owner)
                if (!isApprovedForAll(owner, _msgSenderERC721A())) {
                    revert ApprovalCallerNotOwnerNorApproved();
                }
    
            _tokenApprovals[tokenId].value = to;
            emit Approval(owner, to, tokenId);
        }
    
        /**
         * @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();
    
            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) {
            return
                _startTokenId() <= tokenId &&
                tokenId < _currentIndex && // If within bounds,
                _packedOwnerships[tokenId] & _BITMASK_BURNED == 0; // and not burned.
        }
    
        /**
         * @dev Returns whether `msgSender` is equal to `approvedAddress` or `owner`.
         */
        function _isSenderApprovedOrOwner(
            address approvedAddress,
            address owner,
            address msgSender
        ) private pure returns (bool result) {
            assembly {
                // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.
                owner := and(owner, _BITMASK_ADDRESS)
                // Mask `msgSender` to the lower 160 bits, in case the upper bits somehow aren't clean.
                msgSender := and(msgSender, _BITMASK_ADDRESS)
                // `msgSender == owner || msgSender == approvedAddress`.
                result := or(eq(msgSender, owner), eq(msgSender, approvedAddress))
            }
        }
    
        /**
         * @dev Returns the storage slot and value for the approved address of `tokenId`.
         */
        function _getApprovedSlotAndAddress(uint256 tokenId)
            private
            view
            returns (uint256 approvedAddressSlot, address approvedAddress)
        {
            TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId];
            // The following is equivalent to `approvedAddress = _tokenApprovals[tokenId].value`.
            assembly {
                approvedAddressSlot := tokenApproval.slot
                approvedAddress := 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);
    
            if (address(uint160(prevOwnershipPacked)) != from) revert TransferFromIncorrectOwner();
    
            (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);
    
            // The nested ifs save around 20+ gas over a compound boolean condition.
            if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))
                if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();
    
            if (to == address(0)) revert TransferToZeroAddress();
    
            _beforeTokenTransfers(from, to, tokenId, 1);
    
            // Clear approvals from the previous owner.
            assembly {
                if approvedAddress {
                    // This is equivalent to `delete _tokenApprovals[tokenId]`.
                    sstore(approvedAddressSlot, 0)
                }
            }
    
            // 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 == 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] == 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;
                        }
                    }
                }
            }
    
            emit Transfer(from, to, tokenId);
            _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();
                }
        }
    
        /**
         * @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 == 0) {
                    revert TransferToNonERC721ReceiverImplementer();
                } else {
                    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 == 0) revert MintZeroQuantity();
    
            _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:
                // - `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)
                );
    
                uint256 toMasked;
                uint256 end = startTokenId + quantity;
    
                // Use assembly to loop and emit the `Transfer` event for gas savings.
                // The duplicated `log4` removes an extra check and reduces stack juggling.
                // The assembly, together with the surrounding Solidity code, have been
                // delicately arranged to nudge the compiler into producing optimized opcodes.
                assembly {
                    // Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.
                    toMasked := and(to, _BITMASK_ADDRESS)
                    // 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`.
                        startTokenId // `tokenId`.
                    )
    
                    // The `iszero(eq(,))` check ensures that large values of `quantity`
                    // that overflows uint256 will make the loop run out of gas.
                    // The compiler will optimize the `iszero` away for performance.
                    for {
                        let tokenId := add(startTokenId, 1)
                    } iszero(eq(tokenId, end)) {
                        tokenId := add(tokenId, 1)
                    } {
                        // Emit the `Transfer` event. Similar to above.
                        log4(0, 0, _TRANSFER_EVENT_SIGNATURE, 0, toMasked, tokenId)
                    }
                }
                if (toMasked == 0) revert MintToZeroAddress();
    
                _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();
            if (quantity == 0) revert MintZeroQuantity();
            if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) revert MintERC2309QuantityExceedsLimit();
    
            _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)
                );
    
                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();
                        }
                    } while (index < end);
                    // Reentrancy protection.
                    if (_currentIndex != end) revert();
                }
            }
        }
    
        /**
         * @dev Equivalent to `_safeMint(to, quantity, '')`.
         */
        function _safeMint(address to, uint256 quantity) internal virtual {
            _safeMint(to, quantity, '');
        }
    
        // =============================================================
        //                        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);
    
            address from = address(uint160(prevOwnershipPacked));
    
            (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);
    
            if (approvalCheck) {
                // The nested ifs save around 20+ gas over a compound boolean condition.
                if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))
                    if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();
            }
    
            _beforeTokenTransfers(from, address(0), tokenId, 1);
    
            // Clear approvals from the previous owner.
            assembly {
                if approvedAddress {
                    // This is equivalent to `delete _tokenApprovals[tokenId]`.
                    sstore(approvedAddressSlot, 0)
                }
            }
    
            // 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 {
                // Updates:
                // - `balance -= 1`.
                // - `numberBurned += 1`.
                //
                // We can directly decrement the balance, and increment the number burned.
                // This is equivalent to `packed -= 1; packed += 1 << _BITPOS_NUMBER_BURNED;`.
                _packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1;
    
                // Updates:
                // - `address` to the last owner.
                // - `startTimestamp` to the timestamp of burning.
                // - `burned` to `true`.
                // - `nextInitialized` to `true`.
                _packedOwnerships[tokenId] = _packOwnershipData(
                    from,
                    (_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked)
                );
    
                // If the next slot may not have been initialized (i.e. `nextInitialized == false`) .
                if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 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] == 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;
                        }
                    }
                }
            }
    
            emit Transfer(from, address(0), tokenId);
            _afterTokenTransfers(from, address(0), tokenId, 1);
    
            // Overflow not possible, as _burnCounter cannot be exceed _currentIndex times.
            unchecked {
                _burnCounter++;
            }
        }
    
        // =============================================================
        //                     EXTRA DATA OPERATIONS
        // =============================================================
    
        /**
         * @dev Directly sets the extra data for the ownership data `index`.
         */
        function _setExtraDataAt(uint256 index, uint24 extraData) internal virtual {
            uint256 packed = _packedOwnerships[index];
            if (packed == 0) revert OwnershipNotInitializedForExtraData();
            uint256 extraDataCasted;
            // Cast `extraData` with assembly to avoid redundant masking.
            assembly {
                extraDataCasted := extraData
            }
            packed = (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << _BITPOS_EXTRA_DATA);
            _packedOwnerships[index] = packed;
        }
    
        /**
         * @dev Called during each token transfer to set the 24bit `extraData` field.
         * Intended to be overridden by the cosumer contract.
         *
         * `previousExtraData` - the value of `extraData` before transfer.
         *
         * 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 _extraData(
            address from,
            address to,
            uint24 previousExtraData
        ) internal view virtual returns (uint24) {}
    
        /**
         * @dev Returns the next extra data for the packed ownership data.
         * The returned result is shifted into position.
         */
        function _nextExtraData(
            address from,
            address to,
            uint256 prevOwnershipPacked
        ) private view returns (uint256) {
            uint24 extraData = uint24(prevOwnershipPacked >> _BITPOS_EXTRA_DATA);
            return uint256(_extraData(from, to, extraData)) << _BITPOS_EXTRA_DATA;
        }
    
        // =============================================================
        //                       OTHER OPERATIONS
        // =============================================================
    
        /**
         * @dev Returns the message sender (defaults to `msg.sender`).
         *
         * If you are writing GSN compatible contracts, you need to override this function.
         */
        function _msgSenderERC721A() internal view virtual returns (address) {
            return msg.sender;
        }
    
        /**
         * @dev Converts a uint256 to its ASCII string decimal representation.
         */
        function _toString(uint256 value) internal pure virtual returns (string memory str) {
            assembly {
                // The maximum value of a uint256 contains 78 digits (1 byte per digit), but
                // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.
                // We will need 1 word for the trailing zeros padding, 1 word for the length,
                // and 3 words for a maximum of 78 digits. Total: 5 * 0x20 = 0xa0.
                let m := add(mload(0x40), 0xa0)
                // Update the free memory pointer to allocate.
                mstore(0x40, m)
                // Assign the `str` to the end.
                str := sub(m, 0x20)
                // Zeroize the slot after the string.
                mstore(str, 0)
    
                // Cache the end of the memory to calculate the length later.
                let end := str
    
                // We write the string from rightmost digit to leftmost digit.
                // The following is essentially a do-while loop that also handles the zero case.
                // prettier-ignore
                for { let temp := value } 1 {} {
                    str := sub(str, 1)
                    // Write the character to the pointer.
                    // The ASCII index of the '0' character is 48.
                    mstore8(str, add(48, mod(temp, 10)))
                    // Keep dividing `temp` until zero.
                    temp := div(temp, 10)
                    // prettier-ignore
                    if iszero(temp) { break }
                }
    
                let length := sub(end, str)
                // Move the pointer 32 bytes leftwards to make room for the length.
                str := sub(str, 0x20)
                // Store the length.
                mstore(str, length)
            }
        }
    }
    
    // File: @openzeppelin/contracts/utils/introspection/IERC165.sol
    
    
    // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
    
    pragma solidity ^0.8.0;
    
    /**
     * @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);
    }
    
    // File: @openzeppelin/contracts/utils/introspection/ERC165.sol
    
    
    // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
    
    pragma solidity ^0.8.0;
    
    
    /**
     * @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);
     * }
     * ```
     *
     * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
     */
    abstract contract ERC165 is IERC165 {
        /**
         * @dev See {IERC165-supportsInterface}.
         */
        function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
            return interfaceId == type(IERC165).interfaceId;
        }
    }
    
    // File: @openzeppelin/contracts/interfaces/IERC2981.sol
    
    
    // OpenZeppelin Contracts (last updated v4.6.0) (interfaces/IERC2981.sol)
    
    pragma solidity ^0.8.0;
    
    
    /**
     * @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.
     *
     * _Available since v4.5._
     */
    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);
    }
    
    // File: @openzeppelin/contracts/token/common/ERC2981.sol
    
    
    // OpenZeppelin Contracts (last updated v4.7.0) (token/common/ERC2981.sol)
    
    pragma solidity ^0.8.0;
    
    
    
    /**
     * @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.
     *
     * _Available since v4.5._
     */
    abstract contract ERC2981 is IERC2981, ERC165 {
        struct RoyaltyInfo {
            address receiver;
            uint96 royaltyFraction;
        }
    
        RoyaltyInfo private _defaultRoyaltyInfo;
        mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo;
    
        /**
         * @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 override 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 {
            require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
            require(receiver != address(0), "ERC2981: invalid receiver");
    
            _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 {
            require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
            require(receiver != address(0), "ERC2981: Invalid parameters");
    
            _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];
        }
    }
    
    // File: @openzeppelin/contracts/utils/math/SafeMath.sol
    
    
    // OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)
    
    pragma solidity ^0.8.0;
    
    // CAUTION
    // This version of SafeMath should only be used with Solidity 0.8 or later,
    // because it relies on the compiler's built in overflow checks.
    
    /**
     * @dev Wrappers over Solidity's arithmetic operations.
     *
     * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
     * now has built in overflow checking.
     */
    library SafeMath {
        /**
         * @dev Returns the addition of two unsigned integers, with an overflow flag.
         *
         * _Available since v3.4._
         */
        function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
            unchecked {
                uint256 c = a + b;
                if (c < a) return (false, 0);
                return (true, c);
            }
        }
    
        /**
         * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
         *
         * _Available since v3.4._
         */
        function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
            unchecked {
                if (b > a) return (false, 0);
                return (true, a - b);
            }
        }
    
        /**
         * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
         *
         * _Available since v3.4._
         */
        function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
            unchecked {
                // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
                // benefit is lost if 'b' is also tested.
                // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
                if (a == 0) return (true, 0);
                uint256 c = a * b;
                if (c / a != b) return (false, 0);
                return (true, c);
            }
        }
    
        /**
         * @dev Returns the division of two unsigned integers, with a division by zero flag.
         *
         * _Available since v3.4._
         */
        function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
            unchecked {
                if (b == 0) return (false, 0);
                return (true, a / b);
            }
        }
    
        /**
         * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
         *
         * _Available since v3.4._
         */
        function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
            unchecked {
                if (b == 0) return (false, 0);
                return (true, a % b);
            }
        }
    
        /**
         * @dev Returns the addition of two unsigned integers, reverting on
         * overflow.
         *
         * Counterpart to Solidity's `+` operator.
         *
         * Requirements:
         *
         * - Addition cannot overflow.
         */
        function add(uint256 a, uint256 b) internal pure returns (uint256) {
            return a + b;
        }
    
        /**
         * @dev Returns the subtraction of two unsigned integers, reverting on
         * overflow (when the result is negative).
         *
         * Counterpart to Solidity's `-` operator.
         *
         * Requirements:
         *
         * - Subtraction cannot overflow.
         */
        function sub(uint256 a, uint256 b) internal pure returns (uint256) {
            return a - b;
        }
    
        /**
         * @dev Returns the multiplication of two unsigned integers, reverting on
         * overflow.
         *
         * Counterpart to Solidity's `*` operator.
         *
         * Requirements:
         *
         * - Multiplication cannot overflow.
         */
        function mul(uint256 a, uint256 b) internal pure returns (uint256) {
            return a * b;
        }
    
        /**
         * @dev Returns the integer division of two unsigned integers, reverting on
         * division by zero. The result is rounded towards zero.
         *
         * Counterpart to Solidity's `/` operator.
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function div(uint256 a, uint256 b) internal pure returns (uint256) {
            return a / b;
        }
    
        /**
         * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
         * reverting when dividing by zero.
         *
         * Counterpart to Solidity's `%` operator. This function uses a `revert`
         * opcode (which leaves remaining gas untouched) while Solidity uses an
         * invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function mod(uint256 a, uint256 b) internal pure returns (uint256) {
            return a % b;
        }
    
        /**
         * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
         * overflow (when the result is negative).
         *
         * CAUTION: This function is deprecated because it requires allocating memory for the error
         * message unnecessarily. For custom revert reasons use {trySub}.
         *
         * Counterpart to Solidity's `-` operator.
         *
         * Requirements:
         *
         * - Subtraction cannot overflow.
         */
        function sub(
            uint256 a,
            uint256 b,
            string memory errorMessage
        ) internal pure returns (uint256) {
            unchecked {
                require(b <= a, errorMessage);
                return a - b;
            }
        }
    
        /**
         * @dev Returns the integer division of two unsigned integers, reverting with custom message on
         * division by zero. The result is rounded towards zero.
         *
         * Counterpart to Solidity's `/` operator. Note: this function uses a
         * `revert` opcode (which leaves remaining gas untouched) while Solidity
         * uses an invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function div(
            uint256 a,
            uint256 b,
            string memory errorMessage
        ) internal pure returns (uint256) {
            unchecked {
                require(b > 0, errorMessage);
                return a / b;
            }
        }
    
        /**
         * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
         * reverting with custom message when dividing by zero.
         *
         * CAUTION: This function is deprecated because it requires allocating memory for the error
         * message unnecessarily. For custom revert reasons use {tryMod}.
         *
         * Counterpart to Solidity's `%` operator. This function uses a `revert`
         * opcode (which leaves remaining gas untouched) while Solidity uses an
         * invalid opcode to revert (consuming all remaining gas).
         *
         * Requirements:
         *
         * - The divisor cannot be zero.
         */
        function mod(
            uint256 a,
            uint256 b,
            string memory errorMessage
        ) internal pure returns (uint256) {
            unchecked {
                require(b > 0, errorMessage);
                return a % b;
            }
        }
    }
    
    // File: @openzeppelin/contracts/utils/Strings.sol
    
    
    // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
    
    pragma solidity ^0.8.0;
    
    /**
     * @dev String operations.
     */
    library Strings {
        bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    
        /**
         * @dev Converts a `uint256` to its ASCII `string` decimal representation.
         */
        function toString(uint256 value) internal pure returns (string memory) {
            // Inspired by OraclizeAPI's implementation - MIT licence
            // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
    
            if (value == 0) {
                return "0";
            }
            uint256 temp = value;
            uint256 digits;
            while (temp != 0) {
                digits++;
                temp /= 10;
            }
            bytes memory buffer = new bytes(digits);
            while (value != 0) {
                digits -= 1;
                buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
                value /= 10;
            }
            return string(buffer);
        }
    
        /**
         * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
         */
        function toHexString(uint256 value) internal pure returns (string memory) {
            if (value == 0) {
                return "0x00";
            }
            uint256 temp = value;
            uint256 length = 0;
            while (temp != 0) {
                length++;
                temp >>= 8;
            }
            return toHexString(value, length);
        }
    
        /**
         * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
         */
        function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
            bytes memory buffer = new bytes(2 * length + 2);
            buffer[0] = "0";
            buffer[1] = "x";
            for (uint256 i = 2 * length + 1; i > 1; --i) {
                buffer[i] = _HEX_SYMBOLS[value & 0xf];
                value >>= 4;
            }
            require(value == 0, "Strings: hex length insufficient");
            return string(buffer);
        }
    }
    
    // File: @openzeppelin/contracts/utils/Context.sol
    
    
    // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
    
    pragma solidity ^0.8.0;
    
    /**
     * @dev Provides information about the current execution context, including the
     * sender of the transaction and its data. While these are generally available
     * via msg.sender and msg.data, they should not be accessed in such a direct
     * manner, since when dealing with meta-transactions the account sending and
     * paying for execution may not be the actual sender (as far as an application
     * is concerned).
     *
     * This contract is only required for intermediate, library-like contracts.
     */
    abstract contract Context {
        function _msgSender() internal view virtual returns (address) {
            return msg.sender;
        }
    
        function _msgData() internal view virtual returns (bytes calldata) {
            return msg.data;
        }
    }
    
    // File: @openzeppelin/contracts/access/Ownable.sol
    
    
    // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
    
    pragma solidity ^0.8.0;
    
    
    /**
     * @dev Contract module which provides a basic access control mechanism, where
     * there is an account (an owner) that can be granted exclusive access to
     * specific functions.
     *
     * By default, the owner account will be the one that deploys the contract. This
     * can later be changed with {transferOwnership}.
     *
     * This module is used through inheritance. It will make available the modifier
     * `onlyOwner`, which can be applied to your functions to restrict their use to
     * the owner.
     */
    abstract contract Ownable is Context {
        address private _owner;
    
        event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    
        /**
         * @dev Initializes the contract setting the deployer as the initial owner.
         */
        constructor() {
            _transferOwnership(_msgSender());
        }
    
        /**
         * @dev Returns the address of the current owner.
         */
        function owner() public view virtual returns (address) {
            return _owner;
        }
    
        /**
         * @dev Throws if called by any account other than the owner.
         */
        modifier onlyOwner() {
            require(owner() == _msgSender(), "Ownable: caller is not the owner");
            _;
        }
    
        /**
         * @dev Leaves the contract without owner. It will not be possible to call
         * `onlyOwner` functions anymore. Can only be called by the current owner.
         *
         * NOTE: Renouncing ownership will leave the contract without an owner,
         * thereby removing any functionality that is only available to the owner.
         */
        function renounceOwnership() public virtual onlyOwner {
            _transferOwnership(address(0));
        }
    
        /**
         * @dev Transfers ownership of the contract to a new account (`newOwner`).
         * Can only be called by the current owner.
         */
        function transferOwnership(address newOwner) public virtual onlyOwner {
            require(newOwner != address(0), "Ownable: new owner is the zero address");
            _transferOwnership(newOwner);
        }
    
        /**
         * @dev Transfers ownership of the contract to a new account (`newOwner`).
         * Internal function without access restriction.
         */
        function _transferOwnership(address newOwner) internal virtual {
            address oldOwner = _owner;
            _owner = newOwner;
            emit OwnershipTransferred(oldOwner, newOwner);
        }
    }
    
    // File: contracts/Fairy/Fairy.sol
    
    
    // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
    
    pragma solidity ^0.8.0;
    
    
    
    
    
    
    
    
    contract RaidFairy is ERC721A, ERC2981, Ownable, DefaultOperatorFilterer {
        using SafeMath for uint256;
    
        uint256 public constant MAX_SUPPLY = 100000;
        uint256 public constant FREE_SUPPLY = 3;
        uint256 public constant PAID_SUPPLY = 10;
    
        uint256 private _flag;
        string private _defTokenURI = "https://ipfs.io/ipfs/QmY9VmLXVhq3S7gxZNVu4F8KRkaWjZgutJrXwYvgSXChY5";
        string private _baseTokenURI = "";
    
        mapping(address => bool) private _hasMinted;
    
        event NewMint(address indexed msgSender, uint256 indexed mintQuantity);
    
        constructor() ERC721A("Raid Fairy", "RFY") {
            _setDefaultRoyalty(msg.sender, 0);
        }
    
        function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721A, ERC2981)
        returns (bool) {
          return super.supportsInterface(interfaceId);
        }
    
        function _startTokenId() internal view override virtual returns (uint256) {
            return 1;
        }
    
        function transferOut(address _to) public onlyOwner {
            uint256 balance = address(this).balance;
            payable(_to).transfer(balance);
        }
    
        function changeTokenURIFlag(uint256 flag) external onlyOwner {
            _flag = flag;
        }
    
        function changeDefURI(string calldata _tokenURI) external onlyOwner {
            _defTokenURI = _tokenURI;
        }
    
        function changeURI(string calldata _tokenURI) external onlyOwner {
            _baseTokenURI = _tokenURI;
        }
    
        function _baseURI() internal view virtual override returns (string memory) {
            return _baseTokenURI;
        }
    
        function tokenURI(uint256 tokenId) public view override returns (string memory) {
            if (_flag == 0) {
                return _defTokenURI;
            } else {
                require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
                return string(abi.encodePacked(_baseTokenURI, Strings.toString(tokenId)));
            }
        }
    
        function mint(uint256 quantity) public payable {
            require(totalSupply() + quantity <= MAX_SUPPLY, "ERC721: Exceeds maximum supply");
            require(quantity == 1 || quantity == FREE_SUPPLY || quantity == PAID_SUPPLY, "ERC721: Invalid quantity");
    
            if (quantity <= FREE_SUPPLY ) {
                _safeMint(msg.sender,quantity);
            } else {
                require(msg.value >= 0.0001 ether, "ERC721: Insufficient payment");
                _safeMint(msg.sender,quantity);
            }
            
            emit NewMint(msg.sender, quantity);
        }
    
    }

    File 2 of 2: OperatorFilterRegistry
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
    pragma solidity ^0.8.0;
    import "../utils/Context.sol";
    /**
     * @dev Contract module which provides a basic access control mechanism, where
     * there is an account (an owner) that can be granted exclusive access to
     * specific functions.
     *
     * By default, the owner account will be the one that deploys the contract. This
     * can later be changed with {transferOwnership}.
     *
     * This module is used through inheritance. It will make available the modifier
     * `onlyOwner`, which can be applied to your functions to restrict their use to
     * the owner.
     */
    abstract contract Ownable is Context {
        address private _owner;
        event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
        /**
         * @dev Initializes the contract setting the deployer as the initial owner.
         */
        constructor() {
            _transferOwnership(_msgSender());
        }
        /**
         * @dev Throws if called by any account other than the owner.
         */
        modifier onlyOwner() {
            _checkOwner();
            _;
        }
        /**
         * @dev Returns the address of the current owner.
         */
        function owner() public view virtual returns (address) {
            return _owner;
        }
        /**
         * @dev Throws if the sender is not the owner.
         */
        function _checkOwner() internal view virtual {
            require(owner() == _msgSender(), "Ownable: caller is not the owner");
        }
        /**
         * @dev Leaves the contract without owner. It will not be possible to call
         * `onlyOwner` functions anymore. Can only be called by the current owner.
         *
         * NOTE: Renouncing ownership will leave the contract without an owner,
         * thereby removing any functionality that is only available to the owner.
         */
        function renounceOwnership() public virtual onlyOwner {
            _transferOwnership(address(0));
        }
        /**
         * @dev Transfers ownership of the contract to a new account (`newOwner`).
         * Can only be called by the current owner.
         */
        function transferOwnership(address newOwner) public virtual onlyOwner {
            require(newOwner != address(0), "Ownable: new owner is the zero address");
            _transferOwnership(newOwner);
        }
        /**
         * @dev Transfers ownership of the contract to a new account (`newOwner`).
         * Internal function without access restriction.
         */
        function _transferOwnership(address newOwner) internal virtual {
            address oldOwner = _owner;
            _owner = newOwner;
            emit OwnershipTransferred(oldOwner, newOwner);
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
    pragma solidity ^0.8.0;
    /**
     * @dev Provides information about the current execution context, including the
     * sender of the transaction and its data. While these are generally available
     * via msg.sender and msg.data, they should not be accessed in such a direct
     * manner, since when dealing with meta-transactions the account sending and
     * paying for execution may not be the actual sender (as far as an application
     * is concerned).
     *
     * This contract is only required for intermediate, library-like contracts.
     */
    abstract contract Context {
        function _msgSender() internal view virtual returns (address) {
            return msg.sender;
        }
        function _msgData() internal view virtual returns (bytes calldata) {
            return msg.data;
        }
    }
    // SPDX-License-Identifier: MIT
    // OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)
    // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
    pragma solidity ^0.8.0;
    /**
     * @dev Library for managing
     * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
     * types.
     *
     * Sets have the following properties:
     *
     * - Elements are added, removed, and checked for existence in constant time
     * (O(1)).
     * - Elements are enumerated in O(n). No guarantees are made on the ordering.
     *
     * ```
     * contract Example {
     *     // Add the library methods
     *     using EnumerableSet for EnumerableSet.AddressSet;
     *
     *     // Declare a set state variable
     *     EnumerableSet.AddressSet private mySet;
     * }
     * ```
     *
     * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
     * and `uint256` (`UintSet`) are supported.
     *
     * [WARNING]
     * ====
     * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
     * unusable.
     * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
     *
     * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
     * array of EnumerableSet.
     * ====
     */
    library EnumerableSet {
        // To implement this library for multiple types with as little code
        // repetition as possible, we write it in terms of a generic Set type with
        // bytes32 values.
        // The Set implementation uses private functions, and user-facing
        // implementations (such as AddressSet) are just wrappers around the
        // underlying Set.
        // This means that we can only create new EnumerableSets for types that fit
        // in bytes32.
        struct Set {
            // Storage of set values
            bytes32[] _values;
            // Position of the value in the `values` array, plus 1 because index 0
            // means a value is not in the set.
            mapping(bytes32 => uint256) _indexes;
        }
        /**
         * @dev Add a value to a set. O(1).
         *
         * Returns true if the value was added to the set, that is if it was not
         * already present.
         */
        function _add(Set storage set, bytes32 value) private returns (bool) {
            if (!_contains(set, value)) {
                set._values.push(value);
                // The value is stored at length-1, but we add 1 to all indexes
                // and use 0 as a sentinel value
                set._indexes[value] = set._values.length;
                return true;
            } else {
                return false;
            }
        }
        /**
         * @dev Removes a value from a set. O(1).
         *
         * Returns true if the value was removed from the set, that is if it was
         * present.
         */
        function _remove(Set storage set, bytes32 value) private returns (bool) {
            // We read and store the value's index to prevent multiple reads from the same storage slot
            uint256 valueIndex = set._indexes[value];
            if (valueIndex != 0) {
                // Equivalent to contains(set, value)
                // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
                // the array, and then remove the last element (sometimes called as 'swap and pop').
                // This modifies the order of the array, as noted in {at}.
                uint256 toDeleteIndex = valueIndex - 1;
                uint256 lastIndex = set._values.length - 1;
                if (lastIndex != toDeleteIndex) {
                    bytes32 lastValue = set._values[lastIndex];
                    // Move the last value to the index where the value to delete is
                    set._values[toDeleteIndex] = lastValue;
                    // Update the index for the moved value
                    set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
                }
                // Delete the slot where the moved value was stored
                set._values.pop();
                // Delete the index for the deleted slot
                delete set._indexes[value];
                return true;
            } else {
                return false;
            }
        }
        /**
         * @dev Returns true if the value is in the set. O(1).
         */
        function _contains(Set storage set, bytes32 value) private view returns (bool) {
            return set._indexes[value] != 0;
        }
        /**
         * @dev Returns the number of values on the set. O(1).
         */
        function _length(Set storage set) private view returns (uint256) {
            return set._values.length;
        }
        /**
         * @dev Returns the value stored at position `index` in the set. O(1).
         *
         * Note that there are no guarantees on the ordering of values inside the
         * array, and it may change when more values are added or removed.
         *
         * Requirements:
         *
         * - `index` must be strictly less than {length}.
         */
        function _at(Set storage set, uint256 index) private view returns (bytes32) {
            return set._values[index];
        }
        /**
         * @dev Return the entire set in an array
         *
         * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
         * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
         * this function has an unbounded cost, and using it as part of a state-changing function may render the function
         * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
         */
        function _values(Set storage set) private view returns (bytes32[] memory) {
            return set._values;
        }
        // Bytes32Set
        struct Bytes32Set {
            Set _inner;
        }
        /**
         * @dev Add a value to a set. O(1).
         *
         * Returns true if the value was added to the set, that is if it was not
         * already present.
         */
        function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
            return _add(set._inner, value);
        }
        /**
         * @dev Removes a value from a set. O(1).
         *
         * Returns true if the value was removed from the set, that is if it was
         * present.
         */
        function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
            return _remove(set._inner, value);
        }
        /**
         * @dev Returns true if the value is in the set. O(1).
         */
        function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
            return _contains(set._inner, value);
        }
        /**
         * @dev Returns the number of values in the set. O(1).
         */
        function length(Bytes32Set storage set) internal view returns (uint256) {
            return _length(set._inner);
        }
        /**
         * @dev Returns the value stored at position `index` in the set. O(1).
         *
         * Note that there are no guarantees on the ordering of values inside the
         * array, and it may change when more values are added or removed.
         *
         * Requirements:
         *
         * - `index` must be strictly less than {length}.
         */
        function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
            return _at(set._inner, index);
        }
        /**
         * @dev Return the entire set in an array
         *
         * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
         * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
         * this function has an unbounded cost, and using it as part of a state-changing function may render the function
         * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
         */
        function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
            bytes32[] memory store = _values(set._inner);
            bytes32[] memory result;
            /// @solidity memory-safe-assembly
            assembly {
                result := store
            }
            return result;
        }
        // AddressSet
        struct AddressSet {
            Set _inner;
        }
        /**
         * @dev Add a value to a set. O(1).
         *
         * Returns true if the value was added to the set, that is if it was not
         * already present.
         */
        function add(AddressSet storage set, address value) internal returns (bool) {
            return _add(set._inner, bytes32(uint256(uint160(value))));
        }
        /**
         * @dev Removes a value from a set. O(1).
         *
         * Returns true if the value was removed from the set, that is if it was
         * present.
         */
        function remove(AddressSet storage set, address value) internal returns (bool) {
            return _remove(set._inner, bytes32(uint256(uint160(value))));
        }
        /**
         * @dev Returns true if the value is in the set. O(1).
         */
        function contains(AddressSet storage set, address value) internal view returns (bool) {
            return _contains(set._inner, bytes32(uint256(uint160(value))));
        }
        /**
         * @dev Returns the number of values in the set. O(1).
         */
        function length(AddressSet storage set) internal view returns (uint256) {
            return _length(set._inner);
        }
        /**
         * @dev Returns the value stored at position `index` in the set. O(1).
         *
         * Note that there are no guarantees on the ordering of values inside the
         * array, and it may change when more values are added or removed.
         *
         * Requirements:
         *
         * - `index` must be strictly less than {length}.
         */
        function at(AddressSet storage set, uint256 index) internal view returns (address) {
            return address(uint160(uint256(_at(set._inner, index))));
        }
        /**
         * @dev Return the entire set in an array
         *
         * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
         * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
         * this function has an unbounded cost, and using it as part of a state-changing function may render the function
         * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
         */
        function values(AddressSet storage set) internal view returns (address[] memory) {
            bytes32[] memory store = _values(set._inner);
            address[] memory result;
            /// @solidity memory-safe-assembly
            assembly {
                result := store
            }
            return result;
        }
        // UintSet
        struct UintSet {
            Set _inner;
        }
        /**
         * @dev Add a value to a set. O(1).
         *
         * Returns true if the value was added to the set, that is if it was not
         * already present.
         */
        function add(UintSet storage set, uint256 value) internal returns (bool) {
            return _add(set._inner, bytes32(value));
        }
        /**
         * @dev Removes a value from a set. O(1).
         *
         * Returns true if the value was removed from the set, that is if it was
         * present.
         */
        function remove(UintSet storage set, uint256 value) internal returns (bool) {
            return _remove(set._inner, bytes32(value));
        }
        /**
         * @dev Returns true if the value is in the set. O(1).
         */
        function contains(UintSet storage set, uint256 value) internal view returns (bool) {
            return _contains(set._inner, bytes32(value));
        }
        /**
         * @dev Returns the number of values in the set. O(1).
         */
        function length(UintSet storage set) internal view returns (uint256) {
            return _length(set._inner);
        }
        /**
         * @dev Returns the value stored at position `index` in the set. O(1).
         *
         * Note that there are no guarantees on the ordering of values inside the
         * array, and it may change when more values are added or removed.
         *
         * Requirements:
         *
         * - `index` must be strictly less than {length}.
         */
        function at(UintSet storage set, uint256 index) internal view returns (uint256) {
            return uint256(_at(set._inner, index));
        }
        /**
         * @dev Return the entire set in an array
         *
         * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
         * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
         * this function has an unbounded cost, and using it as part of a state-changing function may render the function
         * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
         */
        function values(UintSet storage set) internal view returns (uint256[] memory) {
            bytes32[] memory store = _values(set._inner);
            uint256[] memory result;
            /// @solidity memory-safe-assembly
            assembly {
                result := store
            }
            return result;
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.13;
    import {EnumerableSet} from "openzeppelin-contracts/utils/structs/EnumerableSet.sol";
    interface IOperatorFilterRegistry {
        function isOperatorAllowed(address registrant, address operator) external returns (bool);
        function register(address registrant) external;
        function registerAndSubscribe(address registrant, address subscription) external;
        function registerAndCopyEntries(address registrant, address registrantToCopy) external;
        function updateOperator(address registrant, address operator, bool filtered) external;
        function updateOperators(address registrant, address[] calldata operators, bool filtered) external;
        function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external;
        function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external;
        function subscribe(address registrant, address registrantToSubscribe) external;
        function unsubscribe(address registrant, bool copyExistingEntries) external;
        function subscriptionOf(address addr) external returns (address registrant);
        function subscribers(address registrant) external returns (address[] memory);
        function subscriberAt(address registrant, uint256 index) external returns (address);
        function copyEntriesOf(address registrant, address registrantToCopy) external;
        function isOperatorFiltered(address registrant, address operator) external returns (bool);
        function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool);
        function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool);
        function filteredOperators(address addr) external returns (address[] memory);
        function filteredCodeHashes(address addr) external returns (bytes32[] memory);
        function filteredOperatorAt(address registrant, uint256 index) external returns (address);
        function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32);
        function isRegistered(address addr) external returns (bool);
        function codeHashOf(address addr) external returns (bytes32);
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.13;
    import {IOperatorFilterRegistry} from "./IOperatorFilterRegistry.sol";
    import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
    import {EnumerableSet} from "openzeppelin-contracts/utils/structs/EnumerableSet.sol";
    import {OperatorFilterRegistryErrorsAndEvents} from "./OperatorFilterRegistryErrorsAndEvents.sol";
    /**
     * @title  OperatorFilterRegistry
     * @notice Borrows heavily from the QQL BlacklistOperatorFilter contract:
     *         https://github.com/qql-art/contracts/blob/main/contracts/BlacklistOperatorFilter.sol
     * @notice This contracts allows tokens or token owners to register specific addresses or codeHashes that may be
     * *       restricted according to the isOperatorAllowed function.
     */
    contract OperatorFilterRegistry is IOperatorFilterRegistry, OperatorFilterRegistryErrorsAndEvents {
        using EnumerableSet for EnumerableSet.AddressSet;
        using EnumerableSet for EnumerableSet.Bytes32Set;
        /// @dev initialized accounts have a nonzero codehash (see https://eips.ethereum.org/EIPS/eip-1052)
        /// Note that this will also be a smart contract's codehash when making calls from its constructor.
        bytes32 constant EOA_CODEHASH = keccak256("");
        mapping(address => EnumerableSet.AddressSet) private _filteredOperators;
        mapping(address => EnumerableSet.Bytes32Set) private _filteredCodeHashes;
        mapping(address => address) private _registrations;
        mapping(address => EnumerableSet.AddressSet) private _subscribers;
        /**
         * @notice restricts method caller to the address or EIP-173 "owner()"
         */
        modifier onlyAddressOrOwner(address addr) {
            if (msg.sender != addr) {
                try Ownable(addr).owner() returns (address owner) {
                    if (msg.sender != owner) {
                        revert OnlyAddressOrOwner();
                    }
                } catch (bytes memory reason) {
                    if (reason.length == 0) {
                        revert NotOwnable();
                    } else {
                        /// @solidity memory-safe-assembly
                        assembly {
                            revert(add(32, reason), mload(reason))
                        }
                    }
                }
            }
            _;
        }
        /**
         * @notice Returns true if operator is not filtered for a given token, either by address or codeHash. Also returns
         *         true if supplied registrant address is not registered.
         */
        function isOperatorAllowed(address registrant, address operator) external view returns (bool) {
            address registration = _registrations[registrant];
            if (registration != address(0)) {
                EnumerableSet.AddressSet storage filteredOperatorsRef;
                EnumerableSet.Bytes32Set storage filteredCodeHashesRef;
                filteredOperatorsRef = _filteredOperators[registration];
                filteredCodeHashesRef = _filteredCodeHashes[registration];
                if (filteredOperatorsRef.contains(operator)) {
                    revert AddressFiltered(operator);
                }
                if (operator.code.length > 0) {
                    bytes32 codeHash = operator.codehash;
                    if (filteredCodeHashesRef.contains(codeHash)) {
                        revert CodeHashFiltered(operator, codeHash);
                    }
                }
            }
            return true;
        }
        //////////////////
        // AUTH METHODS //
        //////////////////
        /**
         * @notice Registers an address with the registry. May be called by address itself or by EIP-173 owner.
         */
        function register(address registrant) external onlyAddressOrOwner(registrant) {
            if (_registrations[registrant] != address(0)) {
                revert AlreadyRegistered();
            }
            _registrations[registrant] = registrant;
            emit RegistrationUpdated(registrant, true);
        }
        /**
         * @notice Unregisters an address with the registry and removes its subscription. May be called by address itself or by EIP-173 owner.
         *         Note that this does not remove any filtered addresses or codeHashes.
         *         Also note that any subscriptions to this registrant will still be active and follow the existing filtered addresses and codehashes.
         */
        function unregister(address registrant) external onlyAddressOrOwner(registrant) {
            address registration = _registrations[registrant];
            if (registration == address(0)) {
                revert NotRegistered(registrant);
            }
            if (registration != registrant) {
                _subscribers[registration].remove(registrant);
                emit SubscriptionUpdated(registrant, registration, false);
            }
            _registrations[registrant] = address(0);
            emit RegistrationUpdated(registrant, false);
        }
        /**
         * @notice Registers an address with the registry and "subscribes" to another address's filtered operators and codeHashes.
         */
        function registerAndSubscribe(address registrant, address subscription) external onlyAddressOrOwner(registrant) {
            address registration = _registrations[registrant];
            if (registration != address(0)) {
                revert AlreadyRegistered();
            }
            if (registrant == subscription) {
                revert CannotSubscribeToSelf();
            }
            address subscriptionRegistration = _registrations[subscription];
            if (subscriptionRegistration == address(0)) {
                revert NotRegistered(subscription);
            }
            if (subscriptionRegistration != subscription) {
                revert CannotSubscribeToRegistrantWithSubscription(subscription);
            }
            _registrations[registrant] = subscription;
            _subscribers[subscription].add(registrant);
            emit RegistrationUpdated(registrant, true);
            emit SubscriptionUpdated(registrant, subscription, true);
        }
        /**
         * @notice Registers an address with the registry and copies the filtered operators and codeHashes from another
         *         address without subscribing.
         */
        function registerAndCopyEntries(address registrant, address registrantToCopy)
            external
            onlyAddressOrOwner(registrant)
        {
            if (registrantToCopy == registrant) {
                revert CannotCopyFromSelf();
            }
            address registration = _registrations[registrant];
            if (registration != address(0)) {
                revert AlreadyRegistered();
            }
            address registrantRegistration = _registrations[registrantToCopy];
            if (registrantRegistration == address(0)) {
                revert NotRegistered(registrantToCopy);
            }
            _registrations[registrant] = registrant;
            emit RegistrationUpdated(registrant, true);
            _copyEntries(registrant, registrantToCopy);
        }
        /**
         * @notice Update an operator address for a registered address - when filtered is true, the operator is filtered.
         */
        function updateOperator(address registrant, address operator, bool filtered)
            external
            onlyAddressOrOwner(registrant)
        {
            address registration = _registrations[registrant];
            if (registration == address(0)) {
                revert NotRegistered(registrant);
            }
            if (registration != registrant) {
                revert CannotUpdateWhileSubscribed(registration);
            }
            EnumerableSet.AddressSet storage filteredOperatorsRef = _filteredOperators[registrant];
            if (!filtered) {
                bool removed = filteredOperatorsRef.remove(operator);
                if (!removed) {
                    revert AddressNotFiltered(operator);
                }
            } else {
                bool added = filteredOperatorsRef.add(operator);
                if (!added) {
                    revert AddressAlreadyFiltered(operator);
                }
            }
            emit OperatorUpdated(registrant, operator, filtered);
        }
        /**
         * @notice Update a codeHash for a registered address - when filtered is true, the codeHash is filtered.
         */
        function updateCodeHash(address registrant, bytes32 codeHash, bool filtered)
            external
            onlyAddressOrOwner(registrant)
        {
            if (codeHash == EOA_CODEHASH) {
                revert CannotFilterEOAs();
            }
            address registration = _registrations[registrant];
            if (registration == address(0)) {
                revert NotRegistered(registrant);
            }
            if (registration != registrant) {
                revert CannotUpdateWhileSubscribed(registration);
            }
            EnumerableSet.Bytes32Set storage filteredCodeHashesRef = _filteredCodeHashes[registrant];
            if (!filtered) {
                bool removed = filteredCodeHashesRef.remove(codeHash);
                if (!removed) {
                    revert CodeHashNotFiltered(codeHash);
                }
            } else {
                bool added = filteredCodeHashesRef.add(codeHash);
                if (!added) {
                    revert CodeHashAlreadyFiltered(codeHash);
                }
            }
            emit CodeHashUpdated(registrant, codeHash, filtered);
        }
        /**
         * @notice Update multiple operators for a registered address - when filtered is true, the operators will be filtered. Reverts on duplicates.
         */
        function updateOperators(address registrant, address[] calldata operators, bool filtered)
            external
            onlyAddressOrOwner(registrant)
        {
            address registration = _registrations[registrant];
            if (registration == address(0)) {
                revert NotRegistered(registrant);
            }
            if (registration != registrant) {
                revert CannotUpdateWhileSubscribed(registration);
            }
            EnumerableSet.AddressSet storage filteredOperatorsRef = _filteredOperators[registrant];
            uint256 operatorsLength = operators.length;
            unchecked {
                if (!filtered) {
                    for (uint256 i = 0; i < operatorsLength; ++i) {
                        address operator = operators[i];
                        bool removed = filteredOperatorsRef.remove(operator);
                        if (!removed) {
                            revert AddressNotFiltered(operator);
                        }
                    }
                } else {
                    for (uint256 i = 0; i < operatorsLength; ++i) {
                        address operator = operators[i];
                        bool added = filteredOperatorsRef.add(operator);
                        if (!added) {
                            revert AddressAlreadyFiltered(operator);
                        }
                    }
                }
            }
            emit OperatorsUpdated(registrant, operators, filtered);
        }
        /**
         * @notice Update multiple codeHashes for a registered address - when filtered is true, the codeHashes will be filtered. Reverts on duplicates.
         */
        function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered)
            external
            onlyAddressOrOwner(registrant)
        {
            address registration = _registrations[registrant];
            if (registration == address(0)) {
                revert NotRegistered(registrant);
            }
            if (registration != registrant) {
                revert CannotUpdateWhileSubscribed(registration);
            }
            EnumerableSet.Bytes32Set storage filteredCodeHashesRef = _filteredCodeHashes[registrant];
            uint256 codeHashesLength = codeHashes.length;
            unchecked {
                if (!filtered) {
                    for (uint256 i = 0; i < codeHashesLength; ++i) {
                        bytes32 codeHash = codeHashes[i];
                        bool removed = filteredCodeHashesRef.remove(codeHash);
                        if (!removed) {
                            revert CodeHashNotFiltered(codeHash);
                        }
                    }
                } else {
                    for (uint256 i = 0; i < codeHashesLength; ++i) {
                        bytes32 codeHash = codeHashes[i];
                        if (codeHash == EOA_CODEHASH) {
                            revert CannotFilterEOAs();
                        }
                        bool added = filteredCodeHashesRef.add(codeHash);
                        if (!added) {
                            revert CodeHashAlreadyFiltered(codeHash);
                        }
                    }
                }
            }
            emit CodeHashesUpdated(registrant, codeHashes, filtered);
        }
        /**
         * @notice Subscribe an address to another registrant's filtered operators and codeHashes. Will remove previous
         *         subscription if present.
         *         Note that accounts with subscriptions may go on to subscribe to other accounts - in this case,
         *         subscriptions will not be forwarded. Instead the former subscription's existing entries will still be
         *         used.
         */
        function subscribe(address registrant, address newSubscription) external onlyAddressOrOwner(registrant) {
            if (registrant == newSubscription) {
                revert CannotSubscribeToSelf();
            }
            if (newSubscription == address(0)) {
                revert CannotSubscribeToZeroAddress();
            }
            address registration = _registrations[registrant];
            if (registration == address(0)) {
                revert NotRegistered(registrant);
            }
            if (registration == newSubscription) {
                revert AlreadySubscribed(newSubscription);
            }
            address newSubscriptionRegistration = _registrations[newSubscription];
            if (newSubscriptionRegistration == address(0)) {
                revert NotRegistered(newSubscription);
            }
            if (newSubscriptionRegistration != newSubscription) {
                revert CannotSubscribeToRegistrantWithSubscription(newSubscription);
            }
            if (registration != registrant) {
                _subscribers[registration].remove(registrant);
                emit SubscriptionUpdated(registrant, registration, false);
            }
            _registrations[registrant] = newSubscription;
            _subscribers[newSubscription].add(registrant);
            emit SubscriptionUpdated(registrant, newSubscription, true);
        }
        /**
         * @notice Unsubscribe an address from its current subscribed registrant, and optionally copy its filtered operators and codeHashes.
         */
        function unsubscribe(address registrant, bool copyExistingEntries) external onlyAddressOrOwner(registrant) {
            address registration = _registrations[registrant];
            if (registration == address(0)) {
                revert NotRegistered(registrant);
            }
            if (registration == registrant) {
                revert NotSubscribed();
            }
            _subscribers[registration].remove(registrant);
            _registrations[registrant] = registrant;
            emit SubscriptionUpdated(registrant, registration, false);
            if (copyExistingEntries) {
                _copyEntries(registrant, registration);
            }
        }
        /**
         * @notice Copy filtered operators and codeHashes from a different registrantToCopy to addr.
         */
        function copyEntriesOf(address registrant, address registrantToCopy) external onlyAddressOrOwner(registrant) {
            if (registrant == registrantToCopy) {
                revert CannotCopyFromSelf();
            }
            address registration = _registrations[registrant];
            if (registration == address(0)) {
                revert NotRegistered(registrant);
            }
            if (registration != registrant) {
                revert CannotUpdateWhileSubscribed(registration);
            }
            address registrantRegistration = _registrations[registrantToCopy];
            if (registrantRegistration == address(0)) {
                revert NotRegistered(registrantToCopy);
            }
            _copyEntries(registrant, registrantToCopy);
        }
        /// @dev helper to copy entries from registrantToCopy to registrant and emit events
        function _copyEntries(address registrant, address registrantToCopy) private {
            EnumerableSet.AddressSet storage filteredOperatorsRef = _filteredOperators[registrantToCopy];
            EnumerableSet.Bytes32Set storage filteredCodeHashesRef = _filteredCodeHashes[registrantToCopy];
            uint256 filteredOperatorsLength = filteredOperatorsRef.length();
            uint256 filteredCodeHashesLength = filteredCodeHashesRef.length();
            unchecked {
                for (uint256 i = 0; i < filteredOperatorsLength; ++i) {
                    address operator = filteredOperatorsRef.at(i);
                    bool added = _filteredOperators[registrant].add(operator);
                    if (added) {
                        emit OperatorUpdated(registrant, operator, true);
                    }
                }
                for (uint256 i = 0; i < filteredCodeHashesLength; ++i) {
                    bytes32 codehash = filteredCodeHashesRef.at(i);
                    bool added = _filteredCodeHashes[registrant].add(codehash);
                    if (added) {
                        emit CodeHashUpdated(registrant, codehash, true);
                    }
                }
            }
        }
        //////////////////
        // VIEW METHODS //
        //////////////////
        /**
         * @notice Get the subscription address of a given registrant, if any.
         */
        function subscriptionOf(address registrant) external view returns (address subscription) {
            subscription = _registrations[registrant];
            if (subscription == address(0)) {
                revert NotRegistered(registrant);
            } else if (subscription == registrant) {
                subscription = address(0);
            }
        }
        /**
         * @notice Get the set of addresses subscribed to a given registrant.
         *         Note that order is not guaranteed as updates are made.
         */
        function subscribers(address registrant) external view returns (address[] memory) {
            return _subscribers[registrant].values();
        }
        /**
         * @notice Get the subscriber at a given index in the set of addresses subscribed to a given registrant.
         *         Note that order is not guaranteed as updates are made.
         */
        function subscriberAt(address registrant, uint256 index) external view returns (address) {
            return _subscribers[registrant].at(index);
        }
        /**
         * @notice Returns true if operator is filtered by a given address or its subscription.
         */
        function isOperatorFiltered(address registrant, address operator) external view returns (bool) {
            address registration = _registrations[registrant];
            if (registration != registrant) {
                return _filteredOperators[registration].contains(operator);
            }
            return _filteredOperators[registrant].contains(operator);
        }
        /**
         * @notice Returns true if a codeHash is filtered by a given address or its subscription.
         */
        function isCodeHashFiltered(address registrant, bytes32 codeHash) external view returns (bool) {
            address registration = _registrations[registrant];
            if (registration != registrant) {
                return _filteredCodeHashes[registration].contains(codeHash);
            }
            return _filteredCodeHashes[registrant].contains(codeHash);
        }
        /**
         * @notice Returns true if the hash of an address's code is filtered by a given address or its subscription.
         */
        function isCodeHashOfFiltered(address registrant, address operatorWithCode) external view returns (bool) {
            bytes32 codeHash = operatorWithCode.codehash;
            address registration = _registrations[registrant];
            if (registration != registrant) {
                return _filteredCodeHashes[registration].contains(codeHash);
            }
            return _filteredCodeHashes[registrant].contains(codeHash);
        }
        /**
         * @notice Returns true if an address has registered
         */
        function isRegistered(address registrant) external view returns (bool) {
            return _registrations[registrant] != address(0);
        }
        /**
         * @notice Returns a list of filtered operators for a given address or its subscription.
         */
        function filteredOperators(address registrant) external view returns (address[] memory) {
            address registration = _registrations[registrant];
            if (registration != registrant) {
                return _filteredOperators[registration].values();
            }
            return _filteredOperators[registrant].values();
        }
        /**
         * @notice Returns the set of filtered codeHashes for a given address or its subscription.
         *         Note that order is not guaranteed as updates are made.
         */
        function filteredCodeHashes(address registrant) external view returns (bytes32[] memory) {
            address registration = _registrations[registrant];
            if (registration != registrant) {
                return _filteredCodeHashes[registration].values();
            }
            return _filteredCodeHashes[registrant].values();
        }
        /**
         * @notice Returns the filtered operator at the given index of the set of filtered operators for a given address or
         *         its subscription.
         *         Note that order is not guaranteed as updates are made.
         */
        function filteredOperatorAt(address registrant, uint256 index) external view returns (address) {
            address registration = _registrations[registrant];
            if (registration != registrant) {
                return _filteredOperators[registration].at(index);
            }
            return _filteredOperators[registrant].at(index);
        }
        /**
         * @notice Returns the filtered codeHash at the given index of the list of filtered codeHashes for a given address or
         *         its subscription.
         *         Note that order is not guaranteed as updates are made.
         */
        function filteredCodeHashAt(address registrant, uint256 index) external view returns (bytes32) {
            address registration = _registrations[registrant];
            if (registration != registrant) {
                return _filteredCodeHashes[registration].at(index);
            }
            return _filteredCodeHashes[registrant].at(index);
        }
        /// @dev Convenience method to compute the code hash of an arbitrary contract
        function codeHashOf(address a) external view returns (bytes32) {
            return a.codehash;
        }
    }
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.13;
    contract OperatorFilterRegistryErrorsAndEvents {
        error CannotFilterEOAs();
        error AddressAlreadyFiltered(address operator);
        error AddressNotFiltered(address operator);
        error CodeHashAlreadyFiltered(bytes32 codeHash);
        error CodeHashNotFiltered(bytes32 codeHash);
        error OnlyAddressOrOwner();
        error NotRegistered(address registrant);
        error AlreadyRegistered();
        error AlreadySubscribed(address subscription);
        error NotSubscribed();
        error CannotUpdateWhileSubscribed(address subscription);
        error CannotSubscribeToSelf();
        error CannotSubscribeToZeroAddress();
        error NotOwnable();
        error AddressFiltered(address filtered);
        error CodeHashFiltered(address account, bytes32 codeHash);
        error CannotSubscribeToRegistrantWithSubscription(address registrant);
        error CannotCopyFromSelf();
        event RegistrationUpdated(address indexed registrant, bool indexed registered);
        event OperatorUpdated(address indexed registrant, address indexed operator, bool indexed filtered);
        event OperatorsUpdated(address indexed registrant, address[] operators, bool indexed filtered);
        event CodeHashUpdated(address indexed registrant, bytes32 indexed codeHash, bool indexed filtered);
        event CodeHashesUpdated(address indexed registrant, bytes32[] codeHashes, bool indexed filtered);
        event SubscriptionUpdated(address indexed registrant, address indexed subscription, bool indexed subscribed);
    }