# Tracking balance and TVL

#### Fetching User's Balance <a href="#key-features" id="key-features"></a>

To fetch user's balance within a specific pool:

```typescript
const userPoolBalance = await sdk.vaults.balanceOf(vault, pool, await signer.getAddress());const balance = await sdk.portfolio.getBalance(vault, poolId, user);
```

Wher&#x65;**:**

* **`vault`** – Address of the Yelay vault.
* **`pool`** – ID of the requested pool.

#### Retrieving TVL of a Client's Pool  <a href="#key-features" id="key-features"></a>

To fetch the Total Value Locked (TVL) of a specific pool within a Yelay vault:

```typescript
const vault = '0x1234';
const pool = 1234;
const poolsTvl = await sdk.data.getPoolTvl(vault, [pool]);
```

Where:

* **`vault`** – Address of the Yelay vault.
* **`pool`** – Array of pool IDs to calculate the total TVL

#### Getting historical TVL data for a vault and pool  <a href="#key-features" id="key-features"></a>

```typescript
// Fetch historical TVL data with various filter options
const historicalTVL = await sdk.data.getHistoricalTvl({
	vaultAddress: '0x1234...5678', // Required: The vault address to get TVL for
	poolId: 1, // Required: The specific pool ID to query
	fromTimestamp: 1641034800, // Optional: Start time in seconds (Jan 1, 2022)
	toTimestamp: 1672570800, // Optional: End time in seconds (Jan 1, 2023)
	page: 1, // Optional: Page number for pagination (starts at 1)
	pageSize: 30, // Optional: Number of records per page (max 100)
});

// Example with just the required parameters
const currentTVL = await sdk.data.getHistoricalTvl({
	vaultAddress: '0x1234...5678',
	poolId: 1,
});
```

The  method returns a paginated response with the following structure:

```json
// Example response from historicalTVL
{
  data: [
    {
      vaultAddress: "0x1234...5678",
      poolId: 1,
      createTimestamp: 1745820000,
      assets: "31000000000000"
    },
    // ... more data items
  ],
  totalItems: 11,    // Total number of items matching the query
  totalPages: 1,     // Total number of pages
  currentPage: 1,    // Current page number
  pageSize: 30       // Number of items per page
}
```


---

# 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://docs.yelay.io/yelay-sdk/tracking-balance-and-tvl.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.
