- Check prerequisites
- Install tools
- Watch videos on Cyfrin Updraft
- Do exercises under topics
- Ask questions on GitHub discussions
- Advanced Solidity developer
- Experience with Foundry
- Knowledge of Curve V1
- Basic understanding of DeFi
- Python (optional)
- Foundry
- Python / Jupyter lab (optional)
Check out the videos on Cyfrin Updraft for each lesson.
This section explains what the course will teach, who the course is for and how to do the exercises
- Course intro
- Lead instructor
- Setup repo
This section explains the math of Curve V2's AMM, how liquidity is concentrated and how the AMM decides to repeg the pool's liquidity at a different price.
- Curve V2 intro
- AMM equation
- Graph Curve V2
- Python code concentrated liquidity
- Graph Gamma
- Recap
- Price scale
- Price scale and concentrated liquidity
- Python code (optional) swap with price scale
- Price scale repeg
- Graph AMM with price scale
- Graph review of constant product liquidity
- Graph Quantifying pool value
- Math pool value
- Graph repegging loss part 1
- Graph repegging loss part 2
Here you will learn about what functions to call to interact with the AMM. You will also learn about how state variables such as
A
,gamma
andprice_scale
are stored.
- Contract overview
- Code walkthrough packed state variables
- Code walkthrough price scale
- Code walkthrough
A
- Code walkthrough
ramp_A_gamma
- Code walkthrough
get_virtual_price
- Exercise transformed balances
- Solution transformed balances
This section explains how the function
exchange
works, how to call to swap tokens, followed by exercises to simulate a swap.
- Contract call
exchange
- Code outline
exchange
- Code walkthrough
exchange
- Code walkthrough
_fee
- Graph dynamic fee
- Exercise 1
get_dy
- Solution 1
get_dy
- Exercise 2
exchange
- Solution 2
exchange
This section explains how the function
add_liquidity
is implemented, how to add liquidity, followed by a exercise.
- Contract call
add_liquidity
- Code outline
add_liquidity
- Code walkthrough
add_liquidity
- Code walkthrough
calc_token_fee
- Exercise
add_liquidity
- Solution
add_liquidity
There are 2 ways to remove liquidity (
remove_liquidity
andremove_liquidity_one_coin
). This section will explain how both functions work, followed by exercises.
- Contract call
remove_liquidity
- Code outline
remove_liquidity
- Code walkthrough
remove_liquidity
- Exercise 1
remove_liquidity
- Solution 1
remove_liquidity
- Contract call
remove_liquidity_one_coin
- Code outline
remove_liquidity_one_coin
- Code walkthrough
remove_liquidity_one_coin
- Code walkthrough
calc_withdraw_one_coin
- Exercise 2
remove_liquidity_one_coin
- Solution 2
remove_liquidity_one_coin
Curve V2 has an internal price oracle that decides to re-concentrate liquidity when the internal price and the current price deviates significantly. This section explains the math of how the internal price oracle track prices the function that is responsible for repegging (
tweak_price
).
- Math EMA [regular interval](./excalidraw/amm/curve-v2/curve-v2-ema-regular-interval.png]
- Python example regular interval
- Math EMA [irregular interval](./excalidraw/amm/curve-v2/curve-v2-ema-irregular-interval.png]
- Graph half life
- Python example irregular interval
- Difference between math and code
- Code walkthrough
price_oracle
- When is
tweak_price
called - Code outline
tweak_price
- Code walkthrough
tweak_price
- How does
xcp_profit
track profit and loss? - When is
claim_admin_fees
called - Code walkthrough
claim_admin_fees
Footnote on how the spot price of AMM such as constant sum, constant product, Curve V1 and V2 can be calculated by a mathematical technique called implicit differentiation.
- Curve
- Curve resources
- Docs
- Whitepaper
- USDC/WBTC/ETH
- GitHub
- Tricrypto optimization
- Curve magic
- Understanding Crypto Pools
- Repegging of Curve v2 CryptoSwap|Curve|code review • 0xreviews.xyz
- Deep Dive: Curve v2 Parameters
- Imbalance fee
- Implicit function
- Implicit differentiation
- https://x.com/Kurt_M_Barry/status/1404496489703952384?s=20&t=5sGVQL4HbLrwzA_ALxivhA