owned this note
owned this note
Published
Linked with GitHub
# A Liquidity Density Profile for StableSwap-like Hooks
Specifies a liquidity density profile on a concentrated liquidity AMM that closely resembles the slippage of the StableSwap invariant across the full tick range, enabling passive, efficient like-like liquidity provision on CLMMs.
The liquidity profile function that appears to work well and is simple to implement follows a Cauchy distribution, supplemented by a constant base layer of full range liquidity
$$
l_{\gamma, \rho}(\tau) = \frac{L}{\pi \gamma} \bigg[ \frac{1}{1 + (\tau/\gamma)^2} + \frac{1}{1 + (\rho/\gamma)^2} \bigg]
$$
Parameter constants $\gamma, \rho$ describe
- $\gamma$ -- Half width of liquidity profile around tick zero, acting like 1 / leverage for the AMM
- $\rho$ -- How quickly the AMM transitions from constant sum like behavior to constant product
$L$ increases/decreases as LPs add/remove liquidity to the profile, but is constant for swaps (ignoring possible compounding of fees). Liquidity is fungible with shares issued proportional to $L$, and weightings between constant base and Cauchy determined by the location in the tick range and profile params. Should be easy to calculate given Cauchy as a probability density normalizes to 1
$$
\frac{1}{L}\int_{-\infty}^{\infty} l_{cauchy}(\tau) d\tau = 1
$$
Plots of price slippage given a fraction of x reserves sold into the pool, $\Delta x / x$,

*Slippage for Modified Cauchy liquidity profile for various $\rho$ compared with Uniswap v2, StableSwap*
produce StableSwap-like behavior across the full price range for appropriate parameter choice. For example, Curve $A = 250$ (dotted purple) seems to be most similar in swap dynamics to $l_{\gamma, \rho}$ with $\gamma= 0.0125, \rho=0.4$ (green).
Reasoning about appropriate parameter choice seems relatively straight-forward with the liquidity density function approach given the liquidity profile resembles that of log-price behavior in most simple financial models (albeit with a heavier tailed distribution). Would expect ideal $\gamma$ values to relate directly to the half width of the log-price behavior.
Meaning, if the log-price process is anticipated to walk around tick 0 with volatility of 50 bps, an appropriate choice of $\gamma$ might be e.g. 150 bps so that the leveraged constant sum regime covers the majority of paths due to the anticipated spread in the log-price process. Constant product via the additional constant liquidity term then kicks in outside the peak to cover tail scenarios, with $\rho$ dictating the speed of the transition.
## Intro
Curve's StableSwap invariant extended Uniswap for low slippage swaps between like-like pairs. Stableswap LPs effectively leverage liquidity to offer constant sum (i.e. zero slippage) like behavior around an optimal price of 1, with divergence away from 1 resulting in the AMM curve transitioning to higher slippage constant product like swaps. Curve and Uniswap v2 allowed LPs to be passive, with the AMM curve (and protocol parameter selection) outside of the control of LPs, and the responsibility of LP profitability put on the protocol.
Since then, the AMM space has been dominated by concentrated liquidity after the introduction of Uniswap v3, allowing liquidity providers to choose the profile they wish to provide liquidity in. The upside being LPs have more flexibility in their liquidity provision strategies, but the downside is these strategies require a more active approach (and are still not necessarily profitable), result in greater complexity, and sacrifice the fungibility of the LP token position.
Vault protocols like Bunni v1, Arrakis, and Gamma Strategies aimed to fill this gap for more passive LPs via managed liquidity strategies. However, given the architecture of Uniswap v3, vaults are an external layer outside of the main logic of the AMM, unable to respond to changes in AMM state via e.g. user-initiated swaps at the moment of the swap. Vault strategies then lag behind the state of the AMM and the vault manager pays the rebalancing costs in both time and transaction fees.
Ekubo v1 and now Uniswap v4 recently introduced the concept of extensions/hooks, that allow developers to insert logic at various points in the lifecycle of the user interaction with the underlying concentrated liquidity AMM. Hooks enable passive liquidity products that do not require active external management, likely enabling both active and passive LPs in the same AMM pool.
## A Profile for Like-Like Pairs
Bunni v2 proposed the concept of liquidity density profiles to address the passive use case. Bunni v2 LPs deposit fungible liquidity into their Uniswap v4 hook, which specifies a liquidity density function to provision liquidity with across the full tick range of the CLMM pool. The hook adds/removes liquidity to the CLMM pool according to the shape of the profile function at each tick $\tau$ in the full tick range.
The liquidity density profile effectively defines the AMM curve in liquidity, price space (instead of reserves space), and the associated slippage swappers receive at different price points. Liquidity density profiles offer the possibility of many different AMM curves at the hook layer, without having to rewrite the underlying pool logic.
To transform an AMM specified in reserves space to liquidity space, one could use price as the first derivative of y with respect to x reserves and invert
$$
x(p) = {\frac{dy}{dx}}^{-1}(-p)
$$
alongside the Uniswap v3 definition of the liquidity function as
$$
l(p) = - p \frac{dx}{d\sqrt{p}}
$$
But $(dy/dx)^{-1}$ is not necessarily invertible nor simple.
To arrive at a Curve-like profile, instead I take a similar approach to the original StableSwap paper. Realizing that in liquidity space, constant sum around price 1 is a Dirac delta function at tick zero scaled by the liquidity amount and constant product is simply a constant. Linear combination of the two would yield a good starting point
$$
\chi \cdot \delta(\tau) + c
$$
where the symmetry about tick zero is desired for the like-like pairs.
As with StableSwap, I want the weighting $\chi$ on the constant sum behavior to reduce to zero as one moves away from the optimal price of 1, which requires spreading the liquidity distribution out away from a Dirac delta.
There are a few well known density functions that reduce to a Dirac delta as one takes the width of the density to zero, but easiest to work with and code on-chain would be the Cauchy density function
$$
\frac{1}{\pi \gamma} \frac{1}{1 + (\tau/\gamma)^2}
$$
where $\gamma \to 0$ limit is the infinite leverage Dirac delta constant sum. Cauchy has the added benefit of being a heavier-tailed density, resulting in a higher (and more concentrated) peak near tick 0, and less tail drop off as $\tau \to \pm \infty$ for the wanted transition to constant product.

