diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index da33dc04764..4805202c705 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -183,9 +183,9 @@ func GetLiquidityFromAmounts(sqrtPrice, sqrtPriceA, sqrtPriceB sdk.Dec, amount0, if sqrtPrice.LTE(sqrtPriceA) { // If the current price is less than or equal to the lower tick, then we use the liquidity0 formula. liquidity = Liquidity0(amount0, sqrtPriceA, sqrtPriceB) - } else if sqrtPrice.LTE(sqrtPriceB) { - // If the current price is between the lower and upper ticks (non-inclusive of the lower tick but inclusive of the upper tick), - // then we use the minimum of the liquidity0 and liquidity1 formulas. + } else if sqrtPrice.LT(sqrtPriceB) { + // If the current price is between the lower and upper ticks (exclusive of both the lower and upper ticks, + // as both would trigger a division by zero), then we use the minimum of the liquidity0 and liquidity1 formulas. liquidity0 := Liquidity0(amount0, sqrtPrice, sqrtPriceB) liquidity1 := Liquidity1(amount1, sqrtPrice, sqrtPriceA) liquidity = sdk.MinDec(liquidity0, liquidity1) diff --git a/x/concentrated-liquidity/math/math_test.go b/x/concentrated-liquidity/math/math_test.go index 30da7a6dbfc..5fbd329cd75 100644 --- a/x/concentrated-liquidity/math/math_test.go +++ b/x/concentrated-liquidity/math/math_test.go @@ -413,6 +413,16 @@ func (suite *ConcentratedMathTestSuite) TestGetLiquidityFromAmounts() { expectedLiquidity0: sdk.MustNewDecFromStr("7.706742302257039729"), expectedLiquidity1: sdk.MustNewDecFromStr("4.828427124746190095"), }, + "current sqrt price on upper bound": { + currentSqrtP: sqrt5500, + sqrtPHigh: sqrt5500, + sqrtPLow: sqrt4545, + amount0Desired: sdk.ZeroInt(), + amount1Desired: sdk.NewInt(1000000), + // Liquidity1 = amount1 / (sqrtPriceB - sqrtPriceA) + // https://www.wolframalpha.com/input?i=1000000%2F%2874.161984870956629487-67.416615162732695594%29 + expectedLiquidity: "148249.842967213952971325", + }, } for name, tc := range testCases {