Uniswap: Decentralized Token Exchange on Ethereum

Introduction to Uniswap

Uniswap is a protocol for decentralized and automated token exchanges on the Ethereum blockchain. The protocol is composed of a series of smart contracts for ERC20 tokens, enabling easy swaps between Ethereum (ETH) and ERC20 tokens. Transactions are mostly automated through these contracts, minimizing the trust required among different actors and removing middlemen.

Uniswap does not have a native token and does not charge platform fees. It also has no central governing body. Only exchange contracts in the protocol process transactions.

How Does Uniswap Work?

Source: ERC20 to ERC20 trades, Uniswap Whitepaper

Users can use Uniswap to:

  • Exchange ERC20 tokens
  • Send tokens to other users
  • Add liquidity by supplying ERC20 tokens. Adding liquidity allows suppliers to determine exchange rates

Users need to have Metamask installed on Chrome or Brave in order to use Uniswap.

Uniswap functions through two types of smart contracts: the exchange contract, and the factory contract.

Exchange contracts support different ERC20 tokens. These contracts hold reserves of ETH and specific ERC20 tokens, creating liquidity reserves for the tokens.

Uniswap takes care to maintain a large enough liquidity pool to handle large trades. This is because all trades executed on exchange contracts are determined by the relative supply of ETH and ERC20 tokens in these contracts. Trading between different ERC20 tokens use ETH as an intermediary. What separates it from traditional exchanges is the absence of the traditional order book that matches supply and demand. Uniswap utilizes its liquidity reserve to govern the exchange of cryptos on the protocol. The reserves are then pooled between a network of liquidity providers that supply it with tokens in exchange for a proportional share in transaction fees.

Factory contracts are involved when there are tokens that still do not have smart contracts that open them for trading on the exchange. The factory contract is used to create a new exchange contract. Anybody can use the Uniswap factory to create smart contracts for any ERC20 token of choice without having to ask permission from anyone at Uniswap, as long as the tokens aren’t listed yet. The factory contract also serves as a registry of all exchange contracts. Anyone can be a liquidity provider on an exchange as long as they have the corresponding deposit of ETH and the ERC20 token available for reserve.

Determining Reserves

Uniswap’s reserves rest on liquidity providers who supply equal values of ETH and ERC20 tokens to Uniswap exchange contracts.

Liquidity providers receive ‘liquidity tokens’ which represent the liquidity provider’s contribution to exchange contracts. These are minted in order to track their share of contributions to the total reserve pool. These tokens are burned at the time providers choose to withdraw their share of ETH and ERC20 tokens from exchange contracts.

Providers can either sell or transfer their liquidity tokens while still receiving a share of transaction fees every time a trade is performed in their corresponding exchange contracts. Trading activities on the exchange incur a 0.3% fee which goes into the liquidity pool. This guarantees that the total combined reserve size increases with each trade.

Determining Exchange Rates

Uniswap pools the liquidity provided by all market participants and defines the prices for buying or selling ETH through a deterministic algorithm called the automated market maker (AMM).

Uniswap uses an AMM variant called the Constant Product Market Maker Model. This model addresses the problem of  large price slippages which occur when the price of ERC20 tokens increase relative to ETH for subsequent transactions on the exchange. This is also a reason why Uniswap uses ten times less gas than Bancor and can execute ERC20 trades more efficiently than 0x. Simplifying the price calculation for token swaps and bookkeeping for contracts makes the process more gas-efficient. According to Blocklytics, Uniswap overtook Bancor in terms of total ETH trade volume in February 2019, surpassing Bancor’s volume of $196,478 to post volumes of  $541,408.

An integral part of the protocol is the formula for calculating exchange rates: X * Y = K, where X and Y represent the quanity of ETH and ERC20 tokens in an exchange and K is a constant. This formula can be used to determine the price of tokens on a decentralized exchange, and was adopted from a post on Ether Research by Ethereum’s Vitalik Buterin.

Source: Understanding the Decentralized Ethereum Exchange, Ross Bulat

The graph above shows how the X * Y = K formula is used to determine exchange rates on Uniswap. Assume that the curve represents all possible exchange rates and assume that Token A is an ERC20 token and Token B is ETH. There are 2 scenarios that cause the exchange rate to fluctuate:

  1. Increased demand for the ERC20 token: in this case, there will be a shortage of the ERC20 token relative to ETH. This would cause the exchange rate in the graph above move to the left, making the ERC20 token more expensive.
  2. Decreased demand for the ERC20 token: In this case, the exchange rate would move to the right, resulting in a cheaper ERC20 token. Note that the curve flattens out in this model. This means that if the ERC20 token crashes, the price simply bottoms out instead of crashing repeatedly and falling well below $0.01 (which is what we see happening to some altcoins on traditional exchanges). Of course, once the price has bottomed out, a reversal is also harder than in a centralized exchange. However, this mechanism seems to limit the downside.

The first liquidity provider to add liquidity to an exchange contract will determine the exchange rate between an ETH and the ERC20 token supported by the contract. Providers do this by depositing an amount of the ERC20 token they deem as its equivalent in ETH.

If the defined exchange rate is inconsistent with the overall market value for the ERC20 token, arbitrage traders correct the value. Arbitrage trading involves taking advantage of situations when a coin is priced differently on different exchanges. Once a trader sees an opportunity for arbitrage, they can purchase a coin on one exchange and resell it on another exchange for a profit. This ensures that a coin is eventually priced correctly across exchanges.

Use Case

Decentralized ERC20 Token Exchange

Uniswap’s primary use case allows ETH to be swapped with any ERC20 token. ETH is used as an intermediary asset when trading between ERC20 tokens. The ERC20 token is first converted to ETH using a particular exchange contract. The ETH is then converted to another ERC20 token using another exchange contract. Users currently pay a 0.3% fee for both conversions.

Uniswap relies on arbitrage traders to keep the exchange rates for tokens in check. This makes Uniswap dependent on other exchanges to determine the accurate market exchange rates for exchange contracts.

Founding Team

Hayden Adams
Creator
Twitter | LinkedIn

Hayden Adams is the Founder of Uniswap and Ethereum Programming Services. Adams specializes in smart contracts and dApp development. He was previously an engineer at Siemens. Adams holds a degree in Mechanical Engineering from Stony Brook University.

Competitors

0x

0x is a protocol for decentralized token exchange on the Ethereum blockchain. It uses smart contracts in standardizing a protocol for blockchain transactions to address main issues on decentralized exchanges like cost of transactions, speed, liquidity, and interoperability. Its token ZRX is used to pay trading fees and is also used to vote for governance matters and protocol improvements.

Bancor

Bancor is a token exchange platform that lets users convert between two tokens without intermediaries. It banks on smart contracts to facilitate smooth, frictionless transactions throughout the blockchain. Its protocol utilizes “connector modules” which are smart contracts that also hold balances of different ERC20 tokens. Bancor’s formula is designed to constantly recalculate prices between connector modules and smart contracts.

Kyber Network

Kyber is an exchange platform for crypto assets. It uses derivatives to minimize the risk of cryptocurrency price fluctuations. Kyber Network is governed mainly by smart contracts that allow users and managers exchange or convert tokens. Kyber also offers cross-chain payment services in crypto.

Leave a comment!

Your email address will not be published. Required fields are marked *

*

CAPTCHA


This site uses Akismet to reduce spam. Learn how your comment data is processed.