JOVANA
Explore Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

Lending, leverage, and liquidations: how Aave and Compound work

A pawnshop that never sleeps, never asks your name, and only trusts collateral. Derive the health factor, the utilization-based interest curve, and the liquidation that keeps the whole thing solvent — with real Aave-style numbers.

A pawnshop that never sleeps

Walk into an on-chain money market and the deal is brutally simple. You hand over 10 ETH; you walk out with 12,000 USDC. Nobody asks your name, runs your credit, or checks your payslip. There is no loan officer to charm and no court that can chase you if you vanish. So the protocol leans on the only promise it can actually enforce: collateral worth more than the loan. This is overcollateralized lending, and it is the heart of how a lending protocol survives in a world where the borrower is an anonymous public key.

Two protocols defined the playbook. Compound (2018) and Aave (which grew out of ETHLend) both replaced the bank's matchmaking — find a lender, find a borrower, agree on terms — with a single shared pool per asset. Everyone who supplies USDC pours into one big USDC pool; everyone who borrows USDC draws from it. An interest rate, recalculated every block, balances the two crowds. No human sets your rate; an equation does.

Two sides of one pool

When you supply assets, you are not parking them — you are lending them to the pool's borrowers, and you earn the interest they pay. To track your growing claim, the protocol mints you a receipt token. Aave gives you aTokens (deposit 1,000 USDC, hold 1,000 aUSDC whose balance ticks upward as interest accrues — a rebasing token). Compound gives you cTokens whose quantity stays fixed but whose exchange rate to the underlying climbs. Either way, redeeming the receipt returns principal plus interest. The modern, standardized version of this idea is the ERC-4626 tokenized vault.

// Compound-style cToken: quantity is fixed, exchange rate rises.
// You supply 1,000 USDC when 1 cUSDC = 1.00 USDC  ->  receive 1,000 cUSDC.
exchangeRate = (cash + totalBorrows - reserves) / cTokenSupply;

// Interest accrues into totalBorrows each block, so the rate grows:
//   day   0:  1 cUSDC = 1.0000 USDC   ->  your 1,000 cUSDC = 1,000.00
//   day 365:  1 cUSDC = 1.0324 USDC   ->  your 1,000 cUSDC = 1,032.40
// You redeem cTokens at the higher rate; the +3.24% IS your interest.
Your interest is baked into a rising exchange rate, not a changing balance.

But there is a catch that shapes everything downstream: the pool can be drained of free cash. If borrowers have taken out almost everything suppliers put in, a supplier who wants to withdraw may find the cupboard nearly bare. The protocol cannot force a borrower to repay early, so it manages this tension with price — the interest rate — which we turn to after we know how much you can borrow.

How much can you borrow? LTV and the health factor

Every collateral asset carries two governance-set parameters. The Max LTV (loan-to-value) caps how much you may borrow against it; the Liquidation Threshold is the higher line at which you become liquidatable. The gap between them is your safety margin. Suppose ETH has Max LTV 80% and Liquidation Threshold 82.5%. You deposit 10 ETH at $2,000 = $20,000 of collateral, so you may borrow up to $16,000. You take a conservative $12,000 USDC — a collateralization ratio of 167%.

The single number that tells you how close you are to the edge is the health factor (HF). It weights each collateral by its liquidation threshold and divides by your total debt. Above 1 you are safe; the instant it dips below 1, your position is open season for liquidators.

// Aave health factor (all values in one common unit, e.g. USD)
healthFactor = sum(collateral_i * price_i * liquidationThreshold_i) / totalDebt

// Our position: 10 ETH @ $2,000, liqThreshold = 0.825, debt = 12,000 USDC
HF = (10 * 2000 * 0.825) / 12000
   = 16500 / 12000
   = 1.375          // healthy

// Liquidatable when HF < 1. Solve for the ETH price P that makes HF = 1:
//   (10 * P * 0.825) / 12000 = 1   ->   P = 12000 / (10 * 0.825) = $1,454.5
// ETH must fall ~27% (from $2,000) before you are at risk.
The health factor in one line, plus the exact price that triggers liquidation.

Read that result carefully. Borrowing only $12,000 against $20,000 bought you a 27% price cushion. Had you maxed out at $16,000, your HF would be (16,500 / 16,000) = 1.03 — a 3% dip would liquidate you. The discipline of professional borrowers is exactly this: keep the health factor comfortably above 1, because the market does not announce its crashes in advance.

The price of a loan: utilization-based interest

Nobody negotiates your rate. It is a deterministic function of utilization — the fraction of the pool that is currently borrowed, U = totalBorrows / totalSupplied. When U is low, money is idle and cheap. As U climbs toward an optimal point (say 90%), the rate rises gently. Past that kink, the slope turns vicious: a steep second leg makes the last drops of liquidity extremely expensive, bribing borrowers to repay and suppliers to deposit, so that withdrawing depositors are never left stranded.

// Aave-style two-slope ("kinked") interest rate model.
// Per-year rates; U is utilization in [0, 1].
function borrowRate(U) {
    if (U <= U_OPTIMAL) {
        return BASE + (U / U_OPTIMAL) * SLOPE1;
    } else {
        excess = (U - U_OPTIMAL) / (1 - U_OPTIMAL);
        return BASE + SLOPE1 + excess * SLOPE2;
    }
}
// USDC pool params:  BASE=0%, SLOPE1=4%, SLOPE2=60%, U_OPTIMAL=90%
//   U = 50%  ->  0 + (0.50/0.90)*4%            = 2.22%
//   U = 90%  ->  0 + 4%                        = 4.00%   (the kink)
//   U = 95%  ->  4% + (0.05/0.10)*60%          = 34.00%  (panic zone)

