From 2323ccb6eb054ea0378c2e37071b0521da73d409 Mon Sep 17 00:00:00 2001 From: mingda Date: Mon, 30 Nov 2020 11:59:55 +0800 Subject: [PATCH] support k = 0 case --- contracts/lib/DODOMath.sol | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/contracts/lib/DODOMath.sol b/contracts/lib/DODOMath.sol index 34c5fab..408e92b 100644 --- a/contracts/lib/DODOMath.sol +++ b/contracts/lib/DODOMath.sol @@ -29,6 +29,8 @@ library DODOMath { i is the price of res-V trading pair + support k=1 & k=0 case + [round down] */ function _GeneralIntegrate( @@ -53,6 +55,8 @@ library DODOMath { i is the price of delta-V trading pair give out target of V + support k=1 & k=0 case + [round down] */ function _SolveQuadraticFunctionForTarget( @@ -60,7 +64,10 @@ library DODOMath { uint256 delta, uint256 i, uint256 k - ) internal pure returns (uint256 V0) { + ) 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 @@ -93,6 +100,8 @@ library DODOMath { i is the price of delta-V trading pair + support k=1 & k=0 case + [round down] */ function _SolveQuadraticFunctionForTrade( @@ -107,6 +116,10 @@ library DODOMath { return 0; } + if (k == 0) { + return DecimalMath.mulFloor(i, delta); + } + if (k == DecimalMath.ONE) { // if k==1 // Q2=Q1/(1+ideltaBQ1/Q0/Q0)