Skip to main content

foundry_common/
constants.rs

1//! Commonly used constants.
2
3use alloy_primitives::{Address, address};
4use std::time::Duration;
5
6/// The dev chain-id, inherited from hardhat
7pub const DEV_CHAIN_ID: u64 = 31337;
8
9/// The first four bytes of the call data for a function call specifies the function to be called.
10pub const SELECTOR_LEN: usize = 4;
11
12/// Default request timeout for http requests
13///
14/// Note: this is only used so that connections, that are discarded on the server side won't stay
15/// open forever. We assume some nodes may have some backoff baked into them and will delay some
16/// responses. This timeout should be a reasonable amount of time to wait for a request.
17pub const REQUEST_TIMEOUT: Duration = Duration::from_secs(45);
18
19/// Alchemy free tier cups: <https://docs.alchemy.com/reference/pricing-plans>
20pub const ALCHEMY_FREE_TIER_CUPS: u64 = 330;
21
22/// Logged when an error is indicative that the user is trying to fork from a non-archive node.
23pub const NON_ARCHIVE_NODE_WARNING: &str = "\
24It looks like you're trying to fork from an older block with a non-archive node which is not \
25supported. Please try to change your RPC url to an archive node if the issue persists.";
26
27/// Arbitrum L1 sender address of the first transaction in every block.
28/// `0x00000000000000000000000000000000000a4b05`
29pub const ARBITRUM_SENDER: Address = address!("0x00000000000000000000000000000000000a4b05");
30
31/// The system address, the sender of the first transaction in every block:
32/// `0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001`
33///
34/// See also <https://github.com/ethereum-optimism/optimism/blob/65ec61dde94ffa93342728d324fecf474d228e1f/specs/deposits.md#l1-attributes-deposited-transaction>
35pub const OPTIMISM_SYSTEM_ADDRESS: Address = address!("0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001");
36
37/// The system address, the sender of the first transaction in every block:
38pub const MONAD_SYSTEM_ADDRESS: Address = address!("0x6f49a8F621353f12378d0046E7d7e4b9B249DC9e");
39
40/// HyperEVM system address that credits HyperCore -> HyperEVM native transfers.
41///
42/// These are legacy envelopes with `gasPrice = 0` and a receipt `gasUsed` of `0`, so replaying one
43/// as a regular transaction fails base fee validation and aborts the whole block replay.
44pub const HYPERLIQUID_SYSTEM_ADDRESS: Address = Address::repeat_byte(0x22);
45
46/// MegaETH system address for `Set Slots` in the MegaETH oracle.
47///
48/// Transactions from this sender are submitted with gas price 0.
49///
50/// See: <https://mega.etherscan.io/address/0xa887dcb9d5f39ef79272801d05abdf707cfbbd1d>
51pub const MEGA_SYSTEM_ADDRESS: Address = address!("0xa887dcb9d5f39ef79272801d05abdf707cfbbd1d");
52
53/// Transaction identifier of System transaction types
54pub const SYSTEM_TRANSACTION_TYPE: u8 = 126;
55
56/// Default user agent set as the header for requests that don't specify one.
57pub const DEFAULT_USER_AGENT: &str = concat!("foundry/", env!("CARGO_PKG_VERSION"));
58
59/// Prefix for auto-generated type bindings using `forge bind-json`.
60pub const TYPE_BINDING_PREFIX: &str = "string constant schema_";
61
62/// Returns whether the sender is a known L2 system sender that is the first tx in every block.
63///
64/// Transactions from these senders usually don't have a any fee information OR set absurdly high fees that exceed the gas limit (See: <https://github.com/foundry-rs/foundry/pull/10608>)
65///
66/// See: [ARBITRUM_SENDER], [OPTIMISM_SYSTEM_ADDRESS], [MONAD_SYSTEM_ADDRESS],
67/// [MEGA_SYSTEM_ADDRESS], [HYPERLIQUID_SYSTEM_ADDRESS] and [Address::ZERO]
68pub fn is_known_system_sender(sender: Address) -> bool {
69    [
70        ARBITRUM_SENDER,
71        OPTIMISM_SYSTEM_ADDRESS,
72        MONAD_SYSTEM_ADDRESS,
73        MEGA_SYSTEM_ADDRESS,
74        HYPERLIQUID_SYSTEM_ADDRESS,
75        Address::ZERO,
76    ]
77    .contains(&sender)
78}
79
80#[cfg(test)]
81mod tests {
82    use super::*;
83
84    #[test]
85    fn test_constant_sender() {
86        let arb = address!("0x00000000000000000000000000000000000a4b05");
87        assert_eq!(arb, ARBITRUM_SENDER);
88        let base = address!("0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001");
89        assert_eq!(base, OPTIMISM_SYSTEM_ADDRESS);
90    }
91}