Skip to content

Use Bundlers for Vaults

When building a user-facing application for the Earn product, providing a seamless and efficient user experience is key. Simple actions, like depositing into a vault, often require multiple onchain steps for the user: first, an approve transaction, and then a deposit transaction. This can be slow, costly, and confusing.

Morpho Bundlers solve this problem by allowing you to combine multiple operations into a single, atomic transaction.

This tutorial will introduce the specific Bundler actions available for Morpho Vaults and their related operations, then guide you to the main tutorials for implementation.

Why Use Bundlers for Vault Interactions?

  • Superior User Experience: Users sign only one transaction for complex actions like "wrap ETH, deposit into vault, and claim pending rewards."
  • Gas Efficiency: Combining calls into a single transaction significantly reduces gas costs.
  • Atomicity: If any step in the sequence fails, the entire transaction reverts. This prevents users from getting stuck in an intermediate state (e.g., tokens are approved but not deposited).

For any user-facing application, using the Bundler is the recommended approach.

Core Bundler Actions for the Earn Product

The bundler-sdk-viem package provide a set of InputBundlerOperation types for interacting with Morpho Vaults and claiming rewards.

MetaMorpho_Deposit

This action handles depositing an underlying asset into a vault in exchange for vault shares. The bundler will automatically handle any required token approvals.

import { DEFAULT_SLIPPAGE_TOLERANCE } from "@morpho-org/blue-sdk";
import { type InputBundlerOperation } from "@morpho-org/bundler-sdk-viem";
 
const depositOperation: InputBundlerOperation = {
  type: "MetaMorpho_Deposit",
  args: {
    // Vault address
    // Amount of assets to deposit
    // Receiver of the vault shares
    // Slippage tolerance for the conversion
  },
};

MetaMorpho_Withdraw

This action handles withdrawing an underlying asset from a vault by redeeming vault shares. The bundler automatically handles approvals for the vault shares if needed.

// Example: Redeeming a specific amount of shares
const withdrawOperation: InputBundlerOperation = {
  type: "MetaMorpho_Withdraw",
  args: {
    // Vault address
    // Amount of shares to redeem
    // Owner of the shares
    // Receiver of the underlying asset
    // Slippage tolerance
  },
};

urdClaim

In addition to managing vault positions, the bundler can also claim rewards from the Universal Rewards Distributor (URD) in the same transaction. This is perfect for users who want to deposit and claim their pending rewards at once.

const claimOperation: InputBundlerOperation = {
  type: "urdClaim",
  args: [
    distributorAddress, // Address of the URD contract
    userAddress,        // Address to receive rewards
    rewardTokenAddress, // The reward token
    claimableAmount,    // The cumulative claimable amount
    merkleProof,        // The Merkle proof for validation
  ],
};

Next Steps: Building Your Integration

Now that you understand the vault-related actions, the next step is to integrate them. We have dedicated tutorials that cover the implementation details.

1. Combining Vault Actions with Other Operations

Your users will often want to perform multiple actions at once. For example:

  • Swap USDC for WETH, then deposit the WETH into a vault.
  • Deposit into a vault and claim pending rewards simultaneously.

Our Combine Actions tutorial shows you how to chain these operations together into a single, logical bundle.

Learn how to combine actions in the Bundlers: Combine Actions Tutorial

2. Full SDK Integration

Once you know which actions to combine, you need to use the SDK to simulate, populate, and encode the final transaction. This tutorial provides the complete code flow for using bundler-sdk-viem to prepare and send a bundled transaction.

This is the core implementation guide for building your integration.

Follow the complete guide in the Bundlers: App Integration Tutorial