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(fungible): add query command to get all gas stability pool balances #1247

Merged
merged 7 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
33 changes: 31 additions & 2 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27810,6 +27810,21 @@ paths:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/zetacore/fungible/gas_stability_pool_balance:
get:
summary: Queries all gas stability pool balances.
operationId: Query_GasStabilityPoolBalanceAll
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/fungibleQueryAllGasStabilityPoolBalanceResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/zetacore/fungible/gas_stability_pool_balance/{chain_id}:
get:
summary: Queries the balance of a gas stability pool on a given chain.
Expand Down Expand Up @@ -50202,6 +50217,14 @@ definitions:
- VOTE_OPTION_ABSTAIN: VOTE_OPTION_ABSTAIN defines an abstain vote option.
- VOTE_OPTION_NO: VOTE_OPTION_NO defines a no vote option.
- VOTE_OPTION_NO_WITH_VETO: VOTE_OPTION_NO_WITH_VETO defines a no with veto vote option.
QueryAllGasStabilityPoolBalanceResponseBalance:
type: object
properties:
chain_id:
type: string
format: int64
balance:
type: string
commonBlockHeader:
type: object
properties:
Expand Down Expand Up @@ -50816,6 +50839,14 @@ definitions:
$ref: '#/definitions/fungibleForeignCoins'
pagination:
$ref: '#/definitions/v1beta1PageResponse'
fungibleQueryAllGasStabilityPoolBalanceResponse:
type: object
properties:
balances:
type: array
items:
type: object
$ref: '#/definitions/QueryAllGasStabilityPoolBalanceResponseBalance'
fungibleQueryGetForeignCoinsResponse:
type: object
properties:
Expand All @@ -50831,8 +50862,6 @@ definitions:
fungibleQueryGetGasStabilityPoolBalanceResponse:
type: object
properties:
contract_address:
type: string
balance:
type: string
fungibleQueryGetSystemContractResponse:
Expand Down
16 changes: 15 additions & 1 deletion proto/fungible/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ service Query {
rpc GasStabilityPoolBalance(QueryGetGasStabilityPoolBalance) returns (QueryGetGasStabilityPoolBalanceResponse) {
option (google.api.http).get = "/zeta-chain/zetacore/fungible/gas_stability_pool_balance/{chain_id}";
}

// Queries all gas stability pool balances.
rpc GasStabilityPoolBalanceAll(QueryAllGasStabilityPoolBalance) returns (QueryAllGasStabilityPoolBalanceResponse) {
option (google.api.http).get = "/zeta-chain/zetacore/fungible/gas_stability_pool_balance";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -86,6 +91,15 @@ message QueryGetGasStabilityPoolBalance {
}

message QueryGetGasStabilityPoolBalanceResponse {
string contract_address = 1;
string balance = 2;
}

message QueryAllGasStabilityPoolBalance {}

message QueryAllGasStabilityPoolBalanceResponse {
message Balance {
int64 chain_id = 1;
string balance = 2;
}
repeated Balance balances = 1 [(gogoproto.nullable) = false];
}
1 change: 1 addition & 0 deletions x/fungible/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func GetQueryCmd(_ string) *cobra.Command {
CmdShowForeignCoins(),
CmdGasStabilityPoolAddress(),
CmdGasStabilityPoolBalance(),
CmdGasStabilityPoolBalances(),
)

return cmd
Expand Down
25 changes: 25 additions & 0 deletions x/fungible/client/cli/query_gas_stability_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,28 @@ func CmdGasStabilityPoolBalance() *cobra.Command {

return cmd
}

func CmdGasStabilityPoolBalances() *cobra.Command {
cmd := &cobra.Command{
Use: "gas-stability-pool-balances",
Short: "query all gas stability pool balances",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.GasStabilityPoolBalanceAll(context.Background(), &types.QueryAllGasStabilityPoolBalance{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
flags.AddQueryFlagsToCmd(cmd)

return cmd
}
37 changes: 37 additions & 0 deletions x/fungible/keeper/grpc_gas_stability_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,40 @@ func (k Keeper) GasStabilityPoolBalance(

return &types.QueryGetGasStabilityPoolBalanceResponse{Balance: balance.String()}, nil
}

func (k Keeper) GasStabilityPoolBalanceAll(
c context.Context,
req *types.QueryAllGasStabilityPoolBalance,
) (*types.QueryAllGasStabilityPoolBalanceResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)

// iterate supported chains
chains := k.observerKeeper.GetParams(ctx).GetSupportedChains()
balances := make([]types.QueryAllGasStabilityPoolBalanceResponse_Balance, 0, len(chains))
for _, chain := range chains {
if chain == nil {
return nil, status.Error(codes.Internal, "invalid chain")
}
chainID := chain.ChainId

balance, err := k.GetGasStabilityPoolBalance(ctx, chainID)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
if balance == nil {
return nil, status.Error(codes.NotFound, "no balance for the gas stability pool")
}

balances = append(balances, types.QueryAllGasStabilityPoolBalanceResponse_Balance{
ChainId: chainID,
Balance: balance.String(),
})
}

return &types.QueryAllGasStabilityPoolBalanceResponse{
Balances: balances,
}, nil
}
Loading
Loading