Forkchoice Ethereum Mainnet

Address Contract Verified

Address 0x5aeC6db5FC9490120f209a313EbB8d15C91b1604
Balance 0 ETH
Nonce 1
Code Size 14795 bytes
Indexed Transactions 0 (1 on-chain, 1.4% indexed)
External Etherscan · Sourcify

Contract Bytecode

14795 bytes
0x60806040526004361061022f5760003560e01c8063719de1ef1161012e578063b07da958116100ab578063e67a97981161006f578063e67a9798146107d4578063e7a8cf4f146107f4578063f032e64214610814578063f72f1e3814610834578063fc0c546a1461086a57600080fd5b8063b07da95814610714578063d1d098d214610734578063d547741f14610772578063dc7eae8814610792578063e63ab1e9146107b257600080fd5b8063a217fddf116100f2578063a217fddf1461063f578063ab761e3214610654578063ac28af2414610682578063ad3cb1cc146106b6578063af686544146106f457600080fd5b8063719de1ef14610587578063733d4809146105d5578063784f3b86146105ea5780638456cb591461060a57806391d148541461061f57600080fd5b80633d3d937d116101bc5780635095af64116101805780635095af641461047557806352d1902d146104a95780635c975abb146104be5780636365950c146104e357806370d5ae051461054f57600080fd5b80633d3d937d1461037b5780633f4ba83a146103915780633ff8a1bb146103a6578063414fa511146103c65780634f1ef2861461046257600080fd5b8063282c51f311610203578063282c51f3146102d957806329f6f722146102fb5780632f2ff15d1461031b57806336568abe1461033b5780633c4666cf1461035b57600080fd5b8062897a591461023457806301ffc9a714610256578063248a9ca31461028b57806324f1cb4d146102b9575b600080fd5b34801561024057600080fd5b5061025461024f3660046130ef565b61088a565b005b34801561026257600080fd5b5061027661027136600461310a565b610a74565b60405190151581526020015b60405180910390f35b34801561029757600080fd5b506102ab6102a6366004613134565b610aab565b604051908152602001610282565b3480156102c557600080fd5b506102546102d4366004613198565b610acd565b3480156102e557600080fd5b506102ab6000805160206138f683398151915281565b34801561030757600080fd5b50610254610316366004613231565b610b9b565b34801561032757600080fd5b506102546103363660046132b3565b610c33565b34801561034757600080fd5b506102546103563660046132b3565b610c55565b34801561036757600080fd5b506102546103763660046132df565b610c8d565b34801561038757600080fd5b506102ab60045481565b34801561039d57600080fd5b50610254610f95565b3480156103b257600080fd5b506102546103c13660046133ac565b610fc0565b3480156103d257600080fd5b506104276103e1366004613456565b6001602052600090815260409020546001600160401b038116906001600160581b03600160401b8204811691600160981b81049091169061ffff600160f01b9091041684565b604080516001600160401b039590951685526001600160581b039384166020860152919092169083015261ffff166060820152608001610282565b610254610470366004613487565b61179b565b34801561048157600080fd5b506102ab7f12b42e8a160f6064dc959c6f251e3af0750ad213dbecf573b4710d67d6c28e3981565b3480156104b557600080fd5b506102ab6117b6565b3480156104ca57600080fd5b506000805160206139768339815191525460ff16610276565b3480156104ef57600080fd5b506104276104fe366004613548565b60026020908152600092835260408084209091529082529020546001600160401b038116906001600160581b03600160401b8204811691600160981b81049091169061ffff600160f01b9091041684565b34801561055b57600080fd5b5060055461056f906001600160a01b031681565b6040516001600160a01b039091168152602001610282565b34801561059357600080fd5b506105bd6105a2366004613456565b6000602081905290815260409020546001600160581b031681565b6040516001600160581b039091168152602001610282565b3480156105e157600080fd5b506102546117d3565b3480156105f657600080fd5b50610254610605366004613589565b61198d565b34801561061657600080fd5b50610254611ac8565b34801561062b57600080fd5b5061027661063a3660046132b3565b611af0565b34801561064b57600080fd5b506102ab600081565b34801561066057600080fd5b5060035461066f9061ffff1681565b60405161ffff9091168152602001610282565b34801561068e57600080fd5b506102ab7f88f3509f0e42391f2d94ebfb2a37cbd0782b1b8f73715330017f4663290b811781565b3480156106c257600080fd5b506106e7604051806040016040528060058152602001640352e302e360dc1b81525081565b60405161028291906135c8565b34801561070057600080fd5b5061025461070f366004613231565b611b28565b34801561072057600080fd5b5061025461072f3660046135fb565b611c80565b34801561074057600080fd5b5060035461075a906201000090046001600160401b031681565b6040516001600160401b039091168152602001610282565b34801561077e57600080fd5b5061025461078d3660046132b3565b611c93565b34801561079e57600080fd5b506102546107ad366004613650565b611caf565b3480156107be57600080fd5b506102ab60008051602061393683398151915281565b3480156107e057600080fd5b506102546107ef3660046136a4565b612151565b34801561080057600080fd5b5061025461080f3660046136ce565b612163565b34801561082057600080fd5b5061025461082f3660046136ea565b6123da565b34801561084057600080fd5b506105bd61084f366004613714565b6006602052600090815260409020546001600160581b031681565b34801561087657600080fd5b5060075461056f906001600160a01b031681565b61089261241e565b3360009081526001602052604090208054426001600160401b0390911611156108ce5760405163856807e360e01b815260040160405180910390fd5b80546001600160581b03600160401b909104811690831611156109045760405163fd7850ad60e01b815260040160405180910390fd5b805482908290600890610928908490600160401b90046001600160581b0316613745565b82546101009290920a6001600160581b038181021990931691831602179091553360009081526020819052604081208054869450909261096a91859116613745565b92506101000a8154816001600160581b0302191690836001600160581b03160217905550336001600160a01b03167fdf840a32812a920a66fd3c346227e29e48aff7eaca366912af757fb28b7247e3836040516109d691906001600160581b0391909116815260200190565b60405180910390a260075460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90610a109033908690600401613765565b6020604051808303816000875af1158015610a2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a539190613787565b610a705760405163bfa871c560e01b815260040160405180910390fd5b5050565b60006001600160e01b03198216637965db0b60e01b1480610aa557506301ffc9a760e01b6001600160e01b03198316145b92915050565b6000908152600080516020613956833981519152602052604090206001015490565b610ad561241e565b8483141580610ae45750848114155b15610b025760405163512509d360e11b815260040160405180910390fd5b60005b85811015610b9257610b8a878783818110610b2257610b226137a9565b9050602002016020810190610b379190613456565b868684818110610b4957610b496137a9565b9050602002016020810190610b5e91906130ef565b858585818110610b7057610b706137a9565b9050602002016020810190610b859190613589565b612451565b600101610b05565b50505050505050565b610ba361241e565b828114610bc35760405163512509d360e11b815260040160405180910390fd5b60005b83811015610c2c57610c24858583818110610be357610be36137a9565b9050602002016020810190610bf89190613456565b848484818110610c0a57610c0a6137a9565b9050602002016020810190610c1f9190613589565b612756565b600101610bc6565b5050505050565b610c3c82610aab565b610c45816128ba565b610c4f83836128c4565b50505050565b6001600160a01b0381163314610c7e5760405163334bd91960e11b815260040160405180910390fd5b610c888282612970565b505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b0316600081158015610cd25750825b90506000826001600160401b03166001148015610cee5750303b155b905081158015610cfc575080155b15610d1a5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315610d4457845460ff60401b1916600160401b1785555b6001600160a01b038e16610d6b576040516303988b8160e61b815260040160405180910390fd5b610d736129ec565b610d7b6129f4565b610d8660008d6128c4565b50610d9f6000805160206139368339815191528d6128c4565b50610db86000805160206138f68339815191528d6128c4565b5060005b8a811015610e1d57610e147f12b42e8a160f6064dc959c6f251e3af0750ad213dbecf573b4710d67d6c28e398d8d84818110610dfa57610dfa6137a9565b9050602002016020810190610e0f9190613456565b6128c4565b50600101610dbc565b5060005b88811015610e6857610e5f7f88f3509f0e42391f2d94ebfb2a37cbd0782b1b8f73715330017f4663290b81178b8b84818110610dfa57610dfa6137a9565b50600101610e21565b5060005b86811015610ea157610e986000805160206138f6833981519152898984818110610dfa57610dfa6137a9565b50600101610e6c565b508d600760006101000a8154816001600160a01b0302191690836001600160a01b031602179055508c600560006101000a8154816001600160a01b0302191690836001600160a01b031602179055506001600360006101000a81548161ffff021916908361ffff1602179055506276a700600360026101000a8154816001600160401b0302191690836001600160401b03160217905550426004819055508315610f8557845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b5050505050505050505050505050565b600080516020613936833981519152610fad816128ba565b610fb5612a04565b610fbd612a34565b50565b7f12b42e8a160f6064dc959c6f251e3af0750ad213dbecf573b4710d67d6c28e39610fea816128ba565b610ff261241e565b6064826001600160581b0316118061101157506001600160581b038216155b1561102f57604051632a235f3d60e01b815260040160405180910390fd5b86858481146110515760405163a17efd0360e01b815260040160405180910390fd5b60005b828110156113c85760008b8b83818110611070576110706137a9565b90506020020160208101906110859190613456565b6001600160a01b038116600090815260016020526040812054919250906064906110bf90600160401b90046001600160581b0316896137bf565b6110c991906137ea565b6001600160a01b0383166000908152600160205260409020805491925090600160f01b900461ffff161580159061111257506003548154600160f01b900461ffff908116911614155b156112315760035461112a9060019061ffff1661381e565b815461ffff918216600160f01b9091049091160361121b578054600354600160981b9091046001600160581b03169060069060009061116f9060019061ffff1661381e565b61ffff16815260208101919091526040016000908120805490919061119e9084906001600160581b0316613745565b82546101009290920a6001600160581b03818102199093169183160217909155825460035461ffff1660009081526006602052604081208054600160981b909304841694509290916111f291859116613839565b92506101000a8154816001600160581b0302191690836001600160581b03160217905550611231565b80546affffffffffffffffffffff60981b191681555b60035461ffff166000908152600660205260408120805484929061125f9084906001600160581b0316613839565b82546101009290920a6001600160581b0381810219909316918316021790915560035483546001600160f01b031661ffff909116600160f01b021780845584925083916013916112b8918591600160981b900416613839565b92506101000a8154816001600160581b0302191690836001600160581b03160217905550818160000160088282829054906101000a90046001600160581b03166113029190613745565b82546101009290920a6001600160581b038181021990931691831602179091556001600160a01b03851660009081526020819052604081208054869450909261134d91859116613745565b82546101009290920a6001600160581b0381810219909316918316021790915560035460408051928616835261ffff90911660208301526001600160a01b038616925082917fe4a628b7ff23a2937efd9d26e66add5b40dd3076a7987056bbf84ca5b1d09936910160405180910390a3505050600101611054565b5060005b8181101561178e5760008989838181106113e8576113e86137a9565b90506020020160208101906113fd9190613456565b90506000888884818110611413576114136137a9565b90506020020160208101906114289190613456565b6001600160a01b0383811660009081526002602090815260408083209385168352929052908120549192509060649061147190600160401b90046001600160581b03168a6137bf565b61147b91906137ea565b6001600160a01b038481166000908152600260209081526040808320938716835292905220805491925090600160f01b900461ffff16158015906114d157506003548154600160f01b900461ffff908116911614155b156115f0576003546114e99060019061ffff1661381e565b815461ffff918216600160f01b909104909116036115da578054600354600160981b9091046001600160581b03169060069060009061152e9060019061ffff1661381e565b61ffff16815260208101919091526040016000908120805490919061155d9084906001600160581b0316613745565b82546101009290920a6001600160581b03818102199093169183160217909155825460035461ffff1660009081526006602052604081208054600160981b909304841694509290916115b191859116613839565b92506101000a8154816001600160581b0302191690836001600160581b031602179055506115f0565b80546affffffffffffffffffffff60981b191681555b60035461ffff166000908152600660205260408120805484929061161e9084906001600160581b0316613839565b82546101009290920a6001600160581b0381810219909316918316021790915560035483546001600160f01b031661ffff909116600160f01b02178084558492508391601391611677918591600160981b900416613839565b92506101000a8154816001600160581b0302191690836001600160581b03160217905550818160000160088282829054906101000a90046001600160581b03166116c19190613745565b82546101009290920a6001600160581b038181021990931691831602179091556001600160a01b03861660009081526020819052604081208054869450909261170c91859116613745565b82546101009290920a6001600160581b0381810219909316918316021790915560035460408051928616835261ffff90911660208301526001600160a01b0386811693508716917fe4a628b7ff23a2937efd9d26e66add5b40dd3076a7987056bbf84ca5b1d09936910160405180910390a35050600190920191506113cc9050565b5050505050505050505050565b6117a3612a94565b6117ac82612b39565b610a708282612b44565b60006117c0612c06565b5060008051602061391683398151915290565b6000805160206138f68339815191526117eb816128ba565b6117f361241e565b600354600454620100009091046001600160401b0316906118149042613859565b1015611833576040516302f0e3e760e41b815260040160405180910390fd5b6003546000906118499060019061ffff1661381e565b61ffff808216600090815260066020526040812054600380549495506001600160581b0390911693909261187d911661386c565b91906101000a81548161ffff021916908361ffff160217905550426004819055506000816001600160581b031611156119465760075460055460405163a9059cbb60e01b81526001600160a01b039283169263a9059cbb926118e6929116908590600401613765565b6020604051808303816000875af1158015611905573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119299190613787565b6119465760405163bfa871c560e01b815260040160405180910390fd5b6040516001600160581b038216815261ffff8316907f06367c1bab68f0c9b021d69341825bcbd2483b3f9f80fdedb196a8f33e21179b9060200160405180910390a2505050565b61199561241e565b33600090815260016020526040812054600160401b90046001600160581b031690036119d457604051635e85ae7360e01b815260040160405180910390fd5b60006119e0428361388d565b90506119ef42626ebe006138ad565b816001600160401b03161080611a1a5750611a0e426303bfc4006138ad565b816001600160401b0316115b80611a405750336000908152600160205260409020546001600160401b03908116908216105b15611a5e5760405163abf20e8f60e01b815260040160405180910390fd5b336000818152600160209081526040808320805467ffffffffffffffff19166001600160401b0387169081179091558151938452918301919091527f6600db42842224c3c3595c34733f34ac160702ac47d49fb5f7bdd28fa964b728910160405180910390a25050565b600080516020613936833981519152611ae0816128ba565b611ae861241e565b610fbd612c4f565b6000918252600080516020613956833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b611b3061241e565b828114611b505760405163512509d360e11b815260040160405180910390fd5b6000805b84811015611bed57611bb2868683818110611b7157611b716137a9565b9050602002016020810190611b869190613456565b858584818110611b9857611b986137a9565b9050602002016020810190611bad91906130ef565b612c98565b838382818110611bc457611bc46137a9565b9050602002016020810190611bd991906130ef565b611be39083613839565b9150600101611b54565b5060075460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90611c209033908590600401613765565b6020604051808303816000875af1158015611c3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c639190613787565b610c2c5760405163bfa871c560e01b815260040160405180910390fd5b611c8861241e565b610c88838383612451565b611c9c82610aab565b611ca5816128ba565b610c4f8383612970565b7f88f3509f0e42391f2d94ebfb2a37cbd0782b1b8f73715330017f4663290b8117611cd9816128ba565b611ce161241e565b600354611cf49060019061ffff1661381e565b61ffff168261ffff161015611d1c5760405163162af38760e01b815260040160405180910390fd5b6001600160a01b038416611d43576040516303988b8160e61b815260040160405180910390fd5b6001600160a01b038516611d6a576040516303988b8160e61b815260040160405180910390fd5b6001600160a01b03851660009081526020819052604081208054859290611d9b9084906001600160581b0316613839565b92506101000a8154816001600160581b0302191690836001600160581b03160217905550836001600160a01b0316856001600160a01b031603611f24576001600160a01b0385166000908152600160205260409020546001600160581b03600160981b90910481169084161115611e25576040516356c8f43760e11b815260040160405180910390fd5b6001600160a01b03851660009081526001602052604090205461ffff838116600160f01b9092041614611e6b57604051631eb5af2360e11b815260040160405180910390fd5b6001600160a01b03851660009081526001602052604090208054849190601390611ea6908490600160981b90046001600160581b0316613745565b82546101009290920a6001600160581b038181021990931691831602179091556001600160a01b038716600090815260016020526040902080548693509091600891611efb918591600160401b900416613839565b92506101000a8154816001600160581b0302191690836001600160581b031602179055506120a0565b6001600160a01b038086166000908152600260209081526040808320938816835292905220546001600160581b03600160981b90910481169084161115611f7e576040516356c8f43760e11b815260040160405180910390fd5b6001600160a01b0385811660009081526002602090815260408083209388168352929052205461ffff838116600160f01b9092041614611fd157604051631eb5af2360e11b815260040160405180910390fd5b6001600160a01b0385811660009081526002602090815260408083209388168352929052208054849190601390612019908490600160981b90046001600160581b0316613745565b82546101009290920a6001600160581b038181021990931691831602179091556001600160a01b038781166000908152600260209081526040808320938a168352929052208054869350909160089161207b918591600160401b900416613839565b92506101000a8154816001600160581b0302191690836001600160581b031602179055505b61ffff8216600090815260066020526040812080548592906120cc9084906001600160581b0316613745565b92506101000a8154816001600160581b0302191690836001600160581b03160217905550836001600160a01b0316856001600160a01b03167f1859a1047624eb24b7401a705f696a8f216c1837a55690ea164288ab010293978560405161214291906001600160581b0391909116815260200190565b60405180910390a35050505050565b61215961241e565b610a708282612756565b61216b61241e565b816001600160581b031660000361219557604051635e85ae7360e01b815260040160405180910390fd5b60006121a1428361388d565b90506121b042626ebe006138ad565b816001600160401b031610806121db57506121cf426303bfc4006138ad565b816001600160401b0316115b806122015750336000908152600160205260409020546001600160401b03908116908216105b1561221f5760405163abf20e8f60e01b815260040160405180910390fd5b3360009081526001602052604090208054849190600890612251908490600160401b90046001600160581b0316613839565b82546101009290920a6001600160581b03818102199093169183160217909155336000908152600160209081526040808320805467ffffffffffffffff19166001600160401b038816179055908290528120805487945090926122b691859116613839565b92506101000a8154816001600160581b0302191690836001600160581b03160217905550336001600160a01b03167f6600db42842224c3c3595c34733f34ac160702ac47d49fb5f7bdd28fa964b72884836040516123329291906001600160581b039290921682526001600160401b0316602082015260400190565b60405180910390a26007546040516323b872dd60e01b81523360048201523060248201526001600160581b03851660448201526001600160a01b03909116906323b872dd906064016020604051808303816000875af1158015612399573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123bd9190613787565b610c885760405163bfa871c560e01b815260040160405180910390fd5b6123e261241e565b6123ec8282612c98565b60075460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90610a109033908590600401613765565b6000805160206139768339815191525460ff161561244f5760405163d93c066560e01b815260040160405180910390fd5b565b336001600160a01b0384160361247a57604051635c39972d60e01b815260040160405180910390fd5b6001600160a01b0383166124a1576040516303988b8160e61b815260040160405180910390fd5b816001600160581b03166000036124cb57604051635e85ae7360e01b815260040160405180910390fd5b60006124d7428361388d565b90506124e642626ebe006138ad565b816001600160401b031610806125115750612505426303bfc4006138ad565b816001600160401b0316115b8061254b57503360009081526002602090815260408083206001600160a01b03881684529091529020546001600160401b03908116908216105b156125695760405163abf20e8f60e01b815260040160405180910390fd5b3360009081526002602090815260408083206001600160a01b0388168452909152902080548491906008906125af908490600160401b90046001600160581b0316613839565b82546101009290920a6001600160581b038181021990931691831602179091553360008181526002602090815260408083206001600160a01b038b1684528252808320805467ffffffffffffffff19166001600160401b0389161790559282528190529081208054879450909261262891859116613839565b92506101000a8154816001600160581b0302191690836001600160581b03160217905550836001600160a01b0316336001600160a01b03167fb65e180628043209b010b8f98fd0b36d27d6cf60b5764a937dc4fce9c8a215e385846040516126ae9291906001600160581b039290921682526001600160401b0316602082015260400190565b60405180910390a36007546040516323b872dd60e01b81523360048201523060248201526001600160581b03851660448201526001600160a01b03909116906323b872dd906064016020604051808303816000875af1158015612715573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127399190613787565b610c4f5760405163bfa871c560e01b815260040160405180910390fd5b6001600160a01b03821661277d576040516303988b8160e61b815260040160405180910390fd5b3360009081526002602090815260408083206001600160a01b0386168452909152812080549091600160401b9091046001600160581b031690036127d457604051635e85ae7360e01b815260040160405180910390fd5b60006127e0428461388d565b90506127ef42626ebe006138ad565b816001600160401b0316108061281a575061280e426303bfc4006138ad565b816001600160401b0316115b80612832575081546001600160401b03908116908216105b156128505760405163abf20e8f60e01b815260040160405180910390fd5b815467ffffffffffffffff19166001600160401b0382169081178355604080516000815260208101929092526001600160a01b0386169133917fb65e180628043209b010b8f98fd0b36d27d6cf60b5764a937dc4fce9c8a215e3910160405180910390a350505050565b610fbd8133612e58565b60006000805160206139568339815191526128df8484611af0565b61295f576000848152602082815260408083206001600160a01b03871684529091529020805460ff191660011790556129153390565b6001600160a01b0316836001600160a01b0316857f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a46001915050610aa5565b6000915050610aa5565b5092915050565b600060008051602061395683398151915261298b8484611af0565b1561295f576000848152602082815260408083206001600160a01b0387168085529252808320805460ff1916905551339287917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a46001915050610aa5565b61244f612e91565b6129fc612e91565b61244f612eda565b6000805160206139768339815191525460ff1661244f57604051638dfc202b60e01b815260040160405180910390fd5b612a3c612a04565b600080516020613976833981519152805460ff191681557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a150565b306001600160a01b037f0000000000000000000000005aec6db5fc9490120f209a313ebb8d15c91b1604161480612b1b57507f0000000000000000000000005aec6db5fc9490120f209a313ebb8d15c91b16046001600160a01b0316612b0f600080516020613916833981519152546001600160a01b031690565b6001600160a01b031614155b1561244f5760405163703e46dd60e11b815260040160405180910390fd5b6000610a70816128ba565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612b9e575060408051601f3d908101601f19168201909252612b9b918101906138c0565b60015b612bcb57604051634c9c8ce360e01b81526001600160a01b03831660048201526024015b60405180910390fd5b6000805160206139168339815191528114612bfc57604051632a87526960e21b815260048101829052602401612bc2565b610c888383612efb565b306001600160a01b037f0000000000000000000000005aec6db5fc9490120f209a313ebb8d15c91b1604161461244f5760405163703e46dd60e11b815260040160405180910390fd5b612c5761241e565b600080516020613976833981519152805460ff191660011781557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833612a76565b6001600160a01b038216612cbf576040516303988b8160e61b815260040160405180910390fd5b806001600160581b0316600003612ce957604051635e85ae7360e01b815260040160405180910390fd5b3360009081526002602090815260408083206001600160a01b038616845290915290208054426001600160401b039091161115612d395760405163856807e360e01b815260040160405180910390fd5b80546001600160581b03600160401b90910481169083161115612d6f5760405163fd7850ad60e01b815260040160405180910390fd5b805482908290600890612d93908490600160401b90046001600160581b0316613745565b82546101009290920a6001600160581b0381810219909316918316021790915533600090815260208190526040812080548694509092612dd591859116613745565b92506101000a8154816001600160581b0302191690836001600160581b03160217905550826001600160a01b0316336001600160a01b03167f2caac2d31fe8eb8221533ae01b6f8a86f77673624d0a37836993b272f3846a0e84604051612e4b91906001600160581b0391909116815260200190565b60405180910390a3505050565b612e628282611af0565b610a705760405163e2517d3f60e01b81526001600160a01b038216600482015260248101839052604401612bc2565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661244f57604051631afcd79f60e31b815260040160405180910390fd5b612ee2612e91565b600080516020613976833981519152805460ff19169055565b612f0482612f51565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a2805115612f4957610c888282612fb6565b610a7061302c565b806001600160a01b03163b600003612f8757604051634c9c8ce360e01b81526001600160a01b0382166004820152602401612bc2565b60008051602061391683398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060600080846001600160a01b031684604051612fd391906138d9565b600060405180830381855af49150503d806000811461300e576040519150601f19603f3d011682016040523d82523d6000602084013e613013565b606091505b509150915061302385838361304b565b95945050505050565b341561244f5760405163b398979f60e01b815260040160405180910390fd5b6060826130605761305b826130aa565b6130a3565b815115801561307757506001600160a01b0384163b155b156130a057604051639996b31560e01b81526001600160a01b0385166004820152602401612bc2565b50805b9392505050565b8051156130ba5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b80356001600160581b03811681146130ea57600080fd5b919050565b60006020828403121561310157600080fd5b6130a3826130d3565b60006020828403121561311c57600080fd5b81356001600160e01b0319811681146130a357600080fd5b60006020828403121561314657600080fd5b5035919050565b60008083601f84011261315f57600080fd5b5081356001600160401b0381111561317657600080fd5b6020830191508360208260051b850101111561319157600080fd5b9250929050565b600080600080600080606087890312156131b157600080fd5b86356001600160401b03808211156131c857600080fd5b6131d48a838b0161314d565b909850965060208901359150808211156131ed57600080fd5b6131f98a838b0161314d565b9096509450604089013591508082111561321257600080fd5b5061321f89828a0161314d565b979a9699509497509295939492505050565b6000806000806040858703121561324757600080fd5b84356001600160401b038082111561325e57600080fd5b61326a8883890161314d565b9096509450602087013591508082111561328357600080fd5b506132908782880161314d565b95989497509550505050565b80356001600160a01b03811681146130ea57600080fd5b600080604083850312156132c657600080fd5b823591506132d66020840161329c565b90509250929050565b600080600080600080600080600060c08a8c0312156132fd57600080fd5b6133068a61329c565b985061331460208b0161329c565b975061332260408b0161329c565b965060608a01356001600160401b038082111561333e57600080fd5b61334a8d838e0161314d565b909850965060808c013591508082111561336357600080fd5b61336f8d838e0161314d565b909650945060a08c013591508082111561338857600080fd5b506133958c828d0161314d565b915080935050809150509295985092959850929598565b60008060008060008060006080888a0312156133c757600080fd5b87356001600160401b03808211156133de57600080fd5b6133ea8b838c0161314d565b909950975060208a013591508082111561340357600080fd5b61340f8b838c0161314d565b909750955060408a013591508082111561342857600080fd5b506134358a828b0161314d565b90945092506134489050606089016130d3565b905092959891949750929550565b60006020828403121561346857600080fd5b6130a38261329c565b634e487b7160e01b600052604160045260246000fd5b6000806040838503121561349a57600080fd5b6134a38361329c565b915060208301356001600160401b03808211156134bf57600080fd5b818501915085601f8301126134d357600080fd5b8135818111156134e5576134e5613471565b604051601f8201601f19908116603f0116810190838211818310171561350d5761350d613471565b8160405282815288602084870101111561352657600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b6000806040838503121561355b57600080fd5b6135648361329c565b91506132d66020840161329c565b80356001600160401b03811681146130ea57600080fd5b60006020828403121561359b57600080fd5b6130a382613572565b60005b838110156135bf5781810151838201526020016135a7565b50506000910152565b60208152600082518060208401526135e78160408501602087016135a4565b601f01601f19169190910160400192915050565b60008060006060848603121561361057600080fd5b6136198461329c565b9250613627602085016130d3565b915061363560408501613572565b90509250925092565b803561ffff811681146130ea57600080fd5b6000806000806080858703121561366657600080fd5b61366f8561329c565b935061367d6020860161329c565b925061368b604086016130d3565b91506136996060860161363e565b905092959194509250565b600080604083850312156136b757600080fd5b6136c08361329c565b91506132d660208401613572565b600080604083850312156136e157600080fd5b6136c0836130d3565b600080604083850312156136fd57600080fd5b6137068361329c565b91506132d6602084016130d3565b60006020828403121561372657600080fd5b6130a38261363e565b634e487b7160e01b600052601160045260246000fd5b6001600160581b038281168282160390808211156129695761296961372f565b6001600160a01b039290921682526001600160581b0316602082015260400190565b60006020828403121561379957600080fd5b815180151581146130a357600080fd5b634e487b7160e01b600052603260045260246000fd5b6001600160581b038181168382160280821691908281146137e2576137e261372f565b505092915050565b60006001600160581b038084168061381257634e487b7160e01b600052601260045260246000fd5b92169190910492915050565b61ffff8281168282160390808211156129695761296961372f565b6001600160581b038181168382160190808211156129695761296961372f565b81810381811115610aa557610aa561372f565b600061ffff8083168181036138835761388361372f565b6001019392505050565b6001600160401b038181168382160190808211156129695761296961372f565b80820180821115610aa557610aa561372f565b6000602082840312156138d257600080fd5b5051919050565b600082516138eb8184602087016135a4565b919091019291505056fe3c11d16cbaffd01df69ce1c404f6340ee057498f5f00246190ea54220576a848360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300a2646970667358221220e78bded9c1a614bf0e7c05a409b56666f0709a7f5f26667628d88f80d3da715764736f6c63430008170033

