-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): multicall3 preinstall
- Loading branch information
Showing
7 changed files
with
257 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import { StdAssertions } from "forge-std/StdAssertions.sol"; | ||
|
||
interface Multicall3 { | ||
struct Call3 { | ||
address target; | ||
bool allowFailure; | ||
bytes callData; | ||
} | ||
|
||
struct Result { | ||
bool success; | ||
bytes returnData; | ||
} | ||
|
||
function aggregate3(Call3[] calldata calls) external payable returns (Result[] memory returnData); | ||
} | ||
|
||
interface GovernanceToken { | ||
function name() external view returns (string memory); | ||
function approve(address spender, uint256 amount) external returns (bool); | ||
function allowance(address owner, address spender) external view returns (uint256); | ||
} | ||
|
||
contract Multicall3Preinstall is Script, StdAssertions { | ||
Multicall3 constant MULTICALL = Multicall3(address(0xcA11bde05977b3631167028862bE2a173976CA11)); | ||
GovernanceToken constant TOKEN = GovernanceToken(address(0x4200000000000000000000000000000000000042)); | ||
|
||
function setUp() public {} | ||
|
||
function run() public { | ||
Multicall3.Call3[] memory calls = new Multicall3.Call3[](2); | ||
calls[0] = Multicall3.Call3({ | ||
target: address(TOKEN), | ||
allowFailure: false, | ||
callData: abi.encodeWithSelector(TOKEN.name.selector) | ||
}); | ||
calls[1] = Multicall3.Call3({ | ||
target: address(TOKEN), | ||
allowFailure: false, | ||
callData: abi.encodeWithSelector(TOKEN.allowance.selector, msg.sender, address(0xdeadeee)) | ||
}); | ||
|
||
vm.broadcast(); | ||
Multicall3.Result[] memory results = MULTICALL.aggregate3(calls); | ||
assertEq(string(abi.decode(results[0].returnData, (string))), "Optimism"); | ||
assertEq(abi.decode(results[1].returnData, (uint256)), 0); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"env": { | ||
"currentCoinbase": "0x0000000000000000000000000000000000000000", | ||
"currentDifficulty": "0xa007e14f44c625904d7d47039486877e86e12a89d546e0e1a362a2fb17b79c3a", | ||
"currentGasLimit": "0x1c9c380", | ||
"previousHash": "0xf5f42bdf56f344c59a1580cfa8fed74f1f68800f5f38499bd241bbe1b6cdfcb5", | ||
"currentNumber": "0x75a1d8c", | ||
"currentTimestamp": "0x66a814d1" | ||
}, | ||
"alloc": { | ||
"0x0000000000000000000000000000000000000000": { | ||
"balance": "0x117b08b474fb13e6", | ||
"nonce": 3 | ||
}, | ||
"0xa0ee7a142d267c1f36714e4a8f75612f20a79720": { | ||
"balance": "0x21e19e0c9bab2400000" | ||
} | ||
}, | ||
"outAlloc": { | ||
"0x0000000000000000000000000000000000000000": { | ||
"balance": "0x117b08b62b56a1e1" | ||
}, | ||
"0xa0ee7a142d267c1f36714e4a8f75612f20a79720": { | ||
"balance": "0x21e19e0c9b67a535d1a", | ||
"nonce": 1 | ||
} | ||
}, | ||
"txs": [ | ||
{ | ||
"EIP1559": { | ||
"chainId": "0xa", | ||
"nonce": "0x0", | ||
"gasLimit": "0xd2c9", | ||
"maxFeePerGas": "0xca207", | ||
"maxPriorityFeePerGas": "0x30a9b", | ||
"to": "0xca11bde05977b3631167028862be2a173976ca11", | ||
"value": "0x0", | ||
"accessList": [], | ||
"input": "0x82ad56cb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000420000000000000000000000000000000000004200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000406fdde03000000000000000000000000000000000000000000000000000000000000000000000000000000004200000000000000000000000000000000000042000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044dd62ed3e000000000000000000000000a0ee7a142d267c1f36714e4a8f75612f20a79720000000000000000000000000000000000000000000000000000000000deadeee00000000000000000000000000000000000000000000000000000000", | ||
"r": "0xa2d599599aada7d2cb5a1055efff0614c7de127c5fb4f5a17f760ff861f341eb", | ||
"s": "0x14054c7a37b36f18aa9e8e08258277e796d1d84a639a14dbb365fa96474f5a03", | ||
"yParity": "0x1", | ||
"hash": "0x127f6f00923b31b9cf117cd336490d6cef58808b57e399a6d91c62e3d1a0d43d" | ||
} | ||
} | ||
], | ||
"result": { | ||
"stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"txRoot": "0xb2ca306b0c8561be7b461cd9f6443e81fa97d5bf9309f86a4505bae9e9cedd2b", | ||
"receiptRoot": "0x8a2435e8a304d276ee6bebb6c6d815d4c35d91446233d5cec6f4636ce6dbd79b", | ||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | ||
"receipts": [ | ||
{ | ||
"root": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"transactionHash": "0x127f6f00923b31b9cf117cd336490d6cef58808b57e399a6d91c62e3d1a0d43d", | ||
"gasUsed": "0x9021", | ||
"blockHash": "0x42d589c3e9bc18c0b27d61d36fea48714c3ac56b59122d6093128f53c3f1a5e3", | ||
"transactionIndex": "0x0", | ||
"type": "0x2", | ||
"status": "0x1", | ||
"cumulativeGasUsed": "0x9021", | ||
"logs": [], | ||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.