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:
<img width="839" alt="image"
src="https://github.com/user-attachments/assets/8bc4dbd7-d812-4449-a9cb-4e714843163a">

After:
<img width="672" alt="image"
src="https://github.com/user-attachments/assets/bf890fe6-d95a-42e7-9bdd-fdb908aa2ac0">

<img width="1097" alt="image"
src="https://github.com/user-attachments/assets/e586a33c-c56f-4973-ac87-4e1c8d3e759a">

<img width="913" alt="image"
src="https://github.com/user-attachments/assets/c6263411-8728-4127-a39b-38929f541506">

### 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.
pull/4537/head
xeno097 2 months ago committed by GitHub
parent 4151317b00
commit aef3dbf4d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/lazy-flies-sin.md
  2. 29
      typescript/cli/src/config/warp.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': minor
---
Remove mailbox choice prompt if it can be automatically detected from the registry

@ -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);

Loading…
Cancel
Save