> For the complete documentation index, see [llms.txt](https://docs.yo.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yo.xyz/integrations/integration-guides/sdk/core/client.md).

# Client

The `YoClient` class is the main entry point for `@yo-protocol/core`. It wraps all vault reads, actions, and API calls.

## Creating a Client

```ts
import { createYoClient } from '@yo-protocol/core'

// Minimal — auto-creates a publicClient
const client = createYoClient({ chainId: 8453 })

// With partner ID and custom viem clients
import { createPublicClient, http } from 'viem'
import { base } from 'viem/chains'

const client = createYoClient({
  chainId: 8453,
  partnerId: 42,
  publicClient: createPublicClient({ chain: base, transport: http() }),
  walletClient: myWalletClient,
})
```

## Config

| Property       | Type           | Description                                                    |
| -------------- | -------------- | -------------------------------------------------------------- |
| `chainId`      | `1 \| 8453`    | Ethereum (1) or Base (8453)                                    |
| `publicClient` | `PublicClient` | Optional viem public client                                    |
| `walletClient` | `WalletClient` | Optional viem wallet client (needed for transactions)          |
| `partnerId`    | `number`       | Optional partner attribution ID for gateway calls (default: 0) |

## Methods

### Vault Reads

| Method                           | Returns         | Description                                                  |
| -------------------------------- | --------------- | ------------------------------------------------------------ |
| `getVaults()`                    | `VaultConfig[]` | List vaults for the current chain                            |
| `getVaultState(vault)`           | `VaultState`    | On-chain vault state (name, totalAssets, exchangeRate, etc.) |
| `previewDeposit(vault, assets)`  | `bigint`        | Preview shares received for a deposit                        |
| `previewRedeem(vault, shares)`   | `bigint`        | Preview assets received for a redemption                     |
| `convertToAssets(vault, shares)` | `bigint`        | Convert share amount to assets                               |
| `convertToShares(vault, assets)` | `bigint`        | Convert asset amount to shares                               |

### Gateway Quote Reads

| Method                                | Returns  | Description                                    |
| ------------------------------------- | -------- | ---------------------------------------------- |
| `quotePreviewDeposit(vault, assets)`  | `bigint` | Gateway-aware deposit preview                  |
| `quotePreviewRedeem(vault, shares)`   | `bigint` | Gateway-aware redeem preview                   |
| `quotePreviewWithdraw(vault, assets)` | `bigint` | Gateway-aware withdraw preview (shares needed) |
| `quoteConvertToAssets(vault, shares)` | `bigint` | Gateway-aware share-to-asset conversion        |
| `quoteConvertToShares(vault, assets)` | `bigint` | Gateway-aware asset-to-share conversion        |

### Balance Reads

| Method                            | Returns             | Description                    |
| --------------------------------- | ------------------- | ------------------------------ |
| `getTokenBalance(token, account)` | `TokenBalance`      | ERC-20 balance                 |
| `getShareBalance(vault, account)` | `bigint`            | Vault share balance            |
| `getUserPosition(vault, account)` | `UserVaultPosition` | Full position (shares, assets) |

### Allowance Reads

| Method                                              | Returns          | Description                      |
| --------------------------------------------------- | ---------------- | -------------------------------- |
| `getAllowance(token, owner, spender)`               | `TokenAllowance` | Current ERC-20 allowance         |
| `hasEnoughAllowance(token, owner, spender, amount)` | `boolean`        | Check if allowance is sufficient |
| `getShareAllowance(vault, owner)`                   | `bigint`         | Gateway share allowance          |
| `getAssetAllowance(vault, owner)`                   | `bigint`         | Gateway asset allowance          |

### Actions (require walletClient)

| Method                             | Returns                     | Description                                    |
| ---------------------------------- | --------------------------- | ---------------------------------------------- |
| `deposit(params)`                  | `DepositResult`             | Deposit assets via gateway                     |
| `redeem(params)`                   | `RedeemResult`              | Redeem shares for assets via gateway           |
| `approve(token, amount, spender?)` | `ApproveResult`             | Approve token spending                         |
| `approveMax(token, spender?)`      | `ApproveResult`             | Approve max uint256                            |
| `depositWithApproval(params)`      | `DepositWithApprovalResult` | Approve (if needed) + deposit in one call      |
| `waitForTransaction(hash)`         | `TransactionReceipt`        | Wait for transaction confirmation              |
| `waitForRedeemReceipt(hash)`       | `RedeemReceipt`             | Wait + decode instant/requestId from redeem tx |

### Prepared Transactions (call data mode)

| Method                               | Returns                 | Description                                 |
| ------------------------------------ | ----------------------- | ------------------------------------------- |
| `prepareApprove(params)`             | `PreparedTransaction`   | Build approve call data without executing   |
| `prepareDeposit(params)`             | `PreparedTransaction`   | Build deposit call data without executing   |
| `prepareRedeem(params)`              | `PreparedTransaction`   | Build redeem call data without executing    |
| `prepareDepositWithApproval(params)` | `PreparedTransaction[]` | Build approve+deposit bundle for AA wallets |

### API Methods

| Method                                | Returns              | Description                          |
| ------------------------------------- | -------------------- | ------------------------------------ |
| `getVaultSnapshot(vault)`             | `VaultSnapshot`      | Off-chain snapshot (TVL, APY, pools) |
| `getVaultYieldHistory(vault)`         | `TimeseriesPoint[]`  | Historical APY timeseries            |
| `getVaultTvlHistory(vault)`           | `TimeseriesPoint[]`  | Historical TVL timeseries            |
| `getUserHistory(vault, user, limit?)` | `UserHistoryItem[]`  | User transaction history             |
| `getUserPoints(user)`                 | `UserPoints \| null` | User points and rank                 |
| `getPendingRedemptions(vault, user)`  | `PendingRedeem`      | User pending redemptions             |
| `getVaultPendingRedeems(vault)`       | `PendingRedeem`      | Vault-level pending redeems          |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.yo.xyz/integrations/integration-guides/sdk/core/client.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.
