Skip to content

Commit

Permalink
feat: optional verify after contract deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
lrnt committed Apr 27, 2023
1 parent 9f7d2e9 commit 43e14a2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
"build": "hardhat compile",
"compile": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile",
"coverage": "hardhat coverage --solcoverjs ./.solcover.js --temp artifacts --testfiles \"test/**/*.ts\" && yarn typechain",
"deploy": "hardhat deploy:Hashi",
"deploy:hashi": "hardhat deploy:Hashi",
"deploy:girigiribashi": "hardhat deploy:GiriGiriBashi",
"lint": "yarn lint:sol && yarn lint:ts && yarn prettier:check",
"lint:sol": "solhint --max-warnings 0 \"contracts/**/*.sol\"",
"lint:ts": "eslint --ignore-path ./.eslintignore --ext .js,.ts .",
Expand Down
64 changes: 50 additions & 14 deletions packages/evm/tasks/deploy/hashi.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,67 @@
import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"
import { Contract } from "ethers"
import { task } from "hardhat/config"
import type { TaskArguments } from "hardhat/types"
import type { HardhatRuntimeEnvironment, TaskArguments } from "hardhat/types"

import type { GiriGiriBashi } from "../../types/contracts/GiriGiriBashi"
import type { Hashi } from "../../types/contracts/Hashi"
import type { GiriGiriBashi__factory } from "../../types/factories/contracts/GiriGiriBashi__factory"
import type { Hashi__factory } from "../../types/factories/contracts/Hashi__factory"
import { Hashi__factory } from "../../types/factories/contracts/Hashi__factory"

task("deploy:Hashi").setAction(async function (taskArguments: TaskArguments, { ethers }) {
const signers: SignerWithAddress[] = await ethers.getSigners()
const hashiFactory: Hashi__factory = <Hashi__factory>await ethers.getContractFactory("Hashi")
const hashi: Hashi = <Hashi>await hashiFactory.connect(signers[0]).deploy()
await hashi.deployed()
console.log("Hashi deployed to: ", hashi.address)
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const verify = async (hre: HardhatRuntimeEnvironment, contract: Contract, constructorArguments: any = []) => {
console.log("Waiting for 5 confirmations...")
await contract.deployTransaction.wait(5)
console.log("Verifying contract...")
try {
await hre.run("verify:verify", {
address: contract.address,
constructorArguments,
})
} catch (e) {
if (
e instanceof Error &&
e.stack &&
(e.stack.indexOf("Reason: Already Verified") > -1 ||
e.stack.indexOf("Contract source code already verified") > -1)
) {
console.log(" ✔ Contract is already verified")
} else {
console.log(
" ✘ Verifying the contract failed. This is probably because Etherscan is still indexing the contract. Try running this same command again in a few seconds.",
)
throw e
}
}
}

task("deploy:Hashi")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying Hashi...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const hashiFactory: Hashi__factory = <Hashi__factory>await hre.ethers.getContractFactory("Hashi")
const hashi: Hashi = <Hashi>await hashiFactory.connect(signers[0]).deploy()
await hashi.deployed()
console.log("Hashi deployed to:", hashi.address)
if (taskArguments.verify) await verify(hre, hashi)
})

task("deploy:GiriGiriBashi")
.addParam("owner", "address to set as the owner of this contract")
.addParam("hashi", "address of the hashi contract")
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
const signers: SignerWithAddress[] = await ethers.getSigners()
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying GiriGiriBashi...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const giriGiriBashiFactory: GiriGiriBashi__factory = <GiriGiriBashi__factory>(
await ethers.getContractFactory("GiriGiriBashi")
await hre.ethers.getContractFactory("GiriGiriBashi")
)
const constructorArguments = [taskArguments.owner, taskArguments.hashi] as const
const giriGiriBashi: GiriGiriBashi = <GiriGiriBashi>(
await giriGiriBashiFactory.connect(signers[0]).deploy(taskArguments.owner, taskArguments.hashi)
await giriGiriBashiFactory.connect(signers[0]).deploy(...constructorArguments)
)
await giriGiriBashi.deployed()
console.log("GiriGiriBashi deployed to: ", giriGiriBashi.address)
console.log("GiriGiriBashi deployed to:", giriGiriBashi.address)
if (taskArguments.verify) await verify(hre, giriGiriBashi, constructorArguments)
})

0 comments on commit 43e14a2

Please sign in to comment.