Skip to main content
Avana logo

Liquidation Flow

Every step of one liquidation, in execution order, with the checks, formulas and payouts LPVaultSwap applies, and the steps the flash liquidation helper adds around a flash-funded call.

Overview

One call to LPVaultSwap.liquidate liquidates one account, in its one collateral market, against one debt reserve, and settles it in the same transaction. Every amount is measured as a balance change within the call, never as an absolute balance and never from another contract's return value. If any step fails, the whole transaction reverts.

LPVaultSwap takes no flash loan: every step runs directly in the call, funded by the caller. A flash-funded liquidation wraps the whole call inside the flash liquidation helper's flash-loan callback, and LPVaultSwap runs the same steps with the helper as its caller. No step before the unwind touches the market's own pool.

Who can call, and when an account is eligible, is on the design page: Liquidation Design.

Notation

Every settlement amount is in base units of the repaid debt asset: 6 decimals for USDC and USDT, 18 for GHO and WETH. Prices are 8-decimal USD. Basis points use 10,000 = 100%. ⌊·⌋ rounds down and ⌈·⌉ rounds up.

SymbolMeaning
XdebtToCover, the most debt asset LPVaultSwap pulls from the caller
KfCaller funding: the debt asset LPVaultSwap received from the caller, 0 < Kf ≤ X. Kf equals X unless the asset charges a transfer fee.
DDebt asset Aave pulled in its liquidation call, never more than Kf
cVault-token units LPVaultSwap received
b, lf, bNetAave liquidation bonus, Aave liquidation fee (0 by the listing settings), net bonus, in bps where 10,000 means no bonus
Pc, PdebtVault-token and debt-asset prices served to Aave
VOracle value of the seized units in the debt asset
UOne raw unit of each unwound token, valued in the debt asset
s, sLegEffective slippage of the floor; slippage of each swap leg
minOutRecovery floor
R, R′Debt asset recovered from the seized collateral; R plus the caller's shortfall top-up
GOracle gain, max(0, V − D)
YRealized surplus, max(0, R′ − D)
A, Kr, BAvana fee, caller reward, borrower surplus; A + Kr + B = Y
keeperOutThe caller's payout, Kf + R′ − D − A − B: the funding Aave did not use, the recovered principal and the reward
F, φA flash liquidation helper's loan and its premium. They appear only in the helper's own steps; no formula of LPVaultSwap contains them.

Call Parameters

The call is liquidate(LiquidationParams params).

FieldMeaning
proxyThe borrower's PositionProxy, the Aave account of one wallet in one market
marketIdThe proxy's collateral market
debtReserveIdThe debt reserve to repay, enabled on the CDP Spoke
debtToCoverThe debt asset LPVaultSwap pulls from the caller. The amount that arrives is Aave's bound, and the part Aave does not use returns to the caller.
routeModePrimaryThenBackup or BackupOnly, either value for every caller
minAmountsOptional least amount of each market token the unwind must return; empty means 0 for every token. It can only make the call revert.
deadlineLast valid block timestamp, in seconds on every chain
minPayoutSmallest caller payout accepted. The payout includes the returned funding, so this is the funding plus the smallest net payout accepted.
maxShortfallMost of the caller's own debt asset the call may pull beyond its funding, to close a gap below the recovery floor; 0 disables it

The struct has no caller-funds or flash-amount field: the caller always funds debtToCover itself, and how it obtains the debt asset is outside LPVaultSwap. A caller can never supply a route address, a lender, a funding source, a recipient or an override of the recovery floor. The deadline and the minimum payout can only make the call revert, and maxShortfall only adds the caller's own funds.

Sizing the call

  • debtToCover is the simulated Aave amount. When Aave's dust rule asks for the whole debt, the caller quotes the whole debt plus a 500 bps margin, rounded up.
  • The minimum payout is the funding plus the previewed net payout less at least 1% of that net payout: minPayout ≤ X + ⌊0.99 × (previewed keeperOut − X)⌋.
  • The deadline is a few blocks ahead, for example t + 36 on Ethereum (three blocks) or t + 6 on Base. On Ethereum, callers submit through private order flow.
Example: a simulation shows a whole debt of 1,950 USDC, so debtToCover is ⌈1,950 × 1.05⌉ = 2,047.5 USDC. A 1-wei repay lands first, Aave pulls 1,949.999999 USDC, and the 97.500001 USDC it did not pull returns to the caller inside its payout.

Settlement Steps

The steps below run in this exact order, for every caller.

