Forkchoice Ethereum Mainnet

Address Contract Partially Verified

Address 0xF6A8E47daEEdDcCe297e7541523e27DF2f167BF3
Balance 0 ETH
Nonce 1
Code Size 21674 bytes
Indexed Transactions 0 (1 on-chain, 1.6% indexed)
External Etherscan · Sourcify

Contract Bytecode

21674 bytes
Copy Bytecode
0x60806040523480156200001157600080fd5b5060043610620004a85760003560e01c80637c9b8e89116200026d578063c5bbffe81162000159578063ed0aa42811620000d5578063f2fde38b1162000093578063f2fde38b146200091f578063f3ae6c5f1462000936578063f67ed448146200094d578063f98bea151462000964578063ffa64225146200097b57620004a8565b8063ed0aa42814620008b9578063ee27c68914620008d0578063ee5150b314620008da578063f00f9a0914620008f1578063f2220416146200090857620004a8565b8063d689107c1162000123578063d689107c146200087a578063dd58b41c1462000884578063e67ce706146200088e578063eab5d20e14620008a5578063ec2fd46d14620008af57620004a8565b8063c5bbffe81462000852578063c6b73cf9146200085c578063d47eaa371462000866578063d4b97046146200087057620004a8565b8063aa06ce9b11620001e9578063bc7d679d11620001b3578063bc7d679d1462000806578063c0a5f6ff1462000810578063c0ffa1781462000827578063c3a2a6651462000831578063c59203af146200084857620004a8565b8063aa06ce9b14620007d1578063ab44a7a314620007e8578063ac1fbc9814620007f2578063b2094fd314620007fc57620004a8565b80639299eb3011620002375780639299eb30146200076b578063947cf92b146200078257806395faa5f61462000799578063a2801e1614620007b0578063a598aca714620007c757620004a8565b80637c9b8e8914620007365780638456db1514620007405780638a8c523c146200074a5780638dae7333146200075457620004a8565b806336a53bbb11620003995780635bb7552a11620003155780636ec6a58d11620002d35780636ec6a58d14620006ea57806373a2ab7c14620006f4578063796da7af14620006fe5780637adbf97314620007085780637aed942d146200071f57620004a8565b80635bb7552a14620006755780635f179f64146200068c578063648a4fac14620006a357806367de8be914620006ad57806368be20ad14620006c457620004a8565b80634322ec8311620003635780634322ec8314620006435780634a248d2a146200064d5780634de4527e14620006575780634e71e0c8146200066157806354fd4d50146200066b57620004a8565b806336a53bbb146200060157806336ac41a81462000618578063387b0c1114620006225780633960f142146200063957620004a8565b806316048bc411620004295780631e34b9cc11620003f35780631e34b9cc14620005b55780631f3c156e14620005cc578063245c968514620005d657806327bed8ee14620005e05780632aa82c6514620005f757620004a8565b806316048bc4146200056257806317700f01146200057b57806317be952e146200058557806318c0bbe4146200059e57620004a8565b80630e6518e911620004775780630e6518e91462000516578063108db74414620005205780631184d8be146200053757806313c57624146200054157806313ea5d29146200054b57620004a8565b806304512dc414620004ad5780630923160214620004dc5780630c9f7bd014620004f55780630cd1667d146200050c575b600080fd5b620004c4620004be36600462003b8a565b62000995565b604051620004d39190620043e0565b60405180910390f35b620004f3620004ed36600462003ca7565b62000b1b565b005b620004c46200050636600462003ca7565b62000ba0565b620004c462000c95565b620004c462000d1c565b620004c46200053136600462003c58565b62000d22565b620004f362000f19565b620004f362000f88565b620004f36200055c36600462003b8a565b62000fda565b6200056c62001029565b604051620004d3919062003d97565b620004f362001038565b6200058f6200108a565b604051620004d3919062003e61565b620004c4620005af36600462003ca7565b62001093565b620004c4620005c636600462003b8a565b620010ac565b620004f3620011f9565b620004c462001357565b620004c4620005f136600462003ca7565b6200135d565b620004c462001371565b620004c46200061236600462003b8a565b620013b7565b620004f36200141e565b620004f36200063336600462003ca7565b6200148d565b6200056c620014f4565b6200056c62001503565b6200056c62001512565b620004c462001521565b620004f362001527565b620004c4620015b8565b620004f36200068636600462003ca7565b620015bd565b620004c46200069d36600462003c58565b6200163a565b620004f362001799565b620004f3620006be36600462003ca7565b620018c9565b620006db620006d536600462003b8a565b62001942565b604051620004d3919062003de8565b620006db62001957565b6200056c62001967565b620004c462001976565b620004f36200071936600462003b8a565b620019bc565b620004c46200073036600462003b8a565b62001a0b565b620004c462001a92565b6200056c62001a98565b620004f362001aa7565b620004c46200076536600462003cd9565b62001b16565b620004f36200077c36600462003b8a565b62001daa565b620004c46200079336600462003c58565b62001df9565b620004c4620007aa36600462003b8a565b62001fb2565b620004c4620007c136600462003ca7565b62001ff7565b620006db62002004565b620004c4620007e236600462003c58565b62002014565b620004c462002155565b6200056c6200215b565b620004c46200216a565b620004f362002170565b620004c46200082136600462003ca7565b620021c2565b620004c4620021d0565b620004f36200084236600462003c58565b620021d6565b620004c4620023c5565b620006db620023d2565b620004c4620023e2565b620004c4620023e8565b6200056c620023f5565b6200056c62002404565b620006db62002413565b620004c46200089f36600462003cd9565b62002423565b620004c462002693565b620004c462002699565b620004f3620008ca36600462003ca7565b6200269f565b620004c4620026f6565b620004c4620008eb36600462003ca7565b62002807565b620004f36200090236600462003ba8565b620028b6565b620004f36200091936600462003ca7565b62002ab8565b620004f36200093036600462003b8a565b62002b31565b620004c46200094736600462003ca7565b62002be2565b620004c46200095e36600462003b8a565b62002bf0565b620004c46200097536600462003ca7565b62002c23565b6200098562002c31565b604051620004d3929190620043f9565b600154600090600160a01b900460ff1615620009ce5760405162461bcd60e51b8152600401620009c59062003f83565b60405180910390fd5b6001805460ff60a01b1916600160a01b1790556000620009ee33620013b7565b90506000620009fd3362002bf0565b9050600062000a0c8362000ba0565b90508281111562000a315760405162461bcd60e51b8152600401620009c59062004178565b600d5462000a46908463ffffffff62002d0616565b600d5562000a55338362002d31565b62000a728562000a6c858463ffffffff62002d0616565b62002d9d565b62000a7d8162002dd8565b846001600160a01b0316336001600160a01b0316600080516020620054358339815191526000868660405162000ab69392919062003e03565b60405180910390a3336001600160a01b03166000805160206200545583398151915260008360405162000aeb92919062003df3565b60405180910390a262000b05838263ffffffff62002d0616565b6001805460ff60a01b1916905595945050505050565b6003546001600160a01b031633148062000b3f57506000546001600160a01b031633145b62000b5e5760405162461bcd60e51b8152600401620009c5906200406b565b7f808f99cfd15f1be6019f93dc76c81d5bd82e0b3e0b3d23a54f5a2e647a6cc3cc6002548260405162000b93929190620043f9565b60405180910390a1600255565b6000600f5482111562000bc75760405162461bcd60e51b8152600401620009c59062003e76565b6002600b5460ff16600281111562000bdb57fe5b141562000c8c57600062000bfd600c54600e5462002d0690919063ffffffff16565b9050600062000c0b62001976565b9050600062000c1b838362002e30565b9050600062000c30600f54600a548462002e5d565b9050600062000c5962000c4f88600f5462002d0690919063ffffffff16565b600a548562002e5d565b905062000c7f62000c71828963ffffffff62002f1416565b839063ffffffff62002d0616565b9550505050505062000c90565b5060005b919050565b601054604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd916004808301926020929190829003018186803b15801562000cdb57600080fd5b505afa15801562000cf0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000d16919062003cc0565b90505b90565b60135481565b600154600090600160a01b900460ff161562000d525760405162461bcd60e51b8152600401620009c59062003f83565b6001805460ff60a01b1916600160a01b179055600062000d7162002c31565b915050600062000d8062001371565b90506000811162000da55760405162461bcd60e51b8152600401620009c59062003fa6565b600062000dcb8362000dbe878563ffffffff62002f4316565b9063ffffffff62002f8316565b905062000dd83362002bf0565b81111562000dfa5760405162461bcd60e51b8152600401620009c59062004028565b600062000e078662000ba0565b905085811062000e2b5760405162461bcd60e51b8152600401620009c59062004178565b600d5462000e40908763ffffffff62002d0616565b600d5562000e4f338362002d31565b62000e668762000a6c888463ffffffff62002d0616565b62000e718162002dd8565b6001600160a01b0387163360008051602062005435833981519152600062000ea08a8663ffffffff62002d0616565b8660405162000eb29392919062003e03565b60405180910390a3336001600160a01b03166000805160206200545583398151915260008360405162000ee792919062003df3565b60405180910390a262000f01868263ffffffff62002d0616565b6001805460ff60a01b19169055979650505050505050565b6000546001600160a01b0316331462000f465760405162461bcd60e51b8152600401620009c590620041ea565b600154600160b01b900460ff161562000f735760405162461bcd60e51b8152600401620009c590620041a0565b6001805460ff60c01b1916600160c01b179055565b6003546001600160a01b031633148062000fac57506000546001600160a01b031633145b62000fcb5760405162461bcd60e51b8152600401620009c5906200406b565b6001805460ff60c01b19169055565b6000546001600160a01b03163314620010075760405162461bcd60e51b8152600401620009c590620041ea565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031681565b6003546001600160a01b03163314806200105c57506000546001600160a01b031633145b6200107b5760405162461bcd60e51b8152600401620009c5906200406b565b6001805460ff60c81b19169055565b600b5460ff1681565b6000620010a08262002fb5565b50939695505050505050565b600154600090600160a01b900460ff1615620010dc5760405162461bcd60e51b8152600401620009c59062003f83565b6001805460ff60a01b1916600160a01b1790556000620010fc3362001fb2565b905060006200110b3362001a0b565b905060006200111a8362002807565b9050828111156200113f5760405162461bcd60e51b8152600401620009c59062004178565b600c5462001154908463ffffffff62002d0616565b600c5562001163338362003136565b62001180856200117a858463ffffffff62002d0616565b6200316a565b6200118b81620031a5565b846001600160a01b0316336001600160a01b03166000805160206200543583398151915260018686604051620011c49392919062003e03565b60405180910390a3336001600160a01b03166000805160206200545583398151915260018360405162000aeb92919062003df3565b600154600160a01b900460ff1615620012265760405162461bcd60e51b8152600401620009c59062003f83565b6001805460ff60a01b1916600160a01b1790819055600160b01b900460ff16620012645760405162461bcd60e51b8152600401620009c590620043b7565b3360009081526014602052604090205460ff1615620012975760405162461bcd60e51b8152600401620009c5906200438e565b336000818152601460205260408120805460ff1916600117905590620012cb90620012c29062001a0b565b60125462002e30565b90506000620012e7620012de3362002bf0565b60135462002e30565b9050620012f533826200316a565b62001301338362002d9d565b336001600160a01b03167fbe5f7fe66d16c6a87bb5b8b08a96634fe4f1c2bac9e5e413efe41a782d4d0c4382846040516200133e929190620043f9565b60405180910390a250506001805460ff60a01b19169055565b600d5481565b60006200136b338362002014565b92915050565b601154604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd916004808301926020929190829003018186803b15801562000cdb57600080fd5b600080620013c462001371565b90506000620013d262002c31565b91505081620013e75760009250505062000c90565b62001416826200140983620013fc8862002bf0565b9063ffffffff62002f4316565b9063ffffffff620031f216565b949350505050565b6000546001600160a01b031633146200144b5760405162461bcd60e51b8152600401620009c590620041ea565b600154600160b01b900460ff1615620014785760405162461bcd60e51b8152600401620009c590620041a0565b6001805460ff60b81b1916600160b81b179055565b600154600160a01b900460ff1615620014ba5760405162461bcd60e51b8152600401620009c59062003f83565b6001805460ff60a01b1916600160a01b179055620014d9338262003220565b620014e48162002dd8565b506001805460ff60a01b19169055565b6003546001600160a01b031681565b6004546001600160a01b031681565b6005546001600160a01b031681565b60025481565b6001546001600160a01b03163314620015545760405162461bcd60e51b8152600401620009c59062003eca565b600154600080546040516001600160a01b0393841693909116917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a360018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b606490565b6000546001600160a01b03163314620015ea5760405162461bcd60e51b8152600401620009c590620041ea565b7f3ce6ea91adda496b7a0546fa6558e5b52c3a509de6015820efb00ca4020e0a07600854826040516200161f929190620043f9565b60405180910390a160088190556200163662003255565b5050565b600154600090600160a01b900460ff16156200166a5760405162461bcd60e51b8152600401620009c59062003f83565b6001805460ff60a01b1916600160a01b1790819055600160b81b900460ff16620016a85760405162461bcd60e51b8152600401620009c59062003f4c565b6000620016b462002c31565b9150506000620016c362001371565b90508381620016e657620016de858463ffffffff62002f1416565b905062001707565b82156200170757620017048362001409878563ffffffff62002f4316565b90505b62001713338662003220565b6200171f8682620032ea565b600d5462001734908663ffffffff62002f1416565b600d556040516001600160a01b0387169033907f18081cde2fa64894914e1080b98cca17bb6d1acf633e57f6e26ebdb945ad830b906200177b906000908a90879062003e03565b60405180910390a36001805460ff60a01b1916905595945050505050565b6000546001600160a01b03163314620017c65760405162461bcd60e51b8152600401620009c590620041ea565b600154600160b01b900460ff1615620017f35760405162461bcd60e51b8152600401620009c590620041a0565b6001805462ffffff60b81b1960ff60b01b19909116600160b01b1716905560006200181d62000c95565b905060006200182b62001371565b9050600d54600f5411156200186d57600062001855600d54600f5462002d0690919063ffffffff16565b90506200186381846200331e565b6012555062001874565b600f54600d555b600c54600e541115620018b45760006200189c600c54600e5462002d0690919063ffffffff16565b9050620018aa81836200331e565b60135550620018bb565b600e54600c555b5050600b805460ff19169055565b6000546001600160a01b03163314620018f65760405162461bcd60e51b8152600401620009c590620041ea565b7f023a40bebf7ac113f81c3d628073246cf9e0bc49980a9d6a9531498ce9e3dd1c600a54826040516200192b929190620043f9565b60405180910390a1600a8190556200163662003255565b60146020526000908152604090205460ff1681565b600154600160b01b900460ff1681565b6007546001600160a01b031681565b60075460408051634c6afee560e11b815290516000926001600160a01b0316916398d5fdca916004808301926020929190829003018186803b15801562000cdb57600080fd5b6000546001600160a01b03163314620019e95760405162461bcd60e51b8152600401620009c590620041ea565b600780546001600160a01b0319166001600160a01b0392909216919091179055565b6010546040516370a0823160e01b81526000916001600160a01b0316906370a082319062001a3e90859060040162003d97565b60206040518083038186803b15801562001a5757600080fd5b505afa15801562001a6c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200136b919062003cc0565b600f5481565b6001546001600160a01b031681565b6000546001600160a01b0316331462001ad45760405162461bcd60e51b8152600401620009c590620041ea565b600154600160b01b900460ff161562001b015760405162461bcd60e51b8152600401620009c590620041a0565b6001805460ff60c81b1916600160c81b179055565b600154600090600160c81b900460ff1662001b455760405162461bcd60e51b8152600401620009c59062004126565b6002543a111562001b6a5760405162461bcd60e51b8152600401620009c59062004364565b600154600160a01b900460ff161562001b975760405162461bcd60e51b8152600401620009c59062003f83565b6001805460ff60a01b1916600160a01b1790556000808080808062001bbc8b6200333f565b9550955095509550955095508986101562001beb5760405162461bcd60e51b8152600401620009c590620042bc565b62001bf7338762002d9d565b871562001c615760405163301bc67560e11b815233906360378cea9062001c2c906000908f908b908f908f9060040162003e1b565b600060405180830381600087803b15801562001c4757600080fd5b505af115801562001c5c573d6000803e3d6000fd5b505050505b62001c6d338c620034c6565b831562001cd95760045462001c8c906001600160a01b03168562002d9d565b6004546040516001600160a01b03909116907fe4fed5362e2669c70e5da5a18942d1e617d8917f6adc0164d9668bd3a6d0cebe9062001cd090600090889062003df3565b60405180910390a25b81600d541462001ce957600d8290555b80600c541462001cf957600c8190555b82600281111562001d0657fe5b600b5460ff16600281111562001d1857fe5b1462001d3e57600b805484919060ff1916600183600281111562001d3857fe5b02179055505b62001d498562002dd8565b336001600160a01b03167fd8648b6ac54162763c86fd54bf2005af8ecd2f9cb273a5775921fd7f91e17b2d8c8860405162001d86929190620043f9565b60405180910390a250506001805460ff60a01b191690555091979650505050505050565b6000546001600160a01b0316331462001dd75760405162461bcd60e51b8152600401620009c590620041ea565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b600154600090600160a01b900460ff161562001e295760405162461bcd60e51b8152600401620009c59062003f83565b6001805460ff60a01b1916600160a01b179055600062001e4862002c31565b509050600062001e5762000c95565b90506000811162001e7c5760405162461bcd60e51b8152600401620009c59062003ef1565b600062001e958362000dbe878563ffffffff62002f4316565b905062001ea23362001a0b565b81111562001ec45760405162461bcd60e51b8152600401620009c5906200427a565b600062001ed18662002807565b90508581111562001ef65760405162461bcd60e51b8152600401620009c59062004178565b600c5462001f0b908763ffffffff62002d0616565b600c5562001f1a338362003136565b62001f31876200117a888463ffffffff62002d0616565b62001f3c81620031a5565b6001600160a01b0387163360008051602062005435833981519152600162001f6b8a8663ffffffff62002d0616565b8660405162001f7d9392919062003e03565b60405180910390a3336001600160a01b03166000805160206200545583398151915260018360405162000ee792919062003df3565b60008062001fbf62000c95565b9050600062001fcd62002c31565b5090508162001fe25760009250505062000c90565b62001416826200140983620013fc8862001a0b565b6000620010a0826200333f565b600154600160c01b900460ff1681565b600154600090600160a01b900460ff1615620020445760405162461bcd60e51b8152600401620009c59062003f83565b6001805460ff60a01b1916600160a01b1790819055600160c01b900460ff16620020825760405162461bcd60e51b8152600401620009c59062003f15565b60006200208e62002c31565b50905060006200209d62000c95565b90508381620020c057620020b8858463ffffffff62002f1416565b9050620020e1565b8215620020e157620020de8362001409878563ffffffff62002f4316565b90505b620020ed3386620034c6565b620020f98682620034fb565b600c546200210e908663ffffffff62002f1416565b600c556040516001600160a01b0387169033907f18081cde2fa64894914e1080b98cca17bb6d1acf633e57f6e26ebdb945ad830b906200177b906001908a90879062003e03565b60085481565b6011546001600160a01b031681565b600c5481565b6003546001600160a01b03163314806200219457506000546001600160a01b031633145b620021b35760405162461bcd60e51b8152600401620009c5906200406b565b6001805460ff60b81b19169055565b60006200136b338362000d22565b60095481565b6000546001600160a01b03163314620022035760405162461bcd60e51b8152600401620009c590620041ea565b6005546001600160a01b0383811691161415620022d657600e546200222f908263ffffffff62002f1416565b6005546040516370a0823160e01b81526001600160a01b03909116906370a08231906200226190309060040162003d97565b60206040518083038186803b1580156200227a57600080fd5b505afa1580156200228f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620022b5919062003cc0565b1015620022d65760405162461bcd60e51b8152600401620009c590620040ef565b6006546001600160a01b0383811691161415620023a957600f5462002302908263ffffffff62002f1416565b6006546040516370a0823160e01b81526001600160a01b03909116906370a08231906200233490309060040162003d97565b60206040518083038186803b1580156200234d57600080fd5b505afa15801562002362573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002388919062003cc0565b1015620023a95760405162461bcd60e51b8152600401620009c59062003e76565b620016366001600160a01b038316338363ffffffff6200352f16565b600062000d163362000995565b600154600160b81b900460ff1681565b60125481565b600062000d1633620010ac565b6006546001600160a01b031681565b6010546001600160a01b031681565b600154600160c81b900460ff1681565b600154600090600160c81b900460ff16620024525760405162461bcd60e51b8152600401620009c59062004126565b6002543a1115620024775760405162461bcd60e51b8152600401620009c59062004364565b600154600160a01b900460ff1615620024a45760405162461bcd60e51b8152600401620009c59062003f83565b6001805460ff60a01b1916600160a01b17905560008080808080620024c98b62002fb5565b95509550955095509550955089861115620024f85760405162461bcd60e51b8152600401620009c590620042f3565b62002504338c6200316a565b87156200256e5760405163301bc67560e11b815233906360378cea9062002539906001908f908b908f908f9060040162003e1b565b600060405180830381600087803b1580156200255457600080fd5b505af115801562002569573d6000803e3d6000fd5b505050505b6200257a338762003220565b8315620025e65760045462002599906001600160a01b0316856200316a565b6004546040516001600160a01b03909116907fe4fed5362e2669c70e5da5a18942d1e617d8917f6adc0164d9668bd3a6d0cebe90620025dd90600190889062003df3565b60405180910390a25b81600d5414620025f657600d8290555b80600c54146200260657600c8190555b8260028111156200261357fe5b600b5460ff1660028111156200262557fe5b146200264b57600b805484919060ff191660018360028111156200264557fe5b02179055505b6200265685620031a5565b336001600160a01b03167fe93ad76094f247c0dafc1c61adc2187de1ac2738f7a3b49cb20b2263420251a38c8860405162001d86929190620043f9565b600e5481565b600a5481565b600154600160a01b900460ff1615620026cc5760405162461bcd60e51b8152600401620009c59062003f83565b6001805460ff60a01b1916600160a01b179055620026eb3382620034c6565b620014e481620031a5565b60008060006200270562002c31565b90925090506002600b5460ff1660028111156200271e57fe5b1415620027b15760006200275062002747600f5462001409858662002f4390919063ffffffff16565b600f546200331e565b90506200278f62002764600a548362002e30565b600a546200278290670de0b6b3a76400009063ffffffff62002d0616565b9063ffffffff62002f1416565b9050620027a66200279f62001976565b826200331e565b935050505062000d19565b6000620027dc620027d3600e5462001409868762002f4390919063ffffffff16565b600e546200331e565b9050620027f062002764600a548362002e30565b9050620027a66200280062001976565b8262002e30565b6000600e548211156200282e5760405162461bcd60e51b8152600401620009c590620040ef565b6001600b5460ff1660028111156200284257fe5b141562000c8c57600062002864600d54600f5462002d0690919063ffffffff16565b905060006200287262001976565b905060006200288283836200331e565b9050600062002897600e54600a548462002e5d565b9050600062000c5962000c4f88600e5462002d0690919063ffffffff16565b600154600160a81b900460ff1615620028e35760405162461bcd60e51b8152600401620009c590620040c5565b6001805460ff60a81b1916600160a81b179055600080546001600160a01b03808d166001600160a01b031990921691909117808355604051911691907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3600380546001600160a01b038b81166001600160a01b031992831617909255600480548b8416908316179055600580548a84169083161790819055600680548a8516908416179055600780548985169316929092179091556001805460ff60c81b1960ff60b81b1960ff60c01b19909216600160c01b1791909116600160b81b1716600160c81b179055600283905560088690556009859055600a849055600b805460ff19169055604051911690620029fd9062003b64565b62002a09919062003d97565b604051809103906000f08015801562002a26573d6000803e3d6000fd5b50601080546001600160a01b0319166001600160a01b0392831617905560065460405191169062002a579062003b64565b62002a63919062003d97565b604051809103906000f08015801562002a80573d6000803e3d6000fd5b50601180546001600160a01b0319166001600160a01b039290921691909117905562002aab62003255565b5050505050505050505050565b6000546001600160a01b0316331462002ae55760405162461bcd60e51b8152600401620009c590620041ea565b7f6b04da3d58e4b37d99652babb3ea2bc25ce94379bfff3059f03d61b26c59e5536009548260405162002b1a929190620043f9565b60405180910390a160098190556200163662003255565b6000546001600160a01b0316331462002b5e5760405162461bcd60e51b8152600401620009c590620041ea565b6001600160a01b03811662002b875760405162461bcd60e51b8152600401620009c59062004151565b600080546040516001600160a01b03808516939216917fdcf55418cee3220104fef63f979ff3c4097ad240c0c43dcb33ce837748983e6291a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b60006200136b33836200163a565b6011546040516370a0823160e01b81526000916001600160a01b0316906370a082319062001a3e90859060040162003d97565b60006200136b338362001df9565b600f54600e54600091829182600b5460ff16600281111562002c4f57fe5b141562002c6857600c54600d5493509350505062002d02565b6002600b5460ff16600281111562002c7c57fe5b141562002cb457600062002c8f6200358e565b600c5490915062002ca7848363ffffffff62002f1416565b9450945050505062002d02565b6001600b5460ff16600281111562002cc857fe5b141562002cff57600062002cdb620035ff565b905062002cef828263ffffffff62002f1416565b600d549450945050505062002d02565b50505b9091565b60008282111562002d2b5760405162461bcd60e51b8152600401620009c590620040a2565b50900390565b601154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac9062002d65908590859060040162003dcf565b600060405180830381600087803b15801562002d8057600080fd5b505af115801562002d95573d6000803e3d6000fd5b505050505050565b60065462002dbc906001600160a01b0316838363ffffffff6200352f16565b600f5462002dd1908263ffffffff62002d0616565b600f555050565b600d5462002ded908263ffffffff62002f1416565b600d556040517fa259c93818139b6bc90fb80e8feb75122b42edaae49560f81392cf4e1946726e9062002e25908390600090620043e9565b60405180910390a150565b6000670de0b6b3a764000062002e4d848463ffffffff62002f4316565b8162002e5557fe5b049392505050565b60008062002e7d62002e766004620013fc878762002e30565b8662003667565b905062002ea862002ea2670de0b6b3a7640000620013fc848263ffffffff62002f1416565b62003688565b9050600062002ee362002eca83670de0b6b3a764000063ffffffff62002d0616565b62002edd87600263ffffffff62002f4316565b62003667565b905062002f0a8662002f04670de0b6b3a76400008463ffffffff62002f1416565b62002e30565b9695505050505050565b60008282018381101562002f3c5760405162461bcd60e51b8152600401620009c5906200420d565b9392505050565b60008262002f54575060006200136b565b8282028284828162002f6257fe5b041462002f3c5760405162461bcd60e51b8152600401620009c59062004323565b60008062002f928484620031f2565b90508281028403801562002fac575060010190506200136b565b5090506200136b565b60008060008060008062002fc862002c31565b809350819250505062002fde8760085462002e30565b945062002fee8760095462002e30565b935060006200300985620027828a8963ffffffff62002f1416565b90506000600b5460ff1660028111156200301f57fe5b14156200303e57620030328183620036c3565b9650600193506200312c565b6001600b5460ff1660028111156200305257fe5b141562003068576200303281600e54846200370a565b6002600b5460ff1660028111156200307c57fe5b14156200312c5760006200309c600f548562002d0690919063ffffffff16565b90506000620030b784600e5462002d0690919063ffffffff16565b905080831015620030dd57620030d183600f54876200375a565b98506002955062003129565b80831415620030f3578198506000955062003129565b62003122620031146200310d858463ffffffff62002d0616565b86620036c3565b839063ffffffff62002f1416565b9850600195505b50505b5091939550919395565b601054604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac9062002d65908590859060040162003dcf565b60055462003189906001600160a01b0316838363ffffffff6200352f16565b600e546200319e908263ffffffff62002d0616565b600e555050565b600c54620031ba908263ffffffff62002f1416565b600c556040517fa259c93818139b6bc90fb80e8feb75122b42edaae49560f81392cf4e1946726e9062002e25908390600190620043e9565b6000808211620032165760405162461bcd60e51b8152600401620009c59062004000565b81838162002e5557fe5b60065462003240906001600160a01b031683308463ffffffff6200379c16565b600f5462002dd1908263ffffffff62002f1416565b6000670de0b6b3a7640000600a5410620032835760405162461bcd60e51b8152600401620009c59062004346565b6000600a5411620032a85760405162461bcd60e51b8152600401620009c59062003ead565b670de0b6b3a7640000620032ca60095460085462002f1490919063ffffffff16565b1062000d195760405162461bcd60e51b8152600401620009c590620041c5565b6011546040516340c10f1960e01b81526001600160a01b03909116906340c10f199062002d65908590859060040162003dcf565b600062002f3c826200140985670de0b6b3a764000063ffffffff62002f4316565b6000806000806000806200335262002c31565b92509050866000600b5460ff1660028111156200336b57fe5b14156200338a576200337e8184620037c6565b96506002935062003476565b6001600b5460ff1660028111156200339e57fe5b141562003460576000620033be600e548462002d0690919063ffffffff16565b90506000620033d985600f5462002d0690919063ffffffff16565b9050818310156200340c57620033f383600e548662003808565b9850600195508089111562003406578098505b62003458565b8183141562003422578098506000955062003458565b62003451620034436200343c858563ffffffff62002d0616565b87620037c6565b829063ffffffff62002f1416565b9850600295505b505062003476565b6200346f81600f54856200382c565b9650600293505b620034848760085462002e30565b9550620034948760095462002e30565b9450620034ba85620034ad898963ffffffff62002d0616565b9063ffffffff62002d0616565b96505091939550919395565b600554620034e6906001600160a01b031683308463ffffffff6200379c16565b600e546200319e908263ffffffff62002f1416565b6010546040516340c10f1960e01b81526001600160a01b03909116906340c10f199062002d65908590859060040162003dcf565b620035898363a9059cbb60e01b84846040516024016200355192919062003dcf565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915262003863565b505050565b600080620035aa600c54600e5462002d0690919063ffffffff16565b90506000620035b862001976565b90506000620035c8838362002e30565b90506000620035dd600f54600a548462002e5d565b9050620035f6600f548262002d0690919063ffffffff16565b94505050505090565b6000806200361b600d54600f5462002d0690919063ffffffff16565b905060006200362962001976565b905060006200363983836200331e565b905060006200364e600e54600a548462002e5d565b9050620035f6600e548262002d0690919063ffffffff16565b600062002f3c8262000dbe85670de0b6b3a764000063ffffffff62002f4316565b80600160028204015b81811015620036bd57809150600281828581620036aa57fe5b040181620036b457fe5b04905062003691565b50919050565b6000818310620036e75760405162461bcd60e51b8152600401620009c590620040ef565b6000620036fb838563ffffffff62002d0616565b90506200141683848362003927565b60008284106200372e5760405162461bcd60e51b8152600401620009c590620040ef565b600062003742848663ffffffff62002d0616565b90506200375183858362003927565b95945050505050565b6000806200376762001976565b905060006200378884866200377d858a62002e30565b6001600a5462003947565b905062002f0a818663ffffffff62002d0616565b620037c0846323b872dd60e01b858585604051602401620035519392919062003dab565b50505050565b600080620037d362001976565b90506000620037f48485620037e9858962002e30565b6000600a5462003947565b905062003751848263ffffffff62002d0616565b6000806200381d848663ffffffff62002f1416565b90506200375183828662003927565b6000806200383962001976565b905060006200384f8486620037e9858a62002e30565b905062002f0a858263ffffffff62002d0616565b60006060836001600160a01b03168360405162003881919062003d5b565b6000604051808303816000865af19150503d8060008114620038c0576040519150601f19603f3d011682016040523d82523d6000602084013e620038c5565b606091505b509150915081620038ea5760405162461bcd60e51b8152600401620009c59062003fcb565b805115620037c0578080602001905181019062003908919062003c85565b620037c05760405162461bcd60e51b8152600401620009c59062004230565b6000806200393462001976565b90506200375185858584600a5462003ae1565b60008062003960866200140989620013fc878c62002e30565b905060006200398962003982670de0b6b3a76400008663ffffffff62002d0616565b8862002e30565b905060018515620039ae57620039a6828863ffffffff62002f1416565b9150620039c3565b620039c0838863ffffffff62002f1416565b92505b828210620039e957620039dd828463ffffffff62002d0616565b91506001905062003a02565b620039fb838363ffffffff62002d0616565b9150600090505b600062003a3962003a286004620013fc670de0b6b3a76400008a63ffffffff62002d0616565b62002f048c620013fc8a8f62002e30565b905062003a5662002ea28262002782868063ffffffff62002f4316565b9050600062003a7a6002620013fc670de0b6b3a76400008a63ffffffff62002d0616565b90506000831562003a9f5762003a97858463ffffffff62002f1416565b905062003ab4565b62003ab1838663ffffffff62002d0616565b90505b881562003ad55762003ac781836200331e565b965050505050505062003751565b62003ac7818362003667565b60008062003afb8462002f04888863ffffffff62002d0616565b9050600062003b2162003b1a88620014098b8063ffffffff62002f4316565b8762003667565b9050600062003b31858362002e30565b905062003b578362002f048362002782670de0b6b3a76400008a63ffffffff62002d0616565b9998505050505050505050565b61102d806200440883390190565b80356001600160a01b03811681146200136b57600080fd5b60006020828403121562003b9c578081fd5b62002f3c838362003b72565b6000806000806000806000806000806101408b8d03121562003bc8578586fd5b62003bd48c8c62003b72565b995062003be58c60208d0162003b72565b985062003bf68c60408d0162003b72565b975062003c078c60608d0162003b72565b965062003c188c60808d0162003b72565b955062003c298c60a08d0162003b72565b945060c08b0135935060e08b013592506101008b013591506101208b013590509295989b9194979a5092959850565b6000806040838503121562003c6b578182fd5b62003c77848462003b72565b946020939093013593505050565b60006020828403121562003c97578081fd5b8151801515811462002f3c578182fd5b60006020828403121562003cb9578081fd5b5035919050565b60006020828403121562003cd2578081fd5b5051919050565b6000806000806060858703121562003cef578384fd5b8435935060208501359250604085013567ffffffffffffffff8082111562003d15578384fd5b81870188601f82011262003d27578485fd5b803592508183111562003d38578485fd5b88602084830101111562003d4a578485fd5b959894975050602090940194505050565b60008251815b8181101562003d7d576020818601810151858301520162003d61565b8181111562003d8c5782828501525b509190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b9115158252602082015260400190565b92151583526020830191909152604082015260600190565b6000861515825285602083015284604083015260806060830152826080830152828460a084013781830160a090810191909152601f909201601f19160101949350505050565b602081016003831062003e7057fe5b91905290565b6020808252601d908201527f444f444f5f51554f54455f42414c414e43455f4e4f545f454e4f554748000000604082015260600190565b60208082526003908201526204b3d360ec1b604082015260600190565b6020808252600d908201526c494e56414c49445f434c41494d60981b604082015260600190565b6020808252600a908201526904e4f5f424153455f4c560b41b604082015260600190565b60208082526018908201527f4445504f5349545f424153455f4e4f545f414c4c4f5745440000000000000000604082015260600190565b60208082526019908201527f4445504f5349545f51554f54455f4e4f545f414c4c4f57454400000000000000604082015260600190565b60208082526009908201526814915153951490539560ba1b604082015260600190565b6020808252600b908201526a04e4f5f51554f54455f4c560ac1b604082015260600190565b6020808252818101527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604082015260600190565b6020808252600e908201526d2224ab24a224a723afa2a92927a960911b604082015260600190565b60208082526023908201527f4c505f51554f54455f4341504954414c5f42414c414e43455f4e4f545f454e4f6040820152620aa8e960eb1b606082015260800190565b60208082526017908201527f4e4f545f53555045525649534f525f4f525f4f574e4552000000000000000000604082015260600190565b60208082526009908201526829aaa12fa2a92927a960b91b604082015260600190565b60208082526010908201526f1113d113d7d25392551250531256915160821b604082015260600190565b6020808252601c908201527f444f444f5f424153455f42414c414e43455f4e4f545f454e4f55474800000000604082015260600190565b602080825260119082015270151490511157d393d517d0531313d5d151607a1b604082015260600190565b6020808252600d908201526c24a72b20a624a22fa7aba722a960991b604082015260600190565b6020808252600e908201526d1411539053151657d15610d1515160921b604082015260600190565b6020808252600b908201526a1113d113d7d0d313d4d15160aa1b604082015260600190565b6020808252600b908201526a4645455f524154453e3d3160a81b604082015260600190565b6020808252600990820152682727aa2fa7aba722a960b91b604082015260600190565b60208082526009908201526820a2222fa2a92927a960b91b604082015260600190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b60208082526022908201527f4c505f424153455f4341504954414c5f42414c414e43455f4e4f545f454e4f5560408201526108e960f31b606082015260800190565b6020808252601c908201527f53454c4c5f424153455f524543454956455f4e4f545f454e4f55474800000000604082015260600190565b602080825260169082015275084aab2be8482a68abe869ea6a8bea89e9ebe9aaa86960531b604082015260600190565b60208082526009908201526826aaa62fa2a92927a960b91b604082015260600190565b6020808252600490820152634b3e3d3160e01b604082015260600190565b60208082526010908201526f11d054d7d4149250d157d15610d1515160821b604082015260600190565b6020808252600f908201526e1053149150511657d0d31052535151608a1b604082015260600190565b6020808252600f908201526e1113d113d7d393d517d0d313d4d151608a1b604082015260600190565b90815260200190565b9182521515602082015260400190565b91825260208201526040019056fe60c060405260036080819052620444c560ec1b60a0908152620000269160029190620000c6565b503480156200003457600080fd5b506040516200102d3803806200102d83398101604081905262000057916200016b565b600080546001600160a01b03191633178082556040516001600160a01b039190911691907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3600380546001600160a01b0319166001600160a01b03929092169190911790556200019b565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200010957805160ff191683800117855562000139565b8280016001018555821562000139579182015b82811115620001395782518255916020019190600101906200011c565b50620001479291506200014b565b5090565b6200016891905b8082111562000147576000815560010162000152565b90565b6000602082840312156200017d578081fd5b81516001600160a01b038116811462000194578182fd5b9392505050565b610e8280620001ab6000396000f3fe608060405234801561001057600080fd5b50600436106101005760003560e01c80634e71e0c8116100975780639dc29fac116100665780639dc29fac146101dd578063a9059cbb146101f0578063dd62ed3e14610203578063f2fde38b1461021657610100565b80634e71e0c8146101b257806370a08231146101ba5780638456db15146101cd57806395d89b41146101d557610100565b806318160ddd116100d357806318160ddd1461016057806323b872dd14610175578063313ce5671461018857806340c10f191461019d57610100565b806306fdde0314610105578063095ea7b31461012357806313096a411461014357806316048bc414610158575b600080fd5b61010d610229565b60405161011a9190610c89565b60405180910390f35b610136610131366004610b56565b6102f6565b60405161011a9190610c7e565b61014b610361565b60405161011a9190610c6a565b61014b610370565b61016861037f565b60405161011a9190610dcd565b610136610183366004610b16565b610385565b610190610509565b60405161011a9190610dd6565b6101b06101ab366004610b56565b61058b565b005b6101b061068e565b6101686101c8366004610ac7565b61071c565b61014b610737565b61010d610746565b6101b06101eb366004610b56565b6107d1565b6101366101fe366004610b56565b6108c8565b610168610211366004610ae2565b610986565b6101b0610224366004610ac7565b6109b1565b604080518082018252600f81526e5f444f444f5f4c505f544f4b454e5f60881b602082015260035482516306fdde0360e01b815292516060936001600160a01b03909216916306fdde03916004808301926000929190829003018186803b15801561029357600080fd5b505afa1580156102a7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526102cf9190810190610b80565b816040516020016102e1929190610c3c565b60405160208183030381529060405291505090565b3360008181526006602090815260408083206001600160a01b038716808552925280832085905551919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259061034f908690610dcd565b60405180910390a35060015b92915050565b6003546001600160a01b031681565b6000546001600160a01b031681565b60045481565b6001600160a01b0383166000908152600560205260408120548211156103c65760405162461bcd60e51b81526004016103bd90610d5b565b60405180910390fd5b6001600160a01b03841660009081526006602090815260408083203384529091529020548211156104095760405162461bcd60e51b81526004016103bd90610ce3565b6001600160a01b038416600090815260056020526040902054610432908363ffffffff610a5c16565b6001600160a01b038086166000908152600560205260408082209390935590851681522054610467908363ffffffff610a8416565b6001600160a01b0380851660009081526005602090815260408083209490945591871681526006825282812033825290915220546104ab908363ffffffff610a5c16565b6001600160a01b038086166000818152600660209081526040808320338452909152908190209390935591519085169190600080516020610e2d833981519152906104f7908690610dcd565b60405180910390a35060019392505050565b6003546040805163313ce56760e01b815290516000926001600160a01b03169163313ce567916004808301926020929190829003018186803b15801561054e57600080fd5b505afa158015610562573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105869190610c1b565b905090565b6000546001600160a01b031633146105b55760405162461bcd60e51b81526004016103bd90610d87565b6001600160a01b0382166000908152600560205260409020546105de908263ffffffff610a8416565b6001600160a01b03831660009081526005602052604090205560045461060a908263ffffffff610a8416565b6004556040516001600160a01b038316907f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d412139688590610648908490610dcd565b60405180910390a2816001600160a01b031660006001600160a01b0316600080516020610e2d833981519152836040516106829190610dcd565b60405180910390a35050565b6001546001600160a01b031633146106b85760405162461bcd60e51b81526004016103bd90610cbc565b600154600080546040516001600160a01b0393841693909116917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a360018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b6001600160a01b031660009081526005602052604090205490565b6001546001600160a01b031681565b6002805460408051602060018416156101000260001901909316849004601f810184900484028201840190925281815292918301828280156107c95780601f1061079e576101008083540402835291602001916107c9565b820191906000526020600020905b8154815290600101906020018083116107ac57829003601f168201915b505050505081565b6000546001600160a01b031633146107fb5760405162461bcd60e51b81526004016103bd90610d87565b6001600160a01b038216600090815260056020526040902054610824908263ffffffff610a5c16565b6001600160a01b038316600090815260056020526040902055600454610850908263ffffffff610a5c16565b6004556040516001600160a01b038316907fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca59061088e908490610dcd565b60405180910390a260006001600160a01b0316826001600160a01b0316600080516020610e2d833981519152836040516106829190610dcd565b336000908152600560205260408120548211156108f75760405162461bcd60e51b81526004016103bd90610d5b565b33600090815260056020526040902054610917908363ffffffff610a5c16565b33600090815260056020526040808220929092556001600160a01b03851681522054610949908363ffffffff610a8416565b6001600160a01b038416600081815260056020526040908190209290925590513390600080516020610e2d8339815191529061034f908690610dcd565b6001600160a01b03918216600090815260066020908152604080832093909416825291909152205490565b6000546001600160a01b031633146109db5760405162461bcd60e51b81526004016103bd90610d87565b6001600160a01b038116610a015760405162461bcd60e51b81526004016103bd90610d34565b600080546040516001600160a01b03808516939216917fdcf55418cee3220104fef63f979ff3c4097ad240c0c43dcb33ce837748983e6291a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b600082821115610a7e5760405162461bcd60e51b81526004016103bd90610d11565b50900390565b600082820183811015610aa95760405162461bcd60e51b81526004016103bd90610daa565b9392505050565b80356001600160a01b038116811461035b57600080fd5b600060208284031215610ad8578081fd5b610aa98383610ab0565b60008060408385031215610af4578081fd5b610afe8484610ab0565b9150610b0d8460208501610ab0565b90509250929050565b600080600060608486031215610b2a578081fd5b8335610b3581610e14565b92506020840135610b4581610e14565b929592945050506040919091013590565b60008060408385031215610b68578182fd5b610b728484610ab0565b946020939093013593505050565b600060208284031215610b91578081fd5b815167ffffffffffffffff80821115610ba8578283fd5b81840185601f820112610bb9578384fd5b8051925081831115610bc9578384fd5b604051601f8401601f191681016020018381118282101715610be9578586fd5b604052838152818401602001871015610c00578485fd5b610c11846020830160208501610de4565b9695505050505050565b600060208284031215610c2c578081fd5b815160ff81168114610aa9578182fd5b60008351610c4e818460208801610de4565b8351908301610c61828260208801610de4565b01949350505050565b6001600160a01b0391909116815260200190565b901515815260200190565b6000602082528251806020840152610ca8816040850160208701610de4565b601f01601f19169190910160400192915050565b6020808252600d908201526c494e56414c49445f434c41494d60981b604082015260600190565b60208082526014908201527308298989eae829c868abe9c9ea8be8a9c9eaa8e960631b604082015260600190565b60208082526009908201526829aaa12fa2a92927a960b91b604082015260600190565b6020808252600d908201526c24a72b20a624a22fa7aba722a960991b604082015260600190565b6020808252601290820152710848298829c868abe9c9ea8be8a9c9eaa8e960731b604082015260600190565b6020808252600990820152682727aa2fa7aba722a960b91b604082015260600190565b60208082526009908201526820a2222fa2a92927a960b91b604082015260600190565b90815260200190565b60ff91909116815260200190565b60005b83811015610dff578181015183820152602001610de7565b83811115610e0e576000848401525b50505050565b6001600160a01b0381168114610e2957600080fd5b5056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220841bccf74b44eca30e990eb033f46ce3d579e580f6773f839326e8d16131a6b264736f6c63430006090033e89c586bd81ee35a18f7eac22a732b56e589a2821497cce12a0208828540a36d581f351e2bdb9fa9021bb2a24def989f06ac236f8a92aac14bcbc618ddf3826aa2646970667358221220c1e1b62e47948255d166a6fb5548391cda62d6922ddf060330947b348adb869664736f6c63430006090033

