DeFi Protocol Design: AMMs, Lending, and On-Chain Risk
This is Post 3 in the Blockchain Series. The previous post covered smart contracts and the EVM.
AMMs: Market Making in Code
The canonical constant-product AMM uses:
x * y = k
Where x and y are token reserves. A swap changes reserves and implied price. Deeper liquidity means lower slippage.
Lending Protocol Basics
Lending markets depend on over-collateralization:
- Supply collateral.
- Borrow below collateral factor.
- Liquidation triggers if health factor drops.
Critical parameters:
- Loan-to-value (LTV)
- Liquidation threshold
- Liquidation bonus
- Oracle heartbeat/staleness checks
Risk Surfaces
Top failure modes in DeFi:
- Smart contract bugs
- Oracle manipulation
- Liquidity crunches
- Governance capture
Engineering mitigations:
- Timelocks + multi-sig for upgrades
- Circuit breakers / pause guardians
- Formal verification for core math
- Real-time risk monitoring dashboards
References
- Uniswap v2 whitepaper: https://uniswap.org/whitepaper.pdf
- Aave docs: https://docs.aave.com/
- Chainlink docs (oracle architecture): https://docs.chain.link/
Best Books
- Campbell R. Harvey, Ashwin Ramachandran, Joey Santoro, DeFi and the Future of Finance.
- Andreas M. Antonopoulos, Mastering Bitcoin (for transaction and security foundations).
- Linda Xie et al., DeFi Developer Road Map (community resource/book-length guide).
Comments