forked from gnosis/hashi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optional verify after contract deployment
- Loading branch information
Showing
2 changed files
with
52 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |