Address Contract Verified
Address
0xD0CF7dfbF09CAfaB8AEf00e0Ce19a4638004a364
Balance
0 ETH
Nonce
1
Code Size
15520 bytes
Creator
0xfa0d8ebc...71d0 at tx 0xa053bf32...7be233
Indexed Transactions
0 (1 on-chain, 1.6% indexed)
Contract Bytecode
15520 bytes
0x608060405234801561001057600080fd5b506004361061023d5760003560e01c80638456db151161013b578063d4b97046116100b8578063f2fde38b1161007c578063f2fde38b14610467578063f6b06e701461047a578063f811d69214610482578063fd1ed7e914610497578063fe24cb7f146104b25761023d565b8063d4b9704614610434578063dd93f59a1461043c578063e539ef491461044f578063ec2fd46d14610457578063ee27c6891461045f5761023d565b8063bbf5ce78116100ff578063bbf5ce78146103f6578063bd6015b4146103fe578063bf357dae14610411578063c57a5d0314610419578063d0a494e4146104215761023d565b80638456db151461039c578063880a4d87146103a45780638ff3928c146103b9578063a382d1b9146103cc578063ab44a7a3146103e15761023d565b806344096609116101c957806366410a211161018d57806366410a211461034157806371f9100c1461036457806377f586571461036c57806379a04876146103815780637d721504146103945761023d565b806344096609146102f45780634a248d2a146103075780634e71e0c81461030f57806354fd4d501461031757806365f6fcbb1461032c5761023d565b806328c4e24c1161021057806328c4e24c146102a85780632df6cb48146102bb57806336223ce9146102c35780633b20884a146102d95780634322ec83146102ec5761023d565b806301a3c30b146102425780630d0092971461025757806310d764601461026a57806316048bc414610293575b600080fd5b610255610250366004613372565b6104ba565b005b610255610265366004613357565b61068a565b61027d6102783660046135a0565b6106ea565b60405161028a91906136fd565b60405180910390f35b61029b610815565b60405161028a9190613621565b6102556102b6366004613412565b610824565b61027d610901565b6102cb610911565b60405161028a929190613b43565b61027d6102e73660046135cb565b61092c565b61029b610b1e565b6102cb610302366004613357565b610b2d565b61029b610bc9565b610255610bd8565b61031f610c66565b60405161028a919061371b565b610334610c93565b60405161028a9190613b3a565b61035461034f366004613452565b610d3a565b60405161028a9493929190613b51565b610334610e36565b610374610e7f565b60405161028a9190613b12565b61035461038f366004613452565b610e95565b610374610f84565b61029b610f93565b6103ac610fa2565b60405161028a9190613bab565b61027d6103c736600461347c565b610fb5565b6103d46111c5565b60405161028a9190613ab9565b6103e9611269565b60405161028a9190613bbc565b610374611280565b61033461040c366004613357565b611296565b6103ac611550565b610255611563565b61025561042f36600461350d565b611835565b61029b611e23565b61033461044a366004613357565b611e32565b6103746120d7565b6103e96120e6565b6103346120f6565b610255610475366004613357565b612108565b61029b61218d565b61048a61219c565b60405161028a9190613b26565b61049f6121b2565b60405161028a9796959493929190613b7b565b610334612215565b6104c38961068a565b856001600160a01b0316876001600160a01b031614156104fe5760405162461bcd60e51b81526004016104f590613813565b60405180910390fd5b600380546001600160a01b03808a166001600160a01b03199283161790925560048054898416908316179055600280548b84169083161790556008805492871692909116919091179055670de0b6b3a76400008511156105705760405162461bcd60e51b81526004016104f59061398a565b670de0b6b3a76400008311156105985760405162461bcd60e51b81526004016104f590613962565b6000821180156105b657506a0c097ce7bc90715b34b9f160241b8211155b6105d25760405162461bcd60e51b81526004016104f5906137c8565b6008805467ffffffffffffffff60a01b1916600160a01b67ffffffffffffffff88811691909102919091179091556009805467ffffffffffffffff191691851691909117600160401b600160c01b031916600160401b6001600160801b038516021790556001805460ff60b01b1916600160b01b83158015919091029190911790915561067757600580546001600160e01b03164263ffffffff16600160e01b021790555b61067f61221b565b505050505050505050565b600154600160a01b900460ff16156106b45760405162461bcd60e51b81526004016104f590613901565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b039092166001600160a01b0319909216919091179055565b600154600090600160a81b900460ff16156107175760405162461bcd60e51b81526004016104f5906137f0565b6001805460ff60a81b1916600160a81b179055600054336001600160a01b03909116146107565760405162461bcd60e51b81526004016104f5906139e3565b6005546001600160701b031683118015906107835750600554600160701b90046001600160701b03168211155b61079f5760405162461bcd60e51b81526004016104f59061392b565b6000841180156107bd57506a0c097ce7bc90715b34b9f160241b8411155b6107d95760405162461bcd60e51b81526004016104f5906137c8565b50600980546001600160801b038516600160401b02600160401b600160c01b0319909116179055600180805460ff60a81b191690559392505050565b6000546001600160a01b031681565b600154600160a81b900460ff161561084e5760405162461bcd60e51b81526004016104f5906137f0565b6001805460ff60a81b1916600160a81b179055600054336001600160a01b039091161461088d5760405162461bcd60e51b81526004016104f5906139e3565b6003546001600160a01b038381169116148015906108b957506004546001600160a01b03838116911614155b6108d55760405162461bcd60e51b81526004016104f590613a73565b6108ef6001600160a01b038316848363ffffffff6123ce16565b50506001805460ff60a81b1916905550565b600154600160b01b900460ff1681565b6005546001600160701b0380821692600160701b9092041690565b600154600090600160a81b900460ff16156109595760405162461bcd60e51b81526004016104f5906137f0565b6001805460ff60a81b1916600160a81b179055600054336001600160a01b03909116146109985760405162461bcd60e51b81526004016104f5906139e3565b6005546001600160701b031683118015906109c55750600554600160701b90046001600160701b03168211155b6109e15760405162461bcd60e51b81526004016104f59061392b565b670de0b6b3a7640000861115610a095760405162461bcd60e51b81526004016104f59061398a565b670de0b6b3a7640000841115610a315760405162461bcd60e51b81526004016104f590613962565b600085118015610a4f57506a0c097ce7bc90715b34b9f160241b8511155b610a6b5760405162461bcd60e51b81526004016104f5906137c8565b6008805467ffffffffffffffff60a01b1916600160a01b67ffffffffffffffff89811691909102919091179091556009805467ffffffffffffffff191691861691909117600160401b600160c01b031916600160401b6001600160801b038816021790556040517f9950d5a2f2c7264863d40100bf993f0cdbc4711806caba6284d07e80fd50087990610aff908890613b3a565b60405180910390a150506001805460ff60a81b19168155949350505050565b6002546001600160a01b031681565b600854604051638198edbf60e01b815267ffffffffffffffff600160a01b830416916000916001600160a01b0390911690638198edbf90610b72908690600401613621565b60206040518083038186803b158015610b8a57600080fd5b505afa158015610b9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc291906134f5565b9050915091565b6003546001600160a01b031681565b6001546001600160a01b03163314610c025760405162461bcd60e51b81526004016104f590613779565b600154600080546040516001600160a01b0393841693909116917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a360018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b604080518082019091526012815271044505020416476616e63656420312e302e360741b60208201525b90565b6005546003546040516370a0823160e01b8152600092610d35926001600160701b03909116916001600160a01b03909116906370a0823190610cd9903090600401613621565b60206040518083038186803b158015610cf157600080fd5b505afa158015610d05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d2991906134f5565b9063ffffffff61242916565b905090565b600080600080610d486132f9565b610d506111c5565b9050610d5c8187612456565b600854604051638198edbf60e01b815292975090945067ffffffffffffffff600160a01b820416916000916001600160a01b031690638198edbf90610da5908c90600401613621565b60206040518083038186803b158015610dbd57600080fd5b505afa158015610dd1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610df591906134f5565b9050610e01878261255c565b9550610e2186610d29610e148a8661255c565b8a9063ffffffff61242916565b96508260a00151935050505092959194509250565b600554600480546040516370a0823160e01b8152600093610d3593600160701b9091046001600160701b0316926001600160a01b0316916370a0823191610cd991309101613621565b600654600160701b90046001600160701b031681565b600080600080610ea36132f9565b610eab6111c5565b9050610eb78187612586565b600854604051638198edbf60e01b815292975090945067ffffffffffffffff600160a01b820416916000916001600160a01b031690638198edbf90610f00908c90600401613621565b60206040518083038186803b158015610f1857600080fd5b505afa158015610f2c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f5091906134f5565b9050610f5c878261255c565b9550610f6f86610d29610e148a8661255c565b96508260800151935050505092959194509250565b6005546001600160701b031681565b6001546001600160a01b031681565b600554600160e01b900463ffffffff1681565b600154600090600160a81b900460ff1615610fe25760405162461bcd60e51b81526004016104f5906137f0565b6001805460ff60a81b1916600160a81b179055600054336001600160a01b03909116146110215760405162461bcd60e51b81526004016104f5906139e3565b6005546001600160701b0316831180159061104e5750600554600160701b90046001600160701b03168211155b61106a5760405162461bcd60e51b81526004016104f59061392b565b670de0b6b3a76400008811156110925760405162461bcd60e51b81526004016104f59061398a565b670de0b6b3a76400008611156110ba5760405162461bcd60e51b81526004016104f590613962565b6000871180156110d857506a0c097ce7bc90715b34b9f160241b8711155b6110f45760405162461bcd60e51b81526004016104f5906137c8565b6008805467ffffffffffffffff60a01b1916600160a01b67ffffffffffffffff8b811691909102919091179091556009805467ffffffffffffffff191691881691909117600160401b600160c01b031916600160401b6001600160801b038a16021790556111628986612687565b61116c89856126aa565b61117461221b565b7f9950d5a2f2c7264863d40100bf993f0cdbc4711806caba6284d07e80fd500879886040516111a39190613b3a565b60405180910390a150506001805460ff60a81b19168155979650505050505050565b6111cd6132f9565b600954600160401b81046001600160801b0316825267ffffffffffffffff1660208201526005546001600160701b038082166040840152600160701b918290048116606084015260065480821660808501529182041660a0830152600160e01b900463ffffffff16600281111561124057fe5b8160c00190600281111561125057fe5b9081600281111561125d57fe5b905250610c90816126cd565b600854600160a01b900467ffffffffffffffff1681565b600554600160701b90046001600160701b031681565b600154600090600160a81b900460ff16156112c35760405162461bcd60e51b81526004016104f5906137f0565b6001805460ff60a81b1916600160a81b1790556003546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611307903090600401613621565b60206040518083038186803b15801561131f57600080fd5b505afa158015611333573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061135791906134f5565b60055490915060009061137a9083906001600160701b031663ffffffff61242916565b9050600080600061138b3285610e95565b92985090945090925090506113a087876126aa565b6002546113b6906001600160a01b0316846126aa565b8060028111156113c257fe5b600654600160e01b900463ffffffff90811691161461146f576001600160701b038211156114025760405162461bcd60e51b81526004016104f5906139c1565b600680546001600160701b0319166001600160701b03841617905580600281111561142957fe5b6006601c6101000a81548163ffffffff021916908363ffffffff160217905550600080516020613c2b833981519152816040516114669190613708565b60405180910390a15b600480546040516370a0823160e01b81526114f79288926001600160a01b0316916370a08231916114a291309101613621565b60206040518083038186803b1580156114ba57600080fd5b505afa1580156114ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114f291906134f5565b612777565b600354600454604051600080516020613c4b83398151915292611530926001600160a01b039182169291169088908b9033908e906136aa565b60405180910390a150506001805460ff60a81b1916905550919392505050565b600654600160e01b900463ffffffff1681565b600154600160a81b900460ff161561158d5760405162461bcd60e51b81526004016104f5906137f0565b6001805460ff60a81b1916600160a81b179055600054336001600160a01b03909116146115cc5760405162461bcd60e51b81526004016104f5906139e3565b6003546040516370a0823160e01b81526000916001600160a01b0316906370a08231906115fd903090600401613621565b60206040518083038186803b15801561161557600080fd5b505afa158015611629573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061164d91906134f5565b600480546040516370a0823160e01b81529293506000926001600160a01b03909116916370a082319161168291309101613621565b60206040518083038186803b15801561169a57600080fd5b505afa1580156116ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116d291906134f5565b90506001600160701b0382118015906116f257506001600160701b038111155b61170e5760405162461bcd60e51b81526004016104f5906139c1565b6005546001600160701b0316821461178357600554600654611753916001600160701b039081169161174791168563ffffffff61280416565b9063ffffffff61284516565b600680546001600160701b03199081166001600160701b0393841617909155600580549091169184169190911790555b600554600160701b90046001600160701b0316811461180a576005546006546117cd916001600160701b03600160701b91829004811692611747929004168463ffffffff61280416565b600680546001600160701b03928316600160701b908102600160701b600160e01b0319928316179092556005805493851690920292169190911790555b600154600160b01b900460ff16156118245761182461286f565b50506001805460ff60a81b19169055565b600154600160a81b900460ff161561185f5760405162461bcd60e51b81526004016104f5906137f0565b6001805460ff60a81b1916600160a81b17905561187c8386612687565b61188683856126aa565b80156118f357604051637ed1f1dd60e01b81526001600160a01b03841690637ed1f1dd906118c0903390899089908890889060040161365e565b600060405180830381600087803b1580156118da57600080fd5b505af11580156118ee573d6000803e3d6000fd5b505050505b6003546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611924903090600401613621565b60206040518083038186803b15801561193c57600080fd5b505afa158015611950573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061197491906134f5565b600480546040516370a0823160e01b81529293506000926001600160a01b03909116916370a08231916119a991309101613621565b60206040518083038186803b1580156119c157600080fd5b505afa1580156119d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119f991906134f5565b6005549091506001600160701b031682101580611a285750600554600160701b90046001600160701b03168110155b611a445760405162461bcd60e51b81526004016104f59061374e565b6005546001600160701b0316821015611c0757600554600090611a78908390600160701b90046001600160701b0316612429565b9050600080600080611a8a3286610d3a565b600554939750919550935091508490611ab2906001600160701b03168963ffffffff61242916565b1115611ad05760405162461bcd60e51b81526004016104f59061374e565b600254611ae6906001600160a01b031684612687565b816002811115611af257fe5b600654600160e01b900463ffffffff908116911614611ba8576001600160701b03811115611b325760405162461bcd60e51b81526004016104f5906139c1565b60068054600160701b600160e01b031916600160701b6001600160701b03841602179055816002811115611b6257fe5b6006601c6101000a81548163ffffffff021916908363ffffffff160217905550600080516020613c2b83398151915282604051611b9f9190613708565b60405180910390a15b600080516020613c4b833981519152600460009054906101000a90046001600160a01b0316600360009054906101000a90046001600160a01b03168787338f604051611bf9969594939291906136aa565b60405180910390a150505050505b600554600160701b90046001600160701b0316811015611dc857600554600090611c419084906001600160701b031663ffffffff61242916565b9050600080600080611c533286610e95565b600554939750919550935091508490611c7c90600160701b90046001600160701b031688612429565b1115611c9a5760405162461bcd60e51b81526004016104f59061374e565b600254611cb0906001600160a01b0316846126aa565b816002811115611cbc57fe5b600654600160e01b900463ffffffff908116911614611d69576001600160701b03811115611cfc5760405162461bcd60e51b81526004016104f5906139c1565b600680546001600160701b0319166001600160701b038316179055816002811115611d2357fe5b6006601c6101000a81548163ffffffff021916908363ffffffff160217905550600080516020613c2b83398151915282604051611d609190613708565b60405180910390a15b600080516020613c4b833981519152600360009054906101000a90046001600160a01b0316600460009054906101000a90046001600160a01b03168787338f604051611dba969594939291906136aa565b60405180910390a150505050505b611dd0612904565b7f0b82e93068db15abd9fbb2682c65462ea8a0a10582dce93a5664818e296f54eb33868989604051611e059493929190613635565b60405180910390a150506001805460ff60a81b191690555050505050565b6004546001600160a01b031681565b600154600090600160a81b900460ff1615611e5f5760405162461bcd60e51b81526004016104f5906137f0565b6001805460ff60a81b1916600160a81b179055600480546040516370a0823160e01b81526000926001600160a01b03909216916370a0823191611ea491309101613621565b60206040518083038186803b158015611ebc57600080fd5b505afa158015611ed0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ef491906134f5565b600554909150600090611f18908390600160701b90046001600160701b0316612429565b90506000806000611f293285610d3a565b9298509094509092509050611f3e8787612687565b600254611f54906001600160a01b031684612687565b806002811115611f6057fe5b600654600160e01b900463ffffffff908116911614612016576001600160701b03821115611fa05760405162461bcd60e51b81526004016104f5906139c1565b60068054600160701b600160e01b031916600160701b6001600160701b03851602179055806002811115611fd057fe5b6006601c6101000a81548163ffffffff021916908363ffffffff160217905550600080516020613c2b8339815191528160405161200d9190613708565b60405180910390a15b6003546040516370a0823160e01b815261209e916001600160a01b0316906370a0823190612048903090600401613621565b60206040518083038186803b15801561206057600080fd5b505afa158015612074573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061209891906134f5565b86612777565b600454600354604051600080516020613c4b83398151915292611530926001600160a01b039182169291169088908b9033908e906136aa565b6006546001600160701b031681565b60095467ffffffffffffffff1681565b6000610d356121036111c5565b612acc565b6000546001600160a01b031633146121325760405162461bcd60e51b81526004016104f5906139e3565b600080546040516001600160a01b03808516939216917fdcf55418cee3220104fef63f979ff3c4097ad240c0c43dcb33ce837748983e6291a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b6008546001600160a01b031681565b600954600160401b90046001600160801b031681565b60008060008060008060006121c56132f9565b6121cd6111c5565b905080600001519750806020015196508060400151955080606001519450806080015193508060a0015192508060c00151600281111561220957fe5b91505090919293949596565b60075481565b6003546040516370a0823160e01b81526000916001600160a01b0316906370a082319061224c903090600401613621565b60206040518083038186803b15801561226457600080fd5b505afa158015612278573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061229c91906134f5565b600480546040516370a0823160e01b81529293506000926001600160a01b03909116916370a08231916122d191309101613621565b60206040518083038186803b1580156122e957600080fd5b505afa1580156122fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061232191906134f5565b90506001600160701b03821180159061234157506001600160701b038111155b61235d5760405162461bcd60e51b81526004016104f5906139c1565b600580546001600160701b03838116600160701b02600160701b600160e01b03199186166001600160701b031993841681178316821790945560068054909316909317169091176001600160e01b0316905560015460ff600160b01b90910416156123ca576123ca61286f565b5050565b6124248363a9059cbb60e01b84846040516024016123ed9291906136e4565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612bc3565b505050565b60008282111561244b5760405162461bcd60e51b81526004016104f5906138de565b508082035b92915050565b600080808460c00151600281111561246a57fe5b14156124855761247a8484612c80565b915060019050612555565b60018460c00151600281111561249757fe5b14156124a75761247a8484612ca7565b60006124c485606001518660a0015161242990919063ffffffff16565b905060006124e38660800151876040015161242990919063ffffffff16565b90508185101561250e576124f78686612cc4565b93506002925080841115612509578093505b612552565b818514156125225780935060009250612552565b61254b61253e87612539888663ffffffff61242916565b612c80565b829063ffffffff612cff16565b9350600192505b50505b9250929050565b6000670de0b6b3a7640000612577848463ffffffff61280416565b8161257e57fe5b049392505050565b600080808460c00151600281111561259a57fe5b14156125b5576125aa8484612d24565b915060029050612555565b60018460c0015160028111156125c757fe5b14156126725760006125ea8560400151866080015161242990919063ffffffff16565b905060006126098660a00151876060015161242990919063ffffffff16565b9050818510156126345761261d8686612d43565b9350600192508084111561262f578093505b61266b565b81851415612648578093506000925061266b565b61266461253e8761265f888663ffffffff61242916565b612d24565b9350600292505b5050612555565b61267c8484612d75565b946002945092505050565b80156123ca576003546123ca906001600160a01b0316838363ffffffff6123ce16565b80156123ca576004546123ca906001600160a01b0316838363ffffffff6123ce16565b60028160c0015160028111156126df57fe5b141561271e5761271481606001516127088360800151846040015161242990919063ffffffff16565b83516020850151612d94565b60a0820152612774565b60018160c00151600281111561273057fe5b14156127745761276e81604001516127598360a00151846060015161242990919063ffffffff16565b835161276490612eb8565b8460200151612d94565b60808201525b50565b6001600160701b03821180159061279557506001600160701b038111155b6127b15760405162461bcd60e51b81526004016104f5906139c1565b600580546001600160701b03838116600160701b02600160701b600160e01b03199186166001600160701b0319909316929092171617905560015460ff600160b01b90910416156123ca576123ca61286f565b60008261281357506000612450565b8282028284828161282057fe5b041461283e5760405162461bcd60e51b81526004016104f590613a96565b9392505050565b60008082116128665760405162461bcd60e51b81526004016104f59061387f565b81838161257e57fe5b60055463ffffffff42811691600160e01b900481168203908116158015906128a157506005546001600160701b031615155b80156128be5750600554600160701b90046001600160701b031615155b156128de578063ffffffff166128d26120f6565b60078054919092020190555b506005805463ffffffff909216600160e01b026001600160e01b03909216919091179055565b6003546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612935903090600401613621565b60206040518083038186803b15801561294d57600080fd5b505afa158015612961573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061298591906134f5565b600480546040516370a0823160e01b81529293506000926001600160a01b03909116916370a08231916129ba91309101613621565b60206040518083038186803b1580156129d257600080fd5b505afa1580156129e6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a0a91906134f5565b90506001600160701b038211801590612a2a57506001600160701b038111155b612a465760405162461bcd60e51b81526004016104f5906139c1565b6005546001600160701b03168214612a7457600580546001600160701b0319166001600160701b0384161790555b600554600160701b90046001600160701b03168114612ab25760058054600160701b600160e01b031916600160701b6001600160701b038416021790555b600154600160b01b900460ff16156123ca576123ca61286f565b600060028260c001516002811115612ae057fe5b1415612b6b57606082015160a0830151600091612b1691612b0c9190611747908063ffffffff61280416565b8460600151612ed8565b9050612b53612b2984602001518361255c565b6020850151612b4790670de0b6b3a76400009063ffffffff61242916565b9063ffffffff612cff16565b9050612b63836000015182612ed8565b915050612bbe565b60408201516080830151600091612b9b91612b919190611747908063ffffffff61280416565b8460400151612ed8565b9050612bae612b2984602001518361255c565b9050612b6383600001518261255c565b919050565b60006060836001600160a01b031683604051612bdf9190613605565b6000604051808303816000865af19150503d8060008114612c1c576040519150601f19603f3d011682016040523d82523d6000602084013e612c21565b606091505b509150915081612c435760405162461bcd60e51b81526004016104f59061384a565b805115612c7a5780806020019051810190612c5e91906134d9565b612c7a5760405162461bcd60e51b81526004016104f590613a29565b50505050565b600061283e8360800151846080015184612c9d8760000151612eb8565b8760200151612ef6565b600061283e8360800151846040015184612c9d8760000151612eb8565b600061283e8360a00151612ce5848660600151612cff90919063ffffffff16565b60608601518651612cf590612eb8565b8760200151613193565b60008282018381101561283e5760405162461bcd60e51b81526004016104f590613a06565b600061283e8360a001518460a001518486600001518760200151612ef6565b600061283e8360800151612d64848660400151612cff90919063ffffffff16565b604086015186516020880151613193565b600061283e8360a0015184606001518486600001518760200151612ef6565b600081612dbc57612db5612da8848661255c565b869063ffffffff612cff16565b9050612eb0565b84612dc957506000612eb0565b600080612ddf600485028663ffffffff61280416565b905080612df657670de0b6b3a76400009150612e74565b858187830281612e0257fe5b041415612e3c57612e35612e306a0c097ce7bc90715b34b9f160241b612b47848a028b63ffffffff61284516565b61326b565b9150612e74565b612e71612e306a0c097ce7bc90715b34b9f160241b612b4789612e65868d63ffffffff61284516565b9063ffffffff61280416565b91505b6000612e9e670de0b6b3a7640000612b47612e95868363ffffffff61242916565b88600202612ed8565b9050612eaa888261255c565b93505050505b949350505050565b60006124506a0c097ce7bc90715b34b9f160241b8363ffffffff61284516565b600061283e8261174785670de0b6b3a764000063ffffffff61280416565b6000808611612f175760405162461bcd60e51b81526004016104f5906137a0565b83612f245750600061318a565b81612f515784612f34848661255c565b11612f4857612f43838561255c565b612f4a565b845b905061318a565b670de0b6b3a764000082141561301157600080612f74858763ffffffff61280416565b905080612f845760009150612fdd565b868188830281612f9057fe5b041415612fc057612fb9612faa898063ffffffff61280416565b8289029063ffffffff61284516565b9150612fdd565b612fda8861174787612e6583838c8e63ffffffff61280416565b91505b613008612ff883670de0b6b3a764000063ffffffff612cff16565b611747898563ffffffff61280416565b9250505061318a565b600061303e613026858763ffffffff61280416565b612b4789612e658a611747898463ffffffff61280416565b9050600061305e87612e65670de0b6b3a76400008763ffffffff61242916565b905060008282106130745750819003600061307a565b50810360015b61309282670de0b6b3a764000063ffffffff61284516565b915060006130c96130b66004612e65670de0b6b3a76400008a63ffffffff61242916565b6130c48c612e658a8f61255c565b61255c565b90506130e2612e3082612b47868063ffffffff61280416565b905060006131036002612e65670de0b6b3a76400008a63ffffffff61242916565b9050600083156131415761311d838663ffffffff61242916565b90508061313c5760405162461bcd60e51b81526004016104f5906138a7565b613154565b613151858463ffffffff612cff16565b90505b600061316082846132a2565b90508b81111561317a57600097505050505050505061318a565b8b03965061318a95505050505050565b95945050505050565b60008086116131b45760405162461bcd60e51b81526004016104f5906137a0565b60006131d66131c9878763ffffffff61242916565b859063ffffffff61280416565b9050826131fd576131f581670de0b6b3a764000063ffffffff61284516565b91505061318a565b600061321c613216886117478b8063ffffffff61280416565b87612ed8565b9050600061322a858361255c565b905061325e6a0c097ce7bc90715b34b9f160241b61174785612e6585612b47670de0b6b3a76400008c63ffffffff61242916565b9998505050505050505050565b80600160028204015b8181101561329c5780915060028182858161328b57fe5b04018161329457fe5b049050613274565b50919050565b600061283e826132c085670de0b6b3a764000063ffffffff61280416565b9063ffffffff6132cc16565b6000806132d98484612845565b9050828102840380156132f157506001019050612450565b509050612450565b6040518060e001604052806000815260200160008152602001600081526020016000815260200160008152602001600081526020016000600281111561333b57fe5b905290565b80356001600160a01b038116811461245057600080fd5b600060208284031215613368578081fd5b61283e8383613340565b60008060008060008060008060006101208a8c031215613390578485fd5b893561339b81613c07565b985060208a01356133ab81613c07565b975060408a01356133bb81613c07565b965060608a01356133cb81613c07565b955060808a0135945060a08a01356133e281613c07565b935060c08a0135925060e08a013591506101008a013561340181613c1c565b809150509295985092959850929598565b600080600060608486031215613426578283fd5b833561343181613c07565b9250602084013561344181613c07565b929592945050506040919091013590565b60008060408385031215613464578182fd5b61346e8484613340565b946020939093013593505050565b600080600080600080600080610100898b031215613498578384fd5b88356134a381613c07565b9a60208a01359a5060408a013599606081013599506080810135985060a0810135975060c0810135965060e00135945092505050565b6000602082840312156134ea578081fd5b815161283e81613c1c565b600060208284031215613506578081fd5b5051919050565b600080600080600060808688031215613524578081fd5b853594506020860135935061353c8760408801613340565b9250606086013567ffffffffffffffff80821115613558578283fd5b81880189601f820112613569578384fd5b8035925081831115613579578384fd5b89602084830101111561358a578384fd5b6020810194505050809150509295509295909350565b6000806000606084860312156135b4578283fd5b505081359360208301359350604090920135919050565b600080600080600060a086880312156135e2578081fd5b505083359560208501359550604085013594606081013594506080013592509050565b60008251613617818460208701613bd1565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0394851681529290931660208301526040820152606081019190915260800190565b600060018060a01b038716825285602083015284604083015260806060830152826080830152828460a084013781830160a090810191909152601f909201601f19160101949350505050565b6001600160a01b0396871681529486166020860152604085019390935260608401919091528316608083015290911660a082015260c00190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b6020810161371583613bfd565b91905290565b600060208252825180602084015261373a816040850160208701613bd1565b601f01601f19169190910160400192915050565b60208082526011908201527011931054d217d313d05397d19052531151607a1b604082015260600190565b6020808252600d908201526c494e56414c49445f434c41494d60981b604082015260600190565b6020808252600e908201526d5441524745545f49535f5a45524f60901b604082015260600190565b6020808252600e908201526d495f4f55545f4f465f52414e474560901b604082015260600190565b60208082526009908201526814915153951490539560ba1b604082015260600190565b6020808252601a908201527f424153455f51554f54455f43414e5f4e4f545f42455f53414d45000000000000604082015260600190565b6020808252818101527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604082015260600190565b6020808252600e908201526d2224ab24a224a723afa2a92927a960911b604082015260600190565b6020808252601c908201527f444f444f4d6174683a2073686f756c64206e6f74206265207a65726f00000000604082015260600190565b60208082526009908201526829aaa12fa2a92927a960b91b604082015260600190565b60208082526010908201526f1113d113d7d25392551250531256915160821b604082015260600190565b6020808252601c908201527f524553455256455f414d4f554e545f49535f4e4f545f454e4f55474800000000604082015260600190565b6020808252600e908201526d4b5f4f55545f4f465f52414e474560901b604082015260600190565b60208082526018908201527f4c505f4645455f524154455f4f55545f4f465f52414e47450000000000000000604082015260600190565b6020808252600890820152674f564552464c4f5760c01b604082015260600190565b6020808252600990820152682727aa2fa7aba722a960b91b604082015260600190565b60208082526009908201526820a2222fa2a92927a960b91b604082015260600190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b6020808252600990820152681554d157d49154d15560ba1b604082015260600190565b60208082526009908201526826aaa62fa2a92927a960b91b604082015260600190565b600060e082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c0830151613b0581613bfd565b8060c08401525092915050565b6001600160701b0391909116815260200190565b6001600160801b0391909116815260200190565b90815260200190565b918252602082015260400190565b848152602081018490526080810160038410613b6957fe5b60408201939093526060015292915050565b968752602087019590955260408601939093526060850191909152608084015260a083015260c082015260e00190565b63ffffffff91909116815260200190565b67ffffffffffffffff91909116815260200190565b60005b83811015613bec578181015183820152602001613bd4565b83811115612c7a5750506000910152565b6003811061277457fe5b6001600160a01b038116811461277457600080fd5b801515811461277457600080fdfedf176ad18be4f9f32efaa32f06e9d1175476504739a745f1399a6d3fa4b75917c2c0245e056d5fb095f04cd6373bc770802ebd1e6c918eb78fdef843cdb37b0fa264697066735822122030692917cf7c3507447f6d7211b313ffc04d1fb2b16bf63a770721a578342f9464736f6c63430006090033
Verified Source Code Full Match
Compiler: v0.6.9+commit.3e3065ac
EVM: istanbul
Optimization: Yes (200 runs)
DPPAdvanced_flattened.sol 1481 lines
// File: contracts/intf/IDODOCallee.sol
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
interface IDODOCallee {
function DVMSellShareCall(
address sender,
uint256 burnShareAmount,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
function DVMFlashLoanCall(
address sender,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
function DPPFlashLoanCall(
address sender,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
function DSPFlashLoanCall(
address sender,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
function CPCancelCall(
address sender,
uint256 amount,
bytes calldata data
) external;
function CPClaimBidCall(
address sender,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
function NFTRedeemCall(
address payable assetTo,
uint256 quoteAmount,
bytes calldata
) external;
}
// File: contracts/lib/ReentrancyGuard.sol
/**
* @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/lib/SafeMath.sol
/**
* @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
/**
* @title DecimalMath
* @author DODO Breeder
*
* @notice Functions for fixed point number with 18 decimals
*/
library DecimalMath {
using SafeMath for uint256;
uint256 internal constant ONE = 10**18;
uint256 internal constant ONE2 = 10**36;
function mulFloor(uint256 target, uint256 d) internal pure returns (uint256) {
return target.mul(d) / (10**18);
}
function mulCeil(uint256 target, uint256 d) internal pure returns (uint256) {
return target.mul(d).divCeil(10**18);
}
function divFloor(uint256 target, uint256 d) internal pure returns (uint256) {
return target.mul(10**18).div(d);
}
function divCeil(uint256 target, uint256 d) internal pure returns (uint256) {
return target.mul(10**18).divCeil(d);
}
function reciprocalFloor(uint256 target) internal pure returns (uint256) {
return uint256(10**36).div(target);
}
function reciprocalCeil(uint256 target) internal pure returns (uint256) {
return uint256(10**36).divCeil(target);
}
function powFloor(uint256 target, uint256 e) internal pure returns (uint256) {
if (e == 0) {
return 10 ** 18;
} else if (e == 1) {
return target;
} else {
uint p = powFloor(target, e.div(2));
p = p.mul(p) / (10**18);
if (e % 2 == 1) {
p = p.mul(target) / (10**18);
}
return p;
}
}
}
// File: contracts/lib/DODOMath.sol
/**
* @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 from 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))
i is the price of V-res trading pair
support k=1 & k=0 case
[round down]
*/
function _GeneralIntegrate(
uint256 V0,
uint256 V1,
uint256 V2,
uint256 i,
uint256 k
) internal pure returns (uint256) {
require(V0 > 0, "TARGET_IS_ZERO");
uint256 fairAmount = i.mul(V1.sub(V2)); // i*delta
if (k == 0) {
return fairAmount.div(DecimalMath.ONE);
}
uint256 V0V0V1V2 = DecimalMath.divFloor(V0.mul(V0).div(V1), V2);
uint256 penalty = DecimalMath.mulFloor(k, V0V0V1V2); // k(V0^2/V1/V2)
return DecimalMath.ONE.sub(k).add(penalty).mul(fairAmount).div(DecimalMath.ONE2);
}
/*
Follow the integration function above
i*deltaB = (Q2-Q1)*(1-k+kQ0^2/Q1/Q2)
Assume Q2=Q0, Given Q1 and deltaB, solve Q0
i is the price of delta-V trading pair
give out target of V
support k=1 & k=0 case
[round down]
*/
function _SolveQuadraticFunctionForTarget(
uint256 V1,
uint256 delta,
uint256 i,
uint256 k
) internal pure returns (uint256) {
if (k == 0) {
return V1.add(DecimalMath.mulFloor(i, delta));
}
// V0 = V1*(1+(sqrt-1)/2k)
// sqrt = √(1+4kidelta/V1)
// premium = 1+(sqrt-1)/2k
// uint256 sqrt = (4 * k).mul(i).mul(delta).div(V1).add(DecimalMath.ONE2).sqrt();
if (V1 == 0) {
return 0;
}
uint256 sqrt;
uint256 ki = (4 * k).mul(i);
if (ki == 0) {
sqrt = DecimalMath.ONE;
} else if ((ki * delta) / ki == delta) {
sqrt = (ki * delta).div(V1).add(DecimalMath.ONE2).sqrt();
} else {
sqrt = ki.div(V1).mul(delta).add(DecimalMath.ONE2).sqrt();
}
uint256 premium =
DecimalMath.divFloor(sqrt.sub(DecimalMath.ONE), k * 2).add(DecimalMath.ONE);
// V0 is greater than or equal to V1 according to the solution
return DecimalMath.mulFloor(V1, premium);
}
/*
Follow the 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, user sell Q and receive B
if deltaBSig=false, then Q2<Q1, user sell B and receive Q
return |Q1-Q2|
as we only support sell amount as delta, the deltaB is always negative
the input ideltaB is actually -ideltaB in the equation
i is the price of delta-V trading pair
support k=1 & k=0 case
[round down]
*/
function _SolveQuadraticFunctionForTrade(
uint256 V0,
uint256 V1,
uint256 delta,
uint256 i,
uint256 k
) internal pure returns (uint256) {
require(V0 > 0, "TARGET_IS_ZERO");
if (delta == 0) {
return 0;
}
if (k == 0) {
return DecimalMath.mulFloor(i, delta) > V1 ? V1 : DecimalMath.mulFloor(i, delta);
}
if (k == DecimalMath.ONE) {
// if k==1
// Q2=Q1/(1+ideltaBQ1/Q0/Q0)
// temp = ideltaBQ1/Q0/Q0
// Q2 = Q1/(1+temp)
// Q1-Q2 = Q1*(1-1/(1+temp)) = Q1*(temp/(1+temp))
// uint256 temp = i.mul(delta).mul(V1).div(V0.mul(V0));
uint256 temp;
uint256 idelta = i.mul(delta);
if (idelta == 0) {
temp = 0;
} else if ((idelta * V1) / idelta == V1) {
temp = (idelta * V1).div(V0.mul(V0));
} else {
temp = delta.mul(V1).div(V0).mul(i).div(V0);
}
return V1.mul(temp).div(temp.add(DecimalMath.ONE));
}
// calculate -b value and sig
// b = kQ0^2/Q1-i*deltaB-(1-k)Q1
// part1 = (1-k)Q1 >=0
// part2 = kQ0^2/Q1-i*deltaB >=0
// bAbs = abs(part1-part2)
// if part1>part2 => b is negative => bSig is false
// if part2>part1 => b is positive => bSig is true
uint256 part2 = k.mul(V0).div(V1).mul(V0).add(i.mul(delta)); // kQ0^2/Q1-i*deltaB
uint256 bAbs = DecimalMath.ONE.sub(k).mul(V1); // (1-k)Q1
bool bSig;
if (bAbs >= part2) {
bAbs = bAbs - part2;
bSig = false;
} else {
bAbs = part2 - bAbs;
bSig = true;
}
bAbs = bAbs.div(DecimalMath.ONE);
// calculate sqrt
uint256 squareRoot =
DecimalMath.mulFloor(
DecimalMath.ONE.sub(k).mul(4),
DecimalMath.mulFloor(k, V0).mul(V0)
); // 4(1-k)kQ0^2
squareRoot = bAbs.mul(bAbs).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 (bSig) {
numerator = squareRoot.sub(bAbs);
if (numerator == 0) {
revert("DODOMath: should not be zero");
}
} else {
numerator = bAbs.add(squareRoot);
}
uint256 V2 = DecimalMath.divCeil(numerator, denominator);
if (V2 > V1) {
return 0;
} else {
return V1 - V2;
}
}
}
// File: contracts/lib/PMMPricing.sol
/**
* @title Pricing
* @author DODO Breeder
*
* @notice DODO Pricing model
*/
library PMMPricing {
using SafeMath for uint256;
enum RState {ONE, ABOVE_ONE, BELOW_ONE}
struct PMMState {
uint256 i;
uint256 K;
uint256 B;
uint256 Q;
uint256 B0;
uint256 Q0;
RState R;
}
// ============ buy & sell ============
function sellBaseToken(PMMState memory state, uint256 payBaseAmount)
internal
pure
returns (uint256 receiveQuoteAmount, RState newR)
{
if (state.R == RState.ONE) {
// case 1: R=1
// R falls below one
receiveQuoteAmount = _ROneSellBaseToken(state, payBaseAmount);
newR = RState.BELOW_ONE;
} else if (state.R == RState.ABOVE_ONE) {
uint256 backToOnePayBase = state.B0.sub(state.B);
uint256 backToOneReceiveQuote = state.Q.sub(state.Q0);
// case 2: R>1
// complex case, R status depends on trading amount
if (payBaseAmount < backToOnePayBase) {
// case 2.1: R status do not change
receiveQuoteAmount = _RAboveSellBaseToken(state, payBaseAmount);
newR = RState.ABOVE_ONE;
if (receiveQuoteAmount > 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
receiveQuoteAmount = backToOneReceiveQuote;
}
} else if (payBaseAmount == backToOnePayBase) {
// case 2.2: R status changes to ONE
receiveQuoteAmount = backToOneReceiveQuote;
newR = RState.ONE;
} else {
// case 2.3: R status changes to BELOW_ONE
receiveQuoteAmount = backToOneReceiveQuote.add(
_ROneSellBaseToken(state, payBaseAmount.sub(backToOnePayBase))
);
newR = RState.BELOW_ONE;
}
} else {
// state.R == RState.BELOW_ONE
// case 3: R<1
receiveQuoteAmount = _RBelowSellBaseToken(state, payBaseAmount);
newR = RState.BELOW_ONE;
}
}
function sellQuoteToken(PMMState memory state, uint256 payQuoteAmount)
internal
pure
returns (uint256 receiveBaseAmount, RState newR)
{
if (state.R == RState.ONE) {
receiveBaseAmount = _ROneSellQuoteToken(state, payQuoteAmount);
newR = RState.ABOVE_ONE;
} else if (state.R == RState.ABOVE_ONE) {
receiveBaseAmount = _RAboveSellQuoteToken(state, payQuoteAmount);
newR = RState.ABOVE_ONE;
} else {
uint256 backToOnePayQuote = state.Q0.sub(state.Q);
uint256 backToOneReceiveBase = state.B.sub(state.B0);
if (payQuoteAmount < backToOnePayQuote) {
receiveBaseAmount = _RBelowSellQuoteToken(state, payQuoteAmount);
newR = RState.BELOW_ONE;
if (receiveBaseAmount > backToOneReceiveBase) {
receiveBaseAmount = backToOneReceiveBase;
}
} else if (payQuoteAmount == backToOnePayQuote) {
receiveBaseAmount = backToOneReceiveBase;
newR = RState.ONE;
} else {
receiveBaseAmount = backToOneReceiveBase.add(
_ROneSellQuoteToken(state, payQuoteAmount.sub(backToOnePayQuote))
);
newR = RState.ABOVE_ONE;
}
}
}
// ============ R = 1 cases ============
function _ROneSellBaseToken(PMMState memory state, uint256 payBaseAmount)
internal
pure
returns (
uint256 // receiveQuoteToken
)
{
// in theory Q2 <= targetQuoteTokenAmount
// however when amount is close to 0, precision problems may cause Q2 > targetQuoteTokenAmount
return
DODOMath._SolveQuadraticFunctionForTrade(
state.Q0,
state.Q0,
payBaseAmount,
state.i,
state.K
);
}
function _ROneSellQuoteToken(PMMState memory state, uint256 payQuoteAmount)
internal
pure
returns (
uint256 // receiveBaseToken
)
{
return
DODOMath._SolveQuadraticFunctionForTrade(
state.B0,
state.B0,
payQuoteAmount,
DecimalMath.reciprocalFloor(state.i),
state.K
);
}
// ============ R < 1 cases ============
function _RBelowSellQuoteToken(PMMState memory state, uint256 payQuoteAmount)
internal
pure
returns (
uint256 // receiveBaseToken
)
{
return
DODOMath._GeneralIntegrate(
state.Q0,
state.Q.add(payQuoteAmount),
state.Q,
DecimalMath.reciprocalFloor(state.i),
state.K
);
}
function _RBelowSellBaseToken(PMMState memory state, uint256 payBaseAmount)
internal
pure
returns (
uint256 // receiveQuoteToken
)
{
return
DODOMath._SolveQuadraticFunctionForTrade(
state.Q0,
state.Q,
payBaseAmount,
state.i,
state.K
);
}
// ============ R > 1 cases ============
function _RAboveSellBaseToken(PMMState memory state, uint256 payBaseAmount)
internal
pure
returns (
uint256 // receiveQuoteToken
)
{
return
DODOMath._GeneralIntegrate(
state.B0,
state.B.add(payBaseAmount),
state.B,
state.i,
state.K
);
}
function _RAboveSellQuoteToken(PMMState memory state, uint256 payQuoteAmount)
internal
pure
returns (
uint256 // receiveBaseToken
)
{
return
DODOMath._SolveQuadraticFunctionForTrade(
state.B0,
state.B,
payQuoteAmount,
DecimalMath.reciprocalFloor(state.i),
state.K
);
}
// ============ Helper functions ============
function adjustedTarget(PMMState memory state) internal pure {
if (state.R == RState.BELOW_ONE) {
state.Q0 = DODOMath._SolveQuadraticFunctionForTarget(
state.Q,
state.B.sub(state.B0),
state.i,
state.K
);
} else if (state.R == RState.ABOVE_ONE) {
state.B0 = DODOMath._SolveQuadraticFunctionForTarget(
state.B,
state.Q.sub(state.Q0),
DecimalMath.reciprocalFloor(state.i),
state.K
);
}
}
function getMidPrice(PMMState memory state) internal pure returns (uint256) {
if (state.R == RState.BELOW_ONE) {
uint256 R = DecimalMath.divFloor(state.Q0.mul(state.Q0).div(state.Q), state.Q);
R = DecimalMath.ONE.sub(state.K).add(DecimalMath.mulFloor(state.K, R));
return DecimalMath.divFloor(state.i, R);
} else {
uint256 R = DecimalMath.divFloor(state.B0.mul(state.B0).div(state.B), state.B);
R = DecimalMath.ONE.sub(state.K).add(DecimalMath.mulFloor(state.K, R));
return DecimalMath.mulFloor(state.i, R);
}
}
}
// 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);
function symbol() 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/SafeERC20.sol
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for 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)
);
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @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/lib/InitializableOwnable.sol
/**
* @title Ownable
* @author DODO Breeder
*
* @notice Ownership related functions
*/
contract InitializableOwnable {
address public _OWNER_;
address public _NEW_OWNER_;
bool internal _INITIALIZED_;
// ============ Events ============
event OwnershipTransferPrepared(address indexed previousOwner, address indexed newOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
// ============ Modifiers ============
modifier notInitialized() {
require(!_INITIALIZED_, "DODO_INITIALIZED");
_;
}
modifier onlyOwner() {
require(msg.sender == _OWNER_, "NOT_OWNER");
_;
}
// ============ Functions ============
function initOwner(address newOwner) public notInitialized {
_INITIALIZED_ = true;
_OWNER_ = newOwner;
}
function transferOwnership(address newOwner) public onlyOwner {
emit OwnershipTransferPrepared(_OWNER_, newOwner);
_NEW_OWNER_ = newOwner;
}
function claimOwnership() public {
require(msg.sender == _NEW_OWNER_, "INVALID_CLAIM");
emit OwnershipTransferred(_OWNER_, _NEW_OWNER_);
_OWNER_ = _NEW_OWNER_;
_NEW_OWNER_ = address(0);
}
}
// File: contracts/lib/FeeRateModel.sol
interface IFeeRateImpl {
function getFeeRate(address pool, address trader) external view returns (uint256);
}
interface IFeeRateModel {
function getFeeRate(address trader) external view returns (uint256);
}
contract FeeRateModel is InitializableOwnable {
address public feeRateImpl;
function setFeeProxy(address _feeRateImpl) public onlyOwner {
feeRateImpl = _feeRateImpl;
}
function getFeeRate(address trader) external view returns (uint256) {
if(feeRateImpl == address(0))
return 0;
return IFeeRateImpl(feeRateImpl).getFeeRate(msg.sender,trader);
}
}
// File: contracts/DODOPrivatePool/impl/DPPStorage.sol
contract DPPStorage is InitializableOwnable, ReentrancyGuard {
using SafeMath for uint256;
bool public _IS_OPEN_TWAP_ = false;
// ============ Core Address ============
address public _MAINTAINER_;
IERC20 public _BASE_TOKEN_;
IERC20 public _QUOTE_TOKEN_;
uint112 public _BASE_RESERVE_;
uint112 public _QUOTE_RESERVE_;
uint32 public _BLOCK_TIMESTAMP_LAST_;
uint112 public _BASE_TARGET_;
uint112 public _QUOTE_TARGET_;
uint32 public _RState_;
uint256 public _BASE_PRICE_CUMULATIVE_LAST_;
// ============ Variables for Pricing ============
IFeeRateModel public _MT_FEE_RATE_MODEL_;
uint64 public _LP_FEE_RATE_;
uint64 public _K_;
uint128 public _I_;
// ============ Helper Functions ============
function getPMMState() public view returns (PMMPricing.PMMState memory state) {
state.i = _I_;
state.K = _K_;
state.B = _BASE_RESERVE_;
state.Q = _QUOTE_RESERVE_;
state.B0 = _BASE_TARGET_;
state.Q0 = _QUOTE_TARGET_;
state.R = PMMPricing.RState(_RState_);
PMMPricing.adjustedTarget(state);
}
function getPMMStateForCall()
external
view
returns (
uint256 i,
uint256 K,
uint256 B,
uint256 Q,
uint256 B0,
uint256 Q0,
uint256 R
)
{
PMMPricing.PMMState memory state = getPMMState();
i = state.i;
K = state.K;
B = state.B;
Q = state.Q;
B0 = state.B0;
Q0 = state.Q0;
R = uint256(state.R);
}
function getMidPrice() public view returns (uint256 midPrice) {
return PMMPricing.getMidPrice(getPMMState());
}
}
// File: contracts/DODOPrivatePool/impl/DPPVault.sol
contract DPPVault is DPPStorage {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// ============ Events ============
event LpFeeRateChange(uint256 newLpFeeRate);
// ============ View Functions ============
function getVaultReserve() external view returns (uint256 baseReserve, uint256 quoteReserve) {
baseReserve = _BASE_RESERVE_;
quoteReserve = _QUOTE_RESERVE_;
}
function getUserFeeRate(address user)
external
view
returns (uint256 lpFeeRate, uint256 mtFeeRate)
{
lpFeeRate = _LP_FEE_RATE_;
mtFeeRate = _MT_FEE_RATE_MODEL_.getFeeRate(user);
}
// ============ Get Input ============
function getBaseInput() public view returns (uint256 input) {
return _BASE_TOKEN_.balanceOf(address(this)).sub(uint256(_BASE_RESERVE_));
}
function getQuoteInput() public view returns (uint256 input) {
return _QUOTE_TOKEN_.balanceOf(address(this)).sub(uint256(_QUOTE_RESERVE_));
}
// ============ TWAP UPDATE ===========
function _twapUpdate() internal {
uint32 blockTimestamp = uint32(block.timestamp % 2**32);
uint32 timeElapsed = blockTimestamp - _BLOCK_TIMESTAMP_LAST_;
if (timeElapsed > 0 && _BASE_RESERVE_ != 0 && _QUOTE_RESERVE_ != 0) {
_BASE_PRICE_CUMULATIVE_LAST_ += getMidPrice() * timeElapsed;
}
_BLOCK_TIMESTAMP_LAST_ = blockTimestamp;
}
// ============ Set Status ============
function _setReserve(uint256 baseReserve, uint256 quoteReserve) internal {
require(baseReserve <= uint112(-1) && quoteReserve <= uint112(-1), "OVERFLOW");
_BASE_RESERVE_ = uint112(baseReserve);
_QUOTE_RESERVE_ = uint112(quoteReserve);
if(_IS_OPEN_TWAP_) _twapUpdate();
}
function _sync() internal {
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
require(baseBalance <= uint112(-1) && quoteBalance <= uint112(-1), "OVERFLOW");
if (baseBalance != _BASE_RESERVE_) {
_BASE_RESERVE_ = uint112(baseBalance);
}
if (quoteBalance != _QUOTE_RESERVE_) {
_QUOTE_RESERVE_ = uint112(quoteBalance);
}
if(_IS_OPEN_TWAP_) _twapUpdate();
}
function _resetTargetAndReserve() internal {
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
require(baseBalance <= uint112(-1) && quoteBalance <= uint112(-1), "OVERFLOW");
_BASE_RESERVE_ = uint112(baseBalance);
_QUOTE_RESERVE_ = uint112(quoteBalance);
_BASE_TARGET_ = uint112(baseBalance);
_QUOTE_TARGET_ = uint112(quoteBalance);
_RState_ = uint32(PMMPricing.RState.ONE);
if(_IS_OPEN_TWAP_) _twapUpdate();
}
function ratioSync() external preventReentrant onlyOwner {
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
require(baseBalance <= uint112(-1) && quoteBalance <= uint112(-1), "OVERFLOW");
if (baseBalance != _BASE_RESERVE_) {
_BASE_TARGET_ = uint112(uint256(_BASE_TARGET_).mul(baseBalance).div(uint256(_BASE_RESERVE_)));
_BASE_RESERVE_ = uint112(baseBalance);
}
if (quoteBalance != _QUOTE_RESERVE_) {
_QUOTE_TARGET_ = uint112(uint256(_QUOTE_TARGET_).mul(quoteBalance).div(uint256(_QUOTE_RESERVE_)));
_QUOTE_RESERVE_ = uint112(quoteBalance);
}
if(_IS_OPEN_TWAP_) _twapUpdate();
}
function reset(
address assetTo,
uint256 newLpFeeRate,
uint256 newI,
uint256 newK,
uint256 baseOutAmount,
uint256 quoteOutAmount,
uint256 minBaseReserve,
uint256 minQuoteReserve
) public preventReentrant onlyOwner returns (bool) {
require(
_BASE_RESERVE_ >= minBaseReserve && _QUOTE_RESERVE_ >= minQuoteReserve,
"RESERVE_AMOUNT_IS_NOT_ENOUGH"
);
require(newLpFeeRate <= 1e18, "LP_FEE_RATE_OUT_OF_RANGE");
require(newK <= 1e18, "K_OUT_OF_RANGE");
require(newI > 0 && newI <= 1e36, "I_OUT_OF_RANGE");
_LP_FEE_RATE_ = uint64(newLpFeeRate);
_K_ = uint64(newK);
_I_ = uint128(newI);
_transferBaseOut(assetTo, baseOutAmount);
_transferQuoteOut(assetTo, quoteOutAmount);
_resetTargetAndReserve();
emit LpFeeRateChange(newLpFeeRate);
return true;
}
// ============ Asset Out ============
function _transferBaseOut(address to, uint256 amount) internal {
if (amount > 0) {
_BASE_TOKEN_.safeTransfer(to, amount);
}
}
function _transferQuoteOut(address to, uint256 amount) internal {
if (amount > 0) {
_QUOTE_TOKEN_.safeTransfer(to, amount);
}
}
function retrieve(
address to,
address token,
uint256 amount
) external preventReentrant onlyOwner {
require(token != address(_BASE_TOKEN_) && token != address(_QUOTE_TOKEN_), "USE_RESET");
IERC20(token).safeTransfer(to, amount);
}
}
// File: contracts/DODOPrivatePool/impl/DPPTrader.sol
contract DPPTrader is DPPVault {
using SafeMath for uint256;
// ============ Events ============
event DODOSwap(
address fromToken,
address toToken,
uint256 fromAmount,
uint256 toAmount,
address trader,
address receiver
);
event DODOFlashLoan(
address borrower,
address assetTo,
uint256 baseAmount,
uint256 quoteAmount
);
event RChange(PMMPricing.RState newRState);
// ============ Trade Functions ============
function sellBase(address to)
external
preventReentrant
returns (uint256 receiveQuoteAmount)
{
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 baseInput = baseBalance.sub(uint256(_BASE_RESERVE_));
uint256 mtFee;
uint256 newBaseTarget;
PMMPricing.RState newRState;
(receiveQuoteAmount, mtFee, newRState, newBaseTarget) = querySellBase(tx.origin, baseInput);
_transferQuoteOut(to, receiveQuoteAmount);
_transferQuoteOut(_MAINTAINER_, mtFee);
// update TARGET
if (_RState_ != uint32(newRState)) {
require(newBaseTarget <= uint112(-1),"OVERFLOW");
_BASE_TARGET_ = uint112(newBaseTarget);
_RState_ = uint32(newRState);
emit RChange(newRState);
}
_setReserve(baseBalance, _QUOTE_TOKEN_.balanceOf(address(this)));
emit DODOSwap(
address(_BASE_TOKEN_),
address(_QUOTE_TOKEN_),
baseInput,
receiveQuoteAmount,
msg.sender,
to
);
}
function sellQuote(address to)
external
preventReentrant
returns (uint256 receiveBaseAmount)
{
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
uint256 quoteInput = quoteBalance.sub(uint256(_QUOTE_RESERVE_));
uint256 mtFee;
uint256 newQuoteTarget;
PMMPricing.RState newRState;
(receiveBaseAmount, mtFee, newRState, newQuoteTarget) = querySellQuote(
tx.origin,
quoteInput
);
_transferBaseOut(to, receiveBaseAmount);
_transferBaseOut(_MAINTAINER_, mtFee);
// update TARGET
if (_RState_ != uint32(newRState)) {
require(newQuoteTarget <= uint112(-1),"OVERFLOW");
_QUOTE_TARGET_ = uint112(newQuoteTarget);
_RState_ = uint32(newRState);
emit RChange(newRState);
}
_setReserve(_BASE_TOKEN_.balanceOf(address(this)), quoteBalance);
emit DODOSwap(
address(_QUOTE_TOKEN_),
address(_BASE_TOKEN_),
quoteInput,
receiveBaseAmount,
msg.sender,
to
);
}
function flashLoan(
uint256 baseAmount,
uint256 quoteAmount,
address assetTo,
bytes calldata data
) external preventReentrant {
_transferBaseOut(assetTo, baseAmount);
_transferQuoteOut(assetTo, quoteAmount);
if (data.length > 0)
IDODOCallee(assetTo).DPPFlashLoanCall(msg.sender, baseAmount, quoteAmount, data);
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
// no input -> pure loss
require(
baseBalance >= _BASE_RESERVE_ || quoteBalance >= _QUOTE_RESERVE_,
"FLASH_LOAN_FAILED"
);
// sell quote case
// quote input + base output
if (baseBalance < _BASE_RESERVE_) {
uint256 quoteInput = quoteBalance.sub(uint256(_QUOTE_RESERVE_));
(
uint256 receiveBaseAmount,
uint256 mtFee,
PMMPricing.RState newRState,
uint256 newQuoteTarget
) = querySellQuote(tx.origin, quoteInput); // revert if quoteBalance<quoteReserve
require(uint256(_BASE_RESERVE_).sub(baseBalance) <= receiveBaseAmount, "FLASH_LOAN_FAILED");
_transferBaseOut(_MAINTAINER_, mtFee);
if (_RState_ != uint32(newRState)) {
require(newQuoteTarget <= uint112(-1),"OVERFLOW");
_QUOTE_TARGET_ = uint112(newQuoteTarget);
_RState_ = uint32(newRState);
emit RChange(newRState);
}
emit DODOSwap(
address(_QUOTE_TOKEN_),
address(_BASE_TOKEN_),
quoteInput,
receiveBaseAmount,
msg.sender,
assetTo
);
}
// sell base case
// base input + quote output
if (quoteBalance < _QUOTE_RESERVE_) {
uint256 baseInput = baseBalance.sub(uint256(_BASE_RESERVE_));
(
uint256 receiveQuoteAmount,
uint256 mtFee,
PMMPricing.RState newRState,
uint256 newBaseTarget
) = querySellBase(tx.origin, baseInput); // revert if baseBalance<baseReserve
require(uint256(_QUOTE_RESERVE_).sub(quoteBalance) <= receiveQuoteAmount, "FLASH_LOAN_FAILED");
_transferQuoteOut(_MAINTAINER_, mtFee);
if (_RState_ != uint32(newRState)) {
require(newBaseTarget <= uint112(-1),"OVERFLOW");
_BASE_TARGET_ = uint112(newBaseTarget);
_RState_ = uint32(newRState);
emit RChange(newRState);
}
emit DODOSwap(
address(_BASE_TOKEN_),
address(_QUOTE_TOKEN_),
baseInput,
receiveQuoteAmount,
msg.sender,
assetTo
);
}
_sync();
emit DODOFlashLoan(msg.sender, assetTo, baseAmount, quoteAmount);
}
// ============ Query Functions ============
function querySellBase(address trader, uint256 payBaseAmount)
public
view
returns (
uint256 receiveQuoteAmount,
uint256 mtFee,
PMMPricing.RState newRState,
uint256 newBaseTarget
)
{
PMMPricing.PMMState memory state = getPMMState();
(receiveQuoteAmount, newRState) = PMMPricing.sellBaseToken(state, payBaseAmount);
uint256 lpFeeRate = _LP_FEE_RATE_;
uint256 mtFeeRate = _MT_FEE_RATE_MODEL_.getFeeRate(trader);
mtFee = DecimalMath.mulFloor(receiveQuoteAmount, mtFeeRate);
receiveQuoteAmount = receiveQuoteAmount
.sub(DecimalMath.mulFloor(receiveQuoteAmount, lpFeeRate))
.sub(mtFee);
newBaseTarget = state.B0;
}
function querySellQuote(address trader, uint256 payQuoteAmount)
public
view
returns (
uint256 receiveBaseAmount,
uint256 mtFee,
PMMPricing.RState newRState,
uint256 newQuoteTarget
)
{
PMMPricing.PMMState memory state = getPMMState();
(receiveBaseAmount, newRState) = PMMPricing.sellQuoteToken(state, payQuoteAmount);
uint256 lpFeeRate = _LP_FEE_RATE_;
uint256 mtFeeRate = _MT_FEE_RATE_MODEL_.getFeeRate(trader);
mtFee = DecimalMath.mulFloor(receiveBaseAmount, mtFeeRate);
receiveBaseAmount = receiveBaseAmount
.sub(DecimalMath.mulFloor(receiveBaseAmount, lpFeeRate))
.sub(mtFee);
newQuoteTarget = state.Q0;
}
}
// File: contracts/DODOPrivatePool/impl/DPP.sol
/**
* @title DODO PrivatePool
* @author DODO Breeder
*
* @notice DODOPrivatePool initialization
*/
contract DPP is DPPTrader {
function init(
address owner,
address maintainer,
address baseTokenAddress,
address quoteTokenAddress,
uint256 lpFeeRate,
address mtFeeRateModel,
uint256 k,
uint256 i,
bool isOpenTWAP
) external {
initOwner(owner);
require(baseTokenAddress != quoteTokenAddress, "BASE_QUOTE_CAN_NOT_BE_SAME");
_BASE_TOKEN_ = IERC20(baseTokenAddress);
_QUOTE_TOKEN_ = IERC20(quoteTokenAddress);
_MAINTAINER_ = maintainer;
_MT_FEE_RATE_MODEL_ = IFeeRateModel(mtFeeRateModel);
require(lpFeeRate <= 1e18, "LP_FEE_RATE_OUT_OF_RANGE");
require(k <= 1e18, "K_OUT_OF_RANGE");
require(i > 0 && i <= 1e36, "I_OUT_OF_RANGE");
_LP_FEE_RATE_ = uint64(lpFeeRate);
_K_ = uint64(k);
_I_ = uint128(i);
_IS_OPEN_TWAP_ = isOpenTWAP;
if(isOpenTWAP) _BLOCK_TIMESTAMP_LAST_ = uint32(block.timestamp % 2**32);
_resetTargetAndReserve();
}
// ============ Version Control ============
function version() virtual external pure returns (string memory) {
return "DPP 1.0.0";
}
}
// File: contracts/DODOPrivatePool/impl/DPPAdvanced/DPPAdvanced.sol
/**
* @title DODO PrivatePool
* @author DODO Breeder
*
* @notice Advanced DODOPrivatePool
*/
contract DPPAdvanced is DPP {
function tuneParameters(
uint256 newLpFeeRate,
uint256 newI,
uint256 newK,
uint256 minBaseReserve,
uint256 minQuoteReserve
) public preventReentrant onlyOwner returns (bool) {
require(
_BASE_RESERVE_ >= minBaseReserve && _QUOTE_RESERVE_ >= minQuoteReserve,
"RESERVE_AMOUNT_IS_NOT_ENOUGH"
);
require(newLpFeeRate <= 1e18, "LP_FEE_RATE_OUT_OF_RANGE");
require(newK <= 1e18, "K_OUT_OF_RANGE");
require(newI > 0 && newI <= 1e36, "I_OUT_OF_RANGE");
_LP_FEE_RATE_ = uint64(newLpFeeRate);
_K_ = uint64(newK);
_I_ = uint128(newI);
emit LpFeeRateChange(newLpFeeRate);
return true;
}
function tunePrice(
uint256 newI,
uint256 minBaseReserve,
uint256 minQuoteReserve
) public preventReentrant onlyOwner returns (bool) {
require(
_BASE_RESERVE_ >= minBaseReserve && _QUOTE_RESERVE_ >= minQuoteReserve,
"RESERVE_AMOUNT_IS_NOT_ENOUGH"
);
require(newI > 0 && newI <= 1e36, "I_OUT_OF_RANGE");
_I_ = uint128(newI);
return true;
}
// ============ Version Control ============
function version() override external pure returns (string memory) {
return "DPP Advanced 1.0.0";
}
}
Read Contract
_BASE_PRICE_CUMULATIVE_LAST_ 0xfe24cb7f → uint256
_BASE_RESERVE_ 0x7d721504 → uint112
_BASE_TARGET_ 0xe539ef49 → uint112
_BASE_TOKEN_ 0x4a248d2a → address
_BLOCK_TIMESTAMP_LAST_ 0x880a4d87 → uint32
_IS_OPEN_TWAP_ 0x2df6cb48 → bool
_I_ 0xf811d692 → uint128
_K_ 0xec2fd46d → uint64
_LP_FEE_RATE_ 0xab44a7a3 → uint64
_MAINTAINER_ 0x4322ec83 → address
_MT_FEE_RATE_MODEL_ 0xf6b06e70 → address
_NEW_OWNER_ 0x8456db15 → address
_OWNER_ 0x16048bc4 → address
_QUOTE_RESERVE_ 0xbbf5ce78 → uint112
_QUOTE_TARGET_ 0x77f58657 → uint112
_QUOTE_TOKEN_ 0xd4b97046 → address
_RState_ 0xbf357dae → uint32
getBaseInput 0x65f6fcbb → uint256
getMidPrice 0xee27c689 → uint256
getPMMState 0xa382d1b9 → tuple
getPMMStateForCall 0xfd1ed7e9 → uint256, uint256, uint256, uint256, uint256, uint256, uint256
getQuoteInput 0x71f9100c → uint256
getUserFeeRate 0x44096609 → uint256, uint256
getVaultReserve 0x36223ce9 → uint256, uint256
querySellBase 0x79a04876 → uint256, uint256, uint8, uint256
querySellQuote 0x66410a21 → uint256, uint256, uint8, uint256
version 0x54fd4d50 → string
Write Contract 12 functions
These functions modify contract state and require a wallet transaction to execute.
claimOwnership 0x4e71e0c8
No parameters
flashLoan 0xd0a494e4
uint256 baseAmount
uint256 quoteAmount
address assetTo
bytes data
init 0x01a3c30b
address owner
address maintainer
address baseTokenAddress
address quoteTokenAddress
uint256 lpFeeRate
address mtFeeRateModel
uint256 k
uint256 i
bool isOpenTWAP
initOwner 0x0d009297
address newOwner
ratioSync 0xc57a5d03
No parameters
reset 0x8ff3928c
address assetTo
uint256 newLpFeeRate
uint256 newI
uint256 newK
uint256 baseOutAmount
uint256 quoteOutAmount
uint256 minBaseReserve
uint256 minQuoteReserve
returns: bool
retrieve 0x28c4e24c
address to
address token
uint256 amount
sellBase 0xbd6015b4
address to
returns: uint256
sellQuote 0xdd93f59a
address to
returns: uint256
transferOwnership 0xf2fde38b
address newOwner
tuneParameters 0x3b20884a
uint256 newLpFeeRate
uint256 newI
uint256 newK
uint256 minBaseReserve
uint256 minQuoteReserve
returns: bool
tunePrice 0x10d76460
uint256 newI
uint256 minBaseReserve
uint256 minQuoteReserve
returns: bool
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 →