Skip to content

Commit

Permalink
chore: cleanup, config migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir committed Oct 24, 2023
1 parent 6c88473 commit f4738e1
Show file tree
Hide file tree
Showing 37 changed files with 148 additions and 685 deletions.
2 changes: 1 addition & 1 deletion crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl NodeArgs {
.fork_block_number
.or_else(|| self.evm_opts.fork_url.as_ref().and_then(|f| f.block)),
)
.with_fork_chain_id(self.evm_opts.fork_chain_id)
.with_fork_chain_id(self.evm_opts.fork_chain_id.map(u64::from))
.fork_request_timeout(self.evm_opts.fork_request_timeout.map(Duration::from_millis))
.fork_request_retries(self.evm_opts.fork_request_retries)
.fork_retry_backoff(self.evm_opts.fork_retry_backoff.map(Duration::from_millis))
Expand Down
10 changes: 7 additions & 3 deletions crates/anvil/tests/it/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ use ethers::{
};
use foundry_common::get_http_provider;
use foundry_config::Config;
use foundry_utils::{rpc, rpc::next_http_rpc_endpoint, types::ToAlloy};
use foundry_utils::{
rpc,
rpc::next_http_rpc_endpoint,
types::{ToAlloy, ToEthers},
};
use futures::StreamExt;
use std::{sync::Arc, time::Duration};

Expand Down Expand Up @@ -160,8 +164,8 @@ async fn test_fork_eth_get_nonce() {
}

let addr = Config::DEFAULT_SENDER;
let api_nonce = api.transaction_count(addr, None).await.unwrap();
let provider_nonce = provider.get_transaction_count(addr, None).await.unwrap();
let api_nonce = api.transaction_count(addr.to_ethers(), None).await.unwrap();
let provider_nonce = provider.get_transaction_count(addr.to_ethers(), None).await.unwrap();
assert_eq!(api_nonce, provider_nonce);
}

Expand Down
4 changes: 3 additions & 1 deletion crates/cast/bin/cmd/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use foundry_cli::{
utils,
};
use foundry_config::{Chain, Config};
use foundry_utils::types::ToEthers;
use std::str::FromStr;

