From 65615046412abb8d2aedcf0f9835b863a0f18977 Mon Sep 17 00:00:00 2001 From: ljankovic-txfusion Date: Thu, 21 Nov 2024 18:45:35 +0100 Subject: [PATCH] refactor: improve signer management in warp route deploy config creation --- typescript/cli/src/config/warp.ts | 31 +++++++++++++++++++++------ typescript/cli/src/context/context.ts | 6 +++--- typescript/cli/src/context/types.ts | 2 ++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/typescript/cli/src/config/warp.ts b/typescript/cli/src/config/warp.ts index 1174d0156..5f628a167 100644 --- a/typescript/cli/src/config/warp.ts +++ b/typescript/cli/src/config/warp.ts @@ -21,6 +21,8 @@ import { promiseObjAll, } from '@hyperlane-xyz/utils'; +import { DEFAULT_STRATEGY_CONFIG_PATH } from '../commands/options.js'; +import { MultiProtocolSignerManager } from '../context/strategies/signer/MultiProtocolSignerManager.js'; import { CommandContext } from '../context/types.js'; import { errorRed, log, logBlue, logGreen } from '../logger.js'; import { runMultiChainSelectionStep } from '../utils/chains.js'; @@ -35,6 +37,7 @@ import { } from '../utils/input.js'; import { createAdvancedIsmConfig } from './ism.js'; +import { readChainSubmissionStrategyConfig } from './strategy.js'; const TYPE_DESCRIPTIONS: Record = { [TokenType.synthetic]: 'A new ERC20 with remote transfer functionality', @@ -122,13 +125,6 @@ export async function createWarpRouteDeployConfig({ }) { logBlue('Creating a new warp route deployment config...'); - const owner = await detectAndConfirmOrPrompt( - async () => context.signer?.getAddress(), - 'Enter the desired', - 'owner address', - 'signer', - ); - const warpChains = await runMultiChainSelectionStep({ chainMetadata: context.chainMetadata, message: 'Select chains to connect', @@ -138,11 +134,32 @@ export async function createWarpRouteDeployConfig({ requiresConfirmation: !context.skipConfirmation, }); + const strategyConfig = await readChainSubmissionStrategyConfig( + context.strategyPath ?? DEFAULT_STRATEGY_CONFIG_PATH, + ); + + const multiProtocolSigner = new MultiProtocolSignerManager( + strategyConfig, + warpChains, + context.multiProvider, + { key: context.key }, + ); + + const multiProviderWithSigners = + await multiProtocolSigner.setupMultiProvider(); + const result: WarpRouteDeployConfig = {}; let typeChoices = TYPE_CHOICES; for (const chain of warpChains) { logBlue(`${chain}: Configuring warp route...`); + const owner = await detectAndConfirmOrPrompt( + async () => await multiProviderWithSigners.getSigner(chain).getAddress(), + 'Enter the desired', + 'owner address', + 'signer', + ); + // 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); diff --git a/typescript/cli/src/context/context.ts b/typescript/cli/src/context/context.ts index 900752cd2..8fa69303b 100644 --- a/typescript/cli/src/context/context.ts +++ b/typescript/cli/src/context/context.ts @@ -45,6 +45,7 @@ export async function contextMiddleware(argv: Record) { requiresKey, disableProxy: argv.disableProxy, skipConfirmation: argv.yes, + strategyPath: argv.strategy, }; if (!isDryRun && settings.fromAddress) throw new Error( @@ -57,13 +58,12 @@ export async function contextMiddleware(argv: Record) { } export async function signerMiddleware(argv: Record) { - const { key, context } = argv; - const { requiresKey, multiProvider } = context; + const { key, requiresKey, multiProvider, strategyPath } = argv.context; if (!requiresKey) return argv; const strategyConfig = await readChainSubmissionStrategyConfig( - argv.strategy ?? DEFAULT_STRATEGY_CONFIG_PATH, + strategyPath ?? DEFAULT_STRATEGY_CONFIG_PATH, ); /** diff --git a/typescript/cli/src/context/types.ts b/typescript/cli/src/context/types.ts index eef1ad2bb..783797289 100644 --- a/typescript/cli/src/context/types.ts +++ b/typescript/cli/src/context/types.ts @@ -17,6 +17,7 @@ export interface ContextSettings { requiresKey?: boolean; disableProxy?: boolean; skipConfirmation?: boolean; + strategyPath?: string; } export interface CommandContext { @@ -27,6 +28,7 @@ export interface CommandContext { key?: string; signer?: ethers.Signer; warpCoreConfig?: WarpCoreConfig; + strategyPath?: string; } export interface WriteCommandContext extends CommandContext {