> For the complete documentation index, see [llms.txt](https://docs.aeralend.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aeralend.app/getting-started/repay-and-unlock.md).

# Repay and unlock

Two actions, in that order. You cannot take out collateral your debt still needs, so repaying comes first.

Both live on the **Your position** block at the top of the main screen. Neither navigates anywhere — each opens a sheet over the page.

<figure><img src="/files/Okeg8qva97R3tTW51E8l" alt="The position summary"><figcaption><p>Each line carries its own rate and its own actions.</p></figcaption></figure>

| Line           | Actions      |
| -------------- | ------------ |
| **Lent**       | Withdraw     |
| **Borrowed**   | Repay        |
| **Collateral** | Lock, Unlock |

## Repay

<figure><img src="/files/HRjTzY64w0AZ6GHX8O4V" alt="Pressing Repay and taking MAX"><figcaption><p><strong>MAX</strong> offers everything spendable, not the figure you owe.</p></figcaption></figure>

Repaying is **always permitted** — when borrowing is frozen, when the oracle is in an emergency state, and when your position is already liquidatable. Every state that restricts Aera leaves this exit open, because a protocol that will not let you reduce your own risk is a trap.

{% hint style="info" %}
**MAX offers more than you owe, on purpose.** Interest accrues every slot, so a figure read a moment ago is already stale by the time you sign — and a repayment a few base units short leaves the loan open. So MAX offers your whole spendable balance, and the program takes `min(what you sent, what you owe)`. The sheet says how much will actually be taken.
{% endhint %}

MAX also holds back a little COOK for the transaction fee. COOK is Cookie Chain's native token, so a transaction that spends the entire balance cannot pay for itself.

## Unlock

<figure><img src="/files/bUaYrgNGOgexJPs5qJqO" alt="Pressing Unlock and taking the permitted maximum"><figcaption><p>With debt outstanding, MAX is the largest amount that still leaves the position standing.</p></figcaption></figure>

With no debt, everything unlocks. With debt outstanding, enough collateral has to stay behind to keep the position above the line — so **MAX here is not your locked balance**, it is the largest withdrawal the program will actually permit.

That figure comes from the same preview that decides whether the transaction succeeds, so the sheet and the chain cannot disagree about it.

<figure><img src="/files/vnuDoNjTAW5gLFdgAWPZ" alt="The collateral position on Portfolio"><figcaption><p>Portfolio states the same figure in words, rounded down — a figure rounded up is one the sheet then refuses.</p></figcaption></figure>

{% content-ref url="/pages/99c3AapbBf60c32cgnzN" %}
[Read your risk](/getting-started/read-your-risk.md)
{% endcontent-ref %}


---

# 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.aeralend.app/getting-started/repay-and-unlock.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.
