DeFi Fundamentals

Intermediate13 min readLesson 14 of 166

Decentralized Finance, or DeFi, rebuilds the core machinery of banking - lending, borrowing, trading, earning yield - as open-source code running on public blockchains, with no bank, broker, or custodian in the middle. Instead of trusting an institution, you trust audited smart contracts and the economic incentives that hold them together. By 2021 DeFi peaked above $180B in total value locked; today it remains a multi-hundred-billion-dollar arena where a trader can swap, lend, and leverage 24/7. This lesson takes you from first principles to the mechanics that actually move money on-chain.

What DeFi Actually Is

Traditional finance (TradFi) runs on trusted intermediaries. When you swap currencies, a bank holds both sides; when you borrow, a lender underwrites you; when you trade a stock, an exchange and a clearinghouse settle the deal. Each intermediary takes a fee, imposes hours, demands identity, and can freeze or reverse your funds. DeFi replaces those intermediaries with smart contracts - self-executing programs deployed on a blockchain like Ethereum or Solana. The contract holds the assets, enforces the rules, and settles instantly, with the same code applying identically to everyone.

Three properties define genuine DeFi. It is permissionless: anyone with a wallet can interact without sign-up or approval. It is non-custodial: assets stay in contracts you can exit at any time, not in a company's account. And it is composable: protocols snap together like Lego, so the output of one (say, a yield-bearing token) becomes the input to another. This composability is why DeFi is sometimes called 'money Legos' - a single transaction can swap, deposit, and borrow across three protocols atomically.

The distinction that trips up newcomers is CeFi versus DeFi. Centralized exchanges like Binance, Coinbase, or the now-collapsed FTX are CeFi: they custody your coins and run an internal ledger. DeFi never holds your keys - you sign each action from your own wallet. The 2022 FTX collapse, where customer funds were misappropriated and over $8B went missing, is the canonical lesson in why 'not your keys, not your coins' matters. DeFi's contracts cannot quietly lend out your deposits the way FTX did, because the rules are public and the funds are on-chain.

CeFi vs DeFi
CeFi (Binance, Coinbase, FTX)
  • Company custodies your assets
  • Internal off-chain ledger
  • KYC and account approval required
  • Can freeze, reverse, or rehypothecate
  • Trust the institution
DeFi (Uniswap, Aave, Compound)
  • Self-custody via your own wallet
  • Public on-chain settlement
  • Permissionless - any wallet
  • Code enforces rules, no freezes
  • Trust the audited contract

The DeFi Stack: Building Blocks of On-Chain Finance

DeFi is layered. At the base sits a settlement layer - a Layer 1 blockchain like Ethereum, Solana, or an Ethereum Layer 2 (Arbitrum, Base, Optimism) that provides consensus, finality, and a native asset (ETH, SOL) to pay gas. On top of that lives the asset layer: native coins, wrapped assets (WBTC brings Bitcoin onto Ethereum), and crucially stablecoins like USDC and USDT that give traders a dollar-denominated unit of account on-chain.

Above assets sits the protocol layer - the applications. Decentralized exchanges (DEXs) like Uniswap and Curve handle trading. Lending markets like Aave and Compound handle credit. Derivatives venues like dYdX and GMX handle perpetual futures. Liquid staking protocols like Lido turn staked ETH into tradeable stETH. Finally, the aggregation layer (1inch, Yearn) sits on top, routing across protocols to find the best price or yield. Understanding which layer you are touching tells you where your risk lives.

The DeFi Technology Stack
Aggregation (1inch, Yearn)
best price & yield routing
Protocols (Uniswap, Aave, GMX)
DEX, lending, derivatives
Asset layer (USDC, WBTC, stETH)
stablecoins & wrapped assets
Settlement L1/L2 (Ethereum, Solana, Base)
consensus, gas, finality
Gas is the toll you always pay

Every DeFi action is a transaction that costs gas in the chain's native token. On Ethereum mainnet a complex swap can cost $5-$50 in busy periods; on Solana or an L2 it is often under a cent. Small trades that make sense on Solana can be wiped out by gas on Ethereum mainnet.

DEXs and Automated Market Makers

