From 8b609d6420a83984c8270ad390f5e10a6bdbf00a Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 31 Oct 2023 11:25:20 +0200 Subject: [PATCH 1/6] Fixed buf with VerificationFailedToSave --- src/deployer/MinimalContract.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/deployer/MinimalContract.ts b/src/deployer/MinimalContract.ts index 7b9f1670..2852055e 100644 --- a/src/deployer/MinimalContract.ts +++ b/src/deployer/MinimalContract.ts @@ -1,5 +1,7 @@ import { ethers, InterfaceAbi, Overrides, Signer } from "ethers"; +import { isFullyQualifiedName } from "hardhat/utils/contract-names"; + import { Linker } from "./Linker"; import { catchError, fillParameters, getChainId, getInterfaceOnlyWithConstructor, getSignerHelper } from "../utils"; @@ -16,6 +18,7 @@ import { VerificationProcessor } from "../tools/storage/VerificationProcessor"; @catchError export class MinimalContract { + private readonly _rawBytecode: string; private readonly _interface; constructor( @@ -25,6 +28,7 @@ export class MinimalContract { private readonly _contractName: string = "", ) { this._interface = getInterfaceOnlyWithConstructor(this._abi); + this._rawBytecode = this._bytecode; if (_contractName === "") { try { @@ -122,9 +126,15 @@ export class MinimalContract { TransactionProcessor.saveDeploymentTransaction(tx, tx.contractName, contractAddress); try { + let contractName = tx.contractName; + + if (!isFullyQualifiedName(contractName)) { + contractName = ArtifactProcessor.tryGetContractName(this._rawBytecode); + } + VerificationProcessor.saveVerificationFunction({ contractAddress, - contractName: ArtifactProcessor.tryGetContractName(this._bytecode), + contractName: contractName, constructorArguments: args, chainId: Number(await getChainId()), }); From b69d1c903e05d205bcb37208ef127fe8613e21ac Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 31 Oct 2023 11:27:09 +0200 Subject: [PATCH 2/6] Fixed typo --- src/tools/reporters/Reporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/reporters/Reporter.ts b/src/tools/reporters/Reporter.ts index 2d3355a3..1b95cacb 100644 --- a/src/tools/reporters/Reporter.ts +++ b/src/tools/reporters/Reporter.ts @@ -108,7 +108,7 @@ export class Reporter { } public static notifyTransactionSendingInsteadOfRecovery(contractMethod: string): void { - const output = `\nCan't recover transaction for ${contractMethod}. Sending instead...`; + const output = `\nCan't recover transaction for ${contractMethod}. Being sent instead...`; console.log(output); } From 3e4632755023db652ed0f0e9b2ea9291b5ce7200 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 31 Oct 2023 11:27:27 +0200 Subject: [PATCH 3/6] Updated versions --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a5bfc493..81e397e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/hardhat-migrate", - "version": "2.0.0-alpha.8", + "version": "2.0.0-alpha.9", "description": "Automatic deployment and verification of smart contracts", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", From 9b78c94807ce230448bfcaa10a35a08169a073de Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 31 Oct 2023 11:46:36 +0200 Subject: [PATCH 4/6] Added ability to recover contract verification data --- src/deployer/MinimalContract.ts | 20 ++++++++++++++++++-- src/tools/storage/VerificationProcessor.ts | 4 ++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/deployer/MinimalContract.ts b/src/deployer/MinimalContract.ts index 2852055e..bd3714c6 100644 --- a/src/deployer/MinimalContract.ts +++ b/src/deployer/MinimalContract.ts @@ -87,6 +87,8 @@ export class MinimalContract { Reporter.notifyContractRecovery(tx.contractName, contractAddress); + await this._saveContractForVerification(contractAddress, tx, args); + return contractAddress; } catch { /* empty */ @@ -97,6 +99,8 @@ export class MinimalContract { Reporter.notifyContractRecovery(tx.contractName, contractAddress); + await this._saveContractForVerification(contractAddress, tx, args); + return contractAddress; } catch { /* empty */ @@ -123,8 +127,22 @@ export class MinimalContract { throw new MigrateError("Contract deployment failed. Invalid contract address conversion."); } + await this._saveContractForVerification(contractAddress, tx, args); + TransactionProcessor.saveDeploymentTransaction(tx, tx.contractName, contractAddress); + return contractAddress; + } + + private async _saveContractForVerification( + contractAddress: string, + tx: ContractDeployTransactionWithContractName, + args: any[], + ) { + if (VerificationProcessor.isVerificationDataSaved(contractAddress)) { + return; + } + try { let contractName = tx.contractName; @@ -141,7 +159,5 @@ export class MinimalContract { } catch { Reporter.reportVerificationFailedToSave(tx.contractName); } - - return contractAddress; } } diff --git a/src/tools/storage/VerificationProcessor.ts b/src/tools/storage/VerificationProcessor.ts index e746f27a..e00b2019 100644 --- a/src/tools/storage/VerificationProcessor.ts +++ b/src/tools/storage/VerificationProcessor.ts @@ -27,4 +27,8 @@ export class VerificationProcessor { return Object.values(data); } + + public static isVerificationDataSaved(contractAddress: string): boolean { + return VerificationStorage.has(contractAddress); + } } From e9042ff04f9e2b56c3ee1658a6457ed08c347b26 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 31 Oct 2023 11:50:09 +0200 Subject: [PATCH 5/6] Added Provider init in migrateVerify --- src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.ts b/src/index.ts index 4ee1e466..5324aee5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,6 +56,8 @@ const migrate: ActionType = async (taskArgs, env) => { }; const migrateVerify: ActionType = async (taskArgs, env) => { + await Provider.init(env); + const config = extendVerifyConfigs(taskArgs); await Reporter.init(env.config.migrate); From 8e0646f83a562493458875441c7abfb3fc8d5aca Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 31 Oct 2023 11:52:37 +0200 Subject: [PATCH 6/6] Restore reporter --- src/tools/reporters/Reporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/reporters/Reporter.ts b/src/tools/reporters/Reporter.ts index 1b95cacb..2d3355a3 100644 --- a/src/tools/reporters/Reporter.ts +++ b/src/tools/reporters/Reporter.ts @@ -108,7 +108,7 @@ export class Reporter { } public static notifyTransactionSendingInsteadOfRecovery(contractMethod: string): void { - const output = `\nCan't recover transaction for ${contractMethod}. Being sent instead...`; + const output = `\nCan't recover transaction for ${contractMethod}. Sending instead...`; console.log(output); }