BR Academy
0%
Smart Contracts and Tokens·Lesson 23 of 25·12 min

DeFi and On-Chain Finance

The Concept

Decentralized Finance (DeFi) is the umbrella term for financial services — lending, borrowing, trading, earning interest — rebuilt as smart contracts instead of as products offered by banks, brokerages, or exchanges. Where a traditional bank takes your deposit, decides internally how to lend it out, and simply tells you your balance, a DeFi protocol replaces the bank's internal decision-making with public, auditable smart contract code that anyone can read, verify, and interact with directly, without opening an account, filling out an application, or getting approved.

The building blocks covered in earlier lessons make this possible: tokens (the previous lesson) give DeFi assets to move around; smart contracts (two lessons back) give the automated, trustless logic; and the blockchain itself gives a public, tamper-evident record of every transaction, so nobody has to simply take a bank's word for their own balance or the institution's solvency.

Three DeFi primitives come up constantly:

Decentralized exchanges (DEXs) let users swap one token for another without a company like Coinbase acting as the middleman matching buyers and sellers. Many use an automated market maker (AMM) model: instead of an order book matching individual buy and sell orders, a smart contract holds a pool of two tokens (say, ETH and a stablecoin) contributed by liquidity providers, and prices are set algorithmically based on the ratio of tokens in the pool — the more of one token you buy, the more expensive it gets, automatically, with no human setting the price.

Lending protocols let users deposit a token to earn interest, and let others borrow against collateral — all enforced by smart contract code rather than a loan officer. Borrowers must typically over-collateralize (deposit more value than they borrow), and if their collateral's value falls too close to their loan amount, the contract automatically liquidates (sells) their collateral to protect lenders — a process that happens instantly and algorithmically, with no human intervention, phone call, or negotiation period.

Stablecoins are tokens designed to hold a steady value, usually pegged to the US dollar, either by being backed 1:1 by real dollar reserves held by a company (custodial stablecoins like USDC) or by using smart contract mechanisms and crypto collateral to maintain the peg algorithmically (decentralized stablecoins like DAI). Stablecoins give DeFi users a way to hold and transact value without the volatility of assets like ETH or BTC, and they act as the "cash" that moves through most DeFi activity.

None of this is risk-free. Smart contract bugs can drain a lending protocol's entire reserve in a single transaction; AMM prices can be manipulated with large, fast trades ("price oracle manipulation"); and even collateral-backed stablecoins can lose their peg during extreme market stress. "Decentralized" describes who controls the code and the funds — not how safe the system is. Evaluating a DeFi protocol means asking the same questions you'd ask about any financial product: has the code been audited, how much value does it currently secure, and what happens to your funds in a worst-case scenario.

Worked Example

Walk through swapping tokens on a simplified AMM-style DEX: A liquidity pool holds 100 ETH and 200,000 of a stablecoin (implying a price of 2,000 stablecoin per ETH). You want to swap 1,000 stablecoin for ETH. The AMM's pricing formula keeps the product of the two pool balances constant, so as you add 1,000 stablecoin to the pool, the contract calculates how much ETH must leave the pool to keep that product the same — removing slightly less than 0.5 ETH, with the exact number worked out automatically by the contract's code the instant your transaction executes. No human set that price or approved your trade; the formula and the existing pool balances did, transparently and the same way for every user. The liquidity providers who originally deposited the ETH and stablecoin earn a small fee from every trade that passes through the pool, which is their incentive for supplying it — and their risk is that the pool's ratio can shift against them (a phenomenon called impermanent loss) if one token's price moves significantly relative to the other.

Exercise

In two or three sentences, explain the core difference between depositing money in a traditional savings account versus depositing it into a DeFi lending protocol — specifically, who (or what) decides the terms, and how you would verify your balance and the protocol's solvency in each case. Then, in one more sentence, name one concrete risk a DeFi lending protocol carries that a traditional, FDIC-insured bank account does not.

Recap

  • DeFi rebuilds financial services (trading, lending, borrowing, stable-value holding) as public smart contracts instead of company-run products.
  • DEXs, lending protocols, and stablecoins are the three most common DeFi building blocks, each replacing a human decision-maker with transparent, automatic code.
  • Because the code and the pool balances are public, anyone can verify the state and rules of a DeFi protocol directly — but "decentralized" does not mean "risk-free," so audits, collateral levels, and worst-case scenarios still matter.