-
Notifications
You must be signed in to change notification settings - Fork 128
feat: add new template for addGameType #1027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,144 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.15; | ||
|
|
||
| import {VmSafe} from "forge-std/Vm.sol"; | ||
| import {stdToml} from "forge-std/StdToml.sol"; | ||
|
|
||
| import {OPCMTaskBase} from "src/improvements/tasks/types/OPCMTaskBase.sol"; | ||
| import {SuperchainAddressRegistry} from "src/improvements/SuperchainAddressRegistry.sol"; | ||
|
|
||
| import {IDeputyGuardianModule, IOptimismPortal2} from "@op/interfaces/safe/IDeputyGuardianModule.sol"; | ||
| import {GameType, Claim, Duration} from "@op/src/dispute/lib/Types.sol"; | ||
| import { | ||
| IOPContractsManager, | ||
| IDisputeGameFactory, | ||
| IFaultDisputeGame, | ||
| IBigStepper, | ||
| IProxyAdmin, | ||
| IDelayedWETH, | ||
| ISystemConfig | ||
| } from "@op/interfaces/L1/IOPContractsManager.sol"; | ||
|
|
||
| /// @title AddGameTypeTemplate | ||
| /// @notice This template is used to add a game type to the DisputeGameFactory contract. | ||
| contract AddGameTypeTemplate is OPCMTaskBase { | ||
| using stdToml for string; | ||
|
|
||
| /// @notice Struct that extends the original AddGameInput struct and includes the chain id. | ||
| /// Notably the fields here are also in alphabetical order, this is required because of | ||
| /// the way that Foundry parses TOML data. This MUST be kept in alphabetical order. If | ||
| /// you are adding a new field, you MUST make sure it's in order. Seriously. | ||
| struct AddGameInputWithChainId { | ||
| uint256 chainId; | ||
| IDelayedWETH delayedWETH; | ||
| Claim disputeAbsolutePrestate; | ||
| Duration disputeClockExtension; | ||
| GameType disputeGameType; | ||
| Duration disputeMaxClockDuration; | ||
| uint256 disputeMaxGameDepth; | ||
| uint256 disputeSplitDepth; | ||
| uint256 initialBond; | ||
| bool permissioned; | ||
| IProxyAdmin proxyAdmin; | ||
| string saltMixer; | ||
| ISystemConfig systemConfig; | ||
| IBigStepper vm; | ||
| } | ||
|
|
||
| /// @notice Mapping of chain ID to configuration for the task. | ||
| mapping(uint256 => AddGameInputWithChainId) private cfg; | ||
|
|
||
| /// @notice Returns string identifiers for addresses that are expected to have their storage written to. | ||
| function _taskStorageWrites() internal pure override returns (string[] memory) { | ||
| string[] memory storageWrites = new string[](3); | ||
| storageWrites[0] = "ProxyAdminOwner"; | ||
| storageWrites[1] = "OPCM"; | ||
| storageWrites[2] = "DisputeGameFactoryProxy"; | ||
| return storageWrites; | ||
| } | ||
|
|
||
| /// @notice Sets up the template with implementation configurations from a TOML file. | ||
| function _templateSetup(string memory taskConfigFilePath) internal override { | ||
| super._templateSetup(taskConfigFilePath); | ||
| string memory tomlContent = vm.readFile(taskConfigFilePath); | ||
|
|
||
| // Load configuration. | ||
| AddGameInputWithChainId[] memory configs = | ||
| abi.decode(tomlContent.parseRaw(".configs"), (AddGameInputWithChainId[])); | ||
| for (uint256 i = 0; i < configs.length; i++) { | ||
| cfg[configs[i].chainId] = configs[i]; | ||
| } | ||
|
|
||
| // Load OPCM address. | ||
| OPCM = tomlContent.readAddress(".addresses.OPCM"); | ||
| vm.label(OPCM, "OPCM"); | ||
| } | ||
|
|
||
| /// @notice Write the calls that you want to execute for the task. | ||
| function _build() internal override { | ||
| // Iterate over the chains pull out the configs. | ||
| SuperchainAddressRegistry.ChainInfo[] memory chains = superchainAddrRegistry.getChains(); | ||
| IOPContractsManager.AddGameInput[] memory configs = new IOPContractsManager.AddGameInput[](chains.length); | ||
| for (uint256 i = 0; i < chains.length; i++) { | ||
| uint256 chainId = chains[i].chainId; | ||
| configs[i] = _toAddGameInput(cfg[chainId]); | ||
| } | ||
|
|
||
| // Delegatecall the OPCM.addGameType() function. | ||
| (bool success,) = OPCM.delegatecall(abi.encodeCall(IOPContractsManager.addGameType, configs)); | ||
| require(success, "AddGameType: failed to add game type"); | ||
| } | ||
|
|
||
| /// @notice This method performs all validations and assertions that verify the calls executed as expected. | ||
| function _validate(VmSafe.AccountAccess[] memory, Action[] memory) internal view override { | ||
| // Iterate over the chains and validate the respected game type. | ||
| SuperchainAddressRegistry.ChainInfo[] memory chains = superchainAddrRegistry.getChains(); | ||
| for (uint256 i = 0; i < chains.length; i++) { | ||
| uint256 chainId = chains[i].chainId; | ||
| address factoryAddress = superchainAddrRegistry.getAddress("DisputeGameFactoryProxy", chainId); | ||
| IDisputeGameFactory factory = IDisputeGameFactory(factoryAddress); | ||
| IFaultDisputeGame game = IFaultDisputeGame(address(factory.gameImpls(cfg[chainId].disputeGameType))); | ||
|
|
||
| // Assert that everything is as expected. | ||
| assertEq(address(game.weth()), address(cfg[chainId].delayedWETH)); | ||
| assertEq(game.gameType().raw(), cfg[chainId].disputeGameType.raw()); | ||
| assertEq(game.absolutePrestate().raw(), cfg[chainId].disputeAbsolutePrestate.raw()); | ||
| assertEq(game.maxGameDepth(), cfg[chainId].disputeMaxGameDepth); | ||
| assertEq(game.splitDepth(), cfg[chainId].disputeSplitDepth); | ||
| assertEq(game.clockExtension().raw(), cfg[chainId].disputeClockExtension.raw()); | ||
| assertEq(game.maxClockDuration().raw(), cfg[chainId].disputeMaxClockDuration.raw()); | ||
|
|
||
| // Assert that the bond is set correctly. | ||
| assertEq(factory.initBonds(cfg[chainId].disputeGameType), cfg[chainId].initialBond); | ||
| } | ||
| } | ||
|
|
||
| /// @notice Override to return a list of addresses that should not be checked for code length. | ||
| function getCodeExceptions() internal pure override returns (address[] memory) { | ||
| address[] memory codeExceptions = new address[](0); | ||
| return codeExceptions; | ||
| } | ||
|
|
||
| /// @notice Converts the AddGameInputWithChainId struct to the AddGameInput struct. | ||
| function _toAddGameInput(AddGameInputWithChainId memory _input) | ||
| internal | ||
| pure | ||
| returns (IOPContractsManager.AddGameInput memory) | ||
| { | ||
| return IOPContractsManager.AddGameInput({ | ||
| saltMixer: _input.saltMixer, | ||
| systemConfig: _input.systemConfig, | ||
| proxyAdmin: _input.proxyAdmin, | ||
| delayedWETH: _input.delayedWETH, | ||
| disputeGameType: _input.disputeGameType, | ||
| disputeAbsolutePrestate: _input.disputeAbsolutePrestate, | ||
| disputeMaxGameDepth: _input.disputeMaxGameDepth, | ||
| disputeSplitDepth: _input.disputeSplitDepth, | ||
| disputeClockExtension: _input.disputeClockExtension, | ||
| disputeMaxClockDuration: _input.disputeMaxClockDuration, | ||
| initialBond: _input.initialBond, | ||
| vm: _input.vm, | ||
| permissioned: _input.permissioned | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 @@ | ||
| FORK_BLOCK_NUMBER=8383837 |
This file contains hidden or 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,24 @@ | ||
| templateName = "AddGameTypeTemplate" | ||
|
|
||
| l2chains = [ | ||
| {name = "OP Sepolia Testnet", chainId = 11155420}, | ||
| ] | ||
|
|
||
| [[configs]] | ||
| chainId = 11155420 | ||
| saltMixer = "this is a salt mixer" | ||
| systemConfig = "0x034edD2A225f7f429A63E0f1D2084B9E0A93b538" | ||
| proxyAdmin = "0x189aBAAaa82DfC015A588A7dbaD6F13b1D3485Bc" | ||
| delayedWETH = "0xcdFdC692a53B4aE9F81E0aEBd26107Da4a71dB84" | ||
| disputeGameType = 0 | ||
| disputeAbsolutePrestate = "0x03682932cec7ce0a3874b19675a6bbc923054a7b321efc7d3835187b172494b6" | ||
| disputeMaxGameDepth = 73 | ||
| disputeSplitDepth = 30 | ||
| disputeClockExtension = 10800 | ||
| disputeMaxClockDuration = 302400 | ||
| initialBond = 80000000000000000 | ||
| vm = "0xF027F4A985560fb13324e943edf55ad6F1d15Dc1" | ||
| permissioned = false | ||
|
|
||
| [addresses] | ||
| OPCM = "0xfbceed4de885645fbded164910e10f52febfab35" |
This file contains hidden or 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,24 @@ | ||
| templateName = "AddGameTypeTemplate" | ||
|
|
||
| l2chains = [ | ||
| {name = "OP Sepolia Testnet", chainId = 11155420}, | ||
| ] | ||
|
|
||
| [[configs]] | ||
| chainId = 11155420 | ||
| saltMixer = "this is a salt mixer" | ||
| systemConfig = "0x034edD2A225f7f429A63E0f1D2084B9E0A93b538" | ||
| proxyAdmin = "0x189aBAAaa82DfC015A588A7dbaD6F13b1D3485Bc" | ||
| delayedWETH = "0xcdFdC692a53B4aE9F81E0aEBd26107Da4a71dB84" | ||
| disputeGameType = 0 | ||
| disputeAbsolutePrestate = "0x03682932cec7ce0a3874b19675a6bbc923054a7b321efc7d3835187b172494b6" | ||
| disputeMaxGameDepth = 73 | ||
| disputeSplitDepth = 30 | ||
| disputeClockExtension = 10800 | ||
| disputeMaxClockDuration = 302400 | ||
| initialBond = 80000000000000000 | ||
| vm = "0xF027F4A985560fb13324e943edf55ad6F1d15Dc1" | ||
| permissioned = false | ||
|
|
||
| [addresses] | ||
| OPCM = "0xfbceed4de885645fbded164910e10f52febfab35" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.