JEP's Diary

MultiCall, MultiCall2 본문

Development/개념, 이론

MultiCall, MultiCall2

지으니88 2023. 1. 3. 22:19

소스코드 

contract Multicall {
struct Call {
    address target;
    bytes callData;
}
function aggregate(Call[] memory calls) public returns (uint256 blockNumber, bytes[] memory returnData) {
    blockNumber = block.number;
    returnData = new bytes[](calls.length);
    for(uint256 i = 0; i < calls.length; i++) {
        (bool success, bytes memory ret) = calls[i].target.call(calls[i].callData);
        require(success);
        returnData[i] = ret;
    }
}
...
}
contract Multicall2 {
    struct Call {
        address target;
        bytes callData;
    }
    struct Result {
        bool success;
        bytes returnData;
    }
    ...
    function tryAggregate(bool requireSuccess, Call[] memory calls) public returns (Result[] memory returnData) {
        returnData = new Result[](calls.length);
        for(uint256 i = 0; i < calls.length; i++) {
            (bool success, bytes memory ret) = calls[i].target.call(calls[i].callData);

            if (requireSuccess) {
                require(success, "Multicall2 aggregate: call failed");
            }

            returnData[i] = Result(success, ret);
        }
    }

참고

https://github.com/makerdao/multicall/blob/master/src/Multicall2.sol

https://github.com/makerdao/multicall/blob/master/src/Multicall.sol

https://velog.io/@jjimgo/BlockChainProject-%EC%B6%94%EA%B0%80-%EA%B3%B5%EB%B6%80-Solidity-3-compound-MultiCall

'Development > 개념, 이론' 카테고리의 다른 글

AES 암호화  (0) 2023.05.25
니모닉 코드와 마스터 시드 관계  (0) 2023.05.10
Polygon (암호화폐)  (0) 2022.11.10
블록체인 관련 개념  (0) 2022.11.02
JSON-RPC vs REST  (0) 2022.02.16