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

# Deposit into the Delta Vault

> Turn USDC into vault shares earning funding-rate yield.

This guide deposits USDC into the delta-vault with `open_perp=true`, which
simultaneously opens the matching SOL short to keep the vault delta-neutral.

## 1. Resolve PDAs

```ts theme={null}
import {
  findVaultPda,
  fetchVault,
} from '@/app/generated/delta-vault/accounts';

const [vault] = await findVaultPda({ perpsMarket: marketPda });
const vaultAccount = await fetchVault(rpc, vault);
```

## 2. Post the oracle (required for the spot leg)

Same pattern as the [perp guide](/guides/trade-perpetual), Hermes fetch +
`PythSolanaReceiver.buildPostPriceUpdateInstructions`.

## 3. Deposit

```ts theme={null}
import { getDepositInstruction } from '@/app/generated/delta-vault/instructions';

const ix = getDepositInstruction({
  user: wallet,
  vault,
  perpsMarket: marketPda,
  spotPool: vaultAccount.spotPool,
  oracle: priceUpdate,
  shareMint: vaultAccount.shareMint,
  userUsdcAta,
  userShareAta,
  usdcVault: vaultAccount.usdcVault,
  wsolVault: vaultAccount.wsolVault,
  perpsUserAccount: vaultAccount.perpsUserAccount,
  // + remaining accounts for place_order counterparties
  amount: 1_000_000_000n,    // 1,000 USDC
  openPerp: true,
  sizeAmount: 5_000_000_000n, // 5 SOL short (must match 50% leg sizing)
});

await sendTransaction([...postIxs, ix]);
```

## What happens on chain

<Steps>
  <Step title="USDC → vault">
    Full `amount` transferred into `vault.usdc_vault`.
  </Step>

  <Step title="Mint shares">
    Shares minted to `userShareAta`:
    `sharesOut = amount × totalShares / NAV` (or `amount` on the first deposit).
  </Step>

  <Step title="Spot leg">
    `amount / 2` swapped to wSOL via `kimia-perp::spot_swap`.
  </Step>

  <Step title="Perp leg">
    `amount / 2` deposited as perp collateral; a short of `sizeAmount` opened.
  </Step>
</Steps>

## Claim funding

Accrued funding is not live, it only updates NAV when someone cranks
`claim_funding`. Anyone can do this. The vault auto-settles via CPI:

```ts theme={null}
import { getClaimFundingInstruction } from '@/app/generated/delta-vault/instructions';

const ix = getClaimFundingInstruction({
  keeper: wallet,
  vault,
  perpsMarket: marketPda,
  perpsUserAccount: vaultAccount.perpsUserAccount,
});
```

After the crank, share price jumps by the post-skim yield, and subsequent
deposits get fewer shares for the same USDC.

## Withdraw

```ts theme={null}
import { getWithdrawInstruction } from '@/app/generated/delta-vault/instructions';

const ix = getWithdrawInstruction({
  user: wallet,
  vault,
  ...,
  amount: 500_000_000n, // 500 USDC worth of shares
  closePerp: true,      // proportionally close the hedge
});
```

With `closePerp=true`, the vault buys back a share-weighted portion of the perp
short and swaps the corresponding wSOL back to USDC before returning funds.
