Skip to main content

Crate oculi

Crate oculi 

Source
Expand description

Oculi — structured, Borsh-serialized Anchor events for Solana programs.

§Why this exists

Solana programs rely on msg! for observability, but msg! performs string formatting on-chain. For a swap instruction logging an amount and a pubkey, msg! costs roughly 11,000 CU. Oculi replaces that with a single emit! call over a Borsh-serialized struct, cutting the same log entry to ~781 CU — a 92.96% reduction.

The emitted events are standard Anchor events, visible as Program data: entries in transaction metadata and decodable by any Borsh-aware client.

§Quick start

use anchor_lang::prelude::*;
use oculi::{log_info, log_warn};

#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct SwapExecuted {
    pub amount: u64,
    pub user: Pubkey,
}

pub fn swap(ctx: Context<Swap>, amount: u64) -> Result<()> {
    log_info!("swap_executed", SwapExecuted {
        amount,
        user: ctx.accounts.user.key(),
    });
    Ok(())
}

§Feature flags

FlagDefaultEffect
devnet-onlyoffCompiles out all emit! calls. Enable in mainnet builds.
no-entrypointoffPasses through to anchor-lang/no-entrypoint.

Re-exports§

pub use event::OculiEvent;
pub use level::LogLevel;

Modules§

event
The Anchor event struct emitted by every log! call.
level
Log severity levels for Oculi events.

Macros§

log
Emits a structured OculiEvent with a Borsh-serialized payload.
log_debug
Emits an OculiEvent at LogLevel::Debug.
log_error
Emits an OculiEvent at LogLevel::Error.
log_info
Emits an OculiEvent at LogLevel::Info.
log_warn
Emits an OculiEvent at LogLevel::Warn.