Skip to content

How Bundlers Work

Morpho Bundlers simplify complex onchain interactions by acting as a trusted dispatcher. Developers define a sequence of actions offchain using the SDK, which are then encoded and executed atomically onchain by the Bundler3 smart contract.

The Onchain & Offchain Flow

  1. Offchain (SDK Layer): Your application uses the bundler-sdk to define a sequence of high-level actions (e.g., Blue_SupplyCollateral, Blue_Borrow). The SDK simulates these actions, automatically adding necessary steps like token approvals and transfers, and then encodes them into a single multicall.
  2. Onchain (Contract Layer): The encoded bundle is sent to the Bundler3 contract's multicall function. The bundler then dispatches each call to its respective adapter for execution in a single, atomic transaction.

Onchain Architecture: Bundler3 and Adapters

The onchain system is composed of a core Bundler3 contract and a set of specialized Adapters.

The multicall Function

The core of the system is the multicall(Call[] calldata bundle) function within the Bundler3 contract. It accepts an array of Call structs, where each call is defined by:

  • to: The target address for the call (usually an adapter).
  • data: The encoded function call data.
  • value: The amount of native currency (e.g., ETH) to send with the call.
  • skipRevert: A boolean flag. If true, the multicall will not revert if this specific call fails, allowing the rest of the bundle to proceed.
  • callbackHash: A hash used to control reentrancy, ensuring secure interactions with external contracts that might call back into the bundler.

Adapters

Adapters are modular contracts that handle the logic for specific actions. They all inherit from a CoreAdapter, which grants them secure access to the initiator (the original msg.sender of the multicall) via transient storage (tload). This ensures that adapters can only perform actions on behalf of the user who initiated the transaction.

There are several types of adapters:

  • General Adapters: The GeneralAdapter1 (and its chain-specific versions like EthereumGeneralAdapter1) handles common actions like token transfers, wrapping/unwrapping native currency, and core Morpho market/vault operations.
  • DEX Adapters: The ParaswapAdapter integrates with the ParaSwap DEX aggregator to perform token swaps, buys, and sells within the bundle.
  • Migration Adapters: Specialized adapters exist for migrating user positions from other protocols like Aave V2/V3 and Compound V2/V3 into Morpho seamlessly.