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 // 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. // the change is in direction e.g. deposits for deposits, borrows for borrows, of existing token position.
// TODO: recompute entire health using components. // 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) { for (const change of tokenChanges) {
const bank = group.banksMap.get(change.tokenName); const bank = group.banksMap.get(change.tokenName);
if (change.tokenAmount >= 0) { if (change.tokenAmount >= 0) {
initHealth.add( initHealth = initHealth.add(
bank.initAssetWeight bank.initAssetWeight
.mul(I80F48.fromNumber(change.tokenAmount)) .mul(I80F48.fromNumber(change.tokenAmount))
.mul(bank.price), .mul(bank.price),
); );
} else { } else {
initHealth.sub( initHealth = initHealth.sub(
bank.initLiabWeight bank.initLiabWeight
.mul(I80F48.fromNumber(change.tokenAmount)) .mul(I80F48.fromNumber(change.tokenAmount))
.mul(bank.price), .mul(bank.price),