@solana-program/token-wrap 2.4.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.
Files changed (56) hide show
  1. package/package.json +18 -15
  2. package/src/create-mint.ts +125 -0
  3. package/src/examples/multisig.ts +295 -0
  4. package/src/examples/single-signer.ts +175 -0
  5. package/src/examples/sync-spl-to-token2022.ts +96 -0
  6. package/src/examples/sync-token2022-to-spl.ts +101 -0
  7. package/src/generated/accounts/backpointer.ts +125 -0
  8. package/{dist/types/src/generated/accounts/index.d.ts → src/generated/accounts/index.ts} +1 -0
  9. package/{dist/types/src/generated/errors/index.d.ts → src/generated/errors/index.ts} +1 -0
  10. package/src/generated/errors/tokenWrap.ts +89 -0
  11. package/{dist/types/src/generated/index.d.ts → src/generated/index.ts} +1 -0
  12. package/src/generated/instructions/closeStuckEscrow.ts +235 -0
  13. package/src/generated/instructions/createMint.ts +250 -0
  14. package/{dist/types/src/generated/instructions/index.d.ts → src/generated/instructions/index.ts} +1 -0
  15. package/src/generated/instructions/syncMetadataToSplToken.ts +305 -0
  16. package/src/generated/instructions/syncMetadataToToken2022.ts +253 -0
  17. package/src/generated/instructions/unwrap.ts +326 -0
  18. package/src/generated/instructions/wrap.ts +326 -0
  19. package/src/generated/pdas/backpointer.ts +32 -0
  20. package/{dist/types/src/generated/pdas/index.d.ts → src/generated/pdas/index.ts} +1 -0
  21. package/src/generated/pdas/wrappedMint.ts +37 -0
  22. package/src/generated/pdas/wrappedMintAuthority.ts +32 -0
  23. package/{dist/types/src/generated/programs/index.d.ts → src/generated/programs/index.ts} +1 -0
  24. package/src/generated/programs/tokenWrap.ts +228 -0
  25. package/src/global.d.ts +8 -0
  26. package/src/index.ts +23 -0
  27. package/src/unwrap.ts +208 -0
  28. package/src/utilities.ts +234 -0
  29. package/src/wrap.ts +211 -0
  30. package/dist/src/index.js +0 -1222
  31. package/dist/src/index.js.map +0 -1
  32. package/dist/src/index.mjs +0 -1135
  33. package/dist/src/index.mjs.map +0 -1
  34. package/dist/types/src/create-mint.d.ts +0 -16
  35. package/dist/types/src/examples/multisig.d.ts +0 -1
  36. package/dist/types/src/examples/single-signer.d.ts +0 -1
  37. package/dist/types/src/examples/sync-spl-to-token2022.d.ts +0 -1
  38. package/dist/types/src/examples/sync-token2022-to-spl.d.ts +0 -1
  39. package/dist/types/src/generated/accounts/backpointer.d.ts +0 -33
  40. package/dist/types/src/generated/errors/tokenWrap.d.ts +0 -35
  41. package/dist/types/src/generated/instructions/closeStuckEscrow.d.ts +0 -63
  42. package/dist/types/src/generated/instructions/createMint.d.ts +0 -76
  43. package/dist/types/src/generated/instructions/syncMetadataToSplToken.d.ts +0 -92
  44. package/dist/types/src/generated/instructions/syncMetadataToToken2022.d.ts +0 -75
  45. package/dist/types/src/generated/instructions/unwrap.d.ts +0 -103
  46. package/dist/types/src/generated/instructions/wrap.d.ts +0 -103
  47. package/dist/types/src/generated/pdas/backpointer.d.ts +0 -14
  48. package/dist/types/src/generated/pdas/wrappedMint.d.ts +0 -15
  49. package/dist/types/src/generated/pdas/wrappedMintAuthority.d.ts +0 -14
  50. package/dist/types/src/generated/programs/tokenWrap.d.ts +0 -38
  51. package/dist/types/src/generated/shared/index.d.ts +0 -49
  52. package/dist/types/src/index.d.ts +0 -5
  53. package/dist/types/src/unwrap.d.ts +0 -44
  54. package/dist/types/src/utilities.d.ts +0 -37
  55. package/dist/types/src/wrap.d.ts +0 -41
  56. package/dist/types/tsup.config.d.ts +0 -3
