From aef3dbf4d6f2f73475f37eaad1235a7a07521a5c Mon Sep 17 00:00:00 2001 From: xeno097 Date: Fri, 20 Sep 2024 07:08:28 -0400 Subject: [PATCH] feat: remove mailbox confirmation prompt for `warp init` command (#4485) ### Description This PR removes the mailbox address confirmation prompt from the `warp init` command. The command now uses the default mailbox value retrieved from the registry and asks for user input only if a mailbox address is not found in the registry for the selected chain. - Adds a `isAddressAndMatchesProtocol` function to validate that a provided string is a valid address and belongs to an expected protocol (Ethereum, Solana, ...) - Adds address validation for the user-provided mailbox address using the newly implemented `isAddressAndMatchesProtocol` function Before: image After: image image image ### Drive-by changes - No ### Related issues - Fixes https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/4463 ### Backward compatibility - Yes ### Testing - Manual testing Notes: - E2e test implementation was attempted but testing prompts have proven difficult and require further investigation/hacking to see if there is a way to test user prompts. --- .changeset/lazy-flies-sin.md | 5 +++++ typescript/cli/src/config/warp.ts | 29 ++++++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 .changeset/lazy-flies-sin.md diff --git a/.changeset/lazy-flies-sin.md b/.changeset/lazy-flies-sin.md new file mode 100644 index 000000000..33b439809 --- /dev/null +++ b/.changeset/lazy-flies-sin.md @@ -0,0 +1,5 @@ +--- +'@hyperlane-xyz/cli': minor +--- + +Remove mailbox choice prompt if it can be automatically detected from the registry diff --git a/typescript/cli/src/config/warp.ts b/typescript/cli/src/config/warp.ts index 240e0e39d..8e15ccc3c 100644 --- a/typescript/cli/src/config/warp.ts +++ b/typescript/cli/src/config/warp.ts @@ -12,7 +12,13 @@ import { WarpRouteDeployConfig, WarpRouteDeployConfigSchema, } from '@hyperlane-xyz/sdk'; -import { Address, assert, objMap, promiseObjAll } from '@hyperlane-xyz/utils'; +import { + Address, + assert, + isAddress, + objMap, + promiseObjAll, +} from '@hyperlane-xyz/utils'; import { CommandContext } from '../context/types.js'; import { errorRed, log, logBlue, logGreen } from '../logger.js'; @@ -125,6 +131,17 @@ export async function createWarpRouteDeployConfig({ const result: WarpRouteDeployConfig = {}; for (const chain of warpChains) { logBlue(`${chain}: Configuring warp route...`); + + // default to the mailbox from the registry and if not found ask to the user to submit one + const chainAddresses = await context.registry.getChainAddresses(chain); + + const mailbox = + chainAddresses?.mailbox ?? + (await input({ + validate: isAddress, + message: `Could not retrieve mailbox address from the registry for chain "${chain}". Please enter a valid mailbox address:`, + })); + const type = await select({ message: `Select ${chain}'s token type`, choices: TYPE_CHOICES, @@ -134,16 +151,6 @@ export async function createWarpRouteDeployConfig({ const isNft = type === TokenType.syntheticUri || type === TokenType.collateralUri; - const mailbox = await detectAndConfirmOrPrompt( - async () => { - const addresses = await context.registry.getChainAddresses(chain); - return addresses?.mailbox; - }, - `For ${chain}, enter the`, - 'mailbox address', - 'hyperlane-registry', - ); - const interchainSecurityModule = advanced ? await createAdvancedIsmConfig(context) : createDefaultWarpIsmConfig(owner);