Automated Market Makers in Decentralized Finance: The Basics

The exchange of assets is the driving force behind any financial system. Markets are made to facilitate these transactions, providing a venue for market participants to trade with one another. The importance of understanding how these markets are made cannot be overstated; it is necessary for successfully navigating a financial ecosystem. Decentralized finance is no different. Automated market makers (AMMs) provide the foundation for decentralized finance.

This article will explore examples of AMMs used in DeFi, the objective of which is to give a fundamental understanding to those starting their DeFi journey.

Traditional Market Makers

Before we can understand the mechanics of various AMM models, we first need to review the basic principles of market-making. Traditionally, market makers ensure that trade orders are successfully filled by continuously quoting prices at which they will buy or sell a specific security, allowing the participants to converge on a price – the ‘market price.’ In this way, we say that market makers provide the market with liquidity. Liquidity is the lifeblood of an efficient market; without it, the flow of assets between parties becomes expensive and, in some cases, impossible. The profit made by the makers is the difference between the bid (quoted price for a buyer) and the ask (quoted price for a seller), known as the spread. This is known as the order book model.

An order book model can be reproduced in DeFi, but the speed and costs associated with each transaction on most existing blockchain networks would result in significant losses for those making the market. The constant changing/quoting of prices required to make the market under an order book system would lead to enormous gas fees suffered by the maker, and most networks do not have the transaction speed required to make it efficiently viable. AMMs provide alternative models through which market participants can execute trades and converge on a price.

General Framework for AMMs in DeFi

AMMs run on software designed to facilitate peer-to-peer transactions, replacing a market-making third-party with smart contracts: carefully crafted lines of code that outline the conditions of interaction.

AMMs operate using pools of assets that allow traders to swap one asset for another. These pools are referred to as liquidity pools. Each liquidity pool represents a market of its own, affected only by the participants that interact with it.

Liquidity Pool

Trades happen directly with the pool, where one asset is deposited in exchange for the withdrawal of another. Each transaction performs a price adjustment according to a deterministic algorithm. The stage is set by the algorithm and the contract on which it’s written, the market that emerges directly from the behavior of its participants. This is the essence of decentralized finance, a peer-to-peer exchange absent intermediaries.

AMMs rely on two key actors to create a market: liquidity providers and arbitrageurs.

  1. Liquidity providers (LPs) create the liquidity pools. They offer their assets to be traded against, in return for trading fees and other rewards. An LP’s position is represented by a receipt: an “LP token”, held by the provider who can return the token at any time in exchange for the initial assets deposited.
  1. Arbitrageurs ensure that the prices of the assets in the pool reflect the global market price. Because each pool is a market of its own, AMMs rely on arbitrage to reflect prices accurately. Whenever the price of an asset diverges from the global market price, arbitrageurs take advantage of the difference, performing profitable trades until the market price is reflected across all pools. 

Let’s explore a few AMM models that have been adopted in DeFi, their limitations, and recent innovations aimed at solving some early-stage hurdles.

Constant Product Market Makers

Note: All formulas shown do not take any fees into account, they are the simplest version of each model and for demonstration purposes only. Calculations of price changes are much more complex than the examples shown.

Constant product market makers are the first iteration of a DeFi-native AMM. Introduced by Uniswap, the simplified version of the constant product function is as follows:

The function provides a range of prices for the two assets depending on their reserves (quantities within the pool). Under this model, liquidity providers deposit an equal value of both assets, and the price of each asset relative to the other is determined by the ratio of the reserves within the pool.

The constant product model algorithm provides infinite liquidity because the price increases asymptotically as the desired quantity increases. This can be demonstrated by visualizing the asset curve given by the function.

Constant Product Model

As the quantity of either asset decreases, the price of said asset increases to a theoretically infinite amount, hence “infinite liquidity.”

Let’s run through a simple example to demonstrate the constant product model in action, to better understand the price change that results from a change in reserves.

Consider a pool consisting of 100 FTM and 100 USDC:

Trade #0
Initial Pool Conditions


FTM = x  USDC = y
100 FTM * 100 USDC = 10,000
Price: 1 FTM/USDC

Trade #1
Sell 10 USDC for FTM


