Skip to content

Commit 59b26c6

Browse files
authored
refactor: ctoken sdk (#2100)
* chore: add features to ctoken sdk, move forester instructions to forester utils * refactor: rename token pool -> spl interface pda * fix: ctoken sdk tests, light-sdk docs and activate light-sdk v2 feature by default
1 parent 3b811ef commit 59b26c6

45 files changed

Lines changed: 381 additions & 346 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/sdk-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
cargo test -p light-client
6565
cargo test -p light-sparse-merkle-tree
6666
cargo test -p light-compressed-token-types
67-
cargo test -p light-ctoken-sdk
67+
cargo test -p light-ctoken-sdk --all-features
6868
steps:
6969
- name: Checkout sources
7070
uses: actions/checkout@v4

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

forester-utils/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ light-client = { workspace = true }
3030
light-prover-client = { workspace = true }
3131
light-registry = { workspace = true, features = ["cpi"] }
3232
account-compression = { workspace = true, features = ["cpi"] }
33+
light-ctoken-interface = { workspace = true }
34+
35+
solana-instruction = { workspace = true }
36+
solana-pubkey = { workspace = true }
3337

3438
tokio = { workspace = true }
3539
futures = { workspace = true }
File renamed without changes.

forester-utils/src/instructions/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ pub mod address_batch_update;
22
pub mod create_account;
33

44
pub use create_account::create_account_instruction;
5+
6+
pub mod claim;
7+
pub mod withdraw_funding_pool;

sdk-libs/ctoken-sdk/src/compressible/withdraw_funding_pool.rs renamed to forester-utils/src/instructions/withdraw_funding_pool.rs

File renamed without changes.

program-tests/compressed-token-test/tests/transfer2/compress_spl_failing.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use light_ctoken_sdk::{
3838
CTokenAccount2,
3939
},
4040
ctoken::{derive_ctoken_ata, CreateAssociatedTokenAccount},
41-
token_pool::find_token_pool_pda_with_index,
41+
spl_interface::find_spl_interface_pda_with_index,
4242
ValidityProof,
4343
};
4444
use light_program_test::{utils::assert::assert_rpc_error, LightProgramTest, ProgramTestConfig};
@@ -190,10 +190,10 @@ fn create_spl_compression_inputs(
190190
// Add SPL token program (spl_token::ID is the owner of SPL token accounts)
191191
let _token_program_index = packed_tree_accounts.insert_or_get_read_only(spl_token::ID);
192192

193-
// Derive token pool PDA using SDK function
193+
// Derive SPL interface PDA using SDK function
194194
let pool_index = 0u8;
195-
let (token_pool_pda, bump) = find_token_pool_pda_with_index(&mint, pool_index);
196-
let pool_account_index = packed_tree_accounts.insert_or_get(token_pool_pda);
195+
let (spl_interface_pda, bump) = find_spl_interface_pda_with_index(&mint, pool_index);
196+
let pool_account_index = packed_tree_accounts.insert_or_get(spl_interface_pda);
197197

198198
// Compress from SPL token account
199199
token_account
@@ -454,7 +454,7 @@ async fn test_spl_compression_invalid_pool_bump() -> Result<(), RpcError> {
454454

455455
// Derive pool with correct seed but wrong bump
456456
let pool_index = 0u8;
457-
let (_, correct_bump) = find_token_pool_pda_with_index(&mint, pool_index);
457+
let (_, correct_bump) = find_spl_interface_pda_with_index(&mint, pool_index);
458458

459459
// Modify the bump in the compression data to an incorrect value
460460
if let Some(compression) = &mut compression_inputs.token_accounts[0].compression {
@@ -489,7 +489,7 @@ async fn test_spl_compression_invalid_pool_index() -> Result<(), RpcError> {
489489

490490
// Derive pool with index 1 instead of 0
491491
let wrong_pool_index = 1u8;
492-
let (wrong_pool_pda, wrong_bump) = find_token_pool_pda_with_index(&mint, wrong_pool_index);
492+
let (wrong_pool_pda, wrong_bump) = find_spl_interface_pda_with_index(&mint, wrong_pool_index);
493493

494494
// Update the compression data with wrong pool index
495495
if let Some(compression) = &mut compression_inputs.token_accounts[0].compression {

program-tests/compressed-token-test/tests/transfer2/spl_ctoken.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use light_ctoken_sdk::{
1111
},
1212
CTokenAccount2,
1313
},
14-
token_pool::find_token_pool_pda_with_index,
14+
spl_interface::find_spl_interface_pda_with_index,
1515
ValidityProof,
1616
};
1717
use light_program_test::utils::assert::assert_rpc_error;
@@ -289,7 +289,7 @@ async fn test_failing_ctoken_to_spl_with_compress_and_close() {
289289
// Now transfer back using CompressAndClose instead of regular transfer
290290
println!("Testing reverse transfer with CompressAndClose: ctoken to SPL");
291291

292-
let (token_pool_pda, token_pool_pda_bump) = find_token_pool_pda_with_index(&mint, 0);
292+
let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0);
293293

294294
let transfer_ix = CtokenToSplTransferAndClose {
295295
source_ctoken_account: associated_token_account,
@@ -298,8 +298,8 @@ async fn test_failing_ctoken_to_spl_with_compress_and_close() {
298298
authority: recipient.pubkey(),
299299
mint,
300300
payer: payer.pubkey(),
301-
token_pool_pda,
302-
token_pool_pda_bump,
301+
spl_interface_pda,
302+
spl_interface_pda_bump,
303303
spl_token_program: anchor_spl::token::ID,
304304
}
305305
.instruction()
@@ -319,8 +319,8 @@ pub struct CtokenToSplTransferAndClose {
319319
pub authority: Pubkey,
320320
pub mint: Pubkey,
321321
pub payer: Pubkey,
322-
pub token_pool_pda: Pubkey,
323-
pub token_pool_pda_bump: u8,
322+
pub spl_interface_pda: Pubkey,
323+
pub spl_interface_pda_bump: u8,
324324
pub spl_token_program: Pubkey,
325325
}
326326

@@ -335,8 +335,8 @@ impl CtokenToSplTransferAndClose {
335335
AccountMeta::new(self.destination_spl_token_account, false),
336336
// Authority (index 3) - signer
337337
AccountMeta::new(self.authority, true),
338-
// Token pool PDA (index 4) - writable
339-
AccountMeta::new(self.token_pool_pda, false),
338+
// SPL interface PDA (index 4) - writable
339+
AccountMeta::new(self.spl_interface_pda, false),
340340
// SPL Token program (index 5) - needed for CPI
341341
AccountMeta::new_readonly(self.spl_token_program, false),
342342
];
@@ -368,7 +368,7 @@ impl CtokenToSplTransferAndClose {
368368
2, // destination SPL token account index
369369
4, // pool_account_index
370370
0, // pool_index (TODO: make dynamic)
371-
self.token_pool_pda_bump,
371+
self.spl_interface_pda_bump,
372372
)),
373373
delegate_is_set: false,
374374
method_used: true,

sdk-libs/ctoken-sdk/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = { workspace = true }
55

66
[features]
7+
default = []
8+
v1 = []
9+
compressible = []
710

811
anchor = ["anchor-lang", "light-compressed-token-types/anchor", "light-ctoken-interface/anchor"]
912
cpi-context = ["light-sdk/cpi-context"]
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
//! Compressed token account types and instruction builders.
2+
3+
#[cfg(feature = "v1")]
14
mod v1;
25
mod v2;
36

47
pub mod ctoken_instruction;
58

6-
// Re-export everything from v1 and v2
9+
#[cfg(feature = "v1")]
710
pub use v1::*;
811
pub use v2::*;

0 commit comments

Comments
 (0)