Skip to content

Commit

Permalink
evm/constants: use sync::LazyLock
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <delweng@gmail.com>
  • Loading branch information
jsvisa committed Nov 8, 2024
1 parent b63826a commit 5e254e0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/evm/core/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy_primitives::{address, b256, hex, hex::FromHex, Address, B256};
use std::sync::LazyLock;

/// The cheatcode handler address.
///
Expand Down Expand Up @@ -47,15 +48,21 @@ pub const DEFAULT_CREATE2_DEPLOYER_CODE: &[u8] = &hex!("604580600e600039806000f3
/// The runtime code of the default CREATE2 deployer.
pub const DEFAULT_CREATE2_DEPLOYER_RUNTIME_CODE: &[u8] = &hex!("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3");

/// The address that deploys the default CREATE2 deployer contract.
pub fn get_create2_deployer() -> Address {
/// The lazily initialized CREATE2 deployer address that can be configured via environment
/// variable or the default one.
pub static CREATE2_DEPLOYER: LazyLock<Address> = LazyLock::new(|| {
match std::env::var("FOUNDRY_CREATE2_DEPLOYER") {
Ok(addr) => Address::from_hex(addr).unwrap_or_else(|_| {
error!("env FOUNDRY_CREATE2_DEPLOYER is set, but not a valid Ethereum address, use {DEFAULT_CREATE2_DEPLOYER} instead");
DEFAULT_CREATE2_DEPLOYER
}),
Err(_) => DEFAULT_CREATE2_DEPLOYER,
}
});

/// The address that deploys the default CREATE2 deployer contract.
pub fn get_create2_deployer() -> Address {
*CREATE2_DEPLOYER
}

#[cfg(test)]
Expand Down

0 comments on commit 5e254e0

Please sign in to comment.