DocumentationcontractsCredDAO Program

CredDAO Program

The core governance contract that handles proposals, voting, and delegation.

Program ID

CreDDAo111111111111111111111111111111111111

Instructions

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

AccountDescription
dao_configNew PDA for DAO configuration
authoritySigner who becomes DAO authority
fairscore_oracleFairScore oracle program address
governance_programGovernance program address
token_mintGovernance token mint
system_programSolana 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

AccountDescription
member_profileNew PDA for member profile
memberSigner registering as member
system_programSolana 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.

Warning:

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

TypeTier RequiredAdditional Requirements
StandardGold or PlatinumNone
ExpeditedPlatinumNone
EmergencyPlatinumBadges >= emergency_badge_count

Accounts

AccountDescription
proposalNew PDA for proposal
dao_configDAO configuration account
proposerMember profile of proposer
proposer_memberSigner (must match proposer)
system_programSolana 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

AccountDescription
proposalProposal account (mutable)
voterMember profile of voter
vote_recordNew PDA for vote record
voter_memberSigner (must match voter)
dao_configDAO configuration
system_programSolana system program

finalize_proposal

Finalize a proposal after voting ends.

pub fn finalize_proposal(
    ctx: Context<FinalizeProposal>,
) -> Result<()>

Finalization logic:

  1. Check voting period has ended
  2. Calculate total votes
  3. Check if quorum is reached
  4. 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

AccountSeeds
DaoConfig["dao_config"]
MemberProfile["member", wallet_pubkey]
ProposalAccount["proposal", dao_config, proposals_count]
VoteRecordAccount["vote", proposal_pubkey, voter_pubkey]
DelegationRecord["delegation", delegator_pubkey]