fix for simHealthWithTokenPositionChanges

needs to keep track of health changes in the loop
This commit is contained in:
tjs 2022-08-11 16:43:46 -07:00
parent 4507a6a72a
commit ac0155b79d
1 changed files with 3 additions and 3 deletions

View File

@ -258,17 +258,17 @@ export class MangoAccount {
// mango account has no token positions for tokens in changes list, or
// the change is in direction e.g. deposits for deposits, borrows for borrows, of existing token position.
// TODO: recompute entire health using components.
const initHealth = (this.accountData as MangoAccountData).initHealth;
let initHealth = (this.accountData as MangoAccountData).initHealth;
for (const change of tokenChanges) {
const bank = group.banksMap.get(change.tokenName);
if (change.tokenAmount >= 0) {
initHealth.add(
initHealth = initHealth.add(
bank.initAssetWeight
.mul(I80F48.fromNumber(change.tokenAmount))
.mul(bank.price),
);
} else {
initHealth.sub(
initHealth = initHealth.sub(
bank.initLiabWeight
.mul(I80F48.fromNumber(change.tokenAmount))
.mul(bank.price),