Commit f4c454d1 authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: cleanup deploy script

Use a standard modifier to skip deploying contracts to non devnet
networks. Simplifies the code, removes branching, ensures that
the contracts are always deployed as expected.
parent a9dcc0b1
...@@ -109,6 +109,14 @@ contract Deploy is Deployer { ...@@ -109,6 +109,14 @@ contract Deploy is Deployer {
vm.stopBroadcast(); vm.stopBroadcast();
} }
/// @notice Modifier that will only allow a function to be called on devnet.
modifier onlyDevnet() internal view returns (bool) {
uint256 chainid = block.chainid;
if chaind != Chains.LocalDevnet && chainid != Chains.GethDevnet {
_;
}
}
/// @notice Deploy the AddressManager /// @notice Deploy the AddressManager
function deployAddressManager() broadcast() public returns (address) { function deployAddressManager() broadcast() public returns (address) {
AddressManager manager = new AddressManager(); AddressManager manager = new AddressManager();
...@@ -250,22 +258,19 @@ contract Deploy is Deployer { ...@@ -250,22 +258,19 @@ contract Deploy is Deployer {
} }
/// @notice Deploy the DisputeGameFactoryProxy /// @notice Deploy the DisputeGameFactoryProxy
function deployDisputeGameFactoryProxy() broadcast() public returns (address) { function deployDisputeGameFactoryProxy() onlyDevnet broadcast() public returns (address) {
if (block.chainid == Chains.LocalDevnet || block.chainid == Chains.GethDevnet) { address proxyAdmin = mustGetAddress("ProxyAdmin");
address proxyAdmin = mustGetAddress("ProxyAdmin"); Proxy proxy = new Proxy({
Proxy proxy = new Proxy({ _admin: proxyAdmin
_admin: proxyAdmin });
});
address admin = address(uint160(uint256(vm.load(address(proxy), OWNER_KEY)))); address admin = address(uint160(uint256(vm.load(address(proxy), OWNER_KEY))));
require(admin == proxyAdmin); require(admin == proxyAdmin);
save("DisputeGameFactoryProxy", address(proxy)); save("DisputeGameFactoryProxy", address(proxy));
console.log("DisputeGameFactoryProxy deployed at %s", address(proxy)); console.log("DisputeGameFactoryProxy deployed at %s", address(proxy));
return address(proxy); return address(proxy);
}
return address(0);
} }
/// @notice Deploy the L1CrossDomainMessenger /// @notice Deploy the L1CrossDomainMessenger
...@@ -351,39 +356,36 @@ contract Deploy is Deployer { ...@@ -351,39 +356,36 @@ contract Deploy is Deployer {
} }
/// @notice Deploy the DisputeGameFactory /// @notice Deploy the DisputeGameFactory
function deployDisputeGameFactory() broadcast() public returns (address) { function deployDisputeGameFactory() onlyDevnet broadcast() public returns (address) {
if (block.chainid == Chains.LocalDevnet || block.chainid == Chains.GethDevnet) { DisputeGameFactory factory = new DisputeGameFactory();
DisputeGameFactory factory = new DisputeGameFactory(); save("DisputeGameFactory", address(factory));
save("DisputeGameFactory", address(factory)); console.log("DisputeGameFactory deployed at %s", address(factory));
console.log("DisputeGameFactory deployed at %s", address(factory));
return address(factory); return address(factory);
}
return address(0);
} }
/// @notice Deploy the PreimageOracle /// @notice Deploy the PreimageOracle
function deployPreimageOracle() broadcast() public returns (address) { function deployPreimageOracle() onlyDevnet broadcast() public returns (address) {
if (block.chainid == 900) { PreimageOracle preimageOracle = new PreimageOracle();
PreimageOracle preimageOracle = new PreimageOracle(); save("PreimageOracle", address(preimageOracle));
save("PreimageOracle", address(preimageOracle)); console.log("PreimageOracle deployed at %s", address(preimageOracle));
console.log("PreimageOracle deployed at %s", address(preimageOracle));
return address(preimageOracle); string memory version = preimageOracle.version();
} console.log("PreimageOracle version: %s", version);
return address(0);
return address(preimageOracle);
} }
/// @notice Deploy Mips /// @notice Deploy Mips
function deployMips() broadcast() public returns (address) { function deployMips() onlyDevnet broadcast() public returns (address) {
if (block.chainid == 900) { MIPS mips = new MIPS();
MIPS mips = new MIPS(); save("Mips", address(mips));
save("Mips", address(mips)); console.log("MIPS deployed at %s", address(mips));
console.log("Mips deployed at %s", address(mips));
return address(mips); string memory version = mips.version();
} console.log("MIPS version: %s", version);
return address(0);
return address(mips);
} }
/// @notice Deploy the SystemConfig /// @notice Deploy the SystemConfig
...@@ -470,24 +472,22 @@ contract Deploy is Deployer { ...@@ -470,24 +472,22 @@ contract Deploy is Deployer {
} }
/// @notice Initialize the DisputeGameFactory /// @notice Initialize the DisputeGameFactory
function initializeDisputeGameFactory() broadcast() public { function initializeDisputeGameFactory() onlyDevnet broadcast() public {
if (block.chainid == Chains.LocalDevnet || block.chainid == Chains.GethDevnet) { ProxyAdmin proxyAdmin = ProxyAdmin(mustGetAddress("ProxyAdmin"));
ProxyAdmin proxyAdmin = ProxyAdmin(mustGetAddress("ProxyAdmin")); address disputeGameFactoryProxy = mustGetAddress("DisputeGameFactoryProxy");
address disputeGameFactoryProxy = mustGetAddress("DisputeGameFactoryProxy"); address disputeGameFactory = mustGetAddress("DisputeGameFactory");
address disputeGameFactory = mustGetAddress("DisputeGameFactory");
proxyAdmin.upgradeAndCall({
_proxy: payable(disputeGameFactoryProxy),
_implementation: disputeGameFactory,
_data: abi.encodeCall(
DisputeGameFactory.initialize,
(msg.sender)
)
});
string memory version = DisputeGameFactory(disputeGameFactoryProxy).version(); proxyAdmin.upgradeAndCall({
console.log("DisputeGameFactory version: %s", version); _proxy: payable(disputeGameFactoryProxy),
} _implementation: disputeGameFactory,
_data: abi.encodeCall(
DisputeGameFactory.initialize,
(msg.sender)
)
});
string memory version = DisputeGameFactory(disputeGameFactoryProxy).version();
console.log("DisputeGameFactory version: %s", version);
} }
/// @notice Initialize the SystemConfig /// @notice Initialize the SystemConfig
...@@ -704,34 +704,30 @@ contract Deploy is Deployer { ...@@ -704,34 +704,30 @@ contract Deploy is Deployer {
} }
/// @notice Transfer ownership of the DisputeGameFactory contract to the final system owner /// @notice Transfer ownership of the DisputeGameFactory contract to the final system owner
function transferDisputeGameFactoryOwnership() broadcast() public { function transferDisputeGameFactoryOwnership() onlyDevnet broadcast() public {
if (block.chainid == Chains.LocalDevnet || block.chainid == Chains.GethDevnet) { DisputeGameFactory disputeGameFactory = DisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy"));
DisputeGameFactory disputeGameFactory = DisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy")); address owner = disputeGameFactory.owner();
address owner = disputeGameFactory.owner(); address finalSystemOwner = cfg.finalSystemOwner();
address finalSystemOwner = cfg.finalSystemOwner(); if (owner != finalSystemOwner) {
if (owner != finalSystemOwner) { disputeGameFactory.transferOwnership(finalSystemOwner);
disputeGameFactory.transferOwnership(finalSystemOwner); console.log("DisputeGameFactory ownership transferred to: %s", finalSystemOwner);
console.log("DisputeGameFactory ownership transferred to: %s", finalSystemOwner);
}
} }
} }
/// @notice Sets the implementation for the `FAULT` game type in the `DisputeGameFactory` /// @notice Sets the implementation for the `FAULT` game type in the `DisputeGameFactory`
function setFaultGameImplementation() broadcast() public { function setFaultGameImplementation() onlyDevnet broadcast() public {
if (block.chainid == Chains.LocalDevnet || block.chainid == Chains.GethDevnet) { DisputeGameFactory factory = DisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy"));
DisputeGameFactory factory = DisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy")); Claim absolutePrestate = Claim.wrap(bytes32(cfg.faultGameAbsolutePrestate()));
Claim absolutePrestate = Claim.wrap(bytes32(cfg.faultGameAbsolutePrestate())); IBigStepper faultVm = IBigStepper(new AlphabetVM(absolutePrestate));
IBigStepper faultVm = IBigStepper(new AlphabetVM(absolutePrestate)); if (address(factory.gameImpls(GameTypes.FAULT)) == address(0)) {
if (address(factory.gameImpls(GameTypes.FAULT)) == address(0)) { factory.setImplementation(GameTypes.FAULT, new FaultDisputeGame({
factory.setImplementation(GameTypes.FAULT, new FaultDisputeGame({ _absolutePrestate: absolutePrestate,
_absolutePrestate: absolutePrestate, _maxGameDepth: cfg.faultGameMaxDepth(),
_maxGameDepth: cfg.faultGameMaxDepth(), _gameDuration: Duration.wrap(uint64(cfg.faultGameMaxDuration())),
_gameDuration: Duration.wrap(uint64(cfg.faultGameMaxDuration())), _vm: faultVm,
_vm: faultVm, _l2oo: L2OutputOracle(mustGetAddress("L2OutputOracleProxy"))
_l2oo: L2OutputOracle(mustGetAddress("L2OutputOracleProxy")) }));
})); console.log("DisputeGameFactory: set `FaultDisputeGame` implementation");
console.log("DisputeGameFactory: set `FaultDisputeGame` implementation");
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment