@@ -1362,23 +1362,22 @@ impl<T: Config> Pallet<T> {
13621362 let mechid = T :: SubnetInfo :: mechanism ( netuid. into ( ) ) ;
13631363 let v3_initialized = SwapV3Initialized :: < T > :: get ( netuid) ;
13641364 let user_lp_enabled =
1365- <Self as subtensor_swap_interface:: SwapHandler < T :: AccountId > >:: is_user_liquidity_enabled ( netuid) ;
1365+ <Self as subtensor_swap_interface:: SwapHandler < T :: AccountId > >:: is_user_liquidity_enabled ( netuid) ;
13661366
13671367 let is_v3_mode = mechid == 1 && v3_initialized;
13681368
13691369 if is_v3_mode {
13701370 // -------- V3: close every position, aggregate refunds, clear state --------
13711371
1372- // 1) Snapshot all (owner, position_id) under this netuid to avoid iterator aliasing .
1372+ // 1) Snapshot all (owner, position_id).
13731373 struct CloseItem < A > {
13741374 owner : A ,
13751375 pos_id : PositionId ,
13761376 }
13771377 let mut to_close: sp_std:: vec:: Vec < CloseItem < T :: AccountId > > = sp_std:: vec:: Vec :: new ( ) ;
1378- for ( ( n, owner, pos_id) , _pos) in Positions :: < T > :: iter ( ) {
1379- if n == netuid {
1380- to_close. push ( CloseItem { owner, pos_id } ) ;
1381- }
1378+
1379+ for ( ( owner, pos_id) , _pos) in Positions :: < T > :: iter_prefix ( ( netuid, ) ) {
1380+ to_close. push ( CloseItem { owner, pos_id } ) ;
13821381 }
13831382
13841383 let protocol_account = Self :: protocol_account_id ( ) ;
@@ -1428,22 +1427,17 @@ impl<T: Config> Pallet<T> {
14281427 ActiveTickIndexManager :: < T > :: remove ( netuid, ti) ;
14291428 }
14301429
1431- // 5) Clear storage:
1432- // Positions (StorageNMap) – prefix is **(netuid,)** not just netuid.
1430+ // 5) Clear storage for this netuid.
14331431 let _ = Positions :: < T > :: clear_prefix ( ( netuid, ) , u32:: MAX , None ) ;
1434-
1435- // Ticks (DoubleMap) – OK to pass netuid as first key.
14361432 let _ = Ticks :: < T > :: clear_prefix ( netuid, u32:: MAX , None ) ;
14371433
1438- // Fee globals, price/tick/liquidity, v3 init flag.
14391434 FeeGlobalTao :: < T > :: remove ( netuid) ;
14401435 FeeGlobalAlpha :: < T > :: remove ( netuid) ;
14411436 CurrentLiquidity :: < T > :: remove ( netuid) ;
14421437 CurrentTick :: < T > :: remove ( netuid) ;
14431438 AlphaSqrtPrice :: < T > :: remove ( netuid) ;
14441439 SwapV3Initialized :: < T > :: remove ( netuid) ;
14451440
1446- // Active tick bitmap words (StorageNMap) – prefix is **(netuid,)**.
14471441 let _ = TickIndexBitmapWords :: < T > :: clear_prefix ( ( netuid, ) , u32:: MAX , None ) ;
14481442 FeeRate :: < T > :: remove ( netuid) ;
14491443 EnabledUserLiquidity :: < T > :: remove ( netuid) ;
0 commit comments