Skip to content

Commit

Permalink
update calculate delegation rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
atheeshp committed Nov 6, 2024
1 parent c391ee3 commit 27e39e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions types/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ func (x BondStatus) String() string {

// DelegationI delegation bond for a delegated proof of stake system
type DelegationI interface {
GetDelegatorAddr() string // delegator string for the bond
GetValidatorAddr() string // validator operator address
GetShares() math.LegacyDec // amount of validator's shares held in this delegation
GetDelegatorAddr() string // delegator string for the bond
GetValidatorAddr() string // validator operator address
GetShares() math.LegacyDec // amount of validator's shares held in this delegation
GetEffectiveShares() math.LegacyDec // amount of validator's shares held in this delegation
}

// ValidatorI expected validator functions
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (k Keeper) initializeDelegation(ctx context.Context, val sdk.ValAddress, de
// calculate delegation stake in tokens
// we don't store directly, so multiply delegation shares * (tokens per share)
// note: necessary to truncate so we don't allow withdrawing more rewards than owed
stake := validator.TokensFromSharesTruncated(delegation.GetShares())
stake := validator.TokensFromSharesTruncated(delegation.GetEffectiveShares())
headerinfo := k.HeaderService.HeaderInfo(ctx)
return k.DelegatorStartingInfo.Set(ctx, collections.Join(val, del), types.NewDelegatorStartingInfo(previousPeriod, stake, uint64(headerinfo.Height)))
}
Expand Down
2 changes: 2 additions & 0 deletions x/staking/types/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (d Delegation) GetValidatorAddr() string {
}
func (d Delegation) GetShares() math.LegacyDec { return d.Shares }

func (d Delegation) GetEffectiveShares() math.LegacyDec { return d.EffectiveShares }

// Delegations is a collection of delegations
type Delegations []Delegation

Expand Down

0 comments on commit 27e39e3

Please sign in to comment.