-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: verify contracts on filfox #151
base: main
Are you sure you want to change the base?
Changes from 1 commit
3737a02
9d05fdb
a5ba958
5d4cb80
28cdbfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,4 +139,4 @@ | |
"0x027c1882B975E2cd771AE068b0389FA38B9dda73": 0 | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const axios = require('axios'); | ||
const fs = require('fs'); | ||
const { Command, Option } = require('commander'); | ||
const { addBaseOptions } = require('./cli-utils'); | ||
const { validateParameters, loadConfig, printInfo, printError } = require('./utils'); | ||
|
||
async function verifyFilfox(options) { | ||
const { env, address, contractName, contractPath, compilerVersion, optimizeRuns } = options; | ||
|
||
validateParameters({ | ||
isValidAddress: { address }, | ||
isNonEmptyString: { contractName, contractPath, compilerVersion }, | ||
isValidNumber: { optimizeRuns }, | ||
}); | ||
|
||
const sourceFiles = { | ||
[`${contractName}.sol`]: { | ||
content: fs.readFileSync(contractPath, 'utf8'), | ||
}, | ||
}; | ||
|
||
const optimizerDetails = ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are the optimizerDetails and some other fields empty? Our current config has the optimizer details. Are these fields not necessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I agree, was having some trouble importing the configurations from the hardhat config in other repositories |
||
const license = 'MIT License (MIT)'; | ||
const evmVersion = 'london'; | ||
const libraries = ''; | ||
const metadata = ''; | ||
|
||
const data = { | ||
address, | ||
language: 'Solidity', | ||
compiler: compilerVersion, | ||
optimize: true, | ||
optimizeRuns, | ||
optimizerDetails, | ||
sourceFiles, | ||
license, | ||
evmVersion, | ||
viaIR: false, | ||
libraries, | ||
metadata, | ||
}; | ||
|
||
const config = loadConfig(env); | ||
const api = config.chains.filecoin.explorer?.api; | ||
|
||
if (!api) { | ||
throw new Error(`Explorer API not present for filecoin ${env}`); | ||
} | ||
|
||
try { | ||
const response = await axios.post(api, data, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
printInfo('Verification successful', JSON.stringify(response.data)); | ||
} catch (error) { | ||
printError('Error during verification', JSON.stringify(error.response.data)); | ||
} | ||
} | ||
|
||
async function main(options) { | ||
await verifyFilfox(options); | ||
} | ||
|
||
if (require.main === module) { | ||
const program = new Command(); | ||
|
||
program.name('verify-filfox').description('Verify contracts on filfox explorer for filecoin network'); | ||
|
||
addBaseOptions(program, { ignorePrivateKey: true, ignoreChainNames: true, address: true }); | ||
|
||
program.addOption(new Option('-c, --contractName <contractName>', 'contract name')); | ||
program.addOption(new Option('-p, --contractPath <contractPath>', 'flattened contract file path with respect to project root')); | ||
program.addOption(new Option('--configPath <configPath>', 'hardhat config path with respect to project root')); | ||
program.addOption(new Option('--compilerVersion <compilerVersion>', 'compiler version used to compile contract')); | ||
program.addOption(new Option('--optimizeRuns <optimizeRuns>', 'optimize runs used during contract compilation')); | ||
|
||
program.action((options) => { | ||
main(options); | ||
}); | ||
|
||
program.parse(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be integrated into our normal verifyContract method. If chain is filecoin then call this helper method with appropriate data. you can look into how the existing verify method extracts the compiler version/optimizer runs to do the same (maybe even import that method if possible from hardhat-verify)