@stryke-xyz/premarket-sdk 1.1.8 → 1.2.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 CHANGED
@@ -311,65 +311,102 @@ Constructor config:
311
311
  - `baseUrl`
312
312
  - `fetchFn?`
313
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?)`
314
+ #### Order methods
315
+
316
+ - `createOrder(params, bearerToken)` — submits a new order and synchronously
317
+ returns the engine's match outcome. The backend awaits the matching engine's
318
+ reply (up to ~2 s). If the engine does not reply in time,
319
+ `matchResult.message === "awaiting match"` and `matches` is empty callers
320
+ should then poll `getOrder` or watch the user activity WebSocket.
321
+ - `getOrder(orderHash)` — fetches a single stored order by hash; returns
322
+ `null` on 404.
323
+ - `getOrders(marketId, maker?)` — active orders for a market, optionally
324
+ scoped to a maker.
325
+ - `getUserOrders(maker, marketId)` — convenience wrapper around `getOrders`.
326
+ - `getUserOrdersAllMarkets(maker, opts?)` — all open orders across **all**
327
+ markets for a maker, paginated. `opts` accepts `{ limit?, offset?, status? }`.
328
+ Returns `PaginatedOrdersResponse`.
329
+
330
+ #### Market methods
331
+
332
+ - `getMarkets()` — full market catalog.
333
+ - `getMarketRecentTrades(marketId, limit?)` — recent trade activity, newest
334
+ first.
335
+ - `getMarket(marketId)` — single market by id; returns `null` on 404.
336
+
337
+ #### Position and PnL methods
338
+
339
+ - `getUserPositions(userAddress)` — enriched positions including market name,
340
+ instrument name, logo, collateral info, PnL breakdown, role flags
341
+ (`isOPrm`, `isOpen`), expiry, token ids, and `hasFinalTick`. Also returns a
342
+ `grouped` array keyed by market. Returns `EnrichedPositionsResponse`.
343
+ - `getUserTradingPnL(userAddress)` — realized trading PnL for limit-order
344
+ activity.
345
+ - `getUserPnL(userAddress)` — aggregated PnL across positions and orderbook
346
+ trading.
347
+ - `getTokenPnL(userAddress, tokenId)` — PnL for a single ERC-6909 token id.
348
+ - `getErc20PnL(userAddress, tokenAddress)` — trading PnL for a single ERC-20
349
+ token.
350
+
351
+ #### History methods
352
+
353
+ `getUserHistories` accepts an optional `opts` object with `limit?`, `marketId?`,
354
+ and `tokenId?` filters.
355
+
356
+ - `getUserHistories(userAddress, opts?)` — grouped + enriched user history.
357
+ Every event carries `marketName`, `instrumentName`, `logoUri`,
358
+ `collateralDecimals`, `collateralToken`, and a `type` discriminator. The
359
+ `timeline` field is a flat chronological list of all event types.
338
360
  - `getMintHistory(userAddress, limit?)`
339
361
  - `getRedeemHistory(userAddress, limit?)`
340
362
  - `getUnwindHistory(userAddress, limit?)`
341
363
  - `getTransferHistory(userAddress, limit?)`
342
364
  - `getFillHistory(userAddress, limit?)`
343
365
 
344
- Auth-related methods also exposed by the SDK:
366
+ #### Auth methods
345
367
 
346
- - `getChallenge({ address, chainId })`
347
- - `verifyAuth({ account, nonce, signature, chainId, expiresAt })`
368
+ - `getChallenge({ address, chainId })` — requests an EIP-712 login challenge.
369
+ Returns `AuthChallenge`.
370
+ - `verifyAuth({ account, nonce, signature, chainId, expiresAt })` — verifies
371
+ the signed challenge. Returns `{ access: string }` (bearer token).
348
372
 
349
- Integration note:
373
+ Integration notes:
350
374
 
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).
375
+ - `getOrders` and `getUserOrders` both require a `marketId`. Active and
376
+ partially-filled orders are returned; cancelled / fully-filled / expired
377
+ orders are filtered server-side.
378
+ - `getUserOrdersAllMarkets` operates in paginated mode and does not require a
379
+ `marketId`; it defaults to `limit: 1000, offset: 0`.
354
380
 
355
381
  ### Deserializers
356
382
 
357
383
  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`
384
+ `bigint`. Public helpers convert those payloads into bigint-friendly objects.
385
+
386
+ Scalar deserializers:
387
+
388
+ - `marketInstrumentToBigInt(instrument)` → `BigIntMarketInstrument`
389
+ - `marketToBigInt(market)` → `BigIntMarket`
390
+ - `marketsToBigInt(data)` → `{ markets: BigIntMarket[]; total: number }`
391
+ - `positionToBigInt(position)` → bigint position fields
392
+ - `tradingPnLToBigInt(trading)` → bigint PnL fields
393
+ - `mintHistoryToBigInt(mint)` → bigint mint history fields
394
+ - `redeemHistoryToBigInt(redeem)` → bigint redeem history fields
395
+ - `unwindHistoryToBigInt(unwind)` → bigint unwind history fields
396
+ - `transferHistoryToBigInt(transfer)` → bigint transfer history fields
397
+ - `fillHistoryToBigInt(fill)` → bigint fill history fields
398
+
399
+ BigInt market types exported for use with deserialized data:
400
+
401
+ - `BigIntBaseMarketInstrument`
402
+ - `BigIntVanillaMarketInstrument`
403
+ - `BigIntSpreadMarketInstrument`
404
+ - `BigIntMarketInstrument` (union)
405
+ - `BigIntBaseMarket`
406
+ - `BigIntErc6909Market`
407
+ - `BigIntErc20Market`
408
+ - `BigIntErc20Submarket`
409
+ - `BigIntMarket` (union)
373
410
 
374
411
  ## Vault Module
375
412
 
