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

chore: convert hardcoded envs to dynamic values #343

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 15 additions & 6 deletions common/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

require('dotenv').config();

const { Option } = require('commander');
const fs = require('fs');
const { Option, Command } = require('commander');

// A path to the chain configuration files
const CHAIN_CONFIG_PATH = `${__dirname}/../axelar-chains-config/info`;

// A list of available chain environments which are the names of the files in the CHAIN_CONFIG_PATH
const CHAIN_ENVIRONMENTS = fs.readdirSync(CHAIN_CONFIG_PATH).map((chainName) => chainName.split('.')[0]);

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'),
new Option('-e, --env <env>', 'environment').choices(CHAIN_ENVIRONMENTS).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'));
Expand Down Expand Up @@ -81,7 +84,13 @@ const addExtendedOptions = (program, options = {}) => {
return program;
};

if (require.main === module) {
addBaseOptions(new Command());
}

module.exports = {
CHAIN_CONFIG_PATH,
CHAIN_ENVIRONMENTS,
addBaseOptions,
addExtendedOptions,
};
7 changes: 2 additions & 5 deletions cosmwasm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require('dotenv').config();
const { isNil } = require('lodash');

const { CHAIN_ENVIRONMENTS } = require('../common');
const { isNumber, printInfo, loadConfig, saveConfig, prompt } = require('../evm/utils');
const {
prepareWallet,
Expand Down Expand Up @@ -113,11 +114,7 @@ const programHandler = () => {
program.name('upload-contract').description('Upload CosmWasm contracts');

program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
new Option('-e, --env <env>', 'environment').choices(CHAIN_ENVIRONMENTS).default('testnet').makeOptionMandatory(true).env('ENV'),
);
program.addOption(new Option('-m, --mnemonic <mnemonic>', 'mnemonic').makeOptionMandatory(true).env('MNEMONIC'));
program.addOption(new Option('-a, --artifactPath <artifactPath>', 'artifact path').makeOptionMandatory(true).env('ARTIFACT_PATH'));
Expand Down
3 changes: 2 additions & 1 deletion cosmwasm/submit-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
governanceAddress,
} = require('./utils');
const { isNumber, saveConfig, loadConfig, printInfo, prompt } = require('../evm/utils');
const { CHAIN_ENVIRONMENTS } = require('../common');
const {
StoreCodeProposal,
StoreAndInstantiateContractProposal,
Expand Down Expand Up @@ -251,7 +252,7 @@ const programHandler = () => {
// TODO: combine deploy-contract and submit-proposal options to remove duplicates
program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'devnet-amplifier', 'devnet-verifiers', 'stagenet', 'testnet', 'mainnet'])
.choices(CHAIN_ENVIRONMENTS)
.default('devnet-amplifier')
.makeOptionMandatory(true)
.env('ENV'),
Expand Down
7 changes: 2 additions & 5 deletions stellar/balances.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { Command, Option } = require('commander');
const { getWallet } = require('./utils');
const { loadConfig } = require('../evm/utils');
const { CHAIN_ENVIRONMENTS } = require('../common');
require('./cli-utils');

async function processCommand(options, _, chain) {
Expand All @@ -13,11 +14,7 @@ if (require.main === module) {
program.name('balances').description('Wallet balance');

program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
new Option('-e, --env <env>', 'environment').choices(CHAIN_ENVIRONMENTS).default('testnet').makeOptionMandatory(true).env('ENV'),
);

program.addOption(new Option('-p, --privateKey <privateKey>', 'private key').makeOptionMandatory(true).env('PRIVATE_KEY'));
Expand Down
7 changes: 2 additions & 5 deletions stellar/generate-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { execSync } = require('child_process');
const { loadConfig } = require('../evm/utils');
const path = require('path');
const { getNetworkPassphrase } = require('./utils');
const { CHAIN_ENVIRONMENTS } = require('../common');
require('./cli-utils');

function processCommand(options, _, chain) {
Expand All @@ -28,11 +29,7 @@ function main() {
program.name('Generate TypeScript Bindings for Soroban contract').description('Generates TypeScript bindings for a Soroban contract.');

program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
new Option('-e, --env <env>', 'environment').choices(CHAIN_ENVIRONMENTS).default('testnet').makeOptionMandatory(true).env('ENV'),
);
program.addOption(new Option('--wasmPath <wasmPath>', 'path to the WASM file').makeOptionMandatory(true));
program.addOption(new Option('--contractId <contractId>', 'contract ID').makeOptionMandatory(true));
Expand Down
7 changes: 2 additions & 5 deletions stellar/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { Contract, Address, nativeToScVal } = require('@stellar/stellar-sdk');
const { Command, Option } = require('commander');
const { getWallet, prepareTransaction, buildTransaction, sendTransaction, estimateCost } = require('./utils');
const { loadConfig, printInfo, parseArgs, validateParameters } = require('../evm/utils');
const { CHAIN_ENVIRONMENTS } = require('../common');
require('./cli-utils');

async function processCommand(options, _, chain) {
Expand Down Expand Up @@ -116,11 +117,7 @@ if (require.main === module) {
program.name('operators').description('Operators contract management');

program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
new Option('-e, --env <env>', 'environment').choices(CHAIN_ENVIRONMENTS).default('testnet').makeOptionMandatory(true).env('ENV'),
npty marked this conversation as resolved.
Show resolved Hide resolved
);

program.addOption(new Option('-p, --privateKey <privateKey>', 'private key').makeOptionMandatory(true).env('PRIVATE_KEY'));
Expand Down
7 changes: 2 additions & 5 deletions sui/utils/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ require('dotenv').config();

const { Option, InvalidArgumentError } = require('commander');
const { getUnitAmount } = require('./amount-utils');
const { CHAIN_ENVIRONMENTS } = require('../../common');

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'),
new Option('-e, --env <env>', 'environment').choices(CHAIN_ENVIRONMENTS).default('testnet').makeOptionMandatory(true).env('ENV'),
);
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));
program.addOption(new Option('--gasOptions <gasOptions>', 'gas options cli override'));
Expand Down
Loading