Skip to main content

Skill Guide

DeFi protocol mechanics (AMMs, lending, flash loans, oracles)

DeFi protocol mechanics encompass the core computational and financial primitives-specifically Automated Market Makers, decentralized lending/borrowing, atomic flash loans, and on-chain data oracles-that enable non-custodial, programmable financial services on blockchain networks.

This skill is critical because it enables the design, analysis, and risk assessment of the infrastructure powering over $50 billion in on-chain assets. Mastery directly impacts a firm's ability to innovate in financial product development, create novel trading strategies, or secure protocol operations against systemic exploits.
1 Careers
1 Categories
8.8 Avg Demand
25% Avg AI Risk

How to Learn DeFi protocol mechanics (AMMs, lending, flash loans, oracles)

1. **Foundational Blockchain & Solidity:** Understand Ethereum's state model, gas, and basic smart contract structure (focus on payable functions, modifiers, and events). 2. **Core DeFi Primitives:** Study the whitepapers for Uniswap V2/V3 (AMMs), Aave/Compound (lending pools, interest rate models), and the MakerDAO system. 3. **Key Vocabulary:** Master terms like impermanent loss, utilization rate, collateralization ratio, and liquidity depth.
1. **Protocol Simulation:** Use tools like Foundry or Hardhat to deploy forked mainnet test environments. Simulate user actions: providing liquidity, taking out overcollateralized loans, executing flash loans to arbitrage or liquidate positions. 2. **Read and Analyze Production Code:** Audit critical functions in deployed contracts (e.g., `swap()`, `borrow()`, `liquidate()`). Identify the role of invariant checks and reentrancy guards. 3. **Common Pitfall Avoidance:** Learn to model economic attacks, not just code bugs. Understand how oracle manipulation (e.g., via spot price skew) can drain a lending pool.
1. **Protocol Architecture & Integration:** Design multi-protocol strategies (e.g., using a flash loan from Aave to provide concentrated liquidity on Uniswap V3 to earn yield, then repaying). 2. **Risk Framework Development:** Build quantitative models for protocol risk parameters (e.g., optimal loan-to-value ratios, liquidation penalty sizing) using agent-based simulation. 3. **Mentorship & Review:** Lead code and economic model reviews for new DeFi products, focusing on game-theoretic stability and composability risks.

Practice Projects

Beginner
Project

Build a Constant Product AMM from Scratch

Scenario

You need to implement a basic automated market maker that allows users to swap between two ERC-20 tokens, maintaining the x*y=k invariant.

How to Execute
1. Deploy two mock ERC-20 tokens. 2. Write the AMM contract with functions: `addLiquidity`, `removeLiquidity`, and `swap`. 3. Implement the swap logic using the constant product formula, accounting for a 0.3% fee. 4. Test on a local Hardhat node, verifying price impact and liquidity provider token minting.
Intermediate
Project

Develop and Execute a Flash Loan Arbitrage Bot

Scenario

You identify a price discrepancy for ETH/USDC between Uniswap and SushiSwap. Your goal is to capture this arbitrage profitlessly using a flash loan from Aave, without using your own capital.

How to Execute
1. Write a Solidity contract that implements the IFlashLoanReceiver interface. 2. The `executeOperation` function should: borrow ETH from Aave, swap ETH for USDC on Uniswap, swap USDC back to ETH on SushiSwap, repay the loan + fee, and keep profit. 3. Use Foundry's mainnet fork to simulate the trade, calibrating gas and slippage. 4. Deploy to a testnet and then mainnet with a minimal amount, monitoring for front-running.
Advanced
Project

Design a Novel Lending Market with Custom Risk Parameters

Scenario

You are tasked with creating a permissionless lending pool for a volatile long-tail asset (e.g., a new governance token). Your challenge is to set dynamic risk parameters (collateral factor, interest rate curves, liquidation incentives) that prevent bad debt while remaining competitive.

How to Execute
1. Model asset volatility and correlation to ETH using historical on-chain data. 2. Design an adaptive interest rate model that spikes sharply at high utilization. 3. Implement a two-step liquidation mechanism with a Dutch auction for the collateral. 4. Use agent-based simulation (e.g., with CadCad) to stress-test the system against black swan events (e.g., 80% price crash in one block, oracle failure).

Tools & Frameworks

Development & Testing

Foundry (forge, cast, anvil)Hardhat & Ethers.jsSlither & Mythril

Foundry is the preferred tool for high-performance Solidity testing and mainnet forking. Hardhat is essential for complex deployment scripts and TypeScript integration. Static analysis tools like Slither are used for initial security scans before manual review.

On-Chain Analysis & Data

Dune AnalyticsThe GraphTenderly

Dune is used for deep protocol analytics and custom dashboards (e.g., tracking liquidity depth, loan health). The Graph indexes protocol events for real-time data retrieval. Tenderly provides transaction simulation and debugging for failed or complex transactions.

Conceptual Frameworks

Constant Product / Concentrated Liquidity MathInterest Rate Model DesignOracle Attack Vectors

These mental models are non-negotiable for protocol design. You must be able to derive formulas on a whiteboard and explain how specific design choices (e.g., using a TWAP oracle vs. a spot price) mitigate systemic risk.

Interview Questions

Answer Strategy

The interviewer is testing your granular knowledge of protocol mechanics, not just high-level concepts. Use a step-by-step breakdown. **Sample Answer:** 'A liquidation is triggered when a borrower's health factor drops below 1 due to falling collateral value or rising debt. The liquidator calls `liquidationCall`, specifying the collateral and debt asset. They must repay up to 50% of the borrower's debt in a single call. In return, they receive the borrower's collateral at a discount (currently 5%). The liquidator's profit is the spread between the discount and the gas/flash loan fees. Key risks include front-running by other bots and collateral volatility during the transaction execution.'

Answer Strategy

This tests your understanding of oracle security and game theory. The core competency is identifying manipulation vectors. **Sample Answer:** 'The critical vulnerability is spot price manipulation within a single block to skew the TWAP. An attacker could use a flash loan to execute a massive, illiquid swap on a low-liquidity Uniswap V3 pool, artificially moving the TWAP for that single block. If the lending protocol's collateralization check occurs in that same block, it could allow undercollateralized borrowing. Mitigation requires a multi-layered approach: using a time-weighted median from multiple oracles (e.g., Chainlink, Uniswap V3) with a circuit breaker that halts borrowing if prices deviate beyond a threshold from the median.'

Careers That Require DeFi protocol mechanics (AMMs, lending, flash loans, oracles)

1 career found