Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/true-rules-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@macalinao/clients-spl-governance": patch
---

Add discriminators for SPL governance account types
151 changes: 151 additions & 0 deletions clients/spl-governance/coda.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import {
addPdasVisitor,
constantPdaSeedNodeFromString,
defineConfig,
definedTypeLinkNode,
enumValueNode,
numberTypeNode,
pdaLinkNode,
pdaSeedValueNode,
pdaValueNode,
publicKeyTypeNode,
SYSTEM_PROGRAM_VALUE_NODE,
setAccountDiscriminatorFromFieldVisitor,
setInstructionAccountDefaultValuesVisitor,
stringTypeNode,
updateAccountsVisitor,
Expand Down Expand Up @@ -258,6 +261,154 @@ export default defineConfig({
]),
},
]),
setAccountDiscriminatorFromFieldVisitor({
// Realm accounts
realmV1: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"RealmV1",
),
},
realmV2: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"RealmV2",
),
},
realmConfigAccount: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"RealmConfig",
),
},

// Governance accounts
governanceV1: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"GovernanceV1",
),
},
governanceV2: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"GovernanceV2",
),
},

// Token Owner Record accounts
tokenOwnerRecordV1: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"TokenOwnerRecordV1",
),
},
tokenOwnerRecordV2: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"TokenOwnerRecordV2",
),
},
legacyTokenOwnerRecord: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"TokenOwnerRecordV1",
),
},

// Proposal accounts
proposalV1: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"ProposalV1",
),
},
proposalV2: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"ProposalV2",
),
},
proposalDeposit: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"ProposalDeposit",
),
},
proposalInstructionV1: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"ProposalInstructionV1",
),
},
proposalTransactionV2: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"ProposalTransactionV2",
),
},

// Signatory Record accounts
signatoryRecordV1: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"SignatoryRecordV1",
),
},
signatoryRecordV2: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"SignatoryRecordV2",
),
},
requiredSignatory: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"RequiredSignatory",
),
},

// Vote Record accounts
voteRecordV1: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"VoteRecordV1",
),
},
voteRecordV2: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"VoteRecordV2",
),
},

// Program Metadata
programMetadata: {
field: "accountType",
value: enumValueNode(
definedTypeLinkNode("governanceAccountType"),
"ProgramMetadata",
),
},
}),
addCustomPDAsVisitor,
],
});
33 changes: 19 additions & 14 deletions clients/spl-governance/src/generated/accounts/governanceV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ import type {
MaybeEncodedAccount,
} from "@solana/kit";
import type { GovernanceSeeds } from "../pdas/index.js";
import type {
GovernanceAccountType,
GovernanceAccountTypeArgs,
GovernanceConfig,
GovernanceConfigArgs,
} from "../types/index.js";
import type { GovernanceConfig, GovernanceConfigArgs } from "../types/index.js";
import {
assertAccountExists,
assertAccountsExist,
Expand All @@ -38,15 +33,23 @@ import {
getStructEncoder,
getU32Decoder,
getU32Encoder,
transformEncoder,
} from "@solana/kit";
import { findGovernancePda } from "../pdas/index.js";
import {
GovernanceAccountType,
getGovernanceAccountTypeDecoder,
getGovernanceAccountTypeEncoder,
getGovernanceConfigDecoder,
getGovernanceConfigEncoder,
} from "../types/index.js";

export const GOVERNANCE_V1_ACCOUNT_TYPE = GovernanceAccountType.GovernanceV1;

export function getGovernanceV1AccountTypeBytes() {
return getGovernanceAccountTypeEncoder().encode(GOVERNANCE_V1_ACCOUNT_TYPE);
}

export interface GovernanceV1 {
accountType: GovernanceAccountType;
realm: Address;
Expand All @@ -56,21 +59,23 @@ export interface GovernanceV1 {
}

export interface GovernanceV1Args {
accountType: GovernanceAccountTypeArgs;
realm: Address;
governedAccount: Address;
proposalsCount: number;
config: GovernanceConfigArgs;
}

export function getGovernanceV1Encoder(): Encoder<GovernanceV1Args> {
return getStructEncoder([
["accountType", getGovernanceAccountTypeEncoder()],
["realm", getAddressEncoder()],
["governedAccount", getAddressEncoder()],
["proposalsCount", getU32Encoder()],
["config", getGovernanceConfigEncoder()],
]);
return transformEncoder(
getStructEncoder([
["accountType", getGovernanceAccountTypeEncoder()],
["realm", getAddressEncoder()],
["governedAccount", getAddressEncoder()],
["proposalsCount", getU32Encoder()],
["config", getGovernanceConfigEncoder()],
]),
(value) => ({ ...value, accountType: GOVERNANCE_V1_ACCOUNT_TYPE }),
);
}

export function getGovernanceV1Decoder(): Decoder<GovernanceV1> {
Expand Down
34 changes: 21 additions & 13 deletions clients/spl-governance/src/generated/accounts/governanceV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import type {
} from "@solana/kit";
import type { GovernanceSeeds } from "../pdas/index.js";
import type {
GovernanceAccountType,
GovernanceAccountTypeArgs,
GovernanceConfig,
GovernanceConfigArgs,
Reserved119,
Expand All @@ -44,9 +42,11 @@ import {
getU32Encoder,
getU64Decoder,
getU64Encoder,
transformEncoder,
} from "@solana/kit";
import { findGovernancePda } from "../pdas/index.js";
import {
GovernanceAccountType,
getGovernanceAccountTypeDecoder,
getGovernanceAccountTypeEncoder,
getGovernanceConfigDecoder,
Expand All @@ -55,6 +55,12 @@ import {
getReserved119Encoder,
} from "../types/index.js";

export const GOVERNANCE_V2_ACCOUNT_TYPE = GovernanceAccountType.GovernanceV2;

export function getGovernanceV2AccountTypeBytes() {
return getGovernanceAccountTypeEncoder().encode(GOVERNANCE_V2_ACCOUNT_TYPE);
}

export interface GovernanceV2 {
accountType: GovernanceAccountType;
realm: Address;
Expand All @@ -67,7 +73,6 @@ export interface GovernanceV2 {
}

export interface GovernanceV2Args {
accountType: GovernanceAccountTypeArgs;
realm: Address;
governedAccount: Address;
reserved1: number;
Expand All @@ -78,16 +83,19 @@ export interface GovernanceV2Args {
}

export function getGovernanceV2Encoder(): Encoder<GovernanceV2Args> {
return getStructEncoder([
["accountType", getGovernanceAccountTypeEncoder()],
["realm", getAddressEncoder()],
["governedAccount", getAddressEncoder()],
["reserved1", getU32Encoder()],
["config", getGovernanceConfigEncoder()],
["reservedV2", getReserved119Encoder()],
["requiredSignatoriesCount", getU8Encoder()],
["activeProposalCount", getU64Encoder()],
]);
return transformEncoder(
getStructEncoder([
["accountType", getGovernanceAccountTypeEncoder()],
["realm", getAddressEncoder()],
["governedAccount", getAddressEncoder()],
["reserved1", getU32Encoder()],
["config", getGovernanceConfigEncoder()],
["reservedV2", getReserved119Encoder()],
["requiredSignatoriesCount", getU8Encoder()],
["activeProposalCount", getU64Encoder()],
]),
(value) => ({ ...value, accountType: GOVERNANCE_V2_ACCOUNT_TYPE }),
);
}

export function getGovernanceV2Decoder(): Decoder<GovernanceV2> {
Expand Down
Loading
Loading