feat: upgrade sdk-core to 3.2.6 and add AVAX (#6757)

* init refactor

* upgrade to 3.2.6 and refactor more uses of chainid

* cleaned up lock file

* remove console log and add placeholder

* use supported chains type for switch fn

* allow passing of all chainIds to switcher

* additional typecast

* better casting solution

* yarn.lock cleanup

* prettier

* better casting for rpc

* prettier

* deprecate no longer needed addresses

* better isSupported checking

* deprecate redundant fn

* cleanup toSupportedChainId

* address initial ocmments

* pretier

* includes testnet

* remove unused export

* merge conflicts

* spread for mutable copy

* explorer text

* check is supported before activating chain

* remove extra uses of mumbai

* remove cast to MockChainId

* retain var name supportedChainId

* updated prettier

* use t for explorer translation

* use mockchainid for test

* feat: Add Avalanche support (#6776)

* init avax

* add most avax props

* add logo

* correct subgraph

* update avax blocksPerFetch

* add square logo

* upgrade ur sdk

* version syntax

* correct tokens

* remove unused token

* remove unused token

* update token list and add coming soon to searchbar

* add coming soon to token explore page

* names to ids

* cleaned up routing

* usdc token

* upgrade default token list

* update SOR

* upgrade SOR

* merge conflicts

* snowtrace

* upgrade SOR

* handle be avax support

* temp hide avax

* show pool positions

* whole

* spotprice update

* not yet supported

* BACKEND_SUPPORTED_CHAINS

* add avax to BE not supported

* update multicall blocks to 5

* add todo

* updated prettier

---------

Co-authored-by: Charles Bachmeier <charlie@genie.xyz>

* be added avax token balances

* validateUrlChainParam should return eth for backend unsupported chain

* readonly

* respond to comments

---------

Co-authored-by: Charles Bachmeier <charlie@genie.xyz>
This commit is contained in:
Charles Bachmeier 2023-07-06 21:44:06 -07:00 committed by GitHub
parent 3a0f6920d0
commit 90f72e05b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
122 changed files with 1024 additions and 1373 deletions

@ -1,11 +1,11 @@
import { BigNumber } from '@ethersproject/bignumber'
import { SupportedChainId } from '@uniswap/sdk-core'
import { ChainId } from '@uniswap/sdk-core'
import { DEFAULT_DEADLINE_FROM_NOW } from '../../../src/constants/misc'
import { UNI, USDC_MAINNET } from '../../../src/constants/tokens'
import { getBalance, getTestSelector } from '../../utils'
const UNI_MAINNET = UNI[SupportedChainId.MAINNET]
const UNI_MAINNET = UNI[ChainId.MAINNET]
describe('Swap errors', () => {
it('wallet rejection', () => {

@ -1,9 +1,9 @@
import { SupportedChainId } from '@uniswap/sdk-core'
import { ChainId } from '@uniswap/sdk-core'
import { UNI, USDC_MAINNET } from '../../../src/constants/tokens'
import { getBalance, getTestSelector } from '../../utils'
const UNI_MAINNET = UNI[SupportedChainId.MAINNET]
const UNI_MAINNET = UNI[ChainId.MAINNET]
describe('Swap', () => {
describe('Swap on main page', () => {

@ -1,8 +1,8 @@
import { CurrencyAmount, SupportedChainId, WETH9 } from '@uniswap/sdk-core'
import { ChainId, CurrencyAmount, WETH9 } from '@uniswap/sdk-core'
import { getBalance, getTestSelector } from '../../utils'
const WETH = WETH9[SupportedChainId.MAINNET]
const WETH = WETH9[ChainId.MAINNET]
describe('Swap wrap', () => {
beforeEach(() => {

@ -1,9 +1,9 @@
import { SupportedChainId, WETH9 } from '@uniswap/sdk-core'
import { ChainId, WETH9 } from '@uniswap/sdk-core'
import { ARB, UNI } from '../../src/constants/tokens'
import { getTestSelector } from '../utils'
const UNI_MAINNET = UNI[SupportedChainId.MAINNET]
const UNI_MAINNET = UNI[ChainId.MAINNET]
const UNI_ADDRESS = '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984'

@ -3,11 +3,9 @@
*/
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'
import { SupportedChainId } from '../../src/constants/chains'
import { ChainId } from '@uniswap/sdk-core'
// todo: figure out how env vars actually work in CI
// const TEST_PRIVATE_KEY = Cypress.env('INTEGRATION_TEST_PRIVATE_KEY')
@ -15,7 +13,7 @@ const TEST_PRIVATE_KEY = '0xe580410d7c37d26c6ad1a837bbae46bc27f9066a466fb3a66e77
// address of the above key
const TEST_ADDRESS_NEVER_USE = new Wallet(TEST_PRIVATE_KEY).address
const CHAIN_ID = SupportedChainId.GOERLI
const CHAIN_ID = ChainId.GOERLI
const HEXLIFIED_CHAIN_ID = `0x${CHAIN_ID.toString(16)}`
const provider = new JsonRpcProvider('https://goerli.infura.io/v3/4bf032f2d38a4ed6bb975b80d6340847', 5)

@ -1,4 +1,4 @@
import { SupportedChainId } from '@uniswap/sdk-core'
import { ChainId } from '@uniswap/sdk-core'
/* eslint-env node */
require('dotenv').config()
@ -16,12 +16,12 @@ const forkingConfig = {
}
const forks = {
[SupportedChainId.MAINNET]: {
[ChainId.MAINNET]: {
url: `https://mainnet.infura.io/v3/${process.env.REACT_APP_INFURA_KEY}`,
blockNumber: BLOCK_NUMBER,
...forkingConfig,
},
[SupportedChainId.POLYGON]: {
[ChainId.POLYGON]: {
url: `https://polygon-mainnet.infura.io/v3/${process.env.REACT_APP_INFURA_KEY}`,
blockNumber: POLYGON_BLOCK_NUMBER,
...forkingConfig,
@ -32,8 +32,8 @@ module.exports = {
forks,
networks: {
hardhat: {
chainId: SupportedChainId.MAINNET,
forking: forks[SupportedChainId.MAINNET],
chainId: ChainId.MAINNET,
forking: forks[ChainId.MAINNET],
accounts: {
count: 2,
},

@ -97,7 +97,7 @@
"@types/ua-parser-js": "^0.7.36",
"@types/uuid": "^8.3.4",
"@types/wcag-contrast": "^3.0.0",
"@uniswap/default-token-list": "^9.6.0",
"@uniswap/default-token-list": "^11.2.0",
"@uniswap/eslint-config": "^1.2.0",
"@vanilla-extract/babel-plugin": "^1.1.7",
"@vanilla-extract/jest-transform": "^1.1.1",
@ -166,10 +166,10 @@
"@uniswap/permit2-sdk": "1.2.0",
"@uniswap/redux-multicall": "^1.1.8",
"@uniswap/router-sdk": "^1.3.0",
"@uniswap/sdk-core": "^3.2.3",
"@uniswap/smart-order-router": "^3.12.1",
"@uniswap/sdk-core": "^3.2.6",
"@uniswap/smart-order-router": "3.13.5",
"@uniswap/token-lists": "^1.0.0-beta.31",
"@uniswap/universal-router-sdk": "^1.5.1",
"@uniswap/universal-router-sdk": "^1.5.3",
"@uniswap/v2-core": "1.0.0",
"@uniswap/v2-periphery": "^1.1.0-beta.0",
"@uniswap/v2-sdk": "^3.0.1",

@ -0,0 +1,11 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_13871_12533)">
<path d="M12.9341 2.74118H3.05524V11.7259H12.9341V2.74118Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.9947 8C15.9947 12.4154 12.4154 15.9947 7.99999 15.9947C3.58465 15.9947 0.00531006 12.4154 0.00531006 8C0.00531006 3.58466 3.58465 0.00532532 7.99999 0.00532532C12.4154 0.00532532 15.9947 3.58466 15.9947 8ZM5.73452 11.1815H4.18298C3.85696 11.1815 3.69591 11.1815 3.59772 11.1187C3.49166 11.0499 3.42685 10.936 3.41899 10.8103C3.4131 10.6945 3.49363 10.553 3.65467 10.2702L7.48562 3.51761C7.64864 3.23086 7.73112 3.08749 7.83521 3.03447C7.94715 2.97751 8.08071 2.97751 8.19266 3.03447C8.29675 3.08749 8.37924 3.23086 8.54224 3.51761L9.32981 4.89239L9.33382 4.89941C9.50989 5.20703 9.59917 5.36303 9.63815 5.52675C9.68135 5.70548 9.68135 5.89402 9.63815 6.07274C9.59887 6.23771 9.51049 6.39484 9.33177 6.70711L7.31946 10.2643L7.31426 10.2734C7.13703 10.5836 7.04722 10.7408 6.92274 10.8594C6.78722 10.989 6.62421 11.0832 6.44549 11.1363C6.28247 11.1815 6.09983 11.1815 5.73452 11.1815ZM9.65268 11.1815H11.8759C12.2038 11.1815 12.3689 11.1815 12.4671 11.1168C12.5731 11.048 12.6399 10.9321 12.6458 10.8064C12.6515 10.6943 12.5727 10.5584 12.4184 10.292C12.413 10.283 12.4077 10.2737 12.4023 10.2643L11.2887 8.35928L11.276 8.33783C11.1195 8.07321 11.0405 7.93958 10.9391 7.88793C10.8272 7.83096 10.6955 7.83096 10.5836 7.88793C10.4815 7.94095 10.399 8.0804 10.236 8.36124L9.12633 10.2663L9.12253 10.2729C8.96009 10.5533 8.87891 10.6934 8.88477 10.8084C8.89262 10.9341 8.95743 11.0499 9.06348 11.1187C9.15973 11.1815 9.3247 11.1815 9.65268 11.1815Z" fill="#E84142"/>
</g>
<defs>
<clipPath id="clip0_13871_12533">
<rect width="16" height="16" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

@ -0,0 +1,11 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_298_130193)">
<path d="M12.9346 2.74121H3.05566V11.7259H12.9346V2.74121Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.9998 0C15.9998 4.41538 15.9998 15.9947 15.9998 15.9947C11.5844 15.9947 0.00590861 15.9947 0.00590861 15.9947L0.00488281 5.43594e-05C4.42027 5.43594e-05 15.9998 0 15.9998 0ZM5.73493 11.1815H4.18339C3.85736 11.1815 3.69632 11.1815 3.59813 11.1187C3.49207 11.0499 3.42726 10.936 3.4194 10.8103C3.41351 10.6945 3.49404 10.553 3.65508 10.2702L7.48603 3.51765C7.64905 3.2309 7.73153 3.08753 7.83562 3.03451C7.94756 2.97755 8.08112 2.97755 8.19307 3.03451C8.29716 3.08753 8.37965 3.2309 8.54265 3.51765L9.33022 4.89243L9.33423 4.89945C9.51029 5.20707 9.59958 5.36307 9.63856 5.52679C9.68176 5.70552 9.68176 5.89406 9.63856 6.07278C9.59928 6.23775 9.5109 6.39488 9.33218 6.70715L7.31987 10.2643L7.31466 10.2734C7.13744 10.5836 7.04762 10.7408 6.92315 10.8594C6.78763 10.9891 6.62462 11.0833 6.44589 11.1364C6.28288 11.1815 6.10024 11.1815 5.73493 11.1815ZM9.65309 11.1815H11.8763C12.2043 11.1815 12.3693 11.1815 12.4675 11.1168C12.5735 11.048 12.6403 10.9321 12.6463 10.8065C12.6519 10.6944 12.5731 10.5584 12.4188 10.2921C12.4134 10.283 12.4081 10.2738 12.4027 10.2644L11.2891 8.35932L11.2764 8.33787C11.1199 8.07325 11.0409 7.93962 10.9395 7.88797C10.8276 7.831 10.6959 7.831 10.584 7.88797C10.4819 7.94099 10.3994 8.08044 10.2364 8.36128L9.12674 10.2663L9.12294 10.2729C8.9605 10.5533 8.87932 10.6934 8.88518 10.8084C8.89303 10.9341 8.95784 11.0499 9.06389 11.1187C9.16014 11.1815 9.32511 11.1815 9.65309 11.1815Z" fill="#E84142"/>
</g>
<defs>
<clipPath id="clip0_298_130193">
<rect width="16" height="16" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

@ -1,4 +1,4 @@
import { SupportedChainId, Token, TradeType as MockTradeType } from '@uniswap/sdk-core'
import { ChainId, Token, TradeType as MockTradeType } from '@uniswap/sdk-core'
import { PERMIT2_ADDRESS } from '@uniswap/universal-router-sdk'
import { DAI as MockDAI, nativeOnChain, USDC_MAINNET as MockUSDC_MAINNET, USDT as MockUSDT } from 'constants/tokens'
import { TransactionStatus as MockTxStatus } from 'graphql/data/__generated__/types-and-hooks'
@ -46,7 +46,7 @@ function mockSwapInfo(
const mockAccount1 = '0x000000000000000000000000000000000000000001'
const mockAccount2 = '0x000000000000000000000000000000000000000002'
const mockChainId = SupportedChainId.MAINNET
const mockChainId = ChainId.MAINNET
const mockSpenderAddress = PERMIT2_ADDRESS[mockChainId]
const mockCurrencyAmountRaw = '1000000000000000000'
const mockCurrencyAmountRawUSDC = '1000000'
@ -246,7 +246,7 @@ describe('parseLocalActivity', () => {
status: 1,
},
} as TransactionDetails
const chainId = SupportedChainId.MAINNET
const chainId = ChainId.MAINNET
expect(parseLocalActivity(details, chainId, mockTokenAddressMap)).toEqual({
chainId: 1,
currencies: [MockUSDC_MAINNET, MockDAI],
@ -287,7 +287,7 @@ describe('parseLocalActivity', () => {
status: 1,
},
} as TransactionDetails
const chainId = SupportedChainId.MAINNET
const chainId = ChainId.MAINNET
expect(parseLocalActivity(details, chainId, mockTokenAddressMap)).toMatchObject({
chainId: 1,
currencies: [MockUSDC_MAINNET, MockDAI],
@ -311,7 +311,7 @@ describe('parseLocalActivity', () => {
status: 1,
},
} as TransactionDetails
const chainId = SupportedChainId.MAINNET
const chainId = ChainId.MAINNET
const tokens = {} as ChainTokenMap
expect(parseLocalActivity(details, chainId, tokens)).toMatchObject({
chainId: 1,

@ -1,9 +1,8 @@
import { BigNumber } from '@ethersproject/bignumber'
import { t } from '@lingui/macro'
import { formatCurrencyAmount } from '@uniswap/conedison/format'
import { Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import { ChainId, Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import { nativeOnChain } from '@uniswap/smart-order-router'
import { SupportedChainId } from 'constants/chains'
import { TransactionStatus } from 'graphql/data/__generated__/types-and-hooks'
import { ChainTokenMap, useAllTokensMultichain } from 'hooks/Tokens'
import { useMemo } from 'react'
@ -26,7 +25,7 @@ import {
import { getActivityTitle } from '../constants'
import { Activity, ActivityMap } from './types'
function getCurrency(currencyId: string, chainId: SupportedChainId, tokens: ChainTokenMap): Currency | undefined {
function getCurrency(currencyId: string, chainId: ChainId, tokens: ChainTokenMap): Currency | undefined {
return currencyId === 'ETH' ? nativeOnChain(chainId) : tokens[chainId]?.[currencyId]
}
@ -46,7 +45,7 @@ function buildCurrencyDescriptor(
function parseSwap(
swap: ExactInputSwapTransactionInfo | ExactOutputSwapTransactionInfo,
chainId: SupportedChainId,
chainId: ChainId,
tokens: ChainTokenMap
): Partial<Activity> {
const tokenIn = getCurrency(swap.inputCurrencyId, chainId, tokens)
@ -62,7 +61,7 @@ function parseSwap(
}
}
function parseWrap(wrap: WrapTransactionInfo, chainId: SupportedChainId, status: TransactionStatus): Partial<Activity> {
function parseWrap(wrap: WrapTransactionInfo, chainId: ChainId, status: TransactionStatus): Partial<Activity> {
const native = nativeOnChain(chainId)
const wrapped = native.wrapped
const [input, output] = wrap.unwrapped ? [wrapped, native] : [native, wrapped]
@ -76,7 +75,7 @@ function parseWrap(wrap: WrapTransactionInfo, chainId: SupportedChainId, status:
function parseApproval(
approval: ApproveTransactionInfo,
chainId: SupportedChainId,
chainId: ChainId,
tokens: ChainTokenMap,
status: TransactionStatus
): Partial<Activity> {
@ -97,7 +96,7 @@ type GenericLPInfo = Omit<
AddLiquidityV3PoolTransactionInfo | RemoveLiquidityV3TransactionInfo | AddLiquidityV2PoolTransactionInfo,
'type'
>
function parseLP(lp: GenericLPInfo, chainId: SupportedChainId, tokens: ChainTokenMap): Partial<Activity> {
function parseLP(lp: GenericLPInfo, chainId: ChainId, tokens: ChainTokenMap): Partial<Activity> {
const baseCurrency = getCurrency(lp.baseCurrencyId, chainId, tokens)
const quoteCurrency = getCurrency(lp.quoteCurrencyId, chainId, tokens)
const [baseRaw, quoteRaw] = [lp.expectedAmountBaseRaw, lp.expectedAmountQuoteRaw]
@ -108,7 +107,7 @@ function parseLP(lp: GenericLPInfo, chainId: SupportedChainId, tokens: ChainToke
function parseCollectFees(
collect: CollectFeesTransactionInfo,
chainId: SupportedChainId,
chainId: ChainId,
tokens: ChainTokenMap
): Partial<Activity> {
// Adapts CollectFeesTransactionInfo to generic LP type
@ -123,7 +122,7 @@ function parseCollectFees(
function parseMigrateCreateV3(
lp: MigrateV2LiquidityToV3TransactionInfo | CreateV3PoolTransactionInfo,
chainId: SupportedChainId,
chainId: ChainId,
tokens: ChainTokenMap
): Partial<Activity> {
const baseCurrency = getCurrency(lp.baseCurrencyId, chainId, tokens)
@ -137,7 +136,7 @@ function parseMigrateCreateV3(
export function parseLocalActivity(
details: TransactionDetails,
chainId: SupportedChainId,
chainId: ChainId,
tokens: ChainTokenMap
): Activity | undefined {
try {

@ -1,8 +1,7 @@
import { t } from '@lingui/macro'
import { formatFiatPrice, formatNumberOrString, NumberType } from '@uniswap/conedison/format'
import { SupportedChainId } from '@uniswap/sdk-core'
import { ChainId, NONFUNGIBLE_POSITION_MANAGER_ADDRESSES, UNI_ADDRESSES } from '@uniswap/sdk-core'
import moonpayLogoSrc from 'assets/svg/moonpay.svg'
import { NONFUNGIBLE_POSITION_MANAGER_ADDRESSES, UNI_ADDRESS } from 'constants/addresses'
import { nativeOnChain } from 'constants/tokens'
import {
ActivityType,
@ -38,7 +37,7 @@ const ENS_IMG =
'https://464911102-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/collections%2F2TjMAeHSzwlQgcOdL48E%2Ficon%2FKWP0gk2C6bdRPliWIA6o%2Fens%20transparent%20background.png?alt=media&token=bd28b063-5a75-4971-890c-97becea09076'
const COMMON_CONTRACTS: { [key: string]: Partial<Activity> | undefined } = {
[UNI_ADDRESS[SupportedChainId.MAINNET].toLowerCase()]: {
[UNI_ADDRESSES[ChainId.MAINNET].toLowerCase()]: {
title: t`UNI Governance`,
descriptor: t`Contract Interaction`,
logos: [UNI_IMG],

@ -1,12 +1,11 @@
import { Currency } from '@uniswap/sdk-core'
import { SupportedChainId } from 'constants/chains'
import { ChainId, Currency } from '@uniswap/sdk-core'
import { AssetActivityPartsFragment, TransactionStatus } from 'graphql/data/__generated__/types-and-hooks'
type Receipt = AssetActivityPartsFragment['transaction']
export type Activity = {
hash: string
chainId: SupportedChainId
chainId: ChainId
status: TransactionStatus
timestamp: number
title: string

@ -1,6 +1,5 @@
import { Token } from '@uniswap/sdk-core'
import { ChainId, Token } from '@uniswap/sdk-core'
import { Pool, Position } from '@uniswap/v3-sdk'
import { SupportedChainId } from 'constants/chains'
import { useAllTokensMultichain } from 'hooks/Tokens'
import { atom, useAtom } from 'jotai'
import { atomWithStorage } from 'jotai/utils'
@ -16,7 +15,7 @@ import { useInterfaceMulticallContracts } from './hooks'
export type PositionInfo = {
owner: string
chainId: SupportedChainId
chainId: ChainId
position: Position
pool: Pool
details: PositionDetails
@ -59,7 +58,7 @@ export function useCachedPositions(account: string): UseCachedPositionsReturnTyp
return [cachedPositions[account], setPositionsAndStaleTimeout]
}
const poolAddressKey = (details: PositionDetails, chainId: SupportedChainId) =>
const poolAddressKey = (details: PositionDetails, chainId: ChainId) =>
`${chainId}-${details.token0}-${details.token1}-${details.fee}`
type PoolAddressMap = { [key: string]: string | undefined }
@ -71,11 +70,11 @@ const poolAddressCacheAtom = atomWithStorage<PoolAddressMap>('poolCache', {})
export function usePoolAddressCache() {
const [cache, updateCache] = useAtom(poolAddressCacheAtom)
const get = useCallback(
(details: PositionDetails, chainId: SupportedChainId) => cache[poolAddressKey(details, chainId)],
(details: PositionDetails, chainId: ChainId) => cache[poolAddressKey(details, chainId)],
[cache]
)
const set = useCallback(
(details: PositionDetails, chainId: SupportedChainId, address: string) =>
(details: PositionDetails, chainId: ChainId, address: string) =>
updateCache((c) => ({ ...c, [poolAddressKey(details, chainId)]: address })),
[updateCache]
)
@ -104,8 +103,8 @@ function useTokenCache() {
return { get, set }
}
type TokenGetterFn = (addresses: string[], chainId: SupportedChainId) => Promise<{ [key: string]: Token | undefined }>
export function useGetCachedTokens(chains: SupportedChainId[]): TokenGetterFn {
type TokenGetterFn = (addresses: string[], chainId: ChainId) => Promise<{ [key: string]: Token | undefined }>
export function useGetCachedTokens(chains: ChainId[]): TokenGetterFn {
const allTokens = useAllTokensMultichain()
const multicallContracts = useInterfaceMulticallContracts(chains)
const tokenCache = useTokenCache()

@ -1,8 +1,7 @@
import { Token } from '@uniswap/sdk-core'
import { ChainId, Token } from '@uniswap/sdk-core'
import ERC20_ABI from 'abis/erc20.json'
import { Erc20Interface } from 'abis/types/Erc20'
import { Erc20Bytes32Interface } from 'abis/types/Erc20Bytes32'
import { SupportedChainId } from 'constants/chains'
import { DEFAULT_ERC20_DECIMALS } from 'constants/tokens'
import { Interface } from 'ethers/lib/utils'
import { UniswapInterfaceMulticall } from 'types/v3'
@ -38,7 +37,7 @@ async function fetchChunk(multicall: UniswapInterfaceMulticall, chunk: Call[]):
}
}
function tryParseToken(address: string, chainId: SupportedChainId, data: CallResult[]) {
function tryParseToken(address: string, chainId: ChainId, data: CallResult[]) {
try {
const [nameData, symbolData, decimalsData, nameDataBytes32, symbolDataBytes32] = data
@ -61,7 +60,7 @@ function tryParseToken(address: string, chainId: SupportedChainId, data: CallRes
}
}
function parseTokens(addresses: string[], chainId: SupportedChainId, returnData: CallResult[]) {
function parseTokens(addresses: string[], chainId: ChainId, returnData: CallResult[]) {
const tokenDataSlices = arrayToSlices(returnData, 5)
return tokenDataSlices.reduce((acc: TokenMap, slice, index) => {
@ -90,7 +89,7 @@ const TokenPromiseCache: { [key: CurrencyKey]: Promise<Token | undefined> | unde
// Returns tokens using a single RPC call to the multicall contract
export async function getTokensAsync(
addresses: string[],
chainId: SupportedChainId,
chainId: ChainId,
multicall: UniswapInterfaceMulticall
): Promise<TokenMap> {
if (addresses.length === 0) return {}

@ -1,10 +1,14 @@
import { Token } from '@uniswap/sdk-core'
import {
ChainId,
MULTICALL_ADDRESSES,
NONFUNGIBLE_POSITION_MANAGER_ADDRESSES as V3NFT_ADDRESSES,
Token,
} from '@uniswap/sdk-core'
import { AddressMap } from '@uniswap/smart-order-router'
import MulticallJSON from '@uniswap/v3-periphery/artifacts/contracts/lens/UniswapInterfaceMulticall.sol/UniswapInterfaceMulticall.json'
import NFTPositionManagerJSON from '@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json'
import { useWeb3React } from '@web3-react/core'
import { MULTICALL_ADDRESS, NONFUNGIBLE_POSITION_MANAGER_ADDRESSES as V3NFT_ADDRESSES } from 'constants/addresses'
import { isSupportedChain, SupportedChainId } from 'constants/chains'
import { isSupportedChain } from 'constants/chains'
import { RPC_PROVIDERS } from 'constants/providers'
import { BaseContract } from 'ethers/lib/ethers'
import { ContractInput, useUniswapPricesQuery } from 'graphql/data/__generated__/types-and-hooks'
@ -23,7 +27,7 @@ type ContractMap<T extends BaseContract> = { [key: number]: T }
function useContractMultichain<T extends BaseContract>(
addressMap: AddressMap,
ABI: any,
chainIds?: SupportedChainId[]
chainIds?: ChainId[]
): ContractMap<T> {
const { chainId: walletChainId, provider: walletProvider } = useWeb3React()
@ -35,19 +39,26 @@ function useContractMultichain<T extends BaseContract>(
.filter(isSupportedChain)
return relevantChains.reduce((acc: ContractMap<T>, chainId) => {
const provider = walletProvider && walletChainId === chainId ? walletProvider : RPC_PROVIDERS[chainId]
acc[chainId] = getContract(addressMap[chainId], ABI, provider) as T
const provider =
walletProvider && walletChainId === chainId
? walletProvider
: isSupportedChain(chainId)
? RPC_PROVIDERS[chainId]
: undefined
if (provider) {
acc[chainId] = getContract(addressMap[chainId] ?? '', ABI, provider) as T
}
return acc
}, {})
}, [ABI, addressMap, chainIds, walletChainId, walletProvider])
}
export function useV3ManagerContracts(chainIds: SupportedChainId[]): ContractMap<NonfungiblePositionManager> {
export function useV3ManagerContracts(chainIds: ChainId[]): ContractMap<NonfungiblePositionManager> {
return useContractMultichain<NonfungiblePositionManager>(V3NFT_ADDRESSES, NFTPositionManagerJSON.abi, chainIds)
}
export function useInterfaceMulticallContracts(chainIds: SupportedChainId[]): ContractMap<UniswapInterfaceMulticall> {
return useContractMultichain<UniswapInterfaceMulticall>(MULTICALL_ADDRESS, MulticallJSON.abi, chainIds)
export function useInterfaceMulticallContracts(chainIds: ChainId[]): ContractMap<UniswapInterfaceMulticall> {
return useContractMultichain<UniswapInterfaceMulticall>(MULTICALL_ADDRESSES, MulticallJSON.abi, chainIds)
}
type PriceMap = { [key: CurrencyKey]: number | undefined }

@ -1,5 +1,5 @@
import { BigNumber } from '@ethersproject/bignumber'
import { SupportedChainId, WETH9 } from '@uniswap/sdk-core'
import { ChainId, WETH9 } from '@uniswap/sdk-core'
import { FeeAmount, Pool, Position } from '@uniswap/v3-sdk'
import { USDC_MAINNET } from 'constants/tokens'
import { mocked } from 'test-utils/mocked'
@ -16,7 +16,7 @@ const owner = '0xf5b6bb25f5beaea03dd014c6ef9fa9f3926bf36c'
const pool = new Pool(
USDC_MAINNET,
WETH9[SupportedChainId.MAINNET],
WETH9[ChainId.MAINNET],
FeeAmount.MEDIUM,
'1851127709498178402383049949138810',
'7076437181775065414',
@ -34,7 +34,7 @@ const details = {
tokenId: BigNumber.from('0'),
operator: '0x0',
token0: USDC_MAINNET.address,
token1: WETH9[SupportedChainId.MAINNET].address,
token1: WETH9[ChainId.MAINNET].address,
fee: FeeAmount.MEDIUM,
tickLower: -100,
tickUpper: 100,
@ -48,7 +48,7 @@ const useMultiChainPositionsReturnValue = {
positions: [
{
owner,
chainId: SupportedChainId.MAINNET,
chainId: ChainId.MAINNET,
position,
pool,
details,

@ -1,8 +1,6 @@
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { ChainId, CurrencyAmount, Token, V3_CORE_FACTORY_ADDRESSES } from '@uniswap/sdk-core'
import IUniswapV3PoolStateJSON from '@uniswap/v3-core/artifacts/contracts/interfaces/pool/IUniswapV3PoolState.sol/IUniswapV3PoolState.json'
import { computePoolAddress, Pool, Position } from '@uniswap/v3-sdk'
import { V3_CORE_FACTORY_ADDRESSES } from 'constants/addresses'
import { SupportedChainId } from 'constants/chains'
import { DEFAULT_ERC20_DECIMALS } from 'constants/tokens'
import { BigNumber } from 'ethers/lib/ethers'
import { Interface } from 'ethers/lib/utils'
@ -18,7 +16,7 @@ import { useInterfaceMulticallContracts, usePoolPriceMap, useV3ManagerContracts
function createPositionInfo(
owner: string,
chainId: SupportedChainId,
chainId: ChainId,
details: PositionDetails,
slot0: any,
tokenA: Token,
@ -42,12 +40,13 @@ type FeeAmounts = [BigNumber, BigNumber]
const MAX_UINT128 = BigNumber.from(2).pow(128).sub(1)
const DEFAULT_CHAINS = [
SupportedChainId.MAINNET,
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.OPTIMISM,
SupportedChainId.POLYGON,
SupportedChainId.CELO,
SupportedChainId.BNB,
ChainId.MAINNET,
ChainId.ARBITRUM_ONE,
ChainId.OPTIMISM,
ChainId.POLYGON,
ChainId.CELO,
ChainId.BNB,
ChainId.AVALANCHE,
]
type UseMultiChainPositionsData = { positions?: PositionInfo[]; loading: boolean }
@ -118,7 +117,7 @@ export default function useMultiChainPositions(account: string, chains = DEFAULT
// Combines PositionDetails with Pool data to build our return type
const fetchPositionInfo = useCallback(
async (positionDetails: PositionDetails[], chainId: SupportedChainId, multicall: UniswapInterfaceMulticall) => {
async (positionDetails: PositionDetails[], chainId: ChainId, multicall: UniswapInterfaceMulticall) => {
const poolInterface = new Interface(IUniswapV3PoolStateJSON.abi) as UniswapV3PoolInterface
const tokens = await getTokens(
positionDetails.flatMap((details) => [details.token0, details.token1]),
@ -159,7 +158,7 @@ export default function useMultiChainPositions(account: string, chains = DEFAULT
)
const fetchPositionsForChain = useCallback(
async (chainId: SupportedChainId): Promise<PositionInfo[]> => {
async (chainId: ChainId): Promise<PositionInfo[]> => {
try {
const pm = pms[chainId]
const multicall = multicalls[chainId]

@ -1,4 +1,4 @@
import { SupportedChainId } from '@uniswap/sdk-core'
import { ChainId } from '@uniswap/sdk-core'
import { DAI_ARBITRUM } from '@uniswap/smart-order-router'
import { BRIDGED_USDC_ARBITRUM, DAI, USDC_MAINNET } from 'constants/tokens'
import { render } from 'test-utils/render'
@ -7,13 +7,13 @@ import { PortfolioLogo } from './PortfolioLogo'
describe('PortfolioLogo', () => {
it('renders without L2 icon', () => {
const { container } = render(<PortfolioLogo chainId={SupportedChainId.MAINNET} currencies={[DAI, USDC_MAINNET]} />)
const { container } = render(<PortfolioLogo chainId={ChainId.MAINNET} currencies={[DAI, USDC_MAINNET]} />)
expect(container).toMatchSnapshot()
})
it('renders with L2 icon', () => {
const { container } = render(
<PortfolioLogo chainId={SupportedChainId.ARBITRUM_ONE} currencies={[DAI_ARBITRUM, BRIDGED_USDC_ARBITRUM]} />
<PortfolioLogo chainId={ChainId.ARBITRUM_ONE} currencies={[DAI_ARBITRUM, BRIDGED_USDC_ARBITRUM]} />
)
expect(container).toMatchSnapshot()
})

@ -1,10 +1,9 @@
import { Currency } from '@uniswap/sdk-core'
import { ChainId, Currency } from '@uniswap/sdk-core'
import blankTokenUrl from 'assets/svg/blank_token.svg'
import { ReactComponent as UnknownStatus } from 'assets/svg/contract-interaction.svg'
import { LogoImage, MissingImageLogo } from 'components/Logo/AssetLogo'
import { Unicon } from 'components/Unicon'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import useTokenLogoSource from 'hooks/useAssetLogoSource'
import useENSAvatar from 'hooks/useENSAvatar'
import React from 'react'
@ -37,7 +36,7 @@ const DoubleLogoContainer = styled.div`
`
type MultiLogoProps = {
chainId: SupportedChainId
chainId: ChainId
accountAddress?: string
currencies?: Array<Currency | undefined>
images?: (string | undefined)[]
@ -85,7 +84,7 @@ const L2LogoContainer = styled.div<{ $backgroundColor?: string }>`
* Renders an image by prioritizing a list of sources, and then eventually a fallback triangle alert
*/
export function PortfolioLogo({
chainId = SupportedChainId.MAINNET,
chainId = ChainId.MAINNET,
accountAddress,
currencies,
images,
@ -142,7 +141,7 @@ export function PortfolioLogo({
}
const L2Logo =
chainId !== SupportedChainId.MAINNET && chainLogo ? (
chainId !== ChainId.MAINNET && chainLogo ? (
<L2LogoContainer $backgroundColor={squareLogoUrl ? theme.backgroundSurface : theme.textPrimary}>
{squareLogoUrl ? (
<SquareChainLogo src={chainLogo} alt="chainLogo" />

@ -1,12 +1,12 @@
import { BigNumber } from '@ethersproject/bignumber'
import type { TransactionResponse } from '@ethersproject/providers'
import { UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import uniswapNftAirdropClaim from 'abis/uniswap-nft-airdrop-claim.json'
import airdropBackgroundv2 from 'assets/images/airdopBackground.png'
import { ButtonEmphasis, ButtonSize, ThemeButton } from 'components/Button'
import { OpacityHoverState } from 'components/Common'
import Loader from 'components/Icons/LoadingSpinner'
import { UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS } from 'constants/addresses'
import { useContract } from 'hooks/useContract'
import { ChevronRightIcon } from 'nft/components/icons'
import { useIsNftClaimAvailable } from 'nft/hooks/useIsNftClaimAvailable'

@ -1,39 +1,40 @@
import { Trans } from '@lingui/macro'
import { ChainId, SUPPORTED_CHAINS } from '@uniswap/sdk-core'
import { FeeAmount } from '@uniswap/v3-sdk'
import { ALL_SUPPORTED_CHAIN_IDS, SupportedChainId } from 'constants/chains'
import type { ReactNode } from 'react'
export const FEE_AMOUNT_DETAIL: Record<
FeeAmount,
{ label: string; description: ReactNode; supportedChains: SupportedChainId[] }
{ label: string; description: ReactNode; supportedChains: readonly ChainId[] }
> = {
[FeeAmount.LOWEST]: {
label: '0.01',
description: <Trans>Best for very stable pairs.</Trans>,
supportedChains: [
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.BNB,
SupportedChainId.CELO,
SupportedChainId.CELO_ALFAJORES,
SupportedChainId.MAINNET,
SupportedChainId.OPTIMISM,
SupportedChainId.POLYGON,
SupportedChainId.POLYGON_MUMBAI,
ChainId.ARBITRUM_ONE,
ChainId.BNB,
ChainId.CELO,
ChainId.CELO_ALFAJORES,
ChainId.MAINNET,
ChainId.OPTIMISM,
ChainId.POLYGON,
ChainId.POLYGON_MUMBAI,
ChainId.AVALANCHE,
],
},
[FeeAmount.LOW]: {
label: '0.05',
description: <Trans>Best for stable pairs.</Trans>,
supportedChains: ALL_SUPPORTED_CHAIN_IDS,
supportedChains: SUPPORTED_CHAINS,
},
[FeeAmount.MEDIUM]: {
label: '0.3',
description: <Trans>Best for most pairs.</Trans>,
supportedChains: ALL_SUPPORTED_CHAIN_IDS,
supportedChains: SUPPORTED_CHAINS,
},
[FeeAmount.HIGH]: {
label: '1',
description: <Trans>Best for exotic pairs.</Trans>,
supportedChains: ALL_SUPPORTED_CHAIN_IDS,
supportedChains: SUPPORTED_CHAINS,
},
}

@ -1,5 +1,5 @@
import { ChainId } from '@uniswap/sdk-core'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import useTokenLogoSource from 'hooks/useAssetLogoSource'
import React from 'react'
import styled, { css } from 'styled-components/macro'
@ -63,7 +63,7 @@ const L2NetworkLogo = styled.div<{ networkUrl?: string; parentSize: string }>`
export default function AssetLogo({
isNative,
address,
chainId = SupportedChainId.MAINNET,
chainId = ChainId.MAINNET,
symbol,
backupImg,
size = '24px',

@ -1,4 +1,5 @@
import { t } from '@lingui/macro'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { WalletConnect } from '@web3-react/walletconnect-v2'
import { showTestnetsAtom } from 'components/AccountDrawer/TestnetsToggle'
@ -6,13 +7,7 @@ import { MouseoverTooltip } from 'components/Tooltip'
import { getConnection } from 'connection'
import { ConnectionType } from 'connection/types'
import { getChainInfo } from 'constants/chainInfo'
import {
L1_CHAIN_IDS,
L2_CHAIN_IDS,
SupportedChainId,
TESTNET_CHAIN_IDS,
UniWalletSupportedChains,
} from 'constants/chains'
import { L1_CHAIN_IDS, L2_CHAIN_IDS, TESTNET_CHAIN_IDS, UniWalletSupportedChains } from 'constants/chains'
import { useOnClickOutside } from 'hooks/useOnClickOutside'
import useSelectChain from 'hooks/useSelectChain'
import useSyncChainQuery from 'hooks/useSyncChainQuery'
@ -36,7 +31,7 @@ interface ChainSelectorProps {
leftAlign?: boolean
}
function useWalletSupportedChains(): SupportedChainId[] {
function useWalletSupportedChains(): ChainId[] {
const { connector } = useWeb3React()
const connectionType = getConnection(connector).type
@ -63,7 +58,7 @@ export const ChainSelector = ({ leftAlign }: ChainSelectorProps) => {
const [supportedChains, unsupportedChains] = useMemo(() => {
const { supported, unsupported } = NETWORK_SELECTOR_CHAINS.filter(
(chain) => showTestnets || !TESTNET_CHAIN_IDS.has(chain)
(chain: number) => showTestnets || !TESTNET_CHAIN_IDS.includes(chain)
).reduce(
(acc, chain) => {
if (walletSupportsChain.includes(chain)) {
@ -73,7 +68,7 @@ export const ChainSelector = ({ leftAlign }: ChainSelectorProps) => {
}
return acc
},
{ supported: [], unsupported: [] } as Record<string, SupportedChainId[]>
{ supported: [], unsupported: [] } as Record<string, ChainId[]>
)
return [supported, unsupported]
}, [showTestnets, walletSupportsChain])
@ -87,10 +82,10 @@ export const ChainSelector = ({ leftAlign }: ChainSelectorProps) => {
const selectChain = useSelectChain()
useSyncChainQuery()
const [pendingChainId, setPendingChainId] = useState<SupportedChainId | undefined>(undefined)
const [pendingChainId, setPendingChainId] = useState<ChainId | undefined>(undefined)
const onSelectChain = useCallback(
async (targetChainId: SupportedChainId) => {
async (targetChainId: ChainId) => {
setPendingChainId(targetChainId)
await selectChain(targetChainId)
setPendingChainId(undefined)

@ -1,8 +1,8 @@
import { Trans } from '@lingui/macro'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import Loader from 'components/Icons/LoadingSpinner'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import { CheckMarkIcon } from 'nft/components/icons'
import styled, { useTheme } from 'styled-components/macro'
@ -63,7 +63,7 @@ const Logo = styled.img`
`
interface ChainSelectorRowProps {
disabled?: boolean
targetChain: SupportedChainId
targetChain: ChainId
onSelectChain: (targetChain: number) => void
isPending: boolean
}

@ -1,14 +1,16 @@
import { Trans } from '@lingui/macro'
import { useTrace } from '@uniswap/analytics'
import { InterfaceSectionName, NavBarSearchTypes } from '@uniswap/analytics-events'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import clsx from 'clsx'
import Badge from 'components/Badge'
import { SupportedChainId } from 'constants/chains'
import { getChainInfo } from 'constants/chainInfo'
import { HistoryDuration, SafetyLevel } from 'graphql/data/__generated__/types-and-hooks'
import { useTrendingCollections } from 'graphql/data/nft/TrendingCollections'
import { SearchToken } from 'graphql/data/SearchTokens'
import useTrendingTokens from 'graphql/data/TrendingTokens'
import { BACKEND_NOT_YET_SUPPORTED_CHAIN_IDS } from 'graphql/data/util'
import { useDisableNFTRoutes } from 'hooks/useDisableNFTRoutes'
import { useIsNftPage } from 'hooks/useIsNftPage'
import { Box } from 'nft/components/Box'
@ -20,7 +22,6 @@ import { useLocation } from 'react-router-dom'
import styled from 'styled-components/macro'
import { ThemedText } from 'theme'
import BnbLogoURI from '../../assets/svg/bnb-logo.svg'
import { ClockIcon, TrendingArrow } from '../../nft/components/icons'
import { useRecentlySearchedAssets } from './RecentlySearchedAssets'
import * as styles from './SearchBar.css'
@ -104,12 +105,12 @@ function isKnownToken(token: SearchToken) {
return token.project?.safetyLevel == SafetyLevel.Verified || token.project?.safetyLevel == SafetyLevel.MediumWarning
}
const BNBLogo = styled.img`
const ChainLogo = styled.img`
height: 20px;
width: 20px;
margin-right: 8px;
`
const BNBComingSoonBadge = styled(Badge)`
const ChainComingSoonBadge = styled(Badge)`
align-items: center;
background-color: ${({ theme }) => theme.backgroundModule};
color: ${({ theme }) => theme.textSecondary};
@ -356,21 +357,33 @@ export const SearchBarDropdown = ({
shouldDisableNFTRoutes,
])
const showBNBComingSoonBadge = chainId === SupportedChainId.BNB && !isLoading
const showChainComingSoonBadge = chainId && BACKEND_NOT_YET_SUPPORTED_CHAIN_IDS.includes(chainId) && !isLoading
const logoUri = getChainInfo(chainId)?.logoUrl
return (
<Column overflow="hidden" className={clsx(styles.searchBarDropdownNft, styles.searchBarScrollable)}>
<Box opacity={isLoading ? '0.3' : '1'} transition="125">
{resultsState}
{showBNBComingSoonBadge && (
<BNBComingSoonBadge>
<BNBLogo src={BnbLogoURI} />
{showChainComingSoonBadge && (
<ChainComingSoonBadge>
<ChainLogo src={logoUri} />
<ThemedText.BodySmall color="textSecondary" fontSize="14px" fontWeight="400" lineHeight="20px">
<Trans>Coming soon: search and explore tokens on BNB Chain</Trans>
<ComingSoonText chainId={chainId} />
</ThemedText.BodySmall>
</BNBComingSoonBadge>
</ChainComingSoonBadge>
)}
</Box>
</Column>
)
}
function ComingSoonText({ chainId }: { chainId: ChainId }) {
switch (chainId) {
case ChainId.BNB:
return <Trans>Coming soon: search and explore tokens on BNB Chain</Trans>
case ChainId.AVALANCHE:
return <Trans>Coming soon: search and explore tokens on Avalanche Chain</Trans>
default:
return null
}
}

@ -1,7 +1,7 @@
import { Trans } from '@lingui/macro'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import { ArrowUpRight } from 'react-feather'
import styled from 'styled-components/macro'
import { ExternalLink, HideSmall } from 'theme'
@ -30,15 +30,16 @@ const RootWrapper = styled.div`
`
const SHOULD_SHOW_ALERT = {
[SupportedChainId.OPTIMISM]: true,
[SupportedChainId.OPTIMISM_GOERLI]: true,
[SupportedChainId.ARBITRUM_ONE]: true,
[SupportedChainId.ARBITRUM_GOERLI]: true,
[SupportedChainId.POLYGON]: true,
[SupportedChainId.POLYGON_MUMBAI]: true,
[SupportedChainId.CELO]: true,
[SupportedChainId.CELO_ALFAJORES]: true,
[SupportedChainId.BNB]: true,
[ChainId.OPTIMISM]: true,
[ChainId.OPTIMISM_GOERLI]: true,
[ChainId.ARBITRUM_ONE]: true,
[ChainId.ARBITRUM_GOERLI]: true,
[ChainId.POLYGON]: true,
[ChainId.POLYGON_MUMBAI]: true,
[ChainId.CELO]: true,
[ChainId.CELO_ALFAJORES]: true,
[ChainId.BNB]: true,
[ChainId.AVALANCHE]: true,
}
type NetworkAlertChains = keyof typeof SHOULD_SHOW_ALERT
@ -47,44 +48,48 @@ const BG_COLORS_BY_DARK_MODE_AND_CHAIN_ID: {
[darkMode in 'dark' | 'light']: { [chainId in NetworkAlertChains]: string }
} = {
dark: {
[SupportedChainId.POLYGON]:
[ChainId.POLYGON]:
'radial-gradient(100% 93.36% at 0% 6.64%, rgba(160, 108, 247, 0.1) 0%, rgba(82, 32, 166, 0.1) 100%)',
[SupportedChainId.POLYGON_MUMBAI]:
[ChainId.POLYGON_MUMBAI]:
'radial-gradient(100% 93.36% at 0% 6.64%, rgba(160, 108, 247, 0.1) 0%, rgba(82, 32, 166, 0.1) 100%)',
[SupportedChainId.CELO]:
[ChainId.CELO]:
'radial-gradient(182.71% 150.59% at 2.81% 7.69%, rgba(90, 190, 170, 0.15) 0%, rgba(80, 160, 40, 0.15) 100%)',
[SupportedChainId.CELO_ALFAJORES]:
[ChainId.CELO_ALFAJORES]:
'radial-gradient(182.71% 150.59% at 2.81% 7.69%, rgba(90, 190, 170, 0.15) 0%, rgba(80, 160, 40, 0.15) 100%)',
[SupportedChainId.BNB]:
[ChainId.BNB]:
'radial-gradient(182.71% 150.59% at 2.81% 7.69%, rgba(240, 185, 11, 0.16) 0%, rgba(255, 168, 0, 0.16) 100%)',
[SupportedChainId.OPTIMISM]:
[ChainId.OPTIMISM]:
'radial-gradient(948% 292% at 42% 0%, rgba(255, 58, 212, 0.01) 0%, rgba(255, 255, 255, 0.04) 100%),radial-gradient(98% 96% at 2% 0%, rgba(255, 39, 39, 0.01) 0%, rgba(235, 0, 255, 0.01) 96%)',
[SupportedChainId.OPTIMISM_GOERLI]:
[ChainId.OPTIMISM_GOERLI]:
'radial-gradient(948% 292% at 42% 0%, rgba(255, 58, 212, 0.04) 0%, rgba(255, 255, 255, 0.04) 100%),radial-gradient(98% 96% at 2% 0%, rgba(255, 39, 39, 0.04) 0%, rgba(235, 0, 255, 0.01 96%)',
[SupportedChainId.ARBITRUM_ONE]:
[ChainId.ARBITRUM_ONE]:
'radial-gradient(285% 8200% at 30% 50%, rgba(40, 160, 240, 0.01) 0%, rgba(219, 255, 0, 0) 100%),radial-gradient(75% 75% at 0% 0%, rgba(150, 190, 220, 0.05) 0%, rgba(33, 114, 229, 0.05) 100%), hsla(0, 0%, 100%, 0.05)',
[SupportedChainId.ARBITRUM_GOERLI]:
[ChainId.ARBITRUM_GOERLI]:
'radial-gradient(285% 8200% at 30% 50%, rgba(40, 160, 240, 0.05) 0%, rgba(219, 255, 0, 0) 100%),radial-gradient(75% 75% at 0% 0%, rgba(150, 190, 220, 0.05) 0%, rgba(33, 114, 229, 0.1) 100%), hsla(0, 0%, 100%, 0.05)',
[ChainId.AVALANCHE]:
'radial-gradient(948% 292% at 42% 0%, rgba(255, 58, 212, 0.01) 0%, rgba(255, 255, 255, 0.04) 100%),radial-gradient(98% 96% at 2% 0%, rgba(255, 39, 39, 0.01) 0%, rgba(235, 0, 255, 0.01) 96%)',
},
light: {
[SupportedChainId.POLYGON]:
[ChainId.POLYGON]:
'radial-gradient(182.71% 205.59% at 2.81% 7.69%, rgba(130, 71, 229, 0.2) 0%, rgba(167, 202, 255, 0.2) 100%)',
[SupportedChainId.POLYGON_MUMBAI]:
[ChainId.POLYGON_MUMBAI]:
'radial-gradient(182.71% 205.59% at 2.81% 7.69%, rgba(130, 71, 229, 0.2) 0%, rgba(167, 202, 255, 0.2) 100%)',
[SupportedChainId.CELO]:
[ChainId.CELO]:
'radial-gradient(182.71% 150.59% at 2.81% 7.69%, rgba(63, 208, 137, 0.15) 0%, rgba(49, 205, 50, 0.15) 100%)',
[SupportedChainId.CELO_ALFAJORES]:
[ChainId.CELO_ALFAJORES]:
'radial-gradient(182.71% 150.59% at 2.81% 7.69%, rgba(63, 208, 137, 0.15) 0%, rgba(49, 205, 50, 0.15) 100%)',
[SupportedChainId.BNB]:
[ChainId.BNB]:
'radial-gradient(182.71% 150.59% at 2.81% 7.69%, rgba(240, 185, 11, 0.16) 0%, rgba(255, 168, 0, 0.16) 100%)',
[SupportedChainId.OPTIMISM]:
[ChainId.OPTIMISM]:
'radial-gradient(92% 105% at 50% 7%, rgba(255, 58, 212, 0.04) 0%, rgba(255, 255, 255, 0.03) 100%),radial-gradient(100% 97% at 0% 12%, rgba(235, 0, 255, 0.1) 0%, rgba(243, 19, 19, 0.1) 100%), hsla(0, 0%, 100%, 0.1)',
[SupportedChainId.OPTIMISM_GOERLI]:
[ChainId.OPTIMISM_GOERLI]:
'radial-gradient(92% 105% at 50% 7%, rgba(255, 58, 212, 0.04) 0%, rgba(255, 255, 255, 0.03) 100%),radial-gradient(100% 97% at 0% 12%, rgba(235, 0, 255, 0.1) 0%, rgba(243, 19, 19, 0.1) 100%), hsla(0, 0%, 100%, 0.1)',
[SupportedChainId.ARBITRUM_ONE]:
[ChainId.ARBITRUM_ONE]:
'radial-gradient(285% 8200% at 30% 50%, rgba(40, 160, 240, 0.1) 0%, rgba(219, 255, 0, 0) 100%),radial-gradient(circle at top left, hsla(206, 50%, 75%, 0.01), hsla(215, 79%, 51%, 0.12)), hsla(0, 0%, 100%, 0.1)',
[SupportedChainId.ARBITRUM_GOERLI]:
[ChainId.ARBITRUM_GOERLI]:
'radial-gradient(285% 8200% at 30% 50%, rgba(40, 160, 240, 0.1) 0%, rgba(219, 255, 0, 0) 100%),radial-gradient(circle at top left, hsla(206, 50%, 75%, 0.01), hsla(215, 79%, 51%, 0.12)), hsla(0, 0%, 100%, 0.1)',
[ChainId.AVALANCHE]:
'radial-gradient(92% 105% at 50% 7%, rgba(255, 58, 212, 0.04) 0%, rgba(255, 255, 255, 0.03) 100%),radial-gradient(100% 97% at 0% 12%, rgba(235, 0, 255, 0.1) 0%, rgba(243, 19, 19, 0.1) 100%), hsla(0, 0%, 100%, 0.1)',
},
}
@ -135,15 +140,16 @@ const StyledArrowUpRight = styled(ArrowUpRight)`
`
const TEXT_COLORS: { [chainId in NetworkAlertChains]: string } = {
[SupportedChainId.POLYGON]: 'rgba(130, 71, 229)',
[SupportedChainId.POLYGON_MUMBAI]: 'rgba(130, 71, 229)',
[SupportedChainId.CELO]: 'rgba(53, 178, 97)',
[SupportedChainId.CELO_ALFAJORES]: 'rgba(53, 178, 97)',
[SupportedChainId.OPTIMISM]: '#ff3856',
[SupportedChainId.OPTIMISM_GOERLI]: '#ff3856',
[SupportedChainId.ARBITRUM_ONE]: '#0490ed',
[SupportedChainId.BNB]: colors.gold400,
[SupportedChainId.ARBITRUM_GOERLI]: '#0490ed',
[ChainId.POLYGON]: 'rgba(130, 71, 229)',
[ChainId.POLYGON_MUMBAI]: 'rgba(130, 71, 229)',
[ChainId.CELO]: 'rgba(53, 178, 97)',
[ChainId.CELO_ALFAJORES]: 'rgba(53, 178, 97)',
[ChainId.OPTIMISM]: '#ff3856',
[ChainId.OPTIMISM_GOERLI]: '#ff3856',
[ChainId.ARBITRUM_ONE]: '#0490ed',
[ChainId.BNB]: colors.gold400,
[ChainId.ARBITRUM_GOERLI]: '#0490ed',
[ChainId.AVALANCHE]: '#ff3856',
}
function shouldShowAlert(chainId: number | undefined): chainId is NetworkAlertChains {

@ -1,7 +1,7 @@
import { Trans } from '@lingui/macro'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { getChainInfoOrDefault, L2ChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import { AlertTriangle } from 'react-feather'
import styled from 'styled-components/macro'
import { ExternalLink, MEDIA_WIDTHS } from 'theme'
@ -62,7 +62,7 @@ export function ChainConnectivityWarning() {
</TitleText>
</TitleRow>
<BodyRow>
{chainId === SupportedChainId.MAINNET ? (
{chainId === ChainId.MAINNET ? (
<Trans>You may have lost your network connection.</Trans>
) : (
<Trans>{label} might be down right now, or you may have lost your network connection.</Trans>

@ -1,7 +1,7 @@
import { Trans } from '@lingui/macro'
import { ChainId } from '@uniswap/sdk-core'
import AlertTriangleFilled from 'components/Icons/AlertTriangleFilled'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import styled from 'styled-components/macro'
import { ThemedText } from '../../theme'
@ -22,7 +22,7 @@ export const PopupAlertTriangle = styled(AlertTriangleFilled)`
height: 32px;
`
export default function FailedNetworkSwitchPopup({ chainId }: { chainId: SupportedChainId }) {
export default function FailedNetworkSwitchPopup({ chainId }: { chainId: ChainId }) {
const chainInfo = getChainInfo(chainId)
return (

@ -1,5 +1,5 @@
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from 'constants/chains'
import styled from 'styled-components/macro'
import { MEDIA_WIDTHS } from 'theme'
@ -62,7 +62,7 @@ export default function Popups() {
// need extra padding if network is not L1 Ethereum
const { chainId } = useWeb3React()
const isNotOnMainnet = Boolean(chainId && chainId !== SupportedChainId.MAINNET)
const isNotOnMainnet = Boolean(chainId && chainId !== ChainId.MAINNET)
return (
<>

@ -1,5 +1,5 @@
import { BigNumber } from '@ethersproject/bignumber'
import { SupportedChainId, Token, WETH9 } from '@uniswap/sdk-core'
import { ChainId, Token, WETH9 } from '@uniswap/sdk-core'
import { FeeAmount, Pool } from '@uniswap/v3-sdk'
import { USDC_MAINNET } from 'constants/tokens'
import { useToken } from 'hooks/Tokens'
@ -25,7 +25,7 @@ beforeEach(() => {
// tokenA: Token, tokenB: Token, fee: FeeAmount, sqrtRatioX96: BigintIsh, liquidity: BigintIsh, tickCurrent: number
new Pool(
USDC_MAINNET,
WETH9[SupportedChainId.MAINNET],
WETH9[ChainId.MAINNET],
FeeAmount.MEDIUM,
'1745948049099224684665158875285708',
'4203610460178577802',
@ -37,7 +37,7 @@ beforeEach(() => {
test('PositionListItem should render a position', () => {
const positionDetails = {
token0: USDC_MAINNET.address,
token1: WETH9[SupportedChainId.MAINNET].address,
token1: WETH9[ChainId.MAINNET].address,
tokenId: BigNumber.from(479689),
fee: FeeAmount.MEDIUM,
liquidity: BigNumber.from('1341008833950736'),

@ -1,11 +1,9 @@
// eslint-disable-next-line no-restricted-imports
import { Percent } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { AutoColumn } from 'components/Column'
import { L2_CHAIN_IDS } from 'constants/chains'
import { isSupportedChain, L2_CHAIN_IDS } from 'constants/chains'
import useDisableScrolling from 'hooks/useDisableScrolling'
import { useOnClickOutside } from 'hooks/useOnClickOutside'
import { isSupportedChainId } from 'lib/hooks/routing/clientSideSmartOrderRouter'
import { useRef } from 'react'
import { useModalIsOpen, useToggleSettingsMenu } from 'state/application/hooks'
import { ApplicationModal } from 'state/application/reducer'
@ -54,11 +52,11 @@ export default function SettingsTab({ autoSlippage, chainId }: { autoSlippage: P
useDisableScrolling(isOpen)
const isSupportedChain = isSupportedChainId(chainId)
const isChainSupported = isSupportedChain(chainId)
return (
<Menu ref={node}>
<MenuButton disabled={!isSupportedChain || chainId !== connectedChainId} isActive={isOpen} onClick={toggleMenu} />
<MenuButton disabled={!isChainSupported || chainId !== connectedChainId} isActive={isOpen} onClick={toggleMenu} />
{isOpen && (
<MenuFlyout>
<RouterPreferenceSettings />

@ -1,6 +1,6 @@
import { Trans } from '@lingui/macro'
import { ChainId } from '@uniswap/sdk-core'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import { darken } from 'polished'
import { useState } from 'react'
import styled from 'styled-components/macro'
@ -67,7 +67,7 @@ const ResourcesContainer = styled.div`
type AboutSectionProps = {
address: string
chainId: SupportedChainId
chainId: ChainId
description?: string | null
homepageUrl?: string | null
twitterName?: string | null
@ -105,7 +105,7 @@ export function AboutSection({ address, chainId, description, homepageUrl, twitt
</ThemedText.SubHeaderSmall>
<ResourcesContainer data-cy="resources-container">
<Resource
name={chainId === SupportedChainId.MAINNET ? 'Etherscan' : 'Block Explorer'}
name={chainId === ChainId.MAINNET ? 'Etherscan' : 'Block Explorer'}
link={`${explorer}${address === 'NATIVE' ? '' : 'address/' + address}`}
/>
<Resource name="More analytics" link={`${infoLink}tokens/${address}`} />

@ -1,11 +1,10 @@
import { Trans } from '@lingui/macro'
import { formatCurrencyAmount, NumberType } from '@uniswap/conedison/format'
import { Currency } from '@uniswap/sdk-core'
import { ChainId, Currency } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import CurrencyLogo from 'components/Logo/CurrencyLogo'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import { isSupportedChain } from 'constants/chains'
import { asSupportedChain } from 'constants/chains'
import { useStablecoinValue } from 'hooks/useStablecoinPrice'
import useCurrencyBalance from 'lib/hooks/useCurrencyBalance'
import styled, { useTheme } from 'styled-components/macro'
@ -67,7 +66,7 @@ const StyledNetworkLabel = styled.div`
export default function BalanceSummary({ token }: { token: Currency }) {
const { account, chainId } = useWeb3React()
const theme = useTheme()
const { label, color } = getChainInfo(isSupportedChain(chainId) ? chainId : SupportedChainId.MAINNET)
const { label, color } = getChainInfo(asSupportedChain(chainId) ?? ChainId.MAINNET)
const balance = useCurrencyBalance(account, token)
const formattedBalance = formatCurrencyAmount(balance, NumberType.TokenNonTx)
const formattedUsdValue = formatCurrencyAmount(useStablecoinValue(balance), NumberType.FiatTokenStats)

@ -1,8 +1,8 @@
import { Trans } from '@lingui/macro'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { ButtonPrimary } from 'components/Button'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import useSelectChain from 'hooks/useSelectChain'
import { useNavigate } from 'react-router-dom'
import styled from 'styled-components/macro'
@ -43,7 +43,7 @@ export default function InvalidTokenDetails({
pageChainId,
isInvalidAddress,
}: {
pageChainId: SupportedChainId
pageChainId: ChainId
isInvalidAddress?: boolean
}) {
const { chainId } = useWeb3React()

@ -1,8 +1,8 @@
import { Trans } from '@lingui/macro'
import { formatNumber, NumberType } from '@uniswap/conedison/format'
import { ChainId } from '@uniswap/sdk-core'
import { MouseoverTooltip } from 'components/Tooltip'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import { ReactNode } from 'react'
import styled from 'styled-components/macro'
import { ExternalLink, ThemedText } from 'theme'
@ -68,7 +68,7 @@ function Stat({
}
type StatsSectionProps = {
chainId: SupportedChainId
chainId: ChainId
address: string
priceLow52W?: NumericStat
priceHigh52W?: NumericStat

@ -1,7 +1,11 @@
import Badge from 'components/Badge'
import { getChainInfo } from 'constants/chainInfo'
import { Chain } from 'graphql/data/__generated__/types-and-hooks'
import { BACKEND_CHAIN_NAMES, supportedChainIdFromGQLChain, validateUrlChainParam } from 'graphql/data/util'
import {
BACKEND_NOT_YET_SUPPORTED_CHAIN_IDS,
BACKEND_SUPPORTED_CHAINS,
supportedChainIdFromGQLChain,
validateUrlChainParam,
} from 'graphql/data/util'
import { useOnClickOutside } from 'hooks/useOnClickOutside'
import { useRef } from 'react'
import { Check, ChevronDown, ChevronUp } from 'react-feather'
@ -118,7 +122,6 @@ export default function NetworkFilter() {
const currentChainName = validateUrlChainParam(chainName)
const chainInfo = getChainInfo(supportedChainIdFromGQLChain(currentChainName))
const BNBChainInfo = getChainInfo(supportedChainIdFromGQLChain(Chain.Bnb))
return (
<StyledMenu ref={node}>
@ -143,7 +146,7 @@ export default function NetworkFilter() {
</NetworkFilterOption>
{open && (
<MenuTimeFlyout>
{BACKEND_CHAIN_NAMES.map((network) => {
{BACKEND_SUPPORTED_CHAINS.map((network) => {
const chainInfo = getChainInfo(supportedChainIdFromGQLChain(network))
return (
<InternalLinkMenuItem
@ -166,13 +169,22 @@ export default function NetworkFilter() {
</InternalLinkMenuItem>
)
})}
<InternalLinkMenuItem data-testid="tokens-network-filter-option-bnb-chain" disabled>
<NetworkLabel>
<Logo src={BNBChainInfo.logoUrl} />
{BNBChainInfo.label}
</NetworkLabel>
<Tag>Coming soon</Tag>
</InternalLinkMenuItem>
{BACKEND_NOT_YET_SUPPORTED_CHAIN_IDS.map((network) => {
const chainInfo = getChainInfo(network)
return (
<InternalLinkMenuItem
key={network}
data-testid={`tokens-network-filter-option-${network}-chain`}
disabled
>
<NetworkLabel>
<Logo src={chainInfo.logoUrl} />
{chainInfo.label}
</NetworkLabel>
<Tag>Coming soon</Tag>
</InternalLinkMenuItem>
)
})}
</MenuTimeFlyout>
)}
</StyledMenu>

@ -1,4 +1,4 @@
import { SupportedChainId } from 'constants/chains'
import { ChainId } from '@uniswap/sdk-core'
import { Currency, TokenStandard } from 'graphql/data/__generated__/types-and-hooks'
import { CHAIN_ID_TO_BACKEND_NAME } from 'graphql/data/util'
import { render, screen } from 'test-utils/render'
@ -72,7 +72,7 @@ describe('LoadedRow.tsx', () => {
__typename: 'Token',
id: 'VG9rZW46RVRIRVJFVU1fMHhBMGI4Njk5MWM2MjE4YjM2YzFkMTlENGEyZTlFYjBjRTM2MDZlQjQ4',
name: 'USD Coin',
chain: CHAIN_ID_TO_BACKEND_NAME[SupportedChainId.MAINNET],
chain: CHAIN_ID_TO_BACKEND_NAME[ChainId.MAINNET],
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
symbol: 'USDC',
standard: TokenStandard.Erc20,
@ -96,7 +96,7 @@ describe('LoadedRow.tsx', () => {
__typename: 'Token',
id: 'VG9rZW46RVRIRVJFVU1fMHhBMGI4Njk5MWM2MjE4YjM2YzFkMTlENGEyZTlFYjBjRTM2MDZlQjQ4',
name: 'USD Coin',
chain: CHAIN_ID_TO_BACKEND_NAME[SupportedChainId.MAINNET],
chain: CHAIN_ID_TO_BACKEND_NAME[ChainId.MAINNET],
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
symbol: 'USDC',
standard: TokenStandard.Erc20,

@ -1,4 +1,4 @@
import { SupportedChainId } from 'constants/chains'
import { ChainId } from '@uniswap/sdk-core'
export const MAX_WIDTH_MEDIA_BREAKPOINT = '1200px'
export const XLARGE_MEDIA_BREAKPOINT = '960px'
@ -8,4 +8,4 @@ export const SMALL_MEDIA_BREAKPOINT = '540px'
export const MOBILE_MEDIA_BREAKPOINT = '420px'
// includes chains that the backend does not current source off-chain metadata for
export const UNSUPPORTED_METADATA_CHAINS = [SupportedChainId.BNB]
export const UNSUPPORTED_METADATA_CHAINS = [ChainId.BNB, ChainId.AVALANCHE]

@ -1,9 +1,9 @@
import { Trans } from '@lingui/macro'
import { Currency } from '@uniswap/sdk-core'
import { t, Trans } from '@lingui/macro'
import { ChainId, Currency } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import Badge from 'components/Badge'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId, SupportedL2ChainId } from 'constants/chains'
import { SupportedL2ChainId } from 'constants/chains'
import useCurrencyLogoURIs from 'lib/hooks/useCurrencyLogoURIs'
import { ReactNode, useCallback, useState } from 'react'
import { AlertCircle, ArrowUpCircle, CheckCircle } from 'react-feather'
@ -120,6 +120,8 @@ function TransactionSubmittedContent({
.catch(() => setSuccess(false))
}, [connector, logoURL, token])
const explorerText = chainId === ChainId.MAINNET ? t`View on Etherscan` : t`View on Block Explorer`
return (
<Wrapper>
<AutoColumn>
@ -157,9 +159,7 @@ function TransactionSubmittedContent({
</ButtonPrimary>
{chainId && hash && (
<ExternalLink href={getExplorerLink(chainId, hash, ExplorerDataType.TRANSACTION)}>
<ThemedText.Link color={theme.accentAction}>
<Trans>View on {chainId === SupportedChainId.MAINNET ? 'Etherscan' : 'Block Explorer'}</Trans>
</ThemedText.Link>
<ThemedText.Link color={theme.accentAction}>{explorerText}</ThemedText.Link>
</ExternalLink>
)}
</ConfirmationModalContentWrapper>

@ -5,7 +5,7 @@ import { AutoRow } from 'components/Row'
import { getConnections, networkConnection } from 'connection'
import { ActivationStatus, useActivationState } from 'connection/activate'
import { ConnectionType } from 'connection/types'
import { isSupportedChain } from 'constants/chains'
import { asSupportedChain, isSupportedChain } from 'constants/chains'
import { useWalletConnectV2AsDefault } from 'featureFlags/flags/walletConnectV2'
import { useEffect } from 'react'
import { Settings } from 'react-feather'
@ -55,7 +55,7 @@ export default function WalletModal({ openSettings }: { openSettings: () => void
// Keep the network connector in sync with any active user connector to prevent chain-switching on wallet disconnection.
useEffect(() => {
if (chainId && isSupportedChain(chainId) && connector !== networkConnection.connector) {
networkConnection.connector.activate(chainId)
networkConnection.connector.activate(asSupportedChain(chainId))
}
}, [chainId, connector])

@ -1,10 +1,10 @@
import { t, Trans } from '@lingui/macro'
import { Currency } from '@uniswap/sdk-core'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { ColumnCenter } from 'components/Column'
import Column from 'components/Column'
import Row from 'components/Row'
import { SupportedChainId } from 'constants/chains'
import { useUnmountingAnimation } from 'hooks/useUnmountingAnimation'
import { ReactNode, useRef } from 'react'
import { InterfaceTrade } from 'state/routing/types'
@ -212,7 +212,7 @@ export function PendingModalContent({
}
// On mainnet, we show the success icon once the tx is sent, since it takes longer to confirm than on L2s.
const showSuccess = swapConfirmed || (swapPending && chainId === SupportedChainId.MAINNET)
const showSuccess = swapConfirmed || (swapPending && chainId === ChainId.MAINNET)
return (
<PendingModalContainer gap="lg">

@ -1,4 +1,4 @@
import { SupportedChainId } from 'constants/chains'
import { ChainId } from '@uniswap/sdk-core'
import { transparentize } from 'polished'
import { ReactNode } from 'react'
import { AlertTriangle } from 'react-feather'
@ -29,7 +29,7 @@ export const SwapWrapper = styled.main<{ chainId?: number }>`
border: 1px solid ${({ theme }) => theme.backgroundOutline};
padding: 8px;
padding-top: 12px;
box-shadow: ${({ chainId }) => !!chainId && chainId === SupportedChainId.BNB && '0px 40px 120px 0px #f0b90b29'};
box-shadow: ${({ chainId }) => !!chainId && chainId === ChainId.BNB && '0px 40px 120px 0px #f0b90b29'};
z-index: ${Z_INDEX.default};
transition: transform 250ms ease;

@ -1,6 +1,6 @@
import { Trans } from '@lingui/macro'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from 'constants/chains'
import styled from 'styled-components/macro'
import { ThemedText } from 'theme'
@ -38,7 +38,7 @@ const EmptyState = ({ HeaderContent, SubHeaderContent }: EmptyStateProps) => (
export default function ProposalEmptyState() {
const { chainId } = useWeb3React()
if (chainId && chainId !== SupportedChainId.MAINNET) {
if (chainId && chainId !== ChainId.MAINNET) {
return (
<EmptyState
HeaderContent={() => <Trans>Please connect to Layer 1 Ethereum</Trans>}

@ -1,6 +1,7 @@
import { sendAnalyticsEvent } from '@uniswap/analytics'
import { ChainId } from '@uniswap/sdk-core'
import { URI_AVAILABLE, WalletConnect, WalletConnectConstructorArgs } 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 { Z_INDEX } from 'theme/zIndex'
import { isIOS } from 'utils/userAgent'
@ -69,7 +70,7 @@ export class UniwalletConnect extends WalletConnectV2 {
constructor({ actions, onError }: Omit<WalletConnectConstructorArgs, 'options'>) {
// disables walletconnect's proprietary qr code modal; instead UniwalletModal will listen for events to trigger our custom modal
super({ actions, defaultChainId: SupportedChainId.MAINNET, qrcode: false, onError })
super({ actions, defaultChainId: ChainId.MAINNET, qrcode: false, onError })
this.events.once(URI_AVAILABLE, () => {
this.provider?.events.on('disconnect', this.deactivate)

@ -1,6 +1,6 @@
import { ChainId } from '@uniswap/sdk-core'
import { Web3ReactHooks } from '@web3-react/core'
import { Connector } from '@web3-react/types'
import { SupportedChainId } from 'constants/chains'
import { useAppDispatch, useAppSelector } from 'state/hooks'
import { updateSelectedWallet } from 'state/user/reducer'
import { createDeferredPromise } from 'test-utils/promise'
@ -67,11 +67,11 @@ it('Should call activate function on a connection', async () => {
let activationCall: Promise<void> = new Promise(jest.fn())
act(() => {
activationCall = result.current.tryActivation(mockConnection, onSuccess, SupportedChainId.OPTIMISM)
activationCall = result.current.tryActivation(mockConnection, onSuccess, ChainId.OPTIMISM)
})
expect(result.current.activationState).toEqual({ status: ActivationStatus.PENDING, connection: mockConnection })
expect(mockConnection.overrideActivate).toHaveBeenCalledWith(SupportedChainId.OPTIMISM)
expect(mockConnection.overrideActivate).toHaveBeenCalledWith(ChainId.OPTIMISM)
expect(mockConnection.connector.activate).toHaveBeenCalledTimes(1)
expect(console.debug).toHaveBeenLastCalledWith(`Connection activating: ${mockConnection.getName()}`)
expect(onSuccess).toHaveBeenCalledTimes(0)

@ -1,7 +1,7 @@
import { sendAnalyticsEvent } from '@uniswap/analytics'
import { InterfaceEventName, WalletConnectionResult } from '@uniswap/analytics-events'
import { ChainId } from '@uniswap/sdk-core'
import { Connection } from 'connection/types'
import { SupportedChainId } from 'constants/chains'
import { atom } from 'jotai'
import { useAtomValue, useUpdateAtom } from 'jotai/utils'
import { useCallback } from 'react'
@ -32,7 +32,7 @@ function useTryActivation() {
const currentPage = getCurrentPageFromLocation(pathname)
return useCallback(
async (connection: Connection, onSuccess: () => void, chainId?: SupportedChainId) => {
async (connection: Connection, onSuccess: () => void, chainId?: ChainId) => {
// Skips wallet connection if the connection should override the default
// behavior, i.e. install MetaMask or launch Coinbase app
if (connection.overrideActivate?.(chainId)) return

@ -1,3 +1,4 @@
import { ChainId } from '@uniswap/sdk-core'
import { CoinbaseWallet } from '@web3-react/coinbase-wallet'
import { initializeConnector } from '@web3-react/core'
import { GnosisSafe } from '@web3-react/gnosis-safe'
@ -9,7 +10,6 @@ import UNISWAP_LOGO from 'assets/svg/logo.svg'
import COINBASE_ICON from 'assets/wallets/coinbase-icon.svg'
import UNIWALLET_ICON from 'assets/wallets/uniswap-wallet-icon.png'
import WALLET_CONNECT_ICON from 'assets/wallets/walletconnect-icon.svg'
import { SupportedChainId } from 'constants/chains'
import { isMobile, isNonIOSPhone } from 'utils/userAgent'
import { RPC_URLS } from '../constants/networks'
@ -83,7 +83,7 @@ export const walletConnectV1Connection: Connection = {
}
export const walletConnectV2Connection: Connection = new (class implements Connection {
private initializer = (actions: Actions, defaultChainId = SupportedChainId.MAINNET) =>
private initializer = (actions: Actions, defaultChainId = ChainId.MAINNET) =>
new WalletConnectV2({ actions, defaultChainId, onError })
type = ConnectionType.WALLET_CONNECT_V2
@ -92,7 +92,7 @@ export const walletConnectV2Connection: Connection = new (class implements Conne
shouldDisplay = () => !getIsInjectedMobileBrowser()
private _connector = initializeConnector<WalletConnectV2>(this.initializer)
overrideActivate = (chainId?: SupportedChainId) => {
overrideActivate = (chainId?: ChainId) => {
// Always re-create the connector, so that the chainId is updated.
this._connector = initializeConnector((actions) => this.initializer(actions, chainId))
return false
@ -136,7 +136,7 @@ const [web3CoinbaseWallet, web3CoinbaseWalletHooks] = initializeConnector<Coinba
new CoinbaseWallet({
actions,
options: {
url: RPC_URLS[SupportedChainId.MAINNET][0],
url: RPC_URLS[ChainId.MAINNET][0],
appName: 'Uniswap',
appLogoUrl: UNISWAP_LOGO,
reloadOnDisconnect: false,

@ -1,6 +1,6 @@
import { ChainId } from '@uniswap/sdk-core'
import { Web3ReactHooks } from '@web3-react/core'
import { Connector } from '@web3-react/types'
import { SupportedChainId } from 'constants/chains'
export enum ConnectionType {
UNISWAP_WALLET = 'UNISWAP_WALLET',
@ -22,6 +22,6 @@ export interface Connection {
type: ConnectionType
getIcon?(isDarkMode: boolean): string
shouldDisplay(): boolean
overrideActivate?: (chainId?: SupportedChainId) => boolean
overrideActivate?: (chainId?: ChainId) => boolean
isNew?: boolean
}

@ -1,185 +0,0 @@
import { FACTORY_ADDRESS as V2_FACTORY_ADDRESS } from '@uniswap/v2-sdk'
import { FACTORY_ADDRESS as V3_FACTORY_ADDRESS } from '@uniswap/v3-sdk'
import { SupportedChainId } from './chains'
type AddressMap = { [chainId: number]: string }
const DEFAULT_NETWORKS = [SupportedChainId.MAINNET, SupportedChainId.GOERLI, SupportedChainId.SEPOLIA]
function constructSameAddressMap(address: string, additionalNetworks: SupportedChainId[] = []): AddressMap {
return DEFAULT_NETWORKS.concat(additionalNetworks).reduce<AddressMap>((memo, chainId) => {
memo[chainId] = address
return memo
}, {})
}
export const UNI_ADDRESS: AddressMap = constructSameAddressMap('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984')
export const UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS = '0x8B799381ac40b838BBA4131ffB26197C432AFe78'
export const V2_FACTORY_ADDRESSES: AddressMap = constructSameAddressMap(V2_FACTORY_ADDRESS)
export const V2_ROUTER_ADDRESS: AddressMap = constructSameAddressMap('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D')
// celo v3 addresses
const CELO_V3_CORE_FACTORY_ADDRESSES = '0xAfE208a311B21f13EF87E33A90049fC17A7acDEc'
const CELO_V3_MIGRATOR_ADDRESSES = '0x3cFd4d48EDfDCC53D3f173F596f621064614C582'
const CELO_MULTICALL_ADDRESS = '0x633987602DE5C4F337e3DbF265303A1080324204'
const CELO_QUOTER_ADDRESSES = '0x82825d0554fA07f7FC52Ab63c961F330fdEFa8E8'
const CELO_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES = '0x3d79EdAaBC0EaB6F08ED885C05Fc0B014290D95A'
const CELO_TICK_LENS_ADDRESSES = '0x5f115D9113F88e0a0Db1b5033D90D4a9690AcD3D'
// BNB v3 addresses
const BNB_V3_CORE_FACTORY_ADDRESSES = '0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7'
const BNB_V3_MIGRATOR_ADDRESSES = '0x32681814957e0C13117ddc0c2aba232b5c9e760f'
const BNB_MULTICALL_ADDRESS = '0x963Df249eD09c358A4819E39d9Cd5736c3087184'
const BNB_QUOTER_ADDRESSES = '0x78D78E420Da98ad378D7799bE8f4AF69033EB077'
const BNB_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES = '0x7b8A01B39D58278b5DE7e48c8449c9f4F5170613'
const BNB_TICK_LENS_ADDRESSES = '0xD9270014D396281579760619CCf4c3af0501A47C'
// optimism goerli addresses
const OPTIMISM_GOERLI_V3_CORE_FACTORY_ADDRESSES = '0xB656dA17129e7EB733A557f4EBc57B76CFbB5d10'
const OPTIMISM_GOERLI_V3_MIGRATOR_ADDRESSES = '0xf6c55fBe84B1C8c3283533c53F51bC32F5C7Aba8'
const OPTIMISM_GOERLI_MULTICALL_ADDRESS = '0x07F2D8a2a02251B62af965f22fC4744A5f96BCCd'
const OPTIMISM_GOERLI_QUOTER_ADDRESSES = '0x9569CbA925c8ca2248772A9A4976A516743A246F'
const OPTIMISM_GOERLI_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES = '0x39Ca85Af2F383190cBf7d7c41ED9202D27426EF6'
const OPTIMISM_GOERLI_TICK_LENS_ADDRESSES = '0xe6140Bd164b63E8BfCfc40D5dF952f83e171758e'
// arbitrum goerli v3 addresses
const ARBITRUM_GOERLI_V3_CORE_FACTORY_ADDRESSES = '0x4893376342d5D7b3e31d4184c08b265e5aB2A3f6'
const ARBITRUM_GOERLI_V3_MIGRATOR_ADDRESSES = '0xA815919D2584Ac3F76ea9CB62E6Fd40a43BCe0C3'
const ARBITRUM_GOERLI_MULTICALL_ADDRESS = '0x8260CB40247290317a4c062F3542622367F206Ee'
const ARBITRUM_GOERLI_QUOTER_ADDRESSES = '0x1dd92b83591781D0C6d98d07391eea4b9a6008FA'
const ARBITRUM_GOERLI_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES = '0x622e4726a167799826d1E1D150b076A7725f5D81'
const ARBITRUM_GOERLI_TICK_LENS_ADDRESSES = '0xb52429333da969a0C79a60930a4Bf0020E5D1DE8'
// sepolia v3 addresses
const SEPOLIA_V3_CORE_FACTORY_ADDRESSES = '0x0227628f3F023bb0B980b67D528571c95c6DaC1c'
const SEPOLIA_V3_MIGRATOR_ADDRESSES = '0x729004182cF005CEC8Bd85df140094b6aCbe8b15'
const SEPOLIA_MULTICALL_ADDRESS = '0xD7F33bCdb21b359c8ee6F0251d30E94832baAd07'
const SEPOLIA_QUOTER_ADDRESSES = '0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3'
const SEPOLIA_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES = '0x1238536071E1c677A632429e3655c799b22cDA52'
const SEPOLIA_TICK_LENS_ADDRESSES = '0xd7f33bcdb21b359c8ee6f0251d30e94832baad07'
/* V3 Contract Addresses */
export const V3_CORE_FACTORY_ADDRESSES: AddressMap = {
...constructSameAddressMap(V3_FACTORY_ADDRESS, [
SupportedChainId.OPTIMISM,
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.POLYGON_MUMBAI,
SupportedChainId.POLYGON,
]),
[SupportedChainId.CELO]: CELO_V3_CORE_FACTORY_ADDRESSES,
[SupportedChainId.CELO_ALFAJORES]: CELO_V3_CORE_FACTORY_ADDRESSES,
[SupportedChainId.BNB]: BNB_V3_CORE_FACTORY_ADDRESSES,
[SupportedChainId.OPTIMISM_GOERLI]: OPTIMISM_GOERLI_V3_CORE_FACTORY_ADDRESSES,
[SupportedChainId.ARBITRUM_GOERLI]: ARBITRUM_GOERLI_V3_CORE_FACTORY_ADDRESSES,
[SupportedChainId.SEPOLIA]: SEPOLIA_V3_CORE_FACTORY_ADDRESSES,
}
export const V3_MIGRATOR_ADDRESSES: AddressMap = {
...constructSameAddressMap('0xA5644E29708357803b5A882D272c41cC0dF92B34', [
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.POLYGON_MUMBAI,
SupportedChainId.POLYGON,
]),
[SupportedChainId.CELO]: CELO_V3_MIGRATOR_ADDRESSES,
[SupportedChainId.CELO_ALFAJORES]: CELO_V3_MIGRATOR_ADDRESSES,
[SupportedChainId.BNB]: BNB_V3_MIGRATOR_ADDRESSES,
[SupportedChainId.OPTIMISM_GOERLI]: OPTIMISM_GOERLI_V3_MIGRATOR_ADDRESSES,
[SupportedChainId.ARBITRUM_GOERLI]: ARBITRUM_GOERLI_V3_MIGRATOR_ADDRESSES,
[SupportedChainId.SEPOLIA]: SEPOLIA_V3_MIGRATOR_ADDRESSES,
}
export const MULTICALL_ADDRESS: AddressMap = {
...constructSameAddressMap('0x1F98415757620B543A52E61c46B32eB19261F984', [
SupportedChainId.OPTIMISM,
SupportedChainId.POLYGON_MUMBAI,
SupportedChainId.POLYGON,
]),
[SupportedChainId.ARBITRUM_ONE]: '0xadF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB',
[SupportedChainId.CELO]: CELO_MULTICALL_ADDRESS,
[SupportedChainId.CELO_ALFAJORES]: CELO_MULTICALL_ADDRESS,
[SupportedChainId.BNB]: BNB_MULTICALL_ADDRESS,
[SupportedChainId.OPTIMISM_GOERLI]: OPTIMISM_GOERLI_MULTICALL_ADDRESS,
[SupportedChainId.ARBITRUM_GOERLI]: ARBITRUM_GOERLI_MULTICALL_ADDRESS,
[SupportedChainId.SEPOLIA]: SEPOLIA_MULTICALL_ADDRESS,
}
/**
* The oldest V0 governance address
*/
export const GOVERNANCE_ALPHA_V0_ADDRESSES: AddressMap = constructSameAddressMap(
'0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F'
)
/**
* The older V1 governance address
*/
export const GOVERNANCE_ALPHA_V1_ADDRESSES: AddressMap = {
[SupportedChainId.MAINNET]: '0xC4e172459f1E7939D522503B81AFAaC1014CE6F6',
}
/**
* The latest governor bravo that is currently admin of timelock
*/
export const GOVERNANCE_BRAVO_ADDRESSES: AddressMap = {
[SupportedChainId.MAINNET]: '0x408ED6354d4973f66138C91495F2f2FCbd8724C3',
}
export const TIMELOCK_ADDRESS: AddressMap = constructSameAddressMap('0x1a9C8182C09F50C8318d769245beA52c32BE35BC')
export const MERKLE_DISTRIBUTOR_ADDRESS: AddressMap = {
[SupportedChainId.MAINNET]: '0x090D4613473dEE047c3f2706764f49E0821D256e',
}
export const ARGENT_WALLET_DETECTOR_ADDRESS: AddressMap = {
[SupportedChainId.MAINNET]: '0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8',
}
export const QUOTER_ADDRESSES: AddressMap = {
...constructSameAddressMap('0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6', [
SupportedChainId.OPTIMISM,
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.POLYGON_MUMBAI,
SupportedChainId.POLYGON,
]),
[SupportedChainId.CELO]: CELO_QUOTER_ADDRESSES,
[SupportedChainId.CELO_ALFAJORES]: CELO_QUOTER_ADDRESSES,
[SupportedChainId.BNB]: BNB_QUOTER_ADDRESSES,
[SupportedChainId.OPTIMISM_GOERLI]: OPTIMISM_GOERLI_QUOTER_ADDRESSES,
[SupportedChainId.ARBITRUM_GOERLI]: ARBITRUM_GOERLI_QUOTER_ADDRESSES,
[SupportedChainId.SEPOLIA]: SEPOLIA_QUOTER_ADDRESSES,
}
export const NONFUNGIBLE_POSITION_MANAGER_ADDRESSES: AddressMap = {
...constructSameAddressMap('0xC36442b4a4522E871399CD717aBDD847Ab11FE88', [
SupportedChainId.OPTIMISM,
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.POLYGON_MUMBAI,
SupportedChainId.POLYGON,
]),
[SupportedChainId.CELO]: CELO_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES,
[SupportedChainId.CELO_ALFAJORES]: CELO_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES,
[SupportedChainId.BNB]: BNB_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES,
[SupportedChainId.OPTIMISM_GOERLI]: OPTIMISM_GOERLI_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES,
[SupportedChainId.ARBITRUM_GOERLI]: ARBITRUM_GOERLI_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES,
[SupportedChainId.SEPOLIA]: SEPOLIA_NONFUNGIBLE_POSITION_MANAGER_ADDRESSES,
}
export const ENS_REGISTRAR_ADDRESSES: AddressMap = {
[SupportedChainId.MAINNET]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
[SupportedChainId.GOERLI]: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
}
export const SOCKS_CONTROLLER_ADDRESSES: AddressMap = {
[SupportedChainId.MAINNET]: '0x65770b5283117639760beA3F867b69b3697a91dd',
}
export const TICK_LENS_ADDRESSES: AddressMap = {
[SupportedChainId.ARBITRUM_ONE]: '0xbfd8137f7d1516D3ea5cA83523914859ec47F573',
[SupportedChainId.ARBITRUM_GOERLI]: ARBITRUM_GOERLI_TICK_LENS_ADDRESSES,
[SupportedChainId.CELO]: CELO_TICK_LENS_ADDRESSES,
[SupportedChainId.CELO_ALFAJORES]: CELO_TICK_LENS_ADDRESSES,
[SupportedChainId.BNB]: BNB_TICK_LENS_ADDRESSES,
[SupportedChainId.OPTIMISM_GOERLI]: OPTIMISM_GOERLI_TICK_LENS_ADDRESSES,
[SupportedChainId.SEPOLIA]: SEPOLIA_TICK_LENS_ADDRESSES,
}

@ -1,7 +1,10 @@
import { ChainId } from '@uniswap/sdk-core'
import bnbCircleLogoUrl from 'assets/images/bnbCircle.svg'
import ethereumLogoUrl from 'assets/images/ethereum-logo.png'
import polygonCircleLogoUrl from 'assets/images/polygonCircle.png'
import { default as arbitrumCircleLogoUrl, default as arbitrumLogoUrl } from 'assets/svg/arbitrum_logo.svg'
import avaxLogo from 'assets/svg/avax_logo.svg'
import avaxSquareLogo from 'assets/svg/avax_square_logo.svg'
import bnbSquareLogoUrl from 'assets/svg/bnb_square_logo.svg'
import bnbLogo from 'assets/svg/bnb-logo.svg'
import celoLogo from 'assets/svg/celo_logo.svg'
@ -13,8 +16,8 @@ import polygonMaticLogo from 'assets/svg/polygon-matic-logo.svg'
import ms from 'ms.macro'
import { darkTheme } from 'theme/colors'
import { SupportedChainId, SupportedL1ChainId, SupportedL2ChainId } from './chains'
import { ARBITRUM_LIST, CELO_LIST, OPTIMISM_LIST, PLASMA_BNB_LIST } from './lists'
import { SupportedL1ChainId, SupportedL2ChainId } from './chains'
import { ARBITRUM_LIST, AVALANCHE_LIST, CELO_LIST, OPTIMISM_LIST, PLASMA_BNB_LIST } from './lists'
export const AVERAGE_L1_BLOCK_TIME = ms`12s`
@ -60,7 +63,7 @@ type ChainInfoMap = { readonly [chainId: number]: L1ChainInfo | L2ChainInfo } &
} & { 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/',
@ -70,7 +73,7 @@ const CHAIN_INFO: ChainInfoMap = {
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
color: darkTheme.chain_1,
},
[SupportedChainId.GOERLI]: {
[ChainId.GOERLI]: {
networkType: NetworkType.L1,
docs: 'https://docs.uniswap.org/',
explorer: 'https://goerli.etherscan.io/',
@ -80,7 +83,7 @@ const CHAIN_INFO: ChainInfoMap = {
nativeCurrency: { name: 'Görli Ether', symbol: 'görETH', decimals: 18 },
color: darkTheme.chain_5,
},
[SupportedChainId.SEPOLIA]: {
[ChainId.SEPOLIA]: {
networkType: NetworkType.L1,
docs: 'https://docs.uniswap.org/',
explorer: 'https://sepolia.etherscan.io/',
@ -90,7 +93,7 @@ const CHAIN_INFO: ChainInfoMap = {
nativeCurrency: { name: 'Sepolia Ether', symbol: 'SepoliaETH', decimals: 18 },
color: darkTheme.chain_5,
},
[SupportedChainId.OPTIMISM]: {
[ChainId.OPTIMISM]: {
networkType: NetworkType.L2,
blockWaitMsBeforeWarning: ms`25m`,
bridge: 'https://app.optimism.io/bridge',
@ -109,7 +112,7 @@ const CHAIN_INFO: ChainInfoMap = {
color: darkTheme.chain_10,
backgroundColor: darkTheme.chain_10_background,
},
[SupportedChainId.OPTIMISM_GOERLI]: {
[ChainId.OPTIMISM_GOERLI]: {
networkType: NetworkType.L2,
blockWaitMsBeforeWarning: ms`25m`,
bridge: 'https://app.optimism.io/bridge',
@ -124,7 +127,7 @@ const CHAIN_INFO: ChainInfoMap = {
nativeCurrency: { name: 'Optimism Goerli Ether', symbol: 'görOpETH', decimals: 18 },
color: darkTheme.chain_420,
},
[SupportedChainId.ARBITRUM_ONE]: {
[ChainId.ARBITRUM_ONE]: {
networkType: NetworkType.L2,
blockWaitMsBeforeWarning: ms`10m`,
bridge: 'https://bridge.arbitrum.io/',
@ -140,7 +143,7 @@ const CHAIN_INFO: ChainInfoMap = {
color: darkTheme.chain_42,
backgroundColor: darkTheme.chain_42161_background,
},
[SupportedChainId.ARBITRUM_GOERLI]: {
[ChainId.ARBITRUM_GOERLI]: {
networkType: NetworkType.L2,
blockWaitMsBeforeWarning: ms`10m`,
bridge: 'https://bridge.arbitrum.io/',
@ -154,7 +157,7 @@ const CHAIN_INFO: ChainInfoMap = {
nativeCurrency: { name: 'Goerli Arbitrum Ether', symbol: 'goerliArbETH', decimals: 18 },
color: darkTheme.chain_421613,
},
[SupportedChainId.POLYGON]: {
[ChainId.POLYGON]: {
networkType: NetworkType.L1,
blockWaitMsBeforeWarning: ms`10m`,
bridge: 'https://wallet.polygon.technology/polygon/bridge',
@ -169,7 +172,7 @@ const CHAIN_INFO: ChainInfoMap = {
color: darkTheme.chain_137,
backgroundColor: darkTheme.chain_137_background,
},
[SupportedChainId.POLYGON_MUMBAI]: {
[ChainId.POLYGON_MUMBAI]: {
networkType: NetworkType.L1,
blockWaitMsBeforeWarning: ms`10m`,
bridge: 'https://wallet.polygon.technology/bridge',
@ -180,7 +183,7 @@ const CHAIN_INFO: ChainInfoMap = {
logoUrl: polygonMaticLogo,
nativeCurrency: { name: 'Polygon Mumbai Matic', symbol: 'mMATIC', decimals: 18 },
},
[SupportedChainId.CELO]: {
[ChainId.CELO]: {
networkType: NetworkType.L1,
blockWaitMsBeforeWarning: ms`10m`,
bridge: 'https://www.portalbridge.com/#/transfer',
@ -194,7 +197,7 @@ const CHAIN_INFO: ChainInfoMap = {
nativeCurrency: { name: 'Celo', symbol: 'CELO', decimals: 18 },
defaultListUrl: CELO_LIST,
},
[SupportedChainId.CELO_ALFAJORES]: {
[ChainId.CELO_ALFAJORES]: {
networkType: NetworkType.L1,
blockWaitMsBeforeWarning: ms`10m`,
bridge: 'https://www.portalbridge.com/#/transfer',
@ -206,7 +209,7 @@ const CHAIN_INFO: ChainInfoMap = {
nativeCurrency: { name: 'Celo', symbol: 'CELO', decimals: 18 },
defaultListUrl: CELO_LIST,
},
[SupportedChainId.BNB]: {
[ChainId.BNB]: {
networkType: NetworkType.L1,
blockWaitMsBeforeWarning: ms`10m`,
bridge: 'https://cbridge.celer.network/1/56',
@ -222,20 +225,36 @@ const CHAIN_INFO: ChainInfoMap = {
color: darkTheme.chain_56,
backgroundColor: darkTheme.chain_56_background,
},
}
[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,
circleLogoUrl: avaxLogo,
squareLogoUrl: avaxSquareLogo,
nativeCurrency: { name: 'AVAX', symbol: 'AVAX', decimals: 18 },
defaultListUrl: AVALANCHE_LIST,
color: darkTheme.chain_43114,
backgroundColor: darkTheme.chain_43114_background,
},
} as const
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
/**
* Overloaded method for returning ChainInfo given a chainID
* Return type varies depending on input type:
* number | undefined -> returns chaininfo | undefined
* SupportedChainId -> returns L1ChainInfo | L2ChainInfo
* ChainId -> returns L1ChainInfo | L2ChainInfo
* SupportedL1ChainId -> returns L1ChainInfo
* SupportedL2ChainId -> returns L2ChainInfo
*/
@ -246,7 +265,7 @@ export function getChainInfo(chainId: any): any {
return undefined
}
const MAINNET_INFO = CHAIN_INFO[SupportedChainId.MAINNET]
const MAINNET_INFO = CHAIN_INFO[ChainId.MAINNET]
export function getChainInfoOrDefault(chainId: number | undefined) {
return getChainInfo(chainId) ?? MAINNET_INFO
}

@ -1,47 +0,0 @@
import { SupportedChainId as SdkSupportedChainId } from '@uniswap/sdk-core'
import { ALL_SUPPORTED_CHAIN_IDS, SupportedChainId } from './chains'
describe('ChainIds', () => {
describe('SupportedChainId', () => {
it('derives from sdk-core', () => {
const SDKChains = Object.values(SdkSupportedChainId)
.filter((chainId) => typeof chainId === 'number')
.map((value) => value.toString())
const InterfaceChains = Object.values(SupportedChainId)
.filter((chainId) => typeof chainId === 'number')
.map((value) => value.toString())
const isSubset = InterfaceChains.every((value) => SDKChains.includes(value))
expect(isSubset).toBe(true)
})
})
describe('ALL_SUPPORTED_CHAIN_IDS', () => {
it('contains all the values in the SupportedChainId enum', () => {
Object.values(SupportedChainId)
.filter((chainId) => typeof chainId === 'number')
.forEach((chainId) => {
expect(ALL_SUPPORTED_CHAIN_IDS.includes(chainId as number)).toBeTruthy()
})
})
it('contains no duplicates', () => {
const set = new Set<number>()
ALL_SUPPORTED_CHAIN_IDS.forEach((chainId) => {
expect(set.has(chainId)).toEqual(false)
set.add(chainId)
})
})
it('all values are in the SupportedChainId mapping', () => {
ALL_SUPPORTED_CHAIN_IDS.forEach((chainId) => {
// takes advantage of the reverse mapping
expect(SupportedChainId[chainId]).toBeTruthy()
})
})
it('all values are numeric', () => {
expect(ALL_SUPPORTED_CHAIN_IDS.every((chainId) => typeof chainId === 'number')).toBeTruthy()
})
})
})

@ -1,106 +1,75 @@
/**
* SupportedChainId must be defined inline, without using @uniswap/sdk-core, so that its members are their own types
* {@see https://www.typescriptlang.org/docs/handbook/enums.html#union-enums-and-enum-member-types}. This allows the
* derived const arrays and their types (eg {@link L1_CHAIN_IDS}, {@link SupportedL1ChainId}) to be narrowed and used
* to enforce chain typing.
*
* Because this is not explicitly derived from @uniswap/sdk-core, there is a unit test to enforce conformance.
*/
export enum SupportedChainId {
MAINNET = 1,
GOERLI = 5,
SEPOLIA = 11155111,
import { ChainId, SUPPORTED_CHAINS, SupportedChainsType } from '@uniswap/sdk-core'
ARBITRUM_ONE = 42161,
ARBITRUM_GOERLI = 421613,
OPTIMISM = 10,
OPTIMISM_GOERLI = 420,
POLYGON = 137,
POLYGON_MUMBAI = 80001,
CELO = 42220,
CELO_ALFAJORES = 44787,
BNB = 56,
}
export const UniWalletSupportedChains = [
SupportedChainId.MAINNET,
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.OPTIMISM,
SupportedChainId.POLYGON,
]
export const UniWalletSupportedChains = [ChainId.MAINNET, ChainId.ARBITRUM_ONE, ChainId.OPTIMISM, ChainId.POLYGON]
export const CHAIN_IDS_TO_NAMES = {
[SupportedChainId.MAINNET]: 'mainnet',
[SupportedChainId.GOERLI]: 'goerli',
[SupportedChainId.SEPOLIA]: 'sepolia',
[SupportedChainId.POLYGON]: 'polygon',
[SupportedChainId.POLYGON_MUMBAI]: 'polygon_mumbai',
[SupportedChainId.CELO]: 'celo',
[SupportedChainId.CELO_ALFAJORES]: 'celo_alfajores',
[SupportedChainId.ARBITRUM_ONE]: 'arbitrum',
[SupportedChainId.ARBITRUM_GOERLI]: 'arbitrum_goerli',
[SupportedChainId.OPTIMISM]: 'optimism',
[SupportedChainId.OPTIMISM_GOERLI]: 'optimism_goerli',
[SupportedChainId.BNB]: 'bnb',
[ChainId.MAINNET]: 'mainnet',
[ChainId.GOERLI]: 'goerli',
[ChainId.SEPOLIA]: 'sepolia',
[ChainId.POLYGON]: 'polygon',
[ChainId.POLYGON_MUMBAI]: 'polygon_mumbai',
[ChainId.CELO]: 'celo',
[ChainId.CELO_ALFAJORES]: 'celo_alfajores',
[ChainId.ARBITRUM_ONE]: 'arbitrum',
[ChainId.ARBITRUM_GOERLI]: 'arbitrum_goerli',
[ChainId.OPTIMISM]: 'optimism',
[ChainId.OPTIMISM_GOERLI]: 'optimism_goerli',
[ChainId.BNB]: 'bnb',
[ChainId.AVALANCHE]: 'avalanche',
} as const
export function isSupportedChain(chainId: number | null | undefined | ChainId): chainId is SupportedChainsType {
return !!chainId && SUPPORTED_CHAINS.indexOf(chainId) !== -1
}
/**
* Array of all the supported chain IDs
*/
export const ALL_SUPPORTED_CHAIN_IDS: SupportedChainId[] = Object.values(SupportedChainId).filter(
(id) => typeof id === 'number'
) as SupportedChainId[]
export function isSupportedChain(chainId: number | null | undefined): chainId is SupportedChainId {
return !!chainId && !!SupportedChainId[chainId]
export function asSupportedChain(chainId: number | null | undefined | ChainId): SupportedChainsType | undefined {
return isSupportedChain(chainId) ? chainId : undefined
}
export const SUPPORTED_GAS_ESTIMATE_CHAIN_IDS = [
SupportedChainId.MAINNET,
SupportedChainId.POLYGON,
SupportedChainId.CELO,
SupportedChainId.OPTIMISM,
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.BNB,
ChainId.MAINNET,
ChainId.POLYGON,
ChainId.CELO,
ChainId.OPTIMISM,
ChainId.ARBITRUM_ONE,
ChainId.BNB,
ChainId.AVALANCHE,
] as const
/**
* Unsupported networks for V2 pool behavior.
*/
export const UNSUPPORTED_V2POOL_CHAIN_IDS = [
SupportedChainId.POLYGON,
SupportedChainId.OPTIMISM,
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.BNB,
SupportedChainId.ARBITRUM_GOERLI,
ChainId.POLYGON,
ChainId.OPTIMISM,
ChainId.ARBITRUM_ONE,
ChainId.BNB,
ChainId.ARBITRUM_GOERLI,
ChainId.AVALANCHE,
] as const
export const TESTNET_CHAIN_IDS = new Set([
SupportedChainId.GOERLI,
SupportedChainId.SEPOLIA,
SupportedChainId.ARBITRUM_GOERLI,
SupportedChainId.OPTIMISM_GOERLI,
SupportedChainId.POLYGON_MUMBAI,
SupportedChainId.POLYGON_MUMBAI,
SupportedChainId.CELO_ALFAJORES,
])
export const TESTNET_CHAIN_IDS = [
ChainId.GOERLI,
ChainId.SEPOLIA,
ChainId.POLYGON_MUMBAI,
ChainId.ARBITRUM_GOERLI,
ChainId.OPTIMISM_GOERLI,
ChainId.CELO_ALFAJORES,
] as const
/**
* All the chain IDs that are running the Ethereum protocol.
*/
export const L1_CHAIN_IDS = [
SupportedChainId.MAINNET,
SupportedChainId.GOERLI,
SupportedChainId.SEPOLIA,
SupportedChainId.POLYGON,
SupportedChainId.POLYGON_MUMBAI,
SupportedChainId.CELO,
SupportedChainId.CELO_ALFAJORES,
SupportedChainId.BNB,
ChainId.MAINNET,
ChainId.GOERLI,
ChainId.SEPOLIA,
ChainId.POLYGON,
ChainId.POLYGON_MUMBAI,
ChainId.CELO,
ChainId.CELO_ALFAJORES,
ChainId.BNB,
ChainId.AVALANCHE,
] as const
export type SupportedL1ChainId = (typeof L1_CHAIN_IDS)[number]
@ -110,14 +79,14 @@ export type SupportedL1ChainId = (typeof L1_CHAIN_IDS)[number]
* The expectation is that all of these networks have immediate transaction confirmation.
*/
export const L2_CHAIN_IDS = [
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.ARBITRUM_GOERLI,
SupportedChainId.OPTIMISM,
SupportedChainId.OPTIMISM_GOERLI,
ChainId.ARBITRUM_ONE,
ChainId.ARBITRUM_GOERLI,
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
}

@ -1,19 +1,19 @@
import {
ChainId,
GOVERNANCE_ALPHA_V0_ADDRESSES,
GOVERNANCE_ALPHA_V1_ADDRESSES,
GOVERNANCE_BRAVO_ADDRESSES,
TIMELOCK_ADDRESS,
UNI_ADDRESS,
} from './addresses'
import { SupportedChainId } from './chains'
TIMELOCK_ADDRESSES,
UNI_ADDRESSES,
} from '@uniswap/sdk-core'
export const COMMON_CONTRACT_NAMES: Record<number, { [address: string]: string }> = {
[SupportedChainId.MAINNET]: {
[UNI_ADDRESS[SupportedChainId.MAINNET]]: 'UNI',
[TIMELOCK_ADDRESS[SupportedChainId.MAINNET]]: 'Timelock',
[GOVERNANCE_ALPHA_V0_ADDRESSES[SupportedChainId.MAINNET]]: 'Governance (V0)',
[GOVERNANCE_ALPHA_V1_ADDRESSES[SupportedChainId.MAINNET]]: 'Governance (V1)',
[GOVERNANCE_BRAVO_ADDRESSES[SupportedChainId.MAINNET]]: 'Governance',
[ChainId.MAINNET]: {
[UNI_ADDRESSES[ChainId.MAINNET]]: 'UNI',
[TIMELOCK_ADDRESSES[ChainId.MAINNET]]: 'Timelock',
[GOVERNANCE_ALPHA_V0_ADDRESSES[ChainId.MAINNET]]: 'Governance (V0)',
[GOVERNANCE_ALPHA_V1_ADDRESSES[ChainId.MAINNET]]: 'Governance (V1)',
[GOVERNANCE_BRAVO_ADDRESSES[ChainId.MAINNET]]: 'Governance',
'0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e': 'ENS Registry',
'0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41': 'ENS Public Resolver',
'0xf754A7E347F81cFdc70AF9FbCCe9Df3D826360FA': 'Franchiser Factory',

@ -11,6 +11,7 @@ const COINGECKO_ARBITRUM_LIST = 'https://tokens.coingecko.com/arbitrum-one/all.j
const COINGECKO_OPTIMISM_LIST = 'https://tokens.coingecko.com/optimistic-ethereum/all.json'
const COINGECKO_CELO_LIST = 'https://tokens.coingecko.com/celo/all.json'
const COINGECKO_POLYGON_LIST = 'https://tokens.coingecko.com/polygon-pos/all.json'
const COINGECKO_AVAX_LIST = 'https://tokens.coingecko.com/avalanche/all.json'
const COMPOUND_LIST = 'https://raw.githubusercontent.com/compound-finance/token-list/master/compound.tokenlist.json'
const GEMINI_LIST = 'https://www.gemini.com/uniswap/manifest.json'
const KLEROS_LIST = 't2crtokens.eth'
@ -21,6 +22,8 @@ export const OPTIMISM_LIST = 'https://static.optimism.io/optimism.tokenlist.json
export const ARBITRUM_LIST = 'https://bridge.arbitrum.io/token-list-42161.json'
export const CELO_LIST = 'https://celo-org.github.io/celo-token-list/celo.tokenlist.json'
export const PLASMA_BNB_LIST = 'https://raw.githubusercontent.com/plasmadlt/plasma-finance-token-list/master/bnb.json'
export const AVALANCHE_LIST =
'https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/token_list.json'
export const UNSUPPORTED_LIST_URLS: string[] = [BA_LIST, UNI_UNSUPPORTED_LIST]
@ -37,6 +40,7 @@ export const DEFAULT_INACTIVE_LIST_URLS: string[] = [
COINGECKO_OPTIMISM_LIST,
COINGECKO_CELO_LIST,
COINGECKO_POLYGON_LIST,
COINGECKO_AVAX_LIST,
KLEROS_LIST,
GEMINI_LIST,
WRAPPED_LIST,
@ -45,6 +49,7 @@ export const DEFAULT_INACTIVE_LIST_URLS: string[] = [
OPTIMISM_LIST,
CELO_LIST,
PLASMA_BNB_LIST,
AVALANCHE_LIST,
...UNSUPPORTED_LIST_URLS,
]

@ -1,4 +1,4 @@
import { SupportedChainId } from 'constants/chains'
import { ChainId } from '@uniswap/sdk-core'
const INFURA_KEY = process.env.REACT_APP_INFURA_KEY
if (typeof INFURA_KEY === 'undefined') {
@ -20,7 +20,7 @@ if (typeof QUICKNODE_RPC_URL === 'undefined') {
* These "Safe" URLs are listed first, followed by other fallback URLs, which are taken from chainlist.org.
*/
export const FALLBACK_URLS = {
[SupportedChainId.MAINNET]: [
[ChainId.MAINNET]: [
// "Safe" URLs
'https://api.mycryptoapi.com/eth',
'https://cloudflare-eth.com',
@ -28,13 +28,13 @@ export const FALLBACK_URLS = {
'https://rpc.ankr.com/eth',
'https://eth-mainnet.public.blastapi.io',
],
[SupportedChainId.GOERLI]: [
[ChainId.GOERLI]: [
// "Safe" URLs
'https://rpc.goerli.mudit.blog/',
// "Fallback" URLs
'https://rpc.ankr.com/eth_goerli',
],
[SupportedChainId.SEPOLIA]: [
[ChainId.SEPOLIA]: [
// "Safe" URLs
'https://rpc.sepolia.dev/',
// "Fallback" URLs
@ -45,7 +45,7 @@ export const FALLBACK_URLS = {
'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',
@ -54,41 +54,41 @@ export const FALLBACK_URLS = {
'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_GOERLI]: [
[ChainId.ARBITRUM_GOERLI]: [
// "Safe" URLs
'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`,
],
[SupportedChainId.CELO_ALFAJORES]: [
[ChainId.CELO_ALFAJORES]: [
// "Safe" URLs
`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',
@ -100,6 +100,15 @@ export const FALLBACK_URLS = {
'https://bsc-dataseed4.defibit.io',
'https://rpc.ankr.com/bsc',
],
[ChainId.AVALANCHE]: [
// "Safe" URLs
'https://api.avax.network/ext/bc/C/rpc',
'https://rpc.ankr.com/avalanche',
'https://avalanche.blockpi.network/v1/rpc/public',
'https://avalanche-c-chain.publicnode.com',
'https://endpoints.omniatech.io/v1/avax/mainnet/public',
'https://ava-mainnet.public.blastapi.io/ext/bc/C/rpc',
],
}
/**
@ -107,40 +116,29 @@ export const FALLBACK_URLS = {
* These are the URLs used by the interface when there is not another available source of chain data.
*/
export const RPC_URLS = {
[SupportedChainId.MAINNET]: [
`https://mainnet.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.MAINNET],
],
[SupportedChainId.GOERLI]: [`https://goerli.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[SupportedChainId.GOERLI]],
[SupportedChainId.SEPOLIA]: [
`https://sepolia.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.SEPOLIA],
],
[SupportedChainId.OPTIMISM]: [
`https://optimism-mainnet.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.OPTIMISM],
],
[SupportedChainId.OPTIMISM_GOERLI]: [
[ChainId.MAINNET]: [`https://mainnet.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[ChainId.MAINNET]],
[ChainId.GOERLI]: [`https://goerli.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[ChainId.GOERLI]],
[ChainId.SEPOLIA]: [`https://sepolia.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[ChainId.SEPOLIA]],
[ChainId.OPTIMISM]: [`https://optimism-mainnet.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[ChainId.OPTIMISM]],
[ChainId.OPTIMISM_GOERLI]: [
`https://optimism-goerli.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.OPTIMISM_GOERLI],
...FALLBACK_URLS[ChainId.OPTIMISM_GOERLI],
],
[SupportedChainId.ARBITRUM_ONE]: [
[ChainId.ARBITRUM_ONE]: [
`https://arbitrum-mainnet.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.ARBITRUM_ONE],
...FALLBACK_URLS[ChainId.ARBITRUM_ONE],
],
[SupportedChainId.ARBITRUM_GOERLI]: [
[ChainId.ARBITRUM_GOERLI]: [
`https://arbitrum-goerli.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.ARBITRUM_GOERLI],
...FALLBACK_URLS[ChainId.ARBITRUM_GOERLI],
],
[SupportedChainId.POLYGON]: [
`https://polygon-mainnet.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.POLYGON],
],
[SupportedChainId.POLYGON_MUMBAI]: [
[ChainId.POLYGON]: [`https://polygon-mainnet.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[ChainId.POLYGON]],
[ChainId.POLYGON_MUMBAI]: [
`https://polygon-mumbai.infura.io/v3/${INFURA_KEY}`,
...FALLBACK_URLS[SupportedChainId.POLYGON_MUMBAI],
...FALLBACK_URLS[ChainId.POLYGON_MUMBAI],
],
[SupportedChainId.CELO]: FALLBACK_URLS[SupportedChainId.CELO],
[SupportedChainId.CELO_ALFAJORES]: FALLBACK_URLS[SupportedChainId.CELO_ALFAJORES],
[SupportedChainId.BNB]: [QUICKNODE_RPC_URL, ...FALLBACK_URLS[SupportedChainId.BNB]],
[ChainId.CELO]: FALLBACK_URLS[ChainId.CELO],
[ChainId.CELO_ALFAJORES]: FALLBACK_URLS[ChainId.CELO_ALFAJORES],
[ChainId.BNB]: [QUICKNODE_RPC_URL, ...FALLBACK_URLS[ChainId.BNB]],
[ChainId.AVALANCHE]: [`https://avalanche-mainnet.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[ChainId.AVALANCHE]],
}

@ -3,7 +3,7 @@ import { deepCopy } from '@ethersproject/properties'
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { StaticJsonRpcProvider } from '@ethersproject/providers'
import { isPlain } from '@reduxjs/toolkit'
import { SupportedChainId } from 'constants/chains'
import { ChainId, SupportedChainsType } from '@uniswap/sdk-core'
import { AVERAGE_L1_BLOCK_TIME } from './chainInfo'
import { CHAIN_IDS_TO_NAMES } from './chains'
@ -20,7 +20,7 @@ class AppJsonRpcProvider extends StaticJsonRpcProvider {
return this._blockCache
}
constructor(chainId: SupportedChainId) {
constructor(chainId: SupportedChainsType) {
// Including networkish allows ethers to skip the initial detectNetwork call.
super(RPC_URLS[chainId][0], /* networkish= */ { chainId, name: CHAIN_IDS_TO_NAMES[chainId] })
@ -57,17 +57,18 @@ class AppJsonRpcProvider extends StaticJsonRpcProvider {
/**
* These are the only JsonRpcProviders used directly by the interface.
*/
export const RPC_PROVIDERS: { [key in SupportedChainId]: StaticJsonRpcProvider } = {
[SupportedChainId.MAINNET]: new AppJsonRpcProvider(SupportedChainId.MAINNET),
[SupportedChainId.GOERLI]: new AppJsonRpcProvider(SupportedChainId.GOERLI),
[SupportedChainId.SEPOLIA]: new AppJsonRpcProvider(SupportedChainId.SEPOLIA),
[SupportedChainId.OPTIMISM]: new AppJsonRpcProvider(SupportedChainId.OPTIMISM),
[SupportedChainId.OPTIMISM_GOERLI]: new AppJsonRpcProvider(SupportedChainId.OPTIMISM_GOERLI),
[SupportedChainId.ARBITRUM_ONE]: new AppJsonRpcProvider(SupportedChainId.ARBITRUM_ONE),
[SupportedChainId.ARBITRUM_GOERLI]: new AppJsonRpcProvider(SupportedChainId.ARBITRUM_GOERLI),
[SupportedChainId.POLYGON]: new AppJsonRpcProvider(SupportedChainId.POLYGON),
[SupportedChainId.POLYGON_MUMBAI]: new AppJsonRpcProvider(SupportedChainId.POLYGON_MUMBAI),
[SupportedChainId.CELO]: new AppJsonRpcProvider(SupportedChainId.CELO),
[SupportedChainId.CELO_ALFAJORES]: new AppJsonRpcProvider(SupportedChainId.CELO_ALFAJORES),
[SupportedChainId.BNB]: new AppJsonRpcProvider(SupportedChainId.BNB),
export const RPC_PROVIDERS: { [key in SupportedChainsType]: StaticJsonRpcProvider } = {
[ChainId.MAINNET]: new AppJsonRpcProvider(ChainId.MAINNET),
[ChainId.GOERLI]: new AppJsonRpcProvider(ChainId.GOERLI),
[ChainId.SEPOLIA]: new AppJsonRpcProvider(ChainId.SEPOLIA),
[ChainId.OPTIMISM]: new AppJsonRpcProvider(ChainId.OPTIMISM),
[ChainId.OPTIMISM_GOERLI]: new AppJsonRpcProvider(ChainId.OPTIMISM_GOERLI),
[ChainId.ARBITRUM_ONE]: new AppJsonRpcProvider(ChainId.ARBITRUM_ONE),
[ChainId.ARBITRUM_GOERLI]: new AppJsonRpcProvider(ChainId.ARBITRUM_GOERLI),
[ChainId.POLYGON]: new AppJsonRpcProvider(ChainId.POLYGON),
[ChainId.POLYGON_MUMBAI]: new AppJsonRpcProvider(ChainId.POLYGON_MUMBAI),
[ChainId.CELO]: new AppJsonRpcProvider(ChainId.CELO),
[ChainId.CELO_ALFAJORES]: new AppJsonRpcProvider(ChainId.CELO_ALFAJORES),
[ChainId.BNB]: new AppJsonRpcProvider(ChainId.BNB),
[ChainId.AVALANCHE]: new AppJsonRpcProvider(ChainId.AVALANCHE),
}

@ -1,30 +1,31 @@
import { SupportedChainId } from './chains'
import { ChainId } from '@uniswap/sdk-core'
import { COMMON_BASES } from './routing'
describe('Routing', () => {
describe('COMMON_BASES', () => {
it('contains all coins for mainnet', () => {
const symbols = COMMON_BASES[SupportedChainId.MAINNET].map((coin) => coin.symbol)
const symbols = COMMON_BASES[ChainId.MAINNET].map((coin) => coin.symbol)
expect(symbols).toEqual(['ETH', 'DAI', 'USDC', 'USDT', 'WBTC', 'WETH'])
})
it('contains all coins for arbitrum', () => {
const symbols = COMMON_BASES[SupportedChainId.ARBITRUM_ONE].map((coin) => coin.symbol)
const symbols = COMMON_BASES[ChainId.ARBITRUM_ONE].map((coin) => coin.symbol)
expect(symbols).toEqual(['ETH', 'ARB', 'DAI', 'USDC', 'USDT', 'WBTC', 'WETH'])
})
it('contains all coins for optimism', () => {
const symbols = COMMON_BASES[SupportedChainId.OPTIMISM].map((coin) => coin.symbol)
const symbols = COMMON_BASES[ChainId.OPTIMISM].map((coin) => coin.symbol)
expect(symbols).toEqual(['ETH', 'OP', 'DAI', 'USDC', 'USDT', 'WBTC'])
})
it('contains all coins for polygon', () => {
const symbols = COMMON_BASES[SupportedChainId.POLYGON].map((coin) => coin.symbol)
const symbols = COMMON_BASES[ChainId.POLYGON].map((coin) => coin.symbol)
expect(symbols).toEqual(['MATIC', 'WETH', 'USDC', 'DAI', 'USDT', 'WBTC'])
})
it('contains all coins for celo', () => {
const symbols = COMMON_BASES[SupportedChainId.CELO].map((coin) => coin.symbol)
const symbols = COMMON_BASES[ChainId.CELO].map((coin) => coin.symbol)
expect(symbols).toEqual(['CELO', 'cEUR', 'cUSD', 'ETH', 'USDCet', 'cMCO2'])
})
it('contains all coins for bsc', () => {
const symbols = COMMON_BASES[SupportedChainId.BNB].map((coin) => coin.symbol)
const symbols = COMMON_BASES[ChainId.BNB].map((coin) => coin.symbol)
expect(symbols).toEqual(['BNB', 'DAI', 'USDC', 'USDT', 'ETH', 'BTCB', 'BUSD'])
})
})

@ -1,6 +1,5 @@
// a list of tokens by chain
import { Currency, Token } from '@uniswap/sdk-core'
import { SupportedChainId } from 'constants/chains'
import { ChainId, Currency, Token } from '@uniswap/sdk-core'
import {
AMPL,
@ -15,6 +14,7 @@ import {
CUSD_CELO_ALFAJORES,
DAI,
DAI_ARBITRUM_ONE,
DAI_AVALANCHE,
DAI_BSC,
DAI_OPTIMISM,
DAI_POLYGON,
@ -36,12 +36,14 @@ import {
TRIBE,
USDC_ARBITRUM,
USDC_ARBITRUM_GOERLI,
USDC_AVALANCHE,
USDC_BSC,
USDC_MAINNET,
USDC_OPTIMISM,
USDC_POLYGON,
USDT,
USDT_ARBITRUM_ONE,
USDT_AVALANCHE,
USDT_BSC,
USDT_OPTIMISM,
USDT_POLYGON,
@ -49,6 +51,7 @@ import {
WBTC_ARBITRUM_ONE,
WBTC_OPTIMISM,
WBTC_POLYGON,
WETH_AVALANCHE,
WETH_POLYGON,
WETH_POLYGON_MUMBAI,
WRAPPED_NATIVE_CURRENCY,
@ -71,34 +74,23 @@ 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]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.MAINNET],
DAI,
USDC_MAINNET,
USDT,
WBTC,
],
[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.MAINNET]: [...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.MAINNET], DAI, USDC_MAINNET, USDT, WBTC],
[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.BNB]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.BNB],
[ChainId.BNB]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.BNB],
DAI_BSC,
USDC_BSC,
USDT_BSC,
@ -107,10 +99,17 @@ export const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
MATIC_BSC,
CAKE_BSC,
],
[SupportedChainId.CELO]: [CUSD_CELO, CEUR_CELO, CMC02_CELO, PORTAL_USDC_CELO, PORTAL_ETH_CELO],
[ChainId.AVALANCHE]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.AVALANCHE],
DAI_AVALANCHE,
USDC_AVALANCHE,
USDT_AVALANCHE,
WETH_AVALANCHE,
],
[ChainId.CELO]: [CUSD_CELO, CEUR_CELO, CMC02_CELO, PORTAL_USDC_CELO, PORTAL_ETH_CELO],
}
export const ADDITIONAL_BASES: { [chainId: number]: { [tokenAddress: string]: Token[] } } = {
[SupportedChainId.MAINNET]: {
[ChainId.MAINNET]: {
'0xF16E4d813f4DcfDe4c5b44f305c908742De84eF0': [ETH2X_FLI],
[rETH2.address]: [sETH2],
[SWISE.address]: [sETH2],
@ -127,8 +126,8 @@ 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],
},
}
@ -136,96 +135,65 @@ export const CUSTOM_BASES: { [chainId: number]: { [tokenAddress: string]: Token[
* Shows up in the currency select for swap and add liquidity
*/
export const COMMON_BASES: ChainCurrencyList = {
[SupportedChainId.MAINNET]: [
nativeOnChain(SupportedChainId.MAINNET),
[ChainId.MAINNET]: [
nativeOnChain(ChainId.MAINNET),
DAI,
USDC_MAINNET,
USDT,
WBTC,
WRAPPED_NATIVE_CURRENCY[SupportedChainId.MAINNET] as Token,
WRAPPED_NATIVE_CURRENCY[ChainId.MAINNET] as Token,
],
[SupportedChainId.GOERLI]: [
nativeOnChain(SupportedChainId.GOERLI),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.GOERLI] as Token,
],
[SupportedChainId.SEPOLIA]: [
nativeOnChain(SupportedChainId.SEPOLIA),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.SEPOLIA] as Token,
],
[SupportedChainId.ARBITRUM_ONE]: [
nativeOnChain(SupportedChainId.ARBITRUM_ONE),
[ChainId.GOERLI]: [nativeOnChain(ChainId.GOERLI), WRAPPED_NATIVE_CURRENCY[ChainId.GOERLI] as Token],
[ChainId.SEPOLIA]: [nativeOnChain(ChainId.SEPOLIA), WRAPPED_NATIVE_CURRENCY[ChainId.SEPOLIA] as Token],
[ChainId.ARBITRUM_ONE]: [
nativeOnChain(ChainId.ARBITRUM_ONE),
ARB,
DAI_ARBITRUM_ONE,
USDC_ARBITRUM,
USDT_ARBITRUM_ONE,
WBTC_ARBITRUM_ONE,
WRAPPED_NATIVE_CURRENCY[SupportedChainId.ARBITRUM_ONE] as Token,
WRAPPED_NATIVE_CURRENCY[ChainId.ARBITRUM_ONE] as Token,
],
[SupportedChainId.ARBITRUM_GOERLI]: [
nativeOnChain(SupportedChainId.ARBITRUM_GOERLI),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.ARBITRUM_GOERLI] as Token,
[ChainId.ARBITRUM_GOERLI]: [
nativeOnChain(ChainId.ARBITRUM_GOERLI),
WRAPPED_NATIVE_CURRENCY[ChainId.ARBITRUM_GOERLI] as Token,
USDC_ARBITRUM_GOERLI,
],
[SupportedChainId.OPTIMISM]: [
nativeOnChain(SupportedChainId.OPTIMISM),
OP,
DAI_OPTIMISM,
USDC_OPTIMISM,
USDT_OPTIMISM,
WBTC_OPTIMISM,
],
[SupportedChainId.OPTIMISM_GOERLI]: [nativeOnChain(SupportedChainId.OPTIMISM_GOERLI)],
[SupportedChainId.POLYGON]: [
nativeOnChain(SupportedChainId.POLYGON),
[ChainId.OPTIMISM]: [nativeOnChain(ChainId.OPTIMISM), OP, DAI_OPTIMISM, USDC_OPTIMISM, USDT_OPTIMISM, WBTC_OPTIMISM],
[ChainId.OPTIMISM_GOERLI]: [nativeOnChain(ChainId.OPTIMISM_GOERLI)],
[ChainId.POLYGON]: [
nativeOnChain(ChainId.POLYGON),
WETH_POLYGON,
USDC_POLYGON,
DAI_POLYGON,
USDT_POLYGON,
WBTC_POLYGON,
],
[SupportedChainId.POLYGON_MUMBAI]: [
nativeOnChain(SupportedChainId.POLYGON_MUMBAI),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.POLYGON_MUMBAI] as Token,
[ChainId.POLYGON_MUMBAI]: [
nativeOnChain(ChainId.POLYGON_MUMBAI),
WRAPPED_NATIVE_CURRENCY[ChainId.POLYGON_MUMBAI] as Token,
WETH_POLYGON_MUMBAI,
],
[SupportedChainId.CELO]: [
nativeOnChain(SupportedChainId.CELO),
CEUR_CELO,
CUSD_CELO,
PORTAL_ETH_CELO,
PORTAL_USDC_CELO,
CMC02_CELO,
],
[SupportedChainId.CELO_ALFAJORES]: [
nativeOnChain(SupportedChainId.CELO_ALFAJORES),
CUSD_CELO_ALFAJORES,
CEUR_CELO_ALFAJORES,
],
[ChainId.CELO]: [nativeOnChain(ChainId.CELO), CEUR_CELO, CUSD_CELO, PORTAL_ETH_CELO, PORTAL_USDC_CELO, CMC02_CELO],
[ChainId.CELO_ALFAJORES]: [nativeOnChain(ChainId.CELO_ALFAJORES), CUSD_CELO_ALFAJORES, CEUR_CELO_ALFAJORES],
[SupportedChainId.BNB]: [
nativeOnChain(SupportedChainId.BNB),
DAI_BSC,
USDC_BSC,
USDT_BSC,
ETH_BSC,
BTC_BSC,
BUSD_BSC,
[ChainId.BNB]: [nativeOnChain(ChainId.BNB), DAI_BSC, USDC_BSC, USDT_BSC, ETH_BSC, BTC_BSC, BUSD_BSC],
[ChainId.AVALANCHE]: [
nativeOnChain(ChainId.AVALANCHE),
DAI_AVALANCHE,
USDC_AVALANCHE,
USDT_AVALANCHE,
WETH_AVALANCHE,
],
}
// used to construct the list of all pairs we consider by default in the frontend
export const BASES_TO_TRACK_LIQUIDITY_FOR: ChainTokenList = {
...WRAPPED_NATIVE_CURRENCIES_ONLY,
[SupportedChainId.MAINNET]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.MAINNET],
DAI,
USDC_MAINNET,
USDT,
WBTC,
],
[SupportedChainId.BNB]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.BNB],
[ChainId.MAINNET]: [...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.MAINNET], DAI, USDC_MAINNET, USDT, WBTC],
[ChainId.BNB]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.BNB],
DAI_BSC,
USDC_BSC,
USDT_BSC,
@ -233,18 +201,19 @@ export const BASES_TO_TRACK_LIQUIDITY_FOR: ChainTokenList = {
BUSD_BSC,
ETH_BSC,
],
[ChainId.AVALANCHE]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.AVALANCHE],
DAI_AVALANCHE,
USDC_AVALANCHE,
USDT_AVALANCHE,
WETH_AVALANCHE,
],
}
export const PINNED_PAIRS: { readonly [chainId: number]: [Token, Token][] } = {
[SupportedChainId.MAINNET]: [
[ChainId.MAINNET]: [
[
new Token(SupportedChainId.MAINNET, '0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643', 8, 'cDAI', 'Compound Dai'),
new Token(
SupportedChainId.MAINNET,
'0x39AA39c021dfbaE8faC545936693aC917d5E7563',
8,
'cUSDC',
'Compound USD Coin'
),
new Token(ChainId.MAINNET, '0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643', 8, 'cDAI', 'Compound Dai'),
new Token(ChainId.MAINNET, '0x39AA39c021dfbaE8faC545936693aC917d5E7563', 8, 'cUSDC', 'Compound USD Coin'),
],
[USDC_MAINNET, USDT],
[DAI, USDT],

@ -1,9 +1,6 @@
import { Currency, Ether, NativeCurrency, Token, WETH9 } from '@uniswap/sdk-core'
import { ChainId, Currency, Ether, NativeCurrency, Token, UNI_ADDRESSES, WETH9 } from '@uniswap/sdk-core'
import invariant from 'tiny-invariant'
import { UNI_ADDRESS } from './addresses'
import { SupportedChainId } from './chains'
export const NATIVE_CHAIN_ID = 'NATIVE'
// When decimals are not specified for an ERC20 token
@ -12,238 +9,166 @@ export const NATIVE_CHAIN_ID = 'NATIVE'
export const DEFAULT_ERC20_DECIMALS = 18
export const USDC_MAINNET = new Token(
SupportedChainId.MAINNET,
ChainId.MAINNET,
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
6,
'USDC',
'USD//C'
)
const USDC_GOERLI = new Token(
SupportedChainId.GOERLI,
'0x07865c6e87b9f70255377e024ace6630c1eaa37f',
6,
'USDC',
'USD//C'
)
const USDC_SEPOLIA = new Token(
SupportedChainId.SEPOLIA,
'0x6f14C02Fc1F78322cFd7d707aB90f18baD3B54f5',
6,
'USDC',
'USD//C'
)
const USDC_GOERLI = new Token(ChainId.GOERLI, '0x07865c6e87b9f70255377e024ace6630c1eaa37f', 6, 'USDC', 'USD//C')
const USDC_SEPOLIA = new Token(ChainId.SEPOLIA, '0x6f14C02Fc1F78322cFd7d707aB90f18baD3B54f5', 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 BRIDGED_USDC_ARBITRUM = new Token(
SupportedChainId.ARBITRUM_ONE,
ChainId.ARBITRUM_ONE,
'0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8',
6,
'USDC',
'USD//C'
)
export const USDC_ARBITRUM = new Token(
SupportedChainId.ARBITRUM_ONE,
ChainId.ARBITRUM_ONE,
'0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
6,
'USDC',
'USD//C'
)
export const USDC_ARBITRUM_GOERLI = new Token(
SupportedChainId.ARBITRUM_GOERLI,
ChainId.ARBITRUM_GOERLI,
'0x8FB1E3fC51F3b789dED7557E680551d93Ea9d892',
6,
'USDC',
'USD//C'
)
export const USDC_POLYGON = new Token(
SupportedChainId.POLYGON,
ChainId.POLYGON,
'0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
6,
'USDC',
'USD//C'
)
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 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 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',
@ -251,254 +176,204 @@ export const WETH_POLYGON_MUMBAI = new Token(
)
export const WETH_POLYGON = new Token(
SupportedChainId.POLYGON,
ChainId.POLYGON,
'0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',
18,
'WETH',
'Wrapped Ether'
)
const CELO_CELO = new Token(SupportedChainId.CELO, '0x471EcE3750Da237f93B8E339c536989b8978a438', 18, 'CELO', 'Celo')
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'
)
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 USDC_BSC = new Token(
SupportedChainId.BNB,
'0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d',
18,
export const USDC_BSC = new Token(ChainId.BNB, '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', 18, 'USDC', 'USDC')
export const USDT_BSC = new Token(ChainId.BNB, '0x55d398326f99059fF775485246999027B3197955', 18, 'USDT', 'USDT')
export const ETH_BSC = new Token(ChainId.BNB, '0x2170Ed0880ac9A755fd29B2688956BD959F933F8', 18, 'ETH', 'Ethereum')
export const MATIC_BSC = new Token(ChainId.BNB, '0xCC42724C6683B7E57334c4E856f4c9965ED682bD', 18, 'MATIC', 'Matic')
export const FRAX_BSC = new Token(ChainId.BNB, '0x90C97F71E18723b0Cf0dfa30ee176Ab653E89F40', 18, 'FRAX', 'FRAX')
export const BTC_BSC = new Token(ChainId.BNB, '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c', 18, 'BTCB', 'BTCB')
export const CAKE_BSC = new Token(ChainId.BNB, '0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82', 18, 'CAKE', 'Cake')
export const BUSD_BSC = new Token(ChainId.BNB, '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56', 18, 'BUSD', 'BUSD')
export const DAI_BSC = new Token(ChainId.BNB, '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', 18, 'DAI', 'DAI')
export const USDC_AVALANCHE = new Token(
ChainId.AVALANCHE,
'0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',
6,
'USDC',
'USDC'
'USDC Token'
)
export const USDT_BSC = new Token(
SupportedChainId.BNB,
'0x55d398326f99059fF775485246999027B3197955',
18,
export const USDT_AVALANCHE = new Token(
ChainId.AVALANCHE,
'0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7',
6,
'USDT',
'USDT'
'Tether USD'
)
export const ETH_BSC = new Token(
SupportedChainId.BNB,
'0x2170Ed0880ac9A755fd29B2688956BD959F933F8',
export const WETH_AVALANCHE = new Token(
ChainId.AVALANCHE,
'0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB',
18,
'ETH',
'Ethereum'
'WETH',
'Wrapped Ether'
)
export const MATIC_BSC = new Token(
SupportedChainId.BNB,
'0xCC42724C6683B7E57334c4E856f4c9965ED682bD',
export const DAI_AVALANCHE = new Token(
ChainId.AVALANCHE,
'0xd586E7F844cEa2F87f50152665BCbc2C279D8d70',
18,
'MATIC',
'Matic'
'DAI.e',
'Dai.e Token'
)
export const FRAX_BSC = new Token(
SupportedChainId.BNB,
'0x90C97F71E18723b0Cf0dfa30ee176Ab653E89F40',
18,
'FRAX',
'FRAX'
)
export const BTC_BSC = new Token(SupportedChainId.BNB, '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c', 18, 'BTCB', 'BTCB')
export const CAKE_BSC = new Token(
SupportedChainId.BNB,
'0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82',
18,
'CAKE',
'Cake'
)
export const BUSD_BSC = new Token(
SupportedChainId.BNB,
'0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
18,
'BUSD',
'BUSD'
)
export const DAI_BSC = new Token(SupportedChainId.BNB, '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', 18, 'DAI', 'DAI')
export const UNI: { [chainId: number]: Token } = {
[SupportedChainId.MAINNET]: new Token(
SupportedChainId.MAINNET,
UNI_ADDRESS[SupportedChainId.MAINNET],
18,
'UNI',
'Uniswap'
),
[SupportedChainId.GOERLI]: new Token(
SupportedChainId.GOERLI,
UNI_ADDRESS[SupportedChainId.GOERLI],
18,
'UNI',
'Uniswap'
),
[SupportedChainId.SEPOLIA]: new Token(
SupportedChainId.SEPOLIA,
UNI_ADDRESS[SupportedChainId.SEPOLIA],
18,
'UNI',
'Uniswap'
),
[ChainId.MAINNET]: new Token(ChainId.MAINNET, UNI_ADDRESSES[ChainId.MAINNET], 18, 'UNI', 'Uniswap'),
[ChainId.GOERLI]: new Token(ChainId.GOERLI, UNI_ADDRESSES[ChainId.GOERLI], 18, 'UNI', 'Uniswap'),
[ChainId.SEPOLIA]: new Token(ChainId.SEPOLIA, UNI_ADDRESSES[ChainId.SEPOLIA], 18, 'UNI', 'Uniswap'),
}
export const ARB = new Token(
SupportedChainId.ARBITRUM_ONE,
'0x912CE59144191C1204E64559FE8253a0e49E6548',
18,
'ARB',
'Arbitrum'
)
export const ARB = new Token(ChainId.ARBITRUM_ONE, '0x912CE59144191C1204E64559FE8253a0e49E6548', 18, 'ARB', 'Arbitrum')
export const OP = new Token(
SupportedChainId.OPTIMISM,
'0x4200000000000000000000000000000000000042',
18,
'OP',
'Optimism'
)
export const OP = new Token(ChainId.OPTIMISM, '0x4200000000000000000000000000000000000042', 18, 'OP', 'Optimism')
export const WRAPPED_NATIVE_CURRENCY: { [chainId: number]: Token | undefined } = {
...(WETH9 as Record<SupportedChainId, Token>),
[SupportedChainId.OPTIMISM]: new Token(
SupportedChainId.OPTIMISM,
...(WETH9 as Record<ChainId, Token>),
[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_GOERLI]: new Token(
SupportedChainId.ARBITRUM_GOERLI,
[ChainId.ARBITRUM_GOERLI]: new Token(
ChainId.ARBITRUM_GOERLI,
'0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3',
18,
'WETH',
'Wrapped Ether'
),
[SupportedChainId.SEPOLIA]: new Token(
SupportedChainId.SEPOLIA,
[ChainId.SEPOLIA]: new Token(
ChainId.SEPOLIA,
'0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14',
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.CELO]: new Token(
SupportedChainId.CELO,
[ChainId.CELO]: new Token(
ChainId.CELO,
'0x471ece3750da237f93b8e339c536989b8978a438',
18,
'CELO',
'Celo native asset'
),
[SupportedChainId.CELO_ALFAJORES]: new Token(
SupportedChainId.CELO_ALFAJORES,
[ChainId.CELO_ALFAJORES]: new Token(
ChainId.CELO_ALFAJORES,
'0xf194afdf50b03e69bd7d057c1aa9e10c9954e4c9',
18,
'CELO',
'Celo native asset'
),
[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'
),
}
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')
}
}
export function isMatic(chainId: number): chainId is SupportedChainId.POLYGON | SupportedChainId.POLYGON_MUMBAI {
return chainId === SupportedChainId.POLYGON_MUMBAI || chainId === SupportedChainId.POLYGON
export function isMatic(chainId: number): chainId is ChainId.POLYGON | ChainId.POLYGON_MUMBAI {
return chainId === ChainId.POLYGON_MUMBAI || chainId === ChainId.POLYGON
}
class MaticNativeCurrency extends NativeCurrency {
@ -519,8 +394,8 @@ class MaticNativeCurrency extends NativeCurrency {
}
}
export function isBsc(chainId: number): chainId is SupportedChainId.BNB {
return chainId === SupportedChainId.BNB
export function isBsc(chainId: number): chainId is ChainId.BNB {
return chainId === ChainId.BNB
}
class BscNativeCurrency extends NativeCurrency {
@ -541,6 +416,28 @@ class BscNativeCurrency extends NativeCurrency {
}
}
export function isAvalanche(chainId: number): chainId is ChainId.AVALANCHE {
return chainId === ChainId.AVALANCHE
}
class AvaxNativeCurrency extends NativeCurrency {
equals(other: Currency): boolean {
return other.isNative && other.chainId === this.chainId
}
get wrapped(): Token {
if (!isAvalanche(this.chainId)) throw new Error('Not avalanche')
const wrapped = WRAPPED_NATIVE_CURRENCY[this.chainId]
invariant(wrapped instanceof Token)
return wrapped
}
public constructor(chainId: number) {
if (!isAvalanche(chainId)) throw new Error('Not avalanche')
super(chainId, 18, 'AVAX', 'AVAX')
}
}
class ExtendedEther extends Ether {
public get wrapped(): Token {
const wrapped = WRAPPED_NATIVE_CURRENCY[this.chainId]
@ -565,6 +462,8 @@ export function nativeOnChain(chainId: number): NativeCurrency | Token {
nativeCurrency = getCeloNativeCurrency(chainId)
} else if (isBsc(chainId)) {
nativeCurrency = new BscNativeCurrency(chainId)
} else if (isAvalanche(chainId)) {
nativeCurrency = new AvaxNativeCurrency(chainId)
} else {
nativeCurrency = ExtendedEther.onChain(chainId)
}
@ -578,19 +477,20 @@ export function getSwapCurrencyId(currency: Currency): string {
return NATIVE_CHAIN_ID
}
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]: BRIDGED_USDC_ARBITRUM.address,
[SupportedChainId.ARBITRUM_GOERLI]: USDC_ARBITRUM_GOERLI.address,
[SupportedChainId.OPTIMISM]: USDC_OPTIMISM.address,
[SupportedChainId.OPTIMISM_GOERLI]: USDC_OPTIMISM_GOERLI.address,
[SupportedChainId.POLYGON]: USDC_POLYGON.address,
[SupportedChainId.POLYGON_MUMBAI]: USDC_POLYGON_MUMBAI.address,
[SupportedChainId.BNB]: USDC_BSC.address,
[SupportedChainId.CELO]: PORTAL_USDC_CELO.address,
[SupportedChainId.CELO_ALFAJORES]: PORTAL_USDC_CELO.address,
[SupportedChainId.GOERLI]: USDC_GOERLI.address,
[SupportedChainId.SEPOLIA]: USDC_SEPOLIA.address,
[ChainId.MAINNET]: USDC_MAINNET.address,
[ChainId.ARBITRUM_ONE]: BRIDGED_USDC_ARBITRUM.address,
[ChainId.ARBITRUM_GOERLI]: USDC_ARBITRUM_GOERLI.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.BNB]: USDC_BSC.address,
[ChainId.CELO]: PORTAL_USDC_CELO.address,
[ChainId.CELO_ALFAJORES]: PORTAL_USDC_CELO.address,
[ChainId.GOERLI]: USDC_GOERLI.address,
[ChainId.SEPOLIA]: USDC_SEPOLIA.address,
[ChainId.AVALANCHE]: USDC_AVALANCHE.address,
},
}

@ -1,11 +1,11 @@
import { SupportedChainId } from 'constants/chains'
import { ChainId } from '@uniswap/sdk-core'
import { Chain } from './__generated__/types-and-hooks'
import { isSupportedGQLChain, supportedChainIdFromGQLChain } from './util'
describe('fromGraphQLChain', () => {
it('should return the corresponding chain ID for supported chains', () => {
expect(supportedChainIdFromGQLChain(Chain.Ethereum)).toBe(SupportedChainId.MAINNET)
expect(supportedChainIdFromGQLChain(Chain.Ethereum)).toBe(ChainId.MAINNET)
for (const chain of Object.values(Chain)) {
if (!isSupportedGQLChain(chain)) continue

@ -1,7 +1,6 @@
import { QueryResult } from '@apollo/client'
import * as Sentry from '@sentry/react'
import { Currency, Token } from '@uniswap/sdk-core'
import { SupportedChainId } from 'constants/chains'
import { ChainId, Currency, Token } from '@uniswap/sdk-core'
import { NATIVE_CHAIN_ID, nativeOnChain, WRAPPED_NATIVE_CURRENCY } from 'constants/tokens'
import ms from 'ms.macro'
import { useEffect } from 'react'
@ -64,6 +63,7 @@ export const GQL_MAINNET_CHAINS = [
Chain.Optimism,
Chain.Arbitrum,
Chain.Bnb,
Chain.Avalanche,
] as const
const GQL_TESTNET_CHAINS = [Chain.EthereumGoerli, Chain.EthereumSepolia] as const
@ -72,35 +72,31 @@ const UX_SUPPORTED_GQL_CHAINS = [...GQL_MAINNET_CHAINS, ...GQL_TESTNET_CHAINS] a
export type InterfaceGqlChain = (typeof UX_SUPPORTED_GQL_CHAINS)[number]
export const CHAIN_ID_TO_BACKEND_NAME: { [key: number]: InterfaceGqlChain } = {
[SupportedChainId.MAINNET]: Chain.Ethereum,
[SupportedChainId.GOERLI]: Chain.EthereumGoerli,
[SupportedChainId.SEPOLIA]: Chain.EthereumSepolia,
[SupportedChainId.POLYGON]: Chain.Polygon,
[SupportedChainId.POLYGON_MUMBAI]: Chain.Polygon,
[SupportedChainId.CELO]: Chain.Celo,
[SupportedChainId.CELO_ALFAJORES]: Chain.Celo,
[SupportedChainId.ARBITRUM_ONE]: Chain.Arbitrum,
[SupportedChainId.ARBITRUM_GOERLI]: Chain.Arbitrum,
[SupportedChainId.OPTIMISM]: Chain.Optimism,
[SupportedChainId.OPTIMISM_GOERLI]: Chain.Optimism,
[SupportedChainId.BNB]: Chain.Bnb,
[ChainId.MAINNET]: Chain.Ethereum,
[ChainId.GOERLI]: Chain.EthereumGoerli,
[ChainId.SEPOLIA]: Chain.EthereumSepolia,
[ChainId.POLYGON]: Chain.Polygon,
[ChainId.POLYGON_MUMBAI]: Chain.Polygon,
[ChainId.CELO]: Chain.Celo,
[ChainId.CELO_ALFAJORES]: Chain.Celo,
[ChainId.ARBITRUM_ONE]: Chain.Arbitrum,
[ChainId.ARBITRUM_GOERLI]: Chain.Arbitrum,
[ChainId.OPTIMISM]: Chain.Optimism,
[ChainId.OPTIMISM_GOERLI]: Chain.Optimism,
[ChainId.BNB]: Chain.Bnb,
[ChainId.AVALANCHE]: Chain.Avalanche,
}
export function chainIdToBackendName(chainId: number | undefined) {
return chainId && CHAIN_ID_TO_BACKEND_NAME[chainId]
? CHAIN_ID_TO_BACKEND_NAME[chainId]
: CHAIN_ID_TO_BACKEND_NAME[SupportedChainId.MAINNET]
: CHAIN_ID_TO_BACKEND_NAME[ChainId.MAINNET]
}
const GQL_CHAINS: number[] = [
SupportedChainId.MAINNET,
SupportedChainId.OPTIMISM,
SupportedChainId.POLYGON,
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.CELO,
]
const GQL_CHAINS = [ChainId.MAINNET, ChainId.OPTIMISM, ChainId.POLYGON, ChainId.ARBITRUM_ONE, ChainId.CELO] as const
type GqlChainsType = (typeof GQL_CHAINS)[number]
export function isGqlSupportedChain(chainId: number | undefined): chainId is SupportedChainId {
export function isGqlSupportedChain(chainId: number | undefined): chainId is GqlChainsType {
return !!chainId && GQL_CHAINS.includes(chainId)
}
export function toContractInput(currency: Currency): ContractInput {
@ -129,30 +125,39 @@ const URL_CHAIN_PARAM_TO_BACKEND: { [key: string]: InterfaceGqlChain } = {
arbitrum: Chain.Arbitrum,
optimism: Chain.Optimism,
bnb: Chain.Bnb,
avalanche: Chain.Avalanche,
}
/**
* @param chainName parsed in chain name from url query parameter
* @returns if chainName is a valid chain name supported by the backend, returns the backend chain name, otherwise returns Chain.Ethereum
*/
export function validateUrlChainParam(chainName: string | undefined) {
return chainName && URL_CHAIN_PARAM_TO_BACKEND[chainName] ? URL_CHAIN_PARAM_TO_BACKEND[chainName] : Chain.Ethereum
const isValidChainName = chainName && URL_CHAIN_PARAM_TO_BACKEND[chainName]
const isValidBackEndChain =
isValidChainName && (BACKEND_SUPPORTED_CHAINS as ReadonlyArray<Chain>).includes(isValidChainName)
return isValidBackEndChain ? URL_CHAIN_PARAM_TO_BACKEND[chainName] : Chain.Ethereum
}
const CHAIN_NAME_TO_CHAIN_ID: { [key in InterfaceGqlChain]: SupportedChainId } = {
[Chain.Ethereum]: SupportedChainId.MAINNET,
[Chain.EthereumGoerli]: SupportedChainId.GOERLI,
[Chain.EthereumSepolia]: SupportedChainId.SEPOLIA,
[Chain.Polygon]: SupportedChainId.POLYGON,
[Chain.Celo]: SupportedChainId.CELO,
[Chain.Optimism]: SupportedChainId.OPTIMISM,
[Chain.Arbitrum]: SupportedChainId.ARBITRUM_ONE,
[Chain.Bnb]: SupportedChainId.BNB,
const CHAIN_NAME_TO_CHAIN_ID: { [key in InterfaceGqlChain]: ChainId } = {
[Chain.Ethereum]: ChainId.MAINNET,
[Chain.EthereumGoerli]: ChainId.GOERLI,
[Chain.EthereumSepolia]: ChainId.SEPOLIA,
[Chain.Polygon]: ChainId.POLYGON,
[Chain.Celo]: ChainId.CELO,
[Chain.Optimism]: ChainId.OPTIMISM,
[Chain.Arbitrum]: ChainId.ARBITRUM_ONE,
[Chain.Bnb]: ChainId.BNB,
[Chain.Avalanche]: ChainId.AVALANCHE,
}
export function isSupportedGQLChain(chain: Chain): chain is InterfaceGqlChain {
return (UX_SUPPORTED_GQL_CHAINS as ReadonlyArray<Chain>).includes(chain)
}
export function supportedChainIdFromGQLChain(chain: InterfaceGqlChain): SupportedChainId
export function supportedChainIdFromGQLChain(chain: Chain): SupportedChainId | undefined
export function supportedChainIdFromGQLChain(chain: Chain): SupportedChainId | undefined {
export function supportedChainIdFromGQLChain(chain: InterfaceGqlChain): ChainId
export function supportedChainIdFromGQLChain(chain: Chain): ChainId | undefined
export function supportedChainIdFromGQLChain(chain: Chain): ChainId | undefined {
return isSupportedGQLChain(chain) ? CHAIN_NAME_TO_CHAIN_ID[chain] : undefined
}
@ -172,13 +177,14 @@ export function logSentryErrorForUnsupportedChain({
})
}
export const BACKEND_CHAIN_NAMES: InterfaceGqlChain[] = [
export const BACKEND_SUPPORTED_CHAINS = [
Chain.Ethereum,
Chain.Polygon,
Chain.Optimism,
Chain.Arbitrum,
Chain.Celo,
]
] as const
export const BACKEND_NOT_YET_SUPPORTED_CHAIN_IDS = [ChainId.BNB, ChainId.AVALANCHE] as const
export function getTokenDetailsURL({
address,

@ -1,18 +1,19 @@
import { ApolloClient, ApolloLink, concat, HttpLink, InMemoryCache } from '@apollo/client'
import { SupportedChainId } from 'constants/chains'
import { ChainId } from '@uniswap/sdk-core'
import store from '../../state/index'
const CHAIN_SUBGRAPH_URL: Record<number, string> = {
[SupportedChainId.MAINNET]: 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3',
[SupportedChainId.ARBITRUM_ONE]: 'https://thegraph.com/hosted-service/subgraph/ianlapham/uniswap-arbitrum-one',
[SupportedChainId.OPTIMISM]: 'https://api.thegraph.com/subgraphs/name/ianlapham/optimism-post-regenesis',
[SupportedChainId.POLYGON]: 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-polygon',
[SupportedChainId.CELO]: 'https://api.thegraph.com/subgraphs/name/jesse-sawa/uniswap-celo',
[SupportedChainId.BNB]: 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-bsc',
[ChainId.MAINNET]: 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3',
[ChainId.ARBITRUM_ONE]: 'https://thegraph.com/hosted-service/subgraph/ianlapham/uniswap-arbitrum-one',
[ChainId.OPTIMISM]: 'https://api.thegraph.com/subgraphs/name/ianlapham/optimism-post-regenesis',
[ChainId.POLYGON]: 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-polygon',
[ChainId.CELO]: 'https://api.thegraph.com/subgraphs/name/jesse-sawa/uniswap-celo',
[ChainId.BNB]: 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-bsc',
[ChainId.AVALANCHE]: 'https://api.thegraph.com/subgraphs/name/lynnshaoyu/uniswap-v3-avax',
}
const httpLink = new HttpLink({ uri: CHAIN_SUBGRAPH_URL[SupportedChainId.MAINNET] })
const httpLink = new HttpLink({ uri: CHAIN_SUBGRAPH_URL[ChainId.MAINNET] })
// This middleware will allow us to dynamically update the uri for the requests based off chainId
// For more information: https://www.apollographql.com/docs/react/networking/advanced-http-networking/
@ -21,10 +22,7 @@ const authMiddleware = new ApolloLink((operation, forward) => {
const chainId = store.getState().application.chainId
operation.setContext(() => ({
uri:
chainId && CHAIN_SUBGRAPH_URL[chainId]
? CHAIN_SUBGRAPH_URL[chainId]
: CHAIN_SUBGRAPH_URL[SupportedChainId.MAINNET],
uri: chainId && CHAIN_SUBGRAPH_URL[chainId] ? CHAIN_SUBGRAPH_URL[chainId] : CHAIN_SUBGRAPH_URL[ChainId.MAINNET],
}))
return forward(operation)

@ -1,4 +1,4 @@
import { SupportedChainId as MockSupportedChainId } from 'constants/chains'
import { ChainId as MockChainId } from '@uniswap/sdk-core'
import {
DAI as MockDAI,
USDC_MAINNET as MockUSDC_MAINNET,
@ -13,11 +13,11 @@ import { useAllTokensMultichain } from './Tokens'
jest.mock('../state/lists/hooks.ts', () => {
return {
useCombinedTokenMapFromUrls: () => ({
[MockSupportedChainId.MAINNET]: {
[MockChainId.MAINNET]: {
[MockDAI.address]: { token: MockDAI },
[MockUSDC_MAINNET.address]: { token: MockUSDC_MAINNET },
},
[MockSupportedChainId.POLYGON]: {
[MockChainId.POLYGON]: {
[MockWETH_POLYGON.address]: { token: MockWETH_POLYGON },
},
}),
@ -27,11 +27,11 @@ jest.mock('../state/lists/hooks.ts', () => {
jest.mock('../state/hooks.ts', () => {
return {
useAppSelector: () => ({
[MockSupportedChainId.MAINNET]: {
[MockChainId.MAINNET]: {
[MockDAI.address]: MockDAI,
[MockUSDT.address]: MockUSDT,
},
[MockSupportedChainId.OPTIMISM]: {
[MockChainId.OPTIMISM]: {
[MockUSDC_OPTIMISM.address]: MockUSDC_OPTIMISM,
},
}),
@ -43,15 +43,15 @@ describe('useAllTokensMultichain', () => {
const { result } = renderHook(() => useAllTokensMultichain())
expect(result.current).toStrictEqual({
[MockSupportedChainId.MAINNET]: {
[MockChainId.MAINNET]: {
[MockDAI.address]: MockDAI,
[MockUSDC_MAINNET.address]: MockUSDC_MAINNET,
[MockUSDT.address]: MockUSDT,
},
[MockSupportedChainId.POLYGON]: {
[MockChainId.POLYGON]: {
[MockWETH_POLYGON.address]: MockWETH_POLYGON,
},
[MockSupportedChainId.OPTIMISM]: {
[MockChainId.OPTIMISM]: {
[MockUSDC_OPTIMISM.address]: MockUSDC_OPTIMISM,
},
})

@ -1,7 +1,6 @@
import { Currency, Token } from '@uniswap/sdk-core'
import { ChainId, Currency, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { getChainInfo } from 'constants/chainInfo'
import { SupportedChainId } from 'constants/chains'
import { DEFAULT_INACTIVE_LIST_URLS, DEFAULT_LIST_OF_LISTS } from 'constants/lists'
import { useCurrencyFromMap, useTokenFromMapOrNetwork } from 'lib/hooks/useCurrency'
import { getTokenFilter } from 'lib/hooks/useTokenList/filtering'
@ -18,7 +17,7 @@ import { useUnsupportedTokenList } from './../state/lists/hooks'
type Maybe<T> = T | null | undefined
// reduce token map into standard address <-> Token mapping, optionally include user added tokens
function useTokensFromMap(tokenMap: TokenAddressMap, chainId: Maybe<SupportedChainId>): { [address: string]: Token } {
function useTokensFromMap(tokenMap: TokenAddressMap, chainId: Maybe<ChainId>): { [address: string]: Token } {
return useMemo(() => {
if (!chainId) return {}
@ -65,7 +64,7 @@ export function useAllTokensMultichain(): ChainTokenMap {
}
/** Returns all tokens from the default list + user added tokens */
export function useDefaultActiveTokens(chainId: Maybe<SupportedChainId>): { [address: string]: Token } {
export function useDefaultActiveTokens(chainId: Maybe<ChainId>): { [address: string]: Token } {
const defaultListTokens = useCombinedActiveList()
const tokensFromMap = useTokensFromMap(defaultListTokens, chainId)
const userAddedTokens = useUserAddedTokens()
@ -87,7 +86,7 @@ export function useDefaultActiveTokens(chainId: Maybe<SupportedChainId>): { [add
}
type BridgeInfo = Record<
SupportedChainId,
ChainId,
{
tokenAddress: string
originBridgeAddress: string
@ -124,13 +123,13 @@ export function useUnsupportedTokens(): { [address: string]: Token } {
const bridgeInfo = tokenInfo.extensions?.bridgeInfo as unknown as BridgeInfo
if (
bridgeInfo &&
bridgeInfo[SupportedChainId.MAINNET] &&
bridgeInfo[SupportedChainId.MAINNET].tokenAddress &&
unsupportedSet.has(bridgeInfo[SupportedChainId.MAINNET].tokenAddress)
bridgeInfo[ChainId.MAINNET] &&
bridgeInfo[ChainId.MAINNET].tokenAddress &&
unsupportedSet.has(bridgeInfo[ChainId.MAINNET].tokenAddress)
) {
const address = bridgeInfo[SupportedChainId.MAINNET].tokenAddress
const address = bridgeInfo[ChainId.MAINNET].tokenAddress
// don't rely on decimals--it's possible that a token could be bridged w/ different decimals on the L2
return { ...acc, [address]: new Token(SupportedChainId.MAINNET, address, tokenInfo.decimals) }
return { ...acc, [address]: new Token(ChainId.MAINNET, address, tokenInfo.decimals) }
}
return acc
}, {})
@ -191,7 +190,7 @@ export function useToken(tokenAddress?: string | null): Token | null | undefined
return useTokenFromMapOrNetwork(tokens, tokenAddress)
}
export function useCurrency(currencyId: Maybe<string>, chainId?: SupportedChainId): Currency | null | undefined {
export function useCurrency(currencyId: Maybe<string>, chainId?: ChainId): Currency | null | undefined {
const { chainId: connectedChainId } = useWeb3React()
const tokens = useDefaultActiveTokens(chainId ?? connectedChainId)
return useCurrencyFromMap(tokens, chainId ?? connectedChainId, currencyId)

@ -1,7 +1,7 @@
import { useWeb3React } from '@web3-react/core'
import { isSupportedChainId } from 'lib/hooks/routing/clientSideSmartOrderRouter'
import { isSupportedChain } from 'constants/chains'
export default function useAutoRouterSupported(): boolean {
const { chainId } = useWeb3React()
return isSupportedChainId(chainId)
return isSupportedChain(chainId)
}

@ -1,7 +1,6 @@
import { Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import { ChainId, Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import { Route, SwapQuoter } from '@uniswap/v3-sdk'
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from 'constants/chains'
import JSBI from 'jsbi'
import { useSingleContractWithCallData } from 'lib/hooks/multicall'
import { useMemo } from 'react'
@ -12,13 +11,14 @@ import { useAllV3Routes } from './useAllV3Routes'
import { useQuoter } from './useContract'
const QUOTE_GAS_OVERRIDES: { [chainId: number]: number } = {
[SupportedChainId.ARBITRUM_ONE]: 25_000_000,
[SupportedChainId.ARBITRUM_GOERLI]: 25_000_000,
[SupportedChainId.CELO]: 50_000_000,
[SupportedChainId.CELO_ALFAJORES]: 50_000_000,
[SupportedChainId.POLYGON]: 40_000_000,
[SupportedChainId.POLYGON_MUMBAI]: 40_000_000,
[SupportedChainId.BNB]: 50_000_000,
[ChainId.ARBITRUM_ONE]: 25_000_000,
[ChainId.ARBITRUM_GOERLI]: 25_000_000,
[ChainId.CELO]: 50_000_000,
[ChainId.CELO_ALFAJORES]: 50_000_000,
[ChainId.POLYGON]: 40_000_000,
[ChainId.POLYGON_MUMBAI]: 40_000_000,
[ChainId.BNB]: 50_000_000,
[ChainId.AVALANCHE]: 50_000_000,
}
const DEFAULT_GAS_QUOTE = 2_000_000

@ -1,5 +1,4 @@
import { Token } from '@uniswap/sdk-core'
import { SupportedChainId } from 'constants/chains'
import { ChainId, Token } from '@uniswap/sdk-core'
import uriToHttp from 'lib/utils/uriToHttp'
import Vibrant from 'node-vibrant/lib/bundle.js'
import { shade } from 'polished'
@ -20,7 +19,7 @@ async function getColorFromToken(token: Token): Promise<string | null> {
const { address } = wrappedToken
let { logoURI } = wrappedToken
if (!logoURI) {
if (token.chainId !== SupportedChainId.MAINNET) {
if (token.chainId !== ChainId.MAINNET) {
return null
} else {
logoURI = URIForEthToken(address)

@ -1,4 +1,14 @@
import { Contract } from '@ethersproject/contracts'
import {
ARGENT_WALLET_DETECTOR_ADDRESS,
ENS_REGISTRAR_ADDRESSES,
MULTICALL_ADDRESSES,
NONFUNGIBLE_POSITION_MANAGER_ADDRESSES,
QUOTER_ADDRESSES,
TICK_LENS_ADDRESSES,
V2_ROUTER_ADDRESS,
V3_MIGRATOR_ADDRESSES,
} from '@uniswap/sdk-core'
import QuoterV2Json from '@uniswap/swap-router-contracts/artifacts/contracts/lens/QuoterV2.sol/QuoterV2.json'
import IUniswapV2PairJson from '@uniswap/v2-core/build/IUniswapV2Pair.json'
import IUniswapV2Router02Json from '@uniswap/v2-periphery/build/IUniswapV2Router02.json'
@ -18,16 +28,6 @@ import ERC721_ABI from 'abis/erc721.json'
import ERC1155_ABI from 'abis/erc1155.json'
import { ArgentWalletDetector, EnsPublicResolver, EnsRegistrar, Erc20, Erc721, Erc1155, Weth } from 'abis/types'
import WETH_ABI from 'abis/weth.json'
import {
ARGENT_WALLET_DETECTOR_ADDRESS,
ENS_REGISTRAR_ADDRESSES,
MULTICALL_ADDRESS,
NONFUNGIBLE_POSITION_MANAGER_ADDRESSES,
QUOTER_ADDRESSES,
TICK_LENS_ADDRESSES,
V2_ROUTER_ADDRESS,
V3_MIGRATOR_ADDRESSES,
} from 'constants/addresses'
import { WRAPPED_NATIVE_CURRENCY } from 'constants/tokens'
import { useMemo } from 'react'
import { NonfungiblePositionManager, Quoter, QuoterV2, TickLens, UniswapInterfaceMulticall } from 'types/v3'
@ -120,7 +120,7 @@ export function useV2RouterContract(): Contract | null {
}
export function useInterfaceMulticall() {
return useContract<UniswapInterfaceMulticall>(MULTICALL_ADDRESS, MulticallABI, false) as UniswapInterfaceMulticall
return useContract<UniswapInterfaceMulticall>(MULTICALL_ADDRESSES, MulticallABI, false) as UniswapInterfaceMulticall
}
export function useV3NFTPositionManagerContract(withSignerIfPossible?: boolean): NonfungiblePositionManager | null {

@ -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 JSBI from 'jsbi'
import { useSingleCallResult } from 'lib/hooks/multicall'
import { useMemo, useState } from 'react'
@ -32,16 +31,16 @@ 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.GOERLI]: {
[UNI[SupportedChainId.GOERLI].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
[ChainId.GOERLI]: {
[UNI[ChainId.GOERLI].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
},
[SupportedChainId.SEPOLIA]: {
[UNI[SupportedChainId.SEPOLIA].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
[ChainId.SEPOLIA]: {
[UNI[ChainId.SEPOLIA].address]: { type: PermitType.AMOUNT, name: 'Uniswap' },
},
}

@ -1,6 +1,6 @@
import { nanoid } from '@reduxjs/toolkit'
import { ChainId } from '@uniswap/sdk-core'
import { TokenList } from '@uniswap/token-lists'
import { SupportedChainId } from 'constants/chains'
import { RPC_PROVIDERS } from 'constants/providers'
import getTokenList from 'lib/hooks/useTokenList/fetchTokenList'
import resolveENSContentHash from 'lib/utils/resolveENSContentHash'
@ -18,7 +18,7 @@ export function useFetchListCallback(): (listUrl: string, skipValidation?: boole
dispatch(fetchTokenList.pending({ requestId, url: listUrl }))
return getTokenList(
listUrl,
(ensName: string) => resolveENSContentHash(ensName, RPC_PROVIDERS[SupportedChainId.MAINNET]),
(ensName: string) => resolveENSContentHash(ensName, RPC_PROVIDERS[ChainId.MAINNET]),
skipValidation
)
.then((tokenList) => {

@ -1,7 +1,6 @@
import { Currency } from '@uniswap/sdk-core'
import { ChainId, Currency, V3_CORE_FACTORY_ADDRESSES } from '@uniswap/sdk-core'
import { FeeAmount, nearestUsableTick, Pool, TICK_SPACINGS, tickToPrice } from '@uniswap/v3-sdk'
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from 'constants/chains'
import { ZERO_ADDRESS } from 'constants/misc'
import { useAllV3TicksQuery } from 'graphql/thegraph/__generated__/types-and-hooks'
import { TickData, Ticks } from 'graphql/thegraph/AllV3TicksQuery'
@ -12,12 +11,11 @@ import ms from 'ms.macro'
import { useEffect, useMemo, useState } from 'react'
import computeSurroundingTicks from 'utils/computeSurroundingTicks'
import { V3_CORE_FACTORY_ADDRESSES } from '../constants/addresses'
import { useTickLens } from './useContract'
import { PoolState, usePool } from './usePools'
const PRICE_FIXED_DIGITS = 8
const CHAIN_IDS_MISSING_SUBGRAPH_DATA = [SupportedChainId.ARBITRUM_ONE, SupportedChainId.ARBITRUM_GOERLI]
const CHAIN_IDS_MISSING_SUBGRAPH_DATA = [ChainId.ARBITRUM_ONE, ChainId.ARBITRUM_GOERLI]
// Tick with fields parsed to JSBIs, and active liquidity computed.
export interface TickProcessed {

@ -1,5 +1,5 @@
import { Interface } from '@ethersproject/abi'
import { BigintIsh, Currency, Token } from '@uniswap/sdk-core'
import { BigintIsh, Currency, Token, V3_CORE_FACTORY_ADDRESSES } from '@uniswap/sdk-core'
import IUniswapV3PoolStateJSON from '@uniswap/v3-core/artifacts/contracts/interfaces/pool/IUniswapV3PoolState.sol/IUniswapV3PoolState.json'
import { computePoolAddress } from '@uniswap/v3-sdk'
import { FeeAmount, Pool } from '@uniswap/v3-sdk'
@ -8,7 +8,6 @@ import JSBI from 'jsbi'
import { useMultipleContractSingleData } from 'lib/hooks/multicall'
import { useMemo } from 'react'
import { V3_CORE_FACTORY_ADDRESSES } from '../constants/addresses'
import { IUniswapV3PoolStateInterface } from '../types/v3/IUniswapV3PoolState'
const POOL_STATE_INTERFACE = new Interface(IUniswapV3PoolStateJSON.abi) as IUniswapV3PoolStateInterface

@ -1,7 +1,7 @@
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { getConnection } from 'connection'
import { didUserReject } from 'connection/utils'
import { SupportedChainId } from 'constants/chains'
import { useCallback } from 'react'
import { addPopup } from 'state/application/reducer'
import { useAppDispatch } from 'state/hooks'
@ -14,7 +14,7 @@ export default function useSelectChain() {
const switchChain = useSwitchChain()
return useCallback(
async (targetChain: SupportedChainId) => {
async (targetChain: ChainId) => {
if (!connector) return
const connection = getConnection(connector)

@ -1,17 +1,15 @@
import { Token } from '@uniswap/sdk-core'
import { ChainId, SOCKS_CONTROLLER_ADDRESSES, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { SOCKS_CONTROLLER_ADDRESSES } from 'constants/addresses'
import { SupportedChainId } from 'constants/chains'
import { useMemo } from 'react'
import { useTokenBalance } from 'state/connection/hooks'
// technically a 721, not an ERC20, but suffices for our purposes
const SOCKS = new Token(SupportedChainId.MAINNET, SOCKS_CONTROLLER_ADDRESSES[SupportedChainId.MAINNET], 0)
const SOCKS = new Token(ChainId.MAINNET, SOCKS_CONTROLLER_ADDRESSES[ChainId.MAINNET], 0)
export function useHasSocks(): boolean | undefined {
const { account, chainId } = useWeb3React()
const balance = useTokenBalance(account ?? undefined, chainId === SupportedChainId.MAINNET ? SOCKS : undefined)
const balance = useTokenBalance(account ?? undefined, chainId === ChainId.MAINNET ? SOCKS : undefined)
return useMemo(() => Boolean(balance?.greaterThan(0)), [balance])
}

@ -1,6 +1,5 @@
import { Currency, CurrencyAmount, Price, Token, TradeType } from '@uniswap/sdk-core'
import { ChainId, Currency, CurrencyAmount, Price, Token, TradeType } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from 'constants/chains'
import tryParseCurrencyAmount from 'lib/utils/tryParseCurrencyAmount'
import { useMemo, useRef } from 'react'
import { INTERNAL_ROUTER_PREFERENCE_PRICE } from 'state/routing/slice'
@ -10,6 +9,7 @@ import {
BRIDGED_USDC_ARBITRUM,
CUSD_CELO,
DAI_OPTIMISM,
USDC_AVALANCHE,
USDC_MAINNET,
USDC_POLYGON,
USDT_BSC,
@ -18,12 +18,13 @@ import {
// Stablecoin amounts used when calculating spot price for a given currency.
// The amount is large enough to filter low liquidity pairs.
const STABLECOIN_AMOUNT_OUT: { [chainId: number]: CurrencyAmount<Token> } = {
[SupportedChainId.MAINNET]: CurrencyAmount.fromRawAmount(USDC_MAINNET, 100_000e6),
[SupportedChainId.ARBITRUM_ONE]: CurrencyAmount.fromRawAmount(BRIDGED_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),
[SupportedChainId.BNB]: CurrencyAmount.fromRawAmount(USDT_BSC, 100e18),
[ChainId.MAINNET]: CurrencyAmount.fromRawAmount(USDC_MAINNET, 100_000e6),
[ChainId.ARBITRUM_ONE]: CurrencyAmount.fromRawAmount(BRIDGED_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),
[ChainId.BNB]: CurrencyAmount.fromRawAmount(USDT_BSC, 100e18),
[ChainId.AVALANCHE]: CurrencyAmount.fromRawAmount(USDC_AVALANCHE, 10_000e6),
}
/**

@ -1,3 +1,4 @@
import { ChainId, SupportedChainsType } from '@uniswap/sdk-core'
import { Connector } from '@web3-react/types'
import {
networkConnection,
@ -7,17 +8,17 @@ import {
walletConnectV2Connection,
} from 'connection'
import { getChainInfo } from 'constants/chainInfo'
import { isSupportedChain, SupportedChainId } from 'constants/chains'
import { isSupportedChain } from 'constants/chains'
import { FALLBACK_URLS, RPC_URLS } from 'constants/networks'
import { useCallback } from 'react'
import { useAppDispatch } from 'state/hooks'
import { endSwitchingChain, startSwitchingChain } from 'state/wallets/reducer'
function getRpcUrl(chainId: SupportedChainId): string {
function getRpcUrl(chainId: SupportedChainsType): string {
switch (chainId) {
case SupportedChainId.MAINNET:
case SupportedChainId.GOERLI:
case SupportedChainId.SEPOLIA:
case ChainId.MAINNET:
case ChainId.GOERLI:
case ChainId.SEPOLIA:
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.
@ -31,7 +32,7 @@ export function useSwitchChain() {
const dispatch = useAppDispatch()
return useCallback(
async (connector: Connector, chainId: SupportedChainId) => {
async (connector: Connector, chainId: ChainId) => {
if (!isSupportedChain(chainId)) {
throw new Error(`Chain ${chainId} not supported for connector (${typeof connector})`)
} else {

@ -1,5 +1,5 @@
import { NetworkStatus } from '@apollo/client'
import { Currency, CurrencyAmount, Price, SupportedChainId, TradeType } from '@uniswap/sdk-core'
import { ChainId, Currency, CurrencyAmount, Price, TradeType } from '@uniswap/sdk-core'
import { nativeOnChain } from 'constants/tokens'
import { Chain, useTokenSpotPriceQuery } from 'graphql/data/__generated__/types-and-hooks'
import { chainIdToBackendName, isGqlSupportedChain, PollingInterval } from 'graphql/data/util'
@ -13,11 +13,11 @@ import useStablecoinPrice from './useStablecoinPrice'
// ETH amounts used when calculating spot price for a given currency.
// The amount is large enough to filter low liquidity pairs.
const ETH_AMOUNT_OUT: { [chainId: number]: CurrencyAmount<Currency> } = {
[SupportedChainId.MAINNET]: CurrencyAmount.fromRawAmount(nativeOnChain(SupportedChainId.MAINNET), 50e18),
[SupportedChainId.ARBITRUM_ONE]: CurrencyAmount.fromRawAmount(nativeOnChain(SupportedChainId.ARBITRUM_ONE), 10e18),
[SupportedChainId.OPTIMISM]: CurrencyAmount.fromRawAmount(nativeOnChain(SupportedChainId.OPTIMISM), 10e18),
[SupportedChainId.POLYGON]: CurrencyAmount.fromRawAmount(nativeOnChain(SupportedChainId.POLYGON), 10_000e18),
[SupportedChainId.CELO]: CurrencyAmount.fromRawAmount(nativeOnChain(SupportedChainId.CELO), 10e18),
[ChainId.MAINNET]: CurrencyAmount.fromRawAmount(nativeOnChain(ChainId.MAINNET), 50e18),
[ChainId.ARBITRUM_ONE]: CurrencyAmount.fromRawAmount(nativeOnChain(ChainId.ARBITRUM_ONE), 10e18),
[ChainId.OPTIMISM]: CurrencyAmount.fromRawAmount(nativeOnChain(ChainId.OPTIMISM), 10e18),
[ChainId.POLYGON]: CurrencyAmount.fromRawAmount(nativeOnChain(ChainId.POLYGON), 10_000e18),
[ChainId.CELO]: CurrencyAmount.fromRawAmount(nativeOnChain(ChainId.CELO), 10e18),
}
function useETHValue(currencyAmount?: CurrencyAmount<Currency>): {

@ -1,12 +1,10 @@
import { Interface } from '@ethersproject/abi'
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'
import { Currency, CurrencyAmount, V2_FACTORY_ADDRESSES } from '@uniswap/sdk-core'
import IUniswapV2PairJSON from '@uniswap/v2-core/build/IUniswapV2Pair.json'
import { computePairAddress, Pair } from '@uniswap/v2-sdk'
import { useMultipleContractSingleData } from 'lib/hooks/multicall'
import { useMemo } from 'react'
import { V2_FACTORY_ADDRESSES } from '../constants/addresses'
const PAIR_INTERFACE = new Interface(IUniswapV2PairJSON.abi)
export enum PairState {

@ -1,7 +1,6 @@
import { Currency, Token } from '@uniswap/sdk-core'
import { ChainId, Currency, Token } from '@uniswap/sdk-core'
import { FeeAmount, Pool } from '@uniswap/v3-sdk'
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from 'constants/chains'
import { useMemo } from 'react'
import { useAllCurrencyCombinations } from './useAllCurrencyCombinations'
@ -26,7 +25,7 @@ export function useV3SwapPools(
const allCurrencyCombinationsWithAllFees: [Token, Token, FeeAmount][] = useMemo(
() =>
allCurrencyCombinations.reduce<[Token, Token, FeeAmount][]>((list, [tokenA, tokenB]) => {
return chainId === SupportedChainId.MAINNET
return chainId === ChainId.MAINNET
? list.concat([
[tokenA, tokenB, FeeAmount.LOW],
[tokenA, tokenB, FeeAmount.MEDIUM],

@ -1,24 +1,13 @@
import { BigintIsh, CurrencyAmount, Token, TradeType } from '@uniswap/sdk-core'
// This file is lazy-loaded, so the import of smart-order-router is intentional.
// eslint-disable-next-line no-restricted-imports
import { AlphaRouter, AlphaRouterConfig, ChainId } from '@uniswap/smart-order-router'
import { SupportedChainId } from 'constants/chains'
import { AlphaRouter, AlphaRouterConfig } from '@uniswap/smart-order-router'
import { nativeOnChain } from 'constants/tokens'
import JSBI from 'jsbi'
import { GetQuoteArgs } from 'state/routing/slice'
import { QuoteResult, QuoteState, SwapRouterNativeAssets } from 'state/routing/types'
import { transformSwapRouteToGetQuoteResult } from 'utils/transformSwapRouteToGetQuoteResult'
export function toSupportedChainId(chainId: ChainId): SupportedChainId | undefined {
const numericChainId: number = chainId
if (SupportedChainId[numericChainId]) return numericChainId
return undefined
}
export function isSupportedChainId(chainId: ChainId | undefined): boolean {
if (chainId === undefined) return false
return toSupportedChainId(chainId) !== undefined
}
async function getQuote(
{
tradeType,

@ -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 useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp'
import useBlockNumber, { useFastForwardBlockNumber } from 'lib/hooks/useBlockNumber'
import ms from 'ms.macro'
@ -35,10 +35,10 @@ 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_GOERLI]: { n: 10, minWait: 250, maxWait: 1000 },
[SupportedChainId.OPTIMISM]: { n: 10, minWait: 250, maxWait: 1000 },
[SupportedChainId.OPTIMISM_GOERLI]: { n: 10, minWait: 250, maxWait: 1000 },
[ChainId.ARBITRUM_ONE]: { n: 10, minWait: 250, maxWait: 1000 },
[ChainId.ARBITRUM_GOERLI]: { n: 10, minWait: 250, maxWait: 1000 },
[ChainId.OPTIMISM]: { n: 10, minWait: 250, maxWait: 1000 },
[ChainId.OPTIMISM_GOERLI]: { n: 10, minWait: 250, maxWait: 1000 },
}
const DEFAULT_RETRY_OPTIONS: RetryOptions = { n: 1, minWait: 0, maxWait: 0 }

@ -1,8 +1,8 @@
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 { isSupportedChain, SupportedChainId } from 'constants/chains'
import { asSupportedChain, isSupportedChain } from 'constants/chains'
import { useBytes32TokenContract, useTokenContract } from 'hooks/useContract'
import { NEVER_RELOAD, useSingleCallResult } from 'lib/hooks/multicall'
import useNativeCurrency from 'lib/hooks/useNativeCurrency'
@ -11,7 +11,6 @@ import { useMemo } from 'react'
import { DEFAULT_ERC20_DECIMALS } from '../../constants/tokens'
import { TOKEN_SHORTHANDS } from '../../constants/tokens'
import { isAddress } from '../../utils'
import { supportedChainId } from '../../utils/supportedChainId'
// parse a name or symbol from a token response
const BYTES32_REGEX = /^0x[a-fA-F0-9]{64}$/
@ -94,13 +93,13 @@ export function useTokenFromMapOrNetwork(tokens: TokenMap, tokenAddress?: string
*/
export function useCurrencyFromMap(
tokens: TokenMap,
chainId: SupportedChainId | undefined,
chainId: ChainId | undefined,
currencyId?: string | null
): Currency | null | undefined {
const nativeCurrency = useNativeCurrency(chainId)
const isNative = Boolean(nativeCurrency && currencyId?.toUpperCase() === 'ETH')
const shorthandMatchAddress = useMemo(() => {
const chain = supportedChainId(chainId)
const chain = asSupportedChain(chainId)
return chain && currencyId ? TOKEN_SHORTHANDS[currencyId.toUpperCase()]?.[chain] : undefined
}, [chainId, currencyId])

@ -1,58 +1,58 @@
import { SupportedChainId } from 'constants/chains'
import { ChainId } from '@uniswap/sdk-core'
import useHttpLocations from 'hooks/useHttpLocations'
import { useMemo } from 'react'
import { isAddress } from 'utils'
import EthereumLogo from '../../assets/images/ethereum-logo.png'
import AvaxLogo from '../../assets/svg/avax_logo.svg'
import BnbLogo from '../../assets/svg/bnb-logo.svg'
import CeloLogo from '../../assets/svg/celo_logo.svg'
import MaticLogo from '../../assets/svg/matic-token-icon.svg'
import { isCelo, NATIVE_CHAIN_ID, nativeOnChain } from '../../constants/tokens'
type Network = 'ethereum' | 'arbitrum' | 'optimism' | 'polygon' | 'smartchain' | 'celo'
type Network = 'ethereum' | 'arbitrum' | 'optimism' | 'polygon' | 'smartchain' | 'celo' | 'avalanchec'
export function chainIdToNetworkName(networkId: SupportedChainId): Network {
export function chainIdToNetworkName(networkId: ChainId): Network {
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.BNB:
case ChainId.BNB:
return 'smartchain'
case SupportedChainId.CELO:
case ChainId.CELO:
return 'celo'
case ChainId.AVALANCHE:
return 'avalanchec'
default:
return 'ethereum'
}
}
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.BNB:
case ChainId.BNB:
return BnbLogo
case SupportedChainId.CELO:
case SupportedChainId.CELO_ALFAJORES:
case ChainId.CELO:
case ChainId.CELO_ALFAJORES:
return CeloLogo
case ChainId.AVALANCHE:
return AvaxLogo
default:
return EthereumLogo
}
}
function getTokenLogoURI(address: string, chainId: SupportedChainId = SupportedChainId.MAINNET): string | void {
function getTokenLogoURI(address: string, chainId: ChainId = ChainId.MAINNET): string | void {
const networkName = chainIdToNetworkName(chainId)
const networksWithUrls = [
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.MAINNET,
SupportedChainId.OPTIMISM,
SupportedChainId.BNB,
]
const networksWithUrls = [ChainId.ARBITRUM_ONE, ChainId.MAINNET, ChainId.OPTIMISM, ChainId.BNB, ChainId.AVALANCHE]
if (isCelo(chainId) && address === nativeOnChain(chainId).wrapped.address) {
return CeloLogo
}

@ -1,15 +1,14 @@
import { NativeCurrency, Token } from '@uniswap/sdk-core'
import { SupportedChainId } from 'constants/chains'
import { ChainId, NativeCurrency, Token } from '@uniswap/sdk-core'
import { nativeOnChain } from 'constants/tokens'
import { useMemo } from 'react'
export default function useNativeCurrency(chainId: SupportedChainId | null | undefined): NativeCurrency | Token {
export default function useNativeCurrency(chainId: ChainId | null | undefined): NativeCurrency | Token {
return useMemo(
() =>
chainId
? nativeOnChain(chainId)
: // display mainnet when not connected
nativeOnChain(SupportedChainId.MAINNET),
nativeOnChain(ChainId.MAINNET),
[chainId]
)
}

@ -1,6 +1,6 @@
import { createMulticall, ListenerOptions } from '@uniswap/redux-multicall'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from 'constants/chains'
import { useInterfaceMulticall } from 'hooks/useContract'
import useBlockNumber from 'lib/hooks/useBlockNumber'
import { useMemo } from 'react'
@ -9,14 +9,21 @@ const multicall = createMulticall()
export default multicall
/**
*
* @param chainId
* @returns The approximate whole number of blocks written to the corresponding chainId per Ethereum mainnet epoch.
*/
function getBlocksPerFetchForChainId(chainId: number | undefined): number {
// TODO(WEB-2437): See if these numbers need to be updated
switch (chainId) {
case SupportedChainId.ARBITRUM_ONE:
case SupportedChainId.OPTIMISM:
case ChainId.ARBITRUM_ONE:
case ChainId.OPTIMISM:
return 15
case SupportedChainId.BNB:
case SupportedChainId.CELO:
case SupportedChainId.CELO_ALFAJORES:
case ChainId.AVALANCHE:
case ChainId.BNB:
case ChainId.CELO:
case ChainId.CELO_ALFAJORES:
return 5
default:
return 1

@ -1,6 +1,6 @@
import { BigNumber } from '@ethersproject/bignumber'
import { parseEther } from '@ethersproject/units'
import { CurrencyAmount, Percent, SupportedChainId } from '@uniswap/sdk-core'
import { ChainId, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { nativeOnChain } from 'constants/tokens'
import { useNftUniversalRouterAddress } from 'graphql/data/nft/NftUniversalRouterAddress'
@ -86,7 +86,7 @@ describe('BagFooter.tsx', () => {
allowedSlippage: new Percent(10, 100),
})
mocked(usePayWithAnyTokenSwap).mockReturnValue()
mocked(useCurrency).mockReturnValue(nativeOnChain(SupportedChainId.MAINNET))
mocked(useCurrency).mockReturnValue(nativeOnChain(ChainId.MAINNET))
mocked(useTokenInput).mockReturnValue({
inputCurrency: undefined,
setInputCurrency: () => undefined,

@ -3,7 +3,7 @@ import { formatEther, parseEther } from '@ethersproject/units'
import { t, Trans } from '@lingui/macro'
import { sendAnalyticsEvent, TraceEvent } from '@uniswap/analytics'
import { BrowserEvent, InterfaceElementName, NFTEventName } from '@uniswap/analytics-events'
import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core'
import { ChainId, Currency, CurrencyAmount, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { useToggleAccountDrawer } from 'components/AccountDrawer'
import Column from 'components/Column'
@ -13,7 +13,7 @@ import Row from 'components/Row'
import CurrencySearchModal from 'components/SearchModal/CurrencySearchModal'
import { LoadingBubble } from 'components/Tokens/loading'
import { MouseoverTooltip } from 'components/Tooltip'
import { isSupportedChain, SupportedChainId } from 'constants/chains'
import { isSupportedChain } from 'constants/chains'
import { useNftUniversalRouterAddress } from 'graphql/data/nft/NftUniversalRouterAddress'
import { useCurrency } from 'hooks/Tokens'
import { AllowanceState } from 'hooks/usePermit2Allowance'
@ -297,7 +297,7 @@ export const BagFooter = ({ setModalIsOpen, eventProperties }: BagFooterProps) =
const [tokenSelectorOpen, setTokenSelectorOpen] = useState(false)
const isPending = PENDING_BAG_STATUSES.includes(bagStatus)
const activeCurrency = inputCurrency ?? defaultCurrency
const usingPayWithAnyToken = !!inputCurrency && chainId === SupportedChainId.MAINNET
const usingPayWithAnyToken = !!inputCurrency && chainId === ChainId.MAINNET
const { universalRouterAddress, universalRouterAddressIsLoading } = useNftUniversalRouterAddress()
useSubscribeTransactionState(setModalIsOpen)
@ -327,7 +327,7 @@ export const BagFooter = ({ setModalIsOpen, eventProperties }: BagFooterProps) =
const { balance: balanceInEth } = useWalletBalance()
const sufficientBalance = useMemo(() => {
if (!connected || chainId !== SupportedChainId.MAINNET) {
if (!connected || chainId !== ChainId.MAINNET) {
return undefined
}
@ -360,8 +360,8 @@ export const BagFooter = ({ setModalIsOpen, eventProperties }: BagFooterProps) =
handleClick,
buttonColor,
} = useMemo((): BuyButtonStateData => {
if (connected && chainId !== SupportedChainId.MAINNET) {
const handleClick = () => switchChain(connector, SupportedChainId.MAINNET)
if (connected && chainId !== ChainId.MAINNET) {
const handleClick = () => switchChain(connector, ChainId.MAINNET)
return getBuyButtonStateData(BuyButtonStates.NOT_SUPPORTED_CHAIN, theme, handleClick)
}

@ -1,7 +1,7 @@
import { Trans } from '@lingui/macro'
import { sendAnalyticsEvent, useTrace } from '@uniswap/analytics'
import { InterfacePageName, NFTEventName } from '@uniswap/analytics-events'
import { ChainId } from '@uniswap/smart-order-router'
import { ChainId } from '@uniswap/sdk-core'
import { MouseoverTooltip } from 'components/Tooltip'
import { NftActivityType, NftMarketplace, OrderStatus } from 'graphql/data/__generated__/types-and-hooks'
import { Box } from 'nft/components/Box'

@ -1,6 +1,6 @@
import { sendAnalyticsEvent } from '@uniswap/analytics'
import { InterfaceEventName } from '@uniswap/analytics-events'
import { CurrencyAmount, SupportedChainId, Token } from '@uniswap/sdk-core'
import { ChainId, CurrencyAmount, Token } from '@uniswap/sdk-core'
import { UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk'
import { useWeb3React } from '@web3-react/core'
import { isSupportedChain } from 'constants/chains'
@ -12,7 +12,7 @@ function getURAddress(chainId?: number, nftURAddress?: string) {
if (!chainId) return
// if mainnet and on NFT flow, use the contract address returned by GQL
if (chainId === SupportedChainId.MAINNET) {
if (chainId === ChainId.MAINNET) {
return nftURAddress ?? UNIVERSAL_ROUTER_ADDRESS(chainId)
}

@ -3,7 +3,7 @@ import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import { TraceEvent } from '@uniswap/analytics'
import { BrowserEvent, InterfaceElementName, InterfaceEventName } from '@uniswap/analytics-events'
import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import { Currency, CurrencyAmount, NONFUNGIBLE_POSITION_MANAGER_ADDRESSES, Percent } from '@uniswap/sdk-core'
import { FeeAmount, NonfungiblePositionManager } from '@uniswap/v3-sdk'
import { useWeb3React } from '@web3-react/core'
import { useToggleAccountDrawer } from 'components/AccountDrawer'
@ -42,7 +42,6 @@ import RateToggle from '../../components/RateToggle'
import Row, { AutoRow, RowBetween, RowFixed } from '../../components/Row'
import { SwitchLocaleLink } from '../../components/SwitchLocaleLink'
import TransactionConfirmationModal, { ConfirmationModalContent } from '../../components/TransactionConfirmationModal'
import { NONFUNGIBLE_POSITION_MANAGER_ADDRESSES } from '../../constants/addresses'
import { ZERO_PERCENT } from '../../constants/misc'
import { WRAPPED_NATIVE_CURRENCY } from '../../constants/tokens'
import { useCurrency } from '../../hooks/Tokens'

@ -1,7 +1,7 @@
import { Contract } from '@ethersproject/contracts'
import type { TransactionResponse } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import { CurrencyAmount, Fraction, Percent, Price, Token } from '@uniswap/sdk-core'
import { CurrencyAmount, Fraction, Percent, Price, Token, V2_FACTORY_ADDRESSES } from '@uniswap/sdk-core'
import { FeeAmount, Pool, Position, priceToClosestTick, TickMath } from '@uniswap/v3-sdk'
import { useWeb3React } from '@web3-react/core'
import { sendEvent } from 'components/analytics'
@ -38,7 +38,6 @@ import { AutoColumn } from '../../components/Column'
import FormattedCurrencyAmount from '../../components/FormattedCurrencyAmount'
import CurrencyLogo from '../../components/Logo/CurrencyLogo'
import { AutoRow, RowBetween, RowFixed } from '../../components/Row'
import { V2_FACTORY_ADDRESSES } from '../../constants/addresses'
import { WRAPPED_NATIVE_CURRENCY } from '../../constants/tokens'
import { useToken } from '../../hooks/Tokens'
import { usePairContract, useV2MigratorContract } from '../../hooks/useContract'

@ -1,7 +1,7 @@
import { getCreate2Address } from '@ethersproject/address'
import { keccak256, pack } from '@ethersproject/solidity'
import { Trans } from '@lingui/macro'
import { Token } from '@uniswap/sdk-core'
import { Token, V2_FACTORY_ADDRESSES } from '@uniswap/sdk-core'
import { Pair } from '@uniswap/v2-sdk'
import { useWeb3React } from '@web3-react/core'
import MigrateSushiPositionCard from 'components/PositionCard/Sushi'
@ -17,7 +17,6 @@ import { AutoColumn } from '../../components/Column'
import QuestionHelper from '../../components/QuestionHelper'
import { AutoRow } from '../../components/Row'
import { Dots } from '../../components/swap/styleds'
import { V2_FACTORY_ADDRESSES } from '../../constants/addresses'
import { useTokenBalancesWithLoadingIndicator } from '../../state/connection/hooks'
import { toV2LiquidityToken, useTrackedTokenPairs } from '../../state/user/hooks'
import { BackArrowLink, StyledInternalLink, ThemedText } from '../../theme'

@ -4,7 +4,7 @@ import { Trans } from '@lingui/macro'
import { Trace } from '@uniswap/analytics'
import { InterfacePageName } from '@uniswap/analytics-events'
import { formatPrice, NumberType } from '@uniswap/conedison/format'
import { Currency, CurrencyAmount, Fraction, Percent, Price, Token } from '@uniswap/sdk-core'
import { ChainId, Currency, CurrencyAmount, Fraction, Percent, Price, Token } from '@uniswap/sdk-core'
import { NonfungiblePositionManager, Pool, Position } from '@uniswap/v3-sdk'
import { useWeb3React } from '@web3-react/core'
import { sendEvent } from 'components/analytics'
@ -19,7 +19,7 @@ import { RowBetween, RowFixed } from 'components/Row'
import { Dots } from 'components/swap/styleds'
import Toggle from 'components/Toggle'
import TransactionConfirmationModal, { ConfirmationModalContent } from 'components/TransactionConfirmationModal'
import { CHAIN_IDS_TO_NAMES, isSupportedChain, SupportedChainId } from 'constants/chains'
import { CHAIN_IDS_TO_NAMES, isSupportedChain } from 'constants/chains'
import { isGqlSupportedChain } from 'graphql/data/util'
import { useToken } from 'hooks/Tokens'
import { useV3NFTPositionManagerContract } from 'hooks/useContract'
@ -52,7 +52,7 @@ import { calculateGasMargin } from '../../utils/calculateGasMargin'
import { ExplorerDataType, getExplorerLink } from '../../utils/getExplorerLink'
import { LoadingRows } from './styleds'
const getTokenLink = (chainId: SupportedChainId, address: string) => {
const getTokenLink = (chainId: ChainId, address: string) => {
if (isGqlSupportedChain(chainId)) {
const chainName = CHAIN_IDS_TO_NAMES[chainId]
return `${window.location.origin}/#/tokens/${chainName}/${address}`

@ -1,6 +1,7 @@
import { Trans } from '@lingui/macro'
import { Trace, TraceEvent } from '@uniswap/analytics'
import { BrowserEvent, InterfaceElementName, InterfaceEventName, InterfacePageName } from '@uniswap/analytics-events'
import { V2_FACTORY_ADDRESSES } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { useToggleAccountDrawer } from 'components/AccountDrawer'
import { ButtonGray, ButtonPrimary, ButtonText } from 'components/Button'
@ -20,7 +21,6 @@ import styled, { css, useTheme } from 'styled-components/macro'
import { HideSmall, ThemedText } from 'theme'
import { PositionDetails } from 'types/position'
import { V2_FACTORY_ADDRESSES } from '../../constants/addresses'
import CTACards from './CTACards'
import { LoadingRows } from './styleds'

@ -10,7 +10,7 @@ import {
SwapEventName,
} from '@uniswap/analytics-events'
import { formatCurrencyAmount, NumberType } from '@uniswap/conedison/format'
import { Currency, CurrencyAmount, Percent, Token } from '@uniswap/sdk-core'
import { ChainId, Currency, CurrencyAmount, Percent, Token } from '@uniswap/sdk-core'
import { UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk'
import { useWeb3React } from '@web3-react/core'
import { useToggleAccountDrawer } from 'components/AccountDrawer'
@ -21,7 +21,7 @@ import PriceImpactWarning from 'components/swap/PriceImpactWarning'
import SwapDetailsDropdown from 'components/swap/SwapDetailsDropdown'
import TokenSafetyModal from 'components/TokenSafety/TokenSafetyModal'
import { getChainInfo } from 'constants/chainInfo'
import { isSupportedChain, SupportedChainId } from 'constants/chains'
import { asSupportedChain, isSupportedChain } from 'constants/chains'
import useENSAddress from 'hooks/useENSAddress'
import { useMaxAmountIn } from 'hooks/useMaxAmountIn'
import usePermit2Allowance, { AllowanceState } from 'hooks/usePermit2Allowance'
@ -62,7 +62,6 @@ import { LinkStyledButton, ThemedText } from '../../theme'
import { computeFiatValuePriceImpact } from '../../utils/computeFiatValuePriceImpact'
import { maxAmountSpend } from '../../utils/maxAmountSpend'
import { computeRealizedPriceImpact, warningSeverity } from '../../utils/prices'
import { supportedChainId } from '../../utils/supportedChainId'
export const ArrowContainer = styled.div`
display: inline-flex;
@ -173,7 +172,7 @@ export function Swap({
}: {
className?: string
prefilledState?: Partial<SwapState>
chainId?: SupportedChainId
chainId?: ChainId
onCurrencyChange?: (selected: Pick<SwapState, Field.INPUT | Field.OUTPUT>) => void
disableTokenInputs?: boolean
}) {
@ -214,7 +213,7 @@ export function Swap({
})
.filter((token: Token) => {
// Any token addresses that are loaded from the shorthands map do not need to show the import URL
const supported = supportedChainId(chainId)
const supported = asSupportedChain(chainId)
if (!supported) return true
return !Object.keys(TOKEN_SHORTHANDS).some((shorthand) => {
const shorthandTokenAddress = TOKEN_SHORTHANDS[shorthand][supported]

@ -1,5 +1,5 @@
import { createSlice, nanoid } from '@reduxjs/toolkit'
import { SupportedChainId } from 'constants/chains'
import { ChainId } from '@uniswap/sdk-core'
import { DEFAULT_TXN_DISMISS_MS } from 'constants/misc'
export type PopupContent =
@ -9,7 +9,7 @@ export type PopupContent =
}
}
| {
failedSwitchNetwork: SupportedChainId
failedSwitchNetwork: ChainId
}
export enum ApplicationModal {

@ -1,9 +1,9 @@
import { useWeb3React } from '@web3-react/core'
import { asSupportedChain } from 'constants/chains'
import useDebounce from 'hooks/useDebounce'
import useIsWindowVisible from 'hooks/useIsWindowVisible'
import { useEffect, useRef, useState } from 'react'
import { useAppDispatch } from 'state/hooks'
import { supportedChainId } from 'utils/supportedChainId'
import { useCloseModal } from './hooks'
import { updateChainId } from './reducer'
@ -33,7 +33,7 @@ export default function Updater(): null {
const debouncedChainId = useDebounce(activeChainId, 100)
useEffect(() => {
const chainId = debouncedChainId ? supportedChainId(debouncedChainId) ?? null : null
const chainId = debouncedChainId ? asSupportedChain(debouncedChainId) : null
dispatch(updateChainId({ chainId }))
}, [dispatch, debouncedChainId])

@ -1,8 +1,7 @@
import type { TransactionResponse } from '@ethersproject/providers'
import MerkleDistributorJSON from '@uniswap/merkle-distributor/build/MerkleDistributor.json'
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { CurrencyAmount, MERKLE_DISTRIBUTOR_ADDRESS, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { MERKLE_DISTRIBUTOR_ADDRESS } from 'constants/addresses'
import JSBI from 'jsbi'
import { useSingleCallResult } from 'lib/hooks/multicall'
import { useEffect, useState } from 'react'

@ -8,15 +8,16 @@ import { toUtf8String, Utf8ErrorFuncs, Utf8ErrorReason } from '@ethersproject/st
import { t } from '@lingui/macro'
import GovernorAlphaJSON from '@uniswap/governance/build/GovernorAlpha.json'
import UniJSON from '@uniswap/governance/build/Uni.json'
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import GOVERNOR_BRAVO_ABI from 'abis/governor-bravo.json'
import {
ChainId,
CurrencyAmount,
GOVERNANCE_ALPHA_V0_ADDRESSES,
GOVERNANCE_ALPHA_V1_ADDRESSES,
GOVERNANCE_BRAVO_ADDRESSES,
} from 'constants/addresses'
import { SupportedChainId } from 'constants/chains'
Token,
} from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import GOVERNOR_BRAVO_ABI from 'abis/governor-bravo.json'
import { LATEST_GOVERNOR_INDEX } from 'constants/governance'
import { POLYGON_PROPOSAL_TITLE } from 'constants/proposals/polygon_proposal_title'
import { UNISWAP_GRANTS_PROPOSAL_DESCRIPTION } from 'constants/proposals/uniswap_grants_proposal_description'
@ -240,10 +241,10 @@ export function useAllProposalData(): { data: ProposalData[]; loading: boolean }
const proposalCount2 = useProposalCount(gov2)
const gov0ProposalIndexes = useMemo(() => {
return chainId === SupportedChainId.MAINNET ? V0_PROPOSAL_IDS : countToIndices(proposalCount0)
return chainId === ChainId.MAINNET ? V0_PROPOSAL_IDS : countToIndices(proposalCount0)
}, [chainId, proposalCount0])
const gov1ProposalIndexes = useMemo(() => {
return chainId === SupportedChainId.MAINNET ? V1_PROPOSAL_IDS : countToIndices(proposalCount1)
return chainId === ChainId.MAINNET ? V1_PROPOSAL_IDS : countToIndices(proposalCount1)
}, [chainId, proposalCount1])
const gov2ProposalIndexes = useMemo(() => {
return countToIndices(proposalCount2, 8)
@ -344,7 +345,7 @@ export function useQuorum(governorIndex: number): CurrencyAmount<Token> | undefi
if (
!latestGovernanceContract ||
!quorumVotes ||
chainId !== SupportedChainId.MAINNET ||
chainId !== ChainId.MAINNET ||
!uni ||
governorIndex !== LATEST_GOVERNOR_INDEX
)

Some files were not shown because too many files have changed in this diff Show More