Forkchoice Ethereum Mainnet

Address Contract Verified

Address 0x0650422Ef55BE3Fe99aCdBb50A33203a741bFD89
Balance 0 ETH
Nonce 1
Code Size 22119 bytes
Indexed Transactions 0 (1 on-chain, 1.7% indexed)
External Etherscan · Sourcify

Contract Bytecode

22119 bytes
Copy Bytecode
0x608060405234801561001057600080fd5b50600436106101fb5760003560e01c806390d675141161011a578063d3033c39116100ad578063ec78e8321161007c578063ec78e83214610493578063ee330ee3146104a6578063fb7ee102146104b9578063fc0c546a146104cc578063ffa1ad74146104dd57600080fd5b8063d3033c3914610449578063d8dfeb451461045c578063e260d74714610482578063e5328e061461048b57600080fd5b8063c415b95c116100e9578063c415b95c146103e9578063cdaabe41146103fc578063ce5494bb14610423578063d2c35ce81461043657600080fd5b806390d6751414610385578063951dc22c14610398578063a3f4df7e146103ad578063b2016bd4146103c257600080fd5b8063251c1aa3116101925780634032b72b116101615780634032b72b14610319578063440d72481461032c578063456dc17a1461034f5780637d7c2a1c1461036257600080fd5b8063251c1aa3146102d85780632b3297f9146102e05780632e1a7d4d146102f35780633ac9fc111461030657600080fd5b80631026013a116101ce5780631026013a1461026457806314ae9f2e1461027757806316f0115b1461028a578063201f35c6146102b157600080fd5b806301681a62146102005780630181686c146102155780630ade00f2146102315780630c340a241461025c575b600080fd5b61021361020e366004614efa565b610501565b005b61021e60075481565b6040519081526020015b60405180910390f35b600b54610244906001600160a01b031681565b6040516001600160a01b039091168152602001610228565b610244610758565b61021e610272366004614f17565b6107f0565b610213610285366004614efa565b6109d6565b6102447f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b81565b6102447f000000000000000000000000b5b29320d2dde5ba5bafa1ebcd270052070483ec81565b61021e610b1e565b600254610244906001600160a01b031681565b610213610301366004614f17565b610c53565b610213610314366004614f17565b610ecc565b610213610327366004614efa565b610f23565b61033f61033a366004614efa565b61106b565b6040519015158152602001610228565b600854610244906001600160a01b031681565b61036a6110f0565b60408051938452602084019290925290820152606001610228565b600954610244906001600160a01b031681565b6103a0611155565b6040516102289190614f74565b6103b5611161565b6040516102289190614fb3565b6102447f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8481565b600154610244906001600160a01b031681565b6102447f0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e81565b610213610431366004614efa565b6111ef565b610213610444366004614efa565b6114e8565b610213610457366004614efa565b6116f6565b7f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe84610244565b61021e60065481565b61021e611904565b600054610244906001600160a01b031681565b61021e6104b4366004614fe6565b611aa7565b6102136104c7366004615012565b611ec7565b6000546001600160a01b0316610244565b6103b560405180604001604052806005815260200164352e312e3160d81b81525081565b61050e335b6003906120dd565b6105585760405162461bcd60e51b815260206004820152601660248201527531b0b63632b916b4b996b737ba16b096b5b2b2b832b960511b60448201526064015b60405180910390fd5b6001546001600160a01b03166105b05760405162461bcd60e51b815260206004820152601560248201527f6665652d636f6c6c6563746f722d6e6f742d7365740000000000000000000000604482015260640161054f565b7f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316816001600160a01b031614156106325760405162461bcd60e51b815260206004820152601f60248201527f6e6f742d616c6c6f7765642d746f2d73776565702d636f6c6c61746572616c00604482015260640161054f565b61063b8161106b565b1561067f5760405162461bcd60e51b815260206004820152601460248201527306e6f742d616c6c6f7765642d746f2d73776565760641b604482015260640161054f565b6001600160a01b03811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14156106bd576001546106ba906001600160a01b0316476120ff565b50565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a082319060240160206040518083038186803b1580156106ff57600080fd5b505afa158015610713573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107379190615034565b600154909150610754906001600160a01b0384811691168361221d565b5050565b60007f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b6001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b1580156107b357600080fd5b505afa1580156107c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107eb919061504d565b905090565b60006107fb33610506565b6108405760405162461bcd60e51b815260206004820152601660248201527531b0b63632b916b4b996b737ba16b096b5b2b2b832b960511b604482015260640161054f565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316906370a082319060240160206040518083038186803b1580156108a257600080fd5b505afa1580156108b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108da9190615034565b90506108e46122ad565b6040516370a0823160e01b815230600482015281907f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316906370a082319060240160206040518083038186803b15801561094557600080fd5b505afa158015610959573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061097d9190615034565b6109879190615080565b9150828210156109d05760405162461bcd60e51b81526020600482015260146024820152731b9bdd0b595b9bdd59da0b585b5bdd5b9d13dd5d60621b604482015260640161054f565b50919050565b7f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b6001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b158015610a2f57600080fd5b505afa158015610a43573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a67919061504d565b6001600160a01b0316336001600160a01b031614610ac75760405162461bcd60e51b815260206004820152601a60248201527f63616c6c65722d69732d6e6f742d7468652d676f7665726e6f72000000000000604482015260640161054f565b610ad260038261239f565b6106ba5760405162461bcd60e51b815260206004820152601460248201527f72656d6f76652d6b65657065722d6661696c6564000000000000000000000000604482015260640161054f565b60007f000000000000000000000000b5b29320d2dde5ba5bafa1ebcd270052070483ec6001600160a01b0316639fdb11b66040518163ffffffff1660e01b815260040160206040518083038186803b158015610b7957600080fd5b505afa158015610b8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bb19190615034565b604051630687c2b560e41b81523060048201527f000000000000000000000000b5b29320d2dde5ba5bafa1ebcd270052070483ec6001600160a01b03169063687c2b50906024015b60206040518083038186803b158015610c1157600080fd5b505afa158015610c25573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c499190615034565b6107eb9190615097565b337f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b6001600160a01b031614610ccb5760405162461bcd60e51b815260206004820152601960248201527f63616c6c65722d69732d6e6f742d7665737065722d706f6f6c00000000000000604482015260640161054f565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316906370a082319060240160206040518083038186803b158015610d2d57600080fd5b505afa158015610d41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d659190615034565b9050818110610dc2576107546001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe84167f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b8461221d565b610dd4610dcf8284615080565b6123b4565b6040516370a0823160e01b81523060048201527f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316906370a082319060240160206040518083038186803b158015610e3357600080fd5b505afa158015610e47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6b9190615034565b90506107547f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b610e9b8484612544565b6001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8416919061221d565b610ed533610506565b610f1a5760405162461bcd60e51b815260206004820152601660248201527531b0b63632b916b4b996b737ba16b096b5b2b2b832b960511b604482015260640161054f565b6106ba8161255a565b7f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b6001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b158015610f7c57600080fd5b505afa158015610f90573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb4919061504d565b6001600160a01b0316336001600160a01b0316146110145760405162461bcd60e51b815260206004820152601a60248201527f63616c6c65722d69732d6e6f742d7468652d676f7665726e6f72000000000000604482015260640161054f565b61101f6003826120c1565b6106ba5760405162461bcd60e51b815260206004820152601160248201527f6164642d6b65657065722d6661696c6564000000000000000000000000000000604482015260640161054f565b60007f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316826001600160a01b031614806110ba57506000546001600160a01b038381169116145b806110d257506009546001600160a01b038381169116145b806110ea57506008546001600160a01b038381169116145b92915050565b600080806110fd33610506565b6111425760405162461bcd60e51b815260206004820152601660248201527531b0b63632b916b4b996b737ba16b096b5b2b2b832b960511b604482015260640161054f565b61114a61259d565b925092509250909192565b60606107eb6003612d7e565b6005805461116e906150af565b80601f016020809104026020016040519081016040528092919081815260200182805461119a906150af565b80156111e75780601f106111bc576101008083540402835291602001916111e7565b820191906000526020600020905b8154815290600101906020018083116111ca57829003601f168201915b505050505081565b337f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b6001600160a01b0316146112675760405162461bcd60e51b815260206004820152601960248201527f63616c6c65722d69732d6e6f742d7665737065722d706f6f6c00000000000000604482015260640161054f565b6001600160a01b0381166112bd5760405162461bcd60e51b815260206004820152601c60248201527f6e65772d73747261746567792d616464726573732d69732d7a65726f00000000604482015260640161054f565b7f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b6001600160a01b0316816001600160a01b03166316f0115b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561132057600080fd5b505afa158015611334573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611358919061504d565b6001600160a01b0316146113ae5760405162461bcd60e51b815260206004820152601660248201527f6e6f742d76616c69642d6e65772d737472617465677900000000000000000000604482015260640161054f565b6113b781612d8b565b6000546040516370a0823160e01b815230600482015261144b9183916001600160a01b03909116906370a082319060240160206040518083038186803b15801561140057600080fd5b505afa158015611414573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114389190615034565b6000546001600160a01b0316919061221d565b6040516370a0823160e01b81523060048201526106ba9082906001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8416906370a082319060240160206040518083038186803b1580156114b057600080fd5b505afa1580156114c4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e9b9190615034565b7f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b6001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b15801561154157600080fd5b505afa158015611555573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611579919061504d565b6001600160a01b0316336001600160a01b0316146115d95760405162461bcd60e51b815260206004820152601a60248201527f63616c6c65722d69732d6e6f742d7468652d676f7665726e6f72000000000000604482015260640161054f565b6001600160a01b03811661162f5760405162461bcd60e51b815260206004820152601d60248201527f6665652d636f6c6c6563746f722d616464726573732d69732d7a65726f000000604482015260640161054f565b6001546001600160a01b038281169116141561168d5760405162461bcd60e51b815260206004820152601560248201527f6665652d636f6c6c6563746f722d69732d73616d650000000000000000000000604482015260640161054f565b6001546040516001600160a01b038084169216907f0f06062680f9bd68e786e9980d9bb03d73d5620fc3b345e417b6eacb310b970690600090a36001805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b7f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b6001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b15801561174f57600080fd5b505afa158015611763573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611787919061504d565b6001600160a01b0316336001600160a01b0316146117e75760405162461bcd60e51b815260206004820152601a60248201527f63616c6c65722d69732d6e6f742d7468652d676f7665726e6f72000000000000604482015260640161054f565b6001600160a01b03811661183d5760405162461bcd60e51b815260206004820152601760248201527f737761707065722d616464726573732d69732d7a65726f000000000000000000604482015260640161054f565b6002546001600160a01b038281169116141561189b5760405162461bcd60e51b815260206004820152600f60248201527f737761707065722d69732d73616d650000000000000000000000000000000000604482015260640161054f565b6002546040516001600160a01b038084169216907f6c953b7ec311055c20b96a42cea31e89528e375b1bf953a503db40854b3188fe90600090a36002805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b6040516370a0823160e01b81523060048201526000906119a7906001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8416906370a082319060240160206040518083038186803b15801561196a57600080fd5b505afa15801561197e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119a29190615034565b612f8d565b600b546040516370a0823160e01b81523060048201526001600160a01b03909116906370a082319060240160206040518083038186803b1580156119ea57600080fd5b505afa1580156119fe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a229190615034565b6000546040516370a0823160e01b81523060048201526001600160a01b03909116906370a082319060240160206040518083038186803b158015611a6557600080fd5b505afa158015611a79573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a9d9190615034565b610c499190615097565b6000611ab233610506565b611af75760405162461bcd60e51b815260206004820152601660248201527531b0b63632b916b4b996b737ba16b096b5b2b2b832b960511b604482015260640161054f565b7f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316836001600160a01b03161415611b795760405162461bcd60e51b815260206004820152601f60248201527f6e6f742d616c6c6f7765642d746f2d73776565702d636f6c6c61746572616c00604482015260640161054f565b611b828361106b565b15611bc65760405162461bcd60e51b815260206004820152601460248201527306e6f742d616c6c6f7765642d746f2d73776565760641b604482015260640161054f565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316906370a082319060240160206040518083038186803b158015611c2857600080fd5b505afa158015611c3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c609190615034565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038616906370a082319060240160206040518083038186803b158015611ca557600080fd5b505afa158015611cb9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cdd9190615034565b90508015611dd357600254604051636eb1769f60e11b81523060048201526001600160a01b0391821660248201529086169063dd62ed3e9060440160206040518083038186803b158015611d3057600080fd5b505afa158015611d44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d689190615034565b811115611da657600254611d8a906001600160a01b0387811691166000613013565b600254611da6906001600160a01b038781169116600019613013565b611dd1857f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe848361313e565b505b6040516370a0823160e01b815230600482015282907f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316906370a082319060240160206040518083038186803b158015611e3457600080fd5b505afa158015611e48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e6c9190615034565b611e769190615080565b925083831015611ebf5760405162461bcd60e51b81526020600482015260146024820152731b9bdd0b595b9bdd59da0b585b5bdd5b9d13dd5d60621b604482015260640161054f565b505092915050565b7f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b6001600160a01b0316630c340a246040518163ffffffff1660e01b815260040160206040518083038186803b158015611f2057600080fd5b505afa158015611f34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f58919061504d565b6001600160a01b0316336001600160a01b031614611fb85760405162461bcd60e51b815260206004820152601a60248201527f63616c6c65722d69732d6e6f742d7468652d676f7665726e6f72000000000000604482015260640161054f565b61271081106120095760405162461bcd60e51b815260206004820152601860248201527f696e76616c69642d6d61782d626f72726f772d6c696d69740000000000000000604482015260640161054f565b80158015612015575081155b8061201f57508181115b61206b5760405162461bcd60e51b815260206004820152601d60248201527f6d61782d73686f756c642d62652d6869676865722d7468616e2d6d696e000000604482015260640161054f565b6006546007546040805192835260208301859052820152606081018290527fedd77444afdf63401315e81ffe86d08f7865796e8ad2e11acf1d56a1393f07d59060800160405180910390a1600691909155600755565b60006120d6836001600160a01b0384166131e2565b9392505050565b6001600160a01b038116600090815260018301602052604081205415156120d6565b8047101561214f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015260640161054f565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461219c576040519150601f19603f3d011682016040523d82523d6000602084013e6121a1565b606091505b50509050806122185760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d61792068617665207265766572746564000000000000606482015260840161054f565b505050565b6040516001600160a01b03831660248201526044810182905261221890849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152613231565b6000805481906122c5906001600160a01b0316613303565b8151919350915060005b818110156123995760008382815181106122eb576122eb6150e4565b60200260200101511180156123325750600b5484516001600160a01b039091169085908390811061231e5761231e6150e4565b60200260200101516001600160a01b031614155b156123895761238984828151811061234c5761234c6150e4565b6020026020010151600b60009054906101000a90046001600160a01b031685848151811061237c5761237c6150e4565b602002602001015161344c565b612392816150fa565b90506122cf565b50505050565b60006120d6836001600160a01b0384166134e8565b6106ba817f0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e6001600160a01b031663026b1d5f6040518163ffffffff1660e01b815260040160206040518083038186803b15801561241157600080fd5b505afa158015612425573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612449919061504d565b6009546040516370a0823160e01b81523060048201526001600160a01b03909116906370a082319060240160206040518083038186803b15801561248c57600080fd5b505afa1580156124a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124c49190615034565b6000546040516370a0823160e01b81523060048201526001600160a01b03909116906370a082319060240160206040518083038186803b15801561250757600080fd5b505afa15801561251b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061253f9190615034565b6135db565b600081831061255357816120d6565b5090919050565b612563816137f5565b600b546106ba906001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe848116911683613013565b604051636a9eee1360e11b81523060048201526000908190819081906001600160a01b037f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b169063d53ddc269060240160206040518083038186803b15801561260557600080fd5b505afa158015612619573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061263d9190615034565b6009546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a082319060240160206040518083038186803b15801561268657600080fd5b505afa15801561269a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126be9190615034565b905060006126ca613835565b905060007f0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e6001600160a01b031663026b1d5f6040518163ffffffff1660e01b815260040160206040518083038186803b15801561272757600080fd5b505afa15801561273b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061275f919061504d565b9050818311156127815761277c6127768385615080565b8261386f565b612793565b61279361278e8484615080565b613b16565b600061279d613c5f565b600080546040516370a0823160e01b815230600482015292935090916001600160a01b03909116906370a082319060240160206040518083038186803b1580156127e657600080fd5b505afa1580156127fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061281e9190615034565b9050600061282b82613d8f565b905060006128398483615097565b604051639f2b283360e01b81523060048201529091506000906001600160a01b037f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b1690639f2b28339060240160206040518083038186803b15801561289e57600080fd5b505afa1580156128b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128d69190615034565b9050808211156128f1576128ea8183615080565b9b506128fe565b6128fb8282615080565b9a505b600061290a8a8e615097565b9050808610156129d95760006129296129238884615080565b86612544565b905080156129d75761293d81898c896135db565b6040516370a0823160e01b81523060048201527f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316906370a082319060240160206040518083038186803b15801561299c57600080fd5b505afa1580156129b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129d49190615034565b96505b505b6129e3868b612544565b9a508a86116129f3576000612a06565b612a06612a008c88615080565b8e612544565b6040516302df682360e11b815260048101829052602481018e9052604481018d9052909d506001600160a01b037f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b16906305bed04690606401600060405180830381600087803b158015612a7957600080fd5b505af1158015612a8d573d6000803e3d6000fd5b50506040516370a0823160e01b8152306004820152600092507f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b031691506370a082319060240160206040518083038186803b158015612af357600080fd5b505afa158015612b07573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b2b9190615034565b90508015612b3d57612b3d8189613dca565b6009546040516370a0823160e01b81523060048201526000918291612c4391839182916001600160a01b0316906370a082319060240160206040518083038186803b158015612b8b57600080fd5b505afa158015612b9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bc39190615034565b6000546040516370a0823160e01b81523060048201526001600160a01b03909116906370a082319060240160206040518083038186803b158015612c0657600080fd5b505afa158015612c1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c3e9190615034565b613edd565b90925090508015612c5d57612c58818b6144f6565b612cde565b8115612cde5760085460405163a415bcad60e01b81526001600160a01b039182166004820152602481018490526002604482015260006064820152306084820152908b169063a415bcad9060a401600060405180830381600087803b158015612cc557600080fd5b505af1158015612cd9573d6000803e3d6000fd5b505050505b6008546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b158015612d2257600080fd5b505afa158015612d36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d5a9190615034565b90508015612d6b57612d6b81614576565b5050505050505050505050505050909192565b606060006120d68361457f565b60008054906101000a90046001600160a01b03166001600160a01b0316816001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b158015612de157600080fd5b505afa158015612df5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e19919061504d565b6001600160a01b031614612e6f5760405162461bcd60e51b815260206004820152601360248201527f77726f6e672d726563656970742d746f6b656e00000000000000000000000000604482015260640161054f565b6009546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b158015612eb357600080fd5b505afa158015612ec7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612eeb9190615034565b9050801561075457610754817f0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e6001600160a01b031663026b1d5f6040518163ffffffff1660e01b815260040160206040518083038186803b158015612f5057600080fd5b505afa158015612f64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f88919061504d565b6144f6565b60405162b0e38960e81b815260048101829052600090737f39c581f595b53c5cb19bd0b3f8da6c935e2ca09063b0e38900906024015b60206040518083038186803b158015612fdb57600080fd5b505afa158015612fef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ea9190615034565b80158061309c5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e9060440160206040518083038186803b15801561306257600080fd5b505afa158015613076573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061309a9190615034565b155b61310e5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527f20746f206e6f6e2d7a65726f20616c6c6f77616e636500000000000000000000606482015260840161054f565b6040516001600160a01b03831660248201526044810182905261221890849063095ea7b360e01b90606401612249565b600254604051636ccb2b0160e01b81526001600160a01b038581166004830152848116602483015260448201849052600160648301523060848301526000921690636ccb2b019060a401602060405180830381600087803b1580156131a257600080fd5b505af11580156131b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131da9190615034565b949350505050565b6000818152600183016020526040812054613229575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556110ea565b5060006110ea565b6000613286826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166145db9092919063ffffffff16565b80519091501561221857808060200190518101906132a49190615125565b6122185760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161054f565b606080826001600160a01b03166375d264136040518163ffffffff1660e01b815260040160206040518083038186803b15801561333f57600080fd5b505afa92505050801561336f575060408051601f3d908101601f1916820190925261336c9181019061504d565b60015b61337857915091565b6040805160018082528183019092526000916020808301908036833701905050905084816000815181106133ae576133ae6150e4565b6001600160a01b03928316602091820292909201015260405163bb492bf560e01b81529083169063bb492bf5906133eb9084903090600401615156565b600060405180830381600087803b15801561340557600080fd5b505af1158015613419573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613441919081019061524c565b935093505050915091565b600254604051636ccb2b0160e01b81526001600160a01b0385811660048301528481166024830152604482018490526001606483015230608483015290911690636ccb2b019060a401602060405180830381600087803b1580156134af57600080fd5b505af19250505080156134df575060408051601f3d908101601f191682019092526134dc91810190615034565b60015b61239957505050565b600081815260018301602052604081205480156135d157600061350c600183615080565b855490915060009061352090600190615080565b9050818114613585576000866000018281548110613540576135406150e4565b9060005260206000200154905080876000018481548110613563576135636150e4565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061359657613596615312565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506110ea565b60009150506110ea565b60006135e685612f8d565b905060006135f76000838686613edd565b915050801561360a5761360a81866144f6565b600b54600080546040516370a0823160e01b81526001600160a01b039182166004820152919261369d9286926136989289929116906370a082319060240160206040518083038186803b15801561366057600080fd5b505afa158015613674573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136989190615034565b612544565b600b54604051631a4ca37b60e21b81526001600160a01b039182166004820152602481018390523060448201529192508291908816906369328dec90606401602060405180830381600087803b1580156136f657600080fd5b505af115801561370a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061372e9190615034565b1460405180604001604052806002815260200161323960f01b815250906137685760405162461bcd60e51b815260040161054f9190614fb3565b50600b546040516370a0823160e01b81523060048201526137eb916001600160a01b0316906370a082319060240160206040518083038186803b1580156137ae57600080fd5b505afa1580156137c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137e69190615034565b6145ea565b5050505050505050565b6137fe8161464f565b6008546106ba906001600160a01b03167f000000000000000000000000b5b29320d2dde5ba5bafa1ebcd270052070483ec83613013565b600061383f6149b7565b6008546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401610bf9565b600254600b546008546040516353b609b560e01b81526001600160a01b03928316600482015290821660248201526044810185905260009291909116906353b609b590606401602060405180830381600087803b1580156138cf57600080fd5b505af11580156138e3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139079190615034565b9050801561221857600b546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b15801561395357600080fd5b505afa158015613967573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061398b9190615034565b905080821115613a6f5760006139a18284615080565b600b54604051631a4ca37b60e21b81526001600160a01b039182166004820152602481018390523060448201529192508291908616906369328dec90606401602060405180830381600087803b1580156139fa57600080fd5b505af1158015613a0e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a329190615034565b1460405180604001604052806002815260200161323960f01b81525090613a6c5760405162461bcd60e51b815260040161054f9190614fb3565b50505b600254600b546008546040516381cc619b60e01b81526001600160a01b039283166004820152908216602482015260448101879052606481018590523060848201529116906381cc619b9060a401602060405180830381600087803b158015613ad757600080fd5b505af1158015613aeb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b0f9190615034565b5050505050565b80156106ba576008546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b158015613b6057600080fd5b505afa158015613b74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b989190615034565b905081811015613c3357613bb4613baf8284615080565b614ac7565b506008546040516370a0823160e01b81523060048201526001600160a01b03909116906370a082319060240160206040518083038186803b158015613bf857600080fd5b505afa158015613c0c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c309190615034565b90505b801561075457600854600b54610754916001600160a01b039081169116613c5a8585612544565b61344c565b600b546040516370a0823160e01b815230600482015260009182916001600160a01b03909116906370a082319060240160206040518083038186803b158015613ca757600080fd5b505afa158015613cbb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cdf9190615034565b90508015613cf257613cf0816145ea565b505b6040516370a0823160e01b81523060048201527f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316906370a082319060240160206040518083038186803b158015613d5157600080fd5b505afa158015613d65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d899190615034565b91505090565b604051632eca54bf60e21b815260048101829052600090737f39c581f595b53c5cb19bd0b3f8da6c935e2ca09063bb2952fc90602401612fc3565b6000613dd583614bf9565b9050801561221857600b5460405163617ba03760e01b81526001600160a01b03918216600482015260248101839052306044820152600060648201529083169063617ba03790608401600060405180830381600087803b158015613e3857600080fd5b505af1925050508015613e49575060015b61221857613e55615328565b806308c379a01415613ed15750613e6a615344565b80613e755750613ed3565b613e7e816153ce565b611a9b60f11b146123995760405162461bcd60e51b815260206004820152600e60248201527f6465706f736974206661696c6564000000000000000000000000000000000000604482015260640161054f565b505b3d6000803e3d6000fd5b600080851580613eeb575084155b613f375760405162461bcd60e51b815260206004820152601160248201527f616c6c2d696e7075742d67742d7a65726f000000000000000000000000000000604482015260640161054f565b600754613f49575060009050826144ed565b6000808711613f6f57858411613f60576000613f79565b613f6a8685615080565b613f79565b613f798785615097565b905080613f8d5760008592509250506144ed565b60007f0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e6001600160a01b031663fca513a86040518163ffffffff1660e01b815260040160206040518083038186803b158015613fe857600080fd5b505afa158015613ffc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614020919061504d565b60085460405163b3596f0760e01b81526001600160a01b0391821660048201529192506000919083169063b3596f079060240160206040518083038186803b15801561406b57600080fd5b505afa15801561407f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140a39190615034565b600b5460405163b3596f0760e01b81526001600160a01b0391821660048201529192506000919084169063b3596f079060240160206040518083038186803b1580156140ee57600080fd5b505afa158015614102573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141269190615034565b9050811580614133575080155b156141485760008895509550505050506144ed565b60007f0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e6001600160a01b031663e860accb6040518163ffffffff1660e01b815260040160206040518083038186803b1580156141a357600080fd5b505afa1580156141b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141db919061504d565b600b54604051633e15014160e01b81526001600160a01b039182166004820152911690633e150141906024016101406040518083038186803b15801561422057600080fd5b505afa158015614234573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061425891906153f2565b50505050505050509150506000600b60009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156142b357600080fd5b505afa1580156142c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142eb9190615489565b6142f690600a615590565b6143029061271061559f565b8361430d848961559f565b614317919061559f565b61432191906155be565b9050600084600860009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561437457600080fd5b505afa158015614388573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143ac9190615489565b6143b790600a615590565b6143c1908461559f565b6143cb91906155be565b9050806143e55760008b98509850505050505050506144ed565b6000612710600754836143f8919061559f565b61440291906155be565b9050600061271060065484614417919061559f565b61442191906155be565b9050818d111561443c57614435818e615080565b99506144e3565b8c8111156144e35761444e8d82615080565b600854600a546040516370a0823160e01b81526001600160a01b039182166004820152929d506000929116906370a082319060240160206040518083038186803b15801561449b57600080fd5b505afa1580156144af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144d39190615034565b9050808c11156144e157809b505b505b5050505050505050505b94509492505050565b6144ff82614c34565b60085460405163573ade8160e01b81526001600160a01b03918216600482015260248101849052600260448201523060648201529082169063573ade8190608401600060405180830381600087803b15801561455a57600080fd5b505af115801561456e573d6000803e3d6000fd5b505050505050565b61075481614c3d565b6060816000018054806020026020016040519081016040528092919081815260200182805480156145cf57602002820191906000526020600020905b8154815260200190600101908083116145bb575b50505050509050919050565b60606131da8484600085614d30565b604051636f074d1f60e11b815260048101829052600090737f39c581f595b53c5cb19bd0b3f8da6c935e2ca09063de0e9a3e906024015b602060405180830381600087803b15801561463b57600080fd5b505af1158015612fef573d6000803e3d6000fd5b61465881614e58565b6000600260009054906101000a90046001600160a01b031690506147197f0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e6001600160a01b031663026b1d5f6040518163ffffffff1660e01b815260040160206040518083038186803b1580156146ce57600080fd5b505afa1580156146e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614706919061504d565b600b546001600160a01b03169084613013565b600b54614730906001600160a01b03168284613013565b6147d77f0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e6001600160a01b031663026b1d5f6040518163ffffffff1660e01b815260040160206040518083038186803b15801561478c57600080fd5b505afa1580156147a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147c4919061504d565b6008546001600160a01b03169084613013565b6008546147ee906001600160a01b03168284613013565b60008054906101000a90046001600160a01b03166001600160a01b03166375d264136040518163ffffffff1660e01b815260040160206040518083038186803b15801561483a57600080fd5b505afa92505050801561486a575060408051601f3d908101601f191682019092526148679181019061504d565b60015b614872575050565b6000816001600160a01b031663b45ac1a96040518163ffffffff1660e01b815260040160006040518083038186803b1580156148ad57600080fd5b505afa1580156148c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526148e991908101906155e0565b905060005b8151811015613b0f57600b5482516001600160a01b039091169083908390811061491a5761491a6150e4565b60200260200101516001600160a01b03161415801561496b575060085482516001600160a01b0390911690839083908110614957576149576150e4565b60200260200101516001600160a01b031614155b156149a7576149a78486848481518110614987576149876150e4565b60200260200101516001600160a01b03166130139092919063ffffffff16565b6149b0816150fa565b90506148ee565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000b5b29320d2dde5ba5bafa1ebcd270052070483ec6001600160a01b0316906307a2d13a9082906370a082319060240160206040518083038186803b158015614a2157600080fd5b505afa158015614a35573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a599190615034565b6040518263ffffffff1660e01b8152600401614a7791815260200190565b60206040518083038186803b158015614a8f57600080fd5b505afa158015614aa3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107eb9190615034565b6000614ad1610b1e565b4210614bf4576000614b4183613698614ae86149b7565b7f000000000000000000000000b5b29320d2dde5ba5bafa1ebcd270052070483ec6001600160a01b031663a8144e486040518163ffffffff1660e01b815260040160206040518083038186803b15801561366057600080fd5b905080156109d057604051632d182be560e21b815260048101829052306024820181905260448201527f000000000000000000000000b5b29320d2dde5ba5bafa1ebcd270052070483ec6001600160a01b03169063b460af9490606401602060405180830381600087803b158015614bb857600080fd5b505af1158015614bcc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bf09190615034565b9150505b919050565b604051630ea598cb60e41b815260048101829052600090737f39c581f595b53c5cb19bd0b3f8da6c935e2ca09063ea598cb090602401614621565b61075481614ac7565b60405163ef8b30f760e01b8152600481018290526000907f000000000000000000000000b5b29320d2dde5ba5bafa1ebcd270052070483ec6001600160a01b03169063ef8b30f79060240160206040518083038186803b158015614ca057600080fd5b505afa158015614cb4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614cd89190615034565b15614bf457604051636e553f6560e01b8152600481018390523060248201527f000000000000000000000000b5b29320d2dde5ba5bafa1ebcd270052070483ec6001600160a01b031690636e553f6590604401614621565b606082471015614d915760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161054f565b843b614ddf5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161054f565b600080866001600160a01b03168587604051614dfb9190615615565b60006040518083038185875af1925050503d8060008114614e38576040519150601f19603f3d011682016040523d82523d6000602084013e614e3d565b606091505b5091509150614e4d828286614eac565b979650505050505050565b6106ba6001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe84167f0000000000000000000000004dbe3f01abe271d3e65432c74851625a8c30aa7b83613013565b60608315614ebb5750816120d6565b825115614ecb5782518084602001fd5b8160405162461bcd60e51b815260040161054f9190614fb3565b6001600160a01b03811681146106ba57600080fd5b600060208284031215614f0c57600080fd5b81356120d681614ee5565b600060208284031215614f2957600080fd5b5035919050565b600081518084526020808501945080840160005b83811015614f695781516001600160a01b031687529582019590820190600101614f44565b509495945050505050565b6020815260006120d66020830184614f30565b60005b83811015614fa2578181015183820152602001614f8a565b838111156123995750506000910152565b6020815260008251806020840152614fd2816040850160208701614f87565b601f01601f19169190910160400192915050565b60008060408385031215614ff957600080fd5b823561500481614ee5565b946020939093013593505050565b6000806040838503121561502557600080fd5b50508035926020909101359150565b60006020828403121561504657600080fd5b5051919050565b60006020828403121561505f57600080fd5b81516120d681614ee5565b634e487b7160e01b600052601160045260246000fd5b6000828210156150925761509261506a565b500390565b600082198211156150aa576150aa61506a565b500190565b600181811c908216806150c357607f821691505b602082108114156109d057634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600060001982141561510e5761510e61506a565b5060010190565b80518015158114614bf457600080fd5b60006020828403121561513757600080fd5b6120d682615115565b634e487b7160e01b600052604160045260246000fd5b6040815260006151696040830185614f30565b90506001600160a01b03831660208301529392505050565b601f8201601f1916810167ffffffffffffffff811182821017156151a7576151a7615140565b6040525050565b600067ffffffffffffffff8211156151c8576151c8615140565b5060051b60200190565b600082601f8301126151e357600080fd5b815160206151f0826151ae565b6040516151fd8282615181565b83815260059390931b850182019282810191508684111561521d57600080fd5b8286015b8481101561524157805161523481614ee5565b8352918301918301615221565b509695505050505050565b6000806040838503121561525f57600080fd5b825167ffffffffffffffff8082111561527757600080fd5b615283868387016151d2565b935060209150818501518181111561529a57600080fd5b85019050601f810186136152ad57600080fd5b80516152b8816151ae565b6040516152c58282615181565b82815260059290921b83018401918481019150888311156152e557600080fd5b928401925b82841015615303578351825292840192908401906152ea565b80955050505050509250929050565b634e487b7160e01b600052603160045260246000fd5b600060033d11156153415760046000803e5060005160e01c5b90565b600060443d10156153525790565b6040516003193d81016004833e81513d67ffffffffffffffff816024840111818411171561538257505050505090565b828501915081518181111561539a5750505050505090565b843d87010160208285010111156153b45750505050505090565b6153c360208286010187615181565b509095945050505050565b805160208083015191908110156109d05760001960209190910360031b1b16919050565b6000806000806000806000806000806101408b8d03121561541257600080fd5b8a51995060208b0151985060408b0151975060608b0151965060808b0151955061543e60a08c01615115565b945061544c60c08c01615115565b935061545a60e08c01615115565b92506154696101008c01615115565b91506154786101208c01615115565b90509295989b9194979a5092959850565b60006020828403121561549b57600080fd5b815160ff811681146120d657600080fd5b600181815b808511156154e75781600019048211156154cd576154cd61506a565b808516156154da57918102915b93841c93908002906154b1565b509250929050565b6000826154fe575060016110ea565b8161550b575060006110ea565b8160018114615521576002811461552b57615547565b60019150506110ea565b60ff84111561553c5761553c61506a565b50506001821b6110ea565b5060208310610133831016604e8410600b841016171561556a575081810a6110ea565b61557483836154ac565b80600019048211156155885761558861506a565b029392505050565b60006120d660ff8416836154ef565b60008160001904831182151516156155b9576155b961506a565b500290565b6000826155db57634e487b7160e01b600052601260045260246000fd5b500490565b6000602082840312156155f257600080fd5b815167ffffffffffffffff81111561560957600080fd5b6131da848285016151d2565b60008251615627818460208701614f87565b919091019291505056fea26469706673582212206efb1de97c0c853facdaf8920488b7eb32cac3540605afc910e07ab19bdd7f2364736f6c63430008090033

