Skip to content

Commit

Permalink
Update warp send to enable roundtrip transfer to all routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ltyu committed Jan 7, 2025
1 parent c5d4bd6 commit f95e691
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
18 changes: 14 additions & 4 deletions typescript/cli/src/commands/warp.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
},
};
Expand Down
64 changes: 26 additions & 38 deletions typescript/cli/src/send/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -30,8 +29,7 @@ export const WarpSendLogs = {
export async function sendTestTransfer({
context,
warpCoreConfig,
origin,
destination,
chains,
amount,
recipient,
timeoutSec,
Expand All @@ -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({
Expand Down Expand Up @@ -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!`);
}

0 comments on commit f95e691

Please sign in to comment.