Overview
Wallet rebalancing automatically redistributes your ecash balance across multiple mints according to target percentages. This helps:- Reduce custodial risk - Spread funds across trusted mints
- Maintain liquidity - Ensure each mint has usable balance
- Optimize fees - Consolidate fragmented proofs
Balance Distribution Store
ThemintDistributionStore.ts manages target allocations per currency unit.
Data Structure
Usage Example
Automatic Redistribution
When you adjust one mint’s allocation, others are automatically rebalanced:Special Cases
100% → Less than 100%: When reducing a mint from 100%, all other mints are activated:bp > 0 participate in redistribution:
Quick Actions
Rebalance Planning
The rebalance planner (components/blocks/rebalance/rebalancePlanner.ts) calculates transfer steps:
Algorithm
Already Balanced Check
Rebalance Execution
The rebalance plan screen (app/(mint-flow)/rebalancePlan.tsx) executes transfer steps sequentially:
Step States
Execution Flow
Middleman Routing
When direct routing fails, automatically find intermediary path:Execution Lock
Prevent concurrent melt operations:UI Components
Distribution Editor
The distribution screen (app/(mint-flow)/distribution.tsx) shows:
- Sliders for each mint’s allocation
- Quick actions (Equalize, Max, Min)
- Preview of target balances
- Launch rebalance button
Rebalance Plan Screen
The plan screen (app/(mint-flow)/rebalancePlan.tsx) displays:
Step Grouping
Chain steps (middleman routes) are grouped visually:Advanced: Routing Graph
The routing system uses BFS to find intermediary paths:Graph Construction
Path Selection
Local History Candidates
Best Practices
Set Conservative Distributions
Set Conservative Distributions
Avoid setting a single mint to >50% allocation. Distribute across 3-5 mints for redundancy.
Use Minimum Transfer Threshold
Use Minimum Transfer Threshold
Set
minTransferThreshold to 10-20 sats to avoid wasting fees on micro-transfers:Rebalance Periodically
Rebalance Periodically
Run rebalance weekly or when distributions drift >10% from targets.
Monitor Failed Steps
Monitor Failed Steps
If steps consistently fail for a mint, consider removing it from your trusted list.
Debugging
Rebalance operations log to console with structured debug events:step_start- Transfer step beginsbalances_fetched- Current balances retrievedfee_headroom_computed- Dynamic fees calculatedmelt_prepared- Quote received from mintno_route_auto_routing- Routing failure, trying middlemanchain_hop_start- Middleman hop beginsstep_done- Transfer complete
Related Documentation
Mint Swapping
Learn about the underlying swap mechanism
Know Your Mint
Use trust signals to set distributions