Verified Source Code Full Match

Compiler: v0.8.9+commit.e5eed63a EVM: london Optimization: Yes (500 runs)
IStrategy.sol 28 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

interface IStrategy {
    function rebalance() external returns (uint256 _profit, uint256 _loss, uint256 _payback);

    function sweep(address _fromToken) external;

    function withdraw(uint256 _amount) external;

    function feeCollector() external view returns (address);

    function isReservedToken(address _token) external view returns (bool);

    function keepers() external view returns (address[] memory);

    function migrate(address _newStrategy) external;

    function token() external view returns (address);

    function pool() external view returns (address);

    // solhint-disable-next-line func-name-mixedcase
    function VERSION() external view returns (string memory);

    function collateral() external view returns (address);
}
IERC20Metadata.sol 27 lines
// SPDX-License-Identifier: MIT

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);
}
IERC20.sol 77 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

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

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

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

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
SafeERC20.sol 77 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.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;

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

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

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

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

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

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

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) { // Return data is optional
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
Address.sol 189 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

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

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

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

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

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

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

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

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

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

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

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

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

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT

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) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}
Math.sol 31 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
}
EnumerableSet.sol 356 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastvalue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastvalue;
                // Update the index for the moved value
                set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        assembly {
            result := store
        }

        return result;
    }
}
Errors.sol 38 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;

