Skip to content

Commit

Permalink
Implement task to verify contract
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Oct 5, 2024
1 parent 1b586ed commit 94eb2f6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,15 @@ upgrade-maticx-holesky:
$(BIN_HARDHAT) upgrade-contract --network $(NETWORK_HOLESKY) --name MaticX --contract $(HOLESKY_MATIC_X)
upgrade-maticx-ethereum:
$(BIN_HARDHAT) upgrade-contract --network $(NETWORK_ETHEREUM) --name MaticX --contract $(ETHEREUM_MATIC_X)

# Verify the ValidatorRegistry contract
verify-validatorregistry-holesky:
$(BIN_HARDHAT) verify-contract --network $(NETWORK_HOLESKY) --contract $(HOLESKY_VALIDATOR_REGISTRY)
verify-validatorregistry-ethereum:
$(BIN_HARDHAT) verify-contract --network $(NETWORK_ETHEREUM) --contract $(ETHEREUM_VALIDATOR_REGISTRY)

# Verify the MaticX contract
verify-maticx-holesky:
$(BIN_HARDHAT) verify-contract --network $(NETWORK_HOLESKY) --contract $(HOLESKY_MATIC_X)
verify-maticx-ethereum:
$(BIN_HARDHAT) verify-contract --network $(NETWORK_ETHEREUM) --contract $(ETHEREUM_MATIC_X)
1 change: 1 addition & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./deploy-matic-x";
import "./deploy-validator-registry";
import "./upgrade-contract";
import "./verify-contract";
55 changes: 55 additions & 0 deletions tasks/verify-contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { task, types } from "hardhat/config";
import { TASK_CLEAN, TASK_COMPILE } from "hardhat/builtin-tasks/task-names";
import { isLocalNetwork, Network } from "../utils/network";

interface TaskParams {
address: string;
contractPath: string;
constructorArguments: string[];
}

task("verify-contract")
.setDescription("Verify a contract")
.addParam<string>("address", "Contract address", undefined, types.string)
.addOptionalParam<string>(
"contractPath",
"Contract path",
undefined,
types.string
)
.addOptionalVariadicPositionalParam<string[]>(
"constructorArguments",
"Constructor arguments",
[],
types.string
)
.setAction(
async (
{
address: contractAddress,
contractPath,
constructorArguments,
}: TaskParams,
{ ethers, network, run }
) => {
if (!ethers.utils.isAddress(contractAddress)) {
throw new Error("Invalid contract address");
}

const networkName = network.name as Network;
console.log(`Network name: ${networkName}`);
if (isLocalNetwork(networkName)) {
throw new Error("Unsupported network");
}

await run(TASK_CLEAN);
await run(TASK_COMPILE);

await run("verify:verify", {
address: contractAddress,
contract: contractPath,
constructorArguments,
force: true,
});
}
);

0 comments on commit 94eb2f6

Please sign in to comment.