What:
In traditional exchanges, market makers (e.g. Optiver) match buyers and sellers. DEXs run on chain.
How (Automated Market Making):
- Smart Contracts take up the role of matching overlapping bids and asks. (Order Books)
- Users deposit pairs of tokens (Token A and Token B) into a smart contract pool.
- A pricing algorithm to model price is used: where:
- is the amount of Token A in pool
- is the amount of Token B in pool
- is a constant value
- Thus, if someone removes from the pool, ‘s value increases. We’ve automated supply and demand !
Risks:
- Front-Running / Sandwich Attacks: Since transactions are broadcast publicly before being mined,
Lending in DEXs
- To borrow, you lock up more value in collateral (e.g. ETH) than the amount you want to borrow (e.g. USDC).
- If the value of your collateral drops below a certain threshold, the smart contract automatically sells it to repay the loan.