diff --git a/x/concentrated-liquidity/math/tick_test.go b/x/concentrated-liquidity/math/tick_test.go index 1372a5f9d30..57d8a476bcb 100644 --- a/x/concentrated-liquidity/math/tick_test.go +++ b/x/concentrated-liquidity/math/tick_test.go @@ -891,3 +891,40 @@ func TestSqrtPriceToTickRoundDownSpacing(t *testing.T) { }) } } + +func TestMonotnicityAtPriceBounds(t *testing.T) { + // Note: this starting value was manually adjusted until it was on the boundary of where the + // ticks started becoming monotonic + x := int64(-108000002) + lastValueMonotonic := true + highestMonotonicTick := types.MinInitializedTick + + // Find the highest tick where the sqrt price is monotonic. If nothing is found in 50,000 ticks, + // lastValueMonotonic is false and starting value should be adjusted. + for i := 0; i < 50000; i++ { + _, xSqrtPrice, err := math.TickToSqrtPrice(x) + require.NoError(t, err) + _, xSqrtPriceNext, err := math.TickToSqrtPrice(x + 1) + require.NoError(t, err) + if xSqrtPrice.GTE(xSqrtPriceNext) { + fmt.Printf("Non-monotonic behavior detected at x = %d\n", x) + lastValueMonotonic = false + } else if !lastValueMonotonic { + highestMonotonicTick = x + lastValueMonotonic = true + } else { + lastValueMonotonic = true + } + x++ + } + fmt.Println("Last value was monotonic: ", lastValueMonotonic) + + // highestMonotonicTick lands on tick -108000000 + fmt.Println("Highest monotonic tick: ", highestMonotonicTick) + + // smallestSupportedPrice = 10^-12 + smallestSupportedPrice, smallestSqrtPrice, err := math.TickToSqrtPrice(highestMonotonicTick) + require.NoError(t, err) + fmt.Println("smallestSupportedPrice: ", smallestSupportedPrice) + fmt.Println("smallestSqrtPrice: ", smallestSqrtPrice) +} diff --git a/x/concentrated-liquidity/types/constants.go b/x/concentrated-liquidity/types/constants.go index b2ddc0a3b96..636d443b432 100644 --- a/x/concentrated-liquidity/types/constants.go +++ b/x/concentrated-liquidity/types/constants.go @@ -10,7 +10,7 @@ import ( const ( // Precomputed values for min and max tick - MinInitializedTick, MaxTick int64 = -108000000, 342000000 + MinInitializedTick, MaxTick int64 = -162000000, 342000000 // If we consume all liquidity and cross the min initialized tick, // our current tick will equal to MinInitializedTick - 1 with zero liquidity. // However, note that this tick cannot be crossed. If current tick @@ -28,7 +28,7 @@ const ( var ( MaxSpotPrice = sdk.MustNewDecFromStr("100000000000000000000000000000000000000") - MinSpotPrice = sdk.MustNewDecFromStr("0.000000000001") // 10^-12 + MinSpotPrice = sdk.MustNewDecFromStr("0.000000000000000001") // 10^-12 MaxSqrtPrice = osmomath.MustMonotonicSqrt(MaxSpotPrice) MinSqrtPrice = osmomath.MustMonotonicSqrt(MinSpotPrice) MaxSqrtPriceBigDec = osmomath.BigDecFromSDKDec(MaxSqrtPrice)