[PR #135] [MERGED] SMP 0.25.0: futures with leverage on items (/futures) #137

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/135
Author: @ludovic111
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: feat/smp-futures


📝 Commits (2)

  • 7257e32 SMP futures: the rules (perpetuals on market prices, house = insurance fund)
  • 5ba6179 SMP 0.27.0: futures in the game (/futures menu, minute marking)

📊 Changes

8 files changed (+1488 additions, -8 deletions)

View changed files

📝 native/smp/Cargo.lock (+1 -1)
📝 native/smp/Cargo.toml (+1 -1)
📝 native/smp/README.md (+19 -1)
📝 native/smp/mixins/smp/glue.rs (+171 -3)
📝 native/smp/mixins/smp/horizon-mixin.toml (+7 -1)
➕ native/smp/mixins/smp/smp_futures.rs (+1286 -0)
📝 native/smp/proof.py (+1 -1)
📝 native/smp/src/lib.rs (+2 -0)

📄 Description

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

Futures with leverage on items (smp-econ-1, Ludovic's ask, round 2). Stacked on #134 (smp-market-1's moving market, which brings mark_price/twap/volume): review only the last two commits; the diff shrinks when #134 merges. Merge after #134.

What

  • /futures long|short <item> <margin> [leverage], /futures close <n>, /futures list, /futures info <item>, and /futures alone: a chest menu of your positions (profit green, loss red, the liquidation price; click a position twice to close it), the insurance fund, help. Big liquidations (margin ≥ 1,000) are announced in chat.
  • Mark price = the market's 10-minute TWAP of the mid (Market::mark_price as the ≥5-samples guard, then twap(id, 10, now) for decimals), never the last trade. The market moves prices only on its minute timer with a 2% cap per trade, so a whale who pumps spot 20% for one minute moves the mark ~2%.
  • Marking and liquidation once a minute (on the futures' own minute check: one comparison a second when idle, nothing per tick), offline or not. A position whose equity falls to the 5% maintenance margin is liquidated; its whole margin goes to the insurance fund (the liquidation penalty, so self-liquidation never pays). A player never loses more than the margin; a gap past it is the fund's (gaps). The liquidation price is shown when a position opens.
  • The house is the counterparty through the insurance fund (a Treasury pool): profits are paid from it, losses go into it. A position that would raise the house's net exposure past what the fund could pay in a 30% move is refused (the other side stays open). A profitable close waits if the fund can't pay.
  • Fees 0.2% of size to open and to close → Treasury. Funding hourly: the crowded side pays the fund up to 0.05%/h of its size, scaled by the imbalance (pulls the book toward balance; balanced books pay none).
  • Caps: leverage 2x on any traded item, +1x per 500 items/day of market volume, max 10x; per player 20,000 coins of size on one item and 50,000 in all; open interest on an item ≤ 3 days of its market volume (in coins).
  • Persistence: positions in economy.json (ext.futures), margins in the futures pool, written with the money: a restart keeps them and the minute already marked is never marked twice.
  • Every money move is in the audit log (futures_open, futures_margin, futures_fee, futures_close, futures_liquidated, futures_loss, futures_profit, futures_funding).

Why these numbers: the mark is a 10-min average, so the maintenance margin (5%) is wider than what one minute of manipulation can move it (≤ ~2%); 10x puts the liquidation ~5% away, the most a 2%-capped market can safely carry. Thin markets get 2x since they're the easiest to push. The 30% stress test and the per-item OI cap bound what the fund can lose; fees and funding feed it.

Exploit tests (cargo test --lib, 125 passed incl. 10 futures): mark manipulation (one dumped minute in a 10-minute average doesn't liquidate a 10x long); alts long and short against each other lose (the liquidated side's whole margin goes to the fund; −283 coins for the pair in the test); restart between minutes liquidates once; an offline player liquidated is told when back (the note survives a restart); caps (leverage by volume, player, OI, fund stress, minimum margin); funding paid only by the crowded side; the menu closes only on a second click and only your own positions. clippy -D warnings, fmt. Game build: CI's horizon (smp). proof.py: config key futures. Not run locally (Mac mini disk 22 GB < 25 GB floor).

Version 0.25.0 (after #134's 0.24.0).

🤖 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/135 **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-futures` --- ### 📝 Commits (2) - [`7257e32`](https://github.com/horizon-rust/horizon-mods/commit/7257e322375fa0893647f2c716562c876d293b05) SMP futures: the rules (perpetuals on market prices, house = insurance fund) - [`5ba6179`](https://github.com/horizon-rust/horizon-mods/commit/5ba617927fc1d17e2eae6dd32bcdb24fde6e3640) SMP 0.27.0: futures in the game (/futures menu, minute marking) ### 📊 Changes **8 files changed** (+1488 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `native/smp/Cargo.lock` (+1 -1) 📝 `native/smp/Cargo.toml` (+1 -1) 📝 `native/smp/README.md` (+19 -1) 📝 `native/smp/mixins/smp/glue.rs` (+171 -3) 📝 `native/smp/mixins/smp/horizon-mixin.toml` (+7 -1) ➕ `native/smp/mixins/smp/smp_futures.rs` (+1286 -0) 📝 `native/smp/proof.py` (+1 -1) 📝 `native/smp/src/lib.rs` (+2 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Futures with leverage on items (smp-econ-1, Ludovic's ask, round 2). **Stacked on #134 (smp-market-1's moving market, which brings `mark_price`/`twap`/`volume`)**: review only the last two commits; the diff shrinks when #134 merges. Merge after #134. **What** - `/futures long|short <item> <margin> [leverage]`, `/futures close <n>`, `/futures list`, `/futures info <item>`, and `/futures` alone: a chest menu of your positions (profit green, loss red, the liquidation price; click a position twice to close it), the insurance fund, help. Big liquidations (margin ≥ 1,000) are announced in chat. - **Mark price** = the market's 10-minute TWAP of the mid (`Market::mark_price` as the ≥5-samples guard, then `twap(id, 10, now)` for decimals), never the last trade. The market moves prices only on its minute timer with a 2% cap per trade, so a whale who pumps spot 20% for one minute moves the mark ~2%. - **Marking and liquidation** once a minute (on the futures' own minute check: one comparison a second when idle, nothing per tick), offline or not. A position whose equity falls to the 5% maintenance margin is liquidated; its whole margin goes to the insurance fund (the liquidation penalty, so self-liquidation never pays). A player never loses more than the margin; a gap past it is the fund's (`gaps`). The liquidation price is shown when a position opens. - **The house is the counterparty** through the insurance fund (a Treasury pool): profits are paid from it, losses go into it. A position that would raise the house's net exposure past what the fund could pay in a 30% move is refused (the other side stays open). A profitable close waits if the fund can't pay. - **Fees** 0.2% of size to open and to close → Treasury. **Funding** hourly: the crowded side pays the fund up to 0.05%/h of its size, scaled by the imbalance (pulls the book toward balance; balanced books pay none). - **Caps**: leverage 2x on any traded item, +1x per 500 items/day of market volume, max 10x; per player 20,000 coins of size on one item and 50,000 in all; open interest on an item ≤ 3 days of its market volume (in coins). - **Persistence**: positions in `economy.json` (`ext.futures`), margins in the `futures` pool, written with the money: a restart keeps them and the minute already marked is never marked twice. - Every money move is in the audit log (`futures_open`, `futures_margin`, `futures_fee`, `futures_close`, `futures_liquidated`, `futures_loss`, `futures_profit`, `futures_funding`). **Why these numbers**: the mark is a 10-min average, so the maintenance margin (5%) is wider than what one minute of manipulation can move it (≤ ~2%); 10x puts the liquidation ~5% away, the most a 2%-capped market can safely carry. Thin markets get 2x since they're the easiest to push. The 30% stress test and the per-item OI cap bound what the fund can lose; fees and funding feed it. **Exploit tests** (`cargo test --lib`, 125 passed incl. 10 futures): mark manipulation (one dumped minute in a 10-minute average doesn't liquidate a 10x long); alts long and short against each other lose (the liquidated side's whole margin goes to the fund; −283 coins for the pair in the test); restart between minutes liquidates once; an offline player liquidated is told when back (the note survives a restart); caps (leverage by volume, player, OI, fund stress, minimum margin); funding paid only by the crowded side; the menu closes only on a second click and only your own positions. clippy -D warnings, fmt. Game build: CI's `horizon (smp)`. proof.py: config key `futures`. Not run locally (Mac mini disk 22 GB < 25 GB floor). Version 0.25.0 (after #134's 0.24.0). 🤖 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#137
No description provided.