> For the complete documentation index, see [llms.txt](https://naviprotocol.gitbook.io/navi-protocol-developer-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://naviprotocol.gitbook.io/navi-protocol-developer-docs/smart-contract-overview/dynamic-calculator.md).

# Dynamic Calculator

This module includes functions to dynamically calculate a user's health factor, collateral value, loan value, APY, and more, accounting for potential changes in the user's balances.

It is utilized for risk management and user-interface purposes, such as determining whether a user's actions might put their account at risk of liquidation, or providing insights into the potential impact of a user's intended actions on their account.

### dynamic\_health\_factor

> **Description:** This function calculates a user's dynamic health factor, considering potential changes in their supply and borrow balances. It helps assess the user's risk level in relation to liquidation.

> **Use Cases:** This function is used when estimating how a user's health factor would be affected by an increase or decrease in their supplied or borrowed assets. It is critical for risk management and liquidation prevention.

```rust
public fun dynamic_health_factor<CoinType>(
  clock: &Clock,
  storage: &mut Storage,
  oracle: &PriceOracle,
  pool: &mut Pool<CoinType>,
  user: address,
  asset: u8,
  estimate_supply_value: u64, 
  estimate_borrow_value: u64, 
  is_increase: bool
): u256 {}
```

### ~~dynamic\_calculate\_apy~~

{% hint style="danger" %}
Since the upgrade to V3 incentives, V2 is no longer in use, so its APY will remain at 0. Don't use this function to fetch APY data.
{% endhint %}

> **Description:** This function calculates the dynamic APY for IncentiveV2 based on changes in a user's supply and borrow balances. It provides both the supply APY and borrow APY.

> **Use Cases:** This function is used to estimate how changes in a user's supply and borrow amounts will impact their expected yield. It is essential for users deciding whether to adjust their positions in a lending pool.

```rust
public fun dynamic_calculate_apy<CoinType>(
  clock: &Clock, 
  storage: &mut Storage, 
  pool: &mut Pool<CoinType>, 
  asset: u8, 
  estimate_supply_value: u64, 
  estimate_borrow_value: u64, 
  is_increase: bool
): (u256, u256){}
```


---

# 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://naviprotocol.gitbook.io/navi-protocol-developer-docs/smart-contract-overview/dynamic-calculator.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.