Verified Source Code Partial Match

Compiler: v0.6.9+commit.3e3065ac EVM: istanbul Optimization: Yes (200 runs)
DODO.sol 1811 lines
/*

    Copyright 2020 DODO ZOO.
    SPDX-License-Identifier: Apache-2.0

*/

pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;

library Types {
    enum RStatus {ONE, ABOVE_ONE, BELOW_ONE}
}

// File: contracts/intf/IERC20.sol

// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol

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

    function decimals() external view returns (uint8);

    function name() external view returns (string memory);

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

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

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

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

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

// File: contracts/lib/InitializableOwnable.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title Ownable
 * @author DODO Breeder
 *
 * @notice Ownership related functions
 */
contract InitializableOwnable {
    address public _OWNER_;
    address public _NEW_OWNER_;

    // ============ Events ============

    event OwnershipTransferPrepared(address indexed previousOwner, address indexed newOwner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    // ============ Modifiers ============

    modifier onlyOwner() {
        require(msg.sender == _OWNER_, "NOT_OWNER");
        _;
    }

    // ============ Functions ============

    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "INVALID_OWNER");
        emit OwnershipTransferPrepared(_OWNER_, newOwner);
        _NEW_OWNER_ = newOwner;
    }

    function claimOwnership() external {
        require(msg.sender == _NEW_OWNER_, "INVALID_CLAIM");
        emit OwnershipTransferred(_OWNER_, _NEW_OWNER_);
        _OWNER_ = _NEW_OWNER_;
        _NEW_OWNER_ = address(0);
    }
}

