DeFi basics: swaps, lending and yield, explained
How decentralised exchanges, lending markets and staking actually work, where DeFi yield comes from, and the risks to check before you deposit anything.
Updated 14 Sept 2026 · Intermediate · 4 min read
In short
- DeFi apps are smart contracts that hold funds and follow fixed rules. Nobody can freeze your account, and nobody can reverse your mistakes.
- Every yield has a source: trading fees, interest from borrowers, staking rewards or newly issued tokens. Find out which before you deposit.
- The main risks are contract bugs, admin keys, faulty price feeds and liquidation. Check who controls a contract, approve only what you deposit and start small.
What makes it decentralised
In traditional finance a company holds your money and applies its rules. In DeFi the money sits in smart contracts and the rules are the code: swap at this price, lend at this rate, liquidate below this ratio. You use it from your own wallet, usually by approving a token and then calling the contract, and anyone can read the code that will handle your funds.
Decentralised describes where the funds sit, not always who is in charge. Many protocols keep admin keys that can upgrade the contracts, change their settings or pause them, so who holds those keys is one of the first things to check; contract admin keys shows how.
Swapping on a decentralised exchange
Most decentralised exchanges (DEXs) use an automated market maker: a pool holding two tokens, with the price set by the ratio between them. In the classic design the pool keeps the product of its two balances constant, so every trade moves the price along a curve, and a larger trade moves it further.
x × y = kThe gap between the quoted price and the price you get is slippage, and your wallet asks you to set a tolerance for it. Set it too loose and a bot can trade just before and after you, pushing the price against you and keeping the difference, an attack known as a sandwich. A tight tolerance, for example 0.5% on a busy pair, limits the damage.
Providing liquidity
The tokens in those pools come from liquidity providers, who deposit both tokens and earn a share of the trading fees. The catch is impermanent loss. When one token’s price moves, the pool effectively sells the one that is rising and buys the one that is falling, so you end up with less value than if you had simply held the two tokens.
loss versus holding = 2√r ÷ (1 + r) − 1Trading fees may outweigh that loss, or may not. It is called impermanent because it shrinks back to nothing if prices return to where they were when you deposited.
Lending and borrowing
Lending markets such as Aave and Compound pool deposits and lend them out at rates set by supply and demand. Lenders earn interest. Borrowers must first deposit collateral worth more than their loan, because the protocol has no way to chase anyone for repayment.
If the collateral’s value falls too far relative to the loan, the position can be liquidated: anyone may repay part of the debt and take some of the collateral at a discount. Aave expresses the margin as a health factor, and below 1 liquidation can begin. Someone who deposits a volatile coin and borrows stablecoins against it can be liquidated by one sharp move while they sleep.
Staking and yield
Staking locks tokens to help secure a proof-of-stake network. Liquid staking gives you a token that represents your stake and can be used elsewhere, such as Lido’s stETH for staked ether, and it adds the provider’s contracts and node operators to the list of things you are trusting.
Advertised yields are quoted as APR or APY and can change or stop at any time. Our staking rewards calculator converts one into the other and shows what a rate compounds to. A yield far above what fees, interest or staking can pay usually comes from new token issuance, which is worth only what buyers will pay for those tokens, or from a risk nobody has told you about.
Before you deposit
- Reach the app from its official site, not from an advert or a message, and check the contract address it asks you to approve.
- Look up who controls the contracts in the contract admin inspector: a single key, a multisig, or a timelock that delays changes so users can react.
- Approve only the amount you are depositing. Token approvals explains why, and how to revoke approvals later.
- Count the transactions. Approving, depositing and withdrawing are separate, and on Ethereum mainnet gas can swallow a small position; the gas tracker shows current costs on each chain.
- Start with an amount you could lose, and do not add more just because the yield looks attractive.
This guide explains how DeFi works. It is not financial advice.