@@ -477,26 +514,42 @@ export interface TransactionCall {
477
514
 
478
515
  User-facing lifecycle builders:
479
516
 
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)`
517
+ - `buildMintTransaction(vaultAddress, instrument, amount)` — deposit collateral
518
+ to receive PRM + oPRM tokens.
519
+ - `buildWithdrawTransaction(vaultAddress, prmTokenId, amount, receiver)`
520
+ before expiry burns PRM + oPRM to return collateral; after expiry settles and
521
+ returns collateral minus loss.
522
+ - `buildRedeemTransaction(vaultAddress, oPrmTokenId, receiver)` — option
523
+ holders redeem oPRM tokens to claim profit after expiry.
524
+ - `buildUnwindTransaction(vaultAddress, prmTokenId, amount, receiver)` — alias
525
+ for `buildWithdrawTransaction`; burns both PRM and oPRM to reclaim collateral
526
+ before expiry.
527
+ - `buildRolloverTransaction(vaultAddress, oldPrmTokenId)` — rolls an expired
528
+ PRM position into the next epoch.
529
+ - `buildApproveTransaction(tokenAddress, spender, amount?)` — ERC-20 approval
530
+ (defaults to `maxUint256`).
531
+ - `buildBatchedMintTransactions(collateralTokenAddress, vaultAddress, instrument, collateralAmount, prmAmount)` —
532
+ returns `[approve, mint]` as a `TransactionCall[]` for a single UserOp batch.
533
+ - `buildSetOperatorTransaction(vaultAddress, operator, approved)` — ERC-6909
534
+ operator approval for delegated transfers.
488
535
 
489
536
  Restricted or role-gated builders:
490
537
 
491
- - `buildDelegateRedeemTransaction`
492
- - `buildDelegateRolloverTransaction`
493
- - `buildDelegateWithdrawTransaction`
494
- - `buildFillMarketDeliveryTransaction`
495
- - `buildSetRolloverEnabledTransaction`
496
- - `buildSetRoleTransaction`
497
- - `buildUpdateFinalTickTransaction`
498
- - `buildUpdateMarketExpiryTransaction`
499
- - `buildUpdateMarketExpiryFromMarketTransaction`
538
+ - `buildDelegateRedeemTransaction(vaultAddress, oPrmTokenId, receiver)`
539
+ callable only by RedeemKeeper role.
540
+ - `buildDelegateRolloverTransaction(vaultAddress, oldPrmTokenId, holder)`
541
+ callable only by RolloverKeeper role.
542
+ - `buildDelegateWithdrawTransaction(vaultAddress, prmTokenId, amount, owner, receiver)`
543
+ callable only by WithdrawKeeper role.
544
+ - `buildFillMarketDeliveryTransaction(vaultAddress, marketId, amount)`
545
+ physical settlement market funding.
546
+ - `buildSetRolloverEnabledTransaction(vaultAddress, enabled)`
547
+ - `buildSetRoleTransaction(vaultAddress, account, role, enabled)` — owner only.
548
+ - `buildUpdateFinalTickTransaction(vaultAddress, marketId, tick)` —
549
+ FinalTickKeeper role.
550
+ - `buildUpdateMarketExpiryTransaction(vaultAddress, marketId, expiry)` —
551
+ MarketFinalizer role.
552
+ - `buildUpdateMarketExpiryFromMarketTransaction(vaultAddress, marketId, expiry)`
500
553
 
501
554
  ## Registry Module
502
555
 
@@ -670,8 +723,8 @@ applications do not hardcode environment-specific values.
670
723
 
671
724
  Exports from `src/config/chains.ts`:
672
725
 
673
- - `megaETH`
674
- - `SUPPORTED_CHAINS`
726
+ - `megaETH` — viem chain definition for MegaETH mainnet (chain id `4326`)
727
+ - `SUPPORTED_CHAINS` — union type of supported chain ids
675
728
 
676
729
  Runtime lookup from `src/config/index.ts`:
677
730
 
@@ -733,9 +786,11 @@ safely over JSON.
733
786
  Main exports:
734
787
 
735
788
  - `Order`
736
- - `OrderSignature`
789
+ - `OrderSignature` — `0x${string}` (65-byte concatenated hex)
790
+ - `SplitOrderSignature` — wire format `{ r: string; vs: string }` (EIP-2098
791
+ compact pair) expected by the orderbook backend
737
792
  - `OrderStatus`
738
- - `TimeInForce`
793
+ - `TimeInForce` — `"FOK" | "FAK" | "GTC" | "GTD"`
739
794
  - `CreateOrderParams`
740
795
  - `CreateOrderRequest`
741
796
  - `StoredOrder`
@@ -746,6 +801,7 @@ Main exports:
746
801
  - `CreateOrderResult`
747
802
  - `OrderResponse`
748
803
  - `OrdersSnapshot`
804
+ - `PaginatedOrdersResponse`
749
805
 
750
806
  Main order write shape:
751
807
 
@@ -755,6 +811,8 @@ export interface CreateOrderParams {
755
811
  order: Order;
756
812
  signature: OrderSignature;
757
813
  operator?: string;
814
+ /** Primary wallet address (depositor) — required for ERC1271 smart account maker validation */
815
+ depositor?: string;
758
816
  timeInForce?: TimeInForce;
759
817
  postOnly?: boolean;
760
818
  }
@@ -775,31 +833,119 @@ export interface StoredOrder {
775
833
  status: OrderStatus;
776
834
  side: "bid" | "ask";
777
835
  price: number;
836
+ // Enriched by the order-queue when returning user orders
837
+ marketName?: string;
838
+ instrumentName?: string;
839
+ logoUri?: string | null;
778
840
  }
779
841
  ```
780
842
 
781
843
  ### Market DTOs
782
844
 
845
+ `Market` is a discriminated union (`ApiMarket = Erc6909Market | Erc20Market`).
846
+ The `type` field (`"erc6909"` | `"erc20"`) is the discriminant.
847
+
848
+ `MarketInstrument` is also a discriminated union:
849
+
850
+ ```ts
851
+ export type MarketInstrument =
852
+ | VanillaMarketInstrument // isSpread: false, spreadType: "vanilla"
853
+ | SpreadMarketInstrument; // isSpread: true, spreadType: "standard" | "absolute"
854
+ ```
855
+
783
856
  Public exports:
784
857
 
785
- - `MarketInstrument`
786
- - `Market`
858
+ - `SpreadType` — `"vanilla" | "standard" | "absolute"`
859
+ - `BaseMarket` — shared fields across all market types, including `hasFinalTick`
860
+ - `BaseMarketInstrument` — shared instrument fields including `prmTokenId`,
861
+ `oPrmTokenId`, `expiry`
862
+ - `VanillaMarketInstrument`
863
+ - `SpreadMarketInstrument` — adds `lower` and `upper` bound fields
864
+ - `MarketInstrument` (union)
865
+ - `Erc20Submarket` — ERC-20 sub-market/instrument entry
866
+ - `Erc6909Market` — full ERC-6909 market shape (vault-backed)
867
+ - `Erc20Market` — ERC-20 market shape with `instruments` array
868
+ - `ApiMarket` / `Market` (union)
787
869
  - `MarketResponse`
