Forkchoice Ethereum Mainnet

Address Contract Partially Verified

Address 0xa20caFD257494D7bFBD7122b9af892CD03d9A8De
Balance 0 ETH
Nonce 1
Code Size 22350 bytes
Indexed Transactions 0 (1 on-chain, 1.5% indexed)
External Etherscan · Sourcify

Contract Bytecode

22350 bytes
Copy Bytecode
0x6080604052600436106103bc5760003560e01c80637a4473e1116101f2578063d547741f1161010d578063ec87621c116100a0578063f5404d601161006f578063f5404d6014610b3d578063fa69501814610b5d578063fadb574d14610b7d578063fd9c652b14610b9d57600080fd5b8063ec87621c14610aa3578063ecacf56d14610ad7578063f1f3b3e714610aed578063f22abf3714610b0e57600080fd5b8063e08f2d89116100dc578063e08f2d8914610a23578063e43a495414610a39578063e63ab1e914610a4f578063e7efb74714610a8357600080fd5b8063d547741f146109a2578063d7d25461146109c2578063da863b3b146109e2578063dc3fc3b2146109f857600080fd5b8063a065913f11610185578063be9d96a011610154578063be9d96a0146108cc578063c8c3df4a146108e2578063cdb54a1b14610955578063d283e75f1461096b57600080fd5b8063a065913f14610861578063a13cb53814610877578063a217fddf14610897578063b181033a146108ac57600080fd5b80638d40152c116101c15780638d40152c146107e157806391b66caa1461080157806391d148541461082157806399629f581461084157600080fd5b80637a4473e1146107815780638456cb59146107a1578063849138af146107b65780638b0bfd35146107cb57600080fd5b80633a4b66f1116102e25780634f13b2e31161027557806361c993c51161024457806361c993c51461071f57806364363f2b146107355780636a42602c1461074b578063755d7dd31461076157600080fd5b80634f13b2e314610699578063506a7bec146106b95780635a1239c1146106d65780635c975abb1461070757600080fd5b806342f1e879116102b157806342f1e8791461062b57806349557df91461064d5780634cd79e0a146106635780634e8ab1a11461067957600080fd5b80633a4b66f1146105bc5780633bf39dca146105d15780633f4ba83a146106015780634006ccc51461061657600080fd5b80632ae45fa11161035a57806333e5761f1161032957806333e5761f1461053157806336568abe1461054757806336bf3325146105675780633884545d1461058457600080fd5b80632ae45fa1146104d05780632e12007c146104e65780632f2ff15d146104fb57806330b12c8d1461051b57600080fd5b80630917e776116103965780630917e776146104555780630a1521fc1461046b5780631b2ef1ca1461048d578063248a9ca3146104a057600080fd5b806301ffc9a7146103c857806307e2cea5146103fd57806308b84c0c1461043f57600080fd5b366103c357005b600080fd5b3480156103d457600080fd5b506103e86103e3366004614cf2565b610bb2565b60405190151581526020015b60405180910390f35b34801561040957600080fd5b506104317f68e79a7bf1e0bc45d0a330c573bc367f9cf464fd326078812f301165fbda4ef181565b6040519081526020016103f4565b34801561044b57600080fd5b5061010b54610431565b34801561046157600080fd5b5061010454610431565b34801561047757600080fd5b5061048b610486366004614d67565b610be9565b005b61043161049b366004614e00565b61100d565b3480156104ac57600080fd5b506104316104bb366004614e22565b60009081526097602052604090206001015490565b3480156104dc57600080fd5b5061011754610431565b3480156104f257600080fd5b50610431611228565b34801561050757600080fd5b5061048b610516366004614e50565b61126b565b34801561052757600080fd5b5061010054610431565b34801561053d57600080fd5b5061010f54610431565b34801561055357600080fd5b5061048b610562366004614e50565b611295565b34801561057357600080fd5b506104316801bc16d674ec80000081565b34801561059057600080fd5b5060fb546105a4906001600160a01b031681565b6040516001600160a01b0390911681526020016103f4565b3480156105c857600080fd5b5061048b611313565b3480156105dd57600080fd5b506105f16105ec366004614e00565b61131d565b6040516103f49493929190614f6d565b34801561060d57600080fd5b5061048b6116e3565b34801561062257600080fd5b50610431611718565b34801561063757600080fd5b506104316000805160206156f983398151915281565b34801561065957600080fd5b5061011454610431565b34801561066f57600080fd5b5061043160ff5481565b34801561068557600080fd5b5061048b610694366004614fba565b611722565b3480156106a557600080fd5b5061048b6106b4366004615033565b6119b7565b3480156106c557600080fd5b506104316801a055690d9db8000081565b3480156106e257600080fd5b506106f66106f1366004614e22565b611cb0565b6040516103f495949392919061510d565b34801561071357600080fd5b5060335460ff166103e8565b34801561072b57600080fd5b5061010a54610431565b34801561074157600080fd5b5061010354610431565b34801561075757600080fd5b5061010d54610431565b34801561076d57600080fd5b5061048b61077c366004614e22565b611e11565b34801561078d57600080fd5b5060fd546105a4906001600160a01b031681565b3480156107ad57600080fd5b5061048b611e86565b3480156107c257600080fd5b5061048b611eb8565b3480156107d757600080fd5b5061010554610431565b3480156107ed57600080fd5b5061048b6107fc366004615153565b611ece565b34801561080d57600080fd5b5061048b61081c366004615153565b611f7d565b34801561082d57600080fd5b506103e861083c366004614e50565b611fd6565b34801561084d57600080fd5b5061048b61085c366004615170565b612001565b34801561086d57600080fd5b5061010c54610431565b34801561088357600080fd5b5061048b610892366004614e00565b61231a565b3480156108a357600080fd5b50610431600081565b3480156108b857600080fd5b5060fc546105a4906001600160a01b031681565b3480156108d857600080fd5b5061011054610431565b3480156108ee57600080fd5b506109366108fd366004614e22565b60009081526101066020908152604091829020825180840190935280546001600160a01b03168084526001909101549290910182905291565b604080516001600160a01b0390931683526020830191909152016103f4565b34801561096157600080fd5b5061010e54610431565b34801561097757600080fd5b50610431610986366004615153565b6001600160a01b03166000908152610109602052604090205490565b3480156109ae57600080fd5b5061048b6109bd366004614e50565b61234e565b3480156109ce57600080fd5b5061048b6109dd366004614e22565b612373565b3480156109ee57600080fd5b5061010254610431565b348015610a0457600080fd5b5061010754610108545b604080519283526020830191909152016103f4565b348015610a2f57600080fd5b5061011154610431565b348015610a4557600080fd5b5061043160fe5481565b348015610a5b57600080fd5b506104317f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a81565b348015610a8f57600080fd5b5061048b610a9e366004614fba565b6123b3565b348015610aaf57600080fd5b506104317f241ecf16d79d0f8dbfb92cbc07fe17840425976cf0667f022fe9877caa831b0881565b348015610ae357600080fd5b5061011254610431565b348015610af957600080fd5b5061013c546105a4906001600160a01b031681565b348015610b1a57600080fd5b50610b2e610b29366004614e00565b61263c565b6040516103f4939291906151bb565b348015610b4957600080fd5b50610431610b583660046151fe565b61295b565b348015610b6957600080fd5b50610a0e610b78366004614e22565b612b7b565b348015610b8957600080fd5b5061048b610b98366004614e22565b612b90565b348015610ba957600080fd5b5061048b612c85565b60006001600160e01b03198216637965db0b60e01b1480610be357506301ffc9a760e01b6001600160e01b03198316145b92915050565b6000805160206156f9833981519152610c0181612c9c565b60408051808201909152600681526553595330303760d01b6020820152610c2b9087861490612ca6565b60408051808201909152600681526553595330303760d01b6020820152610c559087841490612ca6565b61013c546040805163d2197bd360e01b8152905188926000926001600160a01b039091169163d2197bd3916004808201926020929091908290030181865afa158015610ca5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cc9919061522a565b905060005b8281101561100157610d2660308b8b84818110610ced57610ced615243565b9050602002810190610cff9190615259565b9050146040518060400160405280600681526020016514d654cc0c0d60d21b815250612ca6565b610d766060898984818110610d3d57610d3d615243565b9050602002810190610d4f9190615259565b9050146040518060400160405280600681526020016553595330303360d01b815250612ca6565b610dc982878784818110610d8c57610d8c615243565b9050602002016020810190610da1919061529f565b60ff16106040518060400160405280600681526020016553595330333160d01b815250612ca6565b60008a8a83818110610ddd57610ddd615243565b9050602002810190610def9190615259565b604051610dfd9291906152c2565b60405180910390209050610e466101016000838152602001908152602001600020546000146040518060400160405280600681526020016553595330303560d01b815250612ca6565b6101006040518060a001604052808d8d86818110610e6657610e66615243565b9050602002810190610e789190615259565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050908252506020018b8b86818110610ec457610ec4615243565b9050602002810190610ed69190615259565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920182905250938552505050602082015260016040820152606001898986818110610f2d57610f2d615243565b9050602002016020810190610f42919061529f565b60ff16905281546001810183556000928352602092839020825180519394600390930290910192610f769284920190614be9565b506020828101518051610f8f9260018501920190614be9565b506040828101516002929092018054606085015160809095015161ffff1990911693151561ff0019169390931761010094151585021762ff000019166201000060ff90941693909302929092179091559054600092835261010160205291205580610ff9816152e8565b915050610cce565b50505050505050505050565b6000600260c954141561103b5760405162461bcd60e51b815260040161103290615303565b60405180910390fd5b600260c95560335460ff16156110635760405162461bcd60e51b81526004016110329061533a565b61108d8242106040518060400160405280600681526020016555535230303160d01b815250612ca6565b6110b860003411604051806040016040528060068152602001652aa9a918181960d11b815250612ca6565b6110c134612cc5565b60fc54604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa15801561110b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061112f919061522a565b9050600061113b611228565b9050600061114a346001615364565b9050811561116a578161115d3485615364565b6111679190615399565b90505b61119586821015604051806040016040528060068152602001651554d48c0c0d60d21b815250612ca6565b60fc546040516340c10f1960e01b8152336004820152602481018390526001600160a01b03909116906340c10f1990604401600060405180830381600087803b1580156111e157600080fd5b505af11580156111f5573d6000803e3d6000fd5b5050505034610103600082825461120c91906153ad565b9091555061121a9050612ce8565b600160c95595945050505050565b600061010c546101055461010a54610104546101035461124891906153ad565b61125291906153ad565b61125c91906153c5565b61126691906153c5565b905090565b60008281526097602052604090206001015461128681612c9c565b6112908383612d9c565b505050565b6001600160a01b03811633146113055760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401611032565b61130f8282612e22565b5050565b61131b612ce8565b565b606080808061132c86866153c5565b6001600160401b03811115611343576113436153dc565b60405190808252806020026020018201604052801561137657816020015b60608152602001906001900390816113615790505b50935061138386866153c5565b6001600160401b0381111561139a5761139a6153dc565b6040519080825280602002602001820160405280156113cd57816020015b60608152602001906001900390816113b85790505b5092506113da86866153c5565b6001600160401b038111156113f1576113f16153dc565b60405190808252806020026020018201604052801561141a578160200160208202803683370190505b50915061142786866153c5565b6001600160401b0381111561143e5761143e6153dc565b604051908082528060200260200182016040528015611467578160200160208202803683370190505b5090506000865b868110156116d857610100818154811061148a5761148a615243565b906000526020600020906003020160000180546114a6906153f2565b80601f01602080910402602001604051908101604052809291908181526020018280546114d2906153f2565b801561151f5780601f106114f45761010080835404028352916020019161151f565b820191906000526020600020905b81548152906001019060200180831161150257829003601f168201915b505050505086838151811061153657611536615243565b6020026020010181905250610100818154811061155557611555615243565b90600052602060002090600302016001018054611571906153f2565b80601f016020809104026020016040519081016040528092919081815260200182805461159d906153f2565b80156115ea5780601f106115bf576101008083540402835291602001916115ea565b820191906000526020600020905b8154815290600101906020018083116115cd57829003601f168201915b505050505085838151811061160157611601615243565b6020026020010181905250610100818154811061162057611620615243565b906000526020600020906003020160020160009054906101000a900460ff1684838151811061165157611651615243565b602002602001019015159081151581525050610100818154811061167757611677615243565b906000526020600020906003020160020160019054906101000a900460ff168383815181106116a8576116a8615243565b91151560209283029190910190910152816116c2816152e8565b92505080806116d0906152e8565b91505061146e565b505092959194509250565b7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a61170d81612c9c565b611715612e89565b50565b6000611266612f1c565b6000805160206156f983398151915261173a81612c9c565b60408051808201909152600681526553595330303760d01b60208201526117649085841490612ca6565b8360005b818110156119ae576117876030888884818110610ced57610ced615243565b61179e6060868684818110610d3d57610d3d615243565b60008787838181106117b2576117b2615243565b90506020028101906117c49190615259565b6040516117d29291906152c2565b6040518091039020905061181b6101016000838152602001908152602001600020546000146040518060400160405280600681526020016553595330303560d01b815250612ca6565b6101006040518060a001604052808a8a8681811061183b5761183b615243565b905060200281019061184d9190615259565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509082525060200188888681811061189957611899615243565b90506020028101906118ab9190615259565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092018290525093855250505060208083018290526001604084018190526060909301829052845492830185559381528390208251805193946003909302909101926119239284920190614be9565b50602082810151805161193c9260018501920190614be9565b506040828101516002929092018054606085015160809095015161ffff1990911693151561ff0019169390931761010094151585021762ff000019166201000060ff909416939093029290921790915590546000928352610101602052912055806119a6816152e8565b915050611768565b50505050505050565b6000805160206156f98339815191526119cf81612c9c565b60408051808201909152600681526553595330303760d01b60208201526119f99088871490612ca6565b60408051808201909152600681526553595330303760d01b6020820152611a23908a891490612ca6565b60408051808201909152600681526553595330303760d01b6020820152611a4d9088841490612ca6565b8660005b81811015611ca257611a7060308d8d84818110610ced57610ced615243565b611a8760308b8b84818110610ced57610ced615243565b611a9e6060898984818110610d3d57610d3d615243565b60008c8c83818110611ab257611ab2615243565b9050602002810190611ac49190615259565b604051611ad29291906152c2565b60405180910390209050611b1b6000610101600084815260200190815260200160002054116040518060400160405280600681526020016529aca998181b60d11b815250612ca6565b60008181526101016020526040812054611b37906001906153c5565b6000838152610101602052604081208190559091508c8c85818110611b5e57611b5e615243565b9050602002810190611b709190615259565b604051611b7e9291906152c2565b6040518091039020905060006101008381548110611b9e57611b9e615243565b906000526020600020906003020190508d8d86818110611bc057611bc0615243565b9050602002810190611bd29190615259565b611bdd918391614c69565b508b8b86818110611bf057611bf0615243565b9050602002810190611c029190615259565b611c10916001840191614c69565b5060028101805461ff0019166101008c151502179055888886818110611c3857611c38615243565b9050602002016020810190611c4d919061529f565b60028201805460ff92909216620100000262ff000019909216919091179055611c778360016153ad565b600092835261010160205260409092209190915550829150611c9a9050816152e8565b915050611a51565b505050505050505050505050565b6101008181548110611cc157600080fd5b9060005260206000209060030201600091509050806000018054611ce4906153f2565b80601f0160208091040260200160405190810160405280929190818152602001828054611d10906153f2565b8015611d5d5780601f10611d3257610100808354040283529160200191611d5d565b820191906000526020600020905b815481529060010190602001808311611d4057829003601f168201915b505050505090806001018054611d72906153f2565b80601f0160208091040260200160405190810160405280929190818152602001828054611d9e906153f2565b8015611deb5780601f10611dc057610100808354040283529160200191611deb565b820191906000526020600020905b815481529060010190602001808311611dce57829003601f168201915b5050506002909301549192505060ff808216916101008104821691620100009091041685565b6000611e1c81612c9c565b611e496103e8831115604051806040016040528060068152602001650a6b2a66060760d31b815250612ca6565b60fe8290556040518281527f4de90ec86e1bc56c192e2399bacbd10bdaba720caca606354d66c5cb33d6802b906020015b60405180910390a15050565b7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a611eb081612c9c565b611715612fe5565b61131b610112546801a055690d9db8000061303d565b7f241ecf16d79d0f8dbfb92cbc07fe17840425976cf0667f022fe9877caa831b08611ef881612c9c565b60fc546040516370a0823160e01b815230600482015261130f9184916001600160a01b03909116906370a0823190602401602060405180830381865afa158015611f46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f6a919061522a565b60fc546001600160a01b03169190613269565b6000611f8881612c9c565b60fb80546001600160a01b0319166001600160a01b0384169081179091556040519081527f1781ac9526b978975dba0fd26a33e044a55a7ace054a3ee7efa5f8459513bead90602001611e7a565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b600260c95414156120245760405162461bcd60e51b815260040161103290615303565b600260c9557f68e79a7bf1e0bc45d0a330c573bc367f9cf464fd326078812f301165fbda4ef161205381612c9c565b6120808261011254146040518060400160405280600681526020016529aca998189960d11b815250612ca6565b60006120956801bc16d674ec80000085615364565b90506120c5600086869050116040518060400160405280600681526020016553595330313760d01b815250612ca6565b610102546101145461210291906120dc90876153ad565b1115604051806040016040528060068152602001650a6b2a66062760d31b815250612ca6565b612133858590506101105410156040518060400160405280600681526020016553595330313960d01b815250612ca6565b60005b8481101561228157600086868381811061215257612152615243565b90506020028101906121649190615259565b6040516121729291906152c2565b604051809103902090506121bb6000610101600084815260200190815260200160002054116040518060400160405280600681526020016529aca998181b60d11b815250612ca6565b600081815261010160205260408120546121d7906001906153c5565b905061223461010082815481106121f0576121f0615243565b906000526020600020906003020160020160009054906101000a900460ff16156040518060400160405280600681526020016505359533032360d41b815250612ca6565b6001610100828154811061224a5761224a615243565b60009182526020909120600390910201600201805460ff191691151591909117905550819050612279816152e8565b915050612136565b5084849050610114600082825461229891906153ad565b909155505061011780548591906000906122b39084906153ad565b909155505061011080548591906000906122ce9084906153c5565b90915550506040518481527ff25558665a382a9abb684f20b20021df5923b51485bbf2829ff0089b5b2714109060200160405180910390a161230e6132bb565b5050600160c955505050565b7f68e79a7bf1e0bc45d0a330c573bc367f9cf464fd326078812f301165fbda4ef161234481612c9c565b611290838361303d565b60008281526097602052604090206001015461236981612c9c565b6112908383612e22565b600061237e81612c9c565b60ff8290556040518281527f690facbfacb53c9319489117a6ac422718b5cb059a6ffade4871ff10f6f9aee990602001611e7a565b6000805160206156f98339815191526123cb81612c9c565b60408051808201909152600681526553595330303760d01b60208201526123f59085841490612ca6565b8360005b818110156119ae576124186030888884818110610ced57610ced615243565b61242f6060868684818110610d3d57610d3d615243565b600087878381811061244357612443615243565b90506020028101906124559190615259565b6040516124639291906152c2565b604051809103902090506124ac6101016000838152602001908152602001600020546000146040518060400160405280600681526020016553595330303560d01b815250612ca6565b6101006040518060a001604052808a8a868181106124cc576124cc615243565b90506020028101906124de9190615259565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509082525060200188888681811061252a5761252a615243565b905060200281019061253c9190615259565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092018290525093855250505060208083018290526040830182905260609092018190528354600181018555938152819020825180519394600302909101926125b19284920190614be9565b5060208281015180516125ca9260018501920190614be9565b506040828101516002929092018054606085015160809095015161ffff1990911693151561ff0019169390931761010094151585021762ff000019166201000060ff90941693909302929092179091559054600092835261010160205291205580612634816152e8565b9150506123f9565b6060808061264a85856153c5565b6001600160401b03811115612661576126616153dc565b60405190808252806020026020018201604052801561269457816020015b606081526020019060019003908161267f5790505b5092506126a185856153c5565b6001600160401b038111156126b8576126b86153dc565b6040519080825280602002602001820160405280156126eb57816020015b60608152602001906001900390816126d65790505b5091506126f885856153c5565b6001600160401b0381111561270f5761270f6153dc565b604051908082528060200260200182016040528015612738578160200160208202803683370190505b5090506000855b8581101561295257610100818154811061275b5761275b615243565b90600052602060002090600302016000018054612777906153f2565b80601f01602080910402602001604051908101604052809291908181526020018280546127a3906153f2565b80156127f05780601f106127c5576101008083540402835291602001916127f0565b820191906000526020600020905b8154815290600101906020018083116127d357829003601f168201915b505050505085838151811061280757612807615243565b6020026020010181905250610100818154811061282657612826615243565b90600052602060002090600302016001018054612842906153f2565b80601f016020809104026020016040519081016040528092919081815260200182805461286e906153f2565b80156128bb5780601f10612890576101008083540402835291602001916128bb565b820191906000526020600020905b81548152906001019060200180831161289e57829003601f168201915b50505050508483815181106128d2576128d2615243565b602002602001018190525061010081815481106128f1576128f1615243565b906000526020600020906003020160020160009054906101000a900460ff1683838151811061292257612922615243565b911515602092830291909101909101528161293c816152e8565b925050808061294a906152e8565b91505061273f565b50509250925092565b6000600260c95414156129805760405162461bcd60e51b815260040161103290615303565b600260c9819055506129b28242106040518060400160405280600681526020016555535230303160d01b815250612ca6565b6129ef6129c86801bc16d674ec8000008661542d565b6000146040518060400160405280600681526020016555535230303560d01b815250612ca6565b612a1a600085116040518060400160405280600681526020016555535230303560d01b815250612ca6565b60fc54604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa158015612a64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a88919061522a565b90506000612a94611228565b612a9e8784615364565b612aa89190615399565b9050612ad585821115604051806040016040528060068152602001651554d48c0c0d60d21b815250612ca6565b60fc5460405163079cc67960e41b8152336004820152602481018390526001600160a01b03909116906379cc679090604401600060405180830381600087803b158015612b2157600080fd5b505af1158015612b35573d6000803e3d6000fd5b50505050612b433387613310565b612b566801bc16d674ec80000087615399565b6101106000828254612b6891906153ad565b9091555050600160c95595945050505050565b600080612b87836133f2565b91509150915091565b600260c9541415612bb35760405162461bcd60e51b815260040161103290615303565b600260c95560335460ff1615612bdb5760405162461bcd60e51b81526004016110329061533a565b600080612be7836133f2565b60fc5460405163079cc67960e41b8152336004820152602481018390529294509092506001600160a01b0316906379cc679090604401600060405180830381600087803b158015612c3757600080fd5b505af1158015612c4b573d6000803e3d6000fd5b50505050816101036000828254612c6291906153c5565b90915550612c719050826134cb565b612c7b33836134e6565b5050600160c95550565b61131b6135ff565b6001600160a01b03163b151590565b6117158133613713565b80826112905760405162461bcd60e51b81526004016110329190615441565b612cce81613777565b61010f6000828254612ce09190615454565b909155505050565b60006801bc16d674ec80000061010354612d029190615399565b6101005461010254919250600091612d1b9084906153ad565b1115612d38576101025461010054612d3391906153c5565b612d3a565b815b905060005b81811015612d6157612d4f6137e5565b80612d59816152e8565b915050612d3f565b50801561130f577fe2a191ee805447bcf5adabadd39cb816b1b46de1364263aef69980bdafd8370f61010254604051611e7a91815260200190565b612da68282611fd6565b61130f5760008281526097602090815260408083206001600160a01b03851684529091529020805460ff19166001179055612dde3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b612e2c8282611fd6565b1561130f5760008281526097602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60335460ff16612ed25760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401611032565b6033805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60008060fc60009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f72573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f96919061522a565b905080612fb657612fb0670de0b6b3a76400006001615364565b91505090565b600081670de0b6b3a7640000612fca611228565b612fd49190615364565b612fde9190615399565b9392505050565b60335460ff16156130085760405162461bcd60e51b81526004016110329061533a565b6033805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612eff3390565b61306a8261011254146040518060400160405280600681526020016529aca998189960d11b815250612ca6565b6130726135ff565b600061013d5461010e5461308691906153ad565b90506000610114546101025461309c91906153c5565b905061010d5461011754826130b191906153ad565b11156130f957600061010d5461011754836130cc91906153ad565b6130d691906153c5565b90506130eb6801bc16d674ec80000082615364565b6130f590846153ad565b9250505b600061310e6801bc16d674ec80000083615364565b9050600061013c60009054906101000a90046001600160a01b03166001600160a01b03166399cba0746040518163ffffffff1660e01b8152600401602060405180830381865afa158015613166573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318a919061522a565b90506131d0846101115483856131a091906153ad565b6131aa91906153ad565b10156040518060400160405280600681526020016553595330313560d01b815250612ca6565b6000846101115483856131e391906153ad565b6131ed91906153ad565b6131f791906153c5565b9050613224868211156040518060400160405280600681526020016529aca998189b60d11b815250612ca6565b61322d81613aca565b613235613b53565b61323d613bfa565b613245613d90565b5061010e9190915561010d9190915561013d55505060006101118190556101175550565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052611290908490613e3c565b61011380549060006132cc836152e8565b909155505061011254610113546040805160208101939093524290830152606082015260800160408051601f19818403018152919052805160209091012061011255565b6001610108600082825461332491906153ad565b90915550506040805180820182526001600160a01b0384811680835260208084018681526101085460009081526101068352868120955186546001600160a01b031916951694909417855551600190940193909355815261010990915290812080548392906133949084906153ad565b925050819055508061010560008282546133ae91906153ad565b9091555050604080516001600160a01b0384168152602081018390527f889f3b08db1ce169841b4f7e2aadfe4298088b1bce57b31fecae3260dd4358299101611e7a565b600080600060fc60009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561344a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061346e919061522a565b9050600061347a611228565b90506000826134898388615364565b6134939190615399565b90506101035481116134a557806134aa565b610103545b9450816134b78685615364565b6134c19190615399565b9350505050915091565b6134d481613777565b61010f6000828254612ce09190615495565b804710156135365760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401611032565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114613583576040519150601f19603f3d011682016040523d82523d6000602084013e613588565b606091505b50509050806112905760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401611032565b61013c60009054906101000a90046001600160a01b03166001600160a01b031663a2e620456040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561365057600080fd5b505af1158015613664573d6000803e3d6000fd5b5050505061010f5461367547613777565b1215613683576136836154d4565b60006136a461010f5461369547613777565b61369f9190615495565b613f0e565b90508015611715576136b547613777565b61010f819055508061011160008282546136cf91906153ad565b909155506136dd90506132bb565b6040518181527fe7948c33eb604391785037114655100edf93283c25b69884e9238ae197f078179060200160405180910390a150565b61371d8282611fd6565b61130f57613735816001600160a01b03166014613f60565b613740836020613f60565b6040516020016137519291906154ea565b60408051601f198184030181529082905262461bcd60e51b825261103291600401615441565b60006001600160ff1b038211156137e15760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608401611032565b5090565b600061010061010254815481106137fe576137fe615243565b90600052602060002090600302016040518060a0016040529081600082018054613827906153f2565b80601f0160208091040260200160405190810160405280929190818152602001828054613853906153f2565b80156138a05780601f10613875576101008083540402835291602001916138a0565b820191906000526020600020905b81548152906001019060200180831161388357829003601f168201915b505050505081526020016001820180546138b9906153f2565b80601f01602080910402602001604051908101604052809291908181526020018280546138e5906153f2565b80156139325780601f1061390757610100808354040283529160200191613932565b820191906000526020600020905b81548152906001019060200180831161391557829003601f168201915b50505091835250506002919091015460ff808216151560208401526101008204811615156040840152620100009091041660609182015281015190915061398d576139888160000151826020015160ff546140fb565b613a75565b61013c546080820151604051636a93ee0f60e01b815260ff90911660048201526000916001600160a01b031690636a93ee0f90602401602060405180830381865afa1580156139e0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a04919061555f565b60408051600b808252818301909252919250600091600160f81b916020820181803683375050604051613a3e93929150859060200161557c565b60405160208183030381529060405290506000613a5c826000614539565b9050613a7184600001518560200151836140fb565b5050505b6101028054906000613a86836152e8565b91905055506801bc16d674ec8000006101046000828254613aa791906153ad565b925050819055506801bc16d674ec8000006101036000828254612ce091906153c5565b60006103e860fe5483613add9190615364565b613ae79190615399565b90508061010b6000828254613afc91906153ad565b90915550613b0c905081836153c5565b61010a6000828254613b1e91906153ad565b90915550506040518281527f82f24840c0f58d92529afdd441950ddc6e8f2d60138d4458a8d74ba367540cda90602001611e7a565b60006801bc16d674ec8000006101035447613b6e91906153c5565b613b789190615399565b613b8b906801bc16d674ec800000615364565b90506000816101055410613b9f5781613ba4565b610105545b9050801561130f576000613bb6612f1c565b90506000613bc383614597565b9050806101046000828254613bd891906153c5565b90915550613be69050612f1c565b8214613bf457613bf46154d4565b50505050565b60006101035447613c0b91906153c5565b9050600061010b548210613c225761010b54613c24565b815b9050801561130f5760fc54604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa158015613c76573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c9a919061522a565b90506000613ca6611228565b9050600081613cb58585615364565b613cbf9190615399565b60fc546040516340c10f1960e01b8152306004820152602481018390529192506001600160a01b0316906340c10f1990604401600060405180830381600087803b158015613d0c57600080fd5b505af1158015613d20573d6000803e3d6000fd5b50505050836101036000828254613d3791906153ad565b925050819055508361010b6000828254613d5191906153c5565b90915550506040518481527f20af1949d4837141c257165539bba8e24981f6d6c45872735b01fbf85848e5db9060200160405180910390a15050505050565b600061010c5461010a54613da491906153c5565b905060006101035447613db791906153c5565b90506000818310613dc85781613dca565b825b9050801561129057806101036000828254613de591906153ad565b925050819055508061010c6000828254613dff91906153ad565b90915550506040518181527f0605699e1cc0752b1c63cb9863a6f07f7ff8f525c69391ab42f8af6b14d9a2bf9060200160405180910390a1505050565b6000613e91826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146fa9092919063ffffffff16565b8051909150156112905780806020019051810190613eaf91906155cb565b6112905760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401611032565b6000808212156137e15760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152606401611032565b60606000613f6f836002615364565b613f7a9060026153ad565b6001600160401b03811115613f9157613f916153dc565b6040519080825280601f01601f191660200182016040528015613fbb576020820181803683370190505b509050600360fc1b81600081518110613fd657613fd6615243565b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061400557614005615243565b60200101906001600160f81b031916908160001a9053506000614029846002615364565b6140349060016153ad565b90505b60018111156140ac576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061406857614068615243565b1a60f81b82828151811061407e5761407e615243565b60200101906001600160f81b031916908160001a90535060049490941c936140a5816155e8565b9050614037565b508315612fde5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401611032565b60408051808201909152600681526514d654cc0c8d60d21b60208201526141259082151590612ca6565b6801bc16d674ec800000600061413f633b9aca0083615399565b905081614150633b9aca0083615364565b1461415d5761415d6154d4565b6000600286600060801b6040516020016141789291906155ff565b60408051601f198184030181529082905261419291615637565b602060405180830381855afa1580156141af573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906141d2919061522a565b905060006002806141e68860006040614711565b6040516141f39190615637565b602060405180830381855afa158015614210573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190614233919061522a565b600261424b8960406142468160606153c5565b614711565b60405161425e9190600090602001615653565b60408051601f198184030181529082905261427891615637565b602060405180830381855afa158015614295573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906142b8919061522a565b60408051602081019390935282015260600160408051601f19818403018152908290526142e491615637565b602060405180830381855afa158015614301573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190614324919061522a565b905060006143318461481e565b905060006002808589604051602001614354929190918252602082015260400190565b60408051601f198184030181529082905261436e91615637565b602060405180830381855afa15801561438b573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906143ae919061522a565b6040516002906143c79086906000908990602001615675565b60408051601f19818403018152908290526143e191615637565b602060405180830381855afa1580156143fe573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190614421919061522a565b60408051602081019390935282015260600160408051601f198184030181529082905261444d91615637565b602060405180830381855afa15801561446a573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525081019061448d919061522a565b60fb546040805160208082018c905282518083039091018152818301928390526304512a2360e31b9092529293506001600160a01b03909116916322895118916801bc16d674ec800000916144ea918e918e9088906044016156ad565b6000604051808303818588803b15801561450357600080fd5b505af1158015614517573d6000803e3d6000fd5b505050505061452e6801bc16d674ec8000006134cb565b505050505050505050565b60006145468260206153ad565b8351101561458e5760405162461bcd60e51b8152602060048201526015602482015274746f427974657333325f6f75744f66426f756e647360581b6044820152606401611032565b50016020015190565b610107546000905b6101085481116146d257826145b3576146d2565b60008181526101066020526040812060018101549091908510156145d757846145dd565b81600101545b9050808260010160008282546145f391906153c5565b90915550614603905081866153c5565b82546001600160a01b0316600090815261010960205260408120805492975083929091906146329084906153c5565b90915550614642905081856153ad565b60fd548354604051630c11dedd60e01b81526001600160a01b0391821660048201529296501690630c11dedd9083906024016000604051808303818588803b15801561468d57600080fd5b505af11580156146a1573d6000803e3d6000fd5b50505050508160010154600014156146bd576146bb6149d2565b505b505080806146ca906152e8565b91505061459f565b508061010560008282546146e691906153c5565b909155506146f59050816134cb565b919050565b60606147098484600085614a88565b949350505050565b60608161471f81601f6153ad565b101561475e5760405162461bcd60e51b815260206004820152600e60248201526d736c6963655f6f766572666c6f7760901b6044820152606401611032565b61476882846153ad565b845110156147ac5760405162461bcd60e51b8152602060048201526011602482015270736c6963655f6f75744f66426f756e647360781b6044820152606401611032565b6060821580156147cb5760405191506000825260208201604052614815565b6040519150601f8416801560200281840101858101878315602002848b0101015b818310156148045780518352602092830192016147ec565b5050858452601f01601f1916604052505b50949350505050565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b8260008151811061485e5761485e615243565b60200101906001600160f81b031916908160001a9053508060061a60f81b8260018151811061488f5761488f615243565b60200101906001600160f81b031916908160001a9053508060051a60f81b826002815181106148c0576148c0615243565b60200101906001600160f81b031916908160001a9053508060041a60f81b826003815181106148f1576148f1615243565b60200101906001600160f81b031916908160001a9053508060031a60f81b8260048151811061492257614922615243565b60200101906001600160f81b031916908160001a9053508060021a60f81b8260058151811061495357614953615243565b60200101906001600160f81b031916908160001a9053508060011a60f81b8260068151811061498457614984615243565b60200101906001600160f81b031916908160001a9053508060001a60f81b826007815181106149b5576149b5615243565b60200101906001600160f81b031916908160001a90535050919050565b6040805180820190915260008082526020820152614a17610107546101085410156040518060400160405280600681526020016529aca998191960d11b815250612ca6565b506101078054600081815261010660208181526040808420815180830190925280546001600160a01b03811683526001808301805485870152978752949093526001600160a01b031990921690915592829055835492939092909190614a7e9084906153ad565b9250508190555090565b606082471015614ae95760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401611032565b843b614b375760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401611032565b600080866001600160a01b03168587604051614b539190615637565b60006040518083038185875af1925050503d8060008114614b90576040519150601f19603f3d011682016040523d82523d6000602084013e614b95565b606091505b5091509150614ba5828286614bb0565b979650505050505050565b60608315614bbf575081612fde565b825115614bcf5782518084602001fd5b8160405162461bcd60e51b81526004016110329190615441565b828054614bf5906153f2565b90600052602060002090601f016020900481019282614c175760008555614c5d565b82601f10614c3057805160ff1916838001178555614c5d565b82800160010185558215614c5d579182015b82811115614c5d578251825591602001919060010190614c42565b506137e1929150614cdd565b828054614c75906153f2565b90600052602060002090601f016020900481019282614c975760008555614c5d565b82601f10614cb05782800160ff19823516178555614c5d565b82800160010185558215614c5d579182015b82811115614c5d578235825591602001919060010190614cc2565b5b808211156137e15760008155600101614cde565b600060208284031215614d0457600080fd5b81356001600160e01b031981168114612fde57600080fd5b60008083601f840112614d2e57600080fd5b5081356001600160401b03811115614d4557600080fd5b6020830191508360208260051b8501011115614d6057600080fd5b9250929050565b60008060008060008060608789031215614d8057600080fd5b86356001600160401b0380821115614d9757600080fd5b614da38a838b01614d1c565b90985096506020890135915080821115614dbc57600080fd5b614dc88a838b01614d1c565b90965094506040890135915080821115614de157600080fd5b50614dee89828a01614d1c565b979a9699509497509295939492505050565b60008060408385031215614e1357600080fd5b50508035926020909101359150565b600060208284031215614e3457600080fd5b5035919050565b6001600160a01b038116811461171557600080fd5b60008060408385031215614e6357600080fd5b823591506020830135614e7581614e3b565b809150509250929050565b60005b83811015614e9b578181015183820152602001614e83565b83811115613bf45750506000910152565b60008151808452614ec4816020860160208601614e80565b601f01601f19169290920160200192915050565b600082825180855260208086019550808260051b84010181860160005b84811015614f2357601f19868403018952614f11838351614eac565b98840198925090830190600101614ef5565b5090979650505050505050565b600081518084526020808501945080840160005b83811015614f62578151151587529582019590820190600101614f44565b509495945050505050565b608081526000614f806080830187614ed8565b8281036020840152614f928187614ed8565b90508281036040840152614fa68186614f30565b90508281036060840152614ba58185614f30565b60008060008060408587031215614fd057600080fd5b84356001600160401b0380821115614fe757600080fd5b614ff388838901614d1c565b9096509450602087013591508082111561500c57600080fd5b5061501987828801614d1c565b95989497509550505050565b801515811461171557600080fd5b600080600080600080600080600060a08a8c03121561505157600080fd5b89356001600160401b038082111561506857600080fd5b6150748d838e01614d1c565b909b50995060208c013591508082111561508d57600080fd5b6150998d838e01614d1c565b909950975060408c01359150808211156150b257600080fd5b6150be8d838e01614d1c565b909750955060608c013591506150d382615025565b90935060808b013590808211156150e957600080fd5b506150f68c828d01614d1c565b915080935050809150509295985092959850929598565b60a08152600061512060a0830188614eac565b82810360208401526151328188614eac565b95151560408401525050911515606083015260ff1660809091015292915050565b60006020828403121561516557600080fd5b8135612fde81614e3b565b60008060006040848603121561518557600080fd5b83356001600160401b0381111561519b57600080fd5b6151a786828701614d1c565b909790965060209590950135949350505050565b6060815260006151ce6060830186614ed8565b82810360208401526151e08186614ed8565b905082810360408401526151f48185614f30565b9695505050505050565b60008060006060848603121561521357600080fd5b505081359360208301359350604090920135919050565b60006020828403121561523c57600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261527057600080fd5b8301803591506001600160401b0382111561528a57600080fd5b602001915036819003821315614d6057600080fd5b6000602082840312156152b157600080fd5b813560ff81168114612fde57600080fd5b8183823760009101908152919050565b634e487b7160e01b600052601160045260246000fd5b60006000198214156152fc576152fc6152d2565b5060010190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b600081600019048311821515161561537e5761537e6152d2565b500290565b634e487b7160e01b600052601260045260246000fd5b6000826153a8576153a8615383565b500490565b600082198211156153c0576153c06152d2565b500190565b6000828210156153d7576153d76152d2565b500390565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061540657607f821691505b6020821081141561542757634e487b7160e01b600052602260045260246000fd5b50919050565b60008261543c5761543c615383565b500690565b602081526000612fde6020830184614eac565b600080821280156001600160ff1b0384900385131615615476576154766152d2565b600160ff1b839003841281161561548f5761548f6152d2565b50500190565b60008083128015600160ff1b8501841216156154b3576154b36152d2565b6001600160ff1b03840183138116156154ce576154ce6152d2565b50500390565b634e487b7160e01b600052600160045260246000fd5b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351615522816017850160208801614e80565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615553816028840160208801614e80565b01602801949350505050565b60006020828403121561557157600080fd5b8151612fde81614e3b565b6001600160f81b031984168152825160009061559f816001850160208801614e80565b60609390931b6bffffffffffffffffffffffff1916600192909301918201929092526015019392505050565b6000602082840312156155dd57600080fd5b8151612fde81615025565b6000816155f7576155f76152d2565b506000190190565b60008351615611818460208801614e80565b6fffffffffffffffffffffffffffffffff19939093169190920190815260100192915050565b60008251615649818460208701614e80565b9190910192915050565b60008351615665818460208801614e80565b9190910191825250602001919050565b60008451615687818460208901614e80565b67ffffffffffffffff199490941691909301908152601881019190915260380192915050565b6080815260006156c06080830187614eac565b82810360208401526156d28187614eac565b905082810360408401526156e68186614eac565b9150508260608301529594505050505056fec2979137d1774e40fe2638d355bf7a7b092be4c67f242aad1655e1e27f9df9cca2646970667358221220f19a60604df3b98d288117c16d4bbbe21f928c773784fe17b39a0c0f97b213d364736f6c634300080c0033

