Skip to main content
This workflow demonstrates a complete round-trip bridge operation using Stargate (LayerZero). Bridge tokens to a destination chain, perform operations, and bridge the result back to the origin chain. Route Mechanics: This bundle executes a complete round-trip bridging workflow:
  • Bridge chUSD from Hyperliquid to Plasma using Stargate
  • Check chUSD balance on Plasma after bridge completion
  • Swap chUSD to schUSD on Plasma
  • Bridge newly acquired schUSD back to Hyperliquid via Stargate
  • Receive schUSD on the origin chain
Use the GET /layerzero/pool API to find the correct OFT pool address for each token/chain pair.
stargateDoubleBridge.ts
import { EnsoClient } from "@ensofinance/sdk";
import { parseUnits } from "viem";

// Chain IDs
const HYPERLIQUID_ID = 999;
const PLASMA_ID = 9745;

// Common addresses
const WALLET_ADDRESS = "0x826e0BB2276271eFdF2a500597f37b94f6c153bA";

// Token addresses on Hyperliquid
const chUSD_HYPE = "0x2222227d90046F1483B3Fb37990DEA31FCaBea02";

// Token addresses on Plasma
const chUSD_PLASMA = "0x22222215d4EdC5510d23D0886133E7ece7F5fdC1";
const schUSD_PLASMA = "0x888888bAb58A7bd3068110749BC7B63B62CE874d";

// Pool addresses (from LayerZero API)
const chUSD_POOL_HYPE_TO_PLASMA = "0x2222227d90046F1483B3Fb37990DEA31FCaBea02";
const schUSD_POOL_PLASMA_TO_HYPE = "0x8888883ACA65976e98E16931b46308E4C588D533";

const client = new EnsoClient({
  apiKey: process.env.ENSO_API_KEY!,
});

// Or fetch pools dynamically:
// const chUsdPools = await client.getLayerZeroPool({
//   chainId: HYPERLIQUID_ID,
//   token: chUSD_HYPE,
//   destinationChainId: PLASMA_ID + "",
// });

const bundle = await client.getBundleData(
  {
    chainId: HYPERLIQUID_ID,
    fromAddress: WALLET_ADDRESS,
    routingStrategy: "router",
  },
  [
    {
      protocol: "stargate",
      action: "bridge",
      args: {
        primaryAddress: chUSD_POOL_HYPE_TO_PLASMA,
        destinationChainId: PLASMA_ID,
        tokenIn: chUSD_HYPE,
        amountIn: parseUnits("1", 18).toString(), // 1 chUSD
        receiver: WALLET_ADDRESS,
        callback: [
          // Step 1: Check chUSD balance on Plasma
          {
            protocol: "enso",
            action: "balance",
            args: {
              token: chUSD_PLASMA,
            },
          },
          // Step 2: Swap chUSD to schUSD on Plasma
          {
            protocol: "enso",
            action: "route",
            args: {
              slippage: "50", // 0.5%
              tokenIn: chUSD_PLASMA,
              tokenOut: schUSD_PLASMA,
              amountIn: { useOutputOfCallAt: 0 },
            },
          },
          // Step 3: Bridge schUSD back to Hyperliquid
          {
            protocol: "stargate",
            action: "bridge",
            args: {
              primaryAddress: schUSD_POOL_PLASMA_TO_HYPE,
              destinationChainId: HYPERLIQUID_ID,
              tokenIn: schUSD_PLASMA,
              amountIn: { useOutputOfCallAt: 1 },
              receiver: WALLET_ADDRESS,
              // Final destination - no callback needed
            },
          },
        ],
      },
    },
  ]
);

return bundle;
Important Considerations:
  • Stargate has a tight callback data limit (~9.5KB) - keep callbacks concise
  • LayerZero bridge fees apply for each bridge operation
  • Gas costs for all destination chain operations are calculated upfront
  • Both ERC20 and native token bridging are supported
  • Use getLayerZeroPool to discover available OFT pools dynamically

Nested Callbacks for Multi-Chain Operations

Stargate supports nested callbacks for complex multi-chain workflows. Each nested bridge can have its own callback array:
{
  protocol: "stargate",
  action: "bridge",
  args: {
    // First bridge: Chain A → Chain B
    callback: [
      { protocol: "enso", action: "balance", args: { token: "..." } },
      {
        protocol: "stargate",
        action: "bridge",
        args: {
          // Second bridge: Chain B → Chain C
          callback: [
            { protocol: "enso", action: "balance", args: { token: "..." } },
            // Operations on Chain C...
          ]
        }
      }
    ]
  }
}

Resources

Updated