diff --git a/.changeset/long-swans-drive.md b/.changeset/long-swans-drive.md new file mode 100644 index 000000000..3f21e56c4 --- /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 8e15ccc3c..6ce1f6665 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, + }; +}