> 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/th/mechanics/deep-dives/redemptions.md).

# การไถ่ถอน

จัดสรรไถ่ถอน ลำดับดอกเบี้ย ค่าธรรมเนียม และการเปลี่ยน CR

ไถ่ถอนปกติเผา USDHN และลดหนี้ Trove ที่เลือก ผู้ไถ่ถอนรับหลักประกันหลังหักค่าธรรมเนียมซึ่งอยู่ใน Trove CollateralRegistry แบ่งข้ามสาขา แล้ว TroveManager เลือกโพซิชัน

## จัดสรรสาขา

สาขาต้อง active ยังไม่ปิด และ `TCR` อย่างน้อย `SCR`

สำหรับสาขา `j` ที่เข้าเกณฑ์:

$$
u\_j = \max(\text{BranchDebt}\_j - \text{SPDeposits}\_j, 0)
$$

นี่คือหนี้เกินเงินฝากพูล ซึ่งยังมีหลักประกัน Trove รองรับ

หากผลรวม `u_j` บวก จำกัดยอดขอที่ผลรวมแล้วแบ่งตามสัดส่วน หากทุกสาขา `u_j = 0` ใช้หนี้รวมสาขาแทน

เมื่อแยกการหารจำนวนเต็มออก:

$$
A\_j = A \times \frac{w\_j}{\sum\_k w\_k}
$$

`A` คือจำนวนหลังจำกัด `w_j` คือ `u_j` หรือหนี้สาขาในกรณีสำรอง สัญญาทำตามลำดับ registry คำนวณยอดกับน้ำหนักที่เหลือใหม่หลังแต่ละครั้ง และแจกเศษจำนวนเต็มในครั้งถัดไป

