From 704240b63213b2cb2a677df4535d897ddc79e59d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=B5?= Date: Thu, 28 Aug 2025 21:23:30 +0200 Subject: [PATCH 1/5] run_coinbase(): move log::debug() statements in preparation of refactor --- pallets/subtensor/src/coinbase/run_coinbase.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 73fc928e9..3bc5785d9 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -123,9 +123,6 @@ impl Pallet { alpha_in.insert(*netuid_i, alpha_in_i); alpha_out.insert(*netuid_i, alpha_out_i); } - log::debug!("tao_in: {tao_in:?}"); - log::debug!("alpha_in: {alpha_in:?}"); - log::debug!("alpha_out: {alpha_out:?}"); // --- 4. Injection. // Actually perform the injection of alpha_in, alpha_out and tao_in into the subnet pool. @@ -162,6 +159,10 @@ impl Pallet { T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_i, alpha_in_i); } + log::debug!("tao_in: {tao_in:?}"); + log::debug!("alpha_in: {alpha_in:?}"); + log::debug!("alpha_out: {alpha_out:?}"); + // --- 5. Compute owner cuts and remove them from alpha_out remaining. // Remove owner cuts here so that we can properly seperate root dividends in the next step. // Owner cuts are accumulated and then fed to the drain at the end of this func. From 8a464a1f511ffe986e9887d1e1f076a35f21f5e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=B5?= Date: Thu, 28 Aug 2025 21:26:07 +0200 Subject: [PATCH 2/5] run_coinbase(): rename _i variables to _curr in step 4 for loop, in preparation of refactor --- .../subtensor/src/coinbase/run_coinbase.rs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 3bc5785d9..004627f30 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -129,34 +129,34 @@ impl Pallet { // This operation changes the pool liquidity each block. for netuid_i in subnets_to_emit_to.iter() { // Inject Alpha in. - let alpha_in_i = + let alpha_in_curr = AlphaCurrency::from(tou64!(*alpha_in.get(netuid_i).unwrap_or(&asfloat!(0)))); - SubnetAlphaInEmission::::insert(*netuid_i, alpha_in_i); + SubnetAlphaInEmission::::insert(*netuid_i, alpha_in_curr); SubnetAlphaIn::::mutate(*netuid_i, |total| { - *total = total.saturating_add(alpha_in_i); + *total = total.saturating_add(alpha_in_curr); }); // Injection Alpha out. - let alpha_out_i = + let alpha_out_curr = AlphaCurrency::from(tou64!(*alpha_out.get(netuid_i).unwrap_or(&asfloat!(0)))); - SubnetAlphaOutEmission::::insert(*netuid_i, alpha_out_i); + SubnetAlphaOutEmission::::insert(*netuid_i, alpha_out_curr); SubnetAlphaOut::::mutate(*netuid_i, |total| { - *total = total.saturating_add(alpha_out_i); + *total = total.saturating_add(alpha_out_curr); }); // Inject TAO in. - let tao_in_i: TaoCurrency = + let tao_in_curr: TaoCurrency = tou64!(*tao_in.get(netuid_i).unwrap_or(&asfloat!(0))).into(); - SubnetTaoInEmission::::insert(*netuid_i, TaoCurrency::from(tao_in_i)); + SubnetTaoInEmission::::insert(*netuid_i, TaoCurrency::from(tao_in_curr)); SubnetTAO::::mutate(*netuid_i, |total| { - *total = total.saturating_add(tao_in_i.into()); + *total = total.saturating_add(tao_in_curr.into()); }); TotalStake::::mutate(|total| { - *total = total.saturating_add(tao_in_i.into()); + *total = total.saturating_add(tao_in_curr.into()); }); TotalIssuance::::mutate(|total| { - *total = total.saturating_add(tao_in_i.into()); + *total = total.saturating_add(tao_in_curr.into()); }); // Adjust protocol liquidity based on new reserves - T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_i, alpha_in_i); + T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_curr, alpha_in_curr); } log::debug!("tao_in: {tao_in:?}"); From 43a2a4db4707eeda6c3c8152335d3e3b769468c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=B5?= Date: Thu, 28 Aug 2025 21:33:11 +0200 Subject: [PATCH 3/5] run_coinbase(): refactor step 3 and 4, take them together in one for loop --- .../subtensor/src/coinbase/run_coinbase.rs | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 004627f30..f21ecdca4 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -49,14 +49,14 @@ impl Pallet { let total_moving_prices = acc_total_moving_prices; log::debug!("total_moving_prices: {total_moving_prices:?}"); - // --- 3. Get subnet terms (tao_in, alpha_in, and alpha_out) - // Computation is described in detail in the dtao whitepaper. let mut tao_in: BTreeMap = BTreeMap::new(); let mut alpha_in: BTreeMap = BTreeMap::new(); let mut alpha_out: BTreeMap = BTreeMap::new(); let mut is_subsidized: BTreeMap = BTreeMap::new(); // Only calculate for subnets that we are emitting to. for netuid_i in subnets_to_emit_to.iter() { + // --- 3. Get subnet terms (tao_in, alpha_in, and alpha_out) + // Computation is described in detail in the dtao whitepaper. // Get subnet price. let price_i = T::SwapInterface::current_alpha_price((*netuid_i).into()); log::debug!("price_i: {price_i:?}"); @@ -122,29 +122,24 @@ impl Pallet { tao_in.insert(*netuid_i, tao_in_i); alpha_in.insert(*netuid_i, alpha_in_i); alpha_out.insert(*netuid_i, alpha_out_i); - } - // --- 4. Injection. - // Actually perform the injection of alpha_in, alpha_out and tao_in into the subnet pool. - // This operation changes the pool liquidity each block. - for netuid_i in subnets_to_emit_to.iter() { + // --- 4. Injection. + // Actually perform the injection of alpha_in, alpha_out and tao_in into the subnet pool. + // This operation changes the pool liquidity each block. // Inject Alpha in. - let alpha_in_curr = - AlphaCurrency::from(tou64!(*alpha_in.get(netuid_i).unwrap_or(&asfloat!(0)))); + let alpha_in_curr = AlphaCurrency::from(tou64!(alpha_in_i)); SubnetAlphaInEmission::::insert(*netuid_i, alpha_in_curr); SubnetAlphaIn::::mutate(*netuid_i, |total| { *total = total.saturating_add(alpha_in_curr); }); // Injection Alpha out. - let alpha_out_curr = - AlphaCurrency::from(tou64!(*alpha_out.get(netuid_i).unwrap_or(&asfloat!(0)))); + let alpha_out_curr = AlphaCurrency::from(tou64!(alpha_out_i)); SubnetAlphaOutEmission::::insert(*netuid_i, alpha_out_curr); SubnetAlphaOut::::mutate(*netuid_i, |total| { *total = total.saturating_add(alpha_out_curr); }); // Inject TAO in. - let tao_in_curr: TaoCurrency = - tou64!(*tao_in.get(netuid_i).unwrap_or(&asfloat!(0))).into(); + let tao_in_curr: TaoCurrency = tou64!(tao_in_i).into(); SubnetTaoInEmission::::insert(*netuid_i, TaoCurrency::from(tao_in_curr)); SubnetTAO::::mutate(*netuid_i, |total| { *total = total.saturating_add(tao_in_curr.into()); From 38ef7d22c78bdc184d7f5b2b3ca38cdc46bee2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=B5?= Date: Thu, 28 Aug 2025 21:38:23 +0200 Subject: [PATCH 4/5] run_coinbase(): refactor step 3 and 4, drop unused maps tao_in and alpha_in --- pallets/subtensor/src/coinbase/run_coinbase.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index f21ecdca4..5d5073b2f 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -49,8 +49,6 @@ impl Pallet { let total_moving_prices = acc_total_moving_prices; log::debug!("total_moving_prices: {total_moving_prices:?}"); - let mut tao_in: BTreeMap = BTreeMap::new(); - let mut alpha_in: BTreeMap = BTreeMap::new(); let mut alpha_out: BTreeMap = BTreeMap::new(); let mut is_subsidized: BTreeMap = BTreeMap::new(); // Only calculate for subnets that we are emitting to. @@ -118,9 +116,7 @@ impl Pallet { alpha_in_i = asfloat!(0.0); alpha_out_i = asfloat!(0.0); } - // Insert values into maps - tao_in.insert(*netuid_i, tao_in_i); - alpha_in.insert(*netuid_i, alpha_in_i); + // Insert value into map alpha_out.insert(*netuid_i, alpha_out_i); // --- 4. Injection. @@ -154,8 +150,6 @@ impl Pallet { T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_curr, alpha_in_curr); } - log::debug!("tao_in: {tao_in:?}"); - log::debug!("alpha_in: {alpha_in:?}"); log::debug!("alpha_out: {alpha_out:?}"); // --- 5. Compute owner cuts and remove them from alpha_out remaining. From ef62820f339eca69c377c2b02f08d3da83e36d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=B5?= Date: Thu, 28 Aug 2025 21:47:02 +0200 Subject: [PATCH 5/5] run_coinbase(): refactor step 3 and 4, collect tao_in_total and update TotalStake and TotalIssuance once --- pallets/subtensor/src/coinbase/run_coinbase.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 5d5073b2f..a74d71d8a 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -49,6 +49,7 @@ impl Pallet { let total_moving_prices = acc_total_moving_prices; log::debug!("total_moving_prices: {total_moving_prices:?}"); + let mut tao_in_total: TaoCurrency = 0.into(); let mut alpha_out: BTreeMap = BTreeMap::new(); let mut is_subsidized: BTreeMap = BTreeMap::new(); // Only calculate for subnets that we are emitting to. @@ -140,16 +141,18 @@ impl Pallet { SubnetTAO::::mutate(*netuid_i, |total| { *total = total.saturating_add(tao_in_curr.into()); }); - TotalStake::::mutate(|total| { - *total = total.saturating_add(tao_in_curr.into()); - }); - TotalIssuance::::mutate(|total| { - *total = total.saturating_add(tao_in_curr.into()); - }); + tao_in_total = tao_in_total.saturating_add(tao_in_curr); // Adjust protocol liquidity based on new reserves T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_curr, alpha_in_curr); } + TotalStake::::mutate(|total| { + *total = total.saturating_add(tao_in_total.into()); + }); + TotalIssuance::::mutate(|total| { + *total = total.saturating_add(tao_in_total.into()); + }); + log::debug!("alpha_out: {alpha_out:?}"); // --- 5. Compute owner cuts and remove them from alpha_out remaining.