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

[CL]: Abstract priceToTick loop to helper function #3985

Closed
czarcas7ic opened this issue Jan 11, 2023 · 0 comments · Fixed by #4133
Closed

[CL]: Abstract priceToTick loop to helper function #3985

czarcas7ic opened this issue Jan 11, 2023 · 0 comments · Fixed by #4133
Assignees
Labels
C:x/concentrated-liquidity F: concentrated-liquidity Tracking the development of concentrated liquidity feature to improve filtering on the project board

Comments

@czarcas7ic
Copy link
Member

czarcas7ic commented Jan 11, 2023

Background

When computing PriceToTick, we currently loop through exponents (incrementing or decrementing depending on if the desired price is above or below 1) until we reach the first exponent that is greater than the desired price:

if price.GT(sdk.OneDec()) {
for currentPrice.LT(price) {
currentAdditiveIncrementInTicks = powTenBigDec(exponentAtCurrentTick)
maxPriceForCurrentAdditiveIncrementInTicks := osmomath.BigDecFromSDKDec(geometricExponentIncrementDistanceInTicks).Mul(currentAdditiveIncrementInTicks)
currentPrice = currentPrice.Add(maxPriceForCurrentAdditiveIncrementInTicks.SDKDec())
exponentAtCurrentTick = exponentAtCurrentTick.Add(sdk.OneInt())
ticksPassed = ticksPassed.Add(geometricExponentIncrementDistanceInTicks.TruncateInt())
}
} else {
// We must decrement the exponentAtCurrentTick by one when traversing negative ticks in order to constantly step up in precision when going further down in ticks
// Otherwise, from tick 0 to tick -(geometricExponentIncrementDistanceInTicks), we would use the same exponent as the exponentAtPriceOne
exponentAtCurrentTick := exponentAtPriceOne.Sub(sdk.OneInt())
for currentPrice.GT(price) {
currentAdditiveIncrementInTicks = powTenBigDec(exponentAtCurrentTick)
maxPriceForCurrentAdditiveIncrementInTicks := osmomath.BigDecFromSDKDec(geometricExponentIncrementDistanceInTicks).Mul(currentAdditiveIncrementInTicks)
currentPrice = currentPrice.Sub(maxPriceForCurrentAdditiveIncrementInTicks.SDKDec())
exponentAtCurrentTick = exponentAtCurrentTick.Sub(sdk.OneInt())
ticksPassed = ticksPassed.Sub(geometricExponentIncrementDistanceInTicks.TruncateInt())
}
}

This should be abstracted into a helper function with tests.

#3874 (comment)

Suggested Design

Abstract the logic into a helper function located within tick.go.

Acceptance Criteria

  • Logic is abstracted into a helper function
  • That helper function is well tested with gotests
@czarcas7ic czarcas7ic added C:x/concentrated-liquidity F: concentrated-liquidity Tracking the development of concentrated liquidity feature to improve filtering on the project board labels Jan 11, 2023
This was referenced Jan 12, 2023
@czarcas7ic czarcas7ic self-assigned this Jan 13, 2023
@p0mvn p0mvn added this to the CL 8: Fees and Misc Bug Fixes milestone Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/concentrated-liquidity F: concentrated-liquidity Tracking the development of concentrated liquidity feature to improve filtering on the project board
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants