Skip to content

Commit ff145bd

Browse files
authored
chore: light-ctoken-sdk small refactors and inline docs (#2102)
* stash docs * feat: ctoken-sdk lib.rs docs * feat: ctoken-sdk ctoken docs * refactor: rename CloseAccount -> CloseCTokenAccount * refactor: rename ctoken AccountInfos structs to Cpi suffix * refactor: light_ctoken_sdk::ctoken docs * 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 * docs: add rustdoc examples to ctoken CPI structs * refactor: clean up ctoken-sdk re-exports and fix import paths * refactor: rename token_pool_pda to spl_interface_pda, add constants re-exports * chore: rename TokenSdkError -> CTokenSdkError * cleanup * doc: compressible config * fix: naming inconsistency TransferCtoken -> TransferCToken * fix: feedback * refactor: rename CTOKEN_PROGRAM_ID -> COMPRESSED_TOKEN_PROGRAM_ID * fix: outdated comment
1 parent 59b26c6 commit ff145bd

133 files changed

Lines changed: 1297 additions & 866 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.

Cargo.lock

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

forester-utils/src/instructions/claim.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID;
1+
use light_ctoken_interface::CTOKEN_PROGRAM_ID;
22
use solana_instruction::{AccountMeta, Instruction};
33
use solana_pubkey::Pubkey;
44

@@ -13,7 +13,7 @@ use solana_pubkey::Pubkey;
1313
pub fn derive_pool_pda(compression_authority: &Pubkey) -> (Pubkey, u8) {
1414
Pubkey::find_program_address(
1515
&[b"pool", compression_authority.as_ref()],
16-
&Pubkey::from(COMPRESSED_TOKEN_PROGRAM_ID),
16+
&Pubkey::from(CTOKEN_PROGRAM_ID),
1717
)
1818
}
1919

@@ -49,7 +49,7 @@ pub fn claim(
4949
}
5050

5151
Instruction {
52-
program_id: Pubkey::from(COMPRESSED_TOKEN_PROGRAM_ID),
52+
program_id: Pubkey::from(CTOKEN_PROGRAM_ID),
5353
accounts,
5454
data: instruction_data,
5555
}

forester-utils/src/instructions/withdraw_funding_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID;
1+
use light_ctoken_interface::CTOKEN_PROGRAM_ID;
22
use solana_instruction::{AccountMeta, Instruction};
33
use solana_pubkey::Pubkey;
44

@@ -37,7 +37,7 @@ pub fn withdraw_funding_pool(
3737
];
3838

3939
Instruction {
40-
program_id: Pubkey::from(COMPRESSED_TOKEN_PROGRAM_ID),
40+
program_id: Pubkey::from(CTOKEN_PROGRAM_ID),
4141
accounts,
4242
data: instruction_data,
4343
}

forester/src/compressible/bootstrap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use base64::{engine::general_purpose, Engine as _};
44
use borsh::BorshDeserialize;
55
use light_ctoken_interface::{
66
state::{extensions::ExtensionStruct, CToken},
7-
COMPRESSED_TOKEN_PROGRAM_ID, COMPRESSIBLE_TOKEN_ACCOUNT_SIZE,
7+
COMPRESSIBLE_TOKEN_ACCOUNT_SIZE, CTOKEN_PROGRAM_ID,
88
};
99
use serde_json::json;
1010
use solana_sdk::pubkey::Pubkey;
@@ -191,7 +191,7 @@ async fn bootstrap_with_v2_api(
191191
mut shutdown_rx: oneshot::Receiver<()>,
192192
) -> Result<()> {
193193
let client = reqwest::Client::new();
194-
let program_id = Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID);
194+
let program_id = Pubkey::new_from_array(CTOKEN_PROGRAM_ID);
195195

196196
let mut total_fetched = 0;
197197
let mut total_inserted = 0;
@@ -314,7 +314,7 @@ async fn bootstrap_with_standard_api(
314314
mut shutdown_rx: oneshot::Receiver<()>,
315315
) -> Result<()> {
316316
let client = reqwest::Client::new();
317-
let program_id = Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID);
317+
let program_id = Pubkey::new_from_array(CTOKEN_PROGRAM_ID);
318318

319319
let payload = json!({
320320
"jsonrpc": "2.0",

forester/src/compressible/compressor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use anchor_lang::{InstructionData, ToAccountMetas};
44
use forester_utils::rpc_pool::SolanaRpcPool;
55
use light_client::rpc::Rpc;
66
use light_compressible::config::CompressibleConfig;
7-
use light_ctoken_interface::COMPRESSED_TOKEN_PROGRAM_ID;
7+
use light_ctoken_interface::CTOKEN_PROGRAM_ID;
88
use light_ctoken_sdk::compressed_token::compress_and_close::CompressAndCloseAccounts as CTokenAccounts;
99
use light_registry::{
1010
accounts::CompressAndCloseContext, compressible::compressed_token::CompressAndCloseIndices,
@@ -60,7 +60,7 @@ impl<R: Rpc> Compressor<R> {
6060
registered_forester_pda: Pubkey,
6161
) -> Result<Signature> {
6262
let registry_program_id = Pubkey::from_str(REGISTRY_PROGRAM_ID_STR)?;
63-
let compressed_token_program_id = Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID);
63+
let compressed_token_program_id = Pubkey::new_from_array(CTOKEN_PROGRAM_ID);
6464

6565
// Derive compression_authority PDA deterministically (version = 1)
6666
let compression_authority_seeds = CompressibleConfig::get_compression_authority_seeds(1);

forester/src/compressible/subscriber.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{str::FromStr, sync::Arc};
22

33
use futures::StreamExt;
4-
use light_ctoken_interface::{COMPRESSED_TOKEN_PROGRAM_ID, COMPRESSIBLE_TOKEN_ACCOUNT_SIZE};
4+
use light_ctoken_interface::{COMPRESSIBLE_TOKEN_ACCOUNT_SIZE, CTOKEN_PROGRAM_ID};
55
use solana_account_decoder::UiAccountEncoding;
66
use solana_client::{
77
nonblocking::pubsub_client::PubsubClient,
@@ -44,7 +44,7 @@ impl AccountSubscriber {
4444
.await
4545
.map_err(|e| anyhow::anyhow!("Failed to connect to WebSocket: {}", e))?;
4646

47-
let program_id = Pubkey::new_from_array(COMPRESSED_TOKEN_PROGRAM_ID);
47+
let program_id = Pubkey::new_from_array(CTOKEN_PROGRAM_ID);
4848

4949
// Subscribe to compressed token program accounts with filter for compressible account size
5050
let (mut subscription, unsubscribe) = pubsub_client

forester/tests/test_compressible_ctoken.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ async fn test_compressible_ctoken_compression() {
218218
// Create mint
219219
let mint_seed = Keypair::new();
220220
let address_tree = rpc.get_address_tree_v2().tree;
221-
let mint = Pubkey::from(create_compressed_mint::derive_compressed_mint_address(
221+
let mint = Pubkey::from(create_compressed_mint::derive_cmint_compressed_address(
222222
&mint_seed.pubkey(),
223223
&address_tree,
224224
));
@@ -369,7 +369,7 @@ async fn test_compressible_ctoken_bootstrap() {
369369
// Create mint
370370
let mint_seed = Keypair::new();
371371
let address_tree = rpc.get_address_tree_v2().tree;
372-
let mint = Pubkey::from(create_compressed_mint::derive_compressed_mint_address(
372+
let mint = Pubkey::from(create_compressed_mint::derive_cmint_compressed_address(
373373
&mint_seed.pubkey(),
374374
&address_tree,
375375
));

program-libs/ctoken-interface/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use light_macros::pubkey_array;
33
use crate::state::CompressionInfo;
44

55
pub const CPI_AUTHORITY: [u8; 32] = pubkey_array!("GXtd2izAiMJPwMEjfgTRH3d7k9mjn4Jq3JrWFv9gySYy");
6-
pub const COMPRESSED_TOKEN_PROGRAM_ID: [u8; 32] =
6+
pub const CTOKEN_PROGRAM_ID: [u8; 32] =
77
pubkey_array!("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m");
88

99
/// Account size constants

program-tests/compressed-token-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ light-ctoken-sdk = { workspace = true }
5050
spl-token-2022 = { workspace = true }
5151
spl-pod = { workspace = true }
5252
light-zero-copy = { workspace = true , features = ["std", "derive", "mut"]}
53+
light-compressed-token-types = { workspace = true }

program-tests/compressed-token-test/tests/ctoken/functional.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async fn test_spl_sdk_compatible_account_lifecycle() -> Result<(), RpcError> {
6565
let destination_pubkey = destination_keypair.pubkey();
6666

6767
// Close account using SPL SDK compatible instruction
68-
let close_account_ix = CloseAccount::new(
68+
let close_account_ix = CloseCTokenAccount::new(
6969
light_compressed_token::ID,
7070
token_account_pubkey,
7171
destination_pubkey,
@@ -272,7 +272,7 @@ async fn test_compressible_account_with_compression_authority_lifecycle() {
272272
.unwrap();
273273

274274
// Close compressible account using owner
275-
let close_account_ix = CloseAccount::new(
275+
let close_account_ix = CloseCTokenAccount::new(
276276
light_compressed_token::ID,
277277
token_account_pubkey,
278278
destination.pubkey(), // destination for user funds

0 commit comments

Comments
 (0)