From 3662297fc581b375c5c1c2b6d6615a9ede5eb56c Mon Sep 17 00:00:00 2001 From: xeno097 Date: Tue, 15 Oct 2024 18:13:10 -0400 Subject: [PATCH] feat: `warp init` simplified config (#4504) ### Description This PR updates the ISM configuration prompting for the `warp init` command allowing the user to choose if a trusted ISM should be used by default or a configured one. Before: ![image](https://github.com/user-attachments/assets/7be4e5af-d664-4481-ac31-b87caf609b91) ![image](https://github.com/user-attachments/assets/030aa59c-82ad-4349-a973-273b0eb15403) After: ![image](https://github.com/user-attachments/assets/c19ca765-c771-4d04-8041-c5c19f44f645) ![image](https://github.com/user-attachments/assets/5e875beb-c86e-464d-bcf9-0c705a9f43ce) ### Drive-by changes - No ### Related issues - Fixes https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/4464 ### Backward compatibility - Yes ### Testing - Manual --------- Co-authored-by: Lee <6251863+ltyu@users.noreply.github.com> --- .changeset/long-swans-drive.md | 5 ++++ typescript/cli/src/config/warp.ts | 49 ++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 .changeset/long-swans-drive.md diff --git a/.changeset/long-swans-drive.md b/.changeset/long-swans-drive.md new file mode 100644 index 0000000000..3f21e56c41 --- /dev/null +++ b/.changeset/long-swans-drive.md @@ -0,0 +1,5 @@ +--- +'@hyperlane-xyz/cli': minor +--- + +Add prompt in `warp init` command to choose if a trusted relayer should be used instead of making the choice by default for the user and enable the `--yes` flag to default to a trusted ISM diff --git a/typescript/cli/src/config/warp.ts b/typescript/cli/src/config/warp.ts index 8e15ccc3c3..6ce1f6665a 100644 --- a/typescript/cli/src/config/warp.ts +++ b/typescript/cli/src/config/warp.ts @@ -1,4 +1,4 @@ -import { input, select } from '@inquirer/prompts'; +import { confirm, input, select } from '@inquirer/prompts'; import { stringify as yamlStringify } from 'yaml'; import { @@ -142,6 +142,29 @@ export async function createWarpRouteDeployConfig({ message: `Could not retrieve mailbox address from the registry for chain "${chain}". Please enter a valid mailbox address:`, })); + /** + * The logic from the cli is as follows: + * --advanced flag is provided: the user will have to build their own configuration using the available ISM types + * --yes flag is provided: the default ISM config will be used (Trusted ISM + Default fallback ISM) + * -- no flag is provided: the user must choose if the default ISM config should be used: + * - yes: the default ISM config will be used (Trusted ISM + Default fallback ISM) + * - no: the default fallback ISM will be used + */ + let interchainSecurityModule: IsmConfig; + if (advanced) { + interchainSecurityModule = await createAdvancedIsmConfig(context); + } else if (context.skipConfirmation) { + interchainSecurityModule = createDefaultWarpIsmConfig(owner); + } else if ( + await confirm({ + message: 'Do you want to use a trusted ISM for warp route?', + }) + ) { + interchainSecurityModule = createDefaultWarpIsmConfig(owner); + } else { + interchainSecurityModule = createFallbackRoutingConfig(owner); + } + const type = await select({ message: `Select ${chain}'s token type`, choices: TYPE_CHOICES, @@ -151,10 +174,6 @@ export async function createWarpRouteDeployConfig({ const isNft = type === TokenType.syntheticUri || type === TokenType.collateralUri; - const interchainSecurityModule = advanced - ? await createAdvancedIsmConfig(context) - : createDefaultWarpIsmConfig(owner); - switch (type) { case TokenType.collateral: case TokenType.XERC20: @@ -234,12 +253,22 @@ function createDefaultWarpIsmConfig(owner: Address): IsmConfig { type: IsmType.TRUSTED_RELAYER, relayer: owner, }, - { - type: IsmType.FALLBACK_ROUTING, - domains: {}, - owner, - }, + createFallbackRoutingConfig(owner), ], threshold: 1, }; } + +/** + * Creates a fallback configuration for an ISM with a FALLBACK_ROUTING and the provided `owner`. + * + * @param owner - The address of the owner of the ISM. + * @returns The Fallback Routing ISM configuration. + */ +function createFallbackRoutingConfig(owner: Address): IsmConfig { + return { + type: IsmType.FALLBACK_ROUTING, + domains: {}, + owner, + }; +}