The POST shortcuts/bundle API converts specifications of DeFi actions into efficient calldata. This API allows chaining actions together by referencing outputs from previous operations.

The Bundle API requires a smart wallet supporting delegatecall for most functionality. Standard EOAs (Externally Owned Accounts) will have limited functionality. Learn more about routing strategies.

Bundle API Bundle API

Example

In this guide, we’ll create a bundle transaction that performs a complete DeFi strategy composed out of following actions:

  • convert ETH to wstETH,
  • deposit it into Aave V3
  • transfer the resulting aTokens to another address.

For more examples, explore the Shortcuts Library and check out the Actions Reference for all available actions.

1

Authentication

  1. Create an API key using Enso Dashboard.
  2. Securely store your API key and make it available in your environment:
authentication.sh
ENSO_API_KEY="$ENSO_API_KEY"
echo $ENSO_API_KEY >> .env
git ignore .env
source .env
2

Define your bundle actions

For our DeFi strategy, we’ll define three actions:

  1. Convert ETH to wstETH using the route action
  2. Deposit wstETH into Aave V3
  3. Transfer the resulting aTokens to a specified address

Explore the Actions Reference for all available actions.

Chain individual actions’ results by using useOutputOfCallAt. This parameter references the output from a prior action by its zero-based index.

const bundleActions = [
  {
    "protocol": "enso",
    "action": "route",
    "args": {
      "tokenIn": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", // ETH
      "tokenOut": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0", // wstETH
      "amountIn": "1000000000000000000", // 1 ETH
      "slippage": "300" // 3% slippage
    }
  },
  {
    "protocol": "aave-v3",
    "action": "deposit",
    "args": {
      "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2", // Aave V3 lending pool
      "tokenIn": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0", // wstETH
      "tokenOut": "0x0b925ed163218f6662a35e0f0371ac234f9e9371", // aEthwstETH
      "amountIn": {
        "useOutputOfCallAt": 0 // Use output from first action
      }
    }
  },
  {
    "protocol": "enso",
    "action": "call",
    "args": {
      "address": "0x0b925ed163218f6662a35e0f0371ac234f9e9371", // aEthwstETH
      "method": "transfer",
      "abi": "function transfer(address,uint256) external",
      "args": [
        "0x93621DCA56fE26Cdee86e4F6B18E116e9758Ff11", // Recipient address
        {
          "useOutputOfCallAt": 1 // Use output from second action
        }
      ]
    }
  }
];
3

Send the bundle request

Submit the bundle to the API to get the transaction data.

bundle.sh
CHAIN_ID=1
FROM_ADDRESS="0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
ROUTING_STRATEGY="delegate"

BUNDLE_RESPONSE=$(curl -X 'POST' \
  "https://api.enso.finance/api/v1/shortcuts/bundle?chainId=$CHAIN_ID&fromAddress=$FROM_ADDRESS&routingStrategy=$ROUTING_STRATEGY" \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $ENSO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '[
    {
      "protocol": "enso",
      "action": "route",
      "args": {
        "tokenIn": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
        "tokenOut": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
        "amountIn": "1000000000000000000",
        "slippage": "300"
      }
    },
    {
      "protocol": "aave-v3",
      "action": "deposit",
      "args": {
        "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
        "tokenIn": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
        "tokenOut": "0x0b925ed163218f6662a35e0f0371ac234f9e9371",
        "amountIn": {
          "useOutputOfCallAt": 0
        }
      }
    },
    {
      "protocol": "enso",
      "action": "call",
      "args": {
        "address": "0x0b925ed163218f6662a35e0f0371ac234f9e9371",
        "method": "transfer",
        "abi": "function transfer(address,uint256) external",
        "args": [
          "0x93621DCA56fE26Cdee86e4F6B18E116e9758Ff11",
          {
            "useOutputOfCallAt": 1
          }
        ]
      }
    }
  ]' | jq)

echo $BUNDLE_RESPONSE

The API will return a response containing:

  • bundle: The bundle actions exactly as submitted
  • tx: A transaction object with calldata—the executable form of the calculated route
  • amountOut: Expected output amount
  • gas: Estimated gas for the transaction
  • createdAt: Block number when the response was generated
4

Execute the transaction

Use the response tx field to send the transaction on-chain.

TX=$(echo "$PATH_RESPONSE" | jq -r '.tx')
send_tx $TX # send_tx is a placeholder
5

Next steps

Updated

Was this page helpful?