> For the complete documentation index, see [llms.txt](https://docs.term.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.term.finance/protocol/term-repos/margin-maintenance.md).

# Margin maintenance

### Term Repo Lockers

Each Term Repo has a Term Repo Locker, which is a smart contract that locks collateral on behalf of borrowers and lenders for that Term Repo.

{% hint style="info" %}
By segregating Term Repo Lockers by maturity and purchase token/collateral token pairs rather than instituting a single large commingled collateral pool reduces user exposure to cybersecurity risks and exploits.&#x20;
{% endhint %}

### Price oracle

All borrower balances, including collateral and repurchase balances are valued in USD using decentralized price oracles (primarily [Chainlink](https://chain.link/)). These oracles are source of truth for the fair-market value of all tokens on the Protocol (including all collateral tokens) and are decentralized to mitigate against unilateral attack by a malicious data provider (for more information, see risk disclosures on [oracle risk)](/protocol/risk-disclosures/term-repo-risks.md#oracle-risk).

### Withdraw collateral

If at any time a borrower has [margin excess](/protocol/term-repos/terminology.md#margin-excess), the borrower may withdraw collateral by calling the public function `externalUnlockCollateral`.  A borrower may not make any withdrawals that would put their account into a [margin deficit](broken://pages/wJn1mggFYDqxJs5R8FY2).

### Add collateral

If at any time a borrower wishes to post additional margin to their account as additional buffer against liquidation, they may do so by calling the public function `externalLockCollateral`. There are not limits to the amount of collateral a borrower my lock in this manner.


---

# 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.term.finance/protocol/term-repos/margin-maintenance.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.
