Welcome to Project 7. We are building an Automated Market Maker (AMM). Before we write code, we need to understand the math that powers decentralized exchanges (DEXs) like Raydium or Orca.
Traditional exchanges (like Binance or Coinbase) use Order Books, matching buyers directly with sellers.
AMMs use Liquidity Pools—smart contract vaults containing two tokens (e.g., SOL and USDC). The price of the tokens is determined automatically by a mathematical formula:
$$ x * y = k $$
If a user buys Token A from the pool, the supply of x decreases. To keep k constant, the amount of y (Token B) must increase, meaning the user must deposit Token B, effectively setting a slippage curve.
Open-source source: https://github.com/solana-developers/developer-bootcamp-2024/tree/main/project-7-swap
Lesson Exam