@solana-program/token-wrap 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.js +96 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +90 -3
- package/dist/src/index.mjs.map +1 -1
- package/dist/types/generated/errors/tokenWrap.d.ts +2 -1
- package/dist/types/generated/instructions/closeStuckEscrow.d.ts +63 -0
- package/dist/types/generated/instructions/index.d.ts +1 -0
- package/dist/types/generated/programs/tokenWrap.d.ts +6 -3
- package/package.json +8 -8
package/dist/src/index.js
CHANGED
|
@@ -100,6 +100,7 @@ var TokenWrapInstruction = /* @__PURE__ */ ((TokenWrapInstruction2) => {
|
|
|
100
100
|
TokenWrapInstruction2[TokenWrapInstruction2["CreateMint"] = 0] = "CreateMint";
|
|
101
101
|
TokenWrapInstruction2[TokenWrapInstruction2["Wrap"] = 1] = "Wrap";
|
|
102
102
|
TokenWrapInstruction2[TokenWrapInstruction2["Unwrap"] = 2] = "Unwrap";
|
|
103
|
+
TokenWrapInstruction2[TokenWrapInstruction2["CloseStuckEscrow"] = 3] = "CloseStuckEscrow";
|
|
103
104
|
return TokenWrapInstruction2;
|
|
104
105
|
})(TokenWrapInstruction || {});
|
|
105
106
|
function identifyTokenWrapInstruction(instruction) {
|
|
@@ -113,6 +114,9 @@ function identifyTokenWrapInstruction(instruction) {
|
|
|
113
114
|
if (kit.containsBytes(data, kit.getU8Encoder().encode(2), 0)) {
|
|
114
115
|
return 2 /* Unwrap */;
|
|
115
116
|
}
|
|
117
|
+
if (kit.containsBytes(data, kit.getU8Encoder().encode(3), 0)) {
|
|
118
|
+
return 3 /* CloseStuckEscrow */;
|
|
119
|
+
}
|
|
116
120
|
throw new Error(
|
|
117
121
|
"The provided instruction could not be identified as a tokenWrap instruction."
|
|
118
122
|
);
|
|
@@ -127,10 +131,12 @@ var TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = 4;
|
|
|
127
131
|
var TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = 5;
|
|
128
132
|
var TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = 6;
|
|
129
133
|
var TOKEN_WRAP_ERROR__ESCROW_MISMATCH = 7;
|
|
134
|
+
var TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE = 8;
|
|
130
135
|
var tokenWrapErrorMessages;
|
|
131
136
|
if (process.env.NODE_ENV !== "production") {
|
|
132
137
|
tokenWrapErrorMessages = {
|
|
133
138
|
[TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH]: `Wrapped backpointer account address does not match expected PDA`,
|
|
139
|
+
[TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE]: `The escrow account is in a good state and cannot be recreated`,
|
|
134
140
|
[TOKEN_WRAP_ERROR__ESCROW_MISMATCH]: `Escrow account address does not match expected ATA`,
|
|
135
141
|
[TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH]: `Unwrapped escrow token owner is not set to expected PDA`,
|
|
136
142
|
[TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER]: `Wrapped backpointer account owner is not the expected token wrap program`,
|
|
@@ -186,7 +192,88 @@ function isTransactionSigner(value) {
|
|
|
186
192
|
return !!value && typeof value === "object" && "address" in value && kit.isTransactionSigner(value);
|
|
187
193
|
}
|
|
188
194
|
|
|
189
|
-
// src/generated/instructions/
|
|
195
|
+
// src/generated/instructions/closeStuckEscrow.ts
|
|
196
|
+
var CLOSE_STUCK_ESCROW_DISCRIMINATOR = 3;
|
|
197
|
+
function getCloseStuckEscrowDiscriminatorBytes() {
|
|
198
|
+
return kit.getU8Encoder().encode(CLOSE_STUCK_ESCROW_DISCRIMINATOR);
|
|
199
|
+
}
|
|
200
|
+
function getCloseStuckEscrowInstructionDataEncoder() {
|
|
201
|
+
return kit.transformEncoder(
|
|
202
|
+
kit.getStructEncoder([["discriminator", kit.getU8Encoder()]]),
|
|
203
|
+
(value) => ({ ...value, discriminator: CLOSE_STUCK_ESCROW_DISCRIMINATOR })
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
function getCloseStuckEscrowInstructionDataDecoder() {
|
|
207
|
+
return kit.getStructDecoder([["discriminator", kit.getU8Decoder()]]);
|
|
208
|
+
}
|
|
209
|
+
function getCloseStuckEscrowInstructionDataCodec() {
|
|
210
|
+
return kit.combineCodec(
|
|
211
|
+
getCloseStuckEscrowInstructionDataEncoder(),
|
|
212
|
+
getCloseStuckEscrowInstructionDataDecoder()
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
function getCloseStuckEscrowInstruction(input, config) {
|
|
216
|
+
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
217
|
+
const originalAccounts = {
|
|
218
|
+
escrow: { value: input.escrow ?? null, isWritable: true },
|
|
219
|
+
destination: { value: input.destination ?? null, isWritable: true },
|
|
220
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
221
|
+
wrappedMint: { value: input.wrappedMint ?? null, isWritable: false },
|
|
222
|
+
wrappedMintAuthority: {
|
|
223
|
+
value: input.wrappedMintAuthority ?? null,
|
|
224
|
+
isWritable: false
|
|
225
|
+
},
|
|
226
|
+
token2022Program: {
|
|
227
|
+
value: input.token2022Program ?? null,
|
|
228
|
+
isWritable: false
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const accounts = originalAccounts;
|
|
232
|
+
if (!accounts.token2022Program.value) {
|
|
233
|
+
accounts.token2022Program.value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
234
|
+
}
|
|
235
|
+
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
236
|
+
const instruction = {
|
|
237
|
+
accounts: [
|
|
238
|
+
getAccountMeta(accounts.escrow),
|
|
239
|
+
getAccountMeta(accounts.destination),
|
|
240
|
+
getAccountMeta(accounts.unwrappedMint),
|
|
241
|
+
getAccountMeta(accounts.wrappedMint),
|
|
242
|
+
getAccountMeta(accounts.wrappedMintAuthority),
|
|
243
|
+
getAccountMeta(accounts.token2022Program)
|
|
244
|
+
],
|
|
245
|
+
programAddress,
|
|
246
|
+
data: getCloseStuckEscrowInstructionDataEncoder().encode({})
|
|
247
|
+
};
|
|
248
|
+
return instruction;
|
|
249
|
+
}
|
|
250
|
+
function parseCloseStuckEscrowInstruction(instruction) {
|
|
251
|
+
if (instruction.accounts.length < 6) {
|
|
252
|
+
throw new Error("Not enough accounts");
|
|
253
|
+
}
|
|
254
|
+
let accountIndex = 0;
|
|
255
|
+
const getNextAccount = () => {
|
|
256
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
257
|
+
accountIndex += 1;
|
|
258
|
+
return accountMeta;
|
|
259
|
+
};
|
|
260
|
+
const getNextOptionalAccount = () => {
|
|
261
|
+
const accountMeta = getNextAccount();
|
|
262
|
+
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
263
|
+
};
|
|
264
|
+
return {
|
|
265
|
+
programAddress: instruction.programAddress,
|
|
266
|
+
accounts: {
|
|
267
|
+
escrow: getNextAccount(),
|
|
268
|
+
destination: getNextAccount(),
|
|
269
|
+
unwrappedMint: getNextAccount(),
|
|
270
|
+
wrappedMint: getNextAccount(),
|
|
271
|
+
wrappedMintAuthority: getNextAccount(),
|
|
272
|
+
token2022Program: getNextOptionalAccount()
|
|
273
|
+
},
|
|
274
|
+
data: getCloseStuckEscrowInstructionDataDecoder().decode(instruction.data)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
190
277
|
var CREATE_MINT_DISCRIMINATOR = 0;
|
|
191
278
|
function getCreateMintDiscriminatorBytes() {
|
|
192
279
|
return kit.getU8Encoder().encode(CREATE_MINT_DISCRIMINATOR);
|
|
@@ -895,8 +982,10 @@ async function multisigOfflineSignUnwrap(args) {
|
|
|
895
982
|
);
|
|
896
983
|
}
|
|
897
984
|
|
|
985
|
+
exports.CLOSE_STUCK_ESCROW_DISCRIMINATOR = CLOSE_STUCK_ESCROW_DISCRIMINATOR;
|
|
898
986
|
exports.CREATE_MINT_DISCRIMINATOR = CREATE_MINT_DISCRIMINATOR;
|
|
899
987
|
exports.TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH = TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH;
|
|
988
|
+
exports.TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE = TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE;
|
|
900
989
|
exports.TOKEN_WRAP_ERROR__ESCROW_MISMATCH = TOKEN_WRAP_ERROR__ESCROW_MISMATCH;
|
|
901
990
|
exports.TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH;
|
|
902
991
|
exports.TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER;
|
|
@@ -926,6 +1015,11 @@ exports.getBackpointerCodec = getBackpointerCodec;
|
|
|
926
1015
|
exports.getBackpointerDecoder = getBackpointerDecoder;
|
|
927
1016
|
exports.getBackpointerEncoder = getBackpointerEncoder;
|
|
928
1017
|
exports.getBackpointerSize = getBackpointerSize;
|
|
1018
|
+
exports.getCloseStuckEscrowDiscriminatorBytes = getCloseStuckEscrowDiscriminatorBytes;
|
|
1019
|
+
exports.getCloseStuckEscrowInstruction = getCloseStuckEscrowInstruction;
|
|
1020
|
+
exports.getCloseStuckEscrowInstructionDataCodec = getCloseStuckEscrowInstructionDataCodec;
|
|
1021
|
+
exports.getCloseStuckEscrowInstructionDataDecoder = getCloseStuckEscrowInstructionDataDecoder;
|
|
1022
|
+
exports.getCloseStuckEscrowInstructionDataEncoder = getCloseStuckEscrowInstructionDataEncoder;
|
|
929
1023
|
exports.getCreateMintDiscriminatorBytes = getCreateMintDiscriminatorBytes;
|
|
930
1024
|
exports.getCreateMintInstruction = getCreateMintInstruction;
|
|
931
1025
|
exports.getCreateMintInstructionDataCodec = getCreateMintInstructionDataCodec;
|
|
@@ -946,6 +1040,7 @@ exports.identifyTokenWrapInstruction = identifyTokenWrapInstruction;
|
|
|
946
1040
|
exports.isTokenWrapError = isTokenWrapError;
|
|
947
1041
|
exports.multisigOfflineSignUnwrap = multisigOfflineSignUnwrap;
|
|
948
1042
|
exports.multisigOfflineSignWrap = multisigOfflineSignWrap;
|
|
1043
|
+
exports.parseCloseStuckEscrowInstruction = parseCloseStuckEscrowInstruction;
|
|
949
1044
|
exports.parseCreateMintInstruction = parseCreateMintInstruction;
|
|
950
1045
|
exports.parseUnwrapInstruction = parseUnwrapInstruction;
|
|
951
1046
|
exports.parseWrapInstruction = parseWrapInstruction;
|