|
26 | 26 | * HORIZON_URL Horizon endpoint (default: testnet) |
27 | 27 | * INDEXER_URL Indexer base URL (default: http://localhost:3000) |
28 | 28 | * NOTIFICATIONS_URL Notifications base URL (default: http://localhost:3001) |
| 29 | + * INSURANCE_POOL_RPC_URL Soroban RPC endpoint for the insurance pool contract |
| 30 | + * INSURANCE_POOL_ID Deployed insurance pool contract address |
29 | 31 | * LEDGER_LAG_THRESHOLD Max acceptable ledger lag (default: 100) |
30 | 32 | * HEALTH_TIMEOUT_MS Per-request timeout in ms (default: 5000) |
31 | 33 | * SLACK_WEBHOOK_URL Incoming webhook used by --alert-slack |
@@ -54,6 +56,8 @@ export interface HealthConfig { |
54 | 56 | horizonUrl: string; |
55 | 57 | indexerUrl: string; |
56 | 58 | notificationsUrl: string; |
| 59 | + insurancePoolRpcUrl: string; |
| 60 | + insurancePoolId: string; |
57 | 61 | ledgerLagThreshold: number; |
58 | 62 | timeoutMs: number; |
59 | 63 | } |
@@ -81,6 +85,8 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): HealthConfig { |
81 | 85 | horizonUrl: (env.HORIZON_URL || "https://horizon-testnet.stellar.org").replace(/\/$/, ""), |
82 | 86 | indexerUrl: (env.INDEXER_URL || "http://localhost:3000").replace(/\/$/, ""), |
83 | 87 | notificationsUrl: (env.NOTIFICATIONS_URL || "http://localhost:3001").replace(/\/$/, ""), |
| 88 | + insurancePoolRpcUrl: env.INSURANCE_POOL_RPC_URL || env.SOROBAN_RPC_URL || "https://soroban-testnet.stellar.org", |
| 89 | + insurancePoolId: env.INSURANCE_POOL_ID || "", |
84 | 90 | ledgerLagThreshold: Number(env.LEDGER_LAG_THRESHOLD || 100), |
85 | 91 | timeoutMs: Number(env.HEALTH_TIMEOUT_MS || 5000), |
86 | 92 | }; |
@@ -247,6 +253,67 @@ export async function checkLedgerLag( |
247 | 253 | } |
248 | 254 | } |
249 | 255 |
|
| 256 | +/** 5. Insurance pool contract — verifies it is initialized (Admin key present). */ |
| 257 | +export async function checkInsurancePool( |
| 258 | + cfg: HealthConfig, |
| 259 | + deps: Deps = defaultDeps |
| 260 | +): Promise<CheckResult> { |
| 261 | + const base: CheckResult = { |
| 262 | + name: "insurance_pool", |
| 263 | + status: "unknown", |
| 264 | + critical: false, |
| 265 | + latencyMs: null, |
| 266 | + details: { contractId: cfg.insurancePoolId }, |
| 267 | + error: null, |
| 268 | + }; |
| 269 | + |
| 270 | + if (!cfg.insurancePoolId) { |
| 271 | + return { ...base, status: "unknown", error: "INSURANCE_POOL_ID not configured" }; |
| 272 | + } |
| 273 | + |
| 274 | + const body = JSON.stringify({ |
| 275 | + jsonrpc: "2.0", |
| 276 | + id: 1, |
| 277 | + method: "getLedgerEntries", |
| 278 | + params: { |
| 279 | + keys: [ |
| 280 | + // DataKey::Admin is a unit enum variant — its XDR is a 1-element vec |
| 281 | + // with symbol "Admin". We request it to confirm the pool is initialised. |
| 282 | + Buffer.from( |
| 283 | + JSON.stringify({ contractId: cfg.insurancePoolId, key: { type: "symbol", value: "Admin" } }) |
| 284 | + ).toString("base64"), |
| 285 | + ], |
| 286 | + }, |
| 287 | + }); |
| 288 | + |
| 289 | + try { |
| 290 | + const { res, latencyMs } = await timedFetch( |
| 291 | + deps, |
| 292 | + cfg.insurancePoolRpcUrl, |
| 293 | + { method: "POST", headers: { "content-type": "application/json" }, body }, |
| 294 | + cfg.timeoutMs |
| 295 | + ); |
| 296 | + base.latencyMs = latencyMs; |
| 297 | + if (!res.ok) { |
| 298 | + return { ...base, status: "fail", error: `RPC returned HTTP ${res.status}` }; |
| 299 | + } |
| 300 | + const json: any = await res.json(); |
| 301 | + if (json.error) { |
| 302 | + return { ...base, status: "fail", error: `RPC error: ${JSON.stringify(json.error)}` }; |
| 303 | + } |
| 304 | + const entries: unknown[] = json.result?.entries ?? []; |
| 305 | + const initialized = entries.length > 0; |
| 306 | + return { |
| 307 | + ...base, |
| 308 | + status: initialized ? "ok" : "fail", |
| 309 | + details: { ...base.details, initialized }, |
| 310 | + error: initialized ? null : "Insurance pool Admin key not found — pool may not be initialized", |
| 311 | + }; |
| 312 | + } catch (e) { |
| 313 | + return { ...base, status: "fail", error: errMsg(e) }; |
| 314 | + } |
| 315 | +} |
| 316 | + |
250 | 317 | /** 4. Notification service `/health` endpoint. */ |
251 | 318 | export async function checkNotifications( |
252 | 319 | cfg: HealthConfig, |
@@ -294,14 +361,15 @@ export async function runHealthChecks( |
294 | 361 | checkContractRpc(cfg, deps), |
295 | 362 | checkIndexer(cfg, deps), |
296 | 363 | ]); |
297 | | - const [lag, notifications] = await Promise.all([ |
| 364 | + const [lag, notifications, insurancePool] = await Promise.all([ |
298 | 365 | checkLedgerLag(cfg, indexer.lastIndexedLedger, deps), |
299 | 366 | checkNotifications(cfg, deps), |
| 367 | + checkInsurancePool(cfg, deps), |
300 | 368 | ]); |
301 | 369 |
|
302 | 370 | // Drop the helper-only field before reporting. |
303 | 371 | const { lastIndexedLedger: _ignored, ...indexerResult } = indexer; |
304 | | - const checks: CheckResult[] = [rpc, indexerResult, lag, notifications]; |
| 372 | + const checks: CheckResult[] = [rpc, indexerResult, lag, notifications, insurancePool]; |
305 | 373 |
|
306 | 374 | const healthy = checks.every((c) => !(c.critical && c.status === "fail")); |
307 | 375 |
|
|
0 commit comments