@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.
- 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,250 @@
|
|
|
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
|
+
getBooleanDecoder,
|
|
12
|
+
getBooleanEncoder,
|
|
13
|
+
getStructDecoder,
|
|
14
|
+
getStructEncoder,
|
|
15
|
+
getU8Decoder,
|
|
16
|
+
getU8Encoder,
|
|
17
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
18
|
+
SolanaError,
|
|
19
|
+
transformEncoder,
|
|
20
|
+
type AccountMeta,
|
|
21
|
+
type Address,
|
|
22
|
+
type FixedSizeCodec,
|
|
23
|
+
type FixedSizeDecoder,
|
|
24
|
+
type FixedSizeEncoder,
|
|
25
|
+
type Instruction,
|
|
26
|
+
type InstructionWithAccounts,
|
|
27
|
+
type InstructionWithData,
|
|
28
|
+
type ReadonlyAccount,
|
|
29
|
+
type ReadonlyUint8Array,
|
|
30
|
+
type WritableAccount,
|
|
31
|
+
} from '@solana/kit';
|
|
32
|
+
import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/program-client-core';
|
|
33
|
+
import { TOKEN_WRAP_PROGRAM_ADDRESS } from '../programs';
|
|
34
|
+
|
|
35
|
+
export const CREATE_MINT_DISCRIMINATOR = 0;
|
|
36
|
+
|
|
37
|
+
export function getCreateMintDiscriminatorBytes(): ReadonlyUint8Array {
|
|
38
|
+
return getU8Encoder().encode(CREATE_MINT_DISCRIMINATOR);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type CreateMintInstruction<
|
|
42
|
+
TProgram extends string = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
43
|
+
TAccountWrappedMint extends string | AccountMeta<string> = string,
|
|
44
|
+
TAccountBackpointer extends string | AccountMeta<string> = string,
|
|
45
|
+
TAccountUnwrappedMint extends string | AccountMeta<string> = string,
|
|
46
|
+
TAccountSystemProgram extends string | AccountMeta<string> = '11111111111111111111111111111111',
|
|
47
|
+
TAccountWrappedTokenProgram extends string | AccountMeta<string> = string,
|
|
48
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
49
|
+
> = Instruction<TProgram> &
|
|
50
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
51
|
+
InstructionWithAccounts<
|
|
52
|
+
[
|
|
53
|
+
TAccountWrappedMint extends string ? WritableAccount<TAccountWrappedMint> : TAccountWrappedMint,
|
|
54
|
+
TAccountBackpointer extends string ? WritableAccount<TAccountBackpointer> : TAccountBackpointer,
|
|
55
|
+
TAccountUnwrappedMint extends string ? ReadonlyAccount<TAccountUnwrappedMint> : TAccountUnwrappedMint,
|
|
56
|
+
TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram,
|
|
57
|
+
TAccountWrappedTokenProgram extends string
|
|
58
|
+
? ReadonlyAccount<TAccountWrappedTokenProgram>
|
|
59
|
+
: TAccountWrappedTokenProgram,
|
|
60
|
+
...TRemainingAccounts,
|
|
61
|
+
]
|
|
62
|
+
>;
|
|
63
|
+
|
|
64
|
+
export type CreateMintInstructionData = {
|
|
65
|
+
discriminator: number;
|
|
66
|
+
/** Whether the creation should fail if the wrapped mint already exists. */
|
|
67
|
+
idempotent: boolean;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type CreateMintInstructionDataArgs = {
|
|
71
|
+
/** Whether the creation should fail if the wrapped mint already exists. */
|
|
72
|
+
idempotent?: boolean;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export function getCreateMintInstructionDataEncoder(): FixedSizeEncoder<CreateMintInstructionDataArgs> {
|
|
76
|
+
return transformEncoder(
|
|
77
|
+
getStructEncoder([
|
|
78
|
+
['discriminator', getU8Encoder()],
|
|
79
|
+
['idempotent', getBooleanEncoder()],
|
|
80
|
+
]),
|
|
81
|
+
value => ({ ...value, discriminator: CREATE_MINT_DISCRIMINATOR, idempotent: value.idempotent ?? false }),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function getCreateMintInstructionDataDecoder(): FixedSizeDecoder<CreateMintInstructionData> {
|
|
86
|
+
return getStructDecoder([
|
|
87
|
+
['discriminator', getU8Decoder()],
|
|
88
|
+
['idempotent', getBooleanDecoder()],
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function getCreateMintInstructionDataCodec(): FixedSizeCodec<
|
|
93
|
+
CreateMintInstructionDataArgs,
|
|
94
|
+
CreateMintInstructionData
|
|
95
|
+
> {
|
|
96
|
+
return combineCodec(getCreateMintInstructionDataEncoder(), getCreateMintInstructionDataDecoder());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type CreateMintInput<
|
|
100
|
+
TAccountWrappedMint extends string = string,
|
|
101
|
+
TAccountBackpointer extends string = string,
|
|
102
|
+
TAccountUnwrappedMint extends string = string,
|
|
103
|
+
TAccountSystemProgram extends string = string,
|
|
104
|
+
TAccountWrappedTokenProgram extends string = string,
|
|
105
|
+
> = {
|
|
106
|
+
/**
|
|
107
|
+
* Unallocated wrapped mint account to create (PDA), address must be:
|
|
108
|
+
* `get_wrapped_mint_address(unwrapped_mint_address, wrapped_token_program_id)`
|
|
109
|
+
*/
|
|
110
|
+
wrappedMint: Address<TAccountWrappedMint>;
|
|
111
|
+
/**
|
|
112
|
+
* Unallocated wrapped backpointer account to create (PDA)
|
|
113
|
+
* `get_wrapped_mint_backpointer_address(wrapped_mint_address)`
|
|
114
|
+
*/
|
|
115
|
+
backpointer: Address<TAccountBackpointer>;
|
|
116
|
+
/** The existing mint */
|
|
117
|
+
unwrappedMint: Address<TAccountUnwrappedMint>;
|
|
118
|
+
/** The system program */
|
|
119
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
120
|
+
/** The token program used to create the wrapped mint */
|
|
121
|
+
wrappedTokenProgram: Address<TAccountWrappedTokenProgram>;
|
|
122
|
+
idempotent?: CreateMintInstructionDataArgs['idempotent'];
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export function getCreateMintInstruction<
|
|
126
|
+
TAccountWrappedMint extends string,
|
|
127
|
+
TAccountBackpointer extends string,
|
|
128
|
+
TAccountUnwrappedMint extends string,
|
|
129
|
+
TAccountSystemProgram extends string,
|
|
130
|
+
TAccountWrappedTokenProgram extends string,
|
|
131
|
+
TProgramAddress extends Address = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
132
|
+
>(
|
|
133
|
+
input: CreateMintInput<
|
|
134
|
+
TAccountWrappedMint,
|
|
135
|
+
TAccountBackpointer,
|
|
136
|
+
TAccountUnwrappedMint,
|
|
137
|
+
TAccountSystemProgram,
|
|
138
|
+
TAccountWrappedTokenProgram
|
|
139
|
+
>,
|
|
140
|
+
config?: { programAddress?: TProgramAddress },
|
|
141
|
+
): CreateMintInstruction<
|
|
142
|
+
TProgramAddress,
|
|
143
|
+
TAccountWrappedMint,
|
|
144
|
+
TAccountBackpointer,
|
|
145
|
+
TAccountUnwrappedMint,
|
|
146
|
+
TAccountSystemProgram,
|
|
147
|
+
TAccountWrappedTokenProgram
|
|
148
|
+
> {
|
|
149
|
+
// Program address.
|
|
150
|
+
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
151
|
+
|
|
152
|
+
// Original accounts.
|
|
153
|
+
const originalAccounts = {
|
|
154
|
+
wrappedMint: { value: input.wrappedMint ?? null, isWritable: true },
|
|
155
|
+
backpointer: { value: input.backpointer ?? null, isWritable: true },
|
|
156
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
157
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
158
|
+
wrappedTokenProgram: { value: input.wrappedTokenProgram ?? null, isWritable: false },
|
|
159
|
+
};
|
|
160
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
161
|
+
|
|
162
|
+
// Original args.
|
|
163
|
+
const args = { ...input };
|
|
164
|
+
|
|
165
|
+
// Resolve default values.
|
|
166
|
+
if (!accounts.systemProgram.value) {
|
|
167
|
+
accounts.systemProgram.value =
|
|
168
|
+
'11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
172
|
+
return Object.freeze({
|
|
173
|
+
accounts: [
|
|
174
|
+
getAccountMeta('wrappedMint', accounts.wrappedMint),
|
|
175
|
+
getAccountMeta('backpointer', accounts.backpointer),
|
|
176
|
+
getAccountMeta('unwrappedMint', accounts.unwrappedMint),
|
|
177
|
+
getAccountMeta('systemProgram', accounts.systemProgram),
|
|
178
|
+
getAccountMeta('wrappedTokenProgram', accounts.wrappedTokenProgram),
|
|
179
|
+
],
|
|
180
|
+
data: getCreateMintInstructionDataEncoder().encode(args as CreateMintInstructionDataArgs),
|
|
181
|
+
programAddress,
|
|
182
|
+
} as CreateMintInstruction<
|
|
183
|
+
TProgramAddress,
|
|
184
|
+
TAccountWrappedMint,
|
|
185
|
+
TAccountBackpointer,
|
|
186
|
+
TAccountUnwrappedMint,
|
|
187
|
+
TAccountSystemProgram,
|
|
188
|
+
TAccountWrappedTokenProgram
|
|
189
|
+
>);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type ParsedCreateMintInstruction<
|
|
193
|
+
TProgram extends string = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
194
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
195
|
+
> = {
|
|
196
|
+
programAddress: Address<TProgram>;
|
|
197
|
+
accounts: {
|
|
198
|
+
/**
|
|
199
|
+
* Unallocated wrapped mint account to create (PDA), address must be:
|
|
200
|
+
* `get_wrapped_mint_address(unwrapped_mint_address, wrapped_token_program_id)`
|
|
201
|
+
*/
|
|
202
|
+
wrappedMint: TAccountMetas[0];
|
|
203
|
+
/**
|
|
204
|
+
* Unallocated wrapped backpointer account to create (PDA)
|
|
205
|
+
* `get_wrapped_mint_backpointer_address(wrapped_mint_address)`
|
|
206
|
+
*/
|
|
207
|
+
backpointer: TAccountMetas[1];
|
|
208
|
+
/** The existing mint */
|
|
209
|
+
unwrappedMint: TAccountMetas[2];
|
|
210
|
+
/** The system program */
|
|
211
|
+
systemProgram?: TAccountMetas[3] | undefined;
|
|
212
|
+
/** The token program used to create the wrapped mint */
|
|
213
|
+
wrappedTokenProgram: TAccountMetas[4];
|
|
214
|
+
};
|
|
215
|
+
data: CreateMintInstructionData;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export function parseCreateMintInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(
|
|
219
|
+
instruction: Instruction<TProgram> &
|
|
220
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
221
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
222
|
+
): ParsedCreateMintInstruction<TProgram, TAccountMetas> {
|
|
223
|
+
if (instruction.accounts.length < 5) {
|
|
224
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
|
|
225
|
+
actualAccountMetas: instruction.accounts.length,
|
|
226
|
+
expectedAccountMetas: 5,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
let accountIndex = 0;
|
|
230
|
+
const getNextAccount = () => {
|
|
231
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
232
|
+
accountIndex += 1;
|
|
233
|
+
return accountMeta;
|
|
234
|
+
};
|
|
235
|
+
const getNextOptionalAccount = () => {
|
|
236
|
+
const accountMeta = getNextAccount();
|
|
237
|
+
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? undefined : accountMeta;
|
|
238
|
+
};
|
|
239
|
+
return {
|
|
240
|
+
programAddress: instruction.programAddress,
|
|
241
|
+
accounts: {
|
|
242
|
+
wrappedMint: getNextAccount(),
|
|
243
|
+
backpointer: getNextAccount(),
|
|
244
|
+
unwrappedMint: getNextAccount(),
|
|
245
|
+
systemProgram: getNextOptionalAccount(),
|
|
246
|
+
wrappedTokenProgram: getNextAccount(),
|
|
247
|
+
},
|
|
248
|
+
data: getCreateMintInstructionDataDecoder().decode(instruction.data),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
@@ -0,0 +1,305 @@
|
|
|
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_SPL_TOKEN_DISCRIMINATOR = 5;
|
|
34
|
+
|
|
35
|
+
export function getSyncMetadataToSplTokenDiscriminatorBytes(): ReadonlyUint8Array {
|
|
36
|
+
return getU8Encoder().encode(SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type SyncMetadataToSplTokenInstruction<
|
|
40
|
+
TProgram extends string = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
41
|
+
TAccountMetaplexMetadata extends string | AccountMeta<string> = string,
|
|
42
|
+
TAccountWrappedMintAuthority extends string | AccountMeta<string> = string,
|
|
43
|
+
TAccountWrappedMint extends string | AccountMeta<string> = string,
|
|
44
|
+
TAccountUnwrappedMint extends string | AccountMeta<string> = string,
|
|
45
|
+
TAccountMetaplexProgram extends string | AccountMeta<string> = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s',
|
|
46
|
+
TAccountSystemProgram extends string | AccountMeta<string> = '11111111111111111111111111111111',
|
|
47
|
+
TAccountRentSysvar extends string | AccountMeta<string> = 'SysvarRent111111111111111111111111111111111',
|
|
48
|
+
TAccountSourceMetadata extends string | AccountMeta<string> = string,
|
|
49
|
+
TAccountOwnerProgram extends string | AccountMeta<string> = string,
|
|
50
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
51
|
+
> = Instruction<TProgram> &
|
|
52
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
53
|
+
InstructionWithAccounts<
|
|
54
|
+
[
|
|
55
|
+
TAccountMetaplexMetadata extends string
|
|
56
|
+
? WritableAccount<TAccountMetaplexMetadata>
|
|
57
|
+
: TAccountMetaplexMetadata,
|
|
58
|
+
TAccountWrappedMintAuthority extends string
|
|
59
|
+
? WritableAccount<TAccountWrappedMintAuthority>
|
|
60
|
+
: TAccountWrappedMintAuthority,
|
|
61
|
+
TAccountWrappedMint extends string ? ReadonlyAccount<TAccountWrappedMint> : TAccountWrappedMint,
|
|
62
|
+
TAccountUnwrappedMint extends string ? ReadonlyAccount<TAccountUnwrappedMint> : TAccountUnwrappedMint,
|
|
63
|
+
TAccountMetaplexProgram extends string ? ReadonlyAccount<TAccountMetaplexProgram> : TAccountMetaplexProgram,
|
|
64
|
+
TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram,
|
|
65
|
+
TAccountRentSysvar extends string ? ReadonlyAccount<TAccountRentSysvar> : TAccountRentSysvar,
|
|
66
|
+
TAccountSourceMetadata extends string ? ReadonlyAccount<TAccountSourceMetadata> : TAccountSourceMetadata,
|
|
67
|
+
TAccountOwnerProgram extends string ? ReadonlyAccount<TAccountOwnerProgram> : TAccountOwnerProgram,
|
|
68
|
+
...TRemainingAccounts,
|
|
69
|
+
]
|
|
70
|
+
>;
|
|
71
|
+
|
|
72
|
+
export type SyncMetadataToSplTokenInstructionData = { discriminator: number };
|
|
73
|
+
|
|
74
|
+
export type SyncMetadataToSplTokenInstructionDataArgs = {};
|
|
75
|
+
|
|
76
|
+
export function getSyncMetadataToSplTokenInstructionDataEncoder(): FixedSizeEncoder<SyncMetadataToSplTokenInstructionDataArgs> {
|
|
77
|
+
return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()]]), value => ({
|
|
78
|
+
...value,
|
|
79
|
+
discriminator: SYNC_METADATA_TO_SPL_TOKEN_DISCRIMINATOR,
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getSyncMetadataToSplTokenInstructionDataDecoder(): FixedSizeDecoder<SyncMetadataToSplTokenInstructionData> {
|
|
84
|
+
return getStructDecoder([['discriminator', getU8Decoder()]]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function getSyncMetadataToSplTokenInstructionDataCodec(): FixedSizeCodec<
|
|
88
|
+
SyncMetadataToSplTokenInstructionDataArgs,
|
|
89
|
+
SyncMetadataToSplTokenInstructionData
|
|
90
|
+
> {
|
|
91
|
+
return combineCodec(
|
|
92
|
+
getSyncMetadataToSplTokenInstructionDataEncoder(),
|
|
93
|
+
getSyncMetadataToSplTokenInstructionDataDecoder(),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type SyncMetadataToSplTokenInput<
|
|
98
|
+
TAccountMetaplexMetadata extends string = string,
|
|
99
|
+
TAccountWrappedMintAuthority extends string = string,
|
|
100
|
+
TAccountWrappedMint extends string = string,
|
|
101
|
+
TAccountUnwrappedMint extends string = string,
|
|
102
|
+
TAccountMetaplexProgram extends string = string,
|
|
103
|
+
TAccountSystemProgram extends string = string,
|
|
104
|
+
TAccountRentSysvar extends string = string,
|
|
105
|
+
TAccountSourceMetadata extends string = string,
|
|
106
|
+
TAccountOwnerProgram extends string = string,
|
|
107
|
+
> = {
|
|
108
|
+
/** `Metaplex` metadata account */
|
|
109
|
+
metaplexMetadata: Address<TAccountMetaplexMetadata>;
|
|
110
|
+
/** Wrapped mint authority (PDA) */
|
|
111
|
+
wrappedMintAuthority: Address<TAccountWrappedMintAuthority>;
|
|
112
|
+
/** Wrapped SPL Token mint */
|
|
113
|
+
wrappedMint: Address<TAccountWrappedMint>;
|
|
114
|
+
/** Unwrapped mint */
|
|
115
|
+
unwrappedMint: Address<TAccountUnwrappedMint>;
|
|
116
|
+
/** `Metaplex` Token Metadata Program */
|
|
117
|
+
metaplexProgram?: Address<TAccountMetaplexProgram>;
|
|
118
|
+
/** System program */
|
|
119
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
120
|
+
/** Rent sysvar */
|
|
121
|
+
rentSysvar?: Address<TAccountRentSysvar>;
|
|
122
|
+
/**
|
|
123
|
+
* Source metadata account. Required if unwrapped mint
|
|
124
|
+
* is an SPL-Token or, if a Token-2022, its metadata pointer indicates
|
|
125
|
+
* an external account.
|
|
126
|
+
*/
|
|
127
|
+
sourceMetadata?: Address<TAccountSourceMetadata>;
|
|
128
|
+
/**
|
|
129
|
+
* Owner program. Required when metadata account is
|
|
130
|
+
* owned by a third-party program.
|
|
131
|
+
*/
|
|
132
|
+
ownerProgram?: Address<TAccountOwnerProgram>;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export function getSyncMetadataToSplTokenInstruction<
|
|
136
|
+
TAccountMetaplexMetadata extends string,
|
|
137
|
+
TAccountWrappedMintAuthority extends string,
|
|
138
|
+
TAccountWrappedMint extends string,
|
|
139
|
+
TAccountUnwrappedMint extends string,
|
|
140
|
+
TAccountMetaplexProgram extends string,
|
|
141
|
+
TAccountSystemProgram extends string,
|
|
142
|
+
TAccountRentSysvar extends string,
|
|
143
|
+
TAccountSourceMetadata extends string,
|
|
144
|
+
TAccountOwnerProgram extends string,
|
|
145
|
+
TProgramAddress extends Address = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
146
|
+
>(
|
|
147
|
+
input: SyncMetadataToSplTokenInput<
|
|
148
|
+
TAccountMetaplexMetadata,
|
|
149
|
+
TAccountWrappedMintAuthority,
|
|
150
|
+
TAccountWrappedMint,
|
|
151
|
+
TAccountUnwrappedMint,
|
|
152
|
+
TAccountMetaplexProgram,
|
|
153
|
+
TAccountSystemProgram,
|
|
154
|
+
TAccountRentSysvar,
|
|
155
|
+
TAccountSourceMetadata,
|
|
156
|
+
TAccountOwnerProgram
|
|
157
|
+
>,
|
|
158
|
+
config?: { programAddress?: TProgramAddress },
|
|
159
|
+
): SyncMetadataToSplTokenInstruction<
|
|
160
|
+
TProgramAddress,
|
|
161
|
+
TAccountMetaplexMetadata,
|
|
162
|
+
TAccountWrappedMintAuthority,
|
|
163
|
+
TAccountWrappedMint,
|
|
164
|
+
TAccountUnwrappedMint,
|
|
165
|
+
TAccountMetaplexProgram,
|
|
166
|
+
TAccountSystemProgram,
|
|
167
|
+
TAccountRentSysvar,
|
|
168
|
+
TAccountSourceMetadata,
|
|
169
|
+
TAccountOwnerProgram
|
|
170
|
+
> {
|
|
171
|
+
// Program address.
|
|
172
|
+
const programAddress = config?.programAddress ?? TOKEN_WRAP_PROGRAM_ADDRESS;
|
|
173
|
+
|
|
174
|
+
// Original accounts.
|
|
175
|
+
const originalAccounts = {
|
|
176
|
+
metaplexMetadata: { value: input.metaplexMetadata ?? null, isWritable: true },
|
|
177
|
+
wrappedMintAuthority: { value: input.wrappedMintAuthority ?? null, isWritable: true },
|
|
178
|
+
wrappedMint: { value: input.wrappedMint ?? null, isWritable: false },
|
|
179
|
+
unwrappedMint: { value: input.unwrappedMint ?? null, isWritable: false },
|
|
180
|
+
metaplexProgram: { value: input.metaplexProgram ?? null, isWritable: false },
|
|
181
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
182
|
+
rentSysvar: { value: input.rentSysvar ?? null, isWritable: false },
|
|
183
|
+
sourceMetadata: { value: input.sourceMetadata ?? null, isWritable: false },
|
|
184
|
+
ownerProgram: { value: input.ownerProgram ?? null, isWritable: false },
|
|
185
|
+
};
|
|
186
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
187
|
+
|
|
188
|
+
// Resolve default values.
|
|
189
|
+
if (!accounts.metaplexProgram.value) {
|
|
190
|
+
accounts.metaplexProgram.value =
|
|
191
|
+
'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>;
|
|
192
|
+
}
|
|
193
|
+
if (!accounts.systemProgram.value) {
|
|
194
|
+
accounts.systemProgram.value =
|
|
195
|
+
'11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
196
|
+
}
|
|
197
|
+
if (!accounts.rentSysvar.value) {
|
|
198
|
+
accounts.rentSysvar.value =
|
|
199
|
+
'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
203
|
+
return Object.freeze({
|
|
204
|
+
accounts: [
|
|
205
|
+
getAccountMeta('metaplexMetadata', accounts.metaplexMetadata),
|
|
206
|
+
getAccountMeta('wrappedMintAuthority', accounts.wrappedMintAuthority),
|
|
207
|
+
getAccountMeta('wrappedMint', accounts.wrappedMint),
|
|
208
|
+
getAccountMeta('unwrappedMint', accounts.unwrappedMint),
|
|
209
|
+
getAccountMeta('metaplexProgram', accounts.metaplexProgram),
|
|
210
|
+
getAccountMeta('systemProgram', accounts.systemProgram),
|
|
211
|
+
getAccountMeta('rentSysvar', accounts.rentSysvar),
|
|
212
|
+
getAccountMeta('sourceMetadata', accounts.sourceMetadata),
|
|
213
|
+
getAccountMeta('ownerProgram', accounts.ownerProgram),
|
|
214
|
+
],
|
|
215
|
+
data: getSyncMetadataToSplTokenInstructionDataEncoder().encode({}),
|
|
216
|
+
programAddress,
|
|
217
|
+
} as SyncMetadataToSplTokenInstruction<
|
|
218
|
+
TProgramAddress,
|
|
219
|
+
TAccountMetaplexMetadata,
|
|
220
|
+
TAccountWrappedMintAuthority,
|
|
221
|
+
TAccountWrappedMint,
|
|
222
|
+
TAccountUnwrappedMint,
|
|
223
|
+
TAccountMetaplexProgram,
|
|
224
|
+
TAccountSystemProgram,
|
|
225
|
+
TAccountRentSysvar,
|
|
226
|
+
TAccountSourceMetadata,
|
|
227
|
+
TAccountOwnerProgram
|
|
228
|
+
>);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export type ParsedSyncMetadataToSplTokenInstruction<
|
|
232
|
+
TProgram extends string = typeof TOKEN_WRAP_PROGRAM_ADDRESS,
|
|
233
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
234
|
+
> = {
|
|
235
|
+
programAddress: Address<TProgram>;
|
|
236
|
+
accounts: {
|
|
237
|
+
/** `Metaplex` metadata account */
|
|
238
|
+
metaplexMetadata: TAccountMetas[0];
|
|
239
|
+
/** Wrapped mint authority (PDA) */
|
|
240
|
+
wrappedMintAuthority: TAccountMetas[1];
|
|
241
|
+
/** Wrapped SPL Token mint */
|
|
242
|
+
wrappedMint: TAccountMetas[2];
|
|
243
|
+
/** Unwrapped mint */
|
|
244
|
+
unwrappedMint: TAccountMetas[3];
|
|
245
|
+
/** `Metaplex` Token Metadata Program */
|
|
246
|
+
metaplexProgram: TAccountMetas[4];
|
|
247
|
+
/** System program */
|
|
248
|
+
systemProgram: TAccountMetas[5];
|
|
249
|
+
/** Rent sysvar */
|
|
250
|
+
rentSysvar: TAccountMetas[6];
|
|
251
|
+
/**
|
|
252
|
+
* Source metadata account. Required if unwrapped mint
|
|
253
|
+
* is an SPL-Token or, if a Token-2022, its metadata pointer indicates
|
|
254
|
+
* an external account.
|
|
255
|
+
*/
|
|
256
|
+
sourceMetadata?: TAccountMetas[7] | undefined;
|
|
257
|
+
/**
|
|
258
|
+
* Owner program. Required when metadata account is
|
|
259
|
+
* owned by a third-party program.
|
|
260
|
+
*/
|
|
261
|
+
ownerProgram?: TAccountMetas[8] | undefined;
|
|
262
|
+
};
|
|
263
|
+
data: SyncMetadataToSplTokenInstructionData;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export function parseSyncMetadataToSplTokenInstruction<
|
|
267
|
+
TProgram extends string,
|
|
268
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
269
|
+
>(
|
|
270
|
+
instruction: Instruction<TProgram> &
|
|
271
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
272
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
273
|
+
): ParsedSyncMetadataToSplTokenInstruction<TProgram, TAccountMetas> {
|
|
274
|
+
if (instruction.accounts.length < 9) {
|
|
275
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
|
|
276
|
+
actualAccountMetas: instruction.accounts.length,
|
|
277
|
+
expectedAccountMetas: 9,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
let accountIndex = 0;
|
|
281
|
+
const getNextAccount = () => {
|
|
282
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
283
|
+
accountIndex += 1;
|
|
284
|
+
return accountMeta;
|
|
285
|
+
};
|
|
286
|
+
const getNextOptionalAccount = () => {
|
|
287
|
+
const accountMeta = getNextAccount();
|
|
288
|
+
return accountMeta.address === TOKEN_WRAP_PROGRAM_ADDRESS ? undefined : accountMeta;
|
|
289
|
+
};
|
|
290
|
+
return {
|
|
291
|
+
programAddress: instruction.programAddress,
|
|
292
|
+
accounts: {
|
|
293
|
+
metaplexMetadata: getNextAccount(),
|
|
294
|
+
wrappedMintAuthority: getNextAccount(),
|
|
295
|
+
wrappedMint: getNextAccount(),
|
|
296
|
+
unwrappedMint: getNextAccount(),
|
|
297
|
+
metaplexProgram: getNextAccount(),
|
|
298
|
+
systemProgram: getNextAccount(),
|
|
299
|
+
rentSysvar: getNextAccount(),
|
|
300
|
+
sourceMetadata: getNextOptionalAccount(),
|
|
301
|
+
ownerProgram: getNextOptionalAccount(),
|
|
302
|
+
},
|
|
303
|
+
data: getSyncMetadataToSplTokenInstructionDataDecoder().decode(instruction.data),
|
|
304
|
+
};
|
|
305
|
+
}
|