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