Verified Source Code Full Match

Compiler: v0.8.23+commit.f704f362 EVM: paris Optimization: Yes (200 runs)
IdentityStaking.sol 694 lines
// SPDX-License-Identifier: GPL
pragma solidity ^0.8.23;

import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

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

/// @title IdentityStaking
/// @author Passport
/// @notice This contract is used to stake GTC on self/community identity
contract IdentityStaking is
  IIdentityStaking,
  Initializable,
  UUPSUpgradeable,
  AccessControlUpgradeable,
  PausableUpgradeable
{
  /***** SECTION 0: Errors, State, Events *****/

  /// @dev Address parameter cannot be zero
  error AddressCannotBeZero();

  /// @dev Stake amount must be greater than zero
  error AmountMustBeGreaterThanZero();

  /// @dev A community stake cannot be placed on the staker's own address
  error CannotStakeOnSelf();

  /// @dev An ERC20 transfer failed
  error FailedTransfer();

  /// @dev The lock time must be between 12 and 104 weeks, and after any existing lock
  error InvalidLockTime();

  /// @dev The stake is still locked and cannot be withdrawn
  error StakeIsLocked();

  /// @dev The requested withdrawal amount is greater than the stake
  error AmountTooHigh();

  /// @dev The slash percent must be between 1 and 100
  error InvalidSlashPercent();

  /// @dev The staker and stakee arrays must be the same length
  error StakerStakeeMismatch();

  /// @dev The requested funds are greater than the slashed amount for this user
  error FundsNotAvailableToRelease();

  /// @dev The requested funds are not available to release for this user from the given round
  error FundsNotAvailableToReleaseFromRound();

  /// @dev The round has already been burned and its slashed stake cannot be released
  error RoundAlreadyBurned();

  /// @dev The minimum burn round duration has not been met, controlled by the `burnRoundMinimumDuration`
  error MinimumBurnRoundDurationNotMet();

  /// @dev Input array lengths do not match
  error ArrayLengthMismatch();

  /// @notice Role held by addresses which are permitted to submit a slash.
  bytes32 public constant SLASHER_ROLE = keccak256("SLASHER_ROLE");

  /// @notice Role held by addresses which are permitted to release an un-burned slash.
  bytes32 public constant RELEASER_ROLE = keccak256("RELEASER_ROLE");

  /// @notice Role held by addresses which are permitted to lock and burn
  bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");

  /// @notice Role held by addresses which are permitted to pause the contract.
  bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

  /// @notice Struct representing a stake
  /// @param unlockTime The unix time in seconds after which the stake can be withdrawn
  /// @param amount The amount of GTC staked, with 18 decimals
  /// @param slashedAmount The amount of GTC slashed (could already be burned)
  /// @param slashedInRound The round in which the stake was last slashed
  /// @dev uint88s can hold up to 300 million w/ 18 decimals, or 3x the current max supply
  ///      `amount` does not include any slashed or burned GTC
  struct Stake {
    uint64 unlockTime;
    uint88 amount;
    uint88 slashedAmount;
    uint16 slashedInRound;
  }

  /// @inheritdoc IIdentityStaking
  mapping(address => uint88) public userTotalStaked;

  /// @inheritdoc IIdentityStaking
  mapping(address => Stake) public selfStakes;

  /// @inheritdoc IIdentityStaking
  mapping(address => mapping(address => Stake)) public communityStakes;

  /// @notice The current round of slashing, incremented on each call to `lockAndBurn`
  /// @dev uint16 can hold up to 65,535 rounds, or 16,383 years with 90 day rounds
  ///      Set to `1` in the initializer
  uint16 public currentSlashRound;

  /// @notice The minimum duration between burn rounds
  /// @dev This sets the minimum appeal period for a slash
  ///      Set to `90 days` in the initializer
  uint64 public burnRoundMinimumDuration;

  /// @notice The timestamp of the last burn
  uint256 public lastBurnTimestamp;

  /// @notice The address to which all burned tokens are sent
  /// @dev Set in the initializer
  ///      This could be set to the zero address. But in the case of GTC,
  ///      it is set to the GTC token contract address because GTC cannot
  ///      be transferred to the zero address
  address public burnAddress;

  /// @notice The total amount of GTC slashed in each round
  mapping(uint16 => uint88) public totalSlashed;

  /// @notice The GTC token contract
  IERC20 public token;

  /// @notice Emitted when a self-stake is added/increased/extended
  /// @param staker The staker's address
  /// @param amount The additional amount added for this particular transaction
  /// @param unlockTime Unlock time for the full self-stake amount for this staker
  /// @dev `amount` could be `0` for an extension
  event SelfStake(address indexed staker, uint88 amount, uint64 unlockTime);

  /// @notice Emitted when a community stake is added/increased/extended
  /// @param staker The staker's address
  /// @param stakee The stakee's address
  /// @param amount The additional amount added for this particular transaction
  /// @param unlockTime Unlock time for the full community stake amount for this staker on this stakee
  /// @dev `amount` could be `0` for an extension
  event CommunityStake(
    address indexed staker,
    address indexed stakee,
    uint88 amount,
    uint64 unlockTime
  );

  /// @notice Emitted when a self-stake is withdrawn
  /// @param staker The staker's address
  /// @param amount The amount withdrawn in this transaction
  event SelfStakeWithdrawn(address indexed staker, uint88 amount);

  /// @notice Emitted when a community stake is withdrawn
  /// @param staker The staker's address
  /// @param stakee The stakee's address
  /// @param amount The amount withdrawn in this transaction
  event CommunityStakeWithdrawn(address indexed staker, address indexed stakee, uint88 amount);

  /// @notice Emitted when a slash is submitted
  /// @param staker Address of the staker who is slashed
  /// @param stakee Address of the stakee who is slashed (same as staker if self-stake)
  /// @param amount The amount slashed in this transaction
  /// @param round The round in which the slash occurred
  event Slash(address indexed staker, address indexed stakee, uint88 amount, uint16 round);

  /// @notice Emitted when a round is burned
  /// @param round The round that was burned
  /// @param amount The amount of GTC burned in this transaction
  event Burn(uint16 indexed round, uint88 amount);

  /// @notice Emitted when a slash is released
  /// @param staker The staker's address
  /// @param stakee The stakee's address
  /// @param amount The amount released in this transaction
  event Release(address indexed staker, address indexed stakee, uint88 amount);

  /***** SECTION 1: Admin Functions *****/

  /// @notice Initialize the contract
  /// @param tokenAddress The address of the GTC token contract
  /// @param _burnAddress The address to which all burned tokens are sent
  /// @param initialAdmin The initial address to assign the DEFAULT_ADMIN_ROLE
  /// @param initialSlashers The initial addresses to assign the SLASHER_ROLE
  /// @param initialReleasers The initial addresses to assign the RELEASER_ROLE
  /// @param initialBurners The initial addresses to assign the BURNER_ROLE
  function initialize(
    address tokenAddress,
    address _burnAddress,
    address initialAdmin,
    address[] calldata initialSlashers,
    address[] calldata initialReleasers,
    address[] calldata initialBurners
  ) public initializer {
    if (tokenAddress == address(0)) {
      revert AddressCannotBeZero();
    }

    __AccessControl_init();
    __Pausable_init();

    _grantRole(DEFAULT_ADMIN_ROLE, initialAdmin);
    _grantRole(PAUSER_ROLE, initialAdmin);
    _grantRole(BURNER_ROLE, initialAdmin);

    for (uint256 i = 0; i < initialSlashers.length; i++) {
      _grantRole(SLASHER_ROLE, initialSlashers[i]);
    }

    for (uint256 i = 0; i < initialReleasers.length; i++) {
      _grantRole(RELEASER_ROLE, initialReleasers[i]);
    }

    for (uint256 i = 0; i < initialBurners.length; i++) {
      _grantRole(BURNER_ROLE, initialBurners[i]);
    }

    token = IERC20(tokenAddress);
    burnAddress = _burnAddress;

    currentSlashRound = 1;
    burnRoundMinimumDuration = 90 days;
    lastBurnTimestamp = block.timestamp;
  }

  /// @notice Pause the contract
  function pause() external onlyRole(PAUSER_ROLE) whenNotPaused {
    _pause();
  }

  /// @notice Unpause the contract
  function unpause() external onlyRole(PAUSER_ROLE) whenPaused {
    _unpause();
  }

  /// @inheritdoc UUPSUpgradeable
  /// @dev Only the admin can upgrade the contract
  /// @dev UUPSUpgradeable allows the contract to be permanently frozen in the future
  function _authorizeUpgrade(address) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}

  /***** SECTION 2: Staking Functions *****/

  /// @notice Add self stake
  /// @param amount The amount of GTC to Stake
  /// @param duration The duration in seconds of the stake lock period
  /// @dev The duration must be between 12 weeks and 104 weeks, and after any existing lock
  ///      The amount must be greater than zero
  ///      The unlock time is calculated as `block.timestamp + duration`
  ///      If there is any existing self-stake, the unlock time is extended for the entire stake amount
  function selfStake(uint88 amount, uint64 duration) external whenNotPaused {
    if (amount == 0) {
      revert AmountMustBeGreaterThanZero();
    }

    uint64 unlockTime = duration + uint64(block.timestamp);

    if (
      // Must be between 12 weeks and 104 weeks
      unlockTime < block.timestamp + 12 weeks ||
      unlockTime > block.timestamp + 104 weeks ||
      // Must be later than any existing lock
      unlockTime < selfStakes[msg.sender].unlockTime
    ) {
      revert InvalidLockTime();
    }

    selfStakes[msg.sender].amount += amount;
    selfStakes[msg.sender].unlockTime = unlockTime;
    userTotalStaked[msg.sender] += amount;

    emit SelfStake(msg.sender, amount, unlockTime);

    if (!token.transferFrom(msg.sender, address(this), amount)) {
      revert FailedTransfer();
    }
  }

  /// @notice Extend lock period for self stake
  /// @param duration The duration in seconds for the new lock period
  /// @dev The duration must be between 12 weeks and 104 weeks, and after any existing lock for this self-stake
  ///      The unlock time is calculated as `block.timestamp + duration`
  function extendSelfStake(uint64 duration) external whenNotPaused {
    if (selfStakes[msg.sender].amount == 0) {
      revert AmountMustBeGreaterThanZero();
    }

    uint64 unlockTime = duration + uint64(block.timestamp);

    if (
      // Must be between 12 weeks and 104 weeks
      unlockTime < block.timestamp + 12 weeks ||
      unlockTime > block.timestamp + 104 weeks ||
      // Must be later than any existing lock
      unlockTime < selfStakes[msg.sender].unlockTime
    ) {
      revert InvalidLockTime();
    }

    selfStakes[msg.sender].unlockTime = unlockTime;

    emit SelfStake(msg.sender, 0, unlockTime);
  }

  /// @notice Withdraw unlocked self stake
  /// @param amount The amount to withdraw
  function withdrawSelfStake(uint88 amount) external whenNotPaused {
    Stake storage sStake = selfStakes[msg.sender];

    if (sStake.unlockTime > block.timestamp) {
      revert StakeIsLocked();
    }

    if (amount > sStake.amount) {
      revert AmountTooHigh();
    }

    sStake.amount -= amount;
    userTotalStaked[msg.sender] -= amount;

    emit SelfStakeWithdrawn(msg.sender, amount);

    if (!token.transfer(msg.sender, amount)) {
      revert FailedTransfer();
    }
  }

  /// @notice Add community stake on a stakee
  /// @param stakee The address of the stakee
  /// @param amount The amount to stake
  /// @param duration The duration in seconds of the stake lock period
  /// @dev The duration must be between 12-104 weeks and 104 weeks, and after any existing lock for this staker+stakee
  ///      The amount must be greater than zero
  ///      The unlock time is calculated as `block.timestamp + duration`
  ///      If there is any existing stake by this staker on this stakee, the unlock time is extended for the entire stake amount
  function _communityStake(address stakee, uint88 amount, uint64 duration) private {
    if (stakee == msg.sender) {
      revert CannotStakeOnSelf();
    }
    if (stakee == address(0)) {
      revert AddressCannotBeZero();
    }
    if (amount == 0) {
      revert AmountMustBeGreaterThanZero();
    }

    uint64 unlockTime = duration + uint64(block.timestamp);

    if (
      // Must be between 12 weeks and 104 weeks
      unlockTime < block.timestamp + 12 weeks ||
      unlockTime > block.timestamp + 104 weeks ||
      // Must be later than any existing lock
      unlockTime < communityStakes[msg.sender][stakee].unlockTime
    ) {
      revert InvalidLockTime();
    }

    communityStakes[msg.sender][stakee].amount += amount;
    communityStakes[msg.sender][stakee].unlockTime = unlockTime;
    userTotalStaked[msg.sender] += amount;

    emit CommunityStake(msg.sender, stakee, amount, unlockTime);

    if (!token.transferFrom(msg.sender, address(this), amount)) {
      revert FailedTransfer();
    }
  }

  /// @notice Add community stake on a stakee
  /// @param stakee The address of the stakee
  /// @param amount The amount to stake
  /// @param duration The duration in seconds of the stake lock period
  /// @dev The duration must be between 12-104 weeks and 104 weeks, and after any existing lock for this staker+stakee
  ///      The amount must be greater than zero
  ///      The unlock time is calculated as `block.timestamp + duration`
  ///      If there is any existing stake by this staker on this stakee, the unlock time is extended for the entire stake amount
  function communityStake(address stakee, uint88 amount, uint64 duration) external whenNotPaused {
    _communityStake(stakee, amount, duration);
  }

  /// @notice Add community stake on a stakee
  /// @param stakees The list of addresses the stakees
  /// @param amounts The amount to stake on each stakee
  /// @param durations The duration in seconds of the stake lock period for each stake
  /// @dev The duration must be between 12-104 weeks and 104 weeks, and after any existing lock for this staker+stakee
  ///      The amount must be greater than zero
  ///      The unlock time is calculated as `block.timestamp + duration`
  ///      If there is any existing stake by this staker on this stakee, the unlock time is extended for the entire stake amount
  function multipleCommunityStakes(
    address[] calldata stakees,
    uint88[] calldata amounts,
    uint64[] calldata durations
  ) external whenNotPaused {
    if (stakees.length != amounts.length || stakees.length != durations.length) {
      revert ArrayLengthMismatch();
    }

    for (uint i = 0; i < stakees.length; i++) {
      _communityStake(stakees[i], amounts[i], durations[i]);
    }
  }

  /// @notice Extend lock period for community stake on a stakee
  /// @param stakee The address of the stakee
  /// @param duration The duration in seconds for the new lock period
  /// @dev The duration must be between 12-104 weeks and 104 weeks, and after any existing lock for this staker+stakee
  ///      The unlock time is calculated as `block.timestamp + duration`
  function _extendCommunityStake(address stakee, uint64 duration) private {
    if (stakee == address(0)) {
      revert AddressCannotBeZero();
    }

    Stake storage comStake = communityStakes[msg.sender][stakee];

    if (comStake.amount == 0) {
      revert AmountMustBeGreaterThanZero();
    }

    uint64 unlockTime = duration + uint64(block.timestamp);

    if (
      // Must be between 12 weeks and 104 weeks
      unlockTime < block.timestamp + 12 weeks ||
      unlockTime > block.timestamp + 104 weeks ||
      // Must be later than any existing lock
      unlockTime < comStake.unlockTime
    ) {
      revert InvalidLockTime();
    }

    comStake.unlockTime = unlockTime;

    emit CommunityStake(msg.sender, stakee, 0, unlockTime);
  }

  /// @notice Extend lock period for community stake on a stakee
  /// @param stakee The address of the stakee
  /// @param duration The duration in seconds for the new lock period
  /// @dev The duration must be between 12-104 weeks and 104 weeks, and after any existing lock for this staker+stakee
  ///      The unlock time is calculated as `block.timestamp + duration`
  function extendCommunityStake(address stakee, uint64 duration) external whenNotPaused {
    _extendCommunityStake(stakee, duration);
  }

  /// @notice Extend lock period for community stakes on a list of stakee
  /// @param stakees The addresses of the stakees
  /// @param durations The duration for each stake in seconds for the new lock period
  /// @dev The duration must be between 12-104 weeks and 104 weeks, and after any existing lock for any of the staker+stakee pairs
  ///      The unlock time is calculated as `block.timestamp + duration`
  function extendMultipleCommunityStakes(
    address[] calldata stakees,
    uint64[] calldata durations
  ) external whenNotPaused {
    if (stakees.length != durations.length) {
      revert ArrayLengthMismatch();
    }

    for (uint i = 0; i < stakees.length; i++) {
      _extendCommunityStake(stakees[i], durations[i]);
    }
  }

  /// @notice Prepare withdraw from community stake. This function will check if the stake is unlocked and
  /// substract the desired amount from the stake object, emit the event and it will return the amount that
  /// needs to be transfered (but it will not execute the transfer).
  /// @param stakee The address of the stakee
  /// @param amount The amount to withdraw
  function _prepareWithdrawCommunityStake(address stakee, uint88 amount) private {
    if (stakee == address(0)) {
      revert AddressCannotBeZero();
    }

    if (amount == 0) {
      revert AmountMustBeGreaterThanZero();
    }

    Stake storage comStake = communityStakes[msg.sender][stakee];

    if (comStake.unlockTime > block.timestamp) {
      revert StakeIsLocked();
    }

    if (amount > comStake.amount) {
      revert AmountTooHigh();
    }

    comStake.amount -= amount;
    userTotalStaked[msg.sender] -= amount;

    emit CommunityStakeWithdrawn(msg.sender, stakee, amount);
  }

  /// @notice Withdraw unlocked community stake on a stakee
  /// @param stakee The address of the stakee
  /// @param amount The amount to withdraw
  function withdrawCommunityStake(address stakee, uint88 amount) external whenNotPaused {
    _prepareWithdrawCommunityStake(stakee, amount);
    if (!token.transfer(msg.sender, amount)) {
      revert FailedTransfer();
    }
  }

  /// @notice Withdraw multiple unlocked community stakes
  /// @param stakees The address of the stakees
  /// @param amounts The amount to withdraw from each stake
  function withdrawMultipleCommunityStakes(
    address[] calldata stakees,
    uint88[] calldata amounts
  ) external whenNotPaused {
    if (stakees.length != amounts.length) {
      revert ArrayLengthMismatch();
    }
    uint88 totalAmountToWithdraw = 0;

    for (uint i = 0; i < stakees.length; i++) {
      _prepareWithdrawCommunityStake(stakees[i], amounts[i]);

      totalAmountToWithdraw += amounts[i];
    }

    if (!token.transfer(msg.sender, totalAmountToWithdraw)) {
      revert FailedTransfer();
    }
  }

  /***** SECTION 3: Slashing Functions *****/

  /// @notice Submit a slash
  /// @param selfStakers The addresses of the self-stakers to slash
  /// @param communityStakers Ordered list of the community-stakers to slash
  /// @param communityStakees Ordered list of the community-stakees to slash
  /// @param percent The percentage to slash from each stake
  /// @dev The slash percent must be between 1 and 100
  ///      The community staker and stakee arrays must be the same length
  ///      Ordered such that communityStakers[i] has a communityStake on communityStakees[i]
  ///      All staked amounts are liable to be slashed, even if they are unlocked
  function slash(
    address[] calldata selfStakers,
    address[] calldata communityStakers,
    address[] calldata communityStakees,
    uint88 percent
  ) external onlyRole(SLASHER_ROLE) whenNotPaused {
    if (percent > 100 || percent == 0) {
      revert InvalidSlashPercent();
    }

    uint256 numSelfStakers = selfStakers.length;
    uint256 numCommunityStakers = communityStakers.length;

    if (numCommunityStakers != communityStakees.length) {
      revert StakerStakeeMismatch();
    }

    for (uint256 i = 0; i < numSelfStakers; i++) {
      address staker = selfStakers[i];
      uint88 slashedAmount = (percent * selfStakes[staker].amount) / 100;

      Stake storage sStake = selfStakes[staker];

      if (sStake.slashedInRound != 0 && sStake.slashedInRound != currentSlashRound) {
        if (sStake.slashedInRound == currentSlashRound - 1) {
          // If this is a slash from the previous round (not yet burned), move
          // it to the current round
          totalSlashed[currentSlashRound - 1] -= sStake.slashedAmount;
          totalSlashed[currentSlashRound] += sStake.slashedAmount;
        } else {
          // Otherwise, this is a stale slash and can be overwritten
          sStake.slashedAmount = 0;
        }
      }

      totalSlashed[currentSlashRound] += slashedAmount;

      sStake.slashedInRound = currentSlashRound;
      sStake.slashedAmount += slashedAmount;
      sStake.amount -= slashedAmount;

      userTotalStaked[staker] -= slashedAmount;

      emit Slash(staker, staker, slashedAmount, currentSlashRound);
    }

    for (uint256 i = 0; i < numCommunityStakers; i++) {
      address staker = communityStakers[i];
      address stakee = communityStakees[i];
      uint88 slashedAmount = (percent * communityStakes[staker][stakee].amount) / 100;

      Stake storage comStake = communityStakes[staker][stakee];

      if (comStake.slashedInRound != 0 && comStake.slashedInRound != currentSlashRound) {
        if (comStake.slashedInRound == currentSlashRound - 1) {
          // If this is a slash from the previous round (not yet burned), move
          // it to the current round
          totalSlashed[currentSlashRound - 1] -= comStake.slashedAmount;
          totalSlashed[currentSlashRound] += comStake.slashedAmount;
        } else {
          // Otherwise, this is a stale slash and can be overwritten
          comStake.slashedAmount = 0;
        }
      }

      totalSlashed[currentSlashRound] += slashedAmount;

      comStake.slashedInRound = currentSlashRound;
      comStake.slashedAmount += slashedAmount;
      comStake.amount -= slashedAmount;

      userTotalStaked[staker] -= slashedAmount;

      emit Slash(staker, stakee, slashedAmount, currentSlashRound);
    }
  }

  /// @notice Progress to the next slash round, this has 3 effects:
  ///      1) Locks the current round so that it can be burned after `burnRoundMinimumDuration` has passed
  ///      2) Burns the previous round
  ///      3) Starts the new round
  /// @dev Anyone can call this function, the `burnRoundMinimumDuration` keeps everything in check
  ///      This is all about enforcing a minimum appeal period for a slash
  ///      The "locking" is implicit, in that the previous round is always burned and there is a minimum duration between burns
  function lockAndBurn() external onlyRole(BURNER_ROLE) whenNotPaused {
    if (block.timestamp - lastBurnTimestamp < burnRoundMinimumDuration) {
      revert MinimumBurnRoundDurationNotMet();
    }
    uint16 roundToBurn = currentSlashRound - 1;
    uint88 amountToBurn = totalSlashed[roundToBurn];

    ++currentSlashRound;
    lastBurnTimestamp = block.timestamp;

    if (amountToBurn > 0) {
      if (!token.transfer(burnAddress, amountToBurn)) {
        revert FailedTransfer();
      }
    }

    emit Burn(roundToBurn, amountToBurn);
  }

  /// @notice Release slashed funds
  /// @param staker The staker's address
  /// @param stakee The stakee's address
  /// @param amountToRelease The amount to release
  /// @param slashRound The round from which to release the funds
  /// @dev Only funds from the current round and the previous round can be released (prior rounds already burned)
  ///      If stakee == staker, the funds are released from the self-stake, otherwise from the community-stake
  ///      Funds can only be released back to the original staker
  function release(
    address staker,
    address stakee,
    uint88 amountToRelease,
    uint16 slashRound
  ) external onlyRole(RELEASER_ROLE) whenNotPaused {
    if (slashRound < currentSlashRound - 1) {
      revert RoundAlreadyBurned();
    }

    if (stakee == address(0)) {
      revert AddressCannotBeZero();
    }

    if (staker == address(0)) {
      revert AddressCannotBeZero();
    }

    userTotalStaked[staker] += amountToRelease;
    if (staker == stakee) {
      if (amountToRelease > selfStakes[staker].slashedAmount) {
        revert FundsNotAvailableToRelease();
      }

      if (selfStakes[staker].slashedInRound != slashRound) {
        revert FundsNotAvailableToReleaseFromRound();
      }

      selfStakes[staker].slashedAmount -= amountToRelease;
      selfStakes[staker].amount += amountToRelease;
    } else {
      if (amountToRelease > communityStakes[staker][stakee].slashedAmount) {
        revert FundsNotAvailableToRelease();
      }

      if (communityStakes[staker][stakee].slashedInRound != slashRound) {
        revert FundsNotAvailableToReleaseFromRound();
      }

      communityStakes[staker][stakee].slashedAmount -= amountToRelease;
      communityStakes[staker][stakee].amount += amountToRelease;
    }

    totalSlashed[slashRound] -= amountToRelease;

    emit Release(staker, stakee, amountToRelease);
  }
}
IIdentityStaking.sol 45 lines
// SPDX-License-Identifier: GPL
pragma solidity ^0.8.23;

