Skip to content

Commit

Permalink
Address feedback from @yorhodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy committed Aug 6, 2023
1 parent ce5fbfc commit e914051
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 140 deletions.
18 changes: 9 additions & 9 deletions typescript/cli/examples/multisig-ism.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# A config for a multisig Interchain Security Module (ISM)
# Schema: https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/typescript/sdk/src/ism/types.ts
# Module types:
# UNUSED : 0
# ROUTING : 1
# AGGREGATION : 2
# LEGACY_MULTISIG : 3
# MERKLE_ROOT_MULTISIG : 4
# MESSAGE_ID_MULTISIG : 5
#
# Valid module types:
# routing
# aggregation
# legacy_multisig
# merkle_root_multisig
# message_id_multisig
---
anvil1:
type: 3 # ModuleType.LEGACY_MULTISIG
type: 'legacy_multisig'
threshold: 1 # Number: Signatures required to approve a message
validators: # Array: List of validator configs
- '0xa0ee7a142d267c1f36714e4a8f75612f20a79720'
anvil2:
type: 3
type: 'legacy_multisig'
threshold: 1
validators:
- '0xa0ee7a142d267c1f36714e4a8f75612f20a79720'
1 change: 1 addition & 0 deletions typescript/cli/examples/warp-tokens.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# A config for a Warp Route deployment
# Typically used with the 'hyperlane deploy warp' command
#
# Token Types:
# synthetic
# syntheticUri
Expand Down
18 changes: 13 additions & 5 deletions typescript/cli/src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { input } from '@inquirer/prompts';
import { confirm, input } from '@inquirer/prompts';
import select from '@inquirer/select';
import { CommandModule } from 'yargs';

import { ChainMetadata, isValidChainMetadata } from '@hyperlane-xyz/sdk';
import { ProtocolType } from '@hyperlane-xyz/utils';

import { readChainConfig } from '../configs.js';
import { errorRed, logBlue, logGreen } from '../logger.js';
import { errorRed, log, logBlue, logGreen } from '../logger.js';
import { FileFormat, mergeYamlOrJson } from '../utils/files.js';

/**
Expand All @@ -21,7 +21,7 @@ export const configCommand: CommandModule = {
.command(validateCommand)
.version(false)
.demandCommand(),
handler: () => console.log('Command required'),
handler: () => log('Command required'),
};

/**
Expand Down Expand Up @@ -52,9 +52,17 @@ const createCommand: CommandModule = {
message: 'Enter chain name (one word, lower case)',
});
const chainId = await input({ message: 'Enter chain id (number)' });
const domainId = await input({
message: 'Enter domain id (number, often matches chainId)',
const skipDomain = await confirm({
message: 'Will the domainId match the chainId (recommended)?',
});
let domainId: string;
if (skipDomain) {
domainId = chainId;
} else {
domainId = await input({
message: 'Enter domain id (number, often matches chainId)',
});
}
const protocol = await select({
message: 'Select protocol type',
choices: Object.values(ProtocolType).map((protocol) => ({
Expand Down
4 changes: 2 additions & 2 deletions typescript/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CommandModule } from 'yargs';

import { runCoreDeploy } from '../deploy/core.js';
import { runWarpDeploy } from '../deploy/warp.js';
import { logGray } from '../logger.js';
import { log, logGray } from '../logger.js';

import {
chainsCommandOption,
Expand All @@ -23,7 +23,7 @@ export const deployCommand: CommandModule = {
.command(warpCommand)
.version(false)
.demandCommand(),
handler: () => console.log('Command required'),
handler: () => log('Command required'),
};

/**
Expand Down
21 changes: 18 additions & 3 deletions typescript/cli/src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import {
ChainMap,
ChainMetadata,
HyperlaneContractsMap,
ModuleType,
MultisigIsmConfig,
isValidChainMetadata,
} from '@hyperlane-xyz/sdk';
import { objMap } from '@hyperlane-xyz/utils';

import { getMultiProvider } from './context.js';
import { errorRed, log, logGreen } from './logger.js';
import { readYamlOrJson } from './utils/files.js';

export function readChainConfig(filepath: string) {
console.log(`Reading file configs in ${filepath}`);
log(`Reading file configs in ${filepath}`);
const chainToMetadata = readYamlOrJson<ChainMap<ChainMetadata>>(filepath);

if (
Expand Down Expand Up @@ -76,7 +78,7 @@ export function readDeploymentArtifacts(filePath: string) {

const MultisigConfigSchema = z.object({}).catchall(
z.object({
type: z.number(),
type: z.string(),
threshold: z.number(),
validators: z.array(z.string()),
}),
Expand All @@ -92,7 +94,20 @@ export function readMultisigConfig(filePath: string) {
`Invalid multisig config: ${firstIssue.path} => ${firstIssue.message}`,
);
}
return result.data as ChainMap<MultisigIsmConfig>;
const parsedConfig = result.data;
const formattedConfig = objMap(parsedConfig, (_, config) => ({
...config,
type: humanReadableIsmTypeToEnum(config.type),
}));

return formattedConfig as ChainMap<MultisigIsmConfig>;
}

function humanReadableIsmTypeToEnum(type: string): ModuleType {
for (const [key, value] of Object.entries(ModuleType)) {
if (key.toLowerCase() === type) return parseInt(value.toString(), 10);
}
throw new Error(`Invalid ISM type ${type}`);
}

const ConnectionConfigSchema = {
Expand Down
Loading

0 comments on commit e914051

Please sign in to comment.