@lifi/perps-sdk 18.1.0 → 20.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 (162) hide show
  1. package/README.md +15 -5
  2. package/dist/cjs/client/PerpsClient.d.ts +14 -8
  3. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  4. package/dist/cjs/client/PerpsClient.js +145 -53
  5. package/dist/cjs/client/PerpsClient.js.map +1 -1
  6. package/dist/cjs/client/createPerpsClient.d.ts +1 -6
  7. package/dist/cjs/client/createPerpsClient.d.ts.map +1 -1
  8. package/dist/cjs/client/createPerpsClient.js +1 -14
  9. package/dist/cjs/client/createPerpsClient.js.map +1 -1
  10. package/dist/cjs/index.d.ts +6 -4
  11. package/dist/cjs/index.d.ts.map +1 -1
  12. package/dist/cjs/index.js +11 -3
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/services/getOhlcv.d.ts.map +1 -1
  15. package/dist/cjs/services/getOhlcv.js.map +1 -1
  16. package/dist/cjs/types/api.d.ts +7 -6
  17. package/dist/cjs/types/api.d.ts.map +1 -1
  18. package/dist/cjs/types/config.d.ts +0 -9
  19. package/dist/cjs/types/config.d.ts.map +1 -1
  20. package/dist/cjs/types/provider.d.ts +5 -6
  21. package/dist/cjs/types/provider.d.ts.map +1 -1
  22. package/dist/cjs/types/withdrawal.d.ts +4 -2
  23. package/dist/cjs/types/withdrawal.d.ts.map +1 -1
  24. package/dist/cjs/utils/calculations.d.ts.map +1 -1
  25. package/dist/cjs/utils/calculations.js +107 -38
  26. package/dist/cjs/utils/calculations.js.map +1 -1
  27. package/dist/cjs/utils/decimal.d.ts +4 -0
  28. package/dist/cjs/utils/decimal.d.ts.map +1 -0
  29. package/dist/cjs/utils/decimal.js +14 -0
  30. package/dist/cjs/utils/decimal.js.map +1 -0
  31. package/dist/cjs/utils/math.d.ts +4 -0
  32. package/dist/cjs/utils/math.d.ts.map +1 -0
  33. package/dist/cjs/utils/math.js +8 -0
  34. package/dist/cjs/utils/math.js.map +1 -0
  35. package/dist/cjs/utils/parse.d.ts +1 -0
  36. package/dist/cjs/utils/parse.d.ts.map +1 -1
  37. package/dist/cjs/utils/parse.js +15 -0
  38. package/dist/cjs/utils/parse.js.map +1 -1
  39. package/dist/cjs/utils/positionMath.d.ts +5 -0
  40. package/dist/cjs/utils/positionMath.d.ts.map +1 -1
  41. package/dist/cjs/utils/positionMath.js +53 -6
  42. package/dist/cjs/utils/positionMath.js.map +1 -1
  43. package/dist/cjs/utils/setupActions.d.ts +4 -2
  44. package/dist/cjs/utils/setupActions.d.ts.map +1 -1
  45. package/dist/cjs/utils/setupActions.js +9 -1
  46. package/dist/cjs/utils/setupActions.js.map +1 -1
  47. package/dist/cjs/utils/switchChain.js +1 -1
  48. package/dist/cjs/utils/switchChain.js.map +1 -1
  49. package/dist/cjs/version.d.ts +1 -1
  50. package/dist/cjs/version.js +1 -1
  51. package/dist/cjs/websocket/PerpsWsClient.d.ts +0 -1
  52. package/dist/cjs/websocket/PerpsWsClient.d.ts.map +1 -1
  53. package/dist/cjs/websocket/PerpsWsClient.js +0 -7
  54. package/dist/cjs/websocket/PerpsWsClient.js.map +1 -1
  55. package/dist/esm/client/PerpsClient.d.ts +70 -61
  56. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  57. package/dist/esm/client/PerpsClient.js +215 -107
  58. package/dist/esm/client/PerpsClient.js.map +1 -1
  59. package/dist/esm/client/createPerpsClient.d.ts +1 -12
  60. package/dist/esm/client/createPerpsClient.d.ts.map +1 -1
  61. package/dist/esm/client/createPerpsClient.js +1 -19
  62. package/dist/esm/client/createPerpsClient.js.map +1 -1
  63. package/dist/esm/client/requireProvider.d.ts +1 -1
  64. package/dist/esm/client/requireProvider.js +1 -1
  65. package/dist/esm/index.d.ts +6 -4
  66. package/dist/esm/index.d.ts.map +1 -1
  67. package/dist/esm/index.js +5 -3
  68. package/dist/esm/index.js.map +1 -1
  69. package/dist/esm/services/getOhlcv.d.ts +1 -0
  70. package/dist/esm/services/getOhlcv.d.ts.map +1 -1
  71. package/dist/esm/services/getOhlcv.js.map +1 -1
  72. package/dist/esm/types/api.d.ts +39 -36
  73. package/dist/esm/types/api.d.ts.map +1 -1
  74. package/dist/esm/types/config.d.ts +0 -27
  75. package/dist/esm/types/config.d.ts.map +1 -1
  76. package/dist/esm/types/provider.d.ts +28 -33
  77. package/dist/esm/types/provider.d.ts.map +1 -1
  78. package/dist/esm/types/withdrawal.d.ts +24 -15
  79. package/dist/esm/types/withdrawal.d.ts.map +1 -1
  80. package/dist/esm/utils/calculations.d.ts +3 -2
  81. package/dist/esm/utils/calculations.d.ts.map +1 -1
  82. package/dist/esm/utils/calculations.js +109 -39
  83. package/dist/esm/utils/calculations.js.map +1 -1
  84. package/dist/esm/utils/decimal.d.ts +9 -0
  85. package/dist/esm/utils/decimal.d.ts.map +1 -0
  86. package/dist/esm/utils/decimal.js +12 -0
  87. package/dist/esm/utils/decimal.js.map +1 -0
  88. package/dist/esm/utils/math.d.ts +6 -0
  89. package/dist/esm/utils/math.d.ts.map +1 -0
  90. package/dist/esm/utils/math.js +5 -0
  91. package/dist/esm/utils/math.js.map +1 -0
  92. package/dist/esm/utils/parse.d.ts +7 -0
  93. package/dist/esm/utils/parse.d.ts.map +1 -1
  94. package/dist/esm/utils/parse.js +20 -0
  95. package/dist/esm/utils/parse.js.map +1 -1
  96. package/dist/esm/utils/positionMath.d.ts +13 -0
  97. package/dist/esm/utils/positionMath.d.ts.map +1 -1
  98. package/dist/esm/utils/positionMath.js +60 -6
  99. package/dist/esm/utils/positionMath.js.map +1 -1
  100. package/dist/esm/utils/setupActions.d.ts +17 -8
  101. package/dist/esm/utils/setupActions.d.ts.map +1 -1
  102. package/dist/esm/utils/setupActions.js +20 -7
  103. package/dist/esm/utils/setupActions.js.map +1 -1
  104. package/dist/esm/utils/switchChain.js +1 -1
  105. package/dist/esm/utils/switchChain.js.map +1 -1
  106. package/dist/esm/version.d.ts +1 -1
  107. package/dist/esm/version.js +1 -1
  108. package/dist/esm/websocket/PerpsWsClient.d.ts +0 -7
  109. package/dist/esm/websocket/PerpsWsClient.d.ts.map +1 -1
  110. package/dist/esm/websocket/PerpsWsClient.js +0 -7
  111. package/dist/esm/websocket/PerpsWsClient.js.map +1 -1
  112. package/dist/types/client/PerpsClient.d.ts +70 -61
  113. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  114. package/dist/types/client/createPerpsClient.d.ts +1 -12
  115. package/dist/types/client/createPerpsClient.d.ts.map +1 -1
  116. package/dist/types/client/requireProvider.d.ts +1 -1
  117. package/dist/types/index.d.ts +6 -4
  118. package/dist/types/index.d.ts.map +1 -1
  119. package/dist/types/services/getOhlcv.d.ts +1 -0
  120. package/dist/types/services/getOhlcv.d.ts.map +1 -1
  121. package/dist/types/types/api.d.ts +39 -36
  122. package/dist/types/types/api.d.ts.map +1 -1
  123. package/dist/types/types/config.d.ts +0 -27
  124. package/dist/types/types/config.d.ts.map +1 -1
  125. package/dist/types/types/provider.d.ts +28 -33
  126. package/dist/types/types/provider.d.ts.map +1 -1
  127. package/dist/types/types/withdrawal.d.ts +24 -15
  128. package/dist/types/types/withdrawal.d.ts.map +1 -1
  129. package/dist/types/utils/calculations.d.ts +3 -2
  130. package/dist/types/utils/calculations.d.ts.map +1 -1
  131. package/dist/types/utils/decimal.d.ts +9 -0
  132. package/dist/types/utils/decimal.d.ts.map +1 -0
  133. package/dist/types/utils/math.d.ts +6 -0
  134. package/dist/types/utils/math.d.ts.map +1 -0
  135. package/dist/types/utils/parse.d.ts +7 -0
  136. package/dist/types/utils/parse.d.ts.map +1 -1
  137. package/dist/types/utils/positionMath.d.ts +13 -0
  138. package/dist/types/utils/positionMath.d.ts.map +1 -1
  139. package/dist/types/utils/setupActions.d.ts +17 -8
  140. package/dist/types/utils/setupActions.d.ts.map +1 -1
  141. package/dist/types/version.d.ts +1 -1
  142. package/dist/types/websocket/PerpsWsClient.d.ts +0 -7
  143. package/dist/types/websocket/PerpsWsClient.d.ts.map +1 -1
  144. package/package.json +2 -2
  145. package/src/client/PerpsClient.ts +296 -137
  146. package/src/client/createPerpsClient.ts +4 -32
  147. package/src/client/requireProvider.ts +1 -1
  148. package/src/index.ts +8 -5
  149. package/src/services/getOhlcv.ts +1 -0
  150. package/src/types/api.ts +40 -40
  151. package/src/types/config.ts +0 -30
  152. package/src/types/provider.ts +29 -36
  153. package/src/types/withdrawal.ts +24 -15
  154. package/src/utils/calculations.ts +114 -43
  155. package/src/utils/decimal.ts +13 -0
  156. package/src/utils/math.ts +7 -0
  157. package/src/utils/parse.ts +25 -0
  158. package/src/utils/positionMath.ts +66 -6
  159. package/src/utils/setupActions.ts +27 -13
  160. package/src/utils/switchChain.ts +1 -1
  161. package/src/version.ts +1 -1
  162. package/src/websocket/PerpsWsClient.ts +0 -19
