Appearance
TypeScript SDK
@superis-labs/flint is an ESM-only TypeScript SDK that speaks gRPC-Web directly to flint-server (tonic + tonic_web). It runs in modern browsers and in Node 20.18+, and ships pre-generated TypeScript, so consumers need no codegen. The spot DEX lives under subpaths of the package:
| Import | What it holds |
|---|---|
@superis-labs/flint/spot | Client (public services), Maker (authenticated: maker data, transaction submit, chain tip), EmailAuthFlow, KeypairAuthFlow, models |
@superis-labs/flint/spot/chain | Program ids, PDAs, account decoders, instructions, units and the QuoteBuilder for building quote transactions |
@superis-labs/flint/spot/swap | Taker swaps: market loading, quotes, direct swaps, the Jupiter route, Jupiter and Titan clients (Taking liquidity) |
@superis-labs/flint/proto/spot | Generated protobuf messages and service descriptors |
@superis-labs/flint | Cluster, ApiError, StatusCode, ApiKey, Subscription, Pager, and the margin exchange's clients |
Surfaces
| Surface | How |
|---|---|
Public (MarketDataService, StatsService, HistoricalService, NodeService) | Client.mainnet(), Client.devnet(), Client.connect(cluster) |
Authenticated (MakerService, TxService) | Maker.connect({ cluster, signer }) with a wallet signer, { apiKey } for an organization API key, or { emailSession } for passwordless email login |
Session heartbeat (SessionService.Session) | Not available: gRPC-Web cannot carry bidirectional streams, so a TypeScript maker never shows in the quoter-session list |
QuotingCore | Rust and Python only; TypeScript builds quote transactions with spot/chain's QuoteBuilder and submits them with maker.submit |
Install
sh
npm install @superis-labs/flint @bufbuild/protobuf @solana/kit bignumber.jsThe package is published to GitHub Packages; add the @superis-labs scope to your .npmrc with a read token. @bufbuild/protobuf (2.2+), @solana/kit (8.x) and bignumber.js (10.x) are peer dependencies, so your app and the SDK share one copy of each. The gRPC-Web transport ships in the package.
TypeScript configuration
The SDK's declarations use AsyncDisposable (await using) and the DOM's fetch and Web Crypto types, so your tsconfig.json needs TypeScript 5.2+ and these libs:
json
{
"compilerOptions": {
"lib": ["ES2022", "DOM", "ESNext.Disposable"]
}
}Projects that load @types/node get ESNext.Disposable through it. If you cannot change lib (an older toolchain or a React Native preset), set "skipLibCheck": true instead, and call close() yourself rather than await using.
Quickstart
ts
import { Client } from "@superis-labs/flint/spot";
// Public methods need no auth. Building the client does no I/O.
const client = Client.mainnet();
const pairs = await client.pairs();
const summary = await client.statsSummary();
const info = await client.nodeInfo();
console.log(pairs);
console.log(summary);
console.log(info);
// Streams return a Subscription; `for await` connects and reconnects it.
for await (const event of client.watchOrderBook(["SOL/USDC"], { level: "l2" })) {
console.log(event);
}Where to go from here
| You want | Page |
|---|---|
| Stream books and fills | Market data |
| Pull historical fills / candles | Historical queries |
Authenticate against MakerService | Auth flow |
Maker (authenticated)
MakerService and TxService need credentials. Maker.connect takes the cluster and exactly one of: a wallet signer (signs the SWEETSPOT-AUTH-V1: challenge with the maker's key), an apiKey (organization API key), or an emailSession (passwordless email login, for dashboards).
ts
import { EmailAuthFlow, Maker } from "@superis-labs/flint/spot";
// Persist the bearer across reloads. Any localStorage-shaped store works:
// pass a sessionStorage, an IndexedDB-backed shim, or your own.
const auth = new EmailAuthFlow({
storage: globalThis.localStorage,
onExpired: () => router.push("/login"),
});
// Login form:
await auth.requestLoginCode("trader@example.com");
// ...prompt the user, then...
await auth.verifyLoginCode("trader@example.com", code);
const maker = await Maker.connect({ cluster: "mainnet", emailSession: auth });
const { balances } = await maker.balance();See Auth flow → TypeScript for the full walk-through, including API key auth.
maker.chainTip({ timeoutMs }) starts the blockhash and slot feed and waits until both are known; maker.slot() then reads the cached slot, and returns undefined before the first one. maker.watchMarketSnapshots(pairs?) streams each pair's book with the maker's own best quotes (makerBid, makerAsk); every event replaces the previous one.
ts
import { Maker } from "@superis-labs/flint/spot";
const maker = await Maker.connect({ cluster: "mainnet", apiKey: process.env.SUPERIS_API_KEY! });
const tip = await maker.chainTip({ timeoutMs: 5_000 });
console.log(tip.slot, maker.slot());
for await (const snapshot of maker.watchMarketSnapshots(["SOL/USDC"])) {
console.log(snapshot.markets[0]?.makerBid?.price.toFixed());
break;
}Historical fills and candles
HistoricalService is public, so client.historicalFills and client.historicalCandles need no session (maker.historicalFills and maker.historicalCandles call the same methods on maker.client). Both return a Pager; collect() drains it, or iterate it page by page:
ts
import { Client } from "@superis-labs/flint/spot";
const client = Client.mainnet();
const fills = await client.historicalFills("SOL/USDC", { pageSize: 100 }).collect();Decimal handling
Prices, sizes and every other money value in the models are Decimal values from bignumber.js, parsed from the wire's decimal strings. Never convert them to number for arithmetic:
ts
const notional = fill.price.multipliedBy(fill.size);Historical fills and candles use the same Decimal type for price, size and OHLCV fields. The raw protobuf messages under @superis-labs/flint/proto/spot keep the wire's Decimal { value: string } wrapper.
The QuoteBuilder lowers human prices to oracle units so that a price between two oracle ticks never improves your quote: a bid or buy price (buyPrice, buyStartPrice, buyEndPrice, a bid placement) rounds down, and an ask or sell price rounds up. Offsets and backoffs round half-up. The low-level orderListPlace(market, side, order) and orderListPlaceAndPop(market, side, order) take the side for this reason.
A fill's signature is optional: the server sends none when it has no valid signature for the fill, and the fill is still delivered.
Errors
ts
import { ApiError, StatusCode } from "@superis-labs/flint";
try {
await client.pairs();
} catch (err) {
if (err instanceof ApiError) {
switch (err.code) {
case StatusCode.ResourceExhausted: await sleep(backoff); break;
case StatusCode.Unavailable: await sleep(backoff); break;
}
}
}See Errors for the full code map.
Logging
The TypeScript SDK stays quiet unless you pass a logger. The logger interface is simple. When debug is present, transport construction logs the SDK version, proto hash, and proto revision stamped on outbound requests.
ts
type Logger = {
debug?: (message: string, fields?: Record<string, unknown>) => void;
trace?: (message: string, fields?: Record<string, unknown>) => void;
};To enable lifecycle logging plus full protobuf message payload logs:
ts
const logger = {
debug: (message: string, fields?: Record<string, unknown>) => console.debug(message, fields),
trace: (message: string, fields?: Record<string, unknown>) => console.debug(message, fields),
};
const client = Client.mainnet({
logger,
logMessages: {
enabled: true,
maxMessageChars: 50_000,
},
});Maker.connect and EmailAuthFlow take the same options.
Notes:
- Message payload logs are opt-in.
- Payload logging covers every client and auth flow in the SDK.
- Payloads are emitted through
logger.trace(...). maxMessageCharscaps each payload in characters. Use0to disable truncation.- Built-in redaction scrubs
nonce,signature,code, andsession_tokenonAuthServicepayloads. logMessages.redactcan rewrite the serialized payload after the built-in redaction.- Bearer headers and API key headers are not logged.
Wire format
The transport speaks application/grpc-web+proto over HTTP/1.1, terminating at the server's tonic_web::GrpcWebLayer. Server streaming is supported via AsyncIterable<Output> on every streaming RPC. There is no gRPC-streaming-bidi or client-streaming over gRPC-Web — those RPCs throw at call time.
Browser compatibility
Modern browsers (Chrome 90+, Firefox 90+, Safari 14+). Requires fetch and ReadableStream — both baseline in every release-channel browser since 2022.