@@ -0,0 +1,326 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import {
10
+ AccountRole,
11
+ combineCodec,
12
+ getStructDecoder,
13
+ getStructEncoder,
14
+ getU64Decoder,
15
+ getU64Encoder,
16
+ getU8Decoder,
17
+ getU8Encoder,
18
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
19
+ SolanaError,
20
+ transformEncoder,
21
+ type AccountMeta,
22
+ type AccountSignerMeta,
23
+ type Address,
24
+ type FixedSizeCodec,
25
+ type FixedSizeDecoder,
26
+ type FixedSizeEncoder,
27
+ type Instruction,
28
+ type InstructionWithAccounts,
29
+ type InstructionWithData,
30
+ type ReadonlyAccount,
31
+ type ReadonlySignerAccount,
32
+ type ReadonlyUint8Array,
33
+ type TransactionSigner,
34
+ type WritableAccount,
35
+ } from '@solana/kit';
36
+ import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/program-client-core';
37
+ import { TOKEN_WRAP_PROGRAM_ADDRESS } from '../programs';
38
+
39
+ export const WRAP_DISCRIMINATOR = 1;
40
+
41
+ export function getWrapDiscriminatorBytes(): ReadonlyUint8Array {
42
+ return getU8Encoder().encode(WRAP_DISCRIMINATOR);
43
+ }
44
+
45
+ export type WrapInstruction<
46
+ TProgram extends string = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
47
+ TAccountRecipientWrappedTokenAccount extends string | AccountMeta<string> = string,
48
+ TAccountWrappedMint extends string | AccountMeta<string> = string,
49
+ TAccountWrappedMintAuthority extends string | AccountMeta<string> = string,
50
+ TAccountUnwrappedTokenProgram extends string | AccountMeta<string> = string,
51
+ TAccountWrappedTokenProgram extends string | AccountMeta<string> = string,
52
+ TAccountUnwrappedTokenAccount extends string | AccountMeta<string> = string,
53
+ TAccountUnwrappedMint extends string | AccountMeta<string> = string,
54
+ TAccountUnwrappedEscrow extends string | AccountMeta<string> = string,
55
+ TAccountTransferAuthority extends string | AccountMeta<string> = string,
56
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
57
+ > = Instruction<TProgram> &
58
+ InstructionWithData<ReadonlyUint8Array> &
59
+ InstructionWithAccounts<
60
+ [
61
+ TAccountRecipientWrappedTokenAccount extends string
62
+ ? WritableAccount<TAccountRecipientWrappedTokenAccount>
63
+ : TAccountRecipientWrappedTokenAccount,
64
+ TAccountWrappedMint extends string ? WritableAccount<TAccountWrappedMint> : TAccountWrappedMint,
65
+ TAccountWrappedMintAuthority extends string
66
+ ? ReadonlyAccount<TAccountWrappedMintAuthority>
67
+ : TAccountWrappedMintAuthority,
68
+ TAccountUnwrappedTokenProgram extends string
69
+ ? ReadonlyAccount<TAccountUnwrappedTokenProgram>
70
+ : TAccountUnwrappedTokenProgram,
71
+ TAccountWrappedTokenProgram extends string
72
+ ? ReadonlyAccount<TAccountWrappedTokenProgram>
73
+ : TAccountWrappedTokenProgram,
74
+ TAccountUnwrappedTokenAccount extends string
75
+ ? WritableAccount<TAccountUnwrappedTokenAccount>
76
+ : TAccountUnwrappedTokenAccount,
77
+ TAccountUnwrappedMint extends string ? ReadonlyAccount<TAccountUnwrappedMint> : TAccountUnwrappedMint,
78
+ TAccountUnwrappedEscrow extends string ? WritableAccount<TAccountUnwrappedEscrow> : TAccountUnwrappedEscrow,
79
+ TAccountTransferAuthority extends string
80
+ ? ReadonlyAccount<TAccountTransferAuthority>
81
+ : TAccountTransferAuthority,
82
+ ...TRemainingAccounts,
83
+ ]
84
+ >;
85
+
86
+ export type WrapInstructionData = {
87
+ discriminator: number;
88
+ /** The amount of tokens to wrap. */
89
+ amount: bigint;
90
+ };
91
+
92
+ export type WrapInstructionDataArgs = {
93
+ /** The amount of tokens to wrap. */
94
+ amount: number | bigint;
95
+ };
96
+
97
+ export function getWrapInstructionDataEncoder(): FixedSizeEncoder<WrapInstructionDataArgs> {
98
+ return transformEncoder(
99
+ getStructEncoder([
100
+ ['discriminator', getU8Encoder()],
101
+ ['amount', getU64Encoder()],
102
+ ]),
103
+ value => ({ ...value, discriminator: WRAP_DISCRIMINATOR }),
104
+ );
105
+ }
106
+
107
+ export function getWrapInstructionDataDecoder(): FixedSizeDecoder<WrapInstructionData> {
108
+ return getStructDecoder([
109
+ ['discriminator', getU8Decoder()],
110
+ ['amount', getU64Decoder()],
111
+ ]);
112
+ }
113
+
114
+ export function getWrapInstructionDataCodec(): FixedSizeCodec<WrapInstructionDataArgs, WrapInstructionData> {
115
+ return combineCodec(getWrapInstructionDataEncoder(), getWrapInstructionDataDecoder());
116
+ }
117
+
118
+ export type WrapInput<
119
+ TAccountRecipientWrappedTokenAccount extends string = string,
120
+ TAccountWrappedMint extends string = string,
121
+ TAccountWrappedMintAuthority extends string = string,
122
+ TAccountUnwrappedTokenProgram extends string = string,
123
+ TAccountWrappedTokenProgram extends string = string,
124
+ TAccountUnwrappedTokenAccount extends string = string,
125
+ TAccountUnwrappedMint extends string = string,
126
+ TAccountUnwrappedEscrow extends string = string,
127
+ TAccountTransferAuthority extends string = string,
128
+ > = {
129
+ /** The token account to receive the wrapped tokens. */
130
+ recipientWrappedTokenAccount: Address<TAccountRecipientWrappedTokenAccount>;
131
+ /**
132
+ * Wrapped mint, must be initialized, address must be:
133
+ * `get_wrapped_mint_address(unwrapped_mint_address, wrapped_token_program_id)`
134
+ */
135
+ wrappedMint: Address<TAccountWrappedMint>;
136
+ /**
137
+ * The PDA authority of the wrapped mint, address must be
138
+ * `get_wrapped_mint_authority(wrapped_mint)`
139
+ */
140
+ wrappedMintAuthority: Address<TAccountWrappedMintAuthority>;
141
+ /** The token program of the unwrapped tokens. */
142
+ unwrappedTokenProgram: Address<TAccountUnwrappedTokenProgram>;
143
+ /** The token program of the wrapped tokens. */
144
+ wrappedTokenProgram: Address<TAccountWrappedTokenProgram>;
145
+ /** The source token account for the unwrapped tokens. */
146
+ unwrappedTokenAccount: Address<TAccountUnwrappedTokenAccount>;
147
+ /** The mint of the unwrapped tokens. */
148
+ unwrappedMint: Address<TAccountUnwrappedMint>;
149
+ /**
150
+ * The escrow account that holds the unwrapped tokens.
151
+ * Address must be ATA: get_escrow_address(unwrapped_mint, unwrapped_token_program, wrapped_token_program)
152
+ */
153
+ unwrappedEscrow: Address<TAccountUnwrappedEscrow>;
154
+ /** The authority to transfer the unwrapped tokens. */
155
+ transferAuthority: Address<TAccountTransferAuthority> | TransactionSigner<TAccountTransferAuthority>;
156
+ amount: WrapInstructionDataArgs['amount'];
157
+ multiSigners?: Array<TransactionSigner>;
158
+ };
159
+
160
+ export function getWrapInstruction<
161
+ TAccountRecipientWrappedTokenAccount extends string,
162
+ TAccountWrappedMint extends string,
163
+ TAccountWrappedMintAuthority extends string,
164
+ TAccountUnwrappedTokenProgram extends string,
165
+ TAccountWrappedTokenProgram extends string,
166
+ TAccountUnwrappedTokenAccount extends string,
167
+ TAccountUnwrappedMint extends string,
168
+ TAccountUnwrappedEscrow extends string,
169
+ TAccountTransferAuthority extends string,
170
+ TProgramAddress extends Address = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
171
+ >(
172
+ input: WrapInput<
173
+ TAccountRecipientWrappedTokenAccount,
174
+ TAccountWrappedMint,
175
+ TAccountWrappedMintAuthority,
176
+ TAccountUnwrappedTokenProgram,
177
+ TAccountWrappedTokenProgram,
178
+ TAccountUnwrappedTokenAccount,
179
+ TAccountUnwrappedMint,
180
+ TAccountUnwrappedEscrow,
181
+ TAccountTransferAuthority
182
+ >,
183
+ config?: { programAddress?: TProgramAddress },
184
+ ): WrapInstruction<
185
+ TProgramAddress,
186
+ TAccountRecipientWrappedTokenAccount,
187
+ TAccountWrappedMint,
188
+ TAccountWrappedMintAuthority,
189
+ TAccountUnwrappedTokenProgram,
190
+ TAccountWrappedTokenProgram,
191
+ TAccountUnwrappedTokenAccount,
192
+ TAccountUnwrappedMint,
193
+ TAccountUnwrappedEscrow,
194
+ (typeof input)['transferAuthority'] extends TransactionSigner<TAccountTransferAuthority>
195
+ ? ReadonlySignerAccount<TAccountTransferAuthority> & AccountSignerMeta<TAccountTransferAuthority>
196
+ : TAccountTransferAuthority
197
+ > {
198
+ // Program address.
199
+ const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
200
+
201
+ // Original accounts.
202
+ const originalAccounts = {
203
+ recipientWrappedTokenAccount: { value: input.recipientWrappedTokenAccount ?? null, isWritable: true },
204
+ wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
205
+ wrappedMintAuthority: { value: input.wrappedMintAuthority ?? null, isWritable: false },
206
+ unwrappedTokenProgram: { value: input.unwrappedTokenProgram ?? null, isWritable: false },
207
+ wrappedTokenProgram: { value: input.wrappedTokenProgram ?? null, isWritable: false },
208
+ unwrappedTokenAccount: { value: input.unwrappedTokenAccount ?? null, isWritable: true },
209
+ unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
210
+ unwrappedEscrow: { value: input.unwrappedEscrow ?? null, isWritable: true },
211
+ transferAuthority: { value: input.transferAuthority ?? null, isWritable: false },
212
+ };
213
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
214
+
215
+ // Original args.
216
+ const args = { ...input };
217
+
218
+ // Remaining accounts.
219
+ const remainingAccounts: AccountMeta[] = (args.multiSigners ?? []).map(signer => ({
220
+ address: signer.address,
221
+ role: AccountRole.READONLY_SIGNER,
222
+ signer,
223
+ }));
224
+
225
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
226
+ return Object.freeze({
227
+ accounts: [
228
+ getAccountMeta('recipientWrappedTokenAccount', accounts.recipientWrappedTokenAccount),
229
+ getAccountMeta('wrappedMint', accounts.wrappedMint),
230
+ getAccountMeta('wrappedMintAuthority', accounts.wrappedMintAuthority),
231
+ getAccountMeta('unwrappedTokenProgram', accounts.unwrappedTokenProgram),
232
+ getAccountMeta('wrappedTokenProgram', accounts.wrappedTokenProgram),
233
+ getAccountMeta('unwrappedTokenAccount', accounts.unwrappedTokenAccount),
234
+ getAccountMeta('unwrappedMint', accounts.unwrappedMint),
235
+ getAccountMeta('unwrappedEscrow', accounts.unwrappedEscrow),
236
+ getAccountMeta('transferAuthority', accounts.transferAuthority),
237
+ ...remainingAccounts,
238
+ ],
239
+ data: getWrapInstructionDataEncoder().encode(args as WrapInstructionDataArgs),
240
+ programAddress,
241
+ } as WrapInstruction<
242
+ TProgramAddress,
243
+ TAccountRecipientWrappedTokenAccount,
244
+ TAccountWrappedMint,
245
+ TAccountWrappedMintAuthority,
246
+ TAccountUnwrappedTokenProgram,
247
+ TAccountWrappedTokenProgram,
248
+ TAccountUnwrappedTokenAccount,
249
+ TAccountUnwrappedMint,
250
+ TAccountUnwrappedEscrow,
251
+ (typeof input)['transferAuthority'] extends TransactionSigner<TAccountTransferAuthority>
252
+ ? ReadonlySignerAccount<TAccountTransferAuthority> & AccountSignerMeta<TAccountTransferAuthority>
253
+ : TAccountTransferAuthority
254
+ >);
255
+ }
256
+
257
+ export type ParsedWrapInstruction<
258
+ TProgram extends string = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
259
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
260
+ > = {
261
+ programAddress: Address<TProgram>;
262
+ accounts: {
263
+ /** The token account to receive the wrapped tokens. */
264
+ recipientWrappedTokenAccount: TAccountMetas[0];
265
+ /**
266
+ * Wrapped mint, must be initialized, address must be:
267
+ * `get_wrapped_mint_address(unwrapped_mint_address, wrapped_token_program_id)`
268
+ */
269
+ wrappedMint: TAccountMetas[1];
270
+ /**
271
+ * The PDA authority of the wrapped mint, address must be
272
+ * `get_wrapped_mint_authority(wrapped_mint)`
273
+ */
274
+ wrappedMintAuthority: TAccountMetas[2];
275
+ /** The token program of the unwrapped tokens. */
276
+ unwrappedTokenProgram: TAccountMetas[3];
277
+ /** The token program of the wrapped tokens. */
278
+ wrappedTokenProgram: TAccountMetas[4];
279
+ /** The source token account for the unwrapped tokens. */
280
+ unwrappedTokenAccount: TAccountMetas[5];
281
+ /** The mint of the unwrapped tokens. */
282
+ unwrappedMint: TAccountMetas[6];
283
+ /**
284
+ * The escrow account that holds the unwrapped tokens.
285
+ * Address must be ATA: get_escrow_address(unwrapped_mint, unwrapped_token_program, wrapped_token_program)
286
+ */
287
+ unwrappedEscrow: TAccountMetas[7];
288
+ /** The authority to transfer the unwrapped tokens. */
289
+ transferAuthority: TAccountMetas[8];
290
+ };
291
+ data: WrapInstructionData;
292
+ };
293
+
294
+ export function parseWrapInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(
295
+ instruction: Instruction<TProgram> &
296
+ InstructionWithAccounts<TAccountMetas> &
297
+ InstructionWithData<ReadonlyUint8Array>,
298
+ ): ParsedWrapInstruction<TProgram, TAccountMetas> {
299
+ if (instruction.accounts.length < 9) {
300
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
301
+ actualAccountMetas: instruction.accounts.length,
302
+ expectedAccountMetas: 9,
303
+ });
304
+ }
305
+ let accountIndex = 0;
306
+ const getNextAccount = () => {
307
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
308
+ accountIndex += 1;
309
+ return accountMeta;
310
+ };
311
+ return {
312
+ programAddress: instruction.programAddress,
313
+ accounts: {
314
+ recipientWrappedTokenAccount: getNextAccount(),
315
+ wrappedMint: getNextAccount(),
316
+ wrappedMintAuthority: getNextAccount(),
317
+ unwrappedTokenProgram: getNextAccount(),
318
+ wrappedTokenProgram: getNextAccount(),
319
+ unwrappedTokenAccount: getNextAccount(),
320
+ unwrappedMint: getNextAccount(),
321
+ unwrappedEscrow: getNextAccount(),
322
+ transferAuthority: getNextAccount(),
323
+ },
324
+ data: getWrapInstructionDataDecoder().decode(instruction.data),
325
+ };
326
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import {
10
+ getAddressEncoder,
11
+ getProgramDerivedAddress,
12
+ getUtf8Encoder,
13
+ type Address,
14
+ type ProgramDerivedAddress,
15
+ } from '@solana/kit';
16
+
17
+ export type BackpointerSeeds = {
18
+ wrappedMint: Address;
19
+ };
20
+
21
+ export async function findBackpointerPda(
22
+ seeds: BackpointerSeeds,
23
+ config: { programAddress?: Address | undefined } = {},
24
+ ): Promise<ProgramDerivedAddress> {
25
+ const {
26
+ programAddress = 'TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR' as Address<'TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR'>,
27
+ } = config;
28
+ return await getProgramDerivedAddress({
29
+ programAddress,
30
+ seeds: [getUtf8Encoder().encode('backpointer'), getAddressEncoder().encode(seeds.wrappedMint)],
31
+ });
32
+ }
@@ -5,6 +5,7 @@
5
5
  *
