diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f7ab03e294..13e58821946 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Features + + * [#4659](https://github.com/osmosis-labs/osmosis/pull/4659) implement AllPools query in x/poolmanager. + ### Misc Improvements * [#4582](https://github.com/osmosis-labs/osmosis/pull/4582) Consistently generate build tags metadata, to return a comma-separated list without stray quotes. This affects the output from `version` CLI subcommand and server info API calls. diff --git a/go.mod b/go.mod index 716dff2cc66..aea7a46f88d 100644 --- a/go.mod +++ b/go.mod @@ -19,10 +19,10 @@ require ( github.com/mattn/go-sqlite3 v1.14.16 github.com/ory/dockertest/v3 v3.9.1 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 - github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230317170635-70db68a41756 - github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230317170635-70db68a41756 - github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230317170635-70db68a41756 - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230317170635-70db68a41756 + github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230316203321-2edd49875f80 + github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230317232332-81bd3c5ef0c2 + github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230313084619-8d291c1d9813 + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230316203321-2edd49875f80 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.5.0 diff --git a/go.sum b/go.sum index f9a3cb501c7..3877819127f 100644 --- a/go.sum +++ b/go.sum @@ -936,14 +936,16 @@ github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20230313061712-4f857c6a941a h1:ycdL github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20230313061712-4f857c6a941a/go.mod h1:rud0OaBIuq3+qOqtwT4SR7Q7iSzRp7w41fjninTjfnQ= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI= -github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230317170635-70db68a41756 h1:31CYo5M3EG0w9WKIJsvRLSbYOBgGChb4zRQGMv7mXpg= -github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230317170635-70db68a41756/go.mod h1:PT796t7vS3STUWYikgwzY9e7jhLo0N/hwZf4R6haj0o= -github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230317170635-70db68a41756 h1:F+c8S5V3F79iomTcJ4IClazDXiCQ1+/UPfLytXcqQGU= -github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230317170635-70db68a41756/go.mod h1:spcwVLt51T9NAUpFb+W0UKO7e9mwF5K/hc3nTrmGoP4= -github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230317170635-70db68a41756 h1:y/xTswWzB7WlAlOIjbY6Eli3REbtScyc2jfd3NRvihE= -github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230317170635-70db68a41756/go.mod h1:lJebPe8cmSTwXXuWmgSNc1S4Bobz9g3x05ZL4igbAAI= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230317170635-70db68a41756 h1:HUc7lu50WjvV0ZwD2eymdtv/glgJUG57KDuRSntfjNc= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230317170635-70db68a41756/go.mod h1:M8MLeBNbbG6qB5/2B5RUPTvqhsNaG0XagqdQfk/lVfY= +github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230316203321-2edd49875f80 h1:MqSb3Q5Uqb2r3PcyijgFL0lcIe57PqncqyfkRtyyn6E= +github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230316203321-2edd49875f80/go.mod h1:PT796t7vS3STUWYikgwzY9e7jhLo0N/hwZf4R6haj0o= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230316203321-2edd49875f80 h1:p/+OkuP3fvSK6UvUxeaX6JirBMhs2yveDmT9Vi80Je0= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230316203321-2edd49875f80/go.mod h1:spcwVLt51T9NAUpFb+W0UKO7e9mwF5K/hc3nTrmGoP4= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230317232332-81bd3c5ef0c2 h1:syLNakfGKE9SjReHzcE8B0vWaykxKeno10uOyHi+0aI= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230317232332-81bd3c5ef0c2/go.mod h1:spcwVLt51T9NAUpFb+W0UKO7e9mwF5K/hc3nTrmGoP4= +github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230313084619-8d291c1d9813 h1:OVT8hqFET8DkAeiSUs5h2nTg1uZFU6kPRP2sDWzVm/o= +github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230313084619-8d291c1d9813/go.mod h1:lJebPe8cmSTwXXuWmgSNc1S4Bobz9g3x05ZL4igbAAI= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230316203321-2edd49875f80 h1:8gZdQsLkU0XOJ43xlzr1ig9fTVqgdZcoGbLL0ZnUzZs= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230316203321-2edd49875f80/go.mod h1:M8MLeBNbbG6qB5/2B5RUPTvqhsNaG0XagqdQfk/lVfY= github.com/osmosis-labs/wasmd v0.30.0-osmo-v15 h1:vjbzq9ta/KmQwUM6PcRmrBJuDwILgLbV4POypC1Uhn8= github.com/osmosis-labs/wasmd v0.30.0-osmo-v15/go.mod h1:5fDYJyMXBq6u2iuHqqOTYiZ5NitIOeIW5k7qEXqbwJE= github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw= diff --git a/osmoutils/slice_helper.go b/osmoutils/slice_helper.go index a7ee4db4eb0..54cc2dc8493 100644 --- a/osmoutils/slice_helper.go +++ b/osmoutils/slice_helper.go @@ -49,3 +49,32 @@ func ContainsDuplicate[T any](arr []T) bool { } return false } + +type LessFunc[T any] func(a, b T) bool + +// MergeSlices efficiently merges two sorted slices into a single sorted slice. +// The resulting slice contains all elements from slice1 and slice2, sorted according to the less function. +// The input slices must be sorted in ascending order according to the less function. +// The less function takes two elements of type T and returns a boolean value indicating whether the first element is less than the second element. +// The function returns a new slice containing all elements from slice1 and slice2, sorted according to the less function. +// The function does not modify the input slices. +func MergeSlices[T any](slice1, slice2 []T, less LessFunc[T]) []T { + result := make([]T, 0, len(slice1)+len(slice2)) + i, j := 0, 0 + + for i < len(slice1) && j < len(slice2) { + if less(slice1[i], slice2[j]) { + result = append(result, slice1[i]) + i++ + } else { + result = append(result, slice2[j]) + j++ + } + } + + // Append any remaining elements from slice1 and slice2 + result = append(result, slice1[i:]...) + result = append(result, slice2[j:]...) + + return result +} diff --git a/osmoutils/slice_helper_test.go b/osmoutils/slice_helper_test.go index eebdcc4ae6c..36552dc4015 100644 --- a/osmoutils/slice_helper_test.go +++ b/osmoutils/slice_helper_test.go @@ -1,6 +1,7 @@ package osmoutils_test import ( + "reflect" "testing" "github.com/stretchr/testify/require" @@ -28,3 +29,47 @@ func TestReverseSlice(t *testing.T) { }) } } + +func TestMergeSlices(t *testing.T) { + lessInt := func(a, b int) bool { + return a < b + } + testCases := []struct { + name string + slice1 []int + slice2 []int + less func(a, b int) bool + want []int + }{ + { + name: "basic merge", + slice1: []int{1, 3, 5}, + slice2: []int{2, 4, 6}, + less: lessInt, + want: []int{1, 2, 3, 4, 5, 6}, + }, + { + name: "Empty slice1", + slice1: []int{}, + slice2: []int{2, 4, 6}, + less: lessInt, + want: []int{2, 4, 6}, + }, + { + name: "Empty slice2", + slice1: []int{1, 3, 5}, + slice2: []int{}, + less: lessInt, + want: []int{1, 3, 5}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + got := osmoutils.MergeSlices(tc.slice1, tc.slice2, lessInt) + if !reflect.DeepEqual(got, tc.want) { + t.Errorf("got: %v, want: %v", got, tc.want) + } + }) + } +} diff --git a/proto/osmosis/poolmanager/v1beta1/query.proto b/proto/osmosis/poolmanager/v1beta1/query.proto index 223f2997a52..ea554bccf40 100644 --- a/proto/osmosis/poolmanager/v1beta1/query.proto +++ b/proto/osmosis/poolmanager/v1beta1/query.proto @@ -44,6 +44,11 @@ service Query { option (google.api.http).get = "/osmosis/poolmanager/v1beta1/pools/{pool_id}"; } + + // AllPools returns all pools on the Osmosis chain sorted by IDs. + rpc AllPools(AllPoolsRequest) returns (AllPoolsResponse) { + option (google.api.http).get = "/osmosis/poolmanager/v1beta1/all-pools"; + } } //=============================== Params @@ -103,3 +108,12 @@ message PoolRequest { message PoolResponse { google.protobuf.Any pool = 1 [ (cosmos_proto.accepts_interface) = "PoolI" ]; } + +//=============================== AllPools +message AllPoolsRequest { + uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ]; +} +message AllPoolsResponse { + repeated google.protobuf.Any pools = 1 + [ (cosmos_proto.accepts_interface) = "PoolI" ]; +} diff --git a/proto/osmosis/poolmanager/v1beta1/query.yml b/proto/osmosis/poolmanager/v1beta1/query.yml index 62480c49a23..192da8fe447 100644 --- a/proto/osmosis/poolmanager/v1beta1/query.yml +++ b/proto/osmosis/poolmanager/v1beta1/query.yml @@ -25,6 +25,11 @@ queries: cmd: "NumPools" Pool: proto_wrapper: - query_func: "k.Pool" + query_func: "k.RoutePool" cli: cmd: "Pool" + AllPools: + proto_wrapper: + query_func: "k.AllPools" + cli: + cmd: "AllPools" diff --git a/tests/mocks/pool_module.go b/tests/mocks/pool_module.go new file mode 100644 index 00000000000..a2f220d0cbb --- /dev/null +++ b/tests/mocks/pool_module.go @@ -0,0 +1,171 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: /root/osmosis/x/poolmanager/types/routes.go + +// Package mocks is a generated GoMock package. +package mocks + +import ( + reflect "reflect" + + types "github.com/cosmos/cosmos-sdk/types" + gomock "github.com/golang/mock/gomock" + types2 "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types" +) + + +// MockPoolModuleI is a mock of PoolModuleI interface. +type MockPoolModuleI struct { + ctrl *gomock.Controller + recorder *MockPoolModuleIMockRecorder +} + +// MockPoolModuleIMockRecorder is the mock recorder for MockPoolModuleI. +type MockPoolModuleIMockRecorder struct { + mock *MockPoolModuleI +} + +// NewMockPoolModuleI creates a new mock instance. +func NewMockPoolModuleI(ctrl *gomock.Controller) *MockPoolModuleI { + mock := &MockPoolModuleI{ctrl: ctrl} + mock.recorder = &MockPoolModuleIMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockPoolModuleI) EXPECT() *MockPoolModuleIMockRecorder { + return m.recorder +} + +// CalcInAmtGivenOut mocks base method. +func (m *MockPoolModuleI) CalcInAmtGivenOut(ctx types.Context, poolI types2.PoolI, tokenOut types.Coin, tokenInDenom string, swapFee types.Dec) (types.Coin, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CalcInAmtGivenOut", ctx, poolI, tokenOut, tokenInDenom, swapFee) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CalcInAmtGivenOut indicates an expected call of CalcInAmtGivenOut. +func (mr *MockPoolModuleIMockRecorder) CalcInAmtGivenOut(ctx, poolI, tokenOut, tokenInDenom, swapFee interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CalcInAmtGivenOut", reflect.TypeOf((*MockPoolModuleI)(nil).CalcInAmtGivenOut), ctx, poolI, tokenOut, tokenInDenom, swapFee) +} + +// CalcOutAmtGivenIn mocks base method. +func (m *MockPoolModuleI) CalcOutAmtGivenIn(ctx types.Context, poolI types2.PoolI, tokenIn types.Coin, tokenOutDenom string, swapFee types.Dec) (types.Coin, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CalcOutAmtGivenIn", ctx, poolI, tokenIn, tokenOutDenom, swapFee) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CalcOutAmtGivenIn indicates an expected call of CalcOutAmtGivenIn. +func (mr *MockPoolModuleIMockRecorder) CalcOutAmtGivenIn(ctx, poolI, tokenIn, tokenOutDenom, swapFee interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CalcOutAmtGivenIn", reflect.TypeOf((*MockPoolModuleI)(nil).CalcOutAmtGivenIn), ctx, poolI, tokenIn, tokenOutDenom, swapFee) +} + +// CalculateSpotPrice mocks base method. +func (m *MockPoolModuleI) CalculateSpotPrice(ctx types.Context, poolId uint64, quoteAssetDenom, baseAssetDenom string) (types.Dec, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CalculateSpotPrice", ctx, poolId, quoteAssetDenom, baseAssetDenom) + ret0, _ := ret[0].(types.Dec) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CalculateSpotPrice indicates an expected call of CalculateSpotPrice. +func (mr *MockPoolModuleIMockRecorder) CalculateSpotPrice(ctx, poolId, quoteAssetDenom, baseAssetDenom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CalculateSpotPrice", reflect.TypeOf((*MockPoolModuleI)(nil).CalculateSpotPrice), ctx, poolId, quoteAssetDenom, baseAssetDenom) +} + +// GetPool mocks base method. +func (m *MockPoolModuleI) GetPool(ctx types.Context, poolId uint64) (types2.PoolI, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetPool", ctx, poolId) + ret0, _ := ret[0].(types2.PoolI) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetPool indicates an expected call of GetPool. +func (mr *MockPoolModuleIMockRecorder) GetPool(ctx, poolId interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPool", reflect.TypeOf((*MockPoolModuleI)(nil).GetPool), ctx, poolId) +} + +// GetPoolDenoms mocks base method. +func (m *MockPoolModuleI) GetPoolDenoms(ctx types.Context, poolId uint64) ([]string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetPoolDenoms", ctx, poolId) + ret0, _ := ret[0].([]string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetPoolDenoms indicates an expected call of GetPoolDenoms. +func (mr *MockPoolModuleIMockRecorder) GetPoolDenoms(ctx, poolId interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPoolDenoms", reflect.TypeOf((*MockPoolModuleI)(nil).GetPoolDenoms), ctx, poolId) +} + +// GetPools mocks base method. +func (m *MockPoolModuleI) GetPools(ctx types.Context) ([]types2.PoolI, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetPools", ctx) + ret0, _ := ret[0].([]types2.PoolI) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetPools indicates an expected call of GetPools. +func (mr *MockPoolModuleIMockRecorder) GetPools(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPools", reflect.TypeOf((*MockPoolModuleI)(nil).GetPools), ctx) +} + +// InitializePool mocks base method. +func (m *MockPoolModuleI) InitializePool(ctx types.Context, pool types2.PoolI, creatorAddress types.AccAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitializePool", ctx, pool, creatorAddress) + ret0, _ := ret[0].(error) + return ret0 +} + +// InitializePool indicates an expected call of InitializePool. +func (mr *MockPoolModuleIMockRecorder) InitializePool(ctx, pool, creatorAddress interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitializePool", reflect.TypeOf((*MockPoolModuleI)(nil).InitializePool), ctx, pool, creatorAddress) +} + +// SwapExactAmountIn mocks base method. +func (m *MockPoolModuleI) SwapExactAmountIn(ctx types.Context, sender types.AccAddress, pool types2.PoolI, tokenIn types.Coin, tokenOutDenom string, tokenOutMinAmount types.Int, swapFee types.Dec) (types.Int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SwapExactAmountIn", ctx, sender, pool, tokenIn, tokenOutDenom, tokenOutMinAmount, swapFee) + ret0, _ := ret[0].(types.Int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SwapExactAmountIn indicates an expected call of SwapExactAmountIn. +func (mr *MockPoolModuleIMockRecorder) SwapExactAmountIn(ctx, sender, pool, tokenIn, tokenOutDenom, tokenOutMinAmount, swapFee interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SwapExactAmountIn", reflect.TypeOf((*MockPoolModuleI)(nil).SwapExactAmountIn), ctx, sender, pool, tokenIn, tokenOutDenom, tokenOutMinAmount, swapFee) +} + +// SwapExactAmountOut mocks base method. +func (m *MockPoolModuleI) SwapExactAmountOut(ctx types.Context, sender types.AccAddress, pool types2.PoolI, tokenInDenom string, tokenInMaxAmount types.Int, tokenOut types.Coin, swapFee types.Dec) (types.Int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SwapExactAmountOut", ctx, sender, pool, tokenInDenom, tokenInMaxAmount, tokenOut, swapFee) + ret0, _ := ret[0].(types.Int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SwapExactAmountOut indicates an expected call of SwapExactAmountOut. +func (mr *MockPoolModuleIMockRecorder) SwapExactAmountOut(ctx, sender, pool, tokenInDenom, tokenInMaxAmount, tokenOut, swapFee interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SwapExactAmountOut", reflect.TypeOf((*MockPoolModuleI)(nil).SwapExactAmountOut), ctx, sender, pool, tokenInDenom, tokenInMaxAmount, tokenOut, swapFee) +} \ No newline at end of file diff --git a/x/concentrated-liquidity/genesis.go b/x/concentrated-liquidity/genesis.go index 5056a43d5f5..a1c940da377 100644 --- a/x/concentrated-liquidity/genesis.go +++ b/x/concentrated-liquidity/genesis.go @@ -46,7 +46,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState genesis.GenesisState) { // ExportGenesis returns the concentrated-liquidity module's exported genesis state. func (k Keeper) ExportGenesis(ctx sdk.Context) *genesis.GenesisState { - pools, err := k.GetAllPools(ctx) + pools, err := k.GetPools(ctx) if err != nil { panic(err) } diff --git a/x/concentrated-liquidity/genesis_test.go b/x/concentrated-liquidity/genesis_test.go index 5f07160e10e..91c95485459 100644 --- a/x/concentrated-liquidity/genesis_test.go +++ b/x/concentrated-liquidity/genesis_test.go @@ -186,7 +186,7 @@ func (s *KeeperTestSuite) TestInitGenesis() { clParamsAfterInitialization := clKeeper.GetParams(ctx) s.Require().Equal(tc.genesis.Params.String(), clParamsAfterInitialization.String()) - clPoolsAfterInitialization, err := clKeeper.GetAllPools(ctx) + clPoolsAfterInitialization, err := clKeeper.GetPools(ctx) s.Require().NoError(err) // Check pools diff --git a/x/concentrated-liquidity/pool.go b/x/concentrated-liquidity/pool.go index 9dc68e47ffc..e19c216f256 100644 --- a/x/concentrated-liquidity/pool.go +++ b/x/concentrated-liquidity/pool.go @@ -72,9 +72,9 @@ func (k Keeper) getPoolById(ctx sdk.Context, poolId uint64) (types.ConcentratedP return &pool, nil } -func (k Keeper) GetAllPools(ctx sdk.Context) ([]types.ConcentratedPoolExtension, error) { +func (k Keeper) GetPools(ctx sdk.Context) ([]poolmanagertypes.PoolI, error) { return osmoutils.GatherValuesFromStorePrefix( - ctx.KVStore(k.storeKey), types.PoolPrefix, func(value []byte) (types.ConcentratedPoolExtension, error) { + ctx.KVStore(k.storeKey), types.PoolPrefix, func(value []byte) (poolmanagertypes.PoolI, error) { pool := model.Pool{} err := k.cdc.Unmarshal(value, &pool) if err != nil { diff --git a/x/concentrated-liquidity/simulation/sim_msgs.go b/x/concentrated-liquidity/simulation/sim_msgs.go index c34cd502e2b..9b46b7df429 100644 --- a/x/concentrated-liquidity/simulation/sim_msgs.go +++ b/x/concentrated-liquidity/simulation/sim_msgs.go @@ -234,7 +234,7 @@ func getRandCLPool(k clkeeper.Keeper, sim *osmosimtypes.SimCtx, ctx sdk.Context) rand := sim.GetRand() // get all pools - clPools, err := k.GetAllPools(ctx) + clPools, err := k.GetPools(ctx) if err != nil { return nil, nil, err } @@ -244,10 +244,15 @@ func getRandCLPool(k clkeeper.Keeper, sim *osmosimtypes.SimCtx, ctx sdk.Context) return nil, nil, fmt.Errorf("no pools created") } - randConcentratedPool := clPools[rand.Intn(numPools)] - poolDenoms := []string{randConcentratedPool.GetToken0(), randConcentratedPool.GetToken1()} + randPool := clPools[rand.Intn(numPools)] + randClPool, ok := randPool.(cltypes.ConcentratedPoolExtension) + if !ok { + return nil, nil, fmt.Errorf("pool is not concentrated liquidity pool") + } + + poolDenoms := []string{randClPool.GetToken0(), randClPool.GetToken1()} - return randConcentratedPool, poolDenoms, err + return randClPool, poolDenoms, err } // getRandomTickPositions returns random lowerTick and upperTick divisible by tickSpacing value. diff --git a/x/gamm/keeper/pool.go b/x/gamm/keeper/pool.go index 58eb27b51eb..73a924a9960 100644 --- a/x/gamm/keeper/pool.go +++ b/x/gamm/keeper/pool.go @@ -29,6 +29,21 @@ func (k Keeper) GetPool(ctx sdk.Context, poolId uint64) (poolmanagertypes.PoolI, return k.GetPoolAndPoke(ctx, poolId) } +func (k Keeper) GetPools(ctx sdk.Context) ([]poolmanagertypes.PoolI, error) { + return osmoutils.GatherValuesFromStorePrefix(ctx.KVStore(k.storeKey), types.KeyPrefixPools, func(bz []byte) (poolmanagertypes.PoolI, error) { + pool, err := k.UnmarshalPool(bz) + if err != nil { + return nil, err + } + + if pokePool, ok := pool.(types.WeightedPoolExtension); ok { + pokePool.PokePool(ctx.BlockTime()) + } + + return pool, nil + }) +} + // GetPoolAndPoke returns a PoolI based on it's identifier if one exists. If poolId corresponds // to a pool with weights (e.g. balancer), the weights of the pool are updated via PokePool prior to returning. // TODO: Consider rename to GetPool due to downstream API confusion. diff --git a/x/gamm/types/expected_keepers.go b/x/gamm/types/expected_keepers.go index ab77e9518d8..e01778d8c9d 100644 --- a/x/gamm/types/expected_keepers.go +++ b/x/gamm/types/expected_keepers.go @@ -85,7 +85,7 @@ type PoolManager interface { routes []poolmanagertypes.SwapAmountOutRoute, tokenOut sdk.Coin) (tokenInAmount sdk.Int, err error) - GetPoolModule(ctx sdk.Context, poolId uint64) (poolmanagertypes.SwapI, error) + GetPoolModule(ctx sdk.Context, poolId uint64) (poolmanagertypes.PoolModuleI, error) RoutePool(ctx sdk.Context, poolId uint64) (poolmanagertypes.PoolI, error) } diff --git a/x/poolmanager/client/grpc/grpc_query.go b/x/poolmanager/client/grpc/grpc_query.go index ca9d236800e..48d5a645be8 100644 --- a/x/poolmanager/client/grpc/grpc_query.go +++ b/x/poolmanager/client/grpc/grpc_query.go @@ -70,3 +70,13 @@ func (q Querier) EstimateSwapExactAmountIn(grpcCtx context.Context, return q.Q.EstimateSwapExactAmountIn(ctx, *req) } +func (q Querier) AllPools(grpcCtx context.Context, + req *queryproto.AllPoolsRequest, +) (*queryproto.AllPoolsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + ctx := sdk.UnwrapSDKContext(grpcCtx) + return q.Q.AllPools(ctx, *req) +} + diff --git a/x/poolmanager/client/query_proto_wrap.go b/x/poolmanager/client/query_proto_wrap.go index ee64c321de4..869164d1466 100644 --- a/x/poolmanager/client/query_proto_wrap.go +++ b/x/poolmanager/client/query_proto_wrap.go @@ -102,3 +102,23 @@ func (q Querier) Pool(ctx sdk.Context, req queryproto.PoolRequest) (*queryproto. Pool: any, }, nil } + +func (q Querier) AllPools(ctx sdk.Context, req queryproto.AllPoolsRequest) (*queryproto.AllPoolsResponse, error) { + pools, err := q.K.AllPools(ctx) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + var anyPools []*codectypes.Any + for _, pool := range pools { + any, err := codectypes.NewAnyWithValue(pool) + if err != nil { + return nil, err + } + anyPools = append(anyPools, any) + } + + return &queryproto.AllPoolsResponse{ + Pools: anyPools, + }, nil +} diff --git a/x/poolmanager/client/queryproto/query.pb.go b/x/poolmanager/client/queryproto/query.pb.go index 103d3577e26..3350768e460 100644 --- a/x/poolmanager/client/queryproto/query.pb.go +++ b/x/poolmanager/client/queryproto/query.pb.go @@ -501,6 +501,95 @@ func (m *PoolResponse) GetPool() *types1.Any { return nil } +// =============================== AllPools +type AllPoolsRequest struct { + PoolId uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty" yaml:"pool_id"` +} + +func (m *AllPoolsRequest) Reset() { *m = AllPoolsRequest{} } +func (m *AllPoolsRequest) String() string { return proto.CompactTextString(m) } +func (*AllPoolsRequest) ProtoMessage() {} +func (*AllPoolsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_6256a4106f701b7d, []int{10} +} +func (m *AllPoolsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AllPoolsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AllPoolsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AllPoolsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_AllPoolsRequest.Merge(m, src) +} +func (m *AllPoolsRequest) XXX_Size() int { + return m.Size() +} +func (m *AllPoolsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_AllPoolsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_AllPoolsRequest proto.InternalMessageInfo + +func (m *AllPoolsRequest) GetPoolId() uint64 { + if m != nil { + return m.PoolId + } + return 0 +} + +type AllPoolsResponse struct { + Pools []*types1.Any `protobuf:"bytes,1,rep,name=pools,proto3" json:"pools,omitempty"` +} + +func (m *AllPoolsResponse) Reset() { *m = AllPoolsResponse{} } +func (m *AllPoolsResponse) String() string { return proto.CompactTextString(m) } +func (*AllPoolsResponse) ProtoMessage() {} +func (*AllPoolsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_6256a4106f701b7d, []int{11} +} +func (m *AllPoolsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AllPoolsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AllPoolsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AllPoolsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_AllPoolsResponse.Merge(m, src) +} +func (m *AllPoolsResponse) XXX_Size() int { + return m.Size() +} +func (m *AllPoolsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_AllPoolsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_AllPoolsResponse proto.InternalMessageInfo + +func (m *AllPoolsResponse) GetPools() []*types1.Any { + if m != nil { + return m.Pools + } + return nil +} + func init() { proto.RegisterType((*ParamsRequest)(nil), "osmosis.poolmanager.v1beta1.ParamsRequest") proto.RegisterType((*ParamsResponse)(nil), "osmosis.poolmanager.v1beta1.ParamsResponse") @@ -512,6 +601,8 @@ func init() { proto.RegisterType((*NumPoolsResponse)(nil), "osmosis.poolmanager.v1beta1.NumPoolsResponse") proto.RegisterType((*PoolRequest)(nil), "osmosis.poolmanager.v1beta1.PoolRequest") proto.RegisterType((*PoolResponse)(nil), "osmosis.poolmanager.v1beta1.PoolResponse") + proto.RegisterType((*AllPoolsRequest)(nil), "osmosis.poolmanager.v1beta1.AllPoolsRequest") + proto.RegisterType((*AllPoolsResponse)(nil), "osmosis.poolmanager.v1beta1.AllPoolsResponse") } func init() { @@ -519,64 +610,67 @@ func init() { } var fileDescriptor_6256a4106f701b7d = []byte{ - // 909 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0xcf, 0x26, 0xae, 0x93, 0x4c, 0xc8, 0x9f, 0x0e, 0x01, 0xdc, 0x05, 0x79, 0xc3, 0x14, 0x8a, - 0xd3, 0x24, 0xbb, 0x72, 0x0a, 0x97, 0x4a, 0x6d, 0x89, 0x2b, 0x23, 0x7c, 0xa1, 0x65, 0x7b, 0x43, - 0x2a, 0xd6, 0xd8, 0x1e, 0x96, 0x55, 0xbd, 0x33, 0x5b, 0xcf, 0x6c, 0x1b, 0x0b, 0x71, 0xe1, 0xc6, - 0xa5, 0xe2, 0x8f, 0x04, 0x7c, 0x10, 0x3e, 0x44, 0xc5, 0xa9, 0x12, 0x17, 0xc4, 0xc1, 0x82, 0x04, - 0xbe, 0x80, 0x3f, 0x01, 0xda, 0x99, 0xb7, 0x6b, 0x27, 0x52, 0x36, 0x26, 0x88, 0x93, 0x67, 0xe7, - 0xfd, 0xde, 0x7b, 0xbf, 0xf7, 0x7b, 0xf3, 0x5e, 0x82, 0xde, 0x11, 0x32, 0x12, 0x32, 0x94, 0x5e, - 0x2c, 0x44, 0x3f, 0xa2, 0x9c, 0x06, 0x6c, 0xe0, 0x3d, 0xa9, 0x77, 0x98, 0xa2, 0x75, 0xef, 0x71, - 0xc2, 0x06, 0x43, 0x37, 0x1e, 0x08, 0x25, 0xf0, 0xeb, 0x00, 0x74, 0xa7, 0x80, 0x2e, 0x00, 0xed, - 0xcd, 0x40, 0x04, 0x42, 0xe3, 0xbc, 0xf4, 0x64, 0x5c, 0xec, 0xed, 0xa2, 0xd8, 0x01, 0xe3, 0x4c, - 0x87, 0xd3, 0xd0, 0xb7, 0x8a, 0xa0, 0xea, 0x10, 0x50, 0xbb, 0x45, 0x28, 0xf9, 0x94, 0xc6, 0xed, - 0x81, 0x48, 0x14, 0x03, 0x74, 0xb5, 0xab, 0xe1, 0x5e, 0x87, 0x4a, 0x96, 0xa3, 0xba, 0x22, 0xe4, - 0x60, 0xbf, 0x3e, 0x6d, 0xd7, 0xa5, 0xe6, 0xa8, 0x98, 0x06, 0x21, 0xa7, 0x2a, 0x14, 0x19, 0xf6, - 0x8d, 0x40, 0x88, 0xa0, 0xcf, 0x3c, 0x1a, 0x87, 0x1e, 0xe5, 0x5c, 0x28, 0x6d, 0xcc, 0xd8, 0x5f, - 0x01, 0xab, 0xfe, 0xea, 0x24, 0x9f, 0x79, 0x94, 0x0f, 0x33, 0x93, 0x49, 0xd2, 0x36, 0xe2, 0x98, - 0x0f, 0x30, 0x39, 0xa7, 0xbd, 0x54, 0x18, 0x31, 0xa9, 0x68, 0x14, 0x1b, 0x00, 0x59, 0x47, 0xab, - 0xf7, 0xe9, 0x80, 0x46, 0xd2, 0x67, 0x8f, 0x13, 0x26, 0x15, 0x79, 0x80, 0xd6, 0xb2, 0x0b, 0x19, - 0x0b, 0x2e, 0x19, 0x3e, 0x40, 0xe5, 0x58, 0xdf, 0x54, 0xac, 0x2d, 0xab, 0xb6, 0xb2, 0x7f, 0xd5, - 0x2d, 0x68, 0x93, 0x6b, 0x9c, 0x1b, 0xa5, 0xe7, 0x23, 0x67, 0xce, 0x07, 0x47, 0xf2, 0xf5, 0x3c, - 0xda, 0x6a, 0x4a, 0x15, 0x46, 0x54, 0xb1, 0x07, 0x4f, 0x69, 0xdc, 0x3c, 0xa4, 0x5d, 0x75, 0x10, - 0x89, 0x84, 0xab, 0x16, 0x87, 0xcc, 0x78, 0x1b, 0x95, 0x25, 0xe3, 0x3d, 0x36, 0xd0, 0x79, 0x96, - 0x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, 0xe9, 0xf6, 0x43, 0xc6, 0x95, 0xf9, 0x77, 0xc8, 0xec, 0x82, 0xb2, 0xfe, 0xb9, 0xf1, 0x4f, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x99, 0x1d, 0x42, 0xba, 0x2a, 0x0a, 0x00, 0x00, + // 957 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x41, 0x6f, 0x1b, 0x45, + 0x14, 0xce, 0x26, 0x8e, 0x9b, 0x4c, 0x48, 0x9c, 0x0e, 0x01, 0x5c, 0x83, 0xec, 0x30, 0x85, 0xe2, + 0x34, 0xf1, 0xae, 0x9c, 0xd2, 0x4b, 0xa5, 0xa6, 0xc4, 0x55, 0x10, 0xbe, 0xd0, 0xb2, 0xbd, 0x21, + 0x15, 0x6b, 0xec, 0x0c, 0xcb, 0xaa, 0xbb, 0x33, 0x5b, 0xcf, 0x6c, 0x1b, 0x0b, 0x71, 0xe1, 0xc6, + 0xa5, 0x02, 0x21, 0x01, 0x3f, 0x82, 0x23, 0x3f, 0xa2, 0xe2, 0x54, 0x89, 0x0b, 0xe2, 0x60, 0x41, + 0x02, 0x7f, 0xc0, 0xbf, 0x00, 0xed, 0xcc, 0xdb, 0xb5, 0x63, 0x29, 0x1b, 0x37, 0x88, 0x93, 0xc7, + 0xf3, 0xbe, 0xf7, 0xe6, 0x7b, 0xdf, 0x9b, 0xf9, 0x6c, 0xf4, 0x9e, 0x90, 0xa1, 0x90, 0xbe, 0x74, + 0x22, 0x21, 0x82, 0x90, 0x72, 0xea, 0xb1, 0xbe, 0xf3, 0xa4, 0xd9, 0x65, 0x8a, 0x36, 0x9d, 0xc7, + 0x31, 0xeb, 0x0f, 0xec, 0xa8, 0x2f, 0x94, 0xc0, 0x6f, 0x02, 0xd0, 0x9e, 0x00, 0xda, 0x00, 0xac, + 0x6c, 0x78, 0xc2, 0x13, 0x1a, 0xe7, 0x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5a, 0xd3, 0xae, 0x31, 0xa3, + 0x5a, 0x34, 0x08, 0x1a, 0x9a, 0x63, 0xeb, 0xe1, 0xf3, 0xe3, 0xaa, 0xf5, 0xe2, 0xb8, 0x6a, 0xfd, + 0x79, 0x5c, 0xb5, 0xbe, 0x3d, 0xa9, 0xce, 0xbd, 0x38, 0xa9, 0xce, 0xfd, 0x7e, 0x52, 0x9d, 0xfb, + 0xf4, 0xee, 0x84, 0xff, 0x43, 0xad, 0x46, 0x40, 0xbb, 0x32, 0x2b, 0xfc, 0xa4, 0x79, 0xd3, 0x39, + 0x3a, 0x55, 0xbe, 0x17, 0xf8, 0x8c, 0x2b, 0xf3, 0x9f, 0xd1, 0xd8, 0x54, 0x51, 0x7f, 0xdc, 0xf8, + 0x37, 0x00, 0x00, 0xff, 0xff, 0xd1, 0x71, 0x54, 0xa2, 0x4f, 0x0b, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -600,6 +694,8 @@ type QueryClient interface { NumPools(ctx context.Context, in *NumPoolsRequest, opts ...grpc.CallOption) (*NumPoolsResponse, error) // Pool returns the Pool specified by the pool id Pool(ctx context.Context, in *PoolRequest, opts ...grpc.CallOption) (*PoolResponse, error) + // AllPools returns all pools on the Osmosis chain sorted by IDs. + AllPools(ctx context.Context, in *AllPoolsRequest, opts ...grpc.CallOption) (*AllPoolsResponse, error) } type queryClient struct { @@ -655,6 +751,15 @@ func (c *queryClient) Pool(ctx context.Context, in *PoolRequest, opts ...grpc.Ca return out, nil } +func (c *queryClient) AllPools(ctx context.Context, in *AllPoolsRequest, opts ...grpc.CallOption) (*AllPoolsResponse, error) { + out := new(AllPoolsResponse) + err := c.cc.Invoke(ctx, "/osmosis.poolmanager.v1beta1.Query/AllPools", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { Params(context.Context, *ParamsRequest) (*ParamsResponse, error) @@ -666,6 +771,8 @@ type QueryServer interface { NumPools(context.Context, *NumPoolsRequest) (*NumPoolsResponse, error) // Pool returns the Pool specified by the pool id Pool(context.Context, *PoolRequest) (*PoolResponse, error) + // AllPools returns all pools on the Osmosis chain sorted by IDs. + AllPools(context.Context, *AllPoolsRequest) (*AllPoolsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -687,6 +794,9 @@ func (*UnimplementedQueryServer) NumPools(ctx context.Context, req *NumPoolsRequ func (*UnimplementedQueryServer) Pool(ctx context.Context, req *PoolRequest) (*PoolResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Pool not implemented") } +func (*UnimplementedQueryServer) AllPools(ctx context.Context, req *AllPoolsRequest) (*AllPoolsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AllPools not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -782,6 +892,24 @@ func _Query_Pool_Handler(srv interface{}, ctx context.Context, dec func(interfac return interceptor(ctx, in, info, handler) } +func _Query_AllPools_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllPoolsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AllPools(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.poolmanager.v1beta1.Query/AllPools", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AllPools(ctx, req.(*AllPoolsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "osmosis.poolmanager.v1beta1.Query", HandlerType: (*QueryServer)(nil), @@ -806,6 +934,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Pool", Handler: _Query_Pool_Handler, }, + { + MethodName: "AllPools", + Handler: _Query_AllPools_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "osmosis/poolmanager/v1beta1/query.proto", @@ -1159,6 +1291,71 @@ func (m *PoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *AllPoolsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AllPoolsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AllPoolsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PoolId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PoolId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *AllPoolsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AllPoolsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AllPoolsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Pools) > 0 { + for iNdEx := len(m.Pools) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Pools[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -1310,6 +1507,33 @@ func (m *PoolResponse) Size() (n int) { return n } +func (m *AllPoolsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PoolId != 0 { + n += 1 + sovQuery(uint64(m.PoolId)) + } + return n +} + +func (m *AllPoolsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Pools) > 0 { + for _, e := range m.Pools { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2225,6 +2449,159 @@ func (m *PoolResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *AllPoolsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AllPoolsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AllPoolsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + m.PoolId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PoolId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AllPoolsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AllPoolsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AllPoolsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pools", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Pools = append(m.Pools, &types1.Any{}) + if err := m.Pools[len(m.Pools)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/poolmanager/client/queryproto/query.pb.gw.go b/x/poolmanager/client/queryproto/query.pb.gw.go index 85607d806bd..d6a4c27bf60 100644 --- a/x/poolmanager/client/queryproto/query.pb.gw.go +++ b/x/poolmanager/client/queryproto/query.pb.gw.go @@ -267,6 +267,42 @@ func local_request_Query_Pool_0(ctx context.Context, marshaler runtime.Marshaler } +var ( + filter_Query_AllPools_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_AllPools_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq AllPoolsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AllPools_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AllPools(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AllPools_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq AllPoolsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AllPools_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AllPools(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -388,6 +424,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_AllPools_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AllPools_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AllPools_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -529,6 +588,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_AllPools_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AllPools_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AllPools_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -542,6 +621,8 @@ var ( pattern_Query_NumPools_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "poolmanager", "v1beta1", "num_pools"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_Pool_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"osmosis", "poolmanager", "v1beta1", "pools", "pool_id"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_AllPools_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "poolmanager", "v1beta1", "all-pools"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -554,4 +635,6 @@ var ( forward_Query_NumPools_0 = runtime.ForwardResponseMessage forward_Query_Pool_0 = runtime.ForwardResponseMessage + + forward_Query_AllPools_0 = runtime.ForwardResponseMessage ) diff --git a/x/poolmanager/create_pool.go b/x/poolmanager/create_pool.go index bf02b739c6e..ee9cd4aee8c 100644 --- a/x/poolmanager/create_pool.go +++ b/x/poolmanager/create_pool.go @@ -123,7 +123,7 @@ func (k Keeper) SetPoolRoute(ctx sdk.Context, poolId uint64, poolType types.Pool // in poolmanager's keeper constructor. // TODO: unexport after concentrated-liqudity upgrade. Currently, it is exported // for the upgrade handler logic and tests. -func (k Keeper) GetPoolModule(ctx sdk.Context, poolId uint64) (types.SwapI, error) { +func (k Keeper) GetPoolModule(ctx sdk.Context, poolId uint64) (types.PoolModuleI, error) { store := ctx.KVStore(k.storeKey) moduleRoute := &types.ModuleRoute{} diff --git a/x/poolmanager/export_test.go b/x/poolmanager/export_test.go index 3f2504742fc..7ad2c4d1d22 100644 --- a/x/poolmanager/export_test.go +++ b/x/poolmanager/export_test.go @@ -20,10 +20,17 @@ func (k Keeper) GetOsmoRoutedMultihopTotalSwapFee(ctx sdk.Context, route types.M // For example, balancer -> gamm. // This utility function is only exposed for testing and should not be moved // outside of the _test.go files. -func (k *Keeper) SetPoolRoutesUnsafe(routes map[types.PoolType]types.SwapI) { +func (k *Keeper) SetPoolRoutesUnsafe(routes map[types.PoolType]types.PoolModuleI) { k.routes = routes } +// SetPoolModulesUnsafe sets the given modules to the poolmanager keeper. +// This utility function is only exposed for testing and should not be moved +// outside of the _test.go files. +func (k *Keeper) SetPoolModulesUnsafe(poolModules []types.PoolModuleI) { + k.poolModules = poolModules +} + func (k Keeper) GetAllPoolRoutes(ctx sdk.Context) []types.ModuleRoute { return k.getAllPoolRoutes(ctx) } diff --git a/x/poolmanager/keeper.go b/x/poolmanager/keeper.go index 5fdae8f34e4..24906c39d8a 100644 --- a/x/poolmanager/keeper.go +++ b/x/poolmanager/keeper.go @@ -13,8 +13,8 @@ import ( type Keeper struct { storeKey sdk.StoreKey - gammKeeper types.SwapI - concentratedKeeper types.SwapI + gammKeeper types.PoolModuleI + concentratedKeeper types.PoolModuleI poolIncentivesKeeper types.PoolIncentivesKeeperI bankKeeper types.BankI accountKeeper types.AccountI @@ -22,24 +22,45 @@ type Keeper struct { poolCreationListeners types.PoolCreationListeners - routes map[types.PoolType]types.SwapI + // routes is a map to get the pool module by id. + routes map[types.PoolType]types.PoolModuleI + + // poolModules is a list of all pool modules. + // It is used when an operation has to be applied to all pool + // modules. Since map iterations are non-deterministic, we + // use this list to ensure deterministic iteration. + poolModules []types.PoolModuleI paramSpace paramtypes.Subspace } -func NewKeeper(storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, gammKeeper types.SwapI, concentratedKeeper types.SwapI, bankKeeper types.BankI, accountKeeper types.AccountI, communityPoolKeeper types.CommunityPoolI) *Keeper { +func NewKeeper(storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, gammKeeper types.PoolModuleI, concentratedKeeper types.PoolModuleI, bankKeeper types.BankI, accountKeeper types.AccountI, communityPoolKeeper types.CommunityPoolI) *Keeper { // set KeyTable if it has not already been set if !paramSpace.HasKeyTable() { paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) } - routes := map[types.PoolType]types.SwapI{ + routesMap := map[types.PoolType]types.PoolModuleI{ types.Balancer: gammKeeper, types.Stableswap: gammKeeper, types.Concentrated: concentratedKeeper, } - return &Keeper{storeKey: storeKey, paramSpace: paramSpace, gammKeeper: gammKeeper, concentratedKeeper: concentratedKeeper, bankKeeper: bankKeeper, accountKeeper: accountKeeper, communityPoolKeeper: communityPoolKeeper, routes: routes} + routesList := []types.PoolModuleI{ + gammKeeper, concentratedKeeper, + } + + return &Keeper{ + storeKey: storeKey, + paramSpace: paramSpace, + gammKeeper: gammKeeper, + concentratedKeeper: concentratedKeeper, + bankKeeper: bankKeeper, + accountKeeper: accountKeeper, + communityPoolKeeper: communityPoolKeeper, + routes: routesMap, + poolModules: routesList, + } } // GetParams returns the total set of poolmanager parameters. diff --git a/x/poolmanager/module/module.go b/x/poolmanager/module/module.go index e24d5372fcd..d4c53d89f87 100644 --- a/x/poolmanager/module/module.go +++ b/x/poolmanager/module/module.go @@ -79,7 +79,7 @@ type AppModule struct { AppModuleBasic k poolmanager.Keeper - gammKeeper types.SwapI + gammKeeper types.PoolModuleI } func (am AppModule) RegisterServices(cfg module.Configurator) { @@ -87,7 +87,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { queryproto.RegisterQueryServer(cfg.QueryServer(), grpc.Querier{Q: pmclient.NewQuerier(am.k)}) } -func NewAppModule(poolmanagerKeeper poolmanager.Keeper, gammKeeper types.SwapI) AppModule { +func NewAppModule(poolmanagerKeeper poolmanager.Keeper, gammKeeper types.PoolModuleI) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, k: poolmanagerKeeper, diff --git a/x/poolmanager/router.go b/x/poolmanager/router.go index 8751ca027da..a5fad247201 100644 --- a/x/poolmanager/router.go +++ b/x/poolmanager/router.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/osmosis-labs/osmosis/osmoutils" appparams "github.com/osmosis-labs/osmosis/v15/app/params" "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types" ) @@ -400,6 +401,31 @@ func (k Keeper) RoutePool( return swapModule.GetPool(ctx, poolId) } +// AllPools returns all pools sorted by their ids +// from every pool module registered in the +// pool manager keeper. +func (k Keeper) AllPools( + ctx sdk.Context, +) ([]types.PoolI, error) { + less := func(i, j types.PoolI) bool { + return i.GetId() < j.GetId() + } + + // Allocate the slice with the exact capacity to avoid reallocations. + poolCount := k.GetNextPoolId(ctx) + sortedPools := make([]types.PoolI, 0, poolCount) + for _, poolModule := range k.poolModules { + currentModulePools, err := poolModule.GetPools(ctx) + if err != nil { + return nil, err + } + + sortedPools = osmoutils.MergeSlices(sortedPools, currentModulePools, less) + } + + return sortedPools, nil +} + func (k Keeper) isOsmoRoutedMultihop(ctx sdk.Context, route types.MultihopRoute, inDenom, outDenom string) (isRouted bool) { if route.Length() != 2 { return false diff --git a/x/poolmanager/router_test.go b/x/poolmanager/router_test.go index 0972a801943..62b3f427606 100644 --- a/x/poolmanager/router_test.go +++ b/x/poolmanager/router_test.go @@ -1,11 +1,14 @@ package poolmanager_test import ( + "errors" "reflect" "time" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/golang/mock/gomock" + "github.com/osmosis-labs/osmosis/v15/tests/mocks" cl "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity" cltypes "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types" gamm "github.com/osmosis-labs/osmosis/v15/x/gamm/keeper" @@ -37,7 +40,7 @@ func (suite *KeeperTestSuite) TestGetPoolModule() { tests := map[string]struct { poolId uint64 preCreatePoolType types.PoolType - routesOverwrite map[types.PoolType]types.SwapI + routesOverwrite map[types.PoolType]types.PoolModuleI expectedModule reflect.Type expectError error @@ -62,7 +65,7 @@ func (suite *KeeperTestSuite) TestGetPoolModule() { "undefined route": { preCreatePoolType: types.Balancer, poolId: 1, - routesOverwrite: map[types.PoolType]types.SwapI{ + routesOverwrite: map[types.PoolType]types.PoolModuleI{ types.Stableswap: &gamm.Keeper{}, // undefined for balancer. }, @@ -104,7 +107,7 @@ func (suite *KeeperTestSuite) TestRouteGetPoolDenoms() { tests := map[string]struct { poolId uint64 preCreatePoolType types.PoolType - routesOverwrite map[types.PoolType]types.SwapI + routesOverwrite map[types.PoolType]types.PoolModuleI expectedDenoms []string expectError error @@ -134,7 +137,7 @@ func (suite *KeeperTestSuite) TestRouteGetPoolDenoms() { "undefined route": { preCreatePoolType: types.Balancer, poolId: 1, - routesOverwrite: map[types.PoolType]types.SwapI{ + routesOverwrite: map[types.PoolType]types.PoolModuleI{ types.Stableswap: &gamm.Keeper{}, // undefined for balancer. }, @@ -174,7 +177,7 @@ func (suite *KeeperTestSuite) TestRouteCalculateSpotPrice() { baseAssetDenom string setPositionForCLPool bool - routesOverwrite map[types.PoolType]types.SwapI + routesOverwrite map[types.PoolType]types.PoolModuleI expectedSpotPrice sdk.Dec expectError error @@ -222,7 +225,7 @@ func (suite *KeeperTestSuite) TestRouteCalculateSpotPrice() { "undefined route": { preCreatePoolType: types.Balancer, poolId: 1, - routesOverwrite: map[types.PoolType]types.SwapI{ + routesOverwrite: map[types.PoolType]types.PoolModuleI{ types.Stableswap: &gamm.Keeper{}, // undefined for balancer. }, @@ -1296,6 +1299,202 @@ func (suite *KeeperTestSuite) TestSingleSwapExactAmountIn() { } } +type MockPoolModule struct { + pools []types.PoolI +} + +func (m *MockPoolModule) GetPools(ctx sdk.Context) ([]types.PoolI, error) { + return m.pools, nil +} + +// This test suite contains test cases for the AllPools function, which returns a sorted list of all pools from different pool modules. +// The test cases cover various scenarios, including no pool modules, single pool modules, multiple pool modules with varying numbers of pools, +// and overlapping and duplicate pool ids. The expected results and potential errors are defined for each test case. +// The test suite sets up mock pool modules and configures their behavior for the GetPools method, injecting them into the pool manager for testing. +// The actual results of the AllPools function are then compared to the expected results, ensuring the function behaves as intended in each scenario. +// Note that in this test we only test with Balancer Pools, as we're focusing on testing via different modules +func (suite *KeeperTestSuite) TestAllPools() { + suite.Setup() + + mockError := errors.New("mock error") + + testCases := []struct { + name string + // the return values of each pool module + // from the call to GetPools() + poolModuleIds [][]uint64 + expectedResult []types.PoolI + expectedError bool + }{ + { + name: "No pool modules", + poolModuleIds: [][]uint64{}, + expectedResult: []types.PoolI{}, + }, + { + name: "Single pool module", + poolModuleIds: [][]uint64{ + {1}, + }, + expectedResult: []types.PoolI{ + &balancer.Pool{Id: 1}, + }, + }, + { + name: "Two pools per module", + poolModuleIds: [][]uint64{ + {1, 2}, + }, + expectedResult: []types.PoolI{ + &balancer.Pool{Id: 1}, &balancer.Pool{Id: 2}, + }, + }, + { + name: "Two pools per module, second module with no pools", + poolModuleIds: [][]uint64{ + {1, 2}, + {}, + }, + expectedResult: []types.PoolI{ + &balancer.Pool{Id: 1}, &balancer.Pool{Id: 2}, + }, + }, + { + name: "Two pools per module, first module with no pools", + poolModuleIds: [][]uint64{ + {}, + {1, 2}, + }, + expectedResult: []types.PoolI{ + &balancer.Pool{Id: 1}, &balancer.Pool{Id: 2}, + }, + }, + { + // This should never happen but added for coverage. + name: "Two pools per module with repeating ids", + poolModuleIds: [][]uint64{ + {3, 3}, + }, + expectedResult: []types.PoolI{ + &balancer.Pool{Id: 3}, &balancer.Pool{Id: 3}, + }, + }, + { + name: "Module with two pools, module with one pool", + poolModuleIds: [][]uint64{ + {1, 2}, + {4}, + }, + expectedResult: []types.PoolI{ + &balancer.Pool{Id: 1}, &balancer.Pool{Id: 2}, &balancer.Pool{Id: 4}, + }, + }, + { + name: "Several modules with overlapping and duplicate pool ids", + poolModuleIds: [][]uint64{ + {1, 32, 77, 1203}, + {1, 4}, + {}, + {4, 88}, + }, + expectedResult: []types.PoolI{ + &balancer.Pool{Id: 1}, + &balancer.Pool{Id: 1}, + &balancer.Pool{Id: 4}, + &balancer.Pool{Id: 4}, + &balancer.Pool{Id: 32}, + &balancer.Pool{Id: 77}, + &balancer.Pool{Id: 88}, + &balancer.Pool{Id: 1203}, + }, + }, + { + name: "Error case", + poolModuleIds: [][]uint64{ + {1}, + }, + expectedError: true, + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + ctrl := gomock.NewController(suite.T()) + defer ctrl.Finish() + + ctx := suite.Ctx + poolManagerKeeper := suite.App.PoolManagerKeeper + + // Configure pool module mocks and inject them into pool manager + // for testing. + poolModules := make([]types.PoolModuleI, len(tc.poolModuleIds)) + if tc.expectedError { + // Configure error case. + mockPoolModule := mocks.NewMockPoolModuleI(ctrl) + mockPoolModule.EXPECT().GetPools(ctx).Return(nil, mockError) + poolModules[0] = mockPoolModule + } else { + // Configure success case. + for i := range tc.poolModuleIds { + mockPoolModule := mocks.NewMockPoolModuleI(ctrl) + poolModules[i] = mockPoolModule + + expectedPools := make([]types.PoolI, len(tc.poolModuleIds[i])) + for j := range tc.poolModuleIds[i] { + expectedPools[j] = &balancer.Pool{Id: tc.poolModuleIds[i][j]} + } + + // Set up the expected behavior for the GetPools method + mockPoolModule.EXPECT().GetPools(ctx).Return(expectedPools, nil) + } + } + poolManagerKeeper.SetPoolModulesUnsafe(poolModules) + + // Call the AllPools function and check if the result matches the expected pools + actualResult, err := poolManagerKeeper.AllPools(ctx) + + if tc.expectedError { + suite.Require().Error(err) + return + } + + suite.Require().NoError(err) + suite.Require().Equal(tc.expectedResult, actualResult) + }) + } +} + +// TestAllPools_RealPools tests the AllPools function with real pools. +func (suite *KeeperTestSuite) TestAllPools_RealPools() { + suite.Setup() + + poolManagerKeeper := suite.App.PoolManagerKeeper + + expectedResult := []types.PoolI{} + + // Prepare CL pool. + clPool := suite.PrepareConcentratedPool() + expectedResult = append(expectedResult, clPool) + + // Prepare balancer pool + balancerId := suite.PrepareBalancerPool() + balancerPool, err := suite.App.GAMMKeeper.GetPool(suite.Ctx, balancerId) + suite.Require().NoError(err) + expectedResult = append(expectedResult, balancerPool) + + // Prepare stableswap pool + stableswapId := suite.PrepareBasicStableswapPool() + stableswapPool, err := suite.App.GAMMKeeper.GetPool(suite.Ctx, stableswapId) + suite.Require().NoError(err) + expectedResult = append(expectedResult, stableswapPool) + + // Call the AllPools function and check if the result matches the expected pools + actualResult, err := poolManagerKeeper.AllPools(suite.Ctx) + suite.Require().NoError(err) + + suite.Require().Equal(expectedResult, actualResult) +} + // setupPools creates pools of desired type and returns their IDs func (suite *KeeperTestSuite) setupPools(poolType types.PoolType, poolDefaultSwapFee sdk.Dec) (firstEstimatePoolId, secondEstimatePoolId uint64) { switch poolType { diff --git a/x/poolmanager/types/routes.go b/x/poolmanager/types/routes.go index 7c542c81425..663f6385c7f 100644 --- a/x/poolmanager/types/routes.go +++ b/x/poolmanager/types/routes.go @@ -27,12 +27,15 @@ type CommunityPoolI interface { FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error } -// TODO: godoc -type SwapI interface { +// PoolModuleI is the interface that must be fulfillled by the module +// storing and containing the pools. +type PoolModuleI interface { InitializePool(ctx sdk.Context, pool PoolI, creatorAddress sdk.AccAddress) error GetPool(ctx sdk.Context, poolId uint64) (PoolI, error) + GetPools(ctx sdk.Context) ([]PoolI, error) + GetPoolDenoms(ctx sdk.Context, poolId uint64) (denoms []string, err error) CalculateSpotPrice( ctx sdk.Context,