Internal unwind

Liquidation triggers on a plain mark at the smoother average, and price impact is paid only in execution: keepers buy the collateral at a bounded discount, or the market unwinds it at prices a same-slot trade cannot move.

Updated Nov 15, 2026

V1 judged a position by simulating the sale of its collateral at the pessimistic price, so price impact entered the trigger itself. V2 separates the two. The trigger is a plain mark, and price impact is paid where it happens, in the sale.

The trigger

Write VV for a position's collateral marked linearly at the symmetric average, net of transfer fees, and DD for its debt. Its equity is

e=V−DVe = \frac{V - D}{V}

and it can be liquidated once it owes anything and D≥VD \ge V or e≤me \le m, its maintenance margin.

For a lending position, m=1−LCFm = 1 - \text{LCF}, the stored collateral factor, so a loan qualifies once D≥LCF⋅VD \ge \text{LCF}\cdot V. In basis points the program clamps mm to 1 through 9,999. For a leverage position, mm comes from tiers of 7%, 12% and 17% by size, against a reference set when the position opens; see Isolated leverage.

VV counts what the vault could deliver after the collateral mint's transfer fee, including a newer fee that takes effect within the next epoch. Depth stays out of the trigger, so withdrawing liquidity cannot make a healthy loan liquidatable. A liquidation aims to bring equity back to m+2%m + 2\%. preview_liquidation_health reads the same health without changing anything.

Every incentive scales with how far equity has fallen through the margin:

p=clamp⁡ ⁣(1−em, 0, 1)p = \operatorname{clamp}\!\Big(1 - \frac{e}{m},\ 0,\ 1\Big)

The program floors pp to whole basis points and sets p=1p = 1 once D≥VD \ge V. Time does not enter it, so a position whose health stays the same keeps the same incentives.

Flash fills

A keeper's flash fill takes collateral and pays a fixed amount of the debt token in the same transaction. The payment is priced at the symmetric average ss, less a discount that grows as health worsens:

δmax⁡=0.5%+4.5%⋅p\delta_{\max} = 0.5\% + 4.5\% \cdot p

A partial fill must improve equity net of maintenance, and may go no further than the first amount that restores m+2%m + 2\%. It takes the largest discount, down to 0.5%, that still improves health. For a partial that repays RR at discount δ\delta, the keeper receives

c=⌈R+f(1−δ) s⌉,f=⌊3%⋅R⌋c = \left\lceil \frac{R + f}{(1 - \delta)\,s} \right\rceil, \qquad f = \lfloor 3\% \cdot R \rfloor

where ff is the liquidation charge below. Every partial leaves at least one debt share behind.

A full fill needs the emergency boundary below, and either insolvency at the average or proof that no improving partial exists. It takes all the collateral for ⌈(1−δmax⁡) V⌉\lceil (1 - \delta_{\max})\,V \rceil. That payment repays the debt up to its size, the charge comes out of anything left over, and the remainder goes to the owner.

An ineligible position fails with PositionNotLiquidatable, a partial that cannot improve health at any allowed discount with LiquidationDoesNotImproveHealth, and a fill that is too large, or a full fill without its proof, with LiquidationRepayTooLarge.

Begin and settle, begin_flash_liquidation and settle_flash_liquidation, are two instructions in one transaction. Begin releases the quoted collateral, locks the position and checks that the matching settle comes later in the same transaction; settle requires the same slot and the quoted payment, and underpaying reverts everything. Nothing is sold into the market's curve unless the keeper routes the fill through it.

The internal unwind

When no keeper has restored a position and its equity falls to 70% of maintenance, e≤0.7 me \le 0.7\,m, any caller can unwind it internally. With 7% maintenance that boundary is 4.9% equity; for a loan with an 85% factor, m=15%m = 15\% and the boundary is 10.5%. Time alone never unlocks it.

The market takes the collateral into its own reserves and repays the debt with an internal swap. That swap is priced on the market's configured curve, concentrated bands included, rebuilt at the symmetric average ss with the depth average Lˉ\bar L and full configured fees. The depth is Lˉ\bar L itself, with no minimum against current depth. On an oracle-guided market the feed does not bend the rebuilt curve, because the symmetric average already follows the guided price. The hedged vaults are left out of the quote and reconciled after settlement.

The quote reads no live reserve, and the averages do not move within a slot, so a trade earlier in the same slot cannot change the price or depth it uses. The fee state is live: on a market that charges a volatility fee, earlier trades can raise the accumulator that the quote's fee reads. Pricing from live spot and depth gave a backstop sale no execution-price bound; the averages fix the quote's price within the slot.

