Skip to content

Commit

Permalink
feat: introduce hardhat-deploy-config (#2755)
Browse files Browse the repository at this point in the history
* feat: introduce hardhat-deploy-config

Creates a new package hardhat-deploy-config. We're using the same
configuration system for all of our contracts package, so might as well
turn it into a hardhat plugin to avoid duplicating code.

* feat(ct): use hardhat-deploy-config

* plugin: don't validate if spec not passed

* contracts: update deps

* contracts-bedrock: use deploy config plugin

* contracts-bedrock: deploy instructions

* contracts-bedrock: modularize deployment

* contracts-bedrock: add deploy-config

* contracts-bedrock: add in deploy config spec

* lint: fix

Co-authored-by: Mark Tyneway <mark.tyneway@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 14, 2022
1 parent 4b2ed64 commit 27234f6
Show file tree
Hide file tree
Showing 40 changed files with 477 additions and 94 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-months-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/contracts': patch
---

Use hardhat-deploy-config for deployments
5 changes: 5 additions & 0 deletions .changeset/giant-cobras-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/hardhat-deploy-config': minor
---

Initial release of hardhat-deploy-config
1 change: 1 addition & 0 deletions ops/docker/Dockerfile.packages
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ COPY packages/contracts-bedrock/package.json ./packages/contracts-bedrock/packag
COPY packages/contracts-periphery/package.json ./packages/contracts-periphery/package.json
COPY packages/contracts-governance/package.json ./packages/contracts-governance/package.json
COPY packages/data-transport-layer/package.json ./packages/data-transport-layer/package.json
COPY packages/hardhat-deploy-config/package.json ./packages/hardhat-deploy-config/package.json
COPY packages/message-relayer/package.json ./packages/message-relayer/package.json
COPY packages/fault-detector/package.json ./packages/fault-detector/package.json
COPY packages/replica-healthcheck/package.json ./packages/replica-healthcheck/package.json
Expand Down
13 changes: 13 additions & 0 deletions packages/contracts-bedrock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ To run only solidity tests:
```shell
yarn test:forge
```

## Deployment

Create a file that corresponds to the network name in the `deploy-config`
directory and then run the command:

```shell
npx hardhat deploy --network <network-name>
```

In the `hardhat.config.ts`, there is a `deployConfigSpec` field that validates that the types
are correct, be sure to export an object in the `deploy-config/<network-name>.ts` file that
has a key for each property in the `deployConfigSpec`.
13 changes: 13 additions & 0 deletions packages/contracts-bedrock/deploy-config/devnetL1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ethers } from 'ethers'

const config = {
submissionInterval: 6,
l2BlockTime: 2,
genesisOutput: ethers.constants.HashZero,
historicalBlocks: 0,
startingBlockTimestamp:
parseInt(process.env.L2OO_STARTING_BLOCK_TIMESTAMP, 10) || Date.now(),
sequencerAddress: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
}

export default config
13 changes: 13 additions & 0 deletions packages/contracts-bedrock/deploy-config/hardhat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ethers } from 'ethers'

const config = {
submissionInterval: 6,
l2BlockTime: 2,
genesisOutput: ethers.constants.HashZero,
historicalBlocks: 0,
startingBlockTimestamp:
parseInt(process.env.L2OO_STARTING_BLOCK_TIMESTAMP, 10) || Date.now(),
sequencerAddress: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
}

export default config
18 changes: 9 additions & 9 deletions packages/contracts-bedrock/deploy/000-L2OutputOracle.deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()

if (
!process.env.L2OO_STARTING_BLOCK_TIMESTAMP ||
isNaN(Number(process.env.L2OO_STARTING_BLOCK_TIMESTAMP))
typeof hre.deployConfig.startingBlockTimestamp !== 'number' ||
isNaN(hre.deployConfig.startingBlockTimestamp)
) {
throw new Error(
'Cannot deploy L2OutputOracle without specifying a valid L2OO_STARTING_BLOCK_TIMESTAMP.'
'Cannot deploy L2OutputOracle without specifying a valid startingBlockTimestamp.'
)
}

