> For the complete documentation index, see [llms.txt](https://cjay-1.gitbook.io/cjay-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cjay-1.gitbook.io/cjay-docs/contracts/events.md).

# Events

Every state transition emits an event so an off-chain indexer can rebuild plan history without polling `get_legacy`. Topic symbols are `symbol_short!` (≤ 9 chars).

| Event       | Topics                              | Data                                     | Emitted by                                          |
| ----------- | ----------------------------------- | ---------------------------------------- | --------------------------------------------------- |
| `created`   | `("created", owner: Address)`       | `(legacy_id: u64, threshold: u32)`       | `create_legacy`                                     |
| `deposited` | `("deposited", owner: Address)`     | `(legacy_id: u64, total_amount: i128)`   | `deposit`                                           |
| `approved`  | `("approved", guardian: Address)`   | `(legacy_id: u64, approvals_count: u32)` | `approve_guardian` (every call)                     |
| `verified`  | `("verified",)`                     | `legacy_id: u64`                         | `approve_guardian` (only when threshold is reached) |
| `released`  | `("released", token: Address)`      | `(legacy_id: u64, total_amount: i128)`   | `finalize_release`                                  |
| `claimed`   | `("claimed", beneficiary: Address)` | `(legacy_id: u64, amount: i128)`         | `claim_assets`                                      |
| `refunded`  | `("refunded", owner: Address)`      | `(legacy_id: u64, total_amount: i128)`   | `cancel_legacy` (only if the plan was funded)       |
| `cancelled` | `("cancelled", owner: Address)`     | `legacy_id: u64`                         | `cancel_legacy` (always)                            |

## Reconstructing a plan's history

```
created    -> plan exists, Draft
deposited  -> Funded
approved   -> one guardian signed (count tells you how many so far)
verified   -> threshold met, Verified
released   -> Released, claims written
claimed    -> one beneficiary withdrew
refunded + cancelled -> owner cancelled a funded plan
cancelled (no refunded) -> owner cancelled an unfunded Draft
```

## Consuming events

Soroban RPC `getEvents` filtered by contract ID:

```bash
stellar events \
  --network testnet \
  --start-ledger <ledger> \
  --id CAA55GCID6DTTQNUFMNT2PNKSBIDMMMKEPP6GKUKL3WJ3SH6QRRSXUNE
```

In TypeScript, use `rpc.Server.getEvents({ startLedger, filters: [{ type: "contract", contractIds: [CONTRACT_ID] }] })` and match on the first topic symbol.


---

# 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, and the optional `goal` query parameter:

```
GET https://cjay-1.gitbook.io/cjay-docs/contracts/events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
