Capital Osmosis: A Deep-Dive Into Two- and Multi-Token Liquidity Pools

Jessica Huhnke
Flipside Governance
8 min readMar 9, 2023

Overview

Osmosis is an automated market maker (AMM) protocol that allows users to create customized AMMs with sovereign liquidity pools. This customizability allows for the creation of custom bonding curve AMMs, dynamic adjustments of swap fees, and multi-token liquidity pools.

The biological process of Osmosis, in which water molecules flow from a high-concentration region to a low-concentration region via a semi-permeable membrane, is an apt namesake for this AMM. On Osmosis, lower liquidity pools can be both internally and externally incentivized to draw liquidity away from deep liquidity pools and into smaller pools.

Osmosis is a cornerstone of the greater Cosmos ecosystem, as it is the AMM with the deepest liquidity and largest number of IBC tokens available to trade. 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 = pre-defined constant that is greater than zero. Unless additional liquidity is added to the liquidity pool, k will remain 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 on Osmosis, currently available pools 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 = pre-defined constant that is greater than zero. In other words, the token price is determined by multiplying the amount of all tokens in the liquidity pool together.

Deep Dive Into Osmosis Liquidity Pools

Two-Token Liquidity Pools

Simulated Evmos / OSMO Liquidity Pool

Assume the current price of 1 Evmos is 0.45 OSMO and that there is a liquidity pool that contains 10,000 Evmos and 4,500 OSMO tokens. Taking the constant product function (Equation 1), this gives a constant product k = 10,000*4,500 = 45,000,000.

In this liquidity pool, any trade is permissible as long as the resulting balance of x Evmos and y OSMO tokens remains a constant 45,000,000. This constant product function that enforces 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 that initially contains 10,000 Evmos and 4,500 OSMO tokens.

In the graph above, the red point denotes the current (relative) price of 10,000 Evmos to 4,500 OSMO tokens. But using this liquidity pool to swap Evmos and Osmo results in a change in the relative price.

The table below looks at the price points in the 9,000–11,000 Evmos range where k = 45,000,000.

If you have 200 Evmos and use this pool to swap 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 receive 88.24 OSMO for your 200 Evmos before any fees are applied. This is a 1.96% price impact, or slippage percent.

The larger the trade, the worse the price impact. If you want to trade 1,000 Evmos for Osmosis tokens, you will receive 409.09 OSMO tokens instead of the expected 450 OSMO. This is a 9.09% price impact.

Thus the actual amount of the 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 is doing a little worse against Osmosis than in the simulated pool discussed in the previous section.

Figure 2: The balance of pool #722 Evmos / OSMO at block 8,292,833, which occurred on Feb. 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 deeper than the liquidity in the simulated pool. The constant product curve for the real pool looks like:

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 move 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 5.15% price impact.

Transaction Confirmation

The above screenshot of pool #722 containing 4,046,513 Evmos and 1,727,555 OSMO was taken as of Osmosis block 8,292,883. This transaction shows a swap of 0.2 OSMO for 0.473 Evmos during that block.

Given a constant product k = 4,046,513*1,727,555 = 6.99 x 10¹², a trade of 0.2 OSMO with a 0.2% fee would create this equation:

Solving for x gives the following equation:

The result of x = 0.47 Evmos matches the transaction!

In doing these confirmation calculations, the possibility of other trades being executed within the same block before the test transaction can result in some slight variation between the expected and final result. But this calculation and the real world result matched to two significant digits.

Multi-Token Liquidity Pools

Simulated FET / JKL / BCNA Liquidity Pool

Assume that 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 permissible 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 the other tokens in the pool and not just one other token.

In the graph above, the red dot is the current (relative) price of 1 FET to both JKL and BCNA. Using the liquidity pool to swap FET, JKL, and BCNA will result in a change of the relative price. However, in a swap transaction on Osmosis you can only swap one token for another. You cannot make a swap of FET and receive both JKL and BCNA in the same transaction. Therefore, when a swap is executed 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 that initially contains 1,000 FET, 2,000 JKL and 20,000 BCNA tokens.

The table below illustrates the token change in this pool when a user swaps FET for JKL using this liquidity pool.

If you have 20 FET and wish to use this pool to swap for JKL, you would increase the pool’s balance of FET to 1,020 FET. However, the pool’s balance of JKL tokens would decrease from 2,000 JKL to 1960.78 JKL. Although the price was originally listed as 40 JKL for 20 FET, the user would receive 39.22 JKL. This is a 1.95% price impact.

During this example swap, the amount of BCNA tokens in the pool remains unchanged. When this pool is used to swap between FET and JKL, the amount of BCNA will remain the same. Similarly if this pool is used to swap FET and BCNA, the amount of JKL in this pool will remain unchanged as illustrated in the table below.

Why does the constant product curve look like a surface if 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 swaps of any two token combinations in the pool are allowed. Thus the surface represents all possible constant product curves possible for this liquidity pool assuming swaps involving all potential token combinations are being performed.

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 ratio of FET : JKL was not too far off in the simulated liquidity pool, the real world pool contains significantly more BCNA tokens.

Figure 5: The balance of pool #722 Evmos / OSMO at block 8,305,743, which occurred on Feb. 16, 2023.

In the real FET / JKL / BCNA pool, the constant product k = 1,471*2,294*31,598 = 1.07*10¹¹. The liquidity in the real life pool is one order of magnitude larger than in the simulated pool. The constant product curve for this pool looks like:

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.

Since the liquidity is slightly deeper in the real FET / JKL / BCNA pool than in the simulated pool, the real pool will absorb 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 above screenshot of pool #851 containing 1,471 FET, 2,294 JKL, and 31,598 BCNA was taken during block 8,305,743 of the Osmosis blockchain. This transaction details a swap of 4.854 BCNA for 0.225 FET that utilizes pool #851 during that block.

Given a constant product k = 1,471*2,294*31,598 = 1.07*10¹¹ and a pool fee of 0.25%, a swap of 4.8535 BCNA for FET would give this equation:

Solving this equation for x, we get the following:

This results in x = 0.2254 FET, which matches the transaction!

Conclusion

Liquidity pools on Osmosis follow the standard xy = k constant product model. While it is well understood how this model works for two-token liquidity pools, it is still valid for 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 low market cap alts. We will explore this theory in a future piece, digging into what might happen in a multi-token pool when adding additional tokens and pool depth.

If you are interested in reading more in-depth research pieces such as this or are looking for experienced delegates to represent you, please follow Flipside Governance on Twitter and Medium.

You can also find me on Twitter and on LinkedIn.

Flipside is committed to open-sourced work. To view the code used for the calculations in this article, please visit the Flipside Governance Github page.

--

--

Jessica Huhnke
Flipside Governance

Governance Data Specialist at Flipside Crypto. Grad of Trine University and native Hoosier. Follow me on Twitter: @web3_analyst