diff --git a/Cargo.lock b/Cargo.lock index 7630bba204..a107e70b97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1389,6 +1389,7 @@ dependencies = [ "light-client", "light-compressed-account", "light-compressed-token", + "light-compressed-token-sdk", "light-compressible", "light-instruction-decoder", "light-program-test", @@ -1608,6 +1609,7 @@ dependencies = [ "light-anchor-spl", "light-client", "light-compressed-account", + "light-compressed-token-sdk", "light-compressible", "light-hasher", "light-heap", @@ -1647,6 +1649,7 @@ dependencies = [ "anchor-lang", "csdk-anchor-full-derived-test", "light-client", + "light-compressed-token-sdk", "light-sdk", "light-token", "solana-pubkey 2.4.0", @@ -2315,6 +2318,7 @@ dependencies = [ "light-client", "light-compressed-account", "light-compressed-token", + "light-compressed-token-sdk", "light-compressible", "light-hash-set", "light-hasher", @@ -3538,6 +3542,7 @@ dependencies = [ "futures", "lazy_static", "light-compressed-account", + "light-compressed-token-sdk", "light-compressible", "light-concurrent-merkle-tree", "light-event", @@ -3642,6 +3647,30 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "light-compressed-token-sdk" +version = "0.1.0" +dependencies = [ + "anchor-lang", + "arrayvec", + "borsh 0.10.4", + "light-account-checks", + "light-compressed-account", + "light-program-profiler", + "light-sdk", + "light-sdk-types", + "light-token-interface", + "light-token-types", + "light-zero-copy", + "solana-account-info", + "solana-cpi", + "solana-instruction", + "solana-msg 2.2.1", + "solana-program-error 2.2.2", + "solana-pubkey 2.4.0", + "thiserror 2.0.17", +] + [[package]] name = "light-compressible" version = "0.4.0" @@ -3900,6 +3929,7 @@ dependencies = [ "light-client", "light-compressed-account", "light-compressed-token", + "light-compressed-token-sdk", "light-compressible", "light-concurrent-merkle-tree", "light-event", @@ -4143,6 +4173,7 @@ dependencies = [ "light-client", "light-compressed-account", "light-compressed-token", + "light-compressed-token-sdk", "light-compressible", "light-concurrent-merkle-tree", "light-event", @@ -4186,6 +4217,7 @@ dependencies = [ "light-batched-merkle-tree", "light-compressed-account", "light-compressed-token", + "light-compressed-token-sdk", "light-compressible", "light-macros", "light-program-profiler", @@ -4213,6 +4245,7 @@ dependencies = [ "borsh 0.10.4", "light-client", "light-compressed-account", + "light-compressed-token-sdk", "light-compressible", "light-sdk", "light-token", @@ -5527,6 +5560,7 @@ dependencies = [ "light-batched-merkle-tree", "light-client", "light-compressed-account", + "light-compressed-token-sdk", "light-compressible", "light-hasher", "light-program-test", @@ -5958,7 +5992,6 @@ dependencies = [ "light-compressible", "light-program-test", "light-sdk", - "light-sdk-types", "light-test-utils", "light-token", "light-token-client", @@ -6033,6 +6066,7 @@ dependencies = [ "light-batched-merkle-tree", "light-client", "light-compressed-account", + "light-compressed-token-sdk", "light-compressible", "light-hasher", "light-instruction-decoder", diff --git a/Cargo.toml b/Cargo.toml index 544311c30a..dc679fc404 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ members = [ "anchor-programs/system", "sdk-libs/client", "sdk-libs/token-sdk", + "sdk-libs/compressed-token-sdk", "sdk-libs/event", "sdk-libs/token-client", "sdk-libs/macros", @@ -216,6 +217,7 @@ light-compressed-token = { path = "programs/compressed-token/program", version = ] } light-token-types = { path = "sdk-libs/token-types", version = "0.4.0" } light-token = { path = "sdk-libs/token-sdk", version = "0.4.0" } +light-compressed-token-sdk = { path = "sdk-libs/compressed-token-sdk", version = "0.1.0" } light-token-client = { path = "sdk-libs/token-client", version = "0.1.0" } light-system-program-anchor = { path = "anchor-programs/system", version = "2.0.0", features = [ "cpi", diff --git a/forester/Cargo.toml b/forester/Cargo.toml index 2a1b177307..5b23dc2855 100644 --- a/forester/Cargo.toml +++ b/forester/Cargo.toml @@ -31,6 +31,7 @@ light-compressible = { workspace = true, default-features = false, features = [" light-token-interface = { workspace = true } light-token-client = { workspace = true } light-token = { workspace = true } +light-compressed-token-sdk = { workspace = true } solana-rpc-client-api = { workspace = true } solana-transaction-status = { workspace = true } bb8 = { workspace = true } diff --git a/forester/src/compressible/ctoken/compressor.rs b/forester/src/compressible/ctoken/compressor.rs index 450d3c9484..00ee28b579 100644 --- a/forester/src/compressible/ctoken/compressor.rs +++ b/forester/src/compressible/ctoken/compressor.rs @@ -3,13 +3,13 @@ use std::{str::FromStr, sync::Arc}; use anchor_lang::{InstructionData, ToAccountMetas}; use forester_utils::rpc_pool::SolanaRpcPool; use light_client::{indexer::Indexer, rpc::Rpc}; +use light_compressed_token_sdk::compressed_token::compress_and_close::CompressAndCloseAccounts as CTokenAccounts; use light_compressible::config::CompressibleConfig; use light_registry::{ accounts::CompressAndCloseContext, compressible::compressed_token::CompressAndCloseIndices, instruction::CompressAndClose, }; use light_sdk::instruction::PackedAccounts; -use light_token::compressed_token::CompressAndCloseAccounts as CTokenAccounts; use light_token_interface::LIGHT_TOKEN_PROGRAM_ID; use solana_sdk::{ instruction::Instruction, diff --git a/forester/tests/test_compressible_ctoken.rs b/forester/tests/test_compressible_ctoken.rs index f818960ae0..c4ba53697e 100644 --- a/forester/tests/test_compressible_ctoken.rs +++ b/forester/tests/test_compressible_ctoken.rs @@ -11,6 +11,7 @@ use light_client::{ local_test_validator::{spawn_validator, LightValidatorConfig}, rpc::{LightClient, LightClientConfig, Rpc}, }; +use light_compressed_token_sdk::compressed_token::create_compressed_mint; use light_registry::{ protocol_config::state::ProtocolConfigPda, sdk::{ @@ -20,7 +21,6 @@ use light_registry::{ utils::{get_forester_pda, get_protocol_config_pda_address}, ForesterConfig, }; -use light_token::compressed_token::create_compressed_mint; use light_token_client::actions::{ create_compressible_token_account, CreateCompressibleTokenAccountInputs, }; diff --git a/program-tests/compressed-token-test/Cargo.toml b/program-tests/compressed-token-test/Cargo.toml index 8257a8c725..0e52ffdaaa 100644 --- a/program-tests/compressed-token-test/Cargo.toml +++ b/program-tests/compressed-token-test/Cargo.toml @@ -48,6 +48,7 @@ light-token-interface = { workspace = true } light-token-client = { workspace = true } light-compressible = { workspace = true } light-token = { workspace = true } +light-compressed-token-sdk = { workspace = true } spl-token-2022 = { workspace = true } spl-pod = { workspace = true } light-zero-copy = { workspace = true , features = ["std", "derive", "mut"]} diff --git a/program-tests/compressed-token-test/tests/compress_only/all.rs b/program-tests/compressed-token-test/tests/compress_only/all.rs index f5b327852f..89be839c88 100644 --- a/program-tests/compressed-token-test/tests/compress_only/all.rs +++ b/program-tests/compressed-token-test/tests/compress_only/all.rs @@ -20,11 +20,9 @@ async fn test_compress_and_close_ctoken_with_extensions() { #[allow(unused_imports)] use light_client::indexer::CompressedTokenAccount; use light_client::indexer::Indexer; + use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; use light_test_utils::mint_2022::{create_token_22_account, mint_spl_tokens_22}; - use light_token::{ - instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}, - spl_interface::find_spl_interface_pda_with_index, - }; + use light_token::instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}; use light_token_client::instructions::transfer2::{ create_generic_transfer2_instruction, DecompressInput, Transfer2InstructionType, }; diff --git a/program-tests/compressed-token-test/tests/compress_only/ata_decompress.rs b/program-tests/compressed-token-test/tests/compress_only/ata_decompress.rs index 002ccc9c52..3fff58d3ac 100644 --- a/program-tests/compressed-token-test/tests/compress_only/ata_decompress.rs +++ b/program-tests/compressed-token-test/tests/compress_only/ata_decompress.rs @@ -4,6 +4,7 @@ //! decompressed to the exact same ATA pubkey that was originally compressed. use light_client::indexer::Indexer; +use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; use light_program_test::{ program_test::TestRpc, utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig, }; @@ -14,12 +15,9 @@ use light_test_utils::{ }, Rpc, RpcError, }; -use light_token::{ - instruction::{ - derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount, CreateTokenAccount, - TransferFromSpl, - }, - spl_interface::find_spl_interface_pda_with_index, +use light_token::instruction::{ + derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount, CreateTokenAccount, + TransferFromSpl, }; use light_token_client::instructions::transfer2::{ create_generic_transfer2_instruction, DecompressInput, Transfer2InstructionType, @@ -790,10 +788,10 @@ async fn test_decompress_skips_delegate_if_destination_has_delegate() { async fn test_ata_decompress_with_mismatched_amount_fails() { use borsh::BorshSerialize; use light_compressed_account::compressed_account::PackedMerkleContext; - use light_sdk::instruction::PackedAccounts; - use light_token::compressed_token::transfer2::account_metas::{ + use light_compressed_token_sdk::compressed_token::transfer2::account_metas::{ get_transfer2_instruction_account_metas, Transfer2AccountsMetaConfig, }; + use light_sdk::instruction::PackedAccounts; use light_token_interface::{ instructions::transfer2::{ CompressedTokenInstructionDataTransfer2, Compression, CompressionMode, diff --git a/program-tests/compressed-token-test/tests/compress_only/decompress_restrictions.rs b/program-tests/compressed-token-test/tests/compress_only/decompress_restrictions.rs index d679b5a80a..430b3ed59a 100644 --- a/program-tests/compressed-token-test/tests/compress_only/decompress_restrictions.rs +++ b/program-tests/compressed-token-test/tests/compress_only/decompress_restrictions.rs @@ -5,6 +5,7 @@ //! - Spec #14: CompressedOnly inputs must decompress complete account (no change output) use light_client::indexer::Indexer; +use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; use light_program_test::{ program_test::{LightProgramTest, TestRpc}, utils::assert::assert_rpc_error, @@ -14,10 +15,7 @@ use light_test_utils::mint_2022::{ create_mint_22_with_extension_types, create_token_22_account, mint_spl_tokens_22, RESTRICTED_EXTENSIONS, }; -use light_token::{ - instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}, - spl_interface::find_spl_interface_pda_with_index, -}; +use light_token::instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}; use light_token_client::instructions::transfer2::{ create_generic_transfer2_instruction, DecompressInput, Transfer2InstructionType, }; diff --git a/program-tests/compressed-token-test/tests/compress_only/invalid_destination.rs b/program-tests/compressed-token-test/tests/compress_only/invalid_destination.rs index c93b1795f8..b9c35082eb 100644 --- a/program-tests/compressed-token-test/tests/compress_only/invalid_destination.rs +++ b/program-tests/compressed-token-test/tests/compress_only/invalid_destination.rs @@ -8,6 +8,7 @@ use anchor_spl::token_2022::spl_token_2022; use light_client::indexer::Indexer; +use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; use light_program_test::{ program_test::{LightProgramTest, TestRpc}, utils::assert::assert_rpc_error, @@ -17,10 +18,7 @@ use light_test_utils::mint_2022::{ create_mint_22_with_extension_types, create_token_22_account, mint_spl_tokens_22, RESTRICTED_EXTENSIONS, }; -use light_token::{ - instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}, - spl_interface::find_spl_interface_pda_with_index, -}; +use light_token::instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}; use light_token_client::instructions::transfer2::{ create_generic_transfer2_instruction, DecompressInput, Transfer2InstructionType, }; diff --git a/program-tests/compressed-token-test/tests/compress_only/invalid_extension_state.rs b/program-tests/compressed-token-test/tests/compress_only/invalid_extension_state.rs index eb391b9c08..e54222acde 100644 --- a/program-tests/compressed-token-test/tests/compress_only/invalid_extension_state.rs +++ b/program-tests/compressed-token-test/tests/compress_only/invalid_extension_state.rs @@ -9,6 +9,10 @@ use anchor_lang::{system_program, InstructionData, ToAccountMetas}; use light_client::indexer::Indexer; +use light_compressed_token_sdk::{ + constants::CPI_AUTHORITY_PDA, + spl_interface::find_spl_interface_pda_with_index as sdk_find_spl_interface_pda, +}; use light_program_test::{ program_test::{LightProgramTest, TestRpc}, utils::assert::assert_rpc_error, @@ -17,10 +21,8 @@ use light_program_test::{ use light_test_utils::mint_2022::{ create_token_22_account, mint_spl_tokens_22, set_mint_transfer_fee, set_mint_transfer_hook, }; -use light_token::{ - constants::CPI_AUTHORITY_PDA, - instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl, TransferToSpl}, - spl_interface::find_spl_interface_pda_with_index as sdk_find_spl_interface_pda, +use light_token::instruction::{ + CompressibleParams, CreateTokenAccount, TransferFromSpl, TransferToSpl, }; use light_token_client::instructions::transfer2::{ create_generic_transfer2_instruction, DecompressInput, Transfer2InstructionType, diff --git a/program-tests/compressed-token-test/tests/compress_only/mod.rs b/program-tests/compressed-token-test/tests/compress_only/mod.rs index 82be04d1eb..f0aeff10c7 100644 --- a/program-tests/compressed-token-test/tests/compress_only/mod.rs +++ b/program-tests/compressed-token-test/tests/compress_only/mod.rs @@ -154,10 +154,8 @@ pub async fn run_compress_and_close_extension_test( config: CompressAndCloseTestConfig, ) -> Result<(), RpcError> { use light_client::indexer::Indexer; - use light_token::{ - instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}, - spl_interface::find_spl_interface_pda_with_index, - }; + use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; + use light_token::instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}; use light_token_client::instructions::transfer2::{ create_generic_transfer2_instruction, DecompressInput, Transfer2InstructionType, }; diff --git a/program-tests/compressed-token-test/tests/compress_only/withheld_fee.rs b/program-tests/compressed-token-test/tests/compress_only/withheld_fee.rs index ef82b12c7d..0caa35e5ca 100644 --- a/program-tests/compressed-token-test/tests/compress_only/withheld_fee.rs +++ b/program-tests/compressed-token-test/tests/compress_only/withheld_fee.rs @@ -5,15 +5,13 @@ use borsh::BorshDeserialize; use light_client::indexer::Indexer; +use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; use light_program_test::{program_test::TestRpc, LightProgramTest, ProgramTestConfig}; use light_test_utils::{ mint_2022::{create_mint_22_with_extension_types, create_token_22_account, mint_spl_tokens_22}, Rpc, RpcError, }; -use light_token::{ - instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}, - spl_interface::find_spl_interface_pda_with_index, -}; +use light_token::instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}; use light_token_client::instructions::transfer2::{ create_generic_transfer2_instruction, DecompressInput, Transfer2InstructionType, }; diff --git a/program-tests/compressed-token-test/tests/freeze/compress_only.rs b/program-tests/compressed-token-test/tests/freeze/compress_only.rs index 46c5ebed7e..f54429f5de 100644 --- a/program-tests/compressed-token-test/tests/freeze/compress_only.rs +++ b/program-tests/compressed-token-test/tests/freeze/compress_only.rs @@ -7,6 +7,7 @@ use light_client::indexer::{CompressedTokenAccount, Indexer}; use light_compressed_token::freeze::sdk::{ create_instruction, CreateInstructionInputs as FreezeInputs, }; +use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; use light_program_test::{program_test::TestRpc, LightProgramTest, ProgramTestConfig}; use light_test_utils::{ conversions::sdk_to_program_token_data, @@ -19,7 +20,6 @@ use light_test_utils::{ use light_token::{ compat::{AccountState, TokenDataWithMerkleContext}, instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}, - spl_interface::find_spl_interface_pda_with_index, }; use light_token_client::instructions::transfer2::{ create_generic_transfer2_instruction, DecompressInput, Transfer2InstructionType, diff --git a/program-tests/compressed-token-test/tests/light_token/burn.rs b/program-tests/compressed-token-test/tests/light_token/burn.rs index e0bf011c6b..8490655227 100644 --- a/program-tests/compressed-token-test/tests/light_token/burn.rs +++ b/program-tests/compressed-token-test/tests/light_token/burn.rs @@ -17,14 +17,12 @@ //! //! **Note**: Max top-up exceeded test requires compressible accounts with time warp. //! For comprehensive max_top_up testing, see sdk-tests/sdk-light-token-test/tests/test_burn.rs +use light_compressed_token_sdk::compressed_token::create_compressed_mint::find_mint_address; use light_program_test::{ program_test::TestRpc, utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig, }; use light_test_utils::assert_ctoken_burn::assert_ctoken_burn; -use light_token::{ - compressed_token::create_compressed_mint::find_mint_address, - instruction::{derive_token_ata, Burn, CreateAssociatedTokenAccount, MintTo}, -}; +use light_token::instruction::{derive_token_ata, Burn, CreateAssociatedTokenAccount, MintTo}; use light_token_client::instructions::mint_action::DecompressMintParams; use super::shared::*; diff --git a/program-tests/compressed-token-test/tests/light_token/extensions.rs b/program-tests/compressed-token-test/tests/light_token/extensions.rs index 942d7e85ba..5b1c737e87 100644 --- a/program-tests/compressed-token-test/tests/light_token/extensions.rs +++ b/program-tests/compressed-token-test/tests/light_token/extensions.rs @@ -79,10 +79,8 @@ async fn test_setup_mint_22_with_all_extensions() { #[tokio::test] #[serial] async fn test_mint_and_compress_with_extensions() { - use light_token::{ - instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}, - spl_interface::find_spl_interface_pda_with_index, - }; + use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; + use light_token::instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}; use light_token_interface::state::TokenDataVersion; let mut context = setup_extensions_test().await.unwrap(); @@ -284,10 +282,8 @@ async fn test_create_ctoken_with_extensions() { async fn test_transfer_with_permanent_delegate() { use anchor_lang::prelude::AccountMeta; use anchor_spl::token_2022::spl_token_2022; - use light_token::{ - instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}, - spl_interface::find_spl_interface_pda_with_index, - }; + use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; + use light_token::instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}; use light_token_interface::state::TokenDataVersion; use solana_sdk::{instruction::Instruction, program_pack::Pack}; @@ -485,10 +481,8 @@ async fn test_transfer_with_owner_authority() { use anchor_lang::prelude::AccountMeta; use anchor_spl::token_2022::spl_token_2022; use borsh::BorshDeserialize; - use light_token::{ - instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}, - spl_interface::find_spl_interface_pda_with_index, - }; + use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; + use light_token::instruction::{CompressibleParams, CreateTokenAccount, TransferFromSpl}; use light_token_interface::state::{AccountState, Token, TokenDataVersion}; use solana_sdk::{instruction::Instruction, program_pack::Pack}; diff --git a/program-tests/compressed-token-test/tests/light_token/extensions_failing.rs b/program-tests/compressed-token-test/tests/light_token/extensions_failing.rs index bb3be01280..1ea5fe69b8 100644 --- a/program-tests/compressed-token-test/tests/light_token/extensions_failing.rs +++ b/program-tests/compressed-token-test/tests/light_token/extensions_failing.rs @@ -8,6 +8,7 @@ //! in compress_only/invalid_extension_state.rs. It succeeds with invalid extension //! state because it exits compressed state without creating new compressed accounts. +use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; use light_program_test::utils::assert::assert_rpc_error; use light_test_utils::{ mint_2022::{ @@ -16,9 +17,8 @@ use light_test_utils::{ }, Rpc, }; -use light_token::{ - instruction::{CompressibleParams, CreateTokenAccount, TransferChecked, TransferFromSpl}, - spl_interface::find_spl_interface_pda_with_index, +use light_token::instruction::{ + CompressibleParams, CreateTokenAccount, TransferChecked, TransferFromSpl, }; use light_token_interface::state::TokenDataVersion; use serial_test::serial; diff --git a/program-tests/compressed-token-test/tests/light_token/shared.rs b/program-tests/compressed-token-test/tests/light_token/shared.rs index 7b52bc1d98..d177bf1665 100644 --- a/program-tests/compressed-token-test/tests/light_token/shared.rs +++ b/program-tests/compressed-token-test/tests/light_token/shared.rs @@ -739,7 +739,7 @@ pub async fn compress_and_close_forester_with_invalid_output( }; // Add system accounts - use light_token::compressed_token::compress_and_close::CompressAndCloseAccounts as CTokenCompressAndCloseAccounts; + use light_compressed_token_sdk::compressed_token::compress_and_close::CompressAndCloseAccounts as CTokenCompressAndCloseAccounts; let config = CTokenCompressAndCloseAccounts { compressed_token_program: compressed_token_program_id, cpi_authority_pda: Pubkey::find_program_address( diff --git a/program-tests/compressed-token-test/tests/light_token/spl_instruction_compat.rs b/program-tests/compressed-token-test/tests/light_token/spl_instruction_compat.rs index 810506fcc4..71ec389827 100644 --- a/program-tests/compressed-token-test/tests/light_token/spl_instruction_compat.rs +++ b/program-tests/compressed-token-test/tests/light_token/spl_instruction_compat.rs @@ -424,8 +424,8 @@ async fn test_spl_instruction_compatibility() { #[serial] #[allow(deprecated)] async fn test_spl_instruction_compatibility_with_mint() { + use light_compressed_token_sdk::compressed_token::create_compressed_mint::find_mint_address; use light_program_test::ProgramTestConfig; - use light_token::compressed_token::create_compressed_mint::find_mint_address; use light_token_client::instructions::mint_action::DecompressMintParams; // Set up test environment diff --git a/program-tests/compressed-token-test/tests/light_token/transfer_checked.rs b/program-tests/compressed-token-test/tests/light_token/transfer_checked.rs index 99d4386024..a9c1559f57 100644 --- a/program-tests/compressed-token-test/tests/light_token/transfer_checked.rs +++ b/program-tests/compressed-token-test/tests/light_token/transfer_checked.rs @@ -4,17 +4,15 @@ //! TransferFee, TransferHook) cannot use CTokenTransfer and must use CTokenTransferChecked. use anchor_spl::token_2022::spl_token_2022; +use light_compressed_token_sdk::spl_interface::find_spl_interface_pda_with_index; use light_program_test::utils::assert::assert_rpc_error; use light_test_utils::{ assert_ctoken_transfer::assert_ctoken_transfer, mint_2022::{create_token_22_account, mint_spl_tokens_22}, Rpc, }; -use light_token::{ - instruction::{ - CompressibleParams, CreateTokenAccount, Transfer, TransferChecked, TransferFromSpl, - }, - spl_interface::find_spl_interface_pda_with_index, +use light_token::instruction::{ + CompressibleParams, CreateTokenAccount, Transfer, TransferChecked, TransferFromSpl, }; use light_token_interface::state::TokenDataVersion; use serial_test::serial; diff --git a/program-tests/compressed-token-test/tests/mint/burn.rs b/program-tests/compressed-token-test/tests/mint/burn.rs index f4d7525150..a17d1a45ef 100644 --- a/program-tests/compressed-token-test/tests/mint/burn.rs +++ b/program-tests/compressed-token-test/tests/mint/burn.rs @@ -1,9 +1,7 @@ +use light_compressed_token_sdk::compressed_token::create_compressed_mint::find_mint_address; use light_program_test::{LightProgramTest, ProgramTestConfig}; use light_test_utils::{assert_ctoken_burn::assert_ctoken_burn, Rpc}; -use light_token::{ - compressed_token::create_compressed_mint::find_mint_address, - instruction::{derive_token_ata, Burn, CreateAssociatedTokenAccount}, -}; +use light_token::instruction::{derive_token_ata, Burn, CreateAssociatedTokenAccount}; use light_token_client::instructions::mint_action::DecompressMintParams; use light_token_interface::instructions::mint_action::Recipient; use serial_test::serial; diff --git a/program-tests/compressed-token-test/tests/mint/cmint_resize.rs b/program-tests/compressed-token-test/tests/mint/cmint_resize.rs index 3bd794ea0d..1e654664c7 100644 --- a/program-tests/compressed-token-test/tests/mint/cmint_resize.rs +++ b/program-tests/compressed-token-test/tests/mint/cmint_resize.rs @@ -11,11 +11,13 @@ use anchor_lang::prelude::borsh::BorshDeserialize; use light_client::indexer::Indexer; +use light_compressed_token_sdk::compressed_token::create_compressed_mint::{ + derive_mint_compressed_address, find_mint_address, +}; use light_program_test::{LightProgramTest, ProgramTestConfig}; use light_test_utils::{assert_mint_action::assert_mint_action, Rpc}; -use light_token::{ - compressed_token::create_compressed_mint::{derive_mint_compressed_address, find_mint_address}, - instruction::{derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount}, +use light_token::instruction::{ + derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount, }; use light_token_client::{ actions::create_mint, 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 58b20f7c3f..c22c2f4ad8 100644 --- a/program-tests/compressed-token-test/tests/mint/cpi_context.rs +++ b/program-tests/compressed-token-test/tests/mint/cpi_context.rs @@ -2,15 +2,15 @@ use anchor_lang::InstructionData; use compressed_token_test::ID as WRAPPER_PROGRAM_ID; use light_client::indexer::Indexer; use light_compressed_account::instruction_data::traits::LightInstructionData; -use light_program_test::{utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig}; -use light_test_utils::Rpc; -use light_token::compressed_token::{ +use light_compressed_token_sdk::compressed_token::{ create_compressed_mint::{derive_mint_compressed_address, find_mint_address}, mint_action::{ get_mint_action_instruction_account_metas_cpi_write, MintActionMetaConfig, MintActionMetaConfigCpiWrite, }, }; +use light_program_test::{utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig}; +use light_test_utils::Rpc; use light_token_interface::{ instructions::mint_action::{ CpiContext, DecompressMintAction, MintActionCompressedInstructionData, MintInstructionData, 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 eceff31dd6..2196795fc9 100644 --- a/program-tests/compressed-token-test/tests/mint/edge_cases.rs +++ b/program-tests/compressed-token-test/tests/mint/edge_cases.rs @@ -1,13 +1,13 @@ use anchor_lang::prelude::borsh::BorshDeserialize; use light_client::indexer::Indexer; +use light_compressed_token_sdk::compressed_token::create_compressed_mint::{ + derive_mint_compressed_address, find_mint_address, +}; use light_program_test::{LightProgramTest, ProgramTestConfig}; use light_test_utils::{ assert_mint_action::assert_mint_action, mint_assert::assert_compressed_mint_account, Rpc, }; -use light_token::{ - compressed_token::create_compressed_mint::{derive_mint_compressed_address, find_mint_address}, - instruction::{CompressibleParams, CreateAssociatedTokenAccount}, -}; +use light_token::instruction::{CompressibleParams, CreateAssociatedTokenAccount}; use light_token_client::{ actions::create_mint, instructions::mint_action::{MintActionType, MintToRecipient}, diff --git a/program-tests/compressed-token-test/tests/mint/failing.rs b/program-tests/compressed-token-test/tests/mint/failing.rs index 0036125642..721053e462 100644 --- a/program-tests/compressed-token-test/tests/mint/failing.rs +++ b/program-tests/compressed-token-test/tests/mint/failing.rs @@ -2,14 +2,14 @@ use anchor_lang::prelude::borsh::BorshDeserialize; use light_client::indexer::Indexer; +use light_compressed_token_sdk::compressed_token::create_compressed_mint::{ + derive_mint_compressed_address, find_mint_address, +}; use light_program_test::{utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig}; use light_test_utils::{ assert_mint_action::assert_mint_action, mint_assert::assert_compressed_mint_account, Rpc, }; -use light_token::{ - compressed_token::create_compressed_mint::{derive_mint_compressed_address, find_mint_address}, - instruction::{CompressibleParams, CreateAssociatedTokenAccount}, -}; +use light_token::instruction::{CompressibleParams, CreateAssociatedTokenAccount}; use light_token_client::{ actions::create_mint, instructions::mint_action::{MintActionType, MintToRecipient}, @@ -811,7 +811,7 @@ async fn functional_and_failing_tests() { #[serial] async fn test_mint_to_ctoken_max_top_up_exceeded() { use light_compressed_account::instruction_data::traits::LightInstructionData; - use light_token::compressed_token::{ + use light_compressed_token_sdk::compressed_token::{ create_compressed_mint::derive_mint_compressed_address, mint_action::MintActionMetaConfig, }; use light_token_interface::{ @@ -1023,9 +1023,9 @@ async fn test_create_mint_non_signer_mint_signer() { #[tokio::test] #[serial] async fn test_compress_and_close_mint_must_be_only_action() { + use light_compressed_token_sdk::compressed_token::create_compressed_mint::derive_mint_compressed_address; use light_compressible::rent::SLOTS_PER_EPOCH; use light_program_test::program_test::TestRpc; - use light_token::compressed_token::create_compressed_mint::derive_mint_compressed_address; use light_token_client::instructions::mint_action::DecompressMintParams; let mut rpc = LightProgramTest::new(ProgramTestConfig::new_v2(false, None)) diff --git a/program-tests/compressed-token-test/tests/mint/functional.rs b/program-tests/compressed-token-test/tests/mint/functional.rs index 86e9b961c5..36a15e9c6c 100644 --- a/program-tests/compressed-token-test/tests/mint/functional.rs +++ b/program-tests/compressed-token-test/tests/mint/functional.rs @@ -1,5 +1,8 @@ use anchor_lang::{prelude::borsh::BorshDeserialize, solana_program::program_pack::Pack}; use light_client::indexer::Indexer; +use light_compressed_token_sdk::compressed_token::create_compressed_mint::{ + derive_mint_compressed_address, find_mint_address, +}; use light_compressible::{compression_info::CompressionInfo, rent::SLOTS_PER_EPOCH}; use light_program_test::{program_test::TestRpc, LightProgramTest, ProgramTestConfig}; use light_test_utils::{ @@ -13,9 +16,8 @@ use light_test_utils::{ mint_assert::assert_compressed_mint_account, Rpc, }; -use light_token::{ - compressed_token::create_compressed_mint::{derive_mint_compressed_address, find_mint_address}, - instruction::{derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount}, +use light_token::instruction::{ + derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount, }; use light_token_client::{ actions::{create_mint, mint_to_compressed, transfer, transfer2}, diff --git a/program-tests/compressed-token-test/tests/mint/mint_to.rs b/program-tests/compressed-token-test/tests/mint/mint_to.rs index c4f90404bc..cbf6561574 100644 --- a/program-tests/compressed-token-test/tests/mint/mint_to.rs +++ b/program-tests/compressed-token-test/tests/mint/mint_to.rs @@ -1,9 +1,7 @@ +use light_compressed_token_sdk::compressed_token::create_compressed_mint::find_mint_address; use light_program_test::{LightProgramTest, ProgramTestConfig}; use light_test_utils::{assert_ctoken_mint_to::assert_ctoken_mint_to, Rpc}; -use light_token::{ - compressed_token::create_compressed_mint::find_mint_address, - instruction::{derive_token_ata, CreateAssociatedTokenAccount, MintTo}, -}; +use light_token::instruction::{derive_token_ata, CreateAssociatedTokenAccount, MintTo}; use light_token_client::instructions::mint_action::DecompressMintParams; use serial_test::serial; use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer}; diff --git a/program-tests/compressed-token-test/tests/mint/random.rs b/program-tests/compressed-token-test/tests/mint/random.rs index 688cfbc0de..081c607d0f 100644 --- a/program-tests/compressed-token-test/tests/mint/random.rs +++ b/program-tests/compressed-token-test/tests/mint/random.rs @@ -1,14 +1,14 @@ use anchor_lang::prelude::borsh::BorshDeserialize; use light_batched_merkle_tree::initialize_state_tree::InitStateTreeAccountsInstructionData; use light_client::indexer::Indexer; +use light_compressed_token_sdk::compressed_token::create_compressed_mint::{ + derive_mint_compressed_address, find_mint_address, +}; use light_program_test::{LightProgramTest, ProgramTestConfig}; use light_test_utils::{ assert_mint_action::assert_mint_action, mint_assert::assert_compressed_mint_account, Rpc, }; -use light_token::{ - compressed_token::create_compressed_mint::{derive_mint_compressed_address, find_mint_address}, - instruction::CreateAssociatedTokenAccount, -}; +use light_token::instruction::CreateAssociatedTokenAccount; use light_token_client::{ actions::create_mint, instructions::mint_action::{MintActionType, MintToRecipient}, diff --git a/program-tests/compressed-token-test/tests/token_pool.rs b/program-tests/compressed-token-test/tests/token_pool.rs index 7b03ad3559..46ab70219b 100644 --- a/program-tests/compressed-token-test/tests/token_pool.rs +++ b/program-tests/compressed-token-test/tests/token_pool.rs @@ -11,12 +11,12 @@ use light_compressed_token::{ mint_sdk::create_create_token_pool_instruction, process_transfer::get_cpi_authority_pda, spl_compression::check_spl_token_pool_derivation_with_index, ErrorCode, }; +use light_compressed_token_sdk::spl_interface::CreateSplInterfacePda; use light_program_test::{utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig}; use light_test_utils::{ spl::{create_additional_token_pools, create_mint_22_helper, create_mint_helper}, Rpc, RpcError, }; -use light_token::spl_interface::CreateSplInterfacePda; use light_token_interface::{ find_spl_interface_pda, find_spl_interface_pda_with_index, has_restricted_extensions, }; 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 ff6b519dff..9e2d63fef5 100644 --- a/program-tests/compressed-token-test/tests/transfer2/compress_failing.rs +++ b/program-tests/compressed-token-test/tests/transfer2/compress_failing.rs @@ -35,20 +35,20 @@ // 1. create and mint to one ctoken compressed account // +use light_compressed_token_sdk::compressed_token::{ + create_compressed_mint::find_mint_address, + transfer2::{ + account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, Transfer2Config, + Transfer2Inputs, + }, + CTokenAccount2, +}; use light_program_test::{ utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig, Rpc, }; use light_sdk::instruction::PackedAccounts; use light_test_utils::RpcError; use light_token::{ - compressed_token::{ - create_compressed_mint::find_mint_address, - transfer2::{ - account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, - Transfer2Config, Transfer2Inputs, - }, - CTokenAccount2, - }, instruction::{derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount}, ValidityProof, }; diff --git a/program-tests/compressed-token-test/tests/transfer2/compress_spl_failing.rs b/program-tests/compressed-token-test/tests/transfer2/compress_spl_failing.rs index f75d7d2242..7779289659 100644 --- a/program-tests/compressed-token-test/tests/transfer2/compress_spl_failing.rs +++ b/program-tests/compressed-token-test/tests/transfer2/compress_spl_failing.rs @@ -29,6 +29,16 @@ // 5.3. recipient out of bounds use anchor_spl::token_2022::spl_token_2022; +use light_compressed_token_sdk::{ + compressed_token::{ + transfer2::{ + account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, + Transfer2Config, Transfer2Inputs, + }, + CTokenAccount2, + }, + spl_interface::find_spl_interface_pda_with_index, +}; use light_program_test::{utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig}; use light_sdk::instruction::PackedAccounts; use light_test_utils::{ @@ -39,15 +49,7 @@ use light_test_utils::{ Rpc, RpcError, }; use light_token::{ - compressed_token::{ - transfer2::{ - account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, - Transfer2Config, Transfer2Inputs, - }, - CTokenAccount2, - }, instruction::{derive_token_ata, CreateAssociatedTokenAccount}, - spl_interface::find_spl_interface_pda_with_index, ValidityProof, }; use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer}; 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 7454f56117..d8d7ca4806 100644 --- a/program-tests/compressed-token-test/tests/transfer2/decompress_failing.rs +++ b/program-tests/compressed-token-test/tests/transfer2/decompress_failing.rs @@ -32,20 +32,20 @@ // use light_client::indexer::{CompressedTokenAccount, Indexer}; +use light_compressed_token_sdk::compressed_token::{ + create_compressed_mint::find_mint_address, + transfer2::{ + account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, Transfer2Config, + Transfer2Inputs, + }, + CTokenAccount2, +}; use light_program_test::{ utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig, Rpc, }; use light_sdk::instruction::PackedAccounts; use light_test_utils::RpcError; use light_token::{ - compressed_token::{ - create_compressed_mint::find_mint_address, - transfer2::{ - account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, - Transfer2Config, Transfer2Inputs, - }, - CTokenAccount2, - }, instruction::{derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount}, ValidityProof, }; 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 e831406748..2cd32161b9 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 @@ -43,13 +43,13 @@ // // ============================================================================ +use light_compressed_token_sdk::compressed_token::create_compressed_mint::find_mint_address; use light_program_test::{ utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig, Rpc, }; use light_sdk::instruction::PackedAccounts; use light_test_utils::{airdrop_lamports, RpcError}; use light_token::{ - compressed_token::create_compressed_mint::find_mint_address, instruction::{derive_token_ata, CreateAssociatedTokenAccount}, ValidityProof, }; diff --git a/program-tests/compressed-token-test/tests/transfer2/shared.rs b/program-tests/compressed-token-test/tests/transfer2/shared.rs index 9f9a121c07..ced4e55898 100644 --- a/program-tests/compressed-token-test/tests/transfer2/shared.rs +++ b/program-tests/compressed-token-test/tests/transfer2/shared.rs @@ -2,6 +2,9 @@ use std::collections::HashMap; use anchor_lang::AnchorDeserialize; use light_client::{indexer::Indexer, rpc::Rpc}; +use light_compressed_token_sdk::compressed_token::create_compressed_mint::{ + derive_mint_compressed_address, find_mint_address, +}; use light_program_test::{indexer::TestIndexerExtensions, LightProgramTest, ProgramTestConfig}; use light_test_utils::{ airdrop_lamports, @@ -11,10 +14,7 @@ use light_test_utils::{ CREATE_MINT_HELPER_DECIMALS, }, }; -use light_token::{ - compressed_token::create_compressed_mint::{derive_mint_compressed_address, find_mint_address}, - instruction::{CompressibleParams, CreateAssociatedTokenAccount}, -}; +use light_token::instruction::{CompressibleParams, CreateAssociatedTokenAccount}; use light_token_client::{ actions::{create_mint, mint_to_compressed}, instructions::{ diff --git a/program-tests/compressed-token-test/tests/transfer2/spl_ctoken.rs b/program-tests/compressed-token-test/tests/transfer2/spl_ctoken.rs index 6e835865d6..3cb1cf1e03 100644 --- a/program-tests/compressed-token-test/tests/transfer2/spl_ctoken.rs +++ b/program-tests/compressed-token-test/tests/transfer2/spl_ctoken.rs @@ -1,6 +1,16 @@ use anchor_lang::prelude::{AccountMeta, ProgramError}; // Re-export all necessary imports for test modules pub use anchor_spl::token_2022::spl_token_2022; +use light_compressed_token_sdk::{ + compressed_token::{ + transfer2::{ + create_transfer2_instruction, Transfer2AccountsMetaConfig, Transfer2Config, + Transfer2Inputs, + }, + CTokenAccount2, + }, + spl_interface::find_spl_interface_pda_with_index, +}; use light_program_test::utils::assert::assert_rpc_error; pub use light_program_test::{LightProgramTest, ProgramTestConfig}; pub use light_test_utils::{ @@ -13,17 +23,7 @@ pub use light_test_utils::{ pub use light_token::instruction::{ derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount, }; -use light_token::{ - compressed_token::{ - transfer2::{ - create_transfer2_instruction, Transfer2AccountsMetaConfig, Transfer2Config, - Transfer2Inputs, - }, - CTokenAccount2, - }, - spl_interface::find_spl_interface_pda_with_index, - ValidityProof, -}; +use light_token::ValidityProof; pub use light_token_client::actions::transfer2::{self}; use light_token_interface::instructions::transfer2::{Compression, MultiTokenTransferOutputData}; use solana_sdk::pubkey::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 d060166b7f..7abbd48302 100644 --- a/program-tests/compressed-token-test/tests/transfer2/transfer_failing.rs +++ b/program-tests/compressed-token-test/tests/transfer2/transfer_failing.rs @@ -5,21 +5,19 @@ // ============================================================================ use light_client::indexer::{CompressedTokenAccount, Indexer}; +use light_compressed_token_sdk::compressed_token::{ + transfer2::{ + account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, Transfer2Config, + Transfer2Inputs, + }, + CTokenAccount2, +}; use light_program_test::{ utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig, Rpc, }; use light_sdk::instruction::PackedAccounts; use light_test_utils::{airdrop_lamports, RpcError}; -use light_token::{ - compressed_token::{ - transfer2::{ - account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, - Transfer2Config, Transfer2Inputs, - }, - CTokenAccount2, - }, - ValidityProof, -}; +use light_token::ValidityProof; use light_token_client::actions::{create_mint, mint_to_compressed, transfer2::approve}; use light_token_interface::{ instructions::{mint_action::Recipient, transfer2::MultiInputTokenDataWithContext}, @@ -72,10 +70,11 @@ async fn setup_transfer_test( ) .await?; - let mint = light_token::compressed_token::create_compressed_mint::find_mint_address( - &mint_seed.pubkey(), - ) - .0; + let mint = + light_compressed_token_sdk::compressed_token::create_compressed_mint::find_mint_address( + &mint_seed.pubkey(), + ) + .0; // Mint tokens to owner if amount > 0 if token_amount > 0 { @@ -683,10 +682,11 @@ async fn setup_transfer_test_with_delegate( ) .await?; - let mint = light_token::compressed_token::create_compressed_mint::find_mint_address( - &mint_seed.pubkey(), - ) - .0; + let mint = + light_compressed_token_sdk::compressed_token::create_compressed_mint::find_mint_address( + &mint_seed.pubkey(), + ) + .0; // Mint tokens to owner if amount > 0 if token_amount > 0 { diff --git a/program-tests/registry-test/Cargo.toml b/program-tests/registry-test/Cargo.toml index 86ecef99e4..089c84ec03 100644 --- a/program-tests/registry-test/Cargo.toml +++ b/program-tests/registry-test/Cargo.toml @@ -38,6 +38,7 @@ serial_test = { workspace = true } light-batched-merkle-tree = { workspace = true } light-account-checks = { workspace = true } light-token = { workspace = true } +light-compressed-token-sdk = { workspace = true } light-compressible = { workspace = true } light-token-client = { workspace = true } light-token-interface = { workspace = true } diff --git a/program-tests/registry-test/tests/compressible.rs b/program-tests/registry-test/tests/compressible.rs index 7104bad345..6326b4f084 100644 --- a/program-tests/registry-test/tests/compressible.rs +++ b/program-tests/registry-test/tests/compressible.rs @@ -16,6 +16,7 @@ fn get_token_compression_info(token: &Token) -> Option { _ => None, }) } +use light_compressed_token_sdk::compressed_token::create_compressed_mint::find_mint_address; use light_program_test::{ forester::claim_forester, program_test::TestRpc, utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig, @@ -27,9 +28,8 @@ use light_registry::accounts::{ use light_test_utils::{ airdrop_lamports, assert_claim::assert_claim, spl::create_mint_helper, Rpc, RpcError, }; -use light_token::{ - compressed_token::create_compressed_mint::find_mint_address, - instruction::{derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount, MintTo}, +use light_token::instruction::{ + derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount, MintTo, }; use light_token_client::{ actions::{ diff --git a/program-tests/utils/Cargo.toml b/program-tests/utils/Cargo.toml index 11cf7e4e50..21b57c5f15 100644 --- a/program-tests/utils/Cargo.toml +++ b/program-tests/utils/Cargo.toml @@ -52,5 +52,6 @@ solana-banks-client = { workspace = true } light-zero-copy = { workspace = true } base64 = { workspace = true } light-token = { workspace = true } +light-compressed-token-sdk = { workspace = true } light-token-client = { workspace = true } light-compressible = { workspace = true } diff --git a/program-tests/utils/src/assert_mint_to_compressed.rs b/program-tests/utils/src/assert_mint_to_compressed.rs index 8825a8137a..25bab32ce7 100644 --- a/program-tests/utils/src/assert_mint_to_compressed.rs +++ b/program-tests/utils/src/assert_mint_to_compressed.rs @@ -5,7 +5,7 @@ use light_client::{ rpc::Rpc, }; use light_compressed_token::instructions::create_token_pool::find_token_pool_pda_with_index; -use light_token::compressed_token::create_compressed_mint::derive_mint_from_spl_mint; +use light_compressed_token_sdk::compressed_token::create_compressed_mint::derive_mint_from_spl_mint; use light_token_interface::{ instructions::mint_action::Recipient, state::Mint, LIGHT_TOKEN_PROGRAM_ID, }; diff --git a/program-tests/utils/src/mint_2022.rs b/program-tests/utils/src/mint_2022.rs index 8341480c1b..f627c319b6 100644 --- a/program-tests/utils/src/mint_2022.rs +++ b/program-tests/utils/src/mint_2022.rs @@ -5,7 +5,7 @@ use forester_utils::instructions::create_account::create_account_instruction; use light_client::rpc::Rpc; -use light_token::spl_interface::{find_spl_interface_pda, CreateSplInterfacePda}; +use light_compressed_token_sdk::spl_interface::{find_spl_interface_pda, CreateSplInterfacePda}; use light_token_interface::RESTRICTED_EXTENSION_TYPES; use solana_sdk::{ instruction::Instruction, diff --git a/sdk-libs/client/Cargo.toml b/sdk-libs/client/Cargo.toml index cdcb1ea347..fa614d97fe 100644 --- a/sdk-libs/client/Cargo.toml +++ b/sdk-libs/client/Cargo.toml @@ -48,6 +48,7 @@ light-sdk = { workspace = true, features = ["v2", "cpi-context"] } light-hasher = { workspace = true, features = ["poseidon"] } light-compressed-account = { workspace = true, features = ["solana", "poseidon"] } light-token = { workspace = true, features = ["cpi-context"] } +light-compressed-token-sdk = { workspace = true } light-token-interface = { workspace = true } light-event = { workspace = true } light-compressible = { workspace = true } diff --git a/sdk-libs/client/src/interface/create_accounts_proof.rs b/sdk-libs/client/src/interface/create_accounts_proof.rs index 0d6a1ab7c4..9b4cff501d 100644 --- a/sdk-libs/client/src/interface/create_accounts_proof.rs +++ b/sdk-libs/client/src/interface/create_accounts_proof.rs @@ -2,8 +2,8 @@ //! Programs must pass this to light accounts that they initialize. use light_compressed_account::instruction_data::compressed_proof::ValidityProof; +use light_compressed_token_sdk::compressed_token::create_compressed_mint::derive_mint_compressed_address; use light_sdk::instruction::PackedAddressTreeInfo; -use light_token::compressed_token::create_compressed_mint::derive_mint_compressed_address; use light_token_interface::MINT_ADDRESS_TREE; use solana_instruction::AccountMeta; use solana_pubkey::Pubkey; diff --git a/sdk-libs/client/src/interface/instructions.rs b/sdk-libs/client/src/interface/instructions.rs index 8fbe8916be..9c93e05941 100644 --- a/sdk-libs/client/src/interface/instructions.rs +++ b/sdk-libs/client/src/interface/instructions.rs @@ -11,8 +11,9 @@ use light_sdk::{ SystemAccountMetaConfig, ValidityProof, }, }; -use light_token::instruction::{ - COMPRESSIBLE_CONFIG_V1, LIGHT_TOKEN_CPI_AUTHORITY, LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR, +use light_token::constants::{ + COMPRESSIBLE_CONFIG_V1, LIGHT_TOKEN_CPI_AUTHORITY, LIGHT_TOKEN_PROGRAM_ID, + RENT_SPONSOR_V1 as RENT_SPONSOR, }; use solana_instruction::{AccountMeta, Instruction}; use solana_pubkey::Pubkey; diff --git a/sdk-libs/client/src/interface/load_accounts.rs b/sdk-libs/client/src/interface/load_accounts.rs index 67d1bd7931..d03d2104f4 100644 --- a/sdk-libs/client/src/interface/load_accounts.rs +++ b/sdk-libs/client/src/interface/load_accounts.rs @@ -3,16 +3,15 @@ use light_compressed_account::{ compressed_account::PackedMerkleContext, instruction_data::compressed_proof::ValidityProof, }; +use light_compressed_token_sdk::compressed_token::{ + transfer2::{ + create_transfer2_instruction, Transfer2AccountsMetaConfig, Transfer2Config, Transfer2Inputs, + }, + CTokenAccount2, +}; use light_sdk::{compressible::Pack, instruction::PackedAccounts}; use light_token::{ compat::AccountState, - compressed_token::{ - transfer2::{ - create_transfer2_instruction, Transfer2AccountsMetaConfig, Transfer2Config, - Transfer2Inputs, - }, - CTokenAccount2, - }, instruction::{ derive_token_ata, CreateAssociatedTokenAccount, DecompressMint, LIGHT_TOKEN_PROGRAM_ID, }, diff --git a/sdk-libs/compressed-token-sdk/Cargo.toml b/sdk-libs/compressed-token-sdk/Cargo.toml new file mode 100644 index 0000000000..af5bb0d9fd --- /dev/null +++ b/sdk-libs/compressed-token-sdk/Cargo.toml @@ -0,0 +1,64 @@ +[package] +name = "light-compressed-token-sdk" +version = "0.1.0" +edition = { workspace = true } +description = "Low-level SDK for compressed token operations on Light Protocol" +license = "Apache-2.0" +repository = "https://github.com/Lightprotocol/light-protocol" + +[features] +default = ["anchor-discriminator"] +v1 = [] +anchor-discriminator = ["light-sdk/anchor-discriminator"] +anchor = ["anchor-lang", "light-token-types/anchor", "light-token-interface/anchor"] +# idl-build feature enables IDL generation for client-side tooling and SDK generation +idl-build = ["anchor", "anchor-lang/idl-build", "light-sdk/idl-build"] +cpi-context = ["light-sdk/cpi-context"] + +profile-program = [ + "light-program-profiler/profile-program", + "light-compressed-account/profile-program", + "light-token-interface/profile-program", +] +profile-heap = [ + "light-program-profiler/profile-heap", + "light-compressed-account/profile-heap", + "light-token-interface/profile-heap", +] + +[dependencies] +# Light Protocol dependencies +light-token-types = { workspace = true } +light-compressed-account = { workspace = true, features = ["std", "solana"] } +light-token-interface = { workspace = true } +light-sdk = { workspace = true, features = ["v2"] } +light-sdk-types = { workspace = true, features = ["v2"] } +light-account-checks = { workspace = true, features = ["solana"] } +light-zero-copy = { workspace = true } +light-program-profiler = { workspace = true } + +# Serialization +borsh = { workspace = true } +thiserror = { workspace = true } +solana-msg = { workspace = true } + +# Solana dependencies +solana-pubkey = { workspace = true, features = ["sha2", "curve25519"] } +solana-instruction = { workspace = true } +solana-account-info = { workspace = true } +solana-cpi = { workspace = true } +solana-program-error = { workspace = true } +arrayvec = { workspace = true } + +# Optional Anchor dependency +anchor-lang = { workspace = true, optional = true } + +[dev-dependencies] +light-account-checks = { workspace = true, features = ["test-only", "pinocchio", "std"] } + +[lints.rust.unexpected_cfgs] +level = "allow" +check-cfg = [ + 'cfg(target_os, values("solana"))', + 'cfg(feature, values("frozen-abi", "no-entrypoint"))', +] diff --git a/sdk-libs/compressed-token-sdk/src/compat.rs b/sdk-libs/compressed-token-sdk/src/compat.rs new file mode 100644 index 0000000000..3caf5db2ed --- /dev/null +++ b/sdk-libs/compressed-token-sdk/src/compat.rs @@ -0,0 +1,130 @@ +//! Solana-compatible token types using `solana_pubkey::Pubkey`. +//! +//! This module provides convenience types that use standard Solana pubkeys +//! instead of byte arrays for easier integration. + +use light_compressed_account::compressed_account::CompressedAccountWithMerkleContext; +use light_sdk::light_hasher::{sha256::Sha256BE, HasherError}; +use solana_program_error::ProgramError; +use solana_pubkey::Pubkey; + +use crate::{AnchorDeserialize, AnchorSerialize}; + +#[derive(Clone, Copy, Debug, PartialEq, Eq, AnchorDeserialize, AnchorSerialize, Default)] +#[repr(u8)] +pub enum AccountState { + #[default] + Initialized = 0, + Frozen = 1, +} + +impl From for light_token_interface::state::CompressedTokenAccountState { + fn from(state: AccountState) -> Self { + match state { + AccountState::Initialized => { + light_token_interface::state::CompressedTokenAccountState::Initialized + } + AccountState::Frozen => { + light_token_interface::state::CompressedTokenAccountState::Frozen + } + } + } +} + +impl TryFrom for AccountState { + type Error = ProgramError; + + fn try_from(value: u8) -> Result { + match value { + 0 => Ok(AccountState::Initialized), + 1 => Ok(AccountState::Frozen), + _ => Err(ProgramError::InvalidAccountData), + } + } +} + +/// TokenData using standard Solana pubkeys. +/// +/// For zero-copy operations, use `TokenData` from `light_token_interface`. +#[derive(Debug, PartialEq, Eq, AnchorDeserialize, AnchorSerialize, Clone, Default)] +pub struct TokenData { + /// The mint associated with this account + pub mint: Pubkey, + /// The owner of this account + pub owner: Pubkey, + /// The amount of tokens this account holds + pub amount: u64, + /// Optional delegate authorized to transfer tokens + pub delegate: Option, + /// The account's state + pub state: AccountState, + /// TLV extensions for compressed token accounts + pub tlv: Option>, +} + +impl TokenData { + /// TokenDataVersion 3 + /// CompressedAccount Discriminator `[0,0,0,0,0,0,0,4]` + #[inline(always)] + pub fn hash_sha_flat(&self) -> Result<[u8; 32], HasherError> { + use light_sdk::light_hasher::Hasher; + let bytes = self.try_to_vec().map_err(|_| HasherError::BorshError)?; + Sha256BE::hash(bytes.as_slice()) + } +} + +/// TokenData with merkle context for verification +#[derive(Debug, Clone, PartialEq)] +pub struct TokenDataWithMerkleContext { + pub token_data: TokenData, + pub compressed_account: CompressedAccountWithMerkleContext, +} + +impl TokenDataWithMerkleContext { + /// Only works for sha flat hash + pub fn hash(&self) -> Result<[u8; 32], HasherError> { + if let Some(data) = self.compressed_account.compressed_account.data.as_ref() { + match data.discriminator { + [0, 0, 0, 0, 0, 0, 0, 4] => self.token_data.hash_sha_flat(), + _ => Err(HasherError::EmptyInput), + } + } else { + Err(HasherError::EmptyInput) + } + } +} + +impl From for light_token_interface::state::TokenData { + fn from(data: TokenData) -> Self { + use light_token_interface::state::CompressedTokenAccountState; + + Self { + mint: data.mint.to_bytes().into(), + owner: data.owner.to_bytes().into(), + amount: data.amount, + delegate: data.delegate.map(|d| d.to_bytes().into()), + state: match data.state { + AccountState::Initialized => CompressedTokenAccountState::Initialized as u8, + AccountState::Frozen => CompressedTokenAccountState::Frozen as u8, + }, + tlv: data.tlv, + } + } +} + +impl From for TokenData { + fn from(data: light_token_interface::state::TokenData) -> Self { + Self { + mint: Pubkey::new_from_array(data.mint.to_bytes()), + owner: Pubkey::new_from_array(data.owner.to_bytes()), + amount: data.amount, + delegate: data.delegate.map(|d| Pubkey::new_from_array(d.to_bytes())), + state: AccountState::try_from(data.state).unwrap_or(AccountState::Initialized), + tlv: data.tlv, + } + } +} + +/// Type alias for backward compatibility +pub type InputTokenDataCompressible = + light_token_interface::instructions::transfer2::MultiTokenTransferOutputData; diff --git a/sdk-libs/token-sdk/src/compressed_token/ctoken_instruction.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/ctoken_instruction.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/ctoken_instruction.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/ctoken_instruction.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/mod.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/account.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/account.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/account.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/account.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/approve/account_metas.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/approve/account_metas.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/approve/account_metas.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/approve/account_metas.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/approve/instruction.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/approve/instruction.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/approve/instruction.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/approve/instruction.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/approve/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/approve/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/approve/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/approve/mod.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/batch_compress/account_metas.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/batch_compress/account_metas.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/batch_compress/account_metas.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/batch_compress/account_metas.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/batch_compress/instruction.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/batch_compress/instruction.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/batch_compress/instruction.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/batch_compress/instruction.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/batch_compress/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/batch_compress/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/batch_compress/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/batch_compress/mod.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/mod.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/transfer/account_infos.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/transfer/account_infos.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/transfer/account_infos.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/transfer/account_infos.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/transfer/account_metas.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/transfer/account_metas.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/transfer/account_metas.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/transfer/account_metas.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/transfer/instruction.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/transfer/instruction.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/transfer/instruction.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/transfer/instruction.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v1/transfer/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v1/transfer/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v1/transfer/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v1/transfer/mod.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/account2.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/account2.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/account2.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/account2.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/compress_and_close.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/compress_and_close.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/compress_and_close.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/compress_and_close.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/create_compressed_mint/account_metas.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/create_compressed_mint/account_metas.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/create_compressed_mint/account_metas.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/create_compressed_mint/account_metas.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/create_compressed_mint/instruction.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/create_compressed_mint/instruction.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/create_compressed_mint/instruction.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/create_compressed_mint/instruction.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/create_compressed_mint/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/create_compressed_mint/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/create_compressed_mint/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/create_compressed_mint/mod.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/decompress_full.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/decompress_full.rs similarity index 98% rename from sdk-libs/token-sdk/src/compressed_token/v2/decompress_full.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/decompress_full.rs index 81829891c6..d180123d27 100644 --- a/sdk-libs/token-sdk/src/compressed_token/v2/decompress_full.rs +++ b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/decompress_full.rs @@ -1,4 +1,6 @@ -use light_compressed_account::compressed_account::PackedMerkleContext; +use light_compressed_account::{ + compressed_account::PackedMerkleContext, instruction_data::compressed_proof::ValidityProof, +}; use light_program_profiler::profile; use light_sdk::{ error::LightSdkError, @@ -21,7 +23,7 @@ use super::{ }; use crate::{ compat::TokenData, error::TokenSdkError, utils::TokenDefaultAccounts, AnchorDeserialize, - AnchorSerialize, ValidityProof, + AnchorSerialize, }; /// Struct to hold all the data needed for DecompressFull operation diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/mint_action/account_metas.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_action/account_metas.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/mint_action/account_metas.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_action/account_metas.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/mint_action/cpi_accounts.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_action/cpi_accounts.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/mint_action/cpi_accounts.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_action/cpi_accounts.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/mint_action/instruction.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_action/instruction.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/mint_action/instruction.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_action/instruction.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/mint_action/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_action/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/mint_action/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_action/mod.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/mint_to_compressed/account_metas.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_to_compressed/account_metas.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/mint_to_compressed/account_metas.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_to_compressed/account_metas.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/mint_to_compressed/instruction.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_to_compressed/instruction.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/mint_to_compressed/instruction.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_to_compressed/instruction.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/mint_to_compressed/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_to_compressed/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/mint_to_compressed/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/mint_to_compressed/mod.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/mod.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/token_metadata_ui.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/token_metadata_ui.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/token_metadata_ui.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/token_metadata_ui.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/transfer2/account_metas.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/transfer2/account_metas.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/transfer2/account_metas.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/transfer2/account_metas.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/transfer2/cpi_accounts.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/transfer2/cpi_accounts.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/transfer2/cpi_accounts.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/transfer2/cpi_accounts.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/transfer2/instruction.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/transfer2/instruction.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/transfer2/instruction.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/transfer2/instruction.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/transfer2/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/transfer2/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/transfer2/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/transfer2/mod.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/update_compressed_mint/account_metas.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/update_compressed_mint/account_metas.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/update_compressed_mint/account_metas.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/update_compressed_mint/account_metas.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/update_compressed_mint/instruction.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/update_compressed_mint/instruction.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/update_compressed_mint/instruction.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/update_compressed_mint/instruction.rs diff --git a/sdk-libs/token-sdk/src/compressed_token/v2/update_compressed_mint/mod.rs b/sdk-libs/compressed-token-sdk/src/compressed_token/v2/update_compressed_mint/mod.rs similarity index 100% rename from sdk-libs/token-sdk/src/compressed_token/v2/update_compressed_mint/mod.rs rename to sdk-libs/compressed-token-sdk/src/compressed_token/v2/update_compressed_mint/mod.rs diff --git a/sdk-libs/compressed-token-sdk/src/constants.rs b/sdk-libs/compressed-token-sdk/src/constants.rs new file mode 100644 index 0000000000..edb6ad980c --- /dev/null +++ b/sdk-libs/compressed-token-sdk/src/constants.rs @@ -0,0 +1,22 @@ +use solana_pubkey::Pubkey; + +pub const SPL_TOKEN_PROGRAM_ID: Pubkey = + Pubkey::new_from_array(light_token_types::SPL_TOKEN_PROGRAM_ID); + +pub const SPL_TOKEN_2022_PROGRAM_ID: Pubkey = + Pubkey::new_from_array(light_token_types::SPL_TOKEN_2022_PROGRAM_ID); + +pub const LIGHT_SYSTEM_PROGRAM_ID: Pubkey = + Pubkey::new_from_array(light_token_types::LIGHT_SYSTEM_PROGRAM_ID); + +pub const ACCOUNT_COMPRESSION_PROGRAM_ID: Pubkey = + Pubkey::new_from_array(light_token_types::ACCOUNT_COMPRESSION_PROGRAM_ID); + +pub const ACCOUNT_COMPRESSION_AUTHORITY_PDA: Pubkey = + Pubkey::new_from_array(light_token_types::ACCOUNT_COMPRESSION_AUTHORITY_PDA); + +pub const NOOP_PROGRAM_ID: Pubkey = Pubkey::new_from_array(light_token_types::NOOP_PROGRAM_ID); + +pub const CPI_AUTHORITY_PDA: Pubkey = Pubkey::new_from_array(light_token_types::CPI_AUTHORITY_PDA); + +pub const LIGHT_TOKEN_PROGRAM_ID: Pubkey = Pubkey::new_from_array(light_token_types::PROGRAM_ID); diff --git a/sdk-libs/compressed-token-sdk/src/error.rs b/sdk-libs/compressed-token-sdk/src/error.rs new file mode 100644 index 0000000000..39ad5a05b4 --- /dev/null +++ b/sdk-libs/compressed-token-sdk/src/error.rs @@ -0,0 +1,150 @@ +use light_account_checks::AccountError; +use light_sdk::error::LightSdkError; +use light_sdk_types::error::LightSdkTypesError; +use light_token_interface::TokenError; +use light_token_types::error::LightTokenSdkTypeError; +use light_zero_copy::errors::ZeroCopyError; +use solana_program_error::ProgramError; +use thiserror::Error; + +pub type Result = std::result::Result; + +#[derive(Debug, Error)] +pub enum TokenSdkError { + #[error("Insufficient balance")] + InsufficientBalance, + #[error("Serialization error")] + SerializationError, + #[error("CPI error: {0}")] + CpiError(String), + #[error("Cannot compress and decompress")] + CannotCompressAndDecompress, + #[error("Compression cannot be set twice")] + CompressionCannotBeSetTwice, + #[error("Inconsistent compress/decompress state")] + InconsistentCompressDecompressState, + #[error("Both compress and decompress specified")] + BothCompressAndDecompress, + #[error("Invalid compress/decompress amount")] + InvalidCompressDecompressAmount, + #[error("Ctoken::transfer, compress, or decompress cannot be used with fn transfer(), fn compress(), fn decompress()")] + MethodUsed, + #[error("DecompressedMintConfig is required for decompressed mints")] + DecompressedMintConfigRequired, + #[error("Invalid compress input owner")] + InvalidCompressInputOwner, + #[error("Account borrow failed")] + AccountBorrowFailed, + #[error("Invalid account data")] + InvalidAccountData, + #[error("Missing required CPI account")] + MissingCpiAccount, + #[error("Too many accounts")] + TooManyAccounts, + #[error("PackedAccount indices are not continuous")] + NonContinuousIndices, + #[error("PackedAccount index out of bounds")] + PackedAccountIndexOutOfBounds, + #[error("Cannot mint with decompressed mint in CPI write mode")] + CannotMintWithDecompressedInCpiWrite, + #[error("RentAuthorityIsNone")] + RentAuthorityIsNone, + #[error("Incomplete SPL interface")] + IncompleteSplInterface, + #[error("SPL interface required")] + SplInterfaceRequired, + #[error("Use regular SPL transfer")] + UseRegularSplTransfer, + #[error("Cannot determine account type")] + CannotDetermineAccountType, + #[error("MintActionMetaConfig::new_cpi_context requires cpi_context data")] + CpiContextRequired, + #[error("Missing mint account")] + MissingMintAccount, + #[error("Missing SPL token program")] + MissingSplTokenProgram, + #[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("Missing Compressible extension on Light Token account")] + MissingCompressibleExtension, + #[error("Invalid Token account data")] + InvalidTokenAccount, + #[error("SPL token program mismatch between source and destination")] + SplTokenProgramMismatch, + #[error(transparent)] + CompressedTokenTypes(#[from] LightTokenSdkTypeError), + #[error(transparent)] + TokenError(#[from] TokenError), + #[error(transparent)] + LightSdkError(#[from] LightSdkError), + #[error(transparent)] + LightSdkTypesError(#[from] LightSdkTypesError), + #[error(transparent)] + ZeroCopyError(#[from] ZeroCopyError), + #[error(transparent)] + AccountError(#[from] AccountError), +} +#[cfg(feature = "anchor")] +impl From for anchor_lang::prelude::ProgramError { + fn from(e: TokenSdkError) -> Self { + ProgramError::Custom(e.into()) + } +} +#[cfg(not(feature = "anchor"))] +impl From for ProgramError { + fn from(e: TokenSdkError) -> Self { + ProgramError::Custom(e.into()) + } +} + +impl From for u32 { + fn from(e: TokenSdkError) -> 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::MissingSplInterfacePda => 17027, + TokenSdkError::MissingSplInterfacePdaBump => 17028, + TokenSdkError::InvalidCpiContext => 17029, + TokenSdkError::NoInputAccounts => 17030, + TokenSdkError::MissingCompressibleExtension => 17031, + TokenSdkError::InvalidTokenAccount => 17032, + TokenSdkError::SplTokenProgramMismatch => 17033, + TokenSdkError::CompressedTokenTypes(e) => e.into(), + TokenSdkError::TokenError(e) => e.into(), + TokenSdkError::LightSdkTypesError(e) => e.into(), + TokenSdkError::LightSdkError(e) => e.into(), + TokenSdkError::ZeroCopyError(e) => e.into(), + TokenSdkError::AccountError(e) => e.into(), + } + } +} diff --git a/sdk-libs/compressed-token-sdk/src/lib.rs b/sdk-libs/compressed-token-sdk/src/lib.rs new file mode 100644 index 0000000000..8cbcd0b623 --- /dev/null +++ b/sdk-libs/compressed-token-sdk/src/lib.rs @@ -0,0 +1,36 @@ +//! # Light Compressed Token SDK +//! +//! Low-level SDK for compressed token operations on Light Protocol. +//! +//! This crate provides the core building blocks for working with compressed token accounts, +//! including instruction builders for transfers, mints, and compress/decompress operations. +//! +//! ## Features +//! +//! - `v1` - Enable v1 compressed token support +//! - `anchor` - Enable Anchor framework integration +//! - `anchor-discriminator` - Use Anchor-style discriminators (default) +//! +//! ## Modules +//! +//! - [`compressed_token`] - Core compressed token types and instruction builders +//! - [`error`] - Error types for compressed token operations +//! - [`utils`] - Utility functions and default account configurations +//! - [`constants`] - Program IDs and other constants +//! - [`spl_interface`] - SPL interface PDA derivation utilities + +pub mod compat; +pub mod compressed_token; +pub mod constants; +pub mod error; +pub mod spl_interface; +pub mod utils; + +// Conditional anchor re-exports +#[cfg(feature = "anchor")] +use anchor_lang::{AnchorDeserialize, AnchorSerialize}; +#[cfg(not(feature = "anchor"))] +use borsh::{BorshDeserialize as AnchorDeserialize, BorshSerialize as AnchorSerialize}; +pub use light_compressed_account::instruction_data::compressed_proof::{ + CompressedProof, ValidityProof, +}; diff --git a/sdk-libs/compressed-token-sdk/src/spl_interface.rs b/sdk-libs/compressed-token-sdk/src/spl_interface.rs new file mode 100644 index 0000000000..3f7b6a87ca --- /dev/null +++ b/sdk-libs/compressed-token-sdk/src/spl_interface.rs @@ -0,0 +1,133 @@ +//! SPL interface PDA derivation utilities. +//! +//! Re-exports from `light_token_interface` with convenience wrappers. + +use light_token_interface::{ + discriminator::{ADD_TOKEN_POOL, CREATE_TOKEN_POOL}, + CPI_AUTHORITY, LIGHT_TOKEN_PROGRAM_ID, +}; +// Re-export derivation functions from token-interface +pub use light_token_interface::{ + find_spl_interface_pda, find_spl_interface_pda_with_index, get_spl_interface_pda, + has_restricted_extensions, is_valid_spl_interface_pda, NUM_MAX_POOL_ACCOUNTS, +}; +use solana_instruction::{AccountMeta, Instruction}; +use solana_pubkey::Pubkey; + +use crate::{AnchorDeserialize, AnchorSerialize}; + +#[derive(Debug, Clone, AnchorDeserialize, AnchorSerialize, PartialEq)] +pub struct SplInterfacePda { + pub pubkey: Pubkey, + pub bump: u8, + pub index: u8, +} + +/// Derive spl interface pda information for a given mint +pub fn derive_spl_interface_pda(mint: &Pubkey, index: u8, restricted: bool) -> SplInterfacePda { + let (pubkey, bump) = find_spl_interface_pda_with_index(mint, index, restricted); + SplInterfacePda { + pubkey, + bump, + index, + } +} + +/// # Create SPL interface PDA (token pool) instruction builder +/// +/// Creates or adds an spl interface pda for an SPL mint. +/// Spl interface pdas store spl tokens that are wrapped in ctoken or compressed token accounts. +/// +/// ```rust +/// # use solana_pubkey::Pubkey; +/// # use light_compressed_token_sdk::spl_interface::CreateSplInterfacePda; +/// # use light_compressed_token_sdk::constants::SPL_TOKEN_PROGRAM_ID; +/// # let fee_payer = Pubkey::new_unique(); +/// # let mint = Pubkey::new_unique(); +/// # let token_program = SPL_TOKEN_PROGRAM_ID; +/// // Create initial pool (index 0) +/// let instruction = CreateSplInterfacePda::new(fee_payer, mint, token_program, false) +/// .instruction(); +/// // Add additional pool (index 1) +/// let instruction = CreateSplInterfacePda::new_with_index(fee_payer, mint, token_program, 1, false) +/// .instruction(); +/// ``` +pub struct CreateSplInterfacePda { + pub fee_payer: Pubkey, + pub mint: Pubkey, + pub token_program: Pubkey, + pub spl_interface_pda: Pubkey, + pub existing_spl_interface_pda: Option, + pub index: u8, +} + +impl CreateSplInterfacePda { + /// Derives the spl interface pda for an SPL mint with index 0. + pub fn new(fee_payer: Pubkey, mint: Pubkey, token_program: Pubkey, restricted: bool) -> Self { + Self::new_with_index(fee_payer, mint, token_program, 0, restricted) + } + + /// Derives the spl interface pda for an SPL mint with a specific index. + /// For index 0, creates the initial pool. For index > 0, adds an additional pool. + pub fn new_with_index( + fee_payer: Pubkey, + mint: Pubkey, + token_program: Pubkey, + index: u8, + restricted: bool, + ) -> Self { + let (spl_interface_pda, _) = find_spl_interface_pda_with_index(&mint, index, restricted); + let existing_spl_interface_pda = if index > 0 { + let (existing_pda, _) = + find_spl_interface_pda_with_index(&mint, index.saturating_sub(1), restricted); + Some(existing_pda) + } else { + None + }; + Self { + fee_payer, + mint, + token_program, + spl_interface_pda, + existing_spl_interface_pda, + index, + } + } + + pub fn instruction(self) -> Instruction { + let cpi_authority = Pubkey::from(CPI_AUTHORITY); + + if self.index == 0 { + // CreateTokenPool instruction + Instruction { + program_id: Pubkey::from(LIGHT_TOKEN_PROGRAM_ID), + accounts: vec![ + AccountMeta::new(self.fee_payer, true), + AccountMeta::new(self.spl_interface_pda, false), + AccountMeta::new_readonly(Pubkey::default(), false), // system_program + AccountMeta::new(self.mint, false), + AccountMeta::new_readonly(self.token_program, false), + AccountMeta::new_readonly(cpi_authority, false), + ], + data: CREATE_TOKEN_POOL.to_vec(), + } + } else { + // AddTokenPool instruction + let mut data = ADD_TOKEN_POOL.to_vec(); + data.push(self.index); + Instruction { + program_id: Pubkey::from(LIGHT_TOKEN_PROGRAM_ID), + accounts: vec![ + AccountMeta::new(self.fee_payer, true), + AccountMeta::new(self.spl_interface_pda, false), + AccountMeta::new_readonly(self.existing_spl_interface_pda.unwrap(), false), + AccountMeta::new_readonly(Pubkey::default(), false), // system_program + AccountMeta::new(self.mint, false), + AccountMeta::new_readonly(self.token_program, false), + AccountMeta::new_readonly(cpi_authority, false), + ], + data, + } + } + } +} diff --git a/sdk-libs/compressed-token-sdk/src/utils.rs b/sdk-libs/compressed-token-sdk/src/utils.rs new file mode 100644 index 0000000000..18a9409418 --- /dev/null +++ b/sdk-libs/compressed-token-sdk/src/utils.rs @@ -0,0 +1,107 @@ +//! Utility functions and default account configurations. + +use light_sdk::constants::REGISTERED_PROGRAM_PDA; +use light_sdk_types::LIGHT_TOKEN_PROGRAM_ID; +use light_token_interface::{ + instructions::transfer2::MultiInputTokenDataWithContext, state::Token, +}; +use light_token_types::{ + ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, CPI_AUTHORITY_PDA, + LIGHT_SYSTEM_PROGRAM_ID, NOOP_PROGRAM_ID, PROGRAM_ID as LIGHT_COMPRESSED_TOKEN_PROGRAM_ID, +}; +use solana_account_info::AccountInfo; +use solana_instruction::AccountMeta; +use solana_pubkey::Pubkey; + +use crate::{error::TokenSdkError, AnchorDeserialize, AnchorSerialize}; + +pub fn get_token_account_balance(token_account_info: &AccountInfo) -> Result { + let data = token_account_info + .try_borrow_data() + .map_err(|_| TokenSdkError::AccountBorrowFailed)?; + Token::amount_from_slice(&data).map_err(|_| TokenSdkError::InvalidAccountData) +} + +/// Check if an account owner is a Light token program. +/// +/// Returns `Ok(true)` if owner is `LIGHT_TOKEN_PROGRAM_ID`. +/// Returns `Ok(false)` if owner is SPL Token or Token-2022. +/// Returns `Err` if owner is unrecognized. +pub fn is_light_token_owner(owner: &Pubkey) -> Result { + let light_token_program_id = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + + if owner == &light_token_program_id { + return Ok(true); + } + + let spl_token = Pubkey::from(light_token_types::SPL_TOKEN_PROGRAM_ID); + let spl_token_2022 = Pubkey::from(light_token_types::SPL_TOKEN_2022_PROGRAM_ID); + + if owner == &spl_token_2022 || owner == &spl_token { + return Ok(false); + } + + Err(TokenSdkError::CannotDetermineAccountType) +} + +/// Check if an account is a Light token account (by checking its owner). +/// +/// Returns `Ok(true)` if owner is `LIGHT_TOKEN_PROGRAM_ID`. +/// Returns `Ok(false)` if owner is SPL Token or Token-2022. +/// Returns `Err` if owner is unrecognized. +pub fn is_token_account(account_info: &AccountInfo) -> Result { + is_light_token_owner(account_info.owner) +} + +pub const CLOSE_TOKEN_ACCOUNT_DISCRIMINATOR: u8 = 9; + +#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)] +pub struct PackedCompressedTokenDataWithContext { + pub mint: u8, + pub source_or_recipient_token_account: u8, + pub multi_input_token_data_with_context: MultiInputTokenDataWithContext, +} + +pub fn account_meta_from_account_info(account_info: &AccountInfo) -> AccountMeta { + AccountMeta { + pubkey: *account_info.key, + is_signer: account_info.is_signer, + is_writable: account_info.is_writable, + } +} + +#[derive(Debug, Clone)] +pub struct AccountInfoToCompress<'info> { + pub account_info: AccountInfo<'info>, + pub signer_seeds: Vec>, +} + +/// Standard pubkeys for compressed token instructions +#[derive(Debug, Copy, Clone)] +pub struct TokenDefaultAccounts { + pub light_system_program: Pubkey, + pub registered_program_pda: Pubkey, + pub noop_program: Pubkey, + pub account_compression_authority: Pubkey, + pub account_compression_program: Pubkey, + pub self_program: Pubkey, + pub cpi_authority_pda: Pubkey, + pub system_program: Pubkey, + pub compressed_token_program: Pubkey, +} + +impl Default for TokenDefaultAccounts { + fn default() -> Self { + Self { + light_system_program: Pubkey::from(LIGHT_SYSTEM_PROGRAM_ID), + registered_program_pda: Pubkey::from(REGISTERED_PROGRAM_PDA), + noop_program: Pubkey::from(NOOP_PROGRAM_ID), + account_compression_authority: Pubkey::from(ACCOUNT_COMPRESSION_AUTHORITY_PDA), + account_compression_program: Pubkey::from(ACCOUNT_COMPRESSION_PROGRAM_ID), + self_program: Pubkey::from(LIGHT_COMPRESSED_TOKEN_PROGRAM_ID), + cpi_authority_pda: Pubkey::from(CPI_AUTHORITY_PDA), + system_program: Pubkey::default(), + compressed_token_program: Pubkey::from(LIGHT_TOKEN_PROGRAM_ID), + } + } +} diff --git a/sdk-libs/program-test/Cargo.toml b/sdk-libs/program-test/Cargo.toml index 3db4d55a09..af6b4f7b77 100644 --- a/sdk-libs/program-test/Cargo.toml +++ b/sdk-libs/program-test/Cargo.toml @@ -21,6 +21,7 @@ light-hasher = { workspace = true, features = ["poseidon", "sha256", "keccak", " light-token-interface = { workspace = true } light-compressible = { workspace = true } light-token = { workspace = true } +light-compressed-token-sdk = { workspace = true } light-compressed-account = { workspace = true, features = ["anchor", "poseidon"] } light-batched-merkle-tree = { workspace = true, features = ["test-only"], optional = true } light-event = { workspace = true } diff --git a/sdk-libs/program-test/src/compressible.rs b/sdk-libs/program-test/src/compressible.rs index bc208d28e0..c8e6b3e657 100644 --- a/sdk-libs/program-test/src/compressible.rs +++ b/sdk-libs/program-test/src/compressible.rs @@ -389,8 +389,8 @@ async fn compress_mint_forester( ) -> Result<(), RpcError> { use light_client::indexer::Indexer; use light_compressed_account::instruction_data::traits::LightInstructionData; + use light_compressed_token_sdk::compressed_token::mint_action::MintActionMetaConfig; use light_compressible::config::CompressibleConfig; - use light_token::compressed_token::mint_action::MintActionMetaConfig; use light_token_interface::instructions::mint_action::{ CompressAndCloseMintAction, MintActionCompressedInstructionData, MintWithContext, }; diff --git a/sdk-libs/program-test/src/forester/compress_and_close_forester.rs b/sdk-libs/program-test/src/forester/compress_and_close_forester.rs index 2c33ee7f87..1ac543bc3d 100644 --- a/sdk-libs/program-test/src/forester/compress_and_close_forester.rs +++ b/sdk-libs/program-test/src/forester/compress_and_close_forester.rs @@ -2,9 +2,9 @@ use light_client::{ indexer::Indexer, rpc::{Rpc, RpcError}, }; +use light_compressed_token_sdk::compressed_token::CompressAndCloseAccounts as CTokenCompressAndCloseAccounts; use light_compressible::config::CompressibleConfig; use light_sdk::instruction::PackedAccounts; -use light_token::compressed_token::CompressAndCloseAccounts as CTokenCompressAndCloseAccounts; use solana_sdk::{ pubkey::Pubkey, signature::{Keypair, Signature}, diff --git a/sdk-libs/token-client/Cargo.toml b/sdk-libs/token-client/Cargo.toml index a5d876fa21..e64936bd00 100644 --- a/sdk-libs/token-client/Cargo.toml +++ b/sdk-libs/token-client/Cargo.toml @@ -14,6 +14,7 @@ light-token-interface = { workspace = true } light-sdk = { workspace = true } light-client = { workspace = true, features = ["v2"] } light-token = { workspace = true } +light-compressed-token-sdk = { workspace = true } light-zero-copy = { workspace = true } # Solana dependencies diff --git a/sdk-libs/token-client/src/actions/mint_action.rs b/sdk-libs/token-client/src/actions/mint_action.rs index 4258f5a219..aa1420e58f 100644 --- a/sdk-libs/token-client/src/actions/mint_action.rs +++ b/sdk-libs/token-client/src/actions/mint_action.rs @@ -2,7 +2,7 @@ use light_client::{ indexer::Indexer, rpc::{Rpc, RpcError}, }; -use light_token::compressed_token::create_compressed_mint::{ +use light_compressed_token_sdk::compressed_token::create_compressed_mint::{ derive_mint_compressed_address, find_mint_address, }; use light_token_interface::instructions::mint_action::Recipient; diff --git a/sdk-libs/token-client/src/actions/spl_interface.rs b/sdk-libs/token-client/src/actions/spl_interface.rs index de0d05f3b2..0efc3d6fb8 100644 --- a/sdk-libs/token-client/src/actions/spl_interface.rs +++ b/sdk-libs/token-client/src/actions/spl_interface.rs @@ -3,7 +3,7 @@ //! This module provides actions for working with SPL interface PDAs (token pools). use light_client::rpc::{Rpc, RpcError}; -use light_token::spl_interface::{find_spl_interface_pda, CreateSplInterfacePda}; +use light_compressed_token_sdk::spl_interface::{find_spl_interface_pda, CreateSplInterfacePda}; use light_token_interface::has_restricted_extensions; use solana_keypair::Keypair; use solana_pubkey::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 df9aa4a177..5a0a389d1f 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 @@ -2,10 +2,10 @@ use light_client::{ indexer::Indexer, rpc::{Rpc, RpcError}, }; -use light_token::{ - constants::SPL_TOKEN_PROGRAM_ID, instruction::TransferToSpl, - spl_interface::find_spl_interface_pda, +use light_compressed_token_sdk::{ + constants::SPL_TOKEN_PROGRAM_ID, spl_interface::find_spl_interface_pda, }; +use light_token::instruction::TransferToSpl; use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signature::Signature; 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 87617dd877..93aa6493be 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 @@ -2,10 +2,10 @@ use light_client::{ indexer::Indexer, rpc::{Rpc, RpcError}, }; -use light_token::{ - constants::SPL_TOKEN_PROGRAM_ID, instruction::TransferFromSpl, - spl_interface::find_spl_interface_pda, +use light_compressed_token_sdk::{ + constants::SPL_TOKEN_PROGRAM_ID, spl_interface::find_spl_interface_pda, }; +use light_token::instruction::TransferFromSpl; use solana_keypair::Keypair; use solana_pubkey::Pubkey; use solana_signature::Signature; diff --git a/sdk-libs/token-client/src/instructions/mint_action.rs b/sdk-libs/token-client/src/instructions/mint_action.rs index 2e18f6d75d..5ae25f6984 100644 --- a/sdk-libs/token-client/src/instructions/mint_action.rs +++ b/sdk-libs/token-client/src/instructions/mint_action.rs @@ -4,11 +4,11 @@ use light_client::{ rpc::{Rpc, RpcError}, }; use light_compressed_account::instruction_data::traits::LightInstructionData; -use light_compressible::config::CompressibleConfig; -use light_token::compressed_token::{ +use light_compressed_token_sdk::compressed_token::{ create_compressed_mint::{derive_mint_compressed_address, find_mint_address}, mint_action::MintActionMetaConfig, }; +use light_compressible::config::CompressibleConfig; use light_token_interface::{ instructions::{ extensions::{token_metadata::TokenMetadataInstructionData, ExtensionInstructionData}, diff --git a/sdk-libs/token-client/src/instructions/mint_to_compressed.rs b/sdk-libs/token-client/src/instructions/mint_to_compressed.rs index 25d2a1b147..dc83177558 100644 --- a/sdk-libs/token-client/src/instructions/mint_to_compressed.rs +++ b/sdk-libs/token-client/src/instructions/mint_to_compressed.rs @@ -3,11 +3,14 @@ use light_client::{ indexer::Indexer, rpc::{Rpc, RpcError}, }; -use light_token::compressed_token::{ - create_compressed_mint::derive_mint_from_spl_mint, - mint_to_compressed::{ - create_mint_to_compressed_instruction, DecompressedMintConfig, MintToCompressedInputs, +use light_compressed_token_sdk::{ + compressed_token::{ + create_compressed_mint::derive_mint_from_spl_mint, + mint_to_compressed::{ + create_mint_to_compressed_instruction, DecompressedMintConfig, MintToCompressedInputs, + }, }, + spl_interface::SplInterfacePda, }; use light_token_interface::{ instructions::mint_action::{MintWithContext, Recipient}, @@ -63,7 +66,7 @@ pub async fn mint_to_compressed_instruction( unimplemented!("SPL mint synchronization for decompressed Mint not yet implemented"); } let decompressed_mint_config: Option> = None; - let spl_interface_pda: Option = None; + let spl_interface_pda: Option = None; // Prepare compressed mint inputs let compressed_mint_inputs = MintWithContext { diff --git a/sdk-libs/token-client/src/instructions/transfer2.rs b/sdk-libs/token-client/src/instructions/transfer2.rs index 312d037ba5..1ff92eeda9 100644 --- a/sdk-libs/token-client/src/instructions/transfer2.rs +++ b/sdk-libs/token-client/src/instructions/transfer2.rs @@ -2,8 +2,7 @@ use light_client::{ indexer::{CompressedTokenAccount, Indexer}, rpc::Rpc, }; -use light_sdk::instruction::{PackedAccounts, PackedStateTreeInfo}; -use light_token::{ +use light_compressed_token_sdk::{ compressed_token::{ transfer2::{ account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, @@ -11,9 +10,10 @@ use light_token::{ }, CTokenAccount2, }, - error::TokenSdkError, spl_interface::find_spl_interface_pda_with_index, }; +use light_sdk::instruction::{PackedAccounts, PackedStateTreeInfo}; +use light_token::error::TokenSdkError; use light_token_interface::{ instructions::{ extensions::ExtensionInstructionData, 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 dbf463503d..3f1a83decb 100644 --- a/sdk-libs/token-client/src/instructions/update_compressed_mint.rs +++ b/sdk-libs/token-client/src/instructions/update_compressed_mint.rs @@ -3,7 +3,7 @@ use light_client::{ indexer::Indexer, rpc::{Rpc, RpcError}, }; -use light_token::compressed_token::update_compressed_mint::{ +use light_compressed_token_sdk::compressed_token::update_compressed_mint::{ update_compressed_mint, UpdateMintInputs, }; use light_token_interface::{ diff --git a/sdk-libs/token-sdk/Cargo.toml b/sdk-libs/token-sdk/Cargo.toml index 9da468d082..1d673711ee 100644 --- a/sdk-libs/token-sdk/Cargo.toml +++ b/sdk-libs/token-sdk/Cargo.toml @@ -8,26 +8,29 @@ repository = "https://github.com/Lightprotocol/light-protocol" [features] default = ["anchor-discriminator"] -v1 = [] -anchor-discriminator = ["light-sdk/anchor-discriminator"] -anchor = ["anchor-lang", "light-token-types/anchor", "light-token-interface/anchor", "dep:light-sdk-macros"] +v1 = ["light-compressed-token-sdk/v1"] +anchor-discriminator = ["light-sdk/anchor-discriminator", "light-compressed-token-sdk/anchor-discriminator"] +anchor = ["anchor-lang", "light-token-types/anchor", "light-token-interface/anchor", "light-compressed-token-sdk/anchor", "dep:light-sdk-macros"] # idl-build feature enables IDL generation for client-side tooling and SDK generation -idl-build = ["anchor", "anchor-lang/idl-build", "light-sdk/idl-build"] -cpi-context = ["light-sdk/cpi-context"] +idl-build = ["anchor", "anchor-lang/idl-build", "light-sdk/idl-build", "light-compressed-token-sdk/idl-build"] +cpi-context = ["light-sdk/cpi-context", "light-compressed-token-sdk/cpi-context"] profile-program = [ "light-program-profiler/profile-program", "light-compressed-account/profile-program", "light-token-interface/profile-program", + "light-compressed-token-sdk/profile-program", ] profile-heap = [ "light-program-profiler/profile-heap", "light-compressed-account/profile-heap", "light-token-interface/profile-heap", + "light-compressed-token-sdk/profile-heap", ] [dependencies] # Light Protocol dependencies +light-compressed-token-sdk = { workspace = true } light-token-types = { workspace = true } light-compressed-account = { workspace = true, features = ["std", "solana"] } light-compressible = { workspace = true } diff --git a/sdk-libs/token-sdk/src/compressible/decompress_runtime.rs b/sdk-libs/token-sdk/src/compressible/decompress_runtime.rs index c191e76d18..f4076029b0 100644 --- a/sdk-libs/token-sdk/src/compressible/decompress_runtime.rs +++ b/sdk-libs/token-sdk/src/compressible/decompress_runtime.rs @@ -1,5 +1,8 @@ //! Runtime helpers for token decompression. // Re-export TokenSeedProvider from sdk (canonical definition). +use light_compressed_token_sdk::compressed_token::decompress_full::{ + decompress_full_token_accounts_with_indices, DecompressFullIndices, +}; pub use light_sdk::interface::TokenSeedProvider; use light_sdk::{cpi::v2::CpiAccounts, instruction::ValidityProof}; use light_sdk_types::instruction::account_meta::CompressedAccountMetaNoLamportsNoAddress; @@ -53,9 +56,8 @@ where return Ok(()); } - let mut token_decompress_indices: Vec< - crate::compressed_token::decompress_full::DecompressFullIndices, - > = Vec::with_capacity(token_accounts.len()); + let mut token_decompress_indices: Vec = + Vec::with_capacity(token_accounts.len()); // Only program-owned tokens need signer seeds let mut token_signers_seed_groups: Vec>> = Vec::with_capacity(token_accounts.len()); let packed_accounts = post_system_accounts; @@ -175,7 +177,7 @@ where merkle_context: meta.tree_info.into(), root_index: meta.tree_info.root_index, }; - let decompress_index = crate::compressed_token::decompress_full::DecompressFullIndices { + let decompress_index = DecompressFullIndices { source, destination_index: owner_index, tlv: None, @@ -189,15 +191,14 @@ where return Ok(()); } - let ctoken_ix = - crate::compressed_token::decompress_full::decompress_full_token_accounts_with_indices( - *fee_payer.key, - proof, - cpi_context_pubkey, - &token_decompress_indices, - packed_accounts, - ) - .map_err(ProgramError::from)?; + let ctoken_ix = decompress_full_token_accounts_with_indices( + *fee_payer.key, + proof, + cpi_context_pubkey, + &token_decompress_indices, + packed_accounts, + ) + .map_err(ProgramError::from)?; // Build account infos for CPI. Must include all accounts needed by the transfer2 instruction: // - System accounts (light_system_program, registered_program_pda, etc.) diff --git a/sdk-libs/token-sdk/src/compressible/mod.rs b/sdk-libs/token-sdk/src/compressible/mod.rs index 1b22739596..91c97c24ca 100644 --- a/sdk-libs/token-sdk/src/compressible/mod.rs +++ b/sdk-libs/token-sdk/src/compressible/mod.rs @@ -3,3 +3,10 @@ mod decompress_runtime; pub use decompress_runtime::*; +use solana_account_info::AccountInfo; + +#[derive(Debug, Clone)] +pub struct AccountInfoToCompress<'info> { + pub account_info: AccountInfo<'info>, + pub signer_seeds: Vec>, +} diff --git a/sdk-libs/token-sdk/src/constants.rs b/sdk-libs/token-sdk/src/constants.rs index edb6ad980c..9502100777 100644 --- a/sdk-libs/token-sdk/src/constants.rs +++ b/sdk-libs/token-sdk/src/constants.rs @@ -1,22 +1,44 @@ -use solana_pubkey::Pubkey; - -pub const SPL_TOKEN_PROGRAM_ID: Pubkey = - Pubkey::new_from_array(light_token_types::SPL_TOKEN_PROGRAM_ID); - -pub const SPL_TOKEN_2022_PROGRAM_ID: Pubkey = - Pubkey::new_from_array(light_token_types::SPL_TOKEN_2022_PROGRAM_ID); - -pub const LIGHT_SYSTEM_PROGRAM_ID: Pubkey = - Pubkey::new_from_array(light_token_types::LIGHT_SYSTEM_PROGRAM_ID); - -pub const ACCOUNT_COMPRESSION_PROGRAM_ID: Pubkey = - Pubkey::new_from_array(light_token_types::ACCOUNT_COMPRESSION_PROGRAM_ID); - -pub const ACCOUNT_COMPRESSION_AUTHORITY_PDA: Pubkey = - Pubkey::new_from_array(light_token_types::ACCOUNT_COMPRESSION_AUTHORITY_PDA); - -pub const NOOP_PROGRAM_ID: Pubkey = Pubkey::new_from_array(light_token_types::NOOP_PROGRAM_ID); - -pub const CPI_AUTHORITY_PDA: Pubkey = Pubkey::new_from_array(light_token_types::CPI_AUTHORITY_PDA); - -pub const LIGHT_TOKEN_PROGRAM_ID: Pubkey = Pubkey::new_from_array(light_token_types::PROGRAM_ID); +//! Constants for Light Token SDK. +//! +//! Re-exports constants from `light_compressed_token_sdk::constants` and adds +//! Light Token specific constants. + +// Re-export all constants from compressed-token-sdk +pub use light_compressed_token_sdk::constants::*; +use light_compressible::config::CompressibleConfig; +use solana_pubkey::{pubkey, Pubkey}; + +/// CPI Authority PDA for the Compressed Token Program +pub const LIGHT_TOKEN_CPI_AUTHORITY: Pubkey = + pubkey!("GXtd2izAiMJPwMEjfgTRH3d7k9mjn4Jq3JrWFv9gySYy"); + +/// Returns the program ID for the Compressed Token Program +pub fn id() -> Pubkey { + LIGHT_TOKEN_PROGRAM_ID +} + +/// Return the cpi authority pda of the Compressed Token Program. +pub fn cpi_authority() -> Pubkey { + LIGHT_TOKEN_CPI_AUTHORITY +} + +/// Default compressible config PDA (V1) +pub const COMPRESSIBLE_CONFIG_V1: Pubkey = pubkey!("ACXg8a7VaqecBWrSbdu73W4Pg9gsqXJ3EXAqkHyhvVXg"); + +/// Default rent sponsor PDA (V1) +pub const RENT_SPONSOR_V1: Pubkey = pubkey!("r18WwUxfG8kQ69bQPAB2jV6zGNKy3GosFGctjQoV4ti"); + +/// Returns the default compressible config PDA. +pub fn config_pda() -> Pubkey { + CompressibleConfig::light_token_v1_config_pda() +} + +/// Returns the default rent sponsor PDA. +pub fn rent_sponsor_pda() -> Pubkey { + CompressibleConfig::light_token_v1_rent_sponsor_pda() +} + +/// Returns the compression authority PDA. +pub fn compression_authority_pda() -> Pubkey { + CompressibleConfig::light_token_v1_compression_authority_pda() +} diff --git a/sdk-libs/token-sdk/src/error.rs b/sdk-libs/token-sdk/src/error.rs index 39ad5a05b4..8c80160011 100644 --- a/sdk-libs/token-sdk/src/error.rs +++ b/sdk-libs/token-sdk/src/error.rs @@ -1,64 +1,28 @@ -use light_account_checks::AccountError; -use light_sdk::error::LightSdkError; -use light_sdk_types::error::LightSdkTypesError; -use light_token_interface::TokenError; -use light_token_types::error::LightTokenSdkTypeError; -use light_zero_copy::errors::ZeroCopyError; +//! Error types for light-token SDK. +//! +//! This module re-exports errors from light-compressed-token-sdk and defines +//! additional errors specific to high-level token operations. + +// Re-export base errors from compressed-token-sdk +pub use light_compressed_token_sdk::error::{Result, TokenSdkError}; use solana_program_error::ProgramError; use thiserror::Error; -pub type Result = std::result::Result; +/// Result type for light-token specific errors +pub type LightTokenResult = std::result::Result; +/// Errors specific to high-level token operations in light-token. +/// Error codes start at 17500 to avoid conflicts with TokenSdkError (17001-17033). #[derive(Debug, Error)] -pub enum TokenSdkError { - #[error("Insufficient balance")] - InsufficientBalance, - #[error("Serialization error")] - SerializationError, - #[error("CPI error: {0}")] - CpiError(String), - #[error("Cannot compress and decompress")] - CannotCompressAndDecompress, - #[error("Compression cannot be set twice")] - CompressionCannotBeSetTwice, - #[error("Inconsistent compress/decompress state")] - InconsistentCompressDecompressState, - #[error("Both compress and decompress specified")] - BothCompressAndDecompress, - #[error("Invalid compress/decompress amount")] - InvalidCompressDecompressAmount, - #[error("Ctoken::transfer, compress, or decompress cannot be used with fn transfer(), fn compress(), fn decompress()")] - MethodUsed, - #[error("DecompressedMintConfig is required for decompressed mints")] - DecompressedMintConfigRequired, - #[error("Invalid compress input owner")] - InvalidCompressInputOwner, - #[error("Account borrow failed")] - AccountBorrowFailed, - #[error("Invalid account data")] - InvalidAccountData, - #[error("Missing required CPI account")] - MissingCpiAccount, - #[error("Too many accounts")] - TooManyAccounts, - #[error("PackedAccount indices are not continuous")] - NonContinuousIndices, - #[error("PackedAccount index out of bounds")] - PackedAccountIndexOutOfBounds, - #[error("Cannot mint with decompressed mint in CPI write mode")] - CannotMintWithDecompressedInCpiWrite, - #[error("RentAuthorityIsNone")] - RentAuthorityIsNone, - #[error("Incomplete SPL interface")] - IncompleteSplInterface, - #[error("SPL interface required")] +pub enum LightTokenError { + #[error("SPL interface required for this operation")] SplInterfaceRequired, - #[error("Use regular SPL transfer")] + #[error("Incomplete SPL interface configuration")] + IncompleteSplInterface, + #[error("Use regular SPL transfer for this operation")] UseRegularSplTransfer, #[error("Cannot determine account type")] CannotDetermineAccountType, - #[error("MintActionMetaConfig::new_cpi_context requires cpi_context data")] - CpiContextRequired, #[error("Missing mint account")] MissingMintAccount, #[error("Missing SPL token program")] @@ -67,84 +31,34 @@ pub enum TokenSdkError { 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("Missing Compressible extension on Light Token account")] - MissingCompressibleExtension, - #[error("Invalid Token account data")] - InvalidTokenAccount, #[error("SPL token program mismatch between source and destination")] SplTokenProgramMismatch, - #[error(transparent)] - CompressedTokenTypes(#[from] LightTokenSdkTypeError), - #[error(transparent)] - TokenError(#[from] TokenError), - #[error(transparent)] - LightSdkError(#[from] LightSdkError), - #[error(transparent)] - LightSdkTypesError(#[from] LightSdkTypesError), - #[error(transparent)] - ZeroCopyError(#[from] ZeroCopyError), - #[error(transparent)] - AccountError(#[from] AccountError), -} -#[cfg(feature = "anchor")] -impl From for anchor_lang::prelude::ProgramError { - fn from(e: TokenSdkError) -> Self { - ProgramError::Custom(e.into()) - } + #[error("Invalid account data")] + InvalidAccountData, + #[error("Serialization error")] + SerializationError, } -#[cfg(not(feature = "anchor"))] -impl From for ProgramError { - fn from(e: TokenSdkError) -> Self { + +impl From for ProgramError { + fn from(e: LightTokenError) -> Self { ProgramError::Custom(e.into()) } } -impl From for u32 { - fn from(e: TokenSdkError) -> Self { +impl From for u32 { + fn from(e: LightTokenError) -> 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::MissingSplInterfacePda => 17027, - TokenSdkError::MissingSplInterfacePdaBump => 17028, - TokenSdkError::InvalidCpiContext => 17029, - TokenSdkError::NoInputAccounts => 17030, - TokenSdkError::MissingCompressibleExtension => 17031, - TokenSdkError::InvalidTokenAccount => 17032, - TokenSdkError::SplTokenProgramMismatch => 17033, - TokenSdkError::CompressedTokenTypes(e) => e.into(), - TokenSdkError::TokenError(e) => e.into(), - TokenSdkError::LightSdkTypesError(e) => e.into(), - TokenSdkError::LightSdkError(e) => e.into(), - TokenSdkError::ZeroCopyError(e) => e.into(), - TokenSdkError::AccountError(e) => e.into(), + LightTokenError::SplInterfaceRequired => 17500, + LightTokenError::IncompleteSplInterface => 17501, + LightTokenError::UseRegularSplTransfer => 17502, + LightTokenError::CannotDetermineAccountType => 17503, + LightTokenError::MissingMintAccount => 17504, + LightTokenError::MissingSplTokenProgram => 17505, + LightTokenError::MissingSplInterfacePda => 17506, + LightTokenError::MissingSplInterfacePdaBump => 17507, + LightTokenError::SplTokenProgramMismatch => 17508, + LightTokenError::InvalidAccountData => 17509, + LightTokenError::SerializationError => 17510, } } } diff --git a/sdk-libs/token-sdk/src/instruction/close.rs b/sdk-libs/token-sdk/src/instruction/close.rs index 347ad307c8..361e399302 100644 --- a/sdk-libs/token-sdk/src/instruction/close.rs +++ b/sdk-libs/token-sdk/src/instruction/close.rs @@ -4,7 +4,7 @@ use solana_instruction::{AccountMeta, Instruction}; use solana_program_error::ProgramError; use solana_pubkey::Pubkey; -use crate::instruction::RENT_SPONSOR; +use crate::constants::RENT_SPONSOR_V1 as RENT_SPONSOR; /// # Create a close ctoken account instruction: /// ```rust diff --git a/sdk-libs/token-sdk/src/instruction/compressible.rs b/sdk-libs/token-sdk/src/instruction/compressible.rs index 3fffd3b06f..033c19a893 100644 --- a/sdk-libs/token-sdk/src/instruction/compressible.rs +++ b/sdk-libs/token-sdk/src/instruction/compressible.rs @@ -2,7 +2,7 @@ use light_token_interface::{instructions::extensions::CompressToPubkey, state::T use solana_account_info::AccountInfo; use solana_pubkey::Pubkey; -use crate::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR}; +use crate::constants::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR_V1 as RENT_SPONSOR}; /// Parameters for creating compressible ctoken accounts. /// diff --git a/sdk-libs/token-sdk/src/instruction/create_associated_token_account.rs b/sdk-libs/token-sdk/src/instruction/create_associated_token_account.rs index c67954cdc2..437fe7b189 100644 --- a/sdk-libs/token-sdk/src/instruction/create_associated_token_account.rs +++ b/sdk-libs/token-sdk/src/instruction/create_associated_token_account.rs @@ -11,7 +11,7 @@ use solana_account_info::AccountInfo; use solana_instruction::Instruction; use solana_pubkey::Pubkey; -use crate::error::{Result, TokenSdkError}; +use crate::error::{LightTokenError, LightTokenResult}; /// Discriminators for create ATA instructions const CREATE_ATA_DISCRIMINATOR: u8 = 100; @@ -44,21 +44,21 @@ pub struct CreateCompressibleAssociatedTokenAccountInputs { /// Creates a compressible associated token account instruction (non-idempotent) pub fn create_compressible_associated_token_account( inputs: CreateCompressibleAssociatedTokenAccountInputs, -) -> Result { +) -> LightTokenResult { create_compressible_associated_token_account_with_mode::(inputs) } /// Creates a compressible associated token account instruction (idempotent) pub fn create_compressible_associated_token_account_idempotent( inputs: CreateCompressibleAssociatedTokenAccountInputs, -) -> Result { +) -> LightTokenResult { create_compressible_associated_token_account_with_mode::(inputs) } /// Creates a compressible associated token account instruction with compile-time idempotent mode pub fn create_compressible_associated_token_account_with_mode( inputs: CreateCompressibleAssociatedTokenAccountInputs, -) -> Result { +) -> LightTokenResult { let (ata_pubkey, bump) = derive_associated_token_account(&inputs.owner, &inputs.mint); create_compressible_associated_token_account_with_bump_and_mode::( inputs, ata_pubkey, bump, @@ -70,7 +70,7 @@ pub fn create_compressible_associated_token_account_with_bump( inputs: CreateCompressibleAssociatedTokenAccountInputs, ata_pubkey: Pubkey, bump: u8, -) -> Result { +) -> LightTokenResult { create_compressible_associated_token_account_with_bump_and_mode::( inputs, ata_pubkey, bump, ) @@ -81,7 +81,7 @@ pub fn create_compressible_associated_token_account_with_bump_and_mode Result { +) -> LightTokenResult { create_ata_instruction_unified::( inputs.payer, inputs.owner, @@ -103,7 +103,7 @@ pub fn create_associated_token_account( payer: Pubkey, owner: Pubkey, mint: Pubkey, -) -> Result { +) -> LightTokenResult { create_associated_token_account_with_mode::(payer, owner, mint) } @@ -112,7 +112,7 @@ pub fn create_associated_token_account_idempotent( payer: Pubkey, owner: Pubkey, mint: Pubkey, -) -> Result { +) -> LightTokenResult { create_associated_token_account_with_mode::(payer, owner, mint) } @@ -121,7 +121,7 @@ pub fn create_associated_token_account_with_mode( payer: Pubkey, owner: Pubkey, mint: Pubkey, -) -> Result { +) -> LightTokenResult { let (ata_pubkey, bump) = derive_associated_token_account(&owner, &mint); create_associated_token_account_with_bump_and_mode::( payer, owner, mint, ata_pubkey, bump, @@ -135,7 +135,7 @@ pub fn create_associated_token_account_with_bump( mint: Pubkey, ata_pubkey: Pubkey, bump: u8, -) -> Result { +) -> LightTokenResult { create_associated_token_account_with_bump_and_mode::( payer, owner, mint, ata_pubkey, bump, ) @@ -148,7 +148,7 @@ pub fn create_associated_token_account_with_bump_and_mode Result { +) -> LightTokenResult { create_ata_instruction_unified::(payer, owner, mint, ata_pubkey, bump, None) } @@ -160,7 +160,7 @@ fn create_ata_instruction_unified, Pubkey, Pubkey, TokenDataVersion)>, // (pre_pay_num_epochs, lamports_per_write, rent_sponsor, compressible_config_account, token_account_version) -) -> Result { +) -> LightTokenResult { // Select discriminator based on idempotent mode let discriminator = if IDEMPOTENT { CREATE_ATA_IDEMPOTENT_DISCRIMINATOR @@ -181,7 +181,7 @@ fn create_ata_instruction_unified (Pubkey /// Owner and mint are passed as account infos instead of instruction data pub fn create_compressible_associated_token_account2( inputs: CreateCompressibleAssociatedTokenAccountInputs, -) -> Result { +) -> LightTokenResult { create_compressible_associated_token_account2_with_mode::(inputs) } @@ -254,14 +254,14 @@ pub fn create_compressible_associated_token_account2( /// Owner and mint are passed as account infos instead of instruction data pub fn create_compressible_associated_token_account2_idempotent( inputs: CreateCompressibleAssociatedTokenAccountInputs, -) -> Result { +) -> LightTokenResult { create_compressible_associated_token_account2_with_mode::(inputs) } /// Creates a compressible associated token account instruction v2 with compile-time idempotent mode fn create_compressible_associated_token_account2_with_mode( inputs: CreateCompressibleAssociatedTokenAccountInputs, -) -> Result { +) -> LightTokenResult { let (ata_pubkey, bump) = derive_associated_token_account(&inputs.owner, &inputs.mint); create_compressible_associated_token_account2_with_bump_and_mode::( inputs, ata_pubkey, bump, @@ -273,7 +273,7 @@ fn create_compressible_associated_token_account2_with_bump_and_mode Result { +) -> LightTokenResult { create_ata2_instruction_unified::( inputs.payer, inputs.owner, @@ -296,7 +296,7 @@ pub fn create_associated_token_account2( payer: Pubkey, owner: Pubkey, mint: Pubkey, -) -> Result { +) -> LightTokenResult { create_associated_token_account2_with_mode::(payer, owner, mint) } @@ -306,7 +306,7 @@ pub fn create_associated_token_account2_idempotent( payer: Pubkey, owner: Pubkey, mint: Pubkey, -) -> Result { +) -> LightTokenResult { create_associated_token_account2_with_mode::(payer, owner, mint) } @@ -315,7 +315,7 @@ fn create_associated_token_account2_with_mode( payer: Pubkey, owner: Pubkey, mint: Pubkey, -) -> Result { +) -> LightTokenResult { let (ata_pubkey, bump) = derive_associated_token_account(&owner, &mint); create_associated_token_account2_with_bump_and_mode::( payer, owner, mint, ata_pubkey, bump, @@ -329,7 +329,7 @@ fn create_associated_token_account2_with_bump_and_mode( mint: Pubkey, ata_pubkey: Pubkey, bump: u8, -) -> Result { +) -> LightTokenResult { create_ata2_instruction_unified::(payer, owner, mint, ata_pubkey, bump, None) } @@ -342,7 +342,7 @@ fn create_ata2_instruction_unified, Pubkey, Pubkey, TokenDataVersion)>, -) -> Result { +) -> LightTokenResult { let discriminator = if IDEMPOTENT { CREATE_ATA2_IDEMPOTENT_DISCRIMINATOR } else { @@ -361,7 +361,7 @@ fn create_ata2_instruction_unified Self { - use crate::utils::TokenDefaultAccounts; + use light_compressed_token_sdk::utils::TokenDefaultAccounts; let defaults = TokenDefaultAccounts::default(); Self { light_system_program: defaults.light_system_program, @@ -214,53 +212,13 @@ impl Default for SystemAccounts { } } -/// Compressed Token Program ID: `cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m` -pub const LIGHT_TOKEN_PROGRAM_ID: Pubkey = pubkey!("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"); - -pub const LIGHT_TOKEN_CPI_AUTHORITY: Pubkey = - pubkey!("GXtd2izAiMJPwMEjfgTRH3d7k9mjn4Jq3JrWFv9gySYy"); - -pub const COMPRESSIBLE_CONFIG_V1: Pubkey = pubkey!("ACXg8a7VaqecBWrSbdu73W4Pg9gsqXJ3EXAqkHyhvVXg"); - -pub const RENT_SPONSOR: Pubkey = pubkey!("r18WwUxfG8kQ69bQPAB2jV6zGNKy3GosFGctjQoV4ti"); - -/// Returns the program ID for the Compressed Token Program -pub fn id() -> Pubkey { - LIGHT_TOKEN_PROGRAM_ID -} - -/// Return the cpi authority pda of the Compressed Token Program. -pub fn cpi_authority() -> Pubkey { - LIGHT_TOKEN_CPI_AUTHORITY -} - -pub fn get_spl_interface_pda_and_bump(mint: &Pubkey) -> (Pubkey, u8) { - Pubkey::find_program_address(&[POOL_SEED, mint.as_ref()], &LIGHT_TOKEN_PROGRAM_ID) -} - -/// Returns the associated token address for a given owner and mint. -pub fn get_associated_token_address(owner: &Pubkey, mint: &Pubkey) -> Pubkey { - get_associated_token_address_and_bump(owner, mint).0 -} - -/// Returns the associated token address and bump for a given owner and mint. -pub fn get_associated_token_address_and_bump(owner: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) { - Pubkey::find_program_address( - &[&owner.to_bytes(), &id().to_bytes(), &mint.to_bytes()], - &id(), - ) -} - -/// 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 -} - -pub fn compression_authority_pda() -> Pubkey { - CompressibleConfig::light_token_v1_compression_authority_pda() -} +// Re-export constants for backwards compatibility +pub use crate::{ + constants::{ + compression_authority_pda, config_pda, rent_sponsor_pda, COMPRESSIBLE_CONFIG_V1, + LIGHT_TOKEN_CPI_AUTHORITY, LIGHT_TOKEN_PROGRAM_ID, RENT_SPONSOR_V1 as RENT_SPONSOR, + }, + cpi_authority, id, + spl_interface::get_spl_interface_pda_and_bump, + utils::{get_associated_token_address, get_associated_token_address_and_bump}, +}; diff --git a/sdk-libs/token-sdk/src/instruction/transfer_from_spl.rs b/sdk-libs/token-sdk/src/instruction/transfer_from_spl.rs index 3391a28619..48c48b527c 100644 --- a/sdk-libs/token-sdk/src/instruction/transfer_from_spl.rs +++ b/sdk-libs/token-sdk/src/instruction/transfer_from_spl.rs @@ -1,4 +1,10 @@ use light_compressed_account::instruction_data::compressed_proof::ValidityProof; +use light_compressed_token_sdk::compressed_token::{ + transfer2::{ + create_transfer2_instruction, Transfer2AccountsMetaConfig, Transfer2Config, Transfer2Inputs, + }, + CTokenAccount2, +}; use light_token_interface::instructions::transfer2::{Compression, MultiTokenTransferOutputData}; use solana_account_info::AccountInfo; use solana_cpi::{invoke, invoke_signed}; @@ -6,13 +12,6 @@ use solana_instruction::{AccountMeta, Instruction}; use solana_program_error::ProgramError; use solana_pubkey::Pubkey; -use crate::compressed_token::{ - transfer2::{ - create_transfer2_instruction, Transfer2AccountsMetaConfig, Transfer2Config, Transfer2Inputs, - }, - CTokenAccount2, -}; - /// # Create a transfer SPL to cToken instruction /// ```rust /// # use solana_pubkey::Pubkey; diff --git a/sdk-libs/token-sdk/src/instruction/transfer_interface.rs b/sdk-libs/token-sdk/src/instruction/transfer_interface.rs index f019081c09..dabe1029a9 100644 --- a/sdk-libs/token-sdk/src/instruction/transfer_interface.rs +++ b/sdk-libs/token-sdk/src/instruction/transfer_interface.rs @@ -1,3 +1,4 @@ +use light_compressed_token_sdk::utils::is_light_token_owner; use solana_account_info::AccountInfo; use solana_instruction::{AccountMeta, Instruction}; use solana_program_error::ProgramError; @@ -6,7 +7,7 @@ use solana_pubkey::Pubkey; use super::{ transfer::Transfer, transfer_from_spl::TransferFromSpl, transfer_to_spl::TransferToSpl, }; -use crate::error::TokenSdkError; +use crate::error::LightTokenError; /// Internal enum to classify transfer types based on account owners. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -30,12 +31,10 @@ fn determine_transfer_type( source_owner: &Pubkey, destination_owner: &Pubkey, ) -> Result { - use crate::utils::is_light_token_owner; - let source_is_light = is_light_token_owner(source_owner) - .map_err(|_| ProgramError::Custom(TokenSdkError::CannotDetermineAccountType.into()))?; + .map_err(|_| ProgramError::Custom(LightTokenError::CannotDetermineAccountType.into()))?; let dest_is_light = is_light_token_owner(destination_owner) - .map_err(|_| ProgramError::Custom(TokenSdkError::CannotDetermineAccountType.into()))?; + .map_err(|_| ProgramError::Custom(LightTokenError::CannotDetermineAccountType.into()))?; match (source_is_light, dest_is_light) { (true, true) => Ok(TransferType::LightToLight), @@ -47,7 +46,7 @@ fn determine_transfer_type( Ok(TransferType::SplToSpl) } else { Err(ProgramError::Custom( - TokenSdkError::SplTokenProgramMismatch.into(), + LightTokenError::SplTokenProgramMismatch.into(), )) } } @@ -141,7 +140,7 @@ impl TransferInterface { TransferType::LightToSpl => { let spl = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(LightTokenError::SplInterfaceRequired.into()) })?; TransferToSpl { source: self.source, @@ -160,7 +159,7 @@ impl TransferInterface { TransferType::SplToLight => { let spl = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(LightTokenError::SplInterfaceRequired.into()) })?; TransferFromSpl { source_spl_token_account: self.source, @@ -179,7 +178,7 @@ impl TransferInterface { TransferType::SplToSpl => { let spl = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(LightTokenError::SplInterfaceRequired.into()) })?; // Build SPL transfer_checked instruction manually @@ -303,16 +302,16 @@ impl<'info> TransferInterfaceCpi<'info> { spl_interface_pda_bump: Option, ) -> Result { let mint = - mint.ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingMintAccount.into()))?; + mint.ok_or_else(|| ProgramError::Custom(LightTokenError::MissingMintAccount.into()))?; let spl_token_program = spl_token_program - .ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingSplTokenProgram.into()))?; + .ok_or_else(|| ProgramError::Custom(LightTokenError::MissingSplTokenProgram.into()))?; let spl_interface_pda = spl_interface_pda - .ok_or_else(|| ProgramError::Custom(TokenSdkError::MissingSplInterfacePda.into()))?; + .ok_or_else(|| ProgramError::Custom(LightTokenError::MissingSplInterfacePda.into()))?; let spl_interface_pda_bump = spl_interface_pda_bump.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::MissingSplInterfacePdaBump.into()) + ProgramError::Custom(LightTokenError::MissingSplInterfacePdaBump.into()) })?; self.spl_interface = Some(SplInterfaceCpi { @@ -351,7 +350,7 @@ impl<'info> TransferInterfaceCpi<'info> { TransferType::LightToSpl => { let config = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(LightTokenError::SplInterfaceRequired.into()) })?; let account_infos = [ self.compressed_token_program_authority, @@ -368,7 +367,7 @@ impl<'info> TransferInterfaceCpi<'info> { TransferType::SplToLight => { let config = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(LightTokenError::SplInterfaceRequired.into()) })?; let account_infos = [ self.compressed_token_program_authority, @@ -386,7 +385,7 @@ impl<'info> TransferInterfaceCpi<'info> { TransferType::SplToSpl => { let config = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(LightTokenError::SplInterfaceRequired.into()) })?; let account_infos = [ self.source_account, @@ -421,7 +420,7 @@ impl<'info> TransferInterfaceCpi<'info> { TransferType::LightToSpl => { let config = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(LightTokenError::SplInterfaceRequired.into()) })?; let account_infos = [ self.compressed_token_program_authority, @@ -438,7 +437,7 @@ impl<'info> TransferInterfaceCpi<'info> { TransferType::SplToLight => { let config = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(LightTokenError::SplInterfaceRequired.into()) })?; let account_infos = [ self.compressed_token_program_authority, @@ -456,7 +455,7 @@ impl<'info> TransferInterfaceCpi<'info> { TransferType::SplToSpl => { let config = self.spl_interface.ok_or_else(|| { - ProgramError::Custom(TokenSdkError::SplInterfaceRequired.into()) + ProgramError::Custom(LightTokenError::SplInterfaceRequired.into()) })?; let account_infos = [ self.source_account, diff --git a/sdk-libs/token-sdk/src/instruction/transfer_to_spl.rs b/sdk-libs/token-sdk/src/instruction/transfer_to_spl.rs index 961bb9c558..9ce9d445d7 100644 --- a/sdk-libs/token-sdk/src/instruction/transfer_to_spl.rs +++ b/sdk-libs/token-sdk/src/instruction/transfer_to_spl.rs @@ -1,4 +1,10 @@ use light_compressed_account::instruction_data::compressed_proof::ValidityProof; +use light_compressed_token_sdk::compressed_token::{ + transfer2::{ + create_transfer2_instruction, Transfer2AccountsMetaConfig, Transfer2Config, Transfer2Inputs, + }, + CTokenAccount2, +}; use light_program_profiler::profile; use light_token_interface::instructions::transfer2::{Compression, MultiTokenTransferOutputData}; use solana_account_info::AccountInfo; @@ -7,13 +13,6 @@ use solana_instruction::{AccountMeta, Instruction}; use solana_program_error::ProgramError; use solana_pubkey::Pubkey; -use crate::compressed_token::{ - transfer2::{ - create_transfer2_instruction, Transfer2AccountsMetaConfig, Transfer2Config, Transfer2Inputs, - }, - CTokenAccount2, -}; - /// # Create a transfer ctoken to SPL instruction: /// ```rust /// # use solana_pubkey::Pubkey; diff --git a/sdk-libs/token-sdk/src/lib.rs b/sdk-libs/token-sdk/src/lib.rs index dd21335bca..3360208e0e 100644 --- a/sdk-libs/token-sdk/src/lib.rs +++ b/sdk-libs/token-sdk/src/lib.rs @@ -59,12 +59,10 @@ #[cfg(feature = "anchor")] pub mod anchor; -pub mod compressed_token; pub mod compressible; -pub mod instruction; - pub mod constants; pub mod error; +pub mod instruction; pub mod pack; pub mod spl_interface; pub mod utils; @@ -74,6 +72,10 @@ pub mod utils; use anchor_lang::{AnchorDeserialize, AnchorSerialize}; #[cfg(not(feature = "anchor"))] use borsh::{BorshDeserialize as AnchorDeserialize, BorshSerialize as AnchorSerialize}; +// Re-export key constants and functions from constants module +pub use constants::{ + config_pda, cpi_authority, id, LIGHT_TOKEN_CPI_AUTHORITY, LIGHT_TOKEN_PROGRAM_ID, +}; pub use light_compressed_account::instruction_data::compressed_proof::{ CompressedProof, ValidityProof, }; @@ -81,4 +83,5 @@ pub use light_token_interface::{ instructions::extensions::{ExtensionInstructionData, TokenMetadataInstructionData}, state::AdditionalMetadata, }; +// Re-export pack::compat as the main compat module (has full type definitions including CTokenData, PackedCTokenData) pub use pack::compat; diff --git a/sdk-libs/token-sdk/src/pack.rs b/sdk-libs/token-sdk/src/pack.rs index 4577ddaf4b..990592b713 100644 --- a/sdk-libs/token-sdk/src/pack.rs +++ b/sdk-libs/token-sdk/src/pack.rs @@ -1,9 +1,6 @@ //! Pack implementation for TokenData types for c-tokens. use light_compressed_account::compressed_account::CompressedAccountWithMerkleContext; -use light_sdk::{ - instruction::PackedAccounts, - light_hasher::{sha256::Sha256BE, HasherError}, -}; +use light_sdk::{instruction::PackedAccounts, light_hasher::HasherError}; pub use light_token_interface::state::TokenData; use light_token_interface::state::TokenDataVersion; use solana_account_info::AccountInfo; @@ -28,73 +25,13 @@ pub trait Unpack { /// Solana-compatible token types using `solana_pubkey::Pubkey` pub mod compat { - use solana_pubkey::Pubkey; + // Re-export TokenData and AccountState from compressed-token-sdk for type compatibility + pub use light_compressed_token_sdk::compat::{ + AccountState, InputTokenDataCompressible, TokenData, + }; use super::*; - #[derive(Clone, Copy, Debug, PartialEq, Eq, AnchorDeserialize, AnchorSerialize, Default)] - #[repr(u8)] - pub enum AccountState { - #[default] - Initialized = 0, - Frozen = 1, - } - - impl From for light_token_interface::state::CompressedTokenAccountState { - fn from(state: AccountState) -> Self { - match state { - AccountState::Initialized => { - light_token_interface::state::CompressedTokenAccountState::Initialized - } - AccountState::Frozen => { - light_token_interface::state::CompressedTokenAccountState::Frozen - } - } - } - } - - impl TryFrom for AccountState { - type Error = ProgramError; - - fn try_from(value: u8) -> Result { - match value { - 0 => Ok(AccountState::Initialized), - 1 => Ok(AccountState::Frozen), - _ => Err(ProgramError::InvalidAccountData), - } - } - } - - /// TokenData using standard Solana pubkeys. - /// - /// For zero-copy operations, use `TokenData` from `light_token_interface`. - #[derive(Debug, PartialEq, Eq, AnchorDeserialize, AnchorSerialize, Clone, Default)] - pub struct TokenData { - /// The mint associated with this account - pub mint: Pubkey, - /// The owner of this account - pub owner: Pubkey, - /// The amount of tokens this account holds - pub amount: u64, - /// Optional delegate authorized to transfer tokens - pub delegate: Option, - /// The account's state - pub state: AccountState, - /// TLV extensions for compressed token accounts - pub tlv: Option>, - } - - impl TokenData { - /// TokenDataVersion 3 - /// CompressedAccount Discriminator `[0,0,0,0,0,0,0,4]` - #[inline(always)] - pub fn hash_sha_flat(&self) -> Result<[u8; 32], HasherError> { - use light_sdk::light_hasher::Hasher; - let bytes = self.try_to_vec().map_err(|_| HasherError::BorshError)?; - Sha256BE::hash(bytes.as_slice()) - } - } - /// TokenData with merkle context for verification #[derive(Debug, Clone, PartialEq)] pub struct TokenDataWithMerkleContext { @@ -116,37 +53,6 @@ pub mod compat { } } - impl From for light_token_interface::state::TokenData { - fn from(data: TokenData) -> Self { - use light_token_interface::state::CompressedTokenAccountState; - - Self { - mint: data.mint.to_bytes().into(), - owner: data.owner.to_bytes().into(), - amount: data.amount, - delegate: data.delegate.map(|d| d.to_bytes().into()), - state: match data.state { - AccountState::Initialized => CompressedTokenAccountState::Initialized as u8, - AccountState::Frozen => CompressedTokenAccountState::Frozen as u8, - }, - tlv: data.tlv, - } - } - } - - impl From for TokenData { - fn from(data: light_token_interface::state::TokenData) -> Self { - Self { - mint: Pubkey::new_from_array(data.mint.to_bytes()), - owner: Pubkey::new_from_array(data.owner.to_bytes()), - amount: data.amount, - delegate: data.delegate.map(|d| Pubkey::new_from_array(d.to_bytes())), - state: AccountState::try_from(data.state).unwrap_or(AccountState::Initialized), - tlv: data.tlv, - } - } - } - impl Pack for TokenData { type Packed = InputTokenDataCompressible; @@ -305,8 +211,6 @@ pub mod compat { } // TODO: remove aliases in separate PR - pub type InputTokenDataCompressible = - light_token_interface::instructions::transfer2::MultiTokenTransferOutputData; pub type CompressibleTokenDataWithVariant = CTokenDataWithVariant; pub type PackedCompressibleTokenDataWithVariant = PackedTokenDataWithVariant; pub type CTokenData = CTokenDataWithVariant; diff --git a/sdk-libs/token-sdk/src/spl_interface.rs b/sdk-libs/token-sdk/src/spl_interface.rs index 3f50eb671c..fc1c6a5db7 100644 --- a/sdk-libs/token-sdk/src/spl_interface.rs +++ b/sdk-libs/token-sdk/src/spl_interface.rs @@ -1,133 +1,15 @@ //! SPL interface PDA derivation utilities. //! -//! Re-exports from `light_token_interface` with convenience wrappers. +//! Re-exports from `light_compressed_token_sdk::spl_interface` with additional helpers. -use light_token_interface::{ - discriminator::{ADD_TOKEN_POOL, CREATE_TOKEN_POOL}, - CPI_AUTHORITY, LIGHT_TOKEN_PROGRAM_ID, -}; -// Re-export derivation functions from token-interface -pub use light_token_interface::{ - find_spl_interface_pda, find_spl_interface_pda_with_index, get_spl_interface_pda, - has_restricted_extensions, is_valid_spl_interface_pda, NUM_MAX_POOL_ACCOUNTS, -}; -use solana_instruction::{AccountMeta, Instruction}; +// Re-export everything from compressed-token-sdk spl_interface +pub use light_compressed_token_sdk::spl_interface::*; +use light_token_types::POOL_SEED; use solana_pubkey::Pubkey; -use crate::{AnchorDeserialize, AnchorSerialize}; +use crate::instruction::LIGHT_TOKEN_PROGRAM_ID; -#[derive(Debug, Clone, AnchorDeserialize, AnchorSerialize, PartialEq)] -pub struct SplInterfacePda { - pub pubkey: Pubkey, - pub bump: u8, - pub index: u8, -} - -/// Derive spl interface pda information for a given mint -pub fn derive_spl_interface_pda(mint: &Pubkey, index: u8, restricted: bool) -> SplInterfacePda { - let (pubkey, bump) = find_spl_interface_pda_with_index(mint, index, restricted); - SplInterfacePda { - pubkey, - bump, - index, - } -} - -/// # Create SPL interface PDA (token pool) instruction builder -/// -/// Creates or adds an spl interface pda for an SPL mint. -/// Spl interface pdas store spl tokens that are wrapped in ctoken or compressed token accounts. -/// -/// ```rust -/// # use solana_pubkey::Pubkey; -/// # use light_token::spl_interface::CreateSplInterfacePda; -/// # use light_token::constants::SPL_TOKEN_PROGRAM_ID; -/// # let fee_payer = Pubkey::new_unique(); -/// # let mint = Pubkey::new_unique(); -/// # let token_program = SPL_TOKEN_PROGRAM_ID; -/// // Create initial pool (index 0) -/// let instruction = CreateSplInterfacePda::new(fee_payer, mint, token_program, false) -/// .instruction(); -/// // Add additional pool (index 1) -/// let instruction = CreateSplInterfacePda::new_with_index(fee_payer, mint, token_program, 1, false) -/// .instruction(); -/// ``` -pub struct CreateSplInterfacePda { - pub fee_payer: Pubkey, - pub mint: Pubkey, - pub token_program: Pubkey, - pub spl_interface_pda: Pubkey, - pub existing_spl_interface_pda: Option, - pub index: u8, -} - -impl CreateSplInterfacePda { - /// Derives the spl interface pda for an SPL mint with index 0. - pub fn new(fee_payer: Pubkey, mint: Pubkey, token_program: Pubkey, restricted: bool) -> Self { - Self::new_with_index(fee_payer, mint, token_program, 0, restricted) - } - - /// Derives the spl interface pda for an SPL mint with a specific index. - /// For index 0, creates the initial pool. For index > 0, adds an additional pool. - pub fn new_with_index( - fee_payer: Pubkey, - mint: Pubkey, - token_program: Pubkey, - index: u8, - restricted: bool, - ) -> Self { - let (spl_interface_pda, _) = find_spl_interface_pda_with_index(&mint, index, restricted); - let existing_spl_interface_pda = if index > 0 { - let (existing_pda, _) = - find_spl_interface_pda_with_index(&mint, index.saturating_sub(1), restricted); - Some(existing_pda) - } else { - None - }; - Self { - fee_payer, - mint, - token_program, - spl_interface_pda, - existing_spl_interface_pda, - index, - } - } - - pub fn instruction(self) -> Instruction { - let cpi_authority = Pubkey::from(CPI_AUTHORITY); - - if self.index == 0 { - // CreateTokenPool instruction - Instruction { - program_id: Pubkey::from(LIGHT_TOKEN_PROGRAM_ID), - accounts: vec![ - AccountMeta::new(self.fee_payer, true), - AccountMeta::new(self.spl_interface_pda, false), - AccountMeta::new_readonly(Pubkey::default(), false), // system_program - AccountMeta::new(self.mint, false), - AccountMeta::new_readonly(self.token_program, false), - AccountMeta::new_readonly(cpi_authority, false), - ], - data: CREATE_TOKEN_POOL.to_vec(), - } - } else { - // AddTokenPool instruction - let mut data = ADD_TOKEN_POOL.to_vec(); - data.push(self.index); - Instruction { - program_id: Pubkey::from(LIGHT_TOKEN_PROGRAM_ID), - accounts: vec![ - AccountMeta::new(self.fee_payer, true), - AccountMeta::new(self.spl_interface_pda, false), - AccountMeta::new_readonly(self.existing_spl_interface_pda.unwrap(), false), - AccountMeta::new_readonly(Pubkey::default(), false), // system_program - AccountMeta::new(self.mint, false), - AccountMeta::new_readonly(self.token_program, false), - AccountMeta::new_readonly(cpi_authority, false), - ], - data, - } - } - } +/// Get the SPL interface PDA and bump for a given mint (index 0, non-restricted). +pub fn get_spl_interface_pda_and_bump(mint: &Pubkey) -> (Pubkey, u8) { + Pubkey::find_program_address(&[POOL_SEED, mint.as_ref()], &LIGHT_TOKEN_PROGRAM_ID) } diff --git a/sdk-libs/token-sdk/src/utils.rs b/sdk-libs/token-sdk/src/utils.rs index d72a28c00c..1df6ad6cde 100644 --- a/sdk-libs/token-sdk/src/utils.rs +++ b/sdk-libs/token-sdk/src/utils.rs @@ -1,15 +1,27 @@ //! Utility functions and default account configurations. -use light_sdk_types::LIGHT_TOKEN_PROGRAM_ID; -use light_token_interface::{ - instructions::transfer2::MultiInputTokenDataWithContext, state::Token, -}; +// Re-export TokenDefaultAccounts from compressed-token-sdk +pub use light_compressed_token_sdk::utils::TokenDefaultAccounts; +use light_token_interface::state::Token; use solana_account_info::AccountInfo; -use solana_instruction::AccountMeta; use solana_pubkey::Pubkey; -use crate::{error::TokenSdkError, AnchorDeserialize, AnchorSerialize}; +use crate::{constants::LIGHT_TOKEN_PROGRAM_ID as PROGRAM_ID, error::TokenSdkError}; +/// Returns the associated token address for a given owner and mint. +pub fn get_associated_token_address(owner: &Pubkey, mint: &Pubkey) -> Pubkey { + get_associated_token_address_and_bump(owner, mint).0 +} + +/// Returns the associated token address and bump for a given owner and mint. +pub fn get_associated_token_address_and_bump(owner: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) { + Pubkey::find_program_address( + &[&owner.to_bytes(), &PROGRAM_ID.to_bytes(), &mint.to_bytes()], + &PROGRAM_ID, + ) +} + +/// Get the token balance from a Light token account. pub fn get_token_account_balance(token_account_info: &AccountInfo) -> Result { let data = token_account_info .try_borrow_data() @@ -23,7 +35,7 @@ pub fn get_token_account_balance(token_account_info: &AccountInfo) -> Result Result { - let light_token_program_id = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program_id = PROGRAM_ID; if owner == &light_token_program_id { return Ok(true); @@ -47,61 +59,3 @@ pub fn is_light_token_owner(owner: &Pubkey) -> Result { pub fn is_token_account(account_info: &AccountInfo) -> Result { is_light_token_owner(account_info.owner) } - -pub const CLOSE_TOKEN_ACCOUNT_DISCRIMINATOR: u8 = 9; - -#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)] -pub struct PackedCompressedTokenDataWithContext { - pub mint: u8, - pub source_or_recipient_token_account: u8, - pub multi_input_token_data_with_context: MultiInputTokenDataWithContext, -} - -pub fn account_meta_from_account_info(account_info: &AccountInfo) -> AccountMeta { - AccountMeta { - pubkey: *account_info.key, - is_signer: account_info.is_signer, - is_writable: account_info.is_writable, - } -} - -#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)] -pub struct AccountInfoToCompress<'info> { - pub account_info: AccountInfo<'info>, - pub signer_seeds: Vec>, -} -use light_sdk::constants::REGISTERED_PROGRAM_PDA; -use light_token_types::{ - ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, CPI_AUTHORITY_PDA, - LIGHT_SYSTEM_PROGRAM_ID, NOOP_PROGRAM_ID, PROGRAM_ID as LIGHT_COMPRESSED_TOKEN_PROGRAM_ID, -}; - -/// Standard pubkeys for compressed token instructions -#[derive(Debug, Copy, Clone)] -pub struct TokenDefaultAccounts { - pub light_system_program: Pubkey, - pub registered_program_pda: Pubkey, - pub noop_program: Pubkey, - pub account_compression_authority: Pubkey, - pub account_compression_program: Pubkey, - pub self_program: Pubkey, - pub cpi_authority_pda: Pubkey, - pub system_program: Pubkey, - pub compressed_token_program: Pubkey, -} - -impl Default for TokenDefaultAccounts { - fn default() -> Self { - Self { - light_system_program: Pubkey::from(LIGHT_SYSTEM_PROGRAM_ID), - registered_program_pda: Pubkey::from(REGISTERED_PROGRAM_PDA), - noop_program: Pubkey::from(NOOP_PROGRAM_ID), - account_compression_authority: Pubkey::from(ACCOUNT_COMPRESSION_AUTHORITY_PDA), - account_compression_program: Pubkey::from(ACCOUNT_COMPRESSION_PROGRAM_ID), - self_program: Pubkey::from(LIGHT_COMPRESSED_TOKEN_PROGRAM_ID), - cpi_authority_pda: Pubkey::from(CPI_AUTHORITY_PDA), - system_program: Pubkey::default(), - compressed_token_program: Pubkey::from(LIGHT_TOKEN_PROGRAM_ID), - } - } -} diff --git a/sdk-libs/token-sdk/tests/account_metas_test.rs b/sdk-libs/token-sdk/tests/account_metas_test.rs index c01ce91e76..41a5cb61b0 100644 --- a/sdk-libs/token-sdk/tests/account_metas_test.rs +++ b/sdk-libs/token-sdk/tests/account_metas_test.rs @@ -1,7 +1,6 @@ #![cfg(feature = "v1")] use anchor_lang::ToAccountMetas; -use light_sdk::constants::REGISTERED_PROGRAM_PDA; -use light_token::{ +use light_compressed_token_sdk::{ compressed_token::{ batch_compress::{get_batch_compress_instruction_account_metas, BatchCompressMetaConfig}, transfer::account_metas::{ @@ -10,6 +9,7 @@ use light_token::{ }, utils::TokenDefaultAccounts, }; +use light_sdk::constants::REGISTERED_PROGRAM_PDA; use light_token_types::constants::{ ACCOUNT_COMPRESSION_PROGRAM_ID, CPI_AUTHORITY_PDA, LIGHT_SYSTEM_PROGRAM_ID, NOOP_PROGRAM_ID, PROGRAM_ID as LIGHT_TOKEN_PROGRAM_ID, diff --git a/sdk-libs/token-sdk/tests/mint_action_cpi_accounts_tests.rs b/sdk-libs/token-sdk/tests/mint_action_cpi_accounts_tests.rs index 655ba86c3e..48665a7269 100644 --- a/sdk-libs/token-sdk/tests/mint_action_cpi_accounts_tests.rs +++ b/sdk-libs/token-sdk/tests/mint_action_cpi_accounts_tests.rs @@ -1,13 +1,13 @@ #![cfg(test)] use light_account_checks::account_info::test_account_info::pinocchio::get_account_info; +use light_compressed_token_sdk::compressed_token::mint_action::{ + cpi_accounts::MintActionCpiAccountsConfig, MintActionCpiAccounts, +}; use light_sdk_types::{ ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, LIGHT_SYSTEM_PROGRAM_ID, REGISTERED_PROGRAM_PDA, }; -use light_token::compressed_token::mint_action::{ - cpi_accounts::MintActionCpiAccountsConfig, MintActionCpiAccounts, -}; use light_token_interface::LIGHT_TOKEN_PROGRAM_ID; use light_token_types::CPI_AUTHORITY_PDA; use pinocchio::account_info::AccountInfo; diff --git a/sdk-tests/csdk-anchor-full-derived-test-sdk/Cargo.toml b/sdk-tests/csdk-anchor-full-derived-test-sdk/Cargo.toml index 1a48fbd251..25dcb7f470 100644 --- a/sdk-tests/csdk-anchor-full-derived-test-sdk/Cargo.toml +++ b/sdk-tests/csdk-anchor-full-derived-test-sdk/Cargo.toml @@ -12,6 +12,7 @@ csdk-anchor-full-derived-test = { path = "../csdk-anchor-full-derived-test", fea light-client = { workspace = true, features = ["v2", "anchor"] } light-sdk = { workspace = true, features = ["anchor", "v2"] } light-token = { workspace = true, features = ["anchor"] } +light-compressed-token-sdk = { workspace = true, features = ["anchor"] } anchor-lang = { workspace = true } solana-pubkey = { workspace = true } diff --git a/sdk-tests/csdk-anchor-full-derived-test-sdk/src/lib.rs b/sdk-tests/csdk-anchor-full-derived-test-sdk/src/lib.rs index f7687db7b7..6966efb783 100644 --- a/sdk-tests/csdk-anchor-full-derived-test-sdk/src/lib.rs +++ b/sdk-tests/csdk-anchor-full-derived-test-sdk/src/lib.rs @@ -279,7 +279,7 @@ impl AmmSdk { pub fn derive_lp_mint_compressed_address(&self, address_tree: &Pubkey) -> Option<[u8; 32]> { self.lp_mint_signer.map(|signer| { - light_token::compressed_token::create_compressed_mint::derive_mint_compressed_address( + light_compressed_token_sdk::compressed_token::create_compressed_mint::derive_mint_compressed_address( &signer, address_tree, ) diff --git a/sdk-tests/csdk-anchor-full-derived-test/Cargo.toml b/sdk-tests/csdk-anchor-full-derived-test/Cargo.toml index f53cd9522b..a0752c4360 100644 --- a/sdk-tests/csdk-anchor-full-derived-test/Cargo.toml +++ b/sdk-tests/csdk-anchor-full-derived-test/Cargo.toml @@ -39,6 +39,7 @@ anchor-lang = { workspace = true, features = ["idl-build"] } light-anchor-spl = { workspace = true, features = ["metadata", "idl-build"] } light-token-interface = { workspace = true, features = ["anchor"] } light-token = { workspace = true, features = ["anchor"] } +light-compressed-token-sdk = { workspace = true, features = ["anchor"] } light-token-types = { workspace = true, features = ["anchor"] } light-compressible = { workspace = true, features = ["anchor"] } diff --git a/sdk-tests/csdk-anchor-full-derived-test/tests/amm_test.rs b/sdk-tests/csdk-anchor-full-derived-test/tests/amm_test.rs index 2b30510766..1ae4913fb1 100644 --- a/sdk-tests/csdk-anchor-full-derived-test/tests/amm_test.rs +++ b/sdk-tests/csdk-anchor-full-derived-test/tests/amm_test.rs @@ -524,7 +524,7 @@ async fn test_amm_full_lifecycle() { &ctx.program_id.to_bytes(), ); let mint_compressed_address = - light_token::compressed_token::create_compressed_mint::derive_mint_compressed_address( + light_compressed_token_sdk::compressed_token::create_compressed_mint::derive_mint_compressed_address( &pdas.lp_mint_signer, &address_tree_pubkey, ); 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 8f1b1dde98..640d05e838 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 @@ -162,7 +162,7 @@ async fn test_create_pdas_and_mint_auto() { &program_id.to_bytes(), ); let mint_compressed_address = - light_token::compressed_token::create_compressed_mint::derive_mint_compressed_address( + light_compressed_token_sdk::compressed_token::create_compressed_mint::derive_mint_compressed_address( &mint_signer_pda, &address_tree_pubkey, ); @@ -661,7 +661,7 @@ async fn test_create_two_mints() { let address_tree_pubkey = rpc.get_address_tree_v2().tree; let mint_a_compressed_address = - light_token::compressed_token::create_compressed_mint::derive_mint_compressed_address( + light_compressed_token_sdk::compressed_token::create_compressed_mint::derive_mint_compressed_address( &mint_signer_a_pda, &address_tree_pubkey, ); @@ -678,7 +678,7 @@ async fn test_create_two_mints() { ); let mint_b_compressed_address = - light_token::compressed_token::create_compressed_mint::derive_mint_compressed_address( + light_compressed_token_sdk::compressed_token::create_compressed_mint::derive_mint_compressed_address( &mint_signer_b_pda, &address_tree_pubkey, ); diff --git a/sdk-tests/csdk-anchor-full-derived-test/tests/mint/metadata_test.rs b/sdk-tests/csdk-anchor-full-derived-test/tests/mint/metadata_test.rs index 938500f4bb..dceb3f622a 100644 --- a/sdk-tests/csdk-anchor-full-derived-test/tests/mint/metadata_test.rs +++ b/sdk-tests/csdk-anchor-full-derived-test/tests/mint/metadata_test.rs @@ -194,7 +194,7 @@ async fn test_create_mint_with_metadata() { use light_token_interface::MINT_ADDRESS_TREE; let mint_address_tree = solana_pubkey::Pubkey::new_from_array(MINT_ADDRESS_TREE); let mint_compressed_address = - light_token::compressed_token::create_compressed_mint::derive_mint_compressed_address( + light_compressed_token_sdk::compressed_token::create_compressed_mint::derive_mint_compressed_address( &mint_signer_pda, &mint_address_tree, ); diff --git a/sdk-tests/sdk-light-token-test/Cargo.toml b/sdk-tests/sdk-light-token-test/Cargo.toml index 3b1fb24084..6a205eb6f0 100644 --- a/sdk-tests/sdk-light-token-test/Cargo.toml +++ b/sdk-tests/sdk-light-token-test/Cargo.toml @@ -21,7 +21,6 @@ light-token = { workspace = true } light-token-types = { workspace = true } light-token-interface = { workspace = true } light-sdk = { workspace = true, features = ["v2"] } -light-sdk-types = { workspace = true } light-client = { workspace = true, optional = true } # Solana dependencies diff --git a/sdk-tests/sdk-light-token-test/tests/test_approve_revoke.rs b/sdk-tests/sdk-light-token-test/tests/test_approve_revoke.rs index af47d5cac2..5352347717 100644 --- a/sdk-tests/sdk-light-token-test/tests/test_approve_revoke.rs +++ b/sdk-tests/sdk-light-token-test/tests/test_approve_revoke.rs @@ -5,7 +5,7 @@ mod shared; use borsh::{BorshDeserialize, BorshSerialize}; use light_client::rpc::Rpc; use light_program_test::{LightProgramTest, ProgramTestConfig}; -use light_sdk_types::LIGHT_TOKEN_PROGRAM_ID; +use light_token::LIGHT_TOKEN_PROGRAM_ID; use light_token_interface::state::Token; use native_ctoken_examples::{ApproveData, InstructionType, ID, TOKEN_ACCOUNT_SEED}; use shared::*; @@ -44,7 +44,7 @@ async fn test_approve_invoke() { }; approve_data.serialize(&mut instruction_data).unwrap(); - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; let instruction = Instruction { program_id: ID, accounts: vec![ @@ -102,7 +102,7 @@ async fn test_approve_invoke_signed() { }; approve_data.serialize(&mut instruction_data).unwrap(); - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; let instruction = Instruction { program_id: ID, accounts: vec![ @@ -155,7 +155,7 @@ async fn test_revoke_invoke() { let ata = ata_pubkeys[0]; let delegate = Keypair::new(); let approve_amount = 100u64; - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; // First approve a delegate let mut approve_instruction_data = vec![InstructionType::ApproveInvoke as u8]; @@ -240,7 +240,7 @@ async fn test_revoke_invoke_signed() { let ata = ata_pubkeys[0]; let delegate = Keypair::new(); let approve_amount = 100u64; - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; // First approve a delegate using invoke_signed let mut approve_instruction_data = vec![InstructionType::ApproveInvokeSigned as u8]; diff --git a/sdk-tests/sdk-light-token-test/tests/test_burn.rs b/sdk-tests/sdk-light-token-test/tests/test_burn.rs index af5fc2a1e7..d80e5d02da 100644 --- a/sdk-tests/sdk-light-token-test/tests/test_burn.rs +++ b/sdk-tests/sdk-light-token-test/tests/test_burn.rs @@ -5,7 +5,7 @@ mod shared; use borsh::{BorshDeserialize, BorshSerialize}; use light_client::rpc::Rpc; use light_program_test::{LightProgramTest, ProgramTestConfig}; -use light_sdk_types::LIGHT_TOKEN_PROGRAM_ID; +use light_token::LIGHT_TOKEN_PROGRAM_ID; use light_token_interface::state::Token; use native_ctoken_examples::{BurnData, InstructionType, ID, TOKEN_ACCOUNT_SEED}; use shared::*; @@ -47,7 +47,7 @@ async fn test_burn_invoke() { }; burn_data.serialize(&mut instruction_data).unwrap(); - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; let instruction = Instruction { program_id: ID, accounts: vec![ @@ -113,7 +113,7 @@ async fn test_burn_invoke_signed() { }; burn_data.serialize(&mut instruction_data).unwrap(); - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; let instruction = Instruction { program_id: ID, accounts: vec![ diff --git a/sdk-tests/sdk-light-token-test/tests/test_create_mint.rs b/sdk-tests/sdk-light-token-test/tests/test_create_mint.rs index ef1d864935..194cbddf0b 100644 --- a/sdk-tests/sdk-light-token-test/tests/test_create_mint.rs +++ b/sdk-tests/sdk-light-token-test/tests/test_create_mint.rs @@ -6,8 +6,8 @@ use borsh::BorshSerialize; use light_client::{indexer::Indexer, rpc::Rpc}; use light_program_test::{LightProgramTest, ProgramTestConfig}; use light_token::{ - compressed_token::mint_action::MintActionMetaConfig, - instruction::{config_pda, rent_sponsor_pda}, + constants::{config_pda, rent_sponsor_pda}, + instruction::{CreateMint, CreateMintParams}, }; use light_token_interface::{ instructions::extensions::{ @@ -65,54 +65,74 @@ async fn test_create_compressed_mint() { .unwrap() .value; - // Create instruction data for wrapper program with TokenMetadata extension + // Build params for CreateMint (used for both instruction data and account metas) + let proof = rpc_result.proof.0.unwrap(); + let extensions = Some(vec![ExtensionInstructionData::TokenMetadata( + TokenMetadataInstructionData { + update_authority: Some(payer.pubkey().to_bytes().into()), + name: b"Test Token".to_vec(), + symbol: b"TEST".to_vec(), + uri: b"https://example.com/metadata.json".to_vec(), + additional_metadata: Some(vec![ + AdditionalMetadata { + key: b"test1".to_vec(), + value: b"value1".to_vec(), + }, + AdditionalMetadata { + key: b"test2".to_vec(), + value: b"value2".to_vec(), + }, + ]), + }, + )]); + + let create_mint_params = CreateMintParams { + decimals, + address_merkle_tree_root_index: rpc_result.addresses[0].root_index, + mint_authority, + proof, + compression_address, + mint: mint_pda, + bump: mint_bump, + freeze_authority: None, + extensions: extensions.clone(), + rent_payment: 16, + write_top_up: 766, + }; + + // Create instruction data for wrapper program let create_mint_data = CreateCmintData { decimals, address_merkle_tree_root_index: rpc_result.addresses[0].root_index, mint_authority, - proof: rpc_result.proof.0.unwrap(), + proof, compression_address, mint: mint_pda, bump: mint_bump, freeze_authority: None, - extensions: Some(vec![ExtensionInstructionData::TokenMetadata( - TokenMetadataInstructionData { - update_authority: Some(payer.pubkey().to_bytes().into()), - name: b"Test Token".to_vec(), - symbol: b"TEST".to_vec(), - uri: b"https://example.com/metadata.json".to_vec(), - additional_metadata: Some(vec![ - AdditionalMetadata { - key: b"test1".to_vec(), - value: b"value1".to_vec(), - }, - AdditionalMetadata { - key: b"test2".to_vec(), - value: b"value2".to_vec(), - }, - ]), - }, - )]), + extensions, rent_payment: 16, write_top_up: 766, }; let instruction_data = [vec![0u8], create_mint_data.try_to_vec().unwrap()].concat(); + // Use CreateMint builder to get the correct account metas + let create_mint_ix = CreateMint::new( + create_mint_params, + mint_signer.pubkey(), + payer.pubkey(), + address_tree.tree, + output_queue, + ) + .instruction() + .unwrap(); + // Add compressed token program as first account for CPI, then all SDK-generated accounts let mut wrapper_accounts = vec![AccountMeta::new_readonly( compressed_token_program_id, false, )]; - let account_metas = MintActionMetaConfig::new_create_mint( - payer.pubkey(), - mint_authority, - mint_signer.pubkey(), - address_tree.tree, - output_queue, - ) - .with_compressible_mint(mint_pda, config_pda(), rent_sponsor_pda()) - .to_account_metas(); - wrapper_accounts.extend(account_metas); + wrapper_accounts.extend(create_mint_ix.accounts); let instruction = Instruction { program_id: ID, diff --git a/sdk-tests/sdk-light-token-test/tests/test_ctoken_mint_to.rs b/sdk-tests/sdk-light-token-test/tests/test_ctoken_mint_to.rs index 68d3c57460..66ab66354e 100644 --- a/sdk-tests/sdk-light-token-test/tests/test_ctoken_mint_to.rs +++ b/sdk-tests/sdk-light-token-test/tests/test_ctoken_mint_to.rs @@ -5,7 +5,7 @@ mod shared; use borsh::{BorshDeserialize, BorshSerialize}; use light_client::rpc::Rpc; use light_program_test::{LightProgramTest, ProgramTestConfig}; -use light_sdk_types::LIGHT_TOKEN_PROGRAM_ID; +use light_token::LIGHT_TOKEN_PROGRAM_ID; use light_token_interface::state::Token; use native_ctoken_examples::{InstructionType, MintToData, ID, MINT_AUTHORITY_SEED}; use shared::*; @@ -47,7 +47,7 @@ async fn test_ctoken_mint_to_invoke() { }; mint_data.serialize(&mut instruction_data).unwrap(); - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; let system_program = Pubkey::default(); let instruction = Instruction { program_id: ID, @@ -222,7 +222,7 @@ async fn test_ctoken_mint_to_invoke_signed() { }; mint_data.serialize(&mut instruction_data).unwrap(); - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; let system_program = Pubkey::default(); let instruction = Instruction { program_id: ID, diff --git a/sdk-tests/sdk-light-token-test/tests/test_freeze_thaw.rs b/sdk-tests/sdk-light-token-test/tests/test_freeze_thaw.rs index 07c2a74539..9bd021a5f1 100644 --- a/sdk-tests/sdk-light-token-test/tests/test_freeze_thaw.rs +++ b/sdk-tests/sdk-light-token-test/tests/test_freeze_thaw.rs @@ -5,7 +5,7 @@ mod shared; use borsh::BorshDeserialize; use light_client::rpc::Rpc; use light_program_test::{LightProgramTest, ProgramTestConfig}; -use light_sdk_types::LIGHT_TOKEN_PROGRAM_ID; +use light_token::LIGHT_TOKEN_PROGRAM_ID; use light_token_interface::state::{AccountState, Token}; use native_ctoken_examples::{InstructionType, FREEZE_AUTHORITY_SEED, ID}; use shared::*; @@ -50,7 +50,7 @@ async fn test_freeze_invoke() { // Build freeze instruction via wrapper program let instruction_data = vec![InstructionType::FreezeInvoke as u8]; - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; let instruction = Instruction { program_id: ID, accounts: vec![ @@ -108,7 +108,7 @@ async fn test_freeze_invoke_signed() { // Build freeze instruction via wrapper program using invoke_signed let instruction_data = vec![InstructionType::FreezeInvokeSigned as u8]; - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; let instruction = Instruction { program_id: ID, accounts: vec![ @@ -144,7 +144,7 @@ async fn test_thaw_invoke() { let payer = rpc.get_payer().insecure_clone(); let freeze_authority = Keypair::new(); - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; // Create a compressed mint with freeze_authority and an ATA for the payer with 1000 tokens let (mint_pda, _compression_address, ata_pubkeys) = setup_create_mint_with_freeze_authority( @@ -230,7 +230,7 @@ async fn test_thaw_invoke_signed() { // Derive the PDA that will be the freeze authority let (pda_freeze_authority, _bump) = Pubkey::find_program_address(&[FREEZE_AUTHORITY_SEED], &ID); - let light_token_program = Pubkey::from(LIGHT_TOKEN_PROGRAM_ID); + let light_token_program = LIGHT_TOKEN_PROGRAM_ID; // Create a compressed mint with PDA freeze_authority and an ATA for the payer with 1000 tokens let (mint_pda, _compression_address, ata_pubkeys) = setup_create_mint_with_freeze_authority( diff --git a/sdk-tests/sdk-token-test/Cargo.toml b/sdk-tests/sdk-token-test/Cargo.toml index bd2c1c25e3..8e1b63b6a1 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-token = { workspace = true, features = ["anchor", "cpi-context", "v1"] } +light-compressed-token-sdk = { workspace = true, features = ["anchor", "cpi-context"] } light-token-types = { workspace = true } anchor-lang = { workspace = true } solana-pubkey = { workspace = true } diff --git a/sdk-tests/sdk-token-test/src/ctoken_pda/mint.rs b/sdk-tests/sdk-token-test/src/ctoken_pda/mint.rs index 4f1a73c257..8aaa117898 100644 --- a/sdk-tests/sdk-token-test/src/ctoken_pda/mint.rs +++ b/sdk-tests/sdk-token-test/src/ctoken_pda/mint.rs @@ -1,8 +1,8 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; -use light_sdk::cpi::v2::CpiAccounts; -use light_token::compressed_token::{ +use light_compressed_token_sdk::compressed_token::{ ctoken_instruction::CTokenInstruction, mint_action::MintActionCpiWriteAccounts, }; +use light_sdk::cpi::v2::CpiAccounts; use light_token_interface::instructions::mint_action::{ MintActionCompressedInstructionData, MintToCompressedAction, UpdateAuthority, }; diff --git a/sdk-tests/sdk-token-test/src/lib.rs b/sdk-tests/sdk-token-test/src/lib.rs index ca28952afb..e8203454cb 100644 --- a/sdk-tests/sdk-token-test/src/lib.rs +++ b/sdk-tests/sdk-token-test/src/lib.rs @@ -3,15 +3,13 @@ #![allow(deprecated)] use anchor_lang::prelude::*; +use light_compressed_token_sdk::compressed_token::{batch_compress::Recipient, TokenAccountMeta}; use light_instruction_decoder::instruction_decoder; use light_sdk::{ instruction::{PackedAddressTreeInfo, ValidityProof as LightValidityProof}, PackedAddressTreeInfoExt, }; -use light_token::{ - compressed_token::{batch_compress::Recipient, TokenAccountMeta}, - ValidityProof, -}; +use light_token::ValidityProof; mod ctoken_pda; pub mod mint_compressed_tokens_cpi_write; @@ -135,7 +133,9 @@ pub mod sdk_token_test { /// This decompresses the entire balance to destination ctoken accounts pub fn decompress_full_cpi<'info>( ctx: Context<'_, '_, '_, 'info, Generic<'info>>, - indices: Vec, + indices: Vec< + light_compressed_token_sdk::compressed_token::decompress_full::DecompressFullIndices, + >, validity_proof: light_token::ValidityProof, ) -> Result<()> { process_decompress_full_cpi_context(ctx, indices, validity_proof, None) @@ -145,7 +145,9 @@ pub mod sdk_token_test { /// This decompresses the entire balance to destination ctoken accounts pub fn decompress_full_cpi_with_cpi_context<'info>( ctx: Context<'_, '_, '_, 'info, Generic<'info>>, - indices: Vec, + indices: Vec< + light_compressed_token_sdk::compressed_token::decompress_full::DecompressFullIndices, + >, validity_proof: light_token::ValidityProof, params: Option, ) -> Result<()> { diff --git a/sdk-tests/sdk-token-test/src/mint_compressed_tokens_cpi_write.rs b/sdk-tests/sdk-token-test/src/mint_compressed_tokens_cpi_write.rs index 6063f536f4..4fda701bf4 100644 --- a/sdk-tests/sdk-token-test/src/mint_compressed_tokens_cpi_write.rs +++ b/sdk-tests/sdk-token-test/src/mint_compressed_tokens_cpi_write.rs @@ -1,5 +1,5 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; -use light_token::compressed_token::{ +use light_compressed_token_sdk::compressed_token::{ ctoken_instruction::CTokenInstruction, mint_action::MintActionCpiWriteAccounts, transfer2::Transfer2CpiAccounts, }; diff --git a/sdk-tests/sdk-token-test/src/pda_ctoken/mint.rs b/sdk-tests/sdk-token-test/src/pda_ctoken/mint.rs index 473ae6bfc8..77c7e1dd43 100644 --- a/sdk-tests/sdk-token-test/src/pda_ctoken/mint.rs +++ b/sdk-tests/sdk-token-test/src/pda_ctoken/mint.rs @@ -1,8 +1,8 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; -use light_sdk_types::cpi_accounts::v2::CpiAccounts; -use light_token::compressed_token::{ +use light_compressed_token_sdk::compressed_token::{ ctoken_instruction::CTokenInstruction, mint_action::MintActionCpiAccounts, }; +use light_sdk_types::cpi_accounts::v2::CpiAccounts; use light_token_interface::instructions::mint_action::{ MintActionCompressedInstructionData, MintToAction, MintToCompressedAction, UpdateAuthority, }; 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 8845f2c34d..33a27d0c38 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,5 +1,5 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; -use light_token::compressed_token::batch_compress::{ +use light_compressed_token_sdk::compressed_token::batch_compress::{ create_batch_compress_instruction, BatchCompressInputs, Recipient, }; use light_token_types::account_infos::BatchCompressAccountInfos; 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 faa82191cb..262a3782dd 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 @@ -1,15 +1,12 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; -use light_sdk_types::cpi_accounts::{v2::CpiAccounts, CpiAccountsConfig}; -use light_token::{ - compressed_token::{ - transfer2::{ - account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, - Transfer2Inputs, - }, - CTokenAccount2, +use light_compressed_token_sdk::compressed_token::{ + transfer2::{ + account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, Transfer2Inputs, }, - instruction::CloseAccount, + CTokenAccount2, }; +use light_sdk_types::cpi_accounts::{v2::CpiAccounts, CpiAccountsConfig}; +use light_token::instruction::CloseAccount; use crate::Generic; 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 430823da47..996d4a2fca 100644 --- a/sdk-tests/sdk-token-test/src/process_compress_tokens.rs +++ b/sdk-tests/sdk-token-test/src/process_compress_tokens.rs @@ -1,5 +1,5 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; -use light_token::compressed_token::transfer::{ +use light_compressed_token_sdk::compressed_token::transfer::{ instruction::{compress, CompressInputs}, TransferAccountInfos, }; 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 1df113b713..71d1ddd8ff 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,5 +1,9 @@ use anchor_lang::{prelude::*, solana_program::log::sol_log_compute_units}; use light_compressed_account::instruction_data::cpi_context::CompressedCpiContext; +use light_compressed_token_sdk::compressed_token::{ + transfer::instruction::{TransferConfig, TransferInputs}, + CTokenAccount, TokenAccountMeta, +}; use light_sdk::{ account::LightAccount, cpi::{ @@ -10,10 +14,6 @@ use light_sdk::{ light_account_checks::AccountInfoTrait, LightDiscriminator, LightHasher, }; -use light_token::compressed_token::{ - transfer::instruction::{TransferConfig, TransferInputs}, - CTokenAccount, TokenAccountMeta, -}; #[event] #[derive(Clone, Debug, Default, LightHasher, LightDiscriminator)] @@ -96,7 +96,10 @@ pub fn deposit_tokens<'a, 'info>( amount, }; let instruction = - light_token::compressed_token::transfer::instruction::transfer(transfer_inputs).unwrap(); + light_compressed_token_sdk::compressed_token::transfer::instruction::transfer( + transfer_inputs, + ) + .unwrap(); // msg!("instruction {:?}", instruction); // We can use the property that account infos don't have to be in order if you use // solana program invoke. diff --git a/sdk-tests/sdk-token-test/src/process_decompress_full_cpi_context.rs b/sdk-tests/sdk-token-test/src/process_decompress_full_cpi_context.rs index b909d0a85a..6d2bb9ee8f 100644 --- a/sdk-tests/sdk-token-test/src/process_decompress_full_cpi_context.rs +++ b/sdk-tests/sdk-token-test/src/process_decompress_full_cpi_context.rs @@ -1,5 +1,5 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; -use light_token::compressed_token::{ +use light_compressed_token_sdk::compressed_token::{ decompress_full::{decompress_full_token_accounts_with_indices, DecompressFullIndices}, transfer2::Transfer2CpiAccounts, }; 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 312733b76b..713020604a 100644 --- a/sdk-tests/sdk-token-test/src/process_decompress_tokens.rs +++ b/sdk-tests/sdk-token-test/src/process_decompress_tokens.rs @@ -1,14 +1,12 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; -use light_token::{ - compressed_token::{ - transfer::{ - instruction::{decompress, DecompressInputs}, - TransferAccountInfos, - }, - CTokenAccount, TokenAccountMeta, +use light_compressed_token_sdk::compressed_token::{ + transfer::{ + instruction::{decompress, DecompressInputs}, + TransferAccountInfos, }, - ValidityProof, + CTokenAccount, TokenAccountMeta, }; +use light_token::ValidityProof; use crate::Generic; 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 7098976100..bea2152dd4 100644 --- a/sdk-tests/sdk-token-test/src/process_four_invokes.rs +++ b/sdk-tests/sdk-token-test/src/process_four_invokes.rs @@ -1,14 +1,14 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; use light_compressed_account::instruction_data::cpi_context::CompressedCpiContext; +use light_compressed_token_sdk::compressed_token::{ + transfer::instruction::{compress, transfer, CompressInputs, TransferConfig, TransferInputs}, + CTokenAccount, TokenAccountMeta, +}; use light_sdk::{ cpi::v2::CpiAccounts, instruction::ValidityProof as LightValidityProof, light_account_checks::AccountInfoTrait, }; use light_sdk_types::cpi_accounts::CpiAccountsConfig; -use light_token::compressed_token::{ - transfer::instruction::{compress, transfer, CompressInputs, TransferConfig, TransferInputs}, - CTokenAccount, TokenAccountMeta, -}; use crate::{process_update_deposit::process_update_escrow_pda, PdaParams}; diff --git a/sdk-tests/sdk-token-test/src/process_four_transfer2.rs b/sdk-tests/sdk-token-test/src/process_four_transfer2.rs index 8fc5431eb7..ac799e4f85 100644 --- a/sdk-tests/sdk-token-test/src/process_four_transfer2.rs +++ b/sdk-tests/sdk-token-test/src/process_four_transfer2.rs @@ -1,4 +1,11 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; +use light_compressed_token_sdk::compressed_token::{ + transfer2::{ + account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, Transfer2Config, + Transfer2Inputs, + }, + CTokenAccount2, +}; use light_sdk::{ account::LightAccount, cpi::{v2::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction}, @@ -8,13 +15,6 @@ use light_sdk_types::{ cpi_accounts::{v2::CpiAccounts as CpiAccountsSmall, CpiAccountsConfig}, cpi_context_write::CpiContextWriteAccounts, }; -use light_token::compressed_token::{ - transfer2::{ - account_metas::Transfer2AccountsMetaConfig, create_transfer2_instruction, Transfer2Config, - Transfer2Inputs, - }, - CTokenAccount2, -}; use light_token_interface::instructions::transfer2::MultiInputTokenDataWithContext; use crate::{process_update_deposit::CompressedEscrowPda, PdaParams, LIGHT_CPI_SIGNER}; 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 e4f9c02eab..b1da90182f 100644 --- a/sdk-tests/sdk-token-test/src/process_transfer_tokens.rs +++ b/sdk-tests/sdk-token-test/src/process_transfer_tokens.rs @@ -1,14 +1,12 @@ use anchor_lang::{prelude::*, solana_program::program::invoke}; -use light_token::{ - compressed_token::{ - transfer::{ - instruction::{transfer, TransferInputs}, - TransferAccountInfos, - }, - CTokenAccount, TokenAccountMeta, +use light_compressed_token_sdk::compressed_token::{ + transfer::{ + instruction::{transfer, TransferInputs}, + TransferAccountInfos, }, - ValidityProof, + CTokenAccount, TokenAccountMeta, }; +use light_token::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 fb5b8048ff..72ccdc1dea 100644 --- a/sdk-tests/sdk-token-test/src/process_update_deposit.rs +++ b/sdk-tests/sdk-token-test/src/process_update_deposit.rs @@ -1,6 +1,10 @@ use anchor_lang::prelude::*; use light_batched_merkle_tree::queue::BatchedQueueAccount; use light_compressed_account::instruction_data::cpi_context::CompressedCpiContext; +use light_compressed_token_sdk::compressed_token::{ + transfer::instruction::{TransferConfig, TransferInputs}, + CTokenAccount, TokenAccountMeta, +}; use light_sdk::{ account::LightAccount, cpi::{ @@ -12,10 +16,6 @@ use light_sdk::{ LightDiscriminator, LightHasher, }; use light_sdk_types::cpi_accounts::CpiAccountsConfig; -use light_token::compressed_token::{ - transfer::instruction::{TransferConfig, TransferInputs}, - CTokenAccount, TokenAccountMeta, -}; use crate::{PdaParams, TokenParams}; @@ -105,7 +105,10 @@ fn merge_escrow_token_accounts<'info>( amount: total_escrowed_amount, }; let instruction = - light_token::compressed_token::transfer::instruction::transfer(transfer_inputs).unwrap(); + light_compressed_token_sdk::compressed_token::transfer::instruction::transfer( + transfer_inputs, + ) + .unwrap(); let account_infos = [&[fee_payer, authority][..], remaining_accounts].concat(); @@ -194,7 +197,10 @@ pub fn transfer_tokens_to_escrow_pda<'a, 'info>( amount, }; let instruction = - light_token::compressed_token::transfer::instruction::transfer(transfer_inputs).unwrap(); + light_compressed_token_sdk::compressed_token::transfer::instruction::transfer( + transfer_inputs, + ) + .unwrap(); let account_infos = [&[cpi_accounts.fee_payer().clone()][..], remaining_accounts].concat(); diff --git a/sdk-tests/sdk-token-test/tests/ctoken_pda.rs b/sdk-tests/sdk-token-test/tests/ctoken_pda.rs index 2dc4e717d1..69a344e04d 100644 --- a/sdk-tests/sdk-token-test/tests/ctoken_pda.rs +++ b/sdk-tests/sdk-token-test/tests/ctoken_pda.rs @@ -1,11 +1,11 @@ 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_program_test::{LightProgramTest, ProgramTestConfig, Rpc, RpcError}; -use light_sdk::instruction::{PackedAccounts, SystemAccountMetaConfig}; -use light_token::compressed_token::create_compressed_mint::{ +use light_compressed_token_sdk::compressed_token::create_compressed_mint::{ derive_mint_compressed_address, find_mint_address, }; +use light_program_test::{LightProgramTest, ProgramTestConfig, Rpc, RpcError}; +use light_sdk::instruction::{PackedAccounts, SystemAccountMetaConfig}; use light_token_interface::{ instructions::{ extensions::token_metadata::TokenMetadataInstructionData, 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 a7d5883a51..26f9563c18 100644 --- a/sdk-tests/sdk-token-test/tests/decompress_full_cpi.rs +++ b/sdk-tests/sdk-token-test/tests/decompress_full_cpi.rs @@ -4,12 +4,12 @@ use anchor_lang::{AnchorDeserialize, InstructionData}; /// Test input range for multi-input tests const TEST_INPUT_RANGE: [usize; 4] = [1, 2, 3, 4]; +use light_compressed_token_sdk::compressed_token::{ + create_compressed_mint::find_mint_address, decompress_full::DecompressFullAccounts, +}; use light_program_test::{Indexer, LightProgramTest, ProgramTestConfig, Rpc}; use light_sdk::instruction::PackedAccounts; use light_test_utils::airdrop_lamports; -use light_token::compressed_token::{ - create_compressed_mint::find_mint_address, decompress_full::DecompressFullAccounts, -}; use light_token_client::{actions::mint_action_comprehensive, instructions::mint_action::NewMint}; use light_token_interface::instructions::mint_action::{MintWithContext, Recipient}; use sdk_token_test::mint_compressed_tokens_cpi_write::MintCompressedTokensCpiWriteParams; @@ -240,7 +240,7 @@ async fn test_decompress_full_cpi() { .zip(ctx.destination_accounts.iter()) .zip(versions.iter()) .map(|(((token, tree_info), &dest_pubkey), &version)| { - light_token::compressed_token::decompress_full::pack_for_decompress_full( + light_compressed_token_sdk::compressed_token::decompress_full::pack_for_decompress_full( token, tree_info, dest_pubkey, @@ -350,7 +350,7 @@ async fn test_decompress_full_cpi_with_context() { let address_tree_info = rpc.get_address_tree_v2(); let compressed_mint_address = - light_token::compressed_token::create_compressed_mint::derive_mint_compressed_address( + light_compressed_token_sdk::compressed_token::create_compressed_mint::derive_mint_compressed_address( &ctx.mint_seed.pubkey(), &address_tree_info.tree, ); @@ -446,7 +446,7 @@ async fn test_decompress_full_cpi_with_context() { .zip(ctx.destination_accounts.iter()) .zip(versions.iter()) .map(|(((token, tree_info), &dest_pubkey), &version)| { - light_token::compressed_token::decompress_full::pack_for_decompress_full( + light_compressed_token_sdk::compressed_token::decompress_full::pack_for_decompress_full( token, tree_info, dest_pubkey, diff --git a/sdk-tests/sdk-token-test/tests/pda_ctoken.rs b/sdk-tests/sdk-token-test/tests/pda_ctoken.rs index e6abc50a64..4c19a08d88 100644 --- a/sdk-tests/sdk-token-test/tests/pda_ctoken.rs +++ b/sdk-tests/sdk-token-test/tests/pda_ctoken.rs @@ -4,11 +4,13 @@ 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_sdk::compressed_token::create_compressed_mint::{ + derive_mint_compressed_address, find_mint_address, +}; use light_program_test::{LightProgramTest, ProgramTestConfig, Rpc, RpcError}; use light_sdk::instruction::{PackedAccounts, SystemAccountMetaConfig}; -use light_token::{ - compressed_token::create_compressed_mint::{derive_mint_compressed_address, find_mint_address}, - instruction::{derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount}, +use light_token::instruction::{ + derive_token_ata, CompressibleParams, CreateAssociatedTokenAccount, }; use light_token_interface::{ instructions::{ diff --git a/sdk-tests/sdk-token-test/tests/test.rs b/sdk-tests/sdk-token-test/tests/test.rs index 3e85bdd929..c80fcc256b 100644 --- a/sdk-tests/sdk-token-test/tests/test.rs +++ b/sdk-tests/sdk-token-test/tests/test.rs @@ -3,13 +3,7 @@ use anchor_lang::{AccountDeserialize, InstructionData}; use anchor_spl::token::TokenAccount; use light_client::indexer::CompressedTokenAccount; -use light_program_test::{Indexer, LightProgramTest, ProgramTestConfig, Rpc}; -use light_sdk::instruction::PackedAccounts; -use light_test_utils::{ - spl::{create_mint_helper, create_token_account, mint_spl_tokens}, - RpcError, -}; -use light_token::{ +use light_compressed_token_sdk::{ compressed_token::{ batch_compress::{ get_batch_compress_instruction_account_metas, BatchCompressMetaConfig, Recipient, @@ -20,6 +14,12 @@ use light_token::{ }, spl_interface::{find_spl_interface_pda_with_index, get_spl_interface_pda}, }; +use light_program_test::{Indexer, LightProgramTest, ProgramTestConfig, Rpc}; +use light_sdk::instruction::PackedAccounts; +use light_test_utils::{ + spl::{create_mint_helper, create_token_account, mint_spl_tokens}, + RpcError, +}; use light_token_types::{TokenAccountMeta, SPL_TOKEN_PROGRAM_ID}; use solana_sdk::{ instruction::Instruction, 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 56a98cc3c8..9e70170056 100644 --- a/sdk-tests/sdk-token-test/tests/test_4_invocations.rs +++ b/sdk-tests/sdk-token-test/tests/test_4_invocations.rs @@ -1,4 +1,11 @@ use anchor_lang::{prelude::AccountMeta, AccountDeserialize, InstructionData}; +use light_compressed_token_sdk::{ + compressed_token::transfer::account_metas::{ + get_transfer_instruction_account_metas, TokenAccountsMetaConfig, + }, + spl_interface::get_spl_interface_pda, + utils::TokenDefaultAccounts, +}; use light_program_test::{AddressWithTree, Indexer, LightProgramTest, ProgramTestConfig, Rpc}; use light_sdk::{ address::v1::derive_address, @@ -8,17 +15,7 @@ use light_test_utils::{ spl::{create_mint_helper, create_token_account, mint_spl_tokens}, RpcError, }; -use light_token::{ - compressed_token::{ - transfer::account_metas::{ - get_transfer_instruction_account_metas, TokenAccountsMetaConfig, - }, - TokenAccountMeta, - }, - spl_interface::get_spl_interface_pda, - utils::TokenDefaultAccounts, -}; -use light_token_types::SPL_TOKEN_PROGRAM_ID; +use light_token_types::{TokenAccountMeta, SPL_TOKEN_PROGRAM_ID}; use solana_sdk::{ instruction::Instruction, pubkey::Pubkey, 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 98bf56287c..968107d32f 100644 --- a/sdk-tests/sdk-token-test/tests/test_4_transfer2.rs +++ b/sdk-tests/sdk-token-test/tests/test_4_transfer2.rs @@ -1,18 +1,18 @@ use anchor_lang::{prelude::AccountMeta, InstructionData}; -use light_program_test::{AddressWithTree, Indexer, LightProgramTest, ProgramTestConfig, Rpc}; -use light_sdk::{ - address::v1::derive_address, - instruction::{PackedAccounts, PackedStateTreeInfo, SystemAccountMetaConfig}, -}; -use light_test_utils::RpcError; -use light_token::{ +use light_compressed_token_sdk::{ compressed_token::{ create_compressed_mint::{create_compressed_mint, CreateMintInputs}, mint_to_compressed::{create_mint_to_compressed_instruction, MintToCompressedInputs}, }, - instruction::CreateAssociatedTokenAccount, utils::TokenDefaultAccounts, }; +use light_program_test::{AddressWithTree, Indexer, LightProgramTest, ProgramTestConfig, Rpc}; +use light_sdk::{ + address::v1::derive_address, + instruction::{PackedAccounts, PackedStateTreeInfo, SystemAccountMetaConfig}, +}; +use light_test_utils::RpcError; +use light_token::instruction::CreateAssociatedTokenAccount; use light_token_interface::{ instructions::{ mint_action::{MintWithContext, Recipient}, 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 7ef13f96d0..a97a3cddc8 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 @@ -2,17 +2,15 @@ use anchor_lang::{ prelude::{AccountMeta, Pubkey}, InstructionData, }; +use light_compressed_token_sdk::compressed_token::{ + create_compressed_mint::{create_compressed_mint, CreateMintInputs}, + mint_to_compressed::{create_mint_to_compressed_instruction, MintToCompressedInputs}, +}; use light_program_test::{Indexer, LightProgramTest, ProgramTestConfig, Rpc}; use light_sdk::instruction::{PackedAccounts, SystemAccountMetaConfig}; -use light_token::{ - compressed_token::{ - create_compressed_mint::{create_compressed_mint, CreateMintInputs}, - mint_to_compressed::{create_mint_to_compressed_instruction, MintToCompressedInputs}, - }, - instruction::{ - config_pda, derive_token_ata, rent_sponsor_pda, CompressibleParams, - CreateAssociatedTokenAccount, - }, +use light_token::instruction::{ + config_pda, derive_token_ata, rent_sponsor_pda, CompressibleParams, + CreateAssociatedTokenAccount, }; use light_token_client::instructions::transfer2::create_decompress_instruction; use light_token_interface::{ diff --git a/sdk-tests/sdk-token-test/tests/test_deposit.rs b/sdk-tests/sdk-token-test/tests/test_deposit.rs index 9e651975e4..9ebcbd8549 100644 --- a/sdk-tests/sdk-token-test/tests/test_deposit.rs +++ b/sdk-tests/sdk-token-test/tests/test_deposit.rs @@ -1,5 +1,12 @@ use anchor_lang::InstructionData; use light_client::indexer::{CompressedAccount, CompressedTokenAccount, IndexerRpcConfig}; +use light_compressed_token_sdk::{ + compressed_token::batch_compress::{ + get_batch_compress_instruction_account_metas, BatchCompressMetaConfig, Recipient, + }, + spl_interface::find_spl_interface_pda_with_index, + utils::TokenDefaultAccounts, +}; use light_program_test::{AddressWithTree, Indexer, LightProgramTest, ProgramTestConfig, Rpc}; use light_sdk::{ address::v1::derive_address, @@ -9,13 +16,6 @@ use light_test_utils::{ spl::{create_mint_helper, create_token_account, mint_spl_tokens}, RpcError, }; -use light_token::{ - compressed_token::batch_compress::{ - get_batch_compress_instruction_account_metas, BatchCompressMetaConfig, Recipient, - }, - spl_interface::find_spl_interface_pda_with_index, - utils::TokenDefaultAccounts, -}; use light_token_types::{TokenAccountMeta, SPL_TOKEN_PROGRAM_ID}; use solana_sdk::{ instruction::{AccountMeta, Instruction},