Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api-reference/json-rpc-methods/getvalidityproof.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ async function generateProofForTransfer() {
console.log(\` Token accounts: ${hashes.length}\`);
console.log(\` Roots: ${validityProof.roots.length}\`);

// This proof is now ready to use with CompressedTokenProgram.transfer()
// This proof is now ready to use with LightTokenProgram.transfer()
console.log('\nProof ready for token transfer instruction');
console.log('Use this with:');
console.log(' recentValidityProof: validityProof.compressedProof');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ import {
buildAndSignTx,
} from "@lightprotocol/stateless.js";
import {
CompressedTokenProgram,
LightTokenProgram,
selectMinCompressedTokenAccountsForTransfer,
} from "@lightprotocol/compressed-token";
import { ComputeBudgetProgram, Keypair, PublicKey } from "@solana/web3.js";
Expand Down Expand Up @@ -158,7 +158,7 @@ const amount = bn(1e8);
inputAccounts.map((account) => account.compressedAccount.hash)
);

const ix = await CompressedTokenProgram.transfer({
const ix = await LightTokenProgram.transfer({
payer: payer.publicKey,
inputCompressedTokenAccounts: inputAccounts,
toAddress: recipient.publicKey,
Expand Down Expand Up @@ -291,7 +291,7 @@ import * as fs from 'fs';
import * as os from 'os';

// 1. Setup RPC connection and load filesystem wallet for mint operations
// 2. Call createMint() to create SPL mint with token pool for compression
// 2. Call createMint() to create SPL mint with SPL interface for compression
// 3. Call mintTo() to mint compressed tokens to filesystem wallet

const connection: Rpc = createRpc(); // defaults to localhost:8899
Expand All @@ -307,7 +307,7 @@ const mintKeypair = Keypair.generate();
await connection.requestAirdrop(payer.publicKey, 1e9);
await new Promise(resolve => setTimeout(resolve, 1000));

// Create SPL mint with token pool for compression
// Create SPL mint with SPL interface for compression
const { mint, transactionSignature } = await createMint(
connection,
payer,
Expand All @@ -322,7 +322,7 @@ const mintKeypair = Keypair.generate();
const mintToTxId = await mintTo(
connection,
payer,
mint, // SPL mint with token pool for compression
mint, // SPL mint with SPL interface for compression
payer.publicKey, // recipient address
payer,
10e9,
Expand All @@ -344,7 +344,7 @@ Make sure you add your Mint address to `send-tokens.ts`.
// 1. Load wallet and fetch compressed token accounts with getCompressedTokenAccountsByOwner()
// 2. Select accounts for transfer using selectMinCompressedTokenAccountsForTransfer()
// and get validity proof with getValidityProof()
// 3. Create transfer instruction with CompressedTokenProgram.transfer()
// 3. Create transfer instruction with LightTokenProgram.transfer()
// and submit transaction with sendAndConfirmTx()
// 4. Verify balances via getCompressedTokenAccountsByOwner()

Expand All @@ -357,7 +357,7 @@ import {
buildAndSignTx,
} from "@lightprotocol/stateless.js";
import {
CompressedTokenProgram,
LightTokenProgram,
selectMinCompressedTokenAccountsForTransfer,
} from "@lightprotocol/compressed-token";
import { ComputeBudgetProgram, Keypair, PublicKey } from "@solana/web3.js";
Expand All @@ -381,7 +381,7 @@ const amount = bn(1e8);
// Step 2: Fetch compressed account hashes from state trees
const compressedTokenAccounts =
await connection.getCompressedTokenAccountsByOwner(owner.publicKey, {
mint, // SPL mint with token pool for compression
mint, // SPL mint with SPL interface for compression
});

if (compressedTokenAccounts.items.length === 0) {
Expand All @@ -405,7 +405,7 @@ const amount = bn(1e8);
);

// Step 4: Create transfer instruction that consumes input accounts and creates new output accounts
const ix = await CompressedTokenProgram.transfer({
const ix = await LightTokenProgram.transfer({
payer: payer.publicKey,
inputCompressedTokenAccounts: inputAccounts, // accounts to consume
toAddress: recipient.publicKey,
Expand Down Expand Up @@ -454,7 +454,7 @@ Use these integrations to let users convert between regular and compressed forma

<Accordion title="Decompress to Regular SPL">

This example converts compressed tokens to regular SPL format using `CompressedTokenProgram.decompress().`
This example converts compressed tokens to regular SPL format using `LightTokenProgram.decompress().`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Punctuation inside backtick makes method reference look like a chained property access.

The trailing period is inside the backtick: `LightTokenProgram.decompress().` which renders as a property access. Move the period outside.

Same issue on line 543 with `LightTokenProgram.compress().`.

Proposed fix
-This example converts compressed tokens to regular SPL format using `LightTokenProgram.decompress().`
+This example converts compressed tokens to regular SPL format using `LightTokenProgram.decompress()`.

Line 543:

-This example converts regular SPL tokens to compressed format using `LightTokenProgram.compress().`
+This example converts regular SPL tokens to compressed format using `LightTokenProgram.compress()`.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
This example converts compressed tokens to regular SPL format using `LightTokenProgram.decompress().`
This example converts compressed tokens to regular SPL format using `LightTokenProgram.decompress()`.
🤖 Prompt for AI Agents
In
`@compressed-tokens/advanced-guides/add-wallet-support-for-compressed-tokens.mdx`
at line 457, The backticks around method references include trailing
punctuation, making them render like chained property access; update occurrences
of `LightTokenProgram.decompress().` and `LightTokenProgram.compress().` so the
trailing period is outside the backticks (e.g.,
`LightTokenProgram.decompress()`.). Locate the two instances (one at the example
that says "This example converts compressed tokens..." and the other on the line
that references compress) and move the period outside the inline code span for
correct rendering.


```javascript
import {
Expand All @@ -467,15 +467,15 @@ import {
} from "@lightprotocol/stateless.js";
import { ComputeBudgetProgram } from "@solana/web3.js";
import {
CompressedTokenProgram,
LightTokenProgram,
getTokenPoolInfos,
selectMinCompressedTokenAccountsForTransfer,
selectTokenPoolInfosForDecompression,
} from "@lightprotocol/compressed-token";

// 1. Setup RPC connection and fetch compressed token accounts with getCompressedTokenAccountsByOwner()
// 2. Select accounts and token pool infos using selectMinCompressedTokenAccountsForTransfer() and selectTokenPoolInfosForDecompression()
// 3. Create decompress instruction with CompressedTokenProgram.decompress() and submit transaction
// 2. Select accounts and SPL interface infos using selectMinCompressedTokenAccountsForTransfer() and selectTokenPoolInfosForDecompression()
// 3. Create decompress instruction with LightTokenProgram.decompress() and submit transaction

// Step 1: Setup RPC connection and define decompression parameters
const connection: Rpc = createRpc("https://mainnet.helius-rpc.com?api-key=<api_key>";);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Pre-existing syntax error: stray semicolon inside createRpc() call.

createRpc("https://mainnet.helius-rpc.com?api-key=<api_key>";);

The ; between the closing quote and ) is invalid JavaScript. Users copying this snippet will get a syntax error.

Proposed fix
-const connection: Rpc = createRpc("https://mainnet.helius-rpc.com?api-key=<api_key>";);
+const connection: Rpc = createRpc("https://mainnet.helius-rpc.com?api-key=<api_key>");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const connection: Rpc = createRpc("https://mainnet.helius-rpc.com?api-key=<api_key>";);
const connection: Rpc = createRpc("https://mainnet.helius-rpc.com?api-key=<api_key>");
🤖 Prompt for AI Agents
In
`@compressed-tokens/advanced-guides/add-wallet-support-for-compressed-tokens.mdx`
at line 481, The createRpc call for the connection contains a stray semicolon
inside the parentheses causing a syntax error; update the Rpc initialization
(variable connection and the createRpc(...) invocation) to remove the extra
semicolon so the string argument ends with the closing quote and then the
closing parenthesis — ensure
createRpc("https://mainnet.helius-rpc.com?api-key=<api_key>") is used (keeping
the API key placeholder intact).

Expand Down Expand Up @@ -510,7 +510,7 @@ const amount = 1e5; // 100K tokens to decompress
);

// 5. Build instruction
const ix = await CompressedTokenProgram.decompress({
const ix = await LightTokenProgram.decompress({
payer: payer.publicKey,
inputCompressedTokenAccounts: inputAccounts,
toAddress: owner.publicKey,
Expand Down Expand Up @@ -540,12 +540,12 @@ const amount = 1e5; // 100K tokens to decompress

<Accordion title="Compress Regular SPL Tokens">

This example converts regular SPL tokens to compressed format using `CompressedTokenProgram.compress().`
This example converts regular SPL tokens to compressed format using `LightTokenProgram.compress().`

```typescript
// 1. Setup RPC connection and get user ATA with getOrCreateAssociatedTokenAccount()
// 2. Fetch state tree and token pool infos using getStateTreeInfos() and getTokenPoolInfos()
// 3. Create compress instruction with CompressedTokenProgram.compress() and submit transaction
// 2. Fetch state tree and SPL interface infos using getStateTreeInfos() and getTokenPoolInfos()
// 3. Create compress instruction with LightTokenProgram.compress() and submit transaction


import {
Expand All @@ -557,7 +557,7 @@ import {
} from "@lightprotocol/stateless.js";
import { ComputeBudgetProgram } from "@solana/web3.js";
import {
CompressedTokenProgram,
LightTokenProgram,
getTokenPoolInfos,
selectTokenPoolInfo,
} from "@lightprotocol/compressed-token";
Expand All @@ -584,20 +584,20 @@ const amount = 1e5; // 100K tokens to compress
const treeInfos = await connection.getStateTreeInfos();
const treeInfo = selectStateTreeInfo(treeInfos);

// Step 4: Fetch and select token pool info for compression
// Step 4: Fetch and select SPL interface info for compression
const tokenPoolInfos = await getTokenPoolInfos(connection, mint);
const tokenPoolInfo = selectTokenPoolInfo(tokenPoolInfos);

// Step 5: Create compress instruction - transfer SPL tokens to pool and create compressed accounts
const compressInstruction = await CompressedTokenProgram.compress({
const compressInstruction = await LightTokenProgram.compress({
payer: payer.publicKey, // fee payer
owner: payer.publicKey, // owner of source SPL tokens
source: sourceTokenAccount.address, // source ATA address
toAddress: payer.publicKey, // recipient of compressed tokens (self)
amount, // amount to compress
mint, // token mint address
outputStateTreeInfo: treeInfo, // state tree for compressed accounts
tokenPoolInfo, // token pool for compression
tokenPoolInfo,
});

// Step 6: Build, sign, and submit compression transaction
Expand Down
56 changes: 28 additions & 28 deletions compressed-tokens/advanced-guides/airdrop.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Run this `mint-spl-tokens.ts` to mint SPL tokens to your wallet.
```typescript mint-spl-tokens.ts expandable
// Mint SPL Tokens for Airdrop - LocalNet
// 1. Load wallet and connect to local validator
// 2. Create SPL mint with token pool for compression via createMint()
// 2. Create SPL mint with SPL interface via createMint()
// 3. Create ATA and mint SPL tokens to sender for airdrop preparation
// 4. Output mint address for use in simple-airdrop.ts

Expand All @@ -82,7 +82,7 @@ import {
getOrCreateAssociatedTokenAccount,
mintTo,
} from "@solana/spl-token";
import { createTokenPool } from "@lightprotocol/compressed-token";
import { createSplInterface } from "@lightprotocol/compressed-token";
import * as fs from 'fs';
import * as os from 'os';

Expand All @@ -95,18 +95,18 @@ const secretKey = JSON.parse(fs.readFileSync(walletPath, 'utf8'));
const payer = Keypair.fromSecretKey(Buffer.from(secretKey));

(async () => {
// Step 2: Create SPL mint with token pool for compression
// Step 2: Create SPL mint with SPL interface
const mint = await createMint(connection, payer, payer.publicKey, null, 9);
const poolTxId = await createTokenPool(connection, payer, mint);
const poolTxId = await createSplInterface(connection, payer, mint);
console.log(`Mint address: ${mint.toBase58()}`);
console.log(`TokenPool created: ${poolTxId}`);
console.log(`SPL interface created: ${poolTxId}`);

// Step 3: Create associated token account for sender
// The sender will send tokens from this account to the recipients as compressed tokens.
const ata = await getOrCreateAssociatedTokenAccount(
connection,
payer,
mint, // SPL mint with token pool for compression
mint, // SPL mint with SPL interface for compression
payer.publicKey
);
console.log(`ATA address: ${ata.address.toBase58()}`);
Expand All @@ -116,7 +116,7 @@ const payer = Keypair.fromSecretKey(Buffer.from(secretKey));
const mintToTxId = await mintTo(
connection,
payer,
mint, // SPL mint with token pool for compression
mint, // SPL mint with SPL interface for compression
ata.address, // distributor ATA
payer.publicKey,
100_000_000_000 // amount: 100 tokens with 9 decimals
Expand All @@ -141,13 +141,13 @@ Ensure you have the latest `@lightprotocol/stateless.js` and `@lightprotocol/com
```typescript simple-airdrop.ts expandable highlight={29-30,45,74,100}
// Simple Airdrop - LocalNet
// 1. Load wallet and select compression infrastructure with getStateTreeInfos() and getTokenPoolInfos()
// 2. Build CompressedTokenProgram.compress() instruction for multiple recipients in one transaction
// 2. Build LightTokenProgram.compress() instruction for multiple recipients in one transaction
// 3. Execute transaction with compute budget and confirm compression operation with sendAndConfirmTx()
// 4. Verify distribution via getCompressedTokenAccountsByOwner

import { Keypair, PublicKey, ComputeBudgetProgram } from "@solana/web3.js";
import {
CompressedTokenProgram,
LightTokenProgram,
getTokenPoolInfos,
selectTokenPoolInfo,
} from "@lightprotocol/compressed-token";
Expand Down Expand Up @@ -175,7 +175,7 @@ const payer = Keypair.fromSecretKey(Buffer.from(secretKey));
const owner = payer;

(async () => {
// Step 2: Select state tree and token pool
// Step 2: Select state tree and SPL interface
const activeStateTrees = await connection.getStateTreeInfos();
const treeInfo = selectStateTreeInfo(activeStateTrees);

Expand All @@ -187,7 +187,7 @@ const owner = payer;
const sourceTokenAccount = await getOrCreateAssociatedTokenAccount(
connection,
payer,
mint, // SPL mint with token pool for compression
mint, // SPL mint with SPL interface for compression
payer.publicKey
);

Expand Down Expand Up @@ -221,13 +221,13 @@ const owner = payer;
);

// Create compression instruction for multiple recipients in one transaction
const compressInstruction = await CompressedTokenProgram.compress({
const compressInstruction = await LightTokenProgram.compress({
payer: payer.publicKey,
owner: owner.publicKey,
source: sourceTokenAccount.address, // source ATA holding SPL tokens
toAddress: airDropAddresses, // recipient addresses for compressed tokens
amount: amounts, // different amounts for each recipient
mint, // SPL mint with token pool for compression
mint, // SPL mint with SPL interface for compression
tokenPoolInfo: info,
outputStateTreeInfo: treeInfo, // destination state tree
});
Expand Down Expand Up @@ -346,7 +346,7 @@ Run the airdrop script with your configured environment:

```typescript expandable
// 1. Load environment and select compression infrastructure with getStateTreeInfos() and getTokenPoolInfos()
// 2. Build CompressedTokenProgram.compress() instruction for multiple recipients in one transaction
// 2. Build LightTokenProgram.compress() instruction for multiple recipients in one transaction
// 3. Execute transaction with compute budget, address lookup table, and confirm with sendAndConfirmTx()
// 4. Verify distribution via getCompressedTokenAccountsByOwner

Expand All @@ -356,7 +356,7 @@ import {
ComputeBudgetProgram,
} from '@solana/web3.js';
import {
CompressedTokenProgram,
LightTokenProgram,
getTokenPoolInfos,
selectTokenPoolInfo,
} from '@lightprotocol/compressed-token';
Expand Down Expand Up @@ -387,7 +387,7 @@ import { MINT_ADDRESS, PAYER_KEYPAIR, RPC_ENDPOINT } from '../constants';
const treeInfos = await connection.getStateTreeInfos(); // Fixed: removed deprecated getCachedActiveStateTreeInfos
const treeInfo = selectStateTreeInfo(treeInfos);

// 2. Select a token pool
// 2. Select SPL interface
const tokenPoolInfos = await getTokenPoolInfos(connection, mintAddress);
const tokenPoolInfo = selectTokenPoolInfo(tokenPoolInfos);

Expand Down Expand Up @@ -415,7 +415,7 @@ import { MINT_ADDRESS, PAYER_KEYPAIR, RPC_ENDPOINT } from '../constants';
}),
];

const compressInstruction = await CompressedTokenProgram.compress({
const compressInstruction = await LightTokenProgram.compress({
payer: payer.publicKey,
owner: owner.publicKey,
source: sourceTokenAccount.address,
Expand Down Expand Up @@ -479,12 +479,12 @@ Process recipients in chunks and create batched instructions with optimized comp

```typescript create-instructions.ts expandable

// 1. Process recipients in chunks with selectStateTreeInfo() and selectTokenPoolInfo() for each batch
// 2. Create CompressedTokenProgram.compress() instructions with ComputeBudgetProgram limits for multiple recipients
// 1. Process recipients in chunks with selectStateTreeInfo() and selectTokenPoolInfo() per batch
// 2. Create LightTokenProgram.compress() instructions with ComputeBudgetProgram limits for multiple recipients
// 3. Return batched instructions for optimized large-scale airdrop execution

import {
CompressedTokenProgram,
LightTokenProgram,
TokenPoolInfo,
} from "@lightprotocol/compressed-token";
import {
Expand Down Expand Up @@ -561,7 +561,7 @@ export async function createAirdropInstructions({

if (recipientBatch.length === 0) break;

const compressIx = await CompressedTokenProgram.compress({
const compressIx = await LightTokenProgram.compress({
payer,
owner: payer,
source: sourceTokenAccount,
Expand Down Expand Up @@ -765,8 +765,8 @@ export async function* signAndSendAirdropBatches(
Put it all together in the main airdrop file.

```typescript airdrop.ts expandable
// 1. Create compressed mint with createMint(), mint supply with mintTo(), get infrastructure with getStateTreeInfos() and getTokenPoolInfos()
// 2. Generate batched compression instructions with createAirdropInstructions() - create CompressedTokenProgram.compress() calls
// 1. Create compressed mint with createMint(), mint supply with mintTo(), get infrastructure with getStateTreeInfos() and getTokenPoolInfos() (SPL interface infos)
// 2. Generate batched compression instructions with createAirdropInstructions() - create LightTokenProgram.compress() calls
// 3. Execute batched airdrop with signAndSendAirdropBatches() - sign transactions and confirm with sendAndConfirmTx() for large-scale distribution

import { Keypair, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
Expand Down Expand Up @@ -851,7 +851,7 @@ const recipients = [
// 6a: Fetch available state trees for compressed account storage
const stateTreeInfos = await connection.getStateTreeInfos();

// 6b: Get token pool infos for compression operations
// 6b: Get SPL interface infos for compression
const tokenPoolInfos = await getTokenPoolInfos(connection, mint);

// Step 7: Create instruction batches for large-scale airdrop
Expand All @@ -863,7 +863,7 @@ const recipients = [
sourceTokenAccount: ata.address, // source ATA holding SPL tokens
mint, // token mint
stateTreeInfos, // state trees for compressed accounts
tokenPoolInfos, // token pools for compression
tokenPoolInfos,
computeUnitPrice: calculateComputeUnitPrice(10_000, 500_000), // dynamic priority fee
});

Expand Down Expand Up @@ -913,7 +913,7 @@ import {
} from "@lightprotocol/stateless.js";
import { ComputeBudgetProgram, Keypair, PublicKey } from "@solana/web3.js";
import {
CompressedTokenProgram,
LightTokenProgram,
getTokenPoolInfos,
selectMinCompressedTokenAccountsForTransfer,
selectTokenPoolInfosForDecompression,
Expand Down Expand Up @@ -958,7 +958,7 @@ const connection: Rpc = createRpc(RPC_ENDPOINT);
inputAccounts.map((account) => account.compressedAccount.hash)
);

// 5. Fetch token pool infos
// 5. Fetch SPL interface infos
const tokenPoolInfos = await getTokenPoolInfos(connection, mint);

// 6. Select
Expand All @@ -968,7 +968,7 @@ const connection: Rpc = createRpc(RPC_ENDPOINT);
);

// 7. Build instruction
const ix = await CompressedTokenProgram.decompress({
const ix = await LightTokenProgram.decompress({
payer: payer.publicKey,
inputCompressedTokenAccounts: inputAccounts,
toAddress: ata.address,
Expand Down
Loading
Loading