Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the
btcli liquidity adduser flow by making it price-aware and balance-aware, reducing unnecessary prompts, and ensuring consistent--json-outputbehavior 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:
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 addWhen
--prompt(default), the command now:netuid(if not provided)price_lowandprice_highprice_low >= current_priceprice_high <= current_price2) Non-interactive behavior remains supported
When
--no-prompt, the command requires:--netuid--liquidity--price-low--price-highThe command validates
price_low < price_highand subnet existence before submitting.3) Fix:
--json-outputnow always prints JSON on failurePreviously, 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-outputwas set.This PR ensures that all early failures in
liquidity.add_liquidity()emit a consistent JSON schema:success: boolmessage: strextrinsic_identifier: str | nullImplementation details
CLI layer
bittensor_cli/cli.pyCLIManager.liquidity_add()now defers interactive prompting and chain-dependent decisions to the async command implementation.liquidity/price_low/price_highas optional values (converted toBalanceif provided; otherwiseNone).Liquidity command
bittensor_cli/src/commands/liquidity/liquidity.pyLiquidity math helpers
bittensor_cli/src/commands/liquidity/utils.pyTests
tests/unit_tests/test_liquidity_add.py--json-outputis emitted for early failures (unlock failure, subnet missing)--json-outputis emitted for extrinsic failuremax_liquidity_in_range()math helperNotes / follow-ups