ETH Price: $2,249.38 (-1.09%)

Transaction Decoder

Block:
18834886 at Dec-21-2023 02:38:23 PM +UTC
Transaction Fee:
0.164351488 ETH $369.69
Gas Used:
3,209,990 Gas / 51.2 Gwei

Account State Difference:

  Address   Before After State Difference Code
(beaverbuild)
16.328923886831574965 Eth16.335371138142637345 Eth0.00644725131106238
0xbEaE8e32...8453b92f6
0 Eth
Nonce: 0
0 Eth
Nonce: 1
From: 0 To: 916615430295339841526564107065163164624131077178728337954298516930870723230116025421901262824792862047308244253797784273985360317060723423259703374569384827235366269555406447109044159125783084909184912352898809708862263625274151645082278559122916709536501909215990338621592733506127989274441634940945229610677534707442047808322404763144728656365970569070103417306894829230118233114962055388628759616578329461332541590592934675636074128040993564625768267318537495110302819486754305314232685251996710470848055222040781621854766881043274017802431452172855441807616154453589131975158006029592194415188759322448781149963752070456788863711885513618465202211597922380683284375119509436145852500596227193747039672252608904265789748988835560870922143606862847181130867264313295399356170409010457598037259929321330782304650464018567870841657851338698564624567870364903162031364951425488743343648878549878719486277047523723999552427719423490295672589339308204727977221823431165543516274949861041377145088131747655989397322865763982410815079817867468761788109288713941331978655276628353067747385751561235724837453860669279279156565949094068987214677081398579818034566839014710392353581031687811118822384764812227239157610857135337816660032507193005684068659317653907216932804135982222231381543882440093995338400185970609244635698272088873403470428843088332104610161308650314439694687646849106506359471107176131734155766963210063781110772965454787428583791677885233553985467436194891991737229938549144567543175206644788374748988528524460716268778688795369762819431077107447848390759406443506921073302927288352372411996802095260588576350869143398608612001785935734680449814871936995514310251469469300724467508016714682539932193272202281016919774389499861663958645424904083646297074344923512961230744034090508948990211441520572525841564933658329370512575934295811226133605058805611221211087420472656806748920437594387121041639657786812477703632482244523952711690684001328413156156270120367399151364712461224172940054428477269868172999738559643905902317894078619065271718637546408723309219789484235318924539337549933143465699412620947075686572859322600402731829009344428286462121581056835695966053822432486544547250708980167246747033630840246294391294505547663620274469190705411049712786406503724706083597331841188797330470967695069706766061281753578966792548121464466131065657913704894044512910106167737703062640844436424498054171989611367415841626064417667201049576358601487316746212772673073290040341892964289101062697113421846143215959139769574214234406257646361195006656426731775954692547932604978173182872910967618919662264991175479593049851290645996662737958465439354936481565557994008192429179088219663444282548474989093640927295296340566363497315958942854908743241351322276815549380261398359379330723692920425849322983675627561744079445200366473056665862841628388475795411368256324647178685648136711586874751176181454744483124904101118011177346668492430344654540366693957576984286838605517821846895954397470008197764832733004735024250785121538145350309096567511415067820396168674134441733363957758448996553457912836207999472186309261814328805171386163839635553198598627108941040750150850943808566309698651006428358638935294762720322090741534889140953180037392966283234810196288968537033487001437873717677420078087756564990912407480129632595258543533366336482428903371619693224992307246961382074339999651931053748404868354949928407827992197774392097985709870307050591762438471485384228812077262734211124045667222962845278595108569900065391648491340277563204697442142087803777051153991723397451328779025033732844848198077316300776823649976484427361745763538428590610146323762305957053577944615414374304563350571784655661385706640864739565431123555483773933668136084821989416818108835336793910400395306715776691007555670070902368104394944863088857108088625773608983177764168719012643516078451456156633120990025909967702694430687182976292672586426202319277547944929569029558075569109333844124880799492358660881536756340431694330412883325791110472965116526603833522704342648927941005611617699601031054165654248708406145451876505869856148801002728039456919231256683558719824678609103923508697150628988517296046893287706959304234548521667598668757031266092752565989053745492517276354249423055989769186089364435060920256352249602665039313840837387355492057609182846559108587016256781030408564841167603956420525367021705019466826250433636171445858473996195693350533761684087180341578523912894719149645881504267796725185549045831257297212328060728087950333679266428807893326830274938284445817200890254155853007376936128445299581109894071644694573058936395013837105928133567665976517678233158681830772929002420880821961391173012641180523859874825352117782326681158183814333012437660954603110077061283829269113875451457310555394335425839389780051442006363754947556377177476357011548953279332596939173085614970556690380262730040687924118253239707810985455443404270225280631845151318465322970123431958497107189634562485768771222389230821347787965307900931377650540020001726824277481981823555669794159031822206174735456117559506184807741671264091377464669360808421430751632455074734727240226393681458712708441024723013677936597204036005016234586040326131863954393084720867660613390990937027464260524919130867664014328880471462224005396230429771448866126210186637377241163007100634507190879638697386282642977794271526297669446575360761488628433369543392305834937225044793327771929208036073016901373428474360344295494240255606126522056042385051489410393108508937736399777649224765888428822413942084146393709463086223835023983028133702696145633452901784844493583728251147419431011555096794442644635852206266563258070760122129976856578639782196988633299510650215373596064126360249408606189555185434072452061384011237667060418633938037414075930268003675739358395812353343760851312699999282800631699750101275809554422608563361653585475537916181123039071464664852635260096562915585045389950826529485099925667962368250875611496129352659585166692327267652833069558113275133392384810613084465094755568998272851298998800915712622429878774789531066348184436228471090314461789919170614695191223219222640547666188063829691990910070709866159027697359307535538139006053682671522238898789526046090243206972023773060717803611594911559929379054073915431408539626000954686429733190242677783574153900579802568298520617041159577677467790053482561808637164515738296676108114837193930705409046163678411563949088345287059853814836515214430707350295305596287347497309764793876881002395376157535769708661274595425020603494960837773471808398406828550297700050451561810061108925656239843971765482415322469883974695295062639804161711023641383985633149643126715480676307623708092346639035489706494062623357583740281736995654520662362753527419034381956775077228770242649321175989600712532653826906546820564059150655492787083070852699745540982642197087142150971646723408632206670822515133672908349387489189007819226179001652699247235828016331289084728528089420719856384499460600897859016760286795746129406953472903422714588471194399069655933028791320905876894631662550780287455595689442758729145035311482624968731171158801040227511335327335164271150768193185945958430520676532188149083447166305038576255338249285548553292116475481537585193403431858890868832180352895797235238801772408627405478553882048104289104083016897397265787628638225811152730298963387709462275834226823957113351614460695267554246863618700871903183864536981404642911684815698542802014656241478508189983399703090189836537053378267786392208337818599271539289897634140823366276271222233873056733940058108037677820545165084627497140401161628575334674237895033557509817773863165934992298566403483016455971103875524662871801973995198715835294311892944861494600475560640093663610224431544544776606402158914378770052918264021561744426140141139519400157701207866059156235959371608302440462840170164926177922277376005520244535672572162543324661971401585695811393328058769308701241957600872736432997993733651505906228959470512335933291525456469830181314441768974426126961018836742220429513724115991334012955030396968627392451279443203798789063039322144401088115756378436985081734416459825264107564548668953836436074973317623098524010168930603088791926206748604647299106096639509100356500438723576605104817023133865000439578760853153334360112150417111513592521642903081797634185917822967046865576985252993879009527988787983746264311185098134557224578440348993121084153380870243786042115543410443266506761151004454899396685224303619431185627678276142405430181745978042177039613474308299343800797823197290444761637871979790340216712762931149697396364756903061453127701417012073196075044214153471894429913159390912740723285886691711560704313103607797338453951750431692301124338891643415875482847819901275381223141320688839166689578925924769044136843750048318070572351735797135497655672405788690648365537309971193079205430974149522459724324211962517102989160893818668577301103544103913759249684460240082993854620851419223251347349359498773507601615122491620141569922265554348127341971953883314796255910099912661510010394694212509998900317945526726027954709790141470249643911765479075298561736795203194274894129641943563717946012422187500941035079269959430299617303670944321802593531542092493283724641804089433714901440128772162053418850482654442177108907305570142681694017724024909459548597063969661019177652410694401990371541835379138434622290286329023281351776186647126684751840657991708918573597585645018587749344108404976942085837989931545775612541640706854308225753936956967576122002481122217155660961919966623286956429298853226008013932050563554309480001250317848839066949877946292404337799880358335438305330229868790797058096695094817819469678928581474425450090387785905046558827071299194377717741895895136146497806437429916111370566059107113151680778127308130579286436078951639282210488357987226359198083268712901179519032068468624427348140754537520863617207932156954766693055679934674234408320693377809275529719678550351022108003470154387309615694862130454610175496370274145629974019033206189199093309246462291897025243154784342863224198459902338716488039622143589219351603654722921037986465299093155958272869573790723197565330078460186437093839972738204998415043744947318695007627281928638104768939213781083250519004647724979352476008000281359503543651926987555118722822304473191845793274297825902582145422080968655285548185674693158506071001607857402074681701725190776014029474745931259321310828443802239819887109184304895707465216065251421495250746452497500506977304046484921465374179503378307624657568965198626737856423737273531280924296976073325084736338814643548827590336736816499377264680424927758238687117129265251611159591600297982566978805840466224095459940695837495266111009796064627682543457368632566712338824309774223692928059989803055703855551251077789970687144061613365588779730894725000450303906814505821894205895767994906153698793308397650043429231147931672183024996558320690966017287030321376559851829389875977628586330256189144354088746118607595546386036022359921724017172625826390830218795754770188331569318861743152222011785625059051836499326662131348958009677647181867847651603532646089772045587484067713760165696939160373261954040612276097742449418441627184981021196144796402455167199823060051742971361345842382281596177214629829744814291315438460375460191735152245283711659914872557772016319714729289941374437937606373862990889829036888801255858910394637924213924475583043716676945322614159976105679585573514731621085763144366721796508167101112128317663232677115707861437997700058185457542448369498901540513683589166595055944625930793315977302210956909334164104470684084091472176648301412244518554500748696049012484609556192813624616974145812081424107486286954546482293548605731048860573533297473963927203041903706382865933976920566656792336274789042202098723303114821879566643108461762254287944901794644026128434780980844010686729312974271517808798612276891409430791968279390671338258070927184211703712258345146717706685481113405149050546399011800690957119446543363262987791722798180749078417823694965756746045637579912603596512248684781923183660514935703447498194839277281232981097740294588829894072872261175395379678805974204220654417055615813014486349069467718320880092963666882212706572336330769530469448784078150984771643341079894158581924123150651061126577100235084202904143965042774443412201198580712391167932724593536806602857506035970370512730232748461758788270080509702492006497889222943261572261679794832716885576995974413717975571994957618993565158165335366684318596438401407129580205223596096041708135000379491092313332709740674162289991690582618069117914801356478240355320080091016168677218761939827702622205509591733304104510676666162661862272187864083918760347932852856847362258620347431577194354096412556173996294749023662938322336002750086507429190826580917460235891603890919046756658993586921758908757183582889255058297367885968264094243410270766305891715188402575501275431686206438159720143097042384563707462274085875416051844254290890098488270258278595125798600827341382930968130604391883568188154565764954830114770409969863122790391662873444318334738859388832097723086377829945113289136372796532793743102981099796195491808139034176269063440896156469820479291151292498633995422550860686212819956189936661006283467039255204984337242144977144458631091222020040784712531076335222073720140361232708175320526765448376459291792843892275364881925900273822878219709399591376855938106413495031328791848883218904212263294062094607055853015286406158902067720214159207565289511341349596762150119779127911591992508848701361285548796919203667717134411232577595100822135524913117526991432252086072044366460351305886936638580855728308692564049475822556762833426621289727585642219795932083035091995769673142055692998941451215279555169557845624919818173108007774614223558180005949602779732998858601185161157295864418277884587555479097889909207906813712881014247042767017891957402900787898024102967065798111759358960519127717068597982675633046245142962958165925724221413198733470445773116190303243953462967612864269117216558994859769937294114377875911182644045049812075860973168772353737361297786882490282431208122088579480081634439034350868468863550515494353770193882242950976804599804745680295871009091651540373853463417241263368757519538868592980364599394531100751722744598395967614662631523202077498248927281666076698516521340235222992912099552254027904362294898981170440529941386107745769462105844494627537075719991115299951440904929212727946895590187956945536630824363485500089862151212204177866385677239320885795652259458942357368420723091857789043475308333281303986162399797802831191369044506524555088460780829019718440828816985338311351109536830983196240775150034402757048945108852501188970260596350519647046371369981755947065573966368757044220291583137807988400202011618141628287810067950044008100353243447960794999883817517083185419001064819742503836653069424804805344080937624118454666594387651735346850499518140964428769018062609838979661045727150407280618532339569000762793697415117401638395174358989080665418104335610539918468339667957895072681396132000805698468085982996061284691750252635040779986155745412559369362336740571592307821705291699665782324654164188234350445779118050909037731832104324298058785177442086440497209865618525693558140959285007832227524177092169533811202823668798036121554094769565206921850734673245938677171345638787366806673939120875381761091151370986698499475803934716743936229655502478364809360876631064902359464005958958369624012320935311582477001952164197550648949852842886069040901766717013281026119769595757977722625033283424852524512893277501742613719616609878412767862350919830332640389641393211844520566892576342624145412232816730133054101472783555519705645670726034388450467548145029501098942515002161552063228416835653091626292610474182304354210812502108960946562098926681475128242512174026263536868409233997140083428957301384012652122587720249328373686177305502125718712479532401842486851370485997667497959621748515775656066240589158346719938673215584564059152817541486484875551396413310452819616468457094063328779189854774867461314620030998196591653032108517357021025822767436404685865662939950428004349582814064462037875871688248054951986902620015831742568413039747014650926661445249941860478143505306713562287158880919205633473684592476414902279893475491602265094252302018692854138563605370873114816699695879636156051953150793975661596061430921040469142172131799231370444404864330810886183563351348725019593735773149966126074720642174863885059643748025428944511694165543409962779945317536706407347385270870917241304053618980461598336607375582651836710088641305458039603682825379743605151124089944216306293651477905778731780748182318685500375311885443631781429267966093575066161098324203512319052258383264504452107557636749322429814793320736463537055212543010576797020041898158243825771581523948863318642001470598958577904249093759442218346584978103024721311733061750761166345006938278666768700309682322195601865609792213576895251618962987114140123005746353309965060696395132398377054029736151839337776837585675815222602023435427941996602134786134061661322728039498740608663517857809198166367493322882889178258578173483413659049111905008515934475269780538811083084413775397589603673660749378501896164067598937802338450301859303357400811643652902732509331095899823768673243478585239413628949223394942357002708882033026822734948838028923788860493964117677088623570254641387302337716710564802538817952231223905052480174566838292928884621871934234242617901832175745336788343599973244989125556185129996157100598310017678978692216973371719497351384384833979408093849109995607581137699739755969968330226810828392150981446360210093021099834022835464269288870354594333312143951913687064369512677700596106054384797918306602043307872445255701749272487732845183895008105975409459823995915405660252966340528314700896652133763411439268301256583882003075716950180251957629733147302464932696365558768298262602512174864989080369722525007816399878757337279220727394873002676916292507871361753849085041391128010740573949085074969154023903844734532130969379020247373480727575846318448414358413954588054007138093915902644955808201862117625524046228013163073864268160579634787997584909132247521493500990841867439704534161818127418101534326301345072304181196521647147331678314990072743274206875925486947416199672638489405637460358251704800646942184069389706472299819974584763477559108458308059206216706409145127826217687554063317691587918048916233727430992459131319402736896564362801507865721027386712473389735996178102223817563205598093120649711539601815866624360037450476662398264346944523508480198114648418501280214000790114804815156244111505548879405678838812140710140556557955231069127303482710963633104137233266046679514305243707210023491010721639638051886588376941073139866982206315847778147224827616917314687285776934942600881114267711658824596817005297820491599987071585225716395133965569875985231668600838236170124237222062777958081736703410497839453815920562432197151527109995288840421687531350386346739685424060266547468666285034491986718983630743556914059902993989192897962091065249814768060096326257612048636243425517887256626269661038604628864497322798748444962038620048450871305764888982158662891806462441717181927185119680061550642222564092539815392191363695461090102734249327566048928891608670387810941426201235514314740973650152092553907308802826227195845667680319202683913906284112851950253323121370997876663329028906967920942796765703907702111269715481460206567718199615766674656096422257119442825751313982810926105470458378897346088992259700395339174687776767219045082075674220042322902287390704164861120655631510499496317599850035664791010532615982163186765531615329973158735925480836827655855851707948271643431811428409665636486345984451575929195030647609184372356333148311574895384431753146582422505856261302591296229662438895711075321395737701489614655111034377459005971619938762217494734079967833408245826817966612919405649959707721944138399175463872369539288235747885362717370393365400933671429992299198807884196489047186728031877838558307472422617563253650812945319330101071296616693362330043582515482495410057225197230665390860046660260612343252848870909364353967157087108074441594661672011970464823381659297879747355322818946249822511640762355972331107423733144296770648009154230282570290491841523376247774480558957447179358885619747311719866549261963438152333543815596008426597184647190691634359478058857418225895624069437897140885985550424123900822692589487216734399174513794566262858560035980893004785908119243758674956473982941707003405111749346685780848371517660533601231494296795114568960178097390641050437975713157977539255690330347702018680451047506267977367300695552772155955831873642207663545225612411745256616941668664126895345565078342562911563563000207444962504737783105664664640846622913807130357476041495297243296331964544246647125412244193032608672599783369327906509768732369556834214107519644509489312572849116049812778195779077998954527050830928052721474436946928669143813729281141338552104560748639117597530120511786788632617503355549277706453592893863429105187846032959523204493625796799069762126909225737294777448275574323270982557822925033143931660581865218565481360387856874820229049832230612920509059181139253536404655031871262879148097117882175761647077461749393304094653468427290743616496281455009796115451176078561820972945397302514000835623629409296629268644530520678187929874747350644510526881397783313731582388411482796099553987489250815260840167395643139901000118936761458269199527509121545962539743745670168871591089333193160344726127087646492900406565077089089945586276800540946781948207992872601669384833044103793277870819738716870598287767118206173952151149099259970612794248202068227949640977849347007899976664797519977255302214509665979582890865368365079182095516628183664281018777802198542778882343156492537902227312152640432669806188694934654439692038955465109202798554490368530406093247131231521150689754660783983123219086553252782719849697557535150168186087847601430259940409705355383640366731554571824412473315929730349067799926730691087656098626848230496865525343022767089511891167085461178696261056275386481716961743272166456720139750496607691135790146145059468053206742835814820730946531806420633073520391741934434325972323841745803290346590065536637518499974126333540065133627804655814406805501651151899619120594971000033884115553273992421333269159416978681943499738608066483070020969629821663142591899281427211691315551603062095102938168184785576621122631995710476081784244874591816687940378853737586053974765974300847779675670248048783416872673873876218588978619983900867872596346355636902836794639989616235216915736196796914457331606438963941944403128019496540645190081850735206855535879761976477144931876615275506536528911503459058610456004073290221268982504911107816593593587087088694250055817420524337858790262246040392484964661599104822774923991673211445225725760474219174341772356218924837916819365647812499768128260085946097189986815026144653420781614351368524072962073013242797808729812159545772262126945540298325030290189682326736432430701721355533040200142191293833938774615574162483568353203348802699342010522918664393002701834973028861682417032817792394967268578664754923547635138864649386464832905604724531018984742502185732018036064831593426695924608309576174290666822588683034000271886381283593593774071169517162681400994634648342537498058746752395289920156373052323727327817952095737660984619415946385324240306302345516359846821565083991827659568588029564843453840470972728057564157289043184583358005025965129083183814055664863629610865543243219327955857732631816183994297876547398146745747298469580776485487575221325632690024118883360748837301305019054802830222766511510165262336710497655447388061167095383777766136688322482458630472247300953586162982246228394007045777511034654957646558867058811060498642336623108707400230426117371174998001451674168292447980587268907340428713788441764610877899359179540766183157840461019151905483258438425585273682126384780585993052721251548469648740168510515037846806716176792466166818088686132528861724363677405043090671899905059736086689538086698196796910867732814477914570018966289364352477637559631675237572429648455439589273229628000982723914826000418180715954352860928909242833036312719038846125946269362355305085420991550874646908596753922789599424562881037666481340271778473754230361573417406828661106002348407040036750554467678902006006381060072882423600027224552446850104117690311657132111289707349091750199194101869944739890164646002766090752371312520130227298895747401561363770801426303757059090472123042346801840828621870437310178614452512414138007204533444226769290681200084081465831722751660399423533373146909934754382825571144556214109774508167787908159735109592154692834121121866856019497785403662903030952636078202441420706896405609671615262271961750150027233719905963173731006752504854004363857291456995568422304104255460409729455669695926437239459863572811367151143423493064104719767771453634879182520055645945364288200974012009945386893471025584149710842915123332099337837861132304173316207443008918621902067809644583825344175144962691389460128444464215116752417994702170101672122614166673827083472123047854066719271309925432403978804097703110919695314651930982649071029781253852564547541287661231035240733832627758745979309693735916101406458568654400991301802205371023700433402920607924132110760321674043985056334865253541275419520946926362211815488544009848061865078161100380936466268443243777115302710775648236980260282129217375276668871221870648585602942022123256671791401460842458524264719334966682479749037718748370236352028731682506114177280885990323223162038952768515047418147100965756194830145475432342418980295498577507240082455913190209544711509390166874024011325681772963193553144342833751988522748921662901318064780971181318573375452339998713777735015590201224752381819086661412999901759728451378058210065306950088251761347960868269807697105707612521208975986000185854678502152558705247331437552836151260806740238495784670897716937247171003359586777485823816479208567127507888095917845195712675975070647532813412650509042685702330077148760477820893406912971462667482620636259755089521367858407402137955798799191983951167758579623894057183496121216241886078063815845998493324093891989661854112839453476013542271744742580434088832322120696739443807481670993134567251772572976785303669582285761242467076789769264601940074821136163995998799831570166869727970990605537336796269760932245866398775121744939271916948998864448711045618832293749992899477693047018803655618832269429070500915917688872695682732350961120595540460133876761768551443680643659931763232643006824869910158638694496801703094344582382054731922852276869674331684524795020826343247825070483630427886455478288816892853023869578311122196814466701950905466846370912953275540069829765752173698504259795713458097757766492213684424550651276685999984069259987857091387806997565247042638220931729169556106650679629740090216246724007606593017729845561148713954043238638352825523762313514700674752718947729126910700673625002377249119332954064885037761212386729952997773578634378094128917891079606603048644606821677115263361481210178845151649333675534084476260578031262608787693470871044342435647381036632123892321781190380280927211002186704967653352054184797955175147576724555909747891537896192021768317979574261418549482771653081412487020543649410757938416319583769991725725919872186695747107859473326110111501883370294678480408542383102910271096222267147882348060211462188611856229772985182479479953019327866281301741173341354722622110348854632534478579111862815233506140583744581228755368359942488775381754416124617485201324742346574304755222113020854397823913363857367400872767026231056554307534276932294834722032675212955772707364593511357340285486737233342261681748721966675320327827981369752165077781392595394880919742695627611140868635334343657295866453236440273291115607670920826567690841855318024592005809299862987891167283677573712037742602660236065496507262867074248726278377076728418337546448775157918808118779665658038431462274370535090440263094685414799169773057679979859047786924656644721291036147306908002910082597953872887747098477047581913427529037484132318118838248192866861270740684252045438003742777813124941501415735386565843613205269017658523656850194290977045010667129195942991227423240227878129147777496818683943639934859750373920941511903493226757620176687733060924784474541335344065309626695187374933913533432306553816256804828981303137335211250450406102475896467737161002460297330403208170939003713450250161633875794592728991078674185044831205263079772823893229312476666840429181717940262609994448263106149960893612338454290954854330737087694672801293383800023514058459685793388100255306890099877148344423407682256282990207654661994544687032303355078988498269178565488223840668105061744656782151502373522014950269500842226184803343291139535982765580687472088544412000797040561863013442772639517779502658156409979977434372603486738724427969758652130696844680529536479646422646174454197080788333226696236837712828639916941671136530768201353921596163540690004644638444113598490253079495651444126016689977189362827151279228148991367537560276304769899429312835787074534491034595223129738611537313685744151867619937653733680342307666421493732848412564961787485769823499580865200642512262670678975532393898197695378466116743589230603524206898037165953822079174570979779644081473575863208642622751588275103259786697447362521569147205711447266719053369627137602329078316910318229149131862799346831866972347919213009556224971978052481097495128984469902920585079362485665636013201629484695838236197022949014594946082426426303856501467963986313645441740021310061789564818701058002334252888157055916282840633285772098671183952888836132292541862922552524697859650825784625467777323971406321984245754969309844641112559787418123069747151084084642772001281164163572675274457757121439877700015061108398428561667639256523555006124717579497449933288375971041396167178886242845670667757034225288408921697624335761936796384690326292570404396231163800712734409590978350703158968253776478156669690907699090694299272613568702008492353337557178717632082428250794947675262693179092421651194132588825856344505940073296864303348828377849300961769327768783361095359997012445467118975316196030781360082343184794550254889180131084675090584755122445767198515229393920757281630946729355617706242277771092609860426929550692963318812001372149155914765353548495640542821959983261314207721045246143241825732937291094185539023238509949780311683536142980808645319520429072524305677066670831032809471418483849750923036855390443128906904548288961188476087256886047170798559297795990916215999836593636175771605490690038334830485537229058468526168126518162392694853793872207635989599827772735520453178558229792253931196306840807390935105330683186409705732800149829114935383814528385544345178481965598417253433668503214982430089928230591780764185740684605809101000517088500341302436191315422836006106088196960542222166555853465968290502524643496956004692116237367999534156179697294565197052076114351945878822088850096177011789757701267339611156245886187585342988004229706086318917312186391852683257842287078307322650120375072522365842494950757880478703757819318173389507385854563248975501299458330347823784592954905615061553615883196589059950731416768777732063332757474075218875639143089420643906964760520301583838953907134445351040214319980000034005553210754181118869684610952059588146930565542624894201082416531132146935675702765733538778149124551552305121395771454495801194267120361801996085289364147903828010834344612079624575252400629756314341732249009523754788418421103186553455623230771893881412527223238913985462848119270475598193021125775244614555300685858111879575960235314846754835693543879349642987191597326317081018049937022443997483166102032557129563235890293800120377459782123225143861989946298039663740262181915250348710230975398424140950837876527482525953510133717799825156621853445323272047503078561824774541681531058354093993959906989996309249622778150896965184650780977735567635954753482589473448763580131949990336263968268725794239311031459325284853329117666951714164659468332680780534267536084952471154174059883014732718167991177673250819538218857704112951664906697139968032434007760939698096629996747486252524717341048122588342679326015163478350237570499130914160650552949293551500150062745511983328666393327988207270975372730766627195456895970787863236982274318965288821812641513477096058002749951177388816554285274481895029534061744380951792684596476988156214149415043750474206463954586768497205946819207405612164782091530315729804021683422832241650464853430040482144162512264717187053580824380782214716326513687741376163735434030677583579542448791477560490178794577338250358037092068292509657323985172809026418547009256822421409503456460263359401852403413062216637560456248613373629556143443467406711551402688666432988007763967779418647884040016069299289817842007902968542713917089209048731207249443177153060469366918197467287644058874928039096681470669502331814741801345025482997992318323188251579943429716163330076464306545206724557665025497740695993939623266842055685077858574151569446038770633866955296872975590723511083846377960950547826243555092429292018515271842693468860440035310546323865917118897140759332462317621234842416984193237864540055450024744560574032720088397957046333026119136850490479420238194411278309382303898522797860219218224418007318449866574447774686967251863787468375924341636019252687796894991664757885676546884496732596454923737946871118316919790854511988126043919682433558936652346510101204751944384835709279979897359302319129059941941116044308674101220370312967089711040567152902130020077936449370849864127726602993014929442307859485102832474913326471628957160306126368782555530616811386151990290890256449605780518805171253097319595650754240487448219727358086625703614950178423344664337746758670192983932796768777970032792221967004321904076569361063359079442870737899696912444823797585912857606827579453240206305709733067289308504392320610791005490256188930789473245872475707929588868715711814840477364564950319889801281475126680232265458317755421216438672203033704155004753257691403065033738689427999275103715755482916067242466988607228264020506774152692425916710957862397134341969110400201837343208610833081551238661250723847337151246043110086698919469244878201895465098297024502621047330409574377166895604519800746997978064542943604191935905069572756159878879212032025127887012877553109991257898687524876641054818076089880620806595890702423498921938572712925369412641803274565099407470838667030125801416117700140472725020362523991606016473996664039429186710779931429535713179855248612712443866260557321963086584195386971138278407583168506094837352115810356507557323723883155270646526311123333028771506981749553137756639764576447562715770064025804310904842
0xfE351F5E...2f885A46C
(Monolith: Deployer 1)
0.301496132721910426 Eth
Nonce: 786
0.137144644721910426 Eth
Nonce: 787
0.164351488

