> For the complete documentation index, see [llms.txt](https://docs.hydromancer.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hydromancer.xyz/readme/builder-guides/vaults-and-borrow-lend.md).

# Vaults and borrow/lend

Show Hyperliquid vault deposits and the vaults an address leads, plus borrow and lend rates and each user's lending position.

Vault deposits and lending positions sit outside a wallet's perp and spot balances, so an earn page reads them with their own requests.

Apps with an earn or lending page usually need to:

* show which vaults a user has deposited into, and what each deposit is worth
* show the vaults an address leads
* list borrow and supply rates per token
* show a user's supplied and borrowed amounts and account health

**At a glance**

| What you need                                  | Use                                                                                                                                                                                                                                                      |
| ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| A user's vault deposits                        | [userVaultEquities](https://docs.hydromancer.xyz/readme/rest-api/vaults/uservaultequities)                                                                                                                                                               |
| The vaults an address leads                    | [leadingVaults](https://docs.hydromancer.xyz/readme/rest-api/vaults/leadingvaults)                                                                                                                                                                       |
| Rates and totals for every token               | [allBorrowLendReserveStates](https://docs.hydromancer.xyz/readme/rest-api/borrow-lend/allborrowlendreservestates)                                                                                                                                        |
| Rates and totals for one token                 | [borrowLendReserveState](https://docs.hydromancer.xyz/readme/rest-api/borrow-lend/borrowlendreservestate)                                                                                                                                                |
| A user's lending position                      | [borrowLendUserState](https://docs.hydromancer.xyz/readme/rest-api/borrow-lend/borrowlenduserstate)                                                                                                                                                      |
| Live deposits, withdrawals and lending actions | [userNonFundingLedgerEvents](https://docs.hydromancer.xyz/readme/websocket/user-data/usernonfundingledgerevents), [allUserNonFundingLedgerEvents](https://docs.hydromancer.xyz/readme/websocket/funding-and-deposits-data/allusernonfundingledgerevents) |

**Vault deposits**

[userVaultEquities](https://docs.hydromancer.xyz/readme/rest-api/vaults/uservaultequities) returns one row for every vault a user has deposited into:

* `vaultAddress` - the vault
* `equity` - what the deposit is worth now
* `lockedUntilTimestamp` - when the deposit can be withdrawn, in milliseconds

[leadingVaults](https://docs.hydromancer.xyz/readme/rest-api/vaults/leadingvaults) returns the vaults an address leads, each with its `address` and `name`.

**Borrow and lend rates**

[allBorrowLendReserveStates](https://docs.hydromancer.xyz/readme/rest-api/borrow-lend/allborrowlendreservestates) returns one entry per token, as a `[tokenIndex, state]` pair. [borrowLendReserveState](https://docs.hydromancer.xyz/readme/rest-api/borrow-lend/borrowlendreservestate) returns the same state for a single token, chosen by its index.

Each state has `borrowYearlyRate`, `supplyYearlyRate`, `utilization`, `totalSupplied`, `totalBorrowed`, `ltv` and `oraclePx`:

* Rates are yearly and written as decimals, so `0.05` is 5%.
* `utilization` is the share of the supplied amount that is borrowed.
* Tokens are identified by index. Match the index to a name with the `tokens` list in [spotMeta](https://docs.hydromancer.xyz/readme/rest-api/metadata/spotmeta); index `0` is USDC.

**A user's lending position**

[borrowLendUserState](https://docs.hydromancer.xyz/readme/rest-api/borrow-lend/borrowlenduserstate) returns the user's position per token in `tokenToState`, with the account's `health`. Each entry is a `[tokenIndex, state]` pair with a `supply` and a `borrow` side, each holding a `basis` and a `value`. `healthFactor` is `null` for an account with nothing borrowed. A user with no lending position gets an empty `tokenToState`.

**Live changes**

Vault deposits, vault withdrawals and borrow/lend actions arrive on the ledger streams: [userNonFundingLedgerEvents](https://docs.hydromancer.xyz/readme/websocket/user-data/usernonfundingledgerevents) for chosen users, or [allUserNonFundingLedgerEvents](https://docs.hydromancer.xyz/readme/websocket/funding-and-deposits-data/allusernonfundingledgerevents) for every account. The user stream also carries vault distributions and leader commissions.

**Putting it together**

1. Load the rates table from `allBorrowLendReserveStates`, and token names from `spotMeta`.
2. For a connected wallet, show `userVaultEquities` and `borrowLendUserState`.
3. Subscribe to `userNonFundingLedgerEvents` for that wallet, and refresh both when a vault or lending event arrives.
