Skip to content

Commit

Permalink
Revert "add back TicksToSqrtPrices"
Browse files Browse the repository at this point in the history
This reverts commit 50410c4.
  • Loading branch information
czarcas7ic committed Jan 11, 2023
1 parent 50410c4 commit 794e3b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
12 changes: 2 additions & 10 deletions x/concentrated-liquidity/internal/math/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var sdkTenDec = sdk.NewDec(10)
// TicksToPrice returns the price for the lower and upper ticks.
// Returns error if fails to calculate price.
// TODO: spec and tests
func TicksToSqrtPrice(lowerTick, upperTick int64, exponentAtPriceOne sdk.Int) (sdk.Dec, sdk.Dec, error) {
func TicksToPrice(lowerTick, upperTick int64, exponentAtPriceOne sdk.Int) (sdk.Dec, sdk.Dec, error) {
priceUpperTick, err := TickToPrice(sdk.NewInt(upperTick), exponentAtPriceOne)
if err != nil {
return sdk.Dec{}, sdk.Dec{}, err
Expand All @@ -24,15 +24,7 @@ func TicksToSqrtPrice(lowerTick, upperTick int64, exponentAtPriceOne sdk.Int) (s
if err != nil {
return sdk.Dec{}, sdk.Dec{}, err
}
sqrtPriceUpperTick, err := priceLowerTick.ApproxSqrt()
if err != nil {
return sdk.Dec{}, sdk.Dec{}, err
}
sqrtPriceLowerTick, err := priceUpperTick.ApproxSqrt()
if err != nil {
return sdk.Dec{}, sdk.Dec{}, err
}
return sqrtPriceLowerTick, sqrtPriceUpperTick, nil
return priceLowerTick, priceUpperTick, nil
}

// TickToPrice returns the price given the following two arguments:
Expand Down
28 changes: 24 additions & 4 deletions x/concentrated-liquidity/lp.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@ func (k Keeper) createPosition(ctx sdk.Context, poolId uint64, owner sdk.AccAddr
return sdk.Int{}, sdk.Int{}, sdk.Dec{}, err
}

// Transform the provided ticks into their corresponding sqrt prices.
sqrtPriceLowerTick, sqrtPriceUpperTick, err := math.TicksToSqrtPrice(lowerTick, upperTick, pool.GetPrecisionFactorAtPriceOne())
// Transform the provided ticks into their corresponding prices.
priceLowerTick, priceUpperTick, err := math.TicksToPrice(lowerTick, upperTick, pool.GetPrecisionFactorAtPriceOne())
if err != nil {
return sdk.Int{}, sdk.Int{}, sdk.Dec{}, err
}

// Transform the provided prices into their corresponding square root prices.
sqrtPriceLowerTick, err := priceLowerTick.ApproxSqrt()
if err != nil {
return sdk.Int{}, sdk.Int{}, sdk.Dec{}, err
}
sqrtPriceUpperTick, err := priceUpperTick.ApproxSqrt()
if err != nil {
return sdk.Int{}, sdk.Int{}, sdk.Dec{}, err
}
Expand Down Expand Up @@ -170,8 +180,18 @@ func (k Keeper) updatePosition(ctx sdk.Context, poolId uint64, owner sdk.AccAddr
return sdk.Int{}, sdk.Int{}, err
}

// Transform the provided ticks into their corresponding sqrt prices.
sqrtPriceLowerTick, sqrtPriceUpperTick, err := math.TicksToSqrtPrice(lowerTick, upperTick, pool.GetPrecisionFactorAtPriceOne())
// Transform the provided ticks into their corresponding prices.
priceLowerTick, priceUpperTick, err := math.TicksToPrice(lowerTick, upperTick, pool.GetPrecisionFactorAtPriceOne())
if err != nil {
return sdk.Int{}, sdk.Int{}, err
}

// Transform the provided prices into their corresponding square root prices.
sqrtPriceLowerTick, err := priceLowerTick.ApproxSqrt()
if err != nil {
return sdk.Int{}, sdk.Int{}, err
}
sqrtPriceUpperTick, err := priceUpperTick.ApproxSqrt()
if err != nil {
return sdk.Int{}, sdk.Int{}, err
}
Expand Down

0 comments on commit 794e3b1

Please sign in to comment.