/// @title Errors library
library Errors {
    string public constant INVALID_COLLATERAL_AMOUNT = "1"; // Collateral must be greater than 0 or > defined limit
    string public constant INVALID_SHARE_AMOUNT = "2"; // Share must be greater than 0
    string public constant INVALID_INPUT_LENGTH = "3"; // Input array length must be greater than 0
    string public constant INPUT_LENGTH_MISMATCH = "4"; // Input array length mismatch with another array length
    string public constant NOT_WHITELISTED_ADDRESS = "5"; // Caller is not whitelisted to withdraw without fee
    string public constant MULTI_TRANSFER_FAILED = "6"; // Multi transfer of tokens has failed
    string public constant FEE_COLLECTOR_NOT_SET = "7"; // Fee Collector is not set
    string public constant NOT_ALLOWED_TO_SWEEP = "8"; // Token is not allowed to sweep
    string public constant INSUFFICIENT_BALANCE = "9"; // Insufficient balance to performs operations to follow
    string public constant INPUT_ADDRESS_IS_ZERO = "10"; // Input address is zero
    string public constant FEE_LIMIT_REACHED = "11"; // Fee must be less than MAX_BPS
    string public constant ALREADY_INITIALIZED = "12"; // Data structure, contract, or logic already initialized and can not be called again
    string public constant ADD_IN_LIST_FAILED = "13"; // Cannot add address in address list
    string public constant REMOVE_FROM_LIST_FAILED = "14"; // Cannot remove address from address list
    string public constant STRATEGY_IS_ACTIVE = "15"; // Strategy is already active, an inactive strategy is required
    string public constant STRATEGY_IS_NOT_ACTIVE = "16"; // Strategy is not active, an active strategy is required
    string public constant INVALID_STRATEGY = "17"; // Given strategy is not a strategy of this pool
    string public constant DEBT_RATIO_LIMIT_REACHED = "18"; // Debt ratio limit reached. It must be less than MAX_BPS
    string public constant TOTAL_DEBT_IS_NOT_ZERO = "19"; // Strategy total debt must be 0
    string public constant LOSS_TOO_HIGH = "20"; // Strategy reported loss must be less than current debt
    string public constant INVALID_MAX_BORROW_LIMIT = "21"; // Max borrow limit is beyond range.
    string public constant MAX_LIMIT_LESS_THAN_MIN = "22"; // Max limit should be greater than min limit.
    string public constant INVALID_SLIPPAGE = "23"; // Slippage should be less than MAX_BPS
    string public constant WRONG_RECEIPT_TOKEN = "24"; // Wrong receipt token address
    string public constant AAVE_FLASH_LOAN_NOT_ACTIVE = "25"; // aave flash loan is not active
    string public constant DYDX_FLASH_LOAN_NOT_ACTIVE = "26"; // DYDX flash loan is not active
    string public constant INVALID_FLASH_LOAN = "27"; // invalid-flash-loan
    string public constant INVALID_INITIATOR = "28"; // "invalid-initiator"
    string public constant INCORRECT_WITHDRAW_AMOUNT = "29"; // withdrawn amount is not correct
    string public constant NO_MARKET_ID_FOUND = "30"; // dydx flash loan no marketId found for token
    string public constant SAME_AS_PREVIOUS = "31"; // Input should not be same as previous value.
    string public constant INVALID_INPUT = "32"; // Generic invalid input error code
}
IGovernable.sol 12 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

