Operations
Configuration, keepers, monitoring, runbook and the pre-mainnet checklist.
#Configuration
All configuration is environment variables; see .env.example for the
full list with comments. The service validates them at startup and exits with a clear
message when something is missing or malformed.
In production (NODE_ENV=production) these are required: JWT_SECRET (≥ 32 chars),
SIWE_DOMAINS (the frontend host(s) allowed to sign users in), CORS_ORIGINS, and a
postgres:// DATABASE_URL (embedded PGlite is refused: replicas must share one database).
Error messages are scrubbed of URLs before they are logged, stored or returned, so an RPC
API key in a URL path never leaks through an error.
#Running
pnpm dev # watch mode, ROLE=all
pnpm build && pnpm start # compiled
docker compose up --build # Postgres + api + worker| Role | Runs | Scale |
|---|---|---|
api | HTTP + WebSocket. Reads market data that the worker wrote to the database. | any number of replicas |
worker | HyperCore polling, risk engine, indexer, keepers | 1 leader; extra replicas are hot standbys. One lease for the whole worker, renewed by a heartbeat (a slow job cannot lose it); a standby takes over within ~20 s of the leader dying, immediately on a clean shutdown. Keeper transactions are refused on any replica that is not the leader. |
all | both | development and small deployments |
Migrations are applied at startup (and by pnpm db:migrate). The database can be any
Postgres 14+; Neon's pooled endpoint works (the scheduler uses row leases, not advisory
locks, so it is safe behind pgbouncer).
This is a long-running service (timers, WebSockets, keepers). Host it on something that runs containers continuously (Railway, Fly.io, Render, ECS, a VM), not on a serverless functions platform.
#Health and monitoring
| Endpoint | Use |
|---|---|
GET /healthz | liveness |
GET /readyz | readiness: database, RPC, HyperCore data, indexer lag. 503 when not ready |
GET /metrics | Prometheus text format |
GET /v1/admin/status | keeper addresses and gas balances, indexer cursor, pause flags, job ages (admin wallets only) |
Metrics worth alerting on:
| Metric | Alert when |
|---|---|
price_status{symbol} | 2 (halted) for more than a minute: prices are stale or the book is broken |
indexer_lag_blocks | growing: positions and the health monitor are falling behind |
job_runs_total{outcome="error"} | rising for risk-reporter, liquidations, indexer |
keeper_transactions_total{outcome="failed"|"reverted"} | rising |
liquidations_open | stays above zero for longer than the liquidation TTL (5 min) |
liquidations_total{status="failed"} | any: needs a human (see below) |
accounts_by_health{status="liquidatable"} | above zero while liquidations_open is zero |
indexer_position_corrections_total | any: the position mirror drifted and was repaired |
indexer_reorgs_total | any: informational |
fee_regime | 1 (stress) |
Logs are JSON (pino). Secrets, signatures and tokens are redacted.
#Keepers
Keepers are the protocol's own accounts. Without a key a keeper runs in dry-run mode (logs what it would do, sends nothing) and the service says so at startup.
| Key | Role | Needs |
|---|---|---|
REPORTER_PRIVATE_KEY | REPORTER_ROLE on the risk feed | HYPE for gas (a post every ≤ 40 s, more when prices move) |
LIQUIDATOR_PRIVATE_KEY | LIQUIDATOR_ROLE on the pool | HYPE for gas and inventory: debt assets on Elysium to settle with |
ALLOCATOR_PRIVATE_KEY | ALLOCATOR_ROLE / CONVERTER_ROLE on the fee engine, ROOT_UPDATER_ROLE on both distributors | HYPE for gas |
KEEPER_PRIVATE_KEY is a shortcut that fills any of the three that is not set. Use one key
per role in production and keep them in a secrets manager. Every keeper transaction is
simulated before it is sent and recorded in the keeper_txs table.
#Liquidation venue
LIQUIDATION_VENUE | Behaviour |
|---|---|
simulated (default) | Paper fills against the live HyperCore book with the taker fee. The on-chain legs are real: the liquidator settles from its Elysium inventory at the simulated price. Right for testnet and for dry runs of risk parameters. |
hyperliquid | Real immediate-or-cancel orders through the Hyperliquid exchange API, signed by an agent wallet (HYPERLIQUID_AGENT_PRIVATE_KEY) for the account HYPERLIQUID_ACCOUNT_ADDRESS. An agent can trade but can never withdraw. The account needs inventory of every collateral asset on HyperCore. HYPERCORE_NETWORK must be the network that account is on. This venue has not been exercised against the live exchange from this repository: run it on HyperCore testnet first. |
corewriter | ElysiumCoreWriter. Not live yet; selecting it makes liquidation orders fail with a clear error. |
With real execution the liquidator's inventory has to be rebalanced: it accumulates seized collateral on Elysium and sells from its HyperCore balance. Moving assets between the two goes through the bridge (HyperEVM ⇄ HyperCore is fast; Elysium → HyperEVM has a ~24 h challenge period), so size the inventory for a day of liquidations.
#Runbook
HyperCore data is stale or halted (price_status = 2). The reporter stops posting, the
on-chain price goes stale after maxStaleness (120 s), and the pool then refuses new
borrows and collateral withdrawals on its own. Repayments and supplies keep working.
Liquidations pause (they require fresh prices). Nothing to do unless it lasts; if it does,
consider emergency mode.
The order-book venue is down but positions need liquidating. A guardian calls
LendingPool.setEmergencyMode(true). The engine then liquidates atomically on-chain from
inventory at the last known price plus the emergency bonus. Switch it off when the venue
is back.
Stop everything. A guardian calls LendingPool.setPauseFlags(flags): 1 supply, 2
withdraw, 4 borrow, 8 liquidation (add them up). Repay can never be paused. To freeze
one asset for new borrowing: HyperCoreRiskFeed.setGuardianFrozen(asset, true).
A liquidation is failed. GET /v1/liquidations/:id shows the full timeline; entries
with needsAttention: true are the ones to read. Every non-terminal liquidation is closed
automatically: at the deadline the engine stops trading and settles what was confirmed;
an order whose outcome could not be established (venue unreachable) is marked unknown
and counted as no fill, so the borrower is never charged for it; anything still open 15
minutes past its deadline is unlocked on-chain and closed. What needs a human is inventory:
if the venue did fill but nothing was settled, the liquidator holds the proceeds (or, for
unknown, check the venue's order history by client order id) and the inventory should be
rebalanced. No user funds are affected; the position is re-liquidated on the next pass if
it is still unhealthy (after a 60 s cool-down).
The liquidator is out of inventory. Settlement fails with "fund the liquidation
inventory" in the liquidation's error. Top up the liquidator's balance of the debt
asset; the engine retries automatically. If the deadline passes first, the liquidation is
cancelled on-chain (anyone can do this) and re-opened later.
Bad debt appears (/v1/stats → badDebtUsd). The fee engine switches to the stress
allocation by itself (65% of fees to insurance) and uses insurance reserves to fill the
hole as they arrive. Governance can also call coverBadDebt directly or, as a last
resort, socializeBadDebt.
Rotating a keeper key. Grant the role to the new address, deploy with the new key,
revoke the old address. Roles are standard OpenZeppelin AccessControl.
Rebuilding the database. Everything except sessions, notifications and reward epochs
can be rebuilt from the chain: delete the indexer_state row (and events, positions)
and restart; the indexer replays from the deployment's start block. Do not delete
reward_epochs / reward_balances: they are the record of what each published Merkle
root contains (a copy of each tree is also published to blob storage when
BLOB_READ_WRITE_TOKEN is set).
#Security checklist before real funds
- Contracts audited; findings fixed.
-
DEFAULT_ADMIN_ROLEon a timelocked multisig, deployer's roles revoked. -
GUARDIAN_ROLEon a multisig that can react quickly. - One key per keeper role, in a secrets manager; alerts on keeper gas balances.
-
JWT_SECRETset and stored as a secret;SIWE_DOMAINSandCORS_ORIGINSlist only the real frontend. -
TRUST_PROXYset to the exact number of proxies in front of the service (e.g.1behind one load balancer); leave it0when clients connect directly. - Real risk parameters reviewed per market (
src/config/markets.ts). -
LIQUIDATION_VENUE=hyperliquidexercised on HyperCore testnet with a funded agent. - Alerts wired to the metrics above.
- The
.envin this repository was never committed (it is git-ignored). If any key in it was ever shared, rotate it.