Execution Trace

Migrator.60808060( )
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)
pragma solidity ^0.8.0;
import "./IAccessControlEnumerableUpgradeable.sol";
import "./AccessControlUpgradeable.sol";
import "../utils/structs/EnumerableSetUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
 * @dev Extension of {AccessControl} that allows enumerating the members of each role.
 */
abstract contract AccessControlEnumerableUpgradeable is Initializable, IAccessControlEnumerableUpgradeable, AccessControlUpgradeable {
    function __AccessControlEnumerable_init() internal onlyInitializing {
    }
    function __AccessControlEnumerable_init_unchained() internal onlyInitializing {
    }
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
    mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _roleMembers;
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlEnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId);
    }
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
        return _roleMembers[role].at(index);
    }
    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
        return _roleMembers[role].length();
    }
    /**
     * @dev Overload {_grantRole} to track enumerable memberships
     */
    function _grantRole(bytes32 role, address account) internal virtual override {
        super._grantRole(role, account);
        _roleMembers[role].add(account);
    }
    /**
     * @dev Overload {_revokeRole} to track enumerable memberships
     */
    function _revokeRole(bytes32 role, address account) internal virtual override {
        super._revokeRole(role, account);
        _roleMembers[role].remove(account);
    }
    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
    function __AccessControl_init() internal onlyInitializing {
    }
    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }
    mapping(bytes32 => RoleData) private _roles;
    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
    }
    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }
    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }
    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        StringsUpgradeable.toHexString(account),
                        " is missing role ",
                        StringsUpgradeable.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }
    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }
    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }
    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }
    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");
        _revokeRole(role, account);
    }
    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }
    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }
    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }
    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerableUpgradeable is IAccessControlUpgradeable {
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);
    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControlUpgradeable {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);
    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);
    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;
    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;
    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20Upgradeable.sol";
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.1) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;
    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;
    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);
    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }
    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }
    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }
    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }
    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }
    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @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.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }
    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }
    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }
    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }
    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }
    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }
    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        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());
    }
    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20PermitUpgradeable {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);
    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);
    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);
    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);
    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);
    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);
    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);
    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
