From fbc7fc488c6441967e4654c4270dd2287c1400d4 Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:47:04 -0700 Subject: [PATCH] fix: use fee asset for dust amount conversion --- .../Withdraw/components/Confirm.tsx | 5 ++--- src/lib/utils/thorchain/balance.ts | 8 +++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Withdraw/components/Confirm.tsx b/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Withdraw/components/Confirm.tsx index 20a9157faef..9384ae54a9b 100644 --- a/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Withdraw/components/Confirm.tsx +++ b/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Withdraw/components/Confirm.tsx @@ -221,9 +221,7 @@ export const Confirm: React.FC = ({ accountId, onNext }) => { toBaseUnit(fromThorBaseUnit(protocolFeeCryptoThorBaseUnit), asset.precision), ) setDustAmountCryptoBaseUnit( - bnOrZero(toBaseUnit(fromThorBaseUnit(dust_amount), asset.precision)).toFixed( - asset.precision, - ), + bnOrZero(toBaseUnit(fromThorBaseUnit(dust_amount), feeAsset.precision)).toFixed(), ) const percentage = bnOrZero(slippage_bps).div(BASE_BPS_POINTS).times(100) // total downside (slippage going into position) - 0.007 ETH for 5 ETH deposit @@ -241,6 +239,7 @@ export const Confirm: React.FC = ({ accountId, onNext }) => { accountId, asset, dustAmountCryptoBaseUnit, + feeAsset, opportunity?.apy, opportunityData?.rewardsCryptoBaseUnit, opportunityData?.stakedAmountCryptoBaseUnit, diff --git a/src/lib/utils/thorchain/balance.ts b/src/lib/utils/thorchain/balance.ts index 1b0a354101f..1aa7389788e 100644 --- a/src/lib/utils/thorchain/balance.ts +++ b/src/lib/utils/thorchain/balance.ts @@ -139,13 +139,19 @@ export const fetchHasEnoughBalanceForTxPlusFeesPlusSweep = async ({ throw new Error('Invalid type') } })() + const amountCryptoPrecision = type === 'deposit' ? _amountCryptoPrecision : fromThorBaseUnit( (quote as ThorchainSaversWithdrawQuoteResponseSuccess).dust_amount, ).toFixed() - const amountCryptoBaseUnit = toBaseUnit(amountCryptoPrecision, asset.precision) + + const amountCryptoBaseUnit = toBaseUnit( + amountCryptoPrecision, + type === 'deposit' ? asset.precision : feeAsset?.precision ?? 0, + ) + const estimatedFeesQueryArgs = { estimateFeesInput: { amountCryptoPrecision,