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

# getIsolationModeState

## Overview

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2FYLfyJEi2Nv99n8CBOZwd%2Fimage.png?alt=media&amp;token=9b5204d3-c965-4245-9cc5-f00f42155f62" alt=""><figcaption></figcaption></figure>

* [x] <mark style="color:orange;">cache</mark>
* [x] <mark style="color:orange;">updateState</mark>
* [ ] getIsolationMode
* [ ] validateBorrow
* [ ] mint debt token
* [ ] setBorrowing&#x20;
* [ ] update IsolationMode debt
* [ ] <mark style="color:orange;">updateInterestRates</mark>
* [ ] transfer underlying to user

<img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2FZKVYSqoqxjX8PCf2h8bD%2Ffile.excalidraw.svg?alt=media&amp;token=22f4e1d6-494f-4f7a-ae2d-d0a38497e664" alt="" class="gitbook-drawing">

## getIsolationModeState

Check if user is in isolation mode, if so, return the isolated asset address and its corresponding debt ceiling.

{% hint style="info" %}
Isolation mode: user can only use the specific isolation asset as collateral
{% endhint %}

There 3 other functions within `getIsolationModeState` which we will cover:

1. `isUsingAsCollateralOne`
2. `_getFirstAssetIdByMask`
3. `getDebtCeiling`

Essentially,&#x20;

1. `isUsingAsCollateralOne`: check if user has ONLY ONE asset as collateral (any one).
2. If check returns true, possible that the user is in isolation mode.
   * get and return isolation details: `(true, assetAddress, debtCeiling)`
3. `_getFirstAssetIdByMask` is used to obtain the `assetID` of this asset.&#x20;
   * Since `isUsingAsCollateralOne` is `true`,&#x20;
   * only 1 asset to ID, no need to worry about multiple assets
4. If `isUsingAsCollateralOne` is `false`&#x20;
   * user has multiple reserves as collateral&#x20;
   * not in Isolation mode&#x20;
   * return `(false, address(0), 0)`

### `isUsingAsCollateralOne`

Check if user has ONLY ONE asset as collateral (any one).

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2F3cIZs8pksUEeZg5wqHJh%2Fimage.png?alt=media&amp;token=6b58a927-4b78-4b93-9136-c9acebddd384" alt=""><figcaption></figcaption></figure>

This function was explained previously when covering the `supply` function: [isUsingCollateralOne](/aave-book/functions/supply/isfirstsupply/isusingascollateralone-isusingascollateralany.md#isusingcollateralone)

### `_getFirstAssetIdByMask`

Returns the address of the first asset flagged in the bitmap given the corresponding bitmask.

* if collateral\_mask, find the first asset which has its collateral bit set to `1`

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2FGlr4bB6Scrbrh87SYyRB%2Fimage.png?alt=media&amp;token=c169f06e-da25-4763-a143-d0f17599c18f" alt=""><figcaption></figcaption></figure>

```solidity
uint256 internal constant COLLATERAL_MASK = 
0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
```

* `COLLATERAL_MASK` is passed as `mask`
* `bitmapData` is the binary string comprising of isolated collateral bits as explained in: [isUsingAsCollateralAny](/aave-book/functions/supply/isfirstsupply/isusingascollateralone-isusingascollateralany.md#isusingascollateralany)&#x20;

<img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2FowdWMLMs9FR47OodOWGC%2Ffile.excalidraw.svg?alt=media&amp;token=ee2154d5-b839-4240-b66c-649073c3c012" alt="" class="gitbook-drawing">

As we can see, we can end with id of value 1 -> index of the first asset which has its collateral bit set to `1` is 1.&#x20;

### `getDebtCeiling`

With the previously obtained asset index, we can retrieve the `assetAddress` by the `reserveList` mapping. With the address, we can retrieve its corresponding `reservesData` struct, using it to obtain the debt ceiling.

```solidity
address assetAddress = reserveList[assetId];  //declared on PoolStorage.sol
uint256 ceiling = reservesData[assetAddress].configuration.getDebtCeiling();
```

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2FMgh7wuHzwlUWyWQVFQ40%2Fimage.png?alt=media&amp;token=aa9b5265-2a5b-4c3d-b35a-53171b1b305f" alt=""><figcaption></figcaption></figure>

`getDebtCeiling` will extract the debt ceiling value held within bits 212-251 in the `ReserveConfigurationMap`.

<details>

<summary>Reference: ReserveConfigurationMap</summary>

![](https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2Fif2EJZM7Ut8nVdZ6Lv2o%2Fimage.png?alt=media\&token=242680ff-382c-4041-a6fd-85d2dc86b8a7)

</details>

`getDebtCeiling` utilizes the same approach as explained in [getReserveFactor](/aave-book/primer/bitmap-and-masks.md#getreservefactor); see that section for an in-depth explanation.

{% hint style="info" %}
The debt ceiling value has decimals as dictated in **`ReserveConfiguration::DEBT_CEILING_DECIMALS`**, like so:

```solidity
uint256 public constant DEBT_CEILING_DECIMALS = 2;
```

{% endhint %}
