What DeFi Is: Smart Contracts That Call Each Other
DeFi is a set of smart contracts for lending, trading and stablecoins that call each other. How the pieces fit, and where composability turns into risk.
DeFi, short for decentralized finance, is a set of smart contracts deployed on a public blockchain that let people lend, borrow, trade and mint tokens without a company holding the assets in between. The contracts hold the funds and enforce the rules. A wallet address is the account, and a transaction is the instruction. There is no login, no withdrawal desk and no support line. That is the mechanism, and almost every property of DeFi follows from it: the good ones, the strange ones and the expensive ones.
The term covers a family of protocols rather than a single product. A lending market, a decentralized exchange, a stablecoin system and a derivatives protocol are separate contracts, often written by separate teams, that can be combined in a single transaction. This page describes how those pieces work and how they fail. It does not rank them, price them or recommend any of them.
The four building blocks and what each contract actually does
A lending market is a pool of deposits. Suppliers deposit an asset and receive a receipt token representing their share of the pool. Borrowers post collateral and draw from the pool, paying interest that accrues to the suppliers. The contract’s core job is a collateral check: before any borrow, and again on every price update, it compares the value of the collateral to the value of the debt. If the ratio crosses a threshold, anyone can repay part of the debt and take a discount on the collateral. That is a liquidation, and it is automated.
A decentralized exchange (DEX) is a contract that holds reserves of two or more assets and prices trades according to a formula, most commonly a constant product. A trader adds one asset and removes the other; the formula sets how much comes out. Liquidity providers deposit both assets and receive a share token. The mechanism is covered in more detail on the liquidity pools page.
A stablecoin is a token whose contract or issuer tries to hold a target value. Some are backed by deposits held elsewhere; some are backed by crypto collateral locked in a contract that liquidates positions when the collateral falls; some rely on arbitrage and incentives. The contract mechanics differ enough that the word “stablecoin” hides more than it reveals.
A derivatives protocol is a contract that tracks a position against an external price and settles profit or loss in tokens. Perpetual futures, options and synthetic assets all fall here. The contract does not hold the underlying asset; it holds collateral and reads a price.
Composability: the feature that is also the attack surface
Because every protocol is a contract with a public interface, one contract can call another in the same transaction. A single transaction can swap a token on a DEX, deposit the proceeds into a lending market, borrow against the deposit and swap again. This is what people mean by composability, and it is the main reason DeFi can do in one transaction what would take several days and several intermediaries elsewhere.
The same property means a fault in one contract can propagate. If a lending market reads a price from an oracle that a DEX can move, an attacker can move the price, trigger a borrow or a liquidation, and unwind in the same transaction. If a protocol accepts a receipt token from another protocol as collateral, a bug in the second protocol becomes a bug in the first. Contracts that call each other inherit each other’s assumptions. The reader who understands this can predict a class of incidents that never appear in a protocol’s marketing: the loss is not in the contract that was attacked, but in every contract that trusted it.
Oracles, liquidations and the price the contract believes
Most DeFi contracts do not know the market price of anything. They read it from an oracle: a contract or a set of contracts that report a price, often aggregated from several venues. The oracle is a dependency, and it is a single point of failure in a system that otherwise has no single point of failure.
Two failure modes recur. The first is a stale or manipulated price. If the oracle reports a price that no longer matches the market, positions are mis-valued: borrowers can borrow more than the collateral justifies, or healthy positions are liquidated. The second is a liquidation cascade. When collateral falls quickly, many positions cross their thresholds at once. Liquidators repay debt and sell collateral, which can push the price further, which triggers more liquidations. The contract is behaving exactly as written; the outcome is still a loss for the borrower.
A borrower can reduce this risk by watching the collateral ratio and the oracle source, not just the interest rate. A supplier can reduce it by checking which collateral the market accepts and how concentrated the borrowing is.
Where the assets actually sit: bridges and wrapped tokens
Assets on one chain cannot be spent on another directly. A bridge is a contract or a set of contracts that locks an asset on one chain and issues a representation on another, or burns and re-mints. The representation is only as good as the bridge’s custody and code. Bridge contracts have historically held large balances and have been a repeated target; the bridges page covers the trust models.
A wrapped token is a similar idea inside one chain: a contract holds the original and issues a token that claims to be redeemable for it. The claim is a contract promise, not a legal one. When a wrapped token trades at a discount, the market is pricing the redemption risk.
Governance, upgrades and the admin key
Many DeFi contracts are upgradeable or controlled by a governance contract. A token holder vote, a multisig or a single admin address can change the contract’s rules, pause it or move funds. This is a mechanism, not a scandal: it is how bugs get fixed. But it means the contract’s behaviour is not fixed by its code alone. A reader assessing a protocol should know who can upgrade it, what threshold is required, and whether the upgrade path is timelocked. A protocol with an admin key is a protocol with an admin.
The risks that sit alongside the benefit
Contract bugs. Code can be wrong. A bug in a lending market or a DEX can drain reserves, and deposits are not insured. Reading a contract’s audit history is useful but does not prove it is free of bugs; no audit does.
Oracle failure. Covered above: a wrong price mis-values every position that depends on it.
Liquidation. Borrowing against collateral means the collateral can be sold if its value falls. The threshold is set by the contract, and the liquidation penalty is real.
Impermanent loss. Providing liquidity to a DEX is not the same as holding. If the two assets move apart in price, the pool’s rebalancing leaves the provider with less value than simply holding both. The impermanent loss page works through the arithmetic.
Governance and upgrade risk. An admin can change the rules. A governance vote can do the same, sometimes quickly.
Bridge risk. A bridged asset depends on the bridge’s custody and code. That dependency is separate from the protocol where the asset is used.
Stablecoin risk. A stablecoin’s peg is a mechanism, not a guarantee. The mechanism can be a bank deposit, an overcollateralised crypto position or an arbitrage incentive, and each fails differently.
Tax and record-keeping. Every swap, borrow, repayment and liquidation is a transaction with a potential tax consequence, and the treatment varies by country. The DeFi tax page sets out what to track and what to check with a local adviser.
Reading a protocol before using it
A contract address is public, and the functions it exposes can be inspected. Foundry’s cast tool can call a contract and decode calldata without a wallet connection. The commands below run against a public RPC endpoint; replace the placeholder address and arguments with the ones being checked.
cast call <address> "totalSupply()(uint256)" --rpc-url <url>
This returns the total supply of a token contract as a decimal integer. A supply that does not match the figure shown in a front end is a reason to stop and check the address.
cast decode-calldata "approve(address,uint256)" 0x...
This decodes a transaction’s calldata into a function name and arguments. It is how a reader confirms what a wallet is about to sign: which function, which spender, which amount. The Foundry Book documents the command at cast decode-calldata.
cast 4byte <selector>
This looks up a four-byte function selector and returns candidate signatures. It is useful when a transaction’s calldata begins with a selector the reader does not recognise. The reference is at cast 4byte.
These calls read state; they do not move funds. A wallet prompt that asks for a signature is a separate step, and the calldata behind it can be decoded the same way before it is approved.
What a reader can predict from the mechanism
Once the pieces are clear, several situations become predictable without being listed anywhere. A protocol that accepts another protocol’s receipt token as collateral will fail if that second protocol fails. A lending market whose oracle reads from a single DEX can be moved by a trade on that DEX. A bridged asset’s value depends on a contract the user never interacts with directly. A governance key can change a rule after a deposit is made. A DEX position can lose value relative to holding even when both assets are unchanged in price. None of these are exotic; they are the direct consequences of contracts calling contracts, and they are the reason the mechanism is worth understanding before the interface is.
Common questions
What is DeFi in simple terms?
DeFi is a set of smart contracts on a public blockchain that let people lend, borrow, trade and mint tokens without a company holding the funds in between. The contract holds the assets and enforces the rules, and a wallet address is the account. There is no login or support desk, so the contract's code and its dependencies are the whole system.
Is DeFi the same as crypto?
No. Crypto is the broader category of blockchain-based assets and networks. DeFi is a subset of applications built on those networks: lending markets, exchanges, stablecoins and derivatives implemented as contracts. A token can exist without any DeFi protocol, and a DeFi protocol can exist without issuing its own token.
What are the main DeFi risks?
Contract bugs, oracle failures, liquidation of collateral, impermanent loss for liquidity providers, governance or admin-key changes, bridge risk and stablecoin mechanism risk. Each is a property of how the contracts work rather than an accident, and each can be assessed before depositing by reading the contract's dependencies and admin controls.
Can DeFi funds be recovered if something goes wrong?
Usually not by a support process. If a contract is drained or a position is liquidated, the transaction is final on the chain. Some protocols have pause or upgrade functions controlled by governance or an admin, which can sometimes stop an incident, but that is a property of the specific contract and not a general guarantee.
Do I need to understand smart contracts to use DeFi?
Not to use it, but understanding the mechanism changes what a reader can predict. Knowing that a lending market reads an oracle, that a DEX position can lose value relative to holding, and that a bridge is a separate dependency explains most of what goes wrong. The contract address and its functions are public and can be inspected without connecting a wallet.
Read next
- What a Smart Contract Is and How It Executes A smart contract is code deployed at an address and run by every node. What determinism, immutability and verified source mean for a wallet screen.
- Centralized vs Decentralized Exchanges: How Each Actually Works How centralized and decentralized exchanges differ in custody, order matching, identity checks, counterparty risk, token approvals and MEV exposure.
- Gas Limit vs Gas Price: What Each Number Does Understand the difference between gas limit and gas price, what happens when the limit is too low, and why high estimates may signal contract issues.
- DeFi Tax: What Counts as a Taxable Event Learn why DeFi transactions create multiple taxable events, how liquidity pools and yield farming are taxed, and what to check for your jurisdiction.
- Smart Contract Wallets: A Wallet That Is a Program Recovery without a seed phrase, spending limits and batched approvals, against deployment cost, per-chain addresses and dependence on the contract's code.