Skip to content

Commit

Permalink
fix: CNS-fix-reward-query (#1633)
Browse files Browse the repository at this point in the history
* fix

* add handler vor v2.5.0

---------

Co-authored-by: Yarom Swisa <[email protected] git config --global user.name Yarom>
  • Loading branch information
Yaroms and Yarom Swisa authored Aug 18, 2024
1 parent 26a8fad commit 28a5fdd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ var Upgrades = []upgrades.Upgrade{
upgrades.Upgrade_2_1_3,
upgrades.Upgrade_2_2_0,
upgrades.Upgrade_2_4_0,
upgrades.Upgrade_2_5_0,
}

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/empty_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,9 @@ var Upgrade_2_4_0 = Upgrade{
CreateUpgradeHandler: defaultUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}

var Upgrade_2_5_0 = Upgrade{
UpgradeName: "v2.5.0",
CreateUpgradeHandler: defaultUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}
6 changes: 3 additions & 3 deletions x/subscription/keeper/grpc_query_estimated_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (k Keeper) EstimatedRewards(goCtx context.Context, req *types.QueryEstimate

// delegation of the provider
delegationAmount := entry.Stake
delegatorPart := sdk.NewDecFromInt(delegationAmount.Amount).QuoInt(totalStake).MulInt64(int64(entry.DelegateCommission)).QuoInt64(100)
delegatorPart := sdk.NewDecFromInt(delegationAmount.Amount).QuoInt(totalStake)
if req.AmountDelegator != "" {
_, err := sdk.AccAddressFromBech32(req.AmountDelegator)
if err == nil {
Expand Down Expand Up @@ -69,7 +69,7 @@ func (k Keeper) EstimatedRewards(goCtx context.Context, req *types.QueryEstimate
if entry.DelegateLimit.Amount.LT(entry.DelegateTotal.Amount) {
totalDelegations = entry.DelegateLimit.Amount
}
commission := sdk.NewDecFromInt(totalDelegations).QuoInt(entry.EffectiveStake()).MulInt64(int64(entry.DelegateCommission)).QuoInt64(100)
commission := sdk.NewDecFromInt(totalDelegations).QuoInt(totalStake).MulInt64(int64(entry.DelegateCommission)).QuoInt64(100)
delegatorPart = delegatorPart.Add(commission)
}
delegatorPart = delegatorPart.Mul(sdk.OneDec().Sub(specContribut))
Expand Down Expand Up @@ -99,7 +99,7 @@ func (k Keeper) EstimatedRewards(goCtx context.Context, req *types.QueryEstimate
return nil, fmt.Errorf("spec emission part not found for chain ID: %s", req.ChainId)
}

subscriptionRewards := sdk.NewCoins(totalSubsRewards.MulInt(specEmission.Emission.MulInt64(100).RoundInt())...)
subscriptionRewards, _ := sdk.NewDecCoinsFromCoins(totalSubsRewards...).MulDec(specEmission.Emission).TruncateDecimal()
valRewards, comRewards, err := k.rewardsKeeper.CalculateValidatorsAndCommunityParticipationRewards(ctx, subscriptionRewards[0])
if err != nil {
return nil, fmt.Errorf("failed to calculate Validators And Community Participation Rewards")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (k Keeper) EstimatedValidatorRewards(goCtx context.Context, req *types.Quer
if !found {
return nil, fmt.Errorf("self delegation not found")
}
delegatorPart = del.Shares.Quo(val.DelegatorShares).Add(val.DelegatorShares.Sub(del.Shares).Quo(val.DelegatorShares).Mul(val.Commission.Rate))
delegatorPart = del.Shares.Add(val.DelegatorShares.Sub(del.Shares).Mul(val.Commission.Rate)).Quo(val.DelegatorShares)
} else {
delAddress, err := sdk.AccAddressFromBech32(req.AmountDelegator)
// existing delegator
Expand Down

0 comments on commit 28a5fdd

Please sign in to comment.