@stryke-xyz/premarket-sdk 1.2.0 → 1.2.1
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 +5 -4
- package/dist/cjs/abi/MarketsRegistry.abi.json +98 -0
- package/dist/cjs/abi/OptionMarketVault.abi.json +78 -5
- package/dist/cjs/api/README.md +296 -0
- package/dist/cjs/config/README.md +112 -0
- package/dist/cjs/config/index.js +7 -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/registry/markets-registry-contract.js +4 -1
- package/dist/cjs/registry/types.js +6 -2
- package/dist/cjs/shared/README.md +235 -0
- package/dist/cjs/shared/utils.js +1 -0
- package/dist/cjs/sync/README.md +215 -0
- package/dist/cjs/sync/clients/activity-client.js +454 -325
- package/dist/cjs/sync/clients/base-client.js +518 -0
- package/dist/cjs/sync/clients/order-client.js +426 -606
- package/dist/cjs/sync/redis-ws-client.js +235 -0
- package/dist/cjs/utils/README.md +89 -0
- package/dist/cjs/vault/README.md +268 -0
- package/dist/cjs/vault/transactions.js +4 -3
- package/dist/esm/abi/MarketsRegistry.abi.json +98 -0
- package/dist/esm/abi/OptionMarketVault.abi.json +78 -5
- package/dist/esm/api/README.md +296 -0
- package/dist/esm/config/README.md +112 -0
- package/dist/esm/config/index.js +4 -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/registry/markets-registry-contract.js +4 -1
- package/dist/esm/registry/types.js +6 -2
- package/dist/esm/shared/README.md +235 -0
- package/dist/esm/shared/utils.js +0 -0
- package/dist/esm/sync/README.md +215 -0
- package/dist/esm/sync/clients/activity-client.js +454 -325
- package/dist/esm/sync/clients/base-client.js +508 -0
- package/dist/esm/sync/clients/order-client.js +426 -606
- package/dist/esm/sync/redis-ws-client.js +225 -0
- package/dist/esm/utils/README.md +89 -0
- package/dist/esm/vault/README.md +268 -0
- package/dist/esm/vault/transactions.js +4 -3
- package/dist/types/config/index.d.ts +2 -0
- package/dist/types/registry/types.d.ts +4 -0
- package/dist/types/shared/utils.d.ts +0 -0
- package/dist/types/sync/clients/activity-client.d.ts +32 -39
- package/dist/types/sync/clients/base-client.d.ts +56 -0
- package/dist/types/sync/clients/order-client.d.ts +58 -79
- package/dist/types/sync/index.d.ts +2 -2
- package/dist/types/sync/redis-ws-client.d.ts +21 -0
- package/dist/types/vault/transactions.d.ts +1 -1
- package/package.json +58 -58
package/dist/cjs/config/index.js
CHANGED
|
@@ -12,6 +12,9 @@ _export(exports, {
|
|
|
12
12
|
get CHAIN_ID_TO_CHAIN () {
|
|
13
13
|
return CHAIN_ID_TO_CHAIN;
|
|
14
14
|
},
|
|
15
|
+
get COMMUNITY_MARKET_MANAGER () {
|
|
16
|
+
return COMMUNITY_MARKET_MANAGER;
|
|
17
|
+
},
|
|
15
18
|
get ENTRY_POINT () {
|
|
16
19
|
return ENTRY_POINT;
|
|
17
20
|
},
|
|
@@ -124,11 +127,12 @@ var _obj3;
|
|
|
124
127
|
decimals: 6
|
|
125
128
|
});
|
|
126
129
|
var _obj4;
|
|
127
|
-
/** OptionMarketVault contract addresses by supported chain. */ var OPTION_MARKET_VAULT = (_obj4 = {}, _define_property(_obj4, _chains.anvil.id, "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"), _define_property(_obj4, _chains.arbitrum.id, "0xd07280a68bd53b83b6b25861016bed637b3024ed"), _define_property(_obj4, _chains1.megaETH.id, "
|
|
130
|
+
/** OptionMarketVault contract addresses by supported chain. */ var OPTION_MARKET_VAULT = (_obj4 = {}, _define_property(_obj4, _chains.anvil.id, "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"), _define_property(_obj4, _chains.arbitrum.id, "0xd07280a68bd53b83b6b25861016bed637b3024ed"), _define_property(_obj4, _chains1.megaETH.id, "0x8F210f019EA5AE7da6d4Bf0227CF53997390fAA5"), _obj4);
|
|
128
131
|
var _obj5;
|
|
129
|
-
/** Exchange contract addresses by supported chain. */ var EXCHANGE = (_obj5 = {}, _define_property(_obj5, _chains.anvil.id, "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"), _define_property(_obj5, _chains.arbitrum.id, "0x8e25cc9aed1131c54b176ef2f0a3a5593db1554b"), _define_property(_obj5, _chains1.megaETH.id, "
|
|
132
|
+
/** Exchange contract addresses by supported chain. */ var EXCHANGE = (_obj5 = {}, _define_property(_obj5, _chains.anvil.id, "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"), _define_property(_obj5, _chains.arbitrum.id, "0x8e25cc9aed1131c54b176ef2f0a3a5593db1554b"), _define_property(_obj5, _chains1.megaETH.id, "0xD76DD568918Dd1c37BF88FD3498DbB28147b93f7"), _obj5);
|
|
130
133
|
var _obj6;
|
|
131
|
-
/** MarketsRegistry contract addresses on chains where the registry is deployed. */ var MARKETS_REGISTRY = (_obj6 = {}, _define_property(_obj6, _chains.anvil.id, "0x5FbDB2315678afecb367f032d93F642f64180aa3"), _define_property(_obj6, _chains1.megaETH.id, "
|
|
134
|
+
/** MarketsRegistry contract addresses on chains where the registry is deployed. */ var MARKETS_REGISTRY = (_obj6 = {}, _define_property(_obj6, _chains.anvil.id, "0x5FbDB2315678afecb367f032d93F642f64180aa3"), _define_property(_obj6, _chains1.megaETH.id, "0xc018879Ad776D48dB00D8e42Ee67145D9B02f8bc"), _obj6);
|
|
135
|
+
/** CommunityMarketManager contract addresses on chains where it is deployed. */ var COMMUNITY_MARKET_MANAGER = _define_property({}, _chains1.megaETH.id, "0x702efdacE3c278A13e8a1CC9b4161Cb8d8cFbcC9");
|
|
132
136
|
var _obj7;
|
|
133
137
|
/** ERC-4337 EntryPoint addresses used by Stryke smart accounts. */ var ENTRY_POINT = (_obj7 = {}, _define_property(_obj7, _chains.anvil.id, "0x09635F643e140090A9A8Dcd712eD6285858ceBef"), _define_property(_obj7, _chains.arbitrum.id, "0x0000000071727De22E5E9d8BAf0edAc6f37da032"), _define_property(_obj7, _chains1.megaETH.id, "0x09635F643e140090A9A8Dcd712eD6285858ceBef"), _obj7);
|
|
134
138
|
var _obj8;
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# Exchange Guide
|
|
2
|
+
|
|
3
|
+
The `exchange` module is the trading core of the SDK. It models the native
|
|
4
|
+
order format used by Stryke's `Exchange` contract, reproduces its EIP-712
|
|
5
|
+
signing schema, mirrors the most important fee and crossing math, and encodes
|
|
6
|
+
calldata for fills, matches, cancellation, and batching.
|
|
7
|
+
|
|
8
|
+
For most trading integrations this is the first module to understand.
|
|
9
|
+
|
|
10
|
+
## Source map
|
|
11
|
+
|
|
12
|
+
- [`index.ts`](./index.ts) re-exports the public exchange surface
|
|
13
|
+
- [`types.ts`](./types.ts) defines in-memory and transport-safe order types
|
|
14
|
+
- [`order.ts`](./order.ts) builds and validates orders
|
|
15
|
+
- [`eip712.ts`](./eip712.ts) defines the domain, typed data, hashing, and signer
|
|
16
|
+
recovery helpers
|
|
17
|
+
- [`math.ts`](./math.ts) mirrors pricing, fee, and crossing math
|
|
18
|
+
- [`exchange-contract.ts`](./exchange-contract.ts) encodes calldata for the
|
|
19
|
+
shipped `Exchange` ABI
|
|
20
|
+
- [`errors.ts`](./errors.ts) decodes custom errors from core protocol ABIs
|
|
21
|
+
|
|
22
|
+
## What this module is for
|
|
23
|
+
|
|
24
|
+
In plain language:
|
|
25
|
+
|
|
26
|
+
- it tells wallets exactly what they are signing
|
|
27
|
+
- it gives resolvers and frontends a stable order shape
|
|
28
|
+
- it lets backend and UI code compute prices and fill amounts the same way the
|
|
29
|
+
contract does
|
|
30
|
+
- it builds transaction payloads without each consumer bundling its own ABI
|
|
31
|
+
|
|
32
|
+
## Core order model
|
|
33
|
+
|
|
34
|
+
The canonical in-memory order type is [`ExchangeOrder`](./types.ts). Every
|
|
35
|
+
numeric field is a `bigint`, so callers do not lose precision between order
|
|
36
|
+
construction and signature generation.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
export interface ExchangeOrder {
|
|
40
|
+
salt: bigint;
|
|
41
|
+
nonce: bigint;
|
|
42
|
+
marketId: bigint;
|
|
43
|
+
makingAmount: bigint;
|
|
44
|
+
takingAmount: bigint;
|
|
45
|
+
deadline: bigint;
|
|
46
|
+
maker: Address;
|
|
47
|
+
receiver: Address;
|
|
48
|
+
tradeType: TradeType;
|
|
49
|
+
signatureType: SignatureType;
|
|
50
|
+
tokenId: bigint;
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Related public types:
|
|
55
|
+
|
|
56
|
+
- `TradeType`
|
|
57
|
+
- `BUY = 0`
|
|
58
|
+
- `SELL = 1`
|
|
59
|
+
- `SignatureType`
|
|
60
|
+
- `EIP712 = 0`
|
|
61
|
+
- `ERC1271 = 1`
|
|
62
|
+
- `SerializedExchangeOrder`
|
|
63
|
+
- string-safe transport version for HTTP or persistence
|
|
64
|
+
- `ExchangeOrderStatus`
|
|
65
|
+
- `{ isFilledOrCancelled, remaining }`
|
|
66
|
+
- `SerializedExchangeOrderStatus`
|
|
67
|
+
- string-safe status payload
|
|
68
|
+
- `MulticallResult`
|
|
69
|
+
- helper type for multicall consumers
|
|
70
|
+
|
|
71
|
+
## Building orders
|
|
72
|
+
|
|
73
|
+
`buildExchangeOrder` in [`order.ts`](./order.ts) normalizes an order before it
|
|
74
|
+
is signed or serialized:
|
|
75
|
+
|
|
76
|
+
- `salt` defaults to a random 96-bit-compatible value
|
|
77
|
+
- `receiver` defaults to `maker`
|
|
78
|
+
- `signatureType` defaults to `SignatureType.EIP712`
|
|
79
|
+
- `makingAmount`, `takingAmount`, and `deadline` must all be positive
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import {
|
|
83
|
+
SignatureType,
|
|
84
|
+
TradeType,
|
|
85
|
+
buildExchangeOrder,
|
|
86
|
+
} from "@stryke-xyz/premarket-sdk";
|
|
87
|
+
|
|
88
|
+
const order = buildExchangeOrder({
|
|
89
|
+
maker: "0x1111111111111111111111111111111111111111",
|
|
90
|
+
nonce: 12n,
|
|
91
|
+
marketId: 7n,
|
|
92
|
+
makingAmount: 1_000_000n,
|
|
93
|
+
takingAmount: 500_000n,
|
|
94
|
+
deadline: 1_900_000_000n,
|
|
95
|
+
tradeType: TradeType.SELL,
|
|
96
|
+
signatureType: SignatureType.EIP712,
|
|
97
|
+
tokenId: 123456n,
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Public builder and validation helpers:
|
|
102
|
+
|
|
103
|
+
- `buildExchangeOrder(params)`
|
|
104
|
+
- returns a normalized `ExchangeOrder`
|
|
105
|
+
- `validateExchangeOrder(order)`
|
|
106
|
+
- enforces the minimal numeric invariants expected by the contract
|
|
107
|
+
- `isOrderExpired(order, nowSec?)`
|
|
108
|
+
- compares `deadline` against a supplied or current unix timestamp
|
|
109
|
+
- `getExecutableMakingAmount(order, status)`
|
|
110
|
+
- resolves the important status edge case where
|
|
111
|
+
`remaining === 0 && !isFilledOrCancelled` means the order is still fully
|
|
112
|
+
open
|
|
113
|
+
- `getExchangeOrderHash(order, chainId, exchangeAddress)`
|
|
114
|
+
- convenience wrapper around the typed-data hashing helper
|
|
115
|
+
|
|
116
|
+
## Signing and hashing
|
|
117
|
+
|
|
118
|
+
The EIP-712 implementation in [`eip712.ts`](./eip712.ts) is the contract-aligned
|
|
119
|
+
source of truth for signed order payloads.
|
|
120
|
+
|
|
121
|
+
Important constants:
|
|
122
|
+
|
|
123
|
+
- `EXCHANGE_EIP712_NAME = "Exchange"`
|
|
124
|
+
- `EXCHANGE_EIP712_VERSION = "1"`
|
|
125
|
+
- `EXCHANGE_ORDER_TYPES`
|
|
126
|
+
- the exact typed-data fields and enum serialization used in signatures
|
|
127
|
+
|
|
128
|
+
Public helpers:
|
|
129
|
+
|
|
130
|
+
- `getExchangeDomain(chainId, verifyingContract)`
|
|
131
|
+
- `getExchangeTypedData(order, chainId, verifyingContract)`
|
|
132
|
+
- `hashExchangeOrder(order, chainId, verifyingContract)`
|
|
133
|
+
- `recoverExchangeOrderSigner(order, signature, chainId, verifyingContract)`
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import {
|
|
137
|
+
getExchangeTypedData,
|
|
138
|
+
hashExchangeOrder,
|
|
139
|
+
} from "@stryke-xyz/premarket-sdk";
|
|
140
|
+
|
|
141
|
+
const typedData = getExchangeTypedData(order, 4326, exchangeAddress);
|
|
142
|
+
const digest = hashExchangeOrder(order, 4326, exchangeAddress);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Use these helpers whenever you need exact parity with onchain signature checks.
|
|
146
|
+
That includes CI, frontend signing, backend verification, and smart-account
|
|
147
|
+
flows that still sign the native `Exchange` order shape.
|
|
148
|
+
|
|
149
|
+
## Serialization helpers
|
|
150
|
+
|
|
151
|
+
`serializeExchangeOrder` and `deserializeExchangeOrder` in [`types.ts`](./types.ts)
|
|
152
|
+
bridge the two most common representations:
|
|
153
|
+
|
|
154
|
+
- `ExchangeOrder` for local calculations and signing
|
|
155
|
+
- `SerializedExchangeOrder` for APIs, storage, and JSON payloads
|
|
156
|
+
|
|
157
|
+
Likewise, `serializeOrderStatus` and `deserializeOrderStatus` make it safe to
|
|
158
|
+
transport status objects without losing `bigint` precision.
|
|
159
|
+
|
|
160
|
+
## Math helpers
|
|
161
|
+
|
|
162
|
+
[`math.ts`](./math.ts) contains the SDK's exchange-side arithmetic helpers.
|
|
163
|
+
These are intentionally small, deterministic, and contract-aligned.
|
|
164
|
+
|
|
165
|
+
Public constants:
|
|
166
|
+
|
|
167
|
+
- `EXCHANGE_ONE = 10n ** 18n`
|
|
168
|
+
- `FEE_RATE_BASE = 1_000_000n`
|
|
169
|
+
|
|
170
|
+
Public math functions:
|
|
171
|
+
|
|
172
|
+
- `getTakingAmount(fillMakingAmount, orderMakingAmount, orderTakingAmount)`
|
|
173
|
+
- floor division from maker-side fill amount to taker-side fill amount
|
|
174
|
+
- `getMakingAmount(fillTakingAmount, orderMakingAmount, orderTakingAmount)`
|
|
175
|
+
- inverse of the above, also using floor division
|
|
176
|
+
- `calculateFee(grossAmount, feeRate)`
|
|
177
|
+
- validates `feeRate` is within `[0, 1e6]`
|
|
178
|
+
- `applyFee(grossAmount, feeRate)`
|
|
179
|
+
- returns `{ fee, net }`
|
|
180
|
+
- `getOrderPriceWad(order)`
|
|
181
|
+
- normalizes price into 1e18 precision
|
|
182
|
+
- `optionPrmToPrmId(tokenId)`
|
|
183
|
+
- canonicalizes `oPRM` token ids to the underlying even `PRM` id
|
|
184
|
+
- `isCrossing(orderA, orderB)`
|
|
185
|
+
- detects valid crosses for complementary trades and mint/merge style matches
|
|
186
|
+
- `hasValidTokenPairForMatch(orderA, orderB)`
|
|
187
|
+
- enforces token pairing rules for cross, mint, and merge cases
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
import {
|
|
191
|
+
applyFee,
|
|
192
|
+
getTakingAmount,
|
|
193
|
+
isCrossing,
|
|
194
|
+
} from "@stryke-xyz/premarket-sdk";
|
|
195
|
+
|
|
196
|
+
const takingAmount = getTakingAmount(250_000n, order.makingAmount, order.takingAmount);
|
|
197
|
+
const { fee, net } = applyFee(takingAmount, 2_000n);
|
|
198
|
+
const crossing = isCrossing(buyOrder, sellOrder);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Calldata builders
|
|
202
|
+
|
|
203
|
+
`ExchangeContract` in [`exchange-contract.ts`](./exchange-contract.ts) wraps the
|
|
204
|
+
shipped ABI and returns either raw calldata or a minimal transaction envelope.
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import { ExchangeContract } from "@stryke-xyz/premarket-sdk";
|
|
208
|
+
|
|
209
|
+
const exchange = new ExchangeContract(exchangeAddress);
|
|
210
|
+
|
|
211
|
+
const fillTx = exchange.buildFillOrderTx(order, 500_000n, signature);
|
|
212
|
+
const matchData = exchange.getMatchOrderCalldata(
|
|
213
|
+
takerOrder,
|
|
214
|
+
takerSignature,
|
|
215
|
+
makerOrder,
|
|
216
|
+
makerSignature,
|
|
217
|
+
100_000n,
|
|
218
|
+
100_000n,
|
|
219
|
+
);
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Public methods:
|
|
223
|
+
|
|
224
|
+
- `getFillOrderCalldata(order, fillAmount, signature)`
|
|
225
|
+
- `buildFillOrderTx(order, fillAmount, signature)`
|
|
226
|
+
- `getMatchOrderCalldata(takerOrder, takerSignature, makerOrder, makerSignature, takerFillAmount, makerFillAmount)`
|
|
227
|
+
- `buildMatchOrderTx(takerOrder, takerSignature, makerOrder, makerSignature, takerFillAmount, makerFillAmount)`
|
|
228
|
+
- `getCancelOrderCalldata(order)`
|
|
229
|
+
- `getIncrementNonceCalldata()`
|
|
230
|
+
- `getSetResolverWhitelistCalldata(resolver, isWhitelisted)`
|
|
231
|
+
- `getSetFeeReceiverCalldata(newFeeReceiver)`
|
|
232
|
+
- `getPauseCalldata()`
|
|
233
|
+
- `getUnpauseCalldata()`
|
|
234
|
+
- `getMulticallCalldata(data, allowFailure?)`
|
|
235
|
+
|
|
236
|
+
`buildFillOrderTx` and `buildMatchOrderTx` are the only helpers that currently
|
|
237
|
+
return a full `{ to, data, value }` transaction object. The remaining methods
|
|
238
|
+
return encoded calldata so the caller can place them inside a broader tx or
|
|
239
|
+
user operation.
|
|
240
|
+
|
|
241
|
+
Restricted/admin surfaces:
|
|
242
|
+
|
|
243
|
+
- `getSetResolverWhitelistCalldata`
|
|
244
|
+
- `getSetFeeReceiverCalldata`
|
|
245
|
+
- `getPauseCalldata`
|
|
246
|
+
- `getUnpauseCalldata`
|
|
247
|
+
|
|
248
|
+
These are documented here because they are part of the export surface, but they
|
|
249
|
+
are operationally restricted and should not be treated as general-user flows.
|
|
250
|
+
|
|
251
|
+
## Error decoding
|
|
252
|
+
|
|
253
|
+
`decodeContractError` in [`errors.ts`](./errors.ts) attempts to decode a revert
|
|
254
|
+
payload against the shipped `Exchange`, `OptionMarketVault`, and
|
|
255
|
+
`MarketsRegistry` ABIs.
|
|
256
|
+
|
|
257
|
+
It returns either `null` or:
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
interface DecodedContractError {
|
|
261
|
+
contract: "exchange" | "optionMarketVault" | "marketsRegistry";
|
|
262
|
+
name: string;
|
|
263
|
+
signature: string;
|
|
264
|
+
args: readonly unknown[];
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
This is useful for frontend error messaging, backend diagnostics, and test
|
|
269
|
+
assertions where raw revert bytes are not enough.
|
|
270
|
+
|
|
271
|
+
## Recommended integration pattern
|
|
272
|
+
|
|
273
|
+
1. Build a normalized order with `buildExchangeOrder` or `OrderHelper`.
|
|
274
|
+
2. Hash or sign using the typed-data helpers.
|
|
275
|
+
3. Serialize the order before sending it to the API.
|
|
276
|
+
4. Use `ExchangeContract` to build fill or match calldata.
|
|
277
|
+
5. Use `decodeContractError` when surfacing or logging contract reverts.
|
|
278
|
+
|
|
279
|
+
If you want the higher-level workflow wrapper that bundles these steps together,
|
|
280
|
+
continue with the [API guide](../api/README.md), which documents `OrderHelper`.
|
package/dist/cjs/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@stryke-xyz/premarket-sdk","version":"1.
|
|
1
|
+
{"name":"@stryke-xyz/premarket-sdk","version":"1.1.8","type":"commonjs"}
|
|
@@ -0,0 +1,150 @@
|
|
|
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.
|
|
@@ -49,6 +49,7 @@ function _interop_require_default(obj) {
|
|
|
49
49
|
}
|
|
50
50
|
var marketsRegistryAbi = _MarketsRegistryabijson.default;
|
|
51
51
|
/** Minimal transaction envelope returned by registry calldata builders. */ function normalizeMarket(market) {
|
|
52
|
+
var _market_isSpread, _market_useAbsoluteSpreadCollateral;
|
|
52
53
|
return {
|
|
53
54
|
underlying: market.underlying,
|
|
54
55
|
collateral: market.collateral,
|
|
@@ -65,7 +66,9 @@ var marketsRegistryAbi = _MarketsRegistryabijson.default;
|
|
|
65
66
|
rolloverFeeBps: BigInt(market.rolloverFeeBps),
|
|
66
67
|
marketType: Number(market.marketType),
|
|
67
68
|
isCollateralScaled: market.isCollateralScaled,
|
|
68
|
-
nonRollable: market.nonRollable
|
|
69
|
+
nonRollable: market.nonRollable,
|
|
70
|
+
isSpread: (_market_isSpread = market.isSpread) !== null && _market_isSpread !== void 0 ? _market_isSpread : false,
|
|
71
|
+
useAbsoluteSpreadCollateral: (_market_useAbsoluteSpreadCollateral = market.useAbsoluteSpreadCollateral) !== null && _market_useAbsoluteSpreadCollateral !== void 0 ? _market_useAbsoluteSpreadCollateral : false
|
|
69
72
|
};
|
|
70
73
|
}
|
|
71
74
|
/** Calldata and transaction helpers for the markets registry contract. */ var MarketsRegistryContract = /*#__PURE__*/ function() {
|
|
@@ -41,7 +41,9 @@ _export(exports, {
|
|
|
41
41
|
rolloverFeeBps: market.rolloverFeeBps.toString(),
|
|
42
42
|
marketType: Number(market.marketType),
|
|
43
43
|
isCollateralScaled: market.isCollateralScaled,
|
|
44
|
-
nonRollable: market.nonRollable
|
|
44
|
+
nonRollable: market.nonRollable,
|
|
45
|
+
isSpread: market.isSpread,
|
|
46
|
+
useAbsoluteSpreadCollateral: market.useAbsoluteSpreadCollateral
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
49
|
/** Restores bigint fee and sizing fields from a serialized market payload. */ function deserializeRegistryMarket(market) {
|
|
@@ -61,6 +63,8 @@ _export(exports, {
|
|
|
61
63
|
rolloverFeeBps: BigInt(market.rolloverFeeBps),
|
|
62
64
|
marketType: market.marketType,
|
|
63
65
|
isCollateralScaled: market.isCollateralScaled,
|
|
64
|
-
nonRollable: market.nonRollable
|
|
66
|
+
nonRollable: market.nonRollable,
|
|
67
|
+
isSpread: market.isSpread,
|
|
68
|
+
useAbsoluteSpreadCollateral: market.useAbsoluteSpreadCollateral
|
|
65
69
|
};
|
|
66
70
|
}
|