CredDAO Program
The core governance contract that handles proposals, voting, and delegation.
Program ID
CreDDAo111111111111111111111111111111111111Instructions
initialize_dao
Initialize the DAO with governance parameters.
pub fn initialize_dao(
ctx: Context<InitializeDao>,
quorum_percentage: u8,
voting_period: i64,
emergency_badge_count: u8,
) -> Result<()>Minimum percentage of total voting power required for a proposal to pass (0-100).
Duration of the voting period in seconds.
Number of badges required to submit emergency proposals.
Accounts
| Account | Description |
|---|---|
| dao_config | New PDA for DAO configuration |
| authority | Signer who becomes DAO authority |
| fairscore_oracle | FairScore oracle program address |
| governance_program | Governance program address |
| token_mint | Governance token mint |
| system_program | Solana system program |
register_member
Register a new member with an initial FairScore.
pub fn register_member(
ctx: Context<RegisterMember>,
fairscore: u64,
) -> Result<()>Initial FairScore (typically provided by oracle).
Accounts
| Account | Description |
|---|---|
| member_profile | New PDA for member profile |
| member | Signer registering as member |
| system_program | Solana system program |
Events
MemberRegistered { wallet, fairscore, tier }update_member_score
Update a member’s FairScore from the oracle.
pub fn update_member_score(
ctx: Context<UpdateMemberScore>,
new_score: u64,
) -> Result<()>Updated FairScore from oracle.
If the score drops by more than 10 points (SCORE_DECAY_THRESHOLD), the transaction fails with ScoreDecayDetected error. This prevents manipulation.
create_proposal
Create a new governance proposal.
pub fn create_proposal(
ctx: Context<CreateProposal>,
proposal_type: ProposalType,
) -> Result<()>Type of proposal: Standard, Expedited, or Emergency.
Requirements by Type
| Type | Tier Required | Additional Requirements |
|---|---|---|
| Standard | Gold or Platinum | None |
| Expedited | Platinum | None |
| Emergency | Platinum | Badges >= emergency_badge_count |
Accounts
| Account | Description |
|---|---|
| proposal | New PDA for proposal |
| dao_config | DAO configuration account |
| proposer | Member profile of proposer |
| proposer_member | Signer (must match proposer) |
| system_program | Solana system program |
cast_vote
Cast a vote on an active proposal.
pub fn cast_vote(
ctx: Context<CastVote>,
vote: u8,
) -> Result<()>Vote type: 0 = For, 1 = Against, 2 = Abstain.
Voting Power Calculation
pub fn calculate_voting_power(tokens: u64, fairscore: u64) -> u64 {
let quadratic_base = (tokens as f64).sqrt() as u64;
let reputation_multiplier = 100 + (fairscore * 100 / 50);
quadratic_base.saturating_mul(reputation_multiplier) / 100
}Accounts
| Account | Description |
|---|---|
| proposal | Proposal account (mutable) |
| voter | Member profile of voter |
| vote_record | New PDA for vote record |
| voter_member | Signer (must match voter) |
| dao_config | DAO configuration |
| system_program | Solana system program |
finalize_proposal
Finalize a proposal after voting ends.
pub fn finalize_proposal(
ctx: Context<FinalizeProposal>,
) -> Result<()>Finalization logic:
- Check voting period has ended
- Calculate total votes
- Check if quorum is reached
- Set state to Succeeded or Defeated
execute_proposal
Execute a succeeded proposal after time-lock expires.
pub fn execute_proposal(
ctx: Context<ExecuteProposal>,
) -> Result<()>Requirements:
- Proposal state must be Succeeded
- Current time must be >= time_lock_expiry
delegate
Delegate voting power to another member.
pub fn delegate(
ctx: Context<Delegate>,
delegate: Pubkey,
) -> Result<()>Public key of the member to delegate to.
Efficiency Calculation
let tier_multiplier = match delegate_profile.tier {
ReputationTier::Platinum => 150,
ReputationTier::Gold => 125,
ReputationTier::Silver => 110,
ReputationTier::Bronze => 100,
ReputationTier::Unscored => 80,
};
let delegation_efficiency = delegate_profile.fairscore
.saturating_mul(participation_rate)
.saturating_mul(tier_multiplier)
/ 10000;revoke_delegation
Revoke active delegation.
pub fn revoke_delegation(
ctx: Context<RevokeDelegation>,
) -> Result<()>Account Structures
DaoConfig
#[account]
pub struct DaoConfig {
pub authority: Pubkey,
pub fairscore_oracle: Pubkey,
pub governance_program: Pubkey,
pub token_mint: Pubkey,
pub quorum_percentage: u8,
pub voting_period: i64,
pub min_active_days: u64,
pub emergency_badge_count: u8,
pub proposals_count: u64,
pub bump: u8,
}MemberProfile
#[account]
pub struct MemberProfile {
pub wallet: Pubkey,
pub fairscore: u64,
pub tier: ReputationTier,
pub active_days: u64,
pub first_activity: i64,
pub last_activity: i64,
pub proposals_submitted: u32,
pub proposals_voted: u32,
pub delegate_to: Option<Pubkey>,
pub delegated_power: u64,
pub badges: u8,
pub score_snapshot: u64,
pub snapshot_timestamp: i64,
pub bump: u8,
}ProposalAccount
#[account]
pub struct ProposalAccount {
pub dao_config: Pubkey,
pub proposer: Pubkey,
pub proposal_type: ProposalType,
pub state: ProposalState,
pub for_votes: u64,
pub against_votes: u64,
pub abstain_votes: u64,
pub voting_start: i64,
pub voting_end: i64,
pub time_lock_expiry: i64,
pub quorum_required: u64,
pub total_voting_power: u64,
pub executed_at: Option<i64>,
pub bump: u8,
}PDA Derivation
| Account | Seeds |
|---|---|
| DaoConfig | ["dao_config"] |
| MemberProfile | ["member", wallet_pubkey] |
| ProposalAccount | ["proposal", dao_config, proposals_count] |
| VoteRecordAccount | ["vote", proposal_pubkey, voter_pubkey] |
| DelegationRecord | ["delegation", delegator_pubkey] |