#!/usr/bin/env python3 """Alpha Arena season 1: do the rebuilt accounts agree with Nof1's own record and the exchange's ledger? Served at https://oaia.fun/recompute_alpha_anchor.py. Python 3, standard library only. Written AFTER the scored run, so read this as a check, not as part of the method. It changes no percentile: recompute_alpha_arena.py reads none of it, and a monkey's coins do not depend on the size of an account. 1. Nof1's readings. The Internet Archive captured https://nof1.ai/api/account-totals on 2025-11-06 at 02:27:15Z: each model's dollar_equity about once an hour, with the price of each open position. At every reading up to the bell, the account is rebuilt from the exchange's own records: transfers in so far + realized + funding - fees + open positions at that reading's price. 2. The ledger. Transfers in (the $10,000 and the small ones from other wallets) + every result and funding payment to this day - fees - the sums sent out should equal the wallet's balance today. 3. The recap. The account at the bell from recompute_alpha_arena.py, plus the transfers from other wallets it leaves out, against the figure it reads. Usage, in a folder holding alpha_arena_s1.json, alpha_arena.json and alpha_arena_anchor.json: python3 recompute_alpha_anchor.py rebuild every row; exit code 0 means all match and stay inside the limits python3 recompute_alpha_anchor.py --fetch download again and apply the limits; the file is replaced only if they hold. A fresh file then matches itself, so set the printed lines against the page's table. python3 recompute_alpha_anchor.py --fetch saved.json the same, with a saved copy of the capture """ import gzip import hashlib import json import statistics import sys import time import urllib.error import urllib.request INFO = "https://api.hyperliquid.xyz/info" CAPTURE = "20251106022715" READINGS = f"https://web.archive.org/web/{CAPTURE}id_/https://nof1.ai/api/account-totals" MODEL_IDS = {"Qwen 3 Max": "qwen3-max", "DeepSeek V3.1": "deepseek-chat-v3.1", "Claude Sonnet 4.5": "claude-sonnet-4-5", "Gemini 2.5 Pro": "gemini-2.5-pro", "Grok 4": "grok-4", "GPT-5": "gpt-5"} PERP_IN = ("subAccountTransfer", "internalTransfer") # The limits the page states: median reading off in dollars, percent of the recap, ledger off in dollars. MEDIAN_LIMIT, RECAP_LIMIT, LEDGER_LIMIT = 5.0, 0.5, 2.0 def _info(body): request = urllib.request.Request(INFO, data=json.dumps(body).encode(), headers={"Content-Type": "application/json"}) with urllib.request.urlopen(request, timeout=30) as reply: return json.load(reply) def _pages(kind, wallet, key, since): rows = {} while True: page = _info({"type": kind, "user": wallet, "startTime": since}) if not page: return [rows[k] for k in sorted(rows)] rows.update((key(row), row) for row in page) newest = max(row["time"] for row in page) if newest == since: return [rows[k] for k in sorted(rows)] since = newest def _capture(saved): """The Archive's copy, or a saved one; the Archive answers 429 when asked too often.""" if saved: with open(saved, "rb") as src: return src.read() request = urllib.request.Request(READINGS, headers={"User-Agent": "Mozilla/5.0"}) for wait in (30, 60, 0): try: with urllib.request.urlopen(request, timeout=120) as reply: return reply.read() except urllib.error.HTTPError as error: if error.code != 429 or not wait: raise time.sleep(wait) def fetch(season, saved=None): raw = _capture(saved) plain = gzip.decompress(raw) if raw[:2] == b"\x1f\x8b" else raw capture = json.loads(plain) bell = season["bell"] models = {} for model, model_id in MODEL_IDS.items(): wallet = season["wallets"][model].lower() rows = sorted((r for r in capture["accountTotals"] if r["model_id"] == model_id), key=lambda r: r["timestamp"]) readings = [[r["timestamp"], r["dollar_equity"], {c: p["current_price"] for c, p in r["positions"].items()}] for r in rows] ledger = _info({"type": "userNonFundingLedgerUpdates", "user": wallet, "startTime": season["t0"] - 86400000}) transfers_in, sent_out = [], [] for row in ledger: delta = row["delta"] if delta["type"] in PERP_IN and delta["destination"].lower() == wallet: transfers_in.append([row["time"], float(delta["usdc"])]) elif delta["type"] == "send" and delta["user"].lower() == wallet: sent_out.append([row["time"], float(delta["amount"])]) after = _pages("userFillsByTime", wallet, lambda f: (f["time"], f["tid"]), bell + 1) funding = _pages("userFunding", wallet, lambda f: (f["time"], f["delta"]["coin"]), bell + 1) balance = float(_info({"type": "clearinghouseState", "user": wallet})["marginSummary"]["accountValue"]) models[model] = { "readings": readings, "transfers_in": transfers_in, "sent_out": sent_out, "after_bell_fills": [[f["time"], float(f["closedPnl"]), float(f["fee"])] for f in after], "after_bell_funding": [[f["time"], float(f["delta"]["usdc"])] for f in funding], "balance_today": balance, } print(f"{model}: {len(readings)} readings, {len(after)} fills after the bell, balance {balance:.2f}") return {"capture": READINGS, "capture_sha256": hashlib.sha256(plain).hexdigest(), "server_time": capture["serverTime"], "models": models} def account_at(season, model, transfers_in, moment, prices): """The perp account at `moment` (ms), open positions at the reading's own prices.""" money = sum(usdc for t, usdc in transfers_in if t <= moment) open_at = {} for t, _, coin, side, size, price, before, closed, fee in sorted( season["fills"][model], key=lambda f: (f[0], f[2], f[6] if f[3] == "B" else -f[6])): if t > moment or coin not in season["marks"]: continue money += closed - fee p = open_at.setdefault(coin, {"size": 0.0, "entry": price}) after = round(before + (size if side == "B" else -size), 8) if abs(after) > abs(before): p["entry"] = (p["entry"] * abs(before) + price * size) / abs(after) p["size"] = after money += sum(usdc for t, _, usdc in season["funding"][model] if t <= moment) return money + sum((prices[c] - p["entry"]) * p["size"] for c, p in open_at.items() if abs(p["size"]) > 1e-9 and c in prices) def build_rows(season, result, inputs): bell = season["bell"] scored = {r["model"]: r for r in result["rows"]} rows = [] for model in MODEL_IDS: data = inputs["models"][model] offs = [] for stamp, equity, prices in data["readings"]: moment = int(stamp * 1000) if moment <= bell: offs.append(account_at(season, model, data["transfers_in"], moment, prices) - equity) nearest = min(data["readings"], key=lambda r: abs(r[0] * 1000 - bell)) outside = sum(usdc for t, usdc in data["transfers_in"] if t <= bell) - season["start"] within = [f for f in season["fills"][model] if season["t0"] <= f[0] <= bell and f[2] in season["marks"]] computed = (sum(usdc for _, usdc in data["transfers_in"]) - sum(usdc for _, usdc in data["sent_out"]) + sum(f[7] - f[8] for f in within) + sum(usdc for t, _, usdc in season["funding"][model] if t <= bell) + sum(closed - fee for _, closed, fee in data["after_bell_fills"]) + sum(usdc for _, usdc in data["after_bell_funding"])) rebuilt = scored[model]["rebuilt_final"] recap = scored[model]["reported_final"] rows.append({ "model": model, "readings": len(offs), "median_off": round(statistics.median(abs(o) for o in offs), 2), "largest_off": round(max(abs(o) for o in offs), 2), "nearest_bell_at": int(nearest[0]), "nearest_bell_nof1": round(nearest[1], 2), "outside_transfers": round(outside, 2), "rebuilt_with_transfers": round(rebuilt + outside, 2), "recap": recap, "off_recap_pct": round((rebuilt + outside - recap) / recap * 100, 2), "ledger_computed": round(computed, 2), "balance_today": round(data["balance_today"], 2), "ledger_off": round(computed - data["balance_today"], 2), "after_bell_fills": len(data["after_bell_fills"]), "after_bell_realized": round(sum(f[1] for f in data["after_bell_fills"]), 2), "last_fill_at": max((f[0] for f in data["after_bell_fills"]), default=None), }) return rows def report(rows, stored): """Print each row, against the stored rows if there are any, and return the exit code.""" bad = 0 for i, row in enumerate(rows): same = stored is None or (i < len(stored) and row == stored[i]) inside = (row["median_off"] <= MEDIAN_LIMIT and abs(row["off_recap_pct"]) <= RECAP_LIMIT and abs(row["ledger_off"]) <= LEDGER_LIMIT) bad += not (same and inside) print(f"{row['model']:18s} {row['readings']} readings, median off ${row['median_off']:.2f}, largest " f"${row['largest_off']:.2f} | with transfers {row['off_recap_pct']:+.2f}% of the recap | ledger off " f"${row['ledger_off']:.2f} {'' if same else 'MISMATCH '}{'' if inside else 'OUTSIDE THE LIMIT'}") print(f"{len(rows)} rows, {bad} mismatches") return 1 if bad or (stored is not None and len(rows) != len(stored)) else 0 def main(): with open("alpha_arena_s1.json", encoding="utf-8") as src: season = json.load(src) with open("alpha_arena.json", encoding="utf-8") as src: result = json.load(src) if "--fetch" in sys.argv[1:]: doc = fetch(season, sys.argv[sys.argv.index("--fetch") + 1] if sys.argv[-1] != "--fetch" else None) doc["rows"] = build_rows(season, result, doc) code = report(doc["rows"], None) if code == 0: with open("alpha_arena_anchor.json", "w", encoding="utf-8") as out: json.dump(doc, out, separators=(",", ":")) return code with open("alpha_arena_anchor.json", encoding="utf-8") as src: doc = json.load(src) return report(build_rows(season, result, doc), doc["rows"]) if __name__ == "__main__": sys.exit(main())