@@ -50,7 +50,14 @@ impl<T: Config> Pallet<T> {
50
50
) ;
51
51
52
52
// 2. Validate the user input
53
- Self :: validate_remove_stake ( & coldkey, & hotkey, netuid, alpha_unstaked) ?;
53
+ Self :: validate_remove_stake (
54
+ & coldkey,
55
+ & hotkey,
56
+ netuid,
57
+ alpha_unstaked,
58
+ alpha_unstaked,
59
+ false ,
60
+ ) ?;
54
61
55
62
// 3. Swap the alpba to tao and update counters for this subnet.
56
63
let fee = DefaultStakingFee :: < T > :: get ( ) ;
@@ -223,12 +230,51 @@ impl<T: Config> Pallet<T> {
223
230
Ok ( ( ) )
224
231
}
225
232
233
+ /// ---- The implementation for the extrinsic remove_stake_limit: Removes stake from
234
+ /// a hotkey on a subnet with a price limit.
235
+ ///
236
+ /// In case if slippage occurs and the price shall move beyond the limit
237
+ /// price, the staking order may execute only partially or not execute
238
+ /// at all.
239
+ ///
240
+ /// # Args:
241
+ /// * 'origin': (<T as frame_system::Config>Origin):
242
+ /// - The signature of the caller's coldkey.
243
+ ///
244
+ /// * 'hotkey' (T::AccountId):
245
+ /// - The associated hotkey account.
246
+ ///
247
+ /// * 'amount_unstaked' (u64):
248
+ /// - The amount of stake to be added to the hotkey staking account.
249
+ ///
250
+ /// * 'limit_price' (u64):
251
+ /// - The limit price expressed in units of RAO per one Alpha.
252
+ ///
253
+ /// * 'allow_partial' (bool):
254
+ /// - Allows partial execution of the amount. If set to false, this becomes
255
+ /// fill or kill type or order.
256
+ ///
257
+ /// # Event:
258
+ /// * StakeRemoved;
259
+ /// - On the successfully removing stake from the hotkey account.
260
+ ///
261
+ /// # Raises:
262
+ /// * 'NotRegistered':
263
+ /// - Thrown if the account we are attempting to unstake from is non existent.
264
+ ///
265
+ /// * 'NonAssociatedColdKey':
266
+ /// - Thrown if the coldkey does not own the hotkey we are unstaking from.
267
+ ///
268
+ /// * 'NotEnoughStakeToWithdraw':
269
+ /// - Thrown if there is not enough stake on the hotkey to withdwraw this amount.
270
+ ///
226
271
pub fn do_remove_stake_limit (
227
272
origin : T :: RuntimeOrigin ,
228
273
hotkey : T :: AccountId ,
229
274
netuid : u16 ,
230
275
alpha_unstaked : u64 ,
231
276
limit_price : u64 ,
277
+ allow_partial : bool ,
232
278
) -> dispatch:: DispatchResult {
233
279
// 1. We check the transaction is signed by the caller and retrieve the T::AccountId coldkey information.
234
280
let coldkey = ensure_signed ( origin) ?;
@@ -240,17 +286,24 @@ impl<T: Config> Pallet<T> {
240
286
alpha_unstaked
241
287
) ;
242
288
243
- // 2. Validate the user input
244
- Self :: validate_remove_stake ( & coldkey, & hotkey, netuid, alpha_unstaked) ?;
245
-
246
- // 3. Calcaulate the maximum amount that can be executed with price limit
289
+ // 2. Calcaulate the maximum amount that can be executed with price limit
247
290
let max_amount = Self :: get_max_amount_remove ( netuid, limit_price) ;
248
291
let mut possible_alpha = alpha_unstaked;
249
292
if possible_alpha > max_amount {
250
293
possible_alpha = max_amount;
251
294
}
252
295
253
- // 4. Swap the alpba to tao and update counters for this subnet.
296
+ // 3. Validate the user input
297
+ Self :: validate_remove_stake (
298
+ & coldkey,
299
+ & hotkey,
300
+ netuid,
301
+ alpha_unstaked,
302
+ max_amount,
303
+ allow_partial,
304
+ ) ?;
305
+
306
+ // 4. Swap the alpha to tao and update counters for this subnet.
254
307
let fee = DefaultStakingFee :: < T > :: get ( ) ;
255
308
let tao_unstaked: u64 =
256
309
Self :: unstake_from_subnet ( & hotkey, & coldkey, netuid, possible_alpha, fee) ;
0 commit comments