The mathematical principle of PMM

### PMM Definition

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

The most important thing for a trader is the average transaction price. The average transaction price is the integral of the marginal price
$P$
. 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

### 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
$\Delta Q =\int^{B_2}_{B_1}PdBΔQ$
$= \int^{B_2}_{B_1}(1-k)i+i(B_0/B)^2kdB$
$= 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=\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
$\Delta Q = i(B_2-B_1)*(1-k+k\frac{B_0^2}{B_1B_2})ΔQ$
$\Delta Q, B_0, B_1$
is known ， we can transform the above equation into a standard quadratic equation by solving.
$(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=\frac{kB_0^2}{B_1}-B_1+kB_1-\frac{\Delta Q}{i}, \ c=-kB_0^2$
Since
$B_2>=0$
, we round off the sign (there is a strict derivation here), yielding
$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=0$
and
$k=1$
, to support the constant price curve as well as the bonding curve of the standard AMM.
The constant reference
Here
$B$
and
$Q$
are the current inventory, i.e., the dependent variable. In order to determine this price curve, we also need to know these four parameters
$i$
$k$
${B_0}$
${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
$BQ_0$
. Here
$Q$
is a long side and
$B$
a short side. We do not move
$Q_0$
and use the value before the fixed parameter directly. That is, we know the parameters
$i,k,Q_0$
, and need to solve for the last parameter
$B_0$
.
$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
$B_2$
and we use directly as the new equilibrium value, i.e.
$B_0=B_2$
. Then it is possible to organize the formula into the standard form of the quadratic equation.
$\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
$B_0$
.
$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
$B$
, then we need to solve for
$Q_0$
:
$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.