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.
Module Initialization Flow
Package Published
sui client publish deploys the frontier_pulse module to Sui
AdminCap → Deployer
init() creates AdminCap and transfers to deployer wallet
PulseRegistry Shared
init() creates PulseRegistry as a shared object (public read)
Issue OracleCap
Admin calls issue_oracle_cap() to authorize the oracle backend
Oracle Writes Data
Oracle uses OracleCap to write system health, reputation, CHI, alerts
Core Structs
PlayerReputation
5-dimension behavioral profile stored per player address:
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
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
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
// 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
CHI Overall Score
// 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.
| Function | Purpose | Event |
|---|---|---|
update_player_reputation | Create/update player Trust Compass | ReputationUpdated |
update_system_health | Create/update system health snapshot | SystemHealthUpdated |
update_global_chi | Update global CHI composite | CHIUpdated |
emit_anomaly_alert | Emit anomaly alert event | AnomalyAlertEmitted |
remove_player_reputation | Delete player from registry | ReputationRemoved |
remove_system | Delete system from registry | — |
Public Read Functions
These functions are callable by any contract or off-chain reader. No capabilities required.
| Function | Returns |
|---|---|
get_reputation | (reliability, commerce, diplomacy, stewardship, volatility, composite) |
get_composite_score | u64 — single composite trust score |
get_archetype | String — player archetype label |
meets_trust_threshold | bool — true if composite ≥ min_score |
get_system_health | (activity, trust, players, local_chi) |
get_chi_overall | u64 — global CHI score |
get_chi_details | (overall, economic, security, growth, connectivity, trust, social) |
compare_trust | (player_a_score, player_b_score) |
Integration
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).
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
}