Lesson 4 — DeFi basics: decentralized exchanges, loans and approvals

Lesson 4 of 10 · 3 min

How decentralized exchanges (AMMs), overcollateralized loans and token approvals work, and the risks of DeFi for those just starting out.

DeFi (decentralized finance) are financial applications that work with smart contracts instead of companies: currency swaps, loans or savings, accessible to anyone with a wallet. There is no account or form, but there is also no customer support or guarantee: a mistake, a faulty contract or a poorly given approval can cost you everything you put in there. In this lesson you see the three basic building blocks and their risks.

Decentralized exchanges and AMMs

In a traditional exchange, buyers and sellers meet in an order book. In most decentralized exchanges (DEX), swaps are against a liquidity pool: a contract with two currencies, for example ETH and USDC, deposited by other users (the liquidity providers). The price comes from a formula — the best-known model is the constant product: x × y = k.

How it is calculated, in a simplified way: in a pool with 100 ETH and 300,000 USDC, k = 30,000,000. If someone withdraws 1 ETH, the pool is left with 99 ETH and needs to have 30,000,000 ÷ 99 ≈ 303,030 USDC. That is, that ETH costs about 3,030 USDC, more than the average price of 3,000: this is the price impact, which grows with the size of the swap relative to the pool. That is why the DEX asks you for a «slippage» tolerance. Liquidity providers receive fees, but suffer impermanent loss — try the Impermanent Loss Calculator to see the effect; you will study it in depth in the Advanced course.

Overcollateralized loans

On DeFi lending platforms, you deposit one currency as collateral and borrow another. Since no one knows who you are, the loan is overcollateralized: to borrow 1,000 USDC you may need to deposit 1,500 in ETH. If the value of the collateral falls below a limit, a contract automatically sells part of it (liquidation), with a penalty.

Hypothetical example: you deposit ETH worth 1,500 and borrow 1,000. If the liquidation limit is 80%, liquidation begins when the collateral is worth less than 1,250 (1,000 ÷ 0.8), that is, after an approximately 17% drop in ETH.

Token approvals: the hidden risk

Before a DEX can swap your tokens, you must give it an approval (approve): you authorize the contract to spend a certain token from your wallet. Many applications ask for «unlimited» approval. If that contract is malicious or gets hacked, it can take all the approved tokens, even months later.

Good practices:

  • Approve only the amount you are going to use, when the wallet allows it.
  • Review and revoke old approvals with well-known revocation tools.
  • Read what the wallet shows before signing: «Allow it to spend all your USDC?» is a serious request.

Before interacting with an unknown token, analyze it at Analyze a token by contract address: you see signs such as hidden taxes on sale, the possibility of creating unlimited tokens or sale blocks.

How big is DeFi?

The most used indicator is TVL (total value locked): how much is deposited in the contracts. Check DeFi TVL by network and protocol to see which networks and applications concentrate the most value. A high TVL does not guarantee security, but protocols that have been operating for years, with public audits and a lot of value deposited, have already gone through more tests than one launched last week.

Costs of using DeFi

Each interaction pays gas: approving, swapping, depositing and withdrawing. On an expensive network, four operations can cost more than the expected gain. Calculate beforehand with the Fee (gas) Calculator. The article What is DeFi? gives the overview and What is a crypto airdrop? shows the most common scam linked to approvals.

Summary

  • DEXes swap against liquidity pools; the price comes from a formula and large swaps have price impact.
  • DeFi loans require collateral higher than the amount requested and liquidate automatically.
  • Unlimited approvals are a risk: approve only what you need and revoke what you do not use.
  • TVL measures size, not security; each operation pays gas.

In the next lesson you will see staking and how to compare yields without falling for misleading numbers.

Frequently asked questions

Is DeFi regulated by MiCA?

MiCA applies mainly to identifiable issuers and service providers. Fully decentralized services have largely remained outside its scope for now, which means less protection for the user.

What is slippage?

It is the difference between the expected price of a swap and the actual price, caused by the impact of the swap on the pool or by market movements in the meantime.

How do I revoke a token approval?

Use a well-known revocation tool or the network explorer, connect your wallet, find the approval and send a transaction that sets it to zero. That transaction pays gas.

Practise with the tools

  • DeFi TVL by chain and protocol — Total value locked (TVL) on the main DeFi chains and protocols, in US$, with the 1- and 7-day change when DefiLlama sends it. The source is always visible.
  • Check a token by its contract address — Paste a token address (Ethereum, BNB Chain, Base, Arbitrum, Polygon or Solana) and see in seconds whether it shows scam signs, hidden taxes and enough liquidity.
  • Impermanent loss calculator — Estimate the difference between placing a pair in a constant-product liquidity pool (x·y=k) and simply holding both coins. Optional live prices from CoinGecko. We do not recommend pools.
  • Fee (gas) calculator — Estimate a transaction's cost from current network fees, in US$ and in €.

Read next

Sources

Educational content. Not financial advice or a recommendation to buy or sell.