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//! ├─ 𝐂𝐥𝐢𝐞𝐧𝐭
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//! └─ 𝐂𝐮𝐬𝐭𝐨𝐦 𝐏𝐫𝐨𝐠𝐫𝐚𝐦
14//! ├─ use PackedAddressTreeInfo to create a new address.
15//! ├─ use CompressedAccountMeta to instantiate a LightAccount struct.
16//! │
17//! └─ 𝐋𝐢𝐠𝐡𝐭 𝐒𝐲𝐬𝐭𝐞𝐦 𝐏𝐫𝐨𝐠𝐫𝐚𝐦 𝐂𝐏𝐈
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
43mod pack_accounts;
44mod system_accounts;
45mod tree_info;
46
47/// Zero-knowledge proof to prove the validity of existing compressed accounts and new addresses.
48pub use light_compressed_account::instruction_data::compressed_proof::{
49 CompressedProof, ValidityProof,
50};
51pub use light_sdk_types::instruction::*;
52pub use pack_accounts::*;
53pub use system_accounts::*;
54pub use tree_info::*;