Skip to content

Commit 69d1bb3

Browse files
authored
Merge pull request #4791 from NomicFoundation/sourcify-programmatic-access
Add support for programmatic verification in Sourcify
2 parents b626dc1 + f6a26b4 commit 69d1bb3

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

.changeset/twelve-mails-heal.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomicfoundation/hardhat-verify": patch
3+
---
4+
5+
Added support for programmatic verification in Sourcify

packages/hardhat-verify/src/index.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ subtask(TASK_VERIFY_GET_CONTRACT_INFORMATION)
259259
);
260260

261261
/**
262-
* This subtask is used for backwards compatibility.
263-
* TODO [remove-verify-subtask]: if you're going to remove this subtask,
264-
* update TASK_VERIFY_ETHERSCAN and TASK_VERIFY_ETHERSCAN_RESOLVE_ARGUMENTS accordingly
262+
* This subtask is used to programmatically verify a contract on Etherscan or Sourcify.
265263
*/
266264
subtask(TASK_VERIFY_VERIFY)
267265
.addOptionalParam("address")
@@ -271,7 +269,7 @@ subtask(TASK_VERIFY_VERIFY)
271269
.setAction(
272270
async (
273271
{ address, constructorArguments, libraries, contract }: VerifySubtaskArgs,
274-
{ run }
272+
{ run, config }
275273
) => {
276274
// This can only happen if the subtask is invoked from within Hardhat by a user script or another task.
277275
if (!Array.isArray(constructorArguments)) {
@@ -282,11 +280,21 @@ subtask(TASK_VERIFY_VERIFY)
282280
throw new InvalidLibrariesError();
283281
}
284282

285-
await run(TASK_VERIFY_ETHERSCAN, {
286-
address,
287-
constructorArgsParams: constructorArguments,
288-
libraries,
289-
contract,
290-
});
283+
if (config.etherscan.enabled) {
284+
await run(TASK_VERIFY_ETHERSCAN, {
285+
address,
286+
constructorArgsParams: constructorArguments,
287+
libraries,
288+
contract,
289+
});
290+
}
291+
292+
if (config.sourcify.enabled) {
293+
await run(TASK_VERIFY_SOURCIFY, {
294+
address,
295+
libraries,
296+
contract,
297+
});
298+
}
291299
}
292300
);

packages/hardhat-verify/src/internal/tasks/etherscan.ts

-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ subtask(TASK_VERIFY_ETHERSCAN)
7474
.addParam("address")
7575
.addOptionalParam("constructorArgsParams", undefined, undefined, types.any)
7676
.addOptionalParam("constructorArgs")
77-
// TODO: [remove-verify-subtask] change to types.inputFile
7877
.addOptionalParam("libraries", undefined, undefined, types.any)
7978
.addOptionalParam("contract")
8079
.setAction(async (taskArgs: VerifyTaskArgs, { config, network, run }) => {
@@ -199,7 +198,6 @@ subtask(TASK_VERIFY_ETHERSCAN_RESOLVE_ARGUMENTS)
199198
.addOptionalParam("address")
200199
.addOptionalParam("constructorArgsParams", undefined, [], types.any)
201200
.addOptionalParam("constructorArgs", undefined, undefined, types.inputFile)
202-
// TODO: [remove-verify-subtask] change to types.inputFile
203201
.addOptionalParam("libraries", undefined, undefined, types.any)
204202
.addOptionalParam("contract")
205203
.setAction(
@@ -228,7 +226,6 @@ subtask(TASK_VERIFY_ETHERSCAN_RESOLVE_ARGUMENTS)
228226
constructorArgsModule
229227
);
230228

231-
// TODO: [remove-verify-subtask] librariesModule should always be string
232229
let libraries;
233230
if (typeof librariesModule === "object") {
234231
libraries = librariesModule;

packages/hardhat-verify/src/internal/tasks/sourcify.ts

-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ interface AttemptVerificationArgs {
5151
subtask(TASK_VERIFY_SOURCIFY)
5252
.addParam("address")
5353
.addOptionalParam("contract")
54-
// TODO: [remove-verify-subtask] change to types.inputFile
5554
.addOptionalParam("libraries", undefined, undefined, types.any)
5655
.setAction(async (taskArgs: VerifyTaskArgs, { config, network, run }) => {
5756
const { address, libraries, contractFQN }: VerificationArgs = await run(
@@ -143,7 +142,6 @@ ${contractURL}`);
143142
subtask(TASK_VERIFY_SOURCIFY_RESOLVE_ARGUMENTS)
144143
.addOptionalParam("address")
145144
.addOptionalParam("contract")
146-
// TODO: [remove-verify-subtask] change to types.inputFile
147145
.addOptionalParam("libraries", undefined, undefined, types.any)
148146
.setAction(
149147
async ({
@@ -164,7 +162,6 @@ subtask(TASK_VERIFY_SOURCIFY_RESOLVE_ARGUMENTS)
164162
throw new InvalidContractNameError(contract);
165163
}
166164

167-
// TODO: [remove-verify-subtask] librariesModule should always be string
168165
let libraries;
169166
if (typeof librariesModule === "object") {
170167
libraries = librariesModule;

0 commit comments

Comments
 (0)