Skip to content
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
16 changes: 16 additions & 0 deletions proto/dex/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ service Query {
option (google.api.http).get = "/sei-protocol/seichain/dex/short_book/{contractAddr}/{priceDenom}/{assetDenom}";
}

rpc GetPrice(QueryGetPriceRequest) returns (QueryGetPriceResponse) {
option (google.api.http).get = "/sei-protocol/seichain/dex/get_price/{contractAddr}/{priceDenom}/{assetDenom}";
}

rpc GetPrices(QueryGetPricesRequest) returns (QueryGetPricesResponse) {
option (google.api.http).get = "/sei-protocol/seichain/dex/get_prices/{contractAddr}/{priceDenom}/{assetDenom}";
}
Expand Down Expand Up @@ -156,6 +160,18 @@ message QueryGetPricesResponse {
repeated Price prices = 1;
}

message QueryGetPriceRequest {
string priceDenom = 1;
string assetDenom = 2;
string contractAddr = 3;
uint64 timestamp = 4;
}

message QueryGetPriceResponse {
Price price = 1;
bool found = 2;
}

message QueryGetTwapsRequest {
string contractAddr = 1 [
(gogoproto.jsontag) = "contract_address"
Expand Down
1 change: 1 addition & 0 deletions x/dex/client/cli/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdListShortBook())
cmd.AddCommand(CmdShowShortBook())
cmd.AddCommand(CmdGetPrice())
cmd.AddCommand(CmdGetPrices())
cmd.AddCommand(CmdGetTwaps())
cmd.AddCommand(CmdGetAssetList())
cmd.AddCommand(CmdGetAssetMetadata())
Expand Down
54 changes: 54 additions & 0 deletions x/dex/client/cli/query/query_get_price.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package query

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/sei-protocol/sei-chain/x/dex/types"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdGetPrice() *cobra.Command {
cmd := &cobra.Command{
Use: "get-price [contract-address] [timestamp] [price-denom] [asset-denom]",
Short: "Query getPrice",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqContractAddr := args[0]
reqTimestamp, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}
reqPriceDenom := args[2]
reqAssetDenom := args[3]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryGetPriceRequest{
ContractAddr: reqContractAddr,
PriceDenom: reqPriceDenom,
AssetDenom: reqAssetDenom,
Timestamp: reqTimestamp,
}

res, err := queryClient.GetPrice(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
2 changes: 1 addition & 1 deletion x/dex/client/cli/query/query_get_prices.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var _ = strconv.Itoa(0)

func CmdGetPrice() *cobra.Command {
func CmdGetPrices() *cobra.Command {
cmd := &cobra.Command{
Use: "get-prices [contract-address] [price-denom] [asset-denom]",
Short: "Query getPrices",
Expand Down
25 changes: 25 additions & 0 deletions x/dex/keeper/query/grpc_query_get_price.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package query

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/sei-chain/x/dex/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (k KeeperWrapper) GetPrice(goCtx context.Context, req *types.QueryGetPriceRequest) (*types.QueryGetPriceResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

price, found := k.GetPriceState(ctx, req.ContractAddr, req.Timestamp, types.Pair{PriceDenom: req.PriceDenom, AssetDenom: req.AssetDenom})

return &types.QueryGetPriceResponse{
Price: &price,
Found: found,
}, nil
}
Loading