@lightprotocol/compressed-token 0.1.3 → 0.3.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/LICENSE +674 -0
- package/README.md +1 -1
- package/dist/cjs/browser/index.cjs +1428 -488
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +1401 -786
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +1429 -489
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +1175 -396
- package/package.json +116 -91
- package/dist/es/node/index.js +0 -4404
- package/dist/es/node/index.js.map +0 -1
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var stateless_js = require('@lightprotocol/stateless.js');
|
|
4
|
-
var anchor = require('@coral-xyz/anchor');
|
|
5
4
|
var web3_js = require('@solana/web3.js');
|
|
5
|
+
var anchor = require('@coral-xyz/anchor');
|
|
6
6
|
|
|
7
7
|
const IDL = {
|
|
8
|
-
version: '0.
|
|
8
|
+
version: '0.4.0',
|
|
9
9
|
name: 'light_compressed_token',
|
|
10
|
-
constants: [
|
|
11
|
-
{
|
|
12
|
-
name: 'PROGRAM_ID',
|
|
13
|
-
type: 'string',
|
|
14
|
-
value: '"9sixVEthz2kMSKfeApZXHwuboT6DZuT6crAYJTciUCqE"',
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
10
|
instructions: [
|
|
18
11
|
{
|
|
19
12
|
name: 'createMint',
|
|
20
13
|
docs: [
|
|
21
|
-
'This instruction expects a mint account to be created in a separate
|
|
22
|
-
'with token authority as mint authority.',
|
|
23
|
-
'
|
|
14
|
+
'This instruction expects a mint account to be created in a separate',
|
|
15
|
+
'token program instruction with token authority as mint authority. This',
|
|
16
|
+
'instruction creates a token pool account for that mint owned by token',
|
|
17
|
+
'authority.',
|
|
24
18
|
],
|
|
25
19
|
accounts: [
|
|
26
20
|
{
|
|
@@ -28,11 +22,6 @@ const IDL = {
|
|
|
28
22
|
isMut: true,
|
|
29
23
|
isSigner: true,
|
|
30
24
|
},
|
|
31
|
-
{
|
|
32
|
-
name: 'authority',
|
|
33
|
-
isMut: true,
|
|
34
|
-
isSigner: true,
|
|
35
|
-
},
|
|
36
25
|
{
|
|
37
26
|
name: 'tokenPoolPda',
|
|
38
27
|
isMut: true,
|
|
@@ -48,11 +37,6 @@ const IDL = {
|
|
|
48
37
|
isMut: true,
|
|
49
38
|
isSigner: false,
|
|
50
39
|
},
|
|
51
|
-
{
|
|
52
|
-
name: 'mintAuthorityPda',
|
|
53
|
-
isMut: true,
|
|
54
|
-
isSigner: false,
|
|
55
|
-
},
|
|
56
40
|
{
|
|
57
41
|
name: 'tokenProgram',
|
|
58
42
|
isMut: false,
|
|
@@ -68,6 +52,12 @@ const IDL = {
|
|
|
68
52
|
},
|
|
69
53
|
{
|
|
70
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 one output compressed account.',
|
|
60
|
+
],
|
|
71
61
|
accounts: [
|
|
72
62
|
{
|
|
73
63
|
name: 'feePayer',
|
|
@@ -76,12 +66,12 @@ const IDL = {
|
|
|
76
66
|
},
|
|
77
67
|
{
|
|
78
68
|
name: 'authority',
|
|
79
|
-
isMut:
|
|
69
|
+
isMut: false,
|
|
80
70
|
isSigner: true,
|
|
81
71
|
},
|
|
82
72
|
{
|
|
83
|
-
name: '
|
|
84
|
-
isMut:
|
|
73
|
+
name: 'cpiAuthorityPda',
|
|
74
|
+
isMut: false,
|
|
85
75
|
isSigner: false,
|
|
86
76
|
},
|
|
87
77
|
{
|
|
@@ -100,13 +90,13 @@ const IDL = {
|
|
|
100
90
|
isSigner: false,
|
|
101
91
|
},
|
|
102
92
|
{
|
|
103
|
-
name: '
|
|
93
|
+
name: 'lightSystemProgram',
|
|
104
94
|
isMut: false,
|
|
105
95
|
isSigner: false,
|
|
106
96
|
},
|
|
107
97
|
{
|
|
108
98
|
name: 'registeredProgramPda',
|
|
109
|
-
isMut:
|
|
99
|
+
isMut: false,
|
|
110
100
|
isSigner: false,
|
|
111
101
|
},
|
|
112
102
|
{
|
|
@@ -116,7 +106,7 @@ const IDL = {
|
|
|
116
106
|
},
|
|
117
107
|
{
|
|
118
108
|
name: 'accountCompressionAuthority',
|
|
119
|
-
isMut:
|
|
109
|
+
isMut: false,
|
|
120
110
|
isSigner: false,
|
|
121
111
|
},
|
|
122
112
|
{
|
|
@@ -134,6 +124,11 @@ const IDL = {
|
|
|
134
124
|
isMut: false,
|
|
135
125
|
isSigner: false,
|
|
136
126
|
},
|
|
127
|
+
{
|
|
128
|
+
name: 'systemProgram',
|
|
129
|
+
isMut: false,
|
|
130
|
+
isSigner: false,
|
|
131
|
+
},
|
|
137
132
|
],
|
|
138
133
|
args: [
|
|
139
134
|
{
|
|
@@ -155,7 +150,7 @@ const IDL = {
|
|
|
155
150
|
accounts: [
|
|
156
151
|
{
|
|
157
152
|
name: 'feePayer',
|
|
158
|
-
isMut:
|
|
153
|
+
isMut: true,
|
|
159
154
|
isSigner: true,
|
|
160
155
|
},
|
|
161
156
|
{
|
|
@@ -169,7 +164,7 @@ const IDL = {
|
|
|
169
164
|
isSigner: false,
|
|
170
165
|
},
|
|
171
166
|
{
|
|
172
|
-
name: '
|
|
167
|
+
name: 'lightSystemProgram',
|
|
173
168
|
isMut: false,
|
|
174
169
|
isSigner: false,
|
|
175
170
|
},
|
|
@@ -205,7 +200,7 @@ const IDL = {
|
|
|
205
200
|
isOptional: true,
|
|
206
201
|
},
|
|
207
202
|
{
|
|
208
|
-
name: '
|
|
203
|
+
name: 'compressOrDecompressTokenAccount',
|
|
209
204
|
isMut: true,
|
|
210
205
|
isSigner: false,
|
|
211
206
|
isOptional: true,
|
|
@@ -216,86 +211,476 @@ const IDL = {
|
|
|
216
211
|
isSigner: false,
|
|
217
212
|
isOptional: true,
|
|
218
213
|
},
|
|
214
|
+
{
|
|
215
|
+
name: 'systemProgram',
|
|
216
|
+
isMut: false,
|
|
217
|
+
isSigner: false,
|
|
218
|
+
},
|
|
219
219
|
],
|
|
220
220
|
args: [
|
|
221
221
|
{
|
|
222
222
|
name: 'inputs',
|
|
223
223
|
type: 'bytes',
|
|
224
224
|
},
|
|
225
|
+
],
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: 'approve',
|
|
229
|
+
accounts: [
|
|
225
230
|
{
|
|
226
|
-
name: '
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
231
|
+
name: 'feePayer',
|
|
232
|
+
isMut: true,
|
|
233
|
+
isSigner: true,
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
name: 'authority',
|
|
237
|
+
isMut: false,
|
|
238
|
+
isSigner: true,
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'cpiAuthorityPda',
|
|
242
|
+
isMut: false,
|
|
243
|
+
isSigner: false,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
name: 'lightSystemProgram',
|
|
247
|
+
isMut: false,
|
|
248
|
+
isSigner: false,
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
name: 'registeredProgramPda',
|
|
252
|
+
isMut: false,
|
|
253
|
+
isSigner: false,
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: 'noopProgram',
|
|
257
|
+
isMut: false,
|
|
258
|
+
isSigner: false,
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: 'accountCompressionAuthority',
|
|
262
|
+
isMut: false,
|
|
263
|
+
isSigner: false,
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: 'accountCompressionProgram',
|
|
267
|
+
isMut: false,
|
|
268
|
+
isSigner: false,
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: 'selfProgram',
|
|
272
|
+
isMut: false,
|
|
273
|
+
isSigner: false,
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
name: 'systemProgram',
|
|
277
|
+
isMut: false,
|
|
278
|
+
isSigner: false,
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
args: [
|
|
282
|
+
{
|
|
283
|
+
name: 'inputs',
|
|
284
|
+
type: 'bytes',
|
|
232
285
|
},
|
|
233
286
|
],
|
|
234
287
|
},
|
|
235
|
-
],
|
|
236
|
-
types: [
|
|
237
288
|
{
|
|
238
|
-
name: '
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
289
|
+
name: 'revoke',
|
|
290
|
+
accounts: [
|
|
291
|
+
{
|
|
292
|
+
name: 'feePayer',
|
|
293
|
+
isMut: true,
|
|
294
|
+
isSigner: true,
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: 'authority',
|
|
298
|
+
isMut: false,
|
|
299
|
+
isSigner: true,
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: 'cpiAuthorityPda',
|
|
303
|
+
isMut: false,
|
|
304
|
+
isSigner: false,
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: 'lightSystemProgram',
|
|
308
|
+
isMut: false,
|
|
309
|
+
isSigner: false,
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
name: 'registeredProgramPda',
|
|
313
|
+
isMut: false,
|
|
314
|
+
isSigner: false,
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: 'noopProgram',
|
|
318
|
+
isMut: false,
|
|
319
|
+
isSigner: false,
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
name: 'accountCompressionAuthority',
|
|
323
|
+
isMut: false,
|
|
324
|
+
isSigner: false,
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
name: 'accountCompressionProgram',
|
|
328
|
+
isMut: false,
|
|
329
|
+
isSigner: false,
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
name: 'selfProgram',
|
|
333
|
+
isMut: false,
|
|
334
|
+
isSigner: false,
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
name: 'systemProgram',
|
|
338
|
+
isMut: false,
|
|
339
|
+
isSigner: false,
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
args: [
|
|
343
|
+
{
|
|
344
|
+
name: 'inputs',
|
|
345
|
+
type: 'bytes',
|
|
346
|
+
},
|
|
347
|
+
],
|
|
262
348
|
},
|
|
263
349
|
{
|
|
264
|
-
name: '
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
350
|
+
name: 'freeze',
|
|
351
|
+
accounts: [
|
|
352
|
+
{
|
|
353
|
+
name: 'feePayer',
|
|
354
|
+
isMut: true,
|
|
355
|
+
isSigner: true,
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
name: 'authority',
|
|
359
|
+
isMut: false,
|
|
360
|
+
isSigner: true,
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
name: 'cpiAuthorityPda',
|
|
364
|
+
isMut: false,
|
|
365
|
+
isSigner: false,
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
name: 'lightSystemProgram',
|
|
369
|
+
isMut: false,
|
|
370
|
+
isSigner: false,
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
name: 'registeredProgramPda',
|
|
374
|
+
isMut: false,
|
|
375
|
+
isSigner: false,
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
name: 'noopProgram',
|
|
379
|
+
isMut: false,
|
|
380
|
+
isSigner: false,
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
name: 'accountCompressionAuthority',
|
|
384
|
+
isMut: false,
|
|
385
|
+
isSigner: false,
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
name: 'accountCompressionProgram',
|
|
389
|
+
isMut: false,
|
|
390
|
+
isSigner: false,
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
name: 'selfProgram',
|
|
394
|
+
isMut: false,
|
|
395
|
+
isSigner: false,
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
name: 'systemProgram',
|
|
399
|
+
isMut: false,
|
|
400
|
+
isSigner: false,
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
name: 'mint',
|
|
404
|
+
isMut: false,
|
|
405
|
+
isSigner: false,
|
|
406
|
+
},
|
|
407
|
+
],
|
|
408
|
+
args: [
|
|
409
|
+
{
|
|
410
|
+
name: 'inputs',
|
|
411
|
+
type: 'bytes',
|
|
412
|
+
},
|
|
413
|
+
],
|
|
282
414
|
},
|
|
283
415
|
{
|
|
284
|
-
name: '
|
|
416
|
+
name: 'thaw',
|
|
417
|
+
accounts: [
|
|
418
|
+
{
|
|
419
|
+
name: 'feePayer',
|
|
420
|
+
isMut: true,
|
|
421
|
+
isSigner: true,
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
name: 'authority',
|
|
425
|
+
isMut: false,
|
|
426
|
+
isSigner: true,
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
name: 'cpiAuthorityPda',
|
|
430
|
+
isMut: false,
|
|
431
|
+
isSigner: false,
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
name: 'lightSystemProgram',
|
|
435
|
+
isMut: false,
|
|
436
|
+
isSigner: false,
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
name: 'registeredProgramPda',
|
|
440
|
+
isMut: false,
|
|
441
|
+
isSigner: false,
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
name: 'noopProgram',
|
|
445
|
+
isMut: false,
|
|
446
|
+
isSigner: false,
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
name: 'accountCompressionAuthority',
|
|
450
|
+
isMut: false,
|
|
451
|
+
isSigner: false,
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
name: 'accountCompressionProgram',
|
|
455
|
+
isMut: false,
|
|
456
|
+
isSigner: false,
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
name: 'selfProgram',
|
|
460
|
+
isMut: false,
|
|
461
|
+
isSigner: false,
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
name: 'systemProgram',
|
|
465
|
+
isMut: false,
|
|
466
|
+
isSigner: false,
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
name: 'mint',
|
|
470
|
+
isMut: false,
|
|
471
|
+
isSigner: false,
|
|
472
|
+
},
|
|
473
|
+
],
|
|
474
|
+
args: [
|
|
475
|
+
{
|
|
476
|
+
name: 'inputs',
|
|
477
|
+
type: 'bytes',
|
|
478
|
+
},
|
|
479
|
+
],
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: 'burn',
|
|
483
|
+
accounts: [
|
|
484
|
+
{
|
|
485
|
+
name: 'feePayer',
|
|
486
|
+
isMut: true,
|
|
487
|
+
isSigner: true,
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
name: 'authority',
|
|
491
|
+
isMut: false,
|
|
492
|
+
isSigner: true,
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
name: 'cpiAuthorityPda',
|
|
496
|
+
isMut: false,
|
|
497
|
+
isSigner: false,
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
name: 'lightSystemProgram',
|
|
501
|
+
isMut: false,
|
|
502
|
+
isSigner: false,
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
name: 'registeredProgramPda',
|
|
506
|
+
isMut: false,
|
|
507
|
+
isSigner: false,
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
name: 'noopProgram',
|
|
511
|
+
isMut: false,
|
|
512
|
+
isSigner: false,
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
name: 'accountCompressionAuthority',
|
|
516
|
+
isMut: false,
|
|
517
|
+
isSigner: false,
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
name: 'accountCompressionProgram',
|
|
521
|
+
isMut: false,
|
|
522
|
+
isSigner: false,
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
name: 'selfProgram',
|
|
526
|
+
isMut: false,
|
|
527
|
+
isSigner: false,
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
name: 'systemProgram',
|
|
531
|
+
isMut: false,
|
|
532
|
+
isSigner: false,
|
|
533
|
+
},
|
|
534
|
+
],
|
|
535
|
+
args: [
|
|
536
|
+
{
|
|
537
|
+
name: 'inputs',
|
|
538
|
+
type: 'bytes',
|
|
539
|
+
},
|
|
540
|
+
],
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
name: 'stubIdlBuild',
|
|
544
|
+
docs: [
|
|
545
|
+
'This function is a stub to allow Anchor to include the input types in',
|
|
546
|
+
'the IDL. It should not be included in production builds nor be called in',
|
|
547
|
+
'practice.',
|
|
548
|
+
],
|
|
549
|
+
accounts: [
|
|
550
|
+
{
|
|
551
|
+
name: 'feePayer',
|
|
552
|
+
isMut: true,
|
|
553
|
+
isSigner: true,
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
name: 'authority',
|
|
557
|
+
isMut: false,
|
|
558
|
+
isSigner: true,
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
name: 'cpiAuthorityPda',
|
|
562
|
+
isMut: false,
|
|
563
|
+
isSigner: false,
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
name: 'lightSystemProgram',
|
|
567
|
+
isMut: false,
|
|
568
|
+
isSigner: false,
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
name: 'registeredProgramPda',
|
|
572
|
+
isMut: false,
|
|
573
|
+
isSigner: false,
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
name: 'noopProgram',
|
|
577
|
+
isMut: false,
|
|
578
|
+
isSigner: false,
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
name: 'accountCompressionAuthority',
|
|
582
|
+
isMut: false,
|
|
583
|
+
isSigner: false,
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
name: 'accountCompressionProgram',
|
|
587
|
+
isMut: false,
|
|
588
|
+
isSigner: false,
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
name: 'selfProgram',
|
|
592
|
+
isMut: false,
|
|
593
|
+
isSigner: false,
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
name: 'tokenPoolPda',
|
|
597
|
+
isMut: true,
|
|
598
|
+
isSigner: false,
|
|
599
|
+
isOptional: true,
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
name: 'compressOrDecompressTokenAccount',
|
|
603
|
+
isMut: true,
|
|
604
|
+
isSigner: false,
|
|
605
|
+
isOptional: true,
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
name: 'tokenProgram',
|
|
609
|
+
isMut: false,
|
|
610
|
+
isSigner: false,
|
|
611
|
+
isOptional: true,
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
name: 'systemProgram',
|
|
615
|
+
isMut: false,
|
|
616
|
+
isSigner: false,
|
|
617
|
+
},
|
|
618
|
+
],
|
|
619
|
+
args: [
|
|
620
|
+
{
|
|
621
|
+
name: 'inputs1',
|
|
622
|
+
type: {
|
|
623
|
+
defined: 'CompressedTokenInstructionDataTransfer',
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
name: 'inputs2',
|
|
628
|
+
type: {
|
|
629
|
+
defined: 'TokenData',
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
],
|
|
633
|
+
},
|
|
634
|
+
],
|
|
635
|
+
accounts: [
|
|
636
|
+
{
|
|
637
|
+
name: 'RegisteredProgram',
|
|
285
638
|
type: {
|
|
286
639
|
kind: 'struct',
|
|
287
640
|
fields: [
|
|
288
641
|
{
|
|
289
|
-
name: '
|
|
290
|
-
type: '
|
|
642
|
+
name: 'registeredProgramId',
|
|
643
|
+
type: 'publicKey',
|
|
291
644
|
},
|
|
292
645
|
{
|
|
293
|
-
name: '
|
|
294
|
-
type: '
|
|
646
|
+
name: 'groupAuthorityPda',
|
|
647
|
+
type: 'publicKey',
|
|
295
648
|
},
|
|
649
|
+
],
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
],
|
|
653
|
+
types: [
|
|
654
|
+
{
|
|
655
|
+
name: 'AccessMetadata',
|
|
656
|
+
type: {
|
|
657
|
+
kind: 'struct',
|
|
658
|
+
fields: [
|
|
296
659
|
{
|
|
297
|
-
name: '
|
|
298
|
-
|
|
660
|
+
name: 'owner',
|
|
661
|
+
docs: ['Owner of the Merkle tree.'],
|
|
662
|
+
type: 'publicKey',
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
name: 'programOwner',
|
|
666
|
+
docs: [
|
|
667
|
+
'Delegate of the Merkle tree. This will be used for program owned Merkle trees.',
|
|
668
|
+
],
|
|
669
|
+
type: 'publicKey',
|
|
670
|
+
},
|
|
671
|
+
],
|
|
672
|
+
},
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
name: 'AccountState',
|
|
676
|
+
type: {
|
|
677
|
+
kind: 'enum',
|
|
678
|
+
variants: [
|
|
679
|
+
{
|
|
680
|
+
name: 'Initialized',
|
|
681
|
+
},
|
|
682
|
+
{
|
|
683
|
+
name: 'Frozen',
|
|
299
684
|
},
|
|
300
685
|
],
|
|
301
686
|
},
|
|
@@ -358,56 +743,81 @@ const IDL = {
|
|
|
358
743
|
},
|
|
359
744
|
{
|
|
360
745
|
name: 'CompressedCpiContext',
|
|
361
|
-
docs: ['To spend multiple compressed'],
|
|
362
746
|
type: {
|
|
363
747
|
kind: 'struct',
|
|
364
748
|
fields: [
|
|
365
749
|
{
|
|
366
|
-
name: '
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
750
|
+
name: 'setContext',
|
|
751
|
+
type: 'bool',
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
name: 'cpiContextAccountIndex',
|
|
371
755
|
type: 'u8',
|
|
372
756
|
},
|
|
757
|
+
],
|
|
758
|
+
},
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
name: 'CompressedProof',
|
|
762
|
+
type: {
|
|
763
|
+
kind: 'struct',
|
|
764
|
+
fields: [
|
|
373
765
|
{
|
|
374
|
-
name: '
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
766
|
+
name: 'a',
|
|
767
|
+
type: {
|
|
768
|
+
array: ['u8', 32],
|
|
769
|
+
},
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
name: 'b',
|
|
773
|
+
type: {
|
|
774
|
+
array: ['u8', 64],
|
|
775
|
+
},
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
name: 'c',
|
|
779
|
+
type: {
|
|
780
|
+
array: ['u8', 32],
|
|
781
|
+
},
|
|
381
782
|
},
|
|
382
783
|
],
|
|
383
784
|
},
|
|
384
785
|
},
|
|
385
786
|
{
|
|
386
|
-
name: '
|
|
787
|
+
name: 'CompressedTokenInstructionDataTransfer',
|
|
387
788
|
type: {
|
|
388
789
|
kind: 'struct',
|
|
389
790
|
fields: [
|
|
390
791
|
{
|
|
391
|
-
name: '
|
|
792
|
+
name: 'proof',
|
|
392
793
|
type: {
|
|
393
|
-
|
|
394
|
-
|
|
794
|
+
option: {
|
|
795
|
+
defined: 'CompressedProof',
|
|
395
796
|
},
|
|
396
797
|
},
|
|
397
798
|
},
|
|
398
799
|
{
|
|
399
|
-
name: '
|
|
800
|
+
name: 'mint',
|
|
801
|
+
type: 'publicKey',
|
|
802
|
+
},
|
|
803
|
+
{
|
|
804
|
+
name: 'delegatedTransfer',
|
|
805
|
+
docs: [
|
|
806
|
+
'If the signer is a delegate, the delegate index is index 0 of remaining accounts.',
|
|
807
|
+
'owner = Some(owner) is the owner of the token account.',
|
|
808
|
+
'Is set if the signer is delegate',
|
|
809
|
+
],
|
|
400
810
|
type: {
|
|
401
|
-
|
|
402
|
-
|
|
811
|
+
option: {
|
|
812
|
+
defined: 'DelegatedTransfer',
|
|
403
813
|
},
|
|
404
814
|
},
|
|
405
815
|
},
|
|
406
816
|
{
|
|
407
|
-
name: '
|
|
817
|
+
name: 'inputTokenDataWithContext',
|
|
408
818
|
type: {
|
|
409
819
|
vec: {
|
|
410
|
-
defined: '
|
|
820
|
+
defined: 'InputTokenDataWithContext',
|
|
411
821
|
},
|
|
412
822
|
},
|
|
413
823
|
},
|
|
@@ -415,53 +825,83 @@ const IDL = {
|
|
|
415
825
|
name: 'outputCompressedAccounts',
|
|
416
826
|
type: {
|
|
417
827
|
vec: {
|
|
418
|
-
defined: '
|
|
828
|
+
defined: 'PackedTokenTransferOutputData',
|
|
419
829
|
},
|
|
420
830
|
},
|
|
421
831
|
},
|
|
422
832
|
{
|
|
423
|
-
name: '
|
|
424
|
-
type: '
|
|
833
|
+
name: 'isCompress',
|
|
834
|
+
type: 'bool',
|
|
425
835
|
},
|
|
426
836
|
{
|
|
427
|
-
name: '
|
|
837
|
+
name: 'compressOrDecompressAmount',
|
|
428
838
|
type: {
|
|
429
|
-
|
|
839
|
+
option: 'u64',
|
|
430
840
|
},
|
|
431
841
|
},
|
|
432
842
|
{
|
|
433
|
-
name: '
|
|
843
|
+
name: 'cpiContext',
|
|
434
844
|
type: {
|
|
435
|
-
option:
|
|
845
|
+
option: {
|
|
846
|
+
defined: 'CompressedCpiContext',
|
|
847
|
+
},
|
|
436
848
|
},
|
|
437
849
|
},
|
|
850
|
+
],
|
|
851
|
+
},
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
name: 'DelegatedTransfer',
|
|
855
|
+
type: {
|
|
856
|
+
kind: 'struct',
|
|
857
|
+
fields: [
|
|
438
858
|
{
|
|
439
|
-
name: '
|
|
440
|
-
type: '
|
|
859
|
+
name: 'owner',
|
|
860
|
+
type: 'publicKey',
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
name: 'delegateChangeAccountIndex',
|
|
864
|
+
type: 'u8',
|
|
865
|
+
},
|
|
866
|
+
],
|
|
867
|
+
},
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
name: 'InputTokenDataWithContext',
|
|
871
|
+
type: {
|
|
872
|
+
kind: 'struct',
|
|
873
|
+
fields: [
|
|
874
|
+
{
|
|
875
|
+
name: 'amount',
|
|
876
|
+
type: 'u64',
|
|
441
877
|
},
|
|
442
878
|
{
|
|
443
|
-
name: '
|
|
879
|
+
name: 'delegateIndex',
|
|
444
880
|
type: {
|
|
445
|
-
option: '
|
|
881
|
+
option: 'u8',
|
|
446
882
|
},
|
|
447
883
|
},
|
|
448
884
|
{
|
|
449
|
-
name: '
|
|
885
|
+
name: 'isNative',
|
|
450
886
|
type: {
|
|
451
|
-
|
|
887
|
+
option: 'u64',
|
|
452
888
|
},
|
|
453
889
|
},
|
|
454
890
|
{
|
|
455
|
-
name: '
|
|
891
|
+
name: 'merkleContext',
|
|
456
892
|
type: {
|
|
457
|
-
|
|
893
|
+
defined: 'PackedMerkleContext',
|
|
458
894
|
},
|
|
459
895
|
},
|
|
896
|
+
{
|
|
897
|
+
name: 'rootIndex',
|
|
898
|
+
type: 'u16',
|
|
899
|
+
},
|
|
460
900
|
],
|
|
461
901
|
},
|
|
462
902
|
},
|
|
463
903
|
{
|
|
464
|
-
name: '
|
|
904
|
+
name: 'InstructionDataInvoke',
|
|
465
905
|
type: {
|
|
466
906
|
kind: 'struct',
|
|
467
907
|
fields: [
|
|
@@ -473,6 +913,28 @@ const IDL = {
|
|
|
473
913
|
},
|
|
474
914
|
},
|
|
475
915
|
},
|
|
916
|
+
{
|
|
917
|
+
name: 'inputCompressedAccountsWithMerkleContext',
|
|
918
|
+
type: {
|
|
919
|
+
vec: {
|
|
920
|
+
defined: 'PackedCompressedAccountWithMerkleContext',
|
|
921
|
+
},
|
|
922
|
+
},
|
|
923
|
+
},
|
|
924
|
+
{
|
|
925
|
+
name: 'outputCompressedAccounts',
|
|
926
|
+
type: {
|
|
927
|
+
vec: {
|
|
928
|
+
defined: 'OutputCompressedAccountWithPackedContext',
|
|
929
|
+
},
|
|
930
|
+
},
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
name: 'relayFee',
|
|
934
|
+
type: {
|
|
935
|
+
option: 'u64',
|
|
936
|
+
},
|
|
937
|
+
},
|
|
476
938
|
{
|
|
477
939
|
name: 'newAddressParams',
|
|
478
940
|
type: {
|
|
@@ -482,33 +944,54 @@ const IDL = {
|
|
|
482
944
|
},
|
|
483
945
|
},
|
|
484
946
|
{
|
|
485
|
-
name: '
|
|
947
|
+
name: 'compressOrDecompressLamports',
|
|
486
948
|
type: {
|
|
487
|
-
|
|
949
|
+
option: 'u64',
|
|
488
950
|
},
|
|
489
951
|
},
|
|
490
952
|
{
|
|
491
|
-
name: '
|
|
953
|
+
name: 'isCompress',
|
|
954
|
+
type: 'bool',
|
|
955
|
+
},
|
|
956
|
+
],
|
|
957
|
+
},
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
name: 'InstructionDataInvokeCpi',
|
|
961
|
+
type: {
|
|
962
|
+
kind: 'struct',
|
|
963
|
+
fields: [
|
|
964
|
+
{
|
|
965
|
+
name: 'proof',
|
|
966
|
+
type: {
|
|
967
|
+
option: {
|
|
968
|
+
defined: 'CompressedProof',
|
|
969
|
+
},
|
|
970
|
+
},
|
|
971
|
+
},
|
|
972
|
+
{
|
|
973
|
+
name: 'newAddressParams',
|
|
492
974
|
type: {
|
|
493
975
|
vec: {
|
|
494
|
-
defined: '
|
|
976
|
+
defined: 'NewAddressParamsPacked',
|
|
495
977
|
},
|
|
496
978
|
},
|
|
497
979
|
},
|
|
498
980
|
{
|
|
499
|
-
name: '
|
|
981
|
+
name: 'inputCompressedAccountsWithMerkleContext',
|
|
500
982
|
type: {
|
|
501
983
|
vec: {
|
|
502
|
-
defined: '
|
|
984
|
+
defined: 'PackedCompressedAccountWithMerkleContext',
|
|
503
985
|
},
|
|
504
986
|
},
|
|
505
987
|
},
|
|
506
988
|
{
|
|
507
|
-
name: '
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
989
|
+
name: 'outputCompressedAccounts',
|
|
990
|
+
type: {
|
|
991
|
+
vec: {
|
|
992
|
+
defined: 'OutputCompressedAccountWithPackedContext',
|
|
993
|
+
},
|
|
994
|
+
},
|
|
512
995
|
},
|
|
513
996
|
{
|
|
514
997
|
name: 'relayFee',
|
|
@@ -517,22 +1000,72 @@ const IDL = {
|
|
|
517
1000
|
},
|
|
518
1001
|
},
|
|
519
1002
|
{
|
|
520
|
-
name: '
|
|
1003
|
+
name: 'compressOrDecompressLamports',
|
|
521
1004
|
type: {
|
|
522
1005
|
option: 'u64',
|
|
523
1006
|
},
|
|
524
1007
|
},
|
|
525
1008
|
{
|
|
526
|
-
name: 'isCompress',
|
|
527
|
-
type: 'bool',
|
|
1009
|
+
name: 'isCompress',
|
|
1010
|
+
type: 'bool',
|
|
1011
|
+
},
|
|
1012
|
+
{
|
|
1013
|
+
name: 'signerSeeds',
|
|
1014
|
+
type: {
|
|
1015
|
+
vec: 'bytes',
|
|
1016
|
+
},
|
|
1017
|
+
},
|
|
1018
|
+
{
|
|
1019
|
+
name: 'cpiContext',
|
|
1020
|
+
type: {
|
|
1021
|
+
option: {
|
|
1022
|
+
defined: 'CompressedCpiContext',
|
|
1023
|
+
},
|
|
1024
|
+
},
|
|
1025
|
+
},
|
|
1026
|
+
],
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1029
|
+
{
|
|
1030
|
+
name: 'MerkleTreeMetadata',
|
|
1031
|
+
type: {
|
|
1032
|
+
kind: 'struct',
|
|
1033
|
+
fields: [
|
|
1034
|
+
{
|
|
1035
|
+
name: 'accessMetadata',
|
|
1036
|
+
type: {
|
|
1037
|
+
defined: 'AccessMetadata',
|
|
1038
|
+
},
|
|
1039
|
+
},
|
|
1040
|
+
{
|
|
1041
|
+
name: 'rolloverMetadata',
|
|
1042
|
+
type: {
|
|
1043
|
+
defined: 'RolloverMetadata',
|
|
1044
|
+
},
|
|
1045
|
+
},
|
|
1046
|
+
{
|
|
1047
|
+
name: 'associatedQueue',
|
|
1048
|
+
type: 'publicKey',
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
name: 'nextMerkleTree',
|
|
1052
|
+
type: 'publicKey',
|
|
1053
|
+
},
|
|
1054
|
+
],
|
|
1055
|
+
},
|
|
1056
|
+
},
|
|
1057
|
+
{
|
|
1058
|
+
name: 'MerkleTreeSequenceNumber',
|
|
1059
|
+
type: {
|
|
1060
|
+
kind: 'struct',
|
|
1061
|
+
fields: [
|
|
1062
|
+
{
|
|
1063
|
+
name: 'pubkey',
|
|
1064
|
+
type: 'publicKey',
|
|
528
1065
|
},
|
|
529
1066
|
{
|
|
530
|
-
name: '
|
|
531
|
-
type:
|
|
532
|
-
option: {
|
|
533
|
-
vec: 'bytes',
|
|
534
|
-
},
|
|
535
|
-
},
|
|
1067
|
+
name: 'seq',
|
|
1068
|
+
type: 'u64',
|
|
536
1069
|
},
|
|
537
1070
|
],
|
|
538
1071
|
},
|
|
@@ -564,84 +1097,55 @@ const IDL = {
|
|
|
564
1097
|
},
|
|
565
1098
|
},
|
|
566
1099
|
{
|
|
567
|
-
name: '
|
|
1100
|
+
name: 'OutputCompressedAccountWithPackedContext',
|
|
568
1101
|
type: {
|
|
569
1102
|
kind: 'struct',
|
|
570
1103
|
fields: [
|
|
571
1104
|
{
|
|
572
|
-
name: '
|
|
1105
|
+
name: 'compressedAccount',
|
|
573
1106
|
type: {
|
|
574
|
-
|
|
1107
|
+
defined: 'CompressedAccount',
|
|
575
1108
|
},
|
|
576
1109
|
},
|
|
577
1110
|
{
|
|
578
|
-
name: '
|
|
579
|
-
type: '
|
|
580
|
-
},
|
|
581
|
-
{
|
|
582
|
-
name: 'addressMerkleTreePubkey',
|
|
583
|
-
type: 'publicKey',
|
|
584
|
-
},
|
|
585
|
-
{
|
|
586
|
-
name: 'addressMerkleTreeRootIndex',
|
|
587
|
-
type: 'u16',
|
|
1111
|
+
name: 'merkleTreeIndex',
|
|
1112
|
+
type: 'u8',
|
|
588
1113
|
},
|
|
589
1114
|
],
|
|
590
1115
|
},
|
|
591
1116
|
},
|
|
592
1117
|
{
|
|
593
|
-
name: '
|
|
1118
|
+
name: 'PackedCompressedAccountWithMerkleContext',
|
|
594
1119
|
type: {
|
|
595
1120
|
kind: 'struct',
|
|
596
1121
|
fields: [
|
|
597
1122
|
{
|
|
598
|
-
name: '
|
|
1123
|
+
name: 'compressedAccount',
|
|
599
1124
|
type: {
|
|
600
|
-
|
|
1125
|
+
defined: 'CompressedAccount',
|
|
601
1126
|
},
|
|
602
1127
|
},
|
|
603
1128
|
{
|
|
604
|
-
name: '
|
|
1129
|
+
name: 'merkleContext',
|
|
605
1130
|
type: {
|
|
606
|
-
|
|
1131
|
+
defined: 'PackedMerkleContext',
|
|
607
1132
|
},
|
|
608
1133
|
},
|
|
609
1134
|
{
|
|
610
|
-
name: '
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
1135
|
+
name: 'rootIndex',
|
|
1136
|
+
docs: [
|
|
1137
|
+
'Index of root used in inclusion validity proof.',
|
|
1138
|
+
],
|
|
1139
|
+
type: 'u16',
|
|
614
1140
|
},
|
|
615
1141
|
],
|
|
616
1142
|
},
|
|
617
1143
|
},
|
|
618
1144
|
{
|
|
619
|
-
name: '
|
|
1145
|
+
name: 'PackedMerkleContext',
|
|
620
1146
|
type: {
|
|
621
1147
|
kind: 'struct',
|
|
622
1148
|
fields: [
|
|
623
|
-
{
|
|
624
|
-
name: 'amount',
|
|
625
|
-
type: 'u64',
|
|
626
|
-
},
|
|
627
|
-
{
|
|
628
|
-
name: 'delegateIndex',
|
|
629
|
-
type: {
|
|
630
|
-
option: 'u8',
|
|
631
|
-
},
|
|
632
|
-
},
|
|
633
|
-
{
|
|
634
|
-
name: 'delegatedAmount',
|
|
635
|
-
type: {
|
|
636
|
-
option: 'u64',
|
|
637
|
-
},
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
name: 'isNative',
|
|
641
|
-
type: {
|
|
642
|
-
option: 'u64',
|
|
643
|
-
},
|
|
644
|
-
},
|
|
645
1149
|
{
|
|
646
1150
|
name: 'merkleTreePubkeyIndex',
|
|
647
1151
|
type: 'u8',
|
|
@@ -658,37 +1162,49 @@ const IDL = {
|
|
|
658
1162
|
},
|
|
659
1163
|
},
|
|
660
1164
|
{
|
|
661
|
-
name: '
|
|
1165
|
+
name: 'PackedTokenTransferOutputData',
|
|
662
1166
|
type: {
|
|
663
1167
|
kind: 'struct',
|
|
664
1168
|
fields: [
|
|
665
1169
|
{
|
|
666
|
-
name: '
|
|
667
|
-
type:
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
1170
|
+
name: 'owner',
|
|
1171
|
+
type: 'publicKey',
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
name: 'amount',
|
|
1175
|
+
type: 'u64',
|
|
672
1176
|
},
|
|
673
1177
|
{
|
|
674
|
-
name: '
|
|
1178
|
+
name: 'lamports',
|
|
675
1179
|
type: {
|
|
676
|
-
|
|
1180
|
+
option: 'u64',
|
|
677
1181
|
},
|
|
678
1182
|
},
|
|
679
1183
|
{
|
|
680
|
-
name: '
|
|
681
|
-
type: '
|
|
1184
|
+
name: 'merkleTreeIndex',
|
|
1185
|
+
type: 'u8',
|
|
682
1186
|
},
|
|
1187
|
+
],
|
|
1188
|
+
},
|
|
1189
|
+
},
|
|
1190
|
+
{
|
|
1191
|
+
name: 'PublicTransactionEvent',
|
|
1192
|
+
type: {
|
|
1193
|
+
kind: 'struct',
|
|
1194
|
+
fields: [
|
|
683
1195
|
{
|
|
684
|
-
name: '
|
|
685
|
-
type:
|
|
1196
|
+
name: 'inputCompressedAccountHashes',
|
|
1197
|
+
type: {
|
|
1198
|
+
vec: {
|
|
1199
|
+
array: ['u8', 32],
|
|
1200
|
+
},
|
|
1201
|
+
},
|
|
686
1202
|
},
|
|
687
1203
|
{
|
|
688
|
-
name: '
|
|
1204
|
+
name: 'outputCompressedAccountHashes',
|
|
689
1205
|
type: {
|
|
690
1206
|
vec: {
|
|
691
|
-
|
|
1207
|
+
array: ['u8', 32],
|
|
692
1208
|
},
|
|
693
1209
|
},
|
|
694
1210
|
},
|
|
@@ -696,227 +1212,152 @@ const IDL = {
|
|
|
696
1212
|
name: 'outputCompressedAccounts',
|
|
697
1213
|
type: {
|
|
698
1214
|
vec: {
|
|
699
|
-
defined: '
|
|
1215
|
+
defined: 'OutputCompressedAccountWithPackedContext',
|
|
700
1216
|
},
|
|
701
1217
|
},
|
|
702
1218
|
},
|
|
703
1219
|
{
|
|
704
|
-
name: '
|
|
705
|
-
type: 'bytes',
|
|
706
|
-
},
|
|
707
|
-
{
|
|
708
|
-
name: 'isCompress',
|
|
709
|
-
type: 'bool',
|
|
710
|
-
},
|
|
711
|
-
{
|
|
712
|
-
name: 'compressionAmount',
|
|
1220
|
+
name: 'outputLeafIndices',
|
|
713
1221
|
type: {
|
|
714
|
-
|
|
1222
|
+
vec: 'u32',
|
|
715
1223
|
},
|
|
716
1224
|
},
|
|
717
|
-
],
|
|
718
|
-
},
|
|
719
|
-
},
|
|
720
|
-
{
|
|
721
|
-
name: 'TokenTransferOutputData',
|
|
722
|
-
type: {
|
|
723
|
-
kind: 'struct',
|
|
724
|
-
fields: [
|
|
725
|
-
{
|
|
726
|
-
name: 'owner',
|
|
727
|
-
type: 'publicKey',
|
|
728
|
-
},
|
|
729
1225
|
{
|
|
730
|
-
name: '
|
|
731
|
-
type:
|
|
1226
|
+
name: 'sequenceNumbers',
|
|
1227
|
+
type: {
|
|
1228
|
+
vec: {
|
|
1229
|
+
defined: 'MerkleTreeSequenceNumber',
|
|
1230
|
+
},
|
|
1231
|
+
},
|
|
732
1232
|
},
|
|
733
1233
|
{
|
|
734
|
-
name: '
|
|
1234
|
+
name: 'relayFee',
|
|
735
1235
|
type: {
|
|
736
1236
|
option: 'u64',
|
|
737
1237
|
},
|
|
738
1238
|
},
|
|
739
|
-
],
|
|
740
|
-
},
|
|
741
|
-
},
|
|
742
|
-
{
|
|
743
|
-
name: 'TokenData',
|
|
744
|
-
type: {
|
|
745
|
-
kind: 'struct',
|
|
746
|
-
fields: [
|
|
747
|
-
{
|
|
748
|
-
name: 'mint',
|
|
749
|
-
docs: ['The mint associated with this account'],
|
|
750
|
-
type: 'publicKey',
|
|
751
|
-
},
|
|
752
|
-
{
|
|
753
|
-
name: 'owner',
|
|
754
|
-
docs: ['The owner of this account.'],
|
|
755
|
-
type: 'publicKey',
|
|
756
|
-
},
|
|
757
1239
|
{
|
|
758
|
-
name: '
|
|
759
|
-
|
|
760
|
-
type: 'u64',
|
|
1240
|
+
name: 'isCompress',
|
|
1241
|
+
type: 'bool',
|
|
761
1242
|
},
|
|
762
1243
|
{
|
|
763
|
-
name: '
|
|
764
|
-
docs: [
|
|
765
|
-
'If `delegate` is `Some` then `delegated_amount` represents',
|
|
766
|
-
'the amount authorized by the delegate',
|
|
767
|
-
],
|
|
1244
|
+
name: 'compressOrDecompressLamports',
|
|
768
1245
|
type: {
|
|
769
|
-
option: '
|
|
1246
|
+
option: 'u64',
|
|
770
1247
|
},
|
|
771
1248
|
},
|
|
772
1249
|
{
|
|
773
|
-
name: '
|
|
774
|
-
docs: ["The account's state"],
|
|
1250
|
+
name: 'pubkeyArray',
|
|
775
1251
|
type: {
|
|
776
|
-
|
|
1252
|
+
vec: 'publicKey',
|
|
777
1253
|
},
|
|
778
1254
|
},
|
|
779
1255
|
{
|
|
780
|
-
name: '
|
|
781
|
-
docs: [
|
|
782
|
-
'If is_some, this is a native token, and the value logs the rent-exempt',
|
|
783
|
-
'reserve. An Account is required to be rent-exempt, so the value is',
|
|
784
|
-
'used by the Processor to ensure that wrapped SOL accounts do not',
|
|
785
|
-
'drop below this threshold.',
|
|
786
|
-
],
|
|
1256
|
+
name: 'message',
|
|
787
1257
|
type: {
|
|
788
|
-
option: '
|
|
1258
|
+
option: 'bytes',
|
|
789
1259
|
},
|
|
790
1260
|
},
|
|
791
|
-
{
|
|
792
|
-
name: 'delegatedAmount',
|
|
793
|
-
docs: ['The amount delegated'],
|
|
794
|
-
type: 'u64',
|
|
795
|
-
},
|
|
796
1261
|
],
|
|
797
1262
|
},
|
|
798
1263
|
},
|
|
799
1264
|
{
|
|
800
|
-
name: '
|
|
1265
|
+
name: 'RolloverMetadata',
|
|
801
1266
|
type: {
|
|
802
1267
|
kind: 'struct',
|
|
803
1268
|
fields: [
|
|
804
1269
|
{
|
|
805
|
-
name: '
|
|
806
|
-
docs: ['
|
|
807
|
-
type: 'publicKey',
|
|
808
|
-
},
|
|
809
|
-
{
|
|
810
|
-
name: 'owner',
|
|
811
|
-
docs: ['The owner of this account.'],
|
|
812
|
-
type: 'publicKey',
|
|
813
|
-
},
|
|
814
|
-
{
|
|
815
|
-
name: 'amount',
|
|
816
|
-
docs: ['The amount of tokens this account holds.'],
|
|
1270
|
+
name: 'index',
|
|
1271
|
+
docs: ['Unique index.'],
|
|
817
1272
|
type: 'u64',
|
|
818
1273
|
},
|
|
819
1274
|
{
|
|
820
|
-
name: '
|
|
1275
|
+
name: 'rolloverFee',
|
|
821
1276
|
docs: [
|
|
822
|
-
'
|
|
823
|
-
'the
|
|
1277
|
+
'This fee is used for rent for the next account.',
|
|
1278
|
+
'It accumulates in the account so that once the corresponding Merkle tree account is full it can be rolled over',
|
|
824
1279
|
],
|
|
825
|
-
type:
|
|
826
|
-
option: 'publicKey',
|
|
827
|
-
},
|
|
828
|
-
},
|
|
829
|
-
{
|
|
830
|
-
name: 'state',
|
|
831
|
-
docs: ["The account's state"],
|
|
832
|
-
type: 'u8',
|
|
1280
|
+
type: 'u64',
|
|
833
1281
|
},
|
|
834
1282
|
{
|
|
835
|
-
name: '
|
|
1283
|
+
name: 'rolloverThreshold',
|
|
836
1284
|
docs: [
|
|
837
|
-
'
|
|
838
|
-
'reserve. An Account is required to be rent-exempt, so the value is',
|
|
839
|
-
'used by the Processor to ensure that wrapped SOL accounts do not',
|
|
840
|
-
'drop below this threshold.',
|
|
1285
|
+
'The threshold in percentage points when the account should be rolled over (95 corresponds to 95% filled).',
|
|
841
1286
|
],
|
|
842
|
-
type: {
|
|
843
|
-
option: 'u64',
|
|
844
|
-
},
|
|
845
|
-
},
|
|
846
|
-
{
|
|
847
|
-
name: 'delegatedAmount',
|
|
848
|
-
docs: ['The amount delegated'],
|
|
849
1287
|
type: 'u64',
|
|
850
1288
|
},
|
|
851
|
-
],
|
|
852
|
-
},
|
|
853
|
-
},
|
|
854
|
-
{
|
|
855
|
-
name: 'AccountState',
|
|
856
|
-
type: {
|
|
857
|
-
kind: 'enum',
|
|
858
|
-
variants: [
|
|
859
1289
|
{
|
|
860
|
-
name: '
|
|
1290
|
+
name: 'networkFee',
|
|
1291
|
+
docs: ['Tip for maintaining the account.'],
|
|
1292
|
+
type: 'u64',
|
|
861
1293
|
},
|
|
862
1294
|
{
|
|
863
|
-
name: '
|
|
1295
|
+
name: 'rolledoverSlot',
|
|
1296
|
+
docs: [
|
|
1297
|
+
'The slot when the account was rolled over, a rolled over account should not be written to.',
|
|
1298
|
+
],
|
|
1299
|
+
type: 'u64',
|
|
864
1300
|
},
|
|
865
1301
|
{
|
|
866
|
-
name: '
|
|
1302
|
+
name: 'closeThreshold',
|
|
1303
|
+
docs: [
|
|
1304
|
+
'If current slot is greater than rolledover_slot + close_threshold and',
|
|
1305
|
+
"the account is empty it can be closed. No 'close' functionality has been",
|
|
1306
|
+
'implemented yet.',
|
|
1307
|
+
],
|
|
1308
|
+
type: 'u64',
|
|
867
1309
|
},
|
|
868
1310
|
],
|
|
869
|
-
},
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
name: '
|
|
873
|
-
type: {
|
|
874
|
-
kind: '
|
|
875
|
-
|
|
876
|
-
{
|
|
877
|
-
name: 'PublicKeyAmountMissmatch',
|
|
878
|
-
},
|
|
879
|
-
{
|
|
880
|
-
name: 'MissingNewAuthorityPda',
|
|
881
|
-
},
|
|
882
|
-
{
|
|
883
|
-
name: 'SignerCheckFailed',
|
|
884
|
-
},
|
|
885
|
-
{
|
|
886
|
-
name: 'MintCheckFailed',
|
|
887
|
-
},
|
|
888
|
-
{
|
|
889
|
-
name: 'ComputeInputSumFailed',
|
|
890
|
-
},
|
|
891
|
-
{
|
|
892
|
-
name: 'ComputeOutputSumFailed',
|
|
893
|
-
},
|
|
894
|
-
{
|
|
895
|
-
name: 'ComputeCompressSumFailed',
|
|
896
|
-
},
|
|
897
|
-
{
|
|
898
|
-
name: 'ComputeDecompressSumFailed',
|
|
899
|
-
},
|
|
900
|
-
{
|
|
901
|
-
name: 'SumCheckFailed',
|
|
902
|
-
},
|
|
1311
|
+
},
|
|
1312
|
+
},
|
|
1313
|
+
{
|
|
1314
|
+
name: 'TokenData',
|
|
1315
|
+
type: {
|
|
1316
|
+
kind: 'struct',
|
|
1317
|
+
fields: [
|
|
903
1318
|
{
|
|
904
|
-
name: '
|
|
1319
|
+
name: 'mint',
|
|
1320
|
+
docs: ['The mint associated with this account'],
|
|
1321
|
+
type: 'publicKey',
|
|
905
1322
|
},
|
|
906
1323
|
{
|
|
907
|
-
name: '
|
|
1324
|
+
name: 'owner',
|
|
1325
|
+
docs: ['The owner of this account.'],
|
|
1326
|
+
type: 'publicKey',
|
|
908
1327
|
},
|
|
909
1328
|
{
|
|
910
|
-
name: '
|
|
1329
|
+
name: 'amount',
|
|
1330
|
+
docs: ['The amount of tokens this account holds.'],
|
|
1331
|
+
type: 'u64',
|
|
911
1332
|
},
|
|
912
1333
|
{
|
|
913
|
-
name: '
|
|
1334
|
+
name: 'delegate',
|
|
1335
|
+
docs: [
|
|
1336
|
+
'If `delegate` is `Some` then `delegated_amount` represents',
|
|
1337
|
+
'the amount authorized by the delegate',
|
|
1338
|
+
],
|
|
1339
|
+
type: {
|
|
1340
|
+
option: 'publicKey',
|
|
1341
|
+
},
|
|
914
1342
|
},
|
|
915
1343
|
{
|
|
916
|
-
name: '
|
|
1344
|
+
name: 'state',
|
|
1345
|
+
docs: ["The account's state"],
|
|
1346
|
+
type: {
|
|
1347
|
+
defined: 'AccountState',
|
|
1348
|
+
},
|
|
917
1349
|
},
|
|
918
1350
|
{
|
|
919
|
-
name: '
|
|
1351
|
+
name: 'isNative',
|
|
1352
|
+
docs: [
|
|
1353
|
+
'If is_some, this is a native token, and the value logs the rent-exempt',
|
|
1354
|
+
'reserve. An Account is required to be rent-exempt, so the value is',
|
|
1355
|
+
'used by the Processor to ensure that wrapped SOL accounts do not',
|
|
1356
|
+
'drop below this threshold.',
|
|
1357
|
+
],
|
|
1358
|
+
type: {
|
|
1359
|
+
option: 'u64',
|
|
1360
|
+
},
|
|
920
1361
|
},
|
|
921
1362
|
],
|
|
922
1363
|
},
|
|
@@ -925,13 +1366,108 @@ const IDL = {
|
|
|
925
1366
|
errors: [
|
|
926
1367
|
{
|
|
927
1368
|
code: 6000,
|
|
928
|
-
name: '
|
|
929
|
-
msg: '
|
|
1369
|
+
name: 'PublicKeyAmountMissmatch',
|
|
1370
|
+
msg: 'public keys and amounts must be of same length',
|
|
930
1371
|
},
|
|
931
1372
|
{
|
|
932
1373
|
code: 6001,
|
|
933
|
-
name: '
|
|
934
|
-
msg: '
|
|
1374
|
+
name: 'SignerCheckFailed',
|
|
1375
|
+
msg: 'SignerCheckFailed',
|
|
1376
|
+
},
|
|
1377
|
+
{
|
|
1378
|
+
code: 6002,
|
|
1379
|
+
name: 'ComputeInputSumFailed',
|
|
1380
|
+
msg: 'ComputeInputSumFailed',
|
|
1381
|
+
},
|
|
1382
|
+
{
|
|
1383
|
+
code: 6003,
|
|
1384
|
+
name: 'ComputeOutputSumFailed',
|
|
1385
|
+
msg: 'ComputeOutputSumFailed',
|
|
1386
|
+
},
|
|
1387
|
+
{
|
|
1388
|
+
code: 6004,
|
|
1389
|
+
name: 'ComputeCompressSumFailed',
|
|
1390
|
+
msg: 'ComputeCompressSumFailed',
|
|
1391
|
+
},
|
|
1392
|
+
{
|
|
1393
|
+
code: 6005,
|
|
1394
|
+
name: 'ComputeDecompressSumFailed',
|
|
1395
|
+
msg: 'ComputeDecompressSumFailed',
|
|
1396
|
+
},
|
|
1397
|
+
{
|
|
1398
|
+
code: 6006,
|
|
1399
|
+
name: 'SumCheckFailed',
|
|
1400
|
+
msg: 'SumCheckFailed',
|
|
1401
|
+
},
|
|
1402
|
+
{
|
|
1403
|
+
code: 6007,
|
|
1404
|
+
name: 'DecompressRecipientUndefinedForDecompress',
|
|
1405
|
+
msg: 'DecompressRecipientUndefinedForDecompress',
|
|
1406
|
+
},
|
|
1407
|
+
{
|
|
1408
|
+
code: 6008,
|
|
1409
|
+
name: 'CompressedPdaUndefinedForDecompress',
|
|
1410
|
+
msg: 'CompressedPdaUndefinedForDecompress',
|
|
1411
|
+
},
|
|
1412
|
+
{
|
|
1413
|
+
code: 6009,
|
|
1414
|
+
name: 'DeCompressAmountUndefinedForDecompress',
|
|
1415
|
+
msg: 'DeCompressAmountUndefinedForDecompress',
|
|
1416
|
+
},
|
|
1417
|
+
{
|
|
1418
|
+
code: 6010,
|
|
1419
|
+
name: 'CompressedPdaUndefinedForCompress',
|
|
1420
|
+
msg: 'CompressedPdaUndefinedForCompress',
|
|
1421
|
+
},
|
|
1422
|
+
{
|
|
1423
|
+
code: 6011,
|
|
1424
|
+
name: 'DeCompressAmountUndefinedForCompress',
|
|
1425
|
+
msg: 'DeCompressAmountUndefinedForCompress',
|
|
1426
|
+
},
|
|
1427
|
+
{
|
|
1428
|
+
code: 6012,
|
|
1429
|
+
name: 'DelegateUndefined',
|
|
1430
|
+
msg: 'DelegateUndefined while delegated amount is defined',
|
|
1431
|
+
},
|
|
1432
|
+
{
|
|
1433
|
+
code: 6013,
|
|
1434
|
+
name: 'DelegateSignerCheckFailed',
|
|
1435
|
+
msg: 'DelegateSignerCheckFailed',
|
|
1436
|
+
},
|
|
1437
|
+
{
|
|
1438
|
+
code: 6014,
|
|
1439
|
+
name: 'SplTokenSupplyMismatch',
|
|
1440
|
+
msg: 'SplTokenSupplyMismatch',
|
|
1441
|
+
},
|
|
1442
|
+
{
|
|
1443
|
+
code: 6015,
|
|
1444
|
+
name: 'HeapMemoryCheckFailed',
|
|
1445
|
+
msg: 'HeapMemoryCheckFailed',
|
|
1446
|
+
},
|
|
1447
|
+
{
|
|
1448
|
+
code: 6016,
|
|
1449
|
+
name: 'InstructionNotCallable',
|
|
1450
|
+
msg: 'The instruction is not callable',
|
|
1451
|
+
},
|
|
1452
|
+
{
|
|
1453
|
+
code: 6017,
|
|
1454
|
+
name: 'ArithmeticUnderflow',
|
|
1455
|
+
msg: 'ArithmeticUnderflow',
|
|
1456
|
+
},
|
|
1457
|
+
{
|
|
1458
|
+
code: 6018,
|
|
1459
|
+
name: 'InvalidDelegate',
|
|
1460
|
+
msg: 'InvalidDelegate',
|
|
1461
|
+
},
|
|
1462
|
+
{
|
|
1463
|
+
code: 6019,
|
|
1464
|
+
name: 'HashToFieldError',
|
|
1465
|
+
msg: 'HashToFieldError',
|
|
1466
|
+
},
|
|
1467
|
+
{
|
|
1468
|
+
code: 6020,
|
|
1469
|
+
name: 'InvalidMint',
|
|
1470
|
+
msg: 'InvalidMint',
|
|
935
1471
|
},
|
|
936
1472
|
],
|
|
937
1473
|
};
|
|
@@ -941,7 +1477,7 @@ const IDL = {
|
|
|
941
1477
|
* Packs Compressed Token Accounts.
|
|
942
1478
|
*/
|
|
943
1479
|
function packCompressedTokenAccounts(params) {
|
|
944
|
-
const { inputCompressedTokenAccounts,
|
|
1480
|
+
const { inputCompressedTokenAccounts, outputStateTrees, remainingAccounts = [], rootIndices, tokenTransferOutputs, } = params;
|
|
945
1481
|
const _remainingAccounts = remainingAccounts.slice();
|
|
946
1482
|
let delegateIndex = null;
|
|
947
1483
|
if (inputCompressedTokenAccounts.length > 0 &&
|
|
@@ -952,27 +1488,35 @@ function packCompressedTokenAccounts(params) {
|
|
|
952
1488
|
/// Currently just packs 'delegate' to pubkeyArray
|
|
953
1489
|
const packedInputTokenData = [];
|
|
954
1490
|
/// pack inputs
|
|
955
|
-
inputCompressedTokenAccounts.forEach((account) => {
|
|
1491
|
+
inputCompressedTokenAccounts.forEach((account, index) => {
|
|
956
1492
|
const merkleTreePubkeyIndex = stateless_js.getIndexOrAdd(_remainingAccounts, account.compressedAccount.merkleTree);
|
|
957
1493
|
const nullifierQueuePubkeyIndex = stateless_js.getIndexOrAdd(_remainingAccounts, account.compressedAccount.nullifierQueue);
|
|
958
1494
|
packedInputTokenData.push({
|
|
959
1495
|
amount: account.parsed.amount,
|
|
960
1496
|
delegateIndex,
|
|
961
|
-
delegatedAmount: account.parsed.delegatedAmount.eq(stateless_js.bn(0))
|
|
962
|
-
? null
|
|
963
|
-
: account.parsed.delegatedAmount,
|
|
964
1497
|
isNative: account.parsed.isNative,
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1498
|
+
merkleContext: {
|
|
1499
|
+
merkleTreePubkeyIndex,
|
|
1500
|
+
nullifierQueuePubkeyIndex,
|
|
1501
|
+
leafIndex: account.compressedAccount.leafIndex,
|
|
1502
|
+
},
|
|
1503
|
+
rootIndex: rootIndices[index],
|
|
968
1504
|
});
|
|
969
1505
|
});
|
|
970
1506
|
/// pack output state trees
|
|
971
|
-
const paddedOutputStateMerkleTrees = stateless_js.padOutputStateMerkleTrees(outputStateTrees,
|
|
972
|
-
const
|
|
973
|
-
paddedOutputStateMerkleTrees.forEach(account => {
|
|
974
|
-
|
|
975
|
-
|
|
1507
|
+
const paddedOutputStateMerkleTrees = stateless_js.padOutputStateMerkleTrees(outputStateTrees, tokenTransferOutputs.length, inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
1508
|
+
const packedOutputTokenData = [];
|
|
1509
|
+
paddedOutputStateMerkleTrees.forEach((account, index) => {
|
|
1510
|
+
var _a;
|
|
1511
|
+
const merkleTreeIndex = stateless_js.getIndexOrAdd(_remainingAccounts, account);
|
|
1512
|
+
packedOutputTokenData.push({
|
|
1513
|
+
owner: tokenTransferOutputs[index].owner,
|
|
1514
|
+
amount: tokenTransferOutputs[index].amount,
|
|
1515
|
+
lamports: ((_a = tokenTransferOutputs[index].lamports) === null || _a === void 0 ? void 0 : _a.eq(stateless_js.bn(0)))
|
|
1516
|
+
? null
|
|
1517
|
+
: tokenTransferOutputs[index].lamports,
|
|
1518
|
+
merkleTreeIndex,
|
|
1519
|
+
});
|
|
976
1520
|
});
|
|
977
1521
|
// to meta
|
|
978
1522
|
const remainingAccountMetas = _remainingAccounts.map((account) => ({
|
|
@@ -982,14 +1526,13 @@ function packCompressedTokenAccounts(params) {
|
|
|
982
1526
|
}));
|
|
983
1527
|
return {
|
|
984
1528
|
inputTokenDataWithContext: packedInputTokenData,
|
|
985
|
-
outputStateMerkleTreeIndices,
|
|
986
1529
|
remainingAccountMetas,
|
|
1530
|
+
packedOutputTokenData,
|
|
987
1531
|
};
|
|
988
1532
|
}
|
|
989
1533
|
|
|
990
1534
|
const POOL_SEED = Buffer.from('pool');
|
|
991
1535
|
const CPI_AUTHORITY_SEED = Buffer.from('cpi_authority');
|
|
992
|
-
const MINT_AUTHORITY_SEED = anchor.utils.bytes.utf8.encode('mint_authority_pda');
|
|
993
1536
|
const SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = 1461600;
|
|
994
1537
|
|
|
995
1538
|
/** Address of the SPL Token program */
|
|
@@ -997,7 +1540,7 @@ const TOKEN_PROGRAM_ID = new web3_js.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf
|
|
|
997
1540
|
/** Address of the SPL Token 2022 program */
|
|
998
1541
|
new web3_js.PublicKey('TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb');
|
|
999
1542
|
/** Address of the SPL Associated Token Account program */
|
|
1000
|
-
new web3_js.PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
1543
|
+
const ASSOCIATED_TOKEN_PROGRAM_ID = new web3_js.PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
1001
1544
|
/** Address of the special mint for wrapped native SOL in spl-token */
|
|
1002
1545
|
new web3_js.PublicKey('So11111111111111111111111111111111111111112');
|
|
1003
1546
|
/** Address of the special mint for wrapped native SOL in spl-token-2022 */
|
|
@@ -5426,6 +5969,62 @@ const publicKey = (property) => {
|
|
|
5426
5969
|
return publicKeyLayout;
|
|
5427
5970
|
};
|
|
5428
5971
|
|
|
5972
|
+
/** Base class for errors */
|
|
5973
|
+
class TokenError extends Error {
|
|
5974
|
+
constructor(message) {
|
|
5975
|
+
super(message);
|
|
5976
|
+
}
|
|
5977
|
+
}
|
|
5978
|
+
/** Thrown if an account is not found at the expected address */
|
|
5979
|
+
class TokenAccountNotFoundError extends TokenError {
|
|
5980
|
+
constructor() {
|
|
5981
|
+
super(...arguments);
|
|
5982
|
+
this.name = 'TokenAccountNotFoundError';
|
|
5983
|
+
}
|
|
5984
|
+
}
|
|
5985
|
+
/** Thrown if a program state account is not a valid Account */
|
|
5986
|
+
class TokenInvalidAccountError extends TokenError {
|
|
5987
|
+
constructor() {
|
|
5988
|
+
super(...arguments);
|
|
5989
|
+
this.name = 'TokenInvalidAccountError';
|
|
5990
|
+
}
|
|
5991
|
+
}
|
|
5992
|
+
/** Thrown if a program state account is not owned by the expected token program */
|
|
5993
|
+
class TokenInvalidAccountOwnerError extends TokenError {
|
|
5994
|
+
constructor() {
|
|
5995
|
+
super(...arguments);
|
|
5996
|
+
this.name = 'TokenInvalidAccountOwnerError';
|
|
5997
|
+
}
|
|
5998
|
+
}
|
|
5999
|
+
/** Thrown if the byte length of an program state account doesn't match the expected size */
|
|
6000
|
+
class TokenInvalidAccountSizeError extends TokenError {
|
|
6001
|
+
constructor() {
|
|
6002
|
+
super(...arguments);
|
|
6003
|
+
this.name = 'TokenInvalidAccountSizeError';
|
|
6004
|
+
}
|
|
6005
|
+
}
|
|
6006
|
+
/** Thrown if the mint of a token account doesn't match the expected mint */
|
|
6007
|
+
class TokenInvalidMintError extends TokenError {
|
|
6008
|
+
constructor() {
|
|
6009
|
+
super(...arguments);
|
|
6010
|
+
this.name = 'TokenInvalidMintError';
|
|
6011
|
+
}
|
|
6012
|
+
}
|
|
6013
|
+
/** Thrown if the owner of a token account doesn't match the expected owner */
|
|
6014
|
+
class TokenInvalidOwnerError extends TokenError {
|
|
6015
|
+
constructor() {
|
|
6016
|
+
super(...arguments);
|
|
6017
|
+
this.name = 'TokenInvalidOwnerError';
|
|
6018
|
+
}
|
|
6019
|
+
}
|
|
6020
|
+
/** Thrown if the owner of a token account is a PDA (Program Derived Address) */
|
|
6021
|
+
class TokenOwnerOffCurveError extends TokenError {
|
|
6022
|
+
constructor() {
|
|
6023
|
+
super(...arguments);
|
|
6024
|
+
this.name = 'TokenOwnerOffCurveError';
|
|
6025
|
+
}
|
|
6026
|
+
}
|
|
6027
|
+
|
|
5429
6028
|
/** Instructions defined by the program */
|
|
5430
6029
|
var TokenInstruction;
|
|
5431
6030
|
(function (TokenInstruction) {
|
|
@@ -5465,6 +6064,10 @@ var TokenInstruction;
|
|
|
5465
6064
|
TokenInstruction[TokenInstruction["InterestBearingMintExtension"] = 33] = "InterestBearingMintExtension";
|
|
5466
6065
|
TokenInstruction[TokenInstruction["CpiGuardExtension"] = 34] = "CpiGuardExtension";
|
|
5467
6066
|
TokenInstruction[TokenInstruction["InitializePermanentDelegate"] = 35] = "InitializePermanentDelegate";
|
|
6067
|
+
TokenInstruction[TokenInstruction["TransferHookExtension"] = 36] = "TransferHookExtension";
|
|
6068
|
+
// ConfidentialTransferFeeExtension = 37,
|
|
6069
|
+
// WithdrawalExcessLamports = 38,
|
|
6070
|
+
TokenInstruction[TokenInstruction["MetadataPointerExtension"] = 39] = "MetadataPointerExtension";
|
|
5468
6071
|
})(TokenInstruction || (TokenInstruction = {}));
|
|
5469
6072
|
|
|
5470
6073
|
/** @internal */
|
|
@@ -5512,6 +6115,112 @@ function createApproveInstruction(account, delegate, owner, amount, multiSigners
|
|
|
5512
6115
|
return new web3_js.TransactionInstruction({ keys, programId, data });
|
|
5513
6116
|
}
|
|
5514
6117
|
|
|
6118
|
+
var AccountType;
|
|
6119
|
+
(function (AccountType) {
|
|
6120
|
+
AccountType[AccountType["Uninitialized"] = 0] = "Uninitialized";
|
|
6121
|
+
AccountType[AccountType["Mint"] = 1] = "Mint";
|
|
6122
|
+
AccountType[AccountType["Account"] = 2] = "Account";
|
|
6123
|
+
})(AccountType || (AccountType = {}));
|
|
6124
|
+
const ACCOUNT_TYPE_SIZE = 1;
|
|
6125
|
+
|
|
6126
|
+
/** Buffer layout for de/serializing a multisig */
|
|
6127
|
+
const MultisigLayout = struct([
|
|
6128
|
+
u8('m'),
|
|
6129
|
+
u8('n'),
|
|
6130
|
+
bool('isInitialized'),
|
|
6131
|
+
publicKey('signer1'),
|
|
6132
|
+
publicKey('signer2'),
|
|
6133
|
+
publicKey('signer3'),
|
|
6134
|
+
publicKey('signer4'),
|
|
6135
|
+
publicKey('signer5'),
|
|
6136
|
+
publicKey('signer6'),
|
|
6137
|
+
publicKey('signer7'),
|
|
6138
|
+
publicKey('signer8'),
|
|
6139
|
+
publicKey('signer9'),
|
|
6140
|
+
publicKey('signer10'),
|
|
6141
|
+
publicKey('signer11'),
|
|
6142
|
+
]);
|
|
6143
|
+
/** Byte length of a multisig */
|
|
6144
|
+
const MULTISIG_SIZE = MultisigLayout.span;
|
|
6145
|
+
|
|
6146
|
+
/** Token account state as stored by the program */
|
|
6147
|
+
var AccountState;
|
|
6148
|
+
(function (AccountState) {
|
|
6149
|
+
AccountState[AccountState["Uninitialized"] = 0] = "Uninitialized";
|
|
6150
|
+
AccountState[AccountState["Initialized"] = 1] = "Initialized";
|
|
6151
|
+
AccountState[AccountState["Frozen"] = 2] = "Frozen";
|
|
6152
|
+
})(AccountState || (AccountState = {}));
|
|
6153
|
+
/** Buffer layout for de/serializing a token account */
|
|
6154
|
+
const AccountLayout = struct([
|
|
6155
|
+
publicKey('mint'),
|
|
6156
|
+
publicKey('owner'),
|
|
6157
|
+
u64('amount'),
|
|
6158
|
+
u32('delegateOption'),
|
|
6159
|
+
publicKey('delegate'),
|
|
6160
|
+
u8('state'),
|
|
6161
|
+
u32('isNativeOption'),
|
|
6162
|
+
u64('isNative'),
|
|
6163
|
+
u64('delegatedAmount'),
|
|
6164
|
+
u32('closeAuthorityOption'),
|
|
6165
|
+
publicKey('closeAuthority'),
|
|
6166
|
+
]);
|
|
6167
|
+
/** Byte length of a token account */
|
|
6168
|
+
const ACCOUNT_SIZE = AccountLayout.span;
|
|
6169
|
+
/**
|
|
6170
|
+
* Retrieve information about a token account
|
|
6171
|
+
*
|
|
6172
|
+
* @param connection Connection to use
|
|
6173
|
+
* @param address Token account
|
|
6174
|
+
* @param commitment Desired level of commitment for querying the state
|
|
6175
|
+
* @param programId SPL Token program account
|
|
6176
|
+
*
|
|
6177
|
+
* @return Token account information
|
|
6178
|
+
*/
|
|
6179
|
+
async function getAccount(connection, address, commitment, programId = TOKEN_PROGRAM_ID) {
|
|
6180
|
+
const info = await connection.getAccountInfo(address, commitment);
|
|
6181
|
+
return unpackAccount(address, info, programId);
|
|
6182
|
+
}
|
|
6183
|
+
/**
|
|
6184
|
+
* Unpack a token account
|
|
6185
|
+
*
|
|
6186
|
+
* @param address Token account
|
|
6187
|
+
* @param info Token account data
|
|
6188
|
+
* @param programId SPL Token program account
|
|
6189
|
+
*
|
|
6190
|
+
* @return Unpacked token account
|
|
6191
|
+
*/
|
|
6192
|
+
function unpackAccount(address, info, programId = TOKEN_PROGRAM_ID) {
|
|
6193
|
+
if (!info)
|
|
6194
|
+
throw new TokenAccountNotFoundError();
|
|
6195
|
+
if (!info.owner.equals(programId))
|
|
6196
|
+
throw new TokenInvalidAccountOwnerError();
|
|
6197
|
+
if (info.data.length < ACCOUNT_SIZE)
|
|
6198
|
+
throw new TokenInvalidAccountSizeError();
|
|
6199
|
+
const rawAccount = AccountLayout.decode(info.data.slice(0, ACCOUNT_SIZE));
|
|
6200
|
+
let tlvData = Buffer.alloc(0);
|
|
6201
|
+
if (info.data.length > ACCOUNT_SIZE) {
|
|
6202
|
+
if (info.data.length === MULTISIG_SIZE)
|
|
6203
|
+
throw new TokenInvalidAccountSizeError();
|
|
6204
|
+
if (info.data[ACCOUNT_SIZE] != AccountType.Account)
|
|
6205
|
+
throw new TokenInvalidAccountError();
|
|
6206
|
+
tlvData = info.data.slice(ACCOUNT_SIZE + ACCOUNT_TYPE_SIZE);
|
|
6207
|
+
}
|
|
6208
|
+
return {
|
|
6209
|
+
address,
|
|
6210
|
+
mint: rawAccount.mint,
|
|
6211
|
+
owner: rawAccount.owner,
|
|
6212
|
+
amount: rawAccount.amount,
|
|
6213
|
+
delegate: rawAccount.delegateOption ? rawAccount.delegate : null,
|
|
6214
|
+
delegatedAmount: rawAccount.delegatedAmount,
|
|
6215
|
+
isInitialized: rawAccount.state !== AccountState.Uninitialized,
|
|
6216
|
+
isFrozen: rawAccount.state === AccountState.Frozen,
|
|
6217
|
+
isNative: !!rawAccount.isNativeOption,
|
|
6218
|
+
rentExemptReserve: rawAccount.isNativeOption ? rawAccount.isNative : null,
|
|
6219
|
+
closeAuthority: rawAccount.closeAuthorityOption ? rawAccount.closeAuthority : null,
|
|
6220
|
+
tlvData,
|
|
6221
|
+
};
|
|
6222
|
+
}
|
|
6223
|
+
|
|
5515
6224
|
/** Buffer layout for de/serializing a mint */
|
|
5516
6225
|
const MintLayout = struct([
|
|
5517
6226
|
u32('mintAuthorityOption'),
|
|
@@ -5524,6 +6233,54 @@ const MintLayout = struct([
|
|
|
5524
6233
|
]);
|
|
5525
6234
|
/** Byte length of a mint */
|
|
5526
6235
|
const MINT_SIZE = MintLayout.span;
|
|
6236
|
+
/**
|
|
6237
|
+
* Get the address of the associated token account for a given mint and owner
|
|
6238
|
+
*
|
|
6239
|
+
* @param mint Token mint account
|
|
6240
|
+
* @param owner Owner of the new account
|
|
6241
|
+
* @param allowOwnerOffCurve Allow the owner account to be a PDA (Program Derived Address)
|
|
6242
|
+
* @param programId SPL Token program account
|
|
6243
|
+
* @param associatedTokenProgramId SPL Associated Token program account
|
|
6244
|
+
*
|
|
6245
|
+
* @return Address of the associated token account
|
|
6246
|
+
*/
|
|
6247
|
+
function getAssociatedTokenAddressSync(mint, owner, allowOwnerOffCurve = false, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
6248
|
+
if (!allowOwnerOffCurve && !web3_js.PublicKey.isOnCurve(owner.toBuffer()))
|
|
6249
|
+
throw new TokenOwnerOffCurveError();
|
|
6250
|
+
const [address] = web3_js.PublicKey.findProgramAddressSync([owner.toBuffer(), programId.toBuffer(), mint.toBuffer()], associatedTokenProgramId);
|
|
6251
|
+
return address;
|
|
6252
|
+
}
|
|
6253
|
+
|
|
6254
|
+
/**
|
|
6255
|
+
* Construct a CreateAssociatedTokenAccount instruction
|
|
6256
|
+
*
|
|
6257
|
+
* @param payer Payer of the initialization fees
|
|
6258
|
+
* @param associatedToken New associated token account
|
|
6259
|
+
* @param owner Owner of the new account
|
|
6260
|
+
* @param mint Token mint account
|
|
6261
|
+
* @param programId SPL Token program account
|
|
6262
|
+
* @param associatedTokenProgramId SPL Associated Token program account
|
|
6263
|
+
*
|
|
6264
|
+
* @return Instruction to add to a transaction
|
|
6265
|
+
*/
|
|
6266
|
+
function createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
6267
|
+
return buildAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, Buffer.alloc(0), programId, associatedTokenProgramId);
|
|
6268
|
+
}
|
|
6269
|
+
function buildAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, instructionData, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
6270
|
+
const keys = [
|
|
6271
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
6272
|
+
{ pubkey: associatedToken, isSigner: false, isWritable: true },
|
|
6273
|
+
{ pubkey: owner, isSigner: false, isWritable: false },
|
|
6274
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
6275
|
+
{ pubkey: web3_js.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
6276
|
+
{ pubkey: programId, isSigner: false, isWritable: false },
|
|
6277
|
+
];
|
|
6278
|
+
return new web3_js.TransactionInstruction({
|
|
6279
|
+
keys,
|
|
6280
|
+
programId: associatedTokenProgramId,
|
|
6281
|
+
data: instructionData,
|
|
6282
|
+
});
|
|
6283
|
+
}
|
|
5527
6284
|
|
|
5528
6285
|
/** TODO: docs */
|
|
5529
6286
|
const initializeMint2InstructionData = struct([
|
|
@@ -5557,10 +6314,93 @@ function createInitializeMint2Instruction(mint, decimals, mintAuthority, freezeA
|
|
|
5557
6314
|
return new web3_js.TransactionInstruction({ keys, programId, data });
|
|
5558
6315
|
}
|
|
5559
6316
|
|
|
5560
|
-
|
|
6317
|
+
/**
|
|
6318
|
+
* Retrieve the associated token account, or create it if it doesn't exist
|
|
6319
|
+
*
|
|
6320
|
+
* @param connection Connection to use
|
|
6321
|
+
* @param payer Payer of the transaction and initialization fees
|
|
6322
|
+
* @param mint Mint associated with the account to set or verify
|
|
6323
|
+
* @param owner Owner of the account to set or verify
|
|
6324
|
+
* @param allowOwnerOffCurve Allow the owner account to be a PDA (Program Derived Address)
|
|
6325
|
+
* @param commitment Desired level of commitment for querying the state
|
|
6326
|
+
* @param confirmOptions Options for confirming the transaction
|
|
6327
|
+
* @param programId SPL Token program account
|
|
6328
|
+
* @param associatedTokenProgramId SPL Associated Token program account
|
|
6329
|
+
*
|
|
6330
|
+
* @return Address of the new associated token account
|
|
6331
|
+
*/
|
|
6332
|
+
async function getOrCreateAssociatedTokenAccount(connection, payer, mint, owner, allowOwnerOffCurve = false, commitment, confirmOptions, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
6333
|
+
const associatedToken = getAssociatedTokenAddressSync(mint, owner, allowOwnerOffCurve, programId, associatedTokenProgramId);
|
|
6334
|
+
// This is the optimal logic, considering TX fee, client-side computation, RPC roundtrips and guaranteed idempotent.
|
|
6335
|
+
// Sadly we can't do this atomically.
|
|
6336
|
+
let account;
|
|
6337
|
+
try {
|
|
6338
|
+
account = await getAccount(connection, associatedToken, commitment, programId);
|
|
6339
|
+
}
|
|
6340
|
+
catch (error) {
|
|
6341
|
+
// TokenAccountNotFoundError can be possible if the associated address has already received some lamports,
|
|
6342
|
+
// becoming a system account. Assuming program derived addressing is safe, this is the only case for the
|
|
6343
|
+
// TokenInvalidAccountOwnerError in this code path.
|
|
6344
|
+
if (error instanceof TokenAccountNotFoundError || error instanceof TokenInvalidAccountOwnerError) {
|
|
6345
|
+
// As this isn't atomic, it's possible others can create associated accounts meanwhile.
|
|
6346
|
+
try {
|
|
6347
|
+
const transaction = new web3_js.Transaction().add(createAssociatedTokenAccountInstruction(payer.publicKey, associatedToken, owner, mint, programId, associatedTokenProgramId));
|
|
6348
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer], confirmOptions);
|
|
6349
|
+
}
|
|
6350
|
+
catch (error) {
|
|
6351
|
+
// Ignore all errors; for now there is no API-compatible way to selectively ignore the expected
|
|
6352
|
+
// instruction error if the associated account exists already.
|
|
6353
|
+
}
|
|
6354
|
+
// Now this should always succeed
|
|
6355
|
+
account = await getAccount(connection, associatedToken, commitment, programId);
|
|
6356
|
+
}
|
|
6357
|
+
else {
|
|
6358
|
+
throw error;
|
|
6359
|
+
}
|
|
6360
|
+
}
|
|
6361
|
+
if (!account.mint.equals(mint))
|
|
6362
|
+
throw new TokenInvalidMintError();
|
|
6363
|
+
if (!account.owner.equals(owner))
|
|
6364
|
+
throw new TokenInvalidOwnerError();
|
|
6365
|
+
return account;
|
|
6366
|
+
}
|
|
6367
|
+
|
|
6368
|
+
/** TODO: docs */
|
|
6369
|
+
const mintToInstructionData = struct([u8('instruction'), u64('amount')]);
|
|
6370
|
+
/**
|
|
6371
|
+
* Construct a MintTo instruction
|
|
6372
|
+
*
|
|
6373
|
+
* @param mint Public key of the mint
|
|
6374
|
+
* @param destination Address of the token account to mint to
|
|
6375
|
+
* @param authority The mint authority
|
|
6376
|
+
* @param amount Amount to mint
|
|
6377
|
+
* @param multiSigners Signing accounts if `authority` is a multisig
|
|
6378
|
+
* @param programId SPL Token program account
|
|
6379
|
+
*
|
|
6380
|
+
* @return Instruction to add to a transaction
|
|
6381
|
+
*/
|
|
6382
|
+
function createMintToInstruction(mint, destination, authority, amount, multiSigners = [], programId = TOKEN_PROGRAM_ID) {
|
|
6383
|
+
const keys = addSigners([
|
|
6384
|
+
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
6385
|
+
{ pubkey: destination, isSigner: false, isWritable: true },
|
|
6386
|
+
], authority, multiSigners);
|
|
6387
|
+
const data = Buffer.alloc(mintToInstructionData.span);
|
|
6388
|
+
mintToInstructionData.encode({
|
|
6389
|
+
instruction: TokenInstruction.MintTo,
|
|
6390
|
+
amount: BigInt(amount),
|
|
6391
|
+
}, data);
|
|
6392
|
+
return new web3_js.TransactionInstruction({ keys, programId, data });
|
|
6393
|
+
}
|
|
6394
|
+
|
|
6395
|
+
/**
|
|
6396
|
+
* Sum up the token amounts of the compressed token accounts
|
|
6397
|
+
*/
|
|
5561
6398
|
const sumUpTokenAmount = (accounts) => {
|
|
5562
6399
|
return accounts.reduce((acc, account) => acc.add(account.parsed.amount), stateless_js.bn(0));
|
|
5563
6400
|
};
|
|
6401
|
+
/**
|
|
6402
|
+
* Validate that all the compressed token accounts are owned by the same owner.
|
|
6403
|
+
*/
|
|
5564
6404
|
const validateSameTokenOwner = (accounts) => {
|
|
5565
6405
|
const owner = accounts[0].parsed.owner;
|
|
5566
6406
|
accounts.forEach(acc => {
|
|
@@ -5569,12 +6409,23 @@ const validateSameTokenOwner = (accounts) => {
|
|
|
5569
6409
|
}
|
|
5570
6410
|
});
|
|
5571
6411
|
};
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
6412
|
+
/**
|
|
6413
|
+
* Parse compressed token accounts to get the mint, current owner and delegate.
|
|
6414
|
+
*/
|
|
6415
|
+
const parseTokenData = (compressedTokenAccounts) => {
|
|
6416
|
+
const mint = compressedTokenAccounts[0].parsed.mint;
|
|
6417
|
+
const currentOwner = compressedTokenAccounts[0].parsed.owner;
|
|
6418
|
+
const delegate = compressedTokenAccounts[0].parsed.delegate;
|
|
5576
6419
|
return { mint, currentOwner, delegate };
|
|
5577
6420
|
};
|
|
6421
|
+
/**
|
|
6422
|
+
* Create the output state for a transfer transaction.
|
|
6423
|
+
* @param inputCompressedTokenAccounts Input state
|
|
6424
|
+
* @param toAddress Recipient address
|
|
6425
|
+
* @param amount Amount of tokens to transfer
|
|
6426
|
+
* @returns Output token data for the transfer
|
|
6427
|
+
* instruction
|
|
6428
|
+
*/
|
|
5578
6429
|
function createTransferOutputState(inputCompressedTokenAccounts, toAddress, amount) {
|
|
5579
6430
|
amount = stateless_js.bn(amount);
|
|
5580
6431
|
const inputAmount = sumUpTokenAmount(inputCompressedTokenAccounts);
|
|
@@ -5607,6 +6458,13 @@ function createTransferOutputState(inputCompressedTokenAccounts, toAddress, amou
|
|
|
5607
6458
|
];
|
|
5608
6459
|
return outputCompressedAccounts;
|
|
5609
6460
|
}
|
|
6461
|
+
/**
|
|
6462
|
+
* Create the output state for a compress transaction.
|
|
6463
|
+
* @param inputCompressedTokenAccounts Input state
|
|
6464
|
+
* @param amount Amount of tokens to compress
|
|
6465
|
+
* @returns Output token data for the compress
|
|
6466
|
+
* instruction
|
|
6467
|
+
*/
|
|
5610
6468
|
function createDecompressOutputState(inputCompressedTokenAccounts, amount) {
|
|
5611
6469
|
amount = stateless_js.bn(amount);
|
|
5612
6470
|
const inputLamports = stateless_js.sumUpLamports(inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
@@ -5633,6 +6491,7 @@ class CompressedTokenProgram {
|
|
|
5633
6491
|
* @internal
|
|
5634
6492
|
*/
|
|
5635
6493
|
constructor() { }
|
|
6494
|
+
/** @internal */
|
|
5636
6495
|
static get program() {
|
|
5637
6496
|
if (!this._program) {
|
|
5638
6497
|
this.initializeProgram();
|
|
@@ -5640,12 +6499,14 @@ class CompressedTokenProgram {
|
|
|
5640
6499
|
return this._program;
|
|
5641
6500
|
}
|
|
5642
6501
|
/**
|
|
6502
|
+
* @internal
|
|
5643
6503
|
* Initializes the program statically if not already initialized.
|
|
5644
6504
|
*/
|
|
5645
6505
|
static initializeProgram() {
|
|
5646
6506
|
if (!this._program) {
|
|
5647
|
-
/// We can use a mock connection because we're using the
|
|
5648
|
-
/// serde and building instructions, not for
|
|
6507
|
+
/// Note: We can use a mock connection because we're using the
|
|
6508
|
+
/// program only for serde and building instructions, not for
|
|
6509
|
+
/// interacting with the network.
|
|
5649
6510
|
const mockKeypair = web3_js.Keypair.generate();
|
|
5650
6511
|
const mockConnection = new web3_js.Connection('http://127.0.0.1:8899', 'confirmed');
|
|
5651
6512
|
const mockProvider = new anchor.AnchorProvider(mockConnection, stateless_js.useWallet(mockKeypair), stateless_js.confirmConfig);
|
|
@@ -5664,8 +6525,12 @@ class CompressedTokenProgram {
|
|
|
5664
6525
|
const [address, _] = web3_js.PublicKey.findProgramAddressSync([CPI_AUTHORITY_SEED], this.programId);
|
|
5665
6526
|
return address;
|
|
5666
6527
|
}
|
|
6528
|
+
/**
|
|
6529
|
+
* Construct createMint instruction for compressed tokens
|
|
6530
|
+
*/
|
|
5667
6531
|
static async createMint(params) {
|
|
5668
6532
|
const { mint, authority, feePayer, rentExemptBalance } = params;
|
|
6533
|
+
/// Create and initialize SPL Mint account
|
|
5669
6534
|
const createMintAccountInstruction = web3_js.SystemProgram.createAccount({
|
|
5670
6535
|
fromPubkey: feePayer,
|
|
5671
6536
|
lamports: rentExemptBalance,
|
|
@@ -5673,224 +6538,270 @@ class CompressedTokenProgram {
|
|
|
5673
6538
|
programId: TOKEN_PROGRAM_ID,
|
|
5674
6539
|
space: MINT_SIZE,
|
|
5675
6540
|
});
|
|
5676
|
-
const
|
|
5677
|
-
const
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
toPubkey: mintAuthorityPda,
|
|
5681
|
-
lamports: rentExemptBalance, // TODO: check that this is the right PDA size
|
|
6541
|
+
const initializeMintInstruction = createInitializeMint2Instruction(mint, params.decimals, authority, params.freezeAuthority, TOKEN_PROGRAM_ID);
|
|
6542
|
+
const ix = await this.registerMint({
|
|
6543
|
+
feePayer,
|
|
6544
|
+
mint,
|
|
5682
6545
|
});
|
|
6546
|
+
return [createMintAccountInstruction, initializeMintInstruction, ix];
|
|
6547
|
+
}
|
|
6548
|
+
/**
|
|
6549
|
+
* Enable compression for an existing SPL mint, creating an omnibus account.
|
|
6550
|
+
* For new mints, use `CompressedTokenProgram.createMint`.
|
|
6551
|
+
*/
|
|
6552
|
+
static async registerMint(params) {
|
|
6553
|
+
const { mint, feePayer } = params;
|
|
5683
6554
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
5684
6555
|
const ix = await this.program.methods
|
|
5685
6556
|
.createMint()
|
|
5686
6557
|
.accounts({
|
|
5687
6558
|
mint,
|
|
5688
6559
|
feePayer,
|
|
5689
|
-
authority,
|
|
5690
6560
|
tokenPoolPda,
|
|
5691
6561
|
systemProgram: web3_js.SystemProgram.programId,
|
|
5692
|
-
mintAuthorityPda,
|
|
5693
6562
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
5694
6563
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
5695
6564
|
})
|
|
5696
6565
|
.instruction();
|
|
5697
|
-
return
|
|
5698
|
-
createMintAccountInstruction,
|
|
5699
|
-
initializeMintInstruction,
|
|
5700
|
-
fundAuthorityPdaInstruction,
|
|
5701
|
-
ix,
|
|
5702
|
-
];
|
|
6566
|
+
return ix;
|
|
5703
6567
|
}
|
|
6568
|
+
/**
|
|
6569
|
+
* Construct mintTo instruction for compressed tokens
|
|
6570
|
+
*/
|
|
5704
6571
|
static async mintTo(params) {
|
|
5705
6572
|
const systemKeys = stateless_js.defaultStaticAccountsStruct();
|
|
5706
6573
|
const { mint, feePayer, authority, merkleTree, toPubkey, amount } = params;
|
|
5707
6574
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
5708
|
-
const mintAuthorityPda = this.deriveMintAuthorityPda(authority, mint);
|
|
5709
6575
|
const amounts = stateless_js.toArray(amount).map(amount => stateless_js.bn(amount));
|
|
5710
6576
|
const toPubkeys = stateless_js.toArray(toPubkey);
|
|
5711
|
-
const
|
|
6577
|
+
const instruction = await this.program.methods
|
|
5712
6578
|
.mintTo(toPubkeys, amounts)
|
|
5713
6579
|
.accounts({
|
|
5714
6580
|
feePayer,
|
|
5715
6581
|
authority,
|
|
5716
|
-
|
|
6582
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
5717
6583
|
mint,
|
|
5718
6584
|
tokenPoolPda,
|
|
5719
6585
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
5720
|
-
|
|
6586
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
5721
6587
|
registeredProgramPda: systemKeys.registeredProgramPda,
|
|
5722
6588
|
noopProgram: systemKeys.noopProgram,
|
|
5723
6589
|
accountCompressionAuthority: systemKeys.accountCompressionAuthority,
|
|
5724
6590
|
accountCompressionProgram: systemKeys.accountCompressionProgram,
|
|
5725
|
-
merkleTree,
|
|
6591
|
+
merkleTree: merkleTree !== null && merkleTree !== void 0 ? merkleTree : stateless_js.defaultTestStateTreeAccounts().merkleTree,
|
|
5726
6592
|
selfProgram: this.programId,
|
|
5727
6593
|
})
|
|
5728
6594
|
.instruction();
|
|
5729
|
-
return
|
|
6595
|
+
return instruction;
|
|
6596
|
+
}
|
|
6597
|
+
/// TODO: add compressBatch functionality for batch minting
|
|
6598
|
+
/**
|
|
6599
|
+
* Mint tokens from registed SPL mint account to a compressed account
|
|
6600
|
+
*/
|
|
6601
|
+
static async approveAndMintTo(params) {
|
|
6602
|
+
const { mint, feePayer, authorityTokenAccount, authority, merkleTree, toPubkey, } = params;
|
|
6603
|
+
const amount = BigInt(params.amount.toString());
|
|
6604
|
+
/// 1. Mint to existing ATA of mintAuthority.
|
|
6605
|
+
const splMintToInstruction = createMintToInstruction(mint, authorityTokenAccount, authority, amount);
|
|
6606
|
+
/// 2. Compress from mint authority ATA to recipient compressed account
|
|
6607
|
+
const [approveInstruction, compressInstruction] = await this.compress({
|
|
6608
|
+
payer: feePayer,
|
|
6609
|
+
owner: authority,
|
|
6610
|
+
source: authorityTokenAccount,
|
|
6611
|
+
toAddress: toPubkey,
|
|
6612
|
+
mint,
|
|
6613
|
+
amount: params.amount,
|
|
6614
|
+
outputStateTree: merkleTree,
|
|
6615
|
+
});
|
|
6616
|
+
return [splMintToInstruction, approveInstruction, compressInstruction];
|
|
5730
6617
|
}
|
|
6618
|
+
/**
|
|
6619
|
+
* Construct transfer instruction for compressed tokens
|
|
6620
|
+
*/
|
|
5731
6621
|
static async transfer(params) {
|
|
5732
6622
|
const { payer, inputCompressedTokenAccounts, recentInputStateRootIndices, recentValidityProof, amount, outputStateTrees, toAddress, } = params;
|
|
5733
|
-
const
|
|
5734
|
-
|
|
5735
|
-
const { inputTokenDataWithContext, outputStateMerkleTreeIndices, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
6623
|
+
const tokenTransferOutputs = createTransferOutputState(inputCompressedTokenAccounts, toAddress, amount);
|
|
6624
|
+
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
5736
6625
|
inputCompressedTokenAccounts,
|
|
5737
|
-
outputCompressedAccountsLength: outputCompressedAccounts.length,
|
|
5738
6626
|
outputStateTrees,
|
|
6627
|
+
rootIndices: recentInputStateRootIndices,
|
|
6628
|
+
tokenTransferOutputs,
|
|
5739
6629
|
});
|
|
5740
|
-
const { mint, currentOwner } =
|
|
6630
|
+
const { mint, currentOwner } = parseTokenData(inputCompressedTokenAccounts);
|
|
5741
6631
|
const data = {
|
|
5742
6632
|
proof: recentValidityProof,
|
|
5743
|
-
rootIndices: recentInputStateRootIndices,
|
|
5744
6633
|
mint,
|
|
5745
|
-
|
|
6634
|
+
delegatedTransfer: null, // TODO: implement
|
|
5746
6635
|
inputTokenDataWithContext,
|
|
5747
|
-
outputCompressedAccounts,
|
|
5748
|
-
|
|
5749
|
-
compressionAmount: null,
|
|
6636
|
+
outputCompressedAccounts: packedOutputTokenData,
|
|
6637
|
+
compressOrDecompressAmount: null,
|
|
5750
6638
|
isCompress: false,
|
|
6639
|
+
cpiContext: null,
|
|
5751
6640
|
};
|
|
5752
6641
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
5753
6642
|
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
5754
6643
|
const instruction = await this.program.methods
|
|
5755
|
-
.transfer(encodedData
|
|
6644
|
+
.transfer(encodedData)
|
|
5756
6645
|
.accounts({
|
|
5757
6646
|
feePayer: payer,
|
|
5758
6647
|
authority: currentOwner,
|
|
5759
6648
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
5760
|
-
|
|
6649
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
5761
6650
|
registeredProgramPda: registeredProgramPda,
|
|
5762
6651
|
noopProgram: noopProgram,
|
|
5763
6652
|
accountCompressionAuthority: accountCompressionAuthority,
|
|
5764
6653
|
accountCompressionProgram: accountCompressionProgram,
|
|
5765
6654
|
selfProgram: this.programId,
|
|
5766
6655
|
tokenPoolPda: null,
|
|
5767
|
-
|
|
6656
|
+
compressOrDecompressTokenAccount: null,
|
|
5768
6657
|
tokenProgram: null,
|
|
5769
6658
|
})
|
|
5770
6659
|
.remainingAccounts(remainingAccountMetas)
|
|
5771
6660
|
.instruction();
|
|
5772
|
-
return
|
|
5773
|
-
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
5774
|
-
instruction,
|
|
5775
|
-
];
|
|
6661
|
+
return instruction;
|
|
5776
6662
|
}
|
|
6663
|
+
/**
|
|
6664
|
+
* Construct approve and compress instructions
|
|
6665
|
+
* @returns [approveInstruction, compressInstruction]
|
|
6666
|
+
*/
|
|
5777
6667
|
static async compress(params) {
|
|
5778
6668
|
const { payer, owner, source, toAddress, mint, outputStateTree } = params;
|
|
5779
6669
|
const amount = stateless_js.bn(params.amount);
|
|
5780
|
-
const
|
|
6670
|
+
const tokenTransferOutputs = [
|
|
5781
6671
|
{
|
|
5782
6672
|
owner: toAddress,
|
|
5783
6673
|
amount,
|
|
5784
6674
|
lamports: stateless_js.bn(0),
|
|
5785
6675
|
},
|
|
5786
6676
|
];
|
|
5787
|
-
|
|
5788
|
-
const { inputTokenDataWithContext, outputStateMerkleTreeIndices, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
6677
|
+
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
5789
6678
|
inputCompressedTokenAccounts: [],
|
|
5790
|
-
|
|
5791
|
-
|
|
6679
|
+
outputStateTrees: outputStateTree,
|
|
6680
|
+
rootIndices: [],
|
|
6681
|
+
tokenTransferOutputs,
|
|
5792
6682
|
});
|
|
5793
6683
|
const data = {
|
|
5794
6684
|
proof: null,
|
|
5795
|
-
rootIndices: [],
|
|
5796
6685
|
mint,
|
|
5797
|
-
|
|
6686
|
+
delegatedTransfer: null, // TODO: implement
|
|
5798
6687
|
inputTokenDataWithContext,
|
|
5799
|
-
outputCompressedAccounts,
|
|
5800
|
-
|
|
5801
|
-
compressionAmount: amount,
|
|
6688
|
+
outputCompressedAccounts: packedOutputTokenData,
|
|
6689
|
+
compressOrDecompressAmount: amount,
|
|
5802
6690
|
isCompress: true,
|
|
6691
|
+
cpiContext: null,
|
|
5803
6692
|
};
|
|
5804
6693
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
5805
6694
|
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
5806
|
-
/// TODO: add support for multiSigners
|
|
5807
|
-
/// TODO: validate that we don't need approveChecked
|
|
5808
6695
|
const approveInstruction = createApproveInstruction(source, this.deriveCpiAuthorityPda, owner, BigInt(amount.toString()));
|
|
5809
6696
|
const instruction = await this.program.methods
|
|
5810
|
-
.transfer(encodedData
|
|
6697
|
+
.transfer(encodedData)
|
|
5811
6698
|
.accounts({
|
|
5812
6699
|
feePayer: payer,
|
|
5813
6700
|
authority: owner,
|
|
5814
6701
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
5815
|
-
|
|
6702
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
5816
6703
|
registeredProgramPda: registeredProgramPda,
|
|
5817
6704
|
noopProgram: noopProgram,
|
|
5818
6705
|
accountCompressionAuthority: accountCompressionAuthority,
|
|
5819
6706
|
accountCompressionProgram: accountCompressionProgram,
|
|
5820
6707
|
selfProgram: this.programId,
|
|
5821
6708
|
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
5822
|
-
|
|
6709
|
+
compressOrDecompressTokenAccount: source, // token
|
|
5823
6710
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
5824
6711
|
})
|
|
5825
6712
|
.remainingAccounts(remainingAccountMetas)
|
|
5826
6713
|
.instruction();
|
|
5827
|
-
return [
|
|
5828
|
-
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
5829
|
-
approveInstruction,
|
|
5830
|
-
instruction,
|
|
5831
|
-
];
|
|
6714
|
+
return [approveInstruction, instruction];
|
|
5832
6715
|
}
|
|
6716
|
+
/**
|
|
6717
|
+
* Construct decompress instruction
|
|
6718
|
+
*/
|
|
5833
6719
|
static async decompress(params) {
|
|
5834
6720
|
const { payer, inputCompressedTokenAccounts, toAddress, outputStateTree, recentValidityProof, recentInputStateRootIndices, } = params;
|
|
5835
6721
|
const amount = stateless_js.bn(params.amount);
|
|
5836
6722
|
const tokenTransferOutputs = createDecompressOutputState(inputCompressedTokenAccounts, amount);
|
|
5837
6723
|
/// Pack
|
|
5838
|
-
const { inputTokenDataWithContext,
|
|
6724
|
+
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
5839
6725
|
inputCompressedTokenAccounts,
|
|
5840
|
-
|
|
5841
|
-
|
|
6726
|
+
outputStateTrees: outputStateTree,
|
|
6727
|
+
rootIndices: recentInputStateRootIndices,
|
|
6728
|
+
tokenTransferOutputs: tokenTransferOutputs,
|
|
5842
6729
|
});
|
|
5843
|
-
const { mint, currentOwner } =
|
|
6730
|
+
const { mint, currentOwner } = parseTokenData(inputCompressedTokenAccounts);
|
|
5844
6731
|
const data = {
|
|
5845
6732
|
proof: recentValidityProof,
|
|
5846
|
-
rootIndices: recentInputStateRootIndices,
|
|
5847
6733
|
mint,
|
|
5848
|
-
|
|
6734
|
+
delegatedTransfer: null, // TODO: implement
|
|
5849
6735
|
inputTokenDataWithContext,
|
|
5850
|
-
outputCompressedAccounts:
|
|
5851
|
-
|
|
5852
|
-
compressionAmount: amount,
|
|
6736
|
+
outputCompressedAccounts: packedOutputTokenData,
|
|
6737
|
+
compressOrDecompressAmount: amount,
|
|
5853
6738
|
isCompress: false,
|
|
6739
|
+
cpiContext: null,
|
|
5854
6740
|
};
|
|
5855
6741
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
5856
6742
|
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
5857
6743
|
const instruction = await this.program.methods
|
|
5858
|
-
.transfer(encodedData
|
|
6744
|
+
.transfer(encodedData)
|
|
5859
6745
|
.accounts({
|
|
5860
6746
|
feePayer: payer,
|
|
5861
6747
|
authority: currentOwner,
|
|
5862
6748
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
5863
|
-
|
|
6749
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
5864
6750
|
registeredProgramPda: registeredProgramPda,
|
|
5865
6751
|
noopProgram: noopProgram,
|
|
5866
6752
|
accountCompressionAuthority: accountCompressionAuthority,
|
|
5867
6753
|
accountCompressionProgram: accountCompressionProgram,
|
|
5868
6754
|
selfProgram: this.programId,
|
|
5869
6755
|
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
5870
|
-
|
|
6756
|
+
compressOrDecompressTokenAccount: toAddress,
|
|
5871
6757
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
5872
6758
|
})
|
|
5873
6759
|
.remainingAccounts(remainingAccountMetas)
|
|
5874
6760
|
.instruction();
|
|
5875
|
-
return
|
|
5876
|
-
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
5877
|
-
instruction,
|
|
5878
|
-
];
|
|
6761
|
+
return instruction;
|
|
5879
6762
|
}
|
|
5880
6763
|
}
|
|
5881
|
-
_a = CompressedTokenProgram;
|
|
5882
6764
|
/**
|
|
5883
6765
|
* Public key that identifies the CompressedPda program
|
|
5884
6766
|
*/
|
|
5885
|
-
CompressedTokenProgram.programId = new web3_js.PublicKey(
|
|
5886
|
-
// TODO: can add check to ensure its consistent with the idl
|
|
5887
|
-
'9sixVEthz2kMSKfeApZXHwuboT6DZuT6crAYJTciUCqE');
|
|
6767
|
+
CompressedTokenProgram.programId = new web3_js.PublicKey('HXVfQ44ATEi9WBKLSCCwM54KokdkzqXci9xCQ7ST9SYN');
|
|
5888
6768
|
CompressedTokenProgram._program = null;
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
6769
|
+
|
|
6770
|
+
/**
|
|
6771
|
+
* Mint compressed tokens to a solana address from an external mint authority
|
|
6772
|
+
*
|
|
6773
|
+
* @param rpc Rpc to use
|
|
6774
|
+
* @param payer Payer of the transaction fees
|
|
6775
|
+
* @param mint Mint for the account
|
|
6776
|
+
* @param destination Address of the account to mint to
|
|
6777
|
+
* @param authority Minting authority
|
|
6778
|
+
* @param amount Amount to mint
|
|
6779
|
+
* @param merkleTree State tree account that the compressed tokens should be
|
|
6780
|
+
* part of. Defaults to the default state tree account.
|
|
6781
|
+
* @param confirmOptions Options for confirming the transaction
|
|
6782
|
+
*
|
|
6783
|
+
* @return Signature of the confirmed transaction
|
|
6784
|
+
*/
|
|
6785
|
+
async function approveAndMintTo(rpc, payer, mint, destination, authority, amount, merkleTree, confirmOptions) {
|
|
6786
|
+
const authorityTokenAccount = await getOrCreateAssociatedTokenAccount(rpc, payer, mint, authority.publicKey);
|
|
6787
|
+
const ixs = await CompressedTokenProgram.approveAndMintTo({
|
|
6788
|
+
feePayer: payer.publicKey,
|
|
6789
|
+
mint,
|
|
6790
|
+
authority: authority.publicKey,
|
|
6791
|
+
authorityTokenAccount: authorityTokenAccount.address,
|
|
6792
|
+
amount,
|
|
6793
|
+
toPubkey: destination,
|
|
6794
|
+
merkleTree,
|
|
6795
|
+
});
|
|
6796
|
+
const { blockhash } = await rpc.getLatestBlockhash();
|
|
6797
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
6798
|
+
const tx = stateless_js.buildAndSignTx([
|
|
6799
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
6800
|
+
...ixs,
|
|
6801
|
+
], payer, blockhash, additionalSigners);
|
|
6802
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
6803
|
+
return txId;
|
|
6804
|
+
}
|
|
5894
6805
|
|
|
5895
6806
|
/**
|
|
5896
6807
|
* Compress SPL tokens
|
|
@@ -5910,9 +6821,9 @@ CompressedTokenProgram.deriveMintAuthorityPda = (authority, mint) => {
|
|
|
5910
6821
|
*
|
|
5911
6822
|
* @return Signature of the confirmed transaction
|
|
5912
6823
|
*/
|
|
5913
|
-
async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toAddress, merkleTree
|
|
6824
|
+
async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toAddress, merkleTree, confirmOptions) {
|
|
5914
6825
|
amount = stateless_js.bn(amount);
|
|
5915
|
-
const
|
|
6826
|
+
const [approveIx, compressIx] = await CompressedTokenProgram.compress({
|
|
5916
6827
|
payer: payer.publicKey,
|
|
5917
6828
|
owner: owner.publicKey,
|
|
5918
6829
|
source: sourceTokenAccount,
|
|
@@ -5923,7 +6834,13 @@ async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toA
|
|
|
5923
6834
|
});
|
|
5924
6835
|
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
5925
6836
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
5926
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
6837
|
+
const signedTx = stateless_js.buildAndSignTx([
|
|
6838
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
6839
|
+
units: 1000000,
|
|
6840
|
+
}),
|
|
6841
|
+
approveIx,
|
|
6842
|
+
compressIx,
|
|
6843
|
+
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
5927
6844
|
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
5928
6845
|
return txId;
|
|
5929
6846
|
}
|
|
@@ -5938,7 +6855,8 @@ async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toA
|
|
|
5938
6855
|
* @param owner Owner of the compressed tokens
|
|
5939
6856
|
* @param toAddress Destination address of the recipient
|
|
5940
6857
|
* @param merkleTree State tree account that the compressed tokens should be
|
|
5941
|
-
* inserted into. Defaults to the default state tree
|
|
6858
|
+
* inserted into. Defaults to the default state tree
|
|
6859
|
+
* account.
|
|
5942
6860
|
* @param confirmOptions Options for confirming the transaction
|
|
5943
6861
|
*
|
|
5944
6862
|
*
|
|
@@ -5946,14 +6864,14 @@ async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toA
|
|
|
5946
6864
|
*/
|
|
5947
6865
|
async function transfer(rpc, payer, mint, amount, owner, toAddress,
|
|
5948
6866
|
/// TODO: allow multiple
|
|
5949
|
-
merkleTree
|
|
6867
|
+
merkleTree, confirmOptions) {
|
|
5950
6868
|
amount = stateless_js.bn(amount);
|
|
5951
6869
|
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, {
|
|
5952
6870
|
mint,
|
|
5953
6871
|
});
|
|
5954
6872
|
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(compressedTokenAccounts, amount);
|
|
5955
6873
|
const proof = await rpc.getValidityProof(inputAccounts.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
5956
|
-
const
|
|
6874
|
+
const ix = await CompressedTokenProgram.transfer({
|
|
5957
6875
|
payer: payer.publicKey,
|
|
5958
6876
|
inputCompressedTokenAccounts: inputAccounts,
|
|
5959
6877
|
toAddress,
|
|
@@ -5964,7 +6882,7 @@ merkleTree = stateless_js.defaultTestStateTreeAccounts().merkleTree, confirmOpti
|
|
|
5964
6882
|
});
|
|
5965
6883
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
5966
6884
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
5967
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
6885
|
+
const signedTx = stateless_js.buildAndSignTx([web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }), ix], payer, blockhash, additionalSigners);
|
|
5968
6886
|
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
5969
6887
|
return txId;
|
|
5970
6888
|
}
|
|
@@ -6017,7 +6935,7 @@ function selectMinCompressedTokenAccountsForTransfer(accounts, transferAmount) {
|
|
|
6017
6935
|
*/
|
|
6018
6936
|
async function decompress(rpc, payer, mint, amount, owner, toAddress,
|
|
6019
6937
|
/// TODO: allow multiple
|
|
6020
|
-
merkleTree
|
|
6938
|
+
merkleTree, confirmOptions) {
|
|
6021
6939
|
amount = stateless_js.bn(amount);
|
|
6022
6940
|
const compressedTokenAccounts = await rpc.getCompressedTokenAccountsByOwner(owner.publicKey, {
|
|
6023
6941
|
mint,
|
|
@@ -6025,7 +6943,7 @@ merkleTree = stateless_js.defaultTestStateTreeAccounts().merkleTree, confirmOpti
|
|
|
6025
6943
|
/// TODO: consider using a different selection algorithm
|
|
6026
6944
|
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(compressedTokenAccounts, amount);
|
|
6027
6945
|
const proof = await rpc.getValidityProof(inputAccounts.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
6028
|
-
const
|
|
6946
|
+
const ix = await CompressedTokenProgram.decompress({
|
|
6029
6947
|
payer: payer.publicKey,
|
|
6030
6948
|
inputCompressedTokenAccounts: inputAccounts,
|
|
6031
6949
|
toAddress, // TODO: add explicit check that it is a token account
|
|
@@ -6036,7 +6954,7 @@ merkleTree = stateless_js.defaultTestStateTreeAccounts().merkleTree, confirmOpti
|
|
|
6036
6954
|
});
|
|
6037
6955
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
6038
6956
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
6039
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
6957
|
+
const signedTx = stateless_js.buildAndSignTx([web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }), ix], payer, blockhash, additionalSigners);
|
|
6040
6958
|
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
6041
6959
|
return txId;
|
|
6042
6960
|
}
|
|
@@ -6046,7 +6964,7 @@ merkleTree = stateless_js.defaultTestStateTreeAccounts().merkleTree, confirmOpti
|
|
|
6046
6964
|
*
|
|
6047
6965
|
* @param rpc RPC to use
|
|
6048
6966
|
* @param payer Payer of the transaction and initialization fees
|
|
6049
|
-
* @param mintAuthority Account or multisig that will control minting
|
|
6967
|
+
* @param mintAuthority Account or multisig that will control minting
|
|
6050
6968
|
* @param decimals Location of the decimal place
|
|
6051
6969
|
* @param keypair Optional keypair, defaulting to a new random one
|
|
6052
6970
|
* @param confirmOptions Options for confirming the transaction
|
|
@@ -6059,12 +6977,12 @@ async function createMint(rpc, payer, mintAuthority, decimals, keypair = web3_js
|
|
|
6059
6977
|
feePayer: payer.publicKey,
|
|
6060
6978
|
mint: keypair.publicKey,
|
|
6061
6979
|
decimals,
|
|
6062
|
-
authority: mintAuthority
|
|
6980
|
+
authority: mintAuthority,
|
|
6063
6981
|
freezeAuthority: null, // TODO: add feature
|
|
6064
6982
|
rentExemptBalance,
|
|
6065
6983
|
});
|
|
6066
6984
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
6067
|
-
const additionalSigners = stateless_js.dedupeSigner(payer, [
|
|
6985
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [keypair]);
|
|
6068
6986
|
const tx = stateless_js.buildAndSignTx(ixs, payer, blockhash, additionalSigners);
|
|
6069
6987
|
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
6070
6988
|
return { mint: keypair.publicKey, transactionSignature: txId };
|
|
@@ -6085,8 +7003,7 @@ async function createMint(rpc, payer, mintAuthority, decimals, keypair = web3_js
|
|
|
6085
7003
|
*
|
|
6086
7004
|
* @return Signature of the confirmed transaction
|
|
6087
7005
|
*/
|
|
6088
|
-
async function mintTo(rpc, payer, mint, destination, authority, amount, merkleTree
|
|
6089
|
-
confirmOptions) {
|
|
7006
|
+
async function mintTo(rpc, payer, mint, destination, authority, amount, merkleTree, confirmOptions) {
|
|
6090
7007
|
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
6091
7008
|
const ix = await CompressedTokenProgram.mintTo({
|
|
6092
7009
|
feePayer: payer.publicKey,
|
|
@@ -6102,12 +7019,34 @@ confirmOptions) {
|
|
|
6102
7019
|
return txId;
|
|
6103
7020
|
}
|
|
6104
7021
|
|
|
7022
|
+
/**
|
|
7023
|
+
* Register an existing mint with the CompressedToken program
|
|
7024
|
+
*
|
|
7025
|
+
* @param rpc RPC to use
|
|
7026
|
+
* @param payer Payer of the transaction and initialization fees
|
|
7027
|
+
* @param mintAuthority Account or multisig that will control minting. Is signer.
|
|
7028
|
+
* @param mintAddress Address of the existing mint
|
|
7029
|
+
* @param confirmOptions Options for confirming the transaction
|
|
7030
|
+
*
|
|
7031
|
+
* @return transaction signature
|
|
7032
|
+
*/
|
|
7033
|
+
async function registerMint(rpc, payer, mintAddress, confirmOptions) {
|
|
7034
|
+
const ix = await CompressedTokenProgram.registerMint({
|
|
7035
|
+
feePayer: payer.publicKey,
|
|
7036
|
+
mint: mintAddress,
|
|
7037
|
+
});
|
|
7038
|
+
const { blockhash } = await rpc.getLatestBlockhash();
|
|
7039
|
+
const tx = stateless_js.buildAndSignTx([ix], payer, blockhash);
|
|
7040
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
7041
|
+
return txId;
|
|
7042
|
+
}
|
|
7043
|
+
|
|
6105
7044
|
exports.CPI_AUTHORITY_SEED = CPI_AUTHORITY_SEED;
|
|
6106
7045
|
exports.CompressedTokenProgram = CompressedTokenProgram;
|
|
6107
7046
|
exports.IDL = IDL;
|
|
6108
|
-
exports.MINT_AUTHORITY_SEED = MINT_AUTHORITY_SEED;
|
|
6109
7047
|
exports.POOL_SEED = POOL_SEED;
|
|
6110
7048
|
exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE;
|
|
7049
|
+
exports.approveAndMintTo = approveAndMintTo;
|
|
6111
7050
|
exports.compress = compress;
|
|
6112
7051
|
exports.createDecompressOutputState = createDecompressOutputState;
|
|
6113
7052
|
exports.createMint = createMint;
|
|
@@ -6115,7 +7054,8 @@ exports.createTransferOutputState = createTransferOutputState;
|
|
|
6115
7054
|
exports.decompress = decompress;
|
|
6116
7055
|
exports.mintTo = mintTo;
|
|
6117
7056
|
exports.packCompressedTokenAccounts = packCompressedTokenAccounts;
|
|
6118
|
-
exports.
|
|
7057
|
+
exports.parseTokenData = parseTokenData;
|
|
7058
|
+
exports.registerMint = registerMint;
|
|
6119
7059
|
exports.selectMinCompressedTokenAccountsForTransfer = selectMinCompressedTokenAccountsForTransfer;
|
|
6120
7060
|
exports.sumUpTokenAmount = sumUpTokenAmount;
|
|
6121
7061
|
exports.transfer = transfer;
|