fix usdc unstake amount

This commit is contained in:
saml33 2024-03-15 21:38:55 +11:00
parent 6c207a02b6
commit 97fff7707c
1 changed files with 8 additions and 4 deletions

View File

@ -104,16 +104,20 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
const stakeBankAmount =
mangoAccount && stakeBank && mangoAccount.getTokenBalance(stakeBank)
const borrowAmount =
const borrowBankAmount =
mangoAccount && borrowBank && mangoAccount.getTokenBalance(borrowBank)
const leverage = useMemo(() => {
try {
if (stakeBankAmount && borrowAmount) {
if (
stakeBankAmount &&
borrowBankAmount &&
borrowBankAmount.toNumber() < 0
) {
const lev = stakeBankAmount
.div(
stakeBankAmount.sub(
borrowAmount.abs().div(stakeBank.getAssetPrice()),
borrowBankAmount.abs().div(stakeBank.getAssetPrice()),
),
)
.toNumber()
@ -125,7 +129,7 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
console.log(e)
return 1
}
}, [stakeBankAmount, borrowAmount, stakeBank])
}, [stakeBankAmount, borrowBankAmount, stakeBank])
const tokenMax = useMemo(() => {
if (!stakeBank || !mangoAccount) return { maxAmount: 0.0, maxDecimals: 6 }