The breakthrough that made on-chain trading practical was the Automated Market Maker (AMM). A traditional exchange uses an order book matching buyers and sellers - hard to run on-chain because every order placement and cancellation would cost gas. An AMM instead uses a liquidity pool: a smart contract holding a reserve of two tokens, say ETH and USDC. Anyone can deposit both tokens to become a liquidity provider (LP) and earn a share of trading fees, typically 0.05% to 1% per swap.

Prices are set by a mathematical formula, not by matching orders. Uniswap v2 popularized the constant product formula: x times y equals k, where x and y are the two reserves and k is constant. If a pool holds 100 ETH and 300,000 USDC, k is 30,000,000. A trader buying ETH removes ETH and adds USDC; because the product must stay constant, the price of ETH rises as the pool's ETH shrinks. Large trades move the price more - this is slippage. The deeper the liquidity, the less a given trade moves the price.

Curve refined this for like-valued assets (USDC/USDT, stETH/ETH) with a 'stableswap' invariant that keeps slippage near zero around the peg, which is why Curve dominates stablecoin trading. Uniswap v3 introduced 'concentrated liquidity,' letting LPs supply capital only within a chosen price band for far higher fee efficiency. A trader uses DEXs to swap any token instantly, but should always check expected slippage and set a slippage tolerance to avoid being sandwiched by MEV bots.

ProtocolTypeWhat it doesNative model
UniswapDEX / AMMSwap any ERC-20 tokenConstant product (v2), concentrated liquidity (v3)
CurveDEX / AMMLow-slippage stablecoin swapsStableswap invariant
AaveLendingBorrow against collateralOver-collateralized pools, variable rates
CompoundLendingAlgorithmic money marketsUtilization-based interest
LidoLiquid stakingStake ETH, receive stETHTokenized staking position
GMXDerivativesPerpetual futures, leverageShared liquidity pool (GLP)

Lending, Borrowing, and Over-Collateralization

On-chain lending works without credit scores by demanding collateral worth more than the loan. On Aave or Compound, a lender deposits an asset (say USDC) into a pool and immediately starts earning interest paid by borrowers. A borrower deposits collateral (say ETH) and can borrow up to a limit set by that asset's loan-to-value ratio (LTV) - perhaps 80% for ETH. Deposit $10,000 of ETH and you might borrow up to $8,000 of stablecoins, all enforced by code.

Because the loan is over-collateralized, the protocol does not need to trust the borrower. If the collateral value falls so that the loan approaches the liquidation threshold, anyone can trigger a liquidation: a liquidator repays part of the debt and seizes the borrower's collateral at a discount (the liquidation bonus, often 5-15%). This keeps every pool solvent. Interest rates are algorithmic, driven by utilization - the share of pooled funds currently borrowed. As utilization rises, rates climb to attract more deposits and discourage borrowing.

  • Supply APY: what you earn for lending into a pool, paid by borrowers.
  • Borrow APR: what you pay to borrow; rises with pool utilization.
  • LTV / collateral factor: max you can borrow against a given asset.
  • Liquidation threshold: collateral ratio at which your position can be seized.
  • Health factor: a single number (above 1 = safe) summarizing how close you are to liquidation.

Traders use lending in three classic ways. First, leverage: borrow stablecoins against ETH, buy more ETH, and amplify a long. Second, shorting: borrow an asset you think will fall, sell it, and buy it back cheaper. Third, liquidity without selling: borrow against your holdings to access cash while keeping your spot exposure (and deferring a taxable sale). Each is powerful and each can be liquidated against you.

Liquidation can wipe you out fast

In a sharp drawdown, collateral falls and your health factor can cross the liquidation threshold in minutes, automatically selling your collateral at a discount plus penalty. On 12 March 2020 ('Black Thursday') ETH fell ~50% in a day and MakerDAO liquidations were so chaotic that some collateral was auctioned for $0, leaving the system undercollateralized. Never borrow near your max LTV, monitor your health factor, and keep a buffer.

Stablecoins, Yield, and Where Returns Come From