/**
 * @notice Governable interface
 */
interface IGovernable {
    function governor() external view returns (address _governor);

    function transferGovernorship(address _proposedGovernor) external;
}
IPausable.sol 20 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

/**
 * @notice Pausable interface
 */
interface IPausable {
    function paused() external view returns (bool);

    function stopEverything() external view returns (bool);

    function pause() external;

    function unpause() external;

    function shutdown() external;

    function open() external;
}
IPoolRewards.sol 48 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

interface IPoolRewards {
    /// Emitted after reward added
    event RewardAdded(address indexed rewardToken, uint256 reward, uint256 rewardDuration);
    /// Emitted whenever any user claim rewards
    event RewardPaid(address indexed user, address indexed rewardToken, uint256 reward);
    /// Emitted after adding new rewards token into rewardTokens array
    event RewardTokenAdded(address indexed rewardToken, address[] existingRewardTokens);

    function claimReward(address) external;

    function notifyRewardAmount(address rewardToken_, uint256 _rewardAmount, uint256 _rewardDuration) external;

    function notifyRewardAmount(
        address[] memory rewardTokens_,
        uint256[] memory rewardAmounts_,
        uint256[] memory rewardDurations_
    ) external;

    function updateReward(address) external;

    function claimable(
        address account_
    ) external view returns (address[] memory _rewardTokens, uint256[] memory _claimableAmounts);

    function lastTimeRewardApplicable(address rewardToken_) external view returns (uint256);

    function rewardForDuration()
        external
        view
        returns (address[] memory _rewardTokens, uint256[] memory _rewardForDuration);

    function rewardPerToken()
        external
        view
        returns (address[] memory _rewardTokens, uint256[] memory _rewardPerTokenRate);

    function getRewardTokens() external view returns (address[] memory);

    function isRewardToken(address) external view returns (bool);

    function addRewardToken(address newRewardToken_) external;

    function periodFinish(address) external view returns (uint256);
}
IVesperPool.sol 64 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

import "../../dependencies/openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./IGovernable.sol";
import "./IPausable.sol";

interface IVesperPool is IGovernable, IPausable, IERC20Metadata {
    function calculateUniversalFee(uint256 profit_) external view returns (uint256 _fee);

    function deposit(uint256 collateralAmount_) external;

    function excessDebt(address strategy_) external view returns (uint256);

    function poolAccountant() external view returns (address);

    function poolRewards() external view returns (address);

    function reportEarning(uint256 profit_, uint256 loss_, uint256 payback_) external;

    function reportLoss(uint256 loss_) external;

    function sweepERC20(address fromToken_) external;

    function withdraw(uint256 share_) external;

    function keepers() external view returns (address[] memory);

    function isKeeper(address address_) external view returns (bool);

    function maintainers() external view returns (address[] memory);

    function isMaintainer(address address_) external view returns (bool);

    function pricePerShare() external view returns (uint256);

    function strategy(
        address strategy_
    )
        external
        view
        returns (
            bool _active,
            uint256 _interestFee, // Obsolete
            uint256 _debtRate, // Obsolete
            uint256 _lastRebalance,
            uint256 _totalDebt,
            uint256 _totalLoss,
            uint256 _totalProfit,
            uint256 _debtRatio,
            uint256 _externalDepositFee
        );

    function token() external view returns (IERC20);

    function tokensHere() external view returns (uint256);

    function totalDebtOf(address strategy_) external view returns (uint256);

    function totalValue() external view returns (uint256);

    function totalDebt() external view returns (uint256);
}
IAave.sol 159 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

import "vesper-pools/contracts/dependencies/openzeppelin/contracts/token/ERC20/IERC20.sol";

interface PoolAddressesProviderV3 {
    function getPool() external view returns (AaveLendingPool);

    function getPoolDataProvider() external view returns (AaveProtocolDataProvider);
}

// @dev Interface support both Aave v2 and v3 methods
interface PoolAddressesProvider {
    function getPool() external view returns (address);

    // Aave v2 method.
    function getLendingPool() external view returns (address);

    function getPoolDataProvider() external view returns (address);

    function getAddress(bytes32 id) external view returns (address);

    function getPriceOracle() external view returns (address);
}

interface AaveOracle {
    function getAssetPrice(address _asset) external view returns (uint256);
}

interface AToken is IERC20 {
    /**
     * @dev Returns the address of the incentives controller contract
     **/
    function getIncentivesController() external view returns (address);

    function mint(address user, uint256 amount, uint256 index) external returns (bool);

