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: add in-route-by-denom and out-route-by-denom queries #262

Merged
merged 1 commit into from
Nov 21, 2023
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
112 changes: 112 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37736,6 +37736,98 @@ paths:
type: string
tags:
- Query
/elys-network/elys/amm/in_route_by_denom/{denom_in}/{denom_out}:
get:
summary: Queries a list of InRouteByDenom items.
operationId: ElysAmmInRouteByDenom
responses:
'200':
description: A successful response.
schema:
type: object
properties:
in_route_ids:
type: array
items:
type: object
properties:
pool_id:
type: string
format: uint64
token_out_denom:
type: string
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
parameters:
- name: denom_in
in: path
required: true
type: string
- name: denom_out
in: path
required: true
type: string
tags:
- Query
/elys-network/elys/amm/out_route_by_denom/{denomOut}/{denomIn}:
get:
summary: Queries a list of OutRouteByDenom items.
operationId: ElysAmmOutRouteByDenom
responses:
'200':
description: A successful response.
schema:
type: object
properties:
outRouteIds:
type: array
items:
type: string
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
parameters:
- name: denomOut
in: path
required: true
type: string
- name: denomIn
in: path
required: true
type: string
tags:
- Query
/elys-network/elys/amm/params:
get:
summary: Parameters queries the parameters of the module.
Expand Down Expand Up @@ -82752,6 +82844,26 @@ definitions:
type: string
rebalance_treasury:
type: string
elys.amm.QueryInRouteByDenomResponse:
type: object
properties:
in_route_ids:
type: array
items:
type: object
properties:
pool_id:
type: string
format: uint64
token_out_denom:
type: string
elys.amm.QueryOutRouteByDenomResponse:
type: object
properties:
outRouteIds:
type: array
items:
type: string
elys.amm.QueryParamsResponse:
type: object
properties:
Expand Down
34 changes: 32 additions & 2 deletions proto/elys/amm/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ service Query {
option (google.api.http).get = "/elys-network/elys/amm/balance/{address}/{denom}";

}

// Queries a list of InRouteByDenom items.
rpc InRouteByDenom (QueryInRouteByDenomRequest) returns (QueryInRouteByDenomResponse) {
option (google.api.http).get = "/elys-network/elys/amm/in_route_by_denom/{denom_in}/{denom_out}";

}

