> 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/for-developers/events.md).

# Events Reference

The ksUSD vault emits an event for nearly every state-changing instruction. Subscribe via `program.addEventListener("EventName", cb)` or parse logs from confirmed transactions.

> Sources: `programs/keystone-finance/src/instructions/*.rs` (search for `#[event]`).

| Event                 | Emitted by           | Notable fields                                                                                    |
| --------------------- | -------------------- | ------------------------------------------------------------------------------------------------- |
| `DepositEvent`        | `deposit`            | `user`, `usdc_amount`, `shares_minted`, `share_price_1e9`, `new_total_shares`, `timestamp`        |
| `WithdrawEvent`       | `withdraw_instant`   | `user`, `shares_burned`, `usdc_paid`, `share_price_1e9`, `new_total_shares`, `timestamp`          |
| `WithdrawalRequested` | `request_withdrawal` | `user`, `request_id`, `shares_burned`, `usdc_owed`, `timestamp`                                   |
| `WithdrawalProcessed` | `process_withdrawal` | `user`, `request_id`, `usdc_paid`, `cranker`, `timestamp`                                         |
| `PositionOpened`      | `open_position`      | `mode` (`Normal`), `usdc_in`, `jitosol_purchased`, `perp_base_amount`, `timestamp`                |
| `PositionClosed`      | `close_position`     | `usdc_out`, `realized_pnl_signed`, `timestamp`                                                    |
| `OraclesSet`          | `set_oracles`        | `sol_oracle`, `jitosol_oracle`, `timestamp`                                                       |
| `LendingEnabled`      | `enable_lending`     | `kamino_lend_reserve`, `vault_lend_collateral_ata`, `reserve_lend_collateral_ata`, `timestamp`    |
| `IdleLent`            | `lend_idle_usdc`     | `usdc_amount`, `new_usdc_lent_kamino`, `timestamp`                                                |
| `IdleUnlent`          | `unlend_usdc`        | `collateral_amount`, `usdc_received`, `new_usdc_lent_kamino`, `timestamp`                         |
| `ReserveLent`         | `lend_reserve`       | `usdc_amount`, `new_reserve_lent_kamino`, `timestamp`                                             |
| `ReserveUnlent`       | `unlend_reserve`     | `collateral_amount`, `usdc_received`, `new_reserve_lent_kamino`, `timestamp`                      |
| `NavAttested`         | `attest_nav`         | `old_nav_usdc`, `new_nav_usdc`, `change_bps`, `last_nav_attest_ts`, `timestamp`                   |
| `WindDownInitiated`   | `init_wind_down`     | `cached_nav_usdc`, `total_shares`, `timestamp`                                                    |
| `WindDownClaimed`     | `claim_wind_down`    | `user`, `shares_burned`, `usdc_paid`, `timestamp`                                                 |
| `PauseToggled`        | `set_pause`          | `paused`, `timestamp`                                                                             |
| `PeakReset`           | `reset_peak`         | `new_peak_share_price_1e9`, `timestamp`                                                           |
| `ReservePaidOut`      | `pay_from_reserve`   | `amount_usdc`, `new_reserve_fund_usdc`, `new_cached_nav_usdc`, `timestamp`                        |
| `FeesCollected`       | `collect_fees`       | `perf_fee_usdc`, `admin_share_usdc`, `reserve_share_usdc`, `new_hwm_share_price_1e9`, `timestamp` |

> `settle` and `emergency_close` log via `msg!` rather than `#[event]`; subscribe to program logs if you need them programmatically.

***

## Subscribing in TypeScript

```ts
const listener = program.addEventListener("DepositEvent", (event, _slot, _sig) => {
  console.log("deposit", {
    user: event.user.toBase58(),
    usdc: Number(event.usdcAmount.toString()) / 1e6,
    shares: Number(event.sharesMinted.toString()) / 1e6,
    price: Number(event.sharePrice1e9.toString()) / 1e9,
  });
});

// later
await program.removeEventListener(listener);
```

For historical events, parse transaction logs with `EventParser`:

```ts
import { EventParser } from "@coral-xyz/anchor";

const parser = new EventParser(program.programId, program.coder);
for (const event of parser.parseLogs(tx.meta.logMessages)) {
  console.log(event.name, event.data);
}
```

***

## Related

* [Instructions](/for-developers/instructions.md) · [Account structure](/for-developers/accounts.md) · [Errors](/for-developers/errors.md)