// File: contracts/lib/SafeMath.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title SafeMath
 * @author DODO Breeder
 *
 * @notice Math operations with safety checks that revert on error
 */
library SafeMath {
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b, "MUL_ERROR");

        return c;
    }

    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "DIVIDING_ERROR");
        return a / b;
    }

    function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 quotient = div(a, b);
        uint256 remainder = a - quotient * b;
        if (remainder > 0) {
            return quotient + 1;
        } else {
            return quotient;
        }
    }

    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SUB_ERROR");
        return a - b;
    }

    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "ADD_ERROR");
        return c;
    }

    function sqrt(uint256 x) internal pure returns (uint256 y) {
        uint256 z = x / 2 + 1;
        y = x;
        while (z < y) {
            y = z;
            z = (x / z + z) / 2;
        }
    }
}

// File: contracts/lib/DecimalMath.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title DecimalMath
 * @author DODO Breeder
 *
 * @notice Functions for fixed point number with 18 decimals
 */
library DecimalMath {
    using SafeMath for uint256;

    uint256 constant ONE = 10**18;

    function mul(uint256 target, uint256 d) internal pure returns (uint256) {
        return target.mul(d) / ONE;
    }

    function divFloor(uint256 target, uint256 d) internal pure returns (uint256) {
        return target.mul(ONE).div(d);
    }

    function divCeil(uint256 target, uint256 d) internal pure returns (uint256) {
        return target.mul(ONE).divCeil(d);
    }
}

