alloy-rs / alloy-rs/alloy

[Feature] Mixed tuple-based and dynamic multicall

Aperta
#4,054 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Rust
Stelle
1.3k
Fork
668
Merge medio
2g 1h
PR unite (30g)
29

Descrizione

### 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_

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start by tracing the provider.multicall(), dynamic(), extend(), aggregate(), and to_aggregate_request() entry points and the existing tuple and dynamic multicall implementations. Determine how nested aggregate requests are decoded, then verify both tuple-inside-dynamic and dynamic-inside-tuple examples produce the shown result shapes.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust
Ambito
blockchain
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.