Telegram (AI) YouTube Facebook X
Ру

What is an automated market maker?

What is an automated market maker?
Advanced
What is an automated market maker?
Advanced

Key points

An automated market maker (AMM) is a software algorithm that governs liquidity and pricing for cryptoassets on decentralised exchanges.

AMMs are widely used across DeFi, particularly on decentralised exchanges (DEXs) such as Uniswap, Balancer, Bancor and Curve.

To build decentralised markets, AMMs draw on liquidity in public cryptoasset pools of multiple tokens locked in specialised smart contracts.

How did automated market makers emerge?

An AMM is an autonomous trading mechanism underpinning most trading by DeFi protocols. It channels capital and executes users’ exchange operations across available cryptoasset markets.

The first known developer to discuss implementing an AMM was Alan Lu of the Gnosis team. His ideas were set out by Ethereum founder Vitalik Buterin on Reddit in 2016 and in his personal blog in July 2017.

This concept underpinned the Uniswap protocol, which received an initial grant of $100,000 from the Ethereum Foundation. Vitalik Buterin also advised Uniswap’s developers.

AMMs later became widely known thanks to Uniswap. At the same time, one of the first successful implementations was Bancor Network, which raised $140m via an ICO in June 2017.

How are liquidity pools linked to AMMs?

The key element that makes an AMM work is a liquidity pool—a store of cryptoassets in a smart contract. A pool typically holds two cryptoassets and constitutes a market, analogous to a trading pair on a centralised exchange.

Some participants lock in funds to earn income from swap fees. These users are known as liquidity providers.

Another group comprises end-users of DEXs who swap cryptocurrencies in the protocol using one of the pools.

To understand liquidity pools, consider what led to their creation.

The first DEXs ran on Ethereum and used a standard order book, as on centralised exchanges. For such a mechanism to be efficient, it needs very high transaction throughput. Because DEX operations are confirmed on-chain, their speed and capacity were highly constrained. AMMs offered a way around this.

An AMM is therefore a fundamentally different way to create markets: a set of formulas and rules by which the protocol handles buy and sell orders and manages users’ reserves.

How do liquidity pools work?

Pools can contain two or more assets. On Uniswap you can create pools for token pairs. Balancer allows pools with three or more tokens. The Curve protocol is designed for pools of assets with similar value, such as ETH and the wrapped token WETH, or USDC and DAI. Their operation is governed by an AMM.

Each AMM DEX can use its own formulas and rules for interacting with liquidity pools. For example, Uniswap uses the formula x * y = k.

In this equation, x and y are the quantities of tokens in the pool; k is a constant known as the invariant. Curve uses the formulas x * y = k and x + y = k.

SushiSwap and PancakeSwap also use x * y = k—the most common variety of AMM DEX.

How is pricing determined in a liquidity pool?

When liquidity is locked in a pool, the provider receives LP tokens that prove their share of the pool. These are akin to IOUs that entitle the holder to a share of swap fees and to withdraw their proportionate stake.

LP tokens are transferable cryptoassets. They can be sold or exchanged on the open market, or deployed in third-party DeFi applications.

The process of swapping one asset for another via a liquidity pool is called a swap. Only one asset is added to the pool, unlike when minting LP tokens, which requires two. The pool charges a small fee for a swap, comparable to fees on a centralised exchange—around 0.1–0.3%. Fees are distributed to liquidity providers in proportion to their share of the pool.

Example

Consider a hypothetical ETH/USDC pool. With 1 ETH priced at 2,000 USDC, any amount of the two coins can be deposited into the smart contract at a 1:2000 ratio. At that price, the pool might hold 100 ETH and 200,000 USDC.

The pool’s asset balance is set by their price. If a user swaps 10 ETH via this pool, they submit their coins to the smart contract in a normal transaction. In return, they receive 20,000 USDC (excluding the swap fee).

After this swap, the pool holds 110 ETH and 180,000 USDC. The price of ETH in this pool is therefore about 1,636 USDC instead of 2,000 USDC on other markets. This attracts arbitrage traders, who add USDC to the pool until the price returns to the market level of 2,000 USDC per 1 ETH.

What are the drawbacks of AMMs?

Despite being a breakthrough for trading and DeFi, AMMs have clear drawbacks. First, swaps via an AMM carry a high risk of price slippage. This, in turn, gives rise to risks of impermanent loss for LPs and miner-extractable value (MEV) for ordinary users.

To mitigate such risks, other designs have emerged, such as CowSwap, which combines developments from AMM-Balancer and the Gnosis protocol.

Second, unlike centralised exchanges, AMMs typically allow only one type of order. You cannot trade with limit orders or other types such as stop-loss.

What is impermanent loss?

Impermanent loss (IL) refers to temporary or unrealised losses incurred when holding assets in a liquidity pool on an AMM DEX. IL concerns liquidity providers (LPs) and is the difference between the price at the time of deposit and the effective price while the assets are held. Losses are considered unrealised because they are not crystallised until liquidity is withdrawn.

As an example, consider a Uniswap pool operating under the classic x * y = k formula:

  1. A liquidity provider locked 1 ETH and 2,000 DAI. Their share of the pool is 10%.
  2. The pool in total holds 10 ETH and 20,000 DAI—worth 40,000 DAI.
  3. The pool balance has not changed, as no new liquidity providers joined.
  4. Assume the market price of ETH rises to 4,000 DAI.
  5. Arbitrage traders then exploit the opportunity and shift the pool to 5 ETH on one side and 20,000 DAI on the other. The overall size of the pool remains 40,000 DAI.
  6. At this point, the liquidity provider decides to withdraw their share—10%.
  7. Given the current pool balance, they withdraw 0.5 ETH and 2,000 DAI, even though they initially added 1 ETH and 2,000 DAI.
  8. The initial value of their stake was 4,000 DAI (1 ETH plus 2,000 DAI) in stablecoin terms. The value at withdrawal was the same 4,000 DAI (0.5 ETH plus 2,000 DAI).
  9. However, had the user simply held 1 ETH and 2,000 DAI, the value would now be 6,000 DAI. That is the unrealised loss—or gain—when using an AMM DEX.
  10. The user also receives 10% (proportionate to their pool share) of all pool fees as a reward for providing liquidity. This reward may be reduced, for example by allocations to developers or to the project treasury for future development.

This is a stylised example of a sharp 50% rise in one asset, ignoring the many arbitrage trades and the time it takes to align the pool price with that on centralised exchanges, where changes occur instantly.

In calmer market conditions, calculations of impermanent loss add variables for price movements, as described in his blog by StarkNet developer Peteris Erins. These illustrative calculations suggest an impermanent loss of about 5.7% for a twofold price move. But this is only a projection—potential “losses” are hard to predict.

How can you mitigate risks when trading via AMMs?

Before using a liquidity pool, calculate all the fees you will pay when depositing and when you plan to withdraw assets.

Allow for price moves in both directions. Some potential issues, such as the risk of impermanent loss (IL), can be estimated in advance.

To calculate IL, you need to understand its causes. You can also use one of the online calculators available.

Follow ForkLog on social media

Telegram Instagram
Found a mistake in the text? Highlight it and press CTRL+ENTER.

Рассылки ForkLog: держите руку на пульсе биткоин-индустрии!

We use cookies to improve the quality of our service.

By using this website, you agree to the Privacy policy.

OK