Verified Source Code Partial Match

Compiler: v0.8.12+commit.f00d7308 EVM: istanbul Optimization: Yes (200 runs)
iface.sol 62 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "IERC20.sol";

interface IMintableContract is IERC20 {
    function mint(address account, uint256 amount) external;
    function burn(uint256 amount) external;
    function burnFrom(address account, uint256 amount) external;
}

// This interface is designed to be compatible with the Vyper version.
/// @notice This is the Ethereum 2.0 deposit contract interface.
/// For more information see the Phase 0 specification under https://github.com/ethereum/eth2.0-specs
interface IDepositContract {
    /// @notice A processed deposit event.
    event DepositEvent(
        bytes pubkey,
        bytes withdrawal_credentials,
        bytes amount,
        bytes signature,
        bytes index
    );

    /// @notice Submit a Phase 0 DepositData object.
    /// @param pubkey A BLS12-381 public key.
    /// @param withdrawal_credentials Commitment to a public key for withdrawals.
    /// @param signature A BLS12-381 signature.
    /// @param deposit_data_root The SHA-256 hash of the SSZ-encoded DepositData object.
    /// Used as a protection against malformed input.
    function deposit(
        bytes calldata pubkey,
        bytes calldata withdrawal_credentials,
        bytes calldata signature,
        bytes32 deposit_data_root
    ) external payable;

