Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xaeB46DfF689E0cf97c16e1CbAcc38681a6574234
Balance 0 ETH
Nonce 1
Code Size 18090 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

18090 bytes
0x60806040526004361015610013575b610e0b565b61001d5f3561018c565b8063150b7a02146101875780631e8735c2146101825780632bd7667d1461017d5780633405aa86146101785780634219dc40146101735780634ceccf0c1461016e5780634cf088d91461016957806351f7653e1461016457806357a4b9fe1461015f578063715018a61461015a57806373567ec614610155578063791b98bc1461015057806379ba50971461014b5780637ee28b6b14610146578063848bdb541461014157806387b7c5ef1461013c5780638da5cb5b14610137578063d145e20014610132578063d1503ba11461012d578063de8a28c714610128578063e30c397814610123578063e533da321461011e5763f2fde38b0361000e57610dd8565b610da3565b610d60565b610d28565b610c19565b610bca565b610b68565b610b34565b610aaf565b610a4d565b610a1a565b6109e5565b610942565b6108ef565b6108b5565b610813565b610770565b6106cd565b6105ec565b610521565b61042c565b610392565b6102dd565b60e01c90565b60405190565b5f80fd5b5f80fd5b5f80fd5b60018060a01b031690565b6101b8906101a4565b90565b6101c4816101af565b036101cb57565b5f80fd5b905035906101dc826101bb565b565b90565b6101ea816101de565b036101f157565b5f80fd5b90503590610202826101e1565b565b5f80fd5b5f80fd5b5f80fd5b909182601f8301121561024a5781359167ffffffffffffffff831161024557602001926001830284011161024057565b61020c565b610208565b610204565b906080828203126102aa57610266815f84016101cf565b9261027482602085016101cf565b9261028283604083016101f5565b92606082013567ffffffffffffffff81116102a5576102a19201610210565b9091565b6101a0565b61019c565b63ffffffff60e01b1690565b6102c4906102af565b9052565b91906102db905f602085019401906102bb565b565b346103115761030d6102fc6102f336600461024f565b93929092610e41565b610304610192565b918291826102c8565b0390f35b610198565b919060408382031261033e578061033261033b925f86016101f5565b936020016101f5565b90565b61019c565b61034c906101de565b9052565b90565b61035c90610350565b9052565b604090610389610390949695939661037f60608401985f850190610343565b6020830190610353565b0190610353565b565b346103c6576103c26103ae6103a8366004610316565b90610f20565b6103b9939193610192565b93849384610360565b0390f35b610198565b5f9103126103d557565b61019c565b90565b90565b6103f46103ef6103f9926103da565b6103dd565b610350565b90565b610409620d89b3196103e0565b90565b6104146103fc565b90565b919061042a905f60208501940190610353565b565b3461045c5761043c3660046103cb565b61045861044761040c565b61044f610192565b91829182610417565b0390f35b610198565b9060208282031261047a57610477915f016101f5565b90565b61019c565b61049361048e610498926101de565b6103dd565b6101de565b90565b906104a59061047f565b5f5260205260405f2090565b1c90565b60018060a01b031690565b6104d09060086104d593026104b1565b6104b5565b90565b906104e391546104c0565b90565b6104fc906104f76008915f9261049b565b6104d8565b90565b610508906101af565b9052565b919061051f905f602085019401906104ff565b565b346105515761054d61053c610537366004610461565b6104e6565b610544610192565b9182918261050c565b0390f35b610198565b60018060a01b031690565b61057190600861057693026104b1565b610556565b90565b906105849154610561565b90565b61059360055f90610579565b90565b6105aa6105a56105af926101a4565b6103dd565b6101a4565b90565b6105bb90610596565b90565b6105c7906105b2565b90565b6105d3906105be565b9052565b91906105ea905f602085019401906105ca565b565b3461061c576105fc3660046103cb565b610618610607610587565b61060f610192565b918291826105d7565b0390f35b610198565b9060208282031261063a57610637915f016101cf565b90565b61019c565b610648906105b2565b90565b906106559061063f565b5f5260205260405f2090565b60ff1690565b61067790600861067c93026104b1565b610661565b90565b9061068a9154610667565b90565b6106a39061069e6006915f9261064b565b61067f565b90565b151590565b6106b4906106a6565b9052565b91906106cb905f602085019401906106ab565b565b346106fd576106f96106e86106e3366004610621565b61068d565b6106f0610192565b918291826106b8565b0390f35b610198565b60018060a01b031690565b61071d90600861072293026104b1565b610702565b90565b90610730915461070d565b90565b61073f60015f90610725565b90565b61074b906105b2565b90565b61075790610742565b9052565b919061076e905f6020850194019061074e565b565b346107a0576107803660046103cb565b61079c61078b610733565b610793610192565b9182918261075b565b0390f35b610198565b63ffffffff1690565b6107b7906107a5565b9052565b6107c490610350565b9052565b906040806107fc936107e05f8201515f8601906107ae565b6107f2602082015160208601906107bb565b01519101906107bb565b565b9190610811905f606085019401906107c8565b565b346108435761083f61082e610829366004610621565b611109565b610836610192565b918291826107fe565b0390f35b610198565b906108529061063f565b5f5260205260405f2090565b90565b61087190600861087693026104b1565b61085e565b90565b906108849154610861565b90565b61089d90610898600a915f92610848565b610879565b90565b91906108b3905f60208501940190610343565b565b346108e5576108e16108d06108cb366004610621565b610887565b6108d8610192565b918291826108a0565b0390f35b610198565b5f0190565b34610904576108ff3660046103cb565b611134565b610198565b90565b61092061091b61092592610909565b6103dd565b610350565b90565b610934620d89b461090c565b90565b61093f610928565b90565b34610972576109523660046103cb565b61096e61095d610937565b610965610192565b91829182610417565b0390f35b610198565b60018060a01b031690565b61099290600861099793026104b1565b610977565b90565b906109a59154610982565b90565b6109b460045f9061099a565b90565b6109c0906105b2565b90565b6109cc906109b7565b9052565b91906109e3905f602085019401906109c3565b565b34610a15576109f53660046103cb565b610a11610a006109a8565b610a08610192565b918291826109d0565b0390f35b610198565b34610a4857610a2a3660046103cb565b610a32611139565b610a3a610192565b80610a44816108ea565b0390f35b610198565b34610a7b57610a65610a60366004610461565b611766565b610a6d610192565b80610a77816108ea565b0390f35b610198565b90610a8a9061047f565b5f5260205260405f2090565b610aac90610aa76007915f92610a80565b610879565b90565b34610adf57610adb610aca610ac5366004610461565b610a96565b610ad2610192565b918291826108a0565b0390f35b610198565b610aed816106a6565b03610af457565b5f80fd5b90503590610b0582610ae4565b565b9190604083820312610b2f5780610b23610b2c925f86016101cf565b93602001610af8565b90565b61019c565b34610b6357610b4d610b47366004610b07565b90611823565b610b55610192565b80610b5f816108ea565b0390f35b610198565b34610b9857610b783660046103cb565b610b94610b83611833565b610b8b610192565b9182918261050c565b0390f35b610198565b9190604083820312610bc55780610bb9610bc2925f86016101f5565b936020016101cf565b90565b61019c565b34610bfb57610bf7610be6610be0366004610b9d565b906118b8565b610bee610192565b918291826108a0565b0390f35b610198565b610c1690610c116009915f92610a80565b610879565b90565b34610c4957610c45610c34610c2f366004610461565b610c00565b610c3c610192565b918291826108a0565b0390f35b610198565b90610c589061063f565b5f5260205260405f2090565b5f1c90565b63ffffffff1690565b610c7e610c8391610c64565b610c69565b90565b610c909054610c72565b90565b90565b610ca2610ca791610c64565b610c93565b90565b610cb49054610c96565b90565b610cc290600b610c4e565b610ccd5f8201610c86565b91610ce66002610cdf60018501610caa565b9301610caa565b90565b610cf2906107a5565b9052565b604090610d1f610d269496959396610d1560608401985f850190610ce9565b6020830190610353565b0190610353565b565b34610d5b57610d57610d43610d3e366004610621565b610cb7565b610d4e939193610192565b93849384610cf6565b0390f35b610198565b34610d9057610d703660046103cb565b610d8c610d7b61196b565b610d83610192565b9182918261050c565b0390f35b610198565b610da05f5f906104d8565b90565b34610dd357610db33660046103cb565b610dcf610dbe610d95565b610dc6610192565b9182918261050c565b0390f35b610198565b34610e0657610df0610deb366004610621565b611a31565b610df8610192565b80610e02816108ea565b0390f35b610198565b5f80fd5b5f90565b610e1c906105b2565b90565b60e01b90565b610e39610e34610e3e926107a5565b610e1f565b6102af565b90565b5050505050610e4e610e0f565b50610e5c63150b7a02610e25565b90565b5f90565b5f90565b610e73610e7891610c64565b610661565b90565b610e859054610e67565b90565b610e94610e9991610c64565b61085e565b90565b610ea69054610e88565b90565b634e487b7160e01b5f52601160045260245ffd5b610ecc610ed2919392936101de565b926101de565b8201809211610edd57565b610ea9565b5f1b90565b90610ef35f1991610ee2565b9181191691161790565b90565b90610f15610f10610f1c9261047f565b610efd565b8254610ee7565b9055565b90610f29610e5f565b50610f32610e63565b50610f3b610e63565b50610f4582611aa8565b50503391610f5284611cfe565b610f6f610f69610f646006859061064b565b610e7b565b156106a6565b610fc75783610f82610fc09584906118b8565b90610fab82610fa5610f96600a8890610848565b91610fa083610e9c565b610ebd565b90610f00565b610fb6818690611e47565b9390919293611fb0565b9192909190565b5f62820f3560e61b815280610fde600482016108ea565b0390fd5b601f801991011690565b634e487b7160e01b5f52604160045260245ffd5b9061100a90610fe2565b810190811067ffffffffffffffff82111761102457604052565b610fec565b9061103c611035610192565b9283611000565b565b6110486060611029565b90565b5f90565b5f90565b61105b61103e565b90602080808461106961104b565b81520161107461104f565b81520161107f61104f565b81525050565b61108d611053565b90565b9061109a906107a5565b9052565b906110a890610350565b9052565b906110fb6110f260026110bd61103e565b946110d46110cc5f8301610c86565b5f8801611090565b6110ec6110e360018301610caa565b6020880161109e565b01610caa565b6040840161109e565b565b611106906110ac565b90565b61112061112591611118611085565b50600b610c4e565b6110fd565b90565b611130612141565b5f80fd5b611128565b61114161218f565b61114961196b565b61115b611155836101af565b916101af565b0361116b5761116990612200565b565b611186905f91829163118cdaa760e01b83526004830161050c565b0390fd5b61119661119b91610c64565b610702565b90565b6111a8905461118a565b90565b336111cf6111c96111c46111bf600161119e565b610742565b6101af565b916101af565b036111df576111dd906114f7565b565b5f636c03d7e760e11b8152806111f7600482016108ea565b0390fd5b5f80fd5b9050519061120c826101bb565b565b9060208282031261122757611224915f016111ff565b90565b61019c565b611234610192565b3d5f823e3d90fd5b61124861124d91610c64565b6104b5565b90565b61125a905461123c565b90565b61126c611272919392936101de565b926101de565b820391821161127d57565b610ea9565b5f80fd5b61ffff1690565b61129681611286565b0361129d57565b5f80fd5b905051906112ae8261128d565b565b600511156112ba57565b5f80fd5b905051906112cb826112b0565b565b905051906112da826101e1565b565b6112e581610350565b036112ec57565b5f80fd5b905051906112fd826112dc565b565b9190610120838203126113bb576113b39061131b610120611029565b93611328825f83016112a1565b5f86015261133982602083016112a1565b602086015261134b82604083016112be565b604086015261135d82606083016112cd565b606086015261136f82608083016112cd565b60808601526113818260a083016112cd565b60a08601526113938260c083016112f0565b60c08601526113a58260e083016112f0565b60e0860152610100016112f0565b610100830152565b611282565b90610120828203126113da576113d7915f016112ff565b90565b61019c565b6113e8906107a5565b5f81146113f6576001900390565b610ea9565b9061140a63ffffffff91610ee2565b9181191691161790565b61142861142361142d926107a5565b6103dd565b6107a5565b90565b90565b9061144861144361144f92611414565b611430565b82546113fb565b9055565b61145d9051610350565b90565b61146f61147591939293610350565b92610350565b91828103925f82851281831216928513911215161761149057565b610ea9565b6114a96114a46114ae92610350565b6103dd565b610350565b90565b90565b906114c96114c46114d092611495565b6114b1565b8254610ee7565b9055565b9160206114f59294936114ee60408201965f830190610343565b01906104ff565b565b61150b61150660078390610a80565b610e9c565b61154c602061152261151d600161119e565b610742565b63b5b49303906115418692611535610192565b95869485938493610e1f565b8352600483016108a0565b03915afa908115611761575f91611733575b5061157361156e60098590610a80565b610e9c565b916115886115836008869061049b565b611250565b936115b1846115ab61159c600a8990610848565b916115a683610e9c565b61125d565b90610f00565b6115f36101206115c96115c4600161119e565b610742565b63963c9dd3906115e885926115dc610192565b95869485938493610e1f565b8352600483016108a0565b03915afa801561172e5760e06116739161169a935f916116ff575b506116375f61161f600b8c90610c4e565b0161163161162c82610c86565b6113df565b90611433565b61166d6116476101008301611453565b61166760016116578d600b610c4e565b019161166283610caa565b611460565b906114b4565b01611453565b6116946002611684600b8a90610c4e565b019161168f83610caa565b611460565b906114b4565b6116a5828490612216565b909192936116e56116df6116d97f097c7e22cb1e511bebd75e17f3d3822e43cc0e80b34281263df722f78c8f4cf99461047f565b9461047f565b9461063f565b946116fa6116f1610192565b928392836114d4565b0390a4565b61172191506101203d8111611727575b6117198183611000565b8101906113c0565b5f61160e565b503d61170f565b61122c565b611754915060203d811161175a575b61174c8183611000565b81019061120e565b5f61155e565b503d611742565b61122c565b61176f906111ab565b565b906117839161177e612141565b6117ca565b565b9061179160ff91610ee2565b9181191691161790565b6117a4906106a6565b90565b90565b906117bf6117ba6117c69261179b565b6117a7565b8254611785565b9055565b6117df826117da6006849061064b565b6117aa565b61181e61180c7fb32fea764811933768b2f8d722d28a444891994034c7d4d15063f9b658e2c6309261063f565b92611815610192565b918291826106b8565b0390a2565b9061182d91611771565b565b5f90565b61183b61182f565b506118466002611250565b90565b90565b61186061185b61186592611849565b6103dd565b6107a5565b90565b90565b61187f61187a61188492611868565b6103dd565b6101de565b90565b6fffffffffffffffffffffffffffffffff1690565b6118b06118ab6118b5926101de565b6103dd565b611887565b90565b6118dd916118c4610e5f565b506119146118d38383906122dc565b50949094936123f0565b5090806118fa6118f46118ef5f611250565b6101af565b916101af565b145f1461196457505b9161190e601e61184c565b90612b69565b50826119286119225f61186b565b916101de565b11611934575b50505090565b916119569161194761195c95949261189c565b6119505f611250565b92612ed2565b90610ebd565b5f808061192e565b9050611903565b61197361182f565b5061197e6003611250565b90565b6119929061198d612141565b6119d2565b565b906119a560018060a01b0391610ee2565b9181191691161790565b90565b906119c76119c26119ce9261063f565b6119af565b8254611994565b9055565b6119dd8160036119b2565b6119e5611833565b90611a19611a137f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e227009361063f565b9161063f565b91611a22610192565b80611a2c816108ea565b0390a3565b611a3a90611981565b565b5f90565b611a4c611a5191610c64565b610556565b90565b611a5e9054611a40565b90565b62ffffff1690565b611a7290611a61565b9052565b604090611a9f611aa69496959396611a9560608401985f8501906104ff565b60208301906104ff565b0190611a69565b565b611ad590611ab461182f565b50611abd61182f565b50611ac661182f565b50611acf611a3c565b506123f0565b6020611ae9611ae46005611a54565b6105be565b631698ee8290611b0d8692611b188796611b01610192565b97889687958695610e1f565b855260048501611a76565b03915afa908115611b5c575f91611b2e575b5092565b611b4f915060203d8111611b55575b611b478183611000565b81019061120e565b5f611b2a565b503d611b3d565b61122c565b611b6d611b7291610c64565b610977565b90565b611b7f9054611b61565b90565b6bffffffffffffffffffffffff1690565b611b9c81611b82565b03611ba357565b5f80fd5b90505190611bb482611b93565b565b611bbf81611a61565b03611bc657565b5f80fd5b90505190611bd782611bb6565b565b60020b90565b611be881611bd9565b03611bef57565b5f80fd5b90505190611c0082611bdf565b565b611c0b81611887565b03611c1257565b5f80fd5b90505190611c2382611c02565b565b909161018082840312611cdd57611c3e835f8401611ba7565b92611c4c81602085016111ff565b92611c5a82604083016111ff565b92611c6883606084016111ff565b92611c768160808501611bca565b92611c848260a08301611bf3565b92611c928360c08401611bf3565b92611ca08160e08501611c16565b92611caf8261010083016112cd565b92611cda611cc18461012085016112cd565b93611cd0816101408601611c16565b9361016001611c16565b90565b61019c565b611cf6611cf1611cfb92611bd9565b6103dd565b610350565b90565b610180611d3e91611d17611d126004611b75565b6109b7565b611d336399fbab88611d27610192565b95869485938493610e1f565b8352600483016108a0565b03915afa8015611e01575f808080808080979550959350505050611dc6575b50611d77611d71611d6c6103fc565b610350565b91611ce2565b1415908115611da3575b50611d8857565b5f6264847d60e41b815280611d9f600482016108ea565b0390fd5b9050611dbe611db8611db3610928565b610350565b91611ce2565b14155f611d81565b9050611dea91506101803d8111611dfa575b611de28183611000565b810190611c25565b5050505050955093505050611d5d565b503d611dd8565b61122c565b5f910312611e1057565b61019c565b604090611e3e611e459496959396611e3460608401985f8501906104ff565b60208301906104ff565b0190610343565b565b90611e5a611e556004611b75565b6109b7565b6342842e0e9190611e6a30610e13565b9392813b15611edf575f611e9191611e9c8296611e85610192565b98899788968795610e1f565b855260048501611e15565b03925af18015611eda57611eae575b50565b611ecd905f3d8111611ed3575b611ec58183611000565b810190611e06565b5f611eab565b503d611ebb565b61122c565b6111fb565b9091606082840312611f1957611f16611eff845f85016112cd565b93611f0d81602086016112f0565b936040016112f0565b90565b61019c565b611f53611f5a94611f49606094989795611f3f608086019a5f8701906104ff565b6020850190610343565b6040830190610343565b01906104ff565b565b611f65906107a5565b63ffffffff8114611f765760010190565b610ea9565b611f8a611f9091939293610350565b92610350565b808301925f82851215818312169285129112151617611fab57565b610ea9565b90606090959295949394611fc2610e5f565b50611fcb610e63565b50611fd4610e63565b50611fe7611fe2600161119e565b610742565b6120135f63687a2f1c61201e8b9a611ffe30610e13565b90612007610192565b9c8d9889978896610e1f565b865260048601611f1e565b03925af192831561213c575f8080919690956120f8575b506120f692916120d46120e59296979861206d5f612055600b8690610c4e565b0161206761206282610c86565b611f5c565b90611433565b612098896120926001612082600b8890610c4e565b019161208d83610caa565b611f7b565b906114b4565b6120c3886120bd60026120ad600b8890610c4e565b01916120b883610caa565b611f7b565b906114b4565b6120cf60098b90610a80565b610f00565b6120e06008899061049b565b6119b2565b6120f160078790610a80565b610f00565b565b6120f6939296506120d495506120e591506121299060603d8111612135575b6121218183611000565b810190611ee4565b92509550959192612035565b503d612117565b61122c565b612149611833565b61216261215c61215761218f565b6101af565b916101af565b0361216957565b61218b61217461218f565b5f91829163118cdaa760e01b83526004830161050c565b0390fd5b61219761182f565b503390565b1b90565b919060086121c09102916121ba60018060a01b038461219c565b9261219c565b9181191691161790565b91906121e06121db6121e89361063f565b6119af565b9083546121a0565b9055565b6121fe916121f861182f565b916121ca565b565b6122149061220f5f60036121ec565b613033565b565b906122296122246004611b75565b6109b7565b906342842e0e9161223930610e13565b919392813b156122af575f6122619161226c8296612255610192565b98899788968795610e1f565b855260048501611e15565b03925af180156122aa5761227e575b50565b61229d905f3d81116122a3575b6122958183611000565b810190611e06565b5f61227b565b503d61228b565b61122c565b6111fb565b5f90565b6122c190610596565b90565b6122cd906122b8565b90565b6122d9906105b2565b90565b612341929161235c6020612346612310612338956122f8610e5f565b50612301610e5f565b5061230a6122b4565b50613094565b9691909661231d876131fa565b9761233161232b8a94613939565b91613939565b9192614218565b979097946122c4565b6122d0565b630dfe168190612354610192565b938492610e1f565b8252818061236c600482016108ea565b03915afa9081156123eb575f916123bd575b5061239961239361238e5f611250565b6101af565b916101af565b1493845f146123b757805b945f146123b057505b91565b90506123ad565b816123a4565b6123de915060203d81116123e4575b6123d68183611000565b81019061120e565b5f61237e565b503d6123cc565b61122c565b61018061244b916123ff61182f565b5061240861182f565b50612411611a3c565b5061242461241f6004611b75565b6109b7565b6124406399fbab88612434610192565b95869485938493610e1f565b8352600483016108a0565b03915afa9081156124a8575f8080808093509391509361246c575b50909192565b91505061249191506101803d81116124a1575b6124898183611000565b810190611c25565b5050505050505091935091612466565b503d61247f565b61122c565b5f90565b5f90565b6124c96124c46124ce92611868565b6103dd565b6107a5565b90565b60209181520190565b5f7f4250000000000000000000000000000000000000000000000000000000000000910152565b61250e60026020926124d1565b612517816124da565b0190565b6125309060208101905f818303910152612501565b90565b1561253a57565b612542610192565b62461bcd60e51b8152806125586004820161251b565b0390fd5b90565b61257361256e6125789261255c565b6103dd565b6101de565b90565b67ffffffffffffffff81116125935760208091020190565b610fec565b906125aa6125a58361257b565b611029565b918252565b369037565b906125d96125c183612598565b926020806125cf869361257b565b92019103906125af565b565b634e487b7160e01b5f52603260045260245ffd5b5190565b906125fd826125ef565b81101561260e576020809102010190565b6125db565b90565b61262a61262561262f92612613565b6103dd565b6101de565b90565b67ffffffffffffffff811161264a5760208091020190565b610fec565b60060b90565b61265e8161264f565b0361266557565b5f80fd5b9050519061267682612655565b565b9092919261268d61268882612632565b611029565b93818552602080860192028301928184116126ca57915b8383106126b15750505050565b602080916126bf8486612669565b8152019201916126a4565b61020c565b9080601f830112156126ed578160206126ea93519101612678565b90565b610204565b67ffffffffffffffff811161270a5760208091020190565b610fec565b612718816101a4565b0361271f57565b5f80fd5b905051906127308261270f565b565b90929192612747612742826126f2565b611029565b938185526020808601920283019281841161278457915b83831061276b5750505050565b602080916127798486612723565b81520192019161275e565b61020c565b9080601f830112156127a7578160206127a493519101612732565b90565b610204565b919091604081840312612804575f81015167ffffffffffffffff81116127ff57836127d89183016126cf565b92602082015167ffffffffffffffff81116127fa576127f79201612789565b90565b6101a0565b6101a0565b61019c565b60209181520190565b60200190565b90612825816020936107ae565b0190565b60200190565b9061284c61284661283f846125ef565b8093612809565b92612812565b905f5b81811061285c5750505090565b90919261287561286f6001928651612818565b94612829565b910191909161284f565b6128949160208201915f81840391015261282f565b90565b5190565b906128a582612897565b8110156128b6576020809102010190565b6125db565b6128c5905161264f565b90565b6128d46128da9161264f565b9161264f565b900390667fffffffffffff8213667fffffffffffff198312176128f957565b610ea9565b5190565b9061290c826128fe565b81101561291d576020809102010190565b6125db565b61292c90516101a4565b90565b61293b612941916101a4565b916101a4565b90039060018060a01b03821161295357565b610ea9565b66ffffffffffffff1690565b61297861297361297d926107a5565b6103dd565b612958565b90565b61299461298f61299992612958565b6103dd565b61264f565b90565b634e487b7160e01b5f52601260045260245ffd5b6129bc6129c29161264f565b9161264f565b9081156129e85760015f038214667fffffffffffff198214166129e3570590565b610ea9565b61299c565b612a016129fc612a069261264f565b6103dd565b611bd9565b90565b612a1d612a18612a2292611868565b6103dd565b61264f565b90565b612a31612a379161264f565b9161264f565b908115612a42570790565b61299c565b612a5090611bd9565b627fffff198114612a62576001900390565b610ea9565b60018060c01b031690565b612a86612a81612a8b926107a5565b6103dd565b612a67565b90565b612aa2612a9d612aa7926101a4565b6103dd565b612a67565b90565b612ab9612abf91939293612a67565b92612a67565b91612acb838202612a67565b928184041490151715612ada57565b610ea9565b90565b60ff1690565b612afc612af7612b0192612adf565b6103dd565b612ae2565b90565b612b2390612b1d612b17612b2894612ae2565b91612a67565b9061219c565b612a67565b90565b612b37612b3d91612a67565b91612a67565b908115612b48570490565b61299c565b612b61612b5c612b6692612a67565b6103dd565b611887565b90565b905f612c2a9392612b786124ad565b50612b816124b1565b50612b9f83612b98612b92856124b5565b916107a5565b1415612533565b612c03612bfe612bb7612bb2600261255f565b6125b4565b92612bd486612bcf86612bc98961186b565b906125f3565b611090565b612bf9612be0866124b5565b612bf486612bee6001612616565b906125f3565b611090565b6122c4565b6122d0565b612c1f63883bdbfd612c13610192565b97889485938493610e1f565b83526004830161287f565b03915afa8015612de7575f80949091612dba575b50612c83612cc191612c7d612c78612c68612c6384612c5d6001612616565b9061289b565b6128bb565b92612c725f61186b565b9061289b565b6128bb565b906128c8565b93612cbb612cb6612ca6612ca184612c9b6001612616565b90612902565b612922565b92612cb05f61186b565b90612902565b612922565b9061292f565b90612ce5612ce085612cda612cd585612964565b612980565b906129b0565b6129ed565b9380612cf9612cf35f612a09565b9161264f565b129081612d84575b50612d59575b612d5691612d4b612d3b612d35612d20612d5195612a72565b612d2f60018060a01b03612a8e565b90612aaa565b92612a8e565b612d456020612ae8565b90612b04565b90612b2b565b612b4d565b90565b92612d5691612d4b612d3b612d35612d20612d76612d5196612a47565b989550505050509150612d07565b612da09150612d9a612d9584612964565b612980565b90612a25565b612db2612dac5f612a09565b9161264f565b14155f612d01565b612c839450612cc19150612ddf903d805f833e612dd78183611000565b8101906127ac565b945090612c3e565b61122c565b612e00612dfb612e0592611887565b6103dd565b6101a4565b90565b612e1c612e17612e21926101a4565b6103dd565b6101de565b90565b90565b612e3b612e36612e4092612e24565b6103dd565b6101de565b90565b90565b612e5a612e55612e5f92612e43565b6103dd565b6101de565b90565b612e76612e71612e7b92611887565b6103dd565b6101de565b90565b612e8d612e93919392936101de565b926101de565b91612e9f8382026101de565b928184041490151715612eae57565b610ea9565b90565b612eca612ec5612ecf92612eb3565b6103dd565b6101de565b90565b612ee89093919293612ee2610e5f565b50613939565b80612f0b612f056fffffffffffffffffffffffffffffffff612dec565b916101a4565b11155f14612f9857612f3c612f3582612f2f612f29612f4295612e08565b91612e08565b90612e7e565b94926101af565b916101af565b105f14612f7057612f6b9190612f65612f5f600160c01b92612e62565b91612eb6565b9161430f565b5b905b565b612f9391612f8d612f87600160c01b939293612eb6565b91612e62565b9061430f565b612f6c565b612fd5612fce82612fdb93612fc8612fc2612fbc6801000000000000000093612e08565b93612e08565b91612e27565b9161430f565b94926101af565b916101af565b105f1461300b576130049190612ffe612ff8600160801b92612e62565b91612e46565b9161430f565b5b90612f6e565b61302e91613028613022600160801b939293612e46565b91612e62565b9061430f565b613005565b61303d6002611250565b6130488260026119b2565b9061307c6130767f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09361063f565b9161063f565b91613085610192565b8061308f816108ea565b0390a3565b6101806130ef916130a36124ad565b506130ac6124ad565b506130b56124b1565b506130c86130c36004611b75565b6109b7565b6130e46399fbab886130d8610192565b95869485938493610e1f565b8352600483016108a0565b03915afa908115613153575f8080808080808096509694509692505050613117575b50909192565b91505061313c91506101803d811161314c575b6131348183611000565b810190611c25565b5050505094509450945050613111565b503d61312a565b61122c565b61316181612ae2565b0361316857565b5f80fd5b9050519061317982613158565b565b9050519061318882610ae4565b565b60e0818303126131f5576131a0825f8301612723565b926131ae8360208401611bf3565b926131bc81604085016112a1565b926131ca82606083016112a1565b926131f26131db84608085016112a1565b936131e98160a0860161316c565b9360c00161317b565b90565b61019c565b60e061321961321461322f9361320e6122b4565b506122c4565b6122d0565b633850c7bd90613227610192565b938492610e1f565b8252818061323f600482016108ea565b03915afa908115613287575f91613255575b5090565b613276915060e03d8111613280575b61326e8183611000565b81019061318a565b5050505050613251565b503d613264565b61122c565b6132a061329b6132a592611868565b6103dd565b611bd9565b90565b6132bc6132b76132c192610350565b6103dd565b6101de565b90565b6132cf905f03610350565b90565b90565b6132e96132e46132ee926132d2565b6103dd565b611bd9565b90565b6132fe620d89e7196132d5565b90565b61330c905f03611bd9565b90565b61331f61331a6132f1565b613301565b90565b70ffffffffffffffffffffffffffffffffff1690565b61334c61334761335192612e43565b6103dd565b613322565b90565b90565b61336b61336661337092613354565b6103dd565b613322565b90565b61338761338261338c92613322565b6103dd565b6101de565b90565b90565b6133a66133a16133ab9261338f565b6103dd565b6101de565b90565b906133b991026101de565b90565b90565b6133d36133ce6133d8926133bc565b6103dd565b612ae2565b90565b6133fa906133f46133ee6133ff94612ae2565b916101de565b906104b1565b6101de565b90565b90565b61341961341461341e92613402565b6103dd565b6101de565b90565b90565b61343861343361343d92613421565b6103dd565b6101de565b90565b90565b61345761345261345c92613440565b6103dd565b6101de565b90565b90565b61347661347161347b9261345f565b6103dd565b6101de565b90565b90565b61349561349061349a9261347e565b6103dd565b6101de565b90565b90565b6134b46134af6134b99261349d565b6103dd565b6101de565b90565b6134d06134cb6134d592612adf565b6103dd565b6101de565b90565b90565b6134ef6134ea6134f4926134d8565b6103dd565b6101de565b90565b90565b61350e613509613513926134f7565b6103dd565b6101de565b90565b90565b61352d61352861353292613516565b6103dd565b6101de565b90565b61354961354461354e926133bc565b6103dd565b6101de565b90565b90565b61356861356361356d92613551565b6103dd565b6101de565b90565b90565b61358761358261358c92613570565b6103dd565b6101de565b90565b90565b6135a66135a16135ab9261358f565b6103dd565b6101de565b90565b90565b6135c56135c06135ca926135ae565b6103dd565b6101de565b90565b90565b6135e46135df6135e9926135cd565b6103dd565b6101de565b90565b90565b6136036135fe613608926135ec565b6103dd565b6101de565b90565b90565b61362261361d6136279261360b565b6103dd565b6101de565b90565b90565b61364161363c6136469261362a565b6103dd565b6101de565b90565b90565b61366061365b61366592613649565b6103dd565b6101de565b90565b90565b61367f61367a61368492613668565b6103dd565b6101de565b90565b90565b61369e6136996136a392613687565b6103dd565b6101de565b90565b90565b6136bd6136b86136c2926136a6565b6103dd565b6101de565b90565b90565b6136dc6136d76136e1926136c5565b6103dd565b6101de565b90565b90565b6136fb6136f6613700926136e4565b6103dd565b6101de565b90565b90565b61371a61371561371f92613703565b6103dd565b6101de565b90565b90565b61373961373461373e92613722565b6103dd565b6101de565b90565b90565b61375861375361375d92613741565b6103dd565b6101de565b90565b90565b61377761377261377c92613760565b6103dd565b6101de565b90565b90565b61379661379161379b9261377f565b6103dd565b6101de565b90565b90565b6137b56137b06137ba9261379e565b6103dd565b6101de565b90565b90565b6137d46137cf6137d9926137bd565b6103dd565b6101de565b90565b90565b6137f36137ee6137f8926137dc565b6103dd565b6101de565b90565b90565b61381261380d613817926137fb565b6103dd565b6101de565b90565b90565b61383161382c6138369261381a565b6103dd565b6101de565b90565b90565b61385061384b61385592613839565b6103dd565b6101de565b90565b61386461386a916101de565b916101de565b908115613875570490565b61299c565b90565b61389161388c6138969261387a565b6103dd565b6101de565b90565b6138a56138ab916101de565b916101de565b9081156138b6570690565b61299c565b6138cf6138ca6138d492612613565b6103dd565b612ae2565b90565b6138eb6138e66138f092611868565b6103dd565b612ae2565b90565b61390761390261390c92612ae2565b6103dd565b6101de565b90565b9061391a91016101de565b90565b61393161392c613936926101de565b6103dd565b6101a4565b90565b6139416122b4565b508061395561394f5f61328c565b91611bd9565b125f146142025761397561397061396b83611ce2565b6132c4565b6132a8565b5b90816139a161399b61399661399161398c61330f565b611ce2565b6132a8565b6101de565b916101de565b116141e65781613d2791613d2c936139b96001612616565b166139cc6139c65f61186b565b916101de565b14155f146141d1576139f66139f06ffffcb933bd6fad37aa2d162d1a594001613357565b5b613373565b9180613a02600261255f565b16613a15613a0f5f61186b565b916101de565b03614194575b80613a266004613405565b16613a39613a335f61186b565b916101de565b03614157575b80613a4a6008613443565b16613a5d613a575f61186b565b916101de565b0361411a575b80613a6e6010613481565b16613a81613a7b5f61186b565b916101de565b036140dd575b80613a9260206134bc565b16613aa5613a9f5f61186b565b916101de565b036140a0575b80613ab660406134fa565b16613ac9613ac35f61186b565b916101de565b03614063575b80613ada6080613535565b16613aed613ae75f61186b565b916101de565b03614026575b80613aff610100613573565b16613b12613b0c5f61186b565b916101de565b03613fe9575b80613b246102006135b1565b16613b37613b315f61186b565b916101de565b03613fac575b80613b496104006135ef565b16613b5c613b565f61186b565b916101de565b03613f6f575b80613b6e61080061362d565b16613b81613b7b5f61186b565b916101de565b03613f32575b80613b9361100061366b565b16613ba6613ba05f61186b565b916101de565b03613ef5575b80613bb86120006136a9565b16613bcb613bc55f61186b565b916101de565b03613eb8575b80613bdd6140006136e7565b16613bf0613bea5f61186b565b916101de565b03613e7b575b80613c02618000613725565b16613c15613c0f5f61186b565b916101de565b03613e3e575b80613c2862010000613763565b16613c3b613c355f61186b565b916101de565b03613e01575b80613c4e620200006137a1565b16613c61613c5b5f61186b565b916101de565b03613dc5575b80613c74620400006137df565b16613c87613c815f61186b565b916101de565b03613d8a575b613c996208000061381d565b16613cac613ca65f61186b565b916101de565b03613d51575b613cc4613cbe5f61328c565b91611bd9565b13613d41575b613cf6613ce182613cdb6020612ae8565b906133db565b91613cf064010000000061387d565b90613899565b613d08613d025f61186b565b916101de565b145f14613d2f57613d21613d1b5f6138d7565b5b6138f3565b9061390f565b61391d565b90565b613d21613d3c60016138bb565b613d1c565b613d4c905f19613858565b613cca565b90613d74613d8491613d6e6b048a170391f7dc42444e8fa261383c565b906133ae565b613d7e60806133bf565b906133db565b90613cb2565b91613daf613dbf91613da96d2216e584f5fa1ea926041bedfe986137fe565b906133ae565b613db960806133bf565b906133db565b91613c8d565b91613deb613dfb91613de56e5d6af8dedb81196699c329225ee6046137c0565b906133ae565b613df560806133bf565b906133db565b91613c67565b91613e28613e3891613e226f09aa508b5b7a84e1c677de54f3e99bc9613782565b906133ae565b613e3260806133bf565b906133db565b91613c41565b91613e65613e7591613e5f6f31be135f97d08fd981231505542fcfa6613744565b906133ae565b613e6f60806133bf565b906133db565b91613c1b565b91613ea2613eb291613e9c6f70d869a156d2a1b890bb3df62baf32f7613706565b906133ae565b613eac60806133bf565b906133db565b91613bf6565b91613edf613eef91613ed96fa9f746462d870fdf8a65dc1f90e061e56136c8565b906133ae565b613ee960806133bf565b906133db565b91613bd1565b91613f1c613f2c91613f166fd097f3bdfd2022b8845ad8f792aa582561368a565b906133ae565b613f2660806133bf565b906133db565b91613bac565b91613f59613f6991613f536fe7159475a2c29b7443b29c7fa6e889d961364c565b906133ae565b613f6360806133bf565b906133db565b91613b87565b91613f96613fa691613f906ff3392b0822b70005940c7a398e4b70f361360e565b906133ae565b613fa060806133bf565b906133db565b91613b62565b91613fd3613fe391613fcd6ff987a7253ac413176f2b074cf7815e546135d0565b906133ae565b613fdd60806133bf565b906133db565b91613b3d565b916140106140209161400a6ffcbe86c7900a88aedcffc83b479aa3a4613592565b906133ae565b61401a60806133bf565b906133db565b91613b18565b9161404d61405d916140476ffe5dee046a99a2a811c461f1969c3053613554565b906133ae565b61405760806133bf565b906133db565b91613af3565b9161408a61409a916140846fff2ea16466c96a3843ec78b326b52861613519565b906133ae565b61409460806133bf565b906133db565b91613acf565b916140c76140d7916140c16fff973b41fa98c081472e6896dfb254c06134db565b906133ae565b6140d160806133bf565b906133db565b91613aab565b91614104614114916140fe6fffcb9843d60f6159c9db58835c9266446134a0565b906133ae565b61410e60806133bf565b906133db565b91613a87565b916141416141519161413b6fffe5caca7e10e4e61c3624eaa0941cd0613462565b906133ae565b61414b60806133bf565b906133db565b91613a63565b9161417e61418e916141786ffff2e50f5f656932ef12357cf3c7fdcc613424565b906133ae565b61418860806133bf565b906133db565b91613a3f565b916141bb6141cb916141b56ffff97272373d413259a46990580e213a613392565b906133ae565b6141c560806133bf565b906133db565b91613a1b565b6139f66141e1600160801b613338565b6139f1565b5f6315e4079d60e11b8152806141fe600482016108ea565b0390fd5b61421361420e82611ce2565b6132a8565b613976565b91909392614224610e5f565b9261422d610e5f565b938661424161423b866101a4565b916101a4565b116142cf575b8161425a614254896101a4565b916101a4565b11155f146142765750506142729293949190916145df565b915b565b9080939695945061428f614289886101a4565b916101a4565b105f146142b957506142a96142b2939495839083916145df565b9491909161452c565b905b614274565b9491506142c9929391909161452c565b906142b4565b959295614247565b156142de57565b5f80fd5b906142ed91036101de565b90565b90565b61430761430261430c926142f0565b6103dd565b6101de565b90565b614317610e5f565b50614320610e5f565b50614329610e5f565b505f19828209918082029283808210910303918261434f6143495f61186b565b916101de565b146144cc576144c3928580936143ba9361437e6144c999614378614372876101de565b916101de565b116142d7565b614386610e5f565b500990858211900394039360016143a65f6143a1869161186b565b6142e2565b841680809504960493805f030401906133ae565b17916144bd6144a161447d6144596144356144116143e260036143dd89916142f3565b6133ae565b6143ec600261255f565b1861440b60026144066144008b85906133ae565b9161255f565b6142e2565b906133ae565b61442f600261442a6144248a85906133ae565b9161255f565b6142e2565b906133ae565b614453600261444e6144488985906133ae565b9161255f565b6142e2565b906133ae565b614477600261447261446c8885906133ae565b9161255f565b6142e2565b906133ae565b61449b60026144966144908785906133ae565b9161255f565b6142e2565b906133ae565b916144b86144b260029285906133ae565b9161255f565b6142e2565b906133ae565b906133ae565b90565b5050506144eb826144e56144df5f61186b565b916101de565b116142d7565b0490565b906144fa91036101a4565b90565b90565b61451461450f614519926144fd565b6103dd565b6101de565b90565b614529600160601b614500565b90565b61457d92614538610e5f565b508161454c614546856101a4565b916101a4565b11614580575b9061455d91926144ef565b61457761457161456b61451c565b93612e62565b91612e08565b9061430f565b90565b61455d91929150614552565b90565b6145a361459e6145a89261458c565b6103dd565b612ae2565b90565b6145b5606061458f565b90565b6145d7906145d16145cb6145dc94612ae2565b916101de565b9061219c565b6101de565b90565b90614656926145ec610e5f565b50826146006145fa846101a4565b916101a4565b11614659575b6146509161462761461961464a93612e62565b6146216145ab565b906145b8565b9061464461463e6146398388906144ef565b612e08565b91612e08565b9161430f565b91612e08565b90613858565b90565b9161464a90614627614619614650949593505050915061460656fea2646970667358221220be260f4525f795db442d89ae59b45deca338deb37d6dfca74638a736a3ca058464736f6c634300081c0033

