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

computeTreasuryStatets
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 burn

The agent runs on the unified books: its own costs plus the revenue, refunds and gateway gas that the gateway returns on each push.

Modes

ModeWhenCadenceLLMTradingPrice multiplier
THRIVINGDefault, or revenue covers burn1×AllowedAllowed1
CONSERVINGRunway under 14 days2×OffAllowed1.1
SURVIVALRunway under 3 days4×OffOff1.25
SHUTDOWNTreasury under SHUTDOWN_FLOOR_USD (default $1)8×OffOff1.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

CategoryKindWritten byOn-chain
X402_FEERevenueGateway, after each settled paymentYes
HEDERA_GASCostAgent and gateway, one batch per 10 minutes, actual fee from each recordYes
SWAP_COSTCostAgent, after a live swap: quoted LP fee and impact plus the network feeYes
GUARANTEE_REFUNDCostGateway, after a refund transferYes
LLM_INFERENCECostAgent, per model call, at LLM_CALL_COST_USDNo, 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.