    /// @notice Query the current deposit root hash.
    /// @return The deposit root hash.
    function get_deposit_root() external view returns (bytes32);

    /// @notice Query the current deposit count.
    /// @return The deposit count encoded as a little endian 64-bit number.
    function get_deposit_count() external view returns (bytes memory);
}

interface IRedeem {
    function pay(address account) external payable;
}

interface IRestaking {
    function update() external;
    function getPendingWithdrawalAmount() external view returns (uint256);
    function eigenPod() external view returns (address);
    function getPod(uint256 i) external view returns (address);
    function getTotalPods() external view returns (uint256);
}

interface IPodOwner {
    function transfer(address target, uint256 amount) external;
    function execute(address target, bytes memory data) external returns(bytes memory);
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @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);
}
Address.sol 217 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // 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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
staking.sol 1095 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "iface.sol";
import "BytesLib.sol";
import "SafeERC20.sol";
import "Initializable.sol";
import "AccessControlUpgradeable.sol";
import "PausableUpgradeable.sol";
import "ReentrancyGuardUpgradeable.sol";
import "SafeCast.sol";


/**
 * @title Bedrock Ethereum 2.0 Staking Contract
 *
 * Description:
 * 
 * ───╔═╦═╗─╔╗╔═╗──────╔╗──╔╗╔╗─╔╦╗╔╗─╔═╗─╔╗───────╔╦╗
 * ╔═╗║═╣═╬═╣╚╣═╣╔══╗╔╗╠╬═╗║╚╬╬╗╠╣╚╬╬═╣═╣╔╝╚╗╔═╦═╦╦╬╣╚╦╦╗
 * ║╬╚╬═╠═║╩╣╔╬═║╠══╣║╚╣║╬╚╣╬║║╚╣║╔╣║╩╬═║╚╗╔╝║╩╣╬║║║║╔╣║║
 * ╚══╩═╩═╩═╩═╩═╝╚══╝╚═╩╩══╩═╩╩═╩╩═╩╩═╩═╝─╚╝─╚═╩╗╠═╩╩═╬╗║
 * ─────────────────────────────────────────────╚╝────╚═╝
 * 
 * Term:
 *  ExchangeRatio:              Exchange Ratio of xETH to ETH, normally >= 1.0
 *  TotalXETH:                  Total Supply of xETH
 *  TotalStaked:                Total Ethers Staked to Validators
 *  TotalDebts:                 Total unpaid debts(generated from redeemFromValidators), 
 *                              awaiting to be paid by turn off validators to clean debts.
 *  TotalPending:               Pending Ethers(<32 Ethers), awaiting to be staked
 *  RewardDebts:                The amount re-staked into TotalPending
 *
 *  AccountedUserRevenue:       Overall Net revenue which belongs to all xETH holders(excluded re-staked amount)
 *  ReportedValidators:         Latest Reported Validator Count
 *  ReportedValidatorBalance:   Latest Reported Validator Overall Balance
 *  RecentReceived:             The Amount this contract receives recently.
 *  CurrentReserve:             Assets Under Management
 *
 * Lemma 1: (AUM)
 *
 *          CurrentReserve = TotalPending + TotalStaked + AccountedUserRevenue - TotalDebts - RewardDebts
 *
 * Lemma 2: (Exchange Ratio)
 *
 *          ExchangeRatio = CurrentReserve / TotalXETH
 *
 * Rule 1: (function mint) For every mint operation, the ethers pays debt in priority the reset will be put in TotalPending(deprecated),
 *          ethersToMint:               The amount user deposits
 *
 *          TotalPending = TotalPending + ethersToMint
 *          TotalXETH = TotalXETH + ethersToMint / ExchangeRatio
 *
 * Rule 2: (function mint) At any time TotalPending has more than 32 Ethers, It will be staked, TotalPending
 *          moves to TotalStaked and keeps TotalPending less than 32 Ether.
 *
 *          TotalPending = TotalPending - ⌊TotalPending/32ETH⌋ * 32ETH
 *          TotalStaked = TotalStaked + ⌊TotalPending/32ETH⌋ * 32ETH
 *
 * Rule 3: (function validatorStopped) Whenever a validator stopped, all value pays debts in priority, then:
 *          valueStopped:               The value sent-back via receive() funtion
 *          amountUnstaked:             The amount of unstaked node (base 32ethers)
 *          validatorStopped:           The count of validator stopped
 *          
 *          incrRewardDebt := valueStopped - amountUnstaked
 *          RewardDebts = RewardDebt + incrRewardDebt
 *          RecentReceived = RecentReceived + valueStopped
 *          TotalPending = TotalPending + Max(0, amountUnstaked - TotalDebts) + incrRewardDebt
 *          TotalStaked = TotalStaked - validatorStopped * 32 ETH
 *
 * Rule 4.1: (function pushBeacon) Oracle push balance, rebase if new validator is alive:
 *          aliveValidator:             The count of validators alive
 *          
 *          RewardBase = ReportedValidatorBalance + Max(0, aliveValidator - ReportedValidators) * 32 ETH
 *
 * Rule 4.2: (function pushBeacon) Oracle push balance, revenue calculation:
 *          aliveBalance:               The balance of current alive validators
 *
 *          r := aliveBalance + RecentReceived - RewardBase
 *          AccountedUserRevenue = AccountedUserRevenue + r * (1000 - managerFeeShare) / 1000
 *          RecentReceived = 0
 *          ReportedValidators = aliveValidator
 *          ReportedValidatorBalance = aliveBalance
 */
