Decentralized Exchanges: Uniswap

Table of Contents

Uniswap is a protocol which allows for the exchange of ERC-20 tokens without a central authority for matching and clearing trades. Uniswap is built on the Ethereum blockchain, and therefore does not allow the exchange of cryptocurrencies which are not part of the Ethereum ecosystem (ERC-20 tokens). Because the protocol allows for peer-to-peer exchange, Uniswap is known as a Decentralized Exchange.

https://docs.uniswap.org/

Uniswap allows you to trade and make markets across Ethereum and Ethereum-based tokens.

1. Trade (Swap Tokens)

2. Automated Market Maker

Uniswap uses a constant product relationship between currency pair. The formula is:

\(x*y = k\)

where x and y are the reserve balances for currency x and y respectively, and k is a constant1. * denotes multiplication. The idea behind the equation is that the product of the reserve balances should be a constant.

Rearranging \(x*y = k\) to \(y=\frac{k}{x}\) and plotting we have:

k <- 50
x <- seq(1,10,0.1)
y <- k / x
png("curve_plot.png")
plot(y, type='l', lwd = 3, col = 4, xlab = "X", ylab = "Y")
dev.off()

curve_plot.png

Figure 1: Plot of x*y = k

2.1. Example

3. Order Book vs the Automated Market Maker

Markets in stock, futures, and options are generally made by using a limit order book. See this presentation if you need a review on limit order books. Order books are centralized mechanisms. A stock may trade across 20 limit order books, however each limit order book is reliant on the exchanges servers to maintain the book and match trades. All interaction involves the exchange's servers.

The Uniswap protocol, on the other hand, implements an Automated Market Maker, which is an Ethereum Smart Contract we which holds liquidity reserves against which participants can transact. That is, buy and sell orders execute against the pool of liquidity, and the relative size of the pools determine the relative price of each token.

Notably, because Uniswap is a protocol, there are no personal barriers to transacting. There is no age, income, etc requirements. Think of http.

3.2. Limit Order

To place what we know on stock markets as a limit order we can place what is termed a range order on Uniswap. See this answer.

4. Uniswap and the SEC

5. Languages Used

  • Solidity to implement the smart contracts.
  • Typescript as an interface.

Footnotes:

1

k is in practice increasing because there is a 0.30% fee for each trade which is added to k.

Author: Matt Brigida, Ph.D.

Created: 2022-03-04 Fri 21:55

Validate