Hydra Market Maker (HMM)

1. Motivation

Constant product market makers (CPMM) have allowed savers to become passive market makers. They provide liquidity in DEXes while earning yield from transaction fees. This has been one of the key innovations in DeFi leading to where we are today. However it is just a start and it is far from the optimal setup. Uni v3 is a great improvement allowing LPs to figure out their own sweet spot when providing liquidity. There still remains a wide gap between passive liquidity provision and how sophisticated market makers function.

In the current setup the CPMMs offer a basic pricing mechanism and the sophisticated market makers do the heavy lifting off chain. Solana has the potential to change that and allow AMMs to become a lot more sophisticated as it alleviates the computational and gas bottlenecks we currently see on Ethereum. This would lead to reduction in overall time & cost overhead for sophisticated market makers as well as improve the P&L profile of purely passive LPs.

With HMM we aim to continue on the path of innovation and introduce further sophistication in the AMM process. In version1 we will introduce a smarter pricing mechanism for incentivising arbitrageurs while protecting the P&L of LPs and improving their impermanent loss profile.

In version 2 we will combine compensation parameter with uni v3 style concentrated liquidity using the mechanics described further down in this paper. We will also introduce a volatility adjusted fee for correctly compensating LPs based on the level of volatility in the market.

2. HMM Model v1.0: Compensation Parameter

A traditional market maker (MM) would adjust it’s bid and offer once given a position. This is called applying a price skew. A CPMM does the same by moving up and down the bonding curve based on the token balances after a trade. Traditional MMs use sophisticated machine learning tools taking into account various signals for adjusting pricing. CPMM however relies purely on its own token inventory and is completely agnostic to what’s happening in the broader market. Sometimes this price adjustment can be too aggressive. This leads to pnl leakage as well as adverse selection of trades.

With HMM v1, we introduce a tweak to the CPMM model and introduce a reference oracle price to make a more informed price adjustment mechanism.

Introducing c, the “Compensation Parameter?

When a trade is entered vs a CPMM, token balances change and the price moves along the bonding curve. The LPs experience impermanent loss which is equal to the area of the shaded region in red (ignoring fees).

The price adjustment incentivizes arbitrageurs to step in to replenish the token balance and reduce the impermanent loss.

In HMM, we introduce a compensation parameter ‘c’ which controls how much LPs are willing to compensate arbitrageurs. By controlling this, we can improve the pnl profile of LPs and show that the expected impermanent loss is lower than that of the naive CPMM model.

‘c’ can range from 0 to 2. At c=0, the HMM price is always the same as the CPMM price and creates a large incentive for arbitrageurs. At c=’2’, the HMM price creates no incentive for arbitrageurs. ‘c’ only comes into play when the HMM price is BETTER than the oracle price. In between, HMM still creates an incentive for arbitrageurs but it does so while keeping an eye on the oracle price. If the marginal price using CPMM is too aggressive compared to the oracle price then HMM tries to adjust it closer to the oracle price which provides better performance for LPs.

HMM Parameters

HMM Pricing Formula

When a trader buys token x vs y, token balance goes from x0x_0 to xx_{-}

We calculate the change in quantity for token y using the below equations. If the oracle price at the time of trading is equal to or less than the DEX price:

  • iP0i \le P_0​,

If the oracle price at the time of trading is greater than the DEX price:

  • i>P0i > P_0

if the base token balance after trade is greater than or equal to xix_i

xixx0x_i \le x_{-} \le x_0​,

if the base token balance after trade is lower than xix_i

xxix_{-} \le x_i,

When a trader sells token x vs y, token balance goes from x0x_0to x+x_{+}

We calculate the change in quantity for token y using the below equations.

If the oracle price at the time of trading is equal to or greater than the DEX price:

  • iP0i \ge P_0,

If the oracle price at the time of trading is less than the DEX price:

  • i<P0i<P_0,

    if the base token balance after trade is less than or equal to xix_i

x0x+xix_0 \le x_{+} \le x_i,

if the base token balance after trade is greater than

x+xix_{+} \ge x_i,​

Lower expected Impermanent Loss with HMM vs AMM

