Multicaller
Efficiently call multiple contracts in a single transaction.
Allows for optional "forwarding" of msg.sender
to the contracts called.
Deployments
Please open an issue if you need help to deploy to an EVM chain of your choice.
Contracts
src
├─ Multicaller.sol — "The multicaller contract"
└─ MulticallerReader.sol — "Library to read the `msg.sender` of the multicaller contract"
Installation
You can use the src/MulticallerReader.sol
library in your contracts to query the Multicaller efficiently.
To install with Foundry:
forge install vectorized/multicaller
To install with Hardhat or Truffle:
npm install multicaller
API
Multicaller
aggregate
function aggregate(address[] calldata targets, bytes[] calldata data)
external
payable
returns (bytes[] memory)
Aggregates multiple calls in a single transaction.
The msg.value
will be forwarded to the starting call.
aggregateWithSender
function aggregateWithSender(address[] calldata targets, bytes[] calldata data)
external
payable
returns (bytes[] memory)
Aggregates multiple calls in a single transaction.
The msg.value
will be forwarded to the starting call.
This method will set the multicaller sender to the msg.sender
temporarily for the span of its execution.
This method does not support reentrancy.
fallback
fallback() external payable
Returns the address that called aggregateWithSender
on the contract.
The value is always the zero address outside a transaction.
MulticallerReader
Library to read the sender of the multicaller contract.
multicallerSender
function multicallerSender() internal view returns (address)
Returns the address that called aggregateWithSender
on the multicaller.
sender
function sender() internal view returns (address result)
Returns the address that called aggregateWithSender
on the multicaller, if msg.sender
is the multicaller.
Otherwise, returns msg.sender
.
Design
The contracts are designed with a priority on efficiency and minimalism.
-
Multiple input calldata arrays instead of an array of structs for more compact calldata encoding.
-
Omission of utility functions like getBlockNumber
for more efficient function dispatch. If you need those functions, just add those functions into your contract, or read them off a separate utility contract like MakerDao's Multicall.
Safety
We do not give any warranties and will not be liable for any loss incurred through any use of this codebase.
Acknowledgments
Multicaller is inspired by and directly modified from:
This project is a public good initiative of sound.xyz and Solady.
We would like to thank our reviewers and contributors for their invaluable help.