Learn›Crypto›DeFi & Smart Contracts
Crypto · Lesson 12 of 12

DeFi & Smart Contracts

7 min read  ·  Advanced  ·  Updated November 2026  ·  By

Decentralised Finance — DeFi — is the attempt to rebuild the functions of the traditional financial system on public blockchains. Lending, borrowing, trading, earning interest, insurance — all without banks, intermediaries, or anyone's permission. At its peak in late 2021, over $250 billion was locked in DeFi protocols. At its core are smart contracts: the technology that makes all of it possible, and all of it vulnerable.

What are smart contracts?

A smart contract is code stored on a blockchain that executes automatically when predetermined conditions are met. "If X happens, then Y occurs" — enforced by the blockchain itself, not by any person or company. Once deployed, the code runs exactly as written with no ability for anyone to intervene, modify it, or stop it.

Automatic execution is both the power and the danger of a smart contract. A smart contract can hold and move billions of dollars with no human involved. If the code has a bug, there is often no way to stop the exploit once it begins.

How a smart contract runs Code, not a person, enforces 1. Write rules if X, then Y 2. Deploy on chain code is now fixed 3. Condition met X happens 4. Executes itself nobody can stop it Bugs run just as faithfully
A smart contract is code that runs when its conditions are met. Once deployed, nobody can pause or edit it, which is why a bug can cost as much as a feature earns.

Core DeFi protocols

Lending / borrowing (Aave, Compound): deposit crypto as collateral, borrow other assets. Always overcollateralised — if collateral falls below a threshold, the protocol automatically liquidates it. No credit checks, no paperwork, available to anyone globally.

Decentralised exchanges (Uniswap, Curve): trade tokens directly from your wallet via AMM liquidity pools. No order book, no KYC, no counterparty.

Yield aggregators (Yearn Finance): automatically move your funds between protocols to maximise yield. Complexity abstracted away — deposit once and earn optimised returns.

Yield farming — what it is and why it's risky

Yield farming is deploying crypto across multiple DeFi protocols to maximise returns — typically through a combination of lending fees, trading fees, and governance token rewards. Advertised yields of 100%+ APY are common. These are almost always paid in the protocol's own governance token, not stable value — as the token inflates, your real return evaporates.

Genuine yield in DeFi — from trading fees in liquid pools, for example — is real but modest (1–10% annually). Anything dramatically above that almost always involves: governance token inflation, smart contract risk, or unsustainable subsidies from a treasury that will eventually run dry.

The hack problem

Over $5 billion has been stolen from DeFi protocols through smart contract exploits. Notable incidents:

Bridges — contracts that move assets between different blockchains — are particularly vulnerable. They hold large amounts of locked assets and must process complex cross-chain logic, creating large attack surfaces.

The DeFi risk framework: smart contract risk (code bugs), oracle risk (price feed manipulation), governance risk (malicious proposals), liquidity risk (inability to exit during panic), and regulatory risk (protocols being shut down). Audits reduce but don't eliminate smart contract risk. The only DeFi that has truly proven itself is the oldest — Uniswap, Aave, Compound have been running for years with no catastrophic exploits. New protocols, however hyped, carry dramatically higher risk.

What does liquidation look like with real numbers?

Suppose you deposit a token worth £1,000 into a lending protocol as collateral, and the protocol requires borrowers to stay above a 150% collateral ratio. You borrow £500 of a stablecoin against it. Your collateral ratio is £1,000 ÷ £500 = 200%, so you are comfortably above the line.

Now imagine the token's value falls by 25% to £750. The ratio is £750 ÷ £500 = 150%, exactly the threshold. Any further fall triggers liquidation: the smart contract sells enough of your collateral to repay the loan and charges a liquidation penalty, say 10% of the amount repaid. On a £500 loan that is £50.

You keep whatever collateral is left, roughly £750 minus £500 minus £50 = £200, having started with £1,000 of tokens and £500 of borrowed stablecoin in hand. Nobody phoned you first. The code checked the ratio, found it below the threshold and executed, which is exactly what it was written to do.

What this does not tell you

A worked example on a calm spreadsheet hides several things. First, the price the protocol uses comes from an oracle, and if that feed is wrong or manipulated, a loan can be liquidated at a level that never traded on the open market. Second, liquidations cluster: when a token falls sharply, thousands of positions cross their thresholds together, network fees spike, and the collateral sold may fetch less than the oracle price. Third, "audited" is not the same as "safe".

An audit is a review at a point in time of one version of the code, and the interaction between two individually sound contracts can still be exploited. Finally, a smart contract cannot tell you whether the protocol's treasury, team or governance token holders are trustworthy. Code enforces rules; it does not judge the people who wrote them.

DeFi FAQ

Can a smart contract be changed after it is deployed?

Not directly. Code on a public blockchain is immutable once deployed, which is the point. Many protocols, however, use upgradeable patterns where an admin key or a governance vote can point users to a new version of the contract. That flexibility helps fix bugs, but it also means the rules you agreed to can change, so it is worth checking who holds that power.

Is DeFi regulated in the UK?

Mostly not in the way banks are. The FCA regulates some cryptoasset activities, such as financial promotions and the registration of firms, but most DeFi protocols are not authorised, and the Financial Services Compensation Scheme does not cover losses from them. If a protocol is hacked or fails, there is usually no regulator or compensation scheme to turn to.

What is the difference between DeFi and a crypto exchange app?

A centralised exchange app is a company that holds your crypto for you, matches trades on its own servers and can freeze or reverse activity. A DeFi protocol is a set of smart contracts: you keep your own keys, trades settle on the blockchain, and there is no customer service desk to call if something goes wrong. Each model carries a different kind of risk.

DeFi and smart contracts wrap up the Crypto section. You now understand the technology, the ecosystems, the risks, and the genuine innovations. Next: Strategy — how to actually invest across all of these asset classes.

Sources and further reading: FCA: Cryptoassets · SEC Investor.gov: Crypto assets · FCA: Protect yourself from scams

₿

Practise defi & smart contracts with virtual money

Open a free stock duel on RIP. and use defi & smart contracts against a friend on live prices. No real money is at risk.

Download free on iOS →