Address Contract Partially Verified
Address
0x285408b13370F026F89Eb072D6105138502B79ff
Balance
0 ETH
Nonce
1
Code Size
11858 bytes
Creator
0x728310Fe...72BA at tx 0x2cc10b51...1c8581
Indexed Transactions
0
Contract Bytecode
11858 bytes
0x608060405234801561001057600080fd5b50600436106102535760003560e01c80636d4749fa11610146578063a4d66daf116100c3578063c4d4803a11610087578063c4d4803a146105e6578063cfb636f01461060d578063d8dfeb4514610620578063d9caed1214610647578063f2fde38b1461065a578063f3f480d91461066d57600080fd5b8063a4d66daf1461054c578063a8a3e31d14610573578063babe7c741461057b578063be9a6555146105a2578063c2b6b58c146105c957600080fd5b80637bd6fb9b1161010a5780637bd6fb9b146105025780638da5cb5b1461050a57806399a5d7471461051d5780639de2f79614610530578063a035b1fe1461054357600080fd5b80636d4749fa146104915780636f871cec146104a457806372bf079e146104b7578063730d48b7146104ca578063787a08a6146104f157600080fd5b8063371fd8e6116101d45780634665096d116101985780634665096d1461040d57806346c715fa1461043b57806349746f10146104625780634f02c420146104755780635be980f51461047e57600080fd5b8063371fd8e614610391578063383ef46e146103a45780633a7c29fb146103c057806340c10f19146103e757806342d02041146103fa57600080fd5b806324e657fe1161021b57806324e657fe146102f15780632a37eeae146102fa578063329864aa14610302578063350c35e91461033f578063365a86fc1461035257600080fd5b806308262940146102585780630e49d77e1461027e5780631bbea34c1461028857806320aa9e721461029b578063211d7983146102de575b600080fd5b61026b610266366004612981565b610694565b6040519081526020015b60405180910390f35b610286610733565b005b6102866102963660046129b1565b6107fc565b6102ae6102a9366004612a8b565b610985565b604080516001600160a01b03909516855260208501939093529183015263ffffffff166060820152608001610275565b6102866102ec366004612ab7565b610ac6565b61026b60045481565b61026b61117c565b6001546040805191825264ffffffffff7f000000000000000000000000000000000000000000000000000000000001518016602083015201610275565b61028661034d366004612a8b565b611262565b6103797f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca65355781565b6040516001600160a01b039091168152602001610275565b61026b61039f366004612aec565b61134d565b6103ac6114e9565b60405162ffffff9091168152602001610275565b6103ac7f000000000000000000000000000000000000000000000000000000000005a55081565b6102866103f5366004612a8b565b611506565b610286610408366004612aec565b6115f0565b60055461042590600160281b900464ffffffffff1681565b60405164ffffffffff9091168152602001610275565b6103797f000000000000000000000000285408b13370f026f89eb072d6105138502b79ff81565b610286610470366004612aec565b611714565b61026b60025481565b61028661048c366004612aec565b611784565b61028661049f366004612b18565b61186b565b6102866104b2366004612b46565b611a57565b6102866104c5366004612aec565b611c88565b6103ac7f000000000000000000000000000000000000000000000000000000000000000081565b6005546104259064ffffffffff1681565b6103ac611cd8565b600054610379906001600160a01b031681565b6103ac61052b366004612aec565b611de8565b61026b61053e366004612aec565b611ea0565b61026b60015481565b61026b7f00000000000000000000000000000000000000000001a784379d99db4200000081565b61026b611f27565b61026b7f00000000000000000000000000000000000000000000021e19e0c9bab240000081565b6104257f00000000000000000000000000000000000000000000000000000000677aa7c381565b600554600160501b900460ff166040519015158152602001610275565b6103797f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb81565b61028661061b366004612aec565b611ff3565b6103797f000000000000000000000000d533a949740bb3306d119cc777fa900ba034cd5281565b610286610655366004612b72565b6120da565b610286610668366004612bb3565b6121c6565b6104257f000000000000000000000000000000000000000000000000000000000001518081565b600081156106ff57620f42406106a86114e9565b6106d57f000000000000000000000000000000000000000000000000000000000005a550620f4240612be6565b6106df9190612be6565b6106ee9062ffffff1685612c09565b6106f89190612c20565b905061072d565b620f42406106df7f000000000000000000000000000000000000000000000000000000000005a55082612be6565b92915050565b600454156107545760405163d26e2de960e01b815260040160405180910390fd5b60055464ffffffffff16421161077d57604051631c02820f60e21b815260040160405180910390fd5b600554600160281b900464ffffffffff1642106107cf576005546040516238ddd760e41b815264ffffffffff4281166004830152600160281b9092049190911660248201526044015b60405180910390fd5b600554600160501b900460ff16156107fa57604051631cdde67b60e01b815260040160405180910390fd5b565b7f00000000000000000000000000000000000000000000000000000000677aa7c364ffffffffff1642106108435760405163ecdd1c2960e01b815260040160405180910390fd5b7f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb6001600160a01b031663cd3293de6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c59190612c42565b6001600160a01b031663352e3a833386866040518463ffffffff1660e01b81526004016108f493929190612c5f565b60006040518083038186803b15801561090c57600080fd5b505afa158015610920573d6000803e3d6000fd5b5050505061093c6005805460ff60501b1916600160501b179055565b336001600160a01b03167faca80c800ec0d2aa9d9d31b7f886a1dd3067d4676abc637626a18ffb9381653d8383604051610977929190612cbb565b60405180910390a250505050565b6000808080336001600160a01b037f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca65355716146109d3576040516313bd2e8360e31b815260040160405180910390fd5b84600460008282546109e59190612cea565b90915550600090506109f56121d8565b905085811015610a03578095505b60008115610a29578187600254610a1a9190612c09565b610a249190612c20565b610a2c565b60005b9050610a378161223f565b610a436203f4806122fe565b6000610a4f898961233f565b600154600254604080518481526020810193909352820152909150600080516020612dfd8339815191529060600160405180910390a1506000546001600160a01b031698969750957f000000000000000000000000000000000000000000000000000000000005a55062ffffff1695509350505050565b336001600160a01b037f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca6535571614610b0f576040516313bd2e8360e31b815260040160405180910390fd5b600554600160281b900464ffffffffff16421015610b40576040516302de694d60e41b815260040160405180910390fd5b60045415610b615760405163d26e2de960e01b815260040160405180910390fd5b6000610b6d848461233f565b600254909150156110a1576002546040516302dc1ca760e31b8152600481019190915262ffffff7f000000000000000000000000000000000000000000000000000000000005a5501660248201526000907f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb6001600160a01b0316906316e0e53890604401602060405180830381865afa158015610c0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c339190612cfd565b600254909150610c438285612d16565b10610de4576002546040516318af9f3960e11b81526001600160a01b038781166004830152602482019290925262ffffff7f000000000000000000000000000000000000000000000000000000000005a5501660448201526000917f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb169063315f3e72906064016020604051808303816000875af1158015610ce9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0d9190612cfd565b9050818114610d1e57610d1e612d29565b6000546002546001600160a01b037f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb8116926323b872dd928a929190911690610d67868a612d16565b610d719190612cea565b6040518463ffffffff1660e01b8152600401610d8f93929190612d3f565b6020604051808303816000875af1158015610dae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd29190612d63565b50610dde60025461223f565b5061109b565b6040516323b872dd60e01b81526001600160a01b037f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb16906323b872dd90610e3490889030908890600401612d3f565b6020604051808303816000875af1158015610e53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e779190612d63565b5081600003610fd5577f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb6001600160a01b031663d1fa5e983085600254610ebe9190612cea565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015610f0457600080fd5b505af1158015610f18573d6000803e3d6000fd5b50506002546040516363b20c3360e11b8152600481019190915262ffffff7f000000000000000000000000000000000000000000000000000000000005a5501660248201527f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb6001600160a01b0316925063c76418669150604401600060405180830381600087803b158015610fad57600080fd5b505af1158015610fc1573d6000803e3d6000fd5b50505050610fd060025461223f565b61109b565b60405163a47d75ad60e01b81526004810184905262ffffff7f000000000000000000000000000000000000000000000000000000000005a5501660248201526000907f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb6001600160a01b03169063a47d75ad906044016020604051808303816000875af115801561106a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061108e9190612cfd565b90506110998161223f565b505b5061113a565b6000546040516323b872dd60e01b81526001600160a01b037f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb8116926323b872dd926110f592899216908790600401612d3f565b6020604051808303816000875af1158015611114573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111389190612d63565b505b600080516020612dfd8339815191526111516121d8565b600154600254604080519384526020840192909252908201526060015b60405180910390a150505050565b60006001600160a01b037f000000000000000000000000285408b13370f026f89eb072d6105138502b79ff1630036111e0576003546111db907f00000000000000000000000000000000000000000001a784379d99db42000000612cea565b905090565b7f000000000000000000000000285408b13370f026f89eb072d6105138502b79ff6001600160a01b031663a8a3e31d6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561123e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111db9190612cfd565b7f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca6535576001600160a01b0316632f09177d6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112e49190612c42565b6001600160a01b0316336001600160a01b031614611305576113053361242f565b60006113118383612475565b600154600254604080518481526020810193909352820152909150600080516020612dfd833981519152906060015b60405180910390a1505050565b6040516323b872dd60e01b81526000906001600160a01b037f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb16906323b872dd906113a090339030908790600401612d3f565b6020604051808303816000875af11580156113bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113e39190612d63565b5060405163a47d75ad60e01b81526004810183905262ffffff7f000000000000000000000000000000000000000000000000000000000005a5501660248201526000907f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb6001600160a01b03169063a47d75ad906044016020604051808303816000875af1158015611479573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061149d9190612cfd565b90506114a88161223f565b600080516020612dfd8339815191526114bf6121d8565b6001546002546040805193845260208401929092529082015260600160405180910390a192915050565b6005546000906111db90600160281b900464ffffffffff16611de8565b7f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca6535576001600160a01b0316632f09177d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611564573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115889190612c42565b6001600160a01b0316336001600160a01b0316146115a9576115a93361242f565b60006115b36121d8565b90506115c08383836124dc565b600154600254604080518481526020810193909352820152600080516020612dfd83398151915290606001611340565b336001600160a01b037f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca6535571614611639576040516313bd2e8360e31b815260040160405180910390fd5b600554600160281b900464ffffffffff164210611686576005546040516238ddd760e41b815264ffffffffff4281166004830152600160281b9092049190911660248201526044016107c6565b7f00000000000000000000000000000000000000000000021e19e0c9bab2400000811080156116bb57506116b86121d8565b81105b156116d957604051633c80636b60e21b815260040160405180910390fd5b806000036116fa57604051633c80636b60e21b815260040160405180910390fd5b806004600082825461170c9190612d16565b909155505050565b336001600160a01b037f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca653557161461175d576040516313bd2e8360e31b815260040160405180910390fd5b806004600082825461176f9190612cea565b909155506117819050620151806122fe565b50565b60405163aa5dd7f160e01b81523360048201526001600160a01b037f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca6535578116917f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb9091169063aa5dd7f190602401602060405180830381865afa15801561180e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118329190612c42565b6001600160a01b031614611859576040516313bd2e8360e31b815260040160405180910390fd5b806003600082825461170c9190612cea565b336001600160a01b037f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca65355716146118b4576040516313bd2e8360e31b815260040160405180910390fd5b600554600160281b900464ffffffffff16156118e25760405162dc149f60e41b815260040160405180910390fd5b428164ffffffffff16108061198557507f000000000000000000000000285408b13370f026f89eb072d6105138502b79ff6001600160a01b0316634665096d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611950573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119749190612d80565b64ffffffffff168164ffffffffff16115b156119a357604051637d9533a960e11b815260040160405180910390fd5b806005806101000a81548164ffffffffff021916908364ffffffffff160217905550816001600160a01b031663a035b1fe6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a03573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a279190612cfd565b600155611a537f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca653557612744565b5050565b611a603361242f565b6000611a6a6121d8565b905080831115611b12576001600160a01b037f000000000000000000000000d533a949740bb3306d119cc777fa900ba034cd52166323b872dd3330611aaf8588612cea565b6040518463ffffffff1660e01b8152600401611acd93929190612d3f565b6020604051808303816000875af1158015611aec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b109190612d63565b505b600254841015611c0b577f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb6001600160a01b031663315f3e723386600254611b5a9190612cea565b6040516001600160e01b031960e085901b1681526001600160a01b039092166004830152602482015262ffffff7f000000000000000000000000000000000000000000000000000000000005a5501660448201526064016020604051808303816000875af1158015611bd0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bf49190612cfd565b50611c0b84600254611c069190612cea565b61223f565b80831015611c2857611c2633611c218584612cea565b612475565b505b600254841115611c4a57611c4a3360025486611c449190612cea565b856124dc565b6001548214611c5c57611c5c826127a7565b6040805184815260208101849052908101859052600080516020612dfd8339815191529060600161116e565b611c913361242f565b611c9a816127a7565b600080516020612dfd833981519152611cb16121d8565b6001546002546040805193845260208401929092529082015260600160405180910390a150565b60007f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca6535576001600160a01b0316632c4e722e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d7d9190612c42565b6001600160a01b03166306a7b3766040518163ffffffff1660e01b8152600401602060405180830381865afa158015611dba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dde9190612d9d565b6111db9190612dc2565b6000807f00000000000000000000000000000000000000000000000000000000677aa7c364ffffffffff164210611e1f5742611e48565b7f00000000000000000000000000000000000000000000000000000000677aa7c364ffffffffff165b90506000611e568285612cea565b905060006301e13380611e67611cd8565b611e769062ffffff1684612c09565b611e809190612c20565b9050620f42408111611e925780611e97565b620f42405b95945050505050565b60008115611f1f57611eb06114e9565b611edd7f000000000000000000000000000000000000000000000000000000000005a550620f4240612be6565b611ee79190612be6565b62ffffff166001611efb84620f4240612c09565b611f059190612cea565b611f0f9190612c20565b611f1a906001612d16565b61072d565b600092915050565b600080670de0b6b3a7640000600154611f3e6121d8565b611f489190612c09565b611f529190612c20565b905060008160025411611f7157600254611f6c9083612cea565b611f74565b60005b90507f00000000000000000000000000000000000000000001a784379d99db4200000081600354611fa59190612d16565b10611fb35760009250505090565b806003547f00000000000000000000000000000000000000000001a784379d99db42000000611fe29190612cea565b611fec9190612cea565b9250505090565b60405163aa5dd7f160e01b81523360048201526001600160a01b037f000000000000000000000000de12b620a8a714476a97efd14e6f7180ca6535578116917f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb9091169063aa5dd7f190602401602060405180830381865afa15801561207d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120a19190612c42565b6001600160a01b0316146120c8576040516313bd2e8360e31b815260040160405180910390fd5b806003600082825461170c9190612d16565b6120e33361242f565b7f000000000000000000000000d533a949740bb3306d119cc777fa900ba034cd526001600160a01b0316836001600160a01b03160361212b576121268282611262565b505050565b60006121356121d8565b60405163a9059cbb60e01b81526001600160a01b038581166004830152602482018590529192509085169063a9059cbb906044016020604051808303816000875af1158015612188573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121ac9190612d63565b506121b56121d8565b81146121c057600080fd5b50505050565b6121cf3361242f565b61178181612744565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000d533a949740bb3306d119cc777fa900ba034cd526001600160a01b0316906370a0823190602401602060405180830381865afa15801561123e573d6000803e3d6000fd5b600254811115612272576002546122569082612cea565b604051635795d46960e11b81526004016107c691815260200190565b604051635be980f560e01b8152600481018290527f000000000000000000000000285408b13370f026f89eb072d6105138502b79ff6001600160a01b031690635be980f590602401600060405180830381600087803b1580156122d457600080fd5b505af11580156122e8573d6000803e3d6000fd5b50505050806002600082825461170c9190612cea565b600061230a8242612dde565b60055490915064ffffffffff9081169082161115611a53576005805464ffffffffff831664ffffffffff199091161790555050565b600081156123dc5760405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490527f000000000000000000000000d533a949740bb3306d119cc777fa900ba034cd52169063a9059cbb906044016020604051808303816000875af11580156123b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123da9190612d63565b505b60006123e66121d8565b90507f00000000000000000000000000000000000000000000021e19e0c9bab2400000811015612428576124286005805460ff60501b1916600160501b179055565b9392505050565b6000546001600160a01b0382811691161480159061245757506000546001600160a01b031615155b15611781576040516330cd747160e01b815260040160405180910390fd5b600454600090156124995760405163d26e2de960e01b815260040160405180910390fd5b60055464ffffffffff1642116124c257604051631c02820f60e21b815260040160405180910390fd5b60006124ce848461233f565b90506124288160015461288a565b600454156124fd5760405163d26e2de960e01b815260040160405180910390fd5b60055464ffffffffff16421161252657604051631c02820f60e21b815260040160405180910390fd5b600554600160281b900464ffffffffff164210612573576005546040516238ddd760e41b815264ffffffffff4281166004830152600160281b9092049190911660248201526044016107c6565b600554600160501b900460ff161561259e57604051631cdde67b60e01b815260040160405180910390fd5b6125a661117c565b8211156125d857816125b661117c565b604051634779077960e11b8152600481019290925260248201526044016107c6565b604051630cfb636f60e41b8152600481018390527f000000000000000000000000285408b13370f026f89eb072d6105138502b79ff6001600160a01b03169063cfb636f090602401600060405180830381600087803b15801561263a57600080fd5b505af115801561264e573d6000803e3d6000fd5b505050507f000000000000000000000000b58e61c3098d85632df34eecfb899a1ed80921cb6001600160a01b0316638112eb2b84847f000000000000000000000000000000000000000000000000000000000005a5506126ac6114e9565b6040516001600160e01b031960e087901b1681526001600160a01b039094166004850152602484019290925262ffffff9081166044840152166064820152608401600060405180830381600087803b15801561270757600080fd5b505af115801561271b573d6000803e3d6000fd5b5050505081600260008282546127319190612d16565b925050819055506121268160015461288a565b6001600160a01b03811661275757600080fd5b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600454156127c85760405163d26e2de960e01b815260040160405180910390fd5b600554600160281b900464ffffffffff164210612815576005546040516238ddd760e41b815264ffffffffff4281166004830152600160281b9092049190911660248201526044016107c6565b600554600160501b900460ff161561284057604051631cdde67b60e01b815260040160405180910390fd5b60015481111561285b576128566203f4806122fe565b61286c565b61286c6128666121d8565b8261288a565b6117818161287861117c565b6002546128859190612d16565b612926565b60007f00000000000000000000000000000000000000000000021e19e0c9bab240000083106128b957826128bc565b60005b9050670de0b6b3a76400006002546128d49190612c09565b6128de8383612c09565b1015612126576128ee8282612c09565b670de0b6b3a76400006002546129049190612c09565b604051632c1f8ef160e21b8152600481019290925260248201526044016107c6565b612938670de0b6b3a764000082612c09565b6129627f00000000000000000000000000000000000000000000021e19e0c9bab240000084612c09565b111561296d57600080fd5b50600155565b801515811461178157600080fd5b6000806040838503121561299457600080fd5b8235915060208301356129a681612973565b809150509250929050565b600080600080604085870312156129c757600080fd5b843567ffffffffffffffff808211156129df57600080fd5b818701915087601f8301126129f357600080fd5b813581811115612a0257600080fd5b8860208260051b8501011115612a1757600080fd5b602092830196509450908601359080821115612a3257600080fd5b818701915087601f830112612a4657600080fd5b813581811115612a5557600080fd5b886020828501011115612a6757600080fd5b95989497505060200194505050565b6001600160a01b038116811461178157600080fd5b60008060408385031215612a9e57600080fd5b8235612aa981612a76565b946020939093013593505050565b600080600060608486031215612acc57600080fd5b8335612ad781612a76565b95602085013595506040909401359392505050565b600060208284031215612afe57600080fd5b5035919050565b64ffffffffff8116811461178157600080fd5b60008060408385031215612b2b57600080fd5b8235612b3681612a76565b915060208301356129a681612b05565b600080600060608486031215612b5b57600080fd5b505081359360208301359350604090920135919050565b600080600060608486031215612b8757600080fd5b8335612b9281612a76565b92506020840135612ba281612a76565b929592945050506040919091013590565b600060208284031215612bc557600080fd5b813561242881612a76565b634e487b7160e01b600052601160045260246000fd5b62ffffff828116828216039080821115612c0257612c02612bd0565b5092915050565b808202811582820484141761072d5761072d612bd0565b600082612c3d57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215612c5457600080fd5b815161242881612a76565b6001600160a01b03848116825260406020808401829052908301849052600091859160608501845b87811015612cae578435612c9a81612a76565b841682529382019390820190600101612c87565b5098975050505050505050565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b8181038181111561072d5761072d612bd0565b600060208284031215612d0f57600080fd5b5051919050565b8082018082111561072d5761072d612bd0565b634e487b7160e01b600052600160045260246000fd5b6001600160a01b039384168152919092166020820152604081019190915260600190565b600060208284031215612d7557600080fd5b815161242881612973565b600060208284031215612d9257600080fd5b815161242881612b05565b600060208284031215612daf57600080fd5b815162ffffff8116811461242857600080fd5b62ffffff818116838216019080821115612c0257612c02612bd0565b64ffffffffff818116838216019080821115612c0257612c02612bd056fe9483a26ad376f30b5199a79e75df3bb05158c4ee32a348f53e83245a5e50c86ea26469706673582212203d0e7cc7b31f042803c803a5def335273b3b31f8d50db1473e0cc88de51eebc764736f6c63430008140033
Verified Source Code Partial Match
Compiler: v0.8.20+commit.a1b79de6
EVM: paris
Optimization: Yes (200 runs)
IERC20.sol 89 lines
/**
* SPDX-License-Identifier: MIT
*
* Copyright (c) 2016-2019 zOS Global Limited
*
*/
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP. Does not include
* the optional functions; to access them see `ERC20Detailed`.
*/
interface IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
/**
* @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 always true. Throws error on failure.
*
* 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 can change 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.
*
* > 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 always true. Throws error on failure.
*
* 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);
}
IFrankencoin.sol 43 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./IReserve.sol";
interface IFrankencoin is IERC20 {
function suggestMinter(address _minter, uint256 _applicationPeriod, uint256 _applicationFee, string calldata _message) external;
function registerPosition(address position) external;
function denyMinter(address minter, address[] calldata helpers, string calldata message) external;
function reserve() external view returns (IReserve);
function minterReserve() external view returns (uint256);
function calculateAssignedReserve(uint256 mintedAmount, uint32 _reservePPM) external view returns (uint256);
function calculateFreedAmount(uint256 amountExcludingReserve, uint32 reservePPM) external view returns (uint256);
function equity() external view returns (uint256);
function isMinter(address minter) external view returns (bool);
function getPositionParent(address position) external view returns (address);
function mint(address target, uint256 amount) external;
function mintWithReserve(address target, uint256 amount, uint32 reservePPM, uint32 feePPM) external;
function burnFrom(address target, uint256 amount) external;
function burnWithoutReserve(uint256 amountIncludingReserve, uint32 reservePPM) external;
function burnFromWithReserve(address payer, uint256 targetTotalBurnAmount, uint32 _reservePPM) external returns (uint256);
function burnWithReserve(uint256 amountExcludingReserve, uint32 reservePPM) external returns (uint256);
function coverLoss(address source, uint256 amount) external;
function collectProfits(address source, uint256 _amount) external;
}
ILeadrate.sol 7 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ILeadrate {
function currentRatePPM() external view returns (uint24);
function currentTicks() external view returns (uint64);
}
IPosition.sol 80 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import './IERC20.sol';
interface IPosition {
function hub() external view returns (address);
function collateral() external view returns (IERC20);
function minimumCollateral() external view returns (uint256);
function price() external view returns (uint256);
function minted() external view returns (uint256);
function challengedAmount() external view returns (uint256);
function original() external view returns (address);
function expiration() external view returns (uint40);
function cooldown() external view returns (uint40);
function limit() external view returns (uint256);
function challengePeriod() external view returns (uint40);
function start() external view returns (uint40);
function riskPremiumPPM() external view returns (uint24);
function reserveContribution() external view returns (uint24);
function initialize(address parent, uint40 _expiration) external;
function assertCloneable() external;
function notifyMint(uint256 mint_) external;
function notifyRepaid(uint256 repaid_) external;
function availableForClones() external view returns (uint256);
function availableForMinting() external view returns (uint256);
function deny(address[] calldata helpers, string calldata message) external;
function getUsableMint(uint256 totalMint, bool afterFees) external view returns (uint256);
function getMintAmount(uint256 usableMint) external view returns (uint256);
function adjust(uint256 newMinted, uint256 newCollateral, uint256 newPrice) external;
function adjustPrice(uint256 newPrice) external;
function mint(address target, uint256 amount) external;
function calculateCurrentFee() external view returns (uint24);
function annualInterestPPM() external view returns (uint24);
function calculateFee(uint256 exp) external view returns (uint24);
function repay(uint256 amount) external returns (uint256);
function forceSale(address buyer, uint256 collAmount, uint256 proceeds) external;
function withdraw(address token, address target, uint256 amount) external;
function withdrawCollateral(address target, uint256 amount) external;
function challengeData() external view returns (uint256 liqPrice, uint40 phase);
function notifyChallengeStarted(uint256 size) external;
function notifyChallengeAverted(uint256 size) external;
function notifyChallengeSucceeded(address _bidder, uint256 _size) external returns (address, uint256, uint256, uint32);
}
IReserve.sol 9 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC20.sol";
interface IReserve is IERC20 {
function invest(uint256 amount, uint256 expected) external returns (uint256);
function checkQualified(address sender, address[] calldata helpers) external view;
}
MathUtil.sol 48 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title Functions for share valuation
*/
contract MathUtil {
uint256 internal constant ONE_DEC18 = 10 ** 18;
// Let's go for 12 digits of precision (18-6)
uint256 internal constant THRESH_DEC18 = 10 ** 6;
/**
* @notice Cubic root with Halley approximation
* Number 1e18 decimal
* @param _v number for which we calculate x**(1/3)
* @return returns _v**(1/3)
*/
function _cubicRoot(uint256 _v) internal pure returns (uint256) {
// Good first guess for _v slightly above 1.0, which is often the case in the Frankencoin system
uint256 x = _v > ONE_DEC18 && _v < 10 ** 19 ? (_v - ONE_DEC18) / 3 + ONE_DEC18 : ONE_DEC18;
uint256 diff;
do {
uint256 powX3 = _mulD18(_mulD18(x, x), x);
uint256 xnew = x * (powX3 + 2 * _v) / (2 * powX3 + _v);
diff = xnew > x ? xnew - x : x - xnew;
x = xnew;
} while (diff > THRESH_DEC18);
return x;
}
function _mulD18(uint256 _a, uint256 _b) internal pure returns (uint256) {
return (_a * _b) / ONE_DEC18;
}
function _divD18(uint256 _a, uint256 _b) internal pure returns (uint256) {
return (_a * ONE_DEC18) / _b;
}
function _power3(uint256 _x) internal pure returns (uint256) {
return _mulD18(_mulD18(_x, _x), _x);
}
function _min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
}
Ownable.sol 54 lines
// SPDX-License-Identifier: MIT
//
// From https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol
//
// Modifications:
// - Replaced Context._msgSender() with msg.sender
// - Made leaner
pragma solidity ^0.8.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
error NotOwner();
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_setOwner(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _setOwner(address newOwner) internal {
require(newOwner != address(0x0)); // ensure initialization can only done once
address oldOwner = owner;
owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
function _requireOwner(address sender) internal view {
if (owner != sender && owner != address(0x0)) revert NotOwner();
}
modifier onlyOwner() {
_requireOwner(msg.sender);
_;
}
}
Position.sol 585 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import './Ownable.sol';
import './MathUtil.sol';
import './IERC20.sol';
import './ILeadrate.sol';
import './IReserve.sol';
import './IFrankencoin.sol';
import './IPosition.sol';
/**
* @title Position
* @notice A collateralized minting position.
*/
contract Position is Ownable, IPosition, MathUtil {
/**
* @notice Note that this contract is intended to be cloned. All clones will share the same values for
* the constant and immutable fields, but have their own values for the other fields.
*/
/**
* @notice The zchf price per unit of the collateral below which challenges succeed, (36 - collateral.decimals) decimals
*/
uint256 public price;
/**
* @notice Net minted amount, including reserve.
*/
uint256 public minted;
/**
* @notice How much has been minted in total. This variable is only used in the parent position.
*/
uint256 private totalMinted;
uint256 public immutable limit;
/**
* @notice Amount of the collateral that is currently under a challenge.
* Used to figure out whether there are pending challenges.
*/
uint256 public challengedAmount;
/**
* @notice Challenge period in seconds.
*/
uint40 public immutable challengePeriod;
/**
* @notice Timestamp when minting can start and the position no longer denied.
*/
uint40 public immutable start;
/**
* @notice End of the latest cooldown. If this is in the future, minting is suspended.
*/
uint40 public cooldown;
/**
* @notice Timestamp of the expiration of the position. After expiration, challenges cannot be averted
* any more. This is also the basis for fee calculations.
*/
uint40 public expiration;
bool private closed;
/**
* @notice The original position to help identifying clones.
*/
address public immutable original;
/**
* @notice Pointer to the minting hub.
*/
address public immutable hub;
/**
* @notice The Frankencoin contract.
*/
IFrankencoin public immutable zchf;
/**
* @notice The collateral token.
*/
IERC20 public immutable override collateral;
/**
* @notice Minimum acceptable collateral amount to prevent dust.
*/
uint256 public immutable override minimumCollateral;
/**
* @notice The interest in parts per million per year that is deducted when minting Frankencoins.
* To be paid upfront.
*/
uint24 public immutable riskPremiumPPM;
/**
* @notice The reserve contribution in parts per million of the minted amount.
*/
uint24 public immutable reserveContribution;
event MintingUpdate(uint256 collateral, uint256 price, uint256 minted);
event PositionDenied(address indexed sender, string message); // emitted if closed by governance
error InsufficientCollateral(uint256 needed, uint256 available);
error TooLate();
error RepaidTooMuch(uint256 excess);
error LimitExceeded(uint256 tried, uint256 available);
error ChallengeTooSmall();
error Expired(uint40 time, uint40 expiration);
error Alive();
error Closed();
error Hot();
error Challenged();
error NotHub();
error NotOriginal();
error InvalidExpiration();
error AlreadyInitialized();
modifier alive() {
if (block.timestamp >= expiration) revert Expired(uint40(block.timestamp), expiration);
_;
}
// requires that the position has always been backed by a minimal amount of collateral
modifier backed() {
if (isClosed()) revert Closed();
_;
}
modifier expired() {
if (block.timestamp < expiration) revert Alive();
_;
}
modifier noCooldown() {
if (block.timestamp <= cooldown) revert Hot();
_;
}
modifier noChallenge() {
if (challengedAmount > 0) revert Challenged();
_;
}
modifier onlyHub() {
if (msg.sender != address(hub)) revert NotHub();
_;
}
modifier ownerOrRoller() {
if (msg.sender != address(IHub(hub).roller())) _requireOwner(msg.sender);
_;
}
/**
* @dev See MintingHub.openPosition
*/
constructor(
address _owner,
address _hub,
address _zchf,
address _collateral,
uint256 _minCollateral,
uint256 _initialLimit,
uint40 _initPeriod,
uint40 _duration,
uint40 _challengePeriod,
uint24 _riskPremiumPPM,
uint256 _liqPrice,
uint24 _reservePPM
) {
require(_initPeriod >= 3 days); // must be at least three days, recommended to use higher values
_setOwner(_owner);
original = address(this);
hub = _hub;
zchf = IFrankencoin(_zchf);
collateral = IERC20(_collateral);
riskPremiumPPM = _riskPremiumPPM;
reserveContribution = _reservePPM;
minimumCollateral = _minCollateral;
challengePeriod = _challengePeriod;
start = uint40(block.timestamp) + _initPeriod; // at least three days time to deny the position
cooldown = start;
expiration = start + _duration;
limit = _initialLimit;
_setPrice(_liqPrice, _initialLimit);
}
/**
* Initialization method for clones.
* Can only be called once. Should be called immediately after creating the clone.
*/
function initialize(address parent, uint40 _expiration) external onlyHub {
if (expiration != 0) revert AlreadyInitialized();
if (_expiration < block.timestamp || _expiration > Position(original).expiration()) revert InvalidExpiration(); // expiration must not be later than original
expiration = _expiration;
price = Position(parent).price();
_setOwner(hub);
}
/**
* Cloning a position is only allowed if the position is not challenged, not expired and not in cooldown.
*/
function assertCloneable() external noChallenge noCooldown alive backed {}
/**
* Notify the original that some amount has been minted.
*/
function notifyMint(uint256 mint_) external {
if (zchf.getPositionParent(msg.sender) != hub) revert NotHub();
totalMinted += mint_;
}
function notifyRepaid(uint256 repaid_) external {
if (zchf.getPositionParent(msg.sender) != hub) revert NotHub();
totalMinted -= repaid_;
}
/**
* Should only be called on the original position.
* Better use 'availableForMinting'.
*/
function availableForClones() external view returns (uint256) {
// reserve capacity for the original to the extent the owner provided collateral
uint256 potential = (_collateralBalance() * price) / ONE_DEC18;
uint256 unusedPotential = minted > potential ? 0 : potential - minted;
if (totalMinted + unusedPotential >= limit) {
return 0;
} else {
return limit - totalMinted - unusedPotential;
}
}
/**
* The amount available for minting in this position family.
*
* Does not check if positions are challenged, closed, or under cooldown.
*/
function availableForMinting() public view returns (uint256) {
if (address(this) == original) {
return limit - totalMinted;
} else {
return Position(original).availableForClones();
}
}
/**
* @notice Qualified pool share holders can call this method to immediately expire a freshly proposed position.
*/
function deny(address[] calldata helpers, string calldata message) external {
if (block.timestamp >= start) revert TooLate();
IReserve(zchf.reserve()).checkQualified(msg.sender, helpers);
_close();
emit PositionDenied(msg.sender, message);
}
/**
* Closes the position by putting it into eternal cooldown.
* This allows the users to still withdraw the collateral that is left, but never to mint again.
*/
function _close() internal {
closed = true;
}
function isClosed() public view returns (bool) {
return closed;
}
/**
* @notice This is how much the minter can actually use when minting ZCHF, with the rest being used
* assigned to the minter reserve or (if applicable) fees.
*/
function getUsableMint(uint256 totalMint, bool afterFees) public view returns (uint256) {
if (afterFees) {
return (totalMint * (1000_000 - reserveContribution - calculateCurrentFee())) / 1000_000;
} else {
return (totalMint * (1000_000 - reserveContribution)) / 1000_000;
}
}
/**
* Returns the corresponding mint amount (disregarding the limit).
*/
function getMintAmount(uint256 usableMint) external view returns (uint256) {
return usableMint == 0 ? 0 : (usableMint * 1000_000 - 1) / (1000_000 - reserveContribution - calculateCurrentFee()) + 1;
}
/**
* @notice "All in one" function to adjust the outstanding amount of ZCHF, the collateral amount,
* and the price in one transaction.
*/
function adjust(uint256 newMinted, uint256 newCollateral, uint256 newPrice) external onlyOwner {
uint256 colbal = _collateralBalance();
if (newCollateral > colbal) {
collateral.transferFrom(msg.sender, address(this), newCollateral - colbal);
}
// Must be called after collateral deposit, but before withdrawal
if (newMinted < minted) {
zchf.burnFromWithReserve(msg.sender, minted - newMinted, reserveContribution);
_notifyRepaid(minted - newMinted);
}
if (newCollateral < colbal) {
_withdrawCollateral(msg.sender, colbal - newCollateral);
}
// Must be called after collateral withdrawal
if (newMinted > minted) {
_mint(msg.sender, newMinted - minted, newCollateral);
}
if (newPrice != price) {
_adjustPrice(newPrice);
}
emit MintingUpdate(newCollateral, newPrice, newMinted);
}
/**
* @notice Allows the position owner to adjust the liquidation price as long as there is no pending challenge.
* Lowering the liquidation price can be done with immediate effect, given that there is enough collateral.
* Increasing the liquidation price triggers a cooldown period of 3 days, during which minting is suspended.
*/
function adjustPrice(uint256 newPrice) public onlyOwner {
_adjustPrice(newPrice);
emit MintingUpdate(_collateralBalance(), price, minted);
}
function _adjustPrice(uint256 newPrice) internal noChallenge alive backed {
if (newPrice > price) {
_restrictMinting(3 days);
} else {
_checkCollateral(_collateralBalance(), newPrice);
}
_setPrice(newPrice, minted + availableForMinting());
}
function _setPrice(uint256 newPrice, uint256 bounds) internal {
require(newPrice * minimumCollateral <= bounds * ONE_DEC18); // sanity check
price = newPrice;
}
function _collateralBalance() internal view returns (uint256) {
return IERC20(collateral).balanceOf(address(this));
}
/**
* @notice Mint ZCHF as long as there is no open challenge, the position is not subject to a cooldown,
* and there is sufficient collateral.
*/
function mint(address target, uint256 amount) public ownerOrRoller {
uint256 collateralBalance = _collateralBalance();
_mint(target, amount, collateralBalance);
emit MintingUpdate(collateralBalance, price, minted);
}
/**
* The applicable upfront fee in ppm when minting more Frankencoins based on the annual interest rate and
* the expiration of the position.
*/
function calculateCurrentFee() public view returns (uint24) {
return calculateFee(expiration);
}
/**
* The applicable interest rate in ppm when minting more Frankencoins.
* It consists on the globally valid interest plus an individual risk premium.
*/
function annualInterestPPM() public view returns (uint24) {
return IHub(hub).rate().currentRatePPM() + riskPremiumPPM;
}
/**
* The fee in ppm when cloning and minting with the given expiration date.
*/
function calculateFee(uint256 exp) public view returns (uint24) {
uint256 time = block.timestamp < start ? start : block.timestamp;
uint256 timePassed = exp - time;
// Time resolution is in the range of minutes for typical interest rates.
uint256 feePPM = (timePassed * annualInterestPPM()) / 365 days;
return uint24(feePPM > 1000000 ? 1000000 : feePPM); // fee cannot exceed 100%
}
function _mint(address target, uint256 amount, uint256 collateral_) internal noChallenge noCooldown alive backed {
if (amount > availableForMinting()) revert LimitExceeded(amount, availableForMinting());
Position(original).notifyMint(amount);
zchf.mintWithReserve(target, amount, reserveContribution, calculateCurrentFee());
minted += amount;
_checkCollateral(collateral_, price);
}
function _restrictMinting(uint40 period) internal {
uint40 horizon = uint40(block.timestamp) + period;
if (horizon > cooldown) {
cooldown = horizon;
}
}
/**
* @notice Repay some ZCHF. If too much is repaid, the call fails.
* It is possible to repay while there are challenges, but the collateral is locked until all is clear again.
*
* The repaid amount should fulfill the following equation in order to close the position,
* i.e. bring the minted amount to 0:
* minted = amount + zchf.calculateAssignedReserve(amount, reservePPM)
*
* Under normal circumstances, this implies:
* amount = minted * (1000000 - reservePPM)
*
* E.g. if minted is 50 and reservePPM is 200000, it is necessary to repay 40 to be able to close the position.
*/
function repay(uint256 amount) public returns (uint256) {
IERC20(zchf).transferFrom(msg.sender, address(this), amount);
uint256 actuallyRepaid = IFrankencoin(zchf).burnWithReserve(amount, reserveContribution);
_notifyRepaid(actuallyRepaid);
emit MintingUpdate(_collateralBalance(), price, minted);
return actuallyRepaid;
}
function _notifyRepaid(uint256 amount) internal {
if (amount > minted) revert RepaidTooMuch(amount - minted);
Position(original).notifyRepaid(amount);
minted -= amount;
}
/**
* Force the sale of some collateral after the position is expired.
*
* Can only be called by the minting hub and the minting hub is trusted to calculate the price correctly.
* The proceeds from the sale are first used to repay the outstanding balance and then (if anything is left)
* it is sent to the owner of the position.
*
* Do not allow a forced sale as long as there is an open challenge. Otherwise, a forced sale by the owner
* himself could remove any incentive to launch challenges shortly before the expiration. (CS-ZCHF2-001)
*/
function forceSale(address buyer, uint256 collAmount, uint256 proceeds) external onlyHub expired noChallenge {
// send collateral to buyer
uint256 remainingCollateral = _sendCollateral(buyer, collAmount);
if (minted > 0) {
uint256 availableReserve = zchf.calculateAssignedReserve(minted, reserveContribution);
if (proceeds + availableReserve >= minted) {
// repay everything from the buyer's account
uint256 returnedReserve = zchf.burnFromWithReserve(buyer, minted, reserveContribution);
assert(returnedReserve == availableReserve);
// transfer the remaining purchase price from the buyer to the owner
zchf.transferFrom(buyer, owner, proceeds + returnedReserve - minted);
_notifyRepaid(minted);
} else {
// we can only repay a part, nothing left to pay to owner
zchf.transferFrom(buyer, address(this), proceeds);
if (remainingCollateral == 0) {
// CS-ZCHF2-002, bad debt should be properly handled. In this case, the proceeds from
// the forced sale did not suffice to repay the position and there is a loss
zchf.coverLoss(address(this), minted - proceeds); // more than we need, but returned again on next line
zchf.burnWithoutReserve(minted, reserveContribution);
_notifyRepaid(minted);
} else {
uint256 repaid = zchf.burnWithReserve(proceeds, reserveContribution);
_notifyRepaid(repaid);
}
}
} else {
// wire funds directly to owner
zchf.transferFrom(buyer, owner, proceeds);
}
emit MintingUpdate(_collateralBalance(), price, minted);
}
/**
* @notice Withdraw any ERC20 token that might have ended up on this address.
* Withdrawing collateral is subject to the same restrictions as withdrawCollateral(...).
*/
function withdraw(address token, address target, uint256 amount) external onlyOwner {
if (token == address(collateral)) {
withdrawCollateral(target, amount);
} else {
uint256 balance = _collateralBalance();
IERC20(token).transfer(target, amount);
require(balance == _collateralBalance()); // guard against double-entry-point tokens
}
}
/**
* @notice Withdraw collateral from the position up to the extent that it is still well collateralized afterwards.
* Not possible as long as there is an open challenge or the contract is subject to a cooldown.
*
* Withdrawing collateral below the minimum collateral amount formally closes the position.
*/
function withdrawCollateral(address target, uint256 amount) public ownerOrRoller {
uint256 balance = _withdrawCollateral(target, amount);
emit MintingUpdate(balance, price, minted);
}
function _withdrawCollateral(address target, uint256 amount) internal noChallenge returns (uint256) {
if (block.timestamp <= cooldown) revert Hot();
uint256 balance = _sendCollateral(target, amount);
_checkCollateral(balance, price);
return balance;
}
function _sendCollateral(address target, uint256 amount) internal returns (uint256) {
if (amount > 0) {
// Some weird tokens fail when trying to transfer 0 amounts
IERC20(collateral).transfer(target, amount);
}
uint256 balance = _collateralBalance();
if (balance < minimumCollateral) {
_close();
}
return balance;
}
/**
* @notice This invariant must always hold and must always be checked when any of the three
* variables change in an adverse way.
*/
function _checkCollateral(uint256 collateralReserve, uint256 atPrice) internal view {
uint256 relevantCollateral = collateralReserve < minimumCollateral ? 0 : collateralReserve;
if (relevantCollateral * atPrice < minted * ONE_DEC18)
revert InsufficientCollateral(relevantCollateral * atPrice, minted * ONE_DEC18);
}
/**
* @notice Returns the liquidation price and the durations for phase1 and phase2 of the challenge.
* Both phases are usually of equal duration, but near expiration, phase one is adjusted such that
* it cannot last beyond the expiration date of the position.
*/
function challengeData() external view returns (uint256 liqPrice, uint40 phase) {
return (price, challengePeriod);
}
function notifyChallengeStarted(uint256 size) external onlyHub alive {
// Require minimum size. Collateral balance can be below minimum if it was partially challenged before.
if (size < minimumCollateral && size < _collateralBalance()) revert ChallengeTooSmall();
if (size == 0) revert ChallengeTooSmall();
challengedAmount += size;
}
/**
* @param size amount of collateral challenged (dec18)
*/
function notifyChallengeAverted(uint256 size) external onlyHub {
challengedAmount -= size;
// Don't allow minter to close the position immediately so challenge can be repeated before
// the owner has a chance to mint more on an undercollateralized position
_restrictMinting(1 days);
}
/**
* @notice Notifies the position that a challenge was successful.
* Triggers the payout of the challenged part of the collateral.
* Everything else is assumed to be handled by the hub.
*
* @param _bidder address of the bidder that receives the collateral
* @param _size amount of the collateral bid for
* @return (position owner, effective challenge size in ZCHF, amount to be repaid, reserve ppm)
*/
function notifyChallengeSucceeded(address _bidder, uint256 _size) external onlyHub returns (address, uint256, uint256, uint32) {
challengedAmount -= _size;
uint256 colBal = _collateralBalance();
if (colBal < _size) {
_size = colBal;
}
uint256 repayment = colBal == 0 ? 0 : (minted * _size) / colBal; // for enormous colBal, this could be rounded to 0, which is ok
_notifyRepaid(repayment); // we assume the caller takes care of the actual repayment
// Give time for additional challenges before the owner can mint again. In particular,
// the owner might have added collateral only seconds before the challenge ended, preventing a close.
_restrictMinting(3 days);
uint256 newBalance = _sendCollateral(_bidder, _size); // transfer collateral to the bidder and emit update
emit MintingUpdate(newBalance, price, minted);
return (owner, _size, repayment, reserveContribution);
}
}
interface IHub {
function rate() external view returns (ILeadrate);
function roller() external view returns (address);
}
Read Contract
annualInterestPPM 0x7bd6fb9b → uint24
availableForClones 0xa8a3e31d → uint256
availableForMinting 0x2a37eeae → uint256
calculateCurrentFee 0x383ef46e → uint24
calculateFee 0x99a5d747 → uint24
challengeData 0x329864aa → uint256, uint40
challengePeriod 0xf3f480d9 → uint40
challengedAmount 0x24e657fe → uint256
collateral 0xd8dfeb45 → address
cooldown 0x787a08a6 → uint40
expiration 0x4665096d → uint40
getMintAmount 0x9de2f796 → uint256
getUsableMint 0x08262940 → uint256
hub 0x365a86fc → address
isClosed 0xc2b6b58c → bool
limit 0xa4d66daf → uint256
minimumCollateral 0xbabe7c74 → uint256
minted 0x4f02c420 → uint256
original 0x46c715fa → address
owner 0x8da5cb5b → address
price 0xa035b1fe → uint256
reserveContribution 0x3a7c29fb → uint24
riskPremiumPPM 0x730d48b7 → uint24
start 0xbe9a6555 → uint40
zchf 0xc4d4803a → address
Write Contract 16 functions
These functions modify contract state and require a wallet transaction to execute.
adjust 0x6f871cec
uint256 newMinted
uint256 newCollateral
uint256 newPrice
adjustPrice 0x72bf079e
uint256 newPrice
assertCloneable 0x0e49d77e
No parameters
deny 0x1bbea34c
address[] helpers
string message
forceSale 0x211d7983
address buyer
uint256 collAmount
uint256 proceeds
initialize 0x6d4749fa
address parent
uint40 _expiration
mint 0x40c10f19
address target
uint256 amount
notifyChallengeAverted 0x49746f10
uint256 size
notifyChallengeStarted 0x42d02041
uint256 size
notifyChallengeSucceeded 0x20aa9e72
address _bidder
uint256 _size
returns: address, uint256, uint256, uint32
notifyMint 0xcfb636f0
uint256 mint_
notifyRepaid 0x5be980f5
uint256 repaid_
repay 0x371fd8e6
uint256 amount
returns: uint256
transferOwnership 0xf2fde38b
address newOwner
withdraw 0xd9caed12
address token
address target
uint256 amount
withdrawCollateral 0x350c35e9
address target
uint256 amount
Recent Transactions
No transactions found for this address