Skip to content

Commit d964f08

Browse files
authored
feat(providers): add multicall batch layer (#2174)
* wip * wip * wip * a * fix draining, more tests, docs * feat: get_balance * chore: outdated todo * test: unasync the closure * docs * use json
1 parent 58012d2 commit d964f08

File tree

5 files changed

+565
-13
lines changed

5 files changed

+565
-13
lines changed

crates/provider/src/builder.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{
33
CachedNonceManager, ChainIdFiller, FillerControlFlow, GasFiller, JoinFill, NonceFiller,
44
NonceManager, RecommendedFillers, SimpleNonceManager, TxFiller, WalletFiller,
55
},
6+
layers::{CallBatchLayer, ChainLayer},
67
provider::SendableTx,
78
Provider, RootProvider,
89
};
@@ -266,12 +267,8 @@ impl<L, F, N> ProviderBuilder<L, F, N> {
266267
/// the client's poll interval based on the average block time for this chain.
267268
///
268269
/// Does nothing to the client with a local transport.
269-
pub fn with_chain(
270-
self,
271-
chain: NamedChain,
272-
) -> ProviderBuilder<Stack<crate::layers::ChainLayer, L>, F, N> {
273-
let chain_layer = crate::layers::ChainLayer::from(chain);
274-
self.layer(chain_layer)
270+
pub fn with_chain(self, chain: NamedChain) -> ProviderBuilder<Stack<ChainLayer, L>, F, N> {
271+
self.layer(ChainLayer::new(chain))
275272
}
276273

277274
/// Finish the layer stack by providing a root [`Provider`], outputting
@@ -398,6 +395,13 @@ impl<L, F, N> ProviderBuilder<L, F, N> {
398395
let client = ClientBuilder::default().hyper_http(url);
399396
self.on_client(client)
400397
}
398+
399+
/// Aggregate multiple `eth_call` requests into a single batch request using Multicall3.
400+
///
401+
/// See [`CallBatchLayer`] for more information.
402+
pub fn with_call_batching(self) -> ProviderBuilder<Stack<CallBatchLayer, L>, F, N> {
403+
self.layer(CallBatchLayer::new())
404+
}
401405
}
402406

403407
impl<L, F, N: Network> ProviderBuilder<L, F, N> {

0 commit comments

Comments
 (0)