1#![doc = include_str!("../README.md")]
2#![doc(
3 html_logo_url = "https://raw.githubusercontent.com/op-rs/kona/main/assets/square.png",
4 html_favicon_url = "https://raw.githubusercontent.com/op-rs/kona/main/assets/favicon.ico",
5 issue_tracker_base_url = "https://github.com/op-rs/kona/issues/"
6)]
7#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
8#![cfg_attr(not(feature = "std"), no_std)]
9
10extern crate alloc;
11
12pub use alloy_primitives::map::HashMap;
13pub use kona_genesis::{ChainConfig, RollupConfig};
14
15pub mod chain_list;
16pub use chain_list::{Chain, ChainList};
17
18pub mod superchain;
19pub use superchain::Registry;
20
21#[cfg(test)]
22pub mod test_utils;
23
24lazy_static::lazy_static! {
25 static ref _INIT: Registry = Registry::from_chain_list();
27
28 pub static ref CHAINS: ChainList = _INIT.chain_list.clone();
30
31 pub static ref OPCHAINS: HashMap<u64, ChainConfig> = _INIT.op_chains.clone();
33
34 pub static ref ROLLUP_CONFIGS: HashMap<u64, RollupConfig> = _INIT.rollup_configs.clone();
36}
37
38pub fn scr_rollup_config_by_ident(ident: &str) -> Option<&RollupConfig> {
40 let chain_id = CHAINS.get_chain_by_ident(ident)?.chain_id;
41 ROLLUP_CONFIGS.get(&chain_id)
42}
43
44pub fn scr_rollup_config_by_alloy_ident(chain: &alloy_chains::Chain) -> Option<&RollupConfig> {
46 ROLLUP_CONFIGS.get(&chain.id())
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52 use alloy_chains::Chain as AlloyChain;
53
54 #[test]
55 fn test_hardcoded_rollup_configs() {
56 let test_cases = [
57 (10, test_utils::OP_MAINNET_CONFIG),
58 (8453, test_utils::BASE_MAINNET_CONFIG),
59 (11155420, test_utils::OP_SEPOLIA_CONFIG),
60 (84532, test_utils::BASE_SEPOLIA_CONFIG),
61 ]
62 .to_vec();
63
64 for (chain_id, expected) in test_cases {
65 let derived = super::ROLLUP_CONFIGS.get(&chain_id).unwrap();
66 assert_eq!(expected, *derived);
67 }
68 }
69
70 #[test]
71 fn test_chain_by_ident() {
72 const ALLOY_BASE: AlloyChain = AlloyChain::base_mainnet();
73
74 let chain_by_ident = CHAINS.get_chain_by_ident("mainnet/base").unwrap();
75 let chain_by_alloy_ident = CHAINS.get_chain_by_alloy_ident(&ALLOY_BASE).unwrap();
76 let chain_by_id = CHAINS.get_chain_by_id(8453).unwrap();
77
78 assert_eq!(chain_by_ident, chain_by_id);
79 assert_eq!(chain_by_alloy_ident, chain_by_id);
80 }
81
82 #[test]
83 fn test_rollup_config_by_ident() {
84 const ALLOY_BASE: AlloyChain = AlloyChain::base_mainnet();
85
86 let rollup_config_by_ident = scr_rollup_config_by_ident("mainnet/base").unwrap();
87 let rollup_config_by_alloy_ident = scr_rollup_config_by_alloy_ident(&ALLOY_BASE).unwrap();
88 let rollup_config_by_id = ROLLUP_CONFIGS.get(&8453).unwrap();
89
90 assert_eq!(rollup_config_by_ident, rollup_config_by_id);
91 assert_eq!(rollup_config_by_alloy_ident, rollup_config_by_id);
92 }
93}