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

Commit 0e85d2e

Browse files
authored
Governance: Rename tokens_to_create to weight_to_create (#2839)
* chore: assert options length when serialising ProposalV1 * chore: rename tokens_to_create to weight_to_create * fix: use saturating_sub for voting_proposal_count * chore: update voting_proposal_count comments * Revert "chore: update voting_proposal_count comments" This reverts commit 3e2eb9d. * Revert "fix: use saturating_sub for voting_proposal_count" This reverts commit 5d35704.
1 parent c9f8dda commit 0e85d2e

File tree

12 files changed

+53
-49
lines changed

12 files changed

+53
-49
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ impl GovernanceChatProgramTest {
179179
let governed_account_address = Pubkey::new_unique();
180180

181181
let governance_config = GovernanceConfig {
182-
min_community_tokens_to_create_proposal: 5,
183-
min_council_tokens_to_create_proposal: 2,
182+
min_community_weight_to_create_proposal: 5,
183+
min_council_weight_to_create_proposal: 2,
184184
min_transaction_hold_up_time: 10,
185185
max_voting_time: 10,
186186
vote_threshold_percentage: VoteThresholdPercentage::YesVote(60),

governance/program/src/instruction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ pub fn create_realm(
485485
max_community_voter_weight_addin: Option<Pubkey>,
486486
// Args
487487
name: String,
488-
min_community_tokens_to_create_governance: u64,
488+
min_community_weight_to_create_governance: u64,
489489
community_mint_max_vote_weight_source: MintMaxVoteWeightSource,
490490
) -> Instruction {
491491
let realm_address = get_realm_address(program_id, &name);
@@ -544,7 +544,7 @@ pub fn create_realm(
544544
let instruction = GovernanceInstruction::CreateRealm {
545545
config_args: RealmConfigArgs {
546546
use_council_mint,
547-
min_community_tokens_to_create_governance,
547+
min_community_weight_to_create_governance,
548548
community_mint_max_vote_weight_source,
549549
use_community_voter_weight_addin,
550550
use_max_community_voter_weight_addin,
@@ -1350,7 +1350,7 @@ pub fn set_realm_config(
13501350
community_voter_weight_addin: Option<Pubkey>,
13511351
max_community_voter_weight_addin: Option<Pubkey>,
13521352
// Args
1353-
min_community_tokens_to_create_governance: u64,
1353+
min_community_weight_to_create_governance: u64,
13541354
community_mint_max_vote_weight_source: MintMaxVoteWeightSource,
13551355
) -> Instruction {
13561356
let mut accounts = vec![
@@ -1405,7 +1405,7 @@ pub fn set_realm_config(
14051405
let instruction = GovernanceInstruction::SetRealmConfig {
14061406
config_args: RealmConfigArgs {
14071407
use_council_mint,
1408-
min_community_tokens_to_create_governance,
1408+
min_community_weight_to_create_governance,
14091409
community_mint_max_vote_weight_source,
14101410
use_community_voter_weight_addin,
14111411
use_max_community_voter_weight_addin,

governance/program/src/processor/process_create_realm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ pub fn process_create_realm(
137137
reserved: [0; 6],
138138
community_mint_max_vote_weight_source: config_args
139139
.community_mint_max_vote_weight_source,
140-
min_community_tokens_to_create_governance: config_args
141-
.min_community_tokens_to_create_governance,
140+
min_community_weight_to_create_governance: config_args
141+
.min_community_weight_to_create_governance,
142142
use_community_voter_weight_addin: config_args.use_community_voter_weight_addin,
143143
use_max_community_voter_weight_addin: config_args.use_max_community_voter_weight_addin,
144144
},

governance/program/src/processor/process_set_realm_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ pub fn process_set_realm_config(
148148
realm_data.config.community_mint_max_vote_weight_source =
149149
realm_config_args.community_mint_max_vote_weight_source;
150150

151-
realm_data.config.min_community_tokens_to_create_governance =
152-
realm_config_args.min_community_tokens_to_create_governance;
151+
realm_data.config.min_community_weight_to_create_governance =
152+
realm_config_args.min_community_weight_to_create_governance;
153153

154154
realm_data.config.use_community_voter_weight_addin =
155155
realm_config_args.use_community_voter_weight_addin;

governance/program/src/state/governance.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub struct GovernanceConfig {
2525
/// Note: In the current version only YesVote threshold is supported
2626
pub vote_threshold_percentage: VoteThresholdPercentage,
2727

28-
/// Minimum number of community tokens a governance token owner must possess to be able to create a proposal
29-
pub min_community_tokens_to_create_proposal: u64,
28+
/// Minimum community weight a governance token owner must possess to be able to create a proposal
29+
pub min_community_weight_to_create_proposal: u64,
3030

3131
/// Minimum waiting time in seconds for a transaction to be executed after proposal is voted on
3232
pub min_transaction_hold_up_time: u32,
@@ -42,8 +42,8 @@ pub struct GovernanceConfig {
4242
/// Note: This field is not implemented in the current version
4343
pub proposal_cool_off_time: u32,
4444

45-
/// Minimum number of council tokens a governance token owner must possess to be able to create a proposal
46-
pub min_council_tokens_to_create_proposal: u64,
45+
/// Minimum council weight a governance token owner must possess to be able to create a proposal
46+
pub min_council_weight_to_create_proposal: u64,
4747
}
4848

4949
/// Governance Account

governance/program/src/state/legacy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct RealmConfigArgsV1 {
2222
pub use_council_mint: bool,
2323

2424
/// Min number of community tokens required to create a governance
25-
pub min_community_tokens_to_create_governance: u64,
25+
pub min_community_weight_to_create_governance: u64,
2626

2727
/// The source used for community mint max vote weight source
2828
pub community_mint_max_vote_weight_source: MintMaxVoteWeightSource,
@@ -57,7 +57,7 @@ pub struct RealmConfigV1 {
5757
pub reserved: [u8; 8],
5858

5959
/// Min number of community tokens required to create a governance
60-
pub min_community_tokens_to_create_governance: u64,
60+
pub min_community_weight_to_create_governance: u64,
6161

6262
/// The source used for community mint max vote weight source
6363
pub community_mint_max_vote_weight_source: MintMaxVoteWeightSource,

governance/program/src/state/proposal.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,10 @@ impl ProposalV2 {
773773
panic!("ProposalV1 doesn't support max voting time")
774774
}
775775

776+
if self.options.len() != 1 {
777+
panic!("ProposalV1 doesn't multiple options")
778+
}
779+
776780
let proposal_data_v1 = ProposalV1 {
777781
account_type: self.account_type,
778782
governance: self.governance,
@@ -1099,16 +1103,16 @@ mod test {
10991103

11001104
community_mint_max_vote_weight_source:
11011105
MintMaxVoteWeightSource::FULL_SUPPLY_FRACTION,
1102-
min_community_tokens_to_create_governance: 10,
1106+
min_community_weight_to_create_governance: 10,
11031107
},
11041108
voting_proposal_count: 0,
11051109
}
11061110
}
11071111

11081112
fn create_test_governance_config() -> GovernanceConfig {
11091113
GovernanceConfig {
1110-
min_community_tokens_to_create_proposal: 5,
1111-
min_council_tokens_to_create_proposal: 1,
1114+
min_community_weight_to_create_proposal: 5,
1115+
min_council_weight_to_create_proposal: 1,
11121116
min_transaction_hold_up_time: 10,
11131117
max_voting_time: 5,
11141118
vote_threshold_percentage: VoteThresholdPercentage::YesVote(60),

governance/program/src/state/realm.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct RealmConfigArgs {
3030
pub use_council_mint: bool,
3131

3232
/// Min number of community tokens required to create a governance
33-
pub min_community_tokens_to_create_governance: u64,
33+
pub min_community_weight_to_create_governance: u64,
3434

3535
/// The source used for community mint max vote weight source
3636
pub community_mint_max_vote_weight_source: MintMaxVoteWeightSource,
@@ -52,7 +52,7 @@ pub enum SetRealmAuthorityAction {
5252
SetUnchecked,
5353

5454
/// Sets realm authority and checks the new new authority is one of the realm's governances
55-
// Note: This is not a security feature because governance creation is only gated with min_community_tokens_to_create_governance
55+
// Note: This is not a security feature because governance creation is only gated with min_community_weight_to_create_governance
5656
// The check is done to prevent scenarios where the authority could be accidentally set to a wrong or none existing account
5757
SetChecked,
5858

@@ -73,8 +73,8 @@ pub struct RealmConfig {
7373
/// Reserved space for future versions
7474
pub reserved: [u8; 6],
7575

76-
/// Min number of community tokens required to create a governance
77-
pub min_community_tokens_to_create_governance: u64,
76+
/// Min number of voter's community weight required to create a governance
77+
pub min_community_weight_to_create_governance: u64,
7878

7979
/// The source used for community mint max vote weight source
8080
pub community_mint_max_vote_weight_source: MintMaxVoteWeightSource,
@@ -342,7 +342,7 @@ mod test {
342342
use_max_community_voter_weight_addin: false,
343343
reserved: [0; 6],
344344
community_mint_max_vote_weight_source: MintMaxVoteWeightSource::Absolute(100),
345-
min_community_tokens_to_create_governance: 10,
345+
min_community_weight_to_create_governance: 10,
346346
},
347347

348348
voting_proposal_count: 0,
@@ -363,7 +363,7 @@ mod test {
363363
council_mint: Some(Pubkey::new_unique()),
364364
reserved: [0; 8],
365365
community_mint_max_vote_weight_source: MintMaxVoteWeightSource::Absolute(100),
366-
min_community_tokens_to_create_governance: 10,
366+
min_community_weight_to_create_governance: 10,
367367
},
368368
reserved: [0; 8],
369369
authority: Some(Pubkey::new_unique()),
@@ -380,8 +380,8 @@ mod test {
380380
assert!(!realm_v2.config.use_community_voter_weight_addin);
381381
assert_eq!(realm_v2.account_type, GovernanceAccountType::Realm);
382382
assert_eq!(
383-
realm_v2.config.min_community_tokens_to_create_governance,
384-
realm_v1.config.min_community_tokens_to_create_governance,
383+
realm_v2.config.min_community_weight_to_create_governance,
384+
realm_v1.config.min_community_weight_to_create_governance,
385385
);
386386
}
387387

@@ -392,7 +392,7 @@ mod test {
392392
name: "test-realm".to_string(),
393393
config_args: RealmConfigArgs {
394394
use_council_mint: true,
395-
min_community_tokens_to_create_governance: 100,
395+
min_community_weight_to_create_governance: 100,
396396
community_mint_max_vote_weight_source:
397397
MintMaxVoteWeightSource::FULL_SUPPLY_FRACTION,
398398
use_community_voter_weight_addin: false,

governance/program/src/state/token_owner_record.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ impl TokenOwnerRecord {
110110
) -> Result<(), ProgramError> {
111111
let min_weight_to_create_proposal =
112112
if self.governing_token_mint == realm_data.community_mint {
113-
config.min_community_tokens_to_create_proposal
113+
config.min_community_weight_to_create_proposal
114114
} else if Some(self.governing_token_mint) == realm_data.config.council_mint {
115-
config.min_council_tokens_to_create_proposal
115+
config.min_council_weight_to_create_proposal
116116
} else {
117117
return Err(GovernanceError::InvalidGoverningTokenMint.into());
118118
};
@@ -138,7 +138,7 @@ impl TokenOwnerRecord {
138138
) -> Result<(), ProgramError> {
139139
let min_weight_to_create_governance =
140140
if self.governing_token_mint == realm_data.community_mint {
141-
realm_data.config.min_community_tokens_to_create_governance
141+
realm_data.config.min_community_weight_to_create_governance
142142
} else if Some(self.governing_token_mint) == realm_data.config.council_mint {
143143
// For council tokens it's enough to be in possession of any number of tokens
144144
1

governance/program/tests/process_create_realm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async fn test_create_realm_with_non_default_config() {
3636
let realm_config_args = RealmConfigArgs {
3737
use_council_mint: false,
3838
community_mint_max_vote_weight_source: MintMaxVoteWeightSource::SupplyFraction(1),
39-
min_community_tokens_to_create_governance: 10,
39+
min_community_weight_to_create_governance: 10,
4040
use_community_voter_weight_addin: false,
4141
use_max_community_voter_weight_addin: false,
4242
};

0 commit comments

Comments
 (0)