Skip to main content

Overview

Mint swapping enables you to move ecash from one mint to another using the Lightning Network as an intermediary. This is essential for:
  • Rebalancing - Redistributing funds across mints
  • Exit strategy - Moving funds from untrusted mints
  • Liquidity management - Consolidating or spreading balances

How Swapping Works

Direct Swap (Single Hop)

  1. Create invoice on destination mint (Mint B)
  2. Melt ecash from source mint (Mint A) to pay invoice
  3. Receive ecash from destination mint

Code Example

Fee Handling

Swaps involve multiple fee layers:

Fee Components

Dynamic Fee Headroom

Sovran calculates fee headroom dynamically to avoid “not enough proofs” errors:

Fee Probing

Before executing, probe the actual fee_reserve:

Middleman Routing

When direct Lightning routes fail, Sovran automatically routes through intermediary mints:

Routing Strategy

When to use:
  • no_route error on direct swap
  • Insufficient Lightning liquidity
  • Geographic routing constraints
How it works:
  1. Detect no_route error during melt
  2. Query auditor API for successful swap pairs
  3. Build graph of mint connections
  4. Use BFS to find path from source to destination
  5. Execute chain of swaps (A → M → B)

Routing Implementation

Trust Management for Routing

Intermediaries are temporarily trusted during routing:

Swap Transactions Store

Swaps are tracked in swapTransactionsStore.ts for history and correlation:

Data Structure

Usage Example

Viewing Swap History

Swap transactions appear in the transactions list:

Error Handling

Common Errors

Retry Logic

Proof Recovery

If a swap fails, restore “inflight” proofs:

Pending State Handling

Some mints use async Lightning payments:

Balance Verification

After swapping, verify the destination mint received funds:

UI Components

Transfer Step Row

Chain Card (Middleman Route)

Best Practices

Before swapping large amounts, verify both mints have sufficient Lightning liquidity. Check recent swap success rates in audit data.
Set a minimum threshold (e.g., 10 sats) to avoid paying fees on tiny swaps:
Configure middleman routing behavior in settings:
Avoid running multiple swaps from the same mint simultaneously - use an execution lock to prevent “melt already in progress” errors.

Wallet Rebalancing

Automated multi-mint rebalancing

Know Your Mint

Check mint reliability before swapping