Skip to content

Commit fc3beb2

Browse files
committed
Fix number conversion issues in staking precompile
1 parent 6d9adec commit fc3beb2

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

runtime/src/precompiles/neuron.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use sp_std::vec::Vec;
1212

1313
use crate::precompiles::{
1414
get_method_id, get_pubkey, get_slice, parse_netuid, try_dispatch_runtime_call,
15-
try_dispatch_runtime_call,
1615
};
1716
use crate::{Runtime, RuntimeCall};
1817

runtime/src/precompiles/staking.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ impl StakingPrecompile {
7171

7272
let amount_sub =
7373
<Runtime as pallet_evm::Config>::BalanceConverter::into_substrate_balance(amount)
74-
.ok_or(ExitError::OutOfFund)?;
74+
.ok_or(PrecompileFailure::Error {
75+
exit_status: ExitError::Other(
76+
"error converting balance from ETH to subtensor".into(),
77+
),
78+
})?;
7579

7680
let (hotkey, _) = get_pubkey(address.as_bytes())?;
7781
let netuid = try_u16_from_u256(netuid)?;
@@ -96,16 +100,13 @@ impl StakingPrecompile {
96100
handle.context().caller,
97101
);
98102

99-
let amount_sub =
100-
<Runtime as pallet_evm::Config>::BalanceConverter::into_substrate_balance(amount)
101-
.ok_or(ExitError::OutOfFund)?;
102-
103103
let (hotkey, _) = get_pubkey(address.as_bytes())?;
104104
let netuid = try_u16_from_u256(netuid)?;
105+
let amount_unstaked = amount.unique_saturated_into();
105106
let call = RuntimeCall::SubtensorModule(pallet_subtensor::Call::<Runtime>::remove_stake {
106107
hotkey,
107108
netuid,
108-
amount_unstaked: amount_sub.unique_saturated_into(),
109+
amount_unstaked,
109110
});
110111

111112
try_dispatch_runtime_call(handle, call, RawOrigin::Signed(account_id))
@@ -161,9 +162,7 @@ impl StakingPrecompile {
161162
&hotkey, &coldkey, netuid,
162163
);
163164

164-
// Convert to EVM decimals
165-
<Runtime as pallet_evm::Config>::BalanceConverter::into_evm_balance(stake.into())
166-
.ok_or(ExitError::InvalidRange.into())
165+
Ok(stake.into())
167166
}
168167

169168
fn transfer_back_to_caller(

runtime/src/precompiles/subnet.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const CONTRACT_ADDRESS_SS58: [u8; 32] = [
2525

2626
pub struct SubnetPrecompile;
2727

28+
#[precompile_utils::precompile]
2829
impl SubnetPrecompile {
2930
// pub fn execute(handle: &mut impl PrecompileHandle) -> PrecompileResult {
3031
// let txdata = handle.input();

0 commit comments

Comments
 (0)