From 4000fc74e4a196893bf38c66479b17f119debe7d Mon Sep 17 00:00:00 2001 From: refcell Date: Mon, 4 Nov 2024 11:36:35 -0500 Subject: [PATCH 1/2] chore(book): Load a rollup config --- book/src/examples/README.md | 2 +- .../genesis/loading-a-rollup-config.md | 0 book/src/examples/load-a-rollup-config.md | 34 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) delete mode 100644 book/src/examples/genesis/loading-a-rollup-config.md create mode 100644 book/src/examples/load-a-rollup-config.md diff --git a/book/src/examples/README.md b/book/src/examples/README.md index e22c0162..b7da6dd0 100644 --- a/book/src/examples/README.md +++ b/book/src/examples/README.md @@ -2,4 +2,4 @@ Examples for working with `op-alloy-*` crates. -TODO: document `op-alloy` crate use and using it with re-exports. +- [Load a Rollup Config for a Chain ID](./load-a-rollup-config.md) diff --git a/book/src/examples/genesis/loading-a-rollup-config.md b/book/src/examples/genesis/loading-a-rollup-config.md deleted file mode 100644 index e69de29b..00000000 diff --git a/book/src/examples/load-a-rollup-config.md b/book/src/examples/load-a-rollup-config.md new file mode 100644 index 00000000..ec2db0af --- /dev/null +++ b/book/src/examples/load-a-rollup-config.md @@ -0,0 +1,34 @@ +# Loading a Rollup Config from a Chain ID + +In this section, the code examples demonstrate loading the +rollup config for the given L2 Chain ID. + +Let's load the Rollup Config for OP Mainnet which hash chain id 10. + +```rust +use op_alloy_genesis::{OP_MAINNET_CONFIG, rollup_config_from_chain_id}; + +// The chain id for OP Mainnet +let op_mainnet_id = 10; + +// Load a rollup config from the chain id. +let op_mainnet_config = rollup_config_from_chain_id(op_mainnet_id).expect("infallible"); + +// The chain id should match the hardcoded chain id. +assert_eq!(OP_MAINNET_CONFIG, op_mainnet_config); +``` + +> ⚠️ Available Configs +> +> The `rollup_config_from_chain_id` method in `op-alloy-genesis` uses hardcoded +> rollup configs. But, there are only a few of these hardcoded rollup configs in +> `op-alloy-genesis`. This method and these configs are provided for `no_std` +> environments where dynamic filesystem loading at runtime is not supported +> in `no_std` environments. +> +> In a `std` environment, the [superchain][superchain] crate may be used which +> dynamically provides all rollup configs from the [superchain-registry][registry] +> for their respective chain ids. + +[superchain]: https://crates.io/crates/superchain +[registry]: https://github.com/ethereum-optimism/superchain-registry From 87fffa1efcd7fb915563c9285e98a83e2f72ce6a Mon Sep 17 00:00:00 2001 From: refcell Date: Mon, 4 Nov 2024 12:04:54 -0500 Subject: [PATCH 2/2] fix(book): missing example link --- book/src/SUMMARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 745e5a51..355c309e 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -8,6 +8,7 @@ - [System Config](./building/genesis/system-config.md) - [Consensus](./building/consensus.md) - [Examples](./examples/README.md) + - [Load a Rollup Config](./examples/load-a-rollup-config.md) - [Contributing](./CONTRIBUTING.md) - [Licensing](./LICENSE.md) - [Glossary](./glossary.md)