alloy-rs / alloy-rs/alloy

[Feature] Mixed tuple-based and dynamic multicall

未关闭
#4,054 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
Rust
星标
1.3k
派生
668
平均合并
2 天 2 小时
30 天内合并 PR
29

描述

### Component

provider, pubsub

### Describe the feature you would like

When you need to `eth_call` multiple functions returning different types for each item of a dynamic list, you currently need to perform one separate dynamic multicall for each function:
```rust
async fn separate_multicall(provider: impl Provider, erc20s: &[IERC20Instance]) {
let symbols = provider
.multicall()
.dynamic()
.extend(erc20s.into_iter().map(|e| e.symbol()))
.aggregate()
.await?;
let total_supplies = provider
.multicall()
.dynamic()
.extend(erc20s.into_iter().map(|e| e.totalSupply()))
.aggregate()
.await?;
}
```
It would be a massive performance improvement if that could be done in a single request by mixing the tuple-based and dynamic multicalls, like so:
```rust
async fn multicall_mix(provider: impl Provider, erc20s: &[IERC20Instance]) {
// Dynamic multicall nested inside tuple multicall
let (symbols, total_supplies) = provider
.multicall()
.add(
provider
.multicall()
.dynamic()
.extend(erc20s.into_iter().map(|e| e.symbol()))
.to_aggregate_request(),
)
.add(
provider
.multicall()
.dynamic()
.extend(erc20s.into_iter().map(|e| e.totalSupply()))
.to_aggregate_request(),
)
.aggregate()
.await?;

// Tuple multicall nested inside dynamic multicall
let results: Vec<(String, U256)> = provider
.multicall()
.dynamic()
.extend(erc20s.into_iter().map(|e| {
provider
.multicall()
.add(e.symbol())
.add(e.totalSupply())
.to_aggregate_request()
}))
.aggregate()
.await?;
}
```

### Additional context

_No response_

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。