@@ -878,13 +878,11 @@ impl<T: Config> Pallet<T> {
878878 rm. alpha . saturating_add ( rm. fee_alpha ) ;
879879
880880 // ---------------- USER: refund τ and convert α → stake ----------------
881- let tao_total_from_pool = rm. tao . saturating_add ( rm. fee_tao ) ;
882881 // 1) Refund τ principal directly.
883- if tao_total_from_pool > TaoCurrency :: ZERO {
884- T :: BalanceOps :: increase_balance ( & owner, tao_total_from_pool) ;
885- user_refunded_tao =
886- user_refunded_tao. saturating_add ( tao_total_from_pool) ;
887- T :: TaoReserve :: decrease_provided ( netuid, tao_total_from_pool) ;
882+ if rm. tao > TaoCurrency :: ZERO {
883+ T :: BalanceOps :: increase_balance ( & owner, rm. tao ) ;
884+ user_refunded_tao = user_refunded_tao. saturating_add ( rm. tao ) ;
885+ T :: TaoReserve :: decrease_provided ( netuid, rm. tao ) ;
888886 }
889887
890888 // 2) Stake ALL withdrawn α (principal + fees) to the best permitted validator.
@@ -947,16 +945,12 @@ impl<T: Config> Pallet<T> {
947945 /// Clear **protocol-owned** liquidity and wipe all swap state for `netuid`.
948946 /// # Returns
949947 /// * `(TaoCurrency, AlphaCurrency)` - The amount of TAO and ALPHA burned
950- pub fn do_clear_protocol_liquidity (
951- netuid : NetUid ,
952- ) -> Result < ( TaoCurrency , TaoCurrency , AlphaCurrency , AlphaCurrency ) , DispatchError > {
948+ pub fn do_clear_protocol_liquidity ( netuid : NetUid ) -> DispatchResult {
953949 let protocol_account = Self :: protocol_account_id ( ) ;
954950
955951 // 1) Force-close only protocol positions, burning proceeds.
956- let mut tao = TaoCurrency :: ZERO ;
957- let mut fee_tao = TaoCurrency :: ZERO ;
958- let mut alpha = AlphaCurrency :: ZERO ;
959- let mut fee_alpha = AlphaCurrency :: ZERO ;
952+ let mut burned_tao = TaoCurrency :: ZERO ;
953+ let mut burned_alpha = AlphaCurrency :: ZERO ;
960954
961955 // Collect protocol position IDs first to avoid mutating while iterating.
962956 let protocol_pos_ids: sp_std:: vec:: Vec < PositionId > = Positions :: < T > :: iter_prefix ( ( netuid, ) )
@@ -972,20 +966,27 @@ impl<T: Config> Pallet<T> {
972966 for pos_id in protocol_pos_ids {
973967 match Self :: do_remove_liquidity ( netuid, & protocol_account, pos_id) {
974968 Ok ( rm) => {
975- tao = tao. saturating_add ( rm. tao ) ;
976- fee_tao = fee_tao. saturating_add ( rm. fee_tao ) ;
977- alpha = alpha. saturating_add ( rm. alpha ) ;
978- fee_alpha = fee_alpha. saturating_add ( rm. fee_alpha ) ;
969+ let alpha_total_from_pool: AlphaCurrency =
970+ rm. alpha . saturating_add ( rm. fee_alpha ) ;
971+ let tao = rm. tao ;
972+
973+ if tao > TaoCurrency :: ZERO {
974+ burned_tao = burned_tao. saturating_add ( tao) ;
975+ }
976+ if alpha_total_from_pool > AlphaCurrency :: ZERO {
977+ burned_alpha = burned_alpha. saturating_add ( alpha_total_from_pool) ;
978+ }
979979
980980 log:: debug!(
981- "clear_protocol_liquidity: burned protocol pos: netuid={netuid:?}, \
982- pos_id={pos_id:?}, τ={fee_tao:?}, α={fee_alpha:?}; \
983- protocol liquidity: {tao:?}, {alpha:?}"
981+ "clear_protocol_liquidity: burned protocol pos: netuid={netuid:?}, pos_id={pos_id:?}, τ={tao:?}, α_total={alpha_total_from_pool:?}"
984982 ) ;
985983 }
986- Err ( e) => log:: debug!(
987- "clear_protocol_liquidity: force-close failed: netuid={netuid:?}, pos_id={pos_id:?}, err={e:?}"
988- ) ,
984+ Err ( e) => {
985+ log:: debug!(
986+ "clear_protocol_liquidity: force-close failed: netuid={netuid:?}, pos_id={pos_id:?}, err={e:?}"
987+ ) ;
988+ continue ;
989+ }
989990 }
990991 }
991992
@@ -1011,11 +1012,10 @@ impl<T: Config> Pallet<T> {
10111012 EnabledUserLiquidity :: < T > :: remove ( netuid) ;
10121013
10131014 log:: debug!(
1014- "clear_protocol_liquidity: netuid={netuid:?}, protocol_fees: τ={fee_tao:?}, α={fee_alpha:?}; \
1015- protocol liquidity: {tao:?}, {alpha:?}; state cleared"
1015+ "clear_protocol_liquidity: netuid={netuid:?}, protocol_burned: τ={burned_tao:?}, α={burned_alpha:?}; state cleared"
10161016 ) ;
10171017
1018- Ok ( ( tao , fee_tao , alpha , fee_alpha ) )
1018+ Ok ( ( ) )
10191019 }
10201020}
10211021
@@ -1138,9 +1138,7 @@ impl<T: Config> SwapHandler for Pallet<T> {
11381138 fn toggle_user_liquidity ( netuid : NetUid , enabled : bool ) {
11391139 EnabledUserLiquidity :: < T > :: insert ( netuid, enabled)
11401140 }
1141- fn clear_protocol_liquidity (
1142- netuid : NetUid ,
1143- ) -> Result < ( TaoCurrency , TaoCurrency , AlphaCurrency , AlphaCurrency ) , DispatchError > {
1141+ fn clear_protocol_liquidity ( netuid : NetUid ) -> DispatchResult {
11441142 Self :: do_clear_protocol_liquidity ( netuid)
11451143 }
11461144}
0 commit comments