sss_token/state/audit.rs
1use anchor_lang::prelude::*;
2
3/// Enumerates all auditable actions in the SSS stablecoin system.
4/// Used by both the on-chain `AuditLogEntry` account type and the
5/// Anchor event types in `events.rs`.
6#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug)]
7pub enum AuditAction {
8 Mint,
9 Burn,
10 Freeze,
11 Thaw,
12 Pause,
13 Unpause,
14 BlacklistAdd,
15 BlacklistRemove,
16 Seize,
17 RoleUpdate,
18 MinterUpdate,
19 AuthorityTransfer,
20 ReserveAttestation,
21}
22
23/// On-chain audit log entry account — **reserved for optional use**.
24///
25/// The primary audit trail for SSS stablecoins is implemented via Anchor events
26/// (see `events.rs`), which are emitted on every state-changing operation and can
27/// be indexed off-chain via `getTransaction` logs or the SDK's `parseTransactionEvents`.
28///
29/// This account type is provided for issuers who require **on-chain audit persistence**
30/// (e.g., for regulatory proof that cannot rely on RPC log availability). Creating a
31/// PDA per operation incurs rent costs (~0.003 SOL per entry), so it is opt-in.
32///
33/// Seeds: `["audit", config, index (u64 LE)]`
34#[account]
35pub struct AuditLogEntry {
36 pub bump: u8,
37 pub config: Pubkey,
38 pub index: u64,
39 pub action: AuditAction,
40 pub actor: Pubkey,
41 pub target: Option<Pubkey>,
42 pub amount: Option<u64>,
43 pub details: String, // max 256
44 pub timestamp: i64,
45}
46
47impl AuditLogEntry {
48 pub const MAX_DETAILS_LEN: usize = 256;
49 pub const SEED_PREFIX: &'static [u8] = b"audit";
50
51 // 8 + 1 + 32 + 8 + 1 + 32 + (1 + 32) + (1 + 8) + (4 + 256) + 8
52 pub const SPACE: usize = 8 + 1 + 32 + 8 + 1 + 32 + (1 + 32) + (1 + 8) + (4 + 256) + 8;
53}