@stryke-xyz/premarket-sdk 1.0.7 → 1.1.0
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.
- package/README.md +861 -159
- package/dist/cjs/api/orderbook-api/deserializers.js +98 -5
- package/dist/cjs/api/orderbook-api/index.js +25 -61
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/shared/types.js +1 -1
- package/dist/cjs/sync/clients/activity-client.js +11 -17
- package/dist/cjs/sync/clients/order-client.js +84 -150
- package/dist/cjs/sync/index.js +0 -4
- package/dist/esm/api/orderbook-api/deserializers.js +98 -5
- package/dist/esm/api/orderbook-api/index.js +25 -61
- package/dist/esm/package.json +1 -1
- package/dist/esm/shared/types.js +1 -1
- package/dist/esm/sync/clients/activity-client.js +11 -17
- package/dist/esm/sync/clients/order-client.js +84 -150
- package/dist/esm/sync/index.js +0 -1
- package/dist/esm/sync/types.js +1 -3
- package/dist/types/api/orderbook-api/deserializers.d.ts +46 -6
- package/dist/types/api/orderbook-api/index.d.ts +16 -12
- package/dist/types/shared/types.d.ts +58 -41
- package/dist/types/sync/clients/order-client.d.ts +9 -12
- package/dist/types/sync/index.d.ts +2 -3
- package/dist/types/sync/types.d.ts +0 -23
- package/package.json +1 -1
- package/dist/cjs/api/README.md +0 -296
- package/dist/cjs/config/README.md +0 -112
- package/dist/cjs/exchange/README.md +0 -280
- package/dist/cjs/registry/README.md +0 -150
- package/dist/cjs/shared/README.md +0 -235
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/sync/README.md +0 -215
- package/dist/cjs/sync/clients/base-client.js +0 -518
- package/dist/cjs/sync/redis-ws-client.js +0 -235
- package/dist/cjs/utils/README.md +0 -89
- package/dist/cjs/vault/README.md +0 -268
- package/dist/esm/api/README.md +0 -296
- package/dist/esm/config/README.md +0 -112
- package/dist/esm/exchange/README.md +0 -280
- package/dist/esm/registry/README.md +0 -150
- package/dist/esm/shared/README.md +0 -235
- package/dist/esm/shared/utils.js +0 -0
- package/dist/esm/sync/README.md +0 -215
- package/dist/esm/sync/clients/base-client.js +0 -508
- package/dist/esm/sync/redis-ws-client.js +0 -225
- package/dist/esm/utils/README.md +0 -89
- package/dist/esm/vault/README.md +0 -268
- package/dist/types/shared/utils.d.ts +0 -0
- package/dist/types/sync/clients/base-client.d.ts +0 -56
- package/dist/types/sync/redis-ws-client.d.ts +0 -21
package/README.md
CHANGED
|
@@ -1,82 +1,27 @@
|
|
|
1
1
|
# premarket-sdk
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for Stryke premarket integrations across
|
|
3
|
+
TypeScript SDK for Stryke premarket integrations across onchain contracts,
|
|
4
|
+
backend APIs, and frontend runtimes.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
- `smart-account` contracts (`SimpleAccountFactory`, `EntryPoint`)
|
|
7
|
-
- `premarkets-api` HTTP and WebSocket services
|
|
8
|
-
- `premarkets-interface` frontend runtime
|
|
6
|
+
The package brings together:
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
- native `Exchange` order building, hashing, signing, math, and calldata
|
|
9
|
+
- `OptionMarketVault` token-id helpers, collateral math, and tx builders
|
|
10
|
+
- `MarketsRegistry` market serialization and admin calldata builders
|
|
11
|
+
- `OrderHelper` and `OrderbookApi` for application-facing integrations
|
|
12
|
+
- realtime sync clients for market depth and activity streams
|
|
13
|
+
- chain metadata, deployed addresses, and token constants
|
|
14
|
+
- smart-account derivation and deployment helpers
|
|
15
|
+
- shared transport DTOs for API and UI consumers
|
|
14
16
|
|
|
15
|
-
##
|
|
17
|
+
## Install
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
builders
|
|
21
|
-
- `MarketsRegistry` market serialization and contract calldata builders
|
|
22
|
-
- `OrderHelper` and `OrderbookApi` for backend and frontend integrations
|
|
23
|
-
- realtime sync clients for market depth and activity streams
|
|
24
|
-
- chain definitions, token metadata, and deployed contract addresses
|
|
25
|
-
- smart-account address derivation and deployment checks
|
|
26
|
-
- shared DTOs used by HTTP clients and frontend consumers
|
|
27
|
-
|
|
28
|
-
## Documentation Map
|
|
29
|
-
|
|
30
|
-
The new documentation set lives alongside the legacy docs during migration.
|
|
31
|
-
Start here, then drill into the module guide that matches the surface you are
|
|
32
|
-
integrating.
|
|
33
|
-
|
|
34
|
-
### Module guides
|
|
35
|
-
|
|
36
|
-
- [Exchange guide](./src/exchange/README.md)
|
|
37
|
-
- [Vault guide](./src/vault/README.md)
|
|
38
|
-
- [Registry guide](./src/registry/README.md)
|
|
39
|
-
- [API guide](./src/api/README.md)
|
|
40
|
-
- [Sync guide](./src/sync/README.md)
|
|
41
|
-
- [Config guide](./src/config/README.md)
|
|
42
|
-
- [Shared types guide](./src/shared/README.md)
|
|
43
|
-
- [Utilities guide](./src/utils/README.md)
|
|
44
|
-
|
|
45
|
-
### Root-level exports
|
|
46
|
-
|
|
47
|
-
The package root also exports a handful of single-file helpers that do not live
|
|
48
|
-
under one directory package:
|
|
49
|
-
|
|
50
|
-
- `smart-account`
|
|
51
|
-
- Source: [`src/smart-account.ts`](./src/smart-account.ts)
|
|
52
|
-
- Public surfaces: `SmartAccountHelper`, `getCurrentSalt`,
|
|
53
|
-
`getSmartAccountAddress`, `getAccountCount`,
|
|
54
|
-
`isSmartAccountDeployed`, `getCurrentSmartAccount`,
|
|
55
|
-
`SmartAccountConfig`, `SmartAccountResult`
|
|
56
|
-
- `address`
|
|
57
|
-
- Source: [`src/address.ts`](./src/address.ts)
|
|
58
|
-
- Public surface: `Address`
|
|
59
|
-
- `bps`
|
|
60
|
-
- Source: [`src/bps.ts`](./src/bps.ts)
|
|
61
|
-
- Public surface: `Bps`
|
|
62
|
-
- compatibility and address helpers
|
|
63
|
-
- Source: [`src/constants.ts`](./src/constants.ts)
|
|
64
|
-
- Public surfaces: `ZX`, `getExchangeContract`,
|
|
65
|
-
`getLimitOrderContract`, `getMarketsRegistryContract`,
|
|
66
|
-
`getNativeOrderFactoryContract`, `getNativeOrderImplContract`
|
|
67
|
-
- generic utilities
|
|
68
|
-
- Source: [`src/utils/mul-div.ts`](./src/utils/mul-div.ts),
|
|
69
|
-
[`src/utils/rand-bigint.ts`](./src/utils/rand-bigint.ts),
|
|
70
|
-
[`src/utils/orderUtils.ts`](./src/utils/orderUtils.ts)
|
|
71
|
-
- Public surfaces: `mulDiv`, `Rounding`, `randBigInt`,
|
|
72
|
-
`optionPrmToPrmTokenId`, `prmToOptionPrmTokenId`,
|
|
73
|
-
`isComplementaryOptionTokenPair`, `verifyOrderSignature`
|
|
19
|
+
```bash
|
|
20
|
+
bun add @stryke-xyz/premarket-sdk
|
|
21
|
+
```
|
|
74
22
|
|
|
75
23
|
## Quick Start
|
|
76
24
|
|
|
77
|
-
The SDK is designed so an integrator can stay inside the package root for most
|
|
78
|
-
common workflows.
|
|
79
|
-
|
|
80
25
|
```ts
|
|
81
26
|
import {
|
|
82
27
|
EXCHANGE,
|
|
@@ -106,23 +51,784 @@ const order = helper.buildOrder({
|
|
|
106
51
|
tokenId: 42n,
|
|
107
52
|
});
|
|
108
53
|
|
|
54
|
+
const signature = await helper.signEip712Order(order, walletClient);
|
|
109
55
|
const payload = helper.serializeOrder(order);
|
|
110
56
|
|
|
111
57
|
const api = new OrderbookApi({ baseUrl: "https://example.stryke.xyz" });
|
|
112
|
-
await api.
|
|
58
|
+
await api.createOrder(
|
|
59
|
+
{
|
|
60
|
+
marketId: payload.marketId,
|
|
61
|
+
order: payload,
|
|
62
|
+
signature,
|
|
63
|
+
timeInForce: "GTC",
|
|
64
|
+
postOnly: false,
|
|
65
|
+
},
|
|
66
|
+
bearerToken,
|
|
67
|
+
);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Source Layout
|
|
71
|
+
|
|
72
|
+
- `src/exchange`: native order model, EIP-712 helpers, order math, and exchange
|
|
73
|
+
calldata builders
|
|
74
|
+
- `src/api`: `OrderHelper`, `OrderbookApi`, and response deserializers
|
|
75
|
+
- `src/vault`: token-id derivation, collateral math, and vault tx builders
|
|
76
|
+
- `src/registry`: market serialization and registry calldata builders
|
|
77
|
+
- `src/sync`: realtime depth and activity clients
|
|
78
|
+
- `src/config`: supported chains, token metadata, and deployed addresses
|
|
79
|
+
- `src/shared`: transport DTOs shared across SDK, API, and UI
|
|
80
|
+
- `src/utils`: reusable math, randomness, token-pair, and signature helpers
|
|
81
|
+
- `src/smart-account.ts`: deterministic smart-account helpers
|
|
82
|
+
- `src/address.ts`: address convenience wrapper
|
|
83
|
+
- `src/bps.ts`: basis-point helper wrapper
|
|
84
|
+
- `src/constants.ts`: compatibility address helpers
|
|
85
|
+
|
|
86
|
+
## Exchange Module
|
|
87
|
+
|
|
88
|
+
Source files:
|
|
89
|
+
|
|
90
|
+
- `src/exchange/index.ts`
|
|
91
|
+
- `src/exchange/types.ts`
|
|
92
|
+
- `src/exchange/order.ts`
|
|
93
|
+
- `src/exchange/eip712.ts`
|
|
94
|
+
- `src/exchange/math.ts`
|
|
95
|
+
- `src/exchange/exchange-contract.ts`
|
|
96
|
+
- `src/exchange/errors.ts`
|
|
97
|
+
|
|
98
|
+
This is the trading core of the SDK. It models Stryke's native order format,
|
|
99
|
+
mirrors the contract's EIP-712 schema, reproduces key fee and crossing math,
|
|
100
|
+
and encodes calldata for fills, matches, cancellation, and batching.
|
|
101
|
+
|
|
102
|
+
### Core order model
|
|
103
|
+
|
|
104
|
+
The canonical in-memory type is `ExchangeOrder`, where numeric fields are
|
|
105
|
+
stored as `bigint`.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
export interface ExchangeOrder {
|
|
109
|
+
salt: bigint;
|
|
110
|
+
nonce: bigint;
|
|
111
|
+
marketId: bigint;
|
|
112
|
+
makingAmount: bigint;
|
|
113
|
+
takingAmount: bigint;
|
|
114
|
+
deadline: bigint;
|
|
115
|
+
maker: Address;
|
|
116
|
+
receiver: Address;
|
|
117
|
+
tradeType: TradeType;
|
|
118
|
+
signatureType: SignatureType;
|
|
119
|
+
tokenId: bigint;
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Related public types:
|
|
124
|
+
|
|
125
|
+
- `TradeType`: `BUY = 0`, `SELL = 1`
|
|
126
|
+
- `SignatureType`: `EIP712 = 0`, `ERC1271 = 1`
|
|
127
|
+
- `SerializedExchangeOrder`
|
|
128
|
+
- `ExchangeOrderStatus`
|
|
129
|
+
- `SerializedExchangeOrderStatus`
|
|
130
|
+
- `MulticallResult`
|
|
131
|
+
|
|
132
|
+
### Order building and validation
|
|
133
|
+
|
|
134
|
+
Public helpers:
|
|
135
|
+
|
|
136
|
+
- `buildExchangeOrder(params)`
|
|
137
|
+
- `validateExchangeOrder(order)`
|
|
138
|
+
- `isOrderExpired(order, nowSec?)`
|
|
139
|
+
- `getExecutableMakingAmount(order, status)`
|
|
140
|
+
- `getExchangeOrderHash(order, chainId, exchangeAddress)`
|
|
141
|
+
|
|
142
|
+
Builder behavior:
|
|
143
|
+
|
|
144
|
+
- `salt` defaults to a random 96-bit-compatible value
|
|
145
|
+
- `receiver` defaults to `maker`
|
|
146
|
+
- `signatureType` defaults to `SignatureType.EIP712`
|
|
147
|
+
- `makingAmount`, `takingAmount`, and `deadline` must be positive
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import {
|
|
151
|
+
SignatureType,
|
|
152
|
+
TradeType,
|
|
153
|
+
buildExchangeOrder,
|
|
154
|
+
} from "@stryke-xyz/premarket-sdk";
|
|
155
|
+
|
|
156
|
+
const order = buildExchangeOrder({
|
|
157
|
+
maker: "0x1111111111111111111111111111111111111111",
|
|
158
|
+
nonce: 12n,
|
|
159
|
+
marketId: 7n,
|
|
160
|
+
makingAmount: 1_000_000n,
|
|
161
|
+
takingAmount: 500_000n,
|
|
162
|
+
deadline: 1_900_000_000n,
|
|
163
|
+
tradeType: TradeType.SELL,
|
|
164
|
+
signatureType: SignatureType.EIP712,
|
|
165
|
+
tokenId: 123456n,
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Signing and hashing
|
|
170
|
+
|
|
171
|
+
Important constants:
|
|
172
|
+
|
|
173
|
+
- `EXCHANGE_EIP712_NAME = "Exchange"`
|
|
174
|
+
- `EXCHANGE_EIP712_VERSION = "1"`
|
|
175
|
+
- `EXCHANGE_ORDER_TYPES`
|
|
176
|
+
|
|
177
|
+
Public helpers:
|
|
178
|
+
|
|
179
|
+
- `getExchangeDomain(chainId, verifyingContract)`
|
|
180
|
+
- `getExchangeTypedData(order, chainId, verifyingContract)`
|
|
181
|
+
- `hashExchangeOrder(order, chainId, verifyingContract)`
|
|
182
|
+
- `recoverExchangeOrderSigner(order, signature, chainId, verifyingContract)`
|
|
183
|
+
|
|
184
|
+
These helpers should be used anywhere exact onchain signature parity matters.
|
|
185
|
+
|
|
186
|
+
### Serialization helpers
|
|
187
|
+
|
|
188
|
+
Public helpers:
|
|
189
|
+
|
|
190
|
+
- `serializeExchangeOrder(order)`
|
|
191
|
+
- `deserializeExchangeOrder(order)`
|
|
192
|
+
- `serializeOrderStatus(status)`
|
|
193
|
+
- `deserializeOrderStatus(status)`
|
|
194
|
+
|
|
195
|
+
Use these when moving between bigint-based local models and JSON-safe payloads.
|
|
196
|
+
|
|
197
|
+
### Math helpers
|
|
198
|
+
|
|
199
|
+
Public constants:
|
|
200
|
+
|
|
201
|
+
- `EXCHANGE_ONE = 10n ** 18n`
|
|
202
|
+
- `FEE_RATE_BASE = 1_000_000n`
|
|
203
|
+
|
|
204
|
+
Public functions:
|
|
205
|
+
|
|
206
|
+
- `getTakingAmount(fillMakingAmount, orderMakingAmount, orderTakingAmount)`
|
|
207
|
+
- `getMakingAmount(fillTakingAmount, orderMakingAmount, orderTakingAmount)`
|
|
208
|
+
- `calculateFee(grossAmount, feeRate)`
|
|
209
|
+
- `applyFee(grossAmount, feeRate)`
|
|
210
|
+
- `getOrderPriceWad(order)`
|
|
211
|
+
- `optionPrmToPrmId(tokenId)`
|
|
212
|
+
- `isCrossing(orderA, orderB)`
|
|
213
|
+
- `hasValidTokenPairForMatch(orderA, orderB)`
|
|
214
|
+
|
|
215
|
+
### Calldata builders
|
|
216
|
+
|
|
217
|
+
`ExchangeContract` wraps the shipped ABI and returns either raw calldata or a
|
|
218
|
+
lightweight transaction envelope.
|
|
219
|
+
|
|
220
|
+
Public methods:
|
|
221
|
+
|
|
222
|
+
- `getFillOrderCalldata(order, fillAmount, signature)`
|
|
223
|
+
- `buildFillOrderTx(order, fillAmount, signature)`
|
|
224
|
+
- `getMatchOrderCalldata(takerOrder, takerSignature, makerOrder, makerSignature, takerFillAmount, makerFillAmount)`
|
|
225
|
+
- `buildMatchOrderTx(takerOrder, takerSignature, makerOrder, makerSignature, takerFillAmount, makerFillAmount)`
|
|
226
|
+
- `getCancelOrderCalldata(order)`
|
|
227
|
+
- `getIncrementNonceCalldata()`
|
|
228
|
+
- `getSetResolverWhitelistCalldata(resolver, isWhitelisted)`
|
|
229
|
+
- `getSetFeeReceiverCalldata(newFeeReceiver)`
|
|
230
|
+
- `getPauseCalldata()`
|
|
231
|
+
- `getUnpauseCalldata()`
|
|
232
|
+
- `getMulticallCalldata(data, allowFailure?)`
|
|
233
|
+
|
|
234
|
+
`buildFillOrderTx` and `buildMatchOrderTx` return `{ to, data, value }`.
|
|
235
|
+
The remaining helpers return calldata only.
|
|
236
|
+
|
|
237
|
+
Restricted or admin-oriented surfaces:
|
|
238
|
+
|
|
239
|
+
- `getSetResolverWhitelistCalldata`
|
|
240
|
+
- `getSetFeeReceiverCalldata`
|
|
241
|
+
- `getPauseCalldata`
|
|
242
|
+
- `getUnpauseCalldata`
|
|
243
|
+
|
|
244
|
+
### Error decoding
|
|
245
|
+
|
|
246
|
+
`decodeContractError` attempts to decode revert payloads against the shipped
|
|
247
|
+
`Exchange`, `OptionMarketVault`, and `MarketsRegistry` ABIs.
|
|
248
|
+
|
|
249
|
+
It returns either `null` or:
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
interface DecodedContractError {
|
|
253
|
+
contract: "exchange" | "optionMarketVault" | "marketsRegistry";
|
|
254
|
+
name: string;
|
|
255
|
+
signature: string;
|
|
256
|
+
args: readonly unknown[];
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## API Module
|
|
261
|
+
|
|
262
|
+
Source files:
|
|
263
|
+
|
|
264
|
+
- `src/api/index.ts`
|
|
265
|
+
- `src/api/order-helper.ts`
|
|
266
|
+
- `src/api/orderbook-api/index.ts`
|
|
267
|
+
- `src/api/orderbook-api/deserializers.ts`
|
|
268
|
+
- `src/shared/types.ts`
|
|
269
|
+
|
|
270
|
+
This module gives most applications the two highest-level integration surfaces:
|
|
271
|
+
`OrderHelper` for working with orders and `OrderbookApi` for HTTP reads and
|
|
272
|
+
writes.
|
|
273
|
+
|
|
274
|
+
### OrderHelper
|
|
275
|
+
|
|
276
|
+
`OrderHelper` exists so consumers do not need to manually stitch together order
|
|
277
|
+
building, hashing, typed-data generation, signing, and serialization.
|
|
278
|
+
|
|
279
|
+
Constructor config:
|
|
280
|
+
|
|
281
|
+
- `chainId`
|
|
282
|
+
- `exchangeAddress`
|
|
283
|
+
|
|
284
|
+
Public methods:
|
|
285
|
+
|
|
286
|
+
- `buildOrder(params)`
|
|
287
|
+
- `buildSellOrder(params)`
|
|
288
|
+
- `buildBuyOrder(params)`
|
|
289
|
+
- `serializeOrder(order)`
|
|
290
|
+
- `hashOrder(order)`
|
|
291
|
+
- `getTypedData(order)`
|
|
292
|
+
- `signEip712Order(order, walletClient)`
|
|
293
|
+
- `signSimpleAccountOrder(order, ownerWalletClient)`
|
|
294
|
+
- `signOrder(order, walletClient)`
|
|
295
|
+
- `recoverOrderSigner(order, signature)`
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
const signature = await helper.signEip712Order(order, walletClient);
|
|
299
|
+
const payloadOrder = helper.serializeOrder(order);
|
|
300
|
+
const signer = await helper.recoverOrderSigner(order, signature);
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### OrderbookApi
|
|
304
|
+
|
|
305
|
+
`OrderbookApi` is a fetch-based client that normalizes URLs, handles the
|
|
306
|
+
backend envelope format, exposes typed return values, and produces clearer
|
|
307
|
+
integration errors.
|
|
308
|
+
|
|
309
|
+
Constructor config:
|
|
310
|
+
|
|
311
|
+
- `baseUrl`
|
|
312
|
+
- `fetchFn?`
|
|
313
|
+
|
|
314
|
+
Public order methods:
|
|
315
|
+
|
|
316
|
+
- `createOrder(params, bearerToken)`
|
|
317
|
+
- `getOrder(orderHash)`
|
|
318
|
+
- `getOrders(marketId, maker?)` — active orders for a market, optionally scoped to a maker
|
|
319
|
+
- `getUserOrders(maker, marketId)` — convenience wrapper around `getOrders`
|
|
320
|
+
|
|
321
|
+
Public market methods:
|
|
322
|
+
|
|
323
|
+
- `getMarkets()`
|
|
324
|
+
- `getMarketRecentTrades(marketId, limit?)`
|
|
325
|
+
- `getMarket(marketId)`
|
|
326
|
+
|
|
327
|
+
Public user and analytics methods:
|
|
328
|
+
|
|
329
|
+
- `getUserPositions(userAddress)`
|
|
330
|
+
- `getUserTradingPnL(userAddress)`
|
|
331
|
+
- `getUserPnL(userAddress)`
|
|
332
|
+
- `getTokenPnL(userAddress, tokenId)`
|
|
333
|
+
- `getErc20PnL(userAddress, tokenAddress)`
|
|
334
|
+
|
|
335
|
+
Public history methods:
|
|
336
|
+
|
|
337
|
+
- `getUserHistories(userAddress, limit?)`
|
|
338
|
+
- `getMintHistory(userAddress, limit?)`
|
|
339
|
+
- `getRedeemHistory(userAddress, limit?)`
|
|
340
|
+
- `getUnwindHistory(userAddress, limit?)`
|
|
341
|
+
- `getTransferHistory(userAddress, limit?)`
|
|
342
|
+
- `getFillHistory(userAddress, limit?)`
|
|
343
|
+
|
|
344
|
+
Auth-related methods also exposed by the SDK:
|
|
345
|
+
|
|
346
|
+
- `getChallenge({ address, chainId })`
|
|
347
|
+
- `verifyAuth({ account, nonce, signature, chainId, expiresAt })`
|
|
348
|
+
|
|
349
|
+
Integration note:
|
|
350
|
+
|
|
351
|
+
- `getOrders` and `getUserOrders` both require a `marketId`. Returned orders
|
|
352
|
+
are restricted to active and partially-filled (cancelled / fully-filled
|
|
353
|
+
/ expired are filtered server-side).
|
|
354
|
+
|
|
355
|
+
### Deserializers
|
|
356
|
+
|
|
357
|
+
The API returns string-heavy DTOs because JSON cannot safely transport
|
|
358
|
+
`bigint`. Public helpers convert those payloads into bigint-friendly objects:
|
|
359
|
+
|
|
360
|
+
- `orderToBigInt`
|
|
361
|
+
- `storedOrderToBigInt`
|
|
362
|
+
- `ordersSnapshotToBigInt`
|
|
363
|
+
- `marketInstrumentToBigInt`
|
|
364
|
+
- `marketToBigInt`
|
|
365
|
+
- `marketsToBigInt`
|
|
366
|
+
- `positionToBigInt`
|
|
367
|
+
- `tradingPnLToBigInt`
|
|
368
|
+
- `mintHistoryToBigInt`
|
|
369
|
+
- `redeemHistoryToBigInt`
|
|
370
|
+
- `unwindHistoryToBigInt`
|
|
371
|
+
- `transferHistoryToBigInt`
|
|
372
|
+
- `fillHistoryToBigInt`
|
|
373
|
+
|
|
374
|
+
## Vault Module
|
|
375
|
+
|
|
376
|
+
Source files:
|
|
377
|
+
|
|
378
|
+
- `src/vault/index.ts`
|
|
379
|
+
- `src/vault/types.ts`
|
|
380
|
+
- `src/vault/token-ids.ts`
|
|
381
|
+
- `src/vault/collateral.ts`
|
|
382
|
+
- `src/vault/transactions.ts`
|
|
383
|
+
- `src/vault/constants.ts`
|
|
384
|
+
|
|
385
|
+
This module is built around `OptionMarketVault`. It documents position token
|
|
386
|
+
derivation, collateral and settlement math, precision constants, roles, and
|
|
387
|
+
transaction builders.
|
|
388
|
+
|
|
389
|
+
### Vault concepts
|
|
390
|
+
|
|
391
|
+
The vault mints paired ERC-6909 position ids:
|
|
392
|
+
|
|
393
|
+
- `PRM`: collateral-side position token, always even
|
|
394
|
+
- `oPRM`: option claim token, always odd
|
|
395
|
+
|
|
396
|
+
Pairing rules:
|
|
397
|
+
|
|
398
|
+
- `oPrmTokenId = prmTokenId | 1`
|
|
399
|
+
- `optionPrmToPrm(tokenId)` clears the low bit and returns the canonical `PRM`
|
|
400
|
+
id
|
|
401
|
+
|
|
402
|
+
### Public types
|
|
403
|
+
|
|
404
|
+
Main exports:
|
|
405
|
+
|
|
406
|
+
- `VaultInstrument`
|
|
407
|
+
- `VaultMarket`
|
|
408
|
+
- `PrmInfo`
|
|
409
|
+
- `TokenIdParams`
|
|
410
|
+
- `MarketParams`
|
|
411
|
+
- `InstrumentParams`
|
|
412
|
+
- `SpreadBounds`
|
|
413
|
+
|
|
414
|
+
### Precision constants and roles
|
|
415
|
+
|
|
416
|
+
Public constants:
|
|
417
|
+
|
|
418
|
+
- `VAULT_TOKEN_PRECISION = 1e18`
|
|
419
|
+
- `FEE_BPS_PRECISION = 1e6`
|
|
420
|
+
- `PNL_PRECISION = 1e18`
|
|
421
|
+
- `Role`
|
|
422
|
+
- `ROLE_NAMES`
|
|
423
|
+
|
|
424
|
+
### Token-id helpers
|
|
425
|
+
|
|
426
|
+
Public helpers:
|
|
427
|
+
|
|
428
|
+
- `getPrmTokenId(params)`
|
|
429
|
+
- `getOptionPrmTokenId(params)`
|
|
430
|
+
- `prmToOptionTokenId(prmTokenId)`
|
|
431
|
+
- `optionPrmToPrm(oPrmTokenId)`
|
|
432
|
+
- `isPrmToken(tokenId)`
|
|
433
|
+
- `isOptionPrmToken(tokenId)`
|
|
434
|
+
- `getPositionId(tokenId, userAddress)`
|
|
435
|
+
|
|
436
|
+
Implementation detail:
|
|
437
|
+
|
|
438
|
+
- `getPrmTokenId` hashes vault address, instrument fields, expiry, and
|
|
439
|
+
`chainId`, then left-shifts once to force even parity
|
|
440
|
+
|
|
441
|
+
### Collateral and settlement math
|
|
442
|
+
|
|
443
|
+
Public helpers:
|
|
444
|
+
|
|
445
|
+
- `getSpreadWidth(market)`
|
|
446
|
+
- `getSpreadBounds(instrument, market)`
|
|
447
|
+
- `calculateCollateralAmount(prmAmount, instrument, market)`
|
|
448
|
+
- `calculatePrmAmount(collateralAmount, instrument, market)`
|
|
449
|
+
- `calculateSpreadProfit(instrument, market, finalTick, positionSize)`
|
|
450
|
+
- `calculateSpreadLoss(instrument, market, finalTick, positionSize)`
|
|
451
|
+
- `calculateWithdrawableCollateral(instrument, market, finalTick, positionSize)`
|
|
452
|
+
- `getCollateralPerPosition(instrument, market)`
|
|
453
|
+
- `calculateDepositFees(collateralAmount, depositFeeBps, feeBpsPrecision?)`
|
|
454
|
+
- `calculateRedeemFees(profitAmount, redeemFeeBps, feeBpsPrecision?)`
|
|
455
|
+
- `isInTheMoney(instrument, market, finalTick)`
|
|
456
|
+
- `calculateMoneyness(instrument, market, finalTick)`
|
|
457
|
+
|
|
458
|
+
Important behavior:
|
|
459
|
+
|
|
460
|
+
- spread width falls back to `1` when `tickSpacing <= tickSize`
|
|
461
|
+
- strike-scaled collateral uses `instrument.tick`
|
|
462
|
+
- collateral calculation rounds up when the final division is not exact
|
|
463
|
+
- inverse `PRM` previews use floor division
|
|
464
|
+
- payoff and withdraw math use deterministic `bigint` arithmetic throughout
|
|
465
|
+
|
|
466
|
+
### Transaction builders
|
|
467
|
+
|
|
468
|
+
These helpers return:
|
|
469
|
+
|
|
470
|
+
```ts
|
|
471
|
+
export interface TransactionCall {
|
|
472
|
+
to: `0x${string}`;
|
|
473
|
+
value?: bigint;
|
|
474
|
+
data: Hex;
|
|
475
|
+
}
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
User-facing lifecycle builders:
|
|
479
|
+
|
|
480
|
+
- `buildMintTransaction(vaultAddress, instrument, amount)`
|
|
481
|
+
- `buildWithdrawTransaction(vaultAddress, prmTokenId, amount, receiver)`
|
|
482
|
+
- `buildRedeemTransaction(vaultAddress, oPrmTokenId, receiver)`
|
|
483
|
+
- `buildUnwindTransaction(vaultAddress, prmTokenId, amount, receiver)`
|
|
484
|
+
- `buildRolloverTransaction(vaultAddress, oldPrmTokenId)`
|
|
485
|
+
- `buildApproveTransaction(tokenAddress, spender, amount?)`
|
|
486
|
+
- `buildBatchedMintTransactions(collateralTokenAddress, vaultAddress, instrument, collateralAmount, prmAmount)`
|
|
487
|
+
- `buildSetOperatorTransaction(vaultAddress, operator, approved)`
|
|
488
|
+
|
|
489
|
+
Restricted or role-gated builders:
|
|
490
|
+
|
|
491
|
+
- `buildDelegateRedeemTransaction`
|
|
492
|
+
- `buildDelegateRolloverTransaction`
|
|
493
|
+
- `buildDelegateWithdrawTransaction`
|
|
494
|
+
- `buildFillMarketDeliveryTransaction`
|
|
495
|
+
- `buildSetRolloverEnabledTransaction`
|
|
496
|
+
- `buildSetRoleTransaction`
|
|
497
|
+
- `buildUpdateFinalTickTransaction`
|
|
498
|
+
- `buildUpdateMarketExpiryTransaction`
|
|
499
|
+
- `buildUpdateMarketExpiryFromMarketTransaction`
|
|
500
|
+
|
|
501
|
+
## Registry Module
|
|
502
|
+
|
|
503
|
+
Source files:
|
|
504
|
+
|
|
505
|
+
- `src/registry/index.ts`
|
|
506
|
+
- `src/registry/types.ts`
|
|
507
|
+
- `src/registry/markets-registry-contract.ts`
|
|
508
|
+
|
|
509
|
+
This module wraps the `MarketsRegistry` contract surface used for market
|
|
510
|
+
configuration and serialization.
|
|
511
|
+
|
|
512
|
+
### Public types
|
|
513
|
+
|
|
514
|
+
Main exports:
|
|
515
|
+
|
|
516
|
+
- `MarketType`
|
|
517
|
+
- `ERC20xERC20`
|
|
518
|
+
- `ERC20xERC6909`
|
|
519
|
+
- `RegistryMarket`
|
|
520
|
+
- `SerializedRegistryMarket`
|
|
521
|
+
|
|
522
|
+
Core fields include token addresses, sizing parameters, expiry, fee fields, and
|
|
523
|
+
runtime flags such as `marketType`, `isCollateralScaled`, and `nonRollable`.
|
|
524
|
+
|
|
525
|
+
Serialization helpers:
|
|
526
|
+
|
|
527
|
+
- `serializeRegistryMarket(market)`
|
|
528
|
+
- `deserializeRegistryMarket(market)`
|
|
529
|
+
|
|
530
|
+
### Contract wrapper
|
|
531
|
+
|
|
532
|
+
`MarketsRegistryContract` wraps the shipped ABI and returns calldata or a tx
|
|
533
|
+
envelope.
|
|
534
|
+
|
|
535
|
+
Public surfaces:
|
|
536
|
+
|
|
537
|
+
- `RegistryTransactionCall`
|
|
538
|
+
- `MarketsRegistryContract`
|
|
539
|
+
- `getAddMarketCalldata(market)`
|
|
540
|
+
- `buildAddMarketTx(market)`
|
|
541
|
+
- `getUpdateTokenCalldata(token, isStable, isDelete)`
|
|
542
|
+
- `getSetWhitelistedCalldata(account, allowed)`
|
|
543
|
+
- `getUpdateMarketExpiryCalldata(marketId, expiry)`
|
|
544
|
+
- `getMulticallCalldata(data)`
|
|
545
|
+
|
|
546
|
+
Important nuance:
|
|
547
|
+
|
|
548
|
+
- `buildAddMarketTx` returns a full tx object
|
|
549
|
+
- the remaining helpers return raw calldata only
|
|
550
|
+
|
|
551
|
+
Most registry writes are administrative and should not be treated as normal
|
|
552
|
+
end-user flows.
|
|
553
|
+
|
|
554
|
+
## Sync Module
|
|
555
|
+
|
|
556
|
+
Source files:
|
|
557
|
+
|
|
558
|
+
- `src/sync/index.ts`
|
|
559
|
+
- `src/sync/types.ts`
|
|
560
|
+
- `src/sync/clients/base-client.ts`
|
|
561
|
+
- `src/sync/clients/order-client.ts`
|
|
562
|
+
- `src/sync/clients/activity-client.ts`
|
|
563
|
+
|
|
564
|
+
This module contains the realtime clients used to keep frontends and services
|
|
565
|
+
in sync with depth and activity streams.
|
|
566
|
+
|
|
567
|
+
### Shared sync types
|
|
568
|
+
|
|
569
|
+
Public exports:
|
|
570
|
+
|
|
571
|
+
- `SyncStatus`
|
|
572
|
+
- `"connecting" | "syncing" | "synced" | "recovering" | "disconnected" | "error"`
|
|
573
|
+
|
|
574
|
+
### MarketDepthSyncClient
|
|
575
|
+
|
|
576
|
+
Main config:
|
|
577
|
+
|
|
578
|
+
- `wsUrl`
|
|
579
|
+
- `marketId`
|
|
580
|
+
- `tokenIds`
|
|
581
|
+
- `heartbeatIntervalMs?`
|
|
582
|
+
- `heartbeatTimeoutMs?`
|
|
583
|
+
- `maxReconnectAttempts?`
|
|
584
|
+
- `initialReconnectDelayMs?`
|
|
585
|
+
- `maxReconnectDelayMs?`
|
|
586
|
+
|
|
587
|
+
Connection methods:
|
|
588
|
+
|
|
589
|
+
- `connect()`
|
|
590
|
+
- `disconnect()`
|
|
591
|
+
- `getStatus()`
|
|
592
|
+
|
|
593
|
+
Read methods:
|
|
594
|
+
|
|
595
|
+
- `getTokenIds()`
|
|
596
|
+
- `getTokenState(tokenId)`
|
|
597
|
+
- `getBids(tokenId)`
|
|
598
|
+
- `getAsks(tokenId)`
|
|
599
|
+
- `getBestBid(tokenId)`
|
|
600
|
+
- `getBestAsk(tokenId)`
|
|
601
|
+
- `getLastPrice(tokenId)`
|
|
602
|
+
- `getSeq(tokenId)`
|
|
603
|
+
- `getSpread(tokenId)`
|
|
604
|
+
- `getDepthAtPrice(tokenId, side, price)`
|
|
605
|
+
|
|
606
|
+
Listener hooks:
|
|
607
|
+
|
|
608
|
+
- `onStatus(callback)`
|
|
609
|
+
- `onSnapshot(callback)`
|
|
610
|
+
- `onDelta(callback)`
|
|
611
|
+
|
|
612
|
+
Public event types:
|
|
613
|
+
|
|
614
|
+
- `DepthLevel`
|
|
615
|
+
- `TokenDepthSnapshot`
|
|
616
|
+
- `DepthLevelUpdate`
|
|
617
|
+
- `DepthUpdate`
|
|
618
|
+
|
|
619
|
+
Implementation details captured by the client:
|
|
620
|
+
|
|
621
|
+
- invalid non-websocket URLs are rejected
|
|
622
|
+
- `connect()` waits for initial snapshots
|
|
623
|
+
- sequence ids are deduplicated and gaps trigger recovery
|
|
624
|
+
- equivalent price strings such as `"1"` and `"1.000000"` are normalized
|
|
625
|
+
|
|
626
|
+
### ActivitySyncClient
|
|
627
|
+
|
|
628
|
+
Config:
|
|
629
|
+
|
|
630
|
+
- `wsUrl`
|
|
631
|
+
- `marketId?`
|
|
632
|
+
- `userAddress?`
|
|
633
|
+
- `heartbeatIntervalMs?`
|
|
634
|
+
- `heartbeatTimeoutMs?`
|
|
635
|
+
- `maxReconnectAttempts?`
|
|
636
|
+
- `initialReconnectDelayMs?`
|
|
637
|
+
- `maxReconnectDelayMs?`
|
|
638
|
+
|
|
639
|
+
At least one of `marketId` or `userAddress` is required.
|
|
640
|
+
|
|
641
|
+
Connection methods:
|
|
642
|
+
|
|
643
|
+
- `connect()`
|
|
644
|
+
- `disconnect()`
|
|
645
|
+
- `getStatus()`
|
|
646
|
+
|
|
647
|
+
Listener hooks:
|
|
648
|
+
|
|
649
|
+
- `onStatus(callback)`
|
|
650
|
+
- `onOrderFill(callback)`
|
|
651
|
+
- `onUserFill(callback)`
|
|
652
|
+
- `onMarketFill(callback)`
|
|
653
|
+
|
|
654
|
+
Public event type:
|
|
655
|
+
|
|
656
|
+
- `OrderFillEvent`
|
|
657
|
+
|
|
658
|
+
## Config Module
|
|
659
|
+
|
|
660
|
+
Source files:
|
|
661
|
+
|
|
662
|
+
- `src/config/index.ts`
|
|
663
|
+
- `src/config/chains.ts`
|
|
664
|
+
|
|
665
|
+
This module is the SDK's deployment and chain registry. It centralizes
|
|
666
|
+
supported chain definitions, token metadata, and deployed contract addresses so
|
|
667
|
+
applications do not hardcode environment-specific values.
|
|
668
|
+
|
|
669
|
+
### Chains
|
|
670
|
+
|
|
671
|
+
Exports from `src/config/chains.ts`:
|
|
672
|
+
|
|
673
|
+
- `megaETH`
|
|
674
|
+
- `SUPPORTED_CHAINS`
|
|
675
|
+
|
|
676
|
+
Runtime lookup from `src/config/index.ts`:
|
|
677
|
+
|
|
678
|
+
- `CHAIN_ID_TO_CHAIN`
|
|
679
|
+
|
|
680
|
+
### Token metadata
|
|
681
|
+
|
|
682
|
+
Shared shape:
|
|
683
|
+
|
|
684
|
+
```ts
|
|
685
|
+
export interface Token {
|
|
686
|
+
name: string;
|
|
687
|
+
symbol: string;
|
|
688
|
+
address: `0x${string}`;
|
|
689
|
+
decimals: number;
|
|
690
|
+
logoURI?: string;
|
|
691
|
+
}
|
|
113
692
|
```
|
|
114
693
|
|
|
115
|
-
|
|
116
|
-
the [Exchange guide](./src/exchange/README.md). For API payloads and response
|
|
117
|
-
DTOs, use the [API guide](./src/api/README.md) and
|
|
118
|
-
[Shared types guide](./src/shared/README.md).
|
|
694
|
+
Public token maps:
|
|
119
695
|
|
|
120
|
-
|
|
696
|
+
- `WETH`
|
|
697
|
+
- `USDC`
|
|
698
|
+
- `USDM`
|
|
699
|
+
- `USDT0`
|
|
121
700
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
`
|
|
701
|
+
Important nuance:
|
|
702
|
+
|
|
703
|
+
- `USDM`, `USDT0`, `MARKETS_REGISTRY`, `FEE_REGISTRY`, and
|
|
704
|
+
`ERC_TOKENS_RESTRICTION_MODULE` are partial maps because those deployments do
|
|
705
|
+
not exist on every supported chain
|
|
706
|
+
|
|
707
|
+
### Contract address maps
|
|
708
|
+
|
|
709
|
+
Public address maps:
|
|
710
|
+
|
|
711
|
+
- `PERMIT2_ADDRESS`
|
|
712
|
+
- `OPTION_MARKET_VAULT`
|
|
713
|
+
- `EXCHANGE`
|
|
714
|
+
- `MARKETS_REGISTRY`
|
|
715
|
+
- `ENTRY_POINT`
|
|
716
|
+
- `SIMPLE_ACCOUNT_FACTORY`
|
|
717
|
+
- `FEE_REGISTRY`
|
|
718
|
+
- `ERC_TOKENS_RESTRICTION_MODULE`
|
|
719
|
+
|
|
720
|
+
## Shared DTOs
|
|
721
|
+
|
|
722
|
+
Source files:
|
|
723
|
+
|
|
724
|
+
- `src/shared/index.ts`
|
|
725
|
+
- `src/shared/types.ts`
|
|
726
|
+
|
|
727
|
+
These types are the transport layer between the SDK, the HTTP API, and
|
|
728
|
+
frontend consumers. Numeric fields are usually strings so they can be moved
|
|
729
|
+
safely over JSON.
|
|
730
|
+
|
|
731
|
+
### Order transport types
|
|
732
|
+
|
|
733
|
+
Main exports:
|
|
734
|
+
|
|
735
|
+
- `Order`
|
|
736
|
+
- `OrderSignature`
|
|
737
|
+
- `OrderStatus`
|
|
738
|
+
- `TimeInForce`
|
|
739
|
+
- `CreateOrderParams`
|
|
740
|
+
- `CreateOrderRequest`
|
|
741
|
+
- `StoredOrder`
|
|
742
|
+
- `MatchableOrder`
|
|
743
|
+
- `MatchRequest`
|
|
744
|
+
- `MatchedOrder`
|
|
745
|
+
- `MatchResult`
|
|
746
|
+
- `CreateOrderResult`
|
|
747
|
+
- `OrderResponse`
|
|
748
|
+
- `OrdersSnapshot`
|
|
749
|
+
|
|
750
|
+
Main order write shape:
|
|
751
|
+
|
|
752
|
+
```ts
|
|
753
|
+
export interface CreateOrderParams {
|
|
754
|
+
marketId: string;
|
|
755
|
+
order: Order;
|
|
756
|
+
signature: OrderSignature;
|
|
757
|
+
operator?: string;
|
|
758
|
+
timeInForce?: TimeInForce;
|
|
759
|
+
postOnly?: boolean;
|
|
760
|
+
}
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
Main order read shape:
|
|
764
|
+
|
|
765
|
+
```ts
|
|
766
|
+
export interface StoredOrder {
|
|
767
|
+
orderHash: string;
|
|
768
|
+
signature: OrderSignature;
|
|
769
|
+
marketId: string;
|
|
770
|
+
tokenId: string;
|
|
771
|
+
remainingMakerAmount: string;
|
|
772
|
+
order: Order;
|
|
773
|
+
operator?: string;
|
|
774
|
+
createdAt: number;
|
|
775
|
+
status: OrderStatus;
|
|
776
|
+
side: "bid" | "ask";
|
|
777
|
+
price: number;
|
|
778
|
+
}
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
### Market DTOs
|
|
782
|
+
|
|
783
|
+
Public exports:
|
|
784
|
+
|
|
785
|
+
- `MarketInstrument`
|
|
786
|
+
- `Market`
|
|
787
|
+
- `MarketResponse`
|
|
788
|
+
- `MarketsResponse`
|
|
789
|
+
|
|
790
|
+
`MarketInstrument` carries strike-level data such as paired token ids,
|
|
791
|
+
top-of-book values, recent prices, collateral totals, and supply.
|
|
792
|
+
|
|
793
|
+
`Market` wraps market-level metadata such as pricing increments, token
|
|
794
|
+
addresses, fee fields, expiry, and nested `instruments`.
|
|
795
|
+
|
|
796
|
+
### Position and PnL DTOs
|
|
797
|
+
|
|
798
|
+
Public exports:
|
|
799
|
+
|
|
800
|
+
- `UserPosition`
|
|
801
|
+
- `TradingPnL`
|
|
802
|
+
- `UserPnL`
|
|
803
|
+
- `TokenPnL`
|
|
804
|
+
- `Erc20PnL`
|
|
805
|
+
|
|
806
|
+
### History DTOs
|
|
807
|
+
|
|
808
|
+
Public exports:
|
|
809
|
+
|
|
810
|
+
- `MintHistoryItem`
|
|
811
|
+
- `RedeemHistoryItem`
|
|
812
|
+
- `UnwindHistoryItem`
|
|
813
|
+
- `TransferHistoryItem`
|
|
814
|
+
- `OrderFillHistoryItem`
|
|
815
|
+
- `MarketTradeItem`
|
|
816
|
+
- `UserHistories`
|
|
817
|
+
|
|
818
|
+
`UserHistories` groups `mints`, `redeems`, `unwinds`, `transfers`, and
|
|
819
|
+
`fills`.
|
|
820
|
+
|
|
821
|
+
## Root-Level Helpers
|
|
822
|
+
|
|
823
|
+
### Smart-account helpers
|
|
824
|
+
|
|
825
|
+
Source file:
|
|
826
|
+
|
|
827
|
+
- `src/smart-account.ts`
|
|
828
|
+
|
|
829
|
+
These helpers are for deterministic account derivation and deployment checks
|
|
830
|
+
aligned with the `SimpleAccountFactory`-style surface used elsewhere in the
|
|
831
|
+
Stryke stack.
|
|
126
832
|
|
|
127
833
|
Public types:
|
|
128
834
|
|
|
@@ -146,33 +852,15 @@ Public class:
|
|
|
146
852
|
- `getCurrent(client, owner, depositor)`
|
|
147
853
|
- `isDeployed(client, address)`
|
|
148
854
|
|
|
149
|
-
|
|
150
|
-
import {
|
|
151
|
-
SIMPLE_ACCOUNT_FACTORY,
|
|
152
|
-
SmartAccountHelper,
|
|
153
|
-
} from "@stryke-xyz/premarket-sdk";
|
|
154
|
-
|
|
155
|
-
const helper = new SmartAccountHelper({
|
|
156
|
-
factoryAddress: SIMPLE_ACCOUNT_FACTORY[4326],
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
const account = await helper.getCurrent(client, owner, depositor);
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
These helpers are intentionally small. They do not execute user operations or
|
|
163
|
-
act as a full account-abstraction SDK. Their job is to keep address derivation
|
|
164
|
-
and deployment checks aligned with the factory contract.
|
|
855
|
+
These helpers do not execute user operations and are intentionally small.
|
|
165
856
|
|
|
166
|
-
|
|
857
|
+
### Address
|
|
167
858
|
|
|
168
|
-
|
|
169
|
-
operations.
|
|
859
|
+
Source file:
|
|
170
860
|
|
|
171
|
-
|
|
861
|
+
- `src/address.ts`
|
|
172
862
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
Public surfaces:
|
|
863
|
+
Public surface:
|
|
176
864
|
|
|
177
865
|
- `Address.NATIVE_CURRENCY`
|
|
178
866
|
- `Address.zeroAddress`
|
|
@@ -184,14 +872,13 @@ Public surfaces:
|
|
|
184
872
|
- `isZero()`
|
|
185
873
|
- `lastHalf()`
|
|
186
874
|
|
|
187
|
-
|
|
188
|
-
useful in UI and backend code.
|
|
875
|
+
### Bps
|
|
189
876
|
|
|
190
|
-
|
|
877
|
+
Source file:
|
|
191
878
|
|
|
192
|
-
|
|
879
|
+
- `src/bps.ts`
|
|
193
880
|
|
|
194
|
-
Public
|
|
881
|
+
Public surface:
|
|
195
882
|
|
|
196
883
|
- `Bps.ZERO`
|
|
197
884
|
- `Bps.fromPercent(val, base?)`
|
|
@@ -202,16 +889,15 @@ Public surfaces:
|
|
|
202
889
|
- `toFraction(base?)`
|
|
203
890
|
- `toString()`
|
|
204
891
|
|
|
205
|
-
`Bps`
|
|
206
|
-
`[0, 10000]`.
|
|
892
|
+
`Bps` constrains values to the inclusive range `[0, 10000]`.
|
|
207
893
|
|
|
208
|
-
|
|
894
|
+
### Compatibility constants
|
|
209
895
|
|
|
210
|
-
|
|
896
|
+
Source file:
|
|
211
897
|
|
|
212
|
-
|
|
898
|
+
- `src/constants.ts`
|
|
213
899
|
|
|
214
|
-
Public
|
|
900
|
+
Public surface:
|
|
215
901
|
|
|
216
902
|
- `ZX`
|
|
217
903
|
- `getExchangeContract(chainId)`
|
|
@@ -220,40 +906,55 @@ Public surfaces:
|
|
|
220
906
|
- `getNativeOrderFactoryContract(chainId)`
|
|
221
907
|
- `getNativeOrderImplContract(chainId)`
|
|
222
908
|
|
|
223
|
-
The exchange and registry accessors
|
|
224
|
-
|
|
225
|
-
bridge helpers rather than the center of new integrations.
|
|
909
|
+
The exchange and registry accessors remain useful. The native order factory and
|
|
910
|
+
impl helpers are mostly compatibility-oriented bridge helpers.
|
|
226
911
|
|
|
227
|
-
|
|
912
|
+
## Utilities
|
|
228
913
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
914
|
+
Source files:
|
|
915
|
+
|
|
916
|
+
- `src/utils/mul-div.ts`
|
|
917
|
+
- `src/utils/rand-bigint.ts`
|
|
918
|
+
- `src/utils/orderUtils.ts`
|
|
919
|
+
|
|
920
|
+
This folder contains small reusable helpers that do not belong to a single
|
|
921
|
+
domain module but are still part of the public SDK surface.
|
|
922
|
+
|
|
923
|
+
### `mulDiv` and `Rounding`
|
|
924
|
+
|
|
925
|
+
Public exports:
|
|
232
926
|
|
|
233
|
-
- `mulDiv`
|
|
234
927
|
- `Rounding`
|
|
235
|
-
- `
|
|
236
|
-
- `
|
|
237
|
-
- `
|
|
238
|
-
- `isComplementaryOptionTokenPair`
|
|
239
|
-
- `verifyOrderSignature`
|
|
928
|
+
- `Ceil`
|
|
929
|
+
- `Floor`
|
|
930
|
+
- `mulDiv(a, b, x, rounding?)`
|
|
240
931
|
|
|
241
|
-
|
|
932
|
+
`mulDiv` performs integer multiplication and division in one step using
|
|
933
|
+
`bigint` arithmetic.
|
|
242
934
|
|
|
243
|
-
|
|
935
|
+
### `randBigInt`
|
|
244
936
|
|
|
245
|
-
|
|
246
|
-
- every guide links directly to source files that implement the behavior
|
|
247
|
-
- public exports are documented in terms of both intent and exact runtime shape
|
|
248
|
-
- examples stay realistic and contract-aligned
|
|
249
|
-
- restricted or sensitive surfaces are acknowledged, but the docs avoid becoming
|
|
250
|
-
an admin or auth operations manual
|
|
937
|
+
Public export:
|
|
251
938
|
|
|
252
|
-
|
|
939
|
+
- `randBigInt(max)`
|
|
253
940
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
941
|
+
Behavior:
|
|
942
|
+
|
|
943
|
+
- returns a cryptographically secure random bigint in `[0, max]`
|
|
944
|
+
- requires `globalThis.crypto.getRandomValues`
|
|
945
|
+
- throws if no secure random source is available
|
|
946
|
+
|
|
947
|
+
### Order utility helpers
|
|
948
|
+
|
|
949
|
+
Public exports:
|
|
950
|
+
|
|
951
|
+
- `optionPrmToPrmTokenId(tokenId)`
|
|
952
|
+
- `prmToOptionPrmTokenId(prmTokenId)`
|
|
953
|
+
- `isComplementaryOptionTokenPair(tokenIdA, tokenIdB)`
|
|
954
|
+
- `verifyOrderSignature(order, signature, chainId, exchangeAddress)`
|
|
955
|
+
|
|
956
|
+
These overlap conceptually with the exchange and vault modules, but they are
|
|
957
|
+
useful when a caller wants the smallest possible helper surface.
|
|
257
958
|
|
|
258
959
|
## Development
|
|
259
960
|
|
|
@@ -263,27 +964,28 @@ bun run build
|
|
|
263
964
|
bun test src
|
|
264
965
|
```
|
|
265
966
|
|
|
266
|
-
|
|
967
|
+
Available scripts from `package.json`:
|
|
267
968
|
|
|
268
|
-
-
|
|
269
|
-
|
|
270
|
-
-
|
|
271
|
-
|
|
272
|
-
-
|
|
273
|
-
builders
|
|
274
|
-
- [`src/api`](./src/api): `OrderHelper`, `OrderbookApi`, and deserializers
|
|
275
|
-
- [`src/sync`](./src/sync): realtime market depth and activity clients
|
|
276
|
-
- [`src/config`](./src/config): chains, addresses, and token constants
|
|
277
|
-
- [`src/shared`](./src/shared): transport DTOs used across SDK, API, and UI
|
|
969
|
+
- `bun run build`
|
|
970
|
+
- `bun run test`
|
|
971
|
+
- `bun run typecheck`
|
|
972
|
+
- `bun run test:e2e`
|
|
973
|
+
- `bun run fill-orderbook`
|
|
278
974
|
|
|
279
975
|
## Legacy Docs
|
|
280
976
|
|
|
281
|
-
The
|
|
282
|
-
|
|
283
|
-
-
|
|
284
|
-
-
|
|
285
|
-
-
|
|
286
|
-
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
977
|
+
The repository still contains older reference material under `docs/`:
|
|
978
|
+
|
|
979
|
+
- `docs/CROSS_REPO_INTEGRATION.md`
|
|
980
|
+
- `docs/orderbook-integration.md`
|
|
981
|
+
- `docs/API_REFERENCE.md`
|
|
982
|
+
- `docs/refactor-docs/LimitOrderProtocol_FEE_HOWTO.md`
|
|
983
|
+
- `docs/refactor-docs/OptionMarketVault_AUDITOR_SPEC.md`
|
|
984
|
+
- `docs/refactor-docs/OptionMarketVault_CEO_SUMMARY.md`
|
|
985
|
+
- `docs/refactor-docs/OptionMarketVault_DEV_SPEC.md`
|
|
986
|
+
- `docs/refactor-docs/OptionMarketVault_PUBLIC.md`
|
|
987
|
+
- `docs/refactor-docs/SDK_TECHNICAL_SPEC.md`
|
|
988
|
+
|
|
989
|
+
This root README is now the single repository-level README entry point, while
|
|
990
|
+
the `docs/` directory remains available for deeper historical or protocol
|
|
991
|
+
context.
|