Skip to content

Commit

Permalink
feat: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Amiel committed Nov 4, 2023
1 parent f40357e commit 51baefe
Show file tree
Hide file tree
Showing 24 changed files with 427 additions and 397 deletions.
9 changes: 4 additions & 5 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 { mainProcessor, printWalletInfo, printInfo, addEnvironmentOptions } = require('./utils');
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,9 +27,7 @@ if (require.main === module) {

program.name('balances').description('Display balance of the wallet on specified chains.');

addEnvironmentOptions(program);

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

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

const { printError, printInfo, printWarn, getConfigByChainId, prompt, loadConfig, addEnvironmentOptions } = require('./utils');
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,17 +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));
addEnvironmentOptions(program, true);
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();
}
23 changes: 13 additions & 10 deletions evm/check-wallet-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const { Command, Option } = require('commander');
const { ethers } = require('hardhat');
const { getDefaultProvider, BigNumber } = ethers;

const { printError, mainProcessor, addEnvironmentOptions } = require('./utils');
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,17 +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');

addEnvironmentOptions(program);
addBaseOptions(program, { ignorePrivateKey: 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'));
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.action((options) => {
main(options);
});
program.action((options) => {
main(options);
});

program.parse();
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'),
);
}

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

return program;
};

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

const { printInfo, writeJSON, predictAddressCreate, deployCreate, addDeploymentOptions } = require('./utils');
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,7 +126,7 @@ if (require.main === module) {

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

addDeploymentOptions(program);
addExtendedOptions(program);

program.addOption(new Option('-i, --ignore', 'ignore the nonce value check'));
program.addOption(new Option('-f, --force', 'proceed with contract deployment even if address already returns a bytecode'));
Expand Down
68 changes: 16 additions & 52 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,48 +25,11 @@ const {
prompt,
mainProcessor,
isContract,
addDeploymentOptions,
getContractPath,
} = require('./utils');
const { addExtendedOptions } = require('./cli-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) {
async function getConstructorArgs(contractName, chain, wallet) {
const config = chain.contracts;
const contractConfig = config[contractName];

Expand Down Expand Up @@ -382,19 +344,21 @@ async function main(options) {
await mainProcessor(options, processCommand);
}

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

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

addDeploymentOptions(program, true, true, true, true, true);
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.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.action((options) => {
main(options);
});

program.parse();
program.parse();
}
5 changes: 3 additions & 2 deletions evm/deploy-create3-deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const { predictContractConstant } = require('@axelar-network/axelar-gmp-sdk-soli
const { Command } = require('commander');
const chalk = require('chalk');

const { printInfo, writeJSON, deployCreate2, addDeploymentOptions } = require('./utils');
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,7 +95,7 @@ if (require.main === module) {

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

addDeploymentOptions(program, false, false, true);
addExtendedOptions(program, { salt: true });

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

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

addDeploymentOptions(program, false, false, false, false, true, true);
addExtendedOptions(program, { skipExisting: true, upgrade: true });

program.addOption(new Option('-r, --rpc <rpc>', 'chain rpc url').env('URL'));
program.addOption(new Option('-a, --adminAddresses <adminAddresses>', 'admin addresses').env('ADMIN_ADDRESSES'));
Expand Down
4 changes: 2 additions & 2 deletions evm/deploy-gateway-v6.2.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const {
mainProcessor,
isContract,
deployContract,
addDeploymentOptions,
} = require('./utils');
const { addExtendedOptions } = require('./cli-utils');
const { storeSignedTx, signTransaction, getWallet } = require('./sign-utils.js');

const AxelarGatewayProxy = require('@axelar-network/axelar-cgp-solidity/artifacts/contracts/AxelarGatewayProxy.sol/AxelarGatewayProxy.json');
Expand Down Expand Up @@ -501,7 +501,7 @@ async function programHandler() {

program.name('deploy-gateway-v6.2.x').description('Deploy gateway v6.2.x');

addDeploymentOptions(program, false, false, true, true, true, true);
addExtendedOptions(program, { salt: true, skipChains: true, skipExisting: true, upgrade: true });

program.addOption(new Option('-r, --rpc <rpc>', 'chain rpc url').env('URL'));
program.addOption(
Expand Down
5 changes: 3 additions & 2 deletions evm/deploy-its.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const {
} = ethers;
const readlineSync = require('readline-sync');
const chalk = require('chalk');
const { printInfo, loadConfig, saveConfig, addDeploymentOptions } = require('./utils');
const { printInfo, loadConfig, saveConfig } = require('./utils');
const { addExtendedOptions } = require('./cli-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,7 +363,7 @@ if (require.main === module) {

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

addDeploymentOptions(program, false, false, false, false, true, true);
addExtendedOptions(program, { skipExisting: true, upgrade: true });

program.addOption(new Option('-s, --salt <key>', 'deployment salt to use for ITS deployment').makeOptionMandatory(true).env('SALT'));
program.addOption(new Option('-o, --operator', 'address of the ITS operator').env('OPERATOR_ADDRESS'));
Expand Down
36 changes: 15 additions & 21 deletions evm/deploy-upgradable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,8 @@ const IUpgradable = require('@axelar-network/axelar-gmp-sdk-solidity/interfaces/
const { Command, Option } = require('commander');

const { deployUpgradable, deployCreate2Upgradable, deployCreate3Upgradable, upgradeUpgradable } = require('./upgradable');
const {
printInfo,
printError,
saveConfig,
loadConfig,
printWalletInfo,
getDeployedAddress,
prompt,
addDeploymentOptions,
} = require('./utils');
const { printInfo, printError, saveConfig, loadConfig, printWalletInfo, getDeployedAddress, prompt } = require('./utils');
const { addExtendedOptions } = require('./cli-utils');

function getProxy(wallet, proxyAddress) {
return new Contract(proxyAddress, IUpgradable.abi, wallet);
Expand Down Expand Up @@ -309,19 +301,21 @@ async function main(options) {
}
}

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

program.name('deploy-upgradable').description('Deploy upgradable contracts');
program.name('deploy-upgradable').description('Deploy upgradable contracts');

addDeploymentOptions(program, true, true, true, true, false, true);
addExtendedOptions(program, { artifactPath: true, contractName: true, salt: true, skipChains: true, upgrade: true });

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

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

program.parse();
program.parse();
}
Loading

0 comments on commit 51baefe

Please sign in to comment.