-
Notifications
You must be signed in to change notification settings - Fork 157
chore: manual action for verifying deployments #758
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
Merged
pcarranzav
merged 2 commits into
graphprotocol:dev
from
spalladino:chore/verify-deployments-on-defender
Dec 6, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Verify deployed contracts | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
contracts: | ||
description: 'List of deployed contracts to verify (space delimited)' | ||
required: true | ||
type: string | ||
network: | ||
description: 'Network where the contracts are deployed' | ||
required: true | ||
type: choice | ||
default: mainnet | ||
options: | ||
- mainnet | ||
- arbitrum-one | ||
- goerli | ||
- arbitrum-goerli | ||
|
||
jobs: | ||
build: | ||
name: Compile contracts | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
cache: 'yarn' | ||
- run: yarn install --non-interactive --frozen-lockfile | ||
|
||
- name: Compile contracts | ||
run: yarn build | ||
|
||
- name: Save build artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: contract-artifacts | ||
path: | | ||
build | ||
cache/*.json | ||
|
||
verify: | ||
name: Verify deployments | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
cache: 'yarn' | ||
- run: yarn install --non-interactive --frozen-lockfile | ||
- name: Get build artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: contract-artifacts | ||
|
||
- name: Verify contracts on Defender | ||
run: yarn hardhat --network ${{ inputs.network }} verify-defender ${{ inputs.contracts }} | ||
env: | ||
DEFENDER_API_KEY: "${{ secrets.DEFENDER_API_KEY }}" | ||
DEFENDER_API_SECRET: "${{ secrets.DEFENDER_API_SECRET }}" | ||
INFURA_KEY: "${{ secrets.INFURA_KEY }}" | ||
WORKFLOW_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { execSync } from 'child_process' | ||
import { task } from 'hardhat/config' | ||
import { HardhatRuntimeEnvironment as HRE } from 'hardhat/types' | ||
import { constants } from 'ethers' | ||
import { appendFileSync } from 'fs' | ||
import type { VerificationResponse } from '@openzeppelin/hardhat-defender/dist/verify-deployment' | ||
|
||
async function main(args: { referenceUrl?: string; contracts: string[] }, hre: HRE) { | ||
const { referenceUrl, contracts } = args | ||
const { defender, network, graph } = hre | ||
const summaryPath = process.env.GITHUB_STEP_SUMMARY | ||
if (summaryPath) appendFileSync(summaryPath, `# Contracts deployment verification\n\n`) | ||
|
||
const workflowUrl = | ||
referenceUrl || | ||
process.env.WORKFLOW_URL || | ||
execSync(`git config --get remote.origin.url`).toString().trim() | ||
const addressBook = graph().addressBook | ||
const errs = [] | ||
|
||
for (const contractName of contracts) { | ||
const entry = addressBook.getEntry(contractName) | ||
if (!entry || entry.address === constants.AddressZero) { | ||
errs.push([contractName, { message: `Entry not found on address book.` }]) | ||
continue | ||
} | ||
|
||
const addressToVerify = entry.implementation?.address ?? entry.address | ||
console.error(`Verifying artifact for ${contractName} at ${addressToVerify}`) | ||
|
||
try { | ||
const response = await defender.verifyDeployment(addressToVerify, contractName, workflowUrl) | ||
console.error(`Bytecode match for ${contractName} is ${response.matchType}`) | ||
if (summaryPath) { | ||
appendFileSync( | ||
summaryPath, | ||
`- ${contractName} at ${etherscanLink(network.name, addressToVerify)} is ${ | ||
response.matchType | ||
} ${emojiForMatch(response.matchType)}\n`, | ||
) | ||
} | ||
if (response.matchType === 'NO_MATCH') { | ||
errs.push([contractName, { message: `No bytecode match.` }]) | ||
} | ||
} catch (err: any) { | ||
if (summaryPath) { | ||
appendFileSync( | ||
summaryPath, | ||
`- ${contractName} at ${etherscanLink( | ||
network.name, | ||
addressToVerify, | ||
)} failed to verify :x:\n`, | ||
) | ||
} | ||
console.error(`Error verifying artifact: ${err.message}`) | ||
errs.push([contractName, err]) | ||
} | ||
} | ||
|
||
if (errs.length > 0) { | ||
throw new Error( | ||
`Some verifications failed:\n${errs | ||
.map(([name, err]) => ` ${name}: ${err.message}`) | ||
.join('\n')}`, | ||
) | ||
} | ||
} | ||
|
||
function etherscanLink(network: string, address: string): string { | ||
switch (network) { | ||
case 'mainnet': | ||
return `[\`${address}\`](https://etherscan.io/address/${address})` | ||
case 'arbitrum-one': | ||
return `[\`${address}\`](https://arbiscan.io/address/${address})` | ||
case 'goerli': | ||
return `[\`${address}\`](https://goerli.etherscan.io/address/${address})` | ||
case 'arbitrum-goerli': | ||
return `[\`${address}\`](https://goerli.arbiscan.io/address/${address})` | ||
default: | ||
return `\`${address}\`` | ||
} | ||
} | ||
|
||
function emojiForMatch(matchType: VerificationResponse['matchType']): string { | ||
switch (matchType) { | ||
case 'EXACT': | ||
return ':heavy_check_mark:' | ||
case 'PARTIAL': | ||
return ':warning:' | ||
case 'NO_MATCH': | ||
return ':x:' | ||
} | ||
} | ||
|
||
task('verify-defender') | ||
.addVariadicPositionalParam('contracts', 'List of contracts to verify') | ||
.addOptionalParam( | ||
'referenceUrl', | ||
'URL to link to for artifact verification (defaults to $WORKFLOW_URL or the remote.origin.url of the repository)', | ||
) | ||
.setDescription('Verifies deployed implementations on Defender') | ||
.setAction(main) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.