Skip to content

Commit

Permalink
fix: savers consistent withdraw dust amount (#7780)
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre authored Sep 20, 2024
1 parent 3c1db22 commit 2b679a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {
action: isRunePool ? 'withdrawRunepool' : 'withdrawSavers',
memo,
fromAddress,
dustAmountCryptoBaseUnit,
})

const estimatedGasCryptoPrecision = useMemo(() => {
Expand Down
13 changes: 10 additions & 3 deletions src/lib/utils/thorchain/hooks/useSendThorTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type UseSendThorTxProps = {
disableEstimateFeesRefetch?: boolean
fromAddress: string | null
memo: string | null
dustAmountCryptoBaseUnit?: string
}

export const useSendThorTx = ({
Expand All @@ -77,6 +78,7 @@ export const useSendThorTx = ({
disableEstimateFeesRefetch,
fromAddress,
memo: _memo,
dustAmountCryptoBaseUnit: _dustAmountCryptoBaseUnit,
}: UseSendThorTxProps) => {
const [txId, setTxId] = useState<string | null>(null)
const [serializedTxIndex, setSerializedTxIndex] = useState<string | null>(null)
Expand All @@ -100,13 +102,18 @@ export const useSendThorTx = ({
return ['withdrawLiquidity', 'withdrawSavers'].includes(action)
}, [action])

// Either a fall through of the passed dustAmountCryptoBaseUnit, or the default dust amount for that feeAsset
// @TODO: test this with RUNEPool, might not work properly due to mapping for LPs
const dustAmountCryptoBaseUnit = useMemo(() => {
return THORCHAIN_SAVERS_DUST_THRESHOLDS_CRYPTO_BASE_UNIT[feeAsset?.assetId ?? ''] ?? '0'
}, [feeAsset])
return _dustAmountCryptoBaseUnit
? _dustAmountCryptoBaseUnit
: THORCHAIN_SAVERS_DUST_THRESHOLDS_CRYPTO_BASE_UNIT[feeAsset?.assetId ?? ''] ?? '0'
}, [_dustAmountCryptoBaseUnit, feeAsset?.assetId])

const amountOrDustCryptoBaseUnit = useMemo(() => {
return shouldUseDustAmount ? dustAmountCryptoBaseUnit : bnOrZero(amountCryptoBaseUnit).toFixed()
return shouldUseDustAmount
? bnOrZero(dustAmountCryptoBaseUnit).toFixed(0)
: bnOrZero(amountCryptoBaseUnit).toFixed(0)
}, [shouldUseDustAmount, dustAmountCryptoBaseUnit, amountCryptoBaseUnit])

const transactionType = useMemo(() => {
Expand Down

0 comments on commit 2b679a1

Please sign in to comment.