Skip to content

Instantly share code, notes, and snippets.

@zemse
Created May 18, 2021 01:19
Show Gist options
  • Save zemse/8377f6a2aced2bcf712aef6bdb34e7cc to your computer and use it in GitHub Desktop.
Save zemse/8377f6a2aced2bcf712aef6bdb34e7cc to your computer and use it in GitHub Desktop.
This Multicall aggregates results from multiple contract constant function calls which are not all required to succeed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Copied and modified from https://github.com/makerdao/multicall/blob/e0c7d96c105b665b24ba9b7be22d9df22199de82/src/Multicall.sol
// This Multicall aggregates results from multiple contract constant function calls
// which are not all required to succeed.
contract Multicall {
struct Call {
address target;
bytes callData;
}
struct Result {
bool success;
bytes returnData;
}
function aggregate(Call[] memory calls) public returns (uint256 blockNumber, Result[] memory result) {
blockNumber = block.number;
result = new Result[](calls.length);
for(uint256 i = 0; i < calls.length; i++) {
(result[i].success, result[i].returnData) = calls[i].target.call(calls[i].callData);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment