Skip to content

Commit

Permalink
feat: CLI chain list derived from SDK contract addresses artifact (#3514
Browse files Browse the repository at this point in the history
)
  • Loading branch information
paulbalaji authored Mar 28, 2024
1 parent ff6b060 commit 3ec8108
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
7 changes: 7 additions & 0 deletions .changeset/cuddly-ravens-run.md
Original file line number Diff line number Diff line change
@@ -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.
54 changes: 23 additions & 31 deletions typescript/cli/src/commands/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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');
}
},
};

Expand Down

0 comments on commit 3ec8108

Please sign in to comment.