bridge_route
Calculate optimal cross-chain transfer route between two chains using source and destination chain IDs, token denominations, and amount in minimal units.
Instructions
Find the optimal cross-chain transfer route between two chains.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Transfer amount in minimal denomination | |
| sourceChainId | Yes | Source chain ID | |
| sourceDenom | Yes | Source token denomination | |
| destChainId | Yes | Destination chain ID | |
| destDenom | Yes | Destination token denomination | |
| network | No | Network to use. Defaults to mainnet. |
Implementation Reference
- src/tools/bridge.ts:47-69 (handler)Core handler for the 'bridge_route' tool. Retrieves the provider from chainManager and calls provider.bridge.route() with source/dest chain IDs and denoms to find the optimal cross-chain transfer route. Returns the route as JSON.
registry.register({ name: 'bridge_route', group: 'bridge', description: 'Find the optimal cross-chain transfer route between two chains.', schema: { amount: z.string().describe('Transfer amount in minimal denomination'), sourceChainId: z.string().describe('Source chain ID'), sourceDenom: z.string().describe('Source token denomination'), destChainId: z.string().describe('Destination chain ID'), destDenom: z.string().describe('Destination token denomination'), network: networkParam, }, annotations: { readOnlyHint: true }, handler: async ({ amount, sourceChainId, sourceDenom, destChainId, destDenom, network }, { chainManager }) => { const provider = await chainManager.getProvider(network); const route = await provider.bridge.route({ amount, source: { chainId: sourceChainId, denom: sourceDenom }, dest: { chainId: destChainId, denom: destDenom }, }); return success(route); }, }); - src/tools/bridge.ts:47-69 (schema)Input schema for bridge_route: amount (string), sourceChainId, sourceDenom, destChainId, destDenom (all strings), and network (optional mainnet/testnet). Uses Zod validation.
registry.register({ name: 'bridge_route', group: 'bridge', description: 'Find the optimal cross-chain transfer route between two chains.', schema: { amount: z.string().describe('Transfer amount in minimal denomination'), sourceChainId: z.string().describe('Source chain ID'), sourceDenom: z.string().describe('Source token denomination'), destChainId: z.string().describe('Destination chain ID'), destDenom: z.string().describe('Destination token denomination'), network: networkParam, }, annotations: { readOnlyHint: true }, handler: async ({ amount, sourceChainId, sourceDenom, destChainId, destDenom, network }, { chainManager }) => { const provider = await chainManager.getProvider(network); const route = await provider.bridge.route({ amount, source: { chainId: sourceChainId, denom: sourceDenom }, dest: { chainId: destChainId, denom: destDenom }, }); return success(route); }, }); - src/tools/bridge.ts:47-48 (registration)Registration of the 'bridge_route' tool via registry.register() in src/tools/bridge.ts. The file is side-effect imported via src/tools/index.ts.
registry.register({ name: 'bridge_route', - src/cli/format-custom.ts:137-184 (helper)CLI formatter for bridge_route output. Renders route details including source/dest, amounts, estimated duration, and operations list.
// bridge_route // --------------------------------------------------------------------------- function formatBridgeRoute(data: unknown): string | undefined { if (!isRecord(data)) return undefined; const source = pick(data, 'source', 'srcChainId', 'src_chain_id'); const dest = pick(data, 'dest', 'dstChainId', 'dst_chain_id'); const operations = data.operations; const amountIn = pick(data, 'amountIn', 'amount_in'); const amountOut = pick(data, 'amountOut', 'amount_out'); const durationSecs = pick(data, 'estimatedDurationSeconds', 'estimated_duration_seconds', 'duration'); if (source === undefined && dest === undefined && !Array.isArray(operations)) return undefined; const lines: string[] = []; const srcStr = source !== undefined ? String(source) : '?'; const dstStr = dest !== undefined ? String(dest) : '?'; lines.push(pc.bold(`Route: ${srcStr} \u2192 ${dstStr}`)); if (amountIn !== undefined || amountOut !== undefined) { const inStr = amountIn !== undefined ? formatAmountToken(amountIn) : '?'; const outStr = amountOut !== undefined ? formatAmountToken(amountOut) : '?'; lines.push(` ${pc.dim('Amount ')} ${inStr} \u2192 ${outStr}`); } if (durationSecs !== undefined) { lines.push(` ${pc.dim('Duration')} ~${formatNumber(String(durationSecs))}s`); } if (Array.isArray(operations) && operations.length > 0) { lines.push(` ${pc.dim('Operations:')}`); for (let i = 0; i < operations.length; i++) { const op = operations[i]; if (isRecord(op)) { const opType = String(op.type ?? op.action ?? op.kind ?? 'op'); const detail = op.channel ?? op.pool ?? op.poolId ?? op.pool_id ?? op.dex ?? op.bridge; const detailStr = detail !== undefined ? ` (${detail})` : ''; lines.push(` ${i + 1}. ${opType}${detailStr}`); } else { lines.push(` ${i + 1}. ${String(op)}`); } } } return lines.join('\n'); } - src/cli/format-custom.ts:293-297 (registration)Registration of the bridge_route formatter via registerFormatter('bridge_route', formatBridgeRoute) for CLI display.
registerFormatter('account_get', formatAccountGet); registerFormatter('tx_get', formatTxGet); registerFormatter('bridge_route', formatBridgeRoute); registerFormatter('delegation_get', formatDelegationGet);