@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
|
@@ -0,0 +1,253 @@
|
|
|
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
|
+
combineCodec,
|
|
11
|
+
getStructDecoder,
|
|
12
|
+
getStructEncoder,
|
|
13
|
+
getU8Decoder,
|
|
14
|
+
getU8Encoder,
|
|
15
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
16
|
+
SolanaError,
|
|
17
|
+
transformEncoder,
|
|
18
|
+
type AccountMeta,
|
|
19
|
+
type Address,
|
|
20
|
+
type FixedSizeCodec,
|
|
21
|
+
type FixedSizeDecoder,
|
|
22
|
+
type FixedSizeEncoder,
|
|
23
|
+
type Instruction,
|
|
24
|
+
type InstructionWithAccounts,
|
|
25
|
+
type InstructionWithData,
|
|
26
|
+
type ReadonlyAccount,
|
|
27
|
+
type ReadonlyUint8Array,
|
|
28
|
+
type WritableAccount,
|
|
29
|
+
} from '@solana/kit';
|
|
30
|
+
import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/program-client-core';
|
|
31
|
+
import { TOKEN_WRAP_PROGRAM_ADDRESS } from '../programs';
|
|
32
|
+
|
|
33
|
+
export const SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR = 4;
|
|
34
|
+
|
|
35
|
+
export function getSyncMetadataToToken2022DiscriminatorBytes(): ReadonlyUint8Array {
|
|
36
|
+
return getU8Encoder().encode(SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type SyncMetadataToToken2022Instruction<
|
|
40
|
+
TProgram extends string = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
41
|
+
TAccountWrappedMint extends string | AccountMeta<string> = string,
|
|
42
|
+
TAccountWrappedMintAuthority extends string | AccountMeta<string> = string,
|
|
43
|
+
TAccountUnwrappedMint extends string | AccountMeta<string> = string,
|
|
44
|
+
TAccountToken2022Program extends string | AccountMeta<string> = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
|
|
45
|
+
TAccountSourceMetadata extends string | AccountMeta<string> = string,
|
|
46
|
+
TAccountOwnerProgram extends string | AccountMeta<string> = string,
|
|
47
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
48
|
+
> = Instruction<TProgram> &
|
|
49
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
50
|
+
InstructionWithAccounts<
|
|
51
|
+
[
|
|
52
|
+
TAccountWrappedMint extends string ? WritableAccount<TAccountWrappedMint> : TAccountWrappedMint,
|
|
53
|
+
TAccountWrappedMintAuthority extends string
|
|
54
|
+
? ReadonlyAccount<TAccountWrappedMintAuthority>
|
|
55
|
+
: TAccountWrappedMintAuthority,
|
|
56
|
+
TAccountUnwrappedMint extends string ? ReadonlyAccount<TAccountUnwrappedMint> : TAccountUnwrappedMint,
|
|
57
|
+
TAccountToken2022Program extends string
|
|
58
|
+
? ReadonlyAccount<TAccountToken2022Program>
|
|
59
|
+
: TAccountToken2022Program,
|
|
60
|
+
TAccountSourceMetadata extends string ? ReadonlyAccount<TAccountSourceMetadata> : TAccountSourceMetadata,
|
|
61
|
+
TAccountOwnerProgram extends string ? ReadonlyAccount<TAccountOwnerProgram> : TAccountOwnerProgram,
|
|
62
|
+
...TRemainingAccounts,
|
|
63
|
+
]
|
|
64
|
+
>;
|
|
65
|
+
|
|
66
|
+
export type SyncMetadataToToken2022InstructionData = { discriminator: number };
|
|
67
|
+
|
|
68
|
+
export type SyncMetadataToToken2022InstructionDataArgs = {};
|
|
69
|
+
|
|
70
|
+
export function getSyncMetadataToToken2022InstructionDataEncoder(): FixedSizeEncoder<SyncMetadataToToken2022InstructionDataArgs> {
|
|
71
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()]]), value => ({
|
|
72
|
+
...value,
|
|
73
|
+
discriminator: SYNC_METADATA_TO_TOKEN2022_DISCRIMINATOR,
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getSyncMetadataToToken2022InstructionDataDecoder(): FixedSizeDecoder<SyncMetadataToToken2022InstructionData> {
|
|
78
|
+
return getStructDecoder([['discriminator', getU8Decoder()]]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function getSyncMetadataToToken2022InstructionDataCodec(): FixedSizeCodec<
|
|
82
|
+
SyncMetadataToToken2022InstructionDataArgs,
|
|
83
|
+
SyncMetadataToToken2022InstructionData
|
|
84
|
+
> {
|
|
85
|
+
return combineCodec(
|
|
86
|
+
getSyncMetadataToToken2022InstructionDataEncoder(),
|
|
87
|
+
getSyncMetadataToToken2022InstructionDataDecoder(),
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type SyncMetadataToToken2022Input<
|
|
92
|
+
TAccountWrappedMint extends string = string,
|
|
93
|
+
TAccountWrappedMintAuthority extends string = string,
|
|
94
|
+
TAccountUnwrappedMint extends string = string,
|
|
95
|
+
TAccountToken2022Program extends string = string,
|
|
96
|
+
TAccountSourceMetadata extends string = string,
|
|
97
|
+
TAccountOwnerProgram extends string = string,
|
|
98
|
+
> = {
|
|
99
|
+
/** Wrapped mint */
|
|
100
|
+
wrappedMint: Address<TAccountWrappedMint>;
|
|
101
|
+
/** Wrapped mint authority PDA */
|
|
102
|
+
wrappedMintAuthority: Address<TAccountWrappedMintAuthority>;
|
|
103
|
+
/** Unwrapped mint */
|
|
104
|
+
unwrappedMint: Address<TAccountUnwrappedMint>;
|
|
105
|
+
/** Token-2022 program */
|
|
106
|
+
token2022Program?: Address<TAccountToken2022Program>;
|
|
107
|
+
/**
|
|
108
|
+
* Source metadata account. Required if metadata pointer
|
|
109
|
+
* indicates external account.
|
|
110
|
+
*/
|
|
111
|
+
sourceMetadata?: Address<TAccountSourceMetadata>;
|
|
112
|
+
/**
|
|
113
|
+
* Owner program. Required when metadata account is
|
|
114
|
+
* owned by a third-party program.
|
|
115
|
+
*/
|
|
116
|
+
ownerProgram?: Address<TAccountOwnerProgram>;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export function getSyncMetadataToToken2022Instruction<
|
|
120
|
+
TAccountWrappedMint extends string,
|
|
121
|
+
TAccountWrappedMintAuthority extends string,
|
|
122
|
+
TAccountUnwrappedMint extends string,
|
|
123
|
+
TAccountToken2022Program extends string,
|
|
124
|
+
TAccountSourceMetadata extends string,
|
|
125
|
+
TAccountOwnerProgram extends string,
|
|
126
|
+
TProgramAddress extends Address = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
127
|
+
>(
|
|
128
|
+
input: SyncMetadataToToken2022Input<
|
|
129
|
+
TAccountWrappedMint,
|
|
130
|
+
TAccountWrappedMintAuthority,
|
|
131
|
+
TAccountUnwrappedMint,
|
|
132
|
+
TAccountToken2022Program,
|
|
133
|
+
TAccountSourceMetadata,
|
|
134
|
+
TAccountOwnerProgram
|
|
135
|
+
>,
|
|
136
|
+
config?: { programAddress?: TProgramAddress },
|
|
137
|
+
): SyncMetadataToToken2022Instruction<
|
|
138
|
+
TProgramAddress,
|
|
139
|
+
TAccountWrappedMint,
|
|
140
|
+
TAccountWrappedMintAuthority,
|
|
141
|
+
TAccountUnwrappedMint,
|
|
142
|
+
TAccountToken2022Program,
|
|
143
|
+
TAccountSourceMetadata,
|
|
144
|
+
TAccountOwnerProgram
|
|
145
|
+
> {
|
|
146
|
+
// Program address.
|
|
147
|
+
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
148
|
+
|
|
149
|
+
// Original accounts.
|
|
150
|
+
const originalAccounts = {
|
|
151
|
+
wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
|
|
152
|
+
wrappedMintAuthority: { value: input.wrappedMintAuthority ?? null, isWritable: false },
|
|
153
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
154
|
+
token2022Program: { value: input.token2022Program ?? null, isWritable: false },
|
|
155
|
+
sourceMetadata: { value: input.sourceMetadata ?? null, isWritable: false },
|
|
156
|
+
ownerProgram: { value: input.ownerProgram ?? null, isWritable: false },
|
|
157
|
+
};
|
|
158
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
159
|
+
|
|
160
|
+
// Resolve default values.
|
|
161
|
+
if (!accounts.token2022Program.value) {
|
|
162
|
+
accounts.token2022Program.value =
|
|
163
|
+
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' as Address<'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'>;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
167
|
+
return Object.freeze({
|
|
168
|
+
accounts: [
|
|
169
|
+
getAccountMeta('wrappedMint', accounts.wrappedMint),
|
|
170
|
+
getAccountMeta('wrappedMintAuthority', accounts.wrappedMintAuthority),
|
|
171
|
+
getAccountMeta('unwrappedMint', accounts.unwrappedMint),
|
|
172
|
+
getAccountMeta('token2022Program', accounts.token2022Program),
|
|
173
|
+
getAccountMeta('sourceMetadata', accounts.sourceMetadata),
|
|
174
|
+
getAccountMeta('ownerProgram', accounts.ownerProgram),
|
|
175
|
+
],
|
|
176
|
+
data: getSyncMetadataToToken2022InstructionDataEncoder().encode({}),
|
|
177
|
+
programAddress,
|
|
178
|
+
} as SyncMetadataToToken2022Instruction<
|
|
179
|
+
TProgramAddress,
|
|
180
|
+
TAccountWrappedMint,
|
|
181
|
+
TAccountWrappedMintAuthority,
|
|
182
|
+
TAccountUnwrappedMint,
|
|
183
|
+
TAccountToken2022Program,
|
|
184
|
+
TAccountSourceMetadata,
|
|
185
|
+
TAccountOwnerProgram
|
|
186
|
+
>);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export type ParsedSyncMetadataToToken2022Instruction<
|
|
190
|
+
TProgram extends string = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
191
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
192
|
+
> = {
|
|
193
|
+
programAddress: Address<TProgram>;
|
|
194
|
+
accounts: {
|
|
195
|
+
/** Wrapped mint */
|
|
196
|
+
wrappedMint: TAccountMetas[0];
|
|
197
|
+
/** Wrapped mint authority PDA */
|
|
198
|
+
wrappedMintAuthority: TAccountMetas[1];
|
|
199
|
+
/** Unwrapped mint */
|
|
200
|
+
unwrappedMint: TAccountMetas[2];
|
|
201
|
+
/** Token-2022 program */
|
|
202
|
+
token2022Program: TAccountMetas[3];
|
|
203
|
+
/**
|
|
204
|
+
* Source metadata account. Required if metadata pointer
|
|
205
|
+
* indicates external account.
|
|
206
|
+
*/
|
|
207
|
+
sourceMetadata?: TAccountMetas[4] | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* Owner program. Required when metadata account is
|
|
210
|
+
* owned by a third-party program.
|
|
211
|
+
*/
|
|
212
|
+
ownerProgram?: TAccountMetas[5] | undefined;
|
|
213
|
+
};
|
|
214
|
+
data: SyncMetadataToToken2022InstructionData;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export function parseSyncMetadataToToken2022Instruction<
|
|
218
|
+
TProgram extends string,
|
|
219
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
220
|
+
>(
|
|
221
|
+
instruction: Instruction<TProgram> &
|
|
222
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
223
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
224
|
+
): ParsedSyncMetadataToToken2022Instruction<TProgram, TAccountMetas> {
|
|
225
|
+
if (instruction.accounts.length < 6) {
|
|
226
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
|
|
227
|
+
actualAccountMetas: instruction.accounts.length,
|
|
228
|
+
expectedAccountMetas: 6,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
let accountIndex = 0;
|
|
232
|
+
const getNextAccount = () => {
|
|
233
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
234
|
+
accountIndex += 1;
|
|
235
|
+
return accountMeta;
|
|
236
|
+
};
|
|
237
|
+
const getNextOptionalAccount = () => {
|
|
238
|
+
const accountMeta = getNextAccount();
|
|
239
|
+
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? undefined : accountMeta;
|
|
240
|
+
};
|
|
241
|
+
return {
|
|
242
|
+
programAddress: instruction.programAddress,
|
|
243
|
+
accounts: {
|
|
244
|
+
wrappedMint: getNextAccount(),
|
|
245
|
+
wrappedMintAuthority: getNextAccount(),
|
|
246
|
+
unwrappedMint: getNextAccount(),
|
|
247
|
+
token2022Program: getNextAccount(),
|
|
248
|
+
sourceMetadata: getNextOptionalAccount(),
|
|
249
|
+
ownerProgram: getNextOptionalAccount(),
|
|
250
|
+
},
|
|
251
|
+
data: getSyncMetadataToToken2022InstructionDataDecoder().decode(instruction.data),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
@@ -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 UNWRAP_DISCRIMINATOR = 2;
|
|
40
|
+
|
|
41
|
+
export function getUnwrapDiscriminatorBytes(): ReadonlyUint8Array {
|
|
42
|
+
return getU8Encoder().encode(UNWRAP_DISCRIMINATOR);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type UnwrapInstruction<
|
|
46
|
+
TProgram extends string = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
47
|
+
TAccountUnwrappedEscrow extends string | AccountMeta<string> = string,
|
|
48
|
+
TAccountRecipientUnwrappedToken extends string | AccountMeta<string> = string,
|
|
49
|
+
TAccountWrappedMintAuthority extends string | AccountMeta<string> = string,
|
|
50
|
+
TAccountUnwrappedMint extends string | AccountMeta<string> = string,
|
|
51
|
+
TAccountWrappedTokenProgram extends string | AccountMeta<string> = string,
|
|
52
|
+
TAccountUnwrappedTokenProgram extends string | AccountMeta<string> = string,
|
|
53
|
+
TAccountWrappedTokenAccount extends string | AccountMeta<string> = string,
|
|
54
|
+
TAccountWrappedMint 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
|
+
TAccountUnwrappedEscrow extends string ? WritableAccount<TAccountUnwrappedEscrow> : TAccountUnwrappedEscrow,
|
|
62
|
+
TAccountRecipientUnwrappedToken extends string
|
|
63
|
+
? WritableAccount<TAccountRecipientUnwrappedToken>
|
|
64
|
+
: TAccountRecipientUnwrappedToken,
|
|
65
|
+
TAccountWrappedMintAuthority extends string
|
|
66
|
+
? ReadonlyAccount<TAccountWrappedMintAuthority>
|
|
67
|
+
: TAccountWrappedMintAuthority,
|
|
68
|
+
TAccountUnwrappedMint extends string ? ReadonlyAccount<TAccountUnwrappedMint> : TAccountUnwrappedMint,
|
|
69
|
+
TAccountWrappedTokenProgram extends string
|
|
70
|
+
? ReadonlyAccount<TAccountWrappedTokenProgram>
|
|
71
|
+
: TAccountWrappedTokenProgram,
|
|
72
|
+
TAccountUnwrappedTokenProgram extends string
|
|
73
|
+
? ReadonlyAccount<TAccountUnwrappedTokenProgram>
|
|
74
|
+
: TAccountUnwrappedTokenProgram,
|
|
75
|
+
TAccountWrappedTokenAccount extends string
|
|
76
|
+
? WritableAccount<TAccountWrappedTokenAccount>
|
|
77
|
+
: TAccountWrappedTokenAccount,
|
|
78
|
+
TAccountWrappedMint extends string ? WritableAccount<TAccountWrappedMint> : TAccountWrappedMint,
|
|
79
|
+
TAccountTransferAuthority extends string
|
|
80
|
+
? ReadonlyAccount<TAccountTransferAuthority>
|
|
81
|
+
: TAccountTransferAuthority,
|
|
82
|
+
...TRemainingAccounts,
|
|
83
|
+
]
|
|
84
|
+
>;
|
|
85
|
+
|
|
86
|
+
export type UnwrapInstructionData = {
|
|
87
|
+
discriminator: number;
|
|
88
|
+
/** The amount of tokens to unwrap. */
|
|
89
|
+
amount: bigint;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type UnwrapInstructionDataArgs = {
|
|
93
|
+
/** The amount of tokens to unwrap. */
|
|
94
|
+
amount: number | bigint;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export function getUnwrapInstructionDataEncoder(): FixedSizeEncoder<UnwrapInstructionDataArgs> {
|
|
98
|
+
return transformEncoder(
|
|
99
|
+
getStructEncoder([
|
|
100
|
+
['discriminator', getU8Encoder()],
|
|
101
|
+
['amount', getU64Encoder()],
|
|
102
|
+
]),
|
|
103
|
+
value => ({ ...value, discriminator: UNWRAP_DISCRIMINATOR }),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function getUnwrapInstructionDataDecoder(): FixedSizeDecoder<UnwrapInstructionData> {
|
|
108
|
+
return getStructDecoder([
|
|
109
|
+
['discriminator', getU8Decoder()],
|
|
110
|
+
['amount', getU64Decoder()],
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function getUnwrapInstructionDataCodec(): FixedSizeCodec<UnwrapInstructionDataArgs, UnwrapInstructionData> {
|
|
115
|
+
return combineCodec(getUnwrapInstructionDataEncoder(), getUnwrapInstructionDataDecoder());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type UnwrapInput<
|
|
119
|
+
TAccountUnwrappedEscrow extends string = string,
|
|
120
|
+
TAccountRecipientUnwrappedToken extends string = string,
|
|
121
|
+
TAccountWrappedMintAuthority extends string = string,
|
|
122
|
+
TAccountUnwrappedMint extends string = string,
|
|
123
|
+
TAccountWrappedTokenProgram extends string = string,
|
|
124
|
+
TAccountUnwrappedTokenProgram extends string = string,
|
|
125
|
+
TAccountWrappedTokenAccount extends string = string,
|
|
126
|
+
TAccountWrappedMint extends string = string,
|
|
127
|
+
TAccountTransferAuthority extends string = string,
|
|
128
|
+
> = {
|
|
129
|
+
/**
|
|
130
|
+
* The escrow account holding the unwrapped tokens.
|
|
131
|
+
* Address must be ATA: get_escrow_address(unwrapped_mint, unwrapped_token_program, wrapped_token_program)
|
|
132
|
+
*/
|
|
133
|
+
unwrappedEscrow: Address<TAccountUnwrappedEscrow>;
|
|
134
|
+
/** The account to receive the unwrapped tokens. */
|
|
135
|
+
recipientUnwrappedToken: Address<TAccountRecipientUnwrappedToken>;
|
|
136
|
+
/**
|
|
137
|
+
* The PDA authority of the wrapped mint,
|
|
138
|
+
* address must be: `get_wrapped_mint_authority(wrapped_mint)`
|
|
139
|
+
*/
|
|
140
|
+
wrappedMintAuthority: Address<TAccountWrappedMintAuthority>;
|
|
141
|
+
/** The mint of the unwrapped tokens */
|
|
142
|
+
unwrappedMint: Address<TAccountUnwrappedMint>;
|
|
143
|
+
/** The token program of the wrapped tokens */
|
|
144
|
+
wrappedTokenProgram: Address<TAccountWrappedTokenProgram>;
|
|
145
|
+
/** The token program of the unwrapped tokens */
|
|
146
|
+
unwrappedTokenProgram: Address<TAccountUnwrappedTokenProgram>;
|
|
147
|
+
/** The source token account for the wrapped tokens */
|
|
148
|
+
wrappedTokenAccount: Address<TAccountWrappedTokenAccount>;
|
|
149
|
+
/**
|
|
150
|
+
* The wrapped mint account, address must be:
|
|
151
|
+
* `get_wrapped_mint_address(unwrapped_mint_address, wrapped_token_program_id)`
|
|
152
|
+
*/
|
|
153
|
+
wrappedMint: Address<TAccountWrappedMint>;
|
|
154
|
+
/** The authority to burn the wrapped tokens. */
|
|
155
|
+
transferAuthority: Address<TAccountTransferAuthority> | TransactionSigner<TAccountTransferAuthority>;
|
|
156
|
+
amount: UnwrapInstructionDataArgs['amount'];
|
|
157
|
+
multiSigners?: Array<TransactionSigner>;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export function getUnwrapInstruction<
|
|
161
|
+
TAccountUnwrappedEscrow extends string,
|
|
162
|
+
TAccountRecipientUnwrappedToken extends string,
|
|
163
|
+
TAccountWrappedMintAuthority extends string,
|
|
164
|
+
TAccountUnwrappedMint extends string,
|
|
165
|
+
TAccountWrappedTokenProgram extends string,
|
|
166
|
+
TAccountUnwrappedTokenProgram extends string,
|
|
167
|
+
TAccountWrappedTokenAccount extends string,
|
|
168
|
+
TAccountWrappedMint extends string,
|
|
169
|
+
TAccountTransferAuthority extends string,
|
|
170
|
+
TProgramAddress extends Address = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
171
|
+
>(
|
|
172
|
+
input: UnwrapInput<
|
|
173
|
+
TAccountUnwrappedEscrow,
|
|
174
|
+
TAccountRecipientUnwrappedToken,
|
|
175
|
+
TAccountWrappedMintAuthority,
|
|
176
|
+
TAccountUnwrappedMint,
|
|
177
|
+
TAccountWrappedTokenProgram,
|
|
178
|
+
TAccountUnwrappedTokenProgram,
|
|
179
|
+
TAccountWrappedTokenAccount,
|
|
180
|
+
TAccountWrappedMint,
|
|
181
|
+
TAccountTransferAuthority
|
|
182
|
+
>,
|
|
183
|
+
config?: { programAddress?: TProgramAddress },
|
|
184
|
+
): UnwrapInstruction<
|
|
185
|
+
TProgramAddress,
|
|
186
|
+
TAccountUnwrappedEscrow,
|
|
187
|
+
TAccountRecipientUnwrappedToken,
|
|
188
|
+
TAccountWrappedMintAuthority,
|
|
189
|
+
TAccountUnwrappedMint,
|
|
190
|
+
TAccountWrappedTokenProgram,
|
|
191
|
+
TAccountUnwrappedTokenProgram,
|
|
192
|
+
TAccountWrappedTokenAccount,
|
|
193
|
+
TAccountWrappedMint,
|
|
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
|
+
unwrappedEscrow: { value: input.unwrappedEscrow ?? null, isWritable: true },
|
|
204
|
+
recipientUnwrappedToken: { value: input.recipientUnwrappedToken ?? null, isWritable: true },
|
|
205
|
+
wrappedMintAuthority: { value: input.wrappedMintAuthority ?? null, isWritable: false },
|
|
206
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
207
|
+
wrappedTokenProgram: { value: input.wrappedTokenProgram ?? null, isWritable: false },
|
|
208
|
+
unwrappedTokenProgram: { value: input.unwrappedTokenProgram ?? null, isWritable: false },
|
|
209
|
+
wrappedTokenAccount: { value: input.wrappedTokenAccount ?? null, isWritable: true },
|
|
210
|
+
wrappedMint: { value: input.wrappedMint ?? 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('unwrappedEscrow', accounts.unwrappedEscrow),
|
|
229
|
+
getAccountMeta('recipientUnwrappedToken', accounts.recipientUnwrappedToken),
|
|
230
|
+
getAccountMeta('wrappedMintAuthority', accounts.wrappedMintAuthority),
|
|
231
|
+
getAccountMeta('unwrappedMint', accounts.unwrappedMint),
|
|
232
|
+
getAccountMeta('wrappedTokenProgram', accounts.wrappedTokenProgram),
|
|
233
|
+
getAccountMeta('unwrappedTokenProgram', accounts.unwrappedTokenProgram),
|
|
234
|
+
getAccountMeta('wrappedTokenAccount', accounts.wrappedTokenAccount),
|
|
235
|
+
getAccountMeta('wrappedMint', accounts.wrappedMint),
|
|
236
|
+
getAccountMeta('transferAuthority', accounts.transferAuthority),
|
|
237
|
+
...remainingAccounts,
|
|
238
|
+
],
|
|
239
|
+
data: getUnwrapInstructionDataEncoder().encode(args as UnwrapInstructionDataArgs),
|
|
240
|
+
programAddress,
|
|
241
|
+
} as UnwrapInstruction<
|
|
242
|
+
TProgramAddress,
|
|
243
|
+
TAccountUnwrappedEscrow,
|
|
244
|
+
TAccountRecipientUnwrappedToken,
|
|
245
|
+
TAccountWrappedMintAuthority,
|
|
246
|
+
TAccountUnwrappedMint,
|
|
247
|
+
TAccountWrappedTokenProgram,
|
|
248
|
+
TAccountUnwrappedTokenProgram,
|
|
249
|
+
TAccountWrappedTokenAccount,
|
|
250
|
+
TAccountWrappedMint,
|
|
251
|
+
(typeof input)['transferAuthority'] extends TransactionSigner<TAccountTransferAuthority>
|
|
252
|
+
? ReadonlySignerAccount<TAccountTransferAuthority> & AccountSignerMeta<TAccountTransferAuthority>
|
|
253
|
+
: TAccountTransferAuthority
|
|
254
|
+
>);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export type ParsedUnwrapInstruction<
|
|
258
|
+
TProgram extends string = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
259
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
260
|
+
> = {
|
|
261
|
+
programAddress: Address<TProgram>;
|
|
262
|
+
accounts: {
|
|
263
|
+
/**
|
|
264
|
+
* The escrow account holding the unwrapped tokens.
|
|
265
|
+
* Address must be ATA: get_escrow_address(unwrapped_mint, unwrapped_token_program, wrapped_token_program)
|
|
266
|
+
*/
|
|
267
|
+
unwrappedEscrow: TAccountMetas[0];
|
|
268
|
+
/** The account to receive the unwrapped tokens. */
|
|
269
|
+
recipientUnwrappedToken: TAccountMetas[1];
|
|
270
|
+
/**
|
|
271
|
+
* The PDA authority of the wrapped mint,
|
|
272
|
+
* address must be: `get_wrapped_mint_authority(wrapped_mint)`
|
|
273
|
+
*/
|
|
274
|
+
wrappedMintAuthority: TAccountMetas[2];
|
|
275
|
+
/** The mint of the unwrapped tokens */
|
|
276
|
+
unwrappedMint: TAccountMetas[3];
|
|
277
|
+
/** The token program of the wrapped tokens */
|
|
278
|
+
wrappedTokenProgram: TAccountMetas[4];
|
|
279
|
+
/** The token program of the unwrapped tokens */
|
|
280
|
+
unwrappedTokenProgram: TAccountMetas[5];
|
|
281
|
+
/** The source token account for the wrapped tokens */
|
|
282
|
+
wrappedTokenAccount: TAccountMetas[6];
|
|
283
|
+
/**
|
|
284
|
+
* The wrapped mint account, address must be:
|
|
285
|
+
* `get_wrapped_mint_address(unwrapped_mint_address, wrapped_token_program_id)`
|
|
286
|
+
*/
|
|
287
|
+
wrappedMint: TAccountMetas[7];
|
|
288
|
+
/** The authority to burn the wrapped tokens. */
|
|
289
|
+
transferAuthority: TAccountMetas[8];
|
|
290
|
+
};
|
|
291
|
+
data: UnwrapInstructionData;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export function parseUnwrapInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(
|
|
295
|
+
instruction: Instruction<TProgram> &
|
|
296
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
297
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
298
|
+
): ParsedUnwrapInstruction<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
|
+
unwrappedEscrow: getNextAccount(),
|
|
315
|
+
recipientUnwrappedToken: getNextAccount(),
|
|
316
|
+
wrappedMintAuthority: getNextAccount(),
|
|
317
|
+
unwrappedMint: getNextAccount(),
|
|
318
|
+
wrappedTokenProgram: getNextAccount(),
|
|
319
|
+
unwrappedTokenProgram: getNextAccount(),
|
|
320
|
+
wrappedTokenAccount: getNextAccount(),
|
|
321
|
+
wrappedMint: getNextAccount(),
|
|
322
|
+
transferAuthority: getNextAccount(),
|
|
323
|
+
},
|
|
324
|
+
data: getUnwrapInstructionDataDecoder().decode(instruction.data),
|
|
325
|
+
};
|
|
326
|
+
}
|