Skip to main content

vanity_miner/createx/
config.rs

1use alloy_primitives::{Address, B256, ChainId};
2use serde::{Deserialize, Serialize};
3
4#[cfg(target_arch = "wasm32")]
5use crate::wasm_serde;
6
7/// Configuration for the Create3 mining process via CreateX.
8#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
9pub struct Create3Config {
10    /// The address of the CreateX factory contract.
11    pub deployer: Address,
12    /// Permissioned deploy protection for that address.
13    pub caller: Option<Address>,
14    /// Cross-chain deployment protection.
15    pub chain_id: Option<ChainId>,
16    /// The maximum number of attempts before giving up.
17    #[cfg_attr(
18        target_arch = "wasm32",
19        serde(deserialize_with = "wasm_serde::deserialize_u64")
20    )]
21    pub max_iterations: u64,
22    /// The maximum number of results to find.
23    #[cfg_attr(
24        target_arch = "wasm32",
25        serde(deserialize_with = "wasm_serde::deserialize_u64")
26    )]
27    pub max_results: u64,
28    /// Seed for the random number generator.
29    #[cfg_attr(
30        target_arch = "wasm32",
31        serde(deserialize_with = "wasm_serde::deserialize_option_u128")
32    )]
33    pub seed: Option<u128>,
34}
35
36/// A single successful match from a Create3 mining operation.
37#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
38pub struct Create3Match {
39    /// The raw salt that satisfies the config and predicate.
40    pub salt: B256,
41    /// The guarded salt after the `CreateX#_guard` logic is applied.
42    pub guarded_salt: B256,
43    /// The final, computed contract address.
44    pub computed_address: Address,
45}
46
47/// Result structure that includes Create3 matches and total iterations.
48#[derive(Debug, Serialize, Deserialize)]
49pub struct Create3Result {
50    /// The found matches.
51    pub results: Vec<Create3Match>,
52    /// Total number of iterations performed.
53    #[cfg_attr(
54        target_arch = "wasm32",
55        serde(serialize_with = "crate::wasm_serde::serialize_usize")
56    )]
57    pub total_iterations: usize,
58}
59
60/// Configuration for the Create2 mining process
61#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
62pub struct Create2Config {
63    /// The address of the CreateX factory contract.
64    pub deployer: Address,
65    /// The init code hash to use for the CREATE2 address.
66    pub init_code_hash: B256,
67    /// The maximum number of attempts before giving up.
68    #[cfg_attr(
69        target_arch = "wasm32",
70        serde(deserialize_with = "wasm_serde::deserialize_u64")
71    )]
72    pub max_iterations: u64,
73    /// The maximum number of results to find.
74    #[cfg_attr(
75        target_arch = "wasm32",
76        serde(deserialize_with = "wasm_serde::deserialize_u64")
77    )]
78    pub max_results: u64,
79    /// Seed for the random number generator.
80    #[cfg_attr(
81        target_arch = "wasm32",
82        serde(deserialize_with = "wasm_serde::deserialize_option_u128")
83    )]
84    pub seed: Option<u128>,
85}
86
87/// A single successful match from a Create2 mining operation.
88#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
89pub struct Create2Match {
90    /// The raw salt that satisfies the config and predicate.
91    pub salt: B256,
92    /// The final, computed contract address.
93    pub computed_address: Address,
94}
95
96/// Result structure that includes Create2 matches and total iterations.
97#[derive(Debug, Serialize, Deserialize)]
98pub struct Create2Result {
99    /// The found matches.
100    pub results: Vec<Create2Match>,
101    /// Total number of iterations performed.
102    #[cfg_attr(
103        target_arch = "wasm32",
104        serde(serialize_with = "crate::wasm_serde::serialize_usize")
105    )]
106    pub total_iterations: usize,
107}