Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
feat: hardhat-deploy (#418)
Browse files Browse the repository at this point in the history
* chore(hardhat-ovm): yarn lint:fix

* install hardhat-deploy

* refactor: move predeploys to own file

* feat: enable hardhat-deploy on hardhat config

* feat(contracts): add deployment steps

* feat(ops): copy over any additional build files

* ops: make scripts wait for more retries

hardhat-deploy is slower and requires re-compiling
  • Loading branch information
gakonst authored Apr 12, 2021
1 parent 16393c3 commit ed16eac
Show file tree
Hide file tree
Showing 36 changed files with 1,198 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ cache
cache-ovm

l2geth/build/bin

packages/contracts/deployments/custom
20 changes: 18 additions & 2 deletions ops/docker/Dockerfile.deployer
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,30 @@ COPY --from=builder /optimism/node_modules ./node_modules
COPY --from=builder /optimism/packages/core-utils/package.json ./packages/core-utils/package.json
COPY --from=builder /optimism/packages/core-utils/dist ./packages/core-utils/dist

# get the items
COPY --from=builder /optimism/packages/hardhat-ovm/package.json ./packages/hardhat-ovm/package.json
COPY --from=builder /optimism/packages/hardhat-ovm/dist ./packages/hardhat-ovm/dist

# get the needed built artifacts
WORKDIR /opt/optimism/packages/contracts
COPY --from=builder /optimism/packages/contracts/dist ./dist
COPY --from=builder /optimism/packages/contracts/bin ./bin
COPY --from=builder /optimism/packages/contracts/package.json ./
COPY --from=builder /optimism/packages/contracts/*.json ./
COPY --from=builder /optimism/packages/contracts/node_modules ./node_modules
COPY --from=builder /optimism/packages/contracts/artifacts ./artifacts
COPY --from=builder /optimism/packages/contracts/artifacts-ovm ./artifacts-ovm

# copy over the cache so that hardhat-deploy does not recompile
COPY --from=builder /optimism/packages/contracts/cache ./cache
COPY --from=builder /optimism/packages/contracts/cache-ovm ./cache-ovm

# get the files for hardhat-deploy
COPY --from=builder /optimism/packages/contracts/contracts ./contracts
COPY --from=builder /optimism/packages/contracts/hardhat.config.ts ./
COPY --from=builder /optimism/packages/contracts/deploy ./deploy
COPY --from=builder /optimism/packages/contracts/tasks ./tasks
COPY --from=builder /optimism/packages/contracts/src ./src
COPY --from=builder /optimism/packages/contracts/test/helpers/constants.ts ./test/helpers/constants.ts
COPY --from=builder /optimism/packages/contracts/scripts ./scripts

COPY ./ops/scripts/deployer.sh .
ENTRYPOINT yarn run deploy
4 changes: 2 additions & 2 deletions ops/scripts/batches.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
RETRIES=${RETRIES:-20}
RETRIES=${RETRIES:-40}

# get the addrs from the URL provided
ADDRESSES=$(curl --retry-connrefused --retry $RETRIES --retry-delay 3 $URL)
ADDRESSES=$(curl --retry-connrefused --retry $RETRIES --retry-delay 5 $URL)
# set the env
export ADDRESS_MANAGER_ADDRESS=$(echo $ADDRESSES | jq -r '.AddressManager')

Expand Down
7 changes: 3 additions & 4 deletions ops/scripts/deployer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ JSON='{"jsonrpc":"2.0","id":0,"method":"net_version","params":[]}'

# wait for the base layer to be up
curl -H "Content-Type: application/json" --retry-connrefused --retry $RETRIES --retry-delay 1 -d $JSON $L1_NODE_WEB3_URL
# get the addrs to a var
ADDRESSES=$(yarn run --silent deploy)
# sent them to the file
echo $ADDRESSES > dist/dumps/addresses.json

yarn run deploy

# serve the addrs and the state dump
./bin/serve_dump.sh
4 changes: 2 additions & 2 deletions ops/scripts/dtl.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
RETRIES=${RETRIES:-20}
RETRIES=${RETRIES:-40}

# get the addrs from the URL provided
ADDRESSES=$(curl --retry-connrefused --retry $RETRIES --retry-delay 2 $URL)
ADDRESSES=$(curl --retry-connrefused --retry $RETRIES --retry-delay 5 $URL)
# set the env
export DATA_TRANSPORT_LAYER__ADDRESS_MANAGER=$(echo $ADDRESSES | jq -r '.AddressManager')

Expand Down
4 changes: 2 additions & 2 deletions ops/scripts/geth.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
RETRIES=${RETRIES:-20}
RETRIES=${RETRIES:-40}
# get the addrs from the URL provided
ADDRESSES=$(curl --retry-connrefused --retry $RETRIES --retry-delay 1 $URL)
ADDRESSES=$(curl --retry-connrefused --retry $RETRIES --retry-delay 5 $URL)

function envSet() {
VAR=$1
Expand Down
4 changes: 2 additions & 2 deletions ops/scripts/relayer.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
RETRIES=${RETRIES:-20}
RETRIES=${RETRIES:-40}

# get the addrs from the URL provided
ADDRESSES=$(curl --retry-connrefused --retry $RETRIES --retry-delay 3 $URL)
ADDRESSES=$(curl --retry-connrefused --retry $RETRIES --retry-delay 5 $URL)
# set the env
export ADDRESS_MANAGER_ADDRESS=$(echo $ADDRESSES | jq -r '.AddressManager')

Expand Down
114 changes: 0 additions & 114 deletions packages/contracts/bin/deploy.js

This file was deleted.

76 changes: 76 additions & 0 deletions packages/contracts/bin/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env ts-node-script

import { Wallet } from 'ethers'
import path from 'path'
import dirtree from 'directory-tree'
import fs from 'fs'

// Ensures that all relevant environment vars are properly set. These lines *must* come before the
// hardhat import because importing will load the config (which relies on these vars). Necessary
// because CI currently uses different var names than the ones we've chosen here.
// TODO: Update CI so that we don't have to do this anymore.
process.env.HARDHAT_NETWORK = 'custom' // "custom" here is an arbitrary name. only used for CI.
process.env.CONTRACTS_TARGET_NETWORK = 'custom'
process.env.CONTRACTS_DEPLOYER_KEY = process.env.DEPLOYER_PRIVATE_KEY
process.env.CONTRACTS_RPC_URL =
process.env.L1_NODE_WEB3_URL || 'http://127.0.0.1:8545'

import hre from 'hardhat'

const main = async () => {
const sequencer = new Wallet(process.env.SEQUENCER_PRIVATE_KEY)
const deployer = new Wallet(process.env.DEPLOYER_PRIVATE_KEY)

await hre.run('deploy', {
l1BlockTimeSeconds: process.env.BLOCK_TIME_SECONDS,
ctcForceInclusionPeriodSeconds: process.env.FORCE_INCLUSION_PERIOD_SECONDS,
ctcMaxTransactionGasLimit: process.env.MAX_TRANSACTION_GAS_LIMIT,
emMinTransactionGasLimit: process.env.MIN_TRANSACTION_GAS_LIMIT,
emMaxtransactionGasLimit: process.env.MAX_TRANSACTION_GAS_LIMIT,
emMaxGasPerQueuePerEpoch: process.env.MAX_GAS_PER_QUEUE_PER_EPOCH,
emSecondsPerEpoch: process.env.SECONDS_PER_EPOCH,
emOvmChainId: process.env.CHAIN_ID,
sccFraudProofWindow: parseInt(process.env.FRAUD_PROOF_WINDOW_SECONDS, 10),
sccSequencerPublishWindow: process.env.SEQUENCER_PUBLISH_WINDOW_SECONDS,
ovmSequencerAddress: sequencer.address,
ovmProposerAddress: sequencer.address,
ovmRelayerAddress: sequencer.address,
ovmAddressManagerOwner: deployer.address,
})

// Stuff below this line is currently required for CI to work properly. We probably want to
// update our CI so this is no longer necessary. But I'm adding it for backwards compat so we can
// get the hardhat-deploy stuff merged. Woot.
const nicknames = {
'Lib_AddressManager': 'AddressManager',
'mockOVM_BondManager': 'OVM_BondManager'
}

const contracts = dirtree(
path.resolve(__dirname, `../deployments/custom`)
).children.filter((child) => {
return child.extension === '.json'
}).reduce((contracts, child) => {
const contractName = child.name.replace('.json', '')
const artifact = require(path.resolve(__dirname, `../deployments/custom/${child.name}`))
contracts[nicknames[contractName] || contractName] = artifact.address
return contracts
}, {})

const addresses = JSON.stringify(contracts, null, 2)
const dumpsPath = path.resolve(__dirname, "../dist/dumps")
if (!fs.existsSync(dumpsPath)) {
fs.mkdirSync(dumpsPath)
}
const addrsPath = path.resolve(dumpsPath, 'addresses.json')
fs.writeFileSync(addrsPath, addresses)
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.log(
JSON.stringify({ error: error.message, stack: error.stack }, null, 2)
)
process.exit(1)
})
51 changes: 51 additions & 0 deletions packages/contracts/deploy/000-Lib_AddressManager.deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Imports: External */
import { DeployFunction } from 'hardhat-deploy/dist/types'

/* Imports: Internal */
import { registerAddress } from '../src/hardhat-deploy-ethers'
import { predeploys } from '../src/predeploys'

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

await deploy('Lib_AddressManager', {
from: deployer,
args: [],
log: true,
})

await registerAddress({
hre,
name: 'OVM_L2CrossDomainMessenger',
address: predeploys.OVM_L2CrossDomainMessenger,
})

await registerAddress({
hre,
name: 'OVM_DecompressionPrecompileAddress',
address: predeploys.OVM_SequencerEntrypoint,
})

await registerAddress({
hre,
name: 'OVM_Sequencer',
address: (hre as any).deployConfig.ovmSequencerAddress,
})

await registerAddress({
hre,
name: 'OVM_Proposer',
address: (hre as any).deployConfig.ovmProposerAddress,
})

await registerAddress({
hre,
name: 'OVM_L2BatchMessageRelayer',
address: (hre as any).deployConfig.ovmRelayerAddress,
})
}

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

