@@ -207,7 +207,7 @@ def prompt_stake_amount(
207207 console .print ("[red]Please enter a valid number or 'all'[/red]" )
208208
209209
210- async def stake_move_selection (
210+ async def stake_move_transfer_selection (
211211 subtensor : "SubtensorInterface" ,
212212 wallet : Wallet ,
213213):
@@ -293,25 +293,24 @@ async def stake_move_selection(
293293 title_justify = "center" ,
294294 width = len (origin_hotkey_ss58 ) + 20 ,
295295 )
296- table .add_column ("Index" , justify = "right" )
297296 table .add_column ("Netuid" , style = "cyan" )
298297 table .add_column ("Stake Amount" , style = COLOR_PALETTE ["STAKE" ]["STAKE_AMOUNT" ])
299298
300299 available_netuids = []
301- for idx , netuid in enumerate ( origin_hotkey_info ["netuids" ]) :
300+ for netuid in origin_hotkey_info ["netuids" ]:
302301 stake = origin_hotkey_info ["stakes" ][netuid ]
303302 if stake .tao > 0 :
304303 available_netuids .append (netuid )
305- table .add_row (str (idx ), str ( netuid ), str (stake ))
304+ table .add_row (str (netuid ), str (stake ))
306305
307306 console .print ("\n " , table )
308307
309308 # Select origin netuid
310- netuid_idx = Prompt .ask (
311- "\n Enter the index of the subnet you want to move stake from" ,
312- choices = [str (i ) for i in range ( len ( available_netuids )) ],
309+ origin_netuid = Prompt .ask (
310+ "\n Enter the netuid you want to move stake from" ,
311+ choices = [str (netuid ) for netuid in available_netuids ],
313312 )
314- origin_netuid = available_netuids [ int (netuid_idx )]
313+ origin_netuid = int (origin_netuid )
315314 origin_stake = origin_hotkey_info ["stakes" ][origin_netuid ]
316315
317316 # Ask for amount to move
@@ -334,104 +333,6 @@ async def stake_move_selection(
334333 }
335334
336335
337- async def stake_transfer_selection (
338- wallet : Wallet , subtensor : "SubtensorInterface" , origin_hotkey : str
339- ):
340- """Selection interface for transferring stakes."""
341- (
342- stakes ,
343- all_netuids ,
344- all_subnets ,
345- ) = await asyncio .gather (
346- subtensor .get_stake_for_coldkey (coldkey_ss58 = wallet .coldkeypub .ss58_address ),
347- subtensor .get_all_subnet_netuids (),
348- subtensor .all_subnets (),
349- )
350- all_netuids = sorted (all_netuids )
351- all_subnets = {di .netuid : di for di in all_subnets }
352-
353- available_stakes = {}
354- for stake in stakes :
355- if stake .stake .tao > 0 and stake .hotkey_ss58 == origin_hotkey :
356- available_stakes [stake .netuid ] = {
357- "hotkey_ss58" : stake .hotkey_ss58 ,
358- "stake" : stake .stake ,
359- "is_registered" : stake .is_registered ,
360- }
361-
362- if not available_stakes :
363- console .print ("[red]No stakes available to transfer.[/red]" )
364- return None
365-
366- table = Table (
367- title = (
368- f"\n [{ COLOR_PALETTE ['GENERAL' ]['HEADER' ]} ]"
369- f"Available Stakes to Transfer\n "
370- f"for wallet hotkey:\n "
371- f"[{ COLOR_PALETTE ['GENERAL' ]['HOTKEY' ]} ]{ wallet .hotkey_str } : { wallet .hotkey .ss58_address } "
372- f"[/{ COLOR_PALETTE ['GENERAL' ]['HOTKEY' ]} ]\n "
373- ),
374- show_edge = False ,
375- header_style = "bold white" ,
376- border_style = "bright_black" ,
377- title_justify = "center" ,
378- width = len (wallet .hotkey_str + wallet .hotkey .ss58_address ) + 10 ,
379- )
380-
381- table .add_column ("Index" , justify = "right" , style = "cyan" )
382- table .add_column ("Netuid" )
383- table .add_column ("Name" , style = "cyan" , justify = "left" )
384- table .add_column ("Stake Amount" , style = COLOR_PALETTE ["STAKE" ]["STAKE_AMOUNT" ])
385- table .add_column ("Registered" , justify = "center" )
386-
387- for idx , (netuid , stake_info ) in enumerate (available_stakes .items ()):
388- subnet_name_cell = (
389- f"[{ COLOR_PALETTE ['GENERAL' ]['SYMBOL' ]} ]{ all_subnets [netuid ].symbol if netuid != 0 else 'τ' } [/{ COLOR_PALETTE ['GENERAL' ]['SYMBOL' ]} ]"
390- f" { get_subnet_name (all_subnets [netuid ])} "
391- )
392- table .add_row (
393- str (idx ),
394- str (netuid ),
395- subnet_name_cell ,
396- str (stake_info ["stake" ]),
397- "[dark_sea_green3]YES"
398- if stake_info ["is_registered" ]
399- else f"[{ COLOR_PALETTE ['STAKE' ]['NOT_REGISTERED' ]} ]NO" ,
400- )
401-
402- console .print (table )
403-
404- if not available_stakes :
405- console .print ("[red]No stakes available to transfer.[/red]" )
406- return None
407-
408- # Prompt to select index of stake to transfer
409- selection = Prompt .ask (
410- "\n Enter the index of the stake you want to transfer" ,
411- choices = [str (i ) for i in range (len (available_stakes ))],
412- )
413- selected_netuid = list (available_stakes .keys ())[int (selection )]
414- selected_stake = available_stakes [selected_netuid ]
415-
416- # Prompt for amount
417- stake_balance = selected_stake ["stake" ]
418- amount , _ = prompt_stake_amount (stake_balance , selected_netuid , "transfer" )
419-
420- # Prompt for destination subnet
421- destination_netuid = Prompt .ask (
422- "\n Enter the netuid of the subnet you want to move stake to"
423- + f" ([dim]{ group_subnets (all_netuids )} [/dim])" ,
424- choices = [str (netuid ) for netuid in all_netuids ],
425- show_choices = False ,
426- )
427-
428- return {
429- "origin_netuid" : selected_netuid ,
430- "amount" : amount .tao ,
431- "destination_netuid" : int (destination_netuid ),
432- }
433-
434-
435336async def stake_swap_selection (
436337 subtensor : "SubtensorInterface" ,
437338 wallet : Wallet ,
@@ -540,7 +441,7 @@ async def move_stake(
540441 prompt : bool = True ,
541442):
542443 if interactive_selection :
543- selection = await stake_move_selection (subtensor , wallet )
444+ selection = await stake_move_transfer_selection (subtensor , wallet )
544445 origin_hotkey = selection ["origin_hotkey" ]
545446 origin_netuid = selection ["origin_netuid" ]
546447 amount = selection ["amount" ]
@@ -699,6 +600,7 @@ async def transfer_stake(
699600 dest_netuid : int ,
700601 dest_coldkey_ss58 : str ,
701602 interactive_selection : bool = False ,
603+ stake_all : bool = False ,
702604 prompt : bool = True ,
703605) -> bool :
704606 """Transfers stake from one network to another.
@@ -717,12 +619,13 @@ async def transfer_stake(
717619 Returns:
718620 bool: True if transfer was successful, False otherwise.
719621 """
720- origin_hotkey = origin_hotkey or wallet .hotkey .ss58_address
721622 if interactive_selection :
722- selection = await stake_transfer_selection ( wallet , subtensor , origin_hotkey )
623+ selection = await stake_move_transfer_selection ( subtensor , wallet )
723624 origin_netuid = selection ["origin_netuid" ]
724625 amount = selection ["amount" ]
725626 dest_netuid = selection ["destination_netuid" ]
627+ stake_all = selection ["stake_all" ]
628+ origin_hotkey = selection ["origin_hotkey" ]
726629
727630 # Check if both subnets exist
728631 block_hash = await subtensor .substrate .get_chain_head ()
@@ -750,7 +653,22 @@ async def transfer_stake(
750653 hotkey_ss58 = origin_hotkey ,
751654 netuid = dest_netuid ,
752655 )
753- amount_to_transfer = Balance .from_tao (amount ).set_unit (origin_netuid )
656+
657+ if current_stake .tao == 0 :
658+ err_console .print (
659+ f"[red]No stake found for hotkey: { origin_hotkey } on netuid: { origin_netuid } [/red]"
660+ )
661+ return False
662+
663+ amount_to_transfer = None
664+ if amount :
665+ amount_to_transfer = Balance .from_tao (amount ).set_unit (origin_netuid )
666+ elif stake_all :
667+ amount_to_transfer = current_stake
668+ else :
669+ amount_to_transfer , _ = prompt_stake_amount (
670+ current_stake , origin_netuid , "transfer"
671+ )
754672
755673 # Check if enough stake to transfer
756674 if amount_to_transfer > current_stake :
0 commit comments