DODO Docs
Search…
⌃K

The mathematical principle of PMM

PMM Definition

The price curve described by the PMM is defined as follows
​
P=iRP=iR
​
If
B<B0B<B_0
, then
R=1−k+(B0B)2kR=1-k+(\frac{B_0}{B})^2k
If
Q<Q0Q<Q_0
, then
R=1/(1−k+(Q0Q)2k)RR=1/(1-k+(\frac{Q_0}{Q})^2k)R
Other cases
R=1R=1

Trading

The most important thing for a trader is the average transaction price. The average transaction price is the integral of the marginal price
PP
. So the average price can be found by knowing the shift of the horizontal coordinate and the corresponding integral of the curve. The next example is the case of
B<B0B<B_0
:

Given the horizontal coordinates to find the integral area

This case corresponds to the case where the user is given a Base Token to sell and the average price is found
​
ΔQ=∫B1B2PdBΔQ\Delta Q =\int^{B_2}_{B_1}PdBΔQ
​
​
=∫B1B2(1−k)i+i(B0/B)2kdB= \int^{B_2}_{B_1}(1-k)i+i(B_0/B)^2kdB
​
​
=i(B2−B1)∗(1−k+kB02B1B2)= i(B_2-B_1)*(1-k+k\frac{B_0^2}{B_1B_2})
​
​
The above equation can be modified slightly to obtain the average transaction price as follows
​
P=ΔQB2−B1=i∗(1−k+kB02B1B2)PP=\frac{\Delta Q}{B_2-B_1}=i*(1-k+k\frac{B_0^2}{B_1B_2})P
​

Given the integral area, find the coordinates

This case corresponds to the case where the user is given a Quote Token to pay and the average price is found
​
ΔQ=i(B2−B1)∗(1−k+kB02B1B2)ΔQ\Delta Q = i(B_2-B_1)*(1-k+k\frac{B_0^2}{B_1B_2})ΔQ
​
​
ΔQ,B0,B1\Delta Q, B_0, B_1
is known , we can transform the above equation into a standard quadratic equation by solving.
​
(1−k)B22+(kB02B1−B1+kB1−ΔQi)B2−kB02(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=1−k, b=kB02B1−B1+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
​
Since
B2>=0B_2>=0
, we round off the sign (there is a strict derivation here), yielding
​
Q2=−b+b2−4ac2aQ2​Q_2=\frac{-b+\sqrt{b^2-4ac}}{2a}Q2​
​
Meanwhile DODO V2, on the above equation calculation, focuses on verifying the special cases of ,
k=0k=0
and
k=1k=1
, to support the constant price curve as well as the bonding curve of the standard AMM.
The constant reference
Here
BB
and
QQ
are the current inventory, i.e., the dependent variable. In order to determine this price curve, we also need to know these four parameters
ii
kk
B0{B_0}
Q0{Q_0}
.
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 "parametrization" and is done whenever the parameter changes. "DODO chooses the "long return rule", which is a rule that aims at eliminating all longs.
When the inventory is shifted, one of the two assets of the 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 reversion" priority is to return the long-side assets to their equilibrium values. Once the long-side asset returns, the asset value is deemed to be the new equilibrium value, regardless of the short-side asset. That is, the short side takes a profit or loss.

Example of a long-side regression fixed reference

Suppose the current state is
B<B0,Q>Q0B<B_0, Q>Q_0
. Here
QQ
is a long side and
BB
a short side. We do not move
Q0Q_0
and use the value before the fixed parameter directly. That is, we know the parameters
i,k,Q0i,k,Q_0
, and need to solve for the last parameter
B0B_0
.
​
Q−Q0=ΔQ=i(B2−B1)∗(1−k+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 inventory returns, the new inventory is
B2B_2
and we use directly as the new equilibrium value, i.e.
B0=B2B_0=B_2
. Then it is possible to organize the formula into the standard form of the quadratic equation.
​
kB1B02+(1−2k)B0−[(1−k)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 reset of
B0B_0
.
​
B0=B1+B12k∗(1+4kΔQiB1−1)B_0=B_1+\frac{B_1}{2k}*(\sqrt{1+\frac{4k\Delta Q}{iB_1}}-1)
​
Similarly, if the long positions are accumulated in
BB
, then we need to solve for
Q0Q_0
:
​
Q0=Q1+Q12k∗(1+4kiΔBQ1−1)Q_0=Q_1+\frac{Q_1}{2k}*(\sqrt{1+\frac{4ki\Delta B}{Q_1}}-1)
​

Accrued gains and losses due to fixed parameters

When the system parameters are constant, the price curve is also constant. Even if the inventory changes, it does not matter, just wait for the market environment and the system parameters to match again, the inventory can return to equilibrium. In other words, the gain/loss due to inventory changes is just a "floating gain/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 the AMM algorithm if the parameters remain unchanged and there is no fixed parameter process. However, in practice, one often needs to make adjustments to the price curve. Under the "long return to parametric" rule, the equilibrium value on the short side is reset. The reset equilibrium value may be larger, which is equivalent to a profit accrual. It may also become smaller, which is equivalent to a loss accrual. Each accrual is converting an unrealized floating profit/loss into a real profit/loss.
Each time you set a participation, it is a single accrual, the purpose of which is to eliminate additional positions in time to avoid excessive losses. As for when and how to adjust the curve, it is a matter of opinion, and we hope that developers and traders can make the most of this framework.
​