Skip to content

Commit

Permalink
Add Superfluid Params Query (#1063)
Browse files Browse the repository at this point in the history
* sf params

* query proto change

* added generated proto

* keeper updates

(cherry picked from commit 9f64276)
  • Loading branch information
czarcas7ic authored and mergify-bot committed Mar 9, 2022
1 parent e4a68a2 commit 4216f19
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 156 deletions.
6 changes: 3 additions & 3 deletions proto/osmosis/superfluid/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ option go_package = "github.com/osmosis-labs/osmosis/v7/x/superfluid/types";
// Query defines the gRPC querier service.
service Query {
// Params returns the total set of minting parameters.
rpc Params(ParamsRequest) returns (ParamsResponse) {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/osmosis/superfluid/v1beta1/params";
}

Expand Down Expand Up @@ -114,8 +114,8 @@ service Query {
// }
}

message ParamsRequest {}
message ParamsResponse {
message QueryParamsRequest {}
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
}
Expand Down
33 changes: 33 additions & 0 deletions x/superfluid/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
}

cmd.AddCommand(
GetCmdQueryParams(),
GetCmdAllSuperfluidAssets(),
GetCmdAssetMultiplier(),
GetCmdAllIntermediaryAccounts(),
Expand All @@ -37,6 +38,38 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
return cmd
}

// GetCmdQueryParams implements a command to fetch superfluid parameters.
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current superfluid parameters",
Args: cobra.NoArgs,
Long: strings.TrimSpace(`Query parameters for the superfluid module:
$ <appd> query superfluid params
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryParamsRequest{}
res, err := queryClient.Params(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(&res.Params)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdAllSuperfluidAssets returns all superfluid enabled assets
func GetCmdAllSuperfluidAssets() *cobra.Command {
cmd := &cobra.Command{
Expand Down
4 changes: 2 additions & 2 deletions x/superfluid/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
var _ types.QueryServer = Keeper{}

// Params returns the superfluid module params
func (k Keeper) Params(goCtx context.Context, req *types.ParamsRequest) (*types.ParamsResponse, error) {
func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

params := k.GetParams(ctx)

return &types.ParamsResponse{
return &types.QueryParamsResponse{
Params: params,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion x/superfluid/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func (suite *KeeperTestSuite) TestGRPCParams() {
suite.SetupTest()
res, err := suite.App.SuperfluidKeeper.Params(sdk.WrapSDKContext(suite.Ctx), &types.ParamsRequest{})
res, err := suite.App.SuperfluidKeeper.Params(sdk.WrapSDKContext(suite.Ctx), &types.QueryParamsRequest{})
suite.Require().NoError(err)
suite.Require().True(res.Params.MinimumRiskFactor.Equal(types.DefaultParams().MinimumRiskFactor))
}
Expand Down
Loading

0 comments on commit 4216f19

Please sign in to comment.