Address Contract Verified
Address
0x02A49B18F4681547618FeA6f717f86DCBCe0C3BC
Balance
0 ETH
Nonce
1
Code Size
9175 bytes
Creator
0x89E89C39...7eb3 at tx 0xbf6f64cf...47cd39
Indexed Transactions
0
Contract Bytecode
9175 bytes
0x60806040526004361015610011575f80fd5b5f3560e01c806311d6bf3c146112f557806324889f42146112b55780632bad2ea61461129857806333a7944a1461127b57806337381f421461121f57806337e9f64a146112025780633a98ef39146111e55780633bb959ce14611193578063417d020b146111765780634e71d92d1461114d57806350e7dc3d14611118578063569c93d2146110f05780635fe6b010146110b5578063632447c91461109257806363d38c3b146110755780636806cc93146110325780636dff4ac41461100f5780636eb854c814610d90578063715018a614610d355780637695caa214610d1d578063799e16e214610cf55780637b0a47ee14610cd85780638da5cb5b14610cb05780638eafaea514610c8d57806395a573bd14610c70578063a1a524cd14610c4e578063a757db4a14610c26578063aaf5eb6814610c04578063b5c2204a14610bdc578063c0ed00c914610ae5578063c891091314610a55578063c8f33c9114610a38578063d1bc34c414610a16578063dbc99b2e146109f0578063dd333f0414610818578063ddeae033146107bb578063e9125ee21461079e578063eac5fe3c1461073c578063f2fde38b14610674578063f4ee301114610572578063f520e7e514610555578063f73b07141461052d578063f7c618c1146104e9578063f8e05b01146104c4578063faf1e0911461046e5763ffdd5cf114610213575f80fd5b3461041b57602036600319011261041b5761022c61134c565b5f61010060405161023c816113d2565b8281528260208201528260408201528260608201528260808201528260a08201528260c08201528260e082015201526024604060018060a01b03600254168151928380926367a5b10b60e01b825260018060a01b03871660048301525afa8015610427575f915f91610432575b506103299060018060a01b0384165f52601460205260405f20926008604051946102d2866113d2565b8054865260018101546020870152600281015460408701526003810154606087015260048101546080870152600581015460a0870152600681015460c0870152600781015460e087015201546101008501526113c5565b6101008201526003546040516370a0823160e01b81526001600160a01b038481166004830152909160209183916024918391165afa908115610427575f916103ef575b506101209261037f9160e0840152611841565b606082015260095460a082015260075460c082015261010060405191805183526020810151602084015260408101516040840152606081015160608401526080810151608084015260a081015160a084015260c081015160c084015260e081015160e08401520151610100820152f35b90506020813d60201161041f575b8161040a60209383611433565b8101031261041b575161012061036c565b5f80fd5b3d91506103fd565b6040513d5f823e3d90fd5b9150506040813d604011610466575b8161044e60409383611433565b8101031261041b5761032960208251920151906102a9565b3d9150610441565b3461041b57604036600319011261041b5761048761134c565b6024359081151580920361041b57335f52601360205260405f209060018060a01b03165f5260205260405f209060ff801983541691161790555f80f35b3461041b575f36600319011261041b57602060ff60115460a01c166040519015158152f35b3461041b575f36600319011261041b576040517f0000000000000000000000000655977feb2f289a4ab78af67bab0d17aab843676001600160a01b03168152602090f35b3461041b575f36600319011261041b576003546040516001600160a01b039091168152602090f35b3461041b575f36600319011261041b576020600c54604051908152f35b3461041b57602036600319011261041b5760043561058e611b64565b6224ea00811161062357620151808111156105d4576020817fe61ade5f056d1166fbfb6a8e800a708b29a307c5a96e1c39dfce660e61c70d0b92600d55604051908152a1005b60405162461bcd60e51b815260206004820152602160248201527f7265776172645265667265736854696d65206d757374206265203e20312064616044820152607960f81b6064820152608490fd5b60405162461bcd60e51b8152602060048201526024808201527f7265776172645265667265736854696d65206d757374206265203c3d2034207760448201526365656b7360e01b6064820152608490fd5b3461041b57602036600319011261041b5761068d61134c565b610695611b64565b6001600160a01b039081169081156106e857600154826bffffffffffffffffffffffff60a01b821617600155167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3005b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b3461041b57602036600319011261041b57602061079261075a61134c565b610762611bbc565b6001600160a01b0381165f908152601384526040808220338352855290205461078d9060ff16611b21565b611c10565b60015f55604051908152f35b3461041b575f36600319011261041b576020600554604051908152f35b3461041b57602036600319011261041b5760206107926107d961134c565b6107e1611bbc565b6001600160a01b0381165f908152601384526040808220338352855290205461080c9060ff16611b21565b60ff600f541690611e0e565b3461041b57606036600319011261041b5761083161134c565b610839611362565b906044359081159182150361041b57610850611b64565b6040516370a0823160e01b81523060048201526001600160a01b03918216916020918281602481875afa908115610427575f916109c3575b5093817f0000000000000000000000000655977feb2f289a4ab78af67bab0d17aab843671684146108ef575b50846108e4858596977ff24ef89f38eadc1bde50701ad6e4d6d11a2dc24f7cf834a486991f3883328504966121b6565b6040519586521693a3005b6108f7611991565b610961575b7ff24ef89f38eadc1bde50701ad6e4d6d11a2dc24f7cf834a486991f388332850492939442600a5542600b555f6010555f6009557f41963082c8470994f8de6381945365c741f1a2aaf96b683c18c863323e7bdc6a836040515f8152a19493926108b4565b925060105492600b54804210610978575b506108fc565b7ff24ef89f38eadc1bde50701ad6e4d6d11a2dc24f7cf834a486991f388332850493946109b66109bc926109b060095491429061139a565b90611387565b906113c5565b9392610972565b90508281813d83116109e9575b6109da8183611433565b8101031261041b575186610888565b503d6109d0565b3461041b57602036600319011261041b576020610a0e600435611aa9565b604051908152f35b3461041b575f36600319011261041b57610a2e611b64565b610a36611a22565b005b3461041b575f36600319011261041b576020600a54604051908152f35b3461041b57602036600319011261041b576001600160a01b03610a7661134c565b165f52601460205261012060405f208054906001810154906002810154600382015460048301546005840154916006850154936008600787015496015496604051988952602089015260408801526060870152608086015260a085015260c084015260e0830152610100820152f35b3461041b57602036600319011261041b57600435610b01611b64565b6224ea008111610b8c5762015180811115610b47576020817ffeece2f615b2fecca6c26deadea49416a6ba6b52b2cd2613065fd6a787cf124092600c55604051908152a1005b60405162461bcd60e51b815260206004820152601f60248201527f526577617264206475726174696f6e206d757374206265203e203120646179006044820152606490fd5b60405162461bcd60e51b815260206004820152602260248201527f526577617264206475726174696f6e206d757374206265203c3d2034207765656044820152616b7360f01b6064820152608490fd5b3461041b575f36600319011261041b576002546040516001600160a01b039091168152602090f35b3461041b575f36600319011261041b576020604051670de0b6b3a76400008152f35b3461041b575f36600319011261041b576011546040516001600160a01b039091168152602090f35b3461041b575f36600319011261041b57602060ff600f54166040519015158152f35b3461041b575f36600319011261041b576020600854604051908152f35b3461041b575f36600319011261041b57610ca5611bbc565b602061079233611c10565b3461041b575f36600319011261041b576001546040516001600160a01b039091168152602090f35b3461041b575f36600319011261041b576020600954604051908152f35b3461041b575f36600319011261041b576012546040516001600160a01b039091168152602090f35b3461041b575f36600319011261041b57610a36611991565b3461041b575f36600319011261041b57610d4d611b64565b600180546001600160a01b031981169091555f906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b3461041b5760208060031936011261041b576001600160a01b039081610db461134c565b1691825f526014825260405f2092604051610dce816113d2565b845492838252600186015491858101928352610100600860028901549860408401998a526003810154606085015260048101546080850152600581015460a0850152600681015460c0850152600781015460e08501520154910152806002541692604051908682602481630fa806cd60e21b988982528560048301525afa9586156104275787925f97610fda575b50610e74602491610e6f896005546113c5565b61139a565b94519360035416956040519687938492835260048301525afa928315610427575f93610fa9575b50610eac90610e6f846006546113c5565b9267058d15e176280000948584029584159085880414811715610f8257670de0b6b3a76400008097049684159182159081610f9f575b81610f96575b50610f23575b5050610f0360c09751610e6f886007546113c5565b9060405196875286015260408501526060840152608083015260a0820152f35b909796610f308488611387565b98670853a0d2313c0000998a81029a818c041490151715610f825782860292868404141715610f82576109b6610f689260c09a6113a7565b95868510610f78575b9688610eee565b9395508593610f71565b634e487b7160e01b5f52601160045260245ffd5b9050158a610ee8565b8515159150610ee2565b9092508481813d8311610fd3575b610fc18183611433565b8101031261041b575191610eac610e9b565b503d610fb7565b8381949298503d8311611008575b610ff28183611433565b8101031261041b57905194869190610e74610e5c565b503d610fe8565b3461041b57602036600319011261041b576020610a0e61102d61134c565b611841565b3461041b57602036600319011261041b5761104b61134c565b611053611b64565b600480546001600160a01b0319166001600160a01b0392909216919091179055005b3461041b575f36600319011261041b576020601054604051908152f35b3461041b57602036600319011261041b576020610a0e6110b061134c565b611455565b3461041b57604036600319011261041b576001600160a01b036110d661134c565b165f5260146020526020600260405f200154604051908152f35b3461041b575f36600319011261041b576004546040516001600160a01b039091168152602090f35b3461041b57602036600319011261041b57611131611378565b611139611b64565b60ff8019600f54169115151617600f555f80f35b3461041b575f36600319011261041b57611165611bbc565b602061079260ff600f541633611e0e565b3461041b575f36600319011261041b576020600e54604051908152f35b3461041b57604036600319011261041b576111ac61134c565b6111b4611362565b9060018060a01b038091165f52601360205260405f2091165f52602052602060ff60405f2054166040519015158152f35b3461041b575f36600319011261041b576020600754604051908152f35b3461041b575f36600319011261041b576020600b54604051908152f35b3461041b57602036600319011261041b57600954610e1090818102918183041481151715610f82576201518081029180830460181490151715610f825762093a80029080820460071490151715610f8257602090604051908152f35b3461041b575f36600319011261041b576020600d54604051908152f35b3461041b575f36600319011261041b576020600654604051908152f35b3461041b57602036600319011261041b576112ce611378565b6112d6611b64565b6011805460ff60a01b191691151560a01b60ff60a01b16919091179055005b3461041b57604036600319011261041b5761130e61134c565b611316611362565b61131e611b64565b600280546001600160a01b039384166001600160a01b03199182161790915560038054929093169116179055005b600435906001600160a01b038216820361041b57565b602435906001600160a01b038216820361041b57565b60043590811515820361041b57565b81810292918115918404141715610f8257565b91908203918211610f8257565b81156113b1570490565b634e487b7160e01b5f52601260045260245ffd5b91908201809211610f8257565b610120810190811067ffffffffffffffff8211176113ef57604052565b634e487b7160e01b5f52604160045260245ffd5b67ffffffffffffffff81116113ef57604052565b6040810190811067ffffffffffffffff8211176113ef57604052565b90601f8019910116810190811067ffffffffffffffff8211176113ef57604052565b61145d611991565b60018060a01b03809116805f52602060148152604091825f2090600282019182548061180b575b508054908660025416918651630fa806cd60e21b9182825287826024816004988a8a8301525afa918215611801575f926117d0575b50610e6f826114cc9386556005546113c5565b600555600182019786895491600354169260248a5180958193825289898301525afa9182156117c6575f92611795575b50610e6f8261150f938b556006546113c5565b96876006555467058d15e17628000097888202821599838204148a171561175b57670de0b6b3a764000080910499600554928315918215908161178a575b81611781575b506116dd575b50505050507f4b213b4d8a9d0d5f135a8e3036f787f6cba5893b07dd703819c88d0e64afd21e918691855491896007549761159885610e6f848c6113c5565b6007555560085491015581519081528786820152a21580806116d2575b806116c7575b156116495750507f0ed8cb1ba8161c9828dd61bbaca976d84a455aaa4c036de1fa9c95f9b70375219042600a556010545f601055611643600c549261160084846113a7565b8060095561160e85426113c5565b9182600b5561161f600d54426113c5565b600e5551948594859094939260609260808301968352602083015260408201520152565b0390a190565b15806116bd575b61165957505090565b7f41963082c8470994f8de6381945365c741f1a2aaf96b683c18c863323e7bdc6a91600b54804210611697575b506010549051908152a15f60095590565b6116ac6116b4916109b060095491429061139a565b6010546113c5565b6010555f611686565b5060075415611650565b5060105415156115bb565b5060075415156115b5565b8554949b946116eb91611387565b91670853a0d2313c00009283810293818504149015171561176e5780840293840414171561175b5761172192916109b6916113a7565b96878110611733575b80808080611559565b96507f4b213b4d8a9d0d5f135a8e3036f787f6cba5893b07dd703819c88d0e64afd21e61172a565b601185634e487b7160e01b5f525260245ffd5b601187634e487b7160e01b5f525260245ffd5b9050155f611553565b87541515915061154d565b91508682813d83116117bf575b6117ac8183611433565b8101031261041b57905190610e6f6114fc565b503d6117a2565b88513d5f823e3d90fd5b91508782813d83116117fa575b6117e78183611433565b8101031261041b57905190610e6f6114b9565b503d6117dd565b89513d5f823e3d90fd5b611829670de0b6b3a7640000916109b060085460048601549061139a565b04611839600383019182546113c5565b90555f611484565b60018060a01b03165f52601460205260405f20604051611860816113d2565b815481526001820154602082015260028201546040820190815260038301549160608101928352610100600860048601549560808401968752600581015460a0850152600681015460c0850152600781015460e085015201549101525f90600b548042105f1461198c5750425b600a5490818111611979575b505060085491600754908161191d575b505061190d61191a946109b06119159594670de0b6b3a7640000945192519061139a565b0490516113c5565b611aa9565b90565b61192e906009959492939554611387565b94670de0b6b3a764000095868102968188041490151715610f82576109b06119159561196d61190d946109b6670de0b6b3a76400009761191a9b6113a7565b959650935050946118e9565b61198492935061139a565b905f806118d9565b6118cd565b600b5442811015611a1b575b600a54811115611a1257600a546119b39161139a565b60075490816119cd575b505042600a556119cb611fb0565b565b6119d990600954611387565b670de0b6b3a764000090818102918183041490151715610f8257611a0891611a00916113a7565b6008546113c5565b6008555f806119bd565b506119cb611fb0565b504261199d565b600b5442811015611aa2575b600a54811115611a9957600a54611a449161139a565b6007549081611a5c575b505042600a556119cb612180565b611a6890600954611387565b670de0b6b3a764000090818102918183041490151715610f8257611a8f91611a00916113a7565b6008555f80611a4e565b506119cb612180565b5042611a2e565b60ff600f54161561191a5760115460405163266d6a8360e11b81526004810192909252602090829060249082906001600160a01b03165afa908115610427575f91611af2575090565b90506020813d602011611b19575b81611b0d60209383611433565b8101031261041b575190565b3d9150611b00565b15611b2857565b60405162461bcd60e51b815260206004820152601460248201527318db185a5b595c881b9bdd08185c1c1c9bdd995960621b6044820152606490fd5b6001546001600160a01b03163303611b7857565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b60025f5414611bcb5760025f55565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b5f9060ff60115460a01c165f14611dff576012546001600160a01b0390811690813b1561041b575f916044839260405194859384926361c979a160e11b8452881660048401523060248401525af1801561042757611dec575b505b6001600160a01b03908116808352601460209081526040808520600301805495929492908615611de257819055808015611da05750808584601154166064855180948193635d043b2960e11b83528c60048401523360248401523060448401525af18015611d9657908691611d6d575b506024936011541683519485809263266d6a8360e11b82528a60048301525afa908115611d625790611d28575b5f8051602061238283398151915292505b8151948686528501523393a390565b508382813d8311611d5b575b611d3e8183611433565b8101031261041b575f805160206123828339815191529151611d08565b503d611d34565b8251903d90823e3d90fd5b813d8311611d8f575b611d808183611433565b8101031261041b57845f611cdb565b503d611d76565b83513d84823e3d90fd5b90505f805160206123828339815191529250611ddd86337f0000000000000000000000000655977feb2f289a4ab78af67bab0d17aab843676121b6565b611d19565b5094505050505090565b611df7919250611403565b5f905f611c69565b611e0881611455565b50611c6b565b5f9060ff60115460a01c165f14611f3e576012546001600160a01b0390811690813b1561041b575f916044839260405194859384926361c979a160e11b8452881660048401523060248401525af1801561042757611f2b575b505b60018060a01b0380911690818352602092601484526040906003828220018054968715611f2057828092555f14611da05750808584601154166064855180948193635d043b2960e11b83528c60048401523360248401523060448401525af18015611d9657908691611d6d57506024936011541683519485809263266d6a8360e11b82528a60048301525afa908115611d625790611d28575f8051602061238283398151915292508151948686528501523393a390565b505094505050505090565b611f36919250611403565b5f905f611e67565b611f4781611455565b50611e69565b3d15611f87573d9067ffffffffffffffff82116113ef5760405191611f7c601f8201601f191660200184611433565b82523d5f602084013e565b606090565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b6004546001600160a01b0316801561214457600e5442106120ff575f80809260405182602082019163ae5c935760e01b835260048152611fef81611417565b51925af190611ffc611f4d565b9115612102575060208180518101031261041b57602001515b80156120ff576007546120425761202e906010546113c5565b60105561203d600d54426113c5565b600e55565b61207c7f0ed8cb1ba8161c9828dd61bbaca976d84a455aaa4c036de1fa9c95f9b703752191600b548042106120de575b50601054906113c5565b5f60105561208c600d54426113c5565b600e55600c54906120d96120a083426113c5565b80600b556120ae84846113a7565b8060095542600a55604051948594859094939260609260808301968352602083015260408201520152565b0390a1565b906109b66120f06120f993429061139a565b60095490611387565b5f612072565b50565b9061213c7f435f9fbce15d6120b90d7f20ee78f8f0bee1a717bbe1f226ff7a29ae1e8b271f91604051918291602083526020830190611f8c565b0390a1612015565b60405162461bcd60e51b81526020600482015260146024820152731c995dd85c99121bdb19195c881b9bdd081cd95d60621b6044820152606490fd5b6004546001600160a01b03168015612144575f80809260405182602082019163ae5c935760e01b835260048152611fef81611417565b60405163a9059cbb60e01b602082019081526001600160a01b0393841660248301526044808301959095529381526080810192909167ffffffffffffffff8411838510176113ef57612253945f92839286604052169361221586611417565b602086527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656460a0820152519082855af161224d611f4d565b916122e4565b80519081159182156122c1575b50501561226957565b60405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608490fd5b819250906020918101031261041b5760200151801515810361041b575f80612260565b9192901561234657508151156122f8575090565b3b156123015790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156123595750805190602001fd5b60405162461bcd60e51b81526020600482015290819061237d906024830190611f8c565b0390fdfe7a84a08b02c91f3c62d572853f966fc799bbd121e8ad7833a4494ab8dcfcb404a264697066735822122078fdfa1fc626e480a5608f3a9751f65a4f8c5d5759e9d5b0f72186b2edd98db464736f6c63430008190033
Verified Source Code Full Match
Compiler: v0.8.25+commit.b61c2a91
EVM: cancun
Optimization: Yes (200 runs)
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. 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 {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Math.sol 339 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
Rewarder.sol 533 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import "@openzeppelin/contracts/utils/math/Math.sol";
import "./interfaces/IBoostedStaking.sol";
import "./interfaces/IRewardHolder.sol";
import "./interfaces/ITiltStaking.sol";
import "./interfaces/ITiltCore.sol";
import './interfaces/IDeposit.sol';
/**
* @title Rewarder
* @notice This contract accepts checkpoint updates from users when their Tilt or boosted stake changes.
*
* For Tilt:
* - tiltWeight = tiltStake * (lockWeeks / MAX_LOCK_WEEKS)
*
* For boosted:
* - boostedWeight = boostedStake * boost, where boost = 1 + (min(elapsed, FULL_BOOST_WEEKS) / FULL_BOOST_WEEKS) * 1.5
*
* A user's reward shares are computed as:
* userShares = 0.4 * boostedWeight + 0.6 * boostedWeightTotal * (tiltWeight / tiltWeightTotal)
*
* Global totals (tiltWeightTotal, boostedWeightTotal, totalShares) are updated on each checkpoint.
* Rewards are streamed over a period of time using a reward rate.
*
* This contract retrieves new rewards by calling rewardHolder.requestRewards().
*/
contract Rewarder is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
/// @notice Scaling factor for fixed point math.
uint256 public constant PRECISION = 1e18;
/// @notice ERC20 token used for rewards.
IERC20 public immutable rewardToken;
/// @notice Tilt staking contract.
ITiltStaking public tiltStaking;
/// @notice boosted staking contract.
IBoostedStaking public boostedStaking;
/// @notice reward holder contract to request rewards.
IRewardHolder public rewardHolder;
// Global aggregates.
/// @notice Total adjusted Tilt weight across all users.
uint256 public tiltWeightTotal;
/// @notice Total adjusted boosted weight across all users.
uint256 public boostedWeightTotal;
/// @notice Total reward shares across all users.
uint256 public totalShares;
// Reward distribution accumulator.
/// @notice Global accumulated reward per share (scaled by PRECISION).
uint256 public globalRewardPerShare;
// Streaming reward variables.
/// @notice Reward rate (tokens per second) for streaming rewards.
uint256 public rewardRate;
/// @notice Last timestamp when globalRewardPerShare was updated.
uint256 public lastUpdateTime;
/// @notice Timestamp when the current reward stream ends.
uint256 public rewardEndTime;
/// @notice Duration over which new rewards are distributed.
uint256 public rewardDuration = 2 weeks;
/// @notice Time to wait before rewards can be retrieved
uint256 public rewardRefreshTime = 1 weeks;
/// @notice Next timestamp when rewards can be retrieved
uint256 public nextRewardRetrieval;
/// @notice determines whether or not to allow unwrapping of rewards
bool public unwrappingEnabled = true;
/// @notice holds rewards that can not be issued immediately
uint256 public queuedRewards;
/// @notice wrapper token for rewards
IDeposit public wrappedReward;
/// @notice trigger peer updates on claim
bool public batchUpdateOnClaim = true;
/// @notice TiltCore contract to handle updating multiple users
ITiltCore public tiltCore;
/// @notice maps users to their approved reward claimers
mapping(address owner => mapping(address claimer => bool approved)) public approvedClaimer;
/// @notice User-specific reward and staking data.
struct UserData {
uint256 tiltWeight; // Accepted Tilt-adjusted balance.
uint256 boostedWeight; // Accepted adjusted balance.
uint256 shares; // Accepted reward shares.
uint256 pendingReward; // Accrued but unclaimed reward.
uint256 lastGlobalRewardPerShare; // Last recorded globalRewardPerShare for reward accrual.
uint256 rewardsPerSecond; // Amount of rewards issued every second (for APR calculation)
uint256 totalShares; // Amount of rewards issued every second (for APR calculation)
uint256 boostedStake; // Amount of boosted Staked
uint256 tiltStaked; // Amount of tilt Staked
}
/// @notice Mapping of user addresses to their reward data.
mapping(address => UserData) public userData;
event RewardUpdated(address indexed user, uint256 oldShares, uint256 newShares);
event RewardsAdded(uint256 amount, uint256 duration, uint256 newRewardRate, uint256 rewardEndTime);
event RewardClaimed(address indexed user, address indexed claimer, uint256 wrappedReward, uint256 reward);
event EmergencyWithdraw(address indexed token, address indexed to, uint256 amount);
event RewardsPaused(uint256 queuedAmount);
event RewardRefreshTimeUpdated(uint256 time);
event RewardRequestFailed(bytes returnData);
event RewardDurationUpdated(uint256 time);
/**
* @notice Constructor sets the reward token.
* @param _rewardToken Address of the ERC20 reward token.
* @param _rewardHolder Address which holds rewards before distribution.
*/
constructor(ITiltCore _tiltCore, IERC20 _rewardToken, IRewardHolder _rewardHolder) {
wrappedReward = IDeposit(address(_rewardToken));
rewardHolder = _rewardHolder;
rewardToken = _rewardToken;
tiltCore = _tiltCore;
}
/**
* @notice Sets the reward holder contract.
* @param _rewardHolder Address of the reward holder contract.
*/
function setRewardHolder(address _rewardHolder) external onlyOwner {
rewardHolder = IRewardHolder(_rewardHolder);
}
/**
* @notice Sets batch update on claim
* @param _enabled bool
*/
function setBatchUpdateOnClaim(bool _enabled) external onlyOwner {
batchUpdateOnClaim = _enabled;
}
/**
* @notice Updates the global reward accumulator based on elapsed time.
*/
function updateGlobalReward() public {
uint256 applicableTime = Math.min(rewardEndTime, block.timestamp);
if (applicableTime <= lastUpdateTime)
return _retrieveNewRewards(false);
uint256 elapsed = applicableTime - lastUpdateTime;
if (totalShares > 0)
globalRewardPerShare += (rewardRate * elapsed * PRECISION) / totalShares;
lastUpdateTime = block.timestamp;
_retrieveNewRewards(false);
}
/**
* @notice Force updates the global reward accumulator.
* Doesn't depend on being past the nextRewardRetrieval
*
* @dev only callable by owner
*/
function forceUpdateGlobalReward() public onlyOwner {
uint256 applicableTime = Math.min(rewardEndTime, block.timestamp);
if (applicableTime <= lastUpdateTime)
return _retrieveNewRewards(true);
uint256 elapsed = applicableTime - lastUpdateTime;
if (totalShares > 0)
globalRewardPerShare += (rewardRate * elapsed * PRECISION) / totalShares;
lastUpdateTime = block.timestamp;
_retrieveNewRewards(true);
}
/**
* @notice Updates a user's reward state by recalculating their reward shares.
*
* It performs the following steps:
* 1. Updates the global reward accumulator.
* 2. Accrues pending rewards based on previous shares.
* 3. Updates the user's Tilt weight from TiltStaking and adjusts tiltWeightTotal.
* 4. Updates the user's boosted weight from boostedStaking and adjusts boostedWeightTotal.
* 5. Computes new reward shares as:
* userShares = 0.4 * boostedWeight + 0.6 * boostedWeightTotal * (tiltWeight / tiltWeightTotal)
* 6. Adjusts global totalShares and updates the user's reward debt.
*
* @param user Address of the user.
*/
function updateReward(address user) public returns (uint256) {
// Update global reward accumulator to include streamed rewards.
updateGlobalReward();
UserData storage account = userData[user];
// Accrue pending rewards from previous shares.
if (account.shares > 0) {
uint256 accrued = (account.shares * (globalRewardPerShare - account.lastGlobalRewardPerShare)) / PRECISION;
account.pendingReward += accrued;
}
// --- Update Tilt weight ---
uint256 oldTiltWeight = account.tiltWeight;
account.tiltWeight = tiltStaking.getAccountWeight(user);
tiltWeightTotal = tiltWeightTotal + account.tiltWeight - oldTiltWeight;
// --- Update boosted weight ---
uint256 oldBoostedWeight = account.boostedWeight;
account.boostedWeight = boostedStaking.getAccountWeight(user);
boostedWeightTotal = boostedWeightTotal + account.boostedWeight - oldBoostedWeight;
// --- Compute user's new reward shares ---
uint256 newShares = (account.boostedWeight * 4e17) / PRECISION; // 0.4 * boosted weight
if (tiltWeightTotal > 0 && account.tiltWeight > 0 && account.boostedWeight > 0) {
// Compute 0.6 * boostedWeightTotal * (newTiltWeight / tiltWeightTotal)
newShares += (boostedWeightTotal * account.tiltWeight * 6e17) / (tiltWeightTotal * PRECISION);
if (account.boostedWeight < newShares)
newShares = account.boostedWeight;
}
// Adjust global totalShares.
uint256 oldShares = account.shares;
uint256 totalSharesWas = totalShares;
totalShares = totalShares + newShares - oldShares;
account.shares = newShares;
account.lastGlobalRewardPerShare = globalRewardPerShare;
emit RewardUpdated(user, oldShares, newShares);
if (totalSharesWas == 0 && totalShares > 0 && queuedRewards > 0) {
lastUpdateTime = block.timestamp;
uint256 amount = queuedRewards;
queuedRewards = 0;
rewardRate = amount / rewardDuration;
rewardEndTime = block.timestamp + rewardDuration;
nextRewardRetrieval = block.timestamp + rewardRefreshTime;
emit RewardsAdded(amount, rewardDuration, rewardRate, rewardEndTime);
} else if (totalSharesWas > 0 && totalShares == 0) {
if (block.timestamp < rewardEndTime)
queuedRewards += rewardRate * (rewardEndTime - block.timestamp);
emit RewardsPaused(queuedRewards);
rewardRate = 0;
}
return newShares;
}
function sharesFor(address user) public view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
UserData memory account = userData[user];
// --- Update Tilt weight ---
uint256 oldTiltWeight = account.tiltWeight;
uint256 tiltWeight = tiltStaking.getAccountWeight(user);
uint256 tiltTotal = tiltWeightTotal + tiltWeight - oldTiltWeight;
// --- Update boosted weight ---
uint256 oldBoostedWeight = account.boostedWeight;
uint256 boostedWeight = boostedStaking.getAccountWeight(user);
uint256 boostedTotal = boostedWeightTotal + boostedWeight - oldBoostedWeight;
// --- Compute user's new reward shares ---
uint256 newShares = (boostedWeight * 4e17) / PRECISION; // 0.4 * boosted weight
if (tiltTotal > 0 && tiltWeight > 0 && boostedWeight > 0) {
// Compute 0.6 * boostedWeightTotal * (newTiltWeight / tiltWeightTotal)
newShares += (boostedTotal * tiltWeight * 6e17) / (tiltTotal * PRECISION);
if (boostedWeight < newShares)
newShares = boostedWeight;
}
// Adjust global totalShares.
uint256 oldShares = account.shares;
uint256 _totalShares = totalShares + newShares - oldShares;
return (newShares, _totalShares, tiltWeight, tiltTotal, boostedWeight, boostedTotal);
}
/**
* @notice Requests new rewards from the reward holder and updates the reward stream.
*
* @dev Calls rewardHolder.requestRewards() to transfer new rewards into this contract.
* After the call, it updates the rewardRate and rewardEndTime based on the new total.
*/
function _retrieveNewRewards(bool force) internal {
require(address(rewardHolder) != address(0), "rewardHolder not set");
if (!force && block.timestamp < nextRewardRetrieval) return;
uint256 amount;
// Request rewards from the reward holder
(bool success, bytes memory data) = address(rewardHolder).call(
abi.encodeWithSelector(IRewardHolder.requestRewards.selector)
); if (success) amount = abi.decode(data, (uint256));
else emit RewardRequestFailed(data);
if (amount == 0) return;
// If nobody has shares, just queue these wrapped tokens.
if (totalShares == 0) {
queuedRewards += amount;
nextRewardRetrieval = block.timestamp + rewardRefreshTime;
} else {
if (block.timestamp < rewardEndTime) {
uint256 remaining = rewardEndTime - block.timestamp;
uint256 leftover = remaining * rewardRate;
amount += leftover;
}
amount += queuedRewards;
queuedRewards = 0;
nextRewardRetrieval = block.timestamp + rewardRefreshTime;
rewardEndTime = block.timestamp + rewardDuration;
rewardRate = amount / rewardDuration;
lastUpdateTime = block.timestamp;
emit RewardsAdded(amount, rewardDuration, rewardRate, rewardEndTime);
}
}
/**
* @notice Allows a user to claim their accrued rewards.
*
* @return amount The amount of reward tokens claimed.
*/
function wrappedClaimFor(address user) external nonReentrant returns (uint256 amount) {
require(approvedClaimer[user][msg.sender], "claimer not approved");
return _claim(user, false);
}
/**
* @notice Allows a user to claim their accrued rewards.
*
* @return amount The amount of reward tokens claimed.
*/
function claimFor(address user) external nonReentrant returns (uint256 amount) {
require(approvedClaimer[user][msg.sender], "claimer not approved");
return _claim(user, unwrappingEnabled);
}
/**
* @notice Allows a user to set another address to be able to claim their rewards
* @param claimer address to claim
* @param canClaim bool
*/
function setApprovedClaimer(address claimer, bool canClaim) external {
approvedClaimer[msg.sender][claimer] = canClaim;
}
/**
* @notice Allows a user to claim their accrued rewards.
*
* @return The amount of reward tokens claimed.
*/
function claim() external nonReentrant returns (uint256) {
return _claim(msg.sender, unwrappingEnabled);
}
function _claim(address user, bool _unwrap) internal returns (uint256) {
if (batchUpdateOnClaim)
tiltCore.batchUpdate(user, address(this));
else updateReward(user);
UserData storage account = userData[user];
uint256 reward = account.pendingReward;
if (reward == 0) return 0;
uint256 unwrappedReward;
account.pendingReward = 0;
if (_unwrap) {
wrappedReward.redeem(reward, msg.sender, address(this));
unwrappedReward = wrappedReward.previewRedeem(reward);
} else rewardToken.safeTransfer(msg.sender, reward);
emit RewardClaimed(user, msg.sender, reward, unwrappedReward);
return reward;
}
/**
* @dev Claims the accumulated rewards (still in their wrapper) for the caller.
*/
function claimWrapped() external nonReentrant returns (uint256) {
return _claim(msg.sender, false);
}
/**
* @notice Returns the pending reward for a user.
*
* @param user Address of the user.
* @return UserData with updated pending reward
*/
function getInfo(address user) external view returns (UserData memory) {
(uint256 locked, uint256 unlocked) = tiltStaking.getAccountBalances(user);
UserData memory data = userData[user];
data.tiltStaked = locked + unlocked;
data.boostedStake = boostedStaking.balanceOf(user);
data.pendingReward = viewPendingReward(user);
data.rewardsPerSecond = rewardRate;
data.totalShares = totalShares;
return data;
}
function computeSharesAt(address user, uint256 week) external view returns (uint256) {
return userData[user].shares;
}
/**
* @notice sets unwrapping rewardtoken to be enabled
* @param _unwrap bool
*/
function setUnwrappingEnabled(bool _unwrap) external onlyOwner {
unwrappingEnabled = _unwrap;
}
/**
* @notice returns unwrapped amount if unwrapping is enabled
*/
function unwrapped(uint256 input) public view returns (uint256) {
if (!unwrappingEnabled) return input;
return wrappedReward.previewRedeem(input);
}
/**
* @notice Returns the pending reward for a user.
*
* @param user Address of the user.
* @return The total pending reward amount.
*/
function viewPendingReward(address user) public view returns (uint256) {
UserData memory account = userData[user];
uint256 elapsed;
uint256 currentTime = block.timestamp;
uint256 applicableTime = currentTime < rewardEndTime ? currentTime : rewardEndTime;
if (applicableTime > lastUpdateTime)
elapsed = applicableTime - lastUpdateTime;
uint256 perShare = globalRewardPerShare;
if (totalShares > 0)
perShare += (rewardRate * elapsed * PRECISION) / totalShares;
uint256 accrued = (account.shares * (perShare - account.lastGlobalRewardPerShare)) / PRECISION;
return unwrapped(account.pendingReward + accrued);
}
/**
* @notice Allows the owner to update the staking contract addresses.
*
* @param _tiltStaking Address of the Tilt Staking contract.
* @param _boostedStaking Address of the boosted Staking contract.
*/
function setStakingAddresses(address _tiltStaking, address _boostedStaking) external onlyOwner {
tiltStaking = ITiltStaking(_tiltStaking);
boostedStaking = IBoostedStaking(_boostedStaking);
}
/**
* @notice Sets rewardRefreshTime (time between reward retrievals)
* @param _rewardRefreshTime New epoch duration
*/
function setRewardRefreshTime(uint256 _rewardRefreshTime) external onlyOwner {
require(_rewardRefreshTime <= 4 weeks, "rewardRefreshTime must be <= 4 weeks");
require(_rewardRefreshTime > 1 days, "rewardRefreshTime must be > 1 day");
rewardRefreshTime = _rewardRefreshTime;
emit RewardRefreshTimeUpdated(_rewardRefreshTime);
}
/**
* @notice Sets reward distribution duration
* @param _rewardDuration New reward duration
*/
function setRewardDuration(uint256 _rewardDuration) external onlyOwner {
require(_rewardDuration <= 4 weeks, "Reward duration must be <= 4 weeks");
require(_rewardDuration > 1 days, "Reward duration must be > 1 day");
rewardDuration = _rewardDuration;
emit RewardDurationUpdated(_rewardDuration);
}
function weeklyRewardAmount(uint256 week) external view returns (uint256) {
return rewardRate * 3600 * 24 * 7;
}
/**
* @notice withdraws tokens, if withdrawing reward token,
* @param tokenAddress address of token to withdraw
* @param to address receiver of tokens
* @param includeUnclaimed bool indicating if it should pull all tokens, or only un-owed tokens
*/
function emergencyWithdraw(address tokenAddress, address to, bool includeUnclaimed) external onlyOwner {
IERC20 token = IERC20(tokenAddress);
uint256 amount = token.balanceOf(address(this));
if (tokenAddress == address(rewardToken)) {
// 1) make sure all rewards are up to date to the current moment
updateGlobalReward();
if (!includeUnclaimed) {
// 2) compute what’s still owed in the active stream
amount = queuedRewards;
if (block.timestamp < rewardEndTime)
amount += rewardRate * (rewardEndTime - block.timestamp);
}
// 3) halt & reset all streaming state
lastUpdateTime = block.timestamp;
rewardEndTime = block.timestamp;
queuedRewards = 0;
rewardRate = 0;
emit RewardsPaused(0);
}
// non‐rewardToken: rescue the entire balance
token.safeTransfer(to, amount);
emit EmergencyWithdraw(tokenAddress, to, amount);
}
}
IBoostedStaking.sol 42 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
interface IBoostedStaking {
function getAccountWeight(address user) external view returns (uint256);
function stakeAsMaxWeighted(address _account, uint _amount) external returns (uint);
function checkpointAccount(address user) external returns (uint256);
function unstake(uint256 amount, address receiver) external returns (uint);
function balanceOf(address account) external view returns (uint256);
function stakeFor(address user, uint256 amount) external returns (uint256);
function getInfo(address user) external view returns (UserInfo memory);
function MAX_STAKE_GROWTH_WEEKS() external view returns (uint256);
function totalSupply() external view returns (uint256);
function getAccountWeightAt(address user, uint256 week) external view returns (uint256);
function getGlobalWeightAt(uint256 week) external view returns (uint256);
function globalWeeklyMaxStake(uint256 week) external view returns (uint256);
function globalWeeklyToRealize(uint256 week) external view returns (ToRealize memory);
function accountWeeklyToRealize(address user, uint256 week) external view returns (ToRealize memory);
function accountWeeklyMaxStake(address user, uint256 week) external view returns (uint256);
function stakeToken() external view returns (address);
function getWeek() external view returns (uint256);
struct ToRealize {
uint128 weightPersistent;
uint128 weight;
}
/// @notice Struct representing aggregated user reward info
struct UserInfo {
uint112 realizedStake; // Amount of stake that has fully realized weight.
uint112 pendingStake;
uint256 globalWeight;
uint256 totalStaked;
uint256 staked;
uint256 weight;
}
}
IDeposit.sol 14 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
interface IDeposit {
function balanceOf(address account) external view returns (uint256);
function previewRedeem(uint256 amount) external view returns (uint256);
function previewWithdraw(uint256 amount) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function deposit(uint256 amount, address receiver) external returns (uint256);
function withdraw(uint256 amount, address receiver, address owner) external returns (uint256);
function redeem(uint256 amount, address receiver, address owner) external returns (uint256);
}
IRewardHolder.sol 6 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
interface IRewardHolder {
function requestRewards() external returns (uint256);
}
ITiltCore.sol 11 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
interface ITiltCore {
function updateAll(address user) external;
function batchUpdateAll(address user) external;
function update(address user, address rewarder) external;
function batchUpdate(address user, address rewarder) external;
function setVaultAddress(address vault) external;
}
ITiltStaking.sol 47 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
interface ITiltStaking {
struct DelegationEntry {
uint256 amount;
address delegatee;
uint256 expiry; // 0 indicates indefinite delegation
address handler;
}
function lockToken() external view returns (address);
function MAX_LOCK_EPOCHS() external view returns (uint256);
function withdrawWithPenalty(uint256 amountToWithdraw) external returns (uint256);
function getAccountWeight(address user) external view returns (uint256);
function checkpointAccount(address user) external returns (uint256);
function getAccountWeightAt(address user, uint week) external view returns (uint256);
function getAccountBalances(address account) external view returns (uint256 lockedBalance, uint256 unlockedBalance);
function undelegate(uint256 delegationIndex) external returns (bool);
function approve(address operator, uint256 amount) external returns (bool);
function delegate(uint256 amount, address delegatee, uint256 period) external;
function delegateFor(address delegator, uint256 amount, address delegatee, uint256 period) external;
function getActiveDelegations(address user, uint256 offset) external view returns (DelegationEntry[] memory);
function remainingDelegationWeight(address user, uint256 freezeEpochs) external view returns (uint256);
function getTotalWeight() external view returns (uint256);
function getInfo(address user) external view returns (UserInfo memory);
struct UserInfo {
DelegationEntry[] delegations;
uint256 globalWeight;
uint256 delegatedOut;
uint256 delegatedIn;
uint256 totalStaked;
uint256 currentWeek;
uint16 freezeEpochs;
uint256 unlocked;
uint256 frozen;
uint256 locked;
uint256 staked;
uint256 weight;
}
}
Read Contract
PRECISION 0xaaf5eb68 → uint256
approvedClaimer 0x3bb959ce → bool
batchUpdateOnClaim 0xf8e05b01 → bool
boostedStaking 0xf73b0714 → address
boostedWeightTotal 0x2bad2ea6 → uint256
computeSharesAt 0x5fe6b010 → uint256
getInfo 0xffdd5cf1 → tuple
globalRewardPerShare 0x95a573bd → uint256
lastUpdateTime 0xc8f33c91 → uint256
nextRewardRetrieval 0x417d020b → uint256
owner 0x8da5cb5b → address
queuedRewards 0x63d38c3b → uint256
rewardDuration 0xf520e7e5 → uint256
rewardEndTime 0x37e9f64a → uint256
rewardHolder 0x569c93d2 → address
rewardRate 0x7b0a47ee → uint256
rewardRefreshTime 0x33a7944a → uint256
rewardToken 0xf7c618c1 → address
sharesFor 0x6eb854c8 → uint256, uint256, uint256, uint256, uint256, uint256
tiltCore 0x799e16e2 → address
tiltStaking 0xb5c2204a → address
tiltWeightTotal 0xe9125ee2 → uint256
totalShares 0x3a98ef39 → uint256
unwrapped 0xdbc99b2e → uint256
unwrappingEnabled 0xa1a524cd → bool
userData 0xc8910913 → uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256
viewPendingReward 0x6dff4ac4 → uint256
weeklyRewardAmount 0x37381f42 → uint256
wrappedReward 0xa757db4a → address
Write Contract 17 functions
These functions modify contract state and require a wallet transaction to execute.
claim 0x4e71d92d
No parameters
returns: uint256
claimFor 0xddeae033
address user
returns: uint256
claimWrapped 0x8eafaea5
No parameters
returns: uint256
emergencyWithdraw 0xdd333f04
address tokenAddress
address to
bool includeUnclaimed
forceUpdateGlobalReward 0xd1bc34c4
No parameters
renounceOwnership 0x715018a6
No parameters
setApprovedClaimer 0xfaf1e091
address claimer
bool canClaim
setBatchUpdateOnClaim 0x24889f42
bool _enabled
setRewardDuration 0xc0ed00c9
uint256 _rewardDuration
setRewardHolder 0x6806cc93
address _rewardHolder
setRewardRefreshTime 0xf4ee3011
uint256 _rewardRefreshTime
setStakingAddresses 0x11d6bf3c
address _tiltStaking
address _boostedStaking
setUnwrappingEnabled 0x50e7dc3d
bool _unwrap
transferOwnership 0xf2fde38b
address newOwner
updateGlobalReward 0x7695caa2
No parameters
updateReward 0x632447c9
address user
returns: uint256
wrappedClaimFor 0xeac5fe3c
address user
returns: uint256
Recent Transactions
No transactions found for this address