/**
 * @title IIdentityStaking
 * @notice This is a minimal interface for consuming stake data
 */
interface IIdentityStaking {

  /// @notice Self-stakes by a user
  /// @param staker The staker's address
  /// @return unlockTime Time at which the stake unlocks
  /// @return amount Unslashed amount of the stake, with 18 decimal places
  /// @return slashedAmount Current slash amount
  /// @return slashedInRound Round in which the stake was last slashed
  /// @dev see the `Stake` struct for more details
  function selfStakes(
    address staker
  )
    external
    view
    returns (uint64 unlockTime, uint88 amount, uint88 slashedAmount, uint16 slashedInRound);

  /// @notice Community-stakes by a staker on a stakee
  /// @param staker Staker's address
  /// @param stakee Stakee's address
  /// @return unlockTime Time at which the stake unlocks
  /// @return amount Unslashed amount of the stake, with 18 decimal places
  /// @return slashedAmount Current slash amount
  /// @return slashedInRound Round in which the stake was last slashed
  /// @dev see the `Stake` struct for more details
  function communityStakes(
    address staker,
    address stakee
  )
    external
    view
    returns (uint64 unlockTime, uint88 amount, uint88 slashedAmount, uint16 slashedInRound);

  /// @notice Get the total amount staked by a user
  /// @param staker The staker's address
  /// @return The total amount staked by the user, with 18 decimal places
  /// @dev This includes both self-stake and community-stakes by this user on others
  function userTotalStaked(address staker) external view returns (uint88);
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @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.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @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 or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * 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.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @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`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) 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 FailedInnerCall();
        }
    }
}
StorageSlot.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {UpgradeableBeacon} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}
IAccessControl.sol 98 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)

pragma solidity ^0.8.20;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}
draft-IERC1822.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.20;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822Proxiable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}
ERC1967Utils.sol 193 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.20;

import {IBeacon} from "../beacon/IBeacon.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 */
library ERC1967Utils {
    // We re-declare ERC-1967 events here because they can't be used directly from IERC1967.
    // This will be fixed in Solidity 0.8.21. At that point we should remove these events.
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}
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);
}
ContextUpgradeable.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

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

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

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

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}
PausableUpgradeable.sol 140 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Pausable
    struct PausableStorage {
        bool _paused;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300;

    function _getPausableStorage() private pure returns (PausableStorage storage $) {
        assembly {
            $.slot := PausableStorageLocation
        }
    }

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

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

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        PausableStorage storage $ = _getPausableStorage();
        $._paused = false;
    }

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

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

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

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

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

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        PausableStorage storage $ = _getPausableStorage();
        $._paused = false;
        emit Unpaused(_msgSender());
    }
}
UUPSUpgradeable.sol 153 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.20;

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable __self = address(this);

    /**
     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
     * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
     * during an upgrade.
     */
    string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";

    /**
     * @dev The call is from an unauthorized context.
     */
    error UUPSUnauthorizedCallContext();

    /**
     * @dev The storage `slot` is unsupported as a UUID.
     */
    error UUPSUnsupportedProxiableUUID(bytes32 slot);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        _checkProxy();
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        _checkNotDelegated();
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual notDelegated returns (bytes32) {
        return ERC1967Utils.IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data);
    }

    /**
     * @dev Reverts if the execution is not performed via delegatecall or the execution
     * context is not of a proxy with an ERC1967-compliant implementation pointing to self.
     * See {_onlyProxy}.
     */
    function _checkProxy() internal view virtual {
        if (
            address(this) == __self || // Must be called through delegatecall
            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
        ) {
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Reverts if the execution is performed via delegatecall.
     * See {notDelegated}.
     */
    function _checkNotDelegated() internal view virtual {
        if (address(this) != __self) {
            // Must not be called through delegatecall
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}
AccessControlUpgradeable.sol 233 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControl, ERC165Upgradeable {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;


    /// @custom:storage-location erc7201:openzeppelin.storage.AccessControl
    struct AccessControlStorage {
        mapping(bytes32 role => RoleData) _roles;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800;

    function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) {
        assembly {
            $.slot := AccessControlStorageLocation
        }
    }

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    function __AccessControl_init() internal onlyInitializing {
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        return $._roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        return $._roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        AccessControlStorage storage $ = _getAccessControlStorage();
        bytes32 previousAdminRole = getRoleAdmin(role);
        $._roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        if (!hasRole(role, account)) {
            $._roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        if (hasRole(role, account)) {
            $._roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}
ERC165Upgradeable.sol 33 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165Upgradeable is Initializable, IERC165 {
    function __ERC165_init() internal onlyInitializing {
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

Read Contract

BURNER_ROLE 0x282c51f3 → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
PAUSER_ROLE 0xe63ab1e9 → bytes32
RELEASER_ROLE 0xac28af24 → bytes32
SLASHER_ROLE 0x5095af64 → bytes32
UPGRADE_INTERFACE_VERSION 0xad3cb1cc → string
burnAddress 0x70d5ae05 → address
burnRoundMinimumDuration 0xd1d098d2 → uint64
communityStakes 0x6365950c → uint64, uint88, uint88, uint16
currentSlashRound 0xab761e32 → uint16
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
lastBurnTimestamp 0x3d3d937d → uint256
paused 0x5c975abb → bool
proxiableUUID 0x52d1902d → bytes32
selfStakes 0x414fa511 → uint64, uint88, uint88, uint16
supportsInterface 0x01ffc9a7 → bool
token 0xfc0c546a → address
totalSlashed 0xf72f1e38 → uint88
userTotalStaked 0x719de1ef → uint88

Write Contract 19 functions

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

communityStake 0xb07da958
address stakee
uint88 amount
uint64 duration
extendCommunityStake 0xe67a9798
address stakee
uint64 duration
extendMultipleCommunityStakes 0x29f6f722
address[] stakees
uint64[] durations
extendSelfStake 0x784f3b86
uint64 duration
grantRole 0x2f2ff15d
bytes32 role
address account
initialize 0x3c4666cf
address tokenAddress
address _burnAddress
address initialAdmin
address[] initialSlashers
address[] initialReleasers
address[] initialBurners
lockAndBurn 0x733d4809
No parameters
multipleCommunityStakes 0x24f1cb4d
address[] stakees
uint88[] amounts
uint64[] durations
pause 0x8456cb59
No parameters
release 0xdc7eae88
address staker
address stakee
uint88 amountToRelease
uint16 slashRound
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
revokeRole 0xd547741f
bytes32 role
address account
selfStake 0xe7a8cf4f
uint88 amount
uint64 duration
slash 0x3ff8a1bb
address[] selfStakers
address[] communityStakers
address[] communityStakees
uint88 percent
unpause 0x3f4ba83a
No parameters
upgradeToAndCall 0x4f1ef286
address newImplementation
bytes data
withdrawCommunityStake 0xf032e642
address stakee
uint88 amount
withdrawMultipleCommunityStakes 0xaf686544
address[] stakees
uint88[] amounts
withdrawSelfStake 0x00897a59
uint88 amount

Recent Transactions

This address has 1 on-chain transactions, but only 1.4% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →