From 89c2a634b457801e324d9ca8b8e60fecc6fcbf8f Mon Sep 17 00:00:00 2001 From: alpo Date: Wed, 14 Jun 2023 13:30:55 -0700 Subject: [PATCH] demo monotonicity bound for canonical ticks --- x/concentrated-liquidity/math/tick_test.go | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/x/concentrated-liquidity/math/tick_test.go b/x/concentrated-liquidity/math/tick_test.go index 578bbbebd8e..02fadd33348 100644 --- a/x/concentrated-liquidity/math/tick_test.go +++ b/x/concentrated-liquidity/math/tick_test.go @@ -714,3 +714,40 @@ func (suite *ConcentratedMathTestSuite) TestCalculatePriceToTick() { }) } } + +func (suite *ConcentratedMathTestSuite) TestMonotnicityAtPriceBounds() { + // 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.MinTick + + // 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) + suite.Require().NoError(err) + _, xSqrtPriceNext, err := math.TickToSqrtPrice(x + 1) + suite.Require().NoError(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) + suite.Require().NoError(err) + fmt.Println("smallestSupportedPrice: ", smallestSupportedPrice) + fmt.Println("smallestSqrtPrice: ", smallestSqrtPrice) +}