Configuration
This page lists every field a SomniaMarkets instance accepts, with its type, whether it is required, and its default. The same fields, minus the three signer fields, form ClientConfig, the configuration of the engine. For the values to put in these fields on each network, see Networks and endpoints.
import { SomniaMarkets } from "@somnia-chain/markets-sdk";
const exchange = new SomniaMarkets(config); // config: SomniaMarketsConfig
SomniaMarketsConfig
SomniaMarketsConfig is ClientConfig plus the signer fields privateKey, account, and walletClient.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
indexerUrl | string | yes | none | Envio/Hasura GraphQL endpoint over HTTP. A same-origin relative path is accepted in a browser. |
chain | Chain (viem) | yes | none | The chain the markets live on. |
wsRpcUrl | string | no | chain.rpcUrls.default.webSocket[0] | The WebSocket RPC endpoint. It is the only chain transport: subscriptions, reads, and writes all use it. There is no HTTP fallback. Required when chain carries no WebSocket URL. |
indexerHeaders | Record<string, string> | no | none | Extra headers on every indexer request, for example a Hasura admin secret. Server-side only. |
signal | AbortSignal | no | none | Aborts in-flight indexer reads. Client-wide, not per read. An abort re-throws the caller's own reason, not an IndexerError. Chain reads are not covered; they have a 4-second request timeout of their own. |
fees | FixedFees | no | DEFAULT_FEES | Fixed EIP-1559 fees for SDK-signed writes. |
addresses | SomniaMarketsAddresses | no | {} | Protocol contract addresses. Every entry is optional. A method that needs a missing address throws NotConfiguredError when it is called. |
priceFeed | PriceFeedConfig | no | none | The realtime price-feed endpoint. Required only by the price methods that fetch or watch (watchPrice, fetchPrice, fetchPriceOHLCV, and the client's fetchPrice* and listPriceFeeds). The getLivePrice* reads return null or [] until a watch is open. |
debug | (event: DebugEvent) => void | no | none | Receives structured debug events. When unset the SDK emits nothing and does no debug-only work. |
privateKey | `0x${string}` | no | none | A local signing key. The SDK signs locally and confirms in one round-trip. |
account | Account | Address | no | none | A viem account, or a plain address to trade as through walletClient. |
walletClient | WalletClient | no | none | An external signer, for example an injected browser wallet. |
Signer resolution
A method that writes, or reads data scoped to the caller, resolves the caller's address in this order: walletClient.account.address, then account.address, then account when it is a string, then the address derived from privateKey. When none is set, walletAddress is undefined and every authenticated method throws SignerRequiredError.
setSigner(signer) replaces the signer after construction. Passing {} removes it. Live watches and market data are unaffected.
Signer paths
| Aspect | privateKey or a signing account | walletClient |
|---|---|---|
| Who signs | The SDK, locally | The wallet, after a user prompt |
| Fees and gas | The fixed values from fees and the gas ceiling | The same fixed values, passed to the wallet as maxFeePerGas, maxPriorityFeePerGas, and gas |
| Send path | realtime_sendRawTransaction: send and receipt in one round-trip; falls back to eth_sendRawTransaction when the node does not serve it | eth_sendTransaction through the wallet; the receipt is read on each new block head over the SDK's WebSocket |
| Reverts | Decoded by replaying the failed call at the receipt's block | Surfaced by the wallet's simulation before the prompt, with revert data |
| Approvals | One approve(maxUint256) per token and spender, on the first order that needs it, cached for the trader's lifetime | The same, as a second wallet prompt |
| Nonce | Tracked locally after one fetch; reset on a rejected send | Managed by the wallet |
Lazy connections
The viem chain WebSocket opens on the first chain read, write, or watch. An instance that only performs indexer reads never opens one. The price-feed WebSocket opens on the first watchPrice. close() stops the watches and channels and closes every socket the instance opened, both the price-feed WebSockets and the viem chain transport, so a Node process exits on its own afterwards. Instances sharing a wsRpcUrl share one chain socket, which closes when the last of them closes.
FixedFees
| Field | Type | Description |
|---|---|---|
maxFeePerGas | bigint | Fee ceiling in wei per gas. The unspent margin above base fee plus tip is refunded. |
maxPriorityFeePerGas | bigint | Tip in wei per gas. |
DEFAULT_FEES is { maxFeePerGas: 60_000_000_000n, maxPriorityFeePerGas: 0n }: a 60 gwei ceiling and no tip.
Gas
Every SDK-signed write uses a fixed gas ceiling of 10,000,000 gas. Gas is never estimated. Unused gas is not charged. The mempool accepts a transaction only when the account holds gas × maxFeePerGas on top of the transaction value: 0.6 STT or SOMI at the defaults. A lower-level write accepts a per-call gas override only when its public parameter type declares one. Unified exchange methods such as createOrder and cancelOrder do not expose that override.
SomniaMarketsAddresses
Every field is optional and typed Address, except lend.
| Field | Used by |
|---|---|
collateral | The venue's collateral ERC-20. faucet() mints it on test networks. |
testUsdc | Legacy alias for collateral. collateral takes precedence. |
binaryModule | Complete-set mint and redeem, market creation, hub-approval reads, system diagnostics. |
marketCreator | The live tail watches MarketCreated on it to discover new binary markets. |
clobFactory | System diagnostics fallback. |
binaryPoolImpl, binaryPoolBeacon | Surfaced to apps. Not read by the SDK. |
binarySettlement | redeemDirect, claimOwed, getSettlement. |
operatorPermissionsRegistry | Operator approval of a stop-order registry. Discoverable at runtime with getOperatorPermissionsRegistry(pool). |
marketsCore | Operator and venue reads, createOperatorAdmin. |
collateralRouter | The native-token and Permit2 complete-set path (mintSetNative, mintSetPermit2, redeemNative). |
marketCreatorFactory, marketCreatorFactoryV2 | createMarketCreatorAdmin. |
oracleHub | OracleHub reads and createOracleHubAdmin. |
perpPoolFactory | Perp discovery when the indexer has no perp rows. Normally unnecessary: loadMarkets resolves the factory from MarginBank.getSystemConfig(). When set it takes precedence. |
lend | LendAddresses for the third-party SomniaLend deployment. Backs client.lend. |
fakeOracle | resolve and voidMarket on demo stacks. |
oracleAdapterFactory, sharedOracleAdapter | Deprecated. Kept so old configurations type-check. Not read. |
SOMNIA_MAINNET_ADDRESSES and SOMNIA_TESTNET_ADDRESSES, exported from the root entry, hold the current deployments. SOMNIA_MAINNET_LEND and SOMNIA_TESTNET_LEND hold the SomniaLend addresses and are already included in the two address constants.
PriceFeedConfig
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | yes | none | HTTP GraphQL endpoint of the price-feed indexer. One endpoint serves every asset. |
wsUrl | string | no | url with http replaced by ws | WebSocket GraphQL endpoint for live subscriptions. |
quote | string | no | none | Quote asset to pin every read to, case-insensitive. When unset, a base that trades against two quotes is double-counted. |
SOMNIA_TESTNET_PRICE_FEED is { url: "https://price-feed.dev.oracle.somnia.host/v1/graphql", quote: "USDC" }.
SOMNIA_MAINNET_PRICE_FEED is { url: "https://price-feed.prd.oracle.somnia.host/v1/graphql", quote: "USDC" }.
They index different chains; see networks and endpoints.
Transport constants
| Constant | Value | Where |
|---|---|---|
| WebSocket request timeout | 4,000 ms | Every chain read and write. |
| Indexer request timeout | 30,000 ms | Every indexer read. |
| Default gas ceiling | 10,000,000 | Every SDK-signed write. Not exported. |
DEFAULT_FEES.maxFeePerGas | 60 gwei | Exported from the root entry. |
| Reconnect backoff | 500 ms, doubling to an 8 s cap | Live watches after a socket error. |
| Watch linger | about 30 s | Time a scope stays materialised after its last handle stops. |