Skip to content

Commit

Permalink
Merge branch 'main' into chore/merge-deploy-test-into-deploy-contract
Browse files Browse the repository at this point in the history
  • Loading branch information
npty authored Jul 29, 2024
2 parents ab5d5c3 + 14654c3 commit 4ac2eae
Show file tree
Hide file tree
Showing 5 changed files with 429 additions and 390 deletions.
87 changes: 87 additions & 0 deletions common/cli-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use strict';

require('dotenv').config();

const { Option } = require('commander');

const addBaseOptions = (program, options = {}) => {
program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'devnet-amplifier', 'devnet-verifiers', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
);
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));
program.addOption(new Option('--parallel', 'run script parallely wrt chains'));
program.addOption(new Option('--saveChainSeparately', 'save chain info separately'));
program.addOption(new Option('--gasOptions <gasOptions>', 'gas options cli override'));

if (!options.ignoreChainNames) {
program.addOption(
new Option('-n, --chainNames <chainNames>', 'chains to run the script over').makeOptionMandatory(true).env('CHAINS'),
);
program.addOption(new Option('--skipChains <skipChains>', 'chains to skip over'));
program.addOption(
new Option(
'--startFromChain <startFromChain>',
'start from a specific chain onwards in the config, useful when a cmd fails for an intermediate chain',
),
);
}

if (!options.ignorePrivateKey) {
program.addOption(new Option('-p, --privateKey <privateKey>', 'private key').makeOptionMandatory(true).env('PRIVATE_KEY'));
}

if (options.address) {
program.addOption(new Option('-a, --address <address>', 'override address'));
}

return program;
};

const addExtendedOptions = (program, options = {}) => {
addBaseOptions(program, options);

program.addOption(new Option('-v, --verify', 'verify the deployed contract on the explorer').env('VERIFY'));

if (options.artifactPath) {
program.addOption(new Option('--artifactPath <artifactPath>', 'artifact path'));
}

if (options.contractName) {
program.addOption(new Option('-c, --contractName <contractName>', 'contract name').makeOptionMandatory(true));
}

if (options.deployMethod) {
program.addOption(
new Option('-m, --deployMethod <deployMethod>', 'deployment method')
.choices(['create', 'create2', 'create3'])
.default(options.deployMethod),
);
}

if (options.salt) {
program.addOption(new Option('-s, --salt <salt>', 'salt to use for create2 deployment').env('SALT'));
}

if (options.skipExisting) {
program.addOption(new Option('-x, --skipExisting', 'skip existing if contract was already deployed on chain').env('SKIP_EXISTING'));
}

if (options.upgrade) {
program.addOption(new Option('-u, --upgrade', 'upgrade a deployed contract').env('UPGRADE'));
}

if (options.predictOnly) {
program.addOption(new Option('--predictOnly', 'output the predicted changes only').env('PREDICT_ONLY'));
}

return program;
};

module.exports = {
addBaseOptions,
addExtendedOptions,
};
4 changes: 4 additions & 0 deletions common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
...require('./cli-utils'),
...require('./utils'),
};
Loading

0 comments on commit 4ac2eae

Please sign in to comment.