export default deployFn
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Imports: External */
import { DeployFunction } from 'hardhat-deploy/dist/types'

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

const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getDeployedContract(
hre,
'Lib_AddressManager'
)

await deployAndRegister({
hre,
name: 'OVM_ChainStorageContainer:CTC:batches',
contract: 'OVM_ChainStorageContainer',
args: [Lib_AddressManager.address, 'OVM_CanonicalTransactionChain'],
})
}

deployFn.dependencies = ['Lib_AddressManager']
deployFn.tags = ['OVM_ChainStorageContainer_ctc_batches']

export default deployFn
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Imports: External */
import { DeployFunction } from 'hardhat-deploy/dist/types'

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

const deployFn: DeployFunction = async (hre) => {
const Lib_AddressManager = await getDeployedContract(
hre,
'Lib_AddressManager'
)

await deployAndRegister({
hre,
name: 'OVM_ChainStorageContainer:CTC:queue',
contract: 'OVM_ChainStorageContainer',
args: [Lib_AddressManager.address, 'OVM_CanonicalTransactionChain'],
})
}

deployFn.dependencies = ['Lib_AddressManager']
deployFn.tags = ['OVM_ChainStorageContainer_ctc_queue']

export default deployFn
Loading

0 comments on commit ed16eac

Please sign in to comment.