You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
The text was updated successfully, but these errors were encountered:
The current state:
We need to properly calculate the pricing to fill in accurate values for:
Math behind the values
=== Quoted from @erwanor ===
gamma = (10_000 - fee)/10_000
The text was updated successfully, but these errors were encountered: