Skip to content

Commit

Permalink
refactor: move ChainId to dedicated file (#2182)
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc authored Jan 13, 2025
1 parent 592cdac commit 519c6d9
Show file tree
Hide file tree
Showing 43 changed files with 80 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fs from 'fs'
import 'dotenv/config'
import { getArbitrumNetwork } from '@arbitrum/sdk'
import { ChainId, rpcURLs } from '../src/util/networks'
import { rpcURLs } from '../src/util/networks'
import { ChainId } from '../src/types/ChainId'
import { getChainToMonitor } from './utils'

// github secrets return '' for empty values, so we need to sanitize the value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
NormalizedCacheObject
} from '@apollo/client'

import { ChainId } from '../util/networks'
import { ChainId } from '../types/ChainId'

/**
* The API key to be used for calls to The Graph Network.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
TeleporterMergedTransaction,
WithdrawalStatus
} from '../../state/app/state'
import { ChainId, getL1BlockTime, isNetwork } from '../../util/networks'
import { getL1BlockTime, isNetwork } from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { Deposit, Transfer } from '../../hooks/useTransactionHistory'
import {
getParentToChildMessageDataFromParentTxHash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useMemo } from 'react'
import { twMerge } from 'tailwind-merge'

import { useAppState } from '../../state'
import { ChainId, getNetworkName, isNetwork } from '../../util/networks'
import { getNetworkName, isNetwork } from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { Tooltip } from '../common/Tooltip'
import { formatAmount } from '../../util/NumberUtils'
import { useNativeCurrency } from '../../hooks/useNativeCurrency'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { BridgesTable } from '../common/BridgesTable'
import { SecurityNotGuaranteed } from './SecurityLabels'
import { Dialog, UseDialogProps } from '../common/Dialog'
import { FastBridgeInfo, FastBridgeNames } from '../../util/fastBridges'
import { ChainId, getNetworkName, isNetwork } from '../../util/networks'
import { getNetworkName, isNetwork } from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { ether } from '../../constants'
import { useArbQueryParams } from '../../hooks/useArbQueryParams'
import { useNetworks } from '../../hooks/useNetworks'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Dialog } from '../common/Dialog'
import { sanitizeTokenSymbol } from '../../util/TokenUtils'
import { useNetworks } from '../../hooks/useNetworks'
import { ExternalLink } from '../common/ExternalLink'
import { ChainId, getNetworkName } from '../../util/networks'
import { getNetworkName } from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { getL2ConfigForTeleport } from '../../token-bridge-sdk/teleport'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { withdrawOnlyTokens } from '../../util/WithdrawOnlyUtils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId } from '../../../util/networks'
import { ChainId } from '../../../types/ChainId'

export enum NetworkType {
parentChain = 'parentChain',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import SyntaxHighlighter from 'react-syntax-highlighter'
import { stackoverflowDark } from 'react-syntax-highlighter/dist/esm/styles/hljs'

import {
ChainId,
ChainWithRpcUrl,
getCustomChainsFromLocalStorage,
getCustomChainFromLocalStorageById,
Expand All @@ -22,6 +21,7 @@ import {
rpcURLs,
isNetwork
} from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { Loader } from './atoms/Loader'
import { Erc20Data, fetchErc20Data } from '../../util/TokenUtils'
import { getProviderForChainId } from '@/token-bridge-sdk/utils'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
import { twMerge } from 'tailwind-merge'
import { AutoSizer, List, ListRowProps } from 'react-virtualized'

import { ChainId, isNetwork, getNetworkName } from '../../util/networks'
import { isNetwork, getNetworkName } from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { useIsTestnetMode } from '../../hooks/useIsTestnetMode'
import { SearchPanel } from './SearchPanel/SearchPanel'
import { SearchPanelTable } from './SearchPanel/SearchPanelTable'
Expand Down
3 changes: 2 additions & 1 deletion packages/arb-token-bridge-ui/src/generateOpenGraphImages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react'
import satori, { Font } from 'satori'
import sharp from 'sharp'
import fs from 'fs'
import { ChainId, isNetwork } from './util/networks'
import { isNetwork } from './util/networks'
import { ChainId } from './types/ChainId'
import { getBridgeUiConfigForChain } from './util/bridgeUiConfig'
import { orbitMainnets, orbitTestnets } from './util/orbitChainsList'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import useSWRImmutable from 'swr/immutable'
import { ChainId } from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { getCctpUtils } from '@/token-bridge-sdk/cctp'

export function useCCTPIsBlocked() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
ChainId,
getDestinationChainIds,
getSupportedChainIds
} from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { useIsTestnetMode } from '../useIsTestnetMode'
import { useNetworks } from '../useNetworks'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* @jest-environment jsdom
*/
import { registerCustomArbitrumNetwork } from '@arbitrum/sdk'
import { ChainId, customChainLocalStorageKey } from '../../util/networks'
import { customChainLocalStorageKey } from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { AmountQueryParam, ChainParam } from '../useArbQueryParams'
import { createMockOrbitChain } from './helpers'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* @jest-environment jsdom
*/
import { registerCustomArbitrumNetwork } from '@arbitrum/sdk'
import { ChainId, customChainLocalStorageKey } from '../../util/networks'
import { customChainLocalStorageKey } from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { sanitizeQueryParams } from '../useNetworks'
import { createMockOrbitChain } from './helpers'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
getChainQueryParamForChain,
isValidChainQueryParam
} from '../types/ChainQueryParam'
import { ChainId } from '../util/networks'
import { ChainId } from '../types/ChainId'

