fix: increase Polygon auto-slippage min (#4327)
* fix: increase Polygon auto-slippage min * comment * update percent
This commit is contained in:
parent
8dbc91ee6b
commit
fe55c7ae7a
@ -1,7 +1,7 @@
|
|||||||
import { Protocol, Trade } from '@uniswap/router-sdk'
|
import { Protocol, Trade } from '@uniswap/router-sdk'
|
||||||
import { Currency, CurrencyAmount, Percent, TradeType } from '@uniswap/sdk-core'
|
import { Currency, CurrencyAmount, Percent, TradeType } from '@uniswap/sdk-core'
|
||||||
import { useWeb3React } from '@web3-react/core'
|
import { useWeb3React } from '@web3-react/core'
|
||||||
import { SUPPORTED_GAS_ESTIMATE_CHAIN_IDS } from 'constants/chains'
|
import { SUPPORTED_GAS_ESTIMATE_CHAIN_IDS, SupportedChainId } from 'constants/chains'
|
||||||
import { L2_CHAIN_IDS } from 'constants/chains'
|
import { L2_CHAIN_IDS } from 'constants/chains'
|
||||||
import JSBI from 'jsbi'
|
import JSBI from 'jsbi'
|
||||||
import useNativeCurrency from 'lib/hooks/useNativeCurrency'
|
import useNativeCurrency from 'lib/hooks/useNativeCurrency'
|
||||||
@ -54,6 +54,7 @@ function guesstimateGas(trade: Trade<Currency, Currency, TradeType> | undefined)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const MIN_AUTO_SLIPPAGE_TOLERANCE = new Percent(5, 1000) // 0.5%
|
const MIN_AUTO_SLIPPAGE_TOLERANCE = new Percent(5, 1000) // 0.5%
|
||||||
|
const POLYGON_MIN_AUTO_SLIPPAGE_TOLERANCE = new Percent(1, 100) // 1%
|
||||||
const MAX_AUTO_SLIPPAGE_TOLERANCE = new Percent(25, 100) // 25%
|
const MAX_AUTO_SLIPPAGE_TOLERANCE = new Percent(25, 100) // 25%
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,8 +97,19 @@ export default function useAutoSlippageTolerance(
|
|||||||
// the cost of the gas of the failed transaction
|
// the cost of the gas of the failed transaction
|
||||||
const fraction = dollarCostToUse.asFraction.divide(outputDollarValue.asFraction)
|
const fraction = dollarCostToUse.asFraction.divide(outputDollarValue.asFraction)
|
||||||
const result = new Percent(fraction.numerator, fraction.denominator)
|
const result = new Percent(fraction.numerator, fraction.denominator)
|
||||||
if (result.greaterThan(MAX_AUTO_SLIPPAGE_TOLERANCE)) return MAX_AUTO_SLIPPAGE_TOLERANCE
|
if (result.greaterThan(MAX_AUTO_SLIPPAGE_TOLERANCE)) {
|
||||||
if (result.lessThan(MIN_AUTO_SLIPPAGE_TOLERANCE)) return MIN_AUTO_SLIPPAGE_TOLERANCE
|
return MAX_AUTO_SLIPPAGE_TOLERANCE
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(vm): Added because ~30% of Polygon swaps were failing due to exceeding slippage.
|
||||||
|
// The root cause is likely elsewhere, but added for now to reduce failure rate on production.
|
||||||
|
const isPolygon = chainId && [SupportedChainId.POLYGON, SupportedChainId.POLYGON_MUMBAI].includes(chainId)
|
||||||
|
const minAutoSlippageTolerance = isPolygon ? POLYGON_MIN_AUTO_SLIPPAGE_TOLERANCE : MIN_AUTO_SLIPPAGE_TOLERANCE
|
||||||
|
|
||||||
|
if (result.lessThan(minAutoSlippageTolerance)) {
|
||||||
|
return minAutoSlippageTolerance
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user