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 7d1a4ba commit abbb7b1
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 @@ -11,7 +11,6 @@ use foundry_evm::{
opts::EvmOpts,
revm::interpreter::{return_ok, InstructionResult},
traces::{TraceKind, Traces},
InspectorExt,
};
use std::collections::VecDeque;

Expand Down Expand Up @@ -39,9 +38,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 @@ -53,6 +49,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 @@ -86,7 +85,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 abbb7b1

Please sign in to comment.