Skip to content

Commit e536735

Browse files
committed
feat: add Mode networks
1 parent 2813b50 commit e536735

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/routes/contract/controller.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import {
1414
toEventSelector,
1515
toFunctionSelector,
1616
} from 'viem';
17+
import { mode, modeTestnet } from 'viem/chains';
1718

1819
import EtherscanService from '@/services/etherscan';
1920
import MinioService, { type ContractSource } from '@/services/minio';
20-
import { ChainId, getChainData } from '@/utils/chains';
21+
import { ChainId, getChainData, MODE, MODE_SEPOLIA } from '@/utils/chains';
2122
import { Deployment, SourceCode } from '@/utils/contracts';
2223
import { toErrorSelector } from '@/utils/evm';
2324
import { getImplementation } from '@/utils/proxy';
@@ -71,7 +72,17 @@ type Abis = Record<
7172
>;
7273

7374
function getClient(chain: ChainId, alchemyKey: string): PublicClient {
74-
const endpointUrl = alchemy(chain, alchemyKey);
75+
function getEndpointUrl(chain: ChainId): string {
76+
if (chain === MODE) {
77+
return mode.rpcUrls.default.http[0];
78+
}
79+
if (chain === MODE_SEPOLIA) {
80+
return modeTestnet.rpcUrls.default.http[0];
81+
}
82+
return alchemy(chain, alchemyKey);
83+
}
84+
85+
const endpointUrl = getEndpointUrl(chain);
7586
return createPublicClient({
7687
chain: getChainData(chain),
7788
transport: http(endpointUrl),

src/routes/label/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
POLYGON,
1313
POLYGON_AMOY,
1414
SEPOLIA,
15+
MODE,
16+
MODE_SEPOLIA,
1517
} from '@/utils/chains';
1618
import {
1719
LabelType,
@@ -167,6 +169,10 @@ function getErc20Icon(chain: ChainId, address: string): string | undefined {
167169
return 'polygon';
168170
case POLYGON_AMOY:
169171
return null;
172+
case MODE:
173+
return null;
174+
case MODE_SEPOLIA:
175+
return null;
170176
}
171177
}
172178
const chainName = getChainName(chain);

src/utils/chains.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
polygonAmoy,
1111
arbitrum,
1212
arbitrumSepolia,
13+
mode,
14+
modeTestnet,
1315
} from 'viem/chains';
1416
import { z } from 'zod';
1517

@@ -23,6 +25,8 @@ const BASE = base.id;
2325
const BASE_SEPOLIA = baseSepolia.id;
2426
const ARBITRUM = arbitrum.id;
2527
const ARBITRUM_SEPOLIA = arbitrumSepolia.id;
28+
const MODE = mode.id;
29+
const MODE_SEPOLIA = modeTestnet.id;
2630

2731
const CHAINS: ChainId[] = [
2832
ETHEREUM,
@@ -35,6 +39,8 @@ const CHAINS: ChainId[] = [
3539
BASE_SEPOLIA,
3640
ARBITRUM,
3741
ARBITRUM_SEPOLIA,
42+
MODE,
43+
MODE_SEPOLIA,
3844
];
3945

4046
const chainSchema = z.union([
@@ -49,6 +55,8 @@ const chainSchema = z.union([
4955
z.literal(POLYGON_AMOY.toString()),
5056
z.literal(ARBITRUM.toString()),
5157
z.literal(ARBITRUM_SEPOLIA.toString()),
58+
z.literal(MODE.toString()),
59+
z.literal(MODE_SEPOLIA.toString()),
5260
]);
5361

5462
type ChainId =
@@ -61,7 +69,9 @@ type ChainId =
6169
| typeof BASE
6270
| typeof BASE_SEPOLIA
6371
| typeof ARBITRUM
64-
| typeof ARBITRUM_SEPOLIA;
72+
| typeof ARBITRUM_SEPOLIA
73+
| typeof MODE
74+
| typeof MODE_SEPOLIA;
6575

6676
function getChainData(chain: ChainId): ChainData {
6777
switch (chain) {
@@ -85,6 +95,10 @@ function getChainData(chain: ChainId): ChainData {
8595
return arbitrum;
8696
case ARBITRUM_SEPOLIA:
8797
return arbitrumSepolia;
98+
case MODE:
99+
return mode;
100+
case MODE_SEPOLIA:
101+
return modeTestnet;
88102
}
89103
}
90104

@@ -104,6 +118,8 @@ export {
104118
BASE_SEPOLIA,
105119
ARBITRUM,
106120
ARBITRUM_SEPOLIA,
121+
MODE,
122+
MODE_SEPOLIA,
107123
getChainData,
108124
parseChainId,
109125
chainSchema,

0 commit comments

Comments
 (0)