openskills.info
Course Preview

DeFi Protocol Patterns

DeFi protocol patterns are the recurring smart contract designs behind decentralized finance on Ethereum and similar blockchains: automated market makers that price trades from pooled reserves, overcollateralized lending markets with automatic liquidation, collateral-backed stablecoins, tokenized vaults, flash loans, and price oracles. Each replaces a financial intermediary with public code whose rules anyone can inspect and call.

itDistributed systems, messaging, and integration

Don't Panic: DeFi Protocol Patterns

Decentralized finance takes the jobs of a bank, an exchange and a stablecoin issuer and hands them to smart contracts: programs on a blockchain such as Ethereum that hold assets and enforce rules in code. Nobody approves your account. Anyone with a wallet can call the contract, and anyone can read its books, which is refreshing right up to the moment you realize that includes people looking for mistakes.

The products have cheerful names and dashboards full of numbers. Underneath, they are built from a short list of repeating designs. Learn the designs and most new protocols stop being mysterious. They become a familiar pattern with a new logo.

The first idea is the invariant, a rule the contract checks after every call. A trading pool insists that the product of its two token reserves never shrinks. A lending market insists every borrower keeps a health factor, threshold-weighted collateral divided by debt, above 1. If a call would break the rule, the whole transaction is undone as if it never happened. That all-or-nothing behavior is called atomicity, and it is both the safety net and the loophole.

The second idea is the oracle, the mechanism that brings outside prices into a contract. Lending markets and stablecoins cannot know what collateral is worth without one. The price a pool is showing right now is the one number never to trust, because a trade can push it, a dependent contract can read it, and a second trade can push it back, all inside one transaction.

The third idea is the outside actor. Contracts do not tidy up after themselves. Arbitrageurs trade pools back toward market prices, and liquidators repay unsafe loans in exchange for discounted collateral. They do it because they are paid. When nobody finds the job profitable, the contract's rules still hold in theory and quietly stop working in practice.

The surprise is the flash loan: borrow any amount a pool holds, with no collateral, provided you repay before the transaction ends. It sounds like a typo. It is actually a feature, and it means any rule based on how much of something an account holds for a single moment can be satisfied by anyone. Governance votes counted from current balances are the classic casualty, which is why safer designs count votes from a snapshot taken earlier.

Every contract is public, so protocols stack on each other. A vault deposits into a lending market that reads a price from a pool. This is composability, which is excellent for building quickly and equally excellent at spreading one broken price to everything above it.

The Intro walks through each pattern properly: automated market makers, lending, stablecoins, vaults, flash loans, oracles and governance. The Cheatsheet collects the formulas and comparison tables. The Practice Reference and Exercise let you compute a swap, a health factor, an interest rate and a vault attack yourself, offline, with no money anywhere near it. Field Notes covers how these systems actually break.

Where this skill leads

Relevant careers

See how this topic contributes to broader role-level skill maps.

Sources