Stablecoins are DeFi's lifeblood - the dollar rail that lets traders price, settle, and park value without leaving the chain. They come in three flavors. Fiat-backed (USDC, USDT) hold real dollars and Treasuries in reserve and are redeemable 1:1; they are the most trusted but custodial and centrally issued. Crypto-collateralized (DAI) are minted by locking surplus crypto collateral on-chain - decentralized but capital-inefficient. Algorithmic stablecoins try to hold the peg purely through code and incentives, with no hard backing.

That third category is where DeFi's most famous disaster occurred. In May 2022 Terra's UST, an algorithmic stablecoin that maintained its peg by minting and burning the sister token LUNA, entered a death spiral. As UST slipped below $1, arbitrage minted ever more LUNA, hyperinflating its supply from ~350M to trillions of tokens within days. About $40B+ in value evaporated, dragging the whole market down. The lesson: a stablecoin with no real collateral is only as stable as the market's confidence, and confidence is reflexive.

Yield in DeFi is real but must be sourced. Legitimate yield comes from trading fees (as an LP), borrowing interest (as a lender), staking rewards (securing a chain), or liquidity-mining incentives (protocols paying their own token to bootstrap usage). The danger is yield that is purely emissions of an inflating token with no underlying demand - high headline APY, falling token price, negative real return. Always ask: who is paying this yield, and why?

Stablecoin market share by type (illustrative)
  • USDT (fiat-backed)62%
  • USDC (fiat-backed)24%
  • DAI (crypto-collateralized)7%
  • Other / algorithmic7%

How a Transaction Flows Through DeFi

Walking through a single trade makes the abstractions concrete. Suppose you hold ETH and want a leveraged long. The flow below shows what actually happens on-chain, each step a signed transaction (or, with newer wallets, a bundled set) settling on the blockchain. Notice there is no broker, no settlement delay, and no counterparty other than the contracts themselves.

A leveraged long, end to end
Connect wallet
sign in with keys
Deposit ETH
collateral to Aave
Borrow USDC
up to your LTV
Swap on Uniswap
USDC into more ETH
Monitor health
watch liquidation

Behind that flow sits the network of participants that keeps DeFi running. Liquidity providers supply the capital pools trade against. Lenders and borrowers create the credit market. Validators or miners on the base chain order and finalize transactions. Liquidators enforce solvency. Arbitrageurs and MEV searchers keep prices aligned across venues - though their activity is also the source of sandwich attacks and front-running. Oracles like Chainlink feed real-world prices into contracts so that liquidations and pricing use accurate data; a manipulated oracle is a classic attack vector.

Participants in a DeFi ecosystem
LiquiditBorrowerLiquidatOraclesValidatoArbitragDeFi Proto

For a trader, reading the chart is still half the job - even on-chain, you are trading the same price action. Below is how you might frame an ETH long with on-chain leverage: enter near support, target a prior resistance, and place a mental stop that also keeps you above your liquidation price. The difference from a CEX is that your 'margin call' is a public, automated liquidation rather than a broker's phone call.

ResistanceEntrySupportStopHexaTrades
Framing an on-chain ETH long: enter near support, target prior resistance, keep your stop above liquidation

The Risks: Smart Contracts, Oracles, and Human Error

DeFi removes counterparty risk but introduces technical risk. Smart contract risk is the big one: a bug in the code can let an attacker drain a pool. The 2016 DAO hack drained ~3.6M ETH and forced the Ethereum hard fork that created ETH and ETC. Re-entrancy bugs, flash-loan exploits, and logic errors have collectively cost DeFi billions. The defense is to favor protocols that are battle-tested, heavily audited, and have run with large value for years - though even audits do not guarantee safety.

Oracle risk arises because contracts cannot see outside the chain on their own. If a protocol relies on a thin DEX pool for its price feed, an attacker can use a flash loan to distort that price, trick the protocol into mispricing collateral, and walk away with funds. Robust protocols use decentralized oracle networks (Chainlink) and time-weighted averages to resist manipulation. Beyond code, there is governance risk (a malicious or captured token vote), bridge risk (cross-chain bridges have been the single largest source of hacks), and plain user error - sending to the wrong address, approving a malicious contract, or signing a draining transaction.

  • Smart contract bugs: re-entrancy, integer errors, flawed logic.
  • Oracle manipulation: flash-loan-driven price distortion.
  • Impermanent loss: LP value lags simply holding when prices diverge.
  • Bridge exploits: the largest category of DeFi losses historically.
  • Rug pulls & scams: anonymous teams draining their own protocols.
  • Approval risk: unlimited token allowances a malicious contract can exploit.
