-
Notifications
You must be signed in to change notification settings - Fork 66
chore: remap chains #821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
chore: remap chains #821
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@gobob/bob-sdk", | ||
| "version": "4.3.8", | ||
| "version": "4.3.9", | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "scripts": { | ||
|
|
@@ -51,6 +51,7 @@ | |
| "bitcoin-address-validation": "^3.0.0", | ||
| "bitcoinjs-lib": "^6.1.7", | ||
| "global": "^4.4.0", | ||
| "viem": "^2.33.2" | ||
| } | ||
| "viem": "^2.38.3" | ||
| }, | ||
| "packageManager": "[email protected]+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39" | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import * as bitcoin from 'bitcoinjs-lib'; | |||||
| import { | ||||||
| Address, | ||||||
| createPublicClient, | ||||||
| defineChain, | ||||||
| encodeAbiParameters, | ||||||
| formatUnits, | ||||||
| Hex, | ||||||
|
|
@@ -138,31 +139,59 @@ export function formatBtc(btc: bigint) { | |||||
| return formatUnits(btc, 8); | ||||||
| } | ||||||
|
|
||||||
| const supportedChains = [ | ||||||
| const supportedChainsMapping = { | ||||||
| bob, | ||||||
| mainnet, | ||||||
| sonic, | ||||||
| ethereum: defineChain({ | ||||||
| ...mainnet, | ||||||
| rpcUrls: { | ||||||
| default: { | ||||||
| http: ['https://ethereum-rpc.publicnode.com'], | ||||||
| }, | ||||||
| }, | ||||||
| }), | ||||||
| sonic: defineChain({ | ||||||
| ...sonic, | ||||||
| rpcUrls: { | ||||||
| default: { | ||||||
| http: ['https://sonic.drpc.org'], | ||||||
| }, | ||||||
| }, | ||||||
| }), | ||||||
| bsc, | ||||||
| unichain, | ||||||
| berachain, | ||||||
| sei, | ||||||
| bera: berachain, | ||||||
| sei: defineChain({ | ||||||
| ...sei, | ||||||
| rpcUrls: { | ||||||
| default: { | ||||||
| http: ['https://sei.drpc.org'], | ||||||
| }, | ||||||
| }, | ||||||
| }), | ||||||
| avalanche, | ||||||
| base, | ||||||
| soneium, | ||||||
| optimism, | ||||||
| ] as const; | ||||||
| optimism: defineChain({ | ||||||
| ...optimism, | ||||||
| rpcUrls: { | ||||||
| default: { | ||||||
| http: ['https://optimism.drpc.org'], | ||||||
| }, | ||||||
| }, | ||||||
| }), | ||||||
| } as const; | ||||||
|
|
||||||
| const chainIdToChainConfigMapping = supportedChains.reduce( | ||||||
| const chainIdToChainConfigMapping = Object.values(supportedChainsMapping).reduce( | ||||||
| (acc, chain) => { | ||||||
| acc[chain.id] = chain; | ||||||
| return acc; | ||||||
| }, | ||||||
| {} as Record<ViemChain['id'], ViemChain> | ||||||
| ); | ||||||
|
|
||||||
| const chainNameToChainIdMapping = supportedChains.reduce( | ||||||
| (acc, chain) => { | ||||||
| acc[chain.name.toLowerCase()] = chain.id; | ||||||
| const chainNameToChainIdMapping = Object.entries(supportedChainsMapping).reduce( | ||||||
| (acc, [name, chain]) => { | ||||||
| acc[name.toLowerCase()] = chain.id; | ||||||
| return acc; | ||||||
| }, | ||||||
| {} as Record<ViemChain['name'], ViemChain['id']> | ||||||
|
|
@@ -172,7 +201,7 @@ function getChainIdByName(chainName: string) { | |||||
| const chainId = chainNameToChainIdMapping[chainName.toLowerCase()]; | ||||||
| if (!chainId) { | ||||||
| throw new Error( | ||||||
| `Chain id for "${chainName}" not found. Allowed values ${supportedChains.map((chain) => chain.name)}` | ||||||
| `Chain id for "${chainName}" not found. Allowed values ${Object.keys(supportedChainsMapping).map((chainName) => chainName.toLocaleLowerCase())}` | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The keys of
Suggested change
|
||||||
| ); | ||||||
| } | ||||||
| return chainId; | ||||||
|
|
@@ -182,7 +211,7 @@ function getChainConfigById(chainId: number) { | |||||
| const config = chainIdToChainConfigMapping[chainId]; | ||||||
| if (!config) { | ||||||
| throw new Error( | ||||||
| `Chain id for "${chainId}" not found. Allowed values ${supportedChains.map((chain) => chain.id)}` | ||||||
| `Chain id for "${chainId}" not found. Allowed values ${Object.values(supportedChainsMapping).map((chain) => chain.id)}` | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keys of
supportedChainsMappingare already in lowercase, so the call to.toLowerCase()on thenameis redundant. You can simplify this by usingnamedirectly. Additionally, the type assertion can be made more accurate to reflect that the keys are strings, not necessarilyViemChain['name'].