Module 4 – Decentralised Finance Engineering: AMMs, Lending, Governance & Token Economics

This module provides a deep technical dissection of Decentralised Finance (DeFi) systems. We examine the engineering foundations of Automated Market Makers (AMMs), lending protocols, liquidation engines, risk parameters, governance frameworks, and token economic design. The objective is to build competence in analysing, designing, and evaluating on-chain financial primitives at a professional engineering level.

1. Decentralised Finance as a Smart-Contract Ecosystem

DeFi systems are coordinated networks of interoperable smart contracts implementing financial primitives such as trading, lending, collateralisation, derivatives, governance, and asset issuance. Unlike traditional finance, these systems operate algorithmically, enforcing rules through immutable code.

Core DeFi primitives include:

  • Decentralised Exchanges (DEXs)
  • Automated Market Makers (AMMs)
  • Lending & borrowing protocols
  • Stablecoin systems
  • Derivatives and synthetic assets
  • Governance systems (DAOs)

Each primitive exposes attack surfaces, incentive mechanisms, and systemic dependencies that must be considered holistically.


2. Automated Market Makers (AMMs)

AMMs replace the order book with deterministic mathematical functions. They allow continuous liquidity provision by enabling anyone to deposit assets into liquidity pools in exchange for LP (Liquidity Provider) tokens.

2.1 Constant Product AMM (Uniswap V2)

The invariant is:

x * y = k
  • x: reserve of token A
  • y: reserve of token B
  • k: constant

This model ensures liquidity at all price points but introduces slippage and impermanent loss.

2.2 Constant Sum AMM

Ideal for assets of equal value (e.g., stablecoins), with invariant:

x + y = k

Permits zero-slippage swaps but is unstable under arbitrage pressure in volatile markets.

2.3 Hybrid AMM (Curve)

Combines constant product and constant sum functions:

  • High liquidity near peg
  • Low slippage for stable assets
  • Piecewise curvature allows efficient arbitrage

2.4 Impermanent Loss

Occurs when pool token prices diverge. LPs lose value relative to holding assets passively. This risk is fundamental to AMM economics.

2.5 AMM Security Properties

  • Price oracle dependency
  • Flash-loan exploitation
  • Reserve manipulation
  • Front-running and sandwich attacks

3. Lending Protocols: Collateral, Liquidation & Interest Models

Lending protocols allow user deposits (supply side) and borrowing (demand side) through overcollateralised positions enforced by smart contracts.

3.1 Overcollateralisation

To borrow, users must lock assets worth more than the loan due to volatility risks.

  • Collateral Factor (CF): maximum borrowable ratio
  • Liquidation Threshold (LT): borrow becomes unsafe
  • Liquidation Bonus (LB): incentive for liquidators

3.2 Interest Rate Models

Protocols use algorithmic interest curves:

  • Linear model
  • Jump-rate model
  • Dynamic utilisation-based model

Utilisation rate governs supply and demand through adjustable APYs.

3.3 Liquidations

When a user’s health factor falls below 1, the position becomes liquidatable.

Liquidators repay a portion of the borrower’s debt in exchange for a discounted amount of collateral.

3.4 Lending Contract Architecture

  • Controller contract
  • Market contracts for each asset
  • Interest model contract
  • Price oracle adapter

Multiple upgrades or integrations can occur at each layer.


4. Stablecoin Engineering & Collateral Mechanisms

Stablecoins maintain peg stability through collateral, algorithms, or hybrid models.

4.1 Fiat-Collateralised Stablecoins

Fully backed by cash or liquid securities; requires centralised custody.

4.2 Crypto-Collateralised Stablecoins

Backed by on-chain collateral; overcollateralised to absorb volatility shocks.

4.3 Algorithmic Stablecoins

Use incentives or supply adjustments; vulnerable to death spirals during stress.

4.4 Peg Stability Mechanisms

  • Target rate stabilisation
  • Redemption arbitrage
  • Collateral auctions
  • Dynamic risk parameters

5. Governance & DAO Engineering

Decentralised Autonomous Organisations (DAOs) coordinate protocol upgrades, risk parameters, treasury expenditures, and economic policy.

