Liquidity Math
Definition of liquidity
Liquidity positions on Haiko are defined by an amount of liquidity, L
, and a price range, defined by lower and upper bounds and .
Here, liquidity is an abstract measure. Depending on whether the position is active (i.e. its relative position to current market price), its liquidity can be denominated either in base
assets, quote
assets, or a mix of the two. In particular:
If the position is bounded around the current price , liquidity will be denominated in a mix of
base
andquote
assets.Base =
Quote =
If the position is below the current price, liquidity will be single-sided and denominated in
quote
assets only.Quote =
If the position is above the current price, liquidity will be single-sided and denominated in
base
assets only.Base =
The total amount of liquidity, L
, placed within a position is fixed irrespective of the specific point-in-time mix of base and quote assets. Positions must maintain the following constant function invariant:
where and are the quantities of base and quote assets.
More information can be found, along with underlying derivations for the above equations, in the Uniswap V3 whitepaper.
Liquidity aggregation
Liquidity positions are aggregated horizontally by summing up the total amount of liquidity at a given price.
In practice, this is done by tracking a set of initialised limits (i.e. price points at which liquidity positions start and end), and updating the aggregate active liquidity balance of the market whenever price moves in and out of these positions.
Each limit tracks two values:
liquidity
(u128
), which denotes the total absolute amount of liquidity starting or ending at that limitliquidity_delta
(i128
), which denotes the total amount of liquidity starting at that limit (if+ve
or ending at the limit (if-ve
), reading from ascending order of price.
Together, they allow markets to track the instantaneous amount of active liquidity between limit intervals.
Last updated