From 50e9f39b7600d418026d83f1c3bd533a7bbb9fc9 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Mon, 22 Aug 2022 20:09:31 +0200 Subject: [PATCH] fix Signed-off-by: microwavedcola1 --- ts/client/src/accounts/mangoAccount.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ts/client/src/accounts/mangoAccount.ts b/ts/client/src/accounts/mangoAccount.ts index feeea2373..ae0a8e96b 100644 --- a/ts/client/src/accounts/mangoAccount.ts +++ b/ts/client/src/accounts/mangoAccount.ts @@ -248,19 +248,25 @@ export class MangoAccount { getMaxWithdrawWithBorrowForToken(group: Group, mintPk: PublicKey): I80F48 { const bank: Bank = group.getFirstBankByMint(mintPk); const initHealth = (this.accountData as MangoAccountData).initHealth; + if (initHealth.lte(ZERO_I80F48)) { + return ZERO_I80F48; + } + const maxBorrowNative = MangoAccount.getEquivalentTokenPosition( bank, initHealth.div(bank.initLiabWeight), ); - const maxBorrowNativeWithoutFees = maxBorrowNative.div( + const maxBorrowNativeMinusFees = maxBorrowNative.div( ONE_I80F48.add(bank.loanOriginationFeeRate), ); + // console.log(`initHealth ${initHealth.toNumber()}`); // console.log(`maxBorrowNative ${maxBorrowNative.toNumber()}`); // console.log( // `maxBorrowNativeWithoutFees ${maxBorrowNativeWithoutFees.toNumber()}`, // ); - return maxBorrowNativeWithoutFees; + + return maxBorrowNativeMinusFees; } getMaxWithdrawWithBorrowForTokenUi(group: Group, mintPk: PublicKey): number {