@@ -36,7 +36,10 @@ use sp_runtime::traits::Dispatchable;
36
36
use sp_runtime:: traits:: { BlakeTwo256 , UniqueSaturatedInto } ;
37
37
use sp_runtime:: AccountId32 ;
38
38
39
- use crate :: precompiles:: { get_method_id, get_slice} ;
39
+ use crate :: {
40
+ precompiles:: { get_method_id, get_slice} ,
41
+ ProxyType ,
42
+ } ;
40
43
use sp_std:: vec;
41
44
42
45
use crate :: { Runtime , RuntimeCall } ;
@@ -52,21 +55,23 @@ impl StakingPrecompile {
52
55
. get ( 4 ..)
53
56
. map_or_else ( vec:: Vec :: new, |slice| slice. to_vec ( ) ) ; // Avoiding borrowing conflicts
54
57
55
- match method_id {
56
- id if id == get_method_id ( "addStake(bytes32,uint16)" ) => {
57
- Self :: add_stake ( handle, & method_input)
58
- }
59
- id if id == get_method_id ( "removeStake(bytes32,uint256,uint16)" ) => {
60
- Self :: remove_stake ( handle, & method_input)
61
- }
62
- _ => Err ( PrecompileFailure :: Error {
58
+ if method_id == get_method_id ( "addStake(bytes32,uint16)" ) {
59
+ Self :: add_stake ( handle, & method_input)
60
+ } else if method_id == get_method_id ( "removeStake(bytes32,uint256,uint16)" ) {
61
+ Self :: remove_stake ( handle, & method_input)
62
+ } else if method_id == get_method_id ( "addProxy(bytes32)" ) {
63
+ Self :: add_proxy ( handle, & method_input)
64
+ } else if method_id == get_method_id ( "removeProxy(bytes32)" ) {
65
+ Self :: remove_proxy ( handle, & method_input)
66
+ } else {
67
+ Err ( PrecompileFailure :: Error {
63
68
exit_status : ExitError :: InvalidRange ,
64
- } ) ,
69
+ } )
65
70
}
66
71
}
67
72
68
73
fn add_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
69
- let hotkey = Self :: parse_hotkey ( data) ?. into ( ) ;
74
+ let hotkey = Self :: parse_pub_key ( data) ?. into ( ) ;
70
75
let amount: U256 = handle. context ( ) . apparent_value ;
71
76
let amount_sub =
72
77
<Runtime as pallet_evm:: Config >:: BalanceConverter :: into_substrate_balance ( amount)
@@ -80,8 +85,9 @@ impl StakingPrecompile {
80
85
// Dispatch the add_stake call
81
86
Self :: dispatch ( handle, call)
82
87
}
88
+
83
89
fn remove_stake ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
84
- let hotkey = Self :: parse_hotkey ( data) ?. into ( ) ;
90
+ let hotkey = Self :: parse_pub_key ( data) ?. into ( ) ;
85
91
86
92
// We have to treat this as uint256 (because of Solidity ABI encoding rules, it pads uint64),
87
93
// but this will never exceed 8 bytes, se we will ignore higher bytes and will only use lower
@@ -101,15 +107,37 @@ impl StakingPrecompile {
101
107
Self :: dispatch ( handle, call)
102
108
}
103
109
104
- fn parse_hotkey ( data : & [ u8 ] ) -> Result < [ u8 ; 32 ] , PrecompileFailure > {
110
+ fn add_proxy ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
111
+ let delegate = Self :: parse_pub_key ( data) ?;
112
+ let call = RuntimeCall :: Proxy ( pallet_proxy:: Call :: < Runtime > :: add_proxy {
113
+ delegate,
114
+ proxy_type : ProxyType :: Staking ,
115
+ delay : 0 ,
116
+ } ) ;
117
+
118
+ Self :: dispatch ( handle, call)
119
+ }
120
+
121
+ fn remove_proxy ( handle : & mut impl PrecompileHandle , data : & [ u8 ] ) -> PrecompileResult {
122
+ let delegate = Self :: parse_pub_key ( data) ?;
123
+ let call = RuntimeCall :: Proxy ( pallet_proxy:: Call :: < Runtime > :: remove_proxy {
124
+ delegate,
125
+ proxy_type : ProxyType :: Staking ,
126
+ delay : 0 ,
127
+ } ) ;
128
+
129
+ Self :: dispatch ( handle, call)
130
+ }
131
+
132
+ fn parse_pub_key ( data : & [ u8 ] ) -> Result < [ u8 ; 32 ] , PrecompileFailure > {
105
133
if data. len ( ) < 32 {
106
134
return Err ( PrecompileFailure :: Error {
107
135
exit_status : ExitError :: InvalidRange ,
108
136
} ) ;
109
137
}
110
- let mut hotkey = [ 0u8 ; 32 ] ;
111
- hotkey . copy_from_slice ( get_slice ( data, 0 , 32 ) ?) ;
112
- Ok ( hotkey )
138
+ let mut pubkey = [ 0u8 ; 32 ] ;
139
+ pubkey . copy_from_slice ( get_slice ( data, 0 , 32 ) ?) ;
140
+ Ok ( pubkey )
113
141
}
114
142
115
143
fn dispatch ( handle : & mut impl PrecompileHandle , call : RuntimeCall ) -> PrecompileResult {
0 commit comments