Skip to content

Commit

Permalink
add: Immutable zkEVM and Immutable zkEVM testnet (#88)
Browse files Browse the repository at this point in the history
PR to add Immutable zkEVM and Immutable zkEVM testnet.

The chain configuration is taken from here:
https://docs.immutable.com/platform/zkevm/chain-config/

More information about Immutable can be found here:
https://www.immutable.com/ and https://x.com/Immutable

---------

Co-authored-by: sergerad <serge.radinovich@immutable.com>
  • Loading branch information
drinkcoffee and sergerad authored Sep 13, 2024
1 parent 1a9e492 commit 250a958
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Features

- Add immutable mainnet and testnet ([#88](https://github.com/alloy-rs/chains/issues/88))

## [0.1.30](https://github.com/alloy-rs/chains/releases/tag/v0.1.30) - 2024-09-06

### Features
Expand Down
24 changes: 24 additions & 0 deletions assets/chains.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,18 @@ impl Chain {
Self::from_named(NamedChain::Koi)
}

/// Returns the Immutable zkEVM mainnet chain.
#[inline]
pub const fn immutable() -> Self {
Self::from_named(NamedChain::Immutable)
}

/// Returns the Immutable zkEVM testnet chain.
#[inline]
pub const fn immutable_testnet() -> Self {
Self::from_named(NamedChain::ImmutableTestnet)
}

/// Returns the kind of this chain.
#[inline]
pub const fn kind(&self) -> &ChainKind {
Expand Down
40 changes: 35 additions & 5 deletions src/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ pub enum NamedChain {
#[strum(to_string = "pulsechain-testnet")]
#[cfg_attr(feature = "serde", serde(alias = "pulsechain-testnet"))]
PulsechainTestnet = 943,

#[strum(to_string = "immutable")]
#[cfg_attr(feature = "serde", serde(alias = "immutable"))]
Immutable = 13371,
#[strum(to_string = "immutable-testnet")]
#[cfg_attr(feature = "serde", serde(alias = "immutable-testnet"))]
ImmutableTestnet = 13473,
}

// This must be implemented manually so we avoid a conflict with `TryFromPrimitive` where it treats
Expand Down Expand Up @@ -583,6 +590,8 @@ impl NamedChain {

C::Pulsechain => 10000,
C::PulsechainTestnet => 10101,

C::Immutable | C::ImmutableTestnet => 2_000,
}))
}

Expand Down Expand Up @@ -696,7 +705,9 @@ impl NamedChain {
| C::Crab
| C::Pulsechain
| C::PulsechainTestnet
| C::Koi => false,
| C::Koi
| C::Immutable
| C::ImmutableTestnet => false,

// Unknown / not applicable, default to false for backwards compatibility.
C::Dev
Expand Down Expand Up @@ -786,7 +797,9 @@ impl NamedChain {
| C::CfxTestnet
| C::Pulsechain
| C::PulsechainTestnet
| C::Koi => true,
| C::Koi
| C::Immutable
| C::ImmutableTestnet => true,
_ => false,
}
}
Expand Down Expand Up @@ -862,7 +875,8 @@ impl NamedChain {
| C::PulsechainTestnet
| C::GravityAlphaTestnetSepolia
| C::XaiSepolia
| C::Koi => true,
| C::Koi
| C::ImmutableTestnet => true,

// Dev chains.
C::Dev | C::AnvilHardhat => true,
Expand Down Expand Up @@ -921,7 +935,8 @@ impl NamedChain {
| C::Cfx
| C::Crab
| C::Pulsechain
| C::Etherlink => false,
| C::Etherlink
| C::Immutable => false,
}
}

Expand Down Expand Up @@ -975,6 +990,9 @@ impl NamedChain {
C::Cfx | C::CfxTestnet => "CFX",
C::Pulsechain | C::PulsechainTestnet => "PLS",

C::Immutable => "IMX",
C::ImmutableTestnet => "tIMX",

_ => return None,
})
}
Expand Down Expand Up @@ -1300,6 +1318,14 @@ impl NamedChain {
"https://api.scan.v4.testnet.pulsechain.com",
"https://scan.v4.testnet.pulsechain.com",
),

C::Immutable => {
("https://explorer.immutable.com/api", "https://explorer.immutable.com")
}
C::ImmutableTestnet => (
"https://explorer.testnet.immutable.com/api",
"https://explorer.testnet.immutable.com",
),
})
}

Expand Down Expand Up @@ -1399,7 +1425,9 @@ impl NamedChain {
| C::ZoraSepolia
| C::Darwinia
| C::Crab
| C::Koi => "BLOCKSCOUT_API_KEY",
| C::Koi
| C::Immutable
| C::ImmutableTestnet => "BLOCKSCOUT_API_KEY",

C::Boba => "BOBASCAN_API_KEY",

Expand Down Expand Up @@ -1556,6 +1584,8 @@ mod tests {
(SyndrSepolia, &["syndr-sepolia"]),
(LineaGoerli, &["linea-goerli"]),
(AutonomysNovaTestnet, &["autonomys-nova-testnet"]),
(Immutable, &["immutable"]),
(ImmutableTestnet, &["immutable-testnet"]),
];

for &(chain, aliases) in ALIASES {
Expand Down

0 comments on commit 250a958

Please sign in to comment.