From 41668a4a7232a59ef86d413a87d7274fe0dab6a9 Mon Sep 17 00:00:00 2001 From: Nick Lionis Date: Tue, 15 Oct 2024 23:01:23 +0300 Subject: [PATCH 1/2] verification now should be robust --- packages/hardhat/README.md | 2 +- packages/hardhat/deploy/00_deal_client.ts | 2 +- packages/hardhat/deploy/01_deal_info.ts | 2 +- packages/hardhat/tasks/verify-contract.ts | 30 ++++++++++++++++------- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/hardhat/README.md b/packages/hardhat/README.md index 5c4b1d9..306a721 100644 --- a/packages/hardhat/README.md +++ b/packages/hardhat/README.md @@ -17,5 +17,5 @@ npx hardhat ignition deploy ./ignition/modules/Lock.ts For contracts deployed on Filecoin mainnet or Filecoin testnet (calibration) using this repo you can verify them by executing this script: ```shell -npx hardhat verify-contract --network $networkName --contract-name $contractName +npx hardhat verify-contract --network $networkName --contractname $contractName ``` diff --git a/packages/hardhat/deploy/00_deal_client.ts b/packages/hardhat/deploy/00_deal_client.ts index 86c3459..dc98456 100644 --- a/packages/hardhat/deploy/00_deal_client.ts +++ b/packages/hardhat/deploy/00_deal_client.ts @@ -54,7 +54,7 @@ const deployDealClient: DeployFunction = async function ( if (filecoinNetworks.includes(hre.network.name)) { // Verify the contract on the filfox explorer await hre.run("verify-contract", { - contractName: "DealClient", + contractname: "DealClient", }); } else { await hre.run("verify:verify", { diff --git a/packages/hardhat/deploy/01_deal_info.ts b/packages/hardhat/deploy/01_deal_info.ts index 68215a6..8f67dc3 100644 --- a/packages/hardhat/deploy/01_deal_info.ts +++ b/packages/hardhat/deploy/01_deal_info.ts @@ -54,7 +54,7 @@ const deployDealInfo: DeployFunction = async function ( if (filecoinNetworks.includes(hre.network.name)) { // Verify the contract on the filfox explorer await hre.run("verify-contract", { - contractName: "DealInfo", + contractname: "DealInfo", }); } else { await hre.run("verify:verify", { diff --git a/packages/hardhat/tasks/verify-contract.ts b/packages/hardhat/tasks/verify-contract.ts index 0085ec0..2cf074f 100644 --- a/packages/hardhat/tasks/verify-contract.ts +++ b/packages/hardhat/tasks/verify-contract.ts @@ -3,7 +3,7 @@ import { task } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; interface VerifyContractParams { - contractName: string; + contractname: string; } interface SourceFile { @@ -28,16 +28,16 @@ interface DeploymentData { } task("verify-contract", "Verifies a contract on Filfox") - .addParam("contractName", "The name of the contract to verify") + .addParam("contractname", "The name of the contract to verify") .setAction( async (taskArgs: VerifyContractParams, hre: HardhatRuntimeEnvironment) => { const networkName = hre.network.name; - const { contractName } = taskArgs; + const { contractname } = taskArgs; const verificationData = extractVerificationData( networkName, - contractName + contractname ); const url = "https://calibration.filfox.info/api/v1/tools/verifyContract"; const headers = { @@ -80,15 +80,27 @@ function extractVerificationData(network: string, contractName: string) { const solhintPath = `./deployments/${network}/solcInputs/${deployments.solcInputHash}.json`; const solhint: SolhintData = JSON.parse(fs.readFileSync(solhintPath, "utf8")); - // Extract the necessary data from the deployments and solhint files - const sourceFiles = Object.keys(solhint.sources) - .reverse() - .reduce((acc: any, key: string) => { - acc[key.split("contracts/")[1]] = solhint.sources[key]; + let sourceFiles = Object.keys(solhint.sources).reduce( + (acc: any, key: string) => { + acc[key] = solhint.sources[key]; // Add other sources + return acc; }, {}); + const contractToVerify = Object.keys(sourceFiles).find((key) => + key.includes(contractName + ".sol") + ); + if (!contractToVerify) { + throw new Error( + `Contract ${contractName} not found in the sources provided.` + ); + } + // Ensure the contract source is the first entry + const contractSource = sourceFiles[contractToVerify]; + delete sourceFiles[contractToVerify]; // Remove it from its current position + sourceFiles = { [contractToVerify]: contractSource, ...sourceFiles }; // Add it back at the start + const { compiler, language } = JSON.parse(deployments.metadata) as { compiler: { version: string; From 72f97ea96884a3ec1f9d21278366e4ad1acbef45 Mon Sep 17 00:00:00 2001 From: Nick Lionis Date: Sun, 20 Oct 2024 20:16:21 +0300 Subject: [PATCH 2/2] fix verification task arg --- packages/hardhat/README.md | 2 +- packages/hardhat/deploy/00_deal_client.ts | 2 +- packages/hardhat/deploy/01_deal_info.ts | 2 +- packages/hardhat/tasks/verify-contract.ts | 21 +++++++++++++-------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/hardhat/README.md b/packages/hardhat/README.md index 306a721..5c4b1d9 100644 --- a/packages/hardhat/README.md +++ b/packages/hardhat/README.md @@ -17,5 +17,5 @@ npx hardhat ignition deploy ./ignition/modules/Lock.ts For contracts deployed on Filecoin mainnet or Filecoin testnet (calibration) using this repo you can verify them by executing this script: ```shell -npx hardhat verify-contract --network $networkName --contractname $contractName +npx hardhat verify-contract --network $networkName --contract-name $contractName ``` diff --git a/packages/hardhat/deploy/00_deal_client.ts b/packages/hardhat/deploy/00_deal_client.ts index dc98456..86c3459 100644 --- a/packages/hardhat/deploy/00_deal_client.ts +++ b/packages/hardhat/deploy/00_deal_client.ts @@ -54,7 +54,7 @@ const deployDealClient: DeployFunction = async function ( if (filecoinNetworks.includes(hre.network.name)) { // Verify the contract on the filfox explorer await hre.run("verify-contract", { - contractname: "DealClient", + contractName: "DealClient", }); } else { await hre.run("verify:verify", { diff --git a/packages/hardhat/deploy/01_deal_info.ts b/packages/hardhat/deploy/01_deal_info.ts index 8f67dc3..68215a6 100644 --- a/packages/hardhat/deploy/01_deal_info.ts +++ b/packages/hardhat/deploy/01_deal_info.ts @@ -54,7 +54,7 @@ const deployDealInfo: DeployFunction = async function ( if (filecoinNetworks.includes(hre.network.name)) { // Verify the contract on the filfox explorer await hre.run("verify-contract", { - contractname: "DealInfo", + contractName: "DealInfo", }); } else { await hre.run("verify:verify", { diff --git a/packages/hardhat/tasks/verify-contract.ts b/packages/hardhat/tasks/verify-contract.ts index 2cf074f..f7409a7 100644 --- a/packages/hardhat/tasks/verify-contract.ts +++ b/packages/hardhat/tasks/verify-contract.ts @@ -3,7 +3,7 @@ import { task } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; interface VerifyContractParams { - contractname: string; + contractName: string; } interface SourceFile { @@ -28,18 +28,21 @@ interface DeploymentData { } task("verify-contract", "Verifies a contract on Filfox") - .addParam("contractname", "The name of the contract to verify") + .addParam("contractName", "The name of the contract to verify") .setAction( async (taskArgs: VerifyContractParams, hre: HardhatRuntimeEnvironment) => { const networkName = hre.network.name; - const { contractname } = taskArgs; + const { contractName } = taskArgs; const verificationData = extractVerificationData( networkName, - contractname + contractName ); - const url = "https://calibration.filfox.info/api/v1/tools/verifyContract"; + const url = + networkName === "calibration" + ? "https://calibration.filfox.info/api/v1/tools/verifyContract" + : "https://filfox.info/api/v1/tools/verifyContract"; const headers = { "Content-Type": "application/json", }; @@ -58,9 +61,11 @@ task("verify-contract", "Verifies a contract on Filfox") network: networkName, address: verificationData.address, }); - } catch (error) { - console.error("Error verifying contract:", error); - throw error; + } catch (error: any) { + console.error("⚠️ Error verifying contract: ", error.cause); + console.log( + "Please contact us on [Telegram](https://t.me/Filfoxofficial) if you encounter this error." + ); } } );