Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b6cb088
impl tests benchmarks
camfairchild Nov 5, 2025
3118bb7
bump spec
camfairchild Nov 5, 2025
843bc88
remove duplicate remove
camfairchild Nov 5, 2025
fb053c8
use alpha out here
camfairchild Nov 5, 2025
cb2085e
Hotfix/vune/epoch sub fix (#2186)
0xcacti Nov 5, 2025
b068d02
emit full alpha if subsidized
camfairchild Nov 5, 2025
7d77cf0
fix coinbase test
camfairchild Nov 5, 2025
e792dd1
fix tests
camfairchild Nov 5, 2025
d7a28ba
Revert "Hotfix/vune/epoch sub fix (#2186)"
camfairchild Nov 5, 2025
a837632
add total issuance bump
camfairchild Nov 5, 2025
6bddb56
no alpha out thing
camfairchild Nov 6, 2025
b857d4d
add tests for emissions w/ subs
camfairchild Nov 6, 2025
e1feb05
bump spec
camfairchild Nov 6, 2025
ad602c1
Fix clippy warnings
shamil-gadelshin Nov 6, 2025
cac43c5
Hotfix/vune/epoch sub fix (#2186)
0xcacti Nov 5, 2025
85fe2d4
rename drain_pending to distr em
camfairchild Nov 6, 2025
90d4be4
remove arg and total internally
camfairchild Nov 6, 2025
f81986b
test pending em
camfairchild Nov 6, 2025
be16df6
make sure we check subsidize during those tests
camfairchild Nov 6, 2025
69249f4
fix root claim tests
camfairchild Nov 6, 2025
9762f6a
helper and clippy
camfairchild Nov 6, 2025
94d31d7
bump spec
camfairchild Nov 6, 2025
186c717
rename subsidy to root flag
camfairchild Nov 6, 2025
25290f1
only pull these values if root selling
camfairchild Nov 6, 2025
d3698bf
rename subsidy checks to the root_sell flag
camfairchild Nov 6, 2025
62ecfe1
rename subsidy to excess_tao
camfairchild Nov 6, 2025
c5a7f51
use recycle alpha helper
camfairchild Nov 6, 2025
75440be
Hotfix/vune/subnet-dereg-burn-use-issuance (#2190)
camfairchild Nov 6, 2025
40b4ffc
remove log out
camfairchild Nov 6, 2025
c474b21
Merge remote-tracking branch 'origin/main' into devnet
sam0x17 Nov 7, 2025
8237617
Merge remote-tracking branch 'origin/hotfix/vune/recycle-root-alpha-i…
sam0x17 Nov 7, 2025
6684a27
Merge remote-tracking branch 'origin/hotfix/sn-to-emit-to' into devnet
sam0x17 Nov 10, 2025
69fb210
Merge remote-tracking branch 'origin/hotfix/sn-to-emit-to' into devnet
sam0x17 Nov 10, 2025
1615fd7
Merge remote-tracking branch 'origin/hotfix/sn-to-emit-to' into testnet
camfairchild Nov 12, 2025
f89b7d9
Merge remote-tracking branch 'origin/main' into testnet
sam0x17 Nov 12, 2025
4f9da00
use protocol tao only for tao flow calculation
0xcacti Nov 14, 2025
442ab4f
chore: trigger build
0xcacti Nov 14, 2025
7f20e82
Merge pull request #2205 from subtrahend-labs/fix/liquidity-tracking
sam0x17 Nov 14, 2025
dba7e53
bump spec version
sam0x17 Nov 14, 2025
11c6330
Fix: tao flow tracking proto lp (#2214)
camfairchild Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions pallets/subtensor/src/staking/stake_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ impl<T: Config> Pallet<T> {
SubnetAlphaIn::<T>::get(netuid).saturating_add(SubnetAlphaOut::<T>::get(netuid))
}

pub fn get_protocol_tao(netuid: NetUid) -> TaoCurrency {
T::SwapInterface::get_protocol_tao(netuid)
}

pub fn get_moving_alpha_price(netuid: NetUid) -> U96F32 {
let one = U96F32::saturating_from_num(1.0);
if netuid.is_root() {
Expand Down Expand Up @@ -688,6 +692,9 @@ impl<T: Config> Pallet<T> {
price_limit: TaoCurrency,
drop_fees: bool,
) -> Result<TaoCurrency, DispatchError> {
// Record the protocol TAO before the swap.
let protocol_tao = Self::get_protocol_tao(netuid);

// Decrease alpha on subnet
let actual_alpha_decrease =
Self::decrease_stake_for_hotkey_and_coldkey_on_subnet(hotkey, coldkey, netuid, alpha);
Expand All @@ -696,6 +703,13 @@ impl<T: Config> Pallet<T> {
let swap_result =
Self::swap_alpha_for_tao(netuid, actual_alpha_decrease, price_limit, drop_fees)?;

// Record the protocol TAO after the swap.
let protocol_tao_after = Self::get_protocol_tao(netuid);
// This should decrease as we are removing TAO from the protocol.
let protocol_tao_delta: TaoCurrency = protocol_tao.saturating_sub(protocol_tao_after);
// Use max to overstate the TAO flow from the protocol.
let tao_flow = protocol_tao_delta.max(swap_result.amount_paid_out.into());

// Refund the unused alpha (in case if limit price is hit)
let refund = actual_alpha_decrease.saturating_sub(
swap_result
Expand All @@ -722,7 +736,7 @@ impl<T: Config> Pallet<T> {
// }

// Record TAO outflow
Self::record_tao_outflow(netuid, swap_result.amount_paid_out.into());
Self::record_tao_outflow(netuid, tao_flow);

LastColdkeyHotkeyStakeBlock::<T>::insert(coldkey, hotkey, Self::get_current_block_as_u64());

Expand Down Expand Up @@ -761,9 +775,20 @@ impl<T: Config> Pallet<T> {
set_limit: bool,
drop_fees: bool,
) -> Result<AlphaCurrency, DispatchError> {
// Record the protocol TAO before the swap.
let protocol_tao = Self::get_protocol_tao(netuid);

// Swap the tao to alpha.
let swap_result = Self::swap_tao_for_alpha(netuid, tao, price_limit, drop_fees)?;

// Record the protocol TAO after the swap.
let protocol_tao_after = Self::get_protocol_tao(netuid);

// This should increase as we are adding TAO to the protocol.
let protocol_tao_delta: TaoCurrency = protocol_tao_after.saturating_sub(protocol_tao);
// Use min to understate the TAO flow into the protocol.
let tao_flow = protocol_tao_delta.min(tao);

ensure!(
!swap_result.amount_paid_out.is_zero(),
Error::<T>::AmountTooLow
Expand Down Expand Up @@ -799,7 +824,7 @@ impl<T: Config> Pallet<T> {
}

// Record TAO inflow
Self::record_tao_inflow(netuid, swap_result.amount_paid_in.into());
Self::record_tao_inflow(netuid, tao_flow);

LastColdkeyHotkeyStakeBlock::<T>::insert(coldkey, hotkey, Self::get_current_block_as_u64());

Expand Down
13 changes: 6 additions & 7 deletions pallets/subtensor/src/tests/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5596,14 +5596,13 @@ fn test_staking_records_flow() {
mock::setup_reserves(netuid, tao_reserve, alpha_in);

// Initialize swap v3
let order = GetAlphaForTao::<Test>::with_amount(0);
assert_ok!(<tests::mock::Test as pallet::Config>::SwapInterface::swap(
netuid.into(),
order,
TaoCurrency::MAX,
SubtensorModule::swap_tao_for_alpha(
netuid,
TaoCurrency::ZERO,
1_000_000_000_000.into(),
false,
true
));
)
.unwrap();

// Add stake with slippage safety and check if the result is ok
assert_ok!(SubtensorModule::stake_into_subnet(
Expand Down
1 change: 1 addition & 0 deletions pallets/swap-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub trait SwapHandler {

fn approx_fee_amount<T: Currency>(netuid: NetUid, amount: T) -> T;
fn current_alpha_price(netuid: NetUid) -> U96F32;
fn get_protocol_tao(netuid: NetUid) -> TaoCurrency;
fn max_price<C: Currency>() -> C;
fn min_price<C: Currency>() -> C;
fn adjust_protocol_liquidity(
Expand Down
18 changes: 18 additions & 0 deletions pallets/swap/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,24 @@ impl<T: Config> SwapHandler for Pallet<T> {
Self::current_price(netuid.into())
}

fn get_protocol_tao(netuid: NetUid) -> TaoCurrency {
let protocol_account_id = Self::protocol_account_id();
let mut positions =
Positions::<T>::iter_prefix_values((netuid, protocol_account_id.clone()))
.collect::<sp_std::vec::Vec<_>>();

if let Some(position) = positions.get_mut(0) {
let current_sqrt_price = AlphaSqrtPrice::<T>::get(netuid);
// Adjust liquidity
let maybe_token_amounts = position.to_token_amounts(current_sqrt_price);
if let Ok((tao, _)) = maybe_token_amounts {
return tao.into();
}
}

TaoCurrency::ZERO
}

fn min_price<C: Currency>() -> C {
Self::min_price_inner()
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 345,
spec_version: 347,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading