What Is DeFi?
Decentralized finance means financial services such as trading, lending and saving built from smart contracts that anyone can use with a wallet, without a bank account.
Decentralized Exchanges and AMMs
A traditional exchange matches buyers and sellers. An automated market maker (AMM) uses a pool of two tokens and a formula to set the price.
Python Example of the Formula
90.91 75.76
- Buying a token removes it from the pool, which raises its price
- Bigger trades move the price more (slippage)
- Real DEXs also take a fee, paid to liquidity providers
Liquidity Providers and Impermanent Loss
- Anyone can deposit equal value of both tokens and earn trading fees
- If the price of the tokens moves apart, the provider can end with less value than just holding. This is called impermanent loss
Lending and Borrowing
- Lenders deposit tokens and earn interest
- Borrowers must lock more collateral than they borrow (over-collateralized), for example 150 percent
- If the collateral value falls too low, the position is liquidated automatically and a liquidator buys it at a discount
- Interest rates change with how much of the pool is borrowed
Stablecoins
| Type | How it stays near one dollar | Risk |
|---|---|---|
| Fiat-backed | Issuer holds cash and short-term assets | Trust in issuer and reserves |
| Crypto-backed | Over-collateralized crypto in smart contracts | Collateral crash, liquidation |
| Algorithmic | Code and incentives with little real backing | Can collapse. Several have |
Main Risks
- Smart contract bugs and hacks
- Oracle manipulation
- Liquidation in a market crash
- Rug pulls and fake tokens
- Regulation changes
- Impermanent loss and slippage
Practice
- Run the Python example with a bigger trade and watch the price impact
- Why must borrowers lock extra collateral?
- What is slippage?
Conclusion
DeFi runs trading, lending and stablecoins in smart contracts. AMMs price trades with a formula, loans are over-collateralized and every layer carries technical and market risk.