![ไถ่ถอน 25 USDHN แบ่ง 40%, 20%, 40% ตามหนี้ส่วนเกินจากเงินฝากพูล](https://3695348949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOoXFX6oIaMlfykIjlfhI%2Fuploads%2Fgit-blob-be8b2eb2ff4d115ffc951f349404c5a99292e5a1%2Fredemption-allocation.svg?alt=media)

กองสีน้ำเงินคือหนี้ สีมะนาวคือ USDHN ในพูล เส้นประคือหนี้เกินเงินฝาก

**ตัวอย่าง 25 USDHN** หนี้สามสาขา 150, 100, 170 และเงินฝาก 50, 50, 70 USDHN น้ำหนักคือ 100, 50, 100 จึงแบ่ง 10, 5, 10 USDHN เงินฝากพูลคงเดิม ผู้ไถ่ถอนรับหลักประกันหลังค่าธรรมเนียม

## ลำดับ Trove ในสาขา

เส้นทางปกติ:

1. ตรวจ `lastZombieTroveId` ที่มีหนี้น้อยเหลือจากครั้งก่อน
2. เริ่ม `SortedTroves.getLast()` ตาม `getPrev()` จาก**อัตราต่อปีต่ำสุดขึ้นไป**
3. ข้าม CR ต่ำกว่า 100% ที่ราคาออราเคิลปกติ
4. ใช้ดอกเบี้ยและกระจายก่อนคำนวณหนี้ไถ่ถอนได้
5. ใช้ค่าต่ำกว่าระหว่าง USDHN จัดสรรที่เหลือกับหนี้ Trove

![ไถ่ถอน 250,000 USDHN ลด Trove 4% จาก 200,000 เป็นศูนย์ และ Trove 4.3% จาก 60,000 เป็น 10,000 ส่วน 4.4% คงหนี้ 450,000](https://3695348949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOoXFX6oIaMlfykIjlfhI%2Fuploads%2Fgit-blob-f0e8a0f13308d40a4b9f57296cf5beabf223fa91%2Fredemption-order.svg?alt=media)

**ตัวอย่างสาขารับ 250,000 USDHN** Trove 4% ให้หนี้ทั้งหมด 200,000 ส่วน 4.3% ให้ 50,000 จาก 60,000 เหลือ 10,000 และ Trove 4.4% คงเดิม

ขีดจำกัดรอบนับทุก Trove ที่ผ่าน รวมที่ข้าม ค่า `0` ยกเลิกเพดาน วนหยุดเมื่อครบยอดหรือหมดรายการ

ผู้กู้ตั้งอัตราเองหรือใช้ผู้จัดการ เพิ่มอัตราเลื่อนลำดับไปหลังและเพิ่มต้นทุน Trove ผู้จัดการเดียวกันใช้อัตรากลุ่ม

## ค่าธรรมเนียมไถ่ถอน

รวมอัตราขั้นต่ำกับฐาน โดยใช้สัดส่วน:

* `b`: อัตราฐานที่เก็บ
* `m`: นาทีเต็มตั้งแต่รายการค่าธรรมเนียมล่าสุด
* `A`: จำนวนที่พยายามหลังจำกัดสาขา
* `S`: อุปทาน USDHN ตอนเริ่มธุรกรรม
* `λ = 0.998076443575628800`: ตัวลดต่อนาที
* `β = 1`: ตัวหารส่วนเพิ่มไถ่ถอน
* `f₀ = 0.005`: อัตราขั้นต่ำ 0.5%

$$
b\_{decayed} = b\lambda^m
$$

$$
b\_{quote} = \min\left(1, b\_{decayed} + \frac{A}{\beta S}\right)
$$

$$
f = \min(1, f\_0 + b\_{quote})
$$

ครึ่งชีวิต 6 ชั่วโมง อัตราฐานเริ่ม 100% เมื่อ deploy registry แล้วลดตามเวลา บนเชนใช้จำนวนเต็ม fixed-point

ตรวจ `f` กับเพดานผู้เรียกก่อนไถ่ถอน หลังทำปรับฐานด้วย**จำนวนไถ่ถอนจริง** ดังนั้นการทำบางส่วนเพราะจำกัดรอบอาจเสียอัตราที่เสนอสำหรับยอดพยายามที่มากกว่า

มี `getRedemptionRateWithDecay()`, `getRedemptionRateForRedeemedAmount(amount)`, `getEffectiveRedemptionFeeInUSDHN(amount)` ซึ่งขึ้นกับอุปทาน อัตรา เวลา และจำนวน

## หลักประกันรับและค่าที่เก็บ

ให้:

* `r`: USDHN ที่ไถ่ถอนจาก Trove หนึ่ง
* `pᵣ`: ราคาไถ่ถอนต่อโทเคนหลักประกัน
* `f`: สัดส่วนค่าธรรมเนียม

ในหน่วยปรับแล้ว:

$$
\text{CorrespondingCollateral} = \frac{r}{p\_r}
$$

$$
\text{CollateralFee} = \frac{r}{p\_r}f
$$

$$
\text{CollateralSent} = \frac{r}{p\_r}(1-f)
$$

หนี้ลด `r` หลักประกันลด `CollateralSent` ส่วน `CollateralFee` อยู่ใน Trove สัญญาใช้ `fetchPrice()` ตรวจ 100% และ `fetchRedemptionPrice()` คำนวณผลรับ

เมื่อราคาปกติ `p` มูลค่าหลักประกัน `V` และหนี้ `D`:

$$
CR' = \frac{V-r(1-f)p/p\_r}{D-r}
$$

ต้อง `r < D` หากไถ่ถอนเต็มหนี้เป็นศูนย์และหลักประกันที่เหลือคงอยู่

## ตัวอย่าง CR

ตรึงราคาปกติกับไถ่ถอนให้เท่ากัน ตั้งค่าธรรมเนียมและดอกเบี้ยศูนย์ มูลค่าหลักประกันกับหนี้จึงลดเท่ากัน `r`:

$$
CR' = \frac{V-r}{D-r}
$$

เมื่อ `V > D` และ `0 < r < D`:

$$
CR' - CR = \frac{r(V-D)}{D(D-r)} > 0
$$

หลักประกันกับหนี้ลด และ CR เพิ่ม

### ตัวอย่าง 1: ครั้งเดียว

เริ่ม `V = $200`, `D = 100` USDHN, CR `200 / 100 = 200%`

ไถ่ถอน 20 ได้ `V′ = $180`, `D′ = 80`:

$$
CR' = \frac{180}{80} = 225%
$$

ส่วนเผื่อเพิ่มและโพซิชันเล็กลง หากมีค่าธรรมเนียมและราคาทั้งคู่เท่ากัน ส่วนเก็บใน Trove เพิ่มหลักประกันเหนือผลตัวอย่างนี้

### ตัวอย่าง 2: กู้หลังไถ่ถอน

เริ่ม `V = $180`, `D = 80`, `CR = 225%` คงหลักประกันแล้วกู้ 40 หนี้เป็น 120:

$$
CR = \frac{180}{120} = 150%
$$

กู้เพิ่มใช้ส่วนเผื่อที่เกิดจากไถ่ถอน

### ตัวอย่าง 3: ราคาลดหลังไถ่ถอน

จาก `V = $180`, `D = 80` ราคาลด 40% มูลค่าเป็น `180 × 0.6 = $108`:

$$
CR = \frac{108}{80} = 135%
$$

สาขา `MCR > 135%` ชำระบัญชีได้ หาก `MCR = 135%` ลดอีกจะต่ำกว่าเกณฑ์ ไถ่ถอนลดหนี้แล้ว หลักประกันยังมีความเสี่ยงราคา

## หนี้น้อยหรือไถ่ถอนครบ

หากปกติเหลือต่ำกว่า `MIN_DEBT` Trove เป็น `zombie` และออกจาก SortedTroves เศษที่ไม่เป็นศูนย์อาจบันทึกใน `lastZombieTroveId` สำหรับครั้งหน้า ไถ่ถอนเต็มทำหนี้ศูนย์ หลักประกันยังอยู่กับ Trove ผู้กู้

ปิด Trove เพื่อรับคืน ส่วนที่หนี้น้อยกู้คืน active ผ่านการปรับที่เข้าเกณฑ์ได้

## Helper และสาขาปิด

`RedemptionHelper` โอน USDHN จากผู้เรียก เรียก registry ตรวจขั้นต่ำ `_minCollRedeemed` ส่งหลักประกันและคืน USDHN ที่เหลือ ต้องมี allowance แอปใช้ registry ตรงเผาจากผู้เรียกโดยไม่ใช้ allowance

สาขาปิดมี `TroveManager.urgentRedemption(amount, troveIds, minCollateral)` ผู้เรียกกำหนด ID เอง สัญญาปัจจุบันให้โบนัสหลักประกัน 2% จำกัดที่หลักประกันที่มี อัตราไถ่ถอนปกติเป็นศูนย์ และตรวจขั้นต่ำผลรับที่ส่ง

[ไถ่ถอนและความเสี่ยง](/th/protocol/redemptions-and-risk.md) มีขั้นตอน [เงื่อนไข CDP](/th/mechanics/deep-dives/cdp-safety.md) อธิบาย CR และ[เปิดเผยความเสี่ยง](/th/security/risk-disclosure.md) ครอบคลุมตลาด สภาพคล่อง ออราเคิล


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hann.finance/th/mechanics/deep-dives/redemptions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
