Skip to content

Commit

Permalink
remove all program rewards query & fix amm balance wasmbinding to ret…
Browse files Browse the repository at this point in the history
…urn correct value for Usdc committed amount
  • Loading branch information
jelysn committed May 20, 2024
1 parent 0d53584 commit 42263da
Show file tree
Hide file tree
Showing 12 changed files with 72 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
12 changes: 12 additions & 0 deletions x/estaking/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand All @@ -13,16 +14,19 @@ import (
var _ types.QueryServer = Keeper{}

func (k Keeper) Rewards(goCtx context.Context, req *types.QueryRewardsRequest) (*types.QueryRewardsResponse, error) {
fmt.Println("DEBUG:: EstakingRewards-1")
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

fmt.Println("DEBUG:: EstakingRewards-2")
if req.Address == "" {
return nil, status.Error(codes.InvalidArgument, "empty delegator address")
}

ctx := sdk.UnwrapSDKContext(goCtx)

fmt.Println("DEBUG:: EstakingRewards-3")
total := sdk.DecCoins{}
var delRewards []types.DelegationDelegatorReward

Expand All @@ -31,27 +35,35 @@ func (k Keeper) Rewards(goCtx context.Context, req *types.QueryRewardsRequest) (
return nil, err
}

fmt.Println("DEBUG:: EstakingRewards-4")
k.IterateDelegations(
ctx, delAddr,
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
fmt.Println("DEBUG:: EstakingRewards-4-1")
valAddr := del.GetValidatorAddr()
val := k.Validator(ctx, valAddr)
fmt.Println("DEBUG:: EstakingRewards-4-2", val)
endingPeriod := k.distrKeeper.IncrementValidatorPeriod(ctx, val)
fmt.Println("DEBUG:: EstakingRewards-4-3", del)
delReward := k.distrKeeper.CalculateDelegationRewards(ctx, val, del, endingPeriod)

fmt.Println("DEBUG:: EstakingRewards-4-4", delReward)
finalRewards, _ := delReward.TruncateDecimal()
if finalRewards == nil {
finalRewards = []sdk.Coin{}
}
fmt.Println("DEBUG:: EstakingRewards-4-5", finalRewards)
delRewards = append(delRewards, types.DelegationDelegatorReward{
ValidatorAddress: valAddr.String(),
Reward: finalRewards,
})
total = total.Add(delReward...)
fmt.Println("DEBUG:: EstakingRewards-4-6", total)
return false
},
)
finalTotalRewards, _ := total.TruncateDecimal()
fmt.Println("DEBUG:: EstakingRewards-5")

return &types.QueryRewardsResponse{Rewards: delRewards, Total: finalTotalRewards}, nil
}
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
Loading

0 comments on commit 42263da

Please sign in to comment.