diff --git a/packages/contracts-bedrock/deploy/020-SystemDictatorSteps-1.ts b/packages/contracts-bedrock/deploy/020-SystemDictatorSteps-1.ts index 1e8900f745432..e1f3980c43089 100644 --- a/packages/contracts-bedrock/deploy/020-SystemDictatorSteps-1.ts +++ b/packages/contracts-bedrock/deploy/020-SystemDictatorSteps-1.ts @@ -11,10 +11,8 @@ import { assertContractVariable, getContractsFromArtifacts, getDeploymentAddress, + doOwnershipTransfer, doPhase, - printJsonTransaction, - printTenderlySimulationLink, - printCastCommand, } from '../src/deploy-utils' const uint128Max = ethers.BigNumber.from('0xffffffffffffffffffffffffffffffff') @@ -73,10 +71,13 @@ const deployFn: DeployFunction = async (hre) => { // Transfer ownership of the ProxyAdmin to the SystemDictator. if ((await ProxyAdmin.owner()) !== SystemDictator.address) { - console.log(`Setting ProxyAdmin owner to MSD`) - await ProxyAdmin.transferOwnership(SystemDictator.address) - } else { - console.log(`Proxy admin already owned by MSD`) + await doOwnershipTransfer({ + isLiveDeployer, + proxy: ProxyAdmin, + name: 'ProxyAdmin', + transferFunc: 'transferOwnership', + dictator: SystemDictator, + }) } // We don't need to transfer proxy addresses if we're already beyond the proxy transfer step. @@ -89,30 +90,13 @@ const deployFn: DeployFunction = async (hre) => { needsProxyTransfer && (await AddressManager.owner()) !== SystemDictator.address ) { - if (isLiveDeployer) { - console.log(`Setting AddressManager owner to MSD`) - await AddressManager.transferOwnership(SystemDictator.address) - } else { - const tx = await AddressManager.populateTransaction.transferOwnership( - SystemDictator.address - ) - console.log(`Please transfer AddressManager owner to MSD`) - console.log(`AddressManager address: ${AddressManager.address}`) - console.log(`MSD address: ${SystemDictator.address}`) - printJsonTransaction(tx) - printCastCommand(tx) - await printTenderlySimulationLink(SystemDictator.provider, tx) - } - - // Wait for the ownership transfer to complete. - await awaitCondition( - async () => { - const owner = await AddressManager.owner() - return owner === SystemDictator.address - }, - 5000, - 1000 - ) + await doOwnershipTransfer({ + isLiveDeployer, + proxy: AddressManager, + name: 'AddressManager', + transferFunc: 'transferOwnership', + dictator: SystemDictator, + }) } else { console.log(`AddressManager already owned by the SystemDictator`) } @@ -124,34 +108,13 @@ const deployFn: DeployFunction = async (hre) => { from: ethers.constants.AddressZero, })) !== SystemDictator.address ) { - if (isLiveDeployer) { - console.log(`Setting L1StandardBridge owner to MSD`) - await L1StandardBridgeProxyWithSigner.setOwner(SystemDictator.address) - } else { - const tx = await L1StandardBridgeProxy.populateTransaction.setOwner( - SystemDictator.address - ) - console.log(`Please transfer L1StandardBridge (proxy) owner to MSD`) - console.log( - `L1StandardBridgeProxy address: ${L1StandardBridgeProxy.address}` - ) - console.log(`MSD address: ${SystemDictator.address}`) - printJsonTransaction(tx) - printCastCommand(tx) - await printTenderlySimulationLink(SystemDictator.provider, tx) - } - - // Wait for the ownership transfer to complete. - await awaitCondition( - async () => { - const owner = await L1StandardBridgeProxy.callStatic.getOwner({ - from: ethers.constants.AddressZero, - }) - return owner === SystemDictator.address - }, - 5000, - 1000 - ) + await doOwnershipTransfer({ + isLiveDeployer, + proxy: L1StandardBridgeProxyWithSigner, + name: 'L1StandardBridgeProxy', + transferFunc: 'setOwner', + dictator: SystemDictator, + }) } else { console.log(`L1StandardBridge already owned by MSD`) } @@ -163,36 +126,41 @@ const deployFn: DeployFunction = async (hre) => { from: ethers.constants.AddressZero, })) !== SystemDictator.address ) { - if (isLiveDeployer) { - console.log(`Setting L1ERC721Bridge owner to MSD`) - await L1ERC721BridgeProxyWithSigner.changeAdmin(SystemDictator.address) - } else { - const tx = await L1ERC721BridgeProxy.populateTransaction.changeAdmin( - SystemDictator.address - ) - console.log(`Please transfer L1ERC721Bridge (proxy) owner to MSD`) - console.log(`L1ERC721BridgeProxy address: ${L1ERC721BridgeProxy.address}`) - console.log(`MSD address: ${SystemDictator.address}`) - printJsonTransaction(tx) - printCastCommand(tx) - await printTenderlySimulationLink(SystemDictator.provider, tx) - } - - // Wait for the ownership transfer to complete. - await awaitCondition( - async () => { - const owner = await L1ERC721BridgeProxy.callStatic.admin({ - from: ethers.constants.AddressZero, - }) - return owner === SystemDictator.address - }, - 5000, - 1000 - ) + await doOwnershipTransfer({ + isLiveDeployer, + proxy: L1ERC721BridgeProxyWithSigner, + name: 'L1ERC721BridgeProxy', + transferFunc: 'changeAdmin', + dictator: SystemDictator, + }) } else { console.log(`L1ERC721Bridge already owned by MSD`) } + // Wait for the ownership transfers to complete before continuing. + await awaitCondition( + async (): Promise => { + const proxyAdminOwner = await ProxyAdmin.owner() + const addressManagerOwner = await AddressManager.owner() + const l1StandardBridgeOwner = + await L1StandardBridgeProxy.callStatic.getOwner({ + from: ethers.constants.AddressZero, + }) + const l1Erc721BridgeOwner = await L1ERC721BridgeProxy.callStatic.admin({ + from: ethers.constants.AddressZero, + }) + + return ( + proxyAdminOwner === SystemDictator.address && + addressManagerOwner === SystemDictator.address && + l1StandardBridgeOwner === SystemDictator.address && + l1Erc721BridgeOwner === SystemDictator.address + ) + }, + 5000, + 1000 + ) + await doPhase({ isLiveDeployer, SystemDictator, diff --git a/packages/contracts-bedrock/src/deploy-utils.ts b/packages/contracts-bedrock/src/deploy-utils.ts index 3c20cb98e548a..cf579569ce223 100644 --- a/packages/contracts-bedrock/src/deploy-utils.ts +++ b/packages/contracts-bedrock/src/deploy-utils.ts @@ -322,6 +322,39 @@ export const printJsonTransaction = (tx: ethers.PopulatedTransaction): void => { ) } +/** + * Mini helper for transferring a Proxy to the MSD + * + * @param opts Options for executing the step. + * @param opts.isLiveDeployer True if the deployer is live. + * @param opts.proxy proxy contract. + * @param opts.dictator dictator contract. + */ +export const doOwnershipTransfer = async (opts: { + isLiveDeployer?: boolean + proxy: ethers.Contract + name: string + transferFunc: string + dictator: ethers.Contract +}): Promise => { + if (opts.isLiveDeployer) { + console.log(`Setting ${opts.name} owner to MSD`) + await opts.proxy[opts.transferFunc](opts.dictator.address) + } else { + const tx = await opts.proxy.populateTransaction[opts.transferFunc]( + opts.dictator.address + ) + console.log(` + Please transfer ${opts.name} (proxy) owner to MSD + - ${opts.name} address: ${opts.proxy.address} + - MSD address: ${opts.dictator.address} + `) + printJsonTransaction(tx) + printCastCommand(tx) + await printTenderlySimulationLink(opts.dictator.provider, tx) + } +} + /** * Mini helper for checking if the current step is a target step. *