@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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getProgramDerivedAddress, getUtf8Encoder, getAddressEncoder, getStructEncoder, getStructDecoder, getAddressDecoder, combineCodec, decodeAccount, assertAccountExists, fetchEncodedAccount, assertAccountsExist, fetchEncodedAccounts, containsBytes, getU8Encoder, isProgramError, transformEncoder,
|
|
1
|
+
import { getProgramDerivedAddress, getUtf8Encoder, getAddressEncoder, getStructEncoder, getStructDecoder, getAddressDecoder, combineCodec, decodeAccount, assertAccountExists, fetchEncodedAccount, assertAccountsExist, fetchEncodedAccounts, containsBytes, getU8Encoder, isProgramError, transformEncoder, getU8Decoder, getBooleanEncoder, getBooleanDecoder, getU64Encoder, getU64Decoder, AccountRole, assertTransactionIsFullySigned, pipe, createTransactionMessage, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstructions, upgradeRoleToSigner, isTransactionSigner as isTransactionSigner$1 } from '@solana/kit';
|
|
2
2
|
import { getMintSize, findAssociatedTokenPda, fetchMaybeToken, getCreateAssociatedTokenInstruction, getTokenDecoder } from '@solana-program/token-2022';
|
|
3
3
|
import { getTransferSolInstruction } from '@solana-program/system';
|
|
4
4
|
import '@solana-program/token';
|
|
@@ -98,6 +98,7 @@ var TokenWrapInstruction = /* @__PURE__ */ ((TokenWrapInstruction2) => {
|
|
|
98
98
|
TokenWrapInstruction2[TokenWrapInstruction2["CreateMint"] = 0] = "CreateMint";
|
|
99
99
|
TokenWrapInstruction2[TokenWrapInstruction2["Wrap"] = 1] = "Wrap";
|
|
100
100
|
TokenWrapInstruction2[TokenWrapInstruction2["Unwrap"] = 2] = "Unwrap";
|
|
101
|
+
TokenWrapInstruction2[TokenWrapInstruction2["CloseStuckEscrow"] = 3] = "CloseStuckEscrow";
|
|
101
102
|
return TokenWrapInstruction2;
|
|
102
103
|
})(TokenWrapInstruction || {});
|
|
103
104
|
function identifyTokenWrapInstruction(instruction) {
|
|
@@ -111,6 +112,9 @@ function identifyTokenWrapInstruction(instruction) {
|
|
|
111
112
|
if (containsBytes(data, getU8Encoder().encode(2), 0)) {
|
|
112
113
|
return 2 /* Unwrap */;
|
|
113
114
|
}
|
|
115
|
+
if (containsBytes(data, getU8Encoder().encode(3), 0)) {
|
|
116
|
+
return 3 /* CloseStuckEscrow */;
|
|
117
|
+
}
|
|
114
118
|
throw new Error(
|
|
115
119
|
"The provided instruction could not be identified as a tokenWrap instruction."
|
|
116
120
|
);
|
|
@@ -125,10 +129,12 @@ var TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH = 4;
|
|
|
125
129
|
var TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER = 5;
|
|
126
130
|
var TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER = 6;
|
|
127
131
|
var TOKEN_WRAP_ERROR__ESCROW_MISMATCH = 7;
|
|
132
|
+
var TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE = 8;
|
|
128
133
|
var tokenWrapErrorMessages;
|
|
129
134
|
if (process.env.NODE_ENV !== "production") {
|
|
130
135
|
tokenWrapErrorMessages = {
|
|
131
136
|
[TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH]: `Wrapped backpointer account address does not match expected PDA`,
|
|
137
|
+
[TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE]: `The escrow account is in a good state and cannot be recreated`,
|
|
132
138
|
[TOKEN_WRAP_ERROR__ESCROW_MISMATCH]: `Escrow account address does not match expected ATA`,
|
|
133
139
|
[TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH]: `Unwrapped escrow token owner is not set to expected PDA`,
|
|
134
140
|
[TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER]: `Wrapped backpointer account owner is not the expected token wrap program`,
|
|
@@ -184,7 +190,88 @@ function isTransactionSigner(value) {
|
|
|
184
190
|
return !!value && typeof value === "object" && "address" in value && isTransactionSigner$1(value);
|
|
185
191
|
}
|
|
186
192
|
|
|
187
|
-
// src/generated/instructions/
|
|
193
|
+
// src/generated/instructions/closeStuckEscrow.ts
|
|
194
|
+
var CLOSE_STUCK_ESCROW_DISCRIMINATOR = 3;
|
|
195
|
+
function getCloseStuckEscrowDiscriminatorBytes() {
|
|
196
|
+
return getU8Encoder().encode(CLOSE_STUCK_ESCROW_DISCRIMINATOR);
|
|
197
|
+
}
|
|
198
|
+
function getCloseStuckEscrowInstructionDataEncoder() {
|
|
199
|
+
return transformEncoder(
|
|
200
|
+
getStructEncoder([["discriminator", getU8Encoder()]]),
|
|
201
|
+
(value) => ({ ...value, discriminator: CLOSE_STUCK_ESCROW_DISCRIMINATOR })
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
function getCloseStuckEscrowInstructionDataDecoder() {
|
|
205
|
+
return getStructDecoder([["discriminator", getU8Decoder()]]);
|
|
206
|
+
}
|
|
207
|
+
function getCloseStuckEscrowInstructionDataCodec() {
|
|
208
|
+
return combineCodec(
|
|
209
|
+
getCloseStuckEscrowInstructionDataEncoder(),
|
|
210
|
+
getCloseStuckEscrowInstructionDataDecoder()
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
function getCloseStuckEscrowInstruction(input, config) {
|
|
214
|
+
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
215
|
+
const originalAccounts = {
|
|
216
|
+
escrow: { value: input.escrow ?? null, isWritable: true },
|
|
217
|
+
destination: { value: input.destination ?? null, isWritable: true },
|
|
218
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
219
|
+
wrappedMint: { value: input.wrappedMint ?? null, isWritable: false },
|
|
220
|
+
wrappedMintAuthority: {
|
|
221
|
+
value: input.wrappedMintAuthority ?? null,
|
|
222
|
+
isWritable: false
|
|
223
|
+
},
|
|
224
|
+
token2022Program: {
|
|
225
|
+
value: input.token2022Program ?? null,
|
|
226
|
+
isWritable: false
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const accounts = originalAccounts;
|
|
230
|
+
if (!accounts.token2022Program.value) {
|
|
231
|
+
accounts.token2022Program.value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
232
|
+
}
|
|
233
|
+
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
234
|
+
const instruction = {
|
|
235
|
+
accounts: [
|
|
236
|
+
getAccountMeta(accounts.escrow),
|
|
237
|
+
getAccountMeta(accounts.destination),
|
|
238
|
+
getAccountMeta(accounts.unwrappedMint),
|
|
239
|
+
getAccountMeta(accounts.wrappedMint),
|
|
240
|
+
getAccountMeta(accounts.wrappedMintAuthority),
|
|
241
|
+
getAccountMeta(accounts.token2022Program)
|
|
242
|
+
],
|
|
243
|
+
programAddress,
|
|
244
|
+
data: getCloseStuckEscrowInstructionDataEncoder().encode({})
|
|
245
|
+
};
|
|
246
|
+
return instruction;
|
|
247
|
+
}
|
|
248
|
+
function parseCloseStuckEscrowInstruction(instruction) {
|
|
249
|
+
if (instruction.accounts.length < 6) {
|
|
250
|
+
throw new Error("Not enough accounts");
|
|
251
|
+
}
|
|
252
|
+
let accountIndex = 0;
|
|
253
|
+
const getNextAccount = () => {
|
|
254
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
255
|
+
accountIndex += 1;
|
|
256
|
+
return accountMeta;
|
|
257
|
+
};
|
|
258
|
+
const getNextOptionalAccount = () => {
|
|
259
|
+
const accountMeta = getNextAccount();
|
|
260
|
+
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
261
|
+
};
|
|
262
|
+
return {
|
|
263
|
+
programAddress: instruction.programAddress,
|
|
264
|
+
accounts: {
|
|
265
|
+
escrow: getNextAccount(),
|
|
266
|
+
destination: getNextAccount(),
|
|
267
|
+
unwrappedMint: getNextAccount(),
|
|
268
|
+
wrappedMint: getNextAccount(),
|
|
269
|
+
wrappedMintAuthority: getNextAccount(),
|
|
270
|
+
token2022Program: getNextOptionalAccount()
|
|
271
|
+
},
|
|
272
|
+
data: getCloseStuckEscrowInstructionDataDecoder().decode(instruction.data)
|
|
273
|
+
};
|
|
274
|
+
}
|
|
188
275
|
var CREATE_MINT_DISCRIMINATOR = 0;
|
|
189
276
|
function getCreateMintDiscriminatorBytes() {
|
|
190
277
|
return getU8Encoder().encode(CREATE_MINT_DISCRIMINATOR);
|
|
@@ -893,6 +980,6 @@ async function multisigOfflineSignUnwrap(args) {
|
|
|
893
980
|
);
|
|
894
981
|
}
|
|
895
982
|
|
|
896
|
-
export { CREATE_MINT_DISCRIMINATOR, TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH, TOKEN_WRAP_ERROR__ESCROW_MISMATCH, TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH, TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER, TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER, TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH, TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH, TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT, TOKEN_WRAP_PROGRAM_ADDRESS, TokenWrapAccount, TokenWrapInstruction, UNWRAP_DISCRIMINATOR, WRAP_DISCRIMINATOR, combinedMultisigTx, createEscrowAccount, createMint, decodeBackpointer, fetchAllBackpointer, fetchAllMaybeBackpointer, fetchBackpointer, fetchBackpointerFromSeeds, fetchMaybeBackpointer, fetchMaybeBackpointerFromSeeds, findBackpointerPda, findWrappedMintAuthorityPda, findWrappedMintPda, getBackpointerCodec, getBackpointerDecoder, getBackpointerEncoder, getBackpointerSize, getCreateMintDiscriminatorBytes, getCreateMintInstruction, getCreateMintInstructionDataCodec, getCreateMintInstructionDataDecoder, getCreateMintInstructionDataEncoder, getTokenWrapErrorMessage, getUnwrapDiscriminatorBytes, getUnwrapInstruction, getUnwrapInstructionDataCodec, getUnwrapInstructionDataDecoder, getUnwrapInstructionDataEncoder, getWrapDiscriminatorBytes, getWrapInstruction, getWrapInstructionDataCodec, getWrapInstructionDataDecoder, getWrapInstructionDataEncoder, identifyTokenWrapInstruction, isTokenWrapError, multisigOfflineSignUnwrap, multisigOfflineSignWrap, parseCreateMintInstruction, parseUnwrapInstruction, parseWrapInstruction, singleSignerUnwrap, singleSignerWrap };
|
|
983
|
+
export { CLOSE_STUCK_ESCROW_DISCRIMINATOR, CREATE_MINT_DISCRIMINATOR, TOKEN_WRAP_ERROR__BACKPOINTER_MISMATCH, TOKEN_WRAP_ERROR__ESCROW_IN_GOOD_STATE, TOKEN_WRAP_ERROR__ESCROW_MISMATCH, TOKEN_WRAP_ERROR__ESCROW_OWNER_MISMATCH, TOKEN_WRAP_ERROR__INVALID_BACKPOINTER_OWNER, TOKEN_WRAP_ERROR__INVALID_WRAPPED_MINT_OWNER, TOKEN_WRAP_ERROR__MINT_AUTHORITY_MISMATCH, TOKEN_WRAP_ERROR__WRAPPED_MINT_MISMATCH, TOKEN_WRAP_ERROR__ZERO_WRAP_AMOUNT, TOKEN_WRAP_PROGRAM_ADDRESS, TokenWrapAccount, TokenWrapInstruction, UNWRAP_DISCRIMINATOR, WRAP_DISCRIMINATOR, combinedMultisigTx, createEscrowAccount, createMint, decodeBackpointer, fetchAllBackpointer, fetchAllMaybeBackpointer, fetchBackpointer, fetchBackpointerFromSeeds, fetchMaybeBackpointer, fetchMaybeBackpointerFromSeeds, findBackpointerPda, findWrappedMintAuthorityPda, findWrappedMintPda, getBackpointerCodec, getBackpointerDecoder, getBackpointerEncoder, getBackpointerSize, getCloseStuckEscrowDiscriminatorBytes, getCloseStuckEscrowInstruction, getCloseStuckEscrowInstructionDataCodec, getCloseStuckEscrowInstructionDataDecoder, getCloseStuckEscrowInstructionDataEncoder, getCreateMintDiscriminatorBytes, getCreateMintInstruction, getCreateMintInstructionDataCodec, getCreateMintInstructionDataDecoder, getCreateMintInstructionDataEncoder, getTokenWrapErrorMessage, getUnwrapDiscriminatorBytes, getUnwrapInstruction, getUnwrapInstructionDataCodec, getUnwrapInstructionDataDecoder, getUnwrapInstructionDataEncoder, getWrapDiscriminatorBytes, getWrapInstruction, getWrapInstructionDataCodec, getWrapInstructionDataDecoder, getWrapInstructionDataEncoder, identifyTokenWrapInstruction, isTokenWrapError, multisigOfflineSignUnwrap, multisigOfflineSignWrap, parseCloseStuckEscrowInstruction, parseCreateMintInstruction, parseUnwrapInstruction, parseWrapInstruction, singleSignerUnwrap, singleSignerWrap };
|
|
897
984
|
//# sourceMappingURL=index.mjs.map
|
|
898
985
|
//# sourceMappingURL=index.mjs.map
|