contract Staking is Initializable, PausableUpgradeable, AccessControlUpgradeable, ReentrancyGuardUpgradeable {
    using SafeERC20 for IERC20;
    using Address for address payable;
    using Address for address;

    // stored credentials
    struct ValidatorCredential {
        bytes pubkey;
        bytes signature;
        bool stopped;
        bool restaking; // UPDATE(20240115) : flag the validator is using liquid staking address
        uint8 eigenpod; // UPDATE(20240402) : eigenpod id
    }

    // track ether debts to return to async caller
    struct Debt {
        address account;
        uint256 amount;
    }

    /**
        Incorrect storage preservation:

        |Implementation_v0   |Implementation_v1        |
        |--------------------|-------------------------|
        |address _owner      |address _lastContributor | <=== Storage collision!
        |mapping _balances   |address _owner           |
        |uint256 _supply     |mapping _balances        |
        |...                 |uint256 _supply          |
        |                    |...                      |
        Correct storage preservation:

        |Implementation_v0   |Implementation_v1        |
        |--------------------|-------------------------|
        |address _owner      |address _owner           |
        |mapping _balances   |mapping _balances        |
        |uint256 _supply     |uint256 _supply          |
        |...                 |address _lastContributor | <=== Storage extension.
        |                    |...                      |
    */

    // Always extend storage instead of modifying it
    // Variables in implementation v0 
    bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE");
    bytes32 public constant ORACLE_ROLE = keccak256("ORACLE_ROLE");
    bytes32 public constant REGISTRY_ROLE = keccak256("REGISTRY_ROLE");
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
    uint256 public constant DEPOSIT_SIZE = 32 ether;
    uint256 public constant SAFE_PUSH_REWARDS = 30 ether;

    uint256 private constant MULTIPLIER = 1e18; 
    uint256 private constant DEPOSIT_AMOUNT_UNIT = 1000000000 wei;
    uint256 private constant SIGNATURE_LENGTH = 96;
    uint256 private constant PUBKEY_LENGTH = 48;

    address public ethDepositContract;      // ETH 2.0 Deposit contract
    address public xETHAddress;             // xETH token address
    address public redeemContract;          // redeeming contract for user to pull ethers

    uint256 public managerFeeShare;         // manager's fee in 1/1000
    bytes32 public withdrawalCredentials;   // WithdrawCredential for all validator

    // credentials, pushed by owner
    ValidatorCredential [] public validatorRegistry;
    mapping(bytes32 => uint256) private pubkeyIndices; // indices of validatorRegistry by pubkey hash, starts from 1

    // next validator id
    uint256 private nextValidatorId;

    // exchange ratio related variables
    // track user deposits & redeem (xETH mint & burn)
    uint256 private totalPending;           // track pending ethers awaiting to be staked to validators
    uint256 private totalStaked;            // track current staked ethers for validators, rounded to 32 ethers
    uint256 private totalDebts;             // track current unpaid debts

    // FIFO of debts from redeemFromValidators
    mapping(uint256=>Debt) private etherDebts;
    uint256 private firstDebt;
    uint256 private lastDebt;
    mapping(address=>uint256) private userDebts;    // debts from user's perspective

    // track revenue from validators to form exchange ratio
    uint256 private accountedUserRevenue;           // accounted shared user revenue
    uint256 private accountedManagerRevenue;        // accounted manager's revenue
    uint256 private rewardDebts;                    // check validatorStopped function

    // revenue related variables
    // track beacon validator & balance
    uint256 private reportedValidators;
    uint256 private reportedValidatorBalance;

    // balance tracking
    int256 private accountedBalance;                // tracked balance change in functions,
                                                    // NOTE(x): balance might be negative for not accounting validators's redeeming

    uint256 private maxToStop;                      // set max validators to stop (20240530)
    uint256 private recentReceived;                 // track recently received (un-accounted) value into this contract
    bytes32 private vectorClock;                    // a vector clock for detecting receive() & pushBeacon() causality violations
    uint256 private vectorClockTicks;               // record current vector clock step;

    // track stopped validators
    uint256 private stoppedValidators;              // track stopped validators count

    // phase switch from 0 to 1
    uint256 private __DEPRECATED_phase;

    // gas refunds
    uint256 [] private refunds;

    // PATCH VARIABLES(UPGRADES)
    uint256 private recentStopped;                  // track recent stopped validators(update: 20220927)

    /**
     * @dev empty reserved space for future adding of variables
     */
    uint256[31] private __gap;

    // KYC control
    mapping(address=>uint256) __DEPRECATED_quotaUsed;
    mapping(address=>bool) __DEPRECATED_whiteList;

    // auto-compounding
    bool private __DEPRECATED_autoCompoundEnabled;

    // DEPRECATED(20240130): eigenlayer's restaking withdrawal credential
    bytes32 private __DEPRECATED_restakingWithdrawalCredentials;
    address private __DEPRECATED_restakingAddress;

    // UPDATE(20240130): use variable instead of constant, require upgradeAndCall to set it's value
    address public restakingContract;

    // UPDATE(20240405): record latest unrealized profits
    uint256 private reportedUnrealizedProfits;

    /** 
     * ======================================================================================
     * 
     * SYSTEM SETTINGS, OPERATED VIA OWNER(DAO/TIMELOCK)
     * 
     * ======================================================================================
     */
    receive() external payable { }
    constructor() { _disableInitializers(); }

    /**
     * @dev pause the contract
     */
    function pause() public onlyRole(PAUSER_ROLE) {
        _pause();
    }

    /**
     * @dev unpause the contract
     */
    function unpause() public onlyRole(PAUSER_ROLE) {
        _unpause();
    }

    /**
     * @dev initialization address
     */
    /*
    function initialize() initializer public {
        __Pausable_init();
        __AccessControl_init();
        __ReentrancyGuard_init();

        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _grantRole(ORACLE_ROLE, msg.sender);
        _grantRole(REGISTRY_ROLE, msg.sender);
        _grantRole(PAUSER_ROLE, msg.sender);
        _grantRole(MANAGER_ROLE, msg.sender);

        // init default values
        managerFeeShare = 5;
        firstDebt = 1;
        lastDebt = 0;
        phase = 0;
        _vectorClockTick();

        // initiate default withdrawal credential to the contract itself
        // uint8('0x1') + 11 bytes(0) + this.address
        bytes memory cred = abi.encodePacked(bytes1(0x01), new bytes(11), address(this));
        withdrawalCredentials = BytesLib.toBytes32(cred, 0);
    }
   */
   
    /**
     * UPDATE(20240130): to set a variable after upgrades
     * use upgradeAndCall to initializeV2
     */ 
    /*
    function initializeV2(address restakingContract_) reinitializer(2) public {
        restakingContract = restakingContract_;
    }
    */

    /**
     * @dev replace validators in batch
     */
    function replaceValidators(
        bytes [] calldata oldpubkeys, 
        bytes [] calldata pubkeys, 
        bytes [] calldata signatures, 
        bool restaking, 
        uint8 [] calldata podIds) external onlyRole(REGISTRY_ROLE) {
        _require(pubkeys.length == signatures.length, "SYS007");
        _require(oldpubkeys.length == pubkeys.length, "SYS007");
        _require(pubkeys.length == podIds.length, "SYS007");

        uint256 n = pubkeys.length;

        for(uint256 i=0;i<n;i++) {
            _require(oldpubkeys[i].length == PUBKEY_LENGTH, "SYS004");
            _require(pubkeys[i].length == PUBKEY_LENGTH, "SYS004");
            _require(signatures[i].length == SIGNATURE_LENGTH, "SYS003");

            // mark old pub key to false
            bytes32 oldPubKeyHash = keccak256(oldpubkeys[i]);
            _require(pubkeyIndices[oldPubKeyHash] > 0, "SYS006");
            uint256 index = pubkeyIndices[oldPubKeyHash] - 1;
            delete pubkeyIndices[oldPubKeyHash];

            // set new pubkey
            bytes32 pubkeyHash = keccak256(pubkeys[i]);
            ValidatorCredential storage validator = validatorRegistry[index];
            validator.pubkey = pubkeys[i];
            validator.signature = signatures[i];
            validator.restaking = restaking;
            validator.eigenpod = podIds[i];
            pubkeyIndices[pubkeyHash] = index+1;
        }
    }

    /**
     * @dev register a batch of validators
     */
    function registerValidators(bytes [] calldata pubkeys, bytes [] calldata signatures) external onlyRole(REGISTRY_ROLE) {
        _require(pubkeys.length == signatures.length, "SYS007");
        uint256 n = pubkeys.length;
        for(uint256 i=0;i<n;i++) {
            _require(pubkeys[i].length == PUBKEY_LENGTH, "SYS004");
            _require(signatures[i].length == SIGNATURE_LENGTH, "SYS003");

            bytes32 pubkeyHash = keccak256(pubkeys[i]);
            _require(pubkeyIndices[pubkeyHash] == 0, "SYS005");
            validatorRegistry.push(ValidatorCredential({pubkey:pubkeys[i], signature:signatures[i], stopped:false, restaking: false, eigenpod: 0}));
            pubkeyIndices[pubkeyHash] = validatorRegistry.length;
        }
    }

    /**
     * @dev register a batch of LRT validators
     * UPDATE(20240115): register a batch of validators for Liquid Restaking (EigenLayer)
     */
    function registerRestakingValidators(bytes [] calldata pubkeys, bytes [] calldata signatures) external onlyRole(REGISTRY_ROLE) {
        _require(pubkeys.length == signatures.length, "SYS007");
        uint256 n = pubkeys.length;
        for(uint256 i=0;i<n;i++) {
            _require(pubkeys[i].length == PUBKEY_LENGTH, "SYS004");
            _require(signatures[i].length == SIGNATURE_LENGTH, "SYS003");

            bytes32 pubkeyHash = keccak256(pubkeys[i]);
            _require(pubkeyIndices[pubkeyHash] == 0, "SYS005");
            validatorRegistry.push(ValidatorCredential({pubkey:pubkeys[i], signature:signatures[i], stopped:false, restaking: true, eigenpod: 0}));
            pubkeyIndices[pubkeyHash] = validatorRegistry.length;
        }
    }

    /**
     * @dev register a batch of LRT validators
     * UPDATE(20240402): register a batch of validators for Liquid Restaking (EigenLayer) with given eigenpod id
     */
    function registerRestakingValidators(
        bytes [] calldata pubkeys, 
        bytes [] calldata signatures, 
        uint8 [] calldata podIds) external onlyRole(REGISTRY_ROLE) {
        _require(pubkeys.length == signatures.length, "SYS007");
        _require(pubkeys.length == podIds.length, "SYS007");
        uint256 n = pubkeys.length;
        uint256 maxPods = IRestaking(restakingContract).getTotalPods();

        for(uint256 i=0;i<n;i++) {
            _require(pubkeys[i].length == PUBKEY_LENGTH, "SYS004");
            _require(signatures[i].length == SIGNATURE_LENGTH, "SYS003");
            _require(podIds[i] < maxPods, "SYS031");

            bytes32 pubkeyHash = keccak256(pubkeys[i]);
            _require(pubkeyIndices[pubkeyHash] == 0, "SYS005");
            validatorRegistry.push(ValidatorCredential({pubkey:pubkeys[i], signature:signatures[i], stopped:false, restaking: true, eigenpod: podIds[i]}));
            pubkeyIndices[pubkeyHash] = validatorRegistry.length;
        }
    }

    /**
     * @dev set manager's fee in 1/1000
     */
    function setManagerFeeShare(uint256 milli) external onlyRole(DEFAULT_ADMIN_ROLE)  {
        _require(milli >=0 && milli <=1000, "SYS008");
        managerFeeShare = milli;

        emit ManagerFeeSet(milli);
    }

    /**
     * @dev set eth deposit contract address
     */
    function setETHDepositContract(address _ethDepositContract) external onlyRole(DEFAULT_ADMIN_ROLE) {
        ethDepositContract = _ethDepositContract;

        emit DepositContractSet(_ethDepositContract);
    }


    /**
     * @dev set withdraw credential to receive revenue, usually this should be the contract itself.
     */
    function setWithdrawCredential(bytes32 withdrawalCredentials_) external onlyRole(DEFAULT_ADMIN_ROLE) {
        withdrawalCredentials = withdrawalCredentials_;
        emit WithdrawCredentialSet(withdrawalCredentials);
    } 

    
    /**
     * @dev stake into eth2 staking contract by calling this function
     */
    function stake() external { _stakeInternal(); }

    /**
     * @dev internal entry of stake() external 
     */
    function _stakeInternal() internal {
        // spin max nodes
        uint256 numValidators = totalPending / DEPOSIT_SIZE;
        uint256 maxValidators = (nextValidatorId + numValidators <= validatorRegistry.length)?
                                    numValidators:
                                    validatorRegistry.length - nextValidatorId;

        for (uint256 i = 0;i<maxValidators;i++) {
            _spinup();
        }

        if (maxValidators > 0) {
            emit ValidatorActivated(nextValidatorId);
        }
    }

    /**
     * @dev manager withdraw fees as uniETH
     */
    function withdrawManagerFee(address to) external onlyRole(MANAGER_ROLE) {
        IERC20(xETHAddress).safeTransfer(to, IERC20(xETHAddress).balanceOf(address(this)));
    }

    /**
     * @dev compound manager's revenue
     *  NOTE(20240406): this MUST be called in pushBeacon, to make sure debts are paied in priority, otherwise
     *      debts may be used to pay as the manager's revenue(that may take serveral months to come back).
     */
    function _compoundManagerRevenue() internal {
        uint256 freeEthers = address(this).balance - totalPending;
        uint256 amountEthers = freeEthers < accountedManagerRevenue ? freeEthers:accountedManagerRevenue;

        if (amountEthers > 0) {
            uint256 totalSupply = IERC20(xETHAddress).totalSupply();
            uint256 totalEthers = currentReserve();
            uint256 tokensToMint = totalSupply * amountEthers / totalEthers;

            // swapping
            // uint256 ratio = _exchangeRatioInternal();           // RATIO GUARD BEGIN
            IMintableContract(xETHAddress).mint(address(this), tokensToMint);
            totalPending += amountEthers;
            accountedManagerRevenue -= amountEthers;
            // assert(ratio == _exchangeRatioInternal());          // RATIO GUARD END

            emit ManagerRevenueCompounded(amountEthers);
        }
    }

    /**
     * @dev clear debts
     */
    function _clearDebts() internal {
        uint256 maxUsable = (address(this).balance - totalPending) / 32 ether * 32 ether;
        uint256 effectiveEthers = totalDebts < maxUsable? totalDebts:maxUsable;

        if (effectiveEthers > 0) {
            uint256 ratio = _exchangeRatioInternal();           // RATIO GUARD BEGIN

            uint256 paid = _payDebts(effectiveEthers);
            totalStaked -= paid;

            assert(ratio == _exchangeRatioInternal());          // RATIO GUARD END
        }
    }


    /**
     * @dev balance sync, also moves the vector clock if it has different value
     */
    function syncBalance() external { _syncBalance(); }
    
    /**
     * @dev balance sync, also moves the vector clock if it has different value
     */
    function _syncBalance() internal {
        // account restaking values
        IRestaking(restakingContract).update();

        assert(SafeCast.toInt256(address(this).balance) >= accountedBalance);
        uint256 diff = SafeCast.toUint256(SafeCast.toInt256(address(this).balance) - accountedBalance);
        if (diff > 0) {
            accountedBalance = SafeCast.toInt256(address(this).balance);
            recentReceived += diff;
            _vectorClockTick();
            emit BalanceSynced(diff);
        }
    }
    
    /**
     * @dev public invokable settlement to update exchangeRatio with default revenue limit.
     */
    function pushBeacon() external { _pushBeacon(vectorClock, SAFE_PUSH_REWARDS); }

    /**
     * @dev operators to settle revenue with custom revenue limit under abnormal conditions.
     */
    function pushBeacon(bytes32 clock, uint256 maxRewards) external onlyRole(ORACLE_ROLE) { _pushBeacon(clock, maxRewards); }


    function _pushBeacon(bytes32 clock, uint256 maxRewards) internal {
        _require(vectorClock == clock, "SYS012");

        // Collect new revenue if there is any.
        _syncBalance();
        
        // Check if new validators increased
        // and adjust rewardBase to include the new validators' value
        uint256 rewardBase = reportedValidatorBalance + reportedUnrealizedProfits;
        uint256 _aliveValidators = nextValidatorId - stoppedValidators;
        if (_aliveValidators + recentStopped > reportedValidators) {
            // newly launched validators
            uint256 newValidators = _aliveValidators + recentStopped - reportedValidators;
            rewardBase += newValidators * DEPOSIT_SIZE;
        }

        // Rewards calculation, this also considers recentReceived ethers from 
        // either stopped validators or withdrawed ethers as rewards.
        //
        // During two consecutive pushBeacon operation, the ethers will ONLY: 
        //  1. staked to new validators
        //  2. move from active validators to this contract
        // 
        // so, at any time, revenue generated if:
        //
        //  current active validator balance 
        //      + recent received from validators(since last pushBeacon) 
        //  >(GREATER THAN) reward base(last active validator balance + new nodes balance)
        uint256 _aliveBalance = _aliveValidators * DEPOSIT_SIZE;  // computed balance
        uint256 _unrealizedProfits = IRestaking(restakingContract).getPendingWithdrawalAmount();   // get unrealized profits

        _require(_aliveBalance + _unrealizedProfits + recentReceived >= rewardBase, "SYS015");
        uint256 rewards = _aliveBalance + _unrealizedProfits + recentReceived - rewardBase;
        _require(rewards <= maxRewards, "SYS016");

        _distributeRewards(rewards);

        // PRIORITY IN ETHER USAGE:
        // 1. to clear off debts
        // 2. to compound manager's revenue
        // 3. to auto-compound
        _clearDebts();
        _compoundManagerRevenue();
        _autocompound();

        // Update reportedValidators & reportedValidatorBalance
        // reset the recentReceived to 0
        reportedValidatorBalance = _aliveBalance; 
        reportedValidators = _aliveValidators;
        reportedUnrealizedProfits = _unrealizedProfits;
        recentReceived = 0;
        recentStopped = 0;
    }

    /**
     * @dev notify some validators stopped, and pay the debts
     */
    function validatorStopped(bytes [] calldata _stoppedPubKeys, bytes32 clock) external nonReentrant onlyRole(ORACLE_ROLE) {
        _require(vectorClock == clock, "SYS012");
        uint256 amountUnstaked = _stoppedPubKeys.length * DEPOSIT_SIZE;
        _require(_stoppedPubKeys.length > 0, "SYS017");
        _require(_stoppedPubKeys.length + stoppedValidators <= nextValidatorId, "SYS018");
        _require(maxToStop >= _stoppedPubKeys.length, "SYS019");

        // track stopped validators
        for (uint i=0;i<_stoppedPubKeys.length;i++) {
            bytes32 pubkeyHash = keccak256(_stoppedPubKeys[i]);
            _require(pubkeyIndices[pubkeyHash] > 0, "SYS006");
            uint256 index = pubkeyIndices[pubkeyHash] - 1;
            _require(!validatorRegistry[index].stopped, "SYS020");
            validatorRegistry[index].stopped = true;
        }
        stoppedValidators += _stoppedPubKeys.length;
        recentStopped += _stoppedPubKeys.length;
        maxToStop -= _stoppedPubKeys.length;
    
        // log
        emit ValidatorStopped(_stoppedPubKeys.length);

        // vector clock moves
        _vectorClockTick();
    }

    /**
     * ======================================================================================
     * 
     * VIEW FUNCTIONS
     * 
     * ======================================================================================
     */

    /**
     * @dev returns current reserve of ethers
     */
    function currentReserve() public view returns(uint256) {
        return totalPending + totalStaked + accountedUserRevenue - totalDebts - rewardDebts;
    }

    /*
     * @dev returns current vector clock
     */
    function getVectorClock() external view returns(bytes32) { return vectorClock; }

    /*
     * @dev returns current accounted balance
     */
    function getAccountedBalance() external view returns(int256) { return accountedBalance; }

    /**
     * @dev return total staked ethers
     */
    function getTotalStaked() external view returns (uint256) { return totalStaked; }

    /**
     * @dev return pending ethers
     */
    function getPendingEthers() external view returns (uint256) { return totalPending; }

    /**
     * @dev return reward debts(total compounded ethers)
     */
    function getRewardDebts() external view returns (uint256) { return rewardDebts; }

    /**
     * @dev return current debts
     */
    function getCurrentDebts() external view returns (uint256) { return totalDebts; }

    /**
     * @dev returns the accounted user revenue
     */
    function getAccountedUserRevenue() external view returns (uint256) { return accountedUserRevenue; }

    /**
     * @dev returns the accounted manager's revenue
     */
    function getAccountedManagerRevenue() external view returns (uint256) { return accountedManagerRevenue; }

    /*
     * @dev returns accumulated beacon validators
     */
    function getReportedValidators() external view returns (uint256) { return reportedValidators; }

    /*
     * @dev returns reported validator balance snapshot
     */
    function getReportedValidatorBalance() external view returns (uint256) { return reportedValidatorBalance; }

    /*
     * @dev returns maxToStop
     */
    function getMaxToStop() external view returns (uint256) { return maxToStop; }
    
    /*
     * @dev returns recent received value
     */
    function getRecentReceived() external view returns (uint256) { return recentReceived; }
    /*
     * @dev returns recent received value
     */
    function getRecentStopped() external view returns (uint256) { return recentStopped; }

    /**
     * @dev return debt for an account
     */
    function debtOf(address account) external view returns (uint256) {
        return userDebts[account];
    }

    /**
     * @dev return number of registered validator
     */
    function getRegisteredValidatorsCount() external view returns (uint256) {
        return validatorRegistry.length;
    }
    
    /**
     * @dev return a batch of validators credential
     */
    function getRegisteredValidators(uint256 idx_from, uint256 idx_to) external view returns (bytes [] memory pubkeys, bytes [] memory signatures, bool[] memory stopped) {
        pubkeys = new bytes[](idx_to - idx_from);
        signatures = new bytes[](idx_to - idx_from);
        stopped = new bool[](idx_to - idx_from);


        uint counter = 0;
        for (uint i = idx_from; i < idx_to;i++) {
            pubkeys[counter] = validatorRegistry[i].pubkey;
            signatures[counter] = validatorRegistry[i].signature;
            stopped[counter] = validatorRegistry[i].stopped;
            counter++;
        }
    }

    /**
     * @dev return a batch of validators information
     * UPDATE(20240119): V2 returns restaking info
     */
    function getRegisteredValidatorsV2(uint256 idx_from, uint256 idx_to) external view returns (
         bytes [] memory pubkeys,
         bytes [] memory signatures,
         bool [] memory stopped,
         bool [] memory restaking)
    {
        pubkeys = new bytes[](idx_to - idx_from);
        signatures = new bytes[](idx_to - idx_from);
        stopped = new bool[](idx_to - idx_from);
        restaking = new bool[](idx_to - idx_from);

        uint counter = 0;
        for (uint i = idx_from; i < idx_to;i++) {
            pubkeys[counter] = validatorRegistry[i].pubkey;
            signatures[counter] = validatorRegistry[i].signature;
            stopped[counter] = validatorRegistry[i].stopped;
            restaking[counter] = validatorRegistry[i].restaking;
            counter++;
        }
    }


    /**
     * @dev return next validator id
     */
    function getNextValidatorId() external view returns (uint256) { return nextValidatorId; }

    /**
     * @dev return exchange ratio for 1 uniETH to ETH, multiplied by 1e18
     */
    function exchangeRatio() external view returns (uint256) { return _exchangeRatioInternal(); }

    function _exchangeRatioInternal() internal view returns (uint256) {
        uint256 xETHAmount = IERC20(xETHAddress).totalSupply();
        if (xETHAmount == 0) {
            return 1 * MULTIPLIER;
        }

        uint256 ratio = currentReserve() * MULTIPLIER / xETHAmount;
        return ratio;
    }

    /**
     * @dev return debt of index
     */
    function checkDebt(uint256 index) external view returns (address account, uint256 amount) {
        Debt memory debt = etherDebts[index];
        return (debt.account, debt.amount);
    }
    /**
     * @dev return debt queue index
     */
    function getDebtQueue() external view returns (uint256 first, uint256 last) {
        return (firstDebt, lastDebt);
    }

    /**
     * @dev get stopped validators count
     */
    function getStoppedValidatorsCount() external view returns (uint256) { return stoppedValidators; }

    /**
     * ======================================================================================
     * 
     * EXTERNAL FUNCTIONS
     * 
     * ======================================================================================
     */
    /**
     * @dev mint xETH with ETH
     */
    function mint(uint256 minToMint, uint256 deadline) external payable nonReentrant whenNotPaused returns(uint256 minted) {
        _require(block.timestamp < deadline, "USR001");
        _require(msg.value > 0, "USR002");

        // track balance
        _balanceIncrease(msg.value);

        // mint xETH while keeping the exchange ratio invariant
        uint256 totalXETH = IERC20(xETHAddress).totalSupply();
        uint256 totalEthers = currentReserve();
        uint256 toMint = 1 * msg.value;  // default exchange ratio 1:1

        if (totalEthers > 0) { // avert division overflow
            toMint = totalXETH * msg.value / totalEthers;
        }

        _require(toMint >= minToMint, "USR004");

        // mint token while keeping exchange ratio invariant
        // uint256 ratio = _exchangeRatioInternal();           // RATIO GUARD BEGIN
        IMintableContract(xETHAddress).mint(msg.sender, toMint);
        totalPending += msg.value;
        // assert(ratio == _exchangeRatioInternal());          // RATIO GUARD END

        // try to initiate stake()
        _stakeInternal();

        return toMint;
    }

    /** 
     * @dev preview instant payment at CURRENT exchangeRatio
     */
    function previewInstantSwap(uint256 tokenAmount) external view returns(
        uint256 maxEthersToSwap,
        uint256 maxTokensToBurn
    ) {
        return _instantSwapRate(tokenAmount);
    }


    /** 
     * @dev instant payment as much as possbile from pending ethers at CURRENT exchangeRatio
     */
    function instantSwap(uint256 tokenAmount) external nonReentrant whenNotPaused {
        (uint256 maxEthersToSwap, uint256 maxTokensToBurn) = _instantSwapRate(tokenAmount);
        // _require(maxTokensToBurn > 0 && maxEthersToSwap > 0, "USR007");

        // uint256 ratio = _exchangeRatioInternal();               // RATIO GUARD BEGIN
        // transfer token from user and burn, substract ethers from pending ethers
        IMintableContract(xETHAddress).burnFrom(msg.sender, maxTokensToBurn);
        totalPending -= maxEthersToSwap;
        // assert(ratio == _exchangeRatioInternal());              // RATIO GUARD END

        // track balance change
        _balanceDecrease(maxEthersToSwap);

        // transfer ethers to users
        payable(msg.sender).sendValue(maxEthersToSwap);
    }

    /**
     * @dev internal function for the calculation of max allowed instant swap rate
     */
    function _instantSwapRate(uint256 tokenAmount) internal view returns (
        uint256 maxEthersToSwap,
        uint256 maxTokensToBurn
    ) {
        // find max instant swappable ethers
        uint256 totalSupply = IERC20(xETHAddress).totalSupply();
        uint256 r = currentReserve();
        uint256 expectedEthersToSwap =  tokenAmount * r / totalSupply;
        maxEthersToSwap = expectedEthersToSwap > totalPending ? totalPending:expectedEthersToSwap;
        // reverse calculation for how much token to burn.
        maxTokensToBurn = totalSupply * maxEthersToSwap / r;
    }

    /**
     * @dev redeem N * 32Ethers, which will turn off validadators,
     * note this function is asynchronous, the caller will only receive his ethers
     * after the validator has turned off.
     *
     * this function is dedicated for institutional operations.
     * 
     * redeem keeps the ratio invariant
     */
    function redeemFromValidators(uint256 ethersToRedeem, uint256 maxToBurn, uint256 deadline) external nonReentrant returns(uint256 burned) {
        _require(block.timestamp < deadline, "USR001");
        _require(ethersToRedeem % DEPOSIT_SIZE == 0, "USR005");
        _require(ethersToRedeem > 0, "USR005");

        uint256 totalXETH = IERC20(xETHAddress).totalSupply();
        uint256 xETHToBurn = totalXETH * ethersToRedeem / currentReserve();
        _require(xETHToBurn <= maxToBurn, "USR004");

        // NOTE: the following procdure must keep exchangeRatio invariant:
        // transfer xETH from sender & burn
        // uint256 ratio = _exchangeRatioInternal();           // RATIO GUARD BEGIN
        IMintableContract(xETHAddress).burnFrom(msg.sender, xETHToBurn);
        _enqueueDebt(msg.sender, ethersToRedeem);           // queue ether debts
        // assert(ratio == _exchangeRatioInternal());          // RATIO GUARD END
        maxToStop += ethersToRedeem / DEPOSIT_SIZE;

        // return burned 
        return xETHToBurn;
    }

    /** 
     * ======================================================================================
     * 
     * INTERNAL FUNCTIONS
     * 
     * ======================================================================================
     */

    function _balanceIncrease(uint256 amount) internal { accountedBalance += SafeCast.toInt256(amount); }
    function _balanceDecrease(uint256 amount) internal { accountedBalance -= SafeCast.toInt256(amount); }

    function _vectorClockTick() internal {
        vectorClockTicks++;
        vectorClock = keccak256(abi.encodePacked(vectorClock, block.timestamp, vectorClockTicks));
    }

    function _enqueueDebt(address account, uint256 amount) internal {
        // debt is paid in FIFO queue
        lastDebt += 1;
        etherDebts[lastDebt] = Debt({account:account, amount:amount});

        // track user debts
        userDebts[account] += amount;
        // track total debts
        totalDebts += amount;

        // log
        emit DebtQueued(account, amount);
    }

    function _dequeueDebt() internal returns (Debt memory debt) {
        _require(lastDebt >= firstDebt, "SYS022");  // non-empty queue
        debt = etherDebts[firstDebt];
        delete etherDebts[firstDebt];
        firstDebt += 1;
    }

    /**
     * @dev pay debts for a given amount
     */
    function _payDebts(uint256 total) internal returns(uint256 amountPaid) {
        // ethers to pay
        for (uint i=firstDebt;i<=lastDebt;i++) {
            if (total == 0) {
                break;
            }

            Debt storage debt = etherDebts[i];

            // clean debts
            uint256 toPay = debt.amount <= total? debt.amount:total;
            debt.amount -= toPay;
            total -= toPay;
            userDebts[debt.account] -= toPay;
            amountPaid += toPay;

            // transfer money to debt contract
            IRedeem(redeemContract).pay{value:toPay}(debt.account);

            // dequeue if cleared 
            if (debt.amount == 0) {
                _dequeueDebt();
            }
        }
        
        totalDebts -= amountPaid;
        
        // track balance
        _balanceDecrease(amountPaid);
    }

    /**
     * @dev distribute revenue
     */
    function _distributeRewards(uint256 rewards) internal {
        // rewards distribution
        uint256 fee = rewards * managerFeeShare / 1000;
        accountedManagerRevenue += fee;
        accountedUserRevenue += rewards - fee;

        emit RevenueAccounted(rewards);
    }

    /**
     * @dev auto compounding, after shanghai merge, called in pushBeacon
     *  NOTE(20240406): this MUST be called in pushBeacon, to make sure debts are paied in priority, otherwise
     *      debts may be used to pay as the users' revenue(that may take serveral months to come back).
     */
    function _autocompound() internal {
        uint256 maxCompound = accountedUserRevenue - rewardDebts;
        uint256 maxUsable = address(this).balance - totalPending;
        uint256 effectiveEthers = maxCompound < maxUsable? maxCompound:maxUsable;

        if (effectiveEthers > 0) {
            totalPending += effectiveEthers;
            rewardDebts += effectiveEthers;
            emit UserRevenueCompounded(effectiveEthers);
        }
    }

    /**
     * @dev spin up the node
     */
    function _spinup() internal {
         // load credential
        ValidatorCredential memory cred = validatorRegistry[nextValidatorId];
        
        // UPDATE(20240115):
        //  switch withdrawal credential based on it's registration
        if (!cred.restaking) {
            _stake(cred.pubkey, cred.signature, withdrawalCredentials);
        } else {
            address eigenPod = IRestaking(restakingContract).getPod(cred.eigenpod);
            bytes memory eigenPodCred = abi.encodePacked(bytes1(0x01), new bytes(11), eigenPod);
            bytes32 restakingWithdrawalCredentials = BytesLib.toBytes32(eigenPodCred, 0);

            _stake(cred.pubkey, cred.signature, restakingWithdrawalCredentials);
        }
        nextValidatorId++;        

        // track total staked & total pending ethers
        totalStaked += DEPOSIT_SIZE;
        totalPending -= DEPOSIT_SIZE;
    }

    /**
     * @dev Invokes a deposit call to the official Deposit contract
     *      UPDATE(20240115): add param withCred, instead of using contract variable
     */
    function _stake(bytes memory pubkey, bytes memory signature, bytes32 withCred) internal {
        _require(withCred != bytes32(0x0), "SYS024");
        uint256 value = DEPOSIT_SIZE;
        uint256 depositAmount = DEPOSIT_SIZE / DEPOSIT_AMOUNT_UNIT;
        assert(depositAmount * DEPOSIT_AMOUNT_UNIT == value);    // properly rounded

        // Compute deposit data root (`DepositData` hash tree root)
        // https://etherscan.io/address/0x00000000219ab540356cbb839cbe05303d7705fa#code
        bytes32 pubkey_root = sha256(abi.encodePacked(pubkey, bytes16(0)));
        bytes32 signature_root = sha256(abi.encodePacked(
            sha256(BytesLib.slice(signature, 0, 64)),
            sha256(abi.encodePacked(BytesLib.slice(signature, 64, SIGNATURE_LENGTH - 64), bytes32(0)))
        ));
        
        bytes memory amount = to_little_endian_64(uint64(depositAmount));

        bytes32 depositDataRoot = sha256(abi.encodePacked(
            sha256(abi.encodePacked(pubkey_root, withCred)),
            sha256(abi.encodePacked(amount, bytes24(0), signature_root))
        ));

        IDepositContract(ethDepositContract).deposit{value:DEPOSIT_SIZE} (
            pubkey, abi.encodePacked(withCred), signature, depositDataRoot);

        // track balance
        _balanceDecrease(DEPOSIT_SIZE);
    }

    /**
     * @dev to little endian
     * https://etherscan.io/address/0x00000000219ab540356cbb839cbe05303d7705fa#code
     */
    function to_little_endian_64(uint64 value) internal pure returns (bytes memory ret) {
        ret = new bytes(8);
        bytes8 bytesValue = bytes8(value);
        // Byteswapping during copying to bytes.
        ret[0] = bytesValue[7];
        ret[1] = bytesValue[6];
        ret[2] = bytesValue[5];
        ret[3] = bytesValue[4];
        ret[4] = bytesValue[3];
        ret[5] = bytesValue[2];
        ret[6] = bytesValue[1];
        ret[7] = bytesValue[0];
    }

    /**
     * @dev function version of _require, which could make the code size smaller
     */
    function _require(bool condition, string memory text) private pure {
        require(condition, text);
    }

    /**
     * ======================================================================================
     * 
     * CONTRCT EVENTS
     *
     * ======================================================================================
     */
    event ValidatorActivated(uint256 nextValidatorId);
    event ValidatorStopped(uint256 stoppedCount);
    event RevenueAccounted(uint256 amount);
    event ValidatorSlashedStopped(uint256 stoppedCount);
    event ManagerAccountSet(address account);
    event ManagerFeeSet(uint256 milli);
    event ManagerFeeWithdrawed(uint256 amount, address);
    event WithdrawCredentialSet(bytes32 withdrawCredential);
    event RestakingAddressSet(address addr);
    event DebtQueued(address creditor, uint256 amountEther);
    event DepositContractSet(address addr);
    event BalanceSynced(uint256 diff);
    event WhiteListToggle(address account, bool enabled);
    event ManagerRevenueCompounded(uint256 amount);
    event UserRevenueCompounded(uint256 amount);
}
BytesLib.sol 510 lines
// SPDX-License-Identifier: Unlicense
/*
 * @title Solidity Bytes Arrays Utils
 * @author Gonçalo Sá <[email protected]>
 *
 * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
 *      The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
 */
