Commit d288b2bb authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #4260 from ethereum-optimism/sc/ctb-clean-deploy-fn

maint(ctb): clean up deploy function
parents f2dd7e85 73e9f373
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import { assertContractVariable, deploy } from '../src/deploy-utils'
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts() const { deployer } = await hre.getNamedAccounts()
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'ProxyAdmin', name: 'ProxyAdmin',
args: [deployer], args: [deployer],
......
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import { assertContractVariable, deploy } from '../src/deploy-utils'
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts() const { deployer } = await hre.getNamedAccounts()
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'Lib_AddressManager', name: 'Lib_AddressManager',
contract: 'AddressManager', contract: 'AddressManager',
......
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import { assertContractVariable, deploy } from '../src/deploy-utils'
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts() const { deployer } = await hre.getNamedAccounts()
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'Proxy__OVM_L1StandardBridge', name: 'Proxy__OVM_L1StandardBridge',
contract: 'L1ChugSplashProxy', contract: 'L1ChugSplashProxy',
......
...@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import {
assertContractVariable, assertContractVariable,
deployAndVerifyAndThen, deploy,
getDeploymentAddress, getDeploymentAddress,
} from '../src/deploy-utils' } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin') const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin')
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'L2OutputOracleProxy', name: 'L2OutputOracleProxy',
contract: 'Proxy', contract: 'Proxy',
......
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import { deploy, getDeploymentAddress } from '../src/deploy-utils'
deployAndVerifyAndThen,
getDeploymentAddress,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const addressManager = await getDeploymentAddress(hre, 'Lib_AddressManager') const addressManager = await getDeploymentAddress(hre, 'Lib_AddressManager')
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'Proxy__OVM_L1CrossDomainMessenger', name: 'Proxy__OVM_L1CrossDomainMessenger',
contract: 'ResolvedDelegateProxy', contract: 'ResolvedDelegateProxy',
......
...@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import {
assertContractVariable, assertContractVariable,
deployAndVerifyAndThen, deploy,
getDeploymentAddress, getDeploymentAddress,
} from '../src/deploy-utils' } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin') const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin')
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'OptimismPortalProxy', name: 'OptimismPortalProxy',
contract: 'Proxy', contract: 'Proxy',
......
...@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import {
assertContractVariable, assertContractVariable,
deployAndVerifyAndThen, deploy,
getDeploymentAddress, getDeploymentAddress,
} from '../src/deploy-utils' } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin') const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin')
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'OptimismMintableERC20FactoryProxy', name: 'OptimismMintableERC20FactoryProxy',
contract: 'Proxy', contract: 'Proxy',
......
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import { assertContractVariable, deploy } from '../src/deploy-utils'
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts() const { deployer } = await hre.getNamedAccounts()
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'L1ERC721BridgeProxy', name: 'L1ERC721BridgeProxy',
contract: 'Proxy', contract: 'Proxy',
......
...@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -2,13 +2,13 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import {
assertContractVariable, assertContractVariable,
deployAndVerifyAndThen, deploy,
getDeploymentAddress, getDeploymentAddress,
} from '../src/deploy-utils' } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin') const proxyAdmin = await getDeploymentAddress(hre, 'ProxyAdmin')
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'SystemConfigProxy', name: 'SystemConfigProxy',
contract: 'Proxy', contract: 'Proxy',
......
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import { assertContractVariable, deploy } from '../src/deploy-utils'
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts() const { deployer } = await hre.getNamedAccounts()
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'SystemDictatorProxy', name: 'SystemDictatorProxy',
contract: 'Proxy', contract: 'Proxy',
......
...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import {
assertContractVariable, assertContractVariable,
deployAndVerifyAndThen, deploy,
getContractFromArtifact, getContractFromArtifact,
} from '../src/deploy-utils' } from '../src/deploy-utils'
...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'OptimismPortalProxy' 'OptimismPortalProxy'
) )
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'L1CrossDomainMessenger', name: 'L1CrossDomainMessenger',
args: [OptimismPortalProxy.address], args: [OptimismPortalProxy.address],
......
...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { predeploys } from '../src' import { predeploys } from '../src'
import { import {
assertContractVariable, assertContractVariable,
deployAndVerifyAndThen, deploy,
getContractFromArtifact, getContractFromArtifact,
} from '../src/deploy-utils' } from '../src/deploy-utils'
...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Proxy__OVM_L1CrossDomainMessenger' 'Proxy__OVM_L1CrossDomainMessenger'
) )
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'L1StandardBridge', name: 'L1StandardBridge',
args: [L1CrossDomainMessengerProxy.address], args: [L1CrossDomainMessengerProxy.address],
......
...@@ -2,13 +2,10 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -2,13 +2,10 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import '@eth-optimism/hardhat-deploy-config' import '@eth-optimism/hardhat-deploy-config'
import '@nomiclabs/hardhat-ethers' import '@nomiclabs/hardhat-ethers'
import { import { assertContractVariable, deploy } from '../src/deploy-utils'
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'L2OutputOracle', name: 'L2OutputOracle',
args: [ args: [
......
...@@ -3,7 +3,7 @@ import '@eth-optimism/hardhat-deploy-config' ...@@ -3,7 +3,7 @@ import '@eth-optimism/hardhat-deploy-config'
import { import {
assertContractVariable, assertContractVariable,
deployAndVerifyAndThen, deploy,
getContractFromArtifact, getContractFromArtifact,
} from '../src/deploy-utils' } from '../src/deploy-utils'
...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'L2OutputOracleProxy' 'L2OutputOracleProxy'
) )
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'OptimismPortal', name: 'OptimismPortal',
args: [ args: [
......
...@@ -2,7 +2,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -2,7 +2,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import {
assertContractVariable, assertContractVariable,
deployAndVerifyAndThen, deploy,
getContractFromArtifact, getContractFromArtifact,
} from '../src/deploy-utils' } from '../src/deploy-utils'
...@@ -12,7 +12,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -12,7 +12,7 @@ const deployFn: DeployFunction = async (hre) => {
'Proxy__OVM_L1StandardBridge' 'Proxy__OVM_L1StandardBridge'
) )
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'OptimismMintableERC20Factory', name: 'OptimismMintableERC20Factory',
args: [L1StandardBridgeProxy.address], args: [L1StandardBridgeProxy.address],
......
...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { predeploys } from '../src' import { predeploys } from '../src'
import { import {
assertContractVariable, assertContractVariable,
deployAndVerifyAndThen, deploy,
getContractFromArtifact, getContractFromArtifact,
} from '../src/deploy-utils' } from '../src/deploy-utils'
...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Proxy__OVM_L1CrossDomainMessenger' 'Proxy__OVM_L1CrossDomainMessenger'
) )
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'L1ERC721Bridge', name: 'L1ERC721Bridge',
args: [L1CrossDomainMessengerProxy.address, predeploys.L2ERC721Bridge], args: [L1CrossDomainMessengerProxy.address, predeploys.L2ERC721Bridge],
......
...@@ -2,7 +2,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -2,7 +2,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import {
assertContractVariable, assertContractVariable,
deployAndVerifyAndThen, deploy,
getContractFromArtifact, getContractFromArtifact,
} from '../src/deploy-utils' } from '../src/deploy-utils'
...@@ -12,7 +12,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -12,7 +12,7 @@ const deployFn: DeployFunction = async (hre) => {
'OptimismPortalProxy' 'OptimismPortalProxy'
) )
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'PortalSender', name: 'PortalSender',
args: [OptimismPortalProxy.address], args: [OptimismPortalProxy.address],
......
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
import '@eth-optimism/hardhat-deploy-config' import '@eth-optimism/hardhat-deploy-config'
import { import { assertContractVariable, deploy } from '../src/deploy-utils'
assertContractVariable,
deployAndVerifyAndThen,
} from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const batcherHash = hre.ethers.utils.hexZeroPad( const batcherHash = hre.ethers.utils.hexZeroPad(
...@@ -12,7 +9,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -12,7 +9,7 @@ const deployFn: DeployFunction = async (hre) => {
32 32
) )
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'SystemConfig', name: 'SystemConfig',
args: [ args: [
......
...@@ -2,10 +2,10 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -2,10 +2,10 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
import '@eth-optimism/hardhat-deploy-config' import '@eth-optimism/hardhat-deploy-config'
import 'hardhat-deploy' import 'hardhat-deploy'
import { deployAndVerifyAndThen } from '../src/deploy-utils' import { deploy } from '../src/deploy-utils'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
await deployAndVerifyAndThen({ await deploy({
hre, hre,
name: 'SystemDictator', name: 'SystemDictator',
args: [], args: [],
......
...@@ -8,13 +8,26 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types' ...@@ -8,13 +8,26 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'
import 'hardhat-deploy' import 'hardhat-deploy'
import '@eth-optimism/hardhat-deploy-config' import '@eth-optimism/hardhat-deploy-config'
import '@nomiclabs/hardhat-ethers' import '@nomiclabs/hardhat-ethers'
import { Deployment, DeployResult } from 'hardhat-deploy/dist/types'
export const deployAndVerifyAndThen = async ({
/**
* 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, hre,
name, name,
iface,
args, args,
contract, contract,
iface,
postDeployAction, postDeployAction,
}: { }: {
hre: HardhatRuntimeEnvironment hre: HardhatRuntimeEnvironment
...@@ -24,47 +37,47 @@ export const deployAndVerifyAndThen = async ({ ...@@ -24,47 +37,47 @@ export const deployAndVerifyAndThen = async ({
iface?: string iface?: string
postDeployAction?: (contract: Contract) => Promise<void> postDeployAction?: (contract: Contract) => Promise<void>
}) => { }) => {
const { deploy } = hre.deployments
const { deployer } = await hre.getNamedAccounts() const { deployer } = await hre.getNamedAccounts()
// Hardhat deploy will usually do this check for us, but currently doesn't also consider // 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 // 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. // consider external deployments. If we already have the deployment, return early.
const existing = await hre.deployments.getOrNull(name) let result: Deployment | DeployResult = await hre.deployments.getOrNull(name)
if (existing) { if (result) {
console.log( console.log(`skipping ${name}, using existing at ${result.address}`)
`skipping ${name} deployment, using existing at ${existing.address}` } else {
) result = await hre.deployments.deploy(name, {
return
}
const result = await deploy(name, {
contract, contract,
from: deployer, from: deployer,
args, args,
log: true, log: true,
waitConfirmations: hre.deployConfig.numDeployConfirmations, waitConfirmations: hre.deployConfig.numDeployConfirmations,
}) })
}
// Always wait for the transaction to be mined, just in case.
await hre.ethers.provider.waitForTransaction(result.transactionHash) await hre.ethers.provider.waitForTransaction(result.transactionHash)
if (result.newlyDeployed) { // Create the contract object to return.
if (postDeployAction) { const created = getAdvancedContract({
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
}
await postDeployAction(
getAdvancedContract({
hre, hre,
contract: new Contract(result.address, abi, signer), contract: new Contract(
result.address,
iface !== undefined
? (await hre.ethers.getContractFactory(iface)).interface
: result.abi,
hre.ethers.provider.getSigner(deployer)
),
}) })
)
// 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: // 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