@lightprotocol/stateless.js 0.20.9 → 0.21.0

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.
Files changed (58) hide show
  1. package/dist/cjs/browser/actions/compress.d.ts +9 -7
  2. package/dist/cjs/browser/actions/create-account.d.ts +25 -28
  3. package/dist/cjs/browser/actions/decompress.d.ts +6 -7
  4. package/dist/cjs/browser/actions/index.d.ts +1 -1
  5. package/dist/cjs/browser/actions/transfer.d.ts +8 -11
  6. package/dist/cjs/browser/constants.d.ts +16 -6
  7. package/dist/cjs/browser/index.cjs +1 -1
  8. package/dist/cjs/browser/index.cjs.map +1 -1
  9. package/dist/cjs/browser/index.d.ts +2 -2
  10. package/dist/cjs/browser/instruction/pack-compressed-accounts.d.ts +15 -17
  11. package/dist/cjs/browser/programs/layout.d.ts +27 -0
  12. package/dist/cjs/browser/programs/system.d.ts +18 -27
  13. package/dist/cjs/browser/rpc-interface.d.ts +92 -27
  14. package/dist/cjs/browser/rpc.d.ts +21 -41
  15. package/dist/cjs/browser/state/BN254.d.ts +0 -1
  16. package/dist/cjs/browser/state/bn.d.ts +3 -0
  17. package/dist/cjs/browser/state/compressed-account.d.ts +53 -13
  18. package/dist/cjs/browser/state/index.d.ts +1 -0
  19. package/dist/cjs/browser/state/types.d.ts +87 -12
  20. package/dist/cjs/browser/test-helpers/test-rpc/get-compressed-accounts.d.ts +10 -1
  21. package/dist/cjs/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +1 -1
  22. package/dist/cjs/browser/test-helpers/test-rpc/test-rpc.d.ts +15 -19
  23. package/dist/cjs/browser/utils/get-state-tree-infos.d.ts +41 -0
  24. package/dist/cjs/browser/utils/index.d.ts +5 -2
  25. package/dist/cjs/browser/utils/parse-validity-proof.d.ts +3 -3
  26. package/dist/cjs/browser/utils/state-tree-lookup-table.d.ts +68 -0
  27. package/dist/cjs/node/actions/compress.d.ts +9 -7
  28. package/dist/cjs/node/actions/create-account.d.ts +25 -28
  29. package/dist/cjs/node/actions/decompress.d.ts +6 -7
  30. package/dist/cjs/node/actions/index.d.ts +1 -1
  31. package/dist/cjs/node/actions/transfer.d.ts +8 -11
  32. package/dist/cjs/node/constants.d.ts +16 -6
  33. package/dist/cjs/node/index.cjs +1 -1
  34. package/dist/cjs/node/index.cjs.map +1 -1
  35. package/dist/cjs/node/index.d.ts +2 -2
  36. package/dist/cjs/node/instruction/pack-compressed-accounts.d.ts +15 -17
  37. package/dist/cjs/node/programs/layout.d.ts +27 -0
  38. package/dist/cjs/node/programs/system.d.ts +18 -27
  39. package/dist/cjs/node/rpc-interface.d.ts +92 -27
  40. package/dist/cjs/node/rpc.d.ts +21 -41
  41. package/dist/cjs/node/state/BN254.d.ts +0 -1
  42. package/dist/cjs/node/state/bn.d.ts +3 -0
  43. package/dist/cjs/node/state/compressed-account.d.ts +53 -13
  44. package/dist/cjs/node/state/index.d.ts +1 -0
  45. package/dist/cjs/node/state/types.d.ts +87 -12
  46. package/dist/cjs/node/test-helpers/test-rpc/get-compressed-accounts.d.ts +10 -1
  47. package/dist/cjs/node/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +1 -1
  48. package/dist/cjs/node/test-helpers/test-rpc/test-rpc.d.ts +15 -19
  49. package/dist/cjs/node/utils/get-state-tree-infos.d.ts +41 -0
  50. package/dist/cjs/node/utils/index.d.ts +5 -2
  51. package/dist/cjs/node/utils/parse-validity-proof.d.ts +3 -3
  52. package/dist/cjs/node/utils/state-tree-lookup-table.d.ts +68 -0
  53. package/dist/types/index.d.ts +565 -358
  54. package/package.json +4 -3
  55. package/dist/cjs/browser/utils/get-light-state-tree-info.d.ts +0 -76
  56. package/dist/cjs/node/utils/get-light-state-tree-info.d.ts +0 -76
  57. /package/dist/cjs/browser/{actions/common.d.ts → utils/dedupe-signer.d.ts} +0 -0
  58. /package/dist/cjs/node/{actions/common.d.ts → utils/dedupe-signer.d.ts} +0 -0
@@ -1,10 +1,10 @@
1
1
  import { Connection, ConnectionConfig, PublicKey } from '@solana/web3.js';
2
2
  import { Buffer } from 'buffer';
