Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verification now should be robust #36

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/hardhat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
lordshashank marked this conversation as resolved.
Show resolved Hide resolved
```
2 changes: 1 addition & 1 deletion packages/hardhat/deploy/00_deal_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat/deploy/01_deal_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
30 changes: 21 additions & 9 deletions packages/hardhat/tasks/verify-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";

interface VerifyContractParams {
contractName: string;
contractname: string;
}

interface SourceFile {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down
Loading