Sub topic 13
Liquidations in DeFi lending: health factor and liquidation bonus
This chapter assumes you know how margin, maintenance margin and liquidation price work on a perpetual futures exchange, and that you can read short Python functions. It compares that model with liquidation on a DeFi lending protocol, where no exchange operator closes your position. Open code and independent liquidators do it instead.
How DeFi lending creates leverage
A DeFi lending protocol is a set of smart contracts that lets users deposit crypto as collateral and borrow other assets against it. Borrowing is usually overcollateralized, meaning the collateral is worth more than the loan. No credit check exists, so the only protection for lenders is that the protocol can sell the collateral if its value falls too far.
Leverage appears when a borrower loops. The borrower deposits ETH, borrows a stablecoin, buys more ETH, deposits that too, and repeats. The result is a long ETH position larger than the original deposit, much like a leveraged long on a futures exchange. The same price-move arithmetic applies. Debt stays fixed in stablecoin terms while collateral moves with the market, so a small fall in ETH removes a large share of the borrower's equity.
Health factor: the DeFi version of the margin check
On a futures exchange, the liquidation engine compares equity with maintenance margin. A lending protocol uses a single number called the health factor:
health factor = collateral value × liquidation threshold / debt value- Collateral value is the current market value of the deposited assets.
- Liquidation threshold is a fraction set per asset by the protocol. An 0.80 threshold means each dollar of collateral counts as 80 cents against the debt.
- Debt value is the borrowed amount plus accrued interest, priced in the same unit.
A health factor above 1 means the position is safe. At or below 1 it can be liquidated by anyone.
def health_factor(collateral_value, liquidation_threshold, debt_value):
"""DeFi lending health factor: positions with a value below 1 can be liquidated."""
return collateral_value * liquidation_threshold / debt_value
print(health_factor(10000, 0.80, 6000)) # about 1.33, still safe
print(health_factor(7000, 0.80, 6000)) # below 1, liquidatableIn the first case, collateral can lose some value before the position is at risk. In the second, a 30% fall in collateral pushed the health factor to about 0.93.
Finding the liquidation price
You can solve the health factor equation for the collateral price at which it reaches 1. For a single collateral asset with a quantity of units and a fixed debt:
def collateral_liquidation_price(debt_value, liquidation_threshold, collateral_units):
"""Price per collateral unit at which the health factor falls to 1.
Assumes one collateral asset and a debt that does not change."""
return debt_value / (liquidation_threshold * collateral_units)
# 5 ETH collateral, 6000 USD debt, threshold 0.80
price = collateral_liquidation_price(6000, 0.80, 5)
print(price) # 1500.0If ETH trades at 2000 when the position opens, liquidation happens after a 25% fall to 1500. The futures formula in this tutorial's earlier chapter gave a similar "distance to liquidation" that shrinks as leverage rises. Here, the distance shrinks as the debt-to-collateral ratio rises.
Loan-to-value and threshold are not the same
Protocols publish two related numbers for each collateral asset. The loan-to-value (LTV) limit controls how much you may borrow when opening or increasing a loan. The liquidation threshold is higher than the LTV and controls when liquidation becomes possible. The gap between them is the protocol's equivalent of the buffer between initial and maintenance margin.
| Parameter | Role | Typical relationship |
|---|---|---|
| Maximum LTV | Limits new borrowing | Lower than the threshold |
| Liquidation threshold | Sets the liquidation trigger | Higher than the maximum LTV |
| Health factor | Summarizes current safety | Above 1 safe, at or below 1 liquidatable |
A borrower who borrows right up to the maximum LTV starts with a health factor only a little above 1. For example, with an LTV of 0.75 and a threshold of 0.80, the starting health factor is 0.80 / 0.75, about 1.07. A 6% drop in collateral value is enough to cross 1.
Who liquidates, and why they bother
A futures exchange runs its own liquidation engine. A lending protocol cannot, because smart contracts do not run on their own. Something must send a transaction to trigger the liquidation. The protocol solves this with an incentive.
A liquidator is any account, usually an automated bot, that repays part of an unhealthy borrower's debt and receives collateral in return. The collateral comes at a discount, called the liquidation bonus (or liquidation penalty from the borrower's side). For example, a 5% bonus means that repaying 1000 USD of debt lets the liquidator claim 1050 USD worth of collateral.
def liquidate(debt_repaid, bonus, collateral_price):
"""Collateral seized for repaying part of a borrower's debt."""
value_seized = debt_repaid * (1 + bonus)
units_seized = value_seized / collateral_price
return value_seized, units_seized
value, units = liquidate(1000, 0.05, 1500)
print(value, units) # 1050.0 0.7The bonus pays for gas fees, the risk that the price moves before the liquidator sells the collateral, and a profit margin. It is paid out of the borrower's collateral, so the borrower bears the cost.
Close factor
Many protocols limit how much debt a single liquidation may repay. This limit is the close factor. A close factor of 50% means a liquidator can repay at most half the debt in one transaction. The aim is to restore a healthy position without taking more collateral than needed. Some protocols set a close factor of 100% when the position is far below the threshold.
A worked liquidation
Take the position above: 5 ETH collateral, 6000 USD debt, threshold 0.80, bonus 5%, close factor 50%. ETH falls to 1400.
- Collateral value is 5 × 1400 = 7000 USD. Health factor is 7000 × 0.80 / 6000 = 0.93.
- A liquidator repays up to 3000 USD of debt (50% of 6000).
- The liquidator receives 3000 × 1.05 = 3150 USD of ETH, which is 2.25 ETH.
- The borrower now has 2.75 ETH (3850 USD) and 3000 USD of debt. New health factor: 3850 × 0.80 / 3000, about 1.03.
The borrower is back above 1, but barely. A further small fall in ETH would make another liquidation possible. The borrower lost 2.25 ETH to clear 3000 USD of debt, and 150 USD of that loss is the bonus.
Differences from perpetual futures liquidation
The two systems share the same logic: collateral falls, a threshold is crossed, and a forced sale follows. The mechanics differ in ways that matter for risk.
| Feature | Perpetual futures exchange | DeFi lending protocol |
|---|---|---|
| Who liquidates | The exchange's engine | Any liquidator bot |
| Price source | Exchange mark price | On-chain oracle price |
| Cost to the user | Liquidation fee, loss of margin | Liquidation bonus paid from collateral |
| Partial liquidation | Often tiered or partial | Governed by the close factor |
| Backstop for losses | Insurance fund, auto-deleveraging | Protocol reserves, or losses to lenders (bad debt) |
| Speed limits | Exchange matching engine | Block time and gas costs |
Oracles take the place of the mark price
The futures chapters explained that exchanges liquidate on a mark price to resist manipulation of the last traded price. DeFi protocols face the same problem, and use a price oracle, a service that reports asset prices to the contract. Oracle designs vary. Some aggregate many sources, some update only when the price moves by a set percentage, and some use on-chain exchange prices. Each has failure modes:
- A stale price means a position can be liquidated late, after the true market price has already crossed the threshold.
- A manipulated price can trigger unfair liquidations, or allow borrowing against inflated collateral.
- A fast market can move faster than the oracle updates, so liquidators act on a price that no longer matches trading venues.
Bad debt
If the collateral falls so quickly that its value drops below the debt before anyone liquidates, the liquidation bonus can no longer be paid in full, and liquidators lose interest. The remaining shortfall is bad debt. Protocols cover it from a reserve or by socializing the loss among lenders. This role corresponds to the insurance fund and auto-deleveraging on a futures exchange.
Why DeFi liquidations feed cascades
DeFi liquidations contribute to cascades in the same way futures liquidations do. A liquidator who receives discounted collateral usually sells it quickly on a decentralized exchange to lock in the profit. That sale adds selling pressure, and the price falls further. The lower price pushes other borrowers' health factors below 1, which triggers more liquidations.
Two features make this loop easy to see. First, every position's health factor is public on-chain, so liquidators and observers can see how much collateral becomes liquidatable at each price level. Second, network congestion can slow things down. When many liquidations are due, gas fees rise, and some liquidations are delayed, which may leave more bad debt.
def liquidatable_at(price, positions, threshold):
"""Total debt that becomes liquidatable if the collateral price is `price`.
positions: list of (collateral_units, debt_value) tuples."""
total = 0.0
for units, debt in positions:
if units * price * threshold / debt <= 1:
total += debt
return total
book = [(5, 6000), (10, 11000), (20, 15000)]
for p in (2000, 1500, 1200, 1000):
print(p, liquidatable_at(p, book, 0.80))
# 2000 0.0
# 1500 6000.0
# 1200 17000.0
# 1000 32000.0The output shows debt becoming liquidatable in steps as the price falls. The step between 1500 and 1200 adds 11000 of debt, so a modest further fall brings a larger wave of forced selling.
Practical risk controls for borrowers
- Keep the health factor well above 1. A health factor of 1.5 or higher gives a larger buffer than one near 1.1, though no number is safe for every market.
- Borrow less than the maximum. Choosing a lower LTV is the DeFi equivalent of using lower leverage.
- Watch volatile collateral. A volatile asset needs a larger buffer than a stable one.
- Add collateral or repay debt before the threshold. Both raise the health factor. Doing it early costs gas and effort. Doing it late costs the liquidation bonus.
- Account for interest. Debt grows over time, so the health factor drifts down even when prices are flat.
- Understand the oracle. Know which price feed the protocol uses and how often it updates.
Diagram: the liquidation loop
Common errors
- Treating the LTV as the liquidation point. Liquidation is governed by the liquidation threshold, which is higher. Using the wrong number shifts your estimate of the liquidation price.
- Ignoring accrued interest. The debt value in the formula includes interest, so a position left alone gets worse.
- Forgetting that several collateral assets are blended. With mixed collateral, the health factor uses the sum of each asset's value times its own threshold. A fall in one asset moves the whole number.
- Assuming a partial liquidation ends the risk. As the worked example showed, the health factor can end only slightly above 1 and fall below it again.
- Confusing the bonus with a fee paid to the protocol. The bonus goes to the liquidator. The protocol may charge a separate portion.
Exercise
A borrower deposits 10 ETH and owes 12000 USD. The liquidation threshold is 0.82. (a) What ETH price makes the health factor equal 1? (b) If ETH is 2000 USD, what is the health factor? (c) At a price just below the answer to (a), a liquidator repays 4000 USD of debt with a 6% bonus. How much collateral value does the liquidator receive?
Show answer
(a) Price = debt / (threshold × units) = 12000 / (0.82 × 10) = about 1463.41 USD. (b) Health factor = 10 × 2000 × 0.82 / 12000 = 1.367. (c) The liquidator receives 4000 × 1.06 = 4240 USD of collateral value.
Exercise
Explain why a 5% liquidation bonus makes a cascade more likely than a 0% bonus would, and name one thing that happens to the protocol if the bonus is set too low.
Show answer
A bonus pays liquidators for gas, price risk and profit, so liquidators act quickly and sell the seized collateral at once. Fast, large sales add selling pressure that can push other positions below a health factor of 1. With a bonus set too low, liquidating becomes unprofitable once gas costs and price risk are counted, so liquidators stay away and unhealthy positions remain open until their collateral falls below the debt, creating bad debt for lenders or the protocol reserve.