Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] feat: provider alloy migration #7106

Merged
merged 71 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
16aebe2
chore: make cast use an alloy provider
Evalir Feb 13, 2024
08a9cca
move initial methods to alloy
Evalir Feb 13, 2024
3de8241
feat(`foundry-common`): NameOrAddress ENS util (#7122)
Evalir Feb 14, 2024
f9d6c99
feat(`cast`): Move non `tx` methods to alloy (#7129)
Evalir Feb 16, 2024
0f98e03
Merge branch 'master' into evalir/cast-provider-mig
Evalir Feb 19, 2024
c983f50
Merge branch 'master' into evalir/cast-provider-mig
klkvr Mar 18, 2024
e482bee
DocumentMut
klkvr Mar 18, 2024
953f915
wip
klkvr Mar 18, 2024
435be40
wip
klkvr Mar 18, 2024
d286ae0
wip: bump alloy
klkvr Mar 18, 2024
04ca105
wip
klkvr Mar 18, 2024
f9fcfd4
wip
klkvr Mar 19, 2024
d1ace73
wip
klkvr Mar 20, 2024
2a723a4
[wip] migrate to alloy providers and signers (#7425)
klkvr Mar 20, 2024
20ce388
fix wallets after alloy bump
klkvr Mar 20, 2024
12fee31
clean up deps
klkvr Mar 21, 2024
7b4e7a5
use serde on consensus types
klkvr Mar 21, 2024
13144ef
update TypedTransaction for anvil
klkvr Mar 22, 2024
3077ad8
make anvil compile
klkvr Mar 22, 2024
2867eac
wip: make script compile
klkvr Mar 22, 2024
dc1df12
fix script
klkvr Mar 22, 2024
9fac722
make forge compile
klkvr Mar 22, 2024
7827988
fix: anvil tests
klkvr Mar 22, 2024
67107c3
bump alloy
klkvr Mar 23, 2024
09ee81f
fix tests
klkvr Mar 23, 2024
1539d37
fix tx builder
klkvr Mar 24, 2024
7889a57
fix cargo.toml
klkvr Mar 24, 2024
b479fa8
fix cargo.toml
klkvr Mar 24, 2024
2d67791
fix script gas price logic
klkvr Mar 25, 2024
323ca27
merge
klkvr Mar 25, 2024
43d19b1
remove ethers from anvil
klkvr Mar 25, 2024
f0a6243
clippy
klkvr Mar 25, 2024
203712e
rm all_derives
klkvr Mar 25, 2024
25276b8
deps
klkvr Mar 27, 2024
a61f4a6
fmt
klkvr Mar 27, 2024
e6e3b57
fix tests
klkvr Mar 27, 2024
aa8fb46
Merge branch 'master' into evalir/cast-provider-mig
klkvr Mar 27, 2024
24f746a
configure clippy
klkvr Mar 27, 2024
5d72ea9
clippy
klkvr Mar 27, 2024
1b762d8
add feature
klkvr Mar 27, 2024
852fa11
fix cargo deny
klkvr Mar 27, 2024
c8781e5
fix persist
klkvr Mar 27, 2024
9760679
fix doctests
klkvr Mar 27, 2024
f93a140
fmt
klkvr Mar 27, 2024
7740eb1
fix clap
klkvr Mar 28, 2024
2800a41
review fixes
klkvr Mar 28, 2024
dc1ce6e
Merge branch 'master' into evalir/cast-provider-mig
klkvr Mar 28, 2024
3ccde5b
fmt
klkvr Mar 28, 2024
3d4373d
bump alloy
klkvr Apr 4, 2024
5204f61
Update cargo.toml
klkvr Apr 4, 2024
c2b404b
Merge branch 'master' into evalir/cast-provider-mig
klkvr Apr 4, 2024
879153a
fmt
klkvr Apr 4, 2024
0431bb3
fixes
klkvr Apr 4, 2024
472d4ff
ethers clean-up
klkvr Apr 5, 2024
ecfcca0
fix(fmt): fix indent closing parenthesis enclosed in { } (#7557)
grandizzy Apr 4, 2024
5efa20e
feat(test): only compile files needed for tests (#7334)
klkvr Apr 4, 2024
398ff1f
fix: do not flood dictionary with data dependent on fuzz inputs (#7552)
klkvr Apr 4, 2024
ec8f6de
Feat: Index cheatcode for Strings (#7539)
kamuik16 Apr 4, 2024
1b846d9
chore: reduce logs in tests (#7566)
DaniPopes Apr 5, 2024
03d900a
fix(script): decode custom error in script fail message (#7563)
grandizzy Apr 5, 2024
3ebf3ab
clippy
klkvr Apr 6, 2024
c734de4
bump alloy
klkvr Apr 6, 2024
1165de0
Merge branch 'master' into evalir/cast-provider-mig
klkvr Apr 6, 2024
26bf989
AnyNetwork
klkvr Apr 7, 2024
50b3bc1
bump alloy
klkvr Apr 7, 2024
4ae360b
add comment
klkvr Apr 7, 2024
6900bef
clippy
klkvr Apr 7, 2024
e8ccb7d
bump alloy
klkvr Apr 9, 2024
f1a95d5
Merge branch 'master' into evalir/cast-provider-mig
klkvr Apr 9, 2024
abd79cf
fixes
klkvr Apr 9, 2024
144dc19
refactor cast logs to use alloy (#7594)
bernard-wagner Apr 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 73 additions & 54 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ ethers-solc = { version = "2.0", default-features = false }

## alloy
alloy-consensus = { git = "https://github.com/alloy-rs/alloy" }
alloy-contract = { git = "https://github.com/alloy-rs/alloy" }
alloy-eips = { git = "https://github.com/alloy-rs/alloy" }
alloy-genesis = { git = "https://github.com/alloy-rs/alloy" }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy" }
Expand All @@ -164,9 +165,9 @@ alloy-transport-http = { git = "https://github.com/alloy-rs/alloy" }
alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy" }
alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy" }
alloy-primitives = { version = "0.6.2", features = ["getrandom"] }
alloy-dyn-abi = "0.6.2"
alloy-json-abi = "0.6.2"
alloy-sol-types = "0.6.2"
alloy-dyn-abi = "0.6"
alloy-json-abi = "0.6"
alloy-sol-types = "0.6"
syn-solidity = "0.6.0"
alloy-chains = "0.1"

Expand Down Expand Up @@ -227,6 +228,11 @@ ethers-signers = { git = "https://github.com/gakonst/ethers-rs", rev = "f0e5b194
ethers-middleware = { git = "https://github.com/gakonst/ethers-rs", rev = "f0e5b194f09c533feb10d1a686ddb9e5946ec107" }
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", rev = "f0e5b194f09c533feb10d1a686ddb9e5946ec107" }

alloy-sol-types = { git = "https://github.com/alloy-rs/core", rev = "18b0509950c90d9ec38f25913b692ae4cdd6f227" }
alloy-dyn-abi = { git = "https://github.com/alloy-rs/core", rev = "18b0509950c90d9ec38f25913b692ae4cdd6f227" }
alloy-json-abi = { git = "https://github.com/alloy-rs/core", rev = "18b0509950c90d9ec38f25913b692ae4cdd6f227" }
alloy-primitives = { git = "https://github.com/alloy-rs/core", rev = "18b0509950c90d9ec38f25913b692ae4cdd6f227" }

revm = { git = "https://github.com/bluealloy/revm", branch = "reth_freeze" }
revm-primitives = { git = "https://github.com/bluealloy/revm", branch = "reth_freeze" }
revm-interpreter = { git = "https://github.com/bluealloy/revm", branch = "reth_freeze" }
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/backend/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl ClientFork {

let block_id = BlockId::Number(blocknumber.into());

let code = self.provider().get_code_at(address, block_id).await?;
let code = self.provider().get_code_at(address, Some(block_id)).await?;

let mut storage = self.storage_write();
storage.code_at.insert((address, blocknumber), code.clone().0.into());
Expand Down
28 changes: 24 additions & 4 deletions crates/cast/bin/cmd/access_list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloy_providers::provider::TempProvider;
use cast::{Cast, TxBuilder};
use clap::Parser;
use ethers_core::types::{BlockId, NameOrAddress};
Expand Down Expand Up @@ -60,18 +61,37 @@ impl AccessListArgs {

let config = Config::from(&eth);
let provider = utils::get_provider(&config)?;
let alloy_provider = utils::get_alloy_provider(&config)?;
let chain = utils::get_chain(config.chain, &provider).await?;
let sender = eth.wallet.sender().await;

access_list(&provider, sender.to_ethers(), to, sig, args, data, tx, chain, block, to_json)
.await?;
access_list(
&provider,
alloy_provider,
sender.to_ethers(),
to,
sig,
args,
data,
tx,
chain,
block,
to_json,
)
.await?;
Ok(())
}
}

#[allow(clippy::too_many_arguments)]
async fn access_list<M: Middleware, F: Into<NameOrAddress>, T: Into<NameOrAddress>>(
async fn access_list<
M: Middleware,
P: TempProvider,
F: Into<NameOrAddress>,
T: Into<NameOrAddress>,
>(
provider: M,
alloy_provider: P,
from: F,
to: Option<T>,
sig: Option<String>,
Expand Down Expand Up @@ -104,7 +124,7 @@ where

let builder_output = builder.peek();

let cast = Cast::new(&provider);
let cast = Cast::new(&provider, alloy_provider);

let access_list: String = cast.access_list(builder_output, block, to_json).await?;

Expand Down
3 changes: 2 additions & 1 deletion crates/cast/bin/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl CallArgs {

let config = Config::from(&eth);
let provider = utils::get_provider(&config)?;
let alloy_provider = utils::get_alloy_provider(&config)?;
let chain = utils::get_chain(config.chain, &provider).await?;
let sender = eth.wallet.sender().await;

Expand Down Expand Up @@ -196,7 +197,7 @@ impl CallArgs {
};

let builder_output = builder.build();
println!("{}", Cast::new(provider).call(builder_output, block).await?);
println!("{}", Cast::new(provider, alloy_provider).call(builder_output, block).await?);

Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion crates/cast/bin/cmd/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl EstimateArgs {

let figment = Figment::from(Config::figment()).merge(etherscan).merge(rpc);
let config = Config::try_from(figment)?;
let alloy_provider = utils::get_alloy_provider(&config)?;

let provider = utils::get_provider(&config)?;
let chain = utils::get_chain(config.chain, &provider).await?;
Expand Down Expand Up @@ -109,7 +110,7 @@ impl EstimateArgs {
};

let builder_output = builder.peek();
let gas = Cast::new(&provider).estimate(builder_output).await?;
let gas = Cast::new(&provider, alloy_provider).estimate(builder_output).await?;
println!("{gas}");
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion crates/cast/bin/cmd/find_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ impl FindBlockArgs {
let ts_target = U256::from(timestamp);
let config = Config::from(&rpc);
let provider = utils::get_provider(&config)?;
let alloy_provider = utils::get_alloy_provider(&config)?;

let last_block_num = provider.get_block_number().await?;
let cast_provider = Cast::new(provider);
let cast_provider = Cast::new(provider, alloy_provider);

let res = join!(cast_provider.timestamp(last_block_num), cast_provider.timestamp(1));
let ts_block_latest = res.0?;
Expand Down
17 changes: 9 additions & 8 deletions crates/cast/bin/cmd/logs.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use alloy_rpc_types::BlockHashOrNumber;
use cast::Cast;
use clap::Parser;
use ethers_core::{
abi::{
token::{LenientTokenizer, StrictTokenizer, Tokenizer},
Address, Event, HumanReadableParser, ParamType, RawTopicFilter, Token, Topic, TopicFilter,
},
types::{
BlockId, BlockNumber, Filter, FilterBlockOption, NameOrAddress, ValueOrArray, H256, U256,
},
types::{BlockNumber, Filter, FilterBlockOption, NameOrAddress, ValueOrArray, H256, U256},
};
use ethers_providers::Middleware;
use eyre::{Result, WrapErr};
use foundry_cli::{opts::EthereumOpts, utils};
use foundry_common::types::ToEthers;
use foundry_config::Config;
use itertools::Itertools;
use std::{io, str::FromStr};
Expand All @@ -23,13 +23,13 @@ pub struct LogsArgs {
///
/// Can also be the tags earliest, finalized, safe, latest, or pending.
#[clap(long)]
from_block: Option<BlockId>,
from_block: Option<BlockHashOrNumber>,

/// The block height to stop query at.
///
/// Can also be the tags earliest, finalized, safe, latest, or pending.
#[clap(long)]
to_block: Option<BlockId>,
to_block: Option<BlockHashOrNumber>,

/// The contract address to filter on.
#[clap(
Expand Down Expand Up @@ -76,8 +76,9 @@ impl LogsArgs {

let config = Config::from(&eth);
let provider = utils::get_provider(&config)?;
let alloy_provider = utils::get_alloy_provider(&config)?;

let cast = Cast::new(&provider);
let cast = Cast::new(&provider, alloy_provider);

let address = match address {
Some(address) => {
Expand All @@ -90,8 +91,8 @@ impl LogsArgs {
None => None,
};

let from_block = cast.convert_block_number(from_block).await?;
let to_block = cast.convert_block_number(to_block).await?;
let from_block = cast.convert_block_number(from_block).await?.map(ToEthers::to_ethers);
let to_block = cast.convert_block_number(to_block).await?.map(ToEthers::to_ethers);

let filter = build_filter(from_block, to_block, address, sig_or_topic, topics_or_args)?;

Expand Down
3 changes: 2 additions & 1 deletion crates/cast/bin/cmd/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl RpcArgs {

let config = Config::from(&rpc);
let provider = utils::get_provider(&config)?;
let alloy_provider = utils::get_alloy_provider(&config)?;

let params = if raw {
if params.is_empty() {
Expand All @@ -53,7 +54,7 @@ impl RpcArgs {
} else {
serde_json::Value::Array(params.into_iter().map(value_or_string).collect())
};
println!("{}", Cast::new(provider).rpc(&method, params).await?);
println!("{}", Cast::new(provider, alloy_provider).rpc(&method, params).await?);
Ok(())
}
}
Expand Down
9 changes: 7 additions & 2 deletions crates/cast/bin/cmd/send.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloy_providers::provider::TempProvider;
use cast::{Cast, TxBuilder};
use clap::Parser;
use ethers_core::types::NameOrAddress;
Expand Down Expand Up @@ -114,6 +115,7 @@ impl SendTxArgs {

let config = Config::from(&eth);
let provider = utils::get_provider(&config)?;
let alloy_provider = utils::get_alloy_provider(&config)?;
let chain = utils::get_chain(config.chain, &provider).await?;
let api_key = config.get_etherscan_api_key(Some(chain));

Expand Down Expand Up @@ -152,6 +154,7 @@ impl SendTxArgs {

cast_send(
provider,
alloy_provider,
config.sender.to_ethers(),
to,
code,
Expand Down Expand Up @@ -195,6 +198,7 @@ corresponds to the sender, or let foundry automatically detect it by not specify

cast_send(
provider,
alloy_provider,
from,
to,
code,
Expand All @@ -212,8 +216,9 @@ corresponds to the sender, or let foundry automatically detect it by not specify
}

#[allow(clippy::too_many_arguments)]
async fn cast_send<M: Middleware, F: Into<NameOrAddress>, T: Into<NameOrAddress>>(
async fn cast_send<M: Middleware, P: TempProvider, F: Into<NameOrAddress>, T: Into<NameOrAddress>>(
provider: M,
alloy_provider: P,
from: F,
to: Option<T>,
code: Option<String>,
Expand Down Expand Up @@ -253,7 +258,7 @@ where
};
let builder_output = builder.build();

let cast = Cast::new(provider);
let cast = Cast::new(provider, alloy_provider);

let pending_tx = cast.send(builder_output).await?;
let tx_hash = *pending_tx;
Expand Down
3 changes: 2 additions & 1 deletion crates/cast/bin/cmd/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ impl StorageArgs {
let Self { address, slot, block, build, .. } = self;

let provider = utils::get_provider(&config)?;
let alloy_provider = utils::get_alloy_provider(&config)?;

// Slot was provided, perform a simple RPC call
if let Some(slot) = slot {
let cast = Cast::new(provider);
let cast = Cast::new(provider, alloy_provider);
println!("{}", cast.storage(address, slot.to_ethers(), block).await?);
return Ok(());
}
Expand Down
Loading
Loading