    function burn(address user, address receiverOfUnderlying, uint256 amount, uint256 index) external;

    //solhint-disable func-name-mixedcase
    function UNDERLYING_ASSET_ADDRESS() external view returns (address);
}

interface AaveIncentivesController {
    function getRewardsBalance(address[] calldata assets, address user) external view returns (uint256);

    function claimRewards(address[] calldata assets, uint256 amount, address to) external returns (uint256);

    function claimAllRewards(
        address[] calldata assets,
        address to
    ) external returns (address[] memory rewardsList, uint256[] memory claimedAmounts);

    function getRewardsList() external view returns (address[] memory);
}

interface AaveLendingPool {
    function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external;

    function supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external;

    function withdraw(address asset, uint256 amount, address to) external returns (uint256);

    function flashLoan(
        address receiverAddress,
        address[] calldata assets,
        uint256[] calldata amounts,
        uint256[] calldata interestRateModes,
        address onBehalfOf,
        bytes calldata params,
        uint16 referralCode
    ) external;

    function borrow(
        address asset,
        uint256 amount,
        uint256 interestRateMode,
        uint16 referralCode,
        address onBehalfOf
    ) external;

    function repay(address asset, uint256 amount, uint256 interestRateMode, address onBehalfOf) external;

    function getUserAccountData(
        address _user
    )
        external
        view
        returns (
            uint256 totalCollateralETH,
            uint256 totalDebtETH,
            uint256 availableBorrowsETH,
            uint256 currentLiquidationThreshold,
            uint256 ltv,
            uint256 healthFactor
        );
}

interface AaveProtocolDataProvider {
    function getReserveTokensAddresses(
        address asset
    ) external view returns (address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress);

    function getReserveData(
        address asset
    )
        external
        view
        returns (
            uint256 availableLiquidity,
            uint256 totalStableDebt,
            uint256 totalVariableDebt,
            uint256 liquidityRate,
            uint256 variableBorrowRate,
            uint256 stableBorrowRate,
            uint256 averageStableBorrowRate,
            uint256 liquidityIndex,
            uint256 variableBorrowIndex,
            uint40 lastUpdateTimestamp
        );

    function getReserveConfigurationData(
        address asset
    )
        external
        view
        returns (
            uint256 decimals,
            uint256 ltv,
            uint256 liquidationThreshold,
            uint256 liquidationBonus,
            uint256 reserveFactor,
            bool usageAsCollateralEnabled,
            bool borrowingEnabled,
            bool stableBorrowRateEnabled,
            bool isActive,
            bool isFrozen
        );
}

//solhint-disable func-name-mixedcase
interface StakedAave is IERC20 {
    function claimRewards(address to, uint256 amount) external;

    function cooldown() external;

    function stake(address onBehalfOf, uint256 amount) external;

    function redeem(address to, uint256 amount) external;

    function getTotalRewardsBalance(address staker) external view returns (uint256);

    function stakersCooldowns(address staker) external view returns (uint256);

    function COOLDOWN_SECONDS() external view returns (uint256);

    function UNSTAKE_WINDOW() external view returns (uint256);
}
IWstETH.sol 15 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

import "vesper-pools/contracts/dependencies/openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IWstETH is IERC20 {
    function unwrap(uint256 _wstETHAmount) external returns (uint256 _stETHAmount);

    function wrap(uint256 _stETHAmount) external returns (uint256 _wstETHAmount);

    function getStETHByWstETH(uint256 _wstETHAmount) external view returns (uint256 _stETHAmount);

    function getWstETHByStETH(uint256 _stETHAmount) external view returns (uint256 _wstETHAmount);
}
ISommelier.sol 62 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

import "vesper-pools/contracts/dependencies/openzeppelin/contracts/token/ERC20/IERC20.sol";

interface ICellar is IERC20 {
    function asset() external view returns (address);

    /**
     * @notice The amount of assets that the cellar would exchange for the amount of shares provided.
     * @param shares amount of shares to convert
     * @return assets the shares can be exchanged for
     */
    function convertToAssets(uint256 shares) external view returns (uint256);

    /**
     * @notice After deposits users must wait `shareLockPeriod` time before being able to transfer or withdraw their shares.
     */
    function shareLockPeriod() external view returns (uint256);

    /**
     * @notice The total amount of withdrawable assets in the cellar.
     * @dev Run a re-entrancy check because totalAssetsWithdrawable can be wrong if re-entering from deposit/withdraws.
     */
    function totalAssetsWithdrawable() external view returns (uint256 assets);

    /**
     * @notice mapping that stores every users last time stamp they minted shares.
     */
    function userShareLockStartTime(address user) external view returns (uint256 lockTime);

    /**
     * @notice Simulate the effects of depositing assets at the current block, given current on-chain conditions.
     * @param assets amount of assets to deposit
     * @return shares that will be minted
     */
    function previewDeposit(uint256 assets) external view returns (uint256 shares);

    /**
     * @notice Deposits assets into the cellar, and returns shares to receiver.
     * @param assets amount of assets deposited by user.
     * @param receiver address to receive the shares.
     * @return shares amount of shares given for deposit.
     */
    function deposit(uint256 assets, address receiver) external returns (uint256 shares);

    /**
     * @notice Withdraw assets from the cellar by redeeming shares.
     * @dev Unlike conventional ERC4626 contracts, this may not always return one asset to the receiver.
     *      Since there are no swaps involved in this function, the receiver may receive multiple
     *      assets. The value of all the assets returned will be equal to the amount defined by
     *      `assets` denominated in the `asset` of the cellar (eg. if `asset` is USDC and `assets`
     *      is 1000, then the receiver will receive $1000 worth of assets in either one or many
     *      tokens).
     * @param assets equivalent value of the assets withdrawn, denominated in the cellar's asset
     * @param receiver address that will receive withdrawn assets
     * @param owner address that owns the shares being redeemed
     * @return shares amount of shares redeemed
     */
    function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
}
IRoutedSwapper.sol 51 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

/**
 * @notice Routed Swapper interface
 * @dev This contract doesn't support native coins (e.g. ETH, AVAX, MATIC, etc) use wrapper tokens instead
 */
interface IRoutedSwapper {
    /**
     * @notice The list of supported DEXes
     * @dev This function is gas intensive
     */
    function getAllExchanges() external view returns (address[] memory);

    /**
     * @notice Get *spot* quote
     * It will return the swap amount based on the current reserves of the best pair/path found (i.e. spot price).
     * @dev It shouldn't be used as oracle!!!
     */
    function getAmountIn(address tokenIn_, address tokenOut_, uint256 amountOut_) external returns (uint256 _amountIn);

    /**
     * @notice Get *spot* quote
     * It will return the swap amount based on the current reserves of the best pair/path found (i.e. spot price).
     * @dev It shouldn't be used as oracle!!!
     */
    function getAmountOut(address tokenIn_, address tokenOut_, uint256 amountIn_) external returns (uint256 _amountOut);

    /**
     * @notice Perform an exact input swap - will revert if there is no default routing
     */
    function swapExactInput(
        address tokenIn_,
        address tokenOut_,
        uint256 amountIn_,
        uint256 amountOutMin_,
        address _receiver
    ) external returns (uint256 _amountOut);

    /**
     * @notice Perform an exact output swap - will revert if there is no default routing
     */
    function swapExactOutput(
        address tokenIn_,
        address tokenOut_,
        uint256 amountOut_,
        uint256 amountInMax_,
        address receiver_
    ) external returns (uint256 _amountIn);
}
AaveV3Incentive.sol 22 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;
import "../../../interfaces/aave/IAave.sol";

/// @title This contract provide core operations for Aave v3
library AaveV3Incentive {
    /**
     * @notice Claim rewards from Aave incentive controller
     */
    function _claimRewards(
        address _aToken
    ) internal returns (address[] memory rewardsList, uint256[] memory claimedAmounts) {
        // Some aTokens may have no incentive controller method/variable. Better use try catch
        try AToken(_aToken).getIncentivesController() returns (address _aaveIncentivesController) {
            address[] memory assets = new address[](1);
            assets[0] = address(_aToken);
            return AaveIncentivesController(_aaveIncentivesController).claimAllRewards(assets, address(this));
            //solhint-disable no-empty-blocks
        } catch {}
    }
}
AaveV3SommelierStETH.sol 66 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

import "../../../interfaces/external/lido/IWstETH.sol";
import "./AaveV3SommelierXy.sol";

/// @title Deposit wstETH in Aave and earn yield by depositing borrowed token in a Vesper Pool.
contract AaveV3SommelierStETH is AaveV3SommelierXy {
    using SafeERC20 for IERC20;

    IWstETH internal constant WSTETH = IWstETH(0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0);

    constructor(
        address pool_,
        address swapper_,
        address receiptToken_,
        address borrowToken_,
        address aaveAddressProvider_,
        address cellar_,
        string memory name_
    ) AaveV3SommelierXy(pool_, swapper_, receiptToken_, borrowToken_, aaveAddressProvider_, cellar_, name_) {}

    /// @notice Returns total collateral locked in the strategy
    function tvl() external view virtual override returns (uint256) {
        // receiptToken is aToken. aToken is 1:1 of collateral token
        return
            IERC20(receiptToken).balanceOf(address(this)) +
            wrappedCollateral.balanceOf(address(this)) +
            _calculateWrapped(collateralToken.balanceOf(address(this)));
    }

    function _approveToken(uint256 amount_) internal virtual override {
        super._approveToken(amount_);
        collateralToken.safeApprove(address(wrappedCollateral), amount_);
    }

    function _calculateUnwrapped(uint256 wrappedAmount_) internal view override returns (uint256) {
        return WSTETH.getStETHByWstETH(wrappedAmount_);
    }

    function _calculateWrapped(uint256 unwrappedAmount_) internal view override returns (uint256) {
        return WSTETH.getWstETHByStETH(unwrappedAmount_);
    }

    function _getCollateralHere() internal virtual override returns (uint256) {
        uint256 _wrapped = wrappedCollateral.balanceOf(address(this));
        if (_wrapped > 0) {
            _unwrap(_wrapped);
        }
        // Return unwrapped balance
        return collateralToken.balanceOf(address(this));
    }

    function _getWrappedToken(IERC20) internal pure override returns (IERC20) {
        return IERC20(address(WSTETH));
    }

    function _unwrap(uint256 wrappedAmount_) internal override returns (uint256) {
        return WSTETH.unwrap(wrappedAmount_);
    }

    function _wrap(uint256 unwrappedAmount_) internal override returns (uint256) {
        return WSTETH.wrap(unwrappedAmount_);
    }
}
AaveV3SommelierXy.sol 62 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

import "vesper-pools/contracts/interfaces/vesper/IVesperPool.sol";
import "./AaveV3Xy.sol";
import "../../sommelier/SommelierBase.sol";
import "../../../interfaces/sommelier/ISommelier.sol";

