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

feat: verify contracts on filfox #151

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion axelar-chains-config/info/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,8 @@
},
"confirmations": 3,
"explorer": {
"url": "https://www.filfox.info"
"url": "https://www.filfox.info",
"api": "https://filfox.info/api/v1/tools/verifyContract"
},
"gasOptions": {
"gasLimit": 500000000
Expand Down
3 changes: 2 additions & 1 deletion axelar-chains-config/info/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,8 @@
}
},
"explorer": {
"url": "https://calibration.filfox.info"
"url": "https://calibration.filfox.info",
"api": "https://calibration.filfox.info/api/v1/tools/verifyContract"
},
"gasOptions": {
"gasLimit": 300000000
Expand Down
2 changes: 1 addition & 1 deletion evm/nonces.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@
"0x027c1882B975E2cd771AE068b0389FA38B9dda73": 0
}
}
}
}
85 changes: 85 additions & 0 deletions evm/verify-filfox.js
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) {
Copy link
Member

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)

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 = '';
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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();
}
Loading