saddle.finance

Search…

Automated Market Makers

AMMs democratized cryptocurrency trading by doing away with order books and institutional market makers.

Markets facilitate trade in a society by connecting the sellers to the buyers. Trading of goods, services, or information (assets collectively) happens in a purpose-built marketplace. For instance, a local community might have a farmers’ market to trade locally produced vegetables and fruits. Whilst a stock market like New York Stock Exchange (NYSE) allows global participants to trade in stocks. A traditional market comprises buyers, sellers, brokers-dealers, and market makers.

Let’s look at the fundamentals first.

A cryptocurrency exchange is a marketplace for trading cryptocurrencies. Broadly, two types of cryptocurrency exchanges exist:

The DEX ecosystem is nascent and maturing. Despite few shortcomings, compared to CEX, decentralized exchanges grew in popularity. The allure of removing middlemen, lower fees, and decentralization pushed the adoption of DEX.

The early version of the cryptocurrency exchanges used the order book model, like traditional exchanges. The order book model works well where the trade volumes and liquidity are high, resulting in lower slippages. Leading cryptocurrencies, like Bitcoin and Ethereum, have high volumes of trade. While other cryptocurrencies and tokens, which don’t have high volumes, faced challenges with the order book model.

In the illustration below, the seller's Ask is $20.50 and the buyer's Bids are not closer to the Ask. This results in a liquidity challenge. Market makers, therefore, step in to keep the market functioning by actively buying and selling assets - i.e., transacting on both sides to keep the market functioning. The market makers carry the risk of a price variation during Buy-Hold-Sell cycle.

The main issue is related to high slippages and volatility due to low volumes of trade. The absence of market makers round the clock further constrained the liquidity. Automated Market Makers (AMM), therefore, emerged as a solution to the order book challenge.

Market makers are essential in an exchange to provide liquidity, control spreads, and maintain slippages. Since cryptocurrency exchanges work 24x7, the need for automated market makers rose. AMMs democratized cryptocurrency trading by doing away with order books and institutional market makers. Instead, AMMs execute trade automatically using algorithms and liquidity pools. Let’s understand a few basic concepts first.

Having understood what AMMs are, let’s now deconstruct them. You can think of an AMM as a friendly and obedient market maker bot, always willing to quote a price, no matter the time of the day or day of the week.

To quote you a price, the bot uses a mathematical formula (used interchangeably with pricing algorithm or swap algorithm) and works relentlessly in the background. The algorithm implemented varies from the simplex to the complex. We’ll look at the commonly used swap algorithms, including the StableSwap algorithm used by Saddle.

Constant product formula is probably the simplest and the earliest algorithm to come into the market. Uniswap popularized the mathematical formula:

where **x** is the amount of Token#1 in the liquidity pool, **y** is the amount of Token#2 in the liquidity pool, and **k** is a fixed constant.

Let’s look at a few critical aspects from the example below. An ETH-USDT liquidity pool is set-up with 100 ETH and 300,000 USDT, provided by the liquidity providers. As the pool is set-up, the initial conditions are:

3000 : 1

300,000

100

30,000,000

When a trader wants to swap the tokens in the pool, the formula will try to achieve the constant product equilibrium. For example, if a trader wants to swap USDT for 1 ETH, then to maintain a constant product of 30,000,000 the price quoted for USDT will be 3,030.30 (a premium of 1% over the initial setup price) and the liquid pool composition after the swap will be:

3030.30 : 1

303,030.30

99

30,000,000

Likewise, if a trader wants to swap USDT for 5 ETH, the price quoted by the algorithm will be 3,157.89 (a premium of 5.3% over the initial setup price) and the liquid pool composition after the swap will be:

3157.89 : 1

315,789.47

95

30,000,000

Uniswap first implemented the constant product formula and Balancer refined it with a generalized formula. But there is a challenge.

The constant product formula determines the price when someone trades against the liquidity pool. As we see from the chart below, we calculate the price as a ratio of the tokens in the pool. The pricing curve has a hyperbola when plotted against two tokens. When someone withdraws, say Token#1, the proportionate Token#2 to be deposited, to maintain the constant product, varies.

Given the volatile nature of cryptocurrency, the market price of the tokens also fluctuates. The constant product formula *does not update* the price of the tokens in the pool with the market movement. In certain cases, the price update is a simple off-chain observation. This resulted in the risk of higher slippages.

Thanks to arbitrageurs, once they find a cheaper price, they’ll move the funds around liquid pools for profit making. Eventually, the price in the liquidity pools starts stabilizing closer to the market price. This does not, however, eliminate the slippage challenge in full.

To address the slippage issue, AMMs explored the constant sum formula as an option. Constant sum formula solves for the equation:

where **x** is the amount of Token#1 in the liquidity pool, **y** is the amount of Token#2 in the liquidity pool, and **k** is a fixed constant.

While the constant sum formula solves the slippage problem, it provides only *fixed liquidity*. For markets to function well, they need a constant supply of liquidity and hence this model didn’t suit the purpose well.

The innovation into AMMs mathematical formula continued to find a solution to the slippage (constant product formula) and fixed liquidity (constant sum formula) problems. Hybrid mathematical models, combining the best of many models, rose to prominence. One such model is the Stableswap algorithm.

First introduced by Curve, the Stableswap is a hybrid algorithm. The Stableswap hybrid combines both Constant Product and Constant Sum models, and the following chart shows the Stableswap algorithm in relation to constant product and constant sum invariants.

**Constant Sum:**When the liquidity pool portfolio is balanced, the algorithm functions as a Constant Sum formula;**x + y = k**. You can observe the StableSwapstaying close to the Constant Sum*blue line*, and the price is stable.*red line***Constant Product:**As the liquidity pool portfolio becomes imbalanced, the StableSwap algorithm functions as a Constant Product formula;**x * y = k**. You can observe the StableSwapnow resembling the Constant Product*blue line*, and the price becoming expensive.*purple line*

Saddle liquidity pools implement the StableSwap mathematical formula to reduce slippage and keep the market liquid. Saddle facilitates trades of stablecoins, where the price is pegged to an underlying asset, bringing in further stability. For example:

The Constant Product formula *does not update* the price of the tokens in the pool with the market movement. The Stableswap formula motivates swaps around price ratio 1.0, well suited for stablecoins. Dynamic pegs are the next evolution of AMMs.

Dynamic pegs will bring the benefits of Stableswaps to cryptocurrency assets which aren’t pegged to another asset. By using an automatic price change mechanism, the algorithm will move the price based on real-time profit margin calculations, to adjust for slippages. Thus, benefiting both the traders and the AMMs.

Last modified 1mo ago