Skip to content

Commit 88ade33

Browse files
committed
sdk: fix lut casing
1 parent b928c39 commit 88ade33

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

solana/scripts/regenerateIdl.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ const idl: Idl = JSON.parse(fs.readFileSync(jsonPath, "utf8"));
2020
const name = titleCase(idl["name"]);
2121

2222
idl.accounts?.forEach((account) => {
23-
account.name = account.name.replace(/^[A-Z]+/, (match) =>
24-
match.toLowerCase()
25-
);
23+
// NOTE: here we translate PascalCase to camelCase, with the exception of all
24+
// uppercase account names, such as 'LUT', which we want to preserve.
25+
//
26+
// The translation needs to be done because anchor generates an invalid IDL file, so we patch it.
27+
// Anchor handles all uppercase account names specially (when generating the account discriminator),
28+
// so we need to preserve them.
29+
if (!account.name.match(/^[A-Z]+$/)) {
30+
account.name = account.name.replace(/^[A-Z]+/, (match) =>
31+
match.toLowerCase()
32+
);
33+
}
2634
});
2735

2836
// heredoc

solana/ts/idl/2_0_0/ts/example_native_token_transfers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ export type ExampleNativeTokenTransfers = {
12461246
}
12471247
},
12481248
{
1249-
"name": "lut",
1249+
"name": "LUT",
12501250
"type": {
12511251
"kind": "struct",
12521252
"fields": [
@@ -3178,7 +3178,7 @@ export const IDL: ExampleNativeTokenTransfers = {
31783178
}
31793179
},
31803180
{
3181-
"name": "lut",
3181+
"name": "LUT",
31823182
"type": {
31833183
"kind": "struct",
31843184
"fields": [

solana/ts/lib/ntt.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,10 @@ export namespace NTT {
10481048
if (major < 2) return null;
10491049

10501050
pdas = pdas ?? NTT.pdas(program.programId);
1051+
// @ts-ignore
1052+
// NOTE: lut is 'LUT' in the IDL, but 'lut' in the generated code
1053+
// It needs to be upper-cased in the IDL to compute the anchor
1054+
// account discriminator correctly
10511055
const lut = await program.account.lut.fetchNullable(pdas.lutAccount());
10521056
if (!lut) return null;
10531057

0 commit comments

Comments
 (0)