# repay

## Overview

This function is called when the user wishes to repay his existing debts. User can opt to repay in full or partially.

<img src="/files/X1yJxpCoYJplFeDR31az" alt="" class="gitbook-drawing">

**Inputs**

* address of debt asset: if repaying DAI debt, pass the DAI address
* amount of debt to repay: does not need to be 100%
* interestRateMode: stable or variable
* onBehalfOf: if repaying another user's debt
* useATokens: false

{% hint style="info" %}
**`repayWithATokens`** has `useATokens`: `true`
{% endhint %}

## executeRepay

<figure><img src="/files/N8P1ilwM6c9PVVlBVqz3" alt=""><figcaption></figcaption></figure>

### Execution flow

* [ ] <mark style="color:orange;">cache + updateState</mark>
* [ ] get current debt&#x20;
* [ ] validateRepay
* [ ] get paybackAmount
* [ ] burn debt tokens
* [ ] <mark style="color:orange;">updateInterestRates</mark>
* [ ] setBorrowing
* [ ] updateIsolatedDebtIfIsolated
* [ ] handle repayment

We will breakdown and examine the unique sections of logics within **executeRepay**. Code delineated in orange are common functions and can be explored in that [section](/aave-book/functions/common-functions.md).

## Visual Aid

{% embed url="<https://link.excalidraw.com/readonly/7o8NGeqZaTRyhtCcaHmb?darkMode=true>" %}


---

# Agent Instructions: 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:

```
GET https://calnix.gitbook.io/aave-book/functions/repay.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
