@lifi/perps-types 3.3.2 → 4.0.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.
Files changed (82) hide show
  1. package/dist/cjs/account.d.ts +11 -2
  2. package/dist/cjs/account.d.ts.map +1 -1
  3. package/dist/cjs/action.d.ts +1 -0
  4. package/dist/cjs/action.d.ts.map +1 -1
  5. package/dist/cjs/asset.d.ts.map +1 -1
  6. package/dist/cjs/enums.d.ts +5 -0
  7. package/dist/cjs/enums.d.ts.map +1 -1
  8. package/dist/cjs/enums.js +7 -1
  9. package/dist/cjs/enums.js.map +1 -1
  10. package/dist/cjs/errors.d.ts.map +1 -1
  11. package/dist/cjs/market.d.ts +4 -0
  12. package/dist/cjs/market.d.ts.map +1 -1
  13. package/dist/cjs/primitives.d.ts.map +1 -1
  14. package/dist/cjs/providers.d.ts.map +1 -1
  15. package/dist/cjs/subscriptions.d.ts.map +1 -1
  16. package/dist/cjs/typedData.d.ts.map +1 -1
  17. package/dist/cjs/vote.d.ts.map +1 -1
  18. package/dist/cjs/vote.js.map +1 -1
  19. package/dist/esm/account.d.ts +223 -32
  20. package/dist/esm/account.d.ts.map +1 -1
  21. package/dist/esm/action.d.ts +205 -37
  22. package/dist/esm/action.d.ts.map +1 -1
  23. package/dist/esm/asset.d.ts +1 -4
  24. package/dist/esm/asset.d.ts.map +1 -1
  25. package/dist/esm/enums.d.ts +43 -20
  26. package/dist/esm/enums.d.ts.map +1 -1
  27. package/dist/esm/enums.js +43 -19
  28. package/dist/esm/enums.js.map +1 -1
  29. package/dist/esm/errors.d.ts +6 -1
  30. package/dist/esm/errors.d.ts.map +1 -1
  31. package/dist/esm/market.d.ts +57 -15
  32. package/dist/esm/market.d.ts.map +1 -1
  33. package/dist/esm/primitives.d.ts +12 -2
  34. package/dist/esm/primitives.d.ts.map +1 -1
  35. package/dist/esm/providers.d.ts +19 -6
  36. package/dist/esm/providers.d.ts.map +1 -1
  37. package/dist/esm/quote.d.ts +2 -2
  38. package/dist/esm/quote.d.ts.map +1 -1
  39. package/dist/esm/subscriptions.d.ts +27 -19
  40. package/dist/esm/subscriptions.d.ts.map +1 -1
  41. package/dist/esm/typedData.d.ts +15 -5
  42. package/dist/esm/typedData.d.ts.map +1 -1
  43. package/dist/esm/vote.d.ts +1 -3
  44. package/dist/esm/vote.d.ts.map +1 -1
  45. package/dist/esm/vote.js.map +1 -1
  46. package/dist/types/account.d.ts +223 -32
  47. package/dist/types/account.d.ts.map +1 -1
  48. package/dist/types/action.d.ts +205 -37
  49. package/dist/types/action.d.ts.map +1 -1
  50. package/dist/types/asset.d.ts +1 -4
  51. package/dist/types/asset.d.ts.map +1 -1
  52. package/dist/types/enums.d.ts +43 -20
  53. package/dist/types/enums.d.ts.map +1 -1
  54. package/dist/types/errors.d.ts +6 -1
  55. package/dist/types/errors.d.ts.map +1 -1
  56. package/dist/types/market.d.ts +57 -15
  57. package/dist/types/market.d.ts.map +1 -1
  58. package/dist/types/primitives.d.ts +12 -2
  59. package/dist/types/primitives.d.ts.map +1 -1
  60. package/dist/types/providers.d.ts +19 -6
  61. package/dist/types/providers.d.ts.map +1 -1
  62. package/dist/types/quote.d.ts +2 -2
  63. package/dist/types/quote.d.ts.map +1 -1
  64. package/dist/types/subscriptions.d.ts +27 -19
  65. package/dist/types/subscriptions.d.ts.map +1 -1
  66. package/dist/types/typedData.d.ts +15 -5
  67. package/dist/types/typedData.d.ts.map +1 -1
  68. package/dist/types/vote.d.ts +1 -3
  69. package/dist/types/vote.d.ts.map +1 -1
  70. package/package.json +1 -1
  71. package/src/account.ts +225 -37
  72. package/src/action.ts +205 -37
  73. package/src/asset.ts +1 -4
  74. package/src/enums.ts +44 -20
  75. package/src/errors.ts +6 -1
  76. package/src/market.ts +69 -16
  77. package/src/primitives.ts +12 -2
  78. package/src/providers.ts +19 -6
  79. package/src/quote.ts +2 -2
  80. package/src/subscriptions.ts +27 -19
  81. package/src/typedData.ts +15 -5
  82. package/src/vote.ts +1 -3
