diff --git a/.github/workflows/sdk-tests.yml b/.github/workflows/sdk-tests.yml index b7f0cf854a..6c9d672f1b 100644 --- a/.github/workflows/sdk-tests.yml +++ b/.github/workflows/sdk-tests.yml @@ -64,7 +64,7 @@ jobs: cargo test -p light-client cargo test -p light-sparse-merkle-tree cargo test -p light-compressed-token-types - cargo test -p light-ctoken-sdk + cargo test -p light-ctoken-sdk --all-features steps: - name: Checkout sources uses: actions/checkout@v4 diff --git a/Cargo.lock b/Cargo.lock index c07fbe7b7a..efdb049dff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2407,6 +2407,7 @@ dependencies = [ "light-client", "light-compressed-account", "light-concurrent-merkle-tree", + "light-ctoken-interface", "light-hash-set", "light-hasher", "light-indexed-merkle-tree", @@ -2419,6 +2420,8 @@ dependencies = [ "num-traits", "serde", "serde_json", + "solana-instruction", + "solana-pubkey 2.4.0", "solana-sdk", "thiserror 2.0.17", "tokio", diff --git a/forester-utils/Cargo.toml b/forester-utils/Cargo.toml index 5c697284f8..5bbea231f9 100644 --- a/forester-utils/Cargo.toml +++ b/forester-utils/Cargo.toml @@ -30,6 +30,10 @@ light-client = { workspace = true } light-prover-client = { workspace = true } light-registry = { workspace = true, features = ["cpi"] } account-compression = { workspace = true, features = ["cpi"] } +light-ctoken-interface = { workspace = true } + +solana-instruction = { workspace = true } +solana-pubkey = { workspace = true } tokio = { workspace = true } futures = { workspace = true } diff --git a/sdk-libs/ctoken-sdk/src/compressible/claim.rs b/forester-utils/src/instructions/claim.rs similarity index 100% rename from sdk-libs/ctoken-sdk/src/compressible/claim.rs rename to forester-utils/src/instructions/claim.rs diff --git a/forester-utils/src/instructions/mod.rs b/forester-utils/src/instructions/mod.rs index b8d5dd6f2f..8c70c1ca69 100644 --- a/forester-utils/src/instructions/mod.rs +++ b/forester-utils/src/instructions/mod.rs @@ -2,3 +2,6 @@ pub mod address_batch_update; pub mod create_account; pub use create_account::create_account_instruction; + +pub mod claim; +pub mod withdraw_funding_pool; diff --git a/sdk-libs/ctoken-sdk/src/compressible/withdraw_funding_pool.rs b/forester-utils/src/instructions/withdraw_funding_pool.rs similarity index 100% rename from sdk-libs/ctoken-sdk/src/compressible/withdraw_funding_pool.rs rename to forester-utils/src/instructions/withdraw_funding_pool.rs diff --git a/program-tests/compressed-token-test/tests/transfer2/compress_spl_failing.rs b/program-tests/compressed-token-test/tests/transfer2/compress_spl_failing.rs index 27dfa84988..c8f6b8203f 100644 --- a/program-tests/compressed-token-test/tests/transfer2/compress_spl_failing.rs +++ b/program-tests/compressed-token-test/tests/transfer2/compress_spl_failing.rs @@ -38,7 +38,7 @@ use light_ctoken_sdk::{ CTokenAccount2, }, ctoken::{derive_ctoken_ata, CreateAssociatedTokenAccount}, - token_pool::find_token_pool_pda_with_index, + spl_interface::find_spl_interface_pda_with_index, ValidityProof, }; use light_program_test::{utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig}; @@ -190,10 +190,10 @@ fn create_spl_compression_inputs( // Add SPL token program (spl_token::ID is the owner of SPL token accounts) let _token_program_index = packed_tree_accounts.insert_or_get_read_only(spl_token::ID); - // Derive token pool PDA using SDK function + // Derive SPL interface PDA using SDK function let pool_index = 0u8; - let (token_pool_pda, bump) = find_token_pool_pda_with_index(&mint, pool_index); - let pool_account_index = packed_tree_accounts.insert_or_get(token_pool_pda); + let (spl_interface_pda, bump) = find_spl_interface_pda_with_index(&mint, pool_index); + let pool_account_index = packed_tree_accounts.insert_or_get(spl_interface_pda); // Compress from SPL token account token_account @@ -454,7 +454,7 @@ async fn test_spl_compression_invalid_pool_bump() -> Result<(), RpcError> { // Derive pool with correct seed but wrong bump let pool_index = 0u8; - let (_, correct_bump) = find_token_pool_pda_with_index(&mint, pool_index); + let (_, correct_bump) = find_spl_interface_pda_with_index(&mint, pool_index); // Modify the bump in the compression data to an incorrect value if let Some(compression) = &mut compression_inputs.token_accounts[0].compression { @@ -489,7 +489,7 @@ async fn test_spl_compression_invalid_pool_index() -> Result<(), RpcError> { // Derive pool with index 1 instead of 0 let wrong_pool_index = 1u8; - let (wrong_pool_pda, wrong_bump) = find_token_pool_pda_with_index(&mint, wrong_pool_index); + let (wrong_pool_pda, wrong_bump) = find_spl_interface_pda_with_index(&mint, wrong_pool_index); // Update the compression data with wrong pool index if let Some(compression) = &mut compression_inputs.token_accounts[0].compression { diff --git a/program-tests/compressed-token-test/tests/transfer2/spl_ctoken.rs b/program-tests/compressed-token-test/tests/transfer2/spl_ctoken.rs index 1b026f41db..7382e31b20 100644 --- a/program-tests/compressed-token-test/tests/transfer2/spl_ctoken.rs +++ b/program-tests/compressed-token-test/tests/transfer2/spl_ctoken.rs @@ -11,7 +11,7 @@ use light_ctoken_sdk::{ }, CTokenAccount2, }, - token_pool::find_token_pool_pda_with_index, + spl_interface::find_spl_interface_pda_with_index, ValidityProof, }; use light_program_test::utils::assert::assert_rpc_error; @@ -289,7 +289,7 @@ async fn test_failing_ctoken_to_spl_with_compress_and_close() { // Now transfer back using CompressAndClose instead of regular transfer println!("Testing reverse transfer with CompressAndClose: ctoken to SPL"); - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let transfer_ix = CtokenToSplTransferAndClose { source_ctoken_account: associated_token_account, @@ -298,8 +298,8 @@ async fn test_failing_ctoken_to_spl_with_compress_and_close() { authority: recipient.pubkey(), mint, payer: payer.pubkey(), - token_pool_pda, - token_pool_pda_bump, + spl_interface_pda, + spl_interface_pda_bump, spl_token_program: anchor_spl::token::ID, } .instruction() @@ -319,8 +319,8 @@ pub struct CtokenToSplTransferAndClose { pub authority: Pubkey, pub mint: Pubkey, pub payer: Pubkey, - pub token_pool_pda: Pubkey, - pub token_pool_pda_bump: u8, + pub spl_interface_pda: Pubkey, + pub spl_interface_pda_bump: u8, pub spl_token_program: Pubkey, } @@ -335,8 +335,8 @@ impl CtokenToSplTransferAndClose { AccountMeta::new(self.destination_spl_token_account, false), // Authority (index 3) - signer AccountMeta::new(self.authority, true), - // Token pool PDA (index 4) - writable - AccountMeta::new(self.token_pool_pda, false), + // SPL interface PDA (index 4) - writable + AccountMeta::new(self.spl_interface_pda, false), // SPL Token program (index 5) - needed for CPI AccountMeta::new_readonly(self.spl_token_program, false), ]; @@ -368,7 +368,7 @@ impl CtokenToSplTransferAndClose { 2, // destination SPL token account index 4, // pool_account_index 0, // pool_index (TODO: make dynamic) - self.token_pool_pda_bump, + self.spl_interface_pda_bump, )), delegate_is_set: false, method_used: true, diff --git a/sdk-libs/ctoken-sdk/Cargo.toml b/sdk-libs/ctoken-sdk/Cargo.toml index 194bea0b0f..a8406ff567 100644 --- a/sdk-libs/ctoken-sdk/Cargo.toml +++ b/sdk-libs/ctoken-sdk/Cargo.toml @@ -4,6 +4,9 @@ version = "0.1.0" edition = { workspace = true } [features] +default = [] +v1 = [] +compressible = [] anchor = ["anchor-lang", "light-compressed-token-types/anchor", "light-ctoken-interface/anchor"] cpi-context = ["light-sdk/cpi-context"] diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/mod.rs b/sdk-libs/ctoken-sdk/src/compressed_token/mod.rs index eb8943d216..4594ff3387 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/mod.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/mod.rs @@ -1,8 +1,11 @@ +//! Compressed token account types and instruction builders. + +#[cfg(feature = "v1")] mod v1; mod v2; pub mod ctoken_instruction; -// Re-export everything from v1 and v2 +#[cfg(feature = "v1")] pub use v1::*; pub use v2::*; diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_to_compressed/instruction.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_to_compressed/instruction.rs index f4e536ff5c..47f7d20bc5 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_to_compressed/instruction.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_to_compressed/instruction.rs @@ -10,7 +10,7 @@ use solana_pubkey::Pubkey; use crate::{ compressed_token::mint_action::MintActionMetaConfig, error::{Result, TokenSdkError}, - TokenPool, + spl_interface::SplInterfacePda, }; pub const MINT_TO_COMPRESSED_DISCRIMINATOR: u8 = 101; @@ -32,7 +32,7 @@ pub struct MintToCompressedInputs { pub token_account_version: u8, pub cpi_context_pubkey: Option, /// Required if the mint is decompressed - pub token_pool: Option, + pub spl_interface_pda: Option, } /// Create a mint_to_compressed instruction (wrapper around mint_action) @@ -53,7 +53,7 @@ pub fn create_mint_to_compressed_instruction( proof, token_account_version, cpi_context_pubkey, - token_pool: _, + spl_interface_pda: _, } = inputs; let mint_to_action = diff --git a/sdk-libs/ctoken-sdk/src/compressible/mod.rs b/sdk-libs/ctoken-sdk/src/compressible/mod.rs index 417af90c44..77e5b67aae 100644 --- a/sdk-libs/ctoken-sdk/src/compressible/mod.rs +++ b/sdk-libs/ctoken-sdk/src/compressible/mod.rs @@ -1,7 +1,7 @@ -pub mod claim; +//! Compressible token utilities for runtime decompression. + +#[cfg(feature = "compressible")] pub mod decompress_runtime; -pub mod withdraw_funding_pool; -pub use claim::*; +#[cfg(feature = "compressible")] pub use decompress_runtime::{process_decompress_tokens_runtime, CTokenSeedProvider}; -pub use withdraw_funding_pool::*; diff --git a/sdk-libs/ctoken-sdk/src/ctoken/mod.rs b/sdk-libs/ctoken-sdk/src/ctoken/mod.rs index 16b59e63c4..f2d360b794 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/mod.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/mod.rs @@ -1,3 +1,8 @@ +//! High-level builders for compressed token operations. +//! +//! Provides instruction builders and CPI helpers for creating, transferring, +//! and managing compressed token accounts. + mod close; mod compressible; mod create; diff --git a/sdk-libs/ctoken-sdk/src/ctoken/transfer_ctoken_spl.rs b/sdk-libs/ctoken-sdk/src/ctoken/transfer_ctoken_spl.rs index 71179e53a9..5831c0939e 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/transfer_ctoken_spl.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/transfer_ctoken_spl.rs @@ -21,8 +21,8 @@ pub struct TransferCtokenToSpl { pub authority: Pubkey, pub mint: Pubkey, pub payer: Pubkey, - pub token_pool_pda: Pubkey, - pub token_pool_pda_bump: u8, + pub spl_interface_pda: Pubkey, + pub spl_interface_pda_bump: u8, pub spl_token_program: Pubkey, } @@ -33,8 +33,8 @@ pub struct TransferCtokenToSplAccountInfos<'info> { pub authority: AccountInfo<'info>, pub mint: AccountInfo<'info>, pub payer: AccountInfo<'info>, - pub token_pool_pda: AccountInfo<'info>, - pub token_pool_pda_bump: u8, + pub spl_interface_pda: AccountInfo<'info>, + pub spl_interface_pda_bump: u8, pub spl_token_program: AccountInfo<'info>, pub compressed_token_program_authority: AccountInfo<'info>, } @@ -54,7 +54,7 @@ impl<'info> TransferCtokenToSplAccountInfos<'info> { self.source_ctoken_account, // Index 1: Source ctoken account self.destination_spl_token_account, // Index 2: Destination SPL token account self.authority, // Index 3: Authority (signer) - self.token_pool_pda, // Index 4: Token pool PDA + self.spl_interface_pda, // Index 4: SPL interface PDA self.spl_token_program, // Index 5: SPL Token program ]; invoke(&instruction, &account_infos) @@ -70,7 +70,7 @@ impl<'info> TransferCtokenToSplAccountInfos<'info> { self.source_ctoken_account, // Index 1: Source ctoken account self.destination_spl_token_account, // Index 2: Destination SPL token account self.authority, // Index 3: Authority (signer) - self.token_pool_pda, // Index 4: Token pool PDA + self.spl_interface_pda, // Index 4: SPL interface PDA self.spl_token_program, // Index 5: SPL Token program ]; invoke_signed(&instruction, &account_infos, signer_seeds) @@ -86,8 +86,8 @@ impl<'info> From<&TransferCtokenToSplAccountInfos<'info>> for TransferCtokenToSp authority: *account_infos.authority.key, mint: *account_infos.mint.key, payer: *account_infos.payer.key, - token_pool_pda: *account_infos.token_pool_pda.key, - token_pool_pda_bump: account_infos.token_pool_pda_bump, + spl_interface_pda: *account_infos.spl_interface_pda.key, + spl_interface_pda_bump: account_infos.spl_interface_pda_bump, spl_token_program: *account_infos.spl_token_program.key, } } @@ -105,8 +105,8 @@ impl TransferCtokenToSpl { AccountMeta::new(self.destination_spl_token_account, false), // Authority (index 3) - signer AccountMeta::new_readonly(self.authority, true), - // Token pool PDA (index 4) - writable - AccountMeta::new(self.token_pool_pda, false), + // SPL interface PDA (index 4) - writable + AccountMeta::new(self.spl_interface_pda, false), // SPL Token program (index 5) - needed for CPI AccountMeta::new_readonly(self.spl_token_program, false), ]; @@ -135,7 +135,7 @@ impl TransferCtokenToSpl { 2, // destination SPL token account index 4, // pool_account_index 0, // pool_index (TODO: make dynamic) - self.token_pool_pda_bump, + self.spl_interface_pda_bump, )), delegate_is_set: false, method_used: true, diff --git a/sdk-libs/ctoken-sdk/src/ctoken/transfer_interface.rs b/sdk-libs/ctoken-sdk/src/ctoken/transfer_interface.rs index bd63682da5..44af3a0f46 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/transfer_interface.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/transfer_interface.rs @@ -12,8 +12,8 @@ use crate::{error::TokenSdkError, utils::is_ctoken_account}; pub struct SplInterface<'info> { pub mint: AccountInfo<'info>, pub spl_token_program: AccountInfo<'info>, - pub token_pool_pda: AccountInfo<'info>, - pub token_pool_pda_bump: u8, + pub spl_interface_pda: AccountInfo<'info>, + pub spl_interface_pda_bump: u8, } pub struct TransferInterface<'info> { @@ -56,14 +56,14 @@ impl<'info> TransferInterface<'info> { /// # Arguments /// * `mint` - Optional mint account (required for SPL<->ctoken transfers) /// * `spl_token_program` - Optional SPL token program (required for SPL<->ctoken transfers) - /// * `compressed_token_pool_pda` - Optional token pool PDA (required for SPL<->ctoken transfers) - /// * `compressed_token_pool_pda_bump` - Optional bump seed for token pool PDA + /// * `spl_interface_pda` - Optional SPL interface PDA (required for SPL<->ctoken transfers) + /// * `spl_interface_pda_bump` - Optional bump seed for SPL interface PDA pub fn with_spl_interface( mut self, mint: Option>, spl_token_program: Option>, - token_pool_pda: Option>, - token_pool_pda_bump: Option, + spl_interface_pda: Option>, + spl_interface_pda_bump: Option, ) -> Result { let mint = mint.ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingMintAccount.into()))?; @@ -71,17 +71,17 @@ impl<'info> TransferInterface<'info> { let spl_token_program = spl_token_program .ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingSplTokenProgram.into()))?; - let token_pool_pda = token_pool_pda + let spl_interface_pda = spl_interface_pda .ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingTokenPoolPda.into()))?; - let token_pool_pda_bump = token_pool_pda_bump + let spl_interface_pda_bump = spl_interface_pda_bump .ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingTokenPoolPdaBump.into()))?; self.spl_interface = Some(SplInterface { mint, spl_token_program, - token_pool_pda, - token_pool_pda_bump, + spl_interface_pda, + spl_interface_pda_bump, }); Ok(self) } @@ -118,8 +118,8 @@ impl<'info> TransferInterface<'info> { authority: self.authority.clone(), mint: config.mint.clone(), payer: self.payer.clone(), - token_pool_pda: config.token_pool_pda.clone(), - token_pool_pda_bump: config.token_pool_pda_bump, + spl_interface_pda: config.spl_interface_pda.clone(), + spl_interface_pda_bump: config.spl_interface_pda_bump, spl_token_program: config.spl_token_program.clone(), compressed_token_program_authority: self .compressed_token_program_authority @@ -140,8 +140,8 @@ impl<'info> TransferInterface<'info> { authority: self.authority.clone(), mint: config.mint.clone(), payer: self.payer.clone(), - token_pool_pda: config.token_pool_pda.clone(), - token_pool_pda_bump: config.token_pool_pda_bump, + spl_interface_pda: config.spl_interface_pda.clone(), + spl_interface_pda_bump: config.spl_interface_pda_bump, spl_token_program: config.spl_token_program.clone(), compressed_token_program_authority: self .compressed_token_program_authority @@ -188,8 +188,8 @@ impl<'info> TransferInterface<'info> { authority: self.authority.clone(), mint: config.mint.clone(), payer: self.payer.clone(), - token_pool_pda: config.token_pool_pda.clone(), - token_pool_pda_bump: config.token_pool_pda_bump, + spl_interface_pda: config.spl_interface_pda.clone(), + spl_interface_pda_bump: config.spl_interface_pda_bump, spl_token_program: config.spl_token_program.clone(), compressed_token_program_authority: self .compressed_token_program_authority @@ -210,8 +210,8 @@ impl<'info> TransferInterface<'info> { authority: self.authority.clone(), mint: config.mint.clone(), payer: self.payer.clone(), - token_pool_pda: config.token_pool_pda.clone(), - token_pool_pda_bump: config.token_pool_pda_bump, + spl_interface_pda: config.spl_interface_pda.clone(), + spl_interface_pda_bump: config.spl_interface_pda_bump, spl_token_program: config.spl_token_program.clone(), compressed_token_program_authority: self .compressed_token_program_authority diff --git a/sdk-libs/ctoken-sdk/src/ctoken/transfer_spl_ctoken.rs b/sdk-libs/ctoken-sdk/src/ctoken/transfer_spl_ctoken.rs index b579a3d917..bef7c232e0 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/transfer_spl_ctoken.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/transfer_spl_ctoken.rs @@ -15,27 +15,27 @@ use crate::compressed_token::{ pub struct TransferSplToCtoken { pub amount: u64, - pub token_pool_pda_bump: u8, + pub spl_interface_pda_bump: u8, pub source_spl_token_account: Pubkey, /// Destination ctoken account (writable) pub destination_ctoken_account: Pubkey, pub authority: Pubkey, pub mint: Pubkey, pub payer: Pubkey, - pub token_pool_pda: Pubkey, + pub spl_interface_pda: Pubkey, pub spl_token_program: Pubkey, } pub struct TransferSplToCtokenAccountInfos<'info> { pub amount: u64, - pub token_pool_pda_bump: u8, + pub spl_interface_pda_bump: u8, pub source_spl_token_account: AccountInfo<'info>, /// Destination ctoken account (writable) pub destination_ctoken_account: AccountInfo<'info>, pub authority: AccountInfo<'info>, pub mint: AccountInfo<'info>, pub payer: AccountInfo<'info>, - pub token_pool_pda: AccountInfo<'info>, + pub spl_interface_pda: AccountInfo<'info>, pub spl_token_program: AccountInfo<'info>, pub compressed_token_program_authority: AccountInfo<'info>, } @@ -55,7 +55,7 @@ impl<'info> TransferSplToCtokenAccountInfos<'info> { self.destination_ctoken_account, // Index 1: Destination ctoken account self.authority, // Index 2: Authority (signer) self.source_spl_token_account, // Index 3: Source SPL token account - self.token_pool_pda, // Index 4: Token pool PDA + self.spl_interface_pda, // Index 4: SPL interface PDA self.spl_token_program, // Index 5: SPL Token program ]; invoke(&instruction, &account_infos) @@ -71,7 +71,7 @@ impl<'info> TransferSplToCtokenAccountInfos<'info> { self.destination_ctoken_account, // Index 1: Destination ctoken account self.authority, // Index 2: Authority (signer) self.source_spl_token_account, // Index 3: Source SPL token account - self.token_pool_pda, // Index 4: Token pool PDA + self.spl_interface_pda, // Index 4: SPL interface PDA self.spl_token_program, // Index 5: SPL Token program ]; invoke_signed(&instruction, &account_infos, signer_seeds) @@ -87,8 +87,8 @@ impl<'info> From<&TransferSplToCtokenAccountInfos<'info>> for TransferSplToCtoke authority: *account_infos.authority.key, mint: *account_infos.mint.key, payer: *account_infos.payer.key, - token_pool_pda: *account_infos.token_pool_pda.key, - token_pool_pda_bump: account_infos.token_pool_pda_bump, + spl_interface_pda: *account_infos.spl_interface_pda.key, + spl_interface_pda_bump: account_infos.spl_interface_pda_bump, spl_token_program: *account_infos.spl_token_program.key, } } @@ -105,8 +105,8 @@ impl TransferSplToCtoken { AccountMeta::new_readonly(self.authority, true), // Source SPL token account (index 3) - writable AccountMeta::new(self.source_spl_token_account, false), - // Token pool PDA (index 4) - writable - AccountMeta::new(self.token_pool_pda, false), + // SPL interface PDA (index 4) - writable + AccountMeta::new(self.spl_interface_pda, false), // SPL Token program (index 5) - needed for CPI AccountMeta::new_readonly(self.spl_token_program, false), ]; @@ -121,7 +121,7 @@ impl TransferSplToCtoken { 2, // authority 4, // pool_account_index: 0, // pool_index - self.token_pool_pda_bump, + self.spl_interface_pda_bump, )), delegate_is_set: false, method_used: true, diff --git a/sdk-libs/ctoken-sdk/src/error.rs b/sdk-libs/ctoken-sdk/src/error.rs index bb1b260987..f180c10fb0 100644 --- a/sdk-libs/ctoken-sdk/src/error.rs +++ b/sdk-libs/ctoken-sdk/src/error.rs @@ -1,3 +1,5 @@ +//! Error types for compressed token operations. + use light_account_checks::AccountError; use light_compressed_token_types::error::LightTokenSdkTypeError; use light_ctoken_interface::CTokenError; diff --git a/sdk-libs/ctoken-sdk/src/lib.rs b/sdk-libs/ctoken-sdk/src/lib.rs index 2044a9c34f..7e27b9849f 100644 --- a/sdk-libs/ctoken-sdk/src/lib.rs +++ b/sdk-libs/ctoken-sdk/src/lib.rs @@ -1,10 +1,14 @@ +//! SDK for compressed token operations on Light Protocol. +//! +//! Provides builders and utilities for creating, transferring, and managing compressed tokens. + pub mod compressed_token; pub mod compressible; pub mod ctoken; pub mod error; pub mod pack; -pub mod token_pool; +pub mod spl_interface; pub mod utils; // Conditional anchor re-exports @@ -12,11 +16,13 @@ pub mod utils; use anchor_lang::{AnchorDeserialize, AnchorSerialize}; #[cfg(not(feature = "anchor"))] use borsh::{BorshDeserialize as AnchorDeserialize, BorshSerialize as AnchorSerialize}; +#[cfg(feature = "compressible")] pub use compressible::decompress_runtime::{process_decompress_tokens_runtime, CTokenSeedProvider}; pub use light_compressed_account::instruction_data::compressed_proof::CompressedProof; pub use light_compressed_token_types::*; -pub use pack::{compat, Pack, Unpack}; -pub use token_pool::TokenPool; +pub use pack::compat; +#[cfg(feature = "compressible")] +pub use pack::{Pack, Unpack}; pub use utils::{ account_meta_from_account_info, is_ctoken_account, AccountInfoToCompress, PackedCompressedTokenDataWithContext, diff --git a/sdk-libs/ctoken-sdk/src/spl_interface.rs b/sdk-libs/ctoken-sdk/src/spl_interface.rs new file mode 100644 index 0000000000..b73392fdbd --- /dev/null +++ b/sdk-libs/ctoken-sdk/src/spl_interface.rs @@ -0,0 +1,45 @@ +//! SPL interface PDA derivation utilities. + +use light_compressed_token_types::constants::POOL_SEED; +use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use solana_pubkey::Pubkey; + +use crate::{AnchorDeserialize, AnchorSerialize}; + +#[derive(Debug, Clone, AnchorDeserialize, AnchorSerialize, PartialEq)] +pub struct SplInterfacePda { + pub pubkey: Pubkey, + pub bump: u8, + pub index: u8, +} + +/// Derive the spl interface pda for a given mint +pub fn get_spl_interface_pda(mint: &Pubkey) -> Pubkey { + get_spl_interface_pda_with_index(mint, 0) +} + +/// Find the spl interface pda for a given mint and index +pub fn find_spl_interface_pda_with_index(mint: &Pubkey, spl_interface_index: u8) -> (Pubkey, u8) { + let seeds = &[POOL_SEED, mint.as_ref(), &[spl_interface_index]]; + let seeds = if spl_interface_index == 0 { + &seeds[..2] + } else { + &seeds[..] + }; + Pubkey::find_program_address(seeds, &Pubkey::from(COMPRESSED_TOKEN_PROGRAM_ID)) +} + +/// Get the spl interface pda for a given mint and index +pub fn get_spl_interface_pda_with_index(mint: &Pubkey, spl_interface_index: u8) -> Pubkey { + find_spl_interface_pda_with_index(mint, spl_interface_index).0 +} + +/// Derive spl interface pda information for a given mint +pub fn derive_spl_interface_pda(mint: &solana_pubkey::Pubkey, index: u8) -> SplInterfacePda { + let (pubkey, bump) = find_spl_interface_pda_with_index(mint, index); + SplInterfacePda { + pubkey, + bump, + index, + } +} diff --git a/sdk-libs/ctoken-sdk/src/token_pool.rs b/sdk-libs/ctoken-sdk/src/token_pool.rs deleted file mode 100644 index 062bf409b4..0000000000 --- a/sdk-libs/ctoken-sdk/src/token_pool.rs +++ /dev/null @@ -1,43 +0,0 @@ -use light_compressed_token_types::constants::POOL_SEED; -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; -use solana_pubkey::Pubkey; - -use crate::{AnchorDeserialize, AnchorSerialize}; - -#[derive(Debug, Clone, AnchorDeserialize, AnchorSerialize, PartialEq)] -pub struct TokenPool { - pub pubkey: Pubkey, - pub bump: u8, - pub index: u8, -} - -/// Derive the token pool pda for a given mint -pub fn get_token_pool_pda(mint: &Pubkey) -> Pubkey { - get_token_pool_pda_with_index(mint, 0) -} - -/// Find the token pool pda for a given mint and index -pub fn find_token_pool_pda_with_index(mint: &Pubkey, token_pool_index: u8) -> (Pubkey, u8) { - let seeds = &[POOL_SEED, mint.as_ref(), &[token_pool_index]]; - let seeds = if token_pool_index == 0 { - &seeds[..2] - } else { - &seeds[..] - }; - Pubkey::find_program_address(seeds, &Pubkey::from(COMPRESSED_TOKEN_PROGRAM_ID)) -} - -/// Get the token pool pda for a given mint and index -pub fn get_token_pool_pda_with_index(mint: &Pubkey, token_pool_index: u8) -> Pubkey { - find_token_pool_pda_with_index(mint, token_pool_index).0 -} - -/// Derive token pool information for a given mint -pub fn derive_token_pool(mint: &solana_pubkey::Pubkey, index: u8) -> TokenPool { - let (pubkey, bump) = find_token_pool_pda_with_index(mint, index); - TokenPool { - pubkey, - bump, - index, - } -} diff --git a/sdk-libs/ctoken-sdk/src/utils.rs b/sdk-libs/ctoken-sdk/src/utils.rs index a0a9e9b1be..289459993e 100644 --- a/sdk-libs/ctoken-sdk/src/utils.rs +++ b/sdk-libs/ctoken-sdk/src/utils.rs @@ -1,3 +1,5 @@ +//! Utility functions and default account configurations. + use light_ctoken_interface::instructions::transfer2::MultiInputTokenDataWithContext; use light_sdk_types::C_TOKEN_PROGRAM_ID; use solana_account_info::AccountInfo; diff --git a/sdk-libs/ctoken-sdk/tests/account_metas_test.rs b/sdk-libs/ctoken-sdk/tests/account_metas_test.rs index 9ec4315d02..87727345bc 100644 --- a/sdk-libs/ctoken-sdk/tests/account_metas_test.rs +++ b/sdk-libs/ctoken-sdk/tests/account_metas_test.rs @@ -1,3 +1,4 @@ +#![cfg(feature = "v1")] use anchor_lang::ToAccountMetas; use light_compressed_token_types::constants::{ ACCOUNT_COMPRESSION_PROGRAM_ID, CPI_AUTHORITY_PDA, LIGHT_SYSTEM_PROGRAM_ID, NOOP_PROGRAM_ID, diff --git a/sdk-libs/ctoken-sdk/tests/pack_test.rs b/sdk-libs/ctoken-sdk/tests/pack_test.rs index 265e067493..b30eddf68c 100644 --- a/sdk-libs/ctoken-sdk/tests/pack_test.rs +++ b/sdk-libs/ctoken-sdk/tests/pack_test.rs @@ -1,121 +1,119 @@ -#[cfg(test)] -mod tests { - - use light_ctoken_sdk::{ - compat::{PackedCTokenDataWithVariant, TokenData, TokenDataWithVariant}, - Pack, +#![cfg(feature = "compressible")] + +use light_ctoken_sdk::{ + compat::{PackedCTokenDataWithVariant, TokenData, TokenDataWithVariant}, + Pack, +}; +use light_sdk::instruction::PackedAccounts; +use solana_pubkey::Pubkey; + +#[test] +fn test_token_data_packing() { + let mut remaining_accounts = PackedAccounts::default(); + + let owner = Pubkey::new_unique(); + let mint = Pubkey::new_unique(); + let delegate = Pubkey::new_unique(); + + let token_data = TokenData { + owner, + mint, + amount: 1000, + delegate: Some(delegate), + state: Default::default(), + tlv: None, }; - use light_sdk::instruction::PackedAccounts; - use solana_pubkey::Pubkey; - - #[test] - fn test_token_data_packing() { - let mut remaining_accounts = PackedAccounts::default(); - - let owner = Pubkey::new_unique(); - let mint = Pubkey::new_unique(); - let delegate = Pubkey::new_unique(); - - let token_data = TokenData { - owner, - mint, - amount: 1000, - delegate: Some(delegate), - state: Default::default(), - tlv: None, - }; - - // Pack the token data - let packed = token_data.pack(&mut remaining_accounts); - - // Verify the packed data - assert_eq!(packed.owner, 0); // First pubkey gets index 0 - assert_eq!(packed.mint, 1); // Second pubkey gets index 1 - assert_eq!(packed.delegate, 2); // Third pubkey gets index 2 - assert_eq!(packed.amount, 1000); - assert!(packed.has_delegate); - assert_eq!(packed.version, 3); // TokenDataVersion::ShaFlat - - // Verify remaining_accounts contains the pubkeys - let pubkeys = remaining_accounts.packed_pubkeys(); - assert_eq!(pubkeys[0], owner); - assert_eq!(pubkeys[1], mint); - assert_eq!(pubkeys[2], delegate); - } - #[test] - fn test_token_data_with_variant_packing() { - use anchor_lang::{AnchorDeserialize, AnchorSerialize}; - - #[derive(Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize)] - enum MyVariant { - TypeA = 0, - TypeB = 1, - } - - let mut remaining_accounts = PackedAccounts::default(); - - let token_with_variant = TokenDataWithVariant { - variant: MyVariant::TypeA, - token_data: TokenData { - owner: Pubkey::new_unique(), - mint: Pubkey::new_unique(), - amount: 500, - delegate: None, - state: Default::default(), - tlv: None, - }, - }; - - // Pack the wrapper - let packed: PackedCTokenDataWithVariant = - token_with_variant.pack(&mut remaining_accounts); - - // Verify variant is unchanged - assert!(matches!(packed.variant, MyVariant::TypeA)); - - // Verify token data is packed - assert_eq!(packed.token_data.owner, 0); - assert_eq!(packed.token_data.mint, 1); - assert_eq!(packed.token_data.amount, 500); - assert!(!packed.token_data.has_delegate); - } + // Pack the token data + let packed = token_data.pack(&mut remaining_accounts); + + // Verify the packed data + assert_eq!(packed.owner, 0); // First pubkey gets index 0 + assert_eq!(packed.mint, 1); // Second pubkey gets index 1 + assert_eq!(packed.delegate, 2); // Third pubkey gets index 2 + assert_eq!(packed.amount, 1000); + assert!(packed.has_delegate); + assert_eq!(packed.version, 3); // TokenDataVersion::ShaFlat + + // Verify remaining_accounts contains the pubkeys + let pubkeys = remaining_accounts.packed_pubkeys(); + assert_eq!(pubkeys[0], owner); + assert_eq!(pubkeys[1], mint); + assert_eq!(pubkeys[2], delegate); +} - #[test] - fn test_deduplication_in_packing() { - let mut remaining_accounts = PackedAccounts::default(); +#[test] +fn test_token_data_with_variant_packing() { + use anchor_lang::{AnchorDeserialize, AnchorSerialize}; - let shared_owner = Pubkey::new_unique(); - let shared_mint = Pubkey::new_unique(); + #[derive(Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize)] + enum MyVariant { + TypeA = 0, + TypeB = 1, + } - let token1 = TokenData { - owner: shared_owner, - mint: shared_mint, - amount: 100, - delegate: None, - state: Default::default(), - tlv: None, - }; + let mut remaining_accounts = PackedAccounts::default(); - let token2 = TokenData { - owner: shared_owner, // Same owner - mint: shared_mint, // Same mint - amount: 200, + let token_with_variant = TokenDataWithVariant { + variant: MyVariant::TypeA, + token_data: TokenData { + owner: Pubkey::new_unique(), + mint: Pubkey::new_unique(), + amount: 500, delegate: None, state: Default::default(), tlv: None, - }; + }, + }; - // Pack both tokens - let packed1 = token1.pack(&mut remaining_accounts); - let packed2 = token2.pack(&mut remaining_accounts); + // Pack the wrapper + let packed: PackedCTokenDataWithVariant = + token_with_variant.pack(&mut remaining_accounts); - // Both should reference the same indices - assert_eq!(packed1.owner, packed2.owner); - assert_eq!(packed1.mint, packed2.mint); + // Verify variant is unchanged + assert!(matches!(packed.variant, MyVariant::TypeA)); - // Only 2 unique pubkeys should be stored - let pubkeys = remaining_accounts.packed_pubkeys(); - assert_eq!(pubkeys.len(), 2); - } + // Verify token data is packed + assert_eq!(packed.token_data.owner, 0); + assert_eq!(packed.token_data.mint, 1); + assert_eq!(packed.token_data.amount, 500); + assert!(!packed.token_data.has_delegate); +} + +#[test] +fn test_deduplication_in_packing() { + let mut remaining_accounts = PackedAccounts::default(); + + let shared_owner = Pubkey::new_unique(); + let shared_mint = Pubkey::new_unique(); + + let token1 = TokenData { + owner: shared_owner, + mint: shared_mint, + amount: 100, + delegate: None, + state: Default::default(), + tlv: None, + }; + + let token2 = TokenData { + owner: shared_owner, // Same owner + mint: shared_mint, // Same mint + amount: 200, + delegate: None, + state: Default::default(), + tlv: None, + }; + + // Pack both tokens + let packed1 = token1.pack(&mut remaining_accounts); + let packed2 = token2.pack(&mut remaining_accounts); + + // Both should reference the same indices + assert_eq!(packed1.owner, packed2.owner); + assert_eq!(packed1.mint, packed2.mint); + + // Only 2 unique pubkeys should be stored + let pubkeys = remaining_accounts.packed_pubkeys(); + assert_eq!(pubkeys.len(), 2); } diff --git a/sdk-libs/sdk/Cargo.toml b/sdk-libs/sdk/Cargo.toml index 5ce3c6a2ae..23532618f1 100644 --- a/sdk-libs/sdk/Cargo.toml +++ b/sdk-libs/sdk/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib", "lib"] name = "light_sdk" [features] -default = [] +default = ["v2"] idl-build = ["anchor-lang/idl-build", "anchor"] anchor = [ "anchor-lang", diff --git a/sdk-libs/sdk/src/account.rs b/sdk-libs/sdk/src/account.rs index fc865d689d..13050a649e 100644 --- a/sdk-libs/sdk/src/account.rs +++ b/sdk-libs/sdk/src/account.rs @@ -10,12 +10,12 @@ //! //! ### Account Data Hashing //! -//! Sha256 data hashing is the recommended for most use cases. +//! Sha256 data hashing is recommended for most use cases. //! Account data is serialized into a vector with borsh and hashed with Sha256. //! -//! Poseidon data hashing is recommended zk use cases. -//! The data struct needs to implement the DataHasher implementation. -//! The LightHasher derives, the DataHasher trait a hashing scheme from the compressed account layout. +//! Poseidon data hashing is recommended for zk use cases. +//! The data struct needs to implement the DataHasher trait. +//! The LightHasher macro derives, the DataHasher trait. The hashing scheme resembles the struct layout. //! Alternatively, DataHasher can be implemented manually. //! Poseidon hashing is CU intensive and has limitations with regards to hash inputs see Poseidon module for details. //! diff --git a/sdk-libs/sdk/src/instruction/mod.rs b/sdk-libs/sdk/src/instruction/mod.rs index 03791d0477..e496610674 100644 --- a/sdk-libs/sdk/src/instruction/mod.rs +++ b/sdk-libs/sdk/src/instruction/mod.rs @@ -15,10 +15,6 @@ //! ├─ use CompressedAccountMeta to instantiate a LightAccount struct. //! │ //! └─ 𝐋𝐢𝐠𝐡𝐭 𝐒𝐲𝐬𝐭𝐞𝐦 𝐏𝐫𝐨𝐠𝐫𝐚𝐦 𝐂𝐏𝐈 -//! ├─ Verify ValidityProof. -//! ├─ Update State Merkle tree. -//! ├─ Update Address Merkle tree. -//! └─ Complete atomic state transition. //! ``` //! ## Main Types //! diff --git a/sdk-libs/sdk/src/instruction/pack_accounts.rs b/sdk-libs/sdk/src/instruction/pack_accounts.rs index 04bb14ad51..c6c5d4663c 100644 --- a/sdk-libs/sdk/src/instruction/pack_accounts.rs +++ b/sdk-libs/sdk/src/instruction/pack_accounts.rs @@ -127,7 +127,7 @@ use crate::{ AccountMeta, Pubkey, }; -/// Builder for organizing accounts into compressed account instructions. +/// Builder to collect accounts for compressed account instructions. /// /// Manages three categories of accounts: /// - **Pre-accounts**: Signers and other custom accounts that come before system accounts. diff --git a/sdk-libs/sdk/src/lib.rs b/sdk-libs/sdk/src/lib.rs index 2cbff5d451..8d850dd6af 100644 --- a/sdk-libs/sdk/src/lib.rs +++ b/sdk-libs/sdk/src/lib.rs @@ -1,6 +1,6 @@ //! The base library to use Compressed Accounts in Solana on-chain Rust and Anchor programs. //! -//! Compressed Accounts stores state as account hashes in State Merkle trees. +//! Compressed Accounts store state as account hashes in State Merkle trees. //! and unique addresses in Address Merkle trees. //! Validity proofs (zero-knowledge proofs) verify that compressed account //! state exists and new addresses do not exist yet. @@ -31,6 +31,7 @@ //! - [`LightSystemProgramCpi`](crate::cpi::v1::LightSystemProgramCpi) - Prepare instruction data to cpi the light system program. //! - [`InvokeLightSystemProgram::invoke`](crate::cpi) - Invoke the light system program via cpi. //! +//! # Client Program Interaction Flow //! ```text //! ├─ 𝐂𝐥𝐢𝐞𝐧𝐭 //! │ ├─ Get ValidityProof from RPC. diff --git a/sdk-libs/token-client/src/actions/transfer2/ctoken_to_spl.rs b/sdk-libs/token-client/src/actions/transfer2/ctoken_to_spl.rs index d8e954851f..5621d48475 100644 --- a/sdk-libs/token-client/src/actions/transfer2/ctoken_to_spl.rs +++ b/sdk-libs/token-client/src/actions/transfer2/ctoken_to_spl.rs @@ -3,7 +3,8 @@ use light_client::{ rpc::{Rpc, RpcError}, }; use light_ctoken_sdk::{ - ctoken::TransferCtokenToSpl, token_pool::find_token_pool_pda_with_index, SPL_TOKEN_PROGRAM_ID, + ctoken::TransferCtokenToSpl, spl_interface::find_spl_interface_pda_with_index, + SPL_TOKEN_PROGRAM_ID, }; use solana_keypair::Keypair; use solana_pubkey::Pubkey; @@ -20,7 +21,7 @@ pub async fn transfer_ctoken_to_spl( mint: Pubkey, payer: &Keypair, ) -> Result { - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let transfer_ix = TransferCtokenToSpl { source_ctoken_account, @@ -29,8 +30,8 @@ pub async fn transfer_ctoken_to_spl( authority: authority.pubkey(), mint, payer: payer.pubkey(), - token_pool_pda, - token_pool_pda_bump, + spl_interface_pda, + spl_interface_pda_bump, spl_token_program: Pubkey::new_from_array(SPL_TOKEN_PROGRAM_ID), // TODO: make dynamic } .instruction() diff --git a/sdk-libs/token-client/src/actions/transfer2/spl_to_ctoken.rs b/sdk-libs/token-client/src/actions/transfer2/spl_to_ctoken.rs index ef91e03877..e61fd142be 100644 --- a/sdk-libs/token-client/src/actions/transfer2/spl_to_ctoken.rs +++ b/sdk-libs/token-client/src/actions/transfer2/spl_to_ctoken.rs @@ -3,7 +3,8 @@ use light_client::{ rpc::{Rpc, RpcError}, }; use light_ctoken_sdk::{ - ctoken::TransferSplToCtoken, token_pool::find_token_pool_pda_with_index, SPL_TOKEN_PROGRAM_ID, + ctoken::TransferSplToCtoken, spl_interface::find_spl_interface_pda_with_index, + SPL_TOKEN_PROGRAM_ID, }; use solana_keypair::Keypair; use solana_pubkey::Pubkey; @@ -31,17 +32,17 @@ pub async fn spl_to_ctoken_transfer( let mint = pod_account.mint; - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let ix = TransferSplToCtoken { amount, - token_pool_pda_bump, + spl_interface_pda_bump, source_spl_token_account, destination_ctoken_account, authority: authority.pubkey(), mint, payer: payer.pubkey(), - token_pool_pda, + spl_interface_pda, spl_token_program: Pubkey::new_from_array(SPL_TOKEN_PROGRAM_ID), // TODO: make dynamic } .instruction() diff --git a/sdk-libs/token-client/src/instructions/mint_to_compressed.rs b/sdk-libs/token-client/src/instructions/mint_to_compressed.rs index 5632f57c1f..348941bf53 100644 --- a/sdk-libs/token-client/src/instructions/mint_to_compressed.rs +++ b/sdk-libs/token-client/src/instructions/mint_to_compressed.rs @@ -14,7 +14,7 @@ use light_ctoken_sdk::{ create_mint_to_compressed_instruction, DecompressedMintConfig, MintToCompressedInputs, }, }, - token_pool::{derive_token_pool, find_token_pool_pda_with_index}, + spl_interface::{derive_spl_interface_pda, find_spl_interface_pda_with_index}, }; use solana_instruction::Instruction; use solana_pubkey::Pubkey; @@ -59,19 +59,19 @@ pub async fn mint_to_compressed_instruction( // Create decompressed mint config and token pool if mint is decompressed let decompressed_mint_config = if compressed_mint.metadata.spl_mint_initialized { - let (token_pool_pda, _) = find_token_pool_pda_with_index(&spl_mint_pda, 0); + let (spl_interface_pda, _) = find_spl_interface_pda_with_index(&spl_mint_pda, 0); Some(DecompressedMintConfig { mint_pda: spl_mint_pda, - token_pool_pda, + token_pool_pda: spl_interface_pda, token_program: spl_token_2022::ID, }) } else { None }; - // Derive token pool if needed for decompressed mints - let token_pool = if compressed_mint.metadata.spl_mint_initialized { - Some(derive_token_pool(&spl_mint_pda, 0)) + // Derive spl interface pda if needed for decompressed mints + let spl_interface_pda = if compressed_mint.metadata.spl_mint_initialized { + Some(derive_spl_interface_pda(&spl_mint_pda, 0)) } else { None }; @@ -103,7 +103,7 @@ pub async fn mint_to_compressed_instruction( decompressed_mint_config, proof: rpc_proof_result.proof.into(), token_account_version: token_account_version as u8, // V2 for batched merkle trees - token_pool, + spl_interface_pda, }, None, ) diff --git a/sdk-libs/token-client/src/instructions/transfer2.rs b/sdk-libs/token-client/src/instructions/transfer2.rs index 3417ce4049..79b7040a48 100644 --- a/sdk-libs/token-client/src/instructions/transfer2.rs +++ b/sdk-libs/token-client/src/instructions/transfer2.rs @@ -16,7 +16,7 @@ use light_ctoken_sdk::{ CTokenAccount2, }, error::TokenSdkError, - token_pool::find_token_pool_pda_with_index, + spl_interface::find_spl_interface_pda_with_index, }; use light_sdk::instruction::{PackedAccounts, PackedStateTreeInfo}; use solana_instruction::Instruction; @@ -278,8 +278,9 @@ pub async fn create_generic_transfer2_instruction( // Use pool_index from input, default to 0 let pool_index = input.pool_index.unwrap_or(0); - let (token_pool_pda, bump) = find_token_pool_pda_with_index(&mint, pool_index); - let pool_account_index = packed_tree_accounts.insert_or_get(token_pool_pda); + let (spl_interface_pda, bump) = + find_spl_interface_pda_with_index(&mint, pool_index); + let pool_account_index = packed_tree_accounts.insert_or_get(spl_interface_pda); // Use the new SPL-specific compress method token_account.compress_spl( @@ -344,8 +345,9 @@ pub async fn create_generic_transfer2_instruction( // Use pool_index from input, default to 0 let pool_index = input.pool_index.unwrap_or(0); - let (token_pool_pda, bump) = find_token_pool_pda_with_index(&mint, pool_index); - let pool_account_index = packed_tree_accounts.insert_or_get(token_pool_pda); + let (spl_interface_pda, bump) = + find_spl_interface_pda_with_index(&mint, pool_index); + let pool_account_index = packed_tree_accounts.insert_or_get(spl_interface_pda); // Use the new SPL-specific decompress method token_account.decompress_spl( diff --git a/sdk-tests/csdk-anchor-derived-test/Cargo.toml b/sdk-tests/csdk-anchor-derived-test/Cargo.toml index 63e2fd9d30..a23ca35b46 100644 --- a/sdk-tests/csdk-anchor-derived-test/Cargo.toml +++ b/sdk-tests/csdk-anchor-derived-test/Cargo.toml @@ -30,7 +30,7 @@ light-compressed-account = { workspace = true, features = ["solana"] } anchor-lang = { workspace = true, features = ["idl-build"] } anchor-spl = { version = "=0.31.1", git = "https://github.com/lightprotocol/anchor", rev = "d8a2b3d9", features = ["memo", "metadata", "idl-build"] } light-ctoken-interface = { workspace = true, features = ["anchor"] } -light-ctoken-sdk = { workspace = true, features = ["anchor"] } +light-ctoken-sdk = { workspace = true, features = ["anchor", "compressible"] } light-compressed-token-types = { workspace = true, features = ["anchor"] } light-compressible = { workspace = true, features = ["anchor"] } diff --git a/sdk-tests/csdk-anchor-full-derived-test/Cargo.toml b/sdk-tests/csdk-anchor-full-derived-test/Cargo.toml index 609e5ccc0f..4dbdbf80a7 100644 --- a/sdk-tests/csdk-anchor-full-derived-test/Cargo.toml +++ b/sdk-tests/csdk-anchor-full-derived-test/Cargo.toml @@ -32,7 +32,7 @@ light-compressed-account = { workspace = true, features = ["solana"] } anchor-lang = { workspace = true, features = ["idl-build"] } anchor-spl = { version = "=0.31.1", git = "https://github.com/lightprotocol/anchor", rev = "d8a2b3d9", features = ["memo", "metadata", "idl-build"] } light-ctoken-interface = { workspace = true, features = ["anchor"] } -light-ctoken-sdk = { workspace = true, features = ["anchor"] } +light-ctoken-sdk = { workspace = true, features = ["anchor", "compressible"] } light-compressed-token-types = { workspace = true, features = ["anchor"] } light-compressible = { workspace = true, features = ["anchor"] } diff --git a/sdk-tests/sdk-compressible-test/Cargo.toml b/sdk-tests/sdk-compressible-test/Cargo.toml index b4ee691364..f7840a2d3a 100644 --- a/sdk-tests/sdk-compressible-test/Cargo.toml +++ b/sdk-tests/sdk-compressible-test/Cargo.toml @@ -29,7 +29,7 @@ light-compressed-account = { workspace = true, features = ["solana"] } anchor-lang = { workspace = true, features = ["idl-build"] } anchor-spl = { version = "=0.31.1", git = "https://github.com/lightprotocol/anchor", rev = "d8a2b3d9", features = ["memo", "metadata", "idl-build"] } light-ctoken-interface = { workspace = true, features = ["anchor"] } -light-ctoken-sdk = { workspace = true, features = ["anchor"] } +light-ctoken-sdk = { workspace = true, features = ["anchor", "compressible"] } light-compressed-token-types = { workspace = true, features = ["anchor"] } light-compressible = { workspace = true, features = ["anchor"] } diff --git a/sdk-tests/sdk-ctoken-test/src/transfer_interface.rs b/sdk-tests/sdk-ctoken-test/src/transfer_interface.rs index b55658b11a..284a2a3b4a 100644 --- a/sdk-tests/sdk-ctoken-test/src/transfer_interface.rs +++ b/sdk-tests/sdk-ctoken-test/src/transfer_interface.rs @@ -12,7 +12,7 @@ pub const TRANSFER_INTERFACE_AUTHORITY_SEED: &[u8] = b"transfer_interface_author pub struct TransferInterfaceData { pub amount: u64, /// Required for SPL<->CToken transfers, None for CToken->CToken - pub token_pool_pda_bump: Option, + pub spl_interface_pda_bump: Option, } /// Handler for TransferInterface (invoke) @@ -31,7 +31,7 @@ pub struct TransferInterfaceData { /// - accounts[5]: compressed_token_program_authority /// For SPL bridge (optional, required for SPL<->CToken): /// - accounts[6]: mint -/// - accounts[7]: token_pool_pda +/// - accounts[7]: spl_interface_pda /// - accounts[8]: spl_token_program pub fn process_transfer_interface_invoke( accounts: &[AccountInfo], @@ -51,12 +51,12 @@ pub fn process_transfer_interface_invoke( ); // Add SPL bridge config if provided - if accounts.len() >= 9 && data.token_pool_pda_bump.is_some() { + if accounts.len() >= 9 && data.spl_interface_pda_bump.is_some() { transfer = transfer.with_spl_interface( Some(accounts[6].clone()), // mint Some(accounts[8].clone()), // spl_token_program - Some(accounts[7].clone()), // token_pool_pda - data.token_pool_pda_bump, + Some(accounts[7].clone()), // spl_interface_pda + data.spl_interface_pda_bump, )?; } @@ -78,7 +78,7 @@ pub fn process_transfer_interface_invoke( /// - accounts[5]: compressed_token_program_authority /// For SPL bridge (optional, required for SPL<->CToken): /// - accounts[6]: mint -/// - accounts[7]: token_pool_pda +/// - accounts[7]: spl_interface_pda /// - accounts[8]: spl_token_program pub fn process_transfer_interface_invoke_signed( accounts: &[AccountInfo], @@ -107,12 +107,12 @@ pub fn process_transfer_interface_invoke_signed( ); // Add SPL bridge config if provided - if accounts.len() >= 9 && data.token_pool_pda_bump.is_some() { + if accounts.len() >= 9 && data.spl_interface_pda_bump.is_some() { transfer = transfer.with_spl_interface( Some(accounts[6].clone()), // mint Some(accounts[8].clone()), // spl_token_program - Some(accounts[7].clone()), // token_pool_pda - data.token_pool_pda_bump, + Some(accounts[7].clone()), // spl_interface_pda + data.spl_interface_pda_bump, )?; } diff --git a/sdk-tests/sdk-ctoken-test/src/transfer_spl_ctoken.rs b/sdk-tests/sdk-ctoken-test/src/transfer_spl_ctoken.rs index fb136db28f..33669159b0 100644 --- a/sdk-tests/sdk-ctoken-test/src/transfer_spl_ctoken.rs +++ b/sdk-tests/sdk-ctoken-test/src/transfer_spl_ctoken.rs @@ -11,14 +11,14 @@ pub const TRANSFER_AUTHORITY_SEED: &[u8] = b"transfer_authority"; #[derive(BorshSerialize, BorshDeserialize, Debug)] pub struct TransferSplToCtokenData { pub amount: u64, - pub token_pool_pda_bump: u8, + pub spl_interface_pda_bump: u8, } /// Instruction data for CToken to SPL transfer #[derive(BorshSerialize, BorshDeserialize, Debug)] pub struct TransferCtokenToSplData { pub amount: u64, - pub token_pool_pda_bump: u8, + pub spl_interface_pda_bump: u8, } /// Handler for transferring SPL tokens to CToken (invoke) @@ -30,7 +30,7 @@ pub struct TransferCtokenToSplData { /// - accounts[3]: authority (signer) /// - accounts[4]: mint /// - accounts[5]: payer (signer) -/// - accounts[6]: token_pool_pda +/// - accounts[6]: spl_interface_pda /// - accounts[7]: spl_token_program /// - accounts[8]: compressed_token_program_authority pub fn process_spl_to_ctoken_invoke( @@ -48,8 +48,8 @@ pub fn process_spl_to_ctoken_invoke( authority: accounts[3].clone(), mint: accounts[4].clone(), payer: accounts[5].clone(), - token_pool_pda: accounts[6].clone(), - token_pool_pda_bump: data.token_pool_pda_bump, + spl_interface_pda: accounts[6].clone(), + spl_interface_pda_bump: data.spl_interface_pda_bump, spl_token_program: accounts[7].clone(), compressed_token_program_authority: accounts[8].clone(), } @@ -69,7 +69,7 @@ pub fn process_spl_to_ctoken_invoke( /// - accounts[3]: authority (PDA, not signer - program signs) /// - accounts[4]: mint /// - accounts[5]: payer (signer) -/// - accounts[6]: token_pool_pda +/// - accounts[6]: spl_interface_pda /// - accounts[7]: spl_token_program /// - accounts[8]: compressed_token_program_authority pub fn process_spl_to_ctoken_invoke_signed( @@ -96,8 +96,8 @@ pub fn process_spl_to_ctoken_invoke_signed( authority: accounts[3].clone(), mint: accounts[4].clone(), payer: accounts[5].clone(), - token_pool_pda: accounts[6].clone(), - token_pool_pda_bump: data.token_pool_pda_bump, + spl_interface_pda: accounts[6].clone(), + spl_interface_pda_bump: data.spl_interface_pda_bump, spl_token_program: accounts[7].clone(), compressed_token_program_authority: accounts[8].clone(), }; @@ -118,7 +118,7 @@ pub fn process_spl_to_ctoken_invoke_signed( /// - accounts[3]: authority (signer) /// - accounts[4]: mint /// - accounts[5]: payer (signer) -/// - accounts[6]: token_pool_pda +/// - accounts[6]: spl_interface_pda /// - accounts[7]: spl_token_program /// - accounts[8]: compressed_token_program_authority pub fn process_ctoken_to_spl_invoke( @@ -136,8 +136,8 @@ pub fn process_ctoken_to_spl_invoke( authority: accounts[3].clone(), mint: accounts[4].clone(), payer: accounts[5].clone(), - token_pool_pda: accounts[6].clone(), - token_pool_pda_bump: data.token_pool_pda_bump, + spl_interface_pda: accounts[6].clone(), + spl_interface_pda_bump: data.spl_interface_pda_bump, spl_token_program: accounts[7].clone(), compressed_token_program_authority: accounts[8].clone(), } @@ -157,7 +157,7 @@ pub fn process_ctoken_to_spl_invoke( /// - accounts[3]: authority (PDA, not signer - program signs) /// - accounts[4]: mint /// - accounts[5]: payer (signer) -/// - accounts[6]: token_pool_pda +/// - accounts[6]: spl_interface_pda /// - accounts[7]: spl_token_program /// - accounts[8]: compressed_token_program_authority pub fn process_ctoken_to_spl_invoke_signed( @@ -184,8 +184,8 @@ pub fn process_ctoken_to_spl_invoke_signed( authority: accounts[3].clone(), mint: accounts[4].clone(), payer: accounts[5].clone(), - token_pool_pda: accounts[6].clone(), - token_pool_pda_bump: data.token_pool_pda_bump, + spl_interface_pda: accounts[6].clone(), + spl_interface_pda_bump: data.spl_interface_pda_bump, spl_token_program: accounts[7].clone(), compressed_token_program_authority: accounts[8].clone(), }; diff --git a/sdk-tests/sdk-ctoken-test/tests/test_transfer_interface.rs b/sdk-tests/sdk-ctoken-test/tests/test_transfer_interface.rs index 9f1d3f66df..876736c242 100644 --- a/sdk-tests/sdk-ctoken-test/tests/test_transfer_interface.rs +++ b/sdk-tests/sdk-ctoken-test/tests/test_transfer_interface.rs @@ -7,7 +7,7 @@ use light_client::rpc::Rpc; use light_compressed_token_types::CPI_AUTHORITY_PDA; use light_ctoken_sdk::{ ctoken::{derive_ctoken_ata, CreateAssociatedTokenAccount}, - token_pool::find_token_pool_pda_with_index, + spl_interface::find_spl_interface_pda_with_index, }; use light_program_test::{LightProgramTest, ProgramTestConfig}; use light_test_utils::spl::{create_mint_helper, create_token_2022_account, mint_spl_tokens}; @@ -75,7 +75,7 @@ async fn test_transfer_interface_spl_to_ctoken_invoke() { let ctoken_account = derive_ctoken_ata(&recipient.pubkey(), &mint).0; // Get token pool PDA - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let compressed_token_program_id = Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); @@ -83,7 +83,7 @@ async fn test_transfer_interface_spl_to_ctoken_invoke() { // Build wrapper instruction let data = TransferInterfaceData { amount: transfer_amount, - token_pool_pda_bump: Some(token_pool_pda_bump), + spl_interface_pda_bump: Some(spl_interface_pda_bump), }; // Discriminator 19 = TransferInterfaceInvoke let wrapper_instruction_data = [vec![19u8], data.try_to_vec().unwrap()].concat(); @@ -96,7 +96,7 @@ async fn test_transfer_interface_spl_to_ctoken_invoke() { AccountMeta::new(payer.pubkey(), true), // payer AccountMeta::new_readonly(cpi_authority_pda, false), // compressed_token_program_authority AccountMeta::new_readonly(mint, false), // mint (for SPL bridge) - AccountMeta::new(token_pool_pda, false), // token_pool_pda + AccountMeta::new(spl_interface_pda, false), // spl_interface_pda AccountMeta::new_readonly(anchor_spl::token::ID, false), // spl_token_program ]; @@ -181,7 +181,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke() { .await .unwrap(); - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let compressed_token_program_id = Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); @@ -190,7 +190,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke() { { let data = TransferInterfaceData { amount, - token_pool_pda_bump: Some(token_pool_pda_bump), + spl_interface_pda_bump: Some(spl_interface_pda_bump), }; let wrapper_instruction_data = [vec![19u8], data.try_to_vec().unwrap()].concat(); let wrapper_accounts = vec![ @@ -201,7 +201,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke() { AccountMeta::new(payer.pubkey(), true), AccountMeta::new_readonly(cpi_authority_pda, false), AccountMeta::new_readonly(mint, false), - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), ]; let instruction = Instruction { @@ -217,7 +217,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke() { // Now test CToken -> SPL transfer let data = TransferInterfaceData { amount: transfer_amount, - token_pool_pda_bump: Some(token_pool_pda_bump), + spl_interface_pda_bump: Some(spl_interface_pda_bump), }; let wrapper_instruction_data = [vec![19u8], data.try_to_vec().unwrap()].concat(); @@ -229,7 +229,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke() { AccountMeta::new(payer.pubkey(), true), // payer AccountMeta::new_readonly(cpi_authority_pda, false), AccountMeta::new_readonly(mint, false), - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), ]; @@ -321,7 +321,7 @@ async fn test_transfer_interface_ctoken_to_ctoken_invoke() { .await .unwrap(); - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let compressed_token_program_id = Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); @@ -330,7 +330,7 @@ async fn test_transfer_interface_ctoken_to_ctoken_invoke() { { let data = TransferInterfaceData { amount, - token_pool_pda_bump: Some(token_pool_pda_bump), + spl_interface_pda_bump: Some(spl_interface_pda_bump), }; let wrapper_instruction_data = [vec![19u8], data.try_to_vec().unwrap()].concat(); let wrapper_accounts = vec![ @@ -341,7 +341,7 @@ async fn test_transfer_interface_ctoken_to_ctoken_invoke() { AccountMeta::new(payer.pubkey(), true), AccountMeta::new_readonly(cpi_authority_pda, false), AccountMeta::new_readonly(mint, false), - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), ]; let instruction = Instruction { @@ -357,7 +357,7 @@ async fn test_transfer_interface_ctoken_to_ctoken_invoke() { // Now test CToken -> CToken transfer (no SPL bridge needed) let data = TransferInterfaceData { amount: transfer_amount, - token_pool_pda_bump: None, // Not needed for CToken->CToken + spl_interface_pda_bump: None, // Not needed for CToken->CToken }; let wrapper_instruction_data = [vec![19u8], data.try_to_vec().unwrap()].concat(); @@ -464,14 +464,14 @@ async fn test_transfer_interface_spl_to_ctoken_invoke_signed() { .unwrap(); let ctoken_account = derive_ctoken_ata(&recipient.pubkey(), &mint).0; - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let compressed_token_program_id = Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); let data = TransferInterfaceData { amount: transfer_amount, - token_pool_pda_bump: Some(token_pool_pda_bump), + spl_interface_pda_bump: Some(spl_interface_pda_bump), }; // Discriminator 20 = TransferInterfaceInvokeSigned let wrapper_instruction_data = [vec![20u8], data.try_to_vec().unwrap()].concat(); @@ -484,7 +484,7 @@ async fn test_transfer_interface_spl_to_ctoken_invoke_signed() { AccountMeta::new(payer.pubkey(), true), // payer AccountMeta::new_readonly(cpi_authority_pda, false), // compressed_token_program_authority AccountMeta::new_readonly(mint, false), - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), ]; @@ -587,7 +587,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke_signed() { .await .unwrap(); - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let compressed_token_program_id = Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); @@ -596,7 +596,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke_signed() { { let data = TransferInterfaceData { amount, - token_pool_pda_bump: Some(token_pool_pda_bump), + spl_interface_pda_bump: Some(spl_interface_pda_bump), }; let wrapper_instruction_data = [vec![19u8], data.try_to_vec().unwrap()].concat(); let wrapper_accounts = vec![ @@ -607,7 +607,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke_signed() { AccountMeta::new(payer.pubkey(), true), AccountMeta::new_readonly(cpi_authority_pda, false), AccountMeta::new_readonly(mint, false), - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), ]; let instruction = Instruction { @@ -623,7 +623,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke_signed() { // Now test CToken -> SPL with PDA authority let data = TransferInterfaceData { amount: transfer_amount, - token_pool_pda_bump: Some(token_pool_pda_bump), + spl_interface_pda_bump: Some(spl_interface_pda_bump), }; // Discriminator 20 = TransferInterfaceInvokeSigned let wrapper_instruction_data = [vec![20u8], data.try_to_vec().unwrap()].concat(); @@ -636,7 +636,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke_signed() { AccountMeta::new(payer.pubkey(), true), // payer AccountMeta::new_readonly(cpi_authority_pda, false), AccountMeta::new_readonly(mint, false), - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), ]; @@ -740,7 +740,7 @@ async fn test_transfer_interface_ctoken_to_ctoken_invoke_signed() { .await .unwrap(); - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let compressed_token_program_id = Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); @@ -749,7 +749,7 @@ async fn test_transfer_interface_ctoken_to_ctoken_invoke_signed() { { let data = TransferInterfaceData { amount, - token_pool_pda_bump: Some(token_pool_pda_bump), + spl_interface_pda_bump: Some(spl_interface_pda_bump), }; let wrapper_instruction_data = [vec![19u8], data.try_to_vec().unwrap()].concat(); let wrapper_accounts = vec![ @@ -760,7 +760,7 @@ async fn test_transfer_interface_ctoken_to_ctoken_invoke_signed() { AccountMeta::new(payer.pubkey(), true), AccountMeta::new_readonly(cpi_authority_pda, false), AccountMeta::new_readonly(mint, false), - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), ]; let instruction = Instruction { @@ -776,7 +776,7 @@ async fn test_transfer_interface_ctoken_to_ctoken_invoke_signed() { // Now test CToken -> CToken with PDA authority let data = TransferInterfaceData { amount: transfer_amount, - token_pool_pda_bump: None, // Not needed for CToken->CToken + spl_interface_pda_bump: None, // Not needed for CToken->CToken }; // Discriminator 20 = TransferInterfaceInvokeSigned let wrapper_instruction_data = [vec![20u8], data.try_to_vec().unwrap()].concat(); diff --git a/sdk-tests/sdk-ctoken-test/tests/test_transfer_spl_ctoken.rs b/sdk-tests/sdk-ctoken-test/tests/test_transfer_spl_ctoken.rs index 0d6a7ea548..4e06adeac1 100644 --- a/sdk-tests/sdk-ctoken-test/tests/test_transfer_spl_ctoken.rs +++ b/sdk-tests/sdk-ctoken-test/tests/test_transfer_spl_ctoken.rs @@ -7,7 +7,7 @@ use light_client::rpc::Rpc; use light_compressed_token_types::CPI_AUTHORITY_PDA; use light_ctoken_sdk::{ ctoken::{derive_ctoken_ata, CreateAssociatedTokenAccount}, - token_pool::find_token_pool_pda_with_index, + spl_interface::find_spl_interface_pda_with_index, }; use light_program_test::{LightProgramTest, ProgramTestConfig}; use light_test_utils::spl::{create_mint_helper, create_token_2022_account, mint_spl_tokens}; @@ -86,7 +86,7 @@ async fn test_spl_to_ctoken_invoke() { assert_eq!(initial_spl_balance, amount); // Get token pool PDA - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let compressed_token_program_id = Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); @@ -94,7 +94,7 @@ async fn test_spl_to_ctoken_invoke() { // Build wrapper instruction for SPL to CToken transfer let data = TransferSplToCtokenData { amount: transfer_amount, - token_pool_pda_bump, + spl_interface_pda_bump, }; // Discriminator 15 = SplToCtokenInvoke let wrapper_instruction_data = [vec![15u8], data.try_to_vec().unwrap()].concat(); @@ -106,7 +106,7 @@ async fn test_spl_to_ctoken_invoke() { // - accounts[3]: authority (signer) // - accounts[4]: mint // - accounts[5]: payer (signer) - // - accounts[6]: token_pool_pda + // - accounts[6]: spl_interface_pda // - accounts[7]: spl_token_program // - accounts[8]: compressed_token_program_authority let wrapper_accounts = vec![ @@ -116,7 +116,7 @@ async fn test_spl_to_ctoken_invoke() { AccountMeta::new_readonly(sender.pubkey(), true), // authority (signer) AccountMeta::new_readonly(mint, false), AccountMeta::new(payer.pubkey(), true), // payer (signer) - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), AccountMeta::new_readonly(cpi_authority_pda, false), ]; @@ -209,7 +209,7 @@ async fn test_ctoken_to_spl_invoke() { .unwrap(); // Transfer from temp SPL to ctoken to fund it - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let compressed_token_program_id = Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); @@ -217,7 +217,7 @@ async fn test_ctoken_to_spl_invoke() { { let data = TransferSplToCtokenData { amount, - token_pool_pda_bump, + spl_interface_pda_bump, }; let wrapper_instruction_data = [vec![15u8], data.try_to_vec().unwrap()].concat(); let wrapper_accounts = vec![ @@ -227,7 +227,7 @@ async fn test_ctoken_to_spl_invoke() { AccountMeta::new_readonly(owner.pubkey(), true), AccountMeta::new_readonly(mint, false), AccountMeta::new(payer.pubkey(), true), - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), AccountMeta::new_readonly(cpi_authority_pda, false), ]; @@ -253,7 +253,7 @@ async fn test_ctoken_to_spl_invoke() { // Now test CToken to SPL transfer let data = TransferCtokenToSplData { amount: transfer_amount, - token_pool_pda_bump, + spl_interface_pda_bump, }; // Discriminator 17 = CtokenToSplInvoke let wrapper_instruction_data = [vec![17u8], data.try_to_vec().unwrap()].concat(); @@ -265,7 +265,7 @@ async fn test_ctoken_to_spl_invoke() { // - accounts[3]: authority (signer) // - accounts[4]: mint // - accounts[5]: payer (signer) - // - accounts[6]: token_pool_pda + // - accounts[6]: spl_interface_pda // - accounts[7]: spl_token_program // - accounts[8]: compressed_token_program_authority let wrapper_accounts = vec![ @@ -275,7 +275,7 @@ async fn test_ctoken_to_spl_invoke() { AccountMeta::new_readonly(owner.pubkey(), true), // authority (signer) AccountMeta::new_readonly(mint, false), AccountMeta::new(payer.pubkey(), true), // payer (signer) - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), AccountMeta::new_readonly(cpi_authority_pda, false), ]; @@ -377,8 +377,8 @@ async fn test_spl_to_ctoken_invoke_signed() { .unwrap(); let ctoken_account = derive_ctoken_ata(&recipient.pubkey(), &mint).0; - // Get token pool PDA - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + // Get SPL interface PDA + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let compressed_token_program_id = Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); @@ -386,7 +386,7 @@ async fn test_spl_to_ctoken_invoke_signed() { // Build wrapper instruction for SPL to CToken transfer with PDA authority let data = TransferSplToCtokenData { amount: transfer_amount, - token_pool_pda_bump, + spl_interface_pda_bump, }; // Discriminator 16 = SplToCtokenInvokeSigned let wrapper_instruction_data = [vec![16u8], data.try_to_vec().unwrap()].concat(); @@ -398,7 +398,7 @@ async fn test_spl_to_ctoken_invoke_signed() { AccountMeta::new_readonly(authority_pda, false), // authority is PDA, not signer AccountMeta::new_readonly(mint, false), AccountMeta::new(payer.pubkey(), true), // payer (signer) - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), AccountMeta::new_readonly(cpi_authority_pda, false), ]; @@ -516,7 +516,7 @@ async fn test_ctoken_to_spl_invoke_signed() { .unwrap(); // Transfer from temp SPL to ctoken to fund it - let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0); + let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); let compressed_token_program_id = Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); @@ -524,7 +524,7 @@ async fn test_ctoken_to_spl_invoke_signed() { { let data = TransferSplToCtokenData { amount, - token_pool_pda_bump, + spl_interface_pda_bump, }; let wrapper_instruction_data = [vec![15u8], data.try_to_vec().unwrap()].concat(); let wrapper_accounts = vec![ @@ -534,7 +534,7 @@ async fn test_ctoken_to_spl_invoke_signed() { AccountMeta::new_readonly(temp_owner.pubkey(), true), AccountMeta::new_readonly(mint, false), AccountMeta::new(payer.pubkey(), true), - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), AccountMeta::new_readonly(cpi_authority_pda, false), ]; @@ -560,7 +560,7 @@ async fn test_ctoken_to_spl_invoke_signed() { // Now test CToken to SPL transfer with PDA authority let data = TransferCtokenToSplData { amount: transfer_amount, - token_pool_pda_bump, + spl_interface_pda_bump, }; // Discriminator 18 = CtokenToSplInvokeSigned let wrapper_instruction_data = [vec![18u8], data.try_to_vec().unwrap()].concat(); @@ -572,7 +572,7 @@ async fn test_ctoken_to_spl_invoke_signed() { AccountMeta::new_readonly(authority_pda, false), // authority is PDA, not signer AccountMeta::new_readonly(mint, false), AccountMeta::new(payer.pubkey(), true), // payer (signer) - AccountMeta::new(token_pool_pda, false), + AccountMeta::new(spl_interface_pda, false), AccountMeta::new_readonly(anchor_spl::token::ID, false), AccountMeta::new_readonly(cpi_authority_pda, false), ]; diff --git a/sdk-tests/sdk-token-test/Cargo.toml b/sdk-tests/sdk-token-test/Cargo.toml index e29a0764e9..035402236f 100644 --- a/sdk-tests/sdk-token-test/Cargo.toml +++ b/sdk-tests/sdk-token-test/Cargo.toml @@ -31,7 +31,7 @@ profile-heap = [ ] [dependencies] -light-ctoken-sdk = { workspace = true, features = ["anchor", "cpi-context"] } +light-ctoken-sdk = { workspace = true, features = ["anchor", "cpi-context", "v1"] } anchor-lang = { workspace = true } light-hasher = { workspace = true } light-sdk = { workspace = true, features = ["v2", "cpi-context"] } diff --git a/sdk-tests/sdk-token-test/tests/test.rs b/sdk-tests/sdk-token-test/tests/test.rs index 08b318319b..cbfb49f56b 100644 --- a/sdk-tests/sdk-token-test/tests/test.rs +++ b/sdk-tests/sdk-token-test/tests/test.rs @@ -12,7 +12,7 @@ use light_ctoken_sdk::{ get_transfer_instruction_account_metas, TokenAccountsMetaConfig, }, }, - token_pool::{find_token_pool_pda_with_index, get_token_pool_pda}, + spl_interface::{find_spl_interface_pda_with_index, get_spl_interface_pda}, TokenAccountMeta, SPL_TOKEN_PROGRAM_ID, }; use light_program_test::{Indexer, LightProgramTest, ProgramTestConfig, Rpc}; @@ -289,9 +289,9 @@ async fn compress_spl_tokens( token_account: Pubkey, ) -> Result { let mut remaining_accounts = PackedAccounts::default(); - let token_pool_pda = get_token_pool_pda(&mint); + let spl_interface_pda = get_spl_interface_pda(&mint); let config = TokenAccountsMetaConfig::compress_client( - token_pool_pda, + spl_interface_pda, token_account, SPL_TOKEN_PROGRAM_ID.into(), ); @@ -394,9 +394,9 @@ async fn decompress_compressed_tokens( decompress_token_account: Pubkey, ) -> Result { let mut remaining_accounts = PackedAccounts::default(); - let token_pool_pda = get_token_pool_pda(&compressed_account.token.mint); + let spl_interface_pda = get_spl_interface_pda(&compressed_account.token.mint); let config = TokenAccountsMetaConfig::decompress_client( - token_pool_pda, + spl_interface_pda, decompress_token_account, SPL_TOKEN_PROGRAM_ID.into(), ); @@ -580,12 +580,13 @@ async fn batch_compress_spl_tokens( ) -> Result { let mut remaining_accounts = PackedAccounts::default(); remaining_accounts.add_pre_accounts_signer_mut(payer.pubkey()); - let token_pool_index = 0; - let (token_pool_pda, token_pool_bump) = find_token_pool_pda_with_index(&mint, token_pool_index); - println!("token_pool_pda {:?}", token_pool_pda); + let spl_interface_index = 0; + let (spl_interface_pda, spl_interface_bump) = + find_spl_interface_pda_with_index(&mint, spl_interface_index); + println!("spl_interface_pda {:?}", spl_interface_pda); // Use batch compress account metas let config = BatchCompressMetaConfig::new_client( - token_pool_pda, + spl_interface_pda, token_account, SPL_TOKEN_PROGRAM_ID.into(), rpc.get_random_state_tree_info().unwrap().queue, @@ -603,8 +604,8 @@ async fn batch_compress_spl_tokens( accounts, data: sdk_token_test::instruction::BatchCompressTokens { recipients, - token_pool_index, - token_pool_bump, + token_pool_index: spl_interface_index, + token_pool_bump: spl_interface_bump, } .data(), }; diff --git a/sdk-tests/sdk-token-test/tests/test_4_invocations.rs b/sdk-tests/sdk-token-test/tests/test_4_invocations.rs index 9e186f4cc6..abc399b4d1 100644 --- a/sdk-tests/sdk-token-test/tests/test_4_invocations.rs +++ b/sdk-tests/sdk-token-test/tests/test_4_invocations.rs @@ -3,7 +3,7 @@ use light_ctoken_sdk::{ compressed_token::transfer::account_metas::{ get_transfer_instruction_account_metas, TokenAccountsMetaConfig, }, - token_pool::get_token_pool_pda, + spl_interface::get_spl_interface_pda, utils::CTokenDefaultAccounts, SPL_TOKEN_PROGRAM_ID, }; @@ -259,9 +259,9 @@ async fn compress_spl_tokens( token_account: Pubkey, ) -> Result { let mut remaining_accounts = PackedAccounts::default(); - let token_pool_pda = get_token_pool_pda(&mint); + let spl_interface_pda = get_spl_interface_pda(&mint); let config = TokenAccountsMetaConfig::compress_client( - token_pool_pda, + spl_interface_pda, token_account, SPL_TOKEN_PROGRAM_ID.into(), ); @@ -427,11 +427,11 @@ async fn test_four_invokes_instruction( ) -> Result<(), RpcError> { let default_pubkeys = CTokenDefaultAccounts::default(); let mut remaining_accounts = PackedAccounts::default(); - let token_pool_pda1 = get_token_pool_pda(&mint1); + let spl_interface_pda1 = get_spl_interface_pda(&mint1); // Remaining accounts 0 remaining_accounts.add_pre_accounts_meta(AccountMeta::new(compression_token_account, false)); // Remaining accounts 1 - remaining_accounts.add_pre_accounts_meta(AccountMeta::new(token_pool_pda1, false)); + remaining_accounts.add_pre_accounts_meta(AccountMeta::new(spl_interface_pda1, false)); // Remaining accounts 2 remaining_accounts.add_pre_accounts_meta(AccountMeta::new(SPL_TOKEN_PROGRAM_ID.into(), false)); // Remaining accounts 3 diff --git a/sdk-tests/sdk-token-test/tests/test_4_transfer2.rs b/sdk-tests/sdk-token-test/tests/test_4_transfer2.rs index 0dfa9dec3c..94ba96ef77 100644 --- a/sdk-tests/sdk-token-test/tests/test_4_transfer2.rs +++ b/sdk-tests/sdk-token-test/tests/test_4_transfer2.rs @@ -267,7 +267,7 @@ async fn mint_compressed_tokens( output_queue_tokens: output_queue, decompressed_mint_config: None, token_account_version: 2, - token_pool: None, + spl_interface_pda: None, }, None, ) diff --git a/sdk-tests/sdk-token-test/tests/test_compress_full_and_close.rs b/sdk-tests/sdk-token-test/tests/test_compress_full_and_close.rs index 4a1e65feb9..e17277ad57 100644 --- a/sdk-tests/sdk-token-test/tests/test_compress_full_and_close.rs +++ b/sdk-tests/sdk-token-test/tests/test_compress_full_and_close.rs @@ -153,7 +153,7 @@ async fn test_compress_full_and_close() { output_queue_tokens: compressed_mint_account.tree_info.queue, decompressed_mint_config: None, token_account_version: 2, - token_pool: None, + spl_interface_pda: None, }, None, ) diff --git a/sdk-tests/sdk-token-test/tests/test_deposit.rs b/sdk-tests/sdk-token-test/tests/test_deposit.rs index 186d0c53d1..7f0d2f945a 100644 --- a/sdk-tests/sdk-token-test/tests/test_deposit.rs +++ b/sdk-tests/sdk-token-test/tests/test_deposit.rs @@ -4,7 +4,7 @@ use light_ctoken_sdk::{ compressed_token::batch_compress::{ get_batch_compress_instruction_account_metas, BatchCompressMetaConfig, Recipient, }, - token_pool::find_token_pool_pda_with_index, + spl_interface::find_spl_interface_pda_with_index, utils::CTokenDefaultAccounts, TokenAccountMeta, SPL_TOKEN_PROGRAM_ID, }; @@ -446,13 +446,14 @@ async fn batch_compress_spl_tokens( let token_account = token_account_keypair.pubkey(); let mut remaining_accounts = PackedAccounts::default(); remaining_accounts.add_pre_accounts_signer_mut(payer.pubkey()); - let token_pool_index = 0; - let (token_pool_pda, token_pool_bump) = find_token_pool_pda_with_index(&mint, token_pool_index); - println!("token_pool_pda {:?}", token_pool_pda); + let spl_interface_index = 0; + let (spl_interface_pda, spl_interface_bump) = + find_spl_interface_pda_with_index(&mint, spl_interface_index); + println!("spl_interface_pda {:?}", spl_interface_pda); // Use batch compress account metas let config = BatchCompressMetaConfig::new_client( - token_pool_pda, + spl_interface_pda, token_account, SPL_TOKEN_PROGRAM_ID.into(), rpc.get_random_state_tree_info().unwrap().queue, @@ -470,8 +471,8 @@ async fn batch_compress_spl_tokens( accounts, data: sdk_token_test::instruction::BatchCompressTokens { recipients, - token_pool_index, - token_pool_bump, + token_pool_index: spl_interface_index, + token_pool_bump: spl_interface_bump, } .data(), };