import "../extensions/draft-IERC20PermitUpgradeable.sol";
import "../../../utils/AddressUpgradeable.sol";
/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20Upgradeable {
    using AddressUpgradeable for address;
    function safeTransfer(
        IERC20Upgradeable token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }
    function safeTransferFrom(
        IERC20Upgradeable token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }
    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }
    function safeIncreaseAllowance(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }
    function safeDecreaseAllowance(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }
    function safePermit(
        IERC20PermitUpgradeable token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }
    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.
        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.
        return account.code.length > 0;
    }
    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");
        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }
    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }
    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }
    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }
    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }
    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }
    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }
    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }
    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }
    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }
    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }
    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
    function __ERC165_init() internal onlyInitializing {
    }
    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165Upgradeable).interfaceId;
    }
    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
// SPDX-License-Identifier: MIT
// 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 IERC165Upgradeable {
    /**
     * @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);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library MathUpgradeable {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }
    /**
     * @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 == 0 ? 0 : (a - 1) / b + 1;
    }
    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }
            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                return prod0 / denominator;
            }
            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);
            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////
            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)
                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }
            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.
            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)
                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)
                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }
            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;
            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;
            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256
            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }
    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }
    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }
        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);
        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }
    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }
    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }
    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }
    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10**64) {
                value /= 10**64;
                result += 64;
            }
            if (value >= 10**32) {
                value /= 10**32;
                result += 32;
            }
            if (value >= 10**16) {
                value /= 10**16;
                result += 16;
            }
            if (value >= 10**8) {
                value /= 10**8;
                result += 8;
            }
            if (value >= 10**4) {
                value /= 10**4;
                result += 4;
            }
            if (value >= 10**2) {
                value /= 10**2;
                result += 2;
            }
            if (value >= 10**1) {
                result += 1;
            }
        }
        return result;
    }
    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
        }
    }
    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }
    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
        }
    }
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/MathUpgradeable.sol";
/**
 * @dev String operations.
 */