package/src/account.ts CHANGED
@@ -10,44 +10,97 @@ import type {
10
10
  OrderType,
11
11
  PositionSide,
12
12
  } from './enums.js'
13
- import type { MarketDisplay } from './market.js'
13
+ import type { MarketDisplay, PerpsMarketDisplay } from './market.js'
14
14
  import type { Address } from './primitives.js'
15
15
 
16
- /** @public */
16
+ /**
17
+ * Maker and taker fee rates for the account's current venue tier.
18
+ * Values are decimal fractions represented as strings (for example, `"0.0002"`).
19
+ *
20
+ * @public
21
+ */
17
22
  export interface FeeTier {
23
+ /** Decimal fraction charged to maker fills, represented as a string. */
18
24
  maker: string
25
+ /** Decimal fraction charged to taker fills, represented as a string. */
19
26
  taker: string
20
27
  }
21
28
 
22
- /** @public */
29
+ /**
30
+ * Normalized open perpetual position with prices, margin, and PnL expressed as
31
+ * decimal strings to preserve provider precision.
32
+ *
33
+ * @public
34
+ */
23
35
  export interface Position {
24
- market: MarketDisplay
36
+ market: PerpsMarketDisplay
25
37
  side: PositionSide
38
+ /** Position quantity in base-asset units. */
26
39
  size: string
40
+ /** Average entry price in quote-asset units. */
27
41
  entryPrice: string
42
+ /** Current provider mark price in quote-asset units. */
28
43
  markPrice: string
44
+ /** Estimated liquidation price in quote-asset units. */
29
45
  liquidationPrice: string
46
+ /** Unrealized PnL in quote-currency units. */
30
47
  unrealizedPnl: string
48
+ /** Position leverage as a numeric multiple. */
31
49
  leverage: number
50
+ /**
51
+ * Margin allocated and reserved by this position as a decimal string,
52
+ * excluding unrealized PnL.
53
+ */
32
54
  marginUsed: string
55
+ /**
56
+ * Exact initial margin the venue currently requires for this position.
57
+ * Unlike `leverage`, this decimal string is safe for risk calculations.
58
+ */
59
+ initialMarginRequirement: string
33
60
  marginMode: MarginMode
34
61
  }
35
62
 
36
- /** @public */
63
+ /**
64
+ * Exact provider-owned inputs for changing one position's dedicated margin.
65
+ * `undefined` from the provider means the position has no individual margin
66
+ * adjustment.
67
+ * @public
68
+ */
69
+ export interface PositionMarginConstraints {
70
+ /** Exact margin the venue requires this position to retain. */
71
+ minimumMarginRequirement: string
72
+ /** Smallest accepted margin amount, as an exact decimal string. */
73
+ amountIncrement: string
74
+ }
75
+
76
+ /**
77
+ * Normalized non-trigger order currently open at a provider.
78
+ *
79
+ * @public
80
+ */
37
81
  export interface OpenOrder {
38
82
  orderId: string
39
83
  market: MarketDisplay
40
84
  side: OrderSide
41
85
  type: OrderType
86
+ /** Remaining order quantity in base-asset units. */
42
87
  size: string
88
+ /** Limit/order price in quote-asset units. */
43
89
  price: string
90
+ /** Quantity already filled in base-asset units. */
44
91
  filledSize: string
45
92
  reduceOnly: boolean
46
93
  label?: string
94
+ /** ISO-8601 creation timestamp. */
47
95
  createdAt: string
48
96
  }
49
97
 
