Skip to content

Commit 868bd3a

Browse files
committed
fix(ev-deployer): address clippy lints and nightly rustfmt imports
1 parent 58dd78a commit 868bd3a

4 files changed

Lines changed: 74 additions & 65 deletions

File tree

bin/ev-deployer/src/deploy/create2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use alloy_primitives::{keccak256, Address, Bytes, B256};
44

55
/// The deterministic deployer factory address (Nick's factory).
6-
/// See: https://github.com/Arachnid/deterministic-deployment-proxy
6+
/// See: <https://github.com/Arachnid/deterministic-deployment-proxy>
77
pub(crate) const DETERMINISTIC_DEPLOYER: Address = Address::new(alloy_primitives::hex!(
88
"4e59b44847b379578588920ca78fbf26c0b4956c"
99
));
@@ -41,7 +41,7 @@ mod tests {
4141
let initcode = hex!("60006000f3");
4242
let addr = compute_address(salt, &initcode);
4343

44-
let init_hash = keccak256(&initcode);
44+
let init_hash = keccak256(initcode);
4545
let expected = DETERMINISTIC_DEPLOYER.create2(salt, init_hash);
4646
assert_eq!(addr, expected);
4747
}

bin/ev-deployer/src/deploy/deployer.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
//! ChainDeployer trait and LiveDeployer implementation.
1+
//! `ChainDeployer` trait and `LiveDeployer` implementation.
22
33
use crate::deploy::create2::{build_factory_calldata, DETERMINISTIC_DEPLOYER};
4-
use alloy::network::EthereumWallet;
5-
use alloy::providers::{Provider, ProviderBuilder};
4+
use alloy::{
5+
network::EthereumWallet,
6+
providers::{Provider, ProviderBuilder},
7+
};
68
use alloy_primitives::{Address, Bytes, B256};
79
use alloy_rpc_types_eth::TransactionRequest;
810
use alloy_signer_local::PrivateKeySigner;
@@ -35,7 +37,7 @@ pub(crate) struct LiveDeployer {
3537
}
3638

