Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Support HTTP requests for FilteredPools #3737

Merged
merged 4 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ which acts as a fuzz testing tool tailored for the SDK state machine.
* [#2473](https://github.com/osmosis-labs/osmosis/pull/2473) x/superfluid `AddNewSuperfluidAsset` now returns error, if any occurs instead of ignoring it.
* [#2714](https://github.com/osmosis-labs/osmosis/pull/2714) Upgrade wasmd to v0.28.0.
* Remove x/Bech32IBC
* [#3737](https://github.com/osmosis-labs/osmosis/pull/3737) Change FilteredPools MinLiquidity field from sdk.Coins struct to string.


#### Golang API breaks

Expand Down
8 changes: 3 additions & 5 deletions proto/osmosis/gamm/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,9 @@ message QuerySpotPriceRequest {
//=============================== PoolsWithFilter

message QueryPoolsWithFilterRequest {
repeated cosmos.base.v1beta1.Coin min_liquidity = 1 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "yaml:\"min_liquidity\"",
(gogoproto.nullable) = false
];
// String of the coins in single string seperated by comma. Ex)
// 10uatom,100uosmo
string min_liquidity = 1 [ (gogoproto.moretags) = "yaml:\"min_liquidity\"" ];
string pool_type = 2;
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}
Expand Down
20 changes: 2 additions & 18 deletions x/gamm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import (
"strings"

"github.com/gogo/protobuf/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -286,24 +283,11 @@ $ %s query gamm pools-with-filter <min_liquidity> <pool_type>
}
queryClient := types.NewQueryClient(clientCtx)

var min_liquidity sdk.Coins
var pool_type string
if len(args) == 1 {
coins, err := sdk.ParseCoinsNormalized(args[0])
if err != nil {
pool_type = args[0]
}
min_liquidity = coins
} else {
coins, err := sdk.ParseCoinsNormalized(args[0])
if err != nil {
return status.Errorf(codes.InvalidArgument, "invalid token: %s", err.Error())
}

min_liquidity = coins
min_liquidity := args[0]
if len(args) > 1 {
pool_type = args[1]
}

res, err := queryClient.PoolsWithFilter(cmd.Context(), &types.QueryPoolsWithFilterRequest{
MinLiquidity: min_liquidity,
PoolType: pool_type,
Expand Down
8 changes: 6 additions & 2 deletions x/gamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ func (q Querier) PoolsWithFilter(ctx context.Context, req *types.QueryPoolsWithF
sdkCtx := sdk.UnwrapSDKContext(ctx)
store := sdkCtx.KVStore(q.Keeper.storeKey)
poolStore := prefix.NewStore(store, types.KeyPrefixPools)
minLiquidity, err := sdk.ParseCoinsNormalized(req.MinLiquidity)
if err != nil {
return nil, err
}

var response = []*codectypes.Any{}
pageRes, err := query.FilteredPaginate(poolStore, req.Pagination, func(_, value []byte, accumulate bool) (bool, error) {
Expand All @@ -178,10 +182,10 @@ func (q Querier) PoolsWithFilter(ctx context.Context, req *types.QueryPoolsWithF
poolId := pool.GetId()

// if liquidity specified in request
if len(req.MinLiquidity) > 0 {
if len(minLiquidity) > 0 {
poolLiquidity := pool.GetTotalPoolLiquidity(sdkCtx)

if !poolLiquidity.IsAllGTE(req.MinLiquidity) {
if !poolLiquidity.IsAllGTE(minLiquidity) {
return false, nil
}
}
Expand Down
54 changes: 36 additions & 18 deletions x/gamm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,16 @@ func (suite *KeeperTestSuite) TestPoolsWithFilter() {
name string
num_pools int
expected_num_pools_response int
min_liquidity sdk.Coins
min_liquidity string
pool_type string
poolAssets []balancertypes.PoolAsset
expectedErr error
expectedErr bool
}{
{
name: "valid tc with both filters for min liquidity and pool type",
num_pools: 1,
expected_num_pools_response: 1,
min_liquidity: sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(50000)), sdk.NewCoin("bar", sdk.NewInt(50000))),
min_liquidity: "50000foo, 50000bar",
pool_type: "Balancer",
poolAssets: []balancertypes.PoolAsset{
{
Expand All @@ -207,13 +207,13 @@ func (suite *KeeperTestSuite) TestPoolsWithFilter() {
Token: sdk.NewCoin("bar", sdk.NewInt(5000000)),
},
},
expectedErr: nil,
expectedErr: false,
},
{
name: "only min liquidity specified (too high for pools - return 0 pools)",
num_pools: 1,
expected_num_pools_response: 0,
min_liquidity: sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(500000000)), sdk.NewCoin("bar", sdk.NewInt(500000000))),
min_liquidity: "500000000foo, 500000000bar",
poolAssets: []balancertypes.PoolAsset{
{
Weight: sdk.NewInt(100),
Expand All @@ -224,13 +224,13 @@ func (suite *KeeperTestSuite) TestPoolsWithFilter() {
Token: sdk.NewCoin("bar", sdk.NewInt(5000000)),
},
},
expectedErr: nil,
expectedErr: false,
},
{
name: "wrong pool type specified",
num_pools: 1,
expected_num_pools_response: 0,
min_liquidity: nil,
min_liquidity: "",
pool_type: "balaswap",
poolAssets: []balancertypes.PoolAsset{
{
Expand All @@ -242,13 +242,13 @@ func (suite *KeeperTestSuite) TestPoolsWithFilter() {
Token: sdk.NewCoin("bar", sdk.NewInt(5000000)),
},
},
expectedErr: nil,
expectedErr: false,
},
{
name: "2 parameters specified + single-token min liquidity",
num_pools: 1,
expected_num_pools_response: 4,
min_liquidity: sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(500))),
min_liquidity: "500foo",
pool_type: "Balancer",
poolAssets: []balancertypes.PoolAsset{
{
Expand All @@ -260,13 +260,13 @@ func (suite *KeeperTestSuite) TestPoolsWithFilter() {
Token: sdk.NewCoin("bar", sdk.NewInt(5000000)),
},
},
expectedErr: nil,
expectedErr: false,
},
{
name: "min_liquidity denom not present in pool",
num_pools: 1,
expected_num_pools_response: 0,
min_liquidity: sdk.NewCoins(sdk.NewCoin("whoami", sdk.NewInt(500))),
min_liquidity: "500whoami",
poolAssets: []balancertypes.PoolAsset{
{
Weight: sdk.NewInt(100),
Expand All @@ -277,13 +277,13 @@ func (suite *KeeperTestSuite) TestPoolsWithFilter() {
Token: sdk.NewCoin("bar", sdk.NewInt(5000000)),
},
},
expectedErr: nil,
expectedErr: false,
},
{
name: "only min liquidity specified - valid",
num_pools: 1,
expected_num_pools_response: 6,
min_liquidity: sdk.NewCoins(sdk.NewCoin("foo", sdk.ZeroInt()), sdk.NewCoin("bar", sdk.ZeroInt())),
min_liquidity: "0foo,0bar",
poolAssets: []balancertypes.PoolAsset{
{
Weight: sdk.NewInt(100),
Expand All @@ -294,7 +294,7 @@ func (suite *KeeperTestSuite) TestPoolsWithFilter() {
Token: sdk.NewCoin("bar", sdk.NewInt(5000000)),
},
},
expectedErr: nil,
expectedErr: false,
},
{
name: "only valid pool type specified",
Expand All @@ -311,7 +311,25 @@ func (suite *KeeperTestSuite) TestPoolsWithFilter() {
Token: sdk.NewCoin("bar", sdk.NewInt(5000000)),
},
},
expectedErr: nil,
expectedErr: false,
},
{
name: "invalid min liquidity specified",
num_pools: 1,
expected_num_pools_response: 1,
min_liquidity: "wrong300foo",
pool_type: "Balancer",
poolAssets: []balancertypes.PoolAsset{
{
Weight: sdk.NewInt(100),
Token: sdk.NewCoin("foo", sdk.NewInt(5000000)),
},
{
Weight: sdk.NewInt(200),
Token: sdk.NewCoin("bar", sdk.NewInt(5000000)),
},
},
expectedErr: true,
},
}
for _, tc := range testCases {
Expand All @@ -327,11 +345,11 @@ func (suite *KeeperTestSuite) TestPoolsWithFilter() {
MinLiquidity: tc.min_liquidity,
PoolType: tc.pool_type,
})
if tc.expectedErr == nil {
if tc.expectedErr {
suite.Require().Error(err)
} else {
suite.Require().NoError(err)
suite.Require().Equal(tc.expected_num_pools_response, len(res.Pools))
} else {
suite.Require().ErrorIs(err, tc.expectedErr)
}
})
}
Expand Down
Loading