---
tags: dAMM
---
# Discrete Automated Market Makers
Uniswap-type automated market making was created with the aim of giving retail investors a simple and gas-minimizing way of providing liquidity and earning transaction fees. The innovation was successful beyond expectations with billions of dollars of liquidity provided this way on public blockchains.
With the recent development of layers 2 and low fee blockchains, central limit order books (CLOB) progressively make a come-back and stand as a serious alternative to automated market making (see e.g. [Designing an Exchange](https://twitter.com/FabiusMercurius/status/1452349285865984000)).
Market makers (MM) benefit from the bid-ask spread but have to manage inventory risk. Liquidity providers (LP) in Uniswap-type AMM forego the spread but earn transaction fees to compensate for impermanent loss.
Another difference between the two designs is that retail investors constitute the large majority of liquidity providers in AMMs whereas providing liquidity in CLOB is generally handled by sophisiticated traders and professional market makers.
This note investigates whether the simplicity and automaticity of providing liquidity in AMM could be crosssed with CLOB's market making logics with the aim of making it accessible to the mass of investors. This leads to a new class of AMM called discrete AMM (dAMM) as opposed to existing Uniswap-type AMM, rebranded continuous AMM (cAMM).
## General design
A market is composed of two assets X and Y. $x$ and $y$ are inventories held by the MM or total assets in a cAMM/dAMM pool.
Investors pool their assets in a staking pool like Aave, and grant allowance to a smart contract, which algorthmically posts bids of size $\delta x^+$ and asks of size $\delta x^-$ over a predefined price grid $P = \{p_0, p_1, ..., p_N\}$ (with $p_0 < p_1 < ... < p_N$).
On top of the return from the staking pool, Investors earn revenue from the MM strategy which basically consists in buying low and selling high.
For example, when the price goes from $p$ to $p'>p$, then to $p$ again, they earn:
$$
p' \delta x^- - p \delta x^- = (p'-p) \delta x^- > 0
$$
if the bid and the ask have the same size: $\delta x^+ = \delta x^-$.
## Persistence of quotes
As in cAMMs, the assets received from trades are immediately available for new trades in opposite direction.
The smart contract quotes a bid at price $p^i$ inferior to current price and, an ask at price $p^{i+1}$ higher than current price except where the last order has been filled. Then:
- Everytime a bid is filled at price $p^i$, an ask is posted at price $p^{i+1}$.
- Everytime an ask is filled at price $p^i$, a bid is posted at price $p^{i-1}$.
In this example a filled bid (of size 10) is atomically replaced by an ask of equivalent size:

## Liquidity concentration
Capital can be concentrated over a price range $[p_{max} - p_{min}]$, as in Uniswap V3, but the strategy is not constrained by a bonding curve and could take various forms.
For every price on the price grid, bids and asks' size can be computed so that the share of X in the pool is an increasing function $\phi$: $[0,1] \rightarrow [0,1$ ] of how far $p$ is from its upper bound $p_{max}$:
$$
\dfrac{px}{px + y} = \phi \Big( \dfrac{p_{max}-p}{p_{max} - p_{min}} \Big)
$$
with $\phi'(.) \geq 0$, $\phi(0) = 0$ and $\phi(1) = 1$.
The further the price from its upper limit, the higher the potential upside and the higher the share of X in the MM's portfolio.
When the price hits its hypothetical upper limit $p_{max}$, the share is 0\% (100% in Y). When it reaches its lower bound, the share is 100%.
The function $\phi$ can take a linear form:
$$
\dfrac{px}{px + y} = \dfrac{p_{max} - p}{p_{max} - p_{min}}
$$

The function could also be S-shaped:

leading to liquidity concentrated in the middle of the price range:

## Path independence
A strategy is path independent if investors do not lose whenever the price returns to its initial level.
In market making, path independence is a desirable property. If MM's portfolio never loses value after a price going up and down, it means that the MM is assured to sell at a higher price on average than he bought.
A MM strategy is **path independent** if endowments in X and Y are preserved at the end of a **price loop** (a price action during which the price eventually returns to its initial state): $x_T \geq x_0$ and $y_T \geq y_0$.
Strategies in Uniswap V2 or V3 pools are [path independent](https://vitalik.ca/general/2017/06/22/marketmakers.html). If the price transits to $p'$ and returns to $p$, the pool ends up with intial endowments $x$ and $y$ (plus fees) as both are contrained by the $xy=k$ curve. This is why potential losses are called impermanent.
To see what does path independence mean for dAMMS, let's suppose a price loop. Several bids and asks can be filled during this episode:

In any price loop, all filled bids and asks can be paired:

**Order pairs** are couple of bids and asks for adjacent prices. Bid's and ask's sizes for prices $p^{j-1}$ and $p^j$ are denoted $x(j)^+$ and $x(j)^-$ respectively.
The strategy is **path independent** if bid and ask sizes are equal for all order pairs:
$$
x(j)^+ = x(j)^- \qquad \forall j=1,...,J
$$
The MM sells the same quantity when the price is going up than he buys when the price is going down.
Path independent strategies are always **profitable** after a price loop (as every pair is profitable).
What could go wrong if the strategy is not path independent? Consider a minimal departure from a path independent strategy:

The MM buys one more unit than he sells in a pair order. Whether he makes a profit with the additional X unit depends on a bet on future price evolution.
Moreover, path dependency means that MM's endowment in X or Y can grow larger and larger after every price loop, as illustrated in the example:

Here the price is circulating between three price levels. Because the MM sells 7 units and buys 8 units *every loop*, he accumulates an arbitrary amount of X.
## Backtesting
The strategy is backtested with a series of prices from Uniswap V3 on the ETH/USDC pair between 5th May 2021 and 1st February 2022 (nearly 200,000 trades and price variations).
I first assume that the function $\phi$ takes a linear form:
$$
\dfrac{px}{px + y} = \dfrac{p_{max} - p}{p_{max} - p_{min}}
$$
ETH price range is [1,000; 10,000].
Steps between execution prices are multiplicative:
$$
p^j = (1+\tau) p^{j-1}
$$
Initial capital is 100,000 dollars.
For $\tau = 10\%$, the MM strategy (in red) outperforms the holding strategy (in blue):

Relative to holding the two assets, the MM strategy produces a 20% return over ten months:

A non-linear transformation function $\phi$:
$$
\phi(s) = \dfrac{1}{ 1 + \Big( \dfrac{1-s}{s} \Big)^{\gamma}}
$$
with $\gamma =$ 2 leads to the previously shown S-shaped transformation.

Return relative to holding is around 15%:

For a narrower, more centered price range $[1,500; 5,000]$, the transformation does better (around 60%) than a broader price range:

but also compared to a linear transformation (around 50%):

The reason is that the ETH price moves around the mid-point of the price range $[1,500; 5,000]$, but on the left of the price range $[1,000; 10,000]$. In the first case, $\gamma = 2$ allows to efficiently concentrate liquidity around the mid-point.
Return tends to decrease with multiplicative step $\tau$ getting smaller. For $\tau = 0.5\%$ (and $\gamma = 2$), return is around 40% (instead of 60% for $\tau = 10\%$):

This is without taking into account gas which increases when $\tau$ is gettig smaller due to more micro-transactions.
<!-- ## Comparison between dAMMs and cAMMS
### Fees vs spread
Contrary to MM in CLOB, LP in cAMM also "buy low and sell high", yet do not earn the spread .

Here despite the price variation, LP earn an average exchange rate (tle slope of purple line) which is the same when they sell to $p'$ and buy again to $p$.