feat: CLI chain list derived from SDK contract addresses artifact (#3514)

pull/3519/head
Paul Balaji 7 months ago committed by GitHub
parent ff6b06079e
commit 3ec81081c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      .changeset/cuddly-ravens-run.md
  2. 54
      typescript/cli/src/commands/chains.ts

@ -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.

@ -3,10 +3,10 @@ import { CommandModule } from 'yargs';
import { import {
Chains, Chains,
CoreChainName, CoreChainName,
Mainnets, HyperlaneEnvironment,
Testnets,
chainMetadata, chainMetadata,
hyperlaneContractAddresses, hyperlaneContractAddresses,
hyperlaneEnvironments,
} from '@hyperlane-xyz/sdk'; } from '@hyperlane-xyz/sdk';
import { log, logBlue, logGray, logTable } from '../logger.js'; import { log, logBlue, logGray, logTable } from '../logger.js';
@ -33,44 +33,36 @@ const listCommand: CommandModule = {
command: 'list', command: 'list',
describe: 'List all core chains included in the Hyperlane SDK', describe: 'List all core chains included in the Hyperlane SDK',
builder: (yargs) => builder: (yargs) =>
yargs yargs.option('environment', {
.option('mainnet', { alias: 'e',
alias: 'm', describe: 'Specify the environment to list chains for',
describe: 'Only list mainnet chains', choices: ['mainnet', 'testnet'],
}) }),
.option('testnet', {
alias: 't',
describe: 'Only list testnet chains',
})
.conflicts('mainnet', 'testnet'),
handler: (args) => { handler: (args) => {
const mainnet = args.mainnet as string | undefined; const environment = args.environment as HyperlaneEnvironment | undefined;
const testnet = args.testnet as string | undefined;
const serializer = (chains: string[]) => const serializer = (env: HyperlaneEnvironment) =>
chains.reduce<any>((result, chain) => { Object.keys(hyperlaneEnvironments[env]).reduce<any>((result, chain) => {
const { chainId, displayName } = chainMetadata[chain];
result[chain] = { result[chain] = {
'Display Name': chainMetadata[chain].displayName, 'Display Name': displayName,
'Chain Id': chainMetadata[chain].chainId, 'Chain Id': chainId,
}; };
return result; return result;
}, {}); }, {});
const logMainnet = () => {
logBlue('\nHyperlane core mainnet chains:'); const logChainsForEnv = (env: HyperlaneEnvironment) => {
logGray('------------------------------'); logBlue(`\nHyperlane core ${env} chains:`);
logTable(serializer(Mainnets));
};
const logTestnet = () => {
logBlue('\nHyperlane core testnet chains:');
logGray('------------------------------'); logGray('------------------------------');
logTable(serializer(Testnets)); logTable(serializer(env));
}; };
if (mainnet) return logMainnet(); if (environment) {
else if (testnet) return logTestnet(); logChainsForEnv(environment);
} else {
logMainnet(); logChainsForEnv('mainnet');
logTestnet(); logChainsForEnv('testnet');
}
}, },
}; };

Loading…
Cancel
Save