Skip to content

Commit 8c8bc16

Browse files
authored
Merge pull request #1241 from opentensor/nonclaim
Nonclaim
2 parents f7058a2 + 8729b25 commit 8c8bc16

File tree

10 files changed

+949
-1382
lines changed

10 files changed

+949
-1382
lines changed

pallets/subtensor/src/coinbase/block_step.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
1616
log::debug!("Block emission: {:?}", block_emission);
1717
// --- 3. Run emission through network.
1818
Self::run_coinbase(block_emission);
19-
2019
// --- 4. Set pending children on the epoch; but only after the coinbase has been run.
2120
Self::try_set_pending_children(block_number);
22-
2321
// Return ok.
2422
Ok(())
2523
}

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 281 additions & 542 deletions
Large diffs are not rendered by default.

pallets/subtensor/src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ pub mod pallet {
703703
#[pallet::type_value]
704704
/// Default value for applying pending items (e.g. childkeys).
705705
pub fn DefaultPendingCooldown<T: Config>() -> u64 {
706-
7200
706+
1
707707
}
708708

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

723723
#[pallet::type_value]
@@ -732,6 +732,18 @@ pub mod pallet {
732732
T::InitialDissolveNetworkScheduleDuration::get()
733733
}
734734

735+
#[pallet::type_value]
736+
/// Default moving alpha for the moving price.
737+
pub fn DefaultMovingAlpha<T: Config>() -> I96F32 {
738+
// Moving average take 30 days to reach 50% of the price
739+
// and 3.5 months to reach 90%.
740+
I96F32::saturating_from_num(0.000003)
741+
}
742+
#[pallet::type_value]
743+
/// Default subnet moving price.
744+
pub fn DefaultMovingPrice<T: Config>() -> I96F32 {
745+
I96F32::saturating_from_num(0.0)
746+
}
735747
#[pallet::type_value]
736748
/// Default value for Share Pool variables
737749
pub fn DefaultSharePoolZero<T: Config>() -> U64F64 {
@@ -910,6 +922,11 @@ pub mod pallet {
910922
pub type TotalStake<T> = StorageValue<_, u64, ValueQuery>;
911923
#[pallet::storage] // --- ITEM ( dynamic_block ) -- block when dynamic was turned on.
912924
pub type DynamicBlock<T> = StorageValue<_, u64, ValueQuery>;
925+
#[pallet::storage] // --- ITEM ( moving_alpha ) -- subnet moving alpha.
926+
pub type SubnetMovingAlpha<T> = StorageValue<_, I96F32, ValueQuery, DefaultMovingAlpha<T>>;
927+
#[pallet::storage] // --- MAP ( netuid ) --> moving_price | The subnet moving price.
928+
pub type SubnetMovingPrice<T: Config> =
929+
StorageMap<_, Identity, u16, I96F32, ValueQuery, DefaultMovingPrice<T>>;
913930
#[pallet::storage] // --- MAP ( netuid ) --> total_volume | The total amount of TAO bought and sold since the start of the network.
914931
pub type SubnetVolume<T: Config> =
915932
StorageMap<_, Identity, u16, u128, ValueQuery, DefaultZeroU128<T>>;

pallets/subtensor/src/staking/helpers.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ impl<T: Config> Pallet<T> {
120120
pub fn get_hotkey_take(hotkey: &T::AccountId) -> u16 {
121121
Delegates::<T>::get(hotkey)
122122
}
123+
pub fn get_hotkey_take_float(hotkey: &T::AccountId) -> I96F32 {
124+
I96F32::saturating_from_num(Self::get_hotkey_take(hotkey))
125+
.checked_div(I96F32::saturating_from_num(u16::MAX))
126+
.unwrap_or(I96F32::saturating_from_num(0.0))
127+
}
123128

124129
/// Returns true if the hotkey account has been created.
125130
///

pallets/subtensor/src/staking/stake_utils.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ impl<T: Config> Pallet<T> {
4545
.unwrap_or(I96F32::saturating_from_num(0))
4646
}
4747
}
48+
pub fn get_moving_alpha_price(netuid: u16) -> I96F32 {
49+
if netuid == Self::get_root_netuid() {
50+
// Root.
51+
I96F32::saturating_from_num(1.0)
52+
} else if SubnetMechanism::<T>::get(netuid) == 0 {
53+
// Stable
54+
I96F32::saturating_from_num(1.0)
55+
} else {
56+
SubnetMovingPrice::<T>::get(netuid)
57+
}
58+
}
59+
pub fn update_moving_price(netuid: u16) {
60+
let alpha: I96F32 = SubnetMovingAlpha::<T>::get();
61+
let minus_alpha: I96F32 = I96F32::saturating_from_num(1.0).saturating_sub(alpha);
62+
let current_price: I96F32 = alpha.saturating_mul(Self::get_alpha_price(netuid));
63+
let current_moving: I96F32 =
64+
minus_alpha.saturating_mul(Self::get_moving_alpha_price(netuid));
65+
let new_moving: I96F32 = current_price.saturating_add(current_moving);
66+
SubnetMovingPrice::<T>::insert(netuid, new_moving);
67+
}
4868

4969
/// Retrieves the global global weight as a normalized value between 0 and 1.
5070
///

pallets/subtensor/src/subnets/symbols.rs

Lines changed: 266 additions & 68 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)