Skip to content

Commit d696e3b

Browse files
authored
Merge pull request #724 from opentensor/feat/mev-protection-staking-ops
Feat: MeV protection in staking operations
2 parents 7373f7f + 42055a3 commit d696e3b

File tree

17 files changed

+1178
-158
lines changed

17 files changed

+1178
-158
lines changed

bittensor_cli/cli.py

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ def edit_help(cls, option_name: str, help_text: str):
346346
"--dashboard.path",
347347
help="Path to save the dashboard HTML file. For example: `~/.bittensor/dashboard`.",
348348
)
349+
mev_protection = typer.Option(
350+
True,
351+
"--mev-protection/--no-mev-protection",
352+
show_default=False,
353+
help="Enable or disable MEV protection [dim](default: enabled)[/dim].",
354+
)
349355
json_output = typer.Option(
350356
False,
351357
"--json-output",
@@ -3972,6 +3978,7 @@ def stake_add(
39723978
rate_tolerance: Optional[float] = Options.rate_tolerance,
39733979
safe_staking: Optional[bool] = Options.safe_staking,
39743980
allow_partial_stake: Optional[bool] = Options.allow_partial_stake,
3981+
mev_protection: bool = Options.mev_protection,
39753982
period: int = Options.period,
39763983
prompt: bool = Options.prompt,
39773984
quiet: bool = Options.quiet,
@@ -4006,6 +4013,9 @@ def stake_add(
40064013
7. Stake the same amount to multiple subnets:
40074014
[green]$[/green] btcli stake add --amount 100 --netuids 4,5,6
40084015
4016+
8. Stake without MEV protection:
4017+
[green]$[/green] btcli stake add --amount 100 --netuid 1 --no-mev-protection
4018+
40094019
[bold]Safe Staking Parameters:[/bold]
40104020
• [blue]--safe[/blue]: Enables rate tolerance checks
40114021
• [blue]--tolerance[/blue]: Maximum % rate change allowed (0.05 = 5%)
@@ -4201,6 +4211,7 @@ def stake_add(
42014211
f"rate_tolerance: {rate_tolerance}\n"
42024212
f"allow_partial_stake: {allow_partial_stake}\n"
42034213
f"period: {period}\n"
4214+
f"mev_protection: {mev_protection}\n"
42044215
)
42054216
return self._run_command(
42064217
add_stake.stake_add(
@@ -4218,6 +4229,7 @@ def stake_add(
42184229
allow_partial_stake,
42194230
json_output,
42204231
period,
4232+
mev_protection,
42214233
)
42224234
)
42234235

@@ -4270,6 +4282,7 @@ def stake_remove(
42704282
safe_staking: Optional[bool] = Options.safe_staking,
42714283
allow_partial_stake: Optional[bool] = Options.allow_partial_stake,
42724284
period: int = Options.period,
4285+
mev_protection: bool = Options.mev_protection,
42734286
prompt: bool = Options.prompt,
42744287
interactive: bool = typer.Option(
42754288
False,
@@ -4306,6 +4319,9 @@ def stake_remove(
43064319
6. Unstake all Alpha from a hotkey and stake to Root:
43074320
[green]$[/green] btcli stake remove --all-alpha
43084321
4322+
7. Unstake without MEV protection:
4323+
[green]$[/green] btcli stake remove --amount 100 --netuid 1 --no-mev-protection
4324+
43094325
[bold]Safe Staking Parameters:[/bold]
43104326
• [blue]--safe[/blue]: Enables rate tolerance checks during unstaking
43114327
• [blue]--tolerance[/blue]: Max allowed rate change (0.05 = 5%)
@@ -4478,7 +4494,8 @@ def stake_remove(
44784494
f"all_hotkeys: {all_hotkeys}\n"
44794495
f"include_hotkeys: {include_hotkeys}\n"
44804496
f"exclude_hotkeys: {exclude_hotkeys}\n"
4481-
f"era: {period}"
4497+
f"era: {period}\n"
4498+
f"mev_protection: {mev_protection}"
44824499
)
44834500
return self._run_command(
44844501
remove_stake.unstake_all(
@@ -4492,6 +4509,7 @@ def stake_remove(
44924509
prompt=prompt,
44934510
json_output=json_output,
44944511
era=period,
4512+
mev_protection=mev_protection,
44954513
)
44964514
)
44974515
elif (
@@ -4544,7 +4562,8 @@ def stake_remove(
45444562
f"safe_staking: {safe_staking}\n"
45454563
f"rate_tolerance: {rate_tolerance}\n"
45464564
f"allow_partial_stake: {allow_partial_stake}\n"
4547-
f"era: {period}"
4565+
f"era: {period}\n"
4566+
f"mev_protection: {mev_protection}\n"
45484567
)
45494568

45504569
return self._run_command(
@@ -4564,6 +4583,7 @@ def stake_remove(
45644583
allow_partial_stake=allow_partial_stake,
45654584
json_output=json_output,
45664585
era=period,
4586+
mev_protection=mev_protection,
45674587
)
45684588
)
45694589

@@ -4609,6 +4629,7 @@ def stake_move(
46094629
False, "--stake-all", "--all", help="Stake all", prompt=False
46104630
),
46114631
period: int = Options.period,
4632+
mev_protection: bool = Options.mev_protection,
46124633
prompt: bool = Options.prompt,
46134634
quiet: bool = Options.quiet,
46144635
verbose: bool = Options.verbose,
@@ -4630,9 +4651,13 @@ def stake_move(
46304651
46314652
If no arguments are provided, an interactive selection menu will be shown.
46324653
4633-
EXAMPLE
4654+
EXAMPLES
46344655
4635-
[green]$[/green] btcli stake move
4656+
1. Interactive move (guided prompts):
4657+
[green]$[/green] btcli stake move
4658+
4659+
2. Move stake without MEV protection:
4660+
[green]$[/green] btcli stake move --no-mev-protection
46364661
"""
46374662
self.verbosity_handler(quiet, verbose, json_output)
46384663
if prompt:
@@ -4747,6 +4772,7 @@ def stake_move(
47474772
f"era: {period}\n"
47484773
f"interactive_selection: {interactive_selection}\n"
47494774
f"prompt: {prompt}\n"
4775+
f"mev_protection: {mev_protection}\n"
47504776
)
47514777
result, ext_id = self._run_command(
47524778
move_stake.move_stake(
@@ -4761,6 +4787,7 @@ def stake_move(
47614787
era=period,
47624788
interactive_selection=interactive_selection,
47634789
prompt=prompt,
4790+
mev_protection=mev_protection,
47644791
)
47654792
)
47664793
if json_output:
@@ -4801,6 +4828,7 @@ def stake_transfer(
48014828
stake_all: bool = typer.Option(
48024829
False, "--stake-all", "--all", help="Stake all", prompt=False
48034830
),
4831+
mev_protection: bool = Options.mev_protection,
48044832
period: int = Options.period,
48054833
prompt: bool = Options.prompt,
48064834
quiet: bool = Options.quiet,
@@ -4838,6 +4866,9 @@ def stake_transfer(
48384866
48394867
Transfer all available stake from origin hotkey:
48404868
[green]$[/green] btcli stake transfer --all --origin-netuid 1 --dest-netuid 2
4869+
4870+
Transfer stake without MEV protection:
4871+
[green]$[/green] btcli stake transfer --origin-netuid 1 --dest-netuid 2 --amount 100 --no-mev-protection
48414872
"""
48424873
self.verbosity_handler(quiet, verbose, json_output)
48434874
if prompt:
@@ -4933,7 +4964,8 @@ def stake_transfer(
49334964
f"dest_coldkey_ss58: {dest_ss58}\n"
49344965
f"amount: {amount}\n"
49354966
f"era: {period}\n"
4936-
f"stake_all: {stake_all}"
4967+
f"stake_all: {stake_all}\n"
4968+
f"mev_protection: {mev_protection}"
49374969
)
49384970
result, ext_id = self._run_command(
49394971
move_stake.transfer_stake(
@@ -4948,6 +4980,7 @@ def stake_transfer(
49484980
interactive_selection=interactive_selection,
49494981
stake_all=stake_all,
49504982
prompt=prompt,
4983+
mev_protection=mev_protection,
49514984
)
49524985
)
49534986
if json_output:
@@ -4992,6 +5025,7 @@ def stake_swap(
49925025
prompt: bool = Options.prompt,
49935026
wait_for_inclusion: bool = Options.wait_for_inclusion,
49945027
wait_for_finalization: bool = Options.wait_for_finalization,
5028+
mev_protection: bool = Options.mev_protection,
49955029
quiet: bool = Options.quiet,
49965030
verbose: bool = Options.verbose,
49975031
json_output: bool = Options.json_output,
@@ -5011,10 +5045,13 @@ def stake_swap(
50115045
50125046
If no arguments are provided, an interactive selection menu will be shown.
50135047
5014-
EXAMPLE
5048+
EXAMPLES
50155049
5016-
Swap 100 TAO from subnet 1 to subnet 2:
5017-
[green]$[/green] btcli stake swap --wallet-name default --wallet-hotkey default --origin-netuid 1 --dest-netuid 2 --amount 100
5050+
1. Swap 100 TAO from subnet 1 to subnet 2:
5051+
[green]$[/green] btcli stake swap --wallet-name default --wallet-hotkey default --origin-netuid 1 --dest-netuid 2 --amount 100
5052+
5053+
2. Swap stake without MEV protection:
5054+
[green]$[/green] btcli stake swap --origin-netuid 1 --dest-netuid 2 --amount 100 --no-mev-protection
50185055
"""
50195056
self.verbosity_handler(quiet, verbose, json_output)
50205057
console.print(
@@ -5056,6 +5093,7 @@ def stake_swap(
50565093
f"prompt: {prompt}\n"
50575094
f"wait_for_inclusion: {wait_for_inclusion}\n"
50585095
f"wait_for_finalization: {wait_for_finalization}\n"
5096+
f"mev_protection: {mev_protection}\n"
50595097
)
50605098
result, ext_id = self._run_command(
50615099
move_stake.swap_stake(
@@ -5070,6 +5108,7 @@ def stake_swap(
50705108
prompt=prompt,
50715109
wait_for_inclusion=wait_for_inclusion,
50725110
wait_for_finalization=wait_for_finalization,
5111+
mev_protection=mev_protection,
50735112
)
50745113
)
50755114
if json_output:
@@ -5085,6 +5124,7 @@ def stake_wizard(
50855124
wallet_path: Optional[str] = Options.wallet_path,
50865125
wallet_hotkey: Optional[str] = Options.wallet_hotkey,
50875126
period: int = Options.period,
5127+
mev_protection: bool = Options.mev_protection,
50885128
prompt: bool = Options.prompt,
50895129
quiet: bool = Options.quiet,
50905130
verbose: bool = Options.verbose,
@@ -5150,6 +5190,7 @@ def stake_wizard(
51505190
era=period,
51515191
interactive_selection=False,
51525192
prompt=prompt,
5193+
mev_protection=mev_protection,
51535194
)
51545195
)
51555196
elif operation == "transfer":
@@ -5179,6 +5220,7 @@ def stake_wizard(
51795220
era=period,
51805221
interactive_selection=False,
51815222
prompt=prompt,
5223+
mev_protection=mev_protection,
51825224
)
51835225
)
51845226
elif operation == "swap":
@@ -5194,6 +5236,7 @@ def stake_wizard(
51945236
era=period,
51955237
interactive_selection=False,
51965238
prompt=prompt,
5239+
mev_protection=mev_protection,
51975240
)
51985241
)
51995242
else:
@@ -6427,6 +6470,7 @@ def subnets_create(
64276470
additional_info: Optional[str] = typer.Option(
64286471
None, "--additional-info", help="Additional information"
64296472
),
6473+
mev_protection: bool = Options.mev_protection,
64306474
json_output: bool = Options.json_output,
64316475
prompt: bool = Options.prompt,
64326476
quiet: bool = Options.quiet,
@@ -6445,6 +6489,9 @@ def subnets_create(
64456489
64466490
2. Create with GitHub repo and contact email:
64476491
[green]$[/green] btcli subnets create --subnet-name MySubnet --github-repo https://github.com/myorg/mysubnet --subnet-contact team@mysubnet.net
6492+
6493+
3. Create subnet without MEV protection:
6494+
[green]$[/green] btcli subnets create --no-mev-protection
64486495
"""
64496496
self.verbosity_handler(quiet, verbose, json_output)
64506497
wallet = self.wallet_ask(
@@ -6472,7 +6519,12 @@ def subnets_create(
64726519
logger.debug(f"args:\nnetwork: {network}\nidentity: {identity}\n")
64736520
self._run_command(
64746521
subnets.create(
6475-
wallet, self.initialize_chain(network), identity, json_output, prompt
6522+
wallet,
6523+
self.initialize_chain(network),
6524+
identity,
6525+
json_output,
6526+
prompt,
6527+
mev_protection,
64766528
)
64776529
)
64786530

0 commit comments

Comments
 (0)