RPC escape hatch#
Seesaw's TypeScript SDK offers opt-in API-first reads with validated RPC fallback. Configure an RPC transport explicitly: the SDK does not silently select a public endpoint. Trading and settlement instructions execute on Solana; indexing, analytics, discovery, oracle delivery and proof production also use offchain services.
Configure the SDK#
Use the runnable TypeScript example (unavailable reference) from the repository root. Supply a known market and wallet on your RPC's deployment. The loopback API address below should be unused so that the example exercises RPC for all three reads.
SEESAW_API_URL=http://127.0.0.1:1 SEESAW_RPC_URL="$RPC_URL" \
bun packages/core/examples/30-rpc-escape-hatch.ts "$MARKET_ADDRESS" "$WALLET_ADDRESS"
The example uses solanaRpcDataSource(createSolanaRpc(rpcUrl)) to adapt Kit's
account requests and installs it through createSeesawClient({ resilientData }).
Pass the deployment's program address as a third argument when it differs from
the SDK default. For API-first wallet reads against a running authenticated API,
configure the application's wallet authentication.
The same facade exposes getMarket, getPositions(owner) and
getOpenOrders(owner). Existing client.api, instruction builders, PDA
helpers and streams retain their existing behavior. Without resilientData,
client.data is absent. API and RPC results deliberately have different
shapes: a raw market account does not contain an indexed chart or orderbook.
Python SDK#
The Python SDK ports the same reads. seesaw.rpc_data_source provides
read_market, scan_positions_by_owner and scan_orders_by_owner with the
same validation, RpcDataSourceError (operation, address, cause) and
JsonRpcDataSource, which needs an explicit URL or JSON-RPC call function.
Other transports, including solana-py, implement the small RpcDataSource
protocol. seesaw.resilient_data.ResilientDataSource is the API-first facade.
Its results carry source api, rpc or unavailable.
SEESAW_API_URL=http://127.0.0.1:1 SEESAW_RPC_URL="$RPC_URL" \
PYTHONPATH=packages/sdk-python python3 packages/sdk-python/examples/rpc_escape_hatch.py \
"$MARKET_ADDRESS" "$WALLET_ADDRESS"
The Python reads are synchronous. Cancellation uses a caller token with
is_set(), such as threading.Event. The transport reports only a context
slot, so the reported commitment is the requested one. getMarketDetail, the
maker and spline readers, and client wiring are not ported. Offline coverage is
packages/sdk-python/tests/test_rpc_escape_hatch.py with a fake transport; no
live-RPC run of the Python example is recorded here.
Rust SDK#
The Rust SDK (seesaw-sdk) has the same direct reads in rpc_data_source:
read_market, read_position, read_orderbook, scan_positions_by_owner and
scan_orders_by_owner. They run over any RpcDataSource implementation. With
the rpc feature, SolanaRpcDataSource adapts a blocking solana_client
client and uses finalized commitment when a read names none. Use the
runnable Rust example (unavailable reference):
SEESAW_RPC_URL="$RPC_URL" cargo run --locked -p seesaw-sdk --features rpc \
--example rpc_escape_hatch -- "$MARKET_ADDRESS" "$WALLET_ADDRESS"
The example reads only RPC and needs no API. Pass the deployment's program
address as a third argument when it differs from the SDK default.
resilient_data::ResilientDataSource provides get_market, get_positions
and get_open_orders with RPC fallback. The caller supplies each API read and
classifies its failure as ApiFailure::Fallback or ApiFailure::Propagate.
With the http feature, classify_http_error applies the rules below to
SeesawHttpClient errors. The Rust SDK has no API-first positions snapshot
reader, so a caller's positions read must return a complete owner snapshot.
Direct reads return RpcDataSourceError. When both sources fail, the facade
returns ResilientReadResult::Unavailable with both errors. Validation, scan
bounds and metadata rules match the TypeScript SDK.
Failure semantics#
- Network errors, timeouts, an open API circuit breaker, HTTP 5xx and malformed successful responses trigger RPC fallback. API HTTP 4xx and explicit caller cancellation propagate; the facade does not bypass access or policy errors.
- RPC validates program ownership, account layout and discriminators, position ownership, canonical PDAs and bumps. External markets additionally require validated market metadata. Invalid or missing accounts fail closed.
- Direct readers throw
RpcDataSourceError, retaining operation, address and cause. If the resilient facade exhausts both sources, it returnssource: 'unavailable',value: null, the RPC error and the original API error. This is not an empty successful portfolio. - Owner scans require a limit in
1..1000. Adapters must reject oversized results rather than truncate them. Order scans also enforce the result bound after reading each position's canonical book. A settled position can outlive its market. The scan skips its missing book only when a slot-consistent RPC read confirms that both the market and book are absent. Public RPC providers may deny scans; choose a transport supporting these methods and filters. sourcedistinguishes indexed API, RPC and unavailable data. RPC slot and commitment metadata are optional. Multiple reads report shared metadata only when all responses agree; missing metadata does not imply one atomic snapshot.- Transaction submission and confirmation remain separate from reads. Preserve a submitted signature when confirmation is unknown, reconcile it through RPC, and do not resubmit automatically. Indexer ingestion cannot prove transaction success. RPC failure itself cannot be repaired by an indexer escape hatch.
App behavior and verification#
Known market addresses, wallet positions and open orders can use RPC when indexed reads fail. The apps label their source and unavailable analytics. Discovery, charts, P&L, history and leaderboard services cannot be reconstructed from these account reads. Pyth lifecycle bundles require the user's provider key. The mobile wallet's configured RPC and web RPC transport/relay must stay reachable.
For signed-source markets, use readSourceStatus for finalized market state and
readSourceAcceptance for witness evidence digests in a known finalized
transaction. These reads use Solana RPC. Obtaining a new signed packet needs
the configured witnesses and provider access. Use the
independent stack guide for that workflow.
Local decoder, facade, hook, transaction-outcome, referrer and admin tests provide deterministic coverage. The product outage suite also stops its indexer and checks the market, position PDA, and resting order through SDK RPC fallback before exercising deposit refusal and recovery.
The Playwright 35-api-outage.spec.ts lane rejects product /api/v1 requests
with HTTP 503 and closes indexer WebSockets, retaining RPC and wallet access.
It checks source/degraded messaging and a wallet cancellation against the live
book. Run it against a freshly seeded local stack whose wallet owns a live order:
E2E_API_OUTAGE=1 bun --filter @seesaw/web test:e2e 35-api-outage.spec.ts --reporter=line
The Detox 18-api-outage.test.ts lane requires a debug app/Metro started with
EXPO_PUBLIC_API_URL=http://127.0.0.1:1, an independent working RPC, a seeded
market and connected wallet. Pass the same environment to the test process:
E2E_API_OUTAGE=1 EXPO_PUBLIC_API_URL=http://127.0.0.1:1 bun run --cwd apps/mobile detox test --configuration android.debug.emulator e2e/18-api-outage.test.ts
Detox URL blacklisting only affects synchronization and is not an outage mechanism. The mobile lane checks live market/portfolio reads and degraded analytics. Device wallet cancellation, ForceClose and referrer setup under outage remain external signoffs; unit coverage does not replace them. Neither lane is a completed staging or production signoff merely because it exists.
Behavioral references: packages/core/src/rpcDataSource.ts,
packages/core/src/resilientData.ts, packages/core/src/client.ts, and the
rpcDataSource, resilientData, rpcEscapeHatch, useEssentialRpcFallback
test suites.
The Rust port is packages/sdk-rust/src/rpc_data_source.rs and
packages/sdk-rust/src/resilient_data.rs, tested by
packages/sdk-rust/tests/rpc_data_source.rs. Release readiness follows the
production readiness requirements (unavailable reference).