Skip to content

Commit 47b310f

Browse files
wip
1 parent 67b3aad commit 47b310f

17 files changed

Lines changed: 124 additions & 74 deletions

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
},
3636
"homepage": "https://github.com/Lightprotocol/example-nodejs-client#readme",
3737
"dependencies": {
38-
"@lightprotocol/compressed-token": "0.20.9",
39-
"@lightprotocol/stateless.js": "0.20.9",
38+
"@lightprotocol/compressed-token": "0.21.0",
39+
"@lightprotocol/stateless.js": "0.21.0",
4040
"@solana/spl-token": "0.3.9",
4141
"@solana/spl-token-metadata": "^0.1.6",
4242
"@solana/web3.js": "^1.98.0",

src/internal/create-account-pulse.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
createRpc,
44
LightSystemProgram,
55
Rpc,
6+
selectStateTreeInfo,
67
} from "@lightprotocol/stateless.js";
78
import { PAYER_KEYPAIR, RPC_ENDPOINT } from "../constants";
89
import { randomBytes } from "crypto";
@@ -26,7 +27,9 @@ const trees = [
2627
(async () => {
2728
try {
2829
while (true) {
29-
const pseudoRandomTree = trees[Math.floor(Math.random() * trees.length)];
30+
const stateTreeInfos = await connection.getStateTreeInfos();
31+
const treeInfo = selectStateTreeInfo(stateTreeInfos);
32+
3033
// Create account with random address
3134
const randomSeed = new Uint8Array(randomBytes(32));
3235
const txId = await createAccount(
@@ -35,8 +38,7 @@ const trees = [
3538
[randomSeed],
3639
LightSystemProgram.programId,
3740
undefined,
38-
undefined,
39-
new PublicKey(pseudoRandomTree)
41+
treeInfo
4042
);
4143
console.log(
4244
`Compressed Account Creation Success. Transaction Signature:`,

src/internal/create-account-with-lamports-pulse.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
LightSystemProgram,
77
pickRandomTreeAndQueue,
88
Rpc,
9+
selectStateTreeInfo,
910
} from "@lightprotocol/stateless.js";
1011
import { PAYER_KEYPAIR, RPC_ENDPOINT } from "../constants";
1112
import { randomBytes } from "crypto";
@@ -16,16 +17,16 @@ const connection: Rpc = createRpc(RPC_ENDPOINT);
1617
(async () => {
1718
try {
1819
while (true) {
19-
const activeStateTrees = await connection.getCachedActiveStateTreeInfo();
20+
const stateTreeInfos = await connection.getStateTreeInfos();
21+
const treeInfo = selectStateTreeInfo(stateTreeInfos);
2022

21-
const { tree, queue } = pickRandomTreeAndQueue(activeStateTrees);
22-
console.log("Picked output state tree:", tree.toBase58());
23+
console.log("Picked output state tree:", treeInfo.tree.toBase58());
2324
const compressedTxId = await compress(
2425
connection,
2526
fromKeypair,
2627
bn(10),
2728
fromKeypair.publicKey,
28-
tree
29+
treeInfo
2930
);
3031
console.log("Compressed TxId", compressedTxId);
3132
// Creat account with random address
@@ -36,8 +37,7 @@ const connection: Rpc = createRpc(RPC_ENDPOINT);
3637
10,
3738
LightSystemProgram.programId,
3839
undefined,
39-
undefined,
40-
tree
40+
treeInfo
4141
);
4242
console.log(
4343
`Compressed Account Creation Success. Transaction Signature:`,

src/internal/extend-lut.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
buildAndSignTx,
44
createRpc,
55
dedupeSigner,
6-
getLightStateTreeInfo,
6+
getAllStateTreeInfos,
77
sendAndConfirmTx,
88
} from "@lightprotocol/stateless.js";
99
import {
@@ -16,7 +16,7 @@ import { AddressLookupTableProgram, Keypair, PublicKey } from "@solana/web3.js";
1616

1717
const payer = PAYER_KEYPAIR;
1818
const authority = LUT_DEVNET_AUTHORITY_KEYPAIR;
19-
const connection: Rpc = createRpc(RPC_ENDPOINT, RPC_ENDPOINT, RPC_ENDPOINT);
19+
const connection: Rpc = createRpc(RPC_ENDPOINT);
2020

2121
(async () => {
2222
// const address = new PublicKey("9NYFyEqPkyXUhkerbGHXUXkvb4qpzeEdHuGpgbgpH1NJ");
@@ -36,10 +36,14 @@ const connection: Rpc = createRpc(RPC_ENDPOINT, RPC_ENDPOINT, RPC_ENDPOINT);
3636
"5dhaJLBjnVBQFErr8oiCJmcVsx3Zj6xDekGB2zULPsnP"
3737
);
3838

39-
const info = await getLightStateTreeInfo({
39+
const info = await getAllStateTreeInfos({
4040
connection,
41-
stateTreeLookupTableAddress: stateTreeLookupTableDevnet,
42-
nullifyTableAddress: nullifiedStateTreeLookupTableDevnet,
41+
stateTreeLUTPairs: [
42+
{
43+
stateTreeLookupTable: stateTreeLookupTableDevnet,
44+
nullifyLookupTable: nullifiedStateTreeLookupTableDevnet,
45+
},
46+
],
4347
});
4448

4549
await extend(

src/internal/extend-state-lut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { PAYER_KEYPAIR, RPC_ENDPOINT, AUTHORITY_KEYPAIR } from "../constants";
88
import { PublicKey } from "@solana/web3.js";
99

1010
const payer = PAYER_KEYPAIR;
11-
const connection: Rpc = createRpc(RPC_ENDPOINT, RPC_ENDPOINT, RPC_ENDPOINT);
11+
const connection: Rpc = createRpc(RPC_ENDPOINT);
1212

1313
const stateTreeAddresses = [
1414
"smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",

src/internal/transfer-pulse.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,33 @@ import {
44
createRpc,
55
pickRandomTreeAndQueue,
66
Rpc,
7+
selectStateTreeInfo,
78
sleep,
89
transfer,
910
} from "@lightprotocol/stateless.js";
1011
import { PAYER_KEYPAIR, RPC_ENDPOINT } from "../constants";
1112
import { PublicKey } from "@solana/web3.js";
13+
import {
14+
getTokenPoolInfos,
15+
selectTokenPoolInfo,
16+
} from "@lightprotocol/compressed-token";
1217

1318
const fromKeypair = PAYER_KEYPAIR;
1419
const connection: Rpc = createRpc(RPC_ENDPOINT, RPC_ENDPOINT);
1520

1621
const batchSize = 10;
1722
(async () => {
1823
try {
19-
const activeStateTrees = await connection.getCachedActiveStateTreeInfo();
20-
21-
const { tree, queue } = pickRandomTreeAndQueue(activeStateTrees);
22-
console.log("Picked output state tree:", tree.toBase58());
24+
const stateTreeInfos = await connection.getStateTreeInfos();
25+
const treeInfo = selectStateTreeInfo(stateTreeInfos);
26+
console.log("Picked output state tree:", treeInfo.tree.toBase58());
2327

2428
const compressedTxId = await compress(
2529
connection,
2630
fromKeypair,
2731
bn(1e5),
2832
fromKeypair.publicKey,
29-
tree
33+
treeInfo
3034
);
3135
while (true) {
3236
console.log("Compressed TxId", compressedTxId);
@@ -41,7 +45,7 @@ const batchSize = 10;
4145
1,
4246
fromKeypair,
4347
fromKeypair.publicKey,
44-
tree,
48+
treeInfo,
4549
{
4650
skipPreflight: false,
4751
}

src/scripts/airdrop/airdrop.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import {
33
calculateComputeUnitPrice,
44
createRpc,
55
Rpc,
6+
selectStateTreeInfo,
67
} from "@lightprotocol/stateless.js";
7-
import { createMint } from "@lightprotocol/compressed-token";
8+
import { createMint, getTokenPoolInfos } from "@lightprotocol/compressed-token";
89
import { getOrCreateAssociatedTokenAccount, mintTo } from "@solana/spl-token";
910
import { createAirdropInstructions } from "./create-instructions";
1011
import { BatchResultType, signAndSendAirdropBatches } from "./sign-and-send";
@@ -75,15 +76,16 @@ const recipients = [
7576
);
7677
console.log(`mint-to success! txId: ${mintToTxId}`);
7778

78-
const activeStateTrees = await connection.getCachedActiveStateTreeInfo();
79-
79+
const stateTreeInfos = await connection.getStateTreeInfos();
80+
const tokenPoolInfos = await getTokenPoolInfos(connection, mint);
8081
const instructionBatches = await createAirdropInstructions({
8182
amount: 1e6,
8283
recipients,
8384
payer: PAYER.publicKey,
8485
sourceTokenAccount: ata.address,
8586
mint,
86-
stateTrees: activeStateTrees,
87+
stateTreeInfos,
88+
tokenPoolInfos,
8789
computeUnitPrice: calculateComputeUnitPrice(10_000, 500_000),
8890
});
8991

src/scripts/airdrop/create-instructions.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import { CompressedTokenProgram } from "@lightprotocol/compressed-token";
1+
import {
2+
CompressedTokenProgram,
3+
selectTokenPoolInfo,
4+
TokenPoolInfo,
5+
} from "@lightprotocol/compressed-token";
26
import {
37
bn,
48
ActiveTreeBundle,
59
pickRandomTreeAndQueue,
10+
selectStateTreeInfo,
11+
StateTreeInfo,
612
} from "@lightprotocol/stateless.js";
713
import {
814
ComputeBudgetProgram,
@@ -16,7 +22,8 @@ interface CreateAirdropInstructionsParams {
1622
payer: PublicKey;
1723
sourceTokenAccount: PublicKey;
1824
mint: PublicKey;
19-
stateTrees: ActiveTreeBundle[];
25+
stateTreeInfos: StateTreeInfo[];
26+
tokenPoolInfos: TokenPoolInfo[];
2027
maxRecipientsPerInstruction?: number;
2128
maxInstructionsPerTransaction?: number;
2229
computeUnitLimit?: number;
@@ -31,7 +38,8 @@ export async function createAirdropInstructions({
3138
payer,
3239
sourceTokenAccount,
3340
mint,
34-
stateTrees,
41+
stateTreeInfos,
42+
tokenPoolInfos,
3543
maxRecipientsPerInstruction = 5,
3644
maxInstructionsPerTransaction = 3,
3745
computeUnitLimit = 500_000,
@@ -59,7 +67,8 @@ export async function createAirdropInstructions({
5967
);
6068
}
6169

62-
const { tree } = pickRandomTreeAndQueue(stateTrees);
70+
const treeInfo = selectStateTreeInfo(stateTreeInfos);
71+
const tokenPoolInfo = selectTokenPoolInfo(tokenPoolInfos);
6372

6473
for (let j = 0; j < maxInstructionsPerTransaction; j++) {
6574
const startIdx = i + j * maxRecipientsPerInstruction;
@@ -77,7 +86,8 @@ export async function createAirdropInstructions({
7786
toAddress: recipientBatch,
7887
amount: recipientBatch.map(() => amountBn),
7988
mint,
80-
outputStateTree: tree,
89+
outputStateTreeInfo: treeInfo,
90+
tokenPoolInfo,
8191
});
8292

8393
instructions.push(compressIx);

src/scripts/batch-compress.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as web3 from "@solana/web3.js";
22
import { RPC_ENDPOINT, PAYER_KEYPAIR, MINT_ADDRESS } from "../constants";
3-
import { CompressedTokenProgram } from "@lightprotocol/compressed-token";
3+
import {
4+
CompressedTokenProgram,
5+
getTokenPoolInfos,
6+
selectTokenPoolInfo,
7+
} from "@lightprotocol/compressed-token";
48

59
import {
610
bn,
@@ -9,6 +13,7 @@ import {
913
dedupeSigner,
1014
pickRandomTreeAndQueue,
1115
Rpc,
16+
selectStateTreeInfo,
1217
sendAndConfirmTx,
1318
} from "@lightprotocol/stateless.js";
1419
import * as splToken from "@solana/spl-token";
@@ -19,10 +24,13 @@ import * as splToken from "@solana/spl-token";
1924
const mintAddress = MINT_ADDRESS;
2025
const payer = PAYER_KEYPAIR;
2126

22-
const activeStateTrees = await connection.getCachedActiveStateTreeInfo();
27+
const activeStateTrees = await connection.getStateTreeInfos();
28+
const treeInfo = selectStateTreeInfo(activeStateTrees);
29+
console.log("Picked output state tree:", treeInfo.tree.toBase58());
2330

24-
const { tree } = pickRandomTreeAndQueue(activeStateTrees);
25-
console.log("Picked output state tree:", tree.toBase58());
31+
const tokenPoolInfo = selectTokenPoolInfo(
32+
await getTokenPoolInfos(connection, mintAddress)
33+
);
2634

2735
// Get the source token account for the mint address
2836
const sourceTokenAccount = await splToken.getOrCreateAssociatedTokenAccount(
@@ -78,7 +86,8 @@ import * as splToken from "@solana/spl-token";
7886
toAddress: recipientBatch,
7987
amount: recipientBatch.map(() => amount),
8088
mint: mintAddress,
81-
outputStateTree: tree,
89+
outputStateTreeInfo: treeInfo,
90+
tokenPoolInfo,
8291
});
8392
instructions.push(compressIx);
8493
i += maxRecipientsPerInstruction;

0 commit comments

Comments
 (0)