*Cauchy liquidity profile for various $\gamma$ values*
Simulating price slippage across a CLMM with a liquidity profile of only Cauchy shows the near zero slippage constant sum behavior occurs for a large % of reserves into the pool (as with Curve) but the dropoff vs StableSwap whitepaper's figure 2 is far more severe outside of the set liquidity spread.

*Slippage on Cauchy liquidity profile*
As tick deviates $|\tau| > \gamma$ away from 0, the amount of capital in as a fraction of reserves needed to move price falls off a cliff, even more so than StableSwap behavior. The tail behavior desired of a transition to constant product is difficult to reproduce for higher leverage (smaller $\gamma$) liquidity profiles.
Modifying the Cauchy profile by adding a constant term as a base layer of full range liquidity does the trick
$$
l_{\gamma, \rho} (\tau) = {l_{cauchy}}_{\gamma} (\tau) + {l_{cauchy}}_{\gamma} (\rho)
$$

producing constant product like slippage (i.e. slippage curve flips from concave to convex) as price deviates out to the tails of the liquidity profile.
The constant parameter $\rho$ is best set to be some larger multiple of gamma $n \gamma$ so as not to diminish the concentrated liquidity constant sum behavior near tick zero.

*Slippage for Modified Cauchy liquidity profile for various $\rho$ compared with Uniswap v2, StableSwap*
Larger $\rho$ results in the transition to constant product taking longer and will be more drastic once it happens, but with greater amounts of capital dedicated to concentrating liquidity in the peak of the profile. Plotting slippage against Uniswap v2 and StableSwap as well produces a pretty good fit for the green curve above.