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 venueselysiumandhypercore(for examplehypercore: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)
| Asset | Mark |
|---|---|
| USDC | 1 |
| HYPE | mid of HyperCore's HYPE spot book (@107), else the HYPE perp |
| WHYPE | same as HYPE |
| KNTQ | mid of @334 |
| MOTION | Montra pool price (HYPE per token) × HYPE |
Mid = (best bid + best ask) / 2 from the live book, else Hyperliquid's allMids.
NAV and P&L
NAV = Σ holdings × mark (both venues) + Σ perp unrealized P&L
strategy P&L = realized + unrealized + funding − feesHoldings 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
| Kind | Written when |
|---|---|
engine | Start, stop, paper treasury seeded |
risk | Kill switch, drawdown limit, stale book pulled |
revenue | Creator fees accrued |
harvest | Fees claimed on chain (live) |
swap | Montra pool trade |
hedge | Hedge adjusted |
funding | Funding booked (paper) |
arb | Arbitrage executed |
transfer | Rebalance suggested |
strategy | Strategy paused or resumed by an operator |
Read them with GET /api/v1/ledger or on the app's Ledger page.