Skip to content
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

Merged
merged 11 commits into from
Jan 16, 2025

Conversation

hamdiallam
Copy link
Contributor

@hamdiallam hamdiallam commented Jan 14, 2025

Description

  1. Introduce submodule dependency on the https://github.com/ethereum-optimism/superchain-registry
  2. Add script to generate chains from the submodule. Exported under viem/chains

Generated chains follow the format export const <name><network>. i.e opMainnet or baseSepolia. If an app wants to add all chains, export const mainnetChains and export const sepoliaChains is a list of all the respective chains

Tests

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 correct

Metadata

@hamdiallam hamdiallam requested a review from a team as a code owner January 14, 2025 22:28
Copy link

netlify bot commented Jan 14, 2025

Deploy Preview for storybook-component-library canceled.

Name Link
🔨 Latest commit 2845047
🔍 Latest deploy log https://app.netlify.com/sites/storybook-component-library/deploys/6789951d72d879000839a1f8

Copy link
Contributor Author

hamdiallam commented Jan 16, 2025

Copy link
Contributor

@tremarkley tremarkley left a 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'))
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

@hamdiallam hamdiallam Jan 16, 2025

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.

Comment on lines +102 to +104
const chainConfig = toml.parse(
fs.readFileSync(`${configPath}/${entry}`, 'utf8'),
)
Copy link
Contributor

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

Comment on lines +125 to +127
const normalizedName = entry
.replace('.toml', '')
.replace('-testnet', '')
Copy link
Contributor

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.

Copy link
Contributor Author

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

@hamdiallam hamdiallam merged commit d07cb41 into main Jan 16, 2025
10 checks passed
@hamdiallam hamdiallam deleted the superchain_registry_bindings branch January 16, 2025 23:28
@github-actions github-actions bot mentioned this pull request Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

automatic viem chain definitions for all members in the registry
3 participants