Skip to content

Commit 9f9e0cb

Browse files
authored
Merge pull request #52 from macalinao/igm/fix-vsr
Add discriminators for SPL Governance
2 parents edbbff9 + ef2b16c commit 9f9e0cb

23 files changed

+845
-306
lines changed

.changeset/true-rules-kneel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@macalinao/clients-spl-governance": patch
3+
---
4+
5+
Add discriminators for SPL governance account types

clients/spl-governance/coda.config.mjs

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import {
33
addPdasVisitor,
44
constantPdaSeedNodeFromString,
55
defineConfig,
6+
definedTypeLinkNode,
7+
enumValueNode,
68
numberTypeNode,
79
pdaLinkNode,
810
pdaSeedValueNode,
911
pdaValueNode,
1012
publicKeyTypeNode,
1113
SYSTEM_PROGRAM_VALUE_NODE,
14+
setAccountDiscriminatorFromFieldVisitor,
1215
setInstructionAccountDefaultValuesVisitor,
1316
stringTypeNode,
1417
updateAccountsVisitor,
@@ -258,6 +261,154 @@ export default defineConfig({
258261
]),
259262
},
260263
]),
264+
setAccountDiscriminatorFromFieldVisitor({
265+
// Realm accounts
266+
realmV1: {
267+
field: "accountType",
268+
value: enumValueNode(
269+
definedTypeLinkNode("governanceAccountType"),
270+
"RealmV1",
271+
),
272+
},
273+
realmV2: {
274+
field: "accountType",
275+
value: enumValueNode(
276+
definedTypeLinkNode("governanceAccountType"),
277+
"RealmV2",
278+
),
279+
},
280+
realmConfigAccount: {
281+
field: "accountType",
282+
value: enumValueNode(
283+
definedTypeLinkNode("governanceAccountType"),
284+
"RealmConfig",
285+
),
286+
},
287+
288+
// Governance accounts
289+
governanceV1: {
290+
field: "accountType",
291+
value: enumValueNode(
292+
definedTypeLinkNode("governanceAccountType"),
293+
"GovernanceV1",
294+
),
295+
},
296+
governanceV2: {
297+
field: "accountType",
298+
value: enumValueNode(
299+
definedTypeLinkNode("governanceAccountType"),
300+
"GovernanceV2",
301+
),
302+
},
303+
304+
// Token Owner Record accounts
305+
tokenOwnerRecordV1: {
306+
field: "accountType",
307+
value: enumValueNode(
308+
definedTypeLinkNode("governanceAccountType"),
309+
"TokenOwnerRecordV1",
310+
),
311+
},
312+
tokenOwnerRecordV2: {
313+
field: "accountType",
314+
value: enumValueNode(
315+
definedTypeLinkNode("governanceAccountType"),
316+
"TokenOwnerRecordV2",
317+
),
318+
},
319+
legacyTokenOwnerRecord: {
320+
field: "accountType",
321+
value: enumValueNode(
322+
definedTypeLinkNode("governanceAccountType"),
323+
"TokenOwnerRecordV1",
324+
),
325+
},
326+
327+
// Proposal accounts
328+
proposalV1: {
329+
field: "accountType",
330+
value: enumValueNode(
331+
definedTypeLinkNode("governanceAccountType"),
332+
"ProposalV1",
333+
),
334+
},
335+
proposalV2: {
336+
field: "accountType",
337+
value: enumValueNode(
338+
definedTypeLinkNode("governanceAccountType"),
339+
"ProposalV2",
340+
),
341+
},
342+
proposalDeposit: {
343+
field: "accountType",
344+
value: enumValueNode(
345+
definedTypeLinkNode("governanceAccountType"),
346+
"ProposalDeposit",
347+
),
348+
},
349+
proposalInstructionV1: {
350+
field: "accountType",
351+
value: enumValueNode(
352+
definedTypeLinkNode("governanceAccountType"),
353+
"ProposalInstructionV1",
354+
),
355+
},
356+
proposalTransactionV2: {
357+
field: "accountType",
358+
value: enumValueNode(
359+
definedTypeLinkNode("governanceAccountType"),
360+
"ProposalTransactionV2",
361+
),
362+
},
363+
364+
// Signatory Record accounts
365+
signatoryRecordV1: {
366+
field: "accountType",
367+
value: enumValueNode(
368+
definedTypeLinkNode("governanceAccountType"),
369+
"SignatoryRecordV1",
370+
),
371+
},
372+
signatoryRecordV2: {
373+
field: "accountType",
374+
value: enumValueNode(
375+
definedTypeLinkNode("governanceAccountType"),
376+
"SignatoryRecordV2",
377+
),
378+
},
379+
requiredSignatory: {
380+
field: "accountType",
381+
value: enumValueNode(
382+
definedTypeLinkNode("governanceAccountType"),
383+
"RequiredSignatory",
384+
),
385+
},
386+
387+
// Vote Record accounts
388+
voteRecordV1: {
389+
field: "accountType",
390+
value: enumValueNode(
391+
definedTypeLinkNode("governanceAccountType"),
392+
"VoteRecordV1",
393+
),
394+
},
395+
voteRecordV2: {
396+
field: "accountType",
397+
value: enumValueNode(
398+
definedTypeLinkNode("governanceAccountType"),
399+
"VoteRecordV2",
400+
),
401+
},
402+
403+
// Program Metadata
404+
programMetadata: {
405+
field: "accountType",
406+
value: enumValueNode(
407+
definedTypeLinkNode("governanceAccountType"),
408+
"ProgramMetadata",
409+
),
410+
},
411+
}),
261412
addCustomPDAsVisitor,
262413
],
263414
});

clients/spl-governance/src/generated/accounts/governanceV1.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ import type {
1919
MaybeEncodedAccount,
2020
} from "@solana/kit";
2121
import type { GovernanceSeeds } from "../pdas/index.js";
22-
import type {
23-
GovernanceAccountType,
24-
GovernanceAccountTypeArgs,
25-
GovernanceConfig,
26-
GovernanceConfigArgs,
27-
} from "../types/index.js";
22+
import type { GovernanceConfig, GovernanceConfigArgs } from "../types/index.js";
2823
import {
2924
assertAccountExists,
3025
assertAccountsExist,
@@ -38,15 +33,23 @@ import {
3833
getStructEncoder,
3934
getU32Decoder,
4035
getU32Encoder,
36+
transformEncoder,
4137
} from "@solana/kit";
4238
import { findGovernancePda } from "../pdas/index.js";
4339
import {
40+
GovernanceAccountType,
4441
getGovernanceAccountTypeDecoder,
4542
getGovernanceAccountTypeEncoder,
4643
getGovernanceConfigDecoder,
4744
getGovernanceConfigEncoder,
4845
} from "../types/index.js";
4946

47+
export const GOVERNANCE_V1_ACCOUNT_TYPE = GovernanceAccountType.GovernanceV1;
48+
49+
export function getGovernanceV1AccountTypeBytes() {
50+
return getGovernanceAccountTypeEncoder().encode(GOVERNANCE_V1_ACCOUNT_TYPE);
51+
}
52+
5053
export interface GovernanceV1 {
5154
accountType: GovernanceAccountType;
5255
realm: Address;
@@ -56,21 +59,23 @@ export interface GovernanceV1 {
5659
}
5760

5861
export interface GovernanceV1Args {
59-
accountType: GovernanceAccountTypeArgs;
6062
realm: Address;
6163
governedAccount: Address;
6264
proposalsCount: number;
6365
config: GovernanceConfigArgs;
6466
}
6567

6668
export function getGovernanceV1Encoder(): Encoder<GovernanceV1Args> {
67-
return getStructEncoder([
68-
["accountType", getGovernanceAccountTypeEncoder()],
69-
["realm", getAddressEncoder()],
70-
["governedAccount", getAddressEncoder()],
71-
["proposalsCount", getU32Encoder()],
72-
["config", getGovernanceConfigEncoder()],
73-
]);
69+
return transformEncoder(
70+
getStructEncoder([
71+
["accountType", getGovernanceAccountTypeEncoder()],
72+
["realm", getAddressEncoder()],
73+
["governedAccount", getAddressEncoder()],
74+
["proposalsCount", getU32Encoder()],
75+
["config", getGovernanceConfigEncoder()],
76+
]),
77+
(value) => ({ ...value, accountType: GOVERNANCE_V1_ACCOUNT_TYPE }),
78+
);
7479
}
7580

7681
export function getGovernanceV1Decoder(): Decoder<GovernanceV1> {

clients/spl-governance/src/generated/accounts/governanceV2.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import type {
2020
} from "@solana/kit";
2121
import type { GovernanceSeeds } from "../pdas/index.js";
2222
import type {
23-
GovernanceAccountType,
24-
GovernanceAccountTypeArgs,
2523
GovernanceConfig,
2624
GovernanceConfigArgs,
2725
Reserved119,
@@ -44,9 +42,11 @@ import {
4442
getU32Encoder,
4543
getU64Decoder,
4644
getU64Encoder,
45+
transformEncoder,
4746
} from "@solana/kit";
4847
import { findGovernancePda } from "../pdas/index.js";
4948
import {
49+
GovernanceAccountType,
5050
getGovernanceAccountTypeDecoder,
5151
getGovernanceAccountTypeEncoder,
5252
getGovernanceConfigDecoder,
@@ -55,6 +55,12 @@ import {
5555
getReserved119Encoder,
5656
} from "../types/index.js";
5757

58+
export const GOVERNANCE_V2_ACCOUNT_TYPE = GovernanceAccountType.GovernanceV2;
59+
60+
export function getGovernanceV2AccountTypeBytes() {
61+
return getGovernanceAccountTypeEncoder().encode(GOVERNANCE_V2_ACCOUNT_TYPE);
62+
}
63+
5864
export interface GovernanceV2 {
5965
accountType: GovernanceAccountType;
6066
realm: Address;
@@ -67,7 +73,6 @@ export interface GovernanceV2 {
6773
}
6874

6975
export interface GovernanceV2Args {
70-
accountType: GovernanceAccountTypeArgs;
7176
realm: Address;
7277
governedAccount: Address;
7378
reserved1: number;
@@ -78,16 +83,19 @@ export interface GovernanceV2Args {
7883
}
7984

8085
export function getGovernanceV2Encoder(): Encoder<GovernanceV2Args> {
81-
return getStructEncoder([
82-
["accountType", getGovernanceAccountTypeEncoder()],
83-
["realm", getAddressEncoder()],
84-
["governedAccount", getAddressEncoder()],
85-
["reserved1", getU32Encoder()],
86-
["config", getGovernanceConfigEncoder()],
87-
["reservedV2", getReserved119Encoder()],
88-
["requiredSignatoriesCount", getU8Encoder()],
89-
["activeProposalCount", getU64Encoder()],
90-
]);
86+
return transformEncoder(
87+
getStructEncoder([
88+
["accountType", getGovernanceAccountTypeEncoder()],
89+
["realm", getAddressEncoder()],
90+
["governedAccount", getAddressEncoder()],
91+
["reserved1", getU32Encoder()],
92+
["config", getGovernanceConfigEncoder()],
93+
["reservedV2", getReserved119Encoder()],
94+
["requiredSignatoriesCount", getU8Encoder()],
95+
["activeProposalCount", getU64Encoder()],
96+
]),
97+
(value) => ({ ...value, accountType: GOVERNANCE_V2_ACCOUNT_TYPE }),
98+
);
9199
}
92100

93101
export function getGovernanceV2Decoder(): Decoder<GovernanceV2> {

0 commit comments

Comments
 (0)