/// @title Deposit Collateral in Aave and earn yield by depositing borrowed token in a Sommelier Vault.
contract AaveV3SommelierXy is AaveV3Xy, SommelierBase {
    using SafeERC20 for IERC20;

    constructor(
        address _pool,
        address _swapper,
        address _receiptToken,
        address _borrowToken,
        address _aaveAddressProvider,
        address _cellar,
        string memory _name
    ) AaveV3Xy(_pool, _swapper, _receiptToken, _borrowToken, _aaveAddressProvider, _name) SommelierBase(_cellar) {
        require(ICellar(_cellar).asset() == borrowToken, "invalid-sommelier-vault");
    }

    /// @dev After borrowing Y, deposit to Sommelier vault
    function _afterBorrowY(uint256 _amount) internal virtual override {
        _depositInSommelier(_amount);
    }

    /// @notice Approve all required tokens
    function _approveToken(uint256 _amount) internal virtual override {
        super._approveToken(_amount);
        IERC20(borrowToken).safeApprove(address(cellar), _amount);
    }

    /// @dev Before repaying Y, withdraw it from Sommelier vault

    function _beforeRepayY(uint256 _amount) internal virtual override {
        _withdrawFromSommelier(_amount);
    }

    /// @dev borrowToken balance here + borrowToken balance deposited in Sommelier vault
    function _getInvestedBorrowBalance() internal view virtual override returns (uint256) {
        return IERC20(borrowToken).balanceOf(address(this)) + _getAssetsInSommelier();
    }

    /// @dev Swap excess borrow for more collateral when underlying Sommelier vault is making profits
    function _rebalanceBorrow(uint256 _excessBorrow) internal virtual override {
        if (_excessBorrow > 0) {
            uint256 _borrowedHere = IERC20(borrowToken).balanceOf(address(this));
            if (_borrowedHere < _excessBorrow) {
                _withdrawFromSommelier(_excessBorrow - _borrowedHere);
                _borrowedHere = IERC20(borrowToken).balanceOf(address(this));
            }
            if (_borrowedHere > 0) {
                // Swap minimum of _excessBorrow and _borrowedHere for collateral
                _safeSwapExactInput(borrowToken, address(wrappedCollateral), Math.min(_excessBorrow, _borrowedHere));
            }
        }
    }
}
AaveV3Xy.sol 403 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

import "vesper-pools/contracts/interfaces/vesper/IPoolRewards.sol";
import "vesper-pools/contracts/Errors.sol";
import "../../../interfaces/aave/IAave.sol";
import "./AaveV3Incentive.sol";
import "../../Strategy.sol";

// solhint-disable no-empty-blocks

