Address Contract Partially Verified
Address
0x389c6f04D39fF038cC99F94BcE338D2f5Eb64a67
Balance
0 ETH
Nonce
1
Code Size
14934 bytes
Creator
0x9BB51953...F4d0 at tx 0x32e5cf4c...9cc1ea
Indexed Transactions
0
Contract Bytecode
14934 bytes
0x60806040523480156200001157600080fd5b5060043610620000b85760003560e01c806366d8cc25116200007b57806366d8cc251462000177578063715018a614620001ad5780638da5cb5b14620001b9578063aaf10f4214620001db578063f2fde38b14620001fd578063f77c4791146200021d57620000b8565b806306cb5b6614620000bd5780630ef52d0c14620000dd5780632d6b3a6b1462000113578063485cc955146200013557806359659e901462000155575b600080fd5b620000db6004803603810190620000d5919062000c8f565b6200023f565b005b620000fb6004803603810190620000f5919062000e23565b62000301565b6040516200010a919062000e9a565b60405180910390f35b6200011d620004a6565b6040516200012c919062000e9a565b60405180910390f35b6200015360048036038101906200014d919062000eb7565b620004d0565b005b6200015f620007cb565b6040516200016e919062000f69565b60405180910390f35b6200019560048036038101906200018f919062000fc1565b620007f1565b604051620001a4919062000e9a565b60405180910390f35b620001b762000831565b005b620001c362000849565b604051620001d2919062000e9a565b60405180910390f35b620001e562000873565b604051620001f4919062000e9a565b60405180910390f35b6200021b600480360381019062000215919062000c8f565b6200090e565b005b6200022762000998565b60405162000236919062000e9a565b60405180910390f35b62000249620009be565b80600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603620002bc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620002b39062001054565b60405180910390fd5b81606660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050565b60006200030d620009be565b6000606560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16637ab4339d60e01b85856040516024016200034f929190620010ee565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051620003ba9062000bfa565b620003c79291906200117f565b604051809103906000f080158015620003e4573d6000803e3d6000fd5b5090508091506067829080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff167f6fa707540e21db97a9e1d312fc0a0348372246ef38e15a96cae6f3c115e56322858560405162000497929190620010ee565b60405180910390a25092915050565b6000606560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060019054906101000a900460ff16159050808015620005025750600160008054906101000a900460ff1660ff16105b80620005335750620005143062000a43565b158015620005325750600160008054906101000a900460ff1660ff16145b5b62000575576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016200056c9062001229565b60405180910390fd5b60016000806101000a81548160ff021916908360ff1602179055508015620005b3576001600060016101000a81548160ff0219169083151502179055505b82600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160362000626576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016200061d9062001054565b60405180910390fd5b82600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160362000699576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620006909062001054565b60405180910390fd5b620006a362000a66565b84606660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555083620006ef62000849565b604051620006fd9062000c08565b6200070a9291906200124b565b604051809103906000f08015801562000727573d6000803e3d6000fd5b50606560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050508015620007c65760008060016101000a81548160ff0219169083151502179055507f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024986001604051620007bd9190620012c8565b60405180910390a15b505050565b606560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b606781815481106200080257600080fd5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6200083b620009be565b62000847600062000ac4565b565b6000603360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000606560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620008e3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620009099190620012fc565b905090565b62000918620009be565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036200098a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016200098190620013a4565b60405180910390fd5b620009958162000ac4565b50565b606660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b620009c862000b8a565b73ffffffffffffffffffffffffffffffffffffffff16620009e862000849565b73ffffffffffffffffffffffffffffffffffffffff161462000a41576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040162000a389062001416565b60405180910390fd5b565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b600060019054906101000a900460ff1662000ab8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040162000aaf90620014ae565b60405180910390fd5b62000ac262000b92565b565b6000603360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081603360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b600060019054906101000a900460ff1662000be4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040162000bdb90620014ae565b60405180910390fd5b62000bf862000bf262000b8a565b62000ac4565b565b610f3f80620014d183390190565b611611806200241083390190565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600062000c578262000c2a565b9050919050565b62000c698162000c4a565b811462000c7557600080fd5b50565b60008135905062000c898162000c5e565b92915050565b60006020828403121562000ca85762000ca762000c20565b5b600062000cb88482850162000c78565b91505092915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b62000d168262000ccb565b810181811067ffffffffffffffff8211171562000d385762000d3762000cdc565b5b80604052505050565b600062000d4d62000c16565b905062000d5b828262000d0b565b919050565b600067ffffffffffffffff82111562000d7e5762000d7d62000cdc565b5b62000d898262000ccb565b9050602081019050919050565b82818337600083830152505050565b600062000dbc62000db68462000d60565b62000d41565b90508281526020810184848401111562000ddb5762000dda62000cc6565b5b62000de884828562000d96565b509392505050565b600082601f83011262000e085762000e0762000cc1565b5b813562000e1a84826020860162000da5565b91505092915050565b6000806040838503121562000e3d5762000e3c62000c20565b5b600083013567ffffffffffffffff81111562000e5e5762000e5d62000c25565b5b62000e6c8582860162000df0565b925050602062000e7f8582860162000c78565b9150509250929050565b62000e948162000c4a565b82525050565b600060208201905062000eb1600083018462000e89565b92915050565b6000806040838503121562000ed15762000ed062000c20565b5b600062000ee18582860162000c78565b925050602062000ef48582860162000c78565b9150509250929050565b6000819050919050565b600062000f2962000f2362000f1d8462000c2a565b62000efe565b62000c2a565b9050919050565b600062000f3d8262000f08565b9050919050565b600062000f518262000f30565b9050919050565b62000f638162000f44565b82525050565b600060208201905062000f80600083018462000f58565b92915050565b6000819050919050565b62000f9b8162000f86565b811462000fa757600080fd5b50565b60008135905062000fbb8162000f90565b92915050565b60006020828403121562000fda5762000fd962000c20565b5b600062000fea8482850162000faa565b91505092915050565b600082825260208201905092915050565b7f41646472657373205a65726f0000000000000000000000000000000000000000600082015250565b60006200103c600c8362000ff3565b9150620010498262001004565b602082019050919050565b600060208201905081810360008301526200106f816200102d565b9050919050565b600081519050919050565b60005b83811015620010a157808201518184015260208101905062001084565b60008484015250505050565b6000620010ba8262001076565b620010c6818562000ff3565b9350620010d881856020860162001081565b620010e38162000ccb565b840191505092915050565b600060408201905081810360008301526200110a8185620010ad565b90506200111b602083018462000e89565b9392505050565b600081519050919050565b600082825260208201905092915050565b60006200114b8262001122565b6200115781856200112d565b93506200116981856020860162001081565b620011748162000ccb565b840191505092915050565b600060408201905062001196600083018562000e89565b8181036020830152620011aa81846200113e565b90509392505050565b7f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160008201527f647920696e697469616c697a6564000000000000000000000000000000000000602082015250565b600062001211602e8362000ff3565b91506200121e82620011b3565b604082019050919050565b60006020820190508181036000830152620012448162001202565b9050919050565b600060408201905062001262600083018562000e89565b62001271602083018462000e89565b9392505050565b6000819050919050565b600060ff82169050919050565b6000620012b0620012aa620012a48462001278565b62000efe565b62001282565b9050919050565b620012c2816200128f565b82525050565b6000602082019050620012df6000830184620012b7565b92915050565b600081519050620012f68162000c5e565b92915050565b60006020828403121562001315576200131462000c20565b5b60006200132584828501620012e5565b91505092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006200138c60268362000ff3565b915062001399826200132e565b604082019050919050565b60006020820190508181036000830152620013bf816200137d565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b6000620013fe60208362000ff3565b91506200140b82620013c6565b602082019050919050565b600060208201905081810360008301526200143181620013ef565b9050919050565b7f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960008201527f6e697469616c697a696e67000000000000000000000000000000000000000000602082015250565b600062001496602b8362000ff3565b9150620014a38262001438565b604082019050919050565b60006020820190508181036000830152620014c98162001487565b905091905056fe608060405260405162000f3f38038062000f3f8339818101604052810190620000299190620006a6565b6200003d828260006200004560201b60201c565b5050620009c7565b62000056836200013c60201b60201c565b8273ffffffffffffffffffffffffffffffffffffffff167f1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e60405160405180910390a2600082511180620000a75750805b156200013757620001358373ffffffffffffffffffffffffffffffffffffffff16635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620000fd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200012391906200070c565b83620002db60201b620000371760201c565b505b505050565b62000152816200031160201b620000641760201c565b62000194576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016200018b90620007c5565b60405180910390fd5b6200021b8173ffffffffffffffffffffffffffffffffffffffff16635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620001e4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200020a91906200070c565b6200031160201b620000641760201c565b6200025d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040162000254906200085d565b60405180910390fd5b80620002977fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5060001b6200033460201b620000871760201c565b60000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b606062000309838360405180606001604052806027815260200162000f18602791396200033e60201b60201c565b905092915050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b6000819050919050565b60606000808573ffffffffffffffffffffffffffffffffffffffff16856040516200036a9190620008cc565b600060405180830381855af49150503d8060008114620003a7576040519150601f19603f3d011682016040523d82523d6000602084013e620003ac565b606091505b5091509150620003c586838387620003d060201b60201c565b925050509392505050565b60608315620004405760008351036200043757620003f4856200031160201b60201c565b62000436576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016200042d9062000935565b60405180910390fd5b5b82905062000453565b6200045283836200045b60201b60201c565b5b949350505050565b6000825111156200046f5781518083602001fd5b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620004a59190620009a3565b60405180910390fd5b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620004ef82620004c2565b9050919050565b6200050181620004e2565b81146200050d57600080fd5b50565b6000815190506200052181620004f6565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6200057c8262000531565b810181811067ffffffffffffffff821117156200059e576200059d62000542565b5b80604052505050565b6000620005b3620004ae565b9050620005c1828262000571565b919050565b600067ffffffffffffffff821115620005e457620005e362000542565b5b620005ef8262000531565b9050602081019050919050565b60005b838110156200061c578082015181840152602081019050620005ff565b60008484015250505050565b60006200063f6200063984620005c6565b620005a7565b9050828152602081018484840111156200065e576200065d6200052c565b5b6200066b848285620005fc565b509392505050565b600082601f8301126200068b576200068a62000527565b5b81516200069d84826020860162000628565b91505092915050565b60008060408385031215620006c057620006bf620004b8565b5b6000620006d08582860162000510565b925050602083015167ffffffffffffffff811115620006f457620006f3620004bd565b5b620007028582860162000673565b9150509250929050565b600060208284031215620007255762000724620004b8565b5b6000620007358482850162000510565b91505092915050565b600082825260208201905092915050565b7f455243313936373a206e657720626561636f6e206973206e6f74206120636f6e60008201527f7472616374000000000000000000000000000000000000000000000000000000602082015250565b6000620007ad6025836200073e565b9150620007ba826200074f565b604082019050919050565b60006020820190508181036000830152620007e0816200079e565b9050919050565b7f455243313936373a20626561636f6e20696d706c656d656e746174696f6e206960008201527f73206e6f74206120636f6e747261637400000000000000000000000000000000602082015250565b6000620008456030836200073e565b91506200085282620007e7565b604082019050919050565b60006020820190508181036000830152620008788162000836565b9050919050565b600081519050919050565b600081905092915050565b6000620008a2826200087f565b620008ae81856200088a565b9350620008c0818560208601620005fc565b80840191505092915050565b6000620008da828462000895565b915081905092915050565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b60006200091d601d836200073e565b91506200092a82620008e5565b602082019050919050565b6000602082019050818103600083015262000950816200090e565b9050919050565b600081519050919050565b60006200096f8262000957565b6200097b81856200073e565b93506200098d818560208601620005fc565b620009988162000531565b840191505092915050565b60006020820190508181036000830152620009bf818462000962565b905092915050565b61054180620009d76000396000f3fe6080604052366100135761001161001d565b005b61001b61001d565b005b610025610091565b610035610030610093565b610110565b565b606061005c83836040518060600160405280602781526020016104e560279139610136565b905092915050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b6000819050919050565b565b600061009d6101bc565b73ffffffffffffffffffffffffffffffffffffffff16635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061010b919061033b565b905090565b3660008037600080366000845af43d6000803e8060008114610131573d6000f35b3d6000fd5b60606000808573ffffffffffffffffffffffffffffffffffffffff168560405161016091906103d9565b600060405180830381855af49150503d806000811461019b576040519150601f19603f3d011682016040523d82523d6000602084013e6101a0565b606091505b50915091506101b186838387610213565b925050509392505050565b60006101ea7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5060001b610087565b60000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060831561027557600083510361026d5761022d85610064565b61026c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102639061044d565b60405180910390fd5b5b829050610280565b61027f8383610288565b5b949350505050565b60008251111561029b5781518083602001fd5b806040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102cf91906104c2565b60405180910390fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610308826102dd565b9050919050565b610318816102fd565b811461032357600080fd5b50565b6000815190506103358161030f565b92915050565b600060208284031215610351576103506102d8565b5b600061035f84828501610326565b91505092915050565b600081519050919050565b600081905092915050565b60005b8381101561039c578082015181840152602081019050610381565b60008484015250505050565b60006103b382610368565b6103bd8185610373565b93506103cd81856020860161037e565b80840191505092915050565b60006103e582846103a8565b915081905092915050565b600082825260208201905092915050565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b6000610437601d836103f0565b915061044282610401565b602082019050919050565b600060208201905081810360008301526104668161042a565b9050919050565b600081519050919050565b6000601f19601f8301169050919050565b60006104948261046d565b61049e81856103f0565b93506104ae81856020860161037e565b6104b781610478565b840191505092915050565b600060208201905081810360008301526104dc8184610489565b90509291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212202c7207dfd2b6e6bf237d231d38b838badd9a562a0a064d8527a8b8e12f46be4464736f6c63430008110033416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c656460a06040523480156200001157600080fd5b506040516200161138038062001611833981810160405281019062000037919062000370565b620000576200004b620000dc60201b60201c565b620000e460201b60201c565b816040516200006690620002f8565b620000729190620003c8565b604051809103906000f0801580156200008f573d6000803e3d6000fd5b5073ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff1681525050620000d481620001a860201b60201c565b505062000500565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b620001b86200023e60201b60201c565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036200022a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040162000221906200046c565b60405180910390fd5b6200023b81620000e460201b60201c565b50565b6200024e620000dc60201b60201c565b73ffffffffffffffffffffffffffffffffffffffff1662000274620002cf60201b60201c565b73ffffffffffffffffffffffffffffffffffffffff1614620002cd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620002c490620004de565b60405180910390fd5b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6109cf8062000c4283390190565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600062000338826200030b565b9050919050565b6200034a816200032b565b81146200035657600080fd5b50565b6000815190506200036a816200033f565b92915050565b600080604083850312156200038a576200038962000306565b5b60006200039a8582860162000359565b9250506020620003ad8582860162000359565b9150509250929050565b620003c2816200032b565b82525050565b6000602082019050620003df6000830184620003b7565b92915050565b600082825260208201905092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b600062000454602683620003e5565b91506200046182620003f6565b604082019050919050565b60006020820190508181036000830152620004878162000445565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b6000620004c6602083620003e5565b9150620004d3826200048e565b602082019050919050565b60006020820190508181036000830152620004f981620004b7565b9050919050565b6080516107186200052a6000396000818161010d0152818161019b01526101c101526107186000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063025b22bc1461006757806359659e90146100835780635c60da1b146100a1578063715018a6146100bf5780638da5cb5b146100c9578063f2fde38b146100e7575b600080fd5b610081600480360381019061007c91906104c0565b610103565b005b61008b610199565b604051610098919061054c565b60405180910390f35b6100a96101bd565b6040516100b69190610576565b60405180910390f35b6100c7610253565b005b6100d1610267565b6040516100de9190610576565b60405180910390f35b61010160048036038101906100fc91906104c0565b610290565b005b61010b610313565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16633659cfe6826040518263ffffffff1660e01b81526004016101649190610576565b600060405180830381600087803b15801561017e57600080fd5b505af1158015610192573d6000803e3d6000fd5b5050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561022a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061024e91906105a6565b905090565b61025b610313565b6102656000610391565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b610298610313565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610307576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102fe90610656565b60405180910390fd5b61031081610391565b50565b61031b610455565b73ffffffffffffffffffffffffffffffffffffffff16610339610267565b73ffffffffffffffffffffffffffffffffffffffff161461038f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610386906106c2565b60405180910390fd5b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061048d82610462565b9050919050565b61049d81610482565b81146104a857600080fd5b50565b6000813590506104ba81610494565b92915050565b6000602082840312156104d6576104d561045d565b5b60006104e4848285016104ab565b91505092915050565b6000819050919050565b600061051261050d61050884610462565b6104ed565b610462565b9050919050565b6000610524826104f7565b9050919050565b600061053682610519565b9050919050565b6105468161052b565b82525050565b6000602082019050610561600083018461053d565b92915050565b61057081610482565b82525050565b600060208201905061058b6000830184610567565b92915050565b6000815190506105a081610494565b92915050565b6000602082840312156105bc576105bb61045d565b5b60006105ca84828501610591565b91505092915050565b600082825260208201905092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006106406026836105d3565b915061064b826105e4565b604082019050919050565b6000602082019050818103600083015261066f81610633565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006106ac6020836105d3565b91506106b782610676565b602082019050919050565b600060208201905081810360008301526106db8161069f565b905091905056fea264697066735822122095b197990bf5a1790e1c76ee8974c6e7fc44751e1fa2c4b2413161207dd13f6d64736f6c63430008110033608060405234801561001057600080fd5b506040516109cf3803806109cf8339818101604052810190610032919061024b565b61004e61004361006360201b60201c565b61006b60201b60201c565b61005d8161012f60201b60201c565b5061031b565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b610142816101c560201b61021b1760201c565b610181576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610178906102fb565b60405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610218826101ed565b9050919050565b6102288161020d565b811461023357600080fd5b50565b6000815190506102458161021f565b92915050565b600060208284031215610261576102606101e8565b5b600061026f84828501610236565b91505092915050565b600082825260208201905092915050565b7f5570677261646561626c65426561636f6e3a20696d706c656d656e746174696f60008201527f6e206973206e6f74206120636f6e747261637400000000000000000000000000602082015250565b60006102e5603383610278565b91506102f082610289565b604082019050919050565b60006020820190508181036000830152610314816102d8565b9050919050565b6106a58061032a6000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80633659cfe61461005c5780635c60da1b14610078578063715018a6146100965780638da5cb5b146100a0578063f2fde38b146100be575b600080fd5b61007660048036038101906100719190610477565b6100da565b005b610080610131565b60405161008d91906104b3565b60405180910390f35b61009e61015b565b005b6100a861016f565b6040516100b591906104b3565b60405180910390f35b6100d860048036038101906100d39190610477565b610198565b005b6100e261023e565b6100eb816102bc565b8073ffffffffffffffffffffffffffffffffffffffff167fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b60405160405180910390a250565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b61016361023e565b61016d6000610348565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6101a061023e565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361020f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161020690610551565b60405180910390fd5b61021881610348565b50565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b61024661040c565b73ffffffffffffffffffffffffffffffffffffffff1661026461016f565b73ffffffffffffffffffffffffffffffffffffffff16146102ba576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102b1906105bd565b60405180910390fd5b565b6102c58161021b565b610304576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102fb9061064f565b60405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061044482610419565b9050919050565b61045481610439565b811461045f57600080fd5b50565b6000813590506104718161044b565b92915050565b60006020828403121561048d5761048c610414565b5b600061049b84828501610462565b91505092915050565b6104ad81610439565b82525050565b60006020820190506104c860008301846104a4565b92915050565b600082825260208201905092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b600061053b6026836104ce565b9150610546826104df565b604082019050919050565b6000602082019050818103600083015261056a8161052e565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006105a76020836104ce565b91506105b282610571565b602082019050919050565b600060208201905081810360008301526105d68161059a565b9050919050565b7f5570677261646561626c65426561636f6e3a20696d706c656d656e746174696f60008201527f6e206973206e6f74206120636f6e747261637400000000000000000000000000602082015250565b60006106396033836104ce565b9150610644826105dd565b604082019050919050565b600060208201905081810360008301526106688161062c565b905091905056fea2646970667358221220c89b6a61b644ec4a3d9e842c0121a7093e4a93ea650998ef9857cb2969c9db1164736f6c63430008110033a2646970667358221220746e914c786f726183722b23d4828434d82d4cd6e2d5d73f6683a0f87b5d96b264736f6c63430008110033
Verified Source Code Partial Match
Compiler: v0.8.17+commit.8df45f5f
EVM: london
Optimization: No
RainCollateral.sol 168 lines
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.17;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./interfaces/IRainCollateralFactory.sol";
using SafeERC20 for IERC20;
/**
* @title Collateral contract
* @notice Used to deposit assets as collateral.
* Withdrawal and liquidation are done by RainCollateralController contract.
* Admins can withdraw and make payment by RainCollateralController contract.
* Owner can add/remove admin.
*/
contract RainCollateral is Initializable, Ownable {
/// @notice name of collateral
string public name;
/// @notice RainCollateralFactory Address
/// It is used to get controller address held in factory
address public factory;
/// @notice Admins Of this contracts.
/// They will be checked from RainCollateralController._isCollateralAdmin
address[] public admins;
/// @notice Maximum number of admins
uint8 public constant MAX_ADMINS = 30;
/// @notice Used to authorize transactions from RainCollateralController contract only
modifier onlyController() {
require(_getController() == msg.sender, "Unauthorized");
_;
}
/// @notice Revert if address param is 0x0
modifier validAddress(address _address) {
require(_address != address(0), "Address Zero");
_;
}
/// @notice Prevent the implementation contract from being used
constructor() {
_disableInitializers();
}
/**
* @notice Used to initialize this contract
* @param _name name of collateral
* @param _owner address of collateral owner
* also becomes the first admin
*/
function initialize(string memory _name, address _owner)
public
validAddress(_owner)
initializer
{
_transferOwnership(_owner);
name = _name;
factory = msg.sender;
admins.push(_owner);
}
/**
* @notice Check if _address is admin of this contract
* @param _address address to check
* @return status If true => is admin
*/
function isAdmin(address _address) public view returns (bool) {
// It is expected that the number of admins would be around 1~5
for (uint256 i = 0; i < admins.length; i++) {
if (admins[i] == _address) {
return true;
}
}
return false;
}
/**
* @notice Used to add a collateral admin
* @dev only admin can call this function
* @param _admin new admin address
*/
function addAdmin(address _admin) external validAddress(_admin) onlyOwner {
require(admins.length < MAX_ADMINS, "Max admins");
(bool found, ) = _getAdminIndex(_admin);
require(!found, "Admin already exists");
admins.push(_admin);
}
/**
* @notice Used to remove a collateral admin
* @dev only admin can call this function
* @param _admin admin address to be removed
*/
function removeAdmin(address _admin)
external
validAddress(_admin)
onlyOwner
{
require(admins.length > 1, "Last admin");
(bool found, uint256 index) = _getAdminIndex(_admin);
require(found, "Admin not found");
admins[index] = admins[admins.length - 1];
admins.pop();
}
/**
* @notice Used to withdraw asset that this contract owns.
* @dev only active RainCollateralController can call this function
* @param _recipient recipient address
* @param _amount withdrawed amount
*/
function withdrawAsset(
address _asset,
address _recipient,
uint256 _amount
) external onlyController {
IERC20(_asset).safeTransfer(_recipient, _amount);
}
/**
* @notice Used to get admin index from admins array
* @dev Internal view function
* @param _admin querying admin address
* @return found if index is found or not
* @return index admin address if found
*/
function _getAdminIndex(address _admin)
internal
view
returns (bool found, uint256 index)
{
// It is expected that the number of admins would be around 1~5
for (uint256 i = 0; i < admins.length; i++) {
if (admins[i] == _admin) {
return (true, i);
}
}
// Index value 0 is meaningless here as admin was not found
return (false, 0);
}
/**
* @notice Used to get RainCollateralController contract address
* @dev Internal function used to interact with RainCollateralController contract
* @return address RainCollateralController contract address
*/
function _getController() internal view returns (address) {
// Controller address is kept in RainCollateralFactory
return IRainCollateralFactory(factory).controller();
}
/**
* @notice Block renounceOwnership
* @dev Prevent assets to be stuck in the contract without an owner
*/
function renounceOwnership() public virtual override onlyOwner {
revert("Cannot renounce ownership");
}
}
RainCollateralBeacon.sol 46 lines
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.17;
import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
import "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title RainCollateralBeacon contract
* @notice Wrapper of beacon contract to RainCollateral implementation contract
* @dev Used to update the implementation of all RainCollateral contracts
* generated by RainCollateralFactory in a single transaction.
* Using beacon proxy pattern that RainCollateral contracts(proxies) points to this contract,
* while this contract points to the current implementation of RainCollateral.
* https://docs.openzeppelin.com/contracts/3.x/api/proxy#BeaconProxy
*/
contract RainCollateralBeacon is IBeacon, Ownable {
/// @notice Holds reference to beacon contract
UpgradeableBeacon public immutable beacon;
/**
* @notice Used to initialize
* @param _initialImplementation initial RainCollateral implementation contract address
* @param _owner owner of this contract, Rain company
*/
constructor(address _initialImplementation, address _owner) {
beacon = new UpgradeableBeacon(_initialImplementation);
transferOwnership(_owner);
}
/**
* @notice update RainCollateral implementation
* @dev will update implementation of multiple RainCollateral contracts
*/
function updateImplementation(address _newImplementation) public onlyOwner {
beacon.upgradeTo(_newImplementation);
}
/**
* @notice get RainCollateral implementation contract address
* @return address of implementation contract saved in beacon
*/
function implementation() public view returns (address) {
return beacon.implementation();
}
}
RainCollateralFactory.sol 112 lines
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.17;
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";
import "./RainCollateralBeacon.sol";
import "./RainCollateral.sol";
/**
* @title RainCollateralFactory Contract
* @notice Used to create user RainCollateral contracts.
Also RainCollateralController address is saved here so that
RainCollateral contracts can find which controller address has the permission
to run logical functions.
* @dev This is an upgradable contract
*/
contract RainCollateralFactory is OwnableUpgradeable {
RainCollateralBeacon public beacon;
/// @notice RainCollateralController address,
/// working as beacon from RainCollateral to RainCollateralController
address public controller;
/// @notice RainCollateral contract address array
address[] public collateralProxies;
/// @notice Emitted when a new RainCollateral contract is deployed
event NewRainCollateral(
address indexed _collateralProxy,
string _name,
address _user
);
/// @notice Revert if address param is 0x0
modifier validAddress(address _address) {
require(_address != address(0), "Address Zero");
_;
}
/**
* @notice Used to initialize
* @param _controller RainCollateralController address
*/
function initialize(address _controller, address _initialImplementation)
public
initializer
validAddress(_controller)
validAddress(_initialImplementation)
{
__Ownable_init();
controller = _controller;
beacon = new RainCollateralBeacon(_initialImplementation, owner());
}
/**
* @notice Used to update RainCollateralController address
* @dev Only owner can call this function
* @param _controller new RainCollateralController address
*/
function updateController(address _controller)
external
onlyOwner
validAddress(_controller)
{
controller = _controller;
}
/**
* @notice Used to deploy a new RainCollateral contract
* @dev owner deploys a new RainCollateral contract for this user
* @param _name collateral name
* @param _user user address
* @return collateralProxyAddress new RainCollateral address
*/
function createCollateralContract(string memory _name, address _user)
external
onlyOwner
returns (address collateralProxyAddress)
{
BeaconProxy collateralProxy = new BeaconProxy(
address(beacon),
abi.encodeWithSelector(
RainCollateral.initialize.selector,
_name,
_user
)
);
collateralProxyAddress = address(collateralProxy);
collateralProxies.push(collateralProxyAddress);
emit NewRainCollateral(collateralProxyAddress, _name, _user);
}
/**
* @notice Get the address of the beacon contract
* to the RainCollateral implementation contract
* @dev actual implementation contract address can be retrieved by getImplementation function
* @return address of the becon contract
*/
function getBeacon() public view returns (address) {
return address(beacon);
}
/**
* @notice Get the address of RainCollateral implementation contract
* @dev Retrived via beacon contract
* @return address of RainCollateral implementation contract
*/
function getImplementation() public view returns (address) {
return beacon.implementation();
}
}
Proxy.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol)
pragma solidity ^0.8.0;
/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_fallback();
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive() external payable virtual {
_fallback();
}
/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
* If overridden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {}
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
StorageSlot.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.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);
}
IRainCollateralFactory.sol 6 lines
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.17;
interface IRainCollateralFactory {
function controller() external view returns (address);
}
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
BeaconProxy.sol 61 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/beacon/BeaconProxy.sol)
pragma solidity ^0.8.0;
import "./IBeacon.sol";
import "../Proxy.sol";
import "../ERC1967/ERC1967Upgrade.sol";
/**
* @dev This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}.
*
* The beacon address is stored in storage slot `uint256(keccak256('eip1967.proxy.beacon')) - 1`, so that it doesn't
* conflict with the storage layout of the implementation behind the proxy.
*
* _Available since v3.4._
*/
contract BeaconProxy is Proxy, ERC1967Upgrade {
/**
* @dev Initializes the proxy with `beacon`.
*
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This
* will typically be an encoded function call, and allows initializing the storage of the proxy like a Solidity
* constructor.
*
* Requirements:
*
* - `beacon` must be a contract with the interface {IBeacon}.
*/
constructor(address beacon, bytes memory data) payable {
_upgradeBeaconToAndCall(beacon, data, false);
}
/**
* @dev Returns the current beacon address.
*/
function _beacon() internal view virtual returns (address) {
return _getBeacon();
}
/**
* @dev Returns the current implementation address of the associated beacon.
*/
function _implementation() internal view virtual override returns (address) {
return IBeacon(_getBeacon()).implementation();
}
/**
* @dev Changes the proxy to use a new beacon. Deprecated: see {_upgradeBeaconToAndCall}.
*
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon.
*
* Requirements:
*
* - `beacon` must be a contract.
* - The implementation returned by `beacon` must be a contract.
*/
function _setBeacon(address beacon, bytes memory data) internal virtual {
_upgradeBeaconToAndCall(beacon, data, false);
}
}
draft-IERC1822.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-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;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
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");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
ERC1967Upgrade.sol 185 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeacon.sol";
import "../../interfaces/draft-IERC1822.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*
* @custom:oz-upgrades-unsafe-allow delegatecall
*/
abstract contract ERC1967Upgrade {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Emitted when the beacon is upgraded.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(
address newBeacon,
bytes memory data,
bool forceCall
) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
}
UpgradeableBeacon.sol 65 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/UpgradeableBeacon.sol)
pragma solidity ^0.8.0;
import "./IBeacon.sol";
import "../../access/Ownable.sol";
import "../../utils/Address.sol";
/**
* @dev This contract is used in conjunction with one or more instances of {BeaconProxy} to determine their
* implementation contract, which is where they will delegate all function calls.
*
* An owner is able to change the implementation the beacon points to, thus upgrading the proxies that use this beacon.
*/
contract UpgradeableBeacon is IBeacon, Ownable {
address private _implementation;
/**
* @dev Emitted when the implementation returned by the beacon is changed.
*/
event Upgraded(address indexed implementation);
/**
* @dev Sets the address of the initial implementation, and the deployer account as the owner who can upgrade the
* beacon.
*/
constructor(address implementation_) {
_setImplementation(implementation_);
}
/**
* @dev Returns the current implementation address.
*/
function implementation() public view virtual override returns (address) {
return _implementation;
}
/**
* @dev Upgrades the beacon to a new implementation.
*
* Emits an {Upgraded} event.
*
* Requirements:
*
* - msg.sender must be the owner of the contract.
* - `newImplementation` must be a contract.
*/
function upgradeTo(address newImplementation) public virtual onlyOwner {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Sets the implementation contract address for this beacon
*
* Requirements:
*
* - `newImplementation` must be a contract.
*/
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "UpgradeableBeacon: implementation is not a contract");
_implementation = newImplementation;
}
}
AddressUpgradeable.sol 219 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return 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 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);
}
}
}
ContextUpgradeable.sol 37 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
OwnableUpgradeable.sol 95 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
Initializable.sol 165 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Internal function that returns the initialized version. Returns `_initialized`
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Internal function that returns the initialized version. Returns `_initializing`
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-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
beacon 0x59659e90 → address
collateralProxies 0x66d8cc25 → address
controller 0xf77c4791 → address
getBeacon 0x2d6b3a6b → address
getImplementation 0xaaf10f42 → address
owner 0x8da5cb5b → address
Write Contract 5 functions
These functions modify contract state and require a wallet transaction to execute.
createCollateralContract 0x0ef52d0c
string _name
address _user
returns: address
initialize 0x485cc955
address _controller
address _initialImplementation
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner
updateController 0x06cb5b66
address _controller
Recent Transactions
No transactions found for this address