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