Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -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 Down Expand Up @@ -474,7 +474,7 @@ import {
} 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()
// 2. Select accounts and SPL interface infos using selectMinCompressedTokenAccountsForTransfer() and selectTokenPoolInfosForDecompression()
// 3. Create decompress instruction with CompressedTokenProgram.decompress() and submit transaction

// Step 1: Setup RPC connection and define decompression parameters
Expand Down Expand Up @@ -544,7 +544,7 @@ This example converts regular SPL tokens to compressed format using `CompressedT

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


Expand Down Expand Up @@ -584,7 +584,7 @@ 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);

Expand All @@ -597,7 +597,7 @@ const amount = 1e5; // 100K tokens to compress
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
32 changes: 16 additions & 16 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 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 @@ -227,7 +227,7 @@ const owner = payer;
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 @@ -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 @@ -479,7 +479,7 @@ 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
// 1. Process recipients in chunks with selectStateTreeInfo() and selectTokenPoolInfo() per batch
// 2. Create CompressedTokenProgram.compress() instructions with ComputeBudgetProgram limits for multiple recipients
// 3. Return batched instructions for optimized large-scale airdrop execution

Expand Down Expand Up @@ -765,7 +765,7 @@ 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()
// 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 CompressedTokenProgram.compress() calls
// 3. Execute batched airdrop with signAndSendAirdropBatches() - sign transactions and confirm with sendAndConfirmTx() for large-scale distribution

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 @@ -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 Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Combine Instructions in One Transaction
description: Guide to combine multiple instructions in a single transaction. Full code example for token pool creation and for first-time compression of existing SPL tokens.
description: Combine multiple instructions in one transaction. Full example: create SPL Interface PDA and first-time compression of existing SPL tokens.
keywords: ["batch token operations solana", "combine transactions solana"]
---

Expand All @@ -9,7 +9,7 @@ import SetupEnvironment from '/snippets/setup/setup-environment-tabs.mdx';

The SDK provides instruction-level APIs that return instructions without sending transactions. Combine these instructions to build custom transactions with multiple instructions.
<Note>
This guide demonstrates creating a token pool and compressing existing SPL tokens in a single transaction.
This guide demonstrates creating an SPL interface and compressing existing SPL tokens in a single transaction.
</Note>
# Full Code Example

Expand All @@ -32,11 +32,11 @@ Make sure you have dependencies and developer environment set up!
</Step>

<Step>
### Create Token Pool + Compress
### Create SPL interface + compress

```typescript create-pool-and-compress.ts highlight={26,71} expandable
// 1. Setup: Create regular SPL token and mint to ATA
// 2. Build instructions for create token pool and compress
// 2. Build instructions for SPL interface and compress
// 3. Combine instructions in one transaction
// 4. Verify compressed balance

Expand Down Expand Up @@ -105,20 +105,20 @@ async function createPoolAndCompress() {
console.log("Regular SPL token created:", mint.toBase58());
console.log("ATA balance:", 1, "token");

// Step 2: Build instructions for create token pool and compress
// Step 2: Build instructions for SPL interface and compress
const outputStateTreeInfo = selectStateTreeInfo(await rpc.getStateTreeInfos());

// Derive token pool PDA
// Derive SPL Interface PDA
const tokenPoolPda = CompressedTokenProgram.deriveTokenPoolPda(mint);

// Create token pool instruction
const createTokenPoolIx = await CompressedTokenProgram.createTokenPool({
// Create SPL interface instruction
const createSplInterfaceIx = await CompressedTokenProgram.createSplInterface({
feePayer: payer.publicKey,
mint,
tokenProgram: TOKEN_PROGRAM_ID,
tokenProgramId: TOKEN_PROGRAM_ID,
});

// Manually construct TokenPoolInfo for first-time compression
// Manually construct TokenPoolInfo for first-time compression (SPL interface not yet on-chain)
const tokenPoolInfo = {
mint: mint,
tokenPoolPda: tokenPoolPda,
Expand Down Expand Up @@ -146,7 +146,7 @@ async function createPoolAndCompress() {

const allInstructions = [
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }),
createTokenPoolIx,
createSplInterfaceIx,
compressIx,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ Run `compress-t22.ts`.
```typescript compress-t22.ts expandable
// Token-2022 with ZK Compression - Local
// 1. Load wallet and connect to local validator
// 2. Create Token-2022 mint with metadata extension and register for compression via createTokenPool()
// 2. Create Token-2022 mint with metadata extension and register for compression via createSplInterface()
// 3. Mint SPL tokens to ATA, compress via compress(), and transfer compressed tokens via transfer()
// 4. Verify balances via getTokenAccountBalance and getCompressedTokenAccountsByOwner

import { confirmTx, createRpc } from "@lightprotocol/stateless.js";
import {
compress,
createTokenPool,
createSplInterface,
transfer,
} from "@lightprotocol/compressed-token";
import {
Expand Down Expand Up @@ -177,10 +177,10 @@ const connection = createRpc(); // defaults to localhost:8899
);
console.log(`Token-2022 mint created with address: ${mint.publicKey.toString()}`);

// Step 3: Call createTokenPool() to initialize omnibus account
// Step 3: Call createSplInterface() to initialize omnibus account
// and register Token-2022 mint with Light Token Program
// Create PDA that holds SPL tokens for compressed tokens
const registerTxId = await createTokenPool(
const registerTxId = await createSplInterface(
connection,
payer,
mint.publicKey, // Token-2022 mint to register with Light Token Program
Expand All @@ -192,7 +192,7 @@ const connection = createRpc(); // defaults to localhost:8899
const ata = await getOrCreateAssociatedTokenAccount(
connection,
payer,
mint.publicKey, // Token-2022 mint with token pool for compression
mint.publicKey, // Token-2022 mint with SPL interface for compression
payer.publicKey,
undefined,
undefined,
Expand All @@ -205,7 +205,7 @@ const connection = createRpc(); // defaults to localhost:8899
const mintToTxId = await mintToSpl(
connection,
payer,
mint.publicKey, // Token-2022 mint with token pool for compression
mint.publicKey, // Token-2022 mint with SPL interface for compression
ata.address, // destination token account
payer.publicKey, // mint authority
mintAmount, // amount to mint
Expand All @@ -222,7 +222,7 @@ const connection = createRpc(); // defaults to localhost:8899
const compressTxId = await compress(
connection,
payer,
mint.publicKey, // Token-2022 mint with token pool for compression
mint.publicKey, // Token-2022 mint with SPL interface for compression
compressAmount, // amount to compress
payer, // owner of SPL tokens
ata.address, // Source ATA for compression
Expand All @@ -237,7 +237,7 @@ const connection = createRpc(); // defaults to localhost:8899
const transferTxId = await transfer(
connection,
payer,
mint.publicKey, // Token-2022 mint with token pool for compression
mint.publicKey, // Token-2022 mint with SPL interface for compression
transferAmount,
payer,
transferRecipient.publicKey
Expand Down
2 changes: 1 addition & 1 deletion compressed-tokens/for-privy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const rpc = createRpc(RPC_ENDPOINT);
<Info>
Before we call compress or decompresss, we need:

* An SPL mint with a interface PDA for compression. This PDA can be created for new SPL mints via [`createMint()`](/compressed-tokens/guides/create-mint-with-token-pool) or added to existing SPL mints via [`createTokenPool()`](/compressed-tokens/guides/add-token-pools-to-mint-accounts).
* An SPL mint with a interface PDA for compression. This PDA can be created for new SPL mints via [`createMint()`](/compressed-tokens/guides/create-mint-with-token-pool) or added to existing SPL mints via [`createSplInterface()`](/compressed-tokens/guides/add-token-pools-to-mint-accounts).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Grammar: "a interface" → "an interface"

📝 Proposed fix
-* An SPL mint with a interface PDA for compression. This PDA can be created for new SPL mints via [`createMint()`](/compressed-tokens/guides/create-mint-with-token-pool) or added to existing SPL mints via [`createSplInterface()`](/compressed-tokens/guides/add-token-pools-to-mint-accounts).
+* An SPL mint with an interface PDA for compression. This PDA can be created for new SPL mints via [`createMint()`](/compressed-tokens/guides/create-mint-with-token-pool) or added to existing SPL mints via [`createSplInterface()`](/compressed-tokens/guides/add-token-pools-to-mint-accounts).
📝 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
* An SPL mint with a interface PDA for compression. This PDA can be created for new SPL mints via [`createMint()`](/compressed-tokens/guides/create-mint-with-token-pool) or added to existing SPL mints via [`createSplInterface()`](/compressed-tokens/guides/add-token-pools-to-mint-accounts).
* An SPL mint with an interface PDA for compression. This PDA can be created for new SPL mints via [`createMint()`](/compressed-tokens/guides/create-mint-with-token-pool) or added to existing SPL mints via [`createSplInterface()`](/compressed-tokens/guides/add-token-pools-to-mint-accounts).
🤖 Prompt for AI Agents
In `@compressed-tokens/for-privy.mdx` at line 99, Fix the grammar in the sentence
within compressed-tokens/for-privy.mdx: change the phrase "a interface PDA for
compression" to "an interface PDA for compression" (locate the exact sentence
starting "* An SPL mint with a interface PDA for compression..." and update "a"
to "an").

* For `compress()` SPL tokens in an Associated Token Account, or
* For `decompress()` compressed token accounts with sufficient balance.
</Info>
Expand Down
Loading
Loading