fix max withdraw value for dust amounts

This commit is contained in:
saml33 2023-10-09 15:29:26 +11:00
parent 9e82eec2f4
commit c8ea057f68
1 changed files with 7 additions and 4 deletions

View File

@ -13,11 +13,14 @@ export const getMaxWithdrawForBank = (
mangoAccount: MangoAccount,
allowBorrow = false,
): Decimal => {
const accountBalance = mangoAccount.getTokenBalanceUi(bank)
const accountBalance = floorToDecimal(
mangoAccount.getTokenBalanceUi(bank),
bank.mintDecimals,
)
const vaultBalance = group.getTokenVaultBalanceByMintUi(bank.mint)
const maxBorrow = mangoAccount.getMaxWithdrawWithBorrowForTokenUi(
group,
bank.mint,
const maxBorrow = floorToDecimal(
mangoAccount.getMaxWithdrawWithBorrowForTokenUi(group, bank.mint),
bank.mintDecimals,
)
const maxWithdraw = allowBorrow
? Decimal.min(vaultBalance, maxBorrow)