📄 src/web3/network/chains.ts
D-OPEN SOVEREIGN
1// @ts-ignore
2import coreDaoLogo from './media/core-dao-core-logo.svg';
3import { defineChain, type Chain } from 'viem';
4
5export type ChainPrice =
6 | { stable: true }
7 | { stable?: false; pythOracle: string; usdPriceId: string };
8
9export interface EvmChainConfig {
10 chainId: number;
11 name: string;
12 symbol: string;
13 shortName: string;
14 decimals: number;
15 explorer: string;
16 rpc: string;
17 website: string;
18 main: boolean;
19 logo: string;
20 price: ChainPrice;
21 addresses?: {
22 addressRegistry?: string;
23 stagingAddressRegistry?: string;
24 [contract: string]: string | undefined;
25 };
26 deployed?: boolean;
27 stagingDeployed?: boolean;
28}
29
30export const EVM_CHAINS: Record<number, EvmChainConfig> = {
31 1116: {
32 chainId: 1116,
33 name: 'Core Blockchain MainNet',
34 symbol: 'CORE',
35 shortName: 'TREE',
36 decimals: 18,
37 explorer: 'https://scan.coredao.org',
38 rpc: 'https://rpc.coredao.org',
39 website: 'https://coredao.org/',
40 main: true,
41 logo: coreDaoLogo,
42 price: {
43 pythOracle: '0xA2aa501b19aff244D90cc15a4Cf739D2725B5729',
44 usdPriceId: '0x9b4503710cc8c53f75c30e6e4fda1a7064680ef2e0ee97acd2e3a7c37b3c830c',
45 },
46 deployed: true,
47 addresses: {
48 addressRegistry: '0x4c1759dF25AdddbdF5399D332Ac02B2E77ED90fF'
49 },
50 },
51 1114: {
52 chainId: 1114,
53 name: 'Core Blockchain TestNet',
54 symbol: 'tCORE2',
55 shortName: 'SUN',
56 decimals: 18,
57 explorer: 'https://scan.test2.btcs.network',
58 rpc: 'https://rpc.test2.btcs.network',
59 website: 'https://coredao.org/',
60 main: false,
61 logo: coreDaoLogo,
62 price: {
63 pythOracle: '0x8D254a21b3C86D32F7179855531CE99164721933',
64 usdPriceId: '0x9b4503710cc8c53f75c30e6e4fda1a7064680ef2e0ee97acd2e3a7c37b3c830c',
65 },
66 stagingDeployed: true,
67 addresses: {
68 stagingAddressRegistry: '0x4AB2FF5fAd69eFe62e7Fce1f06FeE5cfFBC31469'
69 },
70 },
71};
72
73export const DEFAULT_CHAIN_ID = 1116;
74
75export function getChain(chainId: number | string): EvmChainConfig {
76 const id = typeof chainId === 'string' ? parseInt(chainId, 10) : chainId;
77 const chain = EVM_CHAINS[id];
78 if (!chain) throw new Error(`Chain ${chainId} not configured`);
79 return chain;
80}
81
82// Shared viem Chain construction — was duplicated five times across EvmClient,
83// MetaMaskConnector, and PrivateKeyConnector before consolidation made it easy
84// to see and collapse.
85export function toViemChain(config: EvmChainConfig): Chain {
86 return defineChain({
87 id: config.chainId,
88 name: config.name,
89 nativeCurrency: { name: config.symbol, symbol: config.symbol, decimals: config.decimals || 18 },
90 rpcUrls: { default: { http: [config.rpc] }, public: { http: [config.rpc] } },
91 });
92}
93