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

Use @nomiclabs/hardhat-etherscan for Etherscan verification #125

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
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
45 changes: 2 additions & 43 deletions .github/workflows/contracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ jobs:
CHAIN_API_URL: ${{ secrets.GOERLI_ETH_HOSTNAME_HTTP }}
CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
KEEP_CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_KEEP_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
run: yarn deploy --network ${{ github.event.inputs.environment }}

- name: Bump up package version
Expand Down Expand Up @@ -171,49 +172,6 @@ jobs:
upstream_ref: ${{ github.event.inputs.upstream_ref }}
version: ${{ steps.npm-version-bump.outputs.version }}

- name: Upload files needed for etherscan verification
uses: actions/upload-artifact@v3
with:
name: Artifacts for etherscan verifcation
path: |
./deployments
./package.json
./yarn.lock

contracts-etherscan-verification:
needs: [contracts-deployment-testnet]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Download files needed for etherscan verification
uses: actions/download-artifact@v3
with:
name: Artifacts for etherscan verifcation

- uses: actions/setup-node@v3
with:
node-version: "14.x"
cache: "yarn"

- name: Install needed dependencies
run: yarn install --frozen-lockfile

# If we don't remove the `keep-core` contracts from `node-modules`, the
# `etherscan-verify` plugins tries to verify them, which is not desired.
- name: Prepare for verification on Etherscan
run: |
rm -rf ./node_modules/@keep-network/keep-core
rm -rf ./external/npm

- name: Verify contracts on Etherscan
env:
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
CHAIN_API_URL: ${{ secrets.GOERLI_ETH_HOSTNAME_HTTP }}
run: |
yarn run hardhat --network ${{ github.event.inputs.environment }} \
etherscan-verify --license GPL-3.0 --force-license

# This job is responsible for publishing packages from `dapp-development`
# branch, which are slightly modified to help with the process of testing some
# features on the Threshold Token dApp. The job starts only if workflow gets
Expand Down Expand Up @@ -244,6 +202,7 @@ jobs:
CHAIN_API_URL: ${{ secrets.GOERLI_ETH_HOSTNAME_HTTP }}
CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.DAPP_DEV_GOERLI_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
KEEP_CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_KEEP_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
run: yarn deploy --network ${{ github.event.inputs.environment }}

- name: Bump up package version
Expand Down
1 change: 0 additions & 1 deletion deploy/00_resolve_nucypher_staking_escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
} else if (
// TODO: For testnets currently we deploy a stub contract. We should consider
// switching to an actual contract.
hre.network.name !== "ropsten" &&
hre.network.name !== "goerli" &&
(!hre.network.tags.allowStubs ||
(hre.network.config as HardhatNetworkConfig)?.forking?.enabled)
Expand Down
1 change: 0 additions & 1 deletion deploy/00_resolve_nucypher_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
} else if (
// TODO: For testnets currently we deploy a stub contract. We should consider
// switching to an actual contract.
hre.network.name !== "ropsten" &&
hre.network.name !== "goerli" &&
(!hre.network.tags.allowStubs ||
(hre.network.config as HardhatNetworkConfig)?.forking?.enabled)
Expand Down
6 changes: 5 additions & 1 deletion deploy/01_deploy_t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments } = hre
const { getNamedAccounts, deployments, helpers } = hre
const { deployer } = await getNamedAccounts()

const T = await deployments.deploy("T", {
from: deployer,
log: true,
})

if (hre.network.tags.etherscan) {
await helpers.etherscan.verify(T)
}

if (hre.network.tags.tenderly) {
await hre.tenderly.verify({
name: "T",
Expand Down
4 changes: 4 additions & 0 deletions deploy/03_deploy_vending_machine_keep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
})

if (hre.network.tags.etherscan) {
await helpers.etherscan.verify(vendingMachine)
}

if (hre.network.tags.tenderly) {
await hre.tenderly.verify({
name: "VendingMachineKeep",
Expand Down
4 changes: 4 additions & 0 deletions deploy/04_deploy_vending_machine_nu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
})

if (hre.network.tags.etherscan) {
await helpers.etherscan.verify(vendingMachine)
}

if (hre.network.tags.tenderly) {
await hre.tenderly.verify({
name: "VendingMachineNuCypher",
Expand Down
6 changes: 5 additions & 1 deletion deploy/06_deploy_keep_stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments } = hre
const { getNamedAccounts, deployments, helpers } = hre
const { deployer } = await getNamedAccounts()

const KeepTokenStaking = await deployments.get("KeepTokenStaking")
Expand All @@ -13,6 +13,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
})

if (hre.network.tags.etherscan) {
await helpers.etherscan.verify(KeepStake)
}

if (hre.network.tags.tenderly) {
await hre.tenderly.verify({
name: "KeepStake",
Expand Down
6 changes: 5 additions & 1 deletion deploy/07_deploy_token_staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DeployFunction } from "hardhat-deploy/types"
import { ethers, upgrades } from "hardhat"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments } = hre
const { getNamedAccounts, deployments, helpers } = hre
const { execute, log } = deployments
const { deployer } = await getNamedAccounts()

Expand Down Expand Up @@ -69,6 +69,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

await execute("TokenStaking", { from: deployer }, "initialize")
log("Initialized TokenStaking.")

if (hre.network.tags.etherscan) {
await helpers.etherscan.verify(TokenStaking)
}
}

if (hre.network.tags.tenderly) {
Expand Down
6 changes: 5 additions & 1 deletion deploy/30_deploy_tokenholder_timelock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DeployFunction } from "hardhat-deploy/types"
import { ethers } from "ethers"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments } = hre
const { getNamedAccounts, deployments, helpers } = hre
const { deployer } = await getNamedAccounts()

const proposers = []
Expand All @@ -21,6 +21,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
})

