Pricing Mathematics
Each currency pair has its own liquidity pool. The pool is initially created by the project, which is also the first liquidity provider of the currency. The exchange rate is calculated using the constant product formula and is based on the supply and demand of the two currencies in the pool: (1)
, where
Va is the volume of cryptocurrency a in the liquidity pool;
Vb is the volume of cryptocurrency b in the liquidity pool;
k is invariant; the only condition for changing k is the replenishment of the pool.
Based on formula (1), let’s find out how the transaction price is calculated. First, let's define the following concepts:
- A pool is a wallet in the Nimera blockchain that contains the balances of a currency pair.
- An incoming currency is the currency that the trader wants to exchange in the pool.
- An outgoing currency is the currency that the trader will receive in return from the pool.
In an exchange operation, a trader adds one type of currency to the pool balance and withdraws another type of currency from the pool balance. The exchange is calculated in such a way that after the exchange operation, k does not change. With this calculation, large transactions have exponentially worse price rates.
Let's introduce the following notation:
Va0 is the volume of currency a in the liquidity pool at the initial moment of time;
Vb0 is the volume of currency b in the liquidity pool at the initial moment of time;
k is the product of volumes Va0 and Vb0;
Vaspent is the volume of cryptocurrency a, which the trader wants to exchange in the pool (a.k.a. incoming currency);
Vbgained is the volume of cryptocurrency b that the trader will receive from the pool in return (a.k.a. outgoing currency);
Let's calculate how the volume of currency a in the pool will change after the exchange operation: (2)
Let's calculate how the volume of currency b in the pool will change after the exchange operation: (3)
Based on formula (3), we calculate the volume of cryptocurrency b that the trader will receive from the pool when exchanging Vaspent : (4)
Thus, you can determine the price for the trader, if cryptocurrency a will be exchanged for cryptocurrency b: (5)
If we combine formulas (2), (3), (4), then the formula for determining the price can be expressed as follows: (6)
This calculation was made subject to zero commission.
Learn more about exchange mechanics in this article: Exchange Mechanics