Skip to content

Commit

Permalink
Governance: Rename vote_threshold_percentage to community_vote_thresh…
Browse files Browse the repository at this point in the history
…old (#3132)
  • Loading branch information
SebastianBor authored May 2, 2022
1 parent e59a0dc commit 3db53e2
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 91 deletions.
4 changes: 2 additions & 2 deletions governance/chat/program/tests/program_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use spl_governance::{
deposit_governing_tokens,
},
state::{
enums::{MintMaxVoteWeightSource, VoteThresholdPercentage},
enums::{MintMaxVoteWeightSource, VoteThreshold},
governance::{get_governance_address, GovernanceConfig},
proposal::{get_proposal_address, VoteType},
realm::get_realm_address,
Expand Down Expand Up @@ -183,7 +183,7 @@ impl GovernanceChatProgramTest {
min_council_weight_to_create_proposal: 2,
min_transaction_hold_up_time: 10,
max_voting_time: 10,
vote_threshold_percentage: VoteThresholdPercentage::YesVote(60),
community_vote_threshold: VoteThreshold::YesVotePercentage(60),
vote_tipping: spl_governance::state::enums::VoteTipping::Strict,
proposal_cool_off_time: 0,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub fn process_create_proposal(

max_vote_weight: None,
max_voting_time: None,
vote_threshold_percentage: None,
vote_threshold: None,

reserved: [0; 64],
};
Expand Down
8 changes: 4 additions & 4 deletions governance/program/src/state/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,18 @@ impl Default for ProposalState {
/// The type of the vote threshold percentage used to resolve a vote on a Proposal
#[repr(C)]
#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
pub enum VoteThresholdPercentage {
/// Voting threshold of Yes votes in % required to tip the vote
pub enum VoteThreshold {
/// Voting threshold of Yes votes in % required to tip the vote (Approval Quorum)
/// It's the percentage of tokens out of the entire pool of governance tokens eligible to vote
/// Note: If the threshold is below or equal to 50% then an even split of votes ex: 50:50 or 40:40 is always resolved as Defeated
/// In other words a '+1 vote' tie breaker is always required to have a successful vote
YesVote(u8),
YesVotePercentage(u8),

/// The minimum number of votes in % out of the entire pool of governance tokens eligible to vote
/// which must be cast for the vote to be valid
/// Once the quorum is achieved a simple majority (50%+1) of Yes votes is required for the vote to succeed
/// Note: Quorum is not implemented in the current version
Quorum(u8),
QuorumPercentage(u8),
}

/// The type of vote tipping to use on a Proposal.
Expand Down
10 changes: 5 additions & 5 deletions governance/program/src/state/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use borsh::maybestd::io::Write;
use crate::{
error::GovernanceError,
state::{
enums::{GovernanceAccountType, VoteThresholdPercentage, VoteTipping},
enums::{GovernanceAccountType, VoteThreshold, VoteTipping},
legacy::{is_governance_v1_account_type, GovernanceV1},
realm::assert_is_valid_realm,
},
Expand All @@ -23,9 +23,9 @@ use spl_governance_tools::{
#[repr(C)]
#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
pub struct GovernanceConfig {
/// The type of the vote threshold used for voting
/// The type of the vote threshold used for community vote
/// Note: In the current version only YesVote threshold is supported
pub vote_threshold_percentage: VoteThresholdPercentage,
pub community_vote_threshold: VoteThreshold,

/// Minimum community weight a governance token owner must possess to be able to create a proposal
pub min_community_weight_to_create_proposal: u64,
Expand Down Expand Up @@ -377,8 +377,8 @@ pub fn assert_valid_create_governance_args(
pub fn assert_is_valid_governance_config(
governance_config: &GovernanceConfig,
) -> Result<(), ProgramError> {
match governance_config.vote_threshold_percentage {
VoteThresholdPercentage::YesVote(yes_vote_threshold_percentage) => {
match governance_config.community_vote_threshold {
VoteThreshold::YesVotePercentage(yes_vote_threshold_percentage) => {
if !(1..=100).contains(&yes_vote_threshold_percentage) {
return Err(GovernanceError::InvalidVoteThresholdPercentage.into());
}
Expand Down
4 changes: 2 additions & 2 deletions governance/program/src/state/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::state::{
enums::{
GovernanceAccountType, InstructionExecutionFlags, ProposalState,
TransactionExecutionStatus, VoteThresholdPercentage,
TransactionExecutionStatus, VoteThreshold,
},
governance::GovernanceConfig,
proposal_transaction::InstructionData,
Expand Down Expand Up @@ -247,7 +247,7 @@ pub struct ProposalV1 {
/// The vote threshold percentage at the time Proposal was decided
/// It's used to show correct vote results for historical proposals in cases when the threshold
/// was changed for governance config after vote was completed.
pub vote_threshold_percentage: Option<VoteThresholdPercentage>,
pub vote_threshold: Option<VoteThreshold>,

/// Proposal name
pub name: String,
Expand Down
Loading

0 comments on commit 3db53e2

Please sign in to comment.