@@ -1,10 +1,6 @@
1
1
  import type { PerpsConfig } from '../types/api.js'
2
- import type { PerpsBaseConfig, ProviderConfigs } from '../types/config.js'
3
- import type {
4
- PerpsProvider,
5
- PerpsProviderPlugin,
6
- PerpsSDKClient,
7
- } from '../types/provider.js'
2
+ import type { PerpsBaseConfig } from '../types/config.js'
3
+ import type { PerpsProvider, PerpsSDKClient } from '../types/provider.js'
8
4
  import { bindProvider } from './bindProvider.js'
9
5
 
10
6
  /**
@@ -30,15 +26,12 @@ export const DEFAULT_API_URL = 'https://li.quest/v1/perps'
30
26
  */
31
27
  export function createPerpsClient(options: PerpsConfig): PerpsSDKClient {
32
28
  const apiUrl = options.apiUrl ?? DEFAULT_API_URL
33
- const { providerPlugins, providerConfigs } = splitProviders(options.providers)
34
29
 
35
30
  const config: PerpsBaseConfig = {
36
31
  integrator: options.integrator?.trim() || undefined,
37
32
  apiKey: options.apiKey?.trim() ?? '',
38
33
  apiUrl,
39
- disableVersionCheck: options.disableVersionCheck,
40
34
  requestInterceptor: options.requestInterceptor,
41
- providers: providerConfigs,
42
35
  retry: options.retry,
43
36
  fetch: options.fetch,
44
37
  }
@@ -58,30 +51,9 @@ export function createPerpsClient(options: PerpsConfig): PerpsSDKClient {
58
51
  },
59
52
  }
