@lifi/perps-sdk 25.0.2 → 26.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/README.md +54 -1
  2. package/dist/cjs/client/PerpsClient.d.ts +5 -5
  3. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  4. package/dist/cjs/client/PerpsClient.js +75 -74
  5. package/dist/cjs/client/PerpsClient.js.map +1 -1
  6. package/dist/cjs/errors/PerpsExecutionError.d.ts +9 -0
  7. package/dist/cjs/errors/PerpsExecutionError.d.ts.map +1 -0
  8. package/dist/cjs/errors/PerpsExecutionError.js +29 -0
  9. package/dist/cjs/errors/PerpsExecutionError.js.map +1 -0
  10. package/dist/cjs/index.d.ts +5 -4
  11. package/dist/cjs/index.d.ts.map +1 -1
  12. package/dist/cjs/index.js +14 -12
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/math/fills.d.ts +0 -1
  15. package/dist/cjs/math/fills.d.ts.map +1 -1
  16. package/dist/cjs/math/fills.js +0 -18
  17. package/dist/cjs/math/fills.js.map +1 -1
  18. package/dist/cjs/math/order.d.ts +5 -5
  19. package/dist/cjs/math/order.d.ts.map +1 -1
  20. package/dist/cjs/math/order.js +10 -10
  21. package/dist/cjs/math/order.js.map +1 -1
  22. package/dist/cjs/math/position.d.ts +2 -2
  23. package/dist/cjs/math/position.d.ts.map +1 -1
  24. package/dist/cjs/math/position.js +5 -5
  25. package/dist/cjs/math/position.js.map +1 -1
  26. package/dist/cjs/types/api.d.ts +1 -10
  27. package/dist/cjs/types/api.d.ts.map +1 -1
  28. package/dist/cjs/types/provider.d.ts +5 -1
  29. package/dist/cjs/types/provider.d.ts.map +1 -1
  30. package/dist/cjs/version.d.ts +1 -1
  31. package/dist/cjs/version.js +1 -1
  32. package/dist/esm/client/PerpsClient.d.ts +63 -47
  33. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  34. package/dist/esm/client/PerpsClient.js +136 -128
  35. package/dist/esm/client/PerpsClient.js.map +1 -1
  36. package/dist/esm/errors/PerpsExecutionError.d.ts +24 -0
  37. package/dist/esm/errors/PerpsExecutionError.d.ts.map +1 -0
  38. package/dist/esm/errors/PerpsExecutionError.js +39 -0
  39. package/dist/esm/errors/PerpsExecutionError.js.map +1 -0
  40. package/dist/esm/index.d.ts +5 -4
  41. package/dist/esm/index.d.ts.map +1 -1
  42. package/dist/esm/index.js +4 -3
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/math/fills.d.ts +0 -9
  45. package/dist/esm/math/fills.d.ts.map +1 -1
  46. package/dist/esm/math/fills.js +0 -25
  47. package/dist/esm/math/fills.js.map +1 -1
  48. package/dist/esm/math/order.d.ts +6 -6
  49. package/dist/esm/math/order.d.ts.map +1 -1
  50. package/dist/esm/math/order.js +6 -6
  51. package/dist/esm/math/order.js.map +1 -1
  52. package/dist/esm/math/position.d.ts +2 -2
  53. package/dist/esm/math/position.d.ts.map +1 -1
  54. package/dist/esm/math/position.js +3 -3
  55. package/dist/esm/math/position.js.map +1 -1
  56. package/dist/esm/types/api.d.ts +1 -18
  57. package/dist/esm/types/api.d.ts.map +1 -1
  58. package/dist/esm/types/provider.d.ts +21 -4
  59. package/dist/esm/types/provider.d.ts.map +1 -1
  60. package/dist/esm/version.d.ts +1 -1
  61. package/dist/esm/version.js +1 -1
  62. package/dist/types/client/PerpsClient.d.ts +63 -47
  63. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  64. package/dist/types/errors/PerpsExecutionError.d.ts +24 -0
  65. package/dist/types/errors/PerpsExecutionError.d.ts.map +1 -0
  66. package/dist/types/index.d.ts +5 -4
  67. package/dist/types/index.d.ts.map +1 -1
  68. package/dist/types/math/fills.d.ts +0 -9
  69. package/dist/types/math/fills.d.ts.map +1 -1
  70. package/dist/types/math/order.d.ts +6 -6
  71. package/dist/types/math/order.d.ts.map +1 -1
  72. package/dist/types/math/position.d.ts +2 -2
  73. package/dist/types/math/position.d.ts.map +1 -1
  74. package/dist/types/types/api.d.ts +1 -18
  75. package/dist/types/types/api.d.ts.map +1 -1
  76. package/dist/types/types/provider.d.ts +21 -4
  77. package/dist/types/types/provider.d.ts.map +1 -1
  78. package/dist/types/version.d.ts +1 -1
  79. package/package.json +2 -2
  80. package/src/client/PerpsClient.ts +167 -164
  81. package/src/errors/PerpsExecutionError.ts +54 -0
  82. package/src/index.ts +12 -8
  83. package/src/math/fills.ts +0 -29
  84. package/src/math/order.ts +11 -11
  85. package/src/math/position.ts +3 -3
  86. package/src/types/api.ts +0 -21
  87. package/src/types/provider.ts +22 -4
  88. package/src/version.ts +1 -1
