@lifi/perps-types 18.0.0 → 19.0.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 (88) hide show
  1. package/dist/cjs/account.d.ts +63 -62
  2. package/dist/cjs/account.d.ts.map +1 -1
  3. package/dist/cjs/action.d.ts +17 -16
  4. package/dist/cjs/action.d.ts.map +1 -1
  5. package/dist/cjs/asset.d.ts +2 -1
  6. package/dist/cjs/asset.d.ts.map +1 -1
  7. package/dist/cjs/decimal.d.ts +4 -0
  8. package/dist/cjs/decimal.d.ts.map +1 -0
  9. package/dist/cjs/decimal.js +9 -0
  10. package/dist/cjs/decimal.js.map +1 -0
  11. package/dist/cjs/index.d.ts +1 -0
  12. package/dist/cjs/index.d.ts.map +1 -1
  13. package/dist/cjs/index.js +1 -0
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/market.d.ts +24 -23
  16. package/dist/cjs/market.d.ts.map +1 -1
  17. package/dist/cjs/portfolioHistory.d.ts +5 -4
  18. package/dist/cjs/portfolioHistory.d.ts.map +1 -1
  19. package/dist/cjs/providers.d.ts +6 -5
  20. package/dist/cjs/providers.d.ts.map +1 -1
  21. package/dist/cjs/quote.d.ts +7 -6
  22. package/dist/cjs/quote.d.ts.map +1 -1
  23. package/dist/cjs/referral.d.ts +4 -3
  24. package/dist/cjs/referral.d.ts.map +1 -1
  25. package/dist/cjs/referral.js.map +1 -1
  26. package/dist/cjs/subscriptions.d.ts +3 -1
  27. package/dist/cjs/subscriptions.d.ts.map +1 -1
  28. package/dist/esm/account.d.ts +63 -62
  29. package/dist/esm/account.d.ts.map +1 -1
  30. package/dist/esm/action.d.ts +17 -16
  31. package/dist/esm/action.d.ts.map +1 -1
  32. package/dist/esm/asset.d.ts +2 -1
  33. package/dist/esm/asset.d.ts.map +1 -1
  34. package/dist/esm/decimal.d.ts +23 -0
  35. package/dist/esm/decimal.d.ts.map +1 -0
  36. package/dist/esm/decimal.js +17 -0
  37. package/dist/esm/decimal.js.map +1 -0
  38. package/dist/esm/index.d.ts +1 -0
  39. package/dist/esm/index.d.ts.map +1 -1
  40. package/dist/esm/index.js +1 -0
  41. package/dist/esm/index.js.map +1 -1
  42. package/dist/esm/market.d.ts +30 -30
  43. package/dist/esm/market.d.ts.map +1 -1
  44. package/dist/esm/portfolioHistory.d.ts +5 -4
  45. package/dist/esm/portfolioHistory.d.ts.map +1 -1
  46. package/dist/esm/providers.d.ts +24 -11
  47. package/dist/esm/providers.d.ts.map +1 -1
  48. package/dist/esm/quote.d.ts +7 -6
  49. package/dist/esm/quote.d.ts.map +1 -1
  50. package/dist/esm/referral.d.ts +4 -3
  51. package/dist/esm/referral.d.ts.map +1 -1
  52. package/dist/esm/referral.js.map +1 -1
  53. package/dist/esm/subscriptions.d.ts +5 -1
  54. package/dist/esm/subscriptions.d.ts.map +1 -1
  55. package/dist/types/account.d.ts +63 -62
  56. package/dist/types/account.d.ts.map +1 -1
  57. package/dist/types/action.d.ts +17 -16
  58. package/dist/types/action.d.ts.map +1 -1
  59. package/dist/types/asset.d.ts +2 -1
  60. package/dist/types/asset.d.ts.map +1 -1
  61. package/dist/types/decimal.d.ts +23 -0
  62. package/dist/types/decimal.d.ts.map +1 -0
  63. package/dist/types/index.d.ts +1 -0
  64. package/dist/types/index.d.ts.map +1 -1
  65. package/dist/types/market.d.ts +30 -30
  66. package/dist/types/market.d.ts.map +1 -1
  67. package/dist/types/portfolioHistory.d.ts +5 -4
  68. package/dist/types/portfolioHistory.d.ts.map +1 -1
  69. package/dist/types/providers.d.ts +24 -11
  70. package/dist/types/providers.d.ts.map +1 -1
  71. package/dist/types/quote.d.ts +7 -6
  72. package/dist/types/quote.d.ts.map +1 -1
  73. package/dist/types/referral.d.ts +4 -3
  74. package/dist/types/referral.d.ts.map +1 -1
  75. package/dist/types/subscriptions.d.ts +5 -1
  76. package/dist/types/subscriptions.d.ts.map +1 -1
  77. package/package.json +1 -1
  78. package/src/account.ts +63 -62
  79. package/src/action.ts +17 -16
  80. package/src/asset.ts +3 -1
  81. package/src/decimal.ts +26 -0
  82. package/src/index.ts +1 -0
  83. package/src/market.ts +30 -30
  84. package/src/portfolioHistory.ts +6 -4
  85. package/src/providers.ts +24 -11
  86. package/src/quote.ts +7 -6
  87. package/src/referral.ts +4 -3
  88. package/src/subscriptions.ts +4 -1