#StepWhat happens
1DeadlineLPVaultSwap reverts with DeadlineExpired if the block timestamp is past the deadline, before the lock and before any external call.
2Lock and entry checksLPVaultSwap takes the chain's protocol lock (LockHeld if held), then checks the amounts (InvalidAmount), a frozen caller (AddressIsFrozen), the proxy (UnknownProxy), the debt reserve (UnknownDebtReserve) and the route mode. There is no keeper check, and the pause state is not read.
3Resolve the marketFrom the MarketRegistry: the CDP Spoke, home Hub, collateral reserve, vault token, AMM integration and its LP Vault, pool and exact range, the market's tokens and swap routes; the debt reserve's asset, decimals, funding Hub, price source and Avana Umbrella (UnknownMarket on mismatch).
4Poke oracles and check pricesLPVaultSwap pokes the market's LP Oracle and the repaid reserve's DebtOracle, then checks the health factor (NotLiquidatable), the collateral price (StalePrice), recovery grace (GraceHealthFactor), Hub shares against assets (SharesNotEqualAssets) and the debt price (DebtPriceStale).
5Sequencer gateDown reverts with SequencerDown. During the grace period after a restart, only accounts below a health factor of 0.95 pass (SequencerGrace). Ethereum is always open.
6Read the bonusThe health factor, the bonus b and the liquidation fee lf from the Spoke, read in the same call and block as the liquidation, so they equal what Aave applies; the debt price Pdebt.
7No pool spot checkLPVaultSwap reads no pool spot price. A moved pool never reverts the call or changes its route mode.
8FundLPVaultSwap pulls X of the debt asset from the caller and measures Kf as its own balance change, reverting with FundingMismatch unless 0 < Kf ≤ X. It calls no flash source and no lender.
9beginSeizureCollateralization checks the lock and the caller, checks Hub shares against assets, and stores the proxy's supplied shares and the vault token's total supply in transient storage.
10liquidationCallLPVaultSwap approves the Spoke for exactly Kf and calls the liquidation with Kf as the bound and receiveShares set to false, then resets the approval. Aave validates, sizes the repayment, pulls D to the funding Hub and sends c vault tokens from the home Hub to LPVaultSwap. It reports deficits if the call empties the collateral.
11Measure D and cBoth measured as balance changes. If c is 0 the call reverts with NothingSeized. The unused Kf − D stays in LPVaultSwap and returns to the caller inside keeperOut; it is never swapped.
12Open the recovery windowLPVaultSwap records its balance of each market token and of the debt asset. The caller's funding and the unused debt asset stay outside the window of R.
13burnSeizedThe AaveAdapter, the vault token's only burner, burns the c units from LPVaultSwap's balance (SeizedUnitsBurned).
14settleSeizureCollateralization checks the snapshot, the pool lock, that the share drop equals c and that the supply drop equals c. It reconciles any earlier unsettled seizure of the proxy, debits c units from the proxy's records, and has the LP Vault unwind exactly those units.
15Measure the unwindLPVaultSwap measures the amount aᵢ of each market token it received. Uncollected fees never enter these amounts.
16Recovery floorLPVaultSwap computes the net bonus, the effective slippage, V, U and the floor minOut in the debt asset, and each leg's minimum.
17Swap legsEach token that is not the debt asset is swapped over its route at its own oracle-derived minimum, in the route mode the caller set. R is the debt asset received from the start of the window to the end of conversion.
18Shortfall checkThe shortfall is max(0, minOut − R). Above maxShortfall the call reverts with RecoveryBelowFloor; otherwise the shortfall is pulled from the caller.
19WaterfallLPVaultSwap computes G, Y, A, Kr, B and keeperOut (a defensive InsufficientProceeds check), then checks keeperOut against minPayout (PayoutTooLow).
20Pay outA to the fee recipient, then B to the borrower's wallet, then keeperOut to the caller, all in the debt asset; then any route residues and dust legs to the caller. Zero amounts are skipped. A refused fee, surplus, residue or dust leg goes to the PayoutEscrow; a failed transfer of keeperOut reverts the whole call.
21Event and lockLPVaultSwap emits LiquidationSettled and releases the lock. Its net balance change is 0 in every token, and every allowance it granted is 0.

Caller Funding

LPVaultSwap pulls the caller's funding with a transferFrom of X from the caller before any other transfer, and measures the rise of its own balance as Kf. The caller is LPVaultSwap's only source of the debt asset in a liquidation. Callers always fund in the debt asset of the reserve they repay, so no swap into the debt asset is needed and no leftover is sold back.

  • The call reverts with FundingMismatch unless 0 < Kf ≤ X.
  • Kf, not X, is Aave's bound, so D ≤ Kf always holds: Aave pulls the repayment out of the caller's own funding.
  • The unused Kf − D returns to the caller inside keeperOut, unswapped. Oversizing debtToCover costs the caller nothing at LPVaultSwap.
  • A debt asset is enabled only while its transfer fee is zero. If a fee is switched on later, Kf is what arrived and keeperOut is what LPVaultSwap sends, and the fee on both transfers falls on the caller alone.
Example (USDT with a transfer fee): debtToCover of 5,000 USDT delivers Kf = 4,995 USDT, and 4,995 USDT is Aave's bound.

