@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / index / ClientConfig

Interface: ClientConfig

Defined in: packages/sdk/src/config.ts:434

Configuration for a SomniaMarketsClient. Each transport is required only by the features that use it: indexerUrl powers the indexer reads and the live watches' snapshot hydration (omit it for a chain-only client — smart accounts, executors, on-chain reads — and those reads throw NotConfiguredError); chain + wsRpcUrl power the live tail, on-chain reads, and writes, but the WebSocket socket is opened lazily, so an indexer-only client (e.g. server-side GraphQL reads) that never touches the chain never opens one.

Properties

reconciliation?

optional reconciliation?: TailReconciliationConfig

Defined in: packages/sdk/src/config.ts:442

Optional diagnostic, off by default. At most once per interval, recover logs through one target and compare both top-N sides at that block and timestamp. Costs chunked getLogs plus one header and two book reads per watched pool. Failures and retained divergence evidence appear in getLiveStatus(). It never replaces seed orders or the event-derived store.


indexerUrl?

optional indexerUrl?: string

Defined in: packages/sdk/src/config.ts:450

Envio/Hasura GraphQL endpoint (HTTP). Same-origin relative paths are fine. Optional: a chain-only client (smart accounts, executors, on-chain reads) needs none; every indexer read and live watch then throws NotConfiguredError naming this field. An empty string counts as absent.


indexerHeaders?

optional indexerHeaders?: Record<string, string>

Defined in: packages/sdk/src/config.ts:458

Extra headers sent with every indexer request — e.g. a Hasura role / admin-secret for SERVER-side reads that need privileges the public role lacks (notably _aggregate fields, which envio hides from the public role). MUST stay server-only; never construct a browser client with a secret here.


indexerLimits?

optional indexerLimits?: IndexerLimits

Defined in: packages/sdk/src/config.ts:472

Bounds on how hard this client may push ClientConfig.indexerUrl. Defaults to DEFAULT_INDEXER_LIMITS; supplied fields override it one by one. Owned by this client: two clients on one endpoint keep separate counters, so one client's outage never fails another's reads.

Throws InvalidInputError at construction on a bound the governor cannot use: a count (maxInFlight, breakerThreshold, maxAttempts, maxQueued) that is not a whole number of at least 1, a delay of 0 or less, or any non-finite value. A cap of 0 would queue every read forever, a fractional one would admit more reads than it names, and a zero or NaN delay would fire every retry immediately, so none is accepted quietly.


signal?

optional signal?: AbortSignal

Defined in: packages/sdk/src/config.ts:490

Cancels this client's in-flight INDEXER reads when aborted — pass one per request on a server, or a component's controller signal in a UI, so a navigation away stops work already on the wire.

Details

Client-wide, not per-read: it is combined with the SDK's own request timeout (whichever fires first wins). An abort re-throws YOUR abort reason unwrapped rather than an IndexerError, so name === "AbortError" checks keep working — a cancellation is not an indexer failure.

Gotchas

Covers indexer reads only. Chain reads go over the WebSocket transport, which is bounded by its own request timeout instead.


chain

chain: Chain

Defined in: packages/sdk/src/config.ts:492

viem chain the markets live on.


wsRpcUrl?

optional wsRpcUrl?: string

Defined in: packages/sdk/src/config.ts:504

Chain WebSocket RPC — the single chain transport. The live tail subscribes to logs + new heads over it, and all on-chain reads/writes use it too. There is no HTTP fallback: the SDK assumes a healthy WebSocket.

Optional when chain carries a WebSocket endpoint — every definition in @somnia-chain/markets-sdk/chains does (rpcUrls.default.webSocket), so with those this is only an override. viem's own somniaTestnet lacks one, so with that chain (or any ws-less definition) it stays required and the first chain touch throws NotConfiguredError without it.


fees?

optional fees?: FixedFees

Defined in: packages/sdk/src/config.ts:509

Fixed fees for SDK-signed writes (default DEFAULT_FEES). Override for a chain whose base fee can exceed the default ceiling.


addresses?

optional addresses?: SomniaMarketsAddresses

Defined in: packages/sdk/src/config.ts:514

Protocol contract addresses — used by the write client, the live tail's factory watch, and /system reads.


priceFeed?

optional priceFeed?: PriceFeedConfig

Defined in: packages/sdk/src/config.ts:521

The realtime price-feed endpoint (see PriceFeedConfig). One endpoint serves every asset; callers filter by asset. Required only for the price-feed methods (watchPrice, getLivePrice, fetchPrices, …); a client that never touches prices needs none.


debug?

optional debug?: (e) => void

Defined in: packages/sdk/src/config.ts:554

Opt-in debug/tracing sink. Unset (the default) means the SDK emits nothing and does no debug-only work. When set, the client sends every DebugEvent it produces — structured log lines plus span start/annotate/end events around trader calls and live-tail hydration — and the sink decides everything else: filtering, formatting, toggling, or forwarding to a real tracer (the shape maps 1:1 onto OpenTelemetry). Two sinks ship with the package: consoleDebugSink (indented span tree) and debugCollector (test capture). The toggle mechanism belongs to the app, not the SDK:

Example (Enabling debug output)

Explorer (dev) — flip on from devtools via localStorage; a Node bot gates a JSON-lines sink on an env var instead:

ts
const devExchange = new SomniaMarkets({
  ...config,
  debug: localStorage.getItem("sdk-debug")
    ? consoleDebugSink()
    : undefined,
});

const botExchange = new SomniaMarkets({
  ...config,
  debug: process.env.SDK_DEBUG
    ? (e) => console.log(JSON.stringify(e, (_, v) => (typeof v === "bigint" ? v.toString() : v)))
    : undefined,
});

Parameters

e

DebugEvent

Returns

void