ETH Price: $2,201.77 (-9.06%)

Transaction Decoder

Block:
14878869 at May-31-2022 01:09:09 PM +UTC
Transaction Fee:
0.0947009 ETH $208.51
Gas Used:
1,894,018 Gas / 50 Gwei

Emitted Events:

19 PxCvx.OwnershipTransferred( previousOwner=0x00000000...000000000, newOwner=[Sender] 0xe49efdb44ab67f8377e59ae9027b0bf4eca9a091 )

Account State Difference:

  Address   Before After State Difference Code
0xBCe0Cf87...9e815C3aC
0 Eth
Nonce: 0
0 Eth
Nonce: 1
From: 0 To: 82324920247095972007518680047844554759731057347623392694547932997258997450038124413676304657857015008664253638315919954316729957826787690922414966887801241268179308616592067192374071537820938383763342943637380410187194185801181121551554244092625995653311113054429129666876915029514681846249006820211455936713766542317694904989997063551229881335870997067891491105327766407488588900471767622817717178145402957386103156160866123414206515754559545686700073320564864741535495415748820323237803627813605189135356607064098502087439351413544065503419819632448171981837764546748959195246950946438116081461876790984871501812736687684060916351640636473722361191198422232078419396136435023418414211141358999220990625633119603395898357680899640253181202964194204405689128818515664072166155579142873935209872060322347661025303112468580576745090197847594090172358061138383881308859807115825051550494576755982340240453802200648681250828530473110841118191224471141789679112896630273022238260235700499552129992322950000687164039646973787275327029358365237234173551135056075647602187485606873613302906314559533532937301571942403127089647254423662199454404435469570524034064012027250501745711396451185410882634431247532282025791450349655128155028918892051346021328316356578376776627338706196591407435472185728399150489781441644514026496366291830579281740785555594054913804370153489066569583505764545313059785473368910491596409292905596469547006327915216710888739658087612366680571200986854479042808428494577134663047527753794367988699591904940748658484332335978842219031398375671122126811202256034016654260524497947364779604794681101304350583048462525278774774791062029739837018130730648957958000402193698622817236132879845131022951696032356703073119286206717171409395979016916866819169229930819303783068713552417609974081409196709261888646926577446859722730790002178930059331182895991494819271892919638795727084853749738987201236327337110435141689969575058059180031348853299363969819331035972560561851898450786859378313160410584450192653296987509277747608779837119843856202697474169552384159240487830870669756711232936447226515820292369453676977874749213364113666500726441332273643827272466641847452145396226820616863113984208752158782929596306071600654056910479787912252203233197492629520118751257302005873845289737050315832652205309307196163984780695976006603737111137654703557402843887181713353501177528343989416717661542220409868115040472616716556956454273029182831148391321480786369676843806662633249042159656802255082876239064248769711286368121579436090479863031454953581439759022141746426057932706643327927272218349103473707162086779024341227803532245213761110302016155734479734343886434377721796827195353417023872364251174791166006050366785455019743200863644631235044729817347673668637944931415977533337041798890530894610743312042848460931792070962327819392198700078574893667034821988442101237844039212314713551327246823111757753780329888865204360133330781163906703859152793731247730366233422167067655497975396389512457007931814003355987888655281598656371434939898522840623691899127065039878345617834588183454134679073164287331785600994220876822443959414107603919808975429365502528365895302952483027090768969435860348970010446591827177644674130392355740929076884881743576247491947036882798279172241507361723108180652673739208813557810785950280391755499276502041783949082230582430180278457092482736687642933040528604548185481616420737963531050273793154268097120653040632183939558057856469186383966961800282496556057584401218432828226781903041240783150281385766335748939883916324320069026814291698745789209659273476350662427866479426041006285457233132255073148420349477299807470224876852338670672897765522377886210016604890294354166023238665614453801456295879899181128177124671942642113138211895203817046093658793918014159503474243865600693105700393961998715298021226720756379081510008341038105508030666444065143230332066319798276086485820982128941078073509599639001621300440021377809566644909693013473401948426122824854900655649131319130539144971566927618797218490443563458725237603588476465387555080166952941257198544650497917281348616175539590635716536027464611239474712420255114305009714411534506211335989403441883943194635302804054714909189274547674938026087834070099039823657170582555356432572044716183116956321081681227860127726079061537445676855183793365468766996707621740307849394594056291588712096154554676632953402218242623540341523984786515370914734303233876033492965106868393658894246342227025537748405129619763976708847121518376330107607915361299481767811106774994359657840669033112707177965559254911007669726042476373139573250808501006334047148639679188558009339231975767289871354392479074190871422582052016850791927359861370811458505752840689539829094601547015391663987083970561438125269270449929747291443226605506734266589375124288566634489077451153367070067258696072131014475489442351680083983711086285988255610028407449033410141664916729919339095877015075373572715473665173398349883545299890108223596381033969737716668028141402528464363457057983915071587705738351656175623500118136443122640689059421173066203732743761358223900079499047028428662425538971610134479094123123711391817862457339636959918662111169190633252171012149596352674283254290907262447758709633247042640612398254701547895197924126617248481237681577655141705837236749531181963982298313016152278905758904058954394506526000901093306235869652280739091391631482718276160787057513653456032690348922127084397207092063470359061678105235961567127750253369037043556864721772023605962285999842839669082095523606000724572761002970150427612196961270247392797630743553972856925189347335986554950600159973580948098034319617466098579125500122641526266386753808919771291579507464186562447154646891806195950964034731352051802634742397828461846682197444178910961268875161451711153980049993380479907944185263159482178059342191475722888488754497789586110366942250465593423447452878689510138441443154212803192212153534970320371660309240720174359774667848887688980580404826556415008894616658091020657627106330404959981910450221531169646998545086260596615630558589692511006517357834224473360564190754106562520711106876175967221635419337447253536938678446699306545711540154558319689162407187771391378551264527241263439569213687251629682321384613163050350661931879111849134775556386803975873500422856979133580778002056669072365318258450170519723433882188991893472605622269661503769121427460693384927641382936504414607616356958428397932429909856181649151339261671510048573355367007995963881409618291842752859514331901758362139030619011855778426772325952313645310864618920172437920183815585336386516168066094253383619434739821290234865774078856703046461972396354322329849501790193904787657261712135083137188599121964969054297834830939105588800935876973268371886744239447441862166118685129927792782267416506515062424494825870169802131183612106001699267301428671609647804882365829898584194829825287785782820530134060068019675721231104573328281838282157288152241731501696740179995109539694328086986956909177082109931913736528886403629341714704854205539784442783093401334267117658932201869057421988165458353898114161549500472112606686097349335388366999950792071601131834490841504307985357123297066369396717717037764835369558741838351770345990204811855717786859290969308701172490778837226043050041279403882090072117530988654158173718088395677240064143524046979645697807460044125346424754927519657068950785382692492540421963751373861226081378550653617033185941123683942265738378874208435423848683859565920479812720967687012239087376087967542670787808830560003927229867155805400247611806266960725679996837390950839617704421434594066519519442721601715173700892968623130835786481789927028965544249816929782906336034396340640530658873959741825908731516400520579960357540798826353200445516103826988935469087763591164853382739534693561540100974620420573671563095960904236659812650854765512253593914089533192685498396062599941725643299627181438522866981898538252187497556450983449095104900738197464226379642768532514512609045208184667719605176137611390592477291015221022112067914327229972957808537569365979052798381022490162615461839252360078134176176170986693774719613628493912224120026907228376468043407896303616529025805888676075392060406770548842651225578355450461385890901692068725173272704846687992360850011929768194740611961019844259056968425194534539638418888697164267558354852164023134044655037432196229629358978161998446982091250300325030810738187871804056528086606807735095567329441946688342201830116133160613140617141768750328123107458213857695472334538044781401601145365944171407027035527310053255862900352618514967999292291530290882790966516738532852434439146685047793573193089020830960923291237459744356095320385891075286942905676865763805173567954508276557301517949614364644920952592187696280053613306837429432686120288044179341403486777216647891740901464289998946260814132953525806210977809442729191738050911656649046056396944567221058327410120851250741657006624738096964382722126480313870206426814604841851353020437222903986170594509565429913797408343313753524932501535267714448393872202088593586342073372992028024460609720059773465347492188879463302243092247905011959618818296081256324023502730680436650940927546863943267759781915958767021282374387453756022414929202025908423706632214738235498358992604027014703401683103221103740108133815022231192828989013527520887116670802261018785423360593358727670795656879498258138927937478323219103421914869510888584038161628778011290810675659690253745146251950517307781326397180644679228466258018542930999864919161028799990053473521032840927955166696008171104817808042588268108780364875001339336815677585509547127453672112180662013302735680632879093286694168396327232674874020830162599723857274720589600231246338131300787727769548180216224313283040164430668858457449059955839719123332011825624723921827989608759165353413505366599224995943115731558407274009440950537160169354524079206356704120944686315213853334629921908371703691875158415874226569324943697618453729513406489934525786841179933897911475356773884408808080564618898547959316009136564693881561304266641931979160814590231650939270558139826649010964664684026054637599325717324655515286425517546189333089006336951085244101812302980842789061393198942631621819977839385620102326953199443379054026575211629990757624199172000355205298578573818389504230562381614677624119392153869502724560945521364377052811817027761261374251651829865242021924130764254635744764786894499124244607162732566253657293086740696622049491500436990054007396967759973056759040057992410633035147904827420715429158136133040311520088932529684325450111475981033538952689059277821013696550719908914502973137646567681371182297344587924892962125547911811249076707354178719758282296898540421042414070017368331181299638457491164452357759675446560867302965695548656365883283595423504061417090770822649368893751996080218006049101585729122455788458241908748917346285176554624817373338362034917692810026093397421592140513042359337617201150232101277412169272387066655641563638451678751648643137144454715608895599424160023118237451542731128294289602439027592356901164153209054548263313665550295182223984552338669340423027357272380098786289281962073497380264288293304749114306451445742168884140413998550737233124092463221878088730650513878069046154401543000407355895036082744753366750351468252899290944346111286414202117566962958169335886707030358235687576220489792609897915597583912890467166965386060952658960692902101284053300960010545014098454309095816043741791303303057737094004344735153398817782462405887863417538491533190593338115679859429057483802675948765702787957178607963720516251247968823127983091222576414005309006585474474614575876664098398008575413291330477073224501551093624959783606013148728476869981947384904370510153033991310209338603204649676639085419098949907976512756926142212570059749992967687173874813655406033280350178514463652415616335011971501042725464074558196265575820059410901126611390064565930935928927609381791004461967585187058899180621321893852407431277196725450342449732324065261003182399032443492791677775641980271759570078319989850372506053194255320234884589457463264413658123109609890989956961561277736070054542231079709293279025281386903278509314125511280877010847836833904550567555526280576978521405209307053074326167311554645638450954375536316700329108813391082295497092840069065680984206800190482152200981435770922988559981789556752902385397558358891701238255472737516922866038616396905877286812710143656684795185099520544577978420672672175986013213225962303637682007417724886076559793065356940689576372723647474665226406323074587359120725241808428625819354172327153628316550852630929837060966446162723304235189351550076351356245603319475750032715611948407624659316527221062950534110894662472485101525475296577623506631757396453491468511609964218024227175183286489261751848319140480440533670407560467201864730910139726442258891319367403178563780848401181662000384532640692787986830793331467437491611941803483907214478218016552805577253171340663517472160091896269953083157564216699264970107076531150840558927992106339162209019066063745716746602435117780543801107764536150690382737098836786087901231577028523440491714430726928141685913463416390940788891493581758935902854830457135993621140007393187066039036337113737533591650792410080845610619983991842044283312787854634881135878959878485578060711135404509582448029646440592668629626777107274266463847373036251008593889257910637672733296316687847707590042869736467545185648749013226887230536480239072188916863257197415426061773450883213637609492387020646561952419926054280332670985821999663431559362051170824557241649027032892824103223739346204819815648154503863205884787777261241163431806086047353651685966082817910811555749394191850486966196904268759181961555793056777219706938878653722210526316044394464890129735583284773106313698121006547200412488216657874503103681022852897272883340937334102921229530549433698239162321895556377105563796834634729015546729982307544067646773646065566481608607315820715927014081026797316268880269295223809092579113691463140153400468043124974009912707571475636530407681103714231906023726265457434105143690433957989700357021059823187465551035636108389515682735998185210676190494178023312549076392795586620514720878888293548953687904523888831198451011572806540713309622032675190251568809393407582581317907855224774704260596706023344109273710463580614892930912126635279542625281014845449922920900844690961786414245832647777042291962177262505908295393608504815733673278551089193126651227009538878423861298004323373180730657942665161109470090209977187632970956643036354355559402441435828195043881371636039934635308107727477833906857760436376390666822664053290107902419497555011691612126561854106109464038606753285678976746159376631108548299310822239055775291398916117100201190779625177603873344516460695694147325416913797083723612794795855848665029393118525704601294802758206448831962997029470805291871072092938594555281486023408761185561433195214484033121225996465009627834412428140539609949402152164960004958653393030804042366440896604671804019676391646378812232464643266300542242173448947492331506067742609490058159949893116967525511309312765492912852495620103345489391690100229973582281736717352112794809420666454949308029133922476199595279151817815121483777470804699650116779922488117537536964086233230179427015423284256912447433308326595942589259837196351062776977191063543394560904367598765930736009428709584154851008802078246386642470759447998600771023235770182972256618058908575428080100471998553614747699422663948649179034261232752150492983567980591231765048571461441443129455709822005643199141661733443853355924355983658888652512371948123177613881667720134188843384974374138924025242711506560329244795587118687508651663973957044941587218231978004424115831232936832167710935995928438723263216657619005471074568831226883064205512496176393594202051472330826436539577166830407224816915226729037213391268765975130248035505006150584047808505365784718333190284972734446781902868264048641928245189271782880753922576039613587386139304864157596798553208300836715499483490135727601769891618202627114710626480863000844056484165334888340732811234825582165153752288859959646804093682247368868271600900672830678921891261465964013598011312371147010304244226624341335745462164023916014629600799357394752024227296997275166233156463131930943665843969299693513595137098119699357592172114982557188545124173247262951591945997083972053357883848846092030167185094118836133338597151204639249453834232769951538042691237185204815063427096553807671555200458563930752020891353016897685777866771351092176813057273720279460478269082597627871334937065245984183021906039385147438694933450520116096537931075458547593031990219956041170189471428016327369279988799175620981669184668198018182876971300245617411427648098883533697281072641101889958433138969111478680420415805335017923851304445547879375852093946266503437613303283591501744061707505524159864468360920121049804330718394528042137186258113798942358106326900395323704156459885135185478009111333064340620272561747989362984742234409150711879828897927702154767885911021136967975254591357919874432954682373771695097402497291547156227319726743628324499605008122642058811039086471720464150267061484601655636977668689270041291042412635388777387436327630797857011438959816573776770910342566501724712752376965961834401285344060428087579335287981705084577640025593245096469318103417130466920608429625752216987032874450481477981275754898002633612462297626803132093217673342679502661593645960014950433666843076039238511936608167453291165674009737662702538727894624928651024782198408591522078444297194196453446451277853537247360220048858895202658274049142201348017189863903934044200286262271066631810776535988018406945606590534917289924943272544382795448951685371938126491150996288075996373468513638554553906888999650300994019343231331539122051321812072152129102459322360355459396367861451532149176110682685665607744259497320283732162632970202531813459289845267490490837090316248109063172792625658580066016438952202026898418426518469253124992656314837622072256397149649648175657444602394125814932180038750508029829292887191614867295755546115250872086233925629142956757494134917610025689298656165908951485190945211526847734873698764770368776349290788809513846316739784455880279692186464616790043016507405850989645210871091465836073586157537487630970602352667643663348216609394166768444663329435683670254729525583257119144834793431823072076174448517712313006500144210426056808968649402850403876086641624682415975250769896297760411349545068756534948664987925599190813411927580460477947750791266690487817212105022658552862485320649025736571892471023276181853520865365998740417326977756264242512198234532234717403551439207279080521603731307770857188021854780814572069885297145677683320204119320128191911460579532453090951854835152619580335174926182307027148563424032423454594912261544495578982188996216875066668297492522149838066450863087719412600823441435064891655335405307046832065870322731269245571637832117052154143564963877451351879409435004023438410971331431159522890927169345442186973009767738202800505513928356737136762525732455267968947599945473436720006186888077328024661740032714378410047297960044853613435286817886096072517886771474504117787168134721635213137945774373657499484474109358547798923491254306903966702775056250454308849699043545422989346982367894381176531512995661039754554273838831445439128745214142549309995197616831597933371750778794902596355212780948828192819
0xe49efDb4...4ecA9a091
2.804563868112603 Eth
Nonce: 2
2.709862968112603 Eth
Nonce: 3
0.0947009
(Ethermine)
1,454.401833447900754919 Eth1,454.456459444344926575 Eth0.054625996444171656

