@domfi/sdk 0.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.
Files changed (93) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +786 -0
  3. package/dist/actions.cjs +1 -0
  4. package/dist/actions.d.cts +17 -0
  5. package/dist/actions.d.ts +17 -0
  6. package/dist/actions.js +1 -0
  7. package/dist/api.cjs +1 -0
  8. package/dist/api.d.cts +664 -0
  9. package/dist/api.d.ts +664 -0
  10. package/dist/api.js +0 -0
  11. package/dist/chunk-2VSPOLVO.js +1 -0
  12. package/dist/chunk-5YZVCHRU.js +0 -0
  13. package/dist/chunk-77XMXAXE.js +1 -0
  14. package/dist/chunk-7OVWNPZQ.js +1 -0
  15. package/dist/chunk-BMYMNNJK.js +1 -0
  16. package/dist/chunk-C5Y2WM7C.js +1 -0
  17. package/dist/chunk-C64LJM7D.js +2 -0
  18. package/dist/chunk-CLOFJTBP.js +1 -0
  19. package/dist/chunk-CMREWGOI.js +1 -0
  20. package/dist/chunk-D5VE2O4F.js +1 -0
  21. package/dist/chunk-LDE3JHVE.js +1 -0
  22. package/dist/chunk-N4Q67DTE.js +1 -0
  23. package/dist/chunk-SZE5DE54.js +1 -0
  24. package/dist/chunk-XHQVWI2J.js +1 -0
  25. package/dist/chunk-YU5DN3PI.js +1 -0
  26. package/dist/config.cjs +2 -0
  27. package/dist/config.d.cts +132 -0
  28. package/dist/config.d.ts +132 -0
  29. package/dist/config.js +1 -0
  30. package/dist/contracts.cjs +1 -0
  31. package/dist/contracts.d.cts +13073 -0
  32. package/dist/contracts.d.ts +13073 -0
  33. package/dist/contracts.js +1 -0
  34. package/dist/delegation.cjs +1 -0
  35. package/dist/delegation.d.cts +7 -0
  36. package/dist/delegation.d.ts +7 -0
  37. package/dist/delegation.js +0 -0
  38. package/dist/errors.cjs +3 -0
  39. package/dist/errors.d.cts +155 -0
  40. package/dist/errors.d.ts +155 -0
  41. package/dist/errors.js +3 -0
  42. package/dist/index.cjs +2 -0
  43. package/dist/index.d.cts +216 -0
  44. package/dist/index.d.ts +216 -0
  45. package/dist/index.js +1 -0
  46. package/dist/math.cjs +1 -0
  47. package/dist/math.d.cts +273 -0
  48. package/dist/math.d.ts +273 -0
  49. package/dist/math.js +1 -0
  50. package/dist/position-BnhSFyGe.d.cts +56 -0
  51. package/dist/position-BnhSFyGe.d.ts +56 -0
  52. package/dist/rawSchemas-MAT7EZCV.js +1 -0
  53. package/dist/referrals.cjs +1 -0
  54. package/dist/referrals.d.cts +66 -0
  55. package/dist/referrals.d.ts +66 -0
  56. package/dist/referrals.js +1 -0
  57. package/dist/serde.cjs +1 -0
  58. package/dist/serde.d.cts +24 -0
  59. package/dist/serde.d.ts +24 -0
  60. package/dist/serde.js +1 -0
  61. package/dist/token.cjs +1 -0
  62. package/dist/token.d.cts +32 -0
  63. package/dist/token.d.ts +32 -0
  64. package/dist/token.js +0 -0
  65. package/dist/trading.cjs +1 -0
  66. package/dist/trading.d.cts +20 -0
  67. package/dist/trading.d.ts +20 -0
  68. package/dist/trading.js +1 -0
  69. package/dist/types-7s13ZSql.d.ts +533 -0
  70. package/dist/types-BK6dYOXr.d.cts +118 -0
  71. package/dist/types-CMtixBIP.d.cts +464 -0
  72. package/dist/types-DB1r_Ppi.d.ts +464 -0
  73. package/dist/types-DDgJiEFg.d.ts +780 -0
  74. package/dist/types-DJBX-p4X.d.cts +780 -0
  75. package/dist/types-DQft82W7.d.cts +533 -0
  76. package/dist/types-DhCzEwnS.d.ts +118 -0
  77. package/dist/types-veTDfbhq.d.ts +436 -0
  78. package/dist/types-x1MvxSdy.d.cts +436 -0
  79. package/dist/units-BYd75H7U.d.cts +22 -0
  80. package/dist/units-BYd75H7U.d.ts +22 -0
  81. package/dist/units.cjs +1 -0
  82. package/dist/units.d.cts +248 -0
  83. package/dist/units.d.ts +248 -0
  84. package/dist/units.js +1 -0
  85. package/dist/valuation.cjs +1 -0
  86. package/dist/valuation.d.cts +5 -0
  87. package/dist/valuation.d.ts +5 -0
  88. package/dist/valuation.js +1 -0
  89. package/dist/vault.cjs +1 -0
  90. package/dist/vault.d.cts +34 -0
  91. package/dist/vault.d.ts +34 -0
  92. package/dist/vault.js +1 -0
  93. package/package.json +181 -0