788
870
  - `MarketsResponse`
789
871
 
790
- `MarketInstrument` carries strike-level data such as paired token ids,
791
- top-of-book values, recent prices, collateral totals, and supply.
872
+ Key `BaseMarket` fields:
792
873
 
793
- `Market` wraps market-level metadata such as pricing increments, token
794
- addresses, fee fields, expiry, and nested `instruments`.
874
+ ```ts
875
+ export interface BaseMarket {
876
+ id: string;
877
+ groupId: string | null;
878
+ groupName: string | null; // populated for grouped ERC-20 markets
879
+ type: "erc6909" | "erc20";
880
+ name: string;
881
+ collateralToken: string;
882
+ collateralDecimals: number;
883
+ marketType: "ERC20xERC20" | "ERC20xERC6909";
884
+ logoUri: string | null;
885
+ /** True when the on-chain FinalTick event has been indexed for this market's current expiry. */
886
+ hasFinalTick: boolean;
887
+ // ... pricing / ordering fields
888
+ }
889
+ ```
795
890
 
796
891
  ### Position and PnL DTOs
797
892
 
798
893
  Public exports:
799
894
 
800
- - `UserPosition`
895
+ - `UserPosition` — raw position fields (holding, cost, proceeds, PnL)
896
+ - `EventEnrichment` — optional market/instrument metadata attached to positions
897
+ and history events (`collateralSymbol`, `marketId`, `marketName`,
898
+ `instrumentName`, `logoUri`, `collateralDecimals`, `collateralToken`)
899
+ - `EnrichedPosition` — `UserPosition` + `EventEnrichment` + role flags and
900
+ additional instrument fields:
901
+
902
+ ```ts
903
+ export interface EnrichedPosition extends UserPosition, EventEnrichment {
904
+ isOpen: boolean; // true when holding > 0
905
+ isOPrm: boolean; // true = oPRM (outcome), false = PRM (write/minted)
906
+ marketId: string;
907
+ marketName: string;
908
+ instrumentName: string;
909
+ logoUri: string | null;
910
+ collateralDecimals: number;
911
+ collateralToken: string;
912
+ /** Unix timestamp string for this instrument's epoch expiry (null for ERC20 markets). */
913
+ expiry?: string | null;
914
+ /** prmTokenId for this instrument (decimal string). */
915
+ prmTokenId?: string | null;
916
+ /** oPrmTokenId for this instrument (decimal string). */
917
+ oPrmTokenId?: string | null;
918
+ /** true when an on-chain FinalTick event has been indexed for this instrument epoch. */
919
+ hasFinalTick?: boolean;
920
+ /** PnL contribution from limit-order trades */
921
+ tradePnl: string;
922
+ /** PnL contribution from redemption / exercise settlements */
923
+ redeemExercisePnl: string;
924
+ }
925
+ ```
926
+
927
+ - `EnrichedPositionsResponse`:
928
+
929
+ ```ts
930
+ export interface EnrichedPositionsResponse {
931
+ /** Flat list sorted by updatedAt desc. */
932
+ positions: EnrichedPosition[];
933
+ /** Same positions grouped by market. */
934
+ grouped: Array<{
935
+ marketId: string;
936
+ marketName: string;
937
+ logoUri: string | null;
938
+ collateralDecimals: number;
939
+ collateralToken: string;
940
+ positions: EnrichedPosition[];
941
+ }>;
942
+ }
943
+ ```
944
+
801
945
  - `TradingPnL`
802
- - `UserPnL`
946
+ - `SettlementPnL` — settlement-specific PnL (`tokenId`, `totalProceeds`,
947
+ `realizedPnL`, `updatedAt`)
948
+ - `UserPnL` — aggregated `tradePnl`, `redeemExercisePnl`, `totalPnl`
803
949
  - `TokenPnL`
804
950
  - `Erc20PnL`
