From ee915a97c5c1d5fd78e12016f38b10931a67f687 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Tue, 16 May 2023 15:06:39 -0500 Subject: [PATCH 1/4] initial push --- osmomath/decimal.go | 4 - osmomath/int.go | 2 - proto/osmosis/concentrated-liquidity/tx.proto | 6 + tests/e2e/e2e_test.go | 8 +- x/concentrated-liquidity/README.md | 9 + x/concentrated-liquidity/bench_test.go | 4 +- x/concentrated-liquidity/export_internal.go | 2 +- x/concentrated-liquidity/export_test.go | 6 +- x/concentrated-liquidity/fees_test.go | 6 +- x/concentrated-liquidity/incentives_test.go | 6 +- x/concentrated-liquidity/keeper_test.go | 6 +- x/concentrated-liquidity/lp.go | 51 ++-- x/concentrated-liquidity/lp_test.go | 91 +++++-- x/concentrated-liquidity/math/tick.go | 22 +- x/concentrated-liquidity/math/tick_test.go | 9 +- x/concentrated-liquidity/model/pool.go | 2 +- x/concentrated-liquidity/model/pool_test.go | 6 +- x/concentrated-liquidity/msg_server.go | 4 +- x/concentrated-liquidity/pool_test.go | 6 +- x/concentrated-liquidity/position.go | 2 +- x/concentrated-liquidity/position_test.go | 16 +- x/concentrated-liquidity/swaps.go | 4 +- x/concentrated-liquidity/swaps_test.go | 34 +-- x/concentrated-liquidity/tick.go | 35 ++- x/concentrated-liquidity/tick_test.go | 4 +- x/concentrated-liquidity/types/tx.pb.go | 241 ++++++++++++------ 26 files changed, 384 insertions(+), 202 deletions(-) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index 1b8e21ce001..03b6fea77bf 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -887,16 +887,12 @@ func MaxDec(d1, d2 BigDec) BigDec { // DecEq returns true if two given decimals are equal. // Intended to be used with require/assert: require.True(t, DecEq(...)) -// -//nolint:thelper func DecEq(t *testing.T, exp, got BigDec) (*testing.T, bool, string, string, string) { return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() } // DecApproxEq returns true if the differences between two given decimals are smaller than the tolerance range. // Intended to be used with require/assert: require.True(t, DecEq(...)) -// -//nolint:thelper func DecApproxEq(t *testing.T, d1 BigDec, d2 BigDec, tol BigDec) (*testing.T, bool, string, string, string) { diff := d1.Sub(d2).Abs() return t, diff.LTE(tol), "expected |d1 - d2| <:\t%v\ngot |d1 - d2| = \t\t%v", tol.String(), diff.String() diff --git a/osmomath/int.go b/osmomath/int.go index 6b2fe80025d..c3ae4ef288e 100644 --- a/osmomath/int.go +++ b/osmomath/int.go @@ -435,8 +435,6 @@ func (i BigInt) MarshalAmino() ([]byte, error) { return i.Marshal() } func (i *BigInt) UnmarshalAmino(bz []byte) error { return i.Unmarshal(bz) } // intended to be used with require/assert: require.True(IntEq(...)) -// -//nolint:thelper func IntEq(t *testing.T, exp, got BigInt) (*testing.T, bool, string, string, string) { return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() } diff --git a/proto/osmosis/concentrated-liquidity/tx.proto b/proto/osmosis/concentrated-liquidity/tx.proto index 1f36da41f93..217961db2e0 100644 --- a/proto/osmosis/concentrated-liquidity/tx.proto +++ b/proto/osmosis/concentrated-liquidity/tx.proto @@ -69,6 +69,12 @@ message MsgCreatePositionResponse { (gogoproto.moretags) = "yaml:\"liquidity_created\"", (gogoproto.nullable) = false ]; + // the lower and upper tick are in the response because there are + // instances in which multiple ticks represent the same price, so + // we may move their provided tick to the canonical tick that represents + // the same price. + int64 lower_tick = 6 [ (gogoproto.moretags) = "yaml:\"lower_tick\"" ]; + int64 upper_tick = 7 [ (gogoproto.moretags) = "yaml:\"upper_tick\"" ]; } // ===================== MsgAddToPosition diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 8c9448baedc..63f60d3ee92 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -371,9 +371,9 @@ func (s *IntegrationTestSuite) TestConcentratedLiquidity() { nextInitTick := sdk.NewInt(40000) // address1 position1's upper tick // Calculate sqrtPrice after and at the next initialized tick (upperTick of address1 position1 - 40000) - sqrtPriceAfterNextInitializedTick, err := cl.TickToSqrtPrice(nextInitTick.Add(tickOffset)) + _, sqrtPriceAfterNextInitializedTick, err := cl.TickToSqrtPrice(nextInitTick.Add(tickOffset)) s.Require().NoError(err) - sqrtPriceAtNextInitializedTick, err := cl.TickToSqrtPrice(nextInitTick) + _, sqrtPriceAtNextInitializedTick, err := cl.TickToSqrtPrice(nextInitTick) s.Require().NoError(err) // Calculate Δ(sqrtPrice): @@ -513,9 +513,9 @@ func (s *IntegrationTestSuite) TestConcentratedLiquidity() { // Using: CalcAmount0Delta = liquidity * ((sqrtPriceB - sqrtPriceA) / (sqrtPriceB * sqrtPriceA)) // Calculate sqrtPrice after and at the next initialized tick (which is upperTick of address1 position1 - 40000) - sqrtPricebBelowNextInitializedTick, err := cl.TickToSqrtPrice(nextInitTick.Sub(tickOffset)) + _, sqrtPricebBelowNextInitializedTick, err := cl.TickToSqrtPrice(nextInitTick.Sub(tickOffset)) s.Require().NoError(err) - sqrtPriceAtNextInitializedTick, err = cl.TickToSqrtPrice(nextInitTick) + _, sqrtPriceAtNextInitializedTick, err = cl.TickToSqrtPrice(nextInitTick) s.Require().NoError(err) // Calculate numerators diff --git a/x/concentrated-liquidity/README.md b/x/concentrated-liquidity/README.md index aba9414ad13..57de9236d00 100644 --- a/x/concentrated-liquidity/README.md +++ b/x/concentrated-liquidity/README.md @@ -284,6 +284,15 @@ a) Preventing trade at a desirable spot price or b) Having the front end round the tick's actual price to the nearest human readable/desirable spot price +One side effect of increasing precision as we get closer to the minimum tick +is that multiple ticks can represent the same price. For example, tick +-161795100 (along with the ticks surrounding it) correlate to a price +of 0.000000000000000002. To get around any issues this may cause, when a +position is created with a user defined lower and upper tick, we determine +if a larger tick exists that represents the same price. If so, we use that tick +instead of the user defined tick. In the above example, the tick would be +changed to -161000000, which is the first tick that represents the same price. + ## Concentrated Liquidity Module Messages ### `MsgCreatePosition` diff --git a/x/concentrated-liquidity/bench_test.go b/x/concentrated-liquidity/bench_test.go index 43cefad5a2a..3720e78c7b7 100644 --- a/x/concentrated-liquidity/bench_test.go +++ b/x/concentrated-liquidity/bench_test.go @@ -23,7 +23,7 @@ type BenchTestSuite struct { func (s BenchTestSuite) createPosition(accountIndex int, poolId uint64, coin0, coin1 sdk.Coin, lowerTick, upperTick int64) { tokensDesired := sdk.NewCoins(coin0, coin1) - _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, poolId, s.TestAccs[accountIndex], tokensDesired, sdk.ZeroInt(), sdk.ZeroInt(), lowerTick, upperTick) + _, _, _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, poolId, s.TestAccs[accountIndex], tokensDesired, sdk.ZeroInt(), sdk.ZeroInt(), lowerTick, upperTick) if err != nil { // This can happen for ticks that map to the very small prices // e.g 2 * 10^(-18) ends up mapping to the same sqrt price @@ -100,7 +100,7 @@ func BenchmarkSwapExactAmountIn(b *testing.B) { tokenDesired0 := sdk.NewCoin(denom0, sdk.NewInt(100)) tokenDesired1 := sdk.NewCoin(denom1, sdk.NewInt(100)) tokensDesired := sdk.NewCoins(tokenDesired0, tokenDesired1) - _, _, _, _, _, err = clKeeper.CreatePosition(s.Ctx, poolId, s.TestAccs[0], tokensDesired, sdk.ZeroInt(), sdk.ZeroInt(), types.MinTick, types.MaxTick) + _, _, _, _, _, _, _, err = clKeeper.CreatePosition(s.Ctx, poolId, s.TestAccs[0], tokensDesired, sdk.ZeroInt(), sdk.ZeroInt(), types.MinTick, types.MaxTick) pool, err := clKeeper.GetPoolById(s.Ctx, poolId) noError(err) diff --git a/x/concentrated-liquidity/export_internal.go b/x/concentrated-liquidity/export_internal.go index 669464fb038..4eb7cb713a4 100644 --- a/x/concentrated-liquidity/export_internal.go +++ b/x/concentrated-liquidity/export_internal.go @@ -6,6 +6,6 @@ import ( "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/math" ) -func TickToSqrtPrice(tickIndex sdk.Int) (price sdk.Dec, err error) { +func TickToSqrtPrice(tickIndex sdk.Int) (price sdk.Dec, sqrtPrice sdk.Dec, err error) { return math.TickToSqrtPrice(tickIndex) } diff --git a/x/concentrated-liquidity/export_test.go b/x/concentrated-liquidity/export_test.go index 682ff6254a3..4ef0a24224a 100644 --- a/x/concentrated-liquidity/export_test.go +++ b/x/concentrated-liquidity/export_test.go @@ -158,6 +158,10 @@ func (k Keeper) SetPositionIdToLock(ctx sdk.Context, positionId, underlyingLockI k.setPositionIdToLock(ctx, positionId, underlyingLockId) } +func RoundTickToCanonicalPriceTick(lowerTick, upperTick int64, priceTickLower, priceTickUpper sdk.Dec, tickSpacing uint64) (int64, int64, error) { + return roundTickToCanonicalPriceTick(lowerTick, upperTick, priceTickLower, priceTickUpper, tickSpacing) +} + // fees methods func (k Keeper) CreateFeeAccumulator(ctx sdk.Context, poolId uint64) error { return k.createFeeAccumulator(ctx, poolId) @@ -191,7 +195,7 @@ func PreparePositionAccumulator(feeAccumulator accum.AccumulatorObject, position return preparePositionAccumulator(feeAccumulator, positionKey, feeGrowthOutside) } -func (k Keeper) CreatePosition(ctx sdk.Context, poolId uint64, owner sdk.AccAddress, tokensProvided sdk.Coins, amount0Min, amount1Min sdk.Int, lowerTick, upperTick int64) (uint64, sdk.Int, sdk.Int, sdk.Dec, time.Time, error) { +func (k Keeper) CreatePosition(ctx sdk.Context, poolId uint64, owner sdk.AccAddress, tokensProvided sdk.Coins, amount0Min, amount1Min sdk.Int, lowerTick, upperTick int64) (positionId uint64, actualAmount0 sdk.Int, actualAmount1 sdk.Int, liquidityDelta sdk.Dec, joinTime time.Time, lowerTickResult int64, upperTickResult int64, err error) { return k.createPosition(ctx, poolId, owner, tokensProvided, amount0Min, amount1Min, lowerTick, upperTick) } diff --git a/x/concentrated-liquidity/fees_test.go b/x/concentrated-liquidity/fees_test.go index 0ee5d92b940..0cb7231928a 100644 --- a/x/concentrated-liquidity/fees_test.go +++ b/x/concentrated-liquidity/fees_test.go @@ -1503,7 +1503,7 @@ func (s *KeeperTestSuite) TestFunctional_Fees_LP() { s.Require().Error(err) // Create position in the default range 1. - positionIdOne, _, _, liquidity, _, err := concentratedLiquidityKeeper.CreatePosition(ctx, pool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + positionIdOne, _, _, liquidity, _, _, _, err := concentratedLiquidityKeeper.CreatePosition(ctx, pool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) // Swap once. @@ -1527,7 +1527,7 @@ func (s *KeeperTestSuite) TestFunctional_Fees_LP() { s.validatePositionFeeGrowth(pool.GetId(), positionIdOne, cl.EmptyCoins) // Create position in the default range 2. - positionIdTwo, _, _, fullLiquidity, _, err := concentratedLiquidityKeeper.CreatePosition(ctx, pool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + positionIdTwo, _, _, fullLiquidity, _, _, _, err := concentratedLiquidityKeeper.CreatePosition(ctx, pool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) // Swap once in the other direction. @@ -1555,7 +1555,7 @@ func (s *KeeperTestSuite) TestFunctional_Fees_LP() { s.Require().Equal(expectesFeesCollected.String(), feesCollected.AmountOf(ETH).String()) // Create position in the default range 3. - positionIdThree, _, _, fullLiquidity, _, err := concentratedLiquidityKeeper.CreatePosition(ctx, pool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + positionIdThree, _, _, fullLiquidity, _, _, _, err := concentratedLiquidityKeeper.CreatePosition(ctx, pool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) collectedThree, err := s.App.ConcentratedLiquidityKeeper.CollectFees(ctx, owner, positionIdThree) diff --git a/x/concentrated-liquidity/incentives_test.go b/x/concentrated-liquidity/incentives_test.go index f39ef5acd0a..68e2ed667b4 100644 --- a/x/concentrated-liquidity/incentives_test.go +++ b/x/concentrated-liquidity/incentives_test.go @@ -940,7 +940,7 @@ func (s *KeeperTestSuite) TestUpdateUptimeAccumulatorsToNow() { if !tc.isInvalidBalancerPool { depositedCoins := sdk.NewCoins(sdk.NewCoin(clPool.GetToken0(), testQualifyingDepositsOne), sdk.NewCoin(clPool.GetToken1(), testQualifyingDepositsOne)) s.FundAcc(testAddressOne, depositedCoins) - _, _, _, qualifyingLiquidity, _, err = clKeeper.CreatePosition(s.Ctx, clPool.GetId(), testAddressOne, depositedCoins, sdk.ZeroInt(), sdk.ZeroInt(), clPool.GetCurrentTick().Int64()-100, clPool.GetCurrentTick().Int64()+100) + _, _, _, qualifyingLiquidity, _, _, _, err = clKeeper.CreatePosition(s.Ctx, clPool.GetId(), testAddressOne, depositedCoins, sdk.ZeroInt(), sdk.ZeroInt(), clPool.GetCurrentTick().Int64()-100, clPool.GetCurrentTick().Int64()+100) s.Require().NoError(err) // If a canonical balancer pool exists, we add its respective shares to the qualifying amount as well. @@ -3589,7 +3589,7 @@ func (s *KeeperTestSuite) TestFunctional_ClaimIncentices_LiquidityChange_Varying s.Require().NoError(err) // Set up position - positionIdOne, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, defaultPoolId, defaultAddress, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + positionIdOne, _, _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, defaultPoolId, defaultAddress, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) // Increase block time by the fully charged duration (first time) @@ -3604,7 +3604,7 @@ func (s *KeeperTestSuite) TestFunctional_ClaimIncentices_LiquidityChange_Varying s.Ctx = s.Ctx.WithBlockTime(s.Ctx.BlockTime().Add(testFullChargeDuration)) // Create another position - positionIdTwo, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, defaultPoolId, defaultAddress, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + positionIdTwo, _, _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, defaultPoolId, defaultAddress, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) // Increase block time by the fully charged duration (third time) diff --git a/x/concentrated-liquidity/keeper_test.go b/x/concentrated-liquidity/keeper_test.go index 5c815c91aad..0abfb7885f5 100644 --- a/x/concentrated-liquidity/keeper_test.go +++ b/x/concentrated-liquidity/keeper_test.go @@ -74,7 +74,7 @@ func (s *KeeperTestSuite) SetupDefaultPosition(poolId uint64) { func (s *KeeperTestSuite) SetupPosition(poolId uint64, owner sdk.AccAddress, providedCoins sdk.Coins, lowerTick, upperTick int64, joinTime time.Time) (sdk.Dec, uint64) { s.FundAcc(owner, providedCoins) - positionId, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, poolId, owner, providedCoins, sdk.ZeroInt(), sdk.ZeroInt(), lowerTick, upperTick) + positionId, _, _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, poolId, owner, providedCoins, sdk.ZeroInt(), sdk.ZeroInt(), lowerTick, upperTick) s.Require().NoError(err) liquidity, err := s.App.ConcentratedLiquidityKeeper.GetPositionLiquidity(s.Ctx, positionId) s.Require().NoError(err) @@ -136,13 +136,13 @@ func (s *KeeperTestSuite) validateTickUpdates(ctx sdk.Context, poolId uint64, ow s.Require().NoError(err) s.Require().Equal(expectedRemainingLiquidity.String(), lowerTickInfo.LiquidityGross.String()) s.Require().Equal(expectedRemainingLiquidity.String(), lowerTickInfo.LiquidityNet.String()) - s.Require().Equal(lowerTickInfo.FeeGrowthOppositeDirectionOfLastTraversal.String(), expectedLowerFeeGrowthOppositeDirectionOfLastTraversal.String()) + s.Require().Equal(expectedLowerFeeGrowthOppositeDirectionOfLastTraversal.String(), lowerTickInfo.FeeGrowthOppositeDirectionOfLastTraversal.String()) upperTickInfo, err := s.App.ConcentratedLiquidityKeeper.GetTickInfo(s.Ctx, poolId, upperTick) s.Require().NoError(err) s.Require().Equal(expectedRemainingLiquidity.String(), upperTickInfo.LiquidityGross.String()) s.Require().Equal(expectedRemainingLiquidity.Neg().String(), upperTickInfo.LiquidityNet.String()) - s.Require().Equal(upperTickInfo.FeeGrowthOppositeDirectionOfLastTraversal.String(), expectedUpperFeeGrowthOppositeDirectionOfLastTraversal.String()) + s.Require().Equal(expectedUpperFeeGrowthOppositeDirectionOfLastTraversal.String(), upperTickInfo.FeeGrowthOppositeDirectionOfLastTraversal.String()) } func (s *KeeperTestSuite) initializeTick(ctx sdk.Context, currentTick int64, tickIndex int64, initialLiquidity sdk.Dec, feeGrowthOppositeDirectionOfTraversal sdk.DecCoins, uptimeTrackers []model.UptimeTracker, isLower bool) { diff --git a/x/concentrated-liquidity/lp.go b/x/concentrated-liquidity/lp.go index f9059551e58..0f9df91a6b9 100644 --- a/x/concentrated-liquidity/lp.go +++ b/x/concentrated-liquidity/lp.go @@ -31,80 +31,85 @@ const noUnderlyingLockId = uint64(0) // - the liquidity delta is zero // - the amount0 or amount1 returned from the position update is less than the given minimums // - the pool or user does not have enough tokens to satisfy the requested amount -func (k Keeper) createPosition(ctx sdk.Context, poolId uint64, owner sdk.AccAddress, tokensProvided sdk.Coins, amount0Min, amount1Min sdk.Int, lowerTick, upperTick int64) (uint64, sdk.Int, sdk.Int, sdk.Dec, time.Time, error) { +func (k Keeper) createPosition(ctx sdk.Context, poolId uint64, owner sdk.AccAddress, tokensProvided sdk.Coins, amount0Min, amount1Min sdk.Int, lowerTick, upperTick int64) (positionId uint64, actualAmount0 sdk.Int, actualAmount1 sdk.Int, liquidityDelta sdk.Dec, joinTime time.Time, lowerTickResult int64, upperTickResult int64, err error) { // Use the current blockTime as the position's join time. - joinTime := ctx.BlockTime() + joinTime = ctx.BlockTime() // Retrieve the pool associated with the given pool ID. pool, err := k.getPoolById(ctx, poolId) if err != nil { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err } // Check if the provided tick range is valid according to the pool's tick spacing and module parameters. if err := validateTickRangeIsValid(pool.GetTickSpacing(), lowerTick, upperTick); err != nil { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err } - amount0Desired := tokensProvided.AmountOf(pool.GetToken0()) amount1Desired := tokensProvided.AmountOf(pool.GetToken1()) if amount0Desired.IsZero() && amount1Desired.IsZero() { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, errors.New("cannot create a position with zero amounts of both pool tokens") + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, errors.New("cannot create a position with zero amounts of both pool tokens") } // sanity check that both given minimum accounts are not negative amounts. if amount0Min.IsNegative() { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, types.NotPositiveRequireAmountError{Amount: amount0Min.String()} + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, types.NotPositiveRequireAmountError{Amount: amount0Min.String()} } if amount1Min.IsNegative() { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, types.NotPositiveRequireAmountError{Amount: amount1Min.String()} + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, types.NotPositiveRequireAmountError{Amount: amount1Min.String()} } // Transform the provided ticks into their corresponding sqrtPrices. - sqrtPriceLowerTick, sqrtPriceUpperTick, err := math.TicksToSqrtPrice(lowerTick, upperTick) + priceLowerTick, priceUpperTick, sqrtPriceLowerTick, sqrtPriceUpperTick, err := math.TicksToSqrtPrice(lowerTick, upperTick) + if err != nil { + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err + } + + // If multiple ticks can represent the same spot price, ensure we are using the largest of those ticks. + lowerTick, upperTick, err = roundTickToCanonicalPriceTick(lowerTick, upperTick, priceLowerTick, priceUpperTick, pool.GetTickSpacing()) if err != nil { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err } - positionId := k.getNextPositionIdAndIncrement(ctx) + positionId = k.getNextPositionIdAndIncrement(ctx) // If this is the first position created in this pool, ensure that the position includes both asset0 and asset1 // in order to assign an initial spot price. hasPositions, err := k.HasAnyPositionForPool(ctx, poolId) if err != nil { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err } if !hasPositions { err := k.initializeInitialPositionForPool(ctx, pool, amount0Desired, amount1Desired) if err != nil { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err } } // Calculate the amount of liquidity that will be added to the pool when this position is created. - liquidityDelta := math.GetLiquidityFromAmounts(pool.GetCurrentSqrtPrice(), sqrtPriceLowerTick, sqrtPriceUpperTick, amount0Desired, amount1Desired) + liquidityDelta = math.GetLiquidityFromAmounts(pool.GetCurrentSqrtPrice(), sqrtPriceLowerTick, sqrtPriceUpperTick, amount0Desired, amount1Desired) if liquidityDelta.IsZero() { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, errors.New("liquidityDelta calculated equals zero") + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, errors.New("liquidityDelta calculated equals zero") } // Initialize / update the position in the pool based on the provided tick range and liquidity delta. - actualAmount0, actualAmount1, err := k.UpdatePosition(ctx, poolId, owner, lowerTick, upperTick, liquidityDelta, joinTime, positionId) + actualAmount0, actualAmount1, err = k.UpdatePosition(ctx, poolId, owner, lowerTick, upperTick, liquidityDelta, joinTime, positionId) if err != nil { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err } // Check if the actual amounts of tokens 0 and 1 are greater than or equal to the given minimum amounts. if actualAmount0.LT(amount0Min) { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, types.InsufficientLiquidityCreatedError{Actual: actualAmount0, Minimum: amount0Min, IsTokenZero: true} + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, types.InsufficientLiquidityCreatedError{Actual: actualAmount0, Minimum: amount0Min, IsTokenZero: true} } if actualAmount1.LT(amount1Min) { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, types.InsufficientLiquidityCreatedError{Actual: actualAmount1, Minimum: amount1Min} + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, types.InsufficientLiquidityCreatedError{Actual: actualAmount1, Minimum: amount1Min} } // Transfer the actual amounts of tokens 0 and 1 from the position owner to the pool. err = k.sendCoinsBetweenPoolAndUser(ctx, pool.GetToken0(), pool.GetToken1(), actualAmount0, actualAmount1, owner, pool.GetAddress()) if err != nil { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err } emitLiquidityChangeEvent(ctx, types.TypeEvtCreatePosition, positionId, owner, poolId, lowerTick, upperTick, joinTime, liquidityDelta, actualAmount0, actualAmount1) @@ -112,12 +117,12 @@ func (k Keeper) createPosition(ctx sdk.Context, poolId uint64, owner sdk.AccAddr if !hasPositions { // N.B. calling this listener propagates to x/twap for twap record creation. // This is done after initial pool position only because only the first position - // initializes the pool's spot price. After initial position is created, only + // initializes the pool's spot price. After the initial position is created, only // swaps update the spot price. k.listeners.AfterInitialPoolPositionCreated(ctx, owner, poolId) } - return positionId, actualAmount0, actualAmount1, liquidityDelta, joinTime, nil + return positionId, actualAmount0, actualAmount1, liquidityDelta, joinTime, lowerTick, upperTick, nil } // WithdrawPosition attempts to withdraw liquidityAmount from a position with the given pool id in the given tick range. @@ -299,7 +304,7 @@ func (k Keeper) addToPosition(ctx sdk.Context, owner sdk.AccAddress, positionId return 0, sdk.Int{}, sdk.Int{}, err } tokensProvided := sdk.NewCoins(sdk.NewCoin(pool.GetToken0(), amount0Desired), sdk.NewCoin(pool.GetToken1(), amount1Desired)) - newPositionId, actualAmount0, actualAmount1, _, _, err := k.createPosition(ctx, position.PoolId, owner, tokensProvided, amount0Withdrawn, amount1Withdrawn, position.LowerTick, position.UpperTick) + newPositionId, actualAmount0, actualAmount1, _, _, _, _, err := k.createPosition(ctx, position.PoolId, owner, tokensProvided, amount0Withdrawn, amount1Withdrawn, position.LowerTick, position.UpperTick) if err != nil { return 0, sdk.Int{}, sdk.Int{}, err } diff --git a/x/concentrated-liquidity/lp_test.go b/x/concentrated-liquidity/lp_test.go index 373a7976e63..d613081ad01 100644 --- a/x/concentrated-liquidity/lp_test.go +++ b/x/concentrated-liquidity/lp_test.go @@ -18,7 +18,9 @@ type lpTest struct { poolId uint64 currentTick sdk.Int lowerTick int64 + expectedLowerTick int64 upperTick int64 + expectedUpperTick int64 joinTime time.Time positionId uint64 underlyingLockId uint64 @@ -152,6 +154,25 @@ var ( amount0Expected: DefaultAmt0Expected.Add(roundingError), amount1Expected: DefaultAmt1Expected, }, + "use ticks that are not the canonical tick for a given price, expect them to be rounded to the proper tick": { + lowerTick: -161987600, + expectedLowerTick: -161000000, + upperTick: -160009800, + expectedUpperTick: -160000000, + currentTick: sdk.NewInt(DefaultUpperTick), + + isNotFirstPositionWithSameAccount: true, + positionId: 2, + + liquidityAmount: sdk.MustNewDecFromStr("15731321859400083838.506717486806808937").MulInt64(2), + preSetChargeFee: oneEth, + expectedFeeGrowthOutsideLower: oneEthCoins, + expectedFeeGrowthOutsideUpper: oneEthCoins, + + // Rounding up in favor of the pool. + amount0Expected: sdk.ZeroInt(), + amount1Expected: DefaultAmt1, + }, } ) @@ -287,7 +308,7 @@ func (s *KeeperTestSuite) TestCreatePosition() { poolBalancePrePositionCreation := s.App.BankKeeper.GetAllBalances(s.Ctx, pool.GetAddress()) // System under test. - positionId, asset0, asset1, liquidityCreated, joinTime, err := clKeeper.CreatePosition(s.Ctx, tc.poolId, s.TestAccs[0], tc.tokensProvided, tc.amount0Minimum, tc.amount1Minimum, tc.lowerTick, tc.upperTick) + positionId, asset0, asset1, liquidityCreated, joinTime, newLowerTick, newUpperTick, err := clKeeper.CreatePosition(s.Ctx, tc.poolId, s.TestAccs[0], tc.tokensProvided, tc.amount0Minimum, tc.amount1Minimum, tc.lowerTick, tc.upperTick) // Note user and pool account balances to compare after create position is called userBalancePostPositionCreation := s.App.BankKeeper.GetAllBalances(s.Ctx, s.TestAccs[0]) @@ -323,6 +344,14 @@ func (s *KeeperTestSuite) TestCreatePosition() { s.Require().Equal(tc.amount1Expected.String(), asset1.String()) s.Require().Equal(expectedLiquidityCreated.String(), liquidityCreated.String()) s.Require().Equal(s.Ctx.BlockTime(), joinTime) + if tc.expectedLowerTick != 0 { + s.Require().Equal(tc.expectedLowerTick, newLowerTick) + tc.lowerTick = newLowerTick + } + if tc.expectedUpperTick != 0 { + s.Require().Equal(tc.expectedUpperTick, newUpperTick) + tc.upperTick = newUpperTick + } // Check account balances s.Require().Equal(userBalancePrePositionCreation.Sub(sdk.NewCoins(sdk.NewCoin(ETH, asset0), (sdk.NewCoin(USDC, asset1)))).String(), userBalancePostPositionCreation.String()) @@ -500,7 +529,7 @@ func (s *KeeperTestSuite) TestWithdrawPosition() { _, _, _, liquidityCreated, _, _, err = concentratedLiquidityKeeper.CreateFullRangePositionUnlocking(s.Ctx, pool.GetId(), owner, fundCoins, tc.timeElapsed-time.Hour) s.Require().NoError(err) } else { - _, _, _, liquidityCreated, _, err = concentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), owner, config.tokensProvided, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + _, _, _, liquidityCreated, _, _, _, err = concentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), owner, config.tokensProvided, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) } @@ -642,7 +671,7 @@ func (s *KeeperTestSuite) TestWithdrawPosition() { if expectedRemainingLiquidity.IsZero() { // Add one USDC because we withdraw one less than originally funded due to truncation in favor of the pool. s.FundAcc(owner, sdk.NewCoins(sdk.NewCoin(USDC, sdk.OneInt()))) - _, _, _, _, _, err = concentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), owner, config.tokensProvided, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + _, _, _, _, _, _, _, err = concentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), owner, config.tokensProvided, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) } }) @@ -944,14 +973,14 @@ func (s *KeeperTestSuite) TestAddToPosition() { _, amount0Initial, amount1Initial, _, _, _, err = concentratedLiquidityKeeper.CreateFullRangePositionUnlocking(s.Ctx, pool.GetId(), owner, fundCoins, tc.timeElapsed-time.Hour) s.Require().NoError(err) } else { - _, amount0Initial, amount1Initial, _, _, err = concentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), owner, config.tokensProvided, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + _, amount0Initial, amount1Initial, _, _, _, _, err = concentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), owner, config.tokensProvided, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) } preSendBalanceSender := s.App.BankKeeper.GetAllBalances(s.Ctx, owner) if !tc.lastPositionInPool { s.FundAcc(s.TestAccs[1], fundCoins) - _, _, _, _, _, err = concentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], config.tokensProvided, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + _, _, _, _, _, _, _, err = concentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], config.tokensProvided, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) } @@ -1059,6 +1088,12 @@ func mergeConfigs(dst *lpTest, overwrite *lpTest) { if overwrite.underlyingLockId != 0 { dst.underlyingLockId = overwrite.underlyingLockId } + if overwrite.expectedLowerTick != 0 { + dst.expectedLowerTick = overwrite.expectedLowerTick + } + if overwrite.expectedUpperTick != 0 { + dst.expectedUpperTick = overwrite.expectedUpperTick + } } } @@ -1323,7 +1358,7 @@ func (s *KeeperTestSuite) TestUpdatePosition() { // create position // Fund test account and create the desired position s.FundAcc(s.TestAccs[0], DefaultCoins) - _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition( + _, _, _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition( s.Ctx, 1, s.TestAccs[0], @@ -1489,6 +1524,17 @@ func (s *KeeperTestSuite) TestInitializeInitialPositionForPool() { } func (s *KeeperTestSuite) TestInverseRelation_CreatePosition_WithdrawPosition() { + var ( + errToleranceOneRoundDown = osmomath.ErrTolerance{ + AdditiveTolerance: sdk.OneDec(), + RoundingDir: osmomath.RoundDown, + } + + errToleranceOneRoundUp = osmomath.ErrTolerance{ + AdditiveTolerance: sdk.OneDec(), + RoundingDir: osmomath.RoundUp, + } + ) tests := map[string]lpTest{} // add test cases for different positions @@ -1539,9 +1585,18 @@ func (s *KeeperTestSuite) TestInverseRelation_CreatePosition_WithdrawPosition() poolBalancePrePositionCreation := s.App.BankKeeper.GetAllBalances(s.Ctx, poolBefore.GetAddress()) // System under test. - positionId, amtDenom0CreatePosition, amtDenom1CreatePosition, liquidityCreated, _, err := clKeeper.CreatePosition(s.Ctx, tc.poolId, s.TestAccs[0], tc.tokensProvided, tc.amount0Minimum, tc.amount1Minimum, tc.lowerTick, tc.upperTick) + positionId, amtDenom0CreatePosition, amtDenom1CreatePosition, liquidityCreated, _, newLowerTick, newUpperTick, err := clKeeper.CreatePosition(s.Ctx, tc.poolId, s.TestAccs[0], tc.tokensProvided, tc.amount0Minimum, tc.amount1Minimum, tc.lowerTick, tc.upperTick) s.Require().NoError(err) + if tc.expectedLowerTick != 0 { + s.Require().Equal(tc.expectedLowerTick, newLowerTick) + tc.lowerTick = newLowerTick + } + if tc.expectedUpperTick != 0 { + s.Require().Equal(tc.expectedUpperTick, newUpperTick) + tc.upperTick = newUpperTick + } + s.Ctx = s.Ctx.WithBlockTime(DefaultJoinTime.Add(time.Hour * 24)) amtDenom0WithdrawPosition, amtDenom1WithdrawPosition, err := clKeeper.WithdrawPosition(s.Ctx, s.TestAccs[0], positionId, liquidityCreated) s.Require().NoError(err) @@ -1549,21 +1604,21 @@ func (s *KeeperTestSuite) TestInverseRelation_CreatePosition_WithdrawPosition() // INVARIANTS // 1. amount for denom0 and denom1 upon creating and withdraw position should be same - // Note: subtracting one because create position rounds in favor of the pool. - s.Require().Equal(amtDenom0CreatePosition.Sub(sdk.OneInt()).String(), amtDenom0WithdrawPosition.String()) - s.Require().Equal(amtDenom1CreatePosition.Sub(sdk.OneInt()).String(), amtDenom1WithdrawPosition.String()) + // Note: round down because create position rounds in favor of the pool. + s.Require().Equal(0, errToleranceOneRoundDown.Compare(amtDenom0CreatePosition, amtDenom0WithdrawPosition)) + s.Require().Equal(0, errToleranceOneRoundDown.Compare(amtDenom1CreatePosition, amtDenom1WithdrawPosition)) // 2. user balance and pool balance after creating / withdrawing position should be same userBalancePostPositionCreation := s.App.BankKeeper.GetAllBalances(s.Ctx, s.TestAccs[0]) poolBalancePostPositionCreation := s.App.BankKeeper.GetAllBalances(s.Ctx, poolBefore.GetAddress()) - // Note: subtracting one since position creation rounds in favor of the pool. - s.Require().Equal(userBalancePrePositionCreation.AmountOf(ETH).Sub(sdk.OneInt()).String(), userBalancePostPositionCreation.AmountOf(ETH).String()) - s.Require().Equal(userBalancePrePositionCreation.AmountOf(USDC).Sub(sdk.OneInt()).String(), userBalancePostPositionCreation.AmountOf(USDC).String()) + // Note: rounding down since position creation rounds in favor of the pool. + s.Require().Equal(0, errToleranceOneRoundDown.Compare(userBalancePrePositionCreation.AmountOf(ETH), userBalancePostPositionCreation.AmountOf(ETH))) + s.Require().Equal(0, errToleranceOneRoundDown.Compare(userBalancePrePositionCreation.AmountOf(USDC), userBalancePostPositionCreation.AmountOf(USDC))) - // Note: adding one since withdrawal rounds in favor of the pool. - s.Require().Equal(poolBalancePrePositionCreation.AmountOf(ETH).Add(roundingError).String(), poolBalancePostPositionCreation.AmountOf(ETH).String()) - s.Require().Equal(poolBalancePrePositionCreation.AmountOf(USDC).Add(roundingError).String(), poolBalancePostPositionCreation.AmountOf(USDC).String()) + // Note: rounding up since withdrawal rounds in favor of the pool. + s.Require().Equal(0, errToleranceOneRoundUp.Compare(poolBalancePrePositionCreation.AmountOf(ETH), poolBalancePostPositionCreation.AmountOf(ETH))) + s.Require().Equal(0, errToleranceOneRoundUp.Compare(poolBalancePrePositionCreation.AmountOf(USDC), poolBalancePostPositionCreation.AmountOf(USDC))) // 3. Check that position's liquidity was deleted positionLiquidity, err := clKeeper.GetPositionLiquidity(s.Ctx, tc.positionId) @@ -1579,8 +1634,8 @@ func (s *KeeperTestSuite) TestInverseRelation_CreatePosition_WithdrawPosition() s.Require().NoError(err) // Note: one ends up remaining due to rounding in favor of the pool. - s.Require().Equal(liquidityBefore.AmountOf(ETH).Add(roundingError).String(), liquidityAfter.AmountOf(ETH).String()) - s.Require().Equal(liquidityBefore.AmountOf(USDC).Add(roundingError).String(), liquidityAfter.AmountOf(USDC).String()) + s.Require().Equal(0, errToleranceOneRoundUp.Compare(liquidityBefore.AmountOf(ETH), liquidityAfter.AmountOf(ETH))) + s.Require().Equal(0, errToleranceOneRoundUp.Compare(liquidityBefore.AmountOf(USDC), liquidityAfter.AmountOf(USDC))) }) } } diff --git a/x/concentrated-liquidity/math/tick.go b/x/concentrated-liquidity/math/tick.go index 5a1138a7243..a9318ad202c 100644 --- a/x/concentrated-liquidity/math/tick.go +++ b/x/concentrated-liquidity/math/tick.go @@ -12,36 +12,36 @@ import ( // TicksToSqrtPrice returns the sqrtPrice for the lower and upper ticks by // individually calling `TickToSqrtPrice` method. // Returns error if fails to calculate price. -func TicksToSqrtPrice(lowerTick, upperTick int64) (sdk.Dec, sdk.Dec, error) { +func TicksToSqrtPrice(lowerTick, upperTick int64) (sdk.Dec, sdk.Dec, sdk.Dec, sdk.Dec, error) { if lowerTick >= upperTick { - return sdk.Dec{}, sdk.Dec{}, types.InvalidLowerUpperTickError{LowerTick: lowerTick, UpperTick: upperTick} + return sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, types.InvalidLowerUpperTickError{LowerTick: lowerTick, UpperTick: upperTick} } - sqrtPriceUpperTick, err := TickToSqrtPrice(sdk.NewInt(upperTick)) + priceUpperTick, sqrtPriceUpperTick, err := TickToSqrtPrice(sdk.NewInt(upperTick)) if err != nil { - return sdk.Dec{}, sdk.Dec{}, err + return sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, err } - sqrtPriceLowerTick, err := TickToSqrtPrice(sdk.NewInt(lowerTick)) + priceLowerTick, sqrtPriceLowerTick, err := TickToSqrtPrice(sdk.NewInt(lowerTick)) if err != nil { - return sdk.Dec{}, sdk.Dec{}, err + return sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, err } - return sqrtPriceLowerTick, sqrtPriceUpperTick, nil + return priceLowerTick, priceUpperTick, sqrtPriceLowerTick, sqrtPriceUpperTick, nil } // TickToSqrtPrice returns the sqrtPrice given a tickIndex // If tickIndex is zero, the function returns sdk.OneDec(). // It is the combination of calling TickToPrice followed by Sqrt. -func TickToSqrtPrice(tickIndex sdk.Int) (sdk.Dec, error) { +func TickToSqrtPrice(tickIndex sdk.Int) (sdk.Dec, sdk.Dec, error) { price, err := TickToPrice(tickIndex) if err != nil { - return sdk.Dec{}, err + return sdk.Dec{}, sdk.Dec{}, err } // Determine the sqrtPrice from the price sqrtPrice, err := price.ApproxSqrt() if err != nil { - return sdk.Dec{}, err + return sdk.Dec{}, sdk.Dec{}, err } - return sqrtPrice, nil + return price, sqrtPrice, nil } // TickToPrice returns the price given a tickIndex diff --git a/x/concentrated-liquidity/math/tick_test.go b/x/concentrated-liquidity/math/tick_test.go index c37ff7ac4e7..18eb73bd0f3 100644 --- a/x/concentrated-liquidity/math/tick_test.go +++ b/x/concentrated-liquidity/math/tick_test.go @@ -182,7 +182,7 @@ func (suite *ConcentratedMathTestSuite) TestTickToSqrtPrice() { for name, tc := range testCases { tc := tc suite.Run(name, func() { - sqrtPrice, err := math.TickToSqrtPrice(tc.tickIndex) + price, sqrtPrice, err := math.TickToSqrtPrice(tc.tickIndex) if tc.expectedError != nil { suite.Require().Error(err) suite.Require().Equal(tc.expectedError.Error(), err.Error()) @@ -192,6 +192,7 @@ func (suite *ConcentratedMathTestSuite) TestTickToSqrtPrice() { expectedSqrtPrice, err := tc.expectedPrice.ApproxSqrt() suite.Require().NoError(err) + suite.Require().Equal(tc.expectedPrice.String(), price.String()) suite.Require().Equal(expectedSqrtPrice.String(), sqrtPrice.String()) }) } @@ -249,7 +250,7 @@ func (suite *ConcentratedMathTestSuite) TestTicksToSqrtPrice() { for name, tc := range testCases { tc := tc suite.Run(name, func() { - lowerSqrtPrice, upperSqrtPrice, err := math.TicksToSqrtPrice(tc.lowerTickIndex.Int64(), tc.upperTickIndex.Int64()) + priceLower, priceUpper, lowerSqrtPrice, upperSqrtPrice, err := math.TicksToSqrtPrice(tc.lowerTickIndex.Int64(), tc.upperTickIndex.Int64()) if tc.expectedError != nil { suite.Require().Error(err) suite.Require().Equal(tc.expectedError.Error(), err.Error()) @@ -263,6 +264,8 @@ func (suite *ConcentratedMathTestSuite) TestTicksToSqrtPrice() { expectedUpperSqrtPrice, err := tc.expectedUpperPrice.ApproxSqrt() suite.Require().NoError(err) + suite.Require().Equal(tc.expectedLowerPrice.String(), priceLower.String()) + suite.Require().Equal(tc.expectedUpperPrice.String(), priceUpper.String()) suite.Require().Equal(expectedLowerSqrtPrice.String(), lowerSqrtPrice.String()) suite.Require().Equal(expectedUpperSqrtPrice.String(), upperSqrtPrice.String()) }) @@ -577,7 +580,7 @@ func (suite *ConcentratedMathTestSuite) TestTickToSqrtPricePriceToTick_InverseRe suite.Require().Equal(tickFromPrice.String(), inverseTickFromPrice.String()) // 4. Validate PriceToTick and TickToSqrtPrice functions - sqrtPrice, err := math.TickToSqrtPrice(tickFromPrice) + _, sqrtPrice, err := math.TickToSqrtPrice(tickFromPrice) suite.Require().NoError(err) priceFromSqrtPrice := sqrtPrice.Power(2) diff --git a/x/concentrated-liquidity/model/pool.go b/x/concentrated-liquidity/model/pool.go index 123c1537802..4e3d0857203 100644 --- a/x/concentrated-liquidity/model/pool.go +++ b/x/concentrated-liquidity/model/pool.go @@ -221,7 +221,7 @@ func (p Pool) CalcActualAmounts(ctx sdk.Context, lowerTick, upperTick int64, liq } // Transform the provided ticks into their corresponding sqrtPrices. - sqrtPriceLowerTick, sqrtPriceUpperTick, err := math.TicksToSqrtPrice(lowerTick, upperTick) + _, _, sqrtPriceLowerTick, sqrtPriceUpperTick, err := math.TicksToSqrtPrice(lowerTick, upperTick) if err != nil { return sdk.Dec{}, sdk.Dec{}, err } diff --git a/x/concentrated-liquidity/model/pool_test.go b/x/concentrated-liquidity/model/pool_test.go index 678d0f70df0..0a532cb43c5 100644 --- a/x/concentrated-liquidity/model/pool_test.go +++ b/x/concentrated-liquidity/model/pool_test.go @@ -406,7 +406,7 @@ func (s *ConcentratedPoolTestSuite) TestNewConcentratedLiquidityPool() { func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { var ( tickToSqrtPrice = func(tick int64) sdk.Dec { - sqrtPrice, err := clmath.TickToSqrtPrice(sdk.NewInt(tick)) + _, sqrtPrice, err := clmath.TickToSqrtPrice(sdk.NewInt(tick)) suite.Require().NoError(err) return sqrtPrice } @@ -517,7 +517,7 @@ func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { pool := model.Pool{ CurrentTick: sdk.NewInt(tc.currentTick), } - pool.CurrentSqrtPrice, _ = clmath.TickToSqrtPrice(pool.CurrentTick) + _, pool.CurrentSqrtPrice, _ = clmath.TickToSqrtPrice(pool.CurrentTick) actualAmount0, actualAmount1, err := pool.CalcActualAmounts(suite.Ctx, tc.lowerTick, tc.upperTick, tc.liquidityDelta) @@ -611,7 +611,7 @@ func (suite *ConcentratedPoolTestSuite) TestUpdateLiquidityIfActivePosition() { CurrentTick: sdk.NewInt(tc.currentTick), CurrentTickLiquidity: defaultLiquidityAmt, } - pool.CurrentSqrtPrice, _ = clmath.TickToSqrtPrice(pool.CurrentTick) + _, pool.CurrentSqrtPrice, _ = clmath.TickToSqrtPrice(pool.CurrentTick) wasUpdated := pool.UpdateLiquidityIfActivePosition(suite.Ctx, tc.lowerTick, tc.upperTick, tc.liquidityDelta) if tc.lowerTick <= tc.currentTick && tc.currentTick <= tc.upperTick { diff --git a/x/concentrated-liquidity/msg_server.go b/x/concentrated-liquidity/msg_server.go index 0ad3a7bcb08..fba3525c909 100644 --- a/x/concentrated-liquidity/msg_server.go +++ b/x/concentrated-liquidity/msg_server.go @@ -53,7 +53,7 @@ func (server msgServer) CreatePosition(goCtx context.Context, msg *types.MsgCrea return nil, err } - positionId, actualAmount0, actualAmount1, liquidityCreated, joinTime, err := server.keeper.createPosition(ctx, msg.PoolId, sender, msg.TokensProvided, msg.TokenMinAmount0, msg.TokenMinAmount1, msg.LowerTick, msg.UpperTick) + positionId, actualAmount0, actualAmount1, liquidityCreated, joinTime, lowerTick, upperTick, err := server.keeper.createPosition(ctx, msg.PoolId, sender, msg.TokensProvided, msg.TokenMinAmount0, msg.TokenMinAmount1, msg.LowerTick, msg.UpperTick) if err != nil { return nil, err } @@ -68,7 +68,7 @@ func (server msgServer) CreatePosition(goCtx context.Context, msg *types.MsgCrea // Note: create position event is emitted in keeper.createPosition(...) - return &types.MsgCreatePositionResponse{PositionId: positionId, Amount0: actualAmount0, Amount1: actualAmount1, JoinTime: joinTime, LiquidityCreated: liquidityCreated}, nil + return &types.MsgCreatePositionResponse{PositionId: positionId, Amount0: actualAmount0, Amount1: actualAmount1, JoinTime: joinTime, LiquidityCreated: liquidityCreated, LowerTick: lowerTick, UpperTick: upperTick}, nil } func (server msgServer) AddToPosition(goCtx context.Context, msg *types.MsgAddToPosition) (*types.MsgAddToPositionResponse, error) { diff --git a/x/concentrated-liquidity/pool_test.go b/x/concentrated-liquidity/pool_test.go index 95836bf61a6..1a5a2a2e1e4 100644 --- a/x/concentrated-liquidity/pool_test.go +++ b/x/concentrated-liquidity/pool_test.go @@ -481,11 +481,11 @@ func (s *KeeperTestSuite) TestDecreaseConcentratedPoolTickSpacing() { concentratedPool := s.PrepareConcentratedPoolWithCoinsAndFullRangePosition(ETH, USDC) // Create a position in the pool that is divisible by the tick spacing - _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, concentratedPool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), -100, 100) + _, _, _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, concentratedPool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), -100, 100) s.Require().NoError(err) // Attempt to create a position that is not divisible by the tick spacing - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, concentratedPool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), test.position.lowerTick, test.position.upperTick) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, concentratedPool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), test.position.lowerTick, test.position.upperTick) s.Require().Error(err) // Alter the tick spacing of the pool @@ -498,7 +498,7 @@ func (s *KeeperTestSuite) TestDecreaseConcentratedPoolTickSpacing() { s.Require().NoError(err) // Attempt to create a position that was previously not divisible by the tick spacing but now is - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, concentratedPool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), test.position.lowerTick, test.position.upperTick) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, concentratedPool.GetId(), owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), test.position.lowerTick, test.position.upperTick) if test.expectedCreatePositionErr != nil { s.Require().Error(err) s.Require().ErrorContains(err, test.expectedCreatePositionErr.Error()) diff --git a/x/concentrated-liquidity/position.go b/x/concentrated-liquidity/position.go index ebce8ab8b27..420d14065d9 100644 --- a/x/concentrated-liquidity/position.go +++ b/x/concentrated-liquidity/position.go @@ -309,7 +309,7 @@ func (k Keeper) CreateFullRangePosition(ctx sdk.Context, poolId uint64, owner sd } // Create a full range (min to max tick) concentrated liquidity position. - positionId, amount0, amount1, liquidity, joinTime, err = k.createPosition(ctx, concentratedPool.GetId(), owner, coins, sdk.ZeroInt(), sdk.ZeroInt(), types.MinTick, types.MaxTick) + positionId, amount0, amount1, liquidity, joinTime, _, _, err = k.createPosition(ctx, concentratedPool.GetId(), owner, coins, sdk.ZeroInt(), sdk.ZeroInt(), types.MinTick, types.MaxTick) if err != nil { return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, err } diff --git a/x/concentrated-liquidity/position_test.go b/x/concentrated-liquidity/position_test.go index 1c7c7ab249b..3b1ed50c920 100644 --- a/x/concentrated-liquidity/position_test.go +++ b/x/concentrated-liquidity/position_test.go @@ -651,12 +651,12 @@ func (s *KeeperTestSuite) TestCalculateUnderlyingAssetsFromPosition() { // prepare concentrated pool with a default position s.PrepareConcentratedPool() s.FundAcc(s.TestAccs[0], sdk.NewCoins(sdk.NewCoin(ETH, DefaultAmt0), sdk.NewCoin(USDC, DefaultAmt1))) - _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, 1, s.TestAccs[0], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + _, _, _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, 1, s.TestAccs[0], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) // create a position from the test case s.FundAcc(s.TestAccs[1], sdk.NewCoins(sdk.NewCoin(ETH, DefaultAmt0), sdk.NewCoin(USDC, DefaultAmt1))) - _, actualAmount0, actualAmount1, liquidity, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, tc.position.PoolId, s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), tc.position.LowerTick, tc.position.UpperTick) + _, actualAmount0, actualAmount1, liquidity, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, tc.position.PoolId, s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), tc.position.LowerTick, tc.position.UpperTick) s.Require().NoError(err) tc.position.Liquidity = liquidity @@ -858,7 +858,7 @@ func (s *KeeperTestSuite) TestValidateAndFungifyChargedPositions() { _, _, _, liquidityCreated, _, _, err = s.App.ConcentratedLiquidityKeeper.CreateFullRangePositionUnlocking(s.Ctx, pos.poolId, pos.acc, pos.coins, lockDuration) s.Require().NoError(err) } else { - _, _, _, liquidityCreated, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pos.poolId, pos.acc, pos.coins, sdk.ZeroInt(), sdk.ZeroInt(), pos.lowerTick, pos.upperTick) + _, _, _, liquidityCreated, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pos.poolId, pos.acc, pos.coins, sdk.ZeroInt(), sdk.ZeroInt(), pos.lowerTick, pos.upperTick) s.Require().NoError(err) } @@ -870,7 +870,7 @@ func (s *KeeperTestSuite) TestValidateAndFungifyChargedPositions() { // Set up uncharged positions for _, pos := range test.setupUnchargedPositions { - _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pos.poolId, pos.acc, pos.coins, sdk.ZeroInt(), sdk.ZeroInt(), pos.lowerTick, pos.upperTick) + _, _, _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pos.poolId, pos.acc, pos.coins, sdk.ZeroInt(), sdk.ZeroInt(), pos.lowerTick, pos.upperTick) s.Require().NoError(err) } @@ -1178,7 +1178,7 @@ func (s *KeeperTestSuite) TestFungifyChargedPositions_SwapAndClaimFees() { // Set up fully charged positions totalLiquidity := sdk.ZeroDec() for i := 0; i < numPositions; i++ { - _, _, _, liquidityCreated, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, defaultPoolId, defaultAddress, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + _, _, _, liquidityCreated, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, defaultPoolId, defaultAddress, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) totalLiquidity = totalLiquidity.Add(liquidityCreated) } @@ -1293,7 +1293,7 @@ func (s *KeeperTestSuite) TestFungifyChargedPositions_ClaimIncentives() { // Set up fully charged positions totalLiquidity := sdk.ZeroDec() for i := 0; i < numPositions; i++ { - _, _, _, liquidityCreated, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, defaultPoolId, defaultAddress, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + _, _, _, liquidityCreated, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, defaultPoolId, defaultAddress, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) totalLiquidity = totalLiquidity.Add(liquidityCreated) } @@ -1517,7 +1517,7 @@ func (s *KeeperTestSuite) TestMintSharesAndLock() { s.Require().NoError(err) } else { var err error - positionId, _, _, liquidity, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, clPool.GetId(), test.owner, defaultPositionCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + positionId, _, _, liquidity, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, clPool.GetId(), test.owner, defaultPositionCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) } @@ -1993,7 +1993,7 @@ func (s *KeeperTestSuite) TestGetAndUpdateFullRangeLiquidity() { // Create a new position that overlaps with the min tick, but is not full range and therefore should not count towards the full range liquidity. s.FundAcc(owner, tc.positionCoins) - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, clPoolId, owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), tc.lowerTick, tc.upperTick) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, clPoolId, owner, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), tc.lowerTick, tc.upperTick) s.Require().NoError(err) clPool, err = s.App.ConcentratedLiquidityKeeper.GetPoolById(s.Ctx, clPoolId) diff --git a/x/concentrated-liquidity/swaps.go b/x/concentrated-liquidity/swaps.go index 8ca5420a405..3358c41f28e 100644 --- a/x/concentrated-liquidity/swaps.go +++ b/x/concentrated-liquidity/swaps.go @@ -332,7 +332,7 @@ func (k Keeper) computeOutAmtGivenIn( } // Utilizing the next initialized tick, we find the corresponding nextPrice (the target price). - nextTickSqrtPrice, err := math.TickToSqrtPrice(nextTick) + _, nextTickSqrtPrice, err := math.TickToSqrtPrice(nextTick) if err != nil { return sdk.Coin{}, sdk.Coin{}, sdk.Int{}, sdk.Dec{}, sdk.Dec{}, fmt.Errorf("could not convert next tick (%v) to nextSqrtPrice", nextTick) } @@ -498,7 +498,7 @@ func (k Keeper) calcInAmtGivenOut( } // utilizing the next initialized tick, we find the corresponding nextPrice (the target price) - sqrtPriceNextTick, err := math.TickToSqrtPrice(nextTick) + _, sqrtPriceNextTick, err := math.TickToSqrtPrice(nextTick) if err != nil { return writeCtx, sdk.Coin{}, sdk.Coin{}, sdk.Int{}, sdk.Dec{}, sdk.Dec{}, fmt.Errorf("could not convert next tick (%v) to nextSqrtPrice", nextTick) } diff --git a/x/concentrated-liquidity/swaps_test.go b/x/concentrated-liquidity/swaps_test.go index edb5f846eaf..f59e3049730 100644 --- a/x/concentrated-liquidity/swaps_test.go +++ b/x/concentrated-liquidity/swaps_test.go @@ -1477,7 +1477,7 @@ func (s *KeeperTestSuite) TestComputeAndSwapOutAmtGivenIn() { newUpperTick, err := math.PriceToTickRoundDown(test.secondPositionUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) s.Require().NoError(err) } @@ -1517,9 +1517,9 @@ func (s *KeeperTestSuite) TestComputeAndSwapOutAmtGivenIn() { newUpperTick, err := math.PriceToTickRoundDown(test.newUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - lowerSqrtPrice, err := math.TickToSqrtPrice(newLowerTick) + _, lowerSqrtPrice, err := math.TickToSqrtPrice(newLowerTick) s.Require().NoError(err) - upperSqrtPrice, err := math.TickToSqrtPrice(newUpperTick) + _, upperSqrtPrice, err := math.TickToSqrtPrice(newUpperTick) s.Require().NoError(err) if test.poolLiqAmount0.IsNil() && test.poolLiqAmount1.IsNil() { @@ -1568,9 +1568,9 @@ func (s *KeeperTestSuite) TestComputeAndSwapOutAmtGivenIn() { newUpperTick, err := math.PriceToTickRoundDown(test.newUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - lowerSqrtPrice, err := math.TickToSqrtPrice(newLowerTick) + _, lowerSqrtPrice, err := math.TickToSqrtPrice(newLowerTick) s.Require().NoError(err) - upperSqrtPrice, err := math.TickToSqrtPrice(newUpperTick) + _, upperSqrtPrice, err := math.TickToSqrtPrice(newUpperTick) s.Require().NoError(err) if test.poolLiqAmount0.IsNil() && test.poolLiqAmount1.IsNil() { @@ -1633,7 +1633,7 @@ func (s *KeeperTestSuite) TestSwapOutAmtGivenIn_TickUpdates() { newUpperTick, err := math.PriceToTickRoundDown(test.secondPositionUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) s.Require().NoError(err) } @@ -1715,7 +1715,7 @@ func (s *KeeperTestSuite) TestCalcAndSwapInAmtGivenOut() { newUpperTick, err := math.PriceToTickRoundDown(test.secondPositionUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) s.Require().NoError(err) } @@ -1748,9 +1748,9 @@ func (s *KeeperTestSuite) TestCalcAndSwapInAmtGivenOut() { newUpperTick, err := math.PriceToTickRoundDown(test.newUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - lowerSqrtPrice, err := math.TickToSqrtPrice(newLowerTick) + _, lowerSqrtPrice, err := math.TickToSqrtPrice(newLowerTick) s.Require().NoError(err) - upperSqrtPrice, err := math.TickToSqrtPrice(newUpperTick) + _, upperSqrtPrice, err := math.TickToSqrtPrice(newUpperTick) s.Require().NoError(err) if test.poolLiqAmount0.IsNil() && test.poolLiqAmount1.IsNil() { @@ -1804,9 +1804,9 @@ func (s *KeeperTestSuite) TestCalcAndSwapInAmtGivenOut() { newUpperTick, err := math.PriceToTickRoundDown(test.newUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - lowerSqrtPrice, err := math.TickToSqrtPrice(newLowerTick) + _, lowerSqrtPrice, err := math.TickToSqrtPrice(newLowerTick) s.Require().NoError(err) - upperSqrtPrice, err := math.TickToSqrtPrice(newUpperTick) + _, upperSqrtPrice, err := math.TickToSqrtPrice(newUpperTick) s.Require().NoError(err) if test.poolLiqAmount0.IsNil() && test.poolLiqAmount1.IsNil() { @@ -1879,7 +1879,7 @@ func (s *KeeperTestSuite) TestSwapInAmtGivenOut_TickUpdates() { newUpperTick, err := math.PriceToTickRoundDown(test.secondPositionUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) s.Require().NoError(err) } @@ -2314,7 +2314,7 @@ func (s *KeeperTestSuite) TestComputeOutAmtGivenIn() { newUpperTick, err := math.PriceToTickRoundDown(test.secondPositionUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) s.Require().NoError(err) } @@ -2382,7 +2382,7 @@ func (s *KeeperTestSuite) TestCalcOutAmtGivenIn_NonMutative() { newUpperTick, err := math.PriceToTickRoundDown(test.secondPositionUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) s.Require().NoError(err) } @@ -2451,7 +2451,7 @@ func (s *KeeperTestSuite) TestCalcInAmtGivenOutWriteCtx() { newUpperTick, err := math.PriceToTickRoundDown(test.secondPositionUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) s.Require().NoError(err) } @@ -2527,7 +2527,7 @@ func (s *KeeperTestSuite) TestInverseRelationshipSwapOutAmtGivenIn() { newUpperTick, err := math.PriceToTickRoundDown(test.secondPositionUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) s.Require().NoError(err) } @@ -2625,7 +2625,7 @@ func (s *KeeperTestSuite) TestInverseRelationshipSwapInAmtGivenOut() { newUpperTick, err := math.PriceToTickRoundDown(test.secondPositionUpperPrice, pool.GetTickSpacing()) s.Require().NoError(err) - _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) + _, _, _, _, _, _, _, err = s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[1], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), newLowerTick.Int64(), newUpperTick.Int64()) s.Require().NoError(err) } diff --git a/x/concentrated-liquidity/tick.go b/x/concentrated-liquidity/tick.go index 09a62ec34f8..c84ece6d0d6 100644 --- a/x/concentrated-liquidity/tick.go +++ b/x/concentrated-liquidity/tick.go @@ -191,6 +191,37 @@ func validateTickRangeIsValid(tickSpacing uint64, lowerTick int64, upperTick int return nil } +// 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 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 + } + newUpperTick, err := math.PriceToTickRoundDown(priceTickUpper, tickSpacing) + if err != nil { + return 0, 0, err + } + + newLowerTickInt64 := newLowerTick.Int64() + newUpperTickInt64 := newUpperTick.Int64() + + // If the lower or upper tick has changed, we need to re-validate the tick range. + if lowerTick != newLowerTickInt64 || upperTick != newUpperTickInt64 { + err := validateTickRangeIsValid(tickSpacing, newLowerTickInt64, newUpperTickInt64) + if err != nil { + return 0, 0, err + } + } + return newLowerTickInt64, newUpperTickInt64, nil +} + // GetTickLiquidityForFullRange returns an array of liquidity depth for all ticks existing from min tick ~ max tick. func (k Keeper) GetTickLiquidityForFullRange(ctx sdk.Context, poolId uint64) ([]queryproto.LiquidityDepthWithRange, error) { pool, err := k.getPoolById(ctx, poolId) @@ -332,7 +363,7 @@ func (k Keeper) GetTickLiquidityNetInDirection(ctx sdk.Context, poolId uint64, t swapStrategy := swapstrategy.New(zeroForOne, sdk.ZeroDec(), k.storeKey, sdk.ZeroDec(), p.GetTickSpacing()) currentTick := p.GetCurrentTick() - currentTickSqrtPrice, err := math.TickToSqrtPrice(currentTick) + _, currentTickSqrtPrice, err := math.TickToSqrtPrice(currentTick) if err != nil { return []queryproto.TickLiquidityNet{}, err } @@ -342,7 +373,7 @@ func (k Keeper) GetTickLiquidityNetInDirection(ctx sdk.Context, poolId uint64, t // function to validate that start tick and bound tick are // between current tick and the min/max tick depending on the swap direction. validateTickIsInValidRange := func(validateTick sdk.Int) error { - validateSqrtPrice, err := math.TickToSqrtPrice(validateTick) + _, validateSqrtPrice, err := math.TickToSqrtPrice(validateTick) if err != nil { return err } diff --git a/x/concentrated-liquidity/tick_test.go b/x/concentrated-liquidity/tick_test.go index e347cd611bb..59f717b6083 100644 --- a/x/concentrated-liquidity/tick_test.go +++ b/x/concentrated-liquidity/tick_test.go @@ -571,7 +571,7 @@ func (s *KeeperTestSuite) TestCrossTick() { if test.poolToGet == validPoolId { s.FundAcc(s.TestAccs[0], sdk.NewCoins(DefaultCoin0, DefaultCoin1)) - _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, test.poolToGet, s.TestAccs[0], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) + _, _, _, _, _, _, _, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, test.poolToGet, s.TestAccs[0], DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick) s.Require().NoError(err) } @@ -1180,7 +1180,7 @@ func (s *KeeperTestSuite) TestGetTickLiquidityNetInDirection() { curTick, err := math.PriceToTick(curPrice) s.Require().NoError(err) if !test.currentPoolTick.IsNil() { - sqrtPrice, err := math.TickToSqrtPrice(test.currentPoolTick) + _, sqrtPrice, err := math.TickToSqrtPrice(test.currentPoolTick) s.Require().NoError(err) curTick = test.currentPoolTick diff --git a/x/concentrated-liquidity/types/tx.pb.go b/x/concentrated-liquidity/types/tx.pb.go index 2929b838987..1e8cd211e35 100644 --- a/x/concentrated-liquidity/types/tx.pb.go +++ b/x/concentrated-liquidity/types/tx.pb.go @@ -123,6 +123,12 @@ type MsgCreatePositionResponse struct { Amount1 github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=amount1,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount1" yaml:"amount1"` JoinTime time.Time `protobuf:"bytes,4,opt,name=join_time,json=joinTime,proto3,stdtime" json:"join_time" yaml:"join_time"` LiquidityCreated github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=liquidity_created,json=liquidityCreated,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"liquidity_created" yaml:"liquidity_created"` + // the lower and upper tick are in the response because there are + // instances in which multiple ticks represent the same price, so + // we may move their provided tick to the canonical tick that represents + // the same price. + LowerTick int64 `protobuf:"varint,6,opt,name=lower_tick,json=lowerTick,proto3" json:"lower_tick,omitempty" yaml:"lower_tick"` + UpperTick int64 `protobuf:"varint,7,opt,name=upper_tick,json=upperTick,proto3" json:"upper_tick,omitempty" yaml:"upper_tick"` } func (m *MsgCreatePositionResponse) Reset() { *m = MsgCreatePositionResponse{} } @@ -172,6 +178,20 @@ func (m *MsgCreatePositionResponse) GetJoinTime() time.Time { return time.Time{} } +func (m *MsgCreatePositionResponse) GetLowerTick() int64 { + if m != nil { + return m.LowerTick + } + return 0 +} + +func (m *MsgCreatePositionResponse) GetUpperTick() int64 { + if m != nil { + return m.UpperTick + } + return 0 +} + // ===================== MsgAddToPosition type MsgAddToPosition struct { PositionId uint64 `protobuf:"varint,1,opt,name=position_id,json=positionId,proto3" json:"position_id,omitempty" yaml:"position_id"` @@ -840,89 +860,90 @@ func init() { } var fileDescriptor_1f1fff802923d7db = []byte{ - // 1305 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x58, 0x4f, 0x6f, 0xdc, 0x44, - 0x14, 0x8f, 0x77, 0xd3, 0xb4, 0x99, 0x74, 0xf3, 0xc7, 0x49, 0xdb, 0xad, 0x5b, 0xd6, 0xd1, 0x20, - 0xe8, 0x22, 0xa8, 0x5d, 0xb7, 0x54, 0x40, 0x11, 0xa2, 0x75, 0xa2, 0x4a, 0x8b, 0x14, 0xa9, 0xb2, - 0x5a, 0x81, 0x2a, 0x24, 0xcb, 0xbb, 0x9e, 0x6c, 0x86, 0xac, 0x3d, 0x5b, 0xcf, 0x6c, 0xd2, 0x3d, - 0x70, 0x2a, 0x17, 0x04, 0x52, 0x2b, 0x24, 0x24, 0xbe, 0x01, 0x12, 0x9f, 0x80, 0x0b, 0xf7, 0x1e, - 0x7b, 0x41, 0x42, 0x08, 0x6d, 0x51, 0x73, 0xe3, 0x82, 0xd8, 0x4f, 0x80, 0xec, 0xb1, 0xc7, 0x1b, - 0x3b, 0xa1, 0xf1, 0xa6, 0xc9, 0x85, 0x53, 0x32, 0x6f, 0xde, 0xef, 0xf7, 0x9b, 0x79, 0xef, 0xcd, - 0xcc, 0xf3, 0x82, 0x4b, 0x84, 0x7a, 0x84, 0x62, 0xaa, 0xb7, 0x88, 0xdf, 0x42, 0x3e, 0x0b, 0x1c, - 0x86, 0xdc, 0xcb, 0x1d, 0xfc, 0xa0, 0x87, 0x5d, 0xcc, 0xfa, 0x3a, 0x7b, 0xa8, 0x75, 0x03, 0xc2, - 0x88, 0xfc, 0x46, 0xec, 0xa8, 0x8d, 0x3a, 0x0a, 0x3f, 0x6d, 0xcb, 0x68, 0x22, 0xe6, 0x18, 0xca, - 0x52, 0x9b, 0xb4, 0x49, 0x84, 0xd0, 0xc3, 0xff, 0x38, 0x58, 0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, 0xa5, 0x23, 0xcc, - 0x64, 0xe9, 0x55, 0x67, 0x72, 0x1b, 0xcc, 0x86, 0x17, 0x3e, 0xe9, 0x74, 0x50, 0x8b, 0xdd, 0x46, - 0x88, 0xca, 0x37, 0xc0, 0xe9, 0x91, 0x34, 0xd1, 0xaa, 0xb4, 0x5c, 0xae, 0x4f, 0x9a, 0xe7, 0x86, - 0x03, 0x75, 0x31, 0x97, 0x44, 0x0a, 0xad, 0x99, 0x34, 0x8b, 0xb4, 0x40, 0x1a, 0x61, 0x1f, 0x9c, - 0xdd, 0x2d, 0x2c, 0x42, 0x69, 0x83, 0xd9, 0x16, 0x37, 0x23, 0xd7, 0x5e, 0x47, 0x88, 0x2f, 0xa1, - 0xc8, 0x59, 0xde, 0x0d, 0x87, 0x56, 0x45, 0x18, 0x42, 0x21, 0xf8, 0x25, 0x58, 0x4a, 0xa5, 0x1b, - 0x51, 0x1b, 0x87, 0xb7, 0x8e, 0x6f, 0xe7, 0x5f, 0x95, 0xc0, 0xc5, 0xbd, 0xf4, 0x45, 0x00, 0x1e, - 0x80, 0xa5, 0x74, 0x07, 0x58, 0xcc, 0xbf, 0x3c, 0x0c, 0xaf, 0xc7, 0x61, 0xb8, 0x90, 0x0d, 0x43, - 0x4a, 0x02, 0xad, 0x45, 0x61, 0x1e, 0xd9, 0xfa, 0x03, 0xb0, 0xb4, 0x4e, 0x82, 0x75, 0x84, 0x33, - 0x92, 0xa5, 0x82, 0x92, 0x7b, 0x91, 0x40, 0x6b, 0x51, 0x98, 0x53, 0x49, 0xf8, 0x68, 0x12, 0xc8, - 0xa2, 0xd7, 0x10, 0xf6, 0x23, 0x6b, 0x56, 0x6d, 0x30, 0x2b, 0x96, 0x64, 0x87, 0x2d, 0x73, 0xe1, - 0x27, 0x68, 0x37, 0x1c, 0x5a, 0x15, 0x61, 0x08, 0xbd, 0xe5, 0x4d, 0x50, 0x41, 0x1e, 0xa6, 0x34, - 0xac, 0x8f, 0xf0, 0xab, 0x20, 0x7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0x9b, - 0x23, 0x4f, 0x46, 0x2c, 0x77, 0xb9, 0xe3, 0x34, 0x69, 0x32, 0xd0, 0xb7, 0x8c, 0xeb, 0xfa, 0xc3, - 0x7d, 0x7f, 0xa6, 0x0c, 0x9f, 0x94, 0xe6, 0x54, 0x74, 0x65, 0x5f, 0xfb, 0x37, 0x00, 0x00, 0xff, - 0xff, 0x60, 0x55, 0xb4, 0xb7, 0xd5, 0x14, 0x00, 0x00, + // 1318 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x58, 0xcf, 0x6f, 0xdc, 0xc4, + 0x17, 0x8f, 0x77, 0xb7, 0x49, 0x33, 0xe9, 0xe6, 0x87, 0x93, 0xb6, 0x5b, 0xb7, 0xdf, 0x75, 0x34, + 0x5f, 0x41, 0x83, 0xa0, 0x76, 0xdd, 0x52, 0x01, 0x45, 0x88, 0xd6, 0x89, 0x2a, 0x2d, 0x52, 0xa4, + 0xca, 0x6a, 0x05, 0xaa, 0x90, 0x2c, 0xef, 0x7a, 0xb2, 0x19, 0xb2, 0xf6, 0x6c, 0x3d, 0xb3, 0x49, + 0xf7, 0xc0, 0xa9, 0x5c, 0x10, 0x48, 0xad, 0x90, 0x90, 0xf8, 0x0f, 0x90, 0xf8, 0x0b, 0xb8, 0x70, + 0xef, 0xb1, 0x17, 0x24, 0xc4, 0x61, 0x8b, 0x9a, 0x1b, 0x17, 0xc4, 0xfe, 0x05, 0xc8, 0x1e, 0x7b, + 0xbc, 0xb1, 0x13, 0x1a, 0x6f, 0x9a, 0x5c, 0x38, 0x25, 0xf3, 0xe6, 0x7d, 0x3e, 0x6f, 0xe6, 0xfd, + 0x98, 0xf7, 0xbc, 0xe0, 0x32, 0xa1, 0x1e, 0xa1, 0x98, 0xea, 0x2d, 0xe2, 0xb7, 0x90, 0xcf, 0x02, + 0x87, 0x21, 0xf7, 0x4a, 0x07, 0x3f, 0xec, 0x61,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 0x9d, 0xb6, 0x3f, 0xc5, 0x6c, + 0xd3, 0x0d, 0x9c, 0x9d, 0x13, 0xcd, 0x25, 0x06, 0xd2, 0x22, 0x8a, 0x9f, 0xcd, 0xf8, 0x82, 0x8d, + 0xc2, 0x85, 0x7a, 0x3e, 0x5b, 0xa8, 0x9c, 0x0f, 0x5a, 0x73, 0x42, 0xc4, 0x9f, 0x61, 0xf8, 0xab, + 0x04, 0x2e, 0xee, 0x73, 0x63, 0x91, 0x02, 0x23, 0x91, 0x94, 0x8e, 0x31, 0x92, 0xa5, 0xd7, 0x1d, + 0xc9, 0x1d, 0x30, 0x1b, 0x36, 0x17, 0xd2, 0xe9, 0xa0, 0x16, 0xbb, 0x83, 0x10, 0x95, 0x6f, 0x82, + 0x33, 0x23, 0x61, 0xa2, 0x35, 0x69, 0xb9, 0xbc, 0x52, 0x31, 0xcf, 0x0f, 0x07, 0xea, 0x62, 0x2e, + 0x88, 0x14, 0x5a, 0x33, 0x69, 0x14, 0x69, 0x81, 0x30, 0xc2, 0x3e, 0x38, 0xb7, 0xd7, 0xb0, 0x70, + 0xa5, 0x0d, 0x66, 0x5b, 0x5c, 0x8c, 0x5c, 0x7b, 0x03, 0x21, 0x7e, 0x84, 0x22, 0xb5, 0xbc, 0x17, + 0x0e, 0xad, 0xaa, 0x10, 0x84, 0x86, 0xe0, 0x97, 0x60, 0x29, 0x35, 0xdd, 0x88, 0x46, 0x46, 0xbc, + 0x7d, 0x72, 0x37, 0xff, 0xaa, 0x04, 0x2e, 0xed, 0x67, 0x5f, 0x38, 0xe0, 0x21, 0x58, 0x4a, 0x6f, + 0x80, 0xc5, 0xfe, 0xab, 0xdd, 0xf0, 0xff, 0xd8, 0x0d, 0x17, 0xb3, 0x6e, 0x48, 0x49, 0xa0, 0xb5, + 0x28, 0xc4, 0x23, 0x57, 0x7f, 0x08, 0x96, 0x36, 0x48, 0xb0, 0x81, 0x70, 0xc6, 0x64, 0xa9, 0xa0, + 0xc9, 0xfd, 0x48,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81, 0xf3, 0x07, 0x3d, 0x2a, 0x05, 0xe8, 0x0f, 0xa0, 0x50, 0x1a, 0x47, 0xa6, 0x48, 0x4e, + 0x6a, 0x7e, 0xfe, 0xec, 0x65, 0x5d, 0x7a, 0xfe, 0xb2, 0x2e, 0xfd, 0xf1, 0xb2, 0x2e, 0x3d, 0xdd, + 0xad, 0x4f, 0x3c, 0xdf, 0xad, 0x4f, 0xfc, 0xb6, 0x5b, 0x9f, 0x78, 0x60, 0x8e, 0xb4, 0x8c, 0xd8, + 0xdc, 0x95, 0x8e, 0xd3, 0xa4, 0xc9, 0x42, 0xdf, 0x36, 0x6e, 0xe8, 0x8f, 0x0e, 0xfc, 0x49, 0x34, + 0x6c, 0x29, 0xcd, 0xc9, 0xe8, 0xc9, 0xbe, 0xfe, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe3, 0xe6, + 0x38, 0xf7, 0x41, 0x15, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1320,6 +1341,16 @@ func (m *MsgCreatePositionResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro _ = i var l int _ = l + if m.UpperTick != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.UpperTick)) + i-- + dAtA[i] = 0x38 + } + if m.LowerTick != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.LowerTick)) + i-- + dAtA[i] = 0x30 + } { size := m.LiquidityCreated.Size() i -= size @@ -2014,6 +2045,12 @@ func (m *MsgCreatePositionResponse) Size() (n int) { n += 1 + l + sovTx(uint64(l)) l = m.LiquidityCreated.Size() n += 1 + l + sovTx(uint64(l)) + if m.LowerTick != 0 { + n += 1 + sovTx(uint64(m.LowerTick)) + } + if m.UpperTick != 0 { + n += 1 + sovTx(uint64(m.UpperTick)) + } return n } @@ -2667,6 +2704,44 @@ func (m *MsgCreatePositionResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LowerTick", wireType) + } + m.LowerTick = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LowerTick |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UpperTick", wireType) + } + m.UpperTick = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UpperTick |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) From 674a9c1001af8515361925993e781f89b551b630 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Tue, 16 May 2023 15:10:17 -0500 Subject: [PATCH 2/4] update gomod --- go.mod | 4 ++-- go.sum | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 06504731330..d70d89cde40 100644 --- a/go.mod +++ b/go.mod @@ -19,8 +19,8 @@ require ( github.com/mattn/go-sqlite3 v1.14.16 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 - github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230503232557-ba905586c111 - github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230511015306-615fa4fcbe56 + github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516200639-ee915a97c5c1 + github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516200639-ee915a97c5c1 github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230331072320-5d6f6cfa2627 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 493d08f32ac..8dca8655068 100644 --- a/go.sum +++ b/go.sum @@ -938,8 +938,12 @@ github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:Ylmch github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI= github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230503232557-ba905586c111 h1:1ahWbf9iF9sxDOjxrHWFaBGLE0nWFdpiX1pqObUaJO8= github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230503232557-ba905586c111/go.mod h1:a7lhiXRpn8QJ21OhFpaEnUNErTSIafaYpp02q6uI/Dk= +github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516200639-ee915a97c5c1 h1:NM8H0Nqhy+qvtx0P06Q46GWUPB/qyIUBzXj53Rv25is= +github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516200639-ee915a97c5c1/go.mod h1:a7lhiXRpn8QJ21OhFpaEnUNErTSIafaYpp02q6uI/Dk= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230511015306-615fa4fcbe56 h1:27yWLC0uXSatRy8aRn0yinHU+K31bkjBRmNnQUDO0Ks= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230511015306-615fa4fcbe56/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516200639-ee915a97c5c1 h1:hB/CvutX3XhtWec01Esr/GMBS1uE4JGO+PtCUvAgsf8= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516200639-ee915a97c5c1/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 h1:RIrWLzIiZN5Xd2JOfSOtGZaf6V3qEQYg6EaDTAkMnCo= github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304/go.mod h1:yPWoJTj5RKrXKUChAicp+G/4Ni/uVEpp27mi/FF/L9c= github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230331072320-5d6f6cfa2627 h1:A0SwZgp4bmJFbivYJc8mmVhMjrr3EdUZluBYFke11+w= From c213fddde0697c582738fd5fe2d39176a3fbf77f Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Tue, 16 May 2023 15:51:27 -0500 Subject: [PATCH 3/4] revert nolint --- osmomath/decimal.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index 03b6fea77bf..1b8e21ce001 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -887,12 +887,16 @@ func MaxDec(d1, d2 BigDec) BigDec { // DecEq returns true if two given decimals are equal. // Intended to be used with require/assert: require.True(t, DecEq(...)) +// +//nolint:thelper func DecEq(t *testing.T, exp, got BigDec) (*testing.T, bool, string, string, string) { return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() } // DecApproxEq returns true if the differences between two given decimals are smaller than the tolerance range. // Intended to be used with require/assert: require.True(t, DecEq(...)) +// +//nolint:thelper func DecApproxEq(t *testing.T, d1 BigDec, d2 BigDec, tol BigDec) (*testing.T, bool, string, string, string) { diff := d1.Sub(d2).Abs() return t, diff.LTE(tol), "expected |d1 - d2| <:\t%v\ngot |d1 - d2| = \t\t%v", tol.String(), diff.String() From 0268af88135a2e1d7f8c77ba9d11643902071ff4 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Tue, 16 May 2023 15:54:37 -0500 Subject: [PATCH 4/4] update gomod --- go.mod | 4 ++-- go.sum | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index d70d89cde40..6fe0cb7a09a 100644 --- a/go.mod +++ b/go.mod @@ -19,8 +19,8 @@ require ( github.com/mattn/go-sqlite3 v1.14.16 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 - github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516200639-ee915a97c5c1 - github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516200639-ee915a97c5c1 + github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069 + github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069 github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230331072320-5d6f6cfa2627 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 8dca8655068..d6160ba87ba 100644 --- a/go.sum +++ b/go.sum @@ -940,10 +940,14 @@ github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230503232557-ba905586c11 github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230503232557-ba905586c111/go.mod h1:a7lhiXRpn8QJ21OhFpaEnUNErTSIafaYpp02q6uI/Dk= github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516200639-ee915a97c5c1 h1:NM8H0Nqhy+qvtx0P06Q46GWUPB/qyIUBzXj53Rv25is= github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516200639-ee915a97c5c1/go.mod h1:a7lhiXRpn8QJ21OhFpaEnUNErTSIafaYpp02q6uI/Dk= +github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069 h1:ZgDrTJ2GCH4CJGbV6rudw4O9rPMAuwWoLVZnG6cUr+A= +github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069/go.mod h1:a7lhiXRpn8QJ21OhFpaEnUNErTSIafaYpp02q6uI/Dk= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230511015306-615fa4fcbe56 h1:27yWLC0uXSatRy8aRn0yinHU+K31bkjBRmNnQUDO0Ks= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230511015306-615fa4fcbe56/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516200639-ee915a97c5c1 h1:hB/CvutX3XhtWec01Esr/GMBS1uE4JGO+PtCUvAgsf8= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516200639-ee915a97c5c1/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069 h1:9C/n+Nx5rre/AHPMlPsQrk1isgydrCNB68aqer86ygE= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230516205127-c213fddde069/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 h1:RIrWLzIiZN5Xd2JOfSOtGZaf6V3qEQYg6EaDTAkMnCo= github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304/go.mod h1:yPWoJTj5RKrXKUChAicp+G/4Ni/uVEpp27mi/FF/L9c= github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230331072320-5d6f6cfa2627 h1:A0SwZgp4bmJFbivYJc8mmVhMjrr3EdUZluBYFke11+w=