liquidate takes no flash loan, and callers batch accounts with separate calls. The core flash source, read from the MarketRegistry's flashSource, serves only repay with collateral. Its callback reverts if it is called while LPVaultSwap holds the lock, which is always the case inside liquidate.

Flash Liquidation Helper

The flash liquidation helper lets a caller that holds no debt asset liquidate. It is a periphery contract outside the core contracts: public, immutable, with no owner, admin, upgrade path, setter, sweep, rescue or arbitrary-call function, and holding no funds or allowances between transactions. One public instance per chain borrows from that chain's Aave V3 Pool (the Ethereum Core Pool; on Base 0xA238Dd80C259a72e81d7e4664a9801593F98d1c5). An operator can deploy its own instance of the operator variant. LPVaultSwap treats every helper as an ordinary caller.

Interface

The helper implements IFlashLiquidator, whose entry point is flashLiquidate(FlashLiquidationRequest request), returning the caller's net payout. The operator variant implements IOperatorFlashLiquidator, which adds SIGNER, FUNDING_SAFE, MAX_TOP_UP_BPS and claimEscrowed.

Request fieldMeaning
paramsThe LiquidationParams, passed to liquidate unchanged
flashAmountThe loan F, with 0 < F ≤ debtToCover
maxPremiumThe most premium the caller accepts on F
maxTopUpThe most debt asset the helper may pull from the caller after liquidate, to repay F plus the premium
minPayoutThe smallest net payout accepted after the loan is repaid

The helper also exposes maxFlashLoan(asset), the Pool's idle liquidity of the asset (0 while the reserve is inactive, paused or not enabled for flash loans), and flashPremium(asset, amount), which is 0 while the helper holds FLASH_BORROWER and otherwise the Pool's premium rounded up. Its immutables are POOL, LP_VAULT_SWAP, MARKET_REGISTRY and PARAMETER_STORE.

Steps up to the liquidation

  1. Checks, in order: no other helper context is open (ContextActive); in the operator variant, the caller is the signer (NotSigner); 0 < F ≤ X (InvalidFlashAmount); the debt asset is read from the MarketRegistry; and F is within the Pool's idle liquidity (InsufficientFlashLiquidity). The helper also refuses a Pool recorded as a Hub (FlashSourceIsHub), at deployment and on every call.
  2. The helper records a single-use context in transient storage: the Pool, itself as initiator, the asset, F, the premium and top-up bounds, the hash of the parameters, the payer and the payout recipient.
  3. If F is below X, it pulls X − F of the debt asset from the payer.
  4. It calls the Pool's flashLoan, not flashLoanSimple, because only flashLoan waives the premium for FLASH_BORROWER.
  5. In the callback, executeOperation accepts only the recorded Pool as caller, itself as initiator, one asset, the recorded asset and amount, and matching parameters, and marks the context used so a second callback fails (InvalidFlashCallback). It reverts with PremiumTooHigh above the caller's maxPremium, and with FlashFeeTooHigh above the ParameterStore's maxFlashFeeBps.
  6. It approves LPVaultSwap for exactly X, calls liquidate with the parameters unchanged, resets the allowance and measures keeperOut as its own balance change.
φ ≤ maxPremium
φ × 10,000 ≤ maxFlashFeeBps × F

maxFlashFeeBps applies only to the helper and to repay with collateral; no check of liquidate reads it. It is 10 bps at launch (bounds 0 to 100), set strictly above the Pool's premium while that premium is above 0, and lowered to 0 once both the helper and the core flash source hold FLASH_BORROWER.

Example: a loan of 2,000 USDC at 5 bps carries a premium of 1 USDC. With maxPremium of 1 USDC the loan proceeds. At 6 bps (1.2 USDC) the helper reverts before LPVaultSwap is called, and the caller resubmits with its own funds or a smaller loan.

Inside the callback LPVaultSwap runs every step above exactly as for any caller: it checks that the helper is not frozen, pulls Kf from the helper and pays keeperOut directly to the helper or reverts. No check or formula of LPVaultSwap depends on the loan. The helper's repayment of the loan is described in its own section below.

Public helper and operator variant

ItemPublic helperOperator variant
Who may callAnyoneOnly its signer
Payer and payout recipientThe caller itselfThe operator's funding Safe
Top-up boundThe request's maxTopUpThe smaller of maxTopUp and ⌊X × MAX_TOP_UP_BPS / 10,000⌋
FLASH_BORROWERRequested in each chain's deployment payloadNone unless an Aave proposal adds one, so it pays the Pool premium
Committed operator registryNever registered, because it commits to nothingThe operator registers this helper, or its signer when it calls liquidate directly
Escrowed residuesNo claim function; a credit can arise only when a market token refuses the helper itselfclaimEscrowed, callable by the signer, pays the credit to the funding Safe

The helper takes no swap step, route, foreign recipient or executable calldata from the request. The unwind and the routes stay in the core.

Seizure, Burn and Unwind

Aave liquidation