if (hre.network.tags.etherscan) {
await helpers.etherscan.verify(timelock)
}

if (hre.network.tags.tenderly) {
await hre.tenderly.verify({
name: "TokenholderTimelock",
Expand Down
14 changes: 13 additions & 1 deletion deploy/31_deploy_tokenholder_governor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments } = hre
const { getNamedAccounts, deployments, helpers } = hre
const { deployer, thresholdCouncil } = await getNamedAccounts()

// TODO: fail if thresholdCouncil is undefined on mainnet
Expand All @@ -23,6 +23,18 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
})

if (hre.network.tags.etherscan) {
await hre.ethers.provider.waitForTransaction(
timelock.transactionHash,
5,
300000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the occasional need for this, but there's nothing inherent to TokenholderGovernor that requires an extra waiting time. It can happen to other deployments with some small probability. Can we instead add this to all Etherscan verification calls? Ideally, we can introduce it as part of a helper function.

)
await helpers.etherscan.verify(
timelock,
"contracts/governance/TokenholderGovernor.sol:TokenholderGovernor"
)
}

if (hre.network.tags.tenderly) {
await hre.tenderly.verify({
name: "TokenholderGovernor",
Expand Down
26 changes: 3 additions & 23 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HardhatUserConfig } from "hardhat/config"

import "@nomiclabs/hardhat-etherscan"
import "@keep-network/hardhat-helpers"
import "@nomiclabs/hardhat-waffle"
import "@openzeppelin/hardhat-upgrades"
Expand Down Expand Up @@ -54,34 +55,15 @@ const config: HardhatUserConfig = {
process.env.KEEP_CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY,
]
: undefined,
tags: ["tenderly"],
},
rinkeby: {
url: process.env.CHAIN_API_URL || "",
chainId: 4,
accounts: process.env.CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY
? [process.env.CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY]
: undefined,
tags: ["tenderly"],
},
ropsten: {
url: process.env.CHAIN_API_URL || "",
chainId: 3,
accounts: process.env.CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY
? [
process.env.CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY,
process.env.KEEP_CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY,
]
: undefined,
tags: ["tenderly"],
tags: ["etherscan", "tenderly"],
},
mainnet: {
url: process.env.CHAIN_API_URL || "",
chainId: 1,
accounts: process.env.CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY
? [process.env.CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY]
: undefined,
tags: ["tenderly"],
tags: ["etherscan", "tenderly"],
},
},
tenderly: {
Expand Down Expand Up @@ -110,7 +92,6 @@ const config: HardhatUserConfig = {
// with `yarn link` command, uncomment the line below to use the linked
// dependencies.
// development: ["external/npm/@keep-network/keep-core/artifacts"],
ropsten: ["external/npm/@keep-network/keep-core/artifacts"],
goerli: ["external/npm/@keep-network/keep-core/artifacts"],
mainnet: ["./external/mainnet"],
},
Expand All @@ -126,7 +107,6 @@ const config: HardhatUserConfig = {
},
keepRegistryKeeper: {
default: 1, // same as the deployer
ropsten: "0x923C5Dbf353e99394A21Aa7B67F3327Ca111C67D",
goerli: "0x68ad60CC5e8f3B7cC53beaB321cf0e6036962dBc",
},
},
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
"prepublishOnly": "hardhat prepare-artifacts --network $npm_config_network"
},
"devDependencies": {
"@keep-network/hardhat-helpers": "^0.6.0-pre.8",
"@keep-network/hardhat-helpers": "^0.6.0-pre.16",
"@keep-network/prettier-config-keep": "github:keep-network/prettier-config-keep#d6ec02e",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "3.0.4",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/hardhat-upgrades": "^1.12.0",
"@tenderly/hardhat-tenderly": "^1.0.12",
Expand All @@ -48,7 +49,7 @@
"ethers": "^5.5.3",
"hardhat": "^2.8.3",
"hardhat-contract-sizer": "^2.5.0",
"hardhat-deploy": "^0.9.27",
"hardhat-deploy": "^0.11.15",
"hardhat-gas-reporter": "^1.0.6",
"prettier": "^2.3.2",
"prettier-plugin-sh": "^0.7.1",
Expand Down
Loading