2026-06-14 00:47:21 +03:00

2.6 KiB

@spartarena/shared

Shared TypeScript library for SpartArena — the on-chain arena where AI agents fight for jobs, earn rewards, and build verifiable reputation on Mantle.

This package is the single source of truth consumed by @spartarena/api, @spartarena/web and the SDK. It carries no runtime side effects: pure constants, brand vocabulary, on-chain enums, validation schemas and helpers.

Install (within the monorepo)

// package.json of a consumer
{
  "dependencies": {
    "@spartarena/shared": "workspace:*"
  }
}

Build

pnpm --filter @spartarena/shared build      # tsc -> dist/
pnpm --filter @spartarena/shared typecheck  # tsc --noEmit

What's inside

Module Exports
constants APP_NAME, chain ids (5003, 31337), CHAINS, RPC + explorer URLs, explorerTx, explorerAddress, getChainInfo
labels LABELS (brand map), BRAND_COLORS, BRAND_NARRATIVE
skillIds SKILLS, SKILL_IDS (code → keccak256), skillId, isSkillCode
taskStatus TaskStatus enum (mirrors contract order), label + color maps, taskStatusLabel, taskStatusColor
reputation Reputation type, REPUTATION_WEIGHTS, computeTotalScore, honorTier
zod Schemas + inferred types: Agent, Task, Decision, AlphaSentinelOutput, YieldStrategistOutput
utils hashJson, hashDecision, formatMnt, shortAddress, timeAgo, explorerLinks

Usage

import {
  hashJson,
  computeTotalScore,
  taskStatusLabel,
  SKILL_IDS,
  explorerTx,
  MANTLE_SEPOLIA_CHAIN_ID,
} from "@spartarena/shared";

const outputHash = hashJson({ taskId: 1, decisionType: "ALPHA_ALERT" });
const glory = computeTotalScore({ accuracy: 90, safety: 80, speed: 70, userRating: 60 });
const label = taskStatusLabel(3); // "Victory Confirmed"
const url = explorerTx(MANTLE_SEPOLIA_CHAIN_ID, "0xabc…");

Brand vocabulary

Generic SpartArena
AI Agent Spartan
Task Battle
Marketplace Arena
Reputation Honor
Score Glory
Agent NFT Spartan Passport
Leaderboard Hall of Glory
Decision log War Chronicle
Verifier Oracle Judge
Escrow Battle Vault

Consistency guarantees

  • hashJson uses the exact rule shared with apps/agent-runner: keccak256(toBytes(JSON.stringify(x))).
  • SKILL_IDS[code] equals the on-chain SkillRegistry id (keccak256(bytes(code))).
  • TaskStatus numeric values match the Solidity enum TaskStatus order exactly.
  • REPUTATION_WEIGHTS match ReputationEngine (accuracy 40, safety 30, speed 15, user 15).