The standard Spoke validates the call (not a self-liquidation, amount above 0, reserves not paused, collateral supplied, debt drawn in the reserve, health factor below 1), sizes the repayment against its target health factor with its dynamic bonus and dust rule, pulls D out of the caller's funding, and removes c vault tokens from the home Hub to LPVaultSwap. Receiving shares instead of tokens is disabled on the reserve, so LPVaultSwap always passes false.

Burn and ledger checks

The AaveAdapter burns the c units, then Collateralization checks that the drop in the proxy's supplied shares equals c (DebitMismatch) and that the drop in the vault token's supply equals c (SupplyDropMismatch). Collateralization reads the Spoke, Hub, reserve and vault token only from the vault token's immutables, never from the caller. It also refuses to unwind while the pool is inside a callback (PoolLocked), reading each AMM's own slot layout for that check only.

Record walk

Collateralization debits c units from the proxy's records, largest credited record first, ties by lowest record ID. It stops at the first record that covers the remainder, so at most one record is partly debited. A record at 0 units stays open for its depositor. An account holds at most 16 records per market. Every record of a market has the market's exact range, so the units are interchangeable and the order has no economic effect. If the records hold fewer than c units, the call reverts with InsufficientCredit.

Before debiting c, Collateralization reconciles any shares an earlier, unsettled seizure took without a debit. It debits those units too, unwinds them into its pending balance, and emits SeizureReconciled. Those tokens are settled later by settlePending and never paid out inside the liquidation.

Unwind

For each debited record, the market's LP Vault removes exactly the debited units and sends the principal to LPVaultSwap. For Uniswap v3 and Aerodrome Slipstream it calls decreaseLiquidity with zero minimums, then collect capped at the principal, so fees owed to the position stay with it for the depositor. Collateralization releases the record's exposure on a fixed basis: the remaining charge is the original charge times remaining units over original units, rounded up.

Example: a record pledged with 600,000,000 units and a 1,200 USD charge is debited 200,000,000 units. It keeps ⌈1,200 × 400 / 600⌉ = 800 USD of charge and releases 400 USD of cap.

Swap Legs

For each market token and each enabled debt asset, the MarketRegistry records a primary and a backup swap route. Each route contract has a fixed path set at deployment, takes only LPVaultSwap as caller, and enforces the minimum output it receives (MinOutNotMet).

  • Route types: DexPath (fixed pool hops on Uniswap v3, Slipstream, Curve or Balancer), PegModule (a GHO Stability Module on Ethereum, backup slot of a GHO debt reserve only, or the Sky LitePSM for DAI or USDS into USDC), and WrapperThenDex (one unwrap step, then pool hops).
  • A route never trades through the market's own pool, which is being unwound in the same transaction. Any pool callback is accepted only from the pool fixed in the route.
  • The backup shares no external contract and no intermediate token, other than the debt asset, with the primary, so one failure cannot disable both.
  • A GHO Stability Module is never a primary route.
  • Listing requires both routes of every token to swap the full one-sided value of the largest position within the market's slippage allowance.
  • In PrimaryThenBackup mode the primary is called first and the backup only if the primary is not usable or reverts. In BackupOnly mode only the backup is called. Both modes are open to every caller and are held to the same floor and leg minimums.

Per-leg minimum

Every leg runs with a minimum output derived from oracle prices, primary and backup alike. No swap of a liquidation runs without one.

minOutᵢ = max(1, ⌈Vlegᵢ × (10,000 − sLeg) / 10,000⌉ − Ulegᵢ − ⌊floorRoundingAllowance / k⌋)

Vlegᵢ is the leg's value in the debt asset at the LP Oracle's capped leg price, Ulegᵢ is one raw unit of the token in the debt asset, k is the number of legs swapped, and sLeg is the leg slippage (the effective slippage s, widened by a shortfall allowance as described below).

Example: a 4,998 USDT leg at 0.9998 USD into USDC, with sLeg of 100 bps, one leg swapped and a 1 USDC allowance: Vleg = 4,997.0004 USDC, and the minimum is 4,947.030396 − 0.000001 − 1 = 4,946.030395 USDC.

Dust legs, residues and failed routes

  • A token worth at most about one raw unit of the debt asset is a dust leg. It is not swapped: LPVaultSwap sends it whole to the caller and counts it as 0 toward R. Otherwise every route could return 0 for it and the account could never be liquidated.
  • Input or intermediate tokens a route returns unconverted count as 0 toward R and go to the caller (ResidueReturned). A residue never stands in for recovery, because the floor and each leg's minimum are met in the debt asset alone.
  • Dust legs and residues are delivered with the gas-limited transfer of the payout step. If a token refuses the caller, the amount is credited to the caller in the PayoutEscrow.
  • A primary that reverts emits RouteFailed, its approval is reset to 0, and the backup is called. If no usable route converts a token, the call reverts with NoRouteAvailable.
  • Route records change only by timelock: setRoute at the normal delay (5 days), disableRoute and restoreRoute of a previously approved route at the short delay (12 hours). An operation that only restores routes can be cancelled only by the Aave governance executor.

Unwind at any pool price

The unwind runs at zero per-token minimums because the LP Oracle values a position at its fair composition, the minimum of its oracle value over all pool prices. Removing the liquidity at any pool price returns tokens worth at least V at oracle prices. What a moved pool can still distort is a swap, and every swap leg has its own oracle minimum. A spot gate would add nothing and would let anyone keep an underwater account alive by moving a thin pool before each attempt.

Example: a full-range USDC/USDT position worth $10,000 at $1.00 each holds about 5,000 of each token. An attacker moves the pool to 2 USDT per USDC. The position now holds 3,535.53 USDC and 7,071.07 USDT, worth $10,606.60 at oracle prices. A caller seizes and unwinds it at that pool price, the USDT leg must still return its oracle minimum, and the floor is computed from V = 10,000.

Recovery Floor

The floor is computed in the debt asset, so the same rule serves GHO, USDC, WETH or any other debt reserve. It allows exactly the swap loss that Aave's net bonus can pay for.

bNet = 10,000 + ⌊(b − 10,000) × (10,000 − lf) / 10,000⌋ (10,000 when b ≤ 10,000)
s = min(slippageAllowanceBps, ⌊10,000 × (bNet − 10,000) / bNet⌋), or 0 when bNet ≤ 10,000
V = ⌊c × Pc × 10^dd / (10^dv × Pdebt)⌋
U = Σᵢ ⌈pᵢ × 10^dd / (10^dᵢ × Pdebt)⌉ (a token that is the debt asset counts 1)
minOut = max(0, ⌈V × (10,000 − s) / 10,000⌉ − U − floorRoundingAllowance)
  • s solves bNet × (1 − s) ≥ 1, so the slippage term alone recovers the debt repaid, up to one vault unit and 1 base unit. slippageAllowanceBps is 100 at launch, so s is at most 1%.
  • The formula has no flash-premium or transfer-fee term. LPVaultSwap takes no flash loan, and a helper's premium is the helper's cost.
  • V uses the prices Aave used for the seizure, so the floor measures swap loss only, never a price difference between Avana and Aave.
  • U and floorRoundingAllowance let dust liquidations settle. AMM removals and swaps round down by up to one raw unit per token. Without these terms a dust liquidation would revert on every attempt, and its deficit would never be recorded. Any amount they leave the recovery below D comes out of the caller's payout.
  • floorRoundingAllowance is set per debt reserve when it is enabled: one whole token for a USD stablecoin (1,000,000 for USDC, 10^18 for GHO) and 0.0005 WETH for WETH debt.
  • The floor depends on no caller input. V rounds down and the slippage term rounds up, both against the caller.
Example (Ethereum, USDC debt): c = 4,998 vault tokens at Pc = 2.00 and bNet = 10,200. s = min(100, ⌊10,000 × 200 / 10,200⌋) = 100. V = 9,996 USDC. With USDC at 1.0000 and USDT at 0.9998, U = 2 base units. minOut = 9,896.04 − 0.000002 − 1 = 9,895.039998 USDC.

When the bonus cap binds

When slippageAllowanceBps is at or above the cap the bonus sets, s sits at that cap and minOut falls to about D. A caller that routes the recovery down to the floor then leaves Y near 0, and Avana's fee near 0 with it. The fee is best-effort in such a market: the floor still protects the debt repaid and the borrower.

Example: the same seizure in a market listed with slippageAllowanceBps = 300 gives s = min(300, 196) = 196. The slippage term is 9,800.0784 USDC and minOut = 9,799.078398 USDC, below D = 9,800 USDC. Routes returning exactly minOut give Y = 0 and A = 0 although G = 196 USDC, and the caller's payout is Kf − 0.921602 USDC.

Shortfall and Rounding

Shortfall top-up

After the swaps, LPVaultSwap computes the amount the caller must add to reach the floor:

shortfall = max(0, minOut − R)
  • If the shortfall exceeds maxShortfall, the call reverts with RecoveryBelowFloor. The caller retries with a larger maxShortfall, a smaller debtToCover or the other route mode.
  • Otherwise LPVaultSwap pulls exactly the shortfall from the caller, and R′ = R + shortfall.
  • The floor is checked on R alone, so unused caller funds cannot hide a poor recovery. Only an explicit, capped top-up closes the gap.

A caller that allows a top-up also lets each leg run at a wider slippage, which keeps liquidations running at full size when routes trade below the oracle in a crash:

sLeg = min(9,999, s + min(maxShortfallBps, ⌊maxShortfall × 10,000 / V⌋))

maxShortfallBps is 1,000 at launch (bounds 0 to 5,000), so a top-up buys at most 10% more slippage. Avana's fee does not fall when a shortfall is paid, and the borrower surplus is 0 in that case, so a caller's top-up never reaches the borrower.

Example: V = 12,422.6 USDC, s = 100 bps and maxShortfall = 200 USDC. The legs run at 260 bps, the routes return 12,174 USDC, 123.373998 USDC is pulled from the caller, and the liquidation settles at full size.

Rounding: the caller bears a recovery below the debt

Aave pulls D out of the caller's funding, so Kf ≥ D, and there is no settlement gap for LPVaultSwap to close. A recovery at or above the floor but a few units below D is the caller's loss, D − R′, taken from keeperOut. No Avana contract pays it, and no settlement budget exists.

  • For any recovery at or above the floor, the loss is at most one vault unit's value plus U + floorRoundingAllowance plus (2 + ⌈drawnIndex / RAY⌉) debt-asset base units.
  • The caller that chose the liquidation's size and funding bears it. Avana's keeper holds enough of each chain's debt assets to fund the whole repayment and that loss, and accepts the loss.
  • A flash-funded caller covers it through the helper's top-up bound, or the helper reverts and the caller resubmits from its own funds.
Example (Ethereum, USDC dust case): D = 0.78 USDC, R = 0.77 USDC, minOut = 0, and the caller funds Kf = 0.78 USDC. The shortfall is 0, Y = A = Kr = B = 0, and keeperOut = 0.78 + 0.77 − 0.78 = 0.77 USDC: a 0.01 USDC loss the caller accepts with a minimum payout of at most 0.77 USDC. Through the public helper with a 0.78 USDC loan, no premium and a top-up bound of 0.02 USDC, LPVaultSwap pays the helper 0.77 USDC, the helper pulls 0.01 USDC from its caller, repays the Pool 0.78 USDC and pays its caller 0. With a top-up bound of 0, the helper reverts and the whole liquidation reverts.

Payout Waterfall

G = max(0, V − D)
Y = max(0, R′ − D)
A = min(⌊G × avanaFeeShareBps / 10,000⌋, Y)
Kr = min(Y − A, G − A)
B = Y − A − Kr
keeperOut = Kf + R′ − D − A − B
  • Avana's fee A is 20% (avanaFeeShareBps = 2,000, bounds 0 to 5,000) of the oracle gain G, never above the realized surplus Y. While Y covers it, A depends only on the oracle value of the seizure and the debt repaid, never on how the caller swapped. Since A never exceeds Y, the fee alone never makes a liquidation revert. It is best-effort where the bonus cap binds.
  • The caller reward Kr is the rest of the oracle gain, capped by what was realized.
  • The borrower surplus B is the recovery above the seized collateral's oracle value. It is non-zero only when the routes beat the oracle price, so a favourable price move during settlement goes to the borrower. B is paid even when the same call leaves a deficit.
  • A + Kr + B = Y exactly. A rounds down, so rounding dust stays with the borrower.
  • When R′ ≥ D, keeperOut = Kf + Kr: the whole funding back plus the reward. When R′ is below D, keeperOut = Kf − (D − R′): the caller bears the difference. It is never negative; a defensive check reverts with InsufficientProceeds if it would be.
  • The caller's net result is keeperOut − Kf − shortfall. A helper's premium comes out of the caller's share, never out of A or B.

The debt asset is conserved: Kf + R + shortfall = D + A + B + keeperOut. LPVaultSwap never keeps or creates the debt asset.

Payout order

  1. Avana's fee A to the fee recipient read from the ParameterStore. A zero fee recipient reverts with InvalidFeeRecipient.
  2. The borrower surplus B to the borrower's wallet, the wallet the AaveAdapter records for the proxy (BorrowerSurplusPaid).
  3. keeperOut to the caller, by a plain transfer. If it fails, the whole liquidation reverts.
  4. Route residues and dust legs to the caller.

No recipient is taken from calldata, nothing accumulates in LPVaultSwap, and every zero-amount transfer is skipped. Each payout is measured as the recipient's balance change.

Example (Ethereum, USDC debt): Kf = D = 9,800, V = 9,996, and the routes return R = 9,950 USDC. G = 196, Y = 150, A = min(⌊196 × 0.2⌋, 150) = 39.2, Kr = min(110.8, 156.8) = 110.8, B = 0 and keeperOut = 9,800 + 9,950 − 9,800 − 39.2 = 9,910.8 USDC, the 9,800 USDC funded plus 110.8. Conservation: 9,800 + 9,950 = 9,800 + 39.2 + 9,910.8 = 19,750. Through the public helper with a 9,800 USDC loan and no premium, the helper receives 9,910.8 USDC, repays the Pool 9,800 USDC and pays its caller 110.8 USDC. With R = 10,010 USDC instead: Y = 210, A = 39.2, Kr = 156.8, B = 14 USDC to the borrower and keeperOut = 9,956.8 USDC.

Minimum payout

After the waterfall, LPVaultSwap reverts with PayoutTooLow if keeperOut is below minPayout. The check only adds a revert: it changes no amount, route or recipient, and the floor stays computed from the oracle alone. The floor protects Avana and the borrower; this check protects the caller.

