@lifi/widget
Version:
LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.
26 lines (24 loc) • 558 B
text/typescript
export const calculateValueLossPercentage = (
fromAmountUSD: number,
toAmountUSD: number,
gasCostUSD: number,
feeCostUSD: number
) => {
return Number.parseFloat(
(
(toAmountUSD / (fromAmountUSD + gasCostUSD + feeCostUSD) - 1) *
100
).toFixed(2)
)
}
export const getTokenValueLossThreshold = (
fromAmountUSD: number,
toAmountUSD: number,
gasCostUSD: number,
feeCostUSD: number
) => {
if (!fromAmountUSD || !toAmountUSD) {
return false
}
return toAmountUSD / (fromAmountUSD + gasCostUSD + feeCostUSD) < 0.9
}