diff --git a/.github/workflows/rs.yml b/.github/workflows/rs.yml new file mode 100644 index 0000000..1c045f4 --- /dev/null +++ b/.github/workflows/rs.yml @@ -0,0 +1,42 @@ +name: Rust - Build and test + +on: [ push ] + +jobs: + build-test: + name: Build and test + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Install rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: "go.mod" + cache: false + - name: Make sure generated files are updated + run: | + if go generate ./rs | grep -q 'rust: no changes detected'; then + exit 0; + fi + exit 1; + - name: cargo fmt + working-directory: rs/chainselectors + run: cargo fmt --all -- --check + - name: cargo clippy + working-directory: rs/chainselectors + run: cargo clippy --all-targets --all-features -- -D warnings + - name: cargo test + working-directory: rs/chainselectors + run: cargo test + timeout-minutes: 1 + - name: cargo build + working-directory: rs/chainselectors + run: cargo build \ No newline at end of file diff --git a/README.md b/README.md index f2ff553..5409520 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Any new chains and selectors should be always added to [selectors.yml](selectors details from this file. This ensures that all client libraries are in sync and use the same mapping. To add a new chain, please add new entry to the `selectors.yml` file and use the following format: -Make sure to run `go generate` after making any changes. +Make sure to run `go generate ./...` after making any changes. ```yaml $chain_id: diff --git a/genchains.go b/genchains.go index 09742c3..aa63572 100644 --- a/genchains.go +++ b/genchains.go @@ -3,17 +3,15 @@ package main import ( - "bytes" "fmt" "go/format" - "html/template" "os" - "sort" "strconv" "strings" + "text/template" "unicode" - chain_selectors "github.com/smartcontractkit/chain-selectors" + "github.com/smartcontractkit/chain-selectors/internal/gotmpl" ) const filename = "generated_chains.go" @@ -48,7 +46,7 @@ var ALL = []Chain{ `) func main() { - src, err := genChainsSourceCode() + src, err := gotmpl.Run(chainTemplate, &goNameEncoder{}) if err != nil { panic(err) } @@ -74,32 +72,9 @@ func main() { } } -func genChainsSourceCode() (string, error) { - var wr = new(bytes.Buffer) - chains := make([]chain, 0) - - for evmChainID, chainSel := range chain_selectors.EvmChainIdToChainSelector() { - name, err := chain_selectors.NameFromChainId(evmChainID) - if err != nil { - return "", err - } - - chains = append(chains, chain{ - EvmChainID: evmChainID, - Selector: chainSel, - Name: name, - VarName: toVarName(name, chainSel), - }) - } - - sort.Slice(chains, func(i, j int) bool { return chains[i].VarName < chains[j].VarName }) - if err := chainTemplate.ExecuteTemplate(wr, "", chains); err != nil { - return "", err - } - return wr.String(), nil -} +type goNameEncoder struct{} -func toVarName(name string, chainSel uint64) string { +func (*goNameEncoder) VarName(name string, chainSel uint64) string { const unnamed = "TEST" x := strings.ReplaceAll(name, "-", "_") x = strings.ToUpper(x) diff --git a/go.mod b/go.mod index 14e1c73..fbfeb82 100644 --- a/go.mod +++ b/go.mod @@ -10,4 +10,5 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/text v0.19.0 // indirect ) diff --git a/go.sum b/go.sum index fa4b6e6..a775a58 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/gotmpl/run.go b/internal/gotmpl/run.go new file mode 100644 index 0000000..7e4b36c --- /dev/null +++ b/internal/gotmpl/run.go @@ -0,0 +1,47 @@ +package gotmpl + +import ( + "bytes" + "sort" + "text/template" + + chain_selectors "github.com/smartcontractkit/chain-selectors" +) + +type NameEncoder interface { + VarName(name string, chainSel uint64) string +} + +type chain struct { + EvmChainID uint64 + Selector uint64 + Name string + VarName string +} + +func Run(tmpl *template.Template, enc NameEncoder) (string, error) { + var wr = new(bytes.Buffer) + chains := make([]chain, 0) + + for evmChainID, chainSel := range chain_selectors.EvmChainIdToChainSelector() { + name, err := chain_selectors.NameFromChainId(evmChainID) + if err != nil { + return "", err + } + + chains = append(chains, chain{ + EvmChainID: evmChainID, + Selector: chainSel, + Name: name, + VarName: enc.VarName(name, chainSel), + }) + } + + sort.Slice(chains, func(i, j int) bool { return chains[i].VarName < chains[j].VarName }) + + if err := tmpl.Execute(wr, chains); err != nil { + return "", err + } + + return wr.String(), nil +} diff --git a/rs/README.md b/rs/README.md new file mode 100644 index 0000000..69073f2 --- /dev/null +++ b/rs/README.md @@ -0,0 +1,42 @@ +# Chain Selectors (Rust) + +This folder contains the Rust implementation of the Chain Selectors module. + +## User Guide + +### Installation + +```shell +cargo add --git https://github.com/smartcontractkit/chain-selectors --tag +``` + +### Usage + +```rust +use std::str::FromStr; +use chainselectors::generated_chains::{ChainName, ChainSelector, ChainId}; + +fn main() { + let chain = ChainName::try_from(ChainId(420)).unwrap(); + assert_eq!(chain, ChainName::EthereumTestnetGoerliOptimism1); + + let selector = ChainSelector::from(ChainName::EthereumTestnetGoerliOptimism1); + assert_eq!( + selector, + ChainSelector(2664363617261496610), + ); + + let chain_from_str = ChainName::from_str("ethereum-testnet-goerli-optimism-1").unwrap(); + assert_eq!(chain_from_str, ChainName::EthereumTestnetGoerliOptimism1); +} +``` + +## Dev Guide + +### Pre-requisites + +As part of the code generation, `rustfmt` is used to format the generated code. If you don't have rust toolchain installed, it will run in docker. + +### Build + +To build the Chain Selectors module, run the `go generate ./rs` from the root of the project, or `go generate ./...` to generate all modules (not just rust). diff --git a/rs/chainselectors/.gitignore b/rs/chainselectors/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/rs/chainselectors/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/rs/chainselectors/Cargo.lock b/rs/chainselectors/Cargo.lock new file mode 100644 index 0000000..bc80854 --- /dev/null +++ b/rs/chainselectors/Cargo.lock @@ -0,0 +1,93 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "chainselectors" +version = "0.1.0" +dependencies = [ + "anyhow", + "serde", + "thiserror", +] + +[[package]] +name = "proc-macro2" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3c6efbfc763e64eb85c11c25320f0737cb7364c4b6336db90aa9ebe27a0bbd" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b607164372e89797d78b8e23a6d67d5d1038c1c65efd52e1389ef8b77caba2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" diff --git a/rs/chainselectors/Cargo.toml b/rs/chainselectors/Cargo.toml new file mode 100644 index 0000000..b39d154 --- /dev/null +++ b/rs/chainselectors/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "chainselectors" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1.0" +serde = {version="1", features = ["derive"]} +thiserror = "1" \ No newline at end of file diff --git a/rs/chainselectors/src/generated_chains.rs b/rs/chainselectors/src/generated_chains.rs new file mode 100644 index 0000000..637f82d --- /dev/null +++ b/rs/chainselectors/src/generated_chains.rs @@ -0,0 +1,1570 @@ +// Code generated by go generate ./rs please DO NOT EDIT + +use std::{ + fmt::{Display, Formatter, Result as FmtResult}, + str::FromStr, +}; +use thiserror::Error; + +#[derive(Error, Debug, PartialEq, Eq, Clone)] +pub enum Error { + #[error("unknown chain name: {0}")] + UnknownChainName(String), + #[error("unknown chain id: {0}")] + UnknownChainId(ChainId), + #[error("unknown chain selector: {0}")] + UnknownChainSelector(ChainSelector), +} + +#[derive( + Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize, PartialOrd, Ord, +)] +pub struct ChainId(pub u64); + +impl Display for ChainId { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!(f, "{}", self.0) + } +} + +#[derive( + Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize, PartialOrd, Ord, +)] +pub struct ChainSelector(pub u64); + +impl Display for ChainSelector { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!(f, "{}", self.0) + } +} + +#[derive( + Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize, PartialOrd, Ord, +)] +#[repr(u64)] +pub enum ChainName { + AreonMainnet = 463, + AreonTestnet = 462, + AvalancheMainnet = 43114, + AvalancheSubnetDexalotMainnet = 432204, + AvalancheSubnetDexalotTestnet = 432201, + AvalancheTestnetFuji = 43113, + AvalancheTestnetNexon = 595581, + BerachainTestnetArtio = 80085, + BerachainTestnetBartio = 80084, + BinanceSmartChainMainnet = 56, + BinanceSmartChainMainnetOpbnb1 = 204, + BinanceSmartChainTestnet = 97, + BinanceSmartChainTestnetOpbnb1 = 5611, + BitcichainMainnet = 1907, + BitcichainTestnet = 1908, + BitcoinMainnetBitlayer1 = 200901, + BitcoinMainnetBob1 = 60808, + BitcoinMainnetBotanix = 3637, + BitcoinMainnetBsquared1 = 223, + BitcoinMerlinMainnet = 4200, + BitcoinTestnetBitlayer1 = 200810, + BitcoinTestnetBotanix = 3636, + BitcoinTestnetBsquared1 = 1123, + BitcoinTestnetMerlin = 686868, + BitcoinTestnetRootstock = 31, + BitcoinTestnetSepoliaBob1 = 808813, + BittorrentChainMainnet = 199, + BittorrentChainTestnet = 1029, + CeloMainnet = 42220, + CeloTestnetAlfajores = 44787, + CoinexSmartChainMainnet = 52, + CoinexSmartChainTestnet = 53, + CronosMainnet = 25, + CronosTestnet = 338, + CronosTestnetZkevm1 = 282, + EthereumMainnet = 1, + EthereumMainnetArbitrum1 = 42161, + EthereumMainnetArbitrum1L3x1 = 12324, + EthereumMainnetArbitrum1Treasure1 = 978670, + EthereumMainnetAstarZkevm1 = 3776, + EthereumMainnetBase1 = 8453, + EthereumMainnetBlast1 = 81457, + EthereumMainnetImmutableZkevm1 = 13371, + EthereumMainnetKroma1 = 255, + EthereumMainnetLinea1 = 59144, + EthereumMainnetMantle1 = 5000, + EthereumMainnetMetis1 = 1088, + EthereumMainnetMode1 = 34443, + EthereumMainnetOptimism1 = 10, + EthereumMainnetPolygonZkevm1 = 1101, + EthereumMainnetScroll1 = 534352, + EthereumMainnetTaiko1 = 167000, + EthereumMainnetWorldchain1 = 480, + EthereumMainnetXlayer1 = 196, + EthereumMainnetZircuit1 = 48900, + EthereumMainnetZksync1 = 324, + EthereumTestnetGoerliArbitrum1 = 421613, + EthereumTestnetGoerliBase1 = 84531, + EthereumTestnetGoerliLinea1 = 59140, + EthereumTestnetGoerliMantle1 = 5001, + EthereumTestnetGoerliOptimism1 = 420, + EthereumTestnetGoerliPolygonZkevm1 = 1442, + EthereumTestnetGoerliZksync1 = 280, + EthereumTestnetHolesky = 17000, + EthereumTestnetHoleskyFraxtal1 = 2522, + EthereumTestnetHoleskyMorph1 = 2810, + EthereumTestnetHoleskyTaiko1 = 167009, + EthereumTestnetSepolia = 11155111, + EthereumTestnetSepoliaArbitrum1 = 421614, + EthereumTestnetSepoliaArbitrum1L3x1 = 12325, + EthereumTestnetSepoliaArbitrum1Treasure1 = 978657, + EthereumTestnetSepoliaBase1 = 84532, + EthereumTestnetSepoliaBlast1 = 168587773, + EthereumTestnetSepoliaCorn1 = 21000000, + EthereumTestnetSepoliaImmutableZkevm1 = 13473, + EthereumTestnetSepoliaKroma1 = 2358, + EthereumTestnetSepoliaLens1 = 37111, + EthereumTestnetSepoliaLinea1 = 59141, + EthereumTestnetSepoliaLisk1 = 4202, + EthereumTestnetSepoliaMantle1 = 5003, + EthereumTestnetSepoliaMetis1 = 59902, + EthereumTestnetSepoliaMode1 = 919, + EthereumTestnetSepoliaOptimism1 = 11155420, + EthereumTestnetSepoliaPolygonValidium1 = 717160, + EthereumTestnetSepoliaPolygonZkevm1 = 2442, + EthereumTestnetSepoliaScroll1 = 534351, + EthereumTestnetSepoliaSoneium1 = 1946, + EthereumTestnetSepoliaUnichain1 = 1301, + EthereumTestnetSepoliaWorldchain1 = 4801, + EthereumTestnetSepoliaXlayer1 = 195, + EthereumTestnetSepoliaZircuit1 = 48899, + EthereumTestnetSepoliaZksync1 = 300, + FantomMainnet = 250, + FantomTestnet = 4002, + FilecoinMainnet = 314, + FilecoinTestnet = 31415926, + FraxtalMainnet = 252, + GethDevnet2 = 2337, + GethDevnet3 = 3337, + GethTestnet = 1337, + GnosisChainMainnet = 100, + GnosisChainTestnetChiado = 10200, + HederaMainnet = 295, + HederaTestnet = 296, + HyperliquidTestnet = 998, + KavaMainnet = 2222, + KavaTestnet = 2221, + KusamaMainnetMoonriver = 1285, + NearMainnet = 397, + NearTestnet = 398, + NeonlinkMainnet = 259, + NeonlinkTestnet = 9559, + PlumeTestnet = 161221135, + PolkadotMainnetAstar = 592, + PolkadotMainnetCentrifuge = 2031, + PolkadotMainnetDarwinia = 46, + PolkadotMainnetMoonbeam = 1284, + PolkadotTestnetAstarShibuya = 81, + PolkadotTestnetCentrifugeAltair = 2088, + PolkadotTestnetDarwiniaPangoro = 45, + PolkadotTestnetMoonbeamMoonbase = 1287, + PolygonMainnet = 137, + PolygonTestnetAmoy = 80002, + PolygonTestnetMumbai = 80001, + PrivateTestnetMica = 424242, + PrivateTestnetOpala = 45439, + RoninMainnet = 2020, + RoninTestnetSaigon = 2021, + SeiMainnet = 1329, + SeiTestnetAtlantic = 1328, + SonicTestnet = 64165, + StoryTestnet = 1513, + TelosEvmMainnet = 40, + TelosEvmTestnet = 41, + Test1000 = 1000, + Test76578 = 76578, + Test90000001 = 90000001, + Test90000002 = 90000002, + Test90000003 = 90000003, + Test90000004 = 90000004, + Test90000005 = 90000005, + Test90000006 = 90000006, + Test90000007 = 90000007, + Test90000008 = 90000008, + Test90000009 = 90000009, + Test90000010 = 90000010, + Test90000011 = 90000011, + Test90000012 = 90000012, + Test90000013 = 90000013, + Test90000014 = 90000014, + Test90000015 = 90000015, + Test90000016 = 90000016, + Test90000017 = 90000017, + Test90000018 = 90000018, + Test90000019 = 90000019, + Test90000020 = 90000020, + Test90000021 = 90000021, + Test90000022 = 90000022, + Test90000023 = 90000023, + Test90000024 = 90000024, + Test90000025 = 90000025, + Test90000026 = 90000026, + Test90000027 = 90000027, + Test90000028 = 90000028, + Test90000029 = 90000029, + Test90000030 = 90000030, + Test90000031 = 90000031, + Test90000032 = 90000032, + Test90000033 = 90000033, + Test90000034 = 90000034, + Test90000035 = 90000035, + Test90000036 = 90000036, + Test90000037 = 90000037, + Test90000038 = 90000038, + Test90000039 = 90000039, + Test90000040 = 90000040, + Test90000041 = 90000041, + Test90000042 = 90000042, + Test90000043 = 90000043, + Test90000044 = 90000044, + Test90000045 = 90000045, + Test90000046 = 90000046, + Test90000047 = 90000047, + Test90000048 = 90000048, + Test90000049 = 90000049, + Test90000050 = 90000050, + Test90000051 = 90000051, + Test90000052 = 90000052, + Test90000053 = 90000053, + Test90000054 = 90000054, + Test90000055 = 90000055, + Test90000056 = 90000056, + Test90000057 = 90000057, + Test90000058 = 90000058, + Test90000059 = 90000059, + Test90000060 = 90000060, + Test90000061 = 90000061, + Test90000062 = 90000062, + Test90000063 = 90000063, + Test90000064 = 90000064, + Test90000065 = 90000065, + Test90000066 = 90000066, + Test90000067 = 90000067, + Test90000068 = 90000068, + Test90000069 = 90000069, + Test90000070 = 90000070, + Test90000071 = 90000071, + Test90000072 = 90000072, + Test90000073 = 90000073, + Test90000074 = 90000074, + Test90000075 = 90000075, + Test90000076 = 90000076, + Test90000077 = 90000077, + Test90000078 = 90000078, + Test90000079 = 90000079, + Test90000080 = 90000080, + Test90000081 = 90000081, + Test90000082 = 90000082, + Test90000083 = 90000083, + Test90000084 = 90000084, + Test90000085 = 90000085, + Test90000086 = 90000086, + Test90000087 = 90000087, + Test90000088 = 90000088, + Test90000089 = 90000089, + Test90000090 = 90000090, + Test90000091 = 90000091, + Test90000092 = 90000092, + Test90000093 = 90000093, + Test90000094 = 90000094, + Test90000095 = 90000095, + Test90000096 = 90000096, + Test90000097 = 90000097, + Test90000098 = 90000098, + Test90000099 = 90000099, + Test90000100 = 90000100, + VelasMainnet = 106, + VelasTestnet = 111, + WemixMainnet = 1111, + WemixTestnet = 1112, + ZklinkNovaMainnet = 810180, + ZklinkNovaTestnet = 810181, +} + +impl From for ChainId { + fn from(chain_name: ChainName) -> ChainId { + ChainId(chain_name as u64) + } +} + +impl From for ChainSelector { + fn from(chain: ChainName) -> Self { + match chain { + ChainName::AreonMainnet => Self(1939936305787790600), + ChainName::AreonTestnet => Self(7317911323415911000), + ChainName::AvalancheMainnet => Self(6433500567565415381), + ChainName::AvalancheSubnetDexalotMainnet => Self(5463201557265485081), + ChainName::AvalancheSubnetDexalotTestnet => Self(1458281248224512906), + ChainName::AvalancheTestnetFuji => Self(14767482510784806043), + ChainName::AvalancheTestnetNexon => Self(7837562506228496256), + ChainName::BerachainTestnetArtio => Self(12336603543561911511), + ChainName::BerachainTestnetBartio => Self(8999465244383784164), + ChainName::BinanceSmartChainMainnet => Self(11344663589394136015), + ChainName::BinanceSmartChainMainnetOpbnb1 => Self(465944652040885897), + ChainName::BinanceSmartChainTestnet => Self(13264668187771770619), + ChainName::BinanceSmartChainTestnetOpbnb1 => Self(13274425992935471758), + ChainName::BitcichainMainnet => Self(4874388048629246000), + ChainName::BitcichainTestnet => Self(4888058894222120000), + ChainName::BitcoinMainnetBitlayer1 => Self(7937294810946806131), + ChainName::BitcoinMainnetBob1 => Self(3849287863852499584), + ChainName::BitcoinMainnetBotanix => Self(4560701533377838164), + ChainName::BitcoinMainnetBsquared1 => Self(5406759801798337480), + ChainName::BitcoinMerlinMainnet => Self(241851231317828981), + ChainName::BitcoinTestnetBitlayer1 => Self(3789623672476206327), + ChainName::BitcoinTestnetBotanix => Self(1467223411771711614), + ChainName::BitcoinTestnetBsquared1 => Self(1948510578179542068), + ChainName::BitcoinTestnetMerlin => Self(5269261765892944301), + ChainName::BitcoinTestnetRootstock => Self(8953668971247136127), + ChainName::BitcoinTestnetSepoliaBob1 => Self(5535534526963509396), + ChainName::BittorrentChainMainnet => Self(3776006016387883143), + ChainName::BittorrentChainTestnet => Self(4459371029167934217), + ChainName::CeloMainnet => Self(1346049177634351622), + ChainName::CeloTestnetAlfajores => Self(3552045678561919002), + ChainName::CoinexSmartChainMainnet => Self(1761333065194157300), + ChainName::CoinexSmartChainTestnet => Self(8955032871639343000), + ChainName::CronosMainnet => Self(1456215246176062136), + ChainName::CronosTestnet => Self(2995292832068775165), + ChainName::CronosTestnetZkevm1 => Self(3842103497652714138), + ChainName::EthereumMainnet => Self(5009297550715157269), + ChainName::EthereumMainnetArbitrum1 => Self(4949039107694359620), + ChainName::EthereumMainnetArbitrum1L3x1 => Self(3162193654116181371), + ChainName::EthereumMainnetArbitrum1Treasure1 => Self(1010349088906777999), + ChainName::EthereumMainnetAstarZkevm1 => Self(1540201334317828111), + ChainName::EthereumMainnetBase1 => Self(15971525489660198786), + ChainName::EthereumMainnetBlast1 => Self(4411394078118774322), + ChainName::EthereumMainnetImmutableZkevm1 => Self(1237925231416731909), + ChainName::EthereumMainnetKroma1 => Self(3719320017875267166), + ChainName::EthereumMainnetLinea1 => Self(4627098889531055414), + ChainName::EthereumMainnetMantle1 => Self(1556008542357238666), + ChainName::EthereumMainnetMetis1 => Self(8805746078405598895), + ChainName::EthereumMainnetMode1 => Self(7264351850409363825), + ChainName::EthereumMainnetOptimism1 => Self(3734403246176062136), + ChainName::EthereumMainnetPolygonZkevm1 => Self(4348158687435793198), + ChainName::EthereumMainnetScroll1 => Self(13204309965629103672), + ChainName::EthereumMainnetTaiko1 => Self(16468599424800719238), + ChainName::EthereumMainnetWorldchain1 => Self(2049429975587534727), + ChainName::EthereumMainnetXlayer1 => Self(3016212468291539606), + ChainName::EthereumMainnetZircuit1 => Self(17198166215261833993), + ChainName::EthereumMainnetZksync1 => Self(1562403441176082196), + ChainName::EthereumTestnetGoerliArbitrum1 => Self(6101244977088475029), + ChainName::EthereumTestnetGoerliBase1 => Self(5790810961207155433), + ChainName::EthereumTestnetGoerliLinea1 => Self(1355246678561316402), + ChainName::EthereumTestnetGoerliMantle1 => Self(4168263376276232250), + ChainName::EthereumTestnetGoerliOptimism1 => Self(2664363617261496610), + ChainName::EthereumTestnetGoerliPolygonZkevm1 => Self(11059667695644972511), + ChainName::EthereumTestnetGoerliZksync1 => Self(6802309497652714138), + ChainName::EthereumTestnetHolesky => Self(7717148896336251131), + ChainName::EthereumTestnetHoleskyFraxtal1 => Self(8901520481741771655), + ChainName::EthereumTestnetHoleskyMorph1 => Self(8304510386741731151), + ChainName::EthereumTestnetHoleskyTaiko1 => Self(7248756420937879088), + ChainName::EthereumTestnetSepolia => Self(16015286601757825753), + ChainName::EthereumTestnetSepoliaArbitrum1 => Self(3478487238524512106), + ChainName::EthereumTestnetSepoliaArbitrum1L3x1 => Self(3486622437121596122), + ChainName::EthereumTestnetSepoliaArbitrum1Treasure1 => Self(10443705513486043421), + ChainName::EthereumTestnetSepoliaBase1 => Self(10344971235874465080), + ChainName::EthereumTestnetSepoliaBlast1 => Self(2027362563942762617), + ChainName::EthereumTestnetSepoliaCorn1 => Self(1467427327723633929), + ChainName::EthereumTestnetSepoliaImmutableZkevm1 => Self(4526165231216331901), + ChainName::EthereumTestnetSepoliaKroma1 => Self(5990477251245693094), + ChainName::EthereumTestnetSepoliaLens1 => Self(6827576821754315911), + ChainName::EthereumTestnetSepoliaLinea1 => Self(5719461335882077547), + ChainName::EthereumTestnetSepoliaLisk1 => Self(5298399861320400553), + ChainName::EthereumTestnetSepoliaMantle1 => Self(8236463271206331221), + ChainName::EthereumTestnetSepoliaMetis1 => Self(3777822886988675105), + ChainName::EthereumTestnetSepoliaMode1 => Self(829525985033418733), + ChainName::EthereumTestnetSepoliaOptimism1 => Self(5224473277236331295), + ChainName::EthereumTestnetSepoliaPolygonValidium1 => Self(4418231248214522936), + ChainName::EthereumTestnetSepoliaPolygonZkevm1 => Self(1654667687261492630), + ChainName::EthereumTestnetSepoliaScroll1 => Self(2279865765895943307), + ChainName::EthereumTestnetSepoliaSoneium1 => Self(686603546605904534), + ChainName::EthereumTestnetSepoliaUnichain1 => Self(14135854469784514356), + ChainName::EthereumTestnetSepoliaWorldchain1 => Self(5299555114858065850), + ChainName::EthereumTestnetSepoliaXlayer1 => Self(2066098519157881736), + ChainName::EthereumTestnetSepoliaZircuit1 => Self(4562743618362911021), + ChainName::EthereumTestnetSepoliaZksync1 => Self(6898391096552792247), + ChainName::FantomMainnet => Self(3768048213127883732), + ChainName::FantomTestnet => Self(4905564228793744293), + ChainName::FilecoinMainnet => Self(4561443241176882990), + ChainName::FilecoinTestnet => Self(7060342227814389000), + ChainName::FraxtalMainnet => Self(1462016016387883143), + ChainName::GethDevnet2 => Self(12922642891491394802), + ChainName::GethDevnet3 => Self(4793464827907405086), + ChainName::GethTestnet => Self(3379446385462418246), + ChainName::GnosisChainMainnet => Self(465200170687744372), + ChainName::GnosisChainTestnetChiado => Self(8871595565390010547), + ChainName::HederaMainnet => Self(3229138320728879060), + ChainName::HederaTestnet => Self(222782988166878823), + ChainName::HyperliquidTestnet => Self(4286062357653186312), + ChainName::KavaMainnet => Self(7550000543357438061), + ChainName::KavaTestnet => Self(2110537777356199208), + ChainName::KusamaMainnetMoonriver => Self(1355020143337428062), + ChainName::NearMainnet => Self(2039744413822257700), + ChainName::NearTestnet => Self(5061593697262339000), + ChainName::NeonlinkMainnet => Self(8239338020728974000), + ChainName::NeonlinkTestnet => Self(1113014352258747600), + ChainName::PlumeTestnet => Self(14684575664602284776), + ChainName::PolkadotMainnetAstar => Self(6422105447186081193), + ChainName::PolkadotMainnetCentrifuge => Self(8175830712062617656), + ChainName::PolkadotMainnetDarwinia => Self(8866418665544333000), + ChainName::PolkadotMainnetMoonbeam => Self(1252863800116739621), + ChainName::PolkadotTestnetAstarShibuya => Self(6955638871347136141), + ChainName::PolkadotTestnetCentrifugeAltair => Self(2333097300889804761), + ChainName::PolkadotTestnetDarwiniaPangoro => Self(4340886533089894000), + ChainName::PolkadotTestnetMoonbeamMoonbase => Self(5361632739113536121), + ChainName::PolygonMainnet => Self(4051577828743386545), + ChainName::PolygonTestnetAmoy => Self(16281711391670634445), + ChainName::PolygonTestnetMumbai => Self(12532609583862916517), + ChainName::PrivateTestnetMica => Self(4489326297382772450), + ChainName::PrivateTestnetOpala => Self(8446413392851542429), + ChainName::RoninMainnet => Self(6916147374840168594), + ChainName::RoninTestnetSaigon => Self(13116810400804392105), + ChainName::SeiMainnet => Self(9027416829622342829), + ChainName::SeiTestnetAtlantic => Self(1216300075444106652), + ChainName::SonicTestnet => Self(3676871237479449268), + ChainName::StoryTestnet => Self(4237030917318060427), + ChainName::TelosEvmMainnet => Self(1477345371608778000), + ChainName::TelosEvmTestnet => Self(729797994450396300), + ChainName::Test1000 => Self(11787463284727550157), + ChainName::Test76578 => Self(781901677223027175), + ChainName::Test90000001 => Self(909606746561742123), + ChainName::Test90000002 => Self(5548718428018410741), + ChainName::Test90000003 => Self(789068866484373046), + ChainName::Test90000004 => Self(5721565186521185178), + ChainName::Test90000005 => Self(964127714438319834), + ChainName::Test90000006 => Self(8966794841936584464), + ChainName::Test90000007 => Self(8412806778050735057), + ChainName::Test90000008 => Self(4066443121807923198), + ChainName::Test90000009 => Self(6747736380229414777), + ChainName::Test90000010 => Self(8694984074292254623), + ChainName::Test90000011 => Self(328334718812072308), + ChainName::Test90000012 => Self(7715160997071429212), + ChainName::Test90000013 => Self(3574539439524578558), + ChainName::Test90000014 => Self(4543928599863227519), + ChainName::Test90000015 => Self(6443235356619661032), + ChainName::Test90000016 => Self(13087962012083037329), + ChainName::Test90000017 => Self(11985232338641871056), + ChainName::Test90000018 => Self(7777066535355430289), + ChainName::Test90000019 => Self(1273605685587320666), + ChainName::Test90000020 => Self(17810359353458878177), + ChainName::Test90000021 => Self(13648736134397881410), + ChainName::Test90000022 => Self(6742472197519042017), + ChainName::Test90000023 => Self(16702426279731183946), + ChainName::Test90000024 => Self(16449698933146693970), + ChainName::Test90000025 => Self(5614341928911841614), + ChainName::Test90000026 => Self(9932483170498916221), + ChainName::Test90000027 => Self(9248511054298050610), + ChainName::Test90000028 => Self(15733873364998401606), + ChainName::Test90000029 => Self(10199579733509604193), + ChainName::Test90000030 => Self(11754399446572002459), + ChainName::Test90000031 => Self(15804983202763665802), + ChainName::Test90000032 => Self(8794884152664322911), + ChainName::Test90000033 => Self(7005880874640146484), + ChainName::Test90000034 => Self(15998314635132476942), + ChainName::Test90000035 => Self(6676710761873615962), + ChainName::Test90000036 => Self(13973515790491921010), + ChainName::Test90000037 => Self(12226902941055802385), + ChainName::Test90000038 => Self(10547673735879567911), + ChainName::Test90000039 => Self(2953028829530698683), + ChainName::Test90000040 => Self(3740583887329090549), + ChainName::Test90000041 => Self(4716670523656754658), + ChainName::Test90000042 => Self(12965905455277595820), + ChainName::Test90000043 => Self(6448403805635971860), + ChainName::Test90000044 => Self(176199025415897437), + ChainName::Test90000045 => Self(17251043223284625647), + ChainName::Test90000046 => Self(14943531413383612703), + ChainName::Test90000047 => Self(8015762103567576333), + ChainName::Test90000048 => Self(2783890746839497525), + ChainName::Test90000049 => Self(16591966440843528322), + ChainName::Test90000050 => Self(9156614022853705708), + ChainName::Test90000051 => Self(10089241509396411113), + ChainName::Test90000052 => Self(7585715102059681757), + ChainName::Test90000053 => Self(9574369650680012313), + ChainName::Test90000054 => Self(15767478222558315144), + ChainName::Test90000055 => Self(928756709184343973), + ChainName::Test90000056 => Self(13936493323944617843), + ChainName::Test90000057 => Self(9264503539336248559), + ChainName::Test90000058 => Self(7032045258883126022), + ChainName::Test90000059 => Self(13781595843667691007), + ChainName::Test90000060 => Self(6751512843227450641), + ChainName::Test90000061 => Self(12027427861168955422), + ChainName::Test90000062 => Self(6690738652320128159), + ChainName::Test90000063 => Self(12513826466599144030), + ChainName::Test90000064 => Self(7823363553221722351), + ChainName::Test90000065 => Self(17759418850483131633), + ChainName::Test90000066 => Self(1488785539820432596), + ChainName::Test90000067 => Self(12470167056735102403), + ChainName::Test90000068 => Self(6059917085984771915), + ChainName::Test90000069 => Self(8698844633699288298), + ChainName::Test90000070 => Self(11335955773964346155), + ChainName::Test90000071 => Self(15210860601736105873), + ChainName::Test90000072 => Self(15447447865219782832), + ChainName::Test90000073 => Self(7404045285477377670), + ChainName::Test90000074 => Self(14506622911400094011), + ChainName::Test90000075 => Self(18316006852148771137), + ChainName::Test90000076 => Self(7961714422080771198), + ChainName::Test90000077 => Self(15168140751097121912), + ChainName::Test90000078 => Self(8354317460459584308), + ChainName::Test90000079 => Self(1974710175227680991), + ChainName::Test90000080 => Self(15896959195233368219), + ChainName::Test90000081 => Self(13819071330241498802), + ChainName::Test90000082 => Self(3632230855428784129), + ChainName::Test90000083 => Self(3330151784927722907), + ChainName::Test90000084 => Self(973671184102733124), + ChainName::Test90000085 => Self(7353384334508842175), + ChainName::Test90000086 => Self(4174149892778961910), + ChainName::Test90000087 => Self(10497629267361915835), + ChainName::Test90000088 => Self(10537986502862404866), + ChainName::Test90000089 => Self(10106333385848939617), + ChainName::Test90000090 => Self(2509173735760116798), + ChainName::Test90000091 => Self(12499149790922928210), + ChainName::Test90000092 => Self(665284410079532457), + ChainName::Test90000093 => Self(17514102371649734225), + ChainName::Test90000094 => Self(8211981504472319767), + ChainName::Test90000095 => Self(15945074456050759193), + ChainName::Test90000096 => Self(17580537314894454709), + ChainName::Test90000097 => Self(13443138560923813712), + ChainName::Test90000098 => Self(9675086780529785020), + ChainName::Test90000099 => Self(7431973150957944526), + ChainName::Test90000100 => Self(6875898693582952601), + ChainName::VelasMainnet => Self(374210358663784372), + ChainName::VelasTestnet => Self(572210378683744374), + ChainName::WemixMainnet => Self(5142893604156789321), + ChainName::WemixTestnet => Self(9284632837123596123), + ChainName::ZklinkNovaMainnet => Self(4350319965322101699), + ChainName::ZklinkNovaTestnet => Self(5837261596322416298), + } + } +} + +impl TryFrom for ChainName { + type Error = Error; + + fn try_from(chain_id: ChainId) -> Result { + match chain_id.0 { + 463 => Ok(Self::AreonMainnet), + 462 => Ok(Self::AreonTestnet), + 43114 => Ok(Self::AvalancheMainnet), + 432204 => Ok(Self::AvalancheSubnetDexalotMainnet), + 432201 => Ok(Self::AvalancheSubnetDexalotTestnet), + 43113 => Ok(Self::AvalancheTestnetFuji), + 595581 => Ok(Self::AvalancheTestnetNexon), + 80085 => Ok(Self::BerachainTestnetArtio), + 80084 => Ok(Self::BerachainTestnetBartio), + 56 => Ok(Self::BinanceSmartChainMainnet), + 204 => Ok(Self::BinanceSmartChainMainnetOpbnb1), + 97 => Ok(Self::BinanceSmartChainTestnet), + 5611 => Ok(Self::BinanceSmartChainTestnetOpbnb1), + 1907 => Ok(Self::BitcichainMainnet), + 1908 => Ok(Self::BitcichainTestnet), + 200901 => Ok(Self::BitcoinMainnetBitlayer1), + 60808 => Ok(Self::BitcoinMainnetBob1), + 3637 => Ok(Self::BitcoinMainnetBotanix), + 223 => Ok(Self::BitcoinMainnetBsquared1), + 4200 => Ok(Self::BitcoinMerlinMainnet), + 200810 => Ok(Self::BitcoinTestnetBitlayer1), + 3636 => Ok(Self::BitcoinTestnetBotanix), + 1123 => Ok(Self::BitcoinTestnetBsquared1), + 686868 => Ok(Self::BitcoinTestnetMerlin), + 31 => Ok(Self::BitcoinTestnetRootstock), + 808813 => Ok(Self::BitcoinTestnetSepoliaBob1), + 199 => Ok(Self::BittorrentChainMainnet), + 1029 => Ok(Self::BittorrentChainTestnet), + 42220 => Ok(Self::CeloMainnet), + 44787 => Ok(Self::CeloTestnetAlfajores), + 52 => Ok(Self::CoinexSmartChainMainnet), + 53 => Ok(Self::CoinexSmartChainTestnet), + 25 => Ok(Self::CronosMainnet), + 338 => Ok(Self::CronosTestnet), + 282 => Ok(Self::CronosTestnetZkevm1), + 1 => Ok(Self::EthereumMainnet), + 42161 => Ok(Self::EthereumMainnetArbitrum1), + 12324 => Ok(Self::EthereumMainnetArbitrum1L3x1), + 978670 => Ok(Self::EthereumMainnetArbitrum1Treasure1), + 3776 => Ok(Self::EthereumMainnetAstarZkevm1), + 8453 => Ok(Self::EthereumMainnetBase1), + 81457 => Ok(Self::EthereumMainnetBlast1), + 13371 => Ok(Self::EthereumMainnetImmutableZkevm1), + 255 => Ok(Self::EthereumMainnetKroma1), + 59144 => Ok(Self::EthereumMainnetLinea1), + 5000 => Ok(Self::EthereumMainnetMantle1), + 1088 => Ok(Self::EthereumMainnetMetis1), + 34443 => Ok(Self::EthereumMainnetMode1), + 10 => Ok(Self::EthereumMainnetOptimism1), + 1101 => Ok(Self::EthereumMainnetPolygonZkevm1), + 534352 => Ok(Self::EthereumMainnetScroll1), + 167000 => Ok(Self::EthereumMainnetTaiko1), + 480 => Ok(Self::EthereumMainnetWorldchain1), + 196 => Ok(Self::EthereumMainnetXlayer1), + 48900 => Ok(Self::EthereumMainnetZircuit1), + 324 => Ok(Self::EthereumMainnetZksync1), + 421613 => Ok(Self::EthereumTestnetGoerliArbitrum1), + 84531 => Ok(Self::EthereumTestnetGoerliBase1), + 59140 => Ok(Self::EthereumTestnetGoerliLinea1), + 5001 => Ok(Self::EthereumTestnetGoerliMantle1), + 420 => Ok(Self::EthereumTestnetGoerliOptimism1), + 1442 => Ok(Self::EthereumTestnetGoerliPolygonZkevm1), + 280 => Ok(Self::EthereumTestnetGoerliZksync1), + 17000 => Ok(Self::EthereumTestnetHolesky), + 2522 => Ok(Self::EthereumTestnetHoleskyFraxtal1), + 2810 => Ok(Self::EthereumTestnetHoleskyMorph1), + 167009 => Ok(Self::EthereumTestnetHoleskyTaiko1), + 11155111 => Ok(Self::EthereumTestnetSepolia), + 421614 => Ok(Self::EthereumTestnetSepoliaArbitrum1), + 12325 => Ok(Self::EthereumTestnetSepoliaArbitrum1L3x1), + 978657 => Ok(Self::EthereumTestnetSepoliaArbitrum1Treasure1), + 84532 => Ok(Self::EthereumTestnetSepoliaBase1), + 168587773 => Ok(Self::EthereumTestnetSepoliaBlast1), + 21000000 => Ok(Self::EthereumTestnetSepoliaCorn1), + 13473 => Ok(Self::EthereumTestnetSepoliaImmutableZkevm1), + 2358 => Ok(Self::EthereumTestnetSepoliaKroma1), + 37111 => Ok(Self::EthereumTestnetSepoliaLens1), + 59141 => Ok(Self::EthereumTestnetSepoliaLinea1), + 4202 => Ok(Self::EthereumTestnetSepoliaLisk1), + 5003 => Ok(Self::EthereumTestnetSepoliaMantle1), + 59902 => Ok(Self::EthereumTestnetSepoliaMetis1), + 919 => Ok(Self::EthereumTestnetSepoliaMode1), + 11155420 => Ok(Self::EthereumTestnetSepoliaOptimism1), + 717160 => Ok(Self::EthereumTestnetSepoliaPolygonValidium1), + 2442 => Ok(Self::EthereumTestnetSepoliaPolygonZkevm1), + 534351 => Ok(Self::EthereumTestnetSepoliaScroll1), + 1946 => Ok(Self::EthereumTestnetSepoliaSoneium1), + 1301 => Ok(Self::EthereumTestnetSepoliaUnichain1), + 4801 => Ok(Self::EthereumTestnetSepoliaWorldchain1), + 195 => Ok(Self::EthereumTestnetSepoliaXlayer1), + 48899 => Ok(Self::EthereumTestnetSepoliaZircuit1), + 300 => Ok(Self::EthereumTestnetSepoliaZksync1), + 250 => Ok(Self::FantomMainnet), + 4002 => Ok(Self::FantomTestnet), + 314 => Ok(Self::FilecoinMainnet), + 31415926 => Ok(Self::FilecoinTestnet), + 252 => Ok(Self::FraxtalMainnet), + 2337 => Ok(Self::GethDevnet2), + 3337 => Ok(Self::GethDevnet3), + 1337 => Ok(Self::GethTestnet), + 100 => Ok(Self::GnosisChainMainnet), + 10200 => Ok(Self::GnosisChainTestnetChiado), + 295 => Ok(Self::HederaMainnet), + 296 => Ok(Self::HederaTestnet), + 998 => Ok(Self::HyperliquidTestnet), + 2222 => Ok(Self::KavaMainnet), + 2221 => Ok(Self::KavaTestnet), + 1285 => Ok(Self::KusamaMainnetMoonriver), + 397 => Ok(Self::NearMainnet), + 398 => Ok(Self::NearTestnet), + 259 => Ok(Self::NeonlinkMainnet), + 9559 => Ok(Self::NeonlinkTestnet), + 161221135 => Ok(Self::PlumeTestnet), + 592 => Ok(Self::PolkadotMainnetAstar), + 2031 => Ok(Self::PolkadotMainnetCentrifuge), + 46 => Ok(Self::PolkadotMainnetDarwinia), + 1284 => Ok(Self::PolkadotMainnetMoonbeam), + 81 => Ok(Self::PolkadotTestnetAstarShibuya), + 2088 => Ok(Self::PolkadotTestnetCentrifugeAltair), + 45 => Ok(Self::PolkadotTestnetDarwiniaPangoro), + 1287 => Ok(Self::PolkadotTestnetMoonbeamMoonbase), + 137 => Ok(Self::PolygonMainnet), + 80002 => Ok(Self::PolygonTestnetAmoy), + 80001 => Ok(Self::PolygonTestnetMumbai), + 424242 => Ok(Self::PrivateTestnetMica), + 45439 => Ok(Self::PrivateTestnetOpala), + 2020 => Ok(Self::RoninMainnet), + 2021 => Ok(Self::RoninTestnetSaigon), + 1329 => Ok(Self::SeiMainnet), + 1328 => Ok(Self::SeiTestnetAtlantic), + 64165 => Ok(Self::SonicTestnet), + 1513 => Ok(Self::StoryTestnet), + 40 => Ok(Self::TelosEvmMainnet), + 41 => Ok(Self::TelosEvmTestnet), + 1000 => Ok(Self::Test1000), + 76578 => Ok(Self::Test76578), + 90000001 => Ok(Self::Test90000001), + 90000002 => Ok(Self::Test90000002), + 90000003 => Ok(Self::Test90000003), + 90000004 => Ok(Self::Test90000004), + 90000005 => Ok(Self::Test90000005), + 90000006 => Ok(Self::Test90000006), + 90000007 => Ok(Self::Test90000007), + 90000008 => Ok(Self::Test90000008), + 90000009 => Ok(Self::Test90000009), + 90000010 => Ok(Self::Test90000010), + 90000011 => Ok(Self::Test90000011), + 90000012 => Ok(Self::Test90000012), + 90000013 => Ok(Self::Test90000013), + 90000014 => Ok(Self::Test90000014), + 90000015 => Ok(Self::Test90000015), + 90000016 => Ok(Self::Test90000016), + 90000017 => Ok(Self::Test90000017), + 90000018 => Ok(Self::Test90000018), + 90000019 => Ok(Self::Test90000019), + 90000020 => Ok(Self::Test90000020), + 90000021 => Ok(Self::Test90000021), + 90000022 => Ok(Self::Test90000022), + 90000023 => Ok(Self::Test90000023), + 90000024 => Ok(Self::Test90000024), + 90000025 => Ok(Self::Test90000025), + 90000026 => Ok(Self::Test90000026), + 90000027 => Ok(Self::Test90000027), + 90000028 => Ok(Self::Test90000028), + 90000029 => Ok(Self::Test90000029), + 90000030 => Ok(Self::Test90000030), + 90000031 => Ok(Self::Test90000031), + 90000032 => Ok(Self::Test90000032), + 90000033 => Ok(Self::Test90000033), + 90000034 => Ok(Self::Test90000034), + 90000035 => Ok(Self::Test90000035), + 90000036 => Ok(Self::Test90000036), + 90000037 => Ok(Self::Test90000037), + 90000038 => Ok(Self::Test90000038), + 90000039 => Ok(Self::Test90000039), + 90000040 => Ok(Self::Test90000040), + 90000041 => Ok(Self::Test90000041), + 90000042 => Ok(Self::Test90000042), + 90000043 => Ok(Self::Test90000043), + 90000044 => Ok(Self::Test90000044), + 90000045 => Ok(Self::Test90000045), + 90000046 => Ok(Self::Test90000046), + 90000047 => Ok(Self::Test90000047), + 90000048 => Ok(Self::Test90000048), + 90000049 => Ok(Self::Test90000049), + 90000050 => Ok(Self::Test90000050), + 90000051 => Ok(Self::Test90000051), + 90000052 => Ok(Self::Test90000052), + 90000053 => Ok(Self::Test90000053), + 90000054 => Ok(Self::Test90000054), + 90000055 => Ok(Self::Test90000055), + 90000056 => Ok(Self::Test90000056), + 90000057 => Ok(Self::Test90000057), + 90000058 => Ok(Self::Test90000058), + 90000059 => Ok(Self::Test90000059), + 90000060 => Ok(Self::Test90000060), + 90000061 => Ok(Self::Test90000061), + 90000062 => Ok(Self::Test90000062), + 90000063 => Ok(Self::Test90000063), + 90000064 => Ok(Self::Test90000064), + 90000065 => Ok(Self::Test90000065), + 90000066 => Ok(Self::Test90000066), + 90000067 => Ok(Self::Test90000067), + 90000068 => Ok(Self::Test90000068), + 90000069 => Ok(Self::Test90000069), + 90000070 => Ok(Self::Test90000070), + 90000071 => Ok(Self::Test90000071), + 90000072 => Ok(Self::Test90000072), + 90000073 => Ok(Self::Test90000073), + 90000074 => Ok(Self::Test90000074), + 90000075 => Ok(Self::Test90000075), + 90000076 => Ok(Self::Test90000076), + 90000077 => Ok(Self::Test90000077), + 90000078 => Ok(Self::Test90000078), + 90000079 => Ok(Self::Test90000079), + 90000080 => Ok(Self::Test90000080), + 90000081 => Ok(Self::Test90000081), + 90000082 => Ok(Self::Test90000082), + 90000083 => Ok(Self::Test90000083), + 90000084 => Ok(Self::Test90000084), + 90000085 => Ok(Self::Test90000085), + 90000086 => Ok(Self::Test90000086), + 90000087 => Ok(Self::Test90000087), + 90000088 => Ok(Self::Test90000088), + 90000089 => Ok(Self::Test90000089), + 90000090 => Ok(Self::Test90000090), + 90000091 => Ok(Self::Test90000091), + 90000092 => Ok(Self::Test90000092), + 90000093 => Ok(Self::Test90000093), + 90000094 => Ok(Self::Test90000094), + 90000095 => Ok(Self::Test90000095), + 90000096 => Ok(Self::Test90000096), + 90000097 => Ok(Self::Test90000097), + 90000098 => Ok(Self::Test90000098), + 90000099 => Ok(Self::Test90000099), + 90000100 => Ok(Self::Test90000100), + 106 => Ok(Self::VelasMainnet), + 111 => Ok(Self::VelasTestnet), + 1111 => Ok(Self::WemixMainnet), + 1112 => Ok(Self::WemixTestnet), + 810180 => Ok(Self::ZklinkNovaMainnet), + 810181 => Ok(Self::ZklinkNovaTestnet), + _ => Err(Error::UnknownChainId(chain_id)), + } + } +} + +impl TryFrom for ChainName { + type Error = Error; + + fn try_from(chain_selector: ChainSelector) -> Result { + match chain_selector.0 { + 1939936305787790600 => Ok(Self::AreonMainnet), + 7317911323415911000 => Ok(Self::AreonTestnet), + 6433500567565415381 => Ok(Self::AvalancheMainnet), + 5463201557265485081 => Ok(Self::AvalancheSubnetDexalotMainnet), + 1458281248224512906 => Ok(Self::AvalancheSubnetDexalotTestnet), + 14767482510784806043 => Ok(Self::AvalancheTestnetFuji), + 7837562506228496256 => Ok(Self::AvalancheTestnetNexon), + 12336603543561911511 => Ok(Self::BerachainTestnetArtio), + 8999465244383784164 => Ok(Self::BerachainTestnetBartio), + 11344663589394136015 => Ok(Self::BinanceSmartChainMainnet), + 465944652040885897 => Ok(Self::BinanceSmartChainMainnetOpbnb1), + 13264668187771770619 => Ok(Self::BinanceSmartChainTestnet), + 13274425992935471758 => Ok(Self::BinanceSmartChainTestnetOpbnb1), + 4874388048629246000 => Ok(Self::BitcichainMainnet), + 4888058894222120000 => Ok(Self::BitcichainTestnet), + 7937294810946806131 => Ok(Self::BitcoinMainnetBitlayer1), + 3849287863852499584 => Ok(Self::BitcoinMainnetBob1), + 4560701533377838164 => Ok(Self::BitcoinMainnetBotanix), + 5406759801798337480 => Ok(Self::BitcoinMainnetBsquared1), + 241851231317828981 => Ok(Self::BitcoinMerlinMainnet), + 3789623672476206327 => Ok(Self::BitcoinTestnetBitlayer1), + 1467223411771711614 => Ok(Self::BitcoinTestnetBotanix), + 1948510578179542068 => Ok(Self::BitcoinTestnetBsquared1), + 5269261765892944301 => Ok(Self::BitcoinTestnetMerlin), + 8953668971247136127 => Ok(Self::BitcoinTestnetRootstock), + 5535534526963509396 => Ok(Self::BitcoinTestnetSepoliaBob1), + 3776006016387883143 => Ok(Self::BittorrentChainMainnet), + 4459371029167934217 => Ok(Self::BittorrentChainTestnet), + 1346049177634351622 => Ok(Self::CeloMainnet), + 3552045678561919002 => Ok(Self::CeloTestnetAlfajores), + 1761333065194157300 => Ok(Self::CoinexSmartChainMainnet), + 8955032871639343000 => Ok(Self::CoinexSmartChainTestnet), + 1456215246176062136 => Ok(Self::CronosMainnet), + 2995292832068775165 => Ok(Self::CronosTestnet), + 3842103497652714138 => Ok(Self::CronosTestnetZkevm1), + 5009297550715157269 => Ok(Self::EthereumMainnet), + 4949039107694359620 => Ok(Self::EthereumMainnetArbitrum1), + 3162193654116181371 => Ok(Self::EthereumMainnetArbitrum1L3x1), + 1010349088906777999 => Ok(Self::EthereumMainnetArbitrum1Treasure1), + 1540201334317828111 => Ok(Self::EthereumMainnetAstarZkevm1), + 15971525489660198786 => Ok(Self::EthereumMainnetBase1), + 4411394078118774322 => Ok(Self::EthereumMainnetBlast1), + 1237925231416731909 => Ok(Self::EthereumMainnetImmutableZkevm1), + 3719320017875267166 => Ok(Self::EthereumMainnetKroma1), + 4627098889531055414 => Ok(Self::EthereumMainnetLinea1), + 1556008542357238666 => Ok(Self::EthereumMainnetMantle1), + 8805746078405598895 => Ok(Self::EthereumMainnetMetis1), + 7264351850409363825 => Ok(Self::EthereumMainnetMode1), + 3734403246176062136 => Ok(Self::EthereumMainnetOptimism1), + 4348158687435793198 => Ok(Self::EthereumMainnetPolygonZkevm1), + 13204309965629103672 => Ok(Self::EthereumMainnetScroll1), + 16468599424800719238 => Ok(Self::EthereumMainnetTaiko1), + 2049429975587534727 => Ok(Self::EthereumMainnetWorldchain1), + 3016212468291539606 => Ok(Self::EthereumMainnetXlayer1), + 17198166215261833993 => Ok(Self::EthereumMainnetZircuit1), + 1562403441176082196 => Ok(Self::EthereumMainnetZksync1), + 6101244977088475029 => Ok(Self::EthereumTestnetGoerliArbitrum1), + 5790810961207155433 => Ok(Self::EthereumTestnetGoerliBase1), + 1355246678561316402 => Ok(Self::EthereumTestnetGoerliLinea1), + 4168263376276232250 => Ok(Self::EthereumTestnetGoerliMantle1), + 2664363617261496610 => Ok(Self::EthereumTestnetGoerliOptimism1), + 11059667695644972511 => Ok(Self::EthereumTestnetGoerliPolygonZkevm1), + 6802309497652714138 => Ok(Self::EthereumTestnetGoerliZksync1), + 7717148896336251131 => Ok(Self::EthereumTestnetHolesky), + 8901520481741771655 => Ok(Self::EthereumTestnetHoleskyFraxtal1), + 8304510386741731151 => Ok(Self::EthereumTestnetHoleskyMorph1), + 7248756420937879088 => Ok(Self::EthereumTestnetHoleskyTaiko1), + 16015286601757825753 => Ok(Self::EthereumTestnetSepolia), + 3478487238524512106 => Ok(Self::EthereumTestnetSepoliaArbitrum1), + 3486622437121596122 => Ok(Self::EthereumTestnetSepoliaArbitrum1L3x1), + 10443705513486043421 => Ok(Self::EthereumTestnetSepoliaArbitrum1Treasure1), + 10344971235874465080 => Ok(Self::EthereumTestnetSepoliaBase1), + 2027362563942762617 => Ok(Self::EthereumTestnetSepoliaBlast1), + 1467427327723633929 => Ok(Self::EthereumTestnetSepoliaCorn1), + 4526165231216331901 => Ok(Self::EthereumTestnetSepoliaImmutableZkevm1), + 5990477251245693094 => Ok(Self::EthereumTestnetSepoliaKroma1), + 6827576821754315911 => Ok(Self::EthereumTestnetSepoliaLens1), + 5719461335882077547 => Ok(Self::EthereumTestnetSepoliaLinea1), + 5298399861320400553 => Ok(Self::EthereumTestnetSepoliaLisk1), + 8236463271206331221 => Ok(Self::EthereumTestnetSepoliaMantle1), + 3777822886988675105 => Ok(Self::EthereumTestnetSepoliaMetis1), + 829525985033418733 => Ok(Self::EthereumTestnetSepoliaMode1), + 5224473277236331295 => Ok(Self::EthereumTestnetSepoliaOptimism1), + 4418231248214522936 => Ok(Self::EthereumTestnetSepoliaPolygonValidium1), + 1654667687261492630 => Ok(Self::EthereumTestnetSepoliaPolygonZkevm1), + 2279865765895943307 => Ok(Self::EthereumTestnetSepoliaScroll1), + 686603546605904534 => Ok(Self::EthereumTestnetSepoliaSoneium1), + 14135854469784514356 => Ok(Self::EthereumTestnetSepoliaUnichain1), + 5299555114858065850 => Ok(Self::EthereumTestnetSepoliaWorldchain1), + 2066098519157881736 => Ok(Self::EthereumTestnetSepoliaXlayer1), + 4562743618362911021 => Ok(Self::EthereumTestnetSepoliaZircuit1), + 6898391096552792247 => Ok(Self::EthereumTestnetSepoliaZksync1), + 3768048213127883732 => Ok(Self::FantomMainnet), + 4905564228793744293 => Ok(Self::FantomTestnet), + 4561443241176882990 => Ok(Self::FilecoinMainnet), + 7060342227814389000 => Ok(Self::FilecoinTestnet), + 1462016016387883143 => Ok(Self::FraxtalMainnet), + 12922642891491394802 => Ok(Self::GethDevnet2), + 4793464827907405086 => Ok(Self::GethDevnet3), + 3379446385462418246 => Ok(Self::GethTestnet), + 465200170687744372 => Ok(Self::GnosisChainMainnet), + 8871595565390010547 => Ok(Self::GnosisChainTestnetChiado), + 3229138320728879060 => Ok(Self::HederaMainnet), + 222782988166878823 => Ok(Self::HederaTestnet), + 4286062357653186312 => Ok(Self::HyperliquidTestnet), + 7550000543357438061 => Ok(Self::KavaMainnet), + 2110537777356199208 => Ok(Self::KavaTestnet), + 1355020143337428062 => Ok(Self::KusamaMainnetMoonriver), + 2039744413822257700 => Ok(Self::NearMainnet), + 5061593697262339000 => Ok(Self::NearTestnet), + 8239338020728974000 => Ok(Self::NeonlinkMainnet), + 1113014352258747600 => Ok(Self::NeonlinkTestnet), + 14684575664602284776 => Ok(Self::PlumeTestnet), + 6422105447186081193 => Ok(Self::PolkadotMainnetAstar), + 8175830712062617656 => Ok(Self::PolkadotMainnetCentrifuge), + 8866418665544333000 => Ok(Self::PolkadotMainnetDarwinia), + 1252863800116739621 => Ok(Self::PolkadotMainnetMoonbeam), + 6955638871347136141 => Ok(Self::PolkadotTestnetAstarShibuya), + 2333097300889804761 => Ok(Self::PolkadotTestnetCentrifugeAltair), + 4340886533089894000 => Ok(Self::PolkadotTestnetDarwiniaPangoro), + 5361632739113536121 => Ok(Self::PolkadotTestnetMoonbeamMoonbase), + 4051577828743386545 => Ok(Self::PolygonMainnet), + 16281711391670634445 => Ok(Self::PolygonTestnetAmoy), + 12532609583862916517 => Ok(Self::PolygonTestnetMumbai), + 4489326297382772450 => Ok(Self::PrivateTestnetMica), + 8446413392851542429 => Ok(Self::PrivateTestnetOpala), + 6916147374840168594 => Ok(Self::RoninMainnet), + 13116810400804392105 => Ok(Self::RoninTestnetSaigon), + 9027416829622342829 => Ok(Self::SeiMainnet), + 1216300075444106652 => Ok(Self::SeiTestnetAtlantic), + 3676871237479449268 => Ok(Self::SonicTestnet), + 4237030917318060427 => Ok(Self::StoryTestnet), + 1477345371608778000 => Ok(Self::TelosEvmMainnet), + 729797994450396300 => Ok(Self::TelosEvmTestnet), + 11787463284727550157 => Ok(Self::Test1000), + 781901677223027175 => Ok(Self::Test76578), + 909606746561742123 => Ok(Self::Test90000001), + 5548718428018410741 => Ok(Self::Test90000002), + 789068866484373046 => Ok(Self::Test90000003), + 5721565186521185178 => Ok(Self::Test90000004), + 964127714438319834 => Ok(Self::Test90000005), + 8966794841936584464 => Ok(Self::Test90000006), + 8412806778050735057 => Ok(Self::Test90000007), + 4066443121807923198 => Ok(Self::Test90000008), + 6747736380229414777 => Ok(Self::Test90000009), + 8694984074292254623 => Ok(Self::Test90000010), + 328334718812072308 => Ok(Self::Test90000011), + 7715160997071429212 => Ok(Self::Test90000012), + 3574539439524578558 => Ok(Self::Test90000013), + 4543928599863227519 => Ok(Self::Test90000014), + 6443235356619661032 => Ok(Self::Test90000015), + 13087962012083037329 => Ok(Self::Test90000016), + 11985232338641871056 => Ok(Self::Test90000017), + 7777066535355430289 => Ok(Self::Test90000018), + 1273605685587320666 => Ok(Self::Test90000019), + 17810359353458878177 => Ok(Self::Test90000020), + 13648736134397881410 => Ok(Self::Test90000021), + 6742472197519042017 => Ok(Self::Test90000022), + 16702426279731183946 => Ok(Self::Test90000023), + 16449698933146693970 => Ok(Self::Test90000024), + 5614341928911841614 => Ok(Self::Test90000025), + 9932483170498916221 => Ok(Self::Test90000026), + 9248511054298050610 => Ok(Self::Test90000027), + 15733873364998401606 => Ok(Self::Test90000028), + 10199579733509604193 => Ok(Self::Test90000029), + 11754399446572002459 => Ok(Self::Test90000030), + 15804983202763665802 => Ok(Self::Test90000031), + 8794884152664322911 => Ok(Self::Test90000032), + 7005880874640146484 => Ok(Self::Test90000033), + 15998314635132476942 => Ok(Self::Test90000034), + 6676710761873615962 => Ok(Self::Test90000035), + 13973515790491921010 => Ok(Self::Test90000036), + 12226902941055802385 => Ok(Self::Test90000037), + 10547673735879567911 => Ok(Self::Test90000038), + 2953028829530698683 => Ok(Self::Test90000039), + 3740583887329090549 => Ok(Self::Test90000040), + 4716670523656754658 => Ok(Self::Test90000041), + 12965905455277595820 => Ok(Self::Test90000042), + 6448403805635971860 => Ok(Self::Test90000043), + 176199025415897437 => Ok(Self::Test90000044), + 17251043223284625647 => Ok(Self::Test90000045), + 14943531413383612703 => Ok(Self::Test90000046), + 8015762103567576333 => Ok(Self::Test90000047), + 2783890746839497525 => Ok(Self::Test90000048), + 16591966440843528322 => Ok(Self::Test90000049), + 9156614022853705708 => Ok(Self::Test90000050), + 10089241509396411113 => Ok(Self::Test90000051), + 7585715102059681757 => Ok(Self::Test90000052), + 9574369650680012313 => Ok(Self::Test90000053), + 15767478222558315144 => Ok(Self::Test90000054), + 928756709184343973 => Ok(Self::Test90000055), + 13936493323944617843 => Ok(Self::Test90000056), + 9264503539336248559 => Ok(Self::Test90000057), + 7032045258883126022 => Ok(Self::Test90000058), + 13781595843667691007 => Ok(Self::Test90000059), + 6751512843227450641 => Ok(Self::Test90000060), + 12027427861168955422 => Ok(Self::Test90000061), + 6690738652320128159 => Ok(Self::Test90000062), + 12513826466599144030 => Ok(Self::Test90000063), + 7823363553221722351 => Ok(Self::Test90000064), + 17759418850483131633 => Ok(Self::Test90000065), + 1488785539820432596 => Ok(Self::Test90000066), + 12470167056735102403 => Ok(Self::Test90000067), + 6059917085984771915 => Ok(Self::Test90000068), + 8698844633699288298 => Ok(Self::Test90000069), + 11335955773964346155 => Ok(Self::Test90000070), + 15210860601736105873 => Ok(Self::Test90000071), + 15447447865219782832 => Ok(Self::Test90000072), + 7404045285477377670 => Ok(Self::Test90000073), + 14506622911400094011 => Ok(Self::Test90000074), + 18316006852148771137 => Ok(Self::Test90000075), + 7961714422080771198 => Ok(Self::Test90000076), + 15168140751097121912 => Ok(Self::Test90000077), + 8354317460459584308 => Ok(Self::Test90000078), + 1974710175227680991 => Ok(Self::Test90000079), + 15896959195233368219 => Ok(Self::Test90000080), + 13819071330241498802 => Ok(Self::Test90000081), + 3632230855428784129 => Ok(Self::Test90000082), + 3330151784927722907 => Ok(Self::Test90000083), + 973671184102733124 => Ok(Self::Test90000084), + 7353384334508842175 => Ok(Self::Test90000085), + 4174149892778961910 => Ok(Self::Test90000086), + 10497629267361915835 => Ok(Self::Test90000087), + 10537986502862404866 => Ok(Self::Test90000088), + 10106333385848939617 => Ok(Self::Test90000089), + 2509173735760116798 => Ok(Self::Test90000090), + 12499149790922928210 => Ok(Self::Test90000091), + 665284410079532457 => Ok(Self::Test90000092), + 17514102371649734225 => Ok(Self::Test90000093), + 8211981504472319767 => Ok(Self::Test90000094), + 15945074456050759193 => Ok(Self::Test90000095), + 17580537314894454709 => Ok(Self::Test90000096), + 13443138560923813712 => Ok(Self::Test90000097), + 9675086780529785020 => Ok(Self::Test90000098), + 7431973150957944526 => Ok(Self::Test90000099), + 6875898693582952601 => Ok(Self::Test90000100), + 374210358663784372 => Ok(Self::VelasMainnet), + 572210378683744374 => Ok(Self::VelasTestnet), + 5142893604156789321 => Ok(Self::WemixMainnet), + 9284632837123596123 => Ok(Self::WemixTestnet), + 4350319965322101699 => Ok(Self::ZklinkNovaMainnet), + 5837261596322416298 => Ok(Self::ZklinkNovaTestnet), + _ => Err(Error::UnknownChainSelector(chain_selector)), + } + } +} + +impl FromStr for ChainName { + type Err = Error; + + fn from_str(input: &str) -> Result { + match input { + "areon-mainnet" => Ok(Self::AreonMainnet), + "areon-testnet" => Ok(Self::AreonTestnet), + "avalanche-mainnet" => Ok(Self::AvalancheMainnet), + "avalanche-subnet-dexalot-mainnet" => Ok(Self::AvalancheSubnetDexalotMainnet), + "avalanche-subnet-dexalot-testnet" => Ok(Self::AvalancheSubnetDexalotTestnet), + "avalanche-testnet-fuji" => Ok(Self::AvalancheTestnetFuji), + "avalanche-testnet-nexon" => Ok(Self::AvalancheTestnetNexon), + "berachain-testnet-artio" => Ok(Self::BerachainTestnetArtio), + "berachain-testnet-bartio" => Ok(Self::BerachainTestnetBartio), + "binance_smart_chain-mainnet" => Ok(Self::BinanceSmartChainMainnet), + "binance_smart_chain-mainnet-opbnb-1" => Ok(Self::BinanceSmartChainMainnetOpbnb1), + "binance_smart_chain-testnet" => Ok(Self::BinanceSmartChainTestnet), + "binance_smart_chain-testnet-opbnb-1" => Ok(Self::BinanceSmartChainTestnetOpbnb1), + "bitcichain-mainnet" => Ok(Self::BitcichainMainnet), + "bitcichain-testnet" => Ok(Self::BitcichainTestnet), + "bitcoin-mainnet-bitlayer-1" => Ok(Self::BitcoinMainnetBitlayer1), + "bitcoin-mainnet-bob-1" => Ok(Self::BitcoinMainnetBob1), + "bitcoin-mainnet-botanix" => Ok(Self::BitcoinMainnetBotanix), + "bitcoin-mainnet-bsquared-1" => Ok(Self::BitcoinMainnetBsquared1), + "bitcoin-merlin-mainnet" => Ok(Self::BitcoinMerlinMainnet), + "bitcoin-testnet-bitlayer-1" => Ok(Self::BitcoinTestnetBitlayer1), + "bitcoin-testnet-botanix" => Ok(Self::BitcoinTestnetBotanix), + "bitcoin-testnet-bsquared-1" => Ok(Self::BitcoinTestnetBsquared1), + "bitcoin-testnet-merlin" => Ok(Self::BitcoinTestnetMerlin), + "bitcoin-testnet-rootstock" => Ok(Self::BitcoinTestnetRootstock), + "bitcoin-testnet-sepolia-bob-1" => Ok(Self::BitcoinTestnetSepoliaBob1), + "bittorrent_chain-mainnet" => Ok(Self::BittorrentChainMainnet), + "bittorrent_chain-testnet" => Ok(Self::BittorrentChainTestnet), + "celo-mainnet" => Ok(Self::CeloMainnet), + "celo-testnet-alfajores" => Ok(Self::CeloTestnetAlfajores), + "coinex_smart_chain-mainnet" => Ok(Self::CoinexSmartChainMainnet), + "coinex_smart_chain-testnet" => Ok(Self::CoinexSmartChainTestnet), + "cronos-mainnet" => Ok(Self::CronosMainnet), + "cronos-testnet" => Ok(Self::CronosTestnet), + "cronos-testnet-zkevm-1" => Ok(Self::CronosTestnetZkevm1), + "ethereum-mainnet" => Ok(Self::EthereumMainnet), + "ethereum-mainnet-arbitrum-1" => Ok(Self::EthereumMainnetArbitrum1), + "ethereum-mainnet-arbitrum-1-l3x-1" => Ok(Self::EthereumMainnetArbitrum1L3x1), + "ethereum-mainnet-arbitrum-1-treasure-1" => Ok(Self::EthereumMainnetArbitrum1Treasure1), + "ethereum-mainnet-astar-zkevm-1" => Ok(Self::EthereumMainnetAstarZkevm1), + "ethereum-mainnet-base-1" => Ok(Self::EthereumMainnetBase1), + "ethereum-mainnet-blast-1" => Ok(Self::EthereumMainnetBlast1), + "ethereum-mainnet-immutable-zkevm-1" => Ok(Self::EthereumMainnetImmutableZkevm1), + "ethereum-mainnet-kroma-1" => Ok(Self::EthereumMainnetKroma1), + "ethereum-mainnet-linea-1" => Ok(Self::EthereumMainnetLinea1), + "ethereum-mainnet-mantle-1" => Ok(Self::EthereumMainnetMantle1), + "ethereum-mainnet-metis-1" => Ok(Self::EthereumMainnetMetis1), + "ethereum-mainnet-mode-1" => Ok(Self::EthereumMainnetMode1), + "ethereum-mainnet-optimism-1" => Ok(Self::EthereumMainnetOptimism1), + "ethereum-mainnet-polygon-zkevm-1" => Ok(Self::EthereumMainnetPolygonZkevm1), + "ethereum-mainnet-scroll-1" => Ok(Self::EthereumMainnetScroll1), + "ethereum-mainnet-taiko-1" => Ok(Self::EthereumMainnetTaiko1), + "ethereum-mainnet-worldchain-1" => Ok(Self::EthereumMainnetWorldchain1), + "ethereum-mainnet-xlayer-1" => Ok(Self::EthereumMainnetXlayer1), + "ethereum-mainnet-zircuit-1" => Ok(Self::EthereumMainnetZircuit1), + "ethereum-mainnet-zksync-1" => Ok(Self::EthereumMainnetZksync1), + "ethereum-testnet-goerli-arbitrum-1" => Ok(Self::EthereumTestnetGoerliArbitrum1), + "ethereum-testnet-goerli-base-1" => Ok(Self::EthereumTestnetGoerliBase1), + "ethereum-testnet-goerli-linea-1" => Ok(Self::EthereumTestnetGoerliLinea1), + "ethereum-testnet-goerli-mantle-1" => Ok(Self::EthereumTestnetGoerliMantle1), + "ethereum-testnet-goerli-optimism-1" => Ok(Self::EthereumTestnetGoerliOptimism1), + "ethereum-testnet-goerli-polygon-zkevm-1" => { + Ok(Self::EthereumTestnetGoerliPolygonZkevm1) + } + "ethereum-testnet-goerli-zksync-1" => Ok(Self::EthereumTestnetGoerliZksync1), + "ethereum-testnet-holesky" => Ok(Self::EthereumTestnetHolesky), + "ethereum-testnet-holesky-fraxtal-1" => Ok(Self::EthereumTestnetHoleskyFraxtal1), + "ethereum-testnet-holesky-morph-1" => Ok(Self::EthereumTestnetHoleskyMorph1), + "ethereum-testnet-holesky-taiko-1" => Ok(Self::EthereumTestnetHoleskyTaiko1), + "ethereum-testnet-sepolia" => Ok(Self::EthereumTestnetSepolia), + "ethereum-testnet-sepolia-arbitrum-1" => Ok(Self::EthereumTestnetSepoliaArbitrum1), + "ethereum-testnet-sepolia-arbitrum-1-l3x-1" => { + Ok(Self::EthereumTestnetSepoliaArbitrum1L3x1) + } + "ethereum-testnet-sepolia-arbitrum-1-treasure-1" => { + Ok(Self::EthereumTestnetSepoliaArbitrum1Treasure1) + } + "ethereum-testnet-sepolia-base-1" => Ok(Self::EthereumTestnetSepoliaBase1), + "ethereum-testnet-sepolia-blast-1" => Ok(Self::EthereumTestnetSepoliaBlast1), + "ethereum-testnet-sepolia-corn-1" => Ok(Self::EthereumTestnetSepoliaCorn1), + "ethereum-testnet-sepolia-immutable-zkevm-1" => { + Ok(Self::EthereumTestnetSepoliaImmutableZkevm1) + } + "ethereum-testnet-sepolia-kroma-1" => Ok(Self::EthereumTestnetSepoliaKroma1), + "ethereum-testnet-sepolia-lens-1" => Ok(Self::EthereumTestnetSepoliaLens1), + "ethereum-testnet-sepolia-linea-1" => Ok(Self::EthereumTestnetSepoliaLinea1), + "ethereum-testnet-sepolia-lisk-1" => Ok(Self::EthereumTestnetSepoliaLisk1), + "ethereum-testnet-sepolia-mantle-1" => Ok(Self::EthereumTestnetSepoliaMantle1), + "ethereum-testnet-sepolia-metis-1" => Ok(Self::EthereumTestnetSepoliaMetis1), + "ethereum-testnet-sepolia-mode-1" => Ok(Self::EthereumTestnetSepoliaMode1), + "ethereum-testnet-sepolia-optimism-1" => Ok(Self::EthereumTestnetSepoliaOptimism1), + "ethereum-testnet-sepolia-polygon-validium-1" => { + Ok(Self::EthereumTestnetSepoliaPolygonValidium1) + } + "ethereum-testnet-sepolia-polygon-zkevm-1" => { + Ok(Self::EthereumTestnetSepoliaPolygonZkevm1) + } + "ethereum-testnet-sepolia-scroll-1" => Ok(Self::EthereumTestnetSepoliaScroll1), + "ethereum-testnet-sepolia-soneium-1" => Ok(Self::EthereumTestnetSepoliaSoneium1), + "ethereum-testnet-sepolia-unichain-1" => Ok(Self::EthereumTestnetSepoliaUnichain1), + "ethereum-testnet-sepolia-worldchain-1" => Ok(Self::EthereumTestnetSepoliaWorldchain1), + "ethereum-testnet-sepolia-xlayer-1" => Ok(Self::EthereumTestnetSepoliaXlayer1), + "ethereum-testnet-sepolia-zircuit-1" => Ok(Self::EthereumTestnetSepoliaZircuit1), + "ethereum-testnet-sepolia-zksync-1" => Ok(Self::EthereumTestnetSepoliaZksync1), + "fantom-mainnet" => Ok(Self::FantomMainnet), + "fantom-testnet" => Ok(Self::FantomTestnet), + "filecoin-mainnet" => Ok(Self::FilecoinMainnet), + "filecoin-testnet" => Ok(Self::FilecoinTestnet), + "fraxtal-mainnet" => Ok(Self::FraxtalMainnet), + "geth-devnet-2" => Ok(Self::GethDevnet2), + "geth-devnet-3" => Ok(Self::GethDevnet3), + "geth-testnet" => Ok(Self::GethTestnet), + "gnosis_chain-mainnet" => Ok(Self::GnosisChainMainnet), + "gnosis_chain-testnet-chiado" => Ok(Self::GnosisChainTestnetChiado), + "hedera-mainnet" => Ok(Self::HederaMainnet), + "hedera-testnet" => Ok(Self::HederaTestnet), + "hyperliquid-testnet" => Ok(Self::HyperliquidTestnet), + "kava-mainnet" => Ok(Self::KavaMainnet), + "kava-testnet" => Ok(Self::KavaTestnet), + "kusama-mainnet-moonriver" => Ok(Self::KusamaMainnetMoonriver), + "near-mainnet" => Ok(Self::NearMainnet), + "near-testnet" => Ok(Self::NearTestnet), + "neonlink-mainnet" => Ok(Self::NeonlinkMainnet), + "neonlink-testnet" => Ok(Self::NeonlinkTestnet), + "plume-testnet" => Ok(Self::PlumeTestnet), + "polkadot-mainnet-astar" => Ok(Self::PolkadotMainnetAstar), + "polkadot-mainnet-centrifuge" => Ok(Self::PolkadotMainnetCentrifuge), + "polkadot-mainnet-darwinia" => Ok(Self::PolkadotMainnetDarwinia), + "polkadot-mainnet-moonbeam" => Ok(Self::PolkadotMainnetMoonbeam), + "polkadot-testnet-astar-shibuya" => Ok(Self::PolkadotTestnetAstarShibuya), + "polkadot-testnet-centrifuge-altair" => Ok(Self::PolkadotTestnetCentrifugeAltair), + "polkadot-testnet-darwinia-pangoro" => Ok(Self::PolkadotTestnetDarwiniaPangoro), + "polkadot-testnet-moonbeam-moonbase" => Ok(Self::PolkadotTestnetMoonbeamMoonbase), + "polygon-mainnet" => Ok(Self::PolygonMainnet), + "polygon-testnet-amoy" => Ok(Self::PolygonTestnetAmoy), + "polygon-testnet-mumbai" => Ok(Self::PolygonTestnetMumbai), + "private-testnet-mica" => Ok(Self::PrivateTestnetMica), + "private-testnet-opala" => Ok(Self::PrivateTestnetOpala), + "ronin-mainnet" => Ok(Self::RoninMainnet), + "ronin-testnet-saigon" => Ok(Self::RoninTestnetSaigon), + "sei-mainnet" => Ok(Self::SeiMainnet), + "sei-testnet-atlantic" => Ok(Self::SeiTestnetAtlantic), + "sonic-testnet" => Ok(Self::SonicTestnet), + "story-testnet" => Ok(Self::StoryTestnet), + "telos-evm-mainnet" => Ok(Self::TelosEvmMainnet), + "telos-evm-testnet" => Ok(Self::TelosEvmTestnet), + "1000" => Ok(Self::Test1000), + "76578" => Ok(Self::Test76578), + "90000001" => Ok(Self::Test90000001), + "90000002" => Ok(Self::Test90000002), + "90000003" => Ok(Self::Test90000003), + "90000004" => Ok(Self::Test90000004), + "90000005" => Ok(Self::Test90000005), + "90000006" => Ok(Self::Test90000006), + "90000007" => Ok(Self::Test90000007), + "90000008" => Ok(Self::Test90000008), + "90000009" => Ok(Self::Test90000009), + "90000010" => Ok(Self::Test90000010), + "90000011" => Ok(Self::Test90000011), + "90000012" => Ok(Self::Test90000012), + "90000013" => Ok(Self::Test90000013), + "90000014" => Ok(Self::Test90000014), + "90000015" => Ok(Self::Test90000015), + "90000016" => Ok(Self::Test90000016), + "90000017" => Ok(Self::Test90000017), + "90000018" => Ok(Self::Test90000018), + "90000019" => Ok(Self::Test90000019), + "90000020" => Ok(Self::Test90000020), + "90000021" => Ok(Self::Test90000021), + "90000022" => Ok(Self::Test90000022), + "90000023" => Ok(Self::Test90000023), + "90000024" => Ok(Self::Test90000024), + "90000025" => Ok(Self::Test90000025), + "90000026" => Ok(Self::Test90000026), + "90000027" => Ok(Self::Test90000027), + "90000028" => Ok(Self::Test90000028), + "90000029" => Ok(Self::Test90000029), + "90000030" => Ok(Self::Test90000030), + "90000031" => Ok(Self::Test90000031), + "90000032" => Ok(Self::Test90000032), + "90000033" => Ok(Self::Test90000033), + "90000034" => Ok(Self::Test90000034), + "90000035" => Ok(Self::Test90000035), + "90000036" => Ok(Self::Test90000036), + "90000037" => Ok(Self::Test90000037), + "90000038" => Ok(Self::Test90000038), + "90000039" => Ok(Self::Test90000039), + "90000040" => Ok(Self::Test90000040), + "90000041" => Ok(Self::Test90000041), + "90000042" => Ok(Self::Test90000042), + "90000043" => Ok(Self::Test90000043), + "90000044" => Ok(Self::Test90000044), + "90000045" => Ok(Self::Test90000045), + "90000046" => Ok(Self::Test90000046), + "90000047" => Ok(Self::Test90000047), + "90000048" => Ok(Self::Test90000048), + "90000049" => Ok(Self::Test90000049), + "90000050" => Ok(Self::Test90000050), + "90000051" => Ok(Self::Test90000051), + "90000052" => Ok(Self::Test90000052), + "90000053" => Ok(Self::Test90000053), + "90000054" => Ok(Self::Test90000054), + "90000055" => Ok(Self::Test90000055), + "90000056" => Ok(Self::Test90000056), + "90000057" => Ok(Self::Test90000057), + "90000058" => Ok(Self::Test90000058), + "90000059" => Ok(Self::Test90000059), + "90000060" => Ok(Self::Test90000060), + "90000061" => Ok(Self::Test90000061), + "90000062" => Ok(Self::Test90000062), + "90000063" => Ok(Self::Test90000063), + "90000064" => Ok(Self::Test90000064), + "90000065" => Ok(Self::Test90000065), + "90000066" => Ok(Self::Test90000066), + "90000067" => Ok(Self::Test90000067), + "90000068" => Ok(Self::Test90000068), + "90000069" => Ok(Self::Test90000069), + "90000070" => Ok(Self::Test90000070), + "90000071" => Ok(Self::Test90000071), + "90000072" => Ok(Self::Test90000072), + "90000073" => Ok(Self::Test90000073), + "90000074" => Ok(Self::Test90000074), + "90000075" => Ok(Self::Test90000075), + "90000076" => Ok(Self::Test90000076), + "90000077" => Ok(Self::Test90000077), + "90000078" => Ok(Self::Test90000078), + "90000079" => Ok(Self::Test90000079), + "90000080" => Ok(Self::Test90000080), + "90000081" => Ok(Self::Test90000081), + "90000082" => Ok(Self::Test90000082), + "90000083" => Ok(Self::Test90000083), + "90000084" => Ok(Self::Test90000084), + "90000085" => Ok(Self::Test90000085), + "90000086" => Ok(Self::Test90000086), + "90000087" => Ok(Self::Test90000087), + "90000088" => Ok(Self::Test90000088), + "90000089" => Ok(Self::Test90000089), + "90000090" => Ok(Self::Test90000090), + "90000091" => Ok(Self::Test90000091), + "90000092" => Ok(Self::Test90000092), + "90000093" => Ok(Self::Test90000093), + "90000094" => Ok(Self::Test90000094), + "90000095" => Ok(Self::Test90000095), + "90000096" => Ok(Self::Test90000096), + "90000097" => Ok(Self::Test90000097), + "90000098" => Ok(Self::Test90000098), + "90000099" => Ok(Self::Test90000099), + "90000100" => Ok(Self::Test90000100), + "velas-mainnet" => Ok(Self::VelasMainnet), + "velas-testnet" => Ok(Self::VelasTestnet), + "wemix-mainnet" => Ok(Self::WemixMainnet), + "wemix-testnet" => Ok(Self::WemixTestnet), + "zklink_nova-mainnet" => Ok(Self::ZklinkNovaMainnet), + "zklink_nova-testnet" => Ok(Self::ZklinkNovaTestnet), + _ => Err(Error::UnknownChainName(input.to_string())), + } + } +} + +impl Display for ChainName { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!( + f, + "{}", + match self { + Self::AreonMainnet => "areon-mainnet", + Self::AreonTestnet => "areon-testnet", + Self::AvalancheMainnet => "avalanche-mainnet", + Self::AvalancheSubnetDexalotMainnet => "avalanche-subnet-dexalot-mainnet", + Self::AvalancheSubnetDexalotTestnet => "avalanche-subnet-dexalot-testnet", + Self::AvalancheTestnetFuji => "avalanche-testnet-fuji", + Self::AvalancheTestnetNexon => "avalanche-testnet-nexon", + Self::BerachainTestnetArtio => "berachain-testnet-artio", + Self::BerachainTestnetBartio => "berachain-testnet-bartio", + Self::BinanceSmartChainMainnet => "binance_smart_chain-mainnet", + Self::BinanceSmartChainMainnetOpbnb1 => "binance_smart_chain-mainnet-opbnb-1", + Self::BinanceSmartChainTestnet => "binance_smart_chain-testnet", + Self::BinanceSmartChainTestnetOpbnb1 => "binance_smart_chain-testnet-opbnb-1", + Self::BitcichainMainnet => "bitcichain-mainnet", + Self::BitcichainTestnet => "bitcichain-testnet", + Self::BitcoinMainnetBitlayer1 => "bitcoin-mainnet-bitlayer-1", + Self::BitcoinMainnetBob1 => "bitcoin-mainnet-bob-1", + Self::BitcoinMainnetBotanix => "bitcoin-mainnet-botanix", + Self::BitcoinMainnetBsquared1 => "bitcoin-mainnet-bsquared-1", + Self::BitcoinMerlinMainnet => "bitcoin-merlin-mainnet", + Self::BitcoinTestnetBitlayer1 => "bitcoin-testnet-bitlayer-1", + Self::BitcoinTestnetBotanix => "bitcoin-testnet-botanix", + Self::BitcoinTestnetBsquared1 => "bitcoin-testnet-bsquared-1", + Self::BitcoinTestnetMerlin => "bitcoin-testnet-merlin", + Self::BitcoinTestnetRootstock => "bitcoin-testnet-rootstock", + Self::BitcoinTestnetSepoliaBob1 => "bitcoin-testnet-sepolia-bob-1", + Self::BittorrentChainMainnet => "bittorrent_chain-mainnet", + Self::BittorrentChainTestnet => "bittorrent_chain-testnet", + Self::CeloMainnet => "celo-mainnet", + Self::CeloTestnetAlfajores => "celo-testnet-alfajores", + Self::CoinexSmartChainMainnet => "coinex_smart_chain-mainnet", + Self::CoinexSmartChainTestnet => "coinex_smart_chain-testnet", + Self::CronosMainnet => "cronos-mainnet", + Self::CronosTestnet => "cronos-testnet", + Self::CronosTestnetZkevm1 => "cronos-testnet-zkevm-1", + Self::EthereumMainnet => "ethereum-mainnet", + Self::EthereumMainnetArbitrum1 => "ethereum-mainnet-arbitrum-1", + Self::EthereumMainnetArbitrum1L3x1 => "ethereum-mainnet-arbitrum-1-l3x-1", + Self::EthereumMainnetArbitrum1Treasure1 => "ethereum-mainnet-arbitrum-1-treasure-1", + Self::EthereumMainnetAstarZkevm1 => "ethereum-mainnet-astar-zkevm-1", + Self::EthereumMainnetBase1 => "ethereum-mainnet-base-1", + Self::EthereumMainnetBlast1 => "ethereum-mainnet-blast-1", + Self::EthereumMainnetImmutableZkevm1 => "ethereum-mainnet-immutable-zkevm-1", + Self::EthereumMainnetKroma1 => "ethereum-mainnet-kroma-1", + Self::EthereumMainnetLinea1 => "ethereum-mainnet-linea-1", + Self::EthereumMainnetMantle1 => "ethereum-mainnet-mantle-1", + Self::EthereumMainnetMetis1 => "ethereum-mainnet-metis-1", + Self::EthereumMainnetMode1 => "ethereum-mainnet-mode-1", + Self::EthereumMainnetOptimism1 => "ethereum-mainnet-optimism-1", + Self::EthereumMainnetPolygonZkevm1 => "ethereum-mainnet-polygon-zkevm-1", + Self::EthereumMainnetScroll1 => "ethereum-mainnet-scroll-1", + Self::EthereumMainnetTaiko1 => "ethereum-mainnet-taiko-1", + Self::EthereumMainnetWorldchain1 => "ethereum-mainnet-worldchain-1", + Self::EthereumMainnetXlayer1 => "ethereum-mainnet-xlayer-1", + Self::EthereumMainnetZircuit1 => "ethereum-mainnet-zircuit-1", + Self::EthereumMainnetZksync1 => "ethereum-mainnet-zksync-1", + Self::EthereumTestnetGoerliArbitrum1 => "ethereum-testnet-goerli-arbitrum-1", + Self::EthereumTestnetGoerliBase1 => "ethereum-testnet-goerli-base-1", + Self::EthereumTestnetGoerliLinea1 => "ethereum-testnet-goerli-linea-1", + Self::EthereumTestnetGoerliMantle1 => "ethereum-testnet-goerli-mantle-1", + Self::EthereumTestnetGoerliOptimism1 => "ethereum-testnet-goerli-optimism-1", + Self::EthereumTestnetGoerliPolygonZkevm1 => + "ethereum-testnet-goerli-polygon-zkevm-1", + Self::EthereumTestnetGoerliZksync1 => "ethereum-testnet-goerli-zksync-1", + Self::EthereumTestnetHolesky => "ethereum-testnet-holesky", + Self::EthereumTestnetHoleskyFraxtal1 => "ethereum-testnet-holesky-fraxtal-1", + Self::EthereumTestnetHoleskyMorph1 => "ethereum-testnet-holesky-morph-1", + Self::EthereumTestnetHoleskyTaiko1 => "ethereum-testnet-holesky-taiko-1", + Self::EthereumTestnetSepolia => "ethereum-testnet-sepolia", + Self::EthereumTestnetSepoliaArbitrum1 => "ethereum-testnet-sepolia-arbitrum-1", + Self::EthereumTestnetSepoliaArbitrum1L3x1 => + "ethereum-testnet-sepolia-arbitrum-1-l3x-1", + Self::EthereumTestnetSepoliaArbitrum1Treasure1 => + "ethereum-testnet-sepolia-arbitrum-1-treasure-1", + Self::EthereumTestnetSepoliaBase1 => "ethereum-testnet-sepolia-base-1", + Self::EthereumTestnetSepoliaBlast1 => "ethereum-testnet-sepolia-blast-1", + Self::EthereumTestnetSepoliaCorn1 => "ethereum-testnet-sepolia-corn-1", + Self::EthereumTestnetSepoliaImmutableZkevm1 => + "ethereum-testnet-sepolia-immutable-zkevm-1", + Self::EthereumTestnetSepoliaKroma1 => "ethereum-testnet-sepolia-kroma-1", + Self::EthereumTestnetSepoliaLens1 => "ethereum-testnet-sepolia-lens-1", + Self::EthereumTestnetSepoliaLinea1 => "ethereum-testnet-sepolia-linea-1", + Self::EthereumTestnetSepoliaLisk1 => "ethereum-testnet-sepolia-lisk-1", + Self::EthereumTestnetSepoliaMantle1 => "ethereum-testnet-sepolia-mantle-1", + Self::EthereumTestnetSepoliaMetis1 => "ethereum-testnet-sepolia-metis-1", + Self::EthereumTestnetSepoliaMode1 => "ethereum-testnet-sepolia-mode-1", + Self::EthereumTestnetSepoliaOptimism1 => "ethereum-testnet-sepolia-optimism-1", + Self::EthereumTestnetSepoliaPolygonValidium1 => + "ethereum-testnet-sepolia-polygon-validium-1", + Self::EthereumTestnetSepoliaPolygonZkevm1 => + "ethereum-testnet-sepolia-polygon-zkevm-1", + Self::EthereumTestnetSepoliaScroll1 => "ethereum-testnet-sepolia-scroll-1", + Self::EthereumTestnetSepoliaSoneium1 => "ethereum-testnet-sepolia-soneium-1", + Self::EthereumTestnetSepoliaUnichain1 => "ethereum-testnet-sepolia-unichain-1", + Self::EthereumTestnetSepoliaWorldchain1 => "ethereum-testnet-sepolia-worldchain-1", + Self::EthereumTestnetSepoliaXlayer1 => "ethereum-testnet-sepolia-xlayer-1", + Self::EthereumTestnetSepoliaZircuit1 => "ethereum-testnet-sepolia-zircuit-1", + Self::EthereumTestnetSepoliaZksync1 => "ethereum-testnet-sepolia-zksync-1", + Self::FantomMainnet => "fantom-mainnet", + Self::FantomTestnet => "fantom-testnet", + Self::FilecoinMainnet => "filecoin-mainnet", + Self::FilecoinTestnet => "filecoin-testnet", + Self::FraxtalMainnet => "fraxtal-mainnet", + Self::GethDevnet2 => "geth-devnet-2", + Self::GethDevnet3 => "geth-devnet-3", + Self::GethTestnet => "geth-testnet", + Self::GnosisChainMainnet => "gnosis_chain-mainnet", + Self::GnosisChainTestnetChiado => "gnosis_chain-testnet-chiado", + Self::HederaMainnet => "hedera-mainnet", + Self::HederaTestnet => "hedera-testnet", + Self::HyperliquidTestnet => "hyperliquid-testnet", + Self::KavaMainnet => "kava-mainnet", + Self::KavaTestnet => "kava-testnet", + Self::KusamaMainnetMoonriver => "kusama-mainnet-moonriver", + Self::NearMainnet => "near-mainnet", + Self::NearTestnet => "near-testnet", + Self::NeonlinkMainnet => "neonlink-mainnet", + Self::NeonlinkTestnet => "neonlink-testnet", + Self::PlumeTestnet => "plume-testnet", + Self::PolkadotMainnetAstar => "polkadot-mainnet-astar", + Self::PolkadotMainnetCentrifuge => "polkadot-mainnet-centrifuge", + Self::PolkadotMainnetDarwinia => "polkadot-mainnet-darwinia", + Self::PolkadotMainnetMoonbeam => "polkadot-mainnet-moonbeam", + Self::PolkadotTestnetAstarShibuya => "polkadot-testnet-astar-shibuya", + Self::PolkadotTestnetCentrifugeAltair => "polkadot-testnet-centrifuge-altair", + Self::PolkadotTestnetDarwiniaPangoro => "polkadot-testnet-darwinia-pangoro", + Self::PolkadotTestnetMoonbeamMoonbase => "polkadot-testnet-moonbeam-moonbase", + Self::PolygonMainnet => "polygon-mainnet", + Self::PolygonTestnetAmoy => "polygon-testnet-amoy", + Self::PolygonTestnetMumbai => "polygon-testnet-mumbai", + Self::PrivateTestnetMica => "private-testnet-mica", + Self::PrivateTestnetOpala => "private-testnet-opala", + Self::RoninMainnet => "ronin-mainnet", + Self::RoninTestnetSaigon => "ronin-testnet-saigon", + Self::SeiMainnet => "sei-mainnet", + Self::SeiTestnetAtlantic => "sei-testnet-atlantic", + Self::SonicTestnet => "sonic-testnet", + Self::StoryTestnet => "story-testnet", + Self::TelosEvmMainnet => "telos-evm-mainnet", + Self::TelosEvmTestnet => "telos-evm-testnet", + Self::Test1000 => "1000", + Self::Test76578 => "76578", + Self::Test90000001 => "90000001", + Self::Test90000002 => "90000002", + Self::Test90000003 => "90000003", + Self::Test90000004 => "90000004", + Self::Test90000005 => "90000005", + Self::Test90000006 => "90000006", + Self::Test90000007 => "90000007", + Self::Test90000008 => "90000008", + Self::Test90000009 => "90000009", + Self::Test90000010 => "90000010", + Self::Test90000011 => "90000011", + Self::Test90000012 => "90000012", + Self::Test90000013 => "90000013", + Self::Test90000014 => "90000014", + Self::Test90000015 => "90000015", + Self::Test90000016 => "90000016", + Self::Test90000017 => "90000017", + Self::Test90000018 => "90000018", + Self::Test90000019 => "90000019", + Self::Test90000020 => "90000020", + Self::Test90000021 => "90000021", + Self::Test90000022 => "90000022", + Self::Test90000023 => "90000023", + Self::Test90000024 => "90000024", + Self::Test90000025 => "90000025", + Self::Test90000026 => "90000026", + Self::Test90000027 => "90000027", + Self::Test90000028 => "90000028", + Self::Test90000029 => "90000029", + Self::Test90000030 => "90000030", + Self::Test90000031 => "90000031", + Self::Test90000032 => "90000032", + Self::Test90000033 => "90000033", + Self::Test90000034 => "90000034", + Self::Test90000035 => "90000035", + Self::Test90000036 => "90000036", + Self::Test90000037 => "90000037", + Self::Test90000038 => "90000038", + Self::Test90000039 => "90000039", + Self::Test90000040 => "90000040", + Self::Test90000041 => "90000041", + Self::Test90000042 => "90000042", + Self::Test90000043 => "90000043", + Self::Test90000044 => "90000044", + Self::Test90000045 => "90000045", + Self::Test90000046 => "90000046", + Self::Test90000047 => "90000047", + Self::Test90000048 => "90000048", + Self::Test90000049 => "90000049", + Self::Test90000050 => "90000050", + Self::Test90000051 => "90000051", + Self::Test90000052 => "90000052", + Self::Test90000053 => "90000053", + Self::Test90000054 => "90000054", + Self::Test90000055 => "90000055", + Self::Test90000056 => "90000056", + Self::Test90000057 => "90000057", + Self::Test90000058 => "90000058", + Self::Test90000059 => "90000059", + Self::Test90000060 => "90000060", + Self::Test90000061 => "90000061", + Self::Test90000062 => "90000062", + Self::Test90000063 => "90000063", + Self::Test90000064 => "90000064", + Self::Test90000065 => "90000065", + Self::Test90000066 => "90000066", + Self::Test90000067 => "90000067", + Self::Test90000068 => "90000068", + Self::Test90000069 => "90000069", + Self::Test90000070 => "90000070", + Self::Test90000071 => "90000071", + Self::Test90000072 => "90000072", + Self::Test90000073 => "90000073", + Self::Test90000074 => "90000074", + Self::Test90000075 => "90000075", + Self::Test90000076 => "90000076", + Self::Test90000077 => "90000077", + Self::Test90000078 => "90000078", + Self::Test90000079 => "90000079", + Self::Test90000080 => "90000080", + Self::Test90000081 => "90000081", + Self::Test90000082 => "90000082", + Self::Test90000083 => "90000083", + Self::Test90000084 => "90000084", + Self::Test90000085 => "90000085", + Self::Test90000086 => "90000086", + Self::Test90000087 => "90000087", + Self::Test90000088 => "90000088", + Self::Test90000089 => "90000089", + Self::Test90000090 => "90000090", + Self::Test90000091 => "90000091", + Self::Test90000092 => "90000092", + Self::Test90000093 => "90000093", + Self::Test90000094 => "90000094", + Self::Test90000095 => "90000095", + Self::Test90000096 => "90000096", + Self::Test90000097 => "90000097", + Self::Test90000098 => "90000098", + Self::Test90000099 => "90000099", + Self::Test90000100 => "90000100", + Self::VelasMainnet => "velas-mainnet", + Self::VelasTestnet => "velas-testnet", + Self::WemixMainnet => "wemix-mainnet", + Self::WemixTestnet => "wemix-testnet", + Self::ZklinkNovaMainnet => "zklink_nova-mainnet", + Self::ZklinkNovaTestnet => "zklink_nova-testnet", + } + ) + } +} diff --git a/rs/chainselectors/src/lib.rs b/rs/chainselectors/src/lib.rs new file mode 100644 index 0000000..6a0dce6 --- /dev/null +++ b/rs/chainselectors/src/lib.rs @@ -0,0 +1,65 @@ +pub mod generated_chains; + +#[cfg(test)] +mod tests { + use super::*; + + use generated_chains::{ChainId, ChainName, ChainSelector}; + use std::str::FromStr; + + #[test] + fn chain_from_id() { + assert_eq!( + ChainName::try_from(ChainId(1)).unwrap(), + ChainName::EthereumMainnet, + ); + } + + #[test] + fn chain_from_unknown_id() { + assert_eq!( + ChainName::try_from(ChainId(0)).unwrap_err().to_string(), + "unknown chain id: 0", + ); + } + + #[test] + fn chain_from_str() { + assert_eq!( + ChainName::from_str("ethereum-mainnet").unwrap(), + ChainName::EthereumMainnet, + ); + } + + #[test] + fn chain_from_str_unknown() { + let e = ChainName::from_str("ethereum-dummy-x").unwrap_err(); + assert_eq!(e.to_string(), "unknown chain name: ethereum-dummy-x"); + } + + #[test] + fn chain_selector_from_chain() { + assert_eq!( + ChainSelector::from(ChainName::EthereumMainnet), + ChainSelector(5009297550715157269), + ); + } + + #[test] + fn chain_from_selector() { + assert_eq!( + ChainName::try_from(ChainSelector(5009297550715157269)).unwrap(), + ChainName::EthereumMainnet, + ); + } + + #[test] + fn chain_from_selector_unknown() { + assert_eq!( + ChainName::try_from(ChainSelector(1)) + .unwrap_err() + .to_string(), + "unknown chain selector: 1" + ); + } +} diff --git a/rs/gen.go b/rs/gen.go new file mode 100644 index 0000000..f1760b0 --- /dev/null +++ b/rs/gen.go @@ -0,0 +1,3 @@ +package rs + +//go:generate go run genchains_rs.go diff --git a/rs/genchains_rs.go b/rs/genchains_rs.go new file mode 100644 index 0000000..1630217 --- /dev/null +++ b/rs/genchains_rs.go @@ -0,0 +1,123 @@ +//go:build ignore + +package main + +import ( + "fmt" + "os" + "os/exec" + "path" + "regexp" + "strconv" + "strings" + "text/template" + "unicode" + + "github.com/smartcontractkit/chain-selectors/internal/gotmpl" + "golang.org/x/text/cases" + "golang.org/x/text/language" +) + +const ( + generatedFileName = "generated_chains.rs" + tmplFileName = "generated_chains.rs.tmpl" +) + +func wd() string { + rsDir := os.Getenv("PWD") + if !strings.HasSuffix(rsDir, "/rs") { + rsDir = path.Join(rsDir, "rs") + } + return rsDir +} + +func main() { + rsDir := wd() + tmplRaw, err := os.ReadFile(path.Join(rsDir, tmplFileName)) + if err != nil { + panic(fmt.Errorf("failed to read template file: %w", err)) + } + tmpl, err := template.New(generatedFileName).Parse(string(tmplRaw)) + if err != nil { + panic(fmt.Errorf("failed to parse template: %w", err)) + } + + generatedFilePath := path.Join(rsDir, "chainselectors", "src", generatedFileName) + existingContent, err := os.ReadFile(generatedFilePath) + if err != nil { + panic(fmt.Errorf("failed to read existing file: %w", err)) + } + + raw, err := gotmpl.Run(tmpl, newRustNameEncoder()) + if err != nil { + panic(fmt.Errorf("failed to run go-template: %w", err)) + } + + formatted, err := rustfmt([]byte(raw)) + if err != nil { + panic(fmt.Errorf("failed to format rust code: %w", err)) + } + + if string(existingContent) == string(formatted) { + fmt.Println("rust: no changes detected") + return + } + + if err := os.WriteFile(generatedFilePath, formatted, 0644); err != nil { + panic(fmt.Errorf("failed to update %s: %w", generatedFileName, err)) + } +} + +func rustfmt(src []byte) ([]byte, error) { + tmpFile := path.Join(os.TempDir(), generatedFileName) + if err := os.WriteFile(tmpFile, src, 0644); err != nil { + return nil, err + } + defer os.Remove(tmpFile) + + cmd := exec.Command("rustfmt", tmpFile) + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + // if rustfmt is not installed, try to use docker + vol := fmt.Sprintf("%s:/usr/src/app/%s", tmpFile, generatedFileName) + rustfmtCmd := fmt.Sprintf("rustup component add rustfmt &>/dev/null && rustfmt %s", generatedFileName) + if dockerErr := exec.Command( + "docker", "run", "--rm", + "-v", vol, "-w", "/usr/src/app", + "rust:1.82-alpine", + "/bin/sh", "-c", rustfmtCmd, + ).Run(); dockerErr != nil { + return nil, err + } + } + formatted, err := os.ReadFile(tmpFile) + if err != nil { + return nil, err + } + + return formatted, nil +} + +type rustNameEncoder struct { + re *regexp.Regexp + caser cases.Caser +} + +func newRustNameEncoder() *rustNameEncoder { + return &rustNameEncoder{ + re: regexp.MustCompile("[-_]+"), + caser: cases.Title(language.English), + } +} + +func (enc *rustNameEncoder) VarName(name string, chainSel uint64) string { + x := enc.re.ReplaceAllString(name, " ") + varName := strings.ReplaceAll(enc.caser.String(x), " ", "") + if len(varName) > 0 && unicode.IsDigit(rune(varName[0])) { + varName = "Test" + varName + } + if len(varName) == 0 { + varName = "Test" + strconv.FormatUint(chainSel, 10) + } + return varName +} diff --git a/rs/generated_chains.rs.tmpl b/rs/generated_chains.rs.tmpl new file mode 100644 index 0000000..4262408 --- /dev/null +++ b/rs/generated_chains.rs.tmpl @@ -0,0 +1,118 @@ +// Code generated by go generate ./rs please DO NOT EDIT + +use std::{ + fmt::{Display, Formatter, Result as FmtResult}, + str::FromStr, +}; +use thiserror::Error; + +#[derive(Error, Debug, PartialEq, Eq, Clone)] +pub enum Error { + #[error("unknown chain name: {0}")] + UnknownChainName(String), + #[error("unknown chain id: {0}")] + UnknownChainId(ChainId), + #[error("unknown chain selector: {0}")] + UnknownChainSelector(ChainSelector), +} + +#[derive( + Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize, PartialOrd, Ord, +)] +pub struct ChainId(pub u64); + +impl Display for ChainId { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!(f, "{}", self.0) + } +} + +#[derive( + Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize, PartialOrd, Ord, +)] +pub struct ChainSelector(pub u64); + +impl Display for ChainSelector { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!(f, "{}", self.0) + } +} + +#[derive( + Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize, PartialOrd, Ord, +)] +#[repr(u64)] +pub enum ChainName { +{{- range .}} + {{ .VarName }} = {{ .EvmChainID }}, +{{- end}} +} + +impl From for ChainId { + fn from(chain_name: ChainName) -> ChainId { + ChainId(chain_name as u64) + } +} + +impl From for ChainSelector { + fn from(chain: ChainName) -> Self { + match chain { + {{- range .}} + ChainName::{{ .VarName }} => Self({{ .Selector }}), + {{- end}} + } + } +} + +impl TryFrom for ChainName { + type Error = Error; + + fn try_from(chain_id: ChainId) -> Result { + match chain_id.0 { + {{- range .}} + {{ .EvmChainID }} => Ok(Self::{{ .VarName }}), + {{- end}} + _ => Err(Error::UnknownChainId(chain_id)), + } + } +} + +impl TryFrom for ChainName { + type Error = Error; + + fn try_from(chain_selector: ChainSelector) -> Result { + match chain_selector.0 { + {{- range .}} + {{ .Selector }} => Ok(Self::{{ .VarName }}), + {{- end}} + _ => Err(Error::UnknownChainSelector(chain_selector)), + } + } +} + +impl FromStr for ChainName { + type Err = Error; + + fn from_str(input: &str) -> Result { + match input { + {{- range .}} + "{{ .Name }}" => Ok(Self::{{ .VarName }}), + {{- end}} + _ => Err(Error::UnknownChainName(input.to_string())), + } + } +} + +impl Display for ChainName { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!( + f, + "{}", + match self { + {{- range .}} + Self::{{ .VarName }} => "{{ .Name }}", + {{- end}} + } + ) + } +} diff --git a/selectors_test.go b/selectors_test.go index 7ae78e6..b31ba0b 100644 --- a/selectors_test.go +++ b/selectors_test.go @@ -20,7 +20,7 @@ func TestNoSameChainSelectorsAreGenerated(t *testing.T) { } func TestNoOverlapBetweenRealAndTestChains(t *testing.T) { - for k, _ := range selectorsMap { + for k := range selectorsMap { _, exist := testSelectorsMap[k] assert.False(t, exist, "Chain %d is duplicated between real and test chains", k) }