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

feat(CL): x/poolmanager spot price query for concentrated liquidity #4682

Merged
merged 8 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [#4336](https://github.com/osmosis-labs/osmosis/pull/4336) Move epochs module into its own go.mod
* [#4658](https://github.com/osmosis-labs/osmosis/pull/4658) Deprecate x/gamm Pool query. The new one is located in x/poolmanager.
* [#4682](https://github.com/osmosis-labs/osmosis/pull/4682) Deprecate x/gamm SpotPrice v2 query. The new one is located in x/poolmanager.

## v15.0.0

Expand Down
12 changes: 6 additions & 6 deletions proto/osmosis/gamm/v2/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ import "cosmos_proto/cosmos.proto";
option go_package = "github.com/osmosis-labs/osmosis/v15/x/gamm/v2types";

service Query {
// SpotPrice defines a gRPC query handler that returns the spot price given
// a base denomination and a quote denomination.
// Deprecated: please use alternate in x/poolmanager
rpc SpotPrice(QuerySpotPriceRequest) returns (QuerySpotPriceResponse) {
option deprecated = true;
option (google.api.http).get = "/osmosis/gamm/v2/pools/{pool_id}/prices";
}
}

// QuerySpotPriceRequest defines the gRPC request structure for a SpotPrice
// query.
// Deprecated: please use alternate in x/poolmanager
message QuerySpotPriceRequest {
option deprecated = true;
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
string base_asset_denom = 2
[ (gogoproto.moretags) = "yaml:\"base_asset_denom\"" ];
string quote_asset_denom = 3
[ (gogoproto.moretags) = "yaml:\"quote_asset_denom\"" ];
}

// QuerySpotPriceResponse defines the gRPC response structure for a SpotPrice
// query.
// Depreacted: please use alternate in x/poolmanager
message QuerySpotPriceResponse {
option deprecated = true;
// String of the Dec. Ex) 10.203uatom
string spot_price = 1 [ (gogoproto.moretags) = "yaml:\"spot_price\"" ];
}
24 changes: 24 additions & 0 deletions proto/osmosis/poolmanager/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ service Query {
option (google.api.http).get =
"/osmosis/poolmanager/v1beta1/pools/{pool_id}";
}

// SpotPrice defines a gRPC query handler that returns the spot price given
// a base denomination and a quote denomination.
rpc SpotPrice(SpotPriceRequest) returns (SpotPriceResponse) {
option (google.api.http).get =
"/osmosis/poolmanager/pools/{pool_id}/prices";
}
}

//=============================== Params
Expand Down Expand Up @@ -103,3 +110,20 @@ message PoolRequest {
message PoolResponse {
google.protobuf.Any pool = 1 [ (cosmos_proto.accepts_interface) = "PoolI" ];
}

// SpotPriceRequest defines the gRPC request structure for a SpotPrice
// query.
message SpotPriceRequest {
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
string base_asset_denom = 2
[ (gogoproto.moretags) = "yaml:\"base_asset_denom\"" ];
string quote_asset_denom = 3
[ (gogoproto.moretags) = "yaml:\"quote_asset_denom\"" ];
}

// SpotPriceResponse defines the gRPC response structure for a SpotPrice
// query.
message SpotPriceResponse {
// String of the Dec. Ex) 10.203uatom
string spot_price = 1 [ (gogoproto.moretags) = "yaml:\"spot_price\"" ];
}
5 changes: 5 additions & 0 deletions proto/osmosis/poolmanager/v1beta1/query.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ queries:
query_func: "k.Pool"
cli:
cmd: "Pool"
SpotPrice:
proto_wrapper:
query_func: "k.RouteCalculateSpotPrice"
cli:
cmd: "SpotPrice"
8 changes: 3 additions & 5 deletions x/gamm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Example:
)
}

//nolint:staticcheck
// Deprecated: use alternate in x/poolmanager.
func GetCmdSpotPrice() (*osmocli.QueryDescriptor, *types.QuerySpotPriceRequest) {
return &osmocli.QueryDescriptor{
Use: "spot-price <pool-ID> [quote-asset-denom] [base-asset-denom]",
Expand All @@ -204,8 +204,7 @@ func GetCmdSpotPrice() (*osmocli.QueryDescriptor, *types.QuerySpotPriceRequest)
`}, &types.QuerySpotPriceRequest{}
}

// GetCmdEstimateSwapExactAmountIn returns estimation of output coin when amount of x token input.
// nolint: staticcheck
// Deprecated: use alternate in x/poolmanager.
func GetCmdEstimateSwapExactAmountIn() (*osmocli.QueryDescriptor, *types.QuerySwapExactAmountInRequest) {
return &osmocli.QueryDescriptor{
Use: "estimate-swap-exact-amount-in <poolID> <sender> <tokenIn>",
Expand All @@ -219,8 +218,7 @@ func GetCmdEstimateSwapExactAmountIn() (*osmocli.QueryDescriptor, *types.QuerySw
}, &types.QuerySwapExactAmountInRequest{}
}

// GetCmdEstimateSwapExactAmountOut returns estimation of input coin to get exact amount of x token output.
// nolint: staticcheck
// Deprecated: use alternate in x/poolmanager.
func GetCmdEstimateSwapExactAmountOut() (*osmocli.QueryDescriptor, *types.QuerySwapExactAmountOutRequest) {
return &osmocli.QueryDescriptor{
Use: "estimate-swap-exact-amount-out <poolID> <sender> <tokenOut>",
Expand Down
4 changes: 4 additions & 0 deletions x/gamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ func (q Querier) SpotPrice(ctx context.Context, req *types.QuerySpotPriceRequest
}, nil
}

// Deeprecated: use alternate in x/poolmanager
// nolint: staticcheck
func (q QuerierV2) SpotPrice(ctx context.Context, req *v2types.QuerySpotPriceRequest) (*v2types.QuerySpotPriceResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
Expand All @@ -402,6 +404,8 @@ func (q QuerierV2) SpotPrice(ctx context.Context, req *v2types.QuerySpotPriceReq
return nil, status.Error(codes.Internal, err.Error())
}

// Deeprecated: use alternate in x/poolmanager
// nolint: staticcheck
return &v2types.QuerySpotPriceResponse{
SpotPrice: sp.String(),
}, nil
Expand Down
78 changes: 40 additions & 38 deletions x/gamm/v2types/query.pb.go

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

10 changes: 10 additions & 0 deletions x/poolmanager/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func GetQueryCmd() *cobra.Command {
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdNumPools)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdEstimateSwapExactAmountIn)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdEstimateSwapExactAmountOut)
osmocli.AddQueryCmd(cmd, queryproto.NewQueryClient, GetCmdSpotPrice)

return cmd
}
Expand Down Expand Up @@ -73,6 +74,15 @@ func GetCmdPool() (*osmocli.QueryDescriptor, *queryproto.PoolRequest) {
{{.CommandPrefix}} pool 1`}, &queryproto.PoolRequest{}
}

func GetCmdSpotPrice() (*osmocli.QueryDescriptor, *queryproto.SpotPriceRequest) {
return &osmocli.QueryDescriptor{
Use: "spot-price <pool-ID> [quote-asset-denom] [base-asset-denom]",
Short: "Query spot-price (LEGACY, arguments are reversed!!)",
p0mvn marked this conversation as resolved.
Show resolved Hide resolved
Long: `Query spot price (Legacy).{{.ExampleHeader}}
p0mvn marked this conversation as resolved.
Show resolved Hide resolved
{{.CommandPrefix}} spot-price 1 uosmo ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2
`}, &queryproto.SpotPriceRequest{}
}

func EstimateSwapExactAmountInParseArgs(args []string, fs *flag.FlagSet) (proto.Message, error) {
poolID, err := strconv.Atoi(args[0])
if err != nil {
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 @@ -20,6 +20,16 @@ type Querier struct {

var _ queryproto.QueryServer = Querier{}

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

func (q Querier) Pool(grpcCtx context.Context,
req *queryproto.PoolRequest,
) (*queryproto.PoolResponse, error) {
Expand Down
20 changes: 20 additions & 0 deletions x/poolmanager/client/query_proto_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,23 @@ func (q Querier) Pool(ctx sdk.Context, req queryproto.PoolRequest) (*queryproto.
Pool: any,
}, nil
}

// Spot price returns the spot price of the pool with the given quote and base asset denoms.
p0mvn marked this conversation as resolved.
Show resolved Hide resolved
func (q Querier) SpotPrice(ctx sdk.Context, req queryproto.SpotPriceRequest) (*queryproto.SpotPriceResponse, error) {
if req.BaseAssetDenom == "" {
return nil, status.Error(codes.InvalidArgument, "invalid base asset denom")
}

if req.QuoteAssetDenom == "" {
return nil, status.Error(codes.InvalidArgument, "invalid quote asset denom")
}

sp, err := q.K.RouteCalculateSpotPrice(ctx, req.PoolId, req.QuoteAssetDenom, req.BaseAssetDenom)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &queryproto.SpotPriceResponse{
SpotPrice: sp.String(),
}, nil
}
Loading