Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust staking fees #1445

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Revert move fee
  • Loading branch information
gztensor committed Mar 21, 2025
commit 589f9f2f93e6f1124778137fe3d7de9a2a7d3db3
10 changes: 9 additions & 1 deletion pallets/subtensor/src/staking/stake_utils.rs
Original file line number Diff line number Diff line change
@@ -1075,13 +1075,21 @@ impl<T: Config> Pallet<T> {
pub(crate) fn calculate_staking_fee(
origin: Option<(&T::AccountId, u16)>,
_origin_coldkey: &T::AccountId,
_destination: Option<(&T::AccountId, u16)>,
destination: Option<(&T::AccountId, u16)>,
_destination_coldkey: &T::AccountId,
alpha_estimate: I96F32,
) -> u64 {
match origin {
// If origin is defined, we are removing/moving stake
Some((origin_hotkey, origin_netuid)) => {
if let Some((_destination_hotkey, destination_netuid)) = destination {
// This is a stake move/swap/transfer
if destination_netuid == origin_netuid {
// If destination is on the same subnet, use the default fee
return DefaultStakingFee::<T>::get();
}
}

if origin_netuid == Self::get_root_netuid()
|| SubnetMechanism::<T>::get(origin_netuid) == 0
{
30 changes: 30 additions & 0 deletions pallets/subtensor/src/tests/staking2.rs
Original file line number Diff line number Diff line change
@@ -914,5 +914,35 @@ fn test_stake_fee_calculation() {
I96F32::from_num(stake_amount),
); // Charged a dynamic fee
assert_ne!(stake_fee_5, default_fee);

// Test stake fee for move between hotkeys on non-root
let stake_fee_6 = SubtensorModule::calculate_staking_fee(
Some((&hotkey1, netuid0)),
&coldkey1,
Some((&hotkey2, netuid0)),
&coldkey1,
I96F32::from_num(stake_amount),
); // Charge the default fee
assert_eq!(stake_fee_6, default_fee);

// Test stake fee for move between coldkeys on non-root
let stake_fee_7 = SubtensorModule::calculate_staking_fee(
Some((&hotkey1, netuid0)),
&coldkey1,
Some((&hotkey1, netuid0)),
&coldkey2,
I96F32::from_num(stake_amount),
); // Charge the default fee; stake did not leave the subnet.
assert_eq!(stake_fee_7, default_fee);

// Test stake fee for *swap* from non-root to non-root
let stake_fee_8 = SubtensorModule::calculate_staking_fee(
Some((&hotkey1, netuid0)),
&coldkey1,
Some((&hotkey1, netuid1)),
&coldkey1,
I96F32::from_num(stake_amount),
); // Charged a dynamic fee
assert_ne!(stake_fee_8, default_fee);
});
}
Loading