Skip to content

Commit

Permalink
Simplify verify task
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Jul 25, 2024
1 parent 0736c77 commit 9f83e5b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 41 deletions.
18 changes: 0 additions & 18 deletions tasks/createEIP1193.ts

This file was deleted.

20 changes: 18 additions & 2 deletions tasks/mastercopy-deploy.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import path from 'path'
import { cwd } from 'process'
import { readFileSync } from 'fs'
import { Signer } from 'ethers'
import { task } from 'hardhat/config'
import { EthereumProvider } from 'hardhat/types'

import {
deployMastercopy,
EIP1193Provider,
MastercopyArtifact,
} from 'zodiac-core'

import createEIP1193 from './createEIP1193'

task(
'mastercopy:deploy',
'For every version entry on the artifacts file, deploys a mastercopy into the current network'
Expand Down Expand Up @@ -44,3 +44,19 @@ async function deploy(
console.log(`version ${version}: Deployed Mastercopy at at ${address}`)
}
}

function createEIP1193(
provider: EthereumProvider,
signer: Signer
): EIP1193Provider {
return {
request: async ({ method, params }) => {
if (method == 'eth_sendTransaction') {
const { hash } = await signer.sendTransaction((params as any[])[0])
return hash
}

return provider.request({ method, params })
},
}
}
30 changes: 9 additions & 21 deletions tasks/mastercopy-verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,36 @@ import { cwd } from 'process'
import { readFileSync } from 'fs'
import { task } from 'hardhat/config'

import {
verifyMastercopy,
MastercopyArtifact,
EIP1193Provider,
} from 'zodiac-core'

import createEIP1193 from './createEIP1193'
import { verifyMastercopy, MastercopyArtifact } from 'zodiac-core'

const { ETHERSCAN_API_KEY } = process.env

task(
'mastercopy:verify',
'Verifies all mastercopies from the artifacts file, in the block explorer corresponding to the current network'
).setAction(async (_, hre) => {
if (!ETHERSCAN_API_KEY) {
throw new Error('Missing ENV ETHERSCAN_API_KEY')
}

const mastercopies = JSON.parse(
readFileSync(path.join(cwd(), 'mastercopies.json'), 'utf8')
)

const [signer] = await hre.ethers.getSigners()

const provider = createEIP1193(hre.network.provider, signer)
const chainId = hre.network.config.chainId!

for (const [version, artifact] of Object.entries(mastercopies)) {
await verify(version, artifact as MastercopyArtifact, provider)
await verify(version, artifact as MastercopyArtifact, chainId)
}
})

async function verify(
version: string,
artifact: MastercopyArtifact,
provider: EIP1193Provider
chainId: number
) {
const chainId = String(
Number(await provider.request({ method: 'eth_chainId' }))
)

if (!ETHERSCAN_API_KEY) {
throw new Error('Missing ENV ETHERSCAN_API_KEY')
}

const { noop } = await verifyMastercopy(artifact, {
network: chainId,
network: String(chainId),
apiKey: ETHERSCAN_API_KEY as string,
})
if (noop) {
Expand Down

0 comments on commit 9f83e5b

Please sign in to comment.