Skip to content

Commit da27d69

Browse files
author
unconst
committed
add volumne
1 parent d0953d8 commit da27d69

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<T: Config> Pallet<T> {
285285
// First clear the netuid from HotkeyDividends
286286
let mut total_root_alpha_divs: u64 = 0;
287287
let mut root_alpha_divs: BTreeMap<T::AccountId, u64> = BTreeMap::new();
288-
let _ = HotkeyDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
288+
let _ = AlphaDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
289289
for (hotkey, incentive, dividends) in hotkey_emission {
290290
log::debug!(
291291
"Processing hotkey {:?} with incentive {:?} and dividends {:?}",
@@ -412,7 +412,7 @@ impl<T: Config> Pallet<T> {
412412
);
413413

414414
// 7.6.3.9: Record dividends for this hotkey on this subnet.
415-
HotkeyDividendsPerSubnet::<T>::mutate(netuid, hotkey_j.clone(), |divs| {
415+
AlphaDividendsPerSubnet::<T>::mutate(netuid, hotkey_j.clone(), |divs| {
416416
*divs = divs.saturating_add(divs_j);
417417
});
418418
log::debug!(
@@ -424,7 +424,7 @@ impl<T: Config> Pallet<T> {
424424
}
425425
}
426426
// For all the root alpha divs give this proportion of the swapped tao to the root participants.
427-
let _ = RootDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
427+
let _ = TaoDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
428428
let total_root_divs_to_distribute = PendingRootDivs::<T>::get(netuid);
429429
PendingRootDivs::<T>::insert(netuid, 0);
430430
for (hotkey_j, root_divs) in root_alpha_divs.iter() {
@@ -454,7 +454,7 @@ impl<T: Config> Pallet<T> {
454454
);
455455

456456
// 7.6.3.9: Record dividends for this hotkey on this subnet.
457-
RootDividendsPerSubnet::<T>::mutate(netuid, hotkey_j.clone(), |divs| {
457+
TaoDividendsPerSubnet::<T>::mutate(netuid, hotkey_j.clone(), |divs| {
458458
*divs = divs.saturating_add(root_divs_to_pay);
459459
});
460460
}

pallets/subtensor/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ pub mod pallet {
814814
DefaultAccountLinkage<T>,
815815
>;
816816
#[pallet::storage] // --- DMAP ( netuid, hotkey ) --> u64 | Last total dividend this hotkey got on tempo.
817-
pub type HotkeyDividendsPerSubnet<T: Config> = StorageDoubleMap<
817+
pub type AlphaDividendsPerSubnet<T: Config> = StorageDoubleMap<
818818
_,
819819
Identity,
820820
u16,
@@ -825,7 +825,7 @@ pub mod pallet {
825825
DefaultZeroU64<T>,
826826
>;
827827
#[pallet::storage] // --- DMAP ( netuid, hotkey ) --> u64 | Last total root dividend paid to this hotkey on this subnet.
828-
pub type RootDividendsPerSubnet<T: Config> = StorageDoubleMap<
828+
pub type TaoDividendsPerSubnet<T: Config> = StorageDoubleMap<
829829
_,
830830
Identity,
831831
u16,
@@ -883,6 +883,9 @@ pub mod pallet {
883883
pub type TotalIssuance<T> = StorageValue<_, u64, ValueQuery, DefaultTotalIssuance<T>>;
884884
#[pallet::storage] // --- ITEM ( total_stake )
885885
pub type TotalStake<T> = StorageValue<_, u64, ValueQuery>;
886+
#[pallet::storage] // --- DMAP ( netuid ) --> total_volume | The total amount of TAO bought and sold since the start of the network.
887+
pub type SubnetVolume<T: Config> =
888+
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
886889
#[pallet::storage] // --- DMAP ( netuid ) --> tao_in_subnet | Returns the amount of TAO in the subnet.
887890
pub type SubnetTAO<T: Config> =
888891
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;

pallets/subtensor/src/rpc_info/stake_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<T: Config> Pallet<T> {
3535
let alpha: u64 = Self::get_stake_for_hotkey_and_coldkey_on_subnet(
3636
hotkey_i, coldkey_i, *netuid_i,
3737
);
38-
let emission: u64 = HotkeyDividendsPerSubnet::<T>::get(*netuid_i, &hotkey_i);
38+
let emission: u64 = AlphaDividendsPerSubnet::<T>::get(*netuid_i, &hotkey_i);
3939
let is_registered: bool =
4040
Self::is_hotkey_registered_on_network(*netuid_i, hotkey_i);
4141
stake_info_for_coldkey.push(StakeInfo {

pallets/subtensor/src/staking/stake_utils.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ impl<T: Config> Pallet<T> {
482482
///
483483
/// Updates TaoIn, AlphaIn, and AlphaOut
484484
pub fn swap_tao_for_alpha(netuid: u16, tao: u64) -> u64 {
485+
485486
// Step 1: Get the mechanism type for the subnet (0 for Stable, 1 for Dynamic)
486487
let mechanism_id: u16 = SubnetMechanism::<T>::get(netuid);
487488
// Step 2: Initialized vars.
@@ -517,7 +518,11 @@ impl<T: Config> Pallet<T> {
517518
TotalStake::<T>::mutate(|total| {
518519
*total = total.saturating_add(tao);
519520
});
520-
// Step 8. Return the alpha received.
521+
// Step 8. Decrease Alpha reserves.
522+
SubnetVolume::<T>::mutate(netuid, |total| {
523+
*total = total.saturating_sub(tao);
524+
});
525+
// Step 9. Return the alpha received.
521526
alpha.to_num::<u64>()
522527
}
523528

@@ -560,7 +565,11 @@ impl<T: Config> Pallet<T> {
560565
TotalStake::<T>::mutate(|total| {
561566
*total = total.saturating_sub(tao.to_num::<u64>());
562567
});
563-
// Step 8. Return the tao received.
568+
// Step 8. Decrease Alpha reserves.
569+
SubnetVolume::<T>::mutate(netuid, |total| {
570+
*total = total.saturating_sub(tao.to_num::<u64>());
571+
});
572+
// Step 9. Return the tao received.
564573
tao.to_num::<u64>()
565574
}
566575

0 commit comments

Comments
 (0)