Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 970f1d5

Browse files
authored
Governance: Rename governed_account to governance_seed (#6346)
* chore: Rename governed_account to governance_seed * chore: Make governance_seed mandatory for create_governance * chore: Rename governed_account to governance_seed for V1 account * chore: Fix governance chat build * chore: Rename governed_account to governance_seed
1 parent 3525210 commit 970f1d5

File tree

7 files changed

+53
-69
lines changed

7 files changed

+53
-69
lines changed

governance/chat/program/tests/program_test/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl GovernanceChatProgramTest {
183183
}
184184

185185
// Create Governance
186-
let governed_account_address = Pubkey::new_unique();
186+
let governance_seed = Pubkey::new_unique();
187187

188188
let governance_config = GovernanceConfig {
189189
community_vote_threshold: VoteThreshold::YesVotePercentage(60),
@@ -235,7 +235,7 @@ impl GovernanceChatProgramTest {
235235
let create_governance_ix = create_governance(
236236
&self.governance_program_id,
237237
&realm_address,
238-
Some(&governed_account_address),
238+
&governance_seed,
239239
&token_owner_record_address,
240240
&self.bench.payer.pubkey(),
241241
&token_owner.pubkey(),
@@ -253,7 +253,7 @@ impl GovernanceChatProgramTest {
253253
let governance_address = get_governance_address(
254254
&self.governance_program_id,
255255
&realm_address,
256-
&governed_account_address,
256+
&governance_seed,
257257
);
258258

259259
let proposal_name = "Proposal #1".to_string();

governance/program/src/instruction.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,8 @@ pub enum GovernanceInstruction {
140140
///
141141
/// 0. `[]` Realm account the created Governance belongs to
142142
/// 1. `[writable]` Governance account
143-
/// * PDA seeds: ['account-governance', realm, governed_account]
144-
/// 2. `[]` Account governed by this Governance Note: The account doesn't
145-
/// have to exist and can be only used as a unique identifier for the
146-
/// Governance account
143+
/// * PDA seeds: ['account-governance', realm, governance_seed]
144+
/// 2. `[]` Governance account PDA seed
147145
/// 3. `[]` Governing TokenOwnerRecord account (Used only if not signed by
148146
/// RealmAuthority)
149147
/// 4. `[signer]` Payer
@@ -831,28 +829,20 @@ pub fn create_governance(
831829
program_id: &Pubkey,
832830
// Accounts
833831
realm: &Pubkey,
834-
governed_account: Option<&Pubkey>,
832+
governance_seed: &Pubkey,
835833
token_owner_record: &Pubkey,
836834
payer: &Pubkey,
837835
create_authority: &Pubkey,
838836
voter_weight_record: Option<Pubkey>,
839837
// Args
840838
config: GovernanceConfig,
841839
) -> Instruction {
842-
let governed_account_address = if let Some(governed_account) = governed_account {
843-
*governed_account
844-
} else {
845-
// If the governed account is not provided then generate a unique identifier for
846-
// the Governance account
847-
Pubkey::new_unique()
848-
};
849-
850-
let governance_address = get_governance_address(program_id, realm, &governed_account_address);
840+
let governance_address = get_governance_address(program_id, realm, governance_seed);
851841

852842
let mut accounts = vec![
853843
AccountMeta::new_readonly(*realm, false),
854844
AccountMeta::new(governance_address, false),
855-
AccountMeta::new_readonly(governed_account_address, false),
845+
AccountMeta::new_readonly(*governance_seed, false),
856846
AccountMeta::new_readonly(*token_owner_record, false),
857847
AccountMeta::new(*payer, true),
858848
AccountMeta::new_readonly(system_program::id(), false),

governance/program/src/processor/process_create_governance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn process_create_governance(
3232

3333
let realm_info = next_account_info(account_info_iter)?; // 0
3434
let governance_info = next_account_info(account_info_iter)?; // 1
35-
let governed_account_info = next_account_info(account_info_iter)?; // 2
35+
let governance_seed_info = next_account_info(account_info_iter)?; // 2
3636

3737
let token_owner_record_info = next_account_info(account_info_iter)?; // 3
3838

@@ -58,7 +58,7 @@ pub fn process_create_governance(
5858
let governance_data = GovernanceV2 {
5959
account_type: GovernanceAccountType::GovernanceV2,
6060
realm: *realm_info.key,
61-
governed_account: *governed_account_info.key,
61+
governance_seed: *governance_seed_info.key,
6262
config,
6363
reserved1: 0,
6464
reserved_v2: Reserved119::default(),
@@ -70,7 +70,7 @@ pub fn process_create_governance(
7070
payer_info,
7171
governance_info,
7272
&governance_data,
73-
&get_governance_address_seeds(realm_info.key, governed_account_info.key),
73+
&get_governance_address_seeds(realm_info.key, governance_seed_info.key),
7474
program_id,
7575
system_info,
7676
&rent,

governance/program/src/state/governance.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,14 @@ pub struct GovernanceV2 {
9191
/// Governance Realm
9292
pub realm: Pubkey,
9393

94-
/// Account governed by this Governance and/or PDA identity seed
95-
/// It can be Program account, Mint account, Token account or any other
96-
/// account
94+
/// The seed used to create Governance account PDA
9795
///
98-
/// Note: The account doesn't have to exist. In that case the field is only
99-
/// a PDA seed
100-
///
101-
/// Note: Setting governed_account doesn't give any authority over the
102-
/// governed account The relevant authorities for specific account types
103-
/// must still be transferred to the Governance PDA Ex: mint_authority/
104-
/// freeze_authority for a Mint account or upgrade_authority for a
105-
/// Program account should be transferred to the Governance PDA
106-
pub governed_account: Pubkey,
96+
/// Note: For the legacy asset specific Governance accounts
97+
/// the seed by convention is:
98+
/// MintGovernance -> mint address
99+
/// TokenAccountGovernance -> token account address
100+
/// ProgramGovernance -> program address
101+
pub governance_seed: Pubkey,
107102

108103
/// Reserved space for future versions
109104
pub reserved1: u32,
@@ -221,17 +216,17 @@ impl GovernanceV2 {
221216
pub fn get_governance_address_seeds(&self) -> Result<[&[u8]; 3], ProgramError> {
222217
let seeds = match self.account_type {
223218
GovernanceAccountType::GovernanceV1 | GovernanceAccountType::GovernanceV2 => {
224-
get_governance_address_seeds(&self.realm, &self.governed_account)
219+
get_governance_address_seeds(&self.realm, &self.governance_seed)
225220
}
226221
GovernanceAccountType::ProgramGovernanceV1
227222
| GovernanceAccountType::ProgramGovernanceV2 => {
228-
get_program_governance_address_seeds(&self.realm, &self.governed_account)
223+
get_program_governance_address_seeds(&self.realm, &self.governance_seed)
229224
}
230225
GovernanceAccountType::MintGovernanceV1 | GovernanceAccountType::MintGovernanceV2 => {
231-
get_mint_governance_address_seeds(&self.realm, &self.governed_account)
226+
get_mint_governance_address_seeds(&self.realm, &self.governance_seed)
232227
}
233228
GovernanceAccountType::TokenGovernanceV1 | GovernanceAccountType::TokenGovernanceV2 => {
234-
get_token_governance_address_seeds(&self.realm, &self.governed_account)
229+
get_token_governance_address_seeds(&self.realm, &self.governance_seed)
235230
}
236231
GovernanceAccountType::Uninitialized
237232
| GovernanceAccountType::RealmV1
@@ -277,7 +272,7 @@ impl GovernanceV2 {
277272
let governance_data_v1 = GovernanceV1 {
278273
account_type: self.account_type,
279274
realm: self.realm,
280-
governed_account: self.governed_account,
275+
governance_seed: self.governance_seed,
281276
proposals_count: 0,
282277
config: self.config,
283278
};
@@ -419,7 +414,7 @@ pub fn get_governance_data(
419414
GovernanceV2 {
420415
account_type,
421416
realm: governance_data_v1.realm,
422-
governed_account: governance_data_v1.governed_account,
417+
governance_seed: governance_data_v1.governance_seed,
423418
reserved1: 0,
424419
config: governance_data_v1.config,
425420
reserved_v2: Reserved119::default(),
@@ -560,22 +555,26 @@ pub fn get_mint_governance_address<'a>(
560555
/// Returns legacy TokenGovernance PDA seeds
561556
pub fn get_token_governance_address_seeds<'a>(
562557
realm: &'a Pubkey,
563-
governed_token: &'a Pubkey,
558+
governed_token_account: &'a Pubkey,
564559
) -> [&'a [u8]; 3] {
565560
// 'token-governance' prefix ensures uniqueness of the PDA
566561
// Note: Only the current token account owner can create an account with this
567562
// PDA using CreateTokenGovernance instruction
568-
[b"token-governance", realm.as_ref(), governed_token.as_ref()]
563+
[
564+
b"token-governance",
565+
realm.as_ref(),
566+
governed_token_account.as_ref(),
567+
]
569568
}
570569

571570
/// Returns legacy TokenGovernance PDA address
572571
pub fn get_token_governance_address<'a>(
573572
program_id: &Pubkey,
574573
realm: &'a Pubkey,
575-
governed_token: &'a Pubkey,
574+
governed_token_account: &'a Pubkey,
576575
) -> Pubkey {
577576
Pubkey::find_program_address(
578-
&get_token_governance_address_seeds(realm, governed_token),
577+
&get_token_governance_address_seeds(realm, governed_token_account),
579578
program_id,
580579
)
581580
.0
@@ -584,23 +583,23 @@ pub fn get_token_governance_address<'a>(
584583
/// Returns Governance PDA seeds
585584
pub fn get_governance_address_seeds<'a>(
586585
realm: &'a Pubkey,
587-
governed_account: &'a Pubkey,
586+
governance_seed: &'a Pubkey,
588587
) -> [&'a [u8]; 3] {
589588
[
590589
b"account-governance",
591590
realm.as_ref(),
592-
governed_account.as_ref(),
591+
governance_seed.as_ref(),
593592
]
594593
}
595594

596595
/// Returns Governance PDA address
597596
pub fn get_governance_address<'a>(
598597
program_id: &Pubkey,
599598
realm: &'a Pubkey,
600-
governed_account: &'a Pubkey,
599+
governance_seed: &'a Pubkey,
601600
) -> Pubkey {
602601
Pubkey::find_program_address(
603-
&get_governance_address_seeds(realm, governed_account),
602+
&get_governance_address_seeds(realm, governance_seed),
604603
program_id,
605604
)
606605
.0
@@ -697,7 +696,7 @@ mod test {
697696
GovernanceV2 {
698697
account_type: GovernanceAccountType::GovernanceV2,
699698
realm: Pubkey::new_unique(),
700-
governed_account: Pubkey::new_unique(),
699+
governance_seed: Pubkey::new_unique(),
701700
reserved1: 0,
702701
config: create_test_governance_config(),
703702
reserved_v2: Reserved119::default(),
@@ -710,7 +709,7 @@ mod test {
710709
GovernanceV1 {
711710
account_type: GovernanceAccountType::GovernanceV1,
712711
realm: Pubkey::new_unique(),
713-
governed_account: Pubkey::new_unique(),
712+
governance_seed: Pubkey::new_unique(),
714713
proposals_count: 10,
715714
config: create_test_governance_config(),
716715
}

governance/program/src/state/legacy.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,14 @@ pub struct GovernanceV1 {
115115
/// Governance Realm
116116
pub realm: Pubkey,
117117

118-
/// Account governed by this Governance and/or PDA identity seed
119-
/// It can be Program account, Mint account, Token account or any other
120-
/// account
118+
/// The seed used to create Governance account PDA
121119
///
122-
/// Note: The account doesn't have to exist. In that case the field is only
123-
/// a PDA seed
124-
///
125-
/// Note: Setting governed_account doesn't give any authority over the
126-
/// governed account The relevant authorities for specific account types
127-
/// must still be transferred to the Governance PDA Ex: mint_authority/
128-
/// freeze_authority for a Mint account or upgrade_authority for a
129-
/// Program account should be transferred to the Governance PDA
130-
pub governed_account: Pubkey,
120+
/// Note: For the legacy asset specific Governance accounts
121+
/// the seed by convention is:
122+
/// MintGovernance -> mint address
123+
/// TokenAccountGovernance -> token account address
124+
/// ProgramGovernance -> program address
125+
pub governance_seed: Pubkey,
131126

132127
/// Running count of proposals
133128
pub proposals_count: u32,

governance/program/tests/program_test/legacy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub struct LegacyGovernanceV1 {
1313
/// Governance Realm
1414
pub realm: Pubkey,
1515

16-
/// Account governed by this Governance.
17-
pub governed_account: Pubkey,
16+
/// Governance seed
17+
pub governance_seed: Pubkey,
1818

1919
/// Running count of proposals
2020
pub proposals_count: u32,
@@ -113,7 +113,7 @@ impl From<GovernanceV2> for LegacyGovernanceV1 {
113113
LegacyGovernanceV1 {
114114
account_type,
115115
realm: governance_v2.realm,
116-
governed_account: governance_v2.governed_account,
116+
governance_seed: governance_v2.governance_seed,
117117
proposals_count: 0,
118118
config: LegacyGovernanceConfigV1 {
119119
vote_threshold_percentage: VoteThresholdPercentage::YesVote(yes_vote_threshold),

governance/program/tests/program_test/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,12 +1468,12 @@ impl GovernanceProgramTest {
14681468
governance_config: &GovernanceConfig,
14691469
signers_override: Option<&[&Keypair]>,
14701470
) -> Result<GovernanceCookie, ProgramError> {
1471-
let governed_account = Pubkey::new_unique();
1471+
let governance_seed = Pubkey::new_unique();
14721472

14731473
let mut create_governance_ix = create_governance(
14741474
&self.program_id,
14751475
&realm_cookie.address,
1476-
Some(&governed_account),
1476+
&governance_seed,
14771477
token_owner_record.unwrap_or(&Pubkey::new_unique()),
14781478
&self.bench.payer.pubkey(),
14791479
&create_authority.pubkey(),
@@ -1484,7 +1484,7 @@ impl GovernanceProgramTest {
14841484
let account = GovernanceV2 {
14851485
account_type: GovernanceAccountType::GovernanceV2,
14861486
realm: realm_cookie.address,
1487-
governed_account,
1487+
governance_seed,
14881488
config: governance_config.clone(),
14891489
reserved1: 0,
14901490
reserved_v2: Reserved119::default(),
@@ -1504,7 +1504,7 @@ impl GovernanceProgramTest {
15041504
.await?;
15051505

15061506
let governance_address =
1507-
get_governance_address(&self.program_id, &realm_cookie.address, &governed_account);
1507+
get_governance_address(&self.program_id, &realm_cookie.address, &governance_seed);
15081508

15091509
Ok(GovernanceCookie {
15101510
address: governance_address,
@@ -2384,7 +2384,7 @@ impl GovernanceProgramTest {
23842384
.unwrap();
23852385

23862386
let mut upgrade_ix = bpf_loader_upgradeable::upgrade(
2387-
&governance_cookie.account.governed_account,
2387+
&governance_cookie.account.governance_seed,
23882388
&program_buffer_keypair.pubkey(),
23892389
&governance_cookie.address,
23902390
&governance_cookie.address,

0 commit comments

Comments
 (0)