Execution Trace

PxCvx.60e06040( )
// Sources flattened with hardhat v2.8.3 https://hardhat.org

// File @openzeppelin/contracts/utils/[email protected]

// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

/**
 * @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/[email protected]

// OpenZeppelin Contracts v4.4.1 (access/Ownable.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 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 @openzeppelin/contracts/security/[email protected]

// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}


// File @openzeppelin/contracts/utils/math/[email protected]

// OpenZeppelin Contracts (last updated v4.5.0) (utils/math/Math.sol)

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a / b + (a % b == 0 ? 0 : 1);
    }
}


// File @openzeppelin/contracts/utils/[email protected]

// OpenZeppelin Contracts v4.4.1 (utils/Arrays.sol)

/**
 * @dev Collection of functions related to array types.
 */
library Arrays {
    /**
     * @dev Searches a sorted `array` and returns the first index that contains
     * a value greater or equal to `element`. If no such index exists (i.e. all
     * values in the array are strictly less than `element`), the array length is
     * returned. Time complexity O(log n).
     *
     * `array` is expected to be sorted in ascending order, and to contain no
     * repeated elements.
     */
    function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
        if (array.length == 0) {
            return 0;
        }

        uint256 low = 0;
        uint256 high = array.length;

        while (low < high) {
            uint256 mid = Math.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds down (it does integer division with truncation).
            if (array[mid] > element) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
        if (low > 0 && array[low - 1] == element) {
            return low - 1;
        } else {
            return low;
        }
    }
}


