fix for simHealthWithTokenPositionChanges
needs to keep track of health changes in the loop
This commit is contained in:
parent
4507a6a72a
commit
ac0155b79d
|
@ -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),
|
||||||
|
|
Loading…
Reference in New Issue