|
| 1 | +import { match } from 'ts-pattern'; |
| 2 | + |
| 3 | +type SupportedChainIds = |
| 4 | + | '0xa4b1' // arbitrum |
| 5 | + | '0xa' // optimism |
| 6 | + | '0x2105' // base |
| 7 | + | '0x66eee' // arbitrum sepolia |
| 8 | + | '0xaa37dc' // optimism sepolia |
| 9 | + | '0x14a34'; // base sepolia |
| 10 | + |
1 | 11 | export function isTestnet(chainId: string): boolean {
|
2 |
| - switch (chainId) { |
3 |
| - case '0xa4b1': |
4 |
| - case '0xa': |
5 |
| - return false; |
6 |
| - case '0x66eee': |
7 |
| - case '0xaa37dc': |
8 |
| - return true; |
9 |
| - default: |
10 |
| - return false; |
11 |
| - } |
| 12 | + return match(chainId as SupportedChainIds) |
| 13 | + .with('0xa4b1', '0xa', '0x2105', () => false) |
| 14 | + .with('0x66eee', '0xaa37dc', '0x14a34', () => true) |
| 15 | + .exhaustive(); |
12 | 16 | }
|
13 | 17 |
|
14 | 18 | export function getVaultAddress(chainId: string): string {
|
15 |
| - switch (chainId) { |
16 |
| - case '0xa4b1': |
17 |
| - return '0x816f722424B49Cf1275cc86DA9840Fbd5a6167e9'; |
18 |
| - case '0xa': |
19 |
| - return '0x816f722424b49cf1275cc86da9840fbd5a6167e9'; |
20 |
| - case '0x66eee': |
21 |
| - return '0x0EaC556c0C2321BA25b9DC01e4e3c95aD5CDCd2f'; |
22 |
| - case '0xaa37dc': |
23 |
| - return '0xEfF2896077B6ff95379EfA89Ff903598190805EC'; |
24 |
| - default: |
25 |
| - throw new Error('chain ID unsupported'); |
26 |
| - } |
| 19 | + return match(chainId as SupportedChainIds) |
| 20 | + .with('0xa4b1', () => '0x816f722424B49Cf1275cc86DA9840Fbd5a6167e9') |
| 21 | + .with('0xa', () => '0x816f722424b49cf1275cc86da9840fbd5a6167e9') |
| 22 | + .with('0x2105', () => '0x816f722424b49cf1275cc86da9840fbd5a6167e9') |
| 23 | + .with('0x66eee', () => '0x0EaC556c0C2321BA25b9DC01e4e3c95aD5CDCd2f') |
| 24 | + .with('0xaa37dc', () => '0xEfF2896077B6ff95379EfA89Ff903598190805EC') |
| 25 | + .with('0x14a34', () => '0xdc7348975aE9334DbdcB944DDa9163Ba8406a0ec') |
| 26 | + .exhaustive(); |
27 | 27 | }
|
28 | 28 |
|
29 | 29 | export function getVerifyingAddress(chainId: string): string {
|
30 |
| - switch (chainId) { |
31 |
| - case '0xa4b1': |
32 |
| - case '0xa': |
33 |
| - return '0x6F7a338F2aA472838dEFD3283eB360d4Dff5D203'; |
34 |
| - case '0x66eee': |
35 |
| - case '0xaa37dc': |
36 |
| - return '0x1826B75e2ef249173FC735149AE4B8e9ea10abff'; |
37 |
| - default: |
38 |
| - throw new Error('chain ID unsupported'); |
39 |
| - } |
| 30 | + return match(isTestnet(chainId)) |
| 31 | + .with(false, () => '0x6F7a338F2aA472838dEFD3283eB360d4Dff5D203') |
| 32 | + .with(true, () => '0x1826B75e2ef249173FC735149AE4B8e9ea10abff') |
| 33 | + .exhaustive(); |
40 | 34 | }
|
41 | 35 |
|
42 | 36 | export function getUSDCAddress(chainId: string): string {
|
43 |
| - switch (chainId) { |
44 |
| - case '0xa4b1': |
45 |
| - return '0xaf88d065e77c8cC2239327C5EDb3A432268e5831'; |
46 |
| - case '0xa': |
47 |
| - return '0x816f722424b49cf1275cc86da9840fbd5a6167e9'; |
48 |
| - case '0x66eee': |
49 |
| - return '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d'; |
50 |
| - case '0xaa37dc': |
51 |
| - return '0x5fd84259d66Cd46123540766Be93DFE6D43130D7'; |
52 |
| - default: |
53 |
| - throw new Error('chain ID unsupported'); |
54 |
| - } |
| 37 | + return match(chainId as SupportedChainIds) |
| 38 | + .with('0xa4b1', () => '0xaf88d065e77c8cC2239327C5EDb3A432268e5831') |
| 39 | + .with('0xa', () => '0x0b2c639c533813f4aa9d7837caf62653d097ff85') |
| 40 | + .with('0x2105', () => '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913') |
| 41 | + .with('0x66eee', () => '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d') |
| 42 | + .with('0xaa37dc', () => '0x5fd84259d66Cd46123540766Be93DFE6D43130D7') |
| 43 | + .with('0x14a34', () => '0x036CbD53842c5426634e7929541eC2318f3dCF7e') |
| 44 | + .exhaustive(); |
55 | 45 | }
|
56 | 46 |
|
57 | 47 | export function getBaseUrl(chainId: string): string {
|
58 |
| - switch (chainId) { |
59 |
| - case '0xa4b1': |
60 |
| - case '0xa': |
61 |
| - return 'https://api-evm.orderly.org'; |
62 |
| - case '0x66eee': |
63 |
| - case '0xaa37dc': |
64 |
| - default: |
65 |
| - return 'https://testnet-api-evm.orderly.org'; |
66 |
| - } |
| 48 | + return match(isTestnet(chainId)) |
| 49 | + .with(false, () => 'https://api-evm.orderly.org') |
| 50 | + .with(true, () => 'https://testnet-api-evm.orderly.org') |
| 51 | + .exhaustive(); |
67 | 52 | }
|
68 | 53 |
|
69 | 54 | export type EIP712Domain = {
|
|
0 commit comments