Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix negative staking token #97

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions x/stake/types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,23 @@ func (v Validator) AddTokensFromDel(pool Pool, amount int64) (Validator, Pool, s

// RemoveDelShares removes delegator shares from a validator.
func (v Validator) RemoveDelShares(pool Pool, delShares sdk.Dec) (Validator, Pool, sdk.Dec) {
issuedTokens := v.DelegatorShareExRate().Mul(delShares)
v.Tokens = v.Tokens.Sub(issuedTokens)
v.DelegatorShares = v.DelegatorShares.Sub(delShares)

remainingShares := v.DelegatorShares.Sub(delShares)
var issuedTokens sdk.Dec
if remainingShares.IsZero() {

// last delegation share gets any trimmings
issuedTokens = v.Tokens
v.Tokens = sdk.ZeroDec()
} else {
// leave excess tokens in the validator
// however fully use all the delegator shares
issuedTokens = v.DelegatorShareExRate().Mul(delShares)
v.Tokens = v.Tokens.Sub(issuedTokens)
if v.Tokens.LTE(sdk.ZeroDec()) {
panic("attempting to remove more tokens than available in validator")
}
}
v.DelegatorShares = remainingShares
if v.Status == sdk.Bonded {
pool = pool.bondedTokensToLoose(issuedTokens)
}
Expand Down