@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.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getProgramDerivedAddress, getUtf8Encoder, getAddressEncoder, getStructEncoder, getStructDecoder, getAddressDecoder, combineCodec, decodeAccount, assertAccountExists, fetchEncodedAccount, assertAccountsExist, fetchEncodedAccounts, containsBytes, getU8Encoder, isProgramError, transformEncoder,
|
|
2
|
-
import { getMintSize, findAssociatedTokenPda, fetchMaybeToken, getCreateAssociatedTokenInstruction, getTokenDecoder } from '@solana-program/token-2022';
|
|
1
|
+
import { getProgramDerivedAddress, getUtf8Encoder, getAddressEncoder, getStructEncoder, getStructDecoder, getAddressDecoder, combineCodec, decodeAccount, assertAccountExists, fetchEncodedAccount, assertAccountsExist, fetchEncodedAccounts, containsBytes, getU8Encoder, isProgramError, transformEncoder, getU8Decoder, getBooleanEncoder, getBooleanDecoder, getU64Encoder, getU64Decoder, AccountRole, assertIsFullySignedTransaction, assertIsSendableTransaction, pipe, createTransactionMessage, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstructions, upgradeRoleToSigner, isTransactionSigner as isTransactionSigner$1 } from '@solana/kit';
|
|
2
|
+
import { extension, getMintSize, TOKEN_2022_PROGRAM_ADDRESS, findAssociatedTokenPda, fetchMaybeToken, getCreateAssociatedTokenInstruction, getTokenDecoder } from '@solana-program/token-2022';
|
|
3
3
|
import { getTransferSolInstruction } from '@solana-program/system';
|
|
4
4
|
import '@solana-program/token';
|
|
5
5
|
|
|
@@ -98,6 +98,9 @@ var TokenWrapInstruction = /* @__PURE__ */ ((TokenWrapInstruction2) => {
|
|
|
98
98
|
TokenWrapInstruction2[TokenWrapInstruction2["CreateMint"] = 0] = "CreateMint";
|
|
99
99
|
TokenWrapInstruction2[TokenWrapInstruction2["Wrap"] = 1] = "Wrap";
|
|
100
100
|
TokenWrapInstruction2[TokenWrapInstruction2["Unwrap"] = 2] = "Unwrap";
|
|
101
|
+
TokenWrapInstruction2[TokenWrapInstruction2["CloseStuckEscrow"] = 3] = "CloseStuckEscrow";
|
|
102
|
+
TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToToken2022"] = 4] = "SyncMetadataToToken2022";
|
|
103
|
+
TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToSplToken"] = 5] = "SyncMetadataToSplToken";
|
|
101
104
|
return TokenWrapInstruction2;
|
|
102
105
|
})(TokenWrapInstruction || {});
|
|
103
106
|
function identifyTokenWrapInstruction(instruction) {
|
|
@@ -111,6 +114,15 @@ function identifyTokenWrapInstruction(instruction) {
|
|
|
111
114
|
if (containsBytes(data, getU8Encoder().encode(2), 0)) {
|
|
112
115
|
return 2 /* Unwrap */;
|
|
113
116
|
}
|
|
117
|
+
if (containsBytes(data, getU8Encoder().encode(3), 0)) {
|
|
118
|
+
return 3 /* CloseStuckEscrow */;
|
|
119
|
+
}
|
|
120
|
+
if (containsBytes(data, getU8Encoder().encode(4), 0)) {
|
|
121
|
+
return 4 /* SyncMetadataToToken2022 */;
|
|
122
|
+
}
|
|
123
|
+
if (containsBytes(data, getU8Encoder().encode(5), 0)) {
|
|
124
|
+
return 5 /* SyncMetadataToSplToken */;
|
|
125
|
+
}
|
|
114
126
|
throw new Error(
|
|
115
127
|
"The provided instruction could not be identified as a tokenWrap instruction."
|
|
116
128
|
);
|
|
@@ -125,15 +137,31 @@ var TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = 4;
|
|
|
125
137
|
var TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = 5;
|
|
126
138
|
var TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = 6;
|
|
127
139
|
var TOKEN_WRAP_ERROR__ESCROW_MISMATCH = 7;
|
|
140
|
+
var TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE = 8;
|
|
141
|
+
var TOKEN_WRAP_ERROR__UNWRAPPED_MINT_HAS_NO_METADATA = 9;
|
|
142
|
+
var TOKEN_WRAP_ERROR__METAPLEX_METADATA_MISMATCH = 10;
|
|
143
|
+
var TOKEN_WRAP_ERROR__METADATA_POINTER_MISSING = 11;
|
|
144
|
+
var TOKEN_WRAP_ERROR__METADATA_POINTER_UNSET = 12;
|
|
145
|
+
var TOKEN_WRAP_ERROR__METADATA_POINTER_MISMATCH = 13;
|
|
146
|
+
var TOKEN_WRAP_ERROR__EXTERNAL_PROGRAM_RETURNED_NO_DATA = 14;
|
|
147
|
+
var TOKEN_WRAP_ERROR__NO_SYNCING_TO_TOKEN2022 = 15;
|
|
128
148
|
var tokenWrapErrorMessages;
|
|
129
149
|
if (process.env.NODE_ENV !== "production") {
|
|
130
150
|
tokenWrapErrorMessages = {
|
|
131
151
|
[TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH]: `Wrapped backpointer account address does not match expected PDA`,
|
|
152
|
+
[TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE]: `The escrow account is in a good state and cannot be recreated`,
|
|
132
153
|
[TOKEN_WRAP_ERROR__ESCROW_MISMATCH]: `Escrow account address does not match expected ATA`,
|
|
133
154
|
[TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH]: `Unwrapped escrow token owner is not set to expected PDA`,
|
|
155
|
+
[TOKEN_WRAP_ERROR__EXTERNAL_PROGRAM_RETURNED_NO_DATA]: `External metadata program returned no data`,
|
|
134
156
|
[TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER]: `Wrapped backpointer account owner is not the expected token wrap program`,
|
|
135
157
|
[TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER]: `Wrapped mint account owner is not the expected token program`,
|
|
158
|
+
[TOKEN_WRAP_ERROR__METADATA_POINTER_MISMATCH]: `Provided source metadata account does not match pointer`,
|
|
159
|
+
[TOKEN_WRAP_ERROR__METADATA_POINTER_MISSING]: `Metadata pointer extension missing on mint`,
|
|
160
|
+
[TOKEN_WRAP_ERROR__METADATA_POINTER_UNSET]: `Metadata pointer is unset (None)`,
|
|
161
|
+
[TOKEN_WRAP_ERROR__METAPLEX_METADATA_MISMATCH]: `Metaplex metadata account address does not match expected PDA`,
|
|
136
162
|
[TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH]: `Wrapped mint authority does not match expected PDA`,
|
|
163
|
+
[TOKEN_WRAP_ERROR__NO_SYNCING_TO_TOKEN2022]: `Instruction can only be used with spl-token wrapped mints`,
|
|
164
|
+
[TOKEN_WRAP_ERROR__UNWRAPPED_MINT_HAS_NO_METADATA]: `Unwrapped mint does not have the TokenMetadata extension`,
|
|
137
165
|
[TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH]: `Wrapped mint account address does not match expected PDA`,
|
|
138
166
|
[TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT]: `Wrap amount should be positive`
|
|
139
167
|
};
|
|
@@ -184,7 +212,88 @@ function isTransactionSigner(value) {
|
|
|
184
212
|
return !!value && typeof value === "object" && "address" in value && isTransactionSigner$1(value);
|
|
185
213
|
}
|
|
186
214
|
|
|
187
|
-
// src/generated/instructions/
|
|
215
|
+
// src/generated/instructions/closeStuckEscrow.ts
|
|
216
|
+
var CLOSE_STUCK_ESCROW_DISCRIMINATOR = 3;
|
|
217
|
+
function getCloseStuckEscrowDiscriminatorBytes() {
|
|
218
|
+
return getU8Encoder().encode(CLOSE_STUCK_ESCROW_DISCRIMINATOR);
|
|
219
|
+
}
|
|
220
|
+
function getCloseStuckEscrowInstructionDataEncoder() {
|
|
221
|
+
return transformEncoder(
|
|
222
|
+
getStructEncoder([["discriminator", getU8Encoder()]]),
|
|
223
|
+
(value) => ({ ...value, discriminator: CLOSE_STUCK_ESCROW_DISCRIMINATOR })
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
function getCloseStuckEscrowInstructionDataDecoder() {
|
|
227
|
+
return getStructDecoder([["discriminator", getU8Decoder()]]);
|
|
228
|
+
}
|
|
229
|
+
function getCloseStuckEscrowInstructionDataCodec() {
|
|
230
|
+
return combineCodec(
|
|
231
|
+
getCloseStuckEscrowInstructionDataEncoder(),
|
|
232
|
+
getCloseStuckEscrowInstructionDataDecoder()
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
function getCloseStuckEscrowInstruction(input, config) {
|
|
236
|
+
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
237
|
+
const originalAccounts = {
|
|
238
|
+
escrow: { value: input.escrow ?? null, isWritable: true },
|
|
239
|
+
destination: { value: input.destination ?? null, isWritable: true },
|
|
240
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
241
|
+
wrappedMint: { value: input.wrappedMint ?? null, isWritable: false },
|
|
242
|
+
wrappedMintAuthority: {
|
|
243
|
+
value: input.wrappedMintAuthority ?? null,
|
|
244
|
+
isWritable: false
|
|
245
|
+
},
|
|
246
|
+
token2022Program: {
|
|
247
|
+
value: input.token2022Program ?? null,
|
|
248
|
+
isWritable: false
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
const accounts = originalAccounts;
|
|
252
|
+
if (!accounts.token2022Program.value) {
|
|
253
|
+
accounts.token2022Program.value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
254
|
+
}
|
|
255
|
+
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
256
|
+
const instruction = {
|
|
257
|
+
accounts: [
|
|
258
|
+
getAccountMeta(accounts.escrow),
|
|
259
|
+
getAccountMeta(accounts.destination),
|
|
260
|
+
getAccountMeta(accounts.unwrappedMint),
|
|
261
|
+
getAccountMeta(accounts.wrappedMint),
|
|
262
|
+
getAccountMeta(accounts.wrappedMintAuthority),
|
|
263
|
+
getAccountMeta(accounts.token2022Program)
|
|
264
|
+
],
|
|
265
|
+
programAddress,
|
|
266
|
+
data: getCloseStuckEscrowInstructionDataEncoder().encode({})
|
|
267
|
+
};
|
|
268
|
+
return instruction;
|
|
269
|
+
}
|
|
270
|
+
function parseCloseStuckEscrowInstruction(instruction) {
|
|
271
|
+
if (instruction.accounts.length < 6) {
|
|
272
|
+
throw new Error("Not enough accounts");
|
|
273
|
+
}
|
|
274
|
+
let accountIndex = 0;
|
|
275
|
+
const getNextAccount = () => {
|
|
276
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
277
|
+
accountIndex += 1;
|
|
278
|
+
return accountMeta;
|
|
279
|
+
};
|
|
280
|
+
const getNextOptionalAccount = () => {
|
|
281
|
+
const accountMeta = getNextAccount();
|
|
282
|
+
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
283
|
+
};
|
|
284
|
+
return {
|
|
285
|
+
programAddress: instruction.programAddress,
|
|
286
|
+
accounts: {
|
|
287
|
+
escrow: getNextAccount(),
|
|
288
|
+
destination: getNextAccount(),
|
|
289
|
+
unwrappedMint: getNextAccount(),
|
|
290
|
+
wrappedMint: getNextAccount(),
|
|
291
|
+
wrappedMintAuthority: getNextAccount(),
|
|
292
|
+
token2022Program: getNextOptionalAccount()
|
|
293
|
+
},
|
|
294
|
+
data: getCloseStuckEscrowInstructionDataDecoder().decode(instruction.data)
|
|
295
|
+
};
|
|
296
|
+
}
|
|
188
297
|
var CREATE_MINT_DISCRIMINATOR = 0;
|
|
189
298
|
function getCreateMintDiscriminatorBytes() {
|
|
190
299
|
return getU8Encoder().encode(CREATE_MINT_DISCRIMINATOR);
|
|
@@ -273,6 +382,196 @@ function parseCreateMintInstruction(instruction) {
|
|
|
273
382
|
data: getCreateMintInstructionDataDecoder().decode(instruction.data)
|
|
274
383
|
};
|
|
275
384
|
}
|
|
385
|
+
var SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR = 5;
|
|
386
|
+
function getSyncMetadataToSplTokenDiscriminatorBytes() {
|
|
387
|
+
return getU8Encoder().encode(SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR);
|
|
388
|
+
}
|
|
389
|
+
function getSyncMetadataToSplTokenInstructionDataEncoder() {
|
|
390
|
+
return transformEncoder(
|
|
391
|
+
getStructEncoder([["discriminator", getU8Encoder()]]),
|
|
392
|
+
(value) => ({
|
|
393
|
+
...value,
|
|
394
|
+
discriminator: SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR
|
|
395
|
+
})
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
function getSyncMetadataToSplTokenInstructionDataDecoder() {
|
|
399
|
+
return getStructDecoder([["discriminator", getU8Decoder()]]);
|
|
400
|
+
}
|
|
401
|
+
function getSyncMetadataToSplTokenInstructionDataCodec() {
|
|
402
|
+
return combineCodec(
|
|
403
|
+
getSyncMetadataToSplTokenInstructionDataEncoder(),
|
|
404
|
+
getSyncMetadataToSplTokenInstructionDataDecoder()
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
function getSyncMetadataToSplTokenInstruction(input, config) {
|
|
408
|
+
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
409
|
+
const originalAccounts = {
|
|
410
|
+
metaplexMetadata: {
|
|
411
|
+
value: input.metaplexMetadata ?? null,
|
|
412
|
+
isWritable: true
|
|
413
|
+
},
|
|
414
|
+
wrappedMintAuthority: {
|
|
415
|
+
value: input.wrappedMintAuthority ?? null,
|
|
416
|
+
isWritable: true
|
|
417
|
+
},
|
|
418
|
+
wrappedMint: { value: input.wrappedMint ?? null, isWritable: false },
|
|
419
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
420
|
+
metaplexProgram: {
|
|
421
|
+
value: input.metaplexProgram ?? null,
|
|
422
|
+
isWritable: false
|
|
423
|
+
},
|
|
424
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
425
|
+
rentSysvar: { value: input.rentSysvar ?? null, isWritable: false },
|
|
426
|
+
sourceMetadata: { value: input.sourceMetadata ?? null, isWritable: false },
|
|
427
|
+
ownerProgram: { value: input.ownerProgram ?? null, isWritable: false }
|
|
428
|
+
};
|
|
429
|
+
const accounts = originalAccounts;
|
|
430
|
+
if (!accounts.metaplexProgram.value) {
|
|
431
|
+
accounts.metaplexProgram.value = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s";
|
|
432
|
+
}
|
|
433
|
+
if (!accounts.systemProgram.value) {
|
|
434
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
435
|
+
}
|
|
436
|
+
if (!accounts.rentSysvar.value) {
|
|
437
|
+
accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
|
|
438
|
+
}
|
|
439
|
+
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
440
|
+
const instruction = {
|
|
441
|
+
accounts: [
|
|
442
|
+
getAccountMeta(accounts.metaplexMetadata),
|
|
443
|
+
getAccountMeta(accounts.wrappedMintAuthority),
|
|
444
|
+
getAccountMeta(accounts.wrappedMint),
|
|
445
|
+
getAccountMeta(accounts.unwrappedMint),
|
|
446
|
+
getAccountMeta(accounts.metaplexProgram),
|
|
447
|
+
getAccountMeta(accounts.systemProgram),
|
|
448
|
+
getAccountMeta(accounts.rentSysvar),
|
|
449
|
+
getAccountMeta(accounts.sourceMetadata),
|
|
450
|
+
getAccountMeta(accounts.ownerProgram)
|
|
451
|
+
],
|
|
452
|
+
programAddress,
|
|
453
|
+
data: getSyncMetadataToSplTokenInstructionDataEncoder().encode({})
|
|
454
|
+
};
|
|
455
|
+
return instruction;
|
|
456
|
+
}
|
|
457
|
+
function parseSyncMetadataToSplTokenInstruction(instruction) {
|
|
458
|
+
if (instruction.accounts.length < 9) {
|
|
459
|
+
throw new Error("Not enough accounts");
|
|
460
|
+
}
|
|
461
|
+
let accountIndex = 0;
|
|
462
|
+
const getNextAccount = () => {
|
|
463
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
464
|
+
accountIndex += 1;
|
|
465
|
+
return accountMeta;
|
|
466
|
+
};
|
|
467
|
+
const getNextOptionalAccount = () => {
|
|
468
|
+
const accountMeta = getNextAccount();
|
|
469
|
+
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
470
|
+
};
|
|
471
|
+
return {
|
|
472
|
+
programAddress: instruction.programAddress,
|
|
473
|
+
accounts: {
|
|
474
|
+
metaplexMetadata: getNextAccount(),
|
|
475
|
+
wrappedMintAuthority: getNextAccount(),
|
|
476
|
+
wrappedMint: getNextAccount(),
|
|
477
|
+
unwrappedMint: getNextAccount(),
|
|
478
|
+
metaplexProgram: getNextAccount(),
|
|
479
|
+
systemProgram: getNextAccount(),
|
|
480
|
+
rentSysvar: getNextAccount(),
|
|
481
|
+
sourceMetadata: getNextOptionalAccount(),
|
|
482
|
+
ownerProgram: getNextOptionalAccount()
|
|
483
|
+
},
|
|
484
|
+
data: getSyncMetadataToSplTokenInstructionDataDecoder().decode(
|
|
485
|
+
instruction.data
|
|
486
|
+
)
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
var SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR = 4;
|
|
490
|
+
function getSyncMetadataToToken2022DiscriminatorBytes() {
|
|
491
|
+
return getU8Encoder().encode(SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR);
|
|
492
|
+
}
|
|
493
|
+
function getSyncMetadataToToken2022InstructionDataEncoder() {
|
|
494
|
+
return transformEncoder(
|
|
495
|
+
getStructEncoder([["discriminator", getU8Encoder()]]),
|
|
496
|
+
(value) => ({
|
|
497
|
+
...value,
|
|
498
|
+
discriminator: SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR
|
|
499
|
+
})
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
function getSyncMetadataToToken2022InstructionDataDecoder() {
|
|
503
|
+
return getStructDecoder([["discriminator", getU8Decoder()]]);
|
|
504
|
+
}
|
|
505
|
+
function getSyncMetadataToToken2022InstructionDataCodec() {
|
|
506
|
+
return combineCodec(
|
|
507
|
+
getSyncMetadataToToken2022InstructionDataEncoder(),
|
|
508
|
+
getSyncMetadataToToken2022InstructionDataDecoder()
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
function getSyncMetadataToToken2022Instruction(input, config) {
|
|
512
|
+
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
513
|
+
const originalAccounts = {
|
|
514
|
+
wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
|
|
515
|
+
wrappedMintAuthority: {
|
|
516
|
+
value: input.wrappedMintAuthority ?? null,
|
|
517
|
+
isWritable: false
|
|
518
|
+
},
|
|
519
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
520
|
+
token2022Program: {
|
|
521
|
+
value: input.token2022Program ?? null,
|
|
522
|
+
isWritable: false
|
|
523
|
+
},
|
|
524
|
+
sourceMetadata: { value: input.sourceMetadata ?? null, isWritable: false },
|
|
525
|
+
ownerProgram: { value: input.ownerProgram ?? null, isWritable: false }
|
|
526
|
+
};
|
|
527
|
+
const accounts = originalAccounts;
|
|
528
|
+
if (!accounts.token2022Program.value) {
|
|
529
|
+
accounts.token2022Program.value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
530
|
+
}
|
|
531
|
+
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
532
|
+
const instruction = {
|
|
533
|
+
accounts: [
|
|
534
|
+
getAccountMeta(accounts.wrappedMint),
|
|
535
|
+
getAccountMeta(accounts.wrappedMintAuthority),
|
|
536
|
+
getAccountMeta(accounts.unwrappedMint),
|
|
537
|
+
getAccountMeta(accounts.token2022Program),
|
|
538
|
+
getAccountMeta(accounts.sourceMetadata),
|
|
539
|
+
getAccountMeta(accounts.ownerProgram)
|
|
540
|
+
],
|
|
541
|
+
programAddress,
|
|
542
|
+
data: getSyncMetadataToToken2022InstructionDataEncoder().encode({})
|
|
543
|
+
};
|
|
544
|
+
return instruction;
|
|
545
|
+
}
|
|
546
|
+
function parseSyncMetadataToToken2022Instruction(instruction) {
|
|
547
|
+
if (instruction.accounts.length < 6) {
|
|
548
|
+
throw new Error("Not enough accounts");
|
|
549
|
+
}
|
|
550
|
+
let accountIndex = 0;
|
|
551
|
+
const getNextAccount = () => {
|
|
552
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
553
|
+
accountIndex += 1;
|
|
554
|
+
return accountMeta;
|
|
555
|
+
};
|
|
556
|
+
const getNextOptionalAccount = () => {
|
|
557
|
+
const accountMeta = getNextAccount();
|
|
558
|
+
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
559
|
+
};
|
|
560
|
+
return {
|
|
561
|
+
programAddress: instruction.programAddress,
|
|
562
|
+
accounts: {
|
|
563
|
+
wrappedMint: getNextAccount(),
|
|
564
|
+
wrappedMintAuthority: getNextAccount(),
|
|
565
|
+
unwrappedMint: getNextAccount(),
|
|
566
|
+
token2022Program: getNextAccount(),
|
|
567
|
+
sourceMetadata: getNextOptionalAccount(),
|
|
568
|
+
ownerProgram: getNextOptionalAccount()
|
|
569
|
+
},
|
|
570
|
+
data: getSyncMetadataToToken2022InstructionDataDecoder().decode(
|
|
571
|
+
instruction.data
|
|
572
|
+
)
|
|
573
|
+
};
|
|
574
|
+
}
|
|
276
575
|
var UNWRAP_DISCRIMINATOR = 2;
|
|
277
576
|
function getUnwrapDiscriminatorBytes() {
|
|
278
577
|
return getU8Encoder().encode(UNWRAP_DISCRIMINATOR);
|
|
@@ -497,6 +796,17 @@ function parseWrapInstruction(instruction) {
|
|
|
497
796
|
data: getWrapInstructionDataDecoder().decode(instruction.data)
|
|
498
797
|
};
|
|
499
798
|
}
|
|
799
|
+
var DEFAULT_EXTENSIONS = [
|
|
800
|
+
extension("ConfidentialTransferMint", {
|
|
801
|
+
autoApproveNewAccounts: true,
|
|
802
|
+
authority: null,
|
|
803
|
+
auditorElgamalPubkey: null
|
|
804
|
+
}),
|
|
805
|
+
extension("MetadataPointer", {
|
|
806
|
+
authority: null,
|
|
807
|
+
metadataAddress: null
|
|
808
|
+
})
|
|
809
|
+
];
|
|
500
810
|
async function createMint({
|
|
501
811
|
rpc,
|
|
502
812
|
unwrappedMint,
|
|
@@ -511,7 +821,10 @@ async function createMint({
|
|
|
511
821
|
const [backpointer] = await findBackpointerPda({ wrappedMint });
|
|
512
822
|
const instructions = [];
|
|
513
823
|
let fundedWrappedMintLamports = 0n;
|
|
514
|
-
|
|
824
|
+
let mintSize = BigInt(getMintSize());
|
|
825
|
+
if (wrappedTokenProgram === TOKEN_2022_PROGRAM_ADDRESS) {
|
|
826
|
+
mintSize = BigInt(getMintSize(DEFAULT_EXTENSIONS));
|
|
827
|
+
}
|
|
515
828
|
const [wrappedMintAccount, wrappedMintRent] = await Promise.all([
|
|
516
829
|
fetchEncodedAccount(rpc, wrappedMint),
|
|
517
830
|
rpc.getMinimumBalanceForRentExemption(mintSize).send()
|
|
@@ -651,7 +964,8 @@ function combinedMultisigTx({
|
|
|
651
964
|
signatures: combineSignatures(signedTxs),
|
|
652
965
|
lifetimeConstraint: blockhash
|
|
653
966
|
};
|
|
654
|
-
|
|
967
|
+
assertIsFullySignedTransaction(tx);
|
|
968
|
+
assertIsSendableTransaction(tx);
|
|
655
969
|
return tx;
|
|
656
970
|
}
|
|
657
971
|
async function multisigOfflineSignWrap(args) {
|
|
@@ -893,6 +1207,6 @@ async function multisigOfflineSignUnwrap(args) {
|
|
|
893
1207
|
);
|
|
894
1208
|
}
|
|
895
1209
|
|
|
896
|
-
export { CREATE_MINT_DISCRIMINATOR, TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH, TOKEN_WRAP_ERROR__ESCROW_MISMATCH, TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH, TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER, TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER, TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH, TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH, TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT, TOKEN_WRAP_PROGRAM_ADDRESS, TokenWrapAccount, TokenWrapInstruction, UNWRAP_DISCRIMINATOR, WRAP_DISCRIMINATOR, combinedMultisigTx, createEscrowAccount, createMint, decodeBackpointer, fetchAllBackpointer, fetchAllMaybeBackpointer, fetchBackpointer, fetchBackpointerFromSeeds, fetchMaybeBackpointer, fetchMaybeBackpointerFromSeeds, findBackpointerPda, findWrappedMintAuthorityPda, findWrappedMintPda, getBackpointerCodec, getBackpointerDecoder, getBackpointerEncoder, getBackpointerSize, getCreateMintDiscriminatorBytes, getCreateMintInstruction, getCreateMintInstructionDataCodec, getCreateMintInstructionDataDecoder, getCreateMintInstructionDataEncoder, getTokenWrapErrorMessage, getUnwrapDiscriminatorBytes, getUnwrapInstruction, getUnwrapInstructionDataCodec, getUnwrapInstructionDataDecoder, getUnwrapInstructionDataEncoder, getWrapDiscriminatorBytes, getWrapInstruction, getWrapInstructionDataCodec, getWrapInstructionDataDecoder, getWrapInstructionDataEncoder, identifyTokenWrapInstruction, isTokenWrapError, multisigOfflineSignUnwrap, multisigOfflineSignWrap, parseCreateMintInstruction, parseUnwrapInstruction, parseWrapInstruction, singleSignerUnwrap, singleSignerWrap };
|
|
1210
|
+
export { CLOSE_STUCK_ESCROW_DISCRIMINATOR, CREATE_MINT_DISCRIMINATOR, SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR, SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR, TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH, TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE, TOKEN_WRAP_ERROR__ESCROW_MISMATCH, TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH, TOKEN_WRAP_ERROR__EXTERNAL_PROGRAM_RETURNED_NO_DATA, TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER, TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER, TOKEN_WRAP_ERROR__METADATA_POINTER_MISMATCH, TOKEN_WRAP_ERROR__METADATA_POINTER_MISSING, TOKEN_WRAP_ERROR__METADATA_POINTER_UNSET, TOKEN_WRAP_ERROR__METAPLEX_METADATA_MISMATCH, TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH, TOKEN_WRAP_ERROR__NO_SYNCING_TO_TOKEN2022, TOKEN_WRAP_ERROR__UNWRAPPED_MINT_HAS_NO_METADATA, TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH, TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT, TOKEN_WRAP_PROGRAM_ADDRESS, TokenWrapAccount, TokenWrapInstruction, UNWRAP_DISCRIMINATOR, WRAP_DISCRIMINATOR, combinedMultisigTx, createEscrowAccount, createMint, decodeBackpointer, fetchAllBackpointer, fetchAllMaybeBackpointer, fetchBackpointer, fetchBackpointerFromSeeds, fetchMaybeBackpointer, fetchMaybeBackpointerFromSeeds, findBackpointerPda, findWrappedMintAuthorityPda, findWrappedMintPda, getBackpointerCodec, getBackpointerDecoder, getBackpointerEncoder, getBackpointerSize, getCloseStuckEscrowDiscriminatorBytes, getCloseStuckEscrowInstruction, getCloseStuckEscrowInstructionDataCodec, getCloseStuckEscrowInstructionDataDecoder, getCloseStuckEscrowInstructionDataEncoder, getCreateMintDiscriminatorBytes, getCreateMintInstruction, getCreateMintInstructionDataCodec, getCreateMintInstructionDataDecoder, getCreateMintInstructionDataEncoder, getSyncMetadataToSplTokenDiscriminatorBytes, getSyncMetadataToSplTokenInstruction, getSyncMetadataToSplTokenInstructionDataCodec, getSyncMetadataToSplTokenInstructionDataDecoder, getSyncMetadataToSplTokenInstructionDataEncoder, getSyncMetadataToToken2022DiscriminatorBytes, getSyncMetadataToToken2022Instruction, getSyncMetadataToToken2022InstructionDataCodec, getSyncMetadataToToken2022InstructionDataDecoder, getSyncMetadataToToken2022InstructionDataEncoder, getTokenWrapErrorMessage, getUnwrapDiscriminatorBytes, getUnwrapInstruction, getUnwrapInstructionDataCodec, getUnwrapInstructionDataDecoder, getUnwrapInstructionDataEncoder, getWrapDiscriminatorBytes, getWrapInstruction, getWrapInstructionDataCodec, getWrapInstructionDataDecoder, getWrapInstructionDataEncoder, identifyTokenWrapInstruction, isTokenWrapError, multisigOfflineSignUnwrap, multisigOfflineSignWrap, parseCloseStuckEscrowInstruction, parseCreateMintInstruction, parseSyncMetadataToSplTokenInstruction, parseSyncMetadataToToken2022Instruction, parseUnwrapInstruction, parseWrapInstruction, singleSignerUnwrap, singleSignerWrap };
|
|
897
1211
|
//# sourceMappingURL=index.mjs.map
|
|
898
1212
|
//# sourceMappingURL=index.mjs.map
|