Skip to content

Commit

Permalink
fix: tidy up collateral balances
Browse files Browse the repository at this point in the history
  • Loading branch information
ze97286 authored and jeremyletang committed Nov 29, 2023
1 parent ef070fc commit 6bf3b53
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/collateral/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3597,6 +3597,8 @@ func (e *Engine) RemoveDistressed(ctx context.Context, parties []events.MarketPo
if err := e.UpdateBalance(ctx, bondAcc.ID, bondAcc.Balance.SetUint64(0)); err != nil {
return nil, err
}
// get an updated copy of the margin account after being topped up from bond account
marginAcc, _ = e.GetAccountByID(e.accountID(marketID, party.Party(), asset, types.AccountTypeMargin))
}
// take whatever is left on the general account, and move to margin balance
// we can take everything from the account, as whatever amount was left here didn't cover the minimum margin requirement
Expand All @@ -3617,6 +3619,8 @@ func (e *Engine) RemoveDistressed(ctx context.Context, parties []events.MarketPo
if err := e.UpdateBalance(ctx, genAcc.ID, genAcc.Balance.SetUint64(0)); err != nil {
return nil, err
}
// get an updated copy of the margin account after being topped up from general account
marginAcc, _ = e.GetAccountByID(e.accountID(marketID, party.Party(), asset, types.AccountTypeMargin))
}
// move monies from the margin account (balance is general, bond, and margin combined now)
if !marginAcc.Balance.IsZero() {
Expand Down

0 comments on commit 6bf3b53

Please sign in to comment.