top of page
uniswap v2 book

Uniswap V2 Book by RareSkills

The Uniswap V2 Book is a comprehensive and in-depth explanation of the codebase. We don’t just screenshot the code and walk you through line by line. Hopefully you can already read code! We motivate why it was written that way in the first place, what the possible alternatives are, and the motivation behind the decisions.

We wrote this book we’ve discovered a lot of engineers underestimate the depth of the protocol — it’s just xy = k, right? In reality, Uniswap V2 is full of brilliant engineering decisions that handle a significant amount of complexity with a small amount of code. It’s something every Solidity developer can learn from.

Furthermore, according to the DeFi Llama Fork Tracker, Uniswap V2 is the most forked DeFi protocol both in TLV (total locked value) and number of forks. The effort spent understanding the protocol will teach you a lot about hundreds of other DeFi applications.

For those who want practice, we’ve introduce problems from DamnVulnerableDeFi , Ethernaut, and Mr Steal Yo Crypto at stages where the reader will have gained enough knowledge to solve the problems minimal difficulty. Finally, we end with a guide to implement a clone of Uniswap V2 yourself, but with a modern twist since the original codebase is over four years old at this point.

Uniswap does not directly use ERC 4626 or ERC 3156. However, it is helpful to be familiar with those standards as Uniswap uses similar concepts. Any decent Solidity developer or auditor should be familiar with those standards anyway. So give those articles a read first if you don’t already know them. The Uniswap articles will assume knowledge of those standards.

Uniswap uses fixed point arithmetic to record prices, so the reader should familiarize themselves with that before they read the chapter on TWAP Oracles.

Pace yourself — cramming your brain with new concepts is not an effective way to learn. We recommend reading only one chapter per day, then reading the source file on your own without a guide to make sure everything makes sense.

Prerequisites

Chapter 1: ERC4626 Vaults

Chapter 2: ERC 3156 Flash Loans

Uniswap V2

Chapter 3: Architecture

Chapter 4: Price Impact of a Swap

Chapter 5: Swap Function

Chapter 6: Mint and Burn Functions

Chapter 7: Protocol mintFee

Chapter 8: TWAP Oracle

Chapter 9: UniswapV2Library

Chapter 10: Routers

Chapter 11: Building a Uniswap V2 Clone

bottom of page