H

H

HydraSwap Gitbook

Searchâ€¦

Introduction

Getting Started

Technology

Tokenomics $HYS

Hydra Market Maker (HMM)

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.

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.

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 Pricing Formula

When a trader buys token x vs y, token balance goes from

$x_0$

to $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 less than the DEX price:

- â€‹$i \le P_0$â€‹,

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

- â€‹$i > P_0$â€‹

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

$x_i$

â€‹â€‹

$x_i \le x_{-} \le x_0$

â€‹,if the base token balance after trade is lower than

$x_i$

â€‹â€‹

$x_{-} \le x_i$

,$x_0$

$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:

- â€‹$i \ge P_0$,

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

- â€‹$i<P_0$,if the base token balance after trade is less than or equal to$x_i$â€‹

â€‹

$x_0 \le x_{+} \le x_i$

,if the base token balance after trade is greater than

â€‹

$x_{+} \ge x_i$

,â€‹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!

Could not load image

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 < P_0$

, while true market price is larger than $P_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:

â€‹

$k^{'} \ge k$

â€‹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.

Same as CPMM, the available liquidity for both tokens within each interval can be easily calculated withand** **

. This can be compared to remaining input token balance (positive or negative) to see if we need to cross the next tick. Within each price interval [

$P_0$

(starting tick price), $P_1$

(ending tick price)], the output token amount (positive or negative) can be calculated with HMM as below:if **â€‹**

$P_1$

is NOT between $P_0$

and $P_i$

(oracle price): if

$P_1$

is between $P_0$

â€‹ and $P_i$

(oracle price):â€‹- If input token is X,

- If input token is Y,

Could not load image

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

$P_0â€‹=Y_0/X_0â€‹$

and $X_tâ€‹Y_tâ€‹=k=L^2$

â€‹â€‹**â€‹**

$X_t$

â€‹ and $Y_t$

â€‹ denote the LP token balances and L is a constant denoting liquidity supplied by the LP. Value of LP assets in the pool ( $W_t$

â€‹ ) are given byThe value of LP assets follow a square root price process.Assuming geometric brownian motion for price** **

$P$

,we have:â€‹$dP = \mu Pdt + \sigma Pdz$

â€‹â€‹Square root price process is given by:**â€‹â€‹**

This means LPs experience a volatility drag** **=

â€‹

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:

Could not load image

Could not load image

Where

$W_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 modified 2mo ago

Copy link

On this page

1. Motivation

2. HMM Model v1.0: Compensation Parameter

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

4. Volatility Adjusted Fee