Verified Source Code Full Match

Compiler: v0.8.28+commit.7893614a EVM: cancun Optimization: No
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
Ownable2Step.sol 59 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        return _pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}
IERC721.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

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

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

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

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

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

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

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

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

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

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

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}
IERC721Receiver.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.20;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be
     * reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}
IERC721Enumerable.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity ^0.8.20;

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

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}
IERC721Metadata.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.20;

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

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

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

/// @title The interface for the Uniswap V3 Factory
/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees
interface IUniswapV3Factory {
    /// @notice Emitted when the owner of the factory is changed
    /// @param oldOwner The owner before the owner was changed
    /// @param newOwner The owner after the owner was changed
    event OwnerChanged(address indexed oldOwner, address indexed newOwner);

    /// @notice Emitted when a pool is created
    /// @param token0 The first token of the pool by address sort order
    /// @param token1 The second token of the pool by address sort order
    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
    /// @param tickSpacing The minimum number of ticks between initialized ticks
    /// @param pool The address of the created pool
    event PoolCreated(
        address indexed token0,
        address indexed token1,
        uint24 indexed fee,
        int24 tickSpacing,
        address pool
    );

    /// @notice Emitted when a new fee amount is enabled for pool creation via the factory
    /// @param fee The enabled fee, denominated in hundredths of a bip
    /// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee
    event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);

    /// @notice Returns the current owner of the factory
    /// @dev Can be changed by the current owner via setOwner
    /// @return The address of the factory owner
    function owner() external view returns (address);

    /// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled
    /// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context
    /// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee
    /// @return The tick spacing
    function feeAmountTickSpacing(uint24 fee) external view returns (int24);

    /// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
    /// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
    /// @param tokenA The contract address of either token0 or token1
    /// @param tokenB The contract address of the other token
    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
    /// @return pool The pool address
    function getPool(
        address tokenA,
        address tokenB,
        uint24 fee
    ) external view returns (address pool);

    /// @notice Creates a pool for the given two tokens and fee
    /// @param tokenA One of the two tokens in the desired pool
    /// @param tokenB The other of the two tokens in the desired pool
    /// @param fee The desired fee for the pool
    /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
    /// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
    /// are invalid.
    /// @return pool The address of the newly created pool
    function createPool(
        address tokenA,
        address tokenB,
        uint24 fee
    ) external returns (address pool);

    /// @notice Updates the owner of the factory
    /// @dev Must be called by the current owner
    /// @param _owner The new owner of the factory
    function setOwner(address _owner) external;

    /// @notice Enables a fee amount with the given tickSpacing
    /// @dev Fee amounts may never be removed once enabled
    /// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)
    /// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount
    function enableFeeAmount(uint24 fee, int24 tickSpacing) external;
}
IUniswapV3Pool.sol 26 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import {IUniswapV3PoolImmutables} from './pool/IUniswapV3PoolImmutables.sol';
import {IUniswapV3PoolState} from './pool/IUniswapV3PoolState.sol';
import {IUniswapV3PoolDerivedState} from './pool/IUniswapV3PoolDerivedState.sol';
import {IUniswapV3PoolActions} from './pool/IUniswapV3PoolActions.sol';
import {IUniswapV3PoolOwnerActions} from './pool/IUniswapV3PoolOwnerActions.sol';
import {IUniswapV3PoolErrors} from './pool/IUniswapV3PoolErrors.sol';
import {IUniswapV3PoolEvents} from './pool/IUniswapV3PoolEvents.sol';