3739
impl LiveDeployer {
38-
/// Create a new LiveDeployer from an RPC URL and a hex-encoded private key.
40+
/// Create a new `LiveDeployer` from an RPC URL and a hex-encoded private key.
3941
pub(crate) fn new(rpc_url: &str, private_key_hex: &str) -> eyre::Result<Self> {
4042
let key_hex = private_key_hex
4143
.strip_prefix("0x")

bin/ev-deployer/src/deploy/pipeline.rs

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
//! Deploy pipeline: orchestrates the full deployment flow.
22
3-
use crate::config::DeployConfig;
4-
use crate::contracts;
5-
use crate::deploy::create2::{compute_address, DETERMINISTIC_DEPLOYER};
6-
use crate::deploy::deployer::ChainDeployer;
7-
use crate::deploy::state::{ContractState, ContractStatus, DeployState};
3+
use crate::{
4+
config::DeployConfig,
5+
contracts,
6+
deploy::{
7+
create2::{compute_address, DETERMINISTIC_DEPLOYER},
8+
deployer::ChainDeployer,
9+
state::{ContractState, ContractStatus, DeployState},
10+
},
11+
};
812
use alloy_primitives::{Address, B256};
913
use std::path::{Path, PathBuf};
1014

@@ -68,31 +72,25 @@ pub(crate) async fn run(
6872
deploy_contract(
6973
deployer,
7074
&mut state,
71-
"admin_proxy",
72-
address,
73-
salt,
74-
&initcode,
75-
contracts::admin_proxy::ADMIN_PROXY_BYTECODE,
76-
&pipeline_cfg.state_path,
75+
&DeployContractParams {
76+
name: "admin_proxy",
77+
address,
78+
salt,
79+
initcode: &initcode,
80+
expected_runtime: contracts::admin_proxy::ADMIN_PROXY_BYTECODE,
81+
state_path: &pipeline_cfg.state_path,
82+
},
7783
)
7884
.await?;
7985
} else {
8086
eprintln!("[3/5] AdminProxy not configured, skipping");
8187
}
8288

8389
// ── Step 3: Deploy Permit2 ──
84-
if pipeline_cfg.config.contracts.permit2.is_some() {
90+
if let Some(ref p2_config) = pipeline_cfg.config.contracts.permit2 {
8591
eprintln!("[4/5] Deploying Permit2...");
8692

87-
if pipeline_cfg
88-
.config
89-
.contracts
90-
.permit2
91-
.as_ref()
92-
.unwrap()
93-
.address
94-
.is_some()
95-
{
93+
if p2_config.address.is_some() {
9694
eprintln!(" WARN: contracts.permit2.address is ignored in deploy mode");
9795
}
9896

@@ -104,12 +102,14 @@ pub(crate) async fn run(
104102
deploy_contract(
105103
deployer,
106104
&mut state,
107-
"permit2",
108-
address,
109-
salt,
110-
&initcode,
111-
&expected_runtime,
112-
&pipeline_cfg.state_path,
105+
&DeployContractParams {
106+
name: "permit2",
107+
address,
108+
salt,
109+
initcode: &initcode,
110+
expected_runtime: &expected_runtime,
111+
state_path: &pipeline_cfg.state_path,
112+
},
113113
)
114114
.await?;
115115
} else {
@@ -139,25 +139,38 @@ pub(crate) async fn run(
139139
Ok(())
140140
}
141141

142-
/// Build AdminProxy initcode with constructor argument.
142+
/// Build `AdminProxy` initcode with constructor argument.
143143
fn build_admin_proxy_initcode(owner: Address) -> Vec<u8> {
144144
let mut initcode = contracts::admin_proxy::ADMIN_PROXY_INITCODE.to_vec();
145145
// ABI-encode the owner address as a 32-byte word and append
146146
initcode.extend_from_slice(owner.into_word().as_slice());
147147
initcode
148148
}
149149

150+
/// Parameters for deploying a single contract.
151+
struct DeployContractParams<'a> {
152+
name: &'a str,
153+
address: Address,
154+
salt: B256,
155+
initcode: &'a [u8],
156+
expected_runtime: &'a [u8],
157+
state_path: &'a Path,
158+
}
159+
150160
/// Deploy a single contract via CREATE2 with idempotency.
151161
async fn deploy_contract(
152162
deployer: &dyn ChainDeployer,
153163
state: &mut DeployState,
154-
name: &str,
155-
address: Address,
156-
salt: B256,
157-
initcode: &[u8],
158-
expected_runtime: &[u8],
159-
state_path: &Path,
164+
params: &DeployContractParams<'_>,
160165
) -> eyre::Result<()> {
166+
let DeployContractParams {
167+
name,
168+
address,
169+
salt,
170+
initcode,
171+
expected_runtime,
172+
state_path,
173+
} = params;
161174
// Check if already deployed or verified in state
162175
let current_status = get_contract_status(state, name);
163176
if current_status >= Some(ContractStatus::Deployed) {
@@ -166,32 +179,31 @@ async fn deploy_contract(
166179
}
167180

168181
// Idempotency: check if code already exists on-chain
169-
let existing_code = deployer.get_code(address).await?;
182+
let existing_code = deployer.get_code(*address).await?;
170183
if !existing_code.is_empty() {
171-
if existing_code.as_ref() == expected_runtime {
184+
if existing_code.as_ref() == *expected_runtime {
172185
eprintln!(" found matching bytecode at {address}, marking as deployed");
173186
set_contract_state(
174187
state,
175188
name,
176189
ContractState {
177190
status: ContractStatus::Deployed,
178-
address,
191+
address: *address,
179192
deploy_tx: None,
180193
},
181194
);
182195
state.save(state_path)?;
183196
return Ok(());
184-
} else {
185-
eyre::bail!(
186-
"unexpected bytecode at {address}: expected {} bytes, found {} bytes",
187-
expected_runtime.len(),
188-
existing_code.len()
189-
);
190197
}
198+
eyre::bail!(
199+
"unexpected bytecode at {address}: expected {} bytes, found {} bytes",
200+
expected_runtime.len(),
201+
existing_code.len()
202+
);
191203
}
192204

193205
// Deploy
194-
let receipt = deployer.deploy_create2(salt, initcode).await?;
206+
let receipt = deployer.deploy_create2(*salt, initcode).await?;
195207
eyre::ensure!(
196208
receipt.success,
197209
"CREATE2 deploy tx reverted for {name}: tx={}",
@@ -205,7 +217,7 @@ async fn deploy_contract(
205217
name,
206218
ContractState {
207219
status: ContractStatus::Deployed,
208-
address,
220+
address: *address,
209221
deploy_tx: Some(receipt.tx_hash),
210222
},
211223
);
@@ -294,12 +306,10 @@ fn build_deploy_manifest(state: &DeployState) -> serde_json::Value {
294306
#[cfg(test)]
295307
mod tests {
296308
use super::*;
297-
use crate::config::*;
298-
use crate::deploy::deployer::TxReceipt;
309+
use crate::{config::*, deploy::deployer::TxReceipt};
299310
use alloy_primitives::{address, Bytes};
300311
use async_trait::async_trait;
301-
use std::collections::HashMap;
302-
use std::sync::Mutex;
312+
use std::{collections::HashMap, sync::Mutex};
303313

304314
/// Mock deployer for testing the pipeline without a live chain.
305315
struct MockDeployer {

bin/ev-deployer/src/deploy/state.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ mod tests {
207207

208208
#[test]
209209
fn immutability_rejects_chain_id_change() {
210-
let config = test_config();
211-
let state = DeployState::new(&config);
212-
let mut changed = config.clone();
210+
let mut changed = test_config();
211+
let state = DeployState::new(&changed);
213212
changed.chain.chain_id = 9999;
214213
let err = state
215214
.validate_immutability(&changed)
@@ -220,9 +219,8 @@ mod tests {
220219

221220
#[test]
222221
fn immutability_rejects_owner_change() {
223-
let config = test_config();
224-
let state = DeployState::new(&config);
225-
let mut changed = config.clone();
222+
let mut changed = test_config();
223+
let state = DeployState::new(&changed);
226224
changed.contracts.admin_proxy.as_mut().unwrap().owner =
227225
address!("0000000000000000000000000000000000000001");
228226
let err = state
@@ -247,16 +245,15 @@ mod tests {
247245
let state = DeployState::new(&config);
248246

249247
// Now add permit2 — this should be allowed
250-
let mut extended = config.clone();
248+
let mut extended = config;
251249
extended.contracts.permit2 = Some(Permit2Config { address: None });
252250
assert!(state.validate_immutability(&extended).is_ok());
253251
}
254252

255253
#[test]
256254
fn immutability_rejects_removing_contract() {
257-
let config = test_config();
258-
let state = DeployState::new(&config);
259-
let mut changed = config.clone();
255+
let mut changed = test_config();
256+
let state = DeployState::new(&changed);
260257
changed.contracts.admin_proxy = None;
261258
let err = state
262259
.validate_immutability(&changed)

0 commit comments

Comments
 (0)