Backend & Chain/Smart Contract
GitHub

Smart Contract

The Sui Move smart contract that stores civilization health data on-chain.

Overview

The frontier_pulse module is written in Sui Move (edition 2024) and deployed to Sui Testnet. It provides the on-chain data layer for Frontier Pulse, storing player reputation profiles, star system health snapshots, and the global Civilization Health Index.

Data is written by the authorized oracle backend and can be read by anyone — enabling other dApps to make trust-based decisions using Frontier Pulse data.

Module Initialization Flow

1

Package Published

sui client publish deploys the frontier_pulse module to Sui

2

AdminCap → Deployer

init() creates AdminCap and transfers to deployer wallet

3

PulseRegistry Shared

init() creates PulseRegistry as a shared object (public read)

4

Issue OracleCap

Admin calls issue_oracle_cap() to authorize the oracle backend

5

Oracle Writes Data

Oracle uses OracleCap to write system health, reputation, CHI, alerts

Core Structs

PlayerReputation

5-dimension behavioral profile stored per player address:

frontier_pulse.move
public struct PlayerReputation has store, drop, copy {
    player: address,
    reliability: u64,       // 0-100: "Can they be counted on?"
    commerce: u64,          // 0-100: "Honest in deals?"
    diplomacy: u64,         // 0-100: "Brings people together?"
    stewardship: u64,       // 0-100: "Builds for others?"
    volatility: u64,        // 0-100: "Could they betray?" (lower = safer)
    composite_score: u64,   // Weighted trust score
    archetype: String,      // e.g. "Trusted Trader", "Warlord"
    update_count: u64,
    last_updated_ms: u64,
}

SystemHealth

frontier_pulse.move
public struct SystemHealth has store, drop, copy {
    system_id: u64,
    activity_level: u64,        // 0-100
    trust_level: u64,           // 0-100
    player_count: u64,
    infrastructure_count: u64,
    tx_frequency: u64,          // 0-100
    combat_incidents: u64,
    local_chi: u64,             // (activity * 40 + trust * 60) / 100
    last_updated_ms: u64,
}

CivilizationHealthIndex

frontier_pulse.move
public struct CivilizationHealthIndex has store, drop, copy {
    overall_score: u64,       // 0-100: weighted composite
    economic_vitality: u64,   // Trade volume, market diversity
    security_index: u64,      // Inverse of kill rate
    growth_rate: u64,         // Territory expansion
    connectivity: u64,        // Gate network density
    trust_index: u64,         // Average reputation scores
    social_cohesion: u64,     // Cross-group cooperation
    diagnosis: String,        // e.g. "Flourishing", "Stressed"
    last_calculated_ms: u64,
}

On-Chain Formulas

Composite Trust Score

frontier_pulse.move
// Weights: R=25, C=25, D=20, S=20, InvV=10 (total = 100)
fun calculate_composite_score(
    reliability: u64, commerce: u64, diplomacy: u64,
    stewardship: u64, volatility: u64,
): u64 {
    let inv_volatility = MAX_SCORE - volatility; // invert: low volatility = good
    (
        reliability * 25 +
        commerce * 25 +
        diplomacy * 20 +
        stewardship * 20 +
        inv_volatility * 10
    ) / 100
}

On-Chain Trust Composite Weights

25%
25%
20%
20%
10%
Reliability (25%)
Commerce (25%)
Diplomacy (20%)
Stewardship (20%)
Inv. Volatility (10%)

CHI Overall Score

frontier_pulse.move
// Weights: E=20, Sec=15, G=15, C=15, T=20, Soc=15 (total = 100)
fun calculate_chi_overall(
    economic: u64, security: u64, growth: u64,
    connectivity: u64, trust: u64, social: u64,
): u64 {
    (
        economic * 20 + security * 15 + growth * 15 +
        connectivity * 15 + trust * 20 + social * 15
    ) / 100
}

Oracle Write Functions

All write functions require an OracleCap reference. They validate scores (0-100 range), compute derived values on-chain, and emit events for real-time subscribers.

FunctionPurposeEvent
update_player_reputationCreate/update player Trust CompassReputationUpdated
update_system_healthCreate/update system health snapshotSystemHealthUpdated
update_global_chiUpdate global CHI compositeCHIUpdated
emit_anomaly_alertEmit anomaly alert eventAnomalyAlertEmitted
remove_player_reputationDelete player from registryReputationRemoved
remove_systemDelete system from registry

Public Read Functions

These functions are callable by any contract or off-chain reader. No capabilities required.

FunctionReturns
get_reputation(reliability, commerce, diplomacy, stewardship, volatility, composite)
get_composite_scoreu64 — single composite trust score
get_archetypeString — player archetype label
meets_trust_thresholdbool — true if composite ≥ min_score
get_system_health(activity, trust, players, local_chi)
get_chi_overallu64 — global CHI score
get_chi_details(overall, economic, security, growth, connectivity, trust, social)
compare_trust(player_a_score, player_b_score)

Integration

Other dApps can use meets_trust_threshold(registry, player, 60)to gate access based on Frontier Pulse trust scores — e.g., requiring a minimum trust level for marketplace trades or alliance membership.

System Endorsements

Any wallet holder can endorse a star system on-chain — a user-driven trust signal. Each wallet can only endorse each system once (anti-spam via BCS key deduplication).

frontier_pulse.move
entry fun endorse_system(
    registry: &mut PulseRegistry,
    clock: &Clock,
    system_id: u64,
    ctx: &TxContext,
) {
    assert!(registry.systems.contains(system_id), ESystemNotFound);

    // Build unique key: sender bytes + system_id bytes
    let mut key = bcs::to_bytes(&ctx.sender());
    key.append(bcs::to_bytes(&system_id));

    assert!(!registry.endorsement_records.contains(key), EAlreadyEndorsed);
    registry.endorsement_records.add(key, true);
    // ... increment count, emit SystemEndorsed event
}