> 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/cdp-safety.md).

# CDP collateral conditions

Calculate collateral ratio, LTV, liquidation price, and the USDHN needed to repay a Trove.

A Trove's collateral ratio changes with collateral prices, debt, and collateral amounts. Its liquidation price also moves when interest accrues or the position changes. The debt is repaid in USDHN units, while buying those units has a separate market cost.

## Values used in the calculation

| Symbol        | Meaning                   | Unit or source                                                                        |
| ------------- | ------------------------- | ------------------------------------------------------------------------------------- |
| `C`           | Current collateral amount | The branch's collateral accounting units, including pending redistributed collateral. |
| `P`           | Collateral price          | USD per collateral unit from the branch price feed.                                   |
| `V = C × P`   | Collateral value          | USD.                                                                                  |
| `D`           | Current debt              | USDHN, including interest, fees, and pending redistributed debt.                      |
| `MCR`         | Minimum collateral ratio  | The threshold for the selected branch, written as a ratio such as `1.5` for `150%`.   |
| `CR = V / D`  | Collateral ratio          | Collateral value divided by debt valued at $1 per USDHN.                              |
| `LTV = D / V` | Loan-to-value ratio       | The reciprocal of CR.                                                                 |

Use the latest total collateral and debt. Original deposit and borrowing amounts omit changes from interest, fees, redemptions, and redistribution. Token deposits that are wrapped must be converted into the branch's collateral accounting units before calculating CR.

## Deriving the liquidation price

For `C > 0` and `D > 0`:

$$
CR = \frac{CP}{D}, \qquad LTV = \frac{D}{CP} = \frac{1}{CR}
$$

At the liquidation boundary, `CR = MCR`. Multiplying by debt and dividing by collateral gives:

$$
\frac{CP\_{liq}}{D} = MCR
\quad \Longrightarrow \quad
P\_{liq} = \frac{MCR \times D}{C}
$$

With collateral and debt fixed, `P < P_liq` gives `CR < MCR`, the contract's liquidation condition. Equality marks the boundary; liquidation requires a ratio below it. The contracts perform these comparisons with scaled integers.

If a redemption fully repays the debt, `D = 0` and the division by debt does not apply. The remaining collateral stays in the Trove until the owner closes it and reclaims the collateral.

### Five changes from the same starting position

For this calculation example, use `MCR = 150% = 1.5`, `C = 10`, `P = $2`, and `D = 10 USDHN`. These are example inputs. An actual loan uses its selected branch's parameters and minimum debt.

The starting values give:

$$
CR = \frac{10 \times 2}{10} = 200%,
\qquad
P\_{liq} = \frac{1.5 \times 10}{10} = $1.50
$$

Each row below changes the starting position independently.

| Change                                                         | New CR                    | New liquidation price       | Meaning                                                                                         |
| -------------------------------------------------------------- | ------------------------- | --------------------------- | ----------------------------------------------------------------------------------------------- |
| Collateral price falls from `$2` to `$1.60`                    | `(10 × 1.60) / 10 = 160%` | `$1.50`                     | The price fall lowers CR without changing the boundary price.                                   |
| Debt increases from `10` to `15`                               | `(10 × 2) / 15 ≈ 133.3%`  | `(1.5 × 15) / 10 = $2.25`   | More debt raises the boundary. This proposed borrowing would fail the example's 150% MCR check. |
| Debt is repaid from `10` to `8`                                | `(10 × 2) / 8 = 250%`     | `(1.5 × 8) / 10 = $1.20`    | Repayment raises CR and lowers the boundary.                                                    |
| Collateral increases from `10` to `12.5`                       | `(12.5 × 2) / 10 = 250%`  | `(1.5 × 10) / 12.5 = $1.20` | More collateral raises CR and lowers the boundary.                                              |
| USDHN's market price changes, with `C`, `P`, and `D` unchanged | `200%`                    | `$1.50`                     | The protocol values debt at $1 per USDHN. The cost of buying USDHN for repayment changes.       |

Interest raises `D` over time, so it raises `P_liq` even when `C` is unchanged. A price movement alone leaves `P_liq` unchanged at that instant, but ongoing debt accrual still changes the next calculation.

## Oracle price and screen updates

The contract checks the branch price feed during execution. A spot exchange price and the displayed loan price can differ because they come from different sources or update at different times. A screen value records a particular read; the transaction is checked against the values available when it executes.

A collateral-ratio buffer is the distance between the current CR and MCR. A price decline or debt growth reduces that distance. Adding collateral or repaying debt increases it. The position must also satisfy the branch-wide borrowing and withdrawal rules described in [Borrowing and liquidation](/protocol/borrowing-and-liquidation.md).

## What increases current debt

The current debt combines these amounts:

$$
D = D\_{recorded} + I\_{accrued} + F\_{batch} + D\_{redistributed}
$$

| Component          | How it arises                                                                                                    |
| ------------------ | ---------------------------------------------------------------------------------------------------------------- |
| Recorded debt      | The outstanding debt recorded by the last operation, including capitalized fees and amounts already applied.     |
| Accrued interest   | Interest on recorded debt since the last accounting update.                                                      |
| Accrued batch fee  | The position's share of management fees while enrolled with a batch manager. It is zero for a non-batched Trove. |
| Redistributed debt | The position's pending share of liquidated debt that its branch's Stability Pool did not offset.                 |

Opening or increasing debt adds an upfront fee to recorded debt. For new borrowing amount `x` and the branch's average annual rate `r_avg`, the seven-day fee is:

$$
F\_{upfront} = x \times r\_{avg} \times \frac{7}{365}
$$

The contract calculates this with fixed-point integer arithmetic and rounds down. The fee is added to debt; it is not included in the USDHN delivered to the wallet. Early interest-rate changes during the seven-day cooldown can also add an upfront fee, calculated on the debt being repriced.

Liquidation penalties are settled from collateral when a Trove is liquidated. They reduce collateral returned after settlement. They do not accrue as an additional running interest charge on that closed Trove.

## USDHN market price and repayment cost

If the debt is `1,000 USDHN`, repayment requires `1,000 USDHN`. A wallet that still holds the borrowed tokens can use them. A wallet that sold or spent them must obtain the repayment tokens again.

For `1,000 USDHN` of debt, excluding additional interest, trading fees, and slippage:

| USDHN purchase price | Cost to buy the repayment amount |
| -------------------- | -------------------------------- |
| `$1.02`              | `$1,020`                         |
| `$0.98`              | `$980`                           |

The market purchase cost changes with USDHN's price. The required USDHN quantity changes with the loan's debt accounting. The closing screen uses the latest amount to repay rather than the original amount borrowed.

Partial repayment preserves the minimum debt. Full repayment uses the closing transaction, which returns collateral and the refundable gas deposit after settlement. If USDHN is short, the app's closing review offers the supported swap and collateral-close paths. Their fees and slippage affect the assets returned.

[Redemptions and risk](/protocol/redemptions-and-risk.md) covers changes caused by USDHN redemptions. [Risk disclosure](/security/risk-disclosure.md) covers oracle, contract, collateral, and market 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/cdp-safety.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.
