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

chore: alloy 0.11 #175

Merged
merged 5 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ significant_drop_tightening = "allow"
needless_return = "allow"

[workspace.dependencies]
alloy = { version = "0.9", features = [
alloy = { version = "0.11", features = [
"eips",
"full",
"hyper",
Expand All @@ -113,7 +113,7 @@ alloy = { version = "0.9", features = [
"signer-yubihsm",
] }

foundry-fork-db = "0.10"
foundry-fork-db = "0.11"

revm-primitives = "15.0"
revm = "19.0"
Expand Down
6 changes: 1 addition & 5 deletions examples/advanced/examples/any_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ async fn main() -> Result<()> {

// Create a provider with the Arbitrum Sepolia network and the wallet.
let rpc_url = "https://sepolia-rollup.arbitrum.io/rpc".parse()?;
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.network::<AnyNetwork>()
.wallet(wallet)
.on_http(rpc_url);
let provider = ProviderBuilder::new().network::<AnyNetwork>().wallet(wallet).on_http(rpc_url);

// Create a contract instance.
let contract = Counter::new(COUNTER_CONTRACT_ADDRESS, &provider);
Expand Down
29 changes: 13 additions & 16 deletions examples/advanced/examples/reth_db_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//!
//! Learn more about `ProviderCall` [here](https://github.com/alloy-rs/alloy/pull/788).

use std::{marker::PhantomData, path::PathBuf, sync::Arc};
use std::{path::PathBuf, sync::Arc};

use alloy::{
eips::{BlockId, BlockNumberOrTag},
Expand All @@ -21,7 +21,7 @@ use alloy::{
Provider, ProviderBuilder, ProviderCall, ProviderLayer, RootProvider, RpcWithBlock,
},
rpc::client::NoParams,
transports::{Transport, TransportErrorKind},
transports::TransportErrorKind,
};
use eyre::Result;

Expand Down Expand Up @@ -96,12 +96,11 @@ async fn main() -> Result<()> {
}

/// Implement the `ProviderLayer` trait for the `RethDBLayer` struct.
impl<P, T> ProviderLayer<P, T> for RethDbLayer
impl<P> ProviderLayer<P> for RethDbLayer
where
P: Provider<T>,
T: Transport + Clone,
P: Provider,
{
type Provider = RethDbProvider<P, T>;
type Provider = RethDbProvider<P>;

fn layer(&self, inner: P) -> Self::Provider {
RethDbProvider::new(inner, self.db_path().clone())
Expand All @@ -113,14 +112,13 @@ where
/// It holds the `reth_provider::ProviderFactory` that enables read-only access to the database
/// tables and static files.
#[derive(Clone, Debug)]
pub struct RethDbProvider<P, T> {
pub struct RethDbProvider<P> {
inner: P,
db_path: PathBuf,
provider_factory: DbAccessor,
_pd: PhantomData<T>,
}

impl<P, T> RethDbProvider<P, T> {
impl<P> RethDbProvider<P> {
/// Create a new `RethDbProvider` instance.
pub fn new(inner: P, db_path: PathBuf) -> Self {
let db = open_db_read_only(&db_path, Default::default()).unwrap();
Expand All @@ -134,7 +132,7 @@ impl<P, T> RethDbProvider<P, T> {
let db_accessor: DbAccessor<
ProviderFactory<NodeTypesWithDBAdapter<EthereumNode, Arc<DatabaseEnv>>>,
> = DbAccessor::new(provider_factory);
Self { inner, db_path, provider_factory: db_accessor, _pd: PhantomData }
Self { inner, db_path, provider_factory: db_accessor }
}

const fn factory(&self) -> &DbAccessor {
Expand All @@ -150,17 +148,16 @@ impl<P, T> RethDbProvider<P, T> {
/// Implement the `Provider` trait for the `RethDbProvider` struct.
///
/// This is where we override specific RPC methods to fetch from the reth-db.
impl<P, T> Provider<T> for RethDbProvider<P, T>
impl<P> Provider for RethDbProvider<P>
where
P: Provider<T>,
T: Transport + Clone,
P: Provider,
{
fn root(&self) -> &RootProvider<T> {
fn root(&self) -> &RootProvider {
self.inner.root()
}

/// Override the `get_block_number` method to fetch the latest block number from the reth-db.
fn get_block_number(&self) -> ProviderCall<T, NoParams, U64, u64> {
fn get_block_number(&self) -> ProviderCall<NoParams, U64, u64> {
let provider = self.factory().provider().map_err(TransportErrorKind::custom).unwrap();

let best = provider.best_block_number().map_err(TransportErrorKind::custom);
Expand All @@ -171,7 +168,7 @@ where
/// Override the `get_transaction_count` method to fetch the transaction count of an address.
///
/// `RpcWithBlock` uses `ProviderCall` under the hood.
fn get_transaction_count(&self, address: Address) -> RpcWithBlock<T, Address, U64, u64> {
fn get_transaction_count(&self, address: Address) -> RpcWithBlock<Address, U64, u64> {
let this = self.factory().clone();
RpcWithBlock::new_provider(move |block_id| {
let provider = this.provider_at(block_id).map_err(TransportErrorKind::custom).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/examples/deploy_from_artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sol!(
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet();
let provider = ProviderBuilder::new().on_anvil_with_wallet();

// Deploy the `Counter` contract.
let contract = Counter::deploy(&provider).await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/examples/deploy_from_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sol! {
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet();
let provider = ProviderBuilder::new().on_anvil_with_wallet();

// Deploy the `Counter` contract from bytecode at runtime.
let bytecode = hex::decode(
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/examples/deploy_from_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sol! {
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet();
let provider = ProviderBuilder::new().on_anvil_with_wallet();

// Deploy the `Counter` contract.
let contract = Counter::deploy(&provider).await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/examples/interact_with_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn main() -> Result<()> {
// Ensure `anvil` is available in $PATH.
let rpc_url = "https://eth.merkle.io";
let provider =
ProviderBuilder::new().on_anvil_with_wallet_and_config(|anvil| anvil.fork(rpc_url));
ProviderBuilder::new().on_anvil_with_wallet_and_config(|anvil| anvil.fork(rpc_url))?;

// Create a contract instance.
let contract = IWETH9::new(address!("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"), provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use eyre::Result;
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet();
let provider = ProviderBuilder::new().on_anvil_with_wallet();

// Deploy the `Counter` contract from bytecode at runtime.
let bytecode = hex::decode(
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/examples/unknown_return_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use eyre::Result;
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet();
let provider = ProviderBuilder::new().on_anvil_with_wallet();

// Get the first account from the wallet, Alice.
let alice = provider.get_accounts().await?[0];
Expand Down
6 changes: 3 additions & 3 deletions examples/fillers/examples/gas_filler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use eyre::Result;
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let provider = ProviderBuilder::new()
let provider = ProviderBuilder::default()
// Add the `GasFiller` to the provider.
// It is generally recommended to use the `.with_recommended_fillers()` method, which
// includes the `GasFiller`.
// It is generally recommended to use the recommended fillers which includes the GasFiller,
// enabled by building the provider using ProviderBuilder::new().
.with_gas_estimation()
.on_anvil_with_wallet();

Expand Down
9 changes: 7 additions & 2 deletions examples/fillers/examples/nonce_filler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ use eyre::Result;
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
// ProviderBuilder::new() enables the recommended fillers by default (ChainIdFiller, GasFiller
// and NonceFiller).
let provider = ProviderBuilder::new()
// You can disable the recommended fillers by calling the `disable_recommended_fillers()`
// and pick the fillers of your choice.
.disable_recommended_fillers()
// Add the `NonceFiller` to the provider.
// It is generally recommended to use the `.with_recommended_fillers()` method, which
// includes the `NonceFiller`.
// It is generally recommended to use the recommended fillers which includes the
// NonceFiller, enabled by building the provider using ProviderBuilder::new().
//
// The `NonceFiller` has two types: `Cached` and `Simple`.
// Unlike `Cached`, `Simple` does not store the transaction count locally,
Expand Down
5 changes: 4 additions & 1 deletion examples/fillers/examples/recommended_fillers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ use eyre::Result;
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
// After `alloy 0.11`, the recommended fillers are enabled by default when building the provider
// with `ProviderBuilder::new()`.
let provider = ProviderBuilder::new()
// Adds the `ChainIdFiller`, `GasFiller` and the `NonceFiller` layers.
// This is the recommended way to set up the provider.
.with_recommended_fillers()
// One can disable the recommended fillers by calling the `disable_recommended_fillers()`
// method or building the provider with `ProviderBuilder::default()`.
.on_anvil_with_wallet();

// Build an EIP-1559 type transaction to send 100 wei to Vitalik.
Expand Down
2 changes: 1 addition & 1 deletion examples/node-bindings/examples/anvil_deploy_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sol! {
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet();
let provider = ProviderBuilder::new().on_anvil_with_wallet();

// Deploy the `Counter` contract.
let contract = Counter::deploy(&provider).await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/node-bindings/examples/anvil_fork_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() -> Result<()> {
// Ensure `anvil` is available in $PATH.
let rpc_url = "https://eth.merkle.io";
let anvil = Anvil::new().fork(rpc_url).try_spawn()?;
let provider = ProviderBuilder::new().with_recommended_fillers().on_http(anvil.endpoint_url());
let provider = ProviderBuilder::new().on_http(anvil.endpoint_url());

// Get node info using the Anvil API.
let info = provider.anvil_node_info().await?;
Expand Down
4 changes: 1 addition & 3 deletions examples/node-bindings/examples/anvil_fork_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ async fn main() -> Result<()> {
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH.
let rpc_url = "https://eth.merkle.io";
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.on_anvil_with_config(|anvil| anvil.fork(rpc_url));
let provider = ProviderBuilder::new().on_anvil_with_config(|anvil| anvil.fork(rpc_url));

// Get node info using the Anvil API.
let info = provider.anvil_node_info().await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/node-bindings/examples/anvil_local_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().block_time(1).chain_id(1337).try_spawn()?;
let provider = ProviderBuilder::new().with_recommended_fillers().on_http(anvil.endpoint_url());
let provider = ProviderBuilder::new().on_http(anvil.endpoint_url());

// Get node info using the Anvil API.
let info = provider.anvil_node_info().await?;
Expand Down
5 changes: 2 additions & 3 deletions examples/node-bindings/examples/anvil_local_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use eyre::Result;
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.on_anvil_with_config(|anvil| anvil.block_time(1).chain_id(1337));
let provider =
ProviderBuilder::new().on_anvil_with_config(|anvil| anvil.block_time(1).chain_id(1337));

// Get node info using the Anvil API.
let info = provider.anvil_node_info().await?;
Expand Down
3 changes: 1 addition & 2 deletions examples/providers/examples/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ async fn main() -> Result<()> {

// Set up the HTTP provider with the `reqwest` crate.
let rpc_url = anvil.endpoint_url();
let provider =
ProviderBuilder::new().with_recommended_fillers().wallet(wallet).on_http(rpc_url);
let provider = ProviderBuilder::new().wallet(wallet).on_http(rpc_url);

// Create a transaction.
let tx = TransactionRequest::default().with_to(bob).with_value(U256::from(100));
Expand Down
2 changes: 1 addition & 1 deletion examples/sol-macro/examples/events_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ sol!(
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let provider = ProviderBuilder::new().with_gas_estimation().on_anvil();
let provider = ProviderBuilder::new().on_anvil_with_wallet();

// Deploy the `Counter` contract.
let contract = CounterWithError::deploy(provider.clone()).await?;
Expand Down
7 changes: 6 additions & 1 deletion examples/subscriptions/examples/event_multiplexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
use std::str::FromStr;

use alloy::{
network::EthereumWallet,
node_bindings::Anvil,
primitives::I256,
providers::{ProviderBuilder, WsConnect},
signers::local::PrivateKeySigner,
sol,
sol_types::SolEvent,
};
Expand Down Expand Up @@ -47,9 +49,12 @@ async fn main() -> Result<()> {
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().block_time(1).try_spawn()?;

let pk: PrivateKeySigner = anvil.keys()[0].clone().into();
let wallet = EthereumWallet::from(pk);

// Create a provider.
let ws = WsConnect::new(anvil.ws_endpoint());
let provider = ProviderBuilder::new().on_ws(ws).await?;
let provider = ProviderBuilder::new().wallet(wallet).on_ws(ws).await?;

// Deploy the `EventExample` contract.
let contract = EventMultiplexer::deploy(provider).await?;
Expand Down
6 changes: 5 additions & 1 deletion examples/subscriptions/examples/poll_logs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Example of watching and polling for contract events by `WebSocket` subscription.

use alloy::{
network::EthereumWallet,
node_bindings::Anvil,
providers::{ProviderBuilder, WsConnect},
signers::local::PrivateKeySigner,
sol,
};
use eyre::Result;
Expand Down Expand Up @@ -36,10 +38,12 @@ async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().block_time(1).try_spawn()?;
let pk: PrivateKeySigner = anvil.keys()[0].clone().into();
let wallet = EthereumWallet::new(pk);

// Create a WebSocket provider.
let ws = WsConnect::new(anvil.ws_endpoint());
let provider = ProviderBuilder::new().on_ws(ws).await?;
let provider = ProviderBuilder::new().wallet(wallet).on_ws(ws).await?;

// Deploy the `Counter` contract.
let contract = Counter::deploy(provider.clone()).await?;
Expand Down
14 changes: 3 additions & 11 deletions examples/transactions/examples/send_eip4844_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use eyre::Result;
async fn main() -> Result<()> {
// Spin up a local Anvil node with the Cancun hardfork enabled.
// Ensure `anvil` is available in $PATH.
let provider =
ProviderBuilder::new().on_anvil_with_config(|anvil| anvil.args(["--hardfork", "cancun"]));
let provider = ProviderBuilder::new()
.on_anvil_with_wallet_and_config(|anvil| anvil.args(["--hardfork", "cancun"]))?;

// Create two users, Alice and Bob.
let accounts = provider.get_accounts().await?;
Expand All @@ -27,15 +27,7 @@ async fn main() -> Result<()> {

// Build a transaction to send the sidecar from Alice to Bob.
// The `from` field is automatically filled to the first signer's address (Alice).
let gas_price = provider.get_gas_price().await?;
let eip1559_est = provider.estimate_eip1559_fees(None).await?;
let tx = TransactionRequest::default()
.with_to(bob)
.with_nonce(0)
.with_max_fee_per_blob_gas(gas_price)
.with_max_fee_per_gas(eip1559_est.max_fee_per_gas)
.with_max_priority_fee_per_gas(eip1559_est.max_priority_fee_per_gas)
.with_blob_sidecar(sidecar);
let tx = TransactionRequest::default().with_to(bob).with_blob_sidecar(sidecar);

// Send the transaction and wait for the broadcast.
let pending_tx = provider.send_transaction(tx).await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ async fn main() -> Result<()> {
// Create a provider with the wallet for only Bob (not Alice).
let rpc_url = anvil.endpoint_url();
let wallet = EthereumWallet::from(bob.clone());
let provider =
ProviderBuilder::new().with_recommended_fillers().wallet(wallet).on_http(rpc_url);
let provider = ProviderBuilder::new().wallet(wallet).on_http(rpc_url);

// Deploy the contract Alice will authorize.
let contract = Log::deploy(&provider).await?;
Expand Down
5 changes: 2 additions & 3 deletions examples/transactions/examples/transfer_erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ async fn main() -> Result<()> {
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH.
let rpc_url = "https://eth.merkle.io";
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.on_anvil_with_wallet_and_config(|anvil| anvil.fork(rpc_url));
let provider =
ProviderBuilder::new().on_anvil_with_wallet_and_config(|anvil| anvil.fork(rpc_url))?;

// Create two users, Alice and Bob.
let accounts = provider.get_accounts().await?;
Expand Down
Loading