Skip to content

Commit

Permalink
Sync hypersync chain list +14 new chains (#308)
Browse files Browse the repository at this point in the history
* Sync hypersync chain list +14 new chains

* Sync explorers and fix sorting

* Update docs
  • Loading branch information
DZakh authored Oct 30, 2024
1 parent 4dc2eb7 commit 0e7c342
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 28 deletions.
2 changes: 1 addition & 1 deletion codegenerator/cli/CommandLineHelp.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Initialize by pulling the contract ABI from a block explorer

* `-b`, `--blockchain <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`



Expand Down
79 changes: 60 additions & 19 deletions codegenerator/cli/src/config_parsing/chain_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub enum Network {
#[subenum(HypersyncNetwork, GraphNetwork, NetworkWithExplorer)]
Avalanche = 43114,

#[subenum(HypersyncNetwork, NetworkWithExplorer)]
B2Testnet = 1123,

#[subenum(HypersyncNetwork, NetworkWithExplorer, GraphNetwork)]
Base = 8453,

Expand Down Expand Up @@ -90,7 +93,6 @@ pub enum Network {
#[subenum(HypersyncNetwork)]
C1Milkomeda = 2001,

#[subenum(NetworkWithExplorer)]
Canto = 7700,

#[subenum(HypersyncNetwork, GraphNetwork, NetworkWithExplorer)]
Expand All @@ -107,7 +109,7 @@ pub enum Network {

CitreaDevnet = 62298,

#[subenum(NetworkWithExplorer)]
#[subenum(HypersyncNetwork, NetworkWithExplorer)]
CitreaTestnet = 5115,

#[subenum(GraphNetwork)]
Expand All @@ -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,
Expand Down Expand Up @@ -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,

Expand All @@ -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)]
Expand All @@ -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,

Expand Down Expand Up @@ -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,

Expand All @@ -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)]
Expand Down Expand Up @@ -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,
}
}
}
Expand Down Expand Up @@ -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"]"#;
Expand Down
42 changes: 34 additions & 8 deletions codegenerator/cli/src/scripts/print_missing_networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ use std::collections::HashSet;
#[derive(Deserialize, Debug)]
struct Chain {
name: String,
chain_id: u64,
chain_id: Option<u64>, // None for Fuel chains
}

pub async fn run() -> Result<()> {
pub struct Diff {
pub missing_chains: Vec<String>,
pub extra_chains: Vec<String>,
}

pub async fn get_diff() -> Result<Diff> {
let url = "https://chains.hyperquery.xyz/active_chains";
let response = reqwest::get(url).await?;
let chains: Vec<Chain> = response.json().await?;
Expand All @@ -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",
Expand All @@ -32,7 +43,7 @@ pub async fn run() -> Result<()> {
" #[subenum({})]\n {} = {},",
subenums,
chain.name.to_case(Case::Pascal),
chain.chain_id
chain_id
));
}
}
Expand All @@ -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() {
Expand All @@ -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(())
}

0 comments on commit 0e7c342

Please sign in to comment.