diff --git a/package.json b/package.json index 939c4dffc..ea9de7dd8 100644 --- a/package.json +++ b/package.json @@ -67,9 +67,9 @@ "@uniswap/redux-multicall": "^1.1.8", "@uniswap/router-sdk": "^1.6.0", "@uniswap/sdk-core": "^4.0.6", - "@uniswap/smart-order-router": "^3.13.7", - "@uniswap/token-lists": "^1.0.0-beta.30", - "@uniswap/universal-router-sdk": "^1.5.6", + "@uniswap/smart-order-router": "^3.15.2", + "@uniswap/token-lists": "^1.0.0-beta.33", + "@uniswap/universal-router-sdk": "^1.5.7", "@uniswap/v2-sdk": "^3.2.0", "@uniswap/v3-sdk": "^3.10.0", "@web3-react/core": "^8.2.0", @@ -166,7 +166,7 @@ "@types/wcag-contrast": "^3.0.0", "@typescript-eslint/eslint-plugin": "^5.21.0", "@typescript-eslint/parser": "^5.21.0", - "@uniswap/default-token-list": "^9.0.0", + "@uniswap/default-token-list": "^11.5.0", "@uniswap/v2-core": "1.0.0", "@uniswap/v3-core": "1.0.0", "@uniswap/v3-periphery": "^1.1.1", diff --git a/src/assets/svg/avax-logo.svg b/src/assets/svg/avax-logo.svg new file mode 100644 index 000000000..041ded0ad --- /dev/null +++ b/src/assets/svg/avax-logo.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/assets/svg/base-logo.svg b/src/assets/svg/base-logo.svg new file mode 100644 index 000000000..d0303fb15 --- /dev/null +++ b/src/assets/svg/base-logo.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/components/EtherscanLink.tsx b/src/components/EtherscanLink.tsx index 125fda563..23875d58b 100644 --- a/src/components/EtherscanLink.tsx +++ b/src/components/EtherscanLink.tsx @@ -1,5 +1,5 @@ +import { ChainId } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' -import { SupportedChainId } from 'constants/chains' import { Link } from 'icons' import { ReactNode, useMemo } from 'react' import styled from 'styled-components/macro' @@ -30,10 +30,7 @@ export default function EtherscanLink({ showIcon = true, }: EtherscanLinkProps) { const { chainId } = useWeb3React() - const url = useMemo( - () => data && getExplorerLink(chainId || SupportedChainId.MAINNET, data, type), - [chainId, data, type] - ) + const url = useMemo(() => data && getExplorerLink(chainId || ChainId.MAINNET, data, type), [chainId, data, type]) return ( diff --git a/src/components/Logo/util.ts b/src/components/Logo/util.ts index 5af2970f0..b818478b3 100644 --- a/src/components/Logo/util.ts +++ b/src/components/Logo/util.ts @@ -1,4 +1,4 @@ -import { SupportedChainId } from 'constants/chains' +import { ChainId } from '@uniswap/sdk-core' import { isAddress } from 'utils' import EthereumLogo from '../../assets/images/ethereum-logo.png' @@ -9,19 +9,19 @@ import { LogoTableInput } from './LogoTable' type Network = 'ethereum' | 'arbitrum' | 'optimism' | 'polygon' | 'celo' | 'smartchain' -function chainIdToNetworkName(networkId: SupportedChainId): Network | undefined { +function chainIdToNetworkName(networkId: ChainId): Network | undefined { switch (networkId) { - case SupportedChainId.MAINNET: + case ChainId.MAINNET: return 'ethereum' - case SupportedChainId.ARBITRUM_ONE: + case ChainId.ARBITRUM_ONE: return 'arbitrum' - case SupportedChainId.OPTIMISM: + case ChainId.OPTIMISM: return 'optimism' - case SupportedChainId.POLYGON: + case ChainId.POLYGON: return 'polygon' - case SupportedChainId.CELO: + case ChainId.CELO: return 'celo' - case SupportedChainId.BNB: + case ChainId.BNB: return 'smartchain' default: return 'ethereum' @@ -41,15 +41,15 @@ export function getAssetsRepoURI(asset: LogoTableInput): string | undefined { : undefined } -export function getNativeLogoURI(chainId: SupportedChainId = SupportedChainId.MAINNET): string { +export function getNativeLogoURI(chainId: ChainId = ChainId.MAINNET): string { switch (chainId) { - case SupportedChainId.POLYGON: - case SupportedChainId.POLYGON_MUMBAI: + case ChainId.POLYGON: + case ChainId.POLYGON_MUMBAI: return MaticLogo - case SupportedChainId.CELO: - case SupportedChainId.CELO_ALFAJORES: + case ChainId.CELO: + case ChainId.CELO_ALFAJORES: return CeloLogo - case SupportedChainId.BNB: + case ChainId.BNB: return BnbLogo default: return EthereumLogo diff --git a/src/components/Swap/SwapActionButton/index.tsx b/src/components/Swap/SwapActionButton/index.tsx index f7a6b8e73..1be6e87f0 100644 --- a/src/components/Swap/SwapActionButton/index.tsx +++ b/src/components/Swap/SwapActionButton/index.tsx @@ -1,6 +1,6 @@ +import { ChainId } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' import { isSupportedChainId } from 'constants/chainInfo' -import { SupportedChainId } from 'constants/chains' import { ChainError, useSwapInfo } from 'hooks/swap' import { SwapApprovalState } from 'hooks/swap/useSwapApproval' import { useIsWrap } from 'hooks/swap/useWrapCallback' @@ -39,7 +39,7 @@ export default function SwapActionButton() { return } else if (error === ChainError.MISMATCHED_CHAINS || error === ChainError.UNSUPPORTED_CHAIN) { const tokenChainId = inputCurrency?.chainId ?? outputCurrency?.chainId - const supportedTokenChainId = isSupportedChainId(tokenChainId) ? tokenChainId : SupportedChainId.MAINNET + const supportedTokenChainId = isSupportedChainId(tokenChainId) ? tokenChainId : ChainId.MAINNET return } else if (isWrap) { return diff --git a/src/constants/addresses.ts b/src/constants/addresses.ts index 2fadaf17f..e9db8c392 100644 --- a/src/constants/addresses.ts +++ b/src/constants/addresses.ts @@ -1,4 +1,4 @@ -import { SupportedChainId } from 'constants/chains' +import { ChainId } from '@uniswap/sdk-core' import { constructSameAddressMap } from 'utils/constructSameAddressMap' type AddressMap = { [chainId: number]: string } @@ -7,37 +7,33 @@ export const UNI_ADDRESS: AddressMap = constructSameAddressMap('0x1f9840a85d5aF5 export const MULTICALL_ADDRESS: AddressMap = { ...constructSameAddressMap('0x1F98415757620B543A52E61c46B32eB19261F984', [ - SupportedChainId.OPTIMISM_GOERLI, - SupportedChainId.OPTIMISM, - SupportedChainId.POLYGON_MUMBAI, - SupportedChainId.POLYGON, + ChainId.OPTIMISM_GOERLI, + ChainId.OPTIMISM, + ChainId.POLYGON_MUMBAI, + ChainId.POLYGON, ]), - [SupportedChainId.ARBITRUM_ONE]: '0xadF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB', - [SupportedChainId.ARBITRUM_RINKEBY]: '0xa501c031958F579dB7676fF1CE78AD305794d579', - [SupportedChainId.CELO]: '0x633987602DE5C4F337e3DbF265303A1080324204', - [SupportedChainId.CELO_ALFAJORES]: '0x633987602DE5C4F337e3DbF265303A1080324204', + [ChainId.ARBITRUM_ONE]: '0xadF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB', + [ChainId.CELO]: '0x633987602DE5C4F337e3DbF265303A1080324204', + [ChainId.CELO_ALFAJORES]: '0x633987602DE5C4F337e3DbF265303A1080324204', } export const SWAP_ROUTER_ADDRESSES: AddressMap = { ...constructSameAddressMap('0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45', [ - SupportedChainId.OPTIMISM, - SupportedChainId.OPTIMISM_GOERLI, - SupportedChainId.ARBITRUM_ONE, - SupportedChainId.ARBITRUM_RINKEBY, - SupportedChainId.POLYGON, - SupportedChainId.POLYGON_MUMBAI, + ChainId.OPTIMISM, + ChainId.OPTIMISM_GOERLI, + ChainId.ARBITRUM_ONE, + ChainId.POLYGON, + ChainId.POLYGON_MUMBAI, ]), - [SupportedChainId.CELO]: '0x5615CDAb10dc425a742d643d949a7F474C01abc4', - [SupportedChainId.CELO_ALFAJORES]: '0x5615CDAb10dc425a742d643d949a7F474C01abc4', + [ChainId.CELO]: '0x5615CDAb10dc425a742d643d949a7F474C01abc4', + [ChainId.CELO_ALFAJORES]: '0x5615CDAb10dc425a742d643d949a7F474C01abc4', } export const ARGENT_WALLET_DETECTOR_ADDRESS: AddressMap = { - [SupportedChainId.MAINNET]: '0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8', + [ChainId.MAINNET]: '0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8', } export const ENS_REGISTRAR_ADDRESSES: AddressMap = { - [SupportedChainId.MAINNET]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', - [SupportedChainId.ROPSTEN]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', - [SupportedChainId.GOERLI]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', - [SupportedChainId.RINKEBY]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', + [ChainId.MAINNET]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', + [ChainId.GOERLI]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', } diff --git a/src/constants/chainInfo.ts b/src/constants/chainInfo.ts index d98069641..72e60324f 100644 --- a/src/constants/chainInfo.ts +++ b/src/constants/chainInfo.ts @@ -1,12 +1,15 @@ +import { ChainId } from '@uniswap/sdk-core' import ethereumLogoUrl from 'assets/images/ethereum-logo.png' import arbitrumLogoUrl from 'assets/svg/arbitrum_logo.svg' +import avaxLogo from 'assets/svg/avax-logo.svg' +import baseLogo from 'assets/svg/base-logo.svg' import bnbLogo from 'assets/svg/bnb-logo.svg' import celoLogo from 'assets/svg/celo_logo.svg' import optimismLogoUrl from 'assets/svg/optimism_logo.svg' import polygonMaticLogo from 'assets/svg/polygon-matic-logo.svg' import ms from 'ms.macro' -import { SupportedChainId, SupportedL1ChainId, SupportedL2ChainId } from './chains' +import { SupportedL1ChainId, SupportedL2ChainId } from './chains' export const STANDARD_L1_BLOCK_TIME = ms`12s` @@ -59,7 +62,7 @@ export type ChainInfoMap = { readonly [chainId: number]: L1ChainInfo | L2ChainIn { readonly [chainId in SupportedL1ChainId]: L1ChainInfo } const CHAIN_INFO: ChainInfoMap = { - [SupportedChainId.MAINNET]: { + [ChainId.MAINNET]: { networkType: NetworkType.L1, docs: 'https://docs.uniswap.org/', explorer: 'https://etherscan.io/', @@ -69,37 +72,7 @@ const CHAIN_INFO: ChainInfoMap = { nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, color: '#627EEA', }, - [SupportedChainId.RINKEBY]: { - networkType: NetworkType.L1, - docs: 'https://docs.uniswap.org/', - explorer: 'https://rinkeby.etherscan.io/', - infoLink: 'https://info.uniswap.org/#/', - label: 'Rinkeby', - logoUrl: ethereumLogoUrl, - nativeCurrency: { name: 'Rinkeby Ether', symbol: 'rETH', decimals: 18 }, - color: '#FB118E', - }, - [SupportedChainId.ROPSTEN]: { - networkType: NetworkType.L1, - docs: 'https://docs.uniswap.org/', - explorer: 'https://ropsten.etherscan.io/', - infoLink: 'https://info.uniswap.org/#/', - label: 'Ropsten', - logoUrl: ethereumLogoUrl, - nativeCurrency: { name: 'Ropsten Ether', symbol: 'ropETH', decimals: 18 }, - color: '#A08116', - }, - [SupportedChainId.KOVAN]: { - networkType: NetworkType.L1, - docs: 'https://docs.uniswap.org/', - explorer: 'https://kovan.etherscan.io/', - infoLink: 'https://info.uniswap.org/#/', - label: 'Kovan', - logoUrl: ethereumLogoUrl, - nativeCurrency: { name: 'Kovan Ether', symbol: 'kovETH', decimals: 18 }, - color: '#FF0420', - }, - [SupportedChainId.GOERLI]: { + [ChainId.GOERLI]: { networkType: NetworkType.L1, docs: 'https://docs.uniswap.org/', explorer: 'https://goerli.etherscan.io/', @@ -109,7 +82,7 @@ const CHAIN_INFO: ChainInfoMap = { nativeCurrency: { name: 'Görli Ether', symbol: 'görETH', decimals: 18 }, color: '#209853', }, - [SupportedChainId.OPTIMISM]: { + [ChainId.OPTIMISM]: { networkType: NetworkType.L2, blockWaitMsBeforeWarning: ms`25m`, bridge: 'https://app.optimism.io/bridge', @@ -124,7 +97,7 @@ const CHAIN_INFO: ChainInfoMap = { color: '#FF0420', backgroundColor: '#ff042029', }, - [SupportedChainId.OPTIMISM_GOERLI]: { + [ChainId.OPTIMISM_GOERLI]: { networkType: NetworkType.L2, blockWaitMsBeforeWarning: ms`25m`, bridge: 'https://app.optimism.io/bridge', @@ -140,7 +113,7 @@ const CHAIN_INFO: ChainInfoMap = { color: '#FF0420', backgroundColor: '#ff042029', }, - [SupportedChainId.ARBITRUM_ONE]: { + [ChainId.ARBITRUM_ONE]: { networkType: NetworkType.L2, blockWaitMsBeforeWarning: ms`10m`, bridge: 'https://bridge.arbitrum.io/', @@ -154,21 +127,7 @@ const CHAIN_INFO: ChainInfoMap = { color: '#28A0F0', backgroundColor: '#28a0f029', }, - [SupportedChainId.ARBITRUM_RINKEBY]: { - networkType: NetworkType.L2, - blockWaitMsBeforeWarning: ms`10m`, - bridge: 'https://bridge.arbitrum.io/', - docs: 'https://offchainlabs.com/', - explorer: 'https://rinkeby-explorer.arbitrum.io/', - infoLink: 'https://info.uniswap.org/#/arbitrum/', - label: 'Arbitrum Rinkeby', - logoUrl: arbitrumLogoUrl, - helpCenterUrl: 'https://help.uniswap.org/en/collections/3137787-uniswap-on-arbitrum', - nativeCurrency: { name: 'Rinkeby Arbitrum Ether', symbol: 'rinkArbETH', decimals: 18 }, - color: '#28A0F0', - backgroundColor: '#28a0f029', - }, - [SupportedChainId.POLYGON]: { + [ChainId.POLYGON]: { networkType: NetworkType.L1, blockWaitMsBeforeWarning: ms`10m`, bridge: 'https://wallet.polygon.technology/login?redirectTo=%2Fpolygon%2Fbridge', @@ -182,7 +141,7 @@ const CHAIN_INFO: ChainInfoMap = { color: '#A457FF', backgroundColor: '#a457ff29', }, - [SupportedChainId.POLYGON_MUMBAI]: { + [ChainId.POLYGON_MUMBAI]: { networkType: NetworkType.L1, blockWaitMsBeforeWarning: ms`10m`, bridge: 'https://wallet.polygon.technology/login?redirectTo=%2Fpolygon%2Fbridge', @@ -196,7 +155,7 @@ const CHAIN_INFO: ChainInfoMap = { color: '#A457FF', backgroundColor: '#a457ff29', }, - [SupportedChainId.CELO]: { + [ChainId.CELO]: { networkType: NetworkType.L1, blockWaitMsBeforeWarning: ms`10m`, bridge: 'https://www.portalbridge.com/#/transfer', @@ -210,7 +169,7 @@ const CHAIN_INFO: ChainInfoMap = { color: '#35D07F', backgroundColor: '#34d07f1f', }, - [SupportedChainId.CELO_ALFAJORES]: { + [ChainId.CELO_ALFAJORES]: { networkType: NetworkType.L1, blockWaitMsBeforeWarning: ms`10m`, bridge: 'https://www.portalbridge.com/#/transfer', @@ -224,7 +183,7 @@ const CHAIN_INFO: ChainInfoMap = { color: '#35D07F', backgroundColor: '#34d07f1f', }, - [SupportedChainId.BNB]: { + [ChainId.BNB]: { networkType: NetworkType.L1, blockWaitMsBeforeWarning: ms`10m`, bridge: 'https://cbridge.celer.network/1/56', @@ -237,13 +196,52 @@ const CHAIN_INFO: ChainInfoMap = { color: '#F0B90B', backgroundColor: '#F0B90B', }, + [ChainId.AVALANCHE]: { + networkType: NetworkType.L1, + blockWaitMsBeforeWarning: ms`10m`, + bridge: 'https://core.app/bridge/', + docs: 'https://docs.avax.network/', + explorer: 'https://snowtrace.io/', + infoLink: 'https://info.uniswap.org/#/avax/', // TODO(WEB-2336): Add avax support to info site + label: 'Avalanche', + logoUrl: avaxLogo, + nativeCurrency: { name: 'AVAX', symbol: 'AVAX', decimals: 18 }, + color: '#FF0420', + backgroundColor: '#FF04201f', + }, + [ChainId.BASE]: { + networkType: NetworkType.L2, + blockWaitMsBeforeWarning: ms`25m`, + bridge: 'https://bridge.base.org/deposit', + docs: 'https://docs.base.org', + explorer: 'https://basescan.org/', + infoLink: 'https://info.uniswap.org/#/base/', + label: 'Base', + logoUrl: baseLogo, + nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, + color: '#0052FF', + backgroundColor: '#0052FF1f', + }, + [ChainId.BASE_GOERLI]: { + networkType: NetworkType.L2, + blockWaitMsBeforeWarning: ms`25m`, + bridge: 'https://goerli-bridge.base.org/deposit', + docs: 'https://docs.base.org', + explorer: 'https://goerli.basescan.org/', + infoLink: 'https://info.uniswap.org/#/base/', // base testnet not supported + label: 'Base Goerli', + logoUrl: baseLogo, + nativeCurrency: { name: 'Base Goerli Ether', symbol: 'ETH', decimals: 18 }, + color: '#0052FF', + backgroundColor: '#0052FF1f', + }, } export function getChainInfo(chainId: SupportedL1ChainId): L1ChainInfo export function getChainInfo(chainId: SupportedL2ChainId): L2ChainInfo -export function getChainInfo(chainId: SupportedChainId): L1ChainInfo | L2ChainInfo +export function getChainInfo(chainId: ChainId): L1ChainInfo | L2ChainInfo export function getChainInfo( - chainId: SupportedChainId | SupportedL1ChainId | SupportedL2ChainId | number | undefined + chainId: ChainId | SupportedL1ChainId | SupportedL2ChainId | number | undefined ): L1ChainInfo | L2ChainInfo | undefined /** @@ -261,12 +259,12 @@ export function getChainInfo(chainId: any): any { return undefined } -export const MAINNET_INFO = CHAIN_INFO[SupportedChainId.MAINNET] +export const MAINNET_INFO = CHAIN_INFO[ChainId.MAINNET] export function getChainInfoOrDefault(chainId: number | undefined) { return getChainInfo(chainId) ?? MAINNET_INFO } -export function isSupportedChainId(chainId: number | undefined): chainId is SupportedChainId { +export function isSupportedChainId(chainId: number | undefined): chainId is ChainId { if (chainId === undefined) return false - return !!SupportedChainId[chainId] + return !!ChainId[chainId] } diff --git a/src/constants/chains.test.ts b/src/constants/chains.test.ts index 6b6f32d5f..0b5b57fb7 100644 --- a/src/constants/chains.test.ts +++ b/src/constants/chains.test.ts @@ -1,9 +1,11 @@ -import { ALL_SUPPORTED_CHAIN_IDS, SupportedChainId } from './chains' +import { ChainId } from '@uniswap/sdk-core' + +import { ALL_SUPPORTED_CHAIN_IDS } from './chains' describe('chains', () => { describe('ALL_SUPPORTED_CHAIN_IDS', () => { - it('contains all the values in the SupportedChainId enum', () => { - Object.values(SupportedChainId).forEach((chainId) => { + it('contains all the values in the ChainId enum', () => { + Object.values(ChainId).forEach((chainId) => { if (typeof chainId === 'number') expect(ALL_SUPPORTED_CHAIN_IDS.includes(chainId as number)).toBeTruthy() }) }) @@ -16,10 +18,10 @@ describe('chains', () => { }) }) - it('all values are in the SupportedChainId mapping', () => { + it('all values are in the ChainId mapping', () => { ALL_SUPPORTED_CHAIN_IDS.forEach((chainId) => { // takes advantage of the reverse mapping - expect(SupportedChainId[chainId]).toBeTruthy() + expect(ChainId[chainId]).toBeTruthy() }) }) diff --git a/src/constants/chains.ts b/src/constants/chains.ts index cf530f941..d33ae37d1 100644 --- a/src/constants/chains.ts +++ b/src/constants/chains.ts @@ -1,27 +1,4 @@ -/** - * List of all the networks supported by the Uniswap Interface - */ -export enum SupportedChainId { - MAINNET = 1, - ROPSTEN = 3, - RINKEBY = 4, - GOERLI = 5, - KOVAN = 42, - - ARBITRUM_ONE = 42161, - ARBITRUM_RINKEBY = 421611, - - OPTIMISM = 10, - OPTIMISM_GOERLI = 420, - - POLYGON = 137, - POLYGON_MUMBAI = 80001, - - CELO = 42220, - CELO_ALFAJORES = 44787, - - BNB = 56, -} +import { ChainId } from '@uniswap/sdk-core' export enum ChainName { MAINNET = 'mainnet', @@ -38,54 +15,51 @@ export enum ChainName { CELO = 'celo', CELO_ALFAJORES = 'celo-alfajores', BNB = 'bnb', + AVALANCHE = 'avalanche', + BASE = 'base', } -export const CHAIN_NAMES_TO_IDS: { [chainName: string]: SupportedChainId } = { - [ChainName.MAINNET]: SupportedChainId.MAINNET, - [ChainName.ROPSTEN]: SupportedChainId.ROPSTEN, - [ChainName.RINKEBY]: SupportedChainId.RINKEBY, - [ChainName.GOERLI]: SupportedChainId.GOERLI, - [ChainName.KOVAN]: SupportedChainId.KOVAN, - [ChainName.POLYGON]: SupportedChainId.POLYGON, - [ChainName.POLYGON_MUMBAI]: SupportedChainId.POLYGON_MUMBAI, - [ChainName.ARBITRUM_ONE]: SupportedChainId.ARBITRUM_ONE, - [ChainName.ARBITRUM_RINKEBY]: SupportedChainId.ARBITRUM_RINKEBY, - [ChainName.OPTIMISM]: SupportedChainId.OPTIMISM, - [ChainName.OPTIMISM_GOERLI]: SupportedChainId.OPTIMISM_GOERLI, - [ChainName.CELO]: SupportedChainId.CELO, - [ChainName.CELO_ALFAJORES]: SupportedChainId.CELO_ALFAJORES, - [ChainName.BNB]: SupportedChainId.BNB, +export const CHAIN_NAMES_TO_IDS: { [chainName: string]: ChainId } = { + [ChainName.MAINNET]: ChainId.MAINNET, + [ChainName.GOERLI]: ChainId.GOERLI, + [ChainName.POLYGON]: ChainId.POLYGON, + [ChainName.POLYGON_MUMBAI]: ChainId.POLYGON_MUMBAI, + [ChainName.ARBITRUM_ONE]: ChainId.ARBITRUM_ONE, + [ChainName.OPTIMISM]: ChainId.OPTIMISM, + [ChainName.OPTIMISM_GOERLI]: ChainId.OPTIMISM_GOERLI, + [ChainName.CELO]: ChainId.CELO, + [ChainName.CELO_ALFAJORES]: ChainId.CELO_ALFAJORES, + [ChainName.BNB]: ChainId.BNB, + [ChainName.AVALANCHE]: ChainId.AVALANCHE, + [ChainName.BASE]: ChainId.BASE, } /** * Array of all the supported chain IDs */ -export const ALL_SUPPORTED_CHAIN_IDS: SupportedChainId[] = Object.values(SupportedChainId).filter( +export const ALL_SUPPORTED_CHAIN_IDS: ChainId[] = Object.values(ChainId).filter( (id) => typeof id === 'number' -) as SupportedChainId[] +) as ChainId[] export const SUPPORTED_GAS_ESTIMATE_CHAIN_IDS = [ - SupportedChainId.MAINNET, - SupportedChainId.POLYGON, - SupportedChainId.OPTIMISM, - SupportedChainId.ARBITRUM_ONE, - SupportedChainId.CELO, - SupportedChainId.BNB, + ChainId.MAINNET, + ChainId.POLYGON, + ChainId.OPTIMISM, + ChainId.ARBITRUM_ONE, + ChainId.CELO, + ChainId.BNB, ] /** * All the chain IDs that are running the Ethereum protocol. */ export const L1_CHAIN_IDS = [ - SupportedChainId.MAINNET, - SupportedChainId.ROPSTEN, - SupportedChainId.RINKEBY, - SupportedChainId.GOERLI, - SupportedChainId.KOVAN, - SupportedChainId.POLYGON, - SupportedChainId.POLYGON_MUMBAI, - SupportedChainId.CELO, - SupportedChainId.CELO_ALFAJORES, + ChainId.MAINNET, + ChainId.GOERLI, + ChainId.POLYGON, + ChainId.POLYGON_MUMBAI, + ChainId.CELO, + ChainId.CELO_ALFAJORES, ] as const export type SupportedL1ChainId = typeof L1_CHAIN_IDS[number] @@ -94,15 +68,10 @@ export type SupportedL1ChainId = typeof L1_CHAIN_IDS[number] * Controls some L2 specific behavior, e.g. slippage tolerance, special UI behavior. * The expectation is that all of these networks have immediate transaction confirmation. */ -export const L2_CHAIN_IDS = [ - SupportedChainId.ARBITRUM_ONE, - SupportedChainId.ARBITRUM_RINKEBY, - SupportedChainId.OPTIMISM, - SupportedChainId.OPTIMISM_GOERLI, -] as const +export const L2_CHAIN_IDS = [ChainId.ARBITRUM_ONE, ChainId.OPTIMISM, ChainId.OPTIMISM_GOERLI] as const export type SupportedL2ChainId = typeof L2_CHAIN_IDS[number] -export function isPolygonChain(chainId: number): chainId is SupportedChainId.POLYGON | SupportedChainId.POLYGON_MUMBAI { - return chainId === SupportedChainId.POLYGON || chainId === SupportedChainId.POLYGON_MUMBAI +export function isPolygonChain(chainId: number): chainId is ChainId.POLYGON | ChainId.POLYGON_MUMBAI { + return chainId === ChainId.POLYGON || chainId === ChainId.POLYGON_MUMBAI } diff --git a/src/constants/jsonRpcEndpoints.ts b/src/constants/jsonRpcEndpoints.ts index 7c7e97561..961a71ebd 100644 --- a/src/constants/jsonRpcEndpoints.ts +++ b/src/constants/jsonRpcEndpoints.ts @@ -1,4 +1,4 @@ -import { SupportedChainId } from './chains' +import { ChainId } from '@uniswap/sdk-core' /** * Fallback JSON RPC endpoints. @@ -10,71 +10,76 @@ import { SupportedChainId } from './chains' * * These "Safe" URLs are listed first, followed by other fallback URLs, which are taken from chainlist.org. */ -export const JSON_RPC_FALLBACK_ENDPOINTS: Record = { - [SupportedChainId.MAINNET]: [ +export const JSON_RPC_FALLBACK_ENDPOINTS = { + [ChainId.MAINNET]: [ // "Safe" URLs + 'https://api.mycryptoapi.com/eth', 'https://cloudflare-eth.com', // "Fallback" URLs 'https://rpc.ankr.com/eth', 'https://eth-mainnet.public.blastapi.io', ], - [SupportedChainId.ROPSTEN]: [ - // "Fallback" URLs - 'https://rpc.ankr.com/eth_ropsten', - ], - [SupportedChainId.RINKEBY]: [ - // "Fallback" URLs - 'https://rinkeby-light.eth.linkpool.io/', - ], - [SupportedChainId.GOERLI]: [ + [ChainId.GOERLI]: [ // "Safe" URLs 'https://rpc.goerli.mudit.blog/', // "Fallback" URLs 'https://rpc.ankr.com/eth_goerli', ], - [SupportedChainId.KOVAN]: [ + [ChainId.SEPOLIA]: [ + // "Safe" URLs + 'https://rpc.sepolia.dev/', // "Fallback" URLs - 'https://eth-kovan.public.blastapi.io', + 'https://rpc.sepolia.org/', + 'https://rpc2.sepolia.org/', + 'https://rpc.sepolia.online/', + 'https://www.sepoliarpc.space/', + 'https://rpc-sepolia.rockx.com/', + 'https://rpc.bordel.wtf/sepolia', ], - [SupportedChainId.POLYGON]: [ + [ChainId.POLYGON]: [ // "Safe" URLs 'https://polygon-rpc.com/', + 'https://rpc-mainnet.matic.network', + 'https://matic-mainnet.chainstacklabs.com', + 'https://rpc-mainnet.maticvigil.com', + 'https://rpc-mainnet.matic.quiknode.pro', + 'https://matic-mainnet-full-rpc.bwarelabs.com', ], - [SupportedChainId.POLYGON_MUMBAI]: [ + [ChainId.POLYGON_MUMBAI]: [ // "Safe" URLs 'https://matic-mumbai.chainstacklabs.com', 'https://rpc-mumbai.maticvigil.com', 'https://matic-testnet-archive-rpc.bwarelabs.com', ], - [SupportedChainId.ARBITRUM_ONE]: [ + [ChainId.ARBITRUM_ONE]: [ // "Safe" URLs 'https://arb1.arbitrum.io/rpc', // "Fallback" URLs 'https://arbitrum.public-rpc.com', ], - [SupportedChainId.ARBITRUM_RINKEBY]: [ + [ChainId.ARBITRUM_GOERLI]: [ // "Safe" URLs - 'https://rinkeby.arbitrum.io/rpc', + 'https://goerli-rollup.arbitrum.io/rpc', ], - [SupportedChainId.OPTIMISM]: [ + [ChainId.OPTIMISM]: [ // "Safe" URLs 'https://mainnet.optimism.io/', // "Fallback" URLs 'https://rpc.ankr.com/optimism', ], - [SupportedChainId.OPTIMISM_GOERLI]: [ + [ChainId.OPTIMISM_GOERLI]: [ // "Safe" URLs 'https://goerli.optimism.io', ], - [SupportedChainId.CELO]: [ + [ChainId.CELO]: [ // "Safe" URLs - 'https://forno.celo.org', + `https://forno.celo.org`, ], - [SupportedChainId.CELO_ALFAJORES]: [ + [ChainId.CELO_ALFAJORES]: [ // "Safe" URLs - 'https://alfajores-forno.celo-testnet.org', + `https://alfajores-forno.celo-testnet.org`, ], - [SupportedChainId.BNB]: [ + [ChainId.BNB]: [ // "Safe" URLs 'https://endpoints.omniatech.io/v1/bsc/mainnet/public', 'https://bsc-mainnet.gateway.pokt.network/v1/lb/6136201a7bad1500343e248d', @@ -86,4 +91,25 @@ export const JSON_RPC_FALLBACK_ENDPOINTS: Record = { 'https://bsc-dataseed4.defibit.io', 'https://rpc.ankr.com/bsc', ], + [ChainId.AVALANCHE]: [ + // "Safe" URLs + 'https://api.avax.network/ext/bc/C/rpc', + 'https://avalanche-c-chain.publicnode.com', + ], + [ChainId.BASE]: [ + // "Safe" URLs + 'https://mainnet.base.org', + // "Unsafe" URLs + 'https://base-mainnet.blastapi.io/b5a802d8-151d-4443-90a7-699108dc4e01', + 'https://svc.blockdaemon.com/base/mainnet/native?apiKey=zpka_1334e7c450464d06b6e33a972a7a4e57_75320f43', + ], + [ChainId.BASE_GOERLI]: [ + // "Safe" URLs + 'https://goerli.base.org', + // "Unsafe" URLs + 'https://base-goerli.blastapi.io/b5a802d8-151d-4443-90a7-699108dc4e01', + 'https://svc.blockdaemon.com/base/testnet/native?apiKey=zpka_1334e7c450464d06b6e33a972a7a4e57_75320f43', + ], + [ChainId.GNOSIS]: [], + [ChainId.MOONBEAM]: [], } diff --git a/src/constants/routing.ts b/src/constants/routing.ts index 1336fe771..92f798743 100644 --- a/src/constants/routing.ts +++ b/src/constants/routing.ts @@ -1,7 +1,6 @@ // a list of tokens by chain -import { NativeCurrency, Token } from '@uniswap/sdk-core' +import { ChainId, NativeCurrency, Token } from '@uniswap/sdk-core' -import { SupportedChainId } from './chains' import { AMPL, CEUR_CELO, @@ -23,6 +22,7 @@ import { sETH2, SWISE, TRIBE, + USDC_BASE, USDC_BNB_CHAIN, USDC_MAINNET, USDC_POLYGON, @@ -51,50 +51,46 @@ const WRAPPED_NATIVE_CURRENCIES_ONLY: ChainTokenList = Object.fromEntries( // used to construct intermediary pairs for trading export const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = { ...WRAPPED_NATIVE_CURRENCIES_ONLY, - [SupportedChainId.MAINNET]: [ - nativeOnChain(SupportedChainId.MAINNET), + [ChainId.MAINNET]: [ + nativeOnChain(ChainId.MAINNET), DAI, USDC_MAINNET, USDT, WBTC, - ...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.MAINNET], + ...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.MAINNET], ], - [SupportedChainId.OPTIMISM]: [ - ...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.OPTIMISM], - DAI_OPTIMISM, - USDT_OPTIMISM, - WBTC_OPTIMISM, - ], - [SupportedChainId.ARBITRUM_ONE]: [ - ...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.ARBITRUM_ONE], + [ChainId.OPTIMISM]: [...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.OPTIMISM], DAI_OPTIMISM, USDT_OPTIMISM, WBTC_OPTIMISM], + [ChainId.ARBITRUM_ONE]: [ + ...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.ARBITRUM_ONE], DAI_ARBITRUM_ONE, USDT_ARBITRUM_ONE, WBTC_ARBITRUM_ONE, ], - [SupportedChainId.POLYGON]: [ - ...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.POLYGON], + [ChainId.POLYGON]: [ + ...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.POLYGON], DAI_POLYGON, USDC_POLYGON, USDT_POLYGON, WETH_POLYGON, ], - [SupportedChainId.CELO]: [ - ...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.CELO], + [ChainId.CELO]: [ + ...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.CELO], CUSD_CELO, CEUR_CELO, CMC02_CELO, PORTAL_USDC_CELO, PORTAL_ETH_CELO, ], - [SupportedChainId.BNB]: [ - nativeOnChain(SupportedChainId.BNB), + [ChainId.BNB]: [ + nativeOnChain(ChainId.BNB), USDC_BNB_CHAIN, USDT_BNB_CHAIN, - ...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.BNB], + ...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.BNB], ], + [ChainId.BASE]: [nativeOnChain(ChainId.BASE), USDC_BASE, ...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.BASE]], } export const ADDITIONAL_BASES: { [chainId: number]: { [tokenAddress: string]: Token[] } } = { - [SupportedChainId.MAINNET]: { + [ChainId.MAINNET]: { '0xF16E4d813f4DcfDe4c5b44f305c908742De84eF0': [ETH2X_FLI], [rETH2.address]: [sETH2], [SWISE.address]: [sETH2], @@ -111,7 +107,7 @@ export const ADDITIONAL_BASES: { [chainId: number]: { [tokenAddress: string]: To * tokens. */ export const CUSTOM_BASES: { [chainId: number]: { [tokenAddress: string]: Token[] } } = { - [SupportedChainId.MAINNET]: { - [AMPL.address]: [DAI, WRAPPED_NATIVE_CURRENCY[SupportedChainId.MAINNET] as Token], + [ChainId.MAINNET]: { + [AMPL.address]: [DAI, WRAPPED_NATIVE_CURRENCY[ChainId.MAINNET] as Token], }, } diff --git a/src/constants/tokens.ts b/src/constants/tokens.ts index df853c490..fd162dfb5 100644 --- a/src/constants/tokens.ts +++ b/src/constants/tokens.ts @@ -1,279 +1,191 @@ -import { Currency, Ether, NativeCurrency, Token, WETH9 } from '@uniswap/sdk-core' +import { ChainId, Currency, Ether, NativeCurrency, Token, WETH9 } from '@uniswap/sdk-core' import invariant from 'tiny-invariant' import { UNI_ADDRESS } from './addresses' -import { SupportedChainId } from './chains' export const USDC_MAINNET = new Token( - SupportedChainId.MAINNET, + ChainId.MAINNET, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6, 'USDC', 'USD//C' ) -export const USDC_ROPSTEN = new Token( - SupportedChainId.ROPSTEN, - '0x07865c6e87b9f70255377e024ace6630c1eaa37f', - 6, - 'USDC', - 'USD//C' -) -export const USDC_RINKEBY = new Token( - SupportedChainId.RINKEBY, - '0x4DBCdF9B62e891a7cec5A2568C3F4FAF9E8Abe2b', - 6, - 'tUSDC', - 'test USD//C' -) -export const USDC_GOERLI = new Token( - SupportedChainId.GOERLI, - '0x07865c6e87b9f70255377e024ace6630c1eaa37f', - 6, - 'USDC', - 'USD//C' -) -export const USDC_KOVAN = new Token( - SupportedChainId.KOVAN, - '0x31eeb2d0f9b6fd8642914ab10f4dd473677d80df', - 6, - 'USDC', - 'USD//C' -) +export const USDC_GOERLI = new Token(ChainId.GOERLI, '0x07865c6e87b9f70255377e024ace6630c1eaa37f', 6, 'USDC', 'USD//C') export const USDC_OPTIMISM = new Token( - SupportedChainId.OPTIMISM, + ChainId.OPTIMISM, '0x7F5c764cBc14f9669B88837ca1490cCa17c31607', 6, 'USDC', 'USD//C' ) const USDC_OPTIMISM_GOERLI = new Token( - SupportedChainId.OPTIMISM_GOERLI, + ChainId.OPTIMISM_GOERLI, '0x7E07E15D2a87A24492740D16f5bdF58c16db0c4E', 6, 'USDC', 'USD//C' ) export const USDC_ARBITRUM = new Token( - SupportedChainId.ARBITRUM_ONE, + ChainId.ARBITRUM_ONE, '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8', 6, 'USDC', 'USD//C' ) -export const USDC_ARBITRUM_RINKEBY = new Token( - SupportedChainId.ARBITRUM_RINKEBY, - '0x09b98f8b2395d076514037ff7d39a091a536206c', - 6, - 'USDC', - 'USD//C' -) export const USDC_POLYGON = new Token( - SupportedChainId.POLYGON, + ChainId.POLYGON, '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', 6, 'USDC', 'USD//C' ) export const USDC_POLYGON_MUMBAI = new Token( - SupportedChainId.POLYGON_MUMBAI, + ChainId.POLYGON_MUMBAI, '0xe11a86849d99f524cac3e7a0ec1241828e332c62', 6, 'USDC', 'USD//C' ) export const PORTAL_USDC_CELO = new Token( - SupportedChainId.CELO, + ChainId.CELO, '0x37f750B7cC259A2f741AF45294f6a16572CF5cAd', 6, 'USDCet', 'USDC (Portal from Ethereum)' ) export const USDC_CELO_ALFAJORES = new Token( - SupportedChainId.CELO_ALFAJORES, + ChainId.CELO_ALFAJORES, '0x41F4a5d2632b019Ae6CE9625bE3c9CaC143AcC7D', 6, 'USDC', 'USD//C' ) -export const AMPL = new Token( - SupportedChainId.MAINNET, - '0xD46bA6D942050d489DBd938a2C909A5d5039A161', - 9, - 'AMPL', - 'Ampleforth' -) -export const DAI = new Token( - SupportedChainId.MAINNET, - '0x6B175474E89094C44Da98b954EedeAC495271d0F', - 18, - 'DAI', - 'Dai Stablecoin' -) +export const AMPL = new Token(ChainId.MAINNET, '0xD46bA6D942050d489DBd938a2C909A5d5039A161', 9, 'AMPL', 'Ampleforth') +export const DAI = new Token(ChainId.MAINNET, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'Dai Stablecoin') export const DAI_ARBITRUM_ONE = new Token( - SupportedChainId.ARBITRUM_ONE, + ChainId.ARBITRUM_ONE, '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', 18, 'DAI', 'Dai stable coin' ) export const DAI_OPTIMISM = new Token( - SupportedChainId.OPTIMISM, + ChainId.OPTIMISM, '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', 18, 'DAI', 'Dai stable coin' ) -export const USDC_BNB_CHAIN = new Token( - SupportedChainId.BNB, - '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', - 18, - 'USDC', +export const USDC_BNB_CHAIN = new Token(ChainId.BNB, '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', 18, 'USDC', 'USDC') +export const USDC_BASE = new Token( + ChainId.BASE, + '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', + 6, + 'USD Base Coin', + 'USDbC' +) +export const USDC_SEPOLIA = new Token(ChainId.SEPOLIA, '0x8267cF9254734C6Eb452a7bb9AAF97B392258b21', 6, 'USDC', 'USDC') +export const USDC_ARBITRUM_GOERLI = new Token( + ChainId.ARBITRUM_GOERLI, + '0x179522635726710Dd7D2035a81d856de4Aa7836c', + 6, 'USDC' ) -export const USDC: { [chainId in SupportedChainId]: Token } = { - [SupportedChainId.MAINNET]: USDC_MAINNET, - [SupportedChainId.ARBITRUM_ONE]: USDC_ARBITRUM, - [SupportedChainId.OPTIMISM]: USDC_OPTIMISM, - [SupportedChainId.ARBITRUM_RINKEBY]: USDC_ARBITRUM_RINKEBY, - [SupportedChainId.OPTIMISM_GOERLI]: USDC_OPTIMISM_GOERLI, - [SupportedChainId.POLYGON]: USDC_POLYGON, - [SupportedChainId.POLYGON_MUMBAI]: USDC_POLYGON_MUMBAI, - [SupportedChainId.CELO]: PORTAL_USDC_CELO, - [SupportedChainId.CELO_ALFAJORES]: USDC_CELO_ALFAJORES, - [SupportedChainId.GOERLI]: USDC_GOERLI, - [SupportedChainId.RINKEBY]: USDC_RINKEBY, - [SupportedChainId.KOVAN]: USDC_KOVAN, - [SupportedChainId.ROPSTEN]: USDC_ROPSTEN, - [SupportedChainId.BNB]: USDC_BNB_CHAIN, +export const USDC: Partial<{ [chainId in ChainId]: Token }> = { + [ChainId.MAINNET]: USDC_MAINNET, + [ChainId.GOERLI]: USDC_GOERLI, + [ChainId.SEPOLIA]: USDC_SEPOLIA, + [ChainId.OPTIMISM]: USDC_OPTIMISM, + [ChainId.OPTIMISM_GOERLI]: USDC_OPTIMISM_GOERLI, + [ChainId.ARBITRUM_ONE]: USDC_ARBITRUM, + [ChainId.ARBITRUM_GOERLI]: USDC_ARBITRUM_GOERLI, + [ChainId.POLYGON]: USDC_POLYGON, + [ChainId.POLYGON_MUMBAI]: USDC_POLYGON_MUMBAI, + [ChainId.CELO]: PORTAL_USDC_CELO, + [ChainId.CELO_ALFAJORES]: USDC_CELO_ALFAJORES, + [ChainId.BNB]: USDC_BNB_CHAIN, + [ChainId.BASE]: USDC_BASE, } export const DAI_POLYGON = new Token( - SupportedChainId.POLYGON, + ChainId.POLYGON, '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063', 18, 'DAI', 'Dai Stablecoin' ) export const USDT_POLYGON = new Token( - SupportedChainId.POLYGON, + ChainId.POLYGON, '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', 6, 'USDT', 'Tether USD' ) export const WBTC_POLYGON = new Token( - SupportedChainId.POLYGON, + ChainId.POLYGON, '0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6', 8, 'WBTC', 'Wrapped BTC' ) -export const USDT = new Token( - SupportedChainId.MAINNET, - '0xdAC17F958D2ee523a2206206994597C13D831ec7', - 6, - 'USDT', - 'Tether USD' -) +export const USDT = new Token(ChainId.MAINNET, '0xdAC17F958D2ee523a2206206994597C13D831ec7', 6, 'USDT', 'Tether USD') export const USDT_ARBITRUM_ONE = new Token( - SupportedChainId.ARBITRUM_ONE, + ChainId.ARBITRUM_ONE, '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9', 6, 'USDT', 'Tether USD' ) export const USDT_OPTIMISM = new Token( - SupportedChainId.OPTIMISM, + ChainId.OPTIMISM, '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58', 6, 'USDT', 'Tether USD' ) -export const WBTC = new Token( - SupportedChainId.MAINNET, - '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', - 8, - 'WBTC', - 'Wrapped BTC' -) +export const WBTC = new Token(ChainId.MAINNET, '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 8, 'WBTC', 'Wrapped BTC') export const WBTC_ARBITRUM_ONE = new Token( - SupportedChainId.ARBITRUM_ONE, + ChainId.ARBITRUM_ONE, '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f', 8, 'WBTC', 'Wrapped BTC' ) export const WBTC_OPTIMISM = new Token( - SupportedChainId.OPTIMISM, + ChainId.OPTIMISM, '0x68f180fcCe6836688e9084f035309E29Bf0A2095', 8, 'WBTC', 'Wrapped BTC' ) -export const FEI = new Token( - SupportedChainId.MAINNET, - '0x956F47F50A910163D8BF957Cf5846D573E7f87CA', - 18, - 'FEI', - 'Fei USD' -) -export const TRIBE = new Token( - SupportedChainId.MAINNET, - '0xc7283b66Eb1EB5FB86327f08e1B5816b0720212B', - 18, - 'TRIBE', - 'Tribe' -) -export const FRAX = new Token( - SupportedChainId.MAINNET, - '0x853d955aCEf822Db058eb8505911ED77F175b99e', - 18, - 'FRAX', - 'Frax' -) -export const FXS = new Token( - SupportedChainId.MAINNET, - '0x3432B6A60D23Ca0dFCa7761B7ab56459D9C964D0', - 18, - 'FXS', - 'Frax Share' -) -export const renBTC = new Token( - SupportedChainId.MAINNET, - '0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D', - 8, - 'renBTC', - 'renBTC' -) +export const FEI = new Token(ChainId.MAINNET, '0x956F47F50A910163D8BF957Cf5846D573E7f87CA', 18, 'FEI', 'Fei USD') +export const TRIBE = new Token(ChainId.MAINNET, '0xc7283b66Eb1EB5FB86327f08e1B5816b0720212B', 18, 'TRIBE', 'Tribe') +export const FRAX = new Token(ChainId.MAINNET, '0x853d955aCEf822Db058eb8505911ED77F175b99e', 18, 'FRAX', 'Frax') +export const FXS = new Token(ChainId.MAINNET, '0x3432B6A60D23Ca0dFCa7761B7ab56459D9C964D0', 18, 'FXS', 'Frax Share') +export const renBTC = new Token(ChainId.MAINNET, '0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D', 8, 'renBTC', 'renBTC') export const ETH2X_FLI = new Token( - SupportedChainId.MAINNET, + ChainId.MAINNET, '0xAa6E8127831c9DE45ae56bB1b0d4D4Da6e5665BD', 18, 'ETH2x-FLI', 'ETH 2x Flexible Leverage Index' ) export const sETH2 = new Token( - SupportedChainId.MAINNET, + ChainId.MAINNET, '0xFe2e637202056d30016725477c5da089Ab0A043A', 18, 'sETH2', 'StakeWise Staked ETH2' ) export const rETH2 = new Token( - SupportedChainId.MAINNET, + ChainId.MAINNET, '0x20BC832ca081b91433ff6c17f85701B6e92486c5', 18, 'rETH2', 'StakeWise Reward ETH2' ) -export const SWISE = new Token( - SupportedChainId.MAINNET, - '0x48C3399719B582dD63eB5AADf12A40B4C3f52FA2', - 18, - 'SWISE', - 'StakeWise' -) +export const SWISE = new Token(ChainId.MAINNET, '0x48C3399719B582dD63eB5AADf12A40B4C3f52FA2', 18, 'SWISE', 'StakeWise') export const WETH_POLYGON_MUMBAI = new Token( - SupportedChainId.POLYGON_MUMBAI, + ChainId.POLYGON_MUMBAI, '0xa6fa4fb5f76172d178d61b04b0ecd319c5d1c0aa', 18, 'WETH', @@ -281,134 +193,86 @@ export const WETH_POLYGON_MUMBAI = new Token( ) export const WETH_POLYGON = new Token( - SupportedChainId.POLYGON, + ChainId.POLYGON, '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', 18, 'WETH', 'Wrapped Ether' ) -export const CELO_CELO = new Token( - SupportedChainId.CELO, - '0x471EcE3750Da237f93B8E339c536989b8978a438', - 18, - 'CELO', - 'Celo' -) +export const CELO_CELO = new Token(ChainId.CELO, '0x471EcE3750Da237f93B8E339c536989b8978a438', 18, 'CELO', 'Celo') export const CUSD_CELO = new Token( - SupportedChainId.CELO, + ChainId.CELO, '0x765DE816845861e75A25fCA122bb6898B8B1282a', 18, 'cUSD', 'Celo Dollar' ) export const CEUR_CELO = new Token( - SupportedChainId.CELO, + ChainId.CELO, '0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73', 18, 'cEUR', 'Celo Euro Stablecoin' ) export const PORTAL_ETH_CELO = new Token( - SupportedChainId.CELO, + ChainId.CELO, '0x66803FB87aBd4aaC3cbB3fAd7C3aa01f6F3FB207', 18, 'ETH', 'Portal Ether' ) export const CMC02_CELO = new Token( - SupportedChainId.CELO, + ChainId.CELO, '0x32A9FE697a32135BFd313a6Ac28792DaE4D9979d', 18, 'cMCO2', 'Celo Moss Carbon Credit' ) export const CELO_CELO_ALFAJORES = new Token( - SupportedChainId.CELO_ALFAJORES, + ChainId.CELO_ALFAJORES, '0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9', 18, 'CELO', 'Celo' ) export const CUSD_CELO_ALFAJORES = new Token( - SupportedChainId.CELO_ALFAJORES, + ChainId.CELO_ALFAJORES, '0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1', 18, 'CUSD', 'Celo Dollar' ) export const CEUR_CELO_ALFAJORES = new Token( - SupportedChainId.CELO_ALFAJORES, + ChainId.CELO_ALFAJORES, '0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F', 18, 'CEUR', 'Celo Euro Stablecoin' ) -export const USDT_BNB_CHAIN = new Token( - SupportedChainId.BNB, - '0x55d398326f99059fF775485246999027B3197955', - 18, - 'USDT', - 'USDT' -) +export const USDT_BNB_CHAIN = new Token(ChainId.BNB, '0x55d398326f99059fF775485246999027B3197955', 18, 'USDT', 'USDT') -export const ETH_BNB_CHAIN = new Token( - SupportedChainId.BNB, - '0x2170Ed0880ac9A755fd29B2688956BD959F933F8', - 18, - 'ETH', - 'Ethereum' -) +export const ETH_BNB_CHAIN = new Token(ChainId.BNB, '0x2170Ed0880ac9A755fd29B2688956BD959F933F8', 18, 'ETH', 'Ethereum') export const MATIC_BNB_CHAIN = new Token( - SupportedChainId.BNB, + ChainId.BNB, '0xCC42724C6683B7E57334c4E856f4c9965ED682bD', 18, 'MATIC', 'Matic' ) -export const FRAX_BNB_CHAIN = new Token( - SupportedChainId.BNB, - '0x90C97F71E18723b0Cf0dfa30ee176Ab653E89F40', - 18, - 'FRAX', - 'FRAX' -) +export const FRAX_BNB_CHAIN = new Token(ChainId.BNB, '0x90C97F71E18723b0Cf0dfa30ee176Ab653E89F40', 18, 'FRAX', 'FRAX') -export const BTC_BNB_CHAIN = new Token( - SupportedChainId.BNB, - '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c', - 18, - 'BTCB', - 'BTCB' -) +export const BTC_BNB_CHAIN = new Token(ChainId.BNB, '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c', 18, 'BTCB', 'BTCB') -export const CAKE_BNB_CHAIN = new Token( - SupportedChainId.BNB, - '0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82', - 18, - 'CAKE', - 'Cake' -) +export const CAKE_BNB_CHAIN = new Token(ChainId.BNB, '0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82', 18, 'CAKE', 'Cake') -export const BUSD_BNB_CHAIN = new Token( - SupportedChainId.BNB, - '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56', - 18, - 'BUSD', - 'BUSD' -) +export const BUSD_BNB_CHAIN = new Token(ChainId.BNB, '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56', 18, 'BUSD', 'BUSD') -export const DAI_BNB_CHAIN = new Token( - SupportedChainId.BNB, - '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', - 18, - 'DAI', - 'DAI' -) +export const DAI_BNB_CHAIN = new Token(ChainId.BNB, '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', 18, 'DAI', 'DAI') -function isBnbChain(chainId: number): chainId is SupportedChainId.BNB { - return chainId === SupportedChainId.BNB +function isBnbChain(chainId: number): chainId is ChainId.BNB { + return chainId === ChainId.BNB } class BnbChainNativeCurrency extends NativeCurrency { @@ -430,85 +294,84 @@ class BnbChainNativeCurrency extends NativeCurrency { } export const UNI: { [chainId: number]: Token } = { - [SupportedChainId.MAINNET]: new Token(SupportedChainId.MAINNET, UNI_ADDRESS[1], 18, 'UNI', 'Uniswap'), - [SupportedChainId.RINKEBY]: new Token(SupportedChainId.RINKEBY, UNI_ADDRESS[4], 18, 'UNI', 'Uniswap'), - [SupportedChainId.ROPSTEN]: new Token(SupportedChainId.ROPSTEN, UNI_ADDRESS[3], 18, 'UNI', 'Uniswap'), - [SupportedChainId.GOERLI]: new Token(SupportedChainId.GOERLI, UNI_ADDRESS[5], 18, 'UNI', 'Uniswap'), - [SupportedChainId.KOVAN]: new Token(SupportedChainId.KOVAN, UNI_ADDRESS[42], 18, 'UNI', 'Uniswap'), + [ChainId.MAINNET]: new Token(ChainId.MAINNET, UNI_ADDRESS[1], 18, 'UNI', 'Uniswap'), + [ChainId.GOERLI]: new Token(ChainId.GOERLI, UNI_ADDRESS[5], 18, 'UNI', 'Uniswap'), } export const WRAPPED_NATIVE_CURRENCY: { [chainId: number]: Token | undefined } = { - ...(WETH9 as Record), - [SupportedChainId.CELO]: CELO_CELO, - [SupportedChainId.CELO_ALFAJORES]: CELO_CELO_ALFAJORES, - [SupportedChainId.OPTIMISM]: new Token( - SupportedChainId.OPTIMISM, + ...(WETH9 as Record), + [ChainId.CELO]: CELO_CELO, + [ChainId.CELO_ALFAJORES]: CELO_CELO_ALFAJORES, + [ChainId.OPTIMISM]: new Token( + ChainId.OPTIMISM, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether' ), - [SupportedChainId.OPTIMISM_GOERLI]: new Token( - SupportedChainId.OPTIMISM_GOERLI, + [ChainId.OPTIMISM_GOERLI]: new Token( + ChainId.OPTIMISM_GOERLI, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether' ), - [SupportedChainId.ARBITRUM_ONE]: new Token( - SupportedChainId.ARBITRUM_ONE, + [ChainId.ARBITRUM_ONE]: new Token( + ChainId.ARBITRUM_ONE, '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', 18, 'WETH', 'Wrapped Ether' ), - [SupportedChainId.ARBITRUM_RINKEBY]: new Token( - SupportedChainId.ARBITRUM_RINKEBY, - '0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681', - 18, - 'WETH', - 'Wrapped Ether' - ), - [SupportedChainId.POLYGON]: new Token( - SupportedChainId.POLYGON, + [ChainId.POLYGON]: new Token( + ChainId.POLYGON, '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', 18, 'WMATIC', 'Wrapped MATIC' ), - [SupportedChainId.POLYGON_MUMBAI]: new Token( - SupportedChainId.POLYGON_MUMBAI, + [ChainId.POLYGON_MUMBAI]: new Token( + ChainId.POLYGON_MUMBAI, '0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889', 18, 'WMATIC', 'Wrapped MATIC' ), - [SupportedChainId.BNB]: new Token( - SupportedChainId.BNB, - '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', + [ChainId.BNB]: new Token(ChainId.BNB, '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', 18, 'WBNB', 'Wrapped BNB'), + [ChainId.AVALANCHE]: new Token( + ChainId.AVALANCHE, + '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7', 18, - 'WBNB', - 'Wrapped BNB' + 'WAVAX', + 'Wrapped AVAX' + ), + [ChainId.BASE]: new Token(ChainId.BASE, '0x4200000000000000000000000000000000000006', 18, 'WETH', 'Wrapped Ether'), + [ChainId.BASE_GOERLI]: new Token( + ChainId.BASE_GOERLI, + '0x4200000000000000000000000000000000000006', + 18, + 'WETH', + 'Wrapped Ether' ), } -export function isCelo(chainId: number): chainId is SupportedChainId.CELO | SupportedChainId.CELO_ALFAJORES { - return chainId === SupportedChainId.CELO_ALFAJORES || chainId === SupportedChainId.CELO +export function isCelo(chainId: number): chainId is ChainId.CELO | ChainId.CELO_ALFAJORES { + return chainId === ChainId.CELO_ALFAJORES || chainId === ChainId.CELO } function getCeloNativeCurrency(chainId: number) { switch (chainId) { - case SupportedChainId.CELO_ALFAJORES: + case ChainId.CELO_ALFAJORES: return CELO_CELO_ALFAJORES - case SupportedChainId.CELO: + case ChainId.CELO: return CELO_CELO default: throw new Error('Not celo') } } -function isMatic(chainId: number): chainId is SupportedChainId.POLYGON | SupportedChainId.POLYGON_MUMBAI { - return chainId === SupportedChainId.POLYGON_MUMBAI || chainId === SupportedChainId.POLYGON +function isMatic(chainId: number): chainId is ChainId.POLYGON | ChainId.POLYGON_MUMBAI { + return chainId === ChainId.POLYGON_MUMBAI || chainId === ChainId.POLYGON } class MaticNativeCurrency extends NativeCurrency { @@ -559,20 +422,16 @@ export function nativeOnChain(chainId: number): NativeCurrency | Token { return (cachedNativeCurrency[chainId] = nativeCurrency) } -export const TOKEN_SHORTHANDS: { [shorthand: string]: { [chainId in SupportedChainId]?: string } } = { +export const TOKEN_SHORTHANDS: { [shorthand: string]: { [chainId in ChainId]?: string } } = { USDC: { - [SupportedChainId.MAINNET]: USDC_MAINNET.address, - [SupportedChainId.ARBITRUM_ONE]: USDC_ARBITRUM.address, - [SupportedChainId.OPTIMISM]: USDC_OPTIMISM.address, - [SupportedChainId.ARBITRUM_RINKEBY]: USDC_ARBITRUM_RINKEBY.address, - [SupportedChainId.OPTIMISM_GOERLI]: USDC_OPTIMISM_GOERLI.address, - [SupportedChainId.POLYGON]: USDC_POLYGON.address, - [SupportedChainId.POLYGON_MUMBAI]: USDC_POLYGON_MUMBAI.address, - [SupportedChainId.GOERLI]: USDC_GOERLI.address, - [SupportedChainId.RINKEBY]: USDC_RINKEBY.address, - [SupportedChainId.KOVAN]: USDC_KOVAN.address, - [SupportedChainId.ROPSTEN]: USDC_ROPSTEN.address, - [SupportedChainId.CELO]: PORTAL_USDC_CELO.address, - [SupportedChainId.CELO_ALFAJORES]: USDC_CELO_ALFAJORES.address, + [ChainId.MAINNET]: USDC_MAINNET.address, + [ChainId.ARBITRUM_ONE]: USDC_ARBITRUM.address, + [ChainId.OPTIMISM]: USDC_OPTIMISM.address, + [ChainId.OPTIMISM_GOERLI]: USDC_OPTIMISM_GOERLI.address, + [ChainId.POLYGON]: USDC_POLYGON.address, + [ChainId.POLYGON_MUMBAI]: USDC_POLYGON_MUMBAI.address, + [ChainId.GOERLI]: USDC_GOERLI.address, + [ChainId.CELO]: PORTAL_USDC_CELO.address, + [ChainId.CELO_ALFAJORES]: USDC_CELO_ALFAJORES.address, }, } diff --git a/src/cosmos/ControlledSwap.fixture.tsx b/src/cosmos/ControlledSwap.fixture.tsx index 0dba336b9..2e42e1016 100644 --- a/src/cosmos/ControlledSwap.fixture.tsx +++ b/src/cosmos/ControlledSwap.fixture.tsx @@ -1,6 +1,6 @@ import { tokens } from '@uniswap/default-token-list' -import { Currency, TradeType } from '@uniswap/sdk-core' -import { Field, SupportedChainId, SwapWidget } from '@uniswap/widgets' +import { ChainId, Currency, TradeType } from '@uniswap/sdk-core' +import { Field, SwapWidget } from '@uniswap/widgets' import Row from 'components/Row' import { useCallback, useMemo, useState } from 'react' @@ -21,12 +21,12 @@ function Fixture() { const currencies: Record = useMemo( () => ({ // Include native token from each chain - ...Object.values(SupportedChainId) + ...Object.values(ChainId) .filter((id): id is number => Number.isInteger(id)) .reduce( (eth, chainId) => ({ ...eth, - [SupportedChainId[chainId]]: nativeOnChain(chainId), + [ChainId[chainId]]: nativeOnChain(chainId), }), {} ), @@ -34,7 +34,7 @@ function Fixture() { ...Object.values(USDC).reduce( (usdc, chainUsdc) => ({ ...usdc, - [`${SupportedChainId[chainUsdc.chainId]} USDC`]: chainUsdc, + [`${ChainId[chainUsdc.chainId]} USDC`]: chainUsdc, }), {} ), @@ -43,14 +43,14 @@ function Fixture() { ) const inputToken = useOption('input', { options: currencies, - defaultValue: SupportedChainId[SupportedChainId.MAINNET], + defaultValue: ChainId[ChainId.MAINNET], }) const outputToken = useOption('output', { options: currencies, - defaultValue: `${SupportedChainId[SupportedChainId.MAINNET]} USDC`, + defaultValue: `${ChainId[ChainId.MAINNET]} USDC`, }) - const connector = useProvider(SupportedChainId.MAINNET) + const connector = useProvider(ChainId.MAINNET) const eventHandlers = useMemo( // eslint-disable-next-line react-hooks/rules-of-hooks diff --git a/src/cosmos/Swap.fixture.tsx b/src/cosmos/Swap.fixture.tsx index 827cae2ad..945d2639f 100644 --- a/src/cosmos/Swap.fixture.tsx +++ b/src/cosmos/Swap.fixture.tsx @@ -1,13 +1,6 @@ import { tokens } from '@uniswap/default-token-list' import { TokenInfo } from '@uniswap/token-lists' -import { - darkTheme, - defaultTheme, - DialogAnimationType, - lightTheme, - SupportedChainId, - SwapWidget, -} from '@uniswap/widgets' +import { ChainId, darkTheme, defaultTheme, DialogAnimationType, lightTheme, SwapWidget } from '@uniswap/widgets' import Row from 'components/Row' import { CHAIN_NAMES_TO_IDS } from 'constants/chains' import { useCallback, useEffect, useMemo, useState } from 'react' @@ -26,7 +19,7 @@ const TOKEN_WITH_NO_LOGO = { address: '0x3819f64f282bf135d62168C1e513280dAF905e06', } -const mainnetTokens = tokens.filter((token) => token.chainId === SupportedChainId.MAINNET) +const mainnetTokens = tokens.filter((token) => token.chainId === ChainId.MAINNET) const tokenLists: Record = { Default: tokens, Extended: 'https://extendedtokens.uniswap.org/', diff --git a/src/cosmos/useProvider.ts b/src/cosmos/useProvider.ts index 0be0d6655..2e17ee61c 100644 --- a/src/cosmos/useProvider.ts +++ b/src/cosmos/useProvider.ts @@ -1,8 +1,9 @@ +import { ChainId } from '@uniswap/sdk-core' import { initializeConnector } from '@web3-react/core' import { MetaMask } from '@web3-react/metamask' import { Connector } from '@web3-react/types' import { WalletConnect } from '@web3-react/walletconnect-v2' -import { L1_CHAIN_IDS, L2_CHAIN_IDS, SupportedChainId } from 'constants/chains' +import { L1_CHAIN_IDS, L2_CHAIN_IDS } from 'constants/chains' import { JSON_RPC_FALLBACK_ENDPOINTS } from 'constants/jsonRpcEndpoints' import { useEffect, useState } from 'react' @@ -27,7 +28,7 @@ const [walletConnect] = initializeConnector( showQrModal: true, projectId: WALLET_CONNECT_PROJECT_ID, // this requires the connecting wallet to support eth mainnet - chains: [SupportedChainId.MAINNET], + chains: [ChainId.MAINNET], optionalChains: [...L1_CHAIN_IDS, ...L2_CHAIN_IDS], optionalMethods: ['eth_signTypedData', 'eth_signTypedData_v4', 'eth_sign'], }, diff --git a/src/hooks/swap/index.test.tsx b/src/hooks/swap/index.test.tsx index 3b4a970b2..2debff2ed 100644 --- a/src/hooks/swap/index.test.tsx +++ b/src/hooks/swap/index.test.tsx @@ -1,5 +1,4 @@ -import { TradeType } from '@uniswap/sdk-core' -import { SupportedChainId } from 'constants/chains' +import { ChainId, TradeType } from '@uniswap/sdk-core' import { DAI, UNI, USDC_MAINNET } from 'constants/tokens' import { useAtomValue } from 'jotai/utils' import { controlledAtom, Field, stateAtom, Swap, swapAtom, swapEventHandlersAtom } from 'state/swap' @@ -8,7 +7,7 @@ import { act, renderHook } from 'test' import { useSwapAmount, useSwapCurrency, useSwitchSwapCurrencies } from './' const DAI_MAINNET = DAI -const UNI_MAINNET = UNI[SupportedChainId.MAINNET] +const UNI_MAINNET = UNI[ChainId.MAINNET] const INITIAL_SWAP: Swap = { type: TradeType.EXACT_INPUT, diff --git a/src/hooks/swap/useSyncTokenDefaults.test.tsx b/src/hooks/swap/useSyncTokenDefaults.test.tsx index 9de592ebf..cb9051808 100644 --- a/src/hooks/swap/useSyncTokenDefaults.test.tsx +++ b/src/hooks/swap/useSyncTokenDefaults.test.tsx @@ -1,6 +1,5 @@ import { renderHook } from '@testing-library/react' -import { TradeType } from '@uniswap/sdk-core' -import { SupportedChainId } from 'constants/chains' +import { ChainId, TradeType } from '@uniswap/sdk-core' import { DAI_POLYGON, nativeOnChain } from 'constants/tokens' import { USDC_MAINNET } from 'constants/tokens' import { Provider as AtomProvider } from 'jotai' @@ -27,11 +26,11 @@ const TOKEN_DEFAULTS: TokenDefaults = { } jest.mock('@web3-react/core', () => { - const { SupportedChainId } = jest.requireActual('constants/chains') + const { ChainId } = jest.requireActual('@uniswap/sdk-core') const connector = {} return { useWeb3React: () => ({ - chainId: SupportedChainId.MAINNET, + chainId: ChainId.MAINNET, connector, }), } @@ -57,15 +56,15 @@ describe('useSyncTokenDefaults', () => { it('syncs to default chainId on initial render if defaultChainId is provided', () => { const { result } = renderHook( () => { - useSyncTokenDefaults({ ...TOKEN_DEFAULTS, defaultChainId: SupportedChainId.POLYGON }) + useSyncTokenDefaults({ ...TOKEN_DEFAULTS, defaultChainId: ChainId.POLYGON }) return useAtomValue(swapAtom) }, { wrapper: Wrapper } ) expect(result.current).toMatchObject({ ...INITIAL_SWAP, - INPUT: nativeOnChain(SupportedChainId.POLYGON), - OUTPUT: nativeOnChain(SupportedChainId.POLYGON), + INPUT: nativeOnChain(ChainId.POLYGON), + OUTPUT: nativeOnChain(ChainId.POLYGON), }) }) @@ -79,8 +78,8 @@ describe('useSyncTokenDefaults', () => { ) expect(result.current).toMatchObject({ ...INITIAL_SWAP, - INPUT: nativeOnChain(SupportedChainId.MAINNET), - OUTPUT: nativeOnChain(SupportedChainId.MAINNET), + INPUT: nativeOnChain(ChainId.MAINNET), + OUTPUT: nativeOnChain(ChainId.MAINNET), }) }) @@ -91,7 +90,7 @@ describe('useSyncTokenDefaults', () => { ...TOKEN_DEFAULTS, defaultInputTokenAddress: DAI_POLYGON.address, defaultOutputTokenAddress: DAI_POLYGON.address, - defaultChainId: SupportedChainId.POLYGON, + defaultChainId: ChainId.POLYGON, }) return useAtomValue(swapAtom) }, @@ -114,8 +113,8 @@ describe('useSyncTokenDefaults', () => { ) expect(result.current).toMatchObject({ ...INITIAL_SWAP, - INPUT: nativeOnChain(SupportedChainId.MAINNET), - OUTPUT: nativeOnChain(SupportedChainId.MAINNET), + INPUT: nativeOnChain(ChainId.MAINNET), + OUTPUT: nativeOnChain(ChainId.MAINNET), }) }) }) diff --git a/src/hooks/swap/useSyncTokenDefaults.ts b/src/hooks/swap/useSyncTokenDefaults.ts index f3022d454..5fedad823 100644 --- a/src/hooks/swap/useSyncTokenDefaults.ts +++ b/src/hooks/swap/useSyncTokenDefaults.ts @@ -1,7 +1,6 @@ -import { Currency, TradeType } from '@uniswap/sdk-core' +import { ChainId, Currency, TradeType } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' import { Connector } from '@web3-react/types' -import { SupportedChainId } from 'constants/chains' import { nativeOnChain } from 'constants/tokens' import { useToken } from 'hooks/useCurrency' import { useUpdateAtom } from 'jotai/utils' @@ -18,7 +17,7 @@ export interface TokenDefaults { defaultInputAmount?: number | string defaultOutputTokenAddress?: DefaultAddress defaultOutputAmount?: number | string - defaultChainId?: SupportedChainId + defaultChainId?: ChainId } function useDefaultToken( diff --git a/src/hooks/swap/useWrapCallback.test.ts b/src/hooks/swap/useWrapCallback.test.ts index 98aea527b..9252298d5 100644 --- a/src/hooks/swap/useWrapCallback.test.ts +++ b/src/hooks/swap/useWrapCallback.test.ts @@ -1,6 +1,5 @@ import { parseEther } from '@ethersproject/units' -import { CurrencyAmount } from '@uniswap/sdk-core' -import { SupportedChainId } from 'constants/chains' +import { ChainId, CurrencyAmount } from '@uniswap/sdk-core' import { ExtendedEther } from 'constants/tokens' import { Field, stateAtom, swapEventHandlersAtom } from 'state/swap' import { TransactionType } from 'state/transactions' @@ -8,7 +7,7 @@ import { renderHook, waitFor } from 'test' import useWrapCallback from './useWrapCallback' -const ETH = ExtendedEther.onChain(SupportedChainId.MAINNET) +const ETH = ExtendedEther.onChain(ChainId.MAINNET) const WETH = ETH.wrapped const AMOUNT = CurrencyAmount.fromRawAmount(ETH, parseEther('1').toString()) const WRAP_TRANSACTION_INFO = { diff --git a/src/hooks/transactions/updater.tsx b/src/hooks/transactions/updater.tsx index e50f7e478..b280f5939 100644 --- a/src/hooks/transactions/updater.tsx +++ b/src/hooks/transactions/updater.tsx @@ -1,6 +1,6 @@ import { TransactionReceipt } from '@ethersproject/abstract-provider' +import { ChainId } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' -import { SupportedChainId } from 'constants/chains' import useBlockNumber, { useFastForwardBlockNumber } from 'hooks/useBlockNumber' import ms from 'ms.macro' import { useCallback, useEffect } from 'react' @@ -31,10 +31,9 @@ export function shouldCheck(lastBlockNumber: number, tx: Transaction): boolean { } const RETRY_OPTIONS_BY_CHAIN_ID: { [chainId: number]: RetryOptions } = { - [SupportedChainId.ARBITRUM_ONE]: { n: 10, minWait: 250, maxWait: 1000 }, - [SupportedChainId.ARBITRUM_RINKEBY]: { n: 10, minWait: 250, maxWait: 1000 }, - [SupportedChainId.OPTIMISM_GOERLI]: { n: 10, minWait: 250, maxWait: 1000 }, - [SupportedChainId.OPTIMISM]: { n: 10, minWait: 250, maxWait: 1000 }, + [ChainId.ARBITRUM_ONE]: { n: 10, minWait: 250, maxWait: 1000 }, + [ChainId.OPTIMISM_GOERLI]: { n: 10, minWait: 250, maxWait: 1000 }, + [ChainId.OPTIMISM]: { n: 10, minWait: 250, maxWait: 1000 }, } const DEFAULT_RETRY_OPTIONS: RetryOptions = { n: 1, minWait: 0, maxWait: 0 } diff --git a/src/hooks/useCurrency.ts b/src/hooks/useCurrency.ts index 801515dd3..9044a140b 100644 --- a/src/hooks/useCurrency.ts +++ b/src/hooks/useCurrency.ts @@ -1,6 +1,6 @@ import { arrayify } from '@ethersproject/bytes' import { parseBytes32String } from '@ethersproject/strings' -import { Currency, Token } from '@uniswap/sdk-core' +import { ChainId, Currency, Token } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' import { TOKEN_SHORTHANDS } from 'constants/tokens' import { NEVER_RELOAD, useSingleCallResult } from 'hooks/multicall' @@ -10,7 +10,6 @@ import { useMemo } from 'react' import { isAddress } from 'utils' import { supportedChainId } from 'utils/supportedChainId' -import { SupportedChainId } from '..' import { TokenMap, useTokenMap } from './useTokenList' // parse a name or symbol from a token response @@ -95,7 +94,7 @@ export function useTokenFromMapOrNetwork( * Returns null if token is loading or null was passed. * Returns undefined if tokenAddress is invalid or token does not exist. */ -export function useToken(tokenAddress?: string | null, chainId?: SupportedChainId): Token | null | undefined { +export function useToken(tokenAddress?: string | null, chainId?: ChainId): Token | null | undefined { const { chainId: activeChainId } = useWeb3React() const tokens = useTokenMap(chainId) diff --git a/src/hooks/useNativeCurrency.ts b/src/hooks/useNativeCurrency.ts index 432a3ce52..68084d8d8 100644 --- a/src/hooks/useNativeCurrency.ts +++ b/src/hooks/useNativeCurrency.ts @@ -1,6 +1,5 @@ -import { NativeCurrency, Token } from '@uniswap/sdk-core' +import { ChainId, NativeCurrency, Token } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' -import { SupportedChainId } from 'constants/chains' import { nativeOnChain } from 'constants/tokens' import { useMemo } from 'react' @@ -11,7 +10,7 @@ export default function useNativeCurrency(): NativeCurrency | Token { chainId ? nativeOnChain(chainId) : // display mainnet when not connected - nativeOnChain(SupportedChainId.MAINNET), + nativeOnChain(ChainId.MAINNET), [chainId] ) } diff --git a/src/hooks/useOnSupportedNetwork.ts b/src/hooks/useOnSupportedNetwork.ts index cf8bd26c9..446d51711 100644 --- a/src/hooks/useOnSupportedNetwork.ts +++ b/src/hooks/useOnSupportedNetwork.ts @@ -1,8 +1,9 @@ +import { ChainId } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' -import { ALL_SUPPORTED_CHAIN_IDS, SupportedChainId } from 'constants/chains' +import { ALL_SUPPORTED_CHAIN_IDS } from 'constants/chains' import { useMemo } from 'react' -function useOnSupportedNetwork(chainId?: SupportedChainId) { +function useOnSupportedNetwork(chainId?: ChainId) { const { chainId: activeChainId } = useWeb3React() chainId = chainId || activeChainId diff --git a/src/hooks/usePermit.ts b/src/hooks/usePermit.ts index 6d1f910eb..983e013e5 100644 --- a/src/hooks/usePermit.ts +++ b/src/hooks/usePermit.ts @@ -1,8 +1,7 @@ import { BigNumber } from '@ethersproject/bignumber' import { splitSignature } from '@ethersproject/bytes' -import { Currency, CurrencyAmount } from '@uniswap/sdk-core' +import { ChainId, Currency, CurrencyAmount } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' -import { SupportedChainId } from 'constants/chains' import { DAI, UNI, USDC_MAINNET } from 'constants/tokens' import { useSingleCallResult } from 'hooks/multicall' import JSBI from 'jsbi' @@ -32,24 +31,13 @@ const PERMITTABLE_TOKENS: { [checksummedTokenAddress: string]: PermitInfo } } = { - [SupportedChainId.MAINNET]: { + [ChainId.MAINNET]: { [USDC_MAINNET.address]: { type: PermitType.AMOUNT, name: 'USD Coin', version: '2' }, [DAI.address]: { type: PermitType.ALLOWED, name: 'Dai Stablecoin', version: '1' }, - [UNI[SupportedChainId.MAINNET].address]: { type: PermitType.AMOUNT, name: 'Uniswap' }, + [UNI[ChainId.MAINNET].address]: { type: PermitType.AMOUNT, name: 'Uniswap' }, }, - [SupportedChainId.RINKEBY]: { - '0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735': { type: PermitType.ALLOWED, name: 'Dai Stablecoin', version: '1' }, - [UNI[SupportedChainId.RINKEBY].address]: { type: PermitType.AMOUNT, name: 'Uniswap' }, - }, - [SupportedChainId.ROPSTEN]: { - [UNI[SupportedChainId.ROPSTEN].address]: { type: PermitType.AMOUNT, name: 'Uniswap' }, - '0x07865c6E87B9F70255377e024ace6630C1Eaa37F': { type: PermitType.AMOUNT, name: 'USD Coin', version: '2' }, - }, - [SupportedChainId.GOERLI]: { - [UNI[SupportedChainId.GOERLI].address]: { type: PermitType.AMOUNT, name: 'Uniswap' }, - }, - [SupportedChainId.KOVAN]: { - [UNI[SupportedChainId.KOVAN].address]: { type: PermitType.AMOUNT, name: 'Uniswap' }, + [ChainId.GOERLI]: { + [UNI[ChainId.GOERLI].address]: { type: PermitType.AMOUNT, name: 'Uniswap' }, }, } diff --git a/src/hooks/usePermit2Allowance.test.ts b/src/hooks/usePermit2Allowance.test.ts index 72a503d9c..d31125508 100644 --- a/src/hooks/usePermit2Allowance.test.ts +++ b/src/hooks/usePermit2Allowance.test.ts @@ -1,7 +1,6 @@ import { PERMIT2_ADDRESS } from '@uniswap/permit2-sdk' -import { CurrencyAmount, MaxUint256 } from '@uniswap/sdk-core' +import { ChainId, CurrencyAmount, MaxUint256 } from '@uniswap/sdk-core' import { UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk' -import { SupportedChainId } from 'constants/chains' import { UNI } from 'constants/tokens' import { useAddTransactionInfo, usePendingApproval } from 'hooks/transactions' import { usePermitAllowance, useUpdatePermitAllowance } from 'hooks/usePermitAllowance' @@ -11,9 +10,9 @@ import { act, renderHook, waitFor } from 'test' import usePermit2Allowance, { AllowanceRequired, AllowanceState } from './usePermit2Allowance' -const SPENDER = UNIVERSAL_ROUTER_ADDRESS(SupportedChainId.MAINNET) +const SPENDER = UNIVERSAL_ROUTER_ADDRESS(ChainId.MAINNET) -const TOKEN = UNI[SupportedChainId.MAINNET] +const TOKEN = UNI[ChainId.MAINNET] const MAX_AMOUNT = CurrencyAmount.fromRawAmount(TOKEN, MaxUint256.toString()) const ZERO_AMOUNT = CurrencyAmount.fromRawAmount(TOKEN, 0) diff --git a/src/hooks/usePermitAllowance.test.ts b/src/hooks/usePermitAllowance.test.ts index 33a5d6838..6a33a6070 100644 --- a/src/hooks/usePermitAllowance.test.ts +++ b/src/hooks/usePermitAllowance.test.ts @@ -1,10 +1,9 @@ import { Contract } from '@ethersproject/contracts' import { MaxAllowanceTransferAmount, PERMIT2_ADDRESS } from '@uniswap/permit2-sdk' -import { CurrencyAmount } from '@uniswap/sdk-core' +import { ChainId, CurrencyAmount } from '@uniswap/sdk-core' import { UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk' import PERMIT2_ABI from 'abis/permit2.json' import { Permit2 } from 'abis/types' -import { SupportedChainId } from 'constants/chains' import { UNI } from 'constants/tokens' import { useSingleCallResult } from 'hooks/multicall' import { useContract } from 'hooks/useContract' @@ -14,9 +13,9 @@ import { renderHook, waitFor } from 'test' import { usePermitAllowance, useUpdatePermitAllowance } from './usePermitAllowance' -const TOKEN = UNI[SupportedChainId.MAINNET] +const TOKEN = UNI[ChainId.MAINNET] const OWNER = hardhat.account.address -const SPENDER = UNIVERSAL_ROUTER_ADDRESS(SupportedChainId.MAINNET) +const SPENDER = UNIVERSAL_ROUTER_ADDRESS(ChainId.MAINNET) const CONTRACT = new Contract(PERMIT2_ADDRESS, PERMIT2_ABI) as Permit2 const EXPIRATION = 1234567890 diff --git a/src/hooks/useStablecoinAmountFromFiatValue.ts b/src/hooks/useStablecoinAmountFromFiatValue.ts index a1d890c00..c65440bde 100644 --- a/src/hooks/useStablecoinAmountFromFiatValue.ts +++ b/src/hooks/useStablecoinAmountFromFiatValue.ts @@ -1,6 +1,5 @@ -import { CurrencyAmount, Token } from '@uniswap/sdk-core' +import { ChainId, CurrencyAmount, Token } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' -import { SupportedChainId } from 'constants/chains' import { CUSD_CELO, DAI_OPTIMISM, USDC_ARBITRUM, USDC_MAINNET, USDC_POLYGON } from 'constants/tokens' import { useMemo } from 'react' import tryParseCurrencyAmount from 'utils/tryParseCurrencyAmount' @@ -8,11 +7,11 @@ import tryParseCurrencyAmount from 'utils/tryParseCurrencyAmount' // Stablecoin amounts used when calculating spot price for a given currency. // The amount is large enough to filter low liquidity pairs. export const STABLECOIN_AMOUNT_OUT: { [chainId: number]: CurrencyAmount } = { - [SupportedChainId.MAINNET]: CurrencyAmount.fromRawAmount(USDC_MAINNET, 100_000e6), - [SupportedChainId.ARBITRUM_ONE]: CurrencyAmount.fromRawAmount(USDC_ARBITRUM, 10_000e6), - [SupportedChainId.OPTIMISM]: CurrencyAmount.fromRawAmount(DAI_OPTIMISM, 10_000e18), - [SupportedChainId.POLYGON]: CurrencyAmount.fromRawAmount(USDC_POLYGON, 10_000e6), - [SupportedChainId.CELO]: CurrencyAmount.fromRawAmount(CUSD_CELO, 10_000e18), + [ChainId.MAINNET]: CurrencyAmount.fromRawAmount(USDC_MAINNET, 100_000e6), + [ChainId.ARBITRUM_ONE]: CurrencyAmount.fromRawAmount(USDC_ARBITRUM, 10_000e6), + [ChainId.OPTIMISM]: CurrencyAmount.fromRawAmount(DAI_OPTIMISM, 10_000e18), + [ChainId.POLYGON]: CurrencyAmount.fromRawAmount(USDC_POLYGON, 10_000e6), + [ChainId.CELO]: CurrencyAmount.fromRawAmount(CUSD_CELO, 10_000e18), } /** diff --git a/src/hooks/useSwitchChain.ts b/src/hooks/useSwitchChain.ts index 031c3391a..c15efdd0a 100644 --- a/src/hooks/useSwitchChain.ts +++ b/src/hooks/useSwitchChain.ts @@ -1,7 +1,7 @@ import type { Web3Provider } from '@ethersproject/providers' +import { ChainId } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' import { getChainInfo } from 'constants/chainInfo' -import { SupportedChainId } from 'constants/chains' import { ErrorCode } from 'constants/eip1193' import useJsonRpcUrlsMap from 'hooks/web3/useJsonRpcUrlsMap' import { atom } from 'jotai' @@ -27,7 +27,7 @@ export interface AddEthereumChainParameter { export type OnSwitchChain = (addChainParameter: AddEthereumChainParameter) => void | Promise export const onSwitchChainAtom = atom(undefined) -function toHex(chainId: SupportedChainId): string { +function toHex(chainId: ChainId): string { return `0x${chainId.toString(16)}` } @@ -50,7 +50,7 @@ async function addChain(provider: Web3Provider, addChainParameter: AddEthereumCh async function switchChain( provider: Web3Provider, - chainId: SupportedChainId, + chainId: ChainId, addChainParameter?: AddEthereumChainParameter ): Promise { try { @@ -63,13 +63,13 @@ async function switchChain( } } -export default function useSwitchChain(): (chainId: SupportedChainId) => Promise { +export default function useSwitchChain(): (chainId: ChainId) => Promise { const { connector, provider } = useWeb3React() const connectors = useConnectors() const urlMap = useJsonRpcUrlsMap() const onSwitchChain = useAtomValue(onSwitchChainAtom) return useCallback( - async (chainId: SupportedChainId) => { + async (chainId: ChainId) => { const { safe, label, nativeCurrency, explorer } = getChainInfo(chainId) const addChainParameter: AddEthereumChainParameter = { chainId: toHex(chainId), diff --git a/src/hooks/useTokenAllowance.test.ts b/src/hooks/useTokenAllowance.test.ts index d0671790e..42c56c341 100644 --- a/src/hooks/useTokenAllowance.test.ts +++ b/src/hooks/useTokenAllowance.test.ts @@ -4,9 +4,8 @@ import { BigNumber } from '@ethersproject/bignumber' import { Contract, ContractTransaction } from '@ethersproject/contracts' import { Deferrable } from '@ethersproject/properties' import { PERMIT2_ADDRESS } from '@uniswap/permit2-sdk' -import { CurrencyAmount, MaxUint256 } from '@uniswap/sdk-core' +import { ChainId, CurrencyAmount, MaxUint256 } from '@uniswap/sdk-core' import ERC20_ABI from 'abis/erc20.json' -import { SupportedChainId } from 'constants/chains' import { UNI } from 'constants/tokens' import { useSingleCallResult } from 'hooks/multicall' import { useTokenContract } from 'hooks/useContract' @@ -16,7 +15,7 @@ import { renderHook } from 'test' import { useTokenAllowance, useUpdateTokenAllowance } from './useTokenAllowance' -const TOKEN = UNI[SupportedChainId.MAINNET] +const TOKEN = UNI[ChainId.MAINNET] const OWNER = hardhat.account.address const SPENDER = PERMIT2_ADDRESS const SIGNER = new VoidSigner(OWNER) diff --git a/src/hooks/useTokenList/index.tsx b/src/hooks/useTokenList/index.tsx index 4a02fadb9..c26e00c62 100644 --- a/src/hooks/useTokenList/index.tsx +++ b/src/hooks/useTokenList/index.tsx @@ -1,8 +1,7 @@ -import { Token } from '@uniswap/sdk-core' +import { ChainId, Token } from '@uniswap/sdk-core' import { TokenInfo, TokenList } from '@uniswap/token-lists' import { useWeb3React } from '@web3-react/core' import { useAsyncError } from 'components/Error/ErrorBoundary' -import { SupportedChainId } from 'constants/chains' import { createContext, PropsWithChildren, useCallback, useContext, useEffect, useMemo, useState } from 'react' import { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo' import resolveENSContentHash from 'utils/resolveENSContentHash' @@ -44,7 +43,7 @@ export default function useTokenList(): WrappedTokenInfo[] { export type TokenMap = { [address: string]: Token } -export function useTokenMap(chainId?: SupportedChainId): TokenMap { +export function useTokenMap(chainId?: ChainId): TokenMap { const { chainId: activeChainId } = useWeb3React() chainId = chainId || activeChainId diff --git a/src/hooks/useUniversalRouter.test.ts b/src/hooks/useUniversalRouter.test.ts index a285ad5fd..c964170a4 100644 --- a/src/hooks/useUniversalRouter.test.ts +++ b/src/hooks/useUniversalRouter.test.ts @@ -1,8 +1,7 @@ import { TransactionResponse } from '@ethersproject/abstract-provider' import { sendTransaction } from '@uniswap/conedison/provider/index' -import { TradeType } from '@uniswap/sdk-core' +import { ChainId, TradeType } from '@uniswap/sdk-core' import { SwapRouter, UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk' -import { SupportedChainId } from 'constants/chains' import { TWO_PERCENT } from 'constants/misc' import { InterfaceTrade } from 'state/routing/types' import { swapEventHandlersAtom } from 'state/swap' @@ -39,7 +38,7 @@ describe('useUniversalRouter', () => { hardhat.provider, { from: expect.stringMatching(new RegExp(hardhat.account.address, 'i')), - to: UNIVERSAL_ROUTER_ADDRESS(SupportedChainId.MAINNET), + to: UNIVERSAL_ROUTER_ADDRESS(ChainId.MAINNET), data: 'calldata', }, 0.2 diff --git a/src/hooks/web3/index.tsx b/src/hooks/web3/index.tsx index 7b6375c96..c7c330a29 100644 --- a/src/hooks/web3/index.tsx +++ b/src/hooks/web3/index.tsx @@ -1,6 +1,7 @@ import './polyfills' // must be imported first import { JsonRpcProvider } from '@ethersproject/providers' +import { ChainId } from '@uniswap/sdk-core' import { initializeConnector, Web3ReactHooks, Web3ReactProvider } from '@web3-react/core' import { EIP1193 } from '@web3-react/eip1193' import { MetaMask } from '@web3-react/metamask' @@ -8,7 +9,7 @@ import { Network } from '@web3-react/network' import { Connector, Provider as Eip1193Provider } from '@web3-react/types' import { WalletConnect } from '@web3-react/walletconnect-v2' import { useAsyncError } from 'components/Error/ErrorBoundary' -import { L1_CHAIN_IDS, L2_CHAIN_IDS, SupportedChainId } from 'constants/chains' +import { L1_CHAIN_IDS, L2_CHAIN_IDS } from 'constants/chains' import { MetaMaskConnectionError } from 'errors' import { PropsWithChildren, useEffect, useMemo, useRef } from 'react' import { Layer } from 'theme' @@ -24,7 +25,7 @@ import { toJsonRpcUrlMap, } from './useJsonRpcUrlsMap' -const DEFAULT_CHAIN_ID = SupportedChainId.MAINNET +const DEFAULT_CHAIN_ID = ChainId.MAINNET type Web3ReactConnector = [T, Web3ReactHooks] @@ -37,7 +38,7 @@ interface Web3ReactConnectors { } export interface ProviderProps { - defaultChainId?: SupportedChainId + defaultChainId?: ChainId jsonRpcUrlMap?: JsonRpcConnectionMap /** * If null, no auto-connection (MetaMask or WalletConnect) will be attempted. @@ -57,7 +58,7 @@ export function TestableProvider({ provider, children }: PropsWithChildren<{ pro } export function Provider({ - defaultChainId: chainId = SupportedChainId.MAINNET, + defaultChainId: chainId = ChainId.MAINNET, jsonRpcUrlMap, provider, children, @@ -65,7 +66,7 @@ export function Provider({ const defaultChainId = useMemo(() => { if (!supportedChainId(chainId)) { console.warn( - `Unsupported chainId: ${chainId}. Falling back to ${DEFAULT_CHAIN_ID} (${SupportedChainId[DEFAULT_CHAIN_ID]}).` + `Unsupported chainId: ${chainId}. Falling back to ${DEFAULT_CHAIN_ID} (${ChainId[DEFAULT_CHAIN_ID]}).` ) return DEFAULT_CHAIN_ID } @@ -169,7 +170,7 @@ function useWeb3ReactConnectors({ defaultChainId, provider, jsonRpcUrlMap }: Pro rpcMap: urlMap, projectId: 'c6c9bacd35afa3eb9e6cccf6d8464395', // this requires the connecting wallet to support eth mainnet - chains: [SupportedChainId.MAINNET], + chains: [ChainId.MAINNET], optionalChains: [...L1_CHAIN_IDS, ...L2_CHAIN_IDS], optionalMethods: ['eth_signTypedData', 'eth_signTypedData_v4', 'eth_sign'], qrModalOptions: { diff --git a/src/hooks/web3/useJsonRpcUrlsMap.tsx b/src/hooks/web3/useJsonRpcUrlsMap.tsx index 3cea0ce7d..ec1bf29e8 100644 --- a/src/hooks/web3/useJsonRpcUrlsMap.tsx +++ b/src/hooks/web3/useJsonRpcUrlsMap.tsx @@ -1,5 +1,5 @@ import { JsonRpcProvider, StaticJsonRpcProvider } from '@ethersproject/providers' -import { SupportedChainId } from 'constants/chains' +import { ChainId } from '@uniswap/sdk-core' import { JSON_RPC_FALLBACK_ENDPOINTS } from 'constants/jsonRpcEndpoints' import { createContext, PropsWithChildren, useContext, useMemo } from 'react' @@ -11,33 +11,36 @@ export function Provider({ jsonRpcMap, children }: PropsWithChildren<{ jsonRpcMa return {children} } -export default function useJsonRpcUrlsMap(): Record { +export default function useJsonRpcUrlsMap(): Record { const jsonRpcMap = useContext(JsonRpcUrlMapContext) return useMemo(() => toJsonRpcUrlsMap(jsonRpcMap), [jsonRpcMap]) } -function toJsonRpcMap(getChainConnections: (chainId: SupportedChainId) => T): Record { +function toJsonRpcMap(getChainConnections: (chainId: ChainId) => T): Record { return { - [SupportedChainId.MAINNET]: getChainConnections(SupportedChainId.MAINNET), - [SupportedChainId.ROPSTEN]: getChainConnections(SupportedChainId.ROPSTEN), - [SupportedChainId.RINKEBY]: getChainConnections(SupportedChainId.RINKEBY), - [SupportedChainId.GOERLI]: getChainConnections(SupportedChainId.GOERLI), - [SupportedChainId.KOVAN]: getChainConnections(SupportedChainId.KOVAN), - [SupportedChainId.POLYGON]: getChainConnections(SupportedChainId.POLYGON), - [SupportedChainId.POLYGON_MUMBAI]: getChainConnections(SupportedChainId.POLYGON_MUMBAI), - [SupportedChainId.ARBITRUM_ONE]: getChainConnections(SupportedChainId.ARBITRUM_ONE), - [SupportedChainId.ARBITRUM_RINKEBY]: getChainConnections(SupportedChainId.ARBITRUM_RINKEBY), - [SupportedChainId.OPTIMISM]: getChainConnections(SupportedChainId.OPTIMISM), - [SupportedChainId.OPTIMISM_GOERLI]: getChainConnections(SupportedChainId.OPTIMISM_GOERLI), - [SupportedChainId.CELO]: getChainConnections(SupportedChainId.CELO), - [SupportedChainId.CELO_ALFAJORES]: getChainConnections(SupportedChainId.CELO_ALFAJORES), - [SupportedChainId.BNB]: getChainConnections(SupportedChainId.BNB), + [ChainId.MAINNET]: getChainConnections(ChainId.MAINNET), + [ChainId.GOERLI]: getChainConnections(ChainId.GOERLI), + [ChainId.SEPOLIA]: getChainConnections(ChainId.SEPOLIA), + [ChainId.POLYGON]: getChainConnections(ChainId.POLYGON), + [ChainId.POLYGON_MUMBAI]: getChainConnections(ChainId.POLYGON_MUMBAI), + [ChainId.ARBITRUM_ONE]: getChainConnections(ChainId.ARBITRUM_ONE), + [ChainId.ARBITRUM_GOERLI]: getChainConnections(ChainId.ARBITRUM_GOERLI), + [ChainId.OPTIMISM]: getChainConnections(ChainId.OPTIMISM), + [ChainId.OPTIMISM_GOERLI]: getChainConnections(ChainId.OPTIMISM_GOERLI), + [ChainId.CELO]: getChainConnections(ChainId.CELO), + [ChainId.CELO_ALFAJORES]: getChainConnections(ChainId.CELO_ALFAJORES), + [ChainId.BNB]: getChainConnections(ChainId.BNB), + [ChainId.GNOSIS]: getChainConnections(ChainId.GNOSIS), + [ChainId.MOONBEAM]: getChainConnections(ChainId.MOONBEAM), + [ChainId.AVALANCHE]: getChainConnections(ChainId.AVALANCHE), + [ChainId.BASE]: getChainConnections(ChainId.BASE), + [ChainId.BASE_GOERLI]: getChainConnections(ChainId.BASE_GOERLI), } } function getChainConnections( connectionMap: JsonRpcConnectionMap | undefined, - chainId: SupportedChainId + chainId: ChainId ): (string | JsonRpcProvider)[] { const value = connectionMap?.[chainId] return (Array.isArray(value) ? value : [value]) @@ -45,26 +48,24 @@ function getChainConnections( .concat(...JSON_RPC_FALLBACK_ENDPOINTS[chainId]) } -export function toJsonRpcConnectionMap( - connectionMap?: JsonRpcConnectionMap -): Record { - function getJsonRpcProvider(chainId: SupportedChainId): JsonRpcProvider { +export function toJsonRpcConnectionMap(connectionMap?: JsonRpcConnectionMap): Record { + function getJsonRpcProvider(chainId: ChainId): JsonRpcProvider { const [connection] = getChainConnections(connectionMap, chainId) return JsonRpcProvider.isProvider(connection) ? connection : new StaticJsonRpcProvider(connection, Number(chainId)) } return toJsonRpcMap(getJsonRpcProvider) } -export function toJsonRpcUrlMap(connectionMap?: JsonRpcConnectionMap): Record { - function getJsonRpcUrl(chainId: SupportedChainId): string { +export function toJsonRpcUrlMap(connectionMap?: JsonRpcConnectionMap): Record { + function getJsonRpcUrl(chainId: ChainId): string { const [connection] = getChainConnections(connectionMap, chainId) return JsonRpcProvider.isProvider(connection) ? connection.connection.url : connection } return toJsonRpcMap(getJsonRpcUrl) } -export function toJsonRpcUrlsMap(connectionMap?: JsonRpcConnectionMap): Record { - function getJsonRpcUrls(chainId: SupportedChainId): string[] { +export function toJsonRpcUrlsMap(connectionMap?: JsonRpcConnectionMap): Record { + function getJsonRpcUrls(chainId: ChainId): string[] { const connections = getChainConnections(connectionMap, chainId) return connections.map((connection) => JsonRpcProvider.isProvider(connection) ? connection.connection.url : connection diff --git a/src/index.tsx b/src/index.tsx index 23ff1b246..76039084c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,14 +7,13 @@ export { getAssetsRepoURI, getNativeLogoURI, Logo, LogoUpdater, useLogo, useLogo export type { Provider as EthersProvider } from '@ethersproject/abstract-provider' export type { JsonRpcProvider } from '@ethersproject/providers' export type { Currency } from '@uniswap/sdk-core' -export { TradeType } from '@uniswap/sdk-core' +export { ChainId, TradeType } from '@uniswap/sdk-core' export type { TokenInfo } from '@uniswap/token-lists' export type { Provider as Eip1193Provider } from '@web3-react/types' export type { DialogOptions, DialogWidgetProps } from 'components/Dialog' export { DialogAnimationType } from 'components/Dialog' export type { SwapWidgetSkeletonProps } from 'components/Swap/Skeleton' export { SwapWidgetSkeleton } from 'components/Swap/Skeleton' -export { SupportedChainId } from 'constants/chains' export type { SupportedLocale } from 'constants/locales' export { DEFAULT_LOCALE, SUPPORTED_LOCALES } from 'constants/locales' export type { WidgetPromise } from 'errors' diff --git a/src/state/swap/index.ts b/src/state/swap/index.ts index 4092d0027..6524b3688 100644 --- a/src/state/swap/index.ts +++ b/src/state/swap/index.ts @@ -1,6 +1,5 @@ -import { Currency, TradeType } from '@uniswap/sdk-core' +import { ChainId, Currency, TradeType } from '@uniswap/sdk-core' import { FeeOptions } from '@uniswap/v3-sdk' -import { SupportedChainId } from 'constants/chains' import { nativeOnChain } from 'constants/tokens' import { atom } from 'jotai' import { atomWithImmer } from 'jotai/immer' @@ -39,7 +38,7 @@ export interface Swap { const initialSwap: Swap = { type: TradeType.EXACT_INPUT, amount: '', - [Field.INPUT]: nativeOnChain(SupportedChainId.MAINNET), + [Field.INPUT]: nativeOnChain(ChainId.MAINNET), } export const controlledAtom = atom(undefined) diff --git a/src/test/index.tsx b/src/test/index.tsx index 225b79d17..1e2e996be 100644 --- a/src/test/index.tsx +++ b/src/test/index.tsx @@ -25,7 +25,7 @@ import { Provider as ReduxProvider } from 'react-redux' import { store } from 'state' import { Provider as ThemeProvider } from 'theme' import JsonRpcConnector from 'utils/JsonRpcConnector' -import { WalletConnectPopup, WalletConnectQR } from 'utils/WalletConnect' +import { WalletConnectQR } from 'utils/WalletConnect' export * from '@testing-library/react' export { default as userEvent } from '@testing-library/user-event' @@ -55,8 +55,8 @@ export function TestableWidget(props: PropsWithChildren) { connectors={{ user: {} as JsonRpcConnector, metaMask: {} as MetaMask, - walletConnect: {} as WalletConnectPopup, walletConnectQR: {} as WalletConnectQR, + walletConnect: {} as WalletConnectQR, network: {} as Network, }} > diff --git a/src/utils/constructSameAddressMap.ts b/src/utils/constructSameAddressMap.ts index 132d4fbf7..a111ed283 100644 --- a/src/utils/constructSameAddressMap.ts +++ b/src/utils/constructSameAddressMap.ts @@ -1,16 +1,10 @@ -import { SupportedChainId } from 'constants/chains' +import { ChainId } from '@uniswap/sdk-core' -const DEFAULT_NETWORKS = [ - SupportedChainId.MAINNET, - SupportedChainId.ROPSTEN, - SupportedChainId.RINKEBY, - SupportedChainId.GOERLI, - SupportedChainId.KOVAN, -] +const DEFAULT_NETWORKS = [ChainId.MAINNET, ChainId.GOERLI] export function constructSameAddressMap( address: T, - additionalNetworks: SupportedChainId[] = [] + additionalNetworks: ChainId[] = [] ): { [chainId: number]: T } { return DEFAULT_NETWORKS.concat(additionalNetworks).reduce<{ [chainId: number]: T }>((memo, chainId) => { memo[chainId] = address diff --git a/src/utils/getExplorerLink.test.ts b/src/utils/getExplorerLink.test.ts index 97a0da36e..0994f4d7f 100644 --- a/src/utils/getExplorerLink.test.ts +++ b/src/utils/getExplorerLink.test.ts @@ -30,13 +30,10 @@ describe('#getExplorerLink', () => { it('alfajores', () => { expect(getExplorerLink(44787, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://alfajores.celoscan.io/address/abc') }) - it('ropsten', () => { - expect(getExplorerLink(3, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://ropsten.etherscan.io/address/abc') - }) - it('enum', () => { - expect(getExplorerLink(4, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://rinkeby.etherscan.io/address/abc') - }) it('bnb chain', () => { expect(getExplorerLink(56, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://bscscan.com/address/abc') }) + it('base chain', () => { + expect(getExplorerLink(8453, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://basescan.org/address/abc') + }) }) diff --git a/src/utils/getExplorerLink.ts b/src/utils/getExplorerLink.ts index 4ad6ab6c4..7d5935be3 100644 --- a/src/utils/getExplorerLink.ts +++ b/src/utils/getExplorerLink.ts @@ -1,18 +1,17 @@ -import { SupportedChainId } from 'constants/chains' +import { ChainId } from '@uniswap/sdk-core' const ETHERSCAN_PREFIXES: { [chainId: number]: string } = { - [SupportedChainId.MAINNET]: 'https://etherscan.io', - [SupportedChainId.ROPSTEN]: 'https://ropsten.etherscan.io', - [SupportedChainId.RINKEBY]: 'https://rinkeby.etherscan.io', - [SupportedChainId.GOERLI]: 'https://goerli.etherscan.io', - [SupportedChainId.KOVAN]: 'https://kovan.etherscan.io', - [SupportedChainId.OPTIMISM]: 'https://optimistic.etherscan.io', - [SupportedChainId.OPTIMISM_GOERLI]: 'https://goerli-optimism.etherscan.io', - [SupportedChainId.POLYGON_MUMBAI]: 'https://mumbai.polygonscan.com', - [SupportedChainId.POLYGON]: 'https://polygonscan.com', - [SupportedChainId.CELO]: 'https://celoscan.io', - [SupportedChainId.CELO_ALFAJORES]: 'https://alfajores.celoscan.io', - [SupportedChainId.BNB]: 'https://bscscan.com', + [ChainId.MAINNET]: 'https://etherscan.io', + [ChainId.GOERLI]: 'https://goerli.etherscan.io', + [ChainId.OPTIMISM]: 'https://optimistic.etherscan.io', + [ChainId.OPTIMISM_GOERLI]: 'https://goerli-optimism.etherscan.io', + [ChainId.POLYGON_MUMBAI]: 'https://mumbai.polygonscan.com', + [ChainId.POLYGON]: 'https://polygonscan.com', + [ChainId.CELO]: 'https://celoscan.io', + [ChainId.CELO_ALFAJORES]: 'https://alfajores.celoscan.io', + [ChainId.BNB]: 'https://bscscan.com', + [ChainId.BASE]: 'https://basescan.org', + [ChainId.BASE_GOERLI]: 'https://goerli.basescan.org', } export enum ExplorerDataType { @@ -29,7 +28,7 @@ export enum ExplorerDataType { * @param type the type of the data */ export function getExplorerLink(chainId: number, data: string, type: ExplorerDataType): string { - if (chainId === SupportedChainId.ARBITRUM_ONE) { + if (chainId === ChainId.ARBITRUM_ONE) { switch (type) { case ExplorerDataType.TRANSACTION: return `https://arbiscan.io/tx/${data}` @@ -43,20 +42,6 @@ export function getExplorerLink(chainId: number, data: string, type: ExplorerDat } } - if (chainId === SupportedChainId.ARBITRUM_RINKEBY) { - switch (type) { - case ExplorerDataType.TRANSACTION: - return `https://rinkeby-explorer.arbitrum.io/tx/${data}` - case ExplorerDataType.ADDRESS: - case ExplorerDataType.TOKEN: - return `https://rinkeby-explorer.arbitrum.io/address/${data}` - case ExplorerDataType.BLOCK: - return `https://rinkeby-explorer.arbitrum.io/block/${data}` - default: - return `https://rinkeby-explorer.arbitrum.io/` - } - } - const prefix = ETHERSCAN_PREFIXES[chainId] ?? 'https://etherscan.io' switch (type) { @@ -67,7 +52,7 @@ export function getExplorerLink(chainId: number, data: string, type: ExplorerDat return `${prefix}/token/${data}` case ExplorerDataType.BLOCK: - if (chainId === SupportedChainId.OPTIMISM || chainId === SupportedChainId.OPTIMISM_GOERLI) { + if (chainId === ChainId.OPTIMISM || chainId === ChainId.OPTIMISM_GOERLI) { return `${prefix}/tx/${data}` } return `${prefix}/block/${data}` diff --git a/src/utils/supportedChainId.ts b/src/utils/supportedChainId.ts index b6c6d474f..dbd809d22 100644 --- a/src/utils/supportedChainId.ts +++ b/src/utils/supportedChainId.ts @@ -1,11 +1,11 @@ -import { SupportedChainId } from 'constants/chains' +import { ChainId } from '@uniswap/sdk-core' /** * Returns the input chain ID if chain is supported. If not, return undefined * @param chainId a chain ID, which will be returned if it is a supported chain ID */ -export function supportedChainId(chainId: number | undefined): SupportedChainId | undefined { - if (typeof chainId === 'number' && chainId in SupportedChainId) { +export function supportedChainId(chainId: number | undefined): ChainId | undefined { + if (typeof chainId === 'number' && chainId in ChainId) { return chainId } return undefined diff --git a/yarn.lock b/yarn.lock index 001d41455..f71d2e2f1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3730,10 +3730,10 @@ resolved "https://registry.yarnpkg.com/@uniswap/default-token-list/-/default-token-list-11.4.0.tgz#d0f8073e4a270ca4bd3c2604ea89c22e0f661efa" integrity sha512-ADAksIMv/emjJpeD9Rx/1vPBfpI5+Qkf/jWMOnNpRgW1MIGbRPKsVWyZTFeebx6p0MxXnxN70PbysgswWNmemA== -"@uniswap/default-token-list@^9.0.0": - version "9.0.0" - resolved "https://registry.yarnpkg.com/@uniswap/default-token-list/-/default-token-list-9.0.0.tgz#35e070095ac24d24ef03877842c5d46807b59c87" - integrity sha512-a62uqv5ApULDVEXCOursXIaEoxP4MtlzdNSiQikYl1x9RfsUAZXl9dBtCo2d1Ne+iS1THic1oCJMshNtT9Z0EQ== +"@uniswap/default-token-list@^11.5.0": + version "11.5.0" + resolved "https://registry.yarnpkg.com/@uniswap/default-token-list/-/default-token-list-11.5.0.tgz#a9c26837aa8ac179f23e7f5a13b5549c25238e61" + integrity sha512-ZlZZf9nFQze8aprGRZRmE+4wc0SzHpfGrlNwbp7ChP8Ajlrr72Ed+axO41shb65yEx2CxXn7twITVfw3/Ks61w== "@uniswap/lib@^4.0.1-alpha": version "4.0.1-alpha" @@ -3776,18 +3776,19 @@ tiny-invariant "^1.1.0" toformat "^2.0.0" -"@uniswap/smart-order-router@^3.13.7": - version "3.13.7" - resolved "https://registry.yarnpkg.com/@uniswap/smart-order-router/-/smart-order-router-3.13.7.tgz#0355402b4459a3a8e78a2dc68c1c6aa7d4386b5c" - integrity sha512-fJDyUngHWw2lH0qIkDzeUqHgP2VLAq33o5O9yM75nQi6LrD8fEIgsfdzFbF8c+F7enAFtA6Xl4lf5AlHKNaXSg== +"@uniswap/smart-order-router@^3.15.2": + version "3.15.2" + resolved "https://registry.yarnpkg.com/@uniswap/smart-order-router/-/smart-order-router-3.15.2.tgz#7f9c20a384295e041360713dc8f95c4328c04425" + integrity sha512-sQveOEWNgPSk/c64X45FdJUntBOPFN6nqcrEAqOMHn3V0f3zvDa+77Agye0jhlE6XaAlX8IYpXX8txsA1SC8qQ== dependencies: "@uniswap/default-token-list" "^11.2.0" "@uniswap/permit2-sdk" "^1.2.0" "@uniswap/router-sdk" "^1.6.0" + "@uniswap/sdk-core" "^4.0.6" "@uniswap/swap-router-contracts" "^1.3.0" "@uniswap/token-lists" "^1.0.0-beta.31" "@uniswap/universal-router" "^1.0.1" - "@uniswap/universal-router-sdk" "^1.5.4" + "@uniswap/universal-router-sdk" "^1.5.7" "@uniswap/v2-sdk" "^3.2.0" "@uniswap/v3-sdk" "^3.10.0" async-retry "^1.3.1" @@ -3826,15 +3827,15 @@ dotenv "^14.2.0" hardhat-watcher "^2.1.1" -"@uniswap/token-lists@^1.0.0-beta.30", "@uniswap/token-lists@^1.0.0-beta.31": +"@uniswap/token-lists@^1.0.0-beta.31", "@uniswap/token-lists@^1.0.0-beta.33": version "1.0.0-beta.33" resolved "https://registry.yarnpkg.com/@uniswap/token-lists/-/token-lists-1.0.0-beta.33.tgz#966ba96c9ccc8f0e9e09809890b438203f2b1911" integrity sha512-JQkXcpRI3jFG8y3/CGC4TS8NkDgcxXaOQuYW8Qdvd6DcDiIyg2vVYCG9igFEzF0G6UvxgHkBKC7cWCgzZNYvQg== -"@uniswap/universal-router-sdk@^1.5.4", "@uniswap/universal-router-sdk@^1.5.6": - version "1.5.6" - resolved "https://registry.yarnpkg.com/@uniswap/universal-router-sdk/-/universal-router-sdk-1.5.6.tgz#274a6ac5df032c34544005fe329aa9e2aac9ade6" - integrity sha512-ZD27U+kugMRJRVEX0oWZsRCw1n5vBN3I17Q22IWE+w/WhOJSppUr6PLo9u4HRdqXTZET7gubnlRc0LOAEkkSkQ== +"@uniswap/universal-router-sdk@^1.5.7": + version "1.5.7" + resolved "https://registry.yarnpkg.com/@uniswap/universal-router-sdk/-/universal-router-sdk-1.5.7.tgz#d79dedcdf66197695d57ef8c80336da807488871" + integrity sha512-5T08dTZoAEN3W7fw467WoNwzfF8Ks5+t4/l0xVAhadUNq6UB/Ng9q5P70j+D+FVLwZbcbyv5zIkPtooADfjEKw== dependencies: "@uniswap/permit2-sdk" "^1.2.0" "@uniswap/router-sdk" "^1.6.0"