/// @title Deposit Collateral in Aave and earn interest by depositing borrowed token in a Vesper Pool.
contract AaveV3Xy is Strategy {
    using SafeERC20 for IERC20;

    // solhint-disable-next-line var-name-mixedcase
    string public NAME;
    string public constant VERSION = "5.1.1";

    uint256 internal constant MAX_BPS = 10_000; //100%
    uint256 public minBorrowLimit = 7_000; // 70% of actual collateral factor of protocol
    uint256 public maxBorrowLimit = 8_500; // 85% of actual collateral factor of protocol

    PoolAddressesProvider public immutable aaveAddressProvider;
    address public borrowToken;
    AToken public vdToken; // Variable Debt Token
    address internal aBorrowToken;

    IERC20 public wrappedCollateral;

    event UpdatedBorrowLimit(
        uint256 previousMinBorrowLimit,
        uint256 newMinBorrowLimit,
        uint256 previousMaxBorrowLimit,
        uint256 newMaxBorrowLimit
    );

    constructor(
        address _pool,
        address _swapper,
        address _receiptToken,
        address _borrowToken,
        address _aaveAddressProvider,
        string memory _name
    ) Strategy(_pool, _swapper, _receiptToken) {
        NAME = _name;
        require(_aaveAddressProvider != address(0), "addressProvider-is-zero");
        wrappedCollateral = _getWrappedToken(collateralToken);
        require(
            AToken(_receiptToken).UNDERLYING_ASSET_ADDRESS() == address(wrappedCollateral),
            "invalid-receipt-token"
        );
        (address _aBorrowToken, , address _vdToken) = AaveProtocolDataProvider(
            PoolAddressesProvider(_aaveAddressProvider).getPoolDataProvider()
        ).getReserveTokensAddresses(_borrowToken);
        vdToken = AToken(_vdToken);
        borrowToken = _borrowToken;
        aBorrowToken = _aBorrowToken;
        aaveAddressProvider = PoolAddressesProvider(_aaveAddressProvider);
    }

    function isReservedToken(address _token) public view virtual override returns (bool) {
        return
            _token == address(collateralToken) ||
            _token == receiptToken ||
            address(vdToken) == _token ||
            borrowToken == _token;
    }

    /// @notice Returns total collateral locked in the strategy
    function tvl() external view virtual override returns (uint256) {
        // receiptToken is aToken. aToken is 1:1 of collateral token
        return IERC20(receiptToken).balanceOf(address(this)) + collateralToken.balanceOf(address(this));
    }

    /// @notice After borrowing Y Hook
    function _afterBorrowY(uint256 _amount) internal virtual {}

    /// @notice Approve all required tokens
    function _approveToken(uint256 _amount) internal virtual override {
        super._approveToken(_amount);
        address _swapper = address(swapper);
        wrappedCollateral.safeApprove(aaveAddressProvider.getPool(), _amount);
        wrappedCollateral.safeApprove(_swapper, _amount);
        IERC20(borrowToken).safeApprove(aaveAddressProvider.getPool(), _amount);
        IERC20(borrowToken).safeApprove(_swapper, _amount);
        try AToken(receiptToken).getIncentivesController() returns (address _aaveIncentivesController) {
            address[] memory _rewardTokens = AaveIncentivesController(_aaveIncentivesController).getRewardsList();
            for (uint256 i; i < _rewardTokens.length; ++i) {
                // WrappedCollateral and borrowToken already approved swapper and hence this check.
                if (_rewardTokens[i] != address(wrappedCollateral) && _rewardTokens[i] != borrowToken) {
                    IERC20(_rewardTokens[i]).safeApprove(_swapper, _amount);
                }
            }
            //solhint-disable no-empty-blocks
        } catch {}
    }

    /**
     * @notice Claim rewardToken and transfer to new strategy
     * @param _newStrategy Address of new strategy.
     */
    function _beforeMigration(address _newStrategy) internal virtual override {
        require(IStrategy(_newStrategy).token() == receiptToken, "wrong-receipt-token");
        uint256 _repayAmount = vdToken.balanceOf(address(this));
        if (_repayAmount > 0) {
            _repayY(_repayAmount, AaveLendingPool(aaveAddressProvider.getPool()));
        }
    }

    /// @notice Before repaying Y Hook
    function _beforeRepayY(uint256 _amount) internal virtual {}

    /**
     * @notice Calculate borrow and repay amount based on current collateral and new deposit/withdraw amount.
     * @param _depositAmount wrapped collateral amount to deposit
     * @param _withdrawAmount wrapped collateral amount to withdraw
     * @param _borrowed borrowed from protocol
     * @param _supplied wrapped collateral supplied to protocol
     * @return _borrowAmount borrow more amount
     * @return _repayAmount repay amount to keep ltv within limit
     */
    function _calculateBorrowPosition(
        uint256 _depositAmount,
        uint256 _withdrawAmount,
        uint256 _borrowed,
        uint256 _supplied
    ) internal view returns (uint256 _borrowAmount, uint256 _repayAmount) {
        require(_depositAmount == 0 || _withdrawAmount == 0, "all-input-gt-zero");
        // If maximum borrow limit set to 0 then repay borrow
        if (maxBorrowLimit == 0) {
            return (0, _borrowed);
        }
        // In case of withdraw, _amount can be greater than _supply
        uint256 _hypotheticalCollateral = _depositAmount > 0 ? _supplied + _depositAmount : _supplied > _withdrawAmount
            ? _supplied - _withdrawAmount
            : 0;
        if (_hypotheticalCollateral == 0) {
            return (0, _borrowed);
        }
        AaveOracle _aaveOracle = AaveOracle(aaveAddressProvider.getPriceOracle());

        uint256 _borrowTokenPrice = _aaveOracle.getAssetPrice(borrowToken);
        uint256 _collateralTokenPrice = _aaveOracle.getAssetPrice(address(wrappedCollateral));
        if (_borrowTokenPrice == 0 || _collateralTokenPrice == 0) {
            // Oracle problem. Lets payback all
            return (0, _borrowed);
        }
        // _collateralFactor in 4 decimal. 10_000 = 100%
        (, uint256 _collateralFactor, , , , , , , , ) = AaveProtocolDataProvider(
            aaveAddressProvider.getPoolDataProvider()
        ).getReserveConfigurationData(address(wrappedCollateral));

        // Collateral in base currency based on oracle price and cf;
        uint256 _actualCollateralForBorrow = (_hypotheticalCollateral * _collateralFactor * _collateralTokenPrice) /
            (MAX_BPS * (10 ** IERC20Metadata(address(wrappedCollateral)).decimals()));
        // Calculate max borrow possible in borrow token number
        uint256 _maxBorrowPossible = (_actualCollateralForBorrow *
            (10 ** IERC20Metadata(address(borrowToken)).decimals())) / _borrowTokenPrice;
        if (_maxBorrowPossible == 0) {
            return (0, _borrowed);
        }
        // Safe buffer to avoid liquidation due to price variations.
        uint256 _borrowUpperBound = (_maxBorrowPossible * maxBorrowLimit) / MAX_BPS;

        // Borrow up to _borrowLowerBound and keep buffer of _borrowUpperBound - _borrowLowerBound for price variation
        uint256 _borrowLowerBound = (_maxBorrowPossible * minBorrowLimit) / MAX_BPS;

        // If current borrow is greater than max borrow, then repay to achieve safe position.
        if (_borrowed > _borrowUpperBound) {
            // If borrow > upperBound then it is greater than lowerBound too.
            _repayAmount = _borrowed - _borrowLowerBound;
        } else if (_borrowLowerBound > _borrowed) {
            _borrowAmount = _borrowLowerBound - _borrowed;
            uint256 _availableLiquidity = IERC20(borrowToken).balanceOf(aBorrowToken);
            if (_borrowAmount > _availableLiquidity) {
                _borrowAmount = _availableLiquidity;
            }
        }
    }

    function _calculateUnwrapped(uint256 wrappedAmount_) internal view virtual returns (uint256) {
        return wrappedAmount_;
    }

    function _calculateWrapped(uint256 unwrappedAmount_) internal view virtual returns (uint256) {
        return unwrappedAmount_;
    }

    /// @dev Claim all rewards and convert to collateral.
    /// Overriding _claimAndSwapRewards will help child contract otherwise override _claimReward.
    function _claimAndSwapRewards() internal virtual override {
        (address[] memory _tokens, uint256[] memory _amounts) = AaveV3Incentive._claimRewards(receiptToken);
        uint256 _length = _tokens.length;
        for (uint256 i; i < _length; ++i) {
            if (_amounts[i] > 0 && _tokens[i] != address(wrappedCollateral)) {
                _safeSwapExactInput(_tokens[i], address(wrappedCollateral), _amounts[i]);
            }
        }
    }

    function _depositToAave(uint256 _amount, AaveLendingPool _aaveLendingPool) internal virtual {
        uint256 _wrappedAmount = _wrap(_amount);
        if (_wrappedAmount > 0) {
            try _aaveLendingPool.supply(address(wrappedCollateral), _wrappedAmount, address(this), 0) {} catch Error(
                string memory _reason
            ) {
                // Aave uses liquidityIndex and some other indexes as needed to normalize input.
                // If normalized input equals to 0 then error will be thrown with '56' error code.
                // CT_INVALID_MINT_AMOUNT = '56'; //invalid amount to mint
                // Hence discard error where error code is '56'
                require(bytes32(bytes(_reason)) == "56", "deposit failed");
            }
        }
    }

    function _getCollateralHere() internal virtual returns (uint256) {
        return collateralToken.balanceOf(address(this));
    }

    /// @notice Borrowed Y balance deposited here or elsewhere hook
    function _getInvestedBorrowBalance() internal view virtual returns (uint256) {
        return IERC20(borrowToken).balanceOf(address(this));
    }

    function _getWrappedToken(IERC20 unwrappedToken_) internal pure virtual returns (IERC20) {
        return unwrappedToken_;
    }

    /**
     * @dev Generate report for pools accounting and also send profit and any payback to pool.
     */
    function _rebalance() internal override returns (uint256 _profit, uint256 _loss, uint256 _payback) {
        // NOTE:: Pool has unwrapped as collateral and any state is also unwrapped amount
        uint256 _excessDebt = IVesperPool(pool).excessDebt(address(this));
        uint256 _borrowed = vdToken.balanceOf(address(this));
        uint256 _investedBorrowBalance = _getInvestedBorrowBalance();
        AaveLendingPool _aaveLendingPool = AaveLendingPool(aaveAddressProvider.getPool());

        // _borrow increases every block. Convert collateral to borrowToken.
        if (_borrowed > _investedBorrowBalance) {
            _swapToBorrowToken(_borrowed - _investedBorrowBalance, _aaveLendingPool);
        } else {
            // When _investedBorrowBalance exceeds _borrow balance from Aave
            // Customize this hook to handle the excess borrowToken for profit
            _rebalanceBorrow(_investedBorrowBalance - _borrowed);
        }
        uint256 _collateralHere = _getCollateralHere();
        uint256 _supplied = IERC20(receiptToken).balanceOf(address(this));
        uint256 _unwrappedSupplied = _calculateUnwrapped(_supplied);
        uint256 _totalCollateral = _unwrappedSupplied + _collateralHere;
        uint256 _totalDebt = IVesperPool(pool).totalDebtOf(address(this));

        if (_totalCollateral > _totalDebt) {
            _profit = _totalCollateral - _totalDebt;
        } else {
            _loss = _totalDebt - _totalCollateral;
        }
        uint256 _profitAndExcessDebt = _profit + _excessDebt;
        if (_collateralHere < _profitAndExcessDebt) {
            uint256 _totalAmountToWithdraw = Math.min((_profitAndExcessDebt - _collateralHere), _unwrappedSupplied);
            if (_totalAmountToWithdraw > 0) {
                _withdrawHere(_totalAmountToWithdraw, _aaveLendingPool, _borrowed, _supplied);
                _collateralHere = collateralToken.balanceOf(address(this));
            }
        }

        // Make sure _collateralHere >= _payback + profit. set actual payback first and then profit
        _payback = Math.min(_collateralHere, _excessDebt);
        _profit = _collateralHere > _payback ? Math.min((_collateralHere - _payback), _profit) : 0;

        IVesperPool(pool).reportEarning(_profit, _loss, _payback);
        // This is unwrapped balance if pool supports unwrap token eg stETH
        uint256 _newSupply = collateralToken.balanceOf(address(this));
        if (_newSupply > 0) {
            _depositToAave(_newSupply, _aaveLendingPool);
        }

        // There are scenarios when we want to call _calculateBorrowPosition and act on it.
        // 1. Strategy got some collateral from pool which will allow strategy to borrow more.
        // 2. Collateral and/or borrow token price is changed which leads to repay or borrow.
        // 3. BorrowLimits are updated.
        // In some edge scenarios, below call is redundant but keeping it as is for simplicity.
        (uint256 _borrowAmount, uint256 _repayAmount) = _calculateBorrowPosition(
            0,
            0,
            vdToken.balanceOf(address(this)),
            IERC20(receiptToken).balanceOf(address(this))
        );
        if (_repayAmount > 0) {
            // Repay _borrowAmount to maintain safe position
            _repayY(_repayAmount, _aaveLendingPool);
        } else if (_borrowAmount > 0) {
            // 2 for variable rate borrow, 0 for referralCode
            _aaveLendingPool.borrow(borrowToken, _borrowAmount, 2, 0, address(this));
        }
        uint256 _borrowTokenBalance = IERC20(borrowToken).balanceOf(address(this));
        if (_borrowTokenBalance > 0) {
            _afterBorrowY(_borrowTokenBalance);
        }
    }

    /// @notice Swap excess borrow for more collateral hook
    function _rebalanceBorrow(uint256 _excessBorrow) internal virtual {}

    function _repayY(uint256 _amount, AaveLendingPool _aaveLendingPool) internal virtual {
        _beforeRepayY(_amount);
        _aaveLendingPool.repay(borrowToken, _amount, 2, address(this));
    }

    /**
     * @dev Swap collateral to borrow token.
     * @param _shortOnBorrow Expected output of this swap
     */
    function _swapToBorrowToken(uint256 _shortOnBorrow, AaveLendingPool _aaveLendingPool) internal {
        // Looking for _amountIn using fixed output amount
        uint256 _amountIn = swapper.getAmountIn(address(wrappedCollateral), borrowToken, _shortOnBorrow);
        if (_amountIn > 0) {
            // Not using unwrapped balance here as those can be used in rebalance reporting via getCollateralHere
            uint256 _collateralHere = wrappedCollateral.balanceOf(address(this));
            if (_amountIn > _collateralHere) {
                // Withdraw some collateral from Aave so that we have enough collateral to get expected output
                uint256 _amount = _amountIn - _collateralHere;
                require(
                    _aaveLendingPool.withdraw(address(wrappedCollateral), _amount, address(this)) == _amount,
                    Errors.INCORRECT_WITHDRAW_AMOUNT
                );
            }
            swapper.swapExactOutput(address(wrappedCollateral), borrowToken, _shortOnBorrow, _amountIn, address(this));
        }
    }

    function _unwrap(uint256 wrappedAmount_) internal virtual returns (uint256) {
        return wrappedAmount_;
    }

    function _wrap(uint256 unwrappedAmount_) internal virtual returns (uint256) {
        return unwrappedAmount_;
    }

    /// @dev If pool supports unwrapped token(stETH) then input and output both are unwrapped token amount.
    function _withdrawHere(uint256 _requireAmount) internal override {
        _withdrawHere(
            _requireAmount,
            AaveLendingPool(aaveAddressProvider.getPool()),
            vdToken.balanceOf(address(this)),
            IERC20(receiptToken).balanceOf(address(this))
        );
    }

    /**
     * @dev If pool supports unwrapped token(stETH) then _requireAmount and output both are unwrapped token amount.
     * @param _requireAmount unwrapped collateral amount
     * @param _supplied wrapped collateral amount
     */
    function _withdrawHere(
        uint256 _requireAmount,
        AaveLendingPool _aaveLendingPool,
        uint256 _borrowed,
        uint256 _supplied
    ) internal {
        uint256 _wrappedRequireAmount = _calculateWrapped(_requireAmount);
        (, uint256 _repayAmount) = _calculateBorrowPosition(0, _wrappedRequireAmount, _borrowed, _supplied);
        if (_repayAmount > 0) {
            _repayY(_repayAmount, _aaveLendingPool);
        }
        // withdraw asking more than available liquidity will fail. To do safe withdraw, check
        // _wrappedRequireAmount against available liquidity.
        uint256 _possibleWithdraw = Math.min(
            _wrappedRequireAmount,
            Math.min(_supplied, wrappedCollateral.balanceOf(receiptToken))
        );
        require(
            _aaveLendingPool.withdraw(address(wrappedCollateral), _possibleWithdraw, address(this)) ==
                _possibleWithdraw,
            Errors.INCORRECT_WITHDRAW_AMOUNT
        );
        // Unwrap wrapped tokens
        _unwrap(wrappedCollateral.balanceOf(address(this)));
    }

    /************************************************************************************************
     *                          Governor/admin/keeper function                                      *
     ***********************************************************************************************/
    /**
     * @notice Update upper and lower borrow limit. Usually maxBorrowLimit < 100% of actual collateral factor of protocol.
     * @dev It is possible to set _maxBorrowLimit and _minBorrowLimit as 0 to not borrow anything
     * @param _minBorrowLimit It is % of actual collateral factor of protocol
     * @param _maxBorrowLimit It is % of actual collateral factor of protocol
     */
    function updateBorrowLimit(uint256 _minBorrowLimit, uint256 _maxBorrowLimit) external onlyGovernor {
        require(_maxBorrowLimit < MAX_BPS, "invalid-max-borrow-limit");
        // set _maxBorrowLimit and _minBorrowLimit to disable borrow;
        require(
            (_maxBorrowLimit == 0 && _minBorrowLimit == 0) || _maxBorrowLimit > _minBorrowLimit,
            "max-should-be-higher-than-min"
        );
        emit UpdatedBorrowLimit(minBorrowLimit, _minBorrowLimit, maxBorrowLimit, _maxBorrowLimit);
        minBorrowLimit = _minBorrowLimit;
        maxBorrowLimit = _maxBorrowLimit;
    }
}
SommelierBase.sol 51 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;
import "vesper-pools/contracts/dependencies/openzeppelin/contracts/utils/math/Math.sol";
import "../../interfaces/sommelier/ISommelier.sol";

/// @dev This strategy will deposit collateral token in Sommelier and earn yield.
abstract contract SommelierBase {
    // Same as receiptToken but it's immutable and saves gas
    ICellar public immutable cellar;

    constructor(address cellar_) {
        cellar = ICellar(cellar_);
    }

    /**
     * @notice Time when withdraw and transfer will be unlocked.
     */
    function unlockTime() public view returns (uint256) {
        return cellar.userShareLockStartTime(address(this)) + cellar.shareLockPeriod();
    }

    function _depositInSommelier(uint256 amount_) internal returns (uint256 shares_) {
        if (cellar.previewDeposit(amount_) != 0) {
            shares_ = cellar.deposit(amount_, address(this));
        }
    }

    function _getAssetsInSommelier() internal view returns (uint256) {
        return cellar.convertToAssets(cellar.balanceOf(address(this)));
    }

    /**
     * @dev Withdraw from sommelier vault
     * @param requireAmount_ equivalent value of the assets withdrawn, denominated in the cellar's asset
     * @return shares_ amount of shares redeemed
     */
    function _withdrawFromSommelier(uint256 requireAmount_) internal returns (uint256 shares_) {
        if (block.timestamp >= unlockTime()) {
            // withdraw asking more than available liquidity will fail. To do safe withdraw, check
            // requireAmount_ against available liquidity.
            uint256 _withdrawable = Math.min(
                requireAmount_,
                Math.min(_getAssetsInSommelier(), cellar.totalAssetsWithdrawable())
            );
            if (_withdrawable > 0) {
                shares_ = cellar.withdraw(_withdrawable, address(this), address(this));
            }
        }
    }
}
Strategy.sol 243 lines
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

