Skip to content

Commit fd9fceb

Browse files
committed
fix base chain support
1 parent 41b403a commit fd9fceb

File tree

3 files changed

+45
-54
lines changed

3 files changed

+45
-54
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"@web3-onboard/walletconnect": "^2.5.5",
2525
"ethers": "^6.12.1",
2626
"react": "^18.3.1",
27-
"react-dom": "^18.3.1"
27+
"react-dom": "^18.3.1",
28+
"ts-pattern": "^5.2.0"
2829
},
2930
"devDependencies": {
3031
"@typechain/ethers-v6": "^0.5.1",

src/helpers/constants.ts

Lines changed: 38 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,54 @@
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+
111
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();
1216
}
1317

1418
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();
2727
}
2828

2929
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();
4034
}
4135

4236
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();
5545
}
5646

5747
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();
6752
}
6853

6954
export type EIP712Domain = {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5982,6 +5982,11 @@ ts-essentials@^7.0.1:
59825982
resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-7.0.3.tgz#686fd155a02133eedcc5362dc8b5056cde3e5a38"
59835983
integrity sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ==
59845984

5985+
ts-pattern@^5.2.0:
5986+
version "5.2.0"
5987+
resolved "https://registry.yarnpkg.com/ts-pattern/-/ts-pattern-5.2.0.tgz#2cad8b58fcd87c52d1785f84eba572641e1bb5f3"
5988+
integrity sha512-aGaSpOlDcns7ZoeG/OMftWyQG1KqPVhgplhJxNCvyIXqWrumM5uIoOSarw/hmmi/T1PnuQ/uD8NaFHvLpHicDg==
5989+
59855990
tsconfig-paths@^3.15.0:
59865991
version "3.15.0"
59875992
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz#5299ec605e55b1abb23ec939ef15edaf483070d4"

0 commit comments

Comments
 (0)