From 0e7c342be277b5b9449e730319f86fae8b9f3007 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Wed, 30 Oct 2024 17:55:12 +0400 Subject: [PATCH] Sync hypersync chain list +14 new chains (#308) * Sync hypersync chain list +14 new chains * Sync explorers and fix sorting * Update docs --- codegenerator/cli/CommandLineHelp.md | 2 +- .../cli/src/config_parsing/chain_helpers.rs | 79 ++++++++++++++----- .../cli/src/scripts/print_missing_networks.rs | 42 ++++++++-- 3 files changed, 95 insertions(+), 28 deletions(-) diff --git a/codegenerator/cli/CommandLineHelp.md b/codegenerator/cli/CommandLineHelp.md index eac40be45..8aeb5650c 100644 --- a/codegenerator/cli/CommandLineHelp.md +++ b/codegenerator/cli/CommandLineHelp.md @@ -106,7 +106,7 @@ Initialize by pulling the contract ABI from a block explorer * `-b`, `--blockchain ` — Network to import the contract from - Possible values: `amoy`, `arbitrum-nova`, `arbitrum-one`, `arbitrum-sepolia`, `arbitrum-testnet`, `aurora`, `aurora-testnet`, `avalanche`, `base`, `base-sepolia`, `blast`, `blast-sepolia`, `boba`, `bsc`, `bsc-testnet`, `canto`, `celo`, `celo-alfajores`, `celo-baklava`, `citrea-testnet`, `crab`, `ethereum-mainnet`, `evmos`, `fantom`, `fantom-testnet`, `fhenix-helium`, `flare`, `fuji`, `galadriel-devnet`, `gnosis`, `gnosis-chiado`, `goerli`, `harmony`, `holesky`, `kroma`, `linea`, `linea-sepolia`, `lukso`, `manta`, `mantle`, `mantle-testnet`, `mbase`, `metis`, `mode`, `mode-sepolia`, `moonbeam`, `moonriver`, `neon-evm`, `optimism`, `optimism-sepolia`, `poa-core`, `poa-sokol`, `polygon`, `polygon-zkevm`, `polygon-zkevm-testnet`, `rsk`, `scroll`, `scroll-sepolia`, `sepolia`, `shimmer-evm`, `zeta`, `zora`, `zora-sepolia` + Possible values: `amoy`, `arbitrum-nova`, `arbitrum-one`, `arbitrum-sepolia`, `arbitrum-testnet`, `aurora`, `aurora-testnet`, `avalanche`, `b2-testnet`, `base`, `base-sepolia`, `blast`, `blast-sepolia`, `boba`, `bsc`, `bsc-testnet`, `celo`, `celo-alfajores`, `celo-baklava`, `citrea-testnet`, `crab`, `ethereum-mainnet`, `evmos`, `fantom`, `fantom-testnet`, `fhenix-helium`, `flare`, `fuji`, `galadriel-devnet`, `gnosis`, `gnosis-chiado`, `goerli`, `harmony`, `holesky`, `kroma`, `linea`, `linea-sepolia`, `lisk`, `lukso`, `lukso-testnet`, `manta`, `mantle`, `mantle-testnet`, `mbase`, `metis`, `mode`, `mode-sepolia`, `moonbeam`, `moonriver`, `morph`, `morph-testnet`, `neon-evm`, `opbnb`, `optimism`, `optimism-sepolia`, `poa-core`, `poa-sokol`, `polygon`, `polygon-zkevm`, `polygon-zkevm-testnet`, `rsk`, `saakuru`, `scroll`, `scroll-sepolia`, `sepolia`, `shimmer-evm`, `taiko`, `tangle`, `unichain-sepolia`, `zeta`, `zora`, `zora-sepolia` diff --git a/codegenerator/cli/src/config_parsing/chain_helpers.rs b/codegenerator/cli/src/config_parsing/chain_helpers.rs index 627deb318..9aa72efcc 100644 --- a/codegenerator/cli/src/config_parsing/chain_helpers.rs +++ b/codegenerator/cli/src/config_parsing/chain_helpers.rs @@ -56,6 +56,9 @@ pub enum Network { #[subenum(HypersyncNetwork, GraphNetwork, NetworkWithExplorer)] Avalanche = 43114, + #[subenum(HypersyncNetwork, NetworkWithExplorer)] + B2Testnet = 1123, + #[subenum(HypersyncNetwork, NetworkWithExplorer, GraphNetwork)] Base = 8453, @@ -90,7 +93,6 @@ pub enum Network { #[subenum(HypersyncNetwork)] C1Milkomeda = 2001, - #[subenum(NetworkWithExplorer)] Canto = 7700, #[subenum(HypersyncNetwork, GraphNetwork, NetworkWithExplorer)] @@ -107,7 +109,7 @@ pub enum Network { CitreaDevnet = 62298, - #[subenum(NetworkWithExplorer)] + #[subenum(HypersyncNetwork, NetworkWithExplorer)] CitreaTestnet = 5115, #[subenum(GraphNetwork)] @@ -122,11 +124,6 @@ pub enum Network { #[subenum(HypersyncNetwork)] Darwinia = 46, - // Still syncing - // #[subenum(HypersyncNetwork)] - // // Explorers: - // // https://explorer.degen.tips/ - // Degen = 666666666, #[subenum( HypersyncNetwork, NetworkWithExplorer, @@ -181,18 +178,21 @@ pub enum Network { #[subenum(HypersyncNetwork, NetworkWithExplorer)] Kroma = 255, - // Still syncing - // #[subenum(HypersyncNetwork)] - // KakarotSepolia = 1802203764, #[subenum(HypersyncNetwork, NetworkWithExplorer)] Linea = 59144, #[subenum(NetworkWithExplorer)] LineaSepolia = 59141, + #[subenum(HypersyncNetwork, NetworkWithExplorer)] + Lisk = 1135, + #[subenum(HypersyncNetwork, NetworkWithExplorer)] Lukso = 42, + #[subenum(HypersyncNetwork, NetworkWithExplorer)] + LuksoTestnet = 4201, + #[subenum(HypersyncNetwork, NetworkWithExplorer)] Manta = 169, @@ -205,13 +205,16 @@ pub enum Network { #[subenum(GraphNetwork, NetworkWithExplorer)] Mbase = 1287, + #[subenum(HypersyncNetwork)] + Merlin = 4200, + #[subenum(HypersyncNetwork, NetworkWithExplorer)] Metis = 1088, #[subenum(HypersyncNetwork)] MevCommit = 17864, - #[subenum(NetworkWithExplorer)] + #[subenum(HypersyncNetwork, NetworkWithExplorer)] Mode = 34443, #[subenum(NetworkWithExplorer)] @@ -223,15 +226,21 @@ pub enum Network { #[subenum(GraphNetwork, NetworkWithExplorer)] Moonriver = 1285, - // Still syncing - // #[subenum(HypersyncNetwork)] - // MorphTestnet = 2810, + #[subenum(HypersyncNetwork, NetworkWithExplorer)] + Morph = 2818, + + #[subenum(HypersyncNetwork, NetworkWithExplorer)] + MorphTestnet = 2810, + #[subenum(GraphNetwork)] Mumbai = 80001, #[subenum(HypersyncNetwork, NetworkWithExplorer)] NeonEvm = 245022934, + #[subenum(HypersyncNetwork, NetworkWithExplorer)] + Opbnb = 204, + #[subenum(HypersyncNetwork, NetworkWithExplorer, GraphNetwork)] Optimism = 10, @@ -266,9 +275,9 @@ pub enum Network { #[subenum(HypersyncNetwork, NetworkWithExplorer)] Rsk = 30, - // Still syncing - // #[subenum(HypersyncNetwork)] - // Saakuru = 7225878, + #[subenum(HypersyncNetwork, NetworkWithExplorer)] + Saakuru = 7225878, + #[subenum(GraphNetwork, HypersyncNetwork, NetworkWithExplorer)] Scroll = 534352, @@ -284,10 +293,18 @@ pub enum Network { #[subenum(HypersyncNetwork)] SophonTestnet = 531050104, + #[subenum(HypersyncNetwork, NetworkWithExplorer)] + Taiko = 167000, + + #[subenum(HypersyncNetwork, NetworkWithExplorer)] + Tangle = 5845, + + #[subenum(HypersyncNetwork, NetworkWithExplorer)] + UnichainSepolia = 1301, + #[subenum(HypersyncNetwork)] XLayer = 196, - #[subenum(HypersyncNetwork)] XLayerTestnet = 195, #[subenum(HypersyncNetwork, NetworkWithExplorer)] @@ -417,7 +434,18 @@ impl Network { | Network::ZksyncEra | Network::ZksyncEraTestnet | Network::Zora - | Network::ZoraSepolia => DEFAULT_CONFIRMED_BLOCK_THRESHOLD, + | Network::ZoraSepolia + | Network::Lisk + | Network::Taiko + | Network::LuksoTestnet + | Network::Merlin + | Network::B2Testnet + | Network::UnichainSepolia + | Network::Opbnb + | Network::Saakuru + | Network::Morph + | Network::MorphTestnet + | Network::Tangle => DEFAULT_CONFIRMED_BLOCK_THRESHOLD, } } } @@ -457,6 +485,19 @@ mod test { ); } + #[tokio::test] + async fn all_hypersync_networks_are_included() { + let diff = crate::scripts::print_missing_networks::get_diff() + .await + .unwrap(); + + if diff.missing_chains.is_empty() || diff.extra_chains.is_empty() { + return; + } + crate::scripts::print_missing_networks::print_diff_message(diff); + assert!(false); + } + #[test] fn network_deserialize() { let names = r#"["ethereum-mainnet", "polygon"]"#; diff --git a/codegenerator/cli/src/scripts/print_missing_networks.rs b/codegenerator/cli/src/scripts/print_missing_networks.rs index 01562acb2..cbf2b6d39 100644 --- a/codegenerator/cli/src/scripts/print_missing_networks.rs +++ b/codegenerator/cli/src/scripts/print_missing_networks.rs @@ -8,10 +8,15 @@ use std::collections::HashSet; #[derive(Deserialize, Debug)] struct Chain { name: String, - chain_id: u64, + chain_id: Option, // None for Fuel chains } -pub async fn run() -> Result<()> { +pub struct Diff { + pub missing_chains: Vec, + pub extra_chains: Vec, +} + +pub async fn get_diff() -> Result { let url = "https://chains.hyperquery.xyz/active_chains"; let response = reqwest::get(url).await?; let chains: Vec = response.json().await?; @@ -20,9 +25,15 @@ pub async fn run() -> Result<()> { let mut api_chain_ids = HashSet::new(); for chain in &chains { - api_chain_ids.insert(chain.chain_id); - if HypersyncNetwork::from_repr(chain.chain_id).is_none() { - let is_graph = GraphNetwork::from_repr(chain.chain_id).is_some(); + let Some(chain_id) = chain.chain_id else { + continue; + }; + if chain.name == "internal-test-chain" { + continue; + } + api_chain_ids.insert(chain_id); + if HypersyncNetwork::from_repr(chain_id).is_none() { + let is_graph = GraphNetwork::from_repr(chain_id).is_some(); let subenums = match is_graph { true => "HypersyncNetwork, GraphNetwork", @@ -32,7 +43,7 @@ pub async fn run() -> Result<()> { " #[subenum({})]\n {} = {},", subenums, chain.name.to_case(Case::Pascal), - chain.chain_id + chain_id )); } } @@ -45,10 +56,21 @@ pub async fn run() -> Result<()> { } } + Ok(Diff { + missing_chains, + extra_chains, + }) +} + +pub fn print_diff_message(diff: Diff) { + let Diff { + missing_chains, + extra_chains, + } = diff; if missing_chains.is_empty() && extra_chains.is_empty() { println!( "All chains from the API are present in the HypersyncNetwork enum, and vice versa. \ - Nothing to update." + Nothing to update." ); } else { if !missing_chains.is_empty() { @@ -61,13 +83,17 @@ pub async fn run() -> Result<()> { if !extra_chains.is_empty() { println!( "\nThe following chains are in the HypersyncNetwork enum but not in the API \ - (remove the HypersyncNetwork enum from the chain_helpers.rs file):" + (remove the HypersyncNetwork subEnum from the chain_helpers.rs file):" ); for chain in extra_chains { println!("- {}", chain); } } } +} +pub async fn run() -> Result<()> { + let diff = get_diff().await?; + print_diff_message(diff); Ok(()) }