Commit 73e9f373 authored by Kelvin Fichter's avatar Kelvin Fichter

maint(ctb): clean up deploy function

Cleans up the custom deployment function that we wrap around
hardhat-deploy and adds new function comments.
parent a37d8623
import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
import { assertContractVariable, deploy } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'ProxyAdmin',
args: [deployer],
......
import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
import { assertContractVariable, deploy } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'Lib_AddressManager',
contract: 'AddressManager',
......
import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
import { assertContractVariable, deploy } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'Proxy__OVM_L1StandardBridge',
contract: 'L1ChugSplashProxy',
......
......@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
deploy,
getDeploymentAddress,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin')
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'L2OutputOracleProxy',
contract: 'Proxy',
......
import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
deployAndVerifyAndThen,
getDeploymentAddress,
} from '../src/deploy-utils'
import { deploy, getDeploymentAddress } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const addressManager = await getDeploymentAddress(hre, 'Lib_AddressManager')
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'Proxy__OVM_L1CrossDomainMessenger',
contract: 'ResolvedDelegateProxy',
......
......@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
deploy,
getDeploymentAddress,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin')
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'OptimismPortalProxy',
contract: 'Proxy',
......
......@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
deploy,
getDeploymentAddress,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin')
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'OptimismMintableERC20FactoryProxy',
contract: 'Proxy',
......
import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
import { assertContractVariable, deploy } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'L1ERC721BridgeProxy',
contract: 'Proxy',
......
......@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
deploy,
getDeploymentAddress,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin')
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'SystemConfigProxy',
contract: 'Proxy',
......
import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
import { assertContractVariable, deploy } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'SystemDictatorProxy',
contract: 'Proxy',
......
......@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
deploy,
getContractFromArtifact,
} from '../src/deploy-utils'
......@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'OptimismPortalProxy'
)
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'L1CrossDomainMessenger',
args: [OptimismPortalProxy.address],
......
......@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { predeploys } from '../src'
import {
assertContractVariable,
deployAndVerifyAndThen,
deploy,
getContractFromArtifact,
} from '../src/deploy-utils'
......@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Proxy__OVM_L1CrossDomainMessenger'
)
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'L1StandardBridge',
args: [L1CrossDomainMessengerProxy.address],
......
......@@ -2,13 +2,10 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import '@eth-optimism/hardhat-deploy-config'
import '@nomiclabs/hardhat-ethers'
import {
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
import { assertContractVariable, deploy } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'L2OutputOracle',
args: [
......
......@@ -3,7 +3,7 @@ import '@eth-optimism/hardhat-deploy-config'
import {
assertContractVariable,
deployAndVerifyAndThen,
deploy,
getContractFromArtifact,
} from '../src/deploy-utils'
......@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'L2OutputOracleProxy'
)
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'OptimismPortal',
args: [
......
......@@ -2,7 +2,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
deploy,
getContractFromArtifact,
} from '../src/deploy-utils'
......@@ -12,7 +12,7 @@ const deployFn: DeployFunction = async (hre) => {
'Proxy__OVM_L1StandardBridge'
)
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'OptimismMintableERC20Factory',
args: [L1StandardBridgeProxy.address],
......
......@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { predeploys } from '../src'
import {
assertContractVariable,
deployAndVerifyAndThen,
deploy,
getContractFromArtifact,
} from '../src/deploy-utils'
......@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Proxy__OVM_L1CrossDomainMessenger'
)
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'L1ERC721Bridge',
args: [L1CrossDomainMessengerProxy.address, predeploys.L2ERC721Bridge],
......
......@@ -2,7 +2,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
assertContractVariable,
deployAndVerifyAndThen,
deploy,
getContractFromArtifact,
} from '../src/deploy-utils'
......@@ -12,7 +12,7 @@ const deployFn: DeployFunction = async (hre) => {
'OptimismPortalProxy'
)
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'PortalSender',
args: [OptimismPortalProxy.address],
......
import { DeployFunction } from 'hardhat-deploy/dist/types'
import '@eth-optimism/hardhat-deploy-config'
import {
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
import { assertContractVariable, deploy } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
const batcherHash = hre.ethers.utils.hexZeroPad(
......@@ -12,7 +9,7 @@ const deployFn: DeployFunction = async (hre) => {
32
)
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'SystemConfig',
args: [
......
......@@ -2,10 +2,10 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import '@eth-optimism/hardhat-deploy-config'
import 'hardhat-deploy'
import { deployAndVerifyAndThen } from '../src/deploy-utils'
import { deploy } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => {
await deployAndVerifyAndThen({
await deploy({
hre,
name: 'SystemDictator',
args: [],
......
......@@ -8,13 +8,26 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'
import 'hardhat-deploy'
import '@eth-optimism/hardhat-deploy-config'
import '@nomiclabs/hardhat-ethers'
export const deployAndVerifyAndThen = async ({
import { Deployment, DeployResult } from 'hardhat-deploy/dist/types'
/**
* Wrapper around hardhat-deploy with some extra features.
*
* @param opts Options for the deployment.
* @param opts.hre HardhatRuntimeEnvironment.
* @param opts.contract Name of the contract to deploy.
* @param opts.name Name to use for the deployment file.
* @param opts.iface Interface to use for the returned contract.
* @param opts.args Arguments to pass to the contract constructor.
* @param opts.postDeployAction Action to perform after the contract is deployed.
* @returns Deployed contract object.
*/
export const deploy = async ({
hre,
name,
iface,
args,
contract,
iface,
postDeployAction,
}: {
hre: HardhatRuntimeEnvironment
......@@ -24,47 +37,47 @@ export const deployAndVerifyAndThen = async ({
iface?: string
postDeployAction?: (contract: Contract) => Promise<void>
}) => {
const { deploy } = hre.deployments
const { deployer } = await hre.getNamedAccounts()
// Hardhat deploy will usually do this check for us, but currently doesn't also consider
// external deployments when doing this check. By doing the check ourselves, we also get to
// consider external deployments. If we already have the deployment, return early.
const existing = await hre.deployments.getOrNull(name)
if (existing) {
console.log(
`skipping ${name} deployment, using existing at ${existing.address}`
)
return
let result: Deployment | DeployResult = await hre.deployments.getOrNull(name)
if (result) {
console.log(`skipping ${name}, using existing at ${result.address}`)
} else {
result = await hre.deployments.deploy(name, {
contract,
from: deployer,
args,
log: true,
waitConfirmations: hre.deployConfig.numDeployConfirmations,
})
}
const result = await deploy(name, {
contract,
from: deployer,
args,
log: true,
waitConfirmations: hre.deployConfig.numDeployConfirmations,
})
// Always wait for the transaction to be mined, just in case.
await hre.ethers.provider.waitForTransaction(result.transactionHash)
if (result.newlyDeployed) {
if (postDeployAction) {
const signer = hre.ethers.provider.getSigner(deployer)
let abi = result.abi
if (iface !== undefined) {
const factory = await hre.ethers.getContractFactory(iface)
abi = factory.interface as any
}
// Create the contract object to return.
const created = getAdvancedContract({
hre,
contract: new Contract(
result.address,
iface !== undefined
? (await hre.ethers.getContractFactory(iface)).interface
: result.abi,
hre.ethers.provider.getSigner(deployer)
),
})
await postDeployAction(
getAdvancedContract({
hre,
contract: new Contract(result.address, abi, signer),
})
)
// Run post-deploy actions if necessary.
if ((result as DeployResult).newlyDeployed) {
if (postDeployAction) {
await postDeployAction(created)
}
}
return created
}
// Returns a version of the contract object which modifies all of the input contract's methods to:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment