Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
ProxyAddressBook,
ProxyAnnouncements,
confirm_action,
print_protection_warnings,
)
from bittensor_cli.src.commands import sudo, wallets, view
from bittensor_cli.src.commands import weights as weights_cmds
Expand Down Expand Up @@ -4699,7 +4700,12 @@ def stake_add(
if safe_staking:
rate_tolerance = self.ask_rate_tolerance(rate_tolerance)
allow_partial_stake = self.ask_partial_stake(allow_partial_stake)
console.print("\n")

print_protection_warnings(
mev_protection=mev_protection,
safe_staking=safe_staking,
command_name="stake add",
)

if netuids:
netuids = parse_to_list(
Expand Down Expand Up @@ -5016,8 +5022,12 @@ def stake_remove(
if safe_staking:
rate_tolerance = self.ask_rate_tolerance(rate_tolerance)
allow_partial_stake = self.ask_partial_stake(allow_partial_stake)
console.print("\n")

print_protection_warnings(
mev_protection=mev_protection,
safe_staking=safe_staking,
command_name="stake remove",
)
if interactive and any(
[hotkey_ss58_address, include_hotkeys, exclude_hotkeys, all_hotkeys]
):
Expand Down Expand Up @@ -5353,6 +5363,11 @@ def stake_move(
"""
self.verbosity_handler(quiet, verbose, json_output, prompt, decline)
proxy = self.is_valid_proxy_name_or_ss58(proxy, announce_only)
print_protection_warnings(
mev_protection=mev_protection,
safe_staking=None,
command_name="stake move",
)
if prompt:
if not confirm_action(
"This transaction will [bold]move stake[/bold] to another hotkey while keeping the same "
Expand Down Expand Up @@ -5574,6 +5589,11 @@ def stake_transfer(
"""
self.verbosity_handler(quiet, verbose, json_output, prompt, decline)
proxy = self.is_valid_proxy_name_or_ss58(proxy, announce_only)
print_protection_warnings(
mev_protection=mev_protection,
safe_staking=None,
command_name="stake transfer",
)
if prompt:
if not confirm_action(
"This transaction will [bold]transfer ownership[/bold] from one coldkey to another, in subnets "
Expand Down Expand Up @@ -5780,6 +5800,15 @@ def stake_swap(
"[dim]This command moves stake from one subnet to another subnet while keeping "
"the same coldkey-hotkey pair.[/dim]"
)
safe_staking = self.ask_safe_staking(safe_staking)
if safe_staking:
rate_tolerance = self.ask_rate_tolerance(rate_tolerance)
allow_partial_stake = self.ask_partial_stake(allow_partial_stake)
print_protection_warnings(
mev_protection=mev_protection,
safe_staking=safe_staking,
command_name="stake swap",
)

wallet = self.wallet_ask(
wallet_name,
Expand All @@ -5803,10 +5832,6 @@ def stake_swap(
)
if not amount and not swap_all:
amount = FloatPrompt.ask("Enter the [blue]amount[/blue] to swap")
safe_staking = self.ask_safe_staking(safe_staking)
if safe_staking:
rate_tolerance = self.ask_rate_tolerance(rate_tolerance)
allow_partial_stake = self.ask_partial_stake(allow_partial_stake)

logger.debug(
"args:\n"
Expand Down Expand Up @@ -7598,6 +7623,11 @@ def subnets_create(
"""
self.verbosity_handler(quiet, verbose, json_output, prompt)
proxy = self.is_valid_proxy_name_or_ss58(proxy, announce_only)
print_protection_warnings(
mev_protection=mev_protection,
safe_staking=None,
command_name="subnets create",
)
wallet = self.wallet_ask(
wallet_name,
wallet_path,
Expand Down
36 changes: 36 additions & 0 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,42 @@ def print_success(message: str, status=None):
print_console(success_message, "green", console)


def print_protection_warnings(
mev_protection: bool,
safe_staking: Optional[bool] = None,
command_name: str = "",
) -> None:
"""
Print warnings about missing MEV protection and/or limit price protection.

Args:
mev_protection: Whether MEV protection is enabled.
safe_staking: Whether safe staking (limit price protection) is enabled.
None if limit price protection is not available for this command.
command_name: Name of the command (e.g., "stake add") for context.
"""
warnings = []

if not mev_protection:
warnings.append(
"⚠️ [dim][yellow]Warning:[/yellow] MEV protection is disabled. "
"This transaction may be exposed to MEV attacks.[/dim]"
)

if safe_staking is not None and not safe_staking:
warnings.append(
"⚠️ [dim][yellow]Warning:[/yellow] Limit price protection (safe staking) is disabled. "
"This transaction may be subject to slippage.[/dim]"
)

if warnings:
if command_name:
console.print(f"\n[dim]Protection status for '{command_name}':[/dim]")
for warning in warnings:
console.print(warning)
console.print()


RAO_PER_TAO = 1e9
U16_MAX = 65535
U64_MAX = 18446744073709551615
Expand Down
Loading