Notes:
- Lower-case x and y denote virtual or v1 reserves, upper-case X and Y denote v3 real reserves.
- The v3 formulae have been adapted from those in the whitepaper to be in terms of price, not square-root-price.
Used to compute the amount of asset0
(X) and asset1
(Y) to add (remove) when opening (closing) a position.
NOTE: Github is not correctly rendering this.
∆X =
∆Y =
Mathematically, there exist two types of swap:
- Volume-based
- Price-based
In a volume-based swap the user specifies a volume of asset0
or asset1
they want to put in (take out) of the pool, then the pool calculates the new price and the amount of the other asset they'll need to take out (put in). In a price-based swap, the user specifies a destination price they want the current price to move to, then the pool calculates the amounts of asset0
and asset1
they need to put in/take out of the pool.
In practice nearly all swaps are volume-based, or a combination of the two.
(i) Next price given liquidity, current price, and ∆X:
(ii) Next price given liquidity, current price, and ∆Y:
(iii) Asset0 delta given liquidity, current, and next prices:
(iv) Asset1 delta given liquidity, current, and next prices:
Note: formulae (i) and (iii) are re-arrangements of each other as are (ii) and (iv)