Quantity of USDC = 110
Quantity of FTM = 90
90.91 FTM * 110 USDC = 10,000
Price paid: 0.91 FTM/USDC
Quantity received: 9.09 FTM

Trade #2:
Sell 10 USDC for FTM


Quantity of USDC = 120
Quantity of FTM = 80
83.33 FTM * 120 USDC = 10,000
Price paid: 0.67 FTM/USDC
Quantity received: 6.77 FTM

As the reserves of FTM in the pool decrease (FTM is bought), the price of FTM rises relative to USDC. This is how an AMM price discovery mechanism works; the forces of supply and demand are realized through the algorithm. How much the price moves depends on the size of the trade, in proportion to the size of the pool. You can confirm this by testing the impact of the same size trade using more significant reserve balances. Pools with deeper liquidity suffer less price slippage and less volatile price movements, an essential lesson for inexperienced DeFi users, as many are unaware of the dangers of slippage in markets with low liquidity.

Limitations of the CPMM

The fixed ratio of reserves is a constraint that subjects this model to impermanent loss. Impermanent loss occurs when the price of one or both assets you provided deviates from the price at entry. Incremental profits made by arbitrageurs during the price adjustment reduce the reserve amounts within the pool, leaving less for each liquidity provider at the time of withdrawal. The full explanation of impermanent loss is outside the scope of this article, but you can read more about it with the link provided above.

Another feature to consider is the exposure to multiple assets. As aforementioned, providing liquidity requires an equal value of both assets in the pool to be provided: a 50/50 ratio (these pools are sometimes referred to as 50/50 pools). If an LP does not want to expose themselves to both assets, they don’t have the option of providing only one and may choose not to enter the pool as a result.

Constant Sum Market Makers (CSMMs)

The constant sum model is a very simple and straightforward implementation of a constant function market maker: the sum of each asset is equal to a constant.

This is what it looks like in MATH

The constant sum function provides a model for which zero price slippage trades are possible, as demonstrated by an example using the formula (I’ll spare you the math but it’s only addition and subtraction, try it for yourself!). This model is meant for assets whose prices remain the same relative to each other, as shown by the function.

Constant Sum

Limitations of the CSMM

While zero slippage is a desirable feature, this model can not be employed on its own. The function does not provide infinite liquidity. The bonding curve is linear; therefore, anytime the price ratio price between the two assets is not 1:1, there is an opportunity for an arbitrageur to deplete one side of the pool, draining all the liquidity supplied by the providers.

Hybrid Function Market Makers

As the name suggests, a hybrid market maker combines different models to capitalize on the advantages of each. Curve was the first protocol to design a hybrid market maker, combining the constant product and the constant sum to create an elegant model that uses the best of both worlds. What Curve realized is they could make an algorithm, built for assets whose prices move in tandem that greatly reduces slippage while still providing infinite liquidity; the function is as follows:

Now don’t panic, I will explain. But for you math heads out there, rejoice! Ain’t she beautiful? This is known as the Stableswap Invariant.

The function works by concentrating liquidity within a specific volatility range, reducing price slippage within that range, effectively acting as a constant sum model. As volatility increases, the ratio of the assets within the pool becomes imbalanced, and the function shifts towards the constant product. The bonding curve provides a good representation of this, as it can be challenging to visualize yourself.

The limitations of this model are easy to follow if you understand the constant product and the constant sum. But by merging the two models, the strengths of each are taken advantage of under the right circumstances. The caveat is that the low-slippage advantage of the constant sum model can only be applied for asset pairs whose prices move together, such as stablecoin pairs. 

Constant Value Market Makers

The constant value model is a generalization of the constant product model. It allows for more than two assets to be combined in a pool, assigning weights to each asset. The constant is the weighted geometric mean of the reserves:

This model has allowed protocols to tailor pools in ways impossible with the constant product’s two-asset model. Brilliantly designed by Balancer, this model has become a staple in DeFi. Balancer’s model allows up to eight assets to be combined in a pool, enabling the creation of diversified multi-asset markets. 

Trades occur between two assets within the pool, and the spot price is defined by the asset’s reserve balances (R) and weights (w) assigned. For a given asset sold to the pool, the price of the asset received (bought) is set so that the constant (k) remains the same, considering the change in reserve balances.

