Skip to content

Commit

Permalink
😬 Perform verification on previously deployed contracts (#21)
Browse files Browse the repository at this point in the history
* 😬 Perform verification on previously deployed contracts

* fix lint
  • Loading branch information
vanruch authored Jan 8, 2021
1 parent 0806c69 commit 3fdec04
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
16 changes: 9 additions & 7 deletions packages/mars/src/execute/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ async function executeDeploy(action: DeployAction, options: ExecuteOptions) {
const params = action.params.map((param) => resolveValue(param))
const tx = getDeployTx(action.artifact[AbiSymbol], action.artifact[Bytecode], params)
const existingAddress = await getExistingDeployment(tx, action.name, options)
let address: string, txHash: string
if (existingAddress) {
console.log(`Skipping deployment ${action.name} - ${existingAddress}`)
action.resolve(existingAddress)
return
}
const { txHash, address } = await sendTransaction(`Deploy ${action.name}`, options, tx)
if (!options.dryRun) {
save(options.deploymentsFile, options.network, action.name, { txHash, address })
address = existingAddress
} else {
// eslint-disable-next-line no-extra-semi,@typescript-eslint/no-extra-semi
;({ txHash, address } = await sendTransaction(`Deploy ${action.name}`, options, tx))
if (!options.dryRun) {
save(options.deploymentsFile, options.network, action.name, { txHash, address })
}
}
if (options.verification) {
await verify(
Expand All @@ -99,7 +101,7 @@ async function executeDeploy(action: DeployAction, options: ExecuteOptions) {
options.verification.waffleConfig,
action.artifact[Name],
address,
new utils.Interface([action.constructor]).encodeDeploy(params),
action.constructor ? new utils.Interface([action.constructor]).encodeDeploy(params) : undefined,
options.network
)
}
Expand Down
25 changes: 22 additions & 3 deletions packages/mars/src/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,27 @@ async function getCompilerOptions(waffleConfigPath: string) {
}
}

async function isContractVerified(etherscanApiKey: string, address: string, network?: string) {
const response = (
await axios.get(
`${etherscanUrl(network)}?${querystring.stringify({
module: 'contract',
action: 'getabi',
apikey: etherscanApiKey,
address,
})}`
)
).data
return response?.status === '1'
}

async function getVerificationRequestBody(
etherscanApiKey: string,
waffleConfigPath: string,
jsonInput: any,
address: string,
contractName: string,
constructorArgs: string
constructorArgs?: string
) {
const waffleConfig = await getCompilerOptions(waffleConfigPath)
const inputWithOptions = {
Expand All @@ -135,7 +149,7 @@ async function getVerificationRequestBody(
codeformat: 'solidity-standard-json-input',
contractname: `${contractName}.sol:${contractName}`,
compilerversion: waffleConfig.compilerVersion,
constructorArguements: constructorArgs.slice(2),
constructorArguements: constructorArgs?.slice(2) ?? '',
licenseType: '1',
})
return body
Expand Down Expand Up @@ -205,12 +219,17 @@ export async function verify(
waffleConfigPath: string,
contractName: string,
address: string,
constructorArgs: string,
constructorArgs?: string,
network?: string
) {
const jsonInput = jsonInputs[contractName]
if (!jsonInput) {
console.log(chalk.bold(chalk.yellow(`No sources found for ${contractName}. Skipping\n`)))
return
}
if (await isContractVerified(etherscanApiKey, address, network)) {
console.log(chalk.bold(chalk.green(`Contract ${contractName} is already verified under ${address}. Skipping\n`)))
return
}
console.log(chalk.green(`Verifying ${contractName} on Etherscan`))
try {
Expand Down

0 comments on commit 3fdec04

Please sign in to comment.