Kryptolesson #8

What is Uniswap?

Although public blockchains set out to build a new open financial system based on decentralized and non-custodial applications, the vast majority of crypto trading still takes place on centralized exchanges such as Binance, Coinbase or Kraken. The thriving decentralized finance (DeFi) ecosystem has createda broad range of applications such as loans, trading or insurance that no longer rely on centralized counterparties. One of these DeFi applications, decentralized exchanges (DEXs), aim to solve many of the vulnerabilities inherent in their centralized counterparts such as hacks, fraud, misappropriation, outages and high fees. First-generation DEXs on the Ethereum blockchain, however, faced their own problems, most notably a lack of liquidity. Enter Uniswap ↗, a next-generation DEX capable of providing high liquidity and trading ERC-20 tokens on Ethereum. Unlike the early DEXs, which matched buyers and sellers in a so-called order book model to determine prices and execute trades, Uniswap’s approach is vastly different. Instead of an order book, Uniswap uses a simple math equation and pools of tokens and ether (ETH) to provide liquidity. This is whyUniswap is also referred to as an automated liquidity protocol, or automated market maker (AMM). Think of an AMM as a robot that is always ready and willing to quote a price between two tokens. Any ERC20 token ↗ can be added to Uniswap on the condition that it is funded with an equivalent value of ETH.

‍To determine the price of any given token, the smart contract uses the function: x*y = k, where x and y represent the quantity of ETH and ERC20 tokens available in a liquidity pool while k is a constant value. The equation uses the balance between the ETH and ERC20 tokens as well as supply and demand to determine the price of a particular token. Imagine two buckets of balls, one red balls and one green balls: during each trade a certain amount balls is removed from the pool for an amount of the other balls. To maintain k, the balances held by the smart contract are adjusted during the execution of the trade, therefore changing the price. Each time new ETH/ERC20 tokens are added to a Uniswap liquidity pool, the contributor receives a “pool token”, which is also an ERC20 token. Contributors are referred to as liquidity providers (LPs) and they typically receive a 0.3% trading fee on their share of the pool. When funds are withdrawn from a Uniswap pool, the pool tokens are burned or destroyed. Each pool token represents an LP’s share of the pool’s total assets and a share of the pool’s 0.3% trading fee. A key drawback of AMMs such as Uniswap is “impermanent loss” which is incurred by LPs when the price ratio of the added tokens changes after they are deposited in the pool. The larger the change, the bigger the impermanent loss. Impermanent loss may or may not be temporary but it its typically rare with token pairs that do not experience large fluctuations, such as stablecoins or wrapped tokens. In September 2020, Uniswap introduced UNI ↗, its own governance token. UNI holders can influence and vote on the protocol’s development decisions and fund grants, liquidity mining pools, and other proposals. Uniswap V3 launched in May 2021 which added new features including concentrated liquidity and multiple fee tiers.

Photo by Nick Wehrli