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'
/* Imports: Internal */
import {
deployAndPostDeploy,
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/hardhat-deploy-ethers'
......@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager'
)
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'ChainStorageContainer-CTC-batches',
contract: 'ChainStorageContainer',
......
......@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/hardhat-deploy-ethers'
......@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager'
)
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'ChainStorageContainer-SCC-batches',
contract: 'ChainStorageContainer',
......
......@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/hardhat-deploy-ethers'
......@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager'
)
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'CanonicalTransactionChain',
args: [
......
......@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/hardhat-deploy-ethers'
......@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager'
)
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'StateCommitmentChain',
args: [
......
......@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/hardhat-deploy-ethers'
......@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager'
)
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'BondManager',
args: [Lib_AddressManager.address],
......
......@@ -4,7 +4,7 @@ import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils'
/* Imports: Internal */
import {
deployAndPostDeploy,
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/hardhat-deploy-ethers'
......@@ -14,7 +14,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager'
)
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'OVM_L1CrossDomainMessenger',
contract: 'L1CrossDomainMessenger',
......
......@@ -3,7 +3,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import {
deployAndPostDeploy,
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/hardhat-deploy-ethers'
......@@ -13,7 +13,7 @@ const deployFn: DeployFunction = async (hre) => {
'Lib_AddressManager'
)
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'Proxy__OVM_L1CrossDomainMessenger',
contract: 'Lib_ResolvedDelegateProxy',
......
......@@ -2,12 +2,12 @@
import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import { deployAndPostDeploy } from '../src/hardhat-deploy-ethers'
import { deployAndVerifyAndThen } from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'Proxy__OVM_L1StandardBridge',
contract: 'L1ChugSplashProxy',
......
......@@ -4,7 +4,7 @@ import { hexStringEquals } from '@eth-optimism/core-utils'
/* Imports: Internal */
import {
deployAndPostDeploy,
deployAndVerifyAndThen,
getContractFromArtifact,
} from '../src/hardhat-deploy-ethers'
import { predeploys } from '../src/predeploys'
......@@ -74,7 +74,7 @@ const deployFn: DeployFunction = async (hre) => {
return !hexStringEquals(existingAddresses[name], address)
})
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'AddressDictator',
contract: 'AddressDictator',
......
/* Imports: External */
import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils'
import { DeployFunction } from 'hardhat-deploy/dist/types'
import { defaultHardhatNetworkParams } from 'hardhat/internal/core/config/default-config'
/* Imports: Internal */
import { getContractFromArtifact } from '../src/hardhat-deploy-ethers'
import {
getContractFromArtifact,
isHardhatNode,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
const { deployer } = await hre.getNamedAccounts()
......@@ -72,11 +74,9 @@ const deployFn: DeployFunction = async (hre) => {
(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
// is the case, we can skip directly to transferring ownership over to the AddressDictator
// contract.
const { chainId } = await hre.ethers.provider.getNetwork()
if (chainId === defaultHardhatNetworkParams.chainId) {
// 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.
if (isHardhatNode(hre)) {
const owner = await hre.ethers.getSigner(currentOwner)
await Lib_AddressManager.connect(owner).transferOwnership(
AddressDictator.address
......
......@@ -7,7 +7,7 @@ import { predeploys } from '../src/predeploys'
import { getContractDefinition } from '../src/contract-defs'
import {
getContractFromArtifact,
deployAndPostDeploy,
deployAndVerifyAndThen,
} from '../src/hardhat-deploy-ethers'
const deployFn: DeployFunction = async (hre) => {
......@@ -25,7 +25,7 @@ const deployFn: DeployFunction = async (hre) => {
'Proxy__OVM_L1CrossDomainMessenger'
)
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'ChugSplashDictator',
contract: 'ChugSplashDictator',
......
......@@ -2,13 +2,13 @@
import { DeployFunction } from 'hardhat-deploy/dist/types'
import { ethers } from 'ethers'
import { hexStringEquals, awaitCondition } from '@eth-optimism/core-utils'
import { defaultHardhatNetworkParams } from 'hardhat/internal/core/config/default-config'
/* Imports: Internal */
import { getContractDefinition } from '../src/contract-defs'
import {
getContractFromArtifact,
deployAndPostDeploy,
deployAndVerifyAndThen,
isHardhatNode,
} from '../src/hardhat-deploy-ethers'
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
// can skip directly to transferring ownership over to the ChugSplashDictator contract.
const { chainId } = await hre.ethers.provider.getNetwork()
if (chainId === defaultHardhatNetworkParams.chainId) {
if (isHardhatNode(hre)) {
const owner = await hre.ethers.getSigner(currentOwner)
await Proxy__OVM_L1StandardBridge.connect(owner).setOwner(
ChugSplashDictator.address
......@@ -131,7 +130,7 @@ const deployFn: DeployFunction = async (hre) => {
// 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...`)
await deployAndPostDeploy({
await deployAndVerifyAndThen({
hre,
name: 'L1StandardBridge_for_verification_only',
contract: 'L1StandardBridge',
......
/* Imports: External */
import { sleep } from '@eth-optimism/core-utils'
import { DeployFunction } from 'hardhat-deploy/dist/types'
import {
defaultHardhatNetworkHdAccountsConfigParams,
defaultHardhatNetworkParams,
} from 'hardhat/internal/core/config/default-config'
import { defaultHardhatNetworkHdAccountsConfigParams } from 'hardhat/internal/core/config/default-config'
import { normalizeHardhatNetworkAccountsConfig } from 'hardhat/internal/core/providers/util'
/* 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
// 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.
const deployFn: DeployFunction = async (hre) => {
// Only execute this step if we're on the hardhat chain ID.
const { chainId } = await hre.ethers.provider.getNetwork()
if (chainId === defaultHardhatNetworkParams.chainId) {
if (isHardhatNode(hre)) {
const L1StandardBridge = await getContractFromArtifact(
hre,
'Proxy__OVM_L1StandardBridge',
......
......@@ -5,7 +5,7 @@ import { Signer } from '@ethersproject/abstract-signer'
import { sleep, awaitCondition } from '@eth-optimism/core-utils'
import { HttpNetworkConfig } from 'hardhat/types'
export const deployAndPostDeploy = async ({
export const deployAndVerifyAndThen = async ({
hre,
name,
args,
......@@ -34,6 +34,22 @@ export const deployAndPostDeploy = async ({
await hre.ethers.provider.waitForTransaction(result.transactionHash)
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) {
const signer = hre.ethers.provider.getSigner(deployer)
let abi = result.abi
......@@ -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.
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