light_token/instruction/
mod.rs

1//! High-level builders for Light Token operations.
2//!
3//!
4//! ## Account Creation
5//!
6//! - [`CreateAssociatedTokenAccount`] - Create associated Light Token account (ATA) instruction
7//! - [`CreateTokenAtaCpi`] - Create associated Light Token account (ATA) via CPI
8//! - [`CreateTokenAccount`] - Create Light Token account instruction
9//! - [`CreateTokenAccountCpi`] - Create Light Token account via CPI
10//!
11//! ## Transfers
12//!
13//! - [`TransferInterfaceCpi`] - Transfer via CPI, auto-detect source/destination account types
14//!
15//! ## Decompress
16//!
17//! - [`Decompress`] - Decompress compressed tokens to a Light Token account
18//!
19//! ## Close
20//!
21//! - [`CloseAccount`] - Create close Light Token account instruction
22//! - [`CloseAccountCpi`] - Close Light Token account via CPI
23//!
24//!
25//! ## Mint
26//!
27//! - [`CreateMint`] - Create Light Mint
28//! - [`create_mints`] - Create multiple Light Mints in a batch
29//! - [`MintTo`] - Mint tokens to Light Token accounts
30//!
31//! ## Revoke and Thaw
32//!
33//! - [`Revoke`] - Revoke delegation for a Light Token account
34//! - [`RevokeCpi`] - Revoke delegation via CPI
35//! - [`Thaw`] - Thaw a frozen Light Token account
36//! - [`ThawCpi`] - Thaw a frozen Light Token account via CPI
37//!
38//! # Example: Create Light Token Account Instruction
39//!
40//! ```rust
41//! # use solana_pubkey::Pubkey;
42//! use light_token::instruction::CreateAssociatedTokenAccount;
43//! # let payer = Pubkey::new_unique();
44//! # let owner = Pubkey::new_unique();
45//! # let mint = Pubkey::new_unique();
46//!
47//! let instruction = CreateAssociatedTokenAccount::new(payer, owner, mint)
48//!     .idempotent()
49//!     .instruction()?;
50//! # Ok::<(), solana_program_error::ProgramError>(())
51//! ```
52//!
53//! # Example: Create rent-free ATA via CPI
54//!
55//! ```rust,ignore
56//! use light_token::instruction::CreateTokenAtaCpi;
57//!
58//! CreateTokenAtaCpi {
59//!     payer: ctx.accounts.payer.to_account_info(),
60//!     owner: ctx.accounts.owner.to_account_info(),
61//!     mint: ctx.accounts.mint.to_account_info(),
62//!     ata: ctx.accounts.user_ata.to_account_info(),
63//!     bump,
64//! }
65//! .idempotent()
66//! .rent_free(
67//!     ctx.accounts.light_token_config.to_account_info(),
68//!     ctx.accounts.rent_sponsor.to_account_info(),
69//!     ctx.accounts.system_program.to_account_info(),
70//! )
71//! .invoke()?;
72//! ```
73//!
74//! # Example: Create rent-free vault via CPI (with PDA signing)
75//!
76//! ```rust,ignore
77//! use light_token::instruction::CreateTokenAccountCpi;
78//!
79//! CreateTokenAccountCpi {
80//!     payer: ctx.accounts.payer.to_account_info(),
81//!     account: ctx.accounts.vault.to_account_info(),
82//!     mint: ctx.accounts.mint.to_account_info(),
83//!     owner: ctx.accounts.vault_authority.key(),
84//! }
85//! .rent_free(
86//!     ctx.accounts.light_token_config.to_account_info(),
87//!     ctx.accounts.rent_sponsor.to_account_info(),
88//!     ctx.accounts.system_program.to_account_info(),
89//!     &crate::ID,
90//! )
91//! .invoke_signed(&[b"vault", mint.key().as_ref(), &[bump]])?;
92//! ```
93//!
94
95mod approve;
96mod approve_checked;
97mod burn;
98mod burn_checked;
99mod close;
100mod compressible;
101mod create;
102mod create_ata;
103mod create_mint;
104mod create_mints;
105mod decompress;
106mod decompress_mint;
107mod freeze;
108mod mint_to;
109mod mint_to_checked;
110mod revoke;
111mod thaw;
112mod transfer;
113mod transfer_checked;
114mod transfer_from_spl;
115mod transfer_interface;
116mod transfer_to_spl;
117
118pub use approve::*;
119pub use approve_checked::*;
120pub use burn::*;
121pub use burn_checked::*;
122pub use close::{CloseAccount, CloseAccountCpi};
123pub use compressible::{CompressibleParams, CompressibleParamsCpi};
124pub use create::*;
125pub use create_ata::{
126    derive_associated_token_account, derive_associated_token_account as derive_token_ata,
127    CreateAssociatedTokenAccount, CreateTokenAtaCpi as CreateAssociatedAccountCpi,
128    CreateTokenAtaCpi,
129};
130pub use create_mint::*;
131pub use create_mints::*;
132pub use decompress::Decompress;
133pub use decompress_mint::*;
134pub use freeze::*;
135use light_compressible::config::CompressibleConfig;
136pub use light_token_interface::{
137    instructions::{
138        extensions::{CompressToPubkey, ExtensionInstructionData, TokenMetadataInstructionData},
139        mint_action::MintWithContext,
140    },
141    state::{AdditionalMetadata, Token, TokenDataVersion},
142};
143use light_token_types::POOL_SEED;
144pub use mint_to::{MintTo, MintToCpi};
145pub use mint_to_checked::*;
146pub use revoke::{Revoke, RevokeCpi};
147use solana_account_info::AccountInfo;
148use solana_pubkey::{pubkey, Pubkey};
149pub use thaw::{Thaw, ThawCpi};
150pub use transfer::*;
151pub use transfer_checked::*;
152pub use transfer_from_spl::{TransferFromSpl, TransferFromSplCpi};
153pub use transfer_interface::{
154    SplInterface, SplInterfaceCpi, TransferInterface, TransferInterfaceCpi,
155};
156pub use transfer_to_spl::{TransferToSpl, TransferToSplCpi};
157
158/// System accounts required for CPI operations to Light Protocol.
159///
160/// Pass these accounts when invoking compressed token operations from your program.
161///
162/// # Fields
163///
164/// - `light_system_program` - Light System Program
165/// - `cpi_authority_pda` - CPI authority (signs for your program)
166/// - `registered_program_pda` - Your program's registration
167/// - `account_compression_authority` - Compression authority
168/// - `account_compression_program` - Account Compression Program
169/// - `system_program` - Solana System Program
170#[derive(Clone)]
171pub struct SystemAccountInfos<'info> {
172    pub light_system_program: AccountInfo<'info>,
173    pub cpi_authority_pda: AccountInfo<'info>,
174    pub registered_program_pda: AccountInfo<'info>,
175    pub account_compression_authority: AccountInfo<'info>,
176    pub account_compression_program: AccountInfo<'info>,
177    pub system_program: AccountInfo<'info>,
178}
179
180/// System accounts with Pubkey references for instruction building.
181///
182/// ```rust
183/// # use light_token::instruction::SystemAccounts;
184/// # use solana_instruction::AccountMeta;
185/// let system_accounts = SystemAccounts::default();
186/// let accounts = vec![
187///     AccountMeta::new_readonly(system_accounts.light_system_program, false),
188///     AccountMeta::new_readonly(system_accounts.cpi_authority_pda, false),
189///     // ...
190/// ];
191/// ```
192#[derive(Debug, Clone, Copy)]
193pub struct SystemAccounts {
194    pub light_system_program: Pubkey,
195    pub cpi_authority_pda: Pubkey,
196    pub registered_program_pda: Pubkey,
197    pub account_compression_authority: Pubkey,
198    pub account_compression_program: Pubkey,
199    pub system_program: Pubkey,
200}
201
202impl Default for SystemAccounts {
203    fn default() -> Self {
204        use crate::utils::TokenDefaultAccounts;
205        let defaults = TokenDefaultAccounts::default();
206        Self {
207            light_system_program: defaults.light_system_program,
208            cpi_authority_pda: defaults.cpi_authority_pda,
209            registered_program_pda: defaults.registered_program_pda,
210            account_compression_authority: defaults.account_compression_authority,
211            account_compression_program: defaults.account_compression_program,
212            system_program: defaults.system_program,
213        }
214    }
215}
216
217/// Compressed Token Program ID: `cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m`
218pub const LIGHT_TOKEN_PROGRAM_ID: Pubkey = pubkey!("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m");
219
220pub const LIGHT_TOKEN_CPI_AUTHORITY: Pubkey =
221    pubkey!("GXtd2izAiMJPwMEjfgTRH3d7k9mjn4Jq3JrWFv9gySYy");
222
223pub const COMPRESSIBLE_CONFIG_V1: Pubkey = pubkey!("ACXg8a7VaqecBWrSbdu73W4Pg9gsqXJ3EXAqkHyhvVXg");
224
225pub const RENT_SPONSOR: Pubkey = pubkey!("r18WwUxfG8kQ69bQPAB2jV6zGNKy3GosFGctjQoV4ti");
226
227/// Returns the program ID for the Compressed Token Program
228pub fn id() -> Pubkey {
229    LIGHT_TOKEN_PROGRAM_ID
230}
231
232/// Return the cpi authority pda of the Compressed Token Program.
233pub fn cpi_authority() -> Pubkey {
234    LIGHT_TOKEN_CPI_AUTHORITY
235}
236
237pub fn get_spl_interface_pda_and_bump(mint: &Pubkey) -> (Pubkey, u8) {
238    Pubkey::find_program_address(&[POOL_SEED, mint.as_ref()], &LIGHT_TOKEN_PROGRAM_ID)
239}
240
241/// Returns the associated token address for a given owner and mint.
242pub fn get_associated_token_address(owner: &Pubkey, mint: &Pubkey) -> Pubkey {
243    get_associated_token_address_and_bump(owner, mint).0
244}
245
246/// Returns the associated token address and bump for a given owner and mint.
247pub fn get_associated_token_address_and_bump(owner: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) {
248    Pubkey::find_program_address(
249        &[&owner.to_bytes(), &id().to_bytes(), &mint.to_bytes()],
250        &id(),
251    )
252}
253
254/// Returns the default compressible config PDA.
255pub fn config_pda() -> Pubkey {
256    COMPRESSIBLE_CONFIG_V1
257}
258
259/// Returns the default rent sponsor PDA.
260pub fn rent_sponsor_pda() -> Pubkey {
261    RENT_SPONSOR
262}
263
264pub fn compression_authority_pda() -> Pubkey {
265    CompressibleConfig::light_token_v1_compression_authority_pda()
266}