/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
    IUniswapV3PoolImmutables,
    IUniswapV3PoolState,
    IUniswapV3PoolDerivedState,
    IUniswapV3PoolActions,
    IUniswapV3PoolOwnerActions,
    IUniswapV3PoolErrors,
    IUniswapV3PoolEvents
{

}
IUniswapV3PoolActions.sol 103 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
    /// @notice Sets the initial price for the pool
    /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
    /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
    function initialize(uint160 sqrtPriceX96) external;

    /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
    /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
    /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
    /// on tickLower, tickUpper, the amount of liquidity, and the current price.
    /// @param recipient The address for which the liquidity will be created
    /// @param tickLower The lower tick of the position in which to add liquidity
    /// @param tickUpper The upper tick of the position in which to add liquidity
    /// @param amount The amount of liquidity to mint
    /// @param data Any data that should be passed through to the callback
    /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
    /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
    function mint(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount,
        bytes calldata data
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Collects tokens owed to a position
    /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
    /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
    /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
    /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
    /// @param recipient The address which should receive the fees collected
    /// @param tickLower The lower tick of the position for which to collect fees
    /// @param tickUpper The upper tick of the position for which to collect fees
    /// @param amount0Requested How much token0 should be withdrawn from the fees owed
    /// @param amount1Requested How much token1 should be withdrawn from the fees owed
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);

    /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
    /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
    /// @dev Fees must be collected separately via a call to #collect
    /// @param tickLower The lower tick of the position for which to burn liquidity
    /// @param tickUpper The upper tick of the position for which to burn liquidity
    /// @param amount How much liquidity to burn
    /// @return amount0 The amount of token0 sent to the recipient
    /// @return amount1 The amount of token1 sent to the recipient
    function burn(
        int24 tickLower,
        int24 tickUpper,
        uint128 amount
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Swap token0 for token1, or token1 for token0
    /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
    /// @param recipient The address to receive the output of the swap
    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap
    /// @param data Any data to be passed through to the callback
    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);

    /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
    /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
    /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
    /// with 0 amount{0,1} and sending the donation amount(s) from the callback
    /// @param recipient The address which will receive the token0 and token1 amounts
    /// @param amount0 The amount of token0 to send
    /// @param amount1 The amount of token1 to send
    /// @param data Any data to be passed through to the callback
    function flash(
        address recipient,
        uint256 amount0,
        uint256 amount1,
        bytes calldata data
    ) external;

    /// @notice Increase the maximum number of price and liquidity observations that this pool will store
    /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
    /// the input observationCardinalityNext.
    /// @param observationCardinalityNext The desired minimum number of observations for the pool to store
    function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}
