|
| 1 | +import { exec } from "child_process"; |
| 2 | +import fs from "fs"; |
| 3 | +import path from "path"; |
| 4 | +import util from "util"; |
| 5 | + |
| 6 | +const execPromise = util.promisify(exec); |
| 7 | + |
| 8 | +async function main() { |
| 9 | + try { |
| 10 | + // Get the deployments directory path |
| 11 | + const deploymentsPath = path.join(__dirname, "../deployments/monadTestnet"); |
| 12 | + |
| 13 | + // Read all files in the deployments directory |
| 14 | + const files = fs.readdirSync(deploymentsPath); |
| 15 | + |
| 16 | + // Filter for .json files and get the latest one by modification time |
| 17 | + const jsonFiles = files |
| 18 | + .filter(file => file.endsWith(".json")) |
| 19 | + .map(file => ({ |
| 20 | + name: file, |
| 21 | + time: fs.statSync(path.join(deploymentsPath, file)).mtime.getTime(), |
| 22 | + })) |
| 23 | + .sort((a, b) => b.time - a.time); |
| 24 | + |
| 25 | + if (jsonFiles.length === 0) { |
| 26 | + throw new Error("No deployment files found"); |
| 27 | + } |
| 28 | + |
| 29 | + // Read the latest deployment file |
| 30 | + const latestDeployment = JSON.parse(fs.readFileSync(path.join(deploymentsPath, jsonFiles[0].name), "utf8")); |
| 31 | + |
| 32 | + const contractAddress = latestDeployment.address; |
| 33 | + const constructorArgs = latestDeployment.args; |
| 34 | + |
| 35 | + console.log(`Latest deployed contract address: ${contractAddress}`); |
| 36 | + console.log(`Contract name: ${jsonFiles[0].name.replace(".json", "")}`); |
| 37 | + console.log(`Constructor arguments: ${constructorArgs.join(", ")}`); |
| 38 | + |
| 39 | + // Run the verify command with constructor arguments |
| 40 | + console.log("Starting verification..."); |
| 41 | + const { stdout, stderr } = await execPromise( |
| 42 | + `yarn hardhat verify --network monadTestnet ${contractAddress} ${constructorArgs.join(" ")}`, |
| 43 | + ); |
| 44 | + |
| 45 | + console.log("Verification output:"); |
| 46 | + console.log(stdout); |
| 47 | + |
| 48 | + if (stderr) { |
| 49 | + console.error("Verification errors:"); |
| 50 | + console.error(stderr); |
| 51 | + } |
| 52 | + } catch (error) { |
| 53 | + console.error("Error during verification:", error); |
| 54 | + process.exit(1); |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +main() |
| 59 | + .then(() => process.exit(0)) |
| 60 | + .catch(error => { |
| 61 | + console.error(error); |
| 62 | + process.exit(1); |
| 63 | + }); |
0 commit comments