@stryke-xyz/premarket-sdk 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cjs/config/index.js +3 -3
  2. package/dist/cjs/package.json +1 -1
  3. package/dist/cjs/sync/clients/activity-client.js +325 -454
  4. package/dist/cjs/sync/clients/order-client.js +609 -429
  5. package/dist/esm/config/index.js +3 -3
  6. package/dist/esm/package.json +1 -1
  7. package/dist/esm/sync/clients/activity-client.js +325 -454
  8. package/dist/esm/sync/clients/order-client.js +609 -429
  9. package/dist/types/sync/clients/activity-client.d.ts +39 -32
  10. package/dist/types/sync/clients/order-client.d.ts +79 -58
  11. package/dist/types/sync/index.d.ts +2 -2
  12. package/package.json +58 -58
  13. package/dist/cjs/api/README.md +0 -296
  14. package/dist/cjs/config/README.md +0 -112
  15. package/dist/cjs/exchange/README.md +0 -280
  16. package/dist/cjs/registry/README.md +0 -150
  17. package/dist/cjs/shared/README.md +0 -235
  18. package/dist/cjs/shared/utils.js +0 -1
  19. package/dist/cjs/sync/README.md +0 -215
  20. package/dist/cjs/sync/clients/base-client.js +0 -518
  21. package/dist/cjs/sync/redis-ws-client.js +0 -235
  22. package/dist/cjs/utils/README.md +0 -89
  23. package/dist/cjs/vault/README.md +0 -268
  24. package/dist/esm/api/README.md +0 -296
  25. package/dist/esm/config/README.md +0 -112
  26. package/dist/esm/exchange/README.md +0 -280
  27. package/dist/esm/registry/README.md +0 -150
  28. package/dist/esm/shared/README.md +0 -235
  29. package/dist/esm/shared/utils.js +0 -0
  30. package/dist/esm/sync/README.md +0 -215
  31. package/dist/esm/sync/clients/base-client.js +0 -508
  32. package/dist/esm/sync/redis-ws-client.js +0 -225
  33. package/dist/esm/utils/README.md +0 -89
  34. package/dist/esm/vault/README.md +0 -268
  35. package/dist/types/shared/utils.d.ts +0 -0
  36. package/dist/types/sync/clients/base-client.d.ts +0 -56
  37. package/dist/types/sync/redis-ws-client.d.ts +0 -21