6
6
  * @see https://github.com/codama-idl/codama
7
7
  */
8
+
8
9
  export * from './backpointer';
9
10
  export * from './wrappedMint';
10
11
  export * from './wrappedMintAuthority';
@@ -0,0 +1,37 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import {
10
+ getAddressEncoder,
11
+ getProgramDerivedAddress,
12
+ getUtf8Encoder,
13
+ type Address,
14
+ type ProgramDerivedAddress,
15
+ } from '@solana/kit';
16
+
17
+ export type WrappedMintSeeds = {
18
+ unwrappedMint: Address;
19
+ wrappedTokenProgram: Address;
20
+ };
21
+
22
+ export async function findWrappedMintPda(
23
+ seeds: WrappedMintSeeds,
24
+ config: { programAddress?: Address | undefined } = {},
25
+ ): Promise<ProgramDerivedAddress> {
26
+ const {
27
+ programAddress = 'TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR' as Address<'TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR'>,
28
+ } = config;
29
+ return await getProgramDerivedAddress({
30
+ programAddress,
31
+ seeds: [
32
+ getUtf8Encoder().encode('mint'),
33
+ getAddressEncoder().encode(seeds.unwrappedMint),
34
+ getAddressEncoder().encode(seeds.wrappedTokenProgram),
35
+ ],
36
+ });
37
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import {
10
+ getAddressEncoder,
11
+ getProgramDerivedAddress,
12
+ getUtf8Encoder,
13
+ type Address,
14
+ type ProgramDerivedAddress,
15
+ } from '@solana/kit';
16
+
17
+ export type WrappedMintAuthoritySeeds = {
18
+ wrappedMint: Address;
19
+ };
20
+
21
+ export async function findWrappedMintAuthorityPda(
22
+ seeds: WrappedMintAuthoritySeeds,
23
+ config: { programAddress?: Address | undefined } = {},
24
+ ): Promise<ProgramDerivedAddress> {
25
+ const {
26
+ programAddress = 'TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR' as Address<'TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR'>,
27
+ } = config;
28
+ return await getProgramDerivedAddress({
29
+ programAddress,
30
+ seeds: [getUtf8Encoder().encode('authority'), getAddressEncoder().encode(seeds.wrappedMint)],
31
+ });
32
+ }
@@ -5,4 +5,5 @@
5
5
  *
6
6
  * @see https://github.com/codama-idl/codama
7
7
  */
8
+
8
9
  export * from './tokenWrap';
@@ -0,0 +1,228 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import {
10
+ assertIsInstructionWithAccounts,
11
+ containsBytes,
12
+ extendClient,
13
+ getU8Encoder,
14
+ SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
15
+ SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
16
+ SolanaError,
17
+ type Address,
18
+ type ClientWithRpc,
19
+ type ClientWithTransactionPlanning,
20
+ type ClientWithTransactionSending,
21
+ type ExtendedClient,
22
+ type GetAccountInfoApi,
23
+ type GetMultipleAccountsApi,
24
+ type Instruction,
25
+ type InstructionWithData,
26
+ type ReadonlyUint8Array,
27
+ } from '@solana/kit';
28
+ import {
29
+ addSelfFetchFunctions,
30
+ addSelfPlanAndSendFunctions,
31
+ type SelfFetchFunctions,
32
+ type SelfPlanAndSendFunctions,
33
+ } from '@solana/program-client-core';
34
+ import { getBackpointerCodec, type Backpointer, type BackpointerArgs } from '../accounts';
35
+ import {
36
+ getCloseStuckEscrowInstruction,
37
+ getCreateMintInstruction,
38
+ getSyncMetadataToSplTokenInstruction,
39
+ getSyncMetadataToToken2022Instruction,
40
+ getUnwrapInstruction,
41
+ getWrapInstruction,
42
+ parseCloseStuckEscrowInstruction,
43
+ parseCreateMintInstruction,
44
+ parseSyncMetadataToSplTokenInstruction,
45
+ parseSyncMetadataToToken2022Instruction,
46
+ parseUnwrapInstruction,
47
+ parseWrapInstruction,
48
+ type CloseStuckEscrowInput,
49
+ type CreateMintInput,
50
+ type ParsedCloseStuckEscrowInstruction,
51
+ type ParsedCreateMintInstruction,
52
+ type ParsedSyncMetadataToSplTokenInstruction,
53
+ type ParsedSyncMetadataToToken2022Instruction,
54
+ type ParsedUnwrapInstruction,
55
+ type ParsedWrapInstruction,
56
+ type SyncMetadataToSplTokenInput,
57
+ type SyncMetadataToToken2022Input,
58
+ type UnwrapInput,
59
+ type WrapInput,
60
+ } from '../instructions';
61
+ import { findBackpointerPda, findWrappedMintAuthorityPda, findWrappedMintPda } from '../pdas';
62
+
63
+ export const TOKEN_WRAP_PROGRAM_ADDRESS =
64
+ 'TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR' as Address<'TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR'>;
65
+
66
+ export enum TokenWrapAccount {
67
+ Backpointer,
68
+ }
69
+
70
+ export enum TokenWrapInstruction {
71
+ CreateMint,
72
+ Wrap,
73
+ Unwrap,
74
+ CloseStuckEscrow,
75
+ SyncMetadataToToken2022,
76
+ SyncMetadataToSplToken,
77
+ }
78
+
79
+ export function identifyTokenWrapInstruction(
80
+ instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
81
+ ): TokenWrapInstruction {
82
+ const data = 'data' in instruction ? instruction.data : instruction;
83
+ if (containsBytes(data, getU8Encoder().encode(0), 0)) {
84
+ return TokenWrapInstruction.CreateMint;
85
+ }
86
+ if (containsBytes(data, getU8Encoder().encode(1), 0)) {
87
+ return TokenWrapInstruction.Wrap;
88
+ }
89
+ if (containsBytes(data, getU8Encoder().encode(2), 0)) {
90
+ return TokenWrapInstruction.Unwrap;
91
+ }
92
+ if (containsBytes(data, getU8Encoder().encode(3), 0)) {
93
+ return TokenWrapInstruction.CloseStuckEscrow;
94
+ }
95
+ if (containsBytes(data, getU8Encoder().encode(4), 0)) {
96
+ return TokenWrapInstruction.SyncMetadataToToken2022;
97
+ }
98
+ if (containsBytes(data, getU8Encoder().encode(5), 0)) {
99
+ return TokenWrapInstruction.SyncMetadataToSplToken;
100
+ }
101
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, {
102
+ instructionData: data,
103
+ programName: 'tokenWrap',
104
+ });
105
+ }
106
+
107
+ export type ParsedTokenWrapInstruction<TProgram extends string = 'TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR'> =
108
+ | ({ instructionType: TokenWrapInstruction.CreateMint } & ParsedCreateMintInstruction<TProgram>)
109
+ | ({ instructionType: TokenWrapInstruction.Wrap } & ParsedWrapInstruction<TProgram>)
110
+ | ({ instructionType: TokenWrapInstruction.Unwrap } & ParsedUnwrapInstruction<TProgram>)
111
+ | ({ instructionType: TokenWrapInstruction.CloseStuckEscrow } & ParsedCloseStuckEscrowInstruction<TProgram>)
112
+ | ({
113
+ instructionType: TokenWrapInstruction.SyncMetadataToToken2022;
114
+ } & ParsedSyncMetadataToToken2022Instruction<TProgram>)
115
+ | ({
116
+ instructionType: TokenWrapInstruction.SyncMetadataToSplToken;
117
+ } & ParsedSyncMetadataToSplTokenInstruction<TProgram>);
118
+
119
+ export function parseTokenWrapInstruction<TProgram extends string>(
120
+ instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
121
+ ): ParsedTokenWrapInstruction<TProgram> {
122
+ const instructionType = identifyTokenWrapInstruction(instruction);
123
+ switch (instructionType) {
124
+ case TokenWrapInstruction.CreateMint: {
125
+ assertIsInstructionWithAccounts(instruction);
126
+ return { instructionType: TokenWrapInstruction.CreateMint, ...parseCreateMintInstruction(instruction) };
127
+ }
128
+ case TokenWrapInstruction.Wrap: {
129
+ assertIsInstructionWithAccounts(instruction);
130
+ return { instructionType: TokenWrapInstruction.Wrap, ...parseWrapInstruction(instruction) };
131
+ }
132
+ case TokenWrapInstruction.Unwrap: {
133
+ assertIsInstructionWithAccounts(instruction);
134
+ return { instructionType: TokenWrapInstruction.Unwrap, ...parseUnwrapInstruction(instruction) };
135
+ }
136
+ case TokenWrapInstruction.CloseStuckEscrow: {
137
+ assertIsInstructionWithAccounts(instruction);
138
+ return {
139
+ instructionType: TokenWrapInstruction.CloseStuckEscrow,
140
+ ...parseCloseStuckEscrowInstruction(instruction),
141
+ };
142
+ }
143
+ case TokenWrapInstruction.SyncMetadataToToken2022: {
144
+ assertIsInstructionWithAccounts(instruction);
145
+ return {
146
+ instructionType: TokenWrapInstruction.SyncMetadataToToken2022,
147
+ ...parseSyncMetadataToToken2022Instruction(instruction),
148
+ };
149
+ }
150
+ case TokenWrapInstruction.SyncMetadataToSplToken: {
151
+ assertIsInstructionWithAccounts(instruction);
152
+ return {
153
+ instructionType: TokenWrapInstruction.SyncMetadataToSplToken,
154
+ ...parseSyncMetadataToSplTokenInstruction(instruction),
155
+ };
156
+ }
157
+ default:
158
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, {
159
+ instructionType: instructionType as string,
160
+ programName: 'tokenWrap',
161
+ });
162
+ }
163
+ }
164
+
165
+ export type TokenWrapPlugin = {
166
+ accounts: TokenWrapPluginAccounts;
167
+ instructions: TokenWrapPluginInstructions;
168
+ pdas: TokenWrapPluginPdas;
169
+ identifyInstruction: typeof identifyTokenWrapInstruction;
170
+ parseInstruction: typeof parseTokenWrapInstruction;
171
+ };
172
+
173
+ export type TokenWrapPluginAccounts = {
174
+ backpointer: ReturnType<typeof getBackpointerCodec> & SelfFetchFunctions<BackpointerArgs, Backpointer>;
175
+ };
176
+
177
+ export type TokenWrapPluginInstructions = {
178
+ createMint: (input: CreateMintInput) => ReturnType<typeof getCreateMintInstruction> & SelfPlanAndSendFunctions;
179
+ wrap: (input: WrapInput) => ReturnType<typeof getWrapInstruction> & SelfPlanAndSendFunctions;
180
+ unwrap: (input: UnwrapInput) => ReturnType<typeof getUnwrapInstruction> & SelfPlanAndSendFunctions;
181
+ closeStuckEscrow: (
182
+ input: CloseStuckEscrowInput,
183
+ ) => ReturnType<typeof getCloseStuckEscrowInstruction> & SelfPlanAndSendFunctions;
184
+ syncMetadataToToken2022: (
185
+ input: SyncMetadataToToken2022Input,
186
+ ) => ReturnType<typeof getSyncMetadataToToken2022Instruction> & SelfPlanAndSendFunctions;
187
+ syncMetadataToSplToken: (
188
+ input: SyncMetadataToSplTokenInput,
189
+ ) => ReturnType<typeof getSyncMetadataToSplTokenInstruction> & SelfPlanAndSendFunctions;
190
+ };
191
+
192
+ export type TokenWrapPluginPdas = {
193
+ backpointer: typeof findBackpointerPda;
194
+ wrappedMint: typeof findWrappedMintPda;
195
+ wrappedMintAuthority: typeof findWrappedMintAuthorityPda;
196
+ };
197
+
198
+ export type TokenWrapPluginRequirements = ClientWithRpc<GetAccountInfoApi & GetMultipleAccountsApi> &
199
+ ClientWithTransactionPlanning &
200
+ ClientWithTransactionSending;
201
+
202
+ export function tokenWrapProgram() {
203
+ return <T extends TokenWrapPluginRequirements>(client: T): ExtendedClient<T, { tokenWrap: TokenWrapPlugin }> => {
204
+ return extendClient(client, {
205
+ tokenWrap: <TokenWrapPlugin>{
206
+ accounts: { backpointer: addSelfFetchFunctions(client, getBackpointerCodec()) },
207
+ instructions: {
208
+ createMint: input => addSelfPlanAndSendFunctions(client, getCreateMintInstruction(input)),
209
+ wrap: input => addSelfPlanAndSendFunctions(client, getWrapInstruction(input)),
210
+ unwrap: input => addSelfPlanAndSendFunctions(client, getUnwrapInstruction(input)),
211
+ closeStuckEscrow: input =>
212
+ addSelfPlanAndSendFunctions(client, getCloseStuckEscrowInstruction(input)),
213
+ syncMetadataToToken2022: input =>
214
+ addSelfPlanAndSendFunctions(client, getSyncMetadataToToken2022Instruction(input)),
215
+ syncMetadataToSplToken: input =>
216
+ addSelfPlanAndSendFunctions(client, getSyncMetadataToSplTokenInstruction(input)),
217
+ },
218
+ pdas: {
219
+ backpointer: findBackpointerPda,
220
+ wrappedMint: findWrappedMintPda,
221
+ wrappedMintAuthority: findWrappedMintAuthorityPda,
222
+ },
223
+ identifyInstruction: identifyTokenWrapInstruction,
224
+ parseInstruction: parseTokenWrapInstruction,
225
+ },
226
+ });
227
+ };
228
+ }
@@ -0,0 +1,8 @@
1
+ // Done to appease issue in generated code:
2
+ // error TS4111: Property 'NODE_ENV' comes from an index signature, so it must be accessed with ['NODE_ENV'].
3
+
4
+ declare namespace NodeJS {
5
+ interface ProcessEnv {
6
+ NODE_ENV: string;
7
+ }
8
+ }