> For the complete documentation index, see [llms.txt](https://docs.keystonefi.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keystonefi.xyz/keystone-finance/deposit.md).

# Deposit

Deposit USDC into the ksUSD vault and receive `ksUSD` share tokens at the current share price.

> **New here?** Read [What is ksUSD?](/keystone-finance/reserve-asset.md) first.

***

## The instruction

```
deposit(usdc_amount: u64)
```

In one atomic transaction:

* Transfers USDC from the user into the vault's USDC ATA
* Mints `ksUSD` to the user at the current share price
* Updates vault NAV accounting

| Account              | Mutability | Purpose                                   |
| -------------------- | ---------- | ----------------------------------------- |
| `vault`              | mut        | Vault PDA (seeds: `[b"vault"]`)           |
| `vault_usdc_account` | mut        | Vault's USDC ATA — receives the deposit   |
| `ksusd_mint`         | mut        | ksUSD share mint — vault PDA is authority |
| `user_usdc_account`  | mut        | Depositor's USDC source ATA               |
| `user_ksusd_account` | mut        | Depositor's ksUSD destination ATA         |
| `user`               | signer     | Depositor                                 |
| `token_program`      | —          | SPL token program                         |

***

## Share-price math

```
share_price_1e9 = (cached_nav_usdc × 1e9) / max(total_shares, 1)
shares_to_mint  = (usdc_amount × 1e9 / share_price_1e9) / 1_000     // ksUSD has 6 decimals
```

* **First deposit** into an empty vault mints `usdc_amount` shares 1:1 at $1.00 (initial `share_price_1e9 = 1_000_000_000`)
* **Every subsequent deposit** mints fewer shares as the share price drifts upward with accrued carry

***

## Guardrails

* **Vault must not be paused.** Admin can pause via `set_pause` for emergency response.
* **Deposit cap.** New deposits revert if `cached_nav_usdc + usdc_amount > deposit_cap_usdc` (default: $1M cap on launch).
* **No zero deposits.** `usdc_amount > 0` required.

***

## TypeScript example

```ts
import { Program, BN } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import { TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from "@solana/spl-token";

const PROGRAM_ID = new PublicKey("HvsAc157bJ7Pd4uGr7xssHMifGs6RMbPu14ZMsiEABWT");

const [vaultPda] = PublicKey.findProgramAddressSync(
  [Buffer.from("vault")],
  PROGRAM_ID
);

const vault = await program.account.vault.fetch(vaultPda);
const userUsdcAta  = getAssociatedTokenAddressSync(vault.usdcMint,  user.publicKey);
const userKsusdAta = getAssociatedTokenAddressSync(vault.ksusdMint, user.publicKey);
const vaultUsdcAta = getAssociatedTokenAddressSync(vault.usdcMint,  vaultPda, true);

const tx = await program.methods
  .deposit(new BN("100_000_000"))         // 100 USDC (6 decimals)
  .accountsStrict({
    vault: vaultPda,
    vaultUsdcAccount: vaultUsdcAta,
    ksusdMint: vault.ksusdMint,
    userUsdcAccount: userUsdcAta,
    userKsusdAccount: userKsusdAta,
    user: user.publicKey,
    tokenProgram: TOKEN_PROGRAM_ID,
  })
  .rpc();
```

***

## Events

`DepositEvent` is emitted on success:

```rust
pub struct DepositEvent {
    pub user: Pubkey,
    pub usdc_amount: u64,
    pub shares_minted: u64,
    pub share_price_1e9: u64,
    pub new_total_shares: u64,
    pub timestamp: i64,
}
```

***

## Related

* [Withdraw](/keystone-finance/withdraw.md) — instant vs. queued paths
* [Check position & NAV](/keystone-finance/check-position.md)
* [NAV & share pricing](/reference/nav-calculation.md)
* [Errors](/for-developers/errors.md)


---

# 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.keystonefi.xyz/keystone-finance/deposit.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.
