# SiloLens

> SiloLens

Utility contract that simplifies reading data from Silo protocol contracts

## Methods

### balanceOfUnderlying

```solidity
function balanceOfUnderlying(uint256 _assetTotalDeposits, contract IShareToken _shareToken, address _user) external view returns (uint256)
```

Get underlying balance of collateral or debt token

*You can think about debt and collateral tokens as cToken in compound. They represent ownership of debt or collateral in given Silo. This method converts that ownership to exact amount of underlying token.*

#### Parameters

| Name                 | Type                 | Description                                                                                                                                                                                                                |
| -------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \_assetTotalDeposits | uint256              | Total amount of assets that has been deposited or borrowed. For collateral token, use `totalDeposits` to get this value. For debt token, use `totalBorrowAmount` to get this value.                                        |
| \_shareToken         | contract IShareToken | share token address. It's the collateral and debt share token address. You can find these addresses in: - `ISilo.AssetStorage.collateralToken` - `ISilo.AssetStorage.collateralOnlyToken` - `ISilo.AssetStorage.debtToken` |
| \_user               | address              | wallet address for which to read data                                                                                                                                                                                      |

#### Returns

| Name | Type    | Description                                                     |
| ---- | ------- | --------------------------------------------------------------- |
| \_0  | uint256 | balance of underlying token deposited or borrowed of given user |

### borrowAPY

```solidity
function borrowAPY(contract ISilo _silo, address _asset) external view returns (uint256)
```

Yearly interest rate for borrowing asset token, dynamically calculated for current block timestamp

#### Parameters

| Name    | Type           | Description                          |
| ------- | -------------- | ------------------------------------ |
| \_silo  | contract ISilo | Silo address from which to read data |
| \_asset | address        | asset address                        |

#### Returns

| Name | Type    | Description          |
| ---- | ------- | -------------------- |
| \_0  | uint256 | APY with 18 decimals |

### borrowShare

```solidity
function borrowShare(contract ISilo _silo, address _asset, address _user) external view returns (uint256)
```

Get debt token balance of a user

*Debt token represents a share in total debt of given asset. This method calls balanceOf(\_user) on that token.*

#### Parameters

| Name    | Type           | Description                           |
| ------- | -------------- | ------------------------------------- |
| \_silo  | contract ISilo | Silo address from which to read data  |
| \_asset | address        | asset address for which to read data  |
| \_user  | address        | wallet address for which to read data |

#### Returns

| Name | Type    | Description                         |
| ---- | ------- | ----------------------------------- |
| \_0  | uint256 | balance of debt token of given user |

### calcFee

```solidity
function calcFee(uint256 _amount) external view returns (uint256)
```

Calculate amount of entry fee for given amount

#### Parameters

| Name     | Type    | Description                       |
| -------- | ------- | --------------------------------- |
| \_amount | uint256 | amount for which to calculate fee |

#### Returns

| Name | Type    | Description                    |
| ---- | ------- | ------------------------------ |
| \_0  | uint256 | Amount of token fee to be paid |

### calculateBorrowValue

```solidity
function calculateBorrowValue(contract ISilo _silo, address _user, address _asset, uint256, uint256) external view returns (uint256)
```

Calculate value of borrowed asset by user

*It dynamically adds interest earned to borrowed amount*

#### Parameters

| Name    | Type           | Description                                  |
| ------- | -------------- | -------------------------------------------- |
| \_silo  | contract ISilo | Silo address from which to read data         |
| \_user  | address        | account for which calculation are done       |
| \_asset | address        | token address for which calculation are done |
| \_3     | uint256        | undefined                                    |
| \_4     | uint256        | undefined                                    |

#### Returns

| Name | Type    | Description                                      |
| ---- | ------- | ------------------------------------------------ |
| \_0  | uint256 | value of debt denominated in ETH with 18 decimal |

### calculateCollateralValue

```solidity
function calculateCollateralValue(contract ISilo _silo, address _user, address _asset) external view returns (uint256)
```

Calculate value of collateral asset for user

*It dynamically adds interest earned. Takes for account collateral only deposits as well.*

#### Parameters

| Name    | Type           | Description                                  |
| ------- | -------------- | -------------------------------------------- |
| \_silo  | contract ISilo | Silo address from which to read data         |
| \_user  | address        | account for which calculation are done       |
| \_asset | address        | token address for which calculation are done |

