Skip to content

Commit

Permalink
refactor: rename SpotPrice gRPC proto fields (#1228)
Browse files Browse the repository at this point in the history
* updates

* updates

* updates
  • Loading branch information
alexanderbez authored Apr 8, 2022
1 parent 3c582ef commit 6594da2
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 242 deletions.
10 changes: 5 additions & 5 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1239,14 +1239,14 @@ TODO: Rename to MsgJoinSwapExactAmountIn
<a name="osmosis.gamm.v1beta1.QuerySpotPriceRequest"></a>

### QuerySpotPriceRequest
=============================== SpotPrice
QuerySpotPriceRequest defines the gRPC request structure for a SpotPrice query.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `poolId` | [uint64](#uint64) | | |
| `tokenInDenom` | [string](#string) | | |
| `tokenOutDenom` | [string](#string) | | |
| `base_asset_denom` | [string](#string) | | |
| `quote_asset_denom` | [string](#string) | | |



Expand All @@ -1256,7 +1256,7 @@ TODO: Rename to MsgJoinSwapExactAmountIn
<a name="osmosis.gamm.v1beta1.QuerySpotPriceResponse"></a>

### QuerySpotPriceResponse

QuerySpotPriceResponse defines the gRPC response structure for a SpotPrice query.


| Field | Type | Label | Description |
Expand Down Expand Up @@ -1439,7 +1439,7 @@ TODO: Rename to MsgJoinSwapExactAmountIn
| `PoolParams` | [QueryPoolParamsRequest](#osmosis.gamm.v1beta1.QueryPoolParamsRequest) | [QueryPoolParamsResponse](#osmosis.gamm.v1beta1.QueryPoolParamsResponse) | | GET|/osmosis/gamm/v1beta1/pools/{poolId}/params|
| `TotalPoolLiquidity` | [QueryTotalPoolLiquidityRequest](#osmosis.gamm.v1beta1.QueryTotalPoolLiquidityRequest) | [QueryTotalPoolLiquidityResponse](#osmosis.gamm.v1beta1.QueryTotalPoolLiquidityResponse) | | GET|/osmosis/gamm/v1beta1/pools/{poolId}/total_pool_liquidity|
| `TotalShares` | [QueryTotalSharesRequest](#osmosis.gamm.v1beta1.QueryTotalSharesRequest) | [QueryTotalSharesResponse](#osmosis.gamm.v1beta1.QueryTotalSharesResponse) | | GET|/osmosis/gamm/v1beta1/pools/{poolId}/total_shares|
| `SpotPrice` | [QuerySpotPriceRequest](#osmosis.gamm.v1beta1.QuerySpotPriceRequest) | [QuerySpotPriceResponse](#osmosis.gamm.v1beta1.QuerySpotPriceResponse) | | GET|/osmosis/gamm/v1beta1/pools/{poolId}/prices|
| `SpotPrice` | [QuerySpotPriceRequest](#osmosis.gamm.v1beta1.QuerySpotPriceRequest) | [QuerySpotPriceResponse](#osmosis.gamm.v1beta1.QuerySpotPriceResponse) | SpotPrice defines a gRPC query handler that returns the spot price given a base denomination and a quote denomination. | GET|/osmosis/gamm/v1beta1/pools/{poolId}/prices|
| `EstimateSwapExactAmountIn` | [QuerySwapExactAmountInRequest](#osmosis.gamm.v1beta1.QuerySwapExactAmountInRequest) | [QuerySwapExactAmountInResponse](#osmosis.gamm.v1beta1.QuerySwapExactAmountInResponse) | Estimate the swap. | GET|/osmosis/gamm/v1beta1/{poolId}/estimate/swap_exact_amount_in|
| `EstimateSwapExactAmountOut` | [QuerySwapExactAmountOutRequest](#osmosis.gamm.v1beta1.QuerySwapExactAmountOutRequest) | [QuerySwapExactAmountOutResponse](#osmosis.gamm.v1beta1.QuerySwapExactAmountOutResponse) | | GET|/osmosis/gamm/v1beta1/{poolId}/estimate/swap_exact_amount_out|

Expand Down
112 changes: 51 additions & 61 deletions proto/osmosis/gamm/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,54 @@ service Query {
rpc Pools(QueryPoolsRequest) returns (QueryPoolsResponse) {
option (google.api.http).get = "/osmosis/gamm/v1beta1/pools";
}

rpc NumPools(QueryNumPoolsRequest) returns (QueryNumPoolsResponse) {
option (google.api.http).get = "/osmosis/gamm/v1beta1/num_pools";
}
rpc TotalLiquidity(QueryTotalLiquidityRequest)
returns (QueryTotalLiquidityResponse) {

rpc TotalLiquidity(QueryTotalLiquidityRequest) returns (QueryTotalLiquidityResponse) {
option (google.api.http).get = "/osmosis/gamm/v1beta1/total_liquidity";
}

// Per Pool gRPC Endpoints
rpc Pool(QueryPoolRequest) returns (QueryPoolResponse) {
option (google.api.http).get = "/osmosis/gamm/v1beta1/pools/{poolId}";
}

rpc PoolParams(QueryPoolParamsRequest) returns (QueryPoolParamsResponse) {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/pools/{poolId}/params";
option (google.api.http).get = "/osmosis/gamm/v1beta1/pools/{poolId}/params";
}

rpc TotalPoolLiquidity(QueryTotalPoolLiquidityRequest)
returns (QueryTotalPoolLiquidityResponse) {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/pools/{poolId}/total_pool_liquidity";
rpc TotalPoolLiquidity(QueryTotalPoolLiquidityRequest) returns (QueryTotalPoolLiquidityResponse) {
option (google.api.http).get = "/osmosis/gamm/v1beta1/pools/{poolId}/total_pool_liquidity";
}

rpc TotalShares(QueryTotalSharesRequest) returns (QueryTotalSharesResponse) {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/pools/{poolId}/total_shares";
option (google.api.http).get = "/osmosis/gamm/v1beta1/pools/{poolId}/total_shares";
}

// SpotPrice defines a gRPC query handler that returns the spot price given
// a base denomination and a quote denomination.
rpc SpotPrice(QuerySpotPriceRequest) returns (QuerySpotPriceResponse) {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/pools/{poolId}/prices";
option (google.api.http).get = "/osmosis/gamm/v1beta1/pools/{poolId}/prices";
}

// Estimate the swap.
rpc EstimateSwapExactAmountIn(QuerySwapExactAmountInRequest)
returns (QuerySwapExactAmountInResponse) {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/{poolId}/estimate/swap_exact_amount_in";
rpc EstimateSwapExactAmountIn(QuerySwapExactAmountInRequest) returns (QuerySwapExactAmountInResponse) {
option (google.api.http).get = "/osmosis/gamm/v1beta1/{poolId}/estimate/swap_exact_amount_in";
}
rpc EstimateSwapExactAmountOut(QuerySwapExactAmountOutRequest)
returns (QuerySwapExactAmountOutResponse) {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/{poolId}/estimate/swap_exact_amount_out";

rpc EstimateSwapExactAmountOut(QuerySwapExactAmountOutRequest) returns (QuerySwapExactAmountOutResponse) {
option (google.api.http).get = "/osmosis/gamm/v1beta1/{poolId}/estimate/swap_exact_amount_out";
}
}

//=============================== Pool
message QueryPoolRequest {
uint64 poolId = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
uint64 poolId = 1 [(gogoproto.moretags) = "yaml:\"pool_id\""];
}
message QueryPoolResponse {
google.protobuf.Any pool = 1 [ (cosmos_proto.accepts_interface) = "PoolI" ];
google.protobuf.Any pool = 1 [(cosmos_proto.accepts_interface) = "PoolI"];
}

//=============================== Pools
Expand All @@ -76,8 +72,7 @@ message QueryPoolsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
message QueryPoolsResponse {
repeated google.protobuf.Any pools = 1
[ (cosmos_proto.accepts_interface) = "PoolI" ];
repeated google.protobuf.Any pools = 1 [(cosmos_proto.accepts_interface) = "PoolI"];

// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
Expand All @@ -86,88 +81,83 @@ message QueryPoolsResponse {
//=============================== NumPools
message QueryNumPoolsRequest {}
message QueryNumPoolsResponse {
uint64 numPools = 1 [ (gogoproto.moretags) = "yaml:\"num_pools\"" ];
uint64 numPools = 1 [(gogoproto.moretags) = "yaml:\"num_pools\""];
}

//=============================== PoolParams
message QueryPoolParamsRequest {
uint64 poolId = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
uint64 poolId = 1 [(gogoproto.moretags) = "yaml:\"pool_id\""];
}
message QueryPoolParamsResponse {
google.protobuf.Any params = 1;
}
message QueryPoolParamsResponse { google.protobuf.Any params = 1; }

//=============================== PoolLiquidity
message QueryTotalPoolLiquidityRequest {
uint64 poolId = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
uint64 poolId = 1 [(gogoproto.moretags) = "yaml:\"pool_id\""];
}

message QueryTotalPoolLiquidityResponse {
repeated cosmos.base.v1beta1.Coin liquidity = 1 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "yaml:\"liquidity\"",
(gogoproto.nullable) = false
(gogoproto.moretags) = "yaml:\"liquidity\"",
(gogoproto.nullable) = false
];
}

//=============================== TotalShares
message QueryTotalSharesRequest {
uint64 poolId = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
uint64 poolId = 1 [(gogoproto.moretags) = "yaml:\"pool_id\""];
}
message QueryTotalSharesResponse {
cosmos.base.v1beta1.Coin totalShares = 1 [
(gogoproto.moretags) = "yaml:\"total_shares\"",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin totalShares = 1
[(gogoproto.moretags) = "yaml:\"total_shares\"", (gogoproto.nullable) = false];
}

//=============================== SpotPrice
// QuerySpotPriceRequest defines the gRPC request structure for a SpotPrice query.
message QuerySpotPriceRequest {
uint64 poolId = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
string tokenInDenom = 2 [ (gogoproto.moretags) = "yaml:\"token_in_denom\"" ];
string tokenOutDenom = 3
[ (gogoproto.moretags) = "yaml:\"token_out_denom\"" ];
uint64 poolId = 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\""];
reserved 4;
reserved "withSwapFee";
}

// QuerySpotPriceResponse defines the gRPC response structure for a SpotPrice query.
message QuerySpotPriceResponse {
// String of the Dec. Ex) 10.203uatom
string spotPrice = 1 [ (gogoproto.moretags) = "yaml:\"spot_price\"" ];
string spotPrice = 1 [(gogoproto.moretags) = "yaml:\"spot_price\""];
}

//=============================== EstimateSwapExactAmountIn
message QuerySwapExactAmountInRequest {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
uint64 poolId = 2 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
string tokenIn = 3 [ (gogoproto.moretags) = "yaml:\"token_in\"" ];
repeated SwapAmountInRoute routes = 4 [
(gogoproto.moretags) = "yaml:\"routes\"",
(gogoproto.nullable) = false
];
string sender = 1 [(gogoproto.moretags) = "yaml:\"sender\""];
uint64 poolId = 2 [(gogoproto.moretags) = "yaml:\"pool_id\""];
string tokenIn = 3 [(gogoproto.moretags) = "yaml:\"token_in\""];
repeated SwapAmountInRoute routes = 4 [(gogoproto.moretags) = "yaml:\"routes\"", (gogoproto.nullable) = false];
}

message QuerySwapExactAmountInResponse {
string tokenOutAmount = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"token_out_amount\"",
(gogoproto.nullable) = false
(gogoproto.moretags) = "yaml:\"token_out_amount\"",
(gogoproto.nullable) = false
];
}

//=============================== EstimateSwapExactAmountOut
message QuerySwapExactAmountOutRequest {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
uint64 poolId = 2 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
repeated SwapAmountOutRoute routes = 3 [
(gogoproto.moretags) = "yaml:\"routes\"",
(gogoproto.nullable) = false
];
string tokenOut = 4 [ (gogoproto.moretags) = "yaml:\"token_out\"" ];
string sender = 1 [(gogoproto.moretags) = "yaml:\"sender\""];
uint64 poolId = 2 [(gogoproto.moretags) = "yaml:\"pool_id\""];
repeated SwapAmountOutRoute routes = 3 [(gogoproto.moretags) = "yaml:\"routes\"", (gogoproto.nullable) = false];
string tokenOut = 4 [(gogoproto.moretags) = "yaml:\"token_out\""];
}

message QuerySwapExactAmountOutResponse {
string tokenInAmount = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"token_in_amount\"",
(gogoproto.nullable) = false
(gogoproto.moretags) = "yaml:\"token_in_amount\"",
(gogoproto.nullable) = false
];
}

Expand All @@ -176,7 +166,7 @@ message QueryTotalLiquidityRequest {}
message QueryTotalLiquidityResponse {
repeated cosmos.base.v1beta1.Coin liquidity = 1 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "yaml:\"liquidity\"",
(gogoproto.nullable) = false
(gogoproto.moretags) = "yaml:\"liquidity\"",
(gogoproto.nullable) = false
];
}
23 changes: 8 additions & 15 deletions x/gamm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
"github.com/osmosis-labs/osmosis/v7/x/gamm/types"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/osmosis-labs/osmosis/v7/x/gamm/types"
)

// GetQueryCmd returns the cli query commands for this module.
Expand Down Expand Up @@ -357,22 +358,15 @@ $ %s query gamm total-liquidity
// GetCmdSpotPrice returns spot price
func GetCmdSpotPrice() *cobra.Command {
cmd := &cobra.Command{
Use: "spot-price <poolID> <tokenInDenom> <tokenOutDenom>",
Use: "spot-price <pool-ID> <base-asset-denom> <quote-asset-denom>",
Short: "Query spot-price",
Long: strings.TrimSpace(
fmt.Sprintf(`Query spot-price.
Example:
$ %s query gamm spot-price 1 stake stake2
`,
version.AppName,
),
),
Args: cobra.ExactArgs(3),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

poolID, err := strconv.Atoi(args[0])
Expand All @@ -381,9 +375,9 @@ $ %s query gamm spot-price 1 stake stake2
}

res, err := queryClient.SpotPrice(cmd.Context(), &types.QuerySpotPriceRequest{
PoolId: uint64(poolID),
TokenInDenom: args[1],
TokenOutDenom: args[2],
PoolId: uint64(poolID),
BaseAssetDenom: args[1],
QuoteAssetDenom: args[2],
})
if err != nil {
return err
Expand All @@ -394,7 +388,6 @@ $ %s query gamm spot-price 1 stake stake2
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

Expand Down
14 changes: 6 additions & 8 deletions x/gamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,22 @@ func (q Querier) SpotPrice(ctx context.Context, req *types.QuerySpotPriceRequest
return nil, status.Error(codes.InvalidArgument, "empty request")
}

if req.TokenInDenom == "" {
return nil, status.Error(codes.InvalidArgument, "invalid denom")
if req.BaseAssetDenom == "" {
return nil, status.Error(codes.InvalidArgument, "invalid base asset denom")
}

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

// Return the spot price anyway, even if the pool is inactive.

sdkCtx := sdk.UnwrapSDKContext(ctx)

pool, err := q.Keeper.GetPool(sdkCtx, req.PoolId)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "failed to get pool by ID: %s", err)
}

sp, err := pool.SpotPrice(sdkCtx, req.TokenInDenom, req.TokenOutDenom)
sp, err := pool.SpotPrice(sdkCtx, req.BaseAssetDenom, req.QuoteAssetDenom)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down
Loading

0 comments on commit 6594da2

Please sign in to comment.