3
- import { CompressedProofWithContext, CompressedTransaction, CompressionApiInterface, GetCompressedTokenAccountsByOwnerOrDelegateOptions, HexInputsForProver, ParsedTokenAccount, SignatureWithMetadata, LatestNonVotingSignatures, LatestNonVotingSignaturesPaginated, WithContext, GetCompressedAccountsByOwnerConfig, WithCursor, AddressWithTree, HashWithTree, CompressedMintTokenHolders, TokenBalance, PaginatedOptions } from './rpc-interface';
4
- import { MerkleContextWithMerkleProof, BN254, CompressedAccountWithMerkleContext, CompressedProof } from './state';
3
+ import { ValidityProofWithContext, CompressedTransaction, CompressionApiInterface, GetCompressedTokenAccountsByOwnerOrDelegateOptions, HexInputsForProver, ParsedTokenAccount, SignatureWithMetadata, LatestNonVotingSignatures, LatestNonVotingSignaturesPaginated, WithContext, GetCompressedAccountsByOwnerConfig, WithCursor, AddressWithTree, HashWithTree, CompressedMintTokenHolders, TokenBalance, PaginatedOptions } from './rpc-interface';
4
+ import { MerkleContextWithMerkleProof, BN254, CompressedAccountWithMerkleContext, ValidityProof, AddressTreeInfo } from './state';
5
5
  import BN from 'bn.js';
6
6
  import { LightWasm } from './test-helpers';
7
- import { ActiveTreeBundle } from './state/types';
7
+ import { StateTreeInfo } from './state/types';
8
8
  /** @internal */
