Skip to content

Commit b647ff4

Browse files
authored
Merge pull request latent-to#779 from opentensor/feat/slippage-prot-stake-swap
2 parents cb77314 + a406e07 commit b647ff4

3 files changed

Lines changed: 262 additions & 34 deletions

File tree

bittensor_cli/cli.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5641,6 +5641,9 @@ def stake_swap(
56415641
wait_for_inclusion: bool = Options.wait_for_inclusion,
56425642
wait_for_finalization: bool = Options.wait_for_finalization,
56435643
mev_protection: bool = Options.mev_protection,
5644+
rate_tolerance: Optional[float] = Options.rate_tolerance,
5645+
safe_staking: Optional[bool] = Options.safe_staking,
5646+
allow_partial_stake: Optional[bool] = Options.allow_partial_stake,
56445647
quiet: bool = Options.quiet,
56455648
verbose: bool = Options.verbose,
56465649
json_output: bool = Options.json_output,
@@ -5667,6 +5670,12 @@ def stake_swap(
56675670
56685671
2. Swap stake without MEV protection:
56695672
[green]$[/green] btcli stake swap --origin-netuid 1 --dest-netuid 2 --amount 100 --no-mev-protection
5673+
5674+
3. Swap stake with custom tolerance and partial stake:
5675+
[green]$[/green] btcli stake swap --origin-netuid 1 --dest-netuid 2 --amount 100 --rate-tolerance 0.01 --allow-partial-stake
5676+
5677+
4. Swap stake without safe staking:
5678+
[green]$[/green] btcli stake swap --origin-netuid 1 --dest-netuid 2 --amount 100 --unsafe
56705679
"""
56715680
self.verbosity_handler(quiet, verbose, json_output, prompt, decline)
56725681
proxy = self.is_valid_proxy_name_or_ss58(proxy, announce_only)
@@ -5697,6 +5706,11 @@ def stake_swap(
56975706
)
56985707
if not amount and not swap_all:
56995708
amount = FloatPrompt.ask("Enter the [blue]amount[/blue] to swap")
5709+
safe_staking = self.ask_safe_staking(safe_staking)
5710+
if safe_staking:
5711+
rate_tolerance = self.ask_rate_tolerance(rate_tolerance)
5712+
allow_partial_stake = self.ask_partial_stake(allow_partial_stake)
5713+
57005714
logger.debug(
57015715
"args:\n"
57025716
f"network: {network}\n"
@@ -5708,6 +5722,9 @@ def stake_swap(
57085722
f"proxy: {proxy}\n"
57095723
f"interactive_selection: {interactive_selection}\n"
57105724
f"prompt: {prompt}\n"
5725+
f"safe_staking: {safe_staking}\n"
5726+
f"rate_tolerance: {rate_tolerance}\n"
5727+
f"allow_partial_stake: {allow_partial_stake}\n"
57115728
f"wait_for_inclusion: {wait_for_inclusion}\n"
57125729
f"wait_for_finalization: {wait_for_finalization}\n"
57135730
f"mev_protection: {mev_protection}\n"
@@ -5719,6 +5736,9 @@ def stake_swap(
57195736
origin_netuid=origin_netuid,
57205737
destination_netuid=dest_netuid,
57215738
amount=amount,
5739+
safe_staking=safe_staking,
5740+
rate_tolerance=rate_tolerance,
5741+
allow_partial_stake=allow_partial_stake,
57225742
swap_all=swap_all,
57235743
era=period,
57245744
interactive_selection=interactive_selection,
@@ -5745,6 +5765,9 @@ def stake_wizard(
57455765
wallet_hotkey: Optional[str] = Options.wallet_hotkey,
57465766
period: int = Options.period,
57475767
mev_protection: bool = Options.mev_protection,
5768+
rate_tolerance: Optional[float] = Options.rate_tolerance,
5769+
safe_staking: Optional[bool] = Options.safe_staking,
5770+
allow_partial_stake: Optional[bool] = Options.allow_partial_stake,
57485771
prompt: bool = Options.prompt,
57495772
decline: bool = Options.decline,
57505773
quiet: bool = Options.quiet,
@@ -5848,6 +5871,10 @@ def stake_wizard(
58485871
)
58495872
elif operation == "swap":
58505873
# Execute swap operation
5874+
safe_staking = self.ask_safe_staking(safe_staking)
5875+
if safe_staking:
5876+
rate_tolerance = self.ask_rate_tolerance(rate_tolerance)
5877+
allow_partial_stake = self.ask_partial_stake(allow_partial_stake)
58515878
result, ext_id = self._run_command(
58525879
move_stake.swap_stake(
58535880
wallet=wallet,
@@ -5856,6 +5883,9 @@ def stake_wizard(
58565883
destination_netuid=wizard_result["destination_netuid"],
58575884
amount=wizard_result.get("amount"),
58585885
swap_all=False,
5886+
safe_staking=safe_staking,
5887+
rate_tolerance=rate_tolerance,
5888+
allow_partial_stake=allow_partial_stake,
58595889
era=period,
58605890
interactive_selection=False,
58615891
prompt=prompt,

0 commit comments

Comments
 (0)