// File: contracts/lib/ReentrancyGuard.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title ReentrancyGuard
 * @author DODO Breeder
 *
 * @notice Protect functions from Reentrancy Attack
 */
contract ReentrancyGuard {
    // https://solidity.readthedocs.io/en/latest/control-structures.html?highlight=zero-state#scoping-and-declarations
    // zero-state of _ENTERED_ is false
    bool private _ENTERED_;

    modifier preventReentrant() {
        require(!_ENTERED_, "REENTRANT");
        _ENTERED_ = true;
        _;
        _ENTERED_ = false;
    }
}

// File: contracts/intf/IOracle.sol

/*

    Copyright 2020 DODO ZOO.

*/

interface IOracle {
    function getPrice() external view returns (uint256);
}

// File: contracts/intf/IDODOLpToken.sol

/*

    Copyright 2020 DODO ZOO.

*/

interface IDODOLpToken {
    function mint(address user, uint256 value) external;

    function burn(address user, uint256 value) external;

    function balanceOf(address owner) external view returns (uint256);

    function totalSupply() external view returns (uint256);
}

// File: contracts/impl/Storage.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title Storage
 * @author DODO Breeder
 *
 * @notice Local Variables
 */
contract Storage is InitializableOwnable, ReentrancyGuard {
    using SafeMath for uint256;

    // ============ Variables for Control ============

    bool internal _INITIALIZED_;
    bool public _CLOSED_;
    bool public _DEPOSIT_QUOTE_ALLOWED_;
    bool public _DEPOSIT_BASE_ALLOWED_;
    bool public _TRADE_ALLOWED_;
    uint256 public _GAS_PRICE_LIMIT_;

    // ============ Core Address ============

    address public _SUPERVISOR_; // could freeze system in emergency
    address public _MAINTAINER_; // collect maintainer fee to buy food for DODO

    address public _BASE_TOKEN_;
    address public _QUOTE_TOKEN_;
    address public _ORACLE_;

    // ============ Variables for PMM Algorithm ============

    uint256 public _LP_FEE_RATE_;
    uint256 public _MT_FEE_RATE_;
    uint256 public _K_;

    Types.RStatus public _R_STATUS_;
    uint256 public _TARGET_BASE_TOKEN_AMOUNT_;
    uint256 public _TARGET_QUOTE_TOKEN_AMOUNT_;
    uint256 public _BASE_BALANCE_;
    uint256 public _QUOTE_BALANCE_;

    address public _BASE_CAPITAL_TOKEN_;
    address public _QUOTE_CAPITAL_TOKEN_;

    // ============ Variables for Final Settlement ============

    uint256 public _BASE_CAPITAL_RECEIVE_QUOTE_;
    uint256 public _QUOTE_CAPITAL_RECEIVE_BASE_;
    mapping(address => bool) public _CLAIMED_;

    // ============ Modifiers ============

    modifier onlySupervisorOrOwner() {
        require(msg.sender == _SUPERVISOR_ || msg.sender == _OWNER_, "NOT_SUPERVISOR_OR_OWNER");
        _;
    }

    modifier notClosed() {
        require(!_CLOSED_, "DODO_CLOSED");
        _;
    }

    // ============ Helper Functions ============

    function _checkDODOParameters() internal view returns (uint256) {
        require(_K_ < DecimalMath.ONE, "K>=1");
        require(_K_ > 0, "K=0");
        require(_LP_FEE_RATE_.add(_MT_FEE_RATE_) < DecimalMath.ONE, "FEE_RATE>=1");
    }

    function getOraclePrice() public view returns (uint256) {
        return IOracle(_ORACLE_).getPrice();
    }

    function getBaseCapitalBalanceOf(address lp) public view returns (uint256) {
        return IDODOLpToken(_BASE_CAPITAL_TOKEN_).balanceOf(lp);
    }

    function getTotalBaseCapital() public view returns (uint256) {
        return IDODOLpToken(_BASE_CAPITAL_TOKEN_).totalSupply();
    }

    function getQuoteCapitalBalanceOf(address lp) public view returns (uint256) {
        return IDODOLpToken(_QUOTE_CAPITAL_TOKEN_).balanceOf(lp);
    }

    function getTotalQuoteCapital() public view returns (uint256) {
        return IDODOLpToken(_QUOTE_CAPITAL_TOKEN_).totalSupply();
    }

    // ============ Version Control ============
    function version() external pure returns (uint256) {
        return 100; // 1.0.0
    }
}