#### Returns

| Name | Type    | Description                                            |
| ---- | ------- | ------------------------------------------------------ |
| \_0  | uint256 | value of collateral denominated in ETH with 18 decimal |

### collateralBalanceOfUnderlying

```solidity
function collateralBalanceOfUnderlying(contract ISilo _silo, address _asset, address _user) external view returns (uint256)
```

Get underlying balance of all deposits of given token of given user including "collateralOnly" deposits

*It reads directly from storage so interest generated between last update and now is not taken for account*

#### Parameters

| Name    | Type           | Description                           |
| ------- | -------------- | ------------------------------------- |
| \_silo  | contract ISilo | Silo address from which to read data  |
| \_asset | address        | asset address for which to read data  |
| \_user  | address        | wallet address for which to read data |

#### Returns

| Name | Type    | Description                         |
| ---- | ------- | ----------------------------------- |
| \_0  | uint256 | balance of debt token of given user |

### collateralOnlyDeposits

```solidity
function collateralOnlyDeposits(contract ISilo _silo, address _asset) external view returns (uint256)
```

Get amount of asset token that has been deposited to Silo with option "collateralOnly"

*It reads directly from storage so interest generated between last update and now is not taken for account*

#### Parameters

| Name    | Type           | Description                          |
| ------- | -------------- | ------------------------------------ |
| \_silo  | contract ISilo | Silo address from which to read data |
| \_asset | address        | asset address for which to read data |

#### Returns

| Name | Type    | Description                                                  |
| ---- | ------- | ------------------------------------------------------------ |
| \_0  | uint256 | amount of all "collateralOnly" deposits made for given asset |

### debtBalanceOfUnderlying

```solidity
function debtBalanceOfUnderlying(contract ISilo _silo, address _asset, address _user) external view returns (uint256)
```

Get amount of debt of underlying token for given user

*It reads directly from storage so interest generated between last update and now is not taken for account*

#### Parameters

| Name    | Type           | Description                           |
| ------- | -------------- | ------------------------------------- |
| \_silo  | contract ISilo | Silo address from which to read data  |
| \_asset | address        | asset address for which to read data  |
| \_user  | address        | wallet address for which to read data |

#### Returns

| Name | Type    | Description                      |
| ---- | ------- | -------------------------------- |
| \_0  | uint256 | balance of underlying token owed |

### depositAPY

```solidity
function depositAPY(contract ISilo _silo, address _asset) external view returns (uint256)
```

Yearly interest rate for depositing asset token, dynamically calculated for current block timestamp

#### Parameters

| Name    | Type           | Description                          |
| ------- | -------------- | ------------------------------------ |
| \_silo  | contract ISilo | Silo address from which to read data |
| \_asset | address        | asset address                        |

#### Returns

| Name | Type    | Description          |
| ---- | ------- | -------------------- |
| \_0  | uint256 | APY with 18 decimals |

### getBorrowAmount

```solidity
function getBorrowAmount(contract ISilo _silo, address _asset, address _user, uint256 _timestamp) external view returns (uint256)
```

Calculates current borrow amount for user with interest

*Interest is calculated based on the provided timestamp with is expected to be current time.*

#### Parameters

| Name        | Type           | Description                                  |
| ----------- | -------------- | -------------------------------------------- |
| \_silo      | contract ISilo | Silo address from which to read data         |
| \_asset     | address        | token address for which calculation are done |
| \_user      | address        | account for which calculation are done       |
| \_timestamp | uint256        | timestamp used for interest calculations     |

#### Returns

| Name | Type    | Description                                                     |
| ---- | ------- | --------------------------------------------------------------- |
| \_0  | uint256 | total amount of asset user needs to repay at provided timestamp |

### getModel

```solidity
function getModel(contract ISilo _silo, address _asset) external view returns (contract IInterestRateModel)
```

*gets interest rates model object*

#### Parameters

| Name    | Type           | Description                                |
| ------- | -------------- | ------------------------------------------ |
| \_silo  | contract ISilo | Silo address from which to read data       |
| \_asset | address        | asset for which to calculate interest rate |

#### Returns