emergency_liquidation takes the debt side, the collateral to sell, a full flag and two caller bounds, min_reward_credit and min_swap_output. It runs in this order:

  1. Accrue interest and refresh the market's curve and risk observations.
  2. Check e≤0.7 me \le 0.7\,m (PositionNotLiquidatable) and that the position has no open flash session (LiquidationSessionActive).
  3. Check the sale. The collateral sold must be nonzero and no more than the position holds (InsufficientAmount). A partial sells less than all of it and, if larger than one atom, needs proof that no smaller sale already restores m+2%m + 2\%. A full unwind sells all of it and needs insolvency at the average or proof that no smaller sale restores m+2%m + 2\%. A failure here is LiquidationRepayTooLarge.
  4. Quote the sale on the reference curve, then the reward, repayment and charge from its output.
  5. Require a partial to improve health (LiquidationDoesNotImproveHealth), and the quote to meet the caller's bounds (SlippageExceeded).
  6. Move the collateral from the collateral vault into its side's reserve vault and check the credited amount.
  7. Apply the swap to the real reserves, burn the repaid debt shares and reconcile the hedged vaults.
  8. Pay the caller's reward and the owner's surplus, credit the charge's junior part to Junior LP and book the protocol's share of the paid interest.
  9. Check custody on both reserve vaults (UnbackedFeeLiability).

The caller's reward rate is ρ=⌊100 p⌋\rho = \lfloor 100\,p \rfloor basis points of the proceeds: 0.3% at the boundary, rising to 1% at zero equity. From the swap output yy:

reward=⌊ρ y⌋,B=y−reward\text{reward} = \lfloor \rho\,y \rfloor, \qquad B = y - \text{reward}

A full unwind repays min⁡(D,B)\min(D, B) and charges 3% of that repayment, capped at what is left of BB; the rest of BB goes to the owner. A partial burns the most debt shares, short of all of them, whose debt RR satisfies R+⌊3%⋅R⌋≤BR + \lfloor 3\% \cdot R \rfloor \le B, and any atoms left over go to the owner.

The proof that no smaller sale restores m+2%m + 2\% covers every whole-atom sale size: the program bisects the range with optimistic bounds and prices the sizes left at the end exactly. If it cannot finish within its step budget, the sale is refused. emergency_liquidation can need more than the default 32 KiB heap, so a transaction that calls it should request a 256 KiB heap frame; the SDK's liquidation builders add that request.

The averages bound the sale's price, and the market still carries the exposure. A manipulator who holds a price long enough still moves them, and the market keeps the collateral as inventory, so trades before and after an unwind can still profit from the change.

Worked example

A lending position holds 1,000 base against a symmetric average of 100 quote, so V=100,000V = 100{,}000. Its stored factor is 85%, so m=15%m = 15\% and the unwind opens at 10.5% equity. The reference curve is constant product at depth 200,000, holding 20,000 base and 2,000,000 quote, with the SDK's default 0.3% fee taken from the input token. The borrow index is 1.0 and neither token charges a transfer fee.

Partial unwindFull unwind
Debt (principal)92,000 (90,000)101,000 (98,000)
Equity before8.00%Below zero
pp46.66%100%
Reward rate0.46%1.00%
Collateral sold3001,000
Swap output yy29,469.2994,965.95
Reward135.56949.66
Budget BB29,333.7394,016.29
Debt repaid28,479.3594,016.29
Charge to junior and protocol683.50 and 170.880
After70,000 of collateral against 63,520.65 of debt, 9.26% equityDebt cleared

The partial raises equity from 8% to 9.26%, short of the 17% recovery target, and the one atom of budget left over goes to the owner. The full unwind is allowed because the position is insolvent at the average. Its proceeds pay principal first: 94,016.29 of the 98,000 is repaid, and the other 3,983.71 of principal and the 3,000 of unpaid interest are written off. Nothing is left over, so the charge is zero.

Charges and losses

A solvent liquidation also pays a fixed charge of 3% of the net repayment, capped by the surplus on a full fill. 20% of it goes to the protocol and the rest to junior income. Both parts are floored: f=⌊3%⋅R⌋f = \lfloor 3\% \cdot R \rfloor and the protocol takes ⌊20%⋅f⌋\lfloor 20\% \cdot f \rfloor.

Recovery pays principal first, then interest. With PP the principal, DD the debt and BB what the sale recovers after the reward:

Prepaid=min⁡(P, B)Ipaid=min⁡(D−P, max⁡(B−P, 0))Pwritten off=P−PrepaidIwritten off=D−P−Ipaid\begin{aligned} P_{\text{repaid}} &= \min(P,\ B) \\ I_{\text{paid}} &= \min\big(D - P,\ \max(B - P,\ 0)\big) \\ P_{\text{written off}} &= P - P_{\text{repaid}} \\ I_{\text{written off}} &= D - P - I_{\text{paid}} \end{aligned}

Unpaid principal and unpaid interest are both written off. The interest's LP and operator part was credited to holders as it accrued, so it joins the loss; the protocol's unpaid part is dropped. The program burns junior reserve shares so that the loss lands on junior holders, and senior shares lose value only once no junior shares remain. The burn is worth the loss at the market's funded value, rounded up and capped at all junior shares; see Tranche accounting. Interest already credited to holders is not reduced.

Parameters

Every liquidation term is a program constant. No creator, operator or governance setting changes them; a lending position's maintenance comes from the factor it stored when it borrowed, and a leverage position's from the terms it opened with.

TermValue
Maximum flash discount0.5% at the maintenance margin, rising to 5% at zero equity
Recovery targetMaintenance plus 2 points
Internal unwind opens at70% of maintenance
Caller reward0.3% at the unwind boundary, rising to 1% at zero equity
Liquidation charge3% of the net repayment
Protocol share of the charge20%, the rest to junior income