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: script optimizations #99

Merged
merged 8 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 3 additions & 10 deletions evm/balances.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ require('dotenv').config();

const { ethers } = require('hardhat');
const { getDefaultProvider } = ethers;
const { Command, Option } = require('commander');
const { Command } = require('commander');
const { mainProcessor, printWalletInfo, printInfo } = require('./utils');
const { addBaseOptions } = require('./cli-utils');
const { getWallet } = require('./sign-utils');

async function processCommand(_, chain, options) {
Expand All @@ -26,15 +27,7 @@ if (require.main === module) {

milapsheth marked this conversation as resolved.
Show resolved Hide resolved
program.name('balances').description('Display balance of the wallet on specified chains.');

program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
);
program.addOption(new Option('-n, --chainNames <chainNames>', 'chain names').makeOptionMandatory(true).env('CHAINS'));
program.addOption(new Option('-p, --privateKey <privateKey>', 'private key').makeOptionMandatory(true).env('PRIVATE_KEY'));
addBaseOptions(program);

program.action((options) => {
main(options);
Expand Down
28 changes: 12 additions & 16 deletions evm/broadcast-transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
} = ethers;

const { printError, printInfo, printWarn, getConfigByChainId, prompt, loadConfig } = require('./utils');
const { addBaseOptions } = require('./cli-utils');
const { sendTransaction, getSignedTx, storeSignedTx } = require('./sign-utils');

async function processCommand(config, _, options, file) {
Expand Down Expand Up @@ -71,23 +72,18 @@ async function main(options) {
}
}

const program = new Command();
if (require.main === module) {
const program = new Command();

program.name('broadcast-transactions').description('Broadcast all the pending signed transactions of the signer');
program.name('broadcast-transactions').description('Broadcast all the pending signed transactions of the signer');

program.addOption(new Option('--files [files...]', 'The file where the signed tx are stored').makeOptionMandatory(true));
program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
);
program.addOption(new Option('-r, --rpc <rpc>', 'The chain rpc'));
program.addOption(new Option('-y, --yes', 'skip prompts'));
program.addOption(new Option('--files [files...]', 'The file where the signed tx are stored').makeOptionMandatory(true));
addBaseOptions(program, { ignoreChainNames: true });
program.addOption(new Option('-r, --rpc <rpc>', 'The chain rpc'));

program.action((options) => {
main(options);
});
program.action((options) => {
main(options);
});

program.parse();
program.parse();
}
29 changes: 13 additions & 16 deletions evm/check-wallet-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { ethers } = require('hardhat');
const { getDefaultProvider, BigNumber } = ethers;

const { printError, mainProcessor } = require('./utils');
const { addBaseOptions } = require('./cli-utils');
const { getNonceFileData } = require('./sign-utils');

async function processCommand(_, chain, options) {
Expand Down Expand Up @@ -47,23 +48,19 @@ async function main(options) {
await mainProcessor(options, processCommand);
}

const program = new Command();
if (require.main === module) {
const program = new Command();

program.name('check-wallet-balance').description('Before offline signing checks if each signer has minimum required wallet balance');
program.name('check-wallet-balance').description('Before offline signing checks if each signer has minimum required wallet balance');

program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
);
program.addOption(new Option('-n, --chainNames <chainNames>', 'chain names').makeOptionMandatory(true));
program.addOption(new Option('-r, --rpc <rpc>', 'The rpc url for creating a provider to fetch gasOptions'));
program.addOption(new Option('--addresses <addresses>', 'The Array of addresses for which the balance to check').env('ADDRESSES'));
addBaseOptions(program, { ignorePrivateKey: true });

program.action((options) => {
main(options);
});
program.addOption(new Option('-r, --rpc <rpc>', 'The rpc url for creating a provider to fetch gasOptions'));
program.addOption(new Option('--addresses <addresses>', 'The Array of addresses for which the balance to check').env('ADDRESSES'));

program.parse();
program.action((options) => {
main(options);
});

program.parse();
}
54 changes: 54 additions & 0 deletions evm/cli-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

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

const addBaseOptions = (program, options = {}) => {
program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
);
program.addOption(new Option('--skipChains <skipChains>', 'chains to skip over'));
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));

