DeFi, short for decentralized finance, refers to financial applications built on blockchain networks, mainly Ethereum. These apps let users lend, borrow, trade, and earn interest without a bank or broker. Instead of a company controlling the system, smart contracts do the work. Smart contracts are self-executing pieces of code that run when conditions are met. They hold funds, enforce rules, and settle trades automatically.
How DeFi works
A smart contract is like a vending machine. You put in a token, the contract checks the price, and sends you another token. No person behind the counter. The code is public, so anyone can verify it. The blockchain records every transaction, making the whole system transparent.
A key piece is the decentralized exchange, or DEX. Uniswap is the biggest example. Instead of matching buyers and sellers on an order book, Uniswap uses liquidity pools. Users deposit two tokens, say ETH and USDC, into a pool. Traders swap one for the other, paying a small fee that goes to the liquidity providers. The price is set by a formula: the product of the two token reserves stays constant. This is called the constant product formula, x * y = k. If you swap ETH for USDC, the ETH reserve goes up and the USDC reserve goes down, so the price of ETH in USDC drops. The larger the trade relative to the pool, the more the price moves. That price impact is slippage.
Real example: swapping on Uniswap
Say a pool holds 100 ETH and 200,000 USDC. The product k is 20 million (100 * 200,000). If someone wants to buy 10 ETH, they put in USDC. The new ETH reserve is 110. To keep k at 20 million, the USDC reserve must become 181,818 (20 million / 110). That means the trader had to put in 200,000 - 181,818 = 18,182 USDC. The effective price is 1,818 USDC per ETH. Before the trade, the price was 2,000 USDC per ETH. Slippage of about 9%.
Lending and borrowing protocols like Aave work differently. Users deposit assets into a pool and earn interest. Borrowers put up collateral, often more than they borrow, and pay a variable rate. If the collateral value drops, the protocol can liquidate the position. A liquidation means the borrower's collateral is sold to repay the loan, plus a penalty.
Risks you need to know
DeFi carries serious risks. Smart contracts can have bugs. Hackers have stolen billions from DeFi protocols. The code may be audited, but audits do not guarantee safety. The biggest loss was the Ronin bridge hack in 2022, where $620 million in crypto was taken.
Liquidation risk is real. If you borrow against ETH and ETH falls 20%, the protocol may seize your collateral. Some protocols let you borrow with 2x, 3x, or higher leverage. A small price move can wipe you out.
Stablecoins in DeFi are not always stable. DAI is a decentralized stablecoin backed by crypto collateral. If the collateral drops sharply, DAI can lose its peg. In March 2020, DAI traded above $1.10. In a panic, trust breaks.
Regulation is unclear. Governments are deciding how to treat DeFi. Some protocols have been sued. The US Securities and Exchange Commission has charged several DeFi projects with offering unregistered securities. New rules could restrict access or make some tokens illegal.
Impermanent loss is a risk for liquidity providers. When you put tokens in a pool, the ratio changes as trades happen. If the price of one token moves a lot compared to the other, you might have been better off just holding them. The loss is permanent only if you withdraw at that point.
Key terms explained
Total value locked, or TVL, is the amount of assets deposited in a DeFi protocol. It measures size and confidence. At its peak in late 2021, DeFi TVL exceeded $180 billion. Today it is around $50 billion, according to DeFi Llama.
Liquidity provider tokens, or LP tokens, represent your share of a pool. You can stake them in other protocols to earn extra yield. This stacking is called yield farming.
Gas fees are transaction costs on Ethereum. During busy times, a simple swap can cost $20 or more. That makes DeFi expensive for small trades. Layer 2 networks like Arbitrum and Optimism cut those fees.
Oracle manipulation is another attack category. Oracles feed outside prices into smart contracts. If an attacker can manipulate an oracle, they can trick a protocol into lending or trading at bad prices. Several attacks have used this technique.
Practical scenario: using a DeFi lending protocol
You have 10 ETH worth $20,000. You want to borrow $10,000 USDC to buy more ETH, but you cannot get a bank loan. On Aave, you deposit the 10 ETH. The protocol lets you borrow up to 75% of the value, or $15,000. You borrow $10,000. Your health factor is a metric. If ETH drops to $1,600 per coin, your collateral is worth $16,000. The loan is still $10,000. Your health factor falls. At a certain threshold, the protocol will liquidate enough ETH to repay the loan, plus a 5-10% penalty. If ETH drops to $1,200, you might lose nearly all your collateral.
DeFi is not a bank. There is no deposit insurance, no customer support, no guarantee. Users are responsible for their own security. Private keys must be kept safe. If you send tokens to the wrong address, they are gone forever.
A checklist before using DeFi
Understand the protocol's code and audit history. Look for audits from firms like Trail of Bits or OpenZeppelin.
Check TVL. A protocol with $100 million TVL is more battle tested than one with $1 million.
Beware of unsustainable yields. If a farm offers 1,000% APY, the risk is extreme.
Start small. Test with a small amount before committing larger sums.
Use a hardware wallet for cold storage when not actively trading.
Keep track of gas fees on Ethereum mainnet. Use Layer 2 if possible.
Never invest money you cannot afford to lose.
Trading and investing in DeFi carries substantial risk. Prices can go to zero. Hacks happen. Regulatory changes can make tokens worthless. There is no guarantee of profit.
Prepared with AlphaScala editorial tooling, examples, and risk-context checks against our education standards. General education only, not personalized financial advice.