One important feature of this model is the option to provide liquidity using one asset instead of the whole basket. While the result of exposure to the entire pool remains, this saves liquidity providers the time and transaction costs otherwise spent on splitting up their assets. However, in contrast to providing an equal share of each asset (full-basket provision), single-asset provision affects the reserve ratio, and thus the price. The weights in the pool must be respected, therefore any transaction that affects the reserve ratio will result in a price change. 

The constant value model is especially useful for liquidity bootstrapping. As the weights assigned can define the value distribution of the assets in the pool, less capital is needed to achieve some target exchange rate in the market. You can learn more about Liquidity Bootstrapping Pools here (for the basics) and here (more advanced).

Limitations of the CVMM

The same limitations of the constant product model discussed above can be applied to the constant value model, with a few considerations. This model’s dynamic weighting and multi-asset pools can significantly reduce impermanent loss. The effects of different pool weight distributions on impermanent loss are shown below.

Regarding exposure to multiple assets, multi-asset pools can also be seen as an advantage rather than a limitation. If an LP values diversification, entering or creating a pool of eight different assets can be a powerful tool for earning yield on a basket of desired holdings.

Dynamic Market Makers (DAMMs)

Dynamic market makers, introduced by Bancor in their V2 launch, are yet another step towards breaking free from limitations present in other models. We will use Bancor’s V2 model as an example of how dynamic models can work.

The mechanism uses price oracles to adjust the weights of the assets in the pool in accordance with the current global market price. Oracles provide off-chain data to on-chain applications, an example of which is price feeds that eliminate the need for arbitrage, as the global market price is fed directly to the exchange. For more info on oracles, check this out.

The pool can accurately reflect the current exchange rate using dynamic weighting through the price oracle integration. This eliminates the reliance on arbitrageurs to reflect accurate prices. Instead, arbitrageurs are only needed to balance the pool’s asset distributions in response to trades. With a variable reserve ratio, the impermanent loss is mitigated entirely, preserving the reserve amounts deposited by the providers. 

The dynamic reserve ratio also enables single asset exposure, granting liquidity providers the option of representing only one side of the pool. This is very desirable for LPs, allowing them to earn yield on an asset they would otherwise be holding without having to make any temporary changes to their portfolio through exposure to other assets.

Integrating price oracles with decentralized exchanges is an exciting and ongoing development for AMMs in DeFi. Removing arbitrage dependence further increases the efficiency of decentralized markets and preserves user capital that would otherwise be paid out to the arbitrageurs. While this seems the obvious path forward, oracle integration is a long and complicated process, currently limited to assets for which off-chain data is abundant – a rare feature for most assets in DeFi. Another consideration regarding price feed integration is the additional security risk it imposes. Further reliance on the oracle technology (and the companies that provide it) means more points of potential system failure.

Capital Inefficiency

For AMMs to be effective market makers, they require pools with lots of liquidity. As the size of the pool increases, the price slippage decreases, and the market becomes more efficient. Assets in large amounts lay in wait, sitting idly by in support of the market but often never used to facilitate a trade. This is why AMMs are often referred to as “lazy markets.” The inefficient use of the capital provided has been of significant concern to many DeFi users; it is a problem that must be solved if AMMs are to replace our current system. Truly sustainable yields are few and far between, trading fees being one of the only reliable sources. Inefficient use of capital only impedes revenue generation and subsequent distribution.

Boosted pools are an example of a solution recently implemented to combat capital inefficiency. These pools use idle liquidity by incorporating yield-bearing assets, such as Yearn’s yvTokens, realized via nested pools and phantom receipt tokens. Incorporating these interest-bearing assets results in higher, more sustainable yields for liquidity providers. 

Closing Remarks

While AMM innovations in DeFi have continued to flourish, substantial progress needs to be made before widespread adoption can be attained. Fortunately, the ceaseless nature of technological innovation in this space only breeds improvement; new iterations and models are constantly developing. AMMs have the potential to be the new norm for market making, to provide a faster, more decentralized instrument for exchange absent from external parties.

Much love, 
Charles

If you’ve got questions, comments, concerns, or even opinions, tell us about them on our Discord thread for this article!

Scroll to Top