FairScore Oracle
The FairScore Oracle manages reputation scores for CredDAO members through a weighted composite scoring system.
Program ID
Faire11111111111111111111111111111111111111Score Components
| Component | Weight | Description |
|---|---|---|
| Active Days | 20% | Account age and activity consistency |
| Social Score | 30% | On-chain social interactions |
| Transaction History | 20% | Trading and protocol usage |
| Governance Participation | 30% | Voting and proposal history |
Instructions
initialize_oracle
Initialize the oracle with authorized updaters.
pub fn initialize_oracle(
ctx: Context<InitializeOracle>,
authorized_updaters: Vec<Pubkey>,
update_cooldown: i64,
) -> Result<()>List of public keys authorized to update scores.
Minimum time between score updates in seconds.
initialize_score
Create a new FairScore account for a wallet.
pub fn initialize_score(
ctx: Context<InitializeScore>,
active_days_score: u64,
social_score: u64,
transaction_history_score: u64,
governance_participation_score: u64,
) -> Result<()>Score component for account activity (0-100).
Score component for social interactions (0-100).
Score component for transaction patterns (0-100).
Score component for governance activity (0-100).
All score components must be between 0 and 100. Values outside this range will fail with InvalidScoreComponent error.
Composite Score Calculation
pub fn calculate_composite_score(
active_days: u64,
social: u64,
transaction_history: u64,
governance_participation: u64,
) -> u64 {
let weighted_active = active_days * ACTIVE_DAYS_WEIGHT;
let weighted_social = social * SOCIAL_SCORE_WEIGHT;
let weighted_transaction = transaction_history * TRANSACTION_HISTORY_WEIGHT;
let weighted_governance = governance_participation * GOVERNANCE_PARTICIPATION_WEIGHT;
(weighted_active + weighted_social + weighted_transaction + weighted_governance) / 100
}update_score
Update an existing FairScore.
pub fn update_score(
ctx: Context<UpdateScore>,
active_days_score: u64,
social_score: u64,
transaction_history_score: u64,
governance_participation_score: u64,
) -> Result<()>Updates can only be performed by authorized updaters. The update_cooldown must have passed since the last update.
Events
ScoreUpdated {
wallet: Pubkey,
old_score: u64,
new_score: u64,
updater: Pubkey
}batch_update_scores
Update multiple scores in a single transaction.
pub fn batch_update_scores(
ctx: Context<BatchUpdateScores>,
updates: Vec<ScoreUpdate>,
) -> Result<()>Array of score updates to process.
ScoreUpdate Structure
pub struct ScoreUpdate {
pub wallet: Pubkey,
pub active_days_score: u64,
pub social_score: u64,
pub transaction_history_score: u64,
pub governance_participation_score: u64,
}record_score_history
Record score to history for audit trail.
pub fn record_score_history(
ctx: Context<RecordScoreHistory>,
) -> Result<()>Stores up to 100 historical score entries per wallet.
get_score
Query a wallet’s current score.
pub fn get_score(
ctx: Context<GetScore>,
) -> Result<()>Emits a ScoreQuery event with the current score.
Account Structures
OracleConfig
#[account]
pub struct OracleConfig {
pub authority: Pubkey,
pub authorized_updaters: Vec<Pubkey>, // Max 10
pub update_cooldown: i64,
pub bump: u8,
}FairScoreAccount
#[account]
pub struct FairScoreAccount {
pub wallet: Pubkey,
pub score: u64,
pub active_days_score: u64,
pub social_score: u64,
pub transaction_history_score: u64,
pub governance_participation_score: u64,
pub last_updated: i64,
pub update_count: u64,
pub bump: u8,
}ScoreHistory
#[account]
pub struct ScoreHistory {
pub wallet: Pubkey,
pub scores: Vec<ScoreEntry>, // Max 100 entries
pub bump: u8,
}ScoreEntry
pub struct ScoreEntry {
pub score: u64,
pub timestamp: i64,
pub updater: Pubkey,
}PDA Derivation
| Account | Seeds |
|---|---|
| OracleConfig | ["oracle_config"] |
| FairScoreAccount | ["score", wallet_pubkey] |
| ScoreHistory | ["history", wallet_pubkey] |
Error Codes
| Code | Error | Description |
|---|---|---|
| 6000 | ScoreExceedsMax | Score above maximum value |
| 6001 | ScoreBelowMin | Score below minimum value |
| 6002 | UnauthorizedOracle | Updater not authorized |
| 6003 | InvalidScoreComponent | Component score out of range |
| 6004 | UpdateTooFrequent | Cooldown period not elapsed |
Integration with CredDAO
The FairScore Oracle is integrated with the main CredDAO program:
- Score initialization - When a member registers, they receive an initial score
- Score updates - Periodic updates from authorized data providers
- Vote weighting - Scores are used to calculate voting power
- Tier assignment - Scores determine member tier
Events
ScoreInitialized { wallet, score }
ScoreUpdated { wallet, old_score, new_score, updater }
BatchScoreUpdate { wallet, score, updater }
ScoreQuery { wallet, score }