Skip to content

Commit

Permalink
feat: cleanup deployment process
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcontracts committed Oct 14, 2021
1 parent 34854f9 commit f34a4b2
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 206 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-shirts-develop.md
@@ -0,0 +1,5 @@
---
'@eth-optimism/contracts': patch
---

Cleans up the contract deployment process
9 changes: 8 additions & 1 deletion packages/contracts/deploy/000-Lib_AddressManager.deploy.ts
Expand Up @@ -15,25 +15,32 @@ const deployFn: DeployFunction = async (hre) => {
log: true,
})

// L2CrossDomainMessenger is the address of the predeploy on L2. We can refactor off-chain
// services such that we can remove the need to set this address, but for now it's easier
// to simply keep setting the address.
await registerAddress({
hre,
name: 'L2CrossDomainMessenger',
address: predeploys.L2CrossDomainMessenger,
})

// OVM_Sequencer is the address allowed to submit "Sequencer" blocks to the
// CanonicalTransactionChain.
await registerAddress({
hre,
name: 'OVM_Sequencer',
address: (hre as any).deployConfig.ovmSequencerAddress,
})

// OVM_Proposer is the address allowed to submit state roots (transaction results) to the
// StateCommitmentChain.
await registerAddress({
hre,
name: 'OVM_Proposer',
address: (hre as any).deployConfig.ovmProposerAddress,
})
}

deployFn.tags = ['Lib_AddressManager', 'required']
deployFn.tags = ['Lib_AddressManager']

export default deployFn
25 changes: 8 additions & 17 deletions packages/contracts/deploy/006-OVM_BondManager.deploy.ts
Expand Up @@ -2,31 +2,22 @@
import { DeployFunction } from 'hardhat-deploy/dist/types'

/* Imports: Internal */
import { getDeployedContract } from '../src/hardhat-deploy-ethers'
import {
deployAndRegister,
getDeployedContract,
} from '../src/hardhat-deploy-ethers'

