@solana-program/token-wrap 2.1.0 → 2.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/dist/src/index.js CHANGED
@@ -101,6 +101,8 @@ var TokenWrapInstruction = /* @__PURE__ */ ((TokenWrapInstruction2) => {
101
101
  TokenWrapInstruction2[TokenWrapInstruction2["Wrap"] = 1] = "Wrap";
102
102
  TokenWrapInstruction2[TokenWrapInstruction2["Unwrap"] = 2] = "Unwrap";
103
103
  TokenWrapInstruction2[TokenWrapInstruction2["CloseStuckEscrow"] = 3] = "CloseStuckEscrow";
104
+ TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToToken2022"] = 4] = "SyncMetadataToToken2022";
105
+ TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToSplToken"] = 5] = "SyncMetadataToSplToken";
104
106
  return TokenWrapInstruction2;
105
107
  })(TokenWrapInstruction || {});
106
108
  function identifyTokenWrapInstruction(instruction) {
@@ -117,6 +119,12 @@ function identifyTokenWrapInstruction(instruction) {
117
119
  if (kit.containsBytes(data, kit.getU8Encoder().encode(3), 0)) {
118
120
  return 3 /* CloseStuckEscrow */;
119
121
  }
122
+ if (kit.containsBytes(data, kit.getU8Encoder().encode(4), 0)) {
123
+ return 4 /* SyncMetadataToToken2022 */;
124
+ }
125
+ if (kit.containsBytes(data, kit.getU8Encoder().encode(5), 0)) {
126
+ return 5 /* SyncMetadataToSplToken */;
127
+ }
120
128
  throw new Error(
121
129
  "The provided instruction could not be identified as a tokenWrap instruction."
122
130
  );
@@ -132,6 +140,13 @@ var TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = 5;
132
140
  var TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = 6;
133
141
  var TOKEN_WRAP_ERROR__ESCROW_MISMATCH = 7;
134
142
  var TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE = 8;
143
+ var TOKEN_WRAP_ERROR__UNWRAPPED_MINT_HAS_NO_METADATA = 9;
144
+ var TOKEN_WRAP_ERROR__METAPLEX_METADATA_MISMATCH = 10;
145
+ var TOKEN_WRAP_ERROR__METADATA_POINTER_MISSING = 11;
146
+ var TOKEN_WRAP_ERROR__METADATA_POINTER_UNSET = 12;
147
+ var TOKEN_WRAP_ERROR__METADATA_POINTER_MISMATCH = 13;
148
+ var TOKEN_WRAP_ERROR__EXTERNAL_PROGRAM_RETURNED_NO_DATA = 14;
149
+ var TOKEN_WRAP_ERROR__NO_SYNCING_TO_TOKEN2022 = 15;
135
150
  var tokenWrapErrorMessages;
136
151
  if (process.env.NODE_ENV !== "production") {
137
152
  tokenWrapErrorMessages = {
@@ -139,9 +154,16 @@ if (process.env.NODE_ENV !== "production") {
139
154
  [TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE]: `The escrow account is in a good state and cannot be recreated`,
140
155
  [TOKEN_WRAP_ERROR__ESCROW_MISMATCH]: `Escrow account address does not match expected ATA`,
141
156
  [TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH]: `Unwrapped escrow token owner is not set to expected PDA`,
157
+ [TOKEN_WRAP_ERROR__EXTERNAL_PROGRAM_RETURNED_NO_DATA]: `External metadata program returned no data`,
142
158
  [TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER]: `Wrapped backpointer account owner is not the expected token wrap program`,
143
159
  [TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER]: `Wrapped mint account owner is not the expected token program`,
160
+ [TOKEN_WRAP_ERROR__METADATA_POINTER_MISMATCH]: `Provided source metadata account does not match pointer`,
161
+ [TOKEN_WRAP_ERROR__METADATA_POINTER_MISSING]: `Metadata pointer extension missing on mint`,
162
+ [TOKEN_WRAP_ERROR__METADATA_POINTER_UNSET]: `Metadata pointer is unset (None)`,
163
+ [TOKEN_WRAP_ERROR__METAPLEX_METADATA_MISMATCH]: `Metaplex metadata account address does not match expected PDA`,
144
164
  [TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH]: `Wrapped mint authority does not match expected PDA`,
165
+ [TOKEN_WRAP_ERROR__NO_SYNCING_TO_TOKEN2022]: `Instruction can only be used with spl-token wrapped mints`,
166
+ [TOKEN_WRAP_ERROR__UNWRAPPED_MINT_HAS_NO_METADATA]: `Unwrapped mint does not have the TokenMetadata extension`,
145
167
  [TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH]: `Wrapped mint account address does not match expected PDA`,
146
168
  [TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT]: `Wrap amount should be positive`
147
169
  };
@@ -362,6 +384,196 @@ function parseCreateMintInstruction(instruction) {
362
384
  data: getCreateMintInstructionDataDecoder().decode(instruction.data)
363
385
  };
364
386
  }
387
+ var SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR = 5;
388
+ function getSyncMetadataToSplTokenDiscriminatorBytes() {
389
+ return kit.getU8Encoder().encode(SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR);
390
+ }
391
+ function getSyncMetadataToSplTokenInstructionDataEncoder() {
392
+ return kit.transformEncoder(
393
+ kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]),
394
+ (value) => ({
395
+ ...value,
396
+ discriminator: SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR
397
+ })
398
+ );
399
+ }
400
+ function getSyncMetadataToSplTokenInstructionDataDecoder() {
401
+ return kit.getStructDecoder([["discriminator", kit.getU8Decoder()]]);
402
+ }
403
+ function getSyncMetadataToSplTokenInstructionDataCodec() {
404
+ return kit.combineCodec(
405
+ getSyncMetadataToSplTokenInstructionDataEncoder(),
406
+ getSyncMetadataToSplTokenInstructionDataDecoder()
407
+ );
408
+ }
409
+ function getSyncMetadataToSplTokenInstruction(input, config) {
410
+ const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
411
+ const originalAccounts = {
412
+ metaplexMetadata: {
413
+ value: input.metaplexMetadata ?? null,
414
+ isWritable: true
415
+ },
416
+ wrappedMintAuthority: {
417
+ value: input.wrappedMintAuthority ?? null,
418
+ isWritable: true
419
+ },
420
+ wrappedMint: { value: input.wrappedMint ?? null, isWritable: false },
421
+ unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
422
+ metaplexProgram: {
423
+ value: input.metaplexProgram ?? null,
424
+ isWritable: false
425
+ },
426
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
427
+ rentSysvar: { value: input.rentSysvar ?? null, isWritable: false },
428
+ sourceMetadata: { value: input.sourceMetadata ?? null, isWritable: false },
429
+ ownerProgram: { value: input.ownerProgram ?? null, isWritable: false }
430
+ };
431
+ const accounts = originalAccounts;
432
+ if (!accounts.metaplexProgram.value) {
433
+ accounts.metaplexProgram.value = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s";
434
+ }
435
+ if (!accounts.systemProgram.value) {
436
+ accounts.systemProgram.value = "11111111111111111111111111111111";
437
+ }
438
+ if (!accounts.rentSysvar.value) {
439
+ accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
440
+ }
441
+ const getAccountMeta = getAccountMetaFactory(programAddress);
442
+ const instruction = {
443
+ accounts: [
444
+ getAccountMeta(accounts.metaplexMetadata),
445
+ getAccountMeta(accounts.wrappedMintAuthority),
446
+ getAccountMeta(accounts.wrappedMint),
447
+ getAccountMeta(accounts.unwrappedMint),
448
+ getAccountMeta(accounts.metaplexProgram),
449
+ getAccountMeta(accounts.systemProgram),
450
+ getAccountMeta(accounts.rentSysvar),
451
+ getAccountMeta(accounts.sourceMetadata),
452
+ getAccountMeta(accounts.ownerProgram)
453
+ ],
454
+ programAddress,
455
+ data: getSyncMetadataToSplTokenInstructionDataEncoder().encode({})
456
+ };
457
+ return instruction;
458
+ }
459
+ function parseSyncMetadataToSplTokenInstruction(instruction) {
460
+ if (instruction.accounts.length < 9) {
461
+ throw new Error("Not enough accounts");
462
+ }
463
+ let accountIndex = 0;
464
+ const getNextAccount = () => {
465
+ const accountMeta = instruction.accounts[accountIndex];
466
+ accountIndex += 1;
467
+ return accountMeta;
468
+ };
469
+ const getNextOptionalAccount = () => {
470
+ const accountMeta = getNextAccount();
471
+ return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
472
+ };
473
+ return {
474
+ programAddress: instruction.programAddress,
475
+ accounts: {
476
+ metaplexMetadata: getNextAccount(),
477
+ wrappedMintAuthority: getNextAccount(),
478
+ wrappedMint: getNextAccount(),
479
+ unwrappedMint: getNextAccount(),
480
+ metaplexProgram: getNextAccount(),
481
+ systemProgram: getNextAccount(),
482
+ rentSysvar: getNextAccount(),
483
+ sourceMetadata: getNextOptionalAccount(),
484
+ ownerProgram: getNextOptionalAccount()
485
+ },
486
+ data: getSyncMetadataToSplTokenInstructionDataDecoder().decode(
487
+ instruction.data
488
+ )
489
+ };
490
+ }
491
+ var SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR = 4;
492
+ function getSyncMetadataToToken2022DiscriminatorBytes() {
493
+ return kit.getU8Encoder().encode(SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR);
494
+ }
495
+ function getSyncMetadataToToken2022InstructionDataEncoder() {
496
+ return kit.transformEncoder(
497
+ kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]),
498
+ (value) => ({
499
+ ...value,
500
+ discriminator: SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR
501
+ })
502
+ );
503
+ }
504
+ function getSyncMetadataToToken2022InstructionDataDecoder() {
505
+ return kit.getStructDecoder([["discriminator", kit.getU8Decoder()]]);
506
+ }
507
+ function getSyncMetadataToToken2022InstructionDataCodec() {
508
+ return kit.combineCodec(
509
+ getSyncMetadataToToken2022InstructionDataEncoder(),
510
+ getSyncMetadataToToken2022InstructionDataDecoder()
511
+ );
512
+ }
513
+ function getSyncMetadataToToken2022Instruction(input, config) {
514
+ const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
515
+ const originalAccounts = {
516
+ wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
517
+ wrappedMintAuthority: {
518
+ value: input.wrappedMintAuthority ?? null,
519
+ isWritable: false
520
+ },
521
+ unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
522
+ token2022Program: {
523
+ value: input.token2022Program ?? null,
524
+ isWritable: false
525
+ },
526
+ sourceMetadata: { value: input.sourceMetadata ?? null, isWritable: false },
527
+ ownerProgram: { value: input.ownerProgram ?? null, isWritable: false }
528
+ };
529
+ const accounts = originalAccounts;
530
+ if (!accounts.token2022Program.value) {
531
+ accounts.token2022Program.value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
532
+ }
533
+ const getAccountMeta = getAccountMetaFactory(programAddress);
534
+ const instruction = {
535
+ accounts: [
536
+ getAccountMeta(accounts.wrappedMint),
537
+ getAccountMeta(accounts.wrappedMintAuthority),
538
+ getAccountMeta(accounts.unwrappedMint),
539
+ getAccountMeta(accounts.token2022Program),
540
+ getAccountMeta(accounts.sourceMetadata),
541
+ getAccountMeta(accounts.ownerProgram)
542
+ ],
543
+ programAddress,
544
+ data: getSyncMetadataToToken2022InstructionDataEncoder().encode({})
545
+ };
546
+ return instruction;
547
+ }
548
+ function parseSyncMetadataToToken2022Instruction(instruction) {
549
+ if (instruction.accounts.length < 6) {
550
+ throw new Error("Not enough accounts");
551
+ }
552
+ let accountIndex = 0;
553
+ const getNextAccount = () => {
554
+ const accountMeta = instruction.accounts[accountIndex];
555
+ accountIndex += 1;
556
+ return accountMeta;
557
+ };
558
+ const getNextOptionalAccount = () => {
559
+ const accountMeta = getNextAccount();
560
+ return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
561
+ };
562
+ return {
563
+ programAddress: instruction.programAddress,
564
+ accounts: {
565
+ wrappedMint: getNextAccount(),
566
+ wrappedMintAuthority: getNextAccount(),
567
+ unwrappedMint: getNextAccount(),
568
+ token2022Program: getNextAccount(),
569
+ sourceMetadata: getNextOptionalAccount(),
570
+ ownerProgram: getNextOptionalAccount()
571
+ },
572
+ data: getSyncMetadataToToken2022InstructionDataDecoder().decode(
573
+ instruction.data
574
+ )
575
+ };
576
+ }
365
577
  var UNWRAP_DISCRIMINATOR = 2;
