@lightprotocol/compressed-token 0.3.4 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/browser/index.cjs +322 -72
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +322 -72
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +323 -73
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +327 -40
- package/package.json +5 -5
package/dist/es/browser/index.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { getIndexOrAdd, bn, padOutputStateMerkleTrees, useWallet, confirmConfig, defaultStaticAccountsStruct, toArray, LightSystemProgram, defaultTestStateTreeAccounts, sumUpLamports, validateSufficientBalance, validateSameOwner, dedupeSigner, buildAndSignTx, sendAndConfirmTx } from '@lightprotocol/stateless.js';
|
|
2
|
-
import { PublicKey,
|
|
2
|
+
import { PublicKey, SystemProgram, TransactionInstruction, Transaction, sendAndConfirmTransaction, Keypair, Connection, ComputeBudgetProgram } from '@solana/web3.js';
|
|
3
3
|
import { AnchorProvider, setProvider, Program } from '@coral-xyz/anchor';
|
|
4
4
|
|
|
5
5
|
const IDL = {
|
|
6
|
-
version: '0.
|
|
6
|
+
version: '0.5.0',
|
|
7
7
|
name: 'light_compressed_token',
|
|
8
8
|
instructions: [
|
|
9
9
|
{
|
|
10
10
|
name: 'createTokenPool',
|
|
11
11
|
docs: [
|
|
12
|
-
'This instruction
|
|
13
|
-
'token
|
|
14
|
-
'
|
|
15
|
-
'
|
|
12
|
+
'This instruction creates a token pool for a given mint. Every spl mint',
|
|
13
|
+
'can have one token pool. When a token is compressed the tokens are',
|
|
14
|
+
'transferrred to the token pool, and their compressed equivalent is',
|
|
15
|
+
'minted into a Merkle tree.',
|
|
16
16
|
],
|
|
17
17
|
accounts: [
|
|
18
18
|
{
|
|
19
19
|
name: 'feePayer',
|
|
20
20
|
isMut: true,
|
|
21
21
|
isSigner: true,
|
|
22
|
+
docs: ['UNCHECKED: only pays fees.'],
|
|
22
23
|
},
|
|
23
24
|
{
|
|
24
25
|
name: 'tokenPoolPda',
|
|
@@ -54,13 +55,17 @@ const IDL = {
|
|
|
54
55
|
'Mints tokens from an spl token mint to a list of compressed accounts.',
|
|
55
56
|
'Minted tokens are transferred to a pool account owned by the compressed',
|
|
56
57
|
'token program. The instruction creates one compressed output account for',
|
|
57
|
-
'every amount and pubkey input pair
|
|
58
|
+
'every amount and pubkey input pair. A constant amount of lamports can be',
|
|
59
|
+
'transferred to each output account to enable. A use case to add lamports',
|
|
60
|
+
'to a compressed token account is to prevent spam. This is the only way',
|
|
61
|
+
'to add lamports to a compressed token account.',
|
|
58
62
|
],
|
|
59
63
|
accounts: [
|
|
60
64
|
{
|
|
61
65
|
name: 'feePayer',
|
|
62
66
|
isMut: true,
|
|
63
67
|
isSigner: true,
|
|
68
|
+
docs: ['UNCHECKED: only pays fees.'],
|
|
64
69
|
},
|
|
65
70
|
{
|
|
66
71
|
name: 'authority',
|
|
@@ -81,6 +86,9 @@ const IDL = {
|
|
|
81
86
|
name: 'tokenPoolPda',
|
|
82
87
|
isMut: true,
|
|
83
88
|
isSigner: false,
|
|
89
|
+
docs: [
|
|
90
|
+
'account to a token account of a different mint will fail',
|
|
91
|
+
],
|
|
84
92
|
},
|
|
85
93
|
{
|
|
86
94
|
name: 'tokenProgram',
|
|
@@ -101,6 +109,7 @@ const IDL = {
|
|
|
101
109
|
name: 'noopProgram',
|
|
102
110
|
isMut: false,
|
|
103
111
|
isSigner: false,
|
|
112
|
+
docs: ['programs'],
|
|
104
113
|
},
|
|
105
114
|
{
|
|
106
115
|
name: 'accountCompressionAuthority',
|
|
@@ -127,6 +136,12 @@ const IDL = {
|
|
|
127
136
|
isMut: false,
|
|
128
137
|
isSigner: false,
|
|
129
138
|
},
|
|
139
|
+
{
|
|
140
|
+
name: 'solPoolPda',
|
|
141
|
+
isMut: true,
|
|
142
|
+
isSigner: false,
|
|
143
|
+
isOptional: true,
|
|
144
|
+
},
|
|
130
145
|
],
|
|
131
146
|
args: [
|
|
132
147
|
{
|
|
@@ -141,20 +156,42 @@ const IDL = {
|
|
|
141
156
|
vec: 'u64',
|
|
142
157
|
},
|
|
143
158
|
},
|
|
159
|
+
{
|
|
160
|
+
name: 'lamports',
|
|
161
|
+
type: {
|
|
162
|
+
option: 'u64',
|
|
163
|
+
},
|
|
164
|
+
},
|
|
144
165
|
],
|
|
145
166
|
},
|
|
146
167
|
{
|
|
147
168
|
name: 'transfer',
|
|
169
|
+
docs: [
|
|
170
|
+
'Transfers compressed tokens from one account to another. All accounts',
|
|
171
|
+
'must be of the same mint. Additional spl tokens can be compressed or',
|
|
172
|
+
'decompressed. In one transaction only compression or decompression is',
|
|
173
|
+
'possible. Lamports can be transferred alongside tokens. If output token',
|
|
174
|
+
'accounts specify less lamports than inputs the remaining lamports are',
|
|
175
|
+
'transferred to an output compressed account. Signer must be owner or',
|
|
176
|
+
'delegate. If a delegated token account is transferred the delegate is',
|
|
177
|
+
'not preserved.',
|
|
178
|
+
],
|
|
148
179
|
accounts: [
|
|
149
180
|
{
|
|
150
181
|
name: 'feePayer',
|
|
151
182
|
isMut: true,
|
|
152
183
|
isSigner: true,
|
|
184
|
+
docs: ['UNCHECKED: only pays fees.'],
|
|
153
185
|
},
|
|
154
186
|
{
|
|
155
187
|
name: 'authority',
|
|
156
188
|
isMut: false,
|
|
157
189
|
isSigner: true,
|
|
190
|
+
docs: [
|
|
191
|
+
'Authority is verified through proof since both owner and delegate',
|
|
192
|
+
'are included in the token data hash, which is a public input to the',
|
|
193
|
+
'validity proof.',
|
|
194
|
+
],
|
|
158
195
|
},
|
|
159
196
|
{
|
|
160
197
|
name: 'cpiAuthorityPda',
|
|
@@ -190,6 +227,10 @@ const IDL = {
|
|
|
190
227
|
name: 'selfProgram',
|
|
191
228
|
isMut: false,
|
|
192
229
|
isSigner: false,
|
|
230
|
+
docs: [
|
|
231
|
+
'(different program) checked in light system program to derive',
|
|
232
|
+
'cpi_authority_pda and check that this program is the signer of the cpi.',
|
|
233
|
+
],
|
|
193
234
|
},
|
|
194
235
|
{
|
|
195
236
|
name: 'tokenPoolPda',
|
|
@@ -224,16 +265,30 @@ const IDL = {
|
|
|
224
265
|
},
|
|
225
266
|
{
|
|
226
267
|
name: 'approve',
|
|
268
|
+
docs: [
|
|
269
|
+
'Delegates an amount to a delegate. A compressed token account is either',
|
|
270
|
+
'completely delegated or not. Prior delegates are not preserved. Cannot',
|
|
271
|
+
'be called by a delegate.',
|
|
272
|
+
'The instruction creates two output accounts:',
|
|
273
|
+
'1. one account with delegated amount',
|
|
274
|
+
'2. one account with remaining(change) amount',
|
|
275
|
+
],
|
|
227
276
|
accounts: [
|
|
228
277
|
{
|
|
229
278
|
name: 'feePayer',
|
|
230
279
|
isMut: true,
|
|
231
280
|
isSigner: true,
|
|
281
|
+
docs: ['UNCHECKED: only pays fees.'],
|
|
232
282
|
},
|
|
233
283
|
{
|
|
234
284
|
name: 'authority',
|
|
235
285
|
isMut: false,
|
|
236
286
|
isSigner: true,
|
|
287
|
+
docs: [
|
|
288
|
+
'Authority is verified through proof since both owner and delegate',
|
|
289
|
+
'are included in the token data hash, which is a public input to the',
|
|
290
|
+
'validity proof.',
|
|
291
|
+
],
|
|
237
292
|
},
|
|
238
293
|
{
|
|
239
294
|
name: 'cpiAuthorityPda',
|
|
@@ -269,6 +324,10 @@ const IDL = {
|
|
|
269
324
|
name: 'selfProgram',
|
|
270
325
|
isMut: false,
|
|
271
326
|
isSigner: false,
|
|
327
|
+
docs: [
|
|
328
|
+
'(different program) checked in light system program to derive',
|
|
329
|
+
'cpi_authority_pda and check that this program is the signer of the cpi.',
|
|
330
|
+
],
|
|
272
331
|
},
|
|
273
332
|
{
|
|
274
333
|
name: 'systemProgram',
|
|
@@ -285,16 +344,26 @@ const IDL = {
|
|
|
285
344
|
},
|
|
286
345
|
{
|
|
287
346
|
name: 'revoke',
|
|
347
|
+
docs: [
|
|
348
|
+
'Revokes a delegation. The instruction merges all inputs into one output',
|
|
349
|
+
'account. Cannot be called by a delegate. Delegates are not preserved.',
|
|
350
|
+
],
|
|
288
351
|
accounts: [
|
|
289
352
|
{
|
|
290
353
|
name: 'feePayer',
|
|
291
354
|
isMut: true,
|
|
292
355
|
isSigner: true,
|
|
356
|
+
docs: ['UNCHECKED: only pays fees.'],
|
|
293
357
|
},
|
|
294
358
|
{
|
|
295
359
|
name: 'authority',
|
|
296
360
|
isMut: false,
|
|
297
361
|
isSigner: true,
|
|
362
|
+
docs: [
|
|
363
|
+
'Authority is verified through proof since both owner and delegate',
|
|
364
|
+
'are included in the token data hash, which is a public input to the',
|
|
365
|
+
'validity proof.',
|
|
366
|
+
],
|
|
298
367
|
},
|
|
299
368
|
{
|
|
300
369
|
name: 'cpiAuthorityPda',
|
|
@@ -330,6 +399,10 @@ const IDL = {
|
|
|
330
399
|
name: 'selfProgram',
|
|
331
400
|
isMut: false,
|
|
332
401
|
isSigner: false,
|
|
402
|
+
docs: [
|
|
403
|
+
'(different program) checked in light system program to derive',
|
|
404
|
+
'cpi_authority_pda and check that this program is the signer of the cpi.',
|
|
405
|
+
],
|
|
333
406
|
},
|
|
334
407
|
{
|
|
335
408
|
name: 'systemProgram',
|
|
@@ -346,11 +419,16 @@ const IDL = {
|
|
|
346
419
|
},
|
|
347
420
|
{
|
|
348
421
|
name: 'freeze',
|
|
422
|
+
docs: [
|
|
423
|
+
'Freezes compressed token accounts. Inputs must not be frozen. Creates as',
|
|
424
|
+
'many outputs as inputs. Balances and delegates are preserved.',
|
|
425
|
+
],
|
|
349
426
|
accounts: [
|
|
350
427
|
{
|
|
351
428
|
name: 'feePayer',
|
|
352
429
|
isMut: true,
|
|
353
430
|
isSigner: true,
|
|
431
|
+
docs: ['UNCHECKED: only pays fees.'],
|
|
354
432
|
},
|
|
355
433
|
{
|
|
356
434
|
name: 'authority',
|
|
@@ -391,6 +469,10 @@ const IDL = {
|
|
|
391
469
|
name: 'selfProgram',
|
|
392
470
|
isMut: false,
|
|
393
471
|
isSigner: false,
|
|
472
|
+
docs: [
|
|
473
|
+
'(different program) checked in light system program to derive',
|
|
474
|
+
'cpi_authority_pda and check that this program is the signer of the cpi.',
|
|
475
|
+
],
|
|
394
476
|
},
|
|
395
477
|
{
|
|
396
478
|
name: 'systemProgram',
|
|
@@ -412,11 +494,16 @@ const IDL = {
|
|
|
412
494
|
},
|
|
413
495
|
{
|
|
414
496
|
name: 'thaw',
|
|
497
|
+
docs: [
|
|
498
|
+
'Thaws frozen compressed token accounts. Inputs must be frozen. Creates',
|
|
499
|
+
'as many outputs as inputs. Balances and delegates are preserved.',
|
|
500
|
+
],
|
|
415
501
|
accounts: [
|
|
416
502
|
{
|
|
417
503
|
name: 'feePayer',
|
|
418
504
|
isMut: true,
|
|
419
505
|
isSigner: true,
|
|
506
|
+
docs: ['UNCHECKED: only pays fees.'],
|
|
420
507
|
},
|
|
421
508
|
{
|
|
422
509
|
name: 'authority',
|
|
@@ -457,6 +544,10 @@ const IDL = {
|
|
|
457
544
|
name: 'selfProgram',
|
|
458
545
|
isMut: false,
|
|
459
546
|
isSigner: false,
|
|
547
|
+
docs: [
|
|
548
|
+
'(different program) checked in light system program to derive',
|
|
549
|
+
'cpi_authority_pda and check that this program is the signer of the cpi.',
|
|
550
|
+
],
|
|
460
551
|
},
|
|
461
552
|
{
|
|
462
553
|
name: 'systemProgram',
|
|
@@ -478,22 +569,48 @@ const IDL = {
|
|
|
478
569
|
},
|
|
479
570
|
{
|
|
480
571
|
name: 'burn',
|
|
572
|
+
docs: [
|
|
573
|
+
'Burns compressed tokens and spl tokens from the pool account. Delegates',
|
|
574
|
+
'can burn tokens. The output compressed token account remains delegated.',
|
|
575
|
+
'Creates one output compressed token account.',
|
|
576
|
+
],
|
|
481
577
|
accounts: [
|
|
482
578
|
{
|
|
483
579
|
name: 'feePayer',
|
|
484
580
|
isMut: true,
|
|
485
581
|
isSigner: true,
|
|
582
|
+
docs: ['UNCHECKED: only pays fees.'],
|
|
486
583
|
},
|
|
487
584
|
{
|
|
488
585
|
name: 'authority',
|
|
489
586
|
isMut: false,
|
|
490
587
|
isSigner: true,
|
|
588
|
+
docs: [
|
|
589
|
+
'Authority is verified through proof since both owner and delegate',
|
|
590
|
+
'are included in the token data hash, which is a public input to the',
|
|
591
|
+
'validity proof.',
|
|
592
|
+
],
|
|
491
593
|
},
|
|
492
594
|
{
|
|
493
595
|
name: 'cpiAuthorityPda',
|
|
494
596
|
isMut: false,
|
|
495
597
|
isSigner: false,
|
|
496
598
|
},
|
|
599
|
+
{
|
|
600
|
+
name: 'mint',
|
|
601
|
+
isMut: true,
|
|
602
|
+
isSigner: false,
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
name: 'tokenPoolPda',
|
|
606
|
+
isMut: true,
|
|
607
|
+
isSigner: false,
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
name: 'tokenProgram',
|
|
611
|
+
isMut: false,
|
|
612
|
+
isSigner: false,
|
|
613
|
+
},
|
|
497
614
|
{
|
|
498
615
|
name: 'lightSystemProgram',
|
|
499
616
|
isMut: false,
|
|
@@ -549,11 +666,17 @@ const IDL = {
|
|
|
549
666
|
name: 'feePayer',
|
|
550
667
|
isMut: true,
|
|
551
668
|
isSigner: true,
|
|
669
|
+
docs: ['UNCHECKED: only pays fees.'],
|
|
552
670
|
},
|
|
553
671
|
{
|
|
554
672
|
name: 'authority',
|
|
555
673
|
isMut: false,
|
|
556
674
|
isSigner: true,
|
|
675
|
+
docs: [
|
|
676
|
+
'Authority is verified through proof since both owner and delegate',
|
|
677
|
+
'are included in the token data hash, which is a public input to the',
|
|
678
|
+
'validity proof.',
|
|
679
|
+
],
|
|
557
680
|
},
|
|
558
681
|
{
|
|
559
682
|
name: 'cpiAuthorityPda',
|
|
@@ -589,6 +712,10 @@ const IDL = {
|
|
|
589
712
|
name: 'selfProgram',
|
|
590
713
|
isMut: false,
|
|
591
714
|
isSigner: false,
|
|
715
|
+
docs: [
|
|
716
|
+
'(different program) checked in light system program to derive',
|
|
717
|
+
'cpi_authority_pda and check that this program is the signer of the cpi.',
|
|
718
|
+
],
|
|
592
719
|
},
|
|
593
720
|
{
|
|
594
721
|
name: 'tokenPoolPda',
|
|
@@ -630,24 +757,6 @@ const IDL = {
|
|
|
630
757
|
],
|
|
631
758
|
},
|
|
632
759
|
],
|
|
633
|
-
accounts: [
|
|
634
|
-
{
|
|
635
|
-
name: 'RegisteredProgram',
|
|
636
|
-
type: {
|
|
637
|
-
kind: 'struct',
|
|
638
|
-
fields: [
|
|
639
|
-
{
|
|
640
|
-
name: 'registeredProgramId',
|
|
641
|
-
type: 'publicKey',
|
|
642
|
-
},
|
|
643
|
-
{
|
|
644
|
-
name: 'groupAuthorityPda',
|
|
645
|
-
type: 'publicKey',
|
|
646
|
-
},
|
|
647
|
-
],
|
|
648
|
-
},
|
|
649
|
-
},
|
|
650
|
-
],
|
|
651
760
|
types: [
|
|
652
761
|
{
|
|
653
762
|
name: 'AccessMetadata',
|
|
@@ -662,7 +771,7 @@ const IDL = {
|
|
|
662
771
|
{
|
|
663
772
|
name: 'programOwner',
|
|
664
773
|
docs: [
|
|
665
|
-
'
|
|
774
|
+
'Program owner of the Merkle tree. This will be used for program owned Merkle trees.',
|
|
666
775
|
],
|
|
667
776
|
type: 'publicKey',
|
|
668
777
|
},
|
|
@@ -816,9 +925,9 @@ const IDL = {
|
|
|
816
925
|
{
|
|
817
926
|
name: 'delegatedTransfer',
|
|
818
927
|
docs: [
|
|
819
|
-
'
|
|
928
|
+
'Is required if the signer is delegate,',
|
|
929
|
+
'-> delegate is authority account,',
|
|
820
930
|
'owner = Some(owner) is the owner of the token account.',
|
|
821
|
-
'Is set if the signer is delegate',
|
|
822
931
|
],
|
|
823
932
|
type: {
|
|
824
933
|
option: {
|
|
@@ -860,11 +969,20 @@ const IDL = {
|
|
|
860
969
|
},
|
|
861
970
|
},
|
|
862
971
|
},
|
|
972
|
+
{
|
|
973
|
+
name: 'lamportsChangeAccountMerkleTreeIndex',
|
|
974
|
+
type: {
|
|
975
|
+
option: 'u8',
|
|
976
|
+
},
|
|
977
|
+
},
|
|
863
978
|
],
|
|
864
979
|
},
|
|
865
980
|
},
|
|
866
981
|
{
|
|
867
982
|
name: 'DelegatedTransfer',
|
|
983
|
+
docs: [
|
|
984
|
+
'Struct to provide the owner when the delegate is signer of the transaction.',
|
|
985
|
+
],
|
|
868
986
|
type: {
|
|
869
987
|
kind: 'struct',
|
|
870
988
|
fields: [
|
|
@@ -874,7 +992,15 @@ const IDL = {
|
|
|
874
992
|
},
|
|
875
993
|
{
|
|
876
994
|
name: 'delegateChangeAccountIndex',
|
|
877
|
-
|
|
995
|
+
docs: [
|
|
996
|
+
'Index of change compressed account in output compressed accounts. In',
|
|
997
|
+
"case that the delegate didn't spend the complete delegated compressed",
|
|
998
|
+
'account balance the change compressed account will be delegated to her',
|
|
999
|
+
'as well.',
|
|
1000
|
+
],
|
|
1001
|
+
type: {
|
|
1002
|
+
option: 'u8',
|
|
1003
|
+
},
|
|
878
1004
|
},
|
|
879
1005
|
],
|
|
880
1006
|
},
|
|
@@ -910,6 +1036,15 @@ const IDL = {
|
|
|
910
1036
|
option: 'u64',
|
|
911
1037
|
},
|
|
912
1038
|
},
|
|
1039
|
+
{
|
|
1040
|
+
name: 'tlv',
|
|
1041
|
+
docs: [
|
|
1042
|
+
'Placeholder for TokenExtension tlv data (unimplemented)',
|
|
1043
|
+
],
|
|
1044
|
+
type: {
|
|
1045
|
+
option: 'bytes',
|
|
1046
|
+
},
|
|
1047
|
+
},
|
|
913
1048
|
],
|
|
914
1049
|
},
|
|
915
1050
|
},
|
|
@@ -1171,6 +1306,18 @@ const IDL = {
|
|
|
1171
1306
|
name: 'leafIndex',
|
|
1172
1307
|
type: 'u32',
|
|
1173
1308
|
},
|
|
1309
|
+
{
|
|
1310
|
+
name: 'queueIndex',
|
|
1311
|
+
docs: [
|
|
1312
|
+
'Index of leaf in queue. Placeholder of batched Merkle tree updates',
|
|
1313
|
+
'currently unimplemented.',
|
|
1314
|
+
],
|
|
1315
|
+
type: {
|
|
1316
|
+
option: {
|
|
1317
|
+
defined: 'QueueIndex',
|
|
1318
|
+
},
|
|
1319
|
+
},
|
|
1320
|
+
},
|
|
1174
1321
|
],
|
|
1175
1322
|
},
|
|
1176
1323
|
},
|
|
@@ -1197,6 +1344,15 @@ const IDL = {
|
|
|
1197
1344
|
name: 'merkleTreeIndex',
|
|
1198
1345
|
type: 'u8',
|
|
1199
1346
|
},
|
|
1347
|
+
{
|
|
1348
|
+
name: 'tlv',
|
|
1349
|
+
docs: [
|
|
1350
|
+
'Placeholder for TokenExtension tlv data (unimplemented)',
|
|
1351
|
+
],
|
|
1352
|
+
type: {
|
|
1353
|
+
option: 'bytes',
|
|
1354
|
+
},
|
|
1355
|
+
},
|
|
1200
1356
|
],
|
|
1201
1357
|
},
|
|
1202
1358
|
},
|
|
@@ -1274,6 +1430,24 @@ const IDL = {
|
|
|
1274
1430
|
],
|
|
1275
1431
|
},
|
|
1276
1432
|
},
|
|
1433
|
+
{
|
|
1434
|
+
name: 'QueueIndex',
|
|
1435
|
+
type: {
|
|
1436
|
+
kind: 'struct',
|
|
1437
|
+
fields: [
|
|
1438
|
+
{
|
|
1439
|
+
name: 'queueId',
|
|
1440
|
+
docs: ['Id of queue in queue account.'],
|
|
1441
|
+
type: 'u8',
|
|
1442
|
+
},
|
|
1443
|
+
{
|
|
1444
|
+
name: 'index',
|
|
1445
|
+
docs: ['Index of compressed account hash in queue.'],
|
|
1446
|
+
type: 'u16',
|
|
1447
|
+
},
|
|
1448
|
+
],
|
|
1449
|
+
},
|
|
1450
|
+
},
|
|
1277
1451
|
{
|
|
1278
1452
|
name: 'RolloverMetadata',
|
|
1279
1453
|
type: {
|
|
@@ -1360,6 +1534,15 @@ const IDL = {
|
|
|
1360
1534
|
defined: 'AccountState',
|
|
1361
1535
|
},
|
|
1362
1536
|
},
|
|
1537
|
+
{
|
|
1538
|
+
name: 'tlv',
|
|
1539
|
+
docs: [
|
|
1540
|
+
'Placeholder for TokenExtension tlv data (unimplemented)',
|
|
1541
|
+
],
|
|
1542
|
+
type: {
|
|
1543
|
+
option: 'bytes',
|
|
1544
|
+
},
|
|
1545
|
+
},
|
|
1363
1546
|
],
|
|
1364
1547
|
},
|
|
1365
1548
|
},
|
|
@@ -1367,23 +1550,107 @@ const IDL = {
|
|
|
1367
1550
|
errors: [
|
|
1368
1551
|
{
|
|
1369
1552
|
code: 6000,
|
|
1370
|
-
name: '
|
|
1371
|
-
msg: '
|
|
1553
|
+
name: 'PublicKeyAmountMissmatch',
|
|
1554
|
+
msg: 'public keys and amounts must be of same length',
|
|
1372
1555
|
},
|
|
1373
1556
|
{
|
|
1374
1557
|
code: 6001,
|
|
1375
|
-
name: '
|
|
1376
|
-
msg: '
|
|
1558
|
+
name: 'ComputeInputSumFailed',
|
|
1559
|
+
msg: 'ComputeInputSumFailed',
|
|
1377
1560
|
},
|
|
1378
1561
|
{
|
|
1379
1562
|
code: 6002,
|
|
1380
|
-
name: '
|
|
1381
|
-
msg: '
|
|
1563
|
+
name: 'ComputeOutputSumFailed',
|
|
1564
|
+
msg: 'ComputeOutputSumFailed',
|
|
1382
1565
|
},
|
|
1383
1566
|
{
|
|
1384
1567
|
code: 6003,
|
|
1385
|
-
name: '
|
|
1386
|
-
msg: '
|
|
1568
|
+
name: 'ComputeCompressSumFailed',
|
|
1569
|
+
msg: 'ComputeCompressSumFailed',
|
|
1570
|
+
},
|
|
1571
|
+
{
|
|
1572
|
+
code: 6004,
|
|
1573
|
+
name: 'ComputeDecompressSumFailed',
|
|
1574
|
+
msg: 'ComputeDecompressSumFailed',
|
|
1575
|
+
},
|
|
1576
|
+
{
|
|
1577
|
+
code: 6005,
|
|
1578
|
+
name: 'SumCheckFailed',
|
|
1579
|
+
msg: 'SumCheckFailed',
|
|
1580
|
+
},
|
|
1581
|
+
{
|
|
1582
|
+
code: 6006,
|
|
1583
|
+
name: 'DecompressRecipientUndefinedForDecompress',
|
|
1584
|
+
msg: 'DecompressRecipientUndefinedForDecompress',
|
|
1585
|
+
},
|
|
1586
|
+
{
|
|
1587
|
+
code: 6007,
|
|
1588
|
+
name: 'CompressedPdaUndefinedForDecompress',
|
|
1589
|
+
msg: 'CompressedPdaUndefinedForDecompress',
|
|
1590
|
+
},
|
|
1591
|
+
{
|
|
1592
|
+
code: 6008,
|
|
1593
|
+
name: 'DeCompressAmountUndefinedForDecompress',
|
|
1594
|
+
msg: 'DeCompressAmountUndefinedForDecompress',
|
|
1595
|
+
},
|
|
1596
|
+
{
|
|
1597
|
+
code: 6009,
|
|
1598
|
+
name: 'CompressedPdaUndefinedForCompress',
|
|
1599
|
+
msg: 'CompressedPdaUndefinedForCompress',
|
|
1600
|
+
},
|
|
1601
|
+
{
|
|
1602
|
+
code: 6010,
|
|
1603
|
+
name: 'DeCompressAmountUndefinedForCompress',
|
|
1604
|
+
msg: 'DeCompressAmountUndefinedForCompress',
|
|
1605
|
+
},
|
|
1606
|
+
{
|
|
1607
|
+
code: 6011,
|
|
1608
|
+
name: 'DelegateSignerCheckFailed',
|
|
1609
|
+
msg: 'DelegateSignerCheckFailed',
|
|
1610
|
+
},
|
|
1611
|
+
{
|
|
1612
|
+
code: 6012,
|
|
1613
|
+
name: 'MintTooLarge',
|
|
1614
|
+
msg: 'Minted amount greater than u64::MAX',
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
code: 6013,
|
|
1618
|
+
name: 'SplTokenSupplyMismatch',
|
|
1619
|
+
msg: 'SplTokenSupplyMismatch',
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
code: 6014,
|
|
1623
|
+
name: 'HeapMemoryCheckFailed',
|
|
1624
|
+
msg: 'HeapMemoryCheckFailed',
|
|
1625
|
+
},
|
|
1626
|
+
{
|
|
1627
|
+
code: 6015,
|
|
1628
|
+
name: 'InstructionNotCallable',
|
|
1629
|
+
msg: 'The instruction is not callable',
|
|
1630
|
+
},
|
|
1631
|
+
{
|
|
1632
|
+
code: 6016,
|
|
1633
|
+
name: 'ArithmeticUnderflow',
|
|
1634
|
+
msg: 'ArithmeticUnderflow',
|
|
1635
|
+
},
|
|
1636
|
+
{
|
|
1637
|
+
code: 6017,
|
|
1638
|
+
name: 'HashToFieldError',
|
|
1639
|
+
msg: 'HashToFieldError',
|
|
1640
|
+
},
|
|
1641
|
+
{
|
|
1642
|
+
code: 6018,
|
|
1643
|
+
name: 'InvalidAuthorityMint',
|
|
1644
|
+
msg: 'Expected the authority to be also a mint authority',
|
|
1645
|
+
},
|
|
1646
|
+
{
|
|
1647
|
+
code: 6019,
|
|
1648
|
+
name: 'InvalidFreezeAuthority',
|
|
1649
|
+
msg: 'Provided authority is not the freeze authority',
|
|
1650
|
+
},
|
|
1651
|
+
{
|
|
1652
|
+
code: 6020,
|
|
1653
|
+
name: 'InvalidDelegateIndex',
|
|
1387
1654
|
},
|
|
1388
1655
|
],
|
|
1389
1656
|
};
|
|
@@ -1414,11 +1681,13 @@ function packCompressedTokenAccounts(params) {
|
|
|
1414
1681
|
merkleTreePubkeyIndex,
|
|
1415
1682
|
nullifierQueuePubkeyIndex,
|
|
1416
1683
|
leafIndex: account.compressedAccount.leafIndex,
|
|
1684
|
+
queueIndex: null,
|
|
1417
1685
|
},
|
|
1418
1686
|
rootIndex: rootIndices[index],
|
|
1419
1687
|
lamports: account.compressedAccount.lamports.eq(bn(0))
|
|
1420
1688
|
? null
|
|
1421
1689
|
: account.compressedAccount.lamports,
|
|
1690
|
+
tlv: null,
|
|
1422
1691
|
});
|
|
1423
1692
|
});
|
|
1424
1693
|
/// pack output state trees
|
|
@@ -1433,6 +1702,7 @@ function packCompressedTokenAccounts(params) {
|
|
|
1433
1702
|
? null
|
|
1434
1703
|
: tokenTransferOutputs[index].lamports,
|
|
1435
1704
|
merkleTreeIndex,
|
|
1705
|
+
tlv: null,
|
|
1436
1706
|
});
|
|
1437
1707
|
});
|
|
1438
1708
|
// to meta
|
|
@@ -6005,33 +6275,6 @@ function addSigners(keys, ownerOrAuthority, multiSigners) {
|
|
|
6005
6275
|
return keys;
|
|
6006
6276
|
}
|
|
6007
6277
|
|
|
6008
|
-
/** TODO: docs */
|
|
6009
|
-
const approveInstructionData = struct([u8('instruction'), u64('amount')]);
|
|
6010
|
-
/**
|
|
6011
|
-
* Construct an Approve instruction
|
|
6012
|
-
*
|
|
6013
|
-
* @param account Account to set the delegate for
|
|
6014
|
-
* @param delegate Account authorized to transfer tokens from the account
|
|
6015
|
-
* @param owner Owner of the account
|
|
6016
|
-
* @param amount Maximum number of tokens the delegate may transfer
|
|
6017
|
-
* @param multiSigners Signing accounts if `owner` is a multisig
|
|
6018
|
-
* @param programId SPL Token program account
|
|
6019
|
-
*
|
|
6020
|
-
* @return Instruction to add to a transaction
|
|
6021
|
-
*/
|
|
6022
|
-
function createApproveInstruction(account, delegate, owner, amount, multiSigners = [], programId = TOKEN_PROGRAM_ID) {
|
|
6023
|
-
const keys = addSigners([
|
|
6024
|
-
{ pubkey: account, isSigner: false, isWritable: true },
|
|
6025
|
-
{ pubkey: delegate, isSigner: false, isWritable: false },
|
|
6026
|
-
], owner, multiSigners);
|
|
6027
|
-
const data = Buffer.alloc(approveInstructionData.span);
|
|
6028
|
-
approveInstructionData.encode({
|
|
6029
|
-
instruction: TokenInstruction.Approve,
|
|
6030
|
-
amount: BigInt(amount),
|
|
6031
|
-
}, data);
|
|
6032
|
-
return new TransactionInstruction({ keys, programId, data });
|
|
6033
|
-
}
|
|
6034
|
-
|
|
6035
6278
|
var AccountType;
|
|
6036
6279
|
(function (AccountType) {
|
|
6037
6280
|
AccountType[AccountType["Uninitialized"] = 0] = "Uninitialized";
|
|
@@ -6355,6 +6598,7 @@ function createTransferOutputState(inputCompressedTokenAccounts, toAddress, amou
|
|
|
6355
6598
|
owner: toAddress,
|
|
6356
6599
|
amount,
|
|
6357
6600
|
lamports: inputLamports,
|
|
6601
|
+
tlv: null,
|
|
6358
6602
|
},
|
|
6359
6603
|
];
|
|
6360
6604
|
}
|
|
@@ -6366,11 +6610,13 @@ function createTransferOutputState(inputCompressedTokenAccounts, toAddress, amou
|
|
|
6366
6610
|
owner: inputCompressedTokenAccounts[0].parsed.owner,
|
|
6367
6611
|
amount: changeAmount,
|
|
6368
6612
|
lamports: inputLamports,
|
|
6613
|
+
tlv: null,
|
|
6369
6614
|
},
|
|
6370
6615
|
{
|
|
6371
6616
|
owner: toAddress,
|
|
6372
6617
|
amount,
|
|
6373
6618
|
lamports: bn(0),
|
|
6619
|
+
tlv: null,
|
|
6374
6620
|
},
|
|
6375
6621
|
];
|
|
6376
6622
|
return outputCompressedAccounts;
|
|
@@ -6399,6 +6645,7 @@ function createDecompressOutputState(inputCompressedTokenAccounts, amount) {
|
|
|
6399
6645
|
owner: inputCompressedTokenAccounts[0].parsed.owner,
|
|
6400
6646
|
amount: changeAmount,
|
|
6401
6647
|
lamports: inputLamports,
|
|
6648
|
+
tlv: null,
|
|
6402
6649
|
},
|
|
6403
6650
|
];
|
|
6404
6651
|
return tokenTransferOutputs;
|
|
@@ -6497,7 +6744,7 @@ class CompressedTokenProgram {
|
|
|
6497
6744
|
const amounts = toArray(amount).map(amount => bn(amount));
|
|
6498
6745
|
const toPubkeys = toArray(toPubkey);
|
|
6499
6746
|
const instruction = await this.program.methods
|
|
6500
|
-
.mintTo(toPubkeys, amounts)
|
|
6747
|
+
.mintTo(toPubkeys, amounts, null)
|
|
6501
6748
|
.accounts({
|
|
6502
6749
|
feePayer,
|
|
6503
6750
|
authority,
|
|
@@ -6512,6 +6759,7 @@ class CompressedTokenProgram {
|
|
|
6512
6759
|
accountCompressionProgram: systemKeys.accountCompressionProgram,
|
|
6513
6760
|
merkleTree: merkleTree ?? defaultTestStateTreeAccounts().merkleTree,
|
|
6514
6761
|
selfProgram: this.programId,
|
|
6762
|
+
solPoolPda: null,
|
|
6515
6763
|
})
|
|
6516
6764
|
.instruction();
|
|
6517
6765
|
return instruction;
|
|
@@ -6526,7 +6774,7 @@ class CompressedTokenProgram {
|
|
|
6526
6774
|
/// 1. Mint to existing ATA of mintAuthority.
|
|
6527
6775
|
const splMintToInstruction = createMintToInstruction(mint, authorityTokenAccount, authority, amount);
|
|
6528
6776
|
/// 2. Compress from mint authority ATA to recipient compressed account
|
|
6529
|
-
const
|
|
6777
|
+
const compressInstruction = await this.compress({
|
|
6530
6778
|
payer: feePayer,
|
|
6531
6779
|
owner: authority,
|
|
6532
6780
|
source: authorityTokenAccount,
|
|
@@ -6535,7 +6783,7 @@ class CompressedTokenProgram {
|
|
|
6535
6783
|
amount: params.amount,
|
|
6536
6784
|
outputStateTree: merkleTree,
|
|
6537
6785
|
});
|
|
6538
|
-
return [splMintToInstruction,
|
|
6786
|
+
return [splMintToInstruction, compressInstruction];
|
|
6539
6787
|
}
|
|
6540
6788
|
/**
|
|
6541
6789
|
* Construct transfer instruction for compressed tokens
|
|
@@ -6559,6 +6807,7 @@ class CompressedTokenProgram {
|
|
|
6559
6807
|
compressOrDecompressAmount: null,
|
|
6560
6808
|
isCompress: false,
|
|
6561
6809
|
cpiContext: null,
|
|
6810
|
+
lamportsChangeAccountMerkleTreeIndex: null,
|
|
6562
6811
|
};
|
|
6563
6812
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
6564
6813
|
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = defaultStaticAccountsStruct();
|
|
@@ -6583,8 +6832,8 @@ class CompressedTokenProgram {
|
|
|
6583
6832
|
return instruction;
|
|
6584
6833
|
}
|
|
6585
6834
|
/**
|
|
6586
|
-
* Construct
|
|
6587
|
-
* @returns
|
|
6835
|
+
* Construct compress instruction
|
|
6836
|
+
* @returns compressInstruction
|
|
6588
6837
|
*/
|
|
6589
6838
|
static async compress(params) {
|
|
6590
6839
|
const { payer, owner, source, toAddress, mint, outputStateTree } = params;
|
|
@@ -6594,6 +6843,7 @@ class CompressedTokenProgram {
|
|
|
6594
6843
|
owner: toAddress,
|
|
6595
6844
|
amount,
|
|
6596
6845
|
lamports: bn(0),
|
|
6846
|
+
tlv: null,
|
|
6597
6847
|
},
|
|
6598
6848
|
];
|
|
6599
6849
|
const { inputTokenDataWithContext, packedOutputTokenData, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
@@ -6611,10 +6861,10 @@ class CompressedTokenProgram {
|
|
|
6611
6861
|
compressOrDecompressAmount: amount,
|
|
6612
6862
|
isCompress: true,
|
|
6613
6863
|
cpiContext: null,
|
|
6864
|
+
lamportsChangeAccountMerkleTreeIndex: null,
|
|
6614
6865
|
};
|
|
6615
6866
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
6616
6867
|
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = defaultStaticAccountsStruct();
|
|
6617
|
-
const approveInstruction = createApproveInstruction(source, this.deriveCpiAuthorityPda, owner, BigInt(amount.toString()));
|
|
6618
6868
|
const instruction = await this.program.methods
|
|
6619
6869
|
.transfer(encodedData)
|
|
6620
6870
|
.accounts({
|
|
@@ -6633,7 +6883,7 @@ class CompressedTokenProgram {
|
|
|
6633
6883
|
})
|
|
6634
6884
|
.remainingAccounts(remainingAccountMetas)
|
|
6635
6885
|
.instruction();
|
|
6636
|
-
return
|
|
6886
|
+
return instruction;
|
|
6637
6887
|
}
|
|
6638
6888
|
/**
|
|
6639
6889
|
* Construct decompress instruction
|
|
@@ -6659,6 +6909,7 @@ class CompressedTokenProgram {
|
|
|
6659
6909
|
compressOrDecompressAmount: amount,
|
|
6660
6910
|
isCompress: false,
|
|
6661
6911
|
cpiContext: null,
|
|
6912
|
+
lamportsChangeAccountMerkleTreeIndex: null,
|
|
6662
6913
|
};
|
|
6663
6914
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
6664
6915
|
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = defaultStaticAccountsStruct();
|
|
@@ -6740,7 +6991,7 @@ async function approveAndMintTo(rpc, payer, mint, destination, authority, amount
|
|
|
6740
6991
|
*/
|
|
6741
6992
|
async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toAddress, merkleTree, confirmOptions) {
|
|
6742
6993
|
amount = bn(amount);
|
|
6743
|
-
const
|
|
6994
|
+
const compressIx = await CompressedTokenProgram.compress({
|
|
6744
6995
|
payer: payer.publicKey,
|
|
6745
6996
|
owner: owner.publicKey,
|
|
6746
6997
|
source: sourceTokenAccount,
|
|
@@ -6755,7 +7006,6 @@ async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toA
|
|
|
6755
7006
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
6756
7007
|
units: 1_000_000,
|
|
6757
7008
|
}),
|
|
6758
|
-
approveIx,
|
|
6759
7009
|
compressIx,
|
|
6760
7010
|
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
6761
7011
|
const txId = await sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|