Bundles

Bundles repository

Bundles structure

Most Bundle entrypoints share the same building blocks:

  • Token permits - each underlying token the Bundle pulls from the caller accepts an optional TokenPermit, either an ERC-2612 permit or a Permit2 SignatureTransfer, so the approval and the operation land in one transaction. An empty permit means the caller granted a standard ERC-20 allowance to the Bundle beforehand. MidnightBundlesV2 uses separate standard ERC-20 approvals and accepts no inline Permit or Permit2 signatures.
  • Share permits - share-based entrypoints (vaultBundlesV1Withdraw, vaultBundlesV1Migrate, vaultExitBundlesV1InKindRedemptionVaultV1, vaultExitBundlesV1InKindRedemptionVaultV2, and vaultExitBundlesV1ForceWithdrawVaultV2) take an ERC-2612 Permit on the vault shares instead, or rely on a prior share allowance to the Bundle. Shares never go through Permit2.
  • Signed authorization - BlueBundlesV1 entrypoints that act on the caller's Morpho position (borrow, withdraw, repay-and-withdraw-collateral, migrate) accept an optional Morpho SignedAuthorization so the caller can authorize the Bundle in the same transaction. An empty signature means the Bundle is already authorized. Vault entrypoints take share permits, not Morpho authorizations.
  • Public allocations - entrypoints that consume market liquidity accept a list of Vault V2 BluePublicAllocator reallocations executed before the operation.

The deployment addresses of every Bundle are listed in the addresses page.

Referral fees and deadlines

Eligible Blue and Vault Bundle entrypoints can collect optional referral fees, paid to a configured recipient in the same transaction.

  • referralFeePct: WAD-scaled percentage, strictly below WAD; pass 0 for no fee.
  • referralFeeRecipient: address that receives the fee.
  • deadline: timestamp after which the entrypoint reverts.
Entrypoint(s)Fee baseFormula
blueBundlesV1Supply, vaultBundlesV1DepositAssets pulled from the callerfee = assets * referralFeePct / WAD; the remainder is supplied or deposited.
blueBundlesV1SupplyCollateralAndBorrow, blueBundlesV1WithdrawLoan-token proceeds after public allocator penaltiesfee = proceeds * referralFeePct / WAD; the remainder is sent to the caller.
vaultBundlesV1Withdraw, vaultExitBundlesV1ForceWithdrawVaultV2Assets withdrawn after any force-deallocate penaltyfee = withdrawnAssets * referralFeePct / WAD; the remainder is sent to the caller.
blueBundlesV1RepayAndWithdrawCollateralActual assets repaidfee = repaidAssets * referralFeePct / (WAD - referralFeePct); the fee is charged on top.
blueBundlesV1MigrateBorrowPositionSource-market debt repaidfee = repaidAssets * referralFeePct / (WAD - referralFeePct); the fee and any allocator penalties increase destination debt.
vaultBundlesV1MigrateAssets withdrawn from the source vaultfee = withdrawnAssets * referralFeePct / WAD; the remainder is deposited into the destination vault.
vaultExitBundlesV1InKindRedemptionVaultV1, vaultExitBundlesV1InKindRedemptionVaultV2No fee baseNo referral fee.

For guidance on charging a borrow fee through Bundles and related Blue and Vault operations, see How to monetize your borrow product.

Every MidnightBundlesV2 entrypoint requires a deadline. Four taker entrypoints accept referral-fee fields, while midnightBundlesV2CancelAndMake does not. See How the referral fee works.

BlueBundlesV1

BlueBundlesV1.sol

Entrypoints for Variable Rate Markets (Morpho Blue):

EntrypointWhat it does
blueBundlesV1SupplySupply loan assets to a market.
blueBundlesV1WithdrawWithdraw supplied loan assets, by assets or by shares.
blueBundlesV1SupplyCollateralAndBorrowSupply collateral and borrow, bounded by a maxLtv check.
blueBundlesV1RepayAndWithdrawCollateralRepay debt, by assets or by shares, and withdraw collateral, bounded by a maxLtv check.
blueBundlesV1MigrateBorrowPositionMove a full borrow position (collateral and debt) from one market to another in one transaction - the source debt is repaid atomically with assets borrowed on the destination market, so the caller needs no assets for repayment.

