Skip to main content

light_sdk/instruction/
mod.rs

1//! # Overview
2//!
3//! This module provides types and utilities for building Solana instructions that work with
4//! compressed accounts. The main workflow involves:
5//! ```text
6//!  |- Client
7//!  |  |- Get ValidityProof from RPC.
8//!  |  |- pack accounts with PackedAccounts into PackedAddressTreeInfo and PackedStateTreeInfo.
9//!  |  |- pack CompressedAccountMeta.
10//!  |  |- Build Instruction from packed accounts and CompressedAccountMetas.
11//!  |  |_ Send transaction
12//!  |
13//!  |_ Custom Program
14//!     |- use PackedAddressTreeInfo to create a new address.
15//!     |- use CompressedAccountMeta to instantiate a LightAccount struct.
16//!     |
17//!     |_ Light System Program CPI
18//! ```
19//! ## Main Types
20//!
21//! - [`PackedAddressTreeInfo`](crate::instruction::PackedAddressTreeInfo) - Indices of address tree and queue accounts.
22//! - [`PackedStateTreeInfo`](crate::instruction::PackedStateTreeInfo) - Indices of state tree and queue accounts.
23//! - [`PackedAccounts`](crate::instruction::PackedAccounts) - Packs accounts and creates indices for instruction building (client-side).
24//! - [`SystemAccountMetaConfig`](crate::instruction::SystemAccountMetaConfig) - Configures which Light system program accounts to add to [`PackedAccounts`](crate::instruction::PackedAccounts).
25//! - [`ValidityProof`](crate::instruction::ValidityProof) - Proves that new addresses don't exist yet, and compressed account state exists.
26//! - [`CompressedAccountMeta`](crate::instruction::account_meta::CompressedAccountMeta) - Metadata for compressed accounts.
27//!
28//! ## Compressed Account Metas
29//! Instruction data types to pass compressed account metadata into instructions.
30//! [`CompressedAccountMeta`](crate::instruction::account_meta::CompressedAccountMeta) and variations with and without lamports and addresses are used to instantiate LightAccount structs in your program.
31//!
32//! ## Packed Structs Pattern
33//!
34//! Structs prefixed with `Packed` (eg [`PackedAddressTreeInfo`](crate::instruction::PackedAddressTreeInfo), [`PackedStateTreeInfo`](crate::instruction::PackedStateTreeInfo)) are instruction data
35//! structs that contain account **indices** instead of **pubkeys** to reduce instruction size.
36//!
37//! - `Packed*` structs: Contain indices (u8) for use in instruction data.
38//! - Non-`Packed` structs: Contain pubkeys (Pubkey) for use in the client, and are returned by RPC methods.
39//! - [`PackedAccounts`](crate::instruction::PackedAccounts): Manages account deduplication and index assignment to create `Packed*` structs.
40
41// TODO: link to examples
42
43// Re-export instruction types from sdk-types (available on all targets)
44// SDK-specific: ValidityProof and CompressedProof
45pub use light_compressed_account::instruction_data::compressed_proof::{
46    CompressedProof, ValidityProof,
47};
48pub use light_sdk_types::instruction::*;
49// Re-export pack_accounts utilities (off-chain only, requires std for HashMap)
50#[cfg(not(target_os = "solana"))]
51pub use light_sdk_types::pack_accounts::*;
52
53// SDK-specific: system account helpers (depend on find_cpi_signer_macro!)
54mod system_accounts;
55pub use system_accounts::*;
56
57// SDK-specific: tree info packing/unpacking
58mod tree_info;
59pub use tree_info::*;
60
61// Newtype wrapper around generic PackedAccounts<AccountMeta> with inherent system account methods
62#[cfg(not(target_os = "solana"))]
63mod packed_accounts;
64#[cfg(not(target_os = "solana"))]
65pub use packed_accounts::PackedAccounts;