library StringsUpgradeable {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;
    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = MathUpgradeable.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }
    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, MathUpgradeable.log256(value) + 1);
        }
    }
    /**
     * @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] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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 EnumerableSetUpgradeable {
    // 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
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/MerkleProof.sol)
pragma solidity ^0.8.0;
/**
 * @dev These functions deal with verification of Merkle Tree proofs.
 *
 * The tree and the proofs can be generated using our
 * https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
 * You will find a quickstart guide in the readme.
 *
 * WARNING: You should avoid using leaf values that are 64 bytes long prior to
 * hashing, or use a hash function other than keccak256 for hashing leaves.
 * This is because the concatenation of a sorted pair of internal nodes in
 * the merkle tree could be reinterpreted as a leaf value.
 * OpenZeppelin's JavaScript library generates merkle trees that are safe
 * against this attack out of the box.
 */
library MerkleProof {
    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     */
    function verify(
        bytes32[] memory proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProof(proof, leaf) == root;
    }
    /**
     * @dev Calldata version of {verify}
     *
     * _Available since v4.7._
     */
    function verifyCalldata(
        bytes32[] calldata proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProofCalldata(proof, leaf) == root;
    }
    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leafs & pre-images are assumed to be sorted.
     *
     * _Available since v4.4._
     */
    function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }
    /**
     * @dev Calldata version of {processProof}
     *
     * _Available since v4.7._
     */
    function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }
    /**
     * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProof(proof, proofFlags, leaves) == root;
    }
    /**
     * @dev Calldata version of {multiProofVerify}
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function multiProofVerifyCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProofCalldata(proof, proofFlags, leaves) == root;
    }
    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
     * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
     * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
     * respectively.
     *
     * CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
     * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
     * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
     *
     * _Available since v4.7._
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 totalHashes = proofFlags.length;
        // Check proof validity.
        require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");
        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }
        if (totalHashes > 0) {
            return hashes[totalHashes - 1];
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }
    /**
     * @dev Calldata version of {processMultiProof}.
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 totalHashes = proofFlags.length;
        // Check proof validity.
        require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");
        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }
        if (totalHashes > 0) {
            return hashes[totalHashes - 1];
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }
    function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
        return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
    }
    function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, a)
            mstore(0x20, b)
            value := keccak256(0x00, 0x40)
        }
    }
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/interfaces/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
contract Migrator is
    Initializable,
    PausableUpgradeable,
    AccessControlEnumerableUpgradeable
{
    using SafeERC20Upgradeable for IERC20Upgradeable;
    enum MigrationPreference {
        BALANCED, // 0
        DEUS, // 1
        SYMM // 2
    }
    struct Migration {
        address user;
        address token;
        uint256 amount;
        uint256 timestamp;
        uint256 block;
        MigrationPreference migrationPreference;
    }
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
    bytes32 public constant UNPAUSER_ROLE = keccak256("UNPAUSER_ROLE");
    bytes32 public constant WITHDRAWER_ROLE = keccak256("WITHDRAWER_ROLE");
    bytes32 public constant SETTER_ROLE = keccak256("SETTER_ROLE");
    address public constant DEUS = 0xDE5ed76E7c05eC5e4572CfC88d1ACEA165109E44;
    uint256 public earlyMigrationDeadline;
    // total migrated amount by token address by project
    mapping(MigrationPreference => mapping(address => uint256))
        public totalLateMigratedAmount;
    mapping(MigrationPreference => mapping(address => uint256))
        public totalEarlyMigratedAmount;
    // user migrated amount: project => user => token => amount
    mapping(MigrationPreference => mapping(address => mapping(address => uint256)))
        public migratedAmount;
    // list of user migrations
    mapping(address => Migration[]) public migrations;
    bytes32 public legacyDEIMerkleRoot;
    bytes32 public bDEIMerkleRoot;
    // users converted amount: user => token => amount
    // address public 
    mapping(address => mapping(address => uint256)) public convertedAmount;
    address public bDEI;
    event Migrate(
        address[] token,
        uint256[] amount,
        MigrationPreference[] migrationPreference,
        address receiver
    );
    event Split(address user, uint256 index, uint256 amount);
    event Transfer(address user, uint256 index, address receiver);
    event Undo(address user, uint256 index);
    event ChangePreference(
        address user,
        uint256 index,
        MigrationPreference newPreference
    );
    event SetMerkleRoots(bytes32 legacyDEIMerkleRoot, bytes32 bDEIMerkleRoot);
    event Convert(address token, uint256 tokenAmount, uint256 deusAmount);
    error InvalidProof();
    function initialize(address _admin) external initializer {
        __Pausable_init();
        __AccessControlEnumerable_init();
        _grantRole(DEFAULT_ADMIN_ROLE, _admin);
        earlyMigrationDeadline = block.timestamp + 30 days;
    }
    function pause() external onlyRole(PAUSER_ROLE) whenNotPaused {
        _pause();
    }
    function unpause() external onlyRole(UNPAUSER_ROLE) {
        _unpause();
    }
    function setMerkleRoots(bytes32 legacyDEIMerkleRoot_, bytes32 bDEIMerkleRoot_) external onlyRole(SETTER_ROLE) {
        legacyDEIMerkleRoot = legacyDEIMerkleRoot_;
        bDEIMerkleRoot = bDEIMerkleRoot_;
        emit SetMerkleRoots(legacyDEIMerkleRoot_, bDEIMerkleRoot_);
    }
    function setBDEIAddress(address bDEI_) external onlyRole(SETTER_ROLE) {
        bDEI = bDEI_;
    }
    function deposit(
        address[] memory tokens,
        uint256[] memory amounts,
        MigrationPreference[] memory migrationPreferences,
        address receiver
    ) external whenNotPaused {
        for (uint256 i; i < tokens.length; ++i) {
            IERC20Upgradeable(tokens[i]).safeTransferFrom(
                msg.sender,
                address(this),
                amounts[i]
            );
            if (block.timestamp < earlyMigrationDeadline) {
                totalEarlyMigratedAmount[migrationPreferences[i]][
                    tokens[i]
                ] += amounts[i];
            } else {
                totalLateMigratedAmount[migrationPreferences[i]][
                    tokens[i]
                ] += amounts[i];
            }
            migratedAmount[migrationPreferences[i]][receiver][
                tokens[i]
            ] += amounts[i];
            migrations[receiver].push(
                Migration({
                    user: receiver,
                    token: tokens[i],
                    amount: amounts[i],
                    timestamp: block.timestamp,
                    block: block.number,
                    migrationPreference: migrationPreferences[i]
                })
            );
        }
        emit Migrate(tokens, amounts, migrationPreferences, receiver);
    }
    function getUserMigrations(
        address user
    ) external view returns (Migration[] memory userMigrations) {
        userMigrations = new Migration[](migrations[user].length);
        for (uint256 i; i < userMigrations.length; ++i) {
            userMigrations[i] = migrations[user][i];
        }
    }
    function getTotalEarlyMigratedAmounts(
        address[] memory tokens
    )
        external
        view
        returns (
            uint256[] memory balancedAmounts,
            uint256[] memory deusAmounts,
            uint256[] memory symmAmounts
        )
    {
        balancedAmounts = new uint256[](tokens.length);
        deusAmounts = new uint256[](tokens.length);
        symmAmounts = new uint256[](tokens.length);
        for (uint256 i; i < tokens.length; ++i) {
            balancedAmounts[i] = totalEarlyMigratedAmount[
                MigrationPreference.BALANCED
            ][tokens[i]];
            deusAmounts[i] = totalEarlyMigratedAmount[MigrationPreference.DEUS][
                tokens[i]
            ];
            symmAmounts[i] = totalEarlyMigratedAmount[MigrationPreference.SYMM][
                tokens[i]
            ];
        }
    }
    function getTotalLateMigratedAmounts(
        address[] memory tokens
    )
        external
        view
        returns (
            uint256[] memory balancedAmounts,
            uint256[] memory deusAmounts,
            uint256[] memory symmAmounts
        )
    {
        balancedAmounts = new uint256[](tokens.length);
        deusAmounts = new uint256[](tokens.length);
        symmAmounts = new uint256[](tokens.length);
        for (uint256 i; i < tokens.length; ++i) {
            balancedAmounts[i] = totalLateMigratedAmount[
                MigrationPreference.BALANCED
            ][tokens[i]];
            deusAmounts[i] = totalLateMigratedAmount[MigrationPreference.DEUS][
                tokens[i]
            ];
            symmAmounts[i] = totalLateMigratedAmount[MigrationPreference.SYMM][
                tokens[i]
            ];
        }
    }
    function split(uint256 index, uint256 amount) external whenNotPaused {
        require(index < migrations[msg.sender].length, "Index Out Of Range");
        Migration storage migration = migrations[msg.sender][index];
        require(migration.amount > amount, "Amount Too High");
        migration.amount -= amount;
        migrations[msg.sender].push(
            Migration({
                user: msg.sender,
                token: migration.token,
                amount: amount,
                timestamp: migration.timestamp,
                block: migration.block,
                migrationPreference: migration.migrationPreference
            })
        );
        emit Split(msg.sender, index, amount);
    }
    function transfer(uint256 index, address receiver) external whenNotPaused {
        require(index < migrations[msg.sender].length, "Index Out Of Range");
        require(receiver != msg.sender, "Transfer To Owner");
        // transfer the migration to receiver
        Migration memory migration = migrations[msg.sender][index];
        migration.user = receiver;
        migrations[receiver].push(migration);
        // remove the migration from msg.sender migrations
        migrations[msg.sender][index] = migrations[msg.sender][
            migrations[msg.sender].length - 1
        ];
        migrations[msg.sender].pop();
        // update migratedAmount for msg.sender and receiver
        migratedAmount[migration.migrationPreference][msg.sender][
            migration.token
        ] -= migration.amount;
        migratedAmount[migration.migrationPreference][receiver][
            migration.token
        ] += migration.amount;
        emit Transfer(msg.sender, index, receiver);
    }
    function undo(uint256 index) external whenNotPaused {
        require(index < migrations[msg.sender].length, "Index Out Of Range");
        // remove the migration from msg.sender migrations
        Migration memory migration = migrations[msg.sender][index];
        migrations[msg.sender][index] = migrations[msg.sender][
            migrations[msg.sender].length - 1
        ];
        migrations[msg.sender].pop();
        // reduce user's migrated amount
        migratedAmount[migration.migrationPreference][msg.sender][
            migration.token
        ] -= migration.amount;
        // reduce total early/late migrated amount
        if (migration.timestamp < earlyMigrationDeadline) {
            totalEarlyMigratedAmount[migration.migrationPreference][
                migration.token
            ] -= migration.amount;
        } else {
            totalLateMigratedAmount[migration.migrationPreference][
                migration.token
            ] -= migration.amount;
        }
        // transfer migrated token back
        IERC20Upgradeable(migration.token).safeTransfer(
            msg.sender,
            migration.amount
        );
        emit Undo(msg.sender, index);
    }
    function changePreference(
        uint256 index,
        MigrationPreference newPreference
    ) external whenNotPaused {
        require(index < migrations[msg.sender].length, "Index Out Of Range");
        Migration storage migration = migrations[msg.sender][index];
        require(
            migration.migrationPreference != newPreference,
            "Same Migration Preference"
        );
        // undo storages which migration preference effects
        migratedAmount[migration.migrationPreference][msg.sender][
            migration.token
        ] -= migration.amount;
        if (migration.timestamp < earlyMigrationDeadline) {
            totalEarlyMigratedAmount[migration.migrationPreference][
                migration.token
            ] -= migration.amount;
        } else {
            totalLateMigratedAmount[migration.migrationPreference][
                migration.token
            ] -= migration.amount;
        }
        // update migration preference
        migration.migrationPreference = newPreference;
        // redo storages which migration preference effects
        migratedAmount[migration.migrationPreference][msg.sender][
            migration.token
        ] += migration.amount;
        if (migration.timestamp < earlyMigrationDeadline) {
            totalEarlyMigratedAmount[migration.migrationPreference][
                migration.token
            ] += migration.amount;
        } else {
            totalLateMigratedAmount[migration.migrationPreference][
                migration.token
            ] += migration.amount;
        }
        emit ChangePreference(msg.sender, index, newPreference);
    }
    function withdraw(
        address[] memory tokens
    ) external onlyRole(WITHDRAWER_ROLE) {
        for (uint256 i; i < tokens.length; ++i) {
            IERC20Upgradeable(tokens[i]).safeTransfer(
                msg.sender,
                IERC20Upgradeable(tokens[i]).balanceOf(address(this))
            );
        }
    }
    function wipeMigrations(
        address[] memory users,
        address[] memory tokens
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        for (uint256 i = 0; i < users.length; ++i) {
            address user = users[i];
            uint256 length = migrations[user].length;
            for (uint256 k = 0; k < tokens.length; ++k) {
                uint256 j = 0;
                while (j < length) {
                    if (migrations[user][j].token == tokens[k]) {
                        length -= 1;
                        migrations[user][j] = migrations[user][length];
                        migrations[user].pop();
                    } else {
                        j += 1;
                    }
                }
            }
        }
    }
    function convertBDEI(uint256 amount, uint256 maxAmount, bytes32[] memory proof) external whenNotPaused {
        require(amount <= maxAmount, "Invalid Amount");
         if (
            !MerkleProof.verify(
                proof,
                bDEIMerkleRoot,
                keccak256(abi.encode(msg.sender, maxAmount))
            )
        ) revert InvalidProof();
        convertedAmount[msg.sender][bDEI] += amount;
        require(convertedAmount[msg.sender][bDEI] <= maxAmount, "Amount Too High");
        IERC20Upgradeable(bDEI).safeTransferFrom(
            msg.sender,
            address(this),
            amount
        );
        uint256 deusAmount = amount / 185;
        IERC20Upgradeable(DEUS).safeTransfer(msg.sender, deusAmount);
        emit Convert(bDEI, amount, deusAmount);
    }
    function convertLegacyDEI(uint256 amount, uint256 maxAmount, bytes32[] memory proof) external whenNotPaused {
        require(amount <= maxAmount, "Invalid Amount");
         if (
            !MerkleProof.verify(
                proof,
                legacyDEIMerkleRoot,
                keccak256(abi.encode(msg.sender, maxAmount))
            )
        ) revert InvalidProof();
        address legacyDEI = 0xDE12c7959E1a72bbe8a5f7A1dc8f8EeF9Ab011B3;
        convertedAmount[msg.sender][legacyDEI] += amount;
        require(convertedAmount[msg.sender][legacyDEI] <= maxAmount, "Amount Too High");
        IERC20Upgradeable(legacyDEI).safeTransferFrom(
            msg.sender,
            address(this),
            amount
        );
        uint256 deusAmount = amount / 217;
        IERC20Upgradeable(DEUS).safeTransfer(msg.sender, deusAmount);
        emit Convert(legacyDEI, amount, deusAmount);
    }
    function convertXDEUS(uint256 amount) external whenNotPaused {
        address xDeus = 0x953Cd009a490176FcEB3a26b9753e6F01645ff28;
        IERC20Upgradeable(xDeus).safeTransferFrom(
            msg.sender,
            address(this),
            amount
        );
        convertedAmount[msg.sender][xDeus] += amount;
        IERC20Upgradeable(DEUS).safeTransfer(msg.sender, amount);
        emit Convert(xDeus, amount, amount);
    }
}