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