@lightprotocol/compressed-token 0.17.0 → 0.17.2-alpha.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.
- package/dist/cjs/browser/index.cjs +1 -2827
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +1 -2827
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +1 -2802
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +34 -1841
- package/package.json +19 -17
package/dist/es/browser/index.js
CHANGED
|
@@ -1,2803 +1,2 @@
|
|
|
1
|
-
import { getIndexOrAdd, bn, padOutputStateMerkleTrees, useWallet, confirmConfig, defaultStaticAccountsStruct, toArray, LightSystemProgram, defaultTestStateTreeAccounts, sumUpLamports, validateSufficientBalance, validateSameOwner, dedupeSigner, buildAndSignTx, sendAndConfirmTx } from '@lightprotocol/stateless.js';
|
|
2
|
-
import { PublicKey, Keypair, Connection, SystemProgram, AddressLookupTableProgram, ComputeBudgetProgram } from '@solana/web3.js';
|
|
3
|
-
import { AnchorProvider, setProvider, Program, BN } from '@coral-xyz/anchor';
|
|
4
|
-
import { MINT_SIZE, createInitializeMint2Instruction, createMintToInstruction, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token';
|
|
5
|
-
|
|
6
|
-
const IDL = {
|
|
7
|
-
version: '1.2.0',
|
|
8
|
-
name: 'light_compressed_token',
|
|
9
|
-
instructions: [
|
|
10
|
-
{
|
|
11
|
-
name: 'createTokenPool',
|
|
12
|
-
docs: [
|
|
13
|
-
'This instruction creates a token pool for a given mint. Every spl mint',
|
|
14
|
-
'can have one token pool. When a token is compressed the tokens are',
|
|
15
|
-
'transferrred to the token pool, and their compressed equivalent is',
|
|
16
|
-
'minted into a Merkle tree.',
|
|
17
|
-
],
|
|
18
|
-
accounts: [
|
|
19
|
-
{
|
|
20
|
-
name: 'feePayer',
|
|
21
|
-
isMut: true,
|
|
22
|
-
isSigner: true,
|
|
23
|
-
docs: ['UNCHECKED: only pays fees.'],
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: 'tokenPoolPda',
|
|
27
|
-
isMut: true,
|
|
28
|
-
isSigner: false,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: 'systemProgram',
|
|
32
|
-
isMut: false,
|
|
33
|
-
isSigner: false,
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
name: 'mint',
|
|
37
|
-
isMut: true,
|
|
38
|
-
isSigner: false,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'tokenProgram',
|
|
42
|
-
isMut: false,
|
|
43
|
-
isSigner: false,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'cpiAuthorityPda',
|
|
47
|
-
isMut: false,
|
|
48
|
-
isSigner: false,
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
args: [],
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: 'mintTo',
|
|
55
|
-
docs: [
|
|
56
|
-
'Mints tokens from an spl token mint to a list of compressed accounts.',
|
|
57
|
-
'Minted tokens are transferred to a pool account owned by the compressed',
|
|
58
|
-
'token program. The instruction creates one compressed output account for',
|
|
59
|
-
'every amount and pubkey input pair. A constant amount of lamports can be',
|
|
60
|
-
'transferred to each output account to enable. A use case to add lamports',
|
|
61
|
-
'to a compressed token account is to prevent spam. This is the only way',
|
|
62
|
-
'to add lamports to a compressed token account.',
|
|
63
|
-
],
|
|
64
|
-
accounts: [
|
|
65
|
-
{
|
|
66
|
-
name: 'feePayer',
|
|
67
|
-
isMut: true,
|
|
68
|
-
isSigner: true,
|
|
69
|
-
docs: ['UNCHECKED: only pays fees.'],
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: 'authority',
|
|
73
|
-
isMut: false,
|
|
74
|
-
isSigner: true,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: 'cpiAuthorityPda',
|
|
78
|
-
isMut: false,
|
|
79
|
-
isSigner: false,
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: 'mint',
|
|
83
|
-
isMut: true,
|
|
84
|
-
isSigner: false,
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: 'tokenPoolPda',
|
|
88
|
-
isMut: true,
|
|
89
|
-
isSigner: false,
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'tokenProgram',
|
|
93
|
-
isMut: false,
|
|
94
|
-
isSigner: false,
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
name: 'lightSystemProgram',
|
|
98
|
-
isMut: false,
|
|
99
|
-
isSigner: false,
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: 'registeredProgramPda',
|
|
103
|
-
isMut: false,
|
|
104
|
-
isSigner: false,
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
name: 'noopProgram',
|
|
108
|
-
isMut: false,
|
|
109
|
-
isSigner: false,
|
|
110
|
-
docs: ['programs'],
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
name: 'accountCompressionAuthority',
|
|
114
|
-
isMut: false,
|
|
115
|
-
isSigner: false,
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: 'accountCompressionProgram',
|
|
119
|
-
isMut: false,
|
|
120
|
-
isSigner: false,
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
name: 'merkleTree',
|
|
124
|
-
isMut: true,
|
|
125
|
-
isSigner: false,
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: 'selfProgram',
|
|
129
|
-
isMut: false,
|
|
130
|
-
isSigner: false,
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
name: 'systemProgram',
|
|
134
|
-
isMut: false,
|
|
135
|
-
isSigner: false,
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
name: 'solPoolPda',
|
|
139
|
-
isMut: true,
|
|
140
|
-
isSigner: false,
|
|
141
|
-
isOptional: true,
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
args: [
|
|
145
|
-
{
|
|
146
|
-
name: 'publicKeys',
|
|
147
|
-
type: {
|
|
148
|
-
vec: 'publicKey',
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
name: 'amounts',
|
|
153
|
-
type: {
|
|
154
|
-
vec: 'u64',
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
name: 'lamports',
|
|
159
|
-
type: {
|
|
160
|
-
option: 'u64',
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
],
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
name: 'compressSplTokenAccount',
|
|
167
|
-
docs: [
|
|
168
|
-
'Compresses the balance of an spl token account sub an optional remaining',
|
|
169
|
-
'amount. This instruction does not close the spl token account. To close',
|
|
170
|
-
'the account bundle a close spl account instruction in your transaction.',
|
|
171
|
-
],
|
|
172
|
-
accounts: [
|
|
173
|
-
{
|
|
174
|
-
name: 'feePayer',
|
|
175
|
-
isMut: true,
|
|
176
|
-
isSigner: true,
|
|
177
|
-
docs: ['UNCHECKED: only pays fees.'],
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
name: 'authority',
|
|
181
|
-
isMut: false,
|
|
182
|
-
isSigner: true,
|
|
183
|
-
docs: [
|
|
184
|
-
'Authority is verified through proof since both owner and delegate',
|
|
185
|
-
'are included in the token data hash, which is a public input to the',
|
|
186
|
-
'validity proof.',
|
|
187
|
-
],
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
name: 'cpiAuthorityPda',
|
|
191
|
-
isMut: false,
|
|
192
|
-
isSigner: false,
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
name: 'lightSystemProgram',
|
|
196
|
-
isMut: false,
|
|
197
|
-
isSigner: false,
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
name: 'registeredProgramPda',
|
|
201
|
-
isMut: false,
|
|
202
|
-
isSigner: false,
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
name: 'noopProgram',
|
|
206
|
-
isMut: false,
|
|
207
|
-
isSigner: false,
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
name: 'accountCompressionAuthority',
|
|
211
|
-
isMut: false,
|
|
212
|
-
isSigner: false,
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
name: 'accountCompressionProgram',
|
|
216
|
-
isMut: false,
|
|
217
|
-
isSigner: false,
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
name: 'selfProgram',
|
|
221
|
-
isMut: false,
|
|
222
|
-
isSigner: false,
|
|
223
|
-
docs: ['this program is the signer of the cpi.'],
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
name: 'tokenPoolPda',
|
|
227
|
-
isMut: true,
|
|
228
|
-
isSigner: false,
|
|
229
|
-
isOptional: true,
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
name: 'compressOrDecompressTokenAccount',
|
|
233
|
-
isMut: true,
|
|
234
|
-
isSigner: false,
|
|
235
|
-
isOptional: true,
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
name: 'tokenProgram',
|
|
239
|
-
isMut: false,
|
|
240
|
-
isSigner: false,
|
|
241
|
-
isOptional: true,
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
name: 'systemProgram',
|
|
245
|
-
isMut: false,
|
|
246
|
-
isSigner: false,
|
|
247
|
-
},
|
|
248
|
-
],
|
|
249
|
-
args: [
|
|
250
|
-
{
|
|
251
|
-
name: 'owner',
|
|
252
|
-
type: 'publicKey',
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
name: 'remainingAmount',
|
|
256
|
-
type: {
|
|
257
|
-
option: 'u64',
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
name: 'cpiContext',
|
|
262
|
-
type: {
|
|
263
|
-
option: {
|
|
264
|
-
defined: 'CompressedCpiContext',
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
],
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
name: 'transfer',
|
|
272
|
-
docs: [
|
|
273
|
-
'Transfers compressed tokens from one account to another. All accounts',
|
|
274
|
-
'must be of the same mint. Additional spl tokens can be compressed or',
|
|
275
|
-
'decompressed. In one transaction only compression or decompression is',
|
|
276
|
-
'possible. Lamports can be transferred alongside tokens. If output token',
|
|
277
|
-
'accounts specify less lamports than inputs the remaining lamports are',
|
|
278
|
-
'transferred to an output compressed account. Signer must be owner or',
|
|
279
|
-
'delegate. If a delegated token account is transferred the delegate is',
|
|
280
|
-
'not preserved.',
|
|
281
|
-
],
|
|
282
|
-
accounts: [
|
|
283
|
-
{
|
|
284
|
-
name: 'feePayer',
|
|
285
|
-
isMut: true,
|
|
286
|
-
isSigner: true,
|
|
287
|
-
docs: ['UNCHECKED: only pays fees.'],
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
name: 'authority',
|
|
291
|
-
isMut: false,
|
|
292
|
-
isSigner: true,
|
|
293
|
-
docs: [
|
|
294
|
-
'Authority is verified through proof since both owner and delegate',
|
|
295
|
-
'are included in the token data hash, which is a public input to the',
|
|
296
|
-
'validity proof.',
|
|
297
|
-
],
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
name: 'cpiAuthorityPda',
|
|
301
|
-
isMut: false,
|
|
302
|
-
isSigner: false,
|
|
303
|
-
},
|
|
304
|
-
{
|
|
305
|
-
name: 'lightSystemProgram',
|
|
306
|
-
isMut: false,
|
|
307
|
-
isSigner: false,
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
name: 'registeredProgramPda',
|
|
311
|
-
isMut: false,
|
|
312
|
-
isSigner: false,
|
|
313
|
-
},
|
|
314
|
-
{
|
|
315
|
-
name: 'noopProgram',
|
|
316
|
-
isMut: false,
|
|
317
|
-
isSigner: false,
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
name: 'accountCompressionAuthority',
|
|
321
|
-
isMut: false,
|
|
322
|
-
isSigner: false,
|
|
323
|
-
},
|
|
324
|
-
{
|
|
325
|
-
name: 'accountCompressionProgram',
|
|
326
|
-
isMut: false,
|
|
327
|
-
isSigner: false,
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
name: 'selfProgram',
|
|
331
|
-
isMut: false,
|
|
332
|
-
isSigner: false,
|
|
333
|
-
docs: ['this program is the signer of the cpi.'],
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
name: 'tokenPoolPda',
|
|
337
|
-
isMut: true,
|
|
338
|
-
isSigner: false,
|
|
339
|
-
isOptional: true,
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
name: 'compressOrDecompressTokenAccount',
|
|
343
|
-
isMut: true,
|
|
344
|
-
isSigner: false,
|
|
345
|
-
isOptional: true,
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
name: 'tokenProgram',
|
|
349
|
-
isMut: false,
|
|
350
|
-
isSigner: false,
|
|
351
|
-
isOptional: true,
|
|
352
|
-
},
|
|
353
|
-
{
|
|
354
|
-
name: 'systemProgram',
|
|
355
|
-
isMut: false,
|
|
356
|
-
isSigner: false,
|
|
357
|
-
},
|
|
358
|
-
],
|
|
359
|
-
args: [
|
|
360
|
-
{
|
|
361
|
-
name: 'inputs',
|
|
362
|
-
type: 'bytes',
|
|
363
|
-
},
|
|
364
|
-
],
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
name: 'approve',
|
|
368
|
-
docs: [
|
|
369
|
-
'Delegates an amount to a delegate. A compressed token account is either',
|
|
370
|
-
'completely delegated or not. Prior delegates are not preserved. Cannot',
|
|
371
|
-
'be called by a delegate.',
|
|
372
|
-
'The instruction creates two output accounts:',
|
|
373
|
-
'1. one account with delegated amount',
|
|
374
|
-
'2. one account with remaining(change) amount',
|
|
375
|
-
],
|
|
376
|
-
accounts: [
|
|
377
|
-
{
|
|
378
|
-
name: 'feePayer',
|
|
379
|
-
isMut: true,
|
|
380
|
-
isSigner: true,
|
|
381
|
-
docs: ['UNCHECKED: only pays fees.'],
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
name: 'authority',
|
|
385
|
-
isMut: false,
|
|
386
|
-
isSigner: true,
|
|
387
|
-
docs: [
|
|
388
|
-
'Authority is verified through proof since both owner and delegate',
|
|
389
|
-
'are included in the token data hash, which is a public input to the',
|
|
390
|
-
'validity proof.',
|
|
391
|
-
],
|
|
392
|
-
},
|
|
393
|
-
{
|
|
394
|
-
name: 'cpiAuthorityPda',
|
|
395
|
-
isMut: false,
|
|
396
|
-
isSigner: false,
|
|
397
|
-
},
|
|
398
|
-
{
|
|
399
|
-
name: 'lightSystemProgram',
|
|
400
|
-
isMut: false,
|
|
401
|
-
isSigner: false,
|
|
402
|
-
},
|
|
403
|
-
{
|
|
404
|
-
name: 'registeredProgramPda',
|
|
405
|
-
isMut: false,
|
|
406
|
-
isSigner: false,
|
|
407
|
-
},
|
|
408
|
-
{
|
|
409
|
-
name: 'noopProgram',
|
|
410
|
-
isMut: false,
|
|
411
|
-
isSigner: false,
|
|
412
|
-
},
|
|
413
|
-
{
|
|
414
|
-
name: 'accountCompressionAuthority',
|
|
415
|
-
isMut: false,
|
|
416
|
-
isSigner: false,
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
name: 'accountCompressionProgram',
|
|
420
|
-
isMut: false,
|
|
421
|
-
isSigner: false,
|
|
422
|
-
},
|
|
423
|
-
{
|
|
424
|
-
name: 'selfProgram',
|
|
425
|
-
isMut: false,
|
|
426
|
-
isSigner: false,
|
|
427
|
-
docs: ['this program is the signer of the cpi.'],
|
|
428
|
-
},
|
|
429
|
-
{
|
|
430
|
-
name: 'systemProgram',
|
|
431
|
-
isMut: false,
|
|
432
|
-
isSigner: false,
|
|
433
|
-
},
|
|
434
|
-
],
|
|
435
|
-
args: [
|
|
436
|
-
{
|
|
437
|
-
name: 'inputs',
|
|
438
|
-
type: 'bytes',
|
|
439
|
-
},
|
|
440
|
-
],
|
|
441
|
-
},
|
|
442
|
-
{
|
|
443
|
-
name: 'revoke',
|
|
444
|
-
docs: [
|
|
445
|
-
'Revokes a delegation. The instruction merges all inputs into one output',
|
|
446
|
-
'account. Cannot be called by a delegate. Delegates are not preserved.',
|
|
447
|
-
],
|
|
448
|
-
accounts: [
|
|
449
|
-
{
|
|
450
|
-
name: 'feePayer',
|
|
451
|
-
isMut: true,
|
|
452
|
-
isSigner: true,
|
|
453
|
-
docs: ['UNCHECKED: only pays fees.'],
|
|
454
|
-
},
|
|
455
|
-
{
|
|
456
|
-
name: 'authority',
|
|
457
|
-
isMut: false,
|
|
458
|
-
isSigner: true,
|
|
459
|
-
docs: [
|
|
460
|
-
'Authority is verified through proof since both owner and delegate',
|
|
461
|
-
'are included in the token data hash, which is a public input to the',
|
|
462
|
-
'validity proof.',
|
|
463
|
-
],
|
|
464
|
-
},
|
|
465
|
-
{
|
|
466
|
-
name: 'cpiAuthorityPda',
|
|
467
|
-
isMut: false,
|
|
468
|
-
isSigner: false,
|
|
469
|
-
},
|
|
470
|
-
{
|
|
471
|
-
name: 'lightSystemProgram',
|
|
472
|
-
isMut: false,
|
|
473
|
-
isSigner: false,
|
|
474
|
-
},
|
|
475
|
-
{
|
|
476
|
-
name: 'registeredProgramPda',
|
|
477
|
-
isMut: false,
|
|
478
|
-
isSigner: false,
|
|
479
|
-
},
|
|
480
|
-
{
|
|
481
|
-
name: 'noopProgram',
|
|
482
|
-
isMut: false,
|
|
483
|
-
isSigner: false,
|
|
484
|
-
},
|
|
485
|
-
{
|
|
486
|
-
name: 'accountCompressionAuthority',
|
|
487
|
-
isMut: false,
|
|
488
|
-
isSigner: false,
|
|
489
|
-
},
|
|
490
|
-
{
|
|
491
|
-
name: 'accountCompressionProgram',
|
|
492
|
-
isMut: false,
|
|
493
|
-
isSigner: false,
|
|
494
|
-
},
|
|
495
|
-
{
|
|
496
|
-
name: 'selfProgram',
|
|
497
|
-
isMut: false,
|
|
498
|
-
isSigner: false,
|
|
499
|
-
docs: ['this program is the signer of the cpi.'],
|
|
500
|
-
},
|
|
501
|
-
{
|
|
502
|
-
name: 'systemProgram',
|
|
503
|
-
isMut: false,
|
|
504
|
-
isSigner: false,
|
|
505
|
-
},
|
|
506
|
-
],
|
|
507
|
-
args: [
|
|
508
|
-
{
|
|
509
|
-
name: 'inputs',
|
|
510
|
-
type: 'bytes',
|
|
511
|
-
},
|
|
512
|
-
],
|
|
513
|
-
},
|
|
514
|
-
{
|
|
515
|
-
name: 'freeze',
|
|
516
|
-
docs: [
|
|
517
|
-
'Freezes compressed token accounts. Inputs must not be frozen. Creates as',
|
|
518
|
-
'many outputs as inputs. Balances and delegates are preserved.',
|
|
519
|
-
],
|
|
520
|
-
accounts: [
|
|
521
|
-
{
|
|
522
|
-
name: 'feePayer',
|
|
523
|
-
isMut: true,
|
|
524
|
-
isSigner: true,
|
|
525
|
-
docs: ['UNCHECKED: only pays fees.'],
|
|
526
|
-
},
|
|
527
|
-
{
|
|
528
|
-
name: 'authority',
|
|
529
|
-
isMut: false,
|
|
530
|
-
isSigner: true,
|
|
531
|
-
},
|
|
532
|
-
{
|
|
533
|
-
name: 'cpiAuthorityPda',
|
|
534
|
-
isMut: false,
|
|
535
|
-
isSigner: false,
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
name: 'lightSystemProgram',
|
|
539
|
-
isMut: false,
|
|
540
|
-
isSigner: false,
|
|
541
|
-
},
|
|
542
|
-
{
|
|
543
|
-
name: 'registeredProgramPda',
|
|
544
|
-
isMut: false,
|
|
545
|
-
isSigner: false,
|
|
546
|
-
},
|
|
547
|
-
{
|
|
548
|
-
name: 'noopProgram',
|
|
549
|
-
isMut: false,
|
|
550
|
-
isSigner: false,
|
|
551
|
-
},
|
|
552
|
-
{
|
|
553
|
-
name: 'accountCompressionAuthority',
|
|
554
|
-
isMut: false,
|
|
555
|
-
isSigner: false,
|
|
556
|
-
},
|
|
557
|
-
{
|
|
558
|
-
name: 'accountCompressionProgram',
|
|
559
|
-
isMut: false,
|
|
560
|
-
isSigner: false,
|
|
561
|
-
},
|
|
562
|
-
{
|
|
563
|
-
name: 'selfProgram',
|
|
564
|
-
isMut: false,
|
|
565
|
-
isSigner: false,
|
|
566
|
-
docs: ['that this program is the signer of the cpi.'],
|
|
567
|
-
},
|
|
568
|
-
{
|
|
569
|
-
name: 'systemProgram',
|
|
570
|
-
isMut: false,
|
|
571
|
-
isSigner: false,
|
|
572
|
-
},
|
|
573
|
-
{
|
|
574
|
-
name: 'mint',
|
|
575
|
-
isMut: false,
|
|
576
|
-
isSigner: false,
|
|
577
|
-
},
|
|
578
|
-
],
|
|
579
|
-
args: [
|
|
580
|
-
{
|
|
581
|
-
name: 'inputs',
|
|
582
|
-
type: 'bytes',
|
|
583
|
-
},
|
|
584
|
-
],
|
|
585
|
-
},
|
|
586
|
-
{
|
|
587
|
-
name: 'thaw',
|
|
588
|
-
docs: [
|
|
589
|
-
'Thaws frozen compressed token accounts. Inputs must be frozen. Creates',
|
|
590
|
-
'as many outputs as inputs. Balances and delegates are preserved.',
|
|
591
|
-
],
|
|
592
|
-
accounts: [
|
|
593
|
-
{
|
|
594
|
-
name: 'feePayer',
|
|
595
|
-
isMut: true,
|
|
596
|
-
isSigner: true,
|
|
597
|
-
docs: ['UNCHECKED: only pays fees.'],
|
|
598
|
-
},
|
|
599
|
-
{
|
|
600
|
-
name: 'authority',
|
|
601
|
-
isMut: false,
|
|
602
|
-
isSigner: true,
|
|
603
|
-
},
|
|
604
|
-
{
|
|
605
|
-
name: 'cpiAuthorityPda',
|
|
606
|
-
isMut: false,
|
|
607
|
-
isSigner: false,
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
name: 'lightSystemProgram',
|
|
611
|
-
isMut: false,
|
|
612
|
-
isSigner: false,
|
|
613
|
-
},
|
|
614
|
-
{
|
|
615
|
-
name: 'registeredProgramPda',
|
|
616
|
-
isMut: false,
|
|
617
|
-
isSigner: false,
|
|
618
|
-
},
|
|
619
|
-
{
|
|
620
|
-
name: 'noopProgram',
|
|
621
|
-
isMut: false,
|
|
622
|
-
isSigner: false,
|
|
623
|
-
},
|
|
624
|
-
{
|
|
625
|
-
name: 'accountCompressionAuthority',
|
|
626
|
-
isMut: false,
|
|
627
|
-
isSigner: false,
|
|
628
|
-
},
|
|
629
|
-
{
|
|
630
|
-
name: 'accountCompressionProgram',
|
|
631
|
-
isMut: false,
|
|
632
|
-
isSigner: false,
|
|
633
|
-
},
|
|
634
|
-
{
|
|
635
|
-
name: 'selfProgram',
|
|
636
|
-
isMut: false,
|
|
637
|
-
isSigner: false,
|
|
638
|
-
docs: ['that this program is the signer of the cpi.'],
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
name: 'systemProgram',
|
|
642
|
-
isMut: false,
|
|
643
|
-
isSigner: false,
|
|
644
|
-
},
|
|
645
|
-
{
|
|
646
|
-
name: 'mint',
|
|
647
|
-
isMut: false,
|
|
648
|
-
isSigner: false,
|
|
649
|
-
},
|
|
650
|
-
],
|
|
651
|
-
args: [
|
|
652
|
-
{
|
|
653
|
-
name: 'inputs',
|
|
654
|
-
type: 'bytes',
|
|
655
|
-
},
|
|
656
|
-
],
|
|
657
|
-
},
|
|
658
|
-
{
|
|
659
|
-
name: 'burn',
|
|
660
|
-
docs: [
|
|
661
|
-
'Burns compressed tokens and spl tokens from the pool account. Delegates',
|
|
662
|
-
'can burn tokens. The output compressed token account remains delegated.',
|
|
663
|
-
'Creates one output compressed token account.',
|
|
664
|
-
],
|
|
665
|
-
accounts: [
|
|
666
|
-
{
|
|
667
|
-
name: 'feePayer',
|
|
668
|
-
isMut: true,
|
|
669
|
-
isSigner: true,
|
|
670
|
-
docs: ['UNCHECKED: only pays fees.'],
|
|
671
|
-
},
|
|
672
|
-
{
|
|
673
|
-
name: 'authority',
|
|
674
|
-
isMut: false,
|
|
675
|
-
isSigner: true,
|
|
676
|
-
docs: [
|
|
677
|
-
'Authority is verified through proof since both owner and delegate',
|
|
678
|
-
'are included in the token data hash, which is a public input to the',
|
|
679
|
-
'validity proof.',
|
|
680
|
-
],
|
|
681
|
-
},
|
|
682
|
-
{
|
|
683
|
-
name: 'cpiAuthorityPda',
|
|
684
|
-
isMut: false,
|
|
685
|
-
isSigner: false,
|
|
686
|
-
},
|
|
687
|
-
{
|
|
688
|
-
name: 'mint',
|
|
689
|
-
isMut: true,
|
|
690
|
-
isSigner: false,
|
|
691
|
-
},
|
|
692
|
-
{
|
|
693
|
-
name: 'tokenPoolPda',
|
|
694
|
-
isMut: true,
|
|
695
|
-
isSigner: false,
|
|
696
|
-
},
|
|
697
|
-
{
|
|
698
|
-
name: 'tokenProgram',
|
|
699
|
-
isMut: false,
|
|
700
|
-
isSigner: false,
|
|
701
|
-
},
|
|
702
|
-
{
|
|
703
|
-
name: 'lightSystemProgram',
|
|
704
|
-
isMut: false,
|
|
705
|
-
isSigner: false,
|
|
706
|
-
},
|
|
707
|
-
{
|
|
708
|
-
name: 'registeredProgramPda',
|
|
709
|
-
isMut: false,
|
|
710
|
-
isSigner: false,
|
|
711
|
-
},
|
|
712
|
-
{
|
|
713
|
-
name: 'noopProgram',
|
|
714
|
-
isMut: false,
|
|
715
|
-
isSigner: false,
|
|
716
|
-
},
|
|
717
|
-
{
|
|
718
|
-
name: 'accountCompressionAuthority',
|
|
719
|
-
isMut: false,
|
|
720
|
-
isSigner: false,
|
|
721
|
-
},
|
|
722
|
-
{
|
|
723
|
-
name: 'accountCompressionProgram',
|
|
724
|
-
isMut: false,
|
|
725
|
-
isSigner: false,
|
|
726
|
-
},
|
|
727
|
-
{
|
|
728
|
-
name: 'selfProgram',
|
|
729
|
-
isMut: false,
|
|
730
|
-
isSigner: false,
|
|
731
|
-
},
|
|
732
|
-
{
|
|
733
|
-
name: 'systemProgram',
|
|
734
|
-
isMut: false,
|
|
735
|
-
isSigner: false,
|
|
736
|
-
},
|
|
737
|
-
],
|
|
738
|
-
args: [
|
|
739
|
-
{
|
|
740
|
-
name: 'inputs',
|
|
741
|
-
type: 'bytes',
|
|
742
|
-
},
|
|
743
|
-
],
|
|
744
|
-
},
|
|
745
|
-
{
|
|
746
|
-
name: 'stubIdlBuild',
|
|
747
|
-
docs: [
|
|
748
|
-
'This function is a stub to allow Anchor to include the input types in',
|
|
749
|
-
'the IDL. It should not be included in production builds nor be called in',
|
|
750
|
-
'practice.',
|
|
751
|
-
],
|
|
752
|
-
accounts: [
|
|
753
|
-
{
|
|
754
|
-
name: 'feePayer',
|
|
755
|
-
isMut: true,
|
|
756
|
-
isSigner: true,
|
|
757
|
-
docs: ['UNCHECKED: only pays fees.'],
|
|
758
|
-
},
|
|
759
|
-
{
|
|
760
|
-
name: 'authority',
|
|
761
|
-
isMut: false,
|
|
762
|
-
isSigner: true,
|
|
763
|
-
docs: [
|
|
764
|
-
'Authority is verified through proof since both owner and delegate',
|
|
765
|
-
'are included in the token data hash, which is a public input to the',
|
|
766
|
-
'validity proof.',
|
|
767
|
-
],
|
|
768
|
-
},
|
|
769
|
-
{
|
|
770
|
-
name: 'cpiAuthorityPda',
|
|
771
|
-
isMut: false,
|
|
772
|
-
isSigner: false,
|
|
773
|
-
},
|
|
774
|
-
{
|
|
775
|
-
name: 'lightSystemProgram',
|
|
776
|
-
isMut: false,
|
|
777
|
-
isSigner: false,
|
|
778
|
-
},
|
|
779
|
-
{
|
|
780
|
-
name: 'registeredProgramPda',
|
|
781
|
-
isMut: false,
|
|
782
|
-
isSigner: false,
|
|
783
|
-
},
|
|
784
|
-
{
|
|
785
|
-
name: 'noopProgram',
|
|
786
|
-
isMut: false,
|
|
787
|
-
isSigner: false,
|
|
788
|
-
},
|
|
789
|
-
{
|
|
790
|
-
name: 'accountCompressionAuthority',
|
|
791
|
-
isMut: false,
|
|
792
|
-
isSigner: false,
|
|
793
|
-
},
|
|
794
|
-
{
|
|
795
|
-
name: 'accountCompressionProgram',
|
|
796
|
-
isMut: false,
|
|
797
|
-
isSigner: false,
|
|
798
|
-
},
|
|
799
|
-
{
|
|
800
|
-
name: 'selfProgram',
|
|
801
|
-
isMut: false,
|
|
802
|
-
isSigner: false,
|
|
803
|
-
docs: ['this program is the signer of the cpi.'],
|
|
804
|
-
},
|
|
805
|
-
{
|
|
806
|
-
name: 'tokenPoolPda',
|
|
807
|
-
isMut: true,
|
|
808
|
-
isSigner: false,
|
|
809
|
-
isOptional: true,
|
|
810
|
-
},
|
|
811
|
-
{
|
|
812
|
-
name: 'compressOrDecompressTokenAccount',
|
|
813
|
-
isMut: true,
|
|
814
|
-
isSigner: false,
|
|
815
|
-
isOptional: true,
|
|
816
|
-
},
|
|
817
|
-
{
|
|
818
|
-
name: 'tokenProgram',
|
|
819
|
-
isMut: false,
|
|
820
|
-
isSigner: false,
|
|
821
|
-
isOptional: true,
|
|
822
|
-
},
|
|
823
|
-
{
|
|
824
|
-
name: 'systemProgram',
|
|
825
|
-
isMut: false,
|
|
826
|
-
isSigner: false,
|
|
827
|
-
},
|
|
828
|
-
],
|
|
829
|
-
args: [
|
|
830
|
-
{
|
|
831
|
-
name: 'inputs1',
|
|
832
|
-
type: {
|
|
833
|
-
defined: 'CompressedTokenInstructionDataTransfer',
|
|
834
|
-
},
|
|
835
|
-
},
|
|
836
|
-
{
|
|
837
|
-
name: 'inputs2',
|
|
838
|
-
type: {
|
|
839
|
-
defined: 'TokenData',
|
|
840
|
-
},
|
|
841
|
-
},
|
|
842
|
-
],
|
|
843
|
-
},
|
|
844
|
-
],
|
|
845
|
-
types: [
|
|
846
|
-
{
|
|
847
|
-
name: 'AccessMetadata',
|
|
848
|
-
type: {
|
|
849
|
-
kind: 'struct',
|
|
850
|
-
fields: [
|
|
851
|
-
{
|
|
852
|
-
name: 'owner',
|
|
853
|
-
docs: ['Owner of the Merkle tree.'],
|
|
854
|
-
type: 'publicKey',
|
|
855
|
-
},
|
|
856
|
-
{
|
|
857
|
-
name: 'programOwner',
|
|
858
|
-
docs: [
|
|
859
|
-
'Program owner of the Merkle tree. This will be used for program owned Merkle trees.',
|
|
860
|
-
],
|
|
861
|
-
type: 'publicKey',
|
|
862
|
-
},
|
|
863
|
-
{
|
|
864
|
-
name: 'forester',
|
|
865
|
-
docs: [
|
|
866
|
-
'Optional privileged forester pubkey, can be set for custom Merkle trees',
|
|
867
|
-
'without a network fee. Merkle trees without network fees are not',
|
|
868
|
-
'forested by light foresters. The variable is not used in the account',
|
|
869
|
-
'compression program but the registry program. The registry program',
|
|
870
|
-
'implements access control to prevent contention during forester. The',
|
|
871
|
-
'forester pubkey specified in this struct can bypass contention checks.',
|
|
872
|
-
],
|
|
873
|
-
type: 'publicKey',
|
|
874
|
-
},
|
|
875
|
-
],
|
|
876
|
-
},
|
|
877
|
-
},
|
|
878
|
-
{
|
|
879
|
-
name: 'AccountState',
|
|
880
|
-
type: {
|
|
881
|
-
kind: 'enum',
|
|
882
|
-
variants: [
|
|
883
|
-
{
|
|
884
|
-
name: 'Initialized',
|
|
885
|
-
},
|
|
886
|
-
{
|
|
887
|
-
name: 'Frozen',
|
|
888
|
-
},
|
|
889
|
-
],
|
|
890
|
-
},
|
|
891
|
-
},
|
|
892
|
-
{
|
|
893
|
-
name: 'CompressedAccount',
|
|
894
|
-
type: {
|
|
895
|
-
kind: 'struct',
|
|
896
|
-
fields: [
|
|
897
|
-
{
|
|
898
|
-
name: 'owner',
|
|
899
|
-
type: 'publicKey',
|
|
900
|
-
},
|
|
901
|
-
{
|
|
902
|
-
name: 'lamports',
|
|
903
|
-
type: 'u64',
|
|
904
|
-
},
|
|
905
|
-
{
|
|
906
|
-
name: 'address',
|
|
907
|
-
type: {
|
|
908
|
-
option: {
|
|
909
|
-
array: ['u8', 32],
|
|
910
|
-
},
|
|
911
|
-
},
|
|
912
|
-
},
|
|
913
|
-
{
|
|
914
|
-
name: 'data',
|
|
915
|
-
type: {
|
|
916
|
-
option: {
|
|
917
|
-
defined: 'CompressedAccountData',
|
|
918
|
-
},
|
|
919
|
-
},
|
|
920
|
-
},
|
|
921
|
-
],
|
|
922
|
-
},
|
|
923
|
-
},
|
|
924
|
-
{
|
|
925
|
-
name: 'CompressedAccountData',
|
|
926
|
-
type: {
|
|
927
|
-
kind: 'struct',
|
|
928
|
-
fields: [
|
|
929
|
-
{
|
|
930
|
-
name: 'discriminator',
|
|
931
|
-
type: {
|
|
932
|
-
array: ['u8', 8],
|
|
933
|
-
},
|
|
934
|
-
},
|
|
935
|
-
{
|
|
936
|
-
name: 'data',
|
|
937
|
-
type: 'bytes',
|
|
938
|
-
},
|
|
939
|
-
{
|
|
940
|
-
name: 'dataHash',
|
|
941
|
-
type: {
|
|
942
|
-
array: ['u8', 32],
|
|
943
|
-
},
|
|
944
|
-
},
|
|
945
|
-
],
|
|
946
|
-
},
|
|
947
|
-
},
|
|
948
|
-
{
|
|
949
|
-
name: 'CompressedCpiContext',
|
|
950
|
-
type: {
|
|
951
|
-
kind: 'struct',
|
|
952
|
-
fields: [
|
|
953
|
-
{
|
|
954
|
-
name: 'setContext',
|
|
955
|
-
docs: [
|
|
956
|
-
'Is set by the program that is invoking the CPI to signal that is should',
|
|
957
|
-
'set the cpi context.',
|
|
958
|
-
],
|
|
959
|
-
type: 'bool',
|
|
960
|
-
},
|
|
961
|
-
{
|
|
962
|
-
name: 'firstSetContext',
|
|
963
|
-
docs: [
|
|
964
|
-
'Is set to wipe the cpi context since someone could have set it before',
|
|
965
|
-
'with unrelated data.',
|
|
966
|
-
],
|
|
967
|
-
type: 'bool',
|
|
968
|
-
},
|
|
969
|
-
{
|
|
970
|
-
name: 'cpiContextAccountIndex',
|
|
971
|
-
docs: [
|
|
972
|
-
'Index of cpi context account in remaining accounts.',
|
|
973
|
-
],
|
|
974
|
-
type: 'u8',
|
|
975
|
-
},
|
|
976
|
-
],
|
|
977
|
-
},
|
|
978
|
-
},
|
|
979
|
-
{
|
|
980
|
-
name: 'CompressedProof',
|
|
981
|
-
type: {
|
|
982
|
-
kind: 'struct',
|
|
983
|
-
fields: [
|
|
984
|
-
{
|
|
985
|
-
name: 'a',
|
|
986
|
-
type: {
|
|
987
|
-
array: ['u8', 32],
|
|
988
|
-
},
|
|
989
|
-
},
|
|
990
|
-
{
|
|
991
|
-
name: 'b',
|
|
992
|
-
type: {
|
|
993
|
-
array: ['u8', 64],
|
|
994
|
-
},
|
|
995
|
-
},
|
|
996
|
-
{
|
|
997
|
-
name: 'c',
|
|
998
|
-
type: {
|
|
999
|
-
array: ['u8', 32],
|
|
1000
|
-
},
|
|
1001
|
-
},
|
|
1002
|
-
],
|
|
1003
|
-
},
|
|
1004
|
-
},
|
|
1005
|
-
{
|
|
1006
|
-
name: 'CompressedTokenInstructionDataTransfer',
|
|
1007
|
-
type: {
|
|
1008
|
-
kind: 'struct',
|
|
1009
|
-
fields: [
|
|
1010
|
-
{
|
|
1011
|
-
name: 'proof',
|
|
1012
|
-
type: {
|
|
1013
|
-
option: {
|
|
1014
|
-
defined: 'CompressedProof',
|
|
1015
|
-
},
|
|
1016
|
-
},
|
|
1017
|
-
},
|
|
1018
|
-
{
|
|
1019
|
-
name: 'mint',
|
|
1020
|
-
type: 'publicKey',
|
|
1021
|
-
},
|
|
1022
|
-
{
|
|
1023
|
-
name: 'delegatedTransfer',
|
|
1024
|
-
docs: [
|
|
1025
|
-
'Is required if the signer is delegate,',
|
|
1026
|
-
'-> delegate is authority account,',
|
|
1027
|
-
'owner = Some(owner) is the owner of the token account.',
|
|
1028
|
-
],
|
|
1029
|
-
type: {
|
|
1030
|
-
option: {
|
|
1031
|
-
defined: 'DelegatedTransfer',
|
|
1032
|
-
},
|
|
1033
|
-
},
|
|
1034
|
-
},
|
|
1035
|
-
{
|
|
1036
|
-
name: 'inputTokenDataWithContext',
|
|
1037
|
-
type: {
|
|
1038
|
-
vec: {
|
|
1039
|
-
defined: 'InputTokenDataWithContext',
|
|
1040
|
-
},
|
|
1041
|
-
},
|
|
1042
|
-
},
|
|
1043
|
-
{
|
|
1044
|
-
name: 'outputCompressedAccounts',
|
|
1045
|
-
type: {
|
|
1046
|
-
vec: {
|
|
1047
|
-
defined: 'PackedTokenTransferOutputData',
|
|
1048
|
-
},
|
|
1049
|
-
},
|
|
1050
|
-
},
|
|
1051
|
-
{
|
|
1052
|
-
name: 'isCompress',
|
|
1053
|
-
type: 'bool',
|
|
1054
|
-
},
|
|
1055
|
-
{
|
|
1056
|
-
name: 'compressOrDecompressAmount',
|
|
1057
|
-
type: {
|
|
1058
|
-
option: 'u64',
|
|
1059
|
-
},
|
|
1060
|
-
},
|
|
1061
|
-
{
|
|
1062
|
-
name: 'cpiContext',
|
|
1063
|
-
type: {
|
|
1064
|
-
option: {
|
|
1065
|
-
defined: 'CompressedCpiContext',
|
|
1066
|
-
},
|
|
1067
|
-
},
|
|
1068
|
-
},
|
|
1069
|
-
{
|
|
1070
|
-
name: 'lamportsChangeAccountMerkleTreeIndex',
|
|
1071
|
-
type: {
|
|
1072
|
-
option: 'u8',
|
|
1073
|
-
},
|
|
1074
|
-
},
|
|
1075
|
-
],
|
|
1076
|
-
},
|
|
1077
|
-
},
|
|
1078
|
-
{
|
|
1079
|
-
name: 'DelegatedTransfer',
|
|
1080
|
-
docs: [
|
|
1081
|
-
'Struct to provide the owner when the delegate is signer of the transaction.',
|
|
1082
|
-
],
|
|
1083
|
-
type: {
|
|
1084
|
-
kind: 'struct',
|
|
1085
|
-
fields: [
|
|
1086
|
-
{
|
|
1087
|
-
name: 'owner',
|
|
1088
|
-
type: 'publicKey',
|
|
1089
|
-
},
|
|
1090
|
-
{
|
|
1091
|
-
name: 'delegateChangeAccountIndex',
|
|
1092
|
-
docs: [
|
|
1093
|
-
'Index of change compressed account in output compressed accounts. In',
|
|
1094
|
-
"case that the delegate didn't spend the complete delegated compressed",
|
|
1095
|
-
'account balance the change compressed account will be delegated to her',
|
|
1096
|
-
'as well.',
|
|
1097
|
-
],
|
|
1098
|
-
type: {
|
|
1099
|
-
option: 'u8',
|
|
1100
|
-
},
|
|
1101
|
-
},
|
|
1102
|
-
],
|
|
1103
|
-
},
|
|
1104
|
-
},
|
|
1105
|
-
{
|
|
1106
|
-
name: 'InputTokenDataWithContext',
|
|
1107
|
-
type: {
|
|
1108
|
-
kind: 'struct',
|
|
1109
|
-
fields: [
|
|
1110
|
-
{
|
|
1111
|
-
name: 'amount',
|
|
1112
|
-
type: 'u64',
|
|
1113
|
-
},
|
|
1114
|
-
{
|
|
1115
|
-
name: 'delegateIndex',
|
|
1116
|
-
type: {
|
|
1117
|
-
option: 'u8',
|
|
1118
|
-
},
|
|
1119
|
-
},
|
|
1120
|
-
{
|
|
1121
|
-
name: 'merkleContext',
|
|
1122
|
-
type: {
|
|
1123
|
-
defined: 'PackedMerkleContext',
|
|
1124
|
-
},
|
|
1125
|
-
},
|
|
1126
|
-
{
|
|
1127
|
-
name: 'rootIndex',
|
|
1128
|
-
type: 'u16',
|
|
1129
|
-
},
|
|
1130
|
-
{
|
|
1131
|
-
name: 'lamports',
|
|
1132
|
-
type: {
|
|
1133
|
-
option: 'u64',
|
|
1134
|
-
},
|
|
1135
|
-
},
|
|
1136
|
-
{
|
|
1137
|
-
name: 'tlv',
|
|
1138
|
-
docs: [
|
|
1139
|
-
'Placeholder for TokenExtension tlv data (unimplemented)',
|
|
1140
|
-
],
|
|
1141
|
-
type: {
|
|
1142
|
-
option: 'bytes',
|
|
1143
|
-
},
|
|
1144
|
-
},
|
|
1145
|
-
],
|
|
1146
|
-
},
|
|
1147
|
-
},
|
|
1148
|
-
{
|
|
1149
|
-
name: 'InstructionDataInvoke',
|
|
1150
|
-
type: {
|
|
1151
|
-
kind: 'struct',
|
|
1152
|
-
fields: [
|
|
1153
|
-
{
|
|
1154
|
-
name: 'proof',
|
|
1155
|
-
type: {
|
|
1156
|
-
option: {
|
|
1157
|
-
defined: 'CompressedProof',
|
|
1158
|
-
},
|
|
1159
|
-
},
|
|
1160
|
-
},
|
|
1161
|
-
{
|
|
1162
|
-
name: 'inputCompressedAccountsWithMerkleContext',
|
|
1163
|
-
type: {
|
|
1164
|
-
vec: {
|
|
1165
|
-
defined: 'PackedCompressedAccountWithMerkleContext',
|
|
1166
|
-
},
|
|
1167
|
-
},
|
|
1168
|
-
},
|
|
1169
|
-
{
|
|
1170
|
-
name: 'outputCompressedAccounts',
|
|
1171
|
-
type: {
|
|
1172
|
-
vec: {
|
|
1173
|
-
defined: 'OutputCompressedAccountWithPackedContext',
|
|
1174
|
-
},
|
|
1175
|
-
},
|
|
1176
|
-
},
|
|
1177
|
-
{
|
|
1178
|
-
name: 'relayFee',
|
|
1179
|
-
type: {
|
|
1180
|
-
option: 'u64',
|
|
1181
|
-
},
|
|
1182
|
-
},
|
|
1183
|
-
{
|
|
1184
|
-
name: 'newAddressParams',
|
|
1185
|
-
type: {
|
|
1186
|
-
vec: {
|
|
1187
|
-
defined: 'NewAddressParamsPacked',
|
|
1188
|
-
},
|
|
1189
|
-
},
|
|
1190
|
-
},
|
|
1191
|
-
{
|
|
1192
|
-
name: 'compressOrDecompressLamports',
|
|
1193
|
-
type: {
|
|
1194
|
-
option: 'u64',
|
|
1195
|
-
},
|
|
1196
|
-
},
|
|
1197
|
-
{
|
|
1198
|
-
name: 'isCompress',
|
|
1199
|
-
type: 'bool',
|
|
1200
|
-
},
|
|
1201
|
-
],
|
|
1202
|
-
},
|
|
1203
|
-
},
|
|
1204
|
-
{
|
|
1205
|
-
name: 'InstructionDataInvokeCpi',
|
|
1206
|
-
type: {
|
|
1207
|
-
kind: 'struct',
|
|
1208
|
-
fields: [
|
|
1209
|
-
{
|
|
1210
|
-
name: 'proof',
|
|
1211
|
-
type: {
|
|
1212
|
-
option: {
|
|
1213
|
-
defined: 'CompressedProof',
|
|
1214
|
-
},
|
|
1215
|
-
},
|
|
1216
|
-
},
|
|
1217
|
-
{
|
|
1218
|
-
name: 'newAddressParams',
|
|
1219
|
-
type: {
|
|
1220
|
-
vec: {
|
|
1221
|
-
defined: 'NewAddressParamsPacked',
|
|
1222
|
-
},
|
|
1223
|
-
},
|
|
1224
|
-
},
|
|
1225
|
-
{
|
|
1226
|
-
name: 'inputCompressedAccountsWithMerkleContext',
|
|
1227
|
-
type: {
|
|
1228
|
-
vec: {
|
|
1229
|
-
defined: 'PackedCompressedAccountWithMerkleContext',
|
|
1230
|
-
},
|
|
1231
|
-
},
|
|
1232
|
-
},
|
|
1233
|
-
{
|
|
1234
|
-
name: 'outputCompressedAccounts',
|
|
1235
|
-
type: {
|
|
1236
|
-
vec: {
|
|
1237
|
-
defined: 'OutputCompressedAccountWithPackedContext',
|
|
1238
|
-
},
|
|
1239
|
-
},
|
|
1240
|
-
},
|
|
1241
|
-
{
|
|
1242
|
-
name: 'relayFee',
|
|
1243
|
-
type: {
|
|
1244
|
-
option: 'u64',
|
|
1245
|
-
},
|
|
1246
|
-
},
|
|
1247
|
-
{
|
|
1248
|
-
name: 'compressOrDecompressLamports',
|
|
1249
|
-
type: {
|
|
1250
|
-
option: 'u64',
|
|
1251
|
-
},
|
|
1252
|
-
},
|
|
1253
|
-
{
|
|
1254
|
-
name: 'isCompress',
|
|
1255
|
-
type: 'bool',
|
|
1256
|
-
},
|
|
1257
|
-
{
|
|
1258
|
-
name: 'cpiContext',
|
|
1259
|
-
type: {
|
|
1260
|
-
option: {
|
|
1261
|
-
defined: 'CompressedCpiContext',
|
|
1262
|
-
},
|
|
1263
|
-
},
|
|
1264
|
-
},
|
|
1265
|
-
],
|
|
1266
|
-
},
|
|
1267
|
-
},
|
|
1268
|
-
{
|
|
1269
|
-
name: 'MerkleTreeMetadata',
|
|
1270
|
-
type: {
|
|
1271
|
-
kind: 'struct',
|
|
1272
|
-
fields: [
|
|
1273
|
-
{
|
|
1274
|
-
name: 'accessMetadata',
|
|
1275
|
-
type: {
|
|
1276
|
-
defined: 'AccessMetadata',
|
|
1277
|
-
},
|
|
1278
|
-
},
|
|
1279
|
-
{
|
|
1280
|
-
name: 'rolloverMetadata',
|
|
1281
|
-
type: {
|
|
1282
|
-
defined: 'RolloverMetadata',
|
|
1283
|
-
},
|
|
1284
|
-
},
|
|
1285
|
-
{
|
|
1286
|
-
name: 'associatedQueue',
|
|
1287
|
-
type: 'publicKey',
|
|
1288
|
-
},
|
|
1289
|
-
{
|
|
1290
|
-
name: 'nextMerkleTree',
|
|
1291
|
-
type: 'publicKey',
|
|
1292
|
-
},
|
|
1293
|
-
],
|
|
1294
|
-
},
|
|
1295
|
-
},
|
|
1296
|
-
{
|
|
1297
|
-
name: 'MerkleTreeSequenceNumber',
|
|
1298
|
-
type: {
|
|
1299
|
-
kind: 'struct',
|
|
1300
|
-
fields: [
|
|
1301
|
-
{
|
|
1302
|
-
name: 'pubkey',
|
|
1303
|
-
type: 'publicKey',
|
|
1304
|
-
},
|
|
1305
|
-
{
|
|
1306
|
-
name: 'seq',
|
|
1307
|
-
type: 'u64',
|
|
1308
|
-
},
|
|
1309
|
-
],
|
|
1310
|
-
},
|
|
1311
|
-
},
|
|
1312
|
-
{
|
|
1313
|
-
name: 'NewAddressParamsPacked',
|
|
1314
|
-
type: {
|
|
1315
|
-
kind: 'struct',
|
|
1316
|
-
fields: [
|
|
1317
|
-
{
|
|
1318
|
-
name: 'seed',
|
|
1319
|
-
type: {
|
|
1320
|
-
array: ['u8', 32],
|
|
1321
|
-
},
|
|
1322
|
-
},
|
|
1323
|
-
{
|
|
1324
|
-
name: 'addressQueueAccountIndex',
|
|
1325
|
-
type: 'u8',
|
|
1326
|
-
},
|
|
1327
|
-
{
|
|
1328
|
-
name: 'addressMerkleTreeAccountIndex',
|
|
1329
|
-
type: 'u8',
|
|
1330
|
-
},
|
|
1331
|
-
{
|
|
1332
|
-
name: 'addressMerkleTreeRootIndex',
|
|
1333
|
-
type: 'u16',
|
|
1334
|
-
},
|
|
1335
|
-
],
|
|
1336
|
-
},
|
|
1337
|
-
},
|
|
1338
|
-
{
|
|
1339
|
-
name: 'OutputCompressedAccountWithPackedContext',
|
|
1340
|
-
type: {
|
|
1341
|
-
kind: 'struct',
|
|
1342
|
-
fields: [
|
|
1343
|
-
{
|
|
1344
|
-
name: 'compressedAccount',
|
|
1345
|
-
type: {
|
|
1346
|
-
defined: 'CompressedAccount',
|
|
1347
|
-
},
|
|
1348
|
-
},
|
|
1349
|
-
{
|
|
1350
|
-
name: 'merkleTreeIndex',
|
|
1351
|
-
type: 'u8',
|
|
1352
|
-
},
|
|
1353
|
-
],
|
|
1354
|
-
},
|
|
1355
|
-
},
|
|
1356
|
-
{
|
|
1357
|
-
name: 'PackedCompressedAccountWithMerkleContext',
|
|
1358
|
-
type: {
|
|
1359
|
-
kind: 'struct',
|
|
1360
|
-
fields: [
|
|
1361
|
-
{
|
|
1362
|
-
name: 'compressedAccount',
|
|
1363
|
-
type: {
|
|
1364
|
-
defined: 'CompressedAccount',
|
|
1365
|
-
},
|
|
1366
|
-
},
|
|
1367
|
-
{
|
|
1368
|
-
name: 'merkleContext',
|
|
1369
|
-
type: {
|
|
1370
|
-
defined: 'PackedMerkleContext',
|
|
1371
|
-
},
|
|
1372
|
-
},
|
|
1373
|
-
{
|
|
1374
|
-
name: 'rootIndex',
|
|
1375
|
-
docs: [
|
|
1376
|
-
'Index of root used in inclusion validity proof.',
|
|
1377
|
-
],
|
|
1378
|
-
type: 'u16',
|
|
1379
|
-
},
|
|
1380
|
-
{
|
|
1381
|
-
name: 'readOnly',
|
|
1382
|
-
docs: [
|
|
1383
|
-
'Placeholder to mark accounts read-only unimplemented set to false.',
|
|
1384
|
-
],
|
|
1385
|
-
type: 'bool',
|
|
1386
|
-
},
|
|
1387
|
-
],
|
|
1388
|
-
},
|
|
1389
|
-
},
|
|
1390
|
-
{
|
|
1391
|
-
name: 'PackedMerkleContext',
|
|
1392
|
-
type: {
|
|
1393
|
-
kind: 'struct',
|
|
1394
|
-
fields: [
|
|
1395
|
-
{
|
|
1396
|
-
name: 'merkleTreePubkeyIndex',
|
|
1397
|
-
type: 'u8',
|
|
1398
|
-
},
|
|
1399
|
-
{
|
|
1400
|
-
name: 'nullifierQueuePubkeyIndex',
|
|
1401
|
-
type: 'u8',
|
|
1402
|
-
},
|
|
1403
|
-
{
|
|
1404
|
-
name: 'leafIndex',
|
|
1405
|
-
type: 'u32',
|
|
1406
|
-
},
|
|
1407
|
-
{
|
|
1408
|
-
name: 'queueIndex',
|
|
1409
|
-
docs: [
|
|
1410
|
-
'Index of leaf in queue. Placeholder of batched Merkle tree updates',
|
|
1411
|
-
'currently unimplemented.',
|
|
1412
|
-
],
|
|
1413
|
-
type: {
|
|
1414
|
-
option: {
|
|
1415
|
-
defined: 'QueueIndex',
|
|
1416
|
-
},
|
|
1417
|
-
},
|
|
1418
|
-
},
|
|
1419
|
-
],
|
|
1420
|
-
},
|
|
1421
|
-
},
|
|
1422
|
-
{
|
|
1423
|
-
name: 'PackedTokenTransferOutputData',
|
|
1424
|
-
type: {
|
|
1425
|
-
kind: 'struct',
|
|
1426
|
-
fields: [
|
|
1427
|
-
{
|
|
1428
|
-
name: 'owner',
|
|
1429
|
-
type: 'publicKey',
|
|
1430
|
-
},
|
|
1431
|
-
{
|
|
1432
|
-
name: 'amount',
|
|
1433
|
-
type: 'u64',
|
|
1434
|
-
},
|
|
1435
|
-
{
|
|
1436
|
-
name: 'lamports',
|
|
1437
|
-
type: {
|
|
1438
|
-
option: 'u64',
|
|
1439
|
-
},
|
|
1440
|
-
},
|
|
1441
|
-
{
|
|
1442
|
-
name: 'merkleTreeIndex',
|
|
1443
|
-
type: 'u8',
|
|
1444
|
-
},
|
|
1445
|
-
{
|
|
1446
|
-
name: 'tlv',
|
|
1447
|
-
docs: [
|
|
1448
|
-
'Placeholder for TokenExtension tlv data (unimplemented)',
|
|
1449
|
-
],
|
|
1450
|
-
type: {
|
|
1451
|
-
option: 'bytes',
|
|
1452
|
-
},
|
|
1453
|
-
},
|
|
1454
|
-
],
|
|
1455
|
-
},
|
|
1456
|
-
},
|
|
1457
|
-
{
|
|
1458
|
-
name: 'PublicTransactionEvent',
|
|
1459
|
-
type: {
|
|
1460
|
-
kind: 'struct',
|
|
1461
|
-
fields: [
|
|
1462
|
-
{
|
|
1463
|
-
name: 'inputCompressedAccountHashes',
|
|
1464
|
-
type: {
|
|
1465
|
-
vec: {
|
|
1466
|
-
array: ['u8', 32],
|
|
1467
|
-
},
|
|
1468
|
-
},
|
|
1469
|
-
},
|
|
1470
|
-
{
|
|
1471
|
-
name: 'outputCompressedAccountHashes',
|
|
1472
|
-
type: {
|
|
1473
|
-
vec: {
|
|
1474
|
-
array: ['u8', 32],
|
|
1475
|
-
},
|
|
1476
|
-
},
|
|
1477
|
-
},
|
|
1478
|
-
{
|
|
1479
|
-
name: 'outputCompressedAccounts',
|
|
1480
|
-
type: {
|
|
1481
|
-
vec: {
|
|
1482
|
-
defined: 'OutputCompressedAccountWithPackedContext',
|
|
1483
|
-
},
|
|
1484
|
-
},
|
|
1485
|
-
},
|
|
1486
|
-
{
|
|
1487
|
-
name: 'outputLeafIndices',
|
|
1488
|
-
type: {
|
|
1489
|
-
vec: 'u32',
|
|
1490
|
-
},
|
|
1491
|
-
},
|
|
1492
|
-
{
|
|
1493
|
-
name: 'sequenceNumbers',
|
|
1494
|
-
type: {
|
|
1495
|
-
vec: {
|
|
1496
|
-
defined: 'MerkleTreeSequenceNumber',
|
|
1497
|
-
},
|
|
1498
|
-
},
|
|
1499
|
-
},
|
|
1500
|
-
{
|
|
1501
|
-
name: 'relayFee',
|
|
1502
|
-
type: {
|
|
1503
|
-
option: 'u64',
|
|
1504
|
-
},
|
|
1505
|
-
},
|
|
1506
|
-
{
|
|
1507
|
-
name: 'isCompress',
|
|
1508
|
-
type: 'bool',
|
|
1509
|
-
},
|
|
1510
|
-
{
|
|
1511
|
-
name: 'compressOrDecompressLamports',
|
|
1512
|
-
type: {
|
|
1513
|
-
option: 'u64',
|
|
1514
|
-
},
|
|
1515
|
-
},
|
|
1516
|
-
{
|
|
1517
|
-
name: 'pubkeyArray',
|
|
1518
|
-
type: {
|
|
1519
|
-
vec: 'publicKey',
|
|
1520
|
-
},
|
|
1521
|
-
},
|
|
1522
|
-
{
|
|
1523
|
-
name: 'message',
|
|
1524
|
-
type: {
|
|
1525
|
-
option: 'bytes',
|
|
1526
|
-
},
|
|
1527
|
-
},
|
|
1528
|
-
],
|
|
1529
|
-
},
|
|
1530
|
-
},
|
|
1531
|
-
{
|
|
1532
|
-
name: 'QueueIndex',
|
|
1533
|
-
type: {
|
|
1534
|
-
kind: 'struct',
|
|
1535
|
-
fields: [
|
|
1536
|
-
{
|
|
1537
|
-
name: 'queueId',
|
|
1538
|
-
docs: ['Id of queue in queue account.'],
|
|
1539
|
-
type: 'u8',
|
|
1540
|
-
},
|
|
1541
|
-
{
|
|
1542
|
-
name: 'index',
|
|
1543
|
-
docs: ['Index of compressed account hash in queue.'],
|
|
1544
|
-
type: 'u16',
|
|
1545
|
-
},
|
|
1546
|
-
],
|
|
1547
|
-
},
|
|
1548
|
-
},
|
|
1549
|
-
{
|
|
1550
|
-
name: 'RolloverMetadata',
|
|
1551
|
-
type: {
|
|
1552
|
-
kind: 'struct',
|
|
1553
|
-
fields: [
|
|
1554
|
-
{
|
|
1555
|
-
name: 'index',
|
|
1556
|
-
docs: ['Unique index.'],
|
|
1557
|
-
type: 'u64',
|
|
1558
|
-
},
|
|
1559
|
-
{
|
|
1560
|
-
name: 'rolloverFee',
|
|
1561
|
-
docs: [
|
|
1562
|
-
'This fee is used for rent for the next account.',
|
|
1563
|
-
'It accumulates in the account so that once the corresponding Merkle tree account is full it can be rolled over',
|
|
1564
|
-
],
|
|
1565
|
-
type: 'u64',
|
|
1566
|
-
},
|
|
1567
|
-
{
|
|
1568
|
-
name: 'rolloverThreshold',
|
|
1569
|
-
docs: [
|
|
1570
|
-
'The threshold in percentage points when the account should be rolled over (95 corresponds to 95% filled).',
|
|
1571
|
-
],
|
|
1572
|
-
type: 'u64',
|
|
1573
|
-
},
|
|
1574
|
-
{
|
|
1575
|
-
name: 'networkFee',
|
|
1576
|
-
docs: ['Tip for maintaining the account.'],
|
|
1577
|
-
type: 'u64',
|
|
1578
|
-
},
|
|
1579
|
-
{
|
|
1580
|
-
name: 'rolledoverSlot',
|
|
1581
|
-
docs: [
|
|
1582
|
-
'The slot when the account was rolled over, a rolled over account should not be written to.',
|
|
1583
|
-
],
|
|
1584
|
-
type: 'u64',
|
|
1585
|
-
},
|
|
1586
|
-
{
|
|
1587
|
-
name: 'closeThreshold',
|
|
1588
|
-
docs: [
|
|
1589
|
-
'If current slot is greater than rolledover_slot + close_threshold and',
|
|
1590
|
-
"the account is empty it can be closed. No 'close' functionality has been",
|
|
1591
|
-
'implemented yet.',
|
|
1592
|
-
],
|
|
1593
|
-
type: 'u64',
|
|
1594
|
-
},
|
|
1595
|
-
{
|
|
1596
|
-
name: 'additionalBytes',
|
|
1597
|
-
docs: [
|
|
1598
|
-
'Placeholder for bytes of additional accounts which are tied to the',
|
|
1599
|
-
'Merkle trees operation and need to be rolled over as well.',
|
|
1600
|
-
],
|
|
1601
|
-
type: 'u64',
|
|
1602
|
-
},
|
|
1603
|
-
],
|
|
1604
|
-
},
|
|
1605
|
-
},
|
|
1606
|
-
{
|
|
1607
|
-
name: 'TokenData',
|
|
1608
|
-
type: {
|
|
1609
|
-
kind: 'struct',
|
|
1610
|
-
fields: [
|
|
1611
|
-
{
|
|
1612
|
-
name: 'mint',
|
|
1613
|
-
docs: ['The mint associated with this account'],
|
|
1614
|
-
type: 'publicKey',
|
|
1615
|
-
},
|
|
1616
|
-
{
|
|
1617
|
-
name: 'owner',
|
|
1618
|
-
docs: ['The owner of this account.'],
|
|
1619
|
-
type: 'publicKey',
|
|
1620
|
-
},
|
|
1621
|
-
{
|
|
1622
|
-
name: 'amount',
|
|
1623
|
-
docs: ['The amount of tokens this account holds.'],
|
|
1624
|
-
type: 'u64',
|
|
1625
|
-
},
|
|
1626
|
-
{
|
|
1627
|
-
name: 'delegate',
|
|
1628
|
-
docs: [
|
|
1629
|
-
'If `delegate` is `Some` then `delegated_amount` represents',
|
|
1630
|
-
'the amount authorized by the delegate',
|
|
1631
|
-
],
|
|
1632
|
-
type: {
|
|
1633
|
-
option: 'publicKey',
|
|
1634
|
-
},
|
|
1635
|
-
},
|
|
1636
|
-
{
|
|
1637
|
-
name: 'state',
|
|
1638
|
-
docs: ["The account's state"],
|
|
1639
|
-
type: {
|
|
1640
|
-
defined: 'AccountState',
|
|
1641
|
-
},
|
|
1642
|
-
},
|
|
1643
|
-
{
|
|
1644
|
-
name: 'tlv',
|
|
1645
|
-
docs: [
|
|
1646
|
-
'Placeholder for TokenExtension tlv data (unimplemented)',
|
|
1647
|
-
],
|
|
1648
|
-
type: {
|
|
1649
|
-
option: 'bytes',
|
|
1650
|
-
},
|
|
1651
|
-
},
|
|
1652
|
-
],
|
|
1653
|
-
},
|
|
1654
|
-
},
|
|
1655
|
-
],
|
|
1656
|
-
errors: [
|
|
1657
|
-
{
|
|
1658
|
-
code: 6000,
|
|
1659
|
-
name: 'PublicKeyAmountMissmatch',
|
|
1660
|
-
msg: 'public keys and amounts must be of same length',
|
|
1661
|
-
},
|
|
1662
|
-
{
|
|
1663
|
-
code: 6001,
|
|
1664
|
-
name: 'ComputeInputSumFailed',
|
|
1665
|
-
msg: 'ComputeInputSumFailed',
|
|
1666
|
-
},
|
|
1667
|
-
{
|
|
1668
|
-
code: 6002,
|
|
1669
|
-
name: 'ComputeOutputSumFailed',
|
|
1670
|
-
msg: 'ComputeOutputSumFailed',
|
|
1671
|
-
},
|
|
1672
|
-
{
|
|
1673
|
-
code: 6003,
|
|
1674
|
-
name: 'ComputeCompressSumFailed',
|
|
1675
|
-
msg: 'ComputeCompressSumFailed',
|
|
1676
|
-
},
|
|
1677
|
-
{
|
|
1678
|
-
code: 6004,
|
|
1679
|
-
name: 'ComputeDecompressSumFailed',
|
|
1680
|
-
msg: 'ComputeDecompressSumFailed',
|
|
1681
|
-
},
|
|
1682
|
-
{
|
|
1683
|
-
code: 6005,
|
|
1684
|
-
name: 'SumCheckFailed',
|
|
1685
|
-
msg: 'SumCheckFailed',
|
|
1686
|
-
},
|
|
1687
|
-
{
|
|
1688
|
-
code: 6006,
|
|
1689
|
-
name: 'DecompressRecipientUndefinedForDecompress',
|
|
1690
|
-
msg: 'DecompressRecipientUndefinedForDecompress',
|
|
1691
|
-
},
|
|
1692
|
-
{
|
|
1693
|
-
code: 6007,
|
|
1694
|
-
name: 'CompressedPdaUndefinedForDecompress',
|
|
1695
|
-
msg: 'CompressedPdaUndefinedForDecompress',
|
|
1696
|
-
},
|
|
1697
|
-
{
|
|
1698
|
-
code: 6008,
|
|
1699
|
-
name: 'DeCompressAmountUndefinedForDecompress',
|
|
1700
|
-
msg: 'DeCompressAmountUndefinedForDecompress',
|
|
1701
|
-
},
|
|
1702
|
-
{
|
|
1703
|
-
code: 6009,
|
|
1704
|
-
name: 'CompressedPdaUndefinedForCompress',
|
|
1705
|
-
msg: 'CompressedPdaUndefinedForCompress',
|
|
1706
|
-
},
|
|
1707
|
-
{
|
|
1708
|
-
code: 6010,
|
|
1709
|
-
name: 'DeCompressAmountUndefinedForCompress',
|
|
1710
|
-
msg: 'DeCompressAmountUndefinedForCompress',
|
|
1711
|
-
},
|
|
1712
|
-
{
|
|
1713
|
-
code: 6011,
|
|
1714
|
-
name: 'DelegateSignerCheckFailed',
|
|
1715
|
-
msg: 'DelegateSignerCheckFailed',
|
|
1716
|
-
},
|
|
1717
|
-
{
|
|
1718
|
-
code: 6012,
|
|
1719
|
-
name: 'MintTooLarge',
|
|
1720
|
-
msg: 'Minted amount greater than u64::MAX',
|
|
1721
|
-
},
|
|
1722
|
-
{
|
|
1723
|
-
code: 6013,
|
|
1724
|
-
name: 'SplTokenSupplyMismatch',
|
|
1725
|
-
msg: 'SplTokenSupplyMismatch',
|
|
1726
|
-
},
|
|
1727
|
-
{
|
|
1728
|
-
code: 6014,
|
|
1729
|
-
name: 'HeapMemoryCheckFailed',
|
|
1730
|
-
msg: 'HeapMemoryCheckFailed',
|
|
1731
|
-
},
|
|
1732
|
-
{
|
|
1733
|
-
code: 6015,
|
|
1734
|
-
name: 'InstructionNotCallable',
|
|
1735
|
-
msg: 'The instruction is not callable',
|
|
1736
|
-
},
|
|
1737
|
-
{
|
|
1738
|
-
code: 6016,
|
|
1739
|
-
name: 'ArithmeticUnderflow',
|
|
1740
|
-
msg: 'ArithmeticUnderflow',
|
|
1741
|
-
},
|
|
1742
|
-
{
|
|
1743
|
-
code: 6017,
|
|
1744
|
-
name: 'HashToFieldError',
|
|
1745
|
-
msg: 'HashToFieldError',
|
|
1746
|
-
},
|
|
1747
|
-
{
|
|
1748
|
-
code: 6018,
|
|
1749
|
-
name: 'InvalidAuthorityMint',
|
|
1750
|
-
msg: 'Expected the authority to be also a mint authority',
|
|
1751
|
-
},
|
|
1752
|
-
{
|
|
1753
|
-
code: 6019,
|
|
1754
|
-
name: 'InvalidFreezeAuthority',
|
|
1755
|
-
msg: 'Provided authority is not the freeze authority',
|
|
1756
|
-
},
|
|
1757
|
-
{
|
|
1758
|
-
code: 6020,
|
|
1759
|
-
name: 'InvalidDelegateIndex',
|
|
1760
|
-
},
|
|
1761
|
-
{
|
|
1762
|
-
code: 6021,
|
|
1763
|
-
name: 'TokenPoolPdaUndefined',
|
|
1764
|
-
},
|
|
1765
|
-
{
|
|
1766
|
-
code: 6022,
|
|
1767
|
-
name: 'IsTokenPoolPda',
|
|
1768
|
-
msg: 'Compress or decompress recipient is the same account as the token pool pda.',
|
|
1769
|
-
},
|
|
1770
|
-
{
|
|
1771
|
-
code: 6023,
|
|
1772
|
-
name: 'InvalidTokenPoolPda',
|
|
1773
|
-
},
|
|
1774
|
-
{
|
|
1775
|
-
code: 6024,
|
|
1776
|
-
name: 'NoInputTokenAccountsProvided',
|
|
1777
|
-
},
|
|
1778
|
-
{
|
|
1779
|
-
code: 6025,
|
|
1780
|
-
name: 'NoInputsProvided',
|
|
1781
|
-
},
|
|
1782
|
-
{
|
|
1783
|
-
code: 6026,
|
|
1784
|
-
name: 'MintHasNoFreezeAuthority',
|
|
1785
|
-
},
|
|
1786
|
-
{
|
|
1787
|
-
code: 6027,
|
|
1788
|
-
name: 'MintWithInvalidExtension',
|
|
1789
|
-
},
|
|
1790
|
-
{
|
|
1791
|
-
code: 6028,
|
|
1792
|
-
name: 'InsufficientTokenAccountBalance',
|
|
1793
|
-
msg: 'The token account balance is less than the remaining amount.',
|
|
1794
|
-
},
|
|
1795
|
-
],
|
|
1796
|
-
};
|
|
1797
|
-
|
|
1798
|
-
// TODO: include owner and lamports in packing.
|
|
1799
|
-
/**
|
|
1800
|
-
* Packs Compressed Token Accounts.
|
|
1801
|
-
*/
|
|
1802
|
-
function packCompressedTokenAccounts(params) {
|
|
1803
|
-
const { inputCompressedTokenAccounts, outputStateTrees, remainingAccounts = [], rootIndices, tokenTransferOutputs, } = params;
|
|
1804
|
-
const _remainingAccounts = remainingAccounts.slice();
|
|
1805
|
-
let delegateIndex = null;
|
|
1806
|
-
if (inputCompressedTokenAccounts.length > 0 &&
|
|
1807
|
-
inputCompressedTokenAccounts[0].parsed.delegate) {
|
|
1808
|
-
delegateIndex = getIndexOrAdd(_remainingAccounts, inputCompressedTokenAccounts[0].parsed.delegate);
|
|
1809
|
-
}
|
|
1810
|
-
/// TODO: move pubkeyArray to remainingAccounts
|
|
1811
|
-
/// Currently just packs 'delegate' to pubkeyArray
|
|
1812
|
-
const packedInputTokenData = [];
|
|
1813
|
-
/// pack inputs
|
|
1814
|
-
inputCompressedTokenAccounts.forEach((account, index) => {
|
|
1815
|
-
const merkleTreePubkeyIndex = getIndexOrAdd(_remainingAccounts, account.compressedAccount.merkleTree);
|
|
1816
|
-
const nullifierQueuePubkeyIndex = getIndexOrAdd(_remainingAccounts, account.compressedAccount.nullifierQueue);
|
|
1817
|
-
packedInputTokenData.push({
|
|
1818
|
-
amount: account.parsed.amount,
|
|
1819
|
-
delegateIndex,
|
|
1820
|
-
merkleContext: {
|
|
1821
|
-
merkleTreePubkeyIndex,
|
|
1822
|
-
nullifierQueuePubkeyIndex,
|
|
1823
|
-
leafIndex: account.compressedAccount.leafIndex,
|
|
1824
|
-
queueIndex: null,
|
|
1825
|
-
},
|
|
1826
|
-
rootIndex: rootIndices[index],
|
|
1827
|
-
lamports: account.compressedAccount.lamports.eq(bn(0))
|
|
1828
|
-
? null
|
|
1829
|
-
: account.compressedAccount.lamports,
|
|
1830
|
-
tlv: null,
|
|
1831
|
-
});
|
|
1832
|
-
});
|
|
1833
|
-
/// pack output state trees
|
|
1834
|
-
const paddedOutputStateMerkleTrees = padOutputStateMerkleTrees(outputStateTrees, tokenTransferOutputs.length, inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1835
|
-
const packedOutputTokenData = [];
|
|
1836
|
-
paddedOutputStateMerkleTrees.forEach((account, index) => {
|
|
1837
|
-
const merkleTreeIndex = getIndexOrAdd(_remainingAccounts, account);
|
|
1838
|
-
packedOutputTokenData.push({
|
|
1839
|
-
owner: tokenTransferOutputs[index].owner,
|
|
1840
|
-
amount: tokenTransferOutputs[index].amount,
|
|
1841
|
-
lamports: tokenTransferOutputs[index].lamports?.eq(bn(0))
|
|
1842
|
-
? null
|
|
1843
|
-
: tokenTransferOutputs[index].lamports,
|
|
1844
|
-
merkleTreeIndex,
|
|
1845
|
-
tlv: null,
|
|
1846
|
-
});
|
|
1847
|
-
});
|
|
1848
|
-
// to meta
|
|
1849
|
-
const remainingAccountMetas = _remainingAccounts.map((account) => ({
|
|
1850
|
-
pubkey: account,
|
|
1851
|
-
isWritable: true,
|
|
1852
|
-
isSigner: false,
|
|
1853
|
-
}));
|
|
1854
|
-
return {
|
|
1855
|
-
inputTokenDataWithContext: packedInputTokenData,
|
|
1856
|
-
remainingAccountMetas,
|
|
1857
|
-
packedOutputTokenData,
|
|
1858
|
-
};
|
|
1859
|
-
}
|
|
1860
|
-
|
|
1861
|
-
const POOL_SEED = Buffer.from('pool');
|
|
1862
|
-
const CPI_AUTHORITY_SEED = Buffer.from('cpi_authority');
|
|
1863
|
-
const SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = 1461600;
|
|
1864
|
-
|
|
1865
|
-
/**
|
|
1866
|
-
* Sum up the token amounts of the compressed token accounts
|
|
1867
|
-
*/
|
|
1868
|
-
const sumUpTokenAmount = (accounts) => {
|
|
1869
|
-
return accounts.reduce((acc, account) => acc.add(account.parsed.amount), bn(0));
|
|
1870
|
-
};
|
|
1871
|
-
/**
|
|
1872
|
-
* Validate that all the compressed token accounts are owned by the same owner.
|
|
1873
|
-
*/
|
|
1874
|
-
const validateSameTokenOwner = (accounts) => {
|
|
1875
|
-
const owner = accounts[0].parsed.owner;
|
|
1876
|
-
accounts.forEach(acc => {
|
|
1877
|
-
if (!acc.parsed.owner.equals(owner)) {
|
|
1878
|
-
throw new Error('Token accounts must be owned by the same owner');
|
|
1879
|
-
}
|
|
1880
|
-
});
|
|
1881
|
-
};
|
|
1882
|
-
/**
|
|
1883
|
-
* Parse compressed token accounts to get the mint, current owner and delegate.
|
|
1884
|
-
*/
|
|
1885
|
-
const parseTokenData = (compressedTokenAccounts) => {
|
|
1886
|
-
const mint = compressedTokenAccounts[0].parsed.mint;
|
|
1887
|
-
const currentOwner = compressedTokenAccounts[0].parsed.owner;
|
|
1888
|
-
const delegate = compressedTokenAccounts[0].parsed.delegate;
|
|
1889
|
-
return { mint, currentOwner, delegate };
|
|
1890
|
-
};
|
|
1891
|
-
/**
|
|
1892
|
-
* Create the output state for a transfer transaction.
|
|
1893
|
-
* @param inputCompressedTokenAccounts Input state
|
|
1894
|
-
* @param toAddress Recipient address
|
|
1895
|
-
* @param amount Amount of tokens to transfer
|
|
1896
|
-
* @returns Output token data for the transfer
|
|
1897
|
-
* instruction
|
|
1898
|
-
*/
|
|
1899
|
-
function createTransferOutputState(inputCompressedTokenAccounts, toAddress, amount) {
|
|
1900
|
-
amount = bn(amount);
|
|
1901
|
-
const inputAmount = sumUpTokenAmount(inputCompressedTokenAccounts);
|
|
1902
|
-
const inputLamports = sumUpLamports(inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1903
|
-
const changeAmount = inputAmount.sub(amount);
|
|
1904
|
-
validateSufficientBalance(changeAmount);
|
|
1905
|
-
if (changeAmount.eq(bn(0)) && inputLamports.eq(bn(0))) {
|
|
1906
|
-
return [
|
|
1907
|
-
{
|
|
1908
|
-
owner: toAddress,
|
|
1909
|
-
amount,
|
|
1910
|
-
lamports: inputLamports,
|
|
1911
|
-
tlv: null,
|
|
1912
|
-
},
|
|
1913
|
-
];
|
|
1914
|
-
}
|
|
1915
|
-
/// validates token program
|
|
1916
|
-
validateSameOwner(inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1917
|
-
validateSameTokenOwner(inputCompressedTokenAccounts);
|
|
1918
|
-
const outputCompressedAccounts = [
|
|
1919
|
-
{
|
|
1920
|
-
owner: inputCompressedTokenAccounts[0].parsed.owner,
|
|
1921
|
-
amount: changeAmount,
|
|
1922
|
-
lamports: inputLamports,
|
|
1923
|
-
tlv: null,
|
|
1924
|
-
},
|
|
1925
|
-
{
|
|
1926
|
-
owner: toAddress,
|
|
1927
|
-
amount,
|
|
1928
|
-
lamports: bn(0),
|
|
1929
|
-
tlv: null,
|
|
1930
|
-
},
|
|
1931
|
-
];
|
|
1932
|
-
return outputCompressedAccounts;
|
|
1933
|
-
}
|
|
1934
|
-
/**
|
|
1935
|
-
* Create the output state for a compress transaction.
|
|
1936
|
-
* @param inputCompressedTokenAccounts Input state
|
|
1937
|
-
* @param amount Amount of tokens to compress
|
|
1938
|
-
* @returns Output token data for the compress
|
|
1939
|
-
* instruction
|
|
1940
|
-
*/
|
|
1941
|
-
function createDecompressOutputState(inputCompressedTokenAccounts, amount) {
|
|
1942
|
-
amount = bn(amount);
|
|
1943
|
-
const inputLamports = sumUpLamports(inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1944
|
-
const inputAmount = sumUpTokenAmount(inputCompressedTokenAccounts);
|
|
1945
|
-
const changeAmount = inputAmount.sub(amount);
|
|
1946
|
-
validateSufficientBalance(changeAmount);
|
|
1947
|
-
/// lamports gets decompressed
|
|
1948
|
-
if (changeAmount.eq(bn(0)) && inputLamports.eq(bn(0))) {
|
|
1949
|
-
return [];
|
|
1950
|
-
}
|
|
1951
|
-
validateSameOwner(inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1952
|
-
validateSameTokenOwner(inputCompressedTokenAccounts);
|
|
1953
|
-
const tokenTransferOutputs = [
|
|
1954
|
-
{
|
|
1955
|
-
owner: inputCompressedTokenAccounts[0].parsed.owner,
|
|
1956
|
-
amount: changeAmount,
|
|
1957
|
-
lamports: inputLamports,
|
|
1958
|
-
tlv: null,
|
|
1959
|
-
},
|
|
1960
|
-
];
|
|
1961
|
-
return tokenTransferOutputs;
|
|
1962
|
-
}
|
|
1963
|
-
class CompressedTokenProgram {
|
|
1964
|
-
/**
|
|
1965
|
-
* @internal
|
|
1966
|
-
*/
|
|
1967
|
-
constructor() { }
|
|
1968
|
-
/**
|
|
1969
|
-
* Public key that identifies the CompressedPda program
|
|
1970
|
-
*/
|
|
1971
|
-
static programId = new PublicKey('cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m');
|
|
1972
|
-
/**
|
|
1973
|
-
* Set a custom programId via PublicKey or base58 encoded string.
|
|
1974
|
-
* This method is not required for regular usage.
|
|
1975
|
-
*
|
|
1976
|
-
* Use this only if you know what you are doing.
|
|
1977
|
-
*/
|
|
1978
|
-
static setProgramId(programId) {
|
|
1979
|
-
this.programId =
|
|
1980
|
-
typeof programId === 'string'
|
|
1981
|
-
? new PublicKey(programId)
|
|
1982
|
-
: programId;
|
|
1983
|
-
// Reset program when programId changes
|
|
1984
|
-
this._program = null;
|
|
1985
|
-
}
|
|
1986
|
-
static _program = null;
|
|
1987
|
-
/** @internal */
|
|
1988
|
-
static get program() {
|
|
1989
|
-
if (!this._program) {
|
|
1990
|
-
this.initializeProgram();
|
|
1991
|
-
}
|
|
1992
|
-
return this._program;
|
|
1993
|
-
}
|
|
1994
|
-
/**
|
|
1995
|
-
* @internal
|
|
1996
|
-
* Initializes the program statically if not already initialized.
|
|
1997
|
-
*/
|
|
1998
|
-
static initializeProgram() {
|
|
1999
|
-
if (!this._program) {
|
|
2000
|
-
/// Note: We can use a mock connection because we're using the
|
|
2001
|
-
/// program only for serde and building instructions, not for
|
|
2002
|
-
/// interacting with the network.
|
|
2003
|
-
const mockKeypair = Keypair.generate();
|
|
2004
|
-
const mockConnection = new Connection('http://127.0.0.1:8899', 'confirmed');
|
|
2005
|
-
const mockProvider = new AnchorProvider(mockConnection, useWallet(mockKeypair), confirmConfig);
|
|
2006
|
-
setProvider(mockProvider);
|
|
2007
|
-
this._program = new Program(IDL, this.programId, mockProvider);
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
/** @internal */
|
|
2011
|
-
static deriveTokenPoolPda(mint) {
|
|
2012
|
-
const seeds = [POOL_SEED, mint.toBuffer()];
|
|
2013
|
-
const [address, _] = PublicKey.findProgramAddressSync(seeds, this.programId);
|
|
2014
|
-
return address;
|
|
2015
|
-
}
|
|
2016
|
-
/** @internal */
|
|
2017
|
-
static get deriveCpiAuthorityPda() {
|
|
2018
|
-
const [address, _] = PublicKey.findProgramAddressSync([CPI_AUTHORITY_SEED], this.programId);
|
|
2019
|
-
return address;
|
|
2020
|
-
}
|
|
2021
|
-
/**
|
|
2022
|
-
* Construct createMint instruction for compressed tokens
|
|
2023
|
-
*/
|
|
2024
|
-
static async createMint(params) {
|
|
2025
|
-
const { mint, authority, feePayer, rentExemptBalance, tokenProgramId, freezeAuthority, mintSize, } = params;
|
|
2026
|
-
const tokenProgram = tokenProgramId ?? TOKEN_PROGRAM_ID;
|
|
2027
|
-
/// Create and initialize SPL Mint account
|
|
2028
|
-
const createMintAccountInstruction = SystemProgram.createAccount({
|
|
2029
|
-
fromPubkey: feePayer,
|
|
2030
|
-
lamports: rentExemptBalance,
|
|
2031
|
-
newAccountPubkey: mint,
|
|
2032
|
-
programId: tokenProgram,
|
|
2033
|
-
space: mintSize ?? MINT_SIZE,
|
|
2034
|
-
});
|
|
2035
|
-
const initializeMintInstruction = createInitializeMint2Instruction(mint, params.decimals, authority, freezeAuthority, tokenProgram);
|
|
2036
|
-
const ix = await this.createTokenPool({
|
|
2037
|
-
feePayer,
|
|
2038
|
-
mint,
|
|
2039
|
-
tokenProgramId: tokenProgram,
|
|
2040
|
-
});
|
|
2041
|
-
return [createMintAccountInstruction, initializeMintInstruction, ix];
|
|
2042
|
-
}
|
|
2043
|
-
/**
|
|
2044
|
-
* Enable compression for an existing SPL mint, creating an omnibus account.
|
|
2045
|
-
* For new mints, use `CompressedTokenProgram.createMint`.
|
|
2046
|
-
*/
|
|
2047
|
-
static async createTokenPool(params) {
|
|
2048
|
-
const { mint, feePayer, tokenProgramId } = params;
|
|
2049
|
-
const tokenProgram = tokenProgramId ?? TOKEN_PROGRAM_ID;
|
|
2050
|
-
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
2051
|
-
const ix = await this.program.methods
|
|
2052
|
-
.createTokenPool()
|
|
2053
|
-
.accounts({
|
|
2054
|
-
mint,
|
|
2055
|
-
feePayer,
|
|
2056
|
-
tokenPoolPda,
|
|
2057
|
-
systemProgram: SystemProgram.programId,
|
|
2058
|
-
tokenProgram,
|
|
2059
|
-
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2060
|
-
})
|
|
2061
|
-
.instruction();
|
|
2062
|
-
return ix;
|
|
2063
|
-
}
|
|
2064
|
-
/**
|
|
2065
|
-
* Construct mintTo instruction for compressed tokens
|
|
2066
|
-
*/
|
|
2067
|
-
static async mintTo(params) {
|
|
2068
|
-
const systemKeys = defaultStaticAccountsStruct();
|
|
2069
|
-
const { mint, feePayer, authority, merkleTree, toPubkey, amount, tokenProgramId, } = params;
|
|
2070
|
-
const tokenProgram = tokenProgramId ?? TOKEN_PROGRAM_ID;
|
|
2071
|
-
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
2072
|
-
const amounts = toArray(amount).map(amount => bn(amount));
|
|
2073
|
-
const toPubkeys = toArray(toPubkey);
|
|
2074
|
-
if (amounts.length !== toPubkeys.length) {
|
|
2075
|
-
throw new Error('Amount and toPubkey arrays must have the same length');
|
|
2076
|
-
}
|
|
2077
|
-
const instruction = await this.program.methods
|
|
2078
|
-
.mintTo(toPubkeys, amounts, null)
|
|
2079
|
-
.accounts({
|
|
2080
|
-
feePayer,
|
|
2081
|
-
authority,
|
|
2082
|
-
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2083
|
-
mint,
|
|
2084
|
-
tokenPoolPda,
|
|
2085
|
-
tokenProgram,
|
|
2086
|
-
lightSystemProgram: LightSystemProgram.programId,
|
|
2087
|
-
registeredProgramPda: systemKeys.registeredProgramPda,
|
|
2088
|
-
noopProgram: systemKeys.noopProgram,
|
|
2089
|
-
accountCompressionAuthority: systemKeys.accountCompressionAuthority,
|
|
2090
|
-
accountCompressionProgram: systemKeys.accountCompressionProgram,
|
|
2091
|
-
merkleTree: merkleTree ?? defaultTestStateTreeAccounts().merkleTree,
|
|
2092
|
-
selfProgram: this.programId,
|
|
2093
|
-
solPoolPda: null,
|
|
2094
|
-
})
|
|
2095
|
-
.instruction();
|
|
2096
|
-
return instruction;
|
|
2097
|
-
}
|
|
2098
|
-
/**
|
|
2099
|
-
* Mint tokens from registered SPL mint account to a compressed account
|
|
2100
|
-
*/
|
|
2101
|
-
static async approveAndMintTo(params) {
|
|
2102
|
-
const { mint, feePayer, authorityTokenAccount, authority, merkleTree, toPubkey, tokenProgramId, } = params;
|
|
2103
|
-
const amount = BigInt(params.amount.toString());
|
|
2104
|
-
/// 1. Mint to existing ATA of mintAuthority.
|
|
2105
|
-
const splMintToInstruction = createMintToInstruction(mint, authorityTokenAccount, authority, amount, [], tokenProgramId);
|
|
2106
|
-
/// 2. Compress from mint authority ATA to recipient compressed account
|
|
2107
|
-
const compressInstruction = await this.compress({
|
|
2108
|
-
payer: feePayer,
|
|
2109
|
-
owner: authority,
|
|
2110
|
-
source: authorityTokenAccount,
|
|
2111
|
-
toAddress: toPubkey,
|
|
2112
|
-
mint,
|
|
2113
|
-
amount: params.amount,
|
|
2114
|
-
outputStateTree: merkleTree,
|
|
2115
|
-
tokenProgramId,
|
|
2116
|
-
});
|
|
2117
|
-
return [splMintToInstruction, compressInstruction];
|
|
2118
|
-
}
|
|
2119
|
-
/**
|
|
2120
|
-
* Construct transfer instruction for compressed tokens
|
|
2121
|
-
*/
|
|
2122
|
-
static async transfer(params) {
|
|
2123
|
-
const { payer, inputCompressedTokenAccounts, recentInputStateRootIndices, recentValidityProof, amount, outputStateTrees, toAddress, } = params;
|
|
2124
|
-
const tokenTransferOutputs = createTransferOutputState(inputCompressedTokenAccounts, toAddress, amount);
|
|
2125
|
-
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
2126
|
-
inputCompressedTokenAccounts,
|
|
2127
|
-
outputStateTrees,
|
|
2128
|
-
rootIndices: recentInputStateRootIndices,
|
|
2129
|
-
tokenTransferOutputs,
|
|
2130
|
-
});
|
|
2131
|
-
const { mint, currentOwner } = parseTokenData(inputCompressedTokenAccounts);
|
|
2132
|
-
const data = {
|
|
2133
|
-
proof: recentValidityProof,
|
|
2134
|
-
mint,
|
|
2135
|
-
delegatedTransfer: null, // TODO: implement
|
|
2136
|
-
inputTokenDataWithContext,
|
|
2137
|
-
outputCompressedAccounts: packedOutputTokenData,
|
|
2138
|
-
compressOrDecompressAmount: null,
|
|
2139
|
-
isCompress: false,
|
|
2140
|
-
cpiContext: null,
|
|
2141
|
-
lamportsChangeAccountMerkleTreeIndex: null,
|
|
2142
|
-
};
|
|
2143
|
-
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
2144
|
-
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = defaultStaticAccountsStruct();
|
|
2145
|
-
const instruction = await this.program.methods
|
|
2146
|
-
.transfer(encodedData)
|
|
2147
|
-
.accounts({
|
|
2148
|
-
feePayer: payer,
|
|
2149
|
-
authority: currentOwner,
|
|
2150
|
-
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2151
|
-
lightSystemProgram: LightSystemProgram.programId,
|
|
2152
|
-
registeredProgramPda: registeredProgramPda,
|
|
2153
|
-
noopProgram: noopProgram,
|
|
2154
|
-
accountCompressionAuthority: accountCompressionAuthority,
|
|
2155
|
-
accountCompressionProgram: accountCompressionProgram,
|
|
2156
|
-
selfProgram: this.programId,
|
|
2157
|
-
tokenPoolPda: null,
|
|
2158
|
-
compressOrDecompressTokenAccount: null,
|
|
2159
|
-
tokenProgram: null,
|
|
2160
|
-
})
|
|
2161
|
-
.remainingAccounts(remainingAccountMetas)
|
|
2162
|
-
.instruction();
|
|
2163
|
-
return instruction;
|
|
2164
|
-
}
|
|
2165
|
-
/**
|
|
2166
|
-
* Create lookup table instructions for the token program's default accounts.
|
|
2167
|
-
*/
|
|
2168
|
-
static async createTokenProgramLookupTable(params) {
|
|
2169
|
-
const { authority, mints, recentSlot, payer, remainingAccounts } = params;
|
|
2170
|
-
const [createInstruction, lookupTableAddress] = AddressLookupTableProgram.createLookupTable({
|
|
2171
|
-
authority,
|
|
2172
|
-
payer: authority,
|
|
2173
|
-
recentSlot,
|
|
2174
|
-
});
|
|
2175
|
-
let optionalMintKeys = [];
|
|
2176
|
-
if (mints) {
|
|
2177
|
-
optionalMintKeys = [
|
|
2178
|
-
...mints,
|
|
2179
|
-
...mints.map(mint => this.deriveTokenPoolPda(mint)),
|
|
2180
|
-
];
|
|
2181
|
-
}
|
|
2182
|
-
const extendInstruction = AddressLookupTableProgram.extendLookupTable({
|
|
2183
|
-
payer,
|
|
2184
|
-
authority,
|
|
2185
|
-
lookupTable: lookupTableAddress,
|
|
2186
|
-
addresses: [
|
|
2187
|
-
this.deriveCpiAuthorityPda,
|
|
2188
|
-
LightSystemProgram.programId,
|
|
2189
|
-
defaultStaticAccountsStruct().registeredProgramPda,
|
|
2190
|
-
defaultStaticAccountsStruct().noopProgram,
|
|
2191
|
-
defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
2192
|
-
defaultStaticAccountsStruct().accountCompressionProgram,
|
|
2193
|
-
defaultTestStateTreeAccounts().merkleTree,
|
|
2194
|
-
defaultTestStateTreeAccounts().nullifierQueue,
|
|
2195
|
-
defaultTestStateTreeAccounts().addressTree,
|
|
2196
|
-
defaultTestStateTreeAccounts().addressQueue,
|
|
2197
|
-
this.programId,
|
|
2198
|
-
TOKEN_PROGRAM_ID,
|
|
2199
|
-
TOKEN_2022_PROGRAM_ID,
|
|
2200
|
-
authority,
|
|
2201
|
-
...optionalMintKeys,
|
|
2202
|
-
...(remainingAccounts ?? []),
|
|
2203
|
-
],
|
|
2204
|
-
});
|
|
2205
|
-
return {
|
|
2206
|
-
instructions: [createInstruction, extendInstruction],
|
|
2207
|
-
address: lookupTableAddress,
|
|
2208
|
-
};
|
|
2209
|
-
}
|
|
2210
|
-
/**
|
|
2211
|
-
* Create compress instruction
|
|
2212
|
-
* @returns compressInstruction
|
|
2213
|
-
*/
|
|
2214
|
-
static async compress(params) {
|
|
2215
|
-
const { payer, owner, source, toAddress, mint, outputStateTree, tokenProgramId, } = params;
|
|
2216
|
-
if (Array.isArray(params.amount) !== Array.isArray(params.toAddress)) {
|
|
2217
|
-
throw new Error('Both amount and toAddress must be arrays or both must be single values');
|
|
2218
|
-
}
|
|
2219
|
-
let tokenTransferOutputs;
|
|
2220
|
-
if (Array.isArray(params.amount) && Array.isArray(params.toAddress)) {
|
|
2221
|
-
if (params.amount.length !== params.toAddress.length) {
|
|
2222
|
-
throw new Error('Amount and toAddress arrays must have the same length');
|
|
2223
|
-
}
|
|
2224
|
-
tokenTransferOutputs = params.amount.map((amt, index) => {
|
|
2225
|
-
const amount = bn(amt);
|
|
2226
|
-
return {
|
|
2227
|
-
owner: params.toAddress[index],
|
|
2228
|
-
amount,
|
|
2229
|
-
lamports: bn(0),
|
|
2230
|
-
tlv: null,
|
|
2231
|
-
};
|
|
2232
|
-
});
|
|
2233
|
-
}
|
|
2234
|
-
else {
|
|
2235
|
-
tokenTransferOutputs = [
|
|
2236
|
-
{
|
|
2237
|
-
owner: toAddress,
|
|
2238
|
-
amount: bn(params.amount),
|
|
2239
|
-
lamports: bn(0),
|
|
2240
|
-
tlv: null,
|
|
2241
|
-
},
|
|
2242
|
-
];
|
|
2243
|
-
}
|
|
2244
|
-
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
2245
|
-
inputCompressedTokenAccounts: [],
|
|
2246
|
-
outputStateTrees: outputStateTree,
|
|
2247
|
-
rootIndices: [],
|
|
2248
|
-
tokenTransferOutputs,
|
|
2249
|
-
});
|
|
2250
|
-
const data = {
|
|
2251
|
-
proof: null,
|
|
2252
|
-
mint,
|
|
2253
|
-
delegatedTransfer: null, // TODO: implement
|
|
2254
|
-
inputTokenDataWithContext,
|
|
2255
|
-
outputCompressedAccounts: packedOutputTokenData,
|
|
2256
|
-
compressOrDecompressAmount: Array.isArray(params.amount)
|
|
2257
|
-
? params.amount
|
|
2258
|
-
.map(amt => new BN(amt))
|
|
2259
|
-
.reduce((sum, amt) => sum.add(amt), new BN(0))
|
|
2260
|
-
: new BN(params.amount),
|
|
2261
|
-
isCompress: true,
|
|
2262
|
-
cpiContext: null,
|
|
2263
|
-
lamportsChangeAccountMerkleTreeIndex: null,
|
|
2264
|
-
};
|
|
2265
|
-
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
2266
|
-
const tokenProgram = tokenProgramId ?? TOKEN_PROGRAM_ID;
|
|
2267
|
-
const instruction = await this.program.methods
|
|
2268
|
-
.transfer(encodedData)
|
|
2269
|
-
.accounts({
|
|
2270
|
-
feePayer: payer,
|
|
2271
|
-
authority: owner,
|
|
2272
|
-
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2273
|
-
lightSystemProgram: LightSystemProgram.programId,
|
|
2274
|
-
registeredProgramPda: defaultStaticAccountsStruct().registeredProgramPda,
|
|
2275
|
-
noopProgram: defaultStaticAccountsStruct().noopProgram,
|
|
2276
|
-
accountCompressionAuthority: defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
2277
|
-
accountCompressionProgram: defaultStaticAccountsStruct().accountCompressionProgram,
|
|
2278
|
-
selfProgram: this.programId,
|
|
2279
|
-
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2280
|
-
compressOrDecompressTokenAccount: source, // token
|
|
2281
|
-
tokenProgram,
|
|
2282
|
-
})
|
|
2283
|
-
.remainingAccounts(remainingAccountMetas)
|
|
2284
|
-
.instruction();
|
|
2285
|
-
return instruction;
|
|
2286
|
-
}
|
|
2287
|
-
/**
|
|
2288
|
-
* Construct decompress instruction
|
|
2289
|
-
*/
|
|
2290
|
-
static async decompress(params) {
|
|
2291
|
-
const { payer, inputCompressedTokenAccounts, toAddress, outputStateTree, recentValidityProof, recentInputStateRootIndices, tokenProgramId, } = params;
|
|
2292
|
-
const amount = bn(params.amount);
|
|
2293
|
-
const tokenTransferOutputs = createDecompressOutputState(inputCompressedTokenAccounts, amount);
|
|
2294
|
-
/// Pack
|
|
2295
|
-
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
2296
|
-
inputCompressedTokenAccounts,
|
|
2297
|
-
outputStateTrees: outputStateTree,
|
|
2298
|
-
rootIndices: recentInputStateRootIndices,
|
|
2299
|
-
tokenTransferOutputs: tokenTransferOutputs,
|
|
2300
|
-
});
|
|
2301
|
-
const { mint, currentOwner } = parseTokenData(inputCompressedTokenAccounts);
|
|
2302
|
-
const data = {
|
|
2303
|
-
proof: recentValidityProof,
|
|
2304
|
-
mint,
|
|
2305
|
-
delegatedTransfer: null, // TODO: implement
|
|
2306
|
-
inputTokenDataWithContext,
|
|
2307
|
-
outputCompressedAccounts: packedOutputTokenData,
|
|
2308
|
-
compressOrDecompressAmount: amount,
|
|
2309
|
-
isCompress: false,
|
|
2310
|
-
cpiContext: null,
|
|
2311
|
-
lamportsChangeAccountMerkleTreeIndex: null,
|
|
2312
|
-
};
|
|
2313
|
-
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
2314
|
-
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = defaultStaticAccountsStruct();
|
|
2315
|
-
const tokenProgram = tokenProgramId ?? TOKEN_PROGRAM_ID;
|
|
2316
|
-
const instruction = await this.program.methods
|
|
2317
|
-
.transfer(encodedData)
|
|
2318
|
-
.accounts({
|
|
2319
|
-
feePayer: payer,
|
|
2320
|
-
authority: currentOwner,
|
|
2321
|
-
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2322
|
-
lightSystemProgram: LightSystemProgram.programId,
|
|
2323
|
-
registeredProgramPda: registeredProgramPda,
|
|
2324
|
-
noopProgram: noopProgram,
|
|
2325
|
-
accountCompressionAuthority: accountCompressionAuthority,
|
|
2326
|
-
accountCompressionProgram: accountCompressionProgram,
|
|
2327
|
-
selfProgram: this.programId,
|
|
2328
|
-
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2329
|
-
compressOrDecompressTokenAccount: toAddress,
|
|
2330
|
-
tokenProgram,
|
|
2331
|
-
})
|
|
2332
|
-
.remainingAccounts(remainingAccountMetas)
|
|
2333
|
-
.instruction();
|
|
2334
|
-
return instruction;
|
|
2335
|
-
}
|
|
2336
|
-
static async mergeTokenAccounts(params) {
|
|
2337
|
-
const { payer, owner, inputCompressedTokenAccounts, outputStateTree, recentValidityProof, recentInputStateRootIndices, } = params;
|
|
2338
|
-
if (inputCompressedTokenAccounts.length > 3) {
|
|
2339
|
-
throw new Error('Cannot merge more than 3 token accounts at once');
|
|
2340
|
-
}
|
|
2341
|
-
const ix = await this.transfer({
|
|
2342
|
-
payer,
|
|
2343
|
-
inputCompressedTokenAccounts,
|
|
2344
|
-
toAddress: owner,
|
|
2345
|
-
amount: inputCompressedTokenAccounts.reduce((sum, account) => sum.add(account.parsed.amount), new BN(0)),
|
|
2346
|
-
outputStateTrees: outputStateTree,
|
|
2347
|
-
recentInputStateRootIndices,
|
|
2348
|
-
recentValidityProof,
|
|
2349
|
-
});
|
|
2350
|
-
return [ix];
|
|
2351
|
-
}
|
|
2352
|
-
static async compressSplTokenAccount(params) {
|
|
2353
|
-
const { feePayer, authority, tokenAccount, mint, remainingAmount, outputStateTree, tokenProgramId, } = params;
|
|
2354
|
-
const tokenProgram = tokenProgramId ?? TOKEN_PROGRAM_ID;
|
|
2355
|
-
const remainingAccountMetas = [
|
|
2356
|
-
{
|
|
2357
|
-
pubkey: outputStateTree,
|
|
2358
|
-
isSigner: false,
|
|
2359
|
-
isWritable: true,
|
|
2360
|
-
},
|
|
2361
|
-
];
|
|
2362
|
-
const instruction = await this.program.methods
|
|
2363
|
-
.compressSplTokenAccount(authority, remainingAmount ?? null, null)
|
|
2364
|
-
.accounts({
|
|
2365
|
-
feePayer,
|
|
2366
|
-
authority,
|
|
2367
|
-
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
2368
|
-
lightSystemProgram: LightSystemProgram.programId,
|
|
2369
|
-
registeredProgramPda: defaultStaticAccountsStruct().registeredProgramPda,
|
|
2370
|
-
noopProgram: defaultStaticAccountsStruct().noopProgram,
|
|
2371
|
-
accountCompressionAuthority: defaultStaticAccountsStruct().accountCompressionAuthority,
|
|
2372
|
-
accountCompressionProgram: defaultStaticAccountsStruct().accountCompressionProgram,
|
|
2373
|
-
selfProgram: this.programId,
|
|
2374
|
-
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
2375
|
-
compressOrDecompressTokenAccount: tokenAccount,
|
|
2376
|
-
tokenProgram,
|
|
2377
|
-
systemProgram: SystemProgram.programId,
|
|
2378
|
-
})
|
|
2379
|
-
.remainingAccounts(remainingAccountMetas)
|
|
2380
|
-
.instruction();
|
|
2381
|
-
return instruction;
|
|
2382
|
-
}
|
|
2383
|
-
static async get_mint_program_id(mint, connection) {
|
|
2384
|
-
return (await connection.getAccountInfo(mint))?.owner;
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
|
-
/**
|
|
2389
|
-
* Mint compressed tokens to a solana address from an external mint authority
|
|
2390
|
-
*
|
|
2391
|
-
* @param rpc Rpc to use
|
|
2392
|
-
* @param payer Payer of the transaction fees
|
|
2393
|
-
* @param mint Mint for the account
|
|
2394
|
-
* @param destination Address of the account to mint to
|
|
2395
|
-
* @param authority Minting authority
|
|
2396
|
-
* @param amount Amount to mint
|
|
2397
|
-
* @param merkleTree State tree account that the compressed tokens should be
|
|
2398
|
-
* part of. Defaults to the default state tree account.
|
|
2399
|
-
* @param confirmOptions Options for confirming the transaction
|
|
2400
|
-
*
|
|
2401
|
-
* @return Signature of the confirmed transaction
|
|
2402
|
-
*/
|
|
2403
|
-
async function approveAndMintTo(rpc, payer, mint, destination, authority, amount, merkleTree, confirmOptions, tokenProgramId) {
|
|
2404
|
-
tokenProgramId = tokenProgramId
|
|
2405
|
-
? tokenProgramId
|
|
2406
|
-
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2407
|
-
const authorityTokenAccount = await getOrCreateAssociatedTokenAccount(rpc, payer, mint, authority.publicKey, undefined, undefined, confirmOptions, tokenProgramId);
|
|
2408
|
-
const ixs = await CompressedTokenProgram.approveAndMintTo({
|
|
2409
|
-
feePayer: payer.publicKey,
|
|
2410
|
-
mint,
|
|
2411
|
-
authority: authority.publicKey,
|
|
2412
|
-
authorityTokenAccount: authorityTokenAccount.address,
|
|
2413
|
-
amount,
|
|
2414
|
-
toPubkey: destination,
|
|
2415
|
-
merkleTree,
|
|
2416
|
-
tokenProgramId,
|
|
2417
|
-
});
|
|
2418
|
-
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2419
|
-
const additionalSigners = dedupeSigner(payer, [authority]);
|
|
2420
|
-
const tx = buildAndSignTx([
|
|
2421
|
-
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }),
|
|
2422
|
-
...ixs,
|
|
2423
|
-
], payer, blockhash, additionalSigners);
|
|
2424
|
-
const txId = await sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
2425
|
-
return txId;
|
|
2426
|
-
}
|
|
2427
|
-
|
|
2428
|
-
/**
|
|
2429
|
-
* Compress SPL tokens
|
|
2430
|
-
*
|
|
2431
|
-
* @param rpc Rpc connection to use
|
|
2432
|
-
* @param payer Payer of the transaction fees
|
|
2433
|
-
* @param mint Mint of the compressed token
|
|
2434
|
-
* @param amount Number of tokens to transfer
|
|
2435
|
-
* @param owner Owner of the compressed tokens.
|
|
2436
|
-
* @param sourceTokenAccount Source (associated) token account
|
|
2437
|
-
* @param toAddress Destination address of the recipient
|
|
2438
|
-
* @param merkleTree State tree account that the compressed tokens
|
|
2439
|
-
* should be inserted into. Defaults to a default
|
|
2440
|
-
* state tree account.
|
|
2441
|
-
* @param confirmOptions Options for confirming the transaction
|
|
2442
|
-
*
|
|
2443
|
-
*
|
|
2444
|
-
* @return Signature of the confirmed transaction
|
|
2445
|
-
*/
|
|
2446
|
-
async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toAddress, merkleTree, confirmOptions, tokenProgramId) {
|
|
2447
|
-
tokenProgramId = tokenProgramId
|
|
2448
|
-
? tokenProgramId
|
|
2449
|
-
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2450
|
-
const compressIx = await CompressedTokenProgram.compress({
|
|
2451
|
-
payer: payer.publicKey,
|
|
2452
|
-
owner: owner.publicKey,
|
|
2453
|
-
source: sourceTokenAccount,
|
|
2454
|
-
toAddress,
|
|
2455
|
-
amount,
|
|
2456
|
-
mint,
|
|
2457
|
-
outputStateTree: merkleTree,
|
|
2458
|
-
tokenProgramId,
|
|
2459
|
-
});
|
|
2460
|
-
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
2461
|
-
const additionalSigners = dedupeSigner(payer, [owner]);
|
|
2462
|
-
const signedTx = buildAndSignTx([
|
|
2463
|
-
ComputeBudgetProgram.setComputeUnitLimit({
|
|
2464
|
-
units: 1_000_000,
|
|
2465
|
-
}),
|
|
2466
|
-
compressIx,
|
|
2467
|
-
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
2468
|
-
const txId = await sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
2469
|
-
return txId;
|
|
2470
|
-
}
|
|
2471
|
-
|
|
2472
|
-
/**
|
|
2473
|
-
* Transfer compressed tokens from one owner to another
|
|
2474
|
-
*
|
|
2475
|
-
* @param rpc Rpc to use
|
|
2476
|
-
* @param payer Payer of the transaction fees
|
|
2477
|
-
* @param mint Mint of the compressed token
|
|
2478
|
-
* @param amount Number of tokens to transfer
|
|
2479
|
-
* @param owner Owner of the compressed tokens
|
|
2480
|
-
* @param toAddress Destination address of the recipient
|
|
2481
|
-
* @param merkleTree State tree account that the compressed tokens should be
|
|
2482
|
-
* inserted into. Defaults to the default state tree
|
|
2483
|
-
* account.
|
|
2484
|
-
* @param confirmOptions Options for confirming the transaction
|
|
2485
|
-
*
|
|
2486
|
-
*
|
|
2487
|
-
* @return Signature of the confirmed transaction
|
|
2488
|
-
*/
|
|
2489
|
-
async function transfer(rpc, payer, mint, amount, owner, toAddress,
|
|
2490
|
-
/// TODO: allow multiple
|
|
2491
|
-
merkleTree, confirmOptions) {
|
|
2492
|
-
amount = bn(amount);
|
|
2493
|
-
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, {
|
|
2494
|
-
mint,
|
|
2495
|
-
});
|
|
2496
|
-
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(compressedTokenAccounts.items, amount);
|
|
2497
|
-
const proof = await rpc.getValidityProof(inputAccounts.map(account => bn(account.compressedAccount.hash)));
|
|
2498
|
-
const ix = await CompressedTokenProgram.transfer({
|
|
2499
|
-
payer: payer.publicKey,
|
|
2500
|
-
inputCompressedTokenAccounts: inputAccounts,
|
|
2501
|
-
toAddress,
|
|
2502
|
-
amount,
|
|
2503
|
-
recentInputStateRootIndices: proof.rootIndices,
|
|
2504
|
-
recentValidityProof: proof.compressedProof,
|
|
2505
|
-
outputStateTrees: merkleTree,
|
|
2506
|
-
});
|
|
2507
|
-
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2508
|
-
const additionalSigners = dedupeSigner(payer, [owner]);
|
|
2509
|
-
const signedTx = buildAndSignTx([ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }), ix], payer, blockhash, additionalSigners);
|
|
2510
|
-
const txId = await sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
2511
|
-
return txId;
|
|
2512
|
-
}
|
|
2513
|
-
/**
|
|
2514
|
-
* Selects the minimal number of compressed token accounts for a transfer.
|
|
2515
|
-
*
|
|
2516
|
-
* 1. Sorts the accounts by amount in descending order
|
|
2517
|
-
* 2. Accumulates the amount until it is greater than or equal to the transfer
|
|
2518
|
-
* amount
|
|
2519
|
-
*/
|
|
2520
|
-
function selectMinCompressedTokenAccountsForTransfer(accounts, transferAmount) {
|
|
2521
|
-
let accumulatedAmount = bn(0);
|
|
2522
|
-
let accumulatedLamports = bn(0);
|
|
2523
|
-
const selectedAccounts = [];
|
|
2524
|
-
accounts.sort((a, b) => b.parsed.amount.cmp(a.parsed.amount));
|
|
2525
|
-
for (const account of accounts) {
|
|
2526
|
-
if (accumulatedAmount.gte(bn(transferAmount)))
|
|
2527
|
-
break;
|
|
2528
|
-
accumulatedAmount = accumulatedAmount.add(account.parsed.amount);
|
|
2529
|
-
accumulatedLamports = accumulatedLamports.add(account.compressedAccount.lamports);
|
|
2530
|
-
selectedAccounts.push(account);
|
|
2531
|
-
}
|
|
2532
|
-
if (accumulatedAmount.lt(bn(transferAmount))) {
|
|
2533
|
-
throw new Error(`Not enough balance for transfer. Required: ${transferAmount.toString()}, available: ${accumulatedAmount.toString()}`);
|
|
2534
|
-
}
|
|
2535
|
-
return [
|
|
2536
|
-
selectedAccounts,
|
|
2537
|
-
accumulatedAmount,
|
|
2538
|
-
accumulatedLamports.lt(bn(0)) ? accumulatedLamports : null,
|
|
2539
|
-
];
|
|
2540
|
-
}
|
|
2541
|
-
|
|
2542
|
-
/**
|
|
2543
|
-
* Decompress compressed tokens
|
|
2544
|
-
*
|
|
2545
|
-
* @param rpc Rpc to use
|
|
2546
|
-
* @param payer Payer of the transaction fees
|
|
2547
|
-
* @param mint Mint of the compressed token
|
|
2548
|
-
* @param amount Number of tokens to transfer
|
|
2549
|
-
* @param owner Owner of the compressed tokens
|
|
2550
|
-
* @param toAddress Destination **uncompressed** (associated) token account
|
|
2551
|
-
* address.
|
|
2552
|
-
* @param merkleTree State tree account that any change compressed tokens should be
|
|
2553
|
-
* inserted into. Defaults to a default state tree
|
|
2554
|
-
* account.
|
|
2555
|
-
* @param confirmOptions Options for confirming the transaction
|
|
2556
|
-
*
|
|
2557
|
-
*
|
|
2558
|
-
* @return Signature of the confirmed transaction
|
|
2559
|
-
*/
|
|
2560
|
-
async function decompress(rpc, payer, mint, amount, owner, toAddress,
|
|
2561
|
-
/// TODO: allow multiple
|
|
2562
|
-
merkleTree, confirmOptions, tokenProgramId) {
|
|
2563
|
-
tokenProgramId = tokenProgramId
|
|
2564
|
-
? tokenProgramId
|
|
2565
|
-
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2566
|
-
amount = bn(amount);
|
|
2567
|
-
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, {
|
|
2568
|
-
mint,
|
|
2569
|
-
});
|
|
2570
|
-
/// TODO: consider using a different selection algorithm
|
|
2571
|
-
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(compressedTokenAccounts.items, amount);
|
|
2572
|
-
const proof = await rpc.getValidityProof(inputAccounts.map(account => bn(account.compressedAccount.hash)));
|
|
2573
|
-
const ix = await CompressedTokenProgram.decompress({
|
|
2574
|
-
payer: payer.publicKey,
|
|
2575
|
-
inputCompressedTokenAccounts: inputAccounts,
|
|
2576
|
-
toAddress, // TODO: add explicit check that it is a token account
|
|
2577
|
-
amount,
|
|
2578
|
-
outputStateTree: merkleTree,
|
|
2579
|
-
recentInputStateRootIndices: proof.rootIndices,
|
|
2580
|
-
recentValidityProof: proof.compressedProof,
|
|
2581
|
-
tokenProgramId,
|
|
2582
|
-
});
|
|
2583
|
-
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2584
|
-
const additionalSigners = dedupeSigner(payer, [owner]);
|
|
2585
|
-
const signedTx = buildAndSignTx([ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }), ix], payer, blockhash, additionalSigners);
|
|
2586
|
-
const txId = await sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
2587
|
-
return txId;
|
|
2588
|
-
}
|
|
2589
|
-
|
|
2590
|
-
/**
|
|
2591
|
-
* Create and initialize a new compressed token mint
|
|
2592
|
-
*
|
|
2593
|
-
* @param rpc RPC to use
|
|
2594
|
-
* @param payer Payer of the transaction and initialization fees
|
|
2595
|
-
* @param mintAuthority Account or multisig that will control minting
|
|
2596
|
-
* @param decimals Location of the decimal place
|
|
2597
|
-
* @param keypair Optional keypair, defaulting to a new random one
|
|
2598
|
-
* @param confirmOptions Options for confirming the transaction
|
|
2599
|
-
* @param isToken22 Whether to create a Token 2022 mint. Defaults to false.
|
|
2600
|
-
*
|
|
2601
|
-
* @return Address of the new mint and the transaction signature
|
|
2602
|
-
*/
|
|
2603
|
-
async function createMint(rpc, payer, mintAuthority, decimals, keypair = Keypair.generate(), confirmOptions, isToken22 = false) {
|
|
2604
|
-
const rentExemptBalance = await rpc.getMinimumBalanceForRentExemption(MINT_SIZE);
|
|
2605
|
-
const tokenProgramId = isToken22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID;
|
|
2606
|
-
const ixs = await CompressedTokenProgram.createMint({
|
|
2607
|
-
feePayer: payer.publicKey,
|
|
2608
|
-
mint: keypair.publicKey,
|
|
2609
|
-
decimals,
|
|
2610
|
-
authority: mintAuthority,
|
|
2611
|
-
freezeAuthority: null, // TODO: add feature
|
|
2612
|
-
rentExemptBalance,
|
|
2613
|
-
tokenProgramId,
|
|
2614
|
-
});
|
|
2615
|
-
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2616
|
-
const additionalSigners = dedupeSigner(payer, [keypair]);
|
|
2617
|
-
const tx = buildAndSignTx(ixs, payer, blockhash, additionalSigners);
|
|
2618
|
-
const txId = await sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
2619
|
-
return { mint: keypair.publicKey, transactionSignature: txId };
|
|
2620
|
-
}
|
|
2621
|
-
|
|
2622
|
-
/**
|
|
2623
|
-
* Mint compressed tokens to a solana address
|
|
2624
|
-
*
|
|
2625
|
-
* @param rpc Rpc to use
|
|
2626
|
-
* @param payer Payer of the transaction fees
|
|
2627
|
-
* @param mint Mint for the account
|
|
2628
|
-
* @param destination Address of the account to mint to. Can be an array of
|
|
2629
|
-
* addresses if the amount is an array of amounts.
|
|
2630
|
-
* @param authority Minting authority
|
|
2631
|
-
* @param amount Amount to mint. Can be an array of amounts if the
|
|
2632
|
-
* destination is an array of addresses.
|
|
2633
|
-
* @param merkleTree State tree account that the compressed tokens should be
|
|
2634
|
-
* part of. Defaults to the default state tree account.
|
|
2635
|
-
* @param confirmOptions Options for confirming the transaction
|
|
2636
|
-
*
|
|
2637
|
-
* @return Signature of the confirmed transaction
|
|
2638
|
-
*/
|
|
2639
|
-
async function mintTo(rpc, payer, mint, destination, authority, amount, merkleTree, confirmOptions, tokenProgramId) {
|
|
2640
|
-
tokenProgramId = tokenProgramId
|
|
2641
|
-
? tokenProgramId
|
|
2642
|
-
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2643
|
-
const additionalSigners = dedupeSigner(payer, [authority]);
|
|
2644
|
-
const ix = await CompressedTokenProgram.mintTo({
|
|
2645
|
-
feePayer: payer.publicKey,
|
|
2646
|
-
mint,
|
|
2647
|
-
authority: authority.publicKey,
|
|
2648
|
-
amount: amount,
|
|
2649
|
-
toPubkey: destination,
|
|
2650
|
-
merkleTree,
|
|
2651
|
-
tokenProgramId,
|
|
2652
|
-
});
|
|
2653
|
-
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2654
|
-
const tx = buildAndSignTx([ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }), ix], payer, blockhash, additionalSigners);
|
|
2655
|
-
const txId = await sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
2656
|
-
return txId;
|
|
2657
|
-
}
|
|
2658
|
-
|
|
2659
|
-
/**
|
|
2660
|
-
* Merge multiple compressed token accounts for a given mint into a single
|
|
2661
|
-
* account
|
|
2662
|
-
*
|
|
2663
|
-
* @param rpc RPC to use
|
|
2664
|
-
* @param payer Payer of the transaction fees
|
|
2665
|
-
* @param mint Public key of the token's mint
|
|
2666
|
-
* @param owner Owner of the token accounts to be merged
|
|
2667
|
-
* @param merkleTree Optional merkle tree for compressed tokens
|
|
2668
|
-
* @param confirmOptions Options for confirming the transaction
|
|
2669
|
-
*
|
|
2670
|
-
* @return Array of transaction signatures
|
|
2671
|
-
*/
|
|
2672
|
-
async function mergeTokenAccounts(rpc, payer, mint, owner, merkleTree, confirmOptions) {
|
|
2673
|
-
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, { mint });
|
|
2674
|
-
if (compressedTokenAccounts.items.length === 0) {
|
|
2675
|
-
throw new Error(`No compressed token accounts found for mint ${mint.toBase58()}`);
|
|
2676
|
-
}
|
|
2677
|
-
if (compressedTokenAccounts.items.length >= 6) {
|
|
2678
|
-
throw new Error(`Too many compressed token accounts used for mint ${mint.toBase58()}`);
|
|
2679
|
-
}
|
|
2680
|
-
const instructions = [
|
|
2681
|
-
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }),
|
|
2682
|
-
];
|
|
2683
|
-
for (let i = 0; i < compressedTokenAccounts.items.slice(0, 6).length; i += 3) {
|
|
2684
|
-
const batch = compressedTokenAccounts.items.slice(i, i + 3);
|
|
2685
|
-
const proof = await rpc.getValidityProof(batch.map(account => bn(account.compressedAccount.hash)));
|
|
2686
|
-
const batchInstructions = await CompressedTokenProgram.mergeTokenAccounts({
|
|
2687
|
-
payer: payer.publicKey,
|
|
2688
|
-
owner: owner.publicKey,
|
|
2689
|
-
mint,
|
|
2690
|
-
inputCompressedTokenAccounts: batch,
|
|
2691
|
-
outputStateTree: merkleTree,
|
|
2692
|
-
recentValidityProof: proof.compressedProof,
|
|
2693
|
-
recentInputStateRootIndices: proof.rootIndices,
|
|
2694
|
-
});
|
|
2695
|
-
instructions.push(...batchInstructions);
|
|
2696
|
-
}
|
|
2697
|
-
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2698
|
-
const additionalSigners = dedupeSigner(payer, [owner]);
|
|
2699
|
-
const signedTx = buildAndSignTx(instructions, payer, blockhash, additionalSigners);
|
|
2700
|
-
const txId = await sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
2701
|
-
return txId;
|
|
2702
|
-
}
|
|
2703
|
-
|
|
2704
|
-
/**
|
|
2705
|
-
* Register an existing mint with the CompressedToken program
|
|
2706
|
-
*
|
|
2707
|
-
* @param rpc RPC to use
|
|
2708
|
-
* @param payer Payer of the transaction and initialization fees
|
|
2709
|
-
* @param mintAuthority Account or multisig that will control minting. Is signer.
|
|
2710
|
-
* @param mintAddress Address of the existing mint
|
|
2711
|
-
* @param confirmOptions Options for confirming the transaction
|
|
2712
|
-
*
|
|
2713
|
-
* @return transaction signature
|
|
2714
|
-
*/
|
|
2715
|
-
async function createTokenPool(rpc, payer, mint, confirmOptions, tokenProgramId) {
|
|
2716
|
-
tokenProgramId = tokenProgramId
|
|
2717
|
-
? tokenProgramId
|
|
2718
|
-
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2719
|
-
const ix = await CompressedTokenProgram.createTokenPool({
|
|
2720
|
-
feePayer: payer.publicKey,
|
|
2721
|
-
mint,
|
|
2722
|
-
tokenProgramId,
|
|
2723
|
-
});
|
|
2724
|
-
const { blockhash } = await rpc.getLatestBlockhash();
|
|
2725
|
-
const tx = buildAndSignTx([ix], payer, blockhash);
|
|
2726
|
-
const txId = await sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
2727
|
-
return txId;
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2730
|
-
/**
|
|
2731
|
-
* Create a lookup table for the token program's default accounts
|
|
2732
|
-
*
|
|
2733
|
-
* @param rpc Rpc connection to use
|
|
2734
|
-
* @param payer Payer of the transaction fees
|
|
2735
|
-
* @param authority Authority of the lookup table
|
|
2736
|
-
* @param mints Optional array of mint public keys to include in
|
|
2737
|
-
* the lookup table
|
|
2738
|
-
* @param additionalAccounts Optional array of additional account public keys
|
|
2739
|
-
* to include in the lookup table
|
|
2740
|
-
*
|
|
2741
|
-
* @return Transaction signatures and the address of the created lookup table
|
|
2742
|
-
*/
|
|
2743
|
-
async function createTokenProgramLookupTable(rpc, payer, authority, mints, additionalAccounts) {
|
|
2744
|
-
const recentSlot = await rpc.getSlot('finalized');
|
|
2745
|
-
const { instructions, address } = await CompressedTokenProgram.createTokenProgramLookupTable({
|
|
2746
|
-
payer: payer.publicKey,
|
|
2747
|
-
authority: authority.publicKey,
|
|
2748
|
-
mints,
|
|
2749
|
-
remainingAccounts: additionalAccounts,
|
|
2750
|
-
recentSlot,
|
|
2751
|
-
});
|
|
2752
|
-
const additionalSigners = dedupeSigner(payer, [authority]);
|
|
2753
|
-
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
2754
|
-
const signedTx = buildAndSignTx([instructions[0]], payer, blockhashCtx.blockhash, additionalSigners);
|
|
2755
|
-
/// Must wait for the first instruction to be finalized.
|
|
2756
|
-
const txId = await sendAndConfirmTx(rpc, signedTx, { commitment: 'finalized' }, blockhashCtx);
|
|
2757
|
-
const blockhashCtx2 = await rpc.getLatestBlockhash();
|
|
2758
|
-
const signedTx2 = buildAndSignTx([instructions[1]], payer, blockhashCtx2.blockhash, additionalSigners);
|
|
2759
|
-
const txId2 = await sendAndConfirmTx(rpc, signedTx2, { commitment: 'finalized' }, blockhashCtx2);
|
|
2760
|
-
return { txIds: [txId, txId2], address };
|
|
2761
|
-
}
|
|
2762
|
-
|
|
2763
|
-
/**
|
|
2764
|
-
* Compress SPL tokens into compressed token format
|
|
2765
|
-
*
|
|
2766
|
-
* @param rpc Rpc connection to use
|
|
2767
|
-
* @param payer Payer of the transaction fees
|
|
2768
|
-
* @param mint Mint of the token to compress
|
|
2769
|
-
* @param owner Owner of the token account
|
|
2770
|
-
* @param tokenAccount Token account to compress
|
|
2771
|
-
* @param outputStateTree State tree to insert the compressed token account into
|
|
2772
|
-
* @param remainingAmount Optional: amount to leave in token account. Default: 0
|
|
2773
|
-
* @param confirmOptions Options for confirming the transaction
|
|
2774
|
-
*
|
|
2775
|
-
* @return Signature of the confirmed transaction
|
|
2776
|
-
*/
|
|
2777
|
-
async function compressSplTokenAccount(rpc, payer, mint, owner, tokenAccount, outputStateTree, remainingAmount, confirmOptions, tokenProgramId) {
|
|
2778
|
-
tokenProgramId = tokenProgramId
|
|
2779
|
-
? tokenProgramId
|
|
2780
|
-
: await CompressedTokenProgram.get_mint_program_id(mint, rpc);
|
|
2781
|
-
const compressIx = await CompressedTokenProgram.compressSplTokenAccount({
|
|
2782
|
-
feePayer: payer.publicKey,
|
|
2783
|
-
authority: owner.publicKey,
|
|
2784
|
-
tokenAccount,
|
|
2785
|
-
mint,
|
|
2786
|
-
remainingAmount,
|
|
2787
|
-
outputStateTree,
|
|
2788
|
-
tokenProgramId,
|
|
2789
|
-
});
|
|
2790
|
-
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
2791
|
-
const additionalSigners = dedupeSigner(payer, [owner]);
|
|
2792
|
-
const signedTx = buildAndSignTx([
|
|
2793
|
-
ComputeBudgetProgram.setComputeUnitLimit({
|
|
2794
|
-
units: 1_000_000,
|
|
2795
|
-
}),
|
|
2796
|
-
compressIx,
|
|
2797
|
-
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
2798
|
-
const txId = await sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
2799
|
-
return txId;
|
|
2800
|
-
}
|
|
2801
|
-
|
|
2802
|
-
export { CPI_AUTHORITY_SEED, CompressedTokenProgram, IDL, POOL_SEED, SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE, approveAndMintTo, compress, compressSplTokenAccount, createDecompressOutputState, createMint, createTokenPool, createTokenProgramLookupTable, createTransferOutputState, decompress, mergeTokenAccounts, mintTo, packCompressedTokenAccounts, parseTokenData, selectMinCompressedTokenAccountsForTransfer, sumUpTokenAmount, transfer, validateSameTokenOwner };
|
|
1
|
+
import{getIndexOrAdd as t,bn as e,padOutputStateMerkleTrees as r,defaultStaticAccountsStruct as n,toArray as i,LightSystemProgram as o,defaultTestStateTreeAccounts as s,sumUpLamports as u,validateSufficientBalance as a,validateSameOwner as h,dedupeSigner as l,buildAndSignTx as c,sendAndConfirmTx as f}from"@lightprotocol/stateless.js";import d,{PublicKey as p,SystemProgram as m,TransactionInstruction as g,AddressLookupTableProgram as y,ComputeBudgetProgram as w,Keypair as v}from"@solana/web3.js";import{MINT_SIZE as b,createInitializeMint2Instruction as M,createMintToInstruction as P,TOKEN_PROGRAM_ID as k,TOKEN_2022_PROGRAM_ID as A,getOrCreateAssociatedTokenAccount as E}from"@solana/spl-token";function _(n){const{inputCompressedTokenAccounts:i,outputStateTrees:o,remainingAccounts:s=[],rootIndices:u,tokenTransferOutputs:a}=n,h=s.slice();let l=null;i.length>0&&i[0].parsed.delegate&&(l=t(h,i[0].parsed.delegate));const c=[];i.forEach(((r,n)=>{const i=t(h,r.compressedAccount.merkleTree),o=t(h,r.compressedAccount.nullifierQueue);c.push({amount:r.parsed.amount,delegateIndex:l,merkleContext:{merkleTreePubkeyIndex:i,nullifierQueuePubkeyIndex:o,leafIndex:r.compressedAccount.leafIndex,queueIndex:null},rootIndex:u[n],lamports:r.compressedAccount.lamports.eq(e(0))?null:r.compressedAccount.lamports,tlv:null})}));const f=r(o,a.length,i.map((t=>t.compressedAccount))),d=[];f.forEach(((r,n)=>{const i=t(h,r);d.push({owner:a[n].owner,amount:a[n].amount,lamports:a[n].lamports?.eq(e(0))?null:a[n].lamports,merkleTreeIndex:i,tlv:null})}));const p=h.map((t=>({pubkey:t,isWritable:1,isSigner:0})));return{inputTokenDataWithContext:c,remainingAccountMetas:p,packedOutputTokenData:d}}const S=Buffer.from("pool"),T=Buffer.from("cpi_authority"),I=1461600;var x="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function B(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function L(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var r=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:1}),Object.keys(t).forEach((function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,n.get?n:{enumerable:1,get:function(){return t[e]}})})),r}var C={exports:{}},R="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},O=[],U=[],D="undefined"!=typeof Uint8Array?Uint8Array:Array,W=0;function Y(){W=1;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;e<64;++e)O[e]=t[e],U[t.charCodeAt(e)]=e;U["-".charCodeAt(0)]=62,U["_".charCodeAt(0)]=63}function N(t,e,r){for(var n,i,o=[],s=e;s<r;s+=3)n=(t[s]<<16)+(t[s+1]<<8)+t[s+2],o.push(O[(i=n)>>18&63]+O[i>>12&63]+O[i>>6&63]+O[63&i]);return o.join("")}function q(t){var e;W||Y();for(var r=t.length,n=r%3,i="",o=[],s=16383,u=0,a=r-n;u<a;u+=s)o.push(N(t,u,u+s>a?a:u+s));return 1===n?(e=t[r-1],i+=O[e>>2],i+=O[e<<4&63],i+="=="):2===n&&(e=(t[r-2]<<8)+t[r-1],i+=O[e>>10],i+=O[e>>4&63],i+=O[e<<2&63],i+="="),o.push(i),o.join("")}function j(t,e,r,n,i){var o,s,u=8*i-n-1,a=(1<<u)-1,h=a>>1,l=-7,c=r?i-1:0,f=r?-1:1,d=t[e+c];for(c+=f,o=d&(1<<-l)-1,d>>=-l,l+=u;l>0;o=256*o+t[e+c],c+=f,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=n;l>0;s=256*s+t[e+c],c+=f,l-=8);if(0===o)o=1-h;else{if(o===a)return s?NaN:Infinity*(d?-1:1);s+=Math.pow(2,n),o-=h}return(d?-1:1)*s*Math.pow(2,o-n)}function K(t,e,r,n,i,o){var s,u,a,h=8*o-i-1,l=(1<<h)-1,c=l>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:o-1,p=n?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||Infinity===e?(u=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(a=Math.pow(2,-s))<1&&(s--,a*=2),(e+=s+c>=1?f/a:f*Math.pow(2,1-c))*a>=2&&(s++,a/=2),s+c>=l?(u=0,s=l):s+c>=1?(u=(e*a-1)*Math.pow(2,i),s+=c):(u=e*Math.pow(2,c-1)*Math.pow(2,i),s=0));i>=8;t[r+d]=255&u,d+=p,u/=256,i-=8);for(s=s<<i|u,h+=i;h>0;t[r+d]=255&s,d+=p,s/=256,h-=8);t[r+d-p]|=128*m}var V={}.toString,Z=Array.isArray||function(t){return"[object Array]"==V.call(t)};Q.TYPED_ARRAY_SUPPORT=void 0!==R.TYPED_ARRAY_SUPPORT?R.TYPED_ARRAY_SUPPORT:1;var z=F();function F(){return Q.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function G(t,e){if(F()<e)throw new RangeError("Invalid typed array length");return Q.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=Q.prototype:(null===t&&(t=new Q(e)),t.length=e),t}function Q(t,e,r){if(!(Q.TYPED_ARRAY_SUPPORT||this instanceof Q))return new Q(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return J(this,t)}return $(this,t,e,r)}function $(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n),Q.TYPED_ARRAY_SUPPORT?(t=e).__proto__=Q.prototype:t=X(t,e),t}(t,e,r,n):"string"==typeof e?function(t,e,r){if("string"==typeof r&&""!==r||(r="utf8"),!Q.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|rt(e,r),i=(t=G(t,n)).write(e,r);return i!==n&&(t=t.slice(0,i)),t}(t,e,r):function(t,e){if(et(e)){var r=0|tt(e.length);return 0===(t=G(t,r)).length||e.copy(t,0,0,r),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(n=e.length)!=n?G(t,0):X(t,e);if("Buffer"===e.type&&Z(e.data))return X(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function H(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function J(t,e){if(H(e),t=G(t,e<0?0:0|tt(e)),!Q.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function X(t,e){var r=e.length<0?0:0|tt(e.length);t=G(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function tt(t){if(t>=F())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+F().toString(16)+" bytes");return 0|t}function et(t){return!(null==t||!t._isBuffer)}function rt(t,e){if(et(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=0;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return Tt(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return It(t).length;default:if(n)return Tt(t).length;e=(""+e).toLowerCase(),n=1}}function nt(t,e,r){var n=0;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return wt(this,e,r);case"utf8":case"utf-8":return pt(this,e,r);case"ascii":return gt(this,e,r);case"latin1":case"binary":return yt(this,e,r);case"base64":return dt(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return vt(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=1}}function it(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function ot(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=Q.from(e,n)),et(e))return 0===e.length?-1:st(t,e,r,n,i);if("number"==typeof e)return e&=255,Q.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):st(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function st(t,e,r,n,i){var o,s=1,u=t.length,a=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,u/=2,a/=2,r/=2}function h(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){var l=-1;for(o=r;o<u;o++)if(h(t,o)===h(e,-1===l?0:o-l)){if(-1===l&&(l=o),o-l+1===a)return l*s}else-1!==l&&(o-=o-l),l=-1}else for(r+a>u&&(r=u-a),o=r;o>=0;o--){for(var c=1,f=0;f<a;f++)if(h(t,o+f)!==h(e,f)){c=0;break}if(c)return o}return-1}function ut(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s<n;++s){var u=parseInt(e.substr(2*s,2),16);if(isNaN(u))return s;t[r+s]=u}return s}function at(t,e,r,n){return xt(Tt(e,t.length-r),t,r,n)}function ht(t,e,r,n){return xt(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function lt(t,e,r,n){return ht(t,e,r,n)}function ct(t,e,r,n){return xt(It(e),t,r,n)}function ft(t,e,r,n){return xt(function(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);++s)n=(r=t.charCodeAt(s))>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function dt(t,e,r){return 0===e&&r===t.length?q(t):q(t.slice(e,r))}function pt(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o,s,u,a,h=t[i],l=null,c=h>239?4:h>223?3:h>191?2:1;if(i+c<=r)switch(c){case 1:h<128&&(l=h);break;case 2:128==(192&(o=t[i+1]))&&(a=(31&h)<<6|63&o)>127&&(l=a);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(a=(15&h)<<12|(63&o)<<6|63&s)>2047&&(a<55296||a>57343)&&(l=a);break;case 4:o=t[i+1],s=t[i+2],u=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&u)&&(a=(15&h)<<18|(63&o)<<12|(63&s)<<6|63&u)>65535&&a<1114112&&(l=a)}null===l?(l=65533,c=1):l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|1023&l),n.push(l),i+=c}return function(t){var e=t.length;if(e<=mt)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=mt));return r}(n)}Q.poolSize=8192,Q._augment=function(t){return t.__proto__=Q.prototype,t},Q.from=function(t,e,r){return $(null,t,e,r)},Q.TYPED_ARRAY_SUPPORT&&(Q.prototype.__proto__=Uint8Array.prototype,Q.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&Q[Symbol.species]),Q.alloc=function(t,e,r){return function(t,e,r,n){return H(e),e<=0?G(t,e):void 0!==r?"string"==typeof n?G(t,e).fill(r,n):G(t,e).fill(r):G(t,e)}(null,t,e,r)},Q.allocUnsafe=function(t){return J(null,t)},Q.allocUnsafeSlow=function(t){return J(null,t)},Q.isBuffer=Bt,Q.compare=function(t,e){if(!et(t)||!et(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},Q.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 1;default:return 0}},Q.concat=function(t,e){if(!Z(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return Q.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=Q.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){var o=t[r];if(!et(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},Q.byteLength=rt,Q.prototype._isBuffer=1,Q.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)it(this,e,e+1);return this},Q.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)it(this,e,e+3),it(this,e+1,e+2);return this},Q.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)it(this,e,e+7),it(this,e+1,e+6),it(this,e+2,e+5),it(this,e+3,e+4);return this},Q.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?pt(this,0,t):nt.apply(this,arguments)},Q.prototype.equals=function(t){if(!et(t))throw new TypeError("Argument must be a Buffer");return this===t?1:0===Q.compare(this,t)},Q.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},Q.prototype.compare=function(t,e,r,n,i){if(!et(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),u=Math.min(o,s),a=this.slice(n,i),h=t.slice(e,r),l=0;l<u;++l)if(a[l]!==h[l]){o=a[l],s=h[l];break}return o<s?-1:s<o?1:0},Q.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},Q.prototype.indexOf=function(t,e,r){return ot(this,t,e,r,1)},Q.prototype.lastIndexOf=function(t,e,r){return ot(this,t,e,r,0)},Q.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=0;;)switch(n){case"hex":return ut(this,t,e,r);case"utf8":case"utf-8":return at(this,t,e,r);case"ascii":return ht(this,t,e,r);case"latin1":case"binary":return lt(this,t,e,r);case"base64":return ct(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ft(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=1}},Q.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var mt=4096;function gt(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function yt(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function wt(t,e,r){var n,i=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>i)&&(r=i);for(var o="",s=e;s<r;++s)o+=(n=t[s])<16?"0"+n.toString(16):n.toString(16);return o}function vt(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function bt(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function Mt(t,e,r,n,i,o){if(!et(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function Pt(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i<o;++i)t[r+i]=(e&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function kt(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i<o;++i)t[r+i]=e>>>8*(n?i:3-i)&255}function At(t,e,r,n){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Et(t,e,r,n,i){return i||At(t,0,r,4),K(t,e,r,n,23,4),r+4}function _t(t,e,r,n,i){return i||At(t,0,r,8),K(t,e,r,n,52,8),r+8}Q.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),Q.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=Q.prototype;else{var i=e-t;r=new Q(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+t]}return r},Q.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n},Q.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},Q.prototype.readUInt8=function(t,e){return e||bt(t,1,this.length),this[t]},Q.prototype.readUInt16LE=function(t,e){return e||bt(t,2,this.length),this[t]|this[t+1]<<8},Q.prototype.readUInt16BE=function(t,e){return e||bt(t,2,this.length),this[t]<<8|this[t+1]},Q.prototype.readUInt32LE=function(t,e){return e||bt(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Q.prototype.readUInt32BE=function(t,e){return e||bt(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Q.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*e)),n},Q.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},Q.prototype.readInt8=function(t,e){return e||bt(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Q.prototype.readInt16LE=function(t,e){e||bt(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},Q.prototype.readInt16BE=function(t,e){e||bt(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},Q.prototype.readInt32LE=function(t,e){return e||bt(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Q.prototype.readInt32BE=function(t,e){return e||bt(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Q.prototype.readFloatLE=function(t,e){return e||bt(t,4,this.length),j(this,t,1,23,4)},Q.prototype.readFloatBE=function(t,e){return e||bt(t,4,this.length),j(this,t,0,23,4)},Q.prototype.readDoubleLE=function(t,e){return e||bt(t,8,this.length),j(this,t,1,52,8)},Q.prototype.readDoubleBE=function(t,e){return e||bt(t,8,this.length),j(this,t,0,52,8)},Q.prototype.writeUIntLE=function(t,e,r,n){t=+t,e|=0,r|=0,n||Mt(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},Q.prototype.writeUIntBE=function(t,e,r,n){t=+t,e|=0,r|=0,n||Mt(this,t,e,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},Q.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||Mt(this,t,e,1,255,0),Q.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},Q.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||Mt(this,t,e,2,65535,0),Q.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):Pt(this,t,e,1),e+2},Q.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||Mt(this,t,e,2,65535,0),Q.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):Pt(this,t,e,0),e+2},Q.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||Mt(this,t,e,4,4294967295,0),Q.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):kt(this,t,e,1),e+4},Q.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||Mt(this,t,e,4,4294967295,0),Q.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):kt(this,t,e,0),e+4},Q.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);Mt(this,t,e,r,i-1,-i)}var o=0,s=1,u=0;for(this[e]=255&t;++o<r&&(s*=256);)t<0&&0===u&&0!==this[e+o-1]&&(u=1),this[e+o]=(t/s>>0)-u&255;return e+r},Q.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);Mt(this,t,e,r,i-1,-i)}var o=r-1,s=1,u=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===u&&0!==this[e+o+1]&&(u=1),this[e+o]=(t/s>>0)-u&255;return e+r},Q.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||Mt(this,t,e,1,127,-128),Q.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},Q.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||Mt(this,t,e,2,32767,-32768),Q.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):Pt(this,t,e,1),e+2},Q.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||Mt(this,t,e,2,32767,-32768),Q.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):Pt(this,t,e,0),e+2},Q.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||Mt(this,t,e,4,2147483647,-2147483648),Q.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):kt(this,t,e,1),e+4},Q.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||Mt(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),Q.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):kt(this,t,e,0),e+4},Q.prototype.writeFloatLE=function(t,e,r){return Et(this,t,e,1,r)},Q.prototype.writeFloatBE=function(t,e,r){return Et(this,t,e,0,r)},Q.prototype.writeDoubleLE=function(t,e,r){return _t(this,t,e,1,r)},Q.prototype.writeDoubleBE=function(t,e,r){return _t(this,t,e,0,r)},Q.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i,o=n-r;if(this===t&&r<e&&e<n)for(i=o-1;i>=0;--i)t[i+e]=this[i+r];else if(o<1e3||!Q.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)t[i+e]=this[i+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+o),e);return o},Q.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!Q.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{var s=et(t)?t:Tt(new Q(t,n).toString()),u=s.length;for(o=0;o<r-e;++o)this[o+e]=s[o%u]}return this};var St=/[^+\/0-9A-Za-z-_]/g;function Tt(t,e){var r;e=e||Infinity;for(var n=t.length,i=null,o=[],s=0;s<n;++s){if((r=t.charCodeAt(s))>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function It(t){return function(t){var e,r,n,i,o,s;W||Y();var u=t.length;if(u%4>0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===t[u-2]?2:"="===t[u-1]?1:0,s=new D(3*u/4-o),n=o>0?u-4:u;var a=0;for(e=0,r=0;e<n;e+=4,r+=3)i=U[t.charCodeAt(e)]<<18|U[t.charCodeAt(e+1)]<<12|U[t.charCodeAt(e+2)]<<6|U[t.charCodeAt(e+3)],s[a++]=i>>16&255,s[a++]=i>>8&255,s[a++]=255&i;return 2===o?(i=U[t.charCodeAt(e)]<<2|U[t.charCodeAt(e+1)]>>4,s[a++]=255&i):1===o&&(i=U[t.charCodeAt(e)]<<10|U[t.charCodeAt(e+1)]<<4|U[t.charCodeAt(e+2)]>>2,s[a++]=i>>8&255,s[a++]=255&i),s}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(St,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function xt(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function Bt(t){return null!=t&&(!!t._isBuffer||Lt(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&Lt(t.slice(0,0))}(t))}function Lt(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var Ct=L(Object.freeze({__proto__:null,Buffer:Q,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),Q.alloc(+t)},isBuffer:Bt,kMaxLength:z}));!function(t,e){function r(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function i(t,e,r){if(i.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var o;"object"==typeof C?C.exports=i:e.BN=i,i.BN=i,i.wordSize=26;try{o="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:Ct.Buffer}catch(t){}function s(t,e){var n=t.charCodeAt(e);return n>=48&&n<=57?n-48:n>=65&&n<=70?n-55:n>=97&&n<=102?n-87:void r(0,"Invalid character in "+t)}function u(t,e,r){var n=s(t,r);return r-1>=e&&(n|=s(t,r-1)<<4),n}function a(t,e,n,i){for(var o=0,s=0,u=Math.min(t.length,n),a=e;a<u;a++){var h=t.charCodeAt(a)-48;o*=i,s=h>=49?h-49+10:h>=17?h-17+10:h,r(h>=0&&s<i,"Invalid character"),o+=s}return o}function h(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(i.isBN=function(t){return t instanceof i?1:null!==t&&"object"==typeof t&&t.constructor.wordSize===i.wordSize&&Array.isArray(t.words)},i.max=function(t,e){return t.cmp(e)>0?t:e},i.min=function(t,e){return t.cmp(e)<0?t:e},i.prototype._init=function(t,e,n){if("number"==typeof t)return this._initNumber(t,e,n);if("object"==typeof t)return this._initArray(t,e,n);"hex"===e&&(e=16),r(e===(0|e)&&e>=2&&e<=36);var i=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(i++,this.negative=1),i<t.length&&(16===e?this._parseHex(t,i,n):(this._parseBase(t,e,i),"le"===n&&this._initArray(this.toArray(),e,n)))},i.prototype._initNumber=function(t,e,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(r(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),e,n)},i.prototype._initArray=function(t,e,n){if(r("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var o,s,u=0;if("be"===n)for(i=t.length-1,o=0;i>=0;i-=3)s=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[o]|=s<<u&67108863,this.words[o+1]=s>>>26-u&67108863,(u+=24)>=26&&(u-=26,o++);else if("le"===n)for(i=0,o=0;i<t.length;i+=3)s=t[i]|t[i+1]<<8|t[i+2]<<16,this.words[o]|=s<<u&67108863,this.words[o+1]=s>>>26-u&67108863,(u+=24)>=26&&(u-=26,o++);return this._strip()},i.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var i,o=0,s=0;if("be"===r)for(n=t.length-1;n>=e;n-=2)i=u(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;else for(n=(t.length-e)%2==0?e+1:e;n<t.length;n+=2)i=u(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;this._strip()},i.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=e)n++;n--,i=i/e|0;for(var o=t.length-r,s=o%n,u=Math.min(o,o-s)+r,h=0,l=r;l<u;l+=n)h=a(t,l,l+n,e),this.imuln(i),this.words[0]+h<67108864?this.words[0]+=h:this._iaddn(h);if(0!==s){var c=1;for(h=a(t,l,t.length,e),l=0;l<s;l++)c*=e;this.imuln(c),this.words[0]+h<67108864?this.words[0]+=h:this._iaddn(h)}this._strip()},i.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red},i.prototype._move=function(t){h(t,this)},i.prototype.clone=function(){var t=new i(null);return this.copy(t),t},i.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},i.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},i.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{i.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(t){i.prototype.inspect=l}else i.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var c=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],f=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],d=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function p(t,e,r){r.negative=e.negative^t.negative;var n=t.length+e.length|0;r.length=n,n=n-1|0;var i=0|t.words[0],o=0|e.words[0],s=i*o,u=67108863&s,a=s/67108864|0;r.words[0]=u;for(var h=1;h<n;h++){for(var l=a>>>26,c=67108863&a,f=Math.min(h,e.length-1),d=Math.max(0,h-t.length+1);d<=f;d++){var p=h-d|0;l+=(s=(i=0|t.words[p])*(o=0|e.words[d])+c)/67108864|0,c=67108863&s}r.words[h]=0|c,a=0|l}return 0!==a?r.words[h]=0|a:r.length--,r._strip()}i.prototype.toString=function(t,e){var n;if(e=0|e||1,16===(t=t||10)||"hex"===t){n="";for(var i=0,o=0,s=0;s<this.length;s++){var u=this.words[s],a=(16777215&(u<<i|o)).toString(16);o=u>>>24-i&16777215,(i+=2)>=26&&(i-=26,s--),n=0!==o||s!==this.length-1?c[6-a.length]+a+n:a+n}for(0!==o&&(n=o.toString(16)+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var h=f[t],l=d[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var m=p.modrn(l).toString(t);n=(p=p.idivn(l)).isZero()?m+n:c[h-m.length]+m+n}for(this.isZero()&&(n="0"+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}r(0,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&r(0,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},i.prototype.toJSON=function(){return this.toString(16,2)},o&&(i.prototype.toBuffer=function(t,e){return this.toArrayLike(o,t,e)}),i.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},i.prototype.toArrayLike=function(t,e,n){this._strip();var i=this.byteLength(),o=n||Math.max(1,i);r(i<=o,"byte array longer than desired length"),r(o>0,"Requested array length <= 0");var s=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,o);return this["_toArrayLike"+("le"===e?"LE":"BE")](s,i),s},i.prototype._toArrayLikeLE=function(t){for(var e=0,r=0,n=0,i=0;n<this.length;n++){var o=this.words[n]<<i|r;t[e++]=255&o,e<t.length&&(t[e++]=o>>8&255),e<t.length&&(t[e++]=o>>16&255),6===i?(e<t.length&&(t[e++]=o>>24&255),r=0,i=0):(r=o>>>24,i+=2)}if(e<t.length)for(t[e++]=r;e<t.length;)t[e++]=0},i.prototype._toArrayLikeBE=function(t){for(var e=t.length-1,r=0,n=0,i=0;n<this.length;n++){var o=this.words[n]<<i|r;t[e--]=255&o,e>=0&&(t[e--]=o>>8&255),e>=0&&(t[e--]=o>>16&255),6===i?(e>=0&&(t[e--]=o>>24&255),r=0,i=0):(r=o>>>24,i+=2)}if(e>=0)for(t[e--]=r;e>=0;)t[e--]=0},Math.clz32?i.prototype._countBits=function(t){return 32-Math.clz32(t)}:i.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},i.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 0==(8191&e)&&(r+=13,e>>>=13),0==(127&e)&&(r+=7,e>>>=7),0==(15&e)&&(r+=4,e>>>=4),0==(3&e)&&(r+=2,e>>>=2),0==(1&e)&&r++,r},i.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var r=this._zeroBits(this.words[e]);if(t+=r,26!==r)break}return t},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},i.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return 0!==this.negative},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},i.prototype.ior=function(t){return r(0==(this.negative|t.negative)),this.iuor(t)},i.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},i.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},i.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;r<e.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=e.length,this._strip()},i.prototype.iand=function(t){return r(0==(this.negative|t.negative)),this.iuand(t)},i.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},i.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},i.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var n=0;n<r.length;n++)this.words[n]=e.words[n]^r.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this._strip()},i.prototype.ixor=function(t){return r(0==(this.negative|t.negative)),this.iuxor(t)},i.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},i.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},i.prototype.inotn=function(t){r("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),n=t%26;this._expand(e),n>0&&e--;for(var i=0;i<e;i++)this.words[i]=67108863&~this.words[i];return n>0&&(this.words[i]=~this.words[i]&67108863>>26-n),this._strip()},i.prototype.notn=function(t){return this.clone().inotn(t)},i.prototype.setn=function(t,e){r("number"==typeof t&&t>=0);var n=t/26|0,i=t%26;return this._expand(n+1),this.words[n]=e?this.words[n]|1<<i:this.words[n]&~(1<<i),this._strip()},i.prototype.iadd=function(t){var e,r,n;if(0!==this.negative&&0===t.negative)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();this.length>t.length?(r=this,n=t):(r=t,n=this);for(var i=0,o=0;o<n.length;o++)e=(0|r.words[o])+(0|n.words[o])+i,this.words[o]=67108863&e,i=e>>>26;for(;0!==i&&o<r.length;o++)e=(0|r.words[o])+i,this.words[o]=67108863&e,i=e>>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this},i.prototype.add=function(t){var e;return 0!==t.negative&&0===this.negative?(t.negative=0,e=this.sub(t),t.negative^=1,e):0===t.negative&&0!==this.negative?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},i.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,n,i=this.cmp(t);if(0===i)return this.negative=0,this.length=1,this.words[0]=0,this;i>0?(r=this,n=t):(r=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(e=(0|r.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&e;for(;0!==o&&s<r.length;s++)o=(e=(0|r.words[s])+o)>>26,this.words[s]=67108863&e;if(0===o&&s<r.length&&r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this.length=Math.max(this.length,s),r!==this&&(this.negative=1),this._strip()},i.prototype.sub=function(t){return this.clone().isub(t)};var m=function(t,e,r){var n,i,o,s=t.words,u=e.words,a=r.words,h=0,l=0|s[0],c=8191&l,f=l>>>13,d=0|s[1],p=8191&d,m=d>>>13,g=0|s[2],y=8191&g,w=g>>>13,v=0|s[3],b=8191&v,M=v>>>13,P=0|s[4],k=8191&P,A=P>>>13,E=0|s[5],_=8191&E,S=E>>>13,T=0|s[6],I=8191&T,x=T>>>13,B=0|s[7],L=8191&B,C=B>>>13,R=0|s[8],O=8191&R,U=R>>>13,D=0|s[9],W=8191&D,Y=D>>>13,N=0|u[0],q=8191&N,j=N>>>13,K=0|u[1],V=8191&K,Z=K>>>13,z=0|u[2],F=8191&z,G=z>>>13,Q=0|u[3],$=8191&Q,H=Q>>>13,J=0|u[4],X=8191&J,tt=J>>>13,et=0|u[5],rt=8191&et,nt=et>>>13,it=0|u[6],ot=8191&it,st=it>>>13,ut=0|u[7],at=8191&ut,ht=ut>>>13,lt=0|u[8],ct=8191<,ft=lt>>>13,dt=0|u[9],pt=8191&dt,mt=dt>>>13;r.negative=t.negative^e.negative,r.length=19;var gt=(h+(n=Math.imul(c,q))|0)+((8191&(i=(i=Math.imul(c,j))+Math.imul(f,q)|0))<<13)|0;h=((o=Math.imul(f,j))+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(p,q),i=(i=Math.imul(p,j))+Math.imul(m,q)|0,o=Math.imul(m,j);var yt=(h+(n=n+Math.imul(c,V)|0)|0)+((8191&(i=(i=i+Math.imul(c,Z)|0)+Math.imul(f,V)|0))<<13)|0;h=((o=o+Math.imul(f,Z)|0)+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(y,q),i=(i=Math.imul(y,j))+Math.imul(w,q)|0,o=Math.imul(w,j),n=n+Math.imul(p,V)|0,i=(i=i+Math.imul(p,Z)|0)+Math.imul(m,V)|0,o=o+Math.imul(m,Z)|0;var wt=(h+(n=n+Math.imul(c,F)|0)|0)+((8191&(i=(i=i+Math.imul(c,G)|0)+Math.imul(f,F)|0))<<13)|0;h=((o=o+Math.imul(f,G)|0)+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(b,q),i=(i=Math.imul(b,j))+Math.imul(M,q)|0,o=Math.imul(M,j),n=n+Math.imul(y,V)|0,i=(i=i+Math.imul(y,Z)|0)+Math.imul(w,V)|0,o=o+Math.imul(w,Z)|0,n=n+Math.imul(p,F)|0,i=(i=i+Math.imul(p,G)|0)+Math.imul(m,F)|0,o=o+Math.imul(m,G)|0;var vt=(h+(n=n+Math.imul(c,$)|0)|0)+((8191&(i=(i=i+Math.imul(c,H)|0)+Math.imul(f,$)|0))<<13)|0;h=((o=o+Math.imul(f,H)|0)+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(k,q),i=(i=Math.imul(k,j))+Math.imul(A,q)|0,o=Math.imul(A,j),n=n+Math.imul(b,V)|0,i=(i=i+Math.imul(b,Z)|0)+Math.imul(M,V)|0,o=o+Math.imul(M,Z)|0,n=n+Math.imul(y,F)|0,i=(i=i+Math.imul(y,G)|0)+Math.imul(w,F)|0,o=o+Math.imul(w,G)|0,n=n+Math.imul(p,$)|0,i=(i=i+Math.imul(p,H)|0)+Math.imul(m,$)|0,o=o+Math.imul(m,H)|0;var bt=(h+(n=n+Math.imul(c,X)|0)|0)+((8191&(i=(i=i+Math.imul(c,tt)|0)+Math.imul(f,X)|0))<<13)|0;h=((o=o+Math.imul(f,tt)|0)+(i>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(_,q),i=(i=Math.imul(_,j))+Math.imul(S,q)|0,o=Math.imul(S,j),n=n+Math.imul(k,V)|0,i=(i=i+Math.imul(k,Z)|0)+Math.imul(A,V)|0,o=o+Math.imul(A,Z)|0,n=n+Math.imul(b,F)|0,i=(i=i+Math.imul(b,G)|0)+Math.imul(M,F)|0,o=o+Math.imul(M,G)|0,n=n+Math.imul(y,$)|0,i=(i=i+Math.imul(y,H)|0)+Math.imul(w,$)|0,o=o+Math.imul(w,H)|0,n=n+Math.imul(p,X)|0,i=(i=i+Math.imul(p,tt)|0)+Math.imul(m,X)|0,o=o+Math.imul(m,tt)|0;var Mt=(h+(n=n+Math.imul(c,rt)|0)|0)+((8191&(i=(i=i+Math.imul(c,nt)|0)+Math.imul(f,rt)|0))<<13)|0;h=((o=o+Math.imul(f,nt)|0)+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(I,q),i=(i=Math.imul(I,j))+Math.imul(x,q)|0,o=Math.imul(x,j),n=n+Math.imul(_,V)|0,i=(i=i+Math.imul(_,Z)|0)+Math.imul(S,V)|0,o=o+Math.imul(S,Z)|0,n=n+Math.imul(k,F)|0,i=(i=i+Math.imul(k,G)|0)+Math.imul(A,F)|0,o=o+Math.imul(A,G)|0,n=n+Math.imul(b,$)|0,i=(i=i+Math.imul(b,H)|0)+Math.imul(M,$)|0,o=o+Math.imul(M,H)|0,n=n+Math.imul(y,X)|0,i=(i=i+Math.imul(y,tt)|0)+Math.imul(w,X)|0,o=o+Math.imul(w,tt)|0,n=n+Math.imul(p,rt)|0,i=(i=i+Math.imul(p,nt)|0)+Math.imul(m,rt)|0,o=o+Math.imul(m,nt)|0;var Pt=(h+(n=n+Math.imul(c,ot)|0)|0)+((8191&(i=(i=i+Math.imul(c,st)|0)+Math.imul(f,ot)|0))<<13)|0;h=((o=o+Math.imul(f,st)|0)+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(L,q),i=(i=Math.imul(L,j))+Math.imul(C,q)|0,o=Math.imul(C,j),n=n+Math.imul(I,V)|0,i=(i=i+Math.imul(I,Z)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,Z)|0,n=n+Math.imul(_,F)|0,i=(i=i+Math.imul(_,G)|0)+Math.imul(S,F)|0,o=o+Math.imul(S,G)|0,n=n+Math.imul(k,$)|0,i=(i=i+Math.imul(k,H)|0)+Math.imul(A,$)|0,o=o+Math.imul(A,H)|0,n=n+Math.imul(b,X)|0,i=(i=i+Math.imul(b,tt)|0)+Math.imul(M,X)|0,o=o+Math.imul(M,tt)|0,n=n+Math.imul(y,rt)|0,i=(i=i+Math.imul(y,nt)|0)+Math.imul(w,rt)|0,o=o+Math.imul(w,nt)|0,n=n+Math.imul(p,ot)|0,i=(i=i+Math.imul(p,st)|0)+Math.imul(m,ot)|0,o=o+Math.imul(m,st)|0;var kt=(h+(n=n+Math.imul(c,at)|0)|0)+((8191&(i=(i=i+Math.imul(c,ht)|0)+Math.imul(f,at)|0))<<13)|0;h=((o=o+Math.imul(f,ht)|0)+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(O,q),i=(i=Math.imul(O,j))+Math.imul(U,q)|0,o=Math.imul(U,j),n=n+Math.imul(L,V)|0,i=(i=i+Math.imul(L,Z)|0)+Math.imul(C,V)|0,o=o+Math.imul(C,Z)|0,n=n+Math.imul(I,F)|0,i=(i=i+Math.imul(I,G)|0)+Math.imul(x,F)|0,o=o+Math.imul(x,G)|0,n=n+Math.imul(_,$)|0,i=(i=i+Math.imul(_,H)|0)+Math.imul(S,$)|0,o=o+Math.imul(S,H)|0,n=n+Math.imul(k,X)|0,i=(i=i+Math.imul(k,tt)|0)+Math.imul(A,X)|0,o=o+Math.imul(A,tt)|0,n=n+Math.imul(b,rt)|0,i=(i=i+Math.imul(b,nt)|0)+Math.imul(M,rt)|0,o=o+Math.imul(M,nt)|0,n=n+Math.imul(y,ot)|0,i=(i=i+Math.imul(y,st)|0)+Math.imul(w,ot)|0,o=o+Math.imul(w,st)|0,n=n+Math.imul(p,at)|0,i=(i=i+Math.imul(p,ht)|0)+Math.imul(m,at)|0,o=o+Math.imul(m,ht)|0;var At=(h+(n=n+Math.imul(c,ct)|0)|0)+((8191&(i=(i=i+Math.imul(c,ft)|0)+Math.imul(f,ct)|0))<<13)|0;h=((o=o+Math.imul(f,ft)|0)+(i>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(W,q),i=(i=Math.imul(W,j))+Math.imul(Y,q)|0,o=Math.imul(Y,j),n=n+Math.imul(O,V)|0,i=(i=i+Math.imul(O,Z)|0)+Math.imul(U,V)|0,o=o+Math.imul(U,Z)|0,n=n+Math.imul(L,F)|0,i=(i=i+Math.imul(L,G)|0)+Math.imul(C,F)|0,o=o+Math.imul(C,G)|0,n=n+Math.imul(I,$)|0,i=(i=i+Math.imul(I,H)|0)+Math.imul(x,$)|0,o=o+Math.imul(x,H)|0,n=n+Math.imul(_,X)|0,i=(i=i+Math.imul(_,tt)|0)+Math.imul(S,X)|0,o=o+Math.imul(S,tt)|0,n=n+Math.imul(k,rt)|0,i=(i=i+Math.imul(k,nt)|0)+Math.imul(A,rt)|0,o=o+Math.imul(A,nt)|0,n=n+Math.imul(b,ot)|0,i=(i=i+Math.imul(b,st)|0)+Math.imul(M,ot)|0,o=o+Math.imul(M,st)|0,n=n+Math.imul(y,at)|0,i=(i=i+Math.imul(y,ht)|0)+Math.imul(w,at)|0,o=o+Math.imul(w,ht)|0,n=n+Math.imul(p,ct)|0,i=(i=i+Math.imul(p,ft)|0)+Math.imul(m,ct)|0,o=o+Math.imul(m,ft)|0;var Et=(h+(n=n+Math.imul(c,pt)|0)|0)+((8191&(i=(i=i+Math.imul(c,mt)|0)+Math.imul(f,pt)|0))<<13)|0;h=((o=o+Math.imul(f,mt)|0)+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,n=Math.imul(W,V),i=(i=Math.imul(W,Z))+Math.imul(Y,V)|0,o=Math.imul(Y,Z),n=n+Math.imul(O,F)|0,i=(i=i+Math.imul(O,G)|0)+Math.imul(U,F)|0,o=o+Math.imul(U,G)|0,n=n+Math.imul(L,$)|0,i=(i=i+Math.imul(L,H)|0)+Math.imul(C,$)|0,o=o+Math.imul(C,H)|0,n=n+Math.imul(I,X)|0,i=(i=i+Math.imul(I,tt)|0)+Math.imul(x,X)|0,o=o+Math.imul(x,tt)|0,n=n+Math.imul(_,rt)|0,i=(i=i+Math.imul(_,nt)|0)+Math.imul(S,rt)|0,o=o+Math.imul(S,nt)|0,n=n+Math.imul(k,ot)|0,i=(i=i+Math.imul(k,st)|0)+Math.imul(A,ot)|0,o=o+Math.imul(A,st)|0,n=n+Math.imul(b,at)|0,i=(i=i+Math.imul(b,ht)|0)+Math.imul(M,at)|0,o=o+Math.imul(M,ht)|0,n=n+Math.imul(y,ct)|0,i=(i=i+Math.imul(y,ft)|0)+Math.imul(w,ct)|0,o=o+Math.imul(w,ft)|0;var _t=(h+(n=n+Math.imul(p,pt)|0)|0)+((8191&(i=(i=i+Math.imul(p,mt)|0)+Math.imul(m,pt)|0))<<13)|0;h=((o=o+Math.imul(m,mt)|0)+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(W,F),i=(i=Math.imul(W,G))+Math.imul(Y,F)|0,o=Math.imul(Y,G),n=n+Math.imul(O,$)|0,i=(i=i+Math.imul(O,H)|0)+Math.imul(U,$)|0,o=o+Math.imul(U,H)|0,n=n+Math.imul(L,X)|0,i=(i=i+Math.imul(L,tt)|0)+Math.imul(C,X)|0,o=o+Math.imul(C,tt)|0,n=n+Math.imul(I,rt)|0,i=(i=i+Math.imul(I,nt)|0)+Math.imul(x,rt)|0,o=o+Math.imul(x,nt)|0,n=n+Math.imul(_,ot)|0,i=(i=i+Math.imul(_,st)|0)+Math.imul(S,ot)|0,o=o+Math.imul(S,st)|0,n=n+Math.imul(k,at)|0,i=(i=i+Math.imul(k,ht)|0)+Math.imul(A,at)|0,o=o+Math.imul(A,ht)|0,n=n+Math.imul(b,ct)|0,i=(i=i+Math.imul(b,ft)|0)+Math.imul(M,ct)|0,o=o+Math.imul(M,ft)|0;var St=(h+(n=n+Math.imul(y,pt)|0)|0)+((8191&(i=(i=i+Math.imul(y,mt)|0)+Math.imul(w,pt)|0))<<13)|0;h=((o=o+Math.imul(w,mt)|0)+(i>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(W,$),i=(i=Math.imul(W,H))+Math.imul(Y,$)|0,o=Math.imul(Y,H),n=n+Math.imul(O,X)|0,i=(i=i+Math.imul(O,tt)|0)+Math.imul(U,X)|0,o=o+Math.imul(U,tt)|0,n=n+Math.imul(L,rt)|0,i=(i=i+Math.imul(L,nt)|0)+Math.imul(C,rt)|0,o=o+Math.imul(C,nt)|0,n=n+Math.imul(I,ot)|0,i=(i=i+Math.imul(I,st)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,st)|0,n=n+Math.imul(_,at)|0,i=(i=i+Math.imul(_,ht)|0)+Math.imul(S,at)|0,o=o+Math.imul(S,ht)|0,n=n+Math.imul(k,ct)|0,i=(i=i+Math.imul(k,ft)|0)+Math.imul(A,ct)|0,o=o+Math.imul(A,ft)|0;var Tt=(h+(n=n+Math.imul(b,pt)|0)|0)+((8191&(i=(i=i+Math.imul(b,mt)|0)+Math.imul(M,pt)|0))<<13)|0;h=((o=o+Math.imul(M,mt)|0)+(i>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(W,X),i=(i=Math.imul(W,tt))+Math.imul(Y,X)|0,o=Math.imul(Y,tt),n=n+Math.imul(O,rt)|0,i=(i=i+Math.imul(O,nt)|0)+Math.imul(U,rt)|0,o=o+Math.imul(U,nt)|0,n=n+Math.imul(L,ot)|0,i=(i=i+Math.imul(L,st)|0)+Math.imul(C,ot)|0,o=o+Math.imul(C,st)|0,n=n+Math.imul(I,at)|0,i=(i=i+Math.imul(I,ht)|0)+Math.imul(x,at)|0,o=o+Math.imul(x,ht)|0,n=n+Math.imul(_,ct)|0,i=(i=i+Math.imul(_,ft)|0)+Math.imul(S,ct)|0,o=o+Math.imul(S,ft)|0;var It=(h+(n=n+Math.imul(k,pt)|0)|0)+((8191&(i=(i=i+Math.imul(k,mt)|0)+Math.imul(A,pt)|0))<<13)|0;h=((o=o+Math.imul(A,mt)|0)+(i>>>13)|0)+(It>>>26)|0,It&=67108863,n=Math.imul(W,rt),i=(i=Math.imul(W,nt))+Math.imul(Y,rt)|0,o=Math.imul(Y,nt),n=n+Math.imul(O,ot)|0,i=(i=i+Math.imul(O,st)|0)+Math.imul(U,ot)|0,o=o+Math.imul(U,st)|0,n=n+Math.imul(L,at)|0,i=(i=i+Math.imul(L,ht)|0)+Math.imul(C,at)|0,o=o+Math.imul(C,ht)|0,n=n+Math.imul(I,ct)|0,i=(i=i+Math.imul(I,ft)|0)+Math.imul(x,ct)|0,o=o+Math.imul(x,ft)|0;var xt=(h+(n=n+Math.imul(_,pt)|0)|0)+((8191&(i=(i=i+Math.imul(_,mt)|0)+Math.imul(S,pt)|0))<<13)|0;h=((o=o+Math.imul(S,mt)|0)+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(W,ot),i=(i=Math.imul(W,st))+Math.imul(Y,ot)|0,o=Math.imul(Y,st),n=n+Math.imul(O,at)|0,i=(i=i+Math.imul(O,ht)|0)+Math.imul(U,at)|0,o=o+Math.imul(U,ht)|0,n=n+Math.imul(L,ct)|0,i=(i=i+Math.imul(L,ft)|0)+Math.imul(C,ct)|0,o=o+Math.imul(C,ft)|0;var Bt=(h+(n=n+Math.imul(I,pt)|0)|0)+((8191&(i=(i=i+Math.imul(I,mt)|0)+Math.imul(x,pt)|0))<<13)|0;h=((o=o+Math.imul(x,mt)|0)+(i>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,n=Math.imul(W,at),i=(i=Math.imul(W,ht))+Math.imul(Y,at)|0,o=Math.imul(Y,ht),n=n+Math.imul(O,ct)|0,i=(i=i+Math.imul(O,ft)|0)+Math.imul(U,ct)|0,o=o+Math.imul(U,ft)|0;var Lt=(h+(n=n+Math.imul(L,pt)|0)|0)+((8191&(i=(i=i+Math.imul(L,mt)|0)+Math.imul(C,pt)|0))<<13)|0;h=((o=o+Math.imul(C,mt)|0)+(i>>>13)|0)+(Lt>>>26)|0,Lt&=67108863,n=Math.imul(W,ct),i=(i=Math.imul(W,ft))+Math.imul(Y,ct)|0,o=Math.imul(Y,ft);var Ct=(h+(n=n+Math.imul(O,pt)|0)|0)+((8191&(i=(i=i+Math.imul(O,mt)|0)+Math.imul(U,pt)|0))<<13)|0;h=((o=o+Math.imul(U,mt)|0)+(i>>>13)|0)+(Ct>>>26)|0,Ct&=67108863;var Rt=(h+(n=Math.imul(W,pt))|0)+((8191&(i=(i=Math.imul(W,mt))+Math.imul(Y,pt)|0))<<13)|0;return h=((o=Math.imul(Y,mt))+(i>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,a[0]=gt,a[1]=yt,a[2]=wt,a[3]=vt,a[4]=bt,a[5]=Mt,a[6]=Pt,a[7]=kt,a[8]=At,a[9]=Et,a[10]=_t,a[11]=St,a[12]=Tt,a[13]=It,a[14]=xt,a[15]=Bt,a[16]=Lt,a[17]=Ct,a[18]=Rt,0!==h&&(a[19]=h,r.length++),r};function g(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var n=0,i=0,o=0;o<r.length-1;o++){var s=i;i=0;for(var u=67108863&n,a=Math.min(o,e.length-1),h=Math.max(0,o-t.length+1);h<=a;h++){var l=o-h,c=(0|t.words[l])*(0|e.words[h]),f=67108863&c;u=67108863&(f=f+u|0),i+=(s=(s=s+(c/67108864|0)|0)+(f>>>26)|0)>>>26,s&=67108863}r.words[o]=u,n=s,s=i}return 0!==n?r.words[o]=n:r.length--,r._strip()}function y(t,e,r){return g(t,e,r)}Math.imul||(m=p),i.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?m(this,t,e):r<63?p(this,t,e):r<1024?g(this,t,e):y(this,t,e)},i.prototype.mul=function(t){var e=new i(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},i.prototype.mulf=function(t){var e=new i(null);return e.words=new Array(this.length+t.length),y(this,t,e)},i.prototype.imul=function(t){return this.clone().mulTo(t,this)},i.prototype.imuln=function(t){var e=t<0;e&&(t=-t),r("number"==typeof t),r(t<67108864);for(var n=0,i=0;i<this.length;i++){var o=(0|this.words[i])*t,s=(67108863&o)+(67108863&n);n>>=26,n+=o/67108864|0,n+=s>>>26,this.words[i]=67108863&s}return 0!==n&&(this.words[i]=n,this.length++),e?this.ineg():this},i.prototype.muln=function(t){return this.clone().imuln(t)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r<e.length;r++){var n=r/26|0,i=r%26;e[r]=t.words[n]>>>i&1}return e}(t);if(0===e.length)return new i(1);for(var r=this,n=0;n<e.length&&0===e[n];n++,r=r.sqr());if(++n<e.length)for(var o=r.sqr();n<e.length;n++,o=o.sqr())0!==e[n]&&(r=r.mul(o));return r},i.prototype.iushln=function(t){r("number"==typeof t&&t>=0);var e,n=t%26,i=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(e=0;e<this.length;e++){var u=this.words[e]&o,a=(0|this.words[e])-u<<n;this.words[e]=a|s,s=u>>>26-n}s&&(this.words[e]=s,this.length++)}if(0!==i){for(e=this.length-1;e>=0;e--)this.words[e+i]=this.words[e];for(e=0;e<i;e++)this.words[e]=0;this.length+=i}return this._strip()},i.prototype.ishln=function(t){return r(0===this.negative),this.iushln(t)},i.prototype.iushrn=function(t,e,n){var i;r("number"==typeof t&&t>=0),i=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),u=67108863^67108863>>>o<<o,a=n;if(i-=s,i=Math.max(0,i),a){for(var h=0;h<s;h++)a.words[h]=this.words[h];a.length=s}if(0===s);else if(this.length>s)for(this.length-=s,h=0;h<this.length;h++)this.words[h]=this.words[h+s];else this.words[0]=0,this.length=1;var l=0;for(h=this.length-1;h>=0&&(0!==l||h>=i);h--){var c=0|this.words[h];this.words[h]=l<<26-o|c>>>o,l=c&u}return a&&0!==l&&(a.words[a.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.ishrn=function(t,e,n){return r(0===this.negative),this.iushrn(t,e,n)},i.prototype.shln=function(t){return this.clone().ishln(t)},i.prototype.ushln=function(t){return this.clone().iushln(t)},i.prototype.shrn=function(t){return this.clone().ishrn(t)},i.prototype.ushrn=function(t){return this.clone().iushrn(t)},i.prototype.testn=function(t){r("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26,i=1<<e;return this.length<=n?0:!!(this.words[n]&i)},i.prototype.imaskn=function(t){r("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==e&&n++,this.length=Math.min(n,this.length),0!==e){var i=67108863^67108863>>>e<<e;this.words[this.length-1]&=i}return this._strip()},i.prototype.maskn=function(t){return this.clone().imaskn(t)},i.prototype.iaddn=function(t){return r("number"==typeof t),r(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<=t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},i.prototype._iaddn=function(t){this.words[0]+=t;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},i.prototype.isubn=function(t){if(r("number"==typeof t),r(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this._strip()},i.prototype.addn=function(t){return this.clone().iaddn(t)},i.prototype.subn=function(t){return this.clone().isubn(t)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(t,e,n){var i,o,s=t.length+n;this._expand(s);var u=0;for(i=0;i<t.length;i++){o=(0|this.words[i+n])+u;var a=(0|t.words[i])*e;u=((o-=67108863&a)>>26)-(a/67108864|0),this.words[i+n]=67108863&o}for(;i<this.length-n;i++)u=(o=(0|this.words[i+n])+u)>>26,this.words[i+n]=67108863&o;if(0===u)return this._strip();for(r(-1===u),u=0,i=0;i<this.length;i++)u=(o=-(0|this.words[i])+u)>>26,this.words[i]=67108863&o;return this.negative=1,this._strip()},i.prototype._wordDiv=function(t,e){var r=(this.length,t.length),n=this.clone(),o=t,s=0|o.words[o.length-1];0!=(r=26-this._countBits(s))&&(o=o.ushln(r),n.iushln(r),s=0|o.words[o.length-1]);var u,a=n.length-o.length;if("mod"!==e){(u=new i(null)).length=a+1,u.words=new Array(u.length);for(var h=0;h<u.length;h++)u.words[h]=0}var l=n.clone()._ishlnsubmul(o,1,a);0===l.negative&&(n=l,u&&(u.words[a]=1));for(var c=a-1;c>=0;c--){var f=67108864*(0|n.words[o.length+c])+(0|n.words[o.length+c-1]);for(f=Math.min(f/s|0,67108863),n._ishlnsubmul(o,f,c);0!==n.negative;)f--,n.negative=0,n._ishlnsubmul(o,1,c),n.isZero()||(n.negative^=1);u&&(u.words[c]=f)}return u&&u._strip(),n._strip(),"div"!==e&&0!==r&&n.iushrn(r),{div:u||null,mod:n}},i.prototype.divmod=function(t,e,n){return r(!t.isZero()),this.isZero()?{div:new i(0),mod:new i(0)}:0!==this.negative&&0===t.negative?(u=this.neg().divmod(t,e),"mod"!==e&&(o=u.div.neg()),"div"!==e&&(s=u.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:o,mod:s}):0===this.negative&&0!==t.negative?(u=this.divmod(t.neg(),e),"mod"!==e&&(o=u.div.neg()),{div:o,mod:u.mod}):0!=(this.negative&t.negative)?(u=this.neg().divmod(t.neg(),e),"div"!==e&&(s=u.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:u.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new i(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new i(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new i(this.modrn(t.words[0]))}:this._wordDiv(t,e);var o,s,u},i.prototype.div=function(t){return this.divmod(t,"div",0).div},i.prototype.mod=function(t){return this.divmod(t,"mod",0).mod},i.prototype.umod=function(t){return this.divmod(t,"mod",1).mod},i.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),i=t.andln(1),o=r.cmp(n);return o<0||1===i&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},i.prototype.modrn=function(t){var e=t<0;e&&(t=-t),r(t<=67108863);for(var n=(1<<26)%t,i=0,o=this.length-1;o>=0;o--)i=(n*i+(0|this.words[o]))%t;return e?-i:i},i.prototype.modn=function(t){return this.modrn(t)},i.prototype.idivn=function(t){var e=t<0;e&&(t=-t),r(t<=67108863);for(var n=0,i=this.length-1;i>=0;i--){var o=(0|this.words[i])+67108864*n;this.words[i]=o/t|0,n=o%t}return this._strip(),e?this.ineg():this},i.prototype.divn=function(t){return this.clone().idivn(t)},i.prototype.egcd=function(t){r(0===t.negative),r(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o=new i(1),s=new i(0),u=new i(0),a=new i(1),h=0;e.isEven()&&n.isEven();)e.iushrn(1),n.iushrn(1),++h;for(var l=n.clone(),c=e.clone();!e.isZero();){for(var f=0,d=1;0==(e.words[0]&d)&&f<26;++f,d<<=1);if(f>0)for(e.iushrn(f);f-- >0;)(o.isOdd()||s.isOdd())&&(o.iadd(l),s.isub(c)),o.iushrn(1),s.iushrn(1);for(var p=0,m=1;0==(n.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(u.isOdd()||a.isOdd())&&(u.iadd(l),a.isub(c)),u.iushrn(1),a.iushrn(1);e.cmp(n)>=0?(e.isub(n),o.isub(u),s.isub(a)):(n.isub(e),u.isub(o),a.isub(s))}return{a:u,b:a,gcd:n.iushln(h)}},i.prototype._invmp=function(t){r(0===t.negative),r(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o,s=new i(1),u=new i(0),a=n.clone();e.cmpn(1)>0&&n.cmpn(1)>0;){for(var h=0,l=1;0==(e.words[0]&l)&&h<26;++h,l<<=1);if(h>0)for(e.iushrn(h);h-- >0;)s.isOdd()&&s.iadd(a),s.iushrn(1);for(var c=0,f=1;0==(n.words[0]&f)&&c<26;++c,f<<=1);if(c>0)for(n.iushrn(c);c-- >0;)u.isOdd()&&u.iadd(a),u.iushrn(1);e.cmp(n)>=0?(e.isub(n),s.isub(u)):(n.isub(e),u.isub(s))}return(o=0===e.cmpn(1)?s:u).cmpn(0)<0&&o.iadd(t),o},i.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var n=0;e.isEven()&&r.isEven();n++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var i=e.cmp(r);if(i<0){var o=e;e=r,r=o}else if(0===i||0===r.cmpn(1))break;e.isub(r)}return r.iushln(n)},i.prototype.invm=function(t){return this.egcd(t).a.umod(t)},i.prototype.isEven=function(){return 0==(1&this.words[0])},i.prototype.isOdd=function(){return 1==(1&this.words[0])},i.prototype.andln=function(t){return this.words[0]&t},i.prototype.bincn=function(t){r("number"==typeof t);var e=t%26,n=(t-e)/26,i=1<<e;if(this.length<=n)return this._expand(n+1),this.words[n]|=i,this;for(var o=i,s=n;0!==o&&s<this.length;s++){var u=0|this.words[s];o=(u+=o)>>>26,u&=67108863,this.words[s]=u}return 0!==o&&(this.words[s]=o,this.length++),this},i.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},i.prototype.cmpn=function(t){var e,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this._strip(),this.length>1)e=1;else{n&&(t=-t),r(t<=67108863,"Number is too big");var i=0|this.words[0];e=i===t?0:i<t?-1:1}return 0!==this.negative?0|-e:e},i.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var e=this.ucmp(t);return 0!==this.negative?0|-e:e},i.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],i=0|t.words[r];if(n!==i){n<i?e=-1:n>i&&(e=1);break}}return e},i.prototype.gtn=function(t){return 1===this.cmpn(t)},i.prototype.gt=function(t){return 1===this.cmp(t)},i.prototype.gten=function(t){return this.cmpn(t)>=0},i.prototype.gte=function(t){return this.cmp(t)>=0},i.prototype.ltn=function(t){return-1===this.cmpn(t)},i.prototype.lt=function(t){return-1===this.cmp(t)},i.prototype.lten=function(t){return this.cmpn(t)<=0},i.prototype.lte=function(t){return this.cmp(t)<=0},i.prototype.eqn=function(t){return 0===this.cmpn(t)},i.prototype.eq=function(t){return 0===this.cmp(t)},i.red=function(t){return new A(t)},i.prototype.toRed=function(t){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},i.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(t){return this.red=t,this},i.prototype.forceRed=function(t){return r(!this.red,"Already a number in reduction context"),this._forceRed(t)},i.prototype.redAdd=function(t){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},i.prototype.redIAdd=function(t){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},i.prototype.redSub=function(t){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},i.prototype.redISub=function(t){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},i.prototype.redShl=function(t){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},i.prototype.redMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},i.prototype.redIMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},i.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(t){return r(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var w={k256:null,p224:null,p192:null,p25519:null};function v(t,e){this.name=t,this.p=new i(e,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function b(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function M(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function P(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function k(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function A(t){if("string"==typeof t){var e=i._prime(t);this.m=e.p,this.prime=e}else r(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function E(t){A.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}v.prototype._tmp=function(){var t=new i(null);return t.words=new Array(Math.ceil(this.n/13)),t},v.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(t,e){t.iushrn(this.n,0,e)},v.prototype.imulK=function(t){return t.imul(this.k)},n(b,v),b.prototype.split=function(t,e){for(var r=4194303,n=Math.min(t.length,9),i=0;i<n;i++)e.words[i]=t.words[i];if(e.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var o=t.words[9];for(e.words[e.length++]=o&r,i=10;i<t.length;i++){var s=0|t.words[i];t.words[i-10]=(s&r)<<4|o>>>22,o=s}o>>>=22,t.words[i-10]=o,0===o&&t.length>10?t.length-=10:t.length-=9},b.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r<t.length;r++){var n=0|t.words[r];e+=977*n,t.words[r]=67108863&e,e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(M,v),n(P,v),n(k,v),k.prototype.imulK=function(t){for(var e=0,r=0;r<t.length;r++){var n=19*(0|t.words[r])+e,i=67108863&n;n>>>=26,t.words[r]=i,e=n}return 0!==e&&(t.words[t.length++]=e),t},i._prime=function(t){if(w[t])return w[t];var e;if("k256"===t)e=new b;else if("p224"===t)e=new M;else if("p192"===t)e=new P;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new k}return w[t]=e,e},A.prototype._verify1=function(t){r(0===t.negative,"red works only with positives"),r(t.red,"red works only with red numbers")},A.prototype._verify2=function(t,e){r(0==(t.negative|e.negative),"red works only with positives"),r(t.red&&t.red===e.red,"red works only with red numbers")},A.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(h(t,t.umod(this.m)._forceRed(this)),t)},A.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},A.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},A.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},A.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},A.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},A.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},A.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},A.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},A.prototype.isqr=function(t){return this.imul(t,t.clone())},A.prototype.sqr=function(t){return this.mul(t,t)},A.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(r(e%2==1),3===e){var n=this.m.add(new i(1)).iushrn(2);return this.pow(t,n)}for(var o=this.m.subn(1),s=0;!o.isZero()&&0===o.andln(1);)s++,o.iushrn(1);r(!o.isZero());var u=new i(1).toRed(this),a=u.redNeg(),h=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new i(2*l*l).toRed(this);0!==this.pow(l,h).cmp(a);)l.redIAdd(a);for(var c=this.pow(l,o),f=this.pow(t,o.addn(1).iushrn(1)),d=this.pow(t,o),p=s;0!==d.cmp(u);){for(var m=d,g=0;0!==m.cmp(u);g++)m=m.redSqr();r(g<p);var y=this.pow(c,new i(1).iushln(p-g-1));f=f.redMul(y),c=y.redSqr(),d=d.redMul(c),p=g}return f},A.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},A.prototype.pow=function(t,e){if(e.isZero())return new i(1).toRed(this);if(0===e.cmpn(1))return t.clone();var r=new Array(16);r[0]=new i(1).toRed(this),r[1]=t;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],t);var o=r[0],s=0,u=0,a=e.bitLength()%26;for(0===a&&(a=26),n=e.length-1;n>=0;n--){for(var h=e.words[n],l=a-1;l>=0;l--){var c=h>>l&1;o!==r[0]&&(o=this.sqr(o)),0!==c||0!==s?(s<<=1,s|=c,(4==++u||0===n&&0===l)&&(o=this.mul(o,r[s]),u=0,s=0)):u=0}a=26}return o},A.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},A.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},i.mont=function(t){return new E(t)},n(E,A),E.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},E.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},E.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),o=i;return i.cmp(this.m)>=0?o=i.isub(this.m):i.cmpn(0)<0&&(o=i.iadd(this.m)),o._forceRed(this)},E.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new i(0)._forceRed(this);var r=t.mul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},E.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,x);var Rt=C.exports,Ot=B(Rt),Ut={},Dt={};class Wt{constructor(t,e){if(!Number.isInteger(t))throw new TypeError("span must be an integer");this.span=t,this.property=e}makeDestinationObject(){return{}}decode(t,e){throw new Error("Layout is abstract")}encode(t,e,r){throw new Error("Layout is abstract")}getSpan(t,e){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(t){const e=Object.create(this.constructor.prototype);return Object.assign(e,this),e.property=t,e}fromArray(t){}}function Yt(t,e){return e.property?t+"["+e.property+"]":t}Dt.Layout=Wt,Dt.nameWithProperty=Yt,Dt.bindConstructorLayout=function(t,e){if("function"!=typeof t)throw new TypeError("Class must be constructor");if(t.hasOwnProperty("layout_"))throw new Error("Class is already bound to a layout");if(!(e&&e instanceof Wt))throw new TypeError("layout must be a Layout");if(e.hasOwnProperty("boundConstructor_"))throw new Error("layout is already bound to a constructor");t.layout_=e,e.boundConstructor_=t,e.makeDestinationObject=()=>new t,Object.defineProperty(t.prototype,"encode",{value:function(t,r){return e.encode(this,t,r)},writable:1}),Object.defineProperty(t,"decode",{value:function(t,r){return e.decode(t,r)},writable:1})};class Nt extends Wt{isCount(){throw new Error("ExternalLayout is abstract")}}class qt extends Nt{constructor(t,e){if(void 0===t&&(t=1),!Number.isInteger(t)||0>=t)throw new TypeError("elementSpan must be a (positive) integer");super(-1,e),this.elementSpan=t}isCount(){return 1}decode(t,e){void 0===e&&(e=0);const r=t.length-e;return Math.floor(r/this.elementSpan)}encode(t,e,r){return 0}}class jt extends Nt{constructor(t,e,r){if(!(t instanceof Wt))throw new TypeError("layout must be a Layout");if(void 0===e)e=0;else if(!Number.isInteger(e))throw new TypeError("offset must be integer or undefined");super(t.span,r||t.property),this.layout=t,this.offset=e}isCount(){return this.layout instanceof Kt||this.layout instanceof Vt}decode(t,e){return void 0===e&&(e=0),this.layout.decode(t,e+this.offset)}encode(t,e,r){return void 0===r&&(r=0),this.layout.encode(t,e,r+this.offset)}}class Kt extends Wt{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e){return void 0===e&&(e=0),t.readUIntLE(e,this.span)}encode(t,e,r){return void 0===r&&(r=0),e.writeUIntLE(t,r,this.span),this.span}}class Vt extends Wt{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e){return void 0===e&&(e=0),t.readUIntBE(e,this.span)}encode(t,e,r){return void 0===r&&(r=0),e.writeUIntBE(t,r,this.span),this.span}}class Zt extends Wt{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e){return void 0===e&&(e=0),t.readIntLE(e,this.span)}encode(t,e,r){return void 0===r&&(r=0),e.writeIntLE(t,r,this.span),this.span}}class zt extends Wt{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e){return void 0===e&&(e=0),t.readIntBE(e,this.span)}encode(t,e,r){return void 0===r&&(r=0),e.writeIntBE(t,r,this.span),this.span}}const Ft=Math.pow(2,32);function Gt(t){const e=Math.floor(t/Ft);return{hi32:e,lo32:t-e*Ft}}function Qt(t,e){return t*Ft+e}class $t extends Wt{constructor(t){super(8,t)}decode(t,e){void 0===e&&(e=0);const r=t.readUInt32LE(e);return Qt(t.readUInt32LE(e+4),r)}encode(t,e,r){void 0===r&&(r=0);const n=Gt(t);return e.writeUInt32LE(n.lo32,r),e.writeUInt32LE(n.hi32,r+4),8}}class Ht extends Wt{constructor(t){super(8,t)}decode(t,e){return void 0===e&&(e=0),Qt(t.readUInt32BE(e),t.readUInt32BE(e+4))}encode(t,e,r){void 0===r&&(r=0);const n=Gt(t);return e.writeUInt32BE(n.hi32,r),e.writeUInt32BE(n.lo32,r+4),8}}class Jt extends Wt{constructor(t){super(8,t)}decode(t,e){void 0===e&&(e=0);const r=t.readUInt32LE(e);return Qt(t.readInt32LE(e+4),r)}encode(t,e,r){void 0===r&&(r=0);const n=Gt(t);return e.writeUInt32LE(n.lo32,r),e.writeInt32LE(n.hi32,r+4),8}}class Xt extends Wt{constructor(t){super(8,t)}decode(t,e){return void 0===e&&(e=0),Qt(t.readInt32BE(e),t.readUInt32BE(e+4))}encode(t,e,r){void 0===r&&(r=0);const n=Gt(t);return e.writeInt32BE(n.hi32,r),e.writeUInt32BE(n.lo32,r+4),8}}class te extends Wt{constructor(t){super(4,t)}decode(t,e){return void 0===e&&(e=0),t.readFloatLE(e)}encode(t,e,r){return void 0===r&&(r=0),e.writeFloatLE(t,r),4}}class ee extends Wt{constructor(t){super(4,t)}decode(t,e){return void 0===e&&(e=0),t.readFloatBE(e)}encode(t,e,r){return void 0===r&&(r=0),e.writeFloatBE(t,r),4}}class re extends Wt{constructor(t){super(8,t)}decode(t,e){return void 0===e&&(e=0),t.readDoubleLE(e)}encode(t,e,r){return void 0===r&&(r=0),e.writeDoubleLE(t,r),8}}class ne extends Wt{constructor(t){super(8,t)}decode(t,e){return void 0===e&&(e=0),t.readDoubleBE(e)}encode(t,e,r){return void 0===r&&(r=0),e.writeDoubleBE(t,r),8}}class ie extends Wt{constructor(t,e,r){if(!(t instanceof Wt))throw new TypeError("elementLayout must be a Layout");if(!(e instanceof Nt&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let n=-1;!(e instanceof Nt)&&0<t.span&&(n=e*t.span),super(n,r),this.elementLayout=t,this.count=e}getSpan(t,e){if(0<=this.span)return this.span;void 0===e&&(e=0);let r=0,n=this.count;if(n instanceof Nt&&(n=n.decode(t,e)),0<this.elementLayout.span)r=n*this.elementLayout.span;else{let i=0;for(;i<n;)r+=this.elementLayout.getSpan(t,e+r),++i}return r}decode(t,e){void 0===e&&(e=0);const r=[];let n=0,i=this.count;for(i instanceof Nt&&(i=i.decode(t,e));n<i;)r.push(this.elementLayout.decode(t,e)),e+=this.elementLayout.getSpan(t,e),n+=1;return r}encode(t,e,r){void 0===r&&(r=0);const n=this.elementLayout,i=t.reduce(((t,i)=>t+n.encode(i,e,r+t)),0);return this.count instanceof Nt&&this.count.encode(t.length,e,r),i}}class oe extends Wt{constructor(t,e,r){if(!Array.isArray(t)||!t.reduce(((t,e)=>t&&e instanceof Wt),1))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof e&&void 0===r&&(r=e,e=void 0);for(const e of t)if(0>e.span&&void 0===e.property)throw new Error("fields cannot contain unnamed variable-length layout");let n=-1;try{n=t.reduce(((t,e)=>t+e.getSpan()),0)}catch(t){}super(n,e),this.fields=t,this.decodePrefixes=!!r}getSpan(t,e){if(0<=this.span)return this.span;void 0===e&&(e=0);let r=0;try{r=this.fields.reduce(((r,n)=>{const i=n.getSpan(t,e);return e+=i,r+i}),0)}catch(t){throw new RangeError("indeterminate span")}return r}decode(t,e){void 0===e&&(e=0);const r=this.makeDestinationObject();for(const n of this.fields)if(void 0!==n.property&&(r[n.property]=n.decode(t,e)),e+=n.getSpan(t,e),this.decodePrefixes&&t.length===e)break;return r}encode(t,e,r){void 0===r&&(r=0);const n=r;let i=0,o=0;for(const n of this.fields){let s=n.span;if(o=0<s?s:0,void 0!==n.property){const i=t[n.property];void 0!==i&&(o=n.encode(i,e,r),0>s&&(s=n.getSpan(e,r)))}i=r,r+=s}return i+o-n}fromArray(t){const e=this.makeDestinationObject();for(const r of this.fields)void 0!==r.property&&0<t.length&&(e[r.property]=t.shift());return e}layoutFor(t){if("string"!=typeof t)throw new TypeError("property must be string");for(const e of this.fields)if(e.property===t)return e}offsetOf(t){if("string"!=typeof t)throw new TypeError("property must be string");let e=0;for(const r of this.fields){if(r.property===t)return e;0>r.span?e=-1:0<=e&&(e+=r.span)}}}class se{constructor(t){this.property=t}decode(){throw new Error("UnionDiscriminator is abstract")}encode(){throw new Error("UnionDiscriminator is abstract")}}class ue extends se{constructor(t,e){if(!(t instanceof Nt&&t.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(e||t.property||"variant"),this.layout=t}decode(t,e){return this.layout.decode(t,e)}encode(t,e,r){return this.layout.encode(t,e,r)}}class ae extends Wt{constructor(t,e,r){const n=t instanceof Kt||t instanceof Vt;if(n)t=new ue(new jt(t));else if(t instanceof Nt&&t.isCount())t=new ue(t);else if(!(t instanceof se))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===e&&(e=null),!(null===e||e instanceof Wt))throw new TypeError("defaultLayout must be null or a Layout");if(null!==e){if(0>e.span)throw new Error("defaultLayout must have constant span");void 0===e.property&&(e=e.replicate("content"))}let i=-1;e&&(i=e.span,0<=i&&n&&(i+=t.layout.span)),super(i,r),this.discriminator=t,this.usesPrefixDiscriminator=n,this.defaultLayout=e,this.registry={};let o=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(t){return o(t)},this.configGetSourceVariant=function(t){o=t.bind(this)}}getSpan(t,e){if(0<=this.span)return this.span;void 0===e&&(e=0);const r=this.getVariant(t,e);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(t,e)}defaultGetSourceVariant(t){if(t.hasOwnProperty(this.discriminator.property)){if(this.defaultLayout&&t.hasOwnProperty(this.defaultLayout.property))return;const e=this.registry[t[this.discriminator.property]];if(e&&(!e.layout||t.hasOwnProperty(e.property)))return e}else for(const e in this.registry){const r=this.registry[e];if(t.hasOwnProperty(r.property))return r}throw new Error("unable to infer src variant")}decode(t,e){let r;void 0===e&&(e=0);const n=this.discriminator,i=n.decode(t,e);let o=this.registry[i];if(void 0===o){let s=0;o=this.defaultLayout,this.usesPrefixDiscriminator&&(s=n.layout.span),r=this.makeDestinationObject(),r[n.property]=i,r[o.property]=this.defaultLayout.decode(t,e+s)}else r=o.decode(t,e);return r}encode(t,e,r){void 0===r&&(r=0);const n=this.getSourceVariant(t);if(void 0===n){const n=this.discriminator,i=this.defaultLayout;let o=0;return this.usesPrefixDiscriminator&&(o=n.layout.span),n.encode(t[n.property],e,r),o+i.encode(t[i.property],e,r+o)}return n.encode(t,e,r)}addVariant(t,e,r){const n=new he(this,t,e,r);return this.registry[t]=n,n}getVariant(t,e){let r=t;return Buffer.isBuffer(t)&&(void 0===e&&(e=0),r=this.discriminator.decode(t,e)),this.registry[r]}}class he extends Wt{constructor(t,e,r,n){if(!(t instanceof ae))throw new TypeError("union must be a Union");if(!Number.isInteger(e)||0>e)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof r&&void 0===n&&(n=r,r=null),r){if(!(r instanceof Wt))throw new TypeError("layout must be a Layout");if(null!==t.defaultLayout&&0<=r.span&&r.span>t.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof n)throw new TypeError("variant must have a String property")}let i=t.span;0>t.span&&(i=r?r.span:0,0<=i&&t.usesPrefixDiscriminator&&(i+=t.discriminator.layout.span)),super(i,n),this.union=t,this.variant=e,this.layout=r||null}getSpan(t,e){if(0<=this.span)return this.span;void 0===e&&(e=0);let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),r+this.layout.getSpan(t,e+r)}decode(t,e){const r=this.makeDestinationObject();if(void 0===e&&(e=0),this!==this.union.getVariant(t,e))throw new Error("variant mismatch");let n=0;return this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(t,e+n):this.property?r[this.property]=1:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(t,e,r){void 0===r&&(r=0);let n=0;if(this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout&&!t.hasOwnProperty(this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,e,r);let i=n;if(this.layout&&(this.layout.encode(t[this.property],e,r+n),i+=this.layout.getSpan(e,r+n),0<=this.union.span&&i>this.union.span))throw new Error("encoded variant overruns containing union");return i}fromArray(t){if(this.layout)return this.layout.fromArray(t)}}function le(t){return 0>t&&(t+=4294967296),t}class ce extends Wt{constructor(t,e,r){if(!(t instanceof Kt||t instanceof Vt))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof e&&void 0===r&&(r=e,e=void 0),4<t.span)throw new RangeError("word cannot exceed 32 bits");super(t.span,r),this.word=t,this.msb=!!e,this.fields=[];let n=0;this._packedSetValue=function(t){return n=le(t),this},this._packedGetValue=function(){return n}}decode(t,e){const r=this.makeDestinationObject();void 0===e&&(e=0);const n=this.word.decode(t,e);this._packedSetValue(n);for(const t of this.fields)void 0!==t.property&&(r[t.property]=t.decode(n));return r}encode(t,e,r){void 0===r&&(r=0);const n=this.word.decode(e,r);this._packedSetValue(n);for(const e of this.fields)if(void 0!==e.property){const r=t[e.property];void 0!==r&&e.encode(r)}return this.word.encode(this._packedGetValue(),e,r)}addField(t,e){const r=new fe(this,t,e);return this.fields.push(r),r}addBoolean(t){const e=new de(this,t);return this.fields.push(e),e}fieldFor(t){if("string"!=typeof t)throw new TypeError("property must be string");for(const e of this.fields)if(e.property===t)return e}}class fe{constructor(t,e,r){if(!(t instanceof ce))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(e)||0>=e)throw new TypeError("bits must be positive integer");const n=8*t.span,i=t.fields.reduce(((t,e)=>t+e.bits),0);if(e+i>n)throw new Error("bits too long for span remainder ("+(n-i)+" of "+n+" remain)");this.container=t,this.bits=e,this.valueMask=(1<<e)-1,32===e&&(this.valueMask=4294967295),this.start=i,this.container.msb&&(this.start=n-i-e),this.wordMask=le(this.valueMask<<this.start),this.property=r}decode(){return le(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(t){if(!Number.isInteger(t)||t!==le(t&this.valueMask))throw new TypeError(Yt("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const e=this.container._packedGetValue(),r=le(t<<this.start);this.container._packedSetValue(le(e&~this.wordMask)|r)}}class de extends fe{constructor(t,e){super(t,1,e)}decode(t,e){return!!fe.prototype.decode.call(this,t,e)}encode(t){return"boolean"==typeof t&&(t=+t),fe.prototype.encode.call(this,t)}}class pe extends Wt{constructor(t,e){if(!(t instanceof Nt&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;t instanceof Nt||(r=t),super(r,e),this.length=t}getSpan(t,e){let r=this.span;return 0>r&&(r=this.length.decode(t,e)),r}decode(t,e){void 0===e&&(e=0);let r=this.span;return 0>r&&(r=this.length.decode(t,e)),t.slice(e,e+r)}encode(t,e,r){let n=this.length;if(this.length instanceof Nt&&(n=t.length),!Buffer.isBuffer(t)||n!==t.length)throw new TypeError(Yt("Blob.encode",this)+" requires (length "+n+") Buffer as src");if(r+n>e.length)throw new RangeError("encoding overruns Buffer");return e.write(t.toString("hex"),r,n,"hex"),this.length instanceof Nt&&this.length.encode(n,e,r),n}}class me extends Wt{constructor(t){super(-1,t)}getSpan(t,e){if(!Buffer.isBuffer(t))throw new TypeError("b must be a Buffer");void 0===e&&(e=0);let r=e;for(;r<t.length&&0!==t[r];)r+=1;return 1+r-e}decode(t,e,r){void 0===e&&(e=0);let n=this.getSpan(t,e);return t.slice(e,e+n-1).toString("utf-8")}encode(t,e,r){void 0===r&&(r=0),"string"!=typeof t&&(t=t.toString());const n=new Buffer(t,"utf8"),i=n.length;if(r+i>e.length)throw new RangeError("encoding overruns Buffer");return n.copy(e,r),e[r+i]=0,i+1}}class ge extends Wt{constructor(t,e){if("string"==typeof t&&void 0===e&&(e=t,t=void 0),void 0===t)t=-1;else if(!Number.isInteger(t))throw new TypeError("maxSpan must be an integer");super(-1,e),this.maxSpan=t}getSpan(t,e){if(!Buffer.isBuffer(t))throw new TypeError("b must be a Buffer");return void 0===e&&(e=0),t.length-e}decode(t,e,r){void 0===e&&(e=0);let n=this.getSpan(t,e);if(0<=this.maxSpan&&this.maxSpan<n)throw new RangeError("text length exceeds maxSpan");return t.slice(e,e+n).toString("utf-8")}encode(t,e,r){void 0===r&&(r=0),"string"!=typeof t&&(t=t.toString());const n=new Buffer(t,"utf8"),i=n.length;if(0<=this.maxSpan&&this.maxSpan<i)throw new RangeError("text length exceeds maxSpan");if(r+i>e.length)throw new RangeError("encoding overruns Buffer");return n.copy(e,r),i}}class ye extends Wt{constructor(t,e){super(0,e),this.value=t}decode(t,e,r){return this.value}encode(t,e,r){return 0}}Dt.ExternalLayout=Nt,Dt.GreedyCount=qt,Dt.OffsetLayout=jt,Dt.UInt=Kt,Dt.UIntBE=Vt,Dt.Int=Zt,Dt.IntBE=zt,Dt.Float=te,Dt.FloatBE=ee,Dt.Double=re,Dt.DoubleBE=ne,Dt.Sequence=ie,Dt.Structure=oe,Dt.UnionDiscriminator=se,Dt.UnionLayoutDiscriminator=ue,Dt.Union=ae,Dt.VariantLayout=he,Dt.BitStructure=ce,Dt.BitField=fe,Dt.Boolean=de,Dt.Blob=pe,Dt.CString=me,Dt.UTF8=ge,Dt.Constant=ye,Dt.greedy=(t,e)=>new qt(t,e),Dt.offset=(t,e,r)=>new jt(t,e,r),Dt.u8=t=>new Kt(1,t),Dt.u16=t=>new Kt(2,t),Dt.u24=t=>new Kt(3,t),Dt.u32=t=>new Kt(4,t),Dt.u40=t=>new Kt(5,t),Dt.u48=t=>new Kt(6,t),Dt.nu64=t=>new $t(t),Dt.u16be=t=>new Vt(2,t),Dt.u24be=t=>new Vt(3,t),Dt.u32be=t=>new Vt(4,t),Dt.u40be=t=>new Vt(5,t),Dt.u48be=t=>new Vt(6,t),Dt.nu64be=t=>new Ht(t),Dt.s8=t=>new Zt(1,t),Dt.s16=t=>new Zt(2,t),Dt.s24=t=>new Zt(3,t),Dt.s32=t=>new Zt(4,t),Dt.s40=t=>new Zt(5,t),Dt.s48=t=>new Zt(6,t),Dt.ns64=t=>new Jt(t),Dt.s16be=t=>new zt(2,t),Dt.s24be=t=>new zt(3,t),Dt.s32be=t=>new zt(4,t),Dt.s40be=t=>new zt(5,t),Dt.s48be=t=>new zt(6,t),Dt.ns64be=t=>new Xt(t),Dt.f32=t=>new te(t),Dt.f32be=t=>new ee(t),Dt.f64=t=>new re(t),Dt.f64be=t=>new ne(t),Dt.struct=(t,e,r)=>new oe(t,e,r),Dt.bits=(t,e,r)=>new ce(t,e,r),Dt.seq=(t,e,r)=>new ie(t,e,r),Dt.union=(t,e,r)=>new ae(t,e,r),Dt.unionLayoutDiscriminator=(t,e)=>new ue(t,e),Dt.blob=(t,e)=>new pe(t,e),Dt.cstr=t=>new me(t),Dt.utf8=(t,e)=>new ge(t,e),Dt.const=(t,e)=>new ye(t,e),function(t){var e=x&&x.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(t,"__esModule",{value:1}),t.map=t.array=t.rustEnum=t.str=t.vecU8=t.tagged=t.vec=t.bool=t.option=t.publicKey=t.i256=t.u256=t.i128=t.u128=t.i64=t.u64=t.struct=t.f64=t.f32=t.i32=t.u32=t.i16=t.u16=t.i8=t.u8=void 0;const r=Dt,n=d,i=e(Rt);var o=Dt;Object.defineProperty(t,"u8",{enumerable:1,get:function(){return o.u8}}),Object.defineProperty(t,"i8",{enumerable:1,get:function(){return o.s8}}),Object.defineProperty(t,"u16",{enumerable:1,get:function(){return o.u16}}),Object.defineProperty(t,"i16",{enumerable:1,get:function(){return o.s16}}),Object.defineProperty(t,"u32",{enumerable:1,get:function(){return o.u32}}),Object.defineProperty(t,"i32",{enumerable:1,get:function(){return o.s32}}),Object.defineProperty(t,"f32",{enumerable:1,get:function(){return o.f32}}),Object.defineProperty(t,"f64",{enumerable:1,get:function(){return o.f64}}),Object.defineProperty(t,"struct",{enumerable:1,get:function(){return o.struct}});class s extends r.Layout{constructor(t,e,n){super(t,n),this.blob=(0,r.blob)(t),this.signed=e}decode(t,e=0){const r=new i.default(this.blob.decode(t,e),10,"le");return this.signed?r.fromTwos(8*this.span).clone():r}encode(t,e,r=0){return this.signed&&(t=t.toTwos(8*this.span)),this.blob.encode(t.toArrayLike(Buffer,"le",this.span),e,r)}}function u(t){return new s(8,0,t)}t.u64=u,t.i64=function(t){return new s(8,1,t)},t.u128=function(t){return new s(16,0,t)},t.i128=function(t){return new s(16,1,t)},t.u256=function(t){return new s(32,0,t)},t.i256=function(t){return new s(32,1,t)};class a extends r.Layout{constructor(t,e,r,n){super(t.span,n),this.layout=t,this.decoder=e,this.encoder=r}decode(t,e){return this.decoder(this.layout.decode(t,e))}encode(t,e,r){return this.layout.encode(this.encoder(t),e,r)}getSpan(t,e){return this.layout.getSpan(t,e)}}t.publicKey=function(t){return new a((0,r.blob)(32),(t=>new n.PublicKey(t)),(t=>t.toBuffer()),t)};class h extends r.Layout{constructor(t,e){super(-1,e),this.layout=t,this.discriminator=(0,r.u8)()}encode(t,e,r=0){return null==t?this.discriminator.encode(0,e,r):(this.discriminator.encode(1,e,r),this.layout.encode(t,e,r+1)+1)}decode(t,e=0){const r=this.discriminator.decode(t,e);if(0===r)return null;if(1===r)return this.layout.decode(t,e+1);throw new Error("Invalid option "+this.property)}getSpan(t,e=0){const r=this.discriminator.decode(t,e);if(0===r)return 1;if(1===r)return this.layout.getSpan(t,e+1)+1;throw new Error("Invalid option "+this.property)}}function l(t){if(0===t)return 0;if(1===t)return 1;throw new Error("Invalid bool: "+t)}function c(t){return t?1:0}function f(t){const e=(0,r.u32)("length"),n=(0,r.struct)([e,(0,r.blob)((0,r.offset)(e,-e.span),"data")]);return new a(n,(({data:t})=>t),(t=>({data:t})),t)}t.option=function(t,e){return new h(t,e)},t.bool=function(t){return new a((0,r.u8)(),l,c,t)},t.vec=function(t,e){const n=(0,r.u32)("length"),i=(0,r.struct)([n,(0,r.seq)(t,(0,r.offset)(n,-n.span),"values")]);return new a(i,(({values:t})=>t),(t=>({values:t})),e)},t.tagged=function(t,e,n){const i=(0,r.struct)([u("tag"),e.replicate("data")]);return new a(i,(function({tag:e,data:r}){if(!e.eq(t))throw new Error("Invalid tag, expected: "+t.toString("hex")+", got: "+e.toString("hex"));return r}),(e=>({tag:t,data:e})),n)},t.vecU8=f,t.str=function(t){return new a(f(),(t=>t.toString("utf-8")),(t=>Buffer.from(t,"utf-8")),t)},t.rustEnum=function(t,e,n){const i=(0,r.union)(null!=n?n:(0,r.u8)(),e);return t.forEach(((t,e)=>i.addVariant(e,t,t.property))),i},t.array=function(t,e,n){const i=(0,r.struct)([(0,r.seq)(t,e,"values")]);return new a(i,(({values:t})=>t),(t=>({values:t})),n)};class p extends r.Layout{constructor(t,e,r){super(t.span+e.span,r),this.keyLayout=t,this.valueLayout=e}decode(t,e){return e=e||0,[this.keyLayout.decode(t,e),this.valueLayout.decode(t,e+this.keyLayout.getSpan(t,e))]}encode(t,e,r){r=r||0;const n=this.keyLayout.encode(t[0],e,r);return n+this.valueLayout.encode(t[1],e,r+n)}getSpan(t,e){return this.keyLayout.getSpan(t,e)+this.valueLayout.getSpan(t,e)}}t.map=function(t,e,n){const i=(0,r.u32)("length"),o=(0,r.struct)([i,(0,r.seq)(new p(t,e),(0,r.offset)(i,-i.span),"values")]);return new a(o,(({values:t})=>new Map(t)),(t=>({values:Array.from(t.entries())})),n)}}(Ut);const we=Q.from([23,169,27,122,147,169,209,152]),ve=Ut.struct([Ut.array(Ut.u8(),32,"a"),Ut.array(Ut.u8(),64,"b"),Ut.array(Ut.u8(),32,"c")]),be=Ut.struct([Ut.publicKey("owner"),Ut.u64("amount"),Ut.option(Ut.u64(),"lamports"),Ut.u8("merkleTreeIndex"),Ut.option(Ut.vecU8(),"tlv")]),Me=Ut.struct([Ut.u8("queueId"),Ut.u16("index")]),Pe=Ut.struct([Ut.u64("amount"),Ut.option(Ut.u8(),"delegateIndex"),Ut.struct([Ut.u8("merkleTreePubkeyIndex"),Ut.u8("nullifierQueuePubkeyIndex"),Ut.u32("leafIndex"),Ut.option(Me,"QueueIndex")],"merkleContext"),Ut.u16("rootIndex"),Ut.option(Ut.u64(),"lamports"),Ut.option(Ut.vecU8(),"tlv")]),ke=Ut.struct([Ut.publicKey("owner"),Ut.option(Ut.u8(),"delegateChangeAccountIndex")]),Ae=Ut.struct([Ut.bool("setContext"),Ut.bool("firstSetContext"),Ut.u8("cpiContextAccountIndex")]),Ee=Ut.struct([Ut.option(ve,"proof"),Ut.publicKey("mint"),Ut.option(ke,"delegatedTransfer"),Ut.vec(Pe,"inputTokenDataWithContext"),Ut.vec(be,"outputCompressedAccounts"),Ut.bool("isCompress"),Ut.option(Ut.u64(),"compressOrDecompressAmount"),Ut.option(Ae,"cpiContext"),Ut.option(Ut.u8(),"lamportsChangeAccountMerkleTreeIndex")]),_e=Ut.struct([Ut.vec(Ut.publicKey(),"recipients"),Ut.vec(Ut.u64(),"amounts"),Ut.option(Ut.u64(),"lamports")]),Se=Ut.struct([Ut.publicKey("owner"),Ut.option(Ut.u64(),"remainingAmount"),Ut.option(Ae,"cpiContext")]),Te=Q.from([241,34,48,186,37,179,123,192]),Ie=Q.from([163,52,200,231,140,3,69,186]),xe=Q.from([112,230,105,101,145,202,157,97]);function Be(t){const e=Q.alloc(1e3),r=Ee.encode(t,e),n=Q.alloc(4);return n.writeUInt32LE(r,0),Q.concat([Ie,n,e.slice(0,r)])}Ut.struct([Ut.publicKey("owner"),Ut.option(Ut.u64(),"remainingAmount"),Ut.option(Ut.struct([],"CompressedCpiContext"),"cpiContext")],"compressSplTokenAccountArgs");const Le=t=>{const e=We.programId,{feePayer:r,authority:n,cpiAuthorityPda:i,lightSystemProgram:o,registeredProgramPda:s,noopProgram:u,accountCompressionAuthority:a,accountCompressionProgram:h,selfProgram:l,tokenPoolPda:c,compressOrDecompressTokenAccount:f,tokenProgram:d,systemProgram:p}=t;return[{pubkey:r,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:c??e,isSigner:0,isWritable:1},{pubkey:f??e,isSigner:0,isWritable:1},{pubkey:d??e,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:0}]},Ce=t=>t.reduce(((t,e)=>t.add(e.parsed.amount)),e(0)),Re=t=>{const e=t[0].parsed.owner;t.forEach((t=>{if(!t.parsed.owner.equals(e))throw new Error("Token accounts must be owned by the same owner")}))},Oe=t=>({mint:t[0].parsed.mint,currentOwner:t[0].parsed.owner,delegate:t[0].parsed.delegate});function Ue(t,r,n){n=e(n);const i=Ce(t),o=u(t.map((t=>t.compressedAccount))),s=i.sub(n);return a(s),s.eq(e(0))&&o.eq(e(0))?[{owner:r,amount:n,lamports:o,tlv:null}]:(h(t.map((t=>t.compressedAccount))),Re(t),[{owner:t[0].parsed.owner,amount:s,lamports:o,tlv:null},{owner:r,amount:n,lamports:e(0),tlv:null}])}function De(t,r){r=e(r);const n=u(t.map((t=>t.compressedAccount))),i=Ce(t).sub(r);return a(i),i.eq(e(0))&&n.eq(e(0))?[]:(h(t.map((t=>t.compressedAccount))),Re(t),[{owner:t[0].parsed.owner,amount:i,lamports:n,tlv:null}])}class We{constructor(){}static programId=new p("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m");static setProgramId(t){this.programId="string"==typeof t?new p(t):t}static deriveTokenPoolPda(t){const e=[S,t.toBuffer()],[r,n]=p.findProgramAddressSync(e,this.programId);return r}static get deriveCpiAuthorityPda(){const[t,e]=p.findProgramAddressSync([T],this.programId);return t}static async createMint(t){const{mint:e,authority:r,feePayer:n,rentExemptBalance:i,tokenProgramId:o,freezeAuthority:s,mintSize:u}=t,a=o??k;return[m.createAccount({fromPubkey:n,lamports:i,newAccountPubkey:e,programId:a,space:u??b}),M(e,t.decimals,r,s,a),await this.createTokenPool({feePayer:n,mint:e,tokenProgramId:a})]}static async createTokenPool(t){const{mint:e,feePayer:r,tokenProgramId:n}=t,i=n??k,o=(t=>{const{feePayer:e,tokenPoolPda:r,systemProgram:n,mint:i,tokenProgram:o,cpiAuthorityPda:s}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:n,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:1},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]})({mint:e,feePayer:r,tokenPoolPda:this.deriveTokenPoolPda(e),tokenProgram:i,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:m.programId});return new g({programId:this.programId,keys:o,data:we})}static async mintTo(t){const r=n(),{mint:u,feePayer:a,authority:h,merkleTree:l,toPubkey:c,amount:f,tokenProgramId:d}=t,p=d??k,y=this.deriveTokenPoolPda(u),w=i(f).map((t=>e(t))),v=i(c);if(w.length!==v.length)throw new Error("Amount and toPubkey arrays must have the same length");const b=(t=>{const e=We.programId,{feePayer:r,authority:n,cpiAuthorityPda:i,mint:o,tokenPoolPda:s,tokenProgram:u,lightSystemProgram:a,registeredProgramPda:h,noopProgram:l,accountCompressionAuthority:c,accountCompressionProgram:f,merkleTree:d,selfProgram:p,systemProgram:m,solPoolPda:g}=t;return[{pubkey:r,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:s,isSigner:0,isWritable:1},{pubkey:u,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:f,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:1},{pubkey:p,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:0},{pubkey:g??e,isSigner:0,isWritable:1}]})({mint:u,feePayer:a,authority:h,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:p,tokenPoolPda:y,lightSystemProgram:o.programId,registeredProgramPda:r.registeredProgramPda,noopProgram:r.noopProgram,accountCompressionAuthority:r.accountCompressionAuthority,accountCompressionProgram:r.accountCompressionProgram,merkleTree:l??s().merkleTree,selfProgram:this.programId,systemProgram:m.programId,solPoolPda:null}),M=function(t,e){const r=Q.alloc(1e3),n=_e.encode({recipients:t,amounts:e,lamports:null},r);return Q.concat([Te,r.slice(0,n)])}(v,w);return new g({programId:this.programId,keys:b,data:M})}static async approveAndMintTo(t){const{mint:e,feePayer:r,authorityTokenAccount:n,authority:i,merkleTree:o,toPubkey:s,tokenProgramId:u}=t,a=BigInt(t.amount.toString());return[P(e,n,i,a,[],u),await this.compress({payer:r,owner:i,source:n,toAddress:s,mint:e,amount:t.amount,outputStateTree:o,tokenProgramId:u})]}static async transfer(t){const{payer:e,inputCompressedTokenAccounts:r,recentInputStateRootIndices:i,recentValidityProof:s,amount:u,outputStateTrees:a,toAddress:h}=t,l=Ue(r,h,u),{inputTokenDataWithContext:c,packedOutputTokenData:f,remainingAccountMetas:d}=_({inputCompressedTokenAccounts:r,outputStateTrees:a,rootIndices:i,tokenTransferOutputs:l}),{mint:p,currentOwner:y}=Oe(r),w=Be({proof:s,mint:p,delegatedTransfer:null,inputTokenDataWithContext:c,outputCompressedAccounts:f,compressOrDecompressAmount:null,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),{accountCompressionAuthority:v,noopProgram:b,registeredProgramPda:M,accountCompressionProgram:P}=n(),k=Le({feePayer:e,authority:y,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:o.programId,registeredProgramPda:M,noopProgram:b,accountCompressionAuthority:v,accountCompressionProgram:P,selfProgram:this.programId,tokenPoolPda:void 0,compressOrDecompressTokenAccount:void 0,tokenProgram:void 0,systemProgram:m.programId});return k.push(...d),new g({programId:this.programId,keys:k,data:w})}static async createTokenProgramLookupTable(t){const{authority:e,mints:r,recentSlot:i,payer:u,remainingAccounts:a}=t,[h,l]=y.createLookupTable({authority:e,payer:e,recentSlot:i});let c=[];return r&&(c=[...r,...r.map((t=>this.deriveTokenPoolPda(t)))]),{instructions:[h,y.extendLookupTable({payer:u,authority:e,lookupTable:l,addresses:[this.deriveCpiAuthorityPda,o.programId,n().registeredProgramPda,n().noopProgram,n().accountCompressionAuthority,n().accountCompressionProgram,s().merkleTree,s().nullifierQueue,s().addressTree,s().addressQueue,this.programId,k,A,e,...c,...a??[]]})],address:l}}static async compress(t){const{payer:r,owner:i,source:s,toAddress:u,mint:a,outputStateTree:h,tokenProgramId:l}=t;if(Array.isArray(t.amount)!==Array.isArray(t.toAddress))throw new Error("Both amount and toAddress must be arrays or both must be single values");let c;if(Array.isArray(t.amount)&&Array.isArray(t.toAddress)){if(t.amount.length!==t.toAddress.length)throw new Error("Amount and toAddress arrays must have the same length");c=t.amount.map(((r,n)=>{const i=e(r);return{owner:t.toAddress[n],amount:i,lamports:e(0),tlv:null}}))}else c=[{owner:u,amount:e(t.amount),lamports:e(0),tlv:null}];const{inputTokenDataWithContext:f,packedOutputTokenData:d,remainingAccountMetas:p}=_({inputCompressedTokenAccounts:[],outputStateTrees:h,rootIndices:[],tokenTransferOutputs:c}),y=Be({proof:null,mint:a,delegatedTransfer:null,inputTokenDataWithContext:f,outputCompressedAccounts:d,compressOrDecompressAmount:Array.isArray(t.amount)?t.amount.map((t=>new Ot(t))).reduce(((t,e)=>t.add(e)),new Ot(0)):new Ot(t.amount),isCompress:1,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),w=l??k,v=Le({...n(),feePayer:r,authority:i,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:o.programId,selfProgram:this.programId,systemProgram:m.programId,tokenPoolPda:this.deriveTokenPoolPda(a),compressOrDecompressTokenAccount:s,tokenProgram:w});return v.push(...p),new g({programId:this.programId,keys:v,data:y})}static async decompress(t){const{payer:r,inputCompressedTokenAccounts:i,toAddress:s,outputStateTree:u,recentValidityProof:a,recentInputStateRootIndices:h,tokenProgramId:l}=t,c=e(t.amount),f=De(i,c),{inputTokenDataWithContext:d,packedOutputTokenData:p,remainingAccountMetas:y}=_({inputCompressedTokenAccounts:i,outputStateTrees:u,rootIndices:h,tokenTransferOutputs:f}),{mint:w,currentOwner:v}=Oe(i),b=Be({proof:a,mint:w,delegatedTransfer:null,inputTokenDataWithContext:d,outputCompressedAccounts:p,compressOrDecompressAmount:c,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),M=l??k,{accountCompressionAuthority:P,noopProgram:A,registeredProgramPda:E,accountCompressionProgram:S}=n(),T=Le({feePayer:r,authority:v,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:o.programId,registeredProgramPda:E,noopProgram:A,accountCompressionAuthority:P,accountCompressionProgram:S,selfProgram:this.programId,tokenPoolPda:this.deriveTokenPoolPda(w),compressOrDecompressTokenAccount:s,tokenProgram:M,systemProgram:m.programId});return T.push(...y),new g({programId:this.programId,keys:T,data:b})}static async mergeTokenAccounts(t){const{payer:e,owner:r,inputCompressedTokenAccounts:n,outputStateTree:i,recentValidityProof:o,recentInputStateRootIndices:s}=t;if(n.length>3)throw new Error("Cannot merge more than 3 token accounts at once");return[await this.transfer({payer:e,inputCompressedTokenAccounts:n,toAddress:r,amount:n.reduce(((t,e)=>t.add(e.parsed.amount)),new Ot(0)),outputStateTrees:i,recentInputStateRootIndices:s,recentValidityProof:o})]}static async compressSplTokenAccount(t){const{feePayer:e,authority:r,tokenAccount:i,mint:s,remainingAmount:u,outputStateTree:a,tokenProgramId:h}=t,l=h??k,c=[{pubkey:a,isSigner:0,isWritable:1}],f=function(t,e){const r=Q.alloc(1e3),n=Se.encode({owner:t,remainingAmount:e,cpiContext:null},r);return Q.concat([xe,r.slice(0,n)])}(r,u??null),{accountCompressionAuthority:d,noopProgram:p,registeredProgramPda:y,accountCompressionProgram:w}=n(),v=Le({feePayer:e,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:o.programId,registeredProgramPda:y,noopProgram:p,accountCompressionAuthority:d,accountCompressionProgram:w,selfProgram:this.programId,tokenPoolPda:this.deriveTokenPoolPda(s),compressOrDecompressTokenAccount:i,tokenProgram:l,systemProgram:m.programId});return v.push(...c),new g({programId:this.programId,keys:v,data:f})}static async get_mint_program_id(t,e){return(await e.getAccountInfo(t))?.owner}}async function Ye(t,e,r,n,i,o,s,u,a){a=a||await We.get_mint_program_id(r,t);const h=await E(t,e,r,i.publicKey,void 0,void 0,u,a),d=await We.approveAndMintTo({feePayer:e.publicKey,mint:r,authority:i.publicKey,authorityTokenAccount:h.address,amount:o,toPubkey:n,merkleTree:s,tokenProgramId:a}),{blockhash:p}=await t.getLatestBlockhash(),m=l(e,[i]),g=c([w.setComputeUnitLimit({units:1e6}),...d],e,p,m);return await f(t,g,u)}async function Ne(t,e,r,n,i,o,s,u,a,h){h=h||await We.get_mint_program_id(r,t);const d=await We.compress({payer:e.publicKey,owner:i.publicKey,source:o,toAddress:s,amount:n,mint:r,outputStateTree:u,tokenProgramId:h}),p=await t.getLatestBlockhash(),m=l(e,[i]),g=c([w.setComputeUnitLimit({units:1e6}),d],e,p.blockhash,m);return await f(t,g,a,p)}async function qe(t,r,n,i,o,s,u,a){i=e(i);const h=await t.getCompressedTokenAccountsByOwner(o.publicKey,{mint:n}),[d]=je(h.items,i),p=await t.getValidityProof(d.map((t=>e(t.compressedAccount.hash)))),m=await We.transfer({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:s,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof,outputStateTrees:u}),{blockhash:g}=await t.getLatestBlockhash(),y=l(r,[o]),v=c([w.setComputeUnitLimit({units:1e6}),m],r,g,y);return await f(t,v,a)}function je(t,r){let n=e(0),i=e(0);const o=[];t.sort(((t,e)=>e.parsed.amount.cmp(t.parsed.amount)));for(const s of t){if(n.gte(e(r)))break;n=n.add(s.parsed.amount),i=i.add(s.compressedAccount.lamports),o.push(s)}if(n.lt(e(r)))throw new Error(`Not enough balance for transfer. Required: ${r.toString()}, available: ${n.toString()}`);return[o,n,i.lt(e(0))?i:null]}async function Ke(t,r,n,i,o,s,u,a,h){h=h||await We.get_mint_program_id(n,t),i=e(i);const d=await t.getCompressedTokenAccountsByOwner(o.publicKey,{mint:n}),[p]=je(d.items,i),m=await t.getValidityProof(p.map((t=>e(t.compressedAccount.hash)))),g=await We.decompress({payer:r.publicKey,inputCompressedTokenAccounts:p,toAddress:s,amount:i,outputStateTree:u,recentInputStateRootIndices:m.rootIndices,recentValidityProof:m.compressedProof,tokenProgramId:h}),{blockhash:y}=await t.getLatestBlockhash(),v=l(r,[o]),b=c([w.setComputeUnitLimit({units:1e6}),g],r,y,v);return await f(t,b,a)}async function Ve(t,e,r,n,i=v.generate(),o,s=0){const u=await t.getMinimumBalanceForRentExemption(b),a=s?A:k,h=await We.createMint({feePayer:e.publicKey,mint:i.publicKey,decimals:n,authority:r,freezeAuthority:null,rentExemptBalance:u,tokenProgramId:a}),{blockhash:d}=await t.getLatestBlockhash(),p=l(e,[i]),m=c(h,e,d,p),g=await f(t,m,o);return{mint:i.publicKey,transactionSignature:g}}async function Ze(t,e,r,n,i,o,s,u,a){a=a||await We.get_mint_program_id(r,t);const h=l(e,[i]),d=await We.mintTo({feePayer:e.publicKey,mint:r,authority:i.publicKey,amount:o,toPubkey:n,merkleTree:s,tokenProgramId:a}),{blockhash:p}=await t.getLatestBlockhash(),m=c([w.setComputeUnitLimit({units:1e6}),d],e,p,h);return await f(t,m,u)}async function ze(t,r,n,i,o,s){const u=await t.getCompressedTokenAccountsByOwner(i.publicKey,{mint:n});if(0===u.items.length)throw new Error(`No compressed token accounts found for mint ${n.toBase58()}`);if(u.items.length>=6)throw new Error(`Too many compressed token accounts used for mint ${n.toBase58()}`);const a=[w.setComputeUnitLimit({units:1e6})];for(let s=0;s<u.items.slice(0,6).length;s+=3){const h=u.items.slice(s,s+3),l=await t.getValidityProof(h.map((t=>e(t.compressedAccount.hash)))),c=await We.mergeTokenAccounts({payer:r.publicKey,owner:i.publicKey,mint:n,inputCompressedTokenAccounts:h,outputStateTree:o,recentValidityProof:l.compressedProof,recentInputStateRootIndices:l.rootIndices});a.push(...c)}const{blockhash:h}=await t.getLatestBlockhash(),d=l(r,[i]),p=c(a,r,h,d);return await f(t,p,s)}async function Fe(t,e,r,n,i){i=i||await We.get_mint_program_id(r,t);const o=await We.createTokenPool({feePayer:e.publicKey,mint:r,tokenProgramId:i}),{blockhash:s}=await t.getLatestBlockhash(),u=c([o],e,s);return await f(t,u,n)}async function Ge(t,e,r,n,i){const o=await t.getSlot("finalized"),{instructions:s,address:u}=await We.createTokenProgramLookupTable({payer:e.publicKey,authority:r.publicKey,mints:n,remainingAccounts:i,recentSlot:o}),a=l(e,[r]),h=await t.getLatestBlockhash(),d=c([s[0]],e,h.blockhash,a),p=await f(t,d,{commitment:"finalized"},h),m=await t.getLatestBlockhash(),g=c([s[1]],e,m.blockhash,a);return{txIds:[p,await f(t,g,{commitment:"finalized"},m)],address:u}}async function Qe(t,e,r,n,i,o,s,u,a){a=a||await We.get_mint_program_id(r,t);const h=await We.compressSplTokenAccount({feePayer:e.publicKey,authority:n.publicKey,tokenAccount:i,mint:r,remainingAmount:s,outputStateTree:o,tokenProgramId:a}),d=await t.getLatestBlockhash(),p=l(e,[n]),m=c([w.setComputeUnitLimit({units:1e6}),h],e,d.blockhash,p);return await f(t,m,u,d)}export{T as CPI_AUTHORITY_SEED,We as CompressedTokenProgram,S as POOL_SEED,I as SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE,Ye as approveAndMintTo,Ne as compress,Qe as compressSplTokenAccount,De as createDecompressOutputState,Ve as createMint,Fe as createTokenPool,Ge as createTokenProgramLookupTable,Ue as createTransferOutputState,Ke as decompress,ze as mergeTokenAccounts,Ze as mintTo,_ as packCompressedTokenAccounts,Oe as parseTokenData,je as selectMinCompressedTokenAccountsForTransfer,Ce as sumUpTokenAmount,qe as transfer,Re as validateSameTokenOwner};
|
|
2803
2
|
//# sourceMappingURL=index.js.map
|