@solana-program/token-wrap 2.3.0 → 2.4.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.
Files changed (34) hide show
  1. package/dist/src/index.js +185 -255
  2. package/dist/src/index.js.map +1 -1
  3. package/dist/src/index.mjs +186 -257
  4. package/dist/src/index.mjs.map +1 -1
  5. package/dist/types/{generated → src/generated}/accounts/backpointer.d.ts +4 -0
  6. package/dist/types/{generated → src/generated}/instructions/closeStuckEscrow.d.ts +1 -1
  7. package/dist/types/{generated → src/generated}/instructions/createMint.d.ts +1 -1
  8. package/dist/types/{generated → src/generated}/instructions/syncMetadataToSplToken.d.ts +1 -1
  9. package/dist/types/{generated → src/generated}/instructions/syncMetadataToToken2022.d.ts +1 -1
  10. package/dist/types/{generated → src/generated}/instructions/unwrap.d.ts +1 -1
  11. package/dist/types/{generated → src/generated}/instructions/wrap.d.ts +1 -1
  12. package/dist/types/{generated → src/generated}/programs/tokenWrap.d.ts +2 -1
  13. package/dist/types/{unwrap.d.ts → src/unwrap.d.ts} +1 -2
  14. package/dist/types/{utilities.d.ts → src/utilities.d.ts} +1 -3
  15. package/dist/types/{wrap.d.ts → src/wrap.d.ts} +1 -2
  16. package/dist/types/tsup.config.d.ts +3 -0
  17. package/package.json +15 -17
  18. /package/dist/types/{create-mint.d.ts → src/create-mint.d.ts} +0 -0
  19. /package/dist/types/{examples → src/examples}/multisig.d.ts +0 -0
  20. /package/dist/types/{examples → src/examples}/single-signer.d.ts +0 -0
  21. /package/dist/types/{examples → src/examples}/sync-spl-to-token2022.d.ts +0 -0
  22. /package/dist/types/{examples → src/examples}/sync-token2022-to-spl.d.ts +0 -0
  23. /package/dist/types/{generated → src/generated}/accounts/index.d.ts +0 -0
  24. /package/dist/types/{generated → src/generated}/errors/index.d.ts +0 -0
  25. /package/dist/types/{generated → src/generated}/errors/tokenWrap.d.ts +0 -0
  26. /package/dist/types/{generated → src/generated}/index.d.ts +0 -0
  27. /package/dist/types/{generated → src/generated}/instructions/index.d.ts +0 -0
  28. /package/dist/types/{generated → src/generated}/pdas/backpointer.d.ts +0 -0
  29. /package/dist/types/{generated → src/generated}/pdas/index.d.ts +0 -0
  30. /package/dist/types/{generated → src/generated}/pdas/wrappedMint.d.ts +0 -0
  31. /package/dist/types/{generated → src/generated}/pdas/wrappedMintAuthority.d.ts +0 -0
  32. /package/dist/types/{generated → src/generated}/programs/index.d.ts +0 -0
  33. /package/dist/types/{generated → src/generated}/shared/index.d.ts +0 -0
  34. /package/dist/types/{index.d.ts → src/index.d.ts} +0 -0
package/dist/src/index.js CHANGED
@@ -12,10 +12,7 @@ async function findBackpointerPda(seeds, config = {}) {
12
12
  } = config;
13
13
  return await kit.getProgramDerivedAddress({
14
14
  programAddress,
15
- seeds: [
16
- kit.getUtf8Encoder().encode("backpointer"),
17
- kit.getAddressEncoder().encode(seeds.wrappedMint)
18
- ]
15
+ seeds: [kit.getUtf8Encoder().encode("backpointer"), kit.getAddressEncoder().encode(seeds.wrappedMint)]
19
16
  });
20
17
  }
21
18
  async function findWrappedMintPda(seeds, config = {}) {
@@ -37,10 +34,7 @@ async function findWrappedMintAuthorityPda(seeds, config = {}) {
37
34
  } = config;
38
35
  return await kit.getProgramDerivedAddress({
39
36
  programAddress,
40
- seeds: [
41
- kit.getUtf8Encoder().encode("authority"),
42
- kit.getAddressEncoder().encode(seeds.wrappedMint)
43
- ]
37
+ seeds: [kit.getUtf8Encoder().encode("authority"), kit.getAddressEncoder().encode(seeds.wrappedMint)]
44
38
  });
45
39
  }
46
40
 
