Skip to content

Commit

Permalink
feat(examples): multicall3 preinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Jul 29, 2024
1 parent 7070703 commit bca88ec
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 105 deletions.
13 changes: 7 additions & 6 deletions bin/opt8n/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use opt8n::Opt8n;
pub struct Args {
#[command(subcommand)]
pub command: Commands,
#[command(flatten)]
pub node_args: NodeArgs,
}

#[derive(Parser, Clone, Debug)]
Expand Down Expand Up @@ -44,27 +46,26 @@ impl Commands {

#[derive(Parser, Clone, Debug)]
pub struct Opt8nArgs {
#[command(flatten)]
pub node_args: NodeArgs,
#[clap(short, long, help = "Output file for the execution test fixture")]
#[clap(long, help = "Output file for the execution test fixture")]
pub output: PathBuf,
#[clap(short, long, help = "Path to genesis state")]
#[clap(long, help = "Path to genesis state")]
pub genesis: Option<PathBuf>,
}

#[tokio::main]
async fn main() -> eyre::Result<()> {
color_eyre::install()?;
let args = Args::parse();
let node_args = args.node_args.clone();
let opt8n_args = args.command.get_opt8n_args();

let evm_options = &opt8n_args.node_args.evm_opts;
let evm_options = node_args.evm_opts.clone();
let forking = evm_options.fork_url.as_ref().map(|fork_url| Forking {
json_rpc_url: Some(fork_url.url.clone()),
block_number: evm_options.fork_block_number,
});

let node_config = opt8n_args.node_args.clone().into_node_config();
let node_config = node_args.clone().into_node_config();
let mut opt8n = Opt8n::new(
Some(node_config),
forking,
Expand Down
10 changes: 8 additions & 2 deletions examples/exec-scripts/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ forge-updates:
# Generates all execution test fixtures for scripts in this project
gen fork_url: install-opt8n forge-updates
just gen-weth9 {{fork_url}}
just gen-governance-token {{fork_url}}
just gen-multicall3 {{fork_url}}

# Generates the execution test fixture for the weth9 precompile script
gen-weth9 fork_url: install-opt8n forge-updates
opt8n --output ../../fixtures/execution/Weth9Precompile.json --fork-url {{fork_url}} script Weth9Precompile
opt8n --fork-url {{fork_url}} script --output ../../fixtures/execution/Weth9Precompile.json Weth9Precompile

# Generates the execution test fixture for the governance token precompile script
gen-governance-token fork_url: install-opt8n forge-updates
opt8n --output ../../fixtures/execution/GovernanceTokenPrecompile.json --fork-url {{fork_url}} script GovernanceTokenPrecompile
opt8n --fork-url {{fork_url}} script --output ../../fixtures/execution/GovernanceTokenPrecompile.json GovernanceTokenPrecompile

# Generates the execution test fixture for the multicall3 preinstall script
gen-multicall3 fork_url: install-opt8n forge-updates
opt8n --fork-url {{fork_url}} script --output ../../fixtures/execution/Multicall3Preinstall.json Multicall3Preinstall
52 changes: 52 additions & 0 deletions examples/exec-scripts/script/Multicall3Preinstall.s.sol
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);
}
}
94 changes: 94 additions & 0 deletions fixtures/execution/GovernanceTokenPrecompile.json

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions fixtures/execution/Multicall3Preinstall.json
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"
}
]
}
}
Loading

0 comments on commit bca88ec

Please sign in to comment.