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

Commit a179eba

Browse files
authored
Governance: Community Veto Vote (#3506)
* feat: Enable Community Veto Vote * chore: test_veto_vote_with_community_voter_weight_addin * chore: test_veto_vote_with_community_max_voter_weight_addin * chore: assert valid community veto vote threshold chore: Fix merge conflict
1 parent e06506b commit a179eba

File tree

10 files changed

+309
-30
lines changed

10 files changed

+309
-30
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ impl GovernanceChatProgramTest {
195195
council_vote_threshold: VoteThreshold::YesVotePercentage(10),
196196
council_veto_vote_threshold: VoteThreshold::YesVotePercentage(50),
197197
council_vote_tipping: spl_governance::state::enums::VoteTipping::Strict,
198+
community_veto_vote_threshold: VoteThreshold::YesVotePercentage(55),
198199
};
199200

200201
let token_owner_record_address = get_token_owner_record_address(

governance/program/src/processor/process_create_governance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn process_create_governance(
5757
governed_account: *governed_account_info.key,
5858
config,
5959
proposals_count: 0,
60-
reserved: [0; 5],
60+
reserved: [0; 3],
6161
voting_proposal_count: 0,
6262
reserved_v2: [0; 128],
6363
};

governance/program/src/processor/process_create_mint_governance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn process_create_mint_governance(
6969
governed_account: *governed_mint_info.key,
7070
config,
7171
proposals_count: 0,
72-
reserved: [0; 5],
72+
reserved: [0; 3],
7373
voting_proposal_count: 0,
7474
reserved_v2: [0; 128],
7575
};

governance/program/src/processor/process_create_program_governance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn process_create_program_governance(
6969
governed_account: *governed_program_info.key,
7070
config,
7171
proposals_count: 0,
72-
reserved: [0; 5],
72+
reserved: [0; 3],
7373
voting_proposal_count: 0,
7474
reserved_v2: [0; 128],
7575
};

governance/program/src/processor/process_create_token_governance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn process_create_token_governance(
6767
governed_account: *governed_token_info.key,
6868
config,
6969
proposals_count: 0,
70-
reserved: [0; 5],
70+
reserved: [0; 3],
7171
voting_proposal_count: 0,
7272
reserved_v2: [0; 128],
7373
};

governance/program/src/state/governance.rs

+42-13
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ pub struct GovernanceConfig {
4848

4949
/// Minimum council weight a governance token owner must possess to be able to create a proposal
5050
pub min_council_weight_to_create_proposal: u64,
51-
//
52-
// The threshold for Community Veto votes
53-
// Note: Community Veto vote is not supported in the current version
54-
// In order to use this threshold the space from GovernanceV2.reserved must be taken to expand GovernanceConfig size
55-
// pub community_veto_vote_threshold: VoteThreshold,
56-
//
51+
5752
/// Conditions under which a Council vote will complete early
5853
pub council_vote_tipping: VoteTipping,
54+
55+
/// The threshold for Community Veto votes
56+
pub community_veto_vote_threshold: VoteThreshold,
5957
}
6058

6159
/// Governance Account
@@ -85,7 +83,7 @@ pub struct GovernanceV2 {
8583
pub config: GovernanceConfig,
8684

8785
/// Reserved space for future versions
88-
pub reserved: [u8; 5],
86+
pub reserved: [u8; 3],
8987

9088
/// The number of proposals in voting state in the Governance
9189
pub voting_proposal_count: u16,
@@ -228,10 +226,7 @@ impl GovernanceV2 {
228226
let vote_threshold = if realm_data.community_mint == *vote_governing_token_mint {
229227
match vote_kind {
230228
VoteKind::Electorate => &self.config.community_vote_threshold,
231-
VoteKind::Veto => {
232-
// Community Veto vote is not supported in current version
233-
return Err(GovernanceError::GoverningTokenMintNotAllowedToVote.into());
234-
}
229+
VoteKind::Veto => &self.config.community_veto_vote_threshold,
235230
}
236231
} else if realm_data.config.council_mint == Some(*vote_governing_token_mint) {
237232
match vote_kind {
@@ -289,7 +284,7 @@ pub fn get_governance_data(
289284
governed_account: governance_data_v1.governed_account,
290285
proposals_count: governance_data_v1.proposals_count,
291286
config: governance_data_v1.config,
292-
reserved: [0; 5],
287+
reserved: [0; 3],
293288
voting_proposal_count: governance_data_v1.voting_proposal_count,
294289

295290
// Add the extra reserved_v2 padding
@@ -317,7 +312,10 @@ pub fn get_governance_data(
317312

318313
// For legacy accounts default Council VoteTipping to the Community
319314
governance_data.config.council_vote_tipping =
320-
governance_data.config.community_vote_tipping.clone()
315+
governance_data.config.community_vote_tipping.clone();
316+
317+
// For legacy accoutns set the community Veto threshold to Disabled
318+
governance_data.config.community_veto_vote_threshold = VoteThreshold::Disabled;
321319
}
322320

323321
Ok(governance_data)
@@ -472,6 +470,8 @@ pub fn assert_is_valid_governance_config(
472470
governance_config: &GovernanceConfig,
473471
) -> Result<(), ProgramError> {
474472
assert_is_valid_vote_threshold(&governance_config.community_vote_threshold)?;
473+
assert_is_valid_vote_threshold(&governance_config.community_veto_vote_threshold)?;
474+
475475
assert_is_valid_vote_threshold(&governance_config.council_vote_threshold)?;
476476
assert_is_valid_vote_threshold(&governance_config.council_veto_vote_threshold)?;
477477

@@ -574,6 +574,7 @@ mod test {
574574
council_veto_vote_threshold: VoteThreshold::YesVotePercentage(1),
575575
min_council_weight_to_create_proposal: 1,
576576
council_vote_tipping: VoteTipping::Strict,
577+
community_veto_vote_threshold: VoteThreshold::YesVotePercentage(1),
577578
};
578579

579580
// Act
@@ -598,6 +599,7 @@ mod test {
598599
council_veto_vote_threshold: VoteThreshold::YesVotePercentage(1),
599600
min_council_weight_to_create_proposal: 1,
600601
council_vote_tipping: VoteTipping::Strict,
602+
community_veto_vote_threshold: VoteThreshold::YesVotePercentage(1),
601603
};
602604

603605
// Act
@@ -622,6 +624,7 @@ mod test {
622624
council_veto_vote_threshold: VoteThreshold::YesVotePercentage(1),
623625
min_council_weight_to_create_proposal: 1,
624626
council_vote_tipping: VoteTipping::Strict,
627+
community_veto_vote_threshold: VoteThreshold::YesVotePercentage(1),
625628
};
626629

627630
// Act
@@ -646,6 +649,32 @@ mod test {
646649
council_veto_vote_threshold: VoteThreshold::YesVotePercentage(0),
647650
min_council_weight_to_create_proposal: 1,
648651
council_vote_tipping: VoteTipping::Strict,
652+
community_veto_vote_threshold: VoteThreshold::YesVotePercentage(1),
653+
};
654+
655+
// Act
656+
let err = assert_is_valid_governance_config(&governance_config)
657+
.err()
658+
.unwrap();
659+
660+
// Assert
661+
assert_eq!(err, GovernanceError::InvalidVoteThresholdPercentage.into());
662+
}
663+
664+
#[test]
665+
fn test_assert_config_invalid_with_community_zero_yes_veto_vote_threshold() {
666+
// Arrange
667+
let governance_config = GovernanceConfig {
668+
community_vote_threshold: VoteThreshold::YesVotePercentage(1),
669+
min_community_weight_to_create_proposal: 1,
670+
min_transaction_hold_up_time: 1,
671+
max_voting_time: 1,
672+
council_vote_tipping: VoteTipping::Strict,
673+
council_vote_threshold: VoteThreshold::YesVotePercentage(1),
674+
council_veto_vote_threshold: VoteThreshold::YesVotePercentage(1),
675+
min_council_weight_to_create_proposal: 1,
676+
community_veto_vote_threshold: VoteThreshold::YesVotePercentage(0),
677+
community_vote_tipping: VoteTipping::Strict,
649678
};
650679

651680
// Act

governance/program/src/state/proposal.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ mod test {
11781178
council_vote_threshold: VoteThreshold::YesVotePercentage(60),
11791179
council_veto_vote_threshold: VoteThreshold::YesVotePercentage(50),
11801180
council_vote_tipping: VoteTipping::Strict,
1181+
community_veto_vote_threshold: VoteThreshold::YesVotePercentage(40),
11811182
}
11821183
}
11831184

governance/program/src/state/realm.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ impl RealmV2 {
226226
VoteKind::Veto => {
227227
// When Community veto Council proposal then return council_token_mint as the Proposal governing_token_mint
228228
if self.community_mint == *vote_governing_token_mint {
229-
// Community Veto is not supported in the current version
230-
return Err(GovernanceError::GoverningTokenMintNotAllowedToVote.into());
231-
//return Ok(self.config.council_mint.unwrap());
229+
return Ok(self.config.council_mint.unwrap());
232230
}
233231

234232
// When Council veto Community proposal then return community_token_mint as the Proposal governing_token_mint

governance/program/tests/program_test/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,7 @@ impl GovernanceProgramTest {
14131413
council_vote_threshold: VoteThreshold::YesVotePercentage(80),
14141414
council_veto_vote_threshold: VoteThreshold::YesVotePercentage(55),
14151415
council_vote_tipping: spl_governance::state::enums::VoteTipping::Strict,
1416+
community_veto_vote_threshold: VoteThreshold::YesVotePercentage(80),
14161417
}
14171418
}
14181419

@@ -1488,7 +1489,7 @@ impl GovernanceProgramTest {
14881489
governed_account: governed_account_cookie.address,
14891490
config: governance_config.clone(),
14901491
proposals_count: 0,
1491-
reserved: [0; 5],
1492+
reserved: [0; 3],
14921493
voting_proposal_count: 0,
14931494
reserved_v2: [0; 128],
14941495
};
@@ -1659,7 +1660,7 @@ impl GovernanceProgramTest {
16591660
governed_account: governed_program_cookie.address,
16601661
config,
16611662
proposals_count: 0,
1662-
reserved: [0; 5],
1663+
reserved: [0; 3],
16631664
voting_proposal_count: 0,
16641665
reserved_v2: [0; 128],
16651666
};
@@ -1783,7 +1784,7 @@ impl GovernanceProgramTest {
17831784
governed_account: governed_mint_cookie.address,
17841785
config: governance_config.clone(),
17851786
proposals_count: 0,
1786-
reserved: [0; 5],
1787+
reserved: [0; 3],
17871788
voting_proposal_count: 0,
17881789
reserved_v2: [0; 128],
17891790
};
@@ -1867,7 +1868,7 @@ impl GovernanceProgramTest {
18671868
governed_account: governed_token_cookie.address,
18681869
config,
18691870
proposals_count: 0,
1870-
reserved: [0; 5],
1871+
reserved: [0; 3],
18711872
voting_proposal_count: 0,
18721873
reserved_v2: [0; 128],
18731874
};

0 commit comments

Comments
 (0)