[PR #134] [MERGED] smp 0.26.0: a moving market, /market, price charts on maps, pages pushed to Kira #136

Closed
opened 2026-11-03 04:03:33 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon-mods/pull/134
Author: @ludovic111
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: feat/smp-dyn-market


📝 Commits (2)

  • c3839da smp 0.26.0: a moving market, /market, price charts on maps, pages pushed to Kira
  • 7ec0a05 smp proof: the selling limit counts Steve's /pay (#139), Moves may read 0.0% on a minute-old history

📊 Changes

12 files changed (+2709 additions, -51 deletions)

View changed files

📝 native/smp/Cargo.lock (+1 -1)
📝 native/smp/Cargo.toml (+1 -1)
📝 native/smp/README.md (+37 -3)
📝 native/smp/mixins/smp/glue.rs (+485 -3)
📝 native/smp/mixins/smp/horizon-mixin.toml (+19 -1)
📝 native/smp/mixins/smp/smp_market.rs (+681 -24)
➕ native/smp/mixins/smp/smp_market_chart.rs (+260 -0)
➕ native/smp/mixins/smp/smp_market_menu.rs (+325 -0)
➕ native/smp/mixins/smp/smp_market_prices.rs (+709 -0)
📝 native/smp/mixins/smp/smp_store.rs (+8 -0)
📝 native/smp/proof.py (+177 -18)
📝 native/smp/src/lib.rs (+6 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

SMP 0.26.0, on main after #129 (/invsee, 0.25.0), #137 (casino, 0.23.0) and #139 (/pay cap, 0.24.0). Needs horizon#6106, merged at 975c07d; the mod is pinned there. Futures (#135, 0.27.0) stack on it.

What players get

  • Moving prices. Every market item has a factor that supply and demand move. Sales push it down and purchases push it up, by count × 1% / depth, with the depth set by rarity: 400 / mid, clamped to 2..400. A diamond moves 50 times faster per item than cobblestone.
    • Prices change only on a one-minute timer, never per trade.
    • Caps: one trade moves a price at most 2%, one player's trades on one item at most 2% a minute, and all trades together at most 5% a minute.
    • Between trades the factor drifts back to 1 with a 6 h half-life, and it stays within 0.6x..1.6x.
  • No money printing. The market-maker spread makes every item's buy at least sell × 1.6 / 0.6, raised at load if needed. So the most the market ever pays for an item is below the least it ever asks, at any two moments.
    • Two tests try it: random pumps and dumps on every item for 2,000 minutes, and a whale who buys 64 diamonds a minute for 2 h and then sells into the rise. The whale ends with less money and the Treasury gains.
    • The recipe-loop check also runs at the worst-case factors.
  • Tax. 2% of every sale and purchase goes to the Treasury via econ's to_pool("market_tax", …), shown on the receipt: Sold 3 diamond for 300 coins, tax 6 coins (2%): +294 coins.
  • Round-trip rule. Items bought from the market in the last 24 h can't be sold back; found ones still sell.
  • History. 1-minute points for 24 h and 1-hour points for 30 days (mid price, volume, items sold), kept in market_prices.json. A thread writes it every 5 minutes, and it is written again when the world closes.
  • /market [item]. A chest menu in a vanilla client:
    • Categories, plus a "movers" sheet.
    • Each item shows buy/sell, its 1 h and 24 h change (green ▲ / red ▼) and its 24 h volume, in lore.
    • An item page has buy and sell at x1/x16/x64 (price and tax on each button), "sell all", and a price chart over 24 h or 7 days, given as a filled map. The server draws the 128×128 picture and sends it as map data, and redraws it each minute for anyone carrying the map.
    • Open menus follow the prices each minute.
  • /worth adds the item's moves and 24 h volume.
  • Daily summary. At 00:00 UTC, the three biggest risers and fallers plus news from real activity (e.g. "News: Diamond supply up 40% today (…)") go to chat and to web/market.json (daily_summary). The horizon-server Discord bridge only forwards chat, join, leave, death and kick, so Kira will post the summary from the JSON.
  • web/market.json (schema 1): prices, moves, volumes, 5-minute points for the day and hourly points for 30 days. A thread builds and writes it each minute that prices move, for /hub/market through Kira.
  • Pages pushed to Kira (web.url, web.token in config.json; empty token = nothing sent). The thread that writes the pages POSTs each one of web/ that changed, gzipped, to <web.url>/<name> with Authorization: Bearer <token>. That's at most one request per page a minute, with a 20 s timeout, never on the tick thread; one at a time. Kira (horizon-rust/kira#110, merged) keeps the last copy and serves /smp/market.json and /smp/economy.json to the site. The server needs no inbound access and Kira holds no panel key. The log gets only the status and the address, never the token.
  • Read API for the futures (smp-econ-1): Market::spot, twap(id, minutes, now), mark_price(id, now) (10-minute TWAP, None below 5 points), volume(id, now, hours), history(id, Span).

Cost

  • An idle tick still costs one counter.
  • Once a second, Market::tick returns at once except at a minute boundary.
  • Once a minute, the decay runs over ~56 items, plus one set_menu_items per open /market menu.
  • Once a minute, the players' stacks are scanned for chart maps (~41 stacks a player), and each carried chart is drawn (16 KB, well under 1 ms) and sent.
  • The web page and the price history are copied on the tick, then built and written by a thread.

Config

config.json gets market.dynamic: enabled, min_factor, max_factor, half_life_hours, max_trade_impact_percent, max_player_impact_percent, max_minute_move_percent, tax_percent, round_trip_hours, depth (per item), news_percent and news_min_volume. Prices that were never edited keep their bases; tight spreads widen at load (e.g. melon slice 2/1 → 3/1, logged). enabled: false restores the fixed prices. web: url (Kira's ingest, default set), token (empty).

Checks

  • cargo test: 144 pass on the rebased head (new here: price rules, anti-arbitrage, whale, tax and round trip, chart, menu, web doc). Clippy and fmt clean; CI mod + horizon + together green.
  • native.py proof smp (two real clients) passed on the pre-rebase head, including everything new here: taxed receipts, the round-trip refusal, the price moving down after a sale and up after a purchase, buying from /market, the chart map in hand (screenshot), web/market.json and market_prices.json, and both pages arriving gzipped with the bearer token at a stand-in for Kira.
  • main's proof.py was broken by #137 (the casino's 20,000 float empties the proof's 5,000 Treasury) and #139 (/pay past the payee's daily limit now answers with the limit). Fixed here: casino.float: 0 in run 1, and the refused-pay step checks both messages. The rerun on this head is noted in a comment.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon-mods/pull/134 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/smp-dyn-market` --- ### 📝 Commits (2) - [`c3839da`](https://github.com/horizon-rust/horizon-mods/commit/c3839da0ef9e481c511f583ffbf471e6000c44a3) smp 0.26.0: a moving market, /market, price charts on maps, pages pushed to Kira - [`7ec0a05`](https://github.com/horizon-rust/horizon-mods/commit/7ec0a0516d90b8f534235b5de3e8d83292e41b6f) smp proof: the selling limit counts Steve's /pay (#139), Moves may read 0.0% on a minute-old history ### 📊 Changes **12 files changed** (+2709 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `native/smp/Cargo.lock` (+1 -1) 📝 `native/smp/Cargo.toml` (+1 -1) 📝 `native/smp/README.md` (+37 -3) 📝 `native/smp/mixins/smp/glue.rs` (+485 -3) 📝 `native/smp/mixins/smp/horizon-mixin.toml` (+19 -1) 📝 `native/smp/mixins/smp/smp_market.rs` (+681 -24) ➕ `native/smp/mixins/smp/smp_market_chart.rs` (+260 -0) ➕ `native/smp/mixins/smp/smp_market_menu.rs` (+325 -0) ➕ `native/smp/mixins/smp/smp_market_prices.rs` (+709 -0) 📝 `native/smp/mixins/smp/smp_store.rs` (+8 -0) 📝 `native/smp/proof.py` (+177 -18) 📝 `native/smp/src/lib.rs` (+6 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. SMP 0.26.0, on main after #129 (/invsee, 0.25.0), #137 (casino, 0.23.0) and #139 (/pay cap, 0.24.0). Needs horizon#6106, merged at 975c07d; the mod is pinned there. Futures (#135, 0.27.0) stack on it. ## What players get - **Moving prices.** Every market item has a factor that supply and demand move. Sales push it down and purchases push it up, by `count × 1% / depth`, with the depth set by rarity: `400 / mid`, clamped to 2..400. A diamond moves 50 times faster per item than cobblestone. - Prices change only on a **one-minute timer**, never per trade. - Caps: one trade moves a price at most 2%, one player's trades on one item at most 2% a minute, and all trades together at most 5% a minute. - Between trades the factor drifts back to 1 with a 6 h half-life, and it stays within 0.6x..1.6x. - **No money printing.** The market-maker spread makes every item's buy at least `sell × 1.6 / 0.6`, raised at load if needed. So the most the market ever pays for an item is below the least it ever asks, at any two moments. - Two tests try it: random pumps and dumps on every item for 2,000 minutes, and a whale who buys 64 diamonds a minute for 2 h and then sells into the rise. The whale ends with less money and the Treasury gains. - The recipe-loop check also runs at the worst-case factors. - **Tax.** 2% of every sale and purchase goes to the Treasury via econ's `to_pool("market_tax", …)`, shown on the receipt: `Sold 3 diamond for 300 coins, tax 6 coins (2%): +294 coins.` - **Round-trip rule.** Items bought from the market in the last 24 h can't be sold back; found ones still sell. - **History.** 1-minute points for 24 h and 1-hour points for 30 days (mid price, volume, items sold), kept in `market_prices.json`. A thread writes it every 5 minutes, and it is written again when the world closes. - **`/market [item]`.** A chest menu in a vanilla client: - Categories, plus a "movers" sheet. - Each item shows buy/sell, its 1 h and 24 h change (green ▲ / red ▼) and its 24 h volume, in lore. - An item page has buy and sell at x1/x16/x64 (price and tax on each button), "sell all", and a **price chart over 24 h or 7 days, given as a filled map**. The server draws the 128×128 picture and sends it as map data, and redraws it each minute for anyone carrying the map. - Open menus follow the prices each minute. - **`/worth`** adds the item's moves and 24 h volume. - **Daily summary.** At 00:00 UTC, the three biggest risers and fallers plus news from real activity (e.g. "News: Diamond supply up 40% today (…)") go to chat and to `web/market.json` (`daily_summary`). The horizon-server Discord bridge only forwards chat, join, leave, death and kick, so Kira will post the summary from the JSON. - **`web/market.json`** (schema 1): prices, moves, volumes, 5-minute points for the day and hourly points for 30 days. A thread builds and writes it each minute that prices move, for /hub/market through Kira. - **Pages pushed to Kira** (`web.url`, `web.token` in config.json; empty token = nothing sent). The thread that writes the pages POSTs each one of `web/` that changed, gzipped, to `<web.url>/<name>` with `Authorization: Bearer <token>`. That's at most one request per page a minute, with a 20 s timeout, never on the tick thread; one at a time. Kira (horizon-rust/kira#110, merged) keeps the last copy and serves `/smp/market.json` and `/smp/economy.json` to the site. The server needs no inbound access and Kira holds no panel key. The log gets only the status and the address, never the token. - **Read API for the futures (smp-econ-1):** `Market::spot`, `twap(id, minutes, now)`, `mark_price(id, now)` (10-minute TWAP, `None` below 5 points), `volume(id, now, hours)`, `history(id, Span)`. ## Cost - An idle tick still costs one counter. - Once a second, `Market::tick` returns at once except at a minute boundary. - Once a minute, the decay runs over ~56 items, plus one `set_menu_items` per open `/market` menu. - Once a minute, the players' stacks are scanned for chart maps (~41 stacks a player), and each carried chart is drawn (16 KB, well under 1 ms) and sent. - The web page and the price history are copied on the tick, then built and written by a thread. ## Config `config.json` gets `market.dynamic`: `enabled`, `min_factor`, `max_factor`, `half_life_hours`, `max_trade_impact_percent`, `max_player_impact_percent`, `max_minute_move_percent`, `tax_percent`, `round_trip_hours`, `depth` (per item), `news_percent` and `news_min_volume`. Prices that were never edited keep their bases; tight spreads widen at load (e.g. melon slice 2/1 → 3/1, logged). `enabled: false` restores the fixed prices. `web`: `url` (Kira's ingest, default set), `token` (empty). ## Checks - `cargo test`: 144 pass on the rebased head (new here: price rules, anti-arbitrage, whale, tax and round trip, chart, menu, web doc). Clippy and fmt clean; CI mod + horizon + together green. - `native.py proof smp` (two real clients) passed on the pre-rebase head, including everything new here: taxed receipts, the round-trip refusal, the price moving down after a sale and up after a purchase, buying from `/market`, the chart map in hand (screenshot), `web/market.json` and `market_prices.json`, and both pages arriving gzipped with the bearer token at a stand-in for Kira. - main's proof.py was broken by #137 (the casino's 20,000 float empties the proof's 5,000 Treasury) and #139 (`/pay` past the payee's daily limit now answers with the limit). Fixed here: `casino.float: 0` in run 1, and the refused-pay step checks both messages. The rerun on this head is noted in a comment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:03:33 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon-mods#136
No description provided.