Commit 64d5712c authored by Maurelian's avatar Maurelian Committed by Kelvin Fichter

feat(contracts): Run etherscan verification after deployment

refactor(contracts): Rename deployAndPostDeploy to deployAndVerifyAndThen
parent 549a8566
...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndVerifyAndThen,
getContractFromArtifact, getContractFromArtifact,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager' 'Lib_AddressManager'
) )
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'ChainStorageContainer-CTC-batches', name: 'ChainStorageContainer-CTC-batches',
contract: 'ChainStorageContainer', contract: 'ChainStorageContainer',
......
...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndVerifyAndThen,
getContractFromArtifact, getContractFromArtifact,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager' 'Lib_AddressManager'
) )
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'ChainStorageContainer-SCC-batches', name: 'ChainStorageContainer-SCC-batches',
contract: 'ChainStorageContainer', contract: 'ChainStorageContainer',
......
...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndVerifyAndThen,
getContractFromArtifact, getContractFromArtifact,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager' 'Lib_AddressManager'
) )
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'CanonicalTransactionChain', name: 'CanonicalTransactionChain',
args: [ args: [
......
...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndVerifyAndThen,
getContractFromArtifact, getContractFromArtifact,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager' 'Lib_AddressManager'
) )
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'StateCommitmentChain', name: 'StateCommitmentChain',
args: [ args: [
......
...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndVerifyAndThen,
getContractFromArtifact, getContractFromArtifact,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager' 'Lib_AddressManager'
) )
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'BondManager', name: 'BondManager',
args: [Lib_AddressManager.address], args: [Lib_AddressManager.address],
......
...@@ -4,7 +4,7 @@ import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils' ...@@ -4,7 +4,7 @@ import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndVerifyAndThen,
getContractFromArtifact, getContractFromArtifact,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
...@@ -14,7 +14,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -14,7 +14,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager' 'Lib_AddressManager'
) )
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'OVM_L1CrossDomainMessenger', name: 'OVM_L1CrossDomainMessenger',
contract: 'L1CrossDomainMessenger', contract: 'L1CrossDomainMessenger',
......
...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' ...@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndVerifyAndThen,
getContractFromArtifact, getContractFromArtifact,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager' 'Lib_AddressManager'
) )
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'Proxy__OVM_L1CrossDomainMessenger', name: 'Proxy__OVM_L1CrossDomainMessenger',
contract: 'Lib_ResolvedDelegateProxy', contract: 'Lib_ResolvedDelegateProxy',
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */ /* Imports: Internal */
import { deployAndPostDeploy } from '../src/hardhat-deploy-ethers' import { deployAndVerifyAndThen } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts() const { deployer } = await hre.getNamedAccounts()
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'Proxy__OVM_L1StandardBridge', name: 'Proxy__OVM_L1StandardBridge',
contract: 'L1ChugSplashProxy', contract: 'L1ChugSplashProxy',
......
...@@ -4,7 +4,7 @@ import { hexStringEquals } from '@eth-optimism/core-utils' ...@@ -4,7 +4,7 @@ import { hexStringEquals } from '@eth-optimism/core-utils'
/* Imports: Internal */ /* Imports: Internal */
import { import {
deployAndPostDeploy, deployAndVerifyAndThen,
getContractFromArtifact, getContractFromArtifact,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
import { predeploys } from '../src/predeploys' import { predeploys } from '../src/predeploys'
...@@ -74,7 +74,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -74,7 +74,7 @@ const deployFn: DeployFunction = async (hre) => {
return !hexStringEquals(existingAddresses[name], address) return !hexStringEquals(existingAddresses[name], address)
}) })
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'AddressDictator', name: 'AddressDictator',
contract: 'AddressDictator', contract: 'AddressDictator',
......
/* Imports: External */ /* Imports: External */
import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils' import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils'
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
import { defaultHardhatNetworkParams } from 'hardhat/internal/core/config/default-config'
/* Imports: Internal */ /* Imports: Internal */
import { getContractFromArtifact } from '../src/hardhat-deploy-ethers' import {
getContractFromArtifact,
isHardhatNode,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts() const { deployer } = await hre.getNamedAccounts()
...@@ -72,11 +74,9 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -72,11 +74,9 @@ const deployFn: DeployFunction = async (hre) => {
(4) Wait for the deploy process to continue. (4) Wait for the deploy process to continue.
`) `)
// Only execute this step if we're on the hardhat chain ID. This will only happen in CI. If this // Check if if we're on the hardhat chain ID. This will only happen in CI. If this is the case, we
// is the case, we can skip directly to transferring ownership over to the AddressDictator // can skip directly to transferring ownership over to the ChugSplashDictator contract.
// contract. if (isHardhatNode(hre)) {
const { chainId } = await hre.ethers.provider.getNetwork()
if (chainId === defaultHardhatNetworkParams.chainId) {
const owner = await hre.ethers.getSigner(currentOwner) const owner = await hre.ethers.getSigner(currentOwner)
await Lib_AddressManager.connect(owner).transferOwnership( await Lib_AddressManager.connect(owner).transferOwnership(
AddressDictator.address AddressDictator.address
......
...@@ -7,7 +7,7 @@ import { predeploys } from '../src/predeploys' ...@@ -7,7 +7,7 @@ import { predeploys } from '../src/predeploys'
import { getContractDefinition } from '../src/contract-defs' import { getContractDefinition } from '../src/contract-defs'
import { import {
getContractFromArtifact, getContractFromArtifact,
deployAndPostDeploy, deployAndVerifyAndThen,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
...@@ -25,7 +25,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -25,7 +25,7 @@ const deployFn: DeployFunction = async (hre) => {
'Proxy__OVM_L1CrossDomainMessenger' 'Proxy__OVM_L1CrossDomainMessenger'
) )
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'ChugSplashDictator', name: 'ChugSplashDictator',
contract: 'ChugSplashDictator', contract: 'ChugSplashDictator',
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
import { ethers } from 'ethers' import { ethers } from 'ethers'
import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils' import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils'
import { defaultHardhatNetworkParams } from 'hardhat/internal/core/config/default-config'
/* Imports: Internal */ /* Imports: Internal */
import { getContractDefinition } from '../src/contract-defs' import { getContractDefinition } from '../src/contract-defs'
import { import {
getContractFromArtifact, getContractFromArtifact,
deployAndPostDeploy, deployAndVerifyAndThen,
isHardhatNode,
} from '../src/hardhat-deploy-ethers' } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
...@@ -85,8 +85,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -85,8 +85,7 @@ const deployFn: DeployFunction = async (hre) => {
// Check if if we're on the hardhat chain ID. This will only happen in CI. If this is the case, we // Check if if we're on the hardhat chain ID. This will only happen in CI. If this is the case, we
// can skip directly to transferring ownership over to the ChugSplashDictator contract. // can skip directly to transferring ownership over to the ChugSplashDictator contract.
const { chainId } = await hre.ethers.provider.getNetwork() if (isHardhatNode(hre)) {
if (chainId === defaultHardhatNetworkParams.chainId) {
const owner = await hre.ethers.getSigner(currentOwner) const owner = await hre.ethers.getSigner(currentOwner)
await Proxy__OVM_L1StandardBridge.connect(owner).setOwner( await Proxy__OVM_L1StandardBridge.connect(owner).setOwner(
ChugSplashDictator.address ChugSplashDictator.address
...@@ -131,7 +130,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -131,7 +130,7 @@ const deployFn: DeployFunction = async (hre) => {
// Deploy a copy of the implementation so it can be successfully verified on Etherscan. // Deploy a copy of the implementation so it can be successfully verified on Etherscan.
console.log(`Deploying a copy of the bridge for Etherscan verification...`) console.log(`Deploying a copy of the bridge for Etherscan verification...`)
await deployAndPostDeploy({ await deployAndVerifyAndThen({
hre, hre,
name: 'L1StandardBridge_for_verification_only', name: 'L1StandardBridge_for_verification_only',
contract: 'L1StandardBridge', contract: 'L1StandardBridge',
......
/* Imports: External */ /* Imports: External */
import { sleep } from '@eth-optimism/core-utils' import { sleep } from '@eth-optimism/core-utils'
import { DeployFunction } from 'hardhat-deploy/dist/types' import { DeployFunction } from 'hardhat-deploy/dist/types'
import { import { defaultHardhatNetworkHdAccountsConfigParams } from 'hardhat/internal/core/config/default-config'
defaultHardhatNetworkHdAccountsConfigParams,
defaultHardhatNetworkParams,
} from 'hardhat/internal/core/config/default-config'
import { normalizeHardhatNetworkAccountsConfig } from 'hardhat/internal/core/providers/util' import { normalizeHardhatNetworkAccountsConfig } from 'hardhat/internal/core/providers/util'
/* Imports: Internal */ /* Imports: Internal */
import { getContractFromArtifact } from '../src/hardhat-deploy-ethers' import {
getContractFromArtifact,
isHardhatNode,
} from '../src/hardhat-deploy-ethers'
// This is a TEMPORARY way to fund the default hardhat accounts on L2. The better way to do this is // This is a TEMPORARY way to fund the default hardhat accounts on L2. The better way to do this is
// to make a modification to hardhat-ovm. However, I don't have the time right now to figure the // to make a modification to hardhat-ovm. However, I don't have the time right now to figure the
// details of how to make that work cleanly. This is fine in the meantime. // details of how to make that work cleanly. This is fine in the meantime.
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
// Only execute this step if we're on the hardhat chain ID. // Only execute this step if we're on the hardhat chain ID.
const { chainId } = await hre.ethers.provider.getNetwork() if (isHardhatNode(hre)) {
if (chainId === defaultHardhatNetworkParams.chainId) {
const L1StandardBridge = await getContractFromArtifact( const L1StandardBridge = await getContractFromArtifact(
hre, hre,
'Proxy__OVM_L1StandardBridge', 'Proxy__OVM_L1StandardBridge',
......
...@@ -5,7 +5,7 @@ import { Signer } from '@ethersproject/abstract-signer' ...@@ -5,7 +5,7 @@ import { Signer } from '@ethersproject/abstract-signer'
import { sleep, awaitCondition } from '@eth-optimism/core-utils' import { sleep, awaitCondition } from '@eth-optimism/core-utils'
import { HttpNetworkConfig } from 'hardhat/types' import { HttpNetworkConfig } from 'hardhat/types'
export const deployAndPostDeploy = async ({ export const deployAndVerifyAndThen = async ({
hre, hre,
name, name,
args, args,
...@@ -34,6 +34,22 @@ export const deployAndPostDeploy = async ({ ...@@ -34,6 +34,22 @@ export const deployAndPostDeploy = async ({
await hre.ethers.provider.waitForTransaction(result.transactionHash) await hre.ethers.provider.waitForTransaction(result.transactionHash)
if (result.newlyDeployed) { if (result.newlyDeployed) {
if (!isHardhatNode(hre)) {
// Verification sometimes fails, even when the contract is correctly deployed and eventually
// verified. Possibly due to a race condition. We don't want to halt the whole deployment
// process just because that happens.
try {
console.log('Verifying on Etherscan...')
await hre.run('verify:verify', {
address: result.address,
constructorArguments: args,
})
console.log('Successfully verified')
} catch (error) {
console.log('Error when verifying bytecode on etherscan:')
console.log(error)
}
}
if (postDeployAction) { if (postDeployAction) {
const signer = hre.ethers.provider.getSigner(deployer) const signer = hre.ethers.provider.getSigner(deployer)
let abi = result.abi let abi = result.abi
...@@ -219,5 +235,10 @@ export const getContractFromArtifact = async ( ...@@ -219,5 +235,10 @@ export const getContractFromArtifact = async (
}) })
} }
export const isHardhatNode = async (hre) => {
const { chainId } = await hre.ethers.provider.getNetwork()
return chainId === 31337
}
// Large balance to fund accounts with. // Large balance to fund accounts with.
export const BIG_BALANCE = ethers.BigNumber.from(`0xFFFFFFFFFFFFFFFFFFFF`) export const BIG_BALANCE = ethers.BigNumber.from(`0xFFFFFFFFFFFFFFFFFFFF`)
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