API

Database

The Postgres tables the engine writes and the API reads.

Motion uses one Postgres database (Neon in production). The schema is defined with Drizzle in lib/protocol/schema.ts; the migration lives in db/migrations and the engine applies it every time it starts, so there are no tables to create by hand. Regenerate migrations with npm run db:generate.

Amounts are stored as double precision in the asset's own units. They are for accounting and display, never a transaction amount: anything sent on chain is built from integer wei by the engine. Times are timestamptz.

Tables

TableKeyImportant columnsWritten byRead by
engine_statekeyvalue (jsonb), updated_atengine, admin APIengine controls, /status, /vault, /arb
strategiesidstatus, allocation_bps, capital_usd, pnl_usd, realized_usd, unrealized_usd, fees_usd, funding_usd, volume_usd, trades, params, note, last_action_atengine, every 5 s/vault, /strategies
balances(venue, asset)amount, usdengine, every 5 s/vault/balances, engine restart
positionsmarketvenue, strategy, size, entry_px, mark_px, unrealized_usd, realized_usd, funding_usdengine, every 5 s/vault/positions, engine restart
ordersidvenue, market, strategy, side, price, size, filled, status (open, filled, cancelled), level, external_idvenues/vault/orders
fillsidtime, venue, market, strategy, side, price, size, notional_usd, fee_usd, liquidity (maker, taker, pool), realized_usd, order_id, tx_hash, paperrecordFill()/vault/fills, /strategies/:id
funding_paymentsidtime, market, size, rate, payment_usdhedge (paper)/vault/funding
revenueidtime, kind (accrued, claimed), source, amount_hype, usd, to_treasury_hype, to_prizes_hype, tx_hash, paperharvest/revenue, /vault
snapshotstimenav_usd, hype_usd, elysium_usd, hypercore_usd, pnl_usd, revenue_usd, drawdown_bps, hype_exposure, by_strategyengine, every minute/vault, /vault/history, drawdown check
eventsidtime, kind, severity, strategy, venue, market, title, detail, tx_hashengine, admin API/ledger, /strategies/:id
transfersidtime, from_venue, to_venue, asset, amount, status, reason, tx_hashengine (suggestions)/vault/transfers

Indexes: open orders by status and market; fills by time and by market and time; revenue and events by time. Closed orders older than a day are deleted every hour.

engine_state keys

KeyValueWritten by
heartbeatmode, start time, version, feed health, starting NAV, hedge ratio, NAVengine, every 5 s
kill{on, reason, by: "api" or "risk"}admin API, drawdown limit
strategy:<id>{status: "running" or "paused"}admin API
paper-startstarting NAV, time, layoutengine, first start
revenue-cursorpool id, last pending valueharvest
arbthe latest arbitrage scanarbitrage, every 15 s

Paper reset

PAPER_RESET=true deletes every row from balances, positions, orders, fills, funding_payments, revenue, snapshots, events, transfers and strategies, and the engine_state keys heartbeat, arb, revenue-cursor and paper-start. The kill switch and strategy pauses are kept.

Connections

ClientPoolNotes
Enginemax 5, idle 60 s, connect timeout 15 suse Neon's direct connection string
Vercel APImax 3 per serverless instance, idle 20 s, connect timeout 10 suse Neon's pooled string (host with -pooler); prepared statements off