Skip to main content
Cleanup transactions ensure users get their tokens back if something fails mid-execution—especially important for cross-chain flows.

Why Cleanups Matter

Single-chain flows are atomic: all succeed or all fail. Cross-chain flows aren’t—a bridge might succeed but the destination swap fails, leaving tokens stranded. Cleanups automatically return leftover tokens to the user.

Fusion Mode

For external wallets (MetaMask, Rabby):
const quote = await meeClient.getFusionQuote({
  trigger,
  instructions: [bridge, swap, deposit],
  cleanUps: [
    {
      chainId: base.id,
      tokenAddress: USDC,
      recipientAddress: userEOA
    }
  ],
  feeToken: { chainId: base.id, address: USDC }
});
No dependsOn needed—Fusion batches everything automatically.

EIP-7702 / Smart Account Mode

For embedded wallets or SCAs:
const quote = await meeClient.getQuote({
  instructions: [bridge, swap, deposit],
  cleanUps: [
    {
      chainId: base.id,
      tokenAddress: USDC,
      recipientAddress: userEOA,
      dependsOn: [userOp(2)]  // Wait for instruction 2
    }
  ],
  feeToken: { chainId: base.id, address: USDC }
});
Use dependsOn when cleanup should wait for specific instructions.

Multi-Token Cleanup

Return multiple tokens:
cleanUps: [
  {
    chainId: base.id,
    tokenAddress: USDT,
    recipientAddress: userEOA,
    dependsOn: [userOp(1)]
  },
  {
    chainId: base.id,
    tokenAddress: USDC,
    recipientAddress: userEOA,
    dependsOn: [userOp(2)]
  }
]
Each cleanup executes after its dependency resolves.

How It Works

  1. Cleanup instructions are added to the transaction
  2. They wait until dependent operations complete
  3. Transfer any remaining balance back to user
  4. If balance is 0, cleanup harmlessly reverts
Cleanups always run last and only transfer tokens that remain in the smart account.

When to Use

ScenarioUse Cleanup?
Cross-chain bridge + swap✅ Yes
Multi-step DeFi flow✅ Yes
Simple single-chain transfer❌ Not needed
Atomic single-chain batch❌ Not needed

Tips

  • Fusion: Skip dependsOn—handled automatically
  • EIP-7702/SCA: Use dependsOn for non-sequential flows
  • Always set recipientAddress to the user’s EOA
  • Cleanups prevent funds from being stuck in intermediate accounts