| Name | Type                        | Description                                    |
| ---- | --------------------------- | ---------------------------------------------- |
| \_0  | contract IInterestRateModel | IInterestRateModel interest rates model object |

### getUserLTV

```solidity
function getUserLTV(contract ISilo _silo, address _user) external view returns (uint256 userLTV)
```

Returns Loan-To-Value for an account

*Each Silo has multiple asset markets (bridge assets + unique asset). This function calculates a sum of all deposits and all borrows denominated in ETH. Returns fraction between borrow value and deposit value with 18 decimals.*

#### Parameters

| Name   | Type           | Description                                |
| ------ | -------------- | ------------------------------------------ |
| \_silo | contract ISilo | Silo address from which to read data       |
| \_user | address        | wallet address for which LTV is calculated |

#### Returns

| Name    | Type    | Description                       |
| ------- | ------- | --------------------------------- |
| userLTV | uint256 | user current LTV with 18 decimals |

### getUserLiquidationThreshold

```solidity
function getUserLiquidationThreshold(contract ISilo _silo, address _user) external view returns (uint256 liquidationThreshold)
```

Get combined liquidation threshold for a user

*Methodology for calculating liquidation threshold is as follows. Each Silo is combined form multiple assets (bridge assets + unique asset). Each of these assets may have different liquidation threshold. That means effective liquidation threshold must be calculated per asset based on current deposits and borrows of given account.*

#### Parameters

| Name   | Type           | Description                           |
| ------ | -------------- | ------------------------------------- |
| \_silo | contract ISilo | Silo address from which to read data  |
| \_user | address        | wallet address for which to read data |

#### Returns

| Name                 | Type    | Description                         |
| -------------------- | ------- | ----------------------------------- |
| liquidationThreshold | uint256 | liquidation threshold of given user |

### getUserMaximumLTV

```solidity
function getUserMaximumLTV(contract ISilo _silo, address _user) external view returns (uint256 maximumLTV)
```

Get combined maximum Loan-To-Value for a user

*Methodology for calculating maximum LTV is as follows. Each Silo is combined form multiple assets (bridge assets + unique asset). Each of these assets may have different maximum Loan-To-Value for opening borrow position. That means effective maximum LTV must be calculated per asset based on current deposits and borrows of given account.*

#### Parameters

| Name   | Type           | Description                           |
| ------ | -------------- | ------------------------------------- |
| \_silo | contract ISilo | Silo address from which to read data  |
| \_user | address        | wallet address for which to read data |

#### Returns

| Name       | Type    | Description                         |
| ---------- | ------- | ----------------------------------- |
| maximumLTV | uint256 | Maximum Loan-To-Value of given user |

### getUtilization

```solidity
function getUtilization(contract ISilo _silo, address _asset) external view returns (uint256)
```

Calculates fraction between borrowed and deposited amount of tokens for given asset denominated in percentage

*Utilization is calculated current values in storage so it does not take for account earned interest and ever-increasing total borrow amount. It assumes 1e18 = 100%.*

#### Parameters

| Name    | Type           | Description                          |
| ------- | -------------- | ------------------------------------ |
| \_silo  | contract ISilo | Silo address from which to read data |
| \_asset | address        | asset address                        |

#### Returns

| Name | Type    | Description       |
| ---- | ------- | ----------------- |
| \_0  | uint256 | utilization value |

### inDebt

```solidity
function inDebt(contract ISilo _silo, address _user) external view returns (bool)
```

Check if user is in debt

#### Parameters

| Name   | Type           | Description                           |
| ------ | -------------- | ------------------------------------- |
| \_silo | contract ISilo | Silo address from which to read data  |
| \_user | address        | wallet address for which to read data |

#### Returns

| Name | Type | Description                                                    |
| ---- | ---- | -------------------------------------------------------------- |
| \_0  | bool | TRUE if user borrowed any amount of any asset, otherwise FALSE |

### lensPing

```solidity
function lensPing() external pure returns (bool)
```

*Method for sanity check*

#### Returns

| Name | Type | Description |
| ---- | ---- | ----------- |
| \_0  | bool | always true |

### liquidity

```solidity
function liquidity(contract ISilo _silo, address _asset) external view returns (uint256)
```

*Amount of token that is available for borrowing.*

#### Parameters