// File: contracts/intf/IDODOCallee.sol

/*

    Copyright 2020 DODO ZOO.

*/

interface IDODOCallee {
    function dodoCall(
        bool isBuyBaseToken,
        uint256 baseAmount,
        uint256 quoteAmount,
        bytes calldata data
    ) external;
}

// File: contracts/lib/DODOMath.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title DODOMath
 * @author DODO Breeder
 *
 * @notice Functions for complex calculating. Including ONE Integration and TWO Quadratic solutions
 */
library DODOMath {
    using SafeMath for uint256;

    /*
        Integrate dodo curve fron V1 to V2
        require V0>=V1>=V2>0
        res = (1-k)i(V1-V2)+ikV0*V0(1/V2-1/V1)
        let V1-V2=delta
        res = i*delta*(1-k+k(V0^2/V1/V2))
    */
    function _GeneralIntegrate(
        uint256 V0,
        uint256 V1,
        uint256 V2,
        uint256 i,
        uint256 k
    ) internal pure returns (uint256) {
        uint256 fairAmount = DecimalMath.mul(i, V1.sub(V2)); // i*delta
        uint256 V0V0V1V2 = DecimalMath.divCeil(V0.mul(V0).div(V1), V2);
        uint256 penalty = DecimalMath.mul(k, V0V0V1V2); // k(V0^2/V1/V2)
        return DecimalMath.mul(fairAmount, DecimalMath.ONE.sub(k).add(penalty));
    }

    /*
        The same with integration expression above, we have:
        i*deltaB = (Q2-Q1)*(1-k+kQ0^2/Q1/Q2)
        Given Q1 and deltaB, solve Q2
        This is a quadratic function and the standard version is
        aQ2^2 + bQ2 + c = 0, where
        a=1-k
        -b=(1-k)Q1-kQ0^2/Q1+i*deltaB
        c=-kQ0^2
        and Q2=(-b+sqrt(b^2+4(1-k)kQ0^2))/2(1-k)
        note: another root is negative, abondan
        if deltaBSig=true, then Q2>Q1
        if deltaBSig=false, then Q2<Q1
    */
    function _SolveQuadraticFunctionForTrade(
        uint256 Q0,
        uint256 Q1,
        uint256 ideltaB,
        bool deltaBSig,
        uint256 k
    ) internal pure returns (uint256) {
        // calculate -b value and sig
        // -b = (1-k)Q1-kQ0^2/Q1+i*deltaB
        uint256 kQ02Q1 = DecimalMath.mul(k, Q0).mul(Q0).div(Q1); // kQ0^2/Q1
        uint256 b = DecimalMath.mul(DecimalMath.ONE.sub(k), Q1); // (1-k)Q1
        bool minusbSig = true;
        if (deltaBSig) {
            b = b.add(ideltaB); // (1-k)Q1+i*deltaB
        } else {
            kQ02Q1 = kQ02Q1.add(ideltaB); // i*deltaB+kQ0^2/Q1
        }
        if (b >= kQ02Q1) {
            b = b.sub(kQ02Q1);
            minusbSig = true;
        } else {
            b = kQ02Q1.sub(b);
            minusbSig = false;
        }

        // calculate sqrt
        uint256 squareRoot = DecimalMath.mul(
            DecimalMath.ONE.sub(k).mul(4),
            DecimalMath.mul(k, Q0).mul(Q0)
        ); // 4(1-k)kQ0^2
        squareRoot = b.mul(b).add(squareRoot).sqrt(); // sqrt(b*b+4(1-k)kQ0*Q0)

        // final res
        uint256 denominator = DecimalMath.ONE.sub(k).mul(2); // 2(1-k)
        uint256 numerator;
        if (minusbSig) {
            numerator = b.add(squareRoot);
        } else {
            numerator = squareRoot.sub(b);
        }

        if (deltaBSig) {
            return DecimalMath.divFloor(numerator, denominator);
        } else {
            return DecimalMath.divCeil(numerator, denominator);
        }
    }

    /*
        Start from the integration function
        i*deltaB = (Q2-Q1)*(1-k+kQ0^2/Q1/Q2)
        Assume Q2=Q0, Given Q1 and deltaB, solve Q0
        let fairAmount = i*deltaB
    */
    function _SolveQuadraticFunctionForTarget(
        uint256 V1,
        uint256 k,
        uint256 fairAmount
    ) internal pure returns (uint256 V0) {
        // V0 = V1+V1*(sqrt-1)/2k
        uint256 sqrt = DecimalMath.divCeil(DecimalMath.mul(k, fairAmount).mul(4), V1);
        sqrt = sqrt.add(DecimalMath.ONE).mul(DecimalMath.ONE).sqrt();
        uint256 premium = DecimalMath.divCeil(sqrt.sub(DecimalMath.ONE), k.mul(2));
        // V0 is greater than or equal to V1 according to the solution
        return DecimalMath.mul(V1, DecimalMath.ONE.add(premium));
    }
}

// File: contracts/impl/Pricing.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title Pricing
 * @author DODO Breeder
 *
 * @notice DODO Pricing model
 */
contract Pricing is Storage {
    using SafeMath for uint256;

    // ============ R = 1 cases ============

    function _ROneSellBaseToken(uint256 amount, uint256 targetQuoteTokenAmount)
        internal
        view
        returns (uint256 receiveQuoteToken)
    {
        uint256 i = getOraclePrice();
        uint256 Q2 = DODOMath._SolveQuadraticFunctionForTrade(
            targetQuoteTokenAmount,
            targetQuoteTokenAmount,
            DecimalMath.mul(i, amount),
            false,
            _K_
        );
        // in theory Q2 <= targetQuoteTokenAmount
        // however when amount is close to 0, precision problems may cause Q2 > targetQuoteTokenAmount
        return targetQuoteTokenAmount.sub(Q2);
    }

    function _ROneBuyBaseToken(uint256 amount, uint256 targetBaseTokenAmount)
        internal
        view
        returns (uint256 payQuoteToken)
    {
        require(amount < targetBaseTokenAmount, "DODO_BASE_BALANCE_NOT_ENOUGH");
        uint256 B2 = targetBaseTokenAmount.sub(amount);
        payQuoteToken = _RAboveIntegrate(targetBaseTokenAmount, targetBaseTokenAmount, B2);
        return payQuoteToken;
    }

    // ============ R < 1 cases ============

    function _RBelowSellBaseToken(
        uint256 amount,
        uint256 quoteBalance,
        uint256 targetQuoteAmount
    ) internal view returns (uint256 receieQuoteToken) {
        uint256 i = getOraclePrice();
        uint256 Q2 = DODOMath._SolveQuadraticFunctionForTrade(
            targetQuoteAmount,
            quoteBalance,
            DecimalMath.mul(i, amount),
            false,
            _K_
        );
        return quoteBalance.sub(Q2);
    }

    function _RBelowBuyBaseToken(
        uint256 amount,
        uint256 quoteBalance,
        uint256 targetQuoteAmount
    ) internal view returns (uint256 payQuoteToken) {
        // Here we don't require amount less than some value
        // Because it is limited at upper function
        // See Trader.queryBuyBaseToken
        uint256 i = getOraclePrice();
        uint256 Q2 = DODOMath._SolveQuadraticFunctionForTrade(
            targetQuoteAmount,
            quoteBalance,
            DecimalMath.mul(i, amount),
            true,
            _K_
        );
        return Q2.sub(quoteBalance);
    }

    function _RBelowBackToOne() internal view returns (uint256 payQuoteToken) {
        // important: carefully design the system to make sure spareBase always greater than or equal to 0
        uint256 spareBase = _BASE_BALANCE_.sub(_TARGET_BASE_TOKEN_AMOUNT_);
        uint256 price = getOraclePrice();
        uint256 fairAmount = DecimalMath.mul(spareBase, price);
        uint256 newTargetQuote = DODOMath._SolveQuadraticFunctionForTarget(
            _QUOTE_BALANCE_,
            _K_,
            fairAmount
        );
        return newTargetQuote.sub(_QUOTE_BALANCE_);
    }

    // ============ R > 1 cases ============

    function _RAboveBuyBaseToken(
        uint256 amount,
        uint256 baseBalance,
        uint256 targetBaseAmount
    ) internal view returns (uint256 payQuoteToken) {
        require(amount < baseBalance, "DODO_BASE_BALANCE_NOT_ENOUGH");
        uint256 B2 = baseBalance.sub(amount);
        return _RAboveIntegrate(targetBaseAmount, baseBalance, B2);
    }

    function _RAboveSellBaseToken(
        uint256 amount,
        uint256 baseBalance,
        uint256 targetBaseAmount
    ) internal view returns (uint256 receiveQuoteToken) {
        // here we don't require B1 <= targetBaseAmount
        // Because it is limited at upper function
        // See Trader.querySellBaseToken
        uint256 B1 = baseBalance.add(amount);
        return _RAboveIntegrate(targetBaseAmount, B1, baseBalance);
    }

    function _RAboveBackToOne() internal view returns (uint256 payBaseToken) {
        // important: carefully design the system to make sure spareBase always greater than or equal to 0
        uint256 spareQuote = _QUOTE_BALANCE_.sub(_TARGET_QUOTE_TOKEN_AMOUNT_);
        uint256 price = getOraclePrice();
        uint256 fairAmount = DecimalMath.divFloor(spareQuote, price);
        uint256 newTargetBase = DODOMath._SolveQuadraticFunctionForTarget(
            _BASE_BALANCE_,
            _K_,
            fairAmount
        );
        return newTargetBase.sub(_BASE_BALANCE_);
    }

    // ============ Helper functions ============

    function getExpectedTarget() public view returns (uint256 baseTarget, uint256 quoteTarget) {
        uint256 Q = _QUOTE_BALANCE_;
        uint256 B = _BASE_BALANCE_;
        if (_R_STATUS_ == Types.RStatus.ONE) {
            return (_TARGET_BASE_TOKEN_AMOUNT_, _TARGET_QUOTE_TOKEN_AMOUNT_);
        } else if (_R_STATUS_ == Types.RStatus.BELOW_ONE) {
            uint256 payQuoteToken = _RBelowBackToOne();
            return (_TARGET_BASE_TOKEN_AMOUNT_, Q.add(payQuoteToken));
        } else if (_R_STATUS_ == Types.RStatus.ABOVE_ONE) {
            uint256 payBaseToken = _RAboveBackToOne();
            return (B.add(payBaseToken), _TARGET_QUOTE_TOKEN_AMOUNT_);
        }
    }

    function getMidPrice() public view returns (uint256 midPrice) {
        (uint256 baseTarget, uint256 quoteTarget) = getExpectedTarget();
        if (_R_STATUS_ == Types.RStatus.BELOW_ONE) {
            uint256 R = DecimalMath.divFloor(
                quoteTarget.mul(quoteTarget).div(_QUOTE_BALANCE_),
                _QUOTE_BALANCE_
            );
            R = DecimalMath.ONE.sub(_K_).add(DecimalMath.mul(_K_, R));
            return DecimalMath.divFloor(getOraclePrice(), R);
        } else {
            uint256 R = DecimalMath.divFloor(
                baseTarget.mul(baseTarget).div(_BASE_BALANCE_),
                _BASE_BALANCE_
            );
            R = DecimalMath.ONE.sub(_K_).add(DecimalMath.mul(_K_, R));
            return DecimalMath.mul(getOraclePrice(), R);
        }
    }

    function _RAboveIntegrate(
        uint256 B0,
        uint256 B1,
        uint256 B2
    ) internal view returns (uint256) {
        uint256 i = getOraclePrice();
        return DODOMath._GeneralIntegrate(B0, B1, B2, i, _K_);
    }

    // function _RBelowIntegrate(
    //     uint256 Q0,
    //     uint256 Q1,
    //     uint256 Q2
    // ) internal view returns (uint256) {
    //     uint256 i = getOraclePrice();
    //     i = DecimalMath.divFloor(DecimalMath.ONE, i); // 1/i
    //     return DODOMath._GeneralIntegrate(Q0, Q1, Q2, i, _K_);
    // }
}

