Skip to content

Commit

Permalink
feat: support ZKSync-specific ISM configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ljankovic-txfusion committed Jan 29, 2025
1 parent e17ca49 commit bae1979
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
10 changes: 6 additions & 4 deletions typescript/cli/src/config/ism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
MultisigIsmConfig,
MultisigIsmConfigSchema,
TrustedRelayerIsmConfig,
isStaticIsm,
} from '@hyperlane-xyz/sdk';

import { CommandContext } from '../context/types.js';
Expand Down Expand Up @@ -87,6 +88,7 @@ const ISM_TYPE_DESCRIPTIONS: Record<string, string> = {

export async function createAdvancedIsmConfig(
context: CommandContext,
excludeStaticIsms: boolean = false,
): Promise<IsmConfig> {
logBlue('Creating a new advanced ISM config');
logBoldUnderlinedRed('WARNING: USE AT YOUR RISK.');
Expand All @@ -96,12 +98,12 @@ export async function createAdvancedIsmConfig(

const moduleType = await select({
message: 'Select ISM type',
choices: Object.entries(ISM_TYPE_DESCRIPTIONS).map(
([value, description]) => ({
choices: Object.entries(ISM_TYPE_DESCRIPTIONS)
.filter(([value]) => !excludeStaticIsms || !isStaticIsm(value as IsmType))
.map(([value, description]) => ({
value,
description,
}),
),
})),
pageSize: 10,
});

Expand Down
57 changes: 42 additions & 15 deletions typescript/cli/src/config/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { stringify as yamlStringify } from 'yaml';

import {
ChainMap,
ChainTechnicalStack,
DeployedOwnableConfig,
IsmConfig,
IsmType,
Expand Down Expand Up @@ -158,6 +159,10 @@ export async function createWarpRouteDeployConfig({
owner,
);

const excludeStaticIsms =
context.multiProvider.getChainMetadata(chain).technicalStack ===
ChainTechnicalStack.ZkSync;

/**
* 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
Expand All @@ -168,15 +173,24 @@ export async function createWarpRouteDeployConfig({
*/
let interchainSecurityModule: IsmConfig;
if (advanced) {
interchainSecurityModule = await createAdvancedIsmConfig(context);
interchainSecurityModule = await createAdvancedIsmConfig(
context,
excludeStaticIsms,
);
} else if (context.skipConfirmation) {
interchainSecurityModule = createDefaultWarpIsmConfig(owner);
interchainSecurityModule = createDefaultWarpIsmConfig(
owner,
excludeStaticIsms,
);
} else if (
await confirm({
message: 'Do you want to use a trusted ISM for warp route?',
})
) {
interchainSecurityModule = createDefaultWarpIsmConfig(owner);
interchainSecurityModule = createDefaultWarpIsmConfig(
owner,
excludeStaticIsms,
);
} else {
interchainSecurityModule = createFallbackRoutingConfig(owner);
}
Expand Down Expand Up @@ -291,23 +305,36 @@ export function readWarpCoreConfig(filePath: string): WarpCoreConfig {
}

/**
* Creates a default configuration for an ISM with a TRUSTED_RELAYER and FALLBACK_ROUTING.
* Creates a default configuration for an ISM.
*
* Properties relayer and owner are both set as input owner.
* When excludeStaticIsms is false (default):
* - Creates an AGGREGATION ISM with TRUSTED_RELAYER and FALLBACK_ROUTING modules
* - Properties relayer and owner are both set as input owner
*
* @param owner - The address of the owner of the ISM.
* @returns The default Aggregation ISM configuration.
* When excludeStaticIsms is true:
* - Creates only a TRUSTED_RELAYER ISM (as static ISMs like AGGREGATION are not supported)
* - Properties relayer is set as input owner
*
* @param owner - The address of the owner of the ISM
* @param excludeStaticIsms - Whether to exclude static ISM types (default: false)
* @returns The ISM configuration
*/
function createDefaultWarpIsmConfig(owner: Address): IsmConfig {
function createDefaultWarpIsmConfig(
owner: Address,
excludeStaticIsms: boolean = false,
): IsmConfig {
const trustedRelayerModule: IsmConfig = {
type: IsmType.TRUSTED_RELAYER,
relayer: owner,
};

if (excludeStaticIsms) {
return trustedRelayerModule;
}

return {
type: IsmType.AGGREGATION,
modules: [
{
type: IsmType.TRUSTED_RELAYER,
relayer: owner,
},
createFallbackRoutingConfig(owner),
],
modules: [trustedRelayerModule, createFallbackRoutingConfig(owner)],
threshold: 1,
};
}
Expand Down

0 comments on commit bae1979

Please sign in to comment.