Uniswap V3 Development Book
This book will teach how to develop an advanced decentralized application! Specifically, we'll be building a clone of Uniswap V3, which is a decentralized exchange.
Why Uniswap?
- It implements a very simple mathematical concept,
x * y = k
, which still makes it very powerful. - It's an advanced application that has a thick layer of engineering on top of the simple formula.
- It's permissionless and battle-tested. Learning from an application that's been running in production for several years and handling billions of dollars will make you a better developer.
What we'll build
We'll build a full clone of Uniswap V3. It won't be an exact copy and it won't be production-ready because we'll do something in our own way and we'll definitely introduce multiple bugs. So, don't deploy this to the mainnet!
While our focus will primarily be on smart contracts, we'll also build a front-end application as a side hustle.
The full code of what we'll build is stored in a separate repository:
https://github.com/Jeiwan/uniswapv3-code
You can read this book at:
Questions?
Each milestone has its own section in the GitHub Discussions. Don't hesitate to ask questions about anything that's not clear in the book!
Table of Contents
-
Milestone 0. Introduction
- Introduction to markets
- Constant Function Market Makers
- Uniswap V3
- Development Environment
- What We'll Build
-
Milestone 1. First Swap
- Introduction
- Calculating Liquidity
- Providing Liquidity
- First Swap
- Manager Contract
- Deployment
- User Interface
-
Milestone 2. Second Swap
- Introduction
- Output Amount Calculation
- Math in Solidity
- Tick Bitmap Index
- Generalize Minting
- Generalize Swapping
- Quoter Contract
- User Interface
-
Milestone 3. Cross-tick Swaps
- Introduction
- Different Price Ranges
- Cross-Tick Swaps
- Slippage Protection
- Liquidity Calculation
- A Little Bit More on Fixed-point Numbers
- Flash Loans
- User Interface
-
Milestone 4. Multi-pool Swaps
- Introduction
- Factory Contract
- Swap Path
- Multi-pool Swaps
- User Interface
- Tick Rounding
-
Milestone 5. Fees and Price Oracle
- Introduction
- Swap Fees
- Flash Loan Fees
- Protocol Fees
- Price Oracle
- User Interface
-
Milestone 6: NFT positions
- Introduction
- ERC721 Overview
- NFT Manager
- NFT Renderer
Running locally
To run the book locally:
- Install Hugo.
- Clone the repo:
$ git clone https://github.com/Jeiwan/uniswapv3-book $ cd uniswapv3-book
- Run:
$ hugo server -D
- Visit http://localhost:1313/ (or whatever URL the previous command outputs!)
TODO
- Milestone 2, Tick Bitmap Index: what happens when there are no ticks? Will it keep looping until it reaches max/min tick?
- Milestone 3: liquidity management
- Somewhere: clarify that sqrtP has better precision than ticks and that current price is never computed from current tick.
- Add dark mode (with images)
- Make a PDF
- Add Next/Back buttons to the bottom of pages.
- Ideas for Extras:
- Tick math implementation. Explanation of the math in TickMath contract.
- Breakdown of the alpha-router: https://github.com/Uniswap/swap-router-contracts