package/src/math/fills.ts CHANGED
@@ -4,7 +4,6 @@ import {
4
4
  OrderSide,
5
5
  } from '@lifi/perps-types'
6
6
  import Big from 'big.js'
7
- import { isDecimalStringZero } from '../decimal/compare.js'
8
7
  import { isDecimalString } from '../decimal/parse.js'
9
8
 
10
9
  /**
@@ -69,31 +68,3 @@ export function classifyFillFromPosition(
69
68
  }
70
69
  return FillClassification.REDUCED_SHORT
71
70
  }
72
-
73
- /**
74
- * Classify a fill as open or close based on realizedPnl.
75
- * @deprecated Use `Fill.classification` instead — it uses startPosition
76
- * for accurate open/increase/reduce/close/reverse classification.
77
- * @returns `BUY` or `SELL` when `realizedPnl` is a string that does not match the
78
- * decimal pattern.
79
- * @public
80
- */
81
- export function classifyFill(
82
- side: OrderSide,
83
- realizedPnl: DecimalString | null | undefined
84
- ): FillClassification {
85
- if (realizedPnl != null && !isDecimalString(realizedPnl)) {
86
- return side === OrderSide.BUY
87
- ? FillClassification.BUY
88
- : FillClassification.SELL
89
- }
90
- const isClose = realizedPnl != null && !isDecimalStringZero(realizedPnl)
91
- if (side === OrderSide.BUY) {
92
- return isClose
93
- ? FillClassification.CLOSED_SHORT
94
- : FillClassification.OPENED_LONG
95
- }
96
- return isClose
97
- ? FillClassification.CLOSED_LONG
98
- : FillClassification.OPENED_SHORT
99
- }
package/src/math/order.ts CHANGED
@@ -96,7 +96,7 @@ export const safeEstimateFees = createSafeFunction('estimateFees', estimateFees)
96
96
  * decimal pattern, or `slippagePercent` is -100 or less.
97
97
  * @public
98
98
  */
99
- export function applySlippageToPrice(
99
+ export function calculateSlippagePrice(
100
100
  price: string,
101
101
  slippagePercent: string,
102
102
  isBuy: boolean
@@ -116,9 +116,9 @@ export function applySlippageToPrice(
116
116
  }
117
117
 
118
118
  /** @public */
119
- export const safeApplySlippageToPrice = createSafeFunction(
120
- 'applySlippageToPrice',
121
- applySlippageToPrice
119
+ export const safeCalculateSlippagePrice = createSafeFunction(
120
+ 'calculateSlippagePrice',
121
+ calculateSlippagePrice
122
122
  )
123
123
 
124
124
  /**
@@ -277,7 +277,7 @@ export const safeCalculateRealizedPnlPercent = createSafeFunction(
277
277
  calculateRealizedPnlPercent
278
278
  )
279
279
 
280
- /** Result of {@link walkOrderbook} — the fill obtained for a USD-notional walk. */
280
+ /** Result of {@link calculateOrderbookWalk} — the fill obtained for a USD-notional walk. */
281
281
  interface BookWalk {
282
282
  /** Base amount filled. */
283
283
  baseSize: string
@@ -301,7 +301,7 @@ interface BookWalk {
301
301
  * or `size` does not match the decimal pattern.
302
302
  * @public
303
303
  */
304
- export function walkOrderbook(
304
+ export function calculateOrderbookWalk(
305
305
  levels: OrderbookLevel[],
306
306
  sizeUsd: string
307
307
  ): BookWalk {
@@ -333,9 +333,9 @@ export function walkOrderbook(
333
333
  }
334
334
 
335
335
  /** @public */
336
- export const safeWalkOrderbook = createSafeFunction(
337
- 'walkOrderbook',
338
- walkOrderbook
336
+ export const safeCalculateOrderbookWalk = createSafeFunction(
337
+ 'calculateOrderbookWalk',
338
+ calculateOrderbookWalk
339
339
  )
340
340
 
341
341
  /** Inputs to {@link buildQuote} — the resolved market, its live price, its book, and the trade ask. */
@@ -369,7 +369,7 @@ export function buildQuote(input: BuildQuoteInput): Quote {
369
369
  const { market, price, side, sizeUsd, feeTier } = input
370
370
  const markPrice = decimalStringToDivBig(price.markPrice)
371
371
  const levels = side === 'buy' ? input.asks : input.bids
372
- const walk = walkOrderbook(levels, sizeUsd)
372
+ const walk = calculateOrderbookWalk(levels, sizeUsd)
373
373
  const vwap = decimalStringToBig(walk.vwap)
374
374
  const priceImpactBps =
375
375
  markPrice.eq(0) || vwap.eq(0)
@@ -407,7 +407,7 @@ export const safeBuildQuote = createSafeFunction('buildQuote', buildQuote)
407
407
  * @param positions - Open positions list (any market).
408
408
  * @public
409
409
  */
410
- export function findMatchingPosition(
410
+ export function resolveMatchingPosition(
411
411
  marketId: string,
412
412
  positions: readonly Position[]
413
413
  ): Position | undefined {
@@ -417,7 +417,7 @@ export const safeCalculateRealizedPnl = createSafeFunction(
417
417
  *
418
418
  * @public
419
419
  */
420
- export function positionSupportsMarginAdjustment(position: Position): boolean {
420
+ export function isPositionMarginAdjustable(position: Position): boolean {
421
421
  return (
422
422
  position.marginMode === MarginMode.ISOLATED &&
423
423
  position.market.positionMarginAdjustment !== PositionMarginAdjustment.NONE
@@ -430,9 +430,9 @@ export function positionSupportsMarginAdjustment(position: Position): boolean {
430
430
  *
431
431
  * @public
432
432
  */
433
- export function positionSupportsMarginRemoval(position: Position): boolean {
433
+ export function isPositionMarginRemovable(position: Position): boolean {
434
434
  return (
435
- positionSupportsMarginAdjustment(position) &&
435
+ isPositionMarginAdjustable(position) &&
436
436
  position.market.positionMarginAdjustment ===
437
437
  PositionMarginAdjustment.ADD_AND_REMOVE
438
438
  )
package/src/types/api.ts CHANGED
@@ -7,7 +7,6 @@ import type {
7
7
  PlaceTwapOrderParams as ActionPlaceTwapOrderParams,
8
8
  ActionStep,
9
9
  DecimalString,
10
- ExecuteActionResponse,
11
10
  MarginMode,
12
11
  MarketRef,
13
12
  MetaActionType,
@@ -18,7 +17,6 @@ import type {
18
17
  PortfolioHistoryRange,
19
18
  SetupAction,
20
19
  SetupOption,
21
- SignedActionStep,
22
20
  TimeInForce,
23
21
  TriggerOrderInput,
24
22
  WithdrawalParams,
@@ -380,25 +378,6 @@ export interface ProviderSetup {
380
378
  checklist: SetupChecklistItem[]
381
379
  }
382
380
 
383
- /**
384
- * Parameters for the internal `PerpsClient.executeProviderSetup` batch submit.
385
- */
386
- export interface ExecuteProviderSetupParams {
387
- provider: string
388
- address: Address
389
- /** The unsatisfied setup steps from checkSetup() */
390
- setup: ActionStep[]
391
- /** Signed counterparts of `setup`, in the same order */
392
- signedActions: SignedActionStep[]
393
- }
394
-
395
- /**
396
- * Result from the internal `PerpsClient.executeProviderSetup` batch submit.
397
- */
398
- export interface ExecuteProviderSetupResult {
399
- results: ExecuteActionResponse
400
- }
401
-
402
381
  /**
403
382
  * Result envelope returned by {@link PerpsClient.getAccount} — wraps the
404
383
  * backend's `AccountResponse` with a single SDK-projected `settings` array.
@@ -79,6 +79,23 @@ export interface SignActionProgress {
79
79
  txHash: string
80
80
  }
81
81
 
82
+ /**
83
+ * Output of {@link PerpsProviderPlugin.signActions}, in batch order.
84
+ *
85
+ * A plugin that executes a step itself while signing (a venue REST mutation,
86
+ * a reverted on-chain leg) puts that step's real result in `executed` and
87
+ * leaves it out of `signed`. The plugin stops at the first `executed` result
88
+ * that is not `Submitted` or `Accepted`. Core submits `signed` to
89
+ * `/executeAction` only when every `executed` result is `Submitted` or
90
+ * `Accepted`, and reports `executed` before the `/executeAction` results.
91
+ *
92
+ * @public
93
+ */
94
+ export interface SignActionsResult {
95
+ signed: SignedActionStep[]
96
+ executed: ActionResult[]
97
+ }
98
+
82
99
  /**
83
100
  * Per-call context passed by `PerpsClient` to a provider's
84
101
  * {@link PerpsProviderPlugin.signActions} implementation. Carries the
@@ -699,12 +716,13 @@ export interface PerpsProviderPlugin {
699
716
  steps: ActionStep[],
700
717
  address: Address,
701
718
  ctx?: SignActionsContext
702
- ): Promise<SignedActionStep[]>
719
+ ): Promise<SignActionsResult>
703
720
 
704
721
  /**
705
- * Observe the per-step results of an `/executeAction` round trip before the
706
- * core surfaces failures. Lets a provider react to structured failure codes
707
- * — e.g. evicting a locally stored credential the venue no longer accepts.
722
+ * Observe the execution report of each `execute` call: the results of the
723
+ * steps the plugin executed while signing, then the `/executeAction`
724
+ * results. Lets a provider react to structured statuses — e.g. evicting a
725
+ * locally stored credential the venue refused.
708
726
  */
709
727
  onExecuteResults?(address: Address, results: ActionResult[]): Promise<void>
710
728
 
package/src/version.ts CHANGED
@@ -10,4 +10,4 @@ export const name = '@lifi/perps-sdk'
10
10
  *
11
11
  * @public
12
12
  */
13
- export const version = '25.0.2'
13
+ export const version = '26.0.0'