Arbitrageurs step in and trade against the AMM until an equilibrium is reached vs outside sources of liquidity. Let R= the price ratio between when liquidity was supplied and now.

Ignoring fees, the impermanent loss in CPMM can be shown to be equal to:

2∗Sqrt(R)/(1+R)−1

With HMM, we can show the impermanent loss to be equal to:

[(R^(C/2)-Sqrt(R))/(C-1) + Sqrt(R)+1]/(1+R)-1

This impermanent loss in HMM is strictly lower than CPMM!

Immunity to Wrong Oracle Price

We can show that HMM has inbuilt immunity to incorrect/manipulated oracle price. An attacker trying to manipulate the oracle price will not be able to make the HMM price better than AMM.

To illustrate this, if the oracle price is wrong (e.g. i<P0i < P_0, while true market price is larger than P0P_0), HMM will perform the same as a CPMM i.e. attackers will not be able gain an advantage. As long as the oracle price gives the right indication of whether the market price is greater than or less than current DEX price, LPs will be better off, the degree to which is dependent on accuracy of the oracle price.​

Mathematically, It can be easily shown that:

so

so

so after each trade in HMM neglecting fees:

kkk^{'} \ge k

3. HMM Model v2.0: Concentrated Liquidity++

Uni V3 with concentrated liquidity introduces a flexible and efficient way that can significantly improve capital efficiency and help LPs customize with range orders. While Uni V3 concentrated liquidity gives LPs granular control over what price ranges their capital is allocated to, it introduces potentially bigger impermanent loss should there be any large one-way price action.

This is where HMM, given its significant outperformance over CPMM in protecting P&L for LPs, can be perfectly combined with Uni V3. In detail look, the HMM combination with Uni V3 can be easily adopted only with changes made to the swapping process within each active tick interval.

if P1P_1 is NOT between P0P_0 and PiP_i (oracle price):

if P1P_1 is between P0P_0​ and PiP_i(oracle price):​

  • If input token is X,

  • If input token is Y,

4. Volatility Adjusted Fee

LPs providing liquidity in an AMM pool experience a volatility drag on their position i.e. they have volatility exposure. When markets are moving a lot, LP profits are eroded away by higher impermanent loss. Sophisticated LPs that dynamically rebalance their token inventories bleed more money doing these rebalancings in volatile markets. Conversely, AMMs accumulate profits in calm markets when there is trading activity around a stable price. Constant fee fails to reflect these market dynamics. This means LPs will be more inclined to take away liquidity from AMMs in volatile markets thus exacerbating market moves. In stable times, traders will be less inclined to pay the high fees on DEXes. This is the exact opposite of the desired dynamic!

Volatility sensitive pricing is needed for incentivising LPs to keep funds during volatile times and traders to continue using DEXes in stable times. LPs should earn higher fees in turbulent times and lower fees in calmer markets. This would lead to a fairer and a more robust trading ecosystem.

We present the heuristic for pricing AMM fee below.

Assuming an LP provides liquidity in a 2-asset constant product market making pool composed of tokens X and Y.

Treating Y as numeraire, we have marginal price P0=Y0/X0P_0​=Y_0/X_0​ and XtYt=k=L2X_t​Y_t​=k=L^2

The value of LP assets follow a square root price process.Assuming geometric brownian motion for price PP ,we have:​

dP=μPdt+σPdzdP = \mu Pdt + \sigma Pdz

​​Square root price process is given by:​​

The above can also be modelled by explicitly calculating the delta-hedging p&l of an LP that constantly hedges its delta to stay hedged in numeraire. This negative gamma pnl experienced by LPs between 2 periods is given by:

Where W0W_0 is the initial value of the LP deposit and denotes the annualized volatility of log returns.

Considering a single day time frame, the expected value of LP loss equates to

We want the expected fee earned from AMM to exceed that of the LP loss.

So:

Here ADV represents the average daily volume, TVL is the total value locked in the pool and α\alpha is the fee rate.

We define velocity as a measure of ADV / TVL. i.e. what multiple of the TVL does the AMM trade daily on average. This gives us the below heuristic for setting min AMM fee.

Last updated