Skip to content

Commit

Permalink
script: wrap create2_deployer inside executor
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <delweng@gmail.com>
  • Loading branch information
jsvisa committed Nov 21, 2024
1 parent ec358ef commit b5928e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 12 additions & 0 deletions crates/evm/evm/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use foundry_evm_core::{
},
decode::{RevertDecoder, SkipReason},
utils::StateChangeset,
InspectorExt,
};
use foundry_evm_coverage::HitMaps;
use foundry_evm_traces::{SparsedTraceArena, TraceMode};
Expand Down Expand Up @@ -237,6 +238,17 @@ impl Executor {
self
}

#[inline]
pub fn set_create2_deployer(&mut self, create2_deployer: Address) -> &mut Self {
self.inspector_mut().set_create2_deployer(create2_deployer);
self
}

#[inline]
pub fn create2_deployer(&self) -> Address {
self.inspector().create2_deployer()
}

/// Deploys a contract and commits the new state to the underlying database.
///
/// Executes a CREATE transaction with the contract `code` and persistent database state
Expand Down
9 changes: 4 additions & 5 deletions crates/script/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use foundry_evm::{
opts::EvmOpts,
revm::interpreter::{return_ok, InstructionResult},
traces::{TraceKind, Traces},
InspectorExt,
};
use std::collections::VecDeque;

Expand Down Expand Up @@ -40,9 +39,6 @@ impl ScriptRunner {
) -> Result<(Address, ScriptResult)> {
trace!(target: "script", "executing setUP()");

// set CREATE2 deployer from EvmOpts.
self.executor.inspector_mut().set_create2_deployer(self.evm_opts.create2_deployer);

if !is_broadcast {
if self.evm_opts.sender == Config::DEFAULT_SENDER {
// We max out their balance so that they can deploy and make calls.
Expand All @@ -54,6 +50,9 @@ impl ScriptRunner {
}
}

// set CREATE2 deployer from EvmOpts.
self.executor.set_create2_deployer(self.evm_opts.create2_deployer);

self.executor.set_nonce(self.evm_opts.sender, sender_nonce)?;

// We max out their balance so that they can deploy and make calls.
Expand Down Expand Up @@ -87,7 +86,7 @@ impl ScriptRunner {
})
}),
ScriptPredeployLibraries::Create2(libraries, salt) => {
let create2_deployer = self.executor.inspector().create2_deployer();
let create2_deployer = self.executor.create2_deployer();
for library in libraries {
let address = create2_deployer.create2_from_code(salt, library.as_ref());
// Skip if already deployed
Expand Down

0 comments on commit b5928e4

Please sign in to comment.