Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: proof non-monotonicity with low precision #6019

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions x/concentrated-liquidity/math/tick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions x/concentrated-liquidity/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down