export enum AmountQueryParamEnum {
MAX = 'max'
Expand Down
3 changes: 2 additions & 1 deletion packages/arb-token-bridge-ui/src/hooks/useIsTestnetMode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback } from 'react'
import { useNetworks } from './useNetworks'
import { ChainId, isNetwork } from '../util/networks'
import { isNetwork } from '../util/networks'
import { ChainId } from '../types/ChainId'

export const useIsTestnetMode = () => {
const [networks, setNetworks] = useNetworks()
Expand Down
3 changes: 2 additions & 1 deletion packages/arb-token-bridge-ui/src/hooks/useNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { useCallback, useMemo } from 'react'
import { mainnet, arbitrum } from '@wagmi/core/chains'

import { useArbQueryParams } from './useArbQueryParams'
import { ChainId, getCustomChainsFromLocalStorage } from '../util/networks'
import { getCustomChainsFromLocalStorage } from '../util/networks'
import { ChainId } from '../types/ChainId'
import {
sepolia,
holesky,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import useSWRInfinite from 'swr/infinite'
import { useCallback, useEffect, useMemo, useState } from 'react'
import dayjs from 'dayjs'

import {
ChainId,
getChains,
getChildChainIds,
isNetwork
} from '../util/networks'
import { getChains, getChildChainIds, isNetwork } from '../util/networks'
import { ChainId } from '../types/ChainId'
import { fetchWithdrawals } from '../util/withdrawals/fetchWithdrawals'
import { fetchDeposits } from '../util/deposits/fetchDeposits'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/pages/api/cctp/[type].ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { gql } from '@apollo/client'
import { NextApiRequest, NextApiResponse } from 'next'

import { ChainId } from '../../../util/networks'
import { ChainId } from '../../../types/ChainId'
import { Address } from '../../../util/AddressUtils'

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { gql } from '@apollo/client'

import { ChainId } from '../../../../util/networks'
import { ChainId } from '../../../../types/ChainId'
import {
getL1SubgraphClient,
getL2SubgraphClient,
Expand Down
8 changes: 2 additions & 6 deletions packages/arb-token-bridge-ui/src/state/cctpState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import useSWRImmutable from 'swr/immutable'
import { useInterval } from 'react-use'

import { getCctpUtils } from '@/token-bridge-sdk/cctp'
import {
ChainId,
getL1BlockTime,
getNetworkName,
isNetwork
} from '../util/networks'
import { getL1BlockTime, getNetworkName, isNetwork } from '../util/networks'
import { ChainId } from '../types/ChainId'
import { fetchCCTPDeposits, fetchCCTPWithdrawals } from '../util/cctp/fetchCCTP'
import { DepositStatus, MergedTransaction, WithdrawalStatus } from './app/state'
import { normalizeTimestamp } from './app/utils'
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/token-bridge-sdk/cctp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChainDomain } from '../pages/api/cctp/[type]'
import { prepareWriteContract, writeContract } from '@wagmi/core'
import { MessageTransmitterAbi } from '../util/cctp/MessageTransmitterAbi'
import { CCTPSupportedChainId } from '../state/cctpState'
import { ChainId } from '../util/networks'
import { ChainId } from '../types/ChainId'
import { CommonAddress } from '../util/CommonAddressUtils'
import { Address } from '../util/AddressUtils'

Expand Down
3 changes: 2 additions & 1 deletion packages/arb-token-bridge-ui/src/token-bridge-sdk/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BigNumber, Signer } from 'ethers'
import { Provider, StaticJsonRpcProvider } from '@ethersproject/providers'

import { ChainId, isNetwork, rpcURLs } from '../util/networks'
import { isNetwork, rpcURLs } from '../util/networks'
import { ChainId } from '../types/ChainId'
import { BridgeTransferStarterPropsWithChainIds } from './BridgeTransferStarter'
import { isValidTeleportChainPair } from './teleport'
import {
Expand Down
18 changes: 18 additions & 0 deletions packages/arb-token-bridge-ui/src/types/ChainId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export enum ChainId {
// L1
Ethereum = 1,
// L1 Testnets
Local = 1337,
Sepolia = 11155111,
Holesky = 17000,
// L2
ArbitrumOne = 42161,
ArbitrumNova = 42170,
Base = 8453,
// L2 Testnets
ArbitrumSepolia = 421614,
ArbitrumLocal = 412346,
BaseSepolia = 84532,
// L3 Testnets
L3Local = 333333
}
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/types/ChainQueryParam.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Chain } from 'wagmi'
import * as chains from 'wagmi/chains'
import {
ChainId,
getCustomChainFromLocalStorageById,
getSupportedChainIds
} from '../util/networks'
import { ChainId } from '../types/ChainId'
import * as customChains from '../util/wagmi/wagmiAdditionalNetworks'
import { getOrbitChains, orbitChains } from '../util/orbitChainsList'
import { chainToWagmiChain } from '../util/wagmi/wagmiAdditionalNetworks'
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/util/L2ApprovalUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId } from '../util/networks'
import { ChainId } from '../types/ChainId'
import { xErc20RequiresApprovalOnChildChain } from './xErc20Utils'

