From e408409b77b58ea616d79cc6a8687cbf4870220e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 18 Jul 2026 03:55:43 +0000 Subject: [PATCH] Resolve economy organ toolchains: ECLiPSe 7.2 + COIN-OR, M3g to Fortran, BoundedPrediction fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hook: - ECLiPSe upgraded 7.1_13 → 7.2_13, adds ic + eplex (if_osiclpcbc) with COIN-OR system dep, sha256 pinned, ECLIPSEDIR exported, correct paths (lib/x86_64_linux/eclipse.exe not bin/) - fpm switched from GitHub binary download to pip (0.12.0) — proxy blocks GitHub release downloads in this environment - Alire download gets sha256 verification on both install and presence check - Fortran comment updated M3d,M3e → M3d,M3e,M3g - Foundry section comment clarified as hosted separately Specs: - M3g §3: Zig → Fortran 2018 (gfortran/fpm/OpenBLAS, hand-rolled Riccati) - M3 hub §3: sub-process list Zig(M3g) → Fortran(M3g) - M3 hub §5: BoundedPrediction adds token_ticker and recent_shift (ground truth from M2, same source as correctness scoring and calibration) - M3b §3: ECLiPSe 7.2 + ic + eplex (COIN-OR CLP/CBC) - M3f §3: ECLiPSe 7.2 + ic + eplex (COIN-OR CLP/CBC) - M3c §3: Solidity + Foundry confirmed, hosted separately, same Hub path --- .claude/hooks/install-toolchains.sh | 71 ++++++++++++------- core/docs/plans/M3-sims-hub.md | 15 ++-- core/docs/plans/M3b-sociological-sims.md | 11 +-- core/docs/plans/M3c-amm-liquidity-sims.md | 8 ++- core/docs/plans/M3f-consensus-staking-sims.md | 9 +-- .../plans/M3g-market-microstructure-sims.md | 8 ++- 6 files changed, 77 insertions(+), 45 deletions(-) diff --git a/.claude/hooks/install-toolchains.sh b/.claude/hooks/install-toolchains.sh index 65b1a2f..2c53c52 100755 --- a/.claude/hooks/install-toolchains.sh +++ b/.claude/hooks/install-toolchains.sh @@ -40,17 +40,21 @@ fi # --------------------------------------------------------------------------- # Alire (alr) 2.1.1 # --------------------------------------------------------------------------- +ALR_SHA256="2e2b8de009b793ad2aed10096e162649bbcc5b0711e3c21785ebe8a1261c5d64" if command -v alr >/dev/null 2>&1; then - log "alr already present; skipping Alire install." + log "alr present; verifying integrity." + echo "$ALR_SHA256 $(command -v alr)" | sha256sum -c - || die "Installed alr sha256 mismatch — binary may be corrupt." else log "Installing Alire (alr) 2.1.1 ..." curl -sSL -o /tmp/alr.zip https://github.com/alire-project/alire/releases/download/v2.1.1/alr-2.1.1-bin-x86_64-linux.zip || die "Alire download failed." - ( cd /tmp && unzip -o -q alr.zip && sudo cp bin/alr /usr/local/bin/alr && chmod +x /usr/local/bin/alr ) || die "Alire unzip/copy failed." + ( cd /tmp && unzip -o -q alr.zip ) || die "Alire unzip failed." + echo "$ALR_SHA256 /tmp/bin/alr" | sha256sum -c - || die "Downloaded alr sha256 mismatch." + sudo cp /tmp/bin/alr /usr/local/bin/alr && chmod +x /usr/local/bin/alr || die "Alire copy failed." log "alr installed to /usr/local/bin/alr" fi # --------------------------------------------------------------------------- -# Fortran 2018 (gfortran) + OpenBLAS (economy organ: M3d, M3e) +# Fortran 2018 (gfortran) + OpenBLAS (economy organ: M3d, M3e, M3g) # --------------------------------------------------------------------------- if command -v gfortran >/dev/null 2>&1; then log "gfortran already present; skipping." @@ -60,16 +64,14 @@ else fi # --------------------------------------------------------------------------- -# fpm — Fortran Package Manager (economy organ: M3d, M3e) +# fpm — Fortran Package Manager (economy organ: M3d, M3e, M3g) # --------------------------------------------------------------------------- -if command -v fpm >/dev/null 2>&1; then +if command -v fpm >/dev/null 2>&1 && fpm --version >/dev/null 2>&1; then log "fpm already present; skipping." else - log "Installing fpm ..." - FPM_URL="https://github.com/fortran-lang/fpm/releases/download/v0.10.1/fpm-0.10.1-linux-x86_64" - curl -sSL -o /tmp/fpm "$FPM_URL" || die "fpm download failed." - sudo cp /tmp/fpm /usr/local/bin/fpm && sudo chmod +x /usr/local/bin/fpm || die "fpm install failed." - log "fpm installed to /usr/local/bin/fpm" + log "Installing fpm via pip ..." + pip install --quiet fpm==0.12.0 || die "pip install fpm failed." + log "fpm $(fpm --version 2>&1 | head -1)" fi # --------------------------------------------------------------------------- @@ -83,21 +85,38 @@ else fi # --------------------------------------------------------------------------- -# ECLiPSe Prolog (economy organ: M3b, M3f) +# ECLiPSe Prolog 7.2_13 (economy organ: M3b, M3f) +# Bundles: basic (includes ic), if_osiclpcbc (COIN-OR backend for eplex LP/MIP) # --------------------------------------------------------------------------- -if command -v eclipse >/dev/null 2>&1 || [ -x /opt/eclipseclp/bin/x86_64_linux/eclipse ]; then - log "ECLiPSe Prolog already present; skipping." +ECL_MIRROR="https://www.mirrorservice.org/sites/eclipseclp.org/Distribution/CurrentRelease" +ECL_PLATFORM="7.2_13%20x86_64_linux%20Intel-64bit-Linux" +ECL_BASIC_SHA256="df12d7ab694331f54cd87e5861ceec2ddd41028d1cccf6496ec56ea6755600a3" +ECL_OSICLPCBC_SHA256="a90d34a19606c916a684b8a8927dda441b743a11d07dbfe0de007c38f9844df6" +if [ -x /opt/eclipseclp/lib/x86_64_linux/eclipse.exe ]; then + log "ECLiPSe Prolog present; verifying." + [ -f /opt/eclipseclp/lib/x86_64_linux/ic.so ] || die "ECLiPSe ic library missing." + [ -f /opt/eclipseclp/lib/x86_64_linux/seosiclpcbc.so ] || die "ECLiPSe eplex COIN-OR backend missing." else - log "Installing ECLiPSe Prolog ..." - ECLIPSE_URL="https://eclipseclp.org/Distribution/Current/7.1_13/x86_64_linux/eclipse_basic.tgz" - curl -sSL -o /tmp/eclipse_basic.tgz "$ECLIPSE_URL" || die "ECLiPSe download failed." + log "Installing ECLiPSe Prolog 7.2_13 ..." + sudo apt-get install -y coinor-libcbc3.1 || die "COIN-OR CBC system library install failed." sudo mkdir -p /opt/eclipseclp || die "Could not create /opt/eclipseclp." - sudo tar -xzf /tmp/eclipse_basic.tgz -C /opt/eclipseclp || die "ECLiPSe extraction failed." - log "ECLiPSe installed to /opt/eclipseclp" + curl -sSL -o /tmp/eclipse_basic.tgz "$ECL_MIRROR/$ECL_PLATFORM/eclipse_basic.tgz" \ + || die "ECLiPSe basic download failed." + echo "$ECL_BASIC_SHA256 /tmp/eclipse_basic.tgz" | sha256sum -c - \ + || die "ECLiPSe basic sha256 mismatch." + sudo tar -xzf /tmp/eclipse_basic.tgz -C /opt/eclipseclp \ + || die "ECLiPSe basic extraction failed." + curl -sSL -o /tmp/if_osiclpcbc.tgz "$ECL_MIRROR/$ECL_PLATFORM/if_osiclpcbc.tgz" \ + || die "ECLiPSe COIN-OR download failed." + echo "$ECL_OSICLPCBC_SHA256 /tmp/if_osiclpcbc.tgz" | sha256sum -c - \ + || die "ECLiPSe COIN-OR sha256 mismatch." + sudo tar -xzf /tmp/if_osiclpcbc.tgz -C /opt/eclipseclp \ + || die "ECLiPSe COIN-OR extraction failed." + log "ECLiPSe 7.2_13 installed to /opt/eclipseclp (basic + ic + eplex/COIN-OR)" fi -# --------------------------------------------------------------------------- --------------------------------------------------------------------------- -# Solidity / Foundry (economy organ: M3c) +# --------------------------------------------------------------------------- +# Solidity / Foundry (economy organ: M3c — hosted separately) # --------------------------------------------------------------------------- # if command -v forge >/dev/null 2>&1; then # log "forge (Foundry) already present; skipping." @@ -111,14 +130,16 @@ fi # --------------------------------------------------------------------------- # PATH for tools not in standard locations. # --------------------------------------------------------------------------- -EXTRA_PATHS='/root/.local/share/ponyup/bin:/opt/eclipseclp/bin/x86_64_linux' +EXTRA_PATHS='/root/.local/share/ponyup/bin:/opt/eclipseclp/lib/x86_64_linux' FOUNDRY_PATH="$HOME/.foundry/bin" FULL_PATH_LINE="export PATH=$EXTRA_PATHS:$FOUNDRY_PATH:\$PATH" -if [ -f "$HOME/.bashrc" ] && grep -qF "eclipseclp" "$HOME/.bashrc"; then - log "Toolchain PATH lines already in ~/.bashrc; skipping." +ECLIPSEDIR_LINE="export ECLIPSEDIR=/opt/eclipseclp" +if [ -f "$HOME/.bashrc" ] && grep -qF "ECLIPSEDIR" "$HOME/.bashrc"; then + log "Toolchain PATH/env lines already in ~/.bashrc; skipping." else - log "Appending toolchain PATH lines to ~/.bashrc" - echo "$FULL_PATH_LINE" >> "$HOME/.bashrc" || die "Could not append to ~/.bashrc." + log "Appending toolchain PATH/env lines to ~/.bashrc" + { echo "$FULL_PATH_LINE"; echo "$ECLIPSEDIR_LINE"; } >> "$HOME/.bashrc" \ + || die "Could not append to ~/.bashrc." fi log "Done." diff --git a/core/docs/plans/M3-sims-hub.md b/core/docs/plans/M3-sims-hub.md index 81c50aa..4e56d8c 100644 --- a/core/docs/plans/M3-sims-hub.md +++ b/core/docs/plans/M3-sims-hub.md @@ -18,8 +18,8 @@ established); specific model parameters C1. ## 3. Language & location **Tcl** · `src/economy/sims/`. The hub is a syntax-agnostic coordinator: Tcl manages lifecycle, tick-advancement, and query routing for sub-sims in their native runtimes via -stdin/stdout JSON — **Fortran** (M3d, M3e), **Prolog** (M3b, M3f), **R** (M3a), -**Solidity** (M3c), **Zig** (M3g). Tcl imposes no type system or paradigm on the +stdin/stdout JSON — **Fortran** (M3d, M3e, M3g), **Prolog** (M3b, M3f), **R** (M3a), +**Solidity** (M3c). Tcl imposes no type system or paradigm on the sub-processes it orchestrates. ## 4. Does / does-not @@ -50,17 +50,22 @@ sub-processes it orchestrates. `SimType` ∈ { `statistical`, `sociological`, `amm_liquidity`, `mev_adversarial`, `tokenomics_macro`, `consensus_staking`, `market_microstructure` } (M3a–M3g). - `BoundedPrediction { value, lower_bound, upper_bound, confidence, correctness, certainty, - time_horizon, sim_type, timestamp }`. + time_horizon, sim_type, timestamp, token_ticker, recent_shift }`. Every output is bounded — no point estimates without uncertainty ranges. Three quality metrics, each ∈ [0.00, 10.00]: **confidence** — how sure the model is of this prediction; - **correctness** — how accurate the model has been historically; + **correctness** — how accurate the model has been historically (scored against literal + market values from M2); **certainty** — how stable the estimate is across perturbations. + **token_ticker** — which asset this prediction concerns (e.g. `"ETH"`, `"BTC"`). + **recent_shift** — literal observed market movement (ground truth from M2, not sim output). + Same M2 source feeds calibration and `correctness` scoring. Gain rates print as `lower - value - upper / 10.00` (e.g. `2.31 - 4.44 - 7.11 / 10.00 gain over next 30 days`); the denominator aids legibility — gain is not capped at 10.00. Example: `{ value: 7.2, lower_bound: 5.8, upper_bound: 8.9, confidence: 7.30, - correctness: 8.10, certainty: 6.50, time_horizon: "4h", sim_type: "amm_liquidity" }`. + correctness: 8.10, certainty: 6.50, time_horizon: "4h", sim_type: "amm_liquidity", + token_ticker: "ETH", recent_shift: -0.023 }`. - `status(sim_type?) -> { running, pop_count, last_calibration, data_freshness }` — health check. - `calibrate(sim_type, feed_data: [NormalizedDatum])` — Data Feeds (M2) pushes live data for model recalibration. diff --git a/core/docs/plans/M3b-sociological-sims.md b/core/docs/plans/M3b-sociological-sims.md index abca9a6..228d9a3 100644 --- a/core/docs/plans/M3b-sociological-sims.md +++ b/core/docs/plans/M3b-sociological-sims.md @@ -17,11 +17,12 @@ solvers C3). Crypto pump-and-dump ABM C3 (3-agent protocol validated on historic Pop behavioral models C1. ## 3. Language & location -ECLiPSe Prolog · `src/economy/sims/sociological/`. **Prolog** — game-theoretic equilibria, replicator -dynamics, and strategy evolution are naturally expressed as logical relations over population -states; Nash equilibrium search is constraint satisfaction. Needs efficient population iteration, -strategy mutation, PDE solvers for MFG (HJB + Fokker-Planck), and bandit algorithms -(UCB/Thompson). +**ECLiPSe Prolog 7.2** · `src/economy/sims/sociological/`. Libraries: **ic** (interval +constraints — bounds propagation for BoundedPrediction ranges), **eplex** (LP/MIP via COIN-OR +CLP/CBC — Nash equilibrium computation). Game-theoretic equilibria, replicator dynamics, and +strategy evolution are naturally expressed as logical relations over population states; Nash +equilibrium search is constraint satisfaction. Needs efficient population iteration, strategy +mutation, PDE solvers for MFG (HJB + Fokker-Planck), and bandit algorithms (UCB/Thompson). ## 4. Does / does-not - **Does:** simulate populations of behavioral archetypes competing in a market; apply diff --git a/core/docs/plans/M3c-amm-liquidity-sims.md b/core/docs/plans/M3c-amm-liquidity-sims.md index 3caa969..53056cf 100644 --- a/core/docs/plans/M3c-amm-liquidity-sims.md +++ b/core/docs/plans/M3c-amm-liquidity-sims.md @@ -12,9 +12,11 @@ impermanent loss formula C5 (closed-form: $\text{IL}(r) = \frac{2\sqrt{r}}{1+r} simulation parameterization C1. ## 3. Language & location -TBD · `src/economy/sims/amm/`. **Solidity** — on-chain-equivalent fixed-point arithmetic -reproduces the exact invariant calculations DEXs execute, eliminating precision-mismatch bugs -between sim and production contracts. +**Solidity** + **Foundry** (forge, anvil) · `src/economy/sims/amm/`. Foundry is hosted +separately from the session container — not a session-start install. M3c's output enters the +system through Hub like every other sim, same `BoundedPrediction` schema, same M2 path. +On-chain-equivalent fixed-point arithmetic reproduces the exact invariant calculations DEXs +execute, eliminating precision-mismatch bugs between sim and production contracts. ## 4. Does / does-not - **Does:** simulate constant-product pools with fee parameter $\gamma$: diff --git a/core/docs/plans/M3f-consensus-staking-sims.md b/core/docs/plans/M3f-consensus-staking-sims.md index 104a996..1723a44 100644 --- a/core/docs/plans/M3f-consensus-staking-sims.md +++ b/core/docs/plans/M3f-consensus-staking-sims.md @@ -14,10 +14,11 @@ validator populations C4 (Lasry & Lions 2007; validator-specific application C3) simulation parameterization C1. ## 3. Language & location -TBD · `src/economy/sims/consensus/`. **Prolog** — Markov chain transition rules, Nash -equilibrium search, and replicator dynamics are constraint-satisfaction problems over validator -populations; Prolog's backtracking search finds equilibria declaratively rather than -imperatively iterating toward them. +**ECLiPSe Prolog 7.2** · `src/economy/sims/consensus/`. Libraries: **ic** (interval +constraints), **eplex** (LP/MIP via COIN-OR CLP/CBC — Nash equilibrium via linear programming). +Markov chain transition rules, Nash equilibrium search, and replicator dynamics are +constraint-satisfaction problems over validator populations; Prolog's backtracking search finds +equilibria declaratively rather than imperatively iterating toward them. ## 4. Does / does-not - **Does:** simulate validator populations where honesty evolves via **evolutionary game theory** diff --git a/core/docs/plans/M3g-market-microstructure-sims.md b/core/docs/plans/M3g-market-microstructure-sims.md index a3c5810..062d966 100644 --- a/core/docs/plans/M3g-market-microstructure-sims.md +++ b/core/docs/plans/M3g-market-microstructure-sims.md @@ -15,9 +15,11 @@ optimal execution C5 (industry standard since 2001; crypto adaptations validated Kurz CMC thesis). DEX-specific microstructure C2 (emerging). Implementation C1. ## 3. Language & location -TBD · `src/economy/sims/microstructure/`. **Zig** — tick-level event-driven simulation with -deterministic memory layout, no GC pauses, and sub-microsecond latency for Riccati solvers and -order-book state updates; comptime generics eliminate runtime dispatch on hot paths. +**Fortran 2018** (gfortran) · `src/economy/sims/microstructure/`. Build: **fpm**. Dependencies: +**OpenBLAS** (LAPACK/BLAS via native Fortran interfaces). Hand-rolled: Riccati ODE solver, +order-book state arrays, JSON I/O against fixed schemas. Almgren-Chriss optimal execution is a +dense ODE (Riccati equations) — Fortran's home turf; LAPACK is native, array intrinsics map +directly to order-book depth vectors, and zero new toolchain is needed (same as M3d/M3e). ## 4. Does / does-not - **Does:** simulate order flow across venues (DEXs and CEXs); model bid-ask spread dynamics as a