@solana-program/token-wrap 1.0.0 → 2.1.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 +172 -112
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +162 -111
- package/dist/src/index.mjs.map +1 -1
- package/dist/types/create-mint.d.ts +5 -10
- package/dist/types/generated/errors/tokenWrap.d.ts +3 -1
- package/dist/types/generated/instructions/closeStuckEscrow.d.ts +63 -0
- package/dist/types/generated/instructions/index.d.ts +1 -0
- package/dist/types/generated/instructions/unwrap.d.ts +4 -4
- package/dist/types/generated/instructions/wrap.d.ts +2 -2
- package/dist/types/generated/programs/tokenWrap.d.ts +6 -3
- package/dist/types/index.d.ts +4 -4
- package/dist/types/unwrap.d.ts +9 -15
- package/dist/types/utilities.d.ts +16 -29
- package/dist/types/wrap.d.ts +11 -17
- package/package.json +15 -14
package/dist/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var kit = require('@solana/kit');
|
|
4
4
|
var token2022 = require('@solana-program/token-2022');
|
|
5
5
|
var system = require('@solana-program/system');
|
|
6
|
-
|
|
6
|
+
require('@solana-program/token');
|
|
7
7
|
|
|
8
8
|
// src/generated/accounts/backpointer.ts
|
|
9
9
|
async function findBackpointerPda(seeds, config = {}) {
|
|
@@ -100,6 +100,7 @@ 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";
|
|
103
104
|
return TokenWrapInstruction2;
|
|
104
105
|
})(TokenWrapInstruction || {});
|
|
105
106
|
function identifyTokenWrapInstruction(instruction) {
|
|
@@ -113,6 +114,9 @@ function identifyTokenWrapInstruction(instruction) {
|
|
|
113
114
|
if (kit.containsBytes(data, kit.getU8Encoder().encode(2), 0)) {
|
|
114
115
|
return 2 /* Unwrap */;
|
|
115
116
|
}
|
|
117
|
+
if (kit.containsBytes(data, kit.getU8Encoder().encode(3), 0)) {
|
|
118
|
+
return 3 /* CloseStuckEscrow */;
|
|
119
|
+
}
|
|
116
120
|
throw new Error(
|
|
117
121
|
"The provided instruction could not be identified as a tokenWrap instruction."
|
|
118
122
|
);
|
|
@@ -126,10 +130,14 @@ var TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH = 3;
|
|
|
126
130
|
var TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = 4;
|
|
127
131
|
var TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = 5;
|
|
128
132
|
var TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = 6;
|
|
133
|
+
var TOKEN_WRAP_ERROR__ESCROW_MISMATCH = 7;
|
|
134
|
+
var TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE = 8;
|
|
129
135
|
var tokenWrapErrorMessages;
|
|
130
136
|
if (process.env.NODE_ENV !== "production") {
|
|
131
137
|
tokenWrapErrorMessages = {
|
|
132
138
|
[TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH]: `Wrapped backpointer account address does not match expected PDA`,
|
|
139
|
+
[TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE]: `The escrow account is in a good state and cannot be recreated`,
|
|
140
|
+
[TOKEN_WRAP_ERROR__ESCROW_MISMATCH]: `Escrow account address does not match expected ATA`,
|
|
133
141
|
[TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH]: `Unwrapped escrow token owner is not set to expected PDA`,
|
|
134
142
|
[TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER]: `Wrapped backpointer account owner is not the expected token wrap program`,
|
|
135
143
|
[TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER]: `Wrapped mint account owner is not the expected token program`,
|
|
@@ -184,7 +192,88 @@ function isTransactionSigner(value) {
|
|
|
184
192
|
return !!value && typeof value === "object" && "address" in value && kit.isTransactionSigner(value);
|
|
185
193
|
}
|
|
186
194
|
|
|
187
|
-
// src/generated/instructions/
|
|
195
|
+
// src/generated/instructions/closeStuckEscrow.ts
|
|
196
|
+
var CLOSE_STUCK_ESCROW_DISCRIMINATOR = 3;
|
|
197
|
+
function getCloseStuckEscrowDiscriminatorBytes() {
|
|
198
|
+
return kit.getU8Encoder().encode(CLOSE_STUCK_ESCROW_DISCRIMINATOR);
|
|
199
|
+
}
|
|
200
|
+
function getCloseStuckEscrowInstructionDataEncoder() {
|
|
201
|
+
return kit.transformEncoder(
|
|
202
|
+
kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]),
|
|
203
|
+
(value) => ({ ...value, discriminator: CLOSE_STUCK_ESCROW_DISCRIMINATOR })
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
function getCloseStuckEscrowInstructionDataDecoder() {
|
|
207
|
+
return kit.getStructDecoder([["discriminator", kit.getU8Decoder()]]);
|
|
208
|
+
}
|
|
209
|
+
function getCloseStuckEscrowInstructionDataCodec() {
|
|
210
|
+
return kit.combineCodec(
|
|
211
|
+
getCloseStuckEscrowInstructionDataEncoder(),
|
|
212
|
+
getCloseStuckEscrowInstructionDataDecoder()
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
function getCloseStuckEscrowInstruction(input, config) {
|
|
216
|
+
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
217
|
+
const originalAccounts = {
|
|
218
|
+
escrow: { value: input.escrow ?? null, isWritable: true },
|
|
219
|
+
destination: { value: input.destination ?? null, isWritable: true },
|
|
220
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
221
|
+
wrappedMint: { value: input.wrappedMint ?? null, isWritable: false },
|
|
222
|
+
wrappedMintAuthority: {
|
|
223
|
+
value: input.wrappedMintAuthority ?? null,
|
|
224
|
+
isWritable: false
|
|
225
|
+
},
|
|
226
|
+
token2022Program: {
|
|
227
|
+
value: input.token2022Program ?? null,
|
|
228
|
+
isWritable: false
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const accounts = originalAccounts;
|
|
232
|
+
if (!accounts.token2022Program.value) {
|
|
233
|
+
accounts.token2022Program.value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
234
|
+
}
|
|
235
|
+
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
236
|
+
const instruction = {
|
|
237
|
+
accounts: [
|
|
238
|
+
getAccountMeta(accounts.escrow),
|
|
239
|
+
getAccountMeta(accounts.destination),
|
|
240
|
+
getAccountMeta(accounts.unwrappedMint),
|
|
241
|
+
getAccountMeta(accounts.wrappedMint),
|
|
242
|
+
getAccountMeta(accounts.wrappedMintAuthority),
|
|
243
|
+
getAccountMeta(accounts.token2022Program)
|
|
244
|
+
],
|
|
245
|
+
programAddress,
|
|
246
|
+
data: getCloseStuckEscrowInstructionDataEncoder().encode({})
|
|
247
|
+
};
|
|
248
|
+
return instruction;
|
|
249
|
+
}
|
|
250
|
+
function parseCloseStuckEscrowInstruction(instruction) {
|
|
251
|
+
if (instruction.accounts.length < 6) {
|
|
252
|
+
throw new Error("Not enough accounts");
|
|
253
|
+
}
|
|
254
|
+
let accountIndex = 0;
|
|
255
|
+
const getNextAccount = () => {
|
|
256
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
257
|
+
accountIndex += 1;
|
|
258
|
+
return accountMeta;
|
|
259
|
+
};
|
|
260
|
+
const getNextOptionalAccount = () => {
|
|
261
|
+
const accountMeta = getNextAccount();
|
|
262
|
+
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
263
|
+
};
|
|
264
|
+
return {
|
|
265
|
+
programAddress: instruction.programAddress,
|
|
266
|
+
accounts: {
|
|
267
|
+
escrow: getNextAccount(),
|
|
268
|
+
destination: getNextAccount(),
|
|
269
|
+
unwrappedMint: getNextAccount(),
|
|
270
|
+
wrappedMint: getNextAccount(),
|
|
271
|
+
wrappedMintAuthority: getNextAccount(),
|
|
272
|
+
token2022Program: getNextOptionalAccount()
|
|
273
|
+
},
|
|
274
|
+
data: getCloseStuckEscrowInstructionDataDecoder().decode(instruction.data)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
188
277
|
var CREATE_MINT_DISCRIMINATOR = 0;
|
|
189
278
|
function getCreateMintDiscriminatorBytes() {
|
|
190
279
|
return kit.getU8Encoder().encode(CREATE_MINT_DISCRIMINATOR);
|
|
@@ -497,9 +586,8 @@ function parseWrapInstruction(instruction) {
|
|
|
497
586
|
data: getWrapInstructionDataDecoder().decode(instruction.data)
|
|
498
587
|
};
|
|
499
588
|
}
|
|
500
|
-
async function
|
|
589
|
+
async function createMint({
|
|
501
590
|
rpc,
|
|
502
|
-
blockhash,
|
|
503
591
|
unwrappedMint,
|
|
504
592
|
wrappedTokenProgram,
|
|
505
593
|
payer,
|
|
@@ -554,63 +642,16 @@ async function createMintTx({
|
|
|
554
642
|
idempotent
|
|
555
643
|
})
|
|
556
644
|
);
|
|
557
|
-
const tx = kit.pipe(
|
|
558
|
-
kit.createTransactionMessage({ version: 0 }),
|
|
559
|
-
(tx2) => kit.setTransactionMessageFeePayerSigner(payer, tx2),
|
|
560
|
-
(tx2) => kit.setTransactionMessageLifetimeUsingBlockhash(blockhash, tx2),
|
|
561
|
-
(tx2) => kit.appendTransactionMessageInstructions(instructions, tx2)
|
|
562
|
-
);
|
|
563
645
|
return {
|
|
564
646
|
wrappedMint,
|
|
565
647
|
backpointer,
|
|
566
|
-
|
|
648
|
+
ixs: instructions,
|
|
567
649
|
fundedWrappedMintLamports,
|
|
568
650
|
fundedBackpointerLamports
|
|
569
651
|
};
|
|
570
652
|
}
|
|
571
|
-
function
|
|
572
|
-
if (tokenProgram === token.TOKEN_PROGRAM_ADDRESS) return token.getInitializeAccountInstruction;
|
|
573
|
-
if (tokenProgram === token2022.TOKEN_2022_PROGRAM_ADDRESS) return token2022.getInitializeAccountInstruction;
|
|
574
|
-
throw new Error(`${tokenProgram} is not a valid token program.`);
|
|
575
|
-
}
|
|
576
|
-
async function createTokenAccountTx({
|
|
577
|
-
rpc,
|
|
578
|
-
blockhash,
|
|
579
|
-
payer,
|
|
580
|
-
mint,
|
|
581
|
-
owner,
|
|
582
|
-
tokenProgram
|
|
583
|
-
}) {
|
|
584
|
-
const [keyPair, lamports] = await Promise.all([
|
|
585
|
-
kit.generateKeyPairSigner(),
|
|
586
|
-
rpc.getMinimumBalanceForRentExemption(165n).send()
|
|
587
|
-
]);
|
|
588
|
-
const createAccountIx = system.getCreateAccountInstruction({
|
|
589
|
-
payer,
|
|
590
|
-
newAccount: keyPair,
|
|
591
|
-
lamports,
|
|
592
|
-
space: 165,
|
|
593
|
-
programAddress: tokenProgram
|
|
594
|
-
});
|
|
595
|
-
const initializeAccountIx = getInitializeTokenFn(tokenProgram)({
|
|
596
|
-
account: keyPair.address,
|
|
597
|
-
mint,
|
|
598
|
-
owner
|
|
599
|
-
});
|
|
600
|
-
const tx = kit.pipe(
|
|
601
|
-
kit.createTransactionMessage({ version: 0 }),
|
|
602
|
-
(tx2) => kit.setTransactionMessageFeePayerSigner(payer, tx2),
|
|
603
|
-
(tx2) => kit.setTransactionMessageLifetimeUsingBlockhash(blockhash, tx2),
|
|
604
|
-
(tx2) => kit.appendTransactionMessageInstructions([createAccountIx, initializeAccountIx], tx2)
|
|
605
|
-
);
|
|
606
|
-
return {
|
|
607
|
-
tx,
|
|
608
|
-
keyPair
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
async function createEscrowAccountTx({
|
|
653
|
+
async function createEscrowAccount({
|
|
612
654
|
rpc,
|
|
613
|
-
blockhash,
|
|
614
655
|
payer,
|
|
615
656
|
unwrappedMint,
|
|
616
657
|
wrappedTokenProgram
|
|
@@ -618,14 +659,23 @@ async function createEscrowAccountTx({
|
|
|
618
659
|
const [wrappedMint] = await findWrappedMintPda({ unwrappedMint, wrappedTokenProgram });
|
|
619
660
|
const [wrappedMintAuthority] = await findWrappedMintAuthorityPda({ wrappedMint });
|
|
620
661
|
const unwrappedTokenProgram = await getOwnerFromAccount(rpc, unwrappedMint);
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
blockhash,
|
|
624
|
-
payer,
|
|
662
|
+
const [escrowAta] = await token2022.findAssociatedTokenPda({
|
|
663
|
+
owner: wrappedMintAuthority,
|
|
625
664
|
mint: unwrappedMint,
|
|
665
|
+
tokenProgram: unwrappedTokenProgram
|
|
666
|
+
});
|
|
667
|
+
const escrowResult = await token2022.fetchMaybeToken(rpc, escrowAta);
|
|
668
|
+
if (escrowResult.exists) {
|
|
669
|
+
return { kind: "already_exists", account: escrowResult };
|
|
670
|
+
}
|
|
671
|
+
const ix = token2022.getCreateAssociatedTokenInstruction({
|
|
672
|
+
payer,
|
|
626
673
|
owner: wrappedMintAuthority,
|
|
674
|
+
mint: unwrappedMint,
|
|
675
|
+
ata: escrowAta,
|
|
627
676
|
tokenProgram: unwrappedTokenProgram
|
|
628
677
|
});
|
|
678
|
+
return { address: escrowAta, ixs: [ix], kind: "instructions_to_create" };
|
|
629
679
|
}
|
|
630
680
|
async function getOwnerFromAccount(rpc, accountAddress) {
|
|
631
681
|
const accountInfo = await rpc.getAccountInfo(accountAddress, { encoding: "base64" }).send();
|
|
@@ -693,15 +743,19 @@ function combinedMultisigTx({
|
|
|
693
743
|
kit.assertTransactionIsFullySigned(tx);
|
|
694
744
|
return tx;
|
|
695
745
|
}
|
|
696
|
-
function
|
|
697
|
-
|
|
746
|
+
async function multisigOfflineSignWrap(args) {
|
|
747
|
+
const wrapIx = await buildWrapIx(args);
|
|
748
|
+
return kit.pipe(
|
|
749
|
+
kit.createTransactionMessage({ version: 0 }),
|
|
750
|
+
(tx) => kit.setTransactionMessageFeePayerSigner(args.payer, tx),
|
|
751
|
+
(tx) => kit.setTransactionMessageLifetimeUsingBlockhash(args.blockhash, tx),
|
|
752
|
+
(tx) => kit.appendTransactionMessageInstructions([wrapIx], tx)
|
|
753
|
+
);
|
|
698
754
|
}
|
|
699
|
-
async function
|
|
755
|
+
async function singleSignerWrap({
|
|
700
756
|
rpc,
|
|
701
|
-
blockhash,
|
|
702
757
|
payer,
|
|
703
758
|
unwrappedTokenAccount,
|
|
704
|
-
escrowAccount,
|
|
705
759
|
wrappedTokenProgram,
|
|
706
760
|
amount,
|
|
707
761
|
transferAuthority: inputTransferAuthority,
|
|
@@ -715,7 +769,8 @@ async function singleSignerWrapTx({
|
|
|
715
769
|
wrappedMint,
|
|
716
770
|
wrappedMintAuthority,
|
|
717
771
|
recipientWrappedTokenAccount,
|
|
718
|
-
transferAuthority
|
|
772
|
+
transferAuthority,
|
|
773
|
+
unwrappedEscrow
|
|
719
774
|
} = await resolveAddrs({
|
|
720
775
|
rpc,
|
|
721
776
|
payer,
|
|
@@ -726,11 +781,8 @@ async function singleSignerWrapTx({
|
|
|
726
781
|
wrappedTokenProgram,
|
|
727
782
|
inputRecipientTokenAccount
|
|
728
783
|
});
|
|
729
|
-
const
|
|
730
|
-
blockhash,
|
|
731
|
-
payer,
|
|
784
|
+
const ix = await buildWrapIx({
|
|
732
785
|
unwrappedTokenAccount,
|
|
733
|
-
escrowAccount,
|
|
734
786
|
wrappedTokenProgram,
|
|
735
787
|
amount,
|
|
736
788
|
transferAuthority,
|
|
@@ -741,9 +793,9 @@ async function singleSignerWrapTx({
|
|
|
741
793
|
unwrappedTokenProgram
|
|
742
794
|
});
|
|
743
795
|
return {
|
|
744
|
-
|
|
796
|
+
ixs: [ix],
|
|
745
797
|
recipientWrappedTokenAccount,
|
|
746
|
-
escrowAccount,
|
|
798
|
+
escrowAccount: unwrappedEscrow,
|
|
747
799
|
amount: BigInt(amount)
|
|
748
800
|
};
|
|
749
801
|
}
|
|
@@ -766,8 +818,14 @@ async function resolveAddrs({
|
|
|
766
818
|
mint: wrappedMint,
|
|
767
819
|
tokenProgram: wrappedTokenProgram
|
|
768
820
|
}))[0];
|
|
821
|
+
const [unwrappedEscrow] = await token2022.findAssociatedTokenPda({
|
|
822
|
+
owner: wrappedMintAuthority,
|
|
823
|
+
mint: unwrappedMint,
|
|
824
|
+
tokenProgram: unwrappedTokenProgram
|
|
825
|
+
});
|
|
769
826
|
const transferAuthority = inputTransferAuthority ?? payer;
|
|
770
827
|
return {
|
|
828
|
+
unwrappedEscrow,
|
|
771
829
|
transferAuthority,
|
|
772
830
|
unwrappedMint,
|
|
773
831
|
unwrappedTokenProgram,
|
|
@@ -776,10 +834,8 @@ async function resolveAddrs({
|
|
|
776
834
|
recipientWrappedTokenAccount
|
|
777
835
|
};
|
|
778
836
|
}
|
|
779
|
-
function
|
|
780
|
-
payer,
|
|
837
|
+
async function buildWrapIx({
|
|
781
838
|
unwrappedTokenAccount,
|
|
782
|
-
escrowAccount,
|
|
783
839
|
wrappedTokenProgram,
|
|
784
840
|
amount,
|
|
785
841
|
transferAuthority,
|
|
@@ -788,9 +844,13 @@ function buildWrapTransaction({
|
|
|
788
844
|
unwrappedTokenProgram,
|
|
789
845
|
wrappedMint,
|
|
790
846
|
wrappedMintAuthority,
|
|
791
|
-
blockhash,
|
|
792
847
|
multiSigners = []
|
|
793
848
|
}) {
|
|
849
|
+
const [unwrappedEscrow] = await token2022.findAssociatedTokenPda({
|
|
850
|
+
owner: wrappedMintAuthority,
|
|
851
|
+
mint: unwrappedMint,
|
|
852
|
+
tokenProgram: unwrappedTokenProgram
|
|
853
|
+
});
|
|
794
854
|
const wrapInstructionInput = {
|
|
795
855
|
recipientWrappedTokenAccount,
|
|
796
856
|
wrappedMint,
|
|
@@ -799,32 +859,26 @@ function buildWrapTransaction({
|
|
|
799
859
|
wrappedTokenProgram,
|
|
800
860
|
unwrappedTokenAccount,
|
|
801
861
|
unwrappedMint,
|
|
802
|
-
unwrappedEscrow
|
|
862
|
+
unwrappedEscrow,
|
|
803
863
|
transferAuthority,
|
|
804
864
|
amount: BigInt(amount),
|
|
805
865
|
multiSigners
|
|
806
866
|
};
|
|
807
|
-
|
|
808
|
-
return kit.pipe(
|
|
809
|
-
kit.createTransactionMessage({ version: 0 }),
|
|
810
|
-
(tx) => kit.setTransactionMessageFeePayerSigner(payer, tx),
|
|
811
|
-
(tx) => kit.setTransactionMessageLifetimeUsingBlockhash(blockhash, tx),
|
|
812
|
-
(tx) => kit.appendTransactionMessageInstructions([wrapInstruction], tx)
|
|
813
|
-
);
|
|
867
|
+
return getWrapInstruction(wrapInstructionInput);
|
|
814
868
|
}
|
|
815
869
|
async function resolveUnwrapAddrs({
|
|
816
870
|
rpc,
|
|
817
871
|
payer,
|
|
818
872
|
wrappedTokenAccount,
|
|
819
|
-
|
|
873
|
+
recipientUnwrappedToken,
|
|
820
874
|
inputUnwrappedMint,
|
|
821
875
|
inputTransferAuthority,
|
|
822
876
|
inputWrappedTokenProgram,
|
|
823
877
|
inputUnwrappedTokenProgram
|
|
824
878
|
}) {
|
|
825
879
|
const wrappedTokenProgram = inputWrappedTokenProgram ?? await getOwnerFromAccount(rpc, wrappedTokenAccount);
|
|
826
|
-
const unwrappedTokenProgram = inputUnwrappedTokenProgram ?? await getOwnerFromAccount(rpc,
|
|
827
|
-
const unwrappedMint = inputUnwrappedMint ?? await getMintFromTokenAccount(rpc,
|
|
880
|
+
const unwrappedTokenProgram = inputUnwrappedTokenProgram ?? await getOwnerFromAccount(rpc, recipientUnwrappedToken);
|
|
881
|
+
const unwrappedMint = inputUnwrappedMint ?? await getMintFromTokenAccount(rpc, recipientUnwrappedToken);
|
|
828
882
|
const wrappedAccountInfo = await kit.fetchEncodedAccount(rpc, wrappedTokenAccount);
|
|
829
883
|
if (!wrappedAccountInfo.exists) {
|
|
830
884
|
throw new Error(`Wrapped token account ${wrappedTokenAccount} not found.`);
|
|
@@ -841,9 +895,7 @@ async function resolveUnwrapAddrs({
|
|
|
841
895
|
unwrappedTokenProgram
|
|
842
896
|
};
|
|
843
897
|
}
|
|
844
|
-
function buildUnwrapTransaction({
|
|
845
|
-
payer,
|
|
846
|
-
unwrappedEscrow,
|
|
898
|
+
async function buildUnwrapTransaction({
|
|
847
899
|
recipientUnwrappedToken,
|
|
848
900
|
wrappedMintAuthority,
|
|
849
901
|
unwrappedMint,
|
|
@@ -853,9 +905,13 @@ function buildUnwrapTransaction({
|
|
|
853
905
|
wrappedMint,
|
|
854
906
|
transferAuthority,
|
|
855
907
|
amount,
|
|
856
|
-
blockhash,
|
|
857
908
|
multiSigners = []
|
|
858
909
|
}) {
|
|
910
|
+
const [unwrappedEscrow] = await token2022.findAssociatedTokenPda({
|
|
911
|
+
owner: wrappedMintAuthority,
|
|
912
|
+
mint: unwrappedMint,
|
|
913
|
+
tokenProgram: unwrappedTokenProgram
|
|
914
|
+
});
|
|
859
915
|
const unwrapInstructionInput = {
|
|
860
916
|
unwrappedEscrow,
|
|
861
917
|
recipientUnwrappedToken,
|
|
@@ -869,20 +925,12 @@ function buildUnwrapTransaction({
|
|
|
869
925
|
amount: BigInt(amount),
|
|
870
926
|
multiSigners
|
|
871
927
|
};
|
|
872
|
-
|
|
873
|
-
return kit.pipe(
|
|
874
|
-
kit.createTransactionMessage({ version: 0 }),
|
|
875
|
-
(tx) => kit.setTransactionMessageFeePayerSigner(payer, tx),
|
|
876
|
-
(tx) => kit.setTransactionMessageLifetimeUsingBlockhash(blockhash, tx),
|
|
877
|
-
(tx) => kit.appendTransactionMessageInstructions([unwrapInstruction], tx)
|
|
878
|
-
);
|
|
928
|
+
return getUnwrapInstruction(unwrapInstructionInput);
|
|
879
929
|
}
|
|
880
|
-
async function
|
|
930
|
+
async function singleSignerUnwrap({
|
|
881
931
|
rpc,
|
|
882
|
-
blockhash,
|
|
883
932
|
payer,
|
|
884
933
|
wrappedTokenAccount,
|
|
885
|
-
unwrappedEscrow,
|
|
886
934
|
amount,
|
|
887
935
|
recipientUnwrappedToken,
|
|
888
936
|
transferAuthority: inputTransferAuthority,
|
|
@@ -901,15 +949,13 @@ async function singleSignerUnwrapTx({
|
|
|
901
949
|
rpc,
|
|
902
950
|
payer,
|
|
903
951
|
wrappedTokenAccount,
|
|
904
|
-
|
|
952
|
+
recipientUnwrappedToken,
|
|
905
953
|
inputUnwrappedMint,
|
|
906
954
|
inputTransferAuthority,
|
|
907
955
|
inputWrappedTokenProgram,
|
|
908
956
|
inputUnwrappedTokenProgram
|
|
909
957
|
});
|
|
910
|
-
const
|
|
911
|
-
payer,
|
|
912
|
-
unwrappedEscrow,
|
|
958
|
+
const ix = await buildUnwrapTransaction({
|
|
913
959
|
recipientUnwrappedToken,
|
|
914
960
|
wrappedMintAuthority,
|
|
915
961
|
unwrappedMint,
|
|
@@ -918,21 +964,29 @@ async function singleSignerUnwrapTx({
|
|
|
918
964
|
wrappedTokenAccount,
|
|
919
965
|
wrappedMint,
|
|
920
966
|
transferAuthority,
|
|
921
|
-
amount
|
|
922
|
-
blockhash
|
|
967
|
+
amount
|
|
923
968
|
});
|
|
924
969
|
return {
|
|
925
970
|
recipientUnwrappedToken,
|
|
926
971
|
amount: BigInt(amount),
|
|
927
|
-
|
|
972
|
+
ixs: [ix]
|
|
928
973
|
};
|
|
929
974
|
}
|
|
930
|
-
function multisigOfflineSignUnwrap(args) {
|
|
931
|
-
|
|
975
|
+
async function multisigOfflineSignUnwrap(args) {
|
|
976
|
+
const unwrapIx = await buildUnwrapTransaction(args);
|
|
977
|
+
return kit.pipe(
|
|
978
|
+
kit.createTransactionMessage({ version: 0 }),
|
|
979
|
+
(tx) => kit.setTransactionMessageFeePayerSigner(args.payer, tx),
|
|
980
|
+
(tx) => kit.setTransactionMessageLifetimeUsingBlockhash(args.blockhash, tx),
|
|
981
|
+
(tx) => kit.appendTransactionMessageInstructions([unwrapIx], tx)
|
|
982
|
+
);
|
|
932
983
|
}
|
|
933
984
|
|
|
985
|
+
exports.CLOSE_STUCK_ESCROW_DISCRIMINATOR = CLOSE_STUCK_ESCROW_DISCRIMINATOR;
|
|
934
986
|
exports.CREATE_MINT_DISCRIMINATOR = CREATE_MINT_DISCRIMINATOR;
|
|
935
987
|
exports.TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH = TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH;
|
|
988
|
+
exports.TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE = TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE;
|
|
989
|
+
exports.TOKEN_WRAP_ERROR__ESCROW_MISMATCH = TOKEN_WRAP_ERROR__ESCROW_MISMATCH;
|
|
936
990
|
exports.TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH;
|
|
937
991
|
exports.TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER;
|
|
938
992
|
exports.TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER;
|
|
@@ -945,8 +999,8 @@ exports.TokenWrapInstruction = TokenWrapInstruction;
|
|
|
945
999
|
exports.UNWRAP_DISCRIMINATOR = UNWRAP_DISCRIMINATOR;
|
|
946
1000
|
exports.WRAP_DISCRIMINATOR = WRAP_DISCRIMINATOR;
|
|
947
1001
|
exports.combinedMultisigTx = combinedMultisigTx;
|
|
948
|
-
exports.
|
|
949
|
-
exports.
|
|
1002
|
+
exports.createEscrowAccount = createEscrowAccount;
|
|
1003
|
+
exports.createMint = createMint;
|
|
950
1004
|
exports.decodeBackpointer = decodeBackpointer;
|
|
951
1005
|
exports.fetchAllBackpointer = fetchAllBackpointer;
|
|
952
1006
|
exports.fetchAllMaybeBackpointer = fetchAllMaybeBackpointer;
|
|
@@ -961,6 +1015,11 @@ exports.getBackpointerCodec = getBackpointerCodec;
|
|
|
961
1015
|
exports.getBackpointerDecoder = getBackpointerDecoder;
|
|
962
1016
|
exports.getBackpointerEncoder = getBackpointerEncoder;
|
|
963
1017
|
exports.getBackpointerSize = getBackpointerSize;
|
|
1018
|
+
exports.getCloseStuckEscrowDiscriminatorBytes = getCloseStuckEscrowDiscriminatorBytes;
|
|
1019
|
+
exports.getCloseStuckEscrowInstruction = getCloseStuckEscrowInstruction;
|
|
1020
|
+
exports.getCloseStuckEscrowInstructionDataCodec = getCloseStuckEscrowInstructionDataCodec;
|
|
1021
|
+
exports.getCloseStuckEscrowInstructionDataDecoder = getCloseStuckEscrowInstructionDataDecoder;
|
|
1022
|
+
exports.getCloseStuckEscrowInstructionDataEncoder = getCloseStuckEscrowInstructionDataEncoder;
|
|
964
1023
|
exports.getCreateMintDiscriminatorBytes = getCreateMintDiscriminatorBytes;
|
|
965
1024
|
exports.getCreateMintInstruction = getCreateMintInstruction;
|
|
966
1025
|
exports.getCreateMintInstructionDataCodec = getCreateMintInstructionDataCodec;
|
|
@@ -980,11 +1039,12 @@ exports.getWrapInstructionDataEncoder = getWrapInstructionDataEncoder;
|
|
|
980
1039
|
exports.identifyTokenWrapInstruction = identifyTokenWrapInstruction;
|
|
981
1040
|
exports.isTokenWrapError = isTokenWrapError;
|
|
982
1041
|
exports.multisigOfflineSignUnwrap = multisigOfflineSignUnwrap;
|
|
983
|
-
exports.
|
|
1042
|
+
exports.multisigOfflineSignWrap = multisigOfflineSignWrap;
|
|
1043
|
+
exports.parseCloseStuckEscrowInstruction = parseCloseStuckEscrowInstruction;
|
|
984
1044
|
exports.parseCreateMintInstruction = parseCreateMintInstruction;
|
|
985
1045
|
exports.parseUnwrapInstruction = parseUnwrapInstruction;
|
|
986
1046
|
exports.parseWrapInstruction = parseWrapInstruction;
|
|
987
|
-
exports.
|
|
988
|
-
exports.
|
|
1047
|
+
exports.singleSignerUnwrap = singleSignerUnwrap;
|
|
1048
|
+
exports.singleSignerWrap = singleSignerWrap;
|
|
989
1049
|
//# sourceMappingURL=index.js.map
|
|
990
1050
|
//# sourceMappingURL=index.js.map
|