@lifi/perps-types 18.0.0 → 18.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 (81) 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/quote.d.ts +7 -6
  20. package/dist/cjs/quote.d.ts.map +1 -1
  21. package/dist/cjs/referral.d.ts +4 -3
  22. package/dist/cjs/referral.d.ts.map +1 -1
  23. package/dist/cjs/referral.js.map +1 -1
  24. package/dist/cjs/subscriptions.d.ts +2 -1
  25. package/dist/cjs/subscriptions.d.ts.map +1 -1
  26. package/dist/esm/account.d.ts +63 -62
  27. package/dist/esm/account.d.ts.map +1 -1
  28. package/dist/esm/action.d.ts +17 -16
  29. package/dist/esm/action.d.ts.map +1 -1
  30. package/dist/esm/asset.d.ts +2 -1
  31. package/dist/esm/asset.d.ts.map +1 -1
  32. package/dist/esm/decimal.d.ts +23 -0
  33. package/dist/esm/decimal.d.ts.map +1 -0
  34. package/dist/esm/decimal.js +17 -0
  35. package/dist/esm/decimal.js.map +1 -0
  36. package/dist/esm/index.d.ts +1 -0
  37. package/dist/esm/index.d.ts.map +1 -1
  38. package/dist/esm/index.js +1 -0
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/market.d.ts +24 -23
  41. package/dist/esm/market.d.ts.map +1 -1
  42. package/dist/esm/portfolioHistory.d.ts +5 -4
  43. package/dist/esm/portfolioHistory.d.ts.map +1 -1
  44. package/dist/esm/quote.d.ts +7 -6
  45. package/dist/esm/quote.d.ts.map +1 -1
  46. package/dist/esm/referral.d.ts +4 -3
  47. package/dist/esm/referral.d.ts.map +1 -1
  48. package/dist/esm/referral.js.map +1 -1
  49. package/dist/esm/subscriptions.d.ts +2 -1
  50. package/dist/esm/subscriptions.d.ts.map +1 -1
  51. package/dist/types/account.d.ts +63 -62
  52. package/dist/types/account.d.ts.map +1 -1
  53. package/dist/types/action.d.ts +17 -16
  54. package/dist/types/action.d.ts.map +1 -1
  55. package/dist/types/asset.d.ts +2 -1
  56. package/dist/types/asset.d.ts.map +1 -1
  57. package/dist/types/decimal.d.ts +23 -0
  58. package/dist/types/decimal.d.ts.map +1 -0
  59. package/dist/types/index.d.ts +1 -0
  60. package/dist/types/index.d.ts.map +1 -1
  61. package/dist/types/market.d.ts +24 -23
  62. package/dist/types/market.d.ts.map +1 -1
  63. package/dist/types/portfolioHistory.d.ts +5 -4
  64. package/dist/types/portfolioHistory.d.ts.map +1 -1
  65. package/dist/types/quote.d.ts +7 -6
  66. package/dist/types/quote.d.ts.map +1 -1
  67. package/dist/types/referral.d.ts +4 -3
  68. package/dist/types/referral.d.ts.map +1 -1
  69. package/dist/types/subscriptions.d.ts +2 -1
  70. package/dist/types/subscriptions.d.ts.map +1 -1
  71. package/package.json +1 -1
  72. package/src/account.ts +63 -62
  73. package/src/action.ts +17 -16
  74. package/src/asset.ts +3 -1
  75. package/src/decimal.ts +26 -0
  76. package/src/index.ts +1 -0
  77. package/src/market.ts +24 -23
  78. package/src/portfolioHistory.ts +6 -4
  79. package/src/quote.ts +7 -6
  80. package/src/referral.ts +4 -3
  81. package/src/subscriptions.ts +2 -1
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
  }
@@ -43,14 +44,14 @@ export interface BaseMarket {
43
44
  * describe the tick. Format prices through the provider's `formatOrderPrice`
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
51
  * describe the lot. Format sizes through the provider's `formatOrderSize`
51
52
  * rather than applying this field directly.
52
53
  */
53
- sizeIncrement?: string
54
+ sizeIncrement?: DecimalString
54
55
  }
55
56
 
56
57
  /**
@@ -71,11 +72,11 @@ export interface PerpsMarket extends BaseMarket {
71
72
  * venue-wide `Provider.minOrderValueUsd`, which is a `number`; parse this
72
73
  * string before comparing the two.
73
74
  */
74
- minOrderValueUsd?: string
75
+ minOrderValueUsd?: DecimalString
75
76
  /** Maximum market-order notional in USD, as a plain decimal string. */
76
- maxMarketOrderUsd?: string
77
+ maxMarketOrderUsd?: DecimalString
77
78
  /** Maximum limit-order notional in USD, as a plain decimal string. */
78
- maxLimitOrderUsd?: string
79
+ maxLimitOrderUsd?: DecimalString
79
80
  onlyIsolated: boolean
80
81
  /** Whether individual position margin can be added and/or removed. */
81
82
  positionMarginAdjustment: PositionMarginAdjustment
@@ -150,16 +151,16 @@ export interface MarketContext {
150
151
  /** Opaque provider market identifier for this context frame. */
151
152
  marketId: string
152
153
  /** Current order-book midpoint, as a decimal quote string. */
153
- midPrice: string
154
+ midPrice: DecimalString
154
155
  /** 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
156
+ markPrice: DecimalString
157
+ oraclePrice?: DecimalString
158
+ prevDayPrice?: DecimalString
159
+ priceChange24h?: DecimalString
160
+ volume24h?: DecimalString
161
+ marketCap?: DecimalString
161
162
  /** Quote-asset open-interest notional as a decimal string. */
162
- openInterest?: string
163
+ openInterest?: DecimalString
163
164
  funding?: FundingInfo
164
165
  }
165
166
 
@@ -176,11 +177,11 @@ export interface PricesResponse {
176
177
  */
177
178
  export interface Candle {
178
179
  t: number
179
- o: string
180
- h: string
181
- l: string
182
- c: string
183
- v: string
180
+ o: DecimalString
181
+ h: DecimalString
182
+ l: DecimalString
183
+ c: DecimalString
184
+ v: DecimalString
184
185
  }
185
186
 
186
187
  /** Response containing candles for one provider market and interval. @public */
@@ -215,8 +216,8 @@ export type OhlcvInterval =
215
216
 
216
217
  /** One price/size level in an order book; both values are decimal strings. @public */
217
218
  export interface OrderbookLevel {
218
- price: string
219
- size: string
219
+ price: DecimalString
220
+ size: DecimalString
220
221
  }
221
222
 
222
223
  /** Snapshot of bids and asks for one market. `timestamp` is Unix milliseconds. @public */
@@ -232,8 +233,8 @@ export interface OrderbookResponse {
232
233
  export interface Trade {
233
234
  provider: string
234
235
  marketId: string
235
- price: string
236
- size: string
236
+ price: DecimalString
237
+ size: DecimalString
237
238
  timestamp: number
238
239
  side: 'buy' | 'sell'
239
240
  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
  }
package/src/quote.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { FeeTier } from './account.js'
2
+ import type { DecimalString } from './decimal.js'
2
3
  import type { FundingInfo } from './market.js'
3
4
 
4
5
  /** Side of the quoted market order, using lowercase wire values. @public */
@@ -26,20 +27,20 @@ export interface Quote {
26
27
  type: TradeType
27
28
  side: QuoteSide
28
29
  /** Input notional in USD. */
29
- sizeUsd: string
30
+ sizeUsd: DecimalString
30
31
  /** Base amount the book filled for `sizeUsd` (or the most obtainable when the book is too thin). */
31
- baseSize: string
32
- markPrice: string
32
+ baseSize: DecimalString
33
+ markPrice: DecimalString
33
34
  /** Volume-weighted average fill price from the book walk. */
34
- expectedFillPrice: string
35
+ expectedFillPrice: DecimalString
35
36
  /** VWAP deviation from `markPrice` in basis points; non-negative. */
36
- priceImpactBps: string
37
+ priceImpactBps: DecimalString
37
38
  /** Base maker/taker fee fractions (not bps) for the public tier. */
38
39
  feeTier: FeeTier
39
40
  /** Always `true` in v1 — quotes use the public base tier, never a per-account tier. */
40
41
  isDefaultFeeTier: boolean
41
42
  /** Taker fee on the filled notional in USD: `filledNotional * feeTier.taker`. */
42
- feeUsd: string
43
+ feeUsd: DecimalString
43
44
  /** Current funding for perps; `null` for spot. */
44
45
  funding: FundingInfo | null
45
46
  /** `true` when the book could not fill the full `sizeUsd` — `baseSize`/fill reflect the best obtainable. */
package/src/referral.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Pagination } from './account.js'
2
+ import type { DecimalString } from './decimal.js'
2
3
  import type { Address } from './primitives.js'
3
4
  import type { PerpsTypedData, TypedDataParameter } from './typedData.js'
4
5
 
@@ -71,9 +72,9 @@ export interface OwnedReferralCodeEligibility {
71
72
  * Executed notional the address must reach, as a decimal string in the
72
73
  * backend's reporting currency. Absent when the backend does not disclose it.
73
74
  */
74
- requiredNotional?: string
75
+ requiredNotional?: DecimalString
75
76
  /** The address's executed notional so far, in the same units as `requiredNotional`. */
76
- currentNotional?: string
77
+ currentNotional?: DecimalString
77
78
  }
78
79
 
79
80
  /**
@@ -125,7 +126,7 @@ export interface ReferralActivityItem {
125
126
  * Executed notional recorded against this attachment, as a decimal string in
126
127
  * the backend's reporting currency.
127
128
  */
128
- notional: string
129
+ notional: DecimalString
129
130
  }
130
131
 
131
132
  /**
@@ -6,6 +6,7 @@ import type {
6
6
  Order,
7
7
  Position,
8
8
  } from './account.js'
9
+ import type { DecimalString } from './decimal.js'
9
10
  import type {
10
11
  Candle,
11
12
  MarketContext,
@@ -152,7 +153,7 @@ export type PositionsEvent = { channel: 'positions'; data: Position[] }
152
153
  */
153
154
  export type SpotBalancesEvent = {
154
155
  channel: 'spotBalances'
155
- data: (Balance & { locked: string })[]
156
+ data: (Balance & { locked: DecimalString })[]
156
157
  }
157
158
 
158
159
  /**