Skip to content

Commit

Permalink
feat: script optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Amiel committed Oct 31, 2023
1 parent 9e87c68 commit 1c1282c
Show file tree
Hide file tree
Showing 22 changed files with 182 additions and 242 deletions.
12 changes: 3 additions & 9 deletions evm/balances.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require('dotenv').config();
const { ethers } = require('hardhat');
const { getDefaultProvider } = ethers;
const { Command, Option } = require('commander');
const { mainProcessor, printWalletInfo, printInfo } = require('./utils');
const { mainProcessor, printWalletInfo, printInfo, addEnvironmentOptions } = require('./utils');
const { getWallet } = require('./sign-utils');

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

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'));
addEnvironmentOptions(program);

program.addOption(new Option('-p, --privateKey <privateKey>', 'private key').makeOptionMandatory(true).env('PRIVATE_KEY'));

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

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

async function processCommand(config, _, options, file) {
Expand Down Expand Up @@ -76,13 +76,7 @@ const program = new Command();
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'),
);
addEnvironmentOptions(program, true);
program.addOption(new Option('-r, --rpc <rpc>', 'The chain rpc'));
program.addOption(new Option('-y, --yes', 'skip prompts'));

Expand Down
12 changes: 3 additions & 9 deletions evm/check-wallet-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { Command, Option } = require('commander');
const { ethers } = require('hardhat');
const { getDefaultProvider, BigNumber } = ethers;

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

async function processCommand(_, chain, options) {
Expand Down Expand Up @@ -51,14 +51,8 @@ const program = new Command();

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));
addEnvironmentOptions(program);

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'));

Expand Down
15 changes: 3 additions & 12 deletions evm/deploy-const-address-deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const readlineSync = require('readline-sync');
const { Command, Option } = require('commander');
const chalk = require('chalk');

