Commit e3b3d9e8 authored by Moody Salem's avatar Moody Salem

fix(swaps): band-aid fix for gas estimates to disable multihop for eth-ampl

parent 3050e967
......@@ -4,6 +4,7 @@ import { useMemo } from 'react'
import { BASES_TO_CHECK_TRADES_AGAINST } from '../constants'
import { PairState, usePairs } from '../data/Reserves'
import { maxHopsFor } from '../utils/maxHopsFor'
import { wrappedCurrency } from '../utils/wrappedCurrency'
import { useActiveWeb3React } from './index'
......@@ -58,8 +59,9 @@ export function useTradeExactIn(currencyAmountIn?: CurrencyAmount, currencyOut?:
return useMemo(() => {
if (currencyAmountIn && currencyOut && allowedPairs.length > 0) {
const maxHops = maxHopsFor(currencyAmountIn.currency, currencyOut)
return (
Trade.bestTradeExactIn(allowedPairs, currencyAmountIn, currencyOut, { maxHops: 3, maxNumResults: 1 })[0] ?? null
Trade.bestTradeExactIn(allowedPairs, currencyAmountIn, currencyOut, { maxHops, maxNumResults: 1 })[0] ?? null
)
}
return null
......@@ -74,9 +76,9 @@ export function useTradeExactOut(currencyIn?: Currency, currencyAmountOut?: Curr
return useMemo(() => {
if (currencyIn && currencyAmountOut && allowedPairs.length > 0) {
const maxHops = maxHopsFor(currencyIn, currencyAmountOut.currency)
return (
Trade.bestTradeExactOut(allowedPairs, currencyIn, currencyAmountOut, { maxHops: 3, maxNumResults: 1 })[0] ??
null
Trade.bestTradeExactOut(allowedPairs, currencyIn, currencyAmountOut, { maxHops, maxNumResults: 1 })[0] ?? null
)
}
return null
......
import { ChainId, Currency, ETHER, Token, WETH } from '@uniswap/sdk'
function isEtherish(currency: Currency): boolean {
return currency === ETHER || (currency instanceof Token && WETH[currency.chainId].equals(currency))
}
const AMPL_TOKEN_ADDRESS = '0xD46bA6D942050d489DBd938a2C909A5d5039A161'
/**
* Band-aid on maxHops because some tokens seems to always fail with multihop swaps
* @param currencyIn currency in
* @param currencyOut currency out
*/
export function maxHopsFor(currencyIn: Currency, currencyOut: Currency): number {
if (
isEtherish(currencyIn) &&
currencyOut instanceof Token &&
currencyOut.chainId === ChainId.MAINNET &&
currencyOut.address === AMPL_TOKEN_ADDRESS
) {
return 1
} else if (
isEtherish(currencyOut) &&
currencyIn instanceof Token &&
currencyIn.chainId === ChainId.MAINNET &&
currencyIn.address === AMPL_TOKEN_ADDRESS
) {
return 1
}
return 3
}
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