From 3ec81081c60e53083035bde2094384e4c449f9f8 Mon Sep 17 00:00:00 2001 From: Paul Balaji Date: Thu, 28 Mar 2024 18:30:33 +0000 Subject: [PATCH] feat: CLI chain list derived from SDK contract addresses artifact (#3514) --- .changeset/cuddly-ravens-run.md | 7 ++++ typescript/cli/src/commands/chains.ts | 54 ++++++++++++--------------- 2 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 .changeset/cuddly-ravens-run.md diff --git a/.changeset/cuddly-ravens-run.md b/.changeset/cuddly-ravens-run.md new file mode 100644 index 0000000000..29455106e6 --- /dev/null +++ b/.changeset/cuddly-ravens-run.md @@ -0,0 +1,7 @@ +--- +'@hyperlane-xyz/cli': minor +--- + +Breaking: Update the `hyperlane chains list` command to accept an `env` (either 'mainnet' or 'testnet') to list chains for. + +Update `hyperlane chains list` command to pull the set of core chains from the contract addresses constant in the SDK. diff --git a/typescript/cli/src/commands/chains.ts b/typescript/cli/src/commands/chains.ts index dc495f9875..938f6219e6 100644 --- a/typescript/cli/src/commands/chains.ts +++ b/typescript/cli/src/commands/chains.ts @@ -3,10 +3,10 @@ import { CommandModule } from 'yargs'; import { Chains, CoreChainName, - Mainnets, - Testnets, + HyperlaneEnvironment, chainMetadata, hyperlaneContractAddresses, + hyperlaneEnvironments, } from '@hyperlane-xyz/sdk'; import { log, logBlue, logGray, logTable } from '../logger.js'; @@ -33,44 +33,36 @@ const listCommand: CommandModule = { command: 'list', describe: 'List all core chains included in the Hyperlane SDK', builder: (yargs) => - yargs - .option('mainnet', { - alias: 'm', - describe: 'Only list mainnet chains', - }) - .option('testnet', { - alias: 't', - describe: 'Only list testnet chains', - }) - .conflicts('mainnet', 'testnet'), + yargs.option('environment', { + alias: 'e', + describe: 'Specify the environment to list chains for', + choices: ['mainnet', 'testnet'], + }), handler: (args) => { - const mainnet = args.mainnet as string | undefined; - const testnet = args.testnet as string | undefined; + const environment = args.environment as HyperlaneEnvironment | undefined; - const serializer = (chains: string[]) => - chains.reduce((result, chain) => { + const serializer = (env: HyperlaneEnvironment) => + Object.keys(hyperlaneEnvironments[env]).reduce((result, chain) => { + const { chainId, displayName } = chainMetadata[chain]; result[chain] = { - 'Display Name': chainMetadata[chain].displayName, - 'Chain Id': chainMetadata[chain].chainId, + 'Display Name': displayName, + 'Chain Id': chainId, }; return result; }, {}); - const logMainnet = () => { - logBlue('\nHyperlane core mainnet chains:'); - logGray('------------------------------'); - logTable(serializer(Mainnets)); - }; - const logTestnet = () => { - logBlue('\nHyperlane core testnet chains:'); + + const logChainsForEnv = (env: HyperlaneEnvironment) => { + logBlue(`\nHyperlane core ${env} chains:`); logGray('------------------------------'); - logTable(serializer(Testnets)); + logTable(serializer(env)); }; - if (mainnet) return logMainnet(); - else if (testnet) return logTestnet(); - - logMainnet(); - logTestnet(); + if (environment) { + logChainsForEnv(environment); + } else { + logChainsForEnv('mainnet'); + logChainsForEnv('testnet'); + } }, };