-
Notifications
You must be signed in to change notification settings - Fork 55
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
viem/chains: chain exports for the superchain registry #615
Conversation
✅ Deploy Preview for storybook-component-library canceled.
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
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.
nice job!
) | ||
const entries = fs | ||
.readdirSync(configPath) | ||
.filter((entry) => !entry.includes('superchain')) |
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.
just curious, why is this needed? might be good to add a comment here
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.
every network dir within the config/<network>
has a superchain.toml
file. This file has the L1 superchain config for that nework
def worth a comment
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.
It looks like the identifier keeps the same filepath structure within config
. I'm going to leave it as it is right now but we can adjust later.
const chainConfig = toml.parse( | ||
fs.readFileSync(`${configPath}/${entry}`, 'utf8'), | ||
) |
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.
nit: you could add a type here for the result of toml.parse so you can avoid having to cast the types each time you access something inside chainConfig
const normalizedName = entry | ||
.replace('.toml', '') | ||
.replace('-testnet', '') |
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.
if you dont want to rely on the file name for this, there is also the identifier
field on chainList.json: https://github.com/ethereum-optimism/superchain-registry/blob/e2d3490729b20a649281899c2c286e6e12db57f3/chainList.json#L59. That could potentially be more stable.
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.
ahh yea this is a good callout. Need to be able to map this identifier to the filename in order to parse the address list
Description
viem/chains
Generated chains follow the format
export const <name><network>
. i.eopMainnet
orbaseSepolia
. If an app wants to add all chains,export const mainnetChains
andexport const sepoliaChains
is a list of all the respective chainsTests
N/A. But I'm thinking of adding tests to make sure the addresses match up with the ones specified in the
SystemConfig
for each network against the public rpc. However it's a safe property/assumption that the registry should already ensure that these are correctMetadata