import "vesper-pools/contracts/interfaces/vesper/IVesperPool.sol";
import "vesper-pools/contracts/dependencies/openzeppelin/contracts/token/ERC20/IERC20.sol";
import "vesper-pools/contracts/dependencies/openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "vesper-pools/contracts/dependencies/openzeppelin/contracts/utils/Context.sol";
import "vesper-pools/contracts/dependencies/openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "vesper-pools/contracts/dependencies/openzeppelin/contracts/utils/math/Math.sol";
import "vesper-commons/contracts/interfaces/vesper/IStrategy.sol";
import "../interfaces/swapper/IRoutedSwapper.sol";

abstract contract Strategy is IStrategy, Context {
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.AddressSet;

    IERC20 public immutable collateralToken;
    address public receiptToken;
    address public immutable override pool;
    address public override feeCollector;
    IRoutedSwapper public swapper;
    address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
    uint256 internal constant MAX_UINT_VALUE = type(uint256).max;

    EnumerableSet.AddressSet private _keepers;

    event UpdatedFeeCollector(address indexed previousFeeCollector, address indexed newFeeCollector);
    event UpdatedSwapper(IRoutedSwapper indexed oldSwapper, IRoutedSwapper indexed newSwapper);

    constructor(address _pool, address _swapper, address _receiptToken) {
        require(_pool != address(0), "pool-address-is-zero");
        require(_swapper != address(0), "swapper-address-is-zero");
        swapper = IRoutedSwapper(_swapper);
        pool = _pool;
        collateralToken = IVesperPool(_pool).token();
        receiptToken = _receiptToken;
        require(_keepers.add(_msgSender()), "add-keeper-failed");
    }

    modifier onlyGovernor() {
        require(_msgSender() == IVesperPool(pool).governor(), "caller-is-not-the-governor");
        _;
    }

    modifier onlyKeeper() {
        require(_keepers.contains(_msgSender()), "caller-is-not-a-keeper");
        _;
    }

    modifier onlyPool() {
        require(_msgSender() == pool, "caller-is-not-vesper-pool");
        _;
    }

    /**
     * @notice Add given address in keepers list.
     * @param _keeperAddress keeper address to add.
     */
    function addKeeper(address _keeperAddress) external onlyGovernor {
        require(_keepers.add(_keeperAddress), "add-keeper-failed");
    }

    /// @dev Approve all required tokens
    function approveToken(uint256 _approvalAmount) external onlyKeeper {
        _approveToken(_approvalAmount);
    }

    /// @notice Claim rewardToken and convert rewardToken into collateral token.
    function claimAndSwapRewards(uint256 _minAmountOut) external onlyKeeper returns (uint256 _amountOut) {
        uint256 _collateralBefore = collateralToken.balanceOf(address(this));
        _claimAndSwapRewards();
        _amountOut = collateralToken.balanceOf(address(this)) - _collateralBefore;
        require(_amountOut >= _minAmountOut, "not-enough-amountOut");
    }

    /// @notice Check whether given token is reserved or not. Reserved tokens are not allowed to sweep.
    function isReservedToken(address _token) public view virtual override returns (bool);

    /// @notice Return list of keepers
    function keepers() external view override returns (address[] memory) {
        return _keepers.values();
    }

    /**
     * @notice Migrate all asset and vault ownership,if any, to new strategy
     * @dev _beforeMigration hook can be implemented in child strategy to do extra steps.
     * @param _newStrategy Address of new strategy
     */
    function migrate(address _newStrategy) external virtual override onlyPool {
        require(_newStrategy != address(0), "new-strategy-address-is-zero");
        require(IStrategy(_newStrategy).pool() == pool, "not-valid-new-strategy");
        _beforeMigration(_newStrategy);
        IERC20(receiptToken).safeTransfer(_newStrategy, IERC20(receiptToken).balanceOf(address(this)));
        collateralToken.safeTransfer(_newStrategy, collateralToken.balanceOf(address(this)));
    }

    /**
     * @notice OnlyKeeper: Rebalance profit, loss and investment of this strategy.
     *  Calculate profit, loss and payback of this strategy and realize profit/loss and
     *  withdraw fund for payback, if any, and submit this report to pool.
     * @return _profit Realized profit in collateral.
     * @return _loss Realized loss, if any, in collateral.
     * @return _payback If strategy has any excess debt, we have to liquidate asset to payback excess debt.
     */
    function rebalance() external onlyKeeper returns (uint256 _profit, uint256 _loss, uint256 _payback) {
        return _rebalance();
    }

    /**
     * @notice Remove given address from keepers list.
     * @param _keeperAddress keeper address to remove.
     */
    function removeKeeper(address _keeperAddress) external onlyGovernor {
        require(_keepers.remove(_keeperAddress), "remove-keeper-failed");
    }

    /// @notice onlyKeeper:: Swap given token into collateral token.
    function swapToCollateral(IERC20 _tokenIn, uint256 _minAmountOut) external onlyKeeper returns (uint256 _amountOut) {
        require(address(_tokenIn) != address(collateralToken), "not-allowed-to-sweep-collateral");
        require(!isReservedToken(address(_tokenIn)), "not-allowed-to-sweep");
        uint256 _collateralBefore = collateralToken.balanceOf(address(this));
        uint256 _amountIn = _tokenIn.balanceOf(address(this));
        if (_amountIn > 0) {
            if (_amountIn > _tokenIn.allowance(address(this), address(swapper))) {
                _tokenIn.safeApprove(address(swapper), 0);
                _tokenIn.safeApprove(address(swapper), MAX_UINT_VALUE);
            }
            _swapExactInput(address(_tokenIn), address(collateralToken), _amountIn);
        }
        _amountOut = collateralToken.balanceOf(address(this)) - _collateralBefore;
        require(_amountOut >= _minAmountOut, "not-enough-amountOut");
    }

    /**
     * @notice sweep given token to feeCollector of strategy
     * @param _fromToken token address to sweep
     */
    function sweep(address _fromToken) external override onlyKeeper {
        require(feeCollector != address(0), "fee-collector-not-set");
        require(_fromToken != address(collateralToken), "not-allowed-to-sweep-collateral");
        require(!isReservedToken(_fromToken), "not-allowed-to-sweep");
        if (_fromToken == ETH) {
            Address.sendValue(payable(feeCollector), address(this).balance);
        } else {
            uint256 _amount = IERC20(_fromToken).balanceOf(address(this));
            IERC20(_fromToken).safeTransfer(feeCollector, _amount);
        }
    }

    /// @notice Returns address of token correspond to receipt token
    function token() external view override returns (address) {
        return receiptToken;
    }

    /// @notice Returns address of token correspond to collateral token
    function collateral() external view override returns (address) {
        return address(collateralToken);
    }

    function governor() external view returns (address) {
        return IVesperPool(pool).governor();
    }

    /// @notice Returns total collateral locked in the strategy
    function tvl() external view virtual returns (uint256);

    /**
     * @notice Update fee collector
     * @param _feeCollector fee collector address
     */
    function updateFeeCollector(address _feeCollector) external onlyGovernor {
        require(_feeCollector != address(0), "fee-collector-address-is-zero");
        require(_feeCollector != feeCollector, "fee-collector-is-same");
        emit UpdatedFeeCollector(feeCollector, _feeCollector);
        feeCollector = _feeCollector;
    }

    /**
     * @notice Update swapper
     * @param _swapper swapper address
     */
    function updateSwapper(IRoutedSwapper _swapper) external onlyGovernor {
        require(address(_swapper) != address(0), "swapper-address-is-zero");
        require(_swapper != swapper, "swapper-is-same");
        emit UpdatedSwapper(swapper, _swapper);
        swapper = _swapper;
    }

    /**
     * @notice Withdraw collateral token from end protocol.
     * @param _amount Amount of collateral token
     */
    function withdraw(uint256 _amount) external override onlyPool {
        uint256 _collateralHere = collateralToken.balanceOf(address(this));
        if (_collateralHere >= _amount) {
            collateralToken.safeTransfer(pool, _amount);
        } else {
            _withdrawHere(_amount - _collateralHere);
            // Do not assume _withdrawHere() will withdraw exact amount. Check balance again and transfer to pool
            _collateralHere = collateralToken.balanceOf(address(this));
            collateralToken.safeTransfer(pool, Math.min(_amount, _collateralHere));
        }
    }

    function _approveToken(uint256 _amount) internal virtual {
        collateralToken.safeApprove(pool, _amount);
    }

    /**
     * @dev some strategy may want to prepare before doing migration.
     *  Example In Maker old strategy want to give vault ownership to new strategy
     * @param _newStrategy .
     */
    function _beforeMigration(address _newStrategy) internal virtual;

    function _claimAndSwapRewards() internal virtual {
        (address _rewardToken, uint256 _rewardsAmount) = _claimRewards();
        if (_rewardsAmount > 0) {
            _safeSwapExactInput(_rewardToken, address(collateralToken), _rewardsAmount);
        }
    }

    // solhint-disable-next-line no-empty-blocks
    function _claimRewards() internal virtual returns (address, uint256) {}

    function _rebalance() internal virtual returns (uint256 _profit, uint256 _loss, uint256 _payback);

    function _swapExactInput(
        address _tokenIn,
        address _tokenOut,
        uint256 _amountIn
    ) internal returns (uint256 _amountOut) {
        _amountOut = swapper.swapExactInput(_tokenIn, _tokenOut, _amountIn, 1, address(this));
    }

    function _safeSwapExactInput(address _tokenIn, address _tokenOut, uint256 _amountIn) internal {
        try swapper.swapExactInput(_tokenIn, _tokenOut, _amountIn, 1, address(this)) {} catch {} //solhint-disable no-empty-blocks
    }

    // These methods must be implemented by the inheriting strategy
    function _withdrawHere(uint256 _amount) internal virtual;
}

Read Contract

NAME 0xa3f4df7e → string
VERSION 0xffa1ad74 → string
aaveAddressProvider 0xcdaabe41 → address
borrowToken 0x456dc17a → address
cellar 0x201f35c6 → address
collateral 0xd8dfeb45 → address
collateralToken 0xb2016bd4 → address
feeCollector 0xc415b95c → address
governor 0x0c340a24 → address
isReservedToken 0x440d7248 → bool
keepers 0x951dc22c → address[]
maxBorrowLimit 0x0181686c → uint256
minBorrowLimit 0xe260d747 → uint256
pool 0x16f0115b → address
receiptToken 0xec78e832 → address
swapper 0x2b3297f9 → address
token 0xfc0c546a → address
tvl 0xe5328e06 → uint256
unlockTime 0x251c1aa3 → uint256
vdToken 0x90d67514 → address
wrappedCollateral 0x0ade00f2 → address

Write Contract 12 functions

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

addKeeper 0x4032b72b
address _keeperAddress
approveToken 0x3ac9fc11
uint256 _approvalAmount
claimAndSwapRewards 0x1026013a
uint256 _minAmountOut
returns: uint256
migrate 0xce5494bb
address _newStrategy
rebalance 0x7d7c2a1c
No parameters
returns: uint256, uint256, uint256
removeKeeper 0x14ae9f2e
address _keeperAddress
swapToCollateral 0xee330ee3
address _tokenIn
uint256 _minAmountOut
returns: uint256
sweep 0x01681a62
address _fromToken
updateBorrowLimit 0xfb7ee102
uint256 _minBorrowLimit
uint256 _maxBorrowLimit
updateFeeCollector 0xd2c35ce8
address _feeCollector
updateSwapper 0xd3033c39
address _swapper
withdraw 0x2e1a7d4d
uint256 _amount

Recent Transactions

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