A practical safety checklist

Use a separate wallet for DeFi, revoke stale token approvals (revoke.cash), verify contract addresses from official sources, start with small amounts, stick to audited blue-chip protocols, and never chase a 10,000% APY - that number is almost always emissions or a trap.

How a Trader Actually Uses DeFi

For an active trader, DeFi is a toolkit rather than a destination. You might park stablecoins in Aave to earn a real, lending-driven yield between setups instead of letting cash sit idle. You can short an alt that has no listing on your CEX by borrowing and selling it on-chain. You can access perpetual futures on GMX or dYdX with no KYC and 24/7 uptime. You can provide concentrated liquidity around a range you expect price to chop in, earning fees from the volatility you would otherwise just watch.

DeFi also surfaces information a CEX hides. On-chain data lets you watch stablecoin flows onto exchanges (often a precursor to buying), track large wallet movements, and see lending utilization spike before volatility. The flip side is execution: you must account for gas, slippage, MEV, and the irreversibility of a wrong transaction. A disciplined DeFi trader treats every approval and every signature with the same caution a TradFi desk treats wire instructions - because there is no chargeback.

The macro arc matters too. Spot Bitcoin ETF approvals in January 2024 and the April 2024 halving pulled institutional attention toward crypto generally, and a chunk of that liquidity reaches DeFi through stablecoins, tokenized Treasuries, and liquid staking. As regulation matures, expect more of TradFi's volume to settle on-chain. The trader who already understands AMMs, collateralized lending, and on-chain risk is positioned to operate in that world fluently while others are still asking what a liquidity pool is.

Key takeaways

  • DeFi = permissionless, non-custodial, composable finance run by smart contracts - no intermediary holds your funds.
  • AMMs price trades by formula (Uniswap v2: x*y=k); deeper liquidity means less slippage; large trades move price.
  • Lending is over-collateralized: watch your health factor (>1 safe) and LTV to avoid automated liquidation plus penalty.
  • Stablecoins: fiat-backed (USDC/USDT) > crypto-collateralized (DAI) > algorithmic; UST's 2022 collapse proved algo pegs are reflexive.
  • Real yield comes from fees, interest, or staking; sky-high APY is usually inflating token emissions.
  • Top risks: smart-contract bugs, oracle manipulation, bridge hacks, impermanent loss, and your own approvals - use a burner wallet and stick to audited blue-chips.

Practical exercises

  1. 1Connect a self-custody wallet to a testnet (e.g. Sepolia) and execute a token swap on a DEX, noting the gas cost and the slippage shown before you confirm.
  2. 2On Aave's interface, simulate depositing ETH and borrowing USDC. Record the LTV, liquidation threshold, and resulting health factor, then model what ETH price would trigger liquidation.
  3. 3Pick three protocols offering yield on a stablecoin and identify the source of each yield (trading fees, lending interest, or token emissions). Rank them by how sustainable the yield is.
  4. 4Use a tool like revoke.cash to inspect and revoke any open token approvals on a wallet, and write down why unlimited approvals are a risk.

Test your knowledge

1. What does it mean that DeFi is 'non-custodial'?

2. In Uniswap v2's constant product formula x*y=k, what happens to the price of a token when a trader buys a large amount of it from the pool?

3. Why can DeFi lending protocols lend without credit checks?

4. What was the core flaw exposed by the May 2022 Terra/UST collapse?

5. Which risk is specifically caused by a protocol relying on a thin or manipulable price source?

Frequently asked questions

No - that is the whole point. You connect a self-custody wallet (MetaMask, Phantom, etc.) and sign each action. The protocol never holds your keys. Anyone asking for your seed phrase is scamming you.

Ready to apply this with real-time signals and a 40,000+ trader community?