> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mystockline.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Read borrowing power

> RiskLens returns max borrow and the per-book liquidation price for an account.

`RiskLens` is view-only. It reads the core and never changes state.

Use Robinhood Chain testnet addresses from [Addresses](/resources/addresses). The snippet keys match that table.

<Steps>
  <Step title="Point at the lens">
    Copy `riskLens` and `stockline` from Addresses. Load [`RiskLens.json`](/abis/RiskLens.json).

    <CodeGroup>
      ```typescript theme={"system"}
      import { createPublicClient, http, parseAbi } from "viem"
      import { addresses, chainId } from "./addresses" // Addresses, testnet

      const lensAbi = parseAbi([
        "function maxBorrow(address account) view returns (uint256)",
        "function health(address account) view returns (uint256)",
        "function liquidationPrice(address account, uint16 bookId) view returns (uint256)",
        "function snapshot(address account) view returns ((uint256 health, uint256 maxBorrow, (uint16 bookId, address collateral, uint256 amount, uint256 amountUi, uint256 debt, uint256 liquidationPrice)[] books))",
      ])

      const client = createPublicClient({
        chain: { id: chainId, name: "Robinhood Chain testnet", nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 }, rpcUrls: { default: { http: ["https://rpc.testnet.chain.robinhood.com"] } } },
        transport: http(),
      })
      ```

      ```solidity theme={"system"}
      // SPDX-License-Identifier: MIT
      pragma solidity 0.8.28;

      interface IRiskLens {
          function maxBorrow(address account) external view returns (uint256);
          function liquidationPrice(address account, uint16 bookId) external view returns (uint256);
      }

      contract PowerReader {
          IRiskLens public immutable lens;
          constructor(IRiskLens lens_) { lens = lens_; }
          function power(address account) external view returns (uint256) {
              return lens.maxBorrow(account);
          }
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Read power and the line">
    `maxBorrow` is sum of `collateral × price × LTV` across books, in USDG wei. `liquidationPrice` is 1e36, same convention as `EquityOracle.price()`.

    <CodeGroup>
      ```typescript theme={"system"}
      const account = "0x1111111111111111111111111111111111111111"
      const bookId = 8 // NVDA at launch; confirm on Books

      const [power, line] = await Promise.all([
        client.readContract({
          address: addresses.riskLens,
          abi: lensAbi,
          functionName: "maxBorrow",
          args: [account],
        }),
        client.readContract({
          address: addresses.riskLens,
          abi: lensAbi,
          functionName: "liquidationPrice",
          args: [account, bookId],
        }),
      ])
      ```

      ```solidity theme={"system"}
      function line(address account, uint16 bookId) external view returns (uint256) {
          return lens.liquidationPrice(account, bookId);
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Prefer snapshot in the app">
    One call returns health, max borrow, and every book the account is listed on, including `amountUi` for display.

    ```typescript theme={"system"}
    const snap = await client.readContract({
      address: addresses.riskLens,
      abi: lensAbi,
      functionName: "snapshot",
      args: [account],
    })
    // snap.books[i].amountUi uses token.uiMultiplier() when present. Display only.
    ```
  </Step>
</Steps>

## What can go wrong

* `UnknownBook` if `bookId` was never created.
* `liquidationPrice` is 0 when the account has no collateral in that book.
* Health is WAD. 1e18 is the line. Below 1e18 the account is liquidatable in LIVE or DARK.
* Do not multiply by `uiMultiplier` in your own risk math. The lens already keeps raw `amount` separate.
* Testnet book ids follow creation order. Do not hardcode production ids from this snippet.

Borrowing power is the sum of collateral times price times LTV across books, in USDG wei. The line for one book is `liquidationPrice`, 1e36, same convention as `EquityOracle.price()`.

Health is WAD. 1e18 is the line. Below 1e18 the account is liquidatable in LIVE or DARK. HALTED, CA\_WINDOW, SEQ\_DOWN, and pause block liquidations. Repay still works.

Prefer `snapshot` in a frontend so you do not issue four RPCs per card. Cache by block. The Stockline app footer prints the block hash so a user can match the drawer to a chain read.

## Return values

| Field                      | Scale                   | Meaning                                                                                                                   |
| -------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `health`                   | WAD (`1e18` = the line) | Weighted collateral at liquidation threshold divided by debt. Below `1e18` the account can be liquidated in LIVE or DARK. |
| `maxBorrow`                | USDG wei                | Additional USDG the account can borrow now, across every book it holds.                                                   |
| `books[].amount`           | Raw ERC-20 units        | Collateral supplied to that book. Use this for risk math.                                                                 |
| `books[].amountUi`         | Display units           | `amount` times `uiMultiplier`. Display only.                                                                              |
| `books[].debt`             | USDG wei                | Index-accrued debt on that book as of the last accrual.                                                                   |
| `books[].liquidationPrice` | `1e36`                  | The line for that book. Same scale as `EquityOracle.price()`. `0` when the account has no collateral there.               |

Next: [Open a loan](/developers/positions/open-loan), [Read the regime](/developers/market-hours).
