Capital Osmosis: A Deep Dive into Dual and Multi-Token Liquidity Pools | by Jessica Huhnke | Downside Governance | March 2023
Osmosis is an Automated Market Maker (AMM) protocol that allows users to create bespoke AMMs with sovereign pools of liquidity. This customizability allows for the creation of custom bonding curve AMMs, dynamic swap fee adjustments, and multi-token liquidity pools.
The biological process of osmosis, in which water molecules flow from a high-concentration area to a low-concentration area across a semi-permeable membrane, is a fitting eponym for this AMM. On Osmosis, lower liquidity pools can be stimulated, both internally and externally, to pull liquidity from deep liquidity pools into smaller pools.
Osmosis is a cornerstone of the larger Cosmos ecosystem as it is the AMM with the deepest liquidity and the largest number of IBC tokens available for trading. This piece explains how token price is determined in liquidity pools on Osmosis, diving into both two-token and multi-token liquidity pools.
Two token liquidity pools
The price of a token in a two-token liquidity pool follows the well-known constant product function:
Where x = the amount of token 1 in the liquidity pool, y = the amount of token 2 in the liquidity pool, and k = predefined constant greater than zero. Unless additional liquidity is added to the liquidity pool, k remains unchanged while swaps involving the token pair change the pool balance.
Multi-Token Liquidity Pools
While the two-token liquidity pool is the most common type of pool at Osmosis, the pools currently available feature up to eight different tokens. To determine the price of tokens in a multi-token liquidity pool, the constant product function given above can be expanded as follows:
Where x = a token in the liquidity pool, n = the total number of tokens in the liquidity pool, and k = predefined constant greater than zero. In other words, the token price is determined by multiplying the amount of all tokens in the liquidity pool together.
Two token liquidity pools
Simulated Evmos/OSMO liquidity pool
Suppose the current price of 1 Evmos is 0.45 OSMO and there is a liquidity pool containing 10,000 Evmos and 4,500 OSMO tokens. Using the constant product function (Equation 1) this gives a constant product k = 10,000 * 4,500 = 45,000,000.
Any trading is allowed in this liquidity pool as long as the resulting balance of x Evmos and y OSMO tokens remains constant at 45,000,000. This constant product function, which forces relative prices, is the only factor that determines the price of tokens in the liquidity pool. External factors such as US dollar or ATOM prices are not relevant.
Figure 1: The constant product curve of a simulated Evmos/OSMO liquidity pool initially containing 10,000 Evmos and 4,500 OSMO tokens.
In the chart above, the red dot denotes the current (relative) price of 10,000 Evmos to 4,500 OSMO tokens. However, using this liquidity pool to swap Evmos and Osmo will result in a change in relative price.
The table below shows the price points ranging from 9,000 to 11,000 Evmos, where k = 45,000,000.
If you have 200 Evmos and use that pool to trade for OSMO, you would change the pool balance from 10,000 Evmos and 4,500 OSMO to 10,200 Evmos and 4411.76 OSMO. Although the price was originally 90 OSMO for 200 Evmos, you would only get 88.24 OSMO for your 200 Evmos before any charges apply. This is a price impact of 1.96% or slippage percent.
The larger the trade, the worse the impact on price. If you want to exchange 1,000 Evmos for Osmosis tokens, you will receive 409.09 OSMO tokens instead of the expected 450 OSMO. This is a price impact of 9.09%.
Thus, the actual amount of token received in a swap using a two-token liquidity pool can be expressed as:
And the slippage percentage can be represented by:
Real World Evmos / Osmosis Liquidity Pool
Pool #722, the real Evmos/OSMO pool, has 4,046,513 Evmos tokens and 1,727,555 OSMO tokens in the pool. This is a relative price of 0.427 OSMO per Evmos. Evmos performs slightly worse against osmosis than in the simulated tank discussed in the previous section.
Figure 2: The balance of Pool #722 Evmos/OSMO at Block 8,292,833 that occurred on February 15, 2023.
In the real Evmos/OSMO pool, the constant product k = 4,046,513*1,727,555 = 6.99 x 10¹². This means that the liquidity in the real pool is significantly lower than the liquidity in the simulated pool. The constant product curve for the real pool looks like this:
Figure 3: The constant product curve of pool #722 Evmos/OSMO at block 8,292,833. During this block, the liquidity pool contained 4,046,513 Evmos and 1,727,555 OSMO tokens.
Due to the deeper liquidity in the real Evmos/OSMO liquidity pool, a move of 1,000 Evmos is easier to absorb.
Selling 1,000 Evmos to increase the token balance in the pool from 4,046,513 Evmos to 4,047,513 Evmos. The user would receive 426.82 OSMO, which is a price impact of 5.15%.
transaction confirmation
The screenshot above of pool #722 with 4,046,513 Evmos and 1,727,555 OSMO was taken from Osmose block 8,292,883. This transaction shows an exchange of 0.2 OSMO for 0.473 Evmos during this block.
Given a constant product k = 4,046,513*1,727,555 = 6.99 x 10¹², a 0.2 OSMO trade with a 0.2% fee would produce this equation:
Solving for x gives the following equation:
The result of x = 0.47 Evmos agrees with the transaction!
With these confirmation calculations, the possibility of other trades being executed within the same block prior to the test transaction can result in slight discrepancies between the expected and final result. But this calculation and the real result coincided by two significant digits.
Multi-Token Liquidity Pools
Simulated FET / JKL / BCNA liquidity pool
Suppose the relative price of 1 FET is 2 JKL and 20 BCNA and there is a liquidity pool that contains 1,000 FET, 2,000 JKL and 20,000 BCNA. Using Equation 2, the constant product function is calculated as follows:
k = 1,000 FET * 2,000 JKL * 20,000 BCNA = 4.0 * 10¹⁰
As with a two-token liquidity pool, any trade in the FET/JKL/BCNA pool is allowed as long as the constant product k remains constant. As with a two-token liquidity pool, this constant product is the only factor that determines the price of the tokens in the liquidity pool. However, the price of a token is relative to ALL other tokens in the pool and not just one other token.
In the chart above, the red dot is the current (relative) price of 1 FET to JKL and BCNA. Using the liquidity pool to exchange FET, JKL and BCNA will result in a change in relative price. However, in a swap transaction on Osmosis, you can only exchange one token for another. You cannot trade FET and get both JKL and BCNA in the same transaction. So when a swap is performed, the amount of two tokens in the pool changes while one remains constant.
Figure 4: The constant product curve of a simulated FET/JKL/BCNA liquidity pool initially containing 1,000 FET, 2,000 JKL and 20,000 BCNA tokens.
The table below shows the token change in this pool when a user exchanges FET for JKL using this liquidity pool.
If you have 20 FET and want to use that pool to trade for JKL, you would increase the pool’s FET balance to 1,020 FET. However, the balance of the pool of JKL tokens would decrease from 2,000 JKL to 1960.78 JKL. Although originally priced as 40 JKL for 20 FET, the user would get 39.22 JKL. This is a price impact of 1.95%.
During this example exchange, the amount of BCNA tokens in the pool remains unchanged. When this pool is used to switch between FET and JKL, the amount of BCNA stays the same. When this pool is used to swap FET and BCNA, the amount of JKL in this pool remains unchanged as shown in the table below.
Why does the constant product curve look like a surface when only two tokens in the pool are involved in a single swap transaction? The answer is simple. The constant product k must still remain constant, and the exchange of any two combinations of tokens in the pool is allowed. Thus, the surface renders all possible constant product curves possible for this liquidity pool, assuming that swaps are performed involving all potential token combinations.
Real World FET/JKL/BCNA Liquidity Pool
Pool #851, the FET/JKL/BCNA liquidity pool, contains 1,471 FET, 2,294 JKL, and 31,598 BCNA tokens. While the FET : JKL ratio was not too far off in the simulated liquidity pool, the real pool contains significantly more BCNA tokens.
Figure 5: The balance of Pool #722 Evmos/OSMO at block 8,305,743 that occurred on February 16, 2023.
In the real FET/JKL/BCNA pool, the constant product k = 1,471*2,294*31,598 = 1.07*10¹¹. Liquidity in the real pool is an order of magnitude greater than in the simulated pool. The constant product curve for this pool looks like this:
Figure 6: The constant product curve of pool #851 Evmos/OSMO at block 8,305,743. During this block, the liquidity pool contained 1,471 FET, 2,294 JKL and 31,598 BCNA tokens.
Because liquidity in the real FET/JKL/BCNA pool is slightly lower than the simulated pool, the real pool absorbs swaps with slightly less price impact than the simulated pool. The table below shows some potential FET to JKL swaps using this pool.
transaction confirmation
The screenshot above of pool #851 with 1,471 FET, 2,294 JKL and 31,598 BCNA was taken during block 8,305,743 of the Osmosis blockchain. This transaction describes an exchange of 4.854 BCNA for 0.225 FET utilizing pool #851 during this block.
Given a constant product k = 1,471*2,294*31,598 = 1.07*10¹¹ and a pool fee of 0.25%, an exchange of 4.8535 BCNA for FET would yield this equation:
If we solve this equation for x, we get the following:
This gives x = 0.2254 FET, which is the transaction!
Liquidity pools on Osmosis follow the constant xy = k product standard model. While it is well known how this model works for two-token liquidity pools, it still applies to multi-token liquidity pools. When analyzing these multi-token pools, any additional tokens can be included in this constant product model to generate a constant product curve.
So what are the benefits of these multi-token liquidity pools? They could be used as a good way to add additional pool depth to stabilize swap rates for small market caps. We will explore this theory in a future article and examine what might happen in a multi-token pool when additional tokens and pool depth are added.
Learn Crypto Trading, Yield Farms, Income strategies and more at CrytoAnswers
https://nov.link/cryptoanswers
Comments are closed.