Skip to content

Commit 66c0e8a

Browse files
committed
add runtimeAPI for new dyn staking fee
1 parent 10d9843 commit 66c0e8a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

pallets/subtensor/runtime-api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ sp_api::decl_runtime_apis! {
4646
fn get_stake_info_for_coldkey( coldkey_account: AccountId32 ) -> Vec<StakeInfo<AccountId32>>;
4747
fn get_stake_info_for_coldkeys( coldkey_accounts: Vec<AccountId32> ) -> Vec<(AccountId32, Vec<StakeInfo<AccountId32>>)>;
4848
fn get_stake_info_for_hotkey_coldkey_netuid( hotkey_account: AccountId32, coldkey_account: AccountId32, netuid: u16 ) -> Option<StakeInfo<AccountId32>>;
49+
fn get_stake_fee_for_hotkey_coldkey_netuid( hotkey_account: AccountId32, coldkey_account: AccountId32, origin_netuid: u16, destination_netuid: u16, amount: i64 ) -> u64;
4950
}
5051

5152
pub trait SubnetRegistrationRuntimeApi {

pallets/subtensor/src/rpc_info/stake_info.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use super::*;
22
use frame_support::pallet_prelude::{Decode, Encode};
3+
use sp_std::ops::Neg;
34
extern crate alloc;
45
use codec::Compact;
6+
use substrate_fixed::types::I96F32;
57

68
#[freeze_struct("5cfb3c84c3af3116")]
79
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)]
@@ -112,4 +114,23 @@ impl<T: Config> Pallet<T> {
112114
is_registered,
113115
})
114116
}
117+
118+
pub fn get_stake_fee_for_hotkey_coldkey_netuid(
119+
hotkey_account: T::AccountId,
120+
_coldkey_account: T::AccountId,
121+
origin_netuid: u16,
122+
_destination_netuid: u16,
123+
amount: i64,
124+
) -> u64 {
125+
if amount >= 0 {
126+
DefaultStakingFee::<T>::get()
127+
} else {
128+
// Calculate fee for unstake (negative amount)
129+
Self::calculate_staking_fee(
130+
origin_netuid,
131+
&hotkey_account,
132+
I96F32::saturating_from_num(amount.neg()),
133+
)
134+
}
135+
}
115136
}

runtime/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,10 @@ impl_runtime_apis! {
20662066
fn get_stake_info_for_hotkey_coldkey_netuid( hotkey_account: AccountId32, coldkey_account: AccountId32, netuid: u16 ) -> Option<StakeInfo<AccountId32>> {
20672067
SubtensorModule::get_stake_info_for_hotkey_coldkey_netuid( hotkey_account, coldkey_account, netuid )
20682068
}
2069+
2070+
fn get_stake_fee_for_hotkey_coldkey_netuid( hotkey_account: AccountId32, coldkey_account: AccountId32, origin_netuid: u16, destination_netuid: u16, amount: i64 ) -> u64 {
2071+
SubtensorModule::get_stake_fee_for_hotkey_coldkey_netuid( hotkey_account, coldkey_account, origin_netuid, destination_netuid, amount )
2072+
}
20692073
}
20702074

20712075
impl subtensor_custom_rpc_runtime_api::SubnetRegistrationRuntimeApi<Block> for Runtime {

0 commit comments

Comments
 (0)