pynchmeister / multicaller

Efficient multicaller contract

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multicaller

NPM CI MIT License

Efficiently call multiple contracts in a single transaction.

Allows for optional "forwarding" of msg.sender to the contracts called.

Warning The contracts are being redeployed. Do NOT use yet.

Deployments

Chain Multicaller
Ethereum 0x00000000000066F8295B13Fb252b7f873CBBA71d
Goerli 0x00000000000066F8295B13Fb252b7f873CBBA71d
Polygon 0x00000000000066F8295B13Fb252b7f873CBBA71d
Mumbai 0x00000000000066F8295B13Fb252b7f873CBBA71d
Optimism 0x00000000000066F8295B13Fb252b7f873CBBA71d
Arbitrum 0x00000000000066F8295B13Fb252b7f873CBBA71d

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 msg.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.

About

Efficient multicaller contract

License:MIT License


Languages

Language:Solidity 95.4%Language:Shell 4.6%