Skip to content

Commit a829ffc

Browse files
author
tilo-14
committed
fix: update to @lightprotocol/stateless.js 0.22.0
- Replace deprecated defaultTestStateTreeAccounts() with selectStateTreeInfo() - Use createRpc() without args for localnet (correct endpoint defaults) - Update outputStateTree to outputStateTreeInfo in compress scripts - Fix RPC endpoint configuration across all scripts >
1 parent 3a8401d commit a829ffc

11 files changed

Lines changed: 162 additions & 93 deletions

package-lock.json

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

src/scripts/batch-compress.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as web3 from "@solana/web3.js";
2-
import { RPC_ENDPOINT, PAYER_KEYPAIR, MINT_ADDRESS } from "../constants";
2+
import { PAYER_KEYPAIR, MINT_ADDRESS } from "../constants";
33
import {
44
CompressedTokenProgram,
55
getTokenPoolInfos,
@@ -20,7 +20,8 @@ import * as splToken from "@solana/spl-token";
2020

2121
(async () => {
2222
try {
23-
const connection: Rpc = createRpc(RPC_ENDPOINT, RPC_ENDPOINT);
23+
/// Localnet, expects `light test-validator` to be running:
24+
const connection: Rpc = createRpc();
2425
const mintAddress = MINT_ADDRESS;
2526
const payer = PAYER_KEYPAIR;
2627

src/scripts/compress-idempotent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import bs58 from "bs58";
2121
import { createIdempotentAirdropInstruction } from "./idempotent";
2222
dotenv.config();
2323

24-
const RPC_ENDPOINT = process.env.RPC_ENDPOINT;
2524
const MINT_ADDRESS = new PublicKey(process.env.MINT_ADDRESS!);
2625
const PAYER_KEYPAIR = Keypair.fromSecretKey(
2726
bs58.decode(process.env.PAYER_KEYPAIR!)
2827
);
2928

3029
(async () => {
3130
try {
32-
const connection: Rpc = createRpc(RPC_ENDPOINT);
31+
/// Localnet, expects `light test-validator` to be running:
32+
const connection: Rpc = createRpc();
3333
const mintAddress = MINT_ADDRESS;
3434
const payer = PAYER_KEYPAIR;
3535

src/scripts/compress.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import dotenv from "dotenv";
2020
import bs58 from "bs58";
2121
dotenv.config();
2222

23-
const RPC_ENDPOINT = process.env.RPC_ENDPOINT;
2423
const MINT_ADDRESS = new PublicKey(process.env.MINT_ADDRESS!);
2524
const PAYER_KEYPAIR = Keypair.fromSecretKey(
2625
bs58.decode(process.env.PAYER_KEYPAIR!)
2726
);
2827

2928
(async () => {
3029
try {
31-
const connection: Rpc = createRpc(RPC_ENDPOINT);
30+
/// Localnet, expects `light test-validator` to be running:
31+
const connection: Rpc = createRpc();
3232
const mintAddress = MINT_ADDRESS;
3333
const payer = PAYER_KEYPAIR;
3434

src/scripts/connection.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Rpc } from "@lightprotocol/stateless.js";
2-
import { RPC_ENDPOINT, PAYER_KEYPAIR } from "../constants";
1+
import { Rpc, createRpc } from "@lightprotocol/stateless.js";
2+
import { PAYER_KEYPAIR } from "../constants";
33

4-
const stateless = require("@lightprotocol/stateless.js");
5-
6-
const connection: Rpc = stateless.createRpc(RPC_ENDPOINT, RPC_ENDPOINT);
4+
/// Localnet, expects `light test-validator` to be running:
5+
const connection: Rpc = createRpc();
76

87
(async () => {
98
const slot = await connection.getSlot();

src/scripts/lamports.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { confirmTx } from "@lightprotocol/stateless.js";
1+
import { confirmTx, selectStateTreeInfo } from "@lightprotocol/stateless.js";
22
import dotenv from "dotenv";
33

44
dotenv.config();
@@ -8,7 +8,6 @@ const {
88
LightSystemProgram,
99
buildAndSignTx,
1010
createRpc,
11-
defaultTestStateTreeAccounts,
1211
sendAndConfirmTx,
1312
} = require("@lightprotocol/stateless.js");
1413

@@ -29,12 +28,16 @@ const connection = createRpc();
2928
/// Fetch latest blockhash
3029
const { blockhash } = await connection.getLatestBlockhash();
3130

31+
/// Get state tree info
32+
const stateTreeInfos = await connection.getStateTreeInfos();
33+
const treeInfo = selectStateTreeInfo(stateTreeInfos);
34+
3235
/// Compress lamports to self
3336
const ix = await LightSystemProgram.compress({
3437
payer: fromKeypair.publicKey,
3538
toAddress: fromKeypair.publicKey,
3639
lamports: 1_000_000_000,
37-
outputStateTree: defaultTestStateTreeAccounts().merkleTree,
40+
outputStateTreeInfo: treeInfo,
3841
});
3942

4043
/// Create a VersionedTransaction and sign it

src/scripts/mint-spl-22-manual.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
LENGTH_SIZE,
2424
TYPE_SIZE,
2525
} from "@solana/spl-token";
26-
import { PAYER_KEYPAIR, RPC_ENDPOINT } from "../constants";
26+
import { PAYER_KEYPAIR } from "../constants";
2727
import {
2828
Keypair,
2929
SystemProgram,
@@ -37,7 +37,8 @@ import {
3737
} from "@solana/spl-token-metadata";
3838

3939
const payer = PAYER_KEYPAIR;
40-
const connection: Rpc = createRpc(RPC_ENDPOINT, RPC_ENDPOINT);
40+
/// Localnet, expects `light test-validator` to be running:
41+
const connection: Rpc = createRpc();
4142

4243
(async () => {
4344
const activeStateTrees = await connection.getStateTreeInfos();

0 commit comments

Comments
 (0)