805
951
 
@@ -808,15 +954,41 @@ Public exports:
808
954
  Public exports:
809
955
 
810
956
  - `MintHistoryItem`
811
- - `RedeemHistoryItem`
957
+ - `RedeemHistoryItem` — includes `netProceeds` (profit minus fees)
812
958
  - `UnwindHistoryItem`
959
+ - `WithdrawHistoryItem` — post-expiry withdraw events (includes `loss`,
960
+ `lossUsdc`, `finalTick`, `netProceeds`)
961
+ - `RolloverHistoryItem` — rollover events (includes `oldExpiry`, `newExpiry`,
962
+ `residualCollateral`, `rolloverFee`, `finalTick`)
813
963
  - `TransferHistoryItem`
814
- - `OrderFillHistoryItem`
815
- - `MarketTradeItem`
964
+ - `OrderFillHistoryItem` — includes `isAsk` and `role` (`"maker" | "taker"`)
965
+ - `OrderCancelHistoryItem`
966
+ - `MarketTradeItem` (alias for `OrderFillHistoryItem`)
967
+ - `AnyHistoryEvent` — discriminated union of all history event types
816
968
  - `UserHistories`
817
969
 
818
- `UserHistories` groups `mints`, `redeems`, `unwinds`, `transfers`, and
819
- `fills`.
970
+ `UserHistories` groups all history types. The `timeline` field (when present)
971
+ is a flat chronological list of all events with a `type` discriminator:
972
+
973
+ ```ts
974
+ export interface UserHistories {
975
+ mints: MintHistoryItem[];
976
+ redeems: RedeemHistoryItem[];
977
+ unwinds: UnwindHistoryItem[];
978
+ withdraws: WithdrawHistoryItem[];
979
+ rollovers: RolloverHistoryItem[];
980
+ transfers: TransferHistoryItem[];
981
+ fills: OrderFillHistoryItem[];
982
+ cancels: OrderCancelHistoryItem[];
983
+ /** Flat chronological list (newest first). Each event has a `type` field. */
984
+ timeline?: AnyHistoryEvent[];
985
+ }
986
+ ```
987
+
988
+ ### Auth types
989
+
990
+ - `AuthChallenge` — EIP-712 typed-data challenge returned by `getChallenge`.
991
+ Contains `domain`, `types`, and `message` (with `nonce` and `expiresAt`).
820
992
 
821
993
  ## Root-Level Helpers
822
994
 
@@ -1 +1 @@
1
- {"name":"@stryke-xyz/premarket-sdk","version":"1.1.8","type":"commonjs"}
1
+ {"name":"@stryke-xyz/premarket-sdk","version":"1.2.0","type":"commonjs"}
@@ -35,7 +35,7 @@ Object.defineProperty(exports, "OrderStatus", {
35
35
  /** PnL contribution from limit-order trades */ /** PnL contribution from redemption / exercise settlements */ /**
36
36
  * Market/instrument metadata the API attaches to positions and history events.
37
37
  * All fields are optional so existing decoders stay backward-compatible.
38
- */ /** Position enriched with market/instrument context returned by /positions. */ /** true when holding > 0 */ /** true = oPRM (outcome position), false = PRM (write/minted) */ /** Flat list sorted by updatedAt desc. */ /** Same positions grouped by market for convenient access. */ // ============================================================================
38
+ */ /** Position enriched with market/instrument context returned by /positions. */ /** true when holding > 0 */ /** true = oPRM (outcome position), false = PRM (write/minted) */ /** Unix timestamp string for this instrument's epoch expiry (null for ERC20 markets). */ /** prmTokenId for this instrument (decimal string). */ /** oPrmTokenId for this instrument (decimal string). */ /** true when an on-chain FinalTick event has been indexed for this instrument epoch. */ /** Flat list sorted by updatedAt desc. */ /** Same positions grouped by market for convenient access. */ // ============================================================================
39
39
  // HISTORY TYPES
40
40
  // ============================================================================
41
41
  /** Net proceeds after fees (profit - fees), as a string */ /** true = ask (maker sells), false = bid (maker buys); from API when available */ /** Recent trade item as returned by getMarketRecentTrades */ /** FinalTick of the just-closed (oldExpiry) epoch, if indexed. Null if the