cosmos-sdk/x/distribution/types/delegator_info.go

30 lines
963 B
Go
Raw Normal View History

package types
import sdk "github.com/cosmos/cosmos-sdk/types"
// distribution info for a delegation
type DelegatorDistInfo struct {
DelegatorAddr sdk.AccAddress
ValOperatorAddr sdk.ValAddress
WithdrawalHeight int64 // last time this delegation withdrew rewards
}
// withdraw rewards from delegator
func (di DelegatorDistInfo) WithdrawRewards(g Global, vi ValidatorDistInfo,
2018-09-13 23:35:02 -07:00
height int64, totalBonded, vdTokens, totalDelShares, delegatorShares,
commissionRate Dec) (di DelegatorDistInfo, g Global, withdrawn DecCoins) {
vi.UpdateTotalDelAccum(height, totalDelShares)
g = vi.TakeGlobalRewards(g, height, totalBonded, vdTokens, commissionRate)
blocks = height - di.WithdrawalHeight
di.WithdrawalHeight = height
2018-09-13 23:35:02 -07:00
accum := delegatorShares.Mul(sdk.NewDec(blocks))
withdrawalTokens := vi.Pool.Mul(accum.Quo(vi.TotalDelAccum))
2018-09-13 23:35:02 -07:00
vi.Pool = vi.Pool.Sub(withdrawalTokens)
vi.TotalDelAccum = vi.TotalDelAccum.sub(accum)
return di, g, withdrawalTokens
}