@@ -1,150 +0,0 @@
1
- # Registry Guide
2
-
3
- The `registry` module wraps the `MarketsRegistry` contract surface that the SDK
4
- needs for market configuration and market serialization. It is intentionally
5
- small: the goal is to keep market definitions consistent across contracts,
6
- backend services, and frontend consumers.
7
-
8
- ## Source map
9
-
10
- - [`index.ts`](./index.ts) re-exports the public registry surface
11
- - [`types.ts`](./types.ts) defines market structs and serializers
12
- - [`markets-registry-contract.ts`](./markets-registry-contract.ts) encodes
13
- `MarketsRegistry` calldata
14
-
15
- ## What this module is for
16
-
17
- In plain language:
18
-
19
- - it describes the market configuration shape used across the system
20
- - it converts that shape between `bigint` form and string-safe transport form
21
- - it encodes the registry's live write surface without each consumer shipping
22
- its own ABI wrapper
23
-
24
- ## Market types
25
-
26
- [`types.ts`](./types.ts) exports the registry's main data model:
27
-
28
- - `MarketType`
29
- - `ERC20xERC20`
30
- - `ERC20xERC6909`
31
- - `RegistryMarket`
32
- - bigint-based market definition used in code
33
- - `SerializedRegistryMarket`
34
- - string-safe market definition for JSON payloads and config files
35
-
36
- Core fields include:
37
-
38
- - token addresses: `underlying`, `collateral`, `delivery`, `owner`
39
- - sizing and strike metadata: `tickSize`, `tickSpacing`, `tokensPerTickSize`
40
- - expiry and fee fields: `expiry`, `depositFeeBps`, `redeemFeeBps`,
41
- `makerFeeBps`, `takerFeeBps`, `rolloverFeeBps`
42
- - runtime flags: `marketType`, `isCollateralScaled`, `nonRollable`
43
-
44
- Serialization helpers:
45
-
46
- - `serializeRegistryMarket(market)`
47
- - `deserializeRegistryMarket(market)`
48
-
49
- ```ts
50
- import {
51
- MarketType,
52
- serializeRegistryMarket,
53
- } from "@stryke-xyz/premarket-sdk";
54
-
55
- const market = serializeRegistryMarket({
56
- underlying: "0x1111111111111111111111111111111111111111",
57
- collateral: "0x2222222222222222222222222222222222222222",
58
- delivery: "0x3333333333333333333333333333333333333333",
59
- owner: "0x4444444444444444444444444444444444444444",
60
- tickSize: 100n,
61
- tickSpacing: 100n,
62
- tokensPerTickSize: 1_000_000n,
63
- expiry: 1_900_000_000n,
64
- depositFeeBps: 0n,
65
- redeemFeeBps: 0n,
66
- makerFeeBps: 2_000n,
67
- takerFeeBps: 2_000n,
68
- rolloverFeeBps: 0n,
69
- marketType: MarketType.ERC20xERC6909,
70
- isCollateralScaled: false,
71
- nonRollable: false,
72
- });
73
- ```
74
-
75
- ## Contract wrapper
76
-
77
- `MarketsRegistryContract` in
78
- [`markets-registry-contract.ts`](./markets-registry-contract.ts) wraps the
79
- shipped registry ABI and returns either calldata or a minimal tx envelope.
80
-
81
- ```ts
82
- import {
83
- MarketType,
84
- MarketsRegistryContract,
85
- } from "@stryke-xyz/premarket-sdk";
86
-
87
- const registry = new MarketsRegistryContract(registryAddress);
88
-
89
- const tx = registry.buildAddMarketTx({
90
- underlying: "0x1111111111111111111111111111111111111111",
91
- collateral: "0x2222222222222222222222222222222222222222",
92
- delivery: "0x3333333333333333333333333333333333333333",
93
- owner: "0x4444444444444444444444444444444444444444",
94
- tickSize: 100n,
95
- tickSpacing: 100n,
96
- tokensPerTickSize: 1_000_000n,
97
- expiry: 1_900_000_000n,
98
- depositFeeBps: 0n,
99
- redeemFeeBps: 0n,
100
- makerFeeBps: 2_000n,
101
- takerFeeBps: 2_000n,
102
- rolloverFeeBps: 0n,
103
- marketType: MarketType.ERC20xERC6909,
104
- isCollateralScaled: false,
105
- nonRollable: false,
106
- });
107
- ```
108
-
109
- Public surfaces:
110
-
111
- - `RegistryTransactionCall`
112
- - `{ to, value?, data }`
113
- - `MarketsRegistryContract`
114
- - `getAddMarketCalldata(market)`
115
- - `buildAddMarketTx(market)`
116
- - `getUpdateTokenCalldata(token, isStable, isDelete)`
117
- - `getSetWhitelistedCalldata(account, allowed)`
118
- - `getUpdateMarketExpiryCalldata(marketId, expiry)`
119
- - `getMulticallCalldata(data)`
120
-
121
- Important nuance:
122
-
123
- - only `buildAddMarketTx` currently returns a full transaction object
124
- - the remaining helpers return raw calldata, which is often what relayers,
125
- deployment scripts, or admin consoles actually want
126
-
127
- ## Restricted surfaces
128
-
129
- Most registry writes are administrative by nature. The SDK documents them
130
- because they are exported and useful to privileged tooling, but they should not
131
- be treated as ordinary end-user operations:
132
-
133
- - `getAddMarketCalldata`
134
- - `buildAddMarketTx`
135
- - `getUpdateTokenCalldata`
136
- - `getSetWhitelistedCalldata`
137
- - `getUpdateMarketExpiryCalldata`
138
- - `getMulticallCalldata`
139
-
140
- ## How this module fits with the rest of the SDK
141
-
142
- - the [Vault guide](../vault/README.md) uses registry-aligned market fields for
143
- collateral and settlement math
144
- - the [Config guide](../config/README.md) ships deployed registry addresses
145
- - the [API guide](../api/README.md) returns market DTOs that map naturally back
146
- to `RegistryMarket`-style concepts
147
-
148
- When protocol market semantics change, this module is one of the first places
149
- that should be updated, because downstream consumers assume it represents the
150
- canonical market shape.
@@ -1,235 +0,0 @@
1
- # Shared Types Guide
2
-
3
- The `shared` module collects the DTOs that move between the SDK, the HTTP API,
4
- and frontend consumers. These types are intentionally transport-oriented:
5
- numeric fields are usually strings so they can be serialized safely over JSON.
6
-
7
- ## Source map
8
-
9
- - [`index.ts`](./index.ts) re-exports the shared surface
10
- - [`types.ts`](./types.ts) defines order, market, PnL, history, and snapshot DTOs
11
-
12
- ## Why this module matters
13
-
14
- These types are the glue between:
15
-
16
- - `OrderbookApi` in the [API guide](../api/README.md)
17
- - frontend state and caches
18
- - backend responses and request payloads
19
- - SDK helpers that need a JSON-safe representation of onchain data
20
-
21
- ## Order transport types
22
-
23
- ### `Order`
24
-
25
- `Order` is the serialized transport-safe order shape used by HTTP payloads:
26
-
27
- ```ts
28
- export interface Order {
29
- salt: string;
30
- nonce: string;
31
- marketId: string;
32
- makingAmount: string;
33
- takingAmount: string;
34
- deadline: string;
35
- maker: string;
36
- receiver: string;
37
- tradeType: number;
38
- signatureType: number;
39
- tokenId: string;
40
- }
41
- ```
42
-
43
- Related order types:
44
-
45
- - `OrderSignature`
46
- - raw `0x...` signature bytes
47
- - `OrderStatus`
48
- - `OPEN`, `PARTIALLY_FILLED`, `FULLY_FILLED`, `CANCELLED`, `EXPIRED`
49
- - `TimeInForce`
50
- - `FOK`, `FAK`, `GTC`, `GTD`
51
- - `CreateOrderParams`
52
- - request body for `OrderbookApi.createOrder`
53
- - `CreateOrderRequest`
54
- - alias of `CreateOrderParams`
55
- - `StoredOrder`
56
- - persisted order record including status, side, price, remaining amount, and
57
- timestamps
58
- - `MatchableOrder`
59
- - alias of `StoredOrder`
60
- - `MatchRequest`
61
- - matching-oriented request model
62
- - `MatchedOrder`
63
- - one resolved match leg
64
- - `MatchResult`
65
- - aggregate match outcome
66
- - `CreateOrderResult`
67
- - order creation result plus match details
68
- - `OrderQueryParams`
69
- - query filters for list reads
70
- - `OrderResponse`
71
- - generic envelope shape used by some backend responses
72
- - `OrdersSnapshot`
73
- - `{ orders, count }`
74
- - `QueryOrdersResponse`
75
- - paginated query result with `limit` and `offset`
76
- - `DepthSnapshot`
77
- - point-in-time depth view for one market and token pair
78
-
79
- ### `CreateOrderParams`
80
-
81
- This is the main order write payload:
82
-
83
- ```ts
84
- export interface CreateOrderParams {
85
- marketId: string;
86
- order: Order;
87
- signature: OrderSignature;
88
- operator?: string;
89
- timeInForce?: TimeInForce;
90
- postOnly?: boolean;
91
- }
92
- ```
93
-
94
- ### `StoredOrder`
95
-
96
- This is the main order read model:
97
-
98
- ```ts
99
- export interface StoredOrder {
100
- orderHash: string;
101
- signature: OrderSignature;
102
- marketId: string;
103
- tokenId: string;
104
- remainingMakerAmount: string;
105
- order: Order;
106
- operator?: string;
107
- createdAt: number;
108
- status: OrderStatus;
109
- side: "bid" | "ask";
110
- price: number;
111
- }
112
- ```
113
-
114
- ## Market DTOs
115
-
116
- The market section of [`types.ts`](./types.ts) defines what the API returns for
117
- catalog and single-market reads.
118
-
119
- Public types:
120
-
121
- - `MarketInstrument`
122
- - `Market`
123
- - `MarketResponse`
124
- - `MarketsResponse`
125
-
126
- `MarketInstrument` carries the tradable strike-level data:
127
-
128
- - ids and labels
129
- - `tick`, `isSpread`, `isCall`
130
- - paired token ids: `prmTokenId`, `oPrmTokenId`
131
- - top-of-book and recent price fields
132
- - collateral and supply totals
133
-
134
- `Market` wraps the market-level metadata:
135
-
136
- - identifiers and descriptive fields
137
- - price band and increment fields
138
- - token addresses for `underlying`, `collateral`, and `delivery`
139
- - fee fields and expiry
140
- - `marketType`, `isCollateralScaled`, `nonRollable`
141
- - nested `instruments`
142
-
143
- `MarketsResponse` has the shape:
144
-
145
- ```ts
146
- {
147
- success: true;
148
- data: {
149
- markets: Market[];
150
- total: number;
151
- };
152
- }
153
- ```
154
-
155
- ## Position and PnL DTOs
156
-
157
- Public types:
158
-
159
- - `UserPosition`
160
- - `TradingPnL`
161
- - `UserPnL`
162
- - `TokenPnL`
163
- - `Erc20PnL`
164
-
165
- These types separate position-level accounting from trading-level accounting:
166
-
167
- - `UserPosition`
168
- - current holding and realized position PnL for one token id
169
- - `TradingPnL`
170
- - realized trading activity grouped by asset and optional token id
171
- - `UserPnL`
172
- - top-level aggregate summary
173
- - `TokenPnL`
174
- - combined position and trading breakdown for one ERC-6909 token id
175
- - `Erc20PnL`
176
- - combined trading breakdown for one ERC-20 token address
177
-
178
- Use these types when rendering user dashboards or analytics screens.
179
-
180
- ## History DTOs
181
-
182
- Public history types:
183
-
184
- - `MintHistoryItem`
185
- - `RedeemHistoryItem`
186
- - `UnwindHistoryItem`
187
- - `TransferHistoryItem`
188
- - `OrderFillHistoryItem`
189
- - `MarketTradeItem`
190
- - alias of `OrderFillHistoryItem`
191
- - `UserHistories`
192
-
193
- `UserHistories` groups the main public activity feeds:
194
-
195
- ```ts
196
- export interface UserHistories {
197
- mints: MintHistoryItem[];
198
- redeems: RedeemHistoryItem[];
199
- unwinds: UnwindHistoryItem[];
200
- transfers: TransferHistoryItem[];
201
- fills: OrderFillHistoryItem[];
202
- }
203
- ```
204
-
205
- The individual item types carry the fields that matter to product experiences:
206
-
207
- - transaction hash and block context
208
- - token ids and amount strings
209
- - sender, receiver, maker, and taker addresses where applicable
210
- - timestamps suitable for activity feeds
211
-
212
- ## Depth snapshot type
213
-
214
- `DepthSnapshot` is the HTTP snapshot companion to the realtime sync clients. It
215
- contains the current bid and ask ladders plus market and token identifiers.
216
-
217
- This type is commonly paired with the [Sync guide](../sync/README.md), where
218
- `MarketDepthSyncClient` turns snapshot state into a continuously updated local
219
- book.
220
-
221
- ## Sensitive and restricted DTOs
222
-
223
- `types.ts` also exports `AuthChallenge`. The SDK keeps that type public because
224
- the auth helpers use it, but this guide intentionally does not provide a full
225
- field-by-field auth payload walkthrough. The focus here is the general public
226
- integration contract used by application code.
227
-
228
- ## How to use these types well
229
-
230
- - use `OrderHelper` or exchange serializers when converting between bigint
231
- orders and `Order`
232
- - treat numeric strings as exact values, not display-formatted strings
233
- - convert to `bigint` only at the application boundary where you need math
234
- - prefer the deserializers in [`../api/orderbook-api/deserializers.ts`](../api/orderbook-api/deserializers.ts)
235
- when you want typed bigint conversion rather than ad hoc parsing
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,215 +0,0 @@
1
- # Sync Guide
2
-
3
- The `sync` module contains the SDK's realtime clients. These clients keep a
4
- frontend or service in sync with depth and activity streams without each
5
- consumer rewriting its own websocket lifecycle, reconnect, sequencing, and
6
- normalization logic.
7
-
8
- ## Source map
9
-
10
- - [`index.ts`](./index.ts) re-exports the public sync surface
11
- - [`types.ts`](./types.ts) defines shared lifecycle and sequencing types
12
- - [`clients/base-client.ts`](./clients/base-client.ts) provides an extensible
13
- base class for Redis-backed sequenced streams
14
- - [`clients/order-client.ts`](./clients/order-client.ts) implements
15
- market-depth syncing
16
- - [`clients/activity-client.ts`](./clients/activity-client.ts) implements order
17
- fill activity syncing
18
-
19
- ## What this module is for
20
-
21
- In plain language:
22
-
23
- - it keeps a local orderbook view current
24
- - it emits lifecycle updates such as connecting, syncing, and recovering
25
- - it gives callers normalized callback hooks instead of raw websocket messages
26
-
27
- ## Shared sync types
28
-
29
- [`types.ts`](./types.ts) exports the shared lifecycle and sequencing model:
30
-
31
- - `SyncStatus`
32
- - `"connecting" | "syncing" | "synced" | "recovering" | "disconnected" | "error"`
33
- - `OrderChange`
34
- - a single `INSERT`, `UPDATE`, or `DELETE` orderbook mutation
35
- - `SequencedMessage`
36
- - `{ seq, previousSeq, marketId, change, timestamp }`
37
- - `SyncClientConfig`
38
- - base config shape for sequenced sync clients
39
-
40
- ## MarketDepthSyncClient
41
-
42
- `MarketDepthSyncClient` is the main realtime client for market depth. It keeps
43
- token-level bid and ask books, tracks per-token sequence ids, normalizes price
44
- keys, handles reconnect logic, and exposes readable snapshot and delta hooks.
45
-
46
- ### Config
47
-
48
- `MarketDepthClientConfig` from [`clients/order-client.ts`](./clients/order-client.ts):
49
-
50
- - `wsUrl`
51
- - `marketId`
52
- - `tokenIds`
53
- - `heartbeatIntervalMs?`
54
- - `heartbeatTimeoutMs?`
55
- - `maxReconnectAttempts?`
56
- - `initialReconnectDelayMs?`
57
- - `maxReconnectDelayMs?`
58
-
59
- ### Connection methods
60
-
61
- - `connect()`
62
- - `disconnect()`
63
- - `getStatus()`
64
-
65
- ### Read methods
66
-
67
- - `getTokenIds()`
68
- - `getTokenState(tokenId)`
69
- - `getBids(tokenId)`
70
- - `getAsks(tokenId)`
71
- - `getBestBid(tokenId)`
72
- - `getBestAsk(tokenId)`
73
- - `getLastPrice(tokenId)`
74
- - `getSeq(tokenId)`
75
- - `getSpread(tokenId)`
76
- - `getDepthAtPrice(tokenId, side, price)`
77
-
78
- ### Listener hooks
79
-
80
- - `onStatus(callback)`
81
- - `onSnapshot(callback)`
82
- - `onDelta(callback)`
83
-
84
- ### Public event types
85
-
86
- - `DepthLevel`
87
- - `TokenDepthSnapshot`
88
- - `DepthLevelUpdate`
89
- - `DepthChangeEvent`
90
- - `DepthUpdate`
91
-
92
- ```ts
93
- import { MarketDepthSyncClient } from "@stryke-xyz/premarket-sdk";
94
-
95
- const client = new MarketDepthSyncClient({
96
- wsUrl: "wss://example.stryke.xyz",
97
- marketId: "12",
98
- tokenIds: ["123", "124"],
99
- });
100
-
101
- client.onSnapshot((snapshots) => {
102
- console.log("initial snapshots", snapshots);
103
- });
104
-
105
- client.onDelta((marketId, update) => {
106
- console.log("delta", marketId, update);
107
- });
108
-
109
- await client.connect();
110
- ```
111
-
112
- Useful details captured by the implementation:
113
-
114
- - the client rejects invalid non-websocket URLs
115
- - it waits for initial snapshots before resolving `connect()`
116
- - it deduplicates sequence ids and detects gaps
117
- - depth lookups normalize equivalent price strings like `"1"` and `"1.000000"`
118
-
119
- ## ActivitySyncClient
120
-
121
- `ActivitySyncClient` subscribes to order-fill activity for a market, a user, or
122
- both. It is intentionally simpler than the depth client because it does not
123
- maintain a mutable book; it forwards fill events as they arrive.
124
-
125
- ### Config
126
-
127
- `ActivityClientConfig` from [`clients/activity-client.ts`](./clients/activity-client.ts):
128
-
129
- - `wsUrl`
130
- - `marketId?`
131
- - `userAddress?`
132
- - `heartbeatIntervalMs?`
133
- - `heartbeatTimeoutMs?`
134
- - `maxReconnectAttempts?`
135
- - `initialReconnectDelayMs?`
136
- - `maxReconnectDelayMs?`
137
-
138
- At least one of `marketId` or `userAddress` is required.
139
-
140
- ### Connection methods
141
-
142
- - `connect()`
143
- - `disconnect()`
144
- - `getStatus()`
145
-
146
- ### Listener hooks
147
-
148
- - `onStatus(callback)`
149
- - `onOrderFill(callback)`
150
- - `onUserFill(callback)`
151
- - `onMarketFill(callback)`
152
-
153
- ### Event type
154
-
155
- - `OrderFillEvent`
156
-
157
- ```ts
158
- import { ActivitySyncClient } from "@stryke-xyz/premarket-sdk";
159
-
160
- const activity = new ActivitySyncClient({
161
- wsUrl: "wss://example.stryke.xyz",
162
- marketId: "12",
163
- });
164
-
165
- activity.onMarketFill((event) => {
166
- console.log("fill", event.orderHash, event.makingAmount, event.takingAmount);
167
- });
168
-
169
- await activity.connect();
170
- ```
171
-
172
- ## BaseSyncClient
173
-
174
- `BaseSyncClient` in [`clients/base-client.ts`](./clients/base-client.ts) is an
175
- advanced extension surface for sequenced Redis-backed streams. It is exported so
176
- integrators can build their own sync clients on the same foundation when
177
- necessary.
178
-
179
- Public methods:
180
-
181
- - `connect()`
182
- - `disconnect()`
183
- - `getStatus()`
184
- - `isSynced()`
185
- - `getLastSequence()`
186
- - `getBufferedCount()`
187
- - `onStatus(callback)`
188
- - `onChange(callback)`
189
- - `onSnapshot(callback)`
190
-
191
- What it handles for subclasses:
192
-
193
- - websocket subscription lifecycle
194
- - initial snapshot gating
195
- - sequence ordering and deduplication
196
- - full resync on gap detection
197
- - listener registration and notification
198
-
199
- What subclasses must provide:
200
-
201
- - `fetchSnapshot()`
202
- - `applyMessage(message)`
203
-
204
- If you do not need to build a custom client, prefer `MarketDepthSyncClient` or
205
- `ActivitySyncClient`.
206
-
207
- ## Recommended usage
208
-
209
- - use `MarketDepthSyncClient` when the UI needs an interactive orderbook
210
- - use `ActivitySyncClient` when the UI needs trade tape or user activity feeds
211
- - use `BaseSyncClient` only when you are creating a new specialized sync client
212
- on top of the same sequencing model
213
-
214
- For snapshot DTOs used alongside these streams, see the
215
- [Shared types guide](../shared/README.md).