Commit f5b601ee authored by Moody Salem's avatar Moody Salem Committed by GitHub

fix(L2): use 10 bips slippage for swaps by default on L2 (#2035)

* use 10bip slippage on L2

* update deps
Co-authored-by: default avatarJordan Frankfurt <jordanwfrankfurt@gmail.com>
parent bf30013b
...@@ -3,6 +3,8 @@ import { Trade as V3Trade } from '@uniswap/v3-sdk' ...@@ -3,6 +3,8 @@ import { Trade as V3Trade } from '@uniswap/v3-sdk'
import { Trade as V2Trade } from '@uniswap/v2-sdk' import { Trade as V2Trade } from '@uniswap/v2-sdk'
import { useMemo } from 'react' import { useMemo } from 'react'
import { useUserSlippageToleranceWithDefault } from '../state/user/hooks' import { useUserSlippageToleranceWithDefault } from '../state/user/hooks'
import { useActiveWeb3React } from './web3'
import { L2_CHAIN_IDS } from 'constants/chains'
const V2_SWAP_DEFAULT_SLIPPAGE = new Percent(50, 10_000) // .50% const V2_SWAP_DEFAULT_SLIPPAGE = new Percent(50, 10_000) // .50%
const V3_SWAP_DEFAULT_SLIPPAGE = new Percent(50, 10_000) // .50% const V3_SWAP_DEFAULT_SLIPPAGE = new Percent(50, 10_000) // .50%
...@@ -11,10 +13,12 @@ const ONE_TENTHS_PERCENT = new Percent(10, 10_000) // .10% ...@@ -11,10 +13,12 @@ const ONE_TENTHS_PERCENT = new Percent(10, 10_000) // .10%
export default function useSwapSlippageTolerance( export default function useSwapSlippageTolerance(
trade: V2Trade<Currency, Currency, TradeType> | V3Trade<Currency, Currency, TradeType> | undefined trade: V2Trade<Currency, Currency, TradeType> | V3Trade<Currency, Currency, TradeType> | undefined
): Percent { ): Percent {
const { chainId } = useActiveWeb3React()
const onL2 = chainId && L2_CHAIN_IDS.includes(chainId)
const defaultSlippageTolerance = useMemo(() => { const defaultSlippageTolerance = useMemo(() => {
if (!trade) return ONE_TENTHS_PERCENT if (!trade || onL2) return ONE_TENTHS_PERCENT
if (trade instanceof V2Trade) return V2_SWAP_DEFAULT_SLIPPAGE if (trade instanceof V2Trade) return V2_SWAP_DEFAULT_SLIPPAGE
return V3_SWAP_DEFAULT_SLIPPAGE return V3_SWAP_DEFAULT_SLIPPAGE
}, [trade]) }, [onL2, trade])
return useUserSlippageToleranceWithDefault(defaultSlippageTolerance) return useUserSlippageToleranceWithDefault(defaultSlippageTolerance)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment