Skip to content

Commit

Permalink
Add Query pools by coin denom (#6766)
Browse files Browse the repository at this point in the history
* Add Cli query pools by denom

* revert

* minor

* minor

* Update x/poolmanager/client/query_proto_wrap.go

Co-authored-by: Ruslan Akhtariev <[email protected]>

* Update x/poolmanager/client/query_proto_wrap.go

Co-authored-by: Ruslan Akhtariev <[email protected]>

* Update x/poolmanager/router.go

Co-authored-by: Ruslan Akhtariev <[email protected]>

* Update proto/osmosis/poolmanager/v1beta1/query.proto

Co-authored-by: Matt, Park <[email protected]>

* Update x/poolmanager/router.go

Co-authored-by: Matt, Park <[email protected]>

* Update proto/osmosis/poolmanager/v1beta1/query.proto

Co-authored-by: Matt, Park <[email protected]>

* Update x/poolmanager/router.go

Co-authored-by: Matt, Park <[email protected]>

* Update x/poolmanager/router.go

Co-authored-by: Matt, Park <[email protected]>

* minor and lint

* Use dynamic slice instead of Allocate the slice

* changelog

* make proto-gen

* lint proto

* add test

* Update x/poolmanager/router_test.go

Co-authored-by: Matt, Park <[email protected]>

* Update x/poolmanager/router_test.go

Co-authored-by: Matt, Park <[email protected]>

* make proto-all

* use a few poolType Concentrated

---------

Co-authored-by: Ruslan Akhtariev <[email protected]>
Co-authored-by: Matt, Park <[email protected]>
Co-authored-by: Hieu Vu <[email protected]>
  • Loading branch information
4 people authored Nov 15, 2023
1 parent 00c6d22 commit 6e876a6
Show file tree
Hide file tree
Showing 10 changed files with 789 additions and 136 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

* [#6766](https://github.com/osmosis-labs/osmosis/pull/6766) CLI: Query pool by coin denom
* [#6468](https://github.com/osmosis-labs/osmosis/pull/6468) feat: remove osmo multihop discount
* [#6420](https://github.com/osmosis-labs/osmosis/pull/6420) feat[CL]: Creates a governance set whitelist of addresses that can bypass the normal pool creation restrictions on concentrated liquidity pools
* [#6623](https://github.com/osmosis-labs/osmosis/pull/6420) feat: transfer cl positions to new owner
Expand Down
17 changes: 17 additions & 0 deletions proto/osmosis/poolmanager/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ service Query {
rpc AllPools(AllPoolsRequest) returns (AllPoolsResponse) {
option (google.api.http).get = "/osmosis/poolmanager/v1beta1/all-pools";
}
// ListPoolsByDenom return all pools by denom
rpc ListPoolsByDenom(ListPoolsByDenomRequest)
returns (ListPoolsByDenomResponse) {
option (google.api.http).get =
"/osmosis/poolmanager/v1beta1/list-pools-by-denom";
}

// SpotPrice defines a gRPC query handler that returns the spot price given
// a base denomination and a quote denomination.
Expand Down Expand Up @@ -238,6 +244,17 @@ message AllPoolsResponse {
[ (cosmos_proto.accepts_interface) = "PoolI" ];
}

// =======================================================
// ListPoolsByDenomRequest
message ListPoolsByDenomRequest {
string denom = 1 [ (gogoproto.moretags) = "yaml:\"denom\"" ];
}

message ListPoolsByDenomResponse {
repeated google.protobuf.Any pools = 1
[ (cosmos_proto.accepts_interface) = "PoolI" ];
}
// ==========================================================
// SpotPriceRequest defines the gRPC request structure for a SpotPrice
// query.
message SpotPriceRequest {
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup_superfluid.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ sleep 7
osmosisd tx gov vote 1 yes --from=validator1 --keyring-backend=test --chain-id=testing --yes --home=$HOME/.osmosisd/validator1
sleep 7
osmosisd tx gov vote 1 yes --from=validator2 --keyring-backend=test --chain-id=testing --yes --home=$HOME/.osmosisd/validator2
sleep 7
sleep 7
10 changes: 10 additions & 0 deletions x/poolmanager/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func GetQueryCmd() *cobra.Command {
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdTotalVolumeForPool)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdTradingPairTakerFee)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdEstimateTradeBasedOnPriceImpact)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdListPoolsByDenom)
cmd.AddCommand(
osmocli.GetParams[*queryproto.ParamsRequest](
types.ModuleName, queryproto.NewQueryClient),
Expand Down Expand Up @@ -105,6 +106,15 @@ func GetCmdSpotPrice() (*osmocli.QueryDescriptor, *queryproto.SpotPriceRequest)
`,
}, &queryproto.SpotPriceRequest{}
}
func GetCmdListPoolsByDenom() (*osmocli.QueryDescriptor, *queryproto.ListPoolsByDenomRequest) {
return &osmocli.QueryDescriptor{
Use: "list-pools-by-denom",
Short: "Query list-pools-by-denom",
Long: `Query list-pools-by-denom
{{.CommandPrefix}} list-pools-by-denom uosmo
`,
}, &queryproto.ListPoolsByDenomRequest{}
}

func EstimateSwapExactAmountInParseArgs(args []string, fs *flag.FlagSet) (proto.Message, error) {
poolID, err := strconv.Atoi(args[0])
Expand Down
10 changes: 10 additions & 0 deletions x/poolmanager/client/grpc/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ func (q Querier) SpotPrice(grpcCtx context.Context,
return q.Q.SpotPrice(ctx, *req)
}

func (q Querier) ListPoolsByDenom(grpcCtx context.Context,
req *queryproto.ListPoolsByDenomRequest,
) (*queryproto.ListPoolsByDenomResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(grpcCtx)
return q.Q.ListPoolsByDenom(ctx, *req)
}

func (q Querier) Pool(grpcCtx context.Context,
req *queryproto.PoolRequest,
) (*queryproto.PoolResponse, error) {
Expand Down
24 changes: 24 additions & 0 deletions x/poolmanager/client/query_proto_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,30 @@ func (q Querier) AllPools(ctx sdk.Context, req queryproto.AllPoolsRequest) (*que
}, nil
}

// ListPoolsByDenom returns a list of pools filtered by denom
func (q Querier) ListPoolsByDenom(ctx sdk.Context, req queryproto.ListPoolsByDenomRequest) (*queryproto.ListPoolsByDenomResponse, error) {
if req.Denom == "" {
return nil, status.Error(codes.InvalidArgument, "invalid denom")
}
pools, err := q.K.ListPoolsByDenom(ctx, req.Denom)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

var anyPools []*codectypes.Any
for _, pool := range pools {
any, err := codectypes.NewAnyWithValue(pool.AsSerializablePool())
if err != nil {
return nil, err
}
anyPools = append(anyPools, any)
}

return &queryproto.ListPoolsByDenomResponse{
Pools: anyPools,
}, nil
}

// SpotPrice returns the spot price of the pool with the given quote and base asset denoms. 18 decimals.
func (q Querier) SpotPrice(ctx sdk.Context, req queryproto.SpotPriceRequest) (*queryproto.SpotPriceResponse, error) {
if req.BaseAssetDenom == "" {
Expand Down
Loading

0 comments on commit 6e876a6

Please sign in to comment.