|
| 1 | +# Balancer Migration Progress |
| 2 | + |
| 3 | +## Completed ✅ |
| 4 | + |
| 5 | +### 1. Planning & Design |
| 6 | +- ✅ Created comprehensive V3 inventory (`V3_POOL_INVENTORY.md`) |
| 7 | +- ✅ Designed Balancer architecture (`BALANCER_MIGRATION_PLAN.md`) |
| 8 | +- ✅ Identified all V3 dependencies and integration points |
| 9 | + |
| 10 | +### 2. Balancer Pallet Foundation |
| 11 | +- ✅ Created pallet directory structure: `pallets/balancer-swap/` |
| 12 | +- ✅ Created `Cargo.toml` with proper dependencies |
| 13 | +- ✅ Implemented `types.rs` with: |
| 14 | + - `Pool` struct with weighted balances |
| 15 | + - `TokenType` enum |
| 16 | + - Spot price calculation |
| 17 | + - Helper methods with tests |
| 18 | +- ✅ Implemented `math.rs` with Balancer formulas: |
| 19 | + - `calc_out_given_in()` - Swap amount out calculation |
| 20 | + - `calc_in_given_out()` - Swap amount in calculation |
| 21 | + - `calc_spot_price()` - Price with fees |
| 22 | + - `calc_shares_for_single_token_in()` - LP shares for unbalanced add |
| 23 | + - `calc_token_out_for_shares()` - Token amount for LP burn |
| 24 | + - `calc_shares_proportional()` - Balanced liquidity shares |
| 25 | + - Comprehensive unit tests |
| 26 | + |
| 27 | +## In Progress 🔄 |
| 28 | + |
| 29 | +### 3. Main Pallet Implementation |
| 30 | +**Next Step**: Create `lib.rs` with: |
| 31 | +- Storage items (Pools, LiquidityShares, ProtocolShares) |
| 32 | +- Config trait |
| 33 | +- Extrinsics (add_liquidity, remove_liquidity, set parameters) |
| 34 | +- Events and Errors |
| 35 | +- SwapHandler trait implementation |
| 36 | + |
| 37 | +## Remaining Tasks 📋 |
| 38 | + |
| 39 | +### 4. Complete Balancer Pallet |
| 40 | +- [ ] Create `lib.rs` with full pallet logic |
| 41 | +- [ ] Implement `weights.rs` placeholder |
| 42 | +- [ ] Create `benchmarking.rs` for weight calculations |
| 43 | +- [ ] Write comprehensive tests in `tests.rs` |
| 44 | + |
| 45 | +### 5. Integration Updates |
| 46 | +- [ ] Update `pallets/swap-interface/src/lib.rs` if needed |
| 47 | +- [ ] Update `pallets/subtensor/src/coinbase/root.rs` |
| 48 | +- [ ] Update `pallets/subtensor/src/coinbase/run_coinbase.rs` |
| 49 | +- [ ] Update `pallets/subtensor/src/staking/claim_root.rs` |
| 50 | +- [ ] Update `pallets/subtensor/src/subnets/subnet.rs` |
| 51 | + |
| 52 | +### 6. Runtime & Precompiles |
| 53 | +- [ ] Update `runtime/src/lib.rs`: |
| 54 | + - Replace Swap pallet config with BalancerSwap |
| 55 | + - Update construct_runtime! macro |
| 56 | + - Update SwapInterface type alias |
| 57 | + - Update runtime API implementation |
| 58 | +- [ ] Verify `precompiles/src/alpha.rs` works with new SwapHandler |
| 59 | + |
| 60 | +### 7. Migration Function |
| 61 | +- [ ] Create runtime migration to convert V3 state to Balancer |
| 62 | +- [ ] Handle existing positions conversion to shares |
| 63 | +- [ ] Test migration on dev/test networks |
| 64 | + |
| 65 | +### 8. V3 Removal |
| 66 | +- [ ] Remove entire `pallets/swap/` directory |
| 67 | +- [ ] Remove V3 imports from all files |
| 68 | +- [ ] Remove V3 tests from subtensor |
| 69 | +- [ ] Remove V3 mock configurations |
| 70 | +- [ ] Update workspace Cargo.toml |
| 71 | + |
| 72 | +### 9. Testing & Validation |
| 73 | +- [ ] Run all unit tests |
| 74 | +- [ ] Run integration tests |
| 75 | +- [ ] Benchmark performance vs. V3 |
| 76 | +- [ ] Test on local devnet |
| 77 | +- [ ] Verify all swap scenarios work |
| 78 | +- [ ] Test unbalanced liquidity provision |
| 79 | +- [ ] Test weighted pools (non-50/50) |
| 80 | + |
| 81 | +### 10. Documentation |
| 82 | +- [ ] Update code documentation |
| 83 | +- [ ] Create migration guide for users |
| 84 | +- [ ] Document new Balancer features |
| 85 | +- [ ] Update API documentation |
| 86 | + |
| 87 | +## Key Files Created |
| 88 | + |
| 89 | +``` |
| 90 | +pallets/balancer-swap/ |
| 91 | +├── Cargo.toml ✅ Complete |
| 92 | +├── src/ |
| 93 | +│ ├── lib.rs 🔄 Next |
| 94 | +│ ├── types.rs ✅ Complete (185 lines) |
| 95 | +│ ├── math.rs ✅ Complete (382 lines) |
| 96 | +│ ├── weights.rs ⏸️ Pending |
| 97 | +│ ├── benchmarking.rs ⏸️ Pending |
| 98 | +│ └── tests.rs ⏸️ Pending |
| 99 | +
|
| 100 | +Documentation/ |
| 101 | +├── V3_POOL_INVENTORY.md ✅ Complete (900+ lines) |
| 102 | +├── BALANCER_MIGRATION_PLAN.md ✅ Complete (600+ lines) |
| 103 | +└── MIGRATION_PROGRESS.md ✅ This file |
| 104 | +``` |
| 105 | + |
| 106 | +## Estimated Remaining Work |
| 107 | + |
| 108 | +- **lib.rs**: ~600 lines (pallet core) |
| 109 | +- **weights.rs**: ~50 lines (placeholder) |
| 110 | +- **benchmarking.rs**: ~150 lines |
| 111 | +- **tests.rs**: ~400 lines |
| 112 | +- **Integration updates**: ~200 lines changes |
| 113 | +- **Runtime updates**: ~100 lines changes |
| 114 | +- **Migration function**: ~200 lines |
| 115 | +- **V3 removal**: Delete ~4,000 lines |
| 116 | + |
| 117 | +**Total new code**: ~1,700 lines |
| 118 | +**Total removed**: ~4,000 lines |
| 119 | +**Net reduction**: ~2,300 lines (57% reduction) |
| 120 | + |
| 121 | +## Next Immediate Steps |
| 122 | + |
| 123 | +1. **Create `lib.rs`** with: |
| 124 | + - Pallet struct and Config trait |
| 125 | + - Storage: `Pools<T>`, `LiquidityShares<T>`, `ProtocolShares<T>` |
| 126 | + - Extrinsics: `add_liquidity`, `remove_liquidity`, `set_pool_weights`, `set_swap_fee` |
| 127 | + - Internal functions: swap logic, share calculations |
| 128 | + - SwapHandler trait implementation |
| 129 | + - Events: LiquidityAdded, LiquidityRemoved, PoolParametersUpdated, Swapped |
| 130 | + - Errors: InsufficientBalance, PoolNotFound, InvalidWeights, etc. |
| 131 | + |
| 132 | +2. **Create weight placeholders** in `weights.rs` |
| 133 | + |
| 134 | +3. **Write basic tests** in `tests.rs` |
| 135 | + |
| 136 | +4. **Update runtime** to use BalancerSwap |
| 137 | + |
| 138 | +5. **Test compilation** and fix any issues |
| 139 | + |
| 140 | +## Status Summary |
| 141 | + |
| 142 | +**Progress**: ~20% complete |
| 143 | +- ✅ Design & planning |
| 144 | +- ✅ Core types & math |
| 145 | +- 🔄 Pallet implementation (in progress) |
| 146 | +- ⏸️ Integration updates (pending) |
| 147 | +- ⏸️ Testing & migration (pending) |
| 148 | +- ⏸️ V3 removal (pending) |
| 149 | + |
| 150 | +**Estimated Time Remaining**: 6-8 days |
| 151 | +- Day 1-2: Complete Balancer pallet |
| 152 | +- Day 3-4: Update integrations & runtime |
| 153 | +- Day 5: Migration function & testing |
| 154 | +- Day 6: V3 removal & cleanup |
| 155 | +- Day 7-8: Comprehensive testing & documentation |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +**Ready to continue with `lib.rs` implementation.** |
| 160 | + |
| 161 | + |
| 162 | + |
0 commit comments