@@ -0,0 +1,533 @@
1
+ import { DiagnosticsEnvelope } from './errors.js';
2
+ import { Address, PairIndex, TradeIndex, TradeId, TriggerOrderIndex, OrderId, Hex, IsoTimestamp, Collateral, Price, Leverage, Notional, DecimalString, SignedCollateral, SignedP18, ClosePercent, TimeInput, WholePercent, FeePercent, Precision2Percent, Ratio, UnsignedP18, ScaleP2, SignedP6, UsdP6 } from './units.js';
3
+
4
+ /** Position identity verified by API data, valuation snapshots, or caller-provided trade IDs. */
5
+ type VerifiedPositionRef = {
6
+ wallet: Address;
7
+ pairIndex: PairIndex;
8
+ index: TradeIndex;
9
+ tradeId: TradeId;
10
+ chainId: number;
11
+ source: "api" | "snapshot" | "caller";
12
+ };
13
+ /** Open limit/stop order identity verified from API read models. */
14
+ type ApiVerifiedOpenTriggerOrderRef = {
15
+ wallet: Address;
16
+ pairIndex: PairIndex;
17
+ index: TriggerOrderIndex;
18
+ chainId: number;
19
+ lifecycleKey: string;
20
+ orderId?: OrderId;
21
+ orderType: "limit" | "stop";
22
+ initiatedTxHash: Hex;
23
+ initiatedEventType: string;
24
+ initiatedLog?: {
25
+ blockNumber: bigint;
26
+ transactionIndex: number;
27
+ logIndex: number;
28
+ };
29
+ source: "api";
30
+ };
31
+ /** Open limit/stop order identity recovered directly from a placement transaction receipt. */
32
+ type ReceiptVerifiedOpenTriggerOrderRef = {
33
+ wallet: Address;
34
+ pairIndex: PairIndex;
35
+ index: TriggerOrderIndex;
36
+ chainId: number;
37
+ lifecycleKey?: string;
38
+ orderId?: OrderId;
39
+ orderType: "limit" | "stop";
40
+ initiatedTxHash: Hex;
41
+ initiatedLog: {
42
+ blockNumber: bigint;
43
+ transactionIndex: number;
44
+ logIndex: number;
45
+ };
46
+ source: "receipt";
47
+ };
48
+ /** Verified open trigger order identity accepted by trigger update/cancel helpers. */
49
+ type VerifiedOpenTriggerOrderRef = ApiVerifiedOpenTriggerOrderRef | ReceiptVerifiedOpenTriggerOrderRef;
50
+ /** Alias for verified trigger order identities. */
51
+ type VerifiedTriggerOrderRef = VerifiedOpenTriggerOrderRef;
52
+ /** Unverified trigger order slot for display or low-level recovery flows. */
53
+ type UnsafeTriggerOrderSlot = {
54
+ wallet: Address;
55
+ pairIndex: PairIndex;
56
+ index: TriggerOrderIndex;
57
+ };
58
+ /** Input accepted by `verifiedPositionRef` for caller-known position identities. */
59
+ type VerifiedPositionRefInput = {
60
+ wallet: Address;
61
+ pairIndex: PairIndex;
62
+ index: TradeIndex;
63
+ tradeId: TradeId;
64
+ chainId: number;
65
+ };
66
+ /** Options for parsing trigger placement identities from transaction receipts. */
67
+ type TriggerReceiptParseOptions = {
68
+ chainId: number;
69
+ expectedWallet?: Address;
70
+ expectedOrderType?: "limit" | "stop";
71
+ };
72
+ /** Brands caller-known position identity as a verified position reference. */
73
+ declare function verifiedPositionRef(input: VerifiedPositionRefInput): VerifiedPositionRef;
74
+
75
+ /** Common controls for SDK REST reads and RPC-backed reads. */
76
+ type ReadOptions = {
77
+ signal?: AbortSignal;
78
+ timeoutMs?: number;
79
+ /** Controls how REST freshness/readiness metadata is enforced. Defaults vary by client. */
80
+ readinessPolicy?: "strict" | "warn" | "ignore";
81
+ };
82
+ /** Cursor pagination controls for REST list endpoints. */
83
+ type PageOptions = ReadOptions & {
84
+ cursor?: string;
85
+ limit?: number;
86
+ };
87
+ /** Pagination controls for vault history endpoints. */
88
+ type VaultHistoryPageOptions = PageOptions;
89
+ /** Read-model freshness metadata returned with mapped REST responses. */
90
+ type Freshness = {
91
+ source: string;
92
+ generatedAt: IsoTimestamp;
93
+ indexedBlock?: bigint;
94
+ chainHeadBlock?: bigint;
95
+ lagBlocks?: bigint;
96
+ cacheStatus?: string;
97
+ cacheAgeSeconds?: bigint;
98
+ isStale: boolean;
99
+ };
100
+ /** Standard mapped REST response envelope. */
101
+ type ResultEnvelope<T> = {
102
+ data: T;
103
+ freshness: Freshness;
104
+ diagnostics?: DiagnosticsEnvelope;
105
+ };
106
+ /** Cursor pagination metadata returned by REST list endpoints. */
107
+ type CursorPagination = {
108
+ cursor?: string;
109
+ nextCursor?: string;
110
+ hasNext: boolean;
111
+ limit: number;
112
+ };
113
+ /** Paginated REST response envelope. */
114
+ type Page<T> = ResultEnvelope<T[]> & {
115
+ pagination: CursorPagination;
116
+ };
117
+ /** Single item yielded by SDK page iterators, including its page metadata. */
118
+ type PageItem<T> = {
119
+ item: T;
120
+ freshness: Freshness;
121
+ pagination: CursorPagination;
122
+ diagnostics?: DiagnosticsEnvelope;
123
+ };
124
+ /** Paginated trade event response grouped under a trade id. */
125
+ type TradeEventsPage = ResultEnvelope<{
126
+ tradeId: TradeId;
127
+ events: TradeEvent[];
128
+ }> & {
129
+ pagination: CursorPagination;
130
+ };
131
+ /** Normalized market availability status. */
132
+ type MarketStatus = "active" | "paused" | "done" | "unknown";
133
+ /** Normalized position side. */
134
+ type PositionSide = "long" | "short";
135
+ /** Normalized order lifecycle status. */
136
+ type OrderStatus = "pending_execution" | "timeout_available" | "executed" | "canceled" | "timed_out" | "unknown";
137
+ /** Normalized order action. */
138
+ type OrderAction = "open" | "close" | "remove_collateral" | "unknown";
139
+ /** Normalized order type. */
140
+ type OrderType = "market" | "limit" | "stop" | "automation" | "remove_collateral" | "unknown";
141
+ /** Raw protocol market state exposed for parity/debugging use cases. */
142
+ type MarketRawState = {
143
+ accPerOiLong: SignedP18;
144
+ accPerOiShort: SignedP18;
145
+ lastFundingRate: SignedP18;
146
+ maxFundingFeePerBlock: UnsignedP18;
147
+ springFactor: UnsignedP18;
148
+ hillInflectionPoint: SignedP18;
149
+ hillPosScale: ScaleP2;
150
+ hillNegScale: ScaleP2;
151
+ sFactorUpScaleP: ScaleP2;
152
+ sFactorDownScaleP: ScaleP2;
153
+ lastOiDelta: SignedP6;
154
+ lastUpdateBlock: bigint;
155
+ asOfBlock: bigint;
156
+ lastTradePrice: Price;
157
+ oiLong: UnsignedP18;
158
+ oiShort: UnsignedP18;
159
+ oiCap: UsdP6;
160
+ groupCollateralLong?: Collateral;
161
+ groupCollateralShort?: Collateral;
162
+ };
163
+ /** Market-level trading limits used by preflight and math helpers. */
164
+ type MarketConstraints = {
165
+ minLeverage: Leverage;
166
+ maxLeverage: Leverage;
167
+ makerMaxLeverage: Leverage;
168
+ minLevPosition: Collateral;
169
+ groupMaxCollateral: Collateral;
170
+ maxAllowedCollateral?: Collateral;
171
+ maxNegativePnlOnOpenP?: WholePercent;
172
+ maxSlP?: WholePercent;
173
+ liqMarginThresholdP?: WholePercent;
174
+ marketOrdersTimeout: bigint;
175
+ maxTradesPerPair: bigint;
176
+ maxPendingMarketOrders: bigint;
177
+ };
178
+ /** Opening or closing fee schedule for a market. */
179
+ type MarketFeeSchedule = {
180
+ makerFeeP: FeePercent;
181
+ takerFeeP: FeePercent;
182
+ usageFeeP: FeePercent;
183
+ utilizationThresholdP: Precision2Percent;
184
+ makerMaxLeverage: Leverage;
185
+ vaultFeePercent: WholePercent;
186
+ };
187
+ /** Contract addresses backing a market. */
188
+ type MarketContracts = {
189
+ trading: Address;
190
+ tradingStorage: Address;
191
+ pairsStorage: Address;
192
+ pairInfos: Address;
193
+ };
194
+ /** Static market metadata plus current constraints and fee schedules. */
195
+ type Market = {
196
+ pairIndex: PairIndex;
197
+ groupIndex: number;
198
+ feeIndex: number;
199
+ symbol: string;
200
+ baseSymbol: string;
201
+ quoteSymbol: string;
202
+ priceAsset: string;
203
+ feedId: Hex;
204
+ priceFeed: string;
205
+ isListed: boolean;
206
+ isPaused: boolean;
207
+ isDone: boolean;
208
+ status: MarketStatus;
209
+ rawStatus?: string;
210
+ oracleFeeWei: bigint;
211
+ contracts: MarketContracts;
212
+ constraints: MarketConstraints;
213
+ fees: {
214
+ opening: MarketFeeSchedule;
215
+ closing: MarketFeeSchedule;
216
+ };
217
+ };
218
+ /** Dynamic market state such as open interest, funding, and volume. */
219
+ type MarketState = {
220
+ pairIndex: PairIndex;
221
+ longOpenInterest: Notional;
222
+ shortOpenInterest: Notional;
223
+ oiMax: Notional;
224
+ oiDelta: Ratio;
225
+ lastFunding1h: Ratio;
226
+ lastFunding8h: Ratio;
227
+ lastFunding24h: Ratio;
228
+ lastFunding1y: Ratio;
229
+ fundingFeeLong: Ratio;
230
+ fundingFeeShort: Ratio;
231
+ fundingFeeRate: Ratio;
232
+ fundingRate1h: Ratio;
233
+ fundingRate8h: Ratio;
234
+ fundingRate24h: Ratio;
235
+ fundingRate1y: Ratio;
236
+ cumulativeVolume: Notional;
237
+ volume24h: Notional;
238
+ rawState?: MarketRawState;
239
+ };
240
+ /** Latest known price for an asset/product. */
241
+ type PriceHead = {
242
+ asset: string;
243
+ productId: string;
244
+ price: Price;
245
+ timestamp: IsoTimestamp;
246
+ };
247
+ /** Price query selector by asset name, pair index, or both. */
248
+ type PriceSelector = {
249
+ asset: string;
250
+ pairIndex?: PairIndex;
251
+ } | {
252
+ pairIndex: PairIndex;
253
+ asset?: string;
254
+ };
255
+ /** Candle query parameters. */
256
+ type CandleParams = PriceSelector & {
257
+ interval: string;
258
+ from: TimeInput;
259
+ to?: TimeInput;
260
+ };
261
+ /** OHLC candle returned by the REST price API. */
262
+ type Candle = {
263
+ pairIndex?: PairIndex;
264
+ asset: string;
265
+ open: Price;
266
+ high: Price;
267
+ low: Price;
268
+ close?: Price;
269
+ headPrice?: Price;
270
+ headTime?: IsoTimestamp;
271
+ openTime: IsoTimestamp;
272
+ closeTime?: IsoTimestamp;
273
+ };
274
+ /** Tick query parameters. */
275
+ type PriceTickParams = PriceSelector & {
276
+ from?: TimeInput;
277
+ to?: TimeInput;
278
+ };
279
+ /** Price tick returned by the REST price API. */
280
+ type PriceTick = {
281
+ pairIndex?: PairIndex;
282
+ asset: string;
283
+ productId: string;
284
+ price: Price;
285
+ publishId?: string;
286
+ blockNumber: bigint;
287
+ txIndex: bigint;
288
+ logIndex: bigint;
289
+ timestamp: IsoTimestamp;
290
+ };
291
+ /** Reason an account position is pending or not directly actionable. */
292
+ type PendingPositionReason = "being_market_closed" | "remove_collateral_pending" | "trigger_pending" | "read_model_not_ready" | "unknown_pending_mutation";
293
+ /** Account position that is currently open and has a concrete trade slot. */
294
+ type OpenAccountPosition = {
295
+ kind: "open_position";
296
+ rawKind?: string;
297
+ wallet: Address;
298
+ pairIndex: PairIndex;
299
+ index: TradeIndex;
300
+ tradeId: TradeId;
301
+ side: PositionSide;
302
+ collateral: Collateral;
303
+ initialCollateral?: Collateral;
304
+ initialAccFundingRaw?: SignedP18;
305
+ leverage: Leverage;
306
+ notional?: Notional;
307
+ openPrice: Price;
308
+ takeProfit?: Price;
309
+ stopLoss?: Price;
310
+ openedAt?: IsoTimestamp;
311
+ pendingReasons: PendingPositionReason[];
312
+ verifiedRef?: VerifiedPositionRef;
313
+ };
314
+ /** Account position-like mutation that has not settled into an open position yet. */
315
+ type PendingAccountPosition = {
316
+ kind: "pending_position";
317
+ rawKind: string;
318
+ wallet: Address;
319
+ orderId?: OrderId;
320
+ eventType: string;
321
+ pairIndex?: PairIndex;
322
+ index?: TradeIndex;
323
+ tradeId?: TradeId;
324
+ side?: PositionSide;
325
+ collateral?: Collateral;
326
+ initialCollateral?: Collateral;
327
+ leverage?: Leverage;
328
+ notional?: Notional;
329
+ openPrice?: Price;
330
+ wantedPrice?: Price;
331
+ takeProfit?: Price;
332
+ stopLoss?: Price;
333
+ targetTradeId?: TradeId;
334
+ closePercentage?: ClosePercent;
335
+ removeAmount?: Collateral;
336
+ limitIndex?: TriggerOrderIndex;
337
+ txHash?: Hex;
338
+ timestamp?: IsoTimestamp;
339
+ pendingReasons: PendingPositionReason[];
340
+ };
341
+ /** Account position view containing both open and pending entries. */
342
+ type AccountPosition = OpenAccountPosition | PendingAccountPosition;
343
+ /** Fully identified position reference returned by account read models. */
344
+ type PositionRef = {
345
+ wallet: Address;
346
+ pairIndex: PairIndex;
347
+ index: TradeIndex;
348
+ tradeId: TradeId;
349
+ };
350
+ /** Lookup reference for resolving a single account position. */
351
+ type AccountPositionLookupRef = {
352
+ pairIndex: PairIndex;
353
+ index: TradeIndex;
354
+ tradeId?: TradeId;
355
+ };
356
+ /** Fully resolved account position lookup reference. */
357
+ type AccountPositionResolvedRef = {
358
+ pairIndex: PairIndex;
359
+ index: TradeIndex;
360
+ tradeId: TradeId;
361
+ };
362
+ /** Batch lookup reference; currently requires fully resolved trade identity. */
363
+ type AccountPositionBatchLookupRef = AccountPositionResolvedRef;
364
+ /** Result status for an account position lookup. */
365
+ type AccountPositionLookupStatus = "found" | "missing" | "pending";
366
+ /** Result of resolving an account position reference against read models. */
367
+ type AccountPositionLookupResult = {
368
+ ref: AccountPositionResolvedRef;
369
+ status: AccountPositionLookupStatus;
370
+ position?: AccountPosition;
371
+ pendingReasons: PendingPositionReason[];
372
+ };
373
+ /** Account order lifecycle summary from read models. */
374
+ type AccountOrder = {
375
+ orderId: OrderId;
376
+ lifecycleKey: string;
377
+ wallet: Address;
378
+ pairIndex?: PairIndex;
379
+ action: OrderAction;
380
+ rawAction?: string;
381
+ orderType: OrderType;
382
+ rawOrderType?: string;
383
+ triggerOrderType?: "limit" | "stop";
384
+ rawTriggerOrderType?: string;
385
+ status: OrderStatus;
386
+ rawStatus?: string;
387
+ isPending: boolean;
388
+ isCancelled: boolean;
389
+ timeoutAvailable?: boolean;
390
+ timeoutBlock?: bigint;
391
+ tradeId?: TradeId;
392
+ positionRef: PositionRef | null;
393
+ limitIndex?: TriggerOrderIndex;
394
+ initiatedBlock?: bigint;
395
+ executedBlock?: bigint;
396
+ initiatedEventType?: string;
397
+ terminalEventType?: string;
398
+ latestEventType?: string;
399
+ initiatedTxHash?: Hex;
400
+ executedTxHash?: Hex;
401
+ cancelReason?: number;
402
+ timestamp: IsoTimestamp;
403
+ verifiedRef?: VerifiedOpenTriggerOrderRef;
404
+ };
405
+ /** Open limit/stop order narrowed to the fields needed for trigger updates/cancels. */
406
+ type OpenTriggerAccountOrder = AccountOrder & {
407
+ lifecycleKey: string;
408
+ pairIndex: PairIndex;
409
+ action: "open";
410
+ orderType: "limit";
411
+ triggerOrderType: "limit" | "stop";
412
+ status: "pending_execution";
413
+ isPending: true;
414
+ limitIndex: TriggerOrderIndex;
415
+ initiatedEventType: string;
416
+ initiatedTxHash: Hex;
417
+ };
418
+ /** Historical or current account trade entry. */
419
+ type AccountTrade = {
420
+ wallet: Address;
421
+ pairIndex: PairIndex;
422
+ index: TradeIndex;
423
+ tradeId: TradeId;
424
+ side: PositionSide;
425
+ openPrice: Price;
426
+ closePrice?: Price;
427
+ initialCollateral: Collateral;
428
+ collateral: Collateral;
429
+ closingCollateral?: Collateral;
430
+ leverage: Leverage;
431
+ notional: Notional;
432
+ openEventType: string;
433
+ closeReason?: string;
434
+ percentProfit?: DecimalString;
435
+ realizedPnl?: SignedCollateral;
436
+ collateralSentToTrader?: Collateral;
437
+ fundingFee?: SignedCollateral;
438
+ status: string;
439
+ limitIndex?: TriggerOrderIndex;
440
+ openTxHash?: Hex;
441
+ closeTxHash?: Hex;
442
+ openedAt: IsoTimestamp;
443
+ closedAt?: IsoTimestamp;
444
+ timestamp: IsoTimestamp;
445
+ };
446
+ /** Additional state used to reconcile remove-collateral order execution. */
447
+ type RemoveCollateralTracking = {
448
+ requestedCollateral?: Collateral;
449
+ executedCollateral?: Collateral;
450
+ adjustedAmountSource: "order_response" | "receipt_event" | "timeline_event" | "unavailable";
451
+ };
452
+ /** Full lifecycle view of a tracked order. */
453
+ type OrderLifecycle = {
454
+ orderId: OrderId;
455
+ wallet: Address;
456
+ pairIndex?: PairIndex;
457
+ action: OrderAction;
458
+ rawAction?: string;
459
+ orderType: OrderType;
460
+ rawOrderType?: string;
461
+ status: OrderStatus;
462
+ rawStatus?: string;
463
+ isPending: boolean;
464
+ isCancelled: boolean;
465
+ timeoutAvailable: boolean;
466
+ timeoutBlock?: bigint;
467
+ tradeId?: TradeId;
468
+ initiatedTradeId?: TradeId;
469
+ terminalTradeId?: TradeId;
470
+ positionRef: PositionRef | null;
471
+ initiatedEventType?: string;
472
+ terminalEventType?: string;
473
+ latestEventType?: string;
474
+ limitIndex?: TriggerOrderIndex;
475
+ initiatedTxHash?: Hex;
476
+ executedTxHash?: Hex;
477
+ initiatedBlock?: bigint;
478
+ executedBlock?: bigint;
479
+ initiatedTxIndex?: bigint;
480
+ initiatedLogIndex?: bigint;
481
+ executedTxIndex?: bigint;
482
+ executedLogIndex?: bigint;
483
+ timestamp: IsoTimestamp;
484
+ cancelReason?: number;
485
+ removeCollateral?: RemoveCollateralTracking;
486
+ };
487
+ /** Timeline event for a trade. */
488
+ type TradeEvent = {
489
+ id: bigint;
490
+ tradeId: TradeId;
491
+ time: IsoTimestamp;
492
+ eventType: string;
493
+ blockNumber: bigint;
494
+ txIndex: bigint;
495
+ logIndex: bigint;
496
+ txHash?: Hex;
497
+ orderId?: OrderId;
498
+ collateral?: Collateral;
499
+ leverage?: Leverage;
500
+ openPrice?: Price;
501
+ closePrice?: Price;
502
+ takeProfit?: Price;
503
+ stopLoss?: Price;
504
+ percentageClosed?: ClosePercent;
505
+ percentProfit?: DecimalString;
506
+ collateralSentToTrader?: Collateral;
507
+ pnlDelta?: SignedCollateral;
508
+ topUpAmount?: Collateral;
509
+ removeAmount?: Collateral;
510
+ newLeverage?: Leverage;
511
+ wantedPrice?: Price;
512
+ cancelReason?: number;
513
+ };
514
+ /** Machine-readable reason the REST API is degraded or not fully ready. */
515
+ type ApiDegradedReason = "rpc_unavailable" | "postgres_unavailable" | "indexer_lagging" | "lag_above_threshold" | "chain_head_behind_indexed_block" | "read_models_not_ready" | "market_metadata_not_ready" | "market_state_not_ready" | string;
516
+ /** REST API health and readiness status. */
517
+ type ApiStatus = {
518
+ network: string;
519
+ apiTime: IsoTimestamp;
520
+ chainHeadBlock?: bigint;
521
+ indexedBlock?: bigint;
522
+ lagBlocks?: bigint;
523
+ rpcAvailable: boolean;
524
+ postgresAvailable: boolean;
525
+ cacheAvailable: boolean;
526
+ degraded: boolean;
527
+ degradedReasons: ApiDegradedReason[];
528
+ apiSchemaHash: string;
529
+ ok: boolean;
530
+ readiness: Record<string, "ready" | "not_ready" | "degraded">;
531
+ };
532
+
533
+ export { type AccountOrder as A, type TradeEventsPage as B, type CursorPagination as C, type TradeEvent as D, type AccountPositionLookupStatus as E, type Freshness as F, type AccountPositionResolvedRef as G, type ApiDegradedReason as H, type MarketConstraints as I, type MarketContracts as J, type MarketFeeSchedule as K, type MarketRawState as L, type Market as M, type MarketStatus as N, type OpenAccountPosition as O, type PendingPositionReason as P, type OrderAction as Q, type ReadOptions as R, type OrderStatus as S, type TriggerReceiptParseOptions as T, type UnsafeTriggerOrderSlot as U, type VerifiedPositionRef as V, type OrderType as W, type PendingAccountPosition as X, type PositionRef as Y, type PositionSide as Z, type PriceSelector as _, type ReceiptVerifiedOpenTriggerOrderRef as a, type VerifiedOpenTriggerOrderRef as b, type OpenTriggerAccountOrder as c, type ApiVerifiedOpenTriggerOrderRef as d, type ResultEnvelope as e, type VaultHistoryPageOptions as f, type ApiStatus as g, type AccountPosition as h, type VerifiedPositionRefInput as i, type VerifiedTriggerOrderRef as j, type OrderLifecycle as k, type RemoveCollateralTracking as l, type AccountTrade as m, type MarketState as n, type PriceHead as o, type CandleParams as p, type Candle as q, type PriceTickParams as r, type PageOptions as s, type Page as t, type PriceTick as u, verifiedPositionRef as v, type PageItem as w, type AccountPositionLookupRef as x, type AccountPositionLookupResult as y, type AccountPositionBatchLookupRef as z };
@@ -0,0 +1,118 @@
1
+ import { V as VerifiedPositionRef, R as ReadOptions, P as PendingPositionReason, F as Freshness } from './types-DQft82W7.cjs';
2
+ import { DiagnosticsEnvelope, DomfiError } from './errors.cjs';
3
+ import { Collateral, Leverage, Price, SignedCollateral, IsoTimestamp, Address, PairIndex, TradeIndex } from './units.cjs';
4
+
5
+ /** Position slot without a verified trade id, useful for display-only fallback reads. */
6
+ type UnverifiedPositionSlot = {
7
+ wallet: Address;
8
+ pairIndex: PairIndex;
9
+ index: TradeIndex;
10
+ };
11
+ /** Source used for the mark price in a valuation snapshot. */
12
+ type MarkSource = "onchain_oracle" | "rest_fallback" | "unavailable";
13
+ /** Preferred mark price source for valuation reads. */
14
+ type MarkSourcePreference = Exclude<MarkSource, "unavailable"> | "auto";
15
+ /** Freshness metadata for valuation snapshots. */
16
+ type SnapshotFreshness = {
17
+ valuationBlock?: bigint;
18
+ valuationBlockTimestamp?: IsoTimestamp;
19
+ markTimestampMs?: bigint;
20
+ oracleTimestampMs?: bigint;
21
+ apiFreshness?: Freshness;
22
+ markApiFreshness?: Freshness;
23
+ markSource: MarkSource;
24
+ isStale: boolean;
25
+ };
26
+ /** Current valuation view for a verified position or unverified slot. */
27
+ type PositionSnapshot = {
28
+ status: "live";
29
+ position: VerifiedPositionRef;
30
+ collateral: Collateral;
31
+ leverage: Leverage;
32
+ liquidationPrice?: Price;
33
+ fundingFee: SignedCollateral;
34
+ markPrice: Price;
35
+ markSource: MarkSource;
36
+ markValue: Collateral;
37
+ unrealizedPnl: SignedCollateral;
38
+ actionability: "actionable" | "pending_mutation" | "read_only";
39
+ pendingReasons: PendingPositionReason[];
40
+ freshness: SnapshotFreshness;
41
+ } | {
42
+ status: "closed_or_stale";
43
+ position: VerifiedPositionRef;
44
+ reason: "gone" | "tradeId_mismatch" | "being_closed" | "pending_mutation" | "read_model_not_ready";
45
+ } | {
46
+ status: "unverified_slot";
47
+ slot: UnverifiedPositionSlot;
48
+ displayOnly: true;
49
+ markSource: MarkSource;
50
+ freshness: SnapshotFreshness;
51
+ };
52
+ /** Snapshot variant returned for an unverified position slot. */
53
+ type UnverifiedSlotSnapshot = Extract<PositionSnapshot, {
54
+ status: "unverified_slot";
55
+ }>;
56
+ /** Snapshot variants returned for verified position references. */
57
+ type VerifiedPositionSnapshot = Exclude<PositionSnapshot, UnverifiedSlotSnapshot>;
58
+ /** Options for single valuation reads. */
59
+ type SnapshotOptions = ReadOptions & {
60
+ blockTag?: bigint | "latest";
61
+ markSource?: MarkSourcePreference;
62
+ };
63
+ /** Options for batched valuation reads. */
64
+ type BulkSnapshotOptions = SnapshotOptions & {
65
+ chunkSize?: number;
66
+ };
67
+ /** Options for valuation watch loops. */
68
+ type WatchSnapshotOptions = SnapshotOptions & {
69
+ intervalMs?: number;
70
+ emitImmediately?: boolean;
71
+ };
72
+ /** Event emitted to valuation watch callbacks. */
73
+ type WatchEvent<T> = {
74
+ type: "snapshot";
75
+ data: T;
76
+ diagnostics?: DiagnosticsEnvelope;
77
+ } | {
78
+ type: "error";
79
+ error: DomfiError;
80
+ diagnostics?: DiagnosticsEnvelope;
81
+ };
82
+ /** Callback invoked for valuation watch snapshots and recoverable errors. */
83
+ type WatchCallback<T> = (event: WatchEvent<T>) => void;
84
+ /** Handle returned by valuation watch methods. */
85
+ type WatchHandle = {
86
+ stop(): void;
87
+ };
88
+ /** Valuation client with REST-assisted verified position reads. */
89
+ type ValuationClient = {
90
+ /** Clears cached market/config data used by valuation reads. */
91
+ clearConfigCache(): void;
92
+ /**
93
+ * @throws ReadModelNotReadyError when API discovery read models are not ready.
94
+ * @throws ValidationError when position refs, REST payloads, or onchain reads fail validation.
95
+ * @throws TimeoutError or AbortError when REST/RPC reads are timed out or aborted.
96
+ * @throws ApiError, TransportError, or MissingPublicClientError for dependency and transport failures.
97
+ */
98
+ positionSnapshot(position: VerifiedPositionRef, opts?: SnapshotOptions): Promise<VerifiedPositionSnapshot>;
99
+ /** @throws ValidationError, TimeoutError, AbortError, TransportError, or MissingPublicClientError. */
100
+ unverifiedSlotSnapshot(slot: UnverifiedPositionSlot, opts?: SnapshotOptions): Promise<UnverifiedSlotSnapshot>;
101
+ /** @throws ReadModelNotReadyError, ValidationError, TimeoutError, AbortError, ApiError, TransportError, or MissingPublicClientError. */
102
+ positionSnapshots(positions: VerifiedPositionRef[], opts?: BulkSnapshotOptions): Promise<VerifiedPositionSnapshot[]>;
103
+ /** @throws ValidationError when watch options or callback arguments are invalid. Runtime read failures are emitted as error events. */
104
+ watchPositionSnapshot(position: VerifiedPositionRef, cb: WatchCallback<VerifiedPositionSnapshot>): WatchHandle;
105
+ watchPositionSnapshot(position: VerifiedPositionRef, opts: WatchSnapshotOptions, cb: WatchCallback<VerifiedPositionSnapshot>): WatchHandle;
106
+ /** @throws ValidationError when watch options or callback arguments are invalid. Runtime read failures are emitted as error events. */
107
+ watchPositionSnapshots(positions: VerifiedPositionRef[], cb: WatchCallback<VerifiedPositionSnapshot[]>): WatchHandle;
108
+ watchPositionSnapshots(positions: VerifiedPositionRef[], opts: WatchSnapshotOptions, cb: WatchCallback<VerifiedPositionSnapshot[]>): WatchHandle;
109
+ };
110
+ /** Valuation client available when REST API access is disabled. */
111
+ type ValuationClientNoApi = {
112
+ /** Clears cached market/config data used by valuation reads. */
113
+ clearConfigCache(): void;
114
+ /** @throws ValidationError, TimeoutError, AbortError, TransportError, or MissingPublicClientError. */
115
+ unverifiedSlotSnapshot(slot: UnverifiedPositionSlot, opts?: SnapshotOptions): Promise<UnverifiedSlotSnapshot>;
116
+ };
117
+
118
+ export type { BulkSnapshotOptions as B, MarkSource as M, PositionSnapshot as P, SnapshotFreshness as S, UnverifiedPositionSlot as U, ValuationClient as V, WatchCallback as W, MarkSourcePreference as a, SnapshotOptions as b, UnverifiedSlotSnapshot as c, ValuationClientNoApi as d, VerifiedPositionSnapshot as e, WatchEvent as f, WatchHandle as g, WatchSnapshotOptions as h };