@solana-program/token-wrap 2.3.0 → 2.5.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/package.json +20 -19
- package/src/create-mint.ts +125 -0
- package/src/examples/multisig.ts +295 -0
- package/src/examples/single-signer.ts +175 -0
- package/src/examples/sync-spl-to-token2022.ts +96 -0
- package/src/examples/sync-token2022-to-spl.ts +101 -0
- package/src/generated/accounts/backpointer.ts +125 -0
- package/{dist/types/generated/accounts/index.d.ts → src/generated/accounts/index.ts} +1 -0
- package/{dist/types/generated/errors/index.d.ts → src/generated/errors/index.ts} +1 -0
- package/src/generated/errors/tokenWrap.ts +89 -0
- package/{dist/types/generated/index.d.ts → src/generated/index.ts} +1 -0
- package/src/generated/instructions/closeStuckEscrow.ts +235 -0
- package/src/generated/instructions/createMint.ts +250 -0
- package/{dist/types/generated/instructions/index.d.ts → src/generated/instructions/index.ts} +1 -0
- package/src/generated/instructions/syncMetadataToSplToken.ts +305 -0
- package/src/generated/instructions/syncMetadataToToken2022.ts +253 -0
- package/src/generated/instructions/unwrap.ts +326 -0
- package/src/generated/instructions/wrap.ts +326 -0
- package/src/generated/pdas/backpointer.ts +32 -0
- package/{dist/types/generated/pdas/index.d.ts → src/generated/pdas/index.ts} +1 -0
- package/src/generated/pdas/wrappedMint.ts +37 -0
- package/src/generated/pdas/wrappedMintAuthority.ts +32 -0
- package/{dist/types/generated/programs/index.d.ts → src/generated/programs/index.ts} +1 -0
- package/src/generated/programs/tokenWrap.ts +228 -0
- package/src/global.d.ts +8 -0
- package/src/index.ts +23 -0
- package/src/unwrap.ts +208 -0
- package/src/utilities.ts +234 -0
- package/src/wrap.ts +211 -0
- package/dist/src/index.js +0 -1292
- package/dist/src/index.js.map +0 -1
- package/dist/src/index.mjs +0 -1206
- package/dist/src/index.mjs.map +0 -1
- package/dist/types/create-mint.d.ts +0 -16
- package/dist/types/examples/multisig.d.ts +0 -1
- package/dist/types/examples/single-signer.d.ts +0 -1
- package/dist/types/examples/sync-spl-to-token2022.d.ts +0 -1
- package/dist/types/examples/sync-token2022-to-spl.d.ts +0 -1
- package/dist/types/generated/accounts/backpointer.d.ts +0 -29
- package/dist/types/generated/errors/tokenWrap.d.ts +0 -35
- package/dist/types/generated/instructions/closeStuckEscrow.d.ts +0 -63
- package/dist/types/generated/instructions/createMint.d.ts +0 -76
- package/dist/types/generated/instructions/syncMetadataToSplToken.d.ts +0 -92
- package/dist/types/generated/instructions/syncMetadataToToken2022.d.ts +0 -75
- package/dist/types/generated/instructions/unwrap.d.ts +0 -103
- package/dist/types/generated/instructions/wrap.d.ts +0 -103
- package/dist/types/generated/pdas/backpointer.d.ts +0 -14
- package/dist/types/generated/pdas/wrappedMint.d.ts +0 -15
- package/dist/types/generated/pdas/wrappedMintAuthority.d.ts +0 -14
- package/dist/types/generated/programs/tokenWrap.d.ts +0 -37
- package/dist/types/generated/shared/index.d.ts +0 -49
- package/dist/types/index.d.ts +0 -5
- package/dist/types/unwrap.d.ts +0 -45
- package/dist/types/utilities.d.ts +0 -39
- package/dist/types/wrap.d.ts +0 -42
package/dist/src/index.mjs
DELETED
|
@@ -1,1206 +0,0 @@
|
|
|
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
|
-
import { getTransferSolInstruction } from '@solana-program/system';
|
|
4
|
-
import '@solana-program/token';
|
|
5
|
-
|
|
6
|
-
// src/generated/accounts/backpointer.ts
|
|
7
|
-
async function findBackpointerPda(seeds, config = {}) {
|
|
8
|
-
const {
|
|
9
|
-
programAddress = "TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR"
|
|
10
|
-
} = config;
|
|
11
|
-
return await getProgramDerivedAddress({
|
|
12
|
-
programAddress,
|
|
13
|
-
seeds: [
|
|
14
|
-
getUtf8Encoder().encode("backpointer"),
|
|
15
|
-
getAddressEncoder().encode(seeds.wrappedMint)
|
|
16
|
-
]
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
async function findWrappedMintPda(seeds, config = {}) {
|
|
20
|
-
const {
|
|
21
|
-
programAddress = "TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR"
|
|
22
|
-
} = config;
|
|
23
|
-
return await getProgramDerivedAddress({
|
|
24
|
-
programAddress,
|
|
25
|
-
seeds: [
|
|
26
|
-
getUtf8Encoder().encode("mint"),
|
|
27
|
-
getAddressEncoder().encode(seeds.unwrappedMint),
|
|
28
|
-
getAddressEncoder().encode(seeds.wrappedTokenProgram)
|
|
29
|
-
]
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
async function findWrappedMintAuthorityPda(seeds, config = {}) {
|
|
33
|
-
const {
|
|
34
|
-
programAddress = "TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR"
|
|
35
|
-
} = config;
|
|
36
|
-
return await getProgramDerivedAddress({
|
|
37
|
-
programAddress,
|
|
38
|
-
seeds: [
|
|
39
|
-
getUtf8Encoder().encode("authority"),
|
|
40
|
-
getAddressEncoder().encode(seeds.wrappedMint)
|
|
41
|
-
]
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// src/generated/accounts/backpointer.ts
|
|
46
|
-
function getBackpointerEncoder() {
|
|
47
|
-
return getStructEncoder([["unwrappedMint", getAddressEncoder()]]);
|
|
48
|
-
}
|
|
49
|
-
function getBackpointerDecoder() {
|
|
50
|
-
return getStructDecoder([["unwrappedMint", getAddressDecoder()]]);
|
|
51
|
-
}
|
|
52
|
-
function getBackpointerCodec() {
|
|
53
|
-
return combineCodec(getBackpointerEncoder(), getBackpointerDecoder());
|
|
54
|
-
}
|
|
55
|
-
function decodeBackpointer(encodedAccount) {
|
|
56
|
-
return decodeAccount(
|
|
57
|
-
encodedAccount,
|
|
58
|
-
getBackpointerDecoder()
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
async function fetchBackpointer(rpc, address, config) {
|
|
62
|
-
const maybeAccount = await fetchMaybeBackpointer(rpc, address, config);
|
|
63
|
-
assertAccountExists(maybeAccount);
|
|
64
|
-
return maybeAccount;
|
|
65
|
-
}
|
|
66
|
-
async function fetchMaybeBackpointer(rpc, address, config) {
|
|
67
|
-
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
68
|
-
return decodeBackpointer(maybeAccount);
|
|
69
|
-
}
|
|
70
|
-
async function fetchAllBackpointer(rpc, addresses, config) {
|
|
71
|
-
const maybeAccounts = await fetchAllMaybeBackpointer(rpc, addresses, config);
|
|
72
|
-
assertAccountsExist(maybeAccounts);
|
|
73
|
-
return maybeAccounts;
|
|
74
|
-
}
|
|
75
|
-
async function fetchAllMaybeBackpointer(rpc, addresses, config) {
|
|
76
|
-
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
77
|
-
return maybeAccounts.map((maybeAccount) => decodeBackpointer(maybeAccount));
|
|
78
|
-
}
|
|
79
|
-
function getBackpointerSize() {
|
|
80
|
-
return 32;
|
|
81
|
-
}
|
|
82
|
-
async function fetchBackpointerFromSeeds(rpc, seeds, config = {}) {
|
|
83
|
-
const maybeAccount = await fetchMaybeBackpointerFromSeeds(rpc, seeds, config);
|
|
84
|
-
assertAccountExists(maybeAccount);
|
|
85
|
-
return maybeAccount;
|
|
86
|
-
}
|
|
87
|
-
async function fetchMaybeBackpointerFromSeeds(rpc, seeds, config = {}) {
|
|
88
|
-
const { programAddress, ...fetchConfig } = config;
|
|
89
|
-
const [address] = await findBackpointerPda(seeds, { programAddress });
|
|
90
|
-
return await fetchMaybeBackpointer(rpc, address, fetchConfig);
|
|
91
|
-
}
|
|
92
|
-
var TOKEN_WRAP_PROGRAM_ADDRESS = "TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR";
|
|
93
|
-
var TokenWrapAccount = /* @__PURE__ */ ((TokenWrapAccount2) => {
|
|
94
|
-
TokenWrapAccount2[TokenWrapAccount2["Backpointer"] = 0] = "Backpointer";
|
|
95
|
-
return TokenWrapAccount2;
|
|
96
|
-
})(TokenWrapAccount || {});
|
|
97
|
-
var TokenWrapInstruction = /* @__PURE__ */ ((TokenWrapInstruction2) => {
|
|
98
|
-
TokenWrapInstruction2[TokenWrapInstruction2["CreateMint"] = 0] = "CreateMint";
|
|
99
|
-
TokenWrapInstruction2[TokenWrapInstruction2["Wrap"] = 1] = "Wrap";
|
|
100
|
-
TokenWrapInstruction2[TokenWrapInstruction2["Unwrap"] = 2] = "Unwrap";
|
|
101
|
-
TokenWrapInstruction2[TokenWrapInstruction2["CloseStuckEscrow"] = 3] = "CloseStuckEscrow";
|
|
102
|
-
TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToToken2022"] = 4] = "SyncMetadataToToken2022";
|
|
103
|
-
TokenWrapInstruction2[TokenWrapInstruction2["SyncMetadataToSplToken"] = 5] = "SyncMetadataToSplToken";
|
|
104
|
-
return TokenWrapInstruction2;
|
|
105
|
-
})(TokenWrapInstruction || {});
|
|
106
|
-
function identifyTokenWrapInstruction(instruction) {
|
|
107
|
-
const data = "data" in instruction ? instruction.data : instruction;
|
|
108
|
-
if (containsBytes(data, getU8Encoder().encode(0), 0)) {
|
|
109
|
-
return 0 /* CreateMint */;
|
|
110
|
-
}
|
|
111
|
-
if (containsBytes(data, getU8Encoder().encode(1), 0)) {
|
|
112
|
-
return 1 /* Wrap */;
|
|
113
|
-
}
|
|
114
|
-
if (containsBytes(data, getU8Encoder().encode(2), 0)) {
|
|
115
|
-
return 2 /* Unwrap */;
|
|
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
|
-
}
|
|
126
|
-
throw new Error(
|
|
127
|
-
"The provided instruction could not be identified as a tokenWrap instruction."
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// src/generated/errors/tokenWrap.ts
|
|
132
|
-
var TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH = 0;
|
|
133
|
-
var TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH = 1;
|
|
134
|
-
var TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT = 2;
|
|
135
|
-
var TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH = 3;
|
|
136
|
-
var TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = 4;
|
|
137
|
-
var TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = 5;
|
|
138
|
-
var TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = 6;
|
|
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;
|
|
148
|
-
var tokenWrapErrorMessages;
|
|
149
|
-
if (process.env.NODE_ENV !== "production") {
|
|
150
|
-
tokenWrapErrorMessages = {
|
|
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`,
|
|
153
|
-
[TOKEN_WRAP_ERROR__ESCROW_MISMATCH]: `Escrow account address does not match expected ATA`,
|
|
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`,
|
|
156
|
-
[TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER]: `Wrapped backpointer account owner is not the expected token wrap program`,
|
|
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`,
|
|
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`,
|
|
165
|
-
[TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH]: `Wrapped mint account address does not match expected PDA`,
|
|
166
|
-
[TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT]: `Wrap amount should be positive`
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
function getTokenWrapErrorMessage(code) {
|
|
170
|
-
if (process.env.NODE_ENV !== "production") {
|
|
171
|
-
return tokenWrapErrorMessages[code];
|
|
172
|
-
}
|
|
173
|
-
return "Error message not available in production bundles.";
|
|
174
|
-
}
|
|
175
|
-
function isTokenWrapError(error, transactionMessage, code) {
|
|
176
|
-
return isProgramError(
|
|
177
|
-
error,
|
|
178
|
-
transactionMessage,
|
|
179
|
-
TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
180
|
-
code
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
function expectAddress(value) {
|
|
184
|
-
if (!value) {
|
|
185
|
-
throw new Error("Expected a Address.");
|
|
186
|
-
}
|
|
187
|
-
if (typeof value === "object" && "address" in value) {
|
|
188
|
-
return value.address;
|
|
189
|
-
}
|
|
190
|
-
if (Array.isArray(value)) {
|
|
191
|
-
return value[0];
|
|
192
|
-
}
|
|
193
|
-
return value;
|
|
194
|
-
}
|
|
195
|
-
function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
|
|
196
|
-
return (account) => {
|
|
197
|
-
if (!account.value) {
|
|
198
|
-
return Object.freeze({
|
|
199
|
-
address: programAddress,
|
|
200
|
-
role: AccountRole.READONLY
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
const writableRole = account.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;
|
|
204
|
-
return Object.freeze({
|
|
205
|
-
address: expectAddress(account.value),
|
|
206
|
-
role: isTransactionSigner(account.value) ? upgradeRoleToSigner(writableRole) : writableRole,
|
|
207
|
-
...isTransactionSigner(account.value) ? { signer: account.value } : {}
|
|
208
|
-
});
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
function isTransactionSigner(value) {
|
|
212
|
-
return !!value && typeof value === "object" && "address" in value && isTransactionSigner$1(value);
|
|
213
|
-
}
|
|
214
|
-
|
|
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
|
-
return Object.freeze({
|
|
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
|
-
data: getCloseStuckEscrowInstructionDataEncoder().encode({}),
|
|
266
|
-
programAddress
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
function parseCloseStuckEscrowInstruction(instruction) {
|
|
270
|
-
if (instruction.accounts.length < 6) {
|
|
271
|
-
throw new Error("Not enough accounts");
|
|
272
|
-
}
|
|
273
|
-
let accountIndex = 0;
|
|
274
|
-
const getNextAccount = () => {
|
|
275
|
-
const accountMeta = instruction.accounts[accountIndex];
|
|
276
|
-
accountIndex += 1;
|
|
277
|
-
return accountMeta;
|
|
278
|
-
};
|
|
279
|
-
const getNextOptionalAccount = () => {
|
|
280
|
-
const accountMeta = getNextAccount();
|
|
281
|
-
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
282
|
-
};
|
|
283
|
-
return {
|
|
284
|
-
programAddress: instruction.programAddress,
|
|
285
|
-
accounts: {
|
|
286
|
-
escrow: getNextAccount(),
|
|
287
|
-
destination: getNextAccount(),
|
|
288
|
-
unwrappedMint: getNextAccount(),
|
|
289
|
-
wrappedMint: getNextAccount(),
|
|
290
|
-
wrappedMintAuthority: getNextAccount(),
|
|
291
|
-
token2022Program: getNextOptionalAccount()
|
|
292
|
-
},
|
|
293
|
-
data: getCloseStuckEscrowInstructionDataDecoder().decode(instruction.data)
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
var CREATE_MINT_DISCRIMINATOR = 0;
|
|
297
|
-
function getCreateMintDiscriminatorBytes() {
|
|
298
|
-
return getU8Encoder().encode(CREATE_MINT_DISCRIMINATOR);
|
|
299
|
-
}
|
|
300
|
-
function getCreateMintInstructionDataEncoder() {
|
|
301
|
-
return transformEncoder(
|
|
302
|
-
getStructEncoder([
|
|
303
|
-
["discriminator", getU8Encoder()],
|
|
304
|
-
["idempotent", getBooleanEncoder()]
|
|
305
|
-
]),
|
|
306
|
-
(value) => ({
|
|
307
|
-
...value,
|
|
308
|
-
discriminator: CREATE_MINT_DISCRIMINATOR,
|
|
309
|
-
idempotent: value.idempotent ?? false
|
|
310
|
-
})
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
function getCreateMintInstructionDataDecoder() {
|
|
314
|
-
return getStructDecoder([
|
|
315
|
-
["discriminator", getU8Decoder()],
|
|
316
|
-
["idempotent", getBooleanDecoder()]
|
|
317
|
-
]);
|
|
318
|
-
}
|
|
319
|
-
function getCreateMintInstructionDataCodec() {
|
|
320
|
-
return combineCodec(
|
|
321
|
-
getCreateMintInstructionDataEncoder(),
|
|
322
|
-
getCreateMintInstructionDataDecoder()
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
function getCreateMintInstruction(input, config) {
|
|
326
|
-
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
327
|
-
const originalAccounts = {
|
|
328
|
-
wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
|
|
329
|
-
backpointer: { value: input.backpointer ?? null, isWritable: true },
|
|
330
|
-
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
331
|
-
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
332
|
-
wrappedTokenProgram: {
|
|
333
|
-
value: input.wrappedTokenProgram ?? null,
|
|
334
|
-
isWritable: false
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
const accounts = originalAccounts;
|
|
338
|
-
const args = { ...input };
|
|
339
|
-
if (!accounts.systemProgram.value) {
|
|
340
|
-
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
341
|
-
}
|
|
342
|
-
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
343
|
-
return Object.freeze({
|
|
344
|
-
accounts: [
|
|
345
|
-
getAccountMeta(accounts.wrappedMint),
|
|
346
|
-
getAccountMeta(accounts.backpointer),
|
|
347
|
-
getAccountMeta(accounts.unwrappedMint),
|
|
348
|
-
getAccountMeta(accounts.systemProgram),
|
|
349
|
-
getAccountMeta(accounts.wrappedTokenProgram)
|
|
350
|
-
],
|
|
351
|
-
data: getCreateMintInstructionDataEncoder().encode(
|
|
352
|
-
args
|
|
353
|
-
),
|
|
354
|
-
programAddress
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
function parseCreateMintInstruction(instruction) {
|
|
358
|
-
if (instruction.accounts.length < 5) {
|
|
359
|
-
throw new Error("Not enough accounts");
|
|
360
|
-
}
|
|
361
|
-
let accountIndex = 0;
|
|
362
|
-
const getNextAccount = () => {
|
|
363
|
-
const accountMeta = instruction.accounts[accountIndex];
|
|
364
|
-
accountIndex += 1;
|
|
365
|
-
return accountMeta;
|
|
366
|
-
};
|
|
367
|
-
const getNextOptionalAccount = () => {
|
|
368
|
-
const accountMeta = getNextAccount();
|
|
369
|
-
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
370
|
-
};
|
|
371
|
-
return {
|
|
372
|
-
programAddress: instruction.programAddress,
|
|
373
|
-
accounts: {
|
|
374
|
-
wrappedMint: getNextAccount(),
|
|
375
|
-
backpointer: getNextAccount(),
|
|
376
|
-
unwrappedMint: getNextAccount(),
|
|
377
|
-
systemProgram: getNextOptionalAccount(),
|
|
378
|
-
wrappedTokenProgram: getNextAccount()
|
|
379
|
-
},
|
|
380
|
-
data: getCreateMintInstructionDataDecoder().decode(instruction.data)
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
var SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR = 5;
|
|
384
|
-
function getSyncMetadataToSplTokenDiscriminatorBytes() {
|
|
385
|
-
return getU8Encoder().encode(SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR);
|
|
386
|
-
}
|
|
387
|
-
function getSyncMetadataToSplTokenInstructionDataEncoder() {
|
|
388
|
-
return transformEncoder(
|
|
389
|
-
getStructEncoder([["discriminator", getU8Encoder()]]),
|
|
390
|
-
(value) => ({
|
|
391
|
-
...value,
|
|
392
|
-
discriminator: SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR
|
|
393
|
-
})
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
function getSyncMetadataToSplTokenInstructionDataDecoder() {
|
|
397
|
-
return getStructDecoder([["discriminator", getU8Decoder()]]);
|
|
398
|
-
}
|
|
399
|
-
function getSyncMetadataToSplTokenInstructionDataCodec() {
|
|
400
|
-
return combineCodec(
|
|
401
|
-
getSyncMetadataToSplTokenInstructionDataEncoder(),
|
|
402
|
-
getSyncMetadataToSplTokenInstructionDataDecoder()
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
function getSyncMetadataToSplTokenInstruction(input, config) {
|
|
406
|
-
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
407
|
-
const originalAccounts = {
|
|
408
|
-
metaplexMetadata: {
|
|
409
|
-
value: input.metaplexMetadata ?? null,
|
|
410
|
-
isWritable: true
|
|
411
|
-
},
|
|
412
|
-
wrappedMintAuthority: {
|
|
413
|
-
value: input.wrappedMintAuthority ?? null,
|
|
414
|
-
isWritable: true
|
|
415
|
-
},
|
|
416
|
-
wrappedMint: { value: input.wrappedMint ?? null, isWritable: false },
|
|
417
|
-
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
418
|
-
metaplexProgram: {
|
|
419
|
-
value: input.metaplexProgram ?? null,
|
|
420
|
-
isWritable: false
|
|
421
|
-
},
|
|
422
|
-
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
423
|
-
rentSysvar: { value: input.rentSysvar ?? null, isWritable: false },
|
|
424
|
-
sourceMetadata: { value: input.sourceMetadata ?? null, isWritable: false },
|
|
425
|
-
ownerProgram: { value: input.ownerProgram ?? null, isWritable: false }
|
|
426
|
-
};
|
|
427
|
-
const accounts = originalAccounts;
|
|
428
|
-
if (!accounts.metaplexProgram.value) {
|
|
429
|
-
accounts.metaplexProgram.value = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s";
|
|
430
|
-
}
|
|
431
|
-
if (!accounts.systemProgram.value) {
|
|
432
|
-
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
433
|
-
}
|
|
434
|
-
if (!accounts.rentSysvar.value) {
|
|
435
|
-
accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
|
|
436
|
-
}
|
|
437
|
-
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
438
|
-
return Object.freeze({
|
|
439
|
-
accounts: [
|
|
440
|
-
getAccountMeta(accounts.metaplexMetadata),
|
|
441
|
-
getAccountMeta(accounts.wrappedMintAuthority),
|
|
442
|
-
getAccountMeta(accounts.wrappedMint),
|
|
443
|
-
getAccountMeta(accounts.unwrappedMint),
|
|
444
|
-
getAccountMeta(accounts.metaplexProgram),
|
|
445
|
-
getAccountMeta(accounts.systemProgram),
|
|
446
|
-
getAccountMeta(accounts.rentSysvar),
|
|
447
|
-
getAccountMeta(accounts.sourceMetadata),
|
|
448
|
-
getAccountMeta(accounts.ownerProgram)
|
|
449
|
-
],
|
|
450
|
-
data: getSyncMetadataToSplTokenInstructionDataEncoder().encode({}),
|
|
451
|
-
programAddress
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
function parseSyncMetadataToSplTokenInstruction(instruction) {
|
|
455
|
-
if (instruction.accounts.length < 9) {
|
|
456
|
-
throw new Error("Not enough accounts");
|
|
457
|
-
}
|
|
458
|
-
let accountIndex = 0;
|
|
459
|
-
const getNextAccount = () => {
|
|
460
|
-
const accountMeta = instruction.accounts[accountIndex];
|
|
461
|
-
accountIndex += 1;
|
|
462
|
-
return accountMeta;
|
|
463
|
-
};
|
|
464
|
-
const getNextOptionalAccount = () => {
|
|
465
|
-
const accountMeta = getNextAccount();
|
|
466
|
-
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
467
|
-
};
|
|
468
|
-
return {
|
|
469
|
-
programAddress: instruction.programAddress,
|
|
470
|
-
accounts: {
|
|
471
|
-
metaplexMetadata: getNextAccount(),
|
|
472
|
-
wrappedMintAuthority: getNextAccount(),
|
|
473
|
-
wrappedMint: getNextAccount(),
|
|
474
|
-
unwrappedMint: getNextAccount(),
|
|
475
|
-
metaplexProgram: getNextAccount(),
|
|
476
|
-
systemProgram: getNextAccount(),
|
|
477
|
-
rentSysvar: getNextAccount(),
|
|
478
|
-
sourceMetadata: getNextOptionalAccount(),
|
|
479
|
-
ownerProgram: getNextOptionalAccount()
|
|
480
|
-
},
|
|
481
|
-
data: getSyncMetadataToSplTokenInstructionDataDecoder().decode(
|
|
482
|
-
instruction.data
|
|
483
|
-
)
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
var SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR = 4;
|
|
487
|
-
function getSyncMetadataToToken2022DiscriminatorBytes() {
|
|
488
|
-
return getU8Encoder().encode(SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR);
|
|
489
|
-
}
|
|
490
|
-
function getSyncMetadataToToken2022InstructionDataEncoder() {
|
|
491
|
-
return transformEncoder(
|
|
492
|
-
getStructEncoder([["discriminator", getU8Encoder()]]),
|
|
493
|
-
(value) => ({
|
|
494
|
-
...value,
|
|
495
|
-
discriminator: SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR
|
|
496
|
-
})
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
function getSyncMetadataToToken2022InstructionDataDecoder() {
|
|
500
|
-
return getStructDecoder([["discriminator", getU8Decoder()]]);
|
|
501
|
-
}
|
|
502
|
-
function getSyncMetadataToToken2022InstructionDataCodec() {
|
|
503
|
-
return combineCodec(
|
|
504
|
-
getSyncMetadataToToken2022InstructionDataEncoder(),
|
|
505
|
-
getSyncMetadataToToken2022InstructionDataDecoder()
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
function getSyncMetadataToToken2022Instruction(input, config) {
|
|
509
|
-
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
510
|
-
const originalAccounts = {
|
|
511
|
-
wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
|
|
512
|
-
wrappedMintAuthority: {
|
|
513
|
-
value: input.wrappedMintAuthority ?? null,
|
|
514
|
-
isWritable: false
|
|
515
|
-
},
|
|
516
|
-
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
517
|
-
token2022Program: {
|
|
518
|
-
value: input.token2022Program ?? null,
|
|
519
|
-
isWritable: false
|
|
520
|
-
},
|
|
521
|
-
sourceMetadata: { value: input.sourceMetadata ?? null, isWritable: false },
|
|
522
|
-
ownerProgram: { value: input.ownerProgram ?? null, isWritable: false }
|
|
523
|
-
};
|
|
524
|
-
const accounts = originalAccounts;
|
|
525
|
-
if (!accounts.token2022Program.value) {
|
|
526
|
-
accounts.token2022Program.value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
527
|
-
}
|
|
528
|
-
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
529
|
-
return Object.freeze({
|
|
530
|
-
accounts: [
|
|
531
|
-
getAccountMeta(accounts.wrappedMint),
|
|
532
|
-
getAccountMeta(accounts.wrappedMintAuthority),
|
|
533
|
-
getAccountMeta(accounts.unwrappedMint),
|
|
534
|
-
getAccountMeta(accounts.token2022Program),
|
|
535
|
-
getAccountMeta(accounts.sourceMetadata),
|
|
536
|
-
getAccountMeta(accounts.ownerProgram)
|
|
537
|
-
],
|
|
538
|
-
data: getSyncMetadataToToken2022InstructionDataEncoder().encode({}),
|
|
539
|
-
programAddress
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
function parseSyncMetadataToToken2022Instruction(instruction) {
|
|
543
|
-
if (instruction.accounts.length < 6) {
|
|
544
|
-
throw new Error("Not enough accounts");
|
|
545
|
-
}
|
|
546
|
-
let accountIndex = 0;
|
|
547
|
-
const getNextAccount = () => {
|
|
548
|
-
const accountMeta = instruction.accounts[accountIndex];
|
|
549
|
-
accountIndex += 1;
|
|
550
|
-
return accountMeta;
|
|
551
|
-
};
|
|
552
|
-
const getNextOptionalAccount = () => {
|
|
553
|
-
const accountMeta = getNextAccount();
|
|
554
|
-
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
555
|
-
};
|
|
556
|
-
return {
|
|
557
|
-
programAddress: instruction.programAddress,
|
|
558
|
-
accounts: {
|
|
559
|
-
wrappedMint: getNextAccount(),
|
|
560
|
-
wrappedMintAuthority: getNextAccount(),
|
|
561
|
-
unwrappedMint: getNextAccount(),
|
|
562
|
-
token2022Program: getNextAccount(),
|
|
563
|
-
sourceMetadata: getNextOptionalAccount(),
|
|
564
|
-
ownerProgram: getNextOptionalAccount()
|
|
565
|
-
},
|
|
566
|
-
data: getSyncMetadataToToken2022InstructionDataDecoder().decode(
|
|
567
|
-
instruction.data
|
|
568
|
-
)
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
var UNWRAP_DISCRIMINATOR = 2;
|
|
572
|
-
function getUnwrapDiscriminatorBytes() {
|
|
573
|
-
return getU8Encoder().encode(UNWRAP_DISCRIMINATOR);
|
|
574
|
-
}
|
|
575
|
-
function getUnwrapInstructionDataEncoder() {
|
|
576
|
-
return transformEncoder(
|
|
577
|
-
getStructEncoder([
|
|
578
|
-
["discriminator", getU8Encoder()],
|
|
579
|
-
["amount", getU64Encoder()]
|
|
580
|
-
]),
|
|
581
|
-
(value) => ({ ...value, discriminator: UNWRAP_DISCRIMINATOR })
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
|
-
function getUnwrapInstructionDataDecoder() {
|
|
585
|
-
return getStructDecoder([
|
|
586
|
-
["discriminator", getU8Decoder()],
|
|
587
|
-
["amount", getU64Decoder()]
|
|
588
|
-
]);
|
|
589
|
-
}
|
|
590
|
-
function getUnwrapInstructionDataCodec() {
|
|
591
|
-
return combineCodec(
|
|
592
|
-
getUnwrapInstructionDataEncoder(),
|
|
593
|
-
getUnwrapInstructionDataDecoder()
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
function getUnwrapInstruction(input, config) {
|
|
597
|
-
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
598
|
-
const originalAccounts = {
|
|
599
|
-
unwrappedEscrow: { value: input.unwrappedEscrow ?? null, isWritable: true },
|
|
600
|
-
recipientUnwrappedToken: {
|
|
601
|
-
value: input.recipientUnwrappedToken ?? null,
|
|
602
|
-
isWritable: true
|
|
603
|
-
},
|
|
604
|
-
wrappedMintAuthority: {
|
|
605
|
-
value: input.wrappedMintAuthority ?? null,
|
|
606
|
-
isWritable: false
|
|
607
|
-
},
|
|
608
|
-
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
609
|
-
wrappedTokenProgram: {
|
|
610
|
-
value: input.wrappedTokenProgram ?? null,
|
|
611
|
-
isWritable: false
|
|
612
|
-
},
|
|
613
|
-
unwrappedTokenProgram: {
|
|
614
|
-
value: input.unwrappedTokenProgram ?? null,
|
|
615
|
-
isWritable: false
|
|
616
|
-
},
|
|
617
|
-
wrappedTokenAccount: {
|
|
618
|
-
value: input.wrappedTokenAccount ?? null,
|
|
619
|
-
isWritable: true
|
|
620
|
-
},
|
|
621
|
-
wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
|
|
622
|
-
transferAuthority: {
|
|
623
|
-
value: input.transferAuthority ?? null,
|
|
624
|
-
isWritable: false
|
|
625
|
-
}
|
|
626
|
-
};
|
|
627
|
-
const accounts = originalAccounts;
|
|
628
|
-
const args = { ...input };
|
|
629
|
-
const remainingAccounts = (args.multiSigners ?? []).map(
|
|
630
|
-
(signer) => ({
|
|
631
|
-
address: signer.address,
|
|
632
|
-
role: AccountRole.READONLY_SIGNER,
|
|
633
|
-
signer
|
|
634
|
-
})
|
|
635
|
-
);
|
|
636
|
-
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
637
|
-
return Object.freeze({
|
|
638
|
-
accounts: [
|
|
639
|
-
getAccountMeta(accounts.unwrappedEscrow),
|
|
640
|
-
getAccountMeta(accounts.recipientUnwrappedToken),
|
|
641
|
-
getAccountMeta(accounts.wrappedMintAuthority),
|
|
642
|
-
getAccountMeta(accounts.unwrappedMint),
|
|
643
|
-
getAccountMeta(accounts.wrappedTokenProgram),
|
|
644
|
-
getAccountMeta(accounts.unwrappedTokenProgram),
|
|
645
|
-
getAccountMeta(accounts.wrappedTokenAccount),
|
|
646
|
-
getAccountMeta(accounts.wrappedMint),
|
|
647
|
-
getAccountMeta(accounts.transferAuthority),
|
|
648
|
-
...remainingAccounts
|
|
649
|
-
],
|
|
650
|
-
data: getUnwrapInstructionDataEncoder().encode(
|
|
651
|
-
args
|
|
652
|
-
),
|
|
653
|
-
programAddress
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
function parseUnwrapInstruction(instruction) {
|
|
657
|
-
if (instruction.accounts.length < 9) {
|
|
658
|
-
throw new Error("Not enough accounts");
|
|
659
|
-
}
|
|
660
|
-
let accountIndex = 0;
|
|
661
|
-
const getNextAccount = () => {
|
|
662
|
-
const accountMeta = instruction.accounts[accountIndex];
|
|
663
|
-
accountIndex += 1;
|
|
664
|
-
return accountMeta;
|
|
665
|
-
};
|
|
666
|
-
return {
|
|
667
|
-
programAddress: instruction.programAddress,
|
|
668
|
-
accounts: {
|
|
669
|
-
unwrappedEscrow: getNextAccount(),
|
|
670
|
-
recipientUnwrappedToken: getNextAccount(),
|
|
671
|
-
wrappedMintAuthority: getNextAccount(),
|
|
672
|
-
unwrappedMint: getNextAccount(),
|
|
673
|
-
wrappedTokenProgram: getNextAccount(),
|
|
674
|
-
unwrappedTokenProgram: getNextAccount(),
|
|
675
|
-
wrappedTokenAccount: getNextAccount(),
|
|
676
|
-
wrappedMint: getNextAccount(),
|
|
677
|
-
transferAuthority: getNextAccount()
|
|
678
|
-
},
|
|
679
|
-
data: getUnwrapInstructionDataDecoder().decode(instruction.data)
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
var WRAP_DISCRIMINATOR = 1;
|
|
683
|
-
function getWrapDiscriminatorBytes() {
|
|
684
|
-
return getU8Encoder().encode(WRAP_DISCRIMINATOR);
|
|
685
|
-
}
|
|
686
|
-
function getWrapInstructionDataEncoder() {
|
|
687
|
-
return transformEncoder(
|
|
688
|
-
getStructEncoder([
|
|
689
|
-
["discriminator", getU8Encoder()],
|
|
690
|
-
["amount", getU64Encoder()]
|
|
691
|
-
]),
|
|
692
|
-
(value) => ({ ...value, discriminator: WRAP_DISCRIMINATOR })
|
|
693
|
-
);
|
|
694
|
-
}
|
|
695
|
-
function getWrapInstructionDataDecoder() {
|
|
696
|
-
return getStructDecoder([
|
|
697
|
-
["discriminator", getU8Decoder()],
|
|
698
|
-
["amount", getU64Decoder()]
|
|
699
|
-
]);
|
|
700
|
-
}
|
|
701
|
-
function getWrapInstructionDataCodec() {
|
|
702
|
-
return combineCodec(
|
|
703
|
-
getWrapInstructionDataEncoder(),
|
|
704
|
-
getWrapInstructionDataDecoder()
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
function getWrapInstruction(input, config) {
|
|
708
|
-
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
709
|
-
const originalAccounts = {
|
|
710
|
-
recipientWrappedTokenAccount: {
|
|
711
|
-
value: input.recipientWrappedTokenAccount ?? null,
|
|
712
|
-
isWritable: true
|
|
713
|
-
},
|
|
714
|
-
wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
|
|
715
|
-
wrappedMintAuthority: {
|
|
716
|
-
value: input.wrappedMintAuthority ?? null,
|
|
717
|
-
isWritable: false
|
|
718
|
-
},
|
|
719
|
-
unwrappedTokenProgram: {
|
|
720
|
-
value: input.unwrappedTokenProgram ?? null,
|
|
721
|
-
isWritable: false
|
|
722
|
-
},
|
|
723
|
-
wrappedTokenProgram: {
|
|
724
|
-
value: input.wrappedTokenProgram ?? null,
|
|
725
|
-
isWritable: false
|
|
726
|
-
},
|
|
727
|
-
unwrappedTokenAccount: {
|
|
728
|
-
value: input.unwrappedTokenAccount ?? null,
|
|
729
|
-
isWritable: true
|
|
730
|
-
},
|
|
731
|
-
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
732
|
-
unwrappedEscrow: { value: input.unwrappedEscrow ?? null, isWritable: true },
|
|
733
|
-
transferAuthority: {
|
|
734
|
-
value: input.transferAuthority ?? null,
|
|
735
|
-
isWritable: false
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
const accounts = originalAccounts;
|
|
739
|
-
const args = { ...input };
|
|
740
|
-
const remainingAccounts = (args.multiSigners ?? []).map(
|
|
741
|
-
(signer) => ({
|
|
742
|
-
address: signer.address,
|
|
743
|
-
role: AccountRole.READONLY_SIGNER,
|
|
744
|
-
signer
|
|
745
|
-
})
|
|
746
|
-
);
|
|
747
|
-
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
748
|
-
return Object.freeze({
|
|
749
|
-
accounts: [
|
|
750
|
-
getAccountMeta(accounts.recipientWrappedTokenAccount),
|
|
751
|
-
getAccountMeta(accounts.wrappedMint),
|
|
752
|
-
getAccountMeta(accounts.wrappedMintAuthority),
|
|
753
|
-
getAccountMeta(accounts.unwrappedTokenProgram),
|
|
754
|
-
getAccountMeta(accounts.wrappedTokenProgram),
|
|
755
|
-
getAccountMeta(accounts.unwrappedTokenAccount),
|
|
756
|
-
getAccountMeta(accounts.unwrappedMint),
|
|
757
|
-
getAccountMeta(accounts.unwrappedEscrow),
|
|
758
|
-
getAccountMeta(accounts.transferAuthority),
|
|
759
|
-
...remainingAccounts
|
|
760
|
-
],
|
|
761
|
-
data: getWrapInstructionDataEncoder().encode(
|
|
762
|
-
args
|
|
763
|
-
),
|
|
764
|
-
programAddress
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
function parseWrapInstruction(instruction) {
|
|
768
|
-
if (instruction.accounts.length < 9) {
|
|
769
|
-
throw new Error("Not enough accounts");
|
|
770
|
-
}
|
|
771
|
-
let accountIndex = 0;
|
|
772
|
-
const getNextAccount = () => {
|
|
773
|
-
const accountMeta = instruction.accounts[accountIndex];
|
|
774
|
-
accountIndex += 1;
|
|
775
|
-
return accountMeta;
|
|
776
|
-
};
|
|
777
|
-
return {
|
|
778
|
-
programAddress: instruction.programAddress,
|
|
779
|
-
accounts: {
|
|
780
|
-
recipientWrappedTokenAccount: getNextAccount(),
|
|
781
|
-
wrappedMint: getNextAccount(),
|
|
782
|
-
wrappedMintAuthority: getNextAccount(),
|
|
783
|
-
unwrappedTokenProgram: getNextAccount(),
|
|
784
|
-
wrappedTokenProgram: getNextAccount(),
|
|
785
|
-
unwrappedTokenAccount: getNextAccount(),
|
|
786
|
-
unwrappedMint: getNextAccount(),
|
|
787
|
-
unwrappedEscrow: getNextAccount(),
|
|
788
|
-
transferAuthority: getNextAccount()
|
|
789
|
-
},
|
|
790
|
-
data: getWrapInstructionDataDecoder().decode(instruction.data)
|
|
791
|
-
};
|
|
792
|
-
}
|
|
793
|
-
var DEFAULT_EXTENSIONS = [
|
|
794
|
-
extension("ConfidentialTransferMint", {
|
|
795
|
-
autoApproveNewAccounts: true,
|
|
796
|
-
authority: null,
|
|
797
|
-
auditorElgamalPubkey: null
|
|
798
|
-
}),
|
|
799
|
-
extension("MetadataPointer", {
|
|
800
|
-
authority: null,
|
|
801
|
-
metadataAddress: null
|
|
802
|
-
})
|
|
803
|
-
];
|
|
804
|
-
async function createMint({
|
|
805
|
-
rpc,
|
|
806
|
-
unwrappedMint,
|
|
807
|
-
wrappedTokenProgram,
|
|
808
|
-
payer,
|
|
809
|
-
idempotent = false
|
|
810
|
-
}) {
|
|
811
|
-
const [wrappedMint] = await findWrappedMintPda({
|
|
812
|
-
unwrappedMint,
|
|
813
|
-
wrappedTokenProgram
|
|
814
|
-
});
|
|
815
|
-
const [backpointer] = await findBackpointerPda({ wrappedMint });
|
|
816
|
-
const instructions = [];
|
|
817
|
-
let fundedWrappedMintLamports = 0n;
|
|
818
|
-
let mintSize = BigInt(getMintSize());
|
|
819
|
-
if (wrappedTokenProgram === TOKEN_2022_PROGRAM_ADDRESS) {
|
|
820
|
-
mintSize = BigInt(getMintSize(DEFAULT_EXTENSIONS));
|
|
821
|
-
}
|
|
822
|
-
const [wrappedMintAccount, wrappedMintRent] = await Promise.all([
|
|
823
|
-
fetchEncodedAccount(rpc, wrappedMint),
|
|
824
|
-
rpc.getMinimumBalanceForRentExemption(mintSize).send()
|
|
825
|
-
]);
|
|
826
|
-
const wrappedMintLamports = wrappedMintAccount.exists ? wrappedMintAccount.lamports : 0n;
|
|
827
|
-
if (wrappedMintLamports < wrappedMintRent) {
|
|
828
|
-
fundedWrappedMintLamports = wrappedMintRent - wrappedMintLamports;
|
|
829
|
-
instructions.push(
|
|
830
|
-
getTransferSolInstruction({
|
|
831
|
-
source: payer,
|
|
832
|
-
destination: wrappedMint,
|
|
833
|
-
amount: fundedWrappedMintLamports
|
|
834
|
-
})
|
|
835
|
-
);
|
|
836
|
-
}
|
|
837
|
-
let fundedBackpointerLamports = 0n;
|
|
838
|
-
const backpointerSize = BigInt(getBackpointerSize());
|
|
839
|
-
const [backpointerAccount, backpointerRent] = await Promise.all([
|
|
840
|
-
fetchEncodedAccount(rpc, backpointer),
|
|
841
|
-
rpc.getMinimumBalanceForRentExemption(backpointerSize).send()
|
|
842
|
-
]);
|
|
843
|
-
const backpointerLamports = backpointerAccount.exists ? backpointerAccount.lamports : 0n;
|
|
844
|
-
if (backpointerLamports < backpointerRent) {
|
|
845
|
-
fundedBackpointerLamports = backpointerRent - backpointerLamports;
|
|
846
|
-
instructions.push(
|
|
847
|
-
getTransferSolInstruction({
|
|
848
|
-
source: payer,
|
|
849
|
-
destination: backpointer,
|
|
850
|
-
amount: fundedBackpointerLamports
|
|
851
|
-
})
|
|
852
|
-
);
|
|
853
|
-
}
|
|
854
|
-
instructions.push(
|
|
855
|
-
getCreateMintInstruction({
|
|
856
|
-
wrappedMint,
|
|
857
|
-
backpointer,
|
|
858
|
-
unwrappedMint,
|
|
859
|
-
wrappedTokenProgram,
|
|
860
|
-
idempotent
|
|
861
|
-
})
|
|
862
|
-
);
|
|
863
|
-
return {
|
|
864
|
-
wrappedMint,
|
|
865
|
-
backpointer,
|
|
866
|
-
ixs: instructions,
|
|
867
|
-
fundedWrappedMintLamports,
|
|
868
|
-
fundedBackpointerLamports
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
async function createEscrowAccount({
|
|
872
|
-
rpc,
|
|
873
|
-
payer,
|
|
874
|
-
unwrappedMint,
|
|
875
|
-
wrappedTokenProgram
|
|
876
|
-
}) {
|
|
877
|
-
const [wrappedMint] = await findWrappedMintPda({ unwrappedMint, wrappedTokenProgram });
|
|
878
|
-
const [wrappedMintAuthority] = await findWrappedMintAuthorityPda({ wrappedMint });
|
|
879
|
-
const unwrappedTokenProgram = await getOwnerFromAccount(rpc, unwrappedMint);
|
|
880
|
-
const [escrowAta] = await findAssociatedTokenPda({
|
|
881
|
-
owner: wrappedMintAuthority,
|
|
882
|
-
mint: unwrappedMint,
|
|
883
|
-
tokenProgram: unwrappedTokenProgram
|
|
884
|
-
});
|
|
885
|
-
const escrowResult = await fetchMaybeToken(rpc, escrowAta);
|
|
886
|
-
if (escrowResult.exists) {
|
|
887
|
-
return { kind: "already_exists", account: escrowResult };
|
|
888
|
-
}
|
|
889
|
-
const ix = getCreateAssociatedTokenInstruction({
|
|
890
|
-
payer,
|
|
891
|
-
owner: wrappedMintAuthority,
|
|
892
|
-
mint: unwrappedMint,
|
|
893
|
-
ata: escrowAta,
|
|
894
|
-
tokenProgram: unwrappedTokenProgram
|
|
895
|
-
});
|
|
896
|
-
return { address: escrowAta, ixs: [ix], kind: "instructions_to_create" };
|
|
897
|
-
}
|
|
898
|
-
async function getOwnerFromAccount(rpc, accountAddress) {
|
|
899
|
-
const accountInfo = await rpc.getAccountInfo(accountAddress, { encoding: "base64" }).send();
|
|
900
|
-
if (!accountInfo.value) {
|
|
901
|
-
throw new Error(`Account ${accountAddress} not found.`);
|
|
902
|
-
}
|
|
903
|
-
return accountInfo.value.owner;
|
|
904
|
-
}
|
|
905
|
-
async function getMintFromTokenAccount(rpc, tokenAccountAddress) {
|
|
906
|
-
const account = await fetchEncodedAccount(rpc, tokenAccountAddress);
|
|
907
|
-
if (!account.exists) {
|
|
908
|
-
throw new Error(`Unwrapped token account ${tokenAccountAddress} not found.`);
|
|
909
|
-
}
|
|
910
|
-
return getTokenDecoder().decode(account.data).mint;
|
|
911
|
-
}
|
|
912
|
-
function messageBytesEqual(results) {
|
|
913
|
-
if (results.length === 1) {
|
|
914
|
-
return true;
|
|
915
|
-
}
|
|
916
|
-
const reference = results[0];
|
|
917
|
-
if (!reference) throw new Error("No transactions in input");
|
|
918
|
-
return results.every(
|
|
919
|
-
(c) => reference.messageBytes.length === c.messageBytes.length && containsBytes(reference.messageBytes, c.messageBytes, 0)
|
|
920
|
-
);
|
|
921
|
-
}
|
|
922
|
-
function combineSignatures(signedTxs) {
|
|
923
|
-
const firstSignedTx = signedTxs[0];
|
|
924
|
-
if (!firstSignedTx) {
|
|
925
|
-
throw new Error("No signed transactions provided");
|
|
926
|
-
}
|
|
927
|
-
const allSignatures = {};
|
|
928
|
-
for (const pubkey of Object.keys(firstSignedTx.signatures)) {
|
|
929
|
-
allSignatures[pubkey] = null;
|
|
930
|
-
}
|
|
931
|
-
for (const signedTx of signedTxs) {
|
|
932
|
-
for (const [address, signature] of Object.entries(signedTx.signatures)) {
|
|
933
|
-
if (signature) {
|
|
934
|
-
allSignatures[address] = signature;
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
const missingSigners = [];
|
|
939
|
-
for (const [pubkey, signature] of Object.entries(allSignatures)) {
|
|
940
|
-
if (signature === null) {
|
|
941
|
-
missingSigners.push(pubkey);
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
if (missingSigners.length > 0) {
|
|
945
|
-
throw new Error(`Missing signatures for: ${missingSigners.join(", ")}`);
|
|
946
|
-
}
|
|
947
|
-
return allSignatures;
|
|
948
|
-
}
|
|
949
|
-
function combinedMultisigTx({
|
|
950
|
-
signedTxs,
|
|
951
|
-
blockhash
|
|
952
|
-
}) {
|
|
953
|
-
const messagesEqual = messageBytesEqual(signedTxs);
|
|
954
|
-
if (!messagesEqual) throw new Error("Messages are not all the same");
|
|
955
|
-
if (!signedTxs[0]) throw new Error("No signed transactions provided");
|
|
956
|
-
const tx = {
|
|
957
|
-
messageBytes: signedTxs[0].messageBytes,
|
|
958
|
-
signatures: combineSignatures(signedTxs),
|
|
959
|
-
lifetimeConstraint: blockhash
|
|
960
|
-
};
|
|
961
|
-
assertIsFullySignedTransaction(tx);
|
|
962
|
-
assertIsSendableTransaction(tx);
|
|
963
|
-
return tx;
|
|
964
|
-
}
|
|
965
|
-
async function multisigOfflineSignWrap(args) {
|
|
966
|
-
const wrapIx = await buildWrapIx(args);
|
|
967
|
-
return pipe(
|
|
968
|
-
createTransactionMessage({ version: 0 }),
|
|
969
|
-
(tx) => setTransactionMessageFeePayerSigner(args.payer, tx),
|
|
970
|
-
(tx) => setTransactionMessageLifetimeUsingBlockhash(args.blockhash, tx),
|
|
971
|
-
(tx) => appendTransactionMessageInstructions([wrapIx], tx)
|
|
972
|
-
);
|
|
973
|
-
}
|
|
974
|
-
async function singleSignerWrap({
|
|
975
|
-
rpc,
|
|
976
|
-
payer,
|
|
977
|
-
unwrappedTokenAccount,
|
|
978
|
-
wrappedTokenProgram,
|
|
979
|
-
amount,
|
|
980
|
-
transferAuthority: inputTransferAuthority,
|
|
981
|
-
unwrappedMint: inputUnwrappedMint,
|
|
982
|
-
recipientWrappedTokenAccount: inputRecipientTokenAccount,
|
|
983
|
-
unwrappedTokenProgram: inputUnwrappedTokenProgram
|
|
984
|
-
}) {
|
|
985
|
-
const {
|
|
986
|
-
unwrappedMint,
|
|
987
|
-
unwrappedTokenProgram,
|
|
988
|
-
wrappedMint,
|
|
989
|
-
wrappedMintAuthority,
|
|
990
|
-
recipientWrappedTokenAccount,
|
|
991
|
-
transferAuthority,
|
|
992
|
-
unwrappedEscrow
|
|
993
|
-
} = await resolveAddrs({
|
|
994
|
-
rpc,
|
|
995
|
-
payer,
|
|
996
|
-
inputTransferAuthority,
|
|
997
|
-
inputUnwrappedMint,
|
|
998
|
-
unwrappedTokenAccount,
|
|
999
|
-
inputUnwrappedTokenProgram,
|
|
1000
|
-
wrappedTokenProgram,
|
|
1001
|
-
inputRecipientTokenAccount
|
|
1002
|
-
});
|
|
1003
|
-
const ix = await buildWrapIx({
|
|
1004
|
-
unwrappedTokenAccount,
|
|
1005
|
-
wrappedTokenProgram,
|
|
1006
|
-
amount,
|
|
1007
|
-
transferAuthority,
|
|
1008
|
-
unwrappedMint,
|
|
1009
|
-
wrappedMint,
|
|
1010
|
-
wrappedMintAuthority,
|
|
1011
|
-
recipientWrappedTokenAccount,
|
|
1012
|
-
unwrappedTokenProgram
|
|
1013
|
-
});
|
|
1014
|
-
return {
|
|
1015
|
-
ixs: [ix],
|
|
1016
|
-
recipientWrappedTokenAccount,
|
|
1017
|
-
escrowAccount: unwrappedEscrow,
|
|
1018
|
-
amount: BigInt(amount)
|
|
1019
|
-
};
|
|
1020
|
-
}
|
|
1021
|
-
async function resolveAddrs({
|
|
1022
|
-
rpc,
|
|
1023
|
-
payer,
|
|
1024
|
-
unwrappedTokenAccount,
|
|
1025
|
-
wrappedTokenProgram,
|
|
1026
|
-
inputTransferAuthority,
|
|
1027
|
-
inputUnwrappedMint,
|
|
1028
|
-
inputRecipientTokenAccount,
|
|
1029
|
-
inputUnwrappedTokenProgram
|
|
1030
|
-
}) {
|
|
1031
|
-
const unwrappedMint = inputUnwrappedMint ?? await getMintFromTokenAccount(rpc, unwrappedTokenAccount);
|
|
1032
|
-
const unwrappedTokenProgram = inputUnwrappedTokenProgram ?? await getOwnerFromAccount(rpc, unwrappedTokenAccount);
|
|
1033
|
-
const [wrappedMint] = await findWrappedMintPda({ unwrappedMint, wrappedTokenProgram });
|
|
1034
|
-
const [wrappedMintAuthority] = await findWrappedMintAuthorityPda({ wrappedMint });
|
|
1035
|
-
const recipientWrappedTokenAccount = inputRecipientTokenAccount ?? (await findAssociatedTokenPda({
|
|
1036
|
-
owner: payer.address,
|
|
1037
|
-
mint: wrappedMint,
|
|
1038
|
-
tokenProgram: wrappedTokenProgram
|
|
1039
|
-
}))[0];
|
|
1040
|
-
const [unwrappedEscrow] = await findAssociatedTokenPda({
|
|
1041
|
-
owner: wrappedMintAuthority,
|
|
1042
|
-
mint: unwrappedMint,
|
|
1043
|
-
tokenProgram: unwrappedTokenProgram
|
|
1044
|
-
});
|
|
1045
|
-
const transferAuthority = inputTransferAuthority ?? payer;
|
|
1046
|
-
return {
|
|
1047
|
-
unwrappedEscrow,
|
|
1048
|
-
transferAuthority,
|
|
1049
|
-
unwrappedMint,
|
|
1050
|
-
unwrappedTokenProgram,
|
|
1051
|
-
wrappedMint,
|
|
1052
|
-
wrappedMintAuthority,
|
|
1053
|
-
recipientWrappedTokenAccount
|
|
1054
|
-
};
|
|
1055
|
-
}
|
|
1056
|
-
async function buildWrapIx({
|
|
1057
|
-
unwrappedTokenAccount,
|
|
1058
|
-
wrappedTokenProgram,
|
|
1059
|
-
amount,
|
|
1060
|
-
transferAuthority,
|
|
1061
|
-
unwrappedMint,
|
|
1062
|
-
recipientWrappedTokenAccount,
|
|
1063
|
-
unwrappedTokenProgram,
|
|
1064
|
-
wrappedMint,
|
|
1065
|
-
wrappedMintAuthority,
|
|
1066
|
-
multiSigners = []
|
|
1067
|
-
}) {
|
|
1068
|
-
const [unwrappedEscrow] = await findAssociatedTokenPda({
|
|
1069
|
-
owner: wrappedMintAuthority,
|
|
1070
|
-
mint: unwrappedMint,
|
|
1071
|
-
tokenProgram: unwrappedTokenProgram
|
|
1072
|
-
});
|
|
1073
|
-
const wrapInstructionInput = {
|
|
1074
|
-
recipientWrappedTokenAccount,
|
|
1075
|
-
wrappedMint,
|
|
1076
|
-
wrappedMintAuthority,
|
|
1077
|
-
unwrappedTokenProgram,
|
|
1078
|
-
wrappedTokenProgram,
|
|
1079
|
-
unwrappedTokenAccount,
|
|
1080
|
-
unwrappedMint,
|
|
1081
|
-
unwrappedEscrow,
|
|
1082
|
-
transferAuthority,
|
|
1083
|
-
amount: BigInt(amount),
|
|
1084
|
-
multiSigners
|
|
1085
|
-
};
|
|
1086
|
-
return getWrapInstruction(wrapInstructionInput);
|
|
1087
|
-
}
|
|
1088
|
-
async function resolveUnwrapAddrs({
|
|
1089
|
-
rpc,
|
|
1090
|
-
payer,
|
|
1091
|
-
wrappedTokenAccount,
|
|
1092
|
-
recipientUnwrappedToken,
|
|
1093
|
-
inputUnwrappedMint,
|
|
1094
|
-
inputTransferAuthority,
|
|
1095
|
-
inputWrappedTokenProgram,
|
|
1096
|
-
inputUnwrappedTokenProgram
|
|
1097
|
-
}) {
|
|
1098
|
-
const wrappedTokenProgram = inputWrappedTokenProgram ?? await getOwnerFromAccount(rpc, wrappedTokenAccount);
|
|
1099
|
-
const unwrappedTokenProgram = inputUnwrappedTokenProgram ?? await getOwnerFromAccount(rpc, recipientUnwrappedToken);
|
|
1100
|
-
const unwrappedMint = inputUnwrappedMint ?? await getMintFromTokenAccount(rpc, recipientUnwrappedToken);
|
|
1101
|
-
const wrappedAccountInfo = await fetchEncodedAccount(rpc, wrappedTokenAccount);
|
|
1102
|
-
if (!wrappedAccountInfo.exists) {
|
|
1103
|
-
throw new Error(`Wrapped token account ${wrappedTokenAccount} not found.`);
|
|
1104
|
-
}
|
|
1105
|
-
const wrappedMint = getTokenDecoder().decode(wrappedAccountInfo.data).mint;
|
|
1106
|
-
const [wrappedMintAuthority] = await findWrappedMintAuthorityPda({ wrappedMint });
|
|
1107
|
-
const transferAuthority = inputTransferAuthority ?? payer;
|
|
1108
|
-
return {
|
|
1109
|
-
unwrappedMint,
|
|
1110
|
-
wrappedMint,
|
|
1111
|
-
wrappedMintAuthority,
|
|
1112
|
-
transferAuthority,
|
|
1113
|
-
wrappedTokenProgram,
|
|
1114
|
-
unwrappedTokenProgram
|
|
1115
|
-
};
|
|
1116
|
-
}
|
|
1117
|
-
async function buildUnwrapTransaction({
|
|
1118
|
-
recipientUnwrappedToken,
|
|
1119
|
-
wrappedMintAuthority,
|
|
1120
|
-
unwrappedMint,
|
|
1121
|
-
wrappedTokenProgram,
|
|
1122
|
-
unwrappedTokenProgram,
|
|
1123
|
-
wrappedTokenAccount,
|
|
1124
|
-
wrappedMint,
|
|
1125
|
-
transferAuthority,
|
|
1126
|
-
amount,
|
|
1127
|
-
multiSigners = []
|
|
1128
|
-
}) {
|
|
1129
|
-
const [unwrappedEscrow] = await findAssociatedTokenPda({
|
|
1130
|
-
owner: wrappedMintAuthority,
|
|
1131
|
-
mint: unwrappedMint,
|
|
1132
|
-
tokenProgram: unwrappedTokenProgram
|
|
1133
|
-
});
|
|
1134
|
-
const unwrapInstructionInput = {
|
|
1135
|
-
unwrappedEscrow,
|
|
1136
|
-
recipientUnwrappedToken,
|
|
1137
|
-
wrappedMintAuthority,
|
|
1138
|
-
unwrappedMint,
|
|
1139
|
-
wrappedTokenProgram,
|
|
1140
|
-
unwrappedTokenProgram,
|
|
1141
|
-
wrappedTokenAccount,
|
|
1142
|
-
wrappedMint,
|
|
1143
|
-
transferAuthority,
|
|
1144
|
-
amount: BigInt(amount),
|
|
1145
|
-
multiSigners
|
|
1146
|
-
};
|
|
1147
|
-
return getUnwrapInstruction(unwrapInstructionInput);
|
|
1148
|
-
}
|
|
1149
|
-
async function singleSignerUnwrap({
|
|
1150
|
-
rpc,
|
|
1151
|
-
payer,
|
|
1152
|
-
wrappedTokenAccount,
|
|
1153
|
-
amount,
|
|
1154
|
-
recipientUnwrappedToken,
|
|
1155
|
-
transferAuthority: inputTransferAuthority,
|
|
1156
|
-
unwrappedMint: inputUnwrappedMint,
|
|
1157
|
-
wrappedTokenProgram: inputWrappedTokenProgram,
|
|
1158
|
-
unwrappedTokenProgram: inputUnwrappedTokenProgram
|
|
1159
|
-
}) {
|
|
1160
|
-
const {
|
|
1161
|
-
wrappedMint,
|
|
1162
|
-
wrappedMintAuthority,
|
|
1163
|
-
transferAuthority,
|
|
1164
|
-
unwrappedTokenProgram,
|
|
1165
|
-
unwrappedMint,
|
|
1166
|
-
wrappedTokenProgram
|
|
1167
|
-
} = await resolveUnwrapAddrs({
|
|
1168
|
-
rpc,
|
|
1169
|
-
payer,
|
|
1170
|
-
wrappedTokenAccount,
|
|
1171
|
-
recipientUnwrappedToken,
|
|
1172
|
-
inputUnwrappedMint,
|
|
1173
|
-
inputTransferAuthority,
|
|
1174
|
-
inputWrappedTokenProgram,
|
|
1175
|
-
inputUnwrappedTokenProgram
|
|
1176
|
-
});
|
|
1177
|
-
const ix = await buildUnwrapTransaction({
|
|
1178
|
-
recipientUnwrappedToken,
|
|
1179
|
-
wrappedMintAuthority,
|
|
1180
|
-
unwrappedMint,
|
|
1181
|
-
wrappedTokenProgram,
|
|
1182
|
-
unwrappedTokenProgram,
|
|
1183
|
-
wrappedTokenAccount,
|
|
1184
|
-
wrappedMint,
|
|
1185
|
-
transferAuthority,
|
|
1186
|
-
amount
|
|
1187
|
-
});
|
|
1188
|
-
return {
|
|
1189
|
-
recipientUnwrappedToken,
|
|
1190
|
-
amount: BigInt(amount),
|
|
1191
|
-
ixs: [ix]
|
|
1192
|
-
};
|
|
1193
|
-
}
|
|
1194
|
-
async function multisigOfflineSignUnwrap(args) {
|
|
1195
|
-
const unwrapIx = await buildUnwrapTransaction(args);
|
|
1196
|
-
return pipe(
|
|
1197
|
-
createTransactionMessage({ version: 0 }),
|
|
1198
|
-
(tx) => setTransactionMessageFeePayerSigner(args.payer, tx),
|
|
1199
|
-
(tx) => setTransactionMessageLifetimeUsingBlockhash(args.blockhash, tx),
|
|
1200
|
-
(tx) => appendTransactionMessageInstructions([unwrapIx], tx)
|
|
1201
|
-
);
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
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 };
|
|
1205
|
-
//# sourceMappingURL=index.mjs.map
|
|
1206
|
-
//# sourceMappingURL=index.mjs.map
|