forked from Uniswap/v3-periphery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniswapInterfaceMulticall.sol
39 lines (34 loc) · 1.27 KB
/
UniswapInterfaceMulticall.sol
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
// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
pragma abicoder v2;
/// @notice A fork of Multicall2 specifically tailored for the Uniswap Interface
contract UniswapInterfaceMulticall {
struct Call {
address target;
uint256 gasLimit;
bytes callData;
}
struct Result {
bool success;
uint256 gasUsed;
bytes returnData;
}
function getCurrentBlockTimestamp() public view returns (uint256 timestamp) {
timestamp = block.timestamp;
}
function getEthBalance(address addr) public view returns (uint256 balance) {
balance = addr.balance;
}
function multicall(Call[] memory calls) public returns (uint256 blockNumber, Result[] memory returnData) {
blockNumber = block.number;
returnData = new Result[](calls.length);
for (uint256 i = 0; i < calls.length; i++) {
(address target, uint256 gasLimit, bytes memory callData) =
(calls[i].target, calls[i].gasLimit, calls[i].callData);
uint256 gasLeftBefore = gasleft();
(bool success, bytes memory ret) = target.call{gas: gasLimit}(callData);
uint256 gasUsed = gasLeftBefore - gasleft();
returnData[i] = Result(success, gasUsed, ret);
}
}
}