Skip to content

Commit 7623fdf

Browse files
chore: bump SDK + idempotent example (#20)
* wip * synced * bump * add idempotent example
1 parent 67b3aad commit 7623fdf

18 files changed

Lines changed: 260 additions & 208 deletions

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"airdrop": "ts-node src/scripts/airdrop/airdrop.ts",
2222
"transfer": "ts-node src/scripts/transfer.ts",
2323
"compress": "ts-node src/scripts/compress.ts",
24+
2425
"test": "npm run lamports && npm run token && npm run connection && npm run batch-compress && npm run mint-spl && npm run mint-spl-22 && npm run mint-spl-22-manual"
2526
},
2627
"repository": {
@@ -35,8 +36,8 @@
3536
},
3637
"homepage": "https://github.com/Lightprotocol/example-nodejs-client#readme",
3738
"dependencies": {
38-
"@lightprotocol/compressed-token": "0.20.9",
39-
"@lightprotocol/stateless.js": "0.20.9",
39+
"@lightprotocol/compressed-token": "0.22.0",
40+
"@lightprotocol/stateless.js": "0.22.0",
4041
"@solana/spl-token": "0.3.9",
4142
"@solana/spl-token-metadata": "^0.1.6",
4243
"@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",

0 commit comments

Comments
 (0)