export type RequireL2ApproveToken = {
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/util/L2NativeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId } from '../util/networks'
import { ChainId } from '../types/ChainId'
import { CommonAddress } from './CommonAddressUtils'

export type L2NativeToken = {
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/util/SubgraphUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId } from './networks'
import { ChainId } from '../types/ChainId'
import { getAPIBaseUrl } from '.'

export function hasL1Subgraph(l2ChainId: number) {
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/util/TokenListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import CMCLogo from '@/images/lists/cmc.png'
import CoinGeckoLogo from '@/images/lists/coinGecko.svg'
import ArbitrumLogo from '@/images/lists/ArbitrumLogo.png'
import { ArbTokenBridge } from '../hooks/arbTokenBridge.types'
import { ChainId } from './networks'
import { ChainId } from '../types/ChainId'
import orbitChainsData from './orbitChainsData.json'

export const SPECIAL_ARBITRUM_TOKEN_TOKEN_LIST_ID =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId } from './networks'
import { ChainId } from '../types/ChainId'

export type TeleportEnabledToken = {
symbol: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId } from '../util/networks'
import { ChainId } from '../types/ChainId'

export type TransferDisabledToken = {
symbol: string
Expand Down
3 changes: 2 additions & 1 deletion packages/arb-token-bridge-ui/src/util/TokenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
import { ERC20__factory } from '@arbitrum/sdk/dist/lib/abi/factories/ERC20__factory'

import { CommonAddress } from './CommonAddressUtils'
import { ChainId, isNetwork } from './networks'
import { isNetwork } from './networks'
import { ChainId } from '../types/ChainId'
import { defaultErc20Decimals } from '../defaults'
import { ERC20BridgeToken, TokenType } from '../hooks/arbTokenBridge.types'
import { getBridger, getChainIdFromProvider } from '../token-bridge-sdk/utils'
Expand Down
3 changes: 2 additions & 1 deletion packages/arb-token-bridge-ui/src/util/WithdrawOnlyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import { ethers } from 'ethers'
import { getProviderForChainId } from '@/token-bridge-sdk/utils'

import { ChainId, isNetwork } from '../util/networks'
import { isNetwork } from '../util/networks'
import { ChainId } from '../types/ChainId'
import {
isTokenArbitrumOneUSDCe,
isTokenArbitrumSepoliaUSDCe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { registerCustomArbitrumNetwork } from '@arbitrum/sdk'

import {
ChainId,
getBlockNumberReferenceChainIdByChainId,
getDestinationChainIds,
getSupportedChainIds
} from '../networks'
import { ChainId } from '../../types/ChainId'
import { orbitTestnets } from '../orbitChainsList'

const xaiTestnetChainId = 37714555429
Expand Down
3 changes: 2 additions & 1 deletion packages/arb-token-bridge-ui/src/util/bridgeUiConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChainId, getCustomChainFromLocalStorageById } from './networks'
import { getCustomChainFromLocalStorageById } from './networks'
import { ChainId } from '../types/ChainId'
import { orbitChains, BridgeUiConfig } from './orbitChainsList'

export function getBridgeUiConfigForChain(chainId: number): BridgeUiConfig {
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/util/cctp/fetchCCTP.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId } from '../networks'
import { ChainId } from '../../types/ChainId'
import { getAPIBaseUrl, sanitizeQueryParams } from '..'
import {
CompletedCCTPTransfer,
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/util/fastBridges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Wormhole from '@/images/bridge/wormhole.svg'
// import LIFI from '@/images/bridge/lifi.webp'
import Router from '@/images/bridge/router.webp'

import { ChainId } from './networks'
import { ChainId } from '../types/ChainId'
import { USDC_LEARN_MORE_LINK } from '../constants'

export enum FastBridgeNames {
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/util/infura.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { providers } from 'ethers'
import { Chain, ChainProviderFn } from 'wagmi'

import { ChainId } from './networks'
import { ChainId } from '../types/ChainId'

// custom implementation based on https://github.com/wevm/wagmi/blob/wagmi%400.12.13/packages/core/src/providers/infura.ts
// with multiple infura keys support
Expand Down
20 changes: 1 addition & 19 deletions packages/arb-token-bridge-ui/src/util/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,7 @@ import { getBridgeUiConfigForChain } from './bridgeUiConfig'
import { chainIdToInfuraUrl } from './infura'
import { fetchErc20Data } from './TokenUtils'
import { orbitChains } from './orbitChainsList'

export enum ChainId {
// L1
Ethereum = 1,
// L1 Testnets
Local = 1337,
Sepolia = 11155111,
Holesky = 17000,
// L2
ArbitrumOne = 42161,
ArbitrumNova = 42170,
Base = 8453,
// L2 Testnets
ArbitrumSepolia = 421614,
ArbitrumLocal = 412346,
BaseSepolia = 84532,
// L3 Testnets
L3Local = 333333
}
import { ChainId } from '../types/ChainId'

/** The network that you reference when calling `block.number` in solidity */
type BlockNumberReferenceNetwork = {
Expand Down
Loading

0 comments on commit 519c6d9

Please sign in to comment.