The Math Behind the PMM

PMM Price Curve Definition

The price curve described by the PMM is mathematically defined as follows:
, then
, then
  • ii
    is the initial "guide price"
  • kk
    is the "slippage factor"
  • BB
    denotes the current base token supply
  • B0{B_0}
    denotes the equilibrium base token supply
  • QQ
    denotes the current quote token supply
  • Q0{Q_0}
    denotes the equilibrium quote token supply

Price Curve Integral

The most important thing for a trader is the average transaction price. The average transaction price is the integral of the marginal price
. Let's examine the case where there is a shortage of base tokens.
This equation describes the case where the user has
base tokens and wishes to purchase enough to have
tokens. To do this, the user needs to calculate the average price they will pay per token purchased.
ΔQ=B1B2PdB\Delta Q =\int^{B_2}_{B_1}PdB
=B1B2(1k)i+(B0/B)2kidB= \int^{B_2}_{B_1}(1-k)i+(B_0/B)^2kidB
=i(B2B1)(1k+kB02B1B2)= i(B_2-B_1)*(1-k+k\frac{B_0^2}{B_1B_2})
The above equation can be rearranged to obtain the average token price as follows:
P=ΔQB2B1=i(1k+kB02B1B2)P=\frac{\Delta Q}{B_2-B_1}=i*(1-k+k\frac{B_0^2}{B_1B_2})

Solving the Quadratic Equation for Trading

Let's derive how to calculate the price when there is a shortage of base tokens and only the number of quote tokens you want to buy or sell with (i.e.
) is given.
ΔQ=i(B2B1)(1k+kB02B1B2)\Delta Q = i(B_2-B_1)*(1-k+k\frac{B_0^2}{B_1B_2})
Now that
ΔQ,B0,B1ΔQ, B_0​, B_1
are given, we need to calculate
, which is found by solving a quadratic equation. Transforming the equation into standard form:
(1k)B22+(kB02B1B1+kB1ΔQi)B2kB02(1-k)B_2^2+(\frac{kB_0^2}{B_1}-B_1+kB_1-\frac{\Delta Q}{i})B_2-kB_0^2
let a=1k, b=kB02B1B1+kB1ΔQi, c=kB02let \ a=1-k, \ b=\frac{kB_0^2}{B_1}-B_1+kB_1-\frac{\Delta Q}{i}, \ c=-kB_0^2
, we discard the negative root, yielding
DODO V2 focuses on verifying the special case of k=0 and k=1, to support a constant selling price and the bonding curve of the standard AMM.


represent the current token supply, i.e. the dependent variables. In order to determine this price curve, we also need to know the four parameters
, and
However, these four parameters are not independent of each other, and given any three of them, the fourth one can be calculated.
The process of calculating the fourth parameter is called "regression" and is done whenever the parameters change. DODO's PMM operates under a "long regression" rule, which is a rule that aims to return the overvalued asset to its equilibrium value.
When the token supply changes, one of the two assets of the trading pair must be more than the equilibrium value and the other less than the equilibrium value. This corresponds to the pool holding a long position in one asset and a short position in the other asset.
The "long regression" rule then acts to return the long-side asset to its equilibrium value. Once the long-side asset returns, the asset value is deemed to be the new equilibrium value, regardless of the short-side asset's new value. That is, the short side takes a profit or loss.

Calculating the Regression Target

Suppose the current state is
B<B0,Q>Q0B<B_0, Q>Q_0
. Here,
is a long-side asset and
is a short-side asset. We know the parameters
and need to solve for the last parameter
- the regression target. To calculate the regression target at a certain oracle price, we make the following derivation:
QQ0=ΔQ=i(B2B1)(1k+kB02B1B2)Q-Q_0=\Delta Q = i(B_2-B_1)*(1-k+k\frac{B_0^2}{B_1B_2})
By definition, when the supply returns to equilibrium, the new inventory will be
, which will be identical to the original equilibrium supply i.e.
. Therefore, it is possible to organize the formula into the standard form of the quadratic equation.
kB1B02+(12k)B0[(1k)B1+ΔQi]=0\frac{k}{B_1}B_0^2+(1-2k)B_0-[(1-k)B_1+\frac{\Delta Q}{i}] =0
Eliminating the negative roots yields the regression target
B0=B1+B12k(1+4kΔQiB11)B_0=B_1+\frac{B_1}{2k}*(\sqrt{1+\frac{4k\Delta Q}{iB_1}}-1)
Similarly, if
becomes the long-side asset, then we can to solve for
instead, yielding:
Q0=Q1+Q12k(1+4kiΔBQ11)Q_0=Q_1+\frac{Q_1}{2k}*(\sqrt{1+\frac{4ki\Delta B}{Q_1}}-1)

Accrued Gains and Losses

When the system parameters are constant, the price curve is also constant. Even if the supply changes, the supply will return to equilibrium eventually. In other words, the gain or loss due to supply changes is just a "floating" gain or loss, and the term "impermanent loss" has been coined to describe this phenomenon.
The same is true for the PMM algorithm, which is similar to an AMM algorithm if the parameters remain unchanged. However, in practice, one often needs to make adjustments to the price curve. If the "long regression" rule is executed, the equilibrium value on the short side gets reset. The reset equilibrium value may be larger, which is equivalent to a profit. It may also become smaller, which is equivalent to a loss. Each regression converts an unrealized floating profit or loss into a real profit or loss.
Each time you change a parameter, it should ideally eliminate extra positions in time to avoid excessive losses. As for when and how to adjust the curve, it is subjective, and we hope that developers and traders can make the most of this framework to suit their own market-making strategy.