Address Contract Partially Verified
Address
0xa980d4c0C2E48d305b582AA439a3575e3de06f0E
Balance
0 ETH
Nonce
1
Code Size
12303 bytes
Creator
0x0bb3a327...88c6 at tx 0xc9fbe657...8fc129
Indexed Transactions
0
Contract Bytecode
12303 bytes
0x60806040526004361061019c5760003560e01c806396171e59116100ec578063bf9934421161008a578063e0115d0d11610064578063e0115d0d146104bf578063e54f0880146104d5578063ea58c644146104ea578063f3fef3a31461051e57600080fd5b8063bf99344214610469578063c05ebc2c1461047f578063ca0b78561461049f57600080fd5b8063a21bab8e116100c6578063a21bab8e146103df578063aabaecd6146103ff578063abbc421714610433578063b0df27fd1461045357600080fd5b806396171e591461038a5780639754d1dc146103aa5780639dc29fac146103bf57600080fd5b80634a7f299e1161015957806369d83b3c1161013357806369d83b3c146103045780636bc05280146103315780636bef22ee1461034e57806375baf37f1461036e57600080fd5b80634a7f299e146102965780635c222bad146102b65780635df10472146102e957600080fd5b806305ad8308146101a157806317d145a2146101ea57806318991153146102005780632b507df8146102155780632f0bc9651461026157806340c10f1914610276575b600080fd5b3480156101ad57600080fd5b506101d76101bc366004612d50565b6001600160a01b031660009081526004602052604090205490565b6040519081526020015b60405180910390f35b3480156101f657600080fd5b506101d760005481565b34801561020c57600080fd5b506101d761053e565b34801561022157600080fd5b506102497f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff81565b6040516001600160a01b0390911681526020016101e1565b61027461026f366004612d6b565b6105a7565b005b34801561028257600080fd5b50610274610291366004612d84565b6107bc565b3480156102a257600080fd5b506102746102b1366004612d6b565b610860565b3480156102c257600080fd5b507f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe84610249565b3480156102f557600080fd5b50670de0b6b3a76400006101d7565b34801561031057600080fd5b506101d761031f366004612d50565b60036020526000908152604090205481565b34801561033d57600080fd5b506101d7680821ab0d441498000081565b34801561035a57600080fd5b50610274610369366004612d6b565b610944565b34801561037a57600080fd5b50604051600081526020016101e1565b34801561039657600080fd5b506102746103a5366004612dae565b61108e565b3480156103b657600080fd5b506002546101d7565b3480156103cb57600080fd5b506102746103da366004612d84565b61154c565b3480156103eb57600080fd5b506101d76103fa366004612d84565b6115ad565b34801561040b57600080fd5b506102497f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8481565b34801561043f57600080fd5b5061027461044e366004612dea565b611600565b34801561045f57600080fd5b506101d760055481565b34801561047557600080fd5b506101d760075481565b34801561048b57600080fd5b5061027461049a366004612dae565b611769565b3480156104ab57600080fd5b506102746104ba366004612e0c565b611cbd565b3480156104cb57600080fd5b506101d760015481565b3480156104e157600080fd5b506101d761210d565b3480156104f657600080fd5b506102497f000000000000000000000000df3ac4f479375802a821f7b7b46cd7eb5e4262cc81565b34801561052a57600080fd5b50610274610539366004612d84565b61211c565b60008062015180600754426105539190612e55565b61055d9190612e84565b90506107088110156105725761271091505090565b600161058061070883612e98565b61058a9190612e55565b610595906064612eac565b6105a190612710612e55565b91505090565b670de0b6b3a76400003410156105ea5760405162461bcd60e51b815260206004820152600360248201526211139360ea1b60448201526064015b60405180910390fd5b60405163a1903eab60e01b81526001600160a01b037f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff811660048301526000917f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe849091169063a1903eab90349060240160206040518083038185885af1158015610678573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061069d9190612ec3565b9050806000036106de5760405162461bcd60e51b815260206004820152600c60248201526b16915493d7d1115413d4d25560a21b60448201526064016105e1565b346000808282546106ef9190612edc565b90915550503360009081526003602052604081208054349290610713908490612edc565b909155505033600090815260066020526040902042905581156107435761074333338461073e61210d565b612322565b604080517f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316815234602082018190529181019190915242606082015233907f6a7b44958c301c33959b506daa1c81df7d298aa58fd6c510f4fd967f0eb87ce8906080015b60405180910390a25050565b6001600160a01b0382166108125760405162461bcd60e51b815260206004820152601860248201527f4d494e545f544f5f5448455f5a45524f5f41444452455353000000000000000060448201526064016105e1565b8060000361084e5760405162461bcd60e51b815260206004820152600960248201526816915493d7d352539560ba1b60448201526064016105e1565b61085c33838361073e61210d565b5050565b604051632474521560e21b81527fdf8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec4260048201523360248201527f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b0316906391d1485490604401602060405180830381865afa1580156108ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061090e9190612eef565b61093f5760405162461bcd60e51b81526020600482015260026024820152614e4160f01b60448201526064016105e1565b600755565b600080546040516370a0823160e01b81523060048201527f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316906370a0823190602401602060405180830381865afa1580156109ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109d09190612ec3565b6109da9190612e55565b905080158015906109ea57508115155b610a465760405162461bcd60e51b815260206004820152602760248201527f4f6e6c79204c53442065786365737320696e636f6d652063616e20626520657860448201526618da185b99d95960ca1b60648201526084016105e1565b6000818311610a555782610a57565b815b90506000610a6361053e565b90506000670de0b6b3a764000061271083610a7c61210d565b610a869087612eac565b610a909190612eac565b610a9a9190612e98565b610aa49190612e98565b90506000610ab061259e565b600554610abd9190612edc565b905080821115610dd8576040516323b872dd60e01b81523360048201526001600160a01b037f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff81166024830152604482018390526000917f000000000000000000000000df3ac4f479375802a821f7b7b46cd7eb5e4262cc909116906323b872dd906064016020604051808303816000875af1158015610b61573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b859190612eef565b905080610bb95760405162461bcd60e51b81526020600482015260026024820152612a2360f11b60448201526064016105e1565b7f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b0316636f4a2cd06040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610c1457600080fd5b505af1925050508015610c25575060015b5060006001600160a01b037f000000000000000000000000df3ac4f479375802a821f7b7b46cd7eb5e4262cc1663b85364e5610c618587612e55565b6040518263ffffffff1660e01b8152600401610c7f91815260200190565b602060405180830381865afa158015610c9c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cc09190612ec3565b905080600003610cd757610cd48385612e55565b90505b604051633b9e9f0160e21b8152336004820152602481018290527f000000000000000000000000df3ac4f479375802a821f7b7b46cd7eb5e4262cc6001600160a01b03169063ee7a7c04906044016020604051808303816000875af1158015610d44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d689190612ec3565b506000600555604080518481524260208201527f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b0316917fec0804e8e1decb589af9c4ba8ebfbacd3be98929d4d53457dfd186061f489f04910160405180910390a25050610fa9565b6040516323b872dd60e01b81523360048201526001600160a01b037f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff81166024830152604482018490526000917f000000000000000000000000df3ac4f479375802a821f7b7b46cd7eb5e4262cc909116906323b872dd906064016020604051808303816000875af1158015610e72573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e969190612eef565b905080610eca5760405162461bcd60e51b81526020600482015260026024820152612a2360f11b60448201526064016105e1565b7f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b0316636f4a2cd06040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610f2557600080fd5b505af1925050508015610f36575060015b50610f418383612e55565b600555604080518481524260208201527f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b0316917fec0804e8e1decb589af9c4ba8ebfbacd3be98929d4d53457dfd186061f489f04910160405180910390a2505b4260015560405163a9059cbb60e01b8152336004820152602481018590527f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b03169063a9059cbb906044016020604051808303816000875af115801561101a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061103e9190612eef565b5060408051858152602081018490529081018490524260608201527fe64f87293a785dc4cbf1b9b65f3cfd04beb2bac2c656aec8f79b2e70be1f88739060800160405180910390a1505050505050565b600061109861210d565b6001600160a01b038416600090815260046020908152604080832054600390925282205492935090916110cc908490612eac565b6110d7906064612eac565b6110e19190612e98565b9050680821ab0d441498000081106111615760405162461bcd60e51b815260206004820152603a60248201527f426f72726f7765727320636f6c6c61746572616c20726174696f2073686f756c60448201527f642062656c6f7720626164436f6c6c61746572616c526174696f00000000000060648201526084016105e1565b6001600160a01b038416600090815260036020526040902054611185846002612eac565b11156111e55760405162461bcd60e51b815260206004820152602960248201527f61206d6178206f662035302520636f6c6c61746572616c2063616e206265206c6044820152681a5c5d5a59185d195960ba1b60648201526084016105e1565b604051636eb1769f60e11b81526001600160a01b0386811660048301523060248301527f000000000000000000000000df3ac4f479375802a821f7b7b46cd7eb5e4262cc169063dd62ed3e90604401602060405180830381865afa158015611251573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112759190612ec3565b15158061128a5750336001600160a01b038616145b6112a65760405162461bcd60e51b81526004016105e190612f11565b6000670de0b6b3a76400006112bb8486612eac565b6112c59190612e98565b90506112d2868683612669565b8368056bc75e2d63100000831180156112f357506805f68e8131ecf8000083105b156113195768056bc75e2d6310000061130c8487612eac565b6113169190612e98565b90505b6805f68e8131ecf80000831061134357600a61133686600b612eac565b6113409190612e98565b90505b806000808282546113549190612e55565b90915550506001600160a01b03861660009081526003602052604081208054839290611381908490612e55565b909155505060405163b300a55960e01b815230600482015260009081907f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b03169063b300a55990602401602060405180830381865afa1580156113ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114139190612ec3565b9050336001600160a01b038a1614801590611452575061143b81670de0b6b3a7640000612eac565b61144e9068056bc75e2d63100000612edc565b8510155b156114a35760646114638289612eac565b61146d9190612e98565b91506114a36001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8416338461284f565b6114e2896114b18486612e55565b6001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8416919061284f565b6040805185815260208101859052908101839052600060608201524260808201526001600160a01b03808a169133918c16907fb59dc9737d55b75fc6ca7522e82d6161da5d7c8337b9ab990a5846f95b5ccdad9060a00160405180910390a4505050505050505050565b6001600160a01b0382166115a25760405162461bcd60e51b815260206004820152601860248201527f4255524e5f544f5f5448455f5a45524f5f41444452455353000000000000000060448201526064016105e1565b61085c338383612669565b6001600160a01b0382166000908152600660205260408120546115d36203f48042612e55565b10156115f7576103e86115e8836103e7612eac565b6115f29190612e98565b6115f9565b815b9392505050565b670de0b6b3a76400008210156116695760405162461bcd60e51b815260206004820152602860248201527f4465706f7369742073686f756c64206e6f74206265206c657373207468616e20604482015267189039ba22aa241760c11b60648201526084016105e1565b61169e6001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe84163330856128b7565b816000808282546116af9190612edc565b909155505033600090815260036020526040812080548492906116d3908490612edc565b909155505033600090815260066020526040902042905580156116fe576116fe33338361073e61210d565b604080517f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b0316815260208101849052429181019190915233907ff80e165f76857acc123ffe20b1116e9ec31ad7f2c4ecd6f379a9cc9151b50371906060016107b0565b600061177361210d565b9050680821ab0d4414980000600254826000546117909190612eac565b61179b906064612eac565b6117a59190612e98565b106118035760405162461bcd60e51b815260206004820152602860248201527f6f766572616c6c436f6c6c61746572616c526174696f2073686f756c642062656044820152676c6f77203135302560c01b60648201526084016105e1565b6001600160a01b0383166000908152600460209081526040808320546003909252822054611832908490612eac565b61183d906064612eac565b6118479190612e98565b90506806c6b935b8bbd4000081106118b55760405162461bcd60e51b815260206004820152602b60248201527f626f72726f7765727320636f6c6c61746572616c526174696f2073686f756c6460448201526a2062656c6f77203132352560a81b60648201526084016105e1565b6001600160a01b0384166000908152600360205260409020548311156119335760405162461bcd60e51b815260206004820152602d60248201527f746f74616c206f6620636f6c6c61746572616c2063616e206265206c6971756960448201526c19185d195908185d081b5bdcdd609a1b60648201526084016105e1565b6000670de0b6b3a76400006119488486612eac565b6119529190612e98565b905068056bc75e2d63100000821061198557816119788268056bc75e2d63100000612eac565b6119829190612e98565b90505b604051636eb1769f60e11b81526001600160a01b0387811660048301523060248301527f000000000000000000000000df3ac4f479375802a821f7b7b46cd7eb5e4262cc169063dd62ed3e90604401602060405180830381865afa1580156119f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a159190612ec3565b151580611a2a5750336001600160a01b038716145b611a465760405162461bcd60e51b81526004016105e190612f11565b611a51868683612669565b83600080828254611a629190612e55565b90915550506001600160a01b03851660009081526003602052604081208054869290611a8f908490612e55565b9091555060009050336001600160a01b03881614801590611b5c575060405163b300a55960e01b81523060048201527f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b03169063b300a55990602401602060405180830381865afa158015611b0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b339190612ec3565b611b4590670de0b6b3a7640000612eac565b611b589068056bc75e2d63100000612edc565b8310155b15611c475760405163b300a55960e01b815230600482015283907f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b03169063b300a55990602401602060405180830381865afa158015611bc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611beb9190612ec3565b611bf59087612eac565b611c0790670de0b6b3a7640000612eac565b611c119190612e98565b9050611c476001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8416338361284f565b611c55876114b18388612e55565b6040805183815260208101879052908101829052600160608201524260808201526001600160a01b038088169133918a16907fb59dc9737d55b75fc6ca7522e82d6161da5d7c8337b9ab990a5846f95b5ccdad9060a00160405180910390a450505050505050565b336001600160a01b03841603611cfb5760405162461bcd60e51b815260206004820152600360248201526243425360e81b60448201526064016105e1565b604051631e24111360e21b81526001600160a01b0384811660048301527f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff1690637890444c90602401602060405180830381865afa158015611d61573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d859190612eef565b611ddd5760405162461bcd60e51b8152602060048201526024808201527f70726f7669646572206973206e6f74206120526564656d7074696f6e50726f7660448201526334b232b960e11b60648201526084016105e1565b6001600160a01b038316600090815260046020526040902054821115611e565760405162461bcd60e51b815260206004820152602860248201527f65757364416d6f756e742063616e6e6f7420737572706173732070726f766964604482015267195c9cc81919589d60c21b60648201526084016105e1565b6000611e6061210d565b6001600160a01b03851660009081526004602090815260408083205460039092528220549293509091611e94908490612eac565b611e9f906064612eac565b611ea99190612e98565b905068056bc75e2d63100000811015611f2a5760405162461bcd60e51b815260206004820152603d60248201527f5468652070726f7669646572277320636f6c6c61746572616c20726174696f2060448201527f73686f756c64206265206e6f74206c657373207468616e20313030252e00000060648201526084016105e1565b611f35338686612669565b6000612710837f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b031663458f58156040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f99573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fbd9190612ec3565b611fc990612710612e55565b611fdb88670de0b6b3a7640000612eac565b611fe59190612eac565b611fef9190612e98565b611ff99190612e98565b9050600061200787836115ad565b90508481101561203e5760405162461bcd60e51b8152602060048201526002602482015261115360f21b60448201526064016105e1565b6001600160a01b03871660009081526003602052604081208054849290612066908490612e55565b925050819055508160008082825461207e9190612e55565b909155506120b890506001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8416338361284f565b6040805187815260208101839052428183015290516001600160a01b0389169133917f1a7ab636ab77b4d93c0afba804a009a127e77def45e623e572144ca8f8a03ac59181900360600190a350505050505050565b60006121176128f5565b905090565b6001600160a01b0382166121585760405162461bcd60e51b8152602060048201526003602482015262545a4160e81b60448201526064016105e1565b806000036121985760405162461bcd60e51b815260206004820152600d60248201526c5a45524f5f574954484452415760981b60448201526064016105e1565b336000908152600360205260409020548111156122095760405162461bcd60e51b815260206004820152602960248201527f576974686472617720616d6f756e742065786365656473206465706f73697465604482015268321030b6b7bab73a1760b91b60648201526084016105e1565b8060008082825461221a9190612e55565b9091555050336000908152600360205260408120805483929061223e908490612e55565b909155506000905061225033836115ad565b90506122866001600160a01b037f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe8416848361284f565b33600090815260046020526040902054156122ac576122ac336122a761210d565b61297b565b604080517f000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe846001600160a01b03908116825260208201849052428284015291519185169133917f31c6c2b083b6c6fb9c8345de5c29efda3ef312a42d1bc0d4a3029465080809c1919081900360600190a3505050565b6040516333050e8160e21b81523060048201527f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b03169063cc143a0490602401602060405180830381865afa158015612386573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123aa9190612ec3565b826002546123b89190612edc565b11156123ec5760405162461bcd60e51b81526020600482015260036024820152621154d360ea1b60448201526064016105e1565b604051636f086f1360e11b81526001600160a01b0385811660048301527f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff169063de10de2690602401600060405180830381600087803b15801561244f57600080fd5b505af1158015612463573d6000803e3d6000fd5b505050506001600160a01b0384166000908152600460205260408120805484929061248f908490612edc565b90915550506040516340c10f1960e01b81526001600160a01b038481166004830152602482018490527f000000000000000000000000df3ac4f479375802a821f7b7b46cd7eb5e4262cc16906340c10f19906044016020604051808303816000875af1158015612503573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125279190612ec3565b50612530612aab565b81600260008282546125429190612edc565b909155506125529050848261297b565b604080518381524260208201526001600160a01b0385169133917f2f00e3cdd69a77be7ed215ec7b2a36784dd158f921fca79ac29deffa353fe6ee91015b60405180910390a350505050565b60006127106301e13380600154426125b69190612e55565b604051630440bd9560e21b81523060048201527f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b031690631102f65490602401602060405180830381865afa15801561261a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061263e9190612ec3565b60025461264b9190612eac565b6126559190612eac565b61265f9190612e98565b6121179190612e98565b6001600160a01b0382166000908152600460205260408120548211156126a7576001600160a01b0383166000908152600460205260409020546126a9565b815b604051632770a7eb60e21b81526001600160a01b038681166004830152602482018390529192507f000000000000000000000000df3ac4f479375802a821f7b7b46cd7eb5e4262cc90911690639dc29fac906044016020604051808303816000875af115801561271d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127419190612ec3565b50604051636f086f1360e11b81526001600160a01b0384811660048301527f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff169063de10de2690602401600060405180830381600087803b1580156127a557600080fd5b505af11580156127b9573d6000803e3d6000fd5b505050506001600160a01b038316600090815260046020526040812080548392906127e5908490612e55565b909155506127f39050612aab565b80600260008282546128059190612e55565b9091555050604080518281524260208201526001600160a01b0380861692908716917f5d624aa9c148153ab3446c1b154f660ee7701e549fe9b62dab7171b1c80e6fa29101612590565b6040516001600160a01b0383166024820152604481018290526128b290849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612acf565b505050565b6040516001600160a01b03808516602483015283166044820152606481018290526128ef9085906323b872dd60e01b9060840161287b565b50505050565b60007f0000000000000000000000004c517d4e2c851ca76d7ec94b805269df0f2201de6001600160a01b0316630fdb11cf6040518163ffffffff1660e01b81526004016020604051808303816000875af1158015612957573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121179190612ec3565b60405163ae91874960e01b81523060048201527f000000000000000000000000c8353594eeedc5ce5a4544d3d9907b694c4690ff6001600160a01b03169063ae91874990602401602060405180830381865afa1580156129df573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a039190612ec3565b6001600160a01b038316600090815260046020908152604080832054600390925290912054612a33908490612eac565b612a3e906064612eac565b612a489190612e98565b101561085c5760405162461bcd60e51b815260206004820152602c60248201527f636f6c6c61746572616c526174696f2069732042656c6f772073616665436f6c60448201526b6c61746572616c526174696f60a01b60648201526084016105e1565b612ab361259e565b60056000828254612ac49190612edc565b909155505042600155565b6000612b24826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612ba49092919063ffffffff16565b9050805160001480612b45575080806020019051810190612b459190612eef565b6128b25760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016105e1565b6060612bb38484600085612bbb565b949350505050565b606082471015612c1c5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016105e1565b600080866001600160a01b03168587604051612c389190612f8a565b60006040518083038185875af1925050503d8060008114612c75576040519150601f19603f3d011682016040523d82523d6000602084013e612c7a565b606091505b5091509150612c8b87838387612c96565b979650505050505050565b60608315612d05578251600003612cfe576001600160a01b0385163b612cfe5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016105e1565b5081612bb3565b612bb38383815115612d1a5781518083602001fd5b8060405162461bcd60e51b81526004016105e19190612fa6565b80356001600160a01b0381168114612d4b57600080fd5b919050565b600060208284031215612d6257600080fd5b6115f982612d34565b600060208284031215612d7d57600080fd5b5035919050565b60008060408385031215612d9757600080fd5b612da083612d34565b946020939093013593505050565b600080600060608486031215612dc357600080fd5b612dcc84612d34565b9250612dda60208501612d34565b9150604084013590509250925092565b60008060408385031215612dfd57600080fd5b50508035926020909101359150565b600080600060608486031215612e2157600080fd5b612e2a84612d34565b95602085013595506040909401359392505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115612e6857612e68612e3f565b92915050565b634e487b7160e01b600052601260045260246000fd5b600082612e9357612e93612e6e565b500690565b600082612ea757612ea7612e6e565b500490565b8082028115828204841417612e6857612e68612e3f565b600060208284031215612ed557600080fd5b5051919050565b80820180821115612e6857612e68612e3f565b600060208284031215612f0157600080fd5b815180151581146115f957600080fd5b60208082526035908201527f70726f76696465722073686f756c6420617574686f72697a6520746f2070726f6040820152741d9a5919481b1a5c5d5a59185d1a5bdb88195554d1605a1b606082015260800190565b60005b83811015612f81578181015183820152602001612f69565b50506000910152565b60008251612f9c818460208701612f66565b9190910192915050565b6020815260008251806020840152612fc5816040850160208701612f66565b601f01601f1916919091016040019291505056fea264697066735822122093d80d552f79f392383acac5e441b0fececc06555b52caf7c74679d2b722a32164736f6c63430008110033
Verified Source Code Partial Match
Compiler: v0.8.17+commit.8df45f5f
EVM: london
Optimization: Yes (200 runs)
IEUSD.sol 55 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.17;
interface IEUSD {
function totalSupply() external view returns (uint256);
function getTotalShares() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function sharesOf(address _account) external view returns (uint256);
function allowance(
address owner,
address spender
) external view returns (uint256);
function approve(address _spender, uint256 _amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
function transferShares(
address _recipient,
uint256 _sharesAmount
) external returns (uint256);
function getSharesByMintedEUSD(
uint256 _EUSDAmount
) external view returns (uint256);
function getMintedEUSDByShares(
uint256 _sharesAmount
) external view returns (uint256);
function mint(
address _recipient,
uint256 _mintAmount
) external returns (uint256 newTotalShares);
function burnShares(
address _account,
uint256 burnAmount
) external returns (uint256 newTotalShares);
function burn(
address _account,
uint256 burnAmount
) external returns (uint256 newTotalShares);
function transfer(address to, uint256 amount) external returns (bool);
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
LybraStETHVault.sol 114 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.17;
import "../interfaces/IEUSD.sol";
import "./base/LybraEUSDVaultBase.sol";
interface Ilido {
function submit(address _referral) external payable returns (uint256 StETH);
}
contract LybraStETHVault is LybraEUSDVaultBase {
// Currently, the official rebase time for Lido is between 12PM to 13PM UTC.
uint256 public lidoRebaseTime = 12 hours;
// stETH = 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84
// oracle = 0x4c517D4e2C851CA76d7eC94B805269Df0f2201De
constructor(address _stETH, address _oracle, address _config) LybraEUSDVaultBase(_stETH, _oracle, _config) {
}
/**
* @notice Sets the rebase time for Lido based on the actual situation.
* This function can only be called by an address with the ADMIN role.
*/
function setLidoRebaseTime(uint256 _time) external {
require(configurator.hasRole(keccak256("ADMIN"), msg.sender), "NA");
lidoRebaseTime = _time;
}
/**
* @notice Allows users to deposit ETH to mint eUSD.
* ETH is directly deposited into Lido and converted to stETH.
* @param mintAmount The amount of eUSD to mint.
* Requirements:
* The deposited amount of ETH must be greater than or equal to 1 ETH.
*/
function depositEtherToMint(uint256 mintAmount) external payable override {
require(msg.value >= 1 ether, "DNL");
//convert to steth
uint256 sharesAmount = Ilido(address(collateralAsset)).submit{value: msg.value}(address(configurator));
require(sharesAmount != 0, "ZERO_DEPOSIT");
totalDepositedAsset += msg.value;
depositedAsset[msg.sender] += msg.value;
depositedTime[msg.sender] = block.timestamp;
if (mintAmount > 0) {
_mintEUSD(msg.sender, msg.sender, mintAmount, getAssetPrice());
}
emit DepositEther(msg.sender, address(collateralAsset), msg.value, msg.value, block.timestamp);
}
/**
* @notice When stETH balance increases through LSD or other reasons, the excess income is sold for eUSD, allocated to eUSD holders through rebase mechanism.
* Emits a `LSDValueCaptured` event.
*
* *Requirements:
* - stETH balance in the contract cannot be less than totalDepositedAsset after exchange.
* @dev Income is used to cover accumulated Service Fee first.
*/
function excessIncomeDistribution(uint256 stETHAmount) external override {
uint256 excessAmount = collateralAsset.balanceOf(address(this)) - totalDepositedAsset;
require(excessAmount != 0 && stETHAmount != 0, "Only LSD excess income can be exchanged");
uint256 realAmount = stETHAmount > excessAmount ? excessAmount : stETHAmount;
uint256 dutchAuctionDiscountPrice = getDutchAuctionDiscountPrice();
uint256 payAmount = realAmount * getAssetPrice() * dutchAuctionDiscountPrice / 10_000 / 1e18;
uint256 income = feeStored + _newFee();
if (payAmount > income) {
bool success = EUSD.transferFrom(msg.sender, address(configurator), income);
require(success, "TF");
try configurator.distributeRewards() {} catch {}
uint256 sharesAmount = EUSD.getSharesByMintedEUSD(payAmount - income);
if (sharesAmount == 0) {
//eUSD totalSupply is 0: assume that shares correspond to eUSD 1-to-1
sharesAmount = (payAmount - income);
}
//Income is distributed to LBR staker.
EUSD.burnShares(msg.sender, sharesAmount);
feeStored = 0;
emit FeeDistribution(address(configurator), income, block.timestamp);
} else {
bool success = EUSD.transferFrom(msg.sender, address(configurator), payAmount);
require(success, "TF");
try configurator.distributeRewards() {} catch {}
feeStored = income - payAmount;
emit FeeDistribution(address(configurator), payAmount, block.timestamp);
}
lastReportTime = block.timestamp;
collateralAsset.transfer(msg.sender, realAmount);
emit LSDValueCaptured(realAmount, payAmount, dutchAuctionDiscountPrice, block.timestamp);
}
/**
* @notice Reduces the discount for the issuance of additional tokens based on the rebase time using the Dutch auction method.
* The specific rule is that the discount rate increases by 1% every 30 minutes after the rebase occurs.
*/
function getDutchAuctionDiscountPrice() public view returns (uint256) {
uint256 time = (block.timestamp - lidoRebaseTime) % 1 days;
if (time < 30 minutes) return 10_000;
return 10_000 - (time / 30 minutes - 1) * 100;
}
function getAssetPrice() public override returns (uint256) {
return _etherPrice();
}
function getAsset2EtherExchangeRate() external view override returns (uint256) {
return 1e18;
}
}
Iconfigurator.sol 29 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.17;
interface Iconfigurator {
function mintVault(address pool) external view returns(bool);
function mintVaultMaxSupply(address pool) external view returns(uint256);
function vaultMintPaused(address pool) external view returns(bool);
function vaultBurnPaused(address pool) external view returns(bool);
function tokenMiner(address pool) external view returns(bool);
function getSafeCollateralRatio(address pool) external view returns(uint256);
function getBadCollateralRatio(address pool) external view returns(uint256);
function getVaultWeight(address pool) external view returns (uint256);
function vaultMintFeeApy(address pool) external view returns(uint256);
function vaultKeeperRatio(address pool) external view returns(uint256);
function redemptionFee() external view returns(uint256);
function getEUSDAddress() external view returns(address);
function peUSD() external view returns(address);
function eUSDMiningIncentives() external view returns(address);
function getProtocolRewardsPool() external view returns(address);
function flashloanFee() external view returns(uint256);
function getEUSDMaxLocked() external view returns (uint256);
function stableToken() external view returns (address);
function isRedemptionProvider(address user) external view returns (bool);
function becomeRedemptionProvider(bool _bool) external;
function refreshMintReward(address user) external;
function distributeRewards() external;
function hasRole(bytes32 role, address account) external view returns (bool);
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
LybraEUSDVaultBase.sol 334 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.17;
import "../../interfaces/IEUSD.sol";
import "../../interfaces/Iconfigurator.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
interface IPriceFeed {
function fetchPrice() external returns (uint256);
}
abstract contract LybraEUSDVaultBase {
using SafeERC20 for IERC20;
IEUSD public immutable EUSD;
IERC20 public immutable collateralAsset;
Iconfigurator public immutable configurator;
uint256 public constant badCollateralRatio = 150 * 1e18;
IPriceFeed immutable etherOracle;
uint256 public totalDepositedAsset;
uint256 public lastReportTime;
uint256 poolTotalCirculation;
mapping(address => uint256) public depositedAsset;
mapping(address => uint256) borrowed;
uint256 public feeStored;
mapping(address => uint256) depositedTime;
event DepositEther(address indexed onBehalfOf, address asset, uint256 etherAmount, uint256 assetAmount, uint256 timestamp);
event DepositAsset(address indexed onBehalfOf, address asset, uint256 amount, uint256 timestamp);
event WithdrawAsset(address indexed sponsor, address asset, address indexed onBehalfOf, uint256 amount, uint256 timestamp);
event Mint(address indexed sponsor, address indexed onBehalfOf, uint256 amount, uint256 timestamp);
event Burn(address indexed sponsor, address indexed onBehalfOf, uint256 amount, uint256 timestamp);
event LiquidationRecord(address indexed provider, address indexed keeper, address indexed onBehalfOf, uint256 eusdamount, uint256 liquidateEtherAmount, uint256 keeperReward, bool superLiquidation, uint256 timestamp);
event LSDValueCaptured(uint256 stETHAdded, uint256 payoutEUSD, uint256 discountRate, uint256 timestamp);
event RigidRedemption(address indexed caller, address indexed provider, uint256 eusdAmount, uint256 collateralAmount, uint256 timestamp);
event FeeDistribution(address indexed feeAddress, uint256 feeAmount, uint256 timestamp);
//etherOracle = 0x4c517D4e2C851CA76d7eC94B805269Df0f2201De
constructor(address _collateralAsset, address _etherOracle, address _configurator) {
collateralAsset = IERC20(_collateralAsset);
configurator = Iconfigurator(_configurator);
EUSD = IEUSD(configurator.getEUSDAddress());
etherOracle = IPriceFeed(_etherOracle);
}
/**
* @notice Allowing direct deposits of ETH, the pool may convert it into the corresponding collateral during the implementation.
* While depositing, it is possible to simultaneously mint eUSD for oneself.
* Emits a `DepositEther` event.
*
* Requirements:
* - `mintAmount` Send 0 if doesn't mint eUSD
* - msg.value Must be higher than 0.
*/
function depositEtherToMint(uint256 mintAmount) external payable virtual;
/**
* @notice Deposit collateral and allow minting eUSD for oneself.
* Emits a `DepositAsset` event.
*
* Requirements:
* - `assetAmount` Must be higher than 1e18.
* - `mintAmount` Send 0 if doesn't mint eUSD
*/
function depositAssetToMint(uint256 assetAmount, uint256 mintAmount) external virtual {
require(assetAmount >= 1 ether, "Deposit should not be less than 1 stETH.");
collateralAsset.safeTransferFrom(msg.sender, address(this), assetAmount);
totalDepositedAsset += assetAmount;
depositedAsset[msg.sender] += assetAmount;
depositedTime[msg.sender] = block.timestamp;
if (mintAmount > 0) {
_mintEUSD(msg.sender, msg.sender, mintAmount, getAssetPrice());
}
emit DepositAsset(msg.sender, address(collateralAsset), assetAmount, block.timestamp);
}
/**
* @notice Withdraw collateral assets to an address
* Emits a `WithdrawEther` event.
*
* Requirements:
* - `onBehalfOf` cannot be the zero address.
* - `amount` Must be higher than 0.
*
* @dev Withdraw stETH. Check user’s collateral ratio after withdrawal, should be higher than `safeCollateralRatio`
*/
function withdraw(address onBehalfOf, uint256 amount) external virtual {
require(onBehalfOf != address(0), "TZA");
require(amount != 0, "ZERO_WITHDRAW");
require(depositedAsset[msg.sender] >= amount, "Withdraw amount exceeds deposited amount.");
totalDepositedAsset -= amount;
depositedAsset[msg.sender] -= amount;
uint256 withdrawal = checkWithdrawal(msg.sender, amount);
collateralAsset.safeTransfer(onBehalfOf, withdrawal);
if (borrowed[msg.sender] > 0) {
_checkHealth(msg.sender, getAssetPrice());
}
emit WithdrawAsset(msg.sender, address(collateralAsset), onBehalfOf, withdrawal, block.timestamp);
}
function checkWithdrawal(address user, uint256 amount) public view returns (uint256 withdrawal) {
withdrawal = block.timestamp - 3 days >= depositedTime[user] ? amount : (amount * 999) / 1000;
}
/**
* @notice The mint amount number of eUSD is minted to the address
* Emits a `Mint` event.
*
* Requirements:
* - `onBehalfOf` cannot be the zero address.
*/
function mint(address onBehalfOf, uint256 amount) external {
require(onBehalfOf != address(0), "MINT_TO_THE_ZERO_ADDRESS");
require(amount != 0, "ZERO_MINT");
_mintEUSD(msg.sender, onBehalfOf, amount, getAssetPrice());
}
/**
* @notice Burn the amount of eUSD and payback the amount of minted eUSD
* Emits a `Burn` event.
* Requirements:
* - `onBehalfOf` cannot be the zero address.
* - `amount` Must be higher than 0.
* @dev Calling the internal`_repay`function.
*/
function burn(address onBehalfOf, uint256 amount) external {
require(onBehalfOf != address(0), "BURN_TO_THE_ZERO_ADDRESS");
_repay(msg.sender, onBehalfOf, amount);
}
/**
* @notice Keeper liquidates borrowers whose collateral ratio is below badCollateralRatio, using eUSD provided by Liquidation Provider.
*
* Requirements:
* - onBehalfOf Collateral Ratio should be below badCollateralRatio
* - collateralAmount should be less than 50% of collateral
* - provider should authorize Lybra to utilize eUSD
* @dev After liquidation, borrower's debt is reduced by collateralAmount * etherPrice, providers and keepers can receive up to an additional 10% liquidation reward.
*/
function liquidation(address provider, address onBehalfOf, uint256 assetAmount) external virtual {
uint256 assetPrice = getAssetPrice();
uint256 onBehalfOfCollateralRatio = (depositedAsset[onBehalfOf] * assetPrice * 100) / borrowed[onBehalfOf];
require(onBehalfOfCollateralRatio < badCollateralRatio, "Borrowers collateral ratio should below badCollateralRatio");
require(assetAmount * 2 <= depositedAsset[onBehalfOf], "a max of 50% collateral can be liquidated");
require(EUSD.allowance(provider, address(this)) != 0 || msg.sender == provider, "provider should authorize to provide liquidation eUSD");
uint256 eusdAmount = (assetAmount * assetPrice) / 1e18;
_repay(provider, onBehalfOf, eusdAmount);
uint256 reducedAsset = assetAmount;
if(onBehalfOfCollateralRatio > 1e20 && onBehalfOfCollateralRatio < 11e19) {
reducedAsset = assetAmount * onBehalfOfCollateralRatio / 1e20;
}
if(onBehalfOfCollateralRatio >= 11e19) {
reducedAsset = assetAmount * 11 / 10;
}
totalDepositedAsset -= reducedAsset;
depositedAsset[onBehalfOf] -= reducedAsset;
uint256 reward2keeper;
uint256 keeperRatio = configurator.vaultKeeperRatio(address(this));
if (msg.sender != provider && onBehalfOfCollateralRatio >= 1e20 + keeperRatio * 1e18) {
reward2keeper = assetAmount * keeperRatio / 100;
collateralAsset.safeTransfer(msg.sender, reward2keeper);
}
collateralAsset.safeTransfer(provider, reducedAsset - reward2keeper);
emit LiquidationRecord(provider, msg.sender, onBehalfOf, eusdAmount, reducedAsset, reward2keeper, false, block.timestamp);
}
/**
* @notice When overallCollateralRatio is below badCollateralRatio, borrowers with collateralRatio below 125% could be fully liquidated.
* Emits a `LiquidationRecord` event.
*
* Requirements:
* - Current overallCollateralRatio should be below badCollateralRatio
* - `onBehalfOf`collateralRatio should be below 125%
* @dev After Liquidation, borrower's debt is reduced by collateralAmount * etherPrice, deposit is reduced by collateralAmount * borrower's collateralRatio. Keeper gets a liquidation reward of `keeperRatio / borrower's collateralRatio
*/
function superLiquidation(address provider, address onBehalfOf, uint256 assetAmount) external virtual {
uint256 assetPrice = getAssetPrice();
require((totalDepositedAsset * assetPrice * 100) / poolTotalCirculation < badCollateralRatio, "overallCollateralRatio should below 150%");
uint256 onBehalfOfCollateralRatio = (depositedAsset[onBehalfOf] * assetPrice * 100) / borrowed[onBehalfOf];
require(onBehalfOfCollateralRatio < 125 * 1e18, "borrowers collateralRatio should below 125%");
require(assetAmount <= depositedAsset[onBehalfOf], "total of collateral can be liquidated at most");
uint256 eusdAmount = (assetAmount * assetPrice) / 1e18;
if (onBehalfOfCollateralRatio >= 1e20) {
eusdAmount = (eusdAmount * 1e20) / onBehalfOfCollateralRatio;
}
require(EUSD.allowance(provider, address(this)) != 0 || msg.sender == provider, "provider should authorize to provide liquidation eUSD");
_repay(provider, onBehalfOf, eusdAmount);
totalDepositedAsset -= assetAmount;
depositedAsset[onBehalfOf] -= assetAmount;
uint256 reward2keeper;
if (msg.sender != provider && onBehalfOfCollateralRatio >= 1e20 + configurator.vaultKeeperRatio(address(this)) * 1e18) {
reward2keeper = ((assetAmount * configurator.vaultKeeperRatio(address(this))) * 1e18) / onBehalfOfCollateralRatio;
collateralAsset.safeTransfer(msg.sender, reward2keeper);
}
collateralAsset.safeTransfer(provider, assetAmount - reward2keeper);
emit LiquidationRecord(provider, msg.sender, onBehalfOf, eusdAmount, assetAmount, reward2keeper, true, block.timestamp);
}
/**
* @notice When stETH balance increases through LSD or other reasons, the excess income is sold for eUSD, allocated to eUSD holders through rebase mechanism.
* Emits a `LSDistribution` event.
*
* *Requirements:
* - stETH balance in the contract cannot be less than totalDepositedAsset after exchange.
* @dev Income is used to cover accumulated Service Fee first.
*/
function excessIncomeDistribution(uint256 payAmount) external virtual;
/**
* @notice Choose a Redemption Provider, Rigid Redeem `eusdAmount` of eUSD and get 1:1 value of collateral
* Emits a `RigidRedemption` event.
*
* *Requirements:
* - `provider` must be a Redemption Provider
* - `provider`debt must equal to or above`eusdAmount`
* @dev Service Fee for rigidRedemption `redemptionFee` is set to 0.5% by default, can be revised by DAO.
*/
function rigidRedemption(address provider, uint256 eusdAmount, uint256 minReceiveAmount) external virtual {
require(provider != msg.sender, "CBS");
require(configurator.isRedemptionProvider(provider), "provider is not a RedemptionProvider");
require(borrowed[provider] >= eusdAmount, "eusdAmount cannot surpass providers debt");
uint256 assetPrice = getAssetPrice();
uint256 providerCollateralRatio = (depositedAsset[provider] * assetPrice * 100) / borrowed[provider];
require(providerCollateralRatio >= 100 * 1e18, "The provider's collateral ratio should be not less than 100%.");
_repay(msg.sender, provider, eusdAmount);
uint256 collateralAmount = eusdAmount * 1e18 * (10_000 - configurator.redemptionFee()) / assetPrice / 10_000;
uint256 sendAmount = checkWithdrawal(provider, collateralAmount);
require(sendAmount >= minReceiveAmount, "EL");
depositedAsset[provider] -= collateralAmount;
totalDepositedAsset -= collateralAmount;
collateralAsset.safeTransfer(msg.sender, sendAmount);
emit RigidRedemption(msg.sender, provider, eusdAmount, sendAmount, block.timestamp);
}
/**
* @notice Mints eUSD tokens for a user.
* @param _provider The provider's address.
* @param _onBehalfOf The user's address.
* @param _mintAmount The amount of eUSD tokens to be minted.
* @param _assetPrice The current collateral asset price.
* @dev Mints eUSD tokens for the specified user, updates the total supply and borrowed balance,
* refreshes the mint reward for the provider, checks the health of the provider,
* and emits a Mint event.
* Requirements:
* The total supply plus mint amount must not exceed the maximum supply allowed for the vault.
* The provider must have sufficient borrowing capacity to mint the specified amount.
*/
function _mintEUSD(address _provider, address _onBehalfOf, uint256 _mintAmount, uint256 _assetPrice) internal virtual {
require(poolTotalCirculation + _mintAmount <= configurator.mintVaultMaxSupply(address(this)), "ESL");
configurator.refreshMintReward(_provider);
borrowed[_provider] += _mintAmount;
EUSD.mint(_onBehalfOf, _mintAmount);
_saveReport();
poolTotalCirculation += _mintAmount;
_checkHealth(_provider, _assetPrice);
emit Mint(msg.sender, _onBehalfOf, _mintAmount, block.timestamp);
}
/**
* @notice Burn _provideramount eUSD to payback minted eUSD for _onBehalfOf.
*
* @dev Refresh LBR reward before reducing providers debt. Refresh Lybra generated service fee before reducing totalEUSDCirculation.
*/
function _repay(address _provider, address _onBehalfOf, uint256 _amount) internal virtual {
uint256 amount = borrowed[_onBehalfOf] >= _amount ? _amount : borrowed[_onBehalfOf];
EUSD.burn(_provider, amount);
configurator.refreshMintReward(_onBehalfOf);
borrowed[_onBehalfOf] -= amount;
_saveReport();
poolTotalCirculation -= amount;
emit Burn(_provider, _onBehalfOf, amount, block.timestamp);
}
/**
* @dev Get USD value of current collateral asset and minted eUSD through price oracle / Collateral asset USD value must higher than safe Collateral Ratio.
*/
function _checkHealth(address _user, uint256 _assetPrice) internal view {
if (((depositedAsset[_user] * _assetPrice * 100) / borrowed[_user]) < configurator.getSafeCollateralRatio(address(this))) revert("collateralRatio is Below safeCollateralRatio");
}
function _saveReport() internal {
feeStored += _newFee();
lastReportTime = block.timestamp;
}
function _newFee() internal view returns (uint256) {
return (poolTotalCirculation * configurator.vaultMintFeeApy(address(this)) * (block.timestamp - lastReportTime)) / (86_400 * 365) / 10_000;
}
/**
* @dev Return USD value of current ETH through Liquity PriceFeed Contract.
*/
function _etherPrice() internal returns (uint256) {
return etherOracle.fetchPrice();
}
function getBorrowedOf(address user) external view returns (uint256) {
return borrowed[user];
}
function getPoolTotalCirculation() external view returns (uint256) {
return poolTotalCirculation;
}
function getAsset() external view virtual returns (address) {
return address(collateralAsset);
}
function getVaultType() external pure returns (uint8) {
return 0;
}
function getAssetPrice() public virtual returns (uint256);
function getAsset2EtherExchangeRate() external view virtual returns (uint256);
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
* 0 before setting it to a non-zero value.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Read Contract
EUSD 0xea58c644 → address
badCollateralRatio 0x6bc05280 → uint256
checkWithdrawal 0xa21bab8e → uint256
collateralAsset 0xaabaecd6 → address
configurator 0x2b507df8 → address
depositedAsset 0x69d83b3c → uint256
feeStored 0xb0df27fd → uint256
getAsset 0x5c222bad → address
getAsset2EtherExchangeRate 0x5df10472 → uint256
getBorrowedOf 0x05ad8308 → uint256
getDutchAuctionDiscountPrice 0x18991153 → uint256
getPoolTotalCirculation 0x9754d1dc → uint256
getVaultType 0x75baf37f → uint8
lastReportTime 0xe0115d0d → uint256
lidoRebaseTime 0xbf993442 → uint256
totalDepositedAsset 0x17d145a2 → uint256
Write Contract 11 functions
These functions modify contract state and require a wallet transaction to execute.
burn 0x9dc29fac
address onBehalfOf
uint256 amount
depositAssetToMint 0xabbc4217
uint256 assetAmount
uint256 mintAmount
depositEtherToMint 0x2f0bc965
uint256 mintAmount
excessIncomeDistribution 0x6bef22ee
uint256 stETHAmount
getAssetPrice 0xe54f0880
No parameters
returns: uint256
liquidation 0x96171e59
address provider
address onBehalfOf
uint256 assetAmount
mint 0x40c10f19
address onBehalfOf
uint256 amount
rigidRedemption 0xca0b7856
address provider
uint256 eusdAmount
uint256 minReceiveAmount
setLidoRebaseTime 0x4a7f299e
uint256 _time
superLiquidation 0xc05ebc2c
address provider
address onBehalfOf
uint256 assetAmount
withdraw 0xf3fef3a3
address onBehalfOf
uint256 amount
Token Balances (2)
View Transfers →Recent Transactions
No transactions found for this address