if (!options.ignoreChainNames) {
program.addOption(
new Option('-n, --chainNames <chainNames>', 'chains to run the script over').makeOptionMandatory(true).env('CHAINS'),
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
);
}

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('-a, --artifactPath <artifactPath>', 'artifact path'));
if (options.contractName) program.addOption(new Option('-c, --contractName <contractName>', 'contract name').makeOptionMandatory(true));
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'));
milapsheth marked this conversation as resolved.
Show resolved Hide resolved

return program;
};

module.exports = {
addBaseOptions,
addExtendedOptions,
};
14 changes: 3 additions & 11 deletions evm/deploy-const-address-deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { Command, Option } = require('commander');
const chalk = require('chalk');

const { printInfo, writeJSON, predictAddressCreate, deployCreate } = require('./utils');
const { addExtendedOptions } = require('./cli-utils');
const contractJson = require('@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/deploy/ConstAddressDeployer.sol/ConstAddressDeployer.json');
const contractName = 'ConstAddressDeployer';

Expand Down Expand Up @@ -125,19 +126,10 @@ if (require.main === module) {

program.name('deploy-const-address-deployer').description('Deploy const address deployer');

program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
);
program.addOption(new Option('-n, --chainNames <chainNames>', 'chain names').makeOptionMandatory(true));
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
program.addOption(new Option('-p, --privateKey <privateKey>', 'private key').makeOptionMandatory(true).env('PRIVATE_KEY'));
addExtendedOptions(program);

program.addOption(new Option('-i, --ignore', 'ignore the nonce value check'));
program.addOption(new Option('-v, --verify', 'verify the deployed contract on the explorer').env('VERIFY'));
program.addOption(new Option('-f, --force', 'proceed with contract deployment even if address already returns a bytecode'));
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));

