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

CLI: Query pools by coin denom #6766

Merged
merged 31 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
eb4cebc
Add Cli query pools by denom
DongLieu Oct 24, 2023
a9df2c7
revert
DongLieu Oct 26, 2023
fc7cd18
minor
DongLieu Oct 26, 2023
a7601dc
Merge branch 'main' into dong/list-pools-by-denom
DongLieu Oct 26, 2023
59b9dfd
minor
DongLieu Oct 26, 2023
60cda3a
Update x/poolmanager/client/query_proto_wrap.go
DongLieu Oct 27, 2023
767245f
Update x/poolmanager/client/query_proto_wrap.go
DongLieu Oct 27, 2023
c7e97b4
Update x/poolmanager/router.go
DongLieu Oct 27, 2023
b6a1548
Update proto/osmosis/poolmanager/v1beta1/query.proto
DongLieu Oct 27, 2023
db8ab86
Update x/poolmanager/router.go
DongLieu Oct 27, 2023
a676097
Update proto/osmosis/poolmanager/v1beta1/query.proto
DongLieu Oct 27, 2023
d27e288
Update x/poolmanager/router.go
DongLieu Oct 27, 2023
ebda3b4
Update x/poolmanager/router.go
DongLieu Oct 27, 2023
49dcac4
minor and lint
DongLieu Oct 27, 2023
0f5179c
Use dynamic slice instead of Allocate the slice
DongLieu Oct 27, 2023
7c4a114
changelog
DongLieu Oct 27, 2023
bd8b379
make proto-gen
DongLieu Oct 27, 2023
0f53613
Merge branch 'main' into dong/list-pools-by-denom
DongLieu Nov 1, 2023
f8e710a
Merge branch 'main' into dong/list-pools-by-denom
DongLieu Nov 1, 2023
e22a244
lint proto
hieuvubk Nov 2, 2023
045fcac
Merge branch 'main' into dong/list-pools-by-denom
DongLieu Nov 2, 2023
3903673
Merge branch 'main' into dong/list-pools-by-denom
DongLieu Nov 5, 2023
182a261
add test
DongLieu Nov 5, 2023
18022fd
Update x/poolmanager/router_test.go
DongLieu Nov 7, 2023
dbaee05
Update x/poolmanager/router_test.go
DongLieu Nov 7, 2023
d8837d3
merge main and fix config
DongLieu Nov 7, 2023
51d4e04
make proto-all
DongLieu Nov 7, 2023
cdccac1
use a few poolType Concentrated
DongLieu Nov 7, 2023
b839255
Merge branch 'main' into dong/list-pools-by-denom
DongLieu Nov 8, 2023
42e668b
Merge branch 'main' into dong/list-pools-by-denom
DongLieu Nov 12, 2023
7fc45e0
Merge branch 'main' into dong/list-pools-by-denom
DongLieu Nov 15, 2023
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
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,10 @@ service Query {
rpc AllPools(AllPoolsRequest) returns (AllPoolsResponse) {
option (google.api.http).get = "/osmosis/poolmanager/v1beta1/all-pools";
}
// ListPoolsByDenom return all pools by denom on the Osmosis chain.
DongLieu marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -234,6 +238,19 @@ message AllPoolsResponse {
[ (cosmos_proto.accepts_interface) = "PoolI" ];
}

// =======================================================
// ListPoolsByDenomRequest
message ListPoolsByDenomRequest {
string denom = 1
[ (gogoproto.moretags) = "yaml:\"base_asset_denom\"" ];
DongLieu marked this conversation as resolved.
Show resolved Hide resolved
}


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 @@ -214,6 +214,30 @@ func (q Querier) AllPools(ctx sdk.Context, req queryproto.AllPoolsRequest) (*que
}, nil
}

// ListPoolsByDenom return list pools by denom
DongLieu marked this conversation as resolved.
Show resolved Hide resolved
func (q Querier) ListPoolsByDenom(ctx sdk.Context, req queryproto.ListPoolsByDenomRequest) (*queryproto.ListPoolsByDenomResponse, error) {
if req.Denom == "" {
return nil, status.Error(codes.InvalidArgument, "invalid quote asset denom")
DongLieu marked this conversation as resolved.
Show resolved Hide resolved
}
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
638 changes: 515 additions & 123 deletions x/poolmanager/client/queryproto/query.pb.go

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions x/poolmanager/client/queryproto/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions x/poolmanager/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,43 @@ func (k Keeper) AllPools(
return sortedPools, nil
}

// ListPoolsByDenom returns all pools by denom sorted by their ids
// from every pool module registered in the
// pool manager keeper.
func (k Keeper) ListPoolsByDenom(
mattverse marked this conversation as resolved.
Show resolved Hide resolved
ctx sdk.Context,
Denom string,
DongLieu marked this conversation as resolved.
Show resolved Hide resolved
) ([]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.
DongLieu marked this conversation as resolved.
Show resolved Hide resolved
poolCount := k.GetNextPoolId(ctx)
sortedPools := make([]types.PoolI, 0, poolCount)
DongLieu marked this conversation as resolved.
Show resolved Hide resolved
DongLieu marked this conversation as resolved.
Show resolved Hide resolved
for _, poolModule := range k.poolModules {
currentModulePools, err := poolModule.GetPools(ctx)
if err != nil {
return nil, err
}

var poolsByDenom []types.PoolI
for _, pool := range currentModulePools {
coins, err := k.GetTotalPoolLiquidity(ctx, pool.GetId())
if err != nil {
return nil, err
}
if coins.AmountOf(Denom).GT(osmomath.ZeroInt()) {
if err != nil {
return nil, err
}
DongLieu marked this conversation as resolved.
Show resolved Hide resolved
DongLieu marked this conversation as resolved.
Show resolved Hide resolved
poolsByDenom = append(poolsByDenom, pool)
}
}
sortedPools = osmoutils.MergeSlices(sortedPools, poolsByDenom, less)
}
return sortedPools, nil
}

// createMultihopExpectedSwapOuts defines the output denom and output amount for the last pool in
// the routeStep of pools the caller is intending to hop through in a fixed-output multihop tx. It estimates the input
// amount for this last pool and then chains that input as the output of the previous pool in the routeStep, repeating
Expand Down