DocumentationcontractsSmart Contracts Overview

Smart Contracts Overview

CredDAO consists of two Anchor programs that work together to enable reputation-weighted governance on Solana.

Architecture

Programs

ProgramAddressDescription
CredDAOCreDDAo111111111111111111111111111111111111Core governance logic
FairScore OracleFaire11111111111111111111111111111111111111Reputation scoring system

Key Features

CredDAO Program

The main governance contract handles:

  • DAO initialization - Set up governance parameters
  • Member registration - Onboard new members with initial scores
  • Proposal lifecycle - Create, vote, finalize, execute
  • Delegation - Delegate voting power to trusted members
  • Time-locks - Tier-based execution delays

FairScore Oracle

The reputation oracle manages:

  • Score initialization - Create reputation profiles
  • Score updates - Refresh scores from authorized sources
  • Batch updates - Efficient bulk score updates
  • Score history - Historical score tracking

Account Relationships

Member Accounts

MemberProfile
├── wallet: Pubkey
├── fairscore: u64
├── tier: ReputationTier
├── active_days: u64
├── proposals_submitted: u32
├── proposals_voted: u32
├── delegate_to: Option<Pubkey>
└── badges: u8

Proposal Accounts

ProposalAccount
├── dao_config: Pubkey
├── proposer: Pubkey
├── proposal_type: ProposalType
├── state: ProposalState
├── for_votes: u64
├── against_votes: u64
├── voting_end: i64
└── time_lock_expiry: i64

Security Model

Access Control

ActionAuthority
Initialize DAODAO authority
Register memberMember wallet
Create proposalMember wallet (tier-gated)
Cast voteMember wallet
Update scoresAuthorized oracle updaters
Execute proposalAnyone (after time-lock)

Flash Loan Protection

The contracts implement multiple flash loan protections:

  1. Minimum active days - 30-day requirement before participation
  2. Score snapshots - Recorded at vote time
  3. Score decay detection - Triggers on sudden drops
  4. Time-locks - Delays before execution

Constants

pub const REPUTATION_MULTIPLIER_DENOMINATOR: u64 = 50;
pub const MIN_ACTIVE_DAYS: u64 = 30;
pub const TIME_LOCK_PLATINUM: i64 = 24 * 60 * 60;   // 24 hours
pub const TIME_LOCK_GOLD: i64 = 48 * 60 * 60;       // 48 hours
pub const TIME_LOCK_SILVER: i64 = 72 * 60 * 60;     // 72 hours
pub const TIME_LOCK_BRONZE: i64 = 168 * 60 * 60;    // 7 days
pub const TIME_LOCK_DEFAULT: i64 = 336 * 60 * 60;   // 14 days
pub const SCORE_DECAY_THRESHOLD: u64 = 10;

Error Codes

CodeErrorDescription
6000InsufficientReputationTierMember tier too low for action
6001InsufficientActiveDaysAccount not active long enough
6002ProposalVotingActiveVoting period still active
6003TimeLockNotExpiredTime-lock period not finished
6004ScoreManipulationScore snapshot mismatch
6005ScoreDecayDetectedSudden score drop detected
6006InsufficientBadgesNot enough badges for emergency
6007DelegationAlreadyActiveAlready delegating
6008InvalidDelegationTargetCannot delegate to self
6009QuorumNotReachedMinimum participation not met
6010FlashLoanDetectedPotential flash loan attack

Events

All major actions emit events for indexing:

MemberRegistered { wallet, fairscore, tier }
MemberScoreUpdated { wallet, old_score, new_score, new_tier }
ProposalCreated { proposal, proposer, proposal_type, voting_end, time_lock_expiry }
VoteCast { proposal, voter, vote, voting_power, fairscore }
ProposalFinalized { proposal, state, for_votes, against_votes }
ProposalExecuted { proposal, executed_at }
DelegationCreated { delegator, delegate, efficiency }
DelegationRevoked { delegator }

Next Steps

CredDAO Program

Deep dive into the main governance contract.

FairScore Oracle

Learn about the reputation scoring system.