Skip to content

Commit fbe3488

Browse files
committed
combine origin and dest info
1 parent 3d3817c commit fbe3488

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +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( origin_hotkey_account: Option<AccountId32>, origin_coldkey_account: AccountId32, destination_hotkey_account: Option<AccountId32>, destination_coldkey_account: AccountId32, origin_netuid: Option<u16>, destination_netuid: Option<u16>, amount: i64 ) -> u64;
49+
fn get_stake_fee( origin: Option<(AccountId32, u16)>, origin_coldkey_account: AccountId32, destination: Option<(AccountId32, u16)>, destination_coldkey_account: AccountId32, amount: u64 ) -> u64;
5050
}
5151

5252
pub trait SubnetRegistrationRuntimeApi {

pallets/subtensor/src/rpc_info/stake_info.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,21 @@ impl<T: Config> Pallet<T> {
116116
}
117117

118118
pub fn get_stake_fee(
119-
origin_hotkey_account: Option<T::AccountId>,
119+
origin: Option<(T::AccountId, u16)>,
120120
_origin_coldkey_account: T::AccountId,
121-
_destination_hotkey_account: Option<T::AccountId>,
121+
_destination: Option<(T::AccountId, u16)>,
122122
_destination_coldkey_account: T::AccountId,
123-
origin_netuid: Option<u16>,
124-
_destination_netuid: Option<u16>,
125-
amount: i64,
123+
amount: u64,
126124
) -> u64 {
127-
if amount >= 0 || origin_netuid.is_none() {
128-
// Adding stake
129-
DefaultStakingFee::<T>::get()
130-
} else {
131-
match (origin_netuid, origin_hotkey_account) {
132-
(Some(origin_netuid), Some(origin_hotkey_account)) => {
133-
// Calculate fee for unstake (negative amount)
134-
Self::calculate_staking_fee(
135-
origin_netuid,
136-
&origin_hotkey_account,
137-
I96F32::saturating_from_num(amount.neg()),
138-
)
139-
}
140-
_ => DefaultStakingFee::<T>::get(),
125+
match origin {
126+
Some((origin_hotkey_account, origin_netuid)) => Self::calculate_staking_fee(
127+
origin_netuid,
128+
&origin_hotkey_account,
129+
I96F32::saturating_from_num(amount),
130+
),
131+
None => {
132+
// Adding stake (comes from no netuid)
133+
DefaultStakingFee::<T>::get()
141134
}
142135
}
143136
}

runtime/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,8 +2067,8 @@ impl_runtime_apis! {
20672067
SubtensorModule::get_stake_info_for_hotkey_coldkey_netuid( hotkey_account, coldkey_account, netuid )
20682068
}
20692069

2070-
fn get_stake_fee( origin_hotkey_account: Option<AccountId32>, origin_coldkey_account: AccountId32, destination_hotkey_account: Option<AccountId32>, destination_coldkey_account: AccountId32, origin_netuid: Option<u16>, destination_netuid: Option<u16>, amount: i64 ) -> u64 {
2071-
SubtensorModule::get_stake_fee( origin_hotkey_account, origin_coldkey_account, destination_hotkey_account, destination_coldkey_account, origin_netuid, destination_netuid, amount )
2070+
fn get_stake_fee( origin: Option<(AccountId32, u16)>, origin_coldkey_account: AccountId32, destination: Option<(AccountId32, u16)>, destination_coldkey_account: AccountId32, amount: u64 ) -> u64 {
2071+
SubtensorModule::get_stake_fee( origin, origin_coldkey_account, destination, destination_coldkey_account, amount )
20722072
}
20732073
}
20742074

0 commit comments

Comments
 (0)