Skip to content

Conversation

@leonace924
Copy link
Contributor

Summary

This PR improves the btcli liquidity add user flow by making it price-aware and balance-aware, reducing unnecessary prompts, and ensuring consistent --json-output behavior on failures. It also adds unit tests for the new behavior.

Closes #532

Motivation

Adding liquidity to a Uniswap-v3 style range behaves differently depending on where the current subnet price sits relative to the chosen range:

  • If the price is below the range, the position is effectively Alpha-only.
  • If the price is above the range, the position is effectively TAO-only.
  • If the price is inside the range, the position requires a TAO + Alpha mix.

This PR updates the CLI flow to guide users correctly based on current subnet price, and to show the maximum liquidity they can provide given their balances.

User-facing changes

1) Improved interactive flow for btcli liquidity add

When --prompt (default), the command now:

  1. Prompts for netuid (if not provided)
  2. Checks that the subnet exists
  3. Prompts for price_low and price_high
  4. Fetches the current subnet price from chain
  5. Branches based on the relationship between range and current price:
    • If price_low >= current_price
      • Prompt: Alpha amount to provide
      • Prompt: optional hotkey to source Alpha stake from (defaults to wallet hotkey)
      • Computes liquidity from Alpha-only deposit
    • If price_high <= current_price
      • Prompt: TAO amount to provide
      • Prompt: optional hotkey (still passed to the extrinsic; has no effect on amounts in this scenario)
      • Computes liquidity from TAO-only deposit
    • Else (price is inside the range)
      • Prompt: optional hotkey (defaults to wallet hotkey)
      • Fetches user TAO balance (coldkey) and Alpha stake (coldkey+hotkey+netuid)
      • Computes and displays the maximum TAO/Alpha amounts currently providable for the chosen range
      • Lets the user choose whether to specify the deposit in TAO or Alpha (default TAO)
      • Displays the corresponding token amount implied by that choice
  6. Confirms parameters and submits the extrinsic

2) Non-interactive behavior remains supported

When --no-prompt, the command requires:

  • --netuid
  • --liquidity
  • --price-low
  • --price-high

The command validates price_low < price_high and subnet existence before submitting.

3) Fix: --json-output now always prints JSON on failure

Previously, some early-return paths (e.g. validation failures or subnet-not-found) could exit before reaching the JSON print block, resulting in no output when --json-output was set.

This PR ensures that all early failures in liquidity.add_liquidity() emit a consistent JSON schema:

  • success: bool
  • message: str
  • extrinsic_identifier: str | null

Implementation details

CLI layer

  • bittensor_cli/cli.py
    • CLIManager.liquidity_add() now defers interactive prompting and chain-dependent decisions to the async command implementation.
    • CLI passes liquidity/price_low/price_high as optional values (converted to Balance if provided; otherwise None).

Liquidity command

  • bittensor_cli/src/commands/liquidity/liquidity.py
    • Implements the new decision tree based on current subnet price.
    • Adds helper for consistent JSON printing on early returns.

Liquidity math helpers

  • bittensor_cli/src/commands/liquidity/utils.py
    • Adds helper functions to compute liquidity from token amounts for:
      • Alpha-only (below range)
      • TAO-only (above range)
      • In-range (TAO or Alpha specified)
    • Adds a helper to compute max in-range liquidity given TAO + Alpha availability.

Tests

  • tests/unit_tests/test_liquidity_add.py
    • Verifies --json-output is emitted for early failures (unlock failure, subnet missing)
    • Verifies --json-output is emitted for extrinsic failure
    • Adds a sanity check for the max_liquidity_in_range() math helper

Notes / follow-ups

  • The in-range flow currently asks the user to choose whether to specify deposit in TAO or Alpha (default TAO). If we want to allow specifying both explicitly (TAO + Alpha) we can extend the prompt flow and validation accordingly.

@leonace924
Copy link
Contributor Author

@thewhaleking would you review my PR for add liquidity logic?
Thank you

@leonace924
Copy link
Contributor Author

leonace924 commented Dec 16, 2025

@ibraheem-abe @thewhaleking we won't improve add liquidity logic? I added test and --json-input and so on

@ibraheem-abe
Copy link
Contributor

The liquidity logic is going to be updated soon from the subtensor side - I am not sure if adding changes at this point will prove to be useful

@thewhaleking
Copy link
Contributor

The liquidity logic is going to be updated soon from the subtensor side - I am not sure if adding changes at this point will prove to be useful

True. Let's put a pin in this PR until we get a better timeline on the new liquidity logic.

@thewhaleking thewhaleking added Do not merge Waiting for Upstream Waiting for a change to some upstream (non-btcli) library/chain labels Dec 17, 2025
@leonace924 leonace924 marked this pull request as draft December 20, 2025 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Do not merge Waiting for Upstream Waiting for a change to some upstream (non-btcli) library/chain

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants