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.
| Symbol | Meaning |
|---|---|
| X | debtToCover, the most debt asset LPVaultSwap pulls from the caller |
| Kf | Caller funding: the debt asset LPVaultSwap received from the caller, 0 < Kf ≤ X. Kf equals X unless the asset charges a transfer fee. |
| D | Debt asset Aave pulled in its liquidation call, never more than Kf |
| c | Vault-token units LPVaultSwap received |
| b, lf, bNet | Aave liquidation bonus, Aave liquidation fee (0 by the listing settings), net bonus, in bps where 10,000 means no bonus |
| Pc, Pdebt | Vault-token and debt-asset prices served to Aave |
| V | Oracle value of the seized units in the debt asset |
| U | One raw unit of each unwound token, valued in the debt asset |
| s, sLeg | Effective slippage of the floor; slippage of each swap leg |
| minOut | Recovery floor |
| R, R′ | Debt asset recovered from the seized collateral; R plus the caller's shortfall top-up |
| G | Oracle gain, max(0, V − D) |
| Y | Realized surplus, max(0, R′ − D) |
| A, Kr, B | Avana fee, caller reward, borrower surplus; A + Kr + B = Y |
| keeperOut | The 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).
| Field | Meaning |
|---|---|
proxy | The borrower's PositionProxy, the Aave account of one wallet in one market |
marketId | The proxy's collateral market |
debtReserveId | The debt reserve to repay, enabled on the CDP Spoke |
debtToCover | The 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. |
routeMode | PrimaryThenBackup or BackupOnly, either value for every caller |
minAmounts | Optional least amount of each market token the unwind must return; empty means 0 for every token. It can only make the call revert. |
deadline | Last valid block timestamp, in seconds on every chain |
minPayout | Smallest caller payout accepted. The payout includes the returned funding, so this is the funding plus the smallest net payout accepted. |
maxShortfall | Most 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.
Settlement Steps
The steps below run in this exact order, for every caller.
| # | Step | What happens |
|---|---|---|
| 1 | Deadline | LPVaultSwap reverts with DeadlineExpired if the block timestamp is past the deadline, before the lock and before any external call. |
| 2 | Lock and entry checks | LPVaultSwap 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. |
| 3 | Resolve the market | From 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). |
| 4 | Poke oracles and check prices | LPVaultSwap 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). |
| 5 | Sequencer gate | Down 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. |
| 6 | Read the bonus | The 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. |
| 7 | No pool spot check | LPVaultSwap reads no pool spot price. A moved pool never reverts the call or changes its route mode. |
| 8 | Fund | LPVaultSwap 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. |
| 9 | beginSeizure | Collateralization 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. |
| 10 | liquidationCall | LPVaultSwap 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. |
| 11 | Measure D and c | Both 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. |
| 12 | Open the recovery window | LPVaultSwap 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. |
| 13 | burnSeized | The AaveAdapter, the vault token's only burner, burns the c units from LPVaultSwap's balance (SeizedUnitsBurned). |
| 14 | settleSeizure | Collateralization 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. |
| 15 | Measure the unwind | LPVaultSwap measures the amount aᵢ of each market token it received. Uncollected fees never enter these amounts. |
| 16 | Recovery floor | LPVaultSwap computes the net bonus, the effective slippage, V, U and the floor minOut in the debt asset, and each leg's minimum. |
| 17 | Swap legs | Each 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. |
| 18 | Shortfall check | The shortfall is max(0, minOut − R). Above maxShortfall the call reverts with RecoveryBelowFloor; otherwise the shortfall is pulled from the caller. |
| 19 | Waterfall | LPVaultSwap computes G, Y, A, Kr, B and keeperOut (a defensive InsufficientProceeds check), then checks keeperOut against minPayout (PayoutTooLow). |
| 20 | Pay out | A 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. |
| 21 | Event and lock | LPVaultSwap 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.
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 field | Meaning |
|---|---|
params | The LiquidationParams, passed to liquidate unchanged |
flashAmount | The loan F, with 0 < F ≤ debtToCover |
maxPremium | The most premium the caller accepts on F |
maxTopUp | The most debt asset the helper may pull from the caller after liquidate, to repay F plus the premium |
minPayout | The 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
- 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.
- 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.
- If F is below X, it pulls X − F of the debt asset from the payer.
- It calls the Pool's flashLoan, not flashLoanSimple, because only flashLoan waives the premium for FLASH_BORROWER.
- 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.
- 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 × FmaxFlashFeeBps 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.
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
| Item | Public helper | Operator variant |
|---|---|---|
| Who may call | Anyone | Only its signer |
| Payer and payout recipient | The caller itself | The operator's funding Safe |
| Top-up bound | The request's maxTopUp | The smaller of maxTopUp and ⌊X × MAX_TOP_UP_BPS / 10,000⌋ |
| FLASH_BORROWER | Requested in each chain's deployment payload | None unless an Aave proposal adds one, so it pays the Pool premium |
| Committed operator registry | Never registered, because it commits to nothing | The operator registers this helper, or its signer when it calls liquidate directly |
| Escrowed residues | No claim function; a credit can arise only when a market token refuses the helper itself | claimEscrowed, 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.
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).
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.
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.
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.
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.
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.
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
- Avana's fee A to the fee recipient read from the ParameterStore. A zero fee recipient reverts with InvalidFeeRecipient.
- The borrower surplus B to the borrower's wallet, the wallet the AaveAdapter records for the proxy (BorrowerSurplusPaid).
- keeperOut to the caller, by a plain transfer. If it fails, the whole liquidation reverts.
- 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.
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.
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:
- 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.
- It approves the Pool for exactly F + φ and returns; the Pool pulls the amount.
- 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.
- 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.
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.
- 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.
- It calls the token's transfer with exactly 100,000 gas (PAYOUT_TRANSFER_GAS) and reads at most 32 bytes of return data.
- 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.
Events
| Contract | Events |
|---|---|
| LP Oracle, DebtOracle | PriceStateChanged, DisagreementRecorded |
| Aave V3 Pool (flash-funded calls only) | FlashLoan, with the helper as target and initiator |
| Flash liquidation helper | FlashLiquidated |
| CDP Spoke | LiquidationCall |
| Funding Hub | ReportDeficit (deficit case, per debt reserve) |
| Vault token | Transfer from the Hub to LPVaultSwap, and from LPVaultSwap to the zero address |
| AaveAdapter | SeizedUnitsBurned |
| AMM protocol and LP Vault | DecreaseLiquidity, Collect, UnitsUnwound |
| Collateralization | RecordDebited, SeizureSettled, SeizureReconciled, PendingSettled |
| LPVaultSwap | RouteFailed, ResidueReturned, BorrowerSurplusPaid, LiquidationSettled, PendingSettlementForwarded |
| PayoutEscrow | RemainderEscrowed, 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
| Error | When |
|---|---|
AddressIsFrozen | The caller of liquidate is on the chain's freeze list. It does not fire for a frozen address that calls through the public helper. |
InvalidAmount | debtToCover is 0, debtToCover or maxShortfall exceeds the uint128 range, or minAmounts has the wrong length |
FundingMismatch | The caller funding is outside 0 < Kf ≤ X, or a shortfall pull delivered a different amount |
RecoveryBelowFloor | The gap below the recovery floor exceeds maxShortfall |
InsufficientProceeds | Defensive only: unreachable while Kf ≥ D, it guards against a faulty balance measurement |
PayoutTooLow | keeperOut is below the call's minPayout, or a helper's net payout is below the request's minPayout |
InsufficientGas | Gas left is below a payout's headroom; the caller retries with more gas |
KeeperFloor | removeKeeper would leave fewer than keeperFloor active committed operators |
ContextActive, NotSigner, InvalidFlashAmount | Helper: a nested call, a caller other than the operator variant's signer, or a flash amount outside 0 to debtToCover |
InsufficientFlashLiquidity | Helper: the flash amount exceeds the Pool's idle liquidity; reverts before LPVaultSwap is called |
PremiumTooHigh, FlashFeeTooHigh | Helper: the Pool's premium exceeds the caller's maxPremium or the maxFlashFeeBps cap |
InvalidFlashCallback, FlashSourceIsHub | Helper: a callback that does not match its single-use context, or a Pool recorded as a Hub |
TopUpExceeded | Helper: 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.
