Commit fb389137 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

feat: adds ethers provider tracing (#4614)

parent c14b6a78
......@@ -81,6 +81,18 @@
}
]
}
],
"@typescript-eslint/no-restricted-imports": [
"error",
{
"paths": [
{
"name": "@ethersproject/providers",
"message": "Please only use Providers instantiated in constants/providers to improve traceability.",
"allowTypeImports": true
}
]
}
]
}
}
......@@ -3,6 +3,7 @@
*/
import { Eip1193Bridge } from '@ethersproject/experimental/lib/eip1193-bridge'
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { JsonRpcProvider } from '@ethersproject/providers'
import { Wallet } from '@ethersproject/wallet'
......
......@@ -5,6 +5,7 @@ import { RedesignVariant, useRedesignFlag } from 'featureFlags/flags/redesign'
import { TokensVariant, useTokensFlag } from 'featureFlags/flags/tokens'
import { TokenSafetyVariant, useTokenSafetyFlag } from 'featureFlags/flags/tokenSafety'
import { TokensNetworkFilterVariant, useTokensNetworkFilterFlag } from 'featureFlags/flags/tokensNetworkFilter'
import { TraceJsonRpcVariant, useTraceJsonRpcFlag } from 'featureFlags/flags/traceJsonRpc'
import { useAtomValue, useUpdateAtom } from 'jotai/utils'
import { Children, PropsWithChildren, ReactElement, ReactNode, useCallback, useState } from 'react'
import { X } from 'react-feather'
......@@ -241,6 +242,14 @@ export default function FeatureFlagModal() {
<FeatureFlagGroup name="Phase 1">
<FeatureFlagOption variant={NftVariant} value={useNftFlag()} featureFlag={FeatureFlag.nft} label="NFTs" />
</FeatureFlagGroup>
<FeatureFlagGroup name="Debug">
<FeatureFlagOption
variant={TraceJsonRpcVariant}
value={useTraceJsonRpcFlag()}
featureFlag={FeatureFlag.traceJsonRpc}
label="Enables JSON-RPC tracing"
/>
</FeatureFlagGroup>
<SaveButton onClick={() => window.location.reload()}>Reload</SaveButton>
</Modal>
)
......
import { Web3ReactHooks, Web3ReactProvider } from '@web3-react/core'
import { SupportedChainId } from '@uniswap/widgets'
import { useWeb3React, Web3ReactHooks, Web3ReactProvider } from '@web3-react/core'
import { Connector } from '@web3-react/types'
import { Connection } from 'connection'
import { getConnectionName } from 'connection/utils'
import { RPC_PROVIDERS } from 'constants/providers'
import { TraceJsonRpcVariant, useTraceJsonRpcFlag } from 'featureFlags/flags/traceJsonRpc'
import useEagerlyConnect from 'hooks/useEagerlyConnect'
import useOrderedConnections from 'hooks/useOrderedConnections'
import { ReactNode, useMemo } from 'react'
import { ReactNode, useEffect, useMemo } from 'react'
export default function Web3Provider({ children }: { children: ReactNode }) {
useEagerlyConnect()
......@@ -15,7 +18,37 @@ export default function Web3Provider({ children }: { children: ReactNode }) {
return (
<Web3ReactProvider connectors={connectors} key={key}>
<Tracer />
{children}
</Web3ReactProvider>
)
}
function Tracer() {
const { chainId, provider } = useWeb3React()
const networkProvider = RPC_PROVIDERS[(chainId || SupportedChainId.MAINNET) as SupportedChainId]
const shouldTrace = useTraceJsonRpcFlag() === TraceJsonRpcVariant.Enabled
useEffect(() => {
if (shouldTrace) {
provider?.on('debug', trace)
if (provider !== networkProvider) {
networkProvider.on('debug', trace)
}
}
return () => {
provider?.off('debug', trace)
networkProvider.off('debug', trace)
}
}, [networkProvider, provider, shouldTrace])
return null
}
function trace(event: any) {
if (event.action !== 'request') return
const { method, id, params } = event.request
console.groupCollapsed(method, id)
console.debug(params)
console.groupEnd()
}
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import StakingRewardsJson from '@uniswap/liquidity-staker/build/StakingRewards.json'
import { useWeb3React } from '@web3-react/core'
......
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import StakingRewardsJson from '@uniswap/liquidity-staker/build/StakingRewards.json'
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
......
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import StakingRewardsJson from '@uniswap/liquidity-staker/build/StakingRewards.json'
import { useWeb3React } from '@web3-react/core'
......
......@@ -8,7 +8,8 @@ import { WalletConnect } from '@web3-react/walletconnect'
import { SupportedChainId } from 'constants/chains'
import UNISWAP_LOGO_URL from '../assets/svg/logo.svg'
import { RPC_PROVIDERS, RPC_URLS } from '../constants/networks'
import { RPC_URLS } from '../constants/networks'
import { RPC_PROVIDERS } from '../constants/providers'
export enum ConnectionType {
INJECTED = 'INJECTED',
......@@ -73,7 +74,7 @@ const [web3CoinbaseWallet, web3CoinbaseWalletHooks] = initializeConnector<Coinba
new CoinbaseWallet({
actions,
options: {
url: RPC_URLS[SupportedChainId.MAINNET],
url: RPC_URLS[SupportedChainId.MAINNET][0],
appName: 'Uniswap',
appLogoUrl: UNISWAP_LOGO_URL,
reloadOnDisconnect: false,
......
import { StaticJsonRpcProvider } from '@ethersproject/providers'
import { SupportedChainId } from './chains'
const INFURA_KEY = process.env.REACT_APP_INFURA_KEY
......@@ -8,36 +6,132 @@ if (typeof INFURA_KEY === 'undefined') {
}
/**
* These are the network URLs used by the interface when there is not another available source of chain data
* Fallback JSON-RPC endpoints.
* These are used if the integrator does not provide an endpoint, or if the endpoint does not work.
*
* MetaMask allows switching to any URL, but displays a warning if it is not on the "Safe" list:
* https://github.com/MetaMask/metamask-mobile/blob/bdb7f37c90e4fc923881a07fca38d4e77c73a579/app/core/RPCMethods/wallet_addEthereumChain.js#L228-L235
* https://chainid.network/chains.json
*
* These "Safe" URLs are listed first, followed by other fallback URLs, which are taken from chainlist.org.
*/
export const RPC_URLS: { [key in SupportedChainId]: string } = {
[SupportedChainId.MAINNET]: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.RINKEBY]: `https://rinkeby.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.ROPSTEN]: `https://ropsten.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.GOERLI]: `https://goerli.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.KOVAN]: `https://kovan.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.OPTIMISM]: `https://optimism-mainnet.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.OPTIMISTIC_KOVAN]: `https://optimism-kovan.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.ARBITRUM_ONE]: `https://arbitrum-mainnet.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.ARBITRUM_RINKEBY]: `https://arbitrum-rinkeby.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.POLYGON]: `https://polygon-mainnet.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.POLYGON_MUMBAI]: `https://polygon-mumbai.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.CELO]: `https://forno.celo.org`,
[SupportedChainId.CELO_ALFAJORES]: `https://alfajores-forno.celo-testnet.org`,
export const FALLBACK_URLS: { [key in SupportedChainId]: string[] } = {
[SupportedChainId.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]: [
// "Safe" URLs
'https://rpc.goerli.mudit.blog/',
// "Fallback" URLs
'https://rpc.ankr.com/eth_goerli',
],
[SupportedChainId.KOVAN]: [
// "Safe" URLs
'https://kovan.poa.network',
// "Fallback" URLs
'https://eth-kovan.public.blastapi.io',
],
[SupportedChainId.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]: [
// "Safe" URLs
'https://matic-mumbai.chainstacklabs.com',
'https://rpc-mumbai.maticvigil.com',
'https://matic-testnet-archive-rpc.bwarelabs.com',
],
[SupportedChainId.ARBITRUM_ONE]: [
// "Safe" URLs
'https://arb1.arbitrum.io/rpc',
// "Fallback" URLs
'https://arbitrum.public-rpc.com',
],
[SupportedChainId.ARBITRUM_RINKEBY]: [
// "Safe" URLs
'https://rinkeby.arbitrum.io/rpc',
],
[SupportedChainId.OPTIMISM]: [
// "Safe" URLs
'https://mainnet.optimism.io/',
// "Fallback" URLs
'https://rpc.ankr.com/optimism',
],
[SupportedChainId.OPTIMISTIC_KOVAN]: [
// "Safe" URLs
'https://kovan.optimism.io',
],
[SupportedChainId.CELO]: [
// "Safe" URLs
`https://forno.celo.org`,
],
[SupportedChainId.CELO_ALFAJORES]: [
// "Safe" URLs
`https://alfajores-forno.celo-testnet.org`,
],
}
export const RPC_PROVIDERS: { [key in SupportedChainId]: StaticJsonRpcProvider } = {
[SupportedChainId.MAINNET]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.MAINNET]),
[SupportedChainId.RINKEBY]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.RINKEBY]),
[SupportedChainId.ROPSTEN]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.ROPSTEN]),
[SupportedChainId.GOERLI]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.GOERLI]),
[SupportedChainId.KOVAN]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.KOVAN]),
[SupportedChainId.OPTIMISM]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.OPTIMISM]),
[SupportedChainId.OPTIMISTIC_KOVAN]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.OPTIMISTIC_KOVAN]),
[SupportedChainId.ARBITRUM_ONE]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.ARBITRUM_ONE]),
[SupportedChainId.ARBITRUM_RINKEBY]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.ARBITRUM_RINKEBY]),
[SupportedChainId.POLYGON]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.POLYGON]),
[SupportedChainId.POLYGON_MUMBAI]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.POLYGON_MUMBAI]),
[SupportedChainId.CELO]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.CELO]),
[SupportedChainId.CELO_ALFAJORES]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.CELO_ALFAJORES]),
/**
* Known JSON-RPC endpoints.
* These are the URLs used by the interface when there is not another available source of chain data.
*/
export const RPC_URLS: { [key in SupportedChainId]: string[] } = {
[SupportedChainId.MAINNET]: [
`https://mainnet.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.MAINNET],
],
[SupportedChainId.RINKEBY]: [
`https://rinkeby.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.RINKEBY],
],
[SupportedChainId.ROPSTEN]: [
`https://ropsten.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.ROPSTEN],
],
[SupportedChainId.GOERLI]: [`https://goerli.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[SupportedChainId.GOERLI]],
[SupportedChainId.KOVAN]: [`https://kovan.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[SupportedChainId.KOVAN]],
[SupportedChainId.OPTIMISM]: [
`https://optimism-mainnet.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.OPTIMISM],
],
[SupportedChainId.OPTIMISTIC_KOVAN]: [
`https://optimism-kovan.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.OPTIMISTIC_KOVAN],
],
[SupportedChainId.ARBITRUM_ONE]: [
`https://arbitrum-mainnet.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.ARBITRUM_ONE],
],
[SupportedChainId.ARBITRUM_RINKEBY]: [
`https://arbitrum-rinkeby.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.ARBITRUM_RINKEBY],
],
[SupportedChainId.POLYGON]: [
`https://polygon-mainnet.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.POLYGON],
],
[SupportedChainId.POLYGON_MUMBAI]: [
`https://polygon-mumbai.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.POLYGON_MUMBAI],
],
[SupportedChainId.CELO]: FALLBACK_URLS[SupportedChainId.CELO],
[SupportedChainId.CELO_ALFAJORES]: FALLBACK_URLS[SupportedChainId.CELO_ALFAJORES],
}
// This is the only file which should instantiate new Providers.
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { StaticJsonRpcProvider } from '@ethersproject/providers'
import { SupportedChainId } from './chains'
import { RPC_URLS } from './networks'
class AppJsonRpcProvider extends StaticJsonRpcProvider {
constructor(urls: string[]) {
super(urls[0])
}
}
/**
* These are the only JsonRpcProviders used directly by the interface.
*/
export const RPC_PROVIDERS: { [key in SupportedChainId]: StaticJsonRpcProvider } = {
[SupportedChainId.MAINNET]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.MAINNET]),
[SupportedChainId.RINKEBY]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.RINKEBY]),
[SupportedChainId.ROPSTEN]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.ROPSTEN]),
[SupportedChainId.GOERLI]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.GOERLI]),
[SupportedChainId.KOVAN]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.KOVAN]),
[SupportedChainId.OPTIMISM]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.OPTIMISM]),
[SupportedChainId.OPTIMISTIC_KOVAN]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.OPTIMISTIC_KOVAN]),
[SupportedChainId.ARBITRUM_ONE]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.ARBITRUM_ONE]),
[SupportedChainId.ARBITRUM_RINKEBY]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.ARBITRUM_RINKEBY]),
[SupportedChainId.POLYGON]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.POLYGON]),
[SupportedChainId.POLYGON_MUMBAI]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.POLYGON_MUMBAI]),
[SupportedChainId.CELO]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.CELO]),
[SupportedChainId.CELO_ALFAJORES]: new AppJsonRpcProvider(RPC_URLS[SupportedChainId.CELO_ALFAJORES]),
}
......@@ -5,4 +5,5 @@ export enum FeatureFlag {
tokens = 'tokens',
tokensNetworkFilter = 'tokensNetworkFilter',
tokenSafety = 'tokenSafety',
traceJsonRpc = 'traceJsonRpc',
}
import { BaseVariant, FeatureFlag, useBaseFlag } from '../index'
export function useTraceJsonRpcFlag(): BaseVariant {
return useBaseFlag(FeatureFlag.traceJsonRpc)
}
export { BaseVariant as TraceJsonRpcVariant }
import { nanoid } from '@reduxjs/toolkit'
import { TokenList } from '@uniswap/token-lists'
import { SupportedChainId } from 'constants/chains'
import { RPC_PROVIDERS } from 'constants/networks'
import { RPC_PROVIDERS } from 'constants/providers'
import getTokenList from 'lib/hooks/useTokenList/fetchTokenList'
import resolveENSContentHash from 'lib/utils/resolveENSContentHash'
import { useCallback } from 'react'
......
import { BigNumber } from '@ethersproject/bignumber'
import { JsonRpcProvider, TransactionResponse } from '@ethersproject/providers'
import type { JsonRpcProvider, TransactionResponse } from '@ethersproject/providers'
// eslint-disable-next-line no-restricted-imports
import { t, Trans } from '@lingui/macro'
import { Trade } from '@uniswap/router-sdk'
......
// eslint-disable-next-line no-restricted-imports
import { BigNumber } from '@ethersproject/bignumber'
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import { Trade } from '@uniswap/router-sdk'
import { Currency, Percent, TradeType } from '@uniswap/sdk-core'
......
import { MaxUint256 } from '@ethersproject/constants'
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { sendAnalyticsEvent } from 'components/AmplitudeAnalytics'
......
......@@ -2,7 +2,7 @@ import { Interface } from '@ethersproject/abi'
import { BigNumber } from '@ethersproject/bignumber'
import { hexStripZeros } from '@ethersproject/bytes'
import { ContractReceipt } from '@ethersproject/contracts'
import { JsonRpcSigner } from '@ethersproject/providers'
import type { JsonRpcSigner } from '@ethersproject/providers'
import create from 'zustand'
import { devtools } from 'zustand/middleware'
......
import { BigNumber } from '@ethersproject/bignumber'
import { Web3Provider } from '@ethersproject/providers'
import type { Web3Provider } from '@ethersproject/providers'
import { parseEther } from '@ethersproject/units'
import { useWeb3React } from '@web3-react/core'
import { useNativeCurrencyBalances } from 'state/connection/hooks'
......
import { Signer } from '@ethersproject/abstract-signer'
import { Contract } from '@ethersproject/contracts'
import { BaseProvider } from '@ethersproject/providers'
import type { BaseProvider } from '@ethersproject/providers'
const looksRareContract = new Contract('0xea37093ce161f090e443f304e1bf3a8f14d7bb40', [
{
......
import { Signer } from '@ethersproject/abstract-signer'
import { BigNumber } from '@ethersproject/bignumber'
import { Contract } from '@ethersproject/contracts'
import { JsonRpcSigner, Web3Provider } from '@ethersproject/providers'
import type { JsonRpcSigner, Web3Provider } from '@ethersproject/providers'
import { parseEther } from '@ethersproject/units'
import { addressesByNetwork, MakerOrder, signMakerOrder, SupportedChainId } from '@looksrare/sdk'
import { Seaport } from '@opensea/seaport-js'
......
......@@ -3,7 +3,7 @@ import { BigNumber, BigNumberish } from '@ethersproject/bignumber'
import { hexZeroPad } from '@ethersproject/bytes'
import { AddressZero } from '@ethersproject/constants'
import { keccak256 } from '@ethersproject/keccak256'
import { Web3Provider } from '@ethersproject/providers'
import type { Web3Provider } from '@ethersproject/providers'
import { randomBytes } from '@ethersproject/random'
const dataParamType = `tuple(address token, uint256 tokenId)[]`
......
import { BigNumber } from '@ethersproject/bignumber'
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import { FeeAmount, NonfungiblePositionManager } from '@uniswap/v3-sdk'
......
import { BigNumber } from '@ethersproject/bignumber'
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
......
import { Contract } from '@ethersproject/contracts'
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import { CurrencyAmount, Fraction, Percent, Price, Token } from '@uniswap/sdk-core'
import { FeeAmount, Pool, Position, priceToClosestTick, TickMath } from '@uniswap/v3-sdk'
......
......@@ -9,7 +9,7 @@ jest.mock('@web3-react/core', () => {
return {
...web3React,
useWeb3React: () => ({
chainId: 99999,
chainId: 42,
}),
}
})
......
import { BigNumber } from '@ethersproject/bignumber'
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Fraction, Percent, Price, Token } from '@uniswap/sdk-core'
import { NonfungiblePositionManager, Pool, Position } from '@uniswap/v3-sdk'
......
import { BigNumber } from '@ethersproject/bignumber'
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import { CurrencyAmount, Percent } from '@uniswap/sdk-core'
import { NonfungiblePositionManager } from '@uniswap/v3-sdk'
......
import { BigNumber } from '@ethersproject/bignumber'
import { Contract } from '@ethersproject/contracts'
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import { Currency, Percent } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
......
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { abi as MERKLE_DISTRIBUTOR_ABI } from '@uniswap/merkle-distributor/build/MerkleDistributor.json'
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
......
......@@ -2,7 +2,7 @@ import { defaultAbiCoder, Interface } from '@ethersproject/abi'
import { isAddress } from '@ethersproject/address'
import { BigNumber } from '@ethersproject/bignumber'
import { Contract } from '@ethersproject/contracts'
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { toUtf8String, Utf8ErrorFuncs, Utf8ErrorReason } from '@ethersproject/strings'
// eslint-disable-next-line no-restricted-imports
import { t } from '@lingui/macro'
......
import { Filter } from '@ethersproject/providers'
import type { Filter } from '@ethersproject/providers'
import { useWeb3React } from '@web3-react/core'
import useBlockNumber from 'lib/hooks/useBlockNumber'
import { useEffect, useMemo } from 'react'
......
import { Filter } from '@ethersproject/providers'
import type { Filter } from '@ethersproject/providers'
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { filterToKey, Log } from './utils'
......
import { Filter } from '@ethersproject/providers'
import type { Filter } from '@ethersproject/providers'
import { useWeb3React } from '@web3-react/core'
import useBlockNumber from 'lib/hooks/useBlockNumber'
import { useEffect, useMemo } from 'react'
......
import { Filter } from '@ethersproject/providers'
import type { Filter } from '@ethersproject/providers'
export interface Log {
topics: Array<string>
......
import { createApi, fetchBaseQuery, FetchBaseQueryError } from '@reduxjs/toolkit/query/react'
import { Protocol } from '@uniswap/router-sdk'
import { AlphaRouter, ChainId } from '@uniswap/smart-order-router'
import { RPC_PROVIDERS } from 'constants/networks'
import { RPC_PROVIDERS } from 'constants/providers'
import { getClientSideQuote, toSupportedChainId } from 'lib/hooks/routing/clientSideSmartOrderRouter'
import ms from 'ms.macro'
import qs from 'qs'
......
import { TransactionResponse } from '@ethersproject/providers'
import type { TransactionResponse } from '@ethersproject/providers'
import { Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { useCallback, useMemo } from 'react'
......
import { getAddress } from '@ethersproject/address'
import { AddressZero } from '@ethersproject/constants'
import { Contract } from '@ethersproject/contracts'
import { JsonRpcProvider, JsonRpcSigner } from '@ethersproject/providers'
import type { JsonRpcProvider, JsonRpcSigner } from '@ethersproject/providers'
import { Token } from '@uniswap/sdk-core'
import { ChainTokenMap } from 'lib/hooks/useTokenList/utils'
......
......@@ -2,36 +2,22 @@ import { Connector } from '@web3-react/types'
import { networkConnection, walletConnectConnection } from 'connection'
import { getChainInfo } from 'constants/chainInfo'
import { isSupportedChain, SupportedChainId } from 'constants/chains'
import { RPC_URLS } from 'constants/networks'
import { FALLBACK_URLS, RPC_URLS } from 'constants/networks'
function getRpcUrls(chainId: SupportedChainId): [string] {
function getRpcUrl(chainId: SupportedChainId): string {
switch (chainId) {
case SupportedChainId.MAINNET:
case SupportedChainId.RINKEBY:
case SupportedChainId.ROPSTEN:
case SupportedChainId.KOVAN:
case SupportedChainId.GOERLI:
return [RPC_URLS[chainId]]
case SupportedChainId.OPTIMISM:
return ['https://mainnet.optimism.io']
case SupportedChainId.OPTIMISTIC_KOVAN:
return ['https://kovan.optimism.io']
case SupportedChainId.ARBITRUM_ONE:
return ['https://arb1.arbitrum.io/rpc']
case SupportedChainId.ARBITRUM_RINKEBY:
return ['https://rinkeby.arbitrum.io/rpc']
case SupportedChainId.POLYGON:
return ['https://polygon-rpc.com/']
case SupportedChainId.POLYGON_MUMBAI:
return ['https://rpc-endpoints.superfluid.dev/mumbai']
case SupportedChainId.CELO:
return ['https://forno.celo.org']
case SupportedChainId.CELO_ALFAJORES:
return ['https://alfajores-forno.celo-testnet.org']
return RPC_URLS[chainId][0]
// Attempting to add a chain using an infura URL will not work, as the URL will be unreachable from the MetaMask background page.
// MetaMask allows switching to any publicly reachable URL, but for novel chains, it will display a warning if it is not on the "Safe" list.
// See the definition of FALLBACK_URLS for more details.
default:
return FALLBACK_URLS[chainId][0]
}
// Our API-keyed URLs will fail security checks when used with external wallets.
throw new Error('RPC URLs must use public endpoints')
}
export const switchChain = async (connector: Connector, chainId: SupportedChainId) => {
......@@ -44,7 +30,7 @@ export const switchChain = async (connector: Connector, chainId: SupportedChainI
const addChainParameter = {
chainId,
chainName: info.label,
rpcUrls: getRpcUrls(chainId),
rpcUrls: [getRpcUrl(chainId)],
nativeCurrency: info.nativeCurrency,
blockExplorerUrls: [info.explorer],
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment