From f95e691015a79bcdf0a6ad8830345a1f8f8ddfc0 Mon Sep 17 00:00:00 2001 From: Le Yu <6251863+ltyu@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:20:02 -0500 Subject: [PATCH] Update warp send to enable roundtrip transfer to all routes --- typescript/cli/src/commands/warp.ts | 18 ++++++-- typescript/cli/src/send/transfer.ts | 64 ++++++++++++----------------- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/typescript/cli/src/commands/warp.ts b/typescript/cli/src/commands/warp.ts index 5d09047617..206109adcd 100644 --- a/typescript/cli/src/commands/warp.ts +++ b/typescript/cli/src/commands/warp.ts @@ -1,7 +1,7 @@ import { stringify as yamlStringify } from 'yaml'; import { CommandModule } from 'yargs'; -import { ChainSubmissionStrategySchema } from '@hyperlane-xyz/sdk'; +import { ChainName, ChainSubmissionStrategySchema } from '@hyperlane-xyz/sdk'; import { runWarpRouteCheck } from '../check/warp.js'; import { @@ -14,7 +14,7 @@ import { } from '../context/types.js'; import { evaluateIfDryRunFailure } from '../deploy/dry-run.js'; import { runWarpRouteApply, runWarpRouteDeploy } from '../deploy/warp.js'; -import { log, logCommandHeader, logGreen } from '../logger.js'; +import { log, logBlue, logCommandHeader, logGreen } from '../logger.js'; import { runWarpRouteRead } from '../read/warp.js'; import { sendTestTransfer } from '../send/transfer.js'; import { @@ -282,17 +282,27 @@ const send: CommandModuleWithWriteContext< context, }); + let chains: ChainName[]; + if (origin && destination) { + chains = [origin, destination]; + } else { + // Send to all chains in WarpCoreConfig + chains = warpCoreConfig.tokens.map((t) => t.chainName); + // Appends the reverse of the array to roundtrip + chains = [...chains, ...chains.reverse().slice(1, chains.length + 1)]; + } + logBlue(`🚀 Sending a message for chains: ${chains.join(' ➡️ ')}`); await sendTestTransfer({ context, warpCoreConfig, - origin, - destination, + chains, amount, recipient, timeoutSec: timeout, skipWaitForDelivery: quick, selfRelay: relay, }); + logGreen(`✅ Sending a message for chains: ${chains.join(' ➡️ ')}`); process.exit(0); }, }; diff --git a/typescript/cli/src/send/transfer.ts b/typescript/cli/src/send/transfer.ts index 134eb9b3b3..8aa4cca59b 100644 --- a/typescript/cli/src/send/transfer.ts +++ b/typescript/cli/src/send/transfer.ts @@ -18,7 +18,6 @@ import { MINIMUM_TEST_SEND_GAS } from '../consts.js'; import { WriteCommandContext } from '../context/types.js'; import { runPreflightChecksForChains } from '../deploy/utils.js'; import { log, logBlue, logGreen, logRed } from '../logger.js'; -import { runSingleChainSelectionStep } from '../utils/chains.js'; import { indentYamlOrJson } from '../utils/files.js'; import { stubMerkleTreeConfig } from '../utils/relay.js'; import { runTokenSelectionStep } from '../utils/tokens.js'; @@ -30,8 +29,7 @@ export const WarpSendLogs = { export async function sendTestTransfer({ context, warpCoreConfig, - origin, - destination, + chains, amount, recipient, timeoutSec, @@ -40,51 +38,41 @@ export async function sendTestTransfer({ }: { context: WriteCommandContext; warpCoreConfig: WarpCoreConfig; - origin?: ChainName; // resolved in signerMiddleware - destination?: ChainName; // resolved in signerMiddleware + chains: ChainName[]; amount: string; recipient?: string; timeoutSec: number; skipWaitForDelivery: boolean; selfRelay?: boolean; }) { - const { chainMetadata } = context; - - if (!origin) { - origin = await runSingleChainSelectionStep( - chainMetadata, - 'Select the origin chain:', - ); - } - - if (!destination) { - destination = await runSingleChainSelectionStep( - chainMetadata, - 'Select the destination chain:', - ); - } - await runPreflightChecksForChains({ context, - chains: [origin, destination], - chainsToGasCheck: [origin], + chains, minGas: MINIMUM_TEST_SEND_GAS, }); - await timeout( - executeDelivery({ - context, - origin, - destination, - warpCoreConfig, - amount, - recipient, - skipWaitForDelivery, - selfRelay, - }), - timeoutSec * 1000, - 'Timed out waiting for messages to be delivered', - ); + for (let i = 0; i < chains.length; i++) { + const origin = chains[i]; + const destination = chains[i + 1]; + + if (destination) { + logBlue(`Sending a message from ${origin} to ${destination}`); + await timeout( + executeDelivery({ + context, + origin, + destination, + warpCoreConfig, + amount, + recipient, + skipWaitForDelivery, + selfRelay, + }), + timeoutSec * 1000, + 'Timed out waiting for messages to be delivered', + ); + } + } } async function executeDelivery({ @@ -199,5 +187,5 @@ async function executeDelivery({ // Max wait 10 minutes await core.waitForMessageProcessed(transferTxReceipt, 10000, 60); - logGreen(`Transfer sent to destination chain!`); + logGreen(`Transfer sent to ${destination} chain!`); }