Skip to content

Commit

Permalink
Merge pull request #137 from onomyprotocol/dong/queryShortfallAmount
Browse files Browse the repository at this point in the history
vault(cli): Add query shortfall amount
  • Loading branch information
DongLieu authored Jan 22, 2025
2 parents 79b4e2f + e7261e9 commit 448114a
Show file tree
Hide file tree
Showing 5 changed files with 586 additions and 74 deletions.
16 changes: 16 additions & 0 deletions proto/reserve/vaults/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,24 @@ service Query {
rpc QueryTotalCollateralLockedByDenom(QueryTotalCollateralLockedByDenomRequest) returns (QueryTotalCollateralLockedByDenomResponse){
option (google.api.http).get = "/reserve/vaults/params";
}

rpc QueryShortfallAmount(QueryShortfallAmountRequest) returns (QueryShortfallAmountResponse){
option (google.api.http).get = "/reserve/vaults/params";
}
}

message QueryShortfallAmountRequest {
string mint_denom = 1;
}

message QueryShortfallAmountResponse {
string amount = 1 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];
}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

Expand Down
27 changes: 27 additions & 0 deletions x/vaults/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func GetQueryCmd() *cobra.Command {
cmd.AddCommand(CmdQueryVaultFromAddress())
cmd.AddCommand(CmdQueryCollateralsByDenom())
cmd.AddCommand(CmdQueryTotalCollateralLockedByDenom())
cmd.AddCommand(CmdQueryShortfallAmount())
return cmd
}

Expand Down Expand Up @@ -245,3 +246,29 @@ func CmdQueryTotalCollateralLockedByDenom() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func CmdQueryShortfallAmount() *cobra.Command {
cmd := &cobra.Command{
Use: "query-shortfall-amount [mint-denom]",
Short: "show total shortfall amount by mint denom",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

msg := types.QueryShortfallAmountRequest{
MintDenom: args[0],
}

res, err := queryClient.QueryShortfallAmount(context.Background(), &msg)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
10 changes: 10 additions & 0 deletions x/vaults/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,13 @@ func (q queryServer) QueryTotalCollateralLockedByDenom(ctx context.Context, req
Total: total,
}, err
}

func (q queryServer) QueryShortfallAmount(ctx context.Context, req *types.QueryShortfallAmountRequest) (*types.QueryShortfallAmountResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

amount, err := q.keeper.ShortfallAmount.Get(ctx, req.MintDenom)

return &types.QueryShortfallAmountResponse{Amount: amount}, err
}
Loading

0 comments on commit 448114a

Please sign in to comment.