Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: savers consistent withdraw dust amount #7780

Merged
merged 6 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
kaladinlight marked this conversation as resolved.
Show resolved Hide resolved
: 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
Loading