foundry_evm_networks/
lib.rs1use crate::celo::transfer::{
6 CELO_TRANSFER_ADDRESS, CELO_TRANSFER_LABEL, PRECOMPILE_ID_CELO_TRANSFER,
7};
8use alloy_chains::NamedChain;
9use alloy_evm::precompiles::PrecompilesMap;
10use alloy_primitives::{Address, map::AddressHashMap};
11use clap::Parser;
12use serde::{Deserialize, Serialize};
13use std::collections::BTreeMap;
14
15pub mod celo;
16
17#[derive(Clone, Debug, Default, Parser, Copy, Serialize, Deserialize)]
18pub struct NetworkConfigs {
19 #[arg(help_heading = "Networks", long, visible_alias = "optimism")]
21 #[serde(skip)]
23 pub optimism: bool,
24 #[arg(help_heading = "Networks", long)]
26 pub celo: bool,
27}
28
29impl NetworkConfigs {
30 pub fn with_optimism() -> Self {
31 Self { optimism: true, ..Default::default() }
32 }
33
34 pub fn with_chain_id(mut self, chain_id: u64) -> Self {
35 if let Ok(NamedChain::Celo | NamedChain::CeloSepolia) = NamedChain::try_from(chain_id) {
36 self.celo = true;
37 }
38 self
39 }
40
41 pub fn inject_precompiles(self, precompiles: &mut PrecompilesMap) {
43 if self.celo {
44 precompiles.apply_precompile(&CELO_TRANSFER_ADDRESS, move |_| {
45 Some(celo::transfer::precompile())
46 });
47 }
48 }
49
50 pub fn precompiles_label(self) -> AddressHashMap<String> {
52 let mut labels = AddressHashMap::default();
53 if self.celo {
54 labels.insert(CELO_TRANSFER_ADDRESS, CELO_TRANSFER_LABEL.to_string());
55 }
56 labels
57 }
58
59 pub fn precompiles(self) -> BTreeMap<String, Address> {
61 let mut precompiles = BTreeMap::new();
62 if self.celo {
63 precompiles
64 .insert(PRECOMPILE_ID_CELO_TRANSFER.name().to_string(), CELO_TRANSFER_ADDRESS);
65 }
66 precompiles
67 }
68}