Engine

Accounting & NAV

How the engine values the vault, books P&L, takes snapshots and suggests rebalances.

The books live in memory (engine/src/portfolio.ts) and are saved to Postgres every 5 seconds.

Holdings and positions

  • Holdings: an amount per venue:asset, with venues elysium and hypercore (for example hypercore:USDC).
  • Positions: one per market, with signed size, average entry price, realized P&L, fees, funding, volume and trade count. A position belongs to the first strategy that trades its market.

Average cost: adding on the same side averages the entry price; reducing realizes closed size × (price − entry) with the position's sign; flipping through zero opens the remainder at the fill price.

Spot and pool fills move both assets. Spot fees are charged in the quote asset; pool fees are already inside the swap amounts. Perp fills only move USDC on HyperCore (realized P&L minus the fee) and the position.

Prices (marks)

AssetMark
USDC1
HYPEmid of HyperCore's HYPE spot book (@107), else the HYPE perp
WHYPEsame as HYPE
KNTQmid of @334
MOTIONMontra pool price (HYPE per token) × HYPE

Mid = (best bid + best ask) / 2 from the live book, else Hyperliquid's allMids.

text
NAV          = Σ holdings × mark   (both venues)   + Σ perp unrealized P&L
strategy P&L = realized + unrealized + funding − fees

Holdings without a price are left out of NAV and reported.

Snapshots

Every SNAPSHOT_SECONDS (60 s) the engine saves a row with: NAV, HYPE price, value on Elysium, value on HyperCore, total strategy P&L, revenue to date, drawdown, HYPE exposure (all HYPE held plus the perp position) and P&L per strategy. These feed the app's charts and GET /api/v1/vault/history.

Revenue and "reinvested"

Revenue is the sum of accrued creator fees (USD). The API's reinvestedUsd is revenue × 0.5 + strategy P&L: the treasury's half of the fees plus what the strategies made.

Rebalance suggestions

After each snapshot the engine compares the share of NAV on HyperCore with a 55 % target. If it is off by 15 points or more, it suggests moving |share − 0.55| × NAV / HYPE price HYPE between the venues. It writes a transfers row with status suggested and a transfer event, and never repeats the same suggestion within 6 hours. The Safe executes it; the engine never moves funds between venues.

Paper seeding and restarts

On the very first start the paper treasury is seeded (see Paper & live modes) and its starting NAV is saved in engine_state.paper-start. On every later start the books are reloaded from the balances and positions tables, with fees and volumes rebuilt from fills. In live mode the starting NAV is the first one synced from the venues.

Ledger events

KindWritten when
engineStart, stop, paper treasury seeded
riskKill switch, drawdown limit, stale book pulled
revenueCreator fees accrued
harvestFees claimed on chain (live)
swapMontra pool trade
hedgeHedge adjusted
fundingFunding booked (paper)
arbArbitrage executed
transferRebalance suggested
strategyStrategy paused or resumed by an operator

Read them with GET /api/v1/ledger or on the app's Ledger page.