@@ -55,10 +49,7 @@ function getBackpointerCodec() {
55
49
  return kit.combineCodec(getBackpointerEncoder(), getBackpointerDecoder());
56
50
  }
57
51
  function decodeBackpointer(encodedAccount) {
58
- return kit.decodeAccount(
59
- encodedAccount,
60
- getBackpointerDecoder()
61
- );
52
+ return kit.decodeAccount(encodedAccount, getBackpointerDecoder());
62
53
  }
63
54
  async function fetchBackpointer(rpc, address, config) {
64
55
  const maybeAccount = await fetchMaybeBackpointer(rpc, address, config);
@@ -91,97 +82,6 @@ async function fetchMaybeBackpointerFromSeeds(rpc, seeds, config = {}) {
91
82
  const [address] = await findBackpointerPda(seeds, { programAddress });
92
83
  return await fetchMaybeBackpointer(rpc, address, fetchConfig);
93
84
  }
94
- var TOKEN_WRAP_PROGRAM_ADDRESS = "TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR";
95
- var TokenWrapAccount = /* @__PURE__ */ ((TokenWrapAccount2) => {
96
- TokenWrapAccount2[TokenWrapAccount2["Backpointer"] = 0] = "Backpointer";
97
- return TokenWrapAccount2;
98
- })(TokenWrapAccount || {});
99
- var TokenWrapInstruction = /* @__PURE__ */ ((TokenWrapInstruction2) => {
100
- TokenWrapInstruction2[TokenWrapInstruction2["CreateMint"] = 0] = "CreateMint";
101
- TokenWrapInstruction2[TokenWrapInstruction2["Wrap"] = 1] = "Wrap";
102
- TokenWrapInstruction2[TokenWrapInstruction2["Unwrap"] = 2] = "Unwrap";
103
- TokenWrapInstruction2[TokenWrapInstruction2["CloseStuckEscrow"] = 3] = "CloseStuckEscrow";
104
- TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToToken2022"] = 4] = "SyncMetadataToToken2022";
105
- TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToSplToken"] = 5] = "SyncMetadataToSplToken";
106
- return TokenWrapInstruction2;
107
- })(TokenWrapInstruction || {});
108
- function identifyTokenWrapInstruction(instruction) {
109
- const data = "data" in instruction ? instruction.data : instruction;
110
- if (kit.containsBytes(data, kit.getU8Encoder().encode(0), 0)) {
111
- return 0 /* CreateMint */;
112
- }
113
- if (kit.containsBytes(data, kit.getU8Encoder().encode(1), 0)) {
114
- return 1 /* Wrap */;
115
- }
116
- if (kit.containsBytes(data, kit.getU8Encoder().encode(2), 0)) {
117
- return 2 /* Unwrap */;
118
- }
119
- if (kit.containsBytes(data, kit.getU8Encoder().encode(3), 0)) {
120
- return 3 /* CloseStuckEscrow */;
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
- }
128
- throw new Error(
129
- "The provided instruction could not be identified as a tokenWrap instruction."
130
- );
131
- }
132
-
133
- // src/generated/errors/tokenWrap.ts
134
- var TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH = 0;
135
- var TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH = 1;
136
- var TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT = 2;
137
- var TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH = 3;
138
- var TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = 4;
139
- var TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = 5;
140
- var TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = 6;
141
- var TOKEN_WRAP_ERROR__ESCROW_MISMATCH = 7;
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;
150
- var tokenWrapErrorMessages;
151
- if (process.env.NODE_ENV !== "production") {
152
- tokenWrapErrorMessages = {
153
- [TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH]: `Wrapped backpointer account address does not match expected PDA`,
154
- [TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE]: `The escrow account is in a good state and cannot be recreated`,
155
- [TOKEN_WRAP_ERROR__ESCROW_MISMATCH]: `Escrow account address does not match expected ATA`,
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`,
158
- [TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER]: `Wrapped backpointer account owner is not the expected token wrap program`,
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`,
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`,
167
- [TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH]: `Wrapped mint account address does not match expected PDA`,
168
- [TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT]: `Wrap amount should be positive`
169
- };
170
- }
171
- function getTokenWrapErrorMessage(code) {
172
- if (process.env.NODE_ENV !== "production") {
173
- return tokenWrapErrorMessages[code];
174
- }
175
- return "Error message not available in production bundles.";
176
- }
177
- function isTokenWrapError(error, transactionMessage, code) {
178
- return kit.isProgramError(
179
- error,
180
- transactionMessage,
181
- TOKEN_WRAP_PROGRAM_ADDRESS,
182
- code
183
- );
184
- }
185
85
  function expectAddress(value) {
186
86
  if (!value) {
187
87
  throw new Error("Expected a Address.");
@@ -197,10 +97,7 @@ function expectAddress(value) {
197
97
  function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
198
98
  return (account) => {
199
99
  if (!account.value) {
200
- return Object.freeze({
201
- address: programAddress,
202
- role: kit.AccountRole.READONLY
203
- });
100
+ return Object.freeze({ address: programAddress, role: kit.AccountRole.READONLY });
204
101
  }
205
102
  const writableRole = account.isWritable ? kit.AccountRole.WRITABLE : kit.AccountRole.READONLY;
206
103
  return Object.freeze({
@@ -220,19 +117,16 @@ function getCloseStuckEscrowDiscriminatorBytes() {
220
117
  return kit.getU8Encoder().encode(CLOSE_STUCK_ESCROW_DISCRIMINATOR);
221
118
  }
222
119
  function getCloseStuckEscrowInstructionDataEncoder() {
223
- return kit.transformEncoder(
224
- kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]),
225
- (value) => ({ ...value, discriminator: CLOSE_STUCK_ESCROW_DISCRIMINATOR })
226
- );
120
+ return kit.transformEncoder(kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]), (value) => ({
121
+ ...value,
122
+ discriminator: CLOSE_STUCK_ESCROW_DISCRIMINATOR
123
+ }));
227
124
  }
228
125
  function getCloseStuckEscrowInstructionDataDecoder() {
229
126
  return kit.getStructDecoder([["discriminator", kit.getU8Decoder()]]);
230
127
  }
231
128
  function getCloseStuckEscrowInstructionDataCodec() {
232
- return kit.combineCodec(
233
- getCloseStuckEscrowInstructionDataEncoder(),
234
- getCloseStuckEscrowInstructionDataDecoder()
235
- );
129
+ return kit.combineCodec(getCloseStuckEscrowInstructionDataEncoder(), getCloseStuckEscrowInstructionDataDecoder());
236
130
  }
237
131
  function getCloseStuckEscrowInstruction(input, config) {
238
132
  const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
@@ -241,14 +135,8 @@ function getCloseStuckEscrowInstruction(input, config) {
241
135
  destination: { value: input.destination ?? null, isWritable: true },
242
136
  unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
243
137
  wrappedMint: { value: input.wrappedMint ?? null, isWritable: false },
244
- wrappedMintAuthority: {
245
- value: input.wrappedMintAuthority ?? null,
246
- isWritable: false
247
- },
248
- token2022Program: {
249
- value: input.token2022Program ?? null,
250
- isWritable: false
251
- }
138
+ wrappedMintAuthority: { value: input.wrappedMintAuthority ?? null, isWritable: false },
139
+ token2022Program: { value: input.token2022Program ?? null, isWritable: false }
252
140
  };
253
141
  const accounts = originalAccounts;
254
142
  if (!accounts.token2022Program.value) {
@@ -305,11 +193,7 @@ function getCreateMintInstructionDataEncoder() {
305
193
  ["discriminator", kit.getU8Encoder()],
306
194
  ["idempotent", kit.getBooleanEncoder()]
307
195
  ]),
308
- (value) => ({
309
- ...value,
310
- discriminator: CREATE_MINT_DISCRIMINATOR,
311
- idempotent: value.idempotent ?? false
312
- })
196
+ (value) => ({ ...value, discriminator: CREATE_MINT_DISCRIMINATOR, idempotent: value.idempotent ?? false })
313
197
  );
314
198
  }
315
199
  function getCreateMintInstructionDataDecoder() {
@@ -319,10 +203,7 @@ function getCreateMintInstructionDataDecoder() {
319
203
  ]);
320
204
  }
321
205
  function getCreateMintInstructionDataCodec() {
322
- return kit.combineCodec(
323
- getCreateMintInstructionDataEncoder(),
324
- getCreateMintInstructionDataDecoder()
325
- );
206
+ return kit.combineCodec(getCreateMintInstructionDataEncoder(), getCreateMintInstructionDataDecoder());
326
207
  }
327
208
  function getCreateMintInstruction(input, config) {
328
209
  const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
@@ -331,10 +212,7 @@ function getCreateMintInstruction(input, config) {
331
212
  backpointer: { value: input.backpointer ?? null, isWritable: true },
332
213
  unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
333
214
  systemProgram: { value: input.systemProgram ?? null, isWritable: false },
334
- wrappedTokenProgram: {
335
- value: input.wrappedTokenProgram ?? null,
336
- isWritable: false
337
- }
215
+ wrappedTokenProgram: { value: input.wrappedTokenProgram ?? null, isWritable: false }
338
216
  };
339
217
  const accounts = originalAccounts;
340
218
  const args = { ...input };
@@ -350,9 +228,7 @@ function getCreateMintInstruction(input, config) {
350
228
  getAccountMeta(accounts.systemProgram),
351
229
  getAccountMeta(accounts.wrappedTokenProgram)
352
230
  ],
353
- data: getCreateMintInstructionDataEncoder().encode(
354
- args
355
- ),
231
+ data: getCreateMintInstructionDataEncoder().encode(args),
356
232
  programAddress
357
233
  });
358
234
  }
@@ -387,13 +263,10 @@ function getSyncMetadataToSplTokenDiscriminatorBytes() {
387
263
  return kit.getU8Encoder().encode(SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR);
388
264
  }
389
265
  function getSyncMetadataToSplTokenInstructionDataEncoder() {
390
- return kit.transformEncoder(
391
- kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]),
392
- (value) => ({
393
- ...value,
394
- discriminator: SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR
395
- })
396
- );
266
+ return kit.transformEncoder(kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]), (value) => ({
267
+ ...value,
268
+ discriminator: SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR
269
+ }));
397
270
  }
398
271
  function getSyncMetadataToSplTokenInstructionDataDecoder() {
399
272
  return kit.getStructDecoder([["discriminator", kit.getU8Decoder()]]);
@@ -407,20 +280,11 @@ function getSyncMetadataToSplTokenInstructionDataCodec() {
407
280
  function getSyncMetadataToSplTokenInstruction(input, config) {
408
281
  const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
409
282
  const originalAccounts = {
410
- metaplexMetadata: {
411
- value: input.metaplexMetadata ?? null,
412
- isWritable: true
413
- },
414
- wrappedMintAuthority: {
415
- value: input.wrappedMintAuthority ?? null,
416
- isWritable: true
417
- },
283
+ metaplexMetadata: { value: input.metaplexMetadata ?? null, isWritable: true },
284
+ wrappedMintAuthority: { value: input.wrappedMintAuthority ?? null, isWritable: true },
418
285
  wrappedMint: { value: input.wrappedMint ?? null, isWritable: false },
419
286
  unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
420
- metaplexProgram: {
421
- value: input.metaplexProgram ?? null,
422
- isWritable: false
423
- },
287
+ metaplexProgram: { value: input.metaplexProgram ?? null, isWritable: false },
424
288
  systemProgram: { value: input.systemProgram ?? null, isWritable: false },
425
289
  rentSysvar: { value: input.rentSysvar ?? null, isWritable: false },
426
290
  sourceMetadata: { value: input.sourceMetadata ?? null, isWritable: false },
@@ -480,9 +344,7 @@ function parseSyncMetadataToSplTokenInstruction(instruction) {
480
344
  sourceMetadata: getNextOptionalAccount(),
481
345
  ownerProgram: getNextOptionalAccount()
482
346
  },
483
- data: getSyncMetadataToSplTokenInstructionDataDecoder().decode(
484
- instruction.data
485
- )
347
+ data: getSyncMetadataToSplTokenInstructionDataDecoder().decode(instruction.data)
486
348
  };
487
349
  }
488
350
  var SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR = 4;
@@ -490,13 +352,10 @@ function getSyncMetadataToToken2022DiscriminatorBytes() {
490
352
  return kit.getU8Encoder().encode(SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR);
491
353
  }
492
354
  function getSyncMetadataToToken2022InstructionDataEncoder() {
493
- return kit.transformEncoder(
494
- kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]),
495
- (value) => ({
496
- ...value,
497
- discriminator: SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR
498
- })
499
- );
355
+ return kit.transformEncoder(kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]), (value) => ({
356
+ ...value,
357
+ discriminator: SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR
358
+ }));
500
359
  }
501
360
  function getSyncMetadataToToken2022InstructionDataDecoder() {
502
361
  return kit.getStructDecoder([["discriminator", kit.getU8Decoder()]]);
@@ -511,15 +370,9 @@ function getSyncMetadataToToken2022Instruction(input, config) {
511
370
  const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
512
371
  const originalAccounts = {
513
372
  wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
514
- wrappedMintAuthority: {
515
- value: input.wrappedMintAuthority ?? null,
516
- isWritable: false
517
- },
373
+ wrappedMintAuthority: { value: input.wrappedMintAuthority ?? null, isWritable: false },
518
374
  unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
519
- token2022Program: {
520
- value: input.token2022Program ?? null,
521
- isWritable: false
522
- },
375
+ token2022Program: { value: input.token2022Program ?? null, isWritable: false },
523
376
  sourceMetadata: { value: input.sourceMetadata ?? null, isWritable: false },
524
377
  ownerProgram: { value: input.ownerProgram ?? null, isWritable: false }
525
378
  };
@@ -565,9 +418,7 @@ function parseSyncMetadataToToken2022Instruction(instruction) {
565
418
  sourceMetadata: getNextOptionalAccount(),
566
419
  ownerProgram: getNextOptionalAccount()
567
420
  },
568
- data: getSyncMetadataToToken2022InstructionDataDecoder().decode(
569
- instruction.data
570
- )
421
+ data: getSyncMetadataToToken2022InstructionDataDecoder().decode(instruction.data)
571
422
  };
572
423
  }
573
424
  var UNWRAP_DISCRIMINATOR = 2;
@@ -590,51 +441,28 @@ function getUnwrapInstructionDataDecoder() {
590
441
  ]);
591
442
  }
592
443
  function getUnwrapInstructionDataCodec() {
593
- return kit.combineCodec(
594
- getUnwrapInstructionDataEncoder(),
595
- getUnwrapInstructionDataDecoder()
596
- );
444
+ return kit.combineCodec(getUnwrapInstructionDataEncoder(), getUnwrapInstructionDataDecoder());
597
445
  }
598
446
  function getUnwrapInstruction(input, config) {
599
447
  const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
600
448
  const originalAccounts = {
601
449
  unwrappedEscrow: { value: input.unwrappedEscrow ?? null, isWritable: true },
602
- recipientUnwrappedToken: {
603
- value: input.recipientUnwrappedToken ?? null,
604
- isWritable: true
605
- },
606
- wrappedMintAuthority: {
607
- value: input.wrappedMintAuthority ?? null,
608
- isWritable: false
609
- },
450
+ recipientUnwrappedToken: { value: input.recipientUnwrappedToken ?? null, isWritable: true },
451
+ wrappedMintAuthority: { value: input.wrappedMintAuthority ?? null, isWritable: false },
610
452
  unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
611
- wrappedTokenProgram: {
612
- value: input.wrappedTokenProgram ?? null,
613
- isWritable: false
614
- },
615
- unwrappedTokenProgram: {
616
- value: input.unwrappedTokenProgram ?? null,
617
- isWritable: false
618
- },
619
- wrappedTokenAccount: {
620
- value: input.wrappedTokenAccount ?? null,
621
- isWritable: true
622
- },
453
+ wrappedTokenProgram: { value: input.wrappedTokenProgram ?? null, isWritable: false },
454
+ unwrappedTokenProgram: { value: input.unwrappedTokenProgram ?? null, isWritable: false },
455
+ wrappedTokenAccount: { value: input.wrappedTokenAccount ?? null, isWritable: true },
623
456
  wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
624
- transferAuthority: {
625
- value: input.transferAuthority ?? null,
626
- isWritable: false
627
- }
457
+ transferAuthority: { value: input.transferAuthority ?? null, isWritable: false }
628
458
  };
629
459
  const accounts = originalAccounts;
630
460
  const args = { ...input };
631
- const remainingAccounts = (args.multiSigners ?? []).map(
632
- (signer) => ({
633
- address: signer.address,
634
- role: kit.AccountRole.READONLY_SIGNER,
635
- signer
636
- })
637
- );
461
+ const remainingAccounts = (args.multiSigners ?? []).map((signer) => ({
462
+ address: signer.address,
463
+ role: kit.AccountRole.READONLY_SIGNER,
464
+ signer
465
+ }));
638
466
  const getAccountMeta = getAccountMetaFactory(programAddress);
639
467
  return Object.freeze({
640
468
  accounts: [
@@ -649,9 +477,7 @@ function getUnwrapInstruction(input, config) {
649
477
  getAccountMeta(accounts.transferAuthority),
650
478
  ...remainingAccounts
651
479
  ],
652
- data: getUnwrapInstructionDataEncoder().encode(
653
- args
654
- ),
480
+ data: getUnwrapInstructionDataEncoder().encode(args),
655
481
  programAddress
656
482
  });
657
483
  }
@@ -701,51 +527,28 @@ function getWrapInstructionDataDecoder() {
701
527
  ]);
702
528
  }
703
529
  function getWrapInstructionDataCodec() {
704
- return kit.combineCodec(
705
- getWrapInstructionDataEncoder(),
706
- getWrapInstructionDataDecoder()
707
- );
530
+ return kit.combineCodec(getWrapInstructionDataEncoder(), getWrapInstructionDataDecoder());
708
531
  }
709
532
  function getWrapInstruction(input, config) {
710
533
  const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
711
534
  const originalAccounts = {
712
- recipientWrappedTokenAccount: {
713
- value: input.recipientWrappedTokenAccount ?? null,
714
- isWritable: true
715
- },
535
+ recipientWrappedTokenAccount: { value: input.recipientWrappedTokenAccount ?? null, isWritable: true },
716
536
  wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
717
- wrappedMintAuthority: {
718
- value: input.wrappedMintAuthority ?? null,
719
- isWritable: false
720
- },
721
- unwrappedTokenProgram: {
722
- value: input.unwrappedTokenProgram ?? null,
723
- isWritable: false
724
- },
725
- wrappedTokenProgram: {
726
- value: input.wrappedTokenProgram ?? null,
727
- isWritable: false
728
- },
729
- unwrappedTokenAccount: {
730
- value: input.unwrappedTokenAccount ?? null,
731
- isWritable: true
732
- },
537
+ wrappedMintAuthority: { value: input.wrappedMintAuthority ?? null, isWritable: false },
538
+ unwrappedTokenProgram: { value: input.unwrappedTokenProgram ?? null, isWritable: false },
539
+ wrappedTokenProgram: { value: input.wrappedTokenProgram ?? null, isWritable: false },
540
+ unwrappedTokenAccount: { value: input.unwrappedTokenAccount ?? null, isWritable: true },
733
541
  unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
734
542
  unwrappedEscrow: { value: input.unwrappedEscrow ?? null, isWritable: true },
735
- transferAuthority: {
736
- value: input.transferAuthority ?? null,
737
- isWritable: false
738
- }
543
+ transferAuthority: { value: input.transferAuthority ?? null, isWritable: false }
739
544
  };
740
545
  const accounts = originalAccounts;
741
546
  const args = { ...input };
742
- const remainingAccounts = (args.multiSigners ?? []).map(
743
- (signer) => ({
744
- address: signer.address,
745
- role: kit.AccountRole.READONLY_SIGNER,
746
- signer
747
- })
748
- );
547
+ const remainingAccounts = (args.multiSigners ?? []).map((signer) => ({
548
+ address: signer.address,
549
+ role: kit.AccountRole.READONLY_SIGNER,
550
+ signer
551
+ }));
749
552
  const getAccountMeta = getAccountMetaFactory(programAddress);
750
553
  return Object.freeze({
751
554
  accounts: [
@@ -760,9 +563,7 @@ function getWrapInstruction(input, config) {
760
563
  getAccountMeta(accounts.transferAuthority),
761
564
  ...remainingAccounts
762
565
  ],
763
- data: getWrapInstructionDataEncoder().encode(
764
- args
765
- ),
566
+ data: getWrapInstructionDataEncoder().encode(args),
766
567
  programAddress
767
568
  });
768
569
  }
@@ -792,6 +593,132 @@ function parseWrapInstruction(instruction) {
792
593
  data: getWrapInstructionDataDecoder().decode(instruction.data)
793
594
  };
794
595
  }
596
+
597
+ // src/generated/programs/tokenWrap.ts
598
+ var TOKEN_WRAP_PROGRAM_ADDRESS = "TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR";
599
+ var TokenWrapAccount = /* @__PURE__ */ ((TokenWrapAccount2) => {
600
+ TokenWrapAccount2[TokenWrapAccount2["Backpointer"] = 0] = "Backpointer";
601
+ return TokenWrapAccount2;
602
+ })(TokenWrapAccount || {});
603
+ var TokenWrapInstruction = /* @__PURE__ */ ((TokenWrapInstruction2) => {
604
+ TokenWrapInstruction2[TokenWrapInstruction2["CreateMint"] = 0] = "CreateMint";
605
+ TokenWrapInstruction2[TokenWrapInstruction2["Wrap"] = 1] = "Wrap";
606
+ TokenWrapInstruction2[TokenWrapInstruction2["Unwrap"] = 2] = "Unwrap";
607
+ TokenWrapInstruction2[TokenWrapInstruction2["CloseStuckEscrow"] = 3] = "CloseStuckEscrow";
608
+ TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToToken2022"] = 4] = "SyncMetadataToToken2022";
609
+ TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToSplToken"] = 5] = "SyncMetadataToSplToken";
610
+ return TokenWrapInstruction2;
611
+ })(TokenWrapInstruction || {});
612
+ function identifyTokenWrapInstruction(instruction) {
613
+ const data = "data" in instruction ? instruction.data : instruction;
614
+ if (kit.containsBytes(data, kit.getU8Encoder().encode(0), 0)) {
615
+ return 0 /* CreateMint */;
616
+ }
617
+ if (kit.containsBytes(data, kit.getU8Encoder().encode(1), 0)) {
618
+ return 1 /* Wrap */;
619
+ }
620
+ if (kit.containsBytes(data, kit.getU8Encoder().encode(2), 0)) {
621
+ return 2 /* Unwrap */;
622
+ }
623
+ if (kit.containsBytes(data, kit.getU8Encoder().encode(3), 0)) {
624
+ return 3 /* CloseStuckEscrow */;
625
+ }
626
+ if (kit.containsBytes(data, kit.getU8Encoder().encode(4), 0)) {
627
+ return 4 /* SyncMetadataToToken2022 */;
628
+ }
629
+ if (kit.containsBytes(data, kit.getU8Encoder().encode(5), 0)) {
630
+ return 5 /* SyncMetadataToSplToken */;
631
+ }
632
+ throw new Error("The provided instruction could not be identified as a tokenWrap instruction.");
633
+ }
634
+ function parseTokenWrapInstruction(instruction) {
635
+ const instructionType = identifyTokenWrapInstruction(instruction);
636
+ switch (instructionType) {
637
+ case 0 /* CreateMint */: {
638
+ kit.assertIsInstructionWithAccounts(instruction);
639
+ return { instructionType: 0 /* CreateMint */, ...parseCreateMintInstruction(instruction) };
640
+ }
641
+ case 1 /* Wrap */: {
642
+ kit.assertIsInstructionWithAccounts(instruction);
643
+ return { instructionType: 1 /* Wrap */, ...parseWrapInstruction(instruction) };
644
+ }
645
+ case 2 /* Unwrap */: {
646
+ kit.assertIsInstructionWithAccounts(instruction);
647
+ return { instructionType: 2 /* Unwrap */, ...parseUnwrapInstruction(instruction) };
648
+ }
649
+ case 3 /* CloseStuckEscrow */: {
650
+ kit.assertIsInstructionWithAccounts(instruction);
651
+ return {
652
+ instructionType: 3 /* CloseStuckEscrow */,
653
+ ...parseCloseStuckEscrowInstruction(instruction)
654
+ };
655
+ }
656
+ case 4 /* SyncMetadataToToken2022 */: {
657
+ kit.assertIsInstructionWithAccounts(instruction);
658
+ return {
659
+ instructionType: 4 /* SyncMetadataToToken2022 */,
660
+ ...parseSyncMetadataToToken2022Instruction(instruction)
661
+ };
662
+ }
663
+ case 5 /* SyncMetadataToSplToken */: {
664
+ kit.assertIsInstructionWithAccounts(instruction);
665
+ return {
666
+ instructionType: 5 /* SyncMetadataToSplToken */,
667
+ ...parseSyncMetadataToSplTokenInstruction(instruction)
668
+ };
669
+ }
670
+ default:
671
+ throw new Error(`Unrecognized instruction type: ${instructionType}`);
672
+ }
673
+ }
674
+
675
+ // src/generated/errors/tokenWrap.ts
676
+ var TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH = 0;
677
+ var TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH = 1;
678
+ var TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT = 2;
679
+ var TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH = 3;
680
+ var TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = 4;
681
+ var TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = 5;
682
+ var TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = 6;
683
+ var TOKEN_WRAP_ERROR__ESCROW_MISMATCH = 7;
684
+ var TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE = 8;
685
+ var TOKEN_WRAP_ERROR__UNWRAPPED_MINT_HAS_NO_METADATA = 9;
686
+ var TOKEN_WRAP_ERROR__METAPLEX_METADATA_MISMATCH = 10;
687
+ var TOKEN_WRAP_ERROR__METADATA_POINTER_MISSING = 11;
688
+ var TOKEN_WRAP_ERROR__METADATA_POINTER_UNSET = 12;
689
+ var TOKEN_WRAP_ERROR__METADATA_POINTER_MISMATCH = 13;
690
+ var TOKEN_WRAP_ERROR__EXTERNAL_PROGRAM_RETURNED_NO_DATA = 14;
691
+ var TOKEN_WRAP_ERROR__NO_SYNCING_TO_TOKEN2022 = 15;
692
+ var tokenWrapErrorMessages;
693
+ if (process.env.NODE_ENV !== "production") {
694
+ tokenWrapErrorMessages = {
695
+ [TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH]: `Wrapped backpointer account address does not match expected PDA`,
696
+ [TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE]: `The escrow account is in a good state and cannot be recreated`,
697
+ [TOKEN_WRAP_ERROR__ESCROW_MISMATCH]: `Escrow account address does not match expected ATA`,
698
+ [TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH]: `Unwrapped escrow token owner is not set to expected PDA`,
699
+ [TOKEN_WRAP_ERROR__EXTERNAL_PROGRAM_RETURNED_NO_DATA]: `External metadata program returned no data`,
700
+ [TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER]: `Wrapped backpointer account owner is not the expected token wrap program`,
701
+ [TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER]: `Wrapped mint account owner is not the expected token program`,
702
+ [TOKEN_WRAP_ERROR__METADATA_POINTER_MISMATCH]: `Provided source metadata account does not match pointer`,
703
+ [TOKEN_WRAP_ERROR__METADATA_POINTER_MISSING]: `Metadata pointer extension missing on mint`,
704
+ [TOKEN_WRAP_ERROR__METADATA_POINTER_UNSET]: `Metadata pointer is unset (None)`,
705
+ [TOKEN_WRAP_ERROR__METAPLEX_METADATA_MISMATCH]: `Metaplex metadata account address does not match expected PDA`,
706
+ [TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH]: `Wrapped mint authority does not match expected PDA`,
707
+ [TOKEN_WRAP_ERROR__NO_SYNCING_TO_TOKEN2022]: `Instruction can only be used with spl-token wrapped mints`,
708
+ [TOKEN_WRAP_ERROR__UNWRAPPED_MINT_HAS_NO_METADATA]: `Unwrapped mint does not have the TokenMetadata extension`,
709
+ [TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH]: `Wrapped mint account address does not match expected PDA`,
710
+ [TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT]: `Wrap amount should be positive`
711
+ };
712
+ }
713
+ function getTokenWrapErrorMessage(code) {
714
+ if (process.env.NODE_ENV !== "production") {
715
+ return tokenWrapErrorMessages[code];
716
+ }
717
+ return "Error message not available in production bundles.";
718
+ }
719
+ function isTokenWrapError(error, transactionMessage, code) {
720
+ return kit.isProgramError(error, transactionMessage, TOKEN_WRAP_PROGRAM_ADDRESS, code);
721
+ }
795
722
  var DEFAULT_EXTENSIONS = [
796
723
  token2022.extension("ConfidentialTransferMint", {
797
724
  autoApproveNewAccounts: true,
@@ -964,6 +891,8 @@ function combinedMultisigTx({
964
891
  kit.assertIsSendableTransaction(tx);
965
892
  return tx;
966
893
  }
894
+
895
+ // src/wrap.ts
967
896
  async function multisigOfflineSignWrap(args) {
968
897
  const wrapIx = await buildWrapIx(args);
969
898
  return kit.pipe(
@@ -1284,6 +1213,7 @@ exports.parseCloseStuckEscrowInstruction = parseCloseStuckEscrowInstruction;
1284
1213
  exports.parseCreateMintInstruction = parseCreateMintInstruction;
1285
1214
  exports.parseSyncMetadataToSplTokenInstruction = parseSyncMetadataToSplTokenInstruction;
1286
1215
  exports.parseSyncMetadataToToken2022Instruction = parseSyncMetadataToToken2022Instruction;
1216
+ exports.parseTokenWrapInstruction = parseTokenWrapInstruction;
1287
1217
  exports.parseUnwrapInstruction = parseUnwrapInstruction;
1288
1218
  exports.parseWrapInstruction = parseWrapInstruction;
1289
1219
  exports.singleSignerUnwrap = singleSignerUnwrap;