blueBundlesV1SupplyCollateralAndBorrow, blueBundlesV1Withdraw and blueBundlesV1MigrateBorrowPosition accept Vault V2 BluePublicAllocator reallocations.

VaultBundlesV1

VaultBundlesV1.sol

Entrypoints for Vault V1 and Vault V2:

EntrypointWhat it does
vaultBundlesV1DepositDeposit assets into a vault.
vaultBundlesV1WithdrawWithdraw assets from a vault.
vaultBundlesV1MigrateMigrate assets from one vault to another vault.

VaultExitBundlesV1

VaultExitBundlesV1.sol

Exit paths for vaults whose liquidity is constrained:

EntrypointWhat it does
vaultExitBundlesV1InKindRedemptionVaultV1Redeem in kind from an illiquid Vault V1.
vaultExitBundlesV1InKindRedemptionVaultV2Withdraw idle assets and redeem the remainder in kind from an illiquid Vault V2.
vaultExitBundlesV1ForceWithdrawVaultV2Force withdraw assets from an illiquid Vault V2 whose underlying markets are liquid, paying the force-deallocate penalty (idle and liquidity-adapter assets are withdrawn penalty-free first).

MidnightBundlesV2

MidnightBundlesV2.sol
EntrypointWhat it does
midnightBundlesV2CancelAndMakeCancels selected offer groups, optionally supplies collateral or parks loan assets on Blue, and atomically activates a new offer root and logs its payload.
midnightBundlesV2BuyWithUnitsTargetAndWithdrawCollateralTakes offers toward a units target, can repay remaining debt, and withdraw collateral.
midnightBundlesV2BuyWithAssetsTargetAndWithdrawCollateralTakes offers toward an asset target, can repay remaining debt, and withdraw collateral.
midnightBundlesV2SupplyCollateralAndSellWithUnitsTargetSupplies collateral and takes offers toward a units target.
midnightBundlesV2SupplyCollateralAndSellWithAssetsTargetSupplies collateral and takes offers toward an asset target.
  • Operations act on msg.sender's position; MidnightBundlesV2 entrypoints do not accept a taker address.
  • Token pulls use separate ERC-20 approvals rather than inline Permit or Permit2. When msg.value is positive, MidnightBundlesV2 wraps the supplied native token and transfers it to the caller.
  • The two buy entrypoints can repay debt and withdraw collateral, and the two sell entrypoints can supply collateral. The separate MidnightBundlesV1 repay-and-withdraw path is removed.
  • Maker publication is atomic: selected offer-group cancellations, optional collateral supply or Blue asset parking, ratifier root activation, and payload logging share one call.
  • MidnightBundlesV2 adds reduce-only bounds, and every entrypoint takes a deadline.

MidnightBundlesV1 compatibility: MidnightBundlesV1 remains functional, and migrating to MidnightBundlesV2 is optional. The Bundles changelog Source code table links both contract versions.

Permit2

In November 2022, Uniswap Labs introduced Permit2, a robust token approval contract designed to standardize and secure token approvals across various smart contracts. By enabling signature-based approvals and efficient management of token allowances, Permit2 significantly enhances the user experience. It reduces transaction costs and bolsters smart contract security by mitigating risks associated with traditional approval methods.

Bundles accept Permit2 SignatureTransfer permits, naming the Bundle as spender, as an alternative to ERC-2612 permits and standard ERC-20 approvals. MidnightBundlesV2 accepts no Permit2 signature and requires a standard ERC-20 approval. Discover the full potential of Permit2 and how it revolutionizes token approvals in the integration guide.

Bundler3 (deprecated)

Bundles are protocol-specific by design. Flows that Bundler3 enabled through arbitrary call composition - DEX swaps and leverage via ParaswapAdapter, migrations from other lending protocols via the migration adapters, and Vault V1 PublicAllocator reallocations - have no Bundle equivalent today.