1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Zero-alloc event emission via `sol_log_data`.
//!
//! Solana programs can emit structured events by writing raw byte slices
//! to the transaction log. Indexers (Helius, Triton, etc.) pick these up.
//! Anchor uses borsh-serialized events behind proc macros. We skip all that.
//!
//! `emit_slices` writes one or more `&[u8]` segments in a single syscall.
//! Stack only, no heap, no alloc, no serialization framework.
//!
//! The `emit!` macro packs up to 8 slices into a stack array and calls
//! `sol_log_data` directly. Use it for discriminators, pubkeys, u64s,
//! whatever your indexer expects.
//!
//! ```rust,ignore
//! // Emit a "Deposit" event: 1-byte discriminator + pubkey + amount
//! let disc = [0x01u8];
//! let amount_bytes = amount.to_le_bytes();
//! emit!(&disc, user.address().as_ref(), &amount_bytes);
//! ```
//!
//! Raw bytes, zero overhead, no serialization framework.
/// Emit one or more byte slices as a single `sol_log_data` entry.
///
/// Each slice becomes a separate data segment in the log. Indexers can
/// parse these however they want. Zero alloc, stack only.
///
/// ```rust,ignore
/// emit_slices(&[&[0x01], authority.address().as_ref(), &amount.to_le_bytes()]);
/// ```
/// Emit byte slices as a structured event log entry.
///
/// Packs up to 8 slices on the stack and calls `sol_log_data` in a single
/// syscall. For indexer-friendly event emission without borsh, proc macros,
/// or an allocator.
///
/// ```rust,ignore
/// // Deposit event: discriminator + user pubkey + amount
/// let disc = [0x01u8];
/// let amt = deposit_amount.to_le_bytes();
/// emit!(&disc, user.address().as_ref(), &amt);
///
/// // Withdraw event: discriminator + vault + user + amount
/// let disc = [0x02u8];
/// let amt = withdraw_amount.to_le_bytes();
/// emit!(&disc, vault.address().as_ref(), user.address().as_ref(), &amt);
/// ```