> 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/build-on-it/quick-start/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`                                                                                                                                                                                                                                                           |
| `MarginAdded`           | `add_margin`         | amount, new posted total, the health ratio that triggered it                                                                                                                                                                                                                                                        |
| `PositionOpened`        | `open_position`      | `mode` (`Normal`), `usdc_in`, `jitosol_purchased`, `perp_base_amount`, `timestamp`                                                                                                                                                                                                                                  |
| `PositionClosed`        | `close_position`     | `usdc_out`, `realized_pnl_signed`, `timestamp`                                                                                                                                                                                                                                                                      |
| `PositionReduced`       | `reduce_position`    | `requested_lots`, `closed_lots`, `before_base_lots`, `after_base_lots`, `jitosol_sold`, `usdc_from_spot`, `margin_withdrawn`, `margin_added`, `health_bps_before`, `permissionless`, `timestamp` — `permissionless` records whether a stranger cranked the de-lever or the keeper did                               |
| `DeltaObserved`         | `rebalance_hedge`    | `target_base_lots`, `current_base_lots`, `delta_bps`, `band_bps`, `breaches_band`, `perp_equity_usdc`, `timestamp` — emitted even when the band is not breached, so drift is observable between corrections                                                                                                         |
| `DeltaRebalanced`       | `rebalance_hedge`    | `target_base_lots`, `before_base_lots`, `after_base_lots`, `filled_lots`, `clipped`, `collateral_capped`, `observed_delta_bps`, `residual_lots`, `timestamp` — `residual_lots` is the correction still outstanding; a non-zero value with `collateral_capped` means margin, not the clip, is the binding constraint |
| `NavAttesterStalled`    | `settle`             | `last_nav_attest_ts`, `stalled_seconds`, `timestamp` — emitted when `settle` auto-pauses after NAV attestation has been dead for 2h, re-opening the permissionless `emergency_close` route                                                                                                                          |
| `OraclesSet`            | `set_oracles`        | `sol_oracle`, `jitosol_oracle`, `timestamp`                                                                                                                                                                                                                                                                         |
| `PhoenixEnabled`        | `enable_phoenix`     | `trader`, `market`, `canonical_ata`, `timestamp`                                                                                                                                                                                                                                                                    |
| `LendingEnabled`        | `enable_lending`     | `kamino_lend_reserve`, `vault_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`                                                                                                                                                                                                                                           |
| `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`                                                                                                                                                                                                                                                                             |
| `FeesCollected`         | `collect_fees`       | `perf_fee_usdc`, `admin_share_usdc`, `reserve_share_usdc`, `new_hwm_share_price_1e9`, `timestamp`                                                                                                                                                                                                                   |
| `DepegAutoPaused`       | `settle`             | `timestamp` — emitted when a jitoSOL depeg auto-pauses the vault                                                                                                                                                                                                                                                    |
| `ParamsUpdated`         | `update_params`      | every configurable parameter plus `authorized_keeper`, `max_position_base_lots`, `timestamp`                                                                                                                                                                                                                        |
| `AdminTransferProposed` | `transfer_admin`     | `current_admin`, `pending_admin`, `timestamp`                                                                                                                                                                                                                                                                       |
| `AdminTransferred`      | `accept_admin`       | `previous_admin`, `new_admin`, `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](/build-on-it/quick-start/instructions.md) · [Account structure](/build-on-it/quick-start/accounts.md) · [Errors](/build-on-it/quick-start/errors.md)
