> 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/calculator.md).

# Calculator

This section contains functions for `calculating utilization`, `borrow rates`,`supply rates`, and `interest`, as well as for converting between asset amounts and values using oracle price data.&#x20;

This module is essential for performing calculations such as determining the current state of a lending pool, applying interest to loans or deposits, and converting between different tokens based on their price.

### calculate\_utilization

> **Description:** This function calculates the utilization ratio of an asset in a lending pool. The utilization ratio is the ratio of total borrowed assets to the total available assets.

> **Use Cases:** This function is used when determining the demand for an asset in the lending pool, which can influence the interest rates applied to borrowing and lending transactions.

```rust
public fun caculate_utilization(
    storage: &mut Storage, 
    asset: u8
): u256 {}
```

### calculate\_borrow\_rate

> **Description:** This function calculates the borrowing interest rate for an asset based on its utilization ratio.

> **Use Cases:** This function is used when a user wishes to borrow an asset from the lending pool. The interest rate calculated will be applied to the loan.

```rust
public fun calculate_borrow_rate(
    storage: &mut Storage, 
    asset: u8
): u256 {}
```

### calculate\_supply\_rate

> **Description:** This function calculates the supply (or deposit) interest rate for an asset based on its borrowing rate and utilization ratio.

> **Use Cases:** This function is used when a user deposits an asset into the lending pool. The interest rate calculated will be the rate at which their deposit accrues interest.

```rust
public fun calculate_supply_rate(
    storage: &mut Storage, 
    asset: u8, 
    borrow_rate: u256
): u256 {}
```

### calculate\_compounded\_interest

> **Description:** This function calculates the compounded interest over a period of time based on a given rate.

> **Use Cases:** This function can be used when calculating the interest accrued on a deposit or loan over a period of time.

```rust
public fun calculate_compounded_interest(
    timestamp_difference: u256, 
    rate: u256
): u256 {}
```

### calculate\_linear\_interest

> **Description:** This function calculates the linear interest over a period of time based on a given rate.

> **Use Cases:** This function can be used when calculating the interest accrued on a deposit or loan over a period of time.

```rust
public fun calculate_linear_interest(
    timestamp_difference: u256, 
    rate: u256
): u256 {}
```

### calculate\_value

> **Description:** This function converts an amount of an asset to its value in a base currency using the price data from a price oracle.

> **Use Cases:** This function can be used when displaying the value of an asset to a user, or when performing calculations that require the value of an asset in the base currency.

```rust
public fun calculate_value(
    clock: &Clock, 
    oracle: &PriceOracle, 
    amount: u256, 
    oracle_id: u8
): u256 {}
```

### calculate\_amount

> **Description:** This function converts a value in a base currency to an amount of an asset using the price data from a price oracle.

```rust
public fun calculate_amount(
    clock: &Clock, 
    oracle: &PriceOracle, 
    value: u256, 
    oracle_id: u8
): 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/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.
