Reputation

On-chain reputation scoring with authority-managed point system

Deployed Anchor 0.32
Program ID ChWH3iGNS4cwrpH1jz1BRVZqVteS177yr6Pe4Y8MFBQ
Binary Size 247K
Cluster Devnet

Instructions

IX initialize

Creates a new reputation system with a named configuration managed by the authority.

ParameterTypeDescription
nameStringName of the reputation system (max 32 characters)
IX add_points

Awards reputation points to a wallet address. Only callable by the authority.

ParameterTypeDescription
amountu64Number of reputation points to add
reason_hash[u8; 32]SHA-256 hash of the reason for awarding points
IX remove_points

Removes reputation points from a wallet address. Only callable by the authority.

ParameterTypeDescription
amountu64Number of reputation points to remove
reason_hash[u8; 32]SHA-256 hash of the reason for removing points

Accounts

ReputationConfig

FieldTypeDescription
authorityPubkeyAdmin who manages the reputation system
nameStringName of the reputation system
total_usersu64Total number of wallets with reputation accounts
bumpu8PDA bump seed

ReputationAccount

FieldTypeDescription
configPubkeyThe reputation config this account belongs to
walletPubkeyWallet address of the reputation holder
pointsu64Current reputation score
history_countu64Number of point changes recorded
last_updatei64Timestamp of the last point modification
bumpu8PDA bump seed

PDA Derivation

config
seeds = [b"config", authority]
reputation
seeds = [b"reputation", config, wallet]

Error Codes

NameTooLong Reputation system name exceeds the maximum 32 character limit
InsufficientPoints Cannot remove more points than the wallet currently holds
Overflow Arithmetic overflow in point calculation

Usage Example

import { Program, BN } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import { createHash } from "crypto";

// Derive config PDA
const [configPda] = PublicKey.findProgramAddressSync(
  [Buffer.from("config"), authority.publicKey.toBuffer()],
  program.programId
);

// Derive reputation PDA for a specific wallet
const [repPda] = PublicKey.findProgramAddressSync(
  [Buffer.from("reputation"), configPda.toBuffer(), userWallet.toBuffer()],
  program.programId
);

// Add 100 reputation points
const reason = createHash("sha256").update("Completed community task").digest();

await program.methods
  .addPoints(new BN(100), [...reason])
  .accounts({
    config: configPda,
    reputation: repPda,
    authority: authority.publicKey,
    wallet: userWallet,
  })
  .signers([authority])
  .rpc();