Skip to content

Commit

Permalink
fix base chain support
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarnadas committed Jun 13, 2024
1 parent 41b403a commit fd9fceb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 54 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"@web3-onboard/walletconnect": "^2.5.5",
"ethers": "^6.12.1",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"ts-pattern": "^5.2.0"
},
"devDependencies": {
"@typechain/ethers-v6": "^0.5.1",
Expand Down
91 changes: 38 additions & 53 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,54 @@
import { match } from 'ts-pattern';

type SupportedChainIds =
| '0xa4b1' // arbitrum
| '0xa' // optimism
| '0x2105' // base
| '0x66eee' // arbitrum sepolia
| '0xaa37dc' // optimism sepolia
| '0x14a34'; // base sepolia

export function isTestnet(chainId: string): boolean {
switch (chainId) {
case '0xa4b1':
case '0xa':
return false;
case '0x66eee':
case '0xaa37dc':
return true;
default:
return false;
}
return match(chainId as SupportedChainIds)
.with('0xa4b1', '0xa', '0x2105', () => false)
.with('0x66eee', '0xaa37dc', '0x14a34', () => true)
.exhaustive();
}

export function getVaultAddress(chainId: string): string {
switch (chainId) {
case '0xa4b1':
return '0x816f722424B49Cf1275cc86DA9840Fbd5a6167e9';
case '0xa':
return '0x816f722424b49cf1275cc86da9840fbd5a6167e9';
case '0x66eee':
return '0x0EaC556c0C2321BA25b9DC01e4e3c95aD5CDCd2f';
case '0xaa37dc':
return '0xEfF2896077B6ff95379EfA89Ff903598190805EC';
default:
throw new Error('chain ID unsupported');
}
return match(chainId as SupportedChainIds)
.with('0xa4b1', () => '0x816f722424B49Cf1275cc86DA9840Fbd5a6167e9')
.with('0xa', () => '0x816f722424b49cf1275cc86da9840fbd5a6167e9')
.with('0x2105', () => '0x816f722424b49cf1275cc86da9840fbd5a6167e9')
.with('0x66eee', () => '0x0EaC556c0C2321BA25b9DC01e4e3c95aD5CDCd2f')
.with('0xaa37dc', () => '0xEfF2896077B6ff95379EfA89Ff903598190805EC')
.with('0x14a34', () => '0xdc7348975aE9334DbdcB944DDa9163Ba8406a0ec')
.exhaustive();
}

export function getVerifyingAddress(chainId: string): string {
switch (chainId) {
case '0xa4b1':
case '0xa':
return '0x6F7a338F2aA472838dEFD3283eB360d4Dff5D203';
case '0x66eee':
case '0xaa37dc':
return '0x1826B75e2ef249173FC735149AE4B8e9ea10abff';
default:
throw new Error('chain ID unsupported');
}
return match(isTestnet(chainId))
.with(false, () => '0x6F7a338F2aA472838dEFD3283eB360d4Dff5D203')
.with(true, () => '0x1826B75e2ef249173FC735149AE4B8e9ea10abff')
.exhaustive();
}

export function getUSDCAddress(chainId: string): string {
switch (chainId) {
case '0xa4b1':
return '0xaf88d065e77c8cC2239327C5EDb3A432268e5831';
case '0xa':
return '0x816f722424b49cf1275cc86da9840fbd5a6167e9';
case '0x66eee':
return '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d';
case '0xaa37dc':
return '0x5fd84259d66Cd46123540766Be93DFE6D43130D7';
default:
throw new Error('chain ID unsupported');
}
return match(chainId as SupportedChainIds)
.with('0xa4b1', () => '0xaf88d065e77c8cC2239327C5EDb3A432268e5831')
.with('0xa', () => '0x0b2c639c533813f4aa9d7837caf62653d097ff85')
.with('0x2105', () => '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913')
.with('0x66eee', () => '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d')
.with('0xaa37dc', () => '0x5fd84259d66Cd46123540766Be93DFE6D43130D7')
.with('0x14a34', () => '0x036CbD53842c5426634e7929541eC2318f3dCF7e')
.exhaustive();
}

export function getBaseUrl(chainId: string): string {
switch (chainId) {
case '0xa4b1':
case '0xa':
return 'https://api-evm.orderly.org';
case '0x66eee':
case '0xaa37dc':
default:
return 'https://testnet-api-evm.orderly.org';
}
return match(isTestnet(chainId))
.with(false, () => 'https://api-evm.orderly.org')
.with(true, () => 'https://testnet-api-evm.orderly.org')
.exhaustive();
}

export type EIP712Domain = {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5982,6 +5982,11 @@ ts-essentials@^7.0.1:
resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-7.0.3.tgz#686fd155a02133eedcc5362dc8b5056cde3e5a38"
integrity sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ==

ts-pattern@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/ts-pattern/-/ts-pattern-5.2.0.tgz#2cad8b58fcd87c52d1785f84eba572641e1bb5f3"
integrity sha512-aGaSpOlDcns7ZoeG/OMftWyQG1KqPVhgplhJxNCvyIXqWrumM5uIoOSarw/hmmi/T1PnuQ/uD8NaFHvLpHicDg==

tsconfig-paths@^3.15.0:
version "3.15.0"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz#5299ec605e55b1abb23ec939ef15edaf483070d4"
Expand Down

0 comments on commit fd9fceb

Please sign in to comment.