const { printInfo, writeJSON, predictAddressCreate, deployCreate } = require('./utils');
const { printInfo, writeJSON, predictAddressCreate, deployCreate, addDeploymentOptions } = require('./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 +125,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));
program.addOption(new Option('-p, --privateKey <privateKey>', 'private key').makeOptionMandatory(true).env('PRIVATE_KEY'));
addDeploymentOptions(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
66 changes: 49 additions & 17 deletions evm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,47 @@ const {
prompt,
mainProcessor,
isContract,
addDeploymentOptions,
} = require('./utils');

function getContractPath(contractName) {
switch (contractName) {
case 'AxelarServiceGovernance': {
return '@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/governance/AxelarServiceGovernance.sol/AxelarServiceGovernance.json';
}

case 'InterchainProposalSender': {
throw new Error(`Artifact path for ${contractName} must be entered manually.`);
}

case 'InterchainGovernance': {
return '@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/governance/InterchainGovernance.sol/InterchainGovernance.json';
}

case 'Multisig': {
return '@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/governance/Multisig.sol/Multisig.json';
}

case 'Operators': {
return '@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/utils/Operators.sol/Operators.json';
}

case 'ConstAddressDeployer': {
return '@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/deploy/ConstAddressDeployer.sol/ConstAddressDeployer.json';
}

case 'Create3Deployer': {
return '@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/deploy/Create3Deployer.sol/Create3Deployer.json';
}

case 'TokenDeployer': {
return '@axelar-network/axelar-cgp-solidity/artifacts/contracts/TokenDeployer.sol/TokenDeployer.json';
}
}

throw new Error(`${contractName} is not supported.`);
}

async function getConstructorArgs(contractName, chain, wallet, options) {
const config = chain.contracts;
const contractConfig = config[contractName];
Expand Down Expand Up @@ -250,7 +289,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);
Expand Down Expand Up @@ -340,25 +386,11 @@ 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'));
program.addOption(new Option('--skipChains <skipChains>', 'chains to skip over'));
addDeploymentOptions(program, true, true, true, true, true);

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) => {
Expand Down
17 changes: 3 additions & 14 deletions evm/deploy-create3-deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ 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 { printInfo, writeJSON, deployCreate2, addDeploymentOptions } = require('./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 +94,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'));
addDeploymentOptions(program, false, false, 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 @@ -16,6 +16,7 @@ const {
isAddressArray,
isNumber,
prompt,
addDeploymentOptions,
} = require('./utils');
const { ethers } = require('hardhat');
const {
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'));
addDeploymentOptions(program, false, false, false, false, true, 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
18 changes: 3 additions & 15 deletions evm/deploy-gateway-v6.2.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
mainProcessor,
isContract,
deployContract,
addDeploymentOptions,
} = require('./utils');
const { storeSignedTx, signTransaction, getWallet } = require('./sign-utils.js');

Expand Down Expand Up @@ -478,22 +479,12 @@ async function programHandler() {

program.name('deploy-gateway-v6.2.x').description('Deploy gateway v6.2.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, --chainNames <chainNames>', 'chains to run the script over').makeOptionMandatory(true).env('CHAINS'));
program.addOption(new Option('--skipChains <skipChains>', 'chains to skip over'));
addDeploymentOptions(program, false, false, true, true, true, 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('--deployMethod <deployMethod>', 'deployment method').choices(['create', 'create2', 'create3']).default('create'),
);
program.addOption(new Option('-s, --salt <salt>', 'salt to use for deployment method'));
program.addOption(new Option('-v, --verify', 'verify the deployed contract on the explorer').env('VERIFY'));
program.addOption(new Option('-r, --reuseProxy', 'reuse proxy contract modules for new implementation deployment').env('REUSE_PROXY'));
program.addOption(
new Option('--reuseHelpers', 'reuse helper auth and token deployer contract modules for new implementation deployment').env(
Expand All @@ -503,14 +494,11 @@ async function programHandler() {
program.addOption(new Option('--ignoreError', 'Ignore deployment errors and proceed to next chain'));
program.addOption(new Option('-g, --governance <governance>', 'governance address').env('GOVERNANCE'));
program.addOption(new Option('-m, --mintLimiter <mintLimiter>', 'mint limiter address').env('MINT_LIMITER'));
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));
program.addOption(new Option('-k, --keyID <keyID>', 'key ID').env('KEY_ID'));
program.addOption(new Option('-a, --amplifier', 'deploy amplifier gateway').env('AMPLIFIER'));
program.addOption(new Option('--prevKeyIDs <prevKeyIDs>', 'previous key IDs to be used for auth contract'));
program.addOption(new Option('-u, --upgrade', 'upgrade gateway').env('UPGRADE'));
program.addOption(new Option('--offline', 'Run in offline mode'));
program.addOption(new Option('--nonceOffset <nonceOffset>', 'The value to add in local nonce if it deviates from actual wallet nonce'));
program.addOption(new Option('-x, --skipExisting', 'skip existing if contract was already deployed on chain'));

program.action((options) => {
main(options);
Expand Down
16 changes: 3 additions & 13 deletions evm/deploy-its.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
} = ethers;
const readlineSync = require('readline-sync');
const chalk = require('chalk');
const { printInfo, loadConfig, saveConfig } = require('./utils');
const { printInfo, loadConfig, saveConfig, addDeploymentOptions } = require('./utils');

const TokenManagerDeployer = require('@axelar-network/interchain-token-service/dist/utils/TokenManagerDeployer.sol/TokenManagerDeployer.json');
const StandardizedTokenLockUnlock = require('@axelar-network/interchain-token-service/dist/token-implementations/StandardizedTokenLockUnlock.sol/StandardizedTokenLockUnlock.json');
Expand Down Expand Up @@ -362,20 +362,10 @@ if (require.main === module) {

program.name('deploy-its').description('Deploy interchain token service');

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'));
addDeploymentOptions(program, false, false, false, false, true, true);

program.addOption(new Option('-s, --salt <key>', 'deployment salt to use for ITS deployment').makeOptionMandatory(true).env('SALT'));
program.addOption(new Option('-v, --verify <verify>', 'verify the deployed contract on the explorer [true|false|only]').env('VERIFY'));
program.addOption(new Option('-x, --skipExisting <boolean>', 'skip deploying contracts if they already exist').env('SKIP_EXISTING'));
program.addOption(new Option('-o, --operator', 'address of the ITS operator').env('OPERATOR_ADDRESS'));
program.addOption(new Option('-u, --upgrade', 'upgrade ITS').env('UPGRADE'));

program.action(async (options) => {
options.skipExisting = options.skipExisting === 'true';
Expand Down
Loading

0 comments on commit 1c1282c

Please sign in to comment.