Skip to content

Commit 7fc38db

Browse files
authored
Add ATA Instruction discriminators in e2e tests (#33)
This only affects the tests so no changeset is needed.
1 parent e0ea30c commit 7fc38db

File tree

7 files changed

+356
-7
lines changed

7 files changed

+356
-7
lines changed

packages/renderers-js/e2e/token/idl.json

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,27 @@
23842384
}
23852385
}
23862386
],
2387-
"arguments": [],
2387+
"arguments": [
2388+
{
2389+
"kind": "instructionArgumentNode",
2390+
"name": "discriminator",
2391+
"type": {
2392+
"kind": "numberTypeNode",
2393+
"format": "u8",
2394+
"endian": "le"
2395+
},
2396+
"docs": [],
2397+
"defaultValue": { "kind": "numberValueNode", "number": 0 },
2398+
"defaultValueStrategy": "omitted"
2399+
}
2400+
],
2401+
"discriminators": [
2402+
{
2403+
"kind": "fieldDiscriminatorNode",
2404+
"name": "discriminator",
2405+
"offset": 0
2406+
}
2407+
],
23882408
"name": "createAssociatedToken",
23892409
"docs": [
23902410
"Creates an associated token account for the given wallet address and",
@@ -2486,7 +2506,27 @@
24862506
}
24872507
}
24882508
],
2489-
"arguments": [],
2509+
"arguments": [
2510+
{
2511+
"kind": "instructionArgumentNode",
2512+
"name": "discriminator",
2513+
"type": {
2514+
"kind": "numberTypeNode",
2515+
"format": "u8",
2516+
"endian": "le"
2517+
},
2518+
"docs": [],
2519+
"defaultValue": { "kind": "numberValueNode", "number": 1 },
2520+
"defaultValueStrategy": "omitted"
2521+
}
2522+
],
2523+
"discriminators": [
2524+
{
2525+
"kind": "fieldDiscriminatorNode",
2526+
"name": "discriminator",
2527+
"offset": 0
2528+
}
2529+
],
24902530
"name": "createAssociatedTokenIdempotent",
24912531
"docs": [
24922532
"Creates an associated token account for the given wallet address and",
@@ -2662,7 +2702,27 @@
26622702
}
26632703
}
26642704
],
2665-
"arguments": [],
2705+
"arguments": [
2706+
{
2707+
"kind": "instructionArgumentNode",
2708+
"name": "discriminator",
2709+
"type": {
2710+
"kind": "numberTypeNode",
2711+
"format": "u8",
2712+
"endian": "le"
2713+
},
2714+
"docs": [],
2715+
"defaultValue": { "kind": "numberValueNode", "number": 2 },
2716+
"defaultValueStrategy": "omitted"
2717+
}
2718+
],
2719+
"discriminators": [
2720+
{
2721+
"kind": "fieldDiscriminatorNode",
2722+
"name": "discriminator",
2723+
"offset": 0
2724+
}
2725+
],
26662726
"name": "recoverNestedAssociatedToken",
26672727
"docs": [
26682728
"Transfers from and closes a nested associated token account: an",

packages/renderers-js/e2e/token/src/generated/instructions/createAssociatedToken.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@
88

99
import {
1010
Address,
11+
Codec,
12+
Decoder,
13+
Encoder,
1114
IAccountMeta,
1215
IAccountSignerMeta,
1316
IInstruction,
1417
IInstructionWithAccounts,
18+
IInstructionWithData,
1519
ReadonlyAccount,
1620
TransactionSigner,
1721
WritableAccount,
1822
WritableSignerAccount,
23+
combineCodec,
24+
getStructDecoder,
25+
getStructEncoder,
26+
getU8Decoder,
27+
getU8Encoder,
28+
transformEncoder,
1929
} from '@solana/web3.js';
2030
import { findAssociatedTokenPda } from '../pdas';
2131
import { ASSOCIATED_TOKEN_PROGRAM_ADDRESS } from '../programs';
@@ -39,6 +49,7 @@ export type CreateAssociatedTokenInstruction<
3949
| IAccountMeta<string> = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
4050
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
4151
> = IInstruction<TProgram> &
52+
IInstructionWithData<Uint8Array> &
4253
IInstructionWithAccounts<
4354
[
4455
TAccountPayer extends string
@@ -62,6 +73,31 @@ export type CreateAssociatedTokenInstruction<
6273
]
6374
>;
6475

76+
export type CreateAssociatedTokenInstructionData = { discriminator: number };
77+
78+
export type CreateAssociatedTokenInstructionDataArgs = {};
79+
80+
export function getCreateAssociatedTokenInstructionDataEncoder(): Encoder<CreateAssociatedTokenInstructionDataArgs> {
81+
return transformEncoder(
82+
getStructEncoder([['discriminator', getU8Encoder()]]),
83+
(value) => ({ ...value, discriminator: 0 })
84+
);
85+
}
86+
87+
export function getCreateAssociatedTokenInstructionDataDecoder(): Decoder<CreateAssociatedTokenInstructionData> {
88+
return getStructDecoder([['discriminator', getU8Decoder()]]);
89+
}
90+
91+
export function getCreateAssociatedTokenInstructionDataCodec(): Codec<
92+
CreateAssociatedTokenInstructionDataArgs,
93+
CreateAssociatedTokenInstructionData
94+
> {
95+
return combineCodec(
96+
getCreateAssociatedTokenInstructionDataEncoder(),
97+
getCreateAssociatedTokenInstructionDataDecoder()
98+
);
99+
}
100+
65101
export type CreateAssociatedTokenAsyncInput<
66102
TAccountPayer extends string = string,
67103
TAccountAta extends string = string,
@@ -156,6 +192,7 @@ export async function getCreateAssociatedTokenInstructionAsync<
156192
getAccountMeta(accounts.tokenProgram),
157193
],
158194
programAddress,
195+
data: getCreateAssociatedTokenInstructionDataEncoder().encode({}),
159196
} as CreateAssociatedTokenInstruction<
160197
typeof ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
161198
TAccountPayer,
@@ -254,6 +291,7 @@ export function getCreateAssociatedTokenInstruction<
254291
getAccountMeta(accounts.tokenProgram),
255292
],
256293
programAddress,
294+
data: getCreateAssociatedTokenInstructionDataEncoder().encode({}),
257295
} as CreateAssociatedTokenInstruction<
258296
typeof ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
259297
TAccountPayer,
@@ -286,13 +324,16 @@ export type ParsedCreateAssociatedTokenInstruction<
286324
/** SPL Token program. */
287325
tokenProgram: TAccountMetas[5];
288326
};
327+
data: CreateAssociatedTokenInstructionData;
289328
};
290329