9
9
  export declare function parseAccountData({ discriminator, data, dataHash, }: {
10
10
  discriminator: BN;
@@ -35,7 +35,7 @@ export declare function wrapBigNumbersAsStrings(text: string): string;
35
35
  /** @internal */
36
36
  export declare const rpcRequest: (rpcEndpoint: string, method: string, params?: any, convertToCamelCase?: boolean, debug?: boolean) => Promise<any>;
37
37
  /** @internal */
38
- export declare const proverRequest: (proverEndpoint: string, method: "inclusion" | "new-address" | "combined", params?: any, log?: boolean, publicInputHash?: BN | undefined) => Promise<CompressedProof>;
38
+ export declare const proverRequest: (proverEndpoint: string, method: "inclusion" | "new-address" | "combined", params?: any, log?: boolean, publicInputHash?: BN | undefined) => Promise<ValidityProof>;
39
39
  export type NonInclusionMerkleProofInputs = {
40
40
  root: BN;
41
41
  value: BN;
@@ -54,8 +54,7 @@ export type MerkleContextWithNewAddressProof = {
54
54
  nextIndex: BN;
55
55
  merkleProofHashedIndexedElementLeaf: BN[];
56
56
  indexHashedIndexedElementLeaf: BN;
57
- merkleTree: PublicKey;
58
- nullifierQueue: PublicKey;
57
+ treeInfo: AddressTreeInfo;
59
58
  };
60
59
  export type NonInclusionJsonStruct = {
61
60
  root: string;
@@ -69,14 +68,6 @@ export type NonInclusionJsonStruct = {
69
68
  export declare function convertMerkleProofsWithContextToHex(merkleProofsWithContext: MerkleContextWithMerkleProof[]): HexInputsForProver[];
70
69
  export declare function convertNonInclusionMerkleProofInputsToHex(nonInclusionMerkleProofInputs: MerkleContextWithNewAddressProof[]): NonInclusionJsonStruct[];
71
70
  export declare function getPublicInputHash(accountProofs: MerkleContextWithMerkleProof[], accountHashes: BN254[], newAddressProofs: MerkleContextWithNewAddressProof[], lightWasm: LightWasm): BN;
72
- /**
73
- * Get the queue for a given tree
74
- *
75
- * @param info - The active state tree addresses
76
- * @param tree - The tree to get the queue for
77
- * @returns The queue for the given tree, or undefined if not found
78
- */
79
- export declare function getQueueForTree(info: ActiveTreeBundle[], tree: PublicKey): PublicKey;
80
71
  /**
81
72
  * Get the tree for a given queue
82
73
  *
@@ -84,40 +75,31 @@ export declare function getQueueForTree(info: ActiveTreeBundle[], tree: PublicKe
84
75
  * @param queue - The queue to get the tree for
85
76
  * @returns The tree for the given queue, or undefined if not found
86
77
  */
87
- export declare function getTreeForQueue(info: ActiveTreeBundle[], queue: PublicKey): PublicKey;
88
- /**
89
- * Get a random tree and queue from the active state tree addresses.
90
- *
91
- * Prevents write lock contention on state trees.
92
- *
93
- * @param info - The active state tree addresses
94
- * @returns A random tree and queue
95
- */
96
- export declare function pickRandomTreeAndQueue(info: ActiveTreeBundle[]): {
97
- tree: PublicKey;
98
- queue: PublicKey;
99
- };
78
+ export declare function getTreeForQueue(info: StateTreeInfo[], queue: PublicKey): PublicKey;
100
79
  /**
101
80
  *
102
81
  */
103
82
  export declare class Rpc extends Connection implements CompressionApiInterface {
104
83
  compressionApiEndpoint: string;
105
84
  proverEndpoint: string;
106
- activeStateTreeInfo: ActiveTreeBundle[] | null;
85
+ allStateTreeInfos: StateTreeInfo[] | null;
86
+ lastStateTreeFetchTime: number | null;
87
+ CACHE_TTL: number;
88
+ fetchPromise: Promise<StateTreeInfo[]> | null;
107
89
  constructor(endpoint: string, compressionApiEndpoint: string, proverEndpoint: string, config?: ConnectionConfig);
108
90
  /**
109
- * Manually set state tree addresses
91
+ * @deprecated Use {@link getStateTreeInfos} instead
110
92
  */
111
- setStateTreeInfo(info: ActiveTreeBundle[]): void;
93
+ getCachedActiveStateTreeInfos(): Promise<void>;
112
94
  /**
113
- * Get the active state tree addresses from the cluster.
114
- * If not already cached, fetches from the cluster.
95
+ * Get a list of all state tree infos. If not already cached, fetches from
96
+ * the cluster.
115
97
  */
116
- getCachedActiveStateTreeInfo(): Promise<ActiveTreeBundle[]>;
98
+ getStateTreeInfos(): Promise<StateTreeInfo[]>;
117
99
  /**
118
- * Fetch the latest state tree addresses from the cluster.
100
+ * @internal
119
101
  */
120
- getLatestActiveStateTreeInfo(): Promise<ActiveTreeBundle[]>;
102
+ doFetch(): Promise<StateTreeInfo[]>;
121
103
  /**
122
104
  * Fetch the compressed account for the specified account address or hash
123
105
  */
@@ -265,12 +247,10 @@ export declare class Rpc extends Connection implements CompressionApiInterface {
265
247
  * @param newAddresses Array of BN254 new addresses.
266
248
  * @returns validity proof with context
267
249
  */
268
- getValidityProofDirect(hashes?: BN254[], newAddresses?: BN254[]): Promise<CompressedProofWithContext>;
250
+ getValidityProofDirect(hashes?: BN254[], newAddresses?: BN254[]): Promise<ValidityProofWithContext>;
269
251
  /**
270
252
  * @deprecated use {@link getValidityProofV0} instead.
271
253
  *
272
- *
273
- *
274
254
  * Fetch the latest validity proof for (1) compressed accounts specified by
275
255
  * an array of account hashes. (2) new unique addresses specified by an
276
256
  * array of addresses.
@@ -284,7 +264,7 @@ export declare class Rpc extends Connection implements CompressionApiInterface {
284
264
  * @param newAddresses Array of BN254 new addresses.
285
265
  * @returns validity proof with context
286
266
  */
287
- getValidityProof(hashes?: BN254[], newAddresses?: BN254[]): Promise<CompressedProofWithContext>;
267
+ getValidityProof(hashes?: BN254[], newAddresses?: BN254[]): Promise<ValidityProofWithContext>;
288
268
  /**
289
269
  * Fetch the latest validity proof for (1) compressed accounts specified by
290
270
  * an array of account hashes. (2) new unique addresses specified by an
@@ -299,7 +279,7 @@ export declare class Rpc extends Connection implements CompressionApiInterface {
299
279
  * @param newAddresses Array of { address: BN254, tree: PublicKey, queue: PublicKey }.
300
280
  * @returns validity proof with context
301
281
  */
302
- getValidityProofV0(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<CompressedProofWithContext>;
282
+ getValidityProofV0(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<ValidityProofWithContext>;
303
283
  /**
304
284
  * Fetch the latest validity proof for (1) compressed accounts specified by
305
285
  * an array of account hashes. (2) new unique addresses specified by an
@@ -316,5 +296,5 @@ export declare class Rpc extends Connection implements CompressionApiInterface {
316
296
  * state tree/queue.
317
297
  * @returns validity proof with context
318
298
  */
319
- getValidityProofAndRpcContext(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<WithContext<CompressedProofWithContext>>;
299
+ getValidityProofAndRpcContext(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<WithContext<ValidityProofWithContext>>;
320
300
  }
@@ -7,7 +7,6 @@ import { Buffer } from 'buffer';
7
7
  * are used to from working with the web3.js PublicKey type.
8
8
  */
9
9
  export type BN254 = BN;
10
- export declare const bn: (number: string | number | BN | Buffer | Uint8Array | number[], base?: number | "hex" | undefined, endian?: BN.Endianness | undefined) => BN;
11
10
  /** Create a bigint instance with <254-bit max size and base58 capabilities */
12
11
  export declare const createBN254: (number: string | number | BN | Buffer | Uint8Array | number[], base?: number | "hex" | "base58" | undefined) => BN254;
13
12
  /** Convert <254-bit bigint to Base58 string. */
@@ -0,0 +1,3 @@
1
+ import BN from 'bn.js';
2
+ import { Buffer } from 'buffer';
3
+ export declare const bn: (number: string | number | BN | Buffer | Uint8Array | number[], base?: number | "hex" | undefined, endian?: BN.Endianness | undefined) => BN;
@@ -1,31 +1,71 @@
1
- import BN from 'bn.js';
2
1
  import { PublicKey } from '@solana/web3.js';
3
- import { CompressedAccount, CompressedAccountData } from './types';
2
+ import { CompressedAccount, CompressedAccountData, StateTreeInfo } from './types';
3
+ import BN from 'bn.js';
4
4
  import { BN254 } from './BN254';
5
5
  export type CompressedAccountWithMerkleContext = CompressedAccount & MerkleContext & {
6
6
  readOnly: boolean;
7
7
  };
8
8
  /**
9
- * Context for compressed account inserted into a state Merkle tree
10
- * */
11
- export type MerkleContext = {
12
- /** State Merkle tree */
9
+ * @deprecated use {@link MerkleContext} instead.
10
+ *
11
+ * Legacy MerkleContext
12
+ */
13
+ export type MerkleContextLegacy = {
14
+ /**
15
+ * State tree
16
+ */
13
17
  merkleTree: PublicKey;
14
- /** The state nullfier queue belonging to merkleTree */
18
+ /**
19
+ * Nullifier queue
20
+ */
15
21
  nullifierQueue: PublicKey;
16
- /** Poseidon hash of the utxo preimage. Is a leaf in state merkle tree */
22
+ /**
23
+ * Poseidon hash of the account. Stored as leaf in state tree
24
+ */
17
25
  hash: number[];
18
- /** 'hash' position within the Merkle tree */
26
+ /**
27
+ * Position of `hash` in the State tree
28
+ */
29
+ leafIndex: number;
30
+ };
31
+ /**
32
+ * Context for compressed account stored in a state tree
33
+ */
34
+ export type MerkleContext = {
35
+ /**
36
+ * Tree info
37
+ */
38
+ treeInfo: StateTreeInfo;
39
+ /**
40
+ * Poseidon hash of the account. Stored as leaf in state tree
41
+ */
42
+ hash: BN;
43
+ /**
44
+ * Position of `hash` in the State tree
45
+ */
19
46
  leafIndex: number;
47
+ /**
48
+ * Whether the account can be proven by index or by merkle proof
49
+ */
50
+ proveByIndex: boolean;
20
51
  };
52
+ /**
53
+ * MerkleContext with merkle proof
54
+ */
21
55
  export type MerkleContextWithMerkleProof = MerkleContext & {
22
- /** Recent valid 'hash' proof path, expires after n slots */
56
+ /**
57
+ * Recent valid 'hash' proof path, expires after n slots
58
+ */
23
59
  merkleProof: BN254[];
24
- /** Index of state root the merkleproof is valid for, expires after n slots */
60
+ /**
61
+ * Index of state root the merkleproof is valid for, expires after n slots
62
+ */
25
63
  rootIndex: number;
26
- /** Current root */
64
+ /**
65
+ * Current root
66
+ */
27
67
  root: BN254;
28
68
  };
29
69
  export declare const createCompressedAccount: (owner: PublicKey, lamports?: BN, data?: CompressedAccountData, address?: number[]) => CompressedAccount;
30
70
  export declare const createCompressedAccountWithMerkleContext: (merkleContext: MerkleContext, owner: PublicKey, lamports?: BN, data?: CompressedAccountData, address?: number[]) => CompressedAccountWithMerkleContext;
31
- export declare const createMerkleContext: (merkleTree: PublicKey, nullifierQueue: PublicKey, hash: number[], leafIndex: number) => MerkleContext;
71
+ export declare const createMerkleContext: (treeInfo: StateTreeInfo, hash: BN254, leafIndex: number, proveByIndex?: boolean) => MerkleContext;
@@ -1,3 +1,4 @@
1
1
  export * from './BN254';
2
+ export * from './bn';
2
3
  export * from './compressed-account';
3
4
  export * from './types';
@@ -6,26 +6,79 @@ export declare enum TreeType {
6
6
  /**
7
7
  * v1 state merkle tree
8
8
  */
9
- State = 0,
9
+ StateV1 = 1,
10
10
  /**
11
11
  * v1 address merkle tree
12
12
  */
13
- Address = 1,
13
+ AddressV1 = 2,
14
14
  /**
15
15
  * v2 state merkle tree
16
16
  */
17
- BatchedState = 2,
17
+ StateV2 = 3,
18
18
  /**
19
19
  * v2 address merkle tree
20
20
  */
21
- BatchedAddress = 3
21
+ AddressV2 = 4
22
22
  }
23
+ /**
24
+ * @deprecated Use {@link StateTreeInfo} instead.
25
+ *
26
+ * A bundle of active trees for a given tree type.
27
+ */
23
28
  export type ActiveTreeBundle = {
24
29
  tree: PublicKey;
25
30
  queue: PublicKey | null;
26
31
  cpiContext: PublicKey | null;
27
32
  treeType: TreeType;
28
33
  };
34
+ /**
35
+ * State tree info, versioned via {@link TreeType}. The protocol
36
+ * stores compressed accounts in state trees.
37
+ *
38
+ * Onchain Accounts are subject to Solana's write-lock limits.
39
+ *
40
+ * To load balance transactions, use {@link selectStateTreeInfo} to
41
+ * select a random tree from a range of active trees.
42
+ *
43
+ * Example:
44
+ * ```typescript
45
+ * const infos = await rpc.getStateTreeInfos();
46
+ * const info = selectStateTreeInfo(infos);
47
+ * const ix = await CompressedTokenProgram.compress({
48
+ * // ...
49
+ * outputStateTreeInfo: info
50
+ * });
51
+ * ```
52
+ */
53
+ export type StateTreeInfo = {
54
+ /**
55
+ * Pubkey of the tree account.
56
+ */
57
+ tree: PublicKey;
58
+ /**
59
+ * Pubkey of the queue account associated with the tree.
60
+ */
61
+ queue: PublicKey;
62
+ /**
63
+ * The type of tree. One of {@link TreeType}.
64
+ */
65
+ treeType: TreeType;
66
+ /**
67
+ * Optional compressed cpi context account.
68
+ */
69
+ cpiContext?: PublicKey;
70
+ /**
71
+ * Optional next tree info if the tree is full.
72
+ */
73
+ nextTreeInfo: StateTreeInfo | null;
74
+ };
75
+ /**
76
+ * Address tree info, versioned via {@link TreeType}. The protocol
77
+ * stores PDAs in address trees.
78
+ */
79
+ export type AddressTreeInfo = Omit<StateTreeInfo, 'cpiContext' | 'nextTreeInfo'> & {
80
+ nextTreeInfo: AddressTreeInfo | null;
81
+ };
29
82
  export interface PackedCompressedAccountWithMerkleContext {
30
83
  compressedAccount: CompressedAccount;
31
84
  merkleContext: PackedMerkleContext;
@@ -47,22 +100,27 @@ export interface QueueIndex {
47
100
  * compressed account.
48
101
  * */
49
102
  export interface CompressedAccount {
50
- /** Public key of program or user that owns the account */
103
+ /**
104
+ * Public key of program or user owning the account.
105
+ */
51
106
  owner: PublicKey;
52
- /** Lamports attached to the account */
107
+ /**
108
+ * Lamports attached to the account.
109
+ */
53
110
  lamports: BN;
54
111
  /**
55
- * TODO: use PublicKey. Optional unique account ID that is persistent across
56
- * transactions.
112
+ * Optional unique account ID that is persistent across transactions.
57
113
  */
58
114
  address: number[] | null;
59
- /** Optional data attached to the account */
115
+ /**
116
+ * Optional data attached to the account.
117
+ */
60
118
  data: CompressedAccountData | null;
61
119
  }
62
120
  /**
63
121
  * Describe the generic compressed account details applicable to every
64
122
  * compressed account.
65
- * */
123
+ */
66
124
  export interface OutputCompressedAccountWithPackedContext {
67
125
  compressedAccount: CompressedAccount;
68
126
  merkleTreeIndex: number;
@@ -89,7 +147,7 @@ export interface PublicTransactionEvent {
89
147
  message: Uint8Array | null;
90
148
  }
91
149
  export interface InstructionDataInvoke {
92
- proof: CompressedProof | null;
150
+ proof: ValidityProof | null;
93
151
  inputCompressedAccountsWithMerkleContext: PackedCompressedAccountWithMerkleContext[];
94
152
  outputCompressedAccounts: OutputCompressedAccountWithPackedContext[];
95
153
  relayFee: BN | null;
@@ -98,7 +156,7 @@ export interface InstructionDataInvoke {
98
156
  isCompress: boolean;
99
157
  }
100
158
  export interface InstructionDataInvokeCpi {
101
- proof: CompressedProof | null;
159
+ proof: ValidityProof | null;
102
160
  inputCompressedAccountsWithMerkleContext: PackedCompressedAccountWithMerkleContext[];
103
161
  outputCompressedAccounts: OutputCompressedAccountWithPackedContext[];
104
162
  relayFee: BN | null;
@@ -112,11 +170,28 @@ export interface CompressedCpiContext {
112
170
  first_set_context: boolean;
113
171
  cpi_context_account_index: number;
114
172
  }
173
+ /**
174
+ * @deprecated Use {@link ValidityProof} instead.
175
+ */
115
176
  export interface CompressedProof {
116
177
  a: number[];
117
178
  b: number[];
118
179
  c: number[];
119
180
  }
181
+ /**
182
+ * Validity proof.
183
+ *
184
+ * You can request proofs via `rpc.getValidityProof` or
185
+ * `rpc.getValidityProofV0`.
186
+ *
187
+ * One proof is 128 bytes large, and can prove the existence of N compressed
188
+ * accounts or the uniqueness of N PDAs.
189
+ */
190
+ export interface ValidityProof {
191
+ a: number[];
192
+ b: number[];
193
+ c: number[];
194
+ }
120
195
  export interface InputTokenDataWithContext {
121
196
  amount: BN;
122
197
  delegateIndex: number | null;
@@ -1,7 +1,16 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
3
  import { Rpc } from '../../rpc';
4
- import { CompressedAccountWithMerkleContext } from '../../state';
4
+ import { CompressedAccountWithMerkleContext, StateTreeInfo } from '../../state';
5
+ /**
6
+ * Get the info for a given tree or queue
7
+ *
8
+ * @param info The active state tree addresses
9
+ * @param treeOrQueue The tree or queue to get the info for
10
+ * @returns The info for the given tree or queue, or throws an error if not
11
+ * found
12
+ */
13
+ export declare function getStateTreeInfoByPubkey(treeInfos: StateTreeInfo[], treeOrQueue: PublicKey): StateTreeInfo;
5
14
  export declare function getCompressedAccountsByOwnerTest(rpc: Rpc, owner: PublicKey): Promise<CompressedAccountWithMerkleContext[]>;
6
15
  export declare function getCompressedAccountByHashTest(rpc: Rpc, hash: BN): Promise<CompressedAccountWithMerkleContext | undefined>;
7
16
  export declare function getMultipleCompressedAccountsByHashTest(rpc: Rpc, hashes: BN[]): Promise<CompressedAccountWithMerkleContext[]>;
@@ -32,7 +32,7 @@ export declare function parseTokenLayoutWithIdl(compressedAccount: CompressedAcc
32
32
  * @param owner PublicKey of the token owner
33
33
  * @param mint PublicKey of the token mint
34
34
  */
35
- export declare function getCompressedTokenAccounts(events: PublicTransactionEvent[]): Promise<ParsedTokenAccount[]>;
35
+ export declare function getCompressedTokenAccounts(events: PublicTransactionEvent[], rpc: Rpc): Promise<ParsedTokenAccount[]>;
36
36
  /** @internal */
37
37
  export declare function getCompressedTokenAccountsByOwnerTest(rpc: Rpc, owner: PublicKey, mint: PublicKey): Promise<WithCursor<ParsedTokenAccount[]>>;
38
38
  export declare function getCompressedTokenAccountsByDelegateTest(rpc: Rpc, delegate: PublicKey, mint: PublicKey): Promise<WithCursor<ParsedTokenAccount[]>>;
@@ -1,10 +1,10 @@
1
1
  import { Connection, ConnectionConfig, PublicKey } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
3
  import { AddressWithTree, CompressedMintTokenHolders, CompressedTransaction, GetCompressedAccountsByOwnerConfig, PaginatedOptions, HashWithTree, LatestNonVotingSignatures, LatestNonVotingSignaturesPaginated, SignatureWithMetadata, WithContext, WithCursor } from '../../rpc-interface';
4
- import { CompressedProofWithContext, CompressionApiInterface, GetCompressedTokenAccountsByOwnerOrDelegateOptions, ParsedTokenAccount, TokenBalance } from '../../rpc-interface';
4
+ import { ValidityProofWithContext, CompressionApiInterface, GetCompressedTokenAccountsByOwnerOrDelegateOptions, ParsedTokenAccount, TokenBalance } from '../../rpc-interface';
5
5
  import { BN254, CompressedAccountWithMerkleContext, MerkleContextWithMerkleProof } from '../../state';
6
6
  import { MerkleContextWithNewAddressProof } from '../../rpc';
7
- import { ActiveTreeBundle } from '../../state/types';
7
+ import { StateTreeInfo } from '../../state/types';
8
8
  export interface TestRpcConfig {
9
9
  /**
10
10
  * Address of the state tree to index. Default: public default test state
@@ -55,7 +55,7 @@ export interface LightWasm {
55
55
  * @param depth Depth of the merkle tree.
56
56
  * @param log Log proof generation time.
57
57
  */
58
- export declare function getTestRpc(lightWasm: LightWasm, endpoint?: string, compressionApiEndpoint?: string, proverEndpoint?: string, merkleTreeAddress?: PublicKey, nullifierQueueAddress?: PublicKey, depth?: number, log?: boolean): Promise<TestRpc>;
58
+ export declare function getTestRpc(lightWasm: LightWasm, endpoint?: string, compressionApiEndpoint?: string, proverEndpoint?: string, depth?: number, log?: boolean): Promise<TestRpc>;
59
59
  /**
60
60
  * Simple mock rpc for unit tests that simulates the compression rpc interface.
61
61
  * Fetches, parses events and builds merkletree on-demand, i.e. it does not persist state.
@@ -68,14 +68,13 @@ export declare function getTestRpc(lightWasm: LightWasm, endpoint?: string, comp
68
68
  export declare class TestRpc extends Connection implements CompressionApiInterface {
69
69
  compressionApiEndpoint: string;
70
70
  proverEndpoint: string;
71
- merkleTreeAddress: PublicKey;
72
- nullifierQueueAddress: PublicKey;
73
- addressTreeAddress: PublicKey;
74
- addressQueueAddress: PublicKey;
75
71
  lightWasm: LightWasm;
76
72
  depth: number;
77
73
  log: boolean;
78
- activeStateTreeInfo: ActiveTreeBundle[] | null;
74
+ allStateTreeInfos: StateTreeInfo[] | null;
75
+ lastStateTreeFetchTime: number | null;
76
+ fetchPromise: Promise<StateTreeInfo[]> | null;
77
+ CACHE_TTL: number;
79
78
  /**
80
79
  * Establish a Compression-compatible JSON RPC mock-connection
81
80
  *
@@ -90,17 +89,14 @@ export declare class TestRpc extends Connection implements CompressionApiInterfa
90
89
  */
91
90
  constructor(endpoint: string, hasher: LightWasm, compressionApiEndpoint: string, proverEndpoint: string, connectionConfig?: ConnectionConfig, testRpcConfig?: TestRpcConfig);
92
91
  /**
93
- * Manually set state tree addresses
92
+ * @deprecated Use {@link getStateTreeInfos} instead
94
93
  */
95
- setStateTreeInfo(info: ActiveTreeBundle[]): void;
94
+ getCachedActiveStateTreeInfos(): Promise<void>;
96
95
  /**
97
96
  * Returns local test state trees.
98
97
  */
99
- getCachedActiveStateTreeInfo(): Promise<ActiveTreeBundle[]>;
100
- /**
101
- * Returns local test state trees.
102
- */
103
- getLatestActiveStateTreeInfo(): Promise<ActiveTreeBundle[]>;
98
+ getStateTreeInfos(): Promise<StateTreeInfo[]>;
99
+ doFetch(): Promise<StateTreeInfo[]>;
104
100
  /**
105
101
  * Fetch the compressed account for the specified account hash
106
102
  */
@@ -238,12 +234,12 @@ export declare class TestRpc extends Connection implements CompressionApiInterfa
238
234
  * Note: Use RPC class for forested trees. TestRpc is only for custom
239
235
  * testing purposes.
240
236
  */
241
- getValidityProofDirect(hashes?: BN254[], newAddresses?: BN254[]): Promise<CompressedProofWithContext>;
237
+ getValidityProofDirect(hashes?: BN254[], newAddresses?: BN254[]): Promise<ValidityProofWithContext>;
242
238
  /**
243
239
  * @deprecated This method is not available for TestRpc. Please use
244
240
  * {@link getValidityProof} instead.
245
241
  */
246
- getValidityProofAndRpcContext(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<WithContext<CompressedProofWithContext>>;
242
+ getValidityProofAndRpcContext(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<WithContext<ValidityProofWithContext>>;
247
243
  /**
248
244
  * Fetch the latest validity proof for (1) compressed accounts specified by
249
245
  * an array of account hashes. (2) new unique addresses specified by an
@@ -258,6 +254,6 @@ export declare class TestRpc extends Connection implements CompressionApiInterfa
258
254
  * @param newAddresses Array of BN254 new addresses.
259
255
  * @returns validity proof with context
260
256
  */
261
- getValidityProof(hashes?: BN254[], newAddresses?: BN254[]): Promise<CompressedProofWithContext>;
262
- getValidityProofV0(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<CompressedProofWithContext>;
257
+ getValidityProof(hashes?: BN254[], newAddresses?: BN254[]): Promise<ValidityProofWithContext>;
258
+ getValidityProofV0(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<ValidityProofWithContext>;
263
259
  }
@@ -0,0 +1,41 @@
1
+ import { Connection, PublicKey } from '@solana/web3.js';
2
+ import { StateTreeInfo, TreeType } from '../state/types';
3
+ import { StateTreeLUTPair } from '../constants';
4
+ /**
5
+ * @deprecated use {@link selectStateTreeInfo} instead.
6
+ *
7
+ * Get a random tree and queue from a set of provided state tree infos.
8
+ *
9
+ * @param infos Set of state tree infos
10
+ * @returns A random tree and queue
11
+ */
12
+ export declare function pickRandomTreeAndQueue(infos: StateTreeInfo[]): {
13
+ tree: PublicKey;
14
+ queue: PublicKey;
15
+ };
16
+ /**
17
+ * Get a pseudo-random active state tree info from the set of provided state
18
+ * tree infos.
19
+ *
20
+ * Using this mitigates write lock contention on state trees.
21
+ *
22
+ * @param infos Set of state tree infos
23
+ * @param treeType The type of tree. Defaults to `TreeType.StateV1`
24
+ * @param useMaxConcurrency If true, return all infos. If false, return at
25
+ * most {@link MAX_HOTSPOTS}. Defaults to `false`.
26
+ *
27
+ * @returns A pseudo-randomly selected tree info
28
+ */
29
+ export declare function selectStateTreeInfo(infos: StateTreeInfo[], treeType?: TreeType, useMaxConcurrency?: boolean): StateTreeInfo;
30
+ /**
31
+ * Get active state tree infos from LUTs.
32
+ *
33
+ * @param connection The connection to the cluster
34
+ * @param stateTreeLUTPairs The state tree lookup table pairs
35
+ *
36
+ * @returns The active state tree infos
37
+ */
38
+ export declare function getAllStateTreeInfos({ connection, stateTreeLUTPairs, }: {
39
+ connection: Connection;
40
+ stateTreeLUTPairs: StateTreeLUTPair[];
41
+ }): Promise<StateTreeInfo[]>;
@@ -1,10 +1,13 @@
1
1
  export * from './address';
2
2
  export * from './airdrop';
3
+ export * from './calculate-compute-unit-price';
3
4
  export * from './conversion';
5
+ export * from './dedupe-signer';
6
+ export * from './get-state-tree-infos';
4
7
  export * from './parse-validity-proof';
5
8
  export * from './pipe';
6
9
  export * from './send-and-confirm';
7
10
  export * from './sleep';
11
+ export * from './state-tree-lookup-table';
8
12
  export * from './validation';
9
- export * from './calculate-compute-unit-price';
10
- export * from './get-light-state-tree-info';
13
+ export * from './get-state-tree-infos';
@@ -1,4 +1,4 @@
1
- import { CompressedProof } from '../state';
1
+ import { ValidityProof } from '../state';
2
2
  interface GnarkProofJson {
3
3
  ar: string[];
4
4
  bs: string[][];
@@ -14,7 +14,7 @@ export declare const placeholderValidityProof: () => {
14
14
  b: number[];
15
15
  c: number[];
16
16
  };
17
- export declare const checkValidityProofShape: (proof: CompressedProof) => void;
17
+ export declare const checkValidityProofShape: (proof: ValidityProof) => void;
18
18
  export declare function proofFromJsonStruct(json: GnarkProofJson): ProofABC;
19
- export declare function negateAndCompressProof(proof: ProofABC): CompressedProof;
19
+ export declare function negateAndCompressProof(proof: ProofABC): ValidityProof;
20
20
  export {};
@@ -0,0 +1,68 @@
1
+ import { PublicKey, Keypair, Connection } from '@solana/web3.js';
2
+ /**
3
+ * Create two lookup tables storing all public state tree and queue addresses
4
+ * returns lookup table addresses and txId
5
+ *
6
+ * @internal
7
+ * @param connection Connection to the Solana network
8
+ * @param payer Keypair of the payer
9
+ * @param authority Keypair of the authority
10
+ * @param recentSlot Slot of the recent block
11
+ */
12
+ export declare function createStateTreeLookupTable({ connection, payer, authority, recentSlot, }: {
13
+ connection: Connection;
14
+ payer: Keypair;
15
+ authority: Keypair;
16
+ recentSlot: number;
17
+ }): Promise<{
18
+ address: PublicKey;
19
+ txId: string;
20
+ }>;
21
+ /**
22
+ * Extend state tree lookup table with new state tree and queue addresses
23
+ *
24
+ * @internal
25
+ * @param connection Connection to the Solana network
26
+ * @param tableAddress Address of the lookup table to extend
27
+ * @param newStateTreeAddresses Addresses of the new state trees to add
28
+ * @param newQueueAddresses Addresses of the new queues to add
29
+ * @param newCpiContextAddresses Addresses of the new cpi contexts to add
30
+ * @param payer Keypair of the payer
31
+ * @param authority Keypair of the authority
32
+ */
33
+ export declare function extendStateTreeLookupTable({ connection, tableAddress, newStateTreeAddresses, newQueueAddresses, newCpiContextAddresses, payer, authority, }: {
34
+ connection: Connection;
35
+ tableAddress: PublicKey;
36
+ newStateTreeAddresses: PublicKey[];
37
+ newQueueAddresses: PublicKey[];
38
+ newCpiContextAddresses: PublicKey[];
39
+ payer: Keypair;
40
+ authority: Keypair;
41
+ }): Promise<{
42
+ tableAddress: PublicKey;
43
+ txId: string;
44
+ }>;
45
+ /**
46
+ * Adds state tree address to lookup table. Acts as nullifier lookup for rolled
47
+ * over state trees.
48
+ *
49
+ * @internal
50
+ * @param connection Connection to the Solana network
51
+ * @param stateTreeAddress Address of the state tree to nullify
52
+ * @param nullifyLookupTableAddress Address of the nullifier lookup table to
53
+ * store address in
54
+ * @param stateTreeLookupTableAddress lookup table storing all state tree
55
+ * addresses
56
+ * @param payer Keypair of the payer
57
+ * @param authority Keypair of the authority
58
+ */
59
+ export declare function nullifyLookupTable({ connection, fullStateTreeAddress, nullifyLookupTableAddress, stateTreeLookupTableAddress, payer, authority, }: {
60
+ connection: Connection;
61
+ fullStateTreeAddress: PublicKey;
62
+ nullifyLookupTableAddress: PublicKey;
63
+ stateTreeLookupTableAddress: PublicKey;
64
+ payer: Keypair;
65
+ authority: Keypair;
66
+ }): Promise<{
67
+ txId: string;
68
+ }>;