const deployFn: DeployFunction = async (hre) => {
const { deploy } = hre.deployments
const { deployer } = await hre.getNamedAccounts()

const Lib_AddressManager = await getDeployedContract(
hre,
'Lib_AddressManager',
{
signerOrProvider: deployer,
}
'Lib_AddressManager'
)

const result = await deploy('BondManager', {
from: deployer,
await deployAndRegister({
hre,
name: 'BondManager',
args: [Lib_AddressManager.address],
log: true,
})

if (!result.newlyDeployed) {
return
}

await Lib_AddressManager.setAddress('BondManager', result.address)
}

deployFn.dependencies = ['Lib_AddressManager']
Expand Down
67 changes: 26 additions & 41 deletions packages/contracts/deploy/007-OVM_L1CrossDomainMessenger.deploy.ts
@@ -1,56 +1,41 @@
/* Imports: External */
import { DeployFunction } from 'hardhat-deploy/dist/types'
import { hexStringEquals } from '@eth-optimism/core-utils'

/* Imports: Internal */
import { getDeployedContract } from '../src/hardhat-deploy-ethers'
import {
getDeployedContract,
deployAndRegister,
waitUntilTrue,
} from '../src/hardhat-deploy-ethers'

const deployFn: DeployFunction = async (hre) => {
const { deploy } = hre.deployments
const { deployer } = await hre.getNamedAccounts()

const Lib_AddressManager = await getDeployedContract(
hre,
'Lib_AddressManager',
{
signerOrProvider: deployer,
}
'Lib_AddressManager'
)

const result = await deploy('L1CrossDomainMessenger', {
from: deployer,
await deployAndRegister({
hre,
name: 'L1CrossDomainMessenger',
args: [],
log: true,
postDeployAction: async (contract) => {
// Theoretically it's not necessary to initialize this contract since it sits behind
// a proxy. However, it's best practice to initialize it anyway just in case there's
// some unknown security hole. It also prevents another user from appearing like an
// official address because it managed to call the initialization function.
console.log(`Initializing L1CrossDomainMessenger...`)
await contract.initialize(Lib_AddressManager.address)

console.log(`Checking that contract was correctly initialized...`)
await waitUntilTrue(async () => {
return hexStringEquals(
await contract.libAddressManager(),
Lib_AddressManager.address
)
})
},
})

if (!result.newlyDeployed) {
return
}

const L1CrossDomainMessenger = await getDeployedContract(
hre,
'L1CrossDomainMessenger',
{
signerOrProvider: deployer,
}
)

// NOTE: this initialization is *not* technically required (we only need to initialize the proxy)
// but it feels safer to initialize this anyway. Otherwise someone else could come along and
// initialize this.
await L1CrossDomainMessenger.initialize(Lib_AddressManager.address)

const libAddressManager = await L1CrossDomainMessenger.libAddressManager()
if (libAddressManager !== Lib_AddressManager.address) {
throw new Error(
`\n**FATAL ERROR. THIS SHOULD NEVER HAPPEN. CHECK YOUR DEPLOYMENT.**:\n` +
`L1CrossDomainMessenger could not be succesfully initialized.\n` +
`Attempted to set Lib_AddressManager to: ${Lib_AddressManager.address}\n` +
`Actual address after initialization: ${libAddressManager}\n` +
`This could indicate a compromised deployment.`
)
}

await Lib_AddressManager.setAddress('L1CrossDomainMessenger', result.address)
}

deployFn.dependencies = ['Lib_AddressManager']
Expand Down
@@ -1,59 +1,39 @@
/* Imports: External */
import { DeployFunction } from 'hardhat-deploy/dist/types'
import { hexStringEquals } from '@eth-optimism/core-utils'

/* Imports: Internal */
import { getDeployedContract } from '../src/hardhat-deploy-ethers'
import {
getDeployedContract,
deployAndRegister,
waitUntilTrue,
} from '../src/hardhat-deploy-ethers'

const deployFn: DeployFunction = async (hre) => {
const { deploy } = hre.deployments
const { deployer } = await hre.getNamedAccounts()

const Lib_AddressManager = await getDeployedContract(
hre,
'Lib_AddressManager',
{
signerOrProvider: deployer,
}
'Lib_AddressManager'
)

const result = await deploy('Proxy__L1CrossDomainMessenger', {
await deployAndRegister({
hre,
name: 'Proxy__L1CrossDomainMessenger',
contract: 'Lib_ResolvedDelegateProxy',
from: deployer,
iface: 'L1CrossDomainMessenger',
args: [Lib_AddressManager.address, 'L1CrossDomainMessenger'],
log: true,
postDeployAction: async (contract) => {
console.log(`Initializing Proxy__L1CrossDomainMessenger...`)
await contract.initialize(Lib_AddressManager.address)

console.log(`Checking that contract was correctly initialized...`)
await waitUntilTrue(async () => {
return hexStringEquals(
await contract.libAddressManager(),
Lib_AddressManager.address
)
})
},
})

if (!result.newlyDeployed) {
return
}

const Proxy__L1CrossDomainMessenger = await getDeployedContract(
hre,
'Proxy__L1CrossDomainMessenger',
{
signerOrProvider: deployer,
iface: 'L1CrossDomainMessenger',
}
)

await Proxy__L1CrossDomainMessenger.initialize(Lib_AddressManager.address)

const libAddressManager =
await Proxy__L1CrossDomainMessenger.libAddressManager()
if (libAddressManager !== Lib_AddressManager.address) {
throw new Error(
`\n**FATAL ERROR. THIS SHOULD NEVER HAPPEN. CHECK YOUR DEPLOYMENT.**:\n` +
`Proxy__L1CrossDomainMessenger could not be succesfully initialized.\n` +
`Attempted to set Lib_AddressManager to: ${Lib_AddressManager.address}\n` +
`Actual address after initialization: ${libAddressManager}\n` +
`This could indicate a compromised deployment.`
)
}

await Lib_AddressManager.setAddress(
'Proxy__L1CrossDomainMessenger',
result.address
)
}

deployFn.dependencies = ['Lib_AddressManager', 'L1CrossDomainMessenger']
Expand Down

0 comments on commit f34a4b2

Please sign in to comment.