Skip to content
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

Range Liquidity TODOs #177

Open
9 of 13 tasks
hdevalence opened this issue Dec 4, 2024 · 1 comment
Open
9 of 13 tasks

Range Liquidity TODOs #177

hdevalence opened this issue Dec 4, 2024 · 1 comment
Assignees

Comments

@hdevalence
Copy link
Member

hdevalence commented Dec 4, 2024

Checklist of iteration points following the initial Range Liquidity implementation in #156

Screenshot:

Screenshot 2024-12-04 at 12 17 44 AM

Highlights (top to bottom):

  • Change "Liquidity Amount" to "Liquidity Target", to better convey that this is a value target for two-sided liquidity rather than the amount of reserves
  • Numeric text inputs don't allow an empty string "", they should allow this value and treat it as 0
    • This causes bad UX where a user can't delete all the text and then type in a different number
  • Change Available Balance to show available balance of both assets, to hint to the user that this is two-sided liquidity at the top rather than just at the bottom
  • Change "Upper bound" to "Upper Price Bound" to have consistent capitalization and convey that it's a price
  • Price range prefill buttons for upper bound don't work
  • Change "Lower bound" to "Lower Price Bound" to have consistent capitalization and convey that it's a price
  • Price range prefill buttons for lower bound don't work
  • Number of positions should be pre filled with slider setting
  • Slider setting should default to middle of range (10)

Also:

  • Number of positions input should validate number to have same range as slider, currently I can input 0 and it propagates through
  • Tooltip text needs to be filled in
  • With a manually input range (from the example below), box errors with "Please enter a valid range"

Finally, there are non-cosmetic changes to the substance of the strategy.

  • Fix strategy math (details below)

The liquidity target is supposed to represent the total amount of the quote asset the user would retain if all of the base asset were sold for the quote asset as the price goes up and out of range.

Compare:

Screenshot 2024-12-04 at 12 31 34 AM Screenshot 2024-12-04 at 12 31 47 AM

With:

pcli --home ~/data/pcli/prax-demo/ tx lp replicate linear upenumbra:transfer/channel-2/uusdc 28000000transfer/channel-2/uusdc --lower-price 0.9 --upper-price 1.2 --fee-bps 100 --num-positions 14
Scanning blocks from last sync height 2354461 to latest height 2367641
[0s] ██████████████████████████████████████████████████   13180/13180   65876/s ETA: 0s
#################################################################################
########################### LIQUIDITY SUMMARY ###################################
#################################################################################

You want to provide liquidity on the pair upenumbra:transfer/channel-2/uusdc
You will need:
 -> 8673607upenumbra
 -> 18000000transfer/channel-2/uusdc
You will create the following positions:
 ID                                                                State      Fee                       Sell Price                  Reserves
 plpid1skd6z6kgp555arnexux930aumd3s7v29hh5250wv9f5agkc7kvlsdsujfh  opened  100bps                 1.111112penumbra  2transfer/channel-2/usdc
 plpid1hm9d0g48rvys2tkh5vr79afqdp4kucjsv8l7rqns4dvca40fgy8qzevwt2  opened  100bps                 1.083335penumbra  2transfer/channel-2/usdc
 plpid17xser7a72e9gfnjm0d60psmmhu03yn0akj66jsanrp3wwehxjnwql979lg  opened  100bps                 1.056912penumbra  2transfer/channel-2/usdc
 plpid1shkwu3yz2ff7sfk7xzpnznhg76awk3zxrpsq2k6ljwcw88t2s5nqmvffcz  opened  100bps                 1.031747penumbra  2transfer/channel-2/usdc
 plpid177v0uv7nndg5r09ql7s8zslypa0hwl4vzqwvfj52vjen66azjeys6s0u0l  opened  100bps                 1.007753penumbra  2transfer/channel-2/usdc
 plpid1zwv2jktlz6je2n8jvq90j26lwr4chfeh0vqfeppnznjcqqg66mdq52jg38  opened  100bps                  984.85mpenumbra  2transfer/channel-2/usdc
 plpid1c6lr7lgx9m9jgp50x6n7nkrxt7ejv5x6uunz6s55qqhq40aheguqm2fuc3  opened  100bps                 962.964mpenumbra  2transfer/channel-2/usdc
 plpid19k59fxdq6hwsjja76g55tq427lvjspv3h2kvky8w0nmkk8he0xes3l32j8  opened  100bps                  942.03mpenumbra  2transfer/channel-2/usdc
 plpid154qy9f5re57ydl993wsfarcz4prqhz9jl5xnnz2yg9rgeypw8afsqvv60n  opened  100bps                 921.987mpenumbra  2transfer/channel-2/usdc
 plpid170pjl97vcdydena93ctxqx57r0zxjphg67ceszyxc52qttczqecsenj8f4  opened  100bps  1.107693transfer/channel-2/usdc          1.805555penumbra
 plpid1z8cfrcj9vhv3nthfj0mttv4u65slsfz7cjfgtja3k6qrhrnalgts3694rv  opened  100bps   1.13077transfer/channel-2/usdc          1.768707penumbra
 plpid1e2nv4yh7gqw5vgulu9j2m4pnzx3zk67n0wquf4zpl0gqx0pmnz6qj2mjch  opened  100bps  1.153847transfer/channel-2/usdc          1.733333penumbra
 plpid1utqynddhrzga06aq2cr6y79jxah0wlfteyjhy0mk2266dnhwy2kqcrv97e  opened  100bps  1.176924transfer/channel-2/usdc          1.699346penumbra
 plpid1jg82q883hdp8x8k0nlflc0lnc72ap8fc49gpe84xlwaw49uk5tpsewawp0  opened  100bps  1.200001transfer/channel-2/usdc          1.666666penumbra
Do you want to open those liquidity positions on-chain? [y/n]

Notice how the positions created by pcli have decreasing amounts of UM as the price of UM increases. This is so that each position has 2 USDC worth of UM at the position's price, not at the current market price. If the
market price moves upwards past the position's price, traders will buy the position's UM for USDC and deposit 2 USDC into the position. This ensures that the amount of liquidity provided is constant throughout the price range.

If the market price moves upwards past the upper bound of the range, all of the positions' UM will be traded away for USDC and the user will have the target amount of USDC they specified left over (ignoring fees here for simplicity).

To work out what the initial reserves should be for each position, the process is:

  • Compute quote_asset_per_position = liq_target / N
  • For each position:
    • If market_price > position_price:
      • The position always holds the less valuable asset, so its reserves will be in the quote asset
      • The amount is quote_asset_per_position of the quote asset (eg. 2 USDC)
    • If position_price > market_price:
      • The position always holds the less valuable asset, so its reserves will be in the base asset
      • The amount of the base asset is the equivalent amount of quote_asset_per_position of the base asset at the position's price
@github-project-automation github-project-automation bot moved this to 🗄️ Backlog in Penumbra web Dec 4, 2024
@grod220 grod220 added this to Labs web Dec 4, 2024
@grod220 grod220 moved this to 📝 Todo in Labs web Dec 4, 2024
@JasonMHasperhoven JasonMHasperhoven moved this from 📝 Todo to 🏗 In progress in Labs web Dec 5, 2024
@JasonMHasperhoven JasonMHasperhoven self-assigned this Dec 5, 2024
@JasonMHasperhoven
Copy link
Contributor

JasonMHasperhoven commented Dec 6, 2024

Comment: Price range prefill buttons for upper bound don't work -> This doesn't work when the pindexer doesn't return a market price

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🗄️ Backlog
Development

No branches or pull requests

2 participants