Commit fb998706 authored by clrdo's avatar clrdo Committed by GitHub

fix: swaps with native currency destination in BNB Chain (#6705)

fix: swaps with native currency destination in BNB Chain
Co-authored-by: default avatarclrdo <clrdo@github.com>
parent c45492c8
...@@ -489,7 +489,7 @@ function getCeloNativeCurrency(chainId: number) { ...@@ -489,7 +489,7 @@ function getCeloNativeCurrency(chainId: number) {
} }
} }
function isMatic(chainId: number): chainId is SupportedChainId.POLYGON | SupportedChainId.POLYGON_MUMBAI { export function isMatic(chainId: number): chainId is SupportedChainId.POLYGON | SupportedChainId.POLYGON_MUMBAI {
return chainId === SupportedChainId.POLYGON_MUMBAI || chainId === SupportedChainId.POLYGON return chainId === SupportedChainId.POLYGON_MUMBAI || chainId === SupportedChainId.POLYGON
} }
...@@ -511,7 +511,7 @@ class MaticNativeCurrency extends NativeCurrency { ...@@ -511,7 +511,7 @@ class MaticNativeCurrency extends NativeCurrency {
} }
} }
function isBsc(chainId: number): chainId is SupportedChainId.BNB { export function isBsc(chainId: number): chainId is SupportedChainId.BNB {
return chainId === SupportedChainId.BNB return chainId === SupportedChainId.BNB
} }
......
...@@ -145,8 +145,10 @@ export enum PoolType { ...@@ -145,8 +145,10 @@ export enum PoolType {
} }
// swap router API special cases these strings to represent native currencies // swap router API special cases these strings to represent native currencies
// all chains have "ETH" as native currency symbol except for polygon // all chains except for bnb chain and polygon
// have "ETH" as native currency symbol
export enum SwapRouterNativeAssets { export enum SwapRouterNativeAssets {
MATIC = 'MATIC', MATIC = 'MATIC',
BNB = 'BNB',
ETH = 'ETH', ETH = 'ETH',
} }
...@@ -3,9 +3,8 @@ import { Currency, CurrencyAmount, Token, TradeType } from '@uniswap/sdk-core' ...@@ -3,9 +3,8 @@ import { Currency, CurrencyAmount, Token, TradeType } from '@uniswap/sdk-core'
import { AlphaRouter, ChainId } from '@uniswap/smart-order-router' import { AlphaRouter, ChainId } from '@uniswap/smart-order-router'
import { Pair, Route as V2Route } from '@uniswap/v2-sdk' import { Pair, Route as V2Route } from '@uniswap/v2-sdk'
import { FeeAmount, Pool, Route as V3Route } from '@uniswap/v3-sdk' import { FeeAmount, Pool, Route as V3Route } from '@uniswap/v3-sdk'
import { isPolygonChain } from 'constants/chains'
import { RPC_PROVIDERS } from 'constants/providers' import { RPC_PROVIDERS } from 'constants/providers'
import { nativeOnChain } from 'constants/tokens' import { isBsc, isMatic, nativeOnChain } from 'constants/tokens'
import { toSupportedChainId } from 'lib/hooks/routing/clientSideSmartOrderRouter' import { toSupportedChainId } from 'lib/hooks/routing/clientSideSmartOrderRouter'
import { GetQuoteArgs, INTERNAL_ROUTER_PREFERENCE_PRICE, RouterPreference } from './slice' import { GetQuoteArgs, INTERNAL_ROUTER_PREFERENCE_PRICE, RouterPreference } from './slice'
...@@ -180,7 +179,9 @@ export function isExactInput(tradeType: TradeType): boolean { ...@@ -180,7 +179,9 @@ export function isExactInput(tradeType: TradeType): boolean {
export function currencyAddressForSwapQuote(currency: Currency): string { export function currencyAddressForSwapQuote(currency: Currency): string {
if (currency.isNative) { if (currency.isNative) {
return isPolygonChain(currency.chainId) ? SwapRouterNativeAssets.MATIC : SwapRouterNativeAssets.ETH if (isMatic(currency.chainId)) return SwapRouterNativeAssets.MATIC
if (isBsc(currency.chainId)) return SwapRouterNativeAssets.BNB
return SwapRouterNativeAssets.ETH
} }
return currency.address return currency.address
......
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