fix negative swap max

This commit is contained in:
saml33 2023-02-10 10:26:28 +11:00
parent efdd8a8934
commit 73162e5544
1 changed files with 9 additions and 7 deletions

View File

@ -53,15 +53,17 @@ export const getTokenInMax = (
? inputTokenBalance ? inputTokenBalance
: new Decimal(0) : new Decimal(0)
const maxUiAmountWithBorrow = floorToDecimal( const rawMaxUiAmountWithBorrow = mangoAccount.getMaxSourceUiForTokenSwap(
mangoAccount.getMaxSourceUiForTokenSwap(
group, group,
inputBank.mint, inputBank.mint,
outputBank.mint outputBank.mint
),
inputBank.mintDecimals
) )
const maxUiAmountWithBorrow =
rawMaxUiAmountWithBorrow > 0
? floorToDecimal(rawMaxUiAmountWithBorrow, inputBank.mintDecimals)
: new Decimal(0)
const inputBankVaultBalance = floorToDecimal( const inputBankVaultBalance = floorToDecimal(
group group
.getTokenVaultBalanceByMintUi(inputBank.mint) .getTokenVaultBalanceByMintUi(inputBank.mint)