Skip to content

Commit

Permalink
feat: warp init simplified config (#4504)
Browse files Browse the repository at this point in the history
### 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 #4464

### Backward compatibility

- Yes

### Testing

- Manual

---------

Co-authored-by: Lee <[email protected]>
  • Loading branch information
xeno097 and ltyu authored Oct 15, 2024
1 parent c08d842 commit 3662297
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-swans-drive.md
Original file line number Diff line number Diff line change
@@ -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
49 changes: 39 additions & 10 deletions typescript/cli/src/config/warp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { input, select } from '@inquirer/prompts';
import { confirm, input, select } from '@inquirer/prompts';
import { stringify as yamlStringify } from 'yaml';

import {
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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,
};
}

0 comments on commit 3662297

Please sign in to comment.