Enso’s bundle API provides the bridge action to facilitate cross-chain token transfers using Stargate.

You can construct the bundle in the following way:

  • pre-bridge actions that prepare the tokens for bridging, such as swapping or charging fees
  • a bridge action that transfers the tokens to the destination chain
  • use bridge action’s callback - an array of post-bridge actions that execute on the destination chain. Callbacks can reference outputs from previous actions using the useOutputOfCallAt
  • When using callbacks, the callback bundle must start with a balance action to check the bridged token balance on the destination chain.
  • To apply slippage constraints to the bridged tokens, you must use the slippage action in the callback bundle, referencing the outputs of the split via useOutputOfCallAt.

Example

This example demonstrates how to use the bridge action in a bundle to transfer tokens from Ethereum Mainnet to Base using Stargate. It includes a series of actions that:

  • swap USDC from mainnet to ETH using Enso routing for optimal path
  • charge a fee in ETH
  • bridge the ETH to Base using Stargate
  • check the bridged ETH balance on Base
  • split the ETH into two tokens
  • apply slippage constraints to the split tokens, referencing the outputs of the split via useOutputOfCallAt
  • deposit the split tokens into Uniswap V4 pools on Base
const bundle = await client.getBundleData(
  {
    chainId: 1,
    fromAddress: "0x93621DCA56fE26Cdee86e4F6B18E116e9758Ff11",
    spender: "0x93621DCA56fE26Cdee86e4F6B18E116e9758Ff11",
    routingStrategy: "router",
  },
  [
    {
      protocol: "enso",
      action: "route",
      args: {
        tokenIn: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC on mainnet
        amountIn: "1000000000", // 1000 USDC
        tokenOut: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", // ETH
      },
    },
    {
      protocol: "enso",
      action: "fee",
      args: {
        token: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
        amount: { useOutputOfCallAt: 0 },
        bps: 25,
        receiver: "0x93621DCA56fE26Cdee86e4F6B18E116e9758Ff11", // Fee receiver
      },
    },
    {
      protocol: "stargate",
      action: "bridge",
      args: {
        primaryAddress: "0x77b2043768d28e9c9ab44e1abfc95944bce57931",
        destinationChainId: 8453,
        tokenIn: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
        amountIn: { useOutputOfCallAt: 1 },
        receiver: "0x93621DCA56fE26Cdee86e4F6B18E116e9758Ff11",
        callback: [
          {
            protocol: "enso",
            action: "balance",
            args: {
              token: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
            },
          },
          {
            protocol: "enso",
            action: "split",
            args: {
              tokenIn: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
              tokenOut: [
                "0x50c5725949a6f0c72e6c4a641f24049a917db0cb",
                "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
              ],
              amountIn: { useOutputOfCallAt: 0 },
            },
          },
          {
            protocol: "enso",
            action: "slippage",
            args: {
              amountOut: { useOutputOfCallAt: 1, index: 0 },
              bps: 50,
            },
          },
          {
            protocol: "enso",
            action: "slippage",
            args: {
              amountOut: { useOutputOfCallAt: 1, index: 1 },
              bps: 50,
            },
          },
          {
            protocol: "uniswap-v4",
            action: "depositclmm",
            args: {
              tokenOut: "0x7c5f5a4bbd8fd63184577525326123b519429bdc",
              ticks: [-276842, -275842],
              tokenIn: [
                "0x50c5725949a6f0c72e6c4a641f24049a917db0cb",
                "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
              ],
              poolFee: "100",
              amountIn: [
                { useOutputOfCallAt: 1, index: 0 },
                { useOutputOfCallAt: 1, index: 1 },
              ],
            },
          },
          {
            protocol: "enso",
            action: "slippage",
            args: {
              amountOut: { useOutputOfCallAt: 4 },
              bps: 200,
            },
          },
        ],
      },
    },
  ],
);

Next Steps:

Updated