Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: warp init simplified config #4504

Merged
merged 11 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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({
xeno097 marked this conversation as resolved.
Show resolved Hide resolved
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,
};
}
Loading