IUniswapV3PoolDerivedState.sol 40 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
    /// you must call it with secondsAgos = [3600, 0].
    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
    /// timestamp
    function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);

    /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
    /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
    /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
    /// snapshot is taken and the second snapshot is taken.
    /// @param tickLower The lower tick of the range
    /// @param tickUpper The upper tick of the range
    /// @return tickCumulativeInside The snapshot of the tick accumulator for the range
    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
    /// @return secondsInside The snapshot of seconds per liquidity for the range
    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
        external
        view
        returns (
            int56 tickCumulativeInside,
            uint160 secondsPerLiquidityInsideX128,
            uint32 secondsInside
        );
}
IUniswapV3PoolErrors.sol 19 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Errors emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolErrors {
    error LOK();
    error TLU();
    error TLM();
    error TUM();
    error AI();
    error M0();
    error M1();
    error AS();
    error IIA();
    error L();
    error F0();
    error F1();
}
IUniswapV3PoolEvents.sol 121 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool
    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
    event Initialize(uint160 sqrtPriceX96, int24 tick);

    /// @notice Emitted when liquidity is minted for a given position
    /// @param sender The address that minted the liquidity
    /// @param owner The owner of the position and recipient of any minted liquidity
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity minted to the position range
    /// @param amount0 How much token0 was required for the minted liquidity
    /// @param amount1 How much token1 was required for the minted liquidity
    event Mint(
        address sender,
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted when fees are collected by the owner of a position
    /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
    /// @param owner The owner of the position for which fees are collected
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount0 The amount of token0 fees collected
    /// @param amount1 The amount of token1 fees collected
    event Collect(
        address indexed owner,
        address recipient,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount0,
        uint128 amount1
    );

    /// @notice Emitted when a position's liquidity is removed
    /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
    /// @param owner The owner of the position for which liquidity is removed
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity to remove
    /// @param amount0 The amount of token0 withdrawn
    /// @param amount1 The amount of token1 withdrawn
    event Burn(
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted by the pool for any swaps between token0 and token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the output of the swap
    /// @param amount0 The delta of the token0 balance of the pool
    /// @param amount1 The delta of the token1 balance of the pool
    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
    /// @param liquidity The liquidity of the pool after the swap
    /// @param tick The log base 1.0001 of price of the pool after the swap
    event Swap(
        address indexed sender,
        address indexed recipient,
        int256 amount0,
        int256 amount1,
        uint160 sqrtPriceX96,
        uint128 liquidity,
        int24 tick
    );

    /// @notice Emitted by the pool for any flashes of token0/token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the tokens from flash
    /// @param amount0 The amount of token0 that was flashed
    /// @param amount1 The amount of token1 that was flashed
    /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
    /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
    event Flash(
        address indexed sender,
        address indexed recipient,
        uint256 amount0,
        uint256 amount1,
        uint256 paid0,
        uint256 paid1
    );

    /// @notice Emitted by the pool for increases to the number of observations that can be stored
    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
    /// just before a mint/swap/burn.
    /// @param observationCardinalityNextOld The previous value of the next observation cardinality
    /// @param observationCardinalityNextNew The updated value of the next observation cardinality
    event IncreaseObservationCardinalityNext(
        uint16 observationCardinalityNextOld,
        uint16 observationCardinalityNextNew
    );

    /// @notice Emitted when the protocol fee is changed by the pool
    /// @param feeProtocol0Old The previous value of the token0 protocol fee
    /// @param feeProtocol1Old The previous value of the token1 protocol fee
    /// @param feeProtocol0New The updated value of the token0 protocol fee
    /// @param feeProtocol1New The updated value of the token1 protocol fee
    event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);

    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
    /// @param sender The address that collects the protocol fees
    /// @param recipient The address that receives the collected protocol fees
    /// @param amount0 The amount of token0 protocol fees that is withdrawn
    /// @param amount0 The amount of token1 protocol fees that is withdrawn
    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}