Example: the caller above funds 9,800 USDC and sets minPayout = 9,909 USDC (its funding plus a net 109 USDC, more than 1% below the previewed net 110.8). The liquidation pays 9,910.8 USDC and succeeds. Had the routes returned R = 9,935 USDC, then Y = 135, A = 39.2, Kr = 95.8, keeperOut = 9,895.8 USDC, and the call reverts with PayoutTooLow(9,895,800,000, 9,909,000,000).

Flash Repayment Through the Helper

LPVaultSwap repays no flash loan. In a flash-funded call, the helper repays the Pool after liquidate returns, still inside the Pool's callback:

  1. The helper owes F + φ. If keeperOut is below that, it pulls the difference from its payer as a top-up, and reverts with TopUpExceeded above the bound. A revert here reverts the whole liquidation.
  2. It approves the Pool for exactly F + φ and returns; the Pool pulls the amount.
  3. After flashLoan returns, the helper computes its caller's payout as its own balance change over the whole call, keeperOut + top-up − F − φ, and reverts with PayoutTooLow below the request's minPayout.
  4. It sends that payout, and any market-token residues or dust legs LPVaultSwap paid it, to the payout recipient, resets every allowance, and emits FlashLiquidated.

The helper pays only after flashLoan returns, so nothing leaves it while the loan is open. The premium on the whole loan, including any part the debt did not need, and any transfer-fee loss on the helper's own transfers come out of the caller's payout. They never reduce Avana's fee or the borrower surplus. The request's minPayout is net of the loan and premium; the liquidation's own minPayout still bounds keeperOut, and a helper caller may leave it at 0.

Example (Ethereum, USDC debt, helper without FLASH_BORROWER): the helper borrows 1,950 USDC at 5 bps, a premium of 0.975 USDC. LPVaultSwap pays it keeperOut = 2,020.8 USDC, the helper repays 1,950.975 USDC and pays its caller 69.825 USDC, which passes a minimum of 69 USDC.
Example (oversized loan): the margined amount of 2,047.5 USDC borrowed whole at 5 bps carries a premium of 1.02375 USDC. LPVaultSwap pays the helper 2,118.3 USDC, including the 97.5 USDC Aave did not use. The helper repays 2,048.52375 USDC and pays its caller 69.77625 USDC, so the premium on the unused 97.5 USDC, 0.04875 USDC, falls on the caller alone.

Refused Payouts

Avana's fee, the borrower surplus, and each route residue or dust leg owed to the caller use a gas-limited delivery that cannot revert the liquidation. The residue of settlePending to the fee recipient uses it too. The caller payout keeperOut does not: it is paid by a plain transfer, and a failure reverts the call.

  1. LPVaultSwap requires enough gas left for the attempt plus a post-call reserve, at least ⌈100,000 × 64 / 63⌉ = 101,588 gas plus that reserve, else InsufficientGas. This stops a caller from starving the call to push a payout into the escrow.
  2. It calls the token's transfer with exactly 100,000 gas (PAYOUT_TRANSFER_GAS) and reads at most 32 bytes of return data.
  3. If the transfer reverts, returns false or runs out of gas, LPVaultSwap approves the PayoutEscrow for exactly the amount and calls its deposit, credited to the recipient. The liquidation continues. Only a revert of the deposit itself reverts the call.

The PayoutEscrow is immutable, one per chain, with no owner, role, setter, pause or sweep, and holding refused payouts is its only job. Only LPVaultSwap can deposit, and only while it holds the lock. The credited account later calls claim(token, recipient) to receive its whole credit at an address it chooses. No Avana switch, pause or address freeze can hold a credit. Deposits emit RemainderEscrowed and claims emit RemainderClaimed.

Why the caller payout is never escrowed: it contains the caller's returned funding, and a flash-funded caller repays its loan from it in the same transaction, so an escrowed payout would leave the loan unpaid and the transaction would revert anyway. The caller chose its own address and controls whether it can receive the debt asset. A blocklisted caller blocks only its own call; any other address can liquidate the account.

Example: a borrower's wallet is on USDC's blocklist and the liquidation owes it a 14 USDC surplus. The transfer fails, the 14 USDC is deposited in the escrow credited to the wallet, and the liquidation completes. The borrower later claims it to another wallet that USDC accepts.
Example: Circle blocklists the treasury Safe that is the fee recipient. In a liquidation that owes a 19.5 USDC fee, the transfer to the Safe reverts within its 100,000 gas, LPVaultSwap deposits 19.5 USDC in the escrow credited to the Safe, pays keeperOut of 2,020.8 USDC to the caller and completes. Had the caller's own address been blocklisted, the transfer of keeperOut would revert and the whole liquidation with it.

Events