package/src/account.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Asset, AssetDisplay } from './asset.js'
2
+ import type { DecimalString } from './decimal.js'
2
3
  import type {
3
4
  ActionType,
4
5
  ActivityType,
@@ -23,9 +24,9 @@ import type { Address, ProviderId } from './primitives.js'
23
24
  */
24
25
  export interface FeeTier {
25
26
  /** Decimal fraction charged to maker fills, represented as a string. */
26
- maker: string
27
+ maker: DecimalString
27
28
  /** Decimal fraction charged to taker fills, represented as a string. */
28
- taker: string
29
+ taker: DecimalString
29
30
  }
30
31
 
31
32
  /**
@@ -38,22 +39,22 @@ export interface Position {
38
39
  market: PerpsMarketDisplay
39
40
  side: PositionSide
40
41
  /** Position quantity in base-asset units. */
41
- size: string
42
+ size: DecimalString
42
43
  /** Average entry price in quote-asset units. */
43
- entryPrice: string
44
+ entryPrice: DecimalString
44
45
  /** Current provider mark price in quote-asset units. */
45
- markPrice: string
46
+ markPrice: DecimalString
46
47
  /** Estimated liquidation price in quote-asset units. */
47
- liquidationPrice: string
48
+ liquidationPrice: DecimalString
48
49
  /** Unrealized PnL in quote-currency units. */
49
- unrealizedPnl: string
50
+ unrealizedPnl: DecimalString
50
51
  /**
51
52
  * Funding this position accrued since it opened, in quote-currency units.
52
53
  * Positive means the account received funding and negative means the account
53
54
  * paid it, matching {@link FundingActivity} amounts. Every venue resets the
54
55
  * value when the position returns to flat.
55
56
  */
56
- accruedFunding: string
57
+ accruedFunding: DecimalString
57
58
  /** Position leverage as a numeric multiple. */
58
59
  leverage: number
59
60
  /**
@@ -62,12 +63,12 @@ export interface Position {
62
63
  * Hyperliquid isolated `marginUsed` includes the unrealized PnL of the
63
64
  * position; Lighter `allocated_margin` excludes it.
64
65
  */
65
- marginUsed: string
66
+ marginUsed: DecimalString
66
67
  /**
67
68
  * Exact initial margin the venue currently requires for this position.
68
69
  * Unlike `leverage`, this decimal string is safe for risk calculations.
69
70
  */
70
- initialMarginRequirement: string
71
+ initialMarginRequirement: DecimalString
71
72
  marginMode: MarginMode
72
73
  }
73
74
 