366
578
  function getUnwrapDiscriminatorBytes() {
367
579
  return kit.getU8Encoder().encode(UNWRAP_DISCRIMINATOR);
@@ -586,6 +798,17 @@ function parseWrapInstruction(instruction) {
586
798
  data: getWrapInstructionDataDecoder().decode(instruction.data)
587
799
  };
588
800
  }
801
+ var DEFAULT_EXTENSIONS = [
802
+ token2022.extension("ConfidentialTransferMint", {
803
+ autoApproveNewAccounts: true,
804
+ authority: null,
805
+ auditorElgamalPubkey: null
806
+ }),
807
+ token2022.extension("MetadataPointer", {
808
+ authority: null,
809
+ metadataAddress: null
810
+ })
811
+ ];
589
812
  async function createMint({
590
813
  rpc,
591
814
  unwrappedMint,
@@ -600,7 +823,10 @@ async function createMint({
600
823
  const [backpointer] = await findBackpointerPda({ wrappedMint });
601
824
  const instructions = [];
602
825
  let fundedWrappedMintLamports = 0n;
603
- const mintSize = BigInt(token2022.getMintSize());
826
+ let mintSize = BigInt(token2022.getMintSize());
827
+ if (wrappedTokenProgram === token2022.TOKEN_2022_PROGRAM_ADDRESS) {
828
+ mintSize = BigInt(token2022.getMintSize(DEFAULT_EXTENSIONS));
829
+ }
604
830
  const [wrappedMintAccount, wrappedMintRent] = await Promise.all([
605
831
  kit.fetchEncodedAccount(rpc, wrappedMint),
606
832
  rpc.getMinimumBalanceForRentExemption(mintSize).send()
@@ -740,7 +966,8 @@ function combinedMultisigTx({
740
966
  signatures: combineSignatures(signedTxs),
741
967
  lifetimeConstraint: blockhash
742
968
  };
743
- kit.assertTransactionIsFullySigned(tx);
969
+ kit.assertIsFullySignedTransaction(tx);
970
+ kit.assertIsSendableTransaction(tx);
744
971
  return tx;
745
972
  }
746
973
  async function multisigOfflineSignWrap(args) {
@@ -984,13 +1211,22 @@ async function multisigOfflineSignUnwrap(args) {
984
1211
 
985
1212
  exports.CLOSE_STUCK_ESCROW_DISCRIMINATOR = CLOSE_STUCK_ESCROW_DISCRIMINATOR;
986
1213
  exports.CREATE_MINT_DISCRIMINATOR = CREATE_MINT_DISCRIMINATOR;
1214
+ exports.SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR = SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR;
1215
+ exports.SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR = SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR;
987
1216
  exports.TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH = TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH;
988
1217
  exports.TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE = TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE;
989
1218
  exports.TOKEN_WRAP_ERROR__ESCROW_MISMATCH = TOKEN_WRAP_ERROR__ESCROW_MISMATCH;
990
1219
  exports.TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH;
1220
+ exports.TOKEN_WRAP_ERROR__EXTERNAL_PROGRAM_RETURNED_NO_DATA = TOKEN_WRAP_ERROR__EXTERNAL_PROGRAM_RETURNED_NO_DATA;
991
1221
  exports.TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER;
992
1222
  exports.TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER;
1223
+ exports.TOKEN_WRAP_ERROR__METADATA_POINTER_MISMATCH = TOKEN_WRAP_ERROR__METADATA_POINTER_MISMATCH;
1224
+ exports.TOKEN_WRAP_ERROR__METADATA_POINTER_MISSING = TOKEN_WRAP_ERROR__METADATA_POINTER_MISSING;
1225
+ exports.TOKEN_WRAP_ERROR__METADATA_POINTER_UNSET = TOKEN_WRAP_ERROR__METADATA_POINTER_UNSET;
1226
+ exports.TOKEN_WRAP_ERROR__METAPLEX_METADATA_MISMATCH = TOKEN_WRAP_ERROR__METAPLEX_METADATA_MISMATCH;
993
1227
  exports.TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH = TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH;
1228
+ exports.TOKEN_WRAP_ERROR__NO_SYNCING_TO_TOKEN2022 = TOKEN_WRAP_ERROR__NO_SYNCING_TO_TOKEN2022;
1229
+ exports.TOKEN_WRAP_ERROR__UNWRAPPED_MINT_HAS_NO_METADATA = TOKEN_WRAP_ERROR__UNWRAPPED_MINT_HAS_NO_METADATA;
994
1230
  exports.TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH = TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH;
995
1231
  exports.TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT = TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT;
996
1232
  exports.TOKEN_WRAP_PROGRAM_ADDRESS = TOKEN_WRAP_PROGRAM_ADDRESS;
@@ -1025,6 +1261,16 @@ exports.getCreateMintInstruction = getCreateMintInstruction;
1025
1261
  exports.getCreateMintInstructionDataCodec = getCreateMintInstructionDataCodec;
1026
1262
  exports.getCreateMintInstructionDataDecoder = getCreateMintInstructionDataDecoder;
1027
1263
  exports.getCreateMintInstructionDataEncoder = getCreateMintInstructionDataEncoder;
1264
+ exports.getSyncMetadataToSplTokenDiscriminatorBytes = getSyncMetadataToSplTokenDiscriminatorBytes;
1265
+ exports.getSyncMetadataToSplTokenInstruction = getSyncMetadataToSplTokenInstruction;
1266
+ exports.getSyncMetadataToSplTokenInstructionDataCodec = getSyncMetadataToSplTokenInstructionDataCodec;
1267
+ exports.getSyncMetadataToSplTokenInstructionDataDecoder = getSyncMetadataToSplTokenInstructionDataDecoder;
1268
+ exports.getSyncMetadataToSplTokenInstructionDataEncoder = getSyncMetadataToSplTokenInstructionDataEncoder;
1269
+ exports.getSyncMetadataToToken2022DiscriminatorBytes = getSyncMetadataToToken2022DiscriminatorBytes;
1270
+ exports.getSyncMetadataToToken2022Instruction = getSyncMetadataToToken2022Instruction;
1271
+ exports.getSyncMetadataToToken2022InstructionDataCodec = getSyncMetadataToToken2022InstructionDataCodec;
1272
+ exports.getSyncMetadataToToken2022InstructionDataDecoder = getSyncMetadataToToken2022InstructionDataDecoder;
1273
+ exports.getSyncMetadataToToken2022InstructionDataEncoder = getSyncMetadataToToken2022InstructionDataEncoder;
1028
1274
  exports.getTokenWrapErrorMessage = getTokenWrapErrorMessage;
1029
1275
  exports.getUnwrapDiscriminatorBytes = getUnwrapDiscriminatorBytes;
1030
1276
  exports.getUnwrapInstruction = getUnwrapInstruction;
@@ -1042,6 +1288,8 @@ exports.multisigOfflineSignUnwrap = multisigOfflineSignUnwrap;
1042
1288
  exports.multisigOfflineSignWrap = multisigOfflineSignWrap;
1043
1289
  exports.parseCloseStuckEscrowInstruction = parseCloseStuckEscrowInstruction;
1044
1290
  exports.parseCreateMintInstruction = parseCreateMintInstruction;
1291
+ exports.parseSyncMetadataToSplTokenInstruction = parseSyncMetadataToSplTokenInstruction;
1292
+ exports.parseSyncMetadataToToken2022Instruction = parseSyncMetadataToToken2022Instruction;
1045
1293
  exports.parseUnwrapInstruction = parseUnwrapInstruction;
1046
1294
  exports.parseWrapInstruction = parseWrapInstruction;
1047
1295
  exports.singleSignerUnwrap = singleSignerUnwrap;