• Stars
    star
    212
  • Rank 179,802 (Top 4 %)
  • Language
    Solidity
  • License
    MIT License
  • Created about 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Efficient multicaller contracts

Multicaller

NPM CI MIT License

Efficiently call multiple contracts in a single transaction.

Enables "forwarding" of msg.sender to the contracts called.

Deployments

Chain Multicaller MulticallerWithSender
Ethereum 0x000000000088228fCF7b8af41Faf3955bD0B3A41 0x00000000002Fd5Aeb385D324B580FCa7c83823A0
Goerli 0x000000000088228fCF7b8af41Faf3955bD0B3A41 0x00000000002Fd5Aeb385D324B580FCa7c83823A0
Sepolia 0x000000000088228fCF7b8af41Faf3955bD0B3A41 0x00000000002Fd5Aeb385D324B580FCa7c83823A0
Polygon 0x000000000088228fCF7b8af41Faf3955bD0B3A41 0x00000000002Fd5Aeb385D324B580FCa7c83823A0
Mumbai 0x000000000088228fCF7b8af41Faf3955bD0B3A41 0x00000000002Fd5Aeb385D324B580FCa7c83823A0
Optimism 0x000000000088228fCF7b8af41Faf3955bD0B3A41 0x00000000002Fd5Aeb385D324B580FCa7c83823A0
Arbitrum 0x000000000088228fCF7b8af41Faf3955bD0B3A41 0x00000000002Fd5Aeb385D324B580FCa7c83823A0

Please open an issue if you need help to deploy to an EVM chain of your choice.

Contracts

src
├─ Multicaller.sol — "The multicaller contract"
├─ MulticallerWithSender.sol — "The multicaller with sender contract"
└─ LibMulticaller.sol — "Library to read the multicaller with sender contract"

Installation

You can use the src/LibMulticaller.sol library in your contracts to query the multicaller with sender contract 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, uint256[] calldata values)
    external
    payable
    returns (bytes[] memory)

Aggregates multiple calls in a single transaction.

MulticallerWithSender

aggregateWithSender

function aggregateWithSender(address[] calldata targets, bytes[] calldata data, uint256[] calldata values)
    external
    payable
    returns (bytes[] memory)

Aggregates multiple calls in a single transaction.

This method will set the multicaller sender to the msg.sender temporarily for the span of its execution.

This method does not support reentrancy.

receive

receive() external payable

Returns the address that called aggregateWithSender on the contract.

The value is always the zero address outside a transaction.

LibMulticaller

Library to read the multicaller with sender contract.

multicallerSender

function multicallerSender() internal view returns (address)

Returns the address that called aggregateWithSender on the multicaller with sender contract.

sender

function sender() internal view returns (address result)

Returns the address that called aggregateWithSender on the multicaller with sender contract, if msg.sender is the multicaller with sender contract.

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.

Use Cases

For the following, the contracts called must read the msg.sender from the multicaller contract.

The LibMulticaller library can be used for efficient reading.

Example use cases:

  • Calling access role restricted functions across multiple contracts in a single transaction.

  • Approving a trusted operator contract to transfer tokens, and doing the transfer in a single transaction.

    Warning This will skip the approval warning on wallets. To mitigate phishing risk, you should make a custom approval function that validates a time-limited EIP-712 signature signed by the msg.sender.

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.

More Repositories

1

solady

Optimized Solidity snippets.
Solidity
1,976
star
2

dn404

Implementation of a co-joined ERC20 and ERC721 pair.
Solidity
398
star
3

Python-KD-Tree

A simple and fast KD-tree for points in Python for kNN or nearest points. (damm short at just ~60 lines) No libraries needed.
Python
158
star
4

closedsea

Optimized and flexible version of OpenSea's operator filterer
Solidity
130
star
5

soledge

Solidity snippets too edgy to be in Solady
Solidity
101
star
6

Aris

Aris - A fast and powerful tool to write HTML in JS easily. Includes syntax highlighting, templates, SVG, CSS autofixing, debugger support and more...
JavaScript
87
star
7

function-selector-miner

Solidity Function Selector Miner (AVX2 + Multithreaded)
Rust
51
star
8

Static-Sort

A simple C++ header-only library for fastest sorting of small arrays. Generates sorting networks on compile time via templates.
C++
47
star
9

preapprove

On-chain pre-approval registry for NFTs. Library included.
Solidity
41
star
10

Fluidsim

A C++ fluid simulator (SPH, OpenCL, GLSL, SSE, Fast Marching Cubes)
C++
18
star
11

VoxNet-Tensorflow

A Tensorflow Implementation of VoxNet.
Python
11
star
12

Othello-AI

A strong Othello AI bot for 50.021 Artificial Intelligence course.
Python
11
star
13

QDES

Quadratic Decay Exponential Surge
Solidity
9
star
14

Softee

Solidity
4
star
15

vectorized

4
star
16

Solidity-Code-Reviews

2
star
17

Sort-Me

A Realtime Multiplayer Sorting Game for Android
Java
2
star
18

ERC721A-Upgradeable-Old

Upgradeable version of ERC721A
Solidity
2
star
19

Python-Attribute-List

Add/set attributes to Python's built-in list.
Python
1
star
20

NFTStaker

Solidity
1
star
21

ERC721A-Transpiler

Transpiler for creating upgradable ERC721A
TypeScript
1
star
22

SUTD-Staff-Room-Maps-old-Dover-edition

An Android App for navigating the staff room in SUTD's old Dover Campus.
Java
1
star
23

CECSATSolver

CEC-SAT verification software for ISTD 2D Design Challenge
Java
1
star