Skip to content

Liquidity operations #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: staging
Choose a base branch
from
Open

Liquidity operations #495

wants to merge 8 commits into from

Conversation

gztensor
Copy link

@gztensor gztensor commented Jun 11, 2025

This PR is only an example, by no means is a final implementation. It shows how to add the following functionality:

  • Adding user liquidity
  • Removing user liquidity
  • Viewing user liquidity and accrued fees

Testing on the local network:

  1. Create and configure subnet:
  • Give your coldkey 2000 TAO
  • Call startCall
  • Enable user liquidity: swap::setUserLiquidityEnabled
  1. Add liquidity
$ btcli lq add --network=local
Enter the netuid to use: 2
Enter the wallet name (default): 
Enter the wallet hotkey name or ss58 address to use stake from: 5Eeq15e55UTfFcsw6kUNRhzRwTsAHciXk5sPajARWXxtjzyA

Enter the amount of liquidity: 1

Enter the liquidity position low price: 0.1 

Enter the liquidity position high price: 0.9
  1. View added liquidity
$ btcli lq list --network=local
Enter the netuid to use: 2
Enter the wallet name (default): 
p = BittensorScaleType(value={'id': (2,), 'netuid': (2,), 'tick_low': (-23027,), 'tick_high': (-1053,), 'liquidity': 1000000000, 'fees_tao': {'bits': 0}, 'fees_alpha': {'bits': 0}})>
tick_low = {'liquidity_net': 1000000000, 'liquidity_gross': 1000000000, 'fees_out_tao': {'bits': 0}, 'fees_out_alpha': {'bits': 0}}
tick_high = {'liquidity_net': -1000000000, 'liquidity_gross': 1000000000, 'fees_out_tao': {'bits': 0}, 'fees_out_alpha': {'bits': 0}}
fees_in_range_tao = 0.0
fees_tao = 0.0000 τ
Position ID: 2
Position liquidity: 1.0000 τ
Price range:
   low:  0.10000002203192325
   high: 0.9000592042233925
Fees accrued:
   tao:   0.0000 τ
   alpha: 0.0000 τ

@thewhaleking thewhaleking changed the base branch from main to staging June 12, 2025 17:04
@thewhaleking
Copy link
Contributor

@gztensor when do you expect this to be able to work on testnet or mainnet?

@@ -0,0 +1,30 @@
import math

min_tick = -887272
Copy link

@bdmason bdmason Jun 19, 2025

Choose a reason for hiding this comment

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

I think these need to be halved to match the ticks used in rust

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

Successfully merging this pull request may close these issues.

4 participants