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 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const Withdraw: React.FC<WithdrawProps> = ({ accountId, fromAddress, onNe
const {
estimatedFeesData,
isEstimatedFeesDataLoading,
dustAmountCryptoBaseUnit,
dustAmountCryptoBaseUnitOrDefault: dustAmountCryptoBaseUnit,
outboundFeeCryptoBaseUnit,
} = useSendThorTx({
assetId,
Expand Down
19 changes: 13 additions & 6 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 | null
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
}

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,14 +102,19 @@ 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])
const dustAmountCryptoBaseUnitOrDefault = useMemo(() => {
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
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()
}, [shouldUseDustAmount, dustAmountCryptoBaseUnit, amountCryptoBaseUnit])
return shouldUseDustAmount
? dustAmountCryptoBaseUnitOrDefault
: bnOrZero(amountCryptoBaseUnit).toFixed()
}, [shouldUseDustAmount, dustAmountCryptoBaseUnitOrDefault, amountCryptoBaseUnit])

const transactionType = useMemo(() => {
return asset ? getThorchainTransactionType(asset.chainId) : undefined
Expand Down Expand Up @@ -447,7 +454,7 @@ export const useSendThorTx = ({
isEstimatedFeesDataError,
txId,
serializedTxIndex,
dustAmountCryptoBaseUnit,
dustAmountCryptoBaseUnitOrDefault,
outboundFeeCryptoBaseUnit,
inboundAddress,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export const RemoveLiquidityInput: React.FC<RemoveLiquidityInputProps> = ({
estimatedFeesData: estimatedRuneFeesData,
isEstimatedFeesDataLoading: isEstimatedRuneFeesDataLoading,
isEstimatedFeesDataError: isEstimatedRuneFeesDataError,
dustAmountCryptoBaseUnit: runeDustAmountCryptoBaseUnit,
dustAmountCryptoBaseUnitOrDefault: runeDustAmountCryptoBaseUnit,
} = useSendThorTx({
assetId: thorchainAssetId,
accountId: positionRuneAccountId ?? null,
Expand Down Expand Up @@ -416,7 +416,7 @@ export const RemoveLiquidityInput: React.FC<RemoveLiquidityInputProps> = ({
estimatedFeesData: estimatedPoolAssetFeesData,
isEstimatedFeesDataLoading: isEstimatedPoolAssetFeesDataLoading,
isEstimatedFeesDataError: isEstimatedPoolAssetFeesDataError,
dustAmountCryptoBaseUnit: poolAssetFeeAssetDustAmountCryptoBaseUnit,
dustAmountCryptoBaseUnitOrDefault: poolAssetFeeAssetDustAmountCryptoBaseUnit,
outboundFeeCryptoBaseUnit,
} = useSendThorTx({
// Asym asset withdraws are the only ones occurring an asset Tx - both sym and asym RUNE side withdraws occur a RUNE Tx instead
Expand Down
Loading