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.
InstrumentTrack utilization, supply/borrow indexes, and HF per account so you can assert changes in tests.
Steps
- Pick two assets (stable:+ volatile) with sample prices; compute maxBorrow and HF for a few positions.
- Simulate utilization changes and:See how borrow/supply APR moves with a kinked model.
- Advance time/blocks in tests;:Accrue interest and confirm debt/supply indexes scale correctly.
- Flip the oracle price:Down 30%; observe HF crossing below 1 and confirm liquidation eligibility.
- Liquidate a portion using:Close factor; ensure seized collateral matches bonus rules and HF improves.
- Add events (Deposit, Borrow,:Repay, Liquidate) and check logs align with state changes.