# uTokens

The uTokens are the implementation of the interest-bearing token for the Unlockd protocol. \
They are the reserves, where all the underlying tokens will be stored.

## View Methods

### balanceOf

`function balanceOf(address user) public view returns (uint256)`

*Calculates the balance of the user: principal balance + interest generated by the principal*

#### *Call Params*

| Name | Type    | Description                          |
| ---- | ------- | ------------------------------------ |
| user | address | The user whose balance is calculated |

#### Return Values

| Type    | Description             |
| ------- | ----------------------- |
| uint256 | The balance of the user |

### scaledBalanceOf

`function scaledBalanceOf(address user) external view returns (uint256)`

Returns the scaled balance of the user. The scaled balance is the sum of all the updated stored balances divided by the reserve's liquidity index at the moment of the update.

#### Call Params

| Name | Type    | Description                          |
| ---- | ------- | ------------------------------------ |
| user | address | The user whose balance is calculated |

#### Return Values

| Type    | Description                    |
| ------- | ------------------------------ |
| uint256 | The scaled balance of the user |

### getScaledUserBalanceAndSupply

`function getScaledUserBalanceAndSupply(address user) external view returns (uint256, uint256)`

Returns the scaled balance of the user and the scaled total supply.

#### Call Params

| Name | Type    | Description             |
| ---- | ------- | ----------------------- |
| user | address | The address of the user |

#### Return Values

| Type    | Description                                    |
| ------- | ---------------------------------------------- |
| uint256 | The scaled balance of the user                 |
| uint256 | The scaled balance and the scaled total supply |

### UNDERLYING\_ASSET\_ADDRESS

`function UNDERLYING_ASSET_ADDRESS() public view returns (address)`

Returns the address of the underlying asset of this uToken.

#### Return Values

| Type    | Description                           |
| ------- | ------------------------------------- |
| address | the underlying address of this uToken |

### RESERVE\_TREASURY\_ADDRESS

`function RESERVE_TREASURY_ADDRESS() public view returns (address)`

Returns the address of the Unlockd treasury, receiving the fees on this uToken

#### Return Values

| Type    | Description                                   |
| ------- | --------------------------------------------- |
| address | the addres of the treasury wallet or contract |

### scaledTotalSupply

`function scaledTotalSupply() public view virtual returns (uint256)`

Returns the scaled total supply of the variable debt token. Represents sum(debt/index).

#### Return Values

| Type    | Description             |
| ------- | ----------------------- |
| uint256 | the scaled total supply |

### totalSupply

`function totalSupply() public view returns (uint256)`

Calculates the total supply of the specific uToken since the balance of every single user increases over time. The total supply does that too.

#### Return Values

| Type    | Description              |
| ------- | ------------------------ |
| uint256 | the current total supply |

## Write Methods

### burn

`function burn(address user, address receiverOfUnderlying, uint256 amount, uint256 index) external`

Burns uTokens from `user` and sends the equivalent amount of underlying to receiverOfUnderlying. This happens after a withdrawal.

{% hint style="info" %}
Only callable by the LendPool
{% endhint %}

#### Call Params

| Name                 | Type    | Description                                   |
| -------------------- | ------- | --------------------------------------------- |
| user                 | address | The owner of the uTokens, getting them burned |
| receiverOfUnderlying | address | The address that will receive the underlying  |
| amount               | uint256 | The amount being burned                       |
| index                | uint256 | The new liquidity index of the reserve        |

### mint

`function mint(address user, uint256 amount, uint256 index) external returns (bool)`

Mints `amount` uTokens to the user. This happens after a deposit.

{% hint style="info" %}
Only callable by the LendPool.
{% endhint %}

#### Call Params

| Name   | Type    | Description                             |
| ------ | ------- | --------------------------------------- |
| user   | address | The address receiving the minted tokens |
| amount | uint256 | The amount of tokens getting minted     |
| index  | uint256 | The new liquidity index of the reserve  |

#### Return Values

| Type | Description                                          |
| ---- | ---------------------------------------------------- |
| bool | `true` if the the previous balance of the user was 0 |

### mintToTreasury

`function mintToTreasury(uint256 amount, uint256 index) external`

Mints uTokens to the treasury wallet or contract address.

{% hint style="info" %}
Only callable by the LendPool
{% endhint %}

#### Call Params

| Name   | Type    | Description                            |
| ------ | ------- | -------------------------------------- |
| amount | uint256 | The amount of tokens getting minted    |
| index  | uint256 | The new liquidity index of the reserve |

### transferUnderlyingTo

`function transferUnderlyingTo(address target, uint256 amount) external returns (uint256)`

Transfers the underlying asset to `target`. Used by the LendPool to transfer assets in borrow(), withdraw() and flashLoan()

#### Call Params

| Name   | Type    | Description                    |
| ------ | ------- | ------------------------------ |
| target | address | The recipient of the uTokens   |
| amount | uint256 | The amount getting transferred |

#### Return Values

| Type    | Description            |
| ------- | ---------------------- |
| uint256 | The amount transferred |


---

# 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://devs.unlockd.finance/unlockd-for-devs-v1/the-core-protocol/utokens.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.
