Primer on Automated Market Making and Uniswap

Primer on Automated Market Making and Uniswap


Decentralized exchanges (DEXs), such as Uniswap, are a fundamental building block of the crypto-financial system. These platforms enable users to trade cryptocurrencies directly with each other, or via pools of liquidity, eliminating the need for a counterparty or a centralized entity to execute the trade.

In this article, we will introduce several of the key concepts and design elements which make DEXs and Automated Market Makers (AMMs) work. This primer will act as a useful reference point for future studies into the on-chain information available in these DEX protocols.

Permissionless Trading

Uniswap is the largest DEX protocol and is known for its permissionless access as well as simplified user experience. Users retain control of their funds and transact via liquidity pools which contain assets from both sides of a trading pair. Furthermore, anyone can create or participate in a trading pool for any kind of token pair. This makes DEXes an attractive platform for trading all kinds of digital assets, and a unique financial primitive.

The main trade-offs with DEXs relate to the scalability of the underlying blockchain, which also comes with more latency and higher transaction fees. Contrast this with centralized exchanges, where users must transfer their assets into the direct custody of the exchange operators but tend to get faster trade execution, without the blockchain transaction fees.

Decentralized Market Making

One of the principal innovations Uniswap introduced was the Automated Market Maker (AMM) design. This simple construct facilitates the creation of liquidity pools, and the adjusting of token prices depending on the relative liquidity balance on both sides of the trade.

In a traditional exchange, Market Makers provide liquidity by placing buy and sell orders to create deeper order books. With DEXes, smart contracts replace this traditional order book model with liquidity pools and prices dictated by the AMM design. Each pool contains a reserve for a given token pair. For example, the WETH-USDC contains reserves of both WETH as well as USDC, often deposited in a 50:50 split based on the price of each side (although AMMs with other splits do exist).

The AMM design opens up market making to anyone who deposits tokens into the pool, making it a permissionless and open system. In return for providing liquidity, the so-called Liquidity Providers (LPs) receive fees from trades that occur in the pool. These fees are typically a small percentage of the transaction value and are distributed proportionally to LPs based on their share of the pool. For each token pair, Uniswap offers pools with different fee tiers: 0.01%, 0.05%, 0.30% and 1.00%.

Price Determination via the Constant Product Formula

Liquidity pools utilize automated market maker algorithms to manage both the token price and the balance of liquidity within the pool after execution. Whenever a trade takes place, the algorithm automatically adjusts the quantities of tokens in the pool and recalculates the price of each token based on the remaining quantities. For that, it uses a simple formula, called the Constant Product Formula:

\[ x \cdot y = k \]
where

  • \(x\) is the quantity of token in liquidity pool \(a\),
  • \(y\) is the quantity of token in liquidity pool\(b\),
  • \(k\) is a constant.

The product of the two token quantities remains constant after a trade occurs. If someone buys Token B using Token A, this is equivalent to adding the sold amount of Token A, and removing the purchased amount of Token B from the pool. This process keeps the product, k, constant as the quantities of each token change with each trade.

\[ (x + \Delta X)(Y - \Delta y) = k \]

The formula above sets the price of each token based on their relative supply in the pool. The exchange rate is determined by the ratio of the change in x, to the change in y. This formula enables the calculation of one token's price relative to another, based on the relative supply balance in the pool.

There is a second market-based dynamic where token prices are maintained in alignment with other trading venues through arbitrage opportunities. Should a DEX liquidity pool offer a particular token at a steep discount to centralized exchanges, for example, traders can acquire it via the DEX, and sell it at the exchange to capture the spread.

Concentrated Liquidity

In the first iterations of AMMs, the majority used a relatively simple 50:50 asset split, with liquidity distributed across the full range of possible prices for each token.

With the introduction of Uniswap V3, the protocol introduced the capacity to apply liquidity within a designated and concentrated price range. Those ranges are defined by discrete points on a given price scale, and fees will only be earned when the market trades within this range (analogous to strike prices). The tighter the range, the larger the relative share and thus fee revenue that LP will have over the specified price range.

This leads to both a better user experience for DEX traders, as spreads tend to be tighter. However, this design also gives Liquidity Providers more opportunity to actively manage their positions and improves capital efficiency for the pools. Interestingly, this can also open up information and insights into price and volatility expectations from the market makers as their liquidity is moved and re-positioned.

Source: Uniswap Whitepaper

Fee Tiers

As noted above, the primary mechanism for attracting liquidity to Uniswap is the fee revenue from trading activity, which is currently offered in four fee tiers: 0.01%, 0.05%, 0.30%, and 1.00%. The different fee tiers are intended to accommodate for varying levels of risk and trading volume.

The lowest fee tier (0.01%) is typically suitable for pools involving stablecoins on both sides of the pair or for assets with minimal price volatility. Since the risk of impermanent loss is lower in these pools, the fees are set lower to encourage higher-volume, lower-margin trading. 1%, is meant for pools that involve tokens with higher volatility or lower liquidity.

On the other hand, pools with larger fee rates are intended to compensate LPs for taking on asset inventory risk, a higher likelihood of impermanent loss, and where trade volumes are expected to be lower.

Summary and Conclusions

Uniswap has been a pioneer in developing new crypto-financial primitives such as the AMM protocol, and enabling permissionless trading via blockchains. These DEX protocols align incentives such that market makers have a fee revenue incentive to provide liquidity, whilst traders get access to global trade execution without giving up custody of their funds.

Whilst this piece covered many of the key design elements which make DEXs operate, the ecosystem continues to push the boundaries of what is possible in a decentralized future.