Skip to content

Commit

Permalink
Query fixes (#512)
Browse files Browse the repository at this point in the history
* cleanup expired lockups

* remove all program rewards query & fix amm balance wasmbinding to return correct value for Usdc committed amount

* remove unused logging
  • Loading branch information
jelysn authored May 20, 2024
1 parent fc23747 commit 930e03d
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 1,037 deletions.
162 changes: 0 additions & 162 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40520,109 +40520,6 @@ paths:
type: string
tags:
- Query
/elys-network/elys/incentive/all_program_rewards:
get:
summary: Queries all program rewards
operationId: ElysIncentiveAllProgramRewards
responses:
'200':
description: A successful response.
schema:
type: object
properties:
usdc_staking_rewards:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
elys_staking_rewards:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
eden_staking_rewards:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
edenb_staking_rewards:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
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: address
in: query
required: false
type: string
tags:
- Query
/elys-network/elys/incentive/apr/{withdraw_type}/{denom}:
get:
summary: Calculate APR
Expand Down Expand Up @@ -86296,65 +86193,6 @@ definitions:

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
elys.incentive.QueryAllProgramRewardsResponse:
type: object
properties:
usdc_staking_rewards:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
elys_staking_rewards:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
eden_staking_rewards:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
edenb_staking_rewards:
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
elys.incentive.QueryAprResponse:
type: object
properties:
Expand Down
28 changes: 0 additions & 28 deletions proto/elys/incentive/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ service Query {
rpc PoolRewards(QueryPoolRewardsRequest) returns (QueryPoolRewardsResponse) {
option (google.api.http).get = "/elys-network/elys/incentive/pool_rewards";
}

// Queries all program rewards
rpc AllProgramRewards(QueryAllProgramRewardsRequest) returns (QueryAllProgramRewardsResponse) {
option (google.api.http).get = "/elys-network/elys/incentive/all_program_rewards";
}
}

message QueryAprRequest {
Expand Down Expand Up @@ -92,29 +87,6 @@ message QueryAprsResponse {
];
}

message QueryAllProgramRewardsRequest {
string address = 1;
}

message QueryAllProgramRewardsResponse {
repeated cosmos.base.v1beta1.Coin usdc_staking_rewards = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
repeated cosmos.base.v1beta1.Coin elys_staking_rewards = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
repeated cosmos.base.v1beta1.Coin eden_staking_rewards = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
repeated cosmos.base.v1beta1.Coin edenb_staking_rewards = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

message QueryPoolRewardsRequest {
repeated uint64 pool_ids = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 2;
Expand Down
5 changes: 2 additions & 3 deletions wasmbindings/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ type ElysQuery struct {
EpochsCurrentEpoch *epochstypes.QueryCurrentEpochRequest `json:"epochs_current_epoch,omitempty"`

// incentive queriers
IncentiveApr *incentivetypes.QueryAprRequest `json:"incentive_apr,omitempty"`
IncentiveAprs *incentivetypes.QueryAprsRequest `json:"incentive_aprs,omitempty"`
IncentiveAllProgramRewards *incentivetypes.QueryAllProgramRewardsRequest `json:"incentive_all_program_rewards,omitempty"`
IncentiveApr *incentivetypes.QueryAprRequest `json:"incentive_apr,omitempty"`
IncentiveAprs *incentivetypes.QueryAprsRequest `json:"incentive_aprs,omitempty"`

// masterchef queriers
MasterchefParams *mastercheftypes.QueryParamsRequest `json:"masterchef_params,omitempty"`
Expand Down
20 changes: 4 additions & 16 deletions x/amm/keeper/query_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package keeper
import (
"context"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/elys-network/elys/x/amm/types"
assetprofiletypes "github.com/elys-network/elys/x/assetprofile/types"
paramtypes "github.com/elys-network/elys/x/parameter/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -27,23 +25,13 @@ func (k Keeper) Balance(goCtx context.Context, req *types.QueryBalanceRequest) (
return nil, sdkerrors.ErrInvalidAddress
}

// Calculates balance in bank module
// For Eden/EdenB, calculates commitment claimed amount
balance := k.bankKeeper.GetBalance(ctx, address, denom)
if denom != paramtypes.Elys {
if denom == paramtypes.Eden || denom == paramtypes.EdenB {
commitment := k.commitmentKeeper.GetCommitments(ctx, addr)
claimed := commitment.GetClaimedForDenom(denom)
commitBalance := sdk.NewCoin(denom, claimed)

baseCurrency, found := k.assetProfileKeeper.GetUsdcDenom(ctx)
if !found {
return nil, errorsmod.Wrapf(assetprofiletypes.ErrAssetProfileNotFound, "asset %s not found", paramtypes.BaseCurrency)
}

// If it is USDC, we should add bank module balance as well.
if denom == baseCurrency {
balance = balance.Add(commitBalance)
} else {
balance = commitBalance
}
balance = sdk.NewCoin(denom, claimed)
}

return &types.QueryBalanceResponse{
Expand Down
27 changes: 0 additions & 27 deletions x/incentive/client/cli/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,3 @@ func CmdPoolRewards() *cobra.Command {

return cmd
}

func CmdAllProgramRewards() *cobra.Command {
cmd := &cobra.Command{
Use: "all-program-rewards [address]",
Short: "calculate all program rewards",
Example: "elysd q incentive all-program-rewards [address]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryAllProgramRewardsRequest{
Address: args[0],
}
res, err := queryClient.AllProgramRewards(context.Background(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
1 change: 0 additions & 1 deletion x/incentive/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdApr())
cmd.AddCommand(CmdAprs())
cmd.AddCommand(CmdPoolRewards())
cmd.AddCommand(CmdAllProgramRewards())
// this line is used by starport scaffolding # 1

return cmd
Expand Down
2 changes: 0 additions & 2 deletions x/incentive/client/wasm/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ func (oq *Querier) HandleQuery(ctx sdk.Context, query wasmbindingstypes.ElysQuer
return oq.queryApr(ctx, query.IncentiveApr)
case query.IncentiveAprs != nil:
return oq.queryAprs(ctx, query.IncentiveAprs)
case query.IncentiveAllProgramRewards != nil:
return oq.queryAllProgramRewards(ctx, query.IncentiveAllProgramRewards)
default:
// This handler cannot handle the query
return nil, wasmbindingstypes.ErrCannotHandleQuery
Expand Down
22 changes: 0 additions & 22 deletions x/incentive/client/wasm/query_all_program_rewards.go

This file was deleted.

Loading

0 comments on commit 930e03d

Please sign in to comment.