From 565c5d7a363fafab47fe7776fe713d5b07433f4a Mon Sep 17 00:00:00 2001 From: NeOMakinG <14963751+NeOMakinG@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:44:10 +0200 Subject: [PATCH 1/3] fix: fiat amount lps gas fee maths --- .../RemoveLiquidity/RemoveLiquidityInput.tsx | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx b/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx index e22c1232665..4f66daa7b5e 100644 --- a/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx +++ b/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx @@ -449,9 +449,28 @@ export const RemoveLiquidityInput: React.FC = ({ [estimatedPoolAssetFeesData?.txFeeCryptoBaseUnit, poolAssetFeeAsset?.precision], ) + const poolAssetFeeAssetDustAmountCryptoPrecision = useMemo(() => { + if (!poolAssetFeeAsset) return 0 + + return fromBaseUnit(poolAssetFeeAssetDustAmountCryptoBaseUnit, poolAssetFeeAsset?.precision) + }, [poolAssetFeeAssetDustAmountCryptoBaseUnit, poolAssetFeeAsset]) + + const poolAssetFeeAssetDustAmountFiatUserCurrency = useMemo(() => { + return bnOrZero(poolAssetFeeAssetDustAmountCryptoPrecision).times( + poolAssetFeeAssetMarketData.price, + ) + }, [poolAssetFeeAssetMarketData.price, poolAssetFeeAssetDustAmountCryptoPrecision]) + const poolAssetGasFeeFiatUserCurrency = useMemo( - () => bnOrZero(poolAssetTxFeeCryptoPrecision).times(poolAssetFeeAssetMarketData.price), - [poolAssetFeeAssetMarketData.price, poolAssetTxFeeCryptoPrecision], + () => + bnOrZero(poolAssetTxFeeCryptoPrecision) + .times(poolAssetFeeAssetMarketData.price) + .plus(poolAssetFeeAssetDustAmountFiatUserCurrency), + [ + poolAssetFeeAssetMarketData.price, + poolAssetTxFeeCryptoPrecision, + poolAssetFeeAssetDustAmountFiatUserCurrency, + ], ) const runeProtocolFeeCryptoPrecision = useMemo(() => { @@ -842,11 +861,6 @@ export const RemoveLiquidityInput: React.FC = ({ poolAssetFeeAsset?.precision, ) - const poolAssetFeeAssetDustAmountCryptoPrecision = fromBaseUnit( - poolAssetFeeAssetDustAmountCryptoBaseUnit, - poolAssetFeeAsset?.precision, - ) - return bnOrZero(poolAssetTxFeeCryptoPrecision) .plus(poolAssetFeeAssetDustAmountCryptoPrecision) .lte(poolAssetFeeAssetBalanceCryptoPrecision) @@ -855,8 +869,8 @@ export const RemoveLiquidityInput: React.FC = ({ withdrawType, poolAssetFeeAsset, poolAssetFeeAssetBalanceCryptoBaseUnit, - poolAssetFeeAssetDustAmountCryptoBaseUnit, poolAssetTxFeeCryptoPrecision, + poolAssetFeeAssetDustAmountCryptoPrecision, ]) const hasEnoughRuneBalanceForTx = useMemo(() => { From 6da3b4d8b8b9161dfb6498096c7c072b68c722a4 Mon Sep 17 00:00:00 2001 From: NeOMakinG <14963751+NeOMakinG@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:53:33 +0200 Subject: [PATCH 2/3] fix: add a comment for the dust and gas fee maths --- .../components/RemoveLiquidity/RemoveLiquidityInput.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx b/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx index 4f66daa7b5e..294452deee4 100644 --- a/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx +++ b/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx @@ -461,6 +461,7 @@ export const RemoveLiquidityInput: React.FC = ({ ) }, [poolAssetFeeAssetMarketData.price, poolAssetFeeAssetDustAmountCryptoPrecision]) + // We also include the dust amount in the gas fee as it's deducted in the input validation const poolAssetGasFeeFiatUserCurrency = useMemo( () => bnOrZero(poolAssetTxFeeCryptoPrecision) From d4e8386331dfb31e9b76b4e366b394e73bde9b2e Mon Sep 17 00:00:00 2001 From: NeOMakinG <14963751+NeOMakinG@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:54:16 +0200 Subject: [PATCH 3/3] fix: add a comment for the dust and gas fee maths --- .../components/RemoveLiquidity/RemoveLiquidityInput.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx b/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx index 294452deee4..95302aa7966 100644 --- a/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx +++ b/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx @@ -462,6 +462,7 @@ export const RemoveLiquidityInput: React.FC = ({ }, [poolAssetFeeAssetMarketData.price, poolAssetFeeAssetDustAmountCryptoPrecision]) // We also include the dust amount in the gas fee as it's deducted in the input validation + // This will result in displaying gas fees and dust amounts as a single value in the UI const poolAssetGasFeeFiatUserCurrency = useMemo( () => bnOrZero(poolAssetTxFeeCryptoPrecision)