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.

ts
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.

FieldTypeRequiredDefaultDescription
indexerUrlstringyesnoneEnvio/Hasura GraphQL endpoint over HTTP. A same-origin relative path is accepted in a browser.
chainChain (viem)yesnoneThe chain the markets live on.
wsRpcUrlstringnochain.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.
indexerHeadersRecord<string, string>nononeExtra headers on every indexer request, for example a Hasura admin secret. Server-side only.
signalAbortSignalnononeAborts 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.
feesFixedFeesnoDEFAULT_FEESFixed EIP-1559 fees for SDK-signed writes.
addressesSomniaMarketsAddressesno{}Protocol contract addresses. Every entry is optional. A method that needs a missing address throws NotConfiguredError when it is called.
priceFeedPriceFeedConfignononeThe 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) => voidnononeReceives structured debug events. When unset the SDK emits nothing and does no debug-only work.
privateKey`0x${string}`nononeA local signing key. The SDK signs locally and confirms in one round-trip.
accountAccount | AddressnononeA viem account, or a plain address to trade as through walletClient.
walletClientWalletClientnononeAn 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

AspectprivateKey or a signing accountwalletClient
Who signsThe SDK, locallyThe wallet, after a user prompt
Fees and gasThe fixed values from fees and the gas ceilingThe same fixed values, passed to the wallet as maxFeePerGas, maxPriorityFeePerGas, and gas
Send pathrealtime_sendRawTransaction: send and receipt in one round-trip; falls back to eth_sendRawTransaction when the node does not serve iteth_sendTransaction through the wallet; the receipt is read on each new block head over the SDK's WebSocket
RevertsDecoded by replaying the failed call at the receipt's blockSurfaced by the wallet's simulation before the prompt, with revert data
ApprovalsOne approve(maxUint256) per token and spender, on the first order that needs it, cached for the trader's lifetimeThe same, as a second wallet prompt
NonceTracked locally after one fetch; reset on a rejected sendManaged 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

FieldTypeDescription
maxFeePerGasbigintFee ceiling in wei per gas. The unspent margin above base fee plus tip is refunded.
maxPriorityFeePerGasbigintTip 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.

FieldUsed by
collateralThe venue's collateral ERC-20. faucet() mints it on test networks.
testUsdcLegacy alias for collateral. collateral takes precedence.
binaryModuleComplete-set mint and redeem, market creation, hub-approval reads, system diagnostics.
marketCreatorThe live tail watches MarketCreated on it to discover new binary markets.
clobFactorySystem diagnostics fallback.
binaryPoolImpl, binaryPoolBeaconSurfaced to apps. Not read by the SDK.
binarySettlementredeemDirect, claimOwed, getSettlement.
operatorPermissionsRegistryOperator approval of a stop-order registry. Discoverable at runtime with getOperatorPermissionsRegistry(pool).
marketsCoreOperator and venue reads, createOperatorAdmin.
collateralRouterThe native-token and Permit2 complete-set path (mintSetNative, mintSetPermit2, redeemNative).
marketCreatorFactory, marketCreatorFactoryV2createMarketCreatorAdmin.
oracleHubOracleHub reads and createOracleHubAdmin.
perpPoolFactoryPerp discovery when the indexer has no perp rows. Normally unnecessary: loadMarkets resolves the factory from MarginBank.getSystemConfig(). When set it takes precedence.
lendLendAddresses for the third-party SomniaLend deployment. Backs client.lend.
fakeOracleresolve and voidMarket on demo stacks.
oracleAdapterFactory, sharedOracleAdapterDeprecated. 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

FieldTypeRequiredDefaultDescription
urlstringyesnoneHTTP GraphQL endpoint of the price-feed indexer. One endpoint serves every asset.
wsUrlstringnourl with http replaced by wsWebSocket GraphQL endpoint for live subscriptions.
quotestringnononeQuote 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

ConstantValueWhere
WebSocket request timeout4,000 msEvery chain read and write.
Indexer request timeout30,000 msEvery indexer read.
Default gas ceiling10,000,000Every SDK-signed write. Not exported.
DEFAULT_FEES.maxFeePerGas60 gweiExported from the root entry.
Reconnect backoff500 ms, doubling to an 8 s capLive watches after a socket error.
Watch lingerabout 30 sTime a scope stays materialised after its last handle stops.