Skip to content

Commit

Permalink
Update allProgramRewards query to return Coins instead of DecCoins
Browse files Browse the repository at this point in the history
  • Loading branch information
jelysn committed May 15, 2024
1 parent 5ea1b36 commit 9234190
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 108 deletions.
36 changes: 16 additions & 20 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40540,11 +40540,10 @@ paths:
amount:
type: string
description: >-
DecCoin defines a token with a denomination and a decimal
amount.
Coin defines a token with a denomination and an amount.


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

signatures required by gogoproto.
Expand All @@ -40558,11 +40557,10 @@ paths:
amount:
type: string
description: >-
DecCoin defines a token with a denomination and a decimal
amount.
Coin defines a token with a denomination and an amount.


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

signatures required by gogoproto.
Expand All @@ -40576,11 +40574,10 @@ paths:
amount:
type: string
description: >-
DecCoin defines a token with a denomination and a decimal
amount.
Coin defines a token with a denomination and an amount.


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

signatures required by gogoproto.
Expand All @@ -40594,11 +40591,10 @@ paths:
amount:
type: string
description: >-
DecCoin defines a token with a denomination and a decimal
amount.
Coin defines a token with a denomination and an amount.


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

signatures required by gogoproto.
Expand Down Expand Up @@ -86313,9 +86309,9 @@ definitions:
amount:
type: string
description: |-
DecCoin defines a token with a denomination and a decimal amount.
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Dec which implements the custom method
NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
elys_staking_rewards:
type: array
Expand All @@ -86327,9 +86323,9 @@ definitions:
amount:
type: string
description: |-
DecCoin defines a token with a denomination and a decimal amount.
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Dec which implements the custom method
NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
eden_staking_rewards:
type: array
Expand All @@ -86341,9 +86337,9 @@ definitions:
amount:
type: string
description: |-
DecCoin defines a token with a denomination and a decimal amount.
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Dec which implements the custom method
NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
edenb_staking_rewards:
type: array
Expand All @@ -86355,9 +86351,9 @@ definitions:
amount:
type: string
description: |-
DecCoin defines a token with a denomination and a decimal amount.
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Dec which implements the custom method
NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
elys.incentive.QueryAprResponse:
type: object
Expand Down
16 changes: 8 additions & 8 deletions proto/elys/incentive/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ message QueryAllProgramRewardsRequest {
}

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

Expand Down
28 changes: 28 additions & 0 deletions scripts/examples/estaking/snapshot_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

elysd query estaking params

elysd query staking validators
VALIDATOR=elysvaloper1dd34v384hdfqgajkg0jzp0y5k6qlvhltr73as2
EDEN_VAL=elysvaloper1gnmpr8vvslp3shcq6e922xr0uq4aa2w5gdzht0
EDENB_VAL=elysvaloper1wajd6ekh9u37hyghyw4mme59qmjllzuyaceanm

elysd tx staking delegate $VALIDATOR 10000000000000uelys --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000
elysd query distribution rewards elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg $VALIDATOR
elysd query distribution rewards elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg $EDEN_VAL
elysd query distribution rewards elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg $EDENB_VAL

elysd tx estaking withdraw-all-rewards --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000

elysd tx commitment commit-claimed-rewards 158762097 ueden --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000
elysd tx commitment commit-claimed-rewards 1066283235 uedenb --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000
elysd tx commitment uncommit-tokens 35235693 ueden --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000
elysd tx commitment commit-claimed-rewards 35235693 ueden --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000
elysd tx commitment uncommit-tokens 304152385 uedenb --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000
elysd tx commitment uncommit-tokens 70471386 ueden --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000

elysd query commitment show-commitments elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg
elysd query estaking rewards elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg
elysd tx estaking withdraw-all-rewards --from=validator --chain-id=elystestnet-1

elysd query incentive all-program-rewards elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg
17 changes: 10 additions & 7 deletions x/incentive/keeper/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,28 +167,29 @@ func (k Keeper) AllProgramRewards(goCtx context.Context, req *types.QueryAllProg

k.masterchef.AfterWithdraw(ctx, stablestaketypes.PoolId, req.Address, sdk.ZeroInt())

stableStakeRewards := sdk.NewDecCoins()
stableStakeRewards := sdk.Coins{}
for _, rewardDenom := range k.masterchef.GetRewardDenoms(ctx, stablestaketypes.PoolId) {
userRewardInfo, found := k.masterchef.GetUserRewardInfo(ctx, req.Address, stablestaketypes.PoolId, rewardDenom)
if found && userRewardInfo.RewardPending.IsPositive() {
stableStakeRewards = stableStakeRewards.Add(
sdk.NewDecCoinFromDec(
sdk.NewCoin(
rewardDenom,
userRewardInfo.RewardPending,
userRewardInfo.RewardPending.TruncateInt(),
),
)
}
}

delAddr := sdk.MustAccAddressFromBech32(req.Address)
delegations := k.estaking.Keeper.GetDelegatorDelegations(ctx, delAddr, 5000)
elysStakingRewards := sdk.DecCoins{}
elysStakingRewards := sdk.Coins{}
for _, del := range delegations {
rewards, err := k.estaking.DelegationRewards(ctx, req.Address, del.ValidatorAddress)
if err != nil {
return nil, err
}
elysStakingRewards = elysStakingRewards.Add(rewards...)
finalRewards, _ := rewards.TruncateDecimal()
elysStakingRewards = elysStakingRewards.Add(finalRewards...)
}

// Eden commit rewards
Expand All @@ -197,19 +198,21 @@ func (k Keeper) AllProgramRewards(goCtx context.Context, req *types.QueryAllProg
if err != nil {
edenCommitRewards = []sdk.DecCoin{}
}
finalEdenCommitRewards, _ := edenCommitRewards.TruncateDecimal()

// EdenB commit rewards
edenBVal := k.estaking.GetParams(ctx).EdenbCommitVal
edenBCommitRewards, err := k.estaking.DelegationRewards(ctx, req.Address, edenBVal)
if err != nil {
edenBCommitRewards = []sdk.DecCoin{}
}
finalEdenBCommitRewards, _ := edenBCommitRewards.TruncateDecimal()

return &types.QueryAllProgramRewardsResponse{
UsdcStakingRewards: stableStakeRewards,
ElysStakingRewards: elysStakingRewards,
EdenStakingRewards: edenCommitRewards,
EdenbStakingRewards: edenBCommitRewards,
EdenStakingRewards: finalEdenCommitRewards,
EdenbStakingRewards: finalEdenBCommitRewards,
}, nil
}

Expand Down
Loading

0 comments on commit 9234190

Please sign in to comment.