diff --git a/Cargo.lock b/Cargo.lock index efdb049dff..b9026ce300 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1427,6 +1427,7 @@ dependencies = [ "light-client", "light-compressed-account", "light-compressed-token", + "light-compressed-token-types", "light-compressible", "light-ctoken-interface", "light-ctoken-sdk", @@ -6158,6 +6159,7 @@ dependencies = [ "light-batched-merkle-tree", "light-client", "light-compressed-account", + "light-compressed-token-types", "light-compressible", "light-ctoken-interface", "light-ctoken-sdk", diff --git a/forester-utils/src/instructions/claim.rs b/forester-utils/src/instructions/claim.rs index 71ffdceee7..fa437ac387 100644 --- a/forester-utils/src/instructions/claim.rs +++ b/forester-utils/src/instructions/claim.rs @@ -1,4 +1,4 @@ -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use solana_instruction::{AccountMeta, Instruction}; use solana_pubkey::Pubkey; @@ -13,7 +13,7 @@ use solana_pubkey::Pubkey; pub fn derive_pool_pda(compression_authority: &Pubkey) -> (Pubkey, u8) { Pubkey::find_program_address( &[b"pool", compression_authority.as_ref()], - &Pubkey::from(COMPRESSED_TOKEN_PROGRAM_ID), + &Pubkey::from(CTOKEN_PROGRAM_ID), ) } @@ -49,7 +49,7 @@ pub fn claim( } Instruction { - program_id: Pubkey::from(COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::from(CTOKEN_PROGRAM_ID), accounts, data: instruction_data, } diff --git a/forester-utils/src/instructions/withdraw_funding_pool.rs b/forester-utils/src/instructions/withdraw_funding_pool.rs index 990c5dbce8..8701fde3f0 100644 --- a/forester-utils/src/instructions/withdraw_funding_pool.rs +++ b/forester-utils/src/instructions/withdraw_funding_pool.rs @@ -1,4 +1,4 @@ -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use solana_instruction::{AccountMeta, Instruction}; use solana_pubkey::Pubkey; @@ -37,7 +37,7 @@ pub fn withdraw_funding_pool( ]; Instruction { - program_id: Pubkey::from(COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::from(CTOKEN_PROGRAM_ID), accounts, data: instruction_data, } diff --git a/forester/src/compressible/bootstrap.rs b/forester/src/compressible/bootstrap.rs index 85e70c5ef2..8d3216c50e 100644 --- a/forester/src/compressible/bootstrap.rs +++ b/forester/src/compressible/bootstrap.rs @@ -4,7 +4,7 @@ use base64::{engine::general_purpose, Engine as _}; use borsh::BorshDeserialize; use light_ctoken_interface::{ state::{extensions::ExtensionStruct, CToken}, - COMPRESSED_TOKEN_PROGRAM_ID, COMPRESSIBLE_TOKEN_ACCOUNT_SIZE, + COMPRESSIBLE_TOKEN_ACCOUNT_SIZE, CTOKEN_PROGRAM_ID, }; use serde_json::json; use solana_sdk::pubkey::Pubkey; @@ -191,7 +191,7 @@ async fn bootstrap_with_v2_api( mut shutdown_rx: oneshot::Receiver<()>, ) -> Result<()> { let client = reqwest::Client::new(); - let program_id = Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID); + let program_id = Pubkey::new_from_array(CTOKEN_PROGRAM_ID); let mut total_fetched = 0; let mut total_inserted = 0; @@ -314,7 +314,7 @@ async fn bootstrap_with_standard_api( mut shutdown_rx: oneshot::Receiver<()>, ) -> Result<()> { let client = reqwest::Client::new(); - let program_id = Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID); + let program_id = Pubkey::new_from_array(CTOKEN_PROGRAM_ID); let payload = json!({ "jsonrpc": "2.0", diff --git a/forester/src/compressible/compressor.rs b/forester/src/compressible/compressor.rs index 8f8d9e7c2f..2c75b65765 100644 --- a/forester/src/compressible/compressor.rs +++ b/forester/src/compressible/compressor.rs @@ -4,7 +4,7 @@ use anchor_lang::{InstructionData, ToAccountMetas}; use forester_utils::rpc_pool::SolanaRpcPool; use light_client::rpc::Rpc; use light_compressible::config::CompressibleConfig; -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use light_ctoken_sdk::compressed_token::compress_and_close::CompressAndCloseAccounts as CTokenAccounts; use light_registry::{ accounts::CompressAndCloseContext, compressible::compressed_token::CompressAndCloseIndices, @@ -60,7 +60,7 @@ impl Compressor { registered_forester_pda: Pubkey, ) -> Result { let registry_program_id = Pubkey::from_str(REGISTRY_PROGRAM_ID_STR)?; - let compressed_token_program_id = Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID); + let compressed_token_program_id = Pubkey::new_from_array(CTOKEN_PROGRAM_ID); // Derive compression_authority PDA deterministically (version = 1) let compression_authority_seeds = CompressibleConfig::get_compression_authority_seeds(1); diff --git a/forester/src/compressible/subscriber.rs b/forester/src/compressible/subscriber.rs index 68f87ec181..ccfd57b657 100644 --- a/forester/src/compressible/subscriber.rs +++ b/forester/src/compressible/subscriber.rs @@ -1,7 +1,7 @@ use std::{str::FromStr, sync::Arc}; use futures::StreamExt; -use light_ctoken_interface::{COMPRESSED_TOKEN_PROGRAM_ID, COMPRESSIBLE_TOKEN_ACCOUNT_SIZE}; +use light_ctoken_interface::{COMPRESSIBLE_TOKEN_ACCOUNT_SIZE, CTOKEN_PROGRAM_ID}; use solana_account_decoder::UiAccountEncoding; use solana_client::{ nonblocking::pubsub_client::PubsubClient, @@ -44,7 +44,7 @@ impl AccountSubscriber { .await .map_err(|e| anyhow::anyhow!("Failed to connect to WebSocket: {}", e))?; - let program_id = Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID); + let program_id = Pubkey::new_from_array(CTOKEN_PROGRAM_ID); // Subscribe to compressed token program accounts with filter for compressible account size let (mut subscription, unsubscribe) = pubsub_client diff --git a/forester/tests/test_compressible_ctoken.rs b/forester/tests/test_compressible_ctoken.rs index a09f9ba677..c2a9fb2d7a 100644 --- a/forester/tests/test_compressible_ctoken.rs +++ b/forester/tests/test_compressible_ctoken.rs @@ -218,7 +218,7 @@ async fn test_compressible_ctoken_compression() { // Create mint let mint_seed = Keypair::new(); let address_tree = rpc.get_address_tree_v2().tree; - let mint = Pubkey::from(create_compressed_mint::derive_compressed_mint_address( + let mint = Pubkey::from(create_compressed_mint::derive_cmint_compressed_address( &mint_seed.pubkey(), &address_tree, )); @@ -369,7 +369,7 @@ async fn test_compressible_ctoken_bootstrap() { // Create mint let mint_seed = Keypair::new(); let address_tree = rpc.get_address_tree_v2().tree; - let mint = Pubkey::from(create_compressed_mint::derive_compressed_mint_address( + let mint = Pubkey::from(create_compressed_mint::derive_cmint_compressed_address( &mint_seed.pubkey(), &address_tree, )); diff --git a/program-libs/ctoken-interface/src/constants.rs b/program-libs/ctoken-interface/src/constants.rs index aa882f7121..cd6d438630 100644 --- a/program-libs/ctoken-interface/src/constants.rs +++ b/program-libs/ctoken-interface/src/constants.rs @@ -3,7 +3,7 @@ use light_macros::pubkey_array; use crate::state::CompressionInfo; pub const CPI_AUTHORITY: [u8; 32] = pubkey_array!("GXtd2izAiMJPwMEjfgTRH3d7k9mjn4Jq3JrWFv9gySYy"); -pub const COMPRESSED_TOKEN_PROGRAM_ID: [u8; 32] = +pub const CTOKEN_PROGRAM_ID: [u8; 32] = pubkey_array!("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"); /// Account size constants diff --git a/program-tests/compressed-token-test/Cargo.toml b/program-tests/compressed-token-test/Cargo.toml index 35cb20191b..acfbb7e6f7 100644 --- a/program-tests/compressed-token-test/Cargo.toml +++ b/program-tests/compressed-token-test/Cargo.toml @@ -50,3 +50,4 @@ light-ctoken-sdk = { workspace = true } spl-token-2022 = { workspace = true } spl-pod = { workspace = true } light-zero-copy = { workspace = true , features = ["std", "derive", "mut"]} +light-compressed-token-types = { workspace = true } diff --git a/program-tests/compressed-token-test/tests/ctoken/functional.rs b/program-tests/compressed-token-test/tests/ctoken/functional.rs index 93eebc13c6..af4d0d253c 100644 --- a/program-tests/compressed-token-test/tests/ctoken/functional.rs +++ b/program-tests/compressed-token-test/tests/ctoken/functional.rs @@ -65,7 +65,7 @@ async fn test_spl_sdk_compatible_account_lifecycle() -> Result<(), RpcError> { let destination_pubkey = destination_keypair.pubkey(); // Close account using SPL SDK compatible instruction - let close_account_ix = CloseAccount::new( + let close_account_ix = CloseCTokenAccount::new( light_compressed_token::ID, token_account_pubkey, destination_pubkey, @@ -272,7 +272,7 @@ async fn test_compressible_account_with_compression_authority_lifecycle() { .unwrap(); // Close compressible account using owner - let close_account_ix = CloseAccount::new( + let close_account_ix = CloseCTokenAccount::new( light_compressed_token::ID, token_account_pubkey, destination.pubkey(), // destination for user funds diff --git a/program-tests/compressed-token-test/tests/ctoken/functional_ata.rs b/program-tests/compressed-token-test/tests/ctoken/functional_ata.rs index 13315a313a..40b1335444 100644 --- a/program-tests/compressed-token-test/tests/ctoken/functional_ata.rs +++ b/program-tests/compressed-token-test/tests/ctoken/functional_ata.rs @@ -1,4 +1,6 @@ -use light_ctoken_sdk::ctoken::{CloseAccount, CompressibleParams, CreateAssociatedTokenAccount}; +use light_ctoken_sdk::ctoken::{ + CloseCTokenAccount, CompressibleParams, CreateAssociatedTokenAccount, +}; use light_test_utils::assert_create_token_account::assert_create_associated_token_account; use super::shared::*; @@ -111,7 +113,7 @@ async fn test_associated_token_account_operations() { .unwrap(); // Close compressible ATA - let close_account_ix = CloseAccount::new( + let close_account_ix = CloseCTokenAccount::new( light_compressed_token::ID, compressible_ata_pubkey, destination.pubkey(), // destination for user funds diff --git a/program-tests/compressed-token-test/tests/ctoken/shared.rs b/program-tests/compressed-token-test/tests/ctoken/shared.rs index f1b8c8bc7c..7c3772e41b 100644 --- a/program-tests/compressed-token-test/tests/ctoken/shared.rs +++ b/program-tests/compressed-token-test/tests/ctoken/shared.rs @@ -2,7 +2,7 @@ pub use light_compressible::rent::{RentConfig, SLOTS_PER_EPOCH}; pub use light_ctoken_interface::COMPRESSIBLE_TOKEN_ACCOUNT_SIZE; pub use light_ctoken_sdk::ctoken::{ - derive_ctoken_ata, CloseAccount, CompressibleParams, CreateAssociatedTokenAccount, + derive_ctoken_ata, CloseCTokenAccount, CompressibleParams, CreateAssociatedTokenAccount, CreateCTokenAccount, }; pub use light_program_test::{ @@ -320,7 +320,7 @@ pub async fn close_and_assert_token_account( panic!("Compressible account must have compressible extension"); }; - CloseAccount { + CloseCTokenAccount { token_program: light_compressed_token::ID, account: token_account_pubkey, destination, @@ -330,7 +330,7 @@ pub async fn close_and_assert_token_account( .instruction() .unwrap() } else { - CloseAccount { + CloseCTokenAccount { token_program: light_compressed_token::ID, account: token_account_pubkey, destination, @@ -378,7 +378,7 @@ pub async fn close_and_assert_token_account_fails( let payer_pubkey = context.payer.pubkey(); let token_account_pubkey = context.token_account_keypair.pubkey(); - let close_ix = CloseAccount { + let close_ix = CloseCTokenAccount { token_program: light_compressed_token::ID, account: token_account_pubkey, destination, diff --git a/program-tests/compressed-token-test/tests/mint/cpi_context.rs b/program-tests/compressed-token-test/tests/mint/cpi_context.rs index cdf4e9bffe..d173b489de 100644 --- a/program-tests/compressed-token-test/tests/mint/cpi_context.rs +++ b/program-tests/compressed-token-test/tests/mint/cpi_context.rs @@ -8,10 +8,10 @@ use light_ctoken_interface::{ MintActionCompressedInstructionData, }, state::CompressedMintMetadata, - CMINT_ADDRESS_TREE, COMPRESSED_TOKEN_PROGRAM_ID, + CMINT_ADDRESS_TREE, CTOKEN_PROGRAM_ID, }; use light_ctoken_sdk::compressed_token::{ - create_compressed_mint::{derive_compressed_mint_address, find_spl_mint_address}, + create_compressed_mint::{derive_cmint_compressed_address, find_cmint_address}, mint_action::{ get_mint_action_instruction_account_metas_cpi_write, MintActionMetaConfig, MintActionMetaConfigCpiWrite, @@ -67,8 +67,8 @@ async fn test_setup() -> TestSetup { // Derive addresses let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree); - let (spl_mint_pda, _) = find_spl_mint_address(&mint_seed.pubkey()); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree); + let (spl_mint_pda, _) = find_cmint_address(&mint_seed.pubkey()); // 3. Build compressed mint inputs let compressed_mint_inputs = CompressedMintWithContext { @@ -158,7 +158,7 @@ async fn test_write_to_cpi_context_create_mint() { // Build compressed token instruction let ctoken_instruction = Instruction { - program_id: Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(CTOKEN_PROGRAM_ID), accounts: account_metas, data: data.clone(), }; @@ -170,7 +170,7 @@ async fn test_write_to_cpi_context_create_mint() { let wrapper_instruction = Instruction { program_id: WRAPPER_PROGRAM_ID, accounts: vec![AccountMeta::new_readonly( - Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + Pubkey::new_from_array(CTOKEN_PROGRAM_ID), false, )] .into_iter() @@ -279,7 +279,7 @@ async fn test_write_to_cpi_context_invalid_address_tree() { // Build compressed token instruction let ctoken_instruction = Instruction { - program_id: Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(CTOKEN_PROGRAM_ID), accounts: account_metas, data: data.clone(), }; @@ -291,7 +291,7 @@ async fn test_write_to_cpi_context_invalid_address_tree() { let wrapper_instruction = Instruction { program_id: WRAPPER_PROGRAM_ID, accounts: vec![AccountMeta::new_readonly( - Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + Pubkey::new_from_array(CTOKEN_PROGRAM_ID), false, )] .into_iter() @@ -371,7 +371,7 @@ async fn test_write_to_cpi_context_invalid_compressed_address() { // Build compressed token instruction let ctoken_instruction = Instruction { - program_id: Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(CTOKEN_PROGRAM_ID), accounts: account_metas, data: data.clone(), }; @@ -383,7 +383,7 @@ async fn test_write_to_cpi_context_invalid_compressed_address() { let wrapper_instruction = Instruction { program_id: WRAPPER_PROGRAM_ID, accounts: vec![AccountMeta::new_readonly( - Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + Pubkey::new_from_array(CTOKEN_PROGRAM_ID), false, )] .into_iter() @@ -466,7 +466,7 @@ async fn test_execute_cpi_context_invalid_tree_index() { // Build compressed token instruction let execute_instruction = Instruction { - program_id: Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(CTOKEN_PROGRAM_ID), accounts: account_metas, data: data.clone(), }; @@ -478,7 +478,7 @@ async fn test_execute_cpi_context_invalid_tree_index() { let execute_wrapper_instruction = Instruction { program_id: WRAPPER_PROGRAM_ID, accounts: vec![AccountMeta::new_readonly( - Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + Pubkey::new_from_array(CTOKEN_PROGRAM_ID), false, )] .into_iter() diff --git a/program-tests/compressed-token-test/tests/mint/edge_cases.rs b/program-tests/compressed-token-test/tests/mint/edge_cases.rs index 146f298082..b7d3b8f9aa 100644 --- a/program-tests/compressed-token-test/tests/mint/edge_cases.rs +++ b/program-tests/compressed-token-test/tests/mint/edge_cases.rs @@ -5,7 +5,7 @@ use light_ctoken_interface::state::{ }; use light_ctoken_sdk::{ compressed_token::create_compressed_mint::{ - derive_compressed_mint_address, find_spl_mint_address, + derive_cmint_compressed_address, find_cmint_address, }, ctoken::{CompressibleParams, CreateAssociatedTokenAccount}, }; @@ -46,10 +46,10 @@ async fn functional_all_in_one_instruction() { let address_tree_pubkey = rpc.get_address_tree_v2().tree; // Derive compressed mint address for verification let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); // Find mint PDA for the rest of the test - let (spl_mint_pda, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (spl_mint_pda, _) = find_cmint_address(&mint_seed.pubkey()); // 1. Create compressed mint with both authorities { create_mint( diff --git a/program-tests/compressed-token-test/tests/mint/failing.rs b/program-tests/compressed-token-test/tests/mint/failing.rs index 7ccca2ebbd..aafeac810d 100644 --- a/program-tests/compressed-token-test/tests/mint/failing.rs +++ b/program-tests/compressed-token-test/tests/mint/failing.rs @@ -5,7 +5,7 @@ use light_client::indexer::Indexer; use light_ctoken_interface::state::{extensions::AdditionalMetadata, CompressedMint}; use light_ctoken_sdk::{ compressed_token::create_compressed_mint::{ - derive_compressed_mint_address, find_spl_mint_address, + derive_cmint_compressed_address, find_cmint_address, }, ctoken::{CompressibleParams, CreateAssociatedTokenAccount}, }; @@ -60,10 +60,10 @@ async fn functional_and_failing_tests() { let address_tree_pubkey = rpc.get_address_tree_v2().tree; // Derive compressed mint address for verification let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); // Find mint PDA for the rest of the test - let (spl_mint_pda, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (spl_mint_pda, _) = find_cmint_address(&mint_seed.pubkey()); // 1. Create compressed mint with both authorities { create_mint( @@ -816,10 +816,10 @@ async fn test_mint_to_ctoken_max_top_up_exceeded() { CompressedMintWithContext, MintActionCompressedInstructionData, MintToCTokenAction, }, state::TokenDataVersion, - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, }; use light_ctoken_sdk::compressed_token::{ - create_compressed_mint::derive_compressed_mint_address, mint_action::MintActionMetaConfig, + create_compressed_mint::derive_cmint_compressed_address, mint_action::MintActionMetaConfig, }; let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2(false, None)) @@ -839,8 +839,8 @@ async fn test_mint_to_ctoken_max_top_up_exceeded() { let address_tree_pubkey = rpc.get_address_tree_v2().tree; let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); - let (spl_mint_pda, _) = find_spl_mint_address(&mint_seed.pubkey()); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); + let (spl_mint_pda, _) = find_cmint_address(&mint_seed.pubkey()); // 1. Create compressed mint light_token_client::actions::create_mint( @@ -942,7 +942,7 @@ async fn test_mint_to_ctoken_max_top_up_exceeded() { // Build final instruction let ix = Instruction { - program_id: COMPRESSED_TOKEN_PROGRAM_ID.into(), + program_id: CTOKEN_PROGRAM_ID.into(), accounts: account_metas, data, }; diff --git a/program-tests/compressed-token-test/tests/mint/functional.rs b/program-tests/compressed-token-test/tests/mint/functional.rs index 87638ec018..9c2bcb573b 100644 --- a/program-tests/compressed-token-test/tests/mint/functional.rs +++ b/program-tests/compressed-token-test/tests/mint/functional.rs @@ -12,7 +12,7 @@ use light_ctoken_interface::{ }; use light_ctoken_sdk::{ compressed_token::create_compressed_mint::{ - derive_compressed_mint_address, find_spl_mint_address, + derive_cmint_compressed_address, find_cmint_address, }, ctoken::{derive_ctoken_ata, CompressibleParams, CreateAssociatedTokenAccount}, }; @@ -63,10 +63,10 @@ async fn test_create_compressed_mint() { let mint_seed = Keypair::new(); // Derive compressed mint address for verification let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); // Find mint PDA for the rest of the test - let (spl_mint_pda, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (spl_mint_pda, _) = find_cmint_address(&mint_seed.pubkey()); // 1. Create compressed mint (no metadata) { @@ -565,7 +565,7 @@ async fn test_update_compressed_mint_authority() { // Get the compressed mint address and info let address_tree_pubkey = rpc.get_address_tree_v2().tree; let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); // Get compressed mint account from indexer let compressed_mint_account = rpc @@ -636,7 +636,7 @@ async fn test_update_compressed_mint_authority() { // Note: We need to get fresh account info after the updates let updated_compressed_accounts = rpc .get_compressed_accounts_by_owner( - &Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + &Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID), None, None, ) @@ -696,7 +696,7 @@ async fn test_ctoken_transfer() { .unwrap(); // Derive addresses - let (spl_mint_pda, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (spl_mint_pda, _) = find_cmint_address(&mint_seed.pubkey()); // Create compressed token ATA for recipient let (recipient_ata, _) = derive_ctoken_ata(&recipient_keypair.pubkey(), &spl_mint_pda); @@ -1052,7 +1052,7 @@ async fn test_create_compressed_mint_with_token_metadata() { &light_compressed_token::ID, ); let compressed_mint_address = - light_ctoken_sdk::compressed_token::create_compressed_mint::derive_compressed_mint_address( + light_ctoken_sdk::compressed_token::create_compressed_mint::derive_cmint_compressed_address( &mint_seed.pubkey(), &address_tree_pubkey, ); @@ -1173,8 +1173,8 @@ async fn test_mint_actions() { // Derive addresses let address_tree_pubkey = rpc.get_address_tree_v2().tree; let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); - let (spl_mint_pda, _) = find_spl_mint_address(&mint_seed.pubkey()); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); + let (spl_mint_pda, _) = find_cmint_address(&mint_seed.pubkey()); rpc.context.warp_to_slot(1); // === SINGLE MINT ACTION INSTRUCTION === // Execute ONE instruction with ALL actions diff --git a/program-tests/compressed-token-test/tests/mint/random.rs b/program-tests/compressed-token-test/tests/mint/random.rs index e2e86a62d1..6874071ab7 100644 --- a/program-tests/compressed-token-test/tests/mint/random.rs +++ b/program-tests/compressed-token-test/tests/mint/random.rs @@ -4,7 +4,7 @@ use light_client::indexer::Indexer; use light_ctoken_interface::state::{extensions::AdditionalMetadata, CompressedMint}; use light_ctoken_sdk::{ compressed_token::create_compressed_mint::{ - derive_compressed_mint_address, find_spl_mint_address, + derive_cmint_compressed_address, find_cmint_address, }, ctoken::CreateAssociatedTokenAccount, }; @@ -67,10 +67,10 @@ async fn test_random_mint_action() { let address_tree_pubkey = rpc.get_address_tree_v2().tree; // Derive compressed mint address for verification let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); // Find mint PDA for the rest of the test - let (spl_mint_pda, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (spl_mint_pda, _) = find_cmint_address(&mint_seed.pubkey()); // Fund authority first rpc.airdrop_lamports(&authority.pubkey(), 10_000_000_000) diff --git a/program-tests/compressed-token-test/tests/transfer2/compress_failing.rs b/program-tests/compressed-token-test/tests/transfer2/compress_failing.rs index 8752e4ffa9..515d5de4bd 100644 --- a/program-tests/compressed-token-test/tests/transfer2/compress_failing.rs +++ b/program-tests/compressed-token-test/tests/transfer2/compress_failing.rs @@ -38,7 +38,7 @@ use light_ctoken_interface::{instructions::mint_action::Recipient, state::TokenDataVersion}; use light_ctoken_sdk::{ compressed_token::{ - create_compressed_mint::find_spl_mint_address, + create_compressed_mint::find_cmint_address, transfer2::{ account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, Transfer2Config, Transfer2Inputs, @@ -84,7 +84,7 @@ async fn setup_compression_test(token_amount: u64) -> Result Result<(), RpcError> { let mint_seed = Keypair::new(); // Derive mint and ATA addresses - let (mint, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (mint, _) = find_cmint_address(&mint_seed.pubkey()); let (ctoken_ata, _) = derive_ctoken_ata(&owner.pubkey(), &mint); // Create compressible CToken ATA with pre_pay_num_epochs = 0 (NO prepaid rent) diff --git a/program-tests/compressed-token-test/tests/transfer2/decompress_failing.rs b/program-tests/compressed-token-test/tests/transfer2/decompress_failing.rs index d72d8324eb..ac89b2df0a 100644 --- a/program-tests/compressed-token-test/tests/transfer2/decompress_failing.rs +++ b/program-tests/compressed-token-test/tests/transfer2/decompress_failing.rs @@ -38,7 +38,7 @@ use light_ctoken_interface::{ }; use light_ctoken_sdk::{ compressed_token::{ - create_compressed_mint::find_spl_mint_address, + create_compressed_mint::find_cmint_address, transfer2::{ account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, Transfer2Config, Transfer2Inputs, @@ -88,7 +88,7 @@ async fn setup_decompression_test( let mint_seed = Keypair::new(); // Derive mint and ATA addresses - let (mint, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (mint, _) = find_cmint_address(&mint_seed.pubkey()); let (ctoken_ata, _) = derive_ctoken_ata(&owner.pubkey(), &mint); // Create compressible CToken ATA for owner (recipient of decompression) diff --git a/program-tests/compressed-token-test/tests/transfer2/no_system_program_cpi_failing.rs b/program-tests/compressed-token-test/tests/transfer2/no_system_program_cpi_failing.rs index ecea653e0c..20e024726c 100644 --- a/program-tests/compressed-token-test/tests/transfer2/no_system_program_cpi_failing.rs +++ b/program-tests/compressed-token-test/tests/transfer2/no_system_program_cpi_failing.rs @@ -45,7 +45,7 @@ use light_ctoken_interface::instructions::{mint_action::Recipient, transfer2::Compression}; use light_ctoken_sdk::{ - compressed_token::create_compressed_mint::find_spl_mint_address, + compressed_token::create_compressed_mint::find_cmint_address, ctoken::{derive_ctoken_ata, CreateAssociatedTokenAccount}, ValidityProof, }; @@ -101,7 +101,7 @@ async fn setup_no_system_program_cpi_test( // Create compressed mint seed let mint_seed = Keypair::new(); - let (mint, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (mint, _) = find_cmint_address(&mint_seed.pubkey()); let (source_ata, _) = derive_ctoken_ata(&owner.pubkey(), &mint); let (recipient_ata, _) = derive_ctoken_ata(&recipient.pubkey(), &mint); @@ -227,8 +227,8 @@ fn build_compressions_only_instruction( packed_account_metas: Vec, ) -> Result { use anchor_lang::AnchorSerialize; + use light_compressed_token_types::{CPI_AUTHORITY_PDA, TRANSFER2}; use light_ctoken_interface::instructions::transfer2::CompressedTokenInstructionDataTransfer2; - use light_ctoken_sdk::constants::{CPI_AUTHORITY_PDA, TRANSFER2}; use solana_sdk::instruction::AccountMeta; // For compressions-only mode (decompressed_accounts_only), the account order is: @@ -271,7 +271,7 @@ fn build_compressions_only_instruction( data.extend(serialized); Ok(solana_sdk::instruction::Instruction { - program_id: light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID.into(), + program_id: light_ctoken_interface::CTOKEN_PROGRAM_ID.into(), accounts: account_metas, data, }) @@ -704,7 +704,7 @@ async fn test_too_many_mints() { for _ in 0..5 { // Create new mint seed let mint_seed = Keypair::new(); - let (mint, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (mint, _) = find_cmint_address(&mint_seed.pubkey()); let (source_ata, _) = derive_ctoken_ata(&context.owner.pubkey(), &mint); let (recipient_ata, _) = derive_ctoken_ata(&context.recipient.pubkey(), &mint); diff --git a/program-tests/compressed-token-test/tests/transfer2/shared.rs b/program-tests/compressed-token-test/tests/transfer2/shared.rs index 1b072158bd..76d3592041 100644 --- a/program-tests/compressed-token-test/tests/transfer2/shared.rs +++ b/program-tests/compressed-token-test/tests/transfer2/shared.rs @@ -7,7 +7,7 @@ use light_ctoken_interface::{ state::TokenDataVersion, }; use light_ctoken_sdk::{ - compressed_token::create_compressed_mint::find_spl_mint_address, + compressed_token::create_compressed_mint::find_cmint_address, ctoken::{CompressibleParams, CreateAssociatedTokenAccount}, }; use light_program_test::{indexer::TestIndexerExtensions, LightProgramTest, ProgramTestConfig}; @@ -318,7 +318,7 @@ impl TestContext { } else { // Create compressed mint for CToken operations let mint_seed = Keypair::new(); - let (mint, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (mint, _) = find_cmint_address(&mint_seed.pubkey()); create_mint( &mut rpc, @@ -492,7 +492,7 @@ impl TestContext { // Get the compressed mint address let address_tree_pubkey = rpc.get_address_tree_v2().tree; let compressed_mint_address = - light_ctoken_sdk::compressed_token::create_compressed_mint::derive_compressed_mint_address( + light_ctoken_sdk::compressed_token::create_compressed_mint::derive_cmint_compressed_address( &mint_seed.pubkey(), &address_tree_pubkey, ); diff --git a/program-tests/compressed-token-test/tests/transfer2/transfer_failing.rs b/program-tests/compressed-token-test/tests/transfer2/transfer_failing.rs index e9cedd1e10..297bf69855 100644 --- a/program-tests/compressed-token-test/tests/transfer2/transfer_failing.rs +++ b/program-tests/compressed-token-test/tests/transfer2/transfer_failing.rs @@ -72,7 +72,7 @@ async fn setup_transfer_test( ) .await?; - let mint = light_ctoken_sdk::compressed_token::create_compressed_mint::find_spl_mint_address( + let mint = light_ctoken_sdk::compressed_token::create_compressed_mint::find_cmint_address( &mint_seed.pubkey(), ) .0; @@ -682,7 +682,7 @@ async fn setup_transfer_test_with_delegate( ) .await?; - let mint = light_ctoken_sdk::compressed_token::create_compressed_mint::find_spl_mint_address( + let mint = light_ctoken_sdk::compressed_token::create_compressed_mint::find_cmint_address( &mint_seed.pubkey(), ) .0; diff --git a/program-tests/utils/src/assert_mint_to_compressed.rs b/program-tests/utils/src/assert_mint_to_compressed.rs index 51c93431a0..a637a3b238 100644 --- a/program-tests/utils/src/assert_mint_to_compressed.rs +++ b/program-tests/utils/src/assert_mint_to_compressed.rs @@ -6,7 +6,7 @@ use light_client::{ }; use light_compressed_token::instructions::create_token_pool::find_token_pool_pda_with_index; use light_ctoken_interface::{ - instructions::mint_action::Recipient, state::CompressedMint, COMPRESSED_TOKEN_PROGRAM_ID, + instructions::mint_action::Recipient, state::CompressedMint, CTOKEN_PROGRAM_ID, }; use light_ctoken_sdk::compressed_token::create_compressed_mint::derive_cmint_from_spl_mint; use solana_sdk::{program_pack::Pack, pubkey::Pubkey}; @@ -67,7 +67,7 @@ pub async fn assert_mint_to_compressed( ); assert_eq!( matching_account.account.owner.to_bytes(), - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, "Recipient token account should have correct program owner" ); diff --git a/program-tests/utils/src/assert_transfer2.rs b/program-tests/utils/src/assert_transfer2.rs index 5ec212147a..e276d9abdc 100644 --- a/program-tests/utils/src/assert_transfer2.rs +++ b/program-tests/utils/src/assert_transfer2.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use anchor_spl::token_2022::spl_token_2022; use light_client::{indexer::Indexer, rpc::Rpc}; -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use light_program_test::LightProgramTest; use light_token_client::instructions::transfer2::{ CompressInput, DecompressInput, Transfer2InstructionType, TransferInput, @@ -107,8 +107,7 @@ pub async fn assert_transfer2_with_delegate( assert!( recipient_accounts .iter() - .any(|account| account.account.owner.to_bytes() - == COMPRESSED_TOKEN_PROGRAM_ID), + .any(|account| account.account.owner.to_bytes() == CTOKEN_PROGRAM_ID), "Transfer change token account should match expected" ); recipient_accounts.iter().for_each(|account| { @@ -179,7 +178,7 @@ pub async fn assert_transfer2_with_delegate( ); assert_eq!( matching_change_account.account.owner.to_bytes(), - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, "Transfer change token account should match expected" ); } @@ -249,7 +248,7 @@ pub async fn assert_transfer2_with_delegate( ); assert_eq!( matching_change_account.account.owner.to_bytes(), - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, "Decompress change token account should match expected" ); } @@ -300,7 +299,7 @@ pub async fn assert_transfer2_with_delegate( ); assert_eq!( matching_change_account.account.owner.to_bytes(), - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, "Transfer change token account should match expected" ); change_accounts.iter().for_each(|account| { @@ -372,7 +371,7 @@ pub async fn assert_transfer2_with_delegate( ); assert_eq!( matching_account.account.owner.to_bytes(), - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, "Compress recipient token account should match expected" ); } @@ -493,7 +492,7 @@ pub async fn assert_transfer2_with_delegate( // Verify compressed account metadata assert_eq!( compressed_account.account.owner.to_bytes(), - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, "CompressAndClose compressed account should be owned by compressed token program" ); assert_eq!( diff --git a/programs/compressed-token/program/src/lib.rs b/programs/compressed-token/program/src/lib.rs index 12e98d3981..5fcc8940c0 100644 --- a/programs/compressed-token/program/src/lib.rs +++ b/programs/compressed-token/program/src/lib.rs @@ -1,7 +1,7 @@ use std::mem::ManuallyDrop; use anchor_lang::solana_program::program_error::ProgramError; -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use light_sdk::{cpi::CpiSigner, derive_light_cpi_signer}; use pinocchio::{account_info::AccountInfo, msg}; @@ -106,7 +106,7 @@ pub fn process_instruction( instruction_data: &[u8], ) -> Result<(), ProgramError> { let discriminator = InstructionType::from(instruction_data[0]); - if *program_id != COMPRESSED_TOKEN_PROGRAM_ID { + if *program_id != CTOKEN_PROGRAM_ID { return Err(ProgramError::IncorrectProgramId); } match discriminator { diff --git a/programs/registry/src/compressible/compressed_token/accounts.rs b/programs/registry/src/compressible/compressed_token/accounts.rs index 528b6d9eab..d41dd3dd8b 100644 --- a/programs/registry/src/compressible/compressed_token/accounts.rs +++ b/programs/registry/src/compressible/compressed_token/accounts.rs @@ -4,7 +4,7 @@ use light_account_checks::{ use light_program_profiler::profile; use super::{ - ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, COMPRESSED_TOKEN_PROGRAM_ID, + ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, CTOKEN_PROGRAM_ID, LIGHT_SYSTEM_PROGRAM_ID, }; @@ -32,10 +32,8 @@ impl<'a, A: AccountInfoTrait + Clone> Transfer2CpiAccounts<'a, A> { #[inline(always)] pub fn try_from_account_infos(fee_payer: A, accounts: &'a [A]) -> Result { let mut iter = AccountIterator::new(accounts); - let compressed_token_program = iter.next_checked_pubkey( - "compressed_token_program", - COMPRESSED_TOKEN_PROGRAM_ID.to_bytes(), - )?; + let compressed_token_program = + iter.next_checked_pubkey("compressed_token_program", CTOKEN_PROGRAM_ID.to_bytes())?; let compressed_token_cpi_authority = iter.next_account("compressed_token_cpi_authority")?; diff --git a/programs/registry/src/compressible/compressed_token/compress_and_close.rs b/programs/registry/src/compressible/compressed_token/compress_and_close.rs index 4515b22547..bfe608e15c 100644 --- a/programs/registry/src/compressible/compressed_token/compress_and_close.rs +++ b/programs/registry/src/compressible/compressed_token/compress_and_close.rs @@ -17,7 +17,7 @@ use crate::errors::RegistryError; const TRANSFER2_DISCRIMINATOR: u8 = 101; use super::{ - ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, COMPRESSED_TOKEN_PROGRAM_ID, + ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, CTOKEN_PROGRAM_ID, LIGHT_SYSTEM_PROGRAM_ID, REGISTERED_PROGRAM_PDA, }; @@ -174,7 +174,7 @@ pub fn compress_and_close_ctoken_accounts_with_indices<'info>( account_metas.extend(packed_account_metas); Ok(Instruction { - program_id: COMPRESSED_TOKEN_PROGRAM_ID, + program_id: CTOKEN_PROGRAM_ID, accounts: account_metas, data, }) diff --git a/programs/registry/src/compressible/compressed_token/mod.rs b/programs/registry/src/compressible/compressed_token/mod.rs index f26dc2e503..3c0a4e4150 100644 --- a/programs/registry/src/compressible/compressed_token/mod.rs +++ b/programs/registry/src/compressible/compressed_token/mod.rs @@ -9,8 +9,7 @@ pub use compress_and_close::{ use solana_pubkey::Pubkey; // Program ID for light-compressed-token -pub const COMPRESSED_TOKEN_PROGRAM_ID: Pubkey = - pubkey!("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"); +pub const CTOKEN_PROGRAM_ID: Pubkey = pubkey!("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"); // Light System Program ID pub const LIGHT_SYSTEM_PROGRAM_ID: Pubkey = pubkey!("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7"); diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v1/account.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v1/account.rs index 11c871d150..2475069014 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v1/account.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v1/account.rs @@ -3,7 +3,7 @@ use std::ops::Deref; use light_compressed_token_types::{PackedTokenTransferOutputData, TokenAccountMeta}; use solana_pubkey::Pubkey; -use crate::error::TokenSdkError; +use crate::error::CTokenSdkError; #[derive(Debug, PartialEq, Clone)] pub struct CTokenAccount { @@ -68,9 +68,9 @@ impl CTokenAccount { recipient: &Pubkey, amount: u64, output_merkle_tree_index: Option, - ) -> Result { + ) -> Result { if amount > self.output.amount { - return Err(TokenSdkError::InsufficientBalance); + return Err(CTokenSdkError::InsufficientBalance); } // TODO: skip outputs with zero amount when creating the instruction data. self.output.amount -= amount; @@ -103,9 +103,9 @@ impl CTokenAccount { _delegate: &Pubkey, amount: u64, output_merkle_tree_index: Option, - ) -> Result { + ) -> Result { if amount > self.output.amount { - return Err(TokenSdkError::InsufficientBalance); + return Err(CTokenSdkError::InsufficientBalance); } // Deduct the delegated amount from current account @@ -134,11 +134,11 @@ impl CTokenAccount { } // TODO: consider this might be confusing because it must not be used in combination with fn compress() - pub fn compress(&mut self, amount: u64) -> Result<(), TokenSdkError> { + pub fn compress(&mut self, amount: u64) -> Result<(), CTokenSdkError> { self.output.amount += amount; self.is_compress = true; if self.is_decompress { - return Err(TokenSdkError::CannotCompressAndDecompress); + return Err(CTokenSdkError::CannotCompressAndDecompress); } match self.compression_amount.as_mut() { @@ -151,12 +151,12 @@ impl CTokenAccount { } // TODO: consider this might be confusing because it must not be used in combination with fn decompress() - pub fn decompress(&mut self, amount: u64) -> Result<(), TokenSdkError> { + pub fn decompress(&mut self, amount: u64) -> Result<(), CTokenSdkError> { if self.is_compress { - return Err(TokenSdkError::CannotCompressAndDecompress); + return Err(CTokenSdkError::CannotCompressAndDecompress); } if self.output.amount < amount { - return Err(TokenSdkError::InsufficientBalance); + return Err(CTokenSdkError::InsufficientBalance); } self.output.amount -= amount; diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v1/approve/instruction.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v1/approve/instruction.rs index 5f5979615b..3eac2aa429 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v1/approve/instruction.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v1/approve/instruction.rs @@ -2,14 +2,14 @@ use borsh::BorshSerialize; use light_compressed_token_types::{ instruction::delegation::CompressedTokenInstructionDataApprove, ValidityProof, }; -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use solana_instruction::Instruction; use solana_pubkey::Pubkey; use super::account_metas::{get_approve_instruction_account_metas, ApproveMetaConfig}; use crate::{ compressed_token::v1::CTokenAccount, - error::{Result, TokenSdkError}, + error::{CTokenSdkError, Result}, }; #[derive(Debug, Clone)] @@ -35,13 +35,13 @@ pub fn create_approve_instruction(inputs: ApproveInputs) -> Result let (input_token_data, _) = inputs.sender_account.into_inputs_and_outputs(); if input_token_data.is_empty() { - return Err(TokenSdkError::InsufficientBalance); + return Err(CTokenSdkError::InsufficientBalance); } // Calculate total input amount let total_input_amount: u64 = input_token_data.iter().map(|data| data.amount).sum(); if total_input_amount < inputs.delegated_amount { - return Err(TokenSdkError::InsufficientBalance); + return Err(CTokenSdkError::InsufficientBalance); } // Use the input token data directly since it's already in the correct format @@ -63,7 +63,7 @@ pub fn create_approve_instruction(inputs: ApproveInputs) -> Result // Serialize instruction data let serialized_data = instruction_data .try_to_vec() - .map_err(|_| TokenSdkError::SerializationError)?; + .map_err(|_| CTokenSdkError::SerializationError)?; // Create account meta config let meta_config = ApproveMetaConfig::new( @@ -76,7 +76,7 @@ pub fn create_approve_instruction(inputs: ApproveInputs) -> Result let account_metas = get_approve_instruction_account_metas(meta_config); Ok(Instruction { - program_id: Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(CTOKEN_PROGRAM_ID), accounts: account_metas, data: serialized_data, }) diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v1/batch_compress/account_metas.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v1/batch_compress/account_metas.rs index e35a0a05bc..960019f0db 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v1/batch_compress/account_metas.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v1/batch_compress/account_metas.rs @@ -8,7 +8,7 @@ use crate::utils::CTokenDefaultAccounts; pub struct BatchCompressMetaConfig { pub fee_payer: Option, pub authority: Option, - pub token_pool_pda: Pubkey, + pub spl_interface_pda: Pubkey, pub sender_token_account: Pubkey, pub token_program: Pubkey, pub merkle_tree: Pubkey, @@ -20,7 +20,7 @@ impl BatchCompressMetaConfig { pub fn new( fee_payer: Pubkey, authority: Pubkey, - token_pool_pda: Pubkey, + spl_interface_pda: Pubkey, sender_token_account: Pubkey, token_program: Pubkey, merkle_tree: Pubkey, @@ -34,7 +34,7 @@ impl BatchCompressMetaConfig { Self { fee_payer: Some(fee_payer), authority: Some(authority), - token_pool_pda, + spl_interface_pda, sender_token_account, token_program, merkle_tree, @@ -44,7 +44,7 @@ impl BatchCompressMetaConfig { /// Create a new BatchCompressMetaConfig for client-side (CPI) usage pub fn new_client( - token_pool_pda: Pubkey, + spl_interface_pda: Pubkey, sender_token_account: Pubkey, token_program: Pubkey, merkle_tree: Pubkey, @@ -58,7 +58,7 @@ impl BatchCompressMetaConfig { Self { fee_payer: None, authority: None, - token_pool_pda, + spl_interface_pda, sender_token_account, token_program, merkle_tree, @@ -75,7 +75,7 @@ pub fn get_batch_compress_instruction_account_metas( let default_pubkeys = CTokenDefaultAccounts::default(); // Calculate capacity based on whether fee_payer is provided - // Base accounts: cpi_authority_pda + token_pool_pda + token_program + light_system_program + + // Base accounts: cpi_authority_pda + spl_interface_pda + token_program + light_system_program + // registered_program_pda + noop_program + account_compression_authority + // account_compression_program + merkle_tree + // self_program + system_program + sender_token_account @@ -113,10 +113,8 @@ pub fn get_batch_compress_instruction_account_metas( false, )); } - println!("config {:?}", config); - println!("default_pubkeys {:?}", default_pubkeys); - // token_pool_pda (mut) - metas.push(AccountMeta::new(config.token_pool_pda, false)); + // spl_interface_pda (mut) + metas.push(AccountMeta::new(config.spl_interface_pda, false)); // token_program metas.push(AccountMeta::new_readonly(config.token_program, false)); diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v1/batch_compress/instruction.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v1/batch_compress/instruction.rs index f6540c47a7..b3be6747ac 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v1/batch_compress/instruction.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v1/batch_compress/instruction.rs @@ -7,7 +7,7 @@ use solana_pubkey::Pubkey; use super::account_metas::{get_batch_compress_instruction_account_metas, BatchCompressMetaConfig}; use crate::{ - error::{Result, TokenSdkError}, + error::{CTokenSdkError, Result}, AnchorDeserialize, AnchorSerialize, }; @@ -21,7 +21,7 @@ pub struct Recipient { pub struct BatchCompressInputs { pub fee_payer: Pubkey, pub authority: Pubkey, - pub token_pool_pda: Pubkey, + pub spl_interface_pda: Pubkey, pub sender_token_account: Pubkey, pub token_program: Pubkey, pub merkle_tree: Pubkey, @@ -54,7 +54,7 @@ pub fn create_batch_compress_instruction(inputs: BatchCompressInputs) -> Result< // Serialize instruction data let data_vec = instruction_data .try_to_vec() - .map_err(|_| TokenSdkError::SerializationError)?; + .map_err(|_| CTokenSdkError::SerializationError)?; let mut data = Vec::with_capacity(data_vec.len() + 8 + 4); data.extend_from_slice(BATCH_COMPRESS.as_slice()); data.extend_from_slice( @@ -68,7 +68,7 @@ pub fn create_batch_compress_instruction(inputs: BatchCompressInputs) -> Result< let meta_config = BatchCompressMetaConfig { fee_payer: Some(inputs.fee_payer), authority: Some(inputs.authority), - token_pool_pda: inputs.token_pool_pda, + spl_interface_pda: inputs.spl_interface_pda, sender_token_account: inputs.sender_token_account, token_program: inputs.token_program, merkle_tree: inputs.merkle_tree, @@ -78,7 +78,7 @@ pub fn create_batch_compress_instruction(inputs: BatchCompressInputs) -> Result< let account_metas = get_batch_compress_instruction_account_metas(meta_config); Ok(Instruction { - program_id: Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID), accounts: account_metas, data, }) diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v1/mod.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v1/mod.rs index 043258adb4..b9cf10903e 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v1/mod.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v1/mod.rs @@ -4,3 +4,4 @@ pub mod batch_compress; pub mod transfer; pub use account::*; +pub use light_compressed_token_types::TokenAccountMeta; diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v1/transfer/account_metas.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v1/transfer/account_metas.rs index 49bb428a33..d599648230 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v1/transfer/account_metas.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v1/transfer/account_metas.rs @@ -8,7 +8,7 @@ use crate::utils::CTokenDefaultAccounts; pub struct TokenAccountsMetaConfig { pub fee_payer: Option, pub authority: Option, - pub token_pool_pda: Option, + pub spl_interface_pda: Option, pub compress_or_decompress_token_account: Option, pub token_program: Option, pub is_compress: bool, @@ -21,7 +21,7 @@ impl TokenAccountsMetaConfig { Self { fee_payer: Some(fee_payer), authority: Some(authority), - token_pool_pda: None, + spl_interface_pda: None, compress_or_decompress_token_account: None, token_program: None, is_compress: false, @@ -34,7 +34,7 @@ impl TokenAccountsMetaConfig { Self { fee_payer: None, authority: None, - token_pool_pda: None, + spl_interface_pda: None, compress_or_decompress_token_account: None, token_program: None, is_compress: false, @@ -47,7 +47,7 @@ impl TokenAccountsMetaConfig { Self { fee_payer: None, authority: None, - token_pool_pda: None, + spl_interface_pda: None, compress_or_decompress_token_account: None, token_program: None, is_compress: false, @@ -59,15 +59,15 @@ impl TokenAccountsMetaConfig { pub fn compress( fee_payer: Pubkey, authority: Pubkey, - token_pool_pda: Pubkey, + spl_interface_pda: Pubkey, sender_token_account: Pubkey, spl_program_id: Pubkey, ) -> Self { - // TODO: derive token_pool_pda here and pass mint instead. + // TODO: derive spl_interface_pda here and pass mint instead. Self { fee_payer: Some(fee_payer), authority: Some(authority), - token_pool_pda: Some(token_pool_pda), + spl_interface_pda: Some(spl_interface_pda), compress_or_decompress_token_account: Some(sender_token_account), token_program: Some(spl_program_id), is_compress: true, @@ -77,14 +77,14 @@ impl TokenAccountsMetaConfig { } pub fn compress_client( - token_pool_pda: Pubkey, + spl_interface_pda: Pubkey, sender_token_account: Pubkey, spl_program_id: Pubkey, ) -> Self { Self { fee_payer: None, authority: None, - token_pool_pda: Some(token_pool_pda), + spl_interface_pda: Some(spl_interface_pda), compress_or_decompress_token_account: Some(sender_token_account), token_program: Some(spl_program_id), is_compress: true, @@ -96,14 +96,14 @@ impl TokenAccountsMetaConfig { pub fn decompress( fee_payer: Pubkey, authority: Pubkey, - token_pool_pda: Pubkey, + spl_interface_pda: Pubkey, recipient_token_account: Pubkey, spl_program_id: Pubkey, ) -> Self { Self { fee_payer: Some(fee_payer), authority: Some(authority), - token_pool_pda: Some(token_pool_pda), + spl_interface_pda: Some(spl_interface_pda), compress_or_decompress_token_account: Some(recipient_token_account), token_program: Some(spl_program_id), is_compress: false, @@ -113,14 +113,14 @@ impl TokenAccountsMetaConfig { } pub fn decompress_client( - token_pool_pda: Pubkey, + spl_interface_pda: Pubkey, recipient_token_account: Pubkey, spl_program_id: Pubkey, ) -> Self { Self { fee_payer: None, authority: None, - token_pool_pda: Some(token_pool_pda), + spl_interface_pda: Some(spl_interface_pda), compress_or_decompress_token_account: Some(recipient_token_account), token_program: Some(spl_program_id), is_compress: false, @@ -182,8 +182,8 @@ pub fn get_transfer_instruction_account_metas(config: TokenAccountsMetaConfig) - }; // Optional token pool PDA (for compression/decompression) - if let Some(token_pool_pda) = config.token_pool_pda { - metas.push(AccountMeta::new(token_pool_pda, false)); + if let Some(spl_interface_pda) = config.spl_interface_pda { + metas.push(AccountMeta::new(spl_interface_pda, false)); } else if config.fee_payer.is_some() || config.with_anchor_none { metas.push(AccountMeta::new_readonly( default_pubkeys.compressed_token_program, diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v1/transfer/instruction.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v1/transfer/instruction.rs index 081bff35f8..3c79efa0a1 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v1/transfer/instruction.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v1/transfer/instruction.rs @@ -2,14 +2,14 @@ use light_compressed_token_types::{ constants::TRANSFER, instruction::transfer::CompressedTokenInstructionDataTransfer, CompressedCpiContext, ValidityProof, }; -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use solana_instruction::{AccountMeta, Instruction}; use solana_pubkey::Pubkey; use super::account_metas::{get_transfer_instruction_account_metas, TokenAccountsMetaConfig}; use crate::{ compressed_token::v1::account::CTokenAccount, - error::{Result, TokenSdkError}, + error::{CTokenSdkError, Result}, AnchorSerialize, }; // CTokenAccount abstraction to bundle inputs and create outputs. @@ -65,17 +65,17 @@ pub fn create_transfer_instruction_raw( // Check 1: cpi accounts must be decompress or compress consistent with accounts if (is_compress && !meta_config.is_compress) || (is_decompress && !meta_config.is_decompress) { - return Err(TokenSdkError::InconsistentCompressDecompressState); + return Err(CTokenSdkError::InconsistentCompressDecompressState); } // Check 2: there can only be compress or decompress not both if is_compress && is_decompress { - return Err(TokenSdkError::BothCompressAndDecompress); + return Err(CTokenSdkError::BothCompressAndDecompress); } // Check 3: compress_or_decompress_amount must be Some if compress_or_decompress_amount.is_none() && meta_config.is_compress_or_decompress() { - return Err(TokenSdkError::InvalidCompressDecompressAmount); + return Err(CTokenSdkError::InvalidCompressDecompressAmount); } // Extract input and output data from token accounts @@ -110,7 +110,7 @@ pub fn create_transfer_instruction_raw( // TODO: calculate exact len. let serialized = instruction_data .try_to_vec() - .map_err(|_| TokenSdkError::SerializationError)?; + .map_err(|_| CTokenSdkError::SerializationError)?; // Serialize instruction data let mut data = Vec::with_capacity(8 + 4 + serialized.len()); // rough estimate @@ -132,7 +132,7 @@ pub fn create_transfer_instruction_raw( account_metas.push(AccountMeta::new(tree_pubkey, false)); } Ok(Instruction { - program_id: Pubkey::from(COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::from(CTOKEN_PROGRAM_ID), accounts: account_metas, data, }) @@ -147,7 +147,7 @@ pub struct CompressInputs { pub sender_token_account: Pubkey, pub amount: u64, // pub output_queue_pubkey: Pubkey, - pub token_pool_pda: Pubkey, + pub spl_interface_pda: Pubkey, pub transfer_config: Option, pub spl_token_program: Pubkey, pub tree_accounts: Vec, @@ -164,7 +164,7 @@ pub fn compress(inputs: CompressInputs) -> Result { recipient, sender_token_account, amount, - token_pool_pda, + spl_interface_pda, transfer_config, spl_token_program, output_tree_index, @@ -177,7 +177,7 @@ pub fn compress(inputs: CompressInputs) -> Result { let meta_config = TokenAccountsMetaConfig::compress( fee_payer, authority, - token_pool_pda, + spl_interface_pda, sender_token_account, spl_token_program, ); @@ -214,7 +214,7 @@ pub fn transfer(inputs: TransferInputs) -> Result { } = inputs; // Sanity check. if sender_account.method_used { - return Err(TokenSdkError::MethodUsed); + return Err(CTokenSdkError::MethodUsed); } let account_meta_config = TokenAccountsMetaConfig::new(fee_payer, sender_account.owner()); // None is the same output_tree_index as token account @@ -238,7 +238,7 @@ pub struct DecompressInputs { pub amount: u64, pub tree_pubkeys: Vec, pub config: Option, - pub token_pool_pda: Pubkey, + pub spl_interface_pda: Pubkey, pub recipient_token_account: Pubkey, pub spl_token_program: Pubkey, } @@ -251,18 +251,18 @@ pub fn decompress(inputs: DecompressInputs) -> Result { mut sender_account, tree_pubkeys, config, - token_pool_pda, + spl_interface_pda, recipient_token_account, spl_token_program, } = inputs; // Sanity check. if sender_account.method_used { - return Err(TokenSdkError::MethodUsed); + return Err(CTokenSdkError::MethodUsed); } let account_meta_config = TokenAccountsMetaConfig::decompress( fee_payer, sender_account.owner(), - token_pool_pda, + spl_interface_pda, recipient_token_account, spl_token_program, ); diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/account2.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/account2.rs index f6c1fb5630..6fe6eeaf2d 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/account2.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/account2.rs @@ -7,7 +7,7 @@ use light_program_profiler::profile; use solana_account_info::AccountInfo; use solana_pubkey::Pubkey; -use crate::{error::TokenSdkError, utils::get_token_account_balance}; +use crate::{error::CTokenSdkError, utils::get_token_account_balance}; #[derive(Debug, PartialEq, Clone)] pub struct CTokenAccount2 { @@ -20,13 +20,13 @@ pub struct CTokenAccount2 { impl CTokenAccount2 { #[profile] - pub fn new(token_data: Vec) -> Result { + pub fn new(token_data: Vec) -> Result { // all mint indices must be the same // all owners must be the same let amount = token_data.iter().map(|data| data.amount).sum(); // Check if token_data is empty if token_data.is_empty() { - return Err(TokenSdkError::InsufficientBalance); // TODO: Add proper error variant + return Err(CTokenSdkError::NoInputAccounts); } // Use the indices from the first token data (assuming they're all the same mint/owner) @@ -56,13 +56,13 @@ impl CTokenAccount2 { #[profile] pub fn new_delegated( token_data: Vec, - ) -> Result { + ) -> Result { // all mint indices must be the same // all owners must be the same let amount = token_data.iter().map(|data| data.amount).sum(); // Check if token_data is empty if token_data.is_empty() { - return Err(TokenSdkError::InsufficientBalance); // TODO: Add proper error variant + return Err(CTokenSdkError::NoInputAccounts); } // Use the indices from the first token data (assuming they're all the same mint/owner) @@ -107,9 +107,9 @@ impl CTokenAccount2 { // TODO: consider this might be confusing because it must not be used in combination with fn transfer() // could mark the struct as transferred and throw in fn transfer #[profile] - pub fn transfer(&mut self, recipient_index: u8, amount: u64) -> Result { + pub fn transfer(&mut self, recipient_index: u8, amount: u64) -> Result { if amount > self.output.amount { - return Err(TokenSdkError::InsufficientBalance); + return Err(CTokenSdkError::InsufficientBalance); } // TODO: skip outputs with zero amount when creating the instruction data. self.output.amount -= amount; @@ -136,9 +136,9 @@ impl CTokenAccount2 { /// and returns a new CTokenAccount that represents the delegated portion. /// The original account balance is reduced by the delegated amount. #[profile] - pub fn approve(&mut self, delegate_index: u8, amount: u64) -> Result { + pub fn approve(&mut self, delegate_index: u8, amount: u64) -> Result { if amount > self.output.amount { - return Err(TokenSdkError::InsufficientBalance); + return Err(CTokenSdkError::InsufficientBalance); } // Deduct the delegated amount from current account @@ -171,10 +171,10 @@ impl CTokenAccount2 { amount: u64, source_or_recipient_index: u8, authority: u8, - ) -> Result<(), TokenSdkError> { + ) -> Result<(), CTokenSdkError> { // Check if there's already a compression set if self.compression.is_some() { - return Err(TokenSdkError::CompressionCannotBeSetTwice); + return Err(CTokenSdkError::CompressionCannotBeSetTwice); } self.output.amount += amount; @@ -198,10 +198,10 @@ impl CTokenAccount2 { pool_account_index: u8, pool_index: u8, bump: u8, - ) -> Result<(), TokenSdkError> { + ) -> Result<(), CTokenSdkError> { // Check if there's already a compression set if self.compression.is_some() { - return Err(TokenSdkError::CompressionCannotBeSetTwice); + return Err(CTokenSdkError::CompressionCannotBeSetTwice); } self.output.amount += amount; @@ -225,14 +225,14 @@ impl CTokenAccount2 { &mut self, amount: u64, source_index: u8, - ) -> Result<(), TokenSdkError> { + ) -> Result<(), CTokenSdkError> { // Check if there's already a compression set if self.compression.is_some() { - return Err(TokenSdkError::CompressionCannotBeSetTwice); + return Err(CTokenSdkError::CompressionCannotBeSetTwice); } if self.output.amount < amount { - return Err(TokenSdkError::InsufficientBalance); + return Err(CTokenSdkError::InsufficientBalance); } self.output.amount -= amount; @@ -254,14 +254,14 @@ impl CTokenAccount2 { pool_account_index: u8, pool_index: u8, bump: u8, - ) -> Result<(), TokenSdkError> { + ) -> Result<(), CTokenSdkError> { // Check if there's already a compression set if self.compression.is_some() { - return Err(TokenSdkError::CompressionCannotBeSetTwice); + return Err(CTokenSdkError::CompressionCannotBeSetTwice); } if self.output.amount < amount { - return Err(TokenSdkError::InsufficientBalance); + return Err(CTokenSdkError::InsufficientBalance); } self.output.amount -= amount; @@ -284,10 +284,10 @@ impl CTokenAccount2 { source_or_recipient_index: u8, authority: u8, token_account_info: &AccountInfo, - ) -> Result<(), TokenSdkError> { + ) -> Result<(), CTokenSdkError> { // Check if there's already a compression set if self.compression.is_some() { - return Err(TokenSdkError::CompressionCannotBeSetTwice); + return Err(CTokenSdkError::CompressionCannotBeSetTwice); } // Get the actual token account balance to add to output @@ -322,10 +322,10 @@ impl CTokenAccount2 { rent_sponsor_index: u8, compressed_account_index: u8, destination_index: u8, - ) -> Result<(), TokenSdkError> { + ) -> Result<(), CTokenSdkError> { // Check if there's already a compression set if self.compression.is_some() { - return Err(TokenSdkError::CompressionCannotBeSetTwice); + return Err(CTokenSdkError::CompressionCannotBeSetTwice); } // Add the full balance to the output amount diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/compress_and_close.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/compress_and_close.rs index c3813aaf63..1a806eb363 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/compress_and_close.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/compress_and_close.rs @@ -21,7 +21,10 @@ use super::{ Transfer2Inputs, }, }; -use crate::{error::TokenSdkError, utils::CTokenDefaultAccounts, AccountInfoToCompress}; +use crate::{ + error::CTokenSdkError, + utils::{AccountInfoToCompress, CTokenDefaultAccounts}, +}; /// Struct to hold all the indices needed for CompressAndClose operation #[derive(Debug, Copy, Clone, crate::AnchorSerialize, crate::AnchorDeserialize)] @@ -41,7 +44,7 @@ pub fn pack_for_compress_and_close( ctoken_account_data: &[u8], packed_accounts: &mut PackedAccounts, signer_is_compression_authority: bool, // if yes rent authority must be signer -) -> Result { +) -> Result { let (ctoken_account, _) = CToken::zero_copy_at(ctoken_account_data)?; let source_index = packed_accounts.insert_or_get(ctoken_account_pubkey); let mint_index = packed_accounts.insert_or_get(Pubkey::from(ctoken_account.mint.to_bytes())); @@ -115,35 +118,35 @@ fn find_account_indices( rent_sponsor_pubkey: &Pubkey, destination_pubkey: &Pubkey, // output_tree_pubkey: &Pubkey, -) -> Result { +) -> Result { let source_index = find_index(ctoken_account_key).ok_or_else(|| { msg!("Source ctoken account not found in packed_accounts"); - TokenSdkError::InvalidAccountData + CTokenSdkError::InvalidAccountData })?; let mint_index = find_index(mint_pubkey).ok_or_else(|| { msg!("Mint {} not found in packed_accounts", mint_pubkey); - TokenSdkError::InvalidAccountData + CTokenSdkError::InvalidAccountData })?; let owner_index = find_index(owner_pubkey).ok_or_else(|| { msg!("Owner {} not found in packed_accounts", owner_pubkey); - TokenSdkError::InvalidAccountData + CTokenSdkError::InvalidAccountData })?; let authority_index = find_index(authority).ok_or_else(|| { msg!("Authority not found in packed_accounts"); - TokenSdkError::InvalidAccountData + CTokenSdkError::InvalidAccountData })?; let rent_sponsor_index = find_index(rent_sponsor_pubkey).ok_or_else(|| { msg!("Rent recipient not found in packed_accounts"); - TokenSdkError::InvalidAccountData + CTokenSdkError::InvalidAccountData })?; let destination_index = find_index(destination_pubkey).ok_or_else(|| { msg!("Destination not found in packed_accounts"); - TokenSdkError::InvalidAccountData + CTokenSdkError::InvalidAccountData })?; Ok(CompressAndCloseIndices { @@ -173,10 +176,10 @@ pub fn compress_and_close_ctoken_accounts_with_indices<'info>( cpi_context_pubkey: Option, indices: &[CompressAndCloseIndices], packed_accounts: &[AccountInfo<'info>], -) -> Result { +) -> Result { if indices.is_empty() { msg!("indices empty"); - return Err(TokenSdkError::InvalidAccountData); + return Err(CTokenSdkError::InvalidAccountData); } // Convert packed_accounts to AccountMetas using ArrayVec to avoid heap allocation let mut packed_account_metas = arrayvec::ArrayVec::::new(); @@ -194,11 +197,11 @@ pub fn compress_and_close_ctoken_accounts_with_indices<'info>( // Get the amount from the source token account let source_account = packed_accounts .get(idx.source_index as usize) - .ok_or(TokenSdkError::InvalidAccountData)?; + .ok_or(CTokenSdkError::InvalidAccountData)?; let account_data = source_account .try_borrow_data() - .map_err(|_| TokenSdkError::AccountBorrowFailed)?; + .map_err(|_| CTokenSdkError::AccountBorrowFailed)?; let amount = light_ctoken_interface::state::CToken::amount_from_slice(&account_data)?; @@ -280,10 +283,10 @@ pub fn compress_and_close_ctoken_accounts<'info>( output_queue: AccountInfo<'info>, ctoken_solana_accounts: &[&AccountInfo<'info>], packed_accounts: &[AccountInfo<'info>], -) -> Result { +) -> Result { if ctoken_solana_accounts.is_empty() { msg!("ctoken_solana_accounts empty"); - return Err(TokenSdkError::InvalidAccountData); + return Err(CTokenSdkError::InvalidAccountData); } // Helper function to find index of a pubkey in packed_accounts using linear search @@ -304,12 +307,12 @@ pub fn compress_and_close_ctoken_accounts<'info>( // Deserialize the ctoken Solana account using light zero copy let account_data = ctoken_account_info .try_borrow_data() - .map_err(|_| TokenSdkError::AccountBorrowFailed)?; + .map_err(|_| CTokenSdkError::AccountBorrowFailed)?; // Deserialize the full CToken including extensions let (compressed_token, _) = light_ctoken_interface::state::CToken::zero_copy_at(&account_data) - .map_err(|_| TokenSdkError::InvalidAccountData)?; + .map_err(|_| CTokenSdkError::InvalidAccountData)?; // Extract pubkeys from the deserialized account let mint_pubkey = Pubkey::from(compressed_token.mint.to_bytes()); @@ -362,7 +365,7 @@ pub fn compress_and_close_ctoken_accounts<'info>( } } } - rent_sponsor_pubkey.ok_or(TokenSdkError::InvalidAccountData)? + rent_sponsor_pubkey.ok_or(CTokenSdkError::InvalidAccountData)? }; let destination_pubkey = if with_compression_authority { @@ -416,7 +419,7 @@ pub fn compress_and_close_ctoken_accounts_signed<'b, 'info>( post_system: &[AccountInfo<'info>], remaining_accounts: &[AccountInfo<'info>], with_compression_authority: bool, -) -> Result<(), TokenSdkError> { +) -> Result<(), CTokenSdkError> { let mut packed_accounts = Vec::with_capacity(post_system.len() + 4); packed_accounts.extend_from_slice(post_system); packed_accounts.push(cpi_authority); @@ -451,7 +454,7 @@ pub fn compress_and_close_ctoken_accounts_signed<'b, 'info>( } invoke_signed(&instruction, &account_infos, &all_signer_seeds) - .map_err(|e| TokenSdkError::CpiError(e.to_string()))?; + .map_err(|e| CTokenSdkError::CpiError(e.to_string()))?; Ok(()) } diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/account_metas.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/account_metas.rs index dd0134f607..28d2402d13 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/account_metas.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/account_metas.rs @@ -3,7 +3,7 @@ use solana_pubkey::Pubkey; use crate::utils::CTokenDefaultAccounts; -/// Account metadata configuration for create compressed mint instruction +/// Account metadata configuration for create cMint instruction #[derive(Debug, Copy, Clone)] pub struct CreateCompressedMintMetaConfig { pub fee_payer: Option, @@ -43,7 +43,7 @@ impl CreateCompressedMintMetaConfig { } } -/// Get the standard account metas for a create compressed mint instruction +/// Get the standard account metas for a create cMint instruction pub fn get_create_compressed_mint_instruction_account_metas( config: CreateCompressedMintMetaConfig, ) -> Vec { diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/instruction.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/instruction.rs index 524db8d46f..a9337d9dd3 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/instruction.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/instruction.rs @@ -18,7 +18,7 @@ use crate::{ get_mint_action_instruction_account_metas_cpi_write, MintActionMetaConfig, MintActionMetaConfigCpiWrite, }, - error::{Result, TokenSdkError}, + error::{CTokenSdkError, Result}, AnchorDeserialize, AnchorSerialize, }; @@ -50,10 +50,7 @@ pub fn create_compressed_mint_cpi( decimals: input.decimals, metadata: light_ctoken_interface::state::CompressedMintMetadata { version: input.version, - mint: find_spl_mint_address(&input.mint_signer) - .0 - .to_bytes() - .into(), + mint: find_cmint_address(&input.mint_signer).0.to_bytes().into(), spl_mint_initialized: false, }, mint_authority: Some(input.mint_authority.to_bytes().into()), @@ -101,11 +98,11 @@ pub fn create_compressed_mint_cpi( let data = instruction_data .data() - .map_err(|_| TokenSdkError::SerializationError)?; + .map_err(|_| CTokenSdkError::SerializationError)?; Ok(Instruction { program_id: solana_pubkey::Pubkey::new_from_array( - light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID, + light_ctoken_interface::CTOKEN_PROGRAM_ID, ), accounts: account_metas, data, @@ -135,7 +132,7 @@ pub fn create_compressed_mint_cpi_write( "Invalid CPI context first cpi set or set context must be true {:?}", input.cpi_context ); - return Err(TokenSdkError::InvalidAccountData); + return Err(CTokenSdkError::InvalidAccountData); } let compressed_mint_instruction_data = CompressedMintInstructionData { @@ -143,10 +140,7 @@ pub fn create_compressed_mint_cpi_write( decimals: input.decimals, metadata: light_ctoken_interface::state::CompressedMintMetadata { version: input.version, - mint: find_spl_mint_address(&input.mint_signer) - .0 - .to_bytes() - .into(), + mint: find_cmint_address(&input.mint_signer).0.to_bytes().into(), spl_mint_initialized: false, }, mint_authority: Some(input.mint_authority.to_bytes().into()), @@ -171,11 +165,11 @@ pub fn create_compressed_mint_cpi_write( let data = instruction_data .data() - .map_err(|_| TokenSdkError::SerializationError)?; + .map_err(|_| CTokenSdkError::SerializationError)?; Ok(Instruction { program_id: solana_pubkey::Pubkey::new_from_array( - light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID, + light_ctoken_interface::CTOKEN_PROGRAM_ID, ), accounts: account_metas, data, @@ -185,19 +179,19 @@ pub fn create_compressed_mint_cpi_write( /// Creates a compressed mint instruction with automatic mint address derivation pub fn create_compressed_mint(input: CreateCompressedMintInputs) -> Result { let mint_address = - derive_compressed_mint_address(&input.mint_signer, &input.address_tree_pubkey); + derive_cmint_compressed_address(&input.mint_signer, &input.address_tree_pubkey); create_compressed_mint_cpi(input, mint_address, None, None) } /// Derives the compressed mint address from the mint seed and address tree -pub fn derive_compressed_mint_address( +pub fn derive_cmint_compressed_address( mint_seed: &Pubkey, address_tree_pubkey: &Pubkey, ) -> [u8; 32] { light_compressed_account::address::derive_address( - &find_spl_mint_address(mint_seed).0.to_bytes(), + &find_cmint_address(mint_seed).0.to_bytes(), &address_tree_pubkey.to_bytes(), - &light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID, + &light_ctoken_interface::CTOKEN_PROGRAM_ID, ) } @@ -205,13 +199,13 @@ pub fn derive_cmint_from_spl_mint(mint: &Pubkey, address_tree_pubkey: &Pubkey) - light_compressed_account::address::derive_address( &mint.to_bytes(), &address_tree_pubkey.to_bytes(), - &light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID, + &light_ctoken_interface::CTOKEN_PROGRAM_ID, ) } -pub fn find_spl_mint_address(mint_seed: &Pubkey) -> (Pubkey, u8) { +pub fn find_cmint_address(mint_seed: &Pubkey) -> (Pubkey, u8) { Pubkey::find_program_address( &[COMPRESSED_MINT_SEED, mint_seed.as_ref()], - &Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + &Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID), ) } diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/mod.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/mod.rs index cbc4175976..443374742e 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/mod.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/create_compressed_mint/mod.rs @@ -6,6 +6,6 @@ pub use account_metas::{ }; pub use instruction::{ create_compressed_mint, create_compressed_mint_cpi, create_compressed_mint_cpi_write, - derive_cmint_from_spl_mint, derive_compressed_mint_address, find_spl_mint_address, + derive_cmint_compressed_address, derive_cmint_from_spl_mint, find_cmint_address, CreateCompressedMintInputs, }; diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/decompress_full.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/decompress_full.rs index e3f485bb8e..64228721f3 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/decompress_full.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/decompress_full.rs @@ -18,7 +18,9 @@ use super::{ Transfer2Inputs, }, }; -use crate::{compat::TokenData, error::TokenSdkError, utils::CTokenDefaultAccounts, ValidityProof}; +use crate::{ + compat::TokenData, error::CTokenSdkError, utils::CTokenDefaultAccounts, ValidityProof, +}; /// Struct to hold all the data needed for DecompressFull operation /// Contains the complete compressed account data and destination index @@ -46,9 +48,9 @@ pub fn decompress_full_ctoken_accounts_with_indices<'info>( cpi_context_pubkey: Option, indices: &[DecompressFullIndices], packed_accounts: &[AccountInfo<'info>], -) -> Result { +) -> Result { if indices.is_empty() { - return Err(TokenSdkError::InvalidAccountData); + return Err(CTokenSdkError::InvalidAccountData); } // Process each set of indices @@ -71,7 +73,7 @@ pub fn decompress_full_ctoken_accounts_with_indices<'info>( let owner_idx = idx.source.owner as usize; if owner_idx >= signer_flags.len() { - return Err(TokenSdkError::InvalidAccountData); + return Err(CTokenSdkError::InvalidAccountData); } signer_flags[owner_idx] = true; } diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/account_metas.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/account_metas.rs index 2e1b094e44..2c34d7bc8f 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/account_metas.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/account_metas.rs @@ -68,7 +68,7 @@ impl MintActionMetaConfig { cpi_context_pubkey: Pubkey, ) -> crate::error::Result { if instruction_data.cpi_context.is_none() { - return Err(crate::error::TokenSdkError::CpiContextRequired); + return Err(crate::error::CTokenSdkError::CpiContextRequired); } Ok(Self { diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/cpi_accounts.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/cpi_accounts.rs index fa5c461e31..e22f55e369 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/cpi_accounts.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/cpi_accounts.rs @@ -1,6 +1,6 @@ use light_account_checks::{AccountError, AccountInfoTrait, AccountIterator}; use light_compressed_token_types::CPI_AUTHORITY_PDA; -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use light_program_profiler::profile; use light_sdk_types::{ ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, LIGHT_SYSTEM_PROGRAM_ID, @@ -9,7 +9,7 @@ use light_sdk_types::{ use solana_instruction::AccountMeta; use solana_msg::msg; -use crate::error::TokenSdkError; +use crate::error::CTokenSdkError; #[derive(Debug, Clone, Default, Copy)] pub struct MintActionCpiAccountsConfig { @@ -69,11 +69,11 @@ impl<'a, A: AccountInfoTrait + Clone> MintActionCpiAccounts<'a, A> { pub fn try_from_account_infos_full( accounts: &'a [A], config: MintActionCpiAccountsConfig, - ) -> Result { + ) -> Result { let mut iter = AccountIterator::new(accounts); let compressed_token_program = - iter.next_checked_pubkey("compressed_token_program", COMPRESSED_TOKEN_PROGRAM_ID)?; + iter.next_checked_pubkey("compressed_token_program", CTOKEN_PROGRAM_ID)?; let light_system_program = iter.next_checked_pubkey("light_system_program", LIGHT_SYSTEM_PROGRAM_ID)?; @@ -171,7 +171,7 @@ impl<'a, A: AccountInfoTrait + Clone> MintActionCpiAccounts<'a, A> { /// Simple version for common case (no optional features) #[inline(always)] #[track_caller] - pub fn try_from_account_infos(accounts: &'a [A]) -> Result { + pub fn try_from_account_infos(accounts: &'a [A]) -> Result { Self::try_from_account_infos_full(accounts, MintActionCpiAccountsConfig::default()) } diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/instruction.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/instruction.rs index 7d6f0c3bd3..4bb546fc18 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/instruction.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_action/instruction.rs @@ -1,13 +1,13 @@ use light_compressed_account::instruction_data::traits::LightInstructionData; use light_ctoken_interface::{ - instructions::mint_action::MintActionCompressedInstructionData, COMPRESSED_TOKEN_PROGRAM_ID, + instructions::mint_action::MintActionCompressedInstructionData, CTOKEN_PROGRAM_ID, }; use solana_instruction::Instruction; use solana_msg::msg; use solana_program_error::ProgramError; use super::{cpi_accounts::MintActionCpiAccounts, MintActionCpiWriteAccounts}; -use crate::{compressed_token::ctoken_instruction::CTokenInstruction, error::TokenSdkError}; +use crate::{compressed_token::ctoken_instruction::CTokenInstruction, error::CTokenSdkError}; impl CTokenInstruction for MintActionCompressedInstructionData { type ExecuteAccounts<'info, A: light_account_checks::AccountInfoTrait + Clone + 'info> = @@ -24,14 +24,14 @@ impl CTokenInstruction for MintActionCompressedInstructionData { msg!( "CPI context write operations not supported in instruction(). Use instruction_write_to_cpi_context_first() or instruction_write_to_cpi_context_set() instead" ); - return Err(ProgramError::from(TokenSdkError::InvalidAccountData)); + return Err(ProgramError::from(CTokenSdkError::InvalidAccountData)); } } let data = self.data().map_err(ProgramError::from)?; Ok(Instruction { - program_id: COMPRESSED_TOKEN_PROGRAM_ID.into(), + program_id: CTOKEN_PROGRAM_ID.into(), accounts: accounts.to_account_metas(), data, }) @@ -86,7 +86,7 @@ fn build_cpi_write_instruction Result { let data = instruction_data.data().map_err(ProgramError::from)?; Ok(Instruction { - program_id: COMPRESSED_TOKEN_PROGRAM_ID.into(), + program_id: CTOKEN_PROGRAM_ID.into(), accounts: { let mut account_metas = Vec::with_capacity( 6 + accounts.recipient_token_accounts.len() diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_to_compressed/account_metas.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_to_compressed/account_metas.rs index 7a26906920..965b598fbb 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_to_compressed/account_metas.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/mint_to_compressed/account_metas.rs @@ -15,7 +15,7 @@ pub struct MintToCompressedMetaConfig { pub compressed_mint_queue: Pubkey, pub spl_mint_initialized: bool, pub mint_pda: Option, - pub token_pool_pda: Option, + pub spl_interface_pda: Option, pub token_program: Option, pub with_lamports: bool, } @@ -43,7 +43,7 @@ impl MintToCompressedMetaConfig { compressed_mint_queue, spl_mint_initialized: false, mint_pda: None, - token_pool_pda: None, + spl_interface_pda: None, token_program: None, with_lamports, } @@ -68,7 +68,7 @@ impl MintToCompressedMetaConfig { compressed_mint_queue, spl_mint_initialized: false, mint_pda: None, - token_pool_pda: None, + spl_interface_pda: None, token_program: None, with_lamports, } @@ -85,7 +85,7 @@ impl MintToCompressedMetaConfig { compressed_mint_tree: Pubkey, compressed_mint_queue: Pubkey, mint_pda: Pubkey, - token_pool_pda: Pubkey, + spl_interface_pda: Pubkey, token_program: Pubkey, with_lamports: bool, ) -> Self { @@ -99,7 +99,7 @@ impl MintToCompressedMetaConfig { compressed_mint_queue, spl_mint_initialized: true, mint_pda: Some(mint_pda), - token_pool_pda: Some(token_pool_pda), + spl_interface_pda: Some(spl_interface_pda), token_program: Some(token_program), with_lamports, } @@ -167,7 +167,7 @@ pub fn get_mint_to_compressed_instruction_account_metas( // Optional decompressed mint accounts if config.spl_mint_initialized { metas.push(AccountMeta::new(config.mint_pda.unwrap(), false)); // mint - metas.push(AccountMeta::new(config.token_pool_pda.unwrap(), false)); // token_pool_pda + metas.push(AccountMeta::new(config.spl_interface_pda.unwrap(), false)); // spl_interface_pda metas.push(AccountMeta::new_readonly( config.token_program.unwrap(), false, 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 47f7d20bc5..b4001ed392 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 @@ -9,7 +9,7 @@ use solana_pubkey::Pubkey; use crate::{ compressed_token::mint_action::MintActionMetaConfig, - error::{Result, TokenSdkError}, + error::{CTokenSdkError, Result}, spl_interface::SplInterfacePda, }; @@ -95,11 +95,11 @@ pub fn create_mint_to_compressed_instruction( let data = instruction_data .data() - .map_err(|_| TokenSdkError::SerializationError)?; + .map_err(|_| CTokenSdkError::SerializationError)?; Ok(Instruction { program_id: solana_pubkey::Pubkey::new_from_array( - light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID, + light_ctoken_interface::CTOKEN_PROGRAM_ID, ), accounts: account_metas, data, diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/transfer2/cpi_accounts.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/transfer2/cpi_accounts.rs index 2d7c8e0335..4f45e973e4 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/transfer2/cpi_accounts.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/transfer2/cpi_accounts.rs @@ -1,6 +1,6 @@ use light_account_checks::{AccountError, AccountInfoTrait, AccountIterator}; use light_compressed_token_types::CPI_AUTHORITY_PDA; -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use light_program_profiler::profile; use light_sdk_types::{ ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, LIGHT_SYSTEM_PROGRAM_ID, @@ -9,7 +9,7 @@ use light_sdk_types::{ use solana_instruction::AccountMeta; use solana_msg::msg; -use crate::error::TokenSdkError; +use crate::error::CTokenSdkError; /// Parsed Transfer2 CPI accounts for structured access #[derive(Debug)] @@ -51,11 +51,11 @@ impl<'a, A: AccountInfoTrait + Clone> Transfer2CpiAccounts<'a, A> { with_sol_decompression: bool, with_cpi_context: bool, light_system_cpi_authority: bool, - ) -> Result { + ) -> Result { let mut iter = AccountIterator::new(accounts); let compressed_token_program = - iter.next_checked_pubkey("compressed_token_program", COMPRESSED_TOKEN_PROGRAM_ID)?; + iter.next_checked_pubkey("compressed_token_program", CTOKEN_PROGRAM_ID)?; let invoking_program_cpi_authority = iter.next_option("CPI_SIGNER.cpi_authority", light_system_cpi_authority)?; @@ -116,7 +116,7 @@ impl<'a, A: AccountInfoTrait + Clone> Transfer2CpiAccounts<'a, A> { pub fn try_from_account_infos( fee_payer: &'a A, accounts: &'a [A], - ) -> Result { + ) -> Result { Self::try_from_account_infos_full(fee_payer, accounts, false, false, false, false) } @@ -125,7 +125,7 @@ impl<'a, A: AccountInfoTrait + Clone> Transfer2CpiAccounts<'a, A> { pub fn try_from_account_infos_cpi_context( fee_payer: &'a A, accounts: &'a [A], - ) -> Result { + ) -> Result { Self::try_from_account_infos_full(fee_payer, accounts, false, false, true, false) } diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/transfer2/instruction.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/transfer2/instruction.rs index 9695e6dfea..1dd55a2945 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/transfer2/instruction.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/transfer2/instruction.rs @@ -1,7 +1,7 @@ use light_compressed_token_types::{constants::TRANSFER2, ValidityProof}; use light_ctoken_interface::{ instructions::transfer2::{CompressedCpiContext, CompressedTokenInstructionDataTransfer2}, - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, }; use light_program_profiler::profile; use solana_instruction::Instruction; @@ -10,7 +10,7 @@ use solana_pubkey::Pubkey; use super::account_metas::{get_transfer2_instruction_account_metas, Transfer2AccountsMetaConfig}; use crate::{ compressed_token::CTokenAccount2, - error::{Result, TokenSdkError}, + error::{CTokenSdkError, Result}, AnchorSerialize, }; @@ -130,7 +130,7 @@ pub fn create_transfer2_instruction(inputs: Transfer2Inputs) -> Result Result Result { // Validate that no token account has been used for token_account in &token_accounts { if token_account.method_used { - return Err(TokenSdkError::MethodUsed); + return Err(CTokenSdkError::MethodUsed); } } diff --git a/sdk-libs/ctoken-sdk/src/compressed_token/v2/update_compressed_mint/instruction.rs b/sdk-libs/ctoken-sdk/src/compressed_token/v2/update_compressed_mint/instruction.rs index 139e6a662c..8609da3c68 100644 --- a/sdk-libs/ctoken-sdk/src/compressed_token/v2/update_compressed_mint/instruction.rs +++ b/sdk-libs/ctoken-sdk/src/compressed_token/v2/update_compressed_mint/instruction.rs @@ -14,7 +14,7 @@ use crate::{ get_mint_action_instruction_account_metas_cpi_write, MintActionMetaConfig, MintActionMetaConfigCpiWrite, }, - error::{Result, TokenSdkError}, + error::{CTokenSdkError, Result}, AnchorDeserialize, AnchorSerialize, }; @@ -75,11 +75,11 @@ pub fn update_compressed_mint_cpi( let data = instruction_data .data() - .map_err(|_| TokenSdkError::SerializationError)?; + .map_err(|_| CTokenSdkError::SerializationError)?; Ok(Instruction { program_id: solana_pubkey::Pubkey::new_from_array( - light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID, + light_ctoken_interface::CTOKEN_PROGRAM_ID, ), accounts: account_metas, data, @@ -108,7 +108,7 @@ pub fn create_update_compressed_mint_cpi_write( inputs: UpdateCompressedMintInputsCpiWrite, ) -> Result { if !inputs.cpi_context.first_set_context && !inputs.cpi_context.set_context { - return Err(TokenSdkError::InvalidAccountData); + return Err(CTokenSdkError::InvalidCpiContext); } let mut instruction_data = @@ -143,11 +143,11 @@ pub fn create_update_compressed_mint_cpi_write( let data = instruction_data .data() - .map_err(|_| TokenSdkError::SerializationError)?; + .map_err(|_| CTokenSdkError::SerializationError)?; Ok(Instruction { program_id: solana_pubkey::Pubkey::new_from_array( - light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID, + light_ctoken_interface::CTOKEN_PROGRAM_ID, ), accounts: account_metas, data, diff --git a/sdk-libs/ctoken-sdk/src/compressible/decompress_runtime.rs b/sdk-libs/ctoken-sdk/src/compressible/decompress_runtime.rs index 2995a875b4..a606316e74 100644 --- a/sdk-libs/ctoken-sdk/src/compressible/decompress_runtime.rs +++ b/sdk-libs/ctoken-sdk/src/compressible/decompress_runtime.rs @@ -138,12 +138,12 @@ where } }); - crate::ctoken::CreateCTokenAccountInfos { + crate::ctoken::CreateCTokenAccountCpi { payer: fee_payer.clone(), account: (*owner_info).clone(), mint: (*mint_info).clone(), owner: *authority.key, - compressible: Some(crate::ctoken::CompressibleParamsInfos { + compressible: Some(crate::ctoken::CompressibleParamsCpi { compressible_config: ctoken_config.clone(), rent_sponsor: ctoken_rent_sponsor.clone(), system_program: cpi_accounts diff --git a/sdk-libs/ctoken-sdk/src/compressible/mod.rs b/sdk-libs/ctoken-sdk/src/compressible/mod.rs index 77e5b67aae..9e47dd867d 100644 --- a/sdk-libs/ctoken-sdk/src/compressible/mod.rs +++ b/sdk-libs/ctoken-sdk/src/compressible/mod.rs @@ -1,7 +1,7 @@ //! Compressible token utilities for runtime decompression. #[cfg(feature = "compressible")] -pub mod decompress_runtime; +mod decompress_runtime; #[cfg(feature = "compressible")] -pub use decompress_runtime::{process_decompress_tokens_runtime, CTokenSeedProvider}; +pub use decompress_runtime::*; diff --git a/sdk-libs/ctoken-sdk/src/constants.rs b/sdk-libs/ctoken-sdk/src/constants.rs new file mode 100644 index 0000000000..08929094f3 --- /dev/null +++ b/sdk-libs/ctoken-sdk/src/constants.rs @@ -0,0 +1,25 @@ +use solana_pubkey::Pubkey; + +pub const SPL_TOKEN_PROGRAM_ID: Pubkey = + Pubkey::new_from_array(light_compressed_token_types::SPL_TOKEN_PROGRAM_ID); + +pub const SPL_TOKEN_2022_PROGRAM_ID: Pubkey = + Pubkey::new_from_array(light_compressed_token_types::SPL_TOKEN_2022_PROGRAM_ID); + +pub const LIGHT_SYSTEM_PROGRAM_ID: Pubkey = + Pubkey::new_from_array(light_compressed_token_types::LIGHT_SYSTEM_PROGRAM_ID); + +pub const ACCOUNT_COMPRESSION_PROGRAM_ID: Pubkey = + Pubkey::new_from_array(light_compressed_token_types::ACCOUNT_COMPRESSION_PROGRAM_ID); + +pub const ACCOUNT_COMPRESSION_AUTHORITY_PDA: Pubkey = + Pubkey::new_from_array(light_compressed_token_types::ACCOUNT_COMPRESSION_AUTHORITY_PDA); + +pub const NOOP_PROGRAM_ID: Pubkey = + Pubkey::new_from_array(light_compressed_token_types::NOOP_PROGRAM_ID); + +pub const CPI_AUTHORITY_PDA: Pubkey = + Pubkey::new_from_array(light_compressed_token_types::CPI_AUTHORITY_PDA); + +pub const CTOKEN_PROGRAM_ID: Pubkey = + Pubkey::new_from_array(light_compressed_token_types::PROGRAM_ID); diff --git a/sdk-libs/ctoken-sdk/src/ctoken/close.rs b/sdk-libs/ctoken-sdk/src/ctoken/close.rs index 2dbafb90e5..9bfe026d6c 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/close.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/close.rs @@ -6,7 +6,19 @@ use solana_pubkey::Pubkey; use crate::ctoken::RENT_SPONSOR; -pub struct CloseAccount { +/// # Create a close ctoken account instruction: +/// ```rust +/// # use solana_pubkey::Pubkey; +/// # use light_ctoken_sdk::ctoken::{CloseCTokenAccount, CTOKEN_PROGRAM_ID}; +/// # let account = Pubkey::new_unique(); +/// # let destination = Pubkey::new_unique(); +/// # let owner = Pubkey::new_unique(); +/// let instruction = +/// CloseCTokenAccount::new(CTOKEN_PROGRAM_ID, account, destination, owner) +/// .instruction()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct CloseCTokenAccount { pub token_program: Pubkey, pub account: Pubkey, pub destination: Pubkey, @@ -14,7 +26,7 @@ pub struct CloseAccount { pub rent_sponsor: Option, } -impl CloseAccount { +impl CloseCTokenAccount { pub fn new(token_program: Pubkey, account: Pubkey, destination: Pubkey, owner: Pubkey) -> Self { Self { token_program, @@ -53,7 +65,27 @@ impl CloseAccount { } } -pub struct CloseAccountInfos<'info> { +/// # Close a ctoken account via CPI: +/// ```rust,no_run +/// # use light_ctoken_sdk::ctoken::CloseCTokenAccountCpi; +/// # use solana_account_info::AccountInfo; +/// # let token_program: AccountInfo = todo!(); +/// # let account: AccountInfo = todo!(); +/// # let destination: AccountInfo = todo!(); +/// # let owner: AccountInfo = todo!(); +/// // Use ctoken::RENT_SPONSOR or ctoken::rent_sponsor_pda() to get the protocol rent sponsor. +/// # let rent_sponsor: AccountInfo = todo!(); +/// CloseCTokenAccountCpi { +/// token_program, +/// account, +/// destination, +/// owner, +/// rent_sponsor: Some(rent_sponsor), +/// } +/// .invoke()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct CloseCTokenAccountCpi<'info> { pub token_program: AccountInfo<'info>, pub account: AccountInfo<'info>, pub destination: AccountInfo<'info>, @@ -61,9 +93,9 @@ pub struct CloseAccountInfos<'info> { pub rent_sponsor: Option>, } -impl<'info> CloseAccountInfos<'info> { +impl<'info> CloseCTokenAccountCpi<'info> { pub fn instruction(&self) -> Result { - CloseAccount::from(self).instruction() + CloseCTokenAccount::from(self).instruction() } pub fn invoke(self) -> Result<(), ProgramError> { @@ -89,8 +121,8 @@ impl<'info> CloseAccountInfos<'info> { } } -impl<'info> From<&CloseAccountInfos<'info>> for CloseAccount { - fn from(account_infos: &CloseAccountInfos<'info>) -> Self { +impl<'info> From<&CloseCTokenAccountCpi<'info>> for CloseCTokenAccount { + fn from(account_infos: &CloseCTokenAccountCpi<'info>) -> Self { Self { token_program: *account_infos.token_program.key, account: *account_infos.account.key, diff --git a/sdk-libs/ctoken-sdk/src/ctoken/compressible.rs b/sdk-libs/ctoken-sdk/src/ctoken/compressible.rs index 365e0ebcf4..b3ecb8c322 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/compressible.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/compressible.rs @@ -6,10 +6,30 @@ use solana_pubkey::Pubkey; use crate::ctoken::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; +/// Parameters for creating compressible ctoken accounts. +/// +/// Compressible accounts have sponsored rent and can be compressed to compressed +/// token accounts when their lamports balance is insufficient. +/// +/// Default values are: +/// - 24 hours rent +/// - lamports for 3 hours rent (paid on transfer when account rent is insufficient to cover the next 2 epochs) +/// - Protocol rent sponsor +/// - TokenDataVersion::ShaFlat token data hashing (only sha is supported for compressible accounts) +/// +/// # Example +/// ```rust +/// use light_ctoken_sdk::ctoken::CompressibleParams; +/// +/// let params = CompressibleParams::new(); +/// ``` #[derive(Debug, Clone)] pub struct CompressibleParams { pub token_account_version: TokenDataVersion, pub pre_pay_num_epochs: u8, + /// Number of lamports transferred on a write operation (eg transfer) when account rent is insufficient to cover the next 2 rent-epochs. + /// Default: 766 lamports for 3 hours rent. + /// These lamports keep the ctoken account perpetually funded when used. pub lamports_per_write: Option, pub compress_to_account_pubkey: Option, pub compressible_config: Pubkey, @@ -31,9 +51,10 @@ impl Default for CompressibleParams { impl CompressibleParams { /// Creates a new `CompressibleParams` with default values. - /// - /// Use builder methods to customize: - /// - [`compress_to_pubkey`](Self::compress_to_pubkey) - set the destination for compression + /// - 24 hours rent + /// - 3 hours top up (paid on transfer when account rent is insufficient to cover the next 2 epochs) + /// - Protocol rent sponsor + /// - TokenDataVersion::ShaFlat token data hashing (only sha is supported for compressible accounts) pub fn new() -> Self { Self::default() } @@ -45,7 +66,24 @@ impl CompressibleParams { } } -pub struct CompressibleParamsInfos<'info> { +/// Parameters for creating compressible ctoken accounts via CPI. +/// +/// # Example +/// ```rust,no_run +/// # use light_ctoken_sdk::ctoken::CompressibleParamsCpi; +/// # use solana_account_info::AccountInfo; +/// // Use ctoken::COMPRESSIBLE_CONFIG_V1 or ctoken::config_pda() to get the protocol config. +/// // Use ctoken::RENT_SPONSOR or ctoken::rent_sponsor_pda() to get the protocol rent sponsor. +/// # let compressible_config: AccountInfo = todo!(); +/// # let rent_sponsor: AccountInfo = todo!(); +/// # let system_program: AccountInfo = todo!(); +/// let params = CompressibleParamsCpi::new( +/// compressible_config, +/// rent_sponsor, +/// system_program, +/// ); +/// ``` +pub struct CompressibleParamsCpi<'info> { pub compressible_config: AccountInfo<'info>, pub rent_sponsor: AccountInfo<'info>, pub system_program: AccountInfo<'info>, @@ -55,7 +93,7 @@ pub struct CompressibleParamsInfos<'info> { pub token_account_version: TokenDataVersion, } -impl<'info> CompressibleParamsInfos<'info> { +impl<'info> CompressibleParamsCpi<'info> { pub fn new( compressible_config: AccountInfo<'info>, rent_sponsor: AccountInfo<'info>, diff --git a/sdk-libs/ctoken-sdk/src/ctoken/create.rs b/sdk-libs/ctoken-sdk/src/ctoken/create.rs index 6f468f27b3..ee49250a52 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/create.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/create.rs @@ -9,8 +9,21 @@ use solana_instruction::{AccountMeta, Instruction}; use solana_program_error::ProgramError; use solana_pubkey::Pubkey; -use crate::ctoken::{compressible::CompressibleParamsInfos, CompressibleParams}; +use crate::ctoken::{compressible::CompressibleParamsCpi, CompressibleParams}; +/// # Create a create ctoken account instruction: +/// ```rust +/// # use solana_pubkey::Pubkey; +/// # use light_ctoken_sdk::ctoken::CreateCTokenAccount; +/// # let payer = Pubkey::new_unique(); +/// # let account = Pubkey::new_unique(); +/// # let mint = Pubkey::new_unique(); +/// # let owner = Pubkey::new_unique(); +/// let instruction = +/// CreateCTokenAccount::new(payer, account, mint, owner) +/// .instruction()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` #[derive(Debug, Clone)] pub struct CreateCTokenAccount { pub payer: Pubkey, @@ -83,28 +96,48 @@ impl CreateCTokenAccount { }; Ok(Instruction { - program_id: Pubkey::from(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::from(light_ctoken_interface::CTOKEN_PROGRAM_ID), accounts, data, }) } } -pub struct CreateCTokenAccountInfos<'info> { +/// # Create a ctoken account via CPI: +/// ```rust,no_run +/// # use light_ctoken_sdk::ctoken::{CreateCTokenAccountCpi, CompressibleParamsCpi}; +/// # use solana_account_info::AccountInfo; +/// # use solana_pubkey::Pubkey; +/// # let payer: AccountInfo = todo!(); +/// # let account: AccountInfo = todo!(); +/// # let mint: AccountInfo = todo!(); +/// # let owner: Pubkey = todo!(); +/// # let compressible: CompressibleParamsCpi = todo!(); +/// CreateCTokenAccountCpi { +/// payer, +/// account, +/// mint, +/// owner, +/// compressible: Some(compressible), +/// } +/// .invoke()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct CreateCTokenAccountCpi<'info> { pub payer: AccountInfo<'info>, pub account: AccountInfo<'info>, pub mint: AccountInfo<'info>, pub owner: Pubkey, - pub compressible: Option>, + pub compressible: Option>, } -impl<'info> CreateCTokenAccountInfos<'info> { +impl<'info> CreateCTokenAccountCpi<'info> { pub fn new( payer: AccountInfo<'info>, account: AccountInfo<'info>, mint: AccountInfo<'info>, owner: Pubkey, - compressible: CompressibleParamsInfos<'info>, + compressible: CompressibleParamsCpi<'info>, ) -> Self { Self { payer, @@ -156,8 +189,8 @@ impl<'info> CreateCTokenAccountInfos<'info> { } } -impl<'info> From<&CreateCTokenAccountInfos<'info>> for CreateCTokenAccount { - fn from(account_infos: &CreateCTokenAccountInfos<'info>) -> Self { +impl<'info> From<&CreateCTokenAccountCpi<'info>> for CreateCTokenAccount { + fn from(account_infos: &CreateCTokenAccountCpi<'info>) -> Self { Self { payer: *account_infos.payer.key, account: *account_infos.account.key, diff --git a/sdk-libs/ctoken-sdk/src/ctoken/create_ata.rs b/sdk-libs/ctoken-sdk/src/ctoken/create_ata.rs index 20a9381241..d76c9c9f74 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/create_ata.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/create_ata.rs @@ -9,7 +9,7 @@ use solana_instruction::{AccountMeta, Instruction}; use solana_program_error::ProgramError; use solana_pubkey::Pubkey; -use crate::ctoken::{compressible::CompressibleParamsInfos, CompressibleParams}; +use crate::ctoken::{compressible::CompressibleParamsCpi, CompressibleParams}; const CREATE_ATA_DISCRIMINATOR: u8 = 100; const CREATE_ATA_IDEMPOTENT_DISCRIMINATOR: u8 = 102; @@ -18,13 +18,25 @@ pub fn derive_ctoken_ata(owner: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) { Pubkey::find_program_address( &[ owner.as_ref(), - light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID.as_ref(), + light_ctoken_interface::CTOKEN_PROGRAM_ID.as_ref(), mint.as_ref(), ], - &Pubkey::from(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + &Pubkey::from(light_ctoken_interface::CTOKEN_PROGRAM_ID), ) } +/// # Create an associated ctoken account instruction: +/// ```rust +/// # use solana_pubkey::Pubkey; +/// # use light_ctoken_sdk::ctoken::CreateAssociatedTokenAccount; +/// # let payer = Pubkey::new_unique(); +/// # let owner = Pubkey::new_unique(); +/// # let mint = Pubkey::new_unique(); +/// let instruction = +/// CreateAssociatedTokenAccount::new(payer, owner, mint) +/// .instruction()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` #[derive(Debug, Clone)] pub struct CreateAssociatedTokenAccount { pub payer: Pubkey, @@ -126,25 +138,49 @@ impl CreateAssociatedTokenAccount { } Ok(Instruction { - program_id: Pubkey::from(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::from(light_ctoken_interface::CTOKEN_PROGRAM_ID), accounts, data, }) } } -pub struct CreateAssociatedTokenAccountInfos<'info> { +/// # Create an associated ctoken account via CPI: +/// ```rust,no_run +/// # use light_ctoken_sdk::ctoken::{CreateAssociatedTokenAccountCpi, CompressibleParamsCpi}; +/// # use solana_account_info::AccountInfo; +/// # let owner: AccountInfo = todo!(); +/// # let mint: AccountInfo = todo!(); +/// # let payer: AccountInfo = todo!(); +/// # let associated_token_account: AccountInfo = todo!(); +/// # let system_program: AccountInfo = todo!(); +/// # let bump: u8 = todo!(); +/// # let compressible: CompressibleParamsCpi = todo!(); +/// CreateAssociatedTokenAccountCpi { +/// owner, +/// mint, +/// payer, +/// associated_token_account, +/// system_program, +/// bump, +/// compressible: Some(compressible), +/// idempotent: true, +/// } +/// .invoke()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct CreateAssociatedTokenAccountCpi<'info> { pub owner: AccountInfo<'info>, pub mint: AccountInfo<'info>, pub payer: AccountInfo<'info>, pub associated_token_account: AccountInfo<'info>, pub system_program: AccountInfo<'info>, pub bump: u8, - pub compressible: Option>, + pub compressible: Option>, pub idempotent: bool, } -impl<'info> CreateAssociatedTokenAccountInfos<'info> { +impl<'info> CreateAssociatedTokenAccountCpi<'info> { pub fn instruction(&self) -> Result { CreateAssociatedTokenAccount::from(self).instruction() } @@ -200,8 +236,8 @@ impl<'info> CreateAssociatedTokenAccountInfos<'info> { } } -impl<'info> From<&CreateAssociatedTokenAccountInfos<'info>> for CreateAssociatedTokenAccount { - fn from(account_infos: &CreateAssociatedTokenAccountInfos<'info>) -> Self { +impl<'info> From<&CreateAssociatedTokenAccountCpi<'info>> for CreateAssociatedTokenAccount { + fn from(account_infos: &CreateAssociatedTokenAccountCpi<'info>) -> Self { Self { payer: *account_infos.payer.key, owner: *account_infos.owner.key, diff --git a/sdk-libs/ctoken-sdk/src/ctoken/create_cmint.rs b/sdk-libs/ctoken-sdk/src/ctoken/create_cmint.rs index e691885941..2cac65a413 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/create_cmint.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/create_cmint.rs @@ -22,6 +22,7 @@ use crate::{ ctoken::SystemAccountInfos, }; +/// Parameters for creating a compressed mint. #[derive(Debug, Clone)] pub struct CreateCMintParams { pub decimals: u8, @@ -34,9 +35,49 @@ pub struct CreateCMintParams { pub extensions: Option>, } +/// # Create a compressed mint instruction: +/// ```rust,no_run +/// # use solana_pubkey::Pubkey; +/// use light_ctoken_sdk::ctoken::{ +/// CreateCMint, CreateCMintParams, derive_cmint_compressed_address, find_cmint_address, +/// }; +/// # use light_ctoken_sdk::CompressedProof; +/// # let mint_seed_pubkey = Pubkey::new_unique(); +/// # let payer = Pubkey::new_unique(); +/// # let address_tree = Pubkey::new_unique(); +/// # let output_queue = Pubkey::new_unique(); +/// # let mint_authority = Pubkey::new_unique(); +/// # let address_merkle_tree_root_index: u16 = 0; +/// # let proof: CompressedProof = todo!(); +/// +/// // Derive addresses +/// let compression_address = derive_cmint_compressed_address(&mint_seed_pubkey, &address_tree); +/// let mint = find_cmint_address(&mint_seed_pubkey).0; +/// +/// let params = CreateCMintParams { +/// decimals: 9, +/// address_merkle_tree_root_index, // from rpc.get_validity_proof +/// mint_authority, +/// proof, // from rpc.get_validity_proof +/// compression_address, +/// mint, +/// freeze_authority: None, +/// extensions: None, +/// }; +/// let instruction = CreateCMint::new( +/// params, +/// mint_seed_pubkey, +/// payer, +/// address_tree, +/// output_queue, +/// ).instruction()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` #[derive(Debug, Clone)] pub struct CreateCMint { - pub mint_signer: Pubkey, + /// Used as seed for the mint address. + /// The mint seed account must be a signer. + pub mint_seed_pubkey: Pubkey, pub payer: Pubkey, pub address_tree_pubkey: Pubkey, pub output_queue: Pubkey, @@ -48,13 +89,13 @@ pub struct CreateCMint { impl CreateCMint { pub fn new( params: CreateCMintParams, - mint_signer: Pubkey, + mint_seed_pubkey: Pubkey, payer: Pubkey, address_tree_pubkey: Pubkey, output_queue: Pubkey, ) -> Self { Self { - mint_signer, + mint_seed_pubkey, payer, address_tree_pubkey, output_queue, @@ -104,7 +145,7 @@ impl CreateCMint { let mut meta_config = MintActionMetaConfig::new_create_mint( self.payer, self.params.mint_authority, - self.mint_signer, + self.mint_seed_pubkey, self.address_tree_pubkey, self.output_queue, ); @@ -119,7 +160,7 @@ impl CreateCMint { .map_err(|e| ProgramError::BorshIoError(e.to_string()))?; Ok(Instruction { - program_id: Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID), accounts: account_metas, data, }) @@ -252,7 +293,7 @@ impl CreateCompressedMintCpiWrite { .map_err(|e| ProgramError::BorshIoError(e.to_string()))?; Ok(Instruction { - program_id: Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID), accounts: account_metas, data, }) @@ -260,10 +301,36 @@ impl CreateCompressedMintCpiWrite { } // ============================================================================ -// AccountInfos Struct: CreateCMintAccountInfos (for CPI usage) +// AccountInfos Struct: CreateCMintCpi (for CPI usage) // ============================================================================ -pub struct CreateCMintAccountInfos<'info> { - pub mint_signer: AccountInfo<'info>, + +/// # Create a compressed mint via CPI: +/// ```rust,no_run +/// # use light_ctoken_sdk::ctoken::{CreateCMintCpi, CreateCMintParams, SystemAccountInfos}; +/// # use solana_account_info::AccountInfo; +/// # let mint_seed: AccountInfo = todo!(); +/// # let authority: AccountInfo = todo!(); +/// # let payer: AccountInfo = todo!(); +/// # let address_tree: AccountInfo = todo!(); +/// # let output_queue: AccountInfo = todo!(); +/// # let system_accounts: SystemAccountInfos = todo!(); +/// # let params: CreateCMintParams = todo!(); +/// CreateCMintCpi { +/// mint_seed, +/// authority, +/// payer, +/// address_tree, +/// output_queue, +/// system_accounts, +/// cpi_context: None, +/// cpi_context_account: None, +/// params, +/// } +/// .invoke()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct CreateCMintCpi<'info> { + pub mint_seed: AccountInfo<'info>, /// The authority for the mint (will be stored as mint_authority). pub authority: AccountInfo<'info>, /// The fee payer for the transaction. @@ -276,9 +343,9 @@ pub struct CreateCMintAccountInfos<'info> { pub params: CreateCMintParams, } -impl<'info> CreateCMintAccountInfos<'info> { - pub fn new_with_address( - mint_signer: AccountInfo<'info>, +impl<'info> CreateCMintCpi<'info> { + pub fn new( + mint_seed: AccountInfo<'info>, authority: AccountInfo<'info>, payer: AccountInfo<'info>, address_tree: AccountInfo<'info>, @@ -287,7 +354,7 @@ impl<'info> CreateCMintAccountInfos<'info> { params: CreateCMintParams, ) -> Self { Self { - mint_signer, + mint_seed, authority, payer, address_tree, @@ -309,7 +376,7 @@ impl<'info> CreateCMintAccountInfos<'info> { // Account order must match the instruction's account metas order (from get_mint_action_instruction_account_metas) let mut account_infos = vec![ self.system_accounts.light_system_program, // Index 0 - self.mint_signer, // Index 1 + self.mint_seed, // Index 1 self.authority, // Index 2 (authority) self.payer, // Index 3 (fee_payer) self.system_accounts.cpi_authority_pda, @@ -334,7 +401,7 @@ impl<'info> CreateCMintAccountInfos<'info> { // Account order must match the instruction's account metas order (from get_mint_action_instruction_account_metas) let mut account_infos = vec![ self.system_accounts.light_system_program, // Index 0 - self.mint_signer, // Index 1 + self.mint_seed, // Index 1 self.authority, // Index 2 (authority) self.payer, // Index 3 (fee_payer) self.system_accounts.cpi_authority_pda, @@ -354,20 +421,20 @@ impl<'info> CreateCMintAccountInfos<'info> { } } -impl<'info> TryFrom<&CreateCMintAccountInfos<'info>> for CreateCMint { +impl<'info> TryFrom<&CreateCMintCpi<'info>> for CreateCMint { type Error = ProgramError; - fn try_from(account_infos: &CreateCMintAccountInfos<'info>) -> Result { + fn try_from(account_infos: &CreateCMintCpi<'info>) -> Result { if account_infos.params.mint_authority != *account_infos.authority.key { solana_msg::msg!( - "CreateCMintAccountInfos: params.mint_authority ({}) does not match authority account ({})", + "CreateCMintCpi: params.mint_authority ({}) does not match authority account ({})", account_infos.params.mint_authority, account_infos.authority.key ); return Err(ProgramError::InvalidAccountData); } Ok(Self { - mint_signer: *account_infos.mint_signer.key, + mint_seed_pubkey: *account_infos.mint_seed.key, payer: *account_infos.payer.key, address_tree_pubkey: *account_infos.address_tree.key, output_queue: *account_infos.output_queue.key, @@ -382,10 +449,10 @@ impl<'info> TryFrom<&CreateCMintAccountInfos<'info>> for CreateCMint { } // ============================================================================ -// AccountInfos Struct: CreateCompressedMintCpiWriteInfos +// AccountInfos Struct: CreateCompressedMintCpiWriteCpi // ============================================================================ -pub struct CreateCompressedMintCpiWriteInfos<'info> { +pub struct CreateCompressedMintCpiWriteCpi<'info> { pub mint_signer: AccountInfo<'info>, pub authority: AccountInfo<'info>, pub payer: AccountInfo<'info>, @@ -394,7 +461,7 @@ pub struct CreateCompressedMintCpiWriteInfos<'info> { pub params: CreateCMintCpiWriteParams, } -impl<'info> CreateCompressedMintCpiWriteInfos<'info> { +impl<'info> CreateCompressedMintCpiWriteCpi<'info> { pub fn instruction(&self) -> Result { CreateCompressedMintCpiWrite::try_from(self)?.instruction() } @@ -415,16 +482,16 @@ impl<'info> CreateCompressedMintCpiWriteInfos<'info> { } } -impl<'info> TryFrom<&CreateCompressedMintCpiWriteInfos<'info>> for CreateCompressedMintCpiWrite { +impl<'info> TryFrom<&CreateCompressedMintCpiWriteCpi<'info>> for CreateCompressedMintCpiWrite { type Error = ProgramError; fn try_from( - account_infos: &CreateCompressedMintCpiWriteInfos<'info>, + account_infos: &CreateCompressedMintCpiWriteCpi<'info>, ) -> Result { // Validate that authority account matches params.mint_authority if account_infos.params.mint_authority != *account_infos.authority.key { solana_msg::msg!( - "CreateCompressedMintCpiWriteInfos: params.mint_authority ({}) does not match authority account ({})", + "CreateCompressedMintCpiWriteCpi: params.mint_authority ({}) does not match authority account ({})", account_infos.params.mint_authority, account_infos.authority.key ); @@ -444,14 +511,14 @@ impl<'info> TryFrom<&CreateCompressedMintCpiWriteInfos<'info>> for CreateCompres // ============================================================================ /// Derives the compressed mint address from the mint seed and address tree -pub fn derive_compressed_mint_address( +pub fn derive_cmint_compressed_address( mint_seed: &Pubkey, address_tree_pubkey: &Pubkey, ) -> [u8; 32] { light_compressed_account::address::derive_address( - &find_spl_mint_address(mint_seed).0.to_bytes(), + &find_cmint_address(mint_seed).0.to_bytes(), &address_tree_pubkey.to_bytes(), - &light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID, + &light_ctoken_interface::CTOKEN_PROGRAM_ID, ) } @@ -460,14 +527,14 @@ pub fn derive_cmint_from_spl_mint(mint: &Pubkey, address_tree_pubkey: &Pubkey) - light_compressed_account::address::derive_address( &mint.to_bytes(), &address_tree_pubkey.to_bytes(), - &light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID, + &light_ctoken_interface::CTOKEN_PROGRAM_ID, ) } -/// Finds the SPL mint address from a mint seed -pub fn find_spl_mint_address(mint_seed: &Pubkey) -> (Pubkey, u8) { +/// Finds the compressed mint (c-mint) address from a mint seed. +pub fn find_cmint_address(mint_seed: &Pubkey) -> (Pubkey, u8) { Pubkey::find_program_address( &[COMPRESSED_MINT_SEED, mint_seed.as_ref()], - &Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + &Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID), ) } diff --git a/sdk-libs/ctoken-sdk/src/ctoken/mint_to.rs b/sdk-libs/ctoken-sdk/src/ctoken/mint_to.rs index 3e12014ee6..5918c3968b 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/mint_to.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/mint_to.rs @@ -15,10 +15,7 @@ use crate::compressed_token::mint_action::{ MintActionMetaConfigCpiWrite, }; -// ============================================================================ -// Params Struct: MintToCTokenParams -// ============================================================================ - +/// Parameters for minting tokens to a ctoken account. #[derive(Debug, Clone)] pub struct MintToCTokenParams { pub compressed_mint_inputs: CompressedMintWithContext, @@ -54,10 +51,36 @@ impl MintToCTokenParams { } } -// ============================================================================ -// Builder Struct: MintToCToken -// ============================================================================ - +/// # Create a mint to ctoken instruction: +/// ```rust,no_run +/// # use solana_pubkey::Pubkey; +/// use light_ctoken_sdk::ctoken::{MintToCToken, MintToCTokenParams, CompressedMintWithContext}; +/// use light_ctoken_sdk::ValidityProof; +/// # let compressed_mint_with_context: CompressedMintWithContext = todo!(); +/// # let validity_proof: ValidityProof = todo!(); +/// # let mint_authority = Pubkey::new_unique(); +/// # let payer = Pubkey::new_unique(); +/// # let state_tree_pubkey = Pubkey::new_unique(); +/// # let input_queue = Pubkey::new_unique(); +/// # let output_queue = Pubkey::new_unique(); +/// # let ctoken_account = Pubkey::new_unique(); +/// +/// let params = MintToCTokenParams::new( +/// compressed_mint_with_context, // from rpc +/// 1000, // amount +/// mint_authority, +/// validity_proof, // from rpc +/// ); +/// let instruction = MintToCToken::new( +/// params, +/// payer, +/// state_tree_pubkey, +/// input_queue, +/// output_queue, +/// vec![ctoken_account], +/// ).instruction()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` #[derive(Debug, Clone)] pub struct MintToCToken { pub payer: Pubkey, @@ -139,7 +162,7 @@ impl MintToCToken { .map_err(|e| ProgramError::BorshIoError(e.to_string()))?; Ok(Instruction { - program_id: Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID), accounts: account_metas, data, }) @@ -249,7 +272,7 @@ impl MintToCTokenCpiWrite { .map_err(|e| ProgramError::BorshIoError(e.to_string()))?; Ok(Instruction { - program_id: Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID), accounts: account_metas, data, }) @@ -257,10 +280,37 @@ impl MintToCTokenCpiWrite { } // ============================================================================ -// AccountInfos Struct: MintToCTokenInfos (for CPI usage) +// AccountInfos Struct: MintToCTokenCpi (for CPI usage) // ============================================================================ -pub struct MintToCTokenInfos<'info> { +/// # Mint to ctoken account via CPI: +/// ```rust,no_run +/// # use light_ctoken_sdk::ctoken::{MintToCTokenCpi, MintToCTokenParams, SystemAccountInfos}; +/// # use solana_account_info::AccountInfo; +/// # let authority: AccountInfo = todo!(); +/// # let payer: AccountInfo = todo!(); +/// # let state_tree: AccountInfo = todo!(); +/// # let input_queue: AccountInfo = todo!(); +/// # let output_queue: AccountInfo = todo!(); +/// # let ctoken_accounts: Vec = todo!(); +/// # let system_accounts: SystemAccountInfos = todo!(); +/// # let params: MintToCTokenParams = todo!(); +/// MintToCTokenCpi { +/// authority, +/// payer, +/// state_tree, +/// input_queue, +/// output_queue, +/// ctoken_accounts, +/// system_accounts, +/// cpi_context: None, +/// cpi_context_account: None, +/// params, +/// } +/// .invoke()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct MintToCTokenCpi<'info> { /// The authority for the mint operation (mint_authority). pub authority: AccountInfo<'info>, /// The fee payer for the transaction. @@ -275,7 +325,7 @@ pub struct MintToCTokenInfos<'info> { pub params: MintToCTokenParams, } -impl<'info> MintToCTokenInfos<'info> { +impl<'info> MintToCTokenCpi<'info> { pub fn instruction(&self) -> Result { MintToCToken::try_from(self)?.instruction() } @@ -335,13 +385,13 @@ impl<'info> MintToCTokenInfos<'info> { } } -impl<'info> TryFrom<&MintToCTokenInfos<'info>> for MintToCToken { +impl<'info> TryFrom<&MintToCTokenCpi<'info>> for MintToCToken { type Error = ProgramError; - fn try_from(account_infos: &MintToCTokenInfos<'info>) -> Result { + fn try_from(account_infos: &MintToCTokenCpi<'info>) -> Result { if account_infos.params.mint_authority != *account_infos.authority.key { solana_msg::msg!( - "MintToCTokenInfos: params.mint_authority ({}) does not match authority account ({})", + "MintToCTokenCpi: params.mint_authority ({}) does not match authority account ({})", account_infos.params.mint_authority, account_infos.authority.key ); @@ -368,17 +418,17 @@ impl<'info> TryFrom<&MintToCTokenInfos<'info>> for MintToCToken { } // ============================================================================ -// AccountInfos Struct: MintToCTokenCpiWriteInfos +// AccountInfos Struct: MintToCTokenCpiWriteCpi // ============================================================================ -pub struct MintToCTokenCpiWriteInfos<'info> { +pub struct MintToCTokenCpiWriteCpi<'info> { pub payer: AccountInfo<'info>, pub cpi_context_account: AccountInfo<'info>, pub ctoken_accounts: Vec>, pub params: MintToCTokenCpiWriteParams, } -impl<'info> MintToCTokenCpiWriteInfos<'info> { +impl<'info> MintToCTokenCpiWriteCpi<'info> { pub fn instruction(&self) -> Result { MintToCTokenCpiWrite::from(self).instruction() } @@ -391,8 +441,8 @@ impl<'info> MintToCTokenCpiWriteInfos<'info> { } } -impl<'info> From<&MintToCTokenCpiWriteInfos<'info>> for MintToCTokenCpiWrite { - fn from(account_infos: &MintToCTokenCpiWriteInfos<'info>) -> Self { +impl<'info> From<&MintToCTokenCpiWriteCpi<'info>> for MintToCTokenCpiWrite { + fn from(account_infos: &MintToCTokenCpiWriteCpi<'info>) -> Self { Self { payer: *account_infos.payer.key, cpi_context_pubkey: *account_infos.cpi_context_account.key, diff --git a/sdk-libs/ctoken-sdk/src/ctoken/mod.rs b/sdk-libs/ctoken-sdk/src/ctoken/mod.rs index f2d360b794..068f3956a5 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/mod.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/mod.rs @@ -1,7 +1,65 @@ -//! High-level builders for compressed token operations. +//! High-level builders for ctoken operations. +//! +//! +//! ## Account Creation +//! +//! - [`CreateAssociatedTokenAccount`] - Create associated ctoken account (ATA) instruction +//! - [`CreateAssociatedTokenAccountCpi`] - Create associated ctoken account (ATA) via CPI +//! - [`CreateCTokenAccount`] - Create ctoken account instruction +//! - [`CreateCTokenAccountCpi`] - Create ctoken account via CPI +//! +//! ## Transfers +//! +//! - [`TransferInterfaceCpi`] - Transfer via CPI, auto-detect source/destination account types +//! +//! ## Close +//! +//! - [`CloseCTokenAccount`] - Create close ctoken account instruction +//! - [`CloseCTokenAccountCpi`] - Close ctoken account via CPI +//! +//! +//! ## Mint +//! +//! - [`CreateCMint`] - Create cMint +//! - [`MintToCToken`] - Mint tokens to ctoken accounts +//! +//! # Example: Create cToken Account Instruction +//! +//! ```rust +//! # use solana_pubkey::Pubkey; +//! use light_ctoken_sdk::ctoken::CreateAssociatedTokenAccount; +//! # let payer = Pubkey::new_unique(); +//! # let owner = Pubkey::new_unique(); +//! # let mint = Pubkey::new_unique(); +//! +//! let instruction = CreateAssociatedTokenAccount::new(payer, owner, mint) +//! .idempotent() +//! .instruction()?; +//! # Ok::<(), solana_program_error::ProgramError>(()) +//! ``` +//! +//! # Example: Create cToken Account CPI +//! +//! ```rust,ignore +//! use light_ctoken_sdk::ctoken::{CreateAssociatedTokenAccountCpi, CompressibleParamsCpi}; +//! +//! CreateAssociatedTokenAccountCpi { +//! owner: ctx.accounts.owner.to_account_info(), +//! mint: ctx.accounts.mint.to_account_info(), +//! payer: ctx.accounts.payer.to_account_info(), +//! associated_token_account: ctx.accounts.ctoken_account.to_account_info(), +//! system_program: ctx.accounts.system_program.to_account_info(), +//! bump, +//! compressible: Some(CompressibleParamsCpi::default_with_accounts( +//! ctx.accounts.compressible_config.to_account_info(), +//! ctx.accounts.rent_sponsor.to_account_info(), +//! ctx.accounts.system_program.to_account_info(), +//! )), +//! idempotent: true, +//! } +//! .invoke()?; +//! ``` //! -//! Provides instruction builders and CPI helpers for creating, transferring, -//! and managing compressed token accounts. mod close; mod compressible; @@ -15,26 +73,39 @@ mod transfer_interface; mod transfer_spl_ctoken; pub use close::*; -pub use compressible::{CompressibleParams, CompressibleParamsInfos}; +pub use compressible::{CompressibleParams, CompressibleParamsCpi}; pub use create::*; pub use create_ata::*; pub use create_cmint::*; use light_compressed_token_types::POOL_SEED; use light_compressible::config::CompressibleConfig; pub use light_ctoken_interface::{ - instructions::extensions::{compressible::CompressToPubkey, ExtensionInstructionData}, + instructions::{ + extensions::{compressible::CompressToPubkey, ExtensionInstructionData}, + mint_action::CompressedMintWithContext, + }, state::TokenDataVersion, }; pub use mint_to::*; use solana_account_info::AccountInfo; use solana_pubkey::{pubkey, Pubkey}; pub use transfer_ctoken::*; -pub use transfer_ctoken_spl::{TransferCtokenToSpl, TransferCtokenToSplAccountInfos}; -pub use transfer_interface::{SplInterface, TransferInterface}; -pub use transfer_spl_ctoken::{TransferSplToCtoken, TransferSplToCtokenAccountInfos}; +pub use transfer_ctoken_spl::{TransferCTokenToSpl, TransferCTokenToSplCpi}; +pub use transfer_interface::{SplInterface, TransferInterfaceCpi}; +pub use transfer_spl_ctoken::{TransferSplToCtoken, TransferSplToCtokenCpi}; -/// System account infos required for CPI operations to the Light Protocol. -/// These accounts are always required when executing compressed token operations (not for CPI write mode). +/// System accounts required for CPI operations to Light Protocol. +/// +/// Pass these accounts when invoking compressed token operations from your program. +/// +/// # Fields +/// +/// - `light_system_program` - Light System Program +/// - `cpi_authority_pda` - CPI authority (signs for your program) +/// - `registered_program_pda` - Your program's registration +/// - `account_compression_authority` - Compression authority +/// - `account_compression_program` - Account Compression Program +/// - `system_program` - Solana System Program pub struct SystemAccountInfos<'info> { pub light_system_program: AccountInfo<'info>, pub cpi_authority_pda: AccountInfo<'info>, @@ -81,6 +152,7 @@ impl Default for SystemAccounts { } } +/// Compressed Token Program ID: `cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m` pub const CTOKEN_PROGRAM_ID: Pubkey = pubkey!("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"); pub const CTOKEN_CPI_AUTHORITY: Pubkey = pubkey!("GXtd2izAiMJPwMEjfgTRH3d7k9mjn4Jq3JrWFv9gySYy"); @@ -99,7 +171,7 @@ pub fn cpi_authority() -> Pubkey { CTOKEN_CPI_AUTHORITY } -pub fn get_token_pool_address_and_bump(mint: &Pubkey) -> (Pubkey, u8) { +pub fn get_spl_interface_pda_and_bump(mint: &Pubkey) -> (Pubkey, u8) { Pubkey::find_program_address(&[POOL_SEED, mint.as_ref()], &CTOKEN_PROGRAM_ID) } @@ -116,10 +188,12 @@ pub fn get_associated_ctoken_address_and_bump(owner: &Pubkey, mint: &Pubkey) -> ) } +/// Returns the default compressible config PDA. pub fn config_pda() -> Pubkey { COMPRESSIBLE_CONFIG_V1 } +/// Returns the default rent sponsor PDA. pub fn rent_sponsor_pda() -> Pubkey { RENT_SPONSOR } diff --git a/sdk-libs/ctoken-sdk/src/ctoken/transfer_ctoken.rs b/sdk-libs/ctoken-sdk/src/ctoken/transfer_ctoken.rs index eaa98b2935..22a9f7961a 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/transfer_ctoken.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/transfer_ctoken.rs @@ -5,7 +5,23 @@ use solana_instruction::{AccountMeta, Instruction}; use solana_program_error::ProgramError; use solana_pubkey::Pubkey; -pub struct TransferCtoken { +/// # Create a transfer ctoken instruction: +/// ```rust +/// # use solana_pubkey::Pubkey; +/// # use light_ctoken_sdk::ctoken::TransferCToken; +/// # let source = Pubkey::new_unique(); +/// # let destination = Pubkey::new_unique(); +/// # let authority = Pubkey::new_unique(); +/// let instruction = TransferCToken { +/// source, +/// destination, +/// amount: 100, +/// authority, +/// max_top_up: None, +/// }.instruction()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct TransferCToken { pub source: Pubkey, pub destination: Pubkey, pub amount: u64, @@ -15,7 +31,24 @@ pub struct TransferCtoken { pub max_top_up: Option, } -pub struct TransferCtokenAccountInfos<'info> { +/// # Transfer ctoken via CPI: +/// ```rust,no_run +/// # use light_ctoken_sdk::ctoken::TransferCTokenCpi; +/// # use solana_account_info::AccountInfo; +/// # let source: AccountInfo = todo!(); +/// # let destination: AccountInfo = todo!(); +/// # let authority: AccountInfo = todo!(); +/// TransferCTokenCpi { +/// source, +/// destination, +/// amount: 100, +/// authority, +/// max_top_up: None, +/// } +/// .invoke()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct TransferCTokenCpi<'info> { pub source: AccountInfo<'info>, pub destination: AccountInfo<'info>, pub amount: u64, @@ -24,26 +57,26 @@ pub struct TransferCtokenAccountInfos<'info> { pub max_top_up: Option, } -impl<'info> TransferCtokenAccountInfos<'info> { +impl<'info> TransferCTokenCpi<'info> { pub fn instruction(&self) -> Result { - TransferCtoken::from(self).instruction() + TransferCToken::from(self).instruction() } pub fn invoke(self) -> Result<(), ProgramError> { - let instruction = TransferCtoken::from(&self).instruction()?; + let instruction = TransferCToken::from(&self).instruction()?; let account_infos = [self.source, self.destination, self.authority]; invoke(&instruction, &account_infos) } pub fn invoke_signed(self, signer_seeds: &[&[&[u8]]]) -> Result<(), ProgramError> { - let instruction = TransferCtoken::from(&self).instruction()?; + let instruction = TransferCToken::from(&self).instruction()?; let account_infos = [self.source, self.destination, self.authority]; invoke_signed(&instruction, &account_infos, signer_seeds) } } -impl<'info> From<&TransferCtokenAccountInfos<'info>> for TransferCtoken { - fn from(account_infos: &TransferCtokenAccountInfos<'info>) -> Self { +impl<'info> From<&TransferCTokenCpi<'info>> for TransferCToken { + fn from(account_infos: &TransferCTokenCpi<'info>) -> Self { Self { source: *account_infos.source.key, destination: *account_infos.destination.key, @@ -54,7 +87,7 @@ impl<'info> From<&TransferCtokenAccountInfos<'info>> for TransferCtoken { } } -impl TransferCtoken { +impl TransferCToken { pub fn instruction(self) -> Result { Ok(Instruction { program_id: Pubkey::from(C_TOKEN_PROGRAM_ID), 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 5831c0939e..ce78ecded2 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/transfer_ctoken_spl.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/transfer_ctoken_spl.rs @@ -14,7 +14,31 @@ use crate::compressed_token::{ CTokenAccount2, }; -pub struct TransferCtokenToSpl { +/// # Create a transfer ctoken to SPL instruction: +/// ```rust +/// # use solana_pubkey::Pubkey; +/// # use light_ctoken_sdk::ctoken::TransferCTokenToSpl; +/// # let source_ctoken_account = Pubkey::new_unique(); +/// # let destination_spl_token_account = Pubkey::new_unique(); +/// # let authority = Pubkey::new_unique(); +/// # let mint = Pubkey::new_unique(); +/// # let payer = Pubkey::new_unique(); +/// # let spl_interface_pda = Pubkey::new_unique(); +/// # let spl_token_program = Pubkey::new_unique(); +/// let instruction = TransferCTokenToSpl { +/// source_ctoken_account, +/// destination_spl_token_account, +/// amount: 100, +/// authority, +/// mint, +/// payer, +/// spl_interface_pda, +/// spl_interface_pda_bump: 255, +/// spl_token_program, +/// }.instruction()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct TransferCTokenToSpl { pub source_ctoken_account: Pubkey, pub destination_spl_token_account: Pubkey, pub amount: u64, @@ -26,7 +50,34 @@ pub struct TransferCtokenToSpl { pub spl_token_program: Pubkey, } -pub struct TransferCtokenToSplAccountInfos<'info> { +/// # Transfer ctoken to SPL via CPI: +/// ```rust,no_run +/// # use light_ctoken_sdk::ctoken::TransferCTokenToSplCpi; +/// # use solana_account_info::AccountInfo; +/// # let source_ctoken_account: AccountInfo = todo!(); +/// # let destination_spl_token_account: AccountInfo = todo!(); +/// # let authority: AccountInfo = todo!(); +/// # let mint: AccountInfo = todo!(); +/// # let payer: AccountInfo = todo!(); +/// # let spl_interface_pda: AccountInfo = todo!(); +/// # let spl_token_program: AccountInfo = todo!(); +/// # let compressed_token_program_authority: AccountInfo = todo!(); +/// TransferCTokenToSplCpi { +/// source_ctoken_account, +/// destination_spl_token_account, +/// amount: 100, +/// authority, +/// mint, +/// payer, +/// spl_interface_pda, +/// spl_interface_pda_bump: 255, +/// spl_token_program, +/// compressed_token_program_authority, +/// } +/// .invoke()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct TransferCTokenToSplCpi<'info> { pub source_ctoken_account: AccountInfo<'info>, pub destination_spl_token_account: AccountInfo<'info>, pub amount: u64, @@ -39,13 +90,13 @@ pub struct TransferCtokenToSplAccountInfos<'info> { pub compressed_token_program_authority: AccountInfo<'info>, } -impl<'info> TransferCtokenToSplAccountInfos<'info> { +impl<'info> TransferCTokenToSplCpi<'info> { pub fn instruction(&self) -> Result { - TransferCtokenToSpl::from(self).instruction() + TransferCTokenToSpl::from(self).instruction() } pub fn invoke(self) -> Result<(), ProgramError> { - let instruction = TransferCtokenToSpl::from(&self).instruction()?; + let instruction = TransferCTokenToSpl::from(&self).instruction()?; // Account order must match instruction metas: cpi_authority_pda, fee_payer, packed_accounts... let account_infos = [ self.compressed_token_program_authority, // CPI authority PDA (first) @@ -61,7 +112,7 @@ impl<'info> TransferCtokenToSplAccountInfos<'info> { } pub fn invoke_signed(self, signer_seeds: &[&[&[u8]]]) -> Result<(), ProgramError> { - let instruction = TransferCtokenToSpl::from(&self).instruction()?; + let instruction = TransferCTokenToSpl::from(&self).instruction()?; // Account order must match instruction metas: cpi_authority_pda, fee_payer, packed_accounts... let account_infos = [ self.compressed_token_program_authority, // CPI authority PDA (first) @@ -77,8 +128,8 @@ impl<'info> TransferCtokenToSplAccountInfos<'info> { } } -impl<'info> From<&TransferCtokenToSplAccountInfos<'info>> for TransferCtokenToSpl { - fn from(account_infos: &TransferCtokenToSplAccountInfos<'info>) -> Self { +impl<'info> From<&TransferCTokenToSplCpi<'info>> for TransferCTokenToSpl { + fn from(account_infos: &TransferCTokenToSplCpi<'info>) -> Self { Self { source_ctoken_account: *account_infos.source_ctoken_account.key, destination_spl_token_account: *account_infos.destination_spl_token_account.key, @@ -93,7 +144,7 @@ impl<'info> From<&TransferCtokenToSplAccountInfos<'info>> for TransferCtokenToSp } } -impl TransferCtokenToSpl { +impl TransferCTokenToSpl { #[profile] pub fn instruction(self) -> Result { let packed_accounts = vec![ diff --git a/sdk-libs/ctoken-sdk/src/ctoken/transfer_interface.rs b/sdk-libs/ctoken-sdk/src/ctoken/transfer_interface.rs index 44af3a0f46..4f7f648c4a 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/transfer_interface.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/transfer_interface.rs @@ -2,11 +2,10 @@ use solana_account_info::AccountInfo; use solana_program_error::ProgramError; use super::{ - transfer_ctoken::TransferCtokenAccountInfos, - transfer_ctoken_spl::TransferCtokenToSplAccountInfos, - transfer_spl_ctoken::TransferSplToCtokenAccountInfos, + transfer_ctoken::TransferCTokenCpi, transfer_ctoken_spl::TransferCTokenToSplCpi, + transfer_spl_ctoken::TransferSplToCtokenCpi, }; -use crate::{error::TokenSdkError, utils::is_ctoken_account}; +use crate::{error::CTokenSdkError, utils::is_ctoken_account}; /// Required accounts to interface between ctoken and SPL token accounts. pub struct SplInterface<'info> { @@ -16,7 +15,7 @@ pub struct SplInterface<'info> { pub spl_interface_pda_bump: u8, } -pub struct TransferInterface<'info> { +pub struct TransferInterfaceCpi<'info> { pub amount: u64, pub source_account: AccountInfo<'info>, pub destination_account: AccountInfo<'info>, @@ -26,7 +25,7 @@ pub struct TransferInterface<'info> { pub spl_interface: Option>, } -impl<'info> TransferInterface<'info> { +impl<'info> TransferInterfaceCpi<'info> { /// # Arguments /// * `amount` - Amount to transfer /// * `source_account` - Source token account (can be ctoken or SPL) @@ -66,16 +65,17 @@ impl<'info> TransferInterface<'info> { spl_interface_pda_bump: Option, ) -> Result { let mint = - mint.ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingMintAccount.into()))?; + mint.ok_or_else(|| ProgramError::Custom(CTokenSdkError::MissingMintAccount.into()))?; let spl_token_program = spl_token_program - .ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingSplTokenProgram.into()))?; + .ok_or_else(|| ProgramError::Custom(CTokenSdkError::MissingSplTokenProgram.into()))?; let spl_interface_pda = spl_interface_pda - .ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingTokenPoolPda.into()))?; + .ok_or_else(|| ProgramError::Custom(CTokenSdkError::MissingSplInterfacePda.into()))?; - let spl_interface_pda_bump = spl_interface_pda_bump - .ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingTokenPoolPdaBump.into()))?; + let spl_interface_pda_bump = spl_interface_pda_bump.ok_or_else(|| { + ProgramError::Custom(CTokenSdkError::MissingSplInterfacePdaBump.into()) + })?; self.spl_interface = Some(SplInterface { mint, @@ -92,12 +92,12 @@ impl<'info> TransferInterface<'info> { /// * `CannotDetermineAccountType` - If account type cannot be determined pub fn invoke(self) -> Result<(), ProgramError> { let source_is_ctoken = is_ctoken_account(&self.source_account) - .map_err(|_| ProgramError::Custom(TokenSdkError::CannotDetermineAccountType.into()))?; + .map_err(|_| ProgramError::Custom(CTokenSdkError::CannotDetermineAccountType.into()))?; let dest_is_ctoken = is_ctoken_account(&self.destination_account) - .map_err(|_| ProgramError::Custom(TokenSdkError::CannotDetermineAccountType.into()))?; + .map_err(|_| ProgramError::Custom(CTokenSdkError::CannotDetermineAccountType.into()))?; match (source_is_ctoken, dest_is_ctoken) { - (true, true) => TransferCtokenAccountInfos { + (true, true) => TransferCTokenCpi { source: self.source_account.clone(), destination: self.destination_account.clone(), amount: self.amount, @@ -108,10 +108,10 @@ impl<'info> TransferInterface<'info> { (true, false) => { let config = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(CTokenSdkError::SplInterfaceRequired.into()) })?; - TransferCtokenToSplAccountInfos { + TransferCTokenToSplCpi { source_ctoken_account: self.source_account.clone(), destination_spl_token_account: self.destination_account.clone(), amount: self.amount, @@ -130,10 +130,10 @@ impl<'info> TransferInterface<'info> { (false, true) => { let config = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(CTokenSdkError::SplInterfaceRequired.into()) })?; - TransferSplToCtokenAccountInfos { + TransferSplToCtokenCpi { source_spl_token_account: self.source_account.clone(), destination_ctoken_account: self.destination_account.clone(), amount: self.amount, @@ -151,7 +151,7 @@ impl<'info> TransferInterface<'info> { } (false, false) => Err(ProgramError::Custom( - TokenSdkError::UseRegularSplTransfer.into(), + CTokenSdkError::UseRegularSplTransfer.into(), )), } } @@ -162,12 +162,12 @@ impl<'info> TransferInterface<'info> { /// * `CannotDetermineAccountType` - If account type cannot be determined pub fn invoke_signed(self, signer_seeds: &[&[&[u8]]]) -> Result<(), ProgramError> { let source_is_ctoken = is_ctoken_account(&self.source_account) - .map_err(|_| ProgramError::Custom(TokenSdkError::CannotDetermineAccountType.into()))?; + .map_err(|_| ProgramError::Custom(CTokenSdkError::CannotDetermineAccountType.into()))?; let dest_is_ctoken = is_ctoken_account(&self.destination_account) - .map_err(|_| ProgramError::Custom(TokenSdkError::CannotDetermineAccountType.into()))?; + .map_err(|_| ProgramError::Custom(CTokenSdkError::CannotDetermineAccountType.into()))?; match (source_is_ctoken, dest_is_ctoken) { - (true, true) => TransferCtokenAccountInfos { + (true, true) => TransferCTokenCpi { source: self.source_account.clone(), destination: self.destination_account.clone(), amount: self.amount, @@ -178,10 +178,10 @@ impl<'info> TransferInterface<'info> { (true, false) => { let config = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(CTokenSdkError::SplInterfaceRequired.into()) })?; - TransferCtokenToSplAccountInfos { + TransferCTokenToSplCpi { source_ctoken_account: self.source_account.clone(), destination_spl_token_account: self.destination_account.clone(), amount: self.amount, @@ -200,10 +200,10 @@ impl<'info> TransferInterface<'info> { (false, true) => { let config = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(CTokenSdkError::SplInterfaceRequired.into()) })?; - TransferSplToCtokenAccountInfos { + TransferSplToCtokenCpi { source_spl_token_account: self.source_account.clone(), destination_ctoken_account: self.destination_account.clone(), amount: self.amount, @@ -221,7 +221,7 @@ impl<'info> TransferInterface<'info> { } (false, false) => Err(ProgramError::Custom( - TokenSdkError::UseRegularSplTransfer.into(), + CTokenSdkError::UseRegularSplTransfer.into(), )), } } 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 bef7c232e0..e67bada1c9 100644 --- a/sdk-libs/ctoken-sdk/src/ctoken/transfer_spl_ctoken.rs +++ b/sdk-libs/ctoken-sdk/src/ctoken/transfer_spl_ctoken.rs @@ -13,6 +13,30 @@ use crate::compressed_token::{ CTokenAccount2, }; +/// # Create a transfer SPL to cToken instruction +/// ```rust +/// # use solana_pubkey::Pubkey; +/// # use light_ctoken_sdk::ctoken::TransferSplToCtoken; +/// # let source_spl_token_account = Pubkey::new_unique(); +/// # let destination_ctoken_account = Pubkey::new_unique(); +/// # let authority = Pubkey::new_unique(); +/// # let mint = Pubkey::new_unique(); +/// # let payer = Pubkey::new_unique(); +/// # let spl_interface_pda = Pubkey::new_unique(); +/// # let spl_token_program = Pubkey::new_unique(); +/// let instruction = TransferSplToCtoken { +/// amount: 100, +/// spl_interface_pda_bump: 255, +/// source_spl_token_account, +/// destination_ctoken_account, +/// authority, +/// mint, +/// payer, +/// spl_interface_pda, +/// spl_token_program, +/// }.instruction()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` pub struct TransferSplToCtoken { pub amount: u64, pub spl_interface_pda_bump: u8, @@ -26,7 +50,34 @@ pub struct TransferSplToCtoken { pub spl_token_program: Pubkey, } -pub struct TransferSplToCtokenAccountInfos<'info> { +/// # Transfer SPL to ctoken via CPI: +/// ```rust,no_run +/// # use light_ctoken_sdk::ctoken::TransferSplToCtokenCpi; +/// # use solana_account_info::AccountInfo; +/// # let source_spl_token_account: AccountInfo = todo!(); +/// # let destination_ctoken_account: AccountInfo = todo!(); +/// # let authority: AccountInfo = todo!(); +/// # let mint: AccountInfo = todo!(); +/// # let payer: AccountInfo = todo!(); +/// # let spl_interface_pda: AccountInfo = todo!(); +/// # let spl_token_program: AccountInfo = todo!(); +/// # let compressed_token_program_authority: AccountInfo = todo!(); +/// TransferSplToCtokenCpi { +/// amount: 100, +/// spl_interface_pda_bump: 255, +/// source_spl_token_account, +/// destination_ctoken_account, +/// authority, +/// mint, +/// payer, +/// spl_interface_pda, +/// spl_token_program, +/// compressed_token_program_authority, +/// } +/// .invoke()?; +/// # Ok::<(), solana_program_error::ProgramError>(()) +/// ``` +pub struct TransferSplToCtokenCpi<'info> { pub amount: u64, pub spl_interface_pda_bump: u8, pub source_spl_token_account: AccountInfo<'info>, @@ -40,7 +91,7 @@ pub struct TransferSplToCtokenAccountInfos<'info> { pub compressed_token_program_authority: AccountInfo<'info>, } -impl<'info> TransferSplToCtokenAccountInfos<'info> { +impl<'info> TransferSplToCtokenCpi<'info> { pub fn instruction(&self) -> Result { TransferSplToCtoken::from(self).instruction() } @@ -78,8 +129,8 @@ impl<'info> TransferSplToCtokenAccountInfos<'info> { } } -impl<'info> From<&TransferSplToCtokenAccountInfos<'info>> for TransferSplToCtoken { - fn from(account_infos: &TransferSplToCtokenAccountInfos<'info>) -> Self { +impl<'info> From<&TransferSplToCtokenCpi<'info>> for TransferSplToCtoken { + fn from(account_infos: &TransferSplToCtokenCpi<'info>) -> Self { Self { source_spl_token_account: *account_infos.source_spl_token_account.key, destination_ctoken_account: *account_infos.destination_ctoken_account.key, diff --git a/sdk-libs/ctoken-sdk/src/error.rs b/sdk-libs/ctoken-sdk/src/error.rs index f180c10fb0..619e1f7ae7 100644 --- a/sdk-libs/ctoken-sdk/src/error.rs +++ b/sdk-libs/ctoken-sdk/src/error.rs @@ -1,5 +1,3 @@ -//! Error types for compressed token operations. - use light_account_checks::AccountError; use light_compressed_token_types::error::LightTokenSdkTypeError; use light_ctoken_interface::CTokenError; @@ -9,10 +7,10 @@ use light_zero_copy::errors::ZeroCopyError; use solana_program_error::ProgramError; use thiserror::Error; -pub type Result = std::result::Result; +pub type Result = std::result::Result; #[derive(Debug, Error)] -pub enum TokenSdkError { +pub enum CTokenSdkError { #[error("Insufficient balance")] InsufficientBalance, #[error("Serialization error")] @@ -65,10 +63,14 @@ pub enum TokenSdkError { MissingMintAccount, #[error("Missing SPL token program")] MissingSplTokenProgram, - #[error("Missing token pool PDA")] - MissingTokenPoolPda, - #[error("Missing token pool PDA bump")] - MissingTokenPoolPdaBump, + #[error("Missing SPL interface PDA")] + MissingSplInterfacePda, + #[error("Missing SPL interface PDA bump")] + MissingSplInterfacePdaBump, + #[error("Invalid CPI context: first_set_context or set_context must be true")] + InvalidCpiContext, + #[error("No input accounts provided")] + NoInputAccounts, #[error(transparent)] CompressedTokenTypes(#[from] LightTokenSdkTypeError), #[error(transparent)] @@ -83,55 +85,57 @@ pub enum TokenSdkError { AccountError(#[from] AccountError), } #[cfg(feature = "anchor")] -impl From for anchor_lang::prelude::ProgramError { - fn from(e: TokenSdkError) -> Self { +impl From for anchor_lang::prelude::ProgramError { + fn from(e: CTokenSdkError) -> Self { ProgramError::Custom(e.into()) } } #[cfg(not(feature = "anchor"))] -impl From for ProgramError { - fn from(e: TokenSdkError) -> Self { +impl From for ProgramError { + fn from(e: CTokenSdkError) -> Self { ProgramError::Custom(e.into()) } } -impl From for u32 { - fn from(e: TokenSdkError) -> Self { +impl From for u32 { + fn from(e: CTokenSdkError) -> Self { match e { - TokenSdkError::InsufficientBalance => 17001, - TokenSdkError::SerializationError => 17002, - TokenSdkError::CpiError(_) => 17003, - TokenSdkError::CannotCompressAndDecompress => 17004, - TokenSdkError::CompressionCannotBeSetTwice => 17005, - TokenSdkError::InconsistentCompressDecompressState => 17006, - TokenSdkError::BothCompressAndDecompress => 17007, - TokenSdkError::InvalidCompressDecompressAmount => 17008, - TokenSdkError::MethodUsed => 17009, - TokenSdkError::DecompressedMintConfigRequired => 17010, - TokenSdkError::InvalidCompressInputOwner => 17011, - TokenSdkError::AccountBorrowFailed => 17012, - TokenSdkError::InvalidAccountData => 17013, - TokenSdkError::MissingCpiAccount => 17014, - TokenSdkError::TooManyAccounts => 17015, - TokenSdkError::NonContinuousIndices => 17016, - TokenSdkError::PackedAccountIndexOutOfBounds => 17017, - TokenSdkError::CannotMintWithDecompressedInCpiWrite => 17018, - TokenSdkError::RentAuthorityIsNone => 17019, - TokenSdkError::SplInterfaceRequired => 17020, - TokenSdkError::IncompleteSplInterface => 17021, - TokenSdkError::UseRegularSplTransfer => 17022, - TokenSdkError::CannotDetermineAccountType => 17023, - TokenSdkError::CpiContextRequired => 17024, - TokenSdkError::MissingMintAccount => 17025, - TokenSdkError::MissingSplTokenProgram => 17026, - TokenSdkError::MissingTokenPoolPda => 17027, - TokenSdkError::MissingTokenPoolPdaBump => 17028, - TokenSdkError::CompressedTokenTypes(e) => e.into(), - TokenSdkError::CTokenError(e) => e.into(), - TokenSdkError::LightSdkTypesError(e) => e.into(), - TokenSdkError::LightSdkError(e) => e.into(), - TokenSdkError::ZeroCopyError(e) => e.into(), - TokenSdkError::AccountError(e) => e.into(), + CTokenSdkError::InsufficientBalance => 17001, + CTokenSdkError::SerializationError => 17002, + CTokenSdkError::CpiError(_) => 17003, + CTokenSdkError::CannotCompressAndDecompress => 17004, + CTokenSdkError::CompressionCannotBeSetTwice => 17005, + CTokenSdkError::InconsistentCompressDecompressState => 17006, + CTokenSdkError::BothCompressAndDecompress => 17007, + CTokenSdkError::InvalidCompressDecompressAmount => 17008, + CTokenSdkError::MethodUsed => 17009, + CTokenSdkError::DecompressedMintConfigRequired => 17010, + CTokenSdkError::InvalidCompressInputOwner => 17011, + CTokenSdkError::AccountBorrowFailed => 17012, + CTokenSdkError::InvalidAccountData => 17013, + CTokenSdkError::MissingCpiAccount => 17014, + CTokenSdkError::TooManyAccounts => 17015, + CTokenSdkError::NonContinuousIndices => 17016, + CTokenSdkError::PackedAccountIndexOutOfBounds => 17017, + CTokenSdkError::CannotMintWithDecompressedInCpiWrite => 17018, + CTokenSdkError::RentAuthorityIsNone => 17019, + CTokenSdkError::SplInterfaceRequired => 17020, + CTokenSdkError::IncompleteSplInterface => 17021, + CTokenSdkError::UseRegularSplTransfer => 17022, + CTokenSdkError::CannotDetermineAccountType => 17023, + CTokenSdkError::CpiContextRequired => 17024, + CTokenSdkError::MissingMintAccount => 17025, + CTokenSdkError::MissingSplTokenProgram => 17026, + CTokenSdkError::MissingSplInterfacePda => 17027, + CTokenSdkError::MissingSplInterfacePdaBump => 17028, + CTokenSdkError::InvalidCpiContext => 17029, + CTokenSdkError::NoInputAccounts => 17030, + CTokenSdkError::CompressedTokenTypes(e) => e.into(), + CTokenSdkError::CTokenError(e) => e.into(), + CTokenSdkError::LightSdkTypesError(e) => e.into(), + CTokenSdkError::LightSdkError(e) => e.into(), + CTokenSdkError::ZeroCopyError(e) => e.into(), + CTokenSdkError::AccountError(e) => e.into(), } } } diff --git a/sdk-libs/ctoken-sdk/src/lib.rs b/sdk-libs/ctoken-sdk/src/lib.rs index 7e27b9849f..45726e4dca 100644 --- a/sdk-libs/ctoken-sdk/src/lib.rs +++ b/sdk-libs/ctoken-sdk/src/lib.rs @@ -1,11 +1,69 @@ -//! SDK for compressed token operations on Light Protocol. +//! # cToken SDK //! -//! Provides builders and utilities for creating, transferring, and managing compressed tokens. +//! The base library to use cToken Accounts, cMints, and compressed token accounts. +//! +//! ## cToken Accounts +//! - are on Solana devnet. +//! - are Solana accounts. +//! - can hold cMint and spl Mint tokens. +//! - cost 17,288 lamports to create with 24 hours rent. +//! - are compressible: +//! - rent exemption is sponsored by the protocol. +//! - rent is 388 lamports per rent epoch (1.5 hours). +//! - once the account's lamports balance is insufficient, it is compressed to a compressed token account. +//! - compressed tokens can be decompressed to a cToken account. +//! - configurable lamports per write (eg transfer) keep the cToken account perpetually funded when used. So you don't have to worry about funding rent. +//! +//! ## Compressed Token Accounts +//! - are on Solana mainnet. +//! - are compressed accounts. +//! - can hold cMint and spl Mint tokens. +//! - cost 5,000 lamports to create. +//! - are well suited for airdrops and reward distribution. +//! +//! ## cMints: +//! - are on Solana devnet. +//! - are Compressed accounts. +//! - cost 15,000 lamports to create. +//! - support `TokenMetadata`. +//! +//! +//! For full program examples, see the [Program Examples](https://github.com/Lightprotocol/program-examples). +//! For detailed documentation, visit [zkcompression.com](https://www.zkcompression.com/). +//! For rust client development see [`light-client`](https://docs.rs/light-client). +//! For rust program testing see [`light-program-test`](https://docs.rs/light-program-test). +//! For local test validator with light system programs see [Light CLI](https://www.npmjs.com/package/@lightprotocol/zk-compression-cli). +//! +//! +//! +//! ## Features +//! +//! 1. anchor - Derives AnchorSerialize, AnchorDeserialize instead of BorshSerialize, BorshDeserialize. +//! 2. compressible - utility functions for compressible sdk macros. +//! +//! ## Common Operations +//! +//! | Operation | Instruction Builder | CPI Builder | +//! |-----------|----------------|-------------| +//! | Create Associated cToken Account | [`CreateAssociatedTokenAccount`](ctoken::CreateAssociatedTokenAccount) | [`CreateAssociatedTokenAccountCpi`](ctoken::CreateAssociatedTokenAccountCpi) | +//! | Create cToken Account | [`CreateCTokenAccount`](ctoken::CreateCTokenAccount) | [`CreateCTokenAccountCpi`](ctoken::CreateCTokenAccountCpi) | +//! | Transfer cToken | [`TransferCToken`](ctoken::TransferCToken) | [`TransferCTokenCpi`](ctoken::TransferCTokenCpi) | +//! | Transfer cToken → SPL | [`TransferCTokenToSpl`](ctoken::TransferCTokenToSpl) | [`TransferCTokenToSplCpi`](ctoken::TransferCTokenToSplCpi) | +//! | Transfer SPL → cToken | [`TransferSplToCtoken`](ctoken::TransferSplToCtoken) | [`TransferSplToCtokenCpi`](ctoken::TransferSplToCtokenCpi) | +//! | Transfer (auto-detect) | - | [`TransferInterfaceCpi`](ctoken::TransferInterfaceCpi) | +//! | Close cToken account | [`CloseCTokenAccount`](ctoken::CloseCTokenAccount) | [`CloseCTokenAccountCpi`](ctoken::CloseCTokenAccountCpi) | +//! | Create cMint | [`CreateCMint`](ctoken::CreateCMint) | [`CreateCMintCpi`](ctoken::CreateCMintCpi) | +//! | MintTo cToken account from cMint | [`MintToCToken`](ctoken::MintToCToken) | [`MintToCTokenCpi`](ctoken::MintToCTokenCpi) | +//! +//! +//! # Disclaimer +//! This library is not audited and in a beta state. Use at your own risk and expect breaking changes. pub mod compressed_token; pub mod compressible; pub mod ctoken; +pub mod constants; pub mod error; pub mod pack; pub mod spl_interface; @@ -16,14 +74,7 @@ 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; -#[cfg(feature = "compressible")] -pub use pack::{Pack, Unpack}; -pub use utils::{ - account_meta_from_account_info, is_ctoken_account, AccountInfoToCompress, - PackedCompressedTokenDataWithContext, +pub use light_compressed_account::instruction_data::compressed_proof::{ + CompressedProof, ValidityProof, }; +pub use pack::compat; diff --git a/sdk-libs/ctoken-sdk/src/spl_interface.rs b/sdk-libs/ctoken-sdk/src/spl_interface.rs index b73392fdbd..6d1c38438a 100644 --- a/sdk-libs/ctoken-sdk/src/spl_interface.rs +++ b/sdk-libs/ctoken-sdk/src/spl_interface.rs @@ -1,7 +1,7 @@ //! SPL interface PDA derivation utilities. use light_compressed_token_types::constants::POOL_SEED; -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use solana_pubkey::Pubkey; use crate::{AnchorDeserialize, AnchorSerialize}; @@ -26,7 +26,7 @@ pub fn find_spl_interface_pda_with_index(mint: &Pubkey, spl_interface_index: u8) } else { &seeds[..] }; - Pubkey::find_program_address(seeds, &Pubkey::from(COMPRESSED_TOKEN_PROGRAM_ID)) + Pubkey::find_program_address(seeds, &Pubkey::from(CTOKEN_PROGRAM_ID)) } /// Get the spl interface pda for a given mint and index diff --git a/sdk-libs/ctoken-sdk/src/utils.rs b/sdk-libs/ctoken-sdk/src/utils.rs index 289459993e..eff2240d81 100644 --- a/sdk-libs/ctoken-sdk/src/utils.rs +++ b/sdk-libs/ctoken-sdk/src/utils.rs @@ -8,20 +8,20 @@ use solana_pubkey::Pubkey; use spl_pod::bytemuck::pod_from_bytes; use spl_token_2022::pod::PodAccount; -use crate::{error::TokenSdkError, AnchorDeserialize, AnchorSerialize}; +use crate::{error::CTokenSdkError, AnchorDeserialize, AnchorSerialize}; -pub fn get_token_account_balance(token_account_info: &AccountInfo) -> Result { +pub fn get_token_account_balance(token_account_info: &AccountInfo) -> Result { let token_account_data = token_account_info .try_borrow_data() - .map_err(|_| TokenSdkError::AccountBorrowFailed)?; + .map_err(|_| CTokenSdkError::AccountBorrowFailed)?; let pod_account = pod_from_bytes::(&token_account_data) - .map_err(|_| TokenSdkError::InvalidAccountData)?; + .map_err(|_| CTokenSdkError::InvalidAccountData)?; Ok(pod_account.amount.into()) } -pub fn is_ctoken_account(account_info: &AccountInfo) -> Result { +pub fn is_ctoken_account(account_info: &AccountInfo) -> Result { let ctoken_program_id = Pubkey::from(C_TOKEN_PROGRAM_ID); if account_info.owner == &ctoken_program_id { @@ -35,7 +35,7 @@ pub fn is_ctoken_account(account_info: &AccountInfo) -> Result], has_pdas: bool, ) -> std::result::Result<(), solana_program_error::ProgramError> { - light_ctoken_sdk::compressible::decompress_runtime::process_decompress_tokens_runtime( + light_ctoken_sdk::compressible::process_decompress_tokens_runtime( self, remaining_accounts, fee_payer, diff --git a/sdk-libs/macros/src/compressible/instructions.rs b/sdk-libs/macros/src/compressible/instructions.rs index 797fb0d974..6469d22290 100644 --- a/sdk-libs/macros/src/compressible/instructions.rs +++ b/sdk-libs/macros/src/compressible/instructions.rs @@ -563,7 +563,7 @@ pub fn add_compressible_instructions( } } - impl light_ctoken_sdk::CTokenSeedProvider for CTokenAccountVariant { + impl light_ctoken_sdk::compressible::CTokenSeedProvider for CTokenAccountVariant { type Accounts<'info> = DecompressAccountsIdempotent<'info>; fn get_seeds<'a, 'info>( diff --git a/sdk-libs/macros/src/compressible/variant_enum.rs b/sdk-libs/macros/src/compressible/variant_enum.rs index 4e4b9052f0..301afc9de7 100644 --- a/sdk-libs/macros/src/compressible/variant_enum.rs +++ b/sdk-libs/macros/src/compressible/variant_enum.rs @@ -187,7 +187,7 @@ pub fn compressed_account_variant(input: TokenStream) -> Result { #(#pack_match_arms)* Self::PackedCTokenData(_) => unreachable!(), Self::CTokenData(data) => { - Self::PackedCTokenData(light_ctoken_sdk::Pack::pack(data, remaining_accounts)) + Self::PackedCTokenData(light_ctoken_sdk::pack::Pack::pack(data, remaining_accounts)) } } } diff --git a/sdk-libs/sdk/src/lib.rs b/sdk-libs/sdk/src/lib.rs index 8d850dd6af..c673edbdec 100644 --- a/sdk-libs/sdk/src/lib.rs +++ b/sdk-libs/sdk/src/lib.rs @@ -13,7 +13,7 @@ //! For full program examples, see the [Program Examples](https://github.com/Lightprotocol/program-examples). //! For detailed documentation, visit [zkcompression.com](https://www.zkcompression.com/). //! For pinocchio solana program development see [`light-sdk-pinocchio`](https://docs.rs/light-sdk-pinocchio). -//! For rust client developement see [`light-client`](https://docs.rs/light-client). +//! For rust client development see [`light-client`](https://docs.rs/light-client). //! For rust program testing see [`light-program-test`](https://docs.rs/light-program-test). //! For local test validator with light system programs see [Light CLI](https://www.npmjs.com/package/@lightprotocol/zk-compression-cli). //! diff --git a/sdk-libs/token-client/src/actions/ctoken_transfer.rs b/sdk-libs/token-client/src/actions/ctoken_transfer.rs index 4804812f91..a6bb29bb2c 100644 --- a/sdk-libs/token-client/src/actions/ctoken_transfer.rs +++ b/sdk-libs/token-client/src/actions/ctoken_transfer.rs @@ -56,7 +56,7 @@ pub fn create_transfer_ctoken_instruction( authority: Pubkey, ) -> Result { let transfer_instruction = Instruction { - program_id: Pubkey::from(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::from(light_ctoken_interface::CTOKEN_PROGRAM_ID), accounts: vec![ AccountMeta::new(source, false), // Source token account AccountMeta::new(destination, false), // Destination token account diff --git a/sdk-libs/token-client/src/actions/mint_action.rs b/sdk-libs/token-client/src/actions/mint_action.rs index f495737b7c..1e5f66c845 100644 --- a/sdk-libs/token-client/src/actions/mint_action.rs +++ b/sdk-libs/token-client/src/actions/mint_action.rs @@ -3,7 +3,7 @@ use light_client::{ rpc::{Rpc, RpcError}, }; use light_ctoken_interface::instructions::mint_action::Recipient; -use light_ctoken_sdk::compressed_token::create_compressed_mint::derive_compressed_mint_address; +use light_ctoken_sdk::compressed_token::create_compressed_mint::derive_cmint_compressed_address; use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signature::Signature; @@ -78,7 +78,7 @@ pub async fn mint_action_comprehensive( // Derive addresses let address_tree_pubkey = rpc.get_address_tree_v2().tree; let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); // Build actions let mut actions = Vec::new(); @@ -100,11 +100,10 @@ pub async fn mint_action_comprehensive( if !mint_to_decompressed_recipients.is_empty() { use light_ctoken_sdk::{ - compressed_token::create_compressed_mint::find_spl_mint_address, - ctoken::derive_ctoken_ata, + compressed_token::create_compressed_mint::find_cmint_address, ctoken::derive_ctoken_ata, }; - let (spl_mint_pda, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (spl_mint_pda, _) = find_cmint_address(&mint_seed.pubkey()); for recipient in mint_to_decompressed_recipients { let recipient_pubkey = solana_pubkey::Pubkey::from(recipient.recipient.to_bytes()); diff --git a/sdk-libs/token-client/src/actions/transfer2/compress.rs b/sdk-libs/token-client/src/actions/transfer2/compress.rs index 5fed4b5a64..6c45066358 100644 --- a/sdk-libs/token-client/src/actions/transfer2/compress.rs +++ b/sdk-libs/token-client/src/actions/transfer2/compress.rs @@ -24,7 +24,7 @@ use crate::instructions::transfer2::{ /// * `payer` - Transaction fee payer /// /// # Returns -/// `Result` - The compression instruction +/// `Result` - The compression instruction pub async fn compress( rpc: &mut R, solana_token_account: Pubkey, 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 5621d48475..b26822347e 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,8 +3,8 @@ use light_client::{ rpc::{Rpc, RpcError}, }; use light_ctoken_sdk::{ - ctoken::TransferCtokenToSpl, spl_interface::find_spl_interface_pda_with_index, - SPL_TOKEN_PROGRAM_ID, + constants::SPL_TOKEN_PROGRAM_ID, ctoken::TransferCTokenToSpl, + spl_interface::find_spl_interface_pda_with_index, }; use solana_keypair::Keypair; use solana_pubkey::Pubkey; @@ -23,7 +23,7 @@ pub async fn transfer_ctoken_to_spl( ) -> Result { let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); - let transfer_ix = TransferCtokenToSpl { + let transfer_ix = TransferCTokenToSpl { source_ctoken_account, destination_spl_token_account, amount, @@ -32,7 +32,7 @@ pub async fn transfer_ctoken_to_spl( payer: payer.pubkey(), spl_interface_pda, spl_interface_pda_bump, - spl_token_program: Pubkey::new_from_array(SPL_TOKEN_PROGRAM_ID), // TODO: make dynamic + spl_token_program: SPL_TOKEN_PROGRAM_ID, // TODO: make dynamic } .instruction() .map_err(|e| RpcError::AssertRpcError(format!("Failed to create instruction: {:?}", e)))?; 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 e61fd142be..62cd551bd5 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,8 +3,8 @@ use light_client::{ rpc::{Rpc, RpcError}, }; use light_ctoken_sdk::{ - ctoken::TransferSplToCtoken, spl_interface::find_spl_interface_pda_with_index, - SPL_TOKEN_PROGRAM_ID, + constants::SPL_TOKEN_PROGRAM_ID, ctoken::TransferSplToCtoken, + spl_interface::find_spl_interface_pda_with_index, }; use solana_keypair::Keypair; use solana_pubkey::Pubkey; @@ -43,7 +43,7 @@ pub async fn spl_to_ctoken_transfer( mint, payer: payer.pubkey(), spl_interface_pda, - spl_token_program: Pubkey::new_from_array(SPL_TOKEN_PROGRAM_ID), // TODO: make dynamic + spl_token_program: SPL_TOKEN_PROGRAM_ID, // TODO: make dynamic } .instruction() .map_err(|e| RpcError::CustomError(e.to_string()))?; diff --git a/sdk-libs/token-client/src/actions/update_compressed_mint.rs b/sdk-libs/token-client/src/actions/update_compressed_mint.rs index 38fdd58a76..4b6c026257 100644 --- a/sdk-libs/token-client/src/actions/update_compressed_mint.rs +++ b/sdk-libs/token-client/src/actions/update_compressed_mint.rs @@ -2,7 +2,7 @@ use light_client::{ indexer::Indexer, rpc::{Rpc, RpcError}, }; -use light_ctoken_sdk::CompressedMintAuthorityType; +use light_compressed_token_types::CompressedMintAuthorityType; use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signature::Signature; diff --git a/sdk-libs/token-client/src/instructions/create_mint.rs b/sdk-libs/token-client/src/instructions/create_mint.rs index bd1b791c4a..a7396eda8c 100644 --- a/sdk-libs/token-client/src/instructions/create_mint.rs +++ b/sdk-libs/token-client/src/instructions/create_mint.rs @@ -6,7 +6,7 @@ use light_ctoken_interface::instructions::extensions::{ token_metadata::TokenMetadataInstructionData, ExtensionInstructionData, }; use light_ctoken_sdk::ctoken::{ - derive_compressed_mint_address, find_spl_mint_address, CreateCMint, CreateCMintParams, + derive_cmint_compressed_address, find_cmint_address, CreateCMint, CreateCMintParams, }; use solana_instruction::Instruction; use solana_keypair::Keypair; @@ -25,7 +25,7 @@ use solana_signer::Signer; /// * `metadata` - Optional metadata for the token /// /// # Returns -/// `Result` - The compressed mint creation instruction +/// `Result` - The compressed mint creation instruction pub async fn create_compressed_mint_instruction( rpc: &mut R, mint_seed: &Keypair, @@ -41,7 +41,7 @@ pub async fn create_compressed_mint_instruction( let output_queue = rpc.get_random_state_tree_info()?.queue; let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); // Create extensions if metadata is provided let extensions = metadata.map(|meta| vec![ExtensionInstructionData::TokenMetadata(meta)]); @@ -68,7 +68,7 @@ pub async fn create_compressed_mint_instruction( mint_authority, proof: rpc_result.proof.0.unwrap(), compression_address: compressed_mint_address, - mint: find_spl_mint_address(&mint_seed.pubkey()).0, + mint: find_cmint_address(&mint_seed.pubkey()).0, freeze_authority, extensions, }; diff --git a/sdk-libs/token-client/src/instructions/mint_action.rs b/sdk-libs/token-client/src/instructions/mint_action.rs index bcf345c997..f9e51e5626 100644 --- a/sdk-libs/token-client/src/instructions/mint_action.rs +++ b/sdk-libs/token-client/src/instructions/mint_action.rs @@ -14,10 +14,10 @@ use light_ctoken_interface::{ }, }, state::CompressedMint, - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, }; use light_ctoken_sdk::compressed_token::{ - create_compressed_mint::{derive_compressed_mint_address, find_spl_mint_address}, + create_compressed_mint::{derive_cmint_compressed_address, find_cmint_address}, mint_action::MintActionMetaConfig, }; use solana_instruction::Instruction; @@ -126,7 +126,7 @@ pub async fn create_mint_action_instruction( decimals: new_mint.decimals, metadata: light_ctoken_interface::state::CompressedMintMetadata { version: new_mint.version, - mint: find_spl_mint_address(¶ms.mint_seed).0.to_bytes().into(), + mint: find_cmint_address(¶ms.mint_seed).0.to_bytes().into(), spl_mint_initialized: false, // Will be set to true if CreateSplMint action is present }, mint_authority: Some(new_mint.mint_authority.to_bytes().into()), @@ -317,7 +317,7 @@ pub async fn create_mint_action_instruction( // Build final instruction Ok(Instruction { - program_id: COMPRESSED_TOKEN_PROGRAM_ID.into(), + program_id: CTOKEN_PROGRAM_ID.into(), accounts: account_metas, data, }) @@ -340,7 +340,7 @@ pub async fn create_comprehensive_mint_action_instruction( // Derive addresses let address_tree_pubkey = rpc.get_address_tree_v2().tree; let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); // Build actions let mut actions = Vec::new(); diff --git a/sdk-libs/token-client/src/instructions/transfer2.rs b/sdk-libs/token-client/src/instructions/transfer2.rs index 79b7040a48..bf4ed3a60a 100644 --- a/sdk-libs/token-client/src/instructions/transfer2.rs +++ b/sdk-libs/token-client/src/instructions/transfer2.rs @@ -5,7 +5,7 @@ use light_client::{ use light_ctoken_interface::{ instructions::transfer2::{MultiInputTokenDataWithContext, MultiTokenTransferOutputData}, state::TokenDataVersion, - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, }; use light_ctoken_sdk::{ compressed_token::{ @@ -15,7 +15,7 @@ use light_ctoken_sdk::{ }, CTokenAccount2, }, - error::TokenSdkError, + error::CTokenSdkError, spl_interface::find_spl_interface_pda_with_index, }; use light_sdk::instruction::{PackedAccounts, PackedStateTreeInfo}; @@ -72,7 +72,7 @@ pub async fn create_decompress_instruction( decompress_amount: u64, solana_token_account: Pubkey, payer: Pubkey, -) -> Result { +) -> Result { create_generic_transfer2_instruction( rpc, vec![Transfer2InstructionType::Decompress(DecompressInput { @@ -149,8 +149,7 @@ pub async fn create_generic_transfer2_instruction( actions: Vec, payer: Pubkey, should_filter_zero_outputs: bool, -) -> Result { - println!("here"); +) -> Result { // // Get a single shared output queue for ALL compress/compress-and-close operations // // This prevents reordering issues caused by the sort_by_key at the end // let shared_output_queue = rpc @@ -232,7 +231,7 @@ pub async fn create_generic_transfer2_instruction( ) .map(|(account, rpc_account)| { if input.to != account.token.owner { - return Err(TokenSdkError::InvalidCompressInputOwner); + return Err(CTokenSdkError::InvalidCompressInputOwner); } Ok(pack_input_token_account( account, @@ -268,7 +267,7 @@ pub async fn create_generic_transfer2_instruction( .unwrap() .owner; - if source_account_owner.to_bytes() != COMPRESSED_TOKEN_PROGRAM_ID { + if source_account_owner.to_bytes() != CTOKEN_PROGRAM_ID { // For SPL compression, get mint first let mint = input.mint; @@ -335,7 +334,7 @@ pub async fn create_generic_transfer2_instruction( .unwrap() .owner; - if recipient_account_owner.to_bytes() != COMPRESSED_TOKEN_PROGRAM_ID { + if recipient_account_owner.to_bytes() != CTOKEN_PROGRAM_ID { // For SPL decompression, get mint first let mint = input.compressed_token_account[0].token.mint; @@ -373,7 +372,6 @@ pub async fn create_generic_transfer2_instruction( token_accounts.push(token_account); } Transfer2InstructionType::Transfer(input) => { - println!("here1"); let token_data = input .compressed_token_account .iter() @@ -399,12 +397,11 @@ pub async fn create_generic_transfer2_instruction( ) }) .collect::>(); - println!("here2 {:?}", token_data); inputs_offset += token_data.len(); if token_data.is_empty() { // When no input accounts, create recipient account directly // This requires mint to be specified in the input - let mint = input.mint.ok_or(TokenSdkError::InvalidAccountData)?; + let mint = input.mint.ok_or(CTokenSdkError::InvalidAccountData)?; let recipient_index = packed_tree_accounts.insert_or_get(input.to); let mint_index = packed_tree_accounts.insert_or_get_read_only(mint); @@ -429,10 +426,6 @@ pub async fn create_generic_transfer2_instruction( } else { // Only use new_delegated if the input accounts actually have delegates let has_delegates = token_data.iter().any(|data| data.has_delegate); - println!( - "is_delegate_transfer: {}, has_delegates: {}", - input.is_delegate_transfer, has_delegates - ); let mut token_account = if input.is_delegate_transfer && has_delegates { CTokenAccount2::new_delegated(token_data) } else { @@ -503,23 +496,18 @@ pub async fn create_generic_transfer2_instruction( token_accounts.push(delegated_token_account); } Transfer2InstructionType::CompressAndClose(input) => { - println!( - "input.solana_ctoken_account {:?}", - input.solana_ctoken_account - ); // Get token account info to extract mint, balance, owner, and rent_sponsor let token_account_info = rpc .get_account(input.solana_ctoken_account) .await - .map_err(|_| TokenSdkError::InvalidAccountData)? - .ok_or(TokenSdkError::InvalidAccountData)?; + .map_err(|_| CTokenSdkError::InvalidAccountData)? + .ok_or(CTokenSdkError::InvalidAccountData)?; // Parse the compressed token account using zero-copy deserialization use light_ctoken_interface::state::{CToken, ZExtensionStruct}; use light_zero_copy::traits::ZeroCopyAt; let (compressed_token, _) = CToken::zero_copy_at(&token_account_info.data) - .map_err(|_| TokenSdkError::InvalidAccountData)?; - println!("compressed_token {:?}", compressed_token); + .map_err(|_| CTokenSdkError::InvalidAccountData)?; let mint = compressed_token.mint; let balance = compressed_token.amount; let owner = compressed_token.owner; @@ -542,20 +530,16 @@ pub async fn create_generic_transfer2_instruction( break; } } - println!("rent sponsor {:?}", found_rent_sponsor); - println!("compress_to_pubkey {:?}", found_compress_to_pubkey); ( - found_rent_sponsor.ok_or(TokenSdkError::InvalidAccountData)?, + found_rent_sponsor.ok_or(CTokenSdkError::InvalidAccountData)?, found_compression_authority, found_compress_to_pubkey, ) } else { - println!("no extensions but is_compressible is true"); - return Err(TokenSdkError::InvalidAccountData); + return Err(CTokenSdkError::InvalidAccountData); } } else { // Non-compressible account: use owner as rent_sponsor - println!("non-compressible account, using owner as rent sponsor"); (owner.to_bytes(), None, false) }; @@ -637,6 +621,5 @@ pub async fn create_generic_transfer2_instruction( token_accounts, output_queue: shared_output_queue, }; - println!("pre create_transfer2_instruction {:?}", inputs); create_transfer2_instruction(inputs) } diff --git a/sdk-libs/token-client/src/instructions/update_compressed_mint.rs b/sdk-libs/token-client/src/instructions/update_compressed_mint.rs index 75c9a83ff0..3f9fec22ca 100644 --- a/sdk-libs/token-client/src/instructions/update_compressed_mint.rs +++ b/sdk-libs/token-client/src/instructions/update_compressed_mint.rs @@ -3,15 +3,13 @@ use light_client::{ indexer::Indexer, rpc::{Rpc, RpcError}, }; +use light_compressed_token_types::CompressedMintAuthorityType; use light_ctoken_interface::{ instructions::mint_action::{CompressedMintInstructionData, CompressedMintWithContext}, state::CompressedMint, }; -use light_ctoken_sdk::{ - compressed_token::update_compressed_mint::{ - update_compressed_mint, UpdateCompressedMintInputs, - }, - CompressedMintAuthorityType, +use light_ctoken_sdk::compressed_token::update_compressed_mint::{ + update_compressed_mint, UpdateCompressedMintInputs, }; use solana_instruction::Instruction; use solana_keypair::Keypair; @@ -47,7 +45,7 @@ pub async fn update_compressed_mint_instruction( // Get compressed account from indexer let compressed_accounts = rpc .get_compressed_accounts_by_owner( - &Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + &Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID), None, None, ) diff --git a/sdk-tests/csdk-anchor-derived-test/src/lib.rs b/sdk-tests/csdk-anchor-derived-test/src/lib.rs index 88f82602c3..1a6ebdb6c1 100644 --- a/sdk-tests/csdk-anchor-derived-test/src/lib.rs +++ b/sdk-tests/csdk-anchor-derived-test/src/lib.rs @@ -29,7 +29,7 @@ pub mod csdk_anchor_derived_test { MintActionCompressedInstructionData, MintToCompressedAction, Recipient, }; use light_ctoken_sdk::compressed_token::{ - create_compressed_mint::find_spl_mint_address, mint_action::MintActionMetaConfig, + create_compressed_mint::find_cmint_address, mint_action::MintActionMetaConfig, }; use light_sdk::{ compressible::{ @@ -136,7 +136,7 @@ pub mod csdk_anchor_derived_test { .write_to_cpi_context_first() .invoke_write_to_cpi_context_first(cpi_context_accounts)?; - let mint = find_spl_mint_address(&ctx.accounts.mint_signer.key()).0; + let mint = find_cmint_address(&ctx.accounts.mint_signer.key()).0; let (_, token_account_address) = get_ctoken_signer_seeds(&ctx.accounts.user.key(), &mint); let output_queue = *cpi_accounts.tree_accounts().unwrap()[0].key; @@ -187,7 +187,7 @@ pub mod csdk_anchor_derived_test { // Build mint action instruction let mint_action_instruction = solana_program::instruction::Instruction { - program_id: light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID.into(), + program_id: light_ctoken_interface::CTOKEN_PROGRAM_ID.into(), accounts: account_metas, data, }; diff --git a/sdk-tests/csdk-anchor-derived-test/src/processor.rs b/sdk-tests/csdk-anchor-derived-test/src/processor.rs index 729eb4011a..8f1082b62a 100644 --- a/sdk-tests/csdk-anchor-derived-test/src/processor.rs +++ b/sdk-tests/csdk-anchor-derived-test/src/processor.rs @@ -183,10 +183,7 @@ impl<'info> light_sdk::compressible::DecompressContext<'info> return Ok(()); } - light_ctoken_sdk::compressible::decompress_runtime::process_decompress_tokens_runtime::< - CTokenAccountVariant, - _, - >( + light_ctoken_sdk::compressible::process_decompress_tokens_runtime::( self, _remaining_accounts, _fee_payer, diff --git a/sdk-tests/csdk-anchor-derived-test/src/variant.rs b/sdk-tests/csdk-anchor-derived-test/src/variant.rs index a2151ee7cd..def6e91c4a 100644 --- a/sdk-tests/csdk-anchor-derived-test/src/variant.rs +++ b/sdk-tests/csdk-anchor-derived-test/src/variant.rs @@ -1,7 +1,7 @@ use anchor_lang::prelude::*; use light_ctoken_sdk::{ compat::{CTokenData, PackedCTokenData}, - Pack as TokenPack, + pack::Pack as TokenPack, }; use light_sdk::{ account::Size, @@ -25,7 +25,7 @@ pub enum CTokenAccountVariant { CTokenSigner = 0, } -impl light_ctoken_sdk::CTokenSeedProvider for CTokenAccountVariant { +impl light_ctoken_sdk::compressible::CTokenSeedProvider for CTokenAccountVariant { type Accounts<'info> = DecompressAccountsIdempotent<'info>; fn get_seeds<'a, 'info>( diff --git a/sdk-tests/csdk-anchor-derived-test/tests/basic_test.rs b/sdk-tests/csdk-anchor-derived-test/tests/basic_test.rs index 524f4044ff..e49651a712 100644 --- a/sdk-tests/csdk-anchor-derived-test/tests/basic_test.rs +++ b/sdk-tests/csdk-anchor-derived-test/tests/basic_test.rs @@ -6,7 +6,7 @@ use light_ctoken_interface::{ state::CompressedMintMetadata, }; use light_ctoken_sdk::compressed_token::create_compressed_mint::{ - derive_compressed_mint_address, find_spl_mint_address, + derive_cmint_compressed_address, find_cmint_address, }; use light_macros::pubkey; use light_program_test::{ @@ -128,7 +128,7 @@ async fn test_create_decompress_compress() { assert_eq!(game_session.score, 0); assert!(game_session.compression_info.is_none()); - let spl_mint = find_spl_mint_address(&mint_signer_pubkey).0; + let spl_mint = find_cmint_address(&mint_signer_pubkey).0; let (_, token_account_address) = csdk_anchor_derived_test::seeds::get_ctoken_signer_seeds(&payer.pubkey(), &spl_mint); @@ -573,9 +573,9 @@ pub async fn create_user_record_and_game_session( let freeze_authority = mint_authority; let mint_signer = Keypair::new(); let compressed_mint_address = - derive_compressed_mint_address(&mint_signer.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_signer.pubkey(), &address_tree_pubkey); - let (spl_mint, mint_bump) = find_spl_mint_address(&mint_signer.pubkey()); + let (spl_mint, mint_bump) = find_cmint_address(&mint_signer.pubkey()); let accounts = csdk_anchor_derived_test::accounts::CreateUserRecordAndGameSession { user: user.pubkey(), user_record: *user_record_pda, diff --git a/sdk-tests/csdk-anchor-full-derived-test/src/lib.rs b/sdk-tests/csdk-anchor-full-derived-test/src/lib.rs index 9303938dba..c3d567ba2b 100644 --- a/sdk-tests/csdk-anchor-full-derived-test/src/lib.rs +++ b/sdk-tests/csdk-anchor-full-derived-test/src/lib.rs @@ -66,7 +66,7 @@ pub mod csdk_anchor_full_derived_test { MintActionCompressedInstructionData, MintToCompressedAction, Recipient, }; use light_ctoken_sdk::compressed_token::{ - create_compressed_mint::find_spl_mint_address, mint_action::MintActionMetaConfig, + create_compressed_mint::find_cmint_address, mint_action::MintActionMetaConfig, }; use light_sdk::{ compressible::{ @@ -175,7 +175,7 @@ pub mod csdk_anchor_full_derived_test { .write_to_cpi_context_first() .invoke_write_to_cpi_context_first(cpi_context_accounts)?; - let mint = find_spl_mint_address(&ctx.accounts.mint_signer.key()).0; + let mint = find_cmint_address(&ctx.accounts.mint_signer.key()).0; // Use the generated client seed function for CToken signer (generated by add_compressible_instructions macro) let (_, token_account_address) = get_ctokensigner_seeds(&ctx.accounts.user.key(), &mint); @@ -228,7 +228,7 @@ pub mod csdk_anchor_full_derived_test { // Build mint action instruction let mint_action_instruction = solana_program::instruction::Instruction { - program_id: light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID.into(), + program_id: light_ctoken_interface::CTOKEN_PROGRAM_ID.into(), accounts: account_metas, data, }; diff --git a/sdk-tests/csdk-anchor-full-derived-test/tests/basic_test.rs b/sdk-tests/csdk-anchor-full-derived-test/tests/basic_test.rs index c26c3792e2..f9ac19985e 100644 --- a/sdk-tests/csdk-anchor-full-derived-test/tests/basic_test.rs +++ b/sdk-tests/csdk-anchor-full-derived-test/tests/basic_test.rs @@ -8,7 +8,7 @@ use light_ctoken_interface::{ state::CompressedMintMetadata, }; use light_ctoken_sdk::compressed_token::create_compressed_mint::{ - derive_compressed_mint_address, find_spl_mint_address, + derive_cmint_compressed_address, find_cmint_address, }; use light_macros::pubkey; use light_program_test::{ @@ -179,7 +179,7 @@ async fn test_create_with_complex_seeds() { assert!(game_session.compression_info.is_none()); // Verify CToken account - let spl_mint = find_spl_mint_address(&mint_signer_pubkey).0; + let spl_mint = find_cmint_address(&mint_signer_pubkey).0; let (_, token_account_address) = csdk_anchor_full_derived_test::get_ctokensigner_seeds(&payer.pubkey(), &spl_mint); @@ -225,9 +225,9 @@ pub async fn create_user_record_and_game_session( let freeze_authority = mint_authority; let mint_signer = Keypair::new(); let compressed_mint_address = - derive_compressed_mint_address(&mint_signer.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_signer.pubkey(), &address_tree_pubkey); - let (spl_mint, mint_bump) = find_spl_mint_address(&mint_signer.pubkey()); + let (spl_mint, mint_bump) = find_cmint_address(&mint_signer.pubkey()); let accounts = csdk_anchor_full_derived_test::accounts::CreateUserRecordAndGameSession { user: user.pubkey(), mint_signer: mint_signer.pubkey(), diff --git a/sdk-tests/sdk-compressible-test/src/instructions/create_user_record_and_game_session.rs b/sdk-tests/sdk-compressible-test/src/instructions/create_user_record_and_game_session.rs index f3814ed147..1764a26ef9 100644 --- a/sdk-tests/sdk-compressible-test/src/instructions/create_user_record_and_game_session.rs +++ b/sdk-tests/sdk-compressible-test/src/instructions/create_user_record_and_game_session.rs @@ -5,7 +5,7 @@ use anchor_lang::{ use light_compressed_account::instruction_data::traits::LightInstructionData; use light_ctoken_interface::instructions::mint_action::{MintToCompressedAction, Recipient}; use light_ctoken_sdk::compressed_token::{ - create_compressed_mint::find_spl_mint_address, mint_action::MintActionMetaConfig, + create_compressed_mint::find_cmint_address, mint_action::MintActionMetaConfig, }; use light_sdk::{ compressible::{ @@ -115,7 +115,7 @@ pub fn create_user_record_and_game_session<'info>( // these are custom seeds of the caller program that are used to derive the program owned onchain tokenb account PDA. // dual use: as owner of the compressed token account. - let mint = find_spl_mint_address(&ctx.accounts.mint_signer.key()).0; + let mint = find_cmint_address(&ctx.accounts.mint_signer.key()).0; let (_, token_account_address) = get_ctoken_signer_seeds(&ctx.accounts.user.key(), &mint); let output_queue = *cpi_accounts.tree_accounts().unwrap()[0].key; // Same tree as PDA @@ -191,7 +191,7 @@ pub fn create_user_record_and_game_session<'info>( // Build instruction let mint_action_instruction = Instruction { - program_id: Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID), + program_id: Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID), accounts: account_metas, data, }; diff --git a/sdk-tests/sdk-compressible-test/src/instructions/decompress_accounts_idempotent.rs b/sdk-tests/sdk-compressible-test/src/instructions/decompress_accounts_idempotent.rs index 52005494af..258b212013 100644 --- a/sdk-tests/sdk-compressible-test/src/instructions/decompress_accounts_idempotent.rs +++ b/sdk-tests/sdk-compressible-test/src/instructions/decompress_accounts_idempotent.rs @@ -1,6 +1,6 @@ // Auto-generated by compressible_instructions macro. use anchor_lang::prelude::*; -use light_ctoken_sdk::ctoken::{CompressibleParamsInfos, CreateCTokenAccountInfos}; +use light_ctoken_sdk::ctoken::{CompressibleParamsCpi, CreateCTokenAccountCpi}; use light_sdk::{ compressible::{ decompress_idempotent::{ @@ -223,12 +223,12 @@ pub fn decompress_accounts_idempotent<'info>( seeds: seeds_without_bump, }; - CreateCTokenAccountInfos { + CreateCTokenAccountCpi { payer: fee_payer.clone().to_account_info(), account: owner_info.clone(), mint: mint_info.clone(), owner: *authority.clone().to_account_info().key, - compressible: Some(CompressibleParamsInfos { + compressible: Some(CompressibleParamsCpi { compressible_config: ctoken_config.to_account_info(), rent_sponsor: ctoken_rent_sponsor.clone().to_account_info(), system_program: accounts.system_program.to_account_info(), diff --git a/sdk-tests/sdk-compressible-test/src/state.rs b/sdk-tests/sdk-compressible-test/src/state.rs index 99dc924443..d8ad3de163 100644 --- a/sdk-tests/sdk-compressible-test/src/state.rs +++ b/sdk-tests/sdk-compressible-test/src/state.rs @@ -4,7 +4,7 @@ use anchor_lang::prelude::*; use light_ctoken_interface::instructions::mint_action::CompressedMintWithContext; -use light_ctoken_sdk::Pack as _TokenPack; +use light_ctoken_sdk::pack::Pack as _TokenPack; use light_sdk::{ account::Size, compressible::{ diff --git a/sdk-tests/sdk-compressible-test/tests/multi_account_tests.rs b/sdk-tests/sdk-compressible-test/tests/multi_account_tests.rs index 5151527323..3d5c7b2fee 100644 --- a/sdk-tests/sdk-compressible-test/tests/multi_account_tests.rs +++ b/sdk-tests/sdk-compressible-test/tests/multi_account_tests.rs @@ -11,7 +11,7 @@ use light_ctoken_interface::{ }; use light_ctoken_sdk::{ compressed_token::create_compressed_mint::{ - derive_compressed_mint_address, find_spl_mint_address, + derive_cmint_compressed_address, find_cmint_address, }, ctoken, pack::compat::CTokenDataWithVariant, @@ -238,9 +238,9 @@ pub async fn create_user_record_and_game_session( let freeze_authority = mint_authority; let mint_signer = Keypair::new(); let compressed_mint_address = - derive_compressed_mint_address(&mint_signer.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_signer.pubkey(), &address_tree_pubkey); - let (spl_mint, mint_bump) = find_spl_mint_address(&mint_signer.pubkey()); + let (spl_mint, mint_bump) = find_cmint_address(&mint_signer.pubkey()); let accounts = sdk_compressible_test::accounts::CreateUserRecordAndGameSession { user: user.pubkey(), user_record: *user_record_pda, @@ -415,13 +415,10 @@ pub async fn create_user_record_and_game_session( assert_eq!(game_session.player, user.pubkey()); assert_eq!(game_session.score, 0); - let token_account_address = get_ctoken_signer_seeds( - &user.pubkey(), - &find_spl_mint_address(&mint_signer.pubkey()).0, - ) - .1; + let token_account_address = + get_ctoken_signer_seeds(&user.pubkey(), &find_cmint_address(&mint_signer.pubkey()).0).1; - let mint = find_spl_mint_address(&mint_signer.pubkey()).0; + let mint = find_cmint_address(&mint_signer.pubkey()).0; let token_account_address_2 = get_ctoken_signer2_seeds(&user.pubkey()).1; let token_account_address_3 = get_ctoken_signer3_seeds(&user.pubkey()).1; let token_account_address_4 = get_ctoken_signer4_seeds(&user.pubkey(), &user.pubkey()).1; diff --git a/sdk-tests/sdk-ctoken-test/README.md b/sdk-tests/sdk-ctoken-test/README.md index bd1639c4dc..bca5d1d6c4 100644 --- a/sdk-tests/sdk-ctoken-test/README.md +++ b/sdk-tests/sdk-ctoken-test/README.md @@ -32,7 +32,7 @@ The builder pattern offers several advantages: ```rust // Build the account infos struct -let transfer_accounts = TransferCtokenAccountInfos { +let transfer_accounts = TransferCTokenCpi { source: accounts[0].clone(), destination: accounts[1].clone(), amount: data.amount, @@ -50,7 +50,7 @@ transfer_accounts.invoke()?; let (pda, bump) = Pubkey::find_program_address(&[TOKEN_ACCOUNT_SEED], &ID); // Build the account infos struct -let transfer_accounts = TransferCtokenAccountInfos { +let transfer_accounts = TransferCTokenCpi { source: accounts[0].clone(), destination: accounts[1].clone(), amount: data.amount, @@ -68,13 +68,13 @@ transfer_accounts.invoke_signed(&[signer_seeds])?; All instructions use the **builder pattern** from `light-ctoken-sdk::ctoken`: -- **create_cmint** (Instruction 0): Create compressed mint using `CreateCMintAccountInfos::invoke()` -- **mint_to_ctoken** (Instruction 1): Mint tokens to compressed accounts using `MintToCTokenInfos::invoke()` -- **create_token_account_invoke** (Instruction 2): Create compressible token account using `CreateCTokenAccountInfos` +- **create_cmint** (Instruction 0): Create compressed mint using `CreateCMintCpi::invoke()` +- **mint_to_ctoken** (Instruction 1): Mint tokens to compressed accounts using `MintToCTokenCpi::invoke()` +- **create_token_account_invoke** (Instruction 2): Create compressible token account using `CreateCTokenAccountCpi` - **create_token_account_invoke_signed** (Instruction 3): Create with PDA ownership using `invoke_signed()` -- **create_ata_invoke** (Instruction 4): Create compressible ATA using `CreateAssociatedTokenAccountInfos` +- **create_ata_invoke** (Instruction 4): Create compressible ATA using `CreateAssociatedTokenAccountCpi` - **create_ata_invoke_signed** (Instruction 5): Create ATA with PDA ownership using `invoke_signed()` -- **transfer_interface_invoke** (Instruction 6): Transfer using `TransferCtokenAccountInfos::invoke()` +- **transfer_interface_invoke** (Instruction 6): Transfer using `TransferCTokenCpi::invoke()` - **transfer_interface_invoke_signed** (Instruction 7): Transfer with PDA signing using `invoke_signed()` All instructions compile successfully and demonstrate the clean builder pattern API with constructor usage. @@ -141,7 +141,7 @@ This is useful for: ### Builder Pattern Benefits -The `AccountInfos` structs from the `ctoken` module provide: +The `Cpi` structs from the `ctoken` module provide: 1. **invoke()** - For regular CPI calls where the program acts as authority 2. **invoke_signed()** - For PDA-signed CPI calls diff --git a/sdk-tests/sdk-ctoken-test/src/close.rs b/sdk-tests/sdk-ctoken-test/src/close.rs index a50a8060d5..33b4d9cd0c 100644 --- a/sdk-tests/sdk-ctoken-test/src/close.rs +++ b/sdk-tests/sdk-ctoken-test/src/close.rs @@ -1,4 +1,4 @@ -use light_ctoken_sdk::ctoken::CloseAccountInfos; +use light_ctoken_sdk::ctoken::CloseCTokenAccountCpi; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::{ID, TOKEN_ACCOUNT_SEED}; @@ -22,7 +22,7 @@ pub fn process_close_account_invoke(accounts: &[AccountInfo]) -> Result<(), Prog None }; - CloseAccountInfos { + CloseCTokenAccountCpi { token_program: accounts[0].clone(), account: accounts[1].clone(), destination: accounts[2].clone(), @@ -62,7 +62,7 @@ pub fn process_close_account_invoke_signed(accounts: &[AccountInfo]) -> Result<( }; let signer_seeds: &[&[u8]] = &[TOKEN_ACCOUNT_SEED, &[bump]]; - CloseAccountInfos { + CloseCTokenAccountCpi { token_program: accounts[0].clone(), account: accounts[1].clone(), destination: accounts[2].clone(), diff --git a/sdk-tests/sdk-ctoken-test/src/create_ata.rs b/sdk-tests/sdk-ctoken-test/src/create_ata.rs index bf005d2089..a7c9f00c63 100644 --- a/sdk-tests/sdk-ctoken-test/src/create_ata.rs +++ b/sdk-tests/sdk-ctoken-test/src/create_ata.rs @@ -1,5 +1,5 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_sdk::ctoken::{CompressibleParamsInfos, CreateAssociatedTokenAccountInfos}; +use light_ctoken_sdk::ctoken::{CompressibleParamsCpi, CreateAssociatedTokenAccountCpi}; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::{ATA_SEED, ID}; @@ -31,14 +31,14 @@ pub fn process_create_ata_invoke( } // Build the compressible params using constructor - let compressible_params = CompressibleParamsInfos::new( + let compressible_params = CompressibleParamsCpi::new( accounts[5].clone(), accounts[6].clone(), accounts[4].clone(), ); - // Use the CreateAssociatedTokenAccountInfos - owner and mint are AccountInfos - CreateAssociatedTokenAccountInfos { + // Use the CreateAssociatedTokenAccountCpi - owner and mint are AccountInfos + CreateAssociatedTokenAccountCpi { owner: accounts[0].clone(), mint: accounts[1].clone(), payer: accounts[2].clone(), @@ -80,14 +80,14 @@ pub fn process_create_ata_invoke_signed( } // Build the compressible params using constructor - let compressible_params = CompressibleParamsInfos::new( + let compressible_params = CompressibleParamsCpi::new( accounts[5].clone(), accounts[6].clone(), accounts[4].clone(), ); - // Use the CreateAssociatedTokenAccountInfos - owner and mint are AccountInfos - let account_infos = CreateAssociatedTokenAccountInfos { + // Use the CreateAssociatedTokenAccountCpi - owner and mint are AccountInfos + let account_infos = CreateAssociatedTokenAccountCpi { owner: accounts[0].clone(), mint: accounts[1].clone(), payer: accounts[2].clone(), diff --git a/sdk-tests/sdk-ctoken-test/src/create_ata2.rs b/sdk-tests/sdk-ctoken-test/src/create_ata2.rs index 5012d8dc73..7f470ac799 100644 --- a/sdk-tests/sdk-ctoken-test/src/create_ata2.rs +++ b/sdk-tests/sdk-ctoken-test/src/create_ata2.rs @@ -1,5 +1,5 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_sdk::ctoken::{CompressibleParamsInfos, CreateAssociatedTokenAccountInfos}; +use light_ctoken_sdk::ctoken::{CompressibleParamsCpi, CreateAssociatedTokenAccountCpi}; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::{ATA_SEED, ID}; @@ -30,13 +30,13 @@ pub fn process_create_ata2_invoke( return Err(ProgramError::NotEnoughAccountKeys); } - let compressible_params = CompressibleParamsInfos::new( + let compressible_params = CompressibleParamsCpi::new( accounts[5].clone(), accounts[6].clone(), accounts[4].clone(), ); - CreateAssociatedTokenAccountInfos { + CreateAssociatedTokenAccountCpi { owner: accounts[0].clone(), mint: accounts[1].clone(), payer: accounts[2].clone(), @@ -77,14 +77,14 @@ pub fn process_create_ata2_invoke_signed( return Err(ProgramError::InvalidSeeds); } - let compressible_params = CompressibleParamsInfos::new( + let compressible_params = CompressibleParamsCpi::new( accounts[5].clone(), accounts[6].clone(), accounts[4].clone(), ); let signer_seeds: &[&[u8]] = &[ATA_SEED, &[bump]]; - CreateAssociatedTokenAccountInfos { + CreateAssociatedTokenAccountCpi { owner: accounts[0].clone(), mint: accounts[1].clone(), payer: accounts[2].clone(), // PDA diff --git a/sdk-tests/sdk-ctoken-test/src/create_cmint.rs b/sdk-tests/sdk-ctoken-test/src/create_cmint.rs index e989af62d6..419e9776e3 100644 --- a/sdk-tests/sdk-ctoken-test/src/create_cmint.rs +++ b/sdk-tests/sdk-ctoken-test/src/create_cmint.rs @@ -1,8 +1,6 @@ use borsh::{BorshDeserialize, BorshSerialize}; use light_ctoken_sdk::{ - ctoken::{ - CreateCMintAccountInfos, CreateCMintParams, ExtensionInstructionData, SystemAccountInfos, - }, + ctoken::{CreateCMintCpi, CreateCMintParams, ExtensionInstructionData, SystemAccountInfos}, CompressedProof, }; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; @@ -27,9 +25,9 @@ pub struct CreateCmintData { /// Handler for creating a compressed mint (invoke) /// -/// Uses the CreateCMintAccountInfos builder pattern. This demonstrates how to: +/// Uses the CreateCMintCpi builder pattern. This demonstrates how to: /// 1. Build the CreateCMintParams struct from instruction data -/// 2. Build the CreateCMintAccountInfos with accounts +/// 2. Build the CreateCMintCpi with accounts /// 3. Call invoke() which handles instruction building and CPI /// /// Account order: @@ -78,8 +76,8 @@ pub fn process_create_cmint( // Build the account infos struct // In this case, payer == authority (accounts[3]) - CreateCMintAccountInfos { - mint_signer: accounts[2].clone(), + CreateCMintCpi { + mint_seed: accounts[2].clone(), authority: accounts[3].clone(), payer: accounts[3].clone(), address_tree: accounts[11].clone(), @@ -96,7 +94,7 @@ pub fn process_create_cmint( /// Handler for creating a compressed mint with PDA mint signer (invoke_signed) /// -/// Uses the CreateCMintAccountInfos builder pattern with invoke_signed. +/// Uses the CreateCMintCpi builder pattern with invoke_signed. /// The mint_signer is a PDA derived from this program. /// /// Account order: @@ -153,8 +151,8 @@ pub fn process_create_cmint_invoke_signed( // Build the account infos struct // In this case, payer == authority (accounts[3]) - let account_infos = CreateCMintAccountInfos { - mint_signer: accounts[2].clone(), + let account_infos = CreateCMintCpi { + mint_seed: accounts[2].clone(), authority: accounts[3].clone(), payer: accounts[3].clone(), address_tree: accounts[11].clone(), @@ -174,7 +172,7 @@ pub fn process_create_cmint_invoke_signed( /// Handler for creating a compressed mint with PDA mint signer AND PDA authority (invoke_signed) /// -/// Uses the SDK's CreateCMintAccountInfos with separate authority and payer accounts. +/// Uses the SDK's CreateCMintCpi with separate authority and payer accounts. /// Both mint_signer and authority are PDAs signed by this program. /// /// Account order: @@ -241,8 +239,8 @@ pub fn process_create_cmint_with_pda_authority( }; // Build the account infos struct using SDK - let account_infos = CreateCMintAccountInfos { - mint_signer: accounts[2].clone(), + let account_infos = CreateCMintCpi { + mint_seed: accounts[2].clone(), authority: accounts[3].clone(), payer: accounts[4].clone(), address_tree: accounts[11].clone(), diff --git a/sdk-tests/sdk-ctoken-test/src/create_token_account.rs b/sdk-tests/sdk-ctoken-test/src/create_token_account.rs index 9c21dcf598..b0e2231f22 100644 --- a/sdk-tests/sdk-ctoken-test/src/create_token_account.rs +++ b/sdk-tests/sdk-ctoken-test/src/create_token_account.rs @@ -1,5 +1,5 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_sdk::ctoken::{CompressibleParamsInfos, CreateCTokenAccountInfos}; +use light_ctoken_sdk::ctoken::{CompressibleParamsCpi, CreateCTokenAccountCpi}; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::{ID, TOKEN_ACCOUNT_SEED}; @@ -34,14 +34,14 @@ pub fn process_create_token_account_invoke( } // Build the compressible params using constructor - let compressible_params = CompressibleParamsInfos::new( + let compressible_params = CompressibleParamsCpi::new( accounts[3].clone(), accounts[5].clone(), accounts[4].clone(), ); // Build the account infos struct - CreateCTokenAccountInfos { + CreateCTokenAccountCpi { payer: accounts[0].clone(), account: accounts[1].clone(), mint: accounts[2].clone(), @@ -79,14 +79,14 @@ pub fn process_create_token_account_invoke_signed( } // Build the compressible params using constructor - let compressible_params = CompressibleParamsInfos::new( + let compressible_params = CompressibleParamsCpi::new( accounts[3].clone(), accounts[5].clone(), accounts[4].clone(), ); // Build the account infos struct - let account_infos = CreateCTokenAccountInfos { + let account_infos = CreateCTokenAccountCpi { payer: accounts[0].clone(), account: accounts[1].clone(), mint: accounts[2].clone(), diff --git a/sdk-tests/sdk-ctoken-test/src/lib.rs b/sdk-tests/sdk-ctoken-test/src/lib.rs index 1c90d75c12..fd9d253c72 100644 --- a/sdk-tests/sdk-ctoken-test/src/lib.rs +++ b/sdk-tests/sdk-ctoken-test/src/lib.rs @@ -38,7 +38,7 @@ pub use transfer_interface::{ }; pub use transfer_spl_ctoken::{ process_ctoken_to_spl_invoke, process_ctoken_to_spl_invoke_signed, - process_spl_to_ctoken_invoke, process_spl_to_ctoken_invoke_signed, TransferCtokenToSplData, + process_spl_to_ctoken_invoke, process_spl_to_ctoken_invoke_signed, TransferCTokenToSplData, TransferSplToCtokenData, TRANSFER_AUTHORITY_SEED, }; @@ -227,12 +227,12 @@ pub fn process_instruction( process_spl_to_ctoken_invoke_signed(accounts, data) } InstructionType::CtokenToSplInvoke => { - let data = TransferCtokenToSplData::try_from_slice(&instruction_data[1..]) + let data = TransferCTokenToSplData::try_from_slice(&instruction_data[1..]) .map_err(|_| ProgramError::InvalidInstructionData)?; process_ctoken_to_spl_invoke(accounts, data) } InstructionType::CtokenToSplInvokeSigned => { - let data = TransferCtokenToSplData::try_from_slice(&instruction_data[1..]) + let data = TransferCTokenToSplData::try_from_slice(&instruction_data[1..]) .map_err(|_| ProgramError::InvalidInstructionData)?; process_ctoken_to_spl_invoke_signed(accounts, data) } diff --git a/sdk-tests/sdk-ctoken-test/src/mint_to_ctoken.rs b/sdk-tests/sdk-ctoken-test/src/mint_to_ctoken.rs index cddab000f5..e3b10c89ef 100644 --- a/sdk-tests/sdk-ctoken-test/src/mint_to_ctoken.rs +++ b/sdk-tests/sdk-ctoken-test/src/mint_to_ctoken.rs @@ -1,6 +1,6 @@ use borsh::{BorshDeserialize, BorshSerialize}; use light_ctoken_interface::instructions::mint_action::CompressedMintWithContext; -use light_ctoken_sdk::ctoken::{MintToCTokenInfos, MintToCTokenParams, SystemAccountInfos}; +use light_ctoken_sdk::ctoken::{MintToCTokenCpi, MintToCTokenParams, SystemAccountInfos}; use light_sdk::instruction::ValidityProof; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; @@ -20,9 +20,9 @@ pub struct MintToCTokenData { /// Handler for minting tokens to compressed token accounts /// -/// Uses the MintToCTokenInfos builder pattern. This demonstrates how to: +/// Uses the MintToCTokenCpi builder pattern. This demonstrates how to: /// 1. Build MintToCTokenParams using the constructor -/// 2. Build MintToCTokenInfos with accounts and params +/// 2. Build MintToCTokenCpi with accounts and params /// 3. Call invoke() which handles instruction building and CPI /// /// Account order (all accounts from SDK-generated instruction): @@ -71,7 +71,7 @@ pub fn process_mint_to_ctoken( // Build the account infos struct and invoke // SDK account order: output_queue (9), tree (10), input_queue (11), ctoken_accounts (12+) // In this case, payer == authority (accounts[3]) - MintToCTokenInfos { + MintToCTokenCpi { authority: accounts[2].clone(), // authority from SDK accounts payer: accounts[3].clone(), // fee_payer from SDK accounts state_tree: accounts[10].clone(), // tree at index 10 @@ -90,7 +90,7 @@ pub fn process_mint_to_ctoken( /// Handler for minting tokens with PDA mint authority (invoke_signed) /// -/// Uses the MintToCTokenInfos builder pattern with invoke_signed. +/// Uses the MintToCTokenCpi builder pattern with invoke_signed. /// The mint authority is a PDA derived from this program. /// /// Account order (all accounts from SDK-generated instruction): @@ -146,7 +146,7 @@ pub fn process_mint_to_ctoken_invoke_signed( // Build the account infos struct // authority is the PDA (accounts[2]) - let account_infos = MintToCTokenInfos { + let account_infos = MintToCTokenCpi { authority: accounts[2].clone(), // authority PDA payer: accounts[3].clone(), // fee_payer from SDK accounts state_tree: accounts[10].clone(), // tree at index 10 diff --git a/sdk-tests/sdk-ctoken-test/src/transfer.rs b/sdk-tests/sdk-ctoken-test/src/transfer.rs index 134eee35c6..1e21cfa7bd 100644 --- a/sdk-tests/sdk-ctoken-test/src/transfer.rs +++ b/sdk-tests/sdk-ctoken-test/src/transfer.rs @@ -1,5 +1,5 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_sdk::ctoken::TransferCtokenAccountInfos; +use light_ctoken_sdk::ctoken::TransferCTokenCpi; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::{ID, TOKEN_ACCOUNT_SEED}; @@ -29,7 +29,7 @@ pub fn process_transfer_invoke( } // Build the account infos struct using the builder pattern - TransferCtokenAccountInfos { + TransferCTokenCpi { source: accounts[0].clone(), destination: accounts[1].clone(), amount: data.amount, @@ -69,7 +69,7 @@ pub fn process_transfer_invoke_signed( } // Build the account infos struct - let transfer_accounts = TransferCtokenAccountInfos { + let transfer_accounts = TransferCTokenCpi { source: accounts[0].clone(), destination: accounts[1].clone(), amount: data.amount, diff --git a/sdk-tests/sdk-ctoken-test/src/transfer_interface.rs b/sdk-tests/sdk-ctoken-test/src/transfer_interface.rs index 284a2a3b4a..c04c2a54de 100644 --- a/sdk-tests/sdk-ctoken-test/src/transfer_interface.rs +++ b/sdk-tests/sdk-ctoken-test/src/transfer_interface.rs @@ -1,5 +1,5 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_sdk::ctoken::TransferInterface; +use light_ctoken_sdk::ctoken::TransferInterfaceCpi; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::ID; @@ -41,7 +41,7 @@ pub fn process_transfer_interface_invoke( return Err(ProgramError::NotEnoughAccountKeys); } - let mut transfer = TransferInterface::new( + let mut transfer = TransferInterfaceCpi::new( data.amount, accounts[1].clone(), // source_account accounts[2].clone(), // destination_account @@ -65,7 +65,7 @@ pub fn process_transfer_interface_invoke( Ok(()) } -/// Handler for TransferInterface with PDA authority (invoke_signed) +/// Handler for TransferInterfaceCpi with PDA authority (invoke_signed) /// /// The authority is a PDA derived from TRANSFER_INTERFACE_AUTHORITY_SEED. /// @@ -97,7 +97,7 @@ pub fn process_transfer_interface_invoke_signed( return Err(ProgramError::InvalidSeeds); } - let mut transfer = TransferInterface::new( + let mut transfer = TransferInterfaceCpi::new( data.amount, accounts[1].clone(), // source_account accounts[2].clone(), // destination_account 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 33669159b0..f2b60f8bb7 100644 --- a/sdk-tests/sdk-ctoken-test/src/transfer_spl_ctoken.rs +++ b/sdk-tests/sdk-ctoken-test/src/transfer_spl_ctoken.rs @@ -1,5 +1,5 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_sdk::ctoken::{TransferCtokenToSplAccountInfos, TransferSplToCtokenAccountInfos}; +use light_ctoken_sdk::ctoken::{TransferCTokenToSplCpi, TransferSplToCtokenCpi}; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::ID; @@ -16,7 +16,7 @@ pub struct TransferSplToCtokenData { /// Instruction data for CToken to SPL transfer #[derive(BorshSerialize, BorshDeserialize, Debug)] -pub struct TransferCtokenToSplData { +pub struct TransferCTokenToSplData { pub amount: u64, pub spl_interface_pda_bump: u8, } @@ -41,7 +41,7 @@ pub fn process_spl_to_ctoken_invoke( return Err(ProgramError::NotEnoughAccountKeys); } - TransferSplToCtokenAccountInfos { + TransferSplToCtokenCpi { source_spl_token_account: accounts[1].clone(), destination_ctoken_account: accounts[2].clone(), amount: data.amount, @@ -89,7 +89,7 @@ pub fn process_spl_to_ctoken_invoke_signed( return Err(ProgramError::InvalidSeeds); } - let account_infos = TransferSplToCtokenAccountInfos { + let account_infos = TransferSplToCtokenCpi { source_spl_token_account: accounts[1].clone(), destination_ctoken_account: accounts[2].clone(), amount: data.amount, @@ -123,13 +123,13 @@ pub fn process_spl_to_ctoken_invoke_signed( /// - accounts[8]: compressed_token_program_authority pub fn process_ctoken_to_spl_invoke( accounts: &[AccountInfo], - data: TransferCtokenToSplData, + data: TransferCTokenToSplData, ) -> Result<(), ProgramError> { if accounts.len() < 9 { return Err(ProgramError::NotEnoughAccountKeys); } - TransferCtokenToSplAccountInfos { + TransferCTokenToSplCpi { source_ctoken_account: accounts[1].clone(), destination_spl_token_account: accounts[2].clone(), amount: data.amount, @@ -162,7 +162,7 @@ pub fn process_ctoken_to_spl_invoke( /// - accounts[8]: compressed_token_program_authority pub fn process_ctoken_to_spl_invoke_signed( accounts: &[AccountInfo], - data: TransferCtokenToSplData, + data: TransferCTokenToSplData, ) -> Result<(), ProgramError> { if accounts.len() < 9 { return Err(ProgramError::NotEnoughAccountKeys); @@ -177,7 +177,7 @@ pub fn process_ctoken_to_spl_invoke_signed( return Err(ProgramError::InvalidSeeds); } - let account_infos = TransferCtokenToSplAccountInfos { + let account_infos = TransferCTokenToSplCpi { source_ctoken_account: accounts[1].clone(), destination_spl_token_account: accounts[2].clone(), amount: data.amount, diff --git a/sdk-tests/sdk-ctoken-test/tests/shared.rs b/sdk-tests/sdk-ctoken-test/tests/shared.rs index 80f14e0637..fbf5b587bf 100644 --- a/sdk-tests/sdk-ctoken-test/tests/shared.rs +++ b/sdk-tests/sdk-ctoken-test/tests/shared.rs @@ -20,17 +20,17 @@ pub async fn setup_create_compressed_mint( MintToCTokenParams, }; - let mint_signer = Keypair::new(); + let mint_seed = Keypair::new(); let address_tree = rpc.get_address_tree_v2(); let output_queue = rpc.get_random_state_tree_info().unwrap().queue; // Derive compression address using SDK helpers - let compression_address = light_ctoken_sdk::ctoken::derive_compressed_mint_address( - &mint_signer.pubkey(), + let compression_address = light_ctoken_sdk::ctoken::derive_cmint_compressed_address( + &mint_seed.pubkey(), &address_tree.tree, ); - let mint_pda = light_ctoken_sdk::ctoken::find_spl_mint_address(&mint_signer.pubkey()).0; + let mint = light_ctoken_sdk::ctoken::find_cmint_address(&mint_seed.pubkey()).0; // Get validity proof for the address let rpc_result = rpc @@ -53,7 +53,7 @@ pub async fn setup_create_compressed_mint( mint_authority, proof: rpc_result.proof.0.unwrap(), compression_address, - mint: mint_pda, + mint, freeze_authority: None, extensions: None, }; @@ -61,7 +61,7 @@ pub async fn setup_create_compressed_mint( // Create instruction directly using SDK let create_cmint_builder = CreateCMint::new( params, - mint_signer.pubkey(), + mint_seed.pubkey(), payer.pubkey(), address_tree.tree, output_queue, @@ -69,7 +69,7 @@ pub async fn setup_create_compressed_mint( let instruction = create_cmint_builder.instruction().unwrap(); // Send transaction - rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &[payer, &mint_signer]) + rpc.create_and_send_transaction(&[instruction], &payer.pubkey(), &[payer, &mint_seed]) .await .unwrap(); @@ -87,7 +87,7 @@ pub async fn setup_create_compressed_mint( // If no recipients, return early if recipients.is_empty() { - return (mint_pda, compression_address, vec![]); + return (mint, compression_address, vec![]); } // Create ATAs for each recipient @@ -96,10 +96,10 @@ pub async fn setup_create_compressed_mint( let mut ata_pubkeys = Vec::with_capacity(recipients.len()); for (_amount, owner) in &recipients { - let (ata_address, _bump) = derive_ctoken_ata(owner, &mint_pda); + let (ata_address, _bump) = derive_ctoken_ata(owner, &mint); ata_pubkeys.push(ata_address); - let create_ata = CreateAssociatedTokenAccount::new(payer.pubkey(), *owner, mint_pda); + let create_ata = CreateAssociatedTokenAccount::new(payer.pubkey(), *owner, mint); let ata_instruction = create_ata.instruction().unwrap(); rpc.create_and_send_transaction(&[ata_instruction], &payer.pubkey(), &[payer]) @@ -180,5 +180,5 @@ pub async fn setup_create_compressed_mint( .unwrap(); } - (mint_pda, compression_address, ata_pubkeys) + (mint, compression_address, ata_pubkeys) } diff --git a/sdk-tests/sdk-ctoken-test/tests/test_close.rs b/sdk-tests/sdk-ctoken-test/tests/test_close.rs index e44abb54e3..f87680de2b 100644 --- a/sdk-tests/sdk-ctoken-test/tests/test_close.rs +++ b/sdk-tests/sdk-ctoken-test/tests/test_close.rs @@ -1,4 +1,4 @@ -// Tests for CloseAccountInfos invoke() and invoke_signed() +// Tests for CloseCTokenAccountCpi invoke() and invoke_signed() mod shared; @@ -13,7 +13,7 @@ use solana_sdk::{ signer::Signer, }; -/// Test closing a compressible token account using CloseAccountInfos::invoke() +/// Test closing a compressible token account using CloseCTokenAccountCpi::invoke() #[tokio::test] async fn test_close_invoke() { let config = ProgramTestConfig::new_v2(true, Some(vec![("native_ctoken_examples", ID)])); @@ -67,7 +67,7 @@ async fn test_close_invoke() { ); } -/// Test closing a PDA-owned compressible token account using CloseAccountInfos::invoke_signed() +/// Test closing a PDA-owned compressible token account using CloseCTokenAccountCpi::invoke_signed() #[tokio::test] async fn test_close_invoke_signed() { let config = ProgramTestConfig::new_v2(true, Some(vec![("native_ctoken_examples", ID)])); diff --git a/sdk-tests/sdk-ctoken-test/tests/test_create_ata.rs b/sdk-tests/sdk-ctoken-test/tests/test_create_ata.rs index 7416c7c558..33ef4bb81c 100644 --- a/sdk-tests/sdk-ctoken-test/tests/test_create_ata.rs +++ b/sdk-tests/sdk-ctoken-test/tests/test_create_ata.rs @@ -1,4 +1,4 @@ -// Tests for CreateAssociatedTokenAccountInfos (CreateAta instructions) +// Tests for CreateAssociatedTokenAccountCpi (CreateAta instructions) mod shared; @@ -14,7 +14,7 @@ use solana_sdk::{ signer::Signer, }; -/// Test creating an ATA using CreateAssociatedTokenAccountInfos::invoke() +/// Test creating an ATA using CreateAssociatedTokenAccountCpi::invoke() #[tokio::test] async fn test_create_ata_invoke() { let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2( @@ -88,7 +88,7 @@ async fn test_create_ata_invoke() { assert_eq!(account_state.amount, 0, "Initial amount should be 0"); } -/// Test creating an ATA with PDA payer using CreateAssociatedTokenAccountInfos::invoke_signed() +/// Test creating an ATA with PDA payer using CreateAssociatedTokenAccountCpi::invoke_signed() #[tokio::test] async fn test_create_ata_invoke_signed() { let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2( diff --git a/sdk-tests/sdk-ctoken-test/tests/test_create_cmint.rs b/sdk-tests/sdk-ctoken-test/tests/test_create_cmint.rs index d127bc58ec..4a659d916a 100644 --- a/sdk-tests/sdk-ctoken-test/tests/test_create_cmint.rs +++ b/sdk-tests/sdk-ctoken-test/tests/test_create_cmint.rs @@ -1,4 +1,4 @@ -// Tests for CreateCMintAccountInfos (CreateCmint instruction) +// Tests for CreateCMintCpi (CreateCmint instruction) mod shared; @@ -20,7 +20,7 @@ use solana_sdk::{ signer::Signer, }; -/// Test creating a compressed mint using CreateCMintAccountInfos::invoke() +/// Test creating a compressed mint using CreateCMintCpi::invoke() #[tokio::test] async fn test_create_compressed_mint() { let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2( @@ -39,15 +39,15 @@ async fn test_create_compressed_mint() { let output_queue = rpc.get_random_state_tree_info().unwrap().queue; let compressed_token_program_id = - Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); // Use SDK helper to derive the compression address correctly - let compression_address = light_ctoken_sdk::ctoken::derive_compressed_mint_address( + let compression_address = light_ctoken_sdk::ctoken::derive_cmint_compressed_address( &mint_signer.pubkey(), &address_tree.tree, ); - let mint_pda = light_ctoken_sdk::ctoken::find_spl_mint_address(&mint_signer.pubkey()).0; + let mint_pda = light_ctoken_sdk::ctoken::find_cmint_address(&mint_signer.pubkey()).0; let rpc_result = rpc .get_validity_proof( @@ -126,7 +126,7 @@ async fn test_create_compressed_mint() { assert!(compressed_account.is_some(), "Compressed mint should exist"); } -/// Test creating a compressed mint with PDA mint signer using CreateCMintAccountInfos::invoke_signed() +/// Test creating a compressed mint with PDA mint signer using CreateCMintCpi::invoke_signed() #[tokio::test] async fn test_create_compressed_mint_invoke_signed() { let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2( @@ -147,15 +147,15 @@ async fn test_create_compressed_mint_invoke_signed() { let output_queue = rpc.get_random_state_tree_info().unwrap().queue; let compressed_token_program_id = - Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); // Use SDK helper to derive the compression address correctly - let compression_address = light_ctoken_sdk::ctoken::derive_compressed_mint_address( + let compression_address = light_ctoken_sdk::ctoken::derive_cmint_compressed_address( &mint_signer_pda, &address_tree.tree, ); - let mint_pda = light_ctoken_sdk::ctoken::find_spl_mint_address(&mint_signer_pda).0; + let mint_pda = light_ctoken_sdk::ctoken::find_cmint_address(&mint_signer_pda).0; let rpc_result = rpc .get_validity_proof( diff --git a/sdk-tests/sdk-ctoken-test/tests/test_create_token_account.rs b/sdk-tests/sdk-ctoken-test/tests/test_create_token_account.rs index 9b54a54ac2..890b6ab51e 100644 --- a/sdk-tests/sdk-ctoken-test/tests/test_create_token_account.rs +++ b/sdk-tests/sdk-ctoken-test/tests/test_create_token_account.rs @@ -1,4 +1,4 @@ -// Tests for CreateCTokenAccountInfos (CreateTokenAccount instructions) +// Tests for CreateCTokenAccountCpi (CreateTokenAccount instructions) mod shared; @@ -15,7 +15,7 @@ use solana_sdk::{ signer::Signer, }; -/// Test creating a token account using CreateCTokenAccountInfos::invoke() +/// Test creating a token account using CreateCTokenAccountCpi::invoke() #[tokio::test] async fn test_create_token_account_invoke() { let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2( @@ -88,7 +88,7 @@ async fn test_create_token_account_invoke() { assert_eq!(account_state.amount, 0, "Initial amount should be 0"); } -/// Test creating a PDA-owned token account using CreateCTokenAccountInfos::invoke_signed() +/// Test creating a PDA-owned token account using CreateCTokenAccountCpi::invoke_signed() #[tokio::test] async fn test_create_token_account_invoke_signed() { let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2( diff --git a/sdk-tests/sdk-ctoken-test/tests/test_mint_to_ctoken.rs b/sdk-tests/sdk-ctoken-test/tests/test_mint_to_ctoken.rs index 3f33b5fae1..25d59bba1a 100644 --- a/sdk-tests/sdk-ctoken-test/tests/test_mint_to_ctoken.rs +++ b/sdk-tests/sdk-ctoken-test/tests/test_mint_to_ctoken.rs @@ -1,4 +1,4 @@ -// Tests for MintToCTokenInfos (MintToCtoken instruction) +// Tests for MintToCTokenCpi (MintToCtoken instruction) mod shared; @@ -20,7 +20,7 @@ use solana_sdk::{ signer::Signer, }; -/// Test minting tokens to a ctoken account using MintToCTokenInfos::invoke() +/// Test minting tokens to a ctoken account using MintToCTokenCpi::invoke() #[tokio::test] async fn test_mint_to_ctoken() { let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2( @@ -124,7 +124,7 @@ async fn test_mint_to_ctoken() { // Build wrapper instruction with compressed token program as first account let compressed_token_program_id = - Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let mut wrapper_accounts = vec![AccountMeta::new_readonly( compressed_token_program_id, @@ -175,7 +175,7 @@ async fn test_mint_to_ctoken() { ); } -/// Test minting tokens with PDA mint authority using MintToCTokenInfos::invoke_signed() +/// Test minting tokens with PDA mint authority using MintToCTokenCpi::invoke_signed() /// /// This test uses the wrapper program to: /// 1. Create a compressed mint with PDA authority (discriminator 14 - CreateCmintWithPdaAuthority) @@ -200,12 +200,12 @@ async fn test_mint_to_ctoken_invoke_signed() { let output_queue = rpc.get_random_state_tree_info().unwrap().queue; // Derive compression address using the PDA mint_signer - let compression_address = light_ctoken_sdk::ctoken::derive_compressed_mint_address( + let compression_address = light_ctoken_sdk::ctoken::derive_cmint_compressed_address( &mint_signer_pda, &address_tree.tree, ); - let mint_pda = light_ctoken_sdk::ctoken::find_spl_mint_address(&mint_signer_pda).0; + let mint_pda = light_ctoken_sdk::ctoken::find_cmint_address(&mint_signer_pda).0; let rpc_result = rpc .get_validity_proof( @@ -221,7 +221,7 @@ async fn test_mint_to_ctoken_invoke_signed() { .value; let compressed_token_program_id = - Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let default_pubkeys = light_ctoken_sdk::utils::CTokenDefaultAccounts::default(); // Step 1: Create compressed mint with PDA authority using wrapper program (discriminator 14) @@ -362,7 +362,7 @@ async fn test_mint_to_ctoken_invoke_signed() { // Build accounts manually since SDK marks authority as signer, but we need it as non-signer // for invoke_signed (the wrapper program signs via CPI) let compressed_token_program_id = - Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let default_pubkeys = light_ctoken_sdk::utils::CTokenDefaultAccounts::default(); let wrapper_accounts = vec![ 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 876736c242..3b87fca1e2 100644 --- a/sdk-tests/sdk-ctoken-test/tests/test_transfer_interface.rs +++ b/sdk-tests/sdk-ctoken-test/tests/test_transfer_interface.rs @@ -1,4 +1,4 @@ -// Tests for TransferInterface - unified transfer interface that auto-detects account types +// Tests for TransferInterfaceCpi - unified transfer interface that auto-detects account types mod shared; @@ -23,7 +23,7 @@ use solana_sdk::{ // INVOKE TESTS (regular signer authority) // ============================================================================= -/// Test TransferInterface: SPL -> CToken (invoke) +/// Test TransferInterfaceCpi: SPL -> CToken (invoke) #[tokio::test] async fn test_transfer_interface_spl_to_ctoken_invoke() { let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2( @@ -77,7 +77,7 @@ async fn test_transfer_interface_spl_to_ctoken_invoke() { // Get token pool 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); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); // Build wrapper instruction @@ -183,7 +183,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke() { 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); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); // Transfer SPL to CToken to fund it @@ -323,7 +323,7 @@ async fn test_transfer_interface_ctoken_to_ctoken_invoke() { 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); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); // Fund sender CToken @@ -466,7 +466,7 @@ async fn test_transfer_interface_spl_to_ctoken_invoke_signed() { 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); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); let data = TransferInterfaceData { @@ -589,7 +589,7 @@ async fn test_transfer_interface_ctoken_to_spl_invoke_signed() { 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); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); // Fund PDA's CToken @@ -742,7 +742,7 @@ async fn test_transfer_interface_ctoken_to_ctoken_invoke_signed() { 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); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); // Fund source CToken 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 4e06adeac1..107cf3425e 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 @@ -1,4 +1,4 @@ -// Tests for TransferSplToCtokenAccountInfos and TransferCtokenToSplAccountInfos +// Tests for TransferSplToCtokenCpi and TransferCTokenToSplCpi mod shared; @@ -12,7 +12,7 @@ use light_ctoken_sdk::{ use light_program_test::{LightProgramTest, ProgramTestConfig}; use light_test_utils::spl::{create_mint_helper, create_token_2022_account, mint_spl_tokens}; use native_ctoken_examples::{ - TransferCtokenToSplData, TransferSplToCtokenData, ID, TRANSFER_AUTHORITY_SEED, + TransferCTokenToSplData, TransferSplToCtokenData, ID, TRANSFER_AUTHORITY_SEED, }; use solana_sdk::{ instruction::{AccountMeta, Instruction}, @@ -21,7 +21,7 @@ use solana_sdk::{ signer::Signer, }; -/// Test transferring SPL tokens to CToken using TransferSplToCtokenAccountInfos::invoke() +/// Test transferring SPL tokens to CToken using TransferSplToCtokenCpi::invoke() #[tokio::test] async fn test_spl_to_ctoken_invoke() { let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2( @@ -88,7 +88,7 @@ async fn test_spl_to_ctoken_invoke() { // Get token pool 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); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); // Build wrapper instruction for SPL to CToken transfer @@ -155,7 +155,7 @@ async fn test_spl_to_ctoken_invoke() { println!("SPL to CToken invoke test passed"); } -/// Test transferring CToken to SPL tokens using TransferCtokenToSplAccountInfos::invoke() +/// Test transferring CToken to SPL tokens using TransferCTokenToSplCpi::invoke() #[tokio::test] async fn test_ctoken_to_spl_invoke() { let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2( @@ -211,7 +211,7 @@ async fn test_ctoken_to_spl_invoke() { // Transfer from temp SPL to ctoken to fund it 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); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); { @@ -251,7 +251,7 @@ async fn test_ctoken_to_spl_invoke() { assert_eq!(u64::from(ctoken_state.amount), amount); // Now test CToken to SPL transfer - let data = TransferCtokenToSplData { + let data = TransferCTokenToSplData { amount: transfer_amount, spl_interface_pda_bump, }; @@ -380,7 +380,7 @@ async fn test_spl_to_ctoken_invoke_signed() { // 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); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); // Build wrapper instruction for SPL to CToken transfer with PDA authority @@ -518,7 +518,7 @@ async fn test_ctoken_to_spl_invoke_signed() { // Transfer from temp SPL to ctoken to fund it 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); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let cpi_authority_pda = Pubkey::new_from_array(CPI_AUTHORITY_PDA); { @@ -558,7 +558,7 @@ async fn test_ctoken_to_spl_invoke_signed() { assert_eq!(u64::from(ctoken_state.amount), amount); // Now test CToken to SPL transfer with PDA authority - let data = TransferCtokenToSplData { + let data = TransferCTokenToSplData { amount: transfer_amount, spl_interface_pda_bump, }; diff --git a/sdk-tests/sdk-token-test/Cargo.toml b/sdk-tests/sdk-token-test/Cargo.toml index 035402236f..1c086c53eb 100644 --- a/sdk-tests/sdk-token-test/Cargo.toml +++ b/sdk-tests/sdk-token-test/Cargo.toml @@ -32,6 +32,7 @@ profile-heap = [ [dependencies] light-ctoken-sdk = { workspace = true, features = ["anchor", "cpi-context", "v1"] } +light-compressed-token-types = { workspace = true } anchor-lang = { workspace = true } light-hasher = { workspace = true } light-sdk = { workspace = true, features = ["v2", "cpi-context"] } diff --git a/sdk-tests/sdk-token-test/src/lib.rs b/sdk-tests/sdk-token-test/src/lib.rs index bde70ac664..57c02809d9 100644 --- a/sdk-tests/sdk-token-test/src/lib.rs +++ b/sdk-tests/sdk-token-test/src/lib.rs @@ -4,7 +4,8 @@ use anchor_lang::prelude::*; use light_ctoken_sdk::{ - compressed_token::batch_compress::Recipient, TokenAccountMeta, ValidityProof, + compressed_token::{batch_compress::Recipient, TokenAccountMeta}, + ValidityProof, }; use light_sdk::instruction::{PackedAddressTreeInfo, ValidityProof as LightValidityProof}; diff --git a/sdk-tests/sdk-token-test/src/process_batch_compress_tokens.rs b/sdk-tests/sdk-token-test/src/process_batch_compress_tokens.rs index dae4ef85d9..1c79b0422c 100644 --- a/sdk-tests/sdk-token-test/src/process_batch_compress_tokens.rs +++ b/sdk-tests/sdk-token-test/src/process_batch_compress_tokens.rs @@ -1,9 +1,7 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; -use light_ctoken_sdk::{ - account_infos::BatchCompressAccountInfos, - compressed_token::batch_compress::{ - create_batch_compress_instruction, BatchCompressInputs, Recipient, - }, +use light_compressed_token_types::account_infos::BatchCompressAccountInfos; +use light_ctoken_sdk::compressed_token::batch_compress::{ + create_batch_compress_instruction, BatchCompressInputs, Recipient, }; use crate::Generic; @@ -31,7 +29,7 @@ pub fn process_batch_compress_tokens<'info>( let batch_compress_inputs = BatchCompressInputs { fee_payer: *ctx.accounts.signer.key, authority: *ctx.accounts.signer.key, - token_pool_pda: *light_cpi_accounts.token_pool_pda().unwrap().key, + spl_interface_pda: *light_cpi_accounts.token_pool_pda().unwrap().key, sender_token_account: *light_cpi_accounts.sender_token_account().unwrap().key, token_program: *light_cpi_accounts.token_program().unwrap().key, merkle_tree: *light_cpi_accounts.merkle_tree().unwrap().key, diff --git a/sdk-tests/sdk-token-test/src/process_compress_full_and_close.rs b/sdk-tests/sdk-token-test/src/process_compress_full_and_close.rs index ba54f3c745..adcfa61113 100644 --- a/sdk-tests/sdk-token-test/src/process_compress_full_and_close.rs +++ b/sdk-tests/sdk-token-test/src/process_compress_full_and_close.rs @@ -7,7 +7,7 @@ use light_ctoken_sdk::{ }, CTokenAccount2, }, - ctoken::CloseAccount, + ctoken::CloseCTokenAccount, }; use light_sdk_types::cpi_accounts::{v2::CpiAccounts, CpiAccountsConfig}; @@ -87,9 +87,9 @@ pub fn process_compress_full_and_close<'info>( invoke(&instruction, account_infos.as_slice())?; let compressed_token_program_id = - Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); // Create close instruction without rent_sponsor for non-compressible accounts - let close_instruction = CloseAccount { + let close_instruction = CloseCTokenAccount { token_program: compressed_token_program_id, account: *token_account_info.key, destination: *close_recipient_info.key, diff --git a/sdk-tests/sdk-token-test/src/process_compress_tokens.rs b/sdk-tests/sdk-token-test/src/process_compress_tokens.rs index 1d552a2a02..1cb3743252 100644 --- a/sdk-tests/sdk-token-test/src/process_compress_tokens.rs +++ b/sdk-tests/sdk-token-test/src/process_compress_tokens.rs @@ -27,7 +27,7 @@ pub fn process_compress_tokens<'info>( sender_token_account: *light_cpi_accounts.sender_token_account().unwrap().key, amount, output_tree_index, - token_pool_pda: *light_cpi_accounts.token_pool_pda().unwrap().key, + spl_interface_pda: *light_cpi_accounts.token_pool_pda().unwrap().key, transfer_config: None, spl_token_program: *light_cpi_accounts.spl_token_program().unwrap().key, tree_accounts: light_cpi_accounts.tree_pubkeys().unwrap(), diff --git a/sdk-tests/sdk-token-test/src/process_create_compressed_account.rs b/sdk-tests/sdk-token-test/src/process_create_compressed_account.rs index 85f5d6ba93..6b5668aad5 100644 --- a/sdk-tests/sdk-token-test/src/process_create_compressed_account.rs +++ b/sdk-tests/sdk-token-test/src/process_create_compressed_account.rs @@ -1,11 +1,8 @@ use anchor_lang::{prelude::*, solana_program::log::sol_log_compute_units}; use light_compressed_account::instruction_data::cpi_context::CompressedCpiContext; -use light_ctoken_sdk::{ - compressed_token::{ - transfer::instruction::{TransferConfig, TransferInputs}, - CTokenAccount, - }, - TokenAccountMeta, +use light_ctoken_sdk::compressed_token::{ + transfer::instruction::{TransferConfig, TransferInputs}, + CTokenAccount, TokenAccountMeta, }; use light_sdk::{ account::LightAccount, diff --git a/sdk-tests/sdk-token-test/src/process_decompress_tokens.rs b/sdk-tests/sdk-token-test/src/process_decompress_tokens.rs index fcc0ff356b..05a4c63b6f 100644 --- a/sdk-tests/sdk-token-test/src/process_decompress_tokens.rs +++ b/sdk-tests/sdk-token-test/src/process_decompress_tokens.rs @@ -5,9 +5,9 @@ use light_ctoken_sdk::{ instruction::{decompress, DecompressInputs}, TransferAccountInfos, }, - CTokenAccount, + CTokenAccount, TokenAccountMeta, }, - TokenAccountMeta, ValidityProof, + ValidityProof, }; use crate::Generic; @@ -38,7 +38,7 @@ pub fn process_decompress_tokens<'info>( sender_account, amount: 10, tree_pubkeys: light_cpi_accounts.tree_pubkeys().unwrap(), - token_pool_pda: *light_cpi_accounts.token_pool_pda().unwrap().key, + spl_interface_pda: *light_cpi_accounts.token_pool_pda().unwrap().key, recipient_token_account: *light_cpi_accounts.decompression_recipient().unwrap().key, spl_token_program: *light_cpi_accounts.spl_token_program().unwrap().key, config: None, diff --git a/sdk-tests/sdk-token-test/src/process_four_invokes.rs b/sdk-tests/sdk-token-test/src/process_four_invokes.rs index a473c6c5b1..55402243d7 100644 --- a/sdk-tests/sdk-token-test/src/process_four_invokes.rs +++ b/sdk-tests/sdk-token-test/src/process_four_invokes.rs @@ -1,13 +1,8 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; use light_compressed_account::instruction_data::cpi_context::CompressedCpiContext; -use light_ctoken_sdk::{ - compressed_token::{ - transfer::instruction::{ - compress, transfer, CompressInputs, TransferConfig, TransferInputs, - }, - CTokenAccount, - }, - TokenAccountMeta, +use light_ctoken_sdk::compressed_token::{ + transfer::instruction::{compress, transfer, CompressInputs, TransferConfig, TransferInputs}, + CTokenAccount, TokenAccountMeta, }; use light_sdk::{ cpi::v2::CpiAccounts, instruction::ValidityProof as LightValidityProof, @@ -174,7 +169,7 @@ fn compress_tokens_with_cpi_context<'a, 'info>( amount, output_tree_index, // output_queue_pubkey: *cpi_accounts.tree_accounts().unwrap()[0].key, - token_pool_pda: *remaining_accounts[1].key, + spl_interface_pda: *remaining_accounts[1].key, transfer_config: Some(TransferConfig { cpi_context: Some(CompressedCpiContext { set_context: true, diff --git a/sdk-tests/sdk-token-test/src/process_transfer_tokens.rs b/sdk-tests/sdk-token-test/src/process_transfer_tokens.rs index 9342a3855e..0e3310bbe2 100644 --- a/sdk-tests/sdk-token-test/src/process_transfer_tokens.rs +++ b/sdk-tests/sdk-token-test/src/process_transfer_tokens.rs @@ -5,9 +5,9 @@ use light_ctoken_sdk::{ instruction::{transfer, TransferInputs}, TransferAccountInfos, }, - CTokenAccount, + CTokenAccount, TokenAccountMeta, }, - TokenAccountMeta, ValidityProof, + ValidityProof, }; use crate::Generic; diff --git a/sdk-tests/sdk-token-test/src/process_update_deposit.rs b/sdk-tests/sdk-token-test/src/process_update_deposit.rs index 47233dfeef..ca82da5842 100644 --- a/sdk-tests/sdk-token-test/src/process_update_deposit.rs +++ b/sdk-tests/sdk-token-test/src/process_update_deposit.rs @@ -1,12 +1,9 @@ use anchor_lang::prelude::*; use light_batched_merkle_tree::queue::BatchedQueueAccount; use light_compressed_account::instruction_data::cpi_context::CompressedCpiContext; -use light_ctoken_sdk::{ - compressed_token::{ - transfer::instruction::{TransferConfig, TransferInputs}, - CTokenAccount, - }, - TokenAccountMeta, +use light_ctoken_sdk::compressed_token::{ + transfer::instruction::{TransferConfig, TransferInputs}, + CTokenAccount, TokenAccountMeta, }; use light_sdk::{ account::LightAccount, diff --git a/sdk-tests/sdk-token-test/tests/ctoken_pda.rs b/sdk-tests/sdk-token-test/tests/ctoken_pda.rs index 19dd8f7ddf..a81d1905ee 100644 --- a/sdk-tests/sdk-token-test/tests/ctoken_pda.rs +++ b/sdk-tests/sdk-token-test/tests/ctoken_pda.rs @@ -1,19 +1,17 @@ use anchor_lang::{AnchorDeserialize, InstructionData, ToAccountMetas}; use light_client::indexer::Indexer; use light_compressed_account::{address::derive_address, hash_to_bn254_field_size_be}; +use light_compressed_token_types::CPI_AUTHORITY_PDA; use light_ctoken_interface::{ instructions::{ extensions::token_metadata::TokenMetadataInstructionData, mint_action::{CompressedMintInstructionData, CompressedMintWithContext, Recipient}, }, state::{extensions::AdditionalMetadata, CompressedMintMetadata}, - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, }; -use light_ctoken_sdk::{ - compressed_token::create_compressed_mint::{ - derive_compressed_mint_address, find_spl_mint_address, - }, - CPI_AUTHORITY_PDA, +use light_ctoken_sdk::compressed_token::create_compressed_mint::{ + derive_cmint_compressed_address, find_cmint_address, }; use light_program_test::{LightProgramTest, ProgramTestConfig, Rpc, RpcError}; use light_sdk::instruction::{PackedAccounts, SystemAccountMetaConfig}; @@ -148,10 +146,10 @@ pub async fn create_mint( // Derive compressed mint address using utility function let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); // Find mint bump for the instruction - let (mint, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (mint, _) = find_cmint_address(&mint_seed.pubkey()); let pda_address_seed = hash_to_bn254_field_size_be( [b"escrow", payer.pubkey().to_bytes().as_ref()] @@ -226,7 +224,7 @@ pub async fn create_mint( payer: payer.pubkey(), mint_authority: mint_authority.pubkey(), mint_seed: mint_seed.pubkey(), - ctoken_program: Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + ctoken_program: Pubkey::new_from_array(CTOKEN_PROGRAM_ID), ctoken_cpi_authority: Pubkey::new_from_array(CPI_AUTHORITY_PDA), }; diff --git a/sdk-tests/sdk-token-test/tests/decompress_full_cpi.rs b/sdk-tests/sdk-token-test/tests/decompress_full_cpi.rs index c674d55420..4c4a5c33df 100644 --- a/sdk-tests/sdk-token-test/tests/decompress_full_cpi.rs +++ b/sdk-tests/sdk-token-test/tests/decompress_full_cpi.rs @@ -6,7 +6,7 @@ const TEST_INPUT_RANGE: [usize; 4] = [1, 2, 3, 4]; use light_ctoken_interface::instructions::mint_action::{CompressedMintWithContext, Recipient}; use light_ctoken_sdk::compressed_token::{ - create_compressed_mint::find_spl_mint_address, decompress_full::DecompressFullAccounts, + create_compressed_mint::find_cmint_address, decompress_full::DecompressFullAccounts, }; use light_program_test::{Indexer, LightProgramTest, ProgramTestConfig, Rpc}; use light_sdk::instruction::PackedAccounts; @@ -45,7 +45,7 @@ async fn setup_decompress_full_test(num_inputs: usize) -> (LightProgramTest, Tes let payer = rpc.get_payer().insecure_clone(); let mint_seed = Keypair::new(); - let mint_pubkey = find_spl_mint_address(&mint_seed.pubkey()).0; + let mint_pubkey = find_cmint_address(&mint_seed.pubkey()).0; let mint_authority = payer.pubkey(); let decimals = 9u8; @@ -332,7 +332,7 @@ async fn test_decompress_full_cpi_with_context() { let address_tree_info = rpc.get_address_tree_v2(); let compressed_mint_address = - light_ctoken_sdk::compressed_token::create_compressed_mint::derive_compressed_mint_address( + light_ctoken_sdk::compressed_token::create_compressed_mint::derive_cmint_compressed_address( &ctx.mint_seed.pubkey(), &address_tree_info.tree, ); diff --git a/sdk-tests/sdk-token-test/tests/pda_ctoken.rs b/sdk-tests/sdk-token-test/tests/pda_ctoken.rs index 83f162582b..7b9c59f677 100644 --- a/sdk-tests/sdk-token-test/tests/pda_ctoken.rs +++ b/sdk-tests/sdk-token-test/tests/pda_ctoken.rs @@ -4,20 +4,20 @@ use anchor_lang::{ use anchor_spl::token_interface::spl_token_2022; use light_client::indexer::Indexer; use light_compressed_account::{address::derive_address, hash_to_bn254_field_size_be}; +use light_compressed_token_types::CPI_AUTHORITY_PDA; use light_ctoken_interface::{ instructions::{ extensions::token_metadata::TokenMetadataInstructionData, mint_action::{CompressedMintInstructionData, CompressedMintWithContext, Recipient}, }, state::{extensions::AdditionalMetadata, CompressedMintMetadata}, - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, }; use light_ctoken_sdk::{ compressed_token::create_compressed_mint::{ - derive_compressed_mint_address, find_spl_mint_address, + derive_cmint_compressed_address, find_cmint_address, }, ctoken::{derive_ctoken_ata, CompressibleParams, CreateAssociatedTokenAccount}, - CPI_AUTHORITY_PDA, }; use light_program_test::{LightProgramTest, ProgramTestConfig, Rpc, RpcError}; use light_sdk::instruction::{PackedAccounts, SystemAccountMetaConfig}; @@ -194,10 +194,10 @@ pub async fn create_mint( // Derive compressed mint address using utility function let compressed_mint_address = - derive_compressed_mint_address(&mint_seed.pubkey(), &address_tree_pubkey); + derive_cmint_compressed_address(&mint_seed.pubkey(), &address_tree_pubkey); // Find mint bump for the instruction - let (mint, _) = find_spl_mint_address(&mint_seed.pubkey()); + let (mint, _) = find_cmint_address(&mint_seed.pubkey()); // Create compressed token associated token account for the mint authority let (token_account, _) = derive_ctoken_ata(&mint_authority.pubkey(), &mint); @@ -296,7 +296,7 @@ pub async fn create_mint( payer: payer.pubkey(), mint_authority: mint_authority.pubkey(), mint_seed: mint_seed.pubkey(), - ctoken_program: Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + ctoken_program: Pubkey::new_from_array(CTOKEN_PROGRAM_ID), ctoken_cpi_authority: Pubkey::new_from_array(CPI_AUTHORITY_PDA), token_account, }; diff --git a/sdk-tests/sdk-token-test/tests/test.rs b/sdk-tests/sdk-token-test/tests/test.rs index cbfb49f56b..e2de43203f 100644 --- a/sdk-tests/sdk-token-test/tests/test.rs +++ b/sdk-tests/sdk-token-test/tests/test.rs @@ -3,6 +3,7 @@ use anchor_lang::{AccountDeserialize, InstructionData}; use anchor_spl::token::TokenAccount; use light_client::indexer::CompressedTokenAccount; +use light_compressed_token_types::{TokenAccountMeta, SPL_TOKEN_PROGRAM_ID}; use light_ctoken_sdk::{ compressed_token::{ batch_compress::{ @@ -13,7 +14,6 @@ use light_ctoken_sdk::{ }, }, 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}; use light_sdk::instruction::PackedAccounts; 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 abc399b4d1..ee3616a02b 100644 --- a/sdk-tests/sdk-token-test/tests/test_4_invocations.rs +++ b/sdk-tests/sdk-token-test/tests/test_4_invocations.rs @@ -1,11 +1,14 @@ use anchor_lang::{prelude::AccountMeta, AccountDeserialize, InstructionData}; +use light_compressed_token_types::SPL_TOKEN_PROGRAM_ID; use light_ctoken_sdk::{ - compressed_token::transfer::account_metas::{ - get_transfer_instruction_account_metas, TokenAccountsMetaConfig, + compressed_token::{ + transfer::account_metas::{ + get_transfer_instruction_account_metas, TokenAccountsMetaConfig, + }, + TokenAccountMeta, }, spl_interface::get_spl_interface_pda, utils::CTokenDefaultAccounts, - SPL_TOKEN_PROGRAM_ID, }; use light_program_test::{AddressWithTree, Indexer, LightProgramTest, ProgramTestConfig, Rpc}; use light_sdk::{ @@ -531,7 +534,7 @@ async fn test_four_invokes_instruction( transfer_2: sdk_token_test::TransferParams { mint: mint2, transfer_amount: 300, - token_metas: vec![light_ctoken_sdk::TokenAccountMeta { + token_metas: vec![TokenAccountMeta { amount: mint2_token_account.token.amount, delegate_index: None, packed_tree_info: mint2_tree_info, @@ -544,7 +547,7 @@ async fn test_four_invokes_instruction( transfer_3: sdk_token_test::TransferParams { mint: mint3, transfer_amount: 200, - token_metas: vec![light_ctoken_sdk::TokenAccountMeta { + token_metas: vec![TokenAccountMeta { amount: mint3_token_account.token.amount, delegate_index: None, packed_tree_info: mint3_tree_info, 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 94ba96ef77..655469aff1 100644 --- a/sdk-tests/sdk-token-test/tests/test_4_transfer2.rs +++ b/sdk-tests/sdk-token-test/tests/test_4_transfer2.rs @@ -155,7 +155,7 @@ async fn create_compressed_mint_helper( // Find mint PDA let compressed_token_program_id = - Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let (mint_pda, _) = Pubkey::find_program_address( &[COMPRESSED_MINT_SEED, mint_signer.pubkey().as_ref()], &compressed_token_program_id, 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 e17277ad57..9bfab0dc21 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 @@ -5,7 +5,7 @@ use anchor_lang::{ use light_ctoken_interface::{ instructions::mint_action::{CompressedMintWithContext, Recipient}, state::{BaseMint, CompressedMint, CompressedMintMetadata}, - COMPRESSED_MINT_SEED, COMPRESSED_TOKEN_PROGRAM_ID, + COMPRESSED_MINT_SEED, CTOKEN_PROGRAM_ID, }; use light_ctoken_sdk::{ compressed_token::{ @@ -47,7 +47,7 @@ async fn test_compress_full_and_close() { let output_queue = rpc.get_random_state_tree_info().unwrap().queue; let compressed_token_program_id = - Pubkey::new_from_array(light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID); + Pubkey::new_from_array(light_ctoken_interface::CTOKEN_PROGRAM_ID); let (mint_pda, _) = Pubkey::find_program_address( &[COMPRESSED_MINT_SEED, mint_signer.pubkey().as_ref()], &compressed_token_program_id, @@ -258,12 +258,12 @@ async fn test_compress_full_and_close() { // Create remaining accounts following four_multi_transfer pattern let mut remaining_accounts = PackedAccounts::default(); remaining_accounts.add_pre_accounts_meta(AccountMeta::new_readonly( - Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID), + Pubkey::new_from_array(CTOKEN_PROGRAM_ID), false, )); remaining_accounts .add_system_accounts_v2(SystemAccountMetaConfig::new(Pubkey::new_from_array( - COMPRESSED_TOKEN_PROGRAM_ID, + CTOKEN_PROGRAM_ID, ))) .unwrap(); diff --git a/sdk-tests/sdk-token-test/tests/test_compress_to_pubkey.rs b/sdk-tests/sdk-token-test/tests/test_compress_to_pubkey.rs index 9e0ca579d3..822d575878 100644 --- a/sdk-tests/sdk-token-test/tests/test_compress_to_pubkey.rs +++ b/sdk-tests/sdk-token-test/tests/test_compress_to_pubkey.rs @@ -1,5 +1,5 @@ use anchor_lang::InstructionData; -use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID; +use light_ctoken_interface::CTOKEN_PROGRAM_ID; use light_program_test::{ program_test::TestRpc, Indexer, LightProgramTest, ProgramTestConfig, Rpc, }; @@ -52,10 +52,8 @@ async fn test_compress_to_pubkey() { false, )); // System program remaining_accounts.add_pre_accounts_meta(AccountMeta::new(rent_sponsor, false)); // Rent recipient - remaining_accounts.add_pre_accounts_meta(AccountMeta::new_readonly( - COMPRESSED_TOKEN_PROGRAM_ID.into(), - false, - )); + remaining_accounts + .add_pre_accounts_meta(AccountMeta::new_readonly(CTOKEN_PROGRAM_ID.into(), false)); let (account_metas, _, _) = remaining_accounts.to_account_metas(); let instruction_data = sdk_token_test::instruction::CreateCtokenWithCompressToPubkey { diff --git a/sdk-tests/sdk-token-test/tests/test_deposit.rs b/sdk-tests/sdk-token-test/tests/test_deposit.rs index 7f0d2f945a..06dab630b2 100644 --- a/sdk-tests/sdk-token-test/tests/test_deposit.rs +++ b/sdk-tests/sdk-token-test/tests/test_deposit.rs @@ -1,12 +1,12 @@ use anchor_lang::InstructionData; use light_client::indexer::{CompressedAccount, CompressedTokenAccount, IndexerRpcConfig}; +use light_compressed_token_types::{TokenAccountMeta, SPL_TOKEN_PROGRAM_ID}; use light_ctoken_sdk::{ compressed_token::batch_compress::{ get_batch_compress_instruction_account_metas, BatchCompressMetaConfig, Recipient, }, spl_interface::find_spl_interface_pda_with_index, utils::CTokenDefaultAccounts, - TokenAccountMeta, SPL_TOKEN_PROGRAM_ID, }; use light_program_test::{AddressWithTree, Indexer, LightProgramTest, ProgramTestConfig, Rpc}; use light_sdk::{