Skip to content

Commit

Permalink
Add entrypoint to deploy against existing Superchain
Browse files Browse the repository at this point in the history
Creates a separate entrypoint in the deploy script to allow an L2 to be deployed against an existing set of Superchain contracts. The deployment assumes that the Superchain contracts have been deployed correctly. The L2 still gets its own ProxyAdmin, AddressManager, and Safe. The API is additive and backwards-compatible.
  • Loading branch information
mslipper committed Sep 9, 2024
1 parent 40750a5 commit 41ea87e
Showing 1 changed file with 56 additions and 10 deletions.
66 changes: 56 additions & 10 deletions packages/contracts-bedrock/scripts/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,36 @@ contract Deploy is Deployer {
_run();
}

function runWithSuperchain(
address payable _superchainConfigProxy,
address payable _protocolVersionsProxy,
bool includeDump
) public {
require(_superchainConfigProxy != address(0), "must specify address for superchain config proxy");
require(_protocolVersionsProxy != address(0), "must specify address for protocol versions proxy");

vm.chainId(cfg.l1ChainID());

console.log("Deploying a fresh OP Stack with existing SuperchainConfig and ProtocolVersions");

Proxy scProxy = Proxy(_superchainConfigProxy);
save("SuperchainConfig", scProxy.implementation());
save("SuperchainConfigProxy", _superchainConfigProxy);

Proxy pvProxy = Proxy(_protocolVersionsProxy);
save("ProtocolVersions", pvProxy.implementation());
save("ProtocolVersionsProxy", _protocolVersionsProxy);

// We still need to set up the address manager and proxy admin
// for this specific chain.
setupAdmin();
_run(false);

if (includeDump) {
vm.dumpState(Config.stateDumpPath(""));
}
}

function runWithStateDump() public {
vm.chainId(cfg.l1ChainID());
_run();
Expand All @@ -284,13 +314,29 @@ contract Deploy is Deployer {
_run();
}

/// @notice Internal function containing the deploy logic.
/// @notice Compatibility function for tests that override _run().
function _run() internal virtual {
_run(true);
}

/// @notice Internal function containing the deploy logic.
function _run(bool _needsSuperchain) internal {
console.log("start of L1 Deploy!");
deploySafe("SystemOwnerSafe");
console.log("deployed Safe!");
setupSuperchain();
console.log("set up superchain!");

// Deploy a new ProxyAdmin and AddressManager
// This proxy will be used on the SuperchainConfig and ProtocolVersions contracts, as well as the contracts
// in the OP Chain system.
setupAdmin();

console.log("needs superchain?", _needsSuperchain);

if (_needsSuperchain) {
setupSuperchain();
console.log("set up superchain!");
}

if (cfg.useAltDA()) {
bytes32 typeHash = keccak256(bytes(cfg.daCommitmentType()));
bytes32 keccakHash = keccak256(bytes("KeccakCommitment"));
Expand All @@ -306,20 +352,20 @@ contract Deploy is Deployer {
// High Level Deployment Functions //
////////////////////////////////////////////////////////////////

/// @notice Deploy the address manager and proxy admin contracts.
function setupAdmin() public {
deployAddressManager();
deployProxyAdmin();
transferProxyAdminOwnership();
}

/// @notice Deploy a full system with a new SuperchainConfig
/// The Superchain system has 2 singleton contracts which lie outside of an OP Chain:
/// 1. The SuperchainConfig contract
/// 2. The ProtocolVersions contract
function setupSuperchain() public {
console.log("Setting up Superchain");

// Deploy a new ProxyAdmin and AddressManager
// This proxy will be used on the SuperchainConfig and ProtocolVersions contracts, as well as the contracts
// in the OP Chain system.
deployAddressManager();
deployProxyAdmin();
transferProxyAdminOwnership();

// Deploy the SuperchainConfigProxy
deployERC1967Proxy("SuperchainConfigProxy");
deploySuperchainConfig();
Expand Down

0 comments on commit 41ea87e

Please sign in to comment.