Automated market maker – Mangrove

GlossaryTokens and DeFi

Automated market maker

Definition: An automated market maker (AMM) is a smart contract that sets prices from the balances of tokens in a pool, so traders swap with the pool.

Most exchanges match orders through an order book, a separate entry. The Bank for International Settlements (BIS) explains that on a blockchain the volume of orders would make an order book “very costly”, so many decentralized exchanges, a separate entry, use AMMs instead (BIS Quarterly Review, December 2021). Liquidity providers deposit tokens into a liquidity pool, and other traders buy or sell against it. In the constant product formula, written x * y = k, x and y are the pool’s balances of its two tokens, and k must stay the same or grow after every trade (Uniswap documentation). The price the pool offers for a very small trade, before fees, is one token’s balance divided by the other’s (Uniswap v2 whitepaper). A larger trade gets a different average price, as the example below shows. Arbitrageurs, traders who profit from price differences between markets, trade with the pool when its price is off by more than the fee, so its price tends to track the wider market. Uniswap v2 charges a 0.30% fee on each trade; later versions set fees by pool.

Because the product of the balances must stay constant, each trade moves the price. Uniswap’s documentation says larger trades relative to the pool’s size move it more, which it calls price impact and treats separately from slippage, a separate entry (Uniswap documentation). A pool with more liquidity, also a separate entry, moves less for the same trade. For example, suppose a hypothetical pool holds 1,000 each of tokens A and B, so k is 1,000,000 and the price is 1 B per A. A trader who pays in 100 B, ignoring fees, would leave the pool with 1,100 B, so the pool could keep only 1,000,000 / 1,100, about 909.1 A. The trader would receive about 90.9 A, an average of about 1.10 B per A, and the pool’s price afterward would be about 1.21 B per A. A trade of 10 B would receive about 9.9 A, an average of about 1.01 B per A.

Guillermo Angeris and colleagues trace research on AMMs to the logarithmic market scoring rule from a 2003 paper by R. Hanson, which is “often used in practice as an AMM for prediction markets”, markets in which people trade on the outcome of future events (arXiv:1911.03380). In a Reddit post, Vitalik Buterin proposed running decentralized exchanges with “the style of ‘on-chain automated market maker’ used in prediction markets” (Reddit, archived). In a March 2018 post, he dated that suggestion to “two years ago” and described the “x*y=k market maker”, a simple approach suggested by Martin Koeppelmann of Gnosis (Ethereum Research). Hayden Adams, who built Uniswap, wrote that he set out to implement an AMM “as described by Vitalik”, and Uniswap was deployed to the Ethereum mainnet on 2 November 2018 (Uniswap blog).