xrplswap #3 — Advanced Decentralized Token Exchange Mechanism, AMM

Joonha Lee
xrplswap
Published in
6 min readSep 25, 2023

※ xrplswap is the first AMM DEX on XRP Ledger. The xrplswap series #1–4 are official community documents from the xrplswap team to introduce xrplswap to XRP holders.

[xrplswap series]
1. XRPL, XRP’s Blockchain
2. XRPL’s DEX
Advanced Decentralized Token Exchange Mechanism, AMM
4. Introducing xrplswap, XRPL’s first AMM DEX

xrplswap ⓒ 2023. xrplswap

Advanced Decentralized Token Exchange Mechanism, AMM

[Table of Contents]
1. Limits of Order Book DEXs
2. AMM, the New Era of DEX
3. Current Status of AMM DEX

In the previous article, we explored the order-book-based DEX (Decentralized Exchange) supported by the XRP Ledger (hereinafter XRPL). In this article, we will delve into AMM-based DEX, which cleverly leverages the properties of blockchain to surpass the limitations of traditional order book DEX.

Limits of Order Book DEXs

Order-book-based DEX fundamentally has limitations when it comes to liquidity. In order to execute an order on an order book DEX, you need to find a matching order in the opposite direction. For example, if you want to exchange XRP for ETH, you need to find another order that wants to exchange ETH for XRP, and both parties need to agree on the price and quantity. If a matching order cannot be found, the trade cannot proceed and is halted. All the numerous orders listed in the order book of an order book DEX represent trades that could not be completed in this manner.

To surpass the limitations of liquidity, an entirely new approach is needed, rather than relying on an order book.

Example of XRPL’s DEX Order Book (Sep. 2023) (src: Sologenic DEX)

AMM, the New Era of DEX

In November 2018, Siemens engineer Hayden Adams introduced a new form of DEX called Uniswap to the world. Uniswap proposed a different approach to facilitating trades by using AMM (Automated Market Maker), instead of an order book.

Uniswap’s proposed AMM garnered praise for cleverly utilizing the properties of blockchain, offering several advantages over traditional order-book-based DEXs, such as the absence of trade interruptions due to liquidity shortages. Uniswap gained significant popularity and continues to lead the way, with many AMM DEXs now serving as the cornerstone of the decentralized cryptocurrency ecosystem.

So, what is AMM, and how does it work? Unlike traditional order book systems where buyers and sellers set desired prices, AMM determines the price of a token or asset based on the state of a Liquidity Pool automatically. A Liquidity Pool typically consists of two different tokens that are deposited into it. Traders can deposit one of these tokens into the Liquidity Pool in exchange for the other token, a process known as a “swap.”

The amount of tokens that can be obtained through a swap is automatically determined based on the condition that the sum (CSMM) or product (CPMM) of the quantities of the two tokens remains constant. For example, if a Liquidity Pool has A tokens and B tokens deposited in quantities a and b respectively, and a user wants to swap 10 A tokens for B tokens, the amount of B tokens the user can obtain is determined by maintaining the product (a × b). So, the amount of B tokens the user can receive would be (a × b) ÷ (a — 10). This means that as the token quantity ratio within the Liquidity Pool changes, the amount of tokens obtainable through a swap, or the trading price, also changes accordingly.

CPMM Price Decision Graph (src: ethsearch)

Users of an AMM DEX can typically participate in trading in two main ways. Firstly, there are traders who initiate swaps, as explained earlier. They are the parties requesting the swaps. Secondly, there are liquidity providers. Liquidity providers are participants who deposit both tokens into the liquidity pool in equal proportions. The liquidity in the liquidity pool is essential for reducing slippage (the phenomenon of not getting the desired price) in swap transactions. Therefore, liquidity providers are compensated for providing liquidity, often in the form of transaction fees or the DEX’s native tokens.

DEXs utilizing AMM are considered superior to order book DEXs in two main aspects. Firstly, they enable continuous trading. Unlike order-book-based exchanges, there’s no need to find matching orders, making it possible to trade at any time without interruptions. Secondly, AMMs offer lower trading costs. In traditional order-book-based DEXs, complex calculations are required to match orders, and the problem is that all of these operations are executed on-chain. This has led to increased transaction costs in many blockchains that calculate fees based on the operations. In contrast, AMM operates with very simple logic, resulting in lower trading costs compared to order-book-based systems.

AMM is not without its drawbacks. There are aspects that users must accept, such as the introduction of the concept of “liquidity provision” to support uninterrupted trading.

The first is the impermanent loss that the liquidity provider will probably experience. While a liquidity provider in an AMM is providing liquidity, the price of the token may change from what it was when the liquidity was provided. This can lead to a loss for the liquidity provider, as it is difficult to be flexible with token price fluctuations during liquidity provision. Of course, this loss can be recovered if the price of the token returns to the initial provision.

Secondly, traders using AMM may experience unpredictable slippage. As mentioned earlier, the price of tokens in AMM is not determined by orders but automatically. When the liquidity in the pool is high, the risk of slippage is low. However, for larger trades or when liquidity in the pool is insufficient, there can be a significant difference between the expected and actual trade prices. This can lead to unexpected losses for traders.

Current Status of AMM DEX

XRPL, which we are examining, does not have an AMM DEX. In a previous article, it was mentioned that XRPL does not have smart contracts, so new features can only be implemented by adding new transaction types. However, as of now, AMM is a feature that is not supported on the XRPL mainnet, so you won’t find an AMM DEX on XRPL.

In contrast to XRPL, many other major blockchains have AMM DEXs that are actively in use. For example, Uniswap, which currently has the highest trading volume, operates on the Ethereum blockchain through smart contracts. Uniswap has evolved through protocol upgrades like V2 and V3 to become more versatile, making it applicable to a wide range of tokens. It has also activated concentrated liquidity provision methods, further enhancing liquidity.

Sushiswap, which gained fame for attracting a large user base from Uniswap, has distinguished itself through community-driven development and a governance model. Its unique incentive structure has also led to active usage.

Curve Finance, which successfully established liquidity pools and supported swaps for stablecoins, even though they are typically considered less suitable for AMM due to their price stability, has crafted a profitable tokenomics model through the issuance of its own coins. As of September 2023, Curve Finance maintains one of the highest token values, following Uniswap.

Outro

So far, we’ve explored AMM-based DEXs that have gone beyond the limitations of order book DEXs, opening up a new era in cryptocurrency trading. We also pointed out that, as of now, XRPL still does not have an AMM DEX.

However, there is some good news. In the next article, we will introduce the first AMM DEX on XRPL, created by the xrplswap team.

References

https://www.coingecko.com/en/categories/automated-market-maker-amm

https://twitter.com/xrplswap

ⓒ 2023. xrplswap ALL RIGHTS RESERVED

--

--