IUniswapV3PoolImmutables.sol 35 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
    /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
    /// @return The contract address
    function factory() external view returns (address);

    /// @notice The first of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token0() external view returns (address);

    /// @notice The second of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token1() external view returns (address);

    /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
    /// @return The fee
    function fee() external view returns (uint24);

    /// @notice The pool tick spacing
    /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
    /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
    /// This value is an int24 to avoid casting even though it is always positive.
    /// @return The tick spacing
    function tickSpacing() external view returns (int24);

    /// @notice The maximum amount of position liquidity that can use any tick in the range
    /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
    /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
    /// @return The max amount of liquidity per tick
    function maxLiquidityPerTick() external view returns (uint128);
}
IUniswapV3PoolOwnerActions.sol 23 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
    /// @notice Set the denominator of the protocol's % share of the fees
    /// @param feeProtocol0 new protocol fee for token0 of the pool
    /// @param feeProtocol1 new protocol fee for token1 of the pool
    function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;

    /// @notice Collect the protocol fee accrued to the pool
    /// @param recipient The address to which collected protocol fees should be sent
    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
    /// @return amount0 The protocol fee collected in token0
    /// @return amount1 The protocol fee collected in token1
    function collectProtocol(
        address recipient,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);
}
IUniswapV3PoolState.sol 117 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
    /// when accessed externally.
    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
    /// @return tick The current tick of the pool, i.e. according to the last tick transition that was run.
    /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
    /// boundary.
    /// @return observationIndex The index of the last oracle observation that was written,
    /// @return observationCardinality The current maximum number of observations stored in the pool,
    /// @return observationCardinalityNext The next maximum number of observations, to be updated when the observation.
    /// @return feeProtocol The protocol fee for both tokens of the pool.
    /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
    /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
    /// unlocked Whether the pool is currently locked to reentrancy
    function slot0()
        external
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tick,
            uint16 observationIndex,
            uint16 observationCardinality,
            uint16 observationCardinalityNext,
            uint8 feeProtocol,
            bool unlocked
        );

    /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal0X128() external view returns (uint256);

    /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal1X128() external view returns (uint256);

    /// @notice The amounts of token0 and token1 that are owed to the protocol
    /// @dev Protocol fees will never exceed uint128 max in either token
    function protocolFees() external view returns (uint128 token0, uint128 token1);

    /// @notice The currently in range liquidity available to the pool
    /// @dev This value has no relationship to the total liquidity across all ticks
    /// @return The liquidity at the current price of the pool
    function liquidity() external view returns (uint128);

    /// @notice Look up information about a specific tick in the pool
    /// @param tick The tick to look up
    /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
    /// tick upper
    /// @return liquidityNet how much liquidity changes when the pool price crosses the tick,
    /// @return feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
    /// @return feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
    /// @return tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
    /// @return secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
    /// @return secondsOutside the seconds spent on the other side of the tick from the current tick,
    /// @return initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
    /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
    /// In addition, these values are only relative and must be used only in comparison to previous snapshots for
    /// a specific position.
    function ticks(int24 tick)
        external
        view
        returns (
            uint128 liquidityGross,
            int128 liquidityNet,
            uint256 feeGrowthOutside0X128,
            uint256 feeGrowthOutside1X128,
            int56 tickCumulativeOutside,
            uint160 secondsPerLiquidityOutsideX128,
            uint32 secondsOutside,
            bool initialized
        );

    /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
    function tickBitmap(int16 wordPosition) external view returns (uint256);

    /// @notice Returns the information about a position by the position's key
    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
    /// @return liquidity The amount of liquidity in the position,
    /// @return feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
    /// @return feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
    /// @return tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
    /// @return tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
    function positions(bytes32 key)
        external
        view
        returns (
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    /// @notice Returns data about a specific observation index
    /// @param index The element of the observations array to fetch
    /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
    /// ago, rather than at a specific index in the array.
    /// @return blockTimestamp The timestamp of the observation,
    /// @return tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
    /// @return secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
    /// @return initialized whether the observation has been initialized and the values are safe to use
    function observations(uint256 index)
        external
        view
        returns (
            uint32 blockTimestamp,
            int56 tickCumulative,
            uint160 secondsPerLiquidityCumulativeX128,
            bool initialized
        );
}
FixedPoint96.sol 10 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;