/// CLI arguments for `cast access-list`.
Expand Down Expand Up @@ -65,7 +66,8 @@ impl AccessListArgs {
let chain = utils::get_chain(config.chain_id, &provider).await?;
let sender = eth.wallet.sender().await;

access_list(&provider, sender, to, sig, args, data, tx, chain, block, to_json).await?;
access_list(&provider, sender.to_ethers(), to, sig, args, data, tx, chain, block, to_json)
.await?;
Ok(())
}
}
Expand Down
17 changes: 9 additions & 8 deletions crates/cast/bin/cmd/call.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloy_primitives::U256;
use cast::{Cast, TxBuilder};
use clap::Parser;
use ethers::types::{BlockId, NameOrAddress, U256};
use ethers::types::{BlockId, NameOrAddress};
use eyre::{Result, WrapErr};
use foundry_cli::{
opts::{EthereumOpts, TransactionOpts},
Expand Down Expand Up @@ -129,7 +130,7 @@ impl CallArgs {
let sender = eth.wallet.sender().await;

let mut builder: TxBuilder<'_, Provider> =
TxBuilder::new(&provider, sender, to, chain, tx.legacy).await?;
TxBuilder::new(&provider, sender.to_ethers(), to, chain, tx.legacy).await?;

builder
.gas(tx.gas_limit)
Expand All @@ -154,9 +155,9 @@ impl CallArgs {
.await;

let trace = match executor.deploy(
sender.to_alloy(),
sender,
code.into_bytes().into(),
value.unwrap_or(U256::zero()).to_alloy(),
value.unwrap_or(U256::ZERO),
None,
) {
Ok(deploy_result) => TraceResult::from(deploy_result),
Expand All @@ -173,7 +174,7 @@ impl CallArgs {
}
_ => {
// fill first here because we need to use the builder in the conditional
fill_tx(&mut builder, tx.value.map(|t| t.to_ethers()), sig, args, data).await?;
fill_tx(&mut builder, tx.value, sig, args, data).await?;

if trace {
let figment = Config::figment_with_root(find_project_root_path(None).unwrap())
Expand All @@ -191,7 +192,7 @@ impl CallArgs {
let (tx, _) = builder.build();

let trace = TraceResult::from(executor.call_raw_committing(
sender.to_alloy(),
sender,
tx.to_addr().copied().expect("an address to be here").to_alloy(),
tx.data().cloned().unwrap_or_default().to_vec().into(),
tx.value().copied().unwrap_or_default().to_alloy(),
Expand Down Expand Up @@ -223,7 +224,7 @@ async fn fill_create(
sig: Option<String>,
args: Vec<String>,
) -> Result<()> {
builder.value(value.map(|v| v.to_alloy()));
builder.value(value);

let mut data = hex::decode(code)?;

Expand All @@ -245,7 +246,7 @@ async fn fill_tx(
args: Vec<String>,
data: Option<String>,
) -> Result<()> {
builder.value(value.map(|v| v.to_alloy()));
builder.value(value);

if let Some(sig) = sig {
builder.set_args(sig.as_str(), args).await?;
Expand Down
4 changes: 2 additions & 2 deletions crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl RunArgs {
.ok_or_else(|| eyre::eyre!("tx not found: {:?}", tx_hash))?;

// check if the tx is a system transaction
if is_known_system_sender(tx.from) ||
if is_known_system_sender(tx.from.to_alloy()) ||
tx.transaction_type.map(|ty| ty.as_u64()) == Some(SYSTEM_TRANSACTION_TYPE)
{
return Err(eyre::eyre!(
Expand Down Expand Up @@ -144,7 +144,7 @@ impl RunArgs {
for (index, tx) in block.transactions.into_iter().enumerate() {
// System transactions such as on L2s don't contain any pricing info so we skip
// them otherwise this would cause reverts
if is_known_system_sender(tx.from) ||
if is_known_system_sender(tx.from.to_alloy()) ||
tx.transaction_type.map(|ty| ty.as_u64()) ==
Some(SYSTEM_TRANSACTION_TYPE)
{
Expand Down
14 changes: 9 additions & 5 deletions crates/cast/bin/cmd/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use foundry_cli::{
};
use foundry_common::cli_warn;
use foundry_config::{Chain, Config};
use foundry_utils::types::ToAlloy;
use foundry_utils::types::{ToAlloy, ToEthers};
use std::str::FromStr;

/// CLI arguments for `cast send`.
Expand Down Expand Up @@ -133,13 +133,17 @@ impl SendTxArgs {
}

if resend {
tx.nonce =
Some(provider.get_transaction_count(config.sender, None).await?.to_alloy());
tx.nonce = Some(
provider
.get_transaction_count(config.sender.to_ethers(), None)
.await?
.to_alloy(),
);
}

cast_send(
provider,
config.sender,
config.sender.to_ethers(),
to,
code,
(sig, args),
Expand All @@ -163,7 +167,7 @@ impl SendTxArgs {
// prevent misconfigured hwlib from sending a transaction that defies
// user-specified --from
if let Some(specified_from) = eth.wallet.from {
if specified_from != from {
if specified_from != from.to_alloy() {
eyre::bail!(
"\
The specified sender via CLI/env vars does not match the sender configured via
Expand Down
7 changes: 2 additions & 5 deletions crates/cast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ fn strip_0x(s: &str) -> &str {
#[cfg(test)]
mod tests {
use super::SimpleCast as Cast;
use std::fmt::Write;
use alloy_primitives::hex;

#[test]
fn simple_selector() {
Expand Down Expand Up @@ -2087,10 +2087,7 @@ mod tests {
.to_lowercase(),
decoded[2].as_uint().unwrap().0.to_string(),
decoded[3].as_uint().unwrap().0.to_string(),
decoded[4].as_bytes().unwrap().iter().copied().fold(String::new(), |mut output, v| {
let _ = write!(output, "{v:02x}");
output
}),
hex::encode(decoded[4].as_bytes().unwrap()),
]
.to_vec();
assert_eq!(
Expand Down
1 change: 0 additions & 1 deletion crates/chisel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ foundry-compilers = { workspace = true, default-features = false, features = ["p

# ethers
ethers.workspace = true
ethers-solc = { workspace = true, features = ["project-util", "full"] }

# alloy
alloy-dyn-abi = { workspace = true, features = ["arbitrary"] }
Expand Down
12 changes: 7 additions & 5 deletions crates/cli/src/opts/wallet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::opts::error::PrivateKeyError;
use alloy_primitives::Address;
use async_trait::async_trait;
use clap::Parser;
use ethers::{
Expand All @@ -9,12 +10,13 @@ use ethers::{
},
types::{
transaction::{eip2718::TypedTransaction, eip712::Eip712},
Address, Signature,
Signature,
},
};
use eyre::{bail, Result, WrapErr};
use foundry_common::fs;
use foundry_config::Config;
use foundry_utils::types::ToAlloy;
use rusoto_core::{
credential::ChainProvider as AwsChainProvider, region::Region as AwsRegion,
request::HttpClient as AwsHttpClient, Client as AwsClient,
Expand Down Expand Up @@ -202,9 +204,9 @@ impl Wallet {
/// Returns the sender address of the signer or `from`.
pub async fn sender(&self) -> Address {
if let Ok(signer) = self.signer(0).await {
signer.address()
signer.address().to_alloy()
} else {
self.from.unwrap_or_else(Address::zero)
self.from.unwrap_or(Address::ZERO)
}
}

Expand Down Expand Up @@ -497,7 +499,7 @@ impl Signer for WalletSigner {
delegate!(self, inner => inner.sign_typed_data(payload).await.map_err(Into::into))
}

fn address(&self) -> Address {
fn address(&self) -> ethers::types::Address {
delegate!(self, inner => inner.address())
}

Expand Down Expand Up @@ -537,7 +539,7 @@ impl Signer for &WalletSigner {
(*self).sign_typed_data(payload).await
}

fn address(&self) -> Address {
fn address(&self) -> ethers::types::Address {
(*self).address()
}

Expand Down
11 changes: 6 additions & 5 deletions crates/cli/src/opts/wallet/multi_wallet.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use super::{WalletSigner, WalletTrait};
use alloy_primitives::Address;
use clap::Parser;
use ethers::{
prelude::{Middleware, Signer},
signers::{AwsSigner, HDPath as LedgerHDPath, Ledger, LocalWallet, Trezor, TrezorHDPath},
types::Address,
};
use eyre::{Context, ContextCompat, Result};
use foundry_common::RetryProvider;
use foundry_config::Config;
use foundry_utils::types::ToAlloy;
use itertools::izip;
use rusoto_core::{
credential::ChainProvider as AwsChainProvider, region::Region as AwsRegion,
Expand Down Expand Up @@ -239,18 +240,18 @@ impl MultiWallet {
],
for wallet in wallets.into_iter() {
let address = wallet.address();
if addresses.contains(&address) {
addresses.remove(&address);
if addresses.contains(&address.to_alloy()) {
addresses.remove(&address.to_alloy());

let signer = WalletSigner::from(wallet.with_chain_id(chain));
local_wallets.insert(address, signer);
local_wallets.insert(address.to_alloy(), signer);

if addresses.is_empty() {
return Ok(local_wallets)
}
} else {
// Just to show on error.
unused_wallets.push(address);
unused_wallets.push(address.to_alloy());
}
}
);
Expand Down
18 changes: 6 additions & 12 deletions crates/common/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Commonly used constants
use ethers_core::types::H160;
use alloy_primitives::{address, Address};
use std::time::Duration;

/// The dev chain-id, inherited from hardhat
Expand Down Expand Up @@ -29,19 +29,13 @@ supported. Please try to change your RPC url to an archive node if the issue per

/// Arbitrum L1 sender address of the first transaction in every block.
/// `0x00000000000000000000000000000000000a4b05`
pub const ARBITRUM_SENDER: H160 = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0a, 0x4b, 0x05,
]);
pub const ARBITRUM_SENDER: Address = address!("00000000000000000000000000000000000a4b05");

/// The system address, the sender of the first transaction in every block:
/// `0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001`
///
/// See also <https://github.com/ethereum-optimism/optimism/blob/65ec61dde94ffa93342728d324fecf474d228e1f/specs/deposits.md#l1-attributes-deposited-transaction>
pub const OPTIMISM_SYSTEM_ADDRESS: H160 = H160([
0xDE, 0xAD, 0xDE, 0xAD, 0xDE, 0xAD, 0xDE, 0xAD, 0xDE, 0xAD, 0xDE, 0xAD, 0xDE, 0xAD, 0xDE, 0xAD,
0xDE, 0xAD, 0x00, 0x01,
]);
pub const OPTIMISM_SYSTEM_ADDRESS: Address = address!("deaddeaddeaddeaddeaddeaddeaddeaddead0001");

/// Transaction identifier of System transaction types
pub const SYSTEM_TRANSACTION_TYPE: u64 = 126u64;
Expand All @@ -52,7 +46,7 @@ pub const SYSTEM_TRANSACTION_TYPE: u64 = 126u64;
///
/// See: [ARBITRUM_SENDER], [OPTIMISM_SYSTEM_ADDRESS]
#[inline]
pub fn is_known_system_sender(sender: H160) -> bool {
pub fn is_known_system_sender(sender: Address) -> bool {
[ARBITRUM_SENDER, OPTIMISM_SYSTEM_ADDRESS].contains(&sender)
}

Expand All @@ -63,9 +57,9 @@ mod tests {

#[test]
fn test_constant_sender() {
let arb = H160::from_str("0x00000000000000000000000000000000000a4b05").unwrap();
let arb = Address::from_str("0x00000000000000000000000000000000000a4b05").unwrap();
assert_eq!(arb, ARBITRUM_SENDER);
let base = H160::from_str("0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001").unwrap();
let base = Address::from_str("0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001").unwrap();
assert_eq!(base, OPTIMISM_SYSTEM_ADDRESS);
}
}
4 changes: 2 additions & 2 deletions crates/common/src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! cli arguments for configuring the evm settings
use alloy_primitives::{Address, B256, U256};
use clap::{ArgAction, Parser};
use ethers_core::types::{Address, H256, U256};
use eyre::ContextCompat;
use foundry_config::{
figment::{
Expand Down Expand Up @@ -228,7 +228,7 @@ pub struct EnvArgs {
/// The block prevrandao value. NOTE: Before merge this field was mix_hash.
#[clap(long, value_name = "PREVRANDAO")]
#[serde(skip_serializing_if = "Option::is_none")]
pub block_prevrandao: Option<H256>,
pub block_prevrandao: Option<B256>,

/// The block gas limit.
#[clap(long, value_name = "GAS_LIMIT")]
Expand Down
1 change: 1 addition & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repository.workspace = true
[dependencies]
# eth
ethers-core.workspace = true
alloy-primitives = { workspace = true, features = ["std", "serde"] }
revm-primitives = { workspace = true, default-features = false, features = ["std"] }

foundry-compilers = { workspace = true, features = ["async", "svm-solc"] }
Expand Down
Loading

0 comments on commit f4738e1

Please sign in to comment.