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

Add proper pricing to My Positions #198

Open
grod220 opened this issue Dec 10, 2024 · 0 comments
Open

Add proper pricing to My Positions #198

grod220 opened this issue Dec 10, 2024 · 0 comments
Labels

Comments

@grod220
Copy link
Contributor

grod220 commented Dec 10, 2024

The current state:
Screenshot 2024-12-10 at 4 04 21 PM

We need to properly calculate the pricing to fill in accurate values for:

  • Effective Price
  • Base Price
  • Current Value

Math behind the values

=== Quoted from @erwanor ===

  • buy/sell
    • the logic that decides whether an LP is buy/sell is sound, but there's one caveat: it's ultimately a user experience decision based on which asset is the "numeraire" (in another word, which asset is the unit of account for the trades)
      • a somewhat under-advertised in the dex is that trading pairs have a canonical (unambiguous) ordering based on asset ids (asset_id_1 < asset_id_2 ), and asset ids are random. this means that for a pair like UM/USDX, it's totally possible that asset_1 is USDX and asset_2 is UM. yet, you would want to render a position that provisions UM to acquire USDX as a Sell and vice-versa.
    • not sure how to best articulate that in the code, but you could keep this logic and have a layer with more context "flip the sign" when necessary, or just fuse it together there. it's possible for a position to be neither a sell/buy, though it should be relatively uncommon once the DEX has fully bootstrapped.
  • Fees
    • a Position is a trading function (defining prices + fee) and a tuple of reserves, the trading function is immutable but the reserves can change.
    • the fee is expressed in basis points:
      • 0bps -> 0u32
      • 10bps -> 10u32
      • 5% -> 500u32
      • 100% -> 10_000u32
    • its practical meaning is that every time inventory is routed through the position, it will confiscate some of the input to go into its own reserves. this means that there's a slight difference between a position "nominal price" (the price defined by its price coefficients) and it's "effective price" (the price people actually get inclusive of fees).
    • in the dex internals, there's another parameter called gamma, it is a fee percentage that is computed as follow: gamma = (10_000 - fee)/10_000
    • for example:
      • 0bps -> 1
      • 10bps -> 0.999
      • 5% -> 0.95
      • 100% -> 0
    • gamma is useful to compute the effective price, it lets you compute a discount/premium on the position quoted price to obtain the effective price. we will see how next:
  • nominal price vs. effective price
    • a Position is:
      • a trading function (immutable)
      • a tuple of reserves
    • a trading function defines a price and a custom fee tier, this is how:
      • it defines two coefficients p_1 and p_2
      • it defines a fee parameter f
    • the nominal exchange rate between asset 1 and asset 2 is given by: p_1/p_2 (how much asset_1 you get per asset_2)
    • the nominal exchange rate between asset 2 and asset 1 is given by: p_2/p_1 (vice-versa)
    • but clearly, this measure of price is insufficient because if two positions have the same coefficients but one quote a 100% fee and the other a 0% fee, they have in fact very different prices. how do we get a measure of price that includes this information?
    • this is what the effective price is for:
      • effective exchange rate between asset 1 and asset 2: (p_1/p_2)*gamma
      • asset 2 to asset 1: (p_2 * gamma)/p_1

Screenshot 2024-12-04 at 8 45 33 AM

  • Now to map onto the figma design:
    • base price is what i call the "nominal price" so p1/p2
    • fee (percentage): this is the fee parameter of the trading function, recall that it's expressed in bps so to turn it into a percentage you will have to do (fee/100), e.g, applying f/100 to our example values:
      • 0 bps -> 0%
      • 10 bps -> 0.01%
      • 500 bps -> 5%
      • 10000 bps -> 100%
    • fee (USDC): this is (f/100) * (p_1/p_2)
    • effective price: (p_1/p_2)*gamma like we explained above
@grod220 grod220 added the ui label Dec 10, 2024
@grod220 grod220 moved this to 📝 Todo in Labs web Dec 10, 2024
@grod220 grod220 added this to Labs web Dec 10, 2024
@github-project-automation github-project-automation bot moved this to 🗄️ Backlog in Penumbra web Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🗄️ Backlog
Development

No branches or pull requests

1 participant