pragma solidity >=0.8.0 <0.9.0;


library BytesLib {
    function concat(
        bytes memory _preBytes,
        bytes memory _postBytes
    )
        internal
        pure
        returns (bytes memory)
    {
        bytes memory tempBytes;

        assembly {
            // Get a location of some free memory and store it in tempBytes as
            // Solidity does for memory variables.
            tempBytes := mload(0x40)

            // Store the length of the first bytes array at the beginning of
            // the memory for tempBytes.
            let length := mload(_preBytes)
            mstore(tempBytes, length)

            // Maintain a memory counter for the current write location in the
            // temp bytes array by adding the 32 bytes for the array length to
            // the starting location.
            let mc := add(tempBytes, 0x20)
            // Stop copying when the memory counter reaches the length of the
            // first bytes array.
            let end := add(mc, length)

            for {
                // Initialize a copy counter to the start of the _preBytes data,
                // 32 bytes into its memory.
                let cc := add(_preBytes, 0x20)
            } lt(mc, end) {
                // Increase both counters by 32 bytes each iteration.
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                // Write the _preBytes data into the tempBytes memory 32 bytes
                // at a time.
                mstore(mc, mload(cc))
            }

            // Add the length of _postBytes to the current length of tempBytes
            // and store it as the new length in the first 32 bytes of the
            // tempBytes memory.
            length := mload(_postBytes)
            mstore(tempBytes, add(length, mload(tempBytes)))

            // Move the memory counter back from a multiple of 0x20 to the
            // actual end of the _preBytes data.
            mc := end
            // Stop copying when the memory counter reaches the new combined
            // length of the arrays.
            end := add(mc, length)

            for {
                let cc := add(_postBytes, 0x20)
            } lt(mc, end) {
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                mstore(mc, mload(cc))
            }

            // Update the free-memory pointer by padding our last write location
            // to 32 bytes: add 31 bytes to the end of tempBytes to move to the
            // next 32 byte block, then round down to the nearest multiple of
            // 32. If the sum of the length of the two arrays is zero then add
            // one before rounding down to leave a blank 32 bytes (the length block with 0).
            mstore(0x40, and(
              add(add(end, iszero(add(length, mload(_preBytes)))), 31),
              not(31) // Round down to the nearest 32 bytes.
            ))
        }

        return tempBytes;
    }

    function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal {
        assembly {
            // Read the first 32 bytes of _preBytes storage, which is the length
            // of the array. (We don't need to use the offset into the slot
            // because arrays use the entire slot.)
            let fslot := sload(_preBytes.slot)
            // Arrays of 31 bytes or less have an even value in their slot,
            // while longer arrays have an odd value. The actual length is
            // the slot divided by two for odd values, and the lowest order
            // byte divided by two for even values.
            // If the slot is even, bitwise and the slot with 255 and divide by
            // two to get the length. If the slot is odd, bitwise and the slot
            // with -1 and divide by two.
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)
            let newlength := add(slength, mlength)
            // slength can contain both the length and contents of the array
            // if length < 32 bytes so let's prepare for that
            // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
            switch add(lt(slength, 32), lt(newlength, 32))
            case 2 {
                // Since the new array still fits in the slot, we just need to
                // update the contents of the slot.
                // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length
                sstore(
                    _preBytes.slot,
                    // all the modifications to the slot are inside this
                    // next block
                    add(
                        // we can just add to the slot contents because the
                        // bytes we want to change are the LSBs
                        fslot,
                        add(
                            mul(
                                div(
                                    // load the bytes from memory
                                    mload(add(_postBytes, 0x20)),
                                    // zero all bytes to the right
                                    exp(0x100, sub(32, mlength))
                                ),
                                // and now shift left the number of bytes to
                                // leave space for the length in the slot
                                exp(0x100, sub(32, newlength))
                            ),
                            // increase length by the double of the memory
                            // bytes length
                            mul(mlength, 2)
                        )
                    )
                )
            }
            case 1 {
                // The stored value fits in the slot, but the combined value
                // will exceed it.
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // The contents of the _postBytes array start 32 bytes into
                // the structure. Our first read should obtain the `submod`
                // bytes that can fit into the unused space in the last word
                // of the stored array. To get this, we read 32 bytes starting
                // from `submod`, so the data we read overlaps with the array
                // contents by `submod` bytes. Masking the lowest-order
                // `submod` bytes allows us to add that value directly to the
                // stored value.

                let submod := sub(32, slength)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(
                    sc,
                    add(
                        and(
                            fslot,
                            0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
                        ),
                        and(mload(mc), mask)
                    )
                )

                for {
                    mc := add(mc, 0x20)
                    sc := add(sc, 1)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
            default {
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                // Start copying to the last used word of the stored array.
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // Copy over the first `submod` bytes of the new data as in
                // case 1 above.
                let slengthmod := mod(slength, 32)
                let mlengthmod := mod(mlength, 32)
                let submod := sub(32, slengthmod)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(sc, add(sload(sc), and(mload(mc), mask)))

                for {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
        }
    }

    function slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    )
        internal
        pure
        returns (bytes memory)
    {
        require(_length + 31 >= _length, "slice_overflow");
        require(_bytes.length >= _start + _length, "slice_outOfBounds");

        bytes memory tempBytes;

        assembly {
            switch iszero(_length)
            case 0 {
                // Get a location of some free memory and store it in tempBytes as
                // Solidity does for memory variables.
                tempBytes := mload(0x40)

                // The first word of the slice result is potentially a partial
                // word read from the original array. To read it, we calculate
                // the length of that partial word and start copying that many
                // bytes into the array. The first word we copy will start with
                // data we don't care about, but the last `lengthmod` bytes will
                // land at the beginning of the contents of the new array. When
                // we're done copying, we overwrite the full first word with
                // the actual length of the slice.
                let lengthmod := and(_length, 31)

                // The multiplication in the next line is necessary
                // because when slicing multiples of 32 bytes (lengthmod == 0)
                // the following copy loop was copying the origin's length
                // and then ending prematurely not copying everything it should.
                let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                let end := add(mc, _length)

                for {
                    // The multiplication in the next line has the same exact purpose
                    // as the one above.
                    let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                } lt(mc, end) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    mstore(mc, mload(cc))
                }

                mstore(tempBytes, _length)

                //update free-memory pointer
                //allocating the array padded to 32 bytes like the compiler does now
                mstore(0x40, and(add(mc, 31), not(31)))
            }
            //if we want a zero-length slice let's just return a zero-length array
            default {
                tempBytes := mload(0x40)
                //zero out the 32 bytes slice we are about to return
                //we need to do it because Solidity does not garbage collect
                mstore(tempBytes, 0)

                mstore(0x40, add(tempBytes, 0x20))
            }
        }

        return tempBytes;
    }

    function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
        require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) {
        require(_bytes.length >= _start + 1 , "toUint8_outOfBounds");
        uint8 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x1), _start))
        }

        return tempUint;
    }

    function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) {
        require(_bytes.length >= _start + 2, "toUint16_outOfBounds");
        uint16 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x2), _start))
        }

        return tempUint;
    }

    function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) {
        require(_bytes.length >= _start + 4, "toUint32_outOfBounds");
        uint32 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x4), _start))
        }

        return tempUint;
    }

    function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) {
        require(_bytes.length >= _start + 8, "toUint64_outOfBounds");
        uint64 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x8), _start))
        }

        return tempUint;
    }

    function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) {
        require(_bytes.length >= _start + 12, "toUint96_outOfBounds");
        uint96 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0xc), _start))
        }

        return tempUint;
    }

    function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) {
        require(_bytes.length >= _start + 16, "toUint128_outOfBounds");
        uint128 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x10), _start))
        }

        return tempUint;
    }

    function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {
        require(_bytes.length >= _start + 32, "toUint256_outOfBounds");
        uint256 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x20), _start))
        }

        return tempUint;
    }

    function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) {
        require(_bytes.length >= _start + 32, "toBytes32_outOfBounds");
        bytes32 tempBytes32;

        assembly {
            tempBytes32 := mload(add(add(_bytes, 0x20), _start))
        }

        return tempBytes32;
    }

    function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
        bool success = true;

        assembly {
            let length := mload(_preBytes)

            // if lengths don't match the arrays are not equal
            switch eq(length, mload(_postBytes))
            case 1 {
                // cb is a circuit breaker in the for loop since there's
                //  no said feature for inline assembly loops
                // cb = 1 - don't breaker
                // cb = 0 - break
                let cb := 1

                let mc := add(_preBytes, 0x20)
                let end := add(mc, length)

                for {
                    let cc := add(_postBytes, 0x20)
                // the next line is the loop condition:
                // while(uint256(mc < end) + cb == 2)
                } eq(add(lt(mc, end), cb), 2) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    // if any of these checks fails then arrays are not equal
                    if iszero(eq(mload(mc), mload(cc))) {
                        // unsuccess:
                        success := 0
                        cb := 0
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }

    function equalStorage(
        bytes storage _preBytes,
        bytes memory _postBytes
    )
        internal
        view
        returns (bool)
    {
        bool success = true;

        assembly {
            // we know _preBytes_offset is 0
            let fslot := sload(_preBytes.slot)
            // Decode the length of the stored array like in concatStorage().
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)

            // if lengths don't match the arrays are not equal
            switch eq(slength, mlength)
            case 1 {
                // slength can contain both the length and contents of the array
                // if length < 32 bytes so let's prepare for that
                // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
                if iszero(iszero(slength)) {
                    switch lt(slength, 32)
                    case 1 {
                        // blank the last byte which is the length
                        fslot := mul(div(fslot, 0x100), 0x100)

                        if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) {
                            // unsuccess:
                            success := 0
                        }
                    }
                    default {
                        // cb is a circuit breaker in the for loop since there's
                        //  no said feature for inline assembly loops
                        // cb = 1 - don't breaker
                        // cb = 0 - break
                        let cb := 1

                        // get the keccak hash to get the contents of the array
                        mstore(0x0, _preBytes.slot)
                        let sc := keccak256(0x0, 0x20)

                        let mc := add(_postBytes, 0x20)
                        let end := add(mc, mlength)

                        // the next line is the loop condition:
                        // while(uint256(mc < end) + cb == 2)
                        for {} eq(add(lt(mc, end), cb), 2) {
                            sc := add(sc, 1)
                            mc := add(mc, 0x20)
                        } {
                            if iszero(eq(sload(sc), mload(mc))) {
                                // unsuccess:
                                success := 0
                                cb := 0
                            }
                        }
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }
}
SafeCast.sol 241 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol)

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128) {
        require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
        return int128(value);
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64) {
        require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
        return int64(value);
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32) {
        require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
        return int32(value);
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16) {
        require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
        return int16(value);
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8) {
        require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
        return int8(value);
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}
SafeERC20.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "IERC20.sol";
import "Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
Initializable.sol 149 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "AddressUpgradeable.sol";

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

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

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

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
     */
    modifier initializer() {
        bool isTopLevelCall = _setInitializedVersion(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.
     *
     * `initializer` is equivalent to `reinitializer(1)`, so 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.
     *
     * 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.
     */
    modifier reinitializer(uint8 version) {
        bool isTopLevelCall = _setInitializedVersion(version);
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(version);
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     */
    function _disableInitializers() internal virtual {
        _setInitializedVersion(type(uint8).max);
    }

    function _setInitializedVersion(uint8 version) private returns (bool) {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, and for the lowest level
        // of initializers, because in other contexts the contract may have been reentered.
        if (_initializing) {
            require(
                version == 1 && !AddressUpgradeable.isContract(address(this)),
                "Initializable: contract is already initialized"
            );
            return false;
        } else {
            require(_initialized < version, "Initializable: contract is already initialized");
            _initialized = version;
            return true;
        }
    }
}
ERC165Upgradeable.sol 42 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "IERC165Upgradeable.sol";
import "Initializable.sol";

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
AddressUpgradeable.sol 195 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // 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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
ContextUpgradeable.sol 37 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "Initializable.sol";

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

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
IERC165Upgradeable.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

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

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library StringsUpgradeable {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}
PausableUpgradeable.sol 103 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)

pragma solidity ^0.8.0;

import "ContextUpgradeable.sol";
import "Initializable.sol";

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

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

    bool private _paused;

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

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

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

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

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

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
AccessControlUpgradeable.sol 248 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "IAccessControlUpgradeable.sol";
import "ContextUpgradeable.sol";
import "StringsUpgradeable.sol";
import "ERC165Upgradeable.sol";
import "Initializable.sol";

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

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

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

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

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        StringsUpgradeable.toHexString(uint160(account), 20),
                        " is missing role ",
                        StringsUpgradeable.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

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

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

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

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

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

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

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
IAccessControlUpgradeable.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControlUpgradeable {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

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

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

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

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

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

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

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

pragma solidity ^0.8.0;
import "Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

Read Contract

DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
DEPOSIT_SIZE 0x36bf3325 → uint256
MANAGER_ROLE 0xec87621c → bytes32
ORACLE_ROLE 0x07e2cea5 → bytes32
PAUSER_ROLE 0xe63ab1e9 → bytes32
REGISTRY_ROLE 0x42f1e879 → bytes32
SAFE_PUSH_REWARDS 0x506a7bec → uint256
checkDebt 0xc8c3df4a → address, uint256
currentReserve 0x2e12007c → uint256
debtOf 0xd283e75f → uint256
ethDepositContract 0x3884545d → address
exchangeRatio 0x4006ccc5 → uint256
getAccountedBalance 0x33e5761f → int256
getAccountedManagerRevenue 0x08b84c0c → uint256
getAccountedUserRevenue 0x61c993c5 → uint256
getCurrentDebts 0x8b0bfd35 → uint256
getDebtQueue 0xdc3fc3b2 → uint256, uint256
getMaxToStop 0xbe9d96a0 → uint256
getNextValidatorId 0xda863b3b → uint256
getPendingEthers 0x64363f2b → uint256
getRecentReceived 0xe08f2d89 → uint256
getRecentStopped 0x2ae45fa1 → uint256
getRegisteredValidators 0xf22abf37 → bytes[], bytes[], bool[]
getRegisteredValidatorsCount 0x30b12c8d → uint256
getRegisteredValidatorsV2 0x3bf39dca → bytes[], bytes[], bool[], bool[]
getReportedValidatorBalance 0xcdb54a1b → uint256
getReportedValidators 0x6a42602c → uint256
getRewardDebts 0xa065913f → uint256
getRoleAdmin 0x248a9ca3 → bytes32
getStoppedValidatorsCount 0x49557df9 → uint256
getTotalStaked 0x0917e776 → uint256
getVectorClock 0xecacf56d → bytes32
hasRole 0x91d14854 → bool
managerFeeShare 0xe43a4954 → uint256
paused 0x5c975abb → bool
previewInstantSwap 0xfa695018 → uint256, uint256
redeemContract 0x7a4473e1 → address
restakingContract 0xf1f3b3e7 → address
supportsInterface 0x01ffc9a7 → bool
validatorRegistry 0x5a1239c1 → bytes, bytes, bool, bool, uint8
withdrawalCredentials 0x4cd79e0a → bytes32
xETHAddress 0xb181033a → address

Write Contract 21 functions

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

grantRole 0x2f2ff15d
bytes32 role
address account
instantSwap 0xfadb574d
uint256 tokenAmount
mint 0x1b2ef1ca
uint256 minToMint
uint256 deadline
returns: uint256
pause 0x8456cb59
No parameters
pushBeacon 0x849138af
No parameters
pushBeacon 0xa13cb538
bytes32 clock
uint256 maxRewards
redeemFromValidators 0xf5404d60
uint256 ethersToRedeem
uint256 maxToBurn
uint256 deadline
returns: uint256
registerRestakingValidators 0x0a1521fc
bytes[] pubkeys
bytes[] signatures
uint8[] podIds
registerRestakingValidators 0x4e8ab1a1
bytes[] pubkeys
bytes[] signatures
registerValidators 0xe7efb747
bytes[] pubkeys
bytes[] signatures
renounceRole 0x36568abe
bytes32 role
address account
replaceValidators 0x4f13b2e3
bytes[] oldpubkeys
bytes[] pubkeys
bytes[] signatures
bool restaking
uint8[] podIds
revokeRole 0xd547741f
bytes32 role
address account
setETHDepositContract 0x91b66caa
address _ethDepositContract
setManagerFeeShare 0x755d7dd3
uint256 milli
setWithdrawCredential 0xd7d25461
bytes32 withdrawalCredentials_
stake 0x3a4b66f1
No parameters
syncBalance 0xfd9c652b
No parameters
unpause 0x3f4ba83a
No parameters
validatorStopped 0x99629f58
bytes[] _stoppedPubKeys
bytes32 clock
withdrawManagerFee 0x8d40152c
address to

Recent Transactions

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