// Queries a list of OutRouteByDenom items.
rpc OutRouteByDenom (QueryOutRouteByDenomRequest) returns (QueryOutRouteByDenomResponse) {
option (google.api.http).get = "/elys-network/elys/amm/out_route_by_denom/{denom_out}/{denom_in}";

}
}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}
Expand Down Expand Up @@ -109,11 +121,11 @@ message QueryAllDenomLiquidityRequest {

message QueryAllDenomLiquidityResponse {
repeated DenomLiquidity denom_liquidity = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QuerySwapEstimationRequest {
repeated SwapAmountInRoute routes = 1;
repeated SwapAmountInRoute routes = 1;
cosmos.base.v1beta1.Coin token_in = 2 [(gogoproto.nullable) = false];
}

Expand Down Expand Up @@ -145,3 +157,21 @@ message QueryBalanceResponse {
cosmos.base.v1beta1.Coin balance = 1 [(gogoproto.nullable) = false];
}

message QueryInRouteByDenomRequest {
string denom_in = 1;
string denom_out = 2;
}

message QueryInRouteByDenomResponse {
repeated SwapAmountInRoute in_route = 1;
}

message QueryOutRouteByDenomRequest {
string denom_out = 1;
string denom_in = 2;
}

message QueryOutRouteByDenomResponse {
repeated SwapAmountOutRoute out_route = 1;
}

2 changes: 2 additions & 0 deletions wasmbindings/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ type ElysQuery struct {
AmmSlippageTrack *ammtypes.QuerySlippageTrackRequest `json:"amm_slippage_track,omitempty"`
AmmSlippageTrackAll *ammtypes.QuerySlippageTrackAllRequest `json:"amm_slippage_track_all,omitempty"`
AmmBalance *ammtypes.QueryBalanceRequest `json:"amm_balance,omitempty"`
AmmInRouteByDenom *ammtypes.QueryInRouteByDenomRequest `json:"amm_in_route_by_denom,omitempty"`
AmmOutRouteByDenom *ammtypes.QueryOutRouteByDenomRequest `json:"amm_out_route_by_denom,omitempty"`

// assetprofile queriers
AssetProfileParams *assetprofiletypes.QueryParamsRequest `json:"asset_profile_params,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions x/amm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdShowDenomLiquidity())
cmd.AddCommand(CmdSwapEstimation())
cmd.AddCommand(CmdBalance())
cmd.AddCommand(CmdInRouteByDenom())

cmd.AddCommand(CmdOutRouteByDenom())

// this line is used by starport scaffolding # 1

Expand Down
48 changes: 48 additions & 0 deletions x/amm/client/cli/query_in_route_by_denom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/elys-network/elys/x/amm/types"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdInRouteByDenom() *cobra.Command {
cmd := &cobra.Command{
Use: "in-route-by-denom [denom-in] [denom-out]",
Example: "elysd q amm in-route-by-denom uelys uusdc",
Short: "Query in-route-by-denom",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqDenomIn := args[0]
reqDenomOut := args[1]

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

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryInRouteByDenomRequest{
DenomIn: reqDenomIn,
DenomOut: reqDenomOut,
}

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

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
48 changes: 48 additions & 0 deletions x/amm/client/cli/query_out_route_by_denom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/elys-network/elys/x/amm/types"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdOutRouteByDenom() *cobra.Command {
cmd := &cobra.Command{
Use: "out-route-by-denom [denom-out] [denom-in]",
Example: "elysd q amm out-route-by-denom uusdc uelys",
Short: "Query out-route-by-denom",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqDenomOut := args[0]
reqDenomIn := args[1]

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

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryOutRouteByDenomRequest{
DenomOut: reqDenomOut,
DenomIn: reqDenomIn,
}

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

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
4 changes: 4 additions & 0 deletions x/amm/client/wasm/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (oq *Querier) HandleQuery(ctx sdk.Context, query wasmbindingstypes.ElysQuer
return oq.querySlippageTrackAll(ctx, query.AmmSlippageTrackAll)
case query.AmmBalance != nil:
return oq.queryBalance(ctx, query.AmmBalance)
case query.AmmInRouteByDenom != nil:
return oq.queryInRouteByDenom(ctx, query.AmmInRouteByDenom)
case query.AmmOutRouteByDenom != nil:
return oq.queryOutRouteByDenom(ctx, query.AmmOutRouteByDenom)
default:
// This handler cannot handle the query
return nil, wasmbindingstypes.ErrCannotHandleQuery
Expand Down
22 changes: 22 additions & 0 deletions x/amm/client/wasm/query_in_route_by_denom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package wasm

import (
"encoding/json"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
ammtypes "github.com/elys-network/elys/x/amm/types"
)

func (oq *Querier) queryInRouteByDenom(ctx sdk.Context, query *ammtypes.QueryInRouteByDenomRequest) ([]byte, error) {
res, err := oq.keeper.InRouteByDenom(sdk.WrapSDKContext(ctx), query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get in route by denom")
}

responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize in route by denom response")
}
return responseBytes, nil
}
22 changes: 22 additions & 0 deletions x/amm/client/wasm/query_out_route_by_denom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package wasm

import (
"encoding/json"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
ammtypes "github.com/elys-network/elys/x/amm/types"
)

func (oq *Querier) queryOutRouteByDenom(ctx sdk.Context, query *ammtypes.QueryOutRouteByDenomRequest) ([]byte, error) {
res, err := oq.keeper.OutRouteByDenom(sdk.WrapSDKContext(ctx), query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get out route by denom")
}

responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize out route by denom response")
}
return responseBytes, nil
}
23 changes: 23 additions & 0 deletions x/amm/keeper/query_in_route_by_denom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (k Keeper) InRouteByDenom(goCtx context.Context, req *types.QueryInRouteByDenomRequest) (*types.QueryInRouteByDenomResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Process the query
_ = ctx

return &types.QueryInRouteByDenomResponse{}, nil
}
Loading
Loading