// File @openzeppelin/contracts/utils/[email protected]

// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}


// File @openzeppelin/contracts/utils/[email protected]

// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)

/**
 * @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/cryptography/[email protected]

// OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/ECDSA.sol)

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        } else if (error == RecoverError.InvalidSignatureV) {
            revert("ECDSA: invalid signature 'v' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        // Check the signature length
        // - case 65: r,s,v signature (standard)
        // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else if (signature.length == 64) {
            bytes32 r;
            bytes32 vs;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            assembly {
                r := mload(add(signature, 0x20))
                vs := mload(add(signature, 0x40))
            }
            return tryRecover(hash, r, vs);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }
        if (v != 27 && v != 28) {
            return (address(0), RecoverError.InvalidSignatureV);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}


// File contracts/tokens/ERC20SnapshotSolmate.sol

// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Snapshot.sol)



/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
    /*///////////////////////////////////////////////////////////////
                                  EVENTS
    //////////////////////////////////////////////////////////////*/

    event Transfer(address indexed from, address indexed to, uint256 amount);

    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 amount
    );

    /*///////////////////////////////////////////////////////////////
                             METADATA STORAGE
    //////////////////////////////////////////////////////////////*/

    string public name;

    string public symbol;

    uint8 public immutable decimals;

    /*///////////////////////////////////////////////////////////////
                              ERC20 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;

    mapping(address => mapping(address => uint256)) public allowance;

    /*///////////////////////////////////////////////////////////////
                             EIP-2612 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 internal immutable INITIAL_CHAIN_ID;

    bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;

    mapping(address => uint256) public nonces;

    /*///////////////////////////////////////////////////////////////
                               CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    constructor(
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) {
        name = _name;
        symbol = _symbol;
        decimals = _decimals;

        INITIAL_CHAIN_ID = block.chainid;
        INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
    }

    /*///////////////////////////////////////////////////////////////
                              ERC20 LOGIC
    //////////////////////////////////////////////////////////////*/

    function approve(address spender, uint256 amount)
        public
        virtual
        returns (bool)
    {
        allowance[msg.sender][spender] = amount;

        emit Approval(msg.sender, spender, amount);

        return true;
    }

    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal {
        allowance[owner][spender] = amount;

        emit Approval(owner, spender, amount);
    }

    function transfer(address to, uint256 amount)
        public
        virtual
        returns (bool)
    {
        _beforeTokenTransfer(msg.sender, to, amount);

        balanceOf[msg.sender] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(msg.sender, to, amount);

        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual returns (bool) {
        _beforeTokenTransfer(from, to, amount);

        uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.

        if (allowed != type(uint256).max)
            allowance[from][msg.sender] = allowed - amount;

        balanceOf[from] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(from, to, amount);

        return true;
    }

    /*///////////////////////////////////////////////////////////////
                              EIP-2612 LOGIC
    //////////////////////////////////////////////////////////////*/

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");

        // Unchecked because the only math done is incrementing
        // the owner's nonce which cannot realistically overflow.
        unchecked {
            address recoveredAddress = ECDSA.recover(
                keccak256(
                    abi.encodePacked(
                        "\x19\x01",
                        DOMAIN_SEPARATOR(),
                        keccak256(
                            abi.encode(
                                keccak256(
                                    "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
                                ),
                                owner,
                                spender,
                                value,
                                nonces[owner]++,
                                deadline
                            )
                        )
                    )
                ),
                v,
                r,
                s
            );

            require(
                recoveredAddress != address(0) && recoveredAddress == owner,
                "INVALID_SIGNER"
            );

            allowance[recoveredAddress][spender] = value;
        }

        emit Approval(owner, spender, value);
    }

    function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
        return
            block.chainid == INITIAL_CHAIN_ID
                ? INITIAL_DOMAIN_SEPARATOR
                : computeDomainSeparator();
    }

    function computeDomainSeparator() internal view virtual returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    keccak256(
                        "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
                    ),
                    keccak256(bytes(name)),
                    keccak256("1"),
                    block.chainid,
                    address(this)
                )
            );
    }

    /*///////////////////////////////////////////////////////////////
                       INTERNAL MINT/BURN LOGIC
    //////////////////////////////////////////////////////////////*/

    function _mint(address to, uint256 amount) internal virtual {
        _beforeTokenTransfer(address(0), to, amount);

        totalSupply += amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(address(0), to, amount);
    }

    function _burn(address from, uint256 amount) internal virtual {
        _beforeTokenTransfer(from, address(0), amount);

        balanceOf[from] -= amount;

        // Cannot underflow because a user's balance
        // will never be larger than the total supply.
        unchecked {
            totalSupply -= amount;
        }

        emit Transfer(from, address(0), amount);
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

/**
 * @dev This contract extends an ERC20 token with a snapshot mechanism. When a snapshot is created, the balances and
 * total supply at the time are recorded for later access.
 *
 * This can be used to safely create mechanisms based on token balances such as trustless dividends or weighted voting.
 * In naive implementations it's possible to perform a "double spend" attack by reusing the same balance from different
 * accounts. By using snapshots to calculate dividends or voting power, those attacks no longer apply. It can also be
 * used to create an efficient ERC20 forking mechanism.
 *
 * Snapshots are created by the internal {_snapshot} function, which will emit the {Snapshot} event and return a
 * snapshot id. To get the total supply at the time of a snapshot, call the function {totalSupplyAt} with the snapshot
 * id. To get the balance of an account at the time of a snapshot, call the {balanceOfAt} function with the snapshot id
 * and the account address.
 *
 * NOTE: Snapshot policy can be customized by overriding the {_getCurrentSnapshotId} method. For example, having it
 * return `block.number` will trigger the creation of snapshot at the begining of each new block. When overridding this
 * function, be careful about the monotonicity of its result. Non-monotonic snapshot ids will break the contract.
 *
 * Implementing snapshots for every block using this method will incur significant gas costs. For a gas-efficient
 * alternative consider {ERC20Votes}.
 *
 * ==== Gas Costs
 *
 * Snapshots are efficient. Snapshot creation is _O(1)_. Retrieval of balances or total supply from a snapshot is _O(log
 * n)_ in the number of snapshots that have been created, although _n_ for a specific account will generally be much
 * smaller since identical balances in subsequent snapshots are stored as a single entry.
 *
 * There is a constant overhead for normal ERC20 transfers due to the additional snapshot bookkeeping. This overhead is
 * only significant for the first transfer that immediately follows a snapshot for a particular account. Subsequent
 * transfers will have normal cost until the next snapshot, and so on.
 */

contract ERC20SnapshotSolmate is ERC20 {
    // Inspired by Jordi Baylina's MiniMeToken to record historical balances:
    // https://github.com/Giveth/minimd/blob/ea04d950eea153a04c51fa510b068b9dded390cb/contracts/MiniMeToken.sol

    using Arrays for uint256[];
    using Counters for Counters.Counter;

    // Snapshotted values have arrays of ids and the value corresponding to that id. These could be an array of a
    // Snapshot struct, but that would impede usage of functions that work on an array.
    struct Snapshots {
        uint256[] ids;
        uint256[] values;
    }

    mapping(address => Snapshots) private _accountBalanceSnapshots;
    Snapshots private _totalSupplySnapshots;

    // Snapshot ids increase monotonically, with the first value being 1. An id of 0 is invalid.
    Counters.Counter private _currentSnapshotId;

    /**
     * @dev Emitted by {_snapshot} when a snapshot identified by `id` is created.
     */
    event Snapshot(uint256 id);

    constructor(
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) ERC20(_name, _symbol, _decimals) {}

    /**
     * @dev Creates a new snapshot and returns its snapshot id.
     *
     * Emits a {Snapshot} event that contains the same id.
     *
     * {_snapshot} is `internal` and you have to decide how to expose it externally. Its usage may be restricted to a
     * set of accounts, for example using {AccessControl}, or it may be open to the public.
     *
     * [WARNING]
     * ====
     * While an open way of calling {_snapshot} is required for certain trust minimization mechanisms such as forking,
     * you must consider that it can potentially be used by attackers in two ways.
     *
     * First, it can be used to increase the cost of retrieval of values from snapshots, although it will grow
     * logarithmically thus rendering this attack ineffective in the long term. Second, it can be used to target
     * specific accounts and increase the cost of ERC20 transfers for them, in the ways specified in the Gas Costs
     * section above.
     *
     * We haven't measured the actual numbers; if this is something you're interested in please reach out to us.
     * ====
     */
    function _snapshot() internal virtual returns (uint256) {
        _currentSnapshotId.increment();

        uint256 currentId = _getCurrentSnapshotId();
        emit Snapshot(currentId);
        return currentId;
    }

    /**
     * @dev Get the current snapshotId
     */
    function _getCurrentSnapshotId() internal view virtual returns (uint256) {
        return _currentSnapshotId.current();
    }

    /**
     * @dev Retrieves the balance of `account` at the time `snapshotId` was created.
     */
    function balanceOfAt(address account, uint256 snapshotId)
        public
        view
        virtual
        returns (uint256)
    {
        (bool snapshotted, uint256 value) = _valueAt(
            snapshotId,
            _accountBalanceSnapshots[account]
        );

        return snapshotted ? value : balanceOf[account];
    }

    /**
     * @dev Retrieves the total supply at the time `snapshotId` was created.
     */
    function totalSupplyAt(uint256 snapshotId)
        public
        view
        virtual
        returns (uint256)
    {
        (bool snapshotted, uint256 value) = _valueAt(
            snapshotId,
            _totalSupplySnapshots
        );

        return snapshotted ? value : totalSupply;
    }

    // Update balance and/or total supply snapshots before the values are modified. This is implemented
    // in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, amount);

        if (from == address(0)) {
            // mint
            _updateAccountSnapshot(to);
            _updateTotalSupplySnapshot();
        } else if (to == address(0)) {
            // burn
            _updateAccountSnapshot(from);
            _updateTotalSupplySnapshot();
        } else {
            // transfer
            _updateAccountSnapshot(from);
            _updateAccountSnapshot(to);
        }
    }

    function _valueAt(uint256 snapshotId, Snapshots storage snapshots)
        private
        view
        returns (bool, uint256)
    {
        require(snapshotId > 0, "ERC20Snapshot: id is 0");
        require(
            snapshotId <= _getCurrentSnapshotId(),
            "ERC20Snapshot: nonexistent id"
        );

        // When a valid snapshot is queried, there are three possibilities:
        //  a) The queried value was not modified after the snapshot was taken. Therefore, a snapshot entry was never
        //  created for this id, and all stored snapshot ids are smaller than the requested one. The value that corresponds
        //  to this id is the current one.
        //  b) The queried value was modified after the snapshot was taken. Therefore, there will be an entry with the
        //  requested id, and its value is the one to return.
        //  c) More snapshots were created after the requested one, and the queried value was later modified. There will be
        //  no entry for the requested id: the value that corresponds to it is that of the smallest snapshot id that is
        //  larger than the requested one.
        //
        // In summary, we need to find an element in an array, returning the index of the smallest value that is larger if
        // it is not found, unless said value doesn't exist (e.g. when all values are smaller). Arrays.findUpperBound does
        // exactly this.

        uint256 index = snapshots.ids.findUpperBound(snapshotId);

        if (index == snapshots.ids.length) {
            return (false, 0);
        } else {
            return (true, snapshots.values[index]);
        }
    }

    function _updateAccountSnapshot(address account) private {
        _updateSnapshot(_accountBalanceSnapshots[account], balanceOf[account]);
    }

    function _updateTotalSupplySnapshot() private {
        _updateSnapshot(_totalSupplySnapshots, totalSupply);
    }

    function _updateSnapshot(Snapshots storage snapshots, uint256 currentValue)
        private
    {
        uint256 currentId = _getCurrentSnapshotId();
        if (_lastSnapshotId(snapshots.ids) < currentId) {
            snapshots.ids.push(currentId);
            snapshots.values.push(currentValue);
        }
    }

    function _lastSnapshotId(uint256[] storage ids)
        private
        view
        returns (uint256)
    {
        uint256 idsLen = ids.length;

        if (idsLen == 0) {
            return 0;
        } else {
            return ids[idsLen - 1];
        }
    }
}


