> For the complete documentation index, see [llms.txt](https://docs.hann.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hann.finance/mechanics/deep-dives/liquidations-and-earn.md).

# Liquidations and Earn

Liquidation debt offsets, collateral distribution, and Stability Pool deposit accounting

A liquidation closes a Trove whose collateral ratio is below the branch’s minimum collateral ratio (`MCR`). The Stability Pool uses deposited USDHN to cancel part or all of the debt and receives collateral. Debt and collateral left after that offset are redistributed to other Troves in the branch.

## The liquidation flow

The collateral ratio uses the branch’s oracle price and current debt, including accrued interest and redistribution amounts.

1. A caller submits Trove IDs to `TroveManager.batchLiquidateTroves`.
2. The contract checks each active or `zombie` Trove. It liquidates those with a collateral ratio strictly below `MCR`.
3. The liquidated Trove is closed and removed from the borrower’s active positions.
4. Available Stability Pool deposits offset debt. The pool burns the USDHN used and receives the allocated collateral.
5. The remaining debt and collateral are redistributed through DefaultPool.
6. The liquidator receives gas compensation. Collateral surplus is recorded in CollSurplusPool for the borrower to claim.

The borrower’s Trove is closed even when the Stability Pool cannot offset all of its debt. Redistribution transfers the remaining debt to other Troves.

## How much debt the pool absorbs

Let `pool` be the pool’s USDHN deposits and `D` the liquidated debt. Liquidations use the amount above 1 USDHN:

$$
\text{AvailableUSDHN} = \max(pool - 1, 0)
$$

$$
\text{DebtOffset} = \min(D, \text{AvailableUSDHN})
$$

A pool with less than 1 USDHN provides no liquidation offset. If the offset is smaller than the liquidated debt, the rest goes through redistribution.

The collateral allocated to the offset starts from the same fraction of the Trove’s collateral as the fraction of debt being offset. The contract deducts collateral gas compensation, then caps the collateral sent to the pool using the branch’s Stability Pool liquidation penalty. Any surplus can be used by the redistribution path before the final borrower surplus is recorded.

The pool receives the branch’s collateral token. In the KAIA branch this is WKAIA; in the EarnUSDT branch it is wEarnUSDT.

## What changes for each participant

| Participant              | Change                                                                                                                                           |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| Liquidated borrower      | The Trove closes, its debt is removed from that position, and its collateral is distributed. Recorded surplus remains claimable by the borrower. |
| Stability Pool depositor | The USDHN deposit shrinks in proportion to the debt offset, and collateral rewards accrue.                                                       |
| Other Trove borrowers    | Redistributed debt and collateral increase their positions in proportion to their stakes.                                                        |
| Liquidator               | Receives the liquidation’s gas compensation.                                                                                                     |

A Stability Pool deposit has no individual borrower-style liquidation threshold. Its USDHN balance still decreases when the pool absorbs liquidations.

## Deposit and collateral accounting

For one event, define:

* `pool`: total USDHN deposits immediately before the offset.
* `you`: your USDHN deposit immediately before the offset.
* `offset`: USDHN burned to cancel debt.
* `collGain`: collateral tokens actually delivered to the pool.

The pro-rata accounting is:

$$
you\_{after} \approx you \times \left(1 - \frac{offset}{pool}\right)
$$

$$
yourCollateralGain \approx \frac{you}{pool} \times collGain
$$

The contract tracks these changes with a deposit product `P`, a collateral accumulator `S`, and depositor snapshots. USDHN interest rewards use a separate accumulator `B`. On-chain integer division rounds down, and the accounting also includes scale changes.

The examples below exclude interest rewards and new deposits from other users. WKAIA is valued at $2 for the collateral-value calculations. The stated collateral gain is the amount delivered to the pool after liquidation allocations.

### Example 1: one liquidation

| Item                             | Amount                          |
| -------------------------------- | ------------------------------- |
| Pool before the event            | 10,000 USDHN                    |
| Your deposit                     | 1,000 USDHN, or 10% of the pool |
| Debt offset                      | 500 USDHN                       |
| Collateral delivered to the pool | 250 WKAIA, valued at $500       |

Your deposit becomes `1,000 × (1 − 500 / 10,000) = 950` USDHN. Your collateral reward is `10% × 250 = 25` WKAIA.

After the event, the position holds **950 USDHN deposited and 25 WKAIA in rewards**.

### Example 2: two consecutive liquidations

Start from the same 10,000 USDHN pool and 1,000 USDHN deposit.

| Event | Pool before  | Your deposit before | Debt offset | Pool collateral gain | Your deposit after | Your collateral gain |
| ----- | ------------ | ------------------- | ----------- | -------------------- | ------------------ | -------------------- |
| 1     | 10,000 USDHN | 1,000 USDHN         | 500 USDHN   | 250 WKAIA            | 950 USDHN          | 25 WKAIA             |
| 2     | 9,500 USDHN  | 950 USDHN           | 1,900 USDHN | 950 WKAIA            | 760 USDHN          | 95 WKAIA             |

The second offset removes 20% of the pool’s remaining deposits:

$$
950 \times \left(1 - \frac{1{,}900}{9{,}500}\right) = 760
$$

After both events, the position holds **760 USDHN deposited and 120 WKAIA in accumulated rewards**. The amounts already received as collateral do not become USDHN deposits automatically.

### Example 3: adding a deposit between liquidations

Start from a 10,000 USDHN pool and a 1,000 USDHN deposit.

1. The first event offsets 200 USDHN and delivers 100 WKAIA. Your deposit becomes 980 USDHN, your reward is 10 WKAIA, and the pool becomes 9,800 USDHN.
2. You add 500 USDHN. Your deposit becomes 1,480 USDHN and the pool becomes 10,300 USDHN.
3. The next event offsets 2,060 USDHN and delivers 1,030 WKAIA.

Your new deposit and collateral gain are:

$$
1{,}480 \times \left(1 - \frac{2{,}060}{10{,}300}\right) = 1{,}184
$$

$$
\frac{1{,}480}{10{,}300} \times 1{,}030 = 148\ \text{WKAIA}
$$

After both events, the position holds **1,184 USDHN deposited and 158 WKAIA in accumulated rewards**. Adding USDHN changed your share of the pool before the second liquidation.

## USDHN interest rewards

ActivePool mints the branch’s aggregate borrower interest and upfront fees, then sends the Stability Pool’s share to the pool. `triggerUSDHNRewards` adds this USDHN to the reward accounting.

USDHN rewards accrue separately from the liquidation-reduced deposit. With less than 1 USDHN deposited, newly distributed yield stays pending until deposits reach the distribution threshold.

| Action                                          | USDHN rewards                                                | Collateral rewards                                           |
| ----------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| Deposit or withdraw with `claimRewards = true`  | Sent to the wallet                                           | Sent to the wallet, including previously recorded collateral |
| Deposit or withdraw with `claimRewards = false` | Added to the deposit                                         | Recorded in `stashedColl` for a later claim                  |
| Claim with an active deposit                    | `withdrawFromSP(0, true)` sends the USDHN rewards            | The same call sends the collateral rewards                   |
| Re-deposit with an active deposit               | `withdrawFromSP(0, false)` adds USDHN rewards to the deposit | Remain recorded in the pool                                  |
| Claim recorded collateral with no deposit       | No USDHN deposit is created                                  | `claimAllCollGains()` sends `stashedColl` to the wallet      |

Withdrawals and claim/re-deposit calls using `withdrawFromSP` must leave at least 1 USDHN in the entire pool.

## Why the return changes

Interest rewards depend on borrower debt, interest rates, and the pool’s deposit size. Liquidation outcomes depend on offset amounts and collateral received. The market value of that collateral changes with price and exit liquidity.

Track the remaining USDHN deposit, USDHN rewards, and collateral rewards separately. [USDHN & Earn](/protocol/usdhn-and-earn.md) contains the app steps; [Borrowing & Liquidation](/protocol/borrowing-and-liquidation.md) covers the borrower’s position, and [Risk Disclosure](/security/risk-disclosure.md) covers market, contract, and oracle risks.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.hann.finance/mechanics/deep-dives/liquidations-and-earn.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
