From 8ac42bb2509bbdd01df235224ddbf135f5da5a15 Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Fri, 12 Jun 2026 15:07:07 -0400 Subject: [PATCH 1/2] Handle dust in order_swap.rs and leasing.rs to sync TI --- pallets/subtensor/src/staking/order_swap.rs | 5 +--- pallets/subtensor/src/subnets/leasing.rs | 23 +++------------- pallets/subtensor/src/tests/tao.rs | 30 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/pallets/subtensor/src/staking/order_swap.rs b/pallets/subtensor/src/staking/order_swap.rs index fd0ae3461c..9cf428d74c 100644 --- a/pallets/subtensor/src/staking/order_swap.rs +++ b/pallets/subtensor/src/staking/order_swap.rs @@ -1,6 +1,4 @@ use super::*; -use frame_support::traits::fungible::Mutate; -use frame_support::traits::tokens::Preservation; use frame_support::transactional; use substrate_fixed::types::U64F64; use subtensor_runtime_common::{AlphaBalance, NetUid, TaoBalance}; @@ -103,8 +101,7 @@ impl OrderSwapInterface for Pallet { } fn transfer_tao(from: &T::AccountId, to: &T::AccountId, amount: TaoBalance) -> DispatchResult { - ::Currency::transfer(from, to, amount, Preservation::Expendable)?; - Ok(()) + Pallet::::transfer_tao(from, to, amount) } #[transactional] diff --git a/pallets/subtensor/src/subnets/leasing.rs b/pallets/subtensor/src/subnets/leasing.rs index d3e1b84df5..3ba615b4c5 100644 --- a/pallets/subtensor/src/subnets/leasing.rs +++ b/pallets/subtensor/src/subnets/leasing.rs @@ -18,7 +18,7 @@ use super::*; use frame_support::{ dispatch::RawOrigin, - traits::{Defensive, fungible::*, tokens::Preservation}, + traits::{Defensive, fungible::*}, }; use frame_system::pallet_prelude::OriginFor; use frame_system::pallet_prelude::*; @@ -92,12 +92,7 @@ impl Pallet { frame_system::Pallet::::inc_providers(&lease_coldkey); frame_system::Pallet::::inc_providers(&lease_hotkey); - ::Currency::transfer( - &crowdloan.funds_account, - &lease_coldkey, - crowdloan.raised, - Preservation::Expendable, - )?; + Self::transfer_tao(&crowdloan.funds_account, &lease_coldkey, crowdloan.raised)?; Self::do_register_network( RawOrigin::Signed(lease_coldkey.clone()).into(), @@ -151,23 +146,13 @@ impl Pallet { .saturating_mul(U64F64::from(u64::from(leftover_cap))) .floor() .saturating_to_num::(); - ::Currency::transfer( - &lease_coldkey, - &contributor, - contributor_refund.into(), - Preservation::Expendable, - )?; + Self::transfer_tao(&lease_coldkey, &contributor, contributor_refund.into())?; refunded_cap = refunded_cap.saturating_add(contributor_refund); } // Refund what's left after refunding the contributors to the beneficiary let beneficiary_refund = leftover_cap.saturating_sub(refunded_cap.into()); - ::Currency::transfer( - &lease_coldkey, - &who, - beneficiary_refund, - Preservation::Expendable, - )?; + Self::transfer_tao(&lease_coldkey, &who, beneficiary_refund)?; Self::deposit_event(Event::SubnetLeaseCreated { beneficiary: who, diff --git a/pallets/subtensor/src/tests/tao.rs b/pallets/subtensor/src/tests/tao.rs index b79b80e3f3..320b447545 100644 --- a/pallets/subtensor/src/tests/tao.rs +++ b/pallets/subtensor/src/tests/tao.rs @@ -19,6 +19,7 @@ use frame_support::{ use sp_core::U256; use sp_runtime::traits::{AccountIdConversion, Zero}; use subtensor_runtime_common::TaoBalance; +use subtensor_swap_interface::OrderSwapInterface; const MAX_TAO_ISSUANCE: u64 = 21_000_000_000_000_000_u64; @@ -500,6 +501,35 @@ fn test_transfer_tao_reaps_origin() { }); } +#[test] +fn test_order_swap_transfer_tao_reaps_origin_and_updates_subtensor_total_issuance() { + new_test_ext(1).execute_with(|| { + let origin = U256::from(1); + let dest = U256::from(2); + + let ed = ExistentialDeposit::get(); + let dust = ed - 1u64.into(); + let amount = TaoBalance::from(1_000); + add_balance_to_coldkey_account(&origin, amount + dust); + + let subtensor_ti_before = subtensor_total_issuance(); + let balances_ti_before = balances_total_issuance(); + + assert_ok!(>::transfer_tao( + &origin, &dest, amount + )); + + let subtensor_ti_after = subtensor_total_issuance(); + let balances_ti_after = balances_total_issuance(); + + assert_eq!(Balances::total_balance(&origin), 0.into()); + assert_eq!(Balances::total_balance(&dest), amount); + assert_eq!(balances_ti_before - balances_ti_after, dust); + assert_eq!(subtensor_ti_before - subtensor_ti_after, dust); + assert_eq!(balances_ti_after, subtensor_ti_after); + }); +} + #[test] fn test_recycle_tao_cannot_cross_preserve_threshold_in_high_ed_runtime() { new_test_ext(1).execute_with(|| { From 8595e4781eae9fee02821aa99be8b10119c6b58a Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Fri, 12 Jun 2026 15:50:03 -0400 Subject: [PATCH 2/2] Fix test_swap_owner_new_hotkey_already_exists --- pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs b/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs index 426572bdcd..76dcd0a9ad 100644 --- a/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs +++ b/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs @@ -926,7 +926,7 @@ fn test_swap_owner_new_hotkey_already_exists() { Some(netuid), false ), - Error::::HotKeyAlreadyRegisteredInSubNet + Error::::NonAssociatedColdKey ); // Verify the swap