Address Contract Verified
Address
0x82fe329f4A9c4BcEDc8a33F004337d51921d55E4
Balance
0 ETH
Nonce
1
Code Size
24265 bytes
Creator
0x7769ee42...84eC at tx 0x9bfa46ab...99de64
Indexed Transactions
0
Contract Bytecode
24265 bytes
0x608060405234801561000f575f5ffd5b5060043610610609575f3560e01c80638da5cb5b11610327578063cacf3b58116101ba578063e7a3317411610109578063f211c390116100a9578063f536459911610084578063f536459914610e11578063f6ccaad414610e1a578063f9557ccb14610e22578063fbbbf94c14610e40575f5ffd5b8063f211c39014610de1578063f2fde38b14610df5578063f384bd0514610e08575f5ffd5b8063eafecffa116100e4578063eafecffa14610da9578063ecf7085814610db2578063eee2421914610dbb578063ef8b30f714610dce575f5ffd5b8063e7a3317414610d7b578063e7e9f92014610d8e578063e8596f7214610da1575f5ffd5b8063d905777e11610174578063e30c39781161014f578063e30c397814610d4e578063e551d11d14610d5f578063e5f13b1614610d68578063e63a391f14610867575f5ffd5b8063d905777e14610d15578063daf33f2a14610d28578063dd62ed3e14610d3b575f5ffd5b8063cacf3b5814610c6a578063cadac47914610c72578063cdd72d5214610c85578063ce96cb7714610cc8578063d2a156e014610cdb578063d41ddc9614610d02575f5ffd5b8063b5af306211610276578063bdc8144b11610230578063c58e4df61161020b578063c58e4df614610c0a578063c63d75b614610c1d578063c6e1c7c914610c30578063c6e6f59214610c57575f5ffd5b8063bdc8144b14610be4578063c0a7e8921461076c578063c158e88d14610bf7575f5ffd5b8063b5af306214610b83578063b68d0a0914610ba2578063b78294dd14610867578063b8ca3b8314610bb5578063ba08765214610bbe578063bc410c6414610bd1575f5ffd5b806399530b06116102e1578063a457c2d7116102bc578063a457c2d714610b37578063a9059cbb14610b4a578063b3d7f6b914610b5d578063b460af9414610b70575f5ffd5b806399530b0614610adf5780639a295e7314610ae75780639fe34bdc14610867575f5ffd5b80638da5cb5b14610a0b5780638f791f8b14610a1c57806393f46f6414610a2f57806394bf804d14610a4257806395d14ca814610a5557806395d89b4114610ad7575f5ffd5b8063492924271161049f5780636cd3cc77116103ee5780637bcad14c116103a85780638142dd53116103835780638142dd531461099f5780638285ef40146109b257806382beee89146109f05780638456cb5914610a03575f5ffd5b80637bcad14c146109665780637d37bdd7146109795780637ec4b5711461098c575f5ffd5b80636cd3cc77146108675780636e553f651461091d57806370a0823114610930578063715018a614610943578063721b0a471461094b57806379ba50971461095e575f5ffd5b80634f8b4ae711610459578063608bc9ae11610434578063608bc9ae146108e757806367800b5f146108f057806369026e88146109025780636b96668f1461090a575f5ffd5b80634f8b4ae7146108a05780634fd422df146108a857806354fd4d50146108c7575f5ffd5b80634929242714610841578063499836f61461085457806349eb7af6146108675780634ac8eb5f146108715780634bc66f321461087a5780634cdad5061461088d575f5ffd5b80631c6c95971161055b57806338d52e0f116105155780633f4ba83a116104f05780633f4ba83a1461080a578063402d267d1461081257806345014095146108255780634732428c14610838575f5ffd5b806338d52e0f146107be57806339509351146107e45780633d417d2d146107f7575f5ffd5b80631c6c95971461073457806323b872dd146107595780632b3ba6811461076c5780632b42e94e1461077b578063313ce5671461078457806337500763146107b5575f5ffd5b80630a28a477116105c657806311a2e4bc116105a157806311a2e4bc146106f757806318160ddd146107005780631956473f146107185780631c2591d314610721575f5ffd5b80630a28a477146106c25780630e9bdced146106d5578063115a334c146106ea575f5ffd5b806301e1d1141461060d57806302ce728f1461062857806306fdde031461064d57806307a2d13a14610662578063090f3f5014610675578063095ea7b31461069f575b5f5ffd5b610615610ebe565b6040519081526020015b60405180910390f35b610630610eee565b60408051931515845260208401929092529082015260600161061f565b610655610f16565b60405161061f9190615905565b61061561067036600461593a565b610fa6565b5f54610687906001600160a01b031681565b6040516001600160a01b03909116815260200161061f565b6106b26106ad366004615965565b610fb9565b604051901515815260200161061f565b6106156106d036600461593a565b610fd0565b6106e86106e336600461598f565b610ffe565b005b6008546106b29060ff1681565b61061560115481565b602254600160801b90046001600160801b0316610615565b61061560165481565b61061561072f3660046159cb565b611076565b610747610742366004615a0a565b6110e5565b60405161061f96959493929190615a25565b6106b2610767366004615ae0565b61131e565b610615670de0b6b3a764000081565b61061560185481565b60405160ff7f000000000000000000000000000000000000000000000000000000000000000616815260200161061f565b61061560135481565b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48610687565b6106b26107f2366004615965565b611341565b610615610805366004615b1e565b611362565b6106e8611424565b610615610820366004615b4c565b61149d565b6106e8610833366004615b4c565b6114ee565b61061560125481565b600454610687906001600160a01b031681565b6106e8610862366004615b67565b611502565b610615620186a081565b61061560245481565b600154610687906001600160a01b031681565b61061561089b36600461593a565b611560565b6106e8611586565b6106156108b6366004615b4c565b60266020525f908152604090205481565b60035f805b6040805193845260208401929092529082015260600161061f565b610615601a5481565b6008546106b290610100900460ff1681565b6106e86115aa565b6106e8610918366004615b4c565b6115bb565b61061561092b366004615b1e565b61162c565b61061561093e366004615b4c565b6116f6565b6106e8611710565b610615610959366004615b9d565b611721565b6106e8611bc2565b600554610687906001600160a01b031681565b6106156109873660046159cb565b611c39565b61061561099a3660046159cb565b611c98565b6106e86109ad366004615be2565b611cf7565b6023546109d0906001600160801b0380821691600160801b90041682565b604080516001600160801b0393841681529290911660208301520161061f565b6106e86109fe366004615b4c565b611dc3565b6106e8611dd4565b6002546001600160a01b0316610687565b6106e8610a2a366004615bfb565b611e23565b610615610a3d3660046159cb565b611f58565b610615610a50366004615b1e565b611fb7565b601d54610a999063ffffffff808216916401000000008104909116906001600160401b03600160401b8204811691600160801b8104821691600160c01b9091041685565b6040805163ffffffff96871681529590941660208601526001600160401b03928316938501939093528116606084015216608082015260a00161061f565b61065561207a565b610615612089565b620186a0808080670de0b6b3a7640000818161c350604080519889526020890197909752958701949094526060860192909252608085015260a084015260c083015260e08201526101000161061f565b6106b2610b45366004615965565b6120a3565b6106b2610b58366004615965565b61211d565b610615610b6b36600461593a565b61212a565b610615610b7e366004615c2e565b612151565b610615610b91366004615b4c565b60256020525f908152604090205481565b6108cc610bb0366004615b4c565b612219565b61061561c35081565b610615610bcc366004615c2e565b612255565b6106e8610bdf36600461593a565b612309565b6106e8610bf236600461593a565b61236a565b6106e8610c05366004615b4c565b61237b565b6008546106b29062010000900460ff1681565b610615610c2b366004615b4c565b61238c565b6106877f000000000000000000000000bb347df435b5c88f9861c9f1c7250f5318a480ff81565b610615610c6536600461593a565b6123e5565b6107476123f2565b6106e8610c80366004615b1e565b61255d565b610c8d6125b2565b604080516001600160801b0396871681529486166020860152928516928401929092529092166060820152608081019190915260a00161061f565b610615610cd6366004615b4c565b612600565b6106877f0000000000000000000000007769ee42787edbd1c189e07a279e11e2196e84ec81565b6106e8610d10366004615b1e565b6126a3565b610615610d23366004615b4c565b612838565b610615610d36366004615c62565b6128b5565b610615610d49366004615c8c565b6129e4565b6003546001600160a01b0316610687565b61061560065481565b610615610d76366004615ca8565b612a0e565b6106e8610d8936600461593a565b612dce565b6106e8610d9c366004615b67565b612ddf565b6106e8612e5e565b61061560145481565b61061560075481565b601554610687906001600160a01b031681565b610615610ddc36600461593a565b612e6f565b6008546106b2906301000000900460ff1681565b6106e8610e03366004615b4c565b612e95565b610615600f5481565b61061560105481565b6106e8612f06565b6022546109d0906001600160801b0380821691600160801b90041682565b601e54601f54602054602154610e79936001600160a01b03811693600160a01b90910463ffffffff16926001600160b81b039091169185565b604080516001600160a01b03909616865263ffffffff90941660208601526001600160b81b03909216928401929092526060830191909152608082015260a00161061f565b5f5f610ec86123f2565b50600554909550610ee894508593506001600160a01b0316915050612f16565b91505090565b5f5f5f610ef9612fb1565b610f0161300a565b925092509250610f116001600e55565b909192565b6060601b8054610f2590615cd3565b80601f0160208091040260200160405190810160405280929190818152602001828054610f5190615cd3565b8015610f9c5780601f10610f7357610100808354040283529160200191610f9c565b820191905f5260205f20905b815481529060010190602001808311610f7f57829003601f168201915b5050505050905090565b5f610fb3825f6001611c39565b92915050565b5f33610fc681858561322c565b5060019392505050565b5f5f610fda6123f2565b50945050505050610ff7836001836133509092919063ffffffff16565b9392505050565b6110066133df565b60115460125460145460408051938452602084019290925282820152606082018690526080820185905260a08201849052517fc9aa62b60be8f25ac9f285edbb80bde64199b3c53e1da1027058551d32695fca9181900360c00190a1601193909355601291909155601455601355565b5f81156110aa575f6110866123f2565b509450505050506110a28585836133509092919063ffffffff16565b915050610ff7565b604080518082019091526022546001600160801b038082168352600160801b9091041660208201526110dd908585613350565b949350505050565b6040805160a0810182525f80825260208201819052918101829052606081018290526080810182905281908190604080518082019091525f8082526020820152604080518082019091525f8082526020820152611140612fb1565b6040805160a081018252601d5463ffffffff8082168352640100000000820481166020808501919091526001600160401b03600160401b8404811685870152600160801b80850482166060870152600160c01b90940416608085015260275460055486518088019097526022546001600160801b0380821689529590049094169186019190915292965091925f926111e2926001600160a01b031690612f1616565b90505f8115611215576023548290611206906001600160801b0316620186a0615d19565b6112109190615d30565b611217565b5f5b90505f8382116112305761122b8285615d4f565b61123a565b61123a8483615d4f565b905083158015906112655750620186a0601654856112589190615d19565b6112629190615d30565b81105b156112a2576040518181527f479ca0b7370ecf25269e837ef2836a8fb256e3683a41bc4b22f6f61d0ee46d509060200160405180910390a16112b6565b6112aa61340a565b929d50909b5099509750505b8a15611307576040805180820182526022546001600160801b038082168352600160801b91829004811660208085019190915284518086019095526023548083168652929092041690830152965094505b505050506113156001600e55565b91939550919395565b5f3361132b858285613727565b61133685858561379f565b506001949350505050565b5f33610fc681858561135383836129e4565b61135d9190615d62565b61322c565b5f61136b612fb1565b6001600160a01b03821661139257604051631e4ec46b60e01b815260040160405180910390fd5b60085460ff16156113b657604051631e61c1e960e11b815260040160405180910390fd5b6113be61340a565b5050604080518082019091526023546001600160801b038082168352600160801b90910416602082015292506113fa9150829050856001613948565b915061141981611409846139bd565b611412876139bd565b3387613a29565b50610fb36001600e55565b61142c613d8c565b6114365f19613dd0565b6114405f19613e05565b6114495f613e3a565b6114525f613e7b565b61145b5f613ec4565b61146361340a565b50505050506114715f613f0f565b601d80546fffffffffffffffff00000000000000001916600160401b426001600160401b031602179055565b5f5f6114a76123f2565b509450505050506007546114c45f83612f1690919063ffffffff16565b10156114e6576114d4815f612f16565b6007546114e19190615d4f565b610ff7565b5f9392505050565b6114f66133df565b6114ff81613f5c565b50565b61150a613d8c565b601854601a546040805192835260208301859052820152606081018290527f33028baf0f22e874d876a756252557e998e2da0d621469d48aebc743c82773c19060800160405180910390a1601891909155601a55565b5f5f61156a6123f2565b50945050505050610ff7835f836139489092919063ffffffff16565b61158e6133df565b611596613fab565b61159f5f613f5c565b6115a85f613fd5565b565b6115b2614030565b6115a85f613e05565b6115c36133df565b601554604080516001600160a01b03928316815291831660208301527faeae842c8b3cd009fbb602e1ed072dc1aec69750e431ceae97f7543b466cd04c910160405180910390a1601580546001600160a01b0319166001600160a01b0392909216919091179055565b5f611635612fb1565b6001600160a01b03821661165c57604051631e4ec46b60e01b815260040160405180910390fd5b61166461340a565b5050604080518082019091526022546001600160801b038082168352600160801b909104166020820152925085915061169f9050825f612f16565b6116a99190615d62565b60075410156116cb57604051630aad288560e21b815260040160405180910390fd5b6116d681855f613350565b9150611419816116e5866139bd565b6116ee856139bd565b8660016140c0565b6001600160a01b03165f9081526009602052604090205490565b611718614486565b6115a85f6144e0565b5f61172a612fb1565b6001600160a01b03821661175157604051631e4ec46b60e01b815260040160405180910390fd5b60085462010000900460ff161561177b57604051631b4b0d7760e21b815260040160405180910390fd5b824211156117aa57604051635ba2a8d560e01b8152426004820152602481018490526044015b60405180910390fd5b601a546001600160a01b0383165f908152601960205260409020546117cf9190615d62565b431015611815576001600160a01b0382165f908152601960205260409081902054601a54915163227ddeed60e01b81526117a19290600401918252602082015260400190565b61181d61340a565b50505050505f61182b61300a565b509150505f61183a84836144f9565b509050801561185c57604051633af2cafd60e11b815260040160405180910390fd5b506040805180820182526023546001600160801b038082168352600160801b909104166020808301919091526001600160a01b0386165f9081526025825283812054602690925292832054919290916118b4906139bd565b90505f8080670de0b6b3a7640000876118d7886001600160801b038f1685613948565b6118e19190615d19565b6118eb9190615d30565b90505f620186a0601154620186a06119039190615d62565b61190d9084615d19565b6119179190615d30565b9050611922816145f2565b61192b876145f2565b6119359190615d75565b93505f84131561196d57620186a0601254620186a06119549190615d62565b61195e9084615d19565b6119689190615d30565b61196f565b855b601454909950156119a557620186a08960145461198c9190615d19565b6119969190615d30565b92506119a2838a615d4f565b98505b505f90506119c66119c1876001600160801b038e166001613948565b6139bd565b90505f80808513611a65576119db8d87615d9b565b91506001600160801b03821615611a6057611a036119c1896001600160801b0385165f613948565b905080885f01818151611a169190615d9b565b6001600160801b039081169091526022805484935090915f91611a3b91859116615d9b565b92506101000a8154816001600160801b0302191690836001600160801b031602179055505b611a90565b611a706013546145f2565b851215611a90576040516326ff709960e11b815260040160405180910390fd5b8a6001600160a01b03167f821de4e13fff1938b3806eb2859b6a5d55111f00dcf286f8a793584228ff36f88b8f86888787604051611b04969594939291909586526001600160801b03948516602087015292841660408601526060850191909152821660808401521660a082015260c00190565b60405180910390a250611b258783838f611b1e9190615dba565b338e613a29565b611b3089338c61465b565b611b3b83308c61465b565b611b4630843061473f565b6005546001600160a01b031615611bb057600554604051631e1b394160e11b81525f60048201526001600160a01b0390911690633c367282906024015f604051808303815f87803b158015611b99575f5ffd5b505af1158015611bab573d5f5f3e3d5ffd5b505050505b5050505050505050610ff76001600e55565b60035433906001600160a01b03168114611c305760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b60648201526084016117a1565b6114ff816144e0565b5f8115611c65575f611c496123f2565b509450505050506110a28585836139489092919063ffffffff16565b604080518082019091526022546001600160801b038082168352600160801b9091041660208201526110dd908585613948565b5f8115611cc4575f611ca86123f2565b955050505050506110a28585836139489092919063ffffffff16565b604080518082019091526023546001600160801b038082168352600160801b9091041660208201526110dd908585613948565b611cff6133df565b6008546301000000900460ff1615611d2a5760405163a02a2bcd60e01b815260040160405180910390fd5b61c3508163ffffffff161115611d535760405163da0afa5760e01b815260040160405180910390fd5b611d5b61340a565b5050601d805467ffffffff00000000191664010000000063ffffffff8716908102919091179091556040519081527f58a58c712558f3d6e20bed57421eb8f73048d881dea9e5bb80efb37c49680d1c93506020019150611db89050565b60405180910390a150565b611dcb6133df565b6114ff81614820565b611ddc614030565b611de55f613dd0565b611dee5f613e05565b611df86001613e3a565b611e026001613e7b565b611e0c6001613ec4565b611e1461340a565b50505050506115a86001613f0f565b611e2b6133df565b6040805160a081018252601e546001600160a01b03811680835263ffffffff600160a01b909204919091166020808401829052601f546001600160b81b0316848601525460608401526021546080840152925191927f78ba1c32ac8ea4b3d51133dd0b6f5d8f98e23797aade6afc381ea317d5d4f28b92611edc929190879087906001600160a01b03948516815263ffffffff93841660208201529190931660408201529116606082015260800190565b60405180910390a16001600160a01b039290921680835263ffffffff919091166020808401829052601e80546001600160c01b031916909317600160a01b909202919091179091556040820151601f80546001600160b81b0319166001600160b81b039092169190911790556060820151905560800151602155565b5f8115611f84575f611f686123f2565b955050505050506110a28585836133509092919063ffffffff16565b604080518082019091526023546001600160801b038082168352600160801b9091041660208201526110dd908585613350565b5f611fc0612fb1565b6001600160a01b038216611fe757604051631e4ec46b60e01b815260040160405180910390fd5b611fef61340a565b5050604080518082019091526022546001600160801b038082168352600160801b909104166020820152925061202b9150829050856001613948565b915081612038825f612f16565b6120429190615d62565b600754101561206457604051630aad288560e21b815260040160405180910390fd5b61141981612071846139bd565b6116ee876139bd565b6060601c8054610f2590615cd3565b5f61209e670de0b6b3a76400005f6001611c39565b905090565b5f33816120b082866129e4565b9050838110156121105760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084016117a1565b611336828686840361322c565b5f33610fc681858561379f565b5f5f6121346123f2565b50945050505050610ff7836001836139489092919063ffffffff16565b5f61215a612fb1565b6001600160a01b03831661218157604051631e4ec46b60e01b815260040160405180910390fd5b600854610100900460ff16156121aa5760405163e0a3980360e01b815260040160405180910390fd5b6121b261340a565b5050604080518082019091526022546001600160801b038082168352600160801b90910416602082015292506121ee9150829050866001613350565b915061220e816121fd876139bd565b612206856139bd565b87875f614882565b50610ff76001600e55565b5f5f5f612225846116f6565b6001600160a01b039094165f90815260266020908152604080832054602590925290912054949590949350915050565b5f61225e612fb1565b6001600160a01b03831661228557604051631e4ec46b60e01b815260040160405180910390fd5b600854610100900460ff16156122ae5760405163e0a3980360e01b815260040160405180910390fd5b6122b661340a565b5050604080518082019091526022546001600160801b038082168352600160801b90910416602082015292506122f19150829050865f613948565b915061220e81612300846139bd565b612206886139bd565b612311613d8c565b620186a08111156123355760405163017d28ed60e41b815260040160405180910390fd5b60168190556040518181527fb0a2e5eb716fabfb1aa7752f8bb8f33931cc548cce738a19d78a0acd325d5cc190602001611db8565b612372613d8c565b6114ff81613e05565b6123836133df565b6114ff81614afc565b5f5f6123966123f2565b509450505050505f6007546123b45f84612f1690919063ffffffff16565b10156123d6576123c4825f612f16565b6007546123d19190615d4f565b6123d8565b5f5b90506110dd82825f613350565b5f610fb3825f6001611076565b6040805160a0810182525f80825260208201819052918101829052606081018290526080810182905281908190604080518082019091525f8082526020820152604080518082019091525f80825260208201526040805160a081018252601d5463ffffffff808216835264010000000082041660208301526001600160401b03600160401b8204811693830193909352600160801b810483166060830152600160c01b9004909116608082015292505f6124ab84614b56565b8051909150156125095760608082015160808084015160a085015160208601516001600160401b03908116958a019590955260408601519094169188019190915260c084015160e0850151929a509098509196509093509150612554565b6040805180820182526022546001600160801b038082168352600160801b91829004811660208085019190915284518086019095526023548083168652929092041690830152935091505b50909192939495565b612565612fb1565b6001600160a01b03811661258c57604051631e4ec46b60e01b815260040160405180910390fd5b61259461340a565b50505050506125a433838361473f565b6125ae6001600e55565b5050565b5f5f5f5f5f5f5f6125c16123f2565b95509550505050506125df6119c15f84612f1690919063ffffffff16565b60209283015182519290930151602454919993985091965090945092509050565b6008545f90610100900460ff161561261957505f919050565b5f5f5f6126246123f2565b9550955050945050505f306001600160a01b0316866001600160a01b03161461265557612650866116f6565b612669565b8361265f876116f6565b6126699190615d62565b90505f61267884846001614e9a565b90505f612686858483613948565b90508082106126955780612697565b815b98975050505050505050565b6126ab612fb1565b336001600160a01b0382166126d357604051631e4ec46b60e01b815260040160405180910390fd5b6126db61340a565b5050335f90815260266020526040902054159250612723915050575f6126ff61300a565b50509050806127215760405163345513d960e01b815260040160405180910390fd5b505b61272e83833361465b565b6040805160a081018252601e546001600160a01b0381168252600160a01b900463ffffffff16602080830191909152601f546001600160b81b03169282019290925290546060820152602154608082018190525f9061278e9084906144f9565b5090508061282b576001600160a01b0383165f908152602660209081526040918290205482518084019093526023546001600160801b038082168552600160801b90910416918301919091526127e691906001613948565b6001600160a01b0384165f90815260256020526040908190205460808501519151633b49de0f60e21b81526004810193909352602483015260448201526064016117a1565b5050506125ae6001600e55565b6008545f90610100900460ff161561285157505f919050565b5f5f5f61285c6123f2565b9550955050945050505f61287283836001614e9a565b90505f612880848383613350565b90505f6001600160a01b03881630146128a15761289c886116f6565b612686565b856128ab896116f6565b6126869190615d62565b5f6128be614486565b6001600160a01b0382166128e557604051631e4ec46b60e01b815260040160405180910390fd5b604080518082019091526022546001600160801b038082168352600160801b9091048116602083015284165f03612925576129226119c1306116f6565b93505b61293a816001600160801b0386166001613948565b91506129503033866001600160801b031661322c565b6129668161295d846139bd565b8686305f614882565b305f8181526025602052604090205490612983908290869061465b565b604080516001600160801b03871681526001600160a01b0386166020820152908101849052606081018290527faf48306b6b4f0ba30d00f05b21559d8d29934142980a553d8a014780c6c7e4529060800160405180910390a1505092915050565b6001600160a01b039182165f908152600a6020908152604080832093909416825291909152205490565b5f612a17612fb1565b33806001600160a01b038416612a4057604051631e4ec46b60e01b815260040160405180910390fd5b612a4861340a565b5050602354612a6593508992506001600160801b03169050615d62565b6006541015612a87576040516397ba4de360e01b815260040160405180910390fd5b5f612a9061300a565b5050905080612ab25760405163345513d960e01b815260040160405180910390fd5b8515612ac357612ac333873361473f565b612ad5612acf886139bd565b86614ef6565b6040805160a081018252601e546001600160a01b0381168252600160a01b900463ffffffff16602080830191909152601f546001600160b81b031692820192909252905460608201526021546080820181905291955091505f90612b3a9084906144f9565b91505080612bd7576001600160a01b0383165f908152602660209081526040918290205482518084019093526023546001600160801b038082168552600160801b9091041691830191909152612b9291906001613948565b6001600160a01b0384165f90815260256020526040908190205460808501519151632045fa4d60e11b81526004810193909352602483015260448201526064016117a1565b6001600160a01b0383165f9081526026602090815260408083205481518083019092526023546001600160801b038082168452600160801b9091041692820192909252612c25916001613948565b6001600160a01b0385165f908152602560205260408120546080860151929350918290620186a090670de0b6b3a764000090612c619087615d19565b612c6b9190615d30565b612c759190615d19565b612c7f9190615d30565b9050612c8f6002620186a0615d30565b811115612d01576018546001600160a01b0387165f90815260176020526040902054612cbb9190615d62565b431015612d01576001600160a01b0386165f90815260176020526040908190205460185491516358e1ee6b60e11b81526117a19290600401918252602082015260400190565b50506040805160a081018252601e546001600160a01b0381168252600160a01b900463ffffffff16602080830191909152601f546001600160b81b03169282019290925290546060820152602154608082018190529094505f9350612d6992508591506144f9565b50905080612dc1576001600160a01b0383165f908152602660209081526040918290205482518084019093526023546001600160801b038082168552600160801b90910416918301919091526127e691906001613948565b505050610ff76001600e55565b612dd6613d8c565b6114ff81613dd0565b612de76133df565b80821015612e085760405163325159e760e21b815260040160405180910390fd5b600f546010546040805192835260208301859052820152606081018290527f729291ced74c9b973d73b46d6179e72fdc6cbe684099b6ed2c85e023a4e9eedb9060800160405180910390a1600f91909155601055565b612e66614030565b6115a85f613dd0565b5f5f612e796123f2565b50945050505050610ff7835f836133509092919063ffffffff16565b612e9d614486565b600380546001600160a01b0383166001600160a01b03199091168117909155612ece6002546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b612f0e613fab565b6115a8615144565b5f6001600160a01b038216612f36575081516001600160801b0316610fb3565b60405163115de16960e11b81523060048201526001600160a01b038316906322bbc2d290602401602060405180830381865afa158015612f78573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f9c9190615dd9565b8351610ff791906001600160801b0316615d62565b6002600e54036130035760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016117a1565b6002600e55565b6040805160a081018252601e546001600160a01b0381168252600160a01b900463ffffffff16602080830191909152601f546001600160b81b031692820183905254606082015260215460808201525f918291829142146131d0575f815f01516001600160a01b031663bd9a548b6040518163ffffffff1660e01b8152600401606060405180830381865afa1580156130a5573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906130c99190615df0565b9095509350905080156131165781516040516001600160a01b0390911681527ffc131c36b7e444dacda44901fd43641dcdcfdc43fe9e2601b3c1dd87061db9e59060200160405180910390a15b6001600160b81b034216604080840182905260608401869052608084018590528351601e805460208088015163ffffffff16600160a01b026001600160c01b03199092166001600160a01b0390941693909317179055601f80546001600160b81b031916909317909255908590556021849055517fc1f41e029acf5127d111625602160c4cee3e1a4d38e691e50544d1f7c68b77be906131c29086908690918252602082015260400190565b60405180910390a1506131df565b80606001519250806080015191505b608081015160608201515f91906131f69082615d4f565b61320390620186a0615d19565b61320d9190615d30565b9050816020015163ffffffff16811161322557600194505b5050909192565b6001600160a01b03831661328e5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016117a1565b6001600160a01b0382166132ef5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016117a1565b6001600160a01b038381165f818152600a602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b82515f906001600160801b0316810361336a575081610ff7565b835160208501516001600160801b0391821691613388911685615d19565b6133929190615d30565b90508180156133cf57508284602001516001600160801b0316855f01516001600160801b0316836133c39190615d19565b6133cd9190615d30565b105b15610ff7576110dd816001615d62565b6001546001600160a01b031633146115a857604051630e05f48560e11b815260040160405180910390fd5b5f5f5f5f61343e6040805160a0810182525f8082526020820181905291810182905260608101829052608081019190915290565b506040805160a081018252601d5463ffffffff80821683526401000000008204166020808401919091526001600160401b03600160401b8304811684860152600160801b80840482166060860152600160c01b909304166080840152835180850185526022546001600160801b0380821683529084900481168284015285518087019096526023548082168752939093049092169084015290915f916134e5916001614e9a565b90508015613517576023548190613508906001600160801b0316620186a0615d19565b6135129190615d30565b613519565b5f5b6027555f61352683614b56565b80519091501561371e57805f0151965080606001519550806080015194508060a0015193507fc63977c8e2362a31182dc8e89a52252f9836922738e0abcfc0de6924972eafe583606001518460800151836020015184604001516040516135b694939291906001600160401b03948516815292841660208401529083166040830152909116606082015260800190565b60405180910390a17f2b5229f33f1d24d5baab718e1e25d0d86195a9b6d786c2c0868edfb21a460e25868260200151878760405161361694939291909384526001600160401b039290921660208401526040830152606082015260800190565b60405180910390a16020818101516001600160401b0390811660608601819052604080850151831660808801819052429093169087018190524363ffffffff908116808952601d80548a88015167ffffffffffffffff1990911690921764010000000092909316919091029190911777ffffffffffffffffffffffffffffffff00000000000000001916600160401b90920267ffffffffffffffff60801b191691909117600160801b928302176001600160c01b0316600160c01b9093029290921790915560c08301518051908301516001600160801b0391821690821683021760225560e0840151805193015192811692160217602355831561371e5761371e308561515c565b50509091929394565b5f61373284846129e4565b90505f198114613799578181101561378c5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016117a1565b613799848484840361322c565b50505050565b6001600160a01b0383166138035760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016117a1565b6001600160a01b0382166138655760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016117a1565b6001600160a01b0383165f90815260096020526040902054818110156138dc5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016117a1565b6001600160a01b038085165f8181526009602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061393b9086815260200190565b60405180910390a3613799565b5f83602001516001600160801b03165f03613964575081610ff7565b602084015184516001600160801b0391821691613982911685615d19565b61398c9190615d30565b90508180156133cf575082845f01516001600160801b031685602001516001600160801b0316836133c39190615d19565b5f6001600160801b03821115613a255760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b60648201526084016117a1565b5090565b83855f01818151613a3a9190615d9b565b6001600160801b0316905250602085018051849190613a5a908390615d9b565b6001600160801b039081169091526001600160a01b0383165f9081526026602052604081208054928716935091613a92908490615d4f565b9091555050845160208601516001600160801b03908116600160801b029116176023556001600160a01b0382163014613b0357613b036001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb481683306001600160801b038816615220565b6005546001600160a01b031615613d3157600554604051631e1b394160e11b8152600160048201526001600160a01b0390911690633c367282906024015f604051808303815f87803b158015613b57575f5ffd5b505af1158015613b69573d5f5f3e3d5ffd5b505050505f600a620186a06008613b809190615d19565b613b8a9190615d30565b600554604051639d6c635160e01b81523060048201529192505f916001600160a01b0390911690639d6c635190602401602060405180830381865afa158015613bd5573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613bf99190615dd9565b6005546040516337082c1560e01b81523060048201529192505f916001600160a01b03909116906337082c1590602401602060405180830381865afa158015613c44573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613c689190615dd9565b9050805f03613cac578115613ca7575f876001600160801b03168311613c8e5782613c99565b876001600160801b03165b9050613ca48161522c565b50505b613d2d565b5f81613cbb84620186a0615d19565b613cc59190615d30565b905083811115613d2b575f620186a083613cdf8785615d4f565b613ce99190615d19565b613cf39190615d30565b90508015613d2957886001600160801b03168111613d115780613d1c565b886001600160801b03165b9050613d278161522c565b505b505b505b5050505b604080516001600160801b038087168252851660208201526001600160a01b0380841692908516917f9dc1449a0ff0c152e18e8289d865b47acc6e1b76b1ecb239c13d6ee22a9206a791015b60405180910390a35050505050565b6002546001600160a01b03163314801590613db257506001546001600160a01b03163314155b156115a857604051636f54526960e01b815260040160405180910390fd5b60068190556040518181527fbf1ce7fb3a8e648b70ea830f99b52f7ea31554186d29763280751f42e77f638690602001611db8565b60078190556040518181527f854df3eb95564502c8bc871ebdd15310ee26270f955f6c6bd8cea68e75045bc090602001611db8565b6008805460ff19168215159081179091556040519081527f34a71a12fa81891b738d910d4d44ffabeeb12f8bc026844db237ea8bf8ebe8be90602001611db8565b600880548215156101000261ff00199091161790556040517fc56dd3e14f5af3a74c61b7cdf855a3d8ab4401c78c0622a4d312de8a8f8736a290611db890831515815260200190565b60088054821515620100000262ff0000199091161790556040517f28bc4f9e24da61e7ba3aa697dfaefd0167093d2425c00b6190a7d3152ee6dfaa90611db890831515815260200190565b6008805482151563010000000263ff000000199091161790556040517fdea8bb46eee4300a7d2de86939c245f568dc5994576194cbfb69969e010dcb6790611db890831515815260200190565b5f80546001600160a01b0319166001600160a01b03838116918217835560015460405192939116917f162998b90abc2507f3953aa797827b03a14c42dbd9a35f09feaf02e0d592773a9190a350565b5f546001600160a01b031633146115a857604051633d71279960e21b815260040160405180910390fd5b6001546040516001600160a01b038084169216907f31b6c5a04b069b6ec1b3cef44c4e7c1eadd721349cda9823d0b1877b3551cdc6905f90a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b6004546001600160a01b0316331480159061405657506002546001600160a01b03163314155b801561408b5750336001600160a01b037f0000000000000000000000007769ee42787edbd1c189e07a279e11e2196e84ec1614155b80156140a257506001546001600160a01b03163314155b156115a857604051631d1e647b60e01b815260040160405180910390fd5b83855f018181516140d19190615dba565b6001600160801b03169052506020850180518491906140f1908390615dba565b6001600160801b0390811690915261410d91508390851661515c565b845160208601516001600160801b03908116600160801b0291161760225580156144395761416f6001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb481633306001600160801b038816615220565b6005546001600160a01b0316158015906141a757506103e8614191865f612f16565b61419b9190615d30565b846001600160801b0316115b1561443957600554604051631e1b394160e11b8152600160048201526001600160a01b0390911690633c367282906024015f604051808303815f87803b1580156141ef575f5ffd5b505af1158015614201573d5f5f3e3d5ffd5b5050600554604051639d6c635160e01b81523060048201525f93506001600160a01b039091169150639d6c635190602401602060405180830381865afa15801561424d573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906142719190615dd9565b90505f670b1a2bc2ec50000060055f9054906101000a90046001600160a01b03166001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa1580156142cd573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906142f19190615dd9565b60055f9054906101000a90046001600160a01b03166001600160a01b0316639cfd2f2e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614341573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906143659190615dd9565b61437790670de0b6b3a7640000615d19565b6143819190615d30565b6005546040516337082c1560e01b81523060048201529290911192505f916001600160a01b03909116906337082c1590602401602060405180830381865afa1580156143cf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906143f39190615dd9565b8311905081806144005750805b15614435575f876001600160801b0316841161441c5783614427565b876001600160801b03165b90506144328161522c565b50505b5050505b604080516001600160801b038087168252851660208201526001600160a01b0384169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d79101613d7d565b6002546001600160a01b031633146115a85760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016117a1565b600380546001600160a01b03191690556114ff816153af565b5f5f600f545f0361450f575060019050806145eb565b6001600160a01b0384165f9081526026602090815260408083205481518083019092526023546001600160801b038082168452600160801b909104169282019290925261455d916001613948565b9050805f036145735760018092509250506145eb565b6001600160a01b0385165f90815260256020526040812054908190036145a0575f5f9350935050506145eb565b5f81620186a0670de0b6b3a76400006145b98987615d19565b6145c39190615d30565b6145cd9190615d19565b6145d79190615d30565b600f54601054908211159650101593505050505b9250929050565b5f6001600160ff1b03821115613a255760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b60648201526084016117a1565b6001600160a01b0381165f9081526025602052604081208054859290614682908490615d4f565b925050819055508260245f82825461469a9190615d4f565b90915550506001600160a01b03821630146146e3576146e36001600160a01b037f000000000000000000000000bb347df435b5c88f9861c9f1c7250f5318a480ff168385615400565b806001600160a01b0316826001600160a01b0316336001600160a01b03167fbc290bb45104f73cf92115c9603987c3f8fd30c182a13603d8cffa49b5f599528660405161473291815260200190565b60405180910390a4505050565b6001600160a01b0381165f9081526025602052604081208054849290614766908490615d62565b925050819055508160245f82825461477e9190615d62565b90915550506001600160a01b038082165f908152601760205260409020439055831630146147db576147db6001600160a01b037f000000000000000000000000bb347df435b5c88f9861c9f1c7250f5318a480ff16843085615220565b806001600160a01b0316836001600160a01b03167fa32435755c235de2976ed44a75a2f85cb01faf0c894f639fe0c32bb9455fea8f8460405161334391815260200190565b600480546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527f4cb8c9e37efb94c6cdbd2a80fe36cee1957b5584d1a1986fa2bae115180af59a91015b60405180910390a15050565b336001600160a01b03831614801590614899575080155b156148cd575f6148a983336129e4565b90505f1981146148cb576148cb833361135d6001600160801b03891685615d4f565b505b604080518082019091526023546001600160801b038082168352600160801b9091041660208201525f906149049088906001614e9a565b9050856001600160801b0316811015614942576040516362ddb6d760e11b8152600481018290526001600160801b03871660248201526044016117a1565b6005546001600160a01b038481169116146149ee57604080518082019091526023546001600160801b038082168352600160801b9091041660208201525f9061498d90899083614e9a565b9050866001600160801b03168110156149ec575f6149b4826001600160801b038a16615d4f565b90506149bf8161540b565b5050604080518082019091526022546001600160801b038082168352600160801b90910416602082015297505b505b85875f018181516149ff9190615d9b565b6001600160801b0316905250602087018051869190614a1f908390615d9b565b6001600160801b03908116909152885160208a01518216600160801b0290821617602255614a519150849087166154c8565b6001600160a01b0384163014614a9e57614a9e6001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816856001600160801b038916615400565b604080516001600160801b038089168252871660208201526001600160a01b03808616929087169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a450505050505050565b600580546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527f555b230d631cc610f418cd672052f049221d785a7c2fba40a3bfe97f6180b5cb9101614876565b614b5e615885565b4282604001516001600160401b031614158015614b8557506008546301000000900460ff16155b15614e9557600181526040805180820182526022546001600160801b038082168352600160801b91829004811660208085019190915260c086019390935283518085018552602354808316825292909204169181019190915260e08301528201515f90614bfb906001600160401b031642615d4f565b60055460c08401519192505f91614c1a916001600160a01b0316612f16565b90505f8115614c505760e0840151518290614c41906001600160801b0316620186a0615d19565b614c4b9190615d30565b614c52565b5f5b601554608087015160405163cd3181d560e01b815260048101879052602481018490526001600160401b0390911660448201529192506001600160a01b03169063cd3181d5906064016040805180830381865afa158015614cb5573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614cd99190615e3a565b6001600160401b039081166040870152166020850181905260e085015151670de0b6b3a76400009190614d15906001600160801b031686615d19565b614d1f9190615d19565b614d299190615d30565b6060850181905215801590614d5d575060e08401515160608501516001600160801b0391614d5a9190831690615d62565b11155b8015614d80575060608401516001600160801b0390614d7d908490615d62565b11155b15614e9157614d9284606001516139bd565b60e08501518051614da4908390615dba565b6001600160801b03169052506060840151614dbe906139bd565b60c08501518051614dd0908390615dba565b6001600160801b0316905250602085015163ffffffff1615614e9157620186a0856020015163ffffffff168560600151614e0a9190615d19565b614e149190615d30565b6080850181905260c0850151614e2a905f612f16565b614e349190615d4f565b8460c00151602001516001600160801b03168560800151614e559190615d19565b614e5f9190615d30565b60a08501819052614e6f906139bd565b8460c00151602001818151614e849190615dba565b6001600160801b03169052505b5050505b919050565b5f8115614ed75782516005546001600160801b0390911690614ec69086906001600160a01b0316612f16565b614ed09190615d4f565b9050610ff7565b82518451614ee59190615d9b565b6001600160801b0316949350505050565b6040805180820182526023546001600160801b038082168352600160801b918290048116602080850191909152845180860190955260225480831686529290920416908301525f918290614f4c90836001614e9a565b9050846001600160801b0316811015614f8a576040516362ddb6d760e11b8152600481018290526001600160801b03861660248201526044016117a1565b604080518082019091526022546001600160801b038082168352600160801b9091041660208201525f90614fbf908483614e9a565b9050856001600160801b0316811015614ff4575f614fe6826001600160801b038916615d4f565b9050614ff18161540b565b50505b615009836001600160801b0388166001613350565b935085835f0181815161501c9190615dba565b6001600160801b0316905250615031846139bd565b836020018181516150429190615dba565b6001600160801b0390811690915284516020808701518316600160801b029190921617602355335f9081526026909152604081208054879350909190615089908490615d62565b9091555050335f9081526019602052604090204390556001600160a01b03851630146150ec576150ec6001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816866001600160801b038916615400565b604080516001600160801b0388168152602081018690526001600160a01b0387169133917f01348584ec81ac7acd52b7d66d9ade986dd909f3d513881c190fc31c90527efe910160405180910390a350505092915050565b5f80546001600160a01b03191690556115a833613fd5565b6001600160a01b0382166151b25760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016117a1565b80600b5f8282546151c39190615d62565b90915550506001600160a01b0382165f818152600960209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b613799848484846155fa565b604080518082019091526022546001600160801b038082168352600160801b9091041660208201525f9061526281846001613350565b6005549092505f9061527c906001600160a01b03166116f6565b905082811061528b578261528d565b805b60055460405163095ea7b360e01b81526001600160a01b039182166004820152602481018790529194507f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48169063095ea7b3906044016020604051808303815f875af11580156152ff573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906153239190615e62565b50600554604051630c264bc360e31b8152600481018690526001600160a01b03909116906361325e18906024015f604051808303815f87803b158015615367575f5ffd5b505af1158015615379573d5f5f3e3d5ffd5b505050506153a88261538a866139bd565b615393866139bd565b60055430906001600160a01b03166001614882565b5050919050565b600280546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b61521b838383615665565b604080518082019091526022546001600160801b038082168352600160801b9091041660208201525f90615440818484613350565b60055460405163f556d88960e01b8152600481018690529193506001600160a01b03169063f556d889906024015f604051808303815f87803b158015615484575f5ffd5b505af1158015615496573d5f5f3e3d5ffd5b505050506154c2816154a7856139bd565b6154b0856139bd565b6005546001600160a01b03165f6140c0565b50919050565b6001600160a01b0382166155285760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b60648201526084016117a1565b6001600160a01b0382165f908152600960205260409020548181101561559b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b60648201526084016117a1565b6001600160a01b0383165f8181526009602090815260408083208686039055600b80548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6040516001600160a01b03808516602483015283166044820152606481018290526137999085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152615695565b6040516001600160a01b03831660248201526044810182905261521b90849063a9059cbb60e01b9060640161562e565b5f6156e9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166157689092919063ffffffff16565b905080515f14806157095750808060200190518101906157099190615e62565b61521b5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016117a1565b60606110dd84845f85855f5f866001600160a01b0316858760405161578d9190615e7d565b5f6040518083038185875af1925050503d805f81146157c7576040519150601f19603f3d011682016040523d82523d5f602084013e6157cc565b606091505b50915091506157dd878383876157e8565b979650505050505050565b606083156158565782515f0361584f576001600160a01b0385163b61584f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016117a1565b50816110dd565b6110dd838381511561586b5781518083602001fd5b8060405162461bcd60e51b81526004016117a19190615905565b6040518061010001604052805f151581526020015f6001600160401b031681526020015f6001600160401b031681526020015f81526020015f81526020015f81526020016158e2604080518082019091525f808252602082015290565b8152602001615900604080518082019091525f808252602082015290565b905290565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f6020828403121561594a575f5ffd5b5035919050565b6001600160a01b03811681146114ff575f5ffd5b5f5f60408385031215615976575f5ffd5b823561598181615951565b946020939093013593505050565b5f5f5f5f608085870312156159a2575f5ffd5b5050823594602084013594506040840135936060013592509050565b80151581146114ff575f5ffd5b5f5f5f606084860312156159dd575f5ffd5b8335925060208401356159ef816159be565b915060408401356159ff816159be565b809150509250925092565b5f60208284031215615a1a575f5ffd5b8135610ff7816159be565b5f6101808201905087825286602083015285604083015263ffffffff855116606083015263ffffffff60208601511660808301526001600160401b0360408601511660a08301526001600160401b0360608601511660c08301526001600160401b0360808601511660e0830152615ab661010083018580516001600160801b03908116835260209182015116910152565b82516001600160801b03908116610140840152602084015116610160830152979650505050505050565b5f5f5f60608486031215615af2575f5ffd5b8335615afd81615951565b92506020840135615b0d81615951565b929592945050506040919091013590565b5f5f60408385031215615b2f575f5ffd5b823591506020830135615b4181615951565b809150509250929050565b5f60208284031215615b5c575f5ffd5b8135610ff781615951565b5f5f60408385031215615b78575f5ffd5b50508035926020909101359150565b80356001600160801b0381168114614e95575f5ffd5b5f5f5f60608486031215615baf575f5ffd5b615bb884615b87565b92506020840135915060408401356159ff81615951565b803563ffffffff81168114614e95575f5ffd5b5f60208284031215615bf2575f5ffd5b610ff782615bcf565b5f5f60408385031215615c0c575f5ffd5b8235615c1781615951565b9150615c2560208401615bcf565b90509250929050565b5f5f5f60608486031215615c40575f5ffd5b833592506020840135615c5281615951565b915060408401356159ff81615951565b5f5f60408385031215615c73575f5ffd5b615c7c83615b87565b91506020830135615b4181615951565b5f5f60408385031215615c9d575f5ffd5b8235615c7c81615951565b5f5f5f60608486031215615cba575f5ffd5b833592506020840135915060408401356159ff81615951565b600181811c90821680615ce757607f821691505b6020821081036154c257634e487b7160e01b5f52602260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b8082028115828204841417610fb357610fb3615d05565b5f82615d4a57634e487b7160e01b5f52601260045260245ffd5b500490565b81810381811115610fb357610fb3615d05565b80820180821115610fb357610fb3615d05565b8181035f831280158383131683831282161715615d9457615d94615d05565b5092915050565b6001600160801b038281168282160390811115610fb357610fb3615d05565b6001600160801b038181168382160190811115610fb357610fb3615d05565b5f60208284031215615de9575f5ffd5b5051919050565b5f5f5f60608486031215615e02575f5ffd5b8351615e0d816159be565b602085015160409095015190969495509392505050565b80516001600160401b0381168114614e95575f5ffd5b5f5f60408385031215615e4b575f5ffd5b615e5483615e24565b9150615c2560208401615e24565b5f60208284031215615e72575f5ffd5b8151610ff7816159be565b5f82518060208501845e5f92019182525091905056fea264697066735822122027c9b764b8ca3ad56a72c118fb949964d88291c0cac253a565952388e7a5908f64736f6c634300081d0033
Verified Source Code Full Match
Compiler: v0.8.29+commit.ab55807c
EVM: cancun
Optimization: Yes (200 runs)
FraxlendPair.sol 514 lines
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ========================== FraxlendPair ============================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Primary Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// Sam Kazemian: https://github.com/samkazemian
// Travis Moore: https://github.com/FortisFortuna
// Jack Corddry: https://github.com/corddry
// Rich Gee: https://github.com/zer0blockchain
// ====================================================================
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {FraxlendPairConstants} from "./FraxlendPairConstants.sol";
import {FraxlendPairCore} from "./FraxlendPairCore.sol";
import {Timelock2Step} from "./Timelock2Step.sol";
import {SafeERC20} from "./libraries/SafeERC20.sol";
import {VaultAccount, VaultAccountingLibrary} from "./libraries/VaultAccount.sol";
import {IRateCalculatorV2} from "./interfaces/IRateCalculatorV2.sol";
import {ISwapper} from "./interfaces/ISwapper.sol";
/// @title FraxlendPair
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice The FraxlendPair is a lending pair that allows users to engage in lending and borrowing activities
contract FraxlendPair is IERC20Metadata, FraxlendPairCore {
using VaultAccountingLibrary for VaultAccount;
using SafeERC20 for IERC20;
using SafeCast for uint256;
/// @param _configData abi.encode(address _asset, address _collateral, address _oracle, uint32 _maxOracleDeviation, address _rateContract, uint64 _fullUtilizationRate, uint256 _maxLTV, uint256 _cleanLiquidationFee, uint256 _dirtyLiquidationFee, uint256 _protocolLiquidationFee)
/// @param _immutables abi.encode(address _circuitBreakerAddress, address _comptrollerAddress, address _timelockAddress)
/// @param _customConfigData abi.encode(string memory _nameOfContract, string memory _symbolOfContract, uint8 _decimalsOfContract)
constructor(bytes memory _configData, bytes memory _immutables, bytes memory _customConfigData)
FraxlendPairCore(_configData, _immutables, _customConfigData)
{}
// ============================================================================================
// ERC20 Metadata
// ============================================================================================
function name() public view override(ERC20, IERC20Metadata) returns (string memory) {
return nameOfContract;
}
function symbol() public view override(ERC20, IERC20Metadata) returns (string memory) {
return symbolOfContract;
}
function decimals() public view override(ERC20, IERC20Metadata) returns (uint8) {
return decimalsOfContract;
}
// totalSupply for fToken ERC20 compatibility
function totalSupply() public view override(ERC20, IERC20) returns (uint256) {
return totalAsset.shares;
}
// ============================================================================================
// Functions: Helpers
// ============================================================================================
function asset() external view returns (address) {
return address(assetContract);
}
function getConstants()
external
pure
returns (
uint256 _LTV_PRECISION,
uint256 _LIQ_PRECISION,
uint256 _UTIL_PREC,
uint256 _FEE_PRECISION,
uint256 _EXCHANGE_PRECISION,
uint256 _DEVIATION_PRECISION,
uint256 _RATE_PRECISION,
uint256 _MAX_PROTOCOL_FEE
)
{
_LTV_PRECISION = LTV_PRECISION;
_LIQ_PRECISION = LIQ_PRECISION;
_UTIL_PREC = UTIL_PREC;
_FEE_PRECISION = FEE_PRECISION;
_EXCHANGE_PRECISION = EXCHANGE_PRECISION;
_DEVIATION_PRECISION = DEVIATION_PRECISION;
_RATE_PRECISION = RATE_PRECISION;
_MAX_PROTOCOL_FEE = MAX_PROTOCOL_FEE;
}
/// @notice The ```getUserSnapshot``` function gets user level accounting data
/// @param _address The user address
/// @return _userAssetShares The user fToken balance
/// @return _userBorrowShares The user borrow shares
/// @return _userCollateralBalance The user collateral balance
function getUserSnapshot(address _address)
external
view
returns (uint256 _userAssetShares, uint256 _userBorrowShares, uint256 _userCollateralBalance)
{
_userAssetShares = balanceOf(_address);
_userBorrowShares = userBorrowShares[_address];
_userCollateralBalance = userCollateralBalance[_address];
}
/// @notice The ```getPairAccounting``` function gets all pair level accounting numbers
/// @return _totalAssetAmount Total assets deposited and interest accrued, total claims
/// @return _totalAssetShares Total fTokens
/// @return _totalBorrowAmount Total borrows
/// @return _totalBorrowShares Total borrow shares
/// @return _totalCollateral Total collateral
function getPairAccounting()
external
view
returns (
uint128 _totalAssetAmount,
uint128 _totalAssetShares,
uint128 _totalBorrowAmount,
uint128 _totalBorrowShares,
uint256 _totalCollateral
)
{
(,,,, VaultAccount memory _totalAsset, VaultAccount memory _totalBorrow) = previewAddInterest();
_totalAssetAmount = _totalAsset.totalAmount(address(address(0))).toUint128();
_totalAssetShares = _totalAsset.shares;
_totalBorrowAmount = _totalBorrow.amount;
_totalBorrowShares = _totalBorrow.shares;
_totalCollateral = totalCollateral;
}
/// @notice The ```toBorrowShares``` function converts a given amount of borrow debt into the number of shares
/// @param _amount Amount of borrow
/// @param _roundUp Whether to roundup during division
/// @param _previewInterest Whether to simulate interest accrual
/// @return _shares The number of shares
function toBorrowShares(uint256 _amount, bool _roundUp, bool _previewInterest)
external
view
returns (uint256 _shares)
{
if (_previewInterest) {
(,,,,, VaultAccount memory _totalBorrow) = previewAddInterest();
_shares = _totalBorrow.toShares(_amount, _roundUp);
} else {
_shares = totalBorrow.toShares(_amount, _roundUp);
}
}
/// @notice The ```toBorrowAmount``` function converts a given amount of borrow debt into the number of shares
/// @param _shares Shares of borrow
/// @param _roundUp Whether to roundup during division
/// @param _previewInterest Whether to simulate interest accrual
/// @return _amount The amount of asset
function toBorrowAmount(uint256 _shares, bool _roundUp, bool _previewInterest)
external
view
returns (uint256 _amount)
{
if (_previewInterest) {
(,,,,, VaultAccount memory _totalBorrow) = previewAddInterest();
_amount = _totalBorrow.toAmount(_shares, _roundUp);
} else {
_amount = totalBorrow.toAmount(_shares, _roundUp);
}
}
/// @notice The ```toAssetAmount``` function converts a given number of shares to an asset amount
/// @param _shares Shares of asset (fToken)
/// @param _roundUp Whether to round up after division
/// @param _previewInterest Whether to preview interest accrual before calculation
/// @return _amount The amount of asset
function toAssetAmount(uint256 _shares, bool _roundUp, bool _previewInterest)
public
view
returns (uint256 _amount)
{
if (_previewInterest) {
(,,,, VaultAccount memory _totalAsset,) = previewAddInterest();
_amount = _totalAsset.toAmount(_shares, _roundUp);
} else {
_amount = totalAsset.toAmount(_shares, _roundUp);
}
}
/// @notice The ```toAssetShares``` function converts a given asset amount to a number of asset shares (fTokens)
/// @param _amount The amount of asset
/// @param _roundUp Whether to round up after division
/// @param _previewInterest Whether to preview interest accrual before calculation
/// @return _shares The number of shares (fTokens)
function toAssetShares(uint256 _amount, bool _roundUp, bool _previewInterest)
public
view
returns (uint256 _shares)
{
if (_previewInterest) {
(,,,, VaultAccount memory _totalAsset,) = previewAddInterest();
_shares = _totalAsset.toShares(_amount, _roundUp);
} else {
_shares = totalAsset.toShares(_amount, _roundUp);
}
}
function convertToAssets(uint256 _shares) external view returns (uint256 _assets) {
_assets = toAssetAmount(_shares, false, true);
}
function convertToShares(uint256 _assets) external view returns (uint256 _shares) {
_shares = toAssetShares(_assets, false, true);
}
function pricePerShare() external view returns (uint256 _amount) {
_amount = toAssetAmount(1e18, false, true);
}
function totalAssets() external view returns (uint256) {
(,,,, VaultAccount memory _totalAsset,) = previewAddInterest();
return _totalAsset.totalAmount(address(externalAssetVault));
}
function maxDeposit(address) public view returns (uint256 _maxAssets) {
(,,,, VaultAccount memory _totalAsset,) = previewAddInterest();
_maxAssets =
_totalAsset.totalAmount(address(0)) >= depositLimit ? 0 : depositLimit - _totalAsset.totalAmount(address(0));
}
function maxMint(address) external view returns (uint256 _maxShares) {
(,,,, VaultAccount memory _totalAsset,) = previewAddInterest();
uint256 _maxDeposit =
_totalAsset.totalAmount(address(0)) >= depositLimit ? 0 : depositLimit - _totalAsset.totalAmount(address(0));
_maxShares = _totalAsset.toShares(_maxDeposit, false);
}
function maxWithdraw(address _owner) external view returns (uint256 _maxAssets) {
if (isWithdrawPaused) return 0;
(,, uint256 _feesShare,, VaultAccount memory _totalAsset, VaultAccount memory _totalBorrow) =
previewAddInterest();
// Get the owner balance and include the fees share if owner is this contract
uint256 _ownerBalance = _owner == address(this) ? balanceOf(_owner) + _feesShare : balanceOf(_owner);
// Return the lower of total assets in contract or total assets available to _owner
uint256 _totalAssetsAvailable = _totalAssetAvailable(_totalAsset, _totalBorrow, true);
uint256 _totalUserWithdraw = _totalAsset.toAmount(_ownerBalance, false);
_maxAssets = _totalAssetsAvailable < _totalUserWithdraw ? _totalAssetsAvailable : _totalUserWithdraw;
}
function maxRedeem(address _owner) external view returns (uint256 _maxShares) {
if (isWithdrawPaused) return 0;
(,, uint256 _feesShare,, VaultAccount memory _totalAsset, VaultAccount memory _totalBorrow) =
previewAddInterest();
// Calculate the total shares available
uint256 _totalAssetsAvailable = _totalAssetAvailable(_totalAsset, _totalBorrow, true);
uint256 _totalSharesAvailable = _totalAsset.toShares(_totalAssetsAvailable, false);
// Get the owner balance and include the fees share if owner is this contract
uint256 _ownerBalance = _owner == address(this) ? balanceOf(_owner) + _feesShare : balanceOf(_owner);
_maxShares = _totalSharesAvailable < _ownerBalance ? _totalSharesAvailable : _ownerBalance;
}
// ============================================================================================
// Functions: Configuration
// ============================================================================================
/// @notice The ```SetOracleInfo``` event is emitted when the oracle info (address and max deviation) is set
/// @param oldOracle The old oracle address
/// @param oldMaxOracleDeviation The old max oracle deviation
/// @param newOracle The new oracle address
/// @param newMaxOracleDeviation The new max oracle deviation
event SetOracleInfo(
address oldOracle, uint32 oldMaxOracleDeviation, address newOracle, uint32 newMaxOracleDeviation
);
/// @notice The ```setOracleInfo``` function sets the oracle data
/// @param _newOracle The new oracle address
/// @param _newMaxOracleDeviation The new max oracle deviation
function setOracle(address _newOracle, uint32 _newMaxOracleDeviation) external {
_requireTimelock();
ExchangeRateInfo memory _exchangeRateInfo = exchangeRateInfo;
emit SetOracleInfo(
_exchangeRateInfo.oracle, _exchangeRateInfo.maxOracleDeviation, _newOracle, _newMaxOracleDeviation
);
_exchangeRateInfo.oracle = _newOracle;
_exchangeRateInfo.maxOracleDeviation = _newMaxOracleDeviation;
exchangeRateInfo = _exchangeRateInfo;
}
/// @notice The ```SetMaxLTV``` event is emitted when the max LTV is set
/// @param oldMaxLTV The old max LTV
/// @param newMaxLTV The new max LTV
/// @param oldMaxBorrowLTV The old max borrow LTV
/// @param newMaxBorrowLTV The new max borrow LTV
event SetMaxLTV(uint256 oldMaxLTV, uint256 newMaxLTV, uint256 oldMaxBorrowLTV, uint256 newMaxBorrowLTV);
/// @notice The ```setMaxLTV``` function sets the max LTV
/// @param _newMaxLTV The new max LTV
/// @param _newMaxBorrowLTV The new max borrow LTV
function setMaxLTV(uint256 _newMaxLTV, uint256 _newMaxBorrowLTV) external {
_requireTimelock();
if (_newMaxLTV < _newMaxBorrowLTV) revert MaxBorrowLTVLargerThanMaxLTV();
emit SetMaxLTV(maxLTV, _newMaxLTV, maxBorrowLTV, _newMaxBorrowLTV);
maxLTV = _newMaxLTV;
maxBorrowLTV = _newMaxBorrowLTV;
}
/// @notice The ```SetRateContract``` event is emitted when the rate contract is set
/// @param oldRateContract The old rate contract
/// @param newRateContract The new rate contract
event SetRateContract(address oldRateContract, address newRateContract);
/// @notice The ```setRateContract``` function sets the rate contract address
/// @param _newRateContract The new rate contract address
function setRateContract(address _newRateContract) external {
_requireTimelock();
emit SetRateContract(address(rateContract), _newRateContract);
rateContract = IRateCalculatorV2(_newRateContract);
}
/// @notice The ```SetLiquidationFees``` event is emitted when the liquidation fees are set
/// @param oldCleanLiquidationFee The old clean liquidation fee
/// @param oldDirtyLiquidationFee The old dirty liquidation fee
/// @param oldProtocolLiquidationFee The old protocol liquidation fee
/// @param newCleanLiquidationFee The new clean liquidation fee
/// @param newDirtyLiquidationFee The new dirty liquidation fee
/// @param newProtocolLiquidationFee The new protocol liquidation fee
event SetLiquidationFees(
uint256 oldCleanLiquidationFee,
uint256 oldDirtyLiquidationFee,
uint256 oldProtocolLiquidationFee,
uint256 newCleanLiquidationFee,
uint256 newDirtyLiquidationFee,
uint256 newProtocolLiquidationFee
);
/// @notice The ```setLiquidationFees``` function sets the liquidation fees
/// @param _newCleanLiquidationFee The new clean liquidation fee
/// @param _newDirtyLiquidationFee The new dirty liquidation fee
/// @param _newProtocolLiquidationFee The new protocol liquidation fee
/// @param _newMinCollateralRequiredOnDirtyLiquidation The new min collateral required to leave on dirty liquidation
function setLiquidationFees(
uint256 _newCleanLiquidationFee,
uint256 _newDirtyLiquidationFee,
uint256 _newProtocolLiquidationFee,
uint256 _newMinCollateralRequiredOnDirtyLiquidation
) external {
_requireTimelock();
emit SetLiquidationFees(
cleanLiquidationFee,
dirtyLiquidationFee,
protocolLiquidationFee,
_newCleanLiquidationFee,
_newDirtyLiquidationFee,
_newProtocolLiquidationFee
);
cleanLiquidationFee = _newCleanLiquidationFee;
dirtyLiquidationFee = _newDirtyLiquidationFee;
protocolLiquidationFee = _newProtocolLiquidationFee;
minCollateralRequiredOnDirtyLiquidation = _newMinCollateralRequiredOnDirtyLiquidation;
}
/// @notice The ```ChangeFee``` event first when the fee is changed
/// @param newFee The new fee
event ChangeFee(uint32 newFee);
/// @notice The ```changeFee``` function changes the protocol fee, max 50%
/// @param _newFee The new fee
function changeFee(uint32 _newFee) external {
_requireTimelock();
if (isInterestPaused) revert InterestPaused();
if (_newFee > MAX_PROTOCOL_FEE) {
revert BadProtocolFee();
}
_addInterest();
currentRateInfo.feeToProtocolRate = _newFee;
emit ChangeFee(_newFee);
}
/// @notice The ```WithdrawFees``` event fires when the fees are withdrawn
/// @param shares Number of shares (fTokens) redeemed
/// @param recipient To whom the assets were sent
/// @param amountToTransfer The amount of fees redeemed
event WithdrawFees(uint128 shares, address recipient, uint256 amountToTransfer, uint256 collateralAmount);
/// @notice The ```withdrawFees``` function withdraws fees accumulated
/// @param _shares Number of fTokens to redeem
/// @param _recipient Address to send the assets
/// @return _amountToTransfer Amount of assets sent to recipient
function withdrawFees(uint128 _shares, address _recipient) external onlyOwner returns (uint256 _amountToTransfer) {
if (_recipient == address(0)) revert InvalidReceiver();
// Grab some data from state to save gas
VaultAccount memory _totalAsset = totalAsset;
// Take all available if 0 value passed
if (_shares == 0) _shares = balanceOf(address(this)).toUint128();
// We must calculate this before we subtract from _totalAsset or invoke _burn
_amountToTransfer = _totalAsset.toAmount(_shares, true);
_approve(address(this), msg.sender, _shares);
_redeem(_totalAsset, _amountToTransfer.toUint128(), _shares, _recipient, address(this), false);
uint256 _collateralAmount = userCollateralBalance[address(this)];
_removeCollateral(_collateralAmount, _recipient, address(this));
emit WithdrawFees(_shares, _recipient, _amountToTransfer, _collateralAmount);
}
// ============================================================================================
// Functions: Access Control
// ============================================================================================
/// @notice The ```pause``` function is called to pause all contract functionality
function pause() external {
_requireProtocolOrOwner();
_setBorrowLimit(0);
_setDepositLimit(0);
_pauseRepay(true);
_pauseWithdraw(true);
_pauseLiquidate(true);
_addInterest();
_pauseInterest(true);
}
/// @notice The ```unpause``` function is called to unpause all contract functionality
function unpause() external {
_requireTimelockOrOwner();
_setBorrowLimit(type(uint256).max);
_setDepositLimit(type(uint256).max);
_pauseRepay(false);
_pauseWithdraw(false);
_pauseLiquidate(false);
_addInterest();
_pauseInterest(false);
currentRateInfo.lastTimestamp = uint64(block.timestamp);
}
event UpdatedMinURChange(uint256 newURChange);
/// @notice The ```setMinURChangeForExternalAddInterest``` function sets the new minimum UR change for external add interest
/// @param _newURChange The new rate change needed
function setMinURChangeForExternalAddInterest(uint256 _newURChange) external {
_requireTimelockOrOwner();
if (_newURChange > UTIL_PREC) revert MinURChangeMax();
minURChangeForExternalAddInterest = _newURChange;
emit UpdatedMinURChange(_newURChange);
}
/// @notice The ```pauseBorrow``` function sets borrow limit to 0
function pauseBorrow() external {
_requireProtocolOrOwner();
_setBorrowLimit(0);
}
/// @notice The ```setBorrowLimit``` function sets the borrow limit
/// @param _limit The new borrow limit
function setBorrowLimit(uint256 _limit) external {
_requireTimelockOrOwner();
_setBorrowLimit(_limit);
}
/// @notice The ```pauseDeposit``` function pauses deposit functionality
function pauseDeposit() external {
_requireProtocolOrOwner();
_setDepositLimit(0);
}
/// @notice The ```setDepositLimit``` function sets the deposit limit
/// @param _limit The new deposit limit
function setDepositLimit(uint256 _limit) external {
_requireTimelockOrOwner();
_setDepositLimit(_limit);
}
event SetOverBorrowAndLiquidateDelays(
uint256 oldOverBorrowDelayAfterAddCollateral,
uint256 newOverBorrowDelayAfterAddCollateral,
uint256 oldLiquidateDelayAfterBorrow,
uint256 newLiquidateDelayAfterBorrow
);
/// @notice The ```setOverBorrowAndLiquidateDelays``` function sets a few protocol delay configurations for over borrow and liquidation
/// @param _overBorrowDelayAfterAddCollateral The new over borrow delay after adding collateral
/// @param _liquidateDelayAfterBorrow The new liquidate delay after over borrowing
function setOverBorrowAndLiquidateDelays(
uint256 _overBorrowDelayAfterAddCollateral,
uint256 _liquidateDelayAfterBorrow
) external {
_requireTimelockOrOwner();
emit SetOverBorrowAndLiquidateDelays(
overBorrowDelayAfterAddCollateral,
_overBorrowDelayAfterAddCollateral,
liquidateDelayAfterBorrow,
_liquidateDelayAfterBorrow
);
overBorrowDelayAfterAddCollateral = _overBorrowDelayAfterAddCollateral;
liquidateDelayAfterBorrow = _liquidateDelayAfterBorrow;
}
}
ERC20.sol 365 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
SafeCast.sol 1136 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
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 uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @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
*
* _Available since v4.2._
*/
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 uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(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
*
* _Available since v2.5._
*/
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 uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(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
*
* _Available since v4.2._
*/
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 uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(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
*
* _Available since v2.5._
*/
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 uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(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
*
* _Available since v2.5._
*/
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 uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(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
*
* _Available since v2.5._
*/
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
*
* _Available since v2.5._
*/
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.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @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 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @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 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @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 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @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 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @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 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
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);
}
}
FraxlendPairConstants.sol 66 lines
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ===================== FraxlendPairConstants ========================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Primary Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// Sam Kazemian: https://github.com/samkazemian
// Travis Moore: https://github.com/FortisFortuna
// Jack Corddry: https://github.com/corddry
// Rich Gee: https://github.com/zer0blockchain
// ====================================================================
/// @title FraxlendPairConstants
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An abstract contract which contains the errors and constants for the FraxlendPair contract
abstract contract FraxlendPairConstants {
// ============================================================================================
// Constants
// ============================================================================================
// Precision settings
uint256 public constant LTV_PRECISION = 1e5; // 5 decimals
uint256 public constant LIQ_PRECISION = 1e5;
uint256 public constant UTIL_PREC = 1e5;
uint256 public constant FEE_PRECISION = 1e5;
uint256 public constant EXCHANGE_PRECISION = 1e18;
uint256 public constant DEVIATION_PRECISION = 1e5;
uint256 public constant RATE_PRECISION = 1e18;
// Protocol Fee
uint256 public constant MAX_PROTOCOL_FEE = 5e4; // 50% 1e5 precision
error Insolvent(uint256 _borrow, uint256 _collateral, uint256 _exchangeRate);
error NotEnoughBorrowCapacity(uint256 _borrow, uint256 _collateral, uint256 _exchangeRate);
error BorrowerSolvent();
error InsufficientAssetsInContract(uint256 _assets, uint256 _request);
error SlippageTooHigh(uint256 _minOut, uint256 _actual);
error BadSwapper();
error InvalidPath(address _expected, address _actual);
error BadProtocolFee();
error PastDeadline(uint256 _blockTimestamp, uint256 _deadline);
error MaxBorrowLTVLargerThanMaxLTV();
error SetterRevoked();
error ExceedsMaxOracleDeviation();
error InvalidReceiver();
error ExternalAssetVaultOnly();
error BadDirtyLiquidation();
error MinURChangeMax();
error MustWaitToOverBorrow(uint256 _lastAddCollateral, uint256 _blockDelay);
error MustWaitToLiquidate(uint256 _lastBorrow, uint256 _blockDelay);
}
FraxlendPairCore.sol 1271 lines
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ========================= FraxlendPairCore =========================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Primary Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// Sam Kazemian: https://github.com/samkazemian
// Travis Moore: https://github.com/FortisFortuna
// Jack Corddry: https://github.com/corddry
// Rich Gee: https://github.com/zer0blockchain
// ====================================================================
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {FraxlendPairAccessControl} from "./FraxlendPairAccessControl.sol";
import {FraxlendPairConstants} from "./FraxlendPairConstants.sol";
import {VaultAccount, VaultAccountingLibrary} from "./libraries/VaultAccount.sol";
import {SafeERC20} from "./libraries/SafeERC20.sol";
import {IDualOracle} from "./interfaces/IDualOracle.sol";
import {IRateCalculatorV2} from "./interfaces/IRateCalculatorV2.sol";
import {ISwapper} from "./interfaces/ISwapper.sol";
/// @title FraxlendPairCore
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An abstract contract which contains the core logic and storage for the FraxlendPair
abstract contract FraxlendPairCore is FraxlendPairAccessControl, FraxlendPairConstants, ERC20, ReentrancyGuard {
using VaultAccountingLibrary for VaultAccount;
using SafeERC20 for IERC20;
using SafeCast for uint256;
function version() external pure returns (uint256 _major, uint256 _minor, uint256 _patch) {
_major = 3;
_minor = 0;
_patch = 0;
}
// ============================================================================================
// Settings set by constructor()
// ============================================================================================
// Asset and collateral contracts
IERC20 internal immutable assetContract;
IERC20 public immutable collateralContract;
// LTV Settings
/// @notice The maximum LTV allowed for this pair before insolvency, and optional max borrow
/// @dev 1e5 precision
uint256 public maxLTV;
uint256 public maxBorrowLTV;
// Liquidation Fees
/// @notice The liquidation fee, given as a % of repayment amount, when all collateral is consumed in liquidation
/// @dev 1e5 precision
uint256 public cleanLiquidationFee;
/// @notice The liquidation fee, given as % of repayment amount, when some collateral remains for borrower
/// @dev 1e5 precision
uint256 public dirtyLiquidationFee;
/// @notice The minimum amount of collateral required to leave upon dirty liquidation
uint256 public minCollateralRequiredOnDirtyLiquidation;
/// @notice The portion of the liquidation fee given to protocol
/// @dev 1e5 precision
uint256 public protocolLiquidationFee;
// Interest Rate Calculator Contract
IRateCalculatorV2 public rateContract; // For complex rate calculations
// If provided, will only update interest rate when external add interest is called if this threshold is met from previous UR update
uint256 public minURChangeForExternalAddInterest = UTIL_PREC / 1000;
// Stores block of last added collateral to position, and then determines how long required to wait
// until a user can borrow > 50% LTV after adding collateral to prevent attack/exploitation
mapping(address => uint256) _lastAddCollateral;
uint256 public overBorrowDelayAfterAddCollateral = 1;
// Stores block of last borrow for position, and then determines how long required to wait
// until liquidation can happen after borrowing to prevent attack/exploitation
mapping(address => uint256) _lastBorrow;
uint256 public liquidateDelayAfterBorrow = 2;
// ERC20 Metadata
string internal nameOfContract;
string internal symbolOfContract;
uint8 internal immutable decimalsOfContract;
// ============================================================================================
// Storage
// ============================================================================================
/// @notice Stores information about the current interest rate
/// @dev struct is packed to reduce SLOADs. feeToProtocolRate is 1e5 precision, ratePerSec & fullUtilizationRate is 1e18 precision
CurrentRateInfo public currentRateInfo;
struct CurrentRateInfo {
uint32 lastBlock;
uint32 feeToProtocolRate; // Fee amount 1e5 precision
uint64 lastTimestamp;
uint64 ratePerSec;
uint64 fullUtilizationRate;
}
/// @notice Stores information about the current exchange rate. Collateral:Asset ratio
/// @dev Struct packed to save SLOADs. Amount of Collateral Token to buy 1e18 Asset Token
ExchangeRateInfo public exchangeRateInfo;
struct ExchangeRateInfo {
address oracle;
uint32 maxOracleDeviation; // % of larger number, 1e5 precision
uint184 lastTimestamp;
uint256 lowExchangeRate;
uint256 highExchangeRate;
}
// Contract Level Accounting
VaultAccount public totalAsset; // amount = total amount of assets, shares = total shares outstanding
VaultAccount public totalBorrow; // amount = total borrow amount with interest accrued, shares = total shares outstanding
uint256 public totalCollateral; // total amount of collateral in contract
// User Level Accounting
/// @notice Stores the balance of collateral for each user
mapping(address => uint256) public userCollateralBalance; // amount of collateral each user is backed
/// @notice Stores the balance of borrow shares for each user
mapping(address => uint256) public userBorrowShares; // represents the shares held by individuals
uint256 _prevUtilizationRate;
// NOTE: user shares of assets are represented as ERC-20 tokens and accessible via balanceOf()
// ============================================================================================
// Constructor
// ============================================================================================
/// @notice The ```constructor``` function is called on deployment
/// @param _configData abi.encode(address _asset, address _collateral, address _oracle, uint32 _maxOracleDeviation, address _rateContract, uint64 _fullUtilizationRate, uint256 _maxLTV, uint256 _cleanLiquidationFee, uint256 _dirtyLiquidationFee, uint256 _protocolLiquidationFee)
/// @param _immutables abi.encode(address _circuitBreakerAddress, address _comptrollerAddress, address _timelockAddress)
/// @param _customConfigData abi.encode(string memory _nameOfContract, string memory _symbolOfContract, uint8 _decimalsOfContract)
constructor(bytes memory _configData, bytes memory _immutables, bytes memory _customConfigData)
FraxlendPairAccessControl(_immutables)
ERC20("", "")
{
{
(
address _asset,
address _collateral,
address _oracle,
uint32 _maxOracleDeviation,
address _rateContract,
uint64 _fullUtilizationRate,
uint256 _maxLTV,
uint256 _maxBorrowLTV,
uint256 _liquidationFee,
uint256 _protocolLiquidationFee
) = abi.decode(
_configData, (address, address, address, uint32, address, uint64, uint256, uint256, uint256, uint256)
);
// Pair Settings
assetContract = IERC20(_asset);
collateralContract = IERC20(_collateral);
currentRateInfo.feeToProtocolRate = 1e4; // 10%
currentRateInfo.fullUtilizationRate = _fullUtilizationRate;
currentRateInfo.lastTimestamp = uint64(block.timestamp - 1);
currentRateInfo.lastBlock = uint32(block.number - 1);
exchangeRateInfo.oracle = _oracle;
exchangeRateInfo.maxOracleDeviation = _maxOracleDeviation;
rateContract = IRateCalculatorV2(_rateContract);
//Liquidation Fee Settings
cleanLiquidationFee = _liquidationFee;
dirtyLiquidationFee = (_liquidationFee * 90_000) / LIQ_PRECISION; // 90% of clean fee
protocolLiquidationFee = _protocolLiquidationFee;
// set maxLTV & maxBorrowLTV
maxLTV = _maxLTV;
maxBorrowLTV = _maxBorrowLTV;
}
{
(string memory _nameOfContract, string memory _symbolOfContract, uint8 _decimalsOfContract) =
abi.decode(_customConfigData, (string, string, uint8));
// ERC20 Metadata
nameOfContract = _nameOfContract;
symbolOfContract = _symbolOfContract;
decimalsOfContract = _decimalsOfContract;
// NOTE: creator should addInterest() and updateExchangeRate() at end of processing
}
}
// ============================================================================================
// Internal Helpers
// ============================================================================================
/// @notice The ```_totalAssetAvailable``` function returns the total balance of Asset Tokens in the contract
/// @param _totalAsset VaultAccount struct which stores total amount and shares for assets
/// @param _totalBorrow VaultAccount struct which stores total amount and shares for borrows
/// @param _includeVault Whether to include assets from the external asset vault, if configured in total available
/// @return The balance of Asset Tokens held by contract
function _totalAssetAvailable(VaultAccount memory _totalAsset, VaultAccount memory _totalBorrow, bool _includeVault)
internal
view
returns (uint256)
{
if (_includeVault) {
return _totalAsset.totalAmount(address(externalAssetVault)) - _totalBorrow.amount;
}
return _totalAsset.amount - _totalBorrow.amount;
}
/// @notice The ```_isSolvent``` function determines if a given borrower is solvent given an exchange rate
/// @param _borrower The borrower address to check
/// @param _exchangeRate The exchange rate, i.e. the amount of collateral to buy 1e18 asset
/// @return Whether borrower is solvent & whether borrower can borrow more assets
function _isSolvent(address _borrower, uint256 _exchangeRate) internal view returns (bool, bool) {
if (maxLTV == 0) return (true, true);
uint256 _borrowerAmount = totalBorrow.toAmount(userBorrowShares[_borrower], true);
if (_borrowerAmount == 0) return (true, true);
uint256 _collateralAmount = userCollateralBalance[_borrower];
if (_collateralAmount == 0) return (false, false);
uint256 _ltv = (((_borrowerAmount * _exchangeRate) / EXCHANGE_PRECISION) * LTV_PRECISION) / _collateralAmount;
return (_ltv <= maxLTV, _ltv <= maxBorrowLTV);
}
// ============================================================================================
// Modifiers
// ============================================================================================
/// @notice Checks for solvency AFTER executing contract code
/// @param _borrower The borrower whose solvency we will check
modifier isSolvent(address _borrower) {
_;
ExchangeRateInfo memory _exchangeRateInfo = exchangeRateInfo;
(bool __isSolvent,) = _isSolvent(_borrower, _exchangeRateInfo.highExchangeRate);
if (!__isSolvent) {
revert Insolvent(
totalBorrow.toAmount(userBorrowShares[_borrower], true),
userCollateralBalance[_borrower],
_exchangeRateInfo.highExchangeRate
);
}
}
/// @notice Checks for borrowing capacity AFTER executing contract code
/// @param _borrower The borrower whose borrow capacity we will check
modifier hasBorrowCapacity(address _borrower) {
_;
ExchangeRateInfo memory _exchangeRateInfo = exchangeRateInfo;
(, bool _canBorrow) = _isSolvent(_borrower, _exchangeRateInfo.highExchangeRate);
if (!_canBorrow) {
revert NotEnoughBorrowCapacity(
totalBorrow.toAmount(userBorrowShares[_borrower], true),
userCollateralBalance[_borrower],
_exchangeRateInfo.highExchangeRate
);
}
uint256 _borrowerAmount = totalBorrow.toAmount(userBorrowShares[_borrower], true);
uint256 _collateralAmount = userCollateralBalance[_borrower];
uint256 _ltv = (((_borrowerAmount * _exchangeRateInfo.highExchangeRate) / EXCHANGE_PRECISION) * LTV_PRECISION)
/ _collateralAmount;
// if borrow amount > 50% LTV make sure user has waited required delay first
if (_ltv > LTV_PRECISION / 2) {
if (block.number < _lastAddCollateral[_borrower] + overBorrowDelayAfterAddCollateral) {
revert MustWaitToOverBorrow(_lastAddCollateral[_borrower], overBorrowDelayAfterAddCollateral);
}
}
}
// ============================================================================================
// Functions: Interest Accumulation and Adjustment
// ============================================================================================
/// @notice The ```AddInterest``` event is emitted when interest is accrued by borrowers
/// @param interestEarned The total interest accrued by all borrowers
/// @param rate The interest rate used to calculate accrued interest
/// @param feesAmount The amount of fees paid to protocol
/// @param feesShare The amount of shares distributed to protocol
event AddInterest(uint256 interestEarned, uint256 rate, uint256 feesAmount, uint256 feesShare);
/// @notice The ```SkipAddingInterest``` event is emitted when external add interest is called byt noops due to small rate change
/// @param rateChange The rate change
event SkipAddingInterest(uint256 rateChange);
/// @notice The ```UpdateRate``` event is emitted when the interest rate is updated
/// @param oldRatePerSec The old interest rate (per second)
/// @param oldFullUtilizationRate The old full utilization rate
/// @param newRatePerSec The new interest rate (per second)
/// @param newFullUtilizationRate The new full utilization rate
event UpdateRate(
uint256 oldRatePerSec, uint256 oldFullUtilizationRate, uint256 newRatePerSec, uint256 newFullUtilizationRate
);
/// @notice The ```addInterest``` function is a public implementation of _addInterest and allows 3rd parties to trigger interest accrual
/// @return _interestEarned The amount of interest accrued by all borrowers
/// @return _feesAmount The amount of fees paid to protocol
/// @return _feesShare The amount of shares distributed to protocol
/// @return _currentRateInfo The new rate info struct
/// @return _totalAsset The new total asset struct
/// @return _totalBorrow The new total borrow struct
function addInterest(bool _returnAccounting)
external
nonReentrant
returns (
uint256 _interestEarned,
uint256 _feesAmount,
uint256 _feesShare,
CurrentRateInfo memory _currentRateInfo,
VaultAccount memory _totalAsset,
VaultAccount memory _totalBorrow
)
{
_currentRateInfo = currentRateInfo;
// the following checks whether the current utilization rate against the new utilization rate
// (including external assets available) exceeds a threshold and only updates interest if so.
// With this enabled, it's obviously possible for there to be some level of "unfair" interest
// paid by borrowers and/or earned by suppliers, but the idea is this unfairness
// should theoretically be negligible within some level of error and therefore it won't matter.
// This is in place to support lower gas & more arbitrage volume through the pair since arbitrage
// would many times only occur with small changes in asset supply or borrowed positions.
uint256 _currentUtilizationRate = _prevUtilizationRate;
uint256 _totalAssetsAvailable = totalAsset.totalAmount(address(externalAssetVault));
uint256 _newUtilizationRate =
_totalAssetsAvailable == 0 ? 0 : (UTIL_PREC * totalBorrow.amount) / _totalAssetsAvailable;
uint256 _rateChange = _newUtilizationRate > _currentUtilizationRate
? _newUtilizationRate - _currentUtilizationRate
: _currentUtilizationRate - _newUtilizationRate;
if (
_currentUtilizationRate != 0
&& _rateChange < _currentUtilizationRate * minURChangeForExternalAddInterest / UTIL_PREC
) {
emit SkipAddingInterest(_rateChange);
} else {
(, _interestEarned, _feesAmount, _feesShare, _currentRateInfo) = _addInterest();
}
if (_returnAccounting) {
_totalAsset = totalAsset;
_totalBorrow = totalBorrow;
}
}
/// @notice The ```previewAddInterest``` function
/// @return _interestEarned The amount of interest accrued by all borrowers
/// @return _feesAmount The amount of fees paid to protocol
/// @return _feesShare The amount of shares distributed to protocol
/// @return _newCurrentRateInfo The new rate info struct
/// @return _totalAsset The new total asset struct
/// @return _totalBorrow The new total borrow struct
function previewAddInterest()
public
view
returns (
uint256 _interestEarned,
uint256 _feesAmount,
uint256 _feesShare,
CurrentRateInfo memory _newCurrentRateInfo,
VaultAccount memory _totalAsset,
VaultAccount memory _totalBorrow
)
{
_newCurrentRateInfo = currentRateInfo;
// Write return values
InterestCalculationResults memory _results = _calculateInterest(_newCurrentRateInfo);
if (_results.isInterestUpdated) {
_interestEarned = _results.interestEarned;
_feesAmount = _results.feesAmount;
_feesShare = _results.feesShare;
_newCurrentRateInfo.ratePerSec = _results.newRate;
_newCurrentRateInfo.fullUtilizationRate = _results.newFullUtilizationRate;
_totalAsset = _results.totalAsset;
_totalBorrow = _results.totalBorrow;
} else {
_totalAsset = totalAsset;
_totalBorrow = totalBorrow;
}
}
struct InterestCalculationResults {
bool isInterestUpdated;
uint64 newRate;
uint64 newFullUtilizationRate;
uint256 interestEarned;
uint256 feesAmount;
uint256 feesShare;
VaultAccount totalAsset;
VaultAccount totalBorrow;
}
/// @notice The ```_calculateInterest``` function calculates the interest to be accrued and the new interest rate info
/// @param _currentRateInfo The current rate info
/// @return _results The results of the interest calculation
function _calculateInterest(CurrentRateInfo memory _currentRateInfo)
internal
view
returns (InterestCalculationResults memory _results)
{
// Short circuit if interest already calculated this block OR if interest is paused
if (_currentRateInfo.lastTimestamp != block.timestamp && !isInterestPaused) {
// Indicate that interest is updated and calculated
_results.isInterestUpdated = true;
// Write return values and use these to save gas
_results.totalAsset = totalAsset;
_results.totalBorrow = totalBorrow;
// Time elapsed since last interest update
uint256 _deltaTime = block.timestamp - _currentRateInfo.lastTimestamp;
// Total assets available including what resides in the external vault
uint256 _totalAssetsAvailable = _results.totalAsset.totalAmount(address(externalAssetVault));
// Get the utilization rate
uint256 _utilizationRate =
_totalAssetsAvailable == 0 ? 0 : (UTIL_PREC * _results.totalBorrow.amount) / _totalAssetsAvailable;
// Request new interest rate and full utilization rate from the rate calculator
(_results.newRate, _results.newFullUtilizationRate) = IRateCalculatorV2(rateContract).getNewRate(
_deltaTime, _utilizationRate, _currentRateInfo.fullUtilizationRate
);
// Calculate interest accrued
_results.interestEarned = (_deltaTime * _results.totalBorrow.amount * _results.newRate) / RATE_PRECISION;
// Accrue interest (if any) and fees iff no overflow
if (
_results.interestEarned > 0
&& _results.interestEarned + _results.totalBorrow.amount <= type(uint128).max
&& _results.interestEarned + _totalAssetsAvailable <= type(uint128).max
) {
// Increment totalBorrow and totalAsset by interestEarned
_results.totalBorrow.amount += _results.interestEarned.toUint128();
_results.totalAsset.amount += _results.interestEarned.toUint128();
if (_currentRateInfo.feeToProtocolRate > 0) {
_results.feesAmount = (_results.interestEarned * _currentRateInfo.feeToProtocolRate) / FEE_PRECISION;
_results.feesShare = (_results.feesAmount * _results.totalAsset.shares)
/ (_results.totalAsset.totalAmount(address(0)) - _results.feesAmount);
// Effects: Give new shares to this contract, effectively diluting lenders an amount equal to the fees
// We can safely cast because _feesShare < _feesAmount < interestEarned which is always less than uint128
_results.totalAsset.shares += _results.feesShare.toUint128();
}
}
}
}
/// @notice The ```_addInterest``` function is invoked prior to every external function and is used to accrue interest and update interest rate
/// @dev Can only called once per block
/// @return _isInterestUpdated True if interest was calculated
/// @return _interestEarned The amount of interest accrued by all borrowers
/// @return _feesAmount The amount of fees paid to protocol
/// @return _feesShare The amount of shares distributed to protocol
/// @return _currentRateInfo The new rate info struct
function _addInterest()
internal
returns (
bool _isInterestUpdated,
uint256 _interestEarned,
uint256 _feesAmount,
uint256 _feesShare,
CurrentRateInfo memory _currentRateInfo
)
{
// Pull from storage and set default return values
_currentRateInfo = currentRateInfo;
// store the current utilization rate as previous for next check
uint256 _totalAssetsAvailable = _totalAssetAvailable(totalAsset, totalBorrow, true);
_prevUtilizationRate = _totalAssetsAvailable == 0 ? 0 : (UTIL_PREC * totalBorrow.amount) / _totalAssetsAvailable;
// Calc interest
InterestCalculationResults memory _results = _calculateInterest(_currentRateInfo);
// Write return values only if interest was updated and calculated
if (_results.isInterestUpdated) {
_isInterestUpdated = _results.isInterestUpdated;
_interestEarned = _results.interestEarned;
_feesAmount = _results.feesAmount;
_feesShare = _results.feesShare;
// emit here so that we have access to the old values
emit UpdateRate(
_currentRateInfo.ratePerSec,
_currentRateInfo.fullUtilizationRate,
_results.newRate,
_results.newFullUtilizationRate
);
emit AddInterest(_interestEarned, _results.newRate, _feesAmount, _feesShare);
// overwrite original values
_currentRateInfo.ratePerSec = _results.newRate;
_currentRateInfo.fullUtilizationRate = _results.newFullUtilizationRate;
_currentRateInfo.lastTimestamp = uint64(block.timestamp);
_currentRateInfo.lastBlock = uint32(block.number);
// Effects: write to state
currentRateInfo = _currentRateInfo;
totalAsset = _results.totalAsset;
totalBorrow = _results.totalBorrow;
if (_feesShare > 0) _mint(address(this), _feesShare);
}
}
// ============================================================================================
// Functions: ExchangeRate
// ============================================================================================
/// @notice The ```UpdateExchangeRate``` event is emitted when the Collateral:Asset exchange rate is updated
/// @param lowExchangeRate The low exchange rate
/// @param highExchangeRate The high exchange rate
event UpdateExchangeRate(uint256 lowExchangeRate, uint256 highExchangeRate);
/// @notice The ```WarnOracleData``` event is emitted when one of the oracles has stale or otherwise problematic data
/// @param oracle The oracle address
event WarnOracleData(address oracle);
/// @notice The ```updateExchangeRate``` function is the external implementation of _updateExchangeRate.
/// @dev This function is invoked at most once per block as these queries can be expensive
/// @return _isBorrowAllowed True if deviation is within bounds
/// @return _lowExchangeRate The low exchange rate
/// @return _highExchangeRate The high exchange rate
function updateExchangeRate()
external
nonReentrant
returns (bool _isBorrowAllowed, uint256 _lowExchangeRate, uint256 _highExchangeRate)
{
return _updateExchangeRate();
}
/// @notice The ```_updateExchangeRate``` function retrieves the latest exchange rate. i.e how much collateral to buy 1e18 asset.
/// @dev This function is invoked at most once per block as these queries can be expensive
/// @return _isBorrowAllowed True if deviation is within bounds
/// @return _lowExchangeRate The low exchange rate
/// @return _highExchangeRate The high exchange rate
function _updateExchangeRate()
internal
returns (bool _isBorrowAllowed, uint256 _lowExchangeRate, uint256 _highExchangeRate)
{
// Pull from storage to save gas and set default return values
ExchangeRateInfo memory _exchangeRateInfo = exchangeRateInfo;
// Short circuit if already updated this block
if (_exchangeRateInfo.lastTimestamp != block.timestamp) {
// Get the latest exchange rate from the dual oracle
bool _oneOracleBad;
(_oneOracleBad, _lowExchangeRate, _highExchangeRate) = IDualOracle(_exchangeRateInfo.oracle).getPrices();
// If one oracle is bad data, emit an event for off-chain monitoring
if (_oneOracleBad) emit WarnOracleData(_exchangeRateInfo.oracle);
// Effects: Bookkeeping and write to storage
_exchangeRateInfo.lastTimestamp = uint184(block.timestamp);
_exchangeRateInfo.lowExchangeRate = _lowExchangeRate;
_exchangeRateInfo.highExchangeRate = _highExchangeRate;
exchangeRateInfo = _exchangeRateInfo;
emit UpdateExchangeRate(_lowExchangeRate, _highExchangeRate);
} else {
// Use default return values if already updated this block
_lowExchangeRate = _exchangeRateInfo.lowExchangeRate;
_highExchangeRate = _exchangeRateInfo.highExchangeRate;
}
uint256 _deviation = (
DEVIATION_PRECISION * (_exchangeRateInfo.highExchangeRate - _exchangeRateInfo.lowExchangeRate)
) / _exchangeRateInfo.highExchangeRate;
if (_deviation <= _exchangeRateInfo.maxOracleDeviation) {
_isBorrowAllowed = true;
}
}
// ============================================================================================
// Functions: Lending
// ============================================================================================
/// @notice The ```Deposit``` event fires when a user deposits assets to the pair
/// @param caller the msg.sender
/// @param owner the account the fTokens are sent to
/// @param assets the amount of assets deposited
/// @param shares the number of fTokens minted
event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares);
/// @notice The ```_deposit``` function is the internal implementation for lending assets
/// @dev Caller must invoke ```ERC20.approve``` on the Asset Token contract prior to calling function
/// @param _totalAsset An in memory VaultAccount struct representing the total amounts and shares for the Asset Token
/// @param _amount The amount of Asset Token to be transferred
/// @param _shares The amount of Asset Shares (fTokens) to be minted
/// @param _receiver The address to receive the Asset Shares (fTokens)
/// @param _shouldTransfer Whether asset tokens should be deposited from the sender
function _deposit(
VaultAccount memory _totalAsset,
uint128 _amount,
uint128 _shares,
address _receiver,
bool _shouldTransfer
) internal {
// Effects: bookkeeping
_totalAsset.amount += _amount;
_totalAsset.shares += _shares;
// Effects: write back to storage
_mint(_receiver, _shares);
totalAsset = _totalAsset;
// Interactions
if (_shouldTransfer) {
assetContract.safeTransferFrom(msg.sender, address(this), _amount);
if (address(externalAssetVault) != address(0) && _amount > _totalAsset.totalAmount(address(0)) / 1000) {
// if the external asset vault is over utilized or this pair is over allocated,
// return the amount being deposited to the vault
externalAssetVault.whitelistUpdate(true);
uint256 _assetsUtilized = externalAssetVault.vaultUtilization(address(this));
bool _vaultOverUtilized =
1e18 * externalAssetVault.totalAssetsUtilized() / externalAssetVault.totalAssets() > 1e18 * 8 / 10;
bool _pairOverAllocation = _assetsUtilized > externalAssetVault.vaultMaxAllocation(address(this));
if (_vaultOverUtilized || _pairOverAllocation) {
uint256 _extAmount = _assetsUtilized > _amount ? _amount : _assetsUtilized;
_withdrawToVault(_extAmount);
}
}
}
emit Deposit(msg.sender, _receiver, _amount, _shares);
}
function previewDeposit(uint256 _assets) external view returns (uint256 _sharesReceived) {
(,,,, VaultAccount memory _totalAsset,) = previewAddInterest();
_sharesReceived = _totalAsset.toShares(_assets, false);
}
/// @notice The ```deposit``` function allows a user to Lend Assets by specifying the amount of Asset Tokens to lend
/// @dev Caller must invoke ```ERC20.approve``` on the Asset Token contract prior to calling function
/// @param _amount The amount of Asset Token to transfer to Pair
/// @param _receiver The address to receive the Asset Shares (fTokens)
/// @return _sharesReceived The number of fTokens received for the deposit
function deposit(uint256 _amount, address _receiver) external nonReentrant returns (uint256 _sharesReceived) {
if (_receiver == address(0)) revert InvalidReceiver();
// Accrue interest if necessary
_addInterest();
// Pull from storage to save gas
VaultAccount memory _totalAsset = totalAsset;
// Check if this deposit will violate the deposit limit
if (depositLimit < _totalAsset.totalAmount(address(0)) + _amount) revert ExceedsDepositLimit();
// Calculate the number of fTokens to mint
_sharesReceived = _totalAsset.toShares(_amount, false);
// Execute the deposit effects
_deposit(_totalAsset, _amount.toUint128(), _sharesReceived.toUint128(), _receiver, true);
}
/// @notice The ```_depositFromVault``` function deposits assets here from the configured external vault if available
/// @param _amount The amount of Asset Tokens to be transferred from the vault
/// @return _sharesReceived The number of Asset Shares (fTokens) to mint for Asset Tokens
function _depositFromVault(uint256 _amount) internal returns (uint256 _sharesReceived) {
// Pull from storage to save gas
VaultAccount memory _totalAsset = totalAsset;
// Calculate the number of fTokens to mint
_sharesReceived = _totalAsset.toShares(_amount, false);
// Withdraw assets from external vault here
externalAssetVault.whitelistWithdraw(_amount);
// Execute the deposit effects
_deposit(_totalAsset, _amount.toUint128(), _sharesReceived.toUint128(), address(externalAssetVault), false);
}
/// @notice The ```_withdrawToVault``` function withdraws assets back to an external vault if previously used
/// @param _amountToReturn The amount of Asset Tokens to be transferred to the vault
/// @return _shares The number of Asset Shares (fTokens) to burn for Asset Tokens
function _withdrawToVault(uint256 _amountToReturn) internal returns (uint256 _shares) {
// Pull from storage to save gas
VaultAccount memory _totalAsset = totalAsset;
// Calculate the number of shares to burn based on the assets to transfer
_shares = _totalAsset.toShares(_amountToReturn, true);
uint256 _vaultBal = balanceOf(address(externalAssetVault));
_shares = _vaultBal < _shares ? _vaultBal : _shares;
// Deposit assets to external vault
assetContract.approve(address(externalAssetVault), _amountToReturn);
externalAssetVault.whitelistDeposit(_amountToReturn);
// Execute the withdraw effects for vault
// receive assets here in order to call whitelistDeposit and handle accounting in external vault
_redeem(
_totalAsset,
_amountToReturn.toUint128(),
_shares.toUint128(),
address(this),
address(externalAssetVault),
true
);
}
function previewMint(uint256 _shares) external view returns (uint256 _amount) {
(,,,, VaultAccount memory _totalAsset,) = previewAddInterest();
_amount = _totalAsset.toAmount(_shares, true);
}
function mint(uint256 _shares, address _receiver) external nonReentrant returns (uint256 _amount) {
if (_receiver == address(0)) revert InvalidReceiver();
// Accrue interest if necessary
_addInterest();
// Pull from storage to save gas
VaultAccount memory _totalAsset = totalAsset;
// Calculate the number of assets to transfer based on the shares to mint
_amount = _totalAsset.toAmount(_shares, true);
// Check if this deposit will violate the deposit limit
if (depositLimit < _totalAsset.totalAmount(address(0)) + _amount) revert ExceedsDepositLimit();
// Execute the deposit effects
_deposit(_totalAsset, _amount.toUint128(), _shares.toUint128(), _receiver, true);
}
/// @notice The ```Withdraw``` event fires when a user redeems their fTokens for the underlying asset
/// @param caller the msg.sender
/// @param receiver The address to which the underlying asset will be transferred to
/// @param owner The owner of the fTokens
/// @param assets The assets transferred
/// @param shares The number of fTokens burned
event Withdraw(
address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares
);
/// @notice The ```_redeem``` function is an internal implementation which allows a Lender to pull their Asset Tokens out of the Pair
/// @dev Caller must invoke ```ERC20.approve``` on the Asset Token contract prior to calling function
/// @param _totalAsset An in-memory VaultAccount struct which holds the total amount of Asset Tokens and the total number of Asset Shares (fTokens)
/// @param _amountToReturn The number of Asset Tokens to return
/// @param _shares The number of Asset Shares (fTokens) to burn
/// @param _receiver The address to which the Asset Tokens will be transferred
/// @param _owner The owner of the Asset Shares (fTokens)
function _redeem(
VaultAccount memory _totalAsset,
uint128 _amountToReturn,
uint128 _shares,
address _receiver,
address _owner,
bool _skipAllowanceCheck
) internal {
// Check for sufficient allowance/approval if necessary
if (msg.sender != _owner && !_skipAllowanceCheck) {
uint256 allowed = allowance(_owner, msg.sender);
// NOTE: This will revert on underflow ensuring that allowance > shares
if (allowed != type(uint256).max) _approve(_owner, msg.sender, allowed - _shares);
}
// Check for sufficient withdraw liquidity (not strictly necessary because balance will underflow)
uint256 _totAssetsAvailable = _totalAssetAvailable(_totalAsset, totalBorrow, true);
if (_totAssetsAvailable < _amountToReturn) {
revert InsufficientAssetsInContract(_totAssetsAvailable, _amountToReturn);
}
// If we're redeeming back to the vault, don't deposit from the vault
if (_owner != address(externalAssetVault)) {
uint256 _localAssetsAvailable = _totalAssetAvailable(_totalAsset, totalBorrow, false);
if (_localAssetsAvailable < _amountToReturn) {
uint256 _vaultAmt = _amountToReturn - _localAssetsAvailable;
_depositFromVault(_vaultAmt);
// Rewrite to memory, now it's the latest value!
_totalAsset = totalAsset;
}
}
// Effects: bookkeeping
_totalAsset.amount -= _amountToReturn;
_totalAsset.shares -= _shares;
// Effects: write to storage
totalAsset = _totalAsset;
_burn(_owner, _shares);
// Interactions
if (_receiver != address(this)) {
assetContract.safeTransfer(_receiver, _amountToReturn);
}
emit Withdraw(msg.sender, _receiver, _owner, _amountToReturn, _shares);
}
function previewRedeem(uint256 _shares) external view returns (uint256 _assets) {
(,,,, VaultAccount memory _totalAsset,) = previewAddInterest();
_assets = _totalAsset.toAmount(_shares, false);
}
/// @notice The ```redeem``` function allows the caller to redeem their Asset Shares for Asset Tokens
/// @param _shares The number of Asset Shares (fTokens) to burn for Asset Tokens
/// @param _receiver The address to which the Asset Tokens will be transferred
/// @param _owner The owner of the Asset Shares (fTokens)
/// @return _amountToReturn The amount of Asset Tokens to be transferred
function redeem(uint256 _shares, address _receiver, address _owner)
external
nonReentrant
returns (uint256 _amountToReturn)
{
if (_receiver == address(0)) revert InvalidReceiver();
// Check if withdraw is paused and revert if necessary
if (isWithdrawPaused) revert WithdrawPaused();
// Accrue interest if necessary
_addInterest();
// Pull from storage to save gas
VaultAccount memory _totalAsset = totalAsset;
// Calculate the number of assets to transfer based on the shares to burn
_amountToReturn = _totalAsset.toAmount(_shares, false);
// Execute the withdraw effects
_redeem(_totalAsset, _amountToReturn.toUint128(), _shares.toUint128(), _receiver, _owner, false);
}
/// @notice The ```previewWithdraw``` function returns the number of Asset Shares (fTokens) that would be burned for a given amount of Asset Tokens
/// @param _amount The amount of Asset Tokens to be withdrawn
/// @return _sharesToBurn The number of shares that would be burned
function previewWithdraw(uint256 _amount) external view returns (uint256 _sharesToBurn) {
(,,,, VaultAccount memory _totalAsset,) = previewAddInterest();
_sharesToBurn = _totalAsset.toShares(_amount, true);
}
/// @notice The ```withdraw``` function allows the caller to withdraw their Asset Tokens for a given amount of fTokens
/// @param _amount The amount to withdraw
/// @param _receiver The address to which the Asset Tokens will be transferred
/// @param _owner The owner of the Asset Shares (fTokens)
/// @return _sharesToBurn The number of shares (fTokens) that were burned
function withdraw(uint256 _amount, address _receiver, address _owner)
external
nonReentrant
returns (uint256 _sharesToBurn)
{
if (_receiver == address(0)) revert InvalidReceiver();
// Check if withdraw is paused and revert if necessary
if (isWithdrawPaused) revert WithdrawPaused();
// Accrue interest if necessary
_addInterest();
// Pull from storage to save gas
VaultAccount memory _totalAsset = totalAsset;
// Calculate the number of shares to burn based on the amount to withdraw
_sharesToBurn = _totalAsset.toShares(_amount, true);
// Execute the withdraw effects
_redeem(_totalAsset, _amount.toUint128(), _sharesToBurn.toUint128(), _receiver, _owner, false);
}
// ============================================================================================
// Functions: Borrowing
// ============================================================================================
/// @notice The ```BorrowAsset``` event is emitted when a borrower increases their position
/// @param _borrower The borrower whose account was debited
/// @param _receiver The address to which the Asset Tokens were transferred
/// @param _borrowAmount The amount of Asset Tokens transferred
/// @param _sharesAdded The number of Borrow Shares the borrower was debited
event BorrowAsset(
address indexed _borrower, address indexed _receiver, uint256 _borrowAmount, uint256 _sharesAdded
);
/// @notice The ```_borrowAsset``` function is the internal implementation for borrowing assets
/// @param _borrowAmount The amount of the Asset Token to borrow
/// @param _receiver The address to receive the Asset Tokens
/// @return _sharesAdded The amount of borrow shares the msg.sender will be debited
function _borrowAsset(uint128 _borrowAmount, address _receiver) internal returns (uint256 _sharesAdded) {
// Get borrow accounting from storage to save gas
VaultAccount memory _totalBorrow = totalBorrow;
// Check available capital (not strictly necessary because balance will underflow, but better revert message)
uint256 _totalAssetsAvailable = _totalAssetAvailable(totalAsset, _totalBorrow, true);
if (_totalAssetsAvailable < _borrowAmount) {
revert InsufficientAssetsInContract(_totalAssetsAvailable, _borrowAmount);
}
uint256 _localAssetsAvailable = _totalAssetAvailable(totalAsset, _totalBorrow, false);
if (_localAssetsAvailable < _borrowAmount) {
uint256 _externalAmt = _borrowAmount - _localAssetsAvailable;
_depositFromVault(_externalAmt);
}
// Calculate the number of shares to add based on the amount to borrow
_sharesAdded = _totalBorrow.toShares(_borrowAmount, true);
// Effects: Bookkeeping to add shares & amounts to total Borrow accounting
_totalBorrow.amount += _borrowAmount;
_totalBorrow.shares += _sharesAdded.toUint128();
// NOTE: we can safely cast here because shares are always less than amount and _borrowAmount is uint128
// Effects: write back to storage
totalBorrow = _totalBorrow;
userBorrowShares[msg.sender] += _sharesAdded;
_lastBorrow[msg.sender] = block.number;
// Interactions
if (_receiver != address(this)) {
assetContract.safeTransfer(_receiver, _borrowAmount);
}
emit BorrowAsset(msg.sender, _receiver, _borrowAmount, _sharesAdded);
}
/// @notice The ```borrowAsset``` function allows a user to open/increase a borrow position
/// @dev Borrower must call ```ERC20.approve``` on the Collateral Token contract if applicable
/// @param _borrowAmount The amount of Asset Token to borrow
/// @param _collateralAmount The amount of Collateral Token to transfer to Pair
/// @param _receiver The address which will receive the Asset Tokens
/// @return _shares The number of borrow Shares the msg.sender will be debited
function borrowAsset(uint256 _borrowAmount, uint256 _collateralAmount, address _receiver)
external
nonReentrant
isSolvent(msg.sender)
hasBorrowCapacity(msg.sender)
returns (uint256 _shares)
{
if (_receiver == address(0)) revert InvalidReceiver();
// Accrue interest if necessary
_addInterest();
// Check if borrow will violate the borrow limit and revert if necessary
if (borrowLimit < totalBorrow.amount + _borrowAmount) revert ExceedsBorrowLimit();
// Update _exchangeRate and check if borrow is allowed based on deviation
(bool _isBorrowAllowed,,) = _updateExchangeRate();
if (!_isBorrowAllowed) revert ExceedsMaxOracleDeviation();
// Only add collateral if necessary
if (_collateralAmount > 0) {
_addCollateral(msg.sender, _collateralAmount, msg.sender);
}
// Effects: Call internal borrow function
_shares = _borrowAsset(_borrowAmount.toUint128(), _receiver);
}
/// @notice The ```AddCollateral``` event is emitted when a borrower adds collateral to their position
/// @param sender The source of funds for the new collateral
/// @param borrower The borrower account for which the collateral should be credited
/// @param collateralAmount The amount of Collateral Token to be transferred
event AddCollateral(address indexed sender, address indexed borrower, uint256 collateralAmount);
/// @notice The ```_addCollateral``` function is an internal implementation for adding collateral to a borrowers position
/// @param _sender The source of funds for the new collateral
/// @param _collateralAmount The amount of Collateral Token to be transferred
/// @param _borrower The borrower account for which the collateral should be credited
function _addCollateral(address _sender, uint256 _collateralAmount, address _borrower) internal {
// Effects: write to state
userCollateralBalance[_borrower] += _collateralAmount;
totalCollateral += _collateralAmount;
_lastAddCollateral[_borrower] = block.number;
// Interactions
if (_sender != address(this)) {
collateralContract.safeTransferFrom(_sender, address(this), _collateralAmount);
}
emit AddCollateral(_sender, _borrower, _collateralAmount);
}
/// @notice The ```addCollateral``` function allows the caller to add Collateral Token to a borrowers position
/// @dev msg.sender must call ERC20.approve() on the Collateral Token contract prior to invocation
/// @param _collateralAmount The amount of Collateral Token to be added to borrower's position
/// @param _borrower The account to be credited
function addCollateral(uint256 _collateralAmount, address _borrower) external nonReentrant {
if (_borrower == address(0)) revert InvalidReceiver();
_addInterest();
_addCollateral(msg.sender, _collateralAmount, _borrower);
}
/// @notice The ```RemoveCollateral``` event is emitted when collateral is removed from a borrower's position
/// @param _sender The account from which funds are transferred
/// @param _collateralAmount The amount of Collateral Token to be transferred
/// @param _receiver The address to which Collateral Tokens will be transferred
event RemoveCollateral(
address indexed _sender, uint256 _collateralAmount, address indexed _receiver, address indexed _borrower
);
/// @notice The ```_removeCollateral``` function is the internal implementation for removing collateral from a borrower's position
/// @param _collateralAmount The amount of Collateral Token to remove from the borrower's position
/// @param _receiver The address to r...
// [truncated — 63423 bytes total]
Timelock2Step.sol 123 lines
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ========================== Timelock2Step ===========================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Primary Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
/// @title Timelock2Step
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @dev Inspired by the OpenZeppelin's Ownable2Step contract
/// @notice An abstract contract which contains 2-step transfer and renounce logic for a timelock address
abstract contract Timelock2Step {
/// @notice The pending timelock address
address public pendingTimelockAddress;
/// @notice The current timelock address
address public timelockAddress;
constructor() {
timelockAddress = msg.sender;
}
/// @notice Emitted when timelock is transferred
error OnlyTimelock();
/// @notice Emitted when pending timelock is transferred
error OnlyPendingTimelock();
/// @notice The ```TimelockTransferStarted``` event is emitted when the timelock transfer is initiated
/// @param previousTimelock The address of the previous timelock
/// @param newTimelock The address of the new timelock
event TimelockTransferStarted(address indexed previousTimelock, address indexed newTimelock);
/// @notice The ```TimelockTransferred``` event is emitted when the timelock transfer is completed
/// @param previousTimelock The address of the previous timelock
/// @param newTimelock The address of the new timelock
event TimelockTransferred(address indexed previousTimelock, address indexed newTimelock);
/// @notice The ```_isSenderTimelock``` function checks if msg.sender is current timelock address
/// @return Whether or not msg.sender is current timelock address
function _isSenderTimelock() internal view returns (bool) {
return msg.sender == timelockAddress;
}
/// @notice The ```_requireTimelock``` function reverts if msg.sender is not current timelock address
function _requireTimelock() internal view {
if (msg.sender != timelockAddress) revert OnlyTimelock();
}
/// @notice The ```_isSenderPendingTimelock``` function checks if msg.sender is pending timelock address
/// @return Whether or not msg.sender is pending timelock address
function _isSenderPendingTimelock() internal view returns (bool) {
return msg.sender == pendingTimelockAddress;
}
/// @notice The ```_requirePendingTimelock``` function reverts if msg.sender is not pending timelock address
function _requirePendingTimelock() internal view {
if (msg.sender != pendingTimelockAddress) revert OnlyPendingTimelock();
}
/// @notice The ```_transferTimelock``` function initiates the timelock transfer
/// @dev This function is to be implemented by a public function
/// @param _newTimelock The address of the nominated (pending) timelock
function _transferTimelock(address _newTimelock) internal {
pendingTimelockAddress = _newTimelock;
emit TimelockTransferStarted(timelockAddress, _newTimelock);
}
/// @notice The ```_acceptTransferTimelock``` function completes the timelock transfer
/// @dev This function is to be implemented by a public function
function _acceptTransferTimelock() internal {
pendingTimelockAddress = address(0);
_setTimelock(msg.sender);
}
/// @notice The ```_setTimelock``` function sets the timelock address
/// @dev This function is to be implemented by a public function
/// @param _newTimelock The address of the new timelock
function _setTimelock(address _newTimelock) internal {
emit TimelockTransferred(timelockAddress, _newTimelock);
timelockAddress = _newTimelock;
}
/// @notice The ```transferTimelock``` function initiates the timelock transfer
/// @dev Must be called by the current timelock
/// @param _newTimelock The address of the nominated (pending) timelock
function transferTimelock(address _newTimelock) external virtual {
_requireTimelock();
_transferTimelock(_newTimelock);
}
/// @notice The ```acceptTransferTimelock``` function completes the timelock transfer
/// @dev Must be called by the pending timelock
function acceptTransferTimelock() external virtual {
_requirePendingTimelock();
_acceptTransferTimelock();
}
/// @notice The ```renounceTimelock``` function renounces the timelock after setting pending timelock to current timelock
/// @dev Pending timelock must be set to current timelock before renouncing, creating a 2-step renounce process
function renounceTimelock() external virtual {
_requireTimelock();
_requirePendingTimelock();
_transferTimelock(address(0));
_setTimelock(address(0));
}
}
SafeERC20.sol 67 lines
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {SafeERC20 as OZSafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
// solhint-disable avoid-low-level-calls
// solhint-disable max-line-length
/// @title SafeERC20 provides helper functions for safe transfers as well as safe metadata access
/// @author Library originally written by @Boring_Crypto github.com/boring_crypto, modified by Drake Evans (Frax Finance) github.com/drakeevans
/// @dev original: https://github.com/boringcrypto/BoringSolidity/blob/fed25c5d43cb7ce20764cd0b838e21a02ea162e9/contracts/libraries/BoringERC20.sol
library SafeERC20 {
bytes4 private constant SIG_SYMBOL = 0x95d89b41; // symbol()
bytes4 private constant SIG_NAME = 0x06fdde03; // name()
bytes4 private constant SIG_DECIMALS = 0x313ce567; // decimals()
function returnDataToString(bytes memory data) internal pure returns (string memory) {
if (data.length >= 64) {
return abi.decode(data, (string));
} else if (data.length == 32) {
uint8 i = 0;
while (i < 32 && data[i] != 0) {
i++;
}
bytes memory bytesArray = new bytes(i);
for (i = 0; i < 32 && data[i] != 0; i++) {
bytesArray[i] = data[i];
}
return string(bytesArray);
} else {
return "???";
}
}
/// @notice Provides a safe ERC20.symbol version which returns '???' as fallback string.
/// @param token The address of the ERC-20 token contract.
/// @return (string) Token symbol.
function safeSymbol(IERC20 token) internal view returns (string memory) {
(bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_SYMBOL));
return success ? returnDataToString(data) : "???";
}
/// @notice Provides a safe ERC20.name version which returns '???' as fallback string.
/// @param token The address of the ERC-20 token contract.
/// @return (string) Token name.
function safeName(IERC20 token) internal view returns (string memory) {
(bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_NAME));
return success ? returnDataToString(data) : "???";
}
/// @notice Provides a safe ERC20.decimals version which returns '18' as fallback value.
/// @param token The address of the ERC-20 token contract.
/// @return (uint8) Token decimals.
function safeDecimals(IERC20 token) internal view returns (uint8) {
(bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_DECIMALS));
return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;
}
function safeTransfer(IERC20 token, address to, uint256 value) internal {
OZSafeERC20.safeTransfer(token, to, value);
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
OZSafeERC20.safeTransferFrom(token, from, to, value);
}
}
VaultAccount.sol 48 lines
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
import {IERC4626Extended} from "../interfaces/IERC4626Extended.sol";
struct VaultAccount {
uint128 amount; // Total amount, analogous to market cap
uint128 shares; // Total shares, analogous to shares outstanding
}
/// @title VaultAccount Library
/// @author Drake Evans (Frax Finance) github.com/drakeevans, modified from work by @Boring_Crypto github.com/boring_crypto
/// @notice Provides a library for use with the VaultAccount struct, provides convenient math implementations
/// @dev Uses uint128 to save on storage
library VaultAccountingLibrary {
function totalAmount(VaultAccount memory total, address vault) internal view returns (uint256 amount) {
if (vault == address(0)) {
return total.amount;
}
return total.amount + IERC4626Extended(vault).totalAvailableAssetsForVault(address(this));
}
/// @notice Calculates the shares value in relationship to `amount` and `total`
/// @dev Given an amount, return the appropriate number of shares
function toShares(VaultAccount memory total, uint256 amount, bool roundUp) internal pure returns (uint256 shares) {
if (total.amount == 0) {
shares = amount;
} else {
shares = (amount * total.shares) / total.amount;
if (roundUp && (shares * total.amount) / total.shares < amount) {
shares = shares + 1;
}
}
}
/// @notice Calculates the amount value in relationship to `shares` and `total`
/// @dev Given a number of shares, returns the appropriate amount
function toAmount(VaultAccount memory total, uint256 shares, bool roundUp) internal pure returns (uint256 amount) {
if (total.shares == 0) {
amount = shares;
} else {
amount = (shares * total.amount) / total.shares;
if (roundUp && (amount * total.shares) / total.amount < shares) {
amount = amount + 1;
}
}
}
}
IRateCalculatorV2.sol 13 lines
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
interface IRateCalculatorV2 {
function name() external view returns (string memory);
function version() external view returns (uint256, uint256, uint256);
function getNewRate(uint256 _deltaTime, uint256 _utilization, uint64 _maxInterest)
external
view
returns (uint64 _newRatePerSec, uint64 _newMaxInterest);
}
ISwapper.sol 12 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
interface ISwapper {
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
FraxlendPairAccessControl.sol 176 lines
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ==================== FraxlendPairAccessControl =====================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Primary Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
import {Ownable2Step, Ownable} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Timelock2Step} from "./Timelock2Step.sol";
import {FraxlendPairAccessControlErrors} from "./FraxlendPairAccessControlErrors.sol";
import {IERC4626Extended} from "./interfaces/IERC4626Extended.sol";
/// @title FraxlendPairAccessControl
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An abstract contract which contains the access control logic for FraxlendPair
abstract contract FraxlendPairAccessControl is Timelock2Step, Ownable2Step, FraxlendPairAccessControlErrors {
// Deployer
address public immutable DEPLOYER_ADDRESS;
// Admin contracts
address public circuitBreakerAddress;
// External asset vault
IERC4626Extended public externalAssetVault;
// access control
uint256 public borrowLimit = type(uint256).max;
uint256 public depositLimit = type(uint256).max;
bool public isRepayPaused;
bool public isWithdrawPaused;
bool public isLiquidatePaused;
bool public isInterestPaused;
/// @param _immutables abi.encode(address _circuitBreakerAddress, address _comptrollerAddress, address _timelockAddress)
constructor(bytes memory _immutables) Timelock2Step() Ownable2Step() {
// Handle Immutables Configuration
(address _circuitBreakerAddress, address _comptrollerAddress, address _timelockAddress) =
abi.decode(_immutables, (address, address, address));
_setTimelock(_timelockAddress);
_transferOwnership(_comptrollerAddress);
// Deployer contract
DEPLOYER_ADDRESS = msg.sender;
circuitBreakerAddress = _circuitBreakerAddress;
}
// ============================================================================================
// Functions: Access Control
// ============================================================================================
function _requireProtocolOrOwner() internal view {
if (
msg.sender != circuitBreakerAddress && msg.sender != owner() && msg.sender != DEPLOYER_ADDRESS
&& msg.sender != timelockAddress
) {
revert OnlyProtocolOrOwner();
}
}
function _requireTimelockOrOwner() internal view {
if (msg.sender != owner() && msg.sender != timelockAddress) {
revert OnlyTimelockOrOwner();
}
}
/// @notice The ```SetBorrowLimit``` event is emitted when the borrow limit is set
/// @param limit The new borrow limit
event SetBorrowLimit(uint256 limit);
function _setBorrowLimit(uint256 _limit) internal {
borrowLimit = _limit;
emit SetBorrowLimit(_limit);
}
/// @notice The ```SetDepositLimit``` event is emitted when the deposit limit is set
/// @param limit The new deposit limit
event SetDepositLimit(uint256 limit);
function _setDepositLimit(uint256 _limit) internal {
depositLimit = _limit;
emit SetDepositLimit(_limit);
}
/// @notice The ```PauseRepay``` event is emitted when repay is paused or unpaused
/// @param isPaused The new paused state
event PauseRepay(bool isPaused);
function _pauseRepay(bool _isPaused) internal {
isRepayPaused = _isPaused;
emit PauseRepay(_isPaused);
}
/// @notice The ```PauseWithdraw``` event is emitted when withdraw is paused or unpaused
/// @param isPaused The new paused state
event PauseWithdraw(bool isPaused);
function _pauseWithdraw(bool _isPaused) internal {
isWithdrawPaused = _isPaused;
emit PauseWithdraw(_isPaused);
}
/// @notice The ```PauseLiquidate``` event is emitted when liquidate is paused or unpaused
/// @param isPaused The new paused state
event PauseLiquidate(bool isPaused);
function _pauseLiquidate(bool _isPaused) internal {
isLiquidatePaused = _isPaused;
emit PauseLiquidate(_isPaused);
}
/// @notice The ```PauseInterest``` event is emitted when interest is paused or unpaused
/// @param isPaused The new paused state
event PauseInterest(bool isPaused);
function _pauseInterest(bool _isPaused) internal {
isInterestPaused = _isPaused;
emit PauseInterest(_isPaused);
}
/// @notice The ```SetExternalAssetVault``` event is emitted when the external vault account is changed
event SetExternalAssetVault(address oldVault, address newVault);
function _setExternalAssetVault(IERC4626Extended vault) internal {
IERC4626Extended _oldVault = externalAssetVault;
externalAssetVault = vault;
emit SetExternalAssetVault(address(_oldVault), address(vault));
}
/// @notice The ```setExternalAssetVault``` function is called to set the external asset vault for the pair
/// @param vault The new external asset vault
function setExternalAssetVault(IERC4626Extended vault) external {
_requireTimelock();
_setExternalAssetVault(vault);
}
/// @notice The ```SetCircuitBreaker``` event is emitted when the circuit breaker address is set
/// @param oldCircuitBreaker The old circuit breaker address
/// @param newCircuitBreaker The new circuit breaker address
event SetCircuitBreaker(address oldCircuitBreaker, address newCircuitBreaker);
/// @notice The ```_setCircuitBreaker``` function is called to set the circuit breaker address
/// @param _newCircuitBreaker The new circuit breaker address
function _setCircuitBreaker(address _newCircuitBreaker) internal {
address oldCircuitBreaker = circuitBreakerAddress;
circuitBreakerAddress = _newCircuitBreaker;
emit SetCircuitBreaker(oldCircuitBreaker, _newCircuitBreaker);
}
/// @notice The ```setCircuitBreaker``` function is called to set the circuit breaker address
/// @param _newCircuitBreaker The new circuit breaker address
function setCircuitBreaker(address _newCircuitBreaker) external virtual {
_requireTimelock();
_setCircuitBreaker(_newCircuitBreaker);
}
}
IDualOracle.sol 36 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IDualOracle is IERC165 {
function ORACLE_PRECISION() external view returns (uint256);
function BASE_TOKEN_0() external view returns (address);
function BASE_TOKEN_0_DECIMALS() external view returns (uint256);
function BASE_TOKEN_1() external view returns (address);
function BASE_TOKEN_1_DECIMALS() external view returns (uint256);
function decimals() external view returns (uint8);
function getPricesNormalized() external view returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh);
function getPrices() external view returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh);
function name() external view returns (string memory);
function NORMALIZATION_0() external view returns (int256);
function NORMALIZATION_1() external view returns (int256);
function QUOTE_TOKEN_0() external view returns (address);
function QUOTE_TOKEN_0_DECIMALS() external view returns (uint256);
function QUOTE_TOKEN_1() external view returns (address);
function QUOTE_TOKEN_1_DECIMALS() external view returns (uint256);
}
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20.sol";
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
* 0 before setting it to a non-zero value.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
IERC4626Extended.sol 22 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
interface IERC4626Extended is IERC4626 {
function vaultUtilization(address vault) external view returns (uint256);
function vaultMaxAllocation(address vault) external view returns (uint256);
function totalAssetsUtilized() external view returns (uint256);
function totalAvailableAssets() external view returns (uint256);
function totalAvailableAssetsForVault(address vault) external view returns (uint256);
function whitelistUpdate(bool onlyCaller) external;
function whitelistWithdraw(uint256 amount) external;
function whitelistDeposit(uint256 amount) external;
}
Ownable2Step.sol 57 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.0;
import "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
_transferOwnership(sender);
}
}
FraxlendPairAccessControlErrors.sol 37 lines
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ================ FraxlendPairAccessControlErrors ===================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Primary Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
/// @title FraxlendPairAccessControlErrors
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An abstract contract which contains the errors for the Access Control contract
abstract contract FraxlendPairAccessControlErrors {
error OnlyProtocolOrOwner();
error OnlyTimelockOrOwner();
error ExceedsBorrowLimit();
error AccessControlRevoked();
error RepayPaused();
error ExceedsDepositLimit();
error WithdrawPaused();
error LiquidatePaused();
error InterestPaused();
}
IERC165.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 IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
IERC4626.sol 232 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4626.sol)
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20.sol";
import "../token/ERC20/extensions/IERC20Metadata.sol";
/**
* @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*
* _Available since v4.7._
*/
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
function asset() external view returns (address assetTokenAddress);
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() external view returns (uint256 totalManagedAssets);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) external view returns (uint256 shares);
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) external view returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) external view returns (uint256 shares);
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address receiver) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) external view returns (uint256 assets);
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Ownable2Step.sol 57 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.0;
import "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
_transferOwnership(sender);
}
}
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20.sol";
IERC4626.sol 232 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4626.sol)
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20.sol";
import "../token/ERC20/extensions/IERC20Metadata.sol";
/**
* @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*
* _Available since v4.7._
*/
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
function asset() external view returns (address assetTokenAddress);
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() external view returns (uint256 totalManagedAssets);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) external view returns (uint256 shares);
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) external view returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) external view returns (uint256 shares);
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address receiver) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) external view returns (uint256 assets);
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
ERC20.sol 365 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
* 0 before setting it to a non-zero value.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
IERC165.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 IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
SafeCast.sol 1136 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
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 uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @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
*
* _Available since v4.2._
*/
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 uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(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
*
* _Available since v2.5._
*/
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 uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(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
*
* _Available since v4.2._
*/
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 uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(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
*
* _Available since v2.5._
*/
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 uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(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
*
* _Available since v2.5._
*/
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 uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(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
*
* _Available since v2.5._
*/
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
*
* _Available since v2.5._
*/
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.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @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 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @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 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @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 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @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 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @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 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
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);
}
}
Read Contract
DEPLOYER_ADDRESS 0xd2a156e0 → address
DEVIATION_PRECISION 0x49eb7af6 → uint256
EXCHANGE_PRECISION 0xc0a7e892 → uint256
FEE_PRECISION 0xe63a391f → uint256
LIQ_PRECISION 0x9fe34bdc → uint256
LTV_PRECISION 0xb78294dd → uint256
MAX_PROTOCOL_FEE 0xb8ca3b83 → uint256
RATE_PRECISION 0x2b3ba681 → uint256
UTIL_PREC 0x6cd3cc77 → uint256
allowance 0xdd62ed3e → uint256
asset 0x38d52e0f → address
balanceOf 0x70a08231 → uint256
borrowLimit 0xe551d11d → uint256
circuitBreakerAddress 0x49292427 → address
cleanLiquidationFee 0x11a2e4bc → uint256
collateralContract 0xc6e1c7c9 → address
convertToAssets 0x07a2d13a → uint256
convertToShares 0xc6e6f592 → uint256
currentRateInfo 0x95d14ca8 → uint32, uint32, uint64, uint64, uint64
decimals 0x313ce567 → uint8
depositLimit 0xecf70858 → uint256
dirtyLiquidationFee 0x4732428c → uint256
exchangeRateInfo 0xfbbbf94c → address, uint32, uint184, uint256, uint256
externalAssetVault 0x7bcad14c → address
getConstants 0x9a295e73 → uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256
getPairAccounting 0xcdd72d52 → uint128, uint128, uint128, uint128, uint256
getUserSnapshot 0xb68d0a09 → uint256, uint256, uint256
isInterestPaused 0xf211c390 → bool
isLiquidatePaused 0xc58e4df6 → bool
isRepayPaused 0x115a334c → bool
isWithdrawPaused 0x67800b5f → bool
liquidateDelayAfterBorrow 0x608bc9ae → uint256
maxBorrowLTV 0xf5364599 → uint256
maxDeposit 0x402d267d → uint256
maxLTV 0xf384bd05 → uint256
maxMint 0xc63d75b6 → uint256
maxRedeem 0xd905777e → uint256
maxWithdraw 0xce96cb77 → uint256
minCollateralRequiredOnDirtyLiquidation 0x37500763 → uint256
minURChangeForExternalAddInterest 0x1956473f → uint256
name 0x06fdde03 → string
overBorrowDelayAfterAddCollateral 0x2b42e94e → uint256
owner 0x8da5cb5b → address
pendingOwner 0xe30c3978 → address
pendingTimelockAddress 0x090f3f50 → address
previewAddInterest 0xcacf3b58 → uint256, uint256, uint256, tuple, tuple, tuple
previewDeposit 0xef8b30f7 → uint256
previewMint 0xb3d7f6b9 → uint256
previewRedeem 0x4cdad506 → uint256
previewWithdraw 0x0a28a477 → uint256
pricePerShare 0x99530b06 → uint256
protocolLiquidationFee 0xeafecffa → uint256
rateContract 0xeee24219 → address
symbol 0x95d89b41 → string
timelockAddress 0x4bc66f32 → address
toAssetAmount 0x7d37bdd7 → uint256
toAssetShares 0x1c2591d3 → uint256
toBorrowAmount 0x7ec4b571 → uint256
toBorrowShares 0x93f46f64 → uint256
totalAsset 0xf9557ccb → uint128, uint128
totalAssets 0x01e1d114 → uint256
totalBorrow 0x8285ef40 → uint128, uint128
totalCollateral 0x4ac8eb5f → uint256
totalSupply 0x18160ddd → uint256
userBorrowShares 0x4fd422df → uint256
userCollateralBalance 0xb5af3062 → uint256
version 0x54fd4d50 → uint256, uint256, uint256
Write Contract 38 functions
These functions modify contract state and require a wallet transaction to execute.
acceptOwnership 0x79ba5097
No parameters
acceptTransferTimelock 0xf6ccaad4
No parameters
addCollateral 0xcadac479
uint256 _collateralAmount
address _borrower
addInterest 0x1c6c9597
bool _returnAccounting
returns: uint256, uint256, uint256, tuple, tuple, tuple
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
borrowAsset 0xe5f13b16
uint256 _borrowAmount
uint256 _collateralAmount
address _receiver
returns: uint256
changeFee 0x8142dd53
uint32 _newFee
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
deposit 0x6e553f65
uint256 _amount
address _receiver
returns: uint256
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
liquidate 0x721b0a47
uint128 _sharesToLiquidate
uint256 _deadline
address _borrower
returns: uint256
mint 0x94bf804d
uint256 _shares
address _receiver
returns: uint256
pause 0x8456cb59
No parameters
pauseBorrow 0xe8596f72
No parameters
pauseDeposit 0x69026e88
No parameters
redeem 0xba087652
uint256 _shares
address _receiver
address _owner
returns: uint256
removeCollateral 0xd41ddc96
uint256 _collateralAmount
address _receiver
renounceOwnership 0x715018a6
No parameters
renounceTimelock 0x4f8b4ae7
No parameters
repayAsset 0x3d417d2d
uint256 _shares
address _borrower
returns: uint256
setBorrowLimit 0xe7a33174
uint256 _limit
setCircuitBreaker 0x82beee89
address _newCircuitBreaker
setDepositLimit 0xbdc8144b
uint256 _limit
setExternalAssetVault 0xc158e88d
address vault
setLiquidationFees 0x0e9bdced
uint256 _newCleanLiquidationFee
uint256 _newDirtyLiquidationFee
uint256 _newProtocolLiquidationFee
uint256 _newMinCollateralRequiredOnDirtyLiquidation
setMaxLTV 0xe7e9f920
uint256 _newMaxLTV
uint256 _newMaxBorrowLTV
setMinURChangeForExternalAddInterest 0xbc410c64
uint256 _newURChange
setOracle 0x8f791f8b
address _newOracle
uint32 _newMaxOracleDeviation
setOverBorrowAndLiquidateDelays 0x499836f6
uint256 _overBorrowDelayAfterAddCollateral
uint256 _liquidateDelayAfterBorrow
setRateContract 0x6b96668f
address _newRateContract
transfer 0xa9059cbb
address to
uint256 amount
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 amount
returns: bool
transferOwnership 0xf2fde38b
address newOwner
transferTimelock 0x45014095
address _newTimelock
unpause 0x3f4ba83a
No parameters
updateExchangeRate 0x02ce728f
No parameters
returns: bool, uint256, uint256
withdraw 0xb460af94
uint256 _amount
address _receiver
address _owner
returns: uint256
withdrawFees 0xdaf33f2a
uint128 _shares
address _recipient
returns: uint256
Token Balances (1)
View Transfers →Recent Transactions
No transactions found for this address