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: fiat amount lps gas fee maths #7787

Merged
merged 4 commits into from
Sep 24, 2024
Merged
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 @@ -449,9 +449,30 @@ export const RemoveLiquidityInput: React.FC<RemoveLiquidityInputProps> = ({
[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])

// 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(
NeOMakinG marked this conversation as resolved.
Show resolved Hide resolved
() => bnOrZero(poolAssetTxFeeCryptoPrecision).times(poolAssetFeeAssetMarketData.price),
[poolAssetFeeAssetMarketData.price, poolAssetTxFeeCryptoPrecision],
() =>
bnOrZero(poolAssetTxFeeCryptoPrecision)
.times(poolAssetFeeAssetMarketData.price)
.plus(poolAssetFeeAssetDustAmountFiatUserCurrency),
[
poolAssetFeeAssetMarketData.price,
poolAssetTxFeeCryptoPrecision,
poolAssetFeeAssetDustAmountFiatUserCurrency,
],
)

const runeProtocolFeeCryptoPrecision = useMemo(() => {
Expand Down Expand Up @@ -842,11 +863,6 @@ export const RemoveLiquidityInput: React.FC<RemoveLiquidityInputProps> = ({
poolAssetFeeAsset?.precision,
)

const poolAssetFeeAssetDustAmountCryptoPrecision = fromBaseUnit(
poolAssetFeeAssetDustAmountCryptoBaseUnit,
poolAssetFeeAsset?.precision,
)

return bnOrZero(poolAssetTxFeeCryptoPrecision)
.plus(poolAssetFeeAssetDustAmountCryptoPrecision)
.lte(poolAssetFeeAssetBalanceCryptoPrecision)
Expand All @@ -855,8 +871,8 @@ export const RemoveLiquidityInput: React.FC<RemoveLiquidityInputProps> = ({
withdrawType,
poolAssetFeeAsset,
poolAssetFeeAssetBalanceCryptoBaseUnit,
poolAssetFeeAssetDustAmountCryptoBaseUnit,
poolAssetTxFeeCryptoPrecision,
poolAssetFeeAssetDustAmountCryptoPrecision,
])

const hasEnoughRuneBalanceForTx = useMemo(() => {
Expand Down
Loading