-
Notifications
You must be signed in to change notification settings - Fork 0
Add indexing tokens warm-up examples #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||
| ```typescript | ||||||||||
| import "dotenv/config"; | ||||||||||
| import { Keypair } from "@solana/web3.js"; | ||||||||||
| import { createRpc } from "@lightprotocol/stateless.js"; | ||||||||||
| import { | ||||||||||
| createMintInterface, | ||||||||||
| createAtaInterface, | ||||||||||
| mintToCompressed, | ||||||||||
| loadAta, | ||||||||||
| transferInterface, | ||||||||||
| getAssociatedTokenAddressInterface, | ||||||||||
| } from "@lightprotocol/compressed-token"; | ||||||||||
| import { homedir } from "os"; | ||||||||||
| import { readFileSync } from "fs"; | ||||||||||
|
|
||||||||||
| // devnet: | ||||||||||
| // const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`; | ||||||||||
| // const rpc = createRpc(RPC_URL); | ||||||||||
| // localnet: | ||||||||||
| const rpc = createRpc(); | ||||||||||
|
|
||||||||||
| const payer = Keypair.fromSecretKey( | ||||||||||
| new Uint8Array( | ||||||||||
| JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8")), | ||||||||||
| ), | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| (async function () { | ||||||||||
| // Inactive Light Tokens are cryptographically preserved on the Solana ledger | ||||||||||
| // as compressed tokens (cold storage) | ||||||||||
| // Setup: Get compressed tokens in light-token associated token account | ||||||||||
| const { mint } = await createMintInterface(rpc, payer, payer, null, 9); | ||||||||||
| await mintToCompressed(rpc, payer, mint, payer, [{ recipient: payer.publicKey, amount: 1000n }]); | ||||||||||
|
|
||||||||||
| const recipient = Keypair.generate(); | ||||||||||
| await createAtaInterface(rpc, payer, mint, recipient.publicKey); | ||||||||||
|
|
||||||||||
| const senderAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); | ||||||||||
| const recipientAta = getAssociatedTokenAddressInterface(mint, recipient.publicKey); | ||||||||||
|
|
||||||||||
| // Warm up: load compressed tokens to associated token account | ||||||||||
| // Returns null if already hot | ||||||||||
| await loadAta(rpc, senderAta, payer, mint, payer); | ||||||||||
|
|
||||||||||
| // Transfer tokens from hot balance | ||||||||||
| const tx = await transferInterface( | ||||||||||
| rpc, | ||||||||||
| payer, | ||||||||||
| senderAta, | ||||||||||
| mint, | ||||||||||
| recipientAta, | ||||||||||
| payer, | ||||||||||
| 500n, | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| console.log("Tx:", tx); | ||||||||||
| })();``` | ||||||||||
|
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline before closing code fence. The closing 📝 Proposed fix console.log("Tx:", tx);
-})();```
+})();
+```📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| ```typescript | ||
| import "dotenv/config"; | ||
| import { Keypair } from "@solana/web3.js"; | ||
| import { | ||
| createRpc, | ||
| buildAndSignTx, | ||
| sendAndConfirmTx, | ||
| } from "@lightprotocol/stateless.js"; | ||
| import { | ||
| createMintInterface, | ||
| createAtaInterface, | ||
| mintToCompressed, | ||
| createLoadAtaInstructions, | ||
| createTransferInterfaceInstruction, | ||
| getAssociatedTokenAddressInterface, | ||
| } from "@lightprotocol/compressed-token"; | ||
| import { homedir } from "os"; | ||
| import { readFileSync } from "fs"; | ||
|
|
||
| // devnet: | ||
| // const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`; | ||
| // const rpc = createRpc(RPC_URL); | ||
| // localnet: | ||
| const rpc = createRpc(); | ||
|
|
||
| const payer = Keypair.fromSecretKey( | ||
| new Uint8Array( | ||
| JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8")), | ||
| ), | ||
| ); | ||
|
|
||
| (async function () { | ||
| // Inactive Light Tokens are cryptographically preserved on the Solana ledger | ||
| // as compressed tokens (cold storage) | ||
| // Setup: Get compressed tokens in light-token associated token account | ||
| const { mint } = await createMintInterface(rpc, payer, payer, null, 9); | ||
| await mintToCompressed(rpc, payer, mint, payer, [{ recipient: payer.publicKey, amount: 1000n }]); | ||
|
|
||
| const recipient = Keypair.generate(); | ||
| await createAtaInterface(rpc, payer, mint, recipient.publicKey); | ||
|
|
||
| const senderAta = getAssociatedTokenAddressInterface(mint, payer.publicKey); | ||
| const recipientAta = getAssociatedTokenAddressInterface( | ||
| mint, | ||
| recipient.publicKey, | ||
| ); | ||
|
|
||
| // Warm up: load compressed tokens (cold) to sender's hot balance | ||
| // Returns [] if already hot — safe to call unconditionally | ||
| const loadIxs = await createLoadAtaInstructions( | ||
| rpc, | ||
| senderAta, | ||
| payer.publicKey, | ||
| mint, | ||
| payer.publicKey, | ||
| ); | ||
|
|
||
| if (loadIxs.length > 0) { | ||
| const blockhash = await rpc.getLatestBlockhash(); | ||
| const loadTx = buildAndSignTx(loadIxs, payer, blockhash.blockhash); | ||
| await sendAndConfirmTx(rpc, loadTx); | ||
| } | ||
|
|
||
| // Trade: transfer from hot balance | ||
| const transferIx = createTransferInterfaceInstruction( | ||
| senderAta, | ||
| recipientAta, | ||
| payer.publicKey, | ||
| 500n, | ||
| ); | ||
|
|
||
| const blockhash = await rpc.getLatestBlockhash(); | ||
| const tradeTx = buildAndSignTx([transferIx], payer, blockhash.blockhash); | ||
| const signature = await sendAndConfirmTx(rpc, tradeTx); | ||
|
|
||
| console.log("Tx:", signature); | ||
| })();``` | ||
|
Comment on lines
+76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline before closing code fence. Same issue as the action snippet - the closing fence needs a preceding newline for proper markdown rendering. 📝 Proposed fix console.log("Tx:", signature);
-})();```
+})();
+```🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hyphenate "warm up" when used as a compound modifier.
Per static analysis, "warm up" should be hyphenated as "warm-up" when used as an adjective modifying "instruction".
📝 Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~19-~19: Use a hyphen to join words.
Context: ...t prepend an idempotent decompress "warm up" instruction. Find the sour...
(QB_NEW_EN_HYPHEN)
🤖 Prompt for AI Agents