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
| Table | Key | Important columns | Written by | Read by |
|---|---|---|---|---|
engine_state | key | value (jsonb), updated_at | engine, admin API | engine controls, /status, /vault, /arb |
strategies | id | status, allocation_bps, capital_usd, pnl_usd, realized_usd, unrealized_usd, fees_usd, funding_usd, volume_usd, trades, params, note, last_action_at | engine, every 5 s | /vault, /strategies |
balances | (venue, asset) | amount, usd | engine, every 5 s | /vault/balances, engine restart |
positions | market | venue, strategy, size, entry_px, mark_px, unrealized_usd, realized_usd, funding_usd | engine, every 5 s | /vault/positions, engine restart |
orders | id | venue, market, strategy, side, price, size, filled, status (open, filled, cancelled), level, external_id | venues | /vault/orders |
fills | id | time, venue, market, strategy, side, price, size, notional_usd, fee_usd, liquidity (maker, taker, pool), realized_usd, order_id, tx_hash, paper | recordFill() | /vault/fills, /strategies/:id |
funding_payments | id | time, market, size, rate, payment_usd | hedge (paper) | /vault/funding |
revenue | id | time, kind (accrued, claimed), source, amount_hype, usd, to_treasury_hype, to_prizes_hype, tx_hash, paper | harvest | /revenue, /vault |
snapshots | time | nav_usd, hype_usd, elysium_usd, hypercore_usd, pnl_usd, revenue_usd, drawdown_bps, hype_exposure, by_strategy | engine, every minute | /vault, /vault/history, drawdown check |
events | id | time, kind, severity, strategy, venue, market, title, detail, tx_hash | engine, admin API | /ledger, /strategies/:id |
transfers | id | time, from_venue, to_venue, asset, amount, status, reason, tx_hash | engine (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
| Key | Value | Written by |
|---|---|---|
heartbeat | mode, start time, version, feed health, starting NAV, hedge ratio, NAV | engine, every 5 s |
kill | {on, reason, by: "api" or "risk"} | admin API, drawdown limit |
strategy:<id> | {status: "running" or "paused"} | admin API |
paper-start | starting NAV, time, layout | engine, first start |
revenue-cursor | pool id, last pending value | harvest |
arb | the latest arbitrage scan | arbitrage, 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
| Client | Pool | Notes |
|---|---|---|
| Engine | max 5, idle 60 s, connect timeout 15 s | use Neon's direct connection string |
| Vercel API | max 3 per serverless instance, idle 20 s, connect timeout 10 s | use Neon's pooled string (host with -pooler); prepared statements off |