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//! ├─ Verify ValidityProof.
19//! ├─ Update State Merkle tree.
20//! ├─ Update Address Merkle tree.
21//! └─ Complete atomic state transition.
22//! ```
23//! ## Main Types
24//!
25//! - [`PackedAddressTreeInfo`](crate::instruction::PackedAddressTreeInfo) - Indices of address tree and queue accounts.
26//! - [`PackedStateTreeInfo`](crate::instruction::PackedStateTreeInfo) - Indices of state tree and queue accounts.
27//! - [`PackedAccounts`](crate::instruction::PackedAccounts) - Packs accounts and creates indices for instruction building (client-side).
28//! - [`SystemAccountMetaConfig`](crate::instruction::SystemAccountMetaConfig) - Configures which Light system program accounts to add to [`PackedAccounts`](crate::instruction::PackedAccounts).
29//! - [`ValidityProof`](crate::instruction::ValidityProof) - Proves that new addresses don't exist yet, and compressed account state exists.
30//! - [`CompressedAccountMeta`](crate::instruction::account_meta::CompressedAccountMeta) - Metadata for compressed accounts.
31//!
32//! ## Compressed Account Metas
33//! Instruction data types to pass compressed account metadata into instructions.
34//! [`CompressedAccountMeta`](crate::instruction::account_meta::CompressedAccountMeta) and variations with and without lamports and addresses are used to instantiate LightAccount structs in your program.
35//!
36//! ## Packed Structs Pattern
37//!
38//! Structs prefixed with `Packed` (eg [`PackedAddressTreeInfo`](crate::instruction::PackedAddressTreeInfo), [`PackedStateTreeInfo`](crate::instruction::PackedStateTreeInfo)) are instruction data
39//! structs that contain account **indices** instead of **pubkeys** to reduce instruction size.
40//!
41//! - `Packed*` structs: Contain indices (u8) for use in instruction data.
42//! - Non-`Packed` structs: Contain pubkeys (Pubkey) for use in the client, and are returned by RPC methods.
43//! - [`PackedAccounts`](crate::instruction::PackedAccounts): Manages account deduplication and index assignment to create `Packed*` structs.
44
45// TODO: link to examples
46
47mod pack_accounts;
48mod system_accounts;
49mod tree_info;
50
51/// Zero-knowledge proof to prove the validity of existing compressed accounts and new addresses.
52pub use light_compressed_account::instruction_data::compressed_proof::{
53 CompressedProof, ValidityProof,
54};
55pub use light_sdk_types::instruction::*;
56pub use pack_accounts::*;
57pub use system_accounts::*;
58pub use tree_info::*;