import { type Account, type Address, type Hash, type Hex, type LocalAccount, type NonceManager, type PublicClient, type TransactionReceipt, type WalletClient } from "viem"; /** The signer sources every SDK write surface accepts (trader, admins, lender). */ export interface SignerSources { /** A pre-built signer (e.g. a browser/wagmi wallet over an injected provider). */ walletClient?: WalletClient; /** A local signing account (e.g. from viem's privateKeyToAccount). */ account?: Account | Address; /** Private key — the SDK derives the account. */ privateKey?: Hex; } /** What {@link resolveSigner} hands back — the two send paths plus the identity. */ export interface ResolvedSigner { /** Set when the SDK can sign locally (privateKey or a signing account). */ localAccount: LocalAccount | undefined; /** The external signer, when one was provided. */ walletClient: WalletClient | undefined; /** The signing identity — an Account, or a bare address for external signers. */ from: Account | Address; /** `from` as a plain address. */ fromAddress: Address; } /** * Resolve a write surface's signer config into the two send paths. Two ways in: * 1. a privateKey / local account — the SDK signs locally (the fast path); * 2. an explicit walletClient (browser/wagmi over an injected provider). * Throws {@link SignerRequiredError} (naming `label`, e.g. "createTrader") * when neither is usable. `nonceManager` is threaded into a derived * private-key account so the hot path can track nonces locally; surfaces that * fetch the nonce per call omit it. */ export declare function resolveSigner(config: SignerSources, label: string, opts?: { nonceManager?: NonceManager; }): ResolvedSigner; /** * True when an RPC error means "this node doesn't implement that method" * (JSON-RPC -32601 Method not found; some nodes surface it as -32601 nested, * others as an Invalid-params -32602 for the unknown method's args). * * Deliberately WIDER than native/errors' probes: a send path treats "the node * garbled the unknown method's params" as "no realtime here" and falls back, * while the native module's `isMethodNotFound` must not read a genuine * invalid-params error on a real somnia_* method as the method missing. */ export declare function isMethodUnsupported(e: unknown): boolean; /** Per-surface knobs for {@link broadcastSigned} — see each consumer for its stance. */ export interface BroadcastSignedOptions { /** Error-message prefix, e.g. `"@somnia-chain/markets-sdk"` — names the surface. */ label: string; /** * Transport retry count passed on BOTH send legs. `0` for a value-bearing * one-shot (a send that was accepted but whose response was lost would be * submitted AGAIN on retry — the second attempt then fails "nonce too low" * at best). Leave unset to pass NO options and keep viem's default * transport retries (trade.ts's current stance — the discrepancy is * deliberate and visible at each call site). */ retryCount?: number; /** * Probe gate for the realtime attempt (default: always try). trade.ts feeds * its cached per-trader flag here so production never pays a probe per * write; one-shot surfaces (bridge, machinery) probe per call. */ isRealtimeSupported?: () => boolean; /** Fired once when the node reports realtime as missing (cache the fallback). */ onRealtimeUnsupported?: () => void; /** * Fired on any REAL rejection — a realtime error that isn't * method-unsupported (including the returned-no-receipt throw), or any * fallback-leg failure including the receipt wait. trade.ts re-syncs its * local nonce here so the next write doesn't inherit a gap. */ onRejected?: () => void; /** Receipt wait for the eth_sendRawTransaction fallback leg. */ waitReceipt: (hash: Hash) => Promise; /** * Map a real rejection into the surface's error vocabulary before it is * thrown; `method` names the leg that failed (`realtime_sendRawTransaction` * or `eth_sendRawTransaction`). The trader decodes reverts to their Solidity * error name here; surfaces that propagate raw transport errors omit it. */ decorateError?: (e: unknown, method: string) => Error; } /** * Broadcast a signed tx. Fast path: Somnia's `realtime_sendRawTransaction`, * which blocks server-side until the receipt is available and returns it * (with logs) in ONE round-trip — no client-side confirm. Fallback: a * standard node (anvil, stock geth) that lacks the method → * `eth_sendRawTransaction` + `waitReceipt`, so the same code runs everywhere. */ export declare function broadcastSigned(client: Pick, serialized: Hex, opts: BroadcastSignedOptions): Promise; /** * Wait for a tx receipt off the WebSocket `newHeads` subscription — the * fallback-leg confirm on nodes without realtime, and the external-signer * confirm (an injected wallet sends; the SDK watches). On each pushed head we * read the receipt; first hit wins. No poll, no timeout: a subscription error * rejects and propagates to the caller, and so does a receipt read that keeps * failing ({@link MAX_CONSECUTIVE_RECEIPT_READ_FAILURES} in a row) — a wait that * swallowed those sat pending forever on a node that could not answer. */ export declare function waitReceiptViaHeads(publicClient: PublicClient, hash: Hash): Promise;