60
53
 
61
- const boundProviders: PerpsProvider[] = providerPlugins.map((plugin) =>
62
- bindProvider(plugin, client)
54
+ const boundProviders: PerpsProvider[] = (options.providers ?? []).map(
55
+ (plugin) => bindProvider(plugin, client)
63
56
  )
64
57
 
65
58
  return client
66
59
  }
67
-
68
- /**
69
- * Split the overloaded `providers` option into its two shapes — the
70
- * plugin array used by {@link PerpsSDKClient.getProvider}, and the
71
- * keyed `ProviderConfigs` consumed internally by `PerpsWsClient` for
72
- * markets filtering.
73
- */
74
- export function splitProviders(
75
- input: PerpsProviderPlugin[] | ProviderConfigs | undefined
76
- ): {
77
- providerPlugins: PerpsProviderPlugin[]
78
- providerConfigs?: ProviderConfigs
79
- } {
80
- if (input === undefined) {
81
- return { providerPlugins: [] }
82
- }
83
- if (Array.isArray(input)) {
84
- return { providerPlugins: input }
85
- }
86
- return { providerPlugins: [], providerConfigs: input }
87
- }
@@ -9,7 +9,7 @@ import type { PerpsProvider, PerpsSDKClient } from '../types/provider.js'
9
9
  * `createPerpsClient({ providers: [...] })`) rather than a runtime-recoverable
10
10
  * state.
11
11
  *
