From 68fa41fbec951a17f3ad7e41c238b3a841301e37 Mon Sep 17 00:00:00 2001 From: naturexie <786281870@qq.com> Date: Mon, 10 Feb 2025 15:31:18 +0800 Subject: [PATCH] fix: withdraw dust issue --- store/actions/withdraw.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/store/actions/withdraw.ts b/store/actions/withdraw.ts index 5b5a9f7b..bb9befee 100644 --- a/store/actions/withdraw.ts +++ b/store/actions/withdraw.ts @@ -47,13 +47,13 @@ export async function withdraw({ // console.log('0000000000000-accountId', accountId) // console.log('0000000000000-account', account) if (!accountId) return; - const asset = assets[tokenId]; const { decimals } = asset.metadata; const { logicContract, oracleContract } = await getBurrow(); const isNEAR = tokenId === nearTokenId; const { isLpToken } = asset; const suppliedBalance = new Decimal(accountPortfolio?.supplied[tokenId]?.balance || 0); + const hasBorrow = accountPortfolio?.borrows?.length > 0; const maxAmount = computeWithdrawMaxAmount(tokenId, assets, accountPortfolio!); const expandedAmount = isMax @@ -137,7 +137,8 @@ export async function withdraw({ { DecreaseCollateral: { token_id: tokenId, - amount: decreaseCollateralAmount.toFixed(0), + amount: + !hasBorrow && isMax ? undefined : decreaseCollateralAmount.toFixed(0), }, }, withdrawAction, @@ -151,7 +152,8 @@ export async function withdraw({ { DecreaseCollateral: { token_id: tokenId, - amount: decreaseCollateralAmount.toFixed(0), + amount: + !hasBorrow && isMax ? undefined : decreaseCollateralAmount.toFixed(0), }, }, withdrawAction,