-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.rs
More file actions
132 lines (114 loc) · 3.92 KB
/
main.rs
File metadata and controls
132 lines (114 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! EV Deployer — genesis alloc generator for ev-reth contracts.
use clap::{Parser, Subcommand};
use ev_deployer::{config, genesis, output};
use std::path::PathBuf;
/// EV Deployer: generate genesis alloc entries for ev-reth contracts.
#[derive(Parser)]
#[command(
name = "ev-deployer",
about = "Generate genesis alloc for ev-reth contracts"
)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
/// Generate a starter config file with all supported contracts commented out.
Init {
/// Write config to this file instead of stdout.
#[arg(long)]
output: Option<PathBuf>,
},
/// Generate genesis alloc JSON from a deploy config.
Genesis {
/// Path to the deploy TOML config.
#[arg(long)]
config: PathBuf,
/// Write alloc JSON to this file instead of stdout.
#[arg(long)]
output: Option<PathBuf>,
/// Merge alloc entries into an existing genesis JSON file.
#[arg(long)]
merge_into: Option<PathBuf>,
/// Allow overwriting existing addresses when merging.
#[arg(long, default_value_t = false)]
force: bool,
/// Write an address manifest to this file.
#[arg(long)]
addresses_out: Option<PathBuf>,
},
/// Compute the address for a configured contract.
ComputeAddress {
/// Path to the deploy TOML config.
#[arg(long)]
config: PathBuf,
/// Contract name (e.g. `admin_proxy`).
#[arg(long)]
contract: String,
},
}
fn main() -> eyre::Result<()> {
let cli = Cli::parse();
match cli.command {
Command::Genesis {
config: config_path,
output,
merge_into,
force,
addresses_out,
} => {
let cfg = config::DeployConfig::load(&config_path)?;
let result = if let Some(ref genesis_path) = merge_into {
genesis::merge_into(&cfg, genesis_path, force)?
} else {
genesis::build_alloc(&cfg)
};
let json = serde_json::to_string_pretty(&result)?;
if let Some(ref out_path) = output {
std::fs::write(out_path, &json)?;
eprintln!("Wrote alloc to {}", out_path.display());
} else {
println!("{json}");
}
if let Some(ref addr_path) = addresses_out {
let manifest = output::build_manifest(&cfg);
let manifest_json = serde_json::to_string_pretty(&manifest)?;
std::fs::write(addr_path, &manifest_json)?;
eprintln!("Wrote address manifest to {}", addr_path.display());
}
}
Command::Init { output } => {
let template = include_str!("init_template.toml");
if let Some(ref out_path) = output {
std::fs::write(out_path, template)?;
eprintln!("Wrote config to {}", out_path.display());
} else {
print!("{template}");
}
}
Command::ComputeAddress {
config: config_path,
contract,
} => {
let cfg = config::DeployConfig::load(&config_path)?;
let address = match contract.as_str() {
"admin_proxy" => cfg
.contracts
.admin_proxy
.as_ref()
.map(|c| c.address)
.ok_or_else(|| eyre::eyre!("admin_proxy not configured"))?,
"permit2" => cfg
.contracts
.permit2
.as_ref()
.map(|c| c.address)
.ok_or_else(|| eyre::eyre!("permit2 not configured"))?,
other => eyre::bail!("unknown contract: {other}"),
};
println!("{address}");
}
}
Ok(())
}