Skip to content

Commit 21c3f52

Browse files
authored
adding query to list all pool infos (#1265)
1 parent 2b49cbb commit 21c3f52

File tree

8 files changed

+2495
-710
lines changed

8 files changed

+2495
-710
lines changed

api/elys/masterchef/query.pulsar.go

Lines changed: 1688 additions & 543 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/elys/masterchef/query_grpc.pb.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/elys/masterchef/query.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ service Query {
3030
rpc PoolInfo(QueryPoolInfoRequest) returns (QueryPoolInfoResponse) {
3131
option (google.api.http).get = "/elys-network/elys/masterchef/pool_info";
3232
}
33+
rpc ListPoolInfos(QueryListPoolInfosRequest)
34+
returns (QueryListPoolInfosResponse) {
35+
option (google.api.http).get =
36+
"/elys-network/elys/masterchef/list_pool_infos";
37+
}
3338
rpc PoolRewardInfo(QueryPoolRewardInfoRequest)
3439
returns (QueryPoolRewardInfoResponse) {
3540
option (google.api.http).get =
@@ -176,6 +181,15 @@ message QueryPoolInfoResponse {
176181
];
177182
}
178183

184+
message QueryListPoolInfosRequest {
185+
cosmos.base.query.v1beta1.PageRequest pagination = 1;
186+
}
187+
188+
message QueryListPoolInfosResponse {
189+
repeated QueryPoolInfoResponse list = 1 [ (gogoproto.nullable) = false ];
190+
cosmos.base.query.v1beta1.PageResponse pagination = 2;
191+
}
192+
179193
message QueryPoolRewardInfoRequest {
180194
uint64 pool_id = 1;
181195
string reward_denom = 2;

proto/elys/tier/query.proto

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ service Query {
105105
option (google.api.http).get = "/elys-network/elys/tier/get_all_prices";
106106
}
107107

108-
// Queries a list of Oracle prices from denoms.
108+
// Queries a list of Oracle prices from denoms.
109109
rpc GetOraclePrices(QueryGetOraclePricesRequest)
110-
returns (QueryGetOraclePricesResponse) {
111-
option (google.api.http).get = "/elys-network/elys/tier/get_oracle_prices/{denoms}";
110+
returns (QueryGetOraclePricesResponse) {
111+
option (google.api.http).get =
112+
"/elys-network/elys/tier/get_oracle_prices/{denoms}";
112113
}
113114
}
114115
// QueryParamsRequest is request type for the Query/Params RPC method.

x/masterchef/autocli.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
3333
Example: "elysd q masterchef pool-info [id]",
3434
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "pool_id"}},
3535
},
36+
{
37+
RpcMethod: "ListPoolInfos",
38+
Use: "list-pool-infos",
39+
Short: "shows all pool infos",
40+
Example: "elysd q masterchef list-pool-infos",
41+
},
3642
{
3743
RpcMethod: "PoolRewardInfo",
3844
Use: "pool-reward-info [id] [reward-denom]",

x/masterchef/keeper/query.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package keeper
22

33
import (
44
"context"
5+
"cosmossdk.io/store/prefix"
6+
"github.com/cosmos/cosmos-sdk/runtime"
7+
"github.com/cosmos/cosmos-sdk/types/query"
58

69
sdkmath "cosmossdk.io/math"
710

@@ -48,6 +51,42 @@ func (k Keeper) PoolInfo(goCtx context.Context, req *types.QueryPoolInfoRequest)
4851
return &types.QueryPoolInfoResponse{PoolInfo: poolInfo, StableApr: stable_apr.Dec()}, nil
4952
}
5053

54+
func (k Keeper) ListPoolInfos(goCtx context.Context, req *types.QueryListPoolInfosRequest) (*types.QueryListPoolInfosResponse, error) {
55+
ctx := sdk.UnwrapSDKContext(goCtx)
56+
57+
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
58+
poolStore := prefix.NewStore(store, types.PoolInfoKeyPrefix)
59+
60+
var list []types.QueryPoolInfoResponse
61+
62+
pageRes, err := query.Paginate(poolStore, req.Pagination, func(key []byte, value []byte) error {
63+
var pool types.PoolInfo
64+
if err := k.cdc.Unmarshal(value, &pool); err != nil {
65+
return err
66+
}
67+
68+
stable_apr := osmomath.ZeroBigDec()
69+
if pool.PoolId >= stabletypes.UsdcPoolId {
70+
borrowPool, found := k.stableKeeper.GetPool(ctx, pool.PoolId)
71+
if found {
72+
res, err := k.stableKeeper.BorrowRatio(ctx, &stabletypes.QueryBorrowRatioRequest{PoolId: pool.PoolId})
73+
if err == nil {
74+
stable_apr = borrowPool.GetBigDecInterestRate().MulDec(res.BorrowRatio)
75+
}
76+
}
77+
}
78+
79+
list = append(list, types.QueryPoolInfoResponse{PoolInfo: pool, StableApr: stable_apr.Dec()})
80+
81+
return nil
82+
})
83+
if err != nil {
84+
return nil, status.Error(codes.Internal, err.Error())
85+
}
86+
87+
return &types.QueryListPoolInfosResponse{List: list, Pagination: pageRes}, nil
88+
}
89+
5190
func (k Keeper) PoolRewardInfo(goCtx context.Context, req *types.QueryPoolRewardInfoRequest) (*types.QueryPoolRewardInfoResponse, error) {
5291
ctx := sdk.UnwrapSDKContext(goCtx)
5392

0 commit comments

Comments
 (0)