---
# System prepended metadata

title: The Economics and Code Behind Uniswap

---

In the Ethereum world, ERC-20 token can represent a lot of things. For example, one DAI token maintained the price of 1 US dollar. An AAVE token represents a ballot to vote in the AAVE Lending Market Governance. These tokens beg the question that how people can trade them.

Uniswap, as the name suggested, essentially enables people to trade (or swap) between any pairs of ERC-20 tokens. Just like any exchanges, buyers and sellers can arrange a deal and get what they want.l However, unlike a traditionally exchange, where buyers, serllers and the exchange have to prove they are credible and negotiate, Uniswap uses a simple math equation to automatically achieve the same goal. 

Because of this desgin, the entities who interacts with Uniswap dosen't need to proved personal identity. They may even be bots. Thus, Uniswap is applauded for resisting financial censorship.  Moreover, the math behind Uniswap is so transparent and predictable that trading price on Uniswap always follows the market price. This assures traders that swaping is not very risky. For these two reasons, uniswap has been an very active exchange. Every day tokens worthy of millions of dallors are swaped on Uniswap.


![](https://hackmd.io/_uploads/Syk2MAG9h.png)



# Plan
## The Basic
1. Explain how liquidity provider interacts with Uniswap (add/remove liquity) with example, math equations and code 
2. Explain how traders interacts with Uniswap (swap) example, math equations and code 

Note: Use the v2/v3 visualizaiton and excel sheet

## Advanced Features
1. Explain why the uniswap v2/v3 is a good price oracle (arbitragers and TWAP)
2. Explain how Flash Swap works
3. The roadmap of V4


# The Secruity Audit of Compound AAVE 
1. Major vulnerabilities
2. Method and tools

code interpretation

read the code (understand the function)

oracle is hard to use


Uniswap core library 
solidity  ( demo replication )


# References
1. [A Brief History of Uniswap and Its Math](https://pandichef.medium.com/a-brief-history-of-uniswap-and-its-math-90443241c9b7)
2. [Formal Specification of Constant Product Market Maker Model ($X \times Y = K$) and Implementation](https://github.com/runtimeverification/verified-smart-contracts/blob/master/uniswap/x-y-k.pdf)
3. [Uniswap V2 Explained (Beginner Friendly)](https://medium.com/@chiqing/uniswap-v2-explained-beginner-friendly-b5d2cb64fe0f)
4. [How are LP token amounts calculated?](https://www.reddit.com/r/UniSwap/comments/i49dmk/how_are_lp_token_amounts_calculated/)
5. [An analysis of Uniswap markets](https://angeris.github.io/papers/uniswap_analysis.pdf)
6. [Uniswap v2 Core](https://uniswap.org/whitepaper.pdf)
7. [ERC-20 TOKEN STANDARD](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/)
8. [UNISWAP-V2 CONTRACT WALK-THROUGH](https://ethereum.org/en/developers/tutorials/uniswap-v2-annotated-code/)
9. [Uniswap V2 Audit Report](https://rskswap.com/audit.html)
10. [A Deep Dive Into the Uniswap V2 Protocol](https://betterprogramming.pub/uniswap-v2-in-depth-98075c826254)
11. 