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)
- Create invoice on destination mint (Mint B)
- Melt ecash from source mint (Mint A) to pay invoice
- 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_routeerror on direct swap- Insufficient Lightning liquidity
- Geographic routing constraints
- Detect
no_routeerror during melt - Query auditor API for successful swap pairs
- Build graph of mint connections
- Use BFS to find path from source to destination
- 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 inswapTransactionsStore.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
Check Liquidity First
Check Liquidity First
Before swapping large amounts, verify both mints have sufficient Lightning liquidity. Check recent swap success rates in audit data.
Use Minimum Transfer Threshold
Use Minimum Transfer Threshold
Set a minimum threshold (e.g., 10 sats) to avoid paying fees on tiny swaps:
Monitor Routing Preferences
Monitor Routing Preferences
Configure middleman routing behavior in settings:
Handle Concurrency
Handle Concurrency
Avoid running multiple swaps from the same mint simultaneously - use an execution lock to prevent “melt already in progress” errors.
Related Documentation
Wallet Rebalancing
Automated multi-mint rebalancing
Know Your Mint
Check mint reliability before swapping