// File: contracts/lib/SafeERC20.sol

/*

    Copyright 2020 DODO ZOO.
    This is a simplified version of OpenZepplin's SafeERC20 library

*/

/**
 * @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 ERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using SafeMath for uint256;

    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 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.

        // A Solidity high level call has three parts:
        //  1. The target address is checked to verify it contains contract code
        //  2. The call itself is made, and success asserted
        //  3. The return value is decoded, which in turn checks the size of the returned data.
        // solhint-disable-next-line max-line-length

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = address(token).call(data);
        require(success, "SafeERC20: low-level call failed");

        if (returndata.length > 0) {
            // Return data is optional
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

// File: contracts/impl/Settlement.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title Settlement
 * @author DODO Breeder
 *
 * @notice Functions for assets settlement
 */
contract Settlement is Storage {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    // ============ Events ============

    event Donate(uint256 amount, bool isBaseToken);

    event ClaimAssets(address indexed user, uint256 baseTokenAmount, uint256 quoteTokenAmount);

    // ============ Assets IN/OUT Functions ============

    function _baseTokenTransferIn(address from, uint256 amount) internal {
        IERC20(_BASE_TOKEN_).safeTransferFrom(from, address(this), amount);
        _BASE_BALANCE_ = _BASE_BALANCE_.add(amount);
    }

    function _quoteTokenTransferIn(address from, uint256 amount) internal {
        IERC20(_QUOTE_TOKEN_).safeTransferFrom(from, address(this), amount);
        _QUOTE_BALANCE_ = _QUOTE_BALANCE_.add(amount);
    }

    function _baseTokenTransferOut(address to, uint256 amount) internal {
        IERC20(_BASE_TOKEN_).safeTransfer(to, amount);
        _BASE_BALANCE_ = _BASE_BALANCE_.sub(amount);
    }

    function _quoteTokenTransferOut(address to, uint256 amount) internal {
        IERC20(_QUOTE_TOKEN_).safeTransfer(to, amount);
        _QUOTE_BALANCE_ = _QUOTE_BALANCE_.sub(amount);
    }

    // ============ Donate to Liquidity Pool Functions ============

    function _donateBaseToken(uint256 amount) internal {
        _TARGET_BASE_TOKEN_AMOUNT_ = _TARGET_BASE_TOKEN_AMOUNT_.add(amount);
        emit Donate(amount, true);
    }

    function _donateQuoteToken(uint256 amount) internal {
        _TARGET_QUOTE_TOKEN_AMOUNT_ = _TARGET_QUOTE_TOKEN_AMOUNT_.add(amount);
        emit Donate(amount, false);
    }

    function donateBaseToken(uint256 amount) external preventReentrant {
        _baseTokenTransferIn(msg.sender, amount);
        _donateBaseToken(amount);
    }

    function donateQuoteToken(uint256 amount) external preventReentrant {
        _quoteTokenTransferIn(msg.sender, amount);
        _donateQuoteToken(amount);
    }

    // ============ Final Settlement Functions ============

    // last step to shut down dodo
    function finalSettlement() external onlyOwner notClosed {
        _CLOSED_ = true;
        _DEPOSIT_QUOTE_ALLOWED_ = false;
        _DEPOSIT_BASE_ALLOWED_ = false;
        _TRADE_ALLOWED_ = false;
        uint256 totalBaseCapital = getTotalBaseCapital();
        uint256 totalQuoteCapital = getTotalQuoteCapital();

        if (_QUOTE_BALANCE_ > _TARGET_QUOTE_TOKEN_AMOUNT_) {
            uint256 spareQuote = _QUOTE_BALANCE_.sub(_TARGET_QUOTE_TOKEN_AMOUNT_);
            _BASE_CAPITAL_RECEIVE_QUOTE_ = DecimalMath.divFloor(spareQuote, totalBaseCapital);
        } else {
            _TARGET_QUOTE_TOKEN_AMOUNT_ = _QUOTE_BALANCE_;
        }

        if (_BASE_BALANCE_ > _TARGET_BASE_TOKEN_AMOUNT_) {
            uint256 spareBase = _BASE_BALANCE_.sub(_TARGET_BASE_TOKEN_AMOUNT_);
            _QUOTE_CAPITAL_RECEIVE_BASE_ = DecimalMath.divFloor(spareBase, totalQuoteCapital);
        } else {
            _TARGET_BASE_TOKEN_AMOUNT_ = _BASE_BALANCE_;
        }

        _R_STATUS_ = Types.RStatus.ONE;
    }

    // claim remaining assets after final settlement
    function claimAssets() external preventReentrant {
        require(_CLOSED_, "DODO_NOT_CLOSED");
        require(!_CLAIMED_[msg.sender], "ALREADY_CLAIMED");
        _CLAIMED_[msg.sender] = true;
        uint256 quoteAmount = DecimalMath.mul(
            getBaseCapitalBalanceOf(msg.sender),
            _BASE_CAPITAL_RECEIVE_QUOTE_
        );
        uint256 baseAmount = DecimalMath.mul(
            getQuoteCapitalBalanceOf(msg.sender),
            _QUOTE_CAPITAL_RECEIVE_BASE_
        );
        _baseTokenTransferOut(msg.sender, baseAmount);
        _quoteTokenTransferOut(msg.sender, quoteAmount);
        emit ClaimAssets(msg.sender, baseAmount, quoteAmount);
        return;
    }

    // in case someone transfer to contract directly
    function retrieve(address token, uint256 amount) external onlyOwner {
        if (token == _BASE_TOKEN_) {
            require(
                IERC20(_BASE_TOKEN_).balanceOf(address(this)) >= _BASE_BALANCE_.add(amount),
                "DODO_BASE_BALANCE_NOT_ENOUGH"
            );
        }
        if (token == _QUOTE_TOKEN_) {
            require(
                IERC20(_QUOTE_TOKEN_).balanceOf(address(this)) >= _QUOTE_BALANCE_.add(amount),
                "DODO_QUOTE_BALANCE_NOT_ENOUGH"
            );
        }
        IERC20(token).safeTransfer(msg.sender, amount);
    }
}

// File: contracts/impl/Trader.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title Trader
 * @author DODO Breeder
 *
 * @notice Functions for trader operations
 */
