Skip to content
Open
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
12 changes: 10 additions & 2 deletions pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ mod events {
NetworkAdded(NetUid, u16),
/// a network is removed.
NetworkRemoved(NetUid),
/// stake has been transferred from the a coldkey account onto the hotkey staking account.
/// Stake has been transferred from a coldkey account onto the hotkey staking account.
/// The origin is the account on behalf of which the staking operation was performed
/// (coldkey for extrinsic calls, lease coldkey for automated distributions).
/// (origin, coldkey, hotkey, tao_amount, alpha_amount, netuid, fee)
StakeAdded(
T::AccountId,
T::AccountId,
T::AccountId,
TaoCurrency,
AlphaCurrency,
NetUid,
u64,
),
/// stake has been removed from the hotkey staking account onto the coldkey account.
/// Stake has been removed from the hotkey staking account onto the coldkey account.
/// The origin is the account on behalf of which the unstaking operation was performed
/// (coldkey for extrinsic calls, lease coldkey for automated distributions).
/// (origin, coldkey, hotkey, tao_amount, alpha_amount, netuid, fee)
StakeRemoved(
T::AccountId,
T::AccountId,
T::AccountId,
TaoCurrency,
Expand Down
2 changes: 2 additions & 0 deletions pallets/subtensor/src/staking/add_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl<T: Config> Pallet<T> {
// 4. Swap the stake into alpha on the subnet and increase counters.
// Emit the staking event.
Self::stake_into_subnet(
&coldkey,
&hotkey,
&coldkey,
netuid,
Expand Down Expand Up @@ -166,6 +167,7 @@ impl<T: Config> Pallet<T> {
// 6. Swap the stake into alpha on the subnet and increase counters.
// Emit the staking event.
Self::stake_into_subnet(
&coldkey,
&hotkey,
&coldkey,
netuid,
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/staking/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl<T: Config> Pallet<T> {
// Actually deletes the staking account.
// Do not apply any fees
let maybe_cleared_stake = Self::unstake_from_subnet(
coldkey,
hotkey,
coldkey,
netuid,
Expand Down
3 changes: 3 additions & 0 deletions pallets/subtensor/src/staking/move_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ impl<T: Config> Pallet<T> {

// do not pay remove fees to avoid double fees in moves transactions
let tao_unstaked = Self::unstake_from_subnet(
origin_coldkey,
origin_hotkey,
origin_coldkey,
origin_netuid,
Expand All @@ -374,6 +375,7 @@ impl<T: Config> Pallet<T> {
}

Self::stake_into_subnet(
origin_coldkey,
destination_hotkey,
destination_coldkey,
destination_netuid,
Expand All @@ -387,6 +389,7 @@ impl<T: Config> Pallet<T> {
Ok(tao_unstaked)
} else {
Self::transfer_stake_within_subnet(
origin_coldkey,
origin_coldkey,
origin_hotkey,
destination_coldkey,
Expand Down
5 changes: 5 additions & 0 deletions pallets/subtensor/src/staking/remove_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl<T: Config> Pallet<T> {

// 3. Swap the alpba to tao and update counters for this subnet.
let tao_unstaked = Self::unstake_from_subnet(
&coldkey,
&hotkey,
&coldkey,
netuid,
Expand Down Expand Up @@ -163,6 +164,7 @@ impl<T: Config> Pallet<T> {
if !alpha_unstaked.is_zero() {
// Swap the alpha to tao and update counters for this subnet.
let tao_unstaked = Self::unstake_from_subnet(
&coldkey,
&hotkey,
&coldkey,
netuid,
Expand Down Expand Up @@ -256,6 +258,7 @@ impl<T: Config> Pallet<T> {
if !alpha_unstaked.is_zero() {
// Swap the alpha to tao and update counters for this subnet.
let tao_unstaked = Self::unstake_from_subnet(
&coldkey,
&hotkey,
&coldkey,
netuid,
Expand All @@ -275,6 +278,7 @@ impl<T: Config> Pallet<T> {

// Stake into root.
Self::stake_into_subnet(
&coldkey,
&hotkey,
&coldkey,
NetUid::ROOT,
Expand Down Expand Up @@ -362,6 +366,7 @@ impl<T: Config> Pallet<T> {

// 4. Swap the alpha to tao and update counters for this subnet.
let tao_unstaked = Self::unstake_from_subnet(
&coldkey,
&hotkey,
&coldkey,
netuid,
Expand Down
13 changes: 11 additions & 2 deletions pallets/subtensor/src/staking/stake_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ impl<T: Config> Pallet<T> {
///
/// We update the pools associated with a subnet as well as update hotkey alpha shares.
pub fn unstake_from_subnet(
origin: &T::AccountId,
hotkey: &T::AccountId,
coldkey: &T::AccountId,
netuid: NetUid,
Expand Down Expand Up @@ -733,6 +734,7 @@ impl<T: Config> Pallet<T> {

// Deposit and log the unstaking event.
Self::deposit_event(Event::StakeRemoved(
origin.clone(),
coldkey.clone(),
hotkey.clone(),
swap_result.amount_paid_out.into(),
Expand All @@ -742,7 +744,8 @@ impl<T: Config> Pallet<T> {
));

log::debug!(
"StakeRemoved( coldkey: {:?}, hotkey:{:?}, tao: {:?}, alpha:{:?}, netuid: {:?}, fee {} )",
"StakeRemoved( origin: {:?}, coldkey: {:?}, hotkey:{:?}, tao: {:?}, alpha:{:?}, netuid: {:?}, fee {} )",
origin.clone(),
coldkey.clone(),
hotkey.clone(),
swap_result.amount_paid_out,
Expand All @@ -758,6 +761,7 @@ impl<T: Config> Pallet<T> {
///
/// We update the pools associated with a subnet as well as update hotkey alpha shares.
pub(crate) fn stake_into_subnet(
origin: &T::AccountId,
hotkey: &T::AccountId,
coldkey: &T::AccountId,
netuid: NetUid,
Expand Down Expand Up @@ -822,6 +826,7 @@ impl<T: Config> Pallet<T> {

// Deposit and log the staking event.
Self::deposit_event(Event::StakeAdded(
origin.clone(),
coldkey.clone(),
hotkey.clone(),
tao,
Expand All @@ -831,7 +836,8 @@ impl<T: Config> Pallet<T> {
));

log::debug!(
"StakeAdded( coldkey: {:?}, hotkey:{:?}, tao: {:?}, alpha:{:?}, netuid: {:?}, fee {} )",
"StakeAdded( origin: {:?}, coldkey: {:?}, hotkey:{:?}, tao: {:?}, alpha:{:?}, netuid: {:?}, fee {} )",
origin.clone(),
coldkey.clone(),
hotkey.clone(),
tao,
Expand All @@ -848,6 +854,7 @@ impl<T: Config> Pallet<T> {
///
/// Does not incur any swapping nor fees
pub fn transfer_stake_within_subnet(
origin: &T::AccountId,
origin_coldkey: &T::AccountId,
origin_hotkey: &T::AccountId,
destination_coldkey: &T::AccountId,
Expand Down Expand Up @@ -916,6 +923,7 @@ impl<T: Config> Pallet<T> {

// Deposit and log the unstaking event.
Self::deposit_event(Event::StakeRemoved(
origin.clone(),
origin_coldkey.clone(),
origin_hotkey.clone(),
tao_equivalent,
Expand All @@ -924,6 +932,7 @@ impl<T: Config> Pallet<T> {
0_u64, // 0 fee
));
Self::deposit_event(Event::StakeAdded(
origin.clone(),
destination_coldkey.clone(),
destination_hotkey.clone(),
tao_equivalent,
Expand Down
2 changes: 2 additions & 0 deletions pallets/subtensor/src/subnets/leasing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl<T: Config> Pallet<T> {
.saturating_to_num::<u64>();

Self::transfer_stake_within_subnet(
&lease.coldkey,
&lease.coldkey,
&lease.hotkey,
&contributor,
Expand All @@ -324,6 +325,7 @@ impl<T: Config> Pallet<T> {
let beneficiary_cut_alpha =
total_contributors_cut_alpha.saturating_sub(alpha_distributed);
Self::transfer_stake_within_subnet(
&lease.coldkey,
&lease.coldkey,
&lease.hotkey,
&lease.beneficiary,
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ pub fn increase_stake_on_coldkey_hotkey_account(
netuid: NetUid,
) {
SubtensorModule::stake_into_subnet(
coldkey,
hotkey,
coldkey,
netuid,
Expand Down
Loading
Loading