ContractEvents
LP Oracle, DebtOraclePriceStateChanged, DisagreementRecorded
Aave V3 Pool (flash-funded calls only)FlashLoan, with the helper as target and initiator
Flash liquidation helperFlashLiquidated
CDP SpokeLiquidationCall
Funding HubReportDeficit (deficit case, per debt reserve)
Vault tokenTransfer from the Hub to LPVaultSwap, and from LPVaultSwap to the zero address
AaveAdapterSeizedUnitsBurned
AMM protocol and LP VaultDecreaseLiquidity, Collect, UnitsUnwound
CollateralizationRecordDebited, SeizureSettled, SeizureReconciled, PendingSettled
LPVaultSwapRouteFailed, ResidueReturned, BorrowerSurplusPaid, LiquidationSettled, PendingSettlementForwarded
PayoutEscrowRemainderEscrowed, RemainderClaimed
Avana Umbrella (Coverage Spoke)ReserveFunded (pending settlement)

Event fields

  • LiquidationSettled carries the caller, the proxy and the market (all indexed), with the debt reserve and debt asset, debt repaid, units seized, amounts unwound, recovered amount, floor, effective slippage, net bonus, caller funds, surplus, Avana fee, keeper reward, borrower surplus, caller payout, minimum payout, route mode, routes used and shortfall. It has no flash field and no flag for the kind of caller, because LPVaultSwap takes no loan and every caller uses the same entry point.
  • BorrowerSurplusPaid carries the proxy, the wallet, the debt asset, the amount and whether it was escrowed.
  • ResidueReturned carries the caller, the token, the amount and whether it was escrowed. It covers route residues and dust legs.
  • FlashLiquidated carries the helper's caller, the payout recipient, the asset, the flash amount, the premium, keeperOut, the top-up and the payout.
  • FlashLoanUsed is emitted only by repay with collateral, never by a liquidation.

A deficit appears in the funding Hub's ReportDeficit event of the same transaction. A failed attempt emits nothing, because every liquidation is one transaction.

LPVaultSwap writes no breaker state. Monitoring computes its alerts off-chain from these events and from reverted calls: collateral seized above 20% of a market in 1 hour, and 3 route failures in 1 hour.

Errors

ErrorWhen
AddressIsFrozenThe caller of liquidate is on the chain's freeze list. It does not fire for a frozen address that calls through the public helper.
InvalidAmountdebtToCover is 0, debtToCover or maxShortfall exceeds the uint128 range, or minAmounts has the wrong length
FundingMismatchThe caller funding is outside 0 < Kf ≤ X, or a shortfall pull delivered a different amount
RecoveryBelowFloorThe gap below the recovery floor exceeds maxShortfall
InsufficientProceedsDefensive only: unreachable while Kf ≥ D, it guards against a faulty balance measurement
PayoutTooLowkeeperOut is below the call's minPayout, or a helper's net payout is below the request's minPayout
InsufficientGasGas left is below a payout's headroom; the caller retries with more gas
KeeperFloorremoveKeeper would leave fewer than keeperFloor active committed operators
ContextActive, NotSigner, InvalidFlashAmountHelper: a nested call, a caller other than the operator variant's signer, or a flash amount outside 0 to debtToCover
InsufficientFlashLiquidityHelper: the flash amount exceeds the Pool's idle liquidity; reverts before LPVaultSwap is called
PremiumTooHigh, FlashFeeTooHighHelper: the Pool's premium exceeds the caller's maxPremium or the maxFlashFeeBps cap
InvalidFlashCallback, FlashSourceIsHubHelper: a callback that does not match its single-use context, or a Pool recorded as a Hub
TopUpExceededHelper: repaying the loan and premium needs a top-up above the caller's bound; the whole liquidation reverts

The price, sequencer, market and seizure errors are listed in the steps above. NotApprovedKeeper no longer exists: a caller outside the committed operator registry runs every check like any other. Aave's own errors pass through unchanged.

End State

  • Vault tokens received by LPVaultSwap = burned by the AaveAdapter = vault-token supply drop = the proxy's share drop on the Spoke = units debited from the proxy's records = units removed from those positions.
  • No depositor fees were taken: every debited position's owed fees remain collectable by its depositor.
  • The recovery plus any top-up met the floor, Avana's fee went to the fee recipient, any borrower surplus went to the borrower or the PayoutEscrow, and the caller payout was at least minPayout and paid directly to the caller.
  • No protocol balance paid any part of the settlement: Aave's repayment came from the caller's funding, and any recovery below D reduced only the caller's payout.
  • A deficit was recorded only if the account has no collateral left, and then its debt is 0 in every debt reserve.
  • LPVaultSwap ends with no net balance change in any token, no allowance granted in the call is non-zero, and the lock is free.
  • The debt asset came only from the caller, never bought with another asset and never flash-borrowed by LPVaultSwap. In a flash-funded call, the helper borrowed from the Aave V3 Pool within the caller's maxPremium, repaid the loan and premium in the same transaction before paying its caller, and holds nothing after the call.