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

Commit f6f5e9a

Browse files
authored
Governance: Min tokens to create governance (#2203)
* feat: add min_community_tokens_to_create_governance to config * feat: add token owner record and governing mint to CreateAccountGovernance * feat: add token owner record and governing mint to CreateMinGovernance * feat: add token owner record and governing mint to CreateProgramGovernance * feat: add token owner record and governing mint to CreateTokenGovernance * feat: remove custodian * fix: remove mint and update comments * chore: make clippy happy * chore: make clippy happy
1 parent f728613 commit f6f5e9a

32 files changed

+1049
-577
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

governance/program/src/instruction.rs

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub enum GovernanceInstruction {
5050
/// 5. `[]` System
5151
/// 6. `[]` SPL Token
5252
/// 7. `[]` Sysvar Rent
53-
/// 8. `[]` Realm custodian - optional
53+
5454
/// 9. `[]` Council Token Mint - optional
5555
/// 10. `[writable]` Council Token Holding account - optional unless council is used. PDA seeds: ['governance',realm,council_mint]
5656
/// The account will be created with the Realm PDA as its owner
@@ -109,10 +109,11 @@ pub enum GovernanceInstruction {
109109
///
110110
/// 0. `[]` Realm account the created Governance belongs to
111111
/// 1. `[writable]` Account Governance account. PDA seeds: ['account-governance', realm, governed_account]
112-
/// 2. `[]` Account governed by this Governance account
113-
/// 3. `[signer]` Payer
114-
/// 4. `[]` System program
115-
/// 5. `[]` Sysvar Rent
112+
/// 2. `[]` Account governed by this Governance
113+
/// 3. `[]` Governing TokenOwnerRecord account
114+
/// 4. `[signer]` Payer
115+
/// 5. `[]` System program
116+
/// 6. `[]` Sysvar Rent
116117
CreateAccountGovernance {
117118
/// Governance config
118119
#[allow(dead_code)]
@@ -126,10 +127,11 @@ pub enum GovernanceInstruction {
126127
/// 2. `[]` Program governed by this Governance account
127128
/// 3. `[writable]` Program Data account of the Program governed by this Governance account
128129
/// 4. `[signer]` Current Upgrade Authority account of the Program governed by this Governance account
129-
/// 5. `[signer]` Payer
130-
/// 6. `[]` bpf_upgradeable_loader program
131-
/// 7. `[]` System program
132-
/// 8. `[]` Sysvar Rent
130+
/// 5. `[]` Governing TokenOwnerRecord account
131+
/// 6. `[signer]` Payer
132+
/// 7. `[]` bpf_upgradeable_loader program
133+
/// 8. `[]` System program
134+
/// 9. `[]` Sysvar Rent
133135
CreateProgramGovernance {
134136
/// Governance config
135137
#[allow(dead_code)]
@@ -310,10 +312,11 @@ pub enum GovernanceInstruction {
310312
/// 1. `[writable]` Mint Governance account. PDA seeds: ['mint-governance', realm, governed_mint]
311313
/// 2. `[writable]` Mint governed by this Governance account
312314
/// 3. `[signer]` Current Mint Authority
313-
/// 4. `[signer]` Payer
314-
/// 5. `[]` SPL Token program
315-
/// 6. `[]` System program
316-
/// 7. `[]` Sysvar Rent
315+
/// 4. `[]` Governing TokenOwnerRecord account
316+
/// 5. `[signer]` Payer
317+
/// 6. `[]` SPL Token program
318+
/// 7. `[]` System program
319+
/// 8. `[]` Sysvar Rent
317320
CreateMintGovernance {
318321
#[allow(dead_code)]
319322
/// Governance config
@@ -331,11 +334,12 @@ pub enum GovernanceInstruction {
331334
/// 0. `[]` Realm account the created Governance belongs to
332335
/// 1. `[writable]` Token Governance account. PDA seeds: ['token-governance', realm, governed_token]
333336
/// 2. `[writable]` Token account governed by this Governance account
334-
/// 3. `[signer]` Current Token account owner
335-
/// 4. `[signer]` Payer
336-
/// 5. `[]` SPL Token program
337-
/// 6. `[]` System program
338-
/// 7. `[]` Sysvar Rent
337+
/// 3. `[signer]` Current Token account
338+
/// 4. `[]` Governing TokenOwnerRecord account
339+
/// 5. `[signer]` Payer
340+
/// 6. `[]` SPL Token program
341+
/// 7. `[]` System program
342+
/// 8. `[]` Sysvar Rent
339343
CreateTokenGovernance {
340344
#[allow(dead_code)]
341345
/// Governance config
@@ -383,7 +387,7 @@ pub enum GovernanceInstruction {
383387
/// Sets realm config
384388
/// 0. `[writable]` Realm account
385389
/// 1. `[signer]` Realm authority
386-
/// 2. `[]` Realm custodian - optional
390+
387391
/// 3. `[]` Council Token Mint - optional
388392
/// Note: In the current version it's only possible to remove council mint (set it to None)
389393
/// After setting council to None it won't be possible to withdraw the tokens from the Realm any longer
@@ -405,10 +409,10 @@ pub fn create_realm(
405409
realm_authority: &Pubkey,
406410
community_token_mint: &Pubkey,
407411
payer: &Pubkey,
408-
realm_custodian: Option<Pubkey>,
409412
council_token_mint: Option<Pubkey>,
410413
// Args
411414
name: String,
415+
min_community_tokens_to_create_governance: u64,
412416
community_mint_max_vote_weight_source: MintMaxVoteWeightSource,
413417
) -> Instruction {
414418
let realm_address = get_realm_address(program_id, &name);
@@ -426,13 +430,6 @@ pub fn create_realm(
426430
AccountMeta::new_readonly(sysvar::rent::id(), false),
427431
];
428432

429-
let use_custodian = if let Some(realm_custodian) = realm_custodian {
430-
accounts.push(AccountMeta::new_readonly(realm_custodian, false));
431-
true
432-
} else {
433-
false
434-
};
435-
436433
let use_council_mint = if let Some(council_token_mint) = council_token_mint {
437434
let council_token_holding_address =
438435
get_governing_token_holding_address(program_id, &realm_address, &council_token_mint);
@@ -447,7 +444,7 @@ pub fn create_realm(
447444
let instruction = GovernanceInstruction::CreateRealm {
448445
config_args: RealmConfigArgs {
449446
use_council_mint,
450-
use_custodian,
447+
min_community_tokens_to_create_governance,
451448
community_mint_max_vote_weight_source,
452449
},
453450
name,
@@ -582,6 +579,7 @@ pub fn create_account_governance(
582579
// Accounts
583580
realm: &Pubkey,
584581
governed_account: &Pubkey,
582+
token_owner_record: &Pubkey,
585583
payer: &Pubkey,
586584
// Args
587585
config: GovernanceConfig,
@@ -593,6 +591,7 @@ pub fn create_account_governance(
593591
AccountMeta::new_readonly(*realm, false),
594592
AccountMeta::new(account_governance_address, false),
595593
AccountMeta::new_readonly(*governed_account, false),
594+
AccountMeta::new_readonly(*token_owner_record, false),
596595
AccountMeta::new_readonly(*payer, true),
597596
AccountMeta::new_readonly(system_program::id(), false),
598597
AccountMeta::new_readonly(sysvar::rent::id(), false),
@@ -608,12 +607,14 @@ pub fn create_account_governance(
608607
}
609608

610609
/// Creates CreateProgramGovernance instruction
610+
#[allow(clippy::too_many_arguments)]
611611
pub fn create_program_governance(
612612
program_id: &Pubkey,
613613
// Accounts
614614
realm: &Pubkey,
615615
governed_program: &Pubkey,
616616
governed_program_upgrade_authority: &Pubkey,
617+
token_owner_record: &Pubkey,
617618
payer: &Pubkey,
618619
// Args
619620
config: GovernanceConfig,
@@ -629,6 +630,7 @@ pub fn create_program_governance(
629630
AccountMeta::new_readonly(*governed_program, false),
630631
AccountMeta::new(governed_program_data_address, false),
631632
AccountMeta::new_readonly(*governed_program_upgrade_authority, true),
633+
AccountMeta::new_readonly(*token_owner_record, false),
632634
AccountMeta::new_readonly(*payer, true),
633635
AccountMeta::new_readonly(bpf_loader_upgradeable::id(), false),
634636
AccountMeta::new_readonly(system_program::id(), false),
@@ -647,13 +649,15 @@ pub fn create_program_governance(
647649
}
648650
}
649651

650-
/// Creates CreateMintGovernance instruction
652+
/// Creates CreateMintGovernance
653+
#[allow(clippy::too_many_arguments)]
651654
pub fn create_mint_governance(
652655
program_id: &Pubkey,
653656
// Accounts
654657
realm: &Pubkey,
655658
governed_mint: &Pubkey,
656659
governed_mint_authority: &Pubkey,
660+
token_owner_record: &Pubkey,
657661
payer: &Pubkey,
658662
// Args
659663
config: GovernanceConfig,
@@ -666,6 +670,7 @@ pub fn create_mint_governance(
666670
AccountMeta::new(mint_governance_address, false),
667671
AccountMeta::new(*governed_mint, false),
668672
AccountMeta::new_readonly(*governed_mint_authority, true),
673+
AccountMeta::new_readonly(*token_owner_record, false),
669674
AccountMeta::new_readonly(*payer, true),
670675
AccountMeta::new_readonly(spl_token::id(), false),
671676
AccountMeta::new_readonly(system_program::id(), false),
@@ -685,12 +690,14 @@ pub fn create_mint_governance(
685690
}
686691

687692
/// Creates CreateTokenGovernance instruction
693+
#[allow(clippy::too_many_arguments)]
688694
pub fn create_token_governance(
689695
program_id: &Pubkey,
690696
// Accounts
691697
realm: &Pubkey,
692698
governed_token: &Pubkey,
693699
governed_token_owner: &Pubkey,
700+
token_owner_record: &Pubkey,
694701
payer: &Pubkey,
695702
// Args
696703
config: GovernanceConfig,
@@ -703,6 +710,7 @@ pub fn create_token_governance(
703710
AccountMeta::new(token_governance_address, false),
704711
AccountMeta::new(*governed_token, false),
705712
AccountMeta::new_readonly(*governed_token_owner, true),
713+
AccountMeta::new_readonly(*token_owner_record, false),
706714
AccountMeta::new_readonly(*payer, true),
707715
AccountMeta::new_readonly(spl_token::id(), false),
708716
AccountMeta::new_readonly(system_program::id(), false),
@@ -1159,22 +1167,16 @@ pub fn set_realm_config(
11591167
realm: &Pubkey,
11601168
realm_authority: &Pubkey,
11611169
council_token_mint: Option<Pubkey>,
1162-
realm_custodian: Option<Pubkey>,
1170+
11631171
// Args
1172+
min_community_tokens_to_create_governance: u64,
11641173
community_mint_max_vote_weight_source: MintMaxVoteWeightSource,
11651174
) -> Instruction {
11661175
let mut accounts = vec![
11671176
AccountMeta::new(*realm, false),
11681177
AccountMeta::new_readonly(*realm_authority, true),
11691178
];
11701179

1171-
let use_custodian = if let Some(realm_custodian) = realm_custodian {
1172-
accounts.push(AccountMeta::new_readonly(realm_custodian, false));
1173-
true
1174-
} else {
1175-
false
1176-
};
1177-
11781180
let use_council_mint = if let Some(council_token_mint) = council_token_mint {
11791181
let council_token_holding_address =
11801182
get_governing_token_holding_address(program_id, realm, &council_token_mint);
@@ -1189,7 +1191,7 @@ pub fn set_realm_config(
11891191
let instruction = GovernanceInstruction::SetRealmConfig {
11901192
config_args: RealmConfigArgs {
11911193
use_council_mint,
1192-
use_custodian,
1194+
min_community_tokens_to_create_governance,
11931195
community_mint_max_vote_weight_source,
11941196
},
11951197
};

governance/program/src/processor/process_create_account_governance.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ pub fn process_create_account_governance(
2929
let realm_info = next_account_info(account_info_iter)?; // 0
3030
let account_governance_info = next_account_info(account_info_iter)?; // 1
3131
let governed_account_info = next_account_info(account_info_iter)?; // 2
32-
let payer_info = next_account_info(account_info_iter)?; // 3
33-
let system_info = next_account_info(account_info_iter)?; // 4
3432

35-
let rent_sysvar_info = next_account_info(account_info_iter)?; // 5
33+
let _token_owner_record_info = next_account_info(account_info_iter)?; // 3
34+
35+
let payer_info = next_account_info(account_info_iter)?; // 4
36+
let system_info = next_account_info(account_info_iter)?; // 5
37+
38+
let rent_sysvar_info = next_account_info(account_info_iter)?; // 6
3639
let rent = &Rent::from_account_info(rent_sysvar_info)?;
3740

3841
assert_valid_create_governance_args(program_id, &config, realm_info)?;

governance/program/src/processor/process_create_mint_governance.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ pub fn process_create_mint_governance(
3636
let governed_mint_info = next_account_info(account_info_iter)?; // 2
3737
let governed_mint_authority_info = next_account_info(account_info_iter)?; // 3
3838

39-
let payer_info = next_account_info(account_info_iter)?; // 4
40-
let spl_token_info = next_account_info(account_info_iter)?; // 5
39+
let _token_owner_record_info = next_account_info(account_info_iter)?; // 4
4140

42-
let system_info = next_account_info(account_info_iter)?; // 6
41+
let payer_info = next_account_info(account_info_iter)?; // 5
42+
let spl_token_info = next_account_info(account_info_iter)?; // 6
4343

44-
let rent_sysvar_info = next_account_info(account_info_iter)?; // 7
44+
let system_info = next_account_info(account_info_iter)?; // 7
45+
46+
let rent_sysvar_info = next_account_info(account_info_iter)?; // 8
4547
let rent = &Rent::from_account_info(rent_sysvar_info)?;
4648

4749
assert_valid_create_governance_args(program_id, &config, realm_info)?;

governance/program/src/processor/process_create_program_governance.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ pub fn process_create_program_governance(
4040
let governed_program_data_info = next_account_info(account_info_iter)?; // 2
4141
let governed_program_upgrade_authority_info = next_account_info(account_info_iter)?; // 3
4242

43-
let payer_info = next_account_info(account_info_iter)?; // 4
44-
let bpf_upgrade_loader_info = next_account_info(account_info_iter)?; // 5
43+
let _token_owner_record_info = next_account_info(account_info_iter)?; // 4
4544

46-
let system_info = next_account_info(account_info_iter)?; // 6
45+
let payer_info = next_account_info(account_info_iter)?; // 5
46+
let bpf_upgrade_loader_info = next_account_info(account_info_iter)?; // 6
4747

48-
let rent_sysvar_info = next_account_info(account_info_iter)?; // 7
48+
let system_info = next_account_info(account_info_iter)?; // 7
49+
50+
let rent_sysvar_info = next_account_info(account_info_iter)?; // 8
4951
let rent = &Rent::from_account_info(rent_sysvar_info)?;
5052

5153
assert_valid_create_governance_args(program_id, &config, realm_info)?;

governance/program/src/processor/process_create_realm.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ pub fn process_create_realm(
6161
rent,
6262
)?;
6363

64-
let realm_custodian = if config_args.use_custodian {
65-
let realm_custodian_info = next_account_info(account_info_iter)?;
66-
Some(*realm_custodian_info.key)
67-
} else {
68-
None
69-
};
70-
7164
let council_token_mint_address = if config_args.use_council_mint {
7265
let council_token_mint_info = next_account_info(account_info_iter)?;
7366
let council_token_holding_info = next_account_info(account_info_iter)?;
@@ -100,9 +93,10 @@ pub fn process_create_realm(
10093
config: RealmConfig {
10194
council_mint: council_token_mint_address,
10295
reserved: [0; 8],
103-
custodian: realm_custodian,
10496
community_mint_max_vote_weight_source: config_args
10597
.community_mint_max_vote_weight_source,
98+
min_community_tokens_to_create_governance: config_args
99+
.min_community_tokens_to_create_governance,
106100
},
107101
};
108102

governance/program/src/processor/process_create_token_governance.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ pub fn process_create_token_governance(
3636
let governed_token_info = next_account_info(account_info_iter)?; // 2
3737
let governed_token_owner_info = next_account_info(account_info_iter)?; // 3
3838

39-
let payer_info = next_account_info(account_info_iter)?; // 4
40-
let spl_token_info = next_account_info(account_info_iter)?; // 5
39+
let _token_owner_record_info = next_account_info(account_info_iter)?; // 4
4140

42-
let system_info = next_account_info(account_info_iter)?; // 6
41+
let payer_info = next_account_info(account_info_iter)?; // 5
42+
let spl_token_info = next_account_info(account_info_iter)?; // 6
4343

44-
let rent_sysvar_info = next_account_info(account_info_iter)?; // 7
44+
let system_info = next_account_info(account_info_iter)?; // 7
45+
46+
let rent_sysvar_info = next_account_info(account_info_iter)?; // 8
4547
let rent = &Rent::from_account_info(rent_sysvar_info)?;
4648

4749
assert_valid_create_governance_args(program_id, &config, realm_info)?;

governance/program/src/processor/process_set_realm_config.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ pub fn process_set_realm_config(
3232

3333
assert_valid_realm_config_args(&config_args)?;
3434

35-
let realm_custodian = if config_args.use_custodian {
36-
let realm_custodian_info = next_account_info(account_info_iter)?;
37-
Some(*realm_custodian_info.key)
38-
} else {
39-
None
40-
};
41-
4235
if config_args.use_council_mint {
4336
let council_token_mint_info = next_account_info(account_info_iter)?;
4437

@@ -60,9 +53,10 @@ pub fn process_set_realm_config(
6053
realm_data.config.council_mint = None;
6154
}
6255

63-
realm_data.config.custodian = realm_custodian;
6456
realm_data.config.community_mint_max_vote_weight_source =
6557
config_args.community_mint_max_vote_weight_source;
58+
realm_data.config.min_community_tokens_to_create_governance =
59+
config_args.min_community_tokens_to_create_governance;
6660

6761
realm_data.serialize(&mut *realm_info.data.borrow_mut())?;
6862

governance/program/src/state/proposal.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,10 @@ mod test {
562562
config: RealmConfig {
563563
council_mint: Some(Pubkey::new_unique()),
564564
reserved: [0; 8],
565-
custodian: Some(Pubkey::new_unique()),
565+
566566
community_mint_max_vote_weight_source:
567567
MintMaxVoteWeightSource::FULL_SUPPLY_FRACTION,
568+
min_community_tokens_to_create_governance: 10,
568569
},
569570
}
570571
}

0 commit comments

Comments
 (0)