Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
On Ethereum, liquidations often complete 20-60 seconds after a position becomes underwater because keepers compete via priority fees and 12-second blocks limit reactivity. On Solana, liquidations land within 1-3 slots (under 2 seconds). This means lending markets can offer higher LTVs and stables can run tighter pegs without insolvency risk.
Inspect a real Solana liquidation tx.
Use these three in order. Each builds on the one before.
In one paragraph, explain why liquidations are critical to a lending market and what happens when they fail.
Walk me through a MarginFi liquidation from oracle update to collateral seizure, step by step.
Design a liquidation system for a lending market where the dominant risk is oracle latency, not solvency. What changes?
// MarginFi-style liquidation pseudocode
// Trigger: borrower health factor < 1.0 (collateral_value < liability_value)
// Anyone can call as a permissionless liquidator
pub fn liquidate(
ctx: Context<Liquidate>,
asset_amount: u64,
) -> Result<()> {
let borrower = &mut ctx.accounts.borrower_account;
let liquidator = &mut ctx.accounts.liquidator_account;
// Step 1: refresh oracle prices (Pyth)
let collat_price = pyth_oracle::get_price(&ctx.accounts.collat_pyth)?;
let liab_price = pyth_oracle::get_price(&ctx.accounts.liab_pyth)?;
// Step 2: compute health factor
let collat_value = borrower.collateral * collat_price;
let liab_value = borrower.liability * liab_price;
let health = collat_value as f64 / liab_value as f64;
require!(health < 1.0, ErrCode::HealthOk);
// Step 3: liquidator repays liability, receives collateral + bonus
let bonus_bps = 500; // 5%
let collat_seized = asset_amount * liab_price / collat_price
* (10_000 + bonus_bps) / 10_000;
// CPI: pull liability from liquidator -> bank
token::transfer(/* liquidator -> bank */)?;
// CPI: push collateral from borrower -> liquidator (bank signs)
token::transfer(/* borrower -> liquidator */)?;
borrower.collateral -= collat_seized;
borrower.liability -= asset_amount;
Ok(())
}
// All of this runs in ONE tx, in <2 seconds from oracle update.
// Compare to Aave on Ethereum: 30-60s latency, MEV-prone.