50
- /** @public */
98
+ /**
99
+ * Asset balance normalized across providers. `units` and `valueUsd` are
100
+ * decimal strings; `valueUsd` is the balance's USD valuation.
101
+ *
102
+ * @public
103
+ */
51
104
  export interface Balance {
52
105
  /** Which category/venue this balance sits in — references a {@link ProviderCategory}. */
53
106
  categoryId: string
@@ -63,7 +116,12 @@ export interface Balance {
63
116
  collateralWeight?: number
64
117
  }
65
118
 
66
- /** @public */
119
+ /**
120
+ * Account snapshot returned by a provider, including balances, positions,
121
+ * aggregate margin/PnL, and provider-specific configuration.
122
+ *
123
+ * @public
124
+ */
67
125
  export interface AccountResponse {
68
126
  provider: string
69
127
  address: Address
@@ -73,40 +131,77 @@ export interface AccountResponse {
73
131
  collateralBalances: Balance[]
74
132
  /** Open positions the snapshot already computed; equals the unfiltered `getPositions` output. */
75
133
  positions: Position[]
134
+ /** Margin reserved across the account, represented as a decimal string. */
76
135
  marginUsed: string
136
+ /** Unrealized account PnL, represented as a decimal string. */
77
137
  unrealizedPnl: string
78
138
  feeTier: FeeTier
79
139
  config: AccountConfig
80
140
  }
81
141
 
82
- /** @public */
142
+ /**
143
+ * Aggregate account values for a provider stream or response. Monetary values
144
+ * are decimal strings in USD.
145
+ *
146
+ * @public
147
+ */
83
148
  export interface AccountSummary {
149
+ /** Total account portfolio value in USD. */
84
150
  portfolioValue: string
151
+ /** Margin currently available for new orders in USD. */
85
152
  availableMargin: string
153
+ /** Margin currently reserved by open positions/orders in USD. */
86
154
  marginUsed: string
155
+ /** Aggregate unrealized PnL in USD. */
87
156
  unrealizedPnl: string
88
157
  }
89
158
 
90
- /** @public */
159
+ /**
160
+ * The user's complete venue-side settings for one market: the margin mode
161
+ * and display leverage the next order on it will use. A provider returns
162
+ * `undefined` when it cannot read both values.
163
+ * @public
164
+ */
165
+ export interface MarketSettings {
166
+ marginMode: MarginMode
167
+ leverage: number
168
+ }
169
+
170
+ /**
171
+ * Normalized take-profit or stop-loss order waiting for its trigger condition.
172
+ *
173
+ * @public
174
+ */
91
175
  export interface TriggerOrder {
92
176
  orderId: string
93
177
  market: MarketDisplay
94
178
  type: OrderType
179
+ /** Triggered quantity in base-asset units. */
95
180
  size: string
181
+ /** Price at which the trigger activates, in quote-asset units. */
96
182
  triggerPrice: string
183
+ /** Optional limit price submitted after activation, in quote-asset units. */
97
184
  limitPrice?: string
98
185
  label?: string
99
186
  createdAt: string
100
187
  }
101
188
 
102
- /** @public */
189
+ /**
190
+ * Paginated open-position response for one provider and account.
191
+ *
192
+ * @public
193
+ */
103
194
  export interface PositionsResponse {
104
195
  provider: string
105
196
  positions: Position[]
106
197
  pagination: Pagination
107
198
  }
108
199
 
109
- /** @public */
200
+ /**
201
+ * Paginated open-order response containing regular and trigger orders.
202
+ *
203
+ * @public
204
+ */
110
205
  export interface OrdersResponse {
111
206
  provider: string
112
207
  openOrders: OpenOrder[]
@@ -114,7 +209,11 @@ export interface OrdersResponse {
114
209
  pagination: Pagination
115
210
  }
116
211
 
117
- /** @public */
212
+ /**
213
+ * Normalized execution/fill record for an order.
214
+ *
215
+ * @public
216
+ */
118
217
  export interface Fill {
119
218
  id: string
120
219
  orderId: string
@@ -136,12 +235,17 @@ export interface Fill {
136
235
  startPosition?: string
137
236
  classification: FillClassification
138
237
  createdAt: string
139
- // Fully-resolved block-explorer URL for the settling on-chain tx. Absent when
140
- // the fill has no on-chain settlement tx.
238
+ /** Fully-resolved block-explorer URL for the settling on-chain tx. Absent when
239
+ * the fill has no on-chain settlement tx. */
141
240
  explorerLink?: string
142
241
  }
143
242
 
144
- /** @public */
243
+ /**
244
+ * Cursor pagination metadata. `cursor` and `nextUrl` are provider-specific
245
+ * continuation values and are absent when no further page exists.
246
+ *
247
+ * @public
248
+ */
145
249
  export interface Pagination {
146
250
  limit: number
147
251
  hasMore: boolean
@@ -149,44 +253,70 @@ export interface Pagination {
149
253
  nextUrl?: string
150
254
  }
151
255
 
152
- /** @public */
256
+ /**
257
+ * Paginated fill response for one provider and account.
258
+ *
259
+ * @public
260
+ */
153
261
  export interface FillsResponse {
154
262
  provider: string
155
263
  items: Fill[]
156
264
  pagination: Pagination
157
265
  }
158
266
 
159
- /** @public */
267
+ /**
268
+ * Common identity and timestamp fields shared by account activity records.
269
+ * `timestamp` is an ISO-8601 timestamp string.
270
+ *
271
+ * @public
272
+ */
160
273
  export interface BaseActivity {
161
274
  id: string
162
275
  provider: string
163
276
  timestamp: string
164
277
  }
165
278
 
166
- /** @public */
279
+ /**
280
+ * Account activity representing a completed deposit.
281
+ *
282
+ * @public
283
+ */
167
284
  export interface DepositActivity extends BaseActivity {
168
285
  type: ActivityType.DEPOSIT
169
286
  amount: string
170
- // Fully-resolved block-explorer URL for the on-chain deposit tx.
287
+ /** Fully-resolved block-explorer URL for the on-chain deposit tx. */
171
288
  explorerLink?: string
172
289
  }
173
290
 
174
- /** @public */
291
+ /**
292
+ * Account activity representing a completed withdrawal. `amount` and `fee`
293
+ * are decimal strings in the transferred asset's units.
294
+ *
295
+ * @public
296
+ */
175
297
  export interface WithdrawalActivity extends BaseActivity {
176
298
  type: ActivityType.WITHDRAWAL
177
299
  amount: string
178
300
  fee: string
179
- // Fully-resolved block-explorer URL for the on-chain withdrawal tx.
301
+ /** Fully-resolved block-explorer URL for the on-chain withdrawal tx. */
180
302
  explorerLink?: string
181
303
  }
182
304
 
183
- /** @public */
305
+ /**
306
+ * Position details attached to a liquidation activity.
307
+ *
308
+ * @public
309
+ */
184
310
  export interface LiquidatedPosition {
185
311
  market: MarketDisplay
186
312
  size: string
187
313
  }
188
314
 
189
- /** @public */
315
+ /**
316
+ * Account activity representing a liquidation event.
317
+ *
318
+ * @public
319
+ */
190
320
  export interface LiquidationActivity extends BaseActivity {
191
321
  type: ActivityType.LIQUIDATION
192
322
  liquidatedNotionalPosition: string
@@ -195,7 +325,12 @@ export interface LiquidationActivity extends BaseActivity {
195
325
  liquidatedPositions: LiquidatedPosition[]
196
326
  }
197
327
 
198
- /** @public */
328
+ /**
329
+ * Account activity representing a periodic funding payment. Amount and rate
330
+ * retain provider precision as decimal strings.
331
+ *
332
+ * @public
333
+ */
199
334
  export interface FundingActivity extends BaseActivity {
200
335
  type: ActivityType.FUNDING
201
336
  market: MarketDisplay
@@ -206,21 +341,30 @@ export interface FundingActivity extends BaseActivity {
206
341
 
207
342
  // At least one of `counterpartyAccountIndex` / `counterpartyAddress` is always
208
343
  // present; both may appear together.
209
- /** @public */
344
+ /**
345
+ * Account activity representing an inbound or outbound transfer. At least one
346
+ * counterparty identifier is required by the type-level union below.
347
+ *
348
+ * @public
349
+ */
210
350
  export type TransferActivity = BaseActivity & {
211
351
  type: ActivityType.TRANSFER
212
352
  direction: 'IN' | 'OUT'
213
353
  asset: string
214
354
  amount: string
215
355
  meta?: Record<string, unknown>
216
- // Fully-resolved block-explorer URL for the on-chain transfer tx.
356
+ /** Fully-resolved block-explorer URL for the on-chain transfer tx. */
217
357
  explorerLink?: string
218
358
  } & (
219
359
  | { counterpartyAccountIndex: number; counterpartyAddress?: string }
220
360
  | { counterpartyAccountIndex?: number; counterpartyAddress: string }
221
361
  )
222
362
 
223
- /** @public */
363
+ /**
364
+ * Discriminated union of all activity records returned by a provider.
365
+ *
366
+ * @public
367
+ */
224
368
  export type ActivityItem =
225
369
  | DepositActivity
226
370
  | WithdrawalActivity
@@ -228,7 +372,11 @@ export type ActivityItem =
228
372
  | FundingActivity
229
373
  | TransferActivity
230
374
 
231
- /** @public */
375
+ /**
376
+ * Paginated account-activity response for one provider and account.
377
+ *
378
+ * @public
379
+ */
232
380
  export interface ActivitiesResponse {
233
381
  provider: string
234
382
  items: ActivityItem[]
@@ -237,10 +385,19 @@ export interface ActivitiesResponse {
237
385
 
238
386
  // Account configuration state — typed `AccountResponse.config`.
239
387
 
240
- /** @public */
388
+ /**
389
+ * Provider-specific Hyperliquid agent configuration. The record contents are
390
+ * provider-defined and intentionally left opaque to the shared type package.
391
+ *
392
+ * @public
393
+ */
241
394
  export type HyperliquidAgent = Record<string, unknown>
242
395
 
243
- /** @public */
396
+ /**
397
+ * Hyperliquid builder-fee approval state for an account.
398
+ *
399
+ * @public
400
+ */
244
401
  export interface HyperliquidBuilderFeeApproval {
245
402
  builderAddress: string
246
403
  /** Basis points as a string. */
@@ -248,7 +405,11 @@ export interface HyperliquidBuilderFeeApproval {
248
405
  approved: boolean
249
406
  }
250
407
 
251
- /** @public */
408
+ /**
409
+ * Hyperliquid account configuration returned in {@link AccountResponse.config}.
410
+ *
411
+ * @public
412
+ */
252
413
  export interface HyperliquidAccountConfig {
253
414
  provider: 'hyperliquid'
254
415
  /** `null` means abstraction has never been set. */
@@ -257,7 +418,11 @@ export interface HyperliquidAccountConfig {
257
418
  builderFeeApproval?: HyperliquidBuilderFeeApproval
258
419
  }
259
420
 
260
- /** @public */
421
+ /**
422
+ * Lighter spot-asset collateral setting for a single asset.
423
+ *
424
+ * @public
425
+ */
261
426
  export interface LighterAssetCollateral {
262
427
  /** Provider-native spot asset id (matches `Asset.id`). */
263
428
  assetId: string
@@ -275,7 +440,12 @@ export interface LighterAssetCollateral {
275
440
  */
276
441
  export type LighterProviderKey = 'lighter' | 'lighter-rh'
277
442
 
278
- /** @public */
443
+ /**
444
+ * Lighter account configuration returned in {@link AccountResponse.config}.
445
+ * Numeric identifiers and account modes use the provider's wire values.
446
+ *
447
+ * @public
448
+ */
279
449
  export interface LighterAccountConfig {
280
450
  provider: LighterProviderKey
281
451
  accountIndex: number
@@ -306,7 +476,12 @@ export interface LighterAccountConfig {
306
476
  referralPresent: boolean
307
477
  }
308
478
 
309
- /** @public */
479
+ /**
480
+ * Ondo account/session configuration returned in {@link AccountResponse.config}.
481
+ * Expiry values are Unix timestamps in seconds.
482
+ *
483
+ * @public
484
+ */
310
485
  export interface OndoAccountConfig {
311
486
  provider: 'ondo'
312
487
  loggedIn: boolean
@@ -322,20 +497,33 @@ export interface OndoAccountConfig {
322
497
  depositAddress: string | null
323
498
  }
324
499
 
325
- /** @public */
500
+ /**
501
+ * Provider-specific account configuration discriminated by its `provider` key.
502
+ *
503
+ * @public
504
+ */
326
505
  export type AccountConfig =
327
506
  | HyperliquidAccountConfig
328
507
  | LighterAccountConfig
329
508
  | OndoAccountConfig
330
509
 
331
- /** @public */
510
+ /**
511
+ * Named account-configuration value exposed to clients.
512
+ *
513
+ * @public
514
+ */
332
515
  export interface AccountConfigValue {
333
516
  name: string
334
517
  /** `null` means no current value — consumers fall back to the descriptor default. */
335
518
  value: string | number | boolean | null
336
519
  }
337
520
 
338
- /** @public */
521
+ /**
522
+ * Account-configuration action and its available values, optionally including
523
+ * whether the setting is currently satisfied.
524
+ *
525
+ * @public
526
+ */
339
527
  export interface AccountConfigSetting {
340
528
  type: ActionType
341
529
  values: AccountConfigValue[]