291330
export function parseCreateAssociatedTokenInstruction<
292331
TProgram extends string,
293332
TAccountMetas extends readonly IAccountMeta[],
294333
>(
295-
instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas>
334+
instruction: IInstruction<TProgram> &
335+
IInstructionWithAccounts<TAccountMetas> &
336+
IInstructionWithData<Uint8Array>
296337
): ParsedCreateAssociatedTokenInstruction<TProgram, TAccountMetas> {
297338
if (instruction.accounts.length < 6) {
298339
// TODO: Coded error.
@@ -314,5 +355,8 @@ export function parseCreateAssociatedTokenInstruction<
314355
systemProgram: getNextAccount(),
315356
tokenProgram: getNextAccount(),
316357
},
358+
data: getCreateAssociatedTokenInstructionDataDecoder().decode(
359+
instruction.data
360+
),
317361
};
318362
}

packages/renderers-js/e2e/token/src/generated/instructions/createAssociatedTokenIdempotent.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@
88

99
import {
1010
Address,
11+
Codec,
12+
Decoder,
13+
Encoder,
1114
IAccountMeta,
1215
IAccountSignerMeta,
1316
IInstruction,
1417
IInstructionWithAccounts,
18+
IInstructionWithData,
1519
ReadonlyAccount,
1620
TransactionSigner,
1721
WritableAccount,
1822
WritableSignerAccount,
23+
combineCodec,
24+
getStructDecoder,
25+
getStructEncoder,
26+
getU8Decoder,
27+
getU8Encoder,
28+
transformEncoder,
1929
} from '@solana/web3.js';
2030
import { findAssociatedTokenPda } from '../pdas';
2131
import { ASSOCIATED_TOKEN_PROGRAM_ADDRESS } from '../programs';
@@ -39,6 +49,7 @@ export type CreateAssociatedTokenIdempotentInstruction<
3949
| IAccountMeta<string> = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
4050
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
4151
> = IInstruction<TProgram> &
52+
IInstructionWithData<Uint8Array> &
4253
IInstructionWithAccounts<
4354
[
4455
TAccountPayer extends string
@@ -62,6 +73,33 @@ export type CreateAssociatedTokenIdempotentInstruction<
6273
]
6374
>;
6475

