Skip to content

Commit

Permalink
change roundTick to roundTickToCanonicalPriceTick
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed May 15, 2023
1 parent 814ea89 commit a74fbd6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions x/concentrated-liquidity/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func (k Keeper) SetPositionIdToLock(ctx sdk.Context, positionId, underlyingLockI
k.setPositionIdToLock(ctx, positionId, underlyingLockId)
}

func RoundTick(lowerTick, upperTick int64, priceTickLower, priceTickUpper sdk.Dec, tickSpacing uint64) (int64, int64, error) {
return roundTick(lowerTick, upperTick, priceTickLower, priceTickUpper, tickSpacing)
func RoundTickToCanonicalPriceTick(lowerTick, upperTick int64, priceTickLower, priceTickUpper sdk.Dec, tickSpacing uint64) (int64, int64, error) {
return roundTickToCanonicalPriceTick(lowerTick, upperTick, priceTickLower, priceTickUpper, tickSpacing)
}

// fees methods
Expand Down
2 changes: 1 addition & 1 deletion x/concentrated-liquidity/lp.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (k Keeper) createPosition(ctx sdk.Context, poolId uint64, owner sdk.AccAddr
}

// If multiple ticks can represent the same spot price, ensure we are using the largest of those ticks.
lowerTick, upperTick, err = roundTick(lowerTick, upperTick, priceLowerTick, priceUpperTick, pool.GetTickSpacing())
lowerTick, upperTick, err = roundTickToCanonicalPriceTick(lowerTick, upperTick, priceLowerTick, priceUpperTick, pool.GetTickSpacing())
if err != nil {
return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err
}
Expand Down
4 changes: 2 additions & 2 deletions x/concentrated-liquidity/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ func validateTickRangeIsValid(tickSpacing uint64, lowerTick int64, upperTick int
return nil
}

// roundTick takes a tick and determines if multiple ticks can represent the same price as the provided tick. If so, it
// roundTickToCanonicalPriceTick takes a tick and determines if multiple ticks can represent the same price as the provided tick. If so, it
// rounds that tick up to the largest tick that can represent the same price that the original tick corresponded to. If one of
// the two ticks happen to be rounded, we re-validate the tick range to ensure that the tick range is still valid.
//
// i.e. the provided tick is -161795100. With our precision, this tick correlates to a sqrtPrice of 0.000000001414213563
// the first tick (given our precision) that is able to represent this price is -161000000, so we use this tick instead.
//
// This really only applies to very small tick values, as the increment of a single tick continues to get smaller as the tick value gets smaller.
func roundTick(lowerTick, upperTick int64, priceTickLower, priceTickUpper sdk.Dec, tickSpacing uint64) (int64, int64, error) {
func roundTickToCanonicalPriceTick(lowerTick, upperTick int64, priceTickLower, priceTickUpper sdk.Dec, tickSpacing uint64) (int64, int64, error) {
newLowerTick, err := math.PriceToTickRoundDown(priceTickLower, tickSpacing)
if err != nil {
return 0, 0, err
Expand Down
4 changes: 2 additions & 2 deletions x/concentrated-liquidity/tick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ func (s *KeeperTestSuite) TestGetAllInitializedTicksForPool() {
}
}

func (s *KeeperTestSuite) TestRoundTick() {
func (s *KeeperTestSuite) TestRoundTickToCanonicalPriceTick() {
tests := []struct {
name string
lowerTick int64
Expand Down Expand Up @@ -1480,7 +1480,7 @@ func (s *KeeperTestSuite) TestRoundTick() {
s.Require().NoError(err)

// System Under Test
newLowerTick, newUpperTick, err := cl.RoundTick(test.lowerTick, test.upperTick, priceTickLower, priceTickUpper, DefaultTickSpacing)
newLowerTick, newUpperTick, err := cl.RoundTickToCanonicalPriceTick(test.lowerTick, test.upperTick, priceTickLower, priceTickUpper, DefaultTickSpacing)

if test.expectedError != nil {
s.Require().Error(err)
Expand Down

0 comments on commit a74fbd6

Please sign in to comment.