Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions pallets/subtensor/src/coinbase/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
log::debug!("Block emission: {:?}", block_emission);
// --- 3. Run emission through network.
Self::run_coinbase(block_emission);

// --- 4. Set pending children on the epoch; but only after the coinbase has been run.
Self::try_set_pending_children(block_number);

// Return ok.
Ok(())
}
Expand Down
823 changes: 281 additions & 542 deletions pallets/subtensor/src/coinbase/run_coinbase.rs

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ pub mod pallet {
#[pallet::type_value]
/// Default value for applying pending items (e.g. childkeys).
pub fn DefaultPendingCooldown<T: Config>() -> u64 {
7200
1
}

#[pallet::type_value]
Expand All @@ -717,7 +717,7 @@ pub mod pallet {
/// Default staking fee.
/// 500k rao matches $0.25 at $500/TAO
pub fn DefaultStakingFee<T: Config>() -> u64 {
500_000
50_000
}

#[pallet::type_value]
Expand All @@ -732,6 +732,18 @@ pub mod pallet {
T::InitialDissolveNetworkScheduleDuration::get()
}

#[pallet::type_value]
/// Default moving alpha for the moving price.
pub fn DefaultMovingAlpha<T: Config>() -> I96F32 {
// Moving average take 30 days to reach 50% of the price
// and 3.5 months to reach 90%.
I96F32::saturating_from_num(0.000003)
}
#[pallet::type_value]
/// Default subnet moving price.
pub fn DefaultMovingPrice<T: Config>() -> I96F32 {
I96F32::saturating_from_num(0.0)
}
#[pallet::type_value]
/// Default value for Share Pool variables
pub fn DefaultSharePoolZero<T: Config>() -> U64F64 {
Expand Down Expand Up @@ -910,6 +922,11 @@ pub mod pallet {
pub type TotalStake<T> = StorageValue<_, u64, ValueQuery>;
#[pallet::storage] // --- ITEM ( dynamic_block ) -- block when dynamic was turned on.
pub type DynamicBlock<T> = StorageValue<_, u64, ValueQuery>;
#[pallet::storage] // --- ITEM ( moving_alpha ) -- subnet moving alpha.
pub type SubnetMovingAlpha<T> = StorageValue<_, I96F32, ValueQuery, DefaultMovingAlpha<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> moving_price | The subnet moving price.
pub type SubnetMovingPrice<T: Config> =
StorageMap<_, Identity, u16, I96F32, ValueQuery, DefaultMovingPrice<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> total_volume | The total amount of TAO bought and sold since the start of the network.
pub type SubnetVolume<T: Config> =
StorageMap<_, Identity, u16, u128, ValueQuery, DefaultZeroU128<T>>;
Expand Down
5 changes: 5 additions & 0 deletions pallets/subtensor/src/staking/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ impl<T: Config> Pallet<T> {
pub fn get_hotkey_take(hotkey: &T::AccountId) -> u16 {
Delegates::<T>::get(hotkey)
}
pub fn get_hotkey_take_float(hotkey: &T::AccountId) -> I96F32 {
I96F32::saturating_from_num(Self::get_hotkey_take(hotkey))
.checked_div(I96F32::saturating_from_num(u16::MAX))
.unwrap_or(I96F32::saturating_from_num(0.0))
}

/// Returns true if the hotkey account has been created.
///
Expand Down
20 changes: 20 additions & 0 deletions pallets/subtensor/src/staking/stake_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ impl<T: Config> Pallet<T> {
.unwrap_or(I96F32::saturating_from_num(0))
}
}
pub fn get_moving_alpha_price(netuid: u16) -> I96F32 {
if netuid == Self::get_root_netuid() {
// Root.
I96F32::saturating_from_num(1.0)
} else if SubnetMechanism::<T>::get(netuid) == 0 {
// Stable
I96F32::saturating_from_num(1.0)
} else {
SubnetMovingPrice::<T>::get(netuid)
}
}
pub fn update_moving_price(netuid: u16) {
let alpha: I96F32 = SubnetMovingAlpha::<T>::get();
let minus_alpha: I96F32 = I96F32::saturating_from_num(1.0).saturating_sub(alpha);
let current_price: I96F32 = alpha.saturating_mul(Self::get_alpha_price(netuid));
let current_moving: I96F32 =
minus_alpha.saturating_mul(Self::get_moving_alpha_price(netuid));
let new_moving: I96F32 = current_price.saturating_add(current_moving);
SubnetMovingPrice::<T>::insert(netuid, new_moving);
}

/// Retrieves the global global weight as a normalized value between 0 and 1.
///
Expand Down
334 changes: 266 additions & 68 deletions pallets/subtensor/src/subnets/symbols.rs

Large diffs are not rendered by default.

Loading