@lightprotocol/stateless.js 0.14.4 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
  <img src="https://github.com/ldiego08/light-protocol/raw/main/assets/logo.svg" width="90" />
3
3
  </p>
4
4
 
5
- <h1 align="center">Stateless.js</h1>
5
+ <h1 align="center">@lightprotocol/stateless.js</h1>
6
6
 
7
7
  <p align="center">
8
- <b>Integrate server and web applications with ZK Compression on Solana.</b>
8
+ <b>This is the JavaScript SDK for building Solana applications with ZK Compression for Node and web.</b>
9
9
  </p>
10
10
 
11
11
  <p align="center">
@@ -16,14 +16,6 @@
16
16
  <img src="https://img.shields.io/npm/dw/%40lightprotocol%2Fstateless.js" alt="package weekly downloads" height="18" />
17
17
  </p>
18
18
 
19
- ## Overview
20
-
21
- This package provides server and web applications with clients, utilities, and types to leverage the power of [ZK Compression](https://www.zkcompression.com/) on Solana via the Compression RPC API.
22
-
23
- > The core ZK Compression Solana programs and clients are maintained by
24
- > [Light](https://github.com/lightprotocol) as a part of the Light Protocol. The RPC API and indexer are maintained by
25
- > [Helius Labs](https://github.com/helius-labs).
26
-
27
19
  ## Usage
28
20
 
29
21
  ### Installation
@@ -31,22 +23,14 @@ This package provides server and web applications with clients, utilities, and t
31
23
  Install this package in your project by running the following terminal command:
32
24
 
33
25
  ```bin
34
- npm install --save \
35
- @lightprotocol/stateless.js \
36
- @solana/web3.js \
37
- @coral-xyz/anchor@0.29
26
+ npm install --save @lightprotocol/stateless.js
38
27
  ```
39
28
 
40
- ### Dependencies
41
-
42
- - [`@solana/web3.js`](https://www.npmjs.com/package/@solana/web3.js) — provides access to the Solana network via RPC.
43
- - [`@coral-xyz/anchor`](https://www.npmjs.com/package/@coral-xyz/anchor) — a client for [Anchor](https://www.anchor-lang.com/) Solana programs.
44
-
45
29
  ## Documentation and Examples
46
30
 
47
31
  For a more detailed documentation on usage, please check [the respective section at the ZK Compression documentation.](https://www.zkcompression.com/developers/typescript-client)
48
32
 
49
- For example implementations, including web and server, refer to the respective repositories:
33
+ For example implementations, including web and Node, refer to the respective repositories:
50
34
 
51
35
  - [Web application example implementation](https://github.com/Lightprotocol/example-web-client)
52
36
 
@@ -55,7 +39,7 @@ For example implementations, including web and server, refer to the respective r
55
39
  ## Troubleshooting
56
40
 
57
41
  Have a question or a problem?
58
- Feel free to ask in the [Light](https://discord.gg/CYvjBgzRFP) and [Helius](https://discord.gg/Uzzf6a7zKr) developer Discord servers. Please, include the following information to better be able to respond:
42
+ Feel free to ask in the [Light](https://discord.gg/CYvjBgzRFP) and [Helius](https://discord.gg/Uzzf6a7zKr) developer Discord servers. Please, include the following information:
59
43
 
60
44
  - A detailed description or context of the issue or what you are trying to achieve.
61
45
  - A code example that we can use to test and debug (if possible). Use [CodeSandbox](https://codesandbox.io/p/sandbox/vanilla-ts) or any other live environment provider.
@@ -11727,128 +11727,23 @@ const IDL = {
11727
11727
  errors: [
11728
11728
  {
11729
11729
  code: 6000,
11730
- name: 'PublicKeyAmountMissmatch',
11731
- msg: 'public keys and amounts must be of same length',
11730
+ name: 'SignerCheckFailed',
11731
+ msg: 'Signer check failed',
11732
11732
  },
11733
11733
  {
11734
11734
  code: 6001,
11735
- name: 'ComputeInputSumFailed',
11736
- msg: 'ComputeInputSumFailed',
11735
+ name: 'CreateTransferInstructionFailed',
11736
+ msg: 'Create transfer instruction failed',
11737
11737
  },
11738
11738
  {
11739
11739
  code: 6002,
11740
- name: 'ComputeOutputSumFailed',
11741
- msg: 'ComputeOutputSumFailed',
11740
+ name: 'AccountNotFound',
11741
+ msg: 'Account not found',
11742
11742
  },
11743
11743
  {
11744
11744
  code: 6003,
11745
- name: 'ComputeCompressSumFailed',
11746
- msg: 'ComputeCompressSumFailed',
11747
- },
11748
- {
11749
- code: 6004,
11750
- name: 'ComputeDecompressSumFailed',
11751
- msg: 'ComputeDecompressSumFailed',
11752
- },
11753
- {
11754
- code: 6005,
11755
- name: 'SumCheckFailed',
11756
- msg: 'SumCheckFailed',
11757
- },
11758
- {
11759
- code: 6006,
11760
- name: 'DecompressRecipientUndefinedForDecompress',
11761
- msg: 'DecompressRecipientUndefinedForDecompress',
11762
- },
11763
- {
11764
- code: 6007,
11765
- name: 'CompressedPdaUndefinedForDecompress',
11766
- msg: 'CompressedPdaUndefinedForDecompress',
11767
- },
11768
- {
11769
- code: 6008,
11770
- name: 'DeCompressAmountUndefinedForDecompress',
11771
- msg: 'DeCompressAmountUndefinedForDecompress',
11772
- },
11773
- {
11774
- code: 6009,
11775
- name: 'CompressedPdaUndefinedForCompress',
11776
- msg: 'CompressedPdaUndefinedForCompress',
11777
- },
11778
- {
11779
- code: 6010,
11780
- name: 'DeCompressAmountUndefinedForCompress',
11781
- msg: 'DeCompressAmountUndefinedForCompress',
11782
- },
11783
- {
11784
- code: 6011,
11785
- name: 'DelegateSignerCheckFailed',
11786
- msg: 'DelegateSignerCheckFailed',
11787
- },
11788
- {
11789
- code: 6012,
11790
- name: 'MintTooLarge',
11791
- msg: 'Minted amount greater than u64::MAX',
11792
- },
11793
- {
11794
- code: 6013,
11795
- name: 'SplTokenSupplyMismatch',
11796
- msg: 'SplTokenSupplyMismatch',
11797
- },
11798
- {
11799
- code: 6014,
11800
- name: 'HeapMemoryCheckFailed',
11801
- msg: 'HeapMemoryCheckFailed',
11802
- },
11803
- {
11804
- code: 6015,
11805
- name: 'InstructionNotCallable',
11806
- msg: 'The instruction is not callable',
11807
- },
11808
- {
11809
- code: 6016,
11810
- name: 'ArithmeticUnderflow',
11811
- msg: 'ArithmeticUnderflow',
11812
- },
11813
- {
11814
- code: 6017,
11815
- name: 'HashToFieldError',
11816
- msg: 'HashToFieldError',
11817
- },
11818
- {
11819
- code: 6018,
11820
- name: 'InvalidAuthorityMint',
11821
- msg: 'Expected the authority to be also a mint authority',
11822
- },
11823
- {
11824
- code: 6019,
11825
- name: 'InvalidFreezeAuthority',
11826
- msg: 'Provided authority is not the freeze authority',
11827
- },
11828
- {
11829
- code: 6020,
11830
- name: 'InvalidDelegateIndex',
11831
- },
11832
- {
11833
- code: 6021,
11834
- name: 'TokenPoolPdaUndefined',
11835
- },
11836
- {
11837
- code: 6022,
11838
- name: 'IsTokenPoolPda',
11839
- msg: 'Compress or decompress recipient is the same account as the token pool pda.',
11840
- },
11841
- {
11842
- code: 6023,
11843
- name: 'InvalidTokenPoolPda',
11844
- },
11845
- {
11846
- code: 6024,
11847
- name: 'NoInputTokenAccountsProvided',
11848
- },
11849
- {
11850
- code: 6025,
11851
- name: 'NoInputsProvided',
11745
+ name: 'SerializationError',
11746
+ msg: 'Serialization error',
11852
11747
  },
11853
11748
  ],
11854
11749
  };
@@ -12637,6 +12532,10 @@ const TokenBalanceListResult = type({
12637
12532
  tokenBalances: array(TokenBalanceResult),
12638
12533
  cursor: nullable(string()),
12639
12534
  });
12535
+ const TokenBalanceListResultV2 = type({
12536
+ items: array(TokenBalanceResult),
12537
+ cursor: nullable(string()),
12538
+ });
12640
12539
  const CompressedMintTokenHoldersResult = type({
12641
12540
  cursor: nullable(string()),
12642
12541
  items: array(type({
@@ -13094,8 +12993,10 @@ class Rpc extends web3_js.Connection {
13094
12993
  return { amount: bn(res.result.value.amount) };
13095
12994
  }
13096
12995
  /**
12996
+ * @deprecated use {@link getCompressedTokenBalancesByOwnerV2} instead.
12997
+ *
13097
12998
  * Fetch all the compressed token balances owned by the specified public
13098
- * key. Can filter by mint
12999
+ * key. Can filter by mint. Returns without context.
13099
13000
  */
13100
13001
  async getCompressedTokenBalancesByOwner(owner, options) {
13101
13002
  var _a, _b;
@@ -13122,6 +13023,38 @@ class Rpc extends web3_js.Connection {
13122
13023
  cursor: res.result.value.cursor,
13123
13024
  };
13124
13025
  }
13026
+ /**
13027
+ * Fetch the compressed token balances owned by the specified public
13028
+ * key. Paginated. Can filter by mint. Returns with context.
13029
+ */
13030
+ async getCompressedTokenBalancesByOwnerV2(owner, options) {
13031
+ var _a, _b;
13032
+ if (!options)
13033
+ options = {};
13034
+ const unsafeRes = await rpcRequest(this.compressionApiEndpoint, 'getCompressedTokenBalancesByOwnerV2', {
13035
+ owner: owner.toBase58(),
13036
+ mint: (_a = options.mint) === null || _a === void 0 ? void 0 : _a.toBase58(),
13037
+ limit: (_b = options.limit) === null || _b === void 0 ? void 0 : _b.toNumber(),
13038
+ cursor: options.cursor,
13039
+ });
13040
+ const res = create(unsafeRes, jsonRpcResultAndContext(TokenBalanceListResultV2));
13041
+ if ('error' in res) {
13042
+ throw new web3_js.SolanaJSONRPCError(res.error, `failed to get compressed token balances for owner ${owner.toBase58()}`);
13043
+ }
13044
+ if (res.result.value === null) {
13045
+ throw new Error(`failed to get compressed token balances for owner ${owner.toBase58()}`);
13046
+ }
13047
+ const maybeFiltered = options.mint
13048
+ ? res.result.value.items.filter(tokenBalance => tokenBalance.mint.toBase58() === options.mint.toBase58())
13049
+ : res.result.value.items;
13050
+ return {
13051
+ context: res.result.context,
13052
+ value: {
13053
+ items: maybeFiltered,
13054
+ cursor: res.result.value.cursor,
13055
+ },
13056
+ };
13057
+ }
13125
13058
  /**
13126
13059
  * Returns confirmed compression signatures for transactions involving the specified
13127
13060
  * account hash forward in time from genesis to the most recent confirmed
@@ -13191,8 +13124,13 @@ class Rpc extends web3_js.Connection {
13191
13124
  *
13192
13125
  * @param address queried compressed account address
13193
13126
  */
13194
- async getCompressionSignaturesForAddress(address) {
13195
- const unsafeRes = await rpcRequest(this.compressionApiEndpoint, 'getCompressionSignaturesForAddress', { address: address.toBase58() });
13127
+ async getCompressionSignaturesForAddress(address, options) {
13128
+ var _a;
13129
+ const unsafeRes = await rpcRequest(this.compressionApiEndpoint, 'getCompressionSignaturesForAddress', {
13130
+ address: address.toBase58(),
13131
+ cursor: options === null || options === void 0 ? void 0 : options.cursor,
13132
+ limit: (_a = options === null || options === void 0 ? void 0 : options.limit) === null || _a === void 0 ? void 0 : _a.toNumber(),
13133
+ });
13196
13134
  const res = create(unsafeRes, jsonRpcResultAndContext(SignatureListWithCursorResult));
13197
13135
  if ('error' in res) {
13198
13136
  throw new web3_js.SolanaJSONRPCError(res.error, `failed to get signatures for address ${address.toBase58()}`);
@@ -13209,8 +13147,13 @@ class Rpc extends web3_js.Connection {
13209
13147
  *
13210
13148
  * @param owner queried owner public key
13211
13149
  */
13212
- async getCompressionSignaturesForOwner(owner) {
13213
- const unsafeRes = await rpcRequest(this.compressionApiEndpoint, 'getCompressionSignaturesForOwner', { owner: owner.toBase58() });
13150
+ async getCompressionSignaturesForOwner(owner, options) {
13151
+ var _a;
13152
+ const unsafeRes = await rpcRequest(this.compressionApiEndpoint, 'getCompressionSignaturesForOwner', {
13153
+ owner: owner.toBase58(),
13154
+ cursor: options === null || options === void 0 ? void 0 : options.cursor,
13155
+ limit: (_a = options === null || options === void 0 ? void 0 : options.limit) === null || _a === void 0 ? void 0 : _a.toNumber(),
13156
+ });
13214
13157
  const res = create(unsafeRes, jsonRpcResultAndContext(SignatureListWithCursorResult));
13215
13158
  if ('error' in res) {
13216
13159
  throw new web3_js.SolanaJSONRPCError(res.error, `failed to get signatures for owner ${owner.toBase58()}`);
@@ -13220,14 +13163,18 @@ class Rpc extends web3_js.Connection {
13220
13163
  }
13221
13164
  return res.result.value;
13222
13165
  }
13223
- /// TODO(photon): needs mint
13224
13166
  /**
13225
13167
  * Returns confirmed signatures for compression transactions involving the
13226
13168
  * specified token account owner forward in time from genesis to the most
13227
13169
  * recent confirmed block
13228
13170
  */
13229
- async getCompressionSignaturesForTokenOwner(owner) {
13230
- const unsafeRes = await rpcRequest(this.compressionApiEndpoint, 'getCompressionSignaturesForTokenOwner', { owner: owner.toBase58() });
13171
+ async getCompressionSignaturesForTokenOwner(owner, options) {
13172
+ var _a;
13173
+ const unsafeRes = await rpcRequest(this.compressionApiEndpoint, 'getCompressionSignaturesForTokenOwner', {
13174
+ owner: owner.toBase58(),
13175
+ cursor: options === null || options === void 0 ? void 0 : options.cursor,
13176
+ limit: (_a = options === null || options === void 0 ? void 0 : options.limit) === null || _a === void 0 ? void 0 : _a.toNumber(),
13177
+ });
13231
13178
  const res = create(unsafeRes, jsonRpcResultAndContext(SignatureListWithCursorResult));
13232
13179
  if ('error' in res) {
13233
13180
  throw new web3_js.SolanaJSONRPCError(res.error, `failed to get signatures for owner ${owner.toBase58()}`);
@@ -13277,6 +13224,9 @@ class Rpc extends web3_js.Connection {
13277
13224
  }
13278
13225
  return res.result;
13279
13226
  }
13227
+ /**
13228
+ * Fetch all the compressed token holders for a given mint. Paginated.
13229
+ */
13280
13230
  async getCompressedMintTokenHolders(mint, options) {
13281
13231
  var _a;
13282
13232
  const unsafeRes = await rpcRequest(this.compressionApiEndpoint, 'getCompressedMintTokenHolders', {
@@ -13305,8 +13255,8 @@ class Rpc extends web3_js.Connection {
13305
13255
  /**
13306
13256
  * Fetch all non-voting signatures
13307
13257
  */
13308
- async getLatestNonVotingSignatures(limit) {
13309
- const unsafeRes = await rpcRequest(this.compressionApiEndpoint, 'getLatestNonVotingSignatures', { limit });
13258
+ async getLatestNonVotingSignatures(limit, cursor) {
13259
+ const unsafeRes = await rpcRequest(this.compressionApiEndpoint, 'getLatestNonVotingSignatures', { limit, cursor });
13310
13260
  const res = create(unsafeRes, jsonRpcResultAndContext(LatestNonVotingSignaturesResult));
13311
13261
  if ('error' in res) {
13312
13262
  throw new web3_js.SolanaJSONRPCError(res.error, 'failed to get latest non-voting signatures');
@@ -17218,8 +17168,9 @@ class TestRpc extends web3_js.Connection {
17218
17168
  return { amount: bn(account.parsed.amount) };
17219
17169
  }
17220
17170
  /**
17171
+ * @deprecated use {@link getCompressedTokenBalancesByOwnerV2}.
17221
17172
  * Fetch all the compressed token balances owned by the specified public
17222
- * key. Can filter by mint
17173
+ * key. Can filter by mint.
17223
17174
  */
17224
17175
  async getCompressedTokenBalancesByOwner(publicKey, options) {
17225
17176
  const accounts = await getCompressedTokenAccountsByOwnerTest(this, publicKey, options.mint);
@@ -17231,6 +17182,23 @@ class TestRpc extends web3_js.Connection {
17231
17182
  cursor: null,
17232
17183
  };
17233
17184
  }
17185
+ /**
17186
+ * Fetch all the compressed token balances owned by the specified public
17187
+ * key. Can filter by mint. Uses context.
17188
+ */
17189
+ async getCompressedTokenBalancesByOwnerV2(publicKey, options) {
17190
+ const accounts = await getCompressedTokenAccountsByOwnerTest(this, publicKey, options.mint);
17191
+ return {
17192
+ context: { slot: 1 },
17193
+ value: {
17194
+ items: accounts.items.map(account => ({
17195
+ balance: bn(account.parsed.amount),
17196
+ mint: account.parsed.mint,
17197
+ })),
17198
+ cursor: null,
17199
+ },
17200
+ };
17201
+ }
17234
17202
  /**
17235
17203
  * Returns confirmed signatures for transactions involving the specified
17236
17204
  * account hash forward in time from genesis to the most recent confirmed
@@ -17238,14 +17206,14 @@ class TestRpc extends web3_js.Connection {
17238
17206
  *
17239
17207
  * @param hash queried account hash
17240
17208
  */
17241
- async getCompressionSignaturesForAccount(hash) {
17209
+ async getCompressionSignaturesForAccount(_hash) {
17242
17210
  throw new Error('getCompressionSignaturesForAccount not implemented in test-rpc');
17243
17211
  }
17244
17212
  /**
17245
17213
  * Fetch a confirmed or finalized transaction from the cluster. Return with
17246
17214
  * CompressionInfo
17247
17215
  */
17248
- async getTransactionWithCompressionInfo(signature) {
17216
+ async getTransactionWithCompressionInfo(_signature) {
17249
17217
  throw new Error('getCompressedTransaction not implemented in test-rpc');
17250
17218
  }
17251
17219
  /**
@@ -17255,7 +17223,7 @@ class TestRpc extends web3_js.Connection {
17255
17223
  *
17256
17224
  * @param address queried compressed account address
17257
17225
  */
17258
- async getCompressionSignaturesForAddress(_address) {
17226
+ async getCompressionSignaturesForAddress(_address, _options) {
17259
17227
  throw new Error('getSignaturesForAddress3 not implemented');
17260
17228
  }
17261
17229
  /**
@@ -17265,7 +17233,7 @@ class TestRpc extends web3_js.Connection {
17265
17233
  *
17266
17234
  * @param owner queried owner public key
17267
17235
  */
17268
- async getCompressionSignaturesForOwner(owner) {
17236
+ async getCompressionSignaturesForOwner(_owner, _options) {
17269
17237
  throw new Error('getSignaturesForOwner not implemented');
17270
17238
  }
17271
17239
  /**
@@ -17273,7 +17241,7 @@ class TestRpc extends web3_js.Connection {
17273
17241
  * specified token account owner forward in time from genesis to the most
17274
17242
  * recent confirmed block
17275
17243
  */
17276
- async getCompressionSignaturesForTokenOwner(owner) {
17244
+ async getCompressionSignaturesForTokenOwner(_owner, _options) {
17277
17245
  throw new Error('getSignaturesForTokenOwner not implemented');
17278
17246
  }
17279
17247
  /**
@@ -17517,6 +17485,7 @@ exports.SlotResult = SlotResult;
17517
17485
  exports.TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD = TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD;
17518
17486
  exports.TestRpc = TestRpc;
17519
17487
  exports.TokenBalanceListResult = TokenBalanceListResult;
17488
+ exports.TokenBalanceListResultV2 = TokenBalanceListResultV2;
17520
17489
  exports.TokenBalanceResult = TokenBalanceResult;
17521
17490
  exports.TokenDataResult = TokenDataResult;
17522
17491
  exports.UTXO_MERGE_MAXIMUM = UTXO_MERGE_MAXIMUM;