12
- * @internal
12
+ * @public
13
13
  */
14
14
  export function requireProvider(
15
15
  client: PerpsSDKClient,
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ export {
16
16
  DEFAULT_API_URL,
17
17
  } from './client/createPerpsClient.js'
18
18
  export { PerpsClient } from './client/PerpsClient.js'
19
+ export { requireProvider } from './client/requireProvider.js'
19
20
  export { PerpsErrorMessage } from './errors/constants.js'
20
21
  export { PerpsError } from './errors/PerpsError.js'
21
22
  // Registries
@@ -132,11 +133,8 @@ export type {
132
133
  WithdrawParams,
133
134
  } from './types/api.js'
134
135
  export type {
135
- HyperliquidConfig,
136
136
  PerpsBaseConfig,
137
137
  PerpsClientSigner,
138
- ProviderConfig,
139
- ProviderConfigs,
140
138
  RequestInterceptor,
141
139
  SDKRequestOptions,
142
140
  SwitchChainHook,
@@ -222,6 +220,7 @@ export {
222
220
  formatSignedUsd,
223
221
  formatUsd,
224
222
  } from './utils/format.js'
223
+ export { maxOf, minOf } from './utils/math.js'
225
224
  export {
226
225
  ACTIVE_ORDER_STATUSES,
227
226
  classifyFill,
@@ -241,7 +240,7 @@ export {
241
240
  findMatchingPosition,
242
241
  resolveCloseSize,
243
242
  } from './utils/orderMath.js'
244
- export { stringToFloat } from './utils/parse.js'
243
+ export { parseDecimal, stringToFloat } from './utils/parse.js'
245
244
  export {
246
245
  directionSign,
247
246
  estimateIsolatedLiquidationPrice,
@@ -249,10 +248,14 @@ export {
249
248
  predictNewLeverage,
250
249
  predictUnrealizedPnl,
251
250
  realizedPnlOnClose,
251
+ wouldImmediatelyLiquidate,
252
252
  } from './utils/positionMath.js'
253
253
  export type { ScaleToIntegerPolicy } from './utils/scaleToInteger.js'
254
254
  export { scaleToInteger } from './utils/scaleToInteger.js'
255
- export { selectUserSetupActions } from './utils/setupActions.js'
255
+ export {
256
+ isSetupOptionFor,
257
+ selectUserSetupActions,
258
+ } from './utils/setupActions.js'
256
259
  export {
257
260
  signTypedData,
258
261
  signTypedDataWithSigner,
@@ -12,6 +12,7 @@ export interface GetOhlcvParams {
12
12
  provider: string
13
13
  /** Opaque provider `Market.id`, not a display symbol. */
14
14
  marketId: string
15
+ /** Pick from the provider's `Provider.supportedIntervals`; support varies per provider. */
15
16
  interval: OhlcvInterval
16
17
  /** Unix timestamp in milliseconds for the start bound. */
17
18
  startTime?: number
package/src/types/api.ts CHANGED
@@ -15,7 +15,8 @@ import type {
15
15
  OrderSide,
16
16
  OrderType,
17
17
  PortfolioHistoryRange,
18
- ProviderAction,
18
+ SetupAction,
19
+ SetupOption,
19
20
  SignedActionStep,
20
21
  TimeInForce,
21
22
  TriggerOrderInput,
@@ -23,11 +24,7 @@ import type {
23
24
  } from '@lifi/perps-types'
24
25
  import type { Account, Address, WalletClient } from 'viem'
25
26
  import type { RetryConfig } from '../transport/retryPolicy.js'
26
- import type {
27
- ProviderConfigs,
28
- RequestInterceptor,
29
- SwitchChainHook,
30
- } from './config.js'
27
+ import type { RequestInterceptor, SwitchChainHook } from './config.js'
31
28
  import type { PerpsProviderPlugin } from './provider.js'
32
29
 
33
30
  /**
@@ -51,28 +48,18 @@ export interface PerpsConfig {
51
48
  apiKey?: string
52
49
  /** Perps API base URL; defaults to {@link DEFAULT_API_URL}. */
53
50
  apiUrl?: string
54
- /** Skip the SDK-version compatibility check when set. */
55
- disableVersionCheck?: boolean
56
51
  /** Hook that can rewrite URL/request options before transport. */
57
52
  requestInterceptor?: RequestInterceptor
58
53
  /**
59
- * Provider plugins or per-provider config. Two shapes are accepted:
60
- *
61
- * - `PerpsProviderPlugin[]` — plugin objects implementing the read surface
62
- * for one DEX each. Bound to the client at construction and looked up at
63
- * runtime as bound {@link PerpsProvider}s via `client.getProvider(key)`.
64
- * Modelled on `@lifi/sdk`'s `providers: SDKProvider[]`.
65
- * - `ProviderConfigs` — keyed config object (e.g.
66
- * `{ hyperliquid: { markets: [...] } }`). Used internally by
67
- * `PerpsWsClient` to filter which markets are subscribed to.
68
- *
69
- * Both may be supplied during the migration to provider packages;
70
- * the array form is preferred for new code.
54
+ * Provider plugins, one per DEX. Bound to the client at construction and
55
+ * looked up at runtime as bound {@link PerpsProvider}s via
56
+ * `client.getProvider(key)`. Modelled on `@lifi/sdk`'s
57
+ * `providers: SDKProvider[]`.
71
58
  */
72
- providers?: PerpsProviderPlugin[] | ProviderConfigs
59
+ providers?: PerpsProviderPlugin[]
73
60
  /**
74
- * The end-user's wallet, used whenever an action's descriptor names the user
75
- * wallet in its `signers` list. Accepts any viem-compatible WalletClient:
61
+ * The end-user's wallet, used whenever an action's descriptor names
62
+ * `PerpsSigner.USER` as its `signer`. Accepts any viem-compatible WalletClient:
76
63
  * - Browser wallet: wagmi's useWalletClient() result
77
64
  * - Private key: createWalletClient({ account: privateKeyToAccount('0x...'), transport: http() })
78
65
  * - Mnemonic: createWalletClient({ account: mnemonicToAccount('word1 ...'), transport: http() })
@@ -116,12 +103,8 @@ export interface PerpsClientOptions {
116
103
  apiKey?: string
117
104
  /** Perps API base URL; defaults to {@link DEFAULT_API_URL}. */
118
105
  apiUrl?: string
119
- /**
120
- * Provider plugins or per-provider config. Accepts the same two shapes as
121
- * {@link PerpsConfig.providers}: an array of `PerpsProviderPlugin` plugins or
122
- * a keyed `ProviderConfigs` map.
123
- */
124
- providers?: PerpsProviderPlugin[] | ProviderConfigs
106
+ /** Provider plugins; see {@link PerpsConfig.providers}. */
107
+ providers?: PerpsProviderPlugin[]
125
108
  /**
126
109
  * Hook invoked before a USER-signed EIP-712 action is signed, to switch the
127
110
  * user's wallet to the action's target chain. Also settable at runtime via
@@ -328,9 +311,21 @@ export interface GetPortfolioHistoryParams {
328
311
  */
329
312
  export interface SetupChecklistItem {
330
313
  /** The `Provider.setup` descriptor for this step. */
331
- descriptor: ProviderAction
314
+ descriptor: SetupAction
332
315
  /** Whether the step is already satisfied for this account. */
333
316
  satisfied: boolean
317
+ /**
318
+ * For a choice step, the option whose bound params match the projected
319
+ * account value. `null` when none matches or the step is not a choice.
320
+ */
321
+ selected: SetupOption | null
322
+ /**
323
+ * For a choice step, the account's current value as the venue names it
324
+ * (the raw projected value, e.g. `standard` or `dexAbstraction`), even when
325
+ * no option binds it. `null` when the venue reports none or the value is
326
+ * unreadable, and always `null` for a non-choice step.
327
+ */
328
+ currentValue: string | null
334
329
  }
335
330
 
336
331
  /**
@@ -341,8 +336,10 @@ export interface SetupChecklistItem {
341
336
  * to the provider's `setup` descriptor, which declares the step's signer and
342
337
  * scheme), so no signer-role partition is exposed here.
343
338
  *
344
- * `Provider.options` items are NEVER included here — they don't gate trading
345
- * and are surfaced separately via `getAccount().settings`.
339
+ * A non-choice step with `signer: SDK` is NEVER included here — the SDK
340
+ * drains it itself. A choice step is listed on `checklist` but never staged or
341
+ * executed: the user picks an option through
342
+ * `PerpsClient.executeProviderOption`.
346
343
  *
347
344
  * @public
348
345
  */
@@ -356,12 +353,15 @@ export interface ProviderSetup {
356
353
  accountExists: boolean
357
354
  /** Unsatisfied setup steps, ordered by descriptor `sequence`. */
358
355
  setup: ActionStep[]
359
- /** Whether all setup items are already satisfied (ready to trade) */
356
+ /**
357
+ * `true` only when nothing is staged and every choice on `checklist` is
358
+ * satisfied: the account is ready to trade.
359
+ */
360
360
  isReady: boolean
361
361
  /**
362
- * The renderable onboarding list: every USER-signed setup descriptor with
363
- * its satisfied state, ordered by `sequence`. SDK-internal steps and
364
- * conditional steps that staged no work for this account (see
362
+ * The renderable onboarding list: every choice step and every `USER`-signed
363
+ * setup step with its satisfied state, ordered by `sequence`. SDK-drained
364
+ * steps and conditional steps that staged no work for this account (see
365
365
  * `PerpsProviderPlugin.conditionalSetupActions`) are omitted. Consumers
366
366
  * render this list directly instead of joining `Provider.setup` metadata
367
367
  * with the staged `setup` steps.
@@ -393,14 +393,14 @@ export interface ExecuteProviderSetupResult {
393
393
  * backend's `AccountResponse` with a single SDK-projected `settings` array.
394
394
  *
395
395
  * `settings` contains exactly one `AccountConfigSetting` per descriptor on
396
- * `Provider.setup` + `Provider.options` (in that order). Index the
397
- * projection by `setting.type === descriptor.type` and read
398
- * `setting.values[i].value` for each `Param` the descriptor declared.
396
+ * `Provider.setup`, in that order. Index the projection by
397
+ * `setting.type === descriptor.type` and read `setting.values[i].value` for
398
+ * each `Param` the descriptor declared.
399
399
  *
400
400
  * @public
401
401
  */
402
402
  export interface GetAccountResult extends AccountResponse {
403
- /** SDK-projected current state of every setup + options descriptor. */
403
+ /** SDK-projected current state of every `Provider.setup` descriptor. */
404
404
  settings: AccountConfigSetting[]
405
405
  }
406
406
 
@@ -23,32 +23,6 @@ export type SwitchChainHook = (
23
23
  chainId: number
24
24
  ) => Promise<PerpsClientSigner | undefined>
25
25
 
26
- /**
27
- * Per-provider config — restricts which `markets` the WS client subscribes
28
- * to. Indexed by provider key.
29
- *
30
- * @public
31
- */
32
- export interface ProviderConfig {
33
- /** Optional provider category/market ids used to filter WS subscriptions. */
34
- markets?: string[]
35
- }
36
-
37
- /**
38
- * @deprecated Use {@link ProviderConfig}.
39
- * @public
40
- */
41
- export type HyperliquidConfig = ProviderConfig
42
-
43
- /**
44
- * Map of per-provider {@link ProviderConfig}, keyed by provider key.
45
- *
46
- * @public
47
- */
48
- export interface ProviderConfigs {
49
- [provider: string]: ProviderConfig | undefined
50
- }
51
-
52
26
  /**
53
27
  * Hook to rewrite each outgoing request's URL/`RequestInit` before it is sent.
54
28
  *
@@ -101,12 +75,8 @@ export interface PerpsBaseConfig {
101
75
  apiKey: string
102
76
  /** Resolved perps API base URL. */
103
77
  apiUrl: string
104
- /** Whether SDK version compatibility checks are disabled. */
105
- disableVersionCheck?: boolean
106
78
  /** Optional outgoing-request URL/options interceptor. */
107
79
  requestInterceptor?: RequestInterceptor
108
- /** Optional per-provider WS market filters. */
109
- providers?: ProviderConfigs
110
80
  /** Optional global or per-provider retry configuration. */
111
81
  retry?: RetryConfig
112
82
  /** Fetch implementation used by core HTTP transport. */
@@ -22,9 +22,9 @@ import type {
22
22
  PortfolioHistoryResponse,
23
23
  Position,
24
24
  PositionsResponse,
25
- ProviderAction,
26
25
  Quote,
27
26
  QuoteSide,
27
+ SetupAction,
28
28
  SignedActionStep,
29
29
  SigningMethod,
30
30
  TradeType,
@@ -86,12 +86,12 @@ export interface SignActionsContext {
86
86
  /** End-user wallet used for USER-signed or EVM transaction legs. */
87
87
  userWallet?: PerpsClientSigner
88
88
  /**
89
- * The signing batch's declared signers, from the action's `ProviderAction`
89
+ * The signing batch's declared signer, from the action's `ProviderAction`
90
90
  * descriptor. The plugin branches on this to pick WHO signs (e.g.
91
- * Hyperliquid: `USER` → end-user wallet, `AGENT` → session keypair). Core
92
- * forwards the descriptor's `signers` as data; it does not branch on them.
91
+ * Hyperliquid: `USER` → end-user wallet, `SDK` → session keypair). Core
92
+ * forwards the descriptor's `signer` as data; it does not branch on it.
93
93
  */
94
- signers?: PerpsSigner[]
94
+ signer?: PerpsSigner
95
95
  /**
96
96
  * Switch `userWallet` to `chainId` and resolve the client to broadcast with.
97
97
  * Bound by core to the consumer's `switchChain` hook and the resolved
@@ -370,23 +370,12 @@ export interface PerpsProviderPlugin {
370
370
  readonly type: string
371
371
 
372
372
  /**
373
- * Setup actions the provider completes on its own, without surfacing a card
374
- * to the caller. `PerpsClient.checkSetup` drains each such pending step in
375
- * place — building, signing, and executing it with the provider's own
376
- * credentials — and omits it from the returned `setup` list. A descriptor
377
- * whose `signers` include {@link PerpsSigner.USER} is never treated as
378
- * internal, even when named here. Omit when the provider has no
379
- * self-completed setup steps.
380
- */
381
- readonly internalSetupActions?: readonly ActionType[]
382
-
383
- /**
384
- * Setup actions that stage work only when the account needs remediation
385
- * (e.g. Hyperliquid's REVOKE_AGENT frees an agent slot only when every
386
- * named slot is taken). When such a step stages no actions,
373
+ * Non-choice setup actions that stage work only when the account needs
374
+ * remediation (e.g. Hyperliquid's REVOKE_AGENT frees an agent slot only
375
+ * when every named slot is taken). When such a step stages no actions,
387
376
  * `PerpsClient.checkSetup` omits it from `ProviderSetup.checklist` instead
388
- * of rendering it as satisfied. Omit when every setup step is
389
- * unconditional.
377
+ * of rendering it as satisfied. Choices are always rendered because they
378
+ * are never staged. Omit when every setup step is unconditional.
390
379
  */
391
380
  readonly conditionalSetupActions?: readonly ActionType[]
392
381
 
@@ -464,16 +453,17 @@ export interface PerpsProviderPlugin {
464
453
  ): Promise<PositionsResponse>
465
454
 
466
455
  /**
467
- * The user's current venue-side settings for one market — the margin mode
468
- * and leverage the next order on it will use. Optional because venues
469
- * expose this unevenly: Hyperliquid reads it directly (`activeAssetData`),
470
- * Lighter only reports it on an account's position row. `undefined` means
471
- * the venue has nothing to read for this market.
456
+ * The user's current venue-side settings for one perps market — the margin
457
+ * mode and leverage the next order on it will use. Resolves the venue value
458
+ * or throws.
459
+ *
460
+ * @throws {PerpsError} `ValidationError` for a spot market; any other
461
+ * `PerpsError` when the venue read fails or carries no usable value.
472
462
  */
473
- getMarketSettings?(
463
+ getMarketSettings(
474
464
  params: ProviderGetMarketSettingsParams,
475
465
  options?: SDKRequestOptions
476
- ): Promise<MarketSettings | undefined>
466
+ ): Promise<MarketSettings>
477
467
 
478
468
  /**
479
469
  * The amounts the account can still buy and sell on one market, in that
@@ -598,9 +588,12 @@ export interface PerpsProviderPlugin {
598
588
 
599
589
  /**
600
590
  * Project a typed {@link AccountConfig} against the provider's `setup`
601
- * + `options` descriptors into `AccountConfigSetting[]`. Used by
591
+ * descriptors into `AccountConfigSetting[]`. Used by
602
592
  * `PerpsClient.getAccount` to attach a `settings` array to the response —
603
- * one entry per descriptor, in `setup`-then-`options` order.
593
+ * one entry per descriptor, in `setup` order. Every choice descriptor
594
+ * (`options` is not `null`) carries a boolean `satisfied`, because
595
+ * `PerpsClient.checkSetup` reads a choice's satisfied state and `selected`
596
+ * option from this projection alone.
604
597
  *
605
598
  * Implementations receive the union-typed `AccountConfig` and narrow on
606
599
  * `config.provider` themselves; the dispatcher in `PerpsClient` does not
@@ -608,8 +601,7 @@ export interface PerpsProviderPlugin {
608
601
  */
609
602
  projectConfig(
610
603
  config: AccountConfig,
611
- setup: ProviderAction[],
612
- options: ProviderAction[]
604
+ setup: SetupAction[]
613
605
  ): AccountConfigSetting[]
614
606
 
615
607
  /**
@@ -617,7 +609,8 @@ export interface PerpsProviderPlugin {
617
609
  * when staging the provider setup. Used for plugin-side state the backend
618
610
  * needs to make a correct idempotency decision (e.g. Lighter's known local
619
611
  * API public key). Returns an empty object when the plugin has no params
620
- * to contribute for the action. Optional — providers without local state
612
+ * to contribute for the action. A choice option runs with its bound params
613
+ * alone and never reads these. Optional — providers without local state
621
614
  * can omit it entirely.
622
615
  */
623
616
  resolveSetupParams?(
@@ -628,7 +621,7 @@ export interface PerpsProviderPlugin {
628
621
  /**
629
622
  * Contribute the signer-bearing wire fields for an action — the plugin owns
630
623
  * signer identity (WHO signs), so core asks the plugin rather than resolving
631
- * a `signerAddress` itself. The descriptor's `signers` are forwarded so the
624
+ * a `signerAddress` itself. The descriptor's `signer` is forwarded so the
632
625
  * plugin can branch on signer role: a provider that signs on the user's
633
626
  * behalf with a session keypair (Hyperliquid's agent) resolves — provisioning
634
627
  * one if needed — and returns the agent address as `signerAddress`; for
@@ -644,7 +637,7 @@ export interface PerpsProviderPlugin {
644
637
  resolveActionRequest?(
645
638
  action: ActionType,
646
639
  address: Address,
647
- signers: PerpsSigner[]
640
+ signer: PerpsSigner
648
641
  ): Promise<ActionSignerContribution>
649
642
 
650
643
  /**
@@ -659,7 +652,7 @@ export interface PerpsProviderPlugin {
659
652
  * provider has no `signActions`.
660
653
  *
661
654
  * `method` mirrors the descriptor's `signingMethod`. The plugin owns every
662
- * arm, branching on the descriptor's `signers` internally: the EIP712 arm
655
+ * arm, branching on the descriptor's `signer` internally: the EIP712 arm
663
656
  * signs with the user's wallet (read from `ctx.userWallet`) or the provider's
664
657
  * session keypair (Hyperliquid's agent), and `WASM_BLOB` / `EVM_TX` sign with
665
658
  * the provider's local credential (Lighter).
@@ -1,15 +1,7 @@
1
- import type { ActionType, Asset } from '@lifi/perps-types'
1
+ import type { ActionType, Asset, WithdrawalRoute } from '@lifi/perps-types'
2
2
  import type { Address } from 'viem'
3
3
 
4
- /**
5
- * Which of a venue's two balance routes a withdrawal is drawn from. Lighter's
6
- * own vocabulary, carried in the signed tx as `AssetRouteType` (`perps` = 0,
7
- * `spot` = 1); an account's mode changes what the two balances mean, never
8
- * which route the tx names.
9
- *
10
- * @public
11
- */
12
- export type WithdrawalRoute = 'perps' | 'spot'
4
+ export type { WithdrawalRoute }
13
5
 
14
6
  /**
15
7
  * One withdrawable `(asset, route)` selection as the provider reports it, keyed
@@ -25,10 +17,16 @@ export interface ProviderWithdrawableBalance {
25
17
  available: string
26
18
  /**
27
19
  * Flat venue fee on a withdrawal from this row, in the asset's own units.
28
- * Absent when the venue publishes no fee for the asset. The client rejects a
29
- * value that is not a non-negative decimal.
20
+ * Absent when the venue publishes no fee for the asset. The client rejects
21
+ * a value that is not a non-negative decimal.
30
22
  */
31
23
  withdrawalFee?: string
24
+ /**
25
+ * `true` when the venue takes `withdrawalFee` out of the requested amount,
26
+ * `false` when it charges the fee in addition. Set together with
27
+ * `withdrawalFee`; the client drops it from a row without a fee.
28
+ */
29
+ isFeeDeducted?: boolean
32
30
  }
33
31
 
34
32
  /**
@@ -44,11 +42,22 @@ export interface WithdrawableBalance {
44
42
  /** Withdrawable amount in the asset's own units. */
45
43
  available: string
46
44
  /**
47
- * Flat venue fee on a withdrawal from this row, in the asset's own units. An
48
- * amount at or below it delivers nothing. Absent when the venue publishes no
49
- * fee for the asset.
45
+ * Flat venue fee on a withdrawal from this row, in the asset's own units.
46
+ * Absent when the venue publishes no fee for the asset. With
47
+ * `isFeeDeducted` `true`, the venue takes the fee out of the requested
48
+ * amount, and an amount at or below the fee delivers nothing. With `false`,
49
+ * the venue charges the fee in addition to the requested amount, so the
50
+ * largest amount the row can fund is `available` minus the fee. That result
51
+ * is zero or negative when the fee is at or above `available`, and the row
52
+ * then funds no withdrawal.
50
53
  */
51
54
  withdrawalFee?: string
55
+ /**
56
+ * Present only together with `withdrawalFee`. Absent on a row from a
57
+ * provider plugin that does not report it; absence means unknown, not
58
+ * `true`.
59
+ */
60
+ isFeeDeducted?: boolean
52
61
  }
53
62
 
54
63
  /**