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

pull/3519/head
Paul Balaji 8 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 {
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<any>((result, chain) => {
const serializer = (env: HyperlaneEnvironment) =>
Object.keys(hyperlaneEnvironments[env]).reduce<any>((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');
}
},
};

Loading…
Cancel
Save