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

# Lending

> Deposit into OMLP vaults and withdraw principal or accrued interest.

Lenders supply a Collateral Mint to its **OMLP (Option Margin Liquidity Pool)** vault and earn interest paid by Writers who borrow for leveraged Shorts.

## Depositing into an OMLP Vault

Use `buildDepositToPositionTransaction` to deposit token base units into a vault. Send the built instructions as a version 1 transaction:

```ts theme={"dark"}
import {
  buildDepositToPositionTransaction,
  sendBuiltTransaction,
} from "@epicentral/sos-sdk";
import { rpc, rpcSubscriptions } from "./config";

const built = await buildDepositToPositionTransaction({
  vault: vaultAddress,
  lenderTokenAccount,
  vaultTokenAccount,
  lender: lenderSigner.address,
  amount: 1_000_000_000n, // 1,000 USDC (6 decimals)
});

const signature = await sendBuiltTransaction({
  ...built,
  rpc,
  rpcSubscriptions,
  feePayer: lenderSigner,
  version: 1,
});
```

## Withdrawing from an OMLP Vault

Choose the withdrawal helper that matches your UI action:

> [tab] Specific Amount
>
> Use `buildWithdrawFromPositionTransaction` when the lender specifies an exact withdrawal amount in Collateral Mint base units.
>
> ```ts theme={"dark"}
> import {
>   buildWithdrawFromPositionTransaction,
>   sendBuiltTransaction,
> } from "@epicentral/sos-sdk";
> import { rpc, rpcSubscriptions } from "./config";
>
> const built = await buildWithdrawFromPositionTransaction({
>   vault: vaultAddress,
>   vaultTokenAccount,
>   lenderTokenAccount,
>   lender: lenderSigner.address,
>   amount: 500_000_000n, // 500 USDC (6 decimals)
> });
>
> const signature = await sendBuiltTransaction({
>   ...built,
>   rpc,
>   rpcSubscriptions,
>   feePayer: lenderSigner,
>   version: 1,
> });
> ```

> [tab] Withdraw All
>
> Use `withdrawAllFromPosition` to withdraw the lender's full share of vault liquidity, capped by the cash currently available in the vault.
>
> ```ts theme={"dark"}
> import {
>   sendBuiltTransaction,
>   withdrawAllFromPosition,
> } from "@epicentral/sos-sdk";
> import { rpc, rpcSubscriptions } from "./config";
>
> const { instructions, amount } = await withdrawAllFromPosition(rpc, {
>   vault: vaultAddress,
>   position: lenderPositionAddress,
>   vaultTokenAccount,
>   lenderTokenAccount,
>   lender: lenderSigner.address,
> });
>
> const signature = await sendBuiltTransaction({
>   instructions,
>   rpc,
>   rpcSubscriptions,
>   feePayer: lenderSigner,
>   version: 1,
> });
> ```

> [tab] Withdraw Interest Only
>
> Use `withdrawInterestFromPosition` to withdraw only share value above the lender's deposited cost basis, capped by available vault cash.
>
> ```ts theme={"dark"}
> import {
>   sendBuiltTransaction,
>   withdrawInterestFromPosition,
> } from "@epicentral/sos-sdk";
> import { rpc, rpcSubscriptions } from "./config";
>
> const { instructions, amount } = await withdrawInterestFromPosition(rpc, {
>   vault: vaultAddress,
>   position: lenderPositionAddress,
>   vaultTokenAccount,
>   lenderTokenAccount,
>   lender: lenderSigner.address,
> });
>
> const signature = await sendBuiltTransaction({
>   instructions,
>   rpc,
>   rpcSubscriptions,
>   feePayer: lenderSigner,
>   version: 1,
> });
> ```

> [!NOTE]
>
> Both `withdrawAllFromPosition` and `withdrawInterestFromPosition` check available vault cash before building instructions and throw if no withdrawable balance is available. If a borrower defaults and the settlement mint's Insurance Fund cannot cover the remaining shortfall, the uncovered amount socializes directly across active vault shares so withdrawals stay open and order-independent.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.