diff --git a/blog/light-token.mdx b/blog/light-token.mdx index 8f7d81f..28c33d6 100644 --- a/blog/light-token.mdx +++ b/blog/light-token.mdx @@ -113,9 +113,8 @@ We have dedicated toolkits for specific use cases: - [Payments](/light-token/toolkits/for-payments) - [Wallets](/light-token/toolkits/for-wallets) -- [DEXs](/light-token/toolkits/for-dexs) -- [Launchpads](/light-token/toolkits/for-launchpads) -- [Trading Apps](/light-token/toolkits/for-trading-apps) +- [Streaming mints](/light-token/toolkits/for-streaming-mints) +- [Streaming tokens](/light-token/toolkits/for-streaming-tokens) Get in touch on telegram for help! diff --git a/cspell.json b/cspell.json index 4ea32a3..4e4f037 100644 --- a/cspell.json +++ b/cspell.json @@ -32,8 +32,8 @@ "Mintlify", "lightprotocol", "Lightprotocol", - "ctoken", - "ctokens", + "lighttoken", + "lighttokens", "cmint", "cmints", "spl", diff --git a/learn/light-token-standard.mdx b/learn/light-token-standard.mdx index ccf315e..3265c7c 100644 --- a/learn/light-token-standard.mdx +++ b/learn/light-token-standard.mdx @@ -93,7 +93,7 @@ Light-mints **uniquely represent a token on Solana and store its global metadata Find the [source code of light-mints - here](https://github.com/Lightprotocol/light-protocol/blob/main/program-libs/token-interface/src/state/mint/compressed_mint.rs). + here](https://github.com/Lightprotocol/light-protocol/blob/bda52c305fad28b1b72093911f878d37fb190656/program-libs/token-interface/src/state/mint/compressed_mint.rs#L19). The `metadata` field is used by the Compressed Token Program to store the internal state of a light-mint. @@ -208,8 +208,8 @@ Additionally Light Token is more compute-efficient than SPL on hot paths: ```rust - /// Ctoken account structure (with extensions). - pub struct CToken { + /// Token account structure (with extensions). + pub struct Token { pub mint: Pubkey, pub owner: Pubkey, pub amount: u64, @@ -226,7 +226,7 @@ Additionally Light Token is more compute-efficient than SPL on hot paths: Find the [source code of light-tokens - here](https://github.com/Lightprotocol/light-protocol/blob/main/program-libs/token-interface/src/state/token/token_struct.rs). + here](https://github.com/Lightprotocol/light-protocol/blob/bda52c305fad28b1b72093911f878d37fb190656/program-libs/token-interface/src/state/token/token_struct.rs#L34). Light token accounts replicate the field layout and serialization format of [SPL Token accounts](https://solana.com/docs/tokens#token-account). The struct is serialized with Borsh to match the on-chain format of SPL tokens. diff --git a/light-token/cookbook/close-token-account.mdx b/light-token/cookbook/close-token-account.mdx index 4d63c89..b5970ed 100644 --- a/light-token/cookbook/close-token-account.mdx +++ b/light-token/cookbook/close-token-account.mdx @@ -8,7 +8,7 @@ keywords: ["close token account on solana", "reclaim rent on solana"] --- import CloseAccountInfosAccountsList from "/snippets/accounts-list/close-account-infos-accounts-list.mdx"; -import CTokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; +import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; import ClientCustomRentConfig from "/snippets/light-token-guides/client-custom-rent-config.mdx"; 1. Closing a light-token account transfers remaining lamports to a destination account and the rent sponsor can reclaim sponsored rent. @@ -23,11 +23,11 @@ import ClientCustomRentConfig from "/snippets/light-token-guides/client-custom-r 1. The example creates a light-token account and mint. -2. Build the instruction with `CloseCTokenAccount`: +2. Build the instruction with `CloseTokenAccount`: ```rust -let close_instruction = CloseCTokenAccount::new( - CTOKEN_PROGRAM_ID, +let close_instruction = CloseTokenAccount::new( + LIGHT_TOKEN_PROGRAM_ID, account.pubkey(), payer.pubkey(), // Destination for remaining lamports owner, @@ -39,7 +39,7 @@ let close_instruction = CloseCTokenAccount::new( ### Prerequisites - + @@ -50,10 +50,10 @@ let close_instruction = CloseCTokenAccount::new( use borsh::BorshDeserialize; use light_client::indexer::{AddressWithTree, Indexer}; use light_client::rpc::{LightClient, LightClientConfig, Rpc}; -use light_ctoken_sdk::ctoken::{ - CloseCTokenAccount, CreateCMint, CreateCMintParams, CreateCTokenAccount, CTOKEN_PROGRAM_ID, +use light_token_sdk::token::{ + CloseTokenAccount, CreateCMint, CreateCMintParams, CreateTokenAccount, LIGHT_TOKEN_PROGRAM_ID, }; -use light_ctoken_interface::state::CToken; +use light_token_interface::state::Token; use serde_json; use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer}; use std::convert::TryFrom; @@ -61,7 +61,7 @@ use std::env; use std::fs; #[tokio::test(flavor = "multi_thread")] -async fn test_close_ctoken_account() { +async fn test_close_token_account() { dotenvy::dotenv().ok(); let keypair_path = env::var("KEYPAIR_PATH") @@ -82,12 +82,12 @@ async fn test_close_ctoken_account() { // Step 1: Create compressed mint (prerequisite) let (mint, _compression_address) = create_compressed_mint(&mut rpc, &payer, 9).await; - // Step 2: Create cToken account with 0 balance + // Step 2: Create token account with 0 balance let account = Keypair::new(); let owner = payer.pubkey(); let create_instruction = - CreateCTokenAccount::new(payer.pubkey(), account.pubkey(), mint, owner) + CreateTokenAccount::new(payer.pubkey(), account.pubkey(), mint, owner) .instruction() .unwrap(); @@ -102,13 +102,13 @@ async fn test_close_ctoken_account() { "Account should exist before closing" ); - let ctoken_state = - CToken::deserialize(&mut &account_before_close.unwrap().data[..]).unwrap(); - assert_eq!(ctoken_state.amount, 0, "Account balance must be 0 to close"); + let token_state = + Token::deserialize(&mut &account_before_close.unwrap().data[..]).unwrap(); + assert_eq!(token_state.amount, 0, "Account balance must be 0 to close"); // Step 4: Build close instruction using SDK builder - let close_instruction = CloseCTokenAccount::new( - CTOKEN_PROGRAM_ID, + let close_instruction = CloseTokenAccount::new( + LIGHT_TOKEN_PROGRAM_ID, account.pubkey(), payer.pubkey(), // Destination for remaining lamports owner, @@ -164,12 +164,12 @@ pub async fn create_compressed_mint( }; // Derive compression address - let compression_address = light_ctoken_sdk::ctoken::derive_cmint_compressed_address( + let compression_address = light_token_sdk::token::derive_cmint_compressed_address( &mint_signer.pubkey(), &address_tree.tree, ); - let mint_pda = light_ctoken_sdk::ctoken::find_cmint_address(&mint_signer.pubkey()).0; + let mint_pda = light_token_sdk::token::find_cmint_address(&mint_signer.pubkey()).0; // Get validity proof for the address let rpc_result = rpc @@ -248,9 +248,9 @@ Find [a full code example at the end](#full-code-example). ```rust -use light_ctoken_sdk::ctoken::CloseCTokenAccountCpi; +use light_token_sdk::token::CloseTokenAccountCpi; -CloseCTokenAccountCpi { +CloseTokenAccountCpi { token_program: token_program.clone(), account: account.clone(), destination: destination.clone(), @@ -264,9 +264,9 @@ CloseCTokenAccountCpi { ```rust -use light_ctoken_sdk::ctoken::CloseCTokenAccountCpi; +use light_token_sdk::token::CloseTokenAccountCpi; -let close_account_cpi = CloseCTokenAccountCpi { +let close_account_cpi = CloseTokenAccountCpi { token_program: token_program.clone(), account: account.clone(), destination: destination.clone(), @@ -292,11 +292,11 @@ close_account_cpi.invoke_signed(&[signer_seeds])?; Find the source code - [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-ctoken-test/src/close.rs). + [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-light-token-test/src/close.rs). ```rust expandable -use light_ctoken_sdk::ctoken::CloseCTokenAccountCpi; +use light_token_sdk::token::CloseTokenAccountCpi; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::{ID, TOKEN_ACCOUNT_SEED}; @@ -304,7 +304,7 @@ use crate::{ID, TOKEN_ACCOUNT_SEED}; /// Handler for closing a compressed token account (invoke) /// /// Account order: -/// - accounts[0]: token_program (ctoken program) +/// - accounts[0]: token_program (light token program) /// - accounts[1]: account to close (writable) /// - accounts[2]: destination for lamports (writable) /// - accounts[3]: owner/authority (signer) @@ -320,7 +320,7 @@ pub fn process_close_account_invoke(accounts: &[AccountInfo]) -> Result<(), Prog None }; - CloseCTokenAccountCpi { + CloseTokenAccountCpi { token_program: accounts[0].clone(), account: accounts[1].clone(), destination: accounts[2].clone(), @@ -335,7 +335,7 @@ pub fn process_close_account_invoke(accounts: &[AccountInfo]) -> Result<(), Prog /// Handler for closing a PDA-owned compressed token account (invoke_signed) /// /// Account order: -/// - accounts[0]: token_program (ctoken program) +/// - accounts[0]: token_program (light token program) /// - accounts[1]: account to close (writable) /// - accounts[2]: destination for lamports (writable) /// - accounts[3]: PDA owner/authority (not signer, program signs) @@ -360,7 +360,7 @@ pub fn process_close_account_invoke_signed(accounts: &[AccountInfo]) -> Result<( }; let signer_seeds: &[&[u8]] = &[TOKEN_ACCOUNT_SEED, &[bump]]; - CloseCTokenAccountCpi { + CloseTokenAccountCpi { token_program: accounts[0].clone(), account: accounts[1].clone(), destination: accounts[2].clone(), diff --git a/light-token/cookbook/create-ata.mdx b/light-token/cookbook/create-ata.mdx index cbee8da..26f46dc 100644 --- a/light-token/cookbook/create-ata.mdx +++ b/light-token/cookbook/create-ata.mdx @@ -7,13 +7,13 @@ keywords: ["associated token account on solana", "create ata for solana tokens", --- -import CTokenCreateATAAccountsList from "/snippets/accounts-list/light-token-create-ata-accounts-list.mdx"; +import TokenCreateATAAccountsList from "/snippets/accounts-list/light-token-create-ata-accounts-list.mdx"; import CompressibleVsSolanaRent from "/snippets/compressible-vs-solana-rent.mdx"; -import CTokenConfigureRent from "/snippets/light-token-configure-rent.mdx"; -import CAtaIntro from "/snippets/light-token-guides/cata-intro.mdx"; +import TokenConfigureRent from "/snippets/light-token-configure-rent.mdx"; +import AtaIntro from "/snippets/light-token-guides/cata-intro.mdx"; import CompressibleRentExplained from "/snippets/compressible-rent-explained.mdx"; -import CTokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; -import CTokenTsClientPrerequisites from "/snippets/light-token-guides/light-token-ts-client-prerequisites.mdx"; +import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; +import TokenTsClientPrerequisites from "/snippets/light-token-guides/light-token-ts-client-prerequisites.mdx"; import ClientCustomRentConfig from "/snippets/light-token-guides/client-custom-rent-config.mdx"; import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; import FullSetup from "/snippets/setup/full-setup.mdx"; @@ -81,12 +81,12 @@ Compare to SPL: 1. The example creates a test light-mint. You can use existing light-mints, SPL or Token 2022 mints as well. 2. Derive the address from mint and owner pubkey. -3. Build the instruction with `CreateAssociatedCTokenAccount`. It automatically includes the default rent config: +3. Build the instruction with `CreateAssociatedTokenAccount`. It automatically includes the default rent config: ```rust -use light_ctoken_sdk::ctoken::CreateAssociatedCTokenAccount; +use light_token_sdk::token::CreateAssociatedTokenAccount; -let instruction = CreateAssociatedCTokenAccount::new( +let instruction = CreateAssociatedTokenAccount::new( payer.pubkey(), owner, mint, @@ -101,7 +101,7 @@ let instruction = CreateAssociatedCTokenAccount::new( ### Prerequisites - + @@ -113,11 +113,11 @@ let instruction = CreateAssociatedCTokenAccount::new( use borsh::BorshDeserialize; use light_client::indexer::{AddressWithTree, Indexer}; use light_client::rpc::{LightClient, LightClientConfig, Rpc}; -use light_ctoken_sdk::ctoken::{ - derive_ctoken_ata, CreateAssociatedCTokenAccount, CreateCMint, +use light_token_sdk::token::{ + derive_token_ata, CreateAssociatedTokenAccount, CreateCMint, CreateCMintParams, }; -use light_ctoken_interface::state::CToken; +use light_token_interface::state::Token; use serde_json; use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer}; use std::convert::TryFrom; @@ -148,10 +148,10 @@ async fn test_create_associated_token_account() { // Step 2: Define owner and derive ATA address let owner = payer.pubkey(); - let (ata_address, _bump) = derive_ctoken_ata(&owner, &mint); + let (ata_address, _bump) = derive_token_ata(&owner, &mint); // Step 3: Build instruction using SDK builder - let instruction = CreateAssociatedCTokenAccount::new( + let instruction = CreateAssociatedTokenAccount::new( payer.pubkey(), owner, mint, @@ -166,11 +166,11 @@ async fn test_create_associated_token_account() { // Step 5: Verify light-ATA creation let account_data = rpc.get_account(ata_address).await.unwrap().unwrap(); - let ctoken_state = CToken::deserialize(&mut &account_data.data[..]).unwrap(); + let token_state = Token::deserialize(&mut &account_data.data[..]).unwrap(); - assert_eq!(ctoken_state.mint, mint.to_bytes(), "Mint should match"); - assert_eq!(ctoken_state.owner, owner.to_bytes(), "Owner should match"); - assert_eq!(ctoken_state.amount, 0, "Initial amount should be 0"); + assert_eq!(token_state.mint, mint.to_bytes(), "Mint should match"); + assert_eq!(token_state.owner, owner.to_bytes(), "Owner should match"); + assert_eq!(token_state.amount, 0, "Initial amount should be 0"); } pub async fn create_compressed_mint( @@ -207,13 +207,13 @@ pub async fn create_compressed_mint( }; // Derive compression address - let compression_address = light_ctoken_sdk::ctoken::derive_cmint_compressed_address( + let compression_address = light_token_sdk::token::derive_cmint_compressed_address( &mint_signer.pubkey(), &address_tree.tree, ); let mint_pda = - light_ctoken_sdk::ctoken::find_cmint_address(&mint_signer.pubkey()).0; + light_token_sdk::token::find_cmint_address(&mint_signer.pubkey()).0; // Get validity proof for the address let rpc_result = rpc @@ -285,7 +285,7 @@ Find [a full code example at the end](#full-code-example). ### Define Rent Config Accounts - + @@ -296,7 +296,7 @@ Find [a full code example at the end](#full-code-example). 1. Pass the required accounts that include the rent config. 2. Use `invoke` or `invoke_signed`, when a CPI requires a PDA signer. - The light-ATA address is derived from `[owner, ctoken_program_id, mint]`. + The light-ATA address is derived from `[owner, light_token_program_id, mint]`. Unlike light-token accounts, owner and mint are passed as accounts, not in instruction data. @@ -305,9 +305,9 @@ Find [a full code example at the end](#full-code-example). ```rust -use light_ctoken_sdk::ctoken::CreateAssociatedCTokenAccountCpi; +use light_token_sdk::token::CreateAssociatedTokenAccountCpi; -CreateAssociatedCTokenAccountCpi { +CreateAssociatedTokenAccountCpi { owner: owner.clone(), mint: mint.clone(), payer: payer.clone(), @@ -324,10 +324,10 @@ CreateAssociatedCTokenAccountCpi { ```rust -use light_ctoken_sdk::ctoken::CreateAssociatedCTokenAccountCpi; +use light_token_sdk::token::CreateAssociatedTokenAccountCpi; let signer_seeds: &[&[u8]] = &[ATA_SEED, &[bump]]; -CreateAssociatedCTokenAccountCpi { +CreateAssociatedTokenAccountCpi { owner: owner.clone(), mint: mint.clone(), payer: payer.clone(), @@ -342,7 +342,7 @@ CreateAssociatedCTokenAccountCpi { - + @@ -350,12 +350,12 @@ CreateAssociatedCTokenAccountCpi { Find the source code - [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-token-test/src/create_ata2.rs). + [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-light-token-test/src/create_ata.rs). ```rust expandable use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_sdk::ctoken::{CompressibleParamsCpi, CreateAssociatedCTokenAccountCpi}; +use light_token_sdk::token::{CompressibleParamsCpi, CreateAssociatedTokenAccountCpi}; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::{ATA_SEED, ID}; @@ -392,7 +392,7 @@ pub fn process_create_ata2_invoke( accounts[4].clone(), ); - CreateAssociatedCTokenAccountCpi { + CreateAssociatedTokenAccountCpi { owner: accounts[0].clone(), mint: accounts[1].clone(), payer: accounts[2].clone(), @@ -440,7 +440,7 @@ pub fn process_create_ata2_invoke_signed( ); let signer_seeds: &[&[u8]] = &[ATA_SEED, &[bump]]; - CreateAssociatedCTokenAccountCpi { + CreateAssociatedTokenAccountCpi { owner: accounts[0].clone(), mint: accounts[1].clone(), payer: accounts[2].clone(), // PDA diff --git a/light-token/cookbook/create-mint.mdx b/light-token/cookbook/create-mint.mdx index 0684f6a..3812a9b 100644 --- a/light-token/cookbook/create-mint.mdx +++ b/light-token/cookbook/create-mint.mdx @@ -8,8 +8,8 @@ keywords: ["create mint account on solana", "rent free mint on solana", "rent fr --- import CMintSystemAccountsList from "/snippets/accounts-list/light-mint-system-accounts-list.mdx"; -import CTokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; -import CTokenTsClientPrerequisites from "/snippets/light-token-guides/light-token-ts-client-prerequisites.mdx"; +import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; +import TokenTsClientPrerequisites from "/snippets/light-token-guides/light-token-ts-client-prerequisites.mdx"; import ClientCustomRentConfig from "/snippets/light-token-guides/client-custom-rent-config.mdx"; import FullSetup from "/snippets/setup/full-setup.mdx"; import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; @@ -32,7 +32,7 @@ import InstructionCode from "/snippets/code-snippets/light-token/create-mint/ins `createMintInterface` is a unified interface that dispatches to different mint creation paths based on programId: - `TOKEN_PROGRAM_ID` or `TOKEN_2022_PROGRAM_ID` → delegates to SPL or T22 `createMint` -- Otherwise it defaults to `CTOKEN_PROGRAM_ID` → creates a light-token mint +- Otherwise it defaults to `LIGHT_TOKEN_PROGRAM_ID` → creates a light-token mint You can use the same interface regardless of mint type. @@ -87,7 +87,7 @@ The example creates a light-mint with token metadata. 4. Build the instruction with `CreateCMint::new()` and send the transaction. ```rust -use light_ctoken_sdk::ctoken::CreateCMint; +use light_token_sdk::token::CreateCMint; let create_cmint = CreateCMint::new( params, @@ -103,7 +103,7 @@ let instruction = create_cmint.instruction()?; ### Prerequisites - + @@ -113,10 +113,10 @@ let instruction = create_cmint.instruction()?; ```rust use light_client::indexer::{AddressWithTree, Indexer}; use light_client::rpc::{LightClient, LightClientConfig, Rpc}; -use light_ctoken_sdk::ctoken::{CreateCMint, CreateCMintParams}; -use light_ctoken_interface::instructions::extensions::token_metadata::TokenMetadataInstructionData; -use light_ctoken_interface::instructions::extensions::ExtensionInstructionData; -use light_ctoken_interface::state::AdditionalMetadata; +use light_token_sdk::token::{CreateCMint, CreateCMintParams}; +use light_token_interface::instructions::extensions::token_metadata::TokenMetadataInstructionData; +use light_token_interface::instructions::extensions::ExtensionInstructionData; +use light_token_interface::state::AdditionalMetadata; use serde_json; use solana_sdk::{bs58, pubkey::Pubkey, signature::Keypair, signer::Signer}; use std::convert::TryFrom; @@ -189,12 +189,12 @@ pub async fn create_compressed_mint( }; // Derive compression address - let compression_address = light_ctoken_sdk::ctoken::derive_cmint_compressed_address( + let compression_address = light_token_sdk::token::derive_cmint_compressed_address( &mint_signer.pubkey(), &address_tree.tree, ); - let mint_pda = light_ctoken_sdk::ctoken::find_cmint_address(&mint_signer.pubkey()).0; + let mint_pda = light_token_sdk::token::find_cmint_address(&mint_signer.pubkey()).0; // Get validity proof for the address let rpc_result = rpc @@ -278,7 +278,7 @@ Find [a full code example at the end](#full-code-example). ### Configure Token Metadata ```rust -use light_ctoken_interface::{ +use light_token_interface::{ instructions::extensions::{ token_metadata::TokenMetadataInstructionData, ExtensionInstructionData, @@ -317,7 +317,7 @@ let token_metadata = ExtensionInstructionData::TokenMetadata( Set `decimals`, `mint_authority`, `freeze_authority`, and pass the `token_metadata` from the previous step. ```rust -use light_ctoken_sdk::ctoken::CreateCMintParams; +use light_token_sdk::token::CreateCMintParams; let params = CreateCMintParams { decimals: data.decimals, @@ -351,7 +351,7 @@ The client includes them in the instruction. ```rust -use light_ctoken_sdk::ctoken::SystemAccountInfos; +use light_token_sdk::token::SystemAccountInfos; let system_accounts = SystemAccountInfos { light_system_program: light_system_program.clone(), @@ -379,7 +379,7 @@ let system_accounts = SystemAccountInfos { ```rust -use light_ctoken_sdk::ctoken::CreateCMintCpi; +use light_token_sdk::token::CreateCMintCpi; CreateCMintCpi { mint_seed: mint_seed.clone(), @@ -400,7 +400,7 @@ CreateCMintCpi { ```rust -use light_ctoken_sdk::ctoken::CreateCMintCpi; +use light_token_sdk::token::CreateCMintCpi; let account_infos = CreateCMintCpi { mint_seed: mint_seed.clone(), @@ -423,7 +423,7 @@ account_infos.invoke_signed(&[signer_seeds])?; ```rust -use light_ctoken_sdk::ctoken::CreateCMintCpi; +use light_token_sdk::token::CreateCMintCpi; let account_infos = CreateCMintCpi { mint_seed: mint_seed.clone(), @@ -454,13 +454,13 @@ account_infos.invoke_signed(&[mint_seed_seeds, authority_seeds])?; Find the source code - [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-ctoken-test/src/create_cmint.rs). + [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-light-token-test/src/create_cmint.rs). ```rust expandable use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_sdk::{ - ctoken::{ +use light_token_sdk::{ + token::{ CreateCMintCpi, CreateCMintParams, ExtensionInstructionData, SystemAccountInfos, }, CompressedProof, diff --git a/light-token/cookbook/create-token-account.mdx b/light-token/cookbook/create-token-account.mdx index 6d4cdbd..0d16594 100644 --- a/light-token/cookbook/create-token-account.mdx +++ b/light-token/cookbook/create-token-account.mdx @@ -7,9 +7,9 @@ keywords: ["token account on solana", "rent free token account for apps", "rent --- -import CTokenCreateAccountsList from "/snippets/accounts-list/light-token-create-accounts-list.mdx"; -import CTokenConfigureRent from "/snippets/light-token-configure-rent.mdx"; -import CTokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; +import TokenCreateAccountsList from "/snippets/accounts-list/light-token-create-accounts-list.mdx"; +import TokenConfigureRent from "/snippets/light-token-configure-rent.mdx"; +import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; import CompressibleRentExplained from "/snippets/compressible-rent-explained.mdx"; 1. Light token accounts are Solana accounts that hold token balances of light, SPL, or Token 2022 mints. @@ -28,12 +28,12 @@ import CompressibleRentExplained from "/snippets/compressible-rent-explained.mdx 1. The example creates a test mint for light-tokens. You can use existing light, SPL or Token 2022 mints as well. -2. Build the instruction with `CreateCTokenAccount`. It automatically includes the default rent config. +2. Build the instruction with `CreateTokenAccount`. It automatically includes the default rent config. ```rust -use light_ctoken_sdk::ctoken::{CreateCTokenAccount}; +use light_token_sdk::token::{CreateTokenAccount}; -let instruction = CreateCTokenAccount::new( +let instruction = CreateTokenAccount::new( payer.pubkey(), account.pubkey(), mint, @@ -48,7 +48,7 @@ let instruction = CreateCTokenAccount::new( ### Prerequisites - + @@ -59,8 +59,8 @@ let instruction = CreateCTokenAccount::new( use borsh::BorshDeserialize; use light_client::indexer::{AddressWithTree, Indexer}; use light_client::rpc::{LightClient, LightClientConfig, Rpc}; -use light_ctoken_sdk::ctoken::{CreateCMint, CreateCMintParams, CreateCTokenAccount}; -use light_ctoken_interface::state::CToken; +use light_token_sdk::token::{CreateCMint, CreateCMintParams, CreateTokenAccount}; +use light_token_interface::state::Token; use serde_json; use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer}; use std::convert::TryFrom; @@ -68,7 +68,7 @@ use std::env; use std::fs; #[tokio::test(flavor = "multi_thread")] -async fn test_create_ctoken_account() { +async fn test_create_token_account() { dotenvy::dotenv().ok(); let keypair_path = env::var("KEYPAIR_PATH") @@ -94,7 +94,7 @@ async fn test_create_ctoken_account() { let owner = payer.pubkey(); // Step 3: Build instruction using SDK builder - let instruction = CreateCTokenAccount::new(payer.pubkey(), account.pubkey(), mint, owner) + let instruction = CreateTokenAccount::new(payer.pubkey(), account.pubkey(), mint, owner) .instruction() .unwrap(); @@ -105,11 +105,11 @@ async fn test_create_ctoken_account() { // Step 5: Verify account creation let account_data = rpc.get_account(account.pubkey()).await.unwrap().unwrap(); - let ctoken_state = CToken::deserialize(&mut &account_data.data[..]).unwrap(); + let token_state = Token::deserialize(&mut &account_data.data[..]).unwrap(); - assert_eq!(ctoken_state.mint, mint.to_bytes(), "Mint should match"); - assert_eq!(ctoken_state.owner, owner.to_bytes(), "Owner should match"); - assert_eq!(ctoken_state.amount, 0, "Initial amount should be 0"); + assert_eq!(token_state.mint, mint.to_bytes(), "Mint should match"); + assert_eq!(token_state.owner, owner.to_bytes(), "Owner should match"); + assert_eq!(token_state.amount, 0, "Initial amount should be 0"); } pub async fn create_compressed_mint( @@ -147,12 +147,12 @@ pub async fn create_compressed_mint( }; // Derive compression address - let compression_address = light_ctoken_sdk::ctoken::derive_cmint_compressed_address( + let compression_address = light_token_sdk::token::derive_cmint_compressed_address( &mint_signer.pubkey(), &address_tree.tree, ); - let mint_pda = light_ctoken_sdk::ctoken::find_cmint_address(&mint_signer.pubkey()).0; + let mint_pda = light_token_sdk::token::find_cmint_address(&mint_signer.pubkey()).0; // Get validity proof for the address let rpc_result = rpc @@ -225,7 +225,7 @@ Find [a full code example at the end](#full-code-example). ### Configure Rent - + @@ -240,9 +240,9 @@ Find [a full code example at the end](#full-code-example). ```rust -use light_ctoken_sdk::ctoken::CreateCTokenAccountCpi; +use light_token_sdk::token::CreateTokenAccountCpi; -CreateCTokenAccountCpi { +CreateTokenAccountCpi { payer: payer.clone(), account: account.clone(), mint: mint.clone(), @@ -252,15 +252,15 @@ CreateCTokenAccountCpi { .invoke()?; ``` - + ```rust -use light_ctoken_sdk::ctoken::CreateCTokenAccountCpi; +use light_token_sdk::token::CreateTokenAccountCpi; -let account_cpi = CreateCTokenAccountCpi { +let account_cpi = CreateTokenAccountCpi { payer: payer.clone(), account: account.clone(), mint: mint.clone(), @@ -282,12 +282,12 @@ account_cpi.invoke_signed(&[signer_seeds])?; Find the source code - [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-ctoken-test/src/create_token_account.rs). + [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-light-token-test/src/create_token_account.rs). ```rust expandable use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_sdk::ctoken::{CompressibleParamsCpi, CreateCTokenAccountCpi}; +use light_token_sdk::token::{CompressibleParamsCpi, CreateTokenAccountCpi}; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::{ID, TOKEN_ACCOUNT_SEED}; @@ -302,7 +302,7 @@ pub struct CreateTokenAccountData { /// Handler for creating a compressible token account (invoke) /// -/// Uses the builder pattern from the ctoken module. This demonstrates how to: +/// Uses the builder pattern from the token module. This demonstrates how to: /// 1. Build the account infos struct with compressible params /// 2. Call the invoke() method which handles instruction building and CPI /// @@ -329,7 +329,7 @@ pub fn process_create_token_account_invoke( ); // Build the account infos struct - CreateCTokenAccountCpi { + CreateTokenAccountCpi { payer: accounts[0].clone(), account: accounts[1].clone(), mint: accounts[2].clone(), @@ -374,7 +374,7 @@ pub fn process_create_token_account_invoke_signed( ); // Build the account infos struct - let account_cpi = CreateCTokenAccountCpi { + let account_cpi = CreateTokenAccountCpi { payer: accounts[0].clone(), account: accounts[1].clone(), mint: accounts[2].clone(), diff --git a/light-token/cookbook/mint-to.mdx b/light-token/cookbook/mint-to.mdx index 29a5d91..19ac18f 100644 --- a/light-token/cookbook/mint-to.mdx +++ b/light-token/cookbook/mint-to.mdx @@ -7,8 +7,8 @@ keywords: ["mint tokens on solana", "spl mint to for developers", "token minting --- import CMintSystemAccountsList from "/snippets/accounts-list/light-mint-system-accounts-list.mdx"; -import CMintToCTokenAccountsList from "/snippets/accounts-list/light-mint-to-light-token-accounts-list.mdx"; -import CTokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; +import MintToTokenAccountsList from "/snippets/accounts-list/light-mint-to-light-token-accounts-list.mdx"; +import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; import ClientCustomRentConfig from "/snippets/light-token-guides/client-custom-rent-config.mdx"; import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; import FullSetup from "/snippets/setup/full-setup.mdx"; @@ -73,12 +73,12 @@ The example mints light-tokens to existing light-token accounts. 1. Prerequisite: The example creates a test light-mint and destination light-token account. 2. Get light-mint account infos and prove it exists with a validity proof.. 3. Set the amount of tokens you will mint and the mint authority. Only the mint authority can mint new light-tokens. -4. Build the instruction with `MintToCToken::new()` and send the transaction. +4. Build the instruction with `MintTo::new()` and send the transaction. ```rust -use light_ctoken_sdk::ctoken::MintToCToken; +use light_token_sdk::token::MintTo; -let instruction = MintToCToken::new( +let instruction = MintTo::new( params, payer.pubkey(), state_tree, @@ -93,7 +93,7 @@ let instruction = MintToCToken::new( ### Prerequisites - + @@ -104,14 +104,14 @@ let instruction = MintToCToken::new( use borsh::BorshDeserialize; use light_client::indexer::{AddressWithTree, Indexer}; use light_client::rpc::{LightClient, LightClientConfig, Rpc}; -use light_ctoken_sdk::ctoken::{ - CreateCMint, CreateCMintParams, CreateCTokenAccount, MintToCToken, MintToCTokenParams, +use light_token_sdk::token::{ + CreateCMint, CreateCMintParams, CreateTokenAccount, MintTo, MintToParams, }; -use light_ctoken_interface::instructions::extensions::token_metadata::TokenMetadataInstructionData; +use light_token_interface::instructions::extensions::token_metadata::TokenMetadataInstructionData; use solana_sdk::compute_budget::ComputeBudgetInstruction; -use light_ctoken_interface::instructions::extensions::ExtensionInstructionData; -use light_ctoken_interface::instructions::mint_action::CompressedMintWithContext; -use light_ctoken_interface::state::{AdditionalMetadata, CToken, CompressedMint}; +use light_token_interface::instructions::extensions::ExtensionInstructionData; +use light_token_interface::instructions::mint_action::CompressedMintWithContext; +use light_token_interface::state::{AdditionalMetadata, Token, CompressedMint}; use serde_json; use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer}; use std::convert::TryFrom; @@ -119,7 +119,7 @@ use std::env; use std::fs; #[tokio::test(flavor = "multi_thread")] -async fn test_mint_to_ctoken() { +async fn test_mint_to_token() { dotenvy::dotenv().ok(); let keypair_path = env::var("KEYPAIR_PATH") @@ -141,18 +141,18 @@ async fn test_mint_to_ctoken() { // Step 1: Create compressed mint with metadata let (mint, compression_address) = create_compressed_mint(&mut rpc, &payer, 9).await; - // Step 2: Create ctoken account - let ctoken_account = Keypair::new(); + // Step 2: Create token account + let token_account = Keypair::new(); let owner = payer.pubkey(); let create_account_ix = - CreateCTokenAccount::new(payer.pubkey(), ctoken_account.pubkey(), mint, owner) + CreateTokenAccount::new(payer.pubkey(), token_account.pubkey(), mint, owner) .instruction() .unwrap(); rpc.create_and_send_transaction( &[create_account_ix], &payer.pubkey(), - &[&payer, &ctoken_account], + &[&payer, &token_account], ) .await .unwrap(); @@ -219,7 +219,7 @@ async fn test_mint_to_ctoken() { }; // Step 8: Build mint params - let params = MintToCTokenParams::new( + let params = MintToParams::new( compressed_mint_with_context, amount, mint_authority, @@ -227,13 +227,13 @@ async fn test_mint_to_ctoken() { ); // Step 9: Build instruction using SDK builder - let instruction = MintToCToken::new( + let instruction = MintTo::new( params, payer.pubkey(), compressed_mint_account.tree_info.tree, compressed_mint_account.tree_info.queue, output_queue, - vec![ctoken_account.pubkey()], + vec![token_account.pubkey()], ) .instruction() .unwrap(); @@ -245,16 +245,16 @@ async fn test_mint_to_ctoken() { .unwrap(); // Step 11: Verify tokens were minted - let ctoken_account_data = rpc - .get_account(ctoken_account.pubkey()) + let token_account_data = rpc + .get_account(token_account.pubkey()) .await .unwrap() .unwrap(); - let ctoken_state = CToken::deserialize(&mut &ctoken_account_data.data[..]).unwrap(); - assert_eq!(ctoken_state.amount, amount, "Token amount should match"); - assert_eq!(ctoken_state.mint, mint.to_bytes(), "Mint should match"); - assert_eq!(ctoken_state.owner, owner.to_bytes(), "Owner should match"); + let token_state = Token::deserialize(&mut &token_account_data.data[..]).unwrap(); + assert_eq!(token_state.amount, amount, "Token amount should match"); + assert_eq!(token_state.mint, mint.to_bytes(), "Mint should match"); + assert_eq!(token_state.owner, owner.to_bytes(), "Owner should match"); } pub async fn create_compressed_mint( @@ -292,12 +292,12 @@ pub async fn create_compressed_mint( }; // Derive compression address - let compression_address = light_ctoken_sdk::ctoken::derive_cmint_compressed_address( + let compression_address = light_token_sdk::token::derive_cmint_compressed_address( &mint_signer.pubkey(), &address_tree.tree, ); - let mint_pda = light_ctoken_sdk::ctoken::find_cmint_address(&mint_signer.pubkey()).0; + let mint_pda = light_token_sdk::token::find_cmint_address(&mint_signer.pubkey()).0; // Get validity proof for the address let rpc_result = rpc @@ -383,9 +383,9 @@ Include your mint, the amount of tokens to be minted and the pubkey of the mint The client passes a validity proof that proves the light-mint exists. ```rust -use light_ctoken_sdk::ctoken::MintToCTokenParams; +use light_token_sdk::token::MintToParams; -let params = MintToCTokenParams::new( +let params = MintToParams::new( data.compressed_mint_inputs, data.amount, data.mint_authority, @@ -407,7 +407,7 @@ The client includes them in the instruction. ```rust -use light_ctoken_sdk::ctoken::SystemAccountInfos; +use light_token_sdk::token::SystemAccountInfos; let system_accounts = SystemAccountInfos { light_system_program: light_system_program.clone(), @@ -433,15 +433,15 @@ let system_accounts = SystemAccountInfos { ```rust -use light_ctoken_sdk::ctoken::MintToCTokenCpi; +use light_token_sdk::token::MintToCpi; -MintToCTokenCpi { +MintToCpi { authority: authority.clone(), payer: payer.clone(), state_tree: state_tree.clone(), input_queue: input_queue.clone(), output_queue: output_queue.clone(), - ctoken_accounts, + token_accounts, system_accounts, cpi_context: None, cpi_context_account: None, @@ -454,15 +454,15 @@ MintToCTokenCpi { ```rust -use light_ctoken_sdk::ctoken::MintToCTokenCpi; +use light_token_sdk::token::MintToCpi; -let account_infos = MintToCTokenCpi { +let account_infos = MintToCpi { authority: authority.clone(), payer: payer.clone(), state_tree: state_tree.clone(), input_queue: input_queue.clone(), output_queue: output_queue.clone(), - ctoken_accounts, + token_accounts, system_accounts, cpi_context: None, cpi_context_account: None, @@ -477,7 +477,7 @@ account_infos.invoke_signed(&[signer_seeds])?; - + @@ -487,13 +487,13 @@ account_infos.invoke_signed(&[signer_seeds])?; Find the source code - [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-ctoken-test/src/mint_to_ctoken.rs). + [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-light-token-test/src/ctoken_mint_to.rs). ```rust expandable use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_interface::instructions::mint_action::CompressedMintWithContext; -use light_ctoken_sdk::ctoken::{MintToCTokenCpi, MintToCTokenParams, SystemAccountInfos}; +use light_token_interface::instructions::mint_action::CompressedMintWithContext; +use light_token_sdk::token::{MintToCpi, MintToParams, SystemAccountInfos}; use light_sdk::instruction::ValidityProof; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; @@ -502,9 +502,9 @@ use crate::ID; /// PDA seed for mint authority in invoke_signed variant pub const MINT_AUTHORITY_SEED: &[u8] = b"mint_authority"; -/// Instruction data for mint_to_ctoken operations +/// Instruction data for mint_to #[derive(BorshSerialize, BorshDeserialize, Debug)] -pub struct MintToCTokenData { +pub struct MintToData { pub compressed_mint_inputs: CompressedMintWithContext, pub amount: u64, pub mint_authority: Pubkey, @@ -513,9 +513,9 @@ pub struct MintToCTokenData { /// Handler for minting tokens to compressed token accounts /// -/// Uses the MintToCTokenCpi builder pattern. This demonstrates how to: -/// 1. Build MintToCTokenParams using the constructor -/// 2. Build MintToCTokenCpi with accounts and params +/// Uses the MintToCpi builder pattern. This demonstrates how to: +/// 1. Build MintToParams using the constructor +/// 2. Build MintToCpi with accounts and params /// 3. Call invoke() which handles instruction building and CPI /// /// Account order (all accounts from SDK-generated instruction): @@ -531,17 +531,17 @@ pub struct MintToCTokenData { /// - accounts[9]: output_queue /// - accounts[10]: state_tree /// - accounts[11]: input_queue -/// - accounts[12..]: ctoken_accounts (variable length - destination accounts) -pub fn process_mint_to_ctoken( +/// - accounts[12..]: token_accounts (variable length - destination accounts) +pub fn process_mint_to( accounts: &[AccountInfo], - data: MintToCTokenData, + data: MintToData, ) -> Result<(), ProgramError> { if accounts.len() < 13 { return Err(ProgramError::NotEnoughAccountKeys); } // Build params using the constructor - let params = MintToCTokenParams::new( + let params = MintToParams::new( data.compressed_mint_inputs, data.amount, data.mint_authority, @@ -558,19 +558,19 @@ pub fn process_mint_to_ctoken( system_program: accounts[8].clone(), }; - // Collect ctoken accounts from remaining accounts (index 12 onwards) - let ctoken_accounts: Vec = accounts[12..].to_vec(); + // Collect token accounts from remaining accounts (index 12 onwards) + let token_accounts: Vec = accounts[12..].to_vec(); // Build the account infos struct and invoke - // SDK account order: output_queue (9), tree (10), input_queue (11), ctoken_accounts (12+) + // SDK account order: output_queue (9), tree (10), input_queue (11), token_accounts (12+) // In this case, payer == authority (accounts[3]) - MintToCTokenCpi { + MintToCpi { 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 input_queue: accounts[11].clone(), // input_queue at index 11 output_queue: accounts[9].clone(), // output_queue at index 9 - ctoken_accounts, + token_accounts, system_accounts, cpi_context: None, cpi_context_account: None, @@ -583,7 +583,7 @@ pub fn process_mint_to_ctoken( /// Handler for minting tokens with PDA mint authority (invoke_signed) /// -/// Uses the MintToCTokenCpi builder pattern with invoke_signed. +/// Uses the MintToCpi builder pattern with invoke_signed. /// The mint authority is a PDA derived from this program. /// /// Account order (all accounts from SDK-generated instruction): @@ -599,10 +599,10 @@ pub fn process_mint_to_ctoken( /// - accounts[9]: output_queue /// - accounts[10]: state_tree /// - accounts[11]: input_queue -/// - accounts[12..]: ctoken_accounts (variable length - destination accounts) -pub fn process_mint_to_ctoken_invoke_signed( +/// - accounts[12..]: token_accounts (variable length - destination accounts) +pub fn process_mint_to_invoke_signed( accounts: &[AccountInfo], - data: MintToCTokenData, + data: MintToData, ) -> Result<(), ProgramError> { if accounts.len() < 13 { return Err(ProgramError::NotEnoughAccountKeys); @@ -617,7 +617,7 @@ pub fn process_mint_to_ctoken_invoke_signed( } // Build params using the constructor - let params = MintToCTokenParams::new( + let params = MintToParams::new( data.compressed_mint_inputs, data.amount, data.mint_authority, @@ -634,18 +634,18 @@ pub fn process_mint_to_ctoken_invoke_signed( system_program: accounts[8].clone(), }; - // Collect ctoken accounts from remaining accounts (index 12 onwards) - let ctoken_accounts: Vec = accounts[12..].to_vec(); + // Collect token accounts from remaining accounts (index 12 onwards) + let token_accounts: Vec = accounts[12..].to_vec(); // Build the account infos struct // authority is the PDA (accounts[2]) - let account_infos = MintToCTokenCpi { + let account_infos = MintToCpi { authority: accounts[2].clone(), // authority PDA payer: accounts[3].clone(), // fee_payer from SDK accounts state_tree: accounts[10].clone(), // tree at index 10 input_queue: accounts[11].clone(), // input_queue at index 11 output_queue: accounts[9].clone(), // output_queue at index 9 - ctoken_accounts, + token_accounts, system_accounts, cpi_context: None, cpi_context_account: None, diff --git a/light-token/cookbook/transfer-interface.mdx b/light-token/cookbook/transfer-interface.mdx index 5e8b872..8ddce1f 100644 --- a/light-token/cookbook/transfer-interface.mdx +++ b/light-token/cookbook/transfer-interface.mdx @@ -9,8 +9,8 @@ keywords: ["transfer tokens on solana", "token transfer on solana", "interface m import TransferInterfaceAccountsListCtoken1 from "/snippets/accounts-list/transfer-interface-accounts-list-light-token-1.mdx"; import TransferInterfaceAccountsListSpl2 from "/snippets/accounts-list/transfer-interface-accounts-list-spl-2.mdx"; import TransferInterfaceIntro from "/snippets/light-token-guides/transfer-interface-intro.mdx"; -import CTokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; -import CTokenTsClientPrerequisites from "/snippets/light-token-guides/light-token-ts-client-prerequisites.mdx"; +import TokenClientPrerequisites from "/snippets/light-token-guides/light-token-client-prerequisites.mdx"; +import TokenTsClientPrerequisites from "/snippets/light-token-guides/light-token-ts-client-prerequisites.mdx"; import ClientCustomRentConfig from "/snippets/light-token-guides/client-custom-rent-config.mdx"; import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; import FullSetup from "/snippets/setup/full-setup.mdx"; @@ -109,7 +109,7 @@ The example transfers SPL token -> light-token and light-token -> light-token: ### Prerequisites - + @@ -121,10 +121,10 @@ The example transfers SPL token -> light-token and light-token -> light-token: ```rust use anchor_spl::token::{spl_token, Mint}; use light_client::rpc::{LightClient, LightClientConfig, Rpc}; -use light_ctoken_sdk::{ - ctoken::{ - derive_ctoken_ata as derive_token_ata, CreateAssociatedCTokenAccount as CreateAssociatedTokenAccount, - TransferCToken as TransferToken, TransferSplToCtoken as TransferSplToToken, +use light_token_sdk::{ + token::{ + derive_token_ata, CreateAssociatedTokenAccount, + Transfer, TransferFromSpl, }, spl_interface::{find_spl_interface_pda_with_index, CreateSplInterfacePda}, }; @@ -278,11 +278,11 @@ async fn test_spl_to_token_to_token() { // 7. Transfer SPL tokens to sender's token account let (spl_interface_pda, spl_interface_pda_bump) = find_spl_interface_pda_with_index(&mint, 0); - let spl_to_token_ix = TransferSplToToken { + let spl_to_token_ix = TransferFromSpl { amount: spl_to_token_amount, spl_interface_pda_bump, source_spl_token_account: spl_token_account_keypair.pubkey(), - destination_ctoken_account: sender_token_ata, + destination_token_account: sender_token_ata, authority: payer.pubkey(), mint, payer: payer.pubkey(), @@ -308,7 +308,7 @@ async fn test_spl_to_token_to_token() { .instruction() .unwrap(); - let token_transfer_ix = TransferToken { + let token_transfer_ix = Transfer { source: sender_token_ata, destination: recipient_token_ata, amount: token_transfer_amount, @@ -358,7 +358,7 @@ Define the number of light-tokens / SPL tokens to transfer - to which SPL or light-token account. ```rust -use light_ctoken_sdk::ctoken::TransferInterfaceCpi; +use light_token_sdk::token::TransferInterfaceCpi; let mut transfer = TransferInterfaceCpi::new( data.amount, @@ -435,12 +435,12 @@ transfer.invoke_signed(&[authority_seeds])?; Find the source code - [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-ctoken-test/src/transfer_interface.rs). + [here](https://github.com/Lightprotocol/light-protocol/blob/main/sdk-tests/sdk-light-token-test/src/transfer_interface.rs). ```rust expandable use borsh::{BorshDeserialize, BorshSerialize}; -use light_ctoken_sdk::ctoken::TransferInterfaceCpi; +use light_token_sdk::token::TransferInterfaceCpi; use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use crate::ID; @@ -452,25 +452,25 @@ pub const TRANSFER_INTERFACE_AUTHORITY_SEED: &[u8] = b"transfer_interface_author #[derive(BorshSerialize, BorshDeserialize, Debug)] pub struct TransferInterfaceData { pub amount: u64, - /// Required for SPL<->CToken transfers, None for CToken->CToken + /// Required for SPL<->Token transfers, None for Token->Token pub token_pool_pda_bump: Option, } /// Handler for TransferInterfaceCpi (invoke) /// /// This unified interface automatically detects account types and routes to: -/// - CToken -> CToken transfer -/// - CToken -> SPL transfer -/// - SPL -> CToken transfer +/// - Token -> Token transfer +/// - Token -> SPL transfer +/// - SPL -> Token transfer /// /// Account order: /// - accounts[0]: compressed_token_program (for CPI) -/// - accounts[1]: source_account (SPL or CToken) -/// - accounts[2]: destination_account (SPL or CToken) +/// - accounts[1]: source_account (SPL or light-token) +/// - accounts[2]: destination_account (SPL or light-token) /// - accounts[3]: authority (signer) /// - accounts[4]: payer (signer) /// - accounts[5]: compressed_token_program_authority -/// For SPL bridge (optional, required for SPL<->CToken): +/// For SPL bridge (optional, required for SPL<->Token): /// - accounts[6]: mint /// - accounts[7]: token_pool_pda /// - accounts[8]: spl_token_program @@ -512,12 +512,12 @@ pub fn process_transfer_interface_invoke( /// /// Account order: /// - accounts[0]: compressed_token_program (for CPI) -/// - accounts[1]: source_account (SPL or CToken) -/// - accounts[2]: destination_account (SPL or CToken) +/// - accounts[1]: source_account (SPL or light-token) +/// - accounts[2]: destination_account (SPL or light-token) /// - accounts[3]: authority (PDA, not signer - program signs) /// - accounts[4]: payer (signer) /// - accounts[5]: compressed_token_program_authority -/// For SPL bridge (optional, required for SPL<->CToken): +/// For SPL bridge (optional, required for SPL<->Token): /// - accounts[6]: mint /// - accounts[7]: token_pool_pda /// - accounts[8]: spl_token_program diff --git a/light-token/interface-methods.mdx b/light-token/interface-methods.mdx deleted file mode 100644 index 4747218..0000000 --- a/light-token/interface-methods.mdx +++ /dev/null @@ -1,486 +0,0 @@ ---- -title: "Reference to Interface Methods" -sidebarTitle: "Interface Methods" -description: "Technical reference for light-token interface methods, account types, and CPI." ---- - -Light token is a high-performance token standard that reduces the cost of mint and token accounts by 200x. - - - [View on - GitHub](https://github.com/Lightprotocol/light-protocol/tree/main/js/compressed-token/src/v3) - - -### Mint Structure - -Compressed mints store data using Light Protocol's compressed accounts, consisting of three layers: - -**BaseMint** (82 bytes) - -```typescript -interface BaseMint { - mintAuthority: PublicKey | null; // Authority to mint new tokens - supply: bigint; // Total token supply - decimals: number; // Decimal precision (0-9) - isInitialized: boolean; // SPL compatibility flag - freezeAuthority: PublicKey | null; // Authority to freeze accounts -} -``` - -**MintContext** (34 bytes) - -```typescript -interface MintContext { - version: number; // Protocol version - splMintInitialized: boolean; // Whether SPL mint is initialized - splMint: PublicKey; // PDA of associated SPL mint -} -``` - -**TokenMetadata Extension** (variable) - -```typescript -interface TokenMetadata { - updateAuthority?: PublicKey | null; // Authority to update metadata - mint: PublicKey; // Associated mint - name: string; // Token name - symbol: string; // Token symbol - uri: string; // Metadata JSON URI - additionalMetadata?: { key: string; value: string }[]; -} -``` - -### Key State Variables - -**MintInterface** - Unified mint query result - -| Field | Type | Description | -| ------------- | ---------------- | ------------------------------------ | -| mint | Mint | SPL-compatible mint structure | -| programId | PublicKey | Token program (SPL, T22, or c-token) | -| merkleContext | MerkleContext? | Compression context (c-token only) | -| mintContext | MintContext? | Protocol context (c-token only) | -| tokenMetadata | TokenMetadata? | Parsed metadata extension | -| extensions | MintExtension[]? | Raw extension data | - -**AccountInterface** - Unified token account query result - -| Field | Type | Description | -| ----------- | -------------- | ----------------------------- | -| accountInfo | AccountInfo | Raw account data | -| parsed | Account | SPL-parsed token account | -| isCold | boolean | Whether account is compressed | -| loadContext | MerkleContext? | Compression proof context | - -**TokenAccountSourceType** - Account location types - -| Value | Description | -| ---------------- | ------------------------------ | -| `spl` | SPL Token Program hot account | -| `token2022` | Token-2022 hot account | -| `spl-cold` | SPL tokens in compressed state | -| `token2022-cold` | T22 tokens in compressed state | -| `ctoken-hot` | C-token decompressed | -| `ctoken-cold` | C-token compressed | - ---- - -## Functions - -### createMintInterface - -Create and initialize a new mint for SPL, Token-2022, or c-token. - -```typescript -const { mint, transactionSignature } = await createMintInterface( - rpc, - payer, - mintAuthority, // Signer for c-token mints - freezeAuthority, // or null - 9 // decimals -); -``` - -**Parameters** - -| Name | Type | Description | -| ------------------- | ----------------------------- | ---------------------------------------- | -| rpc | Rpc | RPC connection | -| payer | Signer | Fee payer | -| mintAuthority | PublicKey \| Signer | Mint authority | -| freezeAuthority | PublicKey \| Signer \| null | Optional freeze authority | -| decimals | number | Decimal places (0-9) | -| keypair | Keypair? | Mint keypair (generated if not provided) | -| confirmOptions | ConfirmOptions? | Transaction confirmation options | -| programId | PublicKey? | Token program (defaults to c-token) | -| tokenMetadata | TokenMetadataInstructionData? | Optional metadata | -| outputStateTreeInfo | TreeInfo? | Optional state tree | -| addressTreeInfo | AddressTreeInfo? | Optional address tree | - -**Returns** - -| Type | Description | -| ---------------------------------------------------------------------------- | ---------------------------------------------- | -| Promise\<\{ mint: PublicKey; transactionSignature: TransactionSignature \}\> | Created mint address and transaction signature | - ---- - -### mintToInterface - -Mint tokens to a decompressed on-chain token account. Works with SPL, Token-2022, and c-token mints. - -```typescript -const ctokenAta = getAssociatedTokenAddressInterface(mint, recipient); - -await mintToInterface(rpc, payer, mint, ctokenAta, mintAuthority, 1_000_000n); -``` - -**Parameters** - -| Name | Type | Description | -| -------------- | ------------------- | -------------------------------- | -| rpc | Rpc | RPC connection | -| payer | Signer | Fee payer | -| mint | PublicKey | Mint address | -| destination | PublicKey | Destination token account | -| authority | Signer \| PublicKey | Mint authority | -| amount | number \| bigint | Amount to mint | -| multiSigners | Signer[]? | Multi-signature signers | -| confirmOptions | ConfirmOptions? | Transaction confirmation options | -| programId | PublicKey? | Token program (auto-detected) | - -**Returns** - -| Type | Description | -| ------------------------------- | --------------------- | -| Promise\ | Transaction signature | - ---- - -### mintToCompressed - -Mint compressed tokens directly to compressed accounts. - -```typescript -await mintToCompressed(rpc, payer, mint, mintAuthority, [ - { recipient: wallet1, amount: 1_000_000n }, - { recipient: wallet2, amount: 500_000n }, -]); -``` - -**Parameters** - -| Name | Type | Description | -| ------------------- | ------------------------------------------------------------- | ---------------------------------- | -| rpc | Rpc | RPC connection | -| payer | Signer | Fee payer | -| mint | PublicKey | Mint address | -| authority | Signer | Mint authority | -| recipients | Array\<\{ recipient: PublicKey; amount: number \| bigint \}\> | Recipients and amounts | -| outputStateTreeInfo | TreeInfo? | Optional state tree | -| tokenAccountVersion | number? | Token account version (default: 3) | -| confirmOptions | ConfirmOptions? | Transaction confirmation options | - -**Returns** - -| Type | Description | -| ------------------------------- | --------------------- | -| Promise\ | Transaction signature | - ---- - -### createAssociatedCTokenAccount - -Create an associated light-token account. - -```typescript -const ata = await createAssociatedCTokenAccount(rpc, payer, owner, mint); -``` - -**Parameters** - -| Name | Type | Description | -| ------------------ | ------------------- | ----------------------------------- | -| rpc | Rpc | RPC connection | -| payer | Signer | Fee payer | -| owner | PublicKey | Account owner | -| mint | PublicKey | Token mint | -| compressibleConfig | CompressibleConfig? | Optional compressible configuration | -| configAccount | PublicKey? | Config account address | -| rentPayerPda | PublicKey? | Rent payer PDA | -| confirmOptions | ConfirmOptions? | Transaction confirmation options | - -**Returns** - -| Type | Description | -| -------------------- | ------------------- | -| Promise\ | Created ATA address | - ---- - -### wrap - -Wrap tokens from an SPL/T22 account to a c-token account. - -```typescript -const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey, false, TOKEN_PROGRAM_ID); -const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); - -await wrap(rpc, payer, splAta, ctokenAta, owner, mint, 1000n); -``` - -**Parameters** - -| Name | Type | Description | -| ---------------- | ----------------- | ----------------------------------- | -| rpc | Rpc | RPC connection | -| payer | Signer | Fee payer | -| source | PublicKey | Source SPL/T22 token account | -| destination | PublicKey | Destination c-token account | -| owner | Signer | Owner of source account (must sign) | -| mint | PublicKey | Token mint | -| amount | bigint | Amount to wrap | -| splInterfaceInfo | SplInterfaceInfo? | SPL interface info | -| confirmOptions | ConfirmOptions? | Transaction confirmation options | - -**Returns** - -| Type | Description | -| ------------------------------- | --------------------- | -| Promise\ | Transaction signature | - ---- - -### unwrap - -Unwrap c-tokens to SPL tokens. Automatically loads all compressed tokens to hot ATA before unwrapping. - -```typescript -const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); - -await unwrap(rpc, payer, splAta, owner, mint, 1000n); -``` - -**Parameters** - -| Name | Type | Description | -| ---------------- | ----------------------- | ---------------------------------- | -| rpc | Rpc | RPC connection | -| payer | Signer | Fee payer | -| destination | PublicKey | Destination SPL/T22 token account | -| owner | Signer | Owner of c-token (must sign) | -| mint | PublicKey | Token mint | -| amount | number \| bigint \| BN? | Amount to unwrap (defaults to all) | -| splInterfaceInfo | SplInterfaceInfo? | SPL interface info | -| confirmOptions | ConfirmOptions? | Transaction confirmation options | - -**Returns** - -| Type | Description | -| ------------------------------- | --------------------- | -| Promise\ | Transaction signature | - ---- - -### transferInterface - -Transfer tokens using the c-token interface. Auto-detects account types and consolidates balances. - -```typescript -const source = getAssociatedTokenAddressInterface(mint, owner.publicKey); -const destination = getAssociatedTokenAddressInterface(mint, recipient); - -await transferInterface(rpc, payer, source, mint, destination, owner, 1000n); -``` - -**Parameters** - -| Name | Type | Description | -| -------------- | ---------------------- | ----------------------------------------- | -| rpc | Rpc | RPC connection | -| payer | Signer | Fee payer | -| source | PublicKey | Source token account | -| mint | PublicKey | Token mint | -| destination | PublicKey | Destination token account | -| owner | Signer | Account owner | -| amount | number \| bigint \| BN | Amount to transfer | -| programId | PublicKey? | Token program (defaults to c-token) | -| confirmOptions | ConfirmOptions? | Transaction confirmation options | -| options | InterfaceOptions? | Interface options | -| wrap | boolean? | Include SPL/T22 balances (default: false) | - -**Returns** - -| Type | Description | -| ------------------------------- | --------------------- | -| Promise\ | Transaction signature | - ---- - -## Rust CPI Reference - -### TransferSplToCtokenCpi - -Transfer SPL tokens to c-token account (wrap operation). - -**Fields** - -| Name | Type | Description | -| ---------------------------------- | ----------- | -------------------------------------- | -| amount | u64 | Amount to transfer | -| spl_interface_pda_bump | u8 | Bump seed for SPL interface PDA | -| source_spl_token_account | AccountInfo | Source SPL token account (writable) | -| destination_ctoken_account | AccountInfo | Destination c-token account (writable) | -| authority | AccountInfo | Authority signer | -| mint | AccountInfo | Mint account | -| payer | AccountInfo | Fee payer (signer) | -| spl_interface_pda | AccountInfo | SPL interface PDA (writable) | -| spl_token_program | AccountInfo | SPL Token Program | -| compressed_token_program_authority | AccountInfo | CPI authority PDA | - -**Methods** - -- `.invoke()` - Execute CPI -- `.invoke_signed(&[seeds])` - Execute CPI with PDA signer - -```rust -use light_ctoken_sdk::ctoken::TransferSplToCtokenCpi; - -TransferSplToCtokenCpi { - amount, - spl_interface_pda_bump, - source_spl_token_account: ctx.accounts.pool_ata.to_account_info(), - destination_ctoken_account: ctx.accounts.user_ctoken_ata.to_account_info(), - authority: ctx.accounts.pool_authority.to_account_info(), - mint: ctx.accounts.mint.to_account_info(), - payer: ctx.accounts.payer.to_account_info(), - spl_interface_pda: ctx.accounts.spl_interface_pda.to_account_info(), - spl_token_program: ctx.accounts.token_program.to_account_info(), - compressed_token_program_authority: ctx.accounts.cpi_authority.to_account_info(), -} -.invoke_signed(&[pool_signer_seeds])?; -``` - ---- - -### TransferCTokenToSplCpi - -Transfer c-tokens to SPL token account (unwrap operation). - -**Fields** - -| Name | Type | Description | -| ---------------------------------- | ----------- | ---------------------------------------- | -| source_ctoken_account | AccountInfo | Source c-token account (writable) | -| destination_spl_token_account | AccountInfo | Destination SPL token account (writable) | -| amount | u64 | Amount to transfer | -| authority | AccountInfo | Authority signer | -| mint | AccountInfo | Mint account | -| payer | AccountInfo | Fee payer (signer) | -| spl_interface_pda | AccountInfo | SPL interface PDA (writable) | -| spl_interface_pda_bump | u8 | Bump seed for SPL interface PDA | -| spl_token_program | AccountInfo | SPL Token Program | -| compressed_token_program_authority | AccountInfo | CPI authority PDA | - -**Methods** - -- `.invoke()` - Execute CPI -- `.invoke_signed(&[seeds])` - Execute CPI with PDA signer - -```rust -use light_ctoken_sdk::ctoken::TransferCTokenToSplCpi; - -TransferCTokenToSplCpi { - source_ctoken_account: ctx.accounts.user_ctoken_ata.to_account_info(), - destination_spl_token_account: ctx.accounts.pool_ata.to_account_info(), - amount, - authority: ctx.accounts.depositor.to_account_info(), - mint: ctx.accounts.mint.to_account_info(), - payer: ctx.accounts.payer.to_account_info(), - spl_interface_pda: ctx.accounts.spl_interface_pda.to_account_info(), - spl_interface_pda_bump, - spl_token_program: ctx.accounts.token_program.to_account_info(), - compressed_token_program_authority: ctx.accounts.cpi_authority.to_account_info(), -} -.invoke()?; -``` - ---- - -### CreateAssociatedCTokenAccountCpi - -Create an associated c-token account via CPI. - -**Fields** - -| Name | Type | Description | -| ------------------------ | ------------------------------- | ---------------------------- | -| owner | AccountInfo | Account owner | -| mint | AccountInfo | Token mint | -| payer | AccountInfo | Fee payer (signer) | -| associated_token_account | AccountInfo | ATA to create (writable) | -| system_program | AccountInfo | Solana System Program | -| bump | u8 | PDA bump seed | -| compressible | Option\ | Optional compressible config | -| idempotent | bool | Use idempotent instruction | - -**Methods** - -- `.invoke()` - Execute CPI -- `.invoke_signed(&[seeds])` - Execute CPI with PDA signer - ---- - -### SystemAccountInfos - -System accounts required for CPI operations to Light Protocol. - -**Fields** - -| Name | Type | Description | -| ----------------------------- | ----------- | -------------------------------------- | -| light_system_program | AccountInfo | Light System Program | -| cpi_authority_pda | AccountInfo | CPI authority (signs for your program) | -| registered_program_pda | AccountInfo | Your program's registration | -| account_compression_authority | AccountInfo | Compression authority | -| account_compression_program | AccountInfo | Account Compression Program | -| system_program | AccountInfo | Solana System Program | - ---- - -## Errors - -### CTokenSdkError - -| Error | Code | Description | -| ------------------------------------ | ----- | ------------------------------------ | -| InsufficientBalance | 17001 | Account balance too low | -| SerializationError | 17002 | Failed to serialize data | -| CpiError | 17003 | CPI invocation failed | -| CannotCompressAndDecompress | 17004 | Invalid operation combination | -| CompressionCannotBeSetTwice | 17005 | Compression already configured | -| InconsistentCompressDecompressState | 17006 | State mismatch | -| BothCompressAndDecompress | 17007 | Both operations specified | -| InvalidCompressDecompressAmount | 17008 | Invalid amount for operation | -| MethodUsed | 17009 | Method already invoked | -| DecompressedMintConfigRequired | 17010 | Missing decompressed mint config | -| InvalidCompressInputOwner | 17011 | Wrong owner for compress input | -| AccountBorrowFailed | 17012 | Failed to borrow account | -| InvalidAccountData | 17013 | Malformed account data | -| MissingCpiAccount | 17014 | Required CPI account missing | -| TooManyAccounts | 17015 | Exceeds account limit | -| NonContinuousIndices | 17016 | PackedAccount indices not continuous | -| PackedAccountIndexOutOfBounds | 17017 | Index exceeds bounds | -| CannotMintWithDecompressedInCpiWrite | 17018 | Invalid mint operation | -| RentAuthorityIsNone | 17019 | Rent authority not set | -| SplInterfaceRequired | 17020 | SPL interface account required | -| IncompleteSplInterface | 17021 | SPL interface not fully initialized | -| UseRegularSplTransfer | 17022 | Use standard SPL transfer instead | -| CannotDetermineAccountType | 17023 | Unable to identify account type | -| CpiContextRequired | 17024 | CPI context data required | -| MissingMintAccount | 17025 | Mint account not provided | -| MissingSplTokenProgram | 17026 | SPL Token Program not provided | -| MissingSplInterfacePda | 17027 | SPL interface PDA not provided | -| MissingSplInterfacePdaBump | 17028 | SPL interface PDA bump not provided | -| InvalidCpiContext | 17029 | CPI context validation failed | -| NoInputAccounts | 17030 | No input accounts provided | diff --git a/light-token/toolkits/for-dexs.mdx b/light-token/toolkits/for-dexs.mdx deleted file mode 100644 index 1d402be..0000000 --- a/light-token/toolkits/for-dexs.mdx +++ /dev/null @@ -1,446 +0,0 @@ ---- -title: "Toolkit for DEXs" -sidebarTitle: "for DEXs" -description: "Guide to integrate light-token support into your DEX protocol." ---- - -import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; -import ToolkitsSetup from "/snippets/setup/toolkits-setup.mdx"; - -1. Enable users to deposit and withdraw light-tokens directly. -2. Reduce user costs by ~200x for token account creation. -3. Support atomic swaps with light-token input/output. - -| Creation Cost | SPL | light-token | -| :---------------- | :------------------ | :------------------- | -| **Token Account** | ~2,000,000 lamports | ~**11,000** lamports | - -### What you will implement - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SPLLight
**Accept Deposit**transfer() to poolunwrap()
**Return Withdrawal**transfer() from poolwrap()
**Swap Input**transferChecked()unwrap()
**Swap Output**transfer()wrap()
**Query Balance**getAccount()getAtaInterface()
- -## Setup - -### TypeScript SDK - - - -```typescript -import { createRpc } from "@lightprotocol/stateless.js"; -import { - wrap, - unwrap, - getAssociatedTokenAddressInterface, - getAtaInterface, - createAtaInterfaceIdempotent, - getSplInterfaceInfos, -} from "@lightprotocol/compressed-token"; - -const rpc = createRpc(RPC_ENDPOINT); -``` - -### Rust SDK (On-chain Programs) - -```toml -[dependencies] -light-ctoken-sdk = "0.2" -``` - -```rust -use light_ctoken_sdk::ctoken::{ - TransferSplToCtokenCpi, // SPL → c-token (wrap) - TransferCTokenToSplCpi, // c-token → SPL (unwrap) -}; -``` - -## Accept Deposits - -Accept light-token deposits by unwrapping them from c-token ATAs to SPL tokens for your pool. - - - - -```typescript -import { - createUnwrapInstruction, - getAssociatedTokenAddressInterface, - getSplInterfaceInfos, -} from "@lightprotocol/compressed-token"; -import { buildAndSignTx, sendAndConfirmTx } from "@lightprotocol/stateless.js"; -import { getAssociatedTokenAddressSync } from "@solana/spl-token"; -import { ComputeBudgetProgram } from "@solana/web3.js"; - -// Derive addresses -const ctokenAta = getAssociatedTokenAddressInterface(mint, depositor.publicKey); -const poolAta = getAssociatedTokenAddressSync(mint, poolAuthority); - -// Get SPL interface info -const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint); -const splInterfaceInfo = splInterfaceInfos.find((info) => info.isInitialized); - -// Create unwrap instruction -const unwrapIx = createUnwrapInstruction( - ctokenAta, // source: user's c-token ATA - poolAta, // destination: pool's SPL ATA - depositor.publicKey, // owner - mint, - amount, - splInterfaceInfo, - payer.publicKey -); - -// Build and send -const { blockhash } = await rpc.getLatestBlockhash(); -const tx = buildAndSignTx( - [ComputeBudgetProgram.setComputeUnitLimit({ units: 200_000 }), unwrapIx], - payer, - blockhash, - [depositor] -); -await sendAndConfirmTx(rpc, tx); -``` - - - - -```typescript -import { unwrap } from "@lightprotocol/compressed-token"; -import { getAssociatedTokenAddressSync } from "@solana/spl-token"; - -// Pool's SPL ATA (destination) -const poolAta = getAssociatedTokenAddressSync(mint, poolAuthority); - -// Unwrap user's light-tokens to pool's SPL ATA -const signature = await unwrap( - rpc, - payer, - poolAta, // destination: pool's SPL ATA - depositor, // owner of c-token ATA (signer) - mint, - amount -); -``` - - - -```typescript -import { transfer } from "@solana/spl-token"; - -// SPL: User transfers from their ATA to pool -await transfer(connection, payer, userAta, poolAta, depositor, amount); -``` - - - - - - -```rust -use light_ctoken_sdk::ctoken::TransferCTokenToSplCpi; - -// In your program instruction handler -pub fn accept_deposit(ctx: Context, amount: u64, spl_interface_pda_bump: u8) -> Result<()> { - // Transfer user's c-tokens to pool's SPL ATA - TransferCTokenToSplCpi { - source_ctoken_account: ctx.accounts.user_ctoken_ata.to_account_info(), - destination_spl_token_account: ctx.accounts.pool_ata.to_account_info(), - amount, - authority: ctx.accounts.depositor.to_account_info(), - mint: ctx.accounts.mint.to_account_info(), - payer: ctx.accounts.payer.to_account_info(), - spl_interface_pda: ctx.accounts.spl_interface_pda.to_account_info(), - spl_interface_pda_bump, - spl_token_program: ctx.accounts.token_program.to_account_info(), - compressed_token_program_authority: ctx.accounts.cpi_authority.to_account_info(), - } - .invoke()?; - - // Continue with your pool deposit logic... - Ok(()) -} -``` - - - - -## Return Withdrawals - -Return light-tokens to users by wrapping SPL tokens from your pool into c-token ATAs. - - - - -```typescript -import { - createWrapInstruction, - getAssociatedTokenAddressInterface, - getSplInterfaceInfos, -} from "@lightprotocol/compressed-token"; -import { buildAndSignTx, sendAndConfirmTx } from "@lightprotocol/stateless.js"; -import { getAssociatedTokenAddressSync } from "@solana/spl-token"; -import { ComputeBudgetProgram } from "@solana/web3.js"; - -// Derive addresses -const poolAta = getAssociatedTokenAddressSync(mint, poolAuthority); -const ctokenAta = getAssociatedTokenAddressInterface(mint, withdrawer); - -// Get SPL interface info -const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint); -const splInterfaceInfo = splInterfaceInfos.find((info) => info.isInitialized); - -// Create wrap instruction -const wrapIx = createWrapInstruction( - poolAta, // source: pool's SPL ATA - ctokenAta, // destination: user's c-token ATA - poolAuthority, // owner - mint, - amount, - splInterfaceInfo, - payer.publicKey -); - -// Build and send -const { blockhash } = await rpc.getLatestBlockhash(); -const tx = buildAndSignTx( - [ComputeBudgetProgram.setComputeUnitLimit({ units: 200_000 }), wrapIx], - payer, - blockhash, - [poolAuthority] -); -await sendAndConfirmTx(rpc, tx); -``` - - - - -```typescript -import { - wrap, - createAtaInterfaceIdempotent, - getAssociatedTokenAddressInterface, -} from "@lightprotocol/compressed-token"; -import { getAssociatedTokenAddressSync } from "@solana/spl-token"; - -// Ensure user's c-token ATA exists -const ctokenAta = getAssociatedTokenAddressInterface(mint, withdrawer); -await createAtaInterfaceIdempotent(rpc, payer, mint, withdrawer); - -// Pool's SPL ATA (source) -const poolAta = getAssociatedTokenAddressSync(mint, poolAuthority); - -// Wrap pool's SPL tokens to user's c-token ATA -const signature = await wrap( - rpc, - payer, - poolAta, // source: pool's SPL ATA - ctokenAta, // destination: user's c-token ATA - poolAuthority, // owner of pool's SPL tokens (signer) - mint, - amount -); -``` - - - -```typescript -import { transfer } from "@solana/spl-token"; - -// SPL: Pool transfers to user's ATA -await transfer(connection, payer, poolAta, userAta, poolAuthority, amount); -``` - - - - - - -```rust -use light_ctoken_sdk::ctoken::TransferSplToCtokenCpi; - -// In your program instruction handler -pub fn process_withdrawal(ctx: Context, amount: u64, spl_interface_pda_bump: u8) -> Result<()> { - // Your pool withdrawal logic first... - - // Transfer SPL tokens from pool to user's c-token ATA - TransferSplToCtokenCpi { - amount, - spl_interface_pda_bump, - source_spl_token_account: ctx.accounts.pool_ata.to_account_info(), - destination_ctoken_account: ctx.accounts.user_ctoken_ata.to_account_info(), - authority: ctx.accounts.pool_authority.to_account_info(), - mint: ctx.accounts.mint.to_account_info(), - payer: ctx.accounts.payer.to_account_info(), - spl_interface_pda: ctx.accounts.spl_interface_pda.to_account_info(), - spl_token_program: ctx.accounts.token_program.to_account_info(), - compressed_token_program_authority: ctx.accounts.cpi_authority.to_account_info(), - } - .invoke_signed(&[pool_signer_seeds])?; - - Ok(()) -} -``` - - - - -## Atomic Swap - -Compose unwrap + swap + wrap instructions in a single atomic transaction. - -```typescript -import { ComputeBudgetProgram } from "@solana/web3.js"; -import { - createUnwrapInstruction, - createWrapInstruction, - getAssociatedTokenAddressInterface, - getSplInterfaceInfos, - loadAta, -} from "@lightprotocol/compressed-token"; -import { buildAndSignTx, sendAndConfirmTx } from "@lightprotocol/stateless.js"; -import { getAssociatedTokenAddressSync } from "@solana/spl-token"; - -// Get addresses -const userInputCtoken = getAssociatedTokenAddressInterface( - inputMint, - user.publicKey -); -const userInputSpl = getAssociatedTokenAddressSync(inputMint, user.publicKey); -const userOutputSpl = getAssociatedTokenAddressSync(outputMint, user.publicKey); -const userOutputCtoken = getAssociatedTokenAddressInterface( - outputMint, - user.publicKey -); - -// Load c-token ATA (brings cold tokens to hot balance) -await loadAta(rpc, userInputCtoken, user, inputMint, payer); - -// Get SPL interface infos -const inputSplInfos = await getSplInterfaceInfos(rpc, inputMint); -const inputSplInfo = inputSplInfos.find((i) => i.isInitialized); -const outputSplInfos = await getSplInterfaceInfos(rpc, outputMint); -const outputSplInfo = outputSplInfos.find((i) => i.isInitialized); - -// 1. Unwrap input light-tokens to SPL for swap -const unwrapIx = createUnwrapInstruction( - userInputCtoken, - userInputSpl, - user.publicKey, - inputMint, - inputAmount, - inputSplInfo, - payer.publicKey -); - -// 2. Your DEX swap instruction (e.g., Raydium, Orca) -const swapIx = createSwapInstruction({ - // ... your swap params -}); - -// 3. Wrap output SPL tokens back to light-tokens -const wrapIx = createWrapInstruction( - userOutputSpl, - userOutputCtoken, - user.publicKey, - outputMint, - outputAmount, - outputSplInfo, - payer.publicKey -); - -// Build atomic transaction -const { blockhash } = await rpc.getLatestBlockhash(); -const tx = buildAndSignTx( - [ - ComputeBudgetProgram.setComputeUnitLimit({ units: 500_000 }), - unwrapIx, - swapIx, - wrapIx, - ], - payer, - blockhash, - [user] -); - -const signature = await sendAndConfirmTx(rpc, tx); -``` - -## Query User Balances - -Check a user's light-token holdings before processing deposits or swaps. - -```typescript -import { - getAssociatedTokenAddressInterface, - getAtaInterface, -} from "@lightprotocol/compressed-token"; - -const ctokenAta = getAssociatedTokenAddressInterface(mint, userPubkey); -const account = await getAtaInterface(rpc, ctokenAta, userPubkey, mint); - -console.log(`User has ${account.parsed.amount} light-tokens`); -``` - - - -```typescript -import { getAccount, getAssociatedTokenAddressSync } from "@solana/spl-token"; - -const ata = getAssociatedTokenAddressSync(mint, userPubkey); -const account = await getAccount(connection, ata); -console.log(`User has ${account.amount} SPL tokens`); -``` - - - -## Integration Flow - -``` - DEX with light-token Support -┌─────────────────────────────────────────────────────────────┐ -│ │ -│ DEPOSIT: │ -│ User c-token ATA ──unwrap()──► Pool SPL ATA │ -│ │ -│ SWAP: │ -│ unwrap() ──► [swap instruction] ──► wrap() │ -│ │ -│ WITHDRAWAL: │ -│ Pool SPL ATA ──wrap()──► User c-token ATA │ -│ │ -└─────────────────────────────────────────────────────────────┘ -``` diff --git a/light-token/toolkits/for-launchpads.mdx b/light-token/toolkits/for-launchpads.mdx deleted file mode 100644 index 0470b74..0000000 --- a/light-token/toolkits/for-launchpads.mdx +++ /dev/null @@ -1,525 +0,0 @@ ---- -title: "Toolkit for Launchpads" -sidebarTitle: "for Launchpads" -description: "Guide to add light-token APIs to your Launchpad Application." ---- - -import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; -import ToolkitsSetup from "/snippets/setup/toolkits-setup.mdx"; - -1. light-token follows similar API patterns like SPL and simply adds an interface suffix. -2. Token accounts cost ~200x less to create than SPL accounts. -3. Mints are rent-free with built-in token metadata. - -| Creation Cost | SPL | light-token | -| :---------------- | :------------------ | :------------------- | -| **Mint Account** | ~1,500,000 lamports | **15,000** lamports | -| **Token Account** | ~2,000,000 lamports | ~**11,000** lamports | - -### What you will implement - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SPLLight
**Create Mint**createMint()createMintInterface()
**Get/Create ATA**getOrCreateAssociatedTokenAccount()getOrCreateAtaInterface()
**Derive ATA**getAssociatedTokenAddress()getAssociatedTokenAddressInterface()
**Mint Tokens**mintTo()mintToInterface()
**Transfer**transfer()transferInterface()
**Get Balance**getAccount()getAtaInterface()
- - - Find devnet examples - [here](https://github.com/Lightprotocol/light-token-toolkits). - - -## Setup - - - -```typescript -import { createRpc } from "@lightprotocol/stateless.js"; - -import { - createMintInterface, - createTokenMetadata, - getOrCreateAtaInterface, - getAtaInterface, - getAssociatedTokenAddressInterface, - mintToInterface, - transferInterface, -} from "@lightprotocol/compressed-token"; - -const rpc = createRpc(RPC_ENDPOINT); -``` - -### Create Token with Metadata - - - - -```typescript -import { Keypair, ComputeBudgetProgram } from "@solana/web3.js"; -import { - buildAndSignTx, - sendAndConfirmTx, - selectAddressTreeInfoV2, - selectStateTreeInfo, -} from "@lightprotocol/stateless.js"; -import { - createMintInstruction, - createTokenMetadata, - findMintAddress, -} from "@lightprotocol/compressed-token"; - -const mintSigner = Keypair.generate(); -const decimals = 9; - -// Get tree infos -const addressTreeInfo = selectAddressTreeInfoV2( - await rpc.getAddressTreeInfos() -); -const stateTreeInfo = selectStateTreeInfo(await rpc.getStateTreeInfos()); - -// Get validity proof for address creation -const [mintPda] = findMintAddress(mintSigner.publicKey); -const validityProof = await rpc.getValidityProofV0( - [], - [{ address: mintPda, tree: addressTreeInfo.tree }] -); - -// Create instruction -const ix = createMintInstruction( - mintSigner.publicKey, - decimals, - payer.publicKey, // mintAuthority - null, // freezeAuthority - payer.publicKey, - validityProof, - addressTreeInfo, - stateTreeInfo, - createTokenMetadata( - "My Launchpad Token", - "MLT", - "https://example.com/metadata.json" - ) -); - -// Build and send transaction -const { blockhash } = await rpc.getLatestBlockhash(); -const tx = buildAndSignTx( - [ComputeBudgetProgram.setComputeUnitLimit({ units: 300_000 }), ix], - payer, - blockhash, - [mintSigner] -); -const signature = await sendAndConfirmTx(rpc, tx); -``` - - - - -```typescript -import { Keypair } from "@solana/web3.js"; -import { createRpc } from "@lightprotocol/stateless.js"; -import { - createMintInterface, - createTokenMetadata, -} from "@lightprotocol/compressed-token"; - -const mintSigner = Keypair.generate(); - -const { mint, transactionSignature } = await createMintInterface( - rpc, - payer, - payer, // mintAuthority - null, // freezeAuthority - 9, // decimals - mintSigner, - undefined, - undefined, - createTokenMetadata( - "My Launchpad Token", - "MLT", - "https://example.com/metadata.json" - ) -); - -console.log("Mint created:", mint.toBase58()); -``` - - - -```typescript -import { createMint } from "@solana/spl-token"; -import { Metaplex } from "@metaplex-foundation/js"; - -// SPL requires separate mint creation + Metaplex metadata -const mint = await createMint(connection, payer, payer.publicKey, null, 9); - -// Then add metadata via Metaplex (additional transaction) -const metaplex = Metaplex.make(connection); -await metaplex.nfts().create({ - name: "My Launchpad Token", - symbol: "MLT", - uri: "https://example.com/metadata.json", - sellerFeeBasisPoints: 0, - useNewMint: mint, -}); -``` - - - - - - -### Create User Account - - - - -```typescript -import { Transaction } from "@solana/web3.js"; -import { - createAssociatedTokenAccountInterfaceIdempotentInstruction, - createLoadAtaInstructions, - getAssociatedTokenAddressInterface, -} from "@lightprotocol/compressed-token/unified"; -import { CTOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; - -const ata = getAssociatedTokenAddressInterface(mint, buyer.publicKey); - -const tx = new Transaction().add( - createAssociatedTokenAccountInterfaceIdempotentInstruction( - payer.publicKey, - ata, - buyer.publicKey, - mint, - CTOKEN_PROGRAM_ID - ), - ...(await createLoadAtaInstructions( - rpc, - ata, - buyer.publicKey, - mint, - payer.publicKey - )) -); -``` - - - - -```typescript -import { getOrCreateAtaInterface } from "@lightprotocol/compressed-token"; - -const ata = await getOrCreateAtaInterface(rpc, payer, mint, buyer.publicKey); - -console.log("User ATA:", ata.parsed.address.toBase58()); -``` - - - -```typescript -import { getOrCreateAssociatedTokenAccount } from "@solana/spl-token"; - -const ata = await getOrCreateAssociatedTokenAccount( - connection, - payer, - mint, - buyer.publicKey -); - -console.log("User ATA:", ata.address.toBase58()); -``` - - - - - - -### Buy (Mint Tokens to Buyer) - -When a user buys from the bonding curve, mint tokens to their account. - - - - -```typescript -import { ComputeBudgetProgram } from "@solana/web3.js"; -import { - buildAndSignTx, - sendAndConfirmTx, - bn, - DerivationMode, -} from "@lightprotocol/stateless.js"; -import { - createMintToInterfaceInstruction, - getMintInterface, - getAssociatedTokenAddressInterface, -} from "@lightprotocol/compressed-token"; - -const buyerAta = getAssociatedTokenAddressInterface(mint, buyer.publicKey); -const amount = 1_000_000_000; - -// Get mint interface (includes merkle context for c-tokens) -const mintInterface = await getMintInterface(rpc, mint); - -// Get validity proof for the mint -let validityProof; -if (mintInterface.merkleContext) { - validityProof = await rpc.getValidityProofV2( - [ - { - hash: bn(mintInterface.merkleContext.hash), - leafIndex: mintInterface.merkleContext.leafIndex, - treeInfo: mintInterface.merkleContext.treeInfo, - proveByIndex: mintInterface.merkleContext.proveByIndex, - }, - ], - [], - DerivationMode.compressible - ); -} - -// Create instruction -const ix = createMintToInterfaceInstruction( - mintInterface, - buyerAta, - mintAuthority.publicKey, // bonding curve authority - payer.publicKey, - amount, - validityProof -); - -// Build and send transaction -const { blockhash } = await rpc.getLatestBlockhash(); -const tx = buildAndSignTx( - [ComputeBudgetProgram.setComputeUnitLimit({ units: 500_000 }), ix], - payer, - blockhash, - [mintAuthority] // include mint authority as signer -); -const signature = await sendAndConfirmTx(rpc, tx); -``` - - - - -```typescript -import { - mintToInterface, - getAssociatedTokenAddressInterface, -} from "@lightprotocol/compressed-token"; - -const buyerAta = getAssociatedTokenAddressInterface(mint, buyer.publicKey); -const amount = 1_000_000_000; // 1 token with 9 decimals - -const signature = await mintToInterface( - rpc, - payer, - mint, - buyerAta, - mintAuthority, // bonding curve PDA or keypair - amount -); - -console.log("Minted tokens to buyer:", signature); -``` - - - -```typescript -import { mintTo, getAssociatedTokenAddressSync } from "@solana/spl-token"; - -const buyerAta = getAssociatedTokenAddressSync(mint, buyer.publicKey); -const amount = 1_000_000_000; - -const signature = await mintTo( - connection, - payer, - mint, - buyerAta, - mintAuthority, - amount -); - -console.log("Minted tokens to buyer:", signature); -``` - - - - - - -### Sell (Transfer Back to Curve) - -When a user sells, transfer tokens back to the bonding curve account. - - - - -```typescript -import { Transaction } from "@solana/web3.js"; -import { - createLoadAtaInstructions, - createTransferInterfaceInstruction, - getAssociatedTokenAddressInterface, -} from "@lightprotocol/compressed-token/unified"; - -const sellerAta = getAssociatedTokenAddressInterface(mint, seller.publicKey); -const curveAta = getAssociatedTokenAddressInterface(mint, bondingCurvePda); -const amount = 500_000_000; - -const tx = new Transaction().add( - ...(await createLoadAtaInstructions( - rpc, - sellerAta, - seller.publicKey, - mint, - payer.publicKey - )), - createTransferInterfaceInstruction( - sellerAta, - curveAta, - seller.publicKey, - amount - ) -); -``` - - - - -```typescript -import { - transferInterface, - getAssociatedTokenAddressInterface, -} from "@lightprotocol/compressed-token"; - -const sellerAta = getAssociatedTokenAddressInterface(mint, seller.publicKey); -const curveAta = getAssociatedTokenAddressInterface(mint, bondingCurvePda); -const amount = 500_000_000; // 0.5 tokens - -const signature = await transferInterface( - rpc, - payer, - sellerAta, - mint, - curveAta, - seller, // owner (must be Signer) - amount -); - -console.log("Sold tokens:", signature); -``` - - - -```typescript -import { transfer, getAssociatedTokenAddressSync } from "@solana/spl-token"; - -const sellerAta = getAssociatedTokenAddressSync(mint, seller.publicKey); -const curveAta = getAssociatedTokenAddressSync(mint, bondingCurvePda); -const amount = 500_000_000; - -const signature = await transfer( - connection, - payer, - sellerAta, - curveAta, - seller, - amount -); - -console.log("Sold tokens:", signature); -``` - - - - - - -### Show Balance - -```typescript -import { - getAssociatedTokenAddressInterface, - getAtaInterface, -} from "@lightprotocol/compressed-token"; - -const ata = getAssociatedTokenAddressInterface(mint, owner); -const account = await getAtaInterface(rpc, ata, owner, mint); - -console.log("Balance:", account.parsed.amount.toString()); -``` - - - -```typescript -import { getAccount, getAssociatedTokenAddressSync } from "@solana/spl-token"; - -const ata = getAssociatedTokenAddressSync(mint, owner); -const account = await getAccount(connection, ata); - -console.log("Balance:", account.amount.toString()); -``` - - - -## On-Chain Program Integration - -If your bonding curve logic is on-chain and needs to CPI into the light token program, see the Program Guide tabs in: - - - - invoke / invoke_signed examples - - - MintToCTokenCpi builder - - - TransferInterfaceCpi builder - - diff --git a/light-token/toolkits/for-payments.mdx b/light-token/toolkits/for-payments.mdx index bad9bad..8d2ded4 100644 --- a/light-token/toolkits/for-payments.mdx +++ b/light-token/toolkits/for-payments.mdx @@ -104,7 +104,7 @@ import { createLoadAtaInstructions, getAssociatedTokenAddressInterface, } from "@lightprotocol/compressed-token/unified"; -import { CTOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; +import { LIGHT_TOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; const ata = getAssociatedTokenAddressInterface(mint, recipient); @@ -114,7 +114,7 @@ const tx = new Transaction().add( ata, recipient, mint, - CTOKEN_PROGRAM_ID + LIGHT_TOKEN_PROGRAM_ID ), ...(await createLoadAtaInstructions( rpc, @@ -222,7 +222,7 @@ import { createTransferInterfaceInstruction, getAssociatedTokenAddressInterface, } from "@lightprotocol/compressed-token/unified"; -import { CTOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; +import { LIGHT_TOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; const sourceAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); const destinationAta = getAssociatedTokenAddressInterface(mint, recipient); @@ -233,7 +233,7 @@ const tx = new Transaction().add( destinationAta, recipient, mint, - CTOKEN_PROGRAM_ID + LIGHT_TOKEN_PROGRAM_ID ), ...(await createLoadAtaInstructions( rpc, @@ -444,7 +444,7 @@ import { import { getSplInterfaceInfos } from "@lightprotocol/compressed-token"; const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); -const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); +const tokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint); const splInterfaceInfo = splInterfaceInfos.find((i) => i.isInitialized); @@ -452,7 +452,7 @@ const splInterfaceInfo = splInterfaceInfos.find((i) => i.isInitialized); const tx = new Transaction().add( createWrapInstruction( splAta, - ctokenAta, + tokenAta, owner.publicKey, mint, amount, @@ -473,10 +473,10 @@ import { // SPL ATA with tokens to wrap const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); -// c-token ATA destination -const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); +// light-token ATA destination +const tokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); -await wrap(rpc, payer, splAta, ctokenAta, owner, mint, amount); +await wrap(rpc, payer, splAta, tokenAta, owner, mint, amount); ```
@@ -506,7 +506,7 @@ import { } from "@lightprotocol/compressed-token/unified"; import { getSplInterfaceInfos } from "@lightprotocol/compressed-token"; -const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); +const tokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint); @@ -515,13 +515,13 @@ const splInterfaceInfo = splInterfaceInfos.find((i) => i.isInitialized); const tx = new Transaction().add( ...(await createLoadAtaInstructions( rpc, - ctokenAta, + tokenAta, owner.publicKey, mint, payer.publicKey )), createUnwrapInstruction( - ctokenAta, + tokenAta, splAta, owner.publicKey, mint, diff --git a/light-token/toolkits/for-streaming-mints.mdx b/light-token/toolkits/for-streaming-mints.mdx index 2ea5b73..7d87c79 100644 --- a/light-token/toolkits/for-streaming-mints.mdx +++ b/light-token/toolkits/for-streaming-mints.mdx @@ -24,7 +24,7 @@ tokio = { version = "1", features = ["full"] } futures = "0.3" light-event = "0.2" light-compressed-account = "0.7" -light-ctoken-interface = "0.1" +light-token-interface = "0.1" borsh = "0.10" bs58 = "0.5" ``` @@ -33,12 +33,12 @@ bs58 = "0.5" use futures::StreamExt; use helius_laserstream::{subscribe, LaserstreamConfig}; use light_event::parse::event_from_light_transaction; -use light_ctoken_interface::state::mint::CompressedMint; -use light_ctoken_interface::state::extensions::ExtensionStruct; +use light_token_interface::state::mint::CompressedMint; +use light_token_interface::state::extensions::ExtensionStruct; use borsh::BorshDeserialize; const LIGHT_SYSTEM_PROGRAM: &str = "SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7"; -const CTOKEN_PROGRAM_ID: &str = "cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"; +const LIGHT_TOKEN_PROGRAM_ID: &str = "cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"; const COMPRESSED_MINT_DISCRIMINATOR: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 1]; ``` @@ -131,8 +131,8 @@ for output in event.output_compressed_accounts.iter() { let owner = output.compressed_account.owner; // Check if owned by light token program - let ctoken_program_id = bs58::decode(CTOKEN_PROGRAM_ID).into_vec().unwrap(); - if owner != ctoken_program_id.as_slice() { + let light_token_program_id = bs58::decode(LIGHT_TOKEN_PROGRAM_ID).into_vec().unwrap(); + if owner != light_token_program_id.as_slice() { continue; } @@ -215,7 +215,7 @@ pub struct BaseMint { pub freeze_authority: Option, } -/// metadata used by the cToken program (34 bytes) +/// metadata used by the light token program (34 bytes) #[repr(C)] pub struct CompressedMintMetadata { pub version: u8, diff --git a/light-token/toolkits/for-streaming-tokens.mdx b/light-token/toolkits/for-streaming-tokens.mdx index 68f9d5e..8b181e6 100644 --- a/light-token/toolkits/for-streaming-tokens.mdx +++ b/light-token/toolkits/for-streaming-tokens.mdx @@ -56,12 +56,12 @@ async function main() { await mintTo(rpc, payer, mint, owner.publicKey, mintAuthority, bn(1000)); - // Get c-token ATA address - const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); + // Get light-token ATA address + const tokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); // Load compressed tokens to hot balance // Creates ATA if needed, returns null if nothing to load - const signature = await loadAta(rpc, ctokenAta, owner, mint, payer); + const signature = await loadAta(rpc, tokenAta, owner, mint, payer); if (signature) { console.log("Loaded tokens to hot balance"); @@ -110,13 +110,13 @@ async function main() { await mintTo(rpc, payer, mint, owner.publicKey, mintAuthority, bn(1000)); - // Get c-token ATA address - const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); + // Get light-token ATA address + const tokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); // Create load instructions const ixs = await createLoadAtaInstructions( rpc, - ctokenAta, + tokenAta, owner.publicKey, mint, payer.publicKey diff --git a/light-token/toolkits/for-trading-apps.mdx b/light-token/toolkits/for-trading-apps.mdx deleted file mode 100644 index 3f4ab1b..0000000 --- a/light-token/toolkits/for-trading-apps.mdx +++ /dev/null @@ -1,444 +0,0 @@ ---- -title: "Toolkit for Trading Apps" -sidebarTitle: "for Trading Apps" -description: "Guide to add light-token APIs to your Trading Application." ---- - -import { CodeCompare } from "/snippets/jsx/code-compare.jsx"; -import ToolkitsSetup from "/snippets/setup/toolkits-setup.mdx"; - -1. light-token follows similar API patterns like SPL and simply adds an interface suffix. -2. Token accounts cost ~200x less to create than SPL accounts. -3. Use wrap/unwrap to convert between light-tokens and SPL for compatibility with DEXs without light-token support. - -| Creation Cost | SPL | light-token | -| :---------------- | :------------------ | :------------------- | -| **Token Account** | ~2,000,000 lamports | ~**11,000** lamports | - -### What you will implement - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SPLLight
**Get/Create ATA**getOrCreateAssociatedTokenAccount()getOrCreateAtaInterface()
**Derive ATA**getAssociatedTokenAddress()getAssociatedTokenAddressInterface()
**Transfer**transfer()transferInterface()
**Get Balance**getAccount()getAtaInterface()
**Tx History**getSignaturesForAddress()rpc.getSignaturesForOwnerInterface()
**Wrap (for DEX)**N/Awrap()
**Unwrap (from DEX)**N/Aunwrap()
- - - Find devnet examples - [here](https://github.com/Lightprotocol/light-token-toolkits). - - -## Setup - - - -```typescript -import { createRpc } from "@lightprotocol/stateless.js"; - -import { - getOrCreateAtaInterface, - getAtaInterface, - getAssociatedTokenAddressInterface, - transferInterface, - wrap, - unwrap, -} from "@lightprotocol/compressed-token/unified"; - -const rpc = createRpc(RPC_ENDPOINT); -``` - -### Portfolio View - -Fetch balances for multiple tokens in a user's portfolio. - -```typescript -import { - getAssociatedTokenAddressInterface, - getAtaInterface, -} from "@lightprotocol/compressed-token/unified"; - -const mints = [USDC_MINT, SOL_MINT, BONK_MINT]; // Token mints to track - -const portfolio = await Promise.all( - mints.map(async (mint) => { - const ata = getAssociatedTokenAddressInterface(mint, owner); - try { - const account = await getAtaInterface(rpc, ata, owner, mint); - return { mint, balance: account.parsed.amount }; - } catch { - return { mint, balance: 0n }; - } - }) -); - -console.log(portfolio); -``` - - - -```typescript -import { getAccount, getAssociatedTokenAddressSync } from "@solana/spl-token"; - -const mints = [USDC_MINT, SOL_MINT, BONK_MINT]; - -const portfolio = await Promise.all( - mints.map(async (mint) => { - const ata = getAssociatedTokenAddressSync(mint, owner); - try { - const account = await getAccount(connection, ata); - return { mint, balance: account.amount }; - } catch { - return { mint, balance: 0n }; - } - }) -); - -console.log(portfolio); -``` - - - -### Transfer Tokens - - - - -```typescript -import { Transaction } from "@solana/web3.js"; -import { - createLoadAtaInstructions, - createTransferInterfaceInstruction, - getAssociatedTokenAddressInterface, -} from "@lightprotocol/compressed-token/unified"; - -const sourceAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); -const destinationAta = getAssociatedTokenAddressInterface(mint, recipient); - -const tx = new Transaction().add( - ...(await createLoadAtaInstructions( - rpc, - sourceAta, - owner.publicKey, - mint, - payer.publicKey - )), - createTransferInterfaceInstruction( - sourceAta, - destinationAta, - owner.publicKey, - amount - ) -); -``` - - - -```typescript -import { Transaction } from "@solana/web3.js"; -import { - getAssociatedTokenAddressSync, - createTransferInstruction, -} from "@solana/spl-token"; - -const sourceAta = getAssociatedTokenAddressSync(mint, owner.publicKey); -const destinationAta = getAssociatedTokenAddressSync(mint, recipient); - -const tx = new Transaction().add( - createTransferInstruction(sourceAta, destinationAta, owner.publicKey, amount) -); -``` - - - - - - -```typescript -import { - getAssociatedTokenAddressInterface, - transferInterface, -} from "@lightprotocol/compressed-token/unified"; - -const sourceAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); -const destinationAta = getAssociatedTokenAddressInterface(mint, recipient); - -await transferInterface( - rpc, - payer, - sourceAta, - mint, - destinationAta, - owner, - amount -); -``` - - - -```typescript -import { transfer, getAssociatedTokenAddressSync } from "@solana/spl-token"; - -const sourceAta = getAssociatedTokenAddressSync(mint, owner.publicKey); -const destinationAta = getAssociatedTokenAddressSync(mint, recipient); - -await transfer(connection, payer, sourceAta, destinationAta, owner, amount); -``` - - - - - - -### Transaction History - -```typescript -const result = await rpc.getSignaturesForOwnerInterface(owner); - -console.log(result.signatures); // Merged + deduplicated -console.log(result.solana); // On-chain txs only -console.log(result.compressed); // Compressed txs only -``` - -Use `getSignaturesForAddressInterface(address)` for address-specific rather than owner-wide history. - - - -```typescript -const signatures = await connection.getSignaturesForAddress(ata); -``` - - - -### Wrap for DEX Swaps - -Before swapping on a DEX, convert light-tokens to SPL tokens. - - - - -```typescript -import { Transaction, ComputeBudgetProgram } from "@solana/web3.js"; -import { getAssociatedTokenAddressSync } from "@solana/spl-token"; -import { - buildAndSignTx, - sendAndConfirmTx, - dedupeSigner, -} from "@lightprotocol/stateless.js"; -import { - createWrapInstruction, - getAssociatedTokenAddressInterface, - getSplInterfaceInfos, -} from "@lightprotocol/compressed-token"; - -const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); -const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); - -// Get SPL interface info for the mint -const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint); -const splInterfaceInfo = splInterfaceInfos.find((info) => info.isInitialized); - -// Create wrap instruction -const ix = createWrapInstruction( - ctokenAta, // source: c-token ATA - splAta, // destination: SPL ATA - owner.publicKey, // owner - mint, - amount, - splInterfaceInfo, - payer.publicKey -); - -// Build and send transaction -const { blockhash } = await rpc.getLatestBlockhash(); -const additionalSigners = dedupeSigner(payer, [owner]); - -const tx = buildAndSignTx( - [ComputeBudgetProgram.setComputeUnitLimit({ units: 200_000 }), ix], - payer, - blockhash, - additionalSigners -); - -const signature = await sendAndConfirmTx(rpc, tx); -``` - - - - -```typescript -import { getAssociatedTokenAddressSync } from "@solana/spl-token"; -import { - wrap, - getAssociatedTokenAddressInterface, - createAtaInterfaceIdempotent, -} from "@lightprotocol/compressed-token/unified"; - -// 1. Create c-token ATA (source) -const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); -await createAtaInterfaceIdempotent(rpc, payer, mint, owner.publicKey); - -// 2. SPL ATA must exist (destination for DEX) -const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); - -// 3. Wrap light-tokens to SPL for DEX swap -await wrap( - rpc, - payer, - ctokenAta, // source: c-token ATA - splAta, // destination: SPL ATA (for DEX) - owner, - mint, - amount -); - -// Now use splAta with your DEX of choice -``` - - - - -### Unwrap After Swaps - -After receiving tokens from a DEX swap, convert SPL tokens back to light-tokens. - - - - -```typescript -import { ComputeBudgetProgram } from "@solana/web3.js"; -import { getAssociatedTokenAddressSync } from "@solana/spl-token"; -import { - buildAndSignTx, - sendAndConfirmTx, - dedupeSigner, -} from "@lightprotocol/stateless.js"; -import { - loadAta, - createUnwrapInstruction, - getAssociatedTokenAddressInterface, - getSplInterfaceInfos, -} from "@lightprotocol/compressed-token"; - -const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); -const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); - -// Load compressed tokens to c-token ATA (hot balance) -await loadAta(rpc, ctokenAta, owner, mint, payer); - -// Get SPL interface info for the mint -const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint); -const splInterfaceInfo = splInterfaceInfos.find((info) => info.isInitialized); - -// Create unwrap instruction -const ix = createUnwrapInstruction( - ctokenAta, // source: c-token ATA - splAta, // destination: SPL ATA - owner.publicKey, // owner - mint, - amount, - splInterfaceInfo, - payer.publicKey -); - -// Build and send transaction -const { blockhash } = await rpc.getLatestBlockhash(); -const additionalSigners = dedupeSigner(payer, [owner]); - -const tx = buildAndSignTx( - [ComputeBudgetProgram.setComputeUnitLimit({ units: 200_000 }), ix], - payer, - blockhash, - additionalSigners -); - -const signature = await sendAndConfirmTx(rpc, tx); -``` - - - - -```typescript -import { getAssociatedTokenAddressSync } from "@solana/spl-token"; -import { unwrap } from "@lightprotocol/compressed-token/unified"; - -// SPL ATA holds tokens received from DEX -const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); - -// Unwrap SPL tokens back to light-tokens -await unwrap( - rpc, - payer, - splAta, // destination: SPL ATA (has tokens from DEX) - owner, - mint, - amount // omit for full balance -); -``` - - - - -## DEX Integration Flow - -``` -┌─────────────────────────────────────────────────────────────┐ -│ Trading App Flow │ -├─────────────────────────────────────────────────────────────┤ -│ │ -│ 1. User holds light-tokens (low storage cost) │ -│ │ │ -│ ▼ │ -│ 2. wrap() → Convert to SPL before swap │ -│ │ │ -│ ▼ │ -│ 3. Execute swap on DEX (Jupiter, Raydium, etc.) │ -│ │ │ -│ ▼ │ -│ 4. unwrap() → Convert received SPL back to light-tokens │ -│ │ │ -│ ▼ │ -│ 5. User holds light-tokens (low storage cost) │ -│ │ -└─────────────────────────────────────────────────────────────┘ -``` diff --git a/light-token/toolkits/for-wallets.mdx b/light-token/toolkits/for-wallets.mdx index ca5bed5..63acf5a 100644 --- a/light-token/toolkits/for-wallets.mdx +++ b/light-token/toolkits/for-wallets.mdx @@ -103,7 +103,7 @@ import { createLoadAtaInstructions, getAssociatedTokenAddressInterface, } from "@lightprotocol/compressed-token"; -import { CTOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; +import { LIGHT_TOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; const ata = getAssociatedTokenAddressInterface(mint, recipient); @@ -113,7 +113,7 @@ const tx = new Transaction().add( ata, recipient, mint, - CTOKEN_PROGRAM_ID + LIGHT_TOKEN_PROGRAM_ID ), ...(await createLoadAtaInstructions( rpc, @@ -265,7 +265,7 @@ import { getAssociatedTokenAddressInterface, createAssociatedTokenAccountInterfaceIdempotentInstruction, } from "@lightprotocol/compressed-token"; -import { CTOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; +import { LIGHT_TOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js"; const destinationAta = getAssociatedTokenAddressInterface(mint, recipient); const createAtaIx = createAssociatedTokenAccountInterfaceIdempotentInstruction( @@ -273,7 +273,7 @@ const createAtaIx = createAssociatedTokenAccountInterfaceIdempotentInstruction( destinationAta, recipient, mint, - CTOKEN_PROGRAM_ID + LIGHT_TOKEN_PROGRAM_ID ); new Transaction().add(createAtaIx, transferIx); @@ -397,7 +397,7 @@ import { } from "@lightprotocol/compressed-token"; const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); -const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); +const tokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint); const splInterfaceInfo = splInterfaceInfos.find((i) => i.isInitialized); @@ -405,7 +405,7 @@ const splInterfaceInfo = splInterfaceInfos.find((i) => i.isInitialized); const tx = new Transaction().add( createWrapInstruction( splAta, - ctokenAta, + tokenAta, owner.publicKey, mint, amount, @@ -426,10 +426,10 @@ import { // SPL ATA with tokens to wrap const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); -// c-token ATA destination -const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); +// light-token ATA destination +const tokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); -await wrap(rpc, payer, splAta, ctokenAta, owner, mint, amount); +await wrap(rpc, payer, splAta, tokenAta, owner, mint, amount); ```
@@ -459,7 +459,7 @@ import { getSplInterfaceInfos, } from "@lightprotocol/compressed-token"; -const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); +const tokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey); const splAta = getAssociatedTokenAddressSync(mint, owner.publicKey); const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint); @@ -468,13 +468,13 @@ const splInterfaceInfo = splInterfaceInfos.find((i) => i.isInitialized); const tx = new Transaction().add( ...(await createLoadAtaInstructions( rpc, - ctokenAta, + tokenAta, owner.publicKey, mint, payer.publicKey )), createUnwrapInstruction( - ctokenAta, + tokenAta, splAta, owner.publicKey, mint, diff --git a/light-token/welcome.mdx b/light-token/welcome.mdx index 4250856..2b3b826 100644 --- a/light-token/welcome.mdx +++ b/light-token/welcome.mdx @@ -9,12 +9,12 @@ import GuidesTable from "/snippets/overview-tables/compressed-tokens-guides-tabl import AdvancedGuidesTable from "/snippets/overview-tables/compressed-tokens-advanced-guides-table.mdx"; import SetupEnvironment from "/snippets/setup/setup-environment-tabs.mdx"; import InstallDependencies from "/snippets/setup/install-dependencies-codegroup.mdx"; -import { CTokenVsSplCalculator } from "/snippets/jsx/light-token-vs-spl-calculator.jsx"; +import { LightTokenVsSplCalculator } from "/snippets/jsx/light-token-vs-spl-calculator.jsx"; import { CompressibleRentCalculator } from "/snippets/jsx/compressible-rent-calculator.jsx"; import { RentLifecycleVisualizer } from "/snippets/jsx/rent-lifecycle-visualizer.jsx"; import CompressibleRentExplained from "/snippets/compressible-rent-explained.mdx"; import CompressibleDefaultRentConfig from "/snippets/compressible-default-rent-config.mdx"; -import IntegrateCTokenGuidesTable from "/snippets/overview-tables/integrate-light-token-guides-table.mdx"; +import IntegrateLightTokenGuidesTable from "/snippets/overview-tables/integrate-light-token-guides-table.mdx"; import CookbookGuidesTable from "/snippets/overview-tables/cookbook-guides-table.mdx"; import WelcomePageInstall from "/snippets/setup/welcome-page-install.mdx"; @@ -78,7 +78,7 @@ import WelcomePageInstall from "/snippets/setup/welcome-page-install.mdx"; ## Integration Toolkits - + ## Cookbook diff --git a/scripts/sync-docs.sh b/scripts/sync-docs.sh index c4b2968..1cf7261 100755 --- a/scripts/sync-docs.sh +++ b/scripts/sync-docs.sh @@ -15,15 +15,14 @@ fi # Mapping of source files to docs files declare -A FILE_MAP=( - ["create_cmint.rs"]="compressed-token-program/cmint/create-cmint.mdx" - ["mint_to_ctoken.rs"]="compressed-token-program/cmint/mint-ctokens.mdx" - ["create_token_account.rs"]="compressed-token-program/ctoken/create-ctoken.mdx" - ["create_ata.rs"]="compressed-token-program/ctoken/create-cata.mdx" - ["close.rs"]="compressed-token-program/ctoken/close-ctoken-account.mdx" - ["transfer_interface.rs"]="compressed-token-program/ctoken/transfer-interface.mdx" + ["create_mint.rs"]="light-token/cookbook/create-mint.mdx" + ["create_token_account.rs"]="light-token/cookbook/create-token-account.mdx" + ["create_ata.rs"]="light-token/cookbook/create-ata.mdx" + ["close.rs"]="light-token/cookbook/close-token-account.mdx" + ["transfer_interface.rs"]="light-token/cookbook/transfer-interface.mdx" ) -SOURCE_DIR="$LIGHT_PROTOCOL_PATH/sdk-tests/sdk-ctoken-test/src" +SOURCE_DIR="$LIGHT_PROTOCOL_PATH/sdk-tests/sdk-light-token-test/src" for filename in "${!FILE_MAP[@]}"; do docs_file="${FILE_MAP[$filename]}" diff --git a/snippets/accounts-list/light-token-create-ata-accounts-list.mdx b/snippets/accounts-list/light-token-create-ata-accounts-list.mdx index 500c743..46c8e29 100644 --- a/snippets/accounts-list/light-token-create-ata-accounts-list.mdx +++ b/snippets/accounts-list/light-token-create-ata-accounts-list.mdx @@ -40,7 +40,7 @@ mutable - The light-ATA being created.
- - Address is derived from `[owner, ctoken_program_id, mint]`. + - Address is derived from `[owner, light_token_program_id, mint]`. diff --git a/snippets/code-snippets/compressed-token/create-mint/instruction.mdx b/snippets/code-snippets/compressed-token/create-mint/instruction.mdx index a4e46b3..47be621 100644 --- a/snippets/code-snippets/compressed-token/create-mint/instruction.mdx +++ b/snippets/code-snippets/compressed-token/create-mint/instruction.mdx @@ -11,7 +11,7 @@ import { createRpc, getBatchAddressTreeInfo, selectStateTreeInfo, - CTOKEN_PROGRAM_ID, + LIGHT_TOKEN_PROGRAM_ID, } from "@lightprotocol/stateless.js"; import { createMintInstruction } from "@lightprotocol/compressed-token"; import { homedir } from "os"; @@ -22,7 +22,7 @@ const COMPRESSED_MINT_SEED = Buffer.from("compressed_mint"); function findMintAddress(mintSigner: PublicKey): [PublicKey, number] { return PublicKey.findProgramAddressSync( [COMPRESSED_MINT_SEED, mintSigner.toBuffer()], - CTOKEN_PROGRAM_ID + LIGHT_TOKEN_PROGRAM_ID ); } diff --git a/snippets/code-snippets/light-token/load-ata/action.mdx b/snippets/code-snippets/light-token/load-ata/action.mdx index 8748784..7d28cd6 100644 --- a/snippets/code-snippets/light-token/load-ata/action.mdx +++ b/snippets/code-snippets/light-token/load-ata/action.mdx @@ -32,8 +32,8 @@ const payer = Keypair.fromSecretKey( await mintTo(rpc, payer, mint, payer.publicKey, payer, bn(1000)); // Load compressed tokens to hot balance - const ctokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); - const tx = await loadAta(rpc, ctokenAta, payer, mint, payer); + const lightTokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); + const tx = await loadAta(rpc, lightTokenAta, payer, mint, payer); console.log("Tx:", tx); })(); diff --git a/snippets/code-snippets/light-token/load-ata/instruction.mdx b/snippets/code-snippets/light-token/load-ata/instruction.mdx index b7201c3..8a8b05f 100644 --- a/snippets/code-snippets/light-token/load-ata/instruction.mdx +++ b/snippets/code-snippets/light-token/load-ata/instruction.mdx @@ -33,12 +33,12 @@ const payer = Keypair.fromSecretKey( const { mint } = await createMint(rpc, payer, payer.publicKey, 9); await mintTo(rpc, payer, mint, payer.publicKey, payer, bn(1000)); - const ctokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); + const lightTokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); // load from cold to hot state const ixs = await createLoadAtaInstructions( rpc, - ctokenAta, + lightTokenAta, payer.publicKey, mint, payer.publicKey diff --git a/snippets/code-snippets/light-token/unwrap/instruction.mdx b/snippets/code-snippets/light-token/unwrap/instruction.mdx index 3eb06b4..e4ed52d 100644 --- a/snippets/code-snippets/light-token/unwrap/instruction.mdx +++ b/snippets/code-snippets/light-token/unwrap/instruction.mdx @@ -33,8 +33,8 @@ const payer = Keypair.fromSecretKey( await mintTo(rpc, payer, mint, payer.publicKey, payer, bn(1000)); // Load compressed tokens to hot balance, then create unwrap instruction - const ctokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); - await loadAta(rpc, ctokenAta, payer, mint, payer); + const lightTokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); + await loadAta(rpc, lightTokenAta, payer, mint, payer); const splAta = await createAssociatedTokenAccount( rpc, @@ -51,7 +51,7 @@ const payer = Keypair.fromSecretKey( if (!splInterfaceInfo) throw new Error("No SPL interface found"); const ix = createUnwrapInstruction( - ctokenAta, + lightTokenAta, splAta, payer.publicKey, mint, diff --git a/snippets/code-snippets/light-token/wrap/action.mdx b/snippets/code-snippets/light-token/wrap/action.mdx index 79b282b..2e00d4d 100644 --- a/snippets/code-snippets/light-token/wrap/action.mdx +++ b/snippets/code-snippets/light-token/wrap/action.mdx @@ -42,10 +42,10 @@ const payer = Keypair.fromSecretKey( await decompress(rpc, payer, mint, bn(1000), payer, splAta); // Wrap SPL tokens to rent-free token ATA - const ctokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); + const lightTokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); await createAtaInterfaceIdempotent(rpc, payer, mint, payer.publicKey); - const tx = await wrap(rpc, payer, splAta, ctokenAta, payer, mint, bn(500)); + const tx = await wrap(rpc, payer, splAta, lightTokenAta, payer, mint, bn(500)); console.log("Tx:", tx); })(); diff --git a/snippets/code-snippets/light-token/wrap/instruction.mdx b/snippets/code-snippets/light-token/wrap/instruction.mdx index ac81bcc..266715d 100644 --- a/snippets/code-snippets/light-token/wrap/instruction.mdx +++ b/snippets/code-snippets/light-token/wrap/instruction.mdx @@ -41,7 +41,7 @@ const payer = Keypair.fromSecretKey( await decompress(rpc, payer, mint, bn(1000), payer, splAta); // Create wrap instruction - const ctokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); + const lightTokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); await createAtaInterfaceIdempotent(rpc, payer, mint, payer.publicKey); const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint); @@ -53,7 +53,7 @@ const payer = Keypair.fromSecretKey( const ix = createWrapInstruction( splAta, - ctokenAta, + lightTokenAta, payer.publicKey, mint, bn(500), diff --git a/snippets/jsx/light-token-vs-spl-calculator.jsx b/snippets/jsx/light-token-vs-spl-calculator.jsx index 864c06e..6e55145 100644 --- a/snippets/jsx/light-token-vs-spl-calculator.jsx +++ b/snippets/jsx/light-token-vs-spl-calculator.jsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState } from "react"; export const LightTokenVsSplCalculator = () => { const [numAccounts, setNumAccounts] = useState(100000); @@ -7,14 +7,14 @@ export const LightTokenVsSplCalculator = () => { const ACCOUNT_STORAGE_OVERHEAD = 128; const LAMPORTS_PER_BYTE = 6960; const DATA_LEN = 165; // SPL token account size - const CTOKEN_DEFAULT_CREATION_COST = 17208; // Default rent config: 6,208 prepaid rent (24h) + 11,000 compression incentive + const LIGHT_TOKEN_DEFAULT_CREATION_COST = 17208; // Default rent config: 6,208 prepaid rent (24h) + 11,000 compression incentive const LAMPORTS_PER_SOL = 1_000_000_000; const ACCOUNTS_MAX = 1000000; const splCost = numAccounts * (ACCOUNT_STORAGE_OVERHEAD + DATA_LEN) * LAMPORTS_PER_BYTE; - const ctokenCost = numAccounts * CTOKEN_DEFAULT_CREATION_COST; - const savings = splCost - ctokenCost; + const tokenCost = numAccounts * LIGHT_TOKEN_DEFAULT_CREATION_COST; + const savings = splCost - tokenCost; const savingsPercent = ((savings / splCost) * 100).toFixed(1); const handleAccountsChange = (value) => { @@ -137,7 +137,7 @@ export const LightTokenVsSplCalculator = () => { Light Token
- {formatSOL(ctokenCost)} + {formatSOL(tokenCost)}
SOL
diff --git a/snippets/jsx/token22-extensions-table.jsx b/snippets/jsx/token22-extensions-table.jsx index 65aa985..68fa3dd 100644 --- a/snippets/jsx/token22-extensions-table.jsx +++ b/snippets/jsx/token22-extensions-table.jsx @@ -18,7 +18,7 @@ export const Token22ExtensionsTable = () => { ]; const pinocchioInstructions = [ - "CTokenTransfer", + "TokenTransfer", "CreateAssociatedTokenAccount", "CreateAssociatedTokenAccountIdempotent", "CreateTokenAccount", @@ -60,63 +60,63 @@ export const Token22ExtensionsTable = () => { name: "MintCloseAuthority", description: "-", instructions: allInstructions.filter( - (i) => !["transfer", "CTokenTransfer", "Transfer2"].includes(i) + (i) => !["transfer", "TokenTransfer", "Transfer2"].includes(i) ), }, { name: "TransferFeeConfig", description: "fees must be zero", instructions: allInstructions.filter( - (i) => !["transfer", "CTokenTransfer", "Transfer2"].includes(i) + (i) => !["transfer", "TokenTransfer", "Transfer2"].includes(i) ), }, { name: "DefaultAccountState", description: "any state allowed", instructions: allInstructions.filter( - (i) => !["transfer", "CTokenTransfer", "Transfer2"].includes(i) + (i) => !["transfer", "TokenTransfer", "Transfer2"].includes(i) ), }, { name: "PermanentDelegate", description: "-", instructions: allInstructions.filter( - (i) => !["transfer", "CTokenTransfer", "Transfer2"].includes(i) + (i) => !["transfer", "TokenTransfer", "Transfer2"].includes(i) ), }, { name: "TransferHook", description: "program_id must be nil", instructions: allInstructions.filter( - (i) => !["transfer", "CTokenTransfer", "Transfer2"].includes(i) + (i) => !["transfer", "TokenTransfer", "Transfer2"].includes(i) ), }, { name: "Pausable", description: "-", instructions: allInstructions.filter( - (i) => !["transfer", "CTokenTransfer", "Transfer2"].includes(i) + (i) => !["transfer", "TokenTransfer", "Transfer2"].includes(i) ), }, { name: "ConfidentialTransferMint", description: "initialized but not enabled", instructions: allInstructions.filter( - (i) => !["transfer", "CTokenTransfer", "Transfer2"].includes(i) + (i) => !["transfer", "TokenTransfer", "Transfer2"].includes(i) ), }, { name: "ConfidentialTransferFeeConfig", description: "fees must be zero", instructions: allInstructions.filter( - (i) => !["transfer", "CTokenTransfer", "Transfer2"].includes(i) + (i) => !["transfer", "TokenTransfer", "Transfer2"].includes(i) ), }, { name: "ConfidentialMintBurn", description: "initialized but not enabled", instructions: allInstructions.filter( - (i) => !["transfer", "CTokenTransfer", "Transfer2"].includes(i) + (i) => !["transfer", "TokenTransfer", "Transfer2"].includes(i) ), }, ]; diff --git a/snippets/light-token-configure-rent.mdx b/snippets/light-token-configure-rent.mdx index ba0e0c5..5b4f701 100644 --- a/snippets/light-token-configure-rent.mdx +++ b/snippets/light-token-configure-rent.mdx @@ -1,5 +1,5 @@ ```rust -use light_compressed_token_sdk::ctoken::CompressibleParamsInfos; +use light_token_sdk::token::CompressibleParamsInfos; let compressible_params = CompressibleParamsInfos::new( compressible_config.clone(), diff --git a/snippets/light-token-guides/client-custom-rent-config.mdx b/snippets/light-token-guides/client-custom-rent-config.mdx index 586d13c..a325912 100644 --- a/snippets/light-token-guides/client-custom-rent-config.mdx +++ b/snippets/light-token-guides/client-custom-rent-config.mdx @@ -8,24 +8,24 @@ We recommend to use default values, but you can customize the rent config based 2. Set the lamports per write a transaction payer will pay for top ups ```rust -use light_compressed_token_sdk::ctoken::{ - CompressibleParams, - CreateCTokenAccount, - ctoken_v1_config_pda, // helper to derive config PDA - ctoken_v1_rent_sponsor_pda // helper to derive rent sponsor PDA +use light_token_sdk::token::{ + CompressibleParams, + CreateTokenAccount, + light_token_v1_config_pda, // helper to derive config PDA + light_token_v1_rent_sponsor_pda // helper to derive rent sponsor PDA }; -use light_ctoken_types::state::TokenDataVersion; +use light_token_types::state::TokenDataVersion; let compressible_params = CompressibleParams { - compressible_config: ctoken_v1_config_pda(), - rent_sponsor: ctoken_v1_rent_sponsor_pda(), + compressible_config: light_token_v1_config_pda(), + rent_sponsor: light_token_v1_rent_sponsor_pda(), pre_pay_num_epochs: 35, // ~52h lamports_per_write: Some(788), compress_to_account_pubkey: None, token_account_version: TokenDataVersion::ShaFlat, }; -let instruction = CreateCTokenAccount::new( +let instruction = CreateTokenAccount::new( payer.pubkey(), account.pubkey(), mint, @@ -53,9 +53,9 @@ let instruction = CreateCTokenAccount::new( - Rent Sponsor + Rent Sponsor - - CToken program PDA that fronts rent exemption at creation.
+ - Light Token program PDA that fronts rent exemption at creation.
- Claims rent when account compresses. diff --git a/snippets/setup/rust-install-dependencies.mdx b/snippets/setup/rust-install-dependencies.mdx index 334c04f..cf39be3 100644 --- a/snippets/setup/rust-install-dependencies.mdx +++ b/snippets/setup/rust-install-dependencies.mdx @@ -2,7 +2,7 @@ [dependencies] light-compressed-token-sdk = "0.1" light-client = "0.1" -light-ctoken-types = "0.1" +light-token-types = "0.1" solana-sdk = "2.2" borsh = "0.10" tokio = { version = "1.36", features = ["full"] }