@stryke-xyz/premarket-sdk 1.0.5 → 1.0.7
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 +260 -16
- package/dist/cjs/abi/Exchange.abi.json +1384 -1384
- package/dist/cjs/abi/MarketsRegistry.abi.json +1055 -991
- package/dist/cjs/abi/OptionMarketVault.abi.json +1948 -1932
- package/dist/cjs/api/README.md +296 -0
- package/dist/cjs/config/README.md +112 -0
- package/dist/cjs/config/index.js +3 -3
- package/dist/cjs/exchange/README.md +280 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/registry/README.md +150 -0
- package/dist/cjs/shared/README.md +235 -0
- package/dist/cjs/sync/README.md +215 -0
- package/dist/cjs/utils/README.md +89 -0
- package/dist/cjs/vault/README.md +268 -0
- package/dist/esm/abi/Exchange.abi.json +1384 -1384
- package/dist/esm/abi/MarketsRegistry.abi.json +1055 -991
- package/dist/esm/abi/OptionMarketVault.abi.json +1948 -1932
- package/dist/esm/api/README.md +296 -0
- package/dist/esm/config/README.md +112 -0
- package/dist/esm/config/index.js +3 -3
- package/dist/esm/exchange/README.md +280 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/registry/README.md +150 -0
- package/dist/esm/shared/README.md +235 -0
- package/dist/esm/sync/README.md +215 -0
- package/dist/esm/utils/README.md +89 -0
- package/dist/esm/vault/README.md +268 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,22 +4,250 @@ TypeScript SDK for Stryke premarket integrations across:
|
|
|
4
4
|
|
|
5
5
|
- `option-markets` contracts (`Exchange`, `MarketsRegistry`, `OptionMarketVault`)
|
|
6
6
|
- `smart-account` contracts (`SimpleAccountFactory`, `EntryPoint`)
|
|
7
|
-
- `premarkets-api` HTTP
|
|
7
|
+
- `premarkets-api` HTTP and WebSocket services
|
|
8
8
|
- `premarkets-interface` frontend runtime
|
|
9
9
|
|
|
10
|
+
This package is the shared integration layer between onchain contracts and the
|
|
11
|
+
application stack. It gives product teams one place to build orders, hash and
|
|
12
|
+
sign typed data, encode contract calls, read market and user data, subscribe to
|
|
13
|
+
live updates, and consume deployment constants.
|
|
14
|
+
|
|
10
15
|
## What This Package Provides
|
|
11
16
|
|
|
12
|
-
- native `Exchange` order builders, hashing, typed-data signing helpers
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
+
- native `Exchange` order builders, hashing, typed-data signing helpers, and
|
|
18
|
+
calldata builders
|
|
19
|
+
- `OptionMarketVault` token-id helpers, collateral math, and transaction
|
|
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`
|
|
74
|
+
|
|
75
|
+
## Quick Start
|
|
76
|
+
|
|
77
|
+
The SDK is designed so an integrator can stay inside the package root for most
|
|
78
|
+
common workflows.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import {
|
|
82
|
+
EXCHANGE,
|
|
83
|
+
OrderHelper,
|
|
84
|
+
OrderbookApi,
|
|
85
|
+
SignatureType,
|
|
86
|
+
TradeType,
|
|
87
|
+
} from "@stryke-xyz/premarket-sdk";
|
|
88
|
+
|
|
89
|
+
const chainId = 4326;
|
|
90
|
+
|
|
91
|
+
const helper = new OrderHelper({
|
|
92
|
+
chainId,
|
|
93
|
+
exchangeAddress: EXCHANGE[chainId],
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const order = helper.buildOrder({
|
|
97
|
+
maker: "0x1111111111111111111111111111111111111111",
|
|
98
|
+
receiver: "0x1111111111111111111111111111111111111111",
|
|
99
|
+
nonce: 0n,
|
|
100
|
+
marketId: 1n,
|
|
101
|
+
makingAmount: 1_000_000n,
|
|
102
|
+
takingAmount: 500_000n,
|
|
103
|
+
deadline: 1_900_000_000n,
|
|
104
|
+
tradeType: TradeType.SELL,
|
|
105
|
+
signatureType: SignatureType.EIP712,
|
|
106
|
+
tokenId: 42n,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const payload = helper.serializeOrder(order);
|
|
17
110
|
|
|
18
|
-
|
|
111
|
+
const api = new OrderbookApi({ baseUrl: "https://example.stryke.xyz" });
|
|
112
|
+
await api.queryOrders({ marketId: payload.marketId });
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
For the exact order model, fill semantics, fee math, and typed-data schema, use
|
|
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).
|
|
119
|
+
|
|
120
|
+
## Smart-Account Helpers
|
|
121
|
+
|
|
122
|
+
The package root exports the smart-account helpers from
|
|
123
|
+
[`src/smart-account.ts`](./src/smart-account.ts). These helpers are for
|
|
124
|
+
deterministic account derivation and deployment checks that match the
|
|
125
|
+
`SimpleAccountFactory`-style contract surface used by the wider Stryke stack.
|
|
126
|
+
|
|
127
|
+
Public types:
|
|
128
|
+
|
|
129
|
+
- `SmartAccountConfig`
|
|
130
|
+
- `SmartAccountResult`
|
|
131
|
+
|
|
132
|
+
Public functions:
|
|
133
|
+
|
|
134
|
+
- `getCurrentSalt(accountCount)`
|
|
135
|
+
- `getSmartAccountAddress(client, factoryAddress, owner, depositor, salt)`
|
|
136
|
+
- `getAccountCount(client, factoryAddress, owner)`
|
|
137
|
+
- `isSmartAccountDeployed(client, address)`
|
|
138
|
+
- `getCurrentSmartAccount(client, factoryAddress, owner, depositor)`
|
|
139
|
+
|
|
140
|
+
Public class:
|
|
141
|
+
|
|
142
|
+
- `SmartAccountHelper`
|
|
143
|
+
- `factoryAddress`
|
|
144
|
+
- `getAddress(client, owner, depositor, salt)`
|
|
145
|
+
- `getAccountCount(client, owner)`
|
|
146
|
+
- `getCurrent(client, owner, depositor)`
|
|
147
|
+
- `isDeployed(client, address)`
|
|
148
|
+
|
|
149
|
+
```ts
|
|
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
|
+
```
|
|
19
161
|
|
|
20
|
-
|
|
21
|
-
-
|
|
22
|
-
|
|
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.
|
|
165
|
+
|
|
166
|
+
## Address And Bps Helpers
|
|
167
|
+
|
|
168
|
+
Two utility classes are exported from the package root for common app-side
|
|
169
|
+
operations.
|
|
170
|
+
|
|
171
|
+
### `Address`
|
|
172
|
+
|
|
173
|
+
Source: [`src/address.ts`](./src/address.ts)
|
|
174
|
+
|
|
175
|
+
Public surfaces:
|
|
176
|
+
|
|
177
|
+
- `Address.NATIVE_CURRENCY`
|
|
178
|
+
- `Address.zeroAddress`
|
|
179
|
+
- `Address.fromBigInt(val)`
|
|
180
|
+
- `Address.fromFirstBytes(bytes)`
|
|
181
|
+
- `toString()`
|
|
182
|
+
- `equal(other)`
|
|
183
|
+
- `isNative()`
|
|
184
|
+
- `isZero()`
|
|
185
|
+
- `lastHalf()`
|
|
186
|
+
|
|
187
|
+
This helper wraps address normalization and a few convenience checks that are
|
|
188
|
+
useful in UI and backend code.
|
|
189
|
+
|
|
190
|
+
### `Bps`
|
|
191
|
+
|
|
192
|
+
Source: [`src/bps.ts`](./src/bps.ts)
|
|
193
|
+
|
|
194
|
+
Public surfaces:
|
|
195
|
+
|
|
196
|
+
- `Bps.ZERO`
|
|
197
|
+
- `Bps.fromPercent(val, base?)`
|
|
198
|
+
- `Bps.fromFraction(val, base?)`
|
|
199
|
+
- `equal(other)`
|
|
200
|
+
- `isZero()`
|
|
201
|
+
- `toPercent(base?)`
|
|
202
|
+
- `toFraction(base?)`
|
|
203
|
+
- `toString()`
|
|
204
|
+
|
|
205
|
+
`Bps` is a small helper around basis-point values in the inclusive range
|
|
206
|
+
`[0, 10000]`.
|
|
207
|
+
|
|
208
|
+
## Compatibility Constants And Utilities
|
|
209
|
+
|
|
210
|
+
### Constants helpers
|
|
211
|
+
|
|
212
|
+
Source: [`src/constants.ts`](./src/constants.ts)
|
|
213
|
+
|
|
214
|
+
Public surfaces:
|
|
215
|
+
|
|
216
|
+
- `ZX`
|
|
217
|
+
- `getExchangeContract(chainId)`
|
|
218
|
+
- `getLimitOrderContract(chainId)`
|
|
219
|
+
- `getMarketsRegistryContract(chainId)`
|
|
220
|
+
- `getNativeOrderFactoryContract(chainId)`
|
|
221
|
+
- `getNativeOrderImplContract(chainId)`
|
|
222
|
+
|
|
223
|
+
The exchange and registry accessors are still useful. The native order factory
|
|
224
|
+
and impl helpers are compatibility-oriented and should be treated as legacy
|
|
225
|
+
bridge helpers rather than the center of new integrations.
|
|
226
|
+
|
|
227
|
+
### Utility functions
|
|
228
|
+
|
|
229
|
+
For the detailed utility reference, use the
|
|
230
|
+
[Utilities guide](./src/utils/README.md). The public root-level utility exports
|
|
231
|
+
are:
|
|
232
|
+
|
|
233
|
+
- `mulDiv`
|
|
234
|
+
- `Rounding`
|
|
235
|
+
- `randBigInt`
|
|
236
|
+
- `optionPrmToPrmTokenId`
|
|
237
|
+
- `prmToOptionPrmTokenId`
|
|
238
|
+
- `isComplementaryOptionTokenPair`
|
|
239
|
+
- `verifyOrderSignature`
|
|
240
|
+
|
|
241
|
+
## Documentation Principles
|
|
242
|
+
|
|
243
|
+
The new docs aim to serve both technical readers and product-adjacent readers:
|
|
244
|
+
|
|
245
|
+
- each module guide starts with purpose and system role
|
|
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
|
|
23
251
|
|
|
24
252
|
## Install
|
|
25
253
|
|
|
@@ -37,9 +265,25 @@ bun test src
|
|
|
37
265
|
|
|
38
266
|
## Source Layout
|
|
39
267
|
|
|
40
|
-
- `src/exchange
|
|
41
|
-
|
|
42
|
-
- `src/
|
|
43
|
-
|
|
44
|
-
- `src/
|
|
45
|
-
|
|
268
|
+
- [`src/exchange`](./src/exchange): native order model, typed-data, math, and
|
|
269
|
+
exchange calldata builders
|
|
270
|
+
- [`src/vault`](./src/vault): token-id helpers, collateral math, and vault
|
|
271
|
+
transaction builders
|
|
272
|
+
- [`src/registry`](./src/registry): market serialization and registry calldata
|
|
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
|
|
278
|
+
|
|
279
|
+
## Legacy Docs
|
|
280
|
+
|
|
281
|
+
The current docs remain available during the transition:
|
|
282
|
+
|
|
283
|
+
- [Cross-repo guide](./docs/CROSS_REPO_INTEGRATION.md)
|
|
284
|
+
- [Orderbook integration quick reference](./docs/orderbook-integration.md)
|
|
285
|
+
- [SDK API reference](./docs/API_REFERENCE.md)
|
|
286
|
+
- [Refactor notes and protocol specs](./docs/refactor-docs)
|
|
287
|
+
|
|
288
|
+
Once the new documentation set is fully adopted, these older guides can be
|
|
289
|
+
trimmed or removed with less migration risk.
|