espresso_contract_deployer/proposals/
proposal_toml.rs1use alloy::primitives::{Address, B256, U256};
4use anyhow::{Context, Result};
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
8pub struct ProposalToml {
9 pub contract: String,
11 pub network: String,
13 pub chain_id: u64,
15 pub proxy: Address,
17 #[serde(rename = "impl")]
19 pub new_impl: Address,
20 pub timelock: Address,
22 pub salt: B256,
24 pub delay: u64,
26 pub predecessor: B256,
28
29 pub schedule: PhaseToml,
30 pub execute: PhaseToml,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
34pub struct PhaseToml {
35 pub safe: Address,
37 pub nonce: u64,
39 pub domain: B256,
41 pub message: B256,
43 pub safe_tx: B256,
45}
46
47impl ProposalToml {
48 pub fn load(dir: &std::path::Path) -> Result<Self> {
49 let p = dir.join("proposal.toml");
50 let text =
51 std::fs::read_to_string(&p).with_context(|| format!("cannot read {}", p.display()))?;
52 toml::from_str(&text).with_context(|| format!("failed to parse {}", p.display()))
53 }
54
55 pub fn write(&self, dir: &std::path::Path) -> Result<()> {
56 let p = dir.join("proposal.toml");
57 let text = toml::to_string_pretty(self).context("failed to serialize proposal.toml")?;
58 let full = format!(
60 "# Generated by `deploy`; validated by `deploy verify-proposal` and CI. Do not \
61 hand-edit.\n{text}"
62 );
63 std::fs::write(&p, full).with_context(|| format!("failed to write {}", p.display()))
64 }
65
66 pub fn delay_u256(&self) -> U256 {
68 U256::from(self.delay)
69 }
70
71 pub fn predecessor_b256(&self) -> B256 {
73 self.predecessor
74 }
75}