Learning pathAdvancedStep 12 of 15
DeFi: decentralized exchanges, lending and their risks
Finance without intermediaries, managed by smart contracts. How automated exchanges and collateralized loans work, and what can go wrong.

Decentralized finance (DeFi) consists of protocols implementing exchange, lending and derivatives through smart contracts: without operator custody, with atomic settlement (everything happens in one transaction or not at all), and with composability: protocols can call one another, also linking their risks.
The essentials
- AMMs set prices using liquidity pools and an invariant function; trading has price impact, and providing liquidity exposes you to impermanent loss.
- Lending is overcollateralized: your position is liquidated if its health factor falls below 1.
- Price oracles, administrative permissions and approval signatures are the most common attack surfaces.
- High yields almost always reflect contract, liquidity or issuance risk.
Automated market makers (AMMs)
In a constant-product AMM, the pool satisfies x · y = k: reserves of the two tokens (x and y) adjust to keep their product constant. The marginal price is the reserve ratio, so a large order moves the price: this is price impact, while slippage is the difference between the expected and executed price.
- Concentrated liquidity: in designs such as Uniswap v3, providers choose a price range. This improves capital efficiency, but outside the range they stop earning fees and hold only one asset.
- Impermanent loss (IL): the difference between your pool position's value and simply holding the tokens. If the price ratio changes by a factor r, IL = 2√r / (1 + r) − 1. With r = 2 (one doubles relative to the other), it is around −5.7%. Fees earned may or may not offset it.
- MEV (value extracted through ordering): whoever orders transactions can front-run or interleave trades. In a sandwich attack, attackers buy before your order and sell afterward, exploiting your slippage. Tight slippage limits and private submission channels help mitigate this.
Overcollateralized lending
You deposit collateral and borrow less value than you deposited. Each asset has a liquidation threshold (LT). The health factor is (collateral × LT) ÷ debt; below 1, anyone can liquidate part of your debt and take collateral with a bonus (around 5–10%) paid from your position.
Example: US$1,000 in ETH collateral, US$600 borrowed, LT of 80%. Health factor = 1,000 × 0.8 ÷ 600 = 1.33. Liquidation begins when collateral is worth US$750: a 25% fall. Rates follow a utilization curve: they rise sharply when nearly all pool funds are borrowed, encouraging repayment.
- Flash loans: uncollateralized credit that must be repaid within the same transaction; otherwise the entire transaction reverts. They support arbitrage and refinancing, but can also manipulate prices within a single block.
Oracles
Contracts cannot see outside prices: they receive them from an oracle. If a protocol uses a low-liquidity pool's spot price, a flash loan can distort it. Defenses include decentralized multisource oracles, time-weighted average prices (TWAP) and variation caps. Also check update frequency and handling of stale data.
Contract and governance risks
- Code vulnerabilities: reentrancy (a contract is called again before updating its state), rounding errors and missing validations. Audits reduce risk but do not eliminate it.
- Administration keys and proxies: many contracts are upgradeable through a proxy. Whoever controls the administration key can change the logic. Check for multisignature controls, timelocks and signer identities.
- Governance: concentrated voting power or borrowed governance tokens can approve hostile proposals.
- Token permissions: unlimited approval (allowance) lets a contract move your tokens. Use limited amounts and revoke old approvals.
- Contagion: composability propagates the failure of collateral assets or stablecoins to dependent protocols.
Before using a protocol
- Read who controls administration keys and how long they must wait before changing code.
- Check that source code is verified on the explorer and recent audits exist with findings resolved.
- Identify the yield's source: actual fees or interest, or token issuance.
- Identify the oracle and liquidity of assets used.
- Test with an amount you can afford to lose and review permissions you sign.
Brief technical glossary
- AMM: a mechanism setting prices through liquidity pools and a formula, without an order book.
- Health factor: collateral adjusted by its threshold divided by debt; below 1, liquidation occurs.
- TWAP: average price over a time window, harder to manipulate than a spot price.
- Upgradeable proxy: a pattern separating a contract's address from its logic so the latter can change.
- MEV: value earned by whoever orders or inserts transactions in a block.
Next step: staking and how a proof-of-stake network is secured.
Tags
This is information, not financial advice. Before deciding, compare sources and consider your own situation.
