-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18MultiCall.sol
More file actions
41 lines (30 loc) · 1001 Bytes
/
18MultiCall.sol
File metadata and controls
41 lines (30 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
# Multi Call
An example of contract that aggregates multiple queries using a for loop and staticcall.
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract MultiCall {
function multiCall(
address[] calldata targets,
bytes[] calldata data
) external view returns (bytes[] memory) {
require(targets.length == data.length, "target length != data length");
bytes[] memory results = new bytes[](data.length);
for (uint i; i < targets.length; i++) {
(bool success, bytes memory result) = targets[i].staticcall(data[i]);
require(success, "call failed");
results[i] = result;
}
return results;
}
}
// Contract to test MultiCall
contract TestMultiCall {
function test(uint _i) external pure returns (uint) {
return _i;
}
function getData(uint _i) external pure returns (bytes memory) {
return abi.encodeWithSelector(this.test.selector, _i);
}
}