Skip to content

Conversation

@Mobile-Crest
Copy link

Improve Add Liquidity Logic

Closes #532

Summary

This PR improves the btcli liquidity add command by implementing a more dynamic and user-friendly interactive flow for liquidity provision. The new logic guides users through a series of prompts based on the current subnet price and their available balances.

Changes

1. New Helper Functions (bittensor_cli/src/commands/liquidity/utils.py)

  • calculate_max_liquidity_from_balances() - Calculates the maximum liquidity that can be provided given TAO and Alpha balances, current price, and price range
  • calculate_alpha_from_tao() - Calculates the Alpha amount needed for a given TAO amount
  • calculate_tao_from_alpha() - Calculates the TAO amount needed for a given Alpha amount

2. Interactive Flow (bittensor_cli/src/commands/liquidity/liquidity.py)

Added add_liquidity_interactive() function that implements the following flow:

  1. Check subnet existence - Validates that the specified netuid exists
  2. Prompt for price range - Asks user to enter low and high position prices
  3. Fetch current subnet price - Retrieves the current Alpha/TAO price from the chain
  4. Conditional logic based on price position:
    • Low price ≥ current price: Only Alpha tokens needed
      • Prompts for Alpha amount and optional hotkey
    • High price ≤ current price: Only TAO tokens needed
      • Prompts for TAO amount and optional hotkey
    • Current price within range: Both TAO and Alpha needed
      • Fetches user's TAO and Alpha balances from chain
      • Calculates and displays maximum liquidity that can be provided
      • Allows user to specify either TAO or Alpha amount
      • Automatically calculates the corresponding amount of the other token
  5. Execute the extrinsic - Submits the liquidity addition transaction

3. CLI Updates (bittensor_cli/cli.py)

  • Added --tao-amount and --alpha-amount options to support the new flow
  • Modified liquidity_add() command to delegate to the new interactive function

4. Unit Tests (tests/unit_tests/test_liquidity_utils.py)

Added comprehensive unit tests covering:

  • Maximum liquidity calculation for all three price scenarios
  • Alpha amount calculation from TAO
  • TAO amount calculation from Alpha
  • Reciprocal calculation consistency

Benefits

  • User-friendly: Clear prompts guide users through the liquidity addition process
  • Smart: Automatically determines which tokens are needed based on price position
  • Helpful: Shows maximum liquidity that can be provided with current balances
  • Flexible: Supports specifying either TAO or Alpha amount in mixed scenarios
  • Safe: Validates inputs and provides clear feedback at each step

Testing

All unit tests pass successfully:

python -m pytest tests/unit_tests/test_liquidity_utils.py -v

Note: The e2e test (test_liquidity.py) requires a running Docker container with a local blockchain node, which is infrastructure-dependent. The unit tests validate the core logic without requiring that infrastructure.

Example Usage

# Interactive mode (recommended)
btcli liquidity add --netuid 2

# With pre-specified values
btcli liquidity add --netuid 2 --price-low 1.5 --price-high 2.0 --tao-amount 10.0

Contribution by Gittensor, learn more at https://gittensor.io/

@Mobile-Crest
Copy link
Author

@basfroman
looking forward to your review on this pull request

@thewhaleking thewhaleking requested a review from a team December 3, 2025 12:09
Copy link
Contributor

@thewhaleking thewhaleking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gotten only about 100 lines into this PR, and it's a mess. It doesn't work in many situations, it hand-holds in the wrong ways, it ignores the use of --no-prompt.

Please don't submit PRs like this in the future. I'm assuming this was entirely chatGPT generated without even a look-over at the output, but please don't do this.

@Mobile-Crest Mobile-Crest marked this pull request as draft December 3, 2025 13:52
@Mobile-Crest Mobile-Crest marked this pull request as ready for review December 4, 2025 18:09
@Mobile-Crest Mobile-Crest marked this pull request as draft December 4, 2025 18:11
@Mobile-Crest Mobile-Crest marked this pull request as ready for review December 4, 2025 18:54
@Mobile-Crest
Copy link
Author

@thewhaleking
can you please review this pr again?
I've attached some preview below

image image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still no respect for --no-prompt

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think extrinsic function doesn't accept prompt, let me know if I am wrong

async def add_liquidity_extrinsic(
subtensor: "SubtensorInterface",

@Mobile-Crest
Copy link
Author

Mobile-Crest commented Dec 5, 2025

@thewhaleking
can you please give me any feedback on the pr?
let me know if I misunderstood something

price_high: Optional[float],
tao_amount: Optional[float],
alpha_amount: Optional[float],
prompt: bool,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thewhaleking
prompt is supported here
I've moved all extrinsic functions to extrinsic folder, and this is the command function which accepts prompt

)

# Step 6: Confirm and execute the extrinsic
if prompt:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where it checks if prompt is enabled or not and ask user confirmation if enabled

@thewhaleking
Copy link
Contributor

Sorry, I meant --json-output, instead of --no-prompt.

This command:

btcli l add --no-prompt --network finney --netuid 120 --price-low 1 --price-high 2 --liquidity 100 --json-output

works fine in the feat/thewhaleking/proxy-app branch in which I am currently working, producing:

{
  "success": false,
  "message": "Subtensor returned `SubstrateRequestException(Invalid Transaction)` error. This means: `Inability to pay some fees (e.g. account balance too low)`.",
  "extrinsic_identifier": null
}

However, in your branch, it produces no output whatsoever (at least when unsuccessful).

@Mobile-Crest
Copy link
Author

@thewhaleking
can you plz open back the pr? let me check and push the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants