Skip to content

Commit 8bb04bb

Browse files
committed
Adds hardhat-verify to hardhat-deploy scripts
1 parent f9a155d commit 8bb04bb

8 files changed

+184
-40
lines changed

deploy/001_deploy_InverseApi3ReaderProxyV1.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
22

3-
module.exports = async ({ getUnnamedAccounts, deployments, ethers }: HardhatRuntimeEnvironment) => {
3+
const VERIFICATION_BLOCK_CONFIRMATIONS = 5;
4+
5+
module.exports = async (hre: HardhatRuntimeEnvironment) => {
6+
const { getUnnamedAccounts, deployments, ethers, network, run } = hre;
47
const { deploy, log } = deployments;
58

69
const [deployerAddress] = await getUnnamedAccounts();
@@ -18,12 +21,29 @@ module.exports = async ({ getUnnamedAccounts, deployments, ethers }: HardhatRunt
1821
}
1922
log(`Proxy address: ${proxyAddress}`);
2023

21-
await deployments.get('InverseApi3ReaderProxyV1').catch(async () => {
22-
return deploy('InverseApi3ReaderProxyV1', {
23-
from: deployerAddress,
24-
args: [proxyAddress],
25-
log: true,
26-
});
24+
const isLocalNetwork = network.name === 'hardhat' || network.name === 'localhost';
25+
26+
const confirmations = isLocalNetwork ? 1 : VERIFICATION_BLOCK_CONFIRMATIONS;
27+
log(`Deployment confirmations: ${confirmations}`);
28+
29+
const contractName = 'InverseApi3ReaderProxyV1';
30+
31+
const deployment = await deploy(contractName, {
32+
from: deployerAddress,
33+
args: [proxyAddress],
34+
log: true,
35+
waitConfirmations: confirmations,
36+
});
37+
38+
if (isLocalNetwork) {
39+
log('Skipping verification on local network.');
40+
return;
41+
}
42+
43+
log(`Attempting verification of ${contractName} (already waited for confirmations)...`);
44+
await run('verify:verify', {
45+
address: deployment.address,
46+
constructorArguments: deployment.args,
2747
});
2848
};
2949
module.exports.tags = ['InverseApi3ReaderProxyV1'];

deploy/002_deploy_NormalizedApi3ReaderProxyV1.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
22
import type { DeploymentsExtension } from 'hardhat-deploy/types';
33

4+
const VERIFICATION_BLOCK_CONFIRMATIONS = 5;
5+
46
const deployTestFeed = async (deployments: DeploymentsExtension, deployerAddress: string) => {
57
const { address: scaledApi3FeedProxyV1Address } = await deployments.get('ScaledApi3FeedProxyV1').catch(async () => {
68
return deployments.deploy('ScaledApi3FeedProxyV1', {
@@ -12,7 +14,8 @@ const deployTestFeed = async (deployments: DeploymentsExtension, deployerAddress
1214
return scaledApi3FeedProxyV1Address;
1315
};
1416

15-
module.exports = async ({ getUnnamedAccounts, deployments, network, ethers }: HardhatRuntimeEnvironment) => {
17+
module.exports = async (hre: HardhatRuntimeEnvironment) => {
18+
const { getUnnamedAccounts, deployments, network, ethers, run } = hre;
1619
const { deploy, log } = deployments;
1720

1821
const [deployerAddress] = await getUnnamedAccounts();
@@ -33,12 +36,29 @@ module.exports = async ({ getUnnamedAccounts, deployments, network, ethers }: Ha
3336
}
3437
log(`Feed address: ${feedAddress}`);
3538

36-
await deployments.get('NormalizedApi3ReaderProxyV1').catch(async () => {
37-
return deploy('NormalizedApi3ReaderProxyV1', {
38-
from: deployerAddress,
39-
args: [feedAddress],
40-
log: true,
41-
});
39+
const isLocalNetwork = network.name === 'hardhat' || network.name === 'localhost';
40+
41+
const confirmations = isLocalNetwork ? 1 : VERIFICATION_BLOCK_CONFIRMATIONS;
42+
log(`Deployment confirmations: ${confirmations}`);
43+
44+
const contractName = 'NormalizedApi3ReaderProxyV1';
45+
46+
const deployment = await deploy(contractName, {
47+
from: deployerAddress,
48+
args: [feedAddress],
49+
log: true,
50+
waitConfirmations: confirmations,
51+
});
52+
53+
if (isLocalNetwork) {
54+
log('Skipping verification on local network.');
55+
return;
56+
}
57+
58+
log(`Attempting verification of ${contractName} (already waited for confirmations)...`);
59+
await run('verify:verify', {
60+
address: deployment.address,
61+
constructorArguments: deployment.args,
4262
});
4363
};
4464
module.exports.tags = ['NormalizedApi3ReaderProxyV1'];

deploy/003_deploy_ProductApi3ReaderProxyV1.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
22

3-
module.exports = async ({ getUnnamedAccounts, deployments, ethers }: HardhatRuntimeEnvironment) => {
3+
const VERIFICATION_BLOCK_CONFIRMATIONS = 5;
4+
5+
module.exports = async (hre: HardhatRuntimeEnvironment) => {
6+
const { getUnnamedAccounts, deployments, ethers, network, run } = hre;
47
const { deploy, log } = deployments;
58

69
const [deployerAddress] = await getUnnamedAccounts();
@@ -27,12 +30,29 @@ module.exports = async ({ getUnnamedAccounts, deployments, ethers }: HardhatRunt
2730
}
2831
log(`Proxy 2 address: ${proxy2Address}`);
2932

30-
await deployments.get('ProductApi3ReaderProxyV1').catch(async () => {
31-
return deploy('ProductApi3ReaderProxyV1', {
32-
from: deployerAddress,
33-
args: [proxy1Address, proxy2Address],
34-
log: true,
35-
});
33+
const isLocalNetwork = network.name === 'hardhat' || network.name === 'localhost';
34+
35+
const confirmations = isLocalNetwork ? 1 : VERIFICATION_BLOCK_CONFIRMATIONS;
36+
log(`Deployment confirmations: ${confirmations}`);
37+
38+
const contractName = 'ProductApi3ReaderProxyV1';
39+
40+
const deployment = await deploy(contractName, {
41+
from: deployerAddress,
42+
args: [proxy1Address, proxy2Address],
43+
log: true,
44+
waitConfirmations: confirmations,
45+
});
46+
47+
if (isLocalNetwork) {
48+
log('Skipping verification on local network.');
49+
return;
50+
}
51+
52+
log(`Attempting verification of ${contractName} (already waited for confirmations)...`);
53+
await run('verify:verify', {
54+
address: deployment.address,
55+
constructorArguments: deployment.args,
3656
});
3757
};
3858
module.exports.tags = ['ProductApi3ReaderProxyV1'];

deploy/004_deploy_ScaledApi3FeedProxyV1.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
22
import type { DeploymentsExtension } from 'hardhat-deploy/types';
33

4+
const VERIFICATION_BLOCK_CONFIRMATIONS = 5;
5+
46
const deployTestProxy = async (deployments: DeploymentsExtension, deployerAddress: string) => {
57
const { address: inverseApi3ReaderProxyV1Address } = await deployments
68
.get('InverseApi3ReaderProxyV1')
@@ -14,7 +16,8 @@ const deployTestProxy = async (deployments: DeploymentsExtension, deployerAddres
1416
return inverseApi3ReaderProxyV1Address;
1517
};
1618

17-
module.exports = async ({ getUnnamedAccounts, deployments, network, ethers }: HardhatRuntimeEnvironment) => {
19+
module.exports = async (hre: HardhatRuntimeEnvironment) => {
20+
const { getUnnamedAccounts, deployments, network, ethers, run } = hre;
1821
const { deploy, log } = deployments;
1922

2023
const [deployerAddress] = await getUnnamedAccounts();
@@ -39,12 +42,29 @@ module.exports = async ({ getUnnamedAccounts, deployments, network, ethers }: Ha
3942
}
4043
log(`Proxy address: ${proxyAddress}`);
4144

42-
await deployments.get('ScaledApi3FeedProxyV1').catch(async () => {
43-
return deploy('ScaledApi3FeedProxyV1', {
44-
from: deployerAddress,
45-
args: [proxyAddress, decimals],
46-
log: true,
47-
});
45+
const isLocalNetwork = network.name === 'hardhat' || network.name === 'localhost';
46+
47+
const confirmations = isLocalNetwork ? 1 : VERIFICATION_BLOCK_CONFIRMATIONS;
48+
log(`Deployment confirmations: ${confirmations}`);
49+
50+
const contractName = 'ScaledApi3FeedProxyV1';
51+
52+
const deployment = await deploy(contractName, {
53+
from: deployerAddress,
54+
args: [proxyAddress, decimals],
55+
log: true,
56+
waitConfirmations: confirmations,
57+
});
58+
59+
if (isLocalNetwork) {
60+
log('Skipping verification on local network.');
61+
return;
62+
}
63+
64+
log(`Attempting verification of ${contractName} (already waited for confirmations)...`);
65+
await run('verify:verify', {
66+
address: deployment.address,
67+
constructorArguments: deployment.args,
4868
});
4969
};
5070
module.exports.tags = ['ScaledApi3FeedProxyV1'];

example.env

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
MNEMONIC=
2+
ETHERSCAN_API_KEY_APECHAIN=
3+
ETHERSCAN_API_KEY_ARBITRUM_SEPOLIA_TESTNET=
4+
ETHERSCAN_API_KEY_ARBITRUM=
5+
ETHERSCAN_API_KEY_AVALANCHE_TESTNET=
6+
ETHERSCAN_API_KEY_AVALANCHE=
7+
ETHERSCAN_API_KEY_BASE_SEPOLIA_TESTNET=
8+
ETHERSCAN_API_KEY_BASE=
9+
ETHERSCAN_API_KEY_BERACHAIN=
10+
ETHERSCAN_API_KEY_BLAST_SEPOLIA_TESTNET=
11+
ETHERSCAN_API_KEY_BLAST=
12+
ETHERSCAN_API_KEY_BSC_TESTNET=
13+
ETHERSCAN_API_KEY_BSC=
14+
ETHERSCAN_API_KEY_CORE_TESTNET=
15+
ETHERSCAN_API_KEY_CORE=
16+
ETHERSCAN_API_KEY_ETHEREUM_HOLESKY_TESTNET=
17+
ETHERSCAN_API_KEY_ETHEREUM_SEPOLIA_TESTNET=
18+
ETHERSCAN_API_KEY_ETHEREUM=
19+
ETHERSCAN_API_KEY_FRAXTAL_HOLESKY_TESTNET=
20+
ETHERSCAN_API_KEY_FRAXTAL=
21+
ETHERSCAN_API_KEY_GNOSIS=
22+
ETHERSCAN_API_KEY_KROMA_SEPOLIA_TESTNET=
23+
ETHERSCAN_API_KEY_LINEA_SEPOLIA_TESTNET=
24+
ETHERSCAN_API_KEY_LINEA=
25+
ETHERSCAN_API_KEY_MANTLE_SEPOLIA_TESTNET=
26+
ETHERSCAN_API_KEY_MANTLE=
27+
ETHERSCAN_API_KEY_MOONBEAM_TESTNET=
28+
ETHERSCAN_API_KEY_MOONBEAM=
29+
ETHERSCAN_API_KEY_MOONRIVER=
30+
ETHERSCAN_API_KEY_OPBNB_TESTNET=
31+
ETHERSCAN_API_KEY_OPBNB=
32+
ETHERSCAN_API_KEY_OPTIMISM_SEPOLIA_TESTNET=
33+
ETHERSCAN_API_KEY_OPTIMISM=
34+
ETHERSCAN_API_KEY_POLYGON_SEPOLIA_TESTNET=
35+
ETHERSCAN_API_KEY_POLYGON_ZKEVM_SEPOLIA_TESTNET=
36+
ETHERSCAN_API_KEY_POLYGON_ZKEVM=
37+
ETHERSCAN_API_KEY_POLYGON=
38+
ETHERSCAN_API_KEY_SCROLL_SEPOLIA_TESTNET=
39+
ETHERSCAN_API_KEY_SCROLL=
40+
ETHERSCAN_API_KEY_SONIC_TESTNET=
41+
ETHERSCAN_API_KEY_SONIC=
42+
ETHERSCAN_API_KEY_TAIKO_HOLESKY_TESTNET=
43+
ETHERSCAN_API_KEY_TAIKO=
44+
ETHERSCAN_API_KEY_UNICHAIN_SEPOLIA_TESTNET=
45+
ETHERSCAN_API_KEY_UNICHAIN=
46+
ETHERSCAN_API_KEY_WORLD=
47+
ETHERSCAN_API_KEY_ZIRCUIT_SEPOLIA_TESTNET=
48+
ETHERSCAN_API_KEY_ZIRCUIT=

hardhat.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { hardhatConfig } from '@api3/contracts';
22
import '@nomicfoundation/hardhat-toolbox';
3+
import '@nomicfoundation/hardhat-verify';
34
import 'hardhat-deploy';
5+
import 'dotenv/config';
46
import type { HardhatUserConfig } from 'hardhat/config';
57

68
const config: HardhatUserConfig = {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@
4242
"@nomicfoundation/hardhat-ethers": "^3.0.8",
4343
"@nomicfoundation/hardhat-network-helpers": "^1.0.12",
4444
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
45+
"@nomicfoundation/hardhat-verify": "^2.0.14",
4546
"@types/chai": "^4.3.20",
4647
"@types/mocha": "^10.0.10",
4748
"@types/node": "^22.15.18",
4849
"@typescript-eslint/eslint-plugin": "^7.18.0",
4950
"@typescript-eslint/parser": "^7.18.0",
5051
"chai": "^4.5.0",
52+
"dotenv": "^16.5.0",
5153
"eslint": "8.57.1",
5254
"ethers": "^6.13.2",
5355
"glob": "^11.0.2",

pnpm-lock.yaml

Lines changed: 24 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)