// File contracts/PxCvx.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.12;



contract PxCvx is ERC20SnapshotSolmate("Pirex CVX", "pxCVX", 18), Ownable {
    /**
        @notice Epoch details
                Reward/snapshotRewards/futuresRewards indexes are associated with 1 reward
        @param  snapshotId               uint256    Snapshot id
        @param  rewards                  bytes32[]  Rewards
        @param  snapshotRewards          uint256[]  Snapshot reward amounts
        @param  futuresRewards           uint256[]  Futures reward amounts
        @param  redeemedSnapshotRewards  mapping    Redeemed snapshot rewards
     */
    struct Epoch {
        uint256 snapshotId;
        bytes32[] rewards;
        uint256[] snapshotRewards;
        uint256[] futuresRewards;
        mapping(address => uint256) redeemedSnapshotRewards;
    }

    // Address of currently assigned operator
    address public operator;

    // Epochs mapped to epoch details
    mapping(uint256 => Epoch) private epochs;

    event SetOperator(address operator);
    event UpdateEpochFuturesRewards(
        uint256 indexed epoch,
        uint256[] futuresRewards
    );

    error NotAuthorized();
    error NoOperator();
    error Paused();
    error ZeroAddress();
    error ZeroAmount();
    error InvalidEpoch();
    error InvalidFuturesRewards();
    error MismatchedFuturesRewards();

    modifier onlyOperator() {
        if (msg.sender != operator) revert NotAuthorized();
        _;
    }

    modifier onlyOperatorOrNotPaused() {
        address _operator = operator;

        // Ensure an operator is set
        if (_operator == address(0)) revert NoOperator();

        // This contract shares the same pause state as the operator
        if (msg.sender != _operator && Pausable(_operator).paused())
            revert Paused();
        _;
    }

    /** 
        @notice Set a new operator address
        @param  _operator  address  New operator address    
     */
    function setOperator(address _operator) external onlyOwner {
        if (_operator == address(0)) revert ZeroAddress();

        emit SetOperator(_operator);

        // If it's the first operator, also set up 1st epoch with snapshot id 1
        // and prevent reward claims until subsequent epochs
        if (operator == address(0)) {
            uint256 currentEpoch = getCurrentEpoch();
            epochs[currentEpoch].snapshotId = _snapshot();
        }

        operator = _operator;
    }

    /** 
        @notice Return the current snapshotId
        @return uint256  Current snapshot id
     */
    function getCurrentSnapshotId() external view returns (uint256) {
        return _getCurrentSnapshotId();
    }

    /**
        @notice Get current epoch
        @return uint256  Current epoch
     */
    function getCurrentEpoch() public view returns (uint256) {
        return (block.timestamp / 1209600) * 1209600;
    }

    /**
        @notice Get epoch
        @param  epoch            uint256    Epoch
        @return snapshotId       uint256    Snapshot id
        @return rewards          address[]  Reward tokens
        @return snapshotRewards  uint256[]  Snapshot reward amounts
        @return futuresRewards   uint256[]  Futures reward amounts
     */
    function getEpoch(uint256 epoch)
        external
        view
        returns (
            uint256 snapshotId,
            bytes32[] memory rewards,
            uint256[] memory snapshotRewards,
            uint256[] memory futuresRewards
        )
    {
        Epoch storage e = epochs[epoch];

        return (e.snapshotId, e.rewards, e.snapshotRewards, e.futuresRewards);
    }

    /**
        @notice Get redeemed snapshot rewards bitmap
        @param  account  address   Account
        @param  epoch    uint256   Epoch
        @return uint256  Redeemed snapshot bitmap
     */
    function getEpochRedeemedSnapshotRewards(address account, uint256 epoch)
        external
        view
        returns (uint256)
    {
        return epochs[epoch].redeemedSnapshotRewards[account];
    }

    /**
        @notice Add new epoch reward metadata
        @param  epoch           uint256  Epoch
        @param  token           address  Token address
        @param  snapshotReward  uint256  Snapshot reward amount
        @param  futuresReward   uint256  Futures reward amount
     */
    function addEpochRewardMetadata(
        uint256 epoch,
        bytes32 token,
        uint256 snapshotReward,
        uint256 futuresReward
    ) external onlyOperator {
        Epoch storage e = epochs[epoch];

        e.rewards.push(token);
        e.snapshotRewards.push(snapshotReward);
        e.futuresRewards.push(futuresReward);
    }

    /**
        @notice Set redeemed snapshot rewards bitmap
        @param  account   address  Account
        @param  epoch     uint256  Epoch
        @param  redeemed  uint256  Redeemed bitmap
     */
    function setEpochRedeemedSnapshotRewards(
        address account,
        uint256 epoch,
        uint256 redeemed
    ) external onlyOperator {
        epochs[epoch].redeemedSnapshotRewards[account] = redeemed;
    }

    /**
        @notice Update epoch futures rewards to reflect amounts remaining after redemptions
        @param  epoch           uint256    Epoch
        @param  futuresRewards  uint256[]  Futures rewards
     */
    function updateEpochFuturesRewards(
        uint256 epoch,
        uint256[] memory futuresRewards
    ) external onlyOperator {
        if (epoch == 0) revert InvalidEpoch();

        uint256 fLen = epochs[epoch].futuresRewards.length;

        if (fLen == 0) revert InvalidEpoch();
        if (futuresRewards.length == 0) revert InvalidFuturesRewards();
        if (futuresRewards.length != fLen) revert MismatchedFuturesRewards();

        epochs[epoch].futuresRewards = futuresRewards;

        emit UpdateEpochFuturesRewards(epoch, futuresRewards);
    }

    /** 
        @notice Mint the specified amount of tokens to the specified account
        @param  account  address  Receiver of the tokens
        @param  amount   uint256  Amount to be minted
     */
    function mint(address account, uint256 amount) external onlyOperator {
        if (account == address(0)) revert ZeroAddress();
        if (amount == 0) revert ZeroAmount();

        _mint(account, amount);
    }

    /** 
        @notice Burn the specified amount of tokens from the specified account
        @param  account  address  Owner of the tokens
        @param  amount   uint256  Amount to be burned
     */
    function burn(address account, uint256 amount) external onlyOperator {
        if (account == address(0)) revert ZeroAddress();
        if (amount == 0) revert ZeroAmount();

        _burn(account, amount);
    }

    /** 
        @notice Approve allowances by operator with specified accounts and amount
        @param  from    address  Owner of the tokens
        @param  to      address  Account to be approved
        @param  amount  uint256  Amount to be approved
     */
    function operatorApprove(
        address from,
        address to,
        uint256 amount
    ) external onlyOperator {
        if (from == address(0)) revert ZeroAddress();
        if (to == address(0)) revert ZeroAddress();
        if (amount == 0) revert ZeroAmount();

        _approve(from, to, amount);
    }

    /**
        @notice Snapshot token balances for the current epoch
     */
    function takeEpochSnapshot() external onlyOperatorOrNotPaused {
        uint256 currentEpoch = getCurrentEpoch();

        // If snapshot has not been set for current epoch, take snapshot
        if (epochs[currentEpoch].snapshotId == 0) {
            epochs[currentEpoch].snapshotId = _snapshot();
        }
    }
}