#ethereum #optimism #crypto

no-std superchain-registry

The Superchain Registry

17 releases (5 breaking)

new 0.11.0 Nov 7, 2024
0.4.0 Sep 7, 2024
0.2.2 Jul 23, 2024

#786 in Magic Beans

Download history 453/week @ 2024-07-22 173/week @ 2024-07-29 185/week @ 2024-08-05 241/week @ 2024-08-12 857/week @ 2024-08-19 679/week @ 2024-08-26 963/week @ 2024-09-02 362/week @ 2024-09-09 101/week @ 2024-09-16 40/week @ 2024-09-23 121/week @ 2024-09-30 14/week @ 2024-10-07 123/week @ 2024-11-04

124 downloads per month
Used in 2 crates

MIT license

115KB
285 lines

Superchain

Rust bindings for the superchain-registry.

CI License Superchain Crate OP Stack Codecov

What's Superchain?UsageFeature FlagsCredits

What's Superchain?

The Superchain is a network of chains that share bridging, decentralized governance, upgrades, a communication layer and more.

Chain configurations for the Superchain are defined in the superchain directory. This repository provides rust bindings for the ethereum-optimism/superchain-registry.

Interface with the rust bindings through superchain, an optionally no_std crate that binds to the ethereum-optimism/superchain-registry at compile-time.

superchain

superchain is a no_std crate that exports rust type definitions for chains in the superchain-registry. Since it reads static files to read configurations for various chains into instantiated objects, the superchain crate requires serde as a dependency. To use the superchain crate, add the crate as a dependency to a Cargo.toml.

superchain-registry = "0.9"

superchain declares lazy evaluated statics that expose ChainConfigs, RollupConfigs, and Chain objects for all chains with static definitions in the superchain registry. The way this works is the the golang side of the superchain registry contains an "internal code generation" script that has been modified to output configuration files to the crates/superchain directory in the etc folder that are read by the superchain rust crate. These static config files contain an up-to-date list of all superchain configurations with their chain configs.

There are three core statics exposed by the superchain.

  • CHAINS: A list of chain objects containing the superchain metadata for this chain.
  • OPCHAINS: A map from chain id to ChainConfig.
  • ROLLUP_CONFIGS: A map from chain id to RollupConfig.

While the op-alloy-genesis crate contains a few hardcoded RollupConfig objects, the superchain exports the complete list of superchains and their chain's RollupConfigs and ChainConfigs.

CHAINS, OPCHAINS, and ROLLUP_CONFIGS are exported at the top-level of the superchain crate and can be used directly. See the usage section below for how to work with superchain mappings.

Usage

Add the following to your Cargo.toml.

[dependencies]
superchain-registry = "0.9"

To make superchain no_std, toggle default-features off like so.

[dependencies]
superchain-registry = { version = "0.9", default-features = false }

Below demonstrates getting the RollupConfig for OP Mainnet (Chain ID 10).

use superchain_registry::ROLLUP_CONFIGS;

let op_chain_id = 10;
let op_rollup_config = ROLLUP_CONFIGS.get(&op_chain_id);
println!("OP Mainnet Rollup Config: {:?}", op_rollup_config);

A mapping from chain id to ChainConfig is also available.

use superchain_registry::OPCHAINS;

let op_chain_id = 10;
let op_chain_config = OPCHAINS.get(&op_chain_id);
println!("OP Mainnet Chain Config: {:?}", op_chain_config);

Feature Flags

  • std: Uses the standard library to pull in environment variables.

Credits

superchain-registry contributors for building and maintaining superchain types.

alloy and op-alloy for creating and maintaining high quality Ethereum and Optimism types in rust.

Dependencies

~14MB
~323K SLoC