contract Trader is Storage, Pricing, Settlement {
    using SafeMath for uint256;

    // ============ Events ============

    event SellBaseToken(address indexed seller, uint256 payBase, uint256 receiveQuote);

    event BuyBaseToken(address indexed buyer, uint256 receiveBase, uint256 payQuote);

    event ChargeMaintainerFee(address indexed maintainer, bool isBaseToken, uint256 amount);

    // ============ Modifiers ============

    modifier tradeAllowed() {
        require(_TRADE_ALLOWED_, "TRADE_NOT_ALLOWED");
        _;
    }

    modifier gasPriceLimit() {
        require(tx.gasprice <= _GAS_PRICE_LIMIT_, "GAS_PRICE_EXCEED");
        _;
    }

    // ============ Trade Functions ============

    function sellBaseToken(
        uint256 amount,
        uint256 minReceiveQuote,
        bytes calldata data
    ) external tradeAllowed gasPriceLimit preventReentrant returns (uint256) {
        // query price
        (
            uint256 receiveQuote,
            uint256 lpFeeQuote,
            uint256 mtFeeQuote,
            Types.RStatus newRStatus,
            uint256 newQuoteTarget,
            uint256 newBaseTarget
        ) = _querySellBaseToken(amount);
        require(receiveQuote >= minReceiveQuote, "SELL_BASE_RECEIVE_NOT_ENOUGH");

        // settle assets
        _quoteTokenTransferOut(msg.sender, receiveQuote);
        if (data.length > 0) {
            IDODOCallee(msg.sender).dodoCall(false, amount, receiveQuote, data);
        }
        _baseTokenTransferIn(msg.sender, amount);
        if (mtFeeQuote != 0) {
            _quoteTokenTransferOut(_MAINTAINER_, mtFeeQuote);
            emit ChargeMaintainerFee(_MAINTAINER_, false, mtFeeQuote);
        }

        // update TARGET
        if (_TARGET_QUOTE_TOKEN_AMOUNT_ != newQuoteTarget) {
            _TARGET_QUOTE_TOKEN_AMOUNT_ = newQuoteTarget;
        }
        if (_TARGET_BASE_TOKEN_AMOUNT_ != newBaseTarget) {
            _TARGET_BASE_TOKEN_AMOUNT_ = newBaseTarget;
        }
        if (_R_STATUS_ != newRStatus) {
            _R_STATUS_ = newRStatus;
        }

        _donateQuoteToken(lpFeeQuote);
        emit SellBaseToken(msg.sender, amount, receiveQuote);

        return receiveQuote;
    }

    function buyBaseToken(
        uint256 amount,
        uint256 maxPayQuote,
        bytes calldata data
    ) external tradeAllowed gasPriceLimit preventReentrant returns (uint256) {
        // query price
        (
            uint256 payQuote,
            uint256 lpFeeBase,
            uint256 mtFeeBase,
            Types.RStatus newRStatus,
            uint256 newQuoteTarget,
            uint256 newBaseTarget
        ) = _queryBuyBaseToken(amount);
        require(payQuote <= maxPayQuote, "BUY_BASE_COST_TOO_MUCH");

        // settle assets
        _baseTokenTransferOut(msg.sender, amount);
        if (data.length > 0) {
            IDODOCallee(msg.sender).dodoCall(true, amount, payQuote, data);
        }
        _quoteTokenTransferIn(msg.sender, payQuote);
        if (mtFeeBase != 0) {
            _baseTokenTransferOut(_MAINTAINER_, mtFeeBase);
            emit ChargeMaintainerFee(_MAINTAINER_, true, mtFeeBase);
        }

        // update TARGET
        if (_TARGET_QUOTE_TOKEN_AMOUNT_ != newQuoteTarget) {
            _TARGET_QUOTE_TOKEN_AMOUNT_ = newQuoteTarget;
        }
        if (_TARGET_BASE_TOKEN_AMOUNT_ != newBaseTarget) {
            _TARGET_BASE_TOKEN_AMOUNT_ = newBaseTarget;
        }
        if (_R_STATUS_ != newRStatus) {
            _R_STATUS_ = newRStatus;
        }

        _donateBaseToken(lpFeeBase);
        emit BuyBaseToken(msg.sender, amount, payQuote);

        return payQuote;
    }

    // ============ Query Functions ============

    function querySellBaseToken(uint256 amount) external view returns (uint256 receiveQuote) {
        (receiveQuote, , , , , ) = _querySellBaseToken(amount);
        return receiveQuote;
    }

    function queryBuyBaseToken(uint256 amount) external view returns (uint256 payQuote) {
        (payQuote, , , , , ) = _queryBuyBaseToken(amount);
        return payQuote;
    }

    function _querySellBaseToken(uint256 amount)
        internal
        view
        returns (
            uint256 receiveQuote,
            uint256 lpFeeQuote,
            uint256 mtFeeQuote,
            Types.RStatus newRStatus,
            uint256 newQuoteTarget,
            uint256 newBaseTarget
        )
    {
        (newBaseTarget, newQuoteTarget) = getExpectedTarget();

        uint256 sellBaseAmount = amount;

        if (_R_STATUS_ == Types.RStatus.ONE) {
            // case 1: R=1
            // R falls below one
            receiveQuote = _ROneSellBaseToken(sellBaseAmount, newQuoteTarget);
            newRStatus = Types.RStatus.BELOW_ONE;
        } else if (_R_STATUS_ == Types.RStatus.ABOVE_ONE) {
            uint256 backToOnePayBase = newBaseTarget.sub(_BASE_BALANCE_);
            uint256 backToOneReceiveQuote = _QUOTE_BALANCE_.sub(newQuoteTarget);
            // case 2: R>1
            // complex case, R status depends on trading amount
            if (sellBaseAmount < backToOnePayBase) {
                // case 2.1: R status do not change
                receiveQuote = _RAboveSellBaseToken(sellBaseAmount, _BASE_BALANCE_, newBaseTarget);
                newRStatus = Types.RStatus.ABOVE_ONE;
                if (receiveQuote > backToOneReceiveQuote) {
                    // [Important corner case!] may enter this branch when some precision problem happens. And consequently contribute to negative spare quote amount
                    // to make sure spare quote>=0, mannually set receiveQuote=backToOneReceiveQuote
                    receiveQuote = backToOneReceiveQuote;
                }
            } else if (sellBaseAmount == backToOnePayBase) {
                // case 2.2: R status changes to ONE
                receiveQuote = backToOneReceiveQuote;
                newRStatus = Types.RStatus.ONE;
            } else {
                // case 2.3: R status changes to BELOW_ONE
                receiveQuote = backToOneReceiveQuote.add(
                    _ROneSellBaseToken(sellBaseAmount.sub(backToOnePayBase), newQuoteTarget)
                );
                newRStatus = Types.RStatus.BELOW_ONE;
            }
        } else {
            // _R_STATUS_ == Types.RStatus.BELOW_ONE
            // case 3: R<1
            receiveQuote = _RBelowSellBaseToken(sellBaseAmount, _QUOTE_BALANCE_, newQuoteTarget);
            newRStatus = Types.RStatus.BELOW_ONE;
        }

        // count fees
        lpFeeQuote = DecimalMath.mul(receiveQuote, _LP_FEE_RATE_);
        mtFeeQuote = DecimalMath.mul(receiveQuote, _MT_FEE_RATE_);
        receiveQuote = receiveQuote.sub(lpFeeQuote).sub(mtFeeQuote);

        return (receiveQuote, lpFeeQuote, mtFeeQuote, newRStatus, newQuoteTarget, newBaseTarget);
    }

    function _queryBuyBaseToken(uint256 amount)
        internal
        view
        returns (
            uint256 payQuote,
            uint256 lpFeeBase,
            uint256 mtFeeBase,
            Types.RStatus newRStatus,
            uint256 newQuoteTarget,
            uint256 newBaseTarget
        )
    {
        (newBaseTarget, newQuoteTarget) = getExpectedTarget();

        // charge fee from user receive amount
        lpFeeBase = DecimalMath.mul(amount, _LP_FEE_RATE_);
        mtFeeBase = DecimalMath.mul(amount, _MT_FEE_RATE_);
        uint256 buyBaseAmount = amount.add(lpFeeBase).add(mtFeeBase);

        if (_R_STATUS_ == Types.RStatus.ONE) {
            // case 1: R=1
            payQuote = _ROneBuyBaseToken(buyBaseAmount, newBaseTarget);
            newRStatus = Types.RStatus.ABOVE_ONE;
        } else if (_R_STATUS_ == Types.RStatus.ABOVE_ONE) {
            // case 2: R>1
            payQuote = _RAboveBuyBaseToken(buyBaseAmount, _BASE_BALANCE_, newBaseTarget);
            newRStatus = Types.RStatus.ABOVE_ONE;
        } else if (_R_STATUS_ == Types.RStatus.BELOW_ONE) {
            uint256 backToOnePayQuote = newQuoteTarget.sub(_QUOTE_BALANCE_);
            uint256 backToOneReceiveBase = _BASE_BALANCE_.sub(newBaseTarget);
            // case 3: R<1
            // complex case, R status may change
            if (buyBaseAmount < backToOneReceiveBase) {
                // case 3.1: R status do not change
                // no need to check payQuote because spare base token must be greater than zero
                payQuote = _RBelowBuyBaseToken(buyBaseAmount, _QUOTE_BALANCE_, newQuoteTarget);
                newRStatus = Types.RStatus.BELOW_ONE;
            } else if (buyBaseAmount == backToOneReceiveBase) {
                // case 3.2: R status changes to ONE
                payQuote = backToOnePayQuote;
                newRStatus = Types.RStatus.ONE;
            } else {
                // case 3.3: R status changes to ABOVE_ONE
                payQuote = backToOnePayQuote.add(
                    _ROneBuyBaseToken(buyBaseAmount.sub(backToOneReceiveBase), newBaseTarget)
                );
                newRStatus = Types.RStatus.ABOVE_ONE;
            }
        }

        return (payQuote, lpFeeBase, mtFeeBase, newRStatus, newQuoteTarget, newBaseTarget);
    }
}

// File: contracts/impl/LiquidityProvider.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title LiquidityProvider
 * @author DODO Breeder
 *
 * @notice Functions for liquidity provider operations
 */
