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
You need to have the following background knowledge to understand Uniswap V2.
ERC4626 Vaults
ERC4626 is a tokenized vault standard that uses ERC20 tokens to represent shares of some other asset.
Read  
ERC3156 Flash Loans
Flash loans are loans between smart contracts that must be repaid in the same transaction. This article describes the ERC 3156 flash loan specification as well as the ways flash lenders and borrowers can be hacked.
Read