// Suppliers earn a share of what borrowers pay:
//   supplyRate = borrowRate * U * (1 - reserveFactor)
//   at U=90%, borrowRate=4%, reserveFactor=10%:
//   supplyRate = 0.04 * 0.90 * 0.90 = 3.24%
The kinked curve: gentle below the optimum, brutal above it.

Notice that suppliers always earn less than borrowers pay (3.24% vs 4.00% here). The wedge has two causes: utilization below 100% means not every supplied dollar is earning, and the reserve factor skims a cut into the protocol's treasury or safety module as a buffer against bad debt. This is also why the eye-watering supply APYs you sometimes see on a new pool are a warning, not a gift: they usually mean utilization is pinned near the kink, liquidity is thin, and withdrawal may be hard. Chasing them is one face of DeFi yield that demands you read the risk behind the number.

Liquidations: the keepers that keep it solvent

The moment your health factor drops below 1, the protocol throws your position open. Anyone — typically a bot called a keeper — may step in, repay part of your debt, and seize your collateral at a discount. That discount is the liquidation bonus (commonly 5–10%): the carrot that pays liquidators to do the protocol's dirty work the instant it becomes profitable. A close factor (50% on Aave v2) caps how much of the debt one liquidation call may clear, so you are usually liquidated in pieces, not all at once.

  1. An oracle update or a price drop pushes the borrower's HF below 1.
  2. A keeper bot spots it and calls liquidationCall(), repaying up to the close-factor share of the debt — here 50% of $12,000 = $6,000 USDC.
  3. In return it seizes collateral worth the repayment plus the 5% bonus: $6,000 * 1.05 = $6,300 of ETH.
  4. The borrower's debt and collateral both shrink, and the HF is nudged back above 1 — the position survives, lighter and bruised.

Run the numbers at the trigger price of $1,454.5. The keeper repays $6,000 and takes $6,300 of ETH ≈ 4.33 ETH, leaving you 5.67 ETH ($8,250) of collateral against $6,000 of debt. Your new HF = (8,250 × 0.825) / 6,000 ≈ 1.13 — healthy again. The brutal part: you just paid a $300 penalty to a stranger for the privilege. This liquidation is also a ferocious MEV game — bots race each other in the mempool for that bonus, often funding the repayment with a flash loan so they need no capital of their own.

Leverage by looping

Here is where lending stops being boring. Deposit ETH, borrow a stablecoin against it, swap the stablecoin back into ETH on a DEX, redeposit, and borrow again. Each turn of this loop (recursive borrowing) stacks more exposure on the same starting capital. Because each loop borrows only the LTV fraction of the last, the total is a geometric series that converges to a clean maximum: 1 / (1 − LTV). The swap leans on an automated market maker (AMM), and the looped position is, in spirit, a leveraged collateralized debt position.

// Recursive "looping" to build leverage on one collateral asset.
deposit(E);                       // start with E of your own equity
repeat:
    borrowable = LTV * freeCollateralValue();
    stable = borrow(borrowable);
    more   = swap(stable -> collateral);   // on an AMM / DEX
    deposit(more);

// Total deposits = E * (1 + LTV + LTV^2 + ...) = E / (1 - LTV)
// LTV = 0.80  ->  max leverage = 1 / 0.20 = 5x
//   total collateral = 5E,  total debt = 4E,  equity = 1E
// A flash loan can build the whole position in ONE transaction.
The looping recipe and the 1/(1−LTV) leverage ceiling.

At 80% LTV the ceiling is 5x, but nobody sane loops to the maximum: at 5x your equity is wiped by a mere ~20% adverse move, and the position liquidates well before that. Looping has three quiet killers. Liquidation risk is amplified — a small dip that a 1x holder shrugs off can erase a 5x position. Negative carry — if the borrow rate creeps above the yield on your looped asset, you bleed money every block just holding the trade. And correlation breaks — the popular trick of looping a liquid-staking token against ETH assumes they trade 1:1, but in June 2022 stETH slipped to a ~7% discount and forced loopers to unwind into a falling market. Leverage is a tool, not a free lunch; for directional bets, perpetual futures are often the cleaner instrument.

Failure modes and honest trade-offs

A lending protocol rests on three external assumptions, and each is a place where it has been broken. First, a correct price oracle: feed it a wrong price and you can mint bad debt out of thin air. In November 2022, an attacker pumped the thin CRV market and used inflated collateral to over-borrow on Aave, leaving ~$1.6M of bad debt when the price snapped back — a textbook brush with oracle manipulation. Second, liquid markets, so liquidators can actually sell seized collateral; thin, volatile, long-tail assets are exactly where Black-Thursday-style gaps happen. Third, sound parameters — LTVs, thresholds, and caps — which are set by governance and can be too generous.

Protocols responded with layered defenses: isolation mode (a risky new collateral can only borrow a capped amount of stablecoins, quarantining its blast radius), supply and borrow caps, and efficiency mode (e-mode) that grants higher LTV only between tightly correlated assets like two stablecoins. None of this removes the deepest risks — a DeFi deposit is also exposed to smart-contract bugs and to governance itself, since a captured token vote could in principle change the very parameters protecting you.

Strip away the jargon and the achievement is striking: lending protocols replaced the human credit officer with three pieces of math — collateral you must overpost, an oracle that prices it, and a liquidation bonus that pays strangers to enforce the rules. That is DeFi's credit layer, and its honest cost is capital inefficiency: locking $20,000 to borrow $12,000 is the price of needing to trust no one. The open frontier — undercollateralized lending, on-chain credit scores, real-world-asset collateral — is the industry's attempt to win back that efficiency without re-importing the very trust assumptions blockchains were built to delete.