@@ -82,10 +83,10 @@ export interface OrderBase {
82
83
  status: OrderStatus
83
84
  /** Venue text for a REJECTED or CANCELLED order, when the venue gives one. */
84
85
  statusReason?: string
85
- originalSize: string
86
- remainingSize: string
87
- filledSize: string
88
- averagePrice?: string
86
+ originalSize: DecimalString
87
+ remainingSize: DecimalString
88
+ filledSize: DecimalString
89
+ averagePrice?: DecimalString
89
90
  reduceOnly: boolean
90
91
  /** Parent of a placement TP/SL leg or TWAP child; absent on position-level triggers. */
91
92
  parentOrderId?: string
@@ -98,7 +99,7 @@ export interface OrderBase {
98
99
  /** Market or limit order with a time-in-force policy. */
99
100
  export interface RegularOrder extends OrderBase {
100
101
  type: OrderType.MARKET | OrderType.LIMIT
101
- price?: string
102
+ price?: DecimalString
102
103
  timeInForce: TimeInForce
103
104
  expiresAt?: string
104
105
  }
@@ -110,9 +111,9 @@ export interface TriggerOrder extends OrderBase {
110
111
  | OrderType.STOP_LIMIT
111
112
  | OrderType.TAKE_PROFIT_MARKET
112
113
  | OrderType.TAKE_PROFIT_LIMIT
113
- triggerPrice: string
114
+ triggerPrice: DecimalString
114
115
  triggerCondition: TriggerCondition
115
- limitPrice?: string
116
+ limitPrice?: DecimalString
116
117
  }
117
118
 
118
119
  /** Time-weighted execution parent. */
@@ -135,18 +136,18 @@ export interface Balance {
135
136
  /** Which category/venue this balance sits in — references a {@link ProviderCategory}. */
136
137
  categoryId: string
137
138
  asset: Asset
138
- units: string
139
+ units: DecimalString
139
140
  /** USD value the SDK fills from the prices map; consumers render with zero math. */
140
- valueUsd: string
141
+ valueUsd: DecimalString
141
142
  /** USD price of one unit. Absent when the provider holds no price for the asset. */
142
- price?: string
143
+ price?: DecimalString
143
144
  /**
144
145
  * Part of `units` the venue releases from this category, as a decimal
145
146
  * string clamped to `[0, units]`. Every collateral row and every spot row
146
147
  * carries it. It is not the withdrawal ceiling: read
147
148
  * `PerpsClient.getWithdrawableBalances` for that.
148
149
  */
149
- transferable?: string
150
+ transferable?: DecimalString
150
151
  }
151
152
 
152
153
  /**
@@ -170,9 +171,9 @@ export interface AccountResponse {
170
171
  /** Open positions the snapshot already computed; equals the unfiltered `getPositions` output. */
171
172
  positions: Position[]
172
173
  /** Margin reserved across the account, represented as a decimal string. */
173
- marginUsed: string
174
+ marginUsed: DecimalString
174
175
  /** Unrealized account PnL, represented as a decimal string. */
175
- unrealizedPnl: string
176
+ unrealizedPnl: DecimalString
176
177
  feeTier: FeeTier
177
178
  config: AccountConfig
178
179
  }
@@ -185,13 +186,13 @@ export interface AccountResponse {
185
186
  */
186
187
  export interface AccountSummary {
187
188
  /** Total account portfolio value in USD. */
188
- portfolioValue: string
189
+ portfolioValue: DecimalString
189
190
  /** Margin currently available for new orders in USD. */
190
- availableMargin: string
191
+ availableMargin: DecimalString
191
192
  /** Margin currently reserved by open positions/orders in USD. */
192
- marginUsed: string
193
+ marginUsed: DecimalString
193
194
  /** Aggregate unrealized PnL in USD. */
194
- unrealizedPnl: string
195
+ unrealizedPnl: DecimalString
195
196
  }
196
197
 
197
198
  /**
@@ -208,9 +209,9 @@ export interface AvailableToTrade {
208
209
  /** The market's margin asset, which both amounts are denominated in. */
209
210
  asset: AssetDisplay
210
211
  /** Amount the account can still buy, represented as a decimal string. */
211
- buy: string
212
+ buy: DecimalString
212
213
  /** Amount the account can still sell, represented as a decimal string. */
213
- sell: string
214
+ sell: DecimalString
214
215
  }
215
216
 
216
217
  /**
@@ -251,7 +252,7 @@ export interface OrdersResponse {
251
252
  */
252
253
  export interface Fee {
253
254
  /** Decimal string in `asset`'s units. */
254
- amount: string
255
+ amount: DecimalString
255
256
  /**
256
257
  * Display symbol the fee is denominated in, resolved by the provider
257
258
  * adapter. Falls back to the venue's own asset id when the registry knows no
@@ -276,10 +277,10 @@ export interface Fill {
276
277
  * Hyperliquid taker fill, which may be a market or an aggressive limit order).
277
278
  */
278
279
  type?: OrderType
279
- size: string
280
- price: string
280
+ size: DecimalString
281
+ price: DecimalString
281
282
  liquidity: LiquidityRole
282
- filledSize?: string
283
+ filledSize?: DecimalString
283
284
  /** Absent when the venue reports no fee for the fill. */
284
285
  fee?: Fee
285
286
  /**
@@ -300,8 +301,8 @@ export interface Fill {
300
301
  * a sentinel value.
301
302
  */
302
303
  leverage?: number
303
- realizedPnl?: string | null
304
- startPosition?: string
304
+ realizedPnl?: DecimalString | null
305
+ startPosition?: DecimalString
305
306
  classification: FillClassification
306
307
  createdAt: string
307
308
  /** Fully-resolved block-explorer URL for the settling on-chain tx. Absent when
@@ -354,7 +355,7 @@ export interface BaseActivity {
354
355
  export interface DepositActivity extends BaseActivity {
355
356
  type: ActivityType.DEPOSIT
356
357
  asset: Asset
357
- amount: string
358
+ amount: DecimalString
358
359
  /**
359
360
  * Address the deposited funds came from, as the venue reports it. Absent
360
361
  * when the venue's deposit payload names no source address.
@@ -373,7 +374,7 @@ export interface DepositActivity extends BaseActivity {
373
374
  export interface WithdrawalActivity extends BaseActivity {
374
375
  type: ActivityType.WITHDRAWAL
375
376
  asset: Asset
376
- amount: string
377
+ amount: DecimalString
377
378
  /** Absent when the venue reports no fee for the withdrawal. */
378
379
  fee?: Fee
379
380
  /** Fully-resolved block-explorer URL for the on-chain withdrawal tx. */
@@ -388,7 +389,7 @@ export interface WithdrawalActivity extends BaseActivity {
388
389
  export interface LiquidatedPosition {
389
390
  market: MarketDisplay
390
391
  /** Absent when the venue reports no liquidated size for the position. */
391
- size?: string
392
+ size?: DecimalString
392
393
  }
393
394
 
394
395
  /**
@@ -402,9 +403,9 @@ export interface LiquidatedPosition {
402
403
  export interface LiquidationActivity extends BaseActivity {
403
404
  type: ActivityType.LIQUIDATION
404
405
  /** Absent when the venue reports no liquidated notional. */
405
- liquidatedNotionalPosition?: string
406
+ liquidatedNotionalPosition?: DecimalString
406
407
  /** Absent when the venue reports no account value at liquidation time. */
407
- accountValue?: string
408
+ accountValue?: DecimalString
408
409
  /**
409
410
  * Margin mode the liquidated account ran under, in the venue's own
410
411
  * vocabulary — typically `cross` or `isolated`, but the venue may report
@@ -432,9 +433,9 @@ export interface FundingActivity extends BaseActivity {
432
433
  * Signed, in quote-currency units. Positive means the account received
433
434
  * funding; negative means the account paid it.
434
435
  */
435
- amount: string
436
- positionSize: string
437
- fundingRate: string
436
+ amount: DecimalString
437
+ positionSize: DecimalString
438
+ fundingRate: DecimalString
438
439
  }
439
440
 
440
441
  // At least one of `counterpartyAccountIndex` / `counterpartyAddress` is always
@@ -451,7 +452,7 @@ export type TransferActivity = BaseActivity & {
451
452
  type: ActivityType.TRANSFER
452
453
  direction: 'IN' | 'OUT'
453
454
  asset: Asset
454
- amount: string
455
+ amount: DecimalString
455
456
  /**
456
457
  * Every fee the venue charged for the transfer, in the order the venue
457
458
  * reports them. A venue may charge several fees for one transfer, each in a
@@ -509,7 +510,7 @@ export type HyperliquidAgent = Record<string, unknown>
509
510
  export interface HyperliquidBuilderFeeApproval {
510
511
  builderAddress: string
511
512
  /** Basis points as a string. */
512
- maxFeeRate: string
513
+ maxFeeRate: DecimalString
513
514
  approved: boolean
514
515
  }
515
516
 
@@ -521,10 +522,10 @@ export interface HyperliquidBuilderFeeApproval {
521
522
  */
522
523
  export interface HyperliquidMarginSummary {
523
524
  /** Total equity: locked margin and unrealized PnL included. */
524
- accountValue: string
525
- totalNtlPos: string
526
- totalRawUsd: string
527
- totalMarginUsed: string
525
+ accountValue: DecimalString
526
+ totalNtlPos: DecimalString
527
+ totalRawUsd: DecimalString
528
+ totalMarginUsed: DecimalString
528
529
  }
529
530
 
530
531
  /**
@@ -539,8 +540,8 @@ export interface HyperliquidDexAccountState {
539
540
  marginSummary: HyperliquidMarginSummary
540
541
  /** Cross-margin subset of {@link HyperliquidDexAccountState.marginSummary}. */
541
542
  crossMarginSummary: HyperliquidMarginSummary
542
- crossMaintenanceMarginUsed: string
543
- withdrawable: string
543
+ crossMaintenanceMarginUsed: DecimalString
544
+ withdrawable: DecimalString
544
545
  }
545
546
 
546
547
  /**
@@ -561,7 +562,7 @@ export interface HyperliquidAccountConfig {
561
562
  * `tokenToAvailableAfterMaintenance` list. Unified and portfolio-margin
562
563
  * accounts only; other modes derive buying power from `marginSummary`.
563
564
  */
564
- availableAfterMaintenance?: string
565
+ availableAfterMaintenance?: DecimalString
565
566
  }
566
567
 
567
568
  /**
@@ -614,23 +615,23 @@ export interface LighterAccountConfig {
614
615
  * equity above its initial margin requirement and subtracts the shortfall
615
616
  * below it. A decimal string in quote-asset units.
616
617
  */
617
- availableBalance: string
618
+ availableBalance: DecimalString
618
619
  /**
619
620
  * Lighter `cross_asset_value`: cross-margin collateral plus the unrealized
620
621
  * PnL of the cross positions. A decimal string in quote-asset units.
621
622
  */
622
- crossAssetValue: string
623
+ crossAssetValue: DecimalString
623
624
  /**
624
625
  * Lighter `cross_initial_margin_requirement`: the initial margin the cross
625
626
  * positions lock. A decimal string in quote-asset units.
626
627
  */
627
- crossInitialMarginRequirement: string
628
+ crossInitialMarginRequirement: DecimalString
628
629
  /**
629
630
  * Lighter `total_asset_value`: perps-route equity, isolated allocations and
630
631
  * unrealized PnL included. It excludes the spot-route balances. A decimal
631
632
  * string in quote-asset units.
632
633
  */
633
- totalAssetValue: string
634
+ totalAssetValue: DecimalString
634
635
  /**
635
636
  * Lighter `user_tier_name` from `/accountLimits`, in the tier vocabulary
636
637
  * `changeAccountTier` accepts. Absent on an unauthenticated read, which
@@ -669,15 +670,15 @@ export interface LighterAccountConfig {
669
670
  */
670
671
  export interface OndoAccountBalance {
671
672
  /** Collateral only: locked margin included, unrealized PnL excluded. */
672
- walletBalance: string
673
- unrealizedPnl: string
673
+ walletBalance: DecimalString
674
+ unrealizedPnl: DecimalString
674
675
  /** Total equity. */
675
- marginBalance: string
676
- usedMargin: string
676
+ marginBalance: DecimalString
677
+ usedMargin: DecimalString
677
678
  /** Venue buying power. */
678
- availableMargin: string
679
+ availableMargin: DecimalString
679
680
  /** Venue withdrawable figure, at or below {@link OndoAccountBalance.availableMargin}. */
680
- withdrawableMargin: string
681
+ withdrawableMargin: DecimalString
681
682
  }
682
683
 
683
684
  /**
package/src/action.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { AcceptTermsParams } from './acceptTerms.js'
2
+ import type { DecimalString } from './decimal.js'
2
3
  import type {
3
4
  ActionType,
4
5
  MarginMode,
@@ -271,13 +272,13 @@ export type ActionResult =
271
272
  * @public
272
273
  */
273
274
  export interface TriggerOrderInput {
274
- triggerPrice: string
275
- limitPrice?: string
275
+ triggerPrice: DecimalString
276
+ limitPrice?: DecimalString
276
277
  /**
277
278
  * Base-asset size the trigger closes. Omitted covers the entire position,
278
279
  * tracking later size changes; set, it is a fixed partial amount.
279
280
  */
280
- size?: string
281
+ size?: DecimalString
281
282
  }
282
283
 
283
284
  /**
@@ -287,10 +288,10 @@ export interface TriggerOrderInput {
287
288
  */
288
289
  export interface ModifyOrderInput {
289
290
  id: string
290
- price?: string
291
- size?: string
292
- triggerPrice?: string
293
- limitPrice?: string
291
+ price?: DecimalString
292
+ size?: DecimalString
293
+ triggerPrice?: DecimalString
294
+ limitPrice?: DecimalString
294
295
  }
295
296
 
296
297
  /**
@@ -302,8 +303,8 @@ export interface PlaceOrderParams {
302
303
  market: MarketRef
303
304
  side: OrderSide
304
305
  type?: Exclude<OrderType, OrderType.TWAP>
305
- size: string
306
- price?: string
306
+ size: DecimalString
307
+ price?: DecimalString
307
308
  leverage?: number
308
309
  /**
309
310
  * Hyperliquid: requires `leverage`. Omitted leaves the market's current
@@ -344,7 +345,7 @@ export interface PlaceTwapOrderParams {
344
345
  market: MarketRef
345
346
  side: OrderSide
346
347
  /** Total base-asset size executed across the TWAP's lifetime, as a decimal string. */
347
- size: string
348
+ size: DecimalString
348
349
  /** Total execution window in seconds. */
349
350
  durationSeconds: number
350
351
  reduceOnly?: boolean
@@ -353,9 +354,9 @@ export interface PlaceTwapOrderParams {
353
354
  /** Ondo: interval between child orders in seconds. */
354
355
  frequencySeconds?: number
355
356
  /** Ondo: lowest acceptable child-order price, as a decimal string. */
356
- minPrice?: string
357
+ minPrice?: DecimalString
357
358
  /** Ondo: highest acceptable child-order price, as a decimal string. */
358
- maxPrice?: string
359
+ maxPrice?: DecimalString
359
360
  }
360
361
 
361
362
  /**
@@ -417,7 +418,7 @@ export interface UpdateLeverageParams {
417
418
  export interface UpdatePositionMarginParams {
418
419
  market: MarketRef
419
420
  action: 'add' | 'remove'
420
- amount: string
421
+ amount: DecimalString
421
422
  }
422
423
 
423
424
  /**
@@ -449,7 +450,7 @@ export type WithdrawalRoute = 'perps' | 'spot'
449
450
  */
450
451
  export interface WithdrawalParams {
451
452
  destination: Address
452
- amount: string
453
+ amount: DecimalString
453
454
  /** Lighter: provider-native `Asset.id` to withdraw. Omitted withdraws the quote asset. */
454
455
  assetId?: string
455
456
  /** Lighter: balance route to draw from. Omitted is `perps`. */
@@ -469,7 +470,7 @@ export interface WithdrawalParams {
469
470
  */
470
471
  export interface DepositParams {
471
472
  /** Amount of the token to deposit, as an integer string in the token's base units (e.g. "100500000" for 100.5 USDC). */
472
- amount: string
473
+ amount: DecimalString
473
474
  /** ERC-20 token address on the source chain. */
474
475
  tokenAddress: Address
475
476
  /** Chain ID of the source chain (e.g. 1 for Ethereum, 42161 for Arbitrum). */
@@ -534,7 +535,7 @@ export interface SendAssetParams {
534
535
  collateral: string
535
536
  sourceDex: string
536
537
  destinationDex: string
537
- amount: string
538
+ amount: DecimalString
538
539
  }
539
540
 
540
541
  /**
package/src/asset.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { DecimalString } from './decimal.js'
2
+
1
3
  /**
2
4
  * Underlying token/registry entry. The base entity of the perps taxonomy:
3
5
  * a tradable unit referenced by markets (as base/quote legs) and held by
@@ -32,7 +34,7 @@ export interface Asset {
32
34
  /** L1 token contract; the zero address denotes native gas. */
33
35
  l1Address?: string
34
36
  /** Venue minimum for a single withdrawal, denominated in this asset — not USD. */
35
- minWithdrawalAmount?: string
37
+ minWithdrawalAmount?: DecimalString
36
38
  }
37
39
 
38
40
  /**
package/src/decimal.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Plain decimal string: optional `-`, digits, optional fraction. No grouping,
3
+ * exponent, currency sign or whitespace; matches {@link DECIMAL_PATTERN}. Build
4
+ * it with an SDK `snap*`/`calculate*` helper or a provider, not `.toString()`.
5
+ *
6
+ * @public
7
+ */
8
+ export type DecimalString = string
9
+
10
+ /**
11
+ * The single spelling rule for a {@link DecimalString}. It stays byte-identical
12
+ * to the pattern `lifi-perps-backend` matches every stored decimal against, so
13
+ * one amount has exactly one spelling in all three repositories.
14
+ *
15
+ * @public
16
+ */
17
+ export const DECIMAL_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/
18
+
19
+ /**
20
+ * Narrows an unknown value to a {@link DecimalString}.
21
+ *
22
+ * @public
23
+ */
24
+ export function isDecimalString(value: unknown): value is DecimalString {
25
+ return typeof value === 'string' && DECIMAL_PATTERN.test(value)
26
+ }
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ export * from './acceptTerms.js'
11
11
  export * from './account.js'
12
12
  export * from './action.js'
13
13
  export * from './asset.js'
14
+ export * from './decimal.js'
14
15
  export * from './enums.js'
15
16
  export * from './errors.js'
16
17
  export * from './market.js'
package/src/market.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Asset } from './asset.js'
2
+ import type { DecimalString } from './decimal.js'
2
3
  import type { PositionMarginAdjustment } from './enums.js'
3
4
 
4
5
  /**
@@ -9,7 +10,7 @@ import type { PositionMarginAdjustment } from './enums.js'
9
10
  */
10
11
  export interface FundingInfo {
11
12
  /** Funding rate as a decimal fraction. */
12
- rate: string
13
+ rate: DecimalString
13
14
  /** Next funding timestamp in Unix milliseconds. */
14
15
  nextFundingTime: number
15
16
  }
@@ -33,24 +34,24 @@ export interface BaseMarket {
33
34
  /**
34
35
  * Maximum decimal places the venue accepts for order prices on this market.
35
36
  * Some venues impose further constraints on top of this budget (e.g. a
36
- * significant-figure cap), so always format prices through the provider's
37
- * `formatOrderPrice` rather than applying this field directly.
37
+ * significant-figure cap), so always snap prices through the provider's
38
+ * `snapOrderPrice` rather than applying this field directly.
38
39
  */
39
40
  priceDecimals?: number
40
41
  /**
41
42
  * Exact price tick as a plain decimal string (e.g. `'0.25'`). Present when
42
43
  * the venue's grid is not a power of ten, where `priceDecimals` alone cannot
43
- * describe the tick. Format prices through the provider's `formatOrderPrice`
44
+ * describe the tick. Snap prices through the provider's `snapOrderPrice`
44
45
  * rather than applying this field directly.
45
46
  */
46
- priceIncrement?: string
47
+ priceIncrement?: DecimalString
47
48
  /**
48
49
  * Exact size lot as a plain decimal string (e.g. `'0.05'`). Present when the
49
50
  * venue's grid is not a power of ten, where `szDecimals` alone cannot
50
- * describe the lot. Format sizes through the provider's `formatOrderSize`
51
+ * describe the lot. Snap sizes through the provider's `snapOrderSize`
51
52
  * rather than applying this field directly.
52
53
  */
53
- sizeIncrement?: string
54
+ sizeIncrement?: DecimalString
54
55
  }
55
56
 
56
57
  /**
@@ -67,15 +68,14 @@ export interface PerpsMarket extends BaseMarket {
67
68
  defaultLeverage?: number
68
69
  /**
69
70
  * Minimum order notional in USD for this market, as a plain decimal string.
70
- * Lighter applies it to resting (post-only) orders only. Separate from the
71
- * venue-wide `Provider.minOrderValueUsd`, which is a `number`; parse this
72
- * string before comparing the two.
71
+ * Lighter applies it to resting (post-only) orders only. This per-market
72
+ * floor is separate from the venue-wide `Provider.minOrderValueUsd`.
73
73
  */
74
- minOrderValueUsd?: string
74
+ minOrderValueUsd?: DecimalString
75
75
  /** Maximum market-order notional in USD, as a plain decimal string. */
76
- maxMarketOrderUsd?: string
76
+ maxMarketOrderUsd?: DecimalString
77
77
  /** Maximum limit-order notional in USD, as a plain decimal string. */
78
- maxLimitOrderUsd?: string
78
+ maxLimitOrderUsd?: DecimalString
79
79
  onlyIsolated: boolean
80
80
  /** Whether individual position margin can be added and/or removed. */
81
81
  positionMarginAdjustment: PositionMarginAdjustment
@@ -150,16 +150,16 @@ export interface MarketContext {
150
150
  /** Opaque provider market identifier for this context frame. */
151
151
  marketId: string
152
152
  /** Current order-book midpoint, as a decimal quote string. */
153
- midPrice: string
153
+ midPrice: DecimalString
154
154
  /** Provider mark price, as a decimal quote string. */
155
- markPrice: string
156
- oraclePrice?: string
157
- prevDayPrice?: string
158
- priceChange24h?: string
159
- volume24h?: string
160
- marketCap?: string
155
+ markPrice: DecimalString
156
+ oraclePrice?: DecimalString
157
+ prevDayPrice?: DecimalString
158
+ priceChange24h?: DecimalString
159
+ volume24h?: DecimalString
160
+ marketCap?: DecimalString
161
161
  /** Quote-asset open-interest notional as a decimal string. */
162
- openInterest?: string
162
+ openInterest?: DecimalString
163
163
  funding?: FundingInfo
164
164
  }
165
165
 
@@ -176,11 +176,11 @@ export interface PricesResponse {
176
176
  */
177
177
  export interface Candle {
178
178
  t: number
179
- o: string
180
- h: string
181
- l: string
182
- c: string
183
- v: string
179
+ o: DecimalString
180
+ h: DecimalString
181
+ l: DecimalString
182
+ c: DecimalString
183
+ v: DecimalString
184
184
  }
185
185
 
186
186
  /** Response containing candles for one provider market and interval. @public */
@@ -215,8 +215,8 @@ export type OhlcvInterval =
215
215
 
216
216
  /** One price/size level in an order book; both values are decimal strings. @public */
217
217
  export interface OrderbookLevel {
218
- price: string
219
- size: string
218
+ price: DecimalString
219
+ size: DecimalString
220
220
  }
221
221
 
222
222
  /** Snapshot of bids and asks for one market. `timestamp` is Unix milliseconds. @public */
@@ -232,8 +232,8 @@ export interface OrderbookResponse {
232
232
  export interface Trade {
233
233
  provider: string
234
234
  marketId: string
235
- price: string
236
- size: string
235
+ price: DecimalString
236
+ size: DecimalString
237
237
  timestamp: number
238
238
  side: 'buy' | 'sell'
239
239
  id?: string
@@ -1,3 +1,5 @@
1
+ import type { DecimalString } from './decimal.js'
2
+
1
3
  /** Lookback window of a portfolio history read. @public */
2
4
  export type PortfolioHistoryRange = '24h' | '7d' | '30d' | 'all'
3
5
 
@@ -9,9 +11,9 @@ export type PortfolioHistoryRange = '24h' | '7d' | '30d' | 'all'
9
11
  export interface PortfolioHistoryPoint {
10
12
  /** Unix milliseconds. */
11
13
  timestamp: number
12
- accountValue: string
14
+ accountValue: DecimalString
13
15
  /** Cumulative PnL from the start of the requested window. */
14
- pnl: string
16
+ pnl: DecimalString
15
17
  }
16
18
 
17
19
  /**
@@ -22,6 +24,6 @@ export interface PortfolioHistoryPoint {
22
24
  export interface PortfolioHistoryResponse {
23
25
  range: PortfolioHistoryRange
24
26
  points: PortfolioHistoryPoint[]
25
- volume?: string
26
- totalPnl?: string
27
+ volume?: DecimalString
28
+ totalPnl?: DecimalString
27
29
  }