@solana-program/token-wrap 2.0.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 +346 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +320 -6
- package/dist/src/index.mjs.map +1 -1
- package/dist/types/create-mint.d.ts +2 -2
- package/dist/types/examples/sync-spl-to-token2022.d.ts +1 -0
- package/dist/types/examples/sync-token2022-to-spl.d.ts +1 -0
- package/dist/types/generated/accounts/backpointer.d.ts +4 -4
- package/dist/types/generated/errors/tokenWrap.d.ts +9 -1
- package/dist/types/generated/instructions/closeStuckEscrow.d.ts +63 -0
- package/dist/types/generated/instructions/createMint.d.ts +8 -8
- package/dist/types/generated/instructions/index.d.ts +3 -0
- package/dist/types/generated/instructions/syncMetadataToSplToken.d.ts +92 -0
- package/dist/types/generated/instructions/syncMetadataToToken2022.d.ts +75 -0
- package/dist/types/generated/instructions/unwrap.d.ts +9 -9
- package/dist/types/generated/instructions/wrap.d.ts +9 -9
- package/dist/types/generated/programs/tokenWrap.d.ts +12 -3
- package/dist/types/generated/shared/index.d.ts +3 -3
- package/dist/types/unwrap.d.ts +3 -3
- package/dist/types/utilities.d.ts +4 -4
- package/dist/types/wrap.d.ts +3 -3
- package/package.json +16 -16
package/dist/src/index.js
CHANGED
|
@@ -100,6 +100,9 @@ var TokenWrapInstruction = /* @__PURE__ */ ((TokenWrapInstruction2) => {
|
|
|
100
100
|
TokenWrapInstruction2[TokenWrapInstruction2["CreateMint"] = 0] = "CreateMint";
|
|
101
101
|
TokenWrapInstruction2[TokenWrapInstruction2["Wrap"] = 1] = "Wrap";
|
|
102
102
|
TokenWrapInstruction2[TokenWrapInstruction2["Unwrap"] = 2] = "Unwrap";
|
|
103
|
+
TokenWrapInstruction2[TokenWrapInstruction2["CloseStuckEscrow"] = 3] = "CloseStuckEscrow";
|
|
104
|
+
TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToToken2022"] = 4] = "SyncMetadataToToken2022";
|
|
105
|
+
TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToSplToken"] = 5] = "SyncMetadataToSplToken";
|
|
103
106
|
return TokenWrapInstruction2;
|
|
104
107
|
})(TokenWrapInstruction || {});
|
|
105
108
|
function identifyTokenWrapInstruction(instruction) {
|
|
@@ -113,6 +116,15 @@ function identifyTokenWrapInstruction(instruction) {
|
|
|
113
116
|
if (kit.containsBytes(data, kit.getU8Encoder().encode(2), 0)) {
|
|
114
117
|
return 2 /* Unwrap */;
|
|
115
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
|
+
}
|
|
116
128
|
throw new Error(
|
|
117
129
|
"The provided instruction could not be identified as a tokenWrap instruction."
|
|
118
130
|
);
|
|
@@ -127,15 +139,31 @@ var TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = 4;
|
|
|
127
139
|
var TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = 5;
|
|
128
140
|
var TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = 6;
|
|
129
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;
|
|
130
150
|
var tokenWrapErrorMessages;
|
|
131
151
|
if (process.env.NODE_ENV !== "production") {
|
|
132
152
|
tokenWrapErrorMessages = {
|
|
133
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`,
|
|
134
155
|
[TOKEN_WRAP_ERROR__ESCROW_MISMATCH]: `Escrow account address does not match expected ATA`,
|
|
135
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`,
|
|
136
158
|
[TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER]: `Wrapped backpointer account owner is not the expected token wrap program`,
|
|
137
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`,
|
|
138
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`,
|
|
139
167
|
[TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH]: `Wrapped mint account address does not match expected PDA`,
|
|
140
168
|
[TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT]: `Wrap amount should be positive`
|
|
141
169
|
};
|
|
@@ -186,7 +214,88 @@ function isTransactionSigner(value) {
|
|
|
186
214
|
return !!value && typeof value === "object" && "address" in value && kit.isTransactionSigner(value);
|
|
187
215
|
}
|
|
188
216
|
|
|
189
|
-
// src/generated/instructions/
|
|
217
|
+
// src/generated/instructions/closeStuckEscrow.ts
|
|
218
|
+
var CLOSE_STUCK_ESCROW_DISCRIMINATOR = 3;
|
|
219
|
+
function getCloseStuckEscrowDiscriminatorBytes() {
|
|
220
|
+
return kit.getU8Encoder().encode(CLOSE_STUCK_ESCROW_DISCRIMINATOR);
|
|
221
|
+
}
|
|
222
|
+
function getCloseStuckEscrowInstructionDataEncoder() {
|
|
223
|
+
return kit.transformEncoder(
|
|
224
|
+
kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]),
|
|
225
|
+
(value) => ({ ...value, discriminator: CLOSE_STUCK_ESCROW_DISCRIMINATOR })
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
function getCloseStuckEscrowInstructionDataDecoder() {
|
|
229
|
+
return kit.getStructDecoder([["discriminator", kit.getU8Decoder()]]);
|
|
230
|
+
}
|
|
231
|
+
function getCloseStuckEscrowInstructionDataCodec() {
|
|
232
|
+
return kit.combineCodec(
|
|
233
|
+
getCloseStuckEscrowInstructionDataEncoder(),
|
|
234
|
+
getCloseStuckEscrowInstructionDataDecoder()
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
function getCloseStuckEscrowInstruction(input, config) {
|
|
238
|
+
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
239
|
+
const originalAccounts = {
|
|
240
|
+
escrow: { value: input.escrow ?? null, isWritable: true },
|
|
241
|
+
destination: { value: input.destination ?? null, isWritable: true },
|
|
242
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
243
|
+
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
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const accounts = originalAccounts;
|
|
254
|
+
if (!accounts.token2022Program.value) {
|
|
255
|
+
accounts.token2022Program.value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
256
|
+
}
|
|
257
|
+
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
258
|
+
const instruction = {
|
|
259
|
+
accounts: [
|
|
260
|
+
getAccountMeta(accounts.escrow),
|
|
261
|
+
getAccountMeta(accounts.destination),
|
|
262
|
+
getAccountMeta(accounts.unwrappedMint),
|
|
263
|
+
getAccountMeta(accounts.wrappedMint),
|
|
264
|
+
getAccountMeta(accounts.wrappedMintAuthority),
|
|
265
|
+
getAccountMeta(accounts.token2022Program)
|
|
266
|
+
],
|
|
267
|
+
programAddress,
|
|
268
|
+
data: getCloseStuckEscrowInstructionDataEncoder().encode({})
|
|
269
|
+
};
|
|
270
|
+
return instruction;
|
|
271
|
+
}
|
|
272
|
+
function parseCloseStuckEscrowInstruction(instruction) {
|
|
273
|
+
if (instruction.accounts.length < 6) {
|
|
274
|
+
throw new Error("Not enough accounts");
|
|
275
|
+
}
|
|
276
|
+
let accountIndex = 0;
|
|
277
|
+
const getNextAccount = () => {
|
|
278
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
279
|
+
accountIndex += 1;
|
|
280
|
+
return accountMeta;
|
|
281
|
+
};
|
|
282
|
+
const getNextOptionalAccount = () => {
|
|
283
|
+
const accountMeta = getNextAccount();
|
|
284
|
+
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
285
|
+
};
|
|
286
|
+
return {
|
|
287
|
+
programAddress: instruction.programAddress,
|
|
288
|
+
accounts: {
|
|
289
|
+
escrow: getNextAccount(),
|
|
290
|
+
destination: getNextAccount(),
|
|
291
|
+
unwrappedMint: getNextAccount(),
|
|
292
|
+
wrappedMint: getNextAccount(),
|
|
293
|
+
wrappedMintAuthority: getNextAccount(),
|
|
294
|
+
token2022Program: getNextOptionalAccount()
|
|
295
|
+
},
|
|
296
|
+
data: getCloseStuckEscrowInstructionDataDecoder().decode(instruction.data)
|
|
297
|
+
};
|
|
298
|
+
}
|
|
190
299
|
var CREATE_MINT_DISCRIMINATOR = 0;
|
|
191
300
|
function getCreateMintDiscriminatorBytes() {
|
|
192
301
|
return kit.getU8Encoder().encode(CREATE_MINT_DISCRIMINATOR);
|
|
@@ -275,6 +384,196 @@ function parseCreateMintInstruction(instruction) {
|
|
|
275
384
|
data: getCreateMintInstructionDataDecoder().decode(instruction.data)
|
|
276
385
|
};
|
|
277
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
|
+
}
|
|
278
577
|
var UNWRAP_DISCRIMINATOR = 2;
|
|
279
578
|
function getUnwrapDiscriminatorBytes() {
|
|
280
579
|
return kit.getU8Encoder().encode(UNWRAP_DISCRIMINATOR);
|
|
@@ -499,6 +798,17 @@ function parseWrapInstruction(instruction) {
|
|
|
499
798
|
data: getWrapInstructionDataDecoder().decode(instruction.data)
|
|
500
799
|
};
|
|
501
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
|
+
];
|
|
502
812
|
async function createMint({
|
|
503
813
|
rpc,
|
|
504
814
|
unwrappedMint,
|
|
@@ -513,7 +823,10 @@ async function createMint({
|
|
|
513
823
|
const [backpointer] = await findBackpointerPda({ wrappedMint });
|
|
514
824
|
const instructions = [];
|
|
515
825
|
let fundedWrappedMintLamports = 0n;
|
|
516
|
-
|
|
826
|
+
let mintSize = BigInt(token2022.getMintSize());
|
|
827
|
+
if (wrappedTokenProgram === token2022.TOKEN_2022_PROGRAM_ADDRESS) {
|
|
828
|
+
mintSize = BigInt(token2022.getMintSize(DEFAULT_EXTENSIONS));
|
|
829
|
+
}
|
|
517
830
|
const [wrappedMintAccount, wrappedMintRent] = await Promise.all([
|
|
518
831
|
kit.fetchEncodedAccount(rpc, wrappedMint),
|
|
519
832
|
rpc.getMinimumBalanceForRentExemption(mintSize).send()
|
|
@@ -653,7 +966,8 @@ function combinedMultisigTx({
|
|
|
653
966
|
signatures: combineSignatures(signedTxs),
|
|
654
967
|
lifetimeConstraint: blockhash
|
|
655
968
|
};
|
|
656
|
-
kit.
|
|
969
|
+
kit.assertIsFullySignedTransaction(tx);
|
|
970
|
+
kit.assertIsSendableTransaction(tx);
|
|
657
971
|
return tx;
|
|
658
972
|
}
|
|
659
973
|
async function multisigOfflineSignWrap(args) {
|
|
@@ -895,13 +1209,24 @@ async function multisigOfflineSignUnwrap(args) {
|
|
|
895
1209
|
);
|
|
896
1210
|
}
|
|
897
1211
|
|
|
1212
|
+
exports.CLOSE_STUCK_ESCROW_DISCRIMINATOR = CLOSE_STUCK_ESCROW_DISCRIMINATOR;
|
|
898
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;
|
|
899
1216
|
exports.TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH = TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH;
|
|
1217
|
+
exports.TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE = TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE;
|
|
900
1218
|
exports.TOKEN_WRAP_ERROR__ESCROW_MISMATCH = TOKEN_WRAP_ERROR__ESCROW_MISMATCH;
|
|
901
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;
|
|
902
1221
|
exports.TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER;
|
|
903
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;
|
|
904
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;
|
|
905
1230
|
exports.TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH = TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH;
|
|
906
1231
|
exports.TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT = TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT;
|
|
907
1232
|
exports.TOKEN_WRAP_PROGRAM_ADDRESS = TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
@@ -926,11 +1251,26 @@ exports.getBackpointerCodec = getBackpointerCodec;
|
|
|
926
1251
|
exports.getBackpointerDecoder = getBackpointerDecoder;
|
|
927
1252
|
exports.getBackpointerEncoder = getBackpointerEncoder;
|
|
928
1253
|
exports.getBackpointerSize = getBackpointerSize;
|
|
1254
|
+
exports.getCloseStuckEscrowDiscriminatorBytes = getCloseStuckEscrowDiscriminatorBytes;
|
|
1255
|
+
exports.getCloseStuckEscrowInstruction = getCloseStuckEscrowInstruction;
|
|
1256
|
+
exports.getCloseStuckEscrowInstructionDataCodec = getCloseStuckEscrowInstructionDataCodec;
|
|
1257
|
+
exports.getCloseStuckEscrowInstructionDataDecoder = getCloseStuckEscrowInstructionDataDecoder;
|
|
1258
|
+
exports.getCloseStuckEscrowInstructionDataEncoder = getCloseStuckEscrowInstructionDataEncoder;
|
|
929
1259
|
exports.getCreateMintDiscriminatorBytes = getCreateMintDiscriminatorBytes;
|
|
930
1260
|
exports.getCreateMintInstruction = getCreateMintInstruction;
|
|
931
1261
|
exports.getCreateMintInstructionDataCodec = getCreateMintInstructionDataCodec;
|
|
932
1262
|
exports.getCreateMintInstructionDataDecoder = getCreateMintInstructionDataDecoder;
|
|
933
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;
|
|
934
1274
|
exports.getTokenWrapErrorMessage = getTokenWrapErrorMessage;
|
|
935
1275
|
exports.getUnwrapDiscriminatorBytes = getUnwrapDiscriminatorBytes;
|
|
936
1276
|
exports.getUnwrapInstruction = getUnwrapInstruction;
|
|
@@ -946,7 +1286,10 @@ exports.identifyTokenWrapInstruction = identifyTokenWrapInstruction;
|
|
|
946
1286
|
exports.isTokenWrapError = isTokenWrapError;
|
|
947
1287
|
exports.multisigOfflineSignUnwrap = multisigOfflineSignUnwrap;
|
|
948
1288
|
exports.multisigOfflineSignWrap = multisigOfflineSignWrap;
|
|
1289
|
+
exports.parseCloseStuckEscrowInstruction = parseCloseStuckEscrowInstruction;
|
|
949
1290
|
exports.parseCreateMintInstruction = parseCreateMintInstruction;
|
|
1291
|
+
exports.parseSyncMetadataToSplTokenInstruction = parseSyncMetadataToSplTokenInstruction;
|
|
1292
|
+
exports.parseSyncMetadataToToken2022Instruction = parseSyncMetadataToToken2022Instruction;
|
|
950
1293
|
exports.parseUnwrapInstruction = parseUnwrapInstruction;
|
|
951
1294
|
exports.parseWrapInstruction = parseWrapInstruction;
|
|
952
1295
|
exports.singleSignerUnwrap = singleSignerUnwrap;
|