From c6790a02bb80b163469e2e3bb0b16ae95ad7334f Mon Sep 17 00:00:00 2001 From: Enrique Date: Mon, 22 Jan 2024 15:09:43 -0400 Subject: [PATCH] feat(`evm`, `forge`): use alloy `TransactionRequest` for saving `BroadcastableTransactions` (#6876) * feat(evm, forge): use alloy TransactionRequest instead of ethers for broadcastable txs * chore: review * chore: bump h2 * clippy --- Cargo.lock | 115 ++++++++++----------- crates/cheatcodes/src/inspector.rs | 42 ++++---- crates/forge/bin/cmd/script/broadcast.rs | 3 +- crates/forge/bin/cmd/script/cmd.rs | 6 +- crates/forge/bin/cmd/script/executor.rs | 24 ++--- crates/forge/bin/cmd/script/mod.rs | 50 ++++----- crates/forge/bin/cmd/script/runner.rs | 13 +-- crates/forge/bin/cmd/script/transaction.rs | 27 ++++- 8 files changed, 136 insertions(+), 144 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db3c1f8aa359..81488f848be6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -431,9 +431,9 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstream" -version = "0.6.11" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +checksum = "4cd2405b3ac1faab2990b74d728624cd9fd115651fcecc7c2d8daf01376275ba" dependencies = [ "anstyle", "anstyle-parse", @@ -986,7 +986,7 @@ version = "0.66.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "cexpr", "clang-sys", "lazy_static", @@ -1026,9 +1026,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" dependencies = [ "arbitrary", "serde", @@ -1419,9 +1419,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.18" +version = "4.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" +checksum = "80932e03c33999b9235edb8655bc9df3204adc9887c2f95b50cb1deb9fd54253" dependencies = [ "clap_builder", "clap_derive", @@ -1429,9 +1429,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.18" +version = "4.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" +checksum = "d6c0db58c659eef1c73e444d298c27322a1b52f6927d2ad470c0c0f96fa7b8fa" dependencies = [ "anstream", "anstyle", @@ -1444,9 +1444,9 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.4.8" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf7dcb7c21d8ca1a2482ee0f1d341f437c9a7af6ca6da359dc5e1b164e98215" +checksum = "dfb0d4825b75ff281318c393e8e1b80c4da9fb75a6b1d98547d389d6fe1f48d2" dependencies = [ "clap", ] @@ -1824,7 +1824,7 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "crossterm_winapi", "libc", "mio", @@ -2205,9 +2205,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.10.2" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" dependencies = [ "humantime", "is-terminal", @@ -2629,9 +2629,9 @@ dependencies = [ [[package]] name = "evmole" -version = "0.3.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ef57dfcf13fc3486c3a760427d88ab0d97cb911f7104fe5a132f2b934d0fe29" +checksum = "f492d1949e58ef83a1bf8e23fbd042af12b03e7642d50dbb4cfb48112de5e01f" dependencies = [ "ruint", ] @@ -2720,9 +2720,9 @@ dependencies = [ [[package]] name = "figment" -version = "0.10.14" +version = "0.10.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b6e5bc7bd59d60d0d45a6ccab6cf0f4ce28698fb4e81e750ddf229c9b824026" +checksum = "7629b8c7bcd214a072c2c88b263b5bb3ceb54c34365d8c41c1665461aeae0993" dependencies = [ "atomic", "parking_lot", @@ -3538,7 +3538,7 @@ version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbf97ba92db08df386e10c8ede66a2a0369bd277090afd8710e19e38de9ec0cd" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "libc", "libgit2-sys", "log", @@ -3587,7 +3587,7 @@ version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e874f41437441c02991dcea76990b9058fadfc54b02ab4dd06ab2218af43897" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "bstr", "gix-path", "libc", @@ -3633,7 +3633,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c07c98204529ac3f24b34754540a852593d2a4c7349008df389240266627a72a" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "bstr", "gix-features", "gix-path", @@ -3718,7 +3718,7 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9615cbd6b456898aeb942cd75e5810c382fbfc48dbbff2fa23ebd2d33dcbe9c7" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "gix-path", "libc", "windows", @@ -3745,12 +3745,11 @@ checksum = "02b202d766a7fefc596e2cc6a89cda8ad8ad733aed82da635ac120691112a9b1" [[package]] name = "gix-utils" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e839f3d0798b296411263da6bee780a176ef8008a5dfc31287f7eda9266ab8" +checksum = "de6225e2de30b6e9bca2d9f1cc4731640fcef0fb3cabddceee366e7e85d3e94f" dependencies = [ "fastrand", - "unicode-normalization", ] [[package]] @@ -3896,9 +3895,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.4" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "hex" @@ -4532,7 +4531,7 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "libc", "redox_syscall", ] @@ -4563,9 +4562,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] name = "lock_api" @@ -4845,7 +4844,7 @@ version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "cfg-if", "libc", ] @@ -5005,7 +5004,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ - "proc-macro-crate 3.1.0", + "proc-macro-crate 3.0.0", "proc-macro2", "quote", "syn 2.0.48", @@ -5091,11 +5090,11 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.63" +version = "0.10.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" +checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "cfg-if", "foreign-types", "libc", @@ -5123,9 +5122,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.99" +version = "0.9.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" +checksum = "c1665caf8ab2dc9aef43d1c0023bd904633a6a05cb30b0ad59bec2ae986e57a7" dependencies = [ "cc", "libc", @@ -5580,9 +5579,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.29" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" +checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" [[package]] name = "plotters" @@ -5700,9 +5699,9 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "3.1.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +checksum = "6b2685dd208a3771337d8d386a89840f0f43cd68be8dae90a5f8c2384effc9cd" dependencies = [ "toml_edit 0.21.0", ] @@ -5772,7 +5771,7 @@ checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.4.2", + "bitflags 2.4.1", "lazy_static", "num-traits", "rand 0.8.5", @@ -5943,7 +5942,7 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ebc917cfb527a566c37ecb94c7e3fd098353516fb4eb6bea17015ade0182425" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "cassowary", "crossterm", "indoc", @@ -5957,9 +5956,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.8.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" dependencies = [ "either", "rayon-core", @@ -5967,9 +5966,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -6118,7 +6117,7 @@ dependencies = [ [[package]] name = "revm-inspectors" version = "0.1.0" -source = "git+https://github.com/paradigmxyz/evm-inspectors#5ee90076f88e64a059e4c0c268929cf9ec91ed6d" +source = "git+https://github.com/paradigmxyz/evm-inspectors#29bb854055855daf84c5aac796681e3aae208895" dependencies = [ "alloy-primitives", "alloy-rpc-trace-types", @@ -6161,7 +6160,7 @@ dependencies = [ "alloy-primitives", "alloy-rlp", "auto_impl", - "bitflags 2.4.2", + "bitflags 2.4.1", "bitvec", "c-kzg", "enumn", @@ -6427,7 +6426,7 @@ version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", @@ -6513,7 +6512,7 @@ version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "994eca4bca05c87e86e15d90fc7a91d1be64b4482b38cb2d27474568fe7c9db9" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "cfg-if", "clipboard-win", "fd-lock 3.0.13", @@ -7010,9 +7009,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" [[package]] name = "socket2" @@ -7641,7 +7640,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.4.1", "bytes", "futures-core", "futures-util", @@ -7879,9 +7878,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.15" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" [[package]] name = "unicode-bom" @@ -7981,9 +7980,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "vergen" -version = "8.3.1" +version = "8.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525" +checksum = "ec0d895592fa7710eba03fe072e614e3dc6a61ab76ae7ae10d2eb4a7ed5b00ca" dependencies = [ "anyhow", "cfg-if", diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index ee2ed1586d0c..3f856c5586c1 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -14,13 +14,11 @@ use crate::{ }, CheatsConfig, CheatsCtxt, Error, Result, Vm, }; -use alloy_primitives::{Address, Bytes, B256, U256}; +use alloy_primitives::{Address, Bytes, B256, U256, U64}; +use alloy_rpc_types::request::TransactionRequest; use alloy_sol_types::{SolInterface, SolValue}; -use ethers_core::types::{ - transaction::eip2718::TypedTransaction, NameOrAddress, TransactionRequest, -}; use ethers_signers::LocalWallet; -use foundry_common::{evm::Breakpoints, provider::alloy::RpcUrl, types::ToEthers}; +use foundry_common::{evm::Breakpoints, provider::alloy::RpcUrl}; use foundry_evm_core::{ backend::{DatabaseError, DatabaseExt, RevertDiagnostic}, constants::{CHEATCODE_ADDRESS, DEFAULT_CREATE2_DEPLOYER, HARDHAT_CONSOLE_ADDRESS}, @@ -80,7 +78,7 @@ pub struct BroadcastableTransaction { /// The optional RPC URL. pub rpc: Option, /// The transaction to broadcast. - pub transaction: TypedTransaction, + pub transaction: TransactionRequest, } /// List of transactions that can be broadcasted. @@ -834,19 +832,19 @@ impl Inspector for Cheatcodes { self.broadcastable_transactions.push_back(BroadcastableTransaction { rpc: data.db.active_fork_url(), - transaction: TypedTransaction::Legacy(TransactionRequest { - from: Some(broadcast.new_origin.to_ethers()), - to: Some(NameOrAddress::Address(call.contract.to_ethers())), - value: Some(call.transfer.value.to_ethers()), - data: Some(call.input.clone().to_ethers()), - nonce: Some(account.info.nonce.into()), + transaction: TransactionRequest { + from: Some(broadcast.new_origin), + to: Some(call.contract), + value: Some(call.transfer.value), + data: Some(call.input.clone()), + nonce: Some(U64::from(account.info.nonce)), gas: if is_fixed_gas_limit { - Some(call.gas_limit.into()) + Some(U256::from(call.gas_limit)) } else { None }, ..Default::default() - }), + }, }); debug!(target: "cheatcodes", tx=?self.broadcastable_transactions.back().unwrap(), "broadcastable call"); @@ -1220,19 +1218,19 @@ impl Inspector for Cheatcodes { self.broadcastable_transactions.push_back(BroadcastableTransaction { rpc: data.db.active_fork_url(), - transaction: TypedTransaction::Legacy(TransactionRequest { - from: Some(broadcast.new_origin.to_ethers()), - to: to.map(|a| NameOrAddress::Address(a.to_ethers())), - value: Some(call.value.to_ethers()), - data: Some(bytecode.to_ethers()), - nonce: Some(nonce.into()), + transaction: TransactionRequest { + from: Some(broadcast.new_origin), + to, + value: Some(call.value), + data: Some(bytecode), + nonce: Some(U64::from(nonce)), gas: if is_fixed_gas_limit { - Some(call.gas_limit.into()) + Some(U256::from(call.gas_limit)) } else { None }, ..Default::default() - }), + }, }); let kind = match call.scheme { CreateScheme::Create => "create", diff --git a/crates/forge/bin/cmd/script/broadcast.rs b/crates/forge/bin/cmd/script/broadcast.rs index b6a8456f5dd9..e32cd02e0c41 100644 --- a/crates/forge/bin/cmd/script/broadcast.rs +++ b/crates/forge/bin/cmd/script/broadcast.rs @@ -3,6 +3,7 @@ use super::{ sequence::ScriptSequence, transaction::TransactionWithMetadata, verify::VerifyBundle, *, }; use alloy_primitives::{utils::format_units, TxHash}; +use ethers_core::types::transaction::eip2718::TypedTransaction; use ethers_providers::{JsonRpcClient, Middleware, Provider}; use ethers_signers::Signer; use eyre::{bail, ContextCompat, Result, WrapErr}; @@ -407,7 +408,7 @@ impl ScriptArgs { shell::println("\nSKIPPING ON CHAIN SIMULATION.")?; txs.into_iter() .map(|btx| { - let mut tx = TransactionWithMetadata::from_typed_transaction(btx.transaction); + let mut tx = TransactionWithMetadata::from_tx_request(btx.transaction); tx.rpc = btx.rpc; tx }) diff --git a/crates/forge/bin/cmd/script/cmd.rs b/crates/forge/bin/cmd/script/cmd.rs index 0f9a16b5fb07..244615b994ca 100644 --- a/crates/forge/bin/cmd/script/cmd.rs +++ b/crates/forge/bin/cmd/script/cmd.rs @@ -1,6 +1,6 @@ use super::{multi::MultiChainSequence, sequence::ScriptSequence, verify::VerifyBundle, *}; use alloy_primitives::Bytes; -use ethers_core::types::transaction::eip2718::TypedTransaction; + use ethers_providers::Middleware; use ethers_signers::Signer; use eyre::Result; @@ -171,7 +171,7 @@ impl ScriptArgs { for tx in txs.iter() { lib_deploy.push_back(BroadcastableTransaction { rpc: tx.rpc.clone(), - transaction: TypedTransaction::Legacy(tx.transaction.clone().into()), + transaction: tx.transaction.clone(), }); } *txs = lib_deploy; @@ -336,7 +336,7 @@ impl ScriptArgs { for new_tx in new_txs.iter() { txs.push_back(BroadcastableTransaction { rpc: new_tx.rpc.clone(), - transaction: TypedTransaction::Legacy(new_tx.transaction.clone().into()), + transaction: new_tx.transaction.clone(), }); } } diff --git a/crates/forge/bin/cmd/script/executor.rs b/crates/forge/bin/cmd/script/executor.rs index 6a5b792fe196..bea7af8cb2c7 100644 --- a/crates/forge/bin/cmd/script/executor.rs +++ b/crates/forge/bin/cmd/script/executor.rs @@ -5,7 +5,6 @@ use super::{ *, }; use alloy_primitives::{Address, Bytes, U256}; -use ethers_core::types::transaction::eip2718::TypedTransaction; use eyre::Result; use forge::{ backend::Backend, @@ -14,11 +13,7 @@ use forge::{ traces::CallTraceDecoder, }; use foundry_cli::utils::{ensure_clean_constructor, needs_setup}; -use foundry_common::{ - provider::ethers::RpcUrl, - shell, - types::{ToAlloy, ToEthers}, -}; +use foundry_common::{provider::ethers::RpcUrl, shell}; use foundry_compilers::artifacts::CompactContractBytecode; use futures::future::join_all; use parking_lot::RwLock; @@ -142,17 +137,14 @@ impl ScriptArgs { let rpc = transaction.rpc.as_ref().expect("missing broadcastable tx rpc url"); let mut runner = runners.get(rpc).expect("invalid rpc url").write(); - let TypedTransaction::Legacy(mut tx) = transaction.transaction else { - unreachable!() - }; + let mut tx = transaction.transaction; let result = runner .simulate( tx.from - .expect("transaction doesn't have a `from` address at execution time") - .to_alloy(), - tx.to.clone(), - tx.data.clone().map(|b| b.to_alloy()), - tx.value.map(|v| v.to_alloy()), + .expect("transaction doesn't have a `from` address at execution time"), + tx.to, + tx.data.clone(), + tx.value, ) .wrap_err("Internal EVM error during simulation")?; @@ -191,12 +183,12 @@ impl ScriptArgs { // We inflate the gas used by the user specified percentage None => { let gas = U256::from(result.gas_used * self.gas_estimate_multiplier / 100); - tx.gas = Some(gas.to_ethers()); + tx.gas = Some(gas); } } let tx = TransactionWithMetadata::new( - tx.into(), + tx, transaction.rpc, &result, &address_to_abi, diff --git a/crates/forge/bin/cmd/script/mod.rs b/crates/forge/bin/cmd/script/mod.rs index 9dae655b5a71..245c59ad63ac 100644 --- a/crates/forge/bin/cmd/script/mod.rs +++ b/crates/forge/bin/cmd/script/mod.rs @@ -2,12 +2,10 @@ use self::{build::BuildOutput, runner::ScriptRunner}; use super::{build::BuildArgs, retry::RetryArgs}; use alloy_dyn_abi::FunctionExt; use alloy_json_abi::{Function, InternalType, JsonAbi}; -use alloy_primitives::{Address, Bytes, Log, U256}; +use alloy_primitives::{Address, Bytes, Log, U256, U64}; +use alloy_rpc_types::request::TransactionRequest; use clap::{Parser, ValueHint}; use dialoguer::Confirm; -use ethers_core::types::{ - transaction::eip2718::TypedTransaction, NameOrAddress, TransactionRequest, -}; use ethers_providers::{Http, Middleware}; use ethers_signers::LocalWallet; use eyre::{ContextCompat, Result, WrapErr}; @@ -29,9 +27,7 @@ use foundry_common::{ evm::{Breakpoints, EvmArgs}, fmt::{format_token, format_token_raw}, provider::ethers::RpcUrl, - shell, - types::{ToAlloy, ToEthers}, - ContractsByArtifact, CONTRACT_MAX_SIZE, SELECTOR_LEN, + shell, ContractsByArtifact, CONTRACT_MAX_SIZE, SELECTOR_LEN, }; use foundry_compilers::{ artifacts::{ContractBytecodeSome, Libraries}, @@ -387,21 +383,16 @@ impl ScriptArgs { // If the user passed a `--sender` don't check anything. if !predeploy_libraries.is_empty() && self.evm_opts.sender.is_none() { for tx in txs.iter() { - match &tx.transaction { - TypedTransaction::Legacy(tx) => { - if tx.to.is_none() { - let sender = tx.from.expect("no sender").to_alloy(); - if let Some(ns) = new_sender { - if sender != ns { - shell::println("You have more than one deployer who could predeploy libraries. Using `--sender` instead.")?; - return Ok(None); - } - } else if sender != evm_opts.sender { - new_sender = Some(sender); - } + if tx.transaction.to.is_none() { + let sender = tx.transaction.from.expect("no sender"); + if let Some(ns) = new_sender { + if sender != ns { + shell::println("You have more than one deployer who could predeploy libraries. Using `--sender` instead.")?; + return Ok(None); } + } else if sender != evm_opts.sender { + new_sender = Some(sender); } - _ => unreachable!(), } } } @@ -422,12 +413,12 @@ impl ScriptArgs { .enumerate() .map(|(i, bytes)| BroadcastableTransaction { rpc: fork_url.clone(), - transaction: TypedTransaction::Legacy(TransactionRequest { - from: Some(from.to_ethers()), - data: Some(bytes.clone().to_ethers()), - nonce: Some((nonce + i as u64).into()), + transaction: TransactionRequest { + from: Some(from), + data: Some(bytes.clone()), + nonce: Some(U64::from(nonce + i as u64)), ..Default::default() - }), + }, }) .collect() } @@ -519,16 +510,17 @@ impl ScriptArgs { for (data, to) in result.transactions.iter().flat_map(|txes| { txes.iter().filter_map(|tx| { tx.transaction - .data() + .data + .clone() .filter(|data| data.len() > max_size) - .map(|data| (data, tx.transaction.to())) + .map(|data| (data, tx.transaction.to)) }) }) { let mut offset = 0; // Find if it's a CREATE or CREATE2. Otherwise, skip transaction. - if let Some(NameOrAddress::Address(to)) = to { - if to.to_alloy() == DEFAULT_CREATE2_DEPLOYER { + if let Some(to) = to { + if to == DEFAULT_CREATE2_DEPLOYER { // Size of the salt prefix. offset = 32; } diff --git a/crates/forge/bin/cmd/script/runner.rs b/crates/forge/bin/cmd/script/runner.rs index 1dc91041cf33..4893c21fa9ea 100644 --- a/crates/forge/bin/cmd/script/runner.rs +++ b/crates/forge/bin/cmd/script/runner.rs @@ -1,6 +1,5 @@ use super::*; use alloy_primitives::{Address, Bytes, U256}; -use ethers_core::types::NameOrAddress; use eyre::Result; use forge::{ constants::CALLER, @@ -204,18 +203,12 @@ impl ScriptRunner { pub fn simulate( &mut self, from: Address, - to: Option, + to: Option
, calldata: Option, value: Option, ) -> Result { - if let Some(NameOrAddress::Address(to)) = to { - self.call( - from, - to.to_alloy(), - calldata.unwrap_or_default(), - value.unwrap_or(U256::ZERO), - true, - ) + if let Some(to) = to { + self.call(from, to, calldata.unwrap_or_default(), value.unwrap_or(U256::ZERO), true) } else if to.is_none() { let (address, gas_used, logs, traces, debug) = match self.executor.deploy( from, diff --git a/crates/forge/bin/cmd/script/transaction.rs b/crates/forge/bin/cmd/script/transaction.rs index 26446bd45e84..5a446648c1ac 100644 --- a/crates/forge/bin/cmd/script/transaction.rs +++ b/crates/forge/bin/cmd/script/transaction.rs @@ -2,7 +2,11 @@ use super::{artifacts::ArtifactInfo, ScriptResult}; use alloy_dyn_abi::JsonAbiExt; use alloy_json_abi::Function; use alloy_primitives::{Address, Bytes, B256}; -use ethers_core::types::{transaction::eip2718::TypedTransaction, NameOrAddress}; +use alloy_rpc_types::request::TransactionRequest; +use ethers_core::types::{ + transaction::eip2718::TypedTransaction, NameOrAddress, + TransactionRequest as EthersTransactionRequest, +}; use eyre::{ContextCompat, Result, WrapErr}; use foundry_common::{ fmt::format_token_raw, @@ -59,12 +63,23 @@ fn default_vec_of_strings() -> Option> { } impl TransactionWithMetadata { - pub fn from_typed_transaction(transaction: TypedTransaction) -> Self { - Self { transaction, ..Default::default() } + pub fn from_tx_request(transaction: TransactionRequest) -> Self { + Self { + transaction: TypedTransaction::Legacy(EthersTransactionRequest { + from: transaction.from.map(ToEthers::to_ethers), + to: transaction.to.map(ToEthers::to_ethers).map(Into::into), + value: transaction.value.map(ToEthers::to_ethers), + data: transaction.data.map(ToEthers::to_ethers), + nonce: transaction.nonce.map(|n| n.to::().into()), + gas: transaction.gas.map(ToEthers::to_ethers), + ..Default::default() + }), + ..Default::default() + } } pub fn new( - transaction: TypedTransaction, + transaction: TransactionRequest, rpc: Option, result: &ScriptResult, local_contracts: &BTreeMap, @@ -72,7 +87,9 @@ impl TransactionWithMetadata { additional_contracts: Vec, is_fixed_gas_limit: bool, ) -> Result { - let mut metadata = Self { transaction, rpc, is_fixed_gas_limit, ..Default::default() }; + let mut metadata = Self::from_tx_request(transaction); + metadata.rpc = rpc; + metadata.is_fixed_gas_limit = is_fixed_gas_limit; // Specify if any contract was directly created with this transaction if let Some(NameOrAddress::Address(to)) = metadata.transaction.to().cloned() {