@lightprotocol/stateless.js 0.22.0 → 0.22.1-alpha.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 +10 -10
- package/dist/cjs/browser/constants.d.ts +24 -7
- package/dist/cjs/browser/index.cjs +1 -1
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/browser/rpc-interface.d.ts +275 -275
- package/dist/cjs/browser/rpc.d.ts +5 -1
- package/dist/cjs/browser/test-helpers/test-rpc/test-rpc.d.ts +4 -0
- package/dist/cjs/browser/utils/address.d.ts +7 -6
- package/dist/cjs/browser/utils/conversion.d.ts +1 -0
- package/dist/cjs/browser/utils/index.d.ts +1 -0
- package/dist/cjs/browser/utils/instruction.d.ts +35 -0
- package/dist/cjs/node/constants.d.ts +24 -7
- package/dist/cjs/node/index.cjs +1 -1
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/cjs/node/rpc-interface.d.ts +275 -275
- package/dist/cjs/node/rpc.d.ts +5 -1
- package/dist/cjs/node/test-helpers/test-rpc/test-rpc.d.ts +4 -0
- package/dist/cjs/node/utils/address.d.ts +7 -6
- package/dist/cjs/node/utils/conversion.d.ts +1 -0
- package/dist/cjs/node/utils/index.d.ts +1 -0
- package/dist/cjs/node/utils/instruction.d.ts +35 -0
- package/dist/es/browser/actions/compress.d.ts +18 -0
- package/dist/es/browser/actions/create-account.d.ts +38 -0
- package/dist/es/browser/actions/decompress.d.ts +15 -0
- package/dist/es/browser/actions/index.d.ts +5 -0
- package/dist/es/browser/actions/transfer.d.ts +16 -0
- package/dist/es/browser/constants.d.ts +157 -0
- package/dist/es/browser/errors.d.ts +74 -0
- package/dist/es/browser/index.d.ts +9 -0
- package/dist/es/browser/index.js +2 -0
- package/dist/es/browser/index.js.map +1 -0
- package/dist/es/browser/programs/index.d.ts +1 -0
- package/dist/es/browser/programs/system/idl.d.ts +997 -0
- package/dist/es/browser/programs/system/index.d.ts +5 -0
- package/dist/es/browser/programs/system/layout.d.ts +77 -0
- package/dist/es/browser/programs/system/pack.d.ts +74 -0
- package/dist/es/browser/programs/system/program.d.ts +175 -0
- package/dist/es/browser/programs/system/select-compressed-accounts.d.ts +10 -0
- package/dist/es/browser/rpc-interface.d.ts +2779 -0
- package/dist/es/browser/rpc.d.ts +284 -0
- package/dist/es/browser/state/BN254.d.ts +13 -0
- package/dist/es/browser/state/bn.d.ts +3 -0
- package/dist/es/browser/state/compressed-account.d.ts +205 -0
- package/dist/es/browser/state/index.d.ts +4 -0
- package/dist/es/browser/state/types.d.ts +449 -0
- package/dist/es/browser/test-helpers/index.d.ts +3 -0
- package/dist/es/browser/test-helpers/merkle-tree/index.d.ts +2 -0
- package/dist/es/browser/test-helpers/merkle-tree/indexed-array.d.ts +85 -0
- package/dist/es/browser/test-helpers/merkle-tree/merkle-tree.d.ts +92 -0
- package/dist/es/browser/test-helpers/test-rpc/get-compressed-accounts.d.ts +7 -0
- package/dist/es/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +40 -0
- package/dist/es/browser/test-helpers/test-rpc/get-parsed-events.d.ts +15 -0
- package/dist/es/browser/test-helpers/test-rpc/index.d.ts +3 -0
- package/dist/es/browser/test-helpers/test-rpc/test-rpc.d.ts +239 -0
- package/dist/es/browser/test-helpers/test-utils.d.ts +31 -0
- package/dist/es/browser/utils/address.d.ts +64 -0
- package/dist/es/browser/utils/airdrop.d.ts +7 -0
- package/dist/es/browser/utils/calculate-compute-unit-price.d.ts +7 -0
- package/dist/es/browser/utils/conversion.d.ts +36 -0
- package/dist/es/browser/utils/dedupe-signer.d.ts +3 -0
- package/dist/es/browser/utils/get-state-tree-infos.d.ts +48 -0
- package/dist/es/browser/utils/index.d.ts +13 -0
- package/dist/es/browser/utils/instruction.d.ts +35 -0
- package/dist/es/browser/utils/parse-validity-proof.d.ts +20 -0
- package/dist/es/browser/utils/pipe.d.ts +2 -0
- package/dist/es/browser/utils/send-and-confirm.d.ts +52 -0
- package/dist/es/browser/utils/sleep.d.ts +1 -0
- package/dist/es/browser/utils/state-tree-lookup-table.d.ts +68 -0
- package/dist/es/browser/utils/validation.d.ts +8 -0
- package/dist/types/index.d.ts +78 -16
- package/package.json +16 -8
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import BN from 'bn.js';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import { NewAddressParamsPacked } from '../utils';
|
|
5
|
+
import { PackedCompressedAccountWithMerkleContext } from './compressed-account';
|
|
6
|
+
export declare enum TreeType {
|
|
7
|
+
/**
|
|
8
|
+
* v1 state merkle tree
|
|
9
|
+
*/
|
|
10
|
+
StateV1 = 1,
|
|
11
|
+
/**
|
|
12
|
+
* v1 address merkle tree
|
|
13
|
+
*/
|
|
14
|
+
AddressV1 = 2,
|
|
15
|
+
/**
|
|
16
|
+
* v2 state merkle tree
|
|
17
|
+
*/
|
|
18
|
+
StateV2 = 3,
|
|
19
|
+
/**
|
|
20
|
+
* v2 address merkle tree
|
|
21
|
+
*/
|
|
22
|
+
AddressV2 = 4
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use {@link TreeInfo} instead.
|
|
26
|
+
*
|
|
27
|
+
* A bundle of active trees for a given tree type.
|
|
28
|
+
*/
|
|
29
|
+
export type ActiveTreeBundle = {
|
|
30
|
+
/**
|
|
31
|
+
* Tree.
|
|
32
|
+
*/
|
|
33
|
+
tree: PublicKey;
|
|
34
|
+
/**
|
|
35
|
+
* Queue.
|
|
36
|
+
*/
|
|
37
|
+
queue: PublicKey | null;
|
|
38
|
+
/**
|
|
39
|
+
* CPI context.
|
|
40
|
+
*/
|
|
41
|
+
cpiContext: PublicKey | null;
|
|
42
|
+
/**
|
|
43
|
+
* Tree type.
|
|
44
|
+
*/
|
|
45
|
+
treeType: TreeType;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use {@link TreeInfo} instead.
|
|
49
|
+
*
|
|
50
|
+
* State tree info, versioned via {@link TreeType}. The protocol
|
|
51
|
+
* stores compressed accounts in state trees.
|
|
52
|
+
*/
|
|
53
|
+
export type StateTreeInfo = TreeInfo;
|
|
54
|
+
/**
|
|
55
|
+
* Tree info, versioned via {@link TreeType}. The protocol
|
|
56
|
+
* stores compressed accounts in state trees, and PDAs in address trees.
|
|
57
|
+
*
|
|
58
|
+
* Onchain Accounts are subject to Solana's write-lock limits.
|
|
59
|
+
*
|
|
60
|
+
* To load balance transactions, use {@link selectStateTreeInfo} to
|
|
61
|
+
* randomly select a tree from a range of active trees.
|
|
62
|
+
*
|
|
63
|
+
* Example:
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const infos = await rpc.getStateTreeInfos();
|
|
66
|
+
* const info = selectStateTreeInfo(infos);
|
|
67
|
+
* const ix = await CompressedTokenProgram.compress({
|
|
68
|
+
* // ...
|
|
69
|
+
* outputStateTreeInfo: info
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export type TreeInfo = {
|
|
74
|
+
/**
|
|
75
|
+
* Pubkey of the tree account.
|
|
76
|
+
*/
|
|
77
|
+
tree: PublicKey;
|
|
78
|
+
/**
|
|
79
|
+
* Pubkey of the queue account associated with the tree.
|
|
80
|
+
*/
|
|
81
|
+
queue: PublicKey;
|
|
82
|
+
/**
|
|
83
|
+
* The type of tree. One of {@link TreeType}.
|
|
84
|
+
*/
|
|
85
|
+
treeType: TreeType;
|
|
86
|
+
/**
|
|
87
|
+
* Optional compressed cpi context account.
|
|
88
|
+
*/
|
|
89
|
+
cpiContext?: PublicKey;
|
|
90
|
+
/**
|
|
91
|
+
* Next tree info. Is `some` if the next tree should be used for the next
|
|
92
|
+
* state transition.
|
|
93
|
+
*/
|
|
94
|
+
nextTreeInfo: TreeInfo | null;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use {@link TreeInfo} instead.
|
|
98
|
+
*
|
|
99
|
+
* Address tree info, versioned via {@link TreeType}. The protocol
|
|
100
|
+
* stores PDAs in address trees.
|
|
101
|
+
*/
|
|
102
|
+
export type AddressTreeInfo = Omit<StateTreeInfo, 'cpiContext' | 'nextTreeInfo'> & {
|
|
103
|
+
/**
|
|
104
|
+
* Next tree info.
|
|
105
|
+
*/
|
|
106
|
+
nextTreeInfo: AddressTreeInfo | null;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Packed merkle context.
|
|
110
|
+
*/
|
|
111
|
+
export interface PackedMerkleContextLegacy {
|
|
112
|
+
/**
|
|
113
|
+
* Merkle tree pubkey index.
|
|
114
|
+
*/
|
|
115
|
+
merkleTreePubkeyIndex: number;
|
|
116
|
+
/**
|
|
117
|
+
* Queue pubkey index in remaining accounts.
|
|
118
|
+
*/
|
|
119
|
+
queuePubkeyIndex: number;
|
|
120
|
+
/**
|
|
121
|
+
* Leaf index.
|
|
122
|
+
*/
|
|
123
|
+
leafIndex: number;
|
|
124
|
+
/**
|
|
125
|
+
* Whether to prove by index or validity proof.
|
|
126
|
+
*/
|
|
127
|
+
proveByIndex: boolean;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @deprecated Use {@link CompressedAccount} instead.
|
|
131
|
+
*
|
|
132
|
+
* Describe the generic compressed account details applicable to every
|
|
133
|
+
* compressed account.
|
|
134
|
+
*
|
|
135
|
+
* */
|
|
136
|
+
export interface CompressedAccountLegacy {
|
|
137
|
+
/**
|
|
138
|
+
* Public key of program or user owning the account.
|
|
139
|
+
*/
|
|
140
|
+
owner: PublicKey;
|
|
141
|
+
/**
|
|
142
|
+
* Lamports attached to the account.
|
|
143
|
+
*/
|
|
144
|
+
lamports: BN;
|
|
145
|
+
/**
|
|
146
|
+
* Optional unique account ID that is persistent across transactions.
|
|
147
|
+
*/
|
|
148
|
+
address: number[] | null;
|
|
149
|
+
/**
|
|
150
|
+
* Optional data attached to the account.
|
|
151
|
+
*/
|
|
152
|
+
data: CompressedAccountData | null;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @deprecated Use {@link CompressedAccountMeta} instead.
|
|
156
|
+
*
|
|
157
|
+
* Describe the generic compressed account details applicable to every
|
|
158
|
+
* compressed account.
|
|
159
|
+
*/
|
|
160
|
+
export interface OutputCompressedAccountWithPackedContext {
|
|
161
|
+
compressedAccount: CompressedAccountLegacy;
|
|
162
|
+
merkleTreeIndex: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Compressed account-related proof metadata.
|
|
166
|
+
*/
|
|
167
|
+
export type AccountProofInput = {
|
|
168
|
+
hash: BN;
|
|
169
|
+
treeInfo: TreeInfo;
|
|
170
|
+
leafIndex: number;
|
|
171
|
+
rootIndex: number;
|
|
172
|
+
proveByIndex: boolean;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* New address proof metadata.
|
|
176
|
+
*/
|
|
177
|
+
export type NewAddressProofInput = {
|
|
178
|
+
treeInfo: TreeInfo;
|
|
179
|
+
address: number[];
|
|
180
|
+
rootIndex: number;
|
|
181
|
+
root: BN;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Describes compressed account data.
|
|
185
|
+
*/
|
|
186
|
+
export interface CompressedAccountData {
|
|
187
|
+
/**
|
|
188
|
+
* 8 bytes.
|
|
189
|
+
*/
|
|
190
|
+
discriminator: number[];
|
|
191
|
+
/**
|
|
192
|
+
* Data.
|
|
193
|
+
*/
|
|
194
|
+
data: Buffer;
|
|
195
|
+
/**
|
|
196
|
+
* 32 bytes.
|
|
197
|
+
*/
|
|
198
|
+
dataHash: number[];
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Merkle tree sequence number.
|
|
202
|
+
*/
|
|
203
|
+
export interface MerkleTreeSequenceNumber {
|
|
204
|
+
/**
|
|
205
|
+
* Public key.
|
|
206
|
+
*/
|
|
207
|
+
pubkey: PublicKey;
|
|
208
|
+
/**
|
|
209
|
+
* Sequence number.
|
|
210
|
+
*/
|
|
211
|
+
seq: BN;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Public transaction event.
|
|
215
|
+
*/
|
|
216
|
+
export interface PublicTransactionEvent {
|
|
217
|
+
/**
|
|
218
|
+
* Input compressed account hashes.
|
|
219
|
+
*/
|
|
220
|
+
inputCompressedAccountHashes: number[][];
|
|
221
|
+
/**
|
|
222
|
+
* Output compressed account hashes.
|
|
223
|
+
*/
|
|
224
|
+
outputCompressedAccountHashes: number[][];
|
|
225
|
+
/**
|
|
226
|
+
* Output compressed accounts.
|
|
227
|
+
*/
|
|
228
|
+
outputCompressedAccounts: OutputCompressedAccountWithPackedContext[];
|
|
229
|
+
/**
|
|
230
|
+
* Output leaf indices.
|
|
231
|
+
*/
|
|
232
|
+
outputLeafIndices: number[];
|
|
233
|
+
/**
|
|
234
|
+
* Sequence numbers.
|
|
235
|
+
*/
|
|
236
|
+
sequenceNumbers: MerkleTreeSequenceNumber[];
|
|
237
|
+
/**
|
|
238
|
+
* Relay fee. Default is null.
|
|
239
|
+
*/
|
|
240
|
+
relayFee: BN | null;
|
|
241
|
+
/**
|
|
242
|
+
* Whether it's a compress or decompress instruction.
|
|
243
|
+
*/
|
|
244
|
+
isCompress: boolean;
|
|
245
|
+
/**
|
|
246
|
+
* If some, it's either a compress or decompress instruction.
|
|
247
|
+
*/
|
|
248
|
+
compressOrDecompressLamports: BN | null;
|
|
249
|
+
/**
|
|
250
|
+
* Public keys.
|
|
251
|
+
*/
|
|
252
|
+
pubkeyArray: PublicKey[];
|
|
253
|
+
/**
|
|
254
|
+
* Message. Default is null.
|
|
255
|
+
*/
|
|
256
|
+
message: Uint8Array | null;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Instruction data for invoke.
|
|
260
|
+
*/
|
|
261
|
+
export interface InstructionDataInvoke {
|
|
262
|
+
/**
|
|
263
|
+
* Validity proof.
|
|
264
|
+
*/
|
|
265
|
+
proof: ValidityProof | null;
|
|
266
|
+
/**
|
|
267
|
+
* Input compressed accounts with merkle context.
|
|
268
|
+
*/
|
|
269
|
+
inputCompressedAccountsWithMerkleContext: PackedCompressedAccountWithMerkleContext[];
|
|
270
|
+
/**
|
|
271
|
+
* Output compressed accounts.
|
|
272
|
+
*/
|
|
273
|
+
outputCompressedAccounts: OutputCompressedAccountWithPackedContext[];
|
|
274
|
+
/**
|
|
275
|
+
* Relay fee. Default is null.
|
|
276
|
+
*/
|
|
277
|
+
relayFee: BN | null;
|
|
278
|
+
/**
|
|
279
|
+
* Params for creating new addresses.
|
|
280
|
+
*/
|
|
281
|
+
newAddressParams: NewAddressParamsPacked[];
|
|
282
|
+
/**
|
|
283
|
+
* If some, it's either a compress or decompress instruction.
|
|
284
|
+
*/
|
|
285
|
+
compressOrDecompressLamports: BN | null;
|
|
286
|
+
/**
|
|
287
|
+
* Whether it's a compress or decompress instruction.
|
|
288
|
+
*/
|
|
289
|
+
isCompress: boolean;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Instruction data for invoking a CPI.
|
|
293
|
+
*/
|
|
294
|
+
export interface InstructionDataInvokeCpi {
|
|
295
|
+
/**
|
|
296
|
+
* Validity proof.
|
|
297
|
+
*/
|
|
298
|
+
proof: ValidityProof | null;
|
|
299
|
+
/**
|
|
300
|
+
* Input compressed accounts with merkle context.
|
|
301
|
+
*/
|
|
302
|
+
inputCompressedAccountsWithMerkleContext: PackedCompressedAccountWithMerkleContext[];
|
|
303
|
+
/**
|
|
304
|
+
* Output compressed accounts.
|
|
305
|
+
*/
|
|
306
|
+
outputCompressedAccounts: OutputCompressedAccountWithPackedContext[];
|
|
307
|
+
/**
|
|
308
|
+
* Relay fee. Default is null.
|
|
309
|
+
*/
|
|
310
|
+
relayFee: BN | null;
|
|
311
|
+
/**
|
|
312
|
+
* Params for creating new addresses.
|
|
313
|
+
*/
|
|
314
|
+
newAddressParams: NewAddressParamsPacked[];
|
|
315
|
+
/**
|
|
316
|
+
* If some, it's either a compress or decompress instruction.
|
|
317
|
+
*/
|
|
318
|
+
compressOrDecompressLamports: BN | null;
|
|
319
|
+
/**
|
|
320
|
+
* If `compressOrDecompressLamports` is some, whether it's a compress or
|
|
321
|
+
* decompress instruction.
|
|
322
|
+
*/
|
|
323
|
+
isCompress: boolean;
|
|
324
|
+
/**
|
|
325
|
+
* Optional compressed CPI context.
|
|
326
|
+
*/
|
|
327
|
+
compressedCpiContext: CompressedCpiContext | null;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Compressed CPI context.
|
|
331
|
+
*
|
|
332
|
+
* Use if you want to use a single {@link ValidityProof} to update two
|
|
333
|
+
* compressed accounts owned by separate programs.
|
|
334
|
+
*/
|
|
335
|
+
export interface CompressedCpiContext {
|
|
336
|
+
/**
|
|
337
|
+
* Is set by the program that is invoking the CPI to signal that it should
|
|
338
|
+
* set the cpi context.
|
|
339
|
+
*/
|
|
340
|
+
setContext: boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Is set to wipe the cpi context since someone could have set it before
|
|
343
|
+
* with unrelated data.
|
|
344
|
+
*/
|
|
345
|
+
firstSetContext: boolean;
|
|
346
|
+
/**
|
|
347
|
+
* Index of cpi context account in remaining accounts.
|
|
348
|
+
*/
|
|
349
|
+
cpiContextAccountIndex: number;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* @deprecated Use {@link ValidityProof} instead.
|
|
353
|
+
*/
|
|
354
|
+
export interface CompressedProof {
|
|
355
|
+
/**
|
|
356
|
+
* 32 bytes.
|
|
357
|
+
*/
|
|
358
|
+
a: number[];
|
|
359
|
+
/**
|
|
360
|
+
* 64 bytes.
|
|
361
|
+
*/
|
|
362
|
+
b: number[];
|
|
363
|
+
/**
|
|
364
|
+
* 32 bytes.
|
|
365
|
+
*/
|
|
366
|
+
c: number[];
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Validity proof.
|
|
370
|
+
*
|
|
371
|
+
* You can request proofs via `rpc.getValidityProof` or
|
|
372
|
+
* `rpc.getValidityProofV0`.
|
|
373
|
+
*
|
|
374
|
+
* One proof can prove the existence of N compressed accounts or the uniqueness
|
|
375
|
+
* of N PDAs.
|
|
376
|
+
*/
|
|
377
|
+
export interface ValidityProof {
|
|
378
|
+
/**
|
|
379
|
+
* 32 bytes.
|
|
380
|
+
*/
|
|
381
|
+
a: number[];
|
|
382
|
+
/**
|
|
383
|
+
* 64 bytes.
|
|
384
|
+
*/
|
|
385
|
+
b: number[];
|
|
386
|
+
/**
|
|
387
|
+
* 32 bytes.
|
|
388
|
+
*/
|
|
389
|
+
c: number[];
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Packed token data for input compressed accounts.
|
|
393
|
+
*/
|
|
394
|
+
export interface InputTokenDataWithContext {
|
|
395
|
+
/**
|
|
396
|
+
* Amount of tokens.
|
|
397
|
+
*/
|
|
398
|
+
amount: BN;
|
|
399
|
+
/**
|
|
400
|
+
* Delegate index.
|
|
401
|
+
*/
|
|
402
|
+
delegateIndex: number | null;
|
|
403
|
+
/**
|
|
404
|
+
* Merkle context.
|
|
405
|
+
*/
|
|
406
|
+
merkleContext: PackedMerkleContextLegacy;
|
|
407
|
+
/**
|
|
408
|
+
* Root index.
|
|
409
|
+
*/
|
|
410
|
+
rootIndex: number;
|
|
411
|
+
/**
|
|
412
|
+
* Lamports.
|
|
413
|
+
*/
|
|
414
|
+
lamports: BN | null;
|
|
415
|
+
/**
|
|
416
|
+
* Tlv.
|
|
417
|
+
*/
|
|
418
|
+
tlv: Buffer | null;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Token data.
|
|
422
|
+
*/
|
|
423
|
+
export type TokenData = {
|
|
424
|
+
/**
|
|
425
|
+
* The mint associated with this account.
|
|
426
|
+
*/
|
|
427
|
+
mint: PublicKey;
|
|
428
|
+
/**
|
|
429
|
+
* The owner of this account.
|
|
430
|
+
*/
|
|
431
|
+
owner: PublicKey;
|
|
432
|
+
/**
|
|
433
|
+
* The amount of tokens this account holds.
|
|
434
|
+
*/
|
|
435
|
+
amount: BN;
|
|
436
|
+
/**
|
|
437
|
+
* If `delegate` is `Some` then `delegated_amount` represents the amount
|
|
438
|
+
* authorized by the delegate.
|
|
439
|
+
*/
|
|
440
|
+
delegate: PublicKey | null;
|
|
441
|
+
/**
|
|
442
|
+
* The account's state.
|
|
443
|
+
*/
|
|
444
|
+
state: number;
|
|
445
|
+
/**
|
|
446
|
+
* Token extension tlv.
|
|
447
|
+
*/
|
|
448
|
+
tlv: Buffer | null;
|
|
449
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LightWasm } from '../test-rpc/test-rpc';
|
|
2
|
+
import BN from 'bn.js';
|
|
3
|
+
export declare class IndexedElement {
|
|
4
|
+
index: number;
|
|
5
|
+
value: BN;
|
|
6
|
+
nextIndex: number;
|
|
7
|
+
constructor(index: number, value: BN, nextIndex: number);
|
|
8
|
+
equals(other: IndexedElement): boolean;
|
|
9
|
+
compareTo(other: IndexedElement): number;
|
|
10
|
+
hash(lightWasm: LightWasm, nextValue: BN): Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
export declare class IndexedElementBundle {
|
|
13
|
+
newLowElement: IndexedElement;
|
|
14
|
+
newElement: IndexedElement;
|
|
15
|
+
newElementNextValue: BN;
|
|
16
|
+
constructor(newLowElement: IndexedElement, newElement: IndexedElement, newElementNextValue: BN);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* This indexed array implementation mirrors the rust implementation of the
|
|
20
|
+
* indexed merkle tree. It stores the elements of the indexed merkle tree.
|
|
21
|
+
*/
|
|
22
|
+
export declare class IndexedArray {
|
|
23
|
+
elements: Array<IndexedElement>;
|
|
24
|
+
currentNodeIndex: number;
|
|
25
|
+
highestElementIndex: number;
|
|
26
|
+
constructor(elements: Array<IndexedElement>, currentNodeIndex: number, highestElementIndex: number);
|
|
27
|
+
static default(): IndexedArray;
|
|
28
|
+
get(index: number): IndexedElement | undefined;
|
|
29
|
+
length(): number;
|
|
30
|
+
isEmpty(): boolean;
|
|
31
|
+
findElement(value: BN): IndexedElement | undefined;
|
|
32
|
+
init(): IndexedElementBundle;
|
|
33
|
+
/**
|
|
34
|
+
* Finds the index of the low element for the given `value` which should not be part of the array.
|
|
35
|
+
* Low element is the greatest element which still has a lower value than the provided one.
|
|
36
|
+
* Low elements are used in non-membership proofs.
|
|
37
|
+
*/
|
|
38
|
+
findLowElementIndex(value: BN): number | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the low element for the given value and the next value for that low element.
|
|
41
|
+
* Low element is the greatest element which still has lower value than the provided one.
|
|
42
|
+
* Low elements are used in non-membership proofs.
|
|
43
|
+
*/
|
|
44
|
+
findLowElement(value: BN): [IndexedElement | undefined, BN | undefined];
|
|
45
|
+
/**
|
|
46
|
+
* Returns the hash of the given element. That hash consists of:
|
|
47
|
+
* - The value of the given element.
|
|
48
|
+
* - The `nextIndex` of the given element.
|
|
49
|
+
* - The value of the element pointed by `nextIndex`.
|
|
50
|
+
*/
|
|
51
|
+
hashElement(lightWasm: LightWasm, index: number): Uint8Array | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Appends a new element with the given value to the indexed array.
|
|
54
|
+
* It finds the low element index and uses it to append the new element correctly.
|
|
55
|
+
* @param value The value of the new element to append.
|
|
56
|
+
* @returns The new element and its low element after insertion.
|
|
57
|
+
*/
|
|
58
|
+
append(value: BN): IndexedElementBundle;
|
|
59
|
+
/**
|
|
60
|
+
* Appends a new element with the given value to the indexed array using a specific low element index.
|
|
61
|
+
* This method ensures the new element is placed correctly relative to the low element.
|
|
62
|
+
* @param lowElementIndex The index of the low element.
|
|
63
|
+
* @param value The value of the new element to append.
|
|
64
|
+
* @returns The new element and its updated low element.
|
|
65
|
+
*/
|
|
66
|
+
appendWithLowElementIndex(lowElementIndex: number, value: BN): IndexedElementBundle;
|
|
67
|
+
/**
|
|
68
|
+
* Finds the lowest element in the array.
|
|
69
|
+
* @returns The lowest element or undefined if the array is empty.
|
|
70
|
+
*/
|
|
71
|
+
lowest(): IndexedElement | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new element with the specified value and updates the low element index accordingly.
|
|
74
|
+
* @param lowElementIndex The index of the low element.
|
|
75
|
+
* @param value The value for the new element.
|
|
76
|
+
* @returns A bundle containing the new element, the updated low element, and the value of the next element.
|
|
77
|
+
*/
|
|
78
|
+
newElementWithLowElementIndex(lowElementIndex: number, value: BN): IndexedElementBundle;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new element with the specified value by first finding the appropriate low element index.
|
|
81
|
+
* @param value The value for the new element.
|
|
82
|
+
* @returns A bundle containing the new element, the updated low element, and the value of the next element.
|
|
83
|
+
*/
|
|
84
|
+
newElement(value: BN): IndexedElementBundle;
|
|
85
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { LightWasm } from '../test-rpc/test-rpc';
|
|
2
|
+
export declare const DEFAULT_ZERO = "0";
|
|
3
|
+
/**
|
|
4
|
+
* @callback hashFunction
|
|
5
|
+
* @param left Left leaf
|
|
6
|
+
* @param right Right leaf
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Merkle tree
|
|
10
|
+
*/
|
|
11
|
+
export declare class MerkleTree {
|
|
12
|
+
/**
|
|
13
|
+
* Constructor
|
|
14
|
+
* @param {number} levels Number of levels in the tree
|
|
15
|
+
* @param {Array} [elements] Initial elements
|
|
16
|
+
* @param {Object} options
|
|
17
|
+
* @param {hashFunction} [options.hashFunction] Function used to hash 2 leaves
|
|
18
|
+
* @param [options.zeroElement] Value for non-existent leaves
|
|
19
|
+
*/
|
|
20
|
+
levels: number;
|
|
21
|
+
capacity: number;
|
|
22
|
+
zeroElement: string;
|
|
23
|
+
_zeros: string[];
|
|
24
|
+
_layers: string[][];
|
|
25
|
+
_lightWasm: LightWasm;
|
|
26
|
+
constructor(levels: number, lightWasm: LightWasm, elements?: string[], { zeroElement }?: {
|
|
27
|
+
zeroElement?: string | undefined;
|
|
28
|
+
});
|
|
29
|
+
_rebuild(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Get tree root
|
|
32
|
+
* @returns {*}
|
|
33
|
+
*/
|
|
34
|
+
root(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Insert new element into the tree
|
|
37
|
+
* @param element Element to insert
|
|
38
|
+
*/
|
|
39
|
+
insert(element: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Insert multiple elements into the tree. Tree will be fully rebuilt during this operation.
|
|
42
|
+
* @param {Array} elements Elements to insert
|
|
43
|
+
*/
|
|
44
|
+
bulkInsert(elements: string[]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Change an element in the tree
|
|
47
|
+
* @param {number} index Index of element to change
|
|
48
|
+
* @param element Updated element value
|
|
49
|
+
*/
|
|
50
|
+
update(index: number, element: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Get merkle path to a leaf
|
|
53
|
+
* @param {number} index Leaf index to generate path for
|
|
54
|
+
* @returns {{pathElements: number[], pathIndex: number[]}} An object containing adjacent elements and left-right index
|
|
55
|
+
*/
|
|
56
|
+
path(index: number): {
|
|
57
|
+
pathElements: string[];
|
|
58
|
+
pathIndices: number[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Find an element in the tree
|
|
62
|
+
* @param element An element to find
|
|
63
|
+
* @param comparator A function that checks leaf value equality
|
|
64
|
+
* @returns {number} Index if element is found, otherwise -1
|
|
65
|
+
*/
|
|
66
|
+
indexOf(element: string, comparator?: ((element: string, el: string) => boolean) | null): number;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a copy of non-zero tree elements
|
|
69
|
+
* @returns {Object[]}
|
|
70
|
+
*/
|
|
71
|
+
elements(): string[];
|
|
72
|
+
/**
|
|
73
|
+
* Serialize entire tree state including intermediate layers into a plain object
|
|
74
|
+
* Deserializing it back will not require to recompute any hashes
|
|
75
|
+
* Elements are not converted to a plain type, this is responsibility of the caller
|
|
76
|
+
*/
|
|
77
|
+
serialize(): {
|
|
78
|
+
levels: number;
|
|
79
|
+
_zeros: string[];
|
|
80
|
+
_layers: string[][];
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Deserialize data into a MerkleTree instance
|
|
84
|
+
* Make sure to provide the same hashFunction as was used in the source tree,
|
|
85
|
+
* otherwise the tree state will be invalid
|
|
86
|
+
*
|
|
87
|
+
* @param data
|
|
88
|
+
* @param hashFunction
|
|
89
|
+
* @returns {MerkleTree}
|
|
90
|
+
*/
|
|
91
|
+
static deserialize(data: any, hashFunction: (left: string, right: string) => string): any;
|
|
92
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import BN from 'bn.js';
|
|
3
|
+
import { Rpc } from '../../rpc';
|
|
4
|
+
import { CompressedAccountWithMerkleContext } from '../../state';
|
|
5
|
+
export declare function getCompressedAccountsByOwnerTest(rpc: Rpc, owner: PublicKey): Promise<CompressedAccountWithMerkleContext[]>;
|
|
6
|
+
export declare function getCompressedAccountByHashTest(rpc: Rpc, hash: BN): Promise<CompressedAccountWithMerkleContext | undefined>;
|
|
7
|
+
export declare function getMultipleCompressedAccountsByHashTest(rpc: Rpc, hashes: BN[]): Promise<CompressedAccountWithMerkleContext[]>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import BN from 'bn.js';
|
|
3
|
+
import { Rpc } from '../../rpc';
|
|
4
|
+
import { ParsedTokenAccount, WithCursor } from '../../rpc-interface';
|
|
5
|
+
import { PublicTransactionEvent, CompressedAccountLegacy } from '../../state';
|
|
6
|
+
import { Layout } from '@coral-xyz/borsh';
|
|
7
|
+
type TokenData = {
|
|
8
|
+
mint: PublicKey;
|
|
9
|
+
owner: PublicKey;
|
|
10
|
+
amount: BN;
|
|
11
|
+
delegate: PublicKey | null;
|
|
12
|
+
state: number;
|
|
13
|
+
tlv: Buffer | null;
|
|
14
|
+
};
|
|
15
|
+
export declare const TokenDataLayout: Layout<TokenData>;
|
|
16
|
+
export type EventWithParsedTokenTlvData = {
|
|
17
|
+
inputCompressedAccountHashes: number[][];
|
|
18
|
+
outputCompressedAccounts: ParsedTokenAccount[];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Manually parse the compressed token layout for a given compressed account.
|
|
22
|
+
* @param compressedAccount - The compressed account
|
|
23
|
+
* @returns The parsed token data
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseTokenLayoutWithIdl(compressedAccount: CompressedAccountLegacy, programId?: PublicKey): TokenData | null;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves all compressed token accounts for a given mint and owner.
|
|
28
|
+
*
|
|
29
|
+
* Note: This function is intended for testing purposes only. For production, use rpc.getCompressedTokenAccounts.
|
|
30
|
+
*
|
|
31
|
+
* @param events Public transaction events
|
|
32
|
+
* @param owner PublicKey of the token owner
|
|
33
|
+
* @param mint PublicKey of the token mint
|
|
34
|
+
*/
|
|
35
|
+
export declare function getCompressedTokenAccounts(events: PublicTransactionEvent[], rpc: Rpc): Promise<ParsedTokenAccount[]>;
|
|
36
|
+
/** @internal */
|
|
37
|
+
export declare function getCompressedTokenAccountsByOwnerTest(rpc: Rpc, owner: PublicKey, mint: PublicKey): Promise<WithCursor<ParsedTokenAccount[]>>;
|
|
38
|
+
export declare function getCompressedTokenAccountsByDelegateTest(rpc: Rpc, delegate: PublicKey, mint: PublicKey): Promise<WithCursor<ParsedTokenAccount[]>>;
|
|
39
|
+
export declare function getCompressedTokenAccountByHashTest(rpc: Rpc, hash: BN): Promise<ParsedTokenAccount>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ParsedTransactionWithMeta, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { Rpc } from '../../rpc';
|
|
3
|
+
import { PublicTransactionEvent } from '../../state';
|
|
4
|
+
import { Buffer } from 'buffer';
|
|
5
|
+
type Deserializer<T> = (data: Buffer, tx: ParsedTransactionWithMeta) => T;
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
* Returns newest first.
|
|
9
|
+
*
|
|
10
|
+
* */
|
|
11
|
+
export declare function getParsedEvents(rpc: Rpc): Promise<PublicTransactionEvent[]>;
|
|
12
|
+
export declare const parseEvents: <T>(indexerEventsTransactions: (ParsedTransactionWithMeta | null)[], deserializeFn: Deserializer<T>) => NonNullable<T>[];
|
|
13
|
+
export declare const parsePublicTransactionEventWithIdl: (data: Buffer) => PublicTransactionEvent | null;
|
|
14
|
+
export declare function parseLightTransaction(dataVec: Uint8Array[], accountKeys: PublicKey[][]): PublicTransactionEvent | null | undefined;
|
|
15
|
+
export {};
|