/// @title FixedPoint96
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
/// @dev Used in SqrtPriceMath.sol
library FixedPoint96 {
    uint8 internal constant RESOLUTION = 96;
    uint256 internal constant Q96 = 0x1000000000000000000000000;
}
FullMath.sol 128 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
    function mulDiv(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = a * b
            // Compute the product mod 2**256 and mod 2**256 - 1
            // then 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(a, b, not(0))
                prod0 := mul(a, b)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division
            if (prod1 == 0) {
                require(denominator > 0);
                assembly {
                    result := div(prod0, denominator)
                }
                return result;
            }

            // 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]
            // Compute remainder using mulmod
            uint256 remainder;
            assembly {
                remainder := mulmod(a, b, denominator)
            }
            // Subtract 256 bit number from 512 bit number
            assembly {
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator
            // Compute largest power of two divisor of denominator.
            // Always >= 1.
            uint256 twos = (0 - denominator) & denominator;
            // Divide denominator by power of two
            assembly {
                denominator := div(denominator, twos)
            }

            // Divide [prod1 prod0] by the factors of two
            assembly {
                prod0 := div(prod0, twos)
            }
            // Shift in bits from prod1 into prod0. For this we need
            // to flip `twos` such that it is 2**256 / twos.
            // If twos is zero, then it becomes one
            assembly {
                twos := add(div(sub(0, twos), twos), 1)
            }
            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
            // correct for four bits. That is, denominator * inv = 1 mod 2**4
            uint256 inv = (3 * denominator) ^ 2;
            // Now use 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.
            inv *= 2 - denominator * inv; // inverse mod 2**8
            inv *= 2 - denominator * inv; // inverse mod 2**16
            inv *= 2 - denominator * inv; // inverse mod 2**32
            inv *= 2 - denominator * inv; // inverse mod 2**64
            inv *= 2 - denominator * inv; // inverse mod 2**128
            inv *= 2 - denominator * inv; // 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 precoditions 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 * inv;
            return result;
        }
    }

    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    function mulDivRoundingUp(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            result = mulDiv(a, b, denominator);
            if (mulmod(a, b, denominator) > 0) {
                require(result < type(uint256).max);
                result++;
            }
        }
    }
}
TickMath.sol 214 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
    error T();
    error R();

    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
    int24 internal constant MAX_TICK = -MIN_TICK;

    /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
    uint160 internal constant MIN_SQRT_RATIO = 4295128739;
    /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;

    /// @notice Calculates sqrt(1.0001^tick) * 2^96
    /// @dev Throws if |tick| > max tick
    /// @param tick The input tick for the above formula
    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
    /// at the given tick
    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        unchecked {
            uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
            if (absTick > uint256(int256(MAX_TICK))) revert T();

            uint256 ratio = absTick & 0x1 != 0
                ? 0xfffcb933bd6fad37aa2d162d1a594001
                : 0x100000000000000000000000000000000;
            if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
            if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
            if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
            if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
            if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
            if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
            if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
            if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
            if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
            if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
            if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
            if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
            if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
            if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
            if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
            if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
            if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
            if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
            if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;

            if (tick > 0) ratio = type(uint256).max / ratio;

            // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
            // we then downcast because we know the result always fits within 160 bits due to our tick input constraint
            // we round up in the division so getTickAtSqrtRatio of the output price is always consistent
            sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
        }
    }

    /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
    /// ever return.
    /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
    /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
        unchecked {
            // second inequality must be < because the price can never reach the price at the max tick
            if (!(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO)) revert R();
            uint256 ratio = uint256(sqrtPriceX96) << 32;

            uint256 r = ratio;
            uint256 msb = 0;

            assembly {
                let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(5, gt(r, 0xFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(4, gt(r, 0xFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(3, gt(r, 0xFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(2, gt(r, 0xF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(1, gt(r, 0x3))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := gt(r, 0x1)
                msb := or(msb, f)
            }

            if (msb >= 128) r = ratio >> (msb - 127);
            else r = ratio << (127 - msb);

            int256 log_2 = (int256(msb) - 128) << 64;

            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(63, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(62, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(61, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(60, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(59, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(58, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(57, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(56, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(55, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(54, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(53, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(52, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(51, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(50, f))
            }

            int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

            int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
            int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);

            tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
        }
    }
}
IERC721Permit.sol 32 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

import '@openzeppelin/contracts/token/ERC721/IERC721.sol';

/// @title ERC721 with permit
/// @notice Extension to ERC721 that includes a permit function for signature based approvals
interface IERC721Permit is IERC721 {
    /// @notice The permit typehash used in the permit signature
    /// @return The typehash for the permit
    function PERMIT_TYPEHASH() external pure returns (bytes32);

    /// @notice The domain separator used in the permit signature
    /// @return The domain seperator used in encoding of permit signature
    function DOMAIN_SEPARATOR() external view returns (bytes32);

    /// @notice Approve of a specific token ID for spending by spender via signature
    /// @param spender The account that is being approved
    /// @param tokenId The ID of the token that is being approved for spending
    /// @param deadline The deadline timestamp by which the call must be mined for the approve to work
    /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
    /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
    /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
    function permit(
        address spender,
        uint256 tokenId,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable;
}
INonfungiblePositionManager.sol 180 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol';

import './IPoolInitializer.sol';
import './IERC721Permit.sol';
import './IPeripheryPayments.sol';
import './IPeripheryImmutableState.sol';
import '../libraries/PoolAddress.sol';

/// @title Non-fungible token for positions
/// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
interface INonfungiblePositionManager is
    IPoolInitializer,
    IPeripheryPayments,
    IPeripheryImmutableState,
    IERC721Metadata,
    IERC721Enumerable,
    IERC721Permit
{
    /// @notice Emitted when liquidity is increased for a position NFT
    /// @dev Also emitted when a token is minted
    /// @param tokenId The ID of the token for which liquidity was increased
    /// @param liquidity The amount by which liquidity for the NFT position was increased
    /// @param amount0 The amount of token0 that was paid for the increase in liquidity
    /// @param amount1 The amount of token1 that was paid for the increase in liquidity
    event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when liquidity is decreased for a position NFT
    /// @param tokenId The ID of the token for which liquidity was decreased
    /// @param liquidity The amount by which liquidity for the NFT position was decreased
    /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
    /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
    event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when tokens are collected for a position NFT
    /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
    /// @param tokenId The ID of the token for which underlying tokens were collected
    /// @param recipient The address of the account that received the collected tokens
    /// @param amount0 The amount of token0 owed to the position that was collected
    /// @param amount1 The amount of token1 owed to the position that was collected
    event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);

    /// @notice Returns the position information associated with a given token ID.
    /// @dev Throws if the token ID is not valid.
    /// @param tokenId The ID of the token that represents the position
    /// @return nonce The nonce for permits
    /// @return operator The address that is approved for spending
    /// @return token0 The address of the token0 for a specific pool
    /// @return token1 The address of the token1 for a specific pool
    /// @return fee The fee associated with the pool
    /// @return tickLower The lower end of the tick range for the position
    /// @return tickUpper The higher end of the tick range for the position
    /// @return liquidity The liquidity of the position
    /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
    /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
    /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
    /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
    function positions(uint256 tokenId)
        external
        view
        returns (
            uint96 nonce,
            address operator,
            address token0,
            address token1,
            uint24 fee,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    struct MintParams {
        address token0;
        address token1;
        uint24 fee;
        int24 tickLower;
        int24 tickUpper;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
        address recipient;
        uint256 deadline;
    }

    /// @notice Creates a new position wrapped in a NFT
    /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
    /// a method does not exist, i.e. the pool is assumed to be initialized.
    /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
    /// @return tokenId The ID of the token that represents the minted position
    /// @return liquidity The amount of liquidity for this position
    /// @return amount0 The amount of token0
    /// @return amount1 The amount of token1
    function mint(MintParams calldata params)
        external
        payable
        returns (
            uint256 tokenId,
            uint128 liquidity,
            uint256 amount0,
            uint256 amount1
        );

    struct IncreaseLiquidityParams {
        uint256 tokenId;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 deadline;
    }

    /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
    /// @param params tokenId The ID of the token for which liquidity is being increased,
    /// amount0Desired The desired amount of token0 to be spent,
    /// amount1Desired The desired amount of token1 to be spent,
    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
    /// deadline The time by which the transaction must be included to effect the change
    /// @return liquidity The new liquidity amount as a result of the increase
    /// @return amount0 The amount of token0 to acheive resulting liquidity
    /// @return amount1 The amount of token1 to acheive resulting liquidity
    function increaseLiquidity(IncreaseLiquidityParams calldata params)
        external
        payable
        returns (
            uint128 liquidity,
            uint256 amount0,
            uint256 amount1
        );

    struct DecreaseLiquidityParams {
        uint256 tokenId;
        uint128 liquidity;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 deadline;
    }

    /// @notice Decreases the amount of liquidity in a position and accounts it to the position
    /// @param params tokenId The ID of the token for which liquidity is being decreased,
    /// amount The amount by which liquidity will be decreased,
    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
    /// deadline The time by which the transaction must be included to effect the change
    /// @return amount0 The amount of token0 accounted to the position's tokens owed
    /// @return amount1 The amount of token1 accounted to the position's tokens owed
    function decreaseLiquidity(DecreaseLiquidityParams calldata params)
        external
        payable
        returns (uint256 amount0, uint256 amount1);

    struct CollectParams {
        uint256 tokenId;
        address recipient;
        uint128 amount0Max;
        uint128 amount1Max;
    }

    /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
    /// @param params tokenId The ID of the NFT for which tokens are being collected,
    /// recipient The account that should receive the tokens,
    /// amount0Max The maximum amount of token0 to collect,
    /// amount1Max The maximum amount of token1 to collect
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);

    /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
    /// must be collected first.
    /// @param tokenId The ID of the token that is being burned
    function burn(uint256 tokenId) external payable;
}
IPeripheryImmutableState.sol 12 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Immutable state
/// @notice Functions that return immutable state of the router
interface IPeripheryImmutableState {
    /// @return Returns the address of the Uniswap V3 factory
    function factory() external view returns (address);

    /// @return Returns the address of WETH9
    function WETH9() external view returns (address);
}
IPeripheryPayments.sol 28 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

/// @title Periphery Payments
/// @notice Functions to ease deposits and withdrawals of ETH
interface IPeripheryPayments {
    /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.
    /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
    /// @param amountMinimum The minimum amount of WETH9 to unwrap
    /// @param recipient The address receiving ETH
    function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;

    /// @notice Refunds any ETH balance held by this contract to the `msg.sender`
    /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
    /// that use ether for the input amount
    function refundETH() external payable;

    /// @notice Transfers the full amount of a token held by this contract to recipient
    /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
    /// @param token The contract address of the token which will be transferred to `recipient`
    /// @param amountMinimum The minimum amount of token required for a transfer
    /// @param recipient The destination address of the token
    function sweepToken(
        address token,
        uint256 amountMinimum,
        address recipient
    ) external payable;
}
IPoolInitializer.sol 22 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

/// @title Creates and initializes V3 Pools
/// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that
/// require the pool to exist.
interface IPoolInitializer {
    /// @notice Creates a new pool if it does not exist, then initializes if not initialized
    /// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool
    /// @param token0 The contract address of token0 of the pool
    /// @param token1 The contract address of token1 of the pool
    /// @param fee The fee amount of the v3 pool for the specified token pair
    /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value
    /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary
    function createAndInitializePoolIfNecessary(
        address token0,
        address token1,
        uint24 fee,
        uint160 sqrtPriceX96
    ) external payable returns (address pool);
}
LiquidityAmounts.sol 145 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import '@uniswap/v3-core/contracts/libraries/FixedPoint96.sol';

/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
library LiquidityAmounts {
    /// @notice Downcasts uint256 to uint128
    /// @param x The uint258 to be downcasted
    /// @return y The passed value, downcasted to uint128
    function toUint128(uint256 x) private pure returns (uint128 y) {
        require((y = uint128(x)) == x);
    }

    /// @notice Computes the amount of liquidity received for a given amount of token0 and price range
    /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param amount0 The amount0 being sent in
    /// @return liquidity The amount of returned liquidity
    function getLiquidityForAmount0(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96);
        unchecked {
            return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96));
        }
    }

    /// @notice Computes the amount of liquidity received for a given amount of token1 and price range
    /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param amount1 The amount1 being sent in
    /// @return liquidity The amount of returned liquidity
    function getLiquidityForAmount1(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        unchecked {
            return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96));
        }
    }

    /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current
    /// pool prices and the prices at the tick boundaries
    /// @param sqrtRatioX96 A sqrt price representing the current pool prices
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param amount0 The amount of token0 being sent in
    /// @param amount1 The amount of token1 being sent in
    /// @return liquidity The maximum amount of liquidity received
    function getLiquidityForAmounts(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);
            uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);

            liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;
        } else {
            liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1);
        }
    }

    /// @notice Computes the amount of token0 for a given amount of liquidity and a price range
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount0 The amount of token0
    function getAmount0ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0) {
        unchecked {
            if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

            return
                FullMath.mulDiv(
                    uint256(liquidity) << FixedPoint96.RESOLUTION,
                    sqrtRatioBX96 - sqrtRatioAX96,
                    sqrtRatioBX96
                ) / sqrtRatioAX96;
        }
    }

    /// @notice Computes the amount of token1 for a given amount of liquidity and a price range
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount1 The amount of token1
    function getAmount1ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        unchecked {
            return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
        }
    }

    /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current
    /// pool prices and the prices at the tick boundaries
    /// @param sqrtRatioX96 A sqrt price representing the current pool prices
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount0 The amount of token0
    /// @return amount1 The amount of token1
    function getAmountsForLiquidity(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0, uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity);
            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity);
        } else {
            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
        }
    }
}
OracleLibrary.sol 186 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0 <0.9.0;

import '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import '@uniswap/v3-core/contracts/libraries/TickMath.sol';
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';

/// @title Oracle library
/// @notice Provides functions to integrate with V3 pool oracle
library OracleLibrary {
    /// @notice Calculates time-weighted means of tick and liquidity for a given Uniswap V3 pool
    /// @param pool Address of the pool that we want to observe
    /// @param secondsAgo Number of seconds in the past from which to calculate the time-weighted means
    /// @return arithmeticMeanTick The arithmetic mean tick from (block.timestamp - secondsAgo) to block.timestamp
    /// @return harmonicMeanLiquidity The harmonic mean liquidity from (block.timestamp - secondsAgo) to block.timestamp
    function consult(address pool, uint32 secondsAgo)
        internal
        view
        returns (int24 arithmeticMeanTick, uint128 harmonicMeanLiquidity)
    {
        require(secondsAgo != 0, 'BP');

        uint32[] memory secondsAgos = new uint32[](2);
        secondsAgos[0] = secondsAgo;
        secondsAgos[1] = 0;

        (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) = IUniswapV3Pool(pool)
            .observe(secondsAgos);

        int56 tickCumulativesDelta = tickCumulatives[1] - tickCumulatives[0];
        uint160 secondsPerLiquidityCumulativesDelta = secondsPerLiquidityCumulativeX128s[1] -
            secondsPerLiquidityCumulativeX128s[0];

        arithmeticMeanTick = int24(tickCumulativesDelta / int56(uint56(secondsAgo)));
        // Always round to negative infinity
        if (tickCumulativesDelta < 0 && (tickCumulativesDelta % int56(uint56(secondsAgo)) != 0)) arithmeticMeanTick--;

        // We are multiplying here instead of shifting to ensure that harmonicMeanLiquidity doesn't overflow uint128
        uint192 secondsAgoX160 = uint192(secondsAgo) * type(uint160).max;
        harmonicMeanLiquidity = uint128(secondsAgoX160 / (uint192(secondsPerLiquidityCumulativesDelta) << 32));
    }

    /// @notice Given a tick and a token amount, calculates the amount of token received in exchange
    /// @param tick Tick value used to calculate the quote
    /// @param baseAmount Amount of token to be converted
    /// @param baseToken Address of an ERC20 token contract used as the baseAmount denomination
    /// @param quoteToken Address of an ERC20 token contract used as the quoteAmount denomination
    /// @return quoteAmount Amount of quoteToken received for baseAmount of baseToken
    function getQuoteAtTick(
        int24 tick,
        uint128 baseAmount,
        address baseToken,
        address quoteToken
    ) internal pure returns (uint256 quoteAmount) {
        uint160 sqrtRatioX96 = TickMath.getSqrtRatioAtTick(tick);

        // Calculate quoteAmount with better precision if it doesn't overflow when multiplied by itself
        if (sqrtRatioX96 <= type(uint128).max) {
            uint256 ratioX192 = uint256(sqrtRatioX96) * sqrtRatioX96;
            quoteAmount = baseToken < quoteToken
                ? FullMath.mulDiv(ratioX192, baseAmount, 1 << 192)
                : FullMath.mulDiv(1 << 192, baseAmount, ratioX192);
        } else {
            uint256 ratioX128 = FullMath.mulDiv(sqrtRatioX96, sqrtRatioX96, 1 << 64);
            quoteAmount = baseToken < quoteToken
                ? FullMath.mulDiv(ratioX128, baseAmount, 1 << 128)
                : FullMath.mulDiv(1 << 128, baseAmount, ratioX128);
        }
    }

    /// @notice Given a pool, it returns the number of seconds ago of the oldest stored observation
    /// @param pool Address of Uniswap V3 pool that we want to observe
    /// @return secondsAgo The number of seconds ago of the oldest observation stored for the pool
    function getOldestObservationSecondsAgo(address pool) internal view returns (uint32 secondsAgo) {
        (, , uint16 observationIndex, uint16 observationCardinality, , , ) = IUniswapV3Pool(pool).slot0();
        require(observationCardinality > 0, 'NI');

        (uint32 observationTimestamp, , , bool initialized) = IUniswapV3Pool(pool).observations(
            (observationIndex + 1) % observationCardinality
        );

        // The next index might not be initialized if the cardinality is in the process of increasing
        // In this case the oldest observation is always in index 0
        if (!initialized) {
            (observationTimestamp, , , ) = IUniswapV3Pool(pool).observations(0);
        }

        unchecked {
            secondsAgo = uint32(block.timestamp) - observationTimestamp;
        }
    }

    /// @notice Given a pool, it returns the tick value as of the start of the current block
    /// @param pool Address of Uniswap V3 pool
    /// @return The tick that the pool was in at the start of the current block
    function getBlockStartingTickAndLiquidity(address pool) internal view returns (int24, uint128) {
        (, int24 tick, uint16 observationIndex, uint16 observationCardinality, , , ) = IUniswapV3Pool(pool).slot0();

        // 2 observations are needed to reliably calculate the block starting tick
        require(observationCardinality > 1, 'NEO');

        // If the latest observation occurred in the past, then no tick-changing trades have happened in this block
        // therefore the tick in `slot0` is the same as at the beginning of the current block.
        // We don't need to check if this observation is initialized - it is guaranteed to be.
        (
            uint32 observationTimestamp,
            int56 tickCumulative,
            uint160 secondsPerLiquidityCumulativeX128,

        ) = IUniswapV3Pool(pool).observations(observationIndex);
        if (observationTimestamp != uint32(block.timestamp)) {
            return (tick, IUniswapV3Pool(pool).liquidity());
        }

        uint256 prevIndex = (uint256(observationIndex) + observationCardinality - 1) % observationCardinality;
        (
            uint32 prevObservationTimestamp,
            int56 prevTickCumulative,
            uint160 prevSecondsPerLiquidityCumulativeX128,
            bool prevInitialized
        ) = IUniswapV3Pool(pool).observations(prevIndex);

        require(prevInitialized, 'ONI');

        uint32 delta = observationTimestamp - prevObservationTimestamp;
        tick = int24((tickCumulative - int56(uint56(prevTickCumulative))) / int56(uint56(delta)));
        uint128 liquidity = uint128(
            (uint192(delta) * type(uint160).max) /
                (uint192(secondsPerLiquidityCumulativeX128 - prevSecondsPerLiquidityCumulativeX128) << 32)
        );
        return (tick, liquidity);
    }

    /// @notice Information for calculating a weighted arithmetic mean tick
    struct WeightedTickData {
        int24 tick;
        uint128 weight;
    }

    /// @notice Given an array of ticks and weights, calculates the weighted arithmetic mean tick
    /// @param weightedTickData An array of ticks and weights
    /// @return weightedArithmeticMeanTick The weighted arithmetic mean tick
    /// @dev Each entry of `weightedTickData` should represents ticks from pools with the same underlying pool tokens. If they do not,
    /// extreme care must be taken to ensure that ticks are comparable (including decimal differences).
    /// @dev Note that the weighted arithmetic mean tick corresponds to the weighted geometric mean price.
    function getWeightedArithmeticMeanTick(WeightedTickData[] memory weightedTickData)
        internal
        pure
        returns (int24 weightedArithmeticMeanTick)
    {
        // Accumulates the sum of products between each tick and its weight
        int256 numerator;

        // Accumulates the sum of the weights
        uint256 denominator;

        // Products fit in 152 bits, so it would take an array of length ~2**104 to overflow this logic
        for (uint256 i; i < weightedTickData.length; i++) {
            numerator += weightedTickData[i].tick * int256(uint256(weightedTickData[i].weight));
            denominator += weightedTickData[i].weight;
        }

        weightedArithmeticMeanTick = int24(numerator / int256(denominator));
        // Always round to negative infinity
        if (numerator < 0 && (numerator % int256(denominator) != 0)) weightedArithmeticMeanTick--;
    }

    /// @notice Returns the "synthetic" tick which represents the price of the first entry in `tokens` in terms of the last
    /// @dev Useful for calculating relative prices along routes.
    /// @dev There must be one tick for each pairwise set of tokens.
    /// @param tokens The token contract addresses
    /// @param ticks The ticks, representing the price of each token pair in `tokens`
    /// @return syntheticTick The synthetic tick, representing the relative price of the outermost tokens in `tokens`
    function getChainedPrice(address[] memory tokens, int24[] memory ticks)
        internal
        pure
        returns (int256 syntheticTick)
    {
        require(tokens.length - 1 == ticks.length, 'DL');
        for (uint256 i = 1; i <= ticks.length; i++) {
            // check the tokens for address sort order, then accumulate the
            // ticks into the running synthetic tick, ensuring that intermediate tokens "cancel out"
            tokens[i - 1] < tokens[i] ? syntheticTick += ticks[i - 1] : syntheticTick -= ticks[i - 1];
        }
    }
}
PoolAddress.sol 50 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
library PoolAddress {
    bytes32 internal constant POOL_INIT_CODE_HASH = 0xa598dd2fba360510c5a8f02f44423a4468e902df5857dbce3ca162a43a3a31ff;

    /// @notice The identifying key of the pool
    struct PoolKey {
        address token0;
        address token1;
        uint24 fee;
    }

    /// @notice Returns PoolKey: the ordered tokens with the matched fee levels
    /// @param tokenA The first token of a pool, unsorted
    /// @param tokenB The second token of a pool, unsorted
    /// @param fee The fee level of the pool
    /// @return Poolkey The pool details with ordered token0 and token1 assignments
    function getPoolKey(
        address tokenA,
        address tokenB,
        uint24 fee
    ) internal pure returns (PoolKey memory) {
        if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
        return PoolKey({token0: tokenA, token1: tokenB, fee: fee});
    }

    /// @notice Deterministically computes the pool address given the factory and PoolKey
    /// @param factory The Uniswap V3 factory contract address
    /// @param key The PoolKey
    /// @return pool The contract address of the V3 pool
    function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) {
        require(key.token0 < key.token1);
        pool = address(
            uint160(
                uint256(
                    keccak256(
                        abi.encodePacked(
                            hex'ff',
                            factory,
                            keccak256(abi.encode(key.token0, key.token1, key.fee)),
                            POOL_INIT_CODE_HASH
                        )
                    )
                )
            )
        );
    }
}
UniswapStakingAdapter.sol 384 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.28;

import {INonfungiblePositionManager} from "@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol";
import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {LiquidityAmounts} from "@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol";
import {TickMath} from "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import {IUniswapV3Factory} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {Ownable2Step, Ownable} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {OracleLibrary} from "@uniswap/v3-periphery/contracts/libraries/OracleLibrary.sol";

import {IStaking} from "./interfaces/IStaking.sol";
import {BaseStakingAdapter} from "./base/BaseStakingAdapter.sol";
import {IUniswapStakingAdapter} from "./interfaces/adapters/IUniswapStakingAdapter.sol";

contract UniswapStakingAdapter is
    BaseStakingAdapter,
    Ownable2Step,
    IERC721Receiver,
    IUniswapStakingAdapter
{
    INonfungiblePositionManager public positionManager;
    IUniswapV3Factory public poolFactory;

    /// @notice Mapping of allowed Uniswap V3 liquidity pools
    /// @dev The key is the pool address, and the value is a boolean indicating whether the pool is allowed
    mapping(address pool => bool allowed) public poolAllowed;

    /// @notice Mapping of user stakes, keyed by stake index
    /// @dev The key is the stake index, and the value is the token ID
    mapping(uint256 stakeIdx => uint256 tokenId) public stakeIdxToTokenId;

    /// @notice Mapping of user stakes, keyed by user address and pool address
    /// @dev The key is the stake index, and the value is the pool address
    mapping(uint256 stakeIdx => address pool) public stakeIdxToPool;

    /// @notice Mapping of stake index to amount staked
    mapping(uint256 stakeIdx => uint256 amount) public stakeIdxToAmountStaked;

    /// @notice Mapping of stakes keyed by pool address
    mapping(address pool => uint256 stakedAmount) public totalStakedByPool;

    /// @notice Mapping of staking metrics keyed by pool address
    mapping(address => IStaking.StakingMetrics) public poolStakingMetrics;

    /// @notice The maximum tick value for a Uniswap V3 position
    int256 public constant TICK_MAX = 887220;

    /// @notice The minimum tick value for a Uniswap V3 position
    int256 public constant TICK_MIN = -887220;

    /// @notice Checks if the caller is the staking contract
    modifier onlyStaking() {
        if (msg.sender != address(staking)) {
            revert OnlyStakingContract();
        }
        _;
    }

    /**
     * @notice Initializes the contract with the Uniswap position manager and factory addresses
     * @param positionManager_ The address of the Uniswap V3 Nonfungible Position Manager
     * @param factory_ The address of the Uniswap V3 Pool Factory
     */
    constructor(
        address positionManager_,
        address factory_,
        address arcadeToken_,
        address staking_,
        address initialOwner_
    ) BaseStakingAdapter(arcadeToken_, staking_) Ownable(initialOwner_) {
        positionManager = INonfungiblePositionManager(positionManager_);
        poolFactory = IUniswapV3Factory(factory_);
    }

    // External functions

    /**
     * @param pool The address of the Uniswap V3 pool
     * @return The staking metrics for the pool
     */
    function getPoolStakingMetrics(
        address pool
    ) external view returns (IStaking.StakingMetrics memory) {
        return poolStakingMetrics[pool];
    }

    /**
     * @notice Handles the unlocking of a stake, releasing the Uniswap position
     * @param stakeId The ID of the stake
     */
    function onStakeUnlocked(
        uint256 stakeId
    )
        external
        override(IUniswapStakingAdapter, BaseStakingAdapter)
        onlyStaking
    {
        uint256 tokenId = stakeIdxToTokenId[stakeId];
        address owner = staking.stakeToUser(stakeId);

        uint256 amountStaked = stakeIdxToAmountStaked[stakeId];
        address pool = stakeIdxToPool[stakeId];

        // Update total staked by pool
        totalStakedByPool[pool] -= amountStaked;

        IStaking.Stake memory stakeRecord = staking.getStakeDetails(stakeId);

        // Update pool staking metrics
        poolStakingMetrics[pool].stakeCount--;
        poolStakingMetrics[pool].aetvl -= stakeRecord.ietvl;
        poolStakingMetrics[pool].totalDlmr -= stakeRecord.dlmr;

        _releasePosition(tokenId, owner);

        emit StakeUnlocked(stakeId, tokenId, owner, amountStaked, pool);
    }

    function setLiquidityPoolAllowed(
        address pool,
        bool status
    ) external onlyOwner {
        poolAllowed[pool] = status;
        emit LiquidityPoolAllowed(pool, status);
    }

    /**
     * @notice Handles receipt of an ERC721 token
     * @dev Always returns `IERC721Receiver.onERC721Received.selector`
     * @return The selector for this function
     */
    function onERC721Received(
        address,
        address,
        uint256,
        bytes calldata
    ) external pure override returns (bytes4) {
        return this.onERC721Received.selector;
    }

    /**
     * @notice Stakes a Uniswap position and locks it into the contract
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @param stakeDurationDays The lockup period for the stake in days
     */
    function stakeWithUniswapPosition(
        uint256 tokenId,
        uint256 stakeDurationDays
    ) public returns (uint256 stakeIdx, int256 ietvl, int256 dlmr) {
        (address pool, , ) = _getPositionPool(tokenId);
        address user = msg.sender;

        _validatePositionTickRange(tokenId);

        if (!poolAllowed[pool]) {
            revert InvalidPool();
        }

        uint256 arcadeTokenValue = getLockedValueInArcadeTokens(tokenId, pool);

        totalStakedByPool[pool] += arcadeTokenValue;

        _lockPosition(tokenId, user);

        return
            _callStake(
                tokenId,
                user,
                arcadeTokenValue,
                stakeDurationDays,
                pool
            );
    }

    /**
     * @notice Gets the total value locked in Arcade tokens for a given Uniswap position
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @param pool The address of the Uniswap V3 pool
     * @return The total value locked in Arcade tokens
     */
    function getLockedValueInArcadeTokens(
        uint256 tokenId,
        address pool
    ) public view returns (uint256) {
        (uint256 amountArc, uint256 amountQuote, ) = _getPositionAmountsSorted(
            tokenId,
            pool
        );

        (address token0, address token1, ) = _getPositionTokenDetails(tokenId);

        bool isArcToken0 = (token0 == arcadeToken);
        address quoteToken = isArcToken0 ? token1 : token0;

        (int24 twapTick, ) = OracleLibrary.consult(pool, 30);

        uint256 totalArcValue = amountArc;

        if (amountQuote > 0) {
            uint256 quoteInArc = OracleLibrary.getQuoteAtTick(
                twapTick,
                uint128(amountQuote),
                quoteToken,
                arcadeToken
            );
            totalArcValue += quoteInArc;
        }

        return totalArcValue;
    }

    // Internal functions

    /**
     * @dev Locks a Uniswap V3 position by transferring the NFT to the contract
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @param positionHolder The address of the user who holds the position
     */
    function _lockPosition(uint256 tokenId, address positionHolder) internal {
        positionManager.safeTransferFrom(
            positionHolder,
            address(this),
            tokenId
        );
    }

    /**
     * @dev Releases a locked Uniswap V3 position by transferring the NFT back to the user
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @param positionHolder The address of the user who held the position
     */
    function _releasePosition(
        uint256 tokenId,
        address positionHolder
    ) internal {
        positionManager.safeTransferFrom(
            address(this),
            positionHolder,
            tokenId
        );
    }

    /**
     * @dev Calls the staking contract to stake the value of the Uniswap position in Arcade tokens
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @param user The address of the user staking the position
     * @param arcValueStaked The value of the position in Arcade tokens
     * @param stakeDuration The duration of the stake in seconds
     * @param pool The address of the Uniswap V3 pool
     */
    function _callStake(
        uint256 tokenId,
        address user,
        uint256 arcValueStaked,
        uint256 stakeDuration,
        address pool
    ) internal returns (uint256 stakeIdx, int256 ietvl, int256 dlmr) {
        (stakeIdx, ietvl, dlmr) = staking.stake(
            user,
            arcValueStaked,
            stakeDuration,
            address(this)
        );

        poolStakingMetrics[pool].stakeCount++;
        poolStakingMetrics[pool].aetvl += ietvl;
        poolStakingMetrics[pool].totalDlmr += dlmr;

        stakeIdxToAmountStaked[stakeIdx] = arcValueStaked;

        stakeIdxToPool[stakeIdx] = pool;
        stakeIdxToTokenId[stakeIdx] = tokenId;
    }

    /**
     * @dev Retrieves the sqrt price for the given Uniswap pool
     * @param pool The address of the Uniswap V3 pool
     * @return sqrtRatioX96 The square root of the current price in the pool
     */
    function _getPoolSqrtRatioX96(
        address pool
    ) internal view returns (uint160 sqrtRatioX96) {
        (sqrtRatioX96, , , , , , ) = IUniswapV3Pool(pool).slot0();
    }

    /**
     * @dev Retrieves the token details for a given Uniswap position
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @return token0 The address of the first token in the pair
     * @return token1 The address of the second token in the pair
     * @return fee The fee tier of the Uniswap pool
     */
    function _getPositionTokenDetails(
        uint256 tokenId
    ) internal view returns (address token0, address token1, uint24 fee) {
        (, , token0, token1, fee, , , , , , , ) = positionManager.positions(
            tokenId
        );
    }

    /**
     * @dev Retrieves the liquidity details for a given Uniswap position
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @return tickLower The lower bound of the tick range
     * @return tickUpper The upper bound of the tick range
     * @return liquidity The amount of liquidity provided in the position
     */
    function _getPositionLiquidityDetails(
        uint256 tokenId
    )
        internal
        view
        returns (int24 tickLower, int24 tickUpper, uint128 liquidity)
    {
        (, , , , , tickLower, tickUpper, liquidity, , , , ) = positionManager
            .positions(tokenId);
    }

    /**
     * @dev Retrieves the pool address for a given Uniswap position
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @return pool The address of the Uniswap V3 pool
     */
    function _getPositionPool(
        uint256 tokenId
    ) internal view returns (address pool, address token0, address token1) {
        uint24 fee;
        (token0, token1, fee) = _getPositionTokenDetails(tokenId);
        pool = poolFactory.getPool(token0, token1, fee);
    }

    /**
     * @dev Retrieves the token amounts sorted as Arcade and Quote tokens for a given position
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @param pool The address of the Uniswap V3 pool
     * @return amountArc The amount of Arcade tokens in the position
     * @return amountQuote The amount of Quote tokens in the position
     * @return sqrtPriceX96 The square root of the current price in the pool
     */
    function _getPositionAmountsSorted(
        uint256 tokenId,
        address pool
    )
        internal
        view
        returns (uint256 amountArc, uint256 amountQuote, uint160 sqrtPriceX96)
    {
        (
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity
        ) = _getPositionLiquidityDetails(tokenId);

        sqrtPriceX96 = _getPoolSqrtRatioX96(pool);

        (uint256 amount0, uint256 amount1) = LiquidityAmounts
            .getAmountsForLiquidity(
                sqrtPriceX96,
                TickMath.getSqrtRatioAtTick(tickLower),
                TickMath.getSqrtRatioAtTick(tickUpper),
                liquidity
            );

        bool isArcToken0 = IUniswapV3Pool(pool).token0() == arcadeToken;

        amountArc = isArcToken0 ? amount0 : amount1;
        amountQuote = isArcToken0 ? amount1 : amount0;
    }

    function _validatePositionTickRange(uint256 tokenId) private view {
        (, , , , , int24 tickLower, int24 tickUpper, , , , , ) = positionManager
            .positions(tokenId);

        if (tickLower != TICK_MIN || tickUpper != TICK_MAX) {
            revert InvalidTickRange();
        }
    }

    function renounceOwnership() public view override onlyOwner {
        revert();
    }
}
BaseStakingAdapter.sol 17 lines
/// SPDX-License-Identifier: UNLICENSED

import {IStaking} from "../interfaces/IStaking.sol";

pragma solidity 0.8.28;

abstract contract BaseStakingAdapter {
    address public arcadeToken;
    IStaking public staking;

    constructor(address arcadeToken_, address staking_) {
        arcadeToken = arcadeToken_;
        staking = IStaking(staking_);
    }

    function onStakeUnlocked(uint256 stakeId) external virtual;
}
IStaking.sol 336 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.28;

/**
 * @title IStaking
 * @notice Interface for the Staking contract that provides functions for staking, claiming, and unstaking tokens.
 */
interface IStaking {
    /// @notice Enum representing the status of a stake
    enum StakeStatus {
        // should not be assigned to any stake in contract and is used for initial state checks
        UNKNOWN,
        ACTIVE,
        COMPLETED,
        EJECTED,
        UNSTAKED
    }

    /**
     * @notice Struct representing a user's stake details
     */
    struct Stake {
        uint16 nextClaimStartFromDayIndex; // Day index from which the next claim starts
        uint16 stakeEndDayIndex; // Day index when the stake ends
        StakeStatus status; // Status of the stake
        uint256 originalAmount; // Amount originally staked
        uint256 startTime; // Timestamp when the stake was created
        uint256 durationDays; // Duration of the stake in days
        int256 claimedAmount; // Amount of rewards already claimed
        int256 dlmr; // DLMR value used for calculations
        int256 ietvl; // Individual Effective Total Value Locked
    }

    /**
     * @notice Struct representing the day index details
     */
    struct StakingMetrics {
        uint32 stakeCount; // Number of user stakes
        int256 aetvl; // AETVL value
        int256 totalDlmr; // Total DLMR value
    }

    /// @notice Emitted when a user stakes tokens
    event Staked(
        address indexed user,
        uint256 indexed stakeIdx,
        uint16 nextClaimStartFromDayIndex,
        uint16 stakeEndDayIndex,
        uint256 originalAmount,
        uint256 startTime,
        uint256 durationDays,
        int256 claimedAmount,
        int256 dlmr,
        int256 ietvl
    );

    /// @notice Emitted when a user claims rewards
    event Claimed(
        address indexed user,
        uint256 indexed stakeIdx,
        uint256 indexed vestIdx,
        uint16 nextClaimStartFromDayIndex,
        uint16 stakeEndDayIndex,
        uint256 originalAmount,
        uint256 startTime,
        uint256 durationDays,
        int256 claimedAmount,
        int256 dlmr,
        int256 ietvl
    );

    /// @notice Emitted when a user unstakes their tokens
    event Unstaked(
        address indexed user,
        uint256 indexed stakeIdx,
        uint16 nextClaimStartFromDayIndex,
        uint16 stakeEndDayIndex,
        uint256 originalAmount,
        uint256 startTime,
        uint256 durationDays,
        int256 claimedAmount,
        int256 dlmr,
        int256 ietvl
    );

    /// @notice Emitted when a stake is forcibly ejected by an admin
    event Ejected(
        address indexed user,
        uint256 indexed stakeIdx,
        uint16 nextClaimStartFromDayIndex,
        uint16 stakeEndDayIndex,
        uint256 originalAmount,
        uint256 startTime,
        uint256 durationDays,
        int256 claimedAmount,
        int256 dlmr,
        int256 ietvl
    );

    /// @notice Emitted when the staker role is set
    event StakerSet(address indexed staker);

    /// @notice Emitted when the vesting address is set
    event VestingSet(address indexed vesting);

    /// @notice Emitted when the growth rate is set
    event GrowthRateSet(uint256 indexed growthRate);

    /// @notice Emitted when the leftover dust is released
    event LeftoverDustReleased(address indexed wallet, uint256 amount);

    /// @notice Error thrown when a stake is completed
    error StakeCompleted();

    /// @notice Error thrown when there is nothing to claim
    error NothingToClaim();

    /// @notice Error thrown when a stake is not completed
    error StakeNotCompleted();

    /// @notice Error thrown when the growth rate is invalid
    error InvalidGrowthRate();

    /// @notice Error thrown when the lookup time is invalid
    error InvalidLookupTime();

    /// @notice Error thrown when the AETVL for a day is zero
    error ZeroAETVLForDay();

    /// @notice Error thrown when the day indices are invalid
    error InvalidDayIndices();

    /// @notice Error thrown when the stake record is invalid
    error InvalidStakeRecord();

    /// @notice Error thrown when the stake index is invalid
    error InvalidStakeIndex();

    /// @notice Error thrown when the campaign has not started yet
    error CampaignNotStarted();

    /// @notice Error thrown when the campaign has ended
    error CampaignEndsBeforeStakeEnds();

    /// @notice Error thrown when the campaign has not ended yet
    error CampaignNotEnded();

    /// @notice Error thrown when the lockup period is invalid
    error InvalidLockupPeriod();

    /// @notice Error thrown when the stake status is invalid for claiming
    error InvalidStatus(StakeStatus currentStatus, StakeStatus requiredStatus);

    /// @notice Error thrown when the stake owner is invalid
    error InvalidStakeOwner();

    /// @notice Error thrown when the stake is late to eject
    error LateToEject();

    // GETTERS FOR PUBLIC STATE VARIABLES

    /**
     * @notice Returns the campaign start time
     * @return The campaign start time in timestamp
     */
    function campaignStartTime() external view returns (uint256);

    /**
     * @notice Returns the growth rate constant
     * @return The growth rate value
     */
    function growthRate_k() external view returns (uint256);

    /**
     * @notice Returns the address of the vesting contract
     * @return The vesting contract address
     */
    function vesting() external view returns (address);

    /**
     * @notice Returns the DEFAULT_STAKER_ROLE
     * @return The DEFAULT_STAKER_ROLE
     */
    function DEFAULT_STAKER_ROLE() external view returns (bytes32);

    /**
     * @notice Returns the current stake index
     * @return The current stake index
     */
    function currentStakeIdx() external view returns (uint256);

    /**
     * @notice Returns the user address for a given stake index
     * @param stakeIdx The index of the stake
     * @return The user address
     */
    function stakeToUser(uint256 stakeIdx) external view returns (address);

    /**
     * @notice Returns the staking adapter address for a user and stake index
     * @param stakeIdx The index of the stake
     * @return The staking adapter address
     */
    function stakeAdapters(uint256 stakeIdx) external view returns (address);

    /**
     * @notice Retrieves the AETVL value for a specific day index.
     * @param dayIndex The index of the day to retrieve the AETVL value for.
     * @return aetvl The AETVL value for the day index.
     */
    function getDailyAetvl(
        uint16 dayIndex
    ) external view returns (int256 aetvl);

    /**
     * @notice Calculates the claimable amount for a specific stake.
     * @param stakeIdx The index of the stake.
     * @return claimableAmount The amount that can be claimed.
     */
    function getClaimableAmount(
        uint256 stakeIdx
    ) external returns (int256 claimableAmount);

    /**
     * @notice Grants the DEFAULT_STAKER_ROLE to a staker address.
     * @dev Callable only by accounts with DEFAULT_ADMIN_ROLE.
     * @param staker The address to be granted the staker role.
     */
    function setStaker(address staker) external;

    /**
     * @notice Releases leftover dust after the campaign ends.
     * @dev Callable only by accounts with DEFAULT_ADMIN_ROLE after the campaign ends.
     * @param wallet The address of the wallet to release the dust to.
     */
    function releaseLeftoverDust(address wallet) external;

    /**
     * @notice Sets the vesting contract address.
     * @dev Callable only by accounts with DEFAULT_ADMIN_ROLE.
     * @param vesting_ The address of the vesting contract.
     */
    function setVesting(address vesting_) external;

    /**
     * @notice Sets the growth rate constant used in DLMR calculation.
     * @dev Callable only by accounts with DEFAULT_ADMIN_ROLE.
     * @param newGrowthRate The new growth rate value (should be between 0.001 and 0.01 with 18 decimals precision).
     */
    function setGrowthRate(uint256 newGrowthRate) external;

    /**
     * @notice Allows a user to stake a certain amount for a specified duration.
     * @dev Callable only by accounts with DEFAULT_STAKER_ROLE.
     * @param user The address of the user who is staking.
     * @param amount The amount to stake.
     * @param duration The duration of the stake in days.
     * @param adapter The address of the staking adapter.
     * @return stakeIndex The index of the created stake.
     * @return ietvl The Individual Effective Total Value Locked (IETVL) value.
     * @return dlmr The Dynamic Linear Multiplier Rate (DLMR) value.
     */
    function stake(
        address user,
        uint256 amount,
        uint256 duration,
        address adapter
    ) external returns (uint256 stakeIndex, int256 ietvl, int256 dlmr);

    /**
     * @notice Allows a user to claim their staking rewards.
     * @param stakeIdx The index of the stake to claim from.
     * @return claimedAmount The total amount claimed.
     */
    function claim(uint256 stakeIdx) external returns (int256 claimedAmount);

    /**
     * @notice Allows a user to claim rewards for multiple stakes.
     * @param stakeIndexes An array of stake indices to claim rewards from.
     */
    function bulkClaim(uint256[] calldata stakeIndexes) external;

    /**
     * @notice Allows a user to unstake after the stake has been completed.
     * @param stakeIdx The index of the stake to unstake.
     */
    function unstake(uint256 stakeIdx) external;

    /**
     * @notice Allows a user to unstake multiple stakes.
     * @param stakeIndexes An array of stake indices to unstake.
     */
    function bulkUnstake(uint256[] calldata stakeIndexes) external;

    /**
     * @notice Allows an admin to eject a user's stake.
     * @dev Callable only by accounts with DEFAULT_ADMIN_ROLE.
     * @param user The address of the user.
     * @param stakeIdx The index of the stake to eject.
     * @param confiscationWallet The address of the confiscation wallet.
     * @param instantRelease Whether to instantly release the stake.
     */
    function ejectStake(
        address user,
        uint256 stakeIdx,
        address confiscationWallet,
        bool instantRelease
    ) external;

    /**
     * @notice Returns the list of all stake indices for a user.
     * @param user The address of the user.
     * @return stakeIndices An array of stake indices associated with the user.
     */
    function getUserStakeIndices(
        address user
    ) external view returns (uint256[] memory stakeIndices);

    /**
     * @notice Retrieves the stake information for a given stake index.
     * @param stakeIndex The index of the stake.
     * @return stakeRecord The Stake struct containing stake information.
     */
    function getStakeDetails(
        uint256 stakeIndex
    ) external view returns (Stake memory stakeRecord);

    /**
     * @notice Calculates the day index based on a given timestamp.
     * @param lookupTime The timestamp to calculate the day index from.
     * @return dayIndex The day index corresponding to the given timestamp.
     */
    function getDayIndex(
        uint256 lookupTime
    ) external view returns (uint16 dayIndex);
}
IUniswapStakingAdapter.sol 107 lines
/// SPDX-License-Identifier: UNLICENSED

pragma solidity 0.8.28;

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

interface IUniswapStakingAdapter {
    /// @notice Error thrown when an invalid pool is used for staking
    error InvalidPool();

    /// @notice Error thrown when a function is called by a non-staking contract
    error OnlyStakingContract();

    /// @notice Error thrown when the tick range of a position is invalid
    error InvalidTickRange();

    /// @notice Emitted when liquidity pool allowance is changed
    /// @param pool The address of the pool
    /// @param status The new allowance status (true/false)
    event LiquidityPoolAllowed(address indexed pool, bool status);

    /// @notice Emitted when a stake is unlocked
    /// @param stakeId The ID of the stake
    /// @param tokenId The ID of the Uniswap V3 NFT representing liquidity
    /// @param owner The address of the owner of the stake
    /// @param amountStaked The amount of ARC tokens staked
    /// @param pool The address of the pool
    event StakeUnlocked(
        uint256 indexed stakeId,
        uint256 indexed tokenId,
        address indexed owner,
        uint256 amountStaked,
        address pool
    );

    /**
     * @notice Sets the allowance status for a Uniswap V3 liquidity pool
     * @param pool The address of the pool
     * @param status The new allowance status (true/false)
     */
    function setLiquidityPoolAllowed(address pool, bool status) external;

    /**
     * @notice Gets the allowance status for a Uniswap V3 liquidity pool
     * @param pool The address of the pool
     * @return The allowance status (true/false)
     */
    function poolAllowed(address pool) external view returns (bool);

    /**
     * @notice Gets the token ID for a stake
     * @param stakeIdx The index of the stake
     * @return The token ID
     */
    function stakeIdxToTokenId(
        uint256 stakeIdx
    ) external view returns (uint256);

    /**
     * @notice Gets the pool address for a stake
     * @param stakeIdx The index of the stake
     * @return The address of the pool
     */
    function stakeIdxToPool(uint256 stakeIdx) external view returns (address);

    /**
     * @notice Gets the total ARC token value locked in a liquidity position
     * @param pool The address of the pool
     * @return The total ARC token value locked
     */
    function totalStakedByPool(address pool) external view returns (uint256);

    /**
     * @notice Handles the unlocking of a stake, releasing the Uniswap position
     * @param stakeId The ID of the stake
     */
    function onStakeUnlocked(uint256 stakeId) external;

    /**
     * @notice Stakes a Uniswap position and locks it into the contract
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @param stakeDurationDays The lockup period for the stake in days
     */
    function stakeWithUniswapPosition(
        uint256 tokenId,
        uint256 stakeDurationDays
    ) external returns (uint256 stakeIdx, int256 ietvl, int256 dlmr);

    /**
     * @notice Gets the total value locked in Arcade tokens for a given Uniswap position
     * @param tokenId The ID of the Uniswap V3 NFT representing liquidity
     * @param pool The address of the Uniswap V3 pool
     * @return The total value locked in Arcade tokens
     */
    function getLockedValueInArcadeTokens(
        uint256 tokenId,
        address pool
    ) external view returns (uint256);

    /**
     * @param pool The address of the Uniswap V3 pool
     * @return The staking metrics for the pool
     */
    function getPoolStakingMetrics(
        address pool
    ) external view returns (IStaking.StakingMetrics memory);
}

Read Contract

TICK_MAX 0x73567ec6 → int256
TICK_MIN 0x2bd7667d → int256
arcadeToken 0xe533da32 → address
getLockedValueInArcadeTokens 0xd145e200 → uint256
getPoolStakingMetrics 0x51f7653e → tuple
onERC721Received 0x150b7a02 → bytes4
owner 0x8da5cb5b → address
pendingOwner 0xe30c3978 → address
poolAllowed 0x4ceccf0c → bool
poolFactory 0x4219dc40 → address
poolStakingMetrics 0xde8a28c7 → uint32, int256, int256
positionManager 0x791b98bc → address
renounceOwnership 0x715018a6
stakeIdxToAmountStaked 0xd1503ba1 → uint256
stakeIdxToPool 0x3405aa86 → address
stakeIdxToTokenId 0x848bdb54 → uint256
staking 0x4cf088d9 → address
totalStakedByPool 0x57a4b9fe → uint256

Write Contract 5 functions

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

acceptOwnership 0x79ba5097
No parameters
onStakeUnlocked 0x7ee28b6b
uint256 stakeId
setLiquidityPoolAllowed 0x87b7c5ef
address pool
bool status
stakeWithUniswapPosition 0x1e8735c2
uint256 tokenId
uint256 stakeDurationDays
returns: uint256, int256, int256
transferOwnership 0xf2fde38b
address newOwner

Recent Transactions

No transactions found for this address