-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
chains.ts
147 lines (133 loc) · 4.24 KB
/
chains.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { ChainId, SUPPORTED_CHAINS, SupportedChainsType, V2_ROUTER_ADDRESSES } from '@uniswap/sdk-core'
export const CHAIN_IDS_TO_NAMES = {
[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',
[ChainId.BASE]: 'base',
} as const
// Include ChainIds in this array if they are not supported by the UX yet, but are already in the SDK.
const NOT_YET_UX_SUPPORTED_CHAIN_IDS: number[] = [
ChainId.BASE_GOERLI,
ChainId.ARBITRUM_SEPOLIA,
ChainId.OPTIMISM_SEPOLIA,
]
// TODO: include BASE_GOERLI, OPTIMISM_SEPOLIA, or ARBITRUM_SEPOLIA when routing is implemented
export type SupportedInterfaceChain = Exclude<
SupportedChainsType,
ChainId.BASE_GOERLI | ChainId.ARBITRUM_SEPOLIA | ChainId.OPTIMISM_SEPOLIA
>
export function isSupportedChain(
chainId: number | null | undefined | ChainId,
featureFlags?: Record<number, boolean>
): chainId is SupportedInterfaceChain {
if (featureFlags && chainId && chainId in featureFlags) {
return featureFlags[chainId]
}
return !!chainId && SUPPORTED_CHAINS.indexOf(chainId) !== -1 && NOT_YET_UX_SUPPORTED_CHAIN_IDS.indexOf(chainId) === -1
}
export function asSupportedChain(
chainId: number | null | undefined | ChainId,
featureFlags?: Record<number, boolean>
): SupportedInterfaceChain | undefined {
if (!chainId) return undefined
if (featureFlags && chainId in featureFlags && !featureFlags[chainId]) {
return undefined
}
return isSupportedChain(chainId) ? chainId : undefined
}
export const SUPPORTED_GAS_ESTIMATE_CHAIN_IDS = [
ChainId.MAINNET,
ChainId.POLYGON,
ChainId.CELO,
ChainId.OPTIMISM,
ChainId.ARBITRUM_ONE,
ChainId.BNB,
ChainId.AVALANCHE,
ChainId.BASE,
] as const
/**
* @deprecated when v2 pools are enabled on chains supported through sdk-core
*/
export const SUPPORTED_V2POOL_CHAIN_IDS_DEPRECATED = [ChainId.MAINNET, ChainId.GOERLI] as const
export const SUPPORTED_V2POOL_CHAIN_IDS = Object.keys(V2_ROUTER_ADDRESSES).map((chainId) => parseInt(chainId))
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 = [
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]
/**
* Controls some L2 specific behavior, e.g. slippage tolerance, special UI behavior.
* The expectation is that all of these networks have immediate transaction confirmation.
*/
export const L2_CHAIN_IDS = [
ChainId.ARBITRUM_ONE,
ChainId.ARBITRUM_GOERLI,
ChainId.OPTIMISM,
ChainId.OPTIMISM_GOERLI,
ChainId.BASE,
] as const
export type SupportedL2ChainId = (typeof L2_CHAIN_IDS)[number]
/**
* Get the priority of a chainId based on its relevance to the user.
* @param {ChainId} chainId - The chainId to determine the priority for.
* @returns {number} The priority of the chainId, the lower the priority, the earlier it should be displayed, with base of MAINNET=0.
*/
export function getChainPriority(chainId: ChainId): number {
switch (chainId) {
case ChainId.MAINNET:
case ChainId.GOERLI:
case ChainId.SEPOLIA:
return 0
case ChainId.ARBITRUM_ONE:
case ChainId.ARBITRUM_GOERLI:
return 1
case ChainId.OPTIMISM:
case ChainId.OPTIMISM_GOERLI:
return 2
case ChainId.POLYGON:
case ChainId.POLYGON_MUMBAI:
return 3
case ChainId.BASE:
return 4
case ChainId.BNB:
return 5
case ChainId.AVALANCHE:
return 6
case ChainId.CELO:
case ChainId.CELO_ALFAJORES:
return 7
default:
return 8
}
}
export function isUniswapXSupportedChain(chainId: number) {
return chainId === ChainId.MAINNET
}