From 261382650c94193fe9d2056c00ff2d7ecc39f6b0 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Tue, 16 May 2023 13:54:54 -0500 Subject: [PATCH] Revert "fix: duplicate price for multiple ticks (#5173)" This reverts commit f116d432d5893c45b5ee100beafed550f1488761. --- osmomath/decimal.go | 4 + osmomath/int.go | 2 + osmoutils/accum/prefix.go | 13 +- proto/osmosis/concentrated-liquidity/tx.proto | 6 - proto/osmosis/superfluid/tx.proto | 5 +- tests/cl-genesis-positions/go.mod | 4 +- tests/cl-genesis-positions/go.sum | 10 +- tests/cl-go-client/go.mod | 2 +- tests/cl-go-client/go.sum | 3 - tests/e2e/e2e_test.go | 8 +- x/concentrated-liquidity/README.md | 9 - 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 | 50 ++-- x/concentrated-liquidity/lp_test.go | 91 ++----- x/concentrated-liquidity/math/precompute.go | 44 ++++ x/concentrated-liquidity/math/tick.go | 49 ++-- 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 | 8 +- x/concentrated-liquidity/swaps_test.go | 32 +-- x/concentrated-liquidity/tick.go | 35 +-- x/concentrated-liquidity/tick_test.go | 90 +------ x/concentrated-liquidity/types/tx.pb.go | 241 ++++++------------ x/gamm/types/key.go | 5 +- x/superfluid/client/cli/tx.go | 9 + x/superfluid/keeper/export_test.go | 13 + x/superfluid/keeper/migrate.go | 9 +- x/superfluid/keeper/msg_server.go | 64 ++--- x/superfluid/keeper/msg_server_test.go | 16 +- x/superfluid/keeper/stake.go | 2 +- x/superfluid/keeper/unpool.go | 42 +-- x/superfluid/keeper/unpool_test.go | 146 +++++++++++ x/superfluid/types/tx.pb.go | 4 +- 42 files changed, 510 insertions(+), 577 deletions(-) create mode 100644 x/concentrated-liquidity/math/precompute.go 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() diff --git a/osmomath/int.go b/osmomath/int.go index c3ae4ef288e..6b2fe80025d 100644 --- a/osmomath/int.go +++ b/osmomath/int.go @@ -435,6 +435,8 @@ 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/osmoutils/accum/prefix.go b/osmoutils/accum/prefix.go index 4dea6af8861..c207d215b6f 100644 --- a/osmoutils/accum/prefix.go +++ b/osmoutils/accum/prefix.go @@ -8,23 +8,16 @@ const ( positionPrefix = "pos" ) -// formatAccumPrefix returns the key prefix used for any -// accum module values to be stored in the KVStore. -// Returns "accum/{key}" as bytes. -func formatModulePrefixKey(key string) []byte { - return []byte(fmt.Sprintf("%s/%s", modulePrefix, key)) -} - // formatAccumPrefix returns the key prefix used // specifically for accumulator values in the KVStore. // Returns "accum/acc/{name}" as bytes. func formatAccumPrefixKey(name string) []byte { - return formatModulePrefixKey(fmt.Sprintf("%s/%s", accumulatorPrefix, name)) + return []byte(fmt.Sprintf(modulePrefix+"/"+accumulatorPrefix+"/%s", name)) } // FormatPositionPrefixKey returns the key prefix used // specifically for position values in the KVStore. -// Returns "accum/pos/{accumName}/{name}" as bytes. +// Returns "accum/acc/pos/{accumName}/{name}" as bytes. func FormatPositionPrefixKey(accumName, name string) []byte { - return formatAccumPrefixKey(fmt.Sprintf("%s/%s/%s", positionPrefix, accumName, name)) + return []byte(fmt.Sprintf(modulePrefix+"/"+accumulatorPrefix+"/"+positionPrefix+"/%s/%s", accumName, name)) } diff --git a/proto/osmosis/concentrated-liquidity/tx.proto b/proto/osmosis/concentrated-liquidity/tx.proto index 217961db2e0..1f36da41f93 100644 --- a/proto/osmosis/concentrated-liquidity/tx.proto +++ b/proto/osmosis/concentrated-liquidity/tx.proto @@ -69,12 +69,6 @@ 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/proto/osmosis/superfluid/tx.proto b/proto/osmosis/superfluid/tx.proto index 1a4301eb6d4..86c0f37a8b5 100644 --- a/proto/osmosis/superfluid/tx.proto +++ b/proto/osmosis/superfluid/tx.proto @@ -150,8 +150,9 @@ message MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition { ]; // token_out_mins indicates minimum token to exit Balancer pool with. repeated cosmos.base.v1beta1.Coin token_out_mins = 4 [ - (gogoproto.moretags) = "yaml:\"token_out_min_amounts\"", - (gogoproto.nullable) = false + (gogoproto.moretags) = "yaml:\"token_out_mins\"", + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" ]; } diff --git a/tests/cl-genesis-positions/go.mod b/tests/cl-genesis-positions/go.mod index efb9515b252..0a68fbc9d82 100644 --- a/tests/cl-genesis-positions/go.mod +++ b/tests/cl-genesis-positions/go.mod @@ -6,7 +6,7 @@ require ( github.com/cosmos/cosmos-sdk v0.47.2 github.com/ignite/cli v0.23.0 github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230503232557-ba905586c111 - github.com/osmosis-labs/osmosis/v15 v15.0.0-20230504143153-c7d6a52cd9f5 + github.com/osmosis-labs/osmosis/v15 v15.0.0-20230513050746-13c81d83ef0d github.com/tendermint/tendermint v0.34.26 ) @@ -101,7 +101,7 @@ require ( github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_golang v1.15.0 // indirect + github.com/prometheus/client_golang v1.15.1 // indirect github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect diff --git a/tests/cl-genesis-positions/go.sum b/tests/cl-genesis-positions/go.sum index 2f77fd7ff16..4d8ef90bc93 100644 --- a/tests/cl-genesis-positions/go.sum +++ b/tests/cl-genesis-positions/go.sum @@ -695,12 +695,10 @@ github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20230326212251-7a2cf2993434 h1:RetE github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20230326212251-7a2cf2993434/go.mod h1:ss3tUfPTwaa6NsoPZrCR7xOqLqCK0LwoNbc2Q8Zs5/Y= 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/osmoutils v0.0.0-20230504001814-1dbcc2079de1 h1:1yzJYsP1bWOX/8/aGA8Mk/UFiU9z/h6LRAr2OezyYQ8= -github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230504001814-1dbcc2079de1/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230510161551-8bf252f26bae h1:I1Cy+GpTPWbVi0lBw9+bS1w42YfQjvXNK9bW4YbHhcs= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230510161551-8bf252f26bae/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= -github.com/osmosis-labs/osmosis/v15 v15.0.0-20230504143153-c7d6a52cd9f5 h1:M4fG/zxok1+9y5SWas1sBzDZWfSbGs7vezE1NF7niCk= -github.com/osmosis-labs/osmosis/v15 v15.0.0-20230504143153-c7d6a52cd9f5/go.mod h1:NEoCQ+jkE0o6CUorEUhRdwdbvXYl5nt4oZeevaEz29o= +github.com/osmosis-labs/osmosis/v15 v15.0.0-20230513050746-13c81d83ef0d h1:8lJNaOABRchMwMO+DoHEGrlrBXlhDloms1GKs/ti8HA= +github.com/osmosis-labs/osmosis/v15 v15.0.0-20230513050746-13c81d83ef0d/go.mod h1:mdvXaHvcLi1Loo2sUF1FPV3RynReBpexO3g3ktEWQA4= 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= @@ -744,8 +742,8 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.15.0 h1:5fCgGYogn0hFdhyhLbw7hEsWxufKtY9klyvdNfFlFhM= -github.com/prometheus/client_golang v1.15.0/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk= +github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI= +github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= diff --git a/tests/cl-go-client/go.mod b/tests/cl-go-client/go.mod index 5d209c66e3f..9a94e464cf0 100644 --- a/tests/cl-go-client/go.mod +++ b/tests/cl-go-client/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/cosmos/cosmos-sdk v0.47.2 github.com/ignite/cli v0.23.0 - github.com/osmosis-labs/osmosis/v15 v15.0.0-20230502194055-e465f0b40c14 + github.com/osmosis-labs/osmosis/v15 v15.0.0-20230502194055-13c81d83ef0d ) diff --git a/tests/cl-go-client/go.sum b/tests/cl-go-client/go.sum index f6d58cd00e3..12dcffdbbb9 100644 --- a/tests/cl-go-client/go.sum +++ b/tests/cl-go-client/go.sum @@ -688,7 +688,6 @@ github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20230326212251-7a2cf2993434 h1:RetE github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20230326212251-7a2cf2993434/go.mod h1:ss3tUfPTwaa6NsoPZrCR7xOqLqCK0LwoNbc2Q8Zs5/Y= 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/osmoutils v0.0.0-20230504190933-b174397f0bc5 h1:fBzTtgZHxvZkpwlg6YtAsNaexEHYaFZDXsYfPQWu9GE= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230510161551-8bf252f26bae h1:I1Cy+GpTPWbVi0lBw9+bS1w42YfQjvXNK9bW4YbHhcs= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230510161551-8bf252f26bae/go.mod h1:hk/o9/kmTSZmZqwXcSrPuwj/gpRMCqbE/d3vj6teL2A= github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 h1:RIrWLzIiZN5Xd2JOfSOtGZaf6V3qEQYg6EaDTAkMnCo= @@ -731,8 +730,6 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.15.0 h1:5fCgGYogn0hFdhyhLbw7hEsWxufKtY9klyvdNfFlFhM= -github.com/prometheus/client_golang v1.15.0/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk= github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI= github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 63f60d3ee92..8c9448baedc 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 57de9236d00..aba9414ad13 100644 --- a/x/concentrated-liquidity/README.md +++ b/x/concentrated-liquidity/README.md @@ -284,15 +284,6 @@ 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/export_internal.go b/x/concentrated-liquidity/export_internal.go index 4eb7cb713a4..669464fb038 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, sqrtPrice sdk.Dec, err error) { +func TickToSqrtPrice(tickIndex sdk.Int) (price 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 4ef0a24224a..682ff6254a3 100644 --- a/x/concentrated-liquidity/export_test.go +++ b/x/concentrated-liquidity/export_test.go @@ -158,10 +158,6 @@ 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) @@ -195,7 +191,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) (positionId uint64, actualAmount0 sdk.Int, actualAmount1 sdk.Int, liquidityDelta sdk.Dec, joinTime time.Time, lowerTickResult int64, upperTickResult int64, err error) { +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) { 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 0cb7231928a..0ee5d92b940 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 68e2ed667b4..f39ef5acd0a 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 0abfb7885f5..5c815c91aad 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(expectedLowerFeeGrowthOppositeDirectionOfLastTraversal.String(), lowerTickInfo.FeeGrowthOppositeDirectionOfLastTraversal.String()) + s.Require().Equal(lowerTickInfo.FeeGrowthOppositeDirectionOfLastTraversal.String(), expectedLowerFeeGrowthOppositeDirectionOfLastTraversal.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(expectedUpperFeeGrowthOppositeDirectionOfLastTraversal.String(), upperTickInfo.FeeGrowthOppositeDirectionOfLastTraversal.String()) + s.Require().Equal(upperTickInfo.FeeGrowthOppositeDirectionOfLastTraversal.String(), expectedUpperFeeGrowthOppositeDirectionOfLastTraversal.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 30dbec38026..f9059551e58 100644 --- a/x/concentrated-liquidity/lp.go +++ b/x/concentrated-liquidity/lp.go @@ -31,86 +31,80 @@ 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) (positionId uint64, actualAmount0 sdk.Int, actualAmount1 sdk.Int, liquidityDelta sdk.Dec, joinTime time.Time, lowerTickResult int64, upperTickResult int64, err error) { +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) { // 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{}, 0, 0, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 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{}, 0, 0, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 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{}, 0, 0, errors.New("cannot create a position with zero amounts of both pool tokens") + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 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{}, 0, 0, types.NotPositiveRequireAmountError{Amount: amount0Min.String()} + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, types.NotPositiveRequireAmountError{Amount: amount0Min.String()} } if amount1Min.IsNegative() { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, types.NotPositiveRequireAmountError{Amount: amount1Min.String()} + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, types.NotPositiveRequireAmountError{Amount: amount1Min.String()} } // Transform the provided ticks into their corresponding sqrtPrices. - priceLowerTick, priceUpperTick, sqrtPriceLowerTick, sqrtPriceUpperTick, err := math.TicksToSqrtPrice(lowerTick, upperTick) + sqrtPriceLowerTick, sqrtPriceUpperTick, err := math.TicksToSqrtPrice(lowerTick, upperTick) if err != nil { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 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{}, 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{}, 0, 0, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, err } if !hasPositions { err := k.initializeInitialPositionForPool(ctx, pool, amount0Desired, amount1Desired) if err != nil { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 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{}, 0, 0, errors.New("liquidityDelta calculated equals zero") + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 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{}, 0, 0, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 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{}, 0, 0, types.InsufficientLiquidityCreatedError{Actual: actualAmount0, Minimum: amount0Min, IsTokenZero: true} + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, types.InsufficientLiquidityCreatedError{Actual: actualAmount0, Minimum: amount0Min, IsTokenZero: true} } if actualAmount1.LT(amount1Min) { - return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, types.InsufficientLiquidityCreatedError{Actual: actualAmount1, Minimum: amount1Min} + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 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{}, 0, 0, err + return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, err } emitLiquidityChangeEvent(ctx, types.TypeEvtCreatePosition, positionId, owner, poolId, lowerTick, upperTick, joinTime, liquidityDelta, actualAmount0, actualAmount1) @@ -118,12 +112,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 the initial position is created, only + // initializes the pool's spot price. After initial position is created, only // swaps update the spot price. k.listeners.AfterInitialPoolPositionCreated(ctx, owner, poolId) } - return positionId, actualAmount0, actualAmount1, liquidityDelta, joinTime, lowerTick, upperTick, nil + return positionId, actualAmount0, actualAmount1, liquidityDelta, joinTime, nil } // WithdrawPosition attempts to withdraw liquidityAmount from a position with the given pool id in the given tick range. @@ -305,7 +299,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 d613081ad01..373a7976e63 100644 --- a/x/concentrated-liquidity/lp_test.go +++ b/x/concentrated-liquidity/lp_test.go @@ -18,9 +18,7 @@ type lpTest struct { poolId uint64 currentTick sdk.Int lowerTick int64 - expectedLowerTick int64 upperTick int64 - expectedUpperTick int64 joinTime time.Time positionId uint64 underlyingLockId uint64 @@ -154,25 +152,6 @@ 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, - }, } ) @@ -308,7 +287,7 @@ func (s *KeeperTestSuite) TestCreatePosition() { poolBalancePrePositionCreation := s.App.BankKeeper.GetAllBalances(s.Ctx, pool.GetAddress()) // System under test. - 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) + 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) // Note user and pool account balances to compare after create position is called userBalancePostPositionCreation := s.App.BankKeeper.GetAllBalances(s.Ctx, s.TestAccs[0]) @@ -344,14 +323,6 @@ 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()) @@ -529,7 +500,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) } @@ -671,7 +642,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) } }) @@ -973,14 +944,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) } @@ -1088,12 +1059,6 @@ 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 - } } } @@ -1358,7 +1323,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], @@ -1524,17 +1489,6 @@ 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 @@ -1585,18 +1539,9 @@ func (s *KeeperTestSuite) TestInverseRelation_CreatePosition_WithdrawPosition() poolBalancePrePositionCreation := s.App.BankKeeper.GetAllBalances(s.Ctx, poolBefore.GetAddress()) // System under test. - 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) + positionId, amtDenom0CreatePosition, amtDenom1CreatePosition, liquidityCreated, _, 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) @@ -1604,21 +1549,21 @@ func (s *KeeperTestSuite) TestInverseRelation_CreatePosition_WithdrawPosition() // INVARIANTS // 1. amount for denom0 and denom1 upon creating and withdraw position should be same - // 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)) + // 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()) // 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: 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: 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 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))) + // 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()) // 3. Check that position's liquidity was deleted positionLiquidity, err := clKeeper.GetPositionLiquidity(s.Ctx, tc.positionId) @@ -1634,8 +1579,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(0, errToleranceOneRoundUp.Compare(liquidityBefore.AmountOf(ETH), liquidityAfter.AmountOf(ETH))) - s.Require().Equal(0, errToleranceOneRoundUp.Compare(liquidityBefore.AmountOf(USDC), liquidityAfter.AmountOf(USDC))) + 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()) }) } } diff --git a/x/concentrated-liquidity/math/precompute.go b/x/concentrated-liquidity/math/precompute.go new file mode 100644 index 00000000000..7996ba3058e --- /dev/null +++ b/x/concentrated-liquidity/math/precompute.go @@ -0,0 +1,44 @@ +package math + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/osmosis/osmomath" +) + +var ( + sdkOneInt = sdk.OneInt() + sdkOneDec = sdk.NewDec(1) + sdkNineDec = sdk.NewDec(9) + sdkTenDec = sdk.NewDec(10) + powersOfTen []sdk.Dec + negPowersOfTen []sdk.Dec + + osmomathBigOneDec = osmomath.NewBigDec(1) + osmomathBigTenDec = osmomath.NewBigDec(10) + bigPowersOfTen []osmomath.BigDec + bigNegPowersOfTen []osmomath.BigDec +) + +// Set precision multipliers +func init() { + negPowersOfTen = make([]sdk.Dec, sdk.Precision+1) + for i := 0; i <= sdk.Precision; i++ { + negPowersOfTen[i] = sdkOneDec.Quo(sdkTenDec.Power(uint64(i))) + } + // 10^77 < sdk.MaxInt < 10^78 + powersOfTen = make([]sdk.Dec, 78) + for i := 0; i <= 77; i++ { + powersOfTen[i] = sdkTenDec.Power(uint64(i)) + } + + bigNegPowersOfTen = make([]osmomath.BigDec, osmomath.Precision+1) + for i := 0; i <= osmomath.Precision; i++ { + bigNegPowersOfTen[i] = osmomathBigOneDec.Quo(osmomathBigTenDec.PowerInteger(uint64(i))) + } + // 10^308 < osmomath.MaxInt < 10^309 + bigPowersOfTen = make([]osmomath.BigDec, 309) + for i := 0; i <= 308; i++ { + bigPowersOfTen[i] = osmomathBigTenDec.PowerInteger(uint64(i)) + } +} diff --git a/x/concentrated-liquidity/math/tick.go b/x/concentrated-liquidity/math/tick.go index 45972a17dba..5a1138a7243 100644 --- a/x/concentrated-liquidity/math/tick.go +++ b/x/concentrated-liquidity/math/tick.go @@ -9,44 +9,39 @@ import ( "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types" ) -var ( - sdkNineDec = sdk.NewDec(9) - sdkTenDec = sdk.NewDec(10) -) - // 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, sdk.Dec, sdk.Dec, error) { +func TicksToSqrtPrice(lowerTick, upperTick int64) (sdk.Dec, sdk.Dec, error) { if lowerTick >= upperTick { - return sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, types.InvalidLowerUpperTickError{LowerTick: lowerTick, UpperTick: upperTick} + return sdk.Dec{}, sdk.Dec{}, types.InvalidLowerUpperTickError{LowerTick: lowerTick, UpperTick: upperTick} } - priceUpperTick, sqrtPriceUpperTick, err := TickToSqrtPrice(sdk.NewInt(upperTick)) + sqrtPriceUpperTick, err := TickToSqrtPrice(sdk.NewInt(upperTick)) if err != nil { - return sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, err + return sdk.Dec{}, sdk.Dec{}, err } - priceLowerTick, sqrtPriceLowerTick, err := TickToSqrtPrice(sdk.NewInt(lowerTick)) + sqrtPriceLowerTick, err := TickToSqrtPrice(sdk.NewInt(lowerTick)) if err != nil { - return sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, sdk.Dec{}, err + return sdk.Dec{}, sdk.Dec{}, err } - return priceLowerTick, priceUpperTick, sqrtPriceLowerTick, sqrtPriceUpperTick, nil + return 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, sdk.Dec, error) { +func TickToSqrtPrice(tickIndex sdk.Int) (sdk.Dec, error) { price, err := TickToPrice(tickIndex) if err != nil { - return sdk.Dec{}, sdk.Dec{}, err + return sdk.Dec{}, err } // Determine the sqrtPrice from the price sqrtPrice, err := price.ApproxSqrt() if err != nil { - return sdk.Dec{}, sdk.Dec{}, err + return sdk.Dec{}, err } - return price, sqrtPrice, nil + return sqrtPrice, nil } // TickToPrice returns the price given a tickIndex @@ -77,7 +72,7 @@ func TickToPrice(tickIndex sdk.Int) (price sdk.Dec, err error) { if tickIndex.IsNegative() { // We must decrement the exponentAtCurrentTick when entering the negative tick range 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 = exponentAtCurrentTick.Sub(sdk.OneInt()) + exponentAtCurrentTick = exponentAtCurrentTick.Sub(sdkOneInt) } // Knowing what our exponentAtCurrentTick is, we can then figure out what power of 10 this exponent corresponds to @@ -146,16 +141,16 @@ func PriceToTickRoundDown(price sdk.Dec, tickSpacing uint64) (sdk.Int, error) { // This is because the sdk.Dec.Power function does not support negative exponents func PowTenInternal(exponent sdk.Int) sdk.Dec { if exponent.GTE(sdk.ZeroInt()) { - return sdkTenDec.Power(exponent.Uint64()) + return powersOfTen[exponent.Int64()] } - return sdk.OneDec().Quo(sdkTenDec.Power(exponent.Abs().Uint64())) + return negPowersOfTen[-exponent.Int64()] } func powTenBigDec(exponent sdk.Int) osmomath.BigDec { if exponent.GTE(sdk.ZeroInt()) { - return osmomath.NewBigDec(10).PowerInteger(exponent.Uint64()) + return bigPowersOfTen[exponent.Int64()] } - return osmomath.OneDec().Quo(osmomath.NewBigDec(10).PowerInteger(exponent.Abs().Uint64())) + return bigNegPowersOfTen[-exponent.Int64()] } // CalculatePriceToTick takes in a price and returns the corresponding tick index. @@ -180,23 +175,23 @@ func CalculatePriceToTick(price sdk.Dec) (tickIndex sdk.Int) { // as well as how many ticks that corresponds to // In the opposite direction (price < 1), we do the same thing (just decrement the geometric exponent instead of incrementing). // The only difference is we must reduce the increment distance by a factor of 10. - if price.GT(sdk.OneDec()) { + if price.GT(sdkOneDec) { for currentPrice.LT(price) { currentAdditiveIncrementInTicks = powTenBigDec(exponentAtCurrentTick) maxPriceForCurrentAdditiveIncrementInTicks := osmomath.BigDecFromSDKDec(geometricExponentIncrementDistanceInTicks).Mul(currentAdditiveIncrementInTicks) - currentPrice = currentPrice.Add(maxPriceForCurrentAdditiveIncrementInTicks.SDKDec()) - exponentAtCurrentTick = exponentAtCurrentTick.Add(sdk.OneInt()) + currentPrice.AddMut(maxPriceForCurrentAdditiveIncrementInTicks.SDKDec()) + exponentAtCurrentTick = exponentAtCurrentTick.Add(sdkOneInt) 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()) + exponentAtCurrentTick := exponentAtPriceOne.Sub(sdkOneInt) for currentPrice.GT(price) { currentAdditiveIncrementInTicks = powTenBigDec(exponentAtCurrentTick) maxPriceForCurrentAdditiveIncrementInTicks := osmomath.BigDecFromSDKDec(geometricExponentIncrementDistanceInTicks).Mul(currentAdditiveIncrementInTicks) - currentPrice = currentPrice.Sub(maxPriceForCurrentAdditiveIncrementInTicks.SDKDec()) - exponentAtCurrentTick = exponentAtCurrentTick.Sub(sdk.OneInt()) + currentPrice.SubMut(maxPriceForCurrentAdditiveIncrementInTicks.SDKDec()) + exponentAtCurrentTick = exponentAtCurrentTick.Sub(sdkOneInt) ticksPassed = ticksPassed.Sub(geometricExponentIncrementDistanceInTicks.TruncateInt()) } } diff --git a/x/concentrated-liquidity/math/tick_test.go b/x/concentrated-liquidity/math/tick_test.go index 18eb73bd0f3..c37ff7ac4e7 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() { - price, sqrtPrice, err := math.TickToSqrtPrice(tc.tickIndex) + sqrtPrice, err := math.TickToSqrtPrice(tc.tickIndex) if tc.expectedError != nil { suite.Require().Error(err) suite.Require().Equal(tc.expectedError.Error(), err.Error()) @@ -192,7 +192,6 @@ 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()) }) } @@ -250,7 +249,7 @@ func (suite *ConcentratedMathTestSuite) TestTicksToSqrtPrice() { for name, tc := range testCases { tc := tc suite.Run(name, func() { - priceLower, priceUpper, lowerSqrtPrice, upperSqrtPrice, err := math.TicksToSqrtPrice(tc.lowerTickIndex.Int64(), tc.upperTickIndex.Int64()) + 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()) @@ -264,8 +263,6 @@ 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()) }) @@ -580,7 +577,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 4e3d0857203..123c1537802 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 0a532cb43c5..678d0f70df0 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 fba3525c909..0ad3a7bcb08 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, lowerTick, upperTick, err := server.keeper.createPosition(ctx, msg.PoolId, sender, msg.TokensProvided, msg.TokenMinAmount0, msg.TokenMinAmount1, msg.LowerTick, msg.UpperTick) + positionId, actualAmount0, actualAmount1, liquidityCreated, joinTime, 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, LowerTick: lowerTick, UpperTick: upperTick}, nil + return &types.MsgCreatePositionResponse{PositionId: positionId, Amount0: actualAmount0, Amount1: actualAmount1, JoinTime: joinTime, LiquidityCreated: liquidityCreated}, 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 1a5a2a2e1e4..95836bf61a6 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 420d14065d9..ebce8ab8b27 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 3b1ed50c920..1c7c7ab249b 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 1cba311d2a3..8ca5420a405 100644 --- a/x/concentrated-liquidity/swaps.go +++ b/x/concentrated-liquidity/swaps.go @@ -66,7 +66,7 @@ func (ss *SwapState) updateFeeGrowthGlobal(feeChargeTotal sdk.Dec) { // We round down here since we want to avoid overdistributing (the "fee charge" refers to // the total fees that will be accrued to the fee accumulator) feesAccruedPerUnitOfLiquidity := feeChargeTotal.QuoTruncate(ss.liquidity) - ss.feeGrowthGlobal = ss.feeGrowthGlobal.Add(feesAccruedPerUnitOfLiquidity) + ss.feeGrowthGlobal.AddMut(feesAccruedPerUnitOfLiquidity) return } } @@ -331,8 +331,8 @@ func (k Keeper) computeOutAmtGivenIn( return sdk.Coin{}, sdk.Coin{}, sdk.Int{}, sdk.Dec{}, sdk.Dec{}, fmt.Errorf("there are no more ticks initialized to fill the swap") } - // Utilizing the next initialized tick, we find the corresponding nextPrice (the target price) - _, nextTickSqrtPrice, err := math.TickToSqrtPrice(nextTick) + // Utilizing the next initialized tick, we find the corresponding nextPrice (the target price). + 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 f59e3049730..b1ee2f65969 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) } @@ -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 c84ece6d0d6..09a62ec34f8 100644 --- a/x/concentrated-liquidity/tick.go +++ b/x/concentrated-liquidity/tick.go @@ -191,37 +191,6 @@ 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) @@ -363,7 +332,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 } @@ -373,7 +342,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 21a802e7099..e347cd611bb 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 @@ -1407,89 +1407,3 @@ func (s *KeeperTestSuite) TestGetAllInitializedTicksForPool() { }) } } - -func (s *KeeperTestSuite) TestRoundTickToCanonicalPriceTick() { - tests := []struct { - name string - lowerTick int64 - upperTick int64 - expectedNewLowerTick int64 - expectedNewUpperTick int64 - expectedError error - }{ - { - name: "exact upper tick for 0.000000000000000003 to exact lower tick for 0.000000000000000002", - lowerTick: -161000000, - expectedNewLowerTick: -161000000, - upperTick: -160000000, - expectedNewUpperTick: -160000000, - }, - { - name: "exact upper tick for 0.000000000000000003 to inexact lower tick for 0.000000000000000002", - lowerTick: -161001234, - expectedNewLowerTick: -161000000, - upperTick: -160000000, - expectedNewUpperTick: -160000000, - }, - { - name: "inexact upper tick for 0.000000000000000003 to exact lower tick for 0.000000000000000002", - lowerTick: -161000000, - expectedNewLowerTick: -161000000, - upperTick: -160001234, - expectedNewUpperTick: -160000000, - }, - { - name: "inexact upper tick for 0.000000000000000003 to inexact lower tick for 0.000000000000000002", - lowerTick: -161001234, - expectedNewLowerTick: -161000000, - upperTick: -160001234, - expectedNewUpperTick: -160000000, - }, - { - name: "upper tick one tick away from lower tick", - lowerTick: -161001234, - expectedNewLowerTick: -161000000, - upperTick: -160999999, - expectedNewUpperTick: -160000000, - }, - { - name: "error: new upper tick is lower than new lower tick", - lowerTick: -160001234, - expectedNewLowerTick: -160000000, - upperTick: -161001234, - expectedNewUpperTick: -161000000, - expectedError: types.InvalidLowerUpperTickError{LowerTick: -160000000, UpperTick: -161000000}, - }, - { - name: "error: new upper tick is the same as new lower tick", - lowerTick: -160001234, - expectedNewLowerTick: -160000000, - upperTick: -160000000, - expectedNewUpperTick: -160000000, - expectedError: types.InvalidLowerUpperTickError{LowerTick: -160000000, UpperTick: -160000000}, - }, - } - - for _, test := range tests { - s.Run(test.name, func() { - s.SetupTest() - - priceTickLower, _, err := cl.TickToSqrtPrice(sdk.NewInt(test.lowerTick)) - s.Require().NoError(err) - priceTickUpper, _, err := cl.TickToSqrtPrice(sdk.NewInt(test.upperTick)) - s.Require().NoError(err) - - // System Under Test - newLowerTick, newUpperTick, err := cl.RoundTickToCanonicalPriceTick(test.lowerTick, test.upperTick, priceTickLower, priceTickUpper, DefaultTickSpacing) - - if test.expectedError != nil { - s.Require().Error(err) - s.Require().ErrorContains(err, test.expectedError.Error()) - } else { - s.Require().NoError(err) - s.Require().Equal(test.expectedNewLowerTick, newLowerTick) - s.Require().Equal(test.expectedNewUpperTick, newUpperTick) - } - }) - } -} diff --git a/x/concentrated-liquidity/types/tx.pb.go b/x/concentrated-liquidity/types/tx.pb.go index 1e8cd211e35..2929b838987 100644 --- a/x/concentrated-liquidity/types/tx.pb.go +++ b/x/concentrated-liquidity/types/tx.pb.go @@ -123,12 +123,6 @@ 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{} } @@ -178,20 +172,6 @@ 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"` @@ -860,90 +840,89 @@ func init() { } var fileDescriptor_1f1fff802923d7db = []byte{ - // 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,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f, 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, 0xa0, 0xb5, 0x28, 0xc4, 0xa9, 0x49, 0xf8, 0xb8, 0x02, 0x64, 0x31, 0xd7, 0x08, - 0xf9, 0xb1, 0x0d, 0xc6, 0x36, 0x98, 0x15, 0x47, 0xb2, 0xc3, 0xf1, 0xbc, 0x70, 0x0b, 0xda, 0x0b, - 0x87, 0x56, 0x55, 0x08, 0x42, 0x6d, 0x79, 0x0b, 0x54, 0x91, 0x87, 0x29, 0x0d, 0xf3, 0x23, 0xfc, - 0x02, 0x89, 0x3a, 0xd0, 0xb4, 0x79, 0xa7, 0xf0, 0xa3, 0xb4, 0xc4, 0xcd, 0xed, 0x21, 0x83, 0xd6, - 0x99, 0x64, 0x6d, 0x39, 0x0c, 0xc9, 0x9f, 0x01, 0x40, 0x99, 0x13, 0x30, 0x3e, 0x06, 0x9d, 0x7a, - 0xe5, 0x18, 0x94, 0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0xe6, - 0x38, 0xf7, 0x41, 0x15, 0x00, 0x00, + // 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, 0x51, 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a5, 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, 0x7a, 0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, + 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, } // Reference imports to suppress errors if they are not otherwise used. @@ -1341,16 +1320,6 @@ 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 @@ -2045,12 +2014,6 @@ 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 } @@ -2704,44 +2667,6 @@ 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:]) diff --git a/x/gamm/types/key.go b/x/gamm/types/key.go index ebfea87e42f..36a00421380 100644 --- a/x/gamm/types/key.go +++ b/x/gamm/types/key.go @@ -33,12 +33,11 @@ var ( ) func MustGetPoolIdFromShareDenom(denom string) uint64 { - numberStr := strings.TrimLeft(denom, GAMMTokenPrefix) - number, err := strconv.Atoi(numberStr) + number, err := GetPoolIdFromShareDenom(denom) if err != nil { panic(err) } - return uint64(number) + return number } func GetPoolIdFromShareDenom(denom string) (uint64, error) { diff --git a/x/superfluid/client/cli/tx.go b/x/superfluid/client/cli/tx.go index 9394ab92a47..ff5c7a020b0 100644 --- a/x/superfluid/client/cli/tx.go +++ b/x/superfluid/client/cli/tx.go @@ -37,6 +37,7 @@ func GetTxCmd() *cobra.Command { ) osmocli.AddTxCmd(cmd, NewCreateFullRangePositionAndSuperfluidDelegateCmd) osmocli.AddTxCmd(cmd, NewAddToConcentratedLiquiditySuperfluidPositionCmd) + osmocli.AddTxCmd(cmd, NewUnlockAndMigrateSharesToFullRangeConcentratedPositionCmd) return cmd } @@ -414,3 +415,11 @@ func NewAddToConcentratedLiquiditySuperfluidPositionCmd() (*osmocli.TxCliDesc, * Example: "add-to-superfluid-cl-position 10 1000000000uosmo 10000000uion", }, &types.MsgAddToConcentratedLiquiditySuperfluidPosition{} } + +func NewUnlockAndMigrateSharesToFullRangeConcentratedPositionCmd() (*osmocli.TxCliDesc, *types.MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition) { + return &osmocli.TxCliDesc{ + Use: "unlock-and-migrate-to-cl [lock-id] [shares-to-migrate] [token-out-mins]", + Short: "unlock and migrate gamm shares to full range concentrated position", + Example: "unlock-and-migrate-cl 10 25000000000gamm/pool/2 1000000000uosmo,10000000uion", + }, &types.MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition{} +} diff --git a/x/superfluid/keeper/export_test.go b/x/superfluid/keeper/export_test.go index 87c821c7cb5..8e060af977a 100644 --- a/x/superfluid/keeper/export_test.go +++ b/x/superfluid/keeper/export_test.go @@ -7,6 +7,7 @@ import ( cltypes "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types" lockuptypes "github.com/osmosis-labs/osmosis/v15/x/lockup/types" + "github.com/osmosis-labs/osmosis/v15/x/superfluid/types" ) var ( @@ -45,3 +46,15 @@ func (k Keeper) PrepareMigration(ctx sdk.Context, sender sdk.AccAddress, lockId func (k Keeper) AddToConcentratedLiquiditySuperfluidPosition(ctx sdk.Context, owner sdk.AccAddress, positionId uint64, amount0Added, amount1Added sdk.Int) (uint64, sdk.Int, sdk.Int, sdk.Dec, uint64, error) { return k.addToConcentratedLiquiditySuperfluidPosition(ctx, owner, positionId, amount0Added, amount1Added) } + +func (k Keeper) SuperfluidUndelegateToConcentratedPosition(ctx sdk.Context, sender string, gammLockID uint64) (types.SuperfluidIntermediaryAccount, error) { + return k.superfluidUndelegateToConcentratedPosition(ctx, sender, gammLockID) +} + +func (k Keeper) ValidateGammLockForSuperfluidStaking(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, lockId uint64) (*lockuptypes.PeriodLock, error) { + return k.validateGammLockForSuperfluidStaking(ctx, sender, poolId, lockId) +} + +func (k Keeper) GetExistingLockRemainingDuration(ctx sdk.Context, lock *lockuptypes.PeriodLock) (time.Duration, error) { + return k.getExistingLockRemainingDuration(ctx, lock) +} diff --git a/x/superfluid/keeper/migrate.go b/x/superfluid/keeper/migrate.go index 2e34469df40..902b321568d 100644 --- a/x/superfluid/keeper/migrate.go +++ b/x/superfluid/keeper/migrate.go @@ -66,7 +66,7 @@ func (k Keeper) migrateSuperfluidBondedBalancerToConcentrated(ctx sdk.Context, // Superfluid undelegate the superfluid delegated position. // This deletes the connection between the lock and the intermediate account, deletes the synthetic lock, and burns the synthetic osmo. - intermediateAccount, err := k.SuperfluidUndelegateToConcentratedPosition(ctx, sender.String(), lockId) + intermediateAccount, err := k.superfluidUndelegateToConcentratedPosition(ctx, sender.String(), lockId) if err != nil { return 0, sdk.Int{}, sdk.Int{}, sdk.Dec{}, time.Time{}, 0, 0, err } @@ -286,13 +286,16 @@ func (k Keeper) prepareMigration(ctx sdk.Context, sender sdk.AccAddress, lockId } // Check that lockID corresponds to sender, and contains correct denomination of LP shares. - preMigrationLock, err = k.validateLockForUnpool(ctx, sender, poolIdLeaving, lockId) + preMigrationLock, err = k.validateGammLockForSuperfluidStaking(ctx, sender, poolIdLeaving, lockId) if err != nil { return 0, 0, nil, &lockuptypes.PeriodLock{}, 0, nil, false, false, err } // Before we break the lock, we must note the time remaining on the lock. - remainingLockTime = k.getExistingLockRemainingDuration(ctx, preMigrationLock) + remainingLockTime, err = k.getExistingLockRemainingDuration(ctx, preMigrationLock) + if err != nil { + return 0, 0, nil, &lockuptypes.PeriodLock{}, 0, nil, false, false, err + } // Check if the lock has a corresponding synthetic lock. // Synthetic lock existence implies that the lock is superfluid delegated or undelegating. diff --git a/x/superfluid/keeper/msg_server.go b/x/superfluid/keeper/msg_server.go index 7b9138b3ce5..c60f3e3387c 100644 --- a/x/superfluid/keeper/msg_server.go +++ b/x/superfluid/keeper/msg_server.go @@ -132,38 +132,6 @@ func (server msgServer) LockAndSuperfluidDelegate(goCtx context.Context, msg *ty }, err } -func (server msgServer) CreateFullRangePositionAndSuperfluidDelegate(goCtx context.Context, msg *types.MsgCreateFullRangePositionAndSuperfluidDelegate) (*types.MsgCreateFullRangePositionAndSuperfluidDelegateResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - address, err := sdk.AccAddressFromBech32(msg.Sender) - if err != nil { - return &types.MsgCreateFullRangePositionAndSuperfluidDelegateResponse{}, err - } - positionId, _, _, _, _, lockId, err := server.keeper.clk.CreateFullRangePositionLocked(ctx, msg.PoolId, address, msg.Coins, server.keeper.sk.GetParams(ctx).UnbondingTime) - if err != nil { - return &types.MsgCreateFullRangePositionAndSuperfluidDelegateResponse{}, err - } - - superfluidDelegateMsg := types.MsgSuperfluidDelegate{ - Sender: msg.Sender, - LockId: lockId, - ValAddr: msg.ValAddr, - } - - _, err = server.SuperfluidDelegate(goCtx, &superfluidDelegateMsg) - - if err != nil { - return &types.MsgCreateFullRangePositionAndSuperfluidDelegateResponse{}, err - } - - events.EmitCreateFullRangePositionAndSuperfluidDelegateEvent(ctx, lockId, positionId, msg.ValAddr) - - return &types.MsgCreateFullRangePositionAndSuperfluidDelegateResponse{ - LockID: lockId, - PositionID: positionId, - }, nil -} - func (server msgServer) UnPoolWhitelistedPool(goCtx context.Context, msg *types.MsgUnPoolWhitelistedPool) (*types.MsgUnPoolWhitelistedPoolResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -197,6 +165,38 @@ func (server msgServer) UnPoolWhitelistedPool(goCtx context.Context, msg *types. return &types.MsgUnPoolWhitelistedPoolResponse{ExitedLockIds: allExitedLockIDs}, nil } +func (server msgServer) CreateFullRangePositionAndSuperfluidDelegate(goCtx context.Context, msg *types.MsgCreateFullRangePositionAndSuperfluidDelegate) (*types.MsgCreateFullRangePositionAndSuperfluidDelegateResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + address, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return &types.MsgCreateFullRangePositionAndSuperfluidDelegateResponse{}, err + } + positionId, _, _, _, _, lockId, err := server.keeper.clk.CreateFullRangePositionLocked(ctx, msg.PoolId, address, msg.Coins, server.keeper.sk.GetParams(ctx).UnbondingTime) + if err != nil { + return &types.MsgCreateFullRangePositionAndSuperfluidDelegateResponse{}, err + } + + superfluidDelegateMsg := types.MsgSuperfluidDelegate{ + Sender: msg.Sender, + LockId: lockId, + ValAddr: msg.ValAddr, + } + + _, err = server.SuperfluidDelegate(goCtx, &superfluidDelegateMsg) + + if err != nil { + return &types.MsgCreateFullRangePositionAndSuperfluidDelegateResponse{}, err + } + + events.EmitCreateFullRangePositionAndSuperfluidDelegateEvent(ctx, lockId, positionId, msg.ValAddr) + + return &types.MsgCreateFullRangePositionAndSuperfluidDelegateResponse{ + LockID: lockId, + PositionID: positionId, + }, nil +} + func (server msgServer) UnlockAndMigrateSharesToFullRangeConcentratedPosition(goCtx context.Context, msg *types.MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition) (*types.MsgUnlockAndMigrateSharesToFullRangeConcentratedPositionResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index e7e329ee876..3f1da11de32 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -473,15 +473,6 @@ func (suite *KeeperTestSuite) TestMsgUnPoolWhitelistedPool_Event() { func (suite *KeeperTestSuite) TestUnlockAndMigrateSharesToFullRangeConcentratedPosition_Event() { suite.SetupTest() - const ( - token0Denom = "token0" - ) - - // Update authorized quote denoms with the quote denom relied on by the test - concentratedLiquidityParams := suite.App.ConcentratedLiquidityKeeper.GetParams(suite.Ctx) - concentratedLiquidityParams.AuthorizedQuoteDenoms = append(concentratedLiquidityParams.AuthorizedQuoteDenoms, token0Denom) - suite.App.ConcentratedLiquidityKeeper.SetParams(suite.Ctx, concentratedLiquidityParams) - msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) suite.FundAcc(suite.TestAccs[0], defaultAcctFunds) fullRangeCoins := sdk.NewCoins(defaultPoolAssets[0].Token, defaultPoolAssets[1].Token) @@ -489,7 +480,7 @@ func (suite *KeeperTestSuite) TestUnlockAndMigrateSharesToFullRangeConcentratedP // Set validators valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) - // Set balancer pool and make its respective gamm share an authorized superfluid asset + // Set balancer pool (foo and stake) and make its respective gamm share an authorized superfluid asset msg := balancer.NewMsgCreateBalancerPool(suite.TestAccs[0], balancer.PoolParams{ SwapFee: sdk.NewDecWithPrec(1, 2), ExitFee: sdk.NewDec(0), @@ -505,7 +496,7 @@ func (suite *KeeperTestSuite) TestUnlockAndMigrateSharesToFullRangeConcentratedP }) suite.Require().NoError(err) - // Set concentrated pool with the same denoms as the balancer pool + // Set concentrated pool with the same denoms as the balancer pool (foo and stake) clPool := suite.PrepareCustomConcentratedPool(suite.TestAccs[0], defaultPoolAssets[0].Token.Denom, defaultPoolAssets[1].Token.Denom, 1, sdk.ZeroDec()) // Set migration link between the balancer and concentrated pool @@ -529,7 +520,8 @@ func (suite *KeeperTestSuite) TestUnlockAndMigrateSharesToFullRangeConcentratedP suite.Require().NoError(err) // Execute UnlockAndMigrateSharesToFullRangeConcentratedPosition message - sender, _ := sdk.AccAddressFromBech32(locks[0].Owner) + sender, err := sdk.AccAddressFromBech32(locks[0].Owner) + suite.Require().NoError(err) _, err = msgServer.UnlockAndMigrateSharesToFullRangeConcentratedPosition(sdk.WrapSDKContext(suite.Ctx), types.NewMsgUnlockAndMigrateSharesToFullRangeConcentratedPosition(sender, locks[0].ID, locks[0].Coins[0])) suite.Require().NoError(err) diff --git a/x/superfluid/keeper/stake.go b/x/superfluid/keeper/stake.go index 8ead741735f..20a0ae0dbfd 100644 --- a/x/superfluid/keeper/stake.go +++ b/x/superfluid/keeper/stake.go @@ -242,7 +242,7 @@ func (k Keeper) SuperfluidDelegate(ctx sdk.Context, sender string, lockID uint64 return k.mintOsmoTokensAndDelegate(ctx, amount, acc) } -// undelegateCommon is a helper function for SuperfluidUndelegate and SuperfluidUndelegateToConcentratedPosition. +// undelegateCommon is a helper function for SuperfluidUndelegate and superfluidUndelegateToConcentratedPosition. // It performs the following tasks: // - checks that the lock is valid for superfluid staking // - gets the intermediary account associated with the lock id diff --git a/x/superfluid/keeper/unpool.go b/x/superfluid/keeper/unpool.go index 0f3dfadc4b5..f2be67e163c 100644 --- a/x/superfluid/keeper/unpool.go +++ b/x/superfluid/keeper/unpool.go @@ -33,14 +33,17 @@ func (k Keeper) UnpoolAllowedPools(ctx sdk.Context, sender sdk.AccAddress, poolI // 2) Consistency check that lockID corresponds to sender, and contains correct LP shares. // These are expected to be true by the caller, but good to double check // TODO: Try to minimize dependence on lock here - lock, err := k.validateLockForUnpool(ctx, sender, poolId, lockId) + lock, err := k.validateGammLockForSuperfluidStaking(ctx, sender, poolId, lockId) if err != nil { return []uint64{}, err } gammSharesInLock := lock.Coins[0] // 3) Get remaining duration on the lock. Handle if the lock was unbonding. - lockRemainingDuration := k.getExistingLockRemainingDuration(ctx, lock) + lockRemainingDuration, err := k.getExistingLockRemainingDuration(ctx, lock) + if err != nil { + return []uint64{}, err + } // 4) If superfluid delegated, superfluid undelegate err = k.unbondSuperfluidIfExists(ctx, sender, lockId) @@ -99,39 +102,48 @@ func (k Keeper) checkUnpoolWhitelisted(ctx sdk.Context, poolId uint64) error { return types.ErrPoolNotWhitelisted } -// check if pool is whitelisted for unpool -func (k Keeper) validateLockForUnpool(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, lockId uint64) (*lockuptypes.PeriodLock, error) { +// validateGammLockForSuperfluidStaking checks if the provided lock: +// 1) is owned by the provided sender +// 2) contains only 1 coin +// 3) contains the gamm LP shares associated with the provided poolId +func (k Keeper) validateGammLockForSuperfluidStaking(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, lockId uint64) (*lockuptypes.PeriodLock, error) { lock, err := k.lk.GetLockByID(ctx, lockId) if err != nil { - return lock, err + return &lockuptypes.PeriodLock{}, err } - // consistency check: validate lock owner - // However, we expect this to be guaranteed by caller though. + // Validate lock owner. + // We expect this to be guaranteed by caller, though. if lock.Owner != sender.String() { - return lock, lockuptypes.ErrNotLockOwner + return &lockuptypes.PeriodLock{}, lockuptypes.ErrNotLockOwner } if lock.Coins.Len() != 1 { - return lock, types.ErrMultipleCoinsLockupNotSupported + return &lockuptypes.PeriodLock{}, types.ErrMultipleCoinsLockupNotSupported } gammShare := lock.Coins[0] if gammShare.Denom != gammtypes.GetPoolShareDenom(poolId) { - return lock, types.ErrLockUnpoolNotAllowed + return &lockuptypes.PeriodLock{}, types.UnexpectedDenomError{ExpectedDenom: gammtypes.GetPoolShareDenom(poolId), ProvidedDenom: gammShare.Denom} } return lock, nil } -func (k Keeper) getExistingLockRemainingDuration(ctx sdk.Context, lock *lockuptypes.PeriodLock) time.Duration { +// getExistingLockRemainingDuration returns the time remaining until the lock is finished unlocking. +// If the lock is not unlocking, then the duration field of the lock is returned. +func (k Keeper) getExistingLockRemainingDuration(ctx sdk.Context, lock *lockuptypes.PeriodLock) (time.Duration, error) { if lock.IsUnlocking() { - // lock is unlocking, so remaining duration equals lock.EndTime - ctx.BlockTime + // Lock is unlocking, so remaining duration equals lock.EndTime - ctx.BlockTime. remainingDuration := lock.EndTime.Sub(ctx.BlockTime()) - return remainingDuration + // Defense in depth, ensure the duration is not negative. + if remainingDuration < 0 { + return 0, types.NegativeDurationError{Duration: remainingDuration} + } + return remainingDuration, nil } - // lock is bonded, thus the time it should take to unlock is lock.Duration - return lock.Duration + // Lock is not unlocking, thus the time it should take to unlock is the locks duration. + return lock.Duration, nil } // TODO: Review this in more depth diff --git a/x/superfluid/keeper/unpool_test.go b/x/superfluid/keeper/unpool_test.go index 19433dab95f..86d78dd9e4c 100644 --- a/x/superfluid/keeper/unpool_test.go +++ b/x/superfluid/keeper/unpool_test.go @@ -1,14 +1,17 @@ package keeper_test import ( + "fmt" "time" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/osmosis-labs/osmosis/v15/x/gamm/pool-models/balancer" gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types" + lockuptypes "github.com/osmosis-labs/osmosis/v15/x/lockup/types" "github.com/osmosis-labs/osmosis/v15/x/superfluid/keeper" "github.com/osmosis-labs/osmosis/v15/x/superfluid/types" ) @@ -280,3 +283,146 @@ func (suite *KeeperTestSuite) TestUnpoolAllowedPools_WhiteList() { suite.Error(err) suite.Require().ErrorIs(err, types.ErrPoolNotWhitelisted) } + +func (suite *KeeperTestSuite) TestValidateGammLockForSuperfluid() { + lockCreator := suite.TestAccs[0] + nonLockCreator := suite.TestAccs[1] + type sendTest struct { + fundsToLock sdk.Coins + accountToValidate sdk.AccAddress + poolIdToValidate uint64 + lockIdToValidate uint64 + expectedError error + } + testCases := map[string]sendTest{ + "happy path": { + fundsToLock: sdk.NewCoins(sdk.NewCoin("gamm/pool/1", sdk.NewInt(100))), + accountToValidate: lockCreator, + poolIdToValidate: 1, + lockIdToValidate: 1, + }, + "error: non-existent lock ID": { + fundsToLock: sdk.NewCoins(sdk.NewCoin("gamm/pool/1", sdk.NewInt(100))), + accountToValidate: lockCreator, + poolIdToValidate: 1, + lockIdToValidate: 2, + expectedError: errorsmod.Wrap(lockuptypes.ErrLockupNotFound, fmt.Sprintf("lock with ID %d does not exist", 2)), + }, + "error: mismatched owner": { + fundsToLock: sdk.NewCoins(sdk.NewCoin("gamm/pool/1", sdk.NewInt(100))), + accountToValidate: nonLockCreator, + poolIdToValidate: 1, + lockIdToValidate: 1, + expectedError: lockuptypes.ErrNotLockOwner, + }, + "error: more than one coin in lock": { + fundsToLock: sdk.NewCoins(sdk.NewCoin("gamm/pool/1", sdk.NewInt(100)), + sdk.NewCoin("gamm/pool/2", sdk.NewInt(100))), + accountToValidate: lockCreator, + poolIdToValidate: 1, + lockIdToValidate: 1, + expectedError: types.ErrMultipleCoinsLockupNotSupported, + }, + "error: wrong pool ID provided when compared to lock denom": { + fundsToLock: sdk.NewCoins(sdk.NewCoin("gamm/pool/1", sdk.NewInt(100))), + accountToValidate: lockCreator, + poolIdToValidate: 2, + lockIdToValidate: 1, + expectedError: types.UnexpectedDenomError{ExpectedDenom: gammtypes.GetPoolShareDenom(2), ProvidedDenom: "gamm/pool/1"}, + }, + "error: right pool ID provided but not gamm/pool/ prefix": { + fundsToLock: sdk.NewCoins(sdk.NewCoin("cl/pool/1", sdk.NewInt(100))), + accountToValidate: lockCreator, + poolIdToValidate: 1, + lockIdToValidate: 1, + expectedError: types.UnexpectedDenomError{ExpectedDenom: gammtypes.GetPoolShareDenom(1), ProvidedDenom: "cl/pool/1"}, + }, + } + + for name, tc := range testCases { + suite.Run(name, func() { + suite.SetupTest() + + ctx := suite.Ctx + superfluidKeeper := suite.App.SuperfluidKeeper + + suite.FundAcc(lockCreator, tc.fundsToLock) + _, err := suite.App.LockupKeeper.CreateLock(ctx, lockCreator, tc.fundsToLock, time.Hour) + suite.Require().NoError(err) + + // System under test + _, err = superfluidKeeper.ValidateGammLockForSuperfluidStaking(ctx, tc.accountToValidate, tc.poolIdToValidate, tc.lockIdToValidate) + if tc.expectedError != nil { + suite.Require().Error(err) + suite.Require().ErrorContains(err, tc.expectedError.Error()) + return + } + suite.Require().NoError(err) + }) + } +} + +func (suite *KeeperTestSuite) TestGetExistingLockRemainingDuration() { + defaultJoinTime := suite.Ctx.BlockTime() + lockCreator := suite.TestAccs[0] + type sendTest struct { + isUnlocking bool + lockDuration time.Duration + timePassed time.Duration + expectedRemainingDuration time.Duration + expectedError error + } + testCases := map[string]sendTest{ + "lock that is not unlocking": { + isUnlocking: false, + lockDuration: time.Hour, + timePassed: time.Hour, + expectedRemainingDuration: time.Hour, + }, + "lock that is unlocking": { + isUnlocking: true, + lockDuration: time.Hour, + timePassed: time.Minute, + expectedRemainingDuration: time.Hour - time.Minute, + }, + "error: negative duration": { + isUnlocking: true, + lockDuration: time.Hour, + timePassed: time.Hour + time.Minute, + expectedError: types.NegativeDurationError{Duration: -time.Minute}, + }, + } + + for name, tc := range testCases { + suite.Run(name, func() { + suite.SetupTest() + ctx := suite.Ctx.WithBlockTime(defaultJoinTime) + + superfluidKeeper := suite.App.SuperfluidKeeper + + suite.FundAcc(lockCreator, defaultAcctFunds) + lock, err := suite.App.LockupKeeper.CreateLock(ctx, lockCreator, defaultAcctFunds, tc.lockDuration) + suite.Require().NoError(err) + + if tc.isUnlocking { + _, err = suite.App.LockupKeeper.BeginUnlock(ctx, lock.ID, defaultAcctFunds) + suite.Require().NoError(err) + } + + ctx = ctx.WithBlockTime(defaultJoinTime.Add(tc.timePassed)) + + lockAfterTime, err := suite.App.LockupKeeper.GetLockByID(ctx, lock.ID) + suite.Require().NoError(err) + + // System under test + remainingDuration, err := superfluidKeeper.GetExistingLockRemainingDuration(ctx, lockAfterTime) + if tc.expectedError != nil { + suite.Require().Error(err) + suite.Require().ErrorContains(err, tc.expectedError.Error()) + return + } + suite.Require().NoError(err) + suite.Require().Equal(tc.expectedRemainingDuration, remainingDuration) + }) + } +} diff --git a/x/superfluid/types/tx.pb.go b/x/superfluid/types/tx.pb.go index 1d8fa701c2f..dc67bf1baa7 100644 --- a/x/superfluid/types/tx.pb.go +++ b/x/superfluid/types/tx.pb.go @@ -766,7 +766,7 @@ type MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition struct { LockId uint64 `protobuf:"varint,2,opt,name=lock_id,json=lockId,proto3" json:"lock_id,omitempty" yaml:"lock_id"` SharesToMigrate types.Coin `protobuf:"bytes,3,opt,name=shares_to_migrate,json=sharesToMigrate,proto3" json:"shares_to_migrate" yaml:"shares_to_migrate"` // token_out_mins indicates minimum token to exit Balancer pool with. - TokenOutMins []types.Coin `protobuf:"bytes,4,rep,name=token_out_mins,json=tokenOutMins,proto3" json:"token_out_mins" yaml:"token_out_min_amounts"` + TokenOutMins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=token_out_mins,json=tokenOutMins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"token_out_mins" yaml:"token_out_mins"` } func (m *MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition) Reset() { @@ -827,7 +827,7 @@ func (m *MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition) GetSharesToMi return types.Coin{} } -func (m *MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition) GetTokenOutMins() []types.Coin { +func (m *MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition) GetTokenOutMins() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { return m.TokenOutMins }