await deploy('L2OutputOracle', {
from: deployer,
args: [
6, // submission interval
2, // l2 block time
`0x${'00'.repeat(32)}`, // genesis output
0, // historical blocks
process.env.L2OO_STARTING_BLOCK_TIMESTAMP,
'0x70997970C51812dc3A010C7d01b50e0d17dc79C8', // sequencer
hre.deployConfig.submissionInterval,
hre.deployConfig.l2BlockTime,
hre.deployConfig.genesisOutput,
hre.deployConfig.historicalBlocks,
hre.deployConfig.startingBlockTimestamp,
hre.deployConfig.sequencerAddress,
],
log: true,
waitConfirmations: 1,
Expand Down
28 changes: 28 additions & 0 deletions packages/contracts-bedrock/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ethers } from 'ethers'
import { HardhatUserConfig, task, subtask } from 'hardhat/config'
import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from 'hardhat/builtin-tasks/task-names'
import '@nomiclabs/hardhat-waffle'
import '@typechain/hardhat'
import 'solidity-coverage'
import 'hardhat-deploy'
import '@foundry-rs/hardhat-forge'
import '@eth-optimism/hardhat-deploy-config'

import './tasks/deposits'

Expand Down Expand Up @@ -33,6 +35,11 @@ const config: HardhatUserConfig = {
],
},
},
paths: {
deploy: './deploy',
deployments: './deployments',
deployConfig: './deploy-config',
},
typechain: {
outDir: 'dist/types',
target: 'ethers-v5',
Expand All @@ -42,6 +49,27 @@ const config: HardhatUserConfig = {
default: 0,
},
},
deployConfigSpec: {
submissionInterval: {
type: 'number',
},
l2BlockTime: {
type: 'number',
},
genesisOutput: {
type: 'string',
default: ethers.constants.HashZero,
},
historicalBlocks: {
type: 'number',
},
startingBlockTimestamp: {
type: 'number',
},
sequencerAddress: {
type: 'address',
},
},
solidity: {
compilers: [
{
Expand Down
1 change: 1 addition & 0 deletions packages/contracts-bedrock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"devDependencies": {
"@foundry-rs/hardhat-forge": "^0.1.5",
"@eth-optimism/hardhat-deploy-config": "^0.1.0",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^2.1.3",
"@nomiclabs/hardhat-waffle": "^2.0.0",
Expand Down
4 changes: 1 addition & 3 deletions packages/contracts/deploy-config/goerli-nightly.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { DeployConfig } from '../src/deploy-config'

const config: DeployConfig = {
const config = {
l1BlockTimeSeconds: 15,
l2BlockGasLimit: 15_000_000,
l2ChainId: 421,
Expand Down
4 changes: 1 addition & 3 deletions packages/contracts/deploy-config/goerli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { DeployConfig } from '../src/deploy-config'

const config: DeployConfig = {
const config = {
numDeployConfirmations: 1,
l1BlockTimeSeconds: 15,
l2BlockGasLimit: 15_000_000,
Expand Down
17 changes: 17 additions & 0 deletions packages/contracts/deploy-config/hardhat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const config = {
l1BlockTimeSeconds: 15,
l2BlockGasLimit: 15_000_000,
l2ChainId: 17,
ctcL2GasDiscountDivisor: 32,
ctcEnqueueGasCost: 60_000,
sccFaultProofWindowSeconds: 0,
sccSequencerPublishWindowSeconds: 12592000,
ovmSequencerAddress: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
ovmProposerAddress: '0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc',
ovmBlockSignerAddress: '0x00000398232E2064F896018496b4b44b3D62751F',
ovmFeeWalletAddress: '0x391716d440c151c42cdf1c95c1d83a5427bca52c',
ovmAddressManagerOwner: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
ovmGasPriceOracleOwner: '0x9965507d1a55bcc2695c58ba16fb37d819b0a4dc',
}

export default config
4 changes: 1 addition & 3 deletions packages/contracts/deploy-config/kovan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { DeployConfig } from '../src/deploy-config'

const config: DeployConfig = {
const config = {
numDeployConfirmations: 1,
gasPrice: 5_000_000_000,
l1BlockTimeSeconds: 15,
Expand Down
4 changes: 1 addition & 3 deletions packages/contracts/deploy-config/local.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { DeployConfig } from '../src/deploy-config'

const config: DeployConfig = {
const config = {
l1BlockTimeSeconds: 15,
l2BlockGasLimit: 15_000_000,
l2ChainId: 17,
Expand Down
4 changes: 1 addition & 3 deletions packages/contracts/deploy-config/mainnet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { DeployConfig } from '../src/deploy-config'

const config: DeployConfig = {
const config = {
numDeployConfirmations: 4,
gasPrice: 150_000_000_000,
l1BlockTimeSeconds: 15,
Expand Down
4 changes: 1 addition & 3 deletions packages/contracts/deploy/000-hardhat-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import {
sendImpersonatedTx,
BIG_BALANCE,
} from '../src/deploy-utils'
import { getDeployConfig } from '../src/deploy-config'
import { names } from '../src/address-names'

const deployFn: DeployFunction = async (hre) => {
const deployConfig = getDeployConfig(hre.network.name)
if (!deployConfig.isForkedNetwork) {
if (!hre.deployConfig.isForkedNetwork) {
return
}

Expand Down
4 changes: 1 addition & 3 deletions packages/contracts/deploy/001-Lib_AddressManager.deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
import { DeployFunction } from 'hardhat-deploy/dist/types'

import { names } from '../src/address-names'
import { getDeployConfig } from '../src/deploy-config'

/* Imports: External */

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

await deploy(names.unmanaged.Lib_AddressManager, {
from: deployer,
args: [],
log: true,
waitConfirmations: deployConfig.numDeployConfirmations,
waitConfirmations: hre.deployConfig.numDeployConfirmations,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import {
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/deploy-utils'
import { getDeployConfig } from '../src/deploy-config'
import { names } from '../src/address-names'

const deployFn: DeployFunction = async (hre) => {
const deployConfig = getDeployConfig(hre.network.name)

const Lib_AddressManager = await getContractFromArtifact(
hre,
names.unmanaged.Lib_AddressManager
Expand All @@ -22,9 +19,9 @@ const deployFn: DeployFunction = async (hre) => {
name: names.managed.contracts.CanonicalTransactionChain,
args: [
Lib_AddressManager.address,
deployConfig.l2BlockGasLimit,
deployConfig.ctcL2GasDiscountDivisor,
deployConfig.ctcEnqueueGasCost,
hre.deployConfig.l2BlockGasLimit,
hre.deployConfig.ctcL2GasDiscountDivisor,
hre.deployConfig.ctcEnqueueGasCost,
],
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import {
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/deploy-utils'
import { getDeployConfig } from '../src/deploy-config'
import { names } from '../src/address-names'

const deployFn: DeployFunction = async (hre) => {
const deployConfig = getDeployConfig(hre.network.name)

const Lib_AddressManager = await getContractFromArtifact(
hre,
names.unmanaged.Lib_AddressManager
Expand All @@ -22,8 +19,8 @@ const deployFn: DeployFunction = async (hre) => {
name: names.managed.contracts.StateCommitmentChain,
args: [
Lib_AddressManager.address,
deployConfig.sccFaultProofWindowSeconds,
deployConfig.sccSequencerPublishWindowSeconds,
hre.deployConfig.sccFaultProofWindowSeconds,
hre.deployConfig.sccSequencerPublishWindowSeconds,
],
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import {
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/deploy-utils'
import { getDeployConfig } from '../src/deploy-config'
import { names } from '../src/address-names'

const deployFn: DeployFunction = async (hre) => {
const deployConfig = getDeployConfig(hre.network.name)

const Lib_AddressManager = await getContractFromArtifact(
hre,
names.unmanaged.Lib_AddressManager
Expand Down Expand Up @@ -48,7 +45,7 @@ const deployFn: DeployFunction = async (hre) => {
console.log(
`Transferring ownership of L1CrossDomainMessenger (implementation)...`
)
const owner = deployConfig.ovmAddressManagerOwner
const owner = hre.deployConfig.ovmAddressManagerOwner
await contract.transferOwnership(owner)

console.log(`Checking that contract owner was correctly set...`)
Expand Down
9 changes: 3 additions & 6 deletions packages/contracts/deploy/010-AddressDictator.deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import {
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/deploy-utils'
import { getDeployConfig } from '../src/deploy-config'
import { names } from '../src/address-names'
import { predeploys } from '../src/predeploys'

const deployFn: DeployFunction = async (hre) => {
const deployConfig = getDeployConfig(hre.network.name)

const Lib_AddressManager = await getContractFromArtifact(
hre,
names.unmanaged.Lib_AddressManager
Expand Down Expand Up @@ -45,13 +42,13 @@ const deployFn: DeployFunction = async (hre) => {
// CanonicalTransactionChain.
{
name: names.managed.accounts.OVM_Sequencer,
address: deployConfig.ovmSequencerAddress,
address: hre.deployConfig.ovmSequencerAddress,
},
// OVM_Proposer is the address allowed to submit state roots (transaction results) to the
// StateCommitmentChain.
{
name: names.managed.accounts.OVM_Proposer,
address: deployConfig.ovmProposerAddress,
address: hre.deployConfig.ovmProposerAddress,
},
]

Expand All @@ -72,7 +69,7 @@ const deployFn: DeployFunction = async (hre) => {
name: names.unmanaged.AddressDictator,
args: [
Lib_AddressManager.address,
deployConfig.ovmAddressManagerOwner,
hre.deployConfig.ovmAddressManagerOwner,
namesAndAddresses.map((pair) => {
return pair.name
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils'

/* Imports: Internal */
import { getContractFromArtifact } from '../src/deploy-utils'
import { getDeployConfig } from '../src/deploy-config'
import { names } from '../src/address-names'

const deployFn: DeployFunction = async (hre) => {
const deployConfig = getDeployConfig(hre.network.name)
const { deployer } = await hre.getNamedAccounts()

// There's a risk that we could get front-run during a fresh deployment, which would brick this
Expand Down Expand Up @@ -45,7 +43,7 @@ const deployFn: DeployFunction = async (hre) => {
)

console.log(`Setting Proxy__OVM_L1CrossDomainMessenger owner...`)
const owner = deployConfig.ovmAddressManagerOwner
const owner = hre.deployConfig.ovmAddressManagerOwner
await Proxy__OVM_L1CrossDomainMessenger.transferOwnership(owner)

console.log(`Checking that the contract owner was correctly set...`)
Expand Down

0 comments on commit 27234f6

Please sign in to comment.