Add btcli deriv: covered long/short derivative commands#1007
Open
unconst wants to merge 4 commits into
Open
Conversation
Adds a deterministic, in-process sandbox (no chain, no wallet) for the covered continuous-unwind long/short model. Implements the spec's closed-form math against a single shared CPMM pool so users can preview, open, top-up, advance time on, and close short/long positions and see how carry, break-even, close cost, and pool price interact. New command group `deriv` (alias `d`): quote / open / topup / close / advance / status / reset Pure engine in src/commands/deriv/sim.py (no btcli deps); rich render layer in deriv.py; wired into cli.py. Co-authored-by: Cursor <cursoragent@cursor.com>
Replaces the local simulator with real on-chain commands that drive the pallet-subtensor covered continuous-unwind extrinsics and read the DerivativesRuntimeApi. Commands (`deriv`, alias `d`), all over --network / wallet / --netuid: quote preview open (quote_open_short/long) positions list your positions (get_*_positions / get_*_position) market per-subnet market state (get_subnet_*_state) open open_short / open_long topup top_up_short / top_up_long close close_short / close_long (partial via --fraction) default permissionless default_short / default_long Removes the sandbox sim engine. Co-authored-by: Cursor <cursoragent@cursor.com>
btcli deriv local long/short sandbox simulatorbtcli deriv: covered long/short derivative commands
- Drop `default` from the CLI surface: it's a permissionless keeper op on other accounts' dusted positions, not something a user runs to manage their own positions. The on-chain extrinsic remains available. - Trim `positions` from 9 (truncating) columns to 7 plain-language ones: you paid P / buffer R / you owe / you'd get P+R / close cost / health. - Trim `market` to the 5 fields you need to decide to open: open allowed, base LTV, capacity left, min input, current carry. - Trim `quote` to plain terms (you pay / buffer / you owe / LTV / carry / close cost); drop internal gross-collateral and escrow rows. Core surface: quote, positions, market, open, topup, close. Co-authored-by: Cursor <cursoragent@cursor.com>
`open` now takes the hotkey the same way as other btcli commands (`--hotkey` / `--hotkey-ss58` / `--wallet.hotkey`, plus a `--validator` alias). When an SS58 is given, only the coldkey is validated — so the liability hotkey need not be your own or registered to you. You can stake to a validator and have the position's Alpha/ TAO liability held (and repaid at close) on that validator hotkey. Co-authored-by: Cursor <cursoragent@cursor.com>
basfroman
requested changes
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
btcli derivcommand group (aliasd) for the covered continuous-unwind long/short derivatives inpallet-subtensor. It drives the real on-chain extrinsics and reads theDerivativesRuntimeApi— no simulation.The economics in three terms: position input P (your capital / floor) + retained-proceeds buffer R (decays over time as carry) + a fixed liability Q (Alpha, short) / D (TAO, long) that you repay to close.
Commands
All take
--network, wallet options, and--netuid;--side short|longselects the side. A tight core loop — easy for a human or an agent.Info (read-only)
quote --netuid N --side ... -a P— preview an open: what you pay, retained buffer, what you owe to close, effective LTV, daily carry, est. close cost.positions --side ... [--netuid N] [--ss58 CK]— your open positions (you paid / buffer / you owe / you'd get P+R / close cost / health).market --netuid N --side ...— whether opens are allowed, base LTV, capacity left, min input, current carry.Lifecycle (extrinsics)
open --netuid N --side ... -a P—open_short/open_long(shows the quote, then confirms).topup --netuid N --side ... -a X—top_up_short/top_up_long(extends the carry buffer).close --netuid N --side ... [-f frac]—close_short/close_long(partial via--fraction, default full).--jsonon every command for agent use.Implementation
bittensor_cli/src/commands/deriv/deriv.py— async impls: compose +sign_and_send_extrinsicfor writes,query_runtime_api("DerivativesRuntimeApi", ...)for reads, lean rich tables. Per-side dispatch keeps short/long symmetric.bittensor_cli/cli.pyfollowing the existingliquiditypattern.Outputs are deliberately trimmed to what a trader needs to decide and act; full structured data is available via
--json. The permissionlessdefault_*keeper extrinsic is intentionally not surfaced in the CLI (niche, acts on other accounts).Test plan
Verified end-to-end against a local subtensor dev network (derivatives enabled via sudo):
deriv market(short & long)deriv quote(short & long)deriv open(short & long)deriv positions(short & long)deriv topupderiv close -f 0.5then full close (short & long)