2626//
2727
2828use frame_system:: RawOrigin ;
29- use pallet_evm:: { AddressMapping , HashedAddressMapping } ;
29+ use pallet_evm:: { AddressMapping , BalanceConverter , HashedAddressMapping } ;
3030use pallet_evm:: {
3131 ExitError , ExitSucceed , PrecompileFailure , PrecompileHandle , PrecompileOutput , PrecompileResult ,
3232} ;
@@ -68,10 +68,14 @@ impl StakingPrecompile {
6868 fn add_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
6969 let hotkey = Self :: parse_hotkey ( data) ?. into ( ) ;
7070 let amount: U256 = handle. context ( ) . apparent_value ;
71+ let amount_sub =
72+ <Runtime as pallet_evm:: Config >:: BalanceConverter :: into_substrate_balance ( amount)
73+ . ok_or ( ExitError :: OutOfFund ) ?;
74+
7175 // Create the add_stake call
7276 let call = RuntimeCall :: SubtensorModule ( pallet_subtensor:: Call :: < Runtime > :: add_stake {
7377 hotkey,
74- amount_staked : amount . as_u64 ( ) ,
78+ amount_staked : amount_sub ,
7579 } ) ;
7680 // Dispatch the add_stake call
7781 Self :: dispatch ( handle, call)
@@ -85,10 +89,14 @@ impl StakingPrecompile {
8589 let amount = data
8690 . get ( 56 ..64 )
8791 . map ( U256 :: from_big_endian)
88- . map_or ( 0 , |v| v. as_u64 ( ) ) ;
92+ . ok_or ( ExitError :: OutOfFund ) ?;
93+ let amount_sub =
94+ <Runtime as pallet_evm:: Config >:: BalanceConverter :: into_substrate_balance ( amount)
95+ . ok_or ( ExitError :: OutOfFund ) ?;
96+
8997 let call = RuntimeCall :: SubtensorModule ( pallet_subtensor:: Call :: < Runtime > :: remove_stake {
9098 hotkey,
91- amount_unstaked : amount ,
99+ amount_unstaked : amount_sub ,
92100 } ) ;
93101 Self :: dispatch ( handle, call)
94102 }
@@ -148,12 +156,15 @@ impl StakingPrecompile {
148156 } ) ;
149157 }
150158 } ;
159+ let amount_sub =
160+ <Runtime as pallet_evm:: Config >:: BalanceConverter :: into_substrate_balance ( amount)
161+ . ok_or ( ExitError :: OutOfFund ) ?;
151162
152163 // Create a transfer call from the smart contract to the caller
153164 let transfer_call =
154165 RuntimeCall :: Balances ( pallet_balances:: Call :: < Runtime > :: transfer_allow_death {
155166 dest : account_id. clone ( ) . into ( ) ,
156- value : amount . as_u64 ( ) ,
167+ value : amount_sub ,
157168 } ) ;
158169
159170 // Execute the transfer
0 commit comments