From 75951385983e0806b6e876a83a55ad791d95c1bf Mon Sep 17 00:00:00 2001 From: gfijrb Date: Wed, 24 Mar 2021 03:01:35 -0700 Subject: [PATCH] Update Multicall.sol Added possibility to skip call result check, optimize code in aggregate method --- src/Multicall.sol | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Multicall.sol b/src/Multicall.sol index 7e6cd97..df9305d 100644 --- a/src/Multicall.sol +++ b/src/Multicall.sol @@ -11,12 +11,16 @@ contract Multicall { address target; bytes callData; } - function aggregate(Call[] memory calls) public returns (uint256 blockNumber, bytes[] memory returnData) { + function aggregate(Call[] memory calls, bool _checkCall) public returns (uint256 blockNumber, bytes[] memory returnData) { blockNumber = block.number; - returnData = new bytes[](calls.length); - for(uint256 i = 0; i < calls.length; i++) { + uint256 cLen = calls.length; + returnData = new bytes[](cLen); + uint256 i; + for(i; i < cLen; i++) { (bool success, bytes memory ret) = calls[i].target.call(calls[i].callData); - require(success); + if (_checkCall) { + require(success, "Multicall: call failed"); + } returnData[i] = ret; } }