contract LiquidityProvider is Storage, Pricing, Settlement {
    using SafeMath for uint256;

    // ============ Events ============

    event Deposit(
        address indexed payer,
        address indexed receiver,
        bool isBaseToken,
        uint256 amount,
        uint256 lpTokenAmount
    );

    event Withdraw(
        address indexed payer,
        address indexed receiver,
        bool isBaseToken,
        uint256 amount,
        uint256 lpTokenAmount
    );

    event ChargePenalty(address indexed payer, bool isBaseToken, uint256 amount);

    // ============ Modifiers ============

    modifier depositQuoteAllowed() {
        require(_DEPOSIT_QUOTE_ALLOWED_, "DEPOSIT_QUOTE_NOT_ALLOWED");
        _;
    }

    modifier depositBaseAllowed() {
        require(_DEPOSIT_BASE_ALLOWED_, "DEPOSIT_BASE_NOT_ALLOWED");
        _;
    }

    // ============ Routine Functions ============

    function withdrawBase(uint256 amount) external returns (uint256) {
        return withdrawBaseTo(msg.sender, amount);
    }

    function depositBase(uint256 amount) external returns (uint256) {
        return depositBaseTo(msg.sender, amount);
    }

    function withdrawQuote(uint256 amount) external returns (uint256) {
        return withdrawQuoteTo(msg.sender, amount);
    }

    function depositQuote(uint256 amount) external returns (uint256) {
        return depositQuoteTo(msg.sender, amount);
    }

    function withdrawAllBase() external returns (uint256) {
        return withdrawAllBaseTo(msg.sender);
    }

    function withdrawAllQuote() external returns (uint256) {
        return withdrawAllQuoteTo(msg.sender);
    }

    // ============ Deposit Functions ============

    function depositQuoteTo(address to, uint256 amount)
        public
        preventReentrant
        depositQuoteAllowed
        returns (uint256)
    {
        (, uint256 quoteTarget) = getExpectedTarget();
        uint256 totalQuoteCapital = getTotalQuoteCapital();
        uint256 capital = amount;
        if (totalQuoteCapital == 0) {
            // give remaining quote token to lp as a gift
            capital = amount.add(quoteTarget);
        } else if (quoteTarget > 0) {
            capital = amount.mul(totalQuoteCapital).div(quoteTarget);
        }

        // settlement
        _quoteTokenTransferIn(msg.sender, amount);
        _mintQuoteCapital(to, capital);
        _TARGET_QUOTE_TOKEN_AMOUNT_ = _TARGET_QUOTE_TOKEN_AMOUNT_.add(amount);

        emit Deposit(msg.sender, to, false, amount, capital);
        return capital;
    }

    function depositBaseTo(address to, uint256 amount)
        public
        preventReentrant
        depositBaseAllowed
        returns (uint256)
    {
        (uint256 baseTarget, ) = getExpectedTarget();
        uint256 totalBaseCapital = getTotalBaseCapital();
        uint256 capital = amount;
        if (totalBaseCapital == 0) {
            // give remaining base token to lp as a gift
            capital = amount.add(baseTarget);
        } else if (baseTarget > 0) {
            capital = amount.mul(totalBaseCapital).div(baseTarget);
        }

        // settlement
        _baseTokenTransferIn(msg.sender, amount);
        _mintBaseCapital(to, capital);
        _TARGET_BASE_TOKEN_AMOUNT_ = _TARGET_BASE_TOKEN_AMOUNT_.add(amount);

        emit Deposit(msg.sender, to, true, amount, capital);
        return capital;
    }

    // ============ Withdraw Functions ============

    function withdrawQuoteTo(address to, uint256 amount) public preventReentrant returns (uint256) {
        // calculate capital
        (, uint256 quoteTarget) = getExpectedTarget();
        uint256 totalQuoteCapital = getTotalQuoteCapital();
        require(totalQuoteCapital > 0, "NO_QUOTE_LP");

        uint256 requireQuoteCapital = amount.mul(totalQuoteCapital).divCeil(quoteTarget);
        require(
            requireQuoteCapital <= getQuoteCapitalBalanceOf(msg.sender),
            "LP_QUOTE_CAPITAL_BALANCE_NOT_ENOUGH"
        );

        // handle penalty, penalty may exceed amount
        uint256 penalty = getWithdrawQuotePenalty(amount);
        require(penalty < amount, "PENALTY_EXCEED");

        // settlement
        _TARGET_QUOTE_TOKEN_AMOUNT_ = _TARGET_QUOTE_TOKEN_AMOUNT_.sub(amount);
        _burnQuoteCapital(msg.sender, requireQuoteCapital);
        _quoteTokenTransferOut(to, amount.sub(penalty));
        _donateQuoteToken(penalty);

        emit Withdraw(msg.sender, to, false, amount.sub(penalty), requireQuoteCapital);
        emit ChargePenalty(msg.sender, false, penalty);

        return amount.sub(penalty);
    }

    function withdrawBaseTo(address to, uint256 amount) public preventReentrant returns (uint256) {
        // calculate capital
        (uint256 baseTarget, ) = getExpectedTarget();
        uint256 totalBaseCapital = getTotalBaseCapital();
        require(totalBaseCapital > 0, "NO_BASE_LP");

        uint256 requireBaseCapital = amount.mul(totalBaseCapital).divCeil(baseTarget);
        require(
            requireBaseCapital <= getBaseCapitalBalanceOf(msg.sender),
            "LP_BASE_CAPITAL_BALANCE_NOT_ENOUGH"
        );

        // handle penalty, penalty may exceed amount
        uint256 penalty = getWithdrawBasePenalty(amount);
        require(penalty <= amount, "PENALTY_EXCEED");

        // settlement
        _TARGET_BASE_TOKEN_AMOUNT_ = _TARGET_BASE_TOKEN_AMOUNT_.sub(amount);
        _burnBaseCapital(msg.sender, requireBaseCapital);
        _baseTokenTransferOut(to, amount.sub(penalty));
        _donateBaseToken(penalty);

        emit Withdraw(msg.sender, to, true, amount.sub(penalty), requireBaseCapital);
        emit ChargePenalty(msg.sender, true, penalty);

        return amount.sub(penalty);
    }

    // ============ Withdraw all Functions ============

    function withdrawAllQuoteTo(address to) public preventReentrant returns (uint256) {
        uint256 withdrawAmount = getLpQuoteBalance(msg.sender);
        uint256 capital = getQuoteCapitalBalanceOf(msg.sender);

        // handle penalty, penalty may exceed amount
        uint256 penalty = getWithdrawQuotePenalty(withdrawAmount);
        require(penalty <= withdrawAmount, "PENALTY_EXCEED");

        // settlement
        _TARGET_QUOTE_TOKEN_AMOUNT_ = _TARGET_QUOTE_TOKEN_AMOUNT_.sub(withdrawAmount);
        _burnQuoteCapital(msg.sender, capital);
        _quoteTokenTransferOut(to, withdrawAmount.sub(penalty));
        _donateQuoteToken(penalty);

        emit Withdraw(msg.sender, to, false, withdrawAmount, capital);
        emit ChargePenalty(msg.sender, false, penalty);

        return withdrawAmount.sub(penalty);
    }

    function withdrawAllBaseTo(address to) public preventReentrant returns (uint256) {
        uint256 withdrawAmount = getLpBaseBalance(msg.sender);
        uint256 capital = getBaseCapitalBalanceOf(msg.sender);

        // handle penalty, penalty may exceed amount
        uint256 penalty = getWithdrawBasePenalty(withdrawAmount);
        require(penalty <= withdrawAmount, "PENALTY_EXCEED");

        // settlement
        _TARGET_BASE_TOKEN_AMOUNT_ = _TARGET_BASE_TOKEN_AMOUNT_.sub(withdrawAmount);
        _burnBaseCapital(msg.sender, capital);
        _baseTokenTransferOut(to, withdrawAmount.sub(penalty));
        _donateBaseToken(penalty);

        emit Withdraw(msg.sender, to, true, withdrawAmount, capital);
        emit ChargePenalty(msg.sender, true, penalty);

        return withdrawAmount.sub(penalty);
    }

    // ============ Helper Functions ============

    function _mintBaseCapital(address user, uint256 amount) internal {
        IDODOLpToken(_BASE_CAPITAL_TOKEN_).mint(user, amount);
    }

    function _mintQuoteCapital(address user, uint256 amount) internal {
        IDODOLpToken(_QUOTE_CAPITAL_TOKEN_).mint(user, amount);
    }

    function _burnBaseCapital(address user, uint256 amount) internal {
        IDODOLpToken(_BASE_CAPITAL_TOKEN_).burn(user, amount);
    }

    function _burnQuoteCapital(address user, uint256 amount) internal {
        IDODOLpToken(_QUOTE_CAPITAL_TOKEN_).burn(user, amount);
    }

    // ============ Getter Functions ============

    function getLpBaseBalance(address lp) public view returns (uint256 lpBalance) {
        uint256 totalBaseCapital = getTotalBaseCapital();
        (uint256 baseTarget, ) = getExpectedTarget();
        if (totalBaseCapital == 0) {
            return 0;
        }
        lpBalance = getBaseCapitalBalanceOf(lp).mul(baseTarget).div(totalBaseCapital);
        return lpBalance;
    }

    function getLpQuoteBalance(address lp) public view returns (uint256 lpBalance) {
        uint256 totalQuoteCapital = getTotalQuoteCapital();
        (, uint256 quoteTarget) = getExpectedTarget();
        if (totalQuoteCapital == 0) {
            return 0;
        }
        lpBalance = getQuoteCapitalBalanceOf(lp).mul(quoteTarget).div(totalQuoteCapital);
        return lpBalance;
    }

    function getWithdrawQuotePenalty(uint256 amount) public view returns (uint256 penalty) {
        require(amount <= _QUOTE_BALANCE_, "DODO_QUOTE_BALANCE_NOT_ENOUGH");
        if (_R_STATUS_ == Types.RStatus.BELOW_ONE) {
            uint256 spareBase = _BASE_BALANCE_.sub(_TARGET_BASE_TOKEN_AMOUNT_);
            uint256 price = getOraclePrice();
            uint256 fairAmount = DecimalMath.mul(spareBase, price);
            uint256 targetQuote = DODOMath._SolveQuadraticFunctionForTarget(
                _QUOTE_BALANCE_,
                _K_,
                fairAmount
            );
            // if amount = _QUOTE_BALANCE_, div error
            uint256 targetQuoteWithWithdraw = DODOMath._SolveQuadraticFunctionForTarget(
                _QUOTE_BALANCE_.sub(amount),
                _K_,
                fairAmount
            );
            return targetQuote.sub(targetQuoteWithWithdraw.add(amount));
        } else {
            return 0;
        }
    }

    function getWithdrawBasePenalty(uint256 amount) public view returns (uint256 penalty) {
        require(amount <= _BASE_BALANCE_, "DODO_BASE_BALANCE_NOT_ENOUGH");
        if (_R_STATUS_ == Types.RStatus.ABOVE_ONE) {
            uint256 spareQuote = _QUOTE_BALANCE_.sub(_TARGET_QUOTE_TOKEN_AMOUNT_);
            uint256 price = getOraclePrice();
            uint256 fairAmount = DecimalMath.divFloor(spareQuote, price);
            uint256 targetBase = DODOMath._SolveQuadraticFunctionForTarget(
                _BASE_BALANCE_,
                _K_,
                fairAmount
            );
            // if amount = _BASE_BALANCE_, div error
            uint256 targetBaseWithWithdraw = DODOMath._SolveQuadraticFunctionForTarget(
                _BASE_BALANCE_.sub(amount),
                _K_,
                fairAmount
            );
            return targetBase.sub(targetBaseWithWithdraw.add(amount));
        } else {
            return 0;
        }
    }
}

// File: contracts/impl/Admin.sol

/*

    Copyright 2020 DODO ZOO.

*/

/**
 * @title Admin
 * @author DODO Breeder
 *
 * @notice Functions for admin operations
 */
contract Admin is Storage {
    // ============ Events ============

    event UpdateGasPriceLimit(uint256 oldGasPriceLimit, uint256 newGasPriceLimit);

    event UpdateLiquidityProviderFeeRate(
        uint256 oldLiquidityProviderFeeRate,
        uint256 newLiquidityProviderFeeRate
    );

    event UpdateMaintainerFeeRate(uint256 oldMaintainerFeeRate, uint256 newMaintainerFeeRate);

    event UpdateK(uint256 oldK, uint256 newK);

    ...

// [truncated — 59166 bytes total]

Read Contract

_BASE_BALANCE_ 0xeab5d20e → uint256
_BASE_CAPITAL_RECEIVE_QUOTE_ 0xc6b73cf9 → uint256
_BASE_CAPITAL_TOKEN_ 0xd689107c → address
_BASE_TOKEN_ 0x4a248d2a → address
_CLAIMED_ 0x68be20ad → bool
_CLOSED_ 0x6ec6a58d → bool
_DEPOSIT_BASE_ALLOWED_ 0xa598aca7 → bool
_DEPOSIT_QUOTE_ALLOWED_ 0xc5bbffe8 → bool
_GAS_PRICE_LIMIT_ 0x4de4527e → uint256
_K_ 0xec2fd46d → uint256
_LP_FEE_RATE_ 0xab44a7a3 → uint256
_MAINTAINER_ 0x4322ec83 → address
_MT_FEE_RATE_ 0xc0ffa178 → uint256
_NEW_OWNER_ 0x8456db15 → address
_ORACLE_ 0x73a2ab7c → address
_OWNER_ 0x16048bc4 → address
_QUOTE_BALANCE_ 0x7c9b8e89 → uint256
_QUOTE_CAPITAL_RECEIVE_BASE_ 0x0e6518e9 → uint256
_QUOTE_CAPITAL_TOKEN_ 0xac1fbc98 → address
_QUOTE_TOKEN_ 0xd4b97046 → address
_R_STATUS_ 0x17be952e → uint8
_SUPERVISOR_ 0x3960f142 → address
_TARGET_BASE_TOKEN_AMOUNT_ 0xb2094fd3 → uint256
_TARGET_QUOTE_TOKEN_AMOUNT_ 0x245c9685 → uint256
_TRADE_ALLOWED_ 0xdd58b41c → bool
getBaseCapitalBalanceOf 0x7aed942d → uint256
getExpectedTarget 0xffa64225 → uint256, uint256
getLpBaseBalance 0x95faa5f6 → uint256
getLpQuoteBalance 0x36a53bbb → uint256
getMidPrice 0xee27c689 → uint256
getOraclePrice 0x796da7af → uint256
getQuoteCapitalBalanceOf 0xf67ed448 → uint256
getTotalBaseCapital 0x0cd1667d → uint256
getTotalQuoteCapital 0x2aa82c65 → uint256
getWithdrawBasePenalty 0xee5150b3 → uint256
getWithdrawQuotePenalty 0x0c9f7bd0 → uint256
queryBuyBaseToken 0x18c0bbe4 → uint256
querySellBaseToken 0xa2801e16 → uint256
version 0x54fd4d50 → uint256

Write Contract 35 functions

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

buyBaseToken 0xe67ce706
uint256 amount
uint256 maxPayQuote
bytes data
returns: uint256
claimAssets 0x1f3c156e
No parameters
claimOwnership 0x4e71e0c8
No parameters
depositBase 0x27bed8ee
uint256 amount
returns: uint256
depositBaseTo 0xaa06ce9b
address to
uint256 amount
returns: uint256
depositQuote 0xf3ae6c5f
uint256 amount
returns: uint256
depositQuoteTo 0x5f179f64
address to
uint256 amount
returns: uint256
disableBaseDeposit 0x13c57624
No parameters
disableQuoteDeposit 0xbc7d679d
No parameters
disableTrading 0x17700f01
No parameters
donateBaseToken 0xed0aa428
uint256 amount
donateQuoteToken 0x387b0c11
uint256 amount
enableBaseDeposit 0x1184d8be
No parameters
enableQuoteDeposit 0x36ac41a8
No parameters
enableTrading 0x8a8c523c
No parameters
finalSettlement 0x648a4fac
No parameters
init 0xf00f9a09
address owner
address supervisor
address maintainer
address baseToken
address quoteToken
address oracle
uint256 lpFeeRate
uint256 mtFeeRate
uint256 k
uint256 gasPriceLimit
retrieve 0xc3a2a665
address token
uint256 amount
sellBaseToken 0x8dae7333
uint256 amount
uint256 minReceiveQuote
bytes data
returns: uint256
setGasPriceLimit 0x09231602
uint256 newGasPriceLimit
setK 0x67de8be9
uint256 newK
setLiquidityProviderFeeRate 0x5bb7552a
uint256 newLiquidityPorviderFeeRate
setMaintainer 0x13ea5d29
address newMaintainer
setMaintainerFeeRate 0xf2220416
uint256 newMaintainerFeeRate
setOracle 0x7adbf973
address newOracle
setSupervisor 0x9299eb30
address newSupervisor
transferOwnership 0xf2fde38b
address newOwner
withdrawAllBase 0xd47eaa37
No parameters
returns: uint256
withdrawAllBaseTo 0x1e34b9cc
address to
returns: uint256
withdrawAllQuote 0xc59203af
No parameters
returns: uint256
withdrawAllQuoteTo 0x04512dc4
address to
returns: uint256
withdrawBase 0xf98bea15
uint256 amount
returns: uint256
withdrawBaseTo 0x947cf92b
address to
uint256 amount
returns: uint256
withdrawQuote 0xc0a5f6ff
uint256 amount
returns: uint256
withdrawQuoteTo 0x108db744
address to
uint256 amount
returns: uint256

Recent Transactions

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