| Name    | Type           | Description                          |
| ------- | -------------- | ------------------------------------ |
| \_silo  | contract ISilo | Silo address from which to read data |
| \_asset | address        | asset address for which to read data |

#### Returns

| Name | Type    | Description    |
| ---- | ------- | -------------- |
| \_0  | uint256 | Silo liquidity |

### protocolFees

```solidity
function protocolFees(contract ISilo _silo, address _asset) external view returns (uint256)
```

Get amount of fees earned by protocol to date

*It reads directly from storage so interest generated between last update and now is not taken for account*

#### Parameters

| Name    | Type           | Description                          |
| ------- | -------------- | ------------------------------------ |
| \_silo  | contract ISilo | Silo address from which to read data |
| \_asset | address        | asset address for which to read data |

#### Returns

| Name | Type    | Description                               |
| ---- | ------- | ----------------------------------------- |
| \_0  | uint256 | amount of fees earned by protocol to date |

### siloRepository

```solidity
function siloRepository() external view returns (contract ISiloRepository)
```

#### Returns

| Name | Type                     | Description |
| ---- | ------------------------ | ----------- |
| \_0  | contract ISiloRepository | undefined   |

### totalBorrowAmount

```solidity
function totalBorrowAmount(contract ISilo _silo, address _asset) external view returns (uint256)
```

Get amount of asset that has been borrowed

*It reads directly from storage so interest generated between last update and now is not taken for account*

#### Parameters

| Name    | Type           | Description                          |
| ------- | -------------- | ------------------------------------ |
| \_silo  | contract ISilo | Silo address from which to read data |
| \_asset | address        | asset address for which to read data |

#### Returns

| Name | Type    | Description                            |
| ---- | ------- | -------------------------------------- |
| \_0  | uint256 | amount of asset that has been borrowed |

### totalBorrowAmountWithInterest

```solidity
function totalBorrowAmountWithInterest(contract ISilo _silo, address _asset) external view returns (uint256 _totalBorrowAmount)
```

returns total borrow amount with interest dynamically calculated at current block timestamp

#### Parameters

| Name    | Type           | Description   |
| ------- | -------------- | ------------- |
| \_silo  | contract ISilo | undefined     |
| \_asset | address        | asset address |

#### Returns

| Name                | Type    | Description                         |
| ------------------- | ------- | ----------------------------------- |
| \_totalBorrowAmount | uint256 | total deposits amount with interest |

### totalBorrowShare

```solidity
function totalBorrowShare(contract ISilo _silo, address _asset) external view returns (uint256)
```

Get totalSupply of debt token

*Debt token represents a share in total debt of given asset*

#### Parameters

| Name    | Type           | Description                          |
| ------- | -------------- | ------------------------------------ |
| \_silo  | contract ISilo | Silo address from which to read data |
| \_asset | address        | asset address for which to read data |

#### Returns

| Name | Type    | Description               |
| ---- | ------- | ------------------------- |
| \_0  | uint256 | totalSupply of debt token |

### totalDeposits

```solidity
function totalDeposits(contract ISilo _silo, address _asset) external view returns (uint256)
```

Get amount of asset token that has been deposited to Silo

*It reads directly from storage so interest generated between last update and now is not taken for account*

#### Parameters

| Name    | Type           | Description                          |
| ------- | -------------- | ------------------------------------ |
| \_silo  | contract ISilo | Silo address from which to read data |
| \_asset | address        | asset address for which to read data |

#### Returns

| Name | Type    | Description                                 |
| ---- | ------- | ------------------------------------------- |
| \_0  | uint256 | amount of all deposits made for given asset |

### totalDepositsWithInterest

```solidity
function totalDepositsWithInterest(contract ISilo _silo, address _asset) external view returns (uint256 _totalDeposits)
```

returns total deposits with interest dynamically calculated at current block timestamp

#### Parameters

| Name    | Type           | Description   |
| ------- | -------------- | ------------- |
| \_silo  | contract ISilo | undefined     |
| \_asset | address        | asset address |

#### Returns

| Name            | Type    | Description                         |
| --------------- | ------- | ----------------------------------- |
| \_totalDeposits | uint256 | total deposits amount with interest |

## Errors

### IncorrectDataLength

```solidity
error IncorrectDataLength()
```


---

# 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://devdocs.silo.finance/smart-contracts-overview/silolens.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.