program.action((options) => {
main(options);
Expand Down
62 changes: 29 additions & 33 deletions evm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {
utils: { isAddress, keccak256, toUtf8Bytes },
} = ethers;
const { Command, Option } = require('commander');

const {
printInfo,
printWarn,
Expand All @@ -26,9 +25,11 @@ const {
prompt,
mainProcessor,
isContract,
getContractPath,
} = require('./utils');
const { addExtendedOptions } = require('./cli-utils');

async function getConstructorArgs(contractName, chain, wallet, options) {
async function getConstructorArgs(contractName, chain, wallet) {
const config = chain.contracts;
const contractConfig = config[contractName];

Expand Down Expand Up @@ -250,7 +251,14 @@ async function processCommand(config, chain, options) {

printInfo('Contract name', contractName);

const contractPath = artifactPath.charAt(0) === '@' ? artifactPath : artifactPath + contractName + '.sol/' + contractName + '.json';
let contractPath;

if (artifactPath) {
contractPath = artifactPath.charAt(0) === '@' ? artifactPath : artifactPath + contractName + '.sol/' + contractName + '.json';
} else {
contractPath = getContractPath(contractName);
}

printInfo('Contract path', contractPath);

const contractJson = require(contractPath);
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -336,33 +344,21 @@ async function main(options) {
await mainProcessor(options, processCommand);
}

const program = new Command();

program.name('deploy-contract').description('Deploy contracts using create, create2, or create3');

program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
);
program.addOption(new Option('-a, --artifactPath <artifactPath>', 'artifact path').makeOptionMandatory(true));
program.addOption(new Option('-c, --contractName <contractName>', 'contract name').makeOptionMandatory(true));
program.addOption(new Option('-n, --chainNames <chainNames>', 'chain names').makeOptionMandatory(true).env('CHAINS'));
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
program.addOption(new Option('--skipChains <skipChains>', 'chains to skip over'));
program.addOption(
new Option('-m, --deployMethod <deployMethod>', 'deployment method').choices(['create', 'create2', 'create3']).default('create2'),
);
program.addOption(new Option('-p, --privateKey <privateKey>', 'private key').makeOptionMandatory(true).env('PRIVATE_KEY'));
program.addOption(new Option('-s, --salt <salt>', 'salt to use for create2 deployment'));
program.addOption(new Option('-v, --verify <verify>', 'verify the deployed contract on the explorer').env('VERIFY'));
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));
program.addOption(new Option('-x, --skipExisting', 'skip existing if contract was already deployed on chain'));
program.addOption(new Option('--ignoreError', 'ignore errors during deployment for a given chain'));

program.action((options) => {
main(options);
});

program.parse();
if (require.main === module) {
const program = new Command();

program.name('deploy-contract').description('Deploy contracts using create, create2, or create3');

addExtendedOptions(program, { artifactPath: true, contractName: true, salt: true, skipChains: true, skipExisting: true });

program.addOption(
new Option('-m, --deployMethod <deployMethod>', 'deployment method').choices(['create', 'create2', 'create3']).default('create2'),
);
program.addOption(new Option('--ignoreError', 'ignore errors during deployment for a given chain'));

program.action((options) => {
main(options);
});

program.parse();
}
16 changes: 3 additions & 13 deletions evm/deploy-create3-deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ const { ethers } = require('hardhat');
const { Wallet, getDefaultProvider } = ethers;
const readlineSync = require('readline-sync');
const { predictContractConstant } = require('@axelar-network/axelar-gmp-sdk-solidity');
const { Command, Option } = require('commander');
const { Command } = require('commander');
const chalk = require('chalk');

const { printInfo, writeJSON, deployCreate2 } = require('./utils');
const { addExtendedOptions } = require('./cli-utils');
const contractJson = require('@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/deploy/Create3Deployer.sol/Create3Deployer.json');
const { deployConstAddressDeployer } = require('./deploy-const-address-deployer');
const contractName = 'Create3Deployer';
Expand Down Expand Up @@ -94,18 +95,7 @@ if (require.main === module) {

program.name('deploy-create3-deployer').description('Deploy create3 deployer');

program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
);
program.addOption(new Option('-n, --chainNames <chainNames>', 'chain names').makeOptionMandatory(true));
program.addOption(new Option('-p, --privateKey <privateKey>', 'private key').makeOptionMandatory(true).env('PRIVATE_KEY'));
program.addOption(new Option('-s, --salt <salt>', 'salt to use for create2 deployment'));
program.addOption(new Option('-v, --verify <verify>', 'verify the deployed contract on the explorer').env('VERIFY'));
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));
addExtendedOptions(program, { salt: true });

program.action((options) => {
main(options);
Expand Down
16 changes: 3 additions & 13 deletions evm/deploy-gateway-v4.3.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
isNumber,
prompt,
} = require('./utils');
const { addExtendedOptions } = require('./cli-utils');
const { ethers } = require('hardhat');
const {
getContractFactory,
Expand Down Expand Up @@ -311,22 +312,11 @@ async function programHandler() {

program.name('deploy-gateway-v4.3.x').description('Deploy gateway v4.3.x');

program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'stagenet', 'testnet', 'mainnet'])
.default('testnet')
.makeOptionMandatory(true)
.env('ENV'),
);
program.addOption(new Option('-n, --chainName <chainName>', 'chain name').makeOptionMandatory(true).env('CHAIN'));
addExtendedOptions(program, { skipExisting: true, upgrade: true });

program.addOption(new Option('-r, --rpc <rpc>', 'chain rpc url').env('URL'));
program.addOption(new Option('-p, --privateKey <privateKey>', 'private key').makeOptionMandatory(true).env('PRIVATE_KEY'));
program.addOption(new Option('-v, --verify', 'verify the deployed contract on the explorer').env('VERIFY'));
program.addOption(new Option('-x, --skipExisting', 'skip deployment for existing contracts in the info files').env('SKIP_EXISTING'));
program.addOption(new Option('-a, --adminAddresses <adminAddresses>', 'admin addresses').env('ADMIN_ADDRESSES'));
program.addOption(new Option('-t, --adminThreshold <adminThreshold>', 'admin threshold').env('ADMIN_THRESHOLD'));
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));
program.addOption(new Option('-u, --upgrade', 'upgrade gateway').env('UPGRADE'));

program.action((options) => {
main(options);
Expand Down
Loading
Loading