Refactor chain metadata (#1449)
- Merge the chain metadata from the explorer, the existing sdk metadata, and the sdk's chain connection configs, all into one - DRY up configs in infra + sdk - Alphabetize chain names and configs - Fix circular dep in types - Add convenience utils for retrieving chain metadatapull/1473/head
parent
ff8ac2eabd
commit
343225a7c1
@ -1,187 +1,628 @@ |
|||||||
import { ChainName } from '../types'; |
import type { Chain as WagmiChain } from '@wagmi/chains'; |
||||||
|
|
||||||
|
import { objMap } from '../utils/objects'; |
||||||
|
|
||||||
|
import { ChainName, Chains, Mainnets, Testnets } from './chains'; |
||||||
|
|
||||||
|
export enum ExplorerFamily { |
||||||
|
Etherscan = 'etherscan', |
||||||
|
Blockscout = 'blockscout', |
||||||
|
Other = 'other', |
||||||
|
} |
||||||
|
|
||||||
/** |
/** |
||||||
* A Chain and its characteristics |
* Collection of useful properties and settings |
||||||
|
* for Hyperlane-supported chains |
||||||
*/ |
*/ |
||||||
export type ChainMetadata = { |
export interface ChainMetadata { |
||||||
id: number; |
id: number; |
||||||
finalityBlocks: number; |
name: ChainName; |
||||||
nativeTokenDecimals?: number; |
/** Human-readable name */ |
||||||
paginate?: RpcPagination; |
displayName: string; |
||||||
// The CoinGecko API expects, in some cases, IDs that do not match
|
/** Shorter human-readable name */ |
||||||
// ChainNames.
|
displayNameShort?: string; |
||||||
|
/** Default currency/token used by chain */ |
||||||
|
nativeToken: { |
||||||
|
name: string; |
||||||
|
symbol: string; |
||||||
|
decimals: number; |
||||||
|
}; |
||||||
|
/** Collection of RPC endpoints */ |
||||||
|
publicRpcUrls: Array<{ |
||||||
|
http: string; |
||||||
|
webSocket?: string; |
||||||
|
pagination?: RpcPagination; |
||||||
|
}>; |
||||||
|
/** Collection of block explorers */ |
||||||
|
blockExplorers: Array<{ |
||||||
|
name: string; |
||||||
|
url: string; |
||||||
|
family: ExplorerFamily; |
||||||
|
apiUrl?: string; |
||||||
|
}>; |
||||||
|
blocks: { |
||||||
|
// Number of blocks to wait before considering a transaction confirmed
|
||||||
|
confirmations: number; |
||||||
|
// TODO consider merging with confirmations, require agent code changes
|
||||||
|
// Number of blocks before a transaction has a near-zero chance of reverting
|
||||||
|
reorgPeriod: number; |
||||||
|
// Rough estimate of time per block in seconds
|
||||||
|
estimateBlockTime: number; |
||||||
|
}; |
||||||
|
// The CoinGecko API sometimes expects IDs that do not match ChainNames
|
||||||
gasCurrencyCoinGeckoId?: string; |
gasCurrencyCoinGeckoId?: string; |
||||||
// URL of the gnosis safe transaction service.
|
// URL of the gnosis safe transaction service.
|
||||||
gnosisSafeTransactionServiceUrl?: string; |
gnosisSafeTransactionServiceUrl?: string; |
||||||
}; |
} |
||||||
|
|
||||||
/** |
|
||||||
* RPC Pagination information |
|
||||||
*/ |
|
||||||
export interface RpcPagination { |
export interface RpcPagination { |
||||||
blocks: number; |
blocks: number; |
||||||
from: number; |
from: number; |
||||||
} |
} |
||||||
|
|
||||||
// IDs can be generated in many ways-- for example, in JS:
|
|
||||||
// > Array.from('celo').map((c, i) => c.charCodeAt(0).toString(16).padStart(2, '0')).join('')
|
|
||||||
// '63656c6f'
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* Mainnets |
* Common native currencies |
||||||
*/ |
*/ |
||||||
export const celo: ChainMetadata = { |
const avaxToken = { |
||||||
id: 42220, |
decimals: 18, |
||||||
finalityBlocks: 0, |
name: 'Avalanche', |
||||||
gnosisSafeTransactionServiceUrl: |
symbol: 'AVAX', |
||||||
'https://transaction-service.gnosis-safe-staging.celo-networks-dev.org', |
}; |
||||||
|
const bnbToken = { |
||||||
|
decimals: 18, |
||||||
|
name: 'BNB', |
||||||
|
symbol: 'BNB', |
||||||
}; |
}; |
||||||
|
const celoToken = { |
||||||
|
decimals: 18, |
||||||
|
name: 'CELO', |
||||||
|
symbol: 'CELO', |
||||||
|
}; |
||||||
|
const etherToken = { name: 'Ether', symbol: 'ETH', decimals: 18 }; |
||||||
|
const maticToken = { name: 'MATIC', symbol: 'MATIC', decimals: 18 }; |
||||||
|
|
||||||
export const ethereum: ChainMetadata = { |
/** |
||||||
id: 1, |
* Chain metadata |
||||||
finalityBlocks: 20, |
*/ |
||||||
gnosisSafeTransactionServiceUrl: 'https://safe-transaction.gnosis.io', |
|
||||||
|
export const alfajores: ChainMetadata = { |
||||||
|
id: 44787, |
||||||
|
name: Chains.alfajores, |
||||||
|
displayName: 'Alfajores', |
||||||
|
nativeToken: celoToken, |
||||||
|
publicRpcUrls: [{ http: 'https://alfajores-forno.celo-testnet.org' }], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'CeloScan', |
||||||
|
url: 'https://alfajores.celoscan.io', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
{ |
||||||
|
name: 'Blockscout', |
||||||
|
url: 'https://explorer.celo.org/alfajores', |
||||||
|
family: ExplorerFamily.Blockscout, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 0, |
||||||
|
estimateBlockTime: 5, |
||||||
|
}, |
||||||
}; |
}; |
||||||
|
|
||||||
export const arbitrum: ChainMetadata = { |
export const arbitrum: ChainMetadata = { |
||||||
id: 42161, |
id: 42161, |
||||||
finalityBlocks: 0, |
name: Chains.arbitrum, |
||||||
|
displayName: 'Arbitrum', |
||||||
|
nativeToken: etherToken, |
||||||
|
publicRpcUrls: [{ http: 'https://arb1.arbitrum.io/rpc' }], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'Arbiscan', |
||||||
|
url: 'https://arbiscan.io', |
||||||
|
apiUrl: 'https://api.arbiscan.io', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 0, |
||||||
|
estimateBlockTime: 3, |
||||||
|
}, |
||||||
gasCurrencyCoinGeckoId: 'ethereum', // ETH is used for gas
|
gasCurrencyCoinGeckoId: 'ethereum', // ETH is used for gas
|
||||||
gnosisSafeTransactionServiceUrl: |
gnosisSafeTransactionServiceUrl: |
||||||
'https://safe-transaction.arbitrum.gnosis.io/', |
'https://safe-transaction.arbitrum.gnosis.io/', |
||||||
}; |
}; |
||||||
|
|
||||||
export const optimism: ChainMetadata = { |
export const arbitrumgoerli: ChainMetadata = { |
||||||
id: 10, |
id: 421613, |
||||||
finalityBlocks: 0, |
name: Chains.arbitrumgoerli, |
||||||
gasCurrencyCoinGeckoId: 'ethereum', // ETH is used for gas
|
displayName: 'Arbitrum Goerli', |
||||||
gnosisSafeTransactionServiceUrl: |
displayNameShort: 'Arb. Goerli', |
||||||
'https://safe-transaction.optimism.gnosis.io/', |
nativeToken: etherToken, |
||||||
}; |
publicRpcUrls: [{ http: 'https://goerli-rollup.arbitrum.io/rpc' }], |
||||||
|
blockExplorers: [ |
||||||
export const bsc: ChainMetadata = { |
{ |
||||||
id: 56, |
name: 'Arbiscan', |
||||||
finalityBlocks: 15, |
url: 'https://goerli.arbiscan.io/', |
||||||
gasCurrencyCoinGeckoId: 'binancecoin', |
apiUrl: 'https://api-goerli.arbiscan.io', |
||||||
gnosisSafeTransactionServiceUrl: 'https://safe-transaction.bsc.gnosis.io/', |
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 1, |
||||||
|
estimateBlockTime: 3, |
||||||
|
}, |
||||||
}; |
}; |
||||||
|
|
||||||
export const avalanche: ChainMetadata = { |
export const avalanche: ChainMetadata = { |
||||||
id: 43114, |
id: 43114, |
||||||
finalityBlocks: 3, |
name: Chains.avalanche, |
||||||
paginate: { |
displayName: 'Avalanche', |
||||||
// Needs to be low to avoid RPC timeouts
|
nativeToken: avaxToken, |
||||||
|
publicRpcUrls: [ |
||||||
|
{ |
||||||
|
http: 'https://api.avax.network/ext/bc/C/rpc', |
||||||
|
pagination: { |
||||||
blocks: 100000, |
blocks: 100000, |
||||||
from: 6765067, |
from: 6765067, |
||||||
}, |
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'SnowTrace', |
||||||
|
url: 'https://snowtrace.io', |
||||||
|
apiUrl: 'https://api.snowtrace.io', |
||||||
|
family: ExplorerFamily.Other, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 3, |
||||||
|
reorgPeriod: 3, |
||||||
|
estimateBlockTime: 2, |
||||||
|
}, |
||||||
gasCurrencyCoinGeckoId: 'avalanche-2', |
gasCurrencyCoinGeckoId: 'avalanche-2', |
||||||
gnosisSafeTransactionServiceUrl: |
gnosisSafeTransactionServiceUrl: |
||||||
'https://safe-transaction.avalanche.gnosis.io/', |
'https://safe-transaction.avalanche.gnosis.io/', |
||||||
}; |
}; |
||||||
|
|
||||||
export const polygon: ChainMetadata = { |
export const bsc: ChainMetadata = { |
||||||
id: 137, |
id: 56, |
||||||
finalityBlocks: 256, |
name: Chains.bsc, |
||||||
paginate: { |
displayName: 'Binance Smart Chain', |
||||||
// Needs to be low to avoid RPC timeouts
|
displayNameShort: 'Binance', |
||||||
blocks: 10000, |
nativeToken: bnbToken, |
||||||
from: 19657100, |
publicRpcUrls: [ |
||||||
|
{ http: 'https://bsc-dataseed.binance.org' }, |
||||||
|
{ http: 'https://rpc.ankr.com/bsc' }, |
||||||
|
], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'BscScan', |
||||||
|
url: 'https://bscscan.com', |
||||||
|
apiUrl: 'https://api.bscscan.com', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 15, |
||||||
|
estimateBlockTime: 3, |
||||||
|
}, |
||||||
|
gasCurrencyCoinGeckoId: 'binancecoin', |
||||||
|
gnosisSafeTransactionServiceUrl: 'https://safe-transaction.bsc.gnosis.io/', |
||||||
|
}; |
||||||
|
|
||||||
|
export const bsctestnet: ChainMetadata = { |
||||||
|
id: 97, |
||||||
|
name: Chains.bsctestnet, |
||||||
|
displayName: 'BSC Testnet', |
||||||
|
nativeToken: bnbToken, |
||||||
|
publicRpcUrls: [{ http: 'https://data-seed-prebsc-1-s3.binance.org:8545' }], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'BscScan', |
||||||
|
url: 'https://testnet.bscscan.com', |
||||||
|
apiUrl: 'https://api-testnet.bscscan.com', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 9, |
||||||
|
estimateBlockTime: 3, |
||||||
|
}, |
||||||
|
}; |
||||||
|
|
||||||
|
export const celo: ChainMetadata = { |
||||||
|
id: 42220, |
||||||
|
name: Chains.celo, |
||||||
|
displayName: 'Celo', |
||||||
|
nativeToken: celoToken, |
||||||
|
publicRpcUrls: [{ http: 'https://forno.celo.org' }], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'CeloScan', |
||||||
|
url: 'https://celoscan.io', |
||||||
|
apiUrl: 'https://api.celoscan.io', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
{ |
||||||
|
name: 'Blockscout', |
||||||
|
url: 'https://explorer.celo.org', |
||||||
|
family: ExplorerFamily.Blockscout, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 0, |
||||||
|
estimateBlockTime: 5, |
||||||
}, |
}, |
||||||
gasCurrencyCoinGeckoId: 'matic-network', |
|
||||||
gnosisSafeTransactionServiceUrl: |
gnosisSafeTransactionServiceUrl: |
||||||
'https://safe-transaction.polygon.gnosis.io/', |
'https://transaction-service.gnosis-safe-staging.celo-networks-dev.org', |
||||||
}; |
}; |
||||||
|
|
||||||
/** |
export const ethereum: ChainMetadata = { |
||||||
* Testnets |
id: 1, |
||||||
*/ |
name: Chains.ethereum, |
||||||
export const alfajores: ChainMetadata = { |
displayName: 'Ethereum', |
||||||
id: 44787, |
nativeToken: etherToken, |
||||||
finalityBlocks: 0, |
publicRpcUrls: [{ http: 'https://cloudflare-eth.com' }], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'Etherscan', |
||||||
|
url: 'https://etherscan.io', |
||||||
|
apiUrl: 'https://api.etherscan.io', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
{ |
||||||
|
name: 'Blockscout', |
||||||
|
url: 'https://blockscout.com/eth/mainnet', |
||||||
|
family: ExplorerFamily.Blockscout, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 7, |
||||||
|
reorgPeriod: 20, |
||||||
|
estimateBlockTime: 13, |
||||||
|
}, |
||||||
|
gnosisSafeTransactionServiceUrl: 'https://safe-transaction.gnosis.io', |
||||||
}; |
}; |
||||||
|
|
||||||
export const fuji: ChainMetadata = { |
export const fuji: ChainMetadata = { |
||||||
id: 43113, |
id: 43113, |
||||||
finalityBlocks: 3, |
name: Chains.fuji, |
||||||
|
displayName: 'Fuji', |
||||||
|
nativeToken: avaxToken, |
||||||
|
publicRpcUrls: [{ http: 'https://api.avax-test.network/ext/bc/C/rpc' }], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'SnowTrace', |
||||||
|
url: 'https://testnet.snowtrace.io', |
||||||
|
apiUrl: 'https://api-testnet.snowtrace.io', |
||||||
|
family: ExplorerFamily.Other, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 3, |
||||||
|
reorgPeriod: 3, |
||||||
|
estimateBlockTime: 2, |
||||||
|
}, |
||||||
}; |
}; |
||||||
|
|
||||||
export const goerli: ChainMetadata = { |
export const goerli: ChainMetadata = { |
||||||
id: 5, |
id: 5, |
||||||
finalityBlocks: 2, |
name: Chains.goerli, |
||||||
}; |
displayName: 'Goerli', |
||||||
|
nativeToken: etherToken, |
||||||
export const optimismgoerli: ChainMetadata = { |
publicRpcUrls: [{ http: 'https://rpc.ankr.com/eth_goerli' }], |
||||||
id: 420, |
blockExplorers: [ |
||||||
finalityBlocks: 1, |
{ |
||||||
|
name: 'Etherscan', |
||||||
|
url: 'https://goerli.etherscan.io', |
||||||
|
apiUrl: 'https://api-goerli.etherscan.io', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 2, |
||||||
|
estimateBlockTime: 13, |
||||||
|
}, |
||||||
}; |
}; |
||||||
|
|
||||||
export const arbitrumgoerli: ChainMetadata = { |
export const moonbasealpha: ChainMetadata = { |
||||||
id: 421613, |
id: 1287, |
||||||
finalityBlocks: 1, |
name: Chains.moonbasealpha, |
||||||
|
displayName: 'Moonbase Alpha', |
||||||
|
displayNameShort: 'Moonbase', |
||||||
|
nativeToken: { |
||||||
|
decimals: 18, |
||||||
|
name: 'DEV', |
||||||
|
symbol: 'DEV', |
||||||
|
}, |
||||||
|
publicRpcUrls: [{ http: 'https://rpc.api.moonbase.moonbeam.network' }], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'MoonScan', |
||||||
|
url: 'https://moonbase.moonscan.io', |
||||||
|
apiUrl: 'https://api-moonbase.moonscan.io', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 1, |
||||||
|
estimateBlockTime: 12, |
||||||
|
}, |
||||||
}; |
}; |
||||||
|
|
||||||
export const zksync2testnet: ChainMetadata = { |
export const moonbeam: ChainMetadata = { |
||||||
id: 280, |
id: 1284, |
||||||
finalityBlocks: 1, |
name: Chains.moonbeam, |
||||||
|
displayName: 'Moonbeam', |
||||||
|
nativeToken: { |
||||||
|
decimals: 18, |
||||||
|
name: 'GLMR', |
||||||
|
symbol: 'GLMR', |
||||||
|
}, |
||||||
|
publicRpcUrls: [{ http: 'https://rpc.api.moonbeam.network' }], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'MoonScan', |
||||||
|
url: 'https://moonscan.io', |
||||||
|
apiUrl: 'https://api-moonbeam.moonscan.io', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 1, |
||||||
|
estimateBlockTime: 12, |
||||||
|
}, |
||||||
}; |
}; |
||||||
|
|
||||||
export const mumbai: ChainMetadata = { |
export const mumbai: ChainMetadata = { |
||||||
id: 80001, |
id: 80001, |
||||||
finalityBlocks: 32, |
name: Chains.mumbai, |
||||||
paginate: { |
displayName: 'Mumbai', |
||||||
|
nativeToken: maticToken, |
||||||
|
publicRpcUrls: [ |
||||||
|
{ |
||||||
|
http: 'https://rpc-mumbai.maticvigil.com', |
||||||
|
pagination: { |
||||||
// eth_getLogs and eth_newFilter are limited to a 10,000 blocks range
|
// eth_getLogs and eth_newFilter are limited to a 10,000 blocks range
|
||||||
blocks: 10000, |
blocks: 10000, |
||||||
from: 22900000, |
from: 22900000, |
||||||
}, |
}, |
||||||
|
}, |
||||||
|
{ |
||||||
|
http: 'https://matic-mumbai.chainstacklabs.com', |
||||||
|
}, |
||||||
|
], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'PolygonScan', |
||||||
|
url: 'https://mumbai.polygonscan.com', |
||||||
|
apiUrl: 'https://api-testnet.polygonscan.com', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 3, |
||||||
|
reorgPeriod: 32, |
||||||
|
estimateBlockTime: 5, |
||||||
|
}, |
||||||
}; |
}; |
||||||
|
|
||||||
const testChains = { |
export const optimism: ChainMetadata = { |
||||||
test1: { |
id: 10, |
||||||
id: 13371, |
name: Chains.optimism, |
||||||
finalityBlocks: 0, |
displayName: 'Optimism', |
||||||
|
nativeToken: etherToken, |
||||||
|
publicRpcUrls: [{ http: 'https://mainnet.optimism.io' }], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'Etherscan', |
||||||
|
url: 'https://optimistic.etherscan.io', |
||||||
|
apiUrl: 'https://api-optimistic.etherscan.io', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
}, |
}, |
||||||
test2: { |
], |
||||||
id: 13372, |
blocks: { |
||||||
finalityBlocks: 1, |
confirmations: 1, |
||||||
|
reorgPeriod: 0, |
||||||
|
estimateBlockTime: 3, |
||||||
}, |
}, |
||||||
test3: { |
gasCurrencyCoinGeckoId: 'ethereum', // ETH is used for gas
|
||||||
id: 13373, |
gnosisSafeTransactionServiceUrl: |
||||||
finalityBlocks: 2, |
'https://safe-transaction.optimism.gnosis.io/', |
||||||
|
}; |
||||||
|
|
||||||
|
export const optimismgoerli: ChainMetadata = { |
||||||
|
id: 420, |
||||||
|
name: Chains.optimismgoerli, |
||||||
|
displayName: 'Optimism Goerli', |
||||||
|
displayNameShort: 'Opt. Goerli', |
||||||
|
nativeToken: etherToken, |
||||||
|
publicRpcUrls: [{ http: 'https://goerli.optimism.io' }], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'Etherscan', |
||||||
|
url: 'https://goerli-optimism.etherscan.io', |
||||||
|
apiUrl: 'https://api-goerli-optimism.etherscan.io', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 1, |
||||||
|
estimateBlockTime: 3, |
||||||
}, |
}, |
||||||
}; |
}; |
||||||
|
|
||||||
export const bsctestnet: ChainMetadata = { |
export const polygon: ChainMetadata = { |
||||||
id: 97, |
id: 137, |
||||||
finalityBlocks: 9, |
name: Chains.polygon, |
||||||
|
displayName: 'Polygon', |
||||||
|
nativeToken: etherToken, |
||||||
|
publicRpcUrls: [ |
||||||
|
{ |
||||||
|
http: 'https://rpc-mainnet.matic.quiknode.pro', |
||||||
|
pagination: { |
||||||
|
// Needs to be low to avoid RPC timeouts
|
||||||
|
blocks: 10000, |
||||||
|
from: 19657100, |
||||||
|
}, |
||||||
|
}, |
||||||
|
{ http: 'https://polygon-rpc.com' }, |
||||||
|
], |
||||||
|
blockExplorers: [ |
||||||
|
{ |
||||||
|
name: 'PolygonScan', |
||||||
|
url: 'https://polygonscan.com', |
||||||
|
apiUrl: 'https://api.polygonscan.com', |
||||||
|
family: ExplorerFamily.Etherscan, |
||||||
|
}, |
||||||
|
], |
||||||
|
blocks: { |
||||||
|
confirmations: 200, |
||||||
|
reorgPeriod: 256, |
||||||
|
estimateBlockTime: 2, |
||||||
|
}, |
||||||
|
gasCurrencyCoinGeckoId: 'matic-network', |
||||||
|
gnosisSafeTransactionServiceUrl: |
||||||
|
'https://safe-transaction.polygon.gnosis.io/', |
||||||
}; |
}; |
||||||
|
|
||||||
export const moonbasealpha: ChainMetadata = { |
export const test1: ChainMetadata = { |
||||||
id: 1287, |
id: 13371, |
||||||
finalityBlocks: 1, |
name: Chains.test1, |
||||||
|
displayName: 'Test 1', |
||||||
|
nativeToken: etherToken, |
||||||
|
publicRpcUrls: [{ http: 'http://localhost:8545' }], |
||||||
|
blockExplorers: [], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 0, |
||||||
|
estimateBlockTime: 3, |
||||||
|
}, |
||||||
}; |
}; |
||||||
|
|
||||||
export const moonbeam: ChainMetadata = { |
export const test2: ChainMetadata = { |
||||||
id: 1284, |
id: 13372, |
||||||
finalityBlocks: 1, |
name: Chains.test2, |
||||||
|
displayName: 'Test 2', |
||||||
|
nativeToken: etherToken, |
||||||
|
publicRpcUrls: [{ http: 'http://localhost:8545' }], |
||||||
|
blockExplorers: [], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 1, |
||||||
|
estimateBlockTime: 3, |
||||||
|
}, |
||||||
}; |
}; |
||||||
|
|
||||||
|
export const test3: ChainMetadata = { |
||||||
|
id: 13373, |
||||||
|
name: Chains.test3, |
||||||
|
displayName: 'Test 3', |
||||||
|
nativeToken: etherToken, |
||||||
|
publicRpcUrls: [{ http: 'http://localhost:8545' }], |
||||||
|
blockExplorers: [], |
||||||
|
blocks: { |
||||||
|
confirmations: 1, |
||||||
|
reorgPeriod: 2, |
||||||
|
estimateBlockTime: 3, |
||||||
|
}, |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* Collection maps |
||||||
|
*/ |
||||||
export const chainMetadata = { |
export const chainMetadata = { |
||||||
|
alfajores, |
||||||
arbitrum, |
arbitrum, |
||||||
|
arbitrumgoerli, |
||||||
|
avalanche, |
||||||
bsc, |
bsc, |
||||||
|
bsctestnet, |
||||||
celo, |
celo, |
||||||
ethereum, |
ethereum, |
||||||
avalanche, |
|
||||||
optimism, |
|
||||||
polygon, |
|
||||||
alfajores, |
|
||||||
fuji, |
fuji, |
||||||
goerli, |
goerli, |
||||||
mumbai, |
|
||||||
bsctestnet, |
|
||||||
moonbasealpha, |
moonbasealpha, |
||||||
moonbeam, |
moonbeam, |
||||||
|
mumbai, |
||||||
|
optimism, |
||||||
optimismgoerli, |
optimismgoerli, |
||||||
arbitrumgoerli, |
polygon, |
||||||
zksync2testnet, |
test1, |
||||||
...testChains, |
test2, |
||||||
|
test3, |
||||||
} as Record<ChainName, ChainMetadata>; |
} as Record<ChainName, ChainMetadata>; |
||||||
|
|
||||||
|
// For convenient use in wagmi-based apps
|
||||||
|
export const wagmiChainMetadata: Record<ChainName, WagmiChain> = objMap( |
||||||
|
chainMetadata, |
||||||
|
(_, metadata) => ({ |
||||||
|
id: metadata.id, |
||||||
|
name: metadata.displayName, |
||||||
|
network: metadata.name as string, |
||||||
|
nativeCurrency: metadata.nativeToken, |
||||||
|
rpcUrls: { default: { http: [metadata.publicRpcUrls[0].http] } }, |
||||||
|
blockExplorers: metadata.blockExplorers.length |
||||||
|
? { |
||||||
|
default: { |
||||||
|
name: metadata.blockExplorers[0].name, |
||||||
|
url: metadata.blockExplorers[0].url, |
||||||
|
}, |
||||||
|
} |
||||||
|
: undefined, |
||||||
|
testnet: Testnets.includes(metadata.name), |
||||||
|
}), |
||||||
|
); |
||||||
|
|
||||||
|
export const chainIdToMetadata = Object.values(chainMetadata).reduce< |
||||||
|
Record<number, ChainMetadata> |
||||||
|
>((result, chain) => { |
||||||
|
result[chain.id] = chain; |
||||||
|
return result; |
||||||
|
}, {}); |
||||||
|
|
||||||
|
export const mainnetChainsMetadata: Array<ChainMetadata> = Mainnets.map( |
||||||
|
(chainName) => chainMetadata[chainName], |
||||||
|
); |
||||||
|
export const testnetChainsMetadata: Array<ChainMetadata> = Testnets.map( |
||||||
|
(chainName) => chainMetadata[chainName], |
||||||
|
); |
||||||
|
|
||||||
|
/** |
||||||
|
* @deprecated use ChainMetadata |
||||||
|
*/ |
||||||
|
export type PartialChainMetadata = { |
||||||
|
id: number; |
||||||
|
finalityBlocks: number; |
||||||
|
nativeTokenDecimals?: number; |
||||||
|
paginate?: RpcPagination; |
||||||
|
// The CoinGecko API expects, in some cases, IDs that do not match
|
||||||
|
// ChainNames.
|
||||||
|
gasCurrencyCoinGeckoId?: string; |
||||||
|
// URL of the gnosis safe transaction service.
|
||||||
|
gnosisSafeTransactionServiceUrl?: string; |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* @deprecated use chainMetadata |
||||||
|
*/ |
||||||
|
export const partialChainMetadata: Record<ChainName, PartialChainMetadata> = |
||||||
|
objMap(chainMetadata, (_, metadata) => ({ |
||||||
|
id: metadata.id, |
||||||
|
finalityBlocks: metadata.blocks.confirmations, |
||||||
|
nativeTokenDecimals: metadata.nativeToken.decimals, |
||||||
|
paginate: metadata.publicRpcUrls[0]?.pagination, |
||||||
|
gasCurrencyCoinGeckoId: metadata.gasCurrencyCoinGeckoId, |
||||||
|
gnosisSafeTransactionServiceUrl: metadata.gnosisSafeTransactionServiceUrl, |
||||||
|
})); |
||||||
|
@ -1,46 +0,0 @@ |
|||||||
export type MetamaskNetwork = { |
|
||||||
chainId: string; |
|
||||||
chainName: string; |
|
||||||
nativeCurrency: { name: string; symbol: string; decimals: number }; |
|
||||||
rpcUrls: string[]; |
|
||||||
blockExplorerUrls: string[]; |
|
||||||
iconUrls: string[]; |
|
||||||
}; |
|
||||||
|
|
||||||
export const CELO_PARAMS: MetamaskNetwork = { |
|
||||||
chainId: '0xa4ec', |
|
||||||
chainName: 'Celo', |
|
||||||
nativeCurrency: { name: 'Celo', symbol: 'CELO', decimals: 18 }, |
|
||||||
rpcUrls: ['https://forno.celo.org'], |
|
||||||
blockExplorerUrls: ['https://explorer.celo.org/'], |
|
||||||
iconUrls: ['future'], |
|
||||||
}; |
|
||||||
|
|
||||||
export const ALFAJORES_PARAMS: MetamaskNetwork = { |
|
||||||
chainId: '0xaef3', |
|
||||||
chainName: 'Alfajores Testnet', |
|
||||||
nativeCurrency: { name: 'Alfajores Celo', symbol: 'A-CELO', decimals: 18 }, |
|
||||||
rpcUrls: ['https://alfajores-forno.celo-testnet.org'], |
|
||||||
blockExplorerUrls: ['https://alfajores-blockscout.celo-testnet.org/'], |
|
||||||
iconUrls: ['future'], |
|
||||||
}; |
|
||||||
|
|
||||||
export const BAKLAVA_PARAMS: MetamaskNetwork = { |
|
||||||
chainId: '0xf370', |
|
||||||
chainName: 'Baklava Testnet', |
|
||||||
nativeCurrency: { name: 'Baklava Celo', symbol: 'B-CELO', decimals: 18 }, |
|
||||||
rpcUrls: ['https://baklava-forno.celo-testnet.org'], |
|
||||||
blockExplorerUrls: ['https://baklava-blockscout.celo-testnet.org/'], |
|
||||||
iconUrls: ['future'], |
|
||||||
}; |
|
||||||
|
|
||||||
export async function connect(params: MetamaskNetwork): Promise<void> { |
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
const w = window as any; |
|
||||||
if (w.ethereum) { |
|
||||||
await w.ethereum.request({ |
|
||||||
method: 'wallet_addEthereumChain', |
|
||||||
params: [params], |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue