Skip to content

Commit a7866c2

Browse files
author
tilo-14
committed
Sync Privy snippets with latest examples
1 parent 6accbe4 commit a7866c2

13 files changed

Lines changed: 772 additions & 176 deletions

File tree

compressed-tokens/for-privy.mdx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sidebarTitle: "Privy Guide"
44
description: "Integrate compressed tokens with Privy embedded wallets for rent-free SPL token accounts and transfers."
55
keywords: ["privy solana", "privy compressed tokens", "embedded wallet compression", "rent-free tokens privy"]
66
---
7-
import ToolkitsSetup from "/snippets/setup/toolkits-setup.mdx";
7+
import Toolkits2Setup from "/snippets/setup/toolkits2-setup.mdx";
88
import TransferNodejs from "/snippets/code-snippets/privy/transfer/nodejs.mdx";
99
import TransferReact from "/snippets/code-snippets/privy/transfer/react.mdx";
1010
import CompressNodejs from "/snippets/code-snippets/privy/compress/nodejs.mdx";
@@ -16,6 +16,7 @@ import BalancesReact from "/snippets/code-snippets/privy/balances/react.mdx";
1616
import TransactionHistoryNodejs from "/snippets/code-snippets/privy/transaction-history/nodejs.mdx";
1717
import TransactionHistoryReact from "/snippets/code-snippets/privy/transaction-history/react.mdx";
1818
import ActionCode from '/snippets/code-snippets/compressed-token/create-mint/action.mdx';
19+
import AiPrompt from "/snippets/ai-prompts/privy-nodejs-compressed.mdx";
1920

2021
| Creation Cost | SPL Token Account | Compressed Token |
2122
| :------------ | :---------------- | :--------------- |
@@ -39,38 +40,40 @@ Privy handles user authentication and wallet management. You build transactions
3940
</thead>
4041
<tbody>
4142
<tr>
42-
<td>**Get Balance**</td>
43-
<td>getAccount()</td>
44-
<td>getCompressedTokenAccountsByOwner()</td>
45-
</tr>
46-
<tr>
47-
<td>**Transfer**</td>
43+
<td>[**Transfer**](#full-code-examples)</td>
4844
<td>transferChecked()</td>
4945
<td>transfer()</td>
5046
</tr>
5147
<tr>
52-
<td>**Compress**</td>
48+
<td>[**Compress**](#full-code-examples)</td>
5349
<td>N/A</td>
5450
<td>compress()</td>
5551
</tr>
5652
<tr>
57-
<td>**Decompress**</td>
53+
<td>[**Decompress**](#full-code-examples)</td>
5854
<td>N/A</td>
5955
<td>decompress()</td>
6056
</tr>
6157
<tr>
62-
<td>**Transaction History**</td>
58+
<td>[**Get Balance**](#get-balances)</td>
59+
<td>getAccount()</td>
60+
<td>getCompressedTokenAccountsByOwner()</td>
61+
</tr>
62+
<tr>
63+
<td>[**Transaction History**](#get-transaction-history)</td>
6364
<td>getSignaturesForAddress()</td>
6465
<td>getCompressionSignaturesForOwner()</td>
6566
</tr>
6667
</tbody>
6768
</table>
6869

70+
<Tabs>
71+
<Tab title="Guide">
6972
<Steps>
7073
<Step>
7174
### Prerequisites
7275

73-
<ToolkitsSetup />
76+
<Toolkits2Setup />
7477

7578
Connect to an RPC endpoint that supports ZK Compression (Helius, Triton)
7679
```typescript
@@ -90,9 +93,9 @@ const rpc = createRpc(RPC_ENDPOINT);
9093

9194

9295
<Info>
93-
Before we can compress or decompresss, we need:
96+
Before we call compress or decompresss, we need:
9497

95-
* An SPL mint with a token pool for compression. This token pool 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).
98+
* 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).
9699
* For `compress()` SPL tokens in an Associated Token Account, or
97100
* For `decompress()` compressed token accounts with sufficient balance.
98101
</Info>
@@ -105,7 +108,7 @@ Before we can compress or decompresss, we need:
105108
## Full Code Examples
106109

107110
<Info>
108-
Find complete examples on Github: [privy/nodejs-privy-compressed](https://github.com/Lightprotocol/examples-zk-compression/tree/main/privy/nodejs-privy-compressed) and [privy/react-privy-compressed](https://github.com/Lightprotocol/examples-zk-compression/tree/main/privy/react-privy-compressed).
111+
Find complete examples on Github: [nodejs](https://github.com/Lightprotocol/examples-zk-compression/tree/main/privy/nodejs-privy-compressed) and [react](https://github.com/Lightprotocol/examples-zk-compression/tree/main/privy/react-privy-compressed).
109112
</Info>
110113

111114
<Tabs>
@@ -188,3 +191,9 @@ Fetch compressed token transaction history for an owner, with optional detailed
188191
<TransactionHistoryReact />
189192
</Tab>
190193
</Tabs>
194+
</Tab>
195+
196+
<Tab title="AI Prompt">
197+
<AiPrompt />
198+
</Tab>
199+
</Tabs>

light-token/toolkits/for-streaming-mints.mdx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ Find devnet examples [here](https://github.com/Lightprotocol/examples-light-toke
2222
helius-laserstream = "0.1"
2323
tokio = { version = "1", features = ["full"] }
2424
futures = "0.3"
25-
light-event = "0.2"
26-
light-compressed-account = "0.7"
27-
light-token-interface = "0.1"
25+
light-event = "0.3"
26+
light-compressed-account = "0.8"
27+
light-token-interface = "0.2"
2828
borsh = "0.10"
2929
bs58 = "0.5"
3030
```
@@ -33,7 +33,7 @@ bs58 = "0.5"
3333
use futures::StreamExt;
3434
use helius_laserstream::{subscribe, LaserstreamConfig};
3535
use light_event::parse::event_from_light_transaction;
36-
use light_token_interface::state::mint::CompressedMint;
36+
use light_token_interface::state::mint::Mint;
3737
use light_token_interface::state::extensions::ExtensionStruct;
3838
use borsh::BorshDeserialize;
3939

@@ -143,7 +143,7 @@ for output in event.output_compressed_accounts.iter() {
143143
};
144144

145145
// Deserialize
146-
let mint = CompressedMint::try_from_slice(data)?;
146+
let mint = Mint::try_from_slice(data)?;
147147

148148
// Check if new (address not in inputs)
149149
let is_new = output
@@ -166,7 +166,7 @@ for output in event.output_compressed_accounts.iter() {
166166
### Extract Token Metadata from Mint Extensions
167167

168168
```rust
169-
fn extract_metadata(mint: &CompressedMint) -> Option<(String, String, String)> {
169+
fn extract_metadata(mint: &Mint) -> Option<(String, String, String)> {
170170
let extensions = mint.extensions.as_ref()?;
171171

172172
for ext in extensions {
@@ -199,9 +199,15 @@ if let Some((name, symbol, uri)) = extract_metadata(&mint) {
199199

200200
```rust
201201
#[repr(C)]
202-
pub struct CompressedMint {
202+
pub struct Mint {
203203
pub base: BaseMint,
204-
pub metadata: CompressedMintMetadata,
204+
pub metadata: MintMetadata,
205+
/// Reserved bytes (16 bytes) for T22 layout compatibility.
206+
pub reserved: [u8; 16],
207+
/// Account type discriminator at byte offset 165 (1 = Mint, 2 = Account)
208+
pub account_type: u8,
209+
/// Compression info embedded directly in the mint
210+
pub compression: CompressionInfo,
205211
pub extensions: Option<Vec<ExtensionStruct>>,
206212
}
207213

@@ -215,12 +221,20 @@ pub struct BaseMint {
215221
pub freeze_authority: Option<Pubkey>,
216222
}
217223

218-
/// metadata used by the light token program (34 bytes)
224+
/// Light Protocol-specific metadata for compressed mints.
225+
/// Total size: 67 bytes
219226
#[repr(C)]
220-
pub struct CompressedMintMetadata {
227+
pub struct MintMetadata {
228+
/// Version for upgradability
221229
pub version: u8,
222-
pub spl_mint_initialized: bool,
223-
pub mint: Pubkey, // PDA with compressed mint seed
230+
/// Whether the compressed mint has been decompressed to a Mint Solana account.
231+
pub mint_decompressed: bool,
232+
/// PDA derived from mint_signer
233+
pub mint: Pubkey,
234+
/// Signer pubkey used to derive the mint PDA
235+
pub mint_signer: [u8; 32],
236+
/// Bump seed from mint PDA derivation
237+
pub bump: u8,
224238
}
225239
```
226240

references/migration-v1-to-v2.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ let new_address_params = instruction_data
253253

254254
</Tab>
255255

256+
<Tab title="AI Prompt">
257+
<V1ToV2MigrationPrompt />
258+
</Tab>
256259
</Tabs>
257260

258261

scripts/copy-privy-snippets.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Wraps each file in typescript markdown code blocks
55

66
NODEJS_SRC="/home/tilo/Workspace/examples-zk-compression/privy/nodejs-privy-compressed/src"
7+
REACT_SRC="/home/tilo/Workspace/examples-zk-compression/privy/react-privy-compressed/src/hooks"
78
SNIPPETS_DIR="/home/tilo/Workspace/docs/snippets/code-snippets/privy"
89

910
# Operations to process
@@ -32,6 +33,15 @@ wrap_typescript "$NODEJS_SRC/decompress.ts" "$SNIPPETS_DIR/decompress/nodejs.mdx
3233
wrap_typescript "$NODEJS_SRC/balances.ts" "$SNIPPETS_DIR/balances/nodejs.mdx"
3334
wrap_typescript "$NODEJS_SRC/get-transaction-history.ts" "$SNIPPETS_DIR/transaction-history/nodejs.mdx"
3435

36+
# Process React operations (hooks)
37+
echo ""
38+
echo "Processing React operations..."
39+
wrap_typescript "$REACT_SRC/useTransfer.ts" "$SNIPPETS_DIR/transfer/react.mdx"
40+
wrap_typescript "$REACT_SRC/useCompress.ts" "$SNIPPETS_DIR/compress/react.mdx"
41+
wrap_typescript "$REACT_SRC/useDecompress.ts" "$SNIPPETS_DIR/decompress/react.mdx"
42+
wrap_typescript "$REACT_SRC/useCompressedBalances.ts" "$SNIPPETS_DIR/balances/react.mdx"
43+
wrap_typescript "$REACT_SRC/useTransactionHistory.ts" "$SNIPPETS_DIR/transaction-history/react.mdx"
44+
3545
echo ""
3646
echo "Done! Created snippets in: $SNIPPETS_DIR"
3747
echo ""

0 commit comments

Comments
 (0)