freecoding.school100% FREE · NO SIGNUP
Yield OceanISSUE #10 of 34

liquidations · health factor · keepers

Liquidity LuVSThe Sandwich Bot
Liquidity Lu saysHealth factor = collateral × threshold / debt. When it drops below 1, anyone can liquidate the position — repay part of the debt and seize collateral at a bonus.

A lending position has a health factor: HF = collateral × liquidationThreshold / debt. Above 1 is safe; below 1 the position is liquidatable by anyone. The liquidator repays a portion of the debt and seizes collateral worth more than the repayment — the difference is the liquidation bonus, typically 5-10%.

Liquidation bots ("keepers") race to find unhealthy positions during volatility spikes. The demo shows a position fall from HF=1.0 to HF=0.80 after a 20% price drop, becoming liquidatable.

Power-ups you unlock

The Sandwich Bot attacks — common mistakes

Boss battleCompute HF before and after a 20% collateral price drop and show liquidation gets triggered.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>
const hf = (c, t, d) => (c * t) / d;
const acct = { collat:1000, threshold:0.85, debt:850 };
const BONUS = 0.05;
const hfStart = hf(acct.collat, acct.threshold, acct.debt);
const collatAfter = acct.collat * 0.80;        // -20% price
const hfAfter = hf(collatAfter, acct.threshold, acct.debt);
const liquidatable = hfAfter < 1;
const seized = Math.min(collatAfter, acct.debt * (1 + BONUS));
document.getElementById('o').textContent = [
  'start: collat=$' + acct.collat + ', debt=$' + acct.debt + ', threshold=' + acct.threshold,
  '  HF = ' + hfStart.toFixed(3) + '   (safe)',
  '',
  '-20% collateral price crash:',
  '  collat=$' + collatAfter,
  '  HF = ' + hfAfter.toFixed(3) + '   → ' + (liquidatable ? 'LIQUIDATABLE' : 'safe'),
  '',
  'liquidator repays $' + acct.debt + ', seizes $' + seized.toFixed(0) + '   (' + (BONUS*100) + '% bonus)'
].join('\n');
</script></body></html>
▶ Open the interactive comic issue
‹ Aave V3 · Isolation Mode · E-ModeInterest Rate Models · Utilization Curves ›