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