Skip to main content

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

The mintDistributionStore.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:
Active-only redistribution: Normally, only mints with 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

Avoid setting a single mint to >50% allocation. Distribute across 3-5 mints for redundancy.
Set minTransferThreshold to 10-20 sats to avoid wasting fees on micro-transfers:
Run rebalance weekly or when distributions drift >10% from targets.
If steps consistently fail for a mint, consider removing it from your trusted list.

Debugging

Rebalance operations log to console with structured debug events:
Key events:
  • step_start - Transfer step begins
  • balances_fetched - Current balances retrieved
  • fee_headroom_computed - Dynamic fees calculated
  • melt_prepared - Quote received from mint
  • no_route_auto_routing - Routing failure, trying middleman
  • chain_hop_start - Middleman hop begins
  • step_done - Transfer complete

Mint Swapping

Learn about the underlying swap mechanism

Know Your Mint

Use trust signals to set distributions