From 531363585b2d4467cf89b7b86fa24c325c933a3b Mon Sep 17 00:00:00 2001 From: "passabilities.eth" Date: Thu, 12 Oct 2023 14:10:52 -0600 Subject: [PATCH 1/7] verify implementation contract after deployment --- packages/plugin-hardhat/src/utils/deploy-impl.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/plugin-hardhat/src/utils/deploy-impl.ts b/packages/plugin-hardhat/src/utils/deploy-impl.ts index 94e9d971b..edf09fafb 100644 --- a/packages/plugin-hardhat/src/utils/deploy-impl.ts +++ b/packages/plugin-hardhat/src/utils/deploy-impl.ts @@ -141,5 +141,10 @@ async function deployImpl( } } + await hre.run("verify:verify", { + address: deployment.address, + constructorArguments: opts.constructorArgs ?? [] + }); + return { impl: deployment.address, txResponse }; } From aaff44886c15dede880e6eeba4876604c7e43587 Mon Sep 17 00:00:00 2001 From: "passabilities.eth" Date: Thu, 12 Oct 2023 14:14:42 -0600 Subject: [PATCH 2/7] verify contract after deployment --- packages/plugin-hardhat/src/utils/deploy.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/plugin-hardhat/src/utils/deploy.ts b/packages/plugin-hardhat/src/utils/deploy.ts index fab957310..9a4cc82d4 100644 --- a/packages/plugin-hardhat/src/utils/deploy.ts +++ b/packages/plugin-hardhat/src/utils/deploy.ts @@ -8,21 +8,31 @@ export interface DeployTransaction { deployTransaction?: ethers.TransactionResponse; } +export type DeployResponse = Required & DeployTransaction & RemoteDeploymentId; + export async function deploy( hre: HardhatRuntimeEnvironment, opts: UpgradeOptions & EthersDeployOptions & DefenderDeployOptions, factory: ContractFactory, ...args: unknown[] -): Promise & DeployTransaction & RemoteDeploymentId> { +): Promise { // defender always includes RemoteDeploymentId, while ethers always includes DeployTransaction + let response: DeployResponse; if (opts?.useDefenderDeploy) { - return await defenderDeploy(hre, factory, opts, ...args); + response = await defenderDeploy(hre, factory, opts, ...args); } else { if (opts.txOverrides !== undefined) { args.push(opts.txOverrides); } - return await ethersDeploy(factory, ...args); + response = await ethersDeploy(factory, ...args); } + + await hre.run("verify:verify", { + address: response.address, + constructorArguments: opts.constructorArgs ?? [] + }); + + return response; } async function ethersDeploy( From 50bee37dc6d8d49a9edebadcae905d67886045ba Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Fri, 13 Oct 2023 09:15:26 -0600 Subject: [PATCH 3/7] format --- packages/plugin-hardhat/src/utils/deploy-impl.ts | 4 ++-- packages/plugin-hardhat/src/utils/deploy.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/plugin-hardhat/src/utils/deploy-impl.ts b/packages/plugin-hardhat/src/utils/deploy-impl.ts index edf09fafb..7f8ff0965 100644 --- a/packages/plugin-hardhat/src/utils/deploy-impl.ts +++ b/packages/plugin-hardhat/src/utils/deploy-impl.ts @@ -141,9 +141,9 @@ async function deployImpl( } } - await hre.run("verify:verify", { + await hre.run('verify:verify', { address: deployment.address, - constructorArguments: opts.constructorArgs ?? [] + constructorArguments: opts.constructorArgs ?? [], }); return { impl: deployment.address, txResponse }; diff --git a/packages/plugin-hardhat/src/utils/deploy.ts b/packages/plugin-hardhat/src/utils/deploy.ts index 9a4cc82d4..1e794497b 100644 --- a/packages/plugin-hardhat/src/utils/deploy.ts +++ b/packages/plugin-hardhat/src/utils/deploy.ts @@ -27,9 +27,9 @@ export async function deploy( response = await ethersDeploy(factory, ...args); } - await hre.run("verify:verify", { + await hre.run('verify:verify', { address: response.address, - constructorArguments: opts.constructorArgs ?? [] + constructorArguments: opts.constructorArgs ?? [], }); return response; From 9607408b482092e12c0661c2b8d79b5dcc29d798 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Fri, 13 Oct 2023 09:48:49 -0600 Subject: [PATCH 4/7] catch verification error --- packages/plugin-hardhat/src/utils/deploy-impl.ts | 6 ++---- packages/plugin-hardhat/src/utils/deploy.ts | 6 ++---- packages/plugin-hardhat/src/verify-proxy.ts | 13 +++++++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/plugin-hardhat/src/utils/deploy-impl.ts b/packages/plugin-hardhat/src/utils/deploy-impl.ts index 7f8ff0965..b361dfc18 100644 --- a/packages/plugin-hardhat/src/utils/deploy-impl.ts +++ b/packages/plugin-hardhat/src/utils/deploy-impl.ts @@ -11,6 +11,7 @@ import { } from '@openzeppelin/upgrades-core'; import type { ContractFactory, ethers } from 'ethers'; import type { EthereumProvider, HardhatRuntimeEnvironment } from 'hardhat/types'; +import { runVerify } from '../verify-proxy'; import { deploy } from './deploy'; import { GetTxResponse, DefenderDeployOptions, StandaloneOptions, UpgradeOptions, withDefaults } from './options'; import { getRemoteDeployment } from '../defender/utils'; @@ -141,10 +142,7 @@ async function deployImpl( } } - await hre.run('verify:verify', { - address: deployment.address, - constructorArguments: opts.constructorArgs ?? [], - }); + await runVerify(hre, deployment.address, opts.constructorArgs); return { impl: deployment.address, txResponse }; } diff --git a/packages/plugin-hardhat/src/utils/deploy.ts b/packages/plugin-hardhat/src/utils/deploy.ts index 1e794497b..342517b5e 100644 --- a/packages/plugin-hardhat/src/utils/deploy.ts +++ b/packages/plugin-hardhat/src/utils/deploy.ts @@ -2,6 +2,7 @@ import type { Deployment, RemoteDeploymentId } from '@openzeppelin/upgrades-core import type { ethers, ContractFactory, ContractMethodArgs } from 'ethers'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { defenderDeploy } from '../defender/deploy'; +import { runVerify } from '../verify-proxy'; import { EthersDeployOptions, DefenderDeployOptions, UpgradeOptions } from './options'; export interface DeployTransaction { @@ -27,10 +28,7 @@ export async function deploy( response = await ethersDeploy(factory, ...args); } - await hre.run('verify:verify', { - address: response.address, - constructorArguments: opts.constructorArgs ?? [], - }); + await runVerify(hre, response.address, opts.constructorArgs); return response; } diff --git a/packages/plugin-hardhat/src/verify-proxy.ts b/packages/plugin-hardhat/src/verify-proxy.ts index 173126208..d159dd643 100644 --- a/packages/plugin-hardhat/src/verify-proxy.ts +++ b/packages/plugin-hardhat/src/verify-proxy.ts @@ -1,3 +1,4 @@ +import { TASK_VERIFY_VERIFY } from '@nomicfoundation/hardhat-verify/internal/task-names'; import { getTransactionByHash, getImplementationAddress, @@ -11,6 +12,7 @@ import { isEmptySlot, } from '@openzeppelin/upgrades-core'; import artifactsBuildInfo from '@openzeppelin/upgrades-core/artifacts/build-info.json'; +import { HARDHAT_NETWORK_NAME } from 'hardhat/plugins'; import { HardhatRuntimeEnvironment, RunSuperFunction } from 'hardhat/types'; @@ -61,6 +63,17 @@ const verifiableContracts = { proxyAdmin: { artifact: ProxyAdmin, event: 'OwnershipTransferred(address,address)' }, }; +export async function runVerify(hre: HardhatRuntimeEnvironment, address: string, constructorArguments: unknown[] = []) { + try { + await hre.run(TASK_VERIFY_VERIFY, { + address, + constructorArguments, + }); + } catch (e) { + // fail silently + } +} + /** * Overrides hardhat-verify's verify:etherscan subtask to fully verify a proxy or beacon. * From ec56e5cfb9dd0b640f8aca1fb0f18c8cd062bde4 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Fri, 13 Oct 2023 09:49:48 -0600 Subject: [PATCH 5/7] skip automatic verification on hardhat network --- packages/plugin-hardhat/src/verify-proxy.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/plugin-hardhat/src/verify-proxy.ts b/packages/plugin-hardhat/src/verify-proxy.ts index d159dd643..b0e443e3f 100644 --- a/packages/plugin-hardhat/src/verify-proxy.ts +++ b/packages/plugin-hardhat/src/verify-proxy.ts @@ -64,6 +64,10 @@ const verifiableContracts = { }; export async function runVerify(hre: HardhatRuntimeEnvironment, address: string, constructorArguments: unknown[] = []) { + if (hre.network.name === HARDHAT_NETWORK_NAME) { + // Don't verify on hardhat network + return; + } try { await hre.run(TASK_VERIFY_VERIFY, { address, From 8a32e8a4a72631e16e11525b8111d57fe2e329a5 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Fri, 13 Oct 2023 09:50:10 -0600 Subject: [PATCH 6/7] import verify etherscan task name --- packages/plugin-hardhat/src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/plugin-hardhat/src/index.ts b/packages/plugin-hardhat/src/index.ts index 836593dcb..6f170b6df 100644 --- a/packages/plugin-hardhat/src/index.ts +++ b/packages/plugin-hardhat/src/index.ts @@ -2,6 +2,7 @@ import '@nomicfoundation/hardhat-ethers'; import './type-extensions'; +import { TASK_VERIFY_ETHERSCAN } from '@nomicfoundation/hardhat-verify/internal/task-names'; import { subtask, extendEnvironment, extendConfig } from 'hardhat/config'; import { TASK_COMPILE_SOLIDITY, TASK_COMPILE_SOLIDITY_COMPILE } from 'hardhat/builtin-tasks/task-names'; import { lazyObject } from 'hardhat/plugins'; @@ -193,7 +194,7 @@ extendConfig((config: HardhatConfig) => { }); if (tryRequire('@nomicfoundation/hardhat-verify')) { - subtask('verify:etherscan').setAction(async (args, hre, runSuper) => { + subtask(TASK_VERIFY_ETHERSCAN).setAction(async (args, hre, runSuper) => { const { verify } = await import('./verify-proxy'); return await verify(args, hre, runSuper); }); From e6b5c93217a4def6bd40cdf836b4e85b644b1813 Mon Sep 17 00:00:00 2001 From: Noah Passalacqua Date: Fri, 13 Oct 2023 10:25:52 -0600 Subject: [PATCH 7/7] wait for tx response --- packages/plugin-hardhat/src/utils/deploy-impl.ts | 7 +++++-- packages/plugin-hardhat/src/utils/deploy.ts | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/plugin-hardhat/src/utils/deploy-impl.ts b/packages/plugin-hardhat/src/utils/deploy-impl.ts index b361dfc18..4c6005e5d 100644 --- a/packages/plugin-hardhat/src/utils/deploy-impl.ts +++ b/packages/plugin-hardhat/src/utils/deploy-impl.ts @@ -133,7 +133,7 @@ async function deployImpl( remoteDeploymentId => getRemoteDeployment(hre, remoteDeploymentId), ); - let txResponse; + let txResponse: ethers.TransactionResponse | undefined; if (opts.getTxResponse) { if ('deployTransaction' in deployment) { txResponse = deployment.deployTransaction ?? undefined; @@ -142,7 +142,10 @@ async function deployImpl( } } - await runVerify(hre, deployment.address, opts.constructorArgs); + if (txResponse) { + await txResponse.wait(1); + await runVerify(hre, deployment.address, opts.constructorArgs); + } return { impl: deployment.address, txResponse }; } diff --git a/packages/plugin-hardhat/src/utils/deploy.ts b/packages/plugin-hardhat/src/utils/deploy.ts index 342517b5e..985a112e7 100644 --- a/packages/plugin-hardhat/src/utils/deploy.ts +++ b/packages/plugin-hardhat/src/utils/deploy.ts @@ -28,7 +28,10 @@ export async function deploy( response = await ethersDeploy(factory, ...args); } - await runVerify(hre, response.address, opts.constructorArgs); + if (response.deployTransaction) { + await response.deployTransaction.wait(1); + await runVerify(hre, response.address, opts.constructorArgs); + } return response; }