Advanced

Lending Protocols (Mechanics) — Hands-on lab

Understand collateral, liquidation, and health factor.

Developer Advanced
6/8 — Lending Protocols (Mechanics) — Hands-on lab

Sim firstUse a script to accrue interest over blocks and trigger liquidations; verify HF crosses 1 when expected.

Blockchains solve coordination problems, not just financial ones.
— Vitalik Buterin

InstrumentTrack utilization, supply/borrow indexes, and HF per account so you can assert changes in tests.

Steps
  1. Pick two assets (stable:+ volatile) with sample prices; compute maxBorrow and HF for a few positions.
  2. Simulate utilization changes and:See how borrow/supply APR moves with a kinked model.
  3. Advance time/blocks in tests;:Accrue interest and confirm debt/supply indexes scale correctly.
  4. Flip the oracle price:Down 30%; observe HF crossing below 1 and confirm liquidation eligibility.
  5. Liquidate a portion using:Close factor; ensure seized collateral matches bonus rules and HF improves.
  6. Add events (Deposit, Borrow,:Repay, Liquidate) and check logs align with state changes.
← Previous section
Next section →