Skip to content

Commit 0bc8e3e

Browse files
chore: backport breaking api changes to v1 js SDKs (#1661)
* stateless.js add treeinfos * wip * add getTokenPoolInfos * wip * wip * wip - storageoptions * wip * wip * wip * wip - known bug in rpc-interop.test.ts if using random trees * debugged test-rpc in ctoken * all ctoken tests working * rm logs * clean * ctxs to infos, removed redundant getMintProgramId calls * rm deadcode, storageoptions * fix cli getMindProgramId use * fix tokenpool * fix test stateless.js add treeinfos wip add getTokenPoolInfos wip wip wip - storageoptions wip wip wip wip - known bug in rpc-interop.test.ts if using random trees debugged test-rpc in ctoken all ctoken tests working rm logs clean ctxs to infos, removed redundant getMintProgramId calls rm deadcode, storageoptions fix cli getMindProgramId use fix tokenpool fix test update CHANGELOG.md files update changelog update CHANGELOG.md export get-token-pool-infos.ts wip clean wip refactor merklecontext refactor StateTreeInfo wip wip debug test-rpc getCompressedTokenAccountsByOwner fix unit test wip wip wip debug .readUIntLE wip wip wip fix buffer conversion at test-rpc decode wip tests working compressedProof -> validityProof update changelog wip refactor: do not allow output trees for decompress, transfer fmt wip rename getCachedStateTreeInfos upd changelog use with getCachedStateTreeInfos getStateTreeInfos wip wip delegate test wip added transfer-delegated.test.ts added transfer-delegated test cases. all green add tests for decompress-delegated fix rm logs from program update changelog update err msg fix state-tree-luts wip getActiveStateTreeInfos -> getAllStateTreeInfos wip fix sigs for nullifyStateTree wip wip cleanup add getCachedActiveStateTreeInfos mock revert to compressedProof add tokenpools tests update comment update CHANGELOG.md update changelog 0.21.0 update changelog fix fix event parsing post rebase stateless js refactor dedupe types link to computebudgetprogram wip fix DX for instructions: add docstrings to call signatures wip dont break mergeTokenAccounts wip wip add v2 trees to test-rpc v1 mergeable test-rpc tests working rpc-interop tests working with v2 all stateless.js tests working with v2 compressed-token tests working
1 parent 5b2ba40 commit 0bc8e3e

File tree

105 files changed

+7897
-3225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+7897
-3225
lines changed

Cargo.lock

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

cli/src/commands/compress-spl/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CompressSplCommand extends Command {
5252
const toPublicKey = new PublicKey(to);
5353
const mintPublicKey = new PublicKey(mint);
5454
const payer = defaultSolanaWalletKeypair();
55-
const tokenProgramId = await CompressedTokenProgram.get_mint_program_id(
55+
const tokenProgramId = await CompressedTokenProgram.getMintProgramId(
5656
mintPublicKey,
5757
rpc(),
5858
);
@@ -75,7 +75,7 @@ class CompressSplCommand extends Command {
7575
toPublicKey,
7676
undefined,
7777
undefined,
78-
tokenProgramId,
78+
undefined,
7979
);
8080

8181
loader.stop(false);

cli/src/commands/decompress-spl/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class DecompressSplCommand extends Command {
5252
const toPublicKey = new PublicKey(to);
5353
const mintPublicKey = new PublicKey(mint);
5454
const payer = defaultSolanaWalletKeypair();
55-
const tokenProgramId = await CompressedTokenProgram.get_mint_program_id(
55+
const tokenProgramId = await CompressedTokenProgram.getMintProgramId(
5656
mintPublicKey,
5757
rpc(),
5858
);
@@ -75,9 +75,6 @@ class DecompressSplCommand extends Command {
7575
amount,
7676
payer,
7777
recipientAta.address,
78-
undefined,
79-
undefined,
80-
tokenProgramId,
8178
);
8279

8380
loader.stop(false);

cli/src/commands/init/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
kebabCase,
3030
snakeCase,
3131
} from "case-anything";
32-
import { execSync } from "child_process";
32+
3333
export default class InitCommand extends Command {
3434
static description = "Initialize a compressed account project.";
3535

examples/browser/nextjs/src/app/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import {
2424
bn,
2525
buildTx,
2626
confirmTx,
27-
defaultTestStateTreeAccounts,
2827
selectMinCompressedSolAccountsForTransfer,
2928
createRpc,
29+
selectStateTreeInfo,
3030
} from '@lightprotocol/stateless.js';
3131

3232
// Default styles that can be overridden by your app
@@ -36,7 +36,10 @@ const SendButton: FC = () => {
3636
const { publicKey, sendTransaction } = useWallet();
3737

3838
const onClick = useCallback(async () => {
39-
const connection = await createRpc();
39+
const connection = createRpc();
40+
const stateTreeInfo = selectStateTreeInfo(
41+
await connection.getStateTreeInfos(),
42+
);
4043

4144
if (!publicKey) throw new WalletNotConnectedError();
4245

@@ -51,7 +54,7 @@ const SendButton: FC = () => {
5154
payer: publicKey,
5255
toAddress: publicKey,
5356
lamports: 1e8,
54-
outputStateTree: defaultTestStateTreeAccounts().merkleTree,
57+
outputStateTreeInfo: stateTreeInfo,
5558
});
5659
const compressInstructions = [
5760
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }),
@@ -109,7 +112,6 @@ const SendButton: FC = () => {
109112
toAddress: recipient,
110113
lamports: 1e7,
111114
inputCompressedAccounts: selectedAccounts,
112-
outputStateTrees: [defaultTestStateTreeAccounts().merkleTree],
113115
recentValidityProof: compressedProof,
114116
recentInputStateRootIndices: rootIndices,
115117
});

js/compressed-token/CHANGELOG.md

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,97 @@
1+
## [0.22.0]
2+
3+
- `CreateMint` action now allows passing a non-payer mint and freeze authority.
4+
- More efficient computebudgets for actions.
5+
- Better DX: Parameter lookup in call signatures of CompressedTokenProgram instructions
6+
- QoL: improved typedocs.
7+
8+
## [0.21.0]
9+
10+
#### Breaking Changes
11+
12+
This release has several breaking changes which improve protocol
13+
scalability. Please reach out to the [team](https://t.me/swen_light) if you need help migrating.
14+
15+
### Migration guide: Compress
16+
17+
**Old Code** (remove this)
18+
19+
```typescript
20+
const activeStateTrees = await connection.getCachedActiveStateTreeInfo();
21+
const { tree } = pickRandomTreeAndQueue(activeStateTrees);
22+
// ...
23+
```
24+
25+
**New Code**
26+
27+
```typescript
28+
// ...
29+
const treeInfos = await rpc.getStateTreeInfos();
30+
const treeInfo = selectStateTreeInfo(treeInfos);
31+
32+
const infos = await getTokenPoolInfos(rpc, mint);
33+
const info = selectTokenPoolInfo(infos);
34+
35+
const compressIx = await CompressedTokenProgram.compress({
36+
// ...
37+
outputStateTreeInfo,
38+
tokenPoolInfo,
39+
});
40+
```
41+
42+
### Migration guide: Decompress
43+
44+
```typescript
45+
// ...
46+
// new code:
47+
const infos = await getTokenPoolInfos(rpc, mint);
48+
const selectedInfos = selectTokenPoolInfosForDecompression(
49+
tokenPoolInfos,
50+
amount,
51+
);
52+
53+
const ix = await CompressedTokenProgram.decompress({
54+
// ...
55+
tokenPoolInfos: selectedTokenPoolInfos,
56+
});
57+
```
58+
59+
### Overview
60+
61+
- new type: TokenPoolInfo
62+
- Instruction Changes:
63+
64+
- `compress`, `mintTo`, `approveAndMintTo`, `compressSplTokenAccount` now require valid TokenPoolInfo
65+
- `decompress` now requires an array of one or more TokenPoolInfos.
66+
- `decompress`, `transfer` now do not allow state tree overrides.
67+
68+
- Action Changes:
69+
70+
- Removed optional tokenProgramId: PublicKey
71+
- removed optional merkleTree: PublicKey
72+
- removed optional outputStateTree: PublicKey
73+
- added optional stateTreeInfo: StateTreeInfo
74+
- added optional tokenPoolInfo: TokenPoolInfo
75+
76+
- new instructions:
77+
- `approve`, `revoke`: delegated transfer support.
78+
- `addTokenPools`: you can now register additional token pool pdas. Use
79+
this if you need very high concurrency.
80+
81+
### Why the Changes are helpful
82+
83+
`getStateTreeInfos()` retrieves relevant info about all active state trees.
84+
85+
When building a transaction you can now pick a random treeInfo via `selectStateTreeInfo(infos)`.
86+
87+
This lets you and other apps execute more transactions within Solana's write lock
88+
limits.
89+
90+
The same applies to `getTokenPoolInfos`. When you compress or decompress SPL
91+
tokens, a tokenpool gets write-locked. If you need additional per-block write
92+
lock capacity, you can register and sample additional (up to 4) tokenpool
93+
accounts.
94+
195
## [0.20.5-0.20.9] - 2025-02-24
296

397
### Changed
@@ -17,7 +111,7 @@
17111
### Added
18112

19113
- `selectSmartCompressedTokenAccountsForTransfer` and
20-
`selectSmartCompressedTokenAccountsForTransferorPartial`
114+
`selectSmartCompressedTokenAccountsForTransferOrPartial`
21115

22116
### Changed
23117

js/compressed-token/package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lightprotocol/compressed-token",
3-
"version": "0.20.9",
3+
"version": "0.21.0",
44
"description": "JS client to interact with the compressed-token program",
55
"sideEffects": false,
66
"main": "dist/cjs/node/index.cjs",
@@ -83,19 +83,23 @@
8383
"test-all:verbose": "vitest run --reporter=verbose",
8484
"test-validator": "./../../cli/test_bin/run test-validator --prover-run-mode rpc",
8585
"test:e2e:create-mint": "pnpm test-validator && NODE_OPTIONS='--trace-deprecation' vitest run tests/e2e/create-mint.test.ts --reporter=verbose",
86-
"test:e2e:layout": "vitest run tests/e2e/layout.test.ts --reporter=verbose",
86+
"test:e2e:layout": "vitest run tests/e2e/layout.test.ts --reporter=verbose --bail=1",
8787
"test:e2e:select-accounts": "vitest run tests/e2e/select-accounts.test.ts --reporter=verbose",
8888
"test:e2e:create-token-pool": "pnpm test-validator && vitest run tests/e2e/create-token-pool.test.ts",
89-
"test:e2e:mint-to": "pnpm test-validator && vitest run tests/e2e/mint-to.test.ts --reporter=verbose",
90-
"test:e2e:approve-and-mint-to": "pnpm test-validator && vitest run tests/e2e/approve-and-mint-to.test.ts --reporter=verbose",
89+
"test:e2e:mint-to": "pnpm test-validator && vitest run tests/e2e/mint-to.test.ts --reporter=verbose --bail=1",
90+
"test:e2e:approve-and-mint-to": "pnpm test-validator && vitest run tests/e2e/approve-and-mint-to.test.ts --reporter=verbose --bail=1",
9191
"test:e2e:merge-token-accounts": "pnpm test-validator && vitest run tests/e2e/merge-token-accounts.test.ts --reporter=verbose",
92-
"test:e2e:transfer": "pnpm test-validator && vitest run tests/e2e/transfer.test.ts --reporter=verbose",
92+
"test:e2e:transfer": "pnpm test-validator && vitest run tests/e2e/transfer.test.ts --reporter=verbose --bail=1",
93+
"test:e2e:delegate": "pnpm test-validator && vitest run tests/e2e/delegate.test.ts --reporter=verbose --bail=1",
94+
"test:e2e:transfer-delegated": "pnpm test-validator && vitest run tests/e2e/transfer-delegated.test.ts --reporter=verbose --bail=1",
9395
"test:e2e:compress": "pnpm test-validator && vitest run tests/e2e/compress.test.ts --reporter=verbose",
9496
"test:e2e:compress-spl-token-account": "pnpm test-validator && vitest run tests/e2e/compress-spl-token-account.test.ts --reporter=verbose",
9597
"test:e2e:decompress": "pnpm test-validator && vitest run tests/e2e/decompress.test.ts --reporter=verbose",
98+
"test:e2e:decompress-delegated": "pnpm test-validator && vitest run tests/e2e/decompress-delegated.test.ts --reporter=verbose",
9699
"test:e2e:rpc-token-interop": "pnpm test-validator && vitest run tests/e2e/rpc-token-interop.test.ts --reporter=verbose",
97100
"test:e2e:rpc-multi-trees": "pnpm test-validator && vitest run tests/e2e/rpc-multi-trees.test.ts --reporter=verbose",
98-
"test:e2e:all": "pnpm test-validator && vitest run tests/e2e/create-mint.test.ts && vitest run tests/e2e/mint-to.test.ts && vitest run tests/e2e/transfer.test.ts && vitest run tests/e2e/compress.test.ts && vitest run tests/e2e/compress-spl-token-account.test.ts && vitest run tests/e2e/decompress.test.ts && vitest run tests/e2e/create-token-pool.test.ts && vitest run tests/e2e/approve-and-mint-to.test.ts && vitest run tests/e2e/rpc-token-interop.test.ts && vitest run tests/e2e/rpc-multi-trees.test.ts && vitest run tests/e2e/layout.test.ts && vitest run tests/e2e/select-accounts.test.ts",
101+
"test:e2e:multi-pool": "pnpm test-validator && vitest run tests/e2e/multi-pool.test.ts --reporter=verbose",
102+
"test:e2e:all": "pnpm test-validator && vitest run tests/e2e/create-mint.test.ts && vitest run tests/e2e/mint-to.test.ts && vitest run tests/e2e/transfer.test.ts && vitest run tests/e2e/delegate.test.ts && vitest run tests/e2e/transfer-delegated.test.ts && vitest run tests/e2e/multi-pool.test.ts && vitest run tests/e2e/decompress-delegated.test.ts && pnpm test-validator &&vitest run tests/e2e/compress.test.ts && vitest run tests/e2e/compress-spl-token-account.test.ts && vitest run tests/e2e/decompress.test.ts && vitest run tests/e2e/create-token-pool.test.ts && vitest run tests/e2e/approve-and-mint-to.test.ts && vitest run tests/e2e/rpc-token-interop.test.ts && vitest run tests/e2e/rpc-multi-trees.test.ts && vitest run tests/e2e/layout.test.ts && vitest run tests/e2e/select-accounts.test.ts",
99103
"pull-idl": "../../scripts/push-compressed-token-idl.sh",
100104
"build": "rimraf dist && pnpm build:bundle",
101105
"build:bundle": "rollup -c",

js/compressed-token/rollup.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ const rolls = (fmt, env) => ({
4747
env === 'browser' ? nodePolyfills() : undefined,
4848
terser({
4949
compress: {
50-
drop_console: true,
50+
drop_console: false,
5151
drop_debugger: true,
5252
passes: 3,
53-
pure_funcs: ['console.log', 'console.error', 'console.warn'],
5453
booleans_as_integers: true,
5554
keep_fargs: false,
5655
keep_fnames: false,

js/compressed-token/src/actions/approve-and-mint-to.ts

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,53 @@ import {
1111
buildAndSignTx,
1212
Rpc,
1313
dedupeSigner,
14-
pickRandomTreeAndQueue,
14+
StateTreeInfo,
15+
selectStateTreeInfo,
16+
toArray,
1517
} from '@lightprotocol/stateless.js';
1618
import { CompressedTokenProgram } from '../program';
1719
import { getOrCreateAssociatedTokenAccount } from '@solana/spl-token';
1820

21+
import {
22+
getTokenPoolInfos,
23+
selectTokenPoolInfo,
24+
TokenPoolInfo,
25+
} from '../utils/get-token-pool-infos';
26+
1927
/**
2028
* Mint compressed tokens to a solana address from an external mint authority
2129
*
22-
* @param rpc Rpc to use
23-
* @param payer Payer of the transaction fees
24-
* @param mint Mint for the account
25-
* @param destination Address of the account to mint to
26-
* @param authority Minting authority
27-
* @param amount Amount to mint
28-
* @param merkleTree State tree account that the compressed tokens should be
29-
* part of. Defaults to random public state tree account.
30-
* @param confirmOptions Options for confirming the transaction
30+
* @param rpc Rpc to use
31+
* @param payer Fee payer
32+
* @param mint SPL Mint address
33+
* @param toPubkey Address of the account to mint to
34+
* @param authority Minting authority
35+
* @param amount Amount to mint
36+
* @param outputStateTreeInfo Optional: State tree account that the compressed
37+
* tokens should be inserted into. Defaults to a
38+
* shared state tree account.
39+
* @param tokenPoolInfo Optional: Token pool info.
40+
* @param confirmOptions Options for confirming the transaction
3141
*
3242
* @return Signature of the confirmed transaction
3343
*/
3444
export async function approveAndMintTo(
3545
rpc: Rpc,
3646
payer: Signer,
3747
mint: PublicKey,
38-
destination: PublicKey,
48+
toPubkey: PublicKey,
3949
authority: Signer,
4050
amount: number | BN,
41-
merkleTree?: PublicKey,
51+
outputStateTreeInfo?: StateTreeInfo,
52+
tokenPoolInfo?: TokenPoolInfo,
4253
confirmOptions?: ConfirmOptions,
43-
tokenProgramId?: PublicKey,
4454
): Promise<TransactionSignature> {
45-
tokenProgramId = tokenProgramId
46-
? tokenProgramId
47-
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
55+
outputStateTreeInfo =
56+
outputStateTreeInfo ??
57+
selectStateTreeInfo(await rpc.getStateTreeInfos());
58+
tokenPoolInfo =
59+
tokenPoolInfo ??
60+
selectTokenPoolInfo(await getTokenPoolInfos(rpc, mint));
4861

4962
const authorityTokenAccount = await getOrCreateAssociatedTokenAccount(
5063
rpc,
@@ -54,40 +67,34 @@ export async function approveAndMintTo(
5467
undefined,
5568
undefined,
5669
confirmOptions,
57-
tokenProgramId,
70+
tokenPoolInfo.tokenProgram,
5871
);
5972

60-
if (!merkleTree) {
61-
const stateTreeInfo = await rpc.getCachedActiveStateTreeInfo();
62-
const { tree } = pickRandomTreeAndQueue(stateTreeInfo);
63-
merkleTree = tree;
64-
}
65-
6673
const ixs = await CompressedTokenProgram.approveAndMintTo({
6774
feePayer: payer.publicKey,
6875
mint,
6976
authority: authority.publicKey,
7077
authorityTokenAccount: authorityTokenAccount.address,
7178
amount,
72-
toPubkey: destination,
73-
merkleTree,
74-
tokenProgramId,
79+
toPubkey,
80+
outputStateTreeInfo,
81+
tokenPoolInfo,
7582
});
7683

7784
const { blockhash } = await rpc.getLatestBlockhash();
7885
const additionalSigners = dedupeSigner(payer, [authority]);
7986

8087
const tx = buildAndSignTx(
8188
[
82-
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }),
89+
ComputeBudgetProgram.setComputeUnitLimit({
90+
units: 150_000 + toArray(amount).length * 20_000,
91+
}),
8392
...ixs,
8493
],
8594
payer,
8695
blockhash,
8796
additionalSigners,
8897
);
8998

90-
const txId = await sendAndConfirmTx(rpc, tx, confirmOptions);
91-
92-
return txId;
99+
return await sendAndConfirmTx(rpc, tx, confirmOptions);
93100
}

0 commit comments

Comments
 (0)