Skip to content

Commit ae60405

Browse files
committed
merge with target branch
2 parents 682ac1a + f1886e2 commit ae60405

File tree

18 files changed

+1729
-261
lines changed

18 files changed

+1729
-261
lines changed

Cargo.lock

Lines changed: 0 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/admin-utils/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ pub mod pallet {
554554
}
555555

556556
/// The extrinsic sets the minimum burn for a subnet.
557-
/// It is only callable by the root account or subnet owner.
557+
/// It is only callable by the root account.
558558
/// The extrinsic will call the Subtensor pallet to set the minimum burn.
559559
#[pallet::call_index(22)]
560560
#[pallet::weight(<T as Config>::WeightInfo::sudo_set_min_burn())]
@@ -563,7 +563,7 @@ pub mod pallet {
563563
netuid: u16,
564564
min_burn: u64,
565565
) -> DispatchResult {
566-
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;
566+
ensure_root(origin)?;
567567

568568
ensure!(
569569
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,26 @@ impl<T: Config> Pallet<T> {
122122
netuid,
123123
subnet_proportion
124124
);
125-
// 3.7: Calculate subnet's TAO emission: E_s = P_s * E_m
126-
let tao_in: u64 = mech_emission
127-
.checked_mul(subnet_proportion)
128-
.unwrap_or(I96F32::saturating_from_num(0))
129-
.saturating_to_num::<u64>();
130-
log::debug!(
131-
"Subnet TAO emission (E_s) for netuid {:?}: {:?}",
132-
netuid,
133-
tao_in
134-
);
135-
// 3.8: Store the subnet TAO emission.
136-
*tao_in_map.entry(*netuid).or_insert(0) = tao_in;
137-
// 3.9: Store the block emission for this subnet for chain storage.
138-
EmissionValues::<T>::insert(*netuid, tao_in);
125+
126+
// Only emit TAO if the subnetwork allows registration.
127+
if Self::get_network_registration_allowed(*netuid)
128+
|| Self::get_network_pow_registration_allowed(*netuid)
129+
{
130+
// 3.7: Calculate subnet's TAO emission: E_s = P_s * E_m
131+
let tao_in: u64 = mech_emission
132+
.checked_mul(subnet_proportion)
133+
.unwrap_or(I96F32::saturating_from_num(0))
134+
.saturating_to_num::<u64>();
135+
log::debug!(
136+
"Subnet TAO emission (E_s) for netuid {:?}: {:?}",
137+
netuid,
138+
tao_in
139+
);
140+
// 3.8: Store the subnet TAO emission.
141+
*tao_in_map.entry(*netuid).or_insert(0) = tao_in;
142+
// 3.9: Store the block emission for this subnet for chain storage.
143+
EmissionValues::<T>::insert(*netuid, tao_in);
144+
}
139145
}
140146

141147
// == We'll save the owner cuts for each subnet.

pallets/subtensor/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub mod pallet {
8282
use sp_std::collections::vec_deque::VecDeque;
8383
use sp_std::vec;
8484
use sp_std::vec::Vec;
85-
use substrate_fixed::types::U64F64;
85+
use substrate_fixed::types::{I96F32, U64F64};
8686
use subtensor_macros::freeze_struct;
8787

8888
#[cfg(not(feature = "std"))]
@@ -733,6 +733,12 @@ pub mod pallet {
733733
U64F64::saturating_from_num(0)
734734
}
735735

736+
#[pallet::type_value]
737+
/// Default value for minimum liquidity in pool
738+
pub fn DefaultMinimumPoolLiquidity<T: Config>() -> I96F32 {
739+
I96F32::saturating_from_num(1_000_000)
740+
}
741+
736742
#[pallet::storage]
737743
pub type ColdkeySwapScheduleDuration<T: Config> =
738744
StorageValue<_, BlockNumberFor<T>, ValueQuery, DefaultColdkeySwapScheduleDuration<T>>;
@@ -1562,6 +1568,8 @@ pub enum CustomTransactionError {
15621568
HotkeyAccountDoesntExist,
15631569
NotEnoughStakeToWithdraw,
15641570
RateLimitExceeded,
1571+
InsufficientLiquidity,
1572+
SlippageTooHigh,
15651573
BadRequest,
15661574
}
15671575

@@ -1575,6 +1583,8 @@ impl From<CustomTransactionError> for u8 {
15751583
CustomTransactionError::HotkeyAccountDoesntExist => 4,
15761584
CustomTransactionError::NotEnoughStakeToWithdraw => 5,
15771585
CustomTransactionError::RateLimitExceeded => 6,
1586+
CustomTransactionError::InsufficientLiquidity => 7,
1587+
CustomTransactionError::SlippageTooHigh => 8,
15781588
CustomTransactionError::BadRequest => 255,
15791589
}
15801590
}
@@ -1642,6 +1652,14 @@ where
16421652
CustomTransactionError::NotEnoughStakeToWithdraw.into(),
16431653
)
16441654
.into()),
1655+
Error::<T>::InsufficientLiquidity => Err(InvalidTransaction::Custom(
1656+
CustomTransactionError::InsufficientLiquidity.into(),
1657+
)
1658+
.into()),
1659+
Error::<T>::SlippageTooHigh => Err(InvalidTransaction::Custom(
1660+
CustomTransactionError::SlippageTooHigh.into(),
1661+
)
1662+
.into()),
16451663
_ => Err(
16461664
InvalidTransaction::Custom(CustomTransactionError::BadRequest.into()).into(),
16471665
),
@@ -1789,6 +1807,8 @@ where
17891807
hotkey,
17901808
*netuid,
17911809
*amount_staked,
1810+
*amount_staked,
1811+
false,
17921812
))
17931813
}
17941814
Some(Call::remove_stake {
@@ -1802,6 +1822,8 @@ where
18021822
hotkey,
18031823
*netuid,
18041824
*amount_unstaked,
1825+
*amount_unstaked,
1826+
false,
18051827
))
18061828
}
18071829
Some(Call::move_stake {

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,5 +1688,128 @@ mod dispatches {
16881688
alpha_amount,
16891689
)
16901690
}
1691+
1692+
/// --- Adds stake to a hotkey on a subnet with a price limit.
1693+
/// This extrinsic allows to specify the limit price for alpha token
1694+
/// at which or better (lower) the staking should execute.
1695+
///
1696+
/// In case if slippage occurs and the price shall move beyond the limit
1697+
/// price, the staking order may execute only partially or not execute
1698+
/// at all.
1699+
///
1700+
/// # Args:
1701+
/// * 'origin': (<T as frame_system::Config>Origin):
1702+
/// - The signature of the caller's coldkey.
1703+
///
1704+
/// * 'hotkey' (T::AccountId):
1705+
/// - The associated hotkey account.
1706+
///
1707+
/// * 'amount_staked' (u64):
1708+
/// - The amount of stake to be added to the hotkey staking account.
1709+
///
1710+
/// * 'limit_price' (u64):
1711+
/// - The limit price expressed in units of RAO per one Alpha.
1712+
///
1713+
/// * 'allow_partial' (bool):
1714+
/// - Allows partial execution of the amount. If set to false, this becomes
1715+
/// fill or kill type or order.
1716+
///
1717+
/// # Event:
1718+
/// * StakeAdded;
1719+
/// - On the successfully adding stake to a global account.
1720+
///
1721+
/// # Raises:
1722+
/// * 'NotEnoughBalanceToStake':
1723+
/// - Not enough balance on the coldkey to add onto the global account.
1724+
///
1725+
/// * 'NonAssociatedColdKey':
1726+
/// - The calling coldkey is not associated with this hotkey.
1727+
///
1728+
/// * 'BalanceWithdrawalError':
1729+
/// - Errors stemming from transaction pallet.
1730+
///
1731+
#[pallet::call_index(88)]
1732+
#[pallet::weight((Weight::from_parts(124_000_000, 0)
1733+
.saturating_add(T::DbWeight::get().reads(10))
1734+
.saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))]
1735+
pub fn add_stake_limit(
1736+
origin: OriginFor<T>,
1737+
hotkey: T::AccountId,
1738+
netuid: u16,
1739+
amount_staked: u64,
1740+
limit_price: u64,
1741+
allow_partial: bool,
1742+
) -> DispatchResult {
1743+
Self::do_add_stake_limit(
1744+
origin,
1745+
hotkey,
1746+
netuid,
1747+
amount_staked,
1748+
limit_price,
1749+
allow_partial,
1750+
)
1751+
}
1752+
1753+
/// --- Removes stake from a hotkey on a subnet with a price limit.
1754+
/// This extrinsic allows to specify the limit price for alpha token
1755+
/// at which or better (higher) the staking should execute.
1756+
///
1757+
/// In case if slippage occurs and the price shall move beyond the limit
1758+
/// price, the staking order may execute only partially or not execute
1759+
/// at all.
1760+
///
1761+
/// # Args:
1762+
/// * 'origin': (<T as frame_system::Config>Origin):
1763+
/// - The signature of the caller's coldkey.
1764+
///
1765+
/// * 'hotkey' (T::AccountId):
1766+
/// - The associated hotkey account.
1767+
///
1768+
/// * 'amount_unstaked' (u64):
1769+
/// - The amount of stake to be added to the hotkey staking account.
1770+
///
1771+
/// * 'limit_price' (u64):
1772+
/// - The limit price expressed in units of RAO per one Alpha.
1773+
///
1774+
/// * 'allow_partial' (bool):
1775+
/// - Allows partial execution of the amount. If set to false, this becomes
1776+
/// fill or kill type or order.
1777+
///
1778+
/// # Event:
1779+
/// * StakeRemoved;
1780+
/// - On the successfully removing stake from the hotkey account.
1781+
///
1782+
/// # Raises:
1783+
/// * 'NotRegistered':
1784+
/// - Thrown if the account we are attempting to unstake from is non existent.
1785+
///
1786+
/// * 'NonAssociatedColdKey':
1787+
/// - Thrown if the coldkey does not own the hotkey we are unstaking from.
1788+
///
1789+
/// * 'NotEnoughStakeToWithdraw':
1790+
/// - Thrown if there is not enough stake on the hotkey to withdwraw this amount.
1791+
///
1792+
#[pallet::call_index(89)]
1793+
#[pallet::weight((Weight::from_parts(111_000_000, 0)
1794+
.saturating_add(Weight::from_parts(0, 43991))
1795+
.saturating_add(T::DbWeight::get().reads(10))
1796+
.saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))]
1797+
pub fn remove_stake_limit(
1798+
origin: OriginFor<T>,
1799+
hotkey: T::AccountId,
1800+
netuid: u16,
1801+
amount_unstaked: u64,
1802+
limit_price: u64,
1803+
allow_partial: bool,
1804+
) -> DispatchResult {
1805+
Self::do_remove_stake_limit(
1806+
origin,
1807+
hotkey,
1808+
netuid,
1809+
amount_unstaked,
1810+
limit_price,
1811+
allow_partial,
1812+
)
1813+
}
16911814
}
16921815
}

pallets/subtensor/src/macros/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,9 @@ mod errors {
185185
CommittingWeightsTooFast,
186186
/// Stake amount is too low.
187187
AmountTooLow,
188+
/// Not enough liquidity.
189+
InsufficientLiquidity,
190+
/// Slippage is too high for the transaction.
191+
SlippageTooHigh,
188192
}
189193
}

0 commit comments

Comments
 (0)