> For the complete documentation index, see [llms.txt](https://calnix.gitbook.io/aave-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calnix.gitbook.io/aave-book/functions/common-functions/.updateinterestrates.md).

# .updateInterestRates

## TLDR

The `updateInterestRates` function serves to update the following interest rates

* liquidity interest rate&#x20;
* variable borrow interest rate&#x20;
* stable borrow interest rate

Typically, this function is executed **after state-changes have been done** (borrow, repay, supply, etc), to reflect updated rates, accounting for said action taken.&#x20;

## Code

### **.updateInterestRates**&#x20;

`updateInterestRates` will modify system-wide rates according to whether&#x20;

* liquidity added: supply or repay
* liquidity removed: borrow or redeem

<figure><img src="/files/6uj72tm2kK7VnBn33KkW" alt=""><figcaption></figcaption></figure>

* In most instances, either `liquidityAdded` or `liquidityRemoved` will be a zero value, while the other is a non-zero value.
* The core logic is wrapped within `.calculateInterestRates`, which returns the updated rates.

### Execution Flow

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

## **.calculateInterestRates**&#x20;

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

### Visual Walkthrough&#x20;

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

* get necessary ratios which will be used in the later section to examine if utilization has exceeded certain thresholds

<figure><img src="/files/8NbqAIkVQXxEWsMxOrsb" alt=""><figcaption></figcaption></figure>

* If borrow utilization exceeds optimal utilization, {...}, else {...}
* OPTIMAL\_USAGE\_RATIO and MAX\_EXCESS\_USAGE\_RATIO are immutable; values are set within constructor.
* For in-depth explanation on why the increments are done as above, see:
  * [variable rate model](/aave-book/deposit-and-borrow-interest.md#borrow-interest)
  * [stable rate model ](/aave-book/stable-borrowing.md#stable-rate-model)

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

* there is an additional check for stable rates

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

* getOverallBorrowRate simply calculates the weighted average borrow rate based off variable and stable components
* currentLiquidityRate is calculated as a component of overallBorrowRate, accounting for the portion that goes to the treasury.

### Complete picture

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


---

# 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://calnix.gitbook.io/aave-book/functions/common-functions/.updateinterestrates.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.
