06/The desk
A desk that budgets for itself
Parity computes its own runway every cycle and, as the treasury shrinks, slows down, drops the LLM, stops trading and finally stops spending, while the gateway keeps selling quotes. The rules are computeTreasuryState and computeUnitEconomics in packages/quant-kernel/src/economics.ts.
Runway
treasury = HBAR × pool mid + USDC // Mirror Node balances
window = the last 24 h of ledger entries
observed = max(now − first entry in window, 1 h) // no wild early estimates
burn = costs in window / observed days
revenue = non-builder revenue in window / observed days
runway = treasury / (burn − revenue) // null when revenue covers burnThe agent runs on the unified books: its own costs plus the revenue, refunds and gateway gas that the gateway returns on each push.
Modes
| Mode | When | Cadence | LLM | Trading | Price multiplier |
|---|---|---|---|---|---|
| THRIVING | Default, or revenue covers burn | 1× | Allowed | Allowed | 1 |
| CONSERVING | Runway under 14 days | 2× | Off | Allowed | 1.1 |
| SURVIVAL | Runway under 3 days | 4× | Off | Off | 1.25 |
| SHUTDOWN | Treasury under SHUTDOWN_FLOOR_USD (default $1) | 8× | Off | Off | 1.25 |
Cadence multiplies POLL_INTERVAL_MS, so at the default of 60 seconds a SURVIVAL desk decides every 4 minutes. In SHUTDOWN the agent also stops publishing to HCS and stops writing to the Uniswap hook, since both cost fees; the gateway keeps selling. Each change of mode after the first cycle is announced once on the decision topic as parity.mode.v1 with from, to, reason and runwayDays.
The ledger
| Category | Kind | Written by | On-chain |
|---|---|---|---|
X402_FEE | Revenue | Gateway, after each settled payment | Yes |
HEDERA_GAS | Cost | Agent and gateway, one batch per 10 minutes, actual fee from each record | Yes |
SWAP_COST | Cost | Agent, after a live swap: quoted LP fee and impact plus the network fee | Yes |
GUARANTEE_REFUND | Cost | Gateway, after a refund transfer | Yes |
LLM_INFERENCE | Cost | Agent, per model call, at LLM_CALL_COST_USD | No, card-billed estimate |
The agent's entries and the gateway's fee and gas entries are published to the P&L topic as parity.pnl.v1, with the Hedera transaction id when there is one; a refund is published there as parity.refund.v1. The type also defines LP_YIELD, ORACLE_DATA and BORROW_INTEREST, but no code writes them today.
Builder exclusion
Payments from the operator account and from any account in BUILDER_ACCOUNT_IDS are booked with isBuilderWallet and left out of revenue, of the payer count and of the runway. Only other accounts count, which is the Hedera prize rule. The x402 asset is USDC 0.0.456858; a payment in HBAR would be valued at the pool mid.
Margin and reasoning mode
computeUnitEconomics sets QUANT_ONLY_CONSERVATION when the ledger has entries and the desk is losing money or its operating margin is under 15%. That mode raises every price by 1.5× (the margin multiplier) and, when the agent has no treasury reading, keeps the LLM off.
- Books persist across restarts: the gateway writes ledger, predictions, scores, clearances and executions to
GATEWAY_STATE_FILE(default.parity/gateway-state.json), keeping the newest 5,000 of each; the agent keeps its memory in.parity/agent-state.json. - HCS is the durable public copy of both.