76+
export type CreateAssociatedTokenIdempotentInstructionData = {
77+
discriminator: number;
78+
};
79+
80+
export type CreateAssociatedTokenIdempotentInstructionDataArgs = {};
81+
82+
export function getCreateAssociatedTokenIdempotentInstructionDataEncoder(): Encoder<CreateAssociatedTokenIdempotentInstructionDataArgs> {
83+
return transformEncoder(
84+
getStructEncoder([['discriminator', getU8Encoder()]]),
85+
(value) => ({ ...value, discriminator: 1 })
86+
);
87+
}
88+
89+
export function getCreateAssociatedTokenIdempotentInstructionDataDecoder(): Decoder<CreateAssociatedTokenIdempotentInstructionData> {
90+
return getStructDecoder([['discriminator', getU8Decoder()]]);
91+
}
92+
93+
export function getCreateAssociatedTokenIdempotentInstructionDataCodec(): Codec<
94+
CreateAssociatedTokenIdempotentInstructionDataArgs,
95+
CreateAssociatedTokenIdempotentInstructionData
96+
> {
97+
return combineCodec(
98+
getCreateAssociatedTokenIdempotentInstructionDataEncoder(),
99+
getCreateAssociatedTokenIdempotentInstructionDataDecoder()
100+
);
101+
}
102+
65103
export type CreateAssociatedTokenIdempotentAsyncInput<
66104
TAccountPayer extends string = string,
67105
TAccountAta extends string = string,
@@ -156,6 +194,7 @@ export async function getCreateAssociatedTokenIdempotentInstructionAsync<
156194
getAccountMeta(accounts.tokenProgram),
157195
],
158196
programAddress,
197+
data: getCreateAssociatedTokenIdempotentInstructionDataEncoder().encode({}),
159198
} as CreateAssociatedTokenIdempotentInstruction<
160199
typeof ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
161200
TAccountPayer,
@@ -254,6 +293,7 @@ export function getCreateAssociatedTokenIdempotentInstruction<
254293
getAccountMeta(accounts.tokenProgram),
255294
],
256295
programAddress,
296+
data: getCreateAssociatedTokenIdempotentInstructionDataEncoder().encode({}),
257297
} as CreateAssociatedTokenIdempotentInstruction<
258298
typeof ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
259299
TAccountPayer,
@@ -286,13 +326,16 @@ export type ParsedCreateAssociatedTokenIdempotentInstruction<
286326
/** SPL Token program. */
287327
tokenProgram: TAccountMetas[5];
288328
};
329+
data: CreateAssociatedTokenIdempotentInstructionData;
289330
};
290331

291332
export function parseCreateAssociatedTokenIdempotentInstruction<
292333
TProgram extends string,
293334
TAccountMetas extends readonly IAccountMeta[],
294335
>(
295-
instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas>
336+
instruction: IInstruction<TProgram> &
337+
IInstructionWithAccounts<TAccountMetas> &
338+
IInstructionWithData<Uint8Array>
296339
): ParsedCreateAssociatedTokenIdempotentInstruction<TProgram, TAccountMetas> {
297340
if (instruction.accounts.length < 6) {
298341
// TODO: Coded error.
@@ -314,5 +357,8 @@ export function parseCreateAssociatedTokenIdempotentInstruction<
314357
systemProgram: getNextAccount(),
315358
tokenProgram: getNextAccount(),
316359
},
360+
data: getCreateAssociatedTokenIdempotentInstructionDataDecoder().decode(
361+
instruction.data
362+
),
317363
};
318364
}

0 commit comments

Comments
 (0)