5.1 Governance Models

  • Token-weighted voting: voters proportional to token holdings
  • Delegated governance: trusted representatives vote on behalf of users
  • Quadratic voting: cost of influence grows quadratically
  • Council-based governance: hybrid on-chain/off-chain committees

5.2 Governance Flow

  1. Proposal submission
  2. Off-chain discussion
  3. On-chain voting
  4. Execution via timelock

5.3 Governance Risks

  • Voter apathy
  • Token concentration
  • Governance capture
  • Proposal manipulation

Proper governance engineering ensures system longevity and reduces systemic fragility.


6. Token Economics & Incentive Engineering

Tokenomics governs supply, incentives, distribution, and utility. Good design aligns user behaviour with protocol sustainability.

6.1 Token Utility Categories

  • Governance tokens
  • Fee tokens
  • Work tokens
  • Collateral tokens
  • Access tokens

6.2 Token Distribution Models

  • Liquidity mining
  • Staking rewards
  • Fixed supply with halving schedules
  • Bonding curve sales

6.3 Vesting & Emission Schedules

Vesting prevents dumping and aligns team incentives with long-term performance.

6.4 Economic Risks

  • Ponzi-like reward loops
  • Incentive misalignment
  • Demand collapse
  • Unsustainable APYs

7. Oracle Integration & Price Feed Engineering

Price feeds underpin lending collateral, AMM routing, liquidations, and derivatives. Oracles are therefore systemic risk centres.

7.1 Types of Oracles

  • Aggregator-based oracles
  • DEX-based TWAP oracles
  • Hybrid oracles with multi-layer consensus

7.2 Oracle Attack Vectors

  • Flash-loan manipulation
  • Illiquid pool attacks
  • Stale price feeds
  • Frontrunning oracle updates

Oracle misconfiguration has caused some of the largest DeFi exploits.


8. Liquidation Engines & Systemic Risk Dynamics

Liquidation engines act as automated risk managers. When collateral value drops, liquidators stabilise the system by seizing assets and repaying borrower debt.

8.1 Liquidation Workflow

  1. Monitor health factors
  2. Trigger liquidation when threshold is crossed
  3. Apply liquidation bonus
  4. Transfer collateral to liquidator

8.2 Liquidation Failure Modes

  • Oracle delays
  • Congested blockspace
  • Insufficient liquidator participation
  • Unprofitable liquidations

9. Composability & Inter-Protocol Dependencies

DeFi is highly composable: protocols stack functionality on top of each other. This amplifies innovation but introduces cascading failure risks.

9.1 Composability Primitives

  • Tokenised positions (LP tokens, lending shares)
  • Flash loans
  • Router contracts
  • Yield aggregators

9.2 Cascading Risks

  • Stablecoin depegs affecting collateralised loans
  • DEX oracles feeding incorrect prices into lending models
  • Bridge exploits triggering liquidity drains

10. DeFi Security Architecture

Ensuring security requires layered defence mechanisms:

  • Formal verification
  • Bug bounty programs
  • Time-delayed governance execution
  • Multi-sig treasury control
  • Rate limiting of contract calls
  • Fail-safe freeze mechanisms

Many DeFi catastrophes stem not from code bugs but from incentive misalignments.


11. DeFi Protocol Engineering Blueprint

A high-level design workflow for new DeFi systems:

  1. Define financial primitive (AMM, lending, derivatives)
  2. Model risk and collateral dynamics
  3. Specify governance structures
  4. Design tokenomics
  5. Develop contract architecture
  6. Simulate economic scenarios
  7. Implement audits and security checks
  8. Deploy with safety limits

The result is a production-ready DeFi system that balances efficiency, risk management, and user incentives.


12. Module Summary

Module 4 presented an in-depth engineering treatment of DeFi systems: AMMs, lending protocols, stablecoins, governance designs, tokenomics, liquidation engines, oracle systems, composability structures, and systemic risk propagation. This equips learners with the analytical frameworks to evaluate, design, and critique decentralised financial infrastructures at a professional level.

Module 5 will focus on security engineering, formal verification, audits, and threat modelling for smart contract systems.

Pages: 1 2 3 4 5 6