@lightprotocol/compressed-token 0.1.3 → 0.2.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 +771 -308
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +789 -651
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.js +770 -309
- package/dist/es/browser/index.js.map +1 -1
- package/dist/types/index.d.ts +481 -268
- package/package.json +106 -91
- package/dist/es/node/index.js +0 -4404
- package/dist/es/node/index.js.map +0 -1
package/dist/cjs/node/index.cjs
CHANGED
|
@@ -4,11 +4,9 @@ var stateless_js = require('@lightprotocol/stateless.js');
|
|
|
4
4
|
var anchor = require('@coral-xyz/anchor');
|
|
5
5
|
var web3_js = require('@solana/web3.js');
|
|
6
6
|
var require$$0 = require('buffer');
|
|
7
|
-
var require$$0$2 = require('fs');
|
|
8
|
-
var require$$0$1 = require('path');
|
|
9
7
|
|
|
10
8
|
const IDL = {
|
|
11
|
-
version: '0.3.
|
|
9
|
+
version: '0.3.1',
|
|
12
10
|
name: 'light_compressed_token',
|
|
13
11
|
constants: [
|
|
14
12
|
{
|
|
@@ -21,9 +19,10 @@ const IDL = {
|
|
|
21
19
|
{
|
|
22
20
|
name: 'createMint',
|
|
23
21
|
docs: [
|
|
24
|
-
'This instruction expects a mint account to be created in a separate
|
|
25
|
-
'with token authority as mint authority.',
|
|
26
|
-
'
|
|
22
|
+
'This instruction expects a mint account to be created in a separate',
|
|
23
|
+
'token program instruction with token authority as mint authority. This',
|
|
24
|
+
'instruction creates a token pool account for that mint owned by token',
|
|
25
|
+
'authority.',
|
|
27
26
|
],
|
|
28
27
|
accounts: [
|
|
29
28
|
{
|
|
@@ -103,7 +102,7 @@ const IDL = {
|
|
|
103
102
|
isSigner: false,
|
|
104
103
|
},
|
|
105
104
|
{
|
|
106
|
-
name: '
|
|
105
|
+
name: 'lightSystemProgram',
|
|
107
106
|
isMut: false,
|
|
108
107
|
isSigner: false,
|
|
109
108
|
},
|
|
@@ -137,6 +136,11 @@ const IDL = {
|
|
|
137
136
|
isMut: false,
|
|
138
137
|
isSigner: false,
|
|
139
138
|
},
|
|
139
|
+
{
|
|
140
|
+
name: 'systemProgram',
|
|
141
|
+
isMut: false,
|
|
142
|
+
isSigner: false,
|
|
143
|
+
},
|
|
140
144
|
],
|
|
141
145
|
args: [
|
|
142
146
|
{
|
|
@@ -151,6 +155,10 @@ const IDL = {
|
|
|
151
155
|
vec: 'u64',
|
|
152
156
|
},
|
|
153
157
|
},
|
|
158
|
+
{
|
|
159
|
+
name: 'bump',
|
|
160
|
+
type: 'u8',
|
|
161
|
+
},
|
|
154
162
|
],
|
|
155
163
|
},
|
|
156
164
|
{
|
|
@@ -158,7 +166,7 @@ const IDL = {
|
|
|
158
166
|
accounts: [
|
|
159
167
|
{
|
|
160
168
|
name: 'feePayer',
|
|
161
|
-
isMut:
|
|
169
|
+
isMut: true,
|
|
162
170
|
isSigner: true,
|
|
163
171
|
},
|
|
164
172
|
{
|
|
@@ -172,7 +180,7 @@ const IDL = {
|
|
|
172
180
|
isSigner: false,
|
|
173
181
|
},
|
|
174
182
|
{
|
|
175
|
-
name: '
|
|
183
|
+
name: 'lightSystemProgram',
|
|
176
184
|
isMut: false,
|
|
177
185
|
isSigner: false,
|
|
178
186
|
},
|
|
@@ -219,139 +227,161 @@ const IDL = {
|
|
|
219
227
|
isSigner: false,
|
|
220
228
|
isOptional: true,
|
|
221
229
|
},
|
|
230
|
+
{
|
|
231
|
+
name: 'systemProgram',
|
|
232
|
+
isMut: false,
|
|
233
|
+
isSigner: false,
|
|
234
|
+
},
|
|
222
235
|
],
|
|
223
236
|
args: [
|
|
224
237
|
{
|
|
225
238
|
name: 'inputs',
|
|
226
239
|
type: 'bytes',
|
|
227
240
|
},
|
|
228
|
-
{
|
|
229
|
-
name: 'cpiContext',
|
|
230
|
-
type: {
|
|
231
|
-
option: {
|
|
232
|
-
defined: 'CompressedCpiContext',
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
},
|
|
236
241
|
],
|
|
237
242
|
},
|
|
238
243
|
],
|
|
239
244
|
types: [
|
|
240
245
|
{
|
|
241
|
-
name: '
|
|
246
|
+
name: 'InstructionDataInvoke',
|
|
242
247
|
type: {
|
|
243
248
|
kind: 'struct',
|
|
244
249
|
fields: [
|
|
245
250
|
{
|
|
246
|
-
name: '
|
|
251
|
+
name: 'proof',
|
|
247
252
|
type: {
|
|
248
|
-
|
|
253
|
+
option: {
|
|
254
|
+
defined: 'CompressedProof',
|
|
255
|
+
},
|
|
249
256
|
},
|
|
250
257
|
},
|
|
251
258
|
{
|
|
252
|
-
name: '
|
|
253
|
-
type:
|
|
259
|
+
name: 'inputRootIndices',
|
|
260
|
+
type: {
|
|
261
|
+
vec: 'u16',
|
|
262
|
+
},
|
|
254
263
|
},
|
|
255
264
|
{
|
|
256
|
-
name: '
|
|
257
|
-
type:
|
|
265
|
+
name: 'inputCompressedAccountsWithMerkleContext',
|
|
266
|
+
type: {
|
|
267
|
+
vec: {
|
|
268
|
+
defined: 'PackedCompressedAccountWithMerkleContext',
|
|
269
|
+
},
|
|
270
|
+
},
|
|
258
271
|
},
|
|
259
272
|
{
|
|
260
|
-
name: '
|
|
261
|
-
type:
|
|
273
|
+
name: 'outputCompressedAccounts',
|
|
274
|
+
type: {
|
|
275
|
+
vec: {
|
|
276
|
+
defined: 'CompressedAccount',
|
|
277
|
+
},
|
|
278
|
+
},
|
|
262
279
|
},
|
|
263
|
-
],
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
name: 'MerkleContext',
|
|
268
|
-
type: {
|
|
269
|
-
kind: 'struct',
|
|
270
|
-
fields: [
|
|
271
280
|
{
|
|
272
|
-
name: '
|
|
273
|
-
|
|
281
|
+
name: 'outputStateMerkleTreeAccountIndices',
|
|
282
|
+
docs: [
|
|
283
|
+
'The indices of the accounts in the output state merkle tree.',
|
|
284
|
+
],
|
|
285
|
+
type: 'bytes',
|
|
274
286
|
},
|
|
275
287
|
{
|
|
276
|
-
name: '
|
|
277
|
-
type:
|
|
288
|
+
name: 'relayFee',
|
|
289
|
+
type: {
|
|
290
|
+
option: 'u64',
|
|
291
|
+
},
|
|
278
292
|
},
|
|
279
293
|
{
|
|
280
|
-
name: '
|
|
281
|
-
type:
|
|
294
|
+
name: 'newAddressParams',
|
|
295
|
+
type: {
|
|
296
|
+
vec: {
|
|
297
|
+
defined: 'NewAddressParamsPacked',
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: 'compressionLamports',
|
|
303
|
+
type: {
|
|
304
|
+
option: 'u64',
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
name: 'isCompress',
|
|
309
|
+
type: 'bool',
|
|
282
310
|
},
|
|
283
311
|
],
|
|
284
312
|
},
|
|
285
313
|
},
|
|
286
314
|
{
|
|
287
|
-
name: '
|
|
315
|
+
name: 'NewAddressParamsPacked',
|
|
288
316
|
type: {
|
|
289
317
|
kind: 'struct',
|
|
290
318
|
fields: [
|
|
291
319
|
{
|
|
292
|
-
name: '
|
|
320
|
+
name: 'seed',
|
|
321
|
+
type: {
|
|
322
|
+
array: ['u8', 32],
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
name: 'addressQueueAccountIndex',
|
|
293
327
|
type: 'u8',
|
|
294
328
|
},
|
|
295
329
|
{
|
|
296
|
-
name: '
|
|
330
|
+
name: 'addressMerkleTreeAccountIndex',
|
|
297
331
|
type: 'u8',
|
|
298
332
|
},
|
|
299
333
|
{
|
|
300
|
-
name: '
|
|
301
|
-
type: '
|
|
334
|
+
name: 'addressMerkleTreeRootIndex',
|
|
335
|
+
type: 'u16',
|
|
302
336
|
},
|
|
303
337
|
],
|
|
304
338
|
},
|
|
305
339
|
},
|
|
306
340
|
{
|
|
307
|
-
name: '
|
|
341
|
+
name: 'NewAddressParams',
|
|
308
342
|
type: {
|
|
309
343
|
kind: 'struct',
|
|
310
344
|
fields: [
|
|
311
345
|
{
|
|
312
|
-
name: '
|
|
313
|
-
type:
|
|
346
|
+
name: 'seed',
|
|
347
|
+
type: {
|
|
348
|
+
array: ['u8', 32],
|
|
349
|
+
},
|
|
314
350
|
},
|
|
315
351
|
{
|
|
316
|
-
name: '
|
|
317
|
-
type: '
|
|
352
|
+
name: 'addressQueuePubkey',
|
|
353
|
+
type: 'publicKey',
|
|
318
354
|
},
|
|
319
355
|
{
|
|
320
|
-
name: '
|
|
321
|
-
type:
|
|
322
|
-
option: {
|
|
323
|
-
array: ['u8', 32],
|
|
324
|
-
},
|
|
325
|
-
},
|
|
356
|
+
name: 'addressMerkleTreePubkey',
|
|
357
|
+
type: 'publicKey',
|
|
326
358
|
},
|
|
327
359
|
{
|
|
328
|
-
name: '
|
|
329
|
-
type:
|
|
330
|
-
option: {
|
|
331
|
-
defined: 'CompressedAccountData',
|
|
332
|
-
},
|
|
333
|
-
},
|
|
360
|
+
name: 'addressMerkleTreeRootIndex',
|
|
361
|
+
type: 'u16',
|
|
334
362
|
},
|
|
335
363
|
],
|
|
336
364
|
},
|
|
337
365
|
},
|
|
338
366
|
{
|
|
339
|
-
name: '
|
|
367
|
+
name: 'CompressedProof',
|
|
340
368
|
type: {
|
|
341
369
|
kind: 'struct',
|
|
342
370
|
fields: [
|
|
343
371
|
{
|
|
344
|
-
name: '
|
|
372
|
+
name: 'a',
|
|
345
373
|
type: {
|
|
346
|
-
array: ['u8',
|
|
374
|
+
array: ['u8', 32],
|
|
347
375
|
},
|
|
348
376
|
},
|
|
349
377
|
{
|
|
350
|
-
name: '
|
|
351
|
-
type:
|
|
378
|
+
name: 'b',
|
|
379
|
+
type: {
|
|
380
|
+
array: ['u8', 64],
|
|
381
|
+
},
|
|
352
382
|
},
|
|
353
383
|
{
|
|
354
|
-
name: '
|
|
384
|
+
name: 'c',
|
|
355
385
|
type: {
|
|
356
386
|
array: ['u8', 32],
|
|
357
387
|
},
|
|
@@ -360,57 +390,37 @@ const IDL = {
|
|
|
360
390
|
},
|
|
361
391
|
},
|
|
362
392
|
{
|
|
363
|
-
name: '
|
|
364
|
-
docs: ['To spend multiple compressed'],
|
|
393
|
+
name: 'InstructionDataInvokeCpi',
|
|
365
394
|
type: {
|
|
366
395
|
kind: 'struct',
|
|
367
396
|
fields: [
|
|
368
397
|
{
|
|
369
|
-
name: '
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
398
|
+
name: 'proof',
|
|
399
|
+
type: {
|
|
400
|
+
option: {
|
|
401
|
+
defined: 'CompressedProof',
|
|
402
|
+
},
|
|
403
|
+
},
|
|
375
404
|
},
|
|
376
405
|
{
|
|
377
|
-
name: '
|
|
378
|
-
docs: [
|
|
379
|
-
'The final cpi of your program needs to set execute to true.',
|
|
380
|
-
'Execute compressed transaction will verify the proof and execute the transaction if this is true.',
|
|
381
|
-
'If this is false the transaction will be stored in the cpi signature account.',
|
|
382
|
-
],
|
|
383
|
-
type: 'bool',
|
|
384
|
-
},
|
|
385
|
-
],
|
|
386
|
-
},
|
|
387
|
-
},
|
|
388
|
-
{
|
|
389
|
-
name: 'PublicTransactionEvent',
|
|
390
|
-
type: {
|
|
391
|
-
kind: 'struct',
|
|
392
|
-
fields: [
|
|
393
|
-
{
|
|
394
|
-
name: 'inputCompressedAccountHashes',
|
|
406
|
+
name: 'newAddressParams',
|
|
395
407
|
type: {
|
|
396
408
|
vec: {
|
|
397
|
-
|
|
409
|
+
defined: 'NewAddressParamsPacked',
|
|
398
410
|
},
|
|
399
411
|
},
|
|
400
412
|
},
|
|
401
413
|
{
|
|
402
|
-
name: '
|
|
414
|
+
name: 'inputRootIndices',
|
|
403
415
|
type: {
|
|
404
|
-
vec:
|
|
405
|
-
array: ['u8', 32],
|
|
406
|
-
},
|
|
416
|
+
vec: 'u16',
|
|
407
417
|
},
|
|
408
418
|
},
|
|
409
419
|
{
|
|
410
|
-
name: '
|
|
420
|
+
name: 'inputCompressedAccountsWithMerkleContext',
|
|
411
421
|
type: {
|
|
412
422
|
vec: {
|
|
413
|
-
defined: '
|
|
423
|
+
defined: 'PackedCompressedAccountWithMerkleContext',
|
|
414
424
|
},
|
|
415
425
|
},
|
|
416
426
|
},
|
|
@@ -424,16 +434,19 @@ const IDL = {
|
|
|
424
434
|
},
|
|
425
435
|
{
|
|
426
436
|
name: 'outputStateMerkleTreeAccountIndices',
|
|
437
|
+
docs: [
|
|
438
|
+
'The indices of the accounts in the output state merkle tree.',
|
|
439
|
+
],
|
|
427
440
|
type: 'bytes',
|
|
428
441
|
},
|
|
429
442
|
{
|
|
430
|
-
name: '
|
|
443
|
+
name: 'relayFee',
|
|
431
444
|
type: {
|
|
432
|
-
|
|
445
|
+
option: 'u64',
|
|
433
446
|
},
|
|
434
447
|
},
|
|
435
448
|
{
|
|
436
|
-
name: '
|
|
449
|
+
name: 'compressionLamports',
|
|
437
450
|
type: {
|
|
438
451
|
option: 'u64',
|
|
439
452
|
},
|
|
@@ -443,178 +456,241 @@ const IDL = {
|
|
|
443
456
|
type: 'bool',
|
|
444
457
|
},
|
|
445
458
|
{
|
|
446
|
-
name: '
|
|
447
|
-
type: {
|
|
448
|
-
option: 'u64',
|
|
449
|
-
},
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
name: 'pubkeyArray',
|
|
459
|
+
name: 'signerSeeds',
|
|
453
460
|
type: {
|
|
454
|
-
vec: '
|
|
461
|
+
vec: 'bytes',
|
|
455
462
|
},
|
|
456
463
|
},
|
|
457
464
|
{
|
|
458
|
-
name: '
|
|
465
|
+
name: 'cpiContext',
|
|
459
466
|
type: {
|
|
460
|
-
option:
|
|
467
|
+
option: {
|
|
468
|
+
defined: 'CompressedCpiContext',
|
|
469
|
+
},
|
|
461
470
|
},
|
|
462
471
|
},
|
|
463
472
|
],
|
|
464
473
|
},
|
|
465
474
|
},
|
|
466
475
|
{
|
|
467
|
-
name: '
|
|
476
|
+
name: 'PackedCompressedAccountWithMerkleContext',
|
|
468
477
|
type: {
|
|
469
478
|
kind: 'struct',
|
|
470
479
|
fields: [
|
|
471
480
|
{
|
|
472
|
-
name: '
|
|
481
|
+
name: 'compressedAccount',
|
|
473
482
|
type: {
|
|
474
|
-
|
|
475
|
-
defined: 'CompressedProof',
|
|
476
|
-
},
|
|
483
|
+
defined: 'CompressedAccount',
|
|
477
484
|
},
|
|
478
485
|
},
|
|
479
486
|
{
|
|
480
|
-
name: '
|
|
487
|
+
name: 'merkleContext',
|
|
481
488
|
type: {
|
|
482
|
-
|
|
483
|
-
defined: 'NewAddressParamsPacked',
|
|
484
|
-
},
|
|
489
|
+
defined: 'PackedMerkleContext',
|
|
485
490
|
},
|
|
486
491
|
},
|
|
492
|
+
],
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
name: 'CompressedAccountWithMerkleContext',
|
|
497
|
+
type: {
|
|
498
|
+
kind: 'struct',
|
|
499
|
+
fields: [
|
|
487
500
|
{
|
|
488
|
-
name: '
|
|
501
|
+
name: 'compressedAccount',
|
|
489
502
|
type: {
|
|
490
|
-
|
|
503
|
+
defined: 'CompressedAccount',
|
|
491
504
|
},
|
|
492
505
|
},
|
|
493
506
|
{
|
|
494
|
-
name: '
|
|
507
|
+
name: 'merkleContext',
|
|
495
508
|
type: {
|
|
496
|
-
|
|
497
|
-
defined: 'CompressedAccountWithMerkleContext',
|
|
498
|
-
},
|
|
509
|
+
defined: 'MerkleContext',
|
|
499
510
|
},
|
|
500
511
|
},
|
|
512
|
+
],
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
name: 'MerkleContext',
|
|
517
|
+
type: {
|
|
518
|
+
kind: 'struct',
|
|
519
|
+
fields: [
|
|
501
520
|
{
|
|
502
|
-
name: '
|
|
503
|
-
type:
|
|
504
|
-
vec: {
|
|
505
|
-
defined: 'CompressedAccount',
|
|
506
|
-
},
|
|
507
|
-
},
|
|
521
|
+
name: 'merkleTreePubkey',
|
|
522
|
+
type: 'publicKey',
|
|
508
523
|
},
|
|
509
524
|
{
|
|
510
|
-
name: '
|
|
511
|
-
|
|
512
|
-
'The indices of the accounts in the output state merkle tree.',
|
|
513
|
-
],
|
|
514
|
-
type: 'bytes',
|
|
525
|
+
name: 'nullifierQueuePubkey',
|
|
526
|
+
type: 'publicKey',
|
|
515
527
|
},
|
|
516
528
|
{
|
|
517
|
-
name: '
|
|
518
|
-
type:
|
|
519
|
-
option: 'u64',
|
|
520
|
-
},
|
|
529
|
+
name: 'leafIndex',
|
|
530
|
+
type: 'u32',
|
|
521
531
|
},
|
|
532
|
+
],
|
|
533
|
+
},
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
name: 'PackedMerkleContext',
|
|
537
|
+
type: {
|
|
538
|
+
kind: 'struct',
|
|
539
|
+
fields: [
|
|
522
540
|
{
|
|
523
|
-
name: '
|
|
524
|
-
type:
|
|
525
|
-
option: 'u64',
|
|
526
|
-
},
|
|
541
|
+
name: 'merkleTreePubkeyIndex',
|
|
542
|
+
type: 'u8',
|
|
527
543
|
},
|
|
528
544
|
{
|
|
529
|
-
name: '
|
|
530
|
-
type: '
|
|
545
|
+
name: 'nullifierQueuePubkeyIndex',
|
|
546
|
+
type: 'u8',
|
|
531
547
|
},
|
|
532
548
|
{
|
|
533
|
-
name: '
|
|
534
|
-
type:
|
|
535
|
-
option: {
|
|
536
|
-
vec: 'bytes',
|
|
537
|
-
},
|
|
538
|
-
},
|
|
549
|
+
name: 'leafIndex',
|
|
550
|
+
type: 'u32',
|
|
539
551
|
},
|
|
540
552
|
],
|
|
541
553
|
},
|
|
542
554
|
},
|
|
543
555
|
{
|
|
544
|
-
name: '
|
|
556
|
+
name: 'CompressedAccount',
|
|
545
557
|
type: {
|
|
546
558
|
kind: 'struct',
|
|
547
559
|
fields: [
|
|
548
560
|
{
|
|
549
|
-
name: '
|
|
550
|
-
type:
|
|
551
|
-
array: ['u8', 32],
|
|
552
|
-
},
|
|
561
|
+
name: 'owner',
|
|
562
|
+
type: 'publicKey',
|
|
553
563
|
},
|
|
554
564
|
{
|
|
555
|
-
name: '
|
|
556
|
-
type: '
|
|
565
|
+
name: 'lamports',
|
|
566
|
+
type: 'u64',
|
|
557
567
|
},
|
|
558
568
|
{
|
|
559
|
-
name: '
|
|
560
|
-
type:
|
|
569
|
+
name: 'address',
|
|
570
|
+
type: {
|
|
571
|
+
option: {
|
|
572
|
+
array: ['u8', 32],
|
|
573
|
+
},
|
|
574
|
+
},
|
|
561
575
|
},
|
|
562
576
|
{
|
|
563
|
-
name: '
|
|
564
|
-
type:
|
|
577
|
+
name: 'data',
|
|
578
|
+
type: {
|
|
579
|
+
option: {
|
|
580
|
+
defined: 'CompressedAccountData',
|
|
581
|
+
},
|
|
582
|
+
},
|
|
565
583
|
},
|
|
566
584
|
],
|
|
567
585
|
},
|
|
568
586
|
},
|
|
569
587
|
{
|
|
570
|
-
name: '
|
|
588
|
+
name: 'CompressedAccountData',
|
|
571
589
|
type: {
|
|
572
590
|
kind: 'struct',
|
|
573
591
|
fields: [
|
|
574
592
|
{
|
|
575
|
-
name: '
|
|
593
|
+
name: 'discriminator',
|
|
576
594
|
type: {
|
|
577
|
-
array: ['u8',
|
|
595
|
+
array: ['u8', 8],
|
|
578
596
|
},
|
|
579
597
|
},
|
|
580
598
|
{
|
|
581
|
-
name: '
|
|
582
|
-
type: '
|
|
583
|
-
},
|
|
584
|
-
{
|
|
585
|
-
name: 'addressMerkleTreePubkey',
|
|
586
|
-
type: 'publicKey',
|
|
599
|
+
name: 'data',
|
|
600
|
+
type: 'bytes',
|
|
587
601
|
},
|
|
588
602
|
{
|
|
589
|
-
name: '
|
|
590
|
-
type:
|
|
603
|
+
name: 'dataHash',
|
|
604
|
+
type: {
|
|
605
|
+
array: ['u8', 32],
|
|
606
|
+
},
|
|
591
607
|
},
|
|
592
608
|
],
|
|
593
609
|
},
|
|
594
610
|
},
|
|
595
611
|
{
|
|
596
|
-
name: '
|
|
612
|
+
name: 'PublicTransactionEvent',
|
|
597
613
|
type: {
|
|
598
614
|
kind: 'struct',
|
|
599
615
|
fields: [
|
|
600
616
|
{
|
|
601
|
-
name: '
|
|
617
|
+
name: 'inputCompressedAccountHashes',
|
|
602
618
|
type: {
|
|
603
|
-
|
|
619
|
+
vec: {
|
|
620
|
+
array: ['u8', 32],
|
|
621
|
+
},
|
|
604
622
|
},
|
|
605
623
|
},
|
|
606
624
|
{
|
|
607
|
-
name: '
|
|
625
|
+
name: 'outputCompressedAccountHashes',
|
|
608
626
|
type: {
|
|
609
|
-
|
|
627
|
+
vec: {
|
|
628
|
+
array: ['u8', 32],
|
|
629
|
+
},
|
|
610
630
|
},
|
|
611
631
|
},
|
|
612
632
|
{
|
|
613
|
-
name: '
|
|
633
|
+
name: 'outputCompressedAccounts',
|
|
614
634
|
type: {
|
|
615
|
-
|
|
635
|
+
vec: {
|
|
636
|
+
defined: 'CompressedAccount',
|
|
637
|
+
},
|
|
616
638
|
},
|
|
617
639
|
},
|
|
640
|
+
{
|
|
641
|
+
name: 'outputStateMerkleTreeAccountIndices',
|
|
642
|
+
type: 'bytes',
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
name: 'outputLeafIndices',
|
|
646
|
+
type: {
|
|
647
|
+
vec: 'u32',
|
|
648
|
+
},
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
name: 'relayFee',
|
|
652
|
+
type: {
|
|
653
|
+
option: 'u64',
|
|
654
|
+
},
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
name: 'isCompress',
|
|
658
|
+
type: 'bool',
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
name: 'compressionLamports',
|
|
662
|
+
type: {
|
|
663
|
+
option: 'u64',
|
|
664
|
+
},
|
|
665
|
+
},
|
|
666
|
+
{
|
|
667
|
+
name: 'pubkeyArray',
|
|
668
|
+
type: {
|
|
669
|
+
vec: 'publicKey',
|
|
670
|
+
},
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
name: 'message',
|
|
674
|
+
type: {
|
|
675
|
+
option: 'bytes',
|
|
676
|
+
},
|
|
677
|
+
},
|
|
678
|
+
],
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
name: 'CompressedCpiContext',
|
|
683
|
+
type: {
|
|
684
|
+
kind: 'struct',
|
|
685
|
+
fields: [
|
|
686
|
+
{
|
|
687
|
+
name: 'setContext',
|
|
688
|
+
type: 'bool',
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
name: 'cpiContextAccountIndex',
|
|
692
|
+
type: 'u8',
|
|
693
|
+
},
|
|
618
694
|
],
|
|
619
695
|
},
|
|
620
696
|
},
|
|
@@ -646,16 +722,10 @@ const IDL = {
|
|
|
646
722
|
},
|
|
647
723
|
},
|
|
648
724
|
{
|
|
649
|
-
name: '
|
|
650
|
-
type:
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
name: 'nullifierQueuePubkeyIndex',
|
|
654
|
-
type: 'u8',
|
|
655
|
-
},
|
|
656
|
-
{
|
|
657
|
-
name: 'leafIndex',
|
|
658
|
-
type: 'u32',
|
|
725
|
+
name: 'merkleContext',
|
|
726
|
+
type: {
|
|
727
|
+
defined: 'PackedMerkleContext',
|
|
728
|
+
},
|
|
659
729
|
},
|
|
660
730
|
],
|
|
661
731
|
},
|
|
@@ -717,90 +787,41 @@ const IDL = {
|
|
|
717
787
|
option: 'u64',
|
|
718
788
|
},
|
|
719
789
|
},
|
|
720
|
-
],
|
|
721
|
-
},
|
|
722
|
-
},
|
|
723
|
-
{
|
|
724
|
-
name: 'TokenTransferOutputData',
|
|
725
|
-
type: {
|
|
726
|
-
kind: 'struct',
|
|
727
|
-
fields: [
|
|
728
|
-
{
|
|
729
|
-
name: 'owner',
|
|
730
|
-
type: 'publicKey',
|
|
731
|
-
},
|
|
732
|
-
{
|
|
733
|
-
name: 'amount',
|
|
734
|
-
type: 'u64',
|
|
735
|
-
},
|
|
736
790
|
{
|
|
737
|
-
name: '
|
|
791
|
+
name: 'cpiContext',
|
|
738
792
|
type: {
|
|
739
|
-
option:
|
|
793
|
+
option: {
|
|
794
|
+
defined: 'CompressedCpiContext',
|
|
795
|
+
},
|
|
740
796
|
},
|
|
741
797
|
},
|
|
742
798
|
],
|
|
743
799
|
},
|
|
744
800
|
},
|
|
745
801
|
{
|
|
746
|
-
name: '
|
|
747
|
-
type: {
|
|
748
|
-
kind: 'struct',
|
|
749
|
-
fields: [
|
|
750
|
-
{
|
|
751
|
-
name: '
|
|
752
|
-
|
|
753
|
-
type: 'publicKey',
|
|
754
|
-
},
|
|
755
|
-
{
|
|
756
|
-
name: 'owner',
|
|
757
|
-
docs: ['The owner of this account.'],
|
|
758
|
-
type: 'publicKey',
|
|
759
|
-
},
|
|
760
|
-
{
|
|
761
|
-
name: 'amount',
|
|
762
|
-
docs: ['The amount of tokens this account holds.'],
|
|
763
|
-
type: 'u64',
|
|
764
|
-
},
|
|
765
|
-
{
|
|
766
|
-
name: 'delegate',
|
|
767
|
-
docs: [
|
|
768
|
-
'If `delegate` is `Some` then `delegated_amount` represents',
|
|
769
|
-
'the amount authorized by the delegate',
|
|
770
|
-
],
|
|
771
|
-
type: {
|
|
772
|
-
option: 'publicKey',
|
|
773
|
-
},
|
|
802
|
+
name: 'TokenTransferOutputData',
|
|
803
|
+
type: {
|
|
804
|
+
kind: 'struct',
|
|
805
|
+
fields: [
|
|
806
|
+
{
|
|
807
|
+
name: 'owner',
|
|
808
|
+
type: 'publicKey',
|
|
774
809
|
},
|
|
775
810
|
{
|
|
776
|
-
name: '
|
|
777
|
-
|
|
778
|
-
type: {
|
|
779
|
-
defined: 'AccountState',
|
|
780
|
-
},
|
|
811
|
+
name: 'amount',
|
|
812
|
+
type: 'u64',
|
|
781
813
|
},
|
|
782
814
|
{
|
|
783
|
-
name: '
|
|
784
|
-
docs: [
|
|
785
|
-
'If is_some, this is a native token, and the value logs the rent-exempt',
|
|
786
|
-
'reserve. An Account is required to be rent-exempt, so the value is',
|
|
787
|
-
'used by the Processor to ensure that wrapped SOL accounts do not',
|
|
788
|
-
'drop below this threshold.',
|
|
789
|
-
],
|
|
815
|
+
name: 'lamports',
|
|
790
816
|
type: {
|
|
791
817
|
option: 'u64',
|
|
792
818
|
},
|
|
793
819
|
},
|
|
794
|
-
{
|
|
795
|
-
name: 'delegatedAmount',
|
|
796
|
-
docs: ['The amount delegated'],
|
|
797
|
-
type: 'u64',
|
|
798
|
-
},
|
|
799
820
|
],
|
|
800
821
|
},
|
|
801
822
|
},
|
|
802
823
|
{
|
|
803
|
-
name: '
|
|
824
|
+
name: 'TokenData',
|
|
804
825
|
type: {
|
|
805
826
|
kind: 'struct',
|
|
806
827
|
fields: [
|
|
@@ -832,7 +853,9 @@ const IDL = {
|
|
|
832
853
|
{
|
|
833
854
|
name: 'state',
|
|
834
855
|
docs: ["The account's state"],
|
|
835
|
-
type:
|
|
856
|
+
type: {
|
|
857
|
+
defined: 'AccountState',
|
|
858
|
+
},
|
|
836
859
|
},
|
|
837
860
|
{
|
|
838
861
|
name: 'isNative',
|
|
@@ -859,9 +882,6 @@ const IDL = {
|
|
|
859
882
|
type: {
|
|
860
883
|
kind: 'enum',
|
|
861
884
|
variants: [
|
|
862
|
-
{
|
|
863
|
-
name: 'Uninitialized',
|
|
864
|
-
},
|
|
865
885
|
{
|
|
866
886
|
name: 'Initialized',
|
|
867
887
|
},
|
|
@@ -965,9 +985,11 @@ function packCompressedTokenAccounts(params) {
|
|
|
965
985
|
? null
|
|
966
986
|
: account.parsed.delegatedAmount,
|
|
967
987
|
isNative: account.parsed.isNative,
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
988
|
+
merkleContext: {
|
|
989
|
+
merkleTreePubkeyIndex,
|
|
990
|
+
nullifierQueuePubkeyIndex,
|
|
991
|
+
leafIndex: account.compressedAccount.leafIndex,
|
|
992
|
+
},
|
|
971
993
|
});
|
|
972
994
|
});
|
|
973
995
|
/// pack output state trees
|
|
@@ -1000,7 +1022,7 @@ const TOKEN_PROGRAM_ID = new web3_js.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf
|
|
|
1000
1022
|
/** Address of the SPL Token 2022 program */
|
|
1001
1023
|
new web3_js.PublicKey('TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb');
|
|
1002
1024
|
/** Address of the SPL Associated Token Account program */
|
|
1003
|
-
new web3_js.PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
1025
|
+
const ASSOCIATED_TOKEN_PROGRAM_ID = new web3_js.PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
1004
1026
|
/** Address of the special mint for wrapped native SOL in spl-token */
|
|
1005
1027
|
new web3_js.PublicKey('So11111111111111111111111111111111111111112');
|
|
1006
1028
|
/** Address of the special mint for wrapped native SOL in spl-token-2022 */
|
|
@@ -3295,334 +3317,16 @@ const encodeDecode = (layout) => {
|
|
|
3295
3317
|
return { decode, encode };
|
|
3296
3318
|
};
|
|
3297
3319
|
|
|
3298
|
-
var
|
|
3299
|
-
|
|
3300
|
-
function commonjsRequire(path) {
|
|
3301
|
-
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
3302
|
-
}
|
|
3303
|
-
|
|
3304
|
-
var bindings = {exports: {}};
|
|
3305
|
-
|
|
3306
|
-
var fileUriToPath_1;
|
|
3307
|
-
var hasRequiredFileUriToPath;
|
|
3308
|
-
|
|
3309
|
-
function requireFileUriToPath () {
|
|
3310
|
-
if (hasRequiredFileUriToPath) return fileUriToPath_1;
|
|
3311
|
-
hasRequiredFileUriToPath = 1;
|
|
3312
|
-
/**
|
|
3313
|
-
* Module dependencies.
|
|
3314
|
-
*/
|
|
3315
|
-
|
|
3316
|
-
var sep = require$$0$1.sep || '/';
|
|
3317
|
-
|
|
3318
|
-
/**
|
|
3319
|
-
* Module exports.
|
|
3320
|
-
*/
|
|
3321
|
-
|
|
3322
|
-
fileUriToPath_1 = fileUriToPath;
|
|
3323
|
-
|
|
3324
|
-
/**
|
|
3325
|
-
* File URI to Path function.
|
|
3326
|
-
*
|
|
3327
|
-
* @param {String} uri
|
|
3328
|
-
* @return {String} path
|
|
3329
|
-
* @api public
|
|
3330
|
-
*/
|
|
3331
|
-
|
|
3332
|
-
function fileUriToPath (uri) {
|
|
3333
|
-
if ('string' != typeof uri ||
|
|
3334
|
-
uri.length <= 7 ||
|
|
3335
|
-
'file://' != uri.substring(0, 7)) {
|
|
3336
|
-
throw new TypeError('must pass in a file:// URI to convert to a file path');
|
|
3337
|
-
}
|
|
3338
|
-
|
|
3339
|
-
var rest = decodeURI(uri.substring(7));
|
|
3340
|
-
var firstSlash = rest.indexOf('/');
|
|
3341
|
-
var host = rest.substring(0, firstSlash);
|
|
3342
|
-
var path = rest.substring(firstSlash + 1);
|
|
3343
|
-
|
|
3344
|
-
// 2. Scheme Definition
|
|
3345
|
-
// As a special case, <host> can be the string "localhost" or the empty
|
|
3346
|
-
// string; this is interpreted as "the machine from which the URL is
|
|
3347
|
-
// being interpreted".
|
|
3348
|
-
if ('localhost' == host) host = '';
|
|
3349
|
-
|
|
3350
|
-
if (host) {
|
|
3351
|
-
host = sep + sep + host;
|
|
3352
|
-
}
|
|
3353
|
-
|
|
3354
|
-
// 3.2 Drives, drive letters, mount points, file system root
|
|
3355
|
-
// Drive letters are mapped into the top of a file URI in various ways,
|
|
3356
|
-
// depending on the implementation; some applications substitute
|
|
3357
|
-
// vertical bar ("|") for the colon after the drive letter, yielding
|
|
3358
|
-
// "file:///c|/tmp/test.txt". In some cases, the colon is left
|
|
3359
|
-
// unchanged, as in "file:///c:/tmp/test.txt". In other cases, the
|
|
3360
|
-
// colon is simply omitted, as in "file:///c/tmp/test.txt".
|
|
3361
|
-
path = path.replace(/^(.+)\|/, '$1:');
|
|
3362
|
-
|
|
3363
|
-
// for Windows, we need to invert the path separators from what a URI uses
|
|
3364
|
-
if (sep == '\\') {
|
|
3365
|
-
path = path.replace(/\//g, '\\');
|
|
3366
|
-
}
|
|
3367
|
-
|
|
3368
|
-
if (/^.+\:/.test(path)) ; else {
|
|
3369
|
-
// unix path…
|
|
3370
|
-
path = sep + path;
|
|
3371
|
-
}
|
|
3372
|
-
|
|
3373
|
-
return host + path;
|
|
3374
|
-
}
|
|
3375
|
-
return fileUriToPath_1;
|
|
3376
|
-
}
|
|
3377
|
-
|
|
3378
|
-
/**
|
|
3379
|
-
* Module dependencies.
|
|
3380
|
-
*/
|
|
3381
|
-
|
|
3382
|
-
var hasRequiredBindings;
|
|
3383
|
-
|
|
3384
|
-
function requireBindings () {
|
|
3385
|
-
if (hasRequiredBindings) return bindings.exports;
|
|
3386
|
-
hasRequiredBindings = 1;
|
|
3387
|
-
(function (module, exports) {
|
|
3388
|
-
var fs = require$$0$2,
|
|
3389
|
-
path = require$$0$1,
|
|
3390
|
-
fileURLToPath = requireFileUriToPath(),
|
|
3391
|
-
join = path.join,
|
|
3392
|
-
dirname = path.dirname,
|
|
3393
|
-
exists =
|
|
3394
|
-
(fs.accessSync &&
|
|
3395
|
-
function(path) {
|
|
3396
|
-
try {
|
|
3397
|
-
fs.accessSync(path);
|
|
3398
|
-
} catch (e) {
|
|
3399
|
-
return false;
|
|
3400
|
-
}
|
|
3401
|
-
return true;
|
|
3402
|
-
}) ||
|
|
3403
|
-
fs.existsSync ||
|
|
3404
|
-
path.existsSync,
|
|
3405
|
-
defaults = {
|
|
3406
|
-
arrow: process.env.NODE_BINDINGS_ARROW || ' → ',
|
|
3407
|
-
compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled',
|
|
3408
|
-
platform: process.platform,
|
|
3409
|
-
arch: process.arch,
|
|
3410
|
-
nodePreGyp:
|
|
3411
|
-
'node-v' +
|
|
3412
|
-
process.versions.modules +
|
|
3413
|
-
'-' +
|
|
3414
|
-
process.platform +
|
|
3415
|
-
'-' +
|
|
3416
|
-
process.arch,
|
|
3417
|
-
version: process.versions.node,
|
|
3418
|
-
bindings: 'bindings.node',
|
|
3419
|
-
try: [
|
|
3420
|
-
// node-gyp's linked version in the "build" dir
|
|
3421
|
-
['module_root', 'build', 'bindings'],
|
|
3422
|
-
// node-waf and gyp_addon (a.k.a node-gyp)
|
|
3423
|
-
['module_root', 'build', 'Debug', 'bindings'],
|
|
3424
|
-
['module_root', 'build', 'Release', 'bindings'],
|
|
3425
|
-
// Debug files, for development (legacy behavior, remove for node v0.9)
|
|
3426
|
-
['module_root', 'out', 'Debug', 'bindings'],
|
|
3427
|
-
['module_root', 'Debug', 'bindings'],
|
|
3428
|
-
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
|
|
3429
|
-
['module_root', 'out', 'Release', 'bindings'],
|
|
3430
|
-
['module_root', 'Release', 'bindings'],
|
|
3431
|
-
// Legacy from node-waf, node <= 0.4.x
|
|
3432
|
-
['module_root', 'build', 'default', 'bindings'],
|
|
3433
|
-
// Production "Release" buildtype binary (meh...)
|
|
3434
|
-
['module_root', 'compiled', 'version', 'platform', 'arch', 'bindings'],
|
|
3435
|
-
// node-qbs builds
|
|
3436
|
-
['module_root', 'addon-build', 'release', 'install-root', 'bindings'],
|
|
3437
|
-
['module_root', 'addon-build', 'debug', 'install-root', 'bindings'],
|
|
3438
|
-
['module_root', 'addon-build', 'default', 'install-root', 'bindings'],
|
|
3439
|
-
// node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
|
|
3440
|
-
['module_root', 'lib', 'binding', 'nodePreGyp', 'bindings']
|
|
3441
|
-
]
|
|
3442
|
-
};
|
|
3443
|
-
|
|
3444
|
-
/**
|
|
3445
|
-
* The main `bindings()` function loads the compiled bindings for a given module.
|
|
3446
|
-
* It uses V8's Error API to determine the parent filename that this function is
|
|
3447
|
-
* being invoked from, which is then used to find the root directory.
|
|
3448
|
-
*/
|
|
3449
|
-
|
|
3450
|
-
function bindings(opts) {
|
|
3451
|
-
// Argument surgery
|
|
3452
|
-
if (typeof opts == 'string') {
|
|
3453
|
-
opts = { bindings: opts };
|
|
3454
|
-
} else if (!opts) {
|
|
3455
|
-
opts = {};
|
|
3456
|
-
}
|
|
3457
|
-
|
|
3458
|
-
// maps `defaults` onto `opts` object
|
|
3459
|
-
Object.keys(defaults).map(function(i) {
|
|
3460
|
-
if (!(i in opts)) opts[i] = defaults[i];
|
|
3461
|
-
});
|
|
3462
|
-
|
|
3463
|
-
// Get the module root
|
|
3464
|
-
if (!opts.module_root) {
|
|
3465
|
-
opts.module_root = exports.getRoot(exports.getFileName());
|
|
3466
|
-
}
|
|
3467
|
-
|
|
3468
|
-
// Ensure the given bindings name ends with .node
|
|
3469
|
-
if (path.extname(opts.bindings) != '.node') {
|
|
3470
|
-
opts.bindings += '.node';
|
|
3471
|
-
}
|
|
3472
|
-
|
|
3473
|
-
// https://github.com/webpack/webpack/issues/4175#issuecomment-342931035
|
|
3474
|
-
var requireFunc =
|
|
3475
|
-
typeof __webpack_require__ === 'function'
|
|
3476
|
-
? __non_webpack_require__
|
|
3477
|
-
: commonjsRequire;
|
|
3320
|
+
var browser = {};
|
|
3478
3321
|
|
|
3479
|
-
|
|
3480
|
-
i = 0,
|
|
3481
|
-
l = opts.try.length,
|
|
3482
|
-
n,
|
|
3483
|
-
b,
|
|
3484
|
-
err;
|
|
3485
|
-
|
|
3486
|
-
for (; i < l; i++) {
|
|
3487
|
-
n = join.apply(
|
|
3488
|
-
null,
|
|
3489
|
-
opts.try[i].map(function(p) {
|
|
3490
|
-
return opts[p] || p;
|
|
3491
|
-
})
|
|
3492
|
-
);
|
|
3493
|
-
tries.push(n);
|
|
3494
|
-
try {
|
|
3495
|
-
b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
|
|
3496
|
-
if (!opts.path) {
|
|
3497
|
-
b.path = n;
|
|
3498
|
-
}
|
|
3499
|
-
return b;
|
|
3500
|
-
} catch (e) {
|
|
3501
|
-
if (e.code !== 'MODULE_NOT_FOUND' &&
|
|
3502
|
-
e.code !== 'QUALIFIED_PATH_RESOLUTION_FAILED' &&
|
|
3503
|
-
!/not find/i.test(e.message)) {
|
|
3504
|
-
throw e;
|
|
3505
|
-
}
|
|
3506
|
-
}
|
|
3507
|
-
}
|
|
3508
|
-
|
|
3509
|
-
err = new Error(
|
|
3510
|
-
'Could not locate the bindings file. Tried:\n' +
|
|
3511
|
-
tries
|
|
3512
|
-
.map(function(a) {
|
|
3513
|
-
return opts.arrow + a;
|
|
3514
|
-
})
|
|
3515
|
-
.join('\n')
|
|
3516
|
-
);
|
|
3517
|
-
err.tries = tries;
|
|
3518
|
-
throw err;
|
|
3519
|
-
}
|
|
3520
|
-
module.exports = exports = bindings;
|
|
3521
|
-
|
|
3522
|
-
/**
|
|
3523
|
-
* Gets the filename of the JavaScript file that invokes this function.
|
|
3524
|
-
* Used to help find the root directory of a module.
|
|
3525
|
-
* Optionally accepts an filename argument to skip when searching for the invoking filename
|
|
3526
|
-
*/
|
|
3527
|
-
|
|
3528
|
-
exports.getFileName = function getFileName(calling_file) {
|
|
3529
|
-
var origPST = Error.prepareStackTrace,
|
|
3530
|
-
origSTL = Error.stackTraceLimit,
|
|
3531
|
-
dummy = {},
|
|
3532
|
-
fileName;
|
|
3533
|
-
|
|
3534
|
-
Error.stackTraceLimit = 10;
|
|
3535
|
-
|
|
3536
|
-
Error.prepareStackTrace = function(e, st) {
|
|
3537
|
-
for (var i = 0, l = st.length; i < l; i++) {
|
|
3538
|
-
fileName = st[i].getFileName();
|
|
3539
|
-
if (fileName !== __filename) {
|
|
3540
|
-
if (calling_file) {
|
|
3541
|
-
if (fileName !== calling_file) {
|
|
3542
|
-
return;
|
|
3543
|
-
}
|
|
3544
|
-
} else {
|
|
3545
|
-
return;
|
|
3546
|
-
}
|
|
3547
|
-
}
|
|
3548
|
-
}
|
|
3549
|
-
};
|
|
3550
|
-
|
|
3551
|
-
// run the 'prepareStackTrace' function above
|
|
3552
|
-
Error.captureStackTrace(dummy);
|
|
3553
|
-
dummy.stack;
|
|
3554
|
-
|
|
3555
|
-
// cleanup
|
|
3556
|
-
Error.prepareStackTrace = origPST;
|
|
3557
|
-
Error.stackTraceLimit = origSTL;
|
|
3558
|
-
|
|
3559
|
-
// handle filename that starts with "file://"
|
|
3560
|
-
var fileSchema = 'file://';
|
|
3561
|
-
if (fileName.indexOf(fileSchema) === 0) {
|
|
3562
|
-
fileName = fileURLToPath(fileName);
|
|
3563
|
-
}
|
|
3564
|
-
|
|
3565
|
-
return fileName;
|
|
3566
|
-
};
|
|
3567
|
-
|
|
3568
|
-
/**
|
|
3569
|
-
* Gets the root directory of a module, given an arbitrary filename
|
|
3570
|
-
* somewhere in the module tree. The "root directory" is the directory
|
|
3571
|
-
* containing the `package.json` file.
|
|
3572
|
-
*
|
|
3573
|
-
* In: /home/nate/node-native-module/lib/index.js
|
|
3574
|
-
* Out: /home/nate/node-native-module
|
|
3575
|
-
*/
|
|
3576
|
-
|
|
3577
|
-
exports.getRoot = function getRoot(file) {
|
|
3578
|
-
var dir = dirname(file),
|
|
3579
|
-
prev;
|
|
3580
|
-
while (true) {
|
|
3581
|
-
if (dir === '.') {
|
|
3582
|
-
// Avoids an infinite loop in rare cases, like the REPL
|
|
3583
|
-
dir = process.cwd();
|
|
3584
|
-
}
|
|
3585
|
-
if (
|
|
3586
|
-
exists(join(dir, 'package.json')) ||
|
|
3587
|
-
exists(join(dir, 'node_modules'))
|
|
3588
|
-
) {
|
|
3589
|
-
// Found the 'package.json' file or 'node_modules' dir; we're done
|
|
3590
|
-
return dir;
|
|
3591
|
-
}
|
|
3592
|
-
if (prev === dir) {
|
|
3593
|
-
// Got to the top
|
|
3594
|
-
throw new Error(
|
|
3595
|
-
'Could not find module root given file: "' +
|
|
3596
|
-
file +
|
|
3597
|
-
'". Do you have a `package.json` file? '
|
|
3598
|
-
);
|
|
3599
|
-
}
|
|
3600
|
-
// Try the parent dir next
|
|
3601
|
-
prev = dir;
|
|
3602
|
-
dir = join(dir, '..');
|
|
3603
|
-
}
|
|
3604
|
-
};
|
|
3605
|
-
} (bindings, bindings.exports));
|
|
3606
|
-
return bindings.exports;
|
|
3607
|
-
}
|
|
3608
|
-
|
|
3609
|
-
Object.defineProperty(node, "__esModule", { value: true });
|
|
3610
|
-
let converter;
|
|
3611
|
-
{
|
|
3612
|
-
try {
|
|
3613
|
-
converter = requireBindings()('bigint_buffer');
|
|
3614
|
-
}
|
|
3615
|
-
catch (e) {
|
|
3616
|
-
console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
|
|
3617
|
-
}
|
|
3618
|
-
}
|
|
3322
|
+
Object.defineProperty(browser, "__esModule", { value: true });
|
|
3619
3323
|
/**
|
|
3620
3324
|
* Convert a little-endian buffer into a BigInt.
|
|
3621
3325
|
* @param buf The little-endian buffer to convert
|
|
3622
3326
|
* @returns A BigInt with the little-endian representation of buf.
|
|
3623
3327
|
*/
|
|
3624
3328
|
function toBigIntLE(buf) {
|
|
3625
|
-
|
|
3329
|
+
{
|
|
3626
3330
|
const reversed = Buffer.from(buf);
|
|
3627
3331
|
reversed.reverse();
|
|
3628
3332
|
const hex = reversed.toString('hex');
|
|
@@ -3631,25 +3335,23 @@ function toBigIntLE(buf) {
|
|
|
3631
3335
|
}
|
|
3632
3336
|
return BigInt(`0x${hex}`);
|
|
3633
3337
|
}
|
|
3634
|
-
return converter.toBigInt(buf, false);
|
|
3635
3338
|
}
|
|
3636
|
-
var toBigIntLE_1 =
|
|
3339
|
+
var toBigIntLE_1 = browser.toBigIntLE = toBigIntLE;
|
|
3637
3340
|
/**
|
|
3638
3341
|
* Convert a big-endian buffer into a BigInt
|
|
3639
3342
|
* @param buf The big-endian buffer to convert.
|
|
3640
3343
|
* @returns A BigInt with the big-endian representation of buf.
|
|
3641
3344
|
*/
|
|
3642
3345
|
function toBigIntBE(buf) {
|
|
3643
|
-
|
|
3346
|
+
{
|
|
3644
3347
|
const hex = buf.toString('hex');
|
|
3645
3348
|
if (hex.length === 0) {
|
|
3646
3349
|
return BigInt(0);
|
|
3647
3350
|
}
|
|
3648
3351
|
return BigInt(`0x${hex}`);
|
|
3649
3352
|
}
|
|
3650
|
-
return converter.toBigInt(buf, true);
|
|
3651
3353
|
}
|
|
3652
|
-
|
|
3354
|
+
browser.toBigIntBE = toBigIntBE;
|
|
3653
3355
|
/**
|
|
3654
3356
|
* Convert a BigInt to a little-endian buffer.
|
|
3655
3357
|
* @param num The BigInt to convert.
|
|
@@ -3657,16 +3359,14 @@ node.toBigIntBE = toBigIntBE;
|
|
|
3657
3359
|
* @returns A little-endian buffer representation of num.
|
|
3658
3360
|
*/
|
|
3659
3361
|
function toBufferLE(num, width) {
|
|
3660
|
-
|
|
3362
|
+
{
|
|
3661
3363
|
const hex = num.toString(16);
|
|
3662
3364
|
const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
3663
3365
|
buffer.reverse();
|
|
3664
3366
|
return buffer;
|
|
3665
3367
|
}
|
|
3666
|
-
// Allocation is done here, since it is slower using napi in C
|
|
3667
|
-
return converter.fromBigInt(num, Buffer.allocUnsafe(width), false);
|
|
3668
3368
|
}
|
|
3669
|
-
var toBufferLE_1 =
|
|
3369
|
+
var toBufferLE_1 = browser.toBufferLE = toBufferLE;
|
|
3670
3370
|
/**
|
|
3671
3371
|
* Convert a BigInt to a big-endian buffer.
|
|
3672
3372
|
* @param num The BigInt to convert.
|
|
@@ -3674,13 +3374,12 @@ var toBufferLE_1 = node.toBufferLE = toBufferLE;
|
|
|
3674
3374
|
* @returns A big-endian buffer representation of num.
|
|
3675
3375
|
*/
|
|
3676
3376
|
function toBufferBE(num, width) {
|
|
3677
|
-
|
|
3377
|
+
{
|
|
3678
3378
|
const hex = num.toString(16);
|
|
3679
3379
|
return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
3680
3380
|
}
|
|
3681
|
-
return converter.fromBigInt(num, Buffer.allocUnsafe(width), true);
|
|
3682
3381
|
}
|
|
3683
|
-
|
|
3382
|
+
browser.toBufferBE = toBufferBE;
|
|
3684
3383
|
|
|
3685
3384
|
const bigInt = (length) => (property) => {
|
|
3686
3385
|
const layout = blob(length, property);
|
|
@@ -3728,6 +3427,62 @@ const publicKey = (property) => {
|
|
|
3728
3427
|
return publicKeyLayout;
|
|
3729
3428
|
};
|
|
3730
3429
|
|
|
3430
|
+
/** Base class for errors */
|
|
3431
|
+
class TokenError extends Error {
|
|
3432
|
+
constructor(message) {
|
|
3433
|
+
super(message);
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
/** Thrown if an account is not found at the expected address */
|
|
3437
|
+
class TokenAccountNotFoundError extends TokenError {
|
|
3438
|
+
constructor() {
|
|
3439
|
+
super(...arguments);
|
|
3440
|
+
this.name = 'TokenAccountNotFoundError';
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
/** Thrown if a program state account is not a valid Account */
|
|
3444
|
+
class TokenInvalidAccountError extends TokenError {
|
|
3445
|
+
constructor() {
|
|
3446
|
+
super(...arguments);
|
|
3447
|
+
this.name = 'TokenInvalidAccountError';
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
/** Thrown if a program state account is not owned by the expected token program */
|
|
3451
|
+
class TokenInvalidAccountOwnerError extends TokenError {
|
|
3452
|
+
constructor() {
|
|
3453
|
+
super(...arguments);
|
|
3454
|
+
this.name = 'TokenInvalidAccountOwnerError';
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
/** Thrown if the byte length of an program state account doesn't match the expected size */
|
|
3458
|
+
class TokenInvalidAccountSizeError extends TokenError {
|
|
3459
|
+
constructor() {
|
|
3460
|
+
super(...arguments);
|
|
3461
|
+
this.name = 'TokenInvalidAccountSizeError';
|
|
3462
|
+
}
|
|
3463
|
+
}
|
|
3464
|
+
/** Thrown if the mint of a token account doesn't match the expected mint */
|
|
3465
|
+
class TokenInvalidMintError extends TokenError {
|
|
3466
|
+
constructor() {
|
|
3467
|
+
super(...arguments);
|
|
3468
|
+
this.name = 'TokenInvalidMintError';
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
/** Thrown if the owner of a token account doesn't match the expected owner */
|
|
3472
|
+
class TokenInvalidOwnerError extends TokenError {
|
|
3473
|
+
constructor() {
|
|
3474
|
+
super(...arguments);
|
|
3475
|
+
this.name = 'TokenInvalidOwnerError';
|
|
3476
|
+
}
|
|
3477
|
+
}
|
|
3478
|
+
/** Thrown if the owner of a token account is a PDA (Program Derived Address) */
|
|
3479
|
+
class TokenOwnerOffCurveError extends TokenError {
|
|
3480
|
+
constructor() {
|
|
3481
|
+
super(...arguments);
|
|
3482
|
+
this.name = 'TokenOwnerOffCurveError';
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
|
|
3731
3486
|
/** Instructions defined by the program */
|
|
3732
3487
|
var TokenInstruction;
|
|
3733
3488
|
(function (TokenInstruction) {
|
|
@@ -3767,6 +3522,10 @@ var TokenInstruction;
|
|
|
3767
3522
|
TokenInstruction[TokenInstruction["InterestBearingMintExtension"] = 33] = "InterestBearingMintExtension";
|
|
3768
3523
|
TokenInstruction[TokenInstruction["CpiGuardExtension"] = 34] = "CpiGuardExtension";
|
|
3769
3524
|
TokenInstruction[TokenInstruction["InitializePermanentDelegate"] = 35] = "InitializePermanentDelegate";
|
|
3525
|
+
TokenInstruction[TokenInstruction["TransferHookExtension"] = 36] = "TransferHookExtension";
|
|
3526
|
+
// ConfidentialTransferFeeExtension = 37,
|
|
3527
|
+
// WithdrawalExcessLamports = 38,
|
|
3528
|
+
TokenInstruction[TokenInstruction["MetadataPointerExtension"] = 39] = "MetadataPointerExtension";
|
|
3770
3529
|
})(TokenInstruction || (TokenInstruction = {}));
|
|
3771
3530
|
|
|
3772
3531
|
/** @internal */
|
|
@@ -3814,6 +3573,112 @@ function createApproveInstruction(account, delegate, owner, amount, multiSigners
|
|
|
3814
3573
|
return new web3_js.TransactionInstruction({ keys, programId, data });
|
|
3815
3574
|
}
|
|
3816
3575
|
|
|
3576
|
+
var AccountType;
|
|
3577
|
+
(function (AccountType) {
|
|
3578
|
+
AccountType[AccountType["Uninitialized"] = 0] = "Uninitialized";
|
|
3579
|
+
AccountType[AccountType["Mint"] = 1] = "Mint";
|
|
3580
|
+
AccountType[AccountType["Account"] = 2] = "Account";
|
|
3581
|
+
})(AccountType || (AccountType = {}));
|
|
3582
|
+
const ACCOUNT_TYPE_SIZE = 1;
|
|
3583
|
+
|
|
3584
|
+
/** Buffer layout for de/serializing a multisig */
|
|
3585
|
+
const MultisigLayout = struct([
|
|
3586
|
+
u8('m'),
|
|
3587
|
+
u8('n'),
|
|
3588
|
+
bool('isInitialized'),
|
|
3589
|
+
publicKey('signer1'),
|
|
3590
|
+
publicKey('signer2'),
|
|
3591
|
+
publicKey('signer3'),
|
|
3592
|
+
publicKey('signer4'),
|
|
3593
|
+
publicKey('signer5'),
|
|
3594
|
+
publicKey('signer6'),
|
|
3595
|
+
publicKey('signer7'),
|
|
3596
|
+
publicKey('signer8'),
|
|
3597
|
+
publicKey('signer9'),
|
|
3598
|
+
publicKey('signer10'),
|
|
3599
|
+
publicKey('signer11'),
|
|
3600
|
+
]);
|
|
3601
|
+
/** Byte length of a multisig */
|
|
3602
|
+
const MULTISIG_SIZE = MultisigLayout.span;
|
|
3603
|
+
|
|
3604
|
+
/** Token account state as stored by the program */
|
|
3605
|
+
var AccountState;
|
|
3606
|
+
(function (AccountState) {
|
|
3607
|
+
AccountState[AccountState["Uninitialized"] = 0] = "Uninitialized";
|
|
3608
|
+
AccountState[AccountState["Initialized"] = 1] = "Initialized";
|
|
3609
|
+
AccountState[AccountState["Frozen"] = 2] = "Frozen";
|
|
3610
|
+
})(AccountState || (AccountState = {}));
|
|
3611
|
+
/** Buffer layout for de/serializing a token account */
|
|
3612
|
+
const AccountLayout = struct([
|
|
3613
|
+
publicKey('mint'),
|
|
3614
|
+
publicKey('owner'),
|
|
3615
|
+
u64('amount'),
|
|
3616
|
+
u32('delegateOption'),
|
|
3617
|
+
publicKey('delegate'),
|
|
3618
|
+
u8('state'),
|
|
3619
|
+
u32('isNativeOption'),
|
|
3620
|
+
u64('isNative'),
|
|
3621
|
+
u64('delegatedAmount'),
|
|
3622
|
+
u32('closeAuthorityOption'),
|
|
3623
|
+
publicKey('closeAuthority'),
|
|
3624
|
+
]);
|
|
3625
|
+
/** Byte length of a token account */
|
|
3626
|
+
const ACCOUNT_SIZE = AccountLayout.span;
|
|
3627
|
+
/**
|
|
3628
|
+
* Retrieve information about a token account
|
|
3629
|
+
*
|
|
3630
|
+
* @param connection Connection to use
|
|
3631
|
+
* @param address Token account
|
|
3632
|
+
* @param commitment Desired level of commitment for querying the state
|
|
3633
|
+
* @param programId SPL Token program account
|
|
3634
|
+
*
|
|
3635
|
+
* @return Token account information
|
|
3636
|
+
*/
|
|
3637
|
+
async function getAccount(connection, address, commitment, programId = TOKEN_PROGRAM_ID) {
|
|
3638
|
+
const info = await connection.getAccountInfo(address, commitment);
|
|
3639
|
+
return unpackAccount(address, info, programId);
|
|
3640
|
+
}
|
|
3641
|
+
/**
|
|
3642
|
+
* Unpack a token account
|
|
3643
|
+
*
|
|
3644
|
+
* @param address Token account
|
|
3645
|
+
* @param info Token account data
|
|
3646
|
+
* @param programId SPL Token program account
|
|
3647
|
+
*
|
|
3648
|
+
* @return Unpacked token account
|
|
3649
|
+
*/
|
|
3650
|
+
function unpackAccount(address, info, programId = TOKEN_PROGRAM_ID) {
|
|
3651
|
+
if (!info)
|
|
3652
|
+
throw new TokenAccountNotFoundError();
|
|
3653
|
+
if (!info.owner.equals(programId))
|
|
3654
|
+
throw new TokenInvalidAccountOwnerError();
|
|
3655
|
+
if (info.data.length < ACCOUNT_SIZE)
|
|
3656
|
+
throw new TokenInvalidAccountSizeError();
|
|
3657
|
+
const rawAccount = AccountLayout.decode(info.data.slice(0, ACCOUNT_SIZE));
|
|
3658
|
+
let tlvData = Buffer.alloc(0);
|
|
3659
|
+
if (info.data.length > ACCOUNT_SIZE) {
|
|
3660
|
+
if (info.data.length === MULTISIG_SIZE)
|
|
3661
|
+
throw new TokenInvalidAccountSizeError();
|
|
3662
|
+
if (info.data[ACCOUNT_SIZE] != AccountType.Account)
|
|
3663
|
+
throw new TokenInvalidAccountError();
|
|
3664
|
+
tlvData = info.data.slice(ACCOUNT_SIZE + ACCOUNT_TYPE_SIZE);
|
|
3665
|
+
}
|
|
3666
|
+
return {
|
|
3667
|
+
address,
|
|
3668
|
+
mint: rawAccount.mint,
|
|
3669
|
+
owner: rawAccount.owner,
|
|
3670
|
+
amount: rawAccount.amount,
|
|
3671
|
+
delegate: rawAccount.delegateOption ? rawAccount.delegate : null,
|
|
3672
|
+
delegatedAmount: rawAccount.delegatedAmount,
|
|
3673
|
+
isInitialized: rawAccount.state !== AccountState.Uninitialized,
|
|
3674
|
+
isFrozen: rawAccount.state === AccountState.Frozen,
|
|
3675
|
+
isNative: !!rawAccount.isNativeOption,
|
|
3676
|
+
rentExemptReserve: rawAccount.isNativeOption ? rawAccount.isNative : null,
|
|
3677
|
+
closeAuthority: rawAccount.closeAuthorityOption ? rawAccount.closeAuthority : null,
|
|
3678
|
+
tlvData,
|
|
3679
|
+
};
|
|
3680
|
+
}
|
|
3681
|
+
|
|
3817
3682
|
/** Buffer layout for de/serializing a mint */
|
|
3818
3683
|
const MintLayout = struct([
|
|
3819
3684
|
u32('mintAuthorityOption'),
|
|
@@ -3826,6 +3691,54 @@ const MintLayout = struct([
|
|
|
3826
3691
|
]);
|
|
3827
3692
|
/** Byte length of a mint */
|
|
3828
3693
|
const MINT_SIZE = MintLayout.span;
|
|
3694
|
+
/**
|
|
3695
|
+
* Get the address of the associated token account for a given mint and owner
|
|
3696
|
+
*
|
|
3697
|
+
* @param mint Token mint account
|
|
3698
|
+
* @param owner Owner of the new account
|
|
3699
|
+
* @param allowOwnerOffCurve Allow the owner account to be a PDA (Program Derived Address)
|
|
3700
|
+
* @param programId SPL Token program account
|
|
3701
|
+
* @param associatedTokenProgramId SPL Associated Token program account
|
|
3702
|
+
*
|
|
3703
|
+
* @return Address of the associated token account
|
|
3704
|
+
*/
|
|
3705
|
+
function getAssociatedTokenAddressSync(mint, owner, allowOwnerOffCurve = false, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
3706
|
+
if (!allowOwnerOffCurve && !web3_js.PublicKey.isOnCurve(owner.toBuffer()))
|
|
3707
|
+
throw new TokenOwnerOffCurveError();
|
|
3708
|
+
const [address] = web3_js.PublicKey.findProgramAddressSync([owner.toBuffer(), programId.toBuffer(), mint.toBuffer()], associatedTokenProgramId);
|
|
3709
|
+
return address;
|
|
3710
|
+
}
|
|
3711
|
+
|
|
3712
|
+
/**
|
|
3713
|
+
* Construct a CreateAssociatedTokenAccount instruction
|
|
3714
|
+
*
|
|
3715
|
+
* @param payer Payer of the initialization fees
|
|
3716
|
+
* @param associatedToken New associated token account
|
|
3717
|
+
* @param owner Owner of the new account
|
|
3718
|
+
* @param mint Token mint account
|
|
3719
|
+
* @param programId SPL Token program account
|
|
3720
|
+
* @param associatedTokenProgramId SPL Associated Token program account
|
|
3721
|
+
*
|
|
3722
|
+
* @return Instruction to add to a transaction
|
|
3723
|
+
*/
|
|
3724
|
+
function createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
3725
|
+
return buildAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, Buffer.alloc(0), programId, associatedTokenProgramId);
|
|
3726
|
+
}
|
|
3727
|
+
function buildAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, instructionData, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
3728
|
+
const keys = [
|
|
3729
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
3730
|
+
{ pubkey: associatedToken, isSigner: false, isWritable: true },
|
|
3731
|
+
{ pubkey: owner, isSigner: false, isWritable: false },
|
|
3732
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
3733
|
+
{ pubkey: web3_js.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
3734
|
+
{ pubkey: programId, isSigner: false, isWritable: false },
|
|
3735
|
+
];
|
|
3736
|
+
return new web3_js.TransactionInstruction({
|
|
3737
|
+
keys,
|
|
3738
|
+
programId: associatedTokenProgramId,
|
|
3739
|
+
data: instructionData,
|
|
3740
|
+
});
|
|
3741
|
+
}
|
|
3829
3742
|
|
|
3830
3743
|
/** TODO: docs */
|
|
3831
3744
|
const initializeMint2InstructionData = struct([
|
|
@@ -3859,10 +3772,94 @@ function createInitializeMint2Instruction(mint, decimals, mintAuthority, freezeA
|
|
|
3859
3772
|
return new web3_js.TransactionInstruction({ keys, programId, data });
|
|
3860
3773
|
}
|
|
3861
3774
|
|
|
3775
|
+
/**
|
|
3776
|
+
* Retrieve the associated token account, or create it if it doesn't exist
|
|
3777
|
+
*
|
|
3778
|
+
* @param connection Connection to use
|
|
3779
|
+
* @param payer Payer of the transaction and initialization fees
|
|
3780
|
+
* @param mint Mint associated with the account to set or verify
|
|
3781
|
+
* @param owner Owner of the account to set or verify
|
|
3782
|
+
* @param allowOwnerOffCurve Allow the owner account to be a PDA (Program Derived Address)
|
|
3783
|
+
* @param commitment Desired level of commitment for querying the state
|
|
3784
|
+
* @param confirmOptions Options for confirming the transaction
|
|
3785
|
+
* @param programId SPL Token program account
|
|
3786
|
+
* @param associatedTokenProgramId SPL Associated Token program account
|
|
3787
|
+
*
|
|
3788
|
+
* @return Address of the new associated token account
|
|
3789
|
+
*/
|
|
3790
|
+
async function getOrCreateAssociatedTokenAccount(connection, payer, mint, owner, allowOwnerOffCurve = false, commitment, confirmOptions, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
3791
|
+
const associatedToken = getAssociatedTokenAddressSync(mint, owner, allowOwnerOffCurve, programId, associatedTokenProgramId);
|
|
3792
|
+
// This is the optimal logic, considering TX fee, client-side computation, RPC roundtrips and guaranteed idempotent.
|
|
3793
|
+
// Sadly we can't do this atomically.
|
|
3794
|
+
let account;
|
|
3795
|
+
try {
|
|
3796
|
+
account = await getAccount(connection, associatedToken, commitment, programId);
|
|
3797
|
+
}
|
|
3798
|
+
catch (error) {
|
|
3799
|
+
// TokenAccountNotFoundError can be possible if the associated address has already received some lamports,
|
|
3800
|
+
// becoming a system account. Assuming program derived addressing is safe, this is the only case for the
|
|
3801
|
+
// TokenInvalidAccountOwnerError in this code path.
|
|
3802
|
+
if (error instanceof TokenAccountNotFoundError || error instanceof TokenInvalidAccountOwnerError) {
|
|
3803
|
+
// As this isn't atomic, it's possible others can create associated accounts meanwhile.
|
|
3804
|
+
try {
|
|
3805
|
+
const transaction = new web3_js.Transaction().add(createAssociatedTokenAccountInstruction(payer.publicKey, associatedToken, owner, mint, programId, associatedTokenProgramId));
|
|
3806
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer], confirmOptions);
|
|
3807
|
+
}
|
|
3808
|
+
catch (error) {
|
|
3809
|
+
// Ignore all errors; for now there is no API-compatible way to selectively ignore the expected
|
|
3810
|
+
// instruction error if the associated account exists already.
|
|
3811
|
+
}
|
|
3812
|
+
// Now this should always succeed
|
|
3813
|
+
account = await getAccount(connection, associatedToken, commitment, programId);
|
|
3814
|
+
}
|
|
3815
|
+
else {
|
|
3816
|
+
throw error;
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
if (!account.mint.equals(mint))
|
|
3820
|
+
throw new TokenInvalidMintError();
|
|
3821
|
+
if (!account.owner.equals(owner))
|
|
3822
|
+
throw new TokenInvalidOwnerError();
|
|
3823
|
+
return account;
|
|
3824
|
+
}
|
|
3825
|
+
|
|
3826
|
+
/** TODO: docs */
|
|
3827
|
+
const mintToInstructionData = struct([u8('instruction'), u64('amount')]);
|
|
3828
|
+
/**
|
|
3829
|
+
* Construct a MintTo instruction
|
|
3830
|
+
*
|
|
3831
|
+
* @param mint Public key of the mint
|
|
3832
|
+
* @param destination Address of the token account to mint to
|
|
3833
|
+
* @param authority The mint authority
|
|
3834
|
+
* @param amount Amount to mint
|
|
3835
|
+
* @param multiSigners Signing accounts if `authority` is a multisig
|
|
3836
|
+
* @param programId SPL Token program account
|
|
3837
|
+
*
|
|
3838
|
+
* @return Instruction to add to a transaction
|
|
3839
|
+
*/
|
|
3840
|
+
function createMintToInstruction(mint, destination, authority, amount, multiSigners = [], programId = TOKEN_PROGRAM_ID) {
|
|
3841
|
+
const keys = addSigners([
|
|
3842
|
+
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
3843
|
+
{ pubkey: destination, isSigner: false, isWritable: true },
|
|
3844
|
+
], authority, multiSigners);
|
|
3845
|
+
const data = Buffer.alloc(mintToInstructionData.span);
|
|
3846
|
+
mintToInstructionData.encode({
|
|
3847
|
+
instruction: TokenInstruction.MintTo,
|
|
3848
|
+
amount: BigInt(amount),
|
|
3849
|
+
}, data);
|
|
3850
|
+
return new web3_js.TransactionInstruction({ keys, programId, data });
|
|
3851
|
+
}
|
|
3852
|
+
|
|
3862
3853
|
var _a;
|
|
3854
|
+
/**
|
|
3855
|
+
* Sum up the token amounts of the compressed token accounts
|
|
3856
|
+
*/
|
|
3863
3857
|
const sumUpTokenAmount = (accounts) => {
|
|
3864
3858
|
return accounts.reduce((acc, account) => acc.add(account.parsed.amount), stateless_js.bn(0));
|
|
3865
3859
|
};
|
|
3860
|
+
/**
|
|
3861
|
+
* Validate that all the compressed token accounts are owned by the same owner.
|
|
3862
|
+
*/
|
|
3866
3863
|
const validateSameTokenOwner = (accounts) => {
|
|
3867
3864
|
const owner = accounts[0].parsed.owner;
|
|
3868
3865
|
accounts.forEach(acc => {
|
|
@@ -3871,12 +3868,23 @@ const validateSameTokenOwner = (accounts) => {
|
|
|
3871
3868
|
}
|
|
3872
3869
|
});
|
|
3873
3870
|
};
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3871
|
+
/**
|
|
3872
|
+
* Parse compressed token accounts to get the mint, current owner and delegate.
|
|
3873
|
+
*/
|
|
3874
|
+
const parseTokenData = (compressedTokenAccounts) => {
|
|
3875
|
+
const mint = compressedTokenAccounts[0].parsed.mint;
|
|
3876
|
+
const currentOwner = compressedTokenAccounts[0].parsed.owner;
|
|
3877
|
+
const delegate = compressedTokenAccounts[0].parsed.delegate;
|
|
3878
3878
|
return { mint, currentOwner, delegate };
|
|
3879
3879
|
};
|
|
3880
|
+
/**
|
|
3881
|
+
* Create the output state for a transfer transaction.
|
|
3882
|
+
* @param inputCompressedTokenAccounts Input state
|
|
3883
|
+
* @param toAddress Recipient address
|
|
3884
|
+
* @param amount Amount of tokens to transfer
|
|
3885
|
+
* @returns Output token data for the transfer
|
|
3886
|
+
* instruction
|
|
3887
|
+
*/
|
|
3880
3888
|
function createTransferOutputState(inputCompressedTokenAccounts, toAddress, amount) {
|
|
3881
3889
|
amount = stateless_js.bn(amount);
|
|
3882
3890
|
const inputAmount = sumUpTokenAmount(inputCompressedTokenAccounts);
|
|
@@ -3909,6 +3917,13 @@ function createTransferOutputState(inputCompressedTokenAccounts, toAddress, amou
|
|
|
3909
3917
|
];
|
|
3910
3918
|
return outputCompressedAccounts;
|
|
3911
3919
|
}
|
|
3920
|
+
/**
|
|
3921
|
+
* Create the output state for a compress transaction.
|
|
3922
|
+
* @param inputCompressedTokenAccounts Input state
|
|
3923
|
+
* @param amount Amount of tokens to compress
|
|
3924
|
+
* @returns Output token data for the compress
|
|
3925
|
+
* instruction
|
|
3926
|
+
*/
|
|
3912
3927
|
function createDecompressOutputState(inputCompressedTokenAccounts, amount) {
|
|
3913
3928
|
amount = stateless_js.bn(amount);
|
|
3914
3929
|
const inputLamports = stateless_js.sumUpLamports(inputCompressedTokenAccounts.map(acc => acc.compressedAccount));
|
|
@@ -3935,6 +3950,7 @@ class CompressedTokenProgram {
|
|
|
3935
3950
|
* @internal
|
|
3936
3951
|
*/
|
|
3937
3952
|
constructor() { }
|
|
3953
|
+
/** @internal */
|
|
3938
3954
|
static get program() {
|
|
3939
3955
|
if (!this._program) {
|
|
3940
3956
|
this.initializeProgram();
|
|
@@ -3942,12 +3958,14 @@ class CompressedTokenProgram {
|
|
|
3942
3958
|
return this._program;
|
|
3943
3959
|
}
|
|
3944
3960
|
/**
|
|
3961
|
+
* @internal
|
|
3945
3962
|
* Initializes the program statically if not already initialized.
|
|
3946
3963
|
*/
|
|
3947
3964
|
static initializeProgram() {
|
|
3948
3965
|
if (!this._program) {
|
|
3949
|
-
/// We can use a mock connection because we're using the
|
|
3950
|
-
/// serde and building instructions, not for
|
|
3966
|
+
/// Note: We can use a mock connection because we're using the
|
|
3967
|
+
/// program only for serde and building instructions, not for
|
|
3968
|
+
/// interacting with the network.
|
|
3951
3969
|
const mockKeypair = web3_js.Keypair.generate();
|
|
3952
3970
|
const mockConnection = new web3_js.Connection('http://127.0.0.1:8899', 'confirmed');
|
|
3953
3971
|
const mockProvider = new anchor.AnchorProvider(mockConnection, stateless_js.useWallet(mockKeypair), stateless_js.confirmConfig);
|
|
@@ -3966,8 +3984,12 @@ class CompressedTokenProgram {
|
|
|
3966
3984
|
const [address, _] = web3_js.PublicKey.findProgramAddressSync([CPI_AUTHORITY_SEED], this.programId);
|
|
3967
3985
|
return address;
|
|
3968
3986
|
}
|
|
3987
|
+
/**
|
|
3988
|
+
* Construct createMint instruction for compressed tokens
|
|
3989
|
+
*/
|
|
3969
3990
|
static async createMint(params) {
|
|
3970
3991
|
const { mint, authority, feePayer, rentExemptBalance } = params;
|
|
3992
|
+
/// Create and initialize SPL Mint account
|
|
3971
3993
|
const createMintAccountInstruction = web3_js.SystemProgram.createAccount({
|
|
3972
3994
|
fromPubkey: feePayer,
|
|
3973
3995
|
lamports: rentExemptBalance,
|
|
@@ -3975,14 +3997,17 @@ class CompressedTokenProgram {
|
|
|
3975
3997
|
programId: TOKEN_PROGRAM_ID,
|
|
3976
3998
|
space: MINT_SIZE,
|
|
3977
3999
|
});
|
|
3978
|
-
const mintAuthorityPda = this.deriveMintAuthorityPda(authority, mint);
|
|
4000
|
+
const [mintAuthorityPda] = this.deriveMintAuthorityPda(authority, mint);
|
|
3979
4001
|
const initializeMintInstruction = createInitializeMint2Instruction(mint, params.decimals, mintAuthorityPda, params.freezeAuthority, TOKEN_PROGRAM_ID);
|
|
4002
|
+
/// Fund the mint authority PDA. The authority is system-owned in order
|
|
4003
|
+
/// to natively mint compressed tokens.
|
|
3980
4004
|
const fundAuthorityPdaInstruction = web3_js.SystemProgram.transfer({
|
|
3981
4005
|
fromPubkey: feePayer,
|
|
3982
4006
|
toPubkey: mintAuthorityPda,
|
|
3983
|
-
lamports: rentExemptBalance,
|
|
4007
|
+
lamports: rentExemptBalance,
|
|
3984
4008
|
});
|
|
3985
4009
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
4010
|
+
/// Create omnibus compressed mint account
|
|
3986
4011
|
const ix = await this.program.methods
|
|
3987
4012
|
.createMint()
|
|
3988
4013
|
.accounts({
|
|
@@ -4003,15 +4028,41 @@ class CompressedTokenProgram {
|
|
|
4003
4028
|
ix,
|
|
4004
4029
|
];
|
|
4005
4030
|
}
|
|
4031
|
+
/**
|
|
4032
|
+
* Enable compression for an existing SPL mint, creating an omnibus account.
|
|
4033
|
+
* For new mints, use `CompressedTokenProgram.createMint`.
|
|
4034
|
+
*/
|
|
4035
|
+
static async registerMint(params) {
|
|
4036
|
+
const { mint, authority, feePayer } = params;
|
|
4037
|
+
const [mintAuthorityPda] = this.deriveMintAuthorityPda(authority, mint);
|
|
4038
|
+
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
4039
|
+
const ix = await this.program.methods
|
|
4040
|
+
.createMint()
|
|
4041
|
+
.accounts({
|
|
4042
|
+
mint,
|
|
4043
|
+
feePayer,
|
|
4044
|
+
authority,
|
|
4045
|
+
tokenPoolPda,
|
|
4046
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
4047
|
+
mintAuthorityPda,
|
|
4048
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
4049
|
+
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
4050
|
+
})
|
|
4051
|
+
.instruction();
|
|
4052
|
+
return [ix];
|
|
4053
|
+
}
|
|
4054
|
+
/**
|
|
4055
|
+
* Construct mintTo instruction for compressed tokens
|
|
4056
|
+
*/
|
|
4006
4057
|
static async mintTo(params) {
|
|
4007
4058
|
const systemKeys = stateless_js.defaultStaticAccountsStruct();
|
|
4008
4059
|
const { mint, feePayer, authority, merkleTree, toPubkey, amount } = params;
|
|
4009
4060
|
const tokenPoolPda = this.deriveTokenPoolPda(mint);
|
|
4010
|
-
const mintAuthorityPda = this.deriveMintAuthorityPda(authority, mint);
|
|
4061
|
+
const [mintAuthorityPda, bump] = this.deriveMintAuthorityPda(authority, mint);
|
|
4011
4062
|
const amounts = stateless_js.toArray(amount).map(amount => stateless_js.bn(amount));
|
|
4012
4063
|
const toPubkeys = stateless_js.toArray(toPubkey);
|
|
4013
|
-
const
|
|
4014
|
-
.mintTo(toPubkeys, amounts)
|
|
4064
|
+
const instruction = await this.program.methods
|
|
4065
|
+
.mintTo(toPubkeys, amounts, bump)
|
|
4015
4066
|
.accounts({
|
|
4016
4067
|
feePayer,
|
|
4017
4068
|
authority,
|
|
@@ -4019,7 +4070,7 @@ class CompressedTokenProgram {
|
|
|
4019
4070
|
mint,
|
|
4020
4071
|
tokenPoolPda,
|
|
4021
4072
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
4022
|
-
|
|
4073
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
4023
4074
|
registeredProgramPda: systemKeys.registeredProgramPda,
|
|
4024
4075
|
noopProgram: systemKeys.noopProgram,
|
|
4025
4076
|
accountCompressionAuthority: systemKeys.accountCompressionAuthority,
|
|
@@ -4028,18 +4079,43 @@ class CompressedTokenProgram {
|
|
|
4028
4079
|
selfProgram: this.programId,
|
|
4029
4080
|
})
|
|
4030
4081
|
.instruction();
|
|
4031
|
-
return
|
|
4082
|
+
return instruction;
|
|
4083
|
+
}
|
|
4084
|
+
/// TODO: add compressBatch functionality for batch minting
|
|
4085
|
+
/**
|
|
4086
|
+
* Mint tokens from registed SPL mint account to a compressed account
|
|
4087
|
+
*/
|
|
4088
|
+
static async approveAndMintTo(params) {
|
|
4089
|
+
const { mint, feePayer, authorityTokenAccount, authority, merkleTree, toPubkey, } = params;
|
|
4090
|
+
const amount = BigInt(params.amount.toString());
|
|
4091
|
+
/// 1. Mint to mint authority ATA
|
|
4092
|
+
const splMintToInstruction = createMintToInstruction(mint, authorityTokenAccount, authority, amount);
|
|
4093
|
+
/// 2. Compressed token program mintTo
|
|
4094
|
+
const approveInstruction = createApproveInstruction(authorityTokenAccount, this.deriveCpiAuthorityPda, authority, amount);
|
|
4095
|
+
/// 3. Compress from mint authority ATA to recipient compressed account
|
|
4096
|
+
const ixs = await this.compress({
|
|
4097
|
+
payer: feePayer,
|
|
4098
|
+
owner: authority,
|
|
4099
|
+
source: authorityTokenAccount,
|
|
4100
|
+
toAddress: toPubkey,
|
|
4101
|
+
mint,
|
|
4102
|
+
amount: stateless_js.bn(amount.toString()),
|
|
4103
|
+
outputStateTree: merkleTree,
|
|
4104
|
+
});
|
|
4105
|
+
return [splMintToInstruction, approveInstruction, ...ixs];
|
|
4032
4106
|
}
|
|
4107
|
+
/**
|
|
4108
|
+
* Construct transfer instruction for compressed tokens
|
|
4109
|
+
*/
|
|
4033
4110
|
static async transfer(params) {
|
|
4034
4111
|
const { payer, inputCompressedTokenAccounts, recentInputStateRootIndices, recentValidityProof, amount, outputStateTrees, toAddress, } = params;
|
|
4035
4112
|
const outputCompressedAccounts = createTransferOutputState(inputCompressedTokenAccounts, toAddress, amount);
|
|
4036
|
-
/// Pack
|
|
4037
4113
|
const { inputTokenDataWithContext, outputStateMerkleTreeIndices, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
4038
4114
|
inputCompressedTokenAccounts,
|
|
4039
4115
|
outputCompressedAccountsLength: outputCompressedAccounts.length,
|
|
4040
4116
|
outputStateTrees,
|
|
4041
4117
|
});
|
|
4042
|
-
const { mint, currentOwner } =
|
|
4118
|
+
const { mint, currentOwner } = parseTokenData(inputCompressedTokenAccounts);
|
|
4043
4119
|
const data = {
|
|
4044
4120
|
proof: recentValidityProof,
|
|
4045
4121
|
rootIndices: recentInputStateRootIndices,
|
|
@@ -4050,16 +4126,17 @@ class CompressedTokenProgram {
|
|
|
4050
4126
|
outputStateMerkleTreeAccountIndices: require$$0.Buffer.from(outputStateMerkleTreeIndices),
|
|
4051
4127
|
compressionAmount: null,
|
|
4052
4128
|
isCompress: false,
|
|
4129
|
+
cpiContext: null,
|
|
4053
4130
|
};
|
|
4054
4131
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
4055
4132
|
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
4056
4133
|
const instruction = await this.program.methods
|
|
4057
|
-
.transfer(encodedData
|
|
4134
|
+
.transfer(encodedData)
|
|
4058
4135
|
.accounts({
|
|
4059
4136
|
feePayer: payer,
|
|
4060
4137
|
authority: currentOwner,
|
|
4061
4138
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
4062
|
-
|
|
4139
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
4063
4140
|
registeredProgramPda: registeredProgramPda,
|
|
4064
4141
|
noopProgram: noopProgram,
|
|
4065
4142
|
accountCompressionAuthority: accountCompressionAuthority,
|
|
@@ -4071,11 +4148,12 @@ class CompressedTokenProgram {
|
|
|
4071
4148
|
})
|
|
4072
4149
|
.remainingAccounts(remainingAccountMetas)
|
|
4073
4150
|
.instruction();
|
|
4074
|
-
return
|
|
4075
|
-
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
4076
|
-
instruction,
|
|
4077
|
-
];
|
|
4151
|
+
return instruction;
|
|
4078
4152
|
}
|
|
4153
|
+
/**
|
|
4154
|
+
* Construct approve and compress instructions
|
|
4155
|
+
* @returns [approveInstruction, compressInstruction]
|
|
4156
|
+
*/
|
|
4079
4157
|
static async compress(params) {
|
|
4080
4158
|
const { payer, owner, source, toAddress, mint, outputStateTree } = params;
|
|
4081
4159
|
const amount = stateless_js.bn(params.amount);
|
|
@@ -4086,7 +4164,6 @@ class CompressedTokenProgram {
|
|
|
4086
4164
|
lamports: stateless_js.bn(0),
|
|
4087
4165
|
},
|
|
4088
4166
|
];
|
|
4089
|
-
/// Pack
|
|
4090
4167
|
const { inputTokenDataWithContext, outputStateMerkleTreeIndices, remainingAccountMetas, } = packCompressedTokenAccounts({
|
|
4091
4168
|
inputCompressedTokenAccounts: [],
|
|
4092
4169
|
outputCompressedAccountsLength: outputCompressedAccounts.length,
|
|
@@ -4102,19 +4179,18 @@ class CompressedTokenProgram {
|
|
|
4102
4179
|
outputStateMerkleTreeAccountIndices: require$$0.Buffer.from(outputStateMerkleTreeIndices),
|
|
4103
4180
|
compressionAmount: amount,
|
|
4104
4181
|
isCompress: true,
|
|
4182
|
+
cpiContext: null,
|
|
4105
4183
|
};
|
|
4106
4184
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
4107
4185
|
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
4108
|
-
/// TODO: add support for multiSigners
|
|
4109
|
-
/// TODO: validate that we don't need approveChecked
|
|
4110
4186
|
const approveInstruction = createApproveInstruction(source, this.deriveCpiAuthorityPda, owner, BigInt(amount.toString()));
|
|
4111
4187
|
const instruction = await this.program.methods
|
|
4112
|
-
.transfer(encodedData
|
|
4188
|
+
.transfer(encodedData)
|
|
4113
4189
|
.accounts({
|
|
4114
4190
|
feePayer: payer,
|
|
4115
4191
|
authority: owner,
|
|
4116
4192
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
4117
|
-
|
|
4193
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
4118
4194
|
registeredProgramPda: registeredProgramPda,
|
|
4119
4195
|
noopProgram: noopProgram,
|
|
4120
4196
|
accountCompressionAuthority: accountCompressionAuthority,
|
|
@@ -4126,12 +4202,11 @@ class CompressedTokenProgram {
|
|
|
4126
4202
|
})
|
|
4127
4203
|
.remainingAccounts(remainingAccountMetas)
|
|
4128
4204
|
.instruction();
|
|
4129
|
-
return [
|
|
4130
|
-
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
4131
|
-
approveInstruction,
|
|
4132
|
-
instruction,
|
|
4133
|
-
];
|
|
4205
|
+
return [approveInstruction, instruction];
|
|
4134
4206
|
}
|
|
4207
|
+
/**
|
|
4208
|
+
* Construct decompress instruction
|
|
4209
|
+
*/
|
|
4135
4210
|
static async decompress(params) {
|
|
4136
4211
|
const { payer, inputCompressedTokenAccounts, toAddress, outputStateTree, recentValidityProof, recentInputStateRootIndices, } = params;
|
|
4137
4212
|
const amount = stateless_js.bn(params.amount);
|
|
@@ -4142,7 +4217,7 @@ class CompressedTokenProgram {
|
|
|
4142
4217
|
outputCompressedAccountsLength: tokenTransferOutputs.length,
|
|
4143
4218
|
outputStateTrees: [outputStateTree],
|
|
4144
4219
|
});
|
|
4145
|
-
const { mint, currentOwner } =
|
|
4220
|
+
const { mint, currentOwner } = parseTokenData(inputCompressedTokenAccounts);
|
|
4146
4221
|
const data = {
|
|
4147
4222
|
proof: recentValidityProof,
|
|
4148
4223
|
rootIndices: recentInputStateRootIndices,
|
|
@@ -4153,47 +4228,78 @@ class CompressedTokenProgram {
|
|
|
4153
4228
|
outputStateMerkleTreeAccountIndices: require$$0.Buffer.from(outputStateMerkleTreeIndices),
|
|
4154
4229
|
compressionAmount: amount,
|
|
4155
4230
|
isCompress: false,
|
|
4231
|
+
cpiContext: null,
|
|
4156
4232
|
};
|
|
4157
4233
|
const encodedData = this.program.coder.types.encode('CompressedTokenInstructionDataTransfer', data);
|
|
4158
4234
|
const { accountCompressionAuthority, noopProgram, registeredProgramPda, accountCompressionProgram, } = stateless_js.defaultStaticAccountsStruct();
|
|
4159
4235
|
const instruction = await this.program.methods
|
|
4160
|
-
.transfer(encodedData
|
|
4236
|
+
.transfer(encodedData)
|
|
4161
4237
|
.accounts({
|
|
4162
4238
|
feePayer: payer,
|
|
4163
4239
|
authority: currentOwner,
|
|
4164
4240
|
cpiAuthorityPda: this.deriveCpiAuthorityPda,
|
|
4165
|
-
|
|
4241
|
+
lightSystemProgram: stateless_js.LightSystemProgram.programId,
|
|
4166
4242
|
registeredProgramPda: registeredProgramPda,
|
|
4167
4243
|
noopProgram: noopProgram,
|
|
4168
4244
|
accountCompressionAuthority: accountCompressionAuthority,
|
|
4169
4245
|
accountCompressionProgram: accountCompressionProgram,
|
|
4170
4246
|
selfProgram: this.programId,
|
|
4171
4247
|
tokenPoolPda: this.deriveTokenPoolPda(mint),
|
|
4172
|
-
decompressTokenAccount: toAddress,
|
|
4248
|
+
decompressTokenAccount: toAddress,
|
|
4173
4249
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
4174
4250
|
})
|
|
4175
4251
|
.remainingAccounts(remainingAccountMetas)
|
|
4176
4252
|
.instruction();
|
|
4177
|
-
return
|
|
4178
|
-
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
4179
|
-
instruction,
|
|
4180
|
-
];
|
|
4253
|
+
return instruction;
|
|
4181
4254
|
}
|
|
4182
4255
|
}
|
|
4183
4256
|
_a = CompressedTokenProgram;
|
|
4184
4257
|
/**
|
|
4185
4258
|
* Public key that identifies the CompressedPda program
|
|
4186
4259
|
*/
|
|
4187
|
-
CompressedTokenProgram.programId = new web3_js.PublicKey(
|
|
4188
|
-
// TODO: can add check to ensure its consistent with the idl
|
|
4189
|
-
'9sixVEthz2kMSKfeApZXHwuboT6DZuT6crAYJTciUCqE');
|
|
4260
|
+
CompressedTokenProgram.programId = new web3_js.PublicKey('9sixVEthz2kMSKfeApZXHwuboT6DZuT6crAYJTciUCqE');
|
|
4190
4261
|
CompressedTokenProgram._program = null;
|
|
4191
4262
|
/** @internal */
|
|
4192
4263
|
CompressedTokenProgram.deriveMintAuthorityPda = (authority, mint) => {
|
|
4193
|
-
|
|
4194
|
-
return pubkey;
|
|
4264
|
+
return web3_js.PublicKey.findProgramAddressSync([MINT_AUTHORITY_SEED, authority.toBuffer(), mint.toBuffer()], _a.programId);
|
|
4195
4265
|
};
|
|
4196
4266
|
|
|
4267
|
+
/**
|
|
4268
|
+
* Mint compressed tokens to a solana address from an external mint authority
|
|
4269
|
+
*
|
|
4270
|
+
* @param rpc Rpc to use
|
|
4271
|
+
* @param payer Payer of the transaction fees
|
|
4272
|
+
* @param mint Mint for the account
|
|
4273
|
+
* @param destination Address of the account to mint to
|
|
4274
|
+
* @param authority Minting authority
|
|
4275
|
+
* @param amount Amount to mint
|
|
4276
|
+
* @param merkleTree State tree account that the compressed tokens should be
|
|
4277
|
+
* part of. Defaults to the default state tree account.
|
|
4278
|
+
* @param confirmOptions Options for confirming the transaction
|
|
4279
|
+
*
|
|
4280
|
+
* @return Signature of the confirmed transaction
|
|
4281
|
+
*/
|
|
4282
|
+
async function approveAndMintTo(rpc, payer, mint, destination, authority, amount, merkleTree = stateless_js.defaultTestStateTreeAccounts().merkleTree, confirmOptions) {
|
|
4283
|
+
const authorityTokenAccount = await getOrCreateAssociatedTokenAccount(rpc, payer, mint, authority.publicKey);
|
|
4284
|
+
const ixs = await CompressedTokenProgram.approveAndMintTo({
|
|
4285
|
+
feePayer: payer.publicKey,
|
|
4286
|
+
mint,
|
|
4287
|
+
authority: authority.publicKey,
|
|
4288
|
+
authorityTokenAccount: authorityTokenAccount.address,
|
|
4289
|
+
amount,
|
|
4290
|
+
toPubkey: destination,
|
|
4291
|
+
merkleTree,
|
|
4292
|
+
});
|
|
4293
|
+
const { blockhash } = await rpc.getLatestBlockhash();
|
|
4294
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [authority]);
|
|
4295
|
+
const tx = stateless_js.buildAndSignTx([
|
|
4296
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }),
|
|
4297
|
+
...ixs,
|
|
4298
|
+
], payer, blockhash, additionalSigners);
|
|
4299
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
4300
|
+
return txId;
|
|
4301
|
+
}
|
|
4302
|
+
|
|
4197
4303
|
/**
|
|
4198
4304
|
* Compress SPL tokens
|
|
4199
4305
|
*
|
|
@@ -4214,7 +4320,7 @@ CompressedTokenProgram.deriveMintAuthorityPda = (authority, mint) => {
|
|
|
4214
4320
|
*/
|
|
4215
4321
|
async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toAddress, merkleTree = stateless_js.defaultTestStateTreeAccounts().merkleTree, confirmOptions) {
|
|
4216
4322
|
amount = stateless_js.bn(amount);
|
|
4217
|
-
const
|
|
4323
|
+
const [approveIx, compressIx] = await CompressedTokenProgram.compress({
|
|
4218
4324
|
payer: payer.publicKey,
|
|
4219
4325
|
owner: owner.publicKey,
|
|
4220
4326
|
source: sourceTokenAccount,
|
|
@@ -4225,7 +4331,13 @@ async function compress(rpc, payer, mint, amount, owner, sourceTokenAccount, toA
|
|
|
4225
4331
|
});
|
|
4226
4332
|
const blockhashCtx = await rpc.getLatestBlockhash();
|
|
4227
4333
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
4228
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
4334
|
+
const signedTx = stateless_js.buildAndSignTx([
|
|
4335
|
+
web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
4336
|
+
units: 1000000,
|
|
4337
|
+
}),
|
|
4338
|
+
approveIx,
|
|
4339
|
+
compressIx,
|
|
4340
|
+
], payer, blockhashCtx.blockhash, additionalSigners);
|
|
4229
4341
|
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions, blockhashCtx);
|
|
4230
4342
|
return txId;
|
|
4231
4343
|
}
|
|
@@ -4255,7 +4367,7 @@ merkleTree = stateless_js.defaultTestStateTreeAccounts().merkleTree, confirmOpti
|
|
|
4255
4367
|
});
|
|
4256
4368
|
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(compressedTokenAccounts, amount);
|
|
4257
4369
|
const proof = await rpc.getValidityProof(inputAccounts.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
4258
|
-
const
|
|
4370
|
+
const ix = await CompressedTokenProgram.transfer({
|
|
4259
4371
|
payer: payer.publicKey,
|
|
4260
4372
|
inputCompressedTokenAccounts: inputAccounts,
|
|
4261
4373
|
toAddress,
|
|
@@ -4266,7 +4378,7 @@ merkleTree = stateless_js.defaultTestStateTreeAccounts().merkleTree, confirmOpti
|
|
|
4266
4378
|
});
|
|
4267
4379
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
4268
4380
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
4269
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
4381
|
+
const signedTx = stateless_js.buildAndSignTx([web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }), ix], payer, blockhash, additionalSigners);
|
|
4270
4382
|
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
4271
4383
|
return txId;
|
|
4272
4384
|
}
|
|
@@ -4327,7 +4439,7 @@ merkleTree = stateless_js.defaultTestStateTreeAccounts().merkleTree, confirmOpti
|
|
|
4327
4439
|
/// TODO: consider using a different selection algorithm
|
|
4328
4440
|
const [inputAccounts] = selectMinCompressedTokenAccountsForTransfer(compressedTokenAccounts, amount);
|
|
4329
4441
|
const proof = await rpc.getValidityProof(inputAccounts.map(account => stateless_js.bn(account.compressedAccount.hash)));
|
|
4330
|
-
const
|
|
4442
|
+
const ix = await CompressedTokenProgram.decompress({
|
|
4331
4443
|
payer: payer.publicKey,
|
|
4332
4444
|
inputCompressedTokenAccounts: inputAccounts,
|
|
4333
4445
|
toAddress, // TODO: add explicit check that it is a token account
|
|
@@ -4338,7 +4450,7 @@ merkleTree = stateless_js.defaultTestStateTreeAccounts().merkleTree, confirmOpti
|
|
|
4338
4450
|
});
|
|
4339
4451
|
const { blockhash } = await rpc.getLatestBlockhash();
|
|
4340
4452
|
const additionalSigners = stateless_js.dedupeSigner(payer, [owner]);
|
|
4341
|
-
const signedTx = stateless_js.buildAndSignTx(
|
|
4453
|
+
const signedTx = stateless_js.buildAndSignTx([web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 }), ix], payer, blockhash, additionalSigners);
|
|
4342
4454
|
const txId = await stateless_js.sendAndConfirmTx(rpc, signedTx, confirmOptions);
|
|
4343
4455
|
return txId;
|
|
4344
4456
|
}
|
|
@@ -4404,12 +4516,37 @@ confirmOptions) {
|
|
|
4404
4516
|
return txId;
|
|
4405
4517
|
}
|
|
4406
4518
|
|
|
4519
|
+
/**
|
|
4520
|
+
* Register an existing mint with the CompressedToken program
|
|
4521
|
+
*
|
|
4522
|
+
* @param rpc RPC to use
|
|
4523
|
+
* @param payer Payer of the transaction and initialization fees
|
|
4524
|
+
* @param mintAuthority Account or multisig that will control minting. Is signer.
|
|
4525
|
+
* @param mintAddress Address of the existing mint
|
|
4526
|
+
* @param confirmOptions Options for confirming the transaction
|
|
4527
|
+
*
|
|
4528
|
+
* @return transaction signature
|
|
4529
|
+
*/
|
|
4530
|
+
async function registerMint(rpc, payer, mintAuthority, mintAddress, confirmOptions) {
|
|
4531
|
+
const ixs = await CompressedTokenProgram.registerMint({
|
|
4532
|
+
feePayer: payer.publicKey,
|
|
4533
|
+
mint: mintAddress,
|
|
4534
|
+
authority: mintAuthority.publicKey,
|
|
4535
|
+
});
|
|
4536
|
+
const { blockhash } = await rpc.getLatestBlockhash();
|
|
4537
|
+
const additionalSigners = stateless_js.dedupeSigner(payer, [mintAuthority]);
|
|
4538
|
+
const tx = stateless_js.buildAndSignTx(ixs, payer, blockhash, additionalSigners);
|
|
4539
|
+
const txId = await stateless_js.sendAndConfirmTx(rpc, tx, confirmOptions);
|
|
4540
|
+
return txId;
|
|
4541
|
+
}
|
|
4542
|
+
|
|
4407
4543
|
exports.CPI_AUTHORITY_SEED = CPI_AUTHORITY_SEED;
|
|
4408
4544
|
exports.CompressedTokenProgram = CompressedTokenProgram;
|
|
4409
4545
|
exports.IDL = IDL;
|
|
4410
4546
|
exports.MINT_AUTHORITY_SEED = MINT_AUTHORITY_SEED;
|
|
4411
4547
|
exports.POOL_SEED = POOL_SEED;
|
|
4412
4548
|
exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE = SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE;
|
|
4549
|
+
exports.approveAndMintTo = approveAndMintTo;
|
|
4413
4550
|
exports.compress = compress;
|
|
4414
4551
|
exports.createDecompressOutputState = createDecompressOutputState;
|
|
4415
4552
|
exports.createMint = createMint;
|
|
@@ -4417,7 +4554,8 @@ exports.createTransferOutputState = createTransferOutputState;
|
|
|
4417
4554
|
exports.decompress = decompress;
|
|
4418
4555
|
exports.mintTo = mintTo;
|
|
4419
4556
|
exports.packCompressedTokenAccounts = packCompressedTokenAccounts;
|
|
4420
|
-
exports.
|
|
4557
|
+
exports.parseTokenData = parseTokenData;
|
|
4558
|
+
exports.registerMint = registerMint;
|
|
4421
4559
|
exports.selectMinCompressedTokenAccountsForTransfer = selectMinCompressedTokenAccountsForTransfer;
|
|
4422
4560
|
exports.sumUpTokenAmount = sumUpTokenAmount;
|
|
4423
4561
|
exports.transfer = transfer;
|