@lifi/perps-sdk 0.0.0-preview-c69c4cc → 0.0.0-preview-232a40e

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 (66) hide show
  1. package/dist/cjs/client/PerpsClient.d.ts +13 -9
  2. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  3. package/dist/cjs/client/PerpsClient.js +135 -52
  4. package/dist/cjs/client/PerpsClient.js.map +1 -1
  5. package/dist/cjs/index.d.ts +4 -4
  6. package/dist/cjs/index.d.ts.map +1 -1
  7. package/dist/cjs/index.js +2 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/types/api.d.ts +3 -6
  10. package/dist/cjs/types/api.d.ts.map +1 -1
  11. package/dist/cjs/types/provider.d.ts +5 -10
  12. package/dist/cjs/types/provider.d.ts.map +1 -1
  13. package/dist/cjs/types/withdrawal.d.ts +1 -11
  14. package/dist/cjs/types/withdrawal.d.ts.map +1 -1
  15. package/dist/cjs/utils/setupActions.d.ts +4 -2
  16. package/dist/cjs/utils/setupActions.d.ts.map +1 -1
  17. package/dist/cjs/utils/setupActions.js +9 -1
  18. package/dist/cjs/utils/setupActions.js.map +1 -1
  19. package/dist/cjs/utils/switchChain.js +1 -1
  20. package/dist/cjs/utils/switchChain.js.map +1 -1
  21. package/dist/cjs/version.d.ts +1 -1
  22. package/dist/cjs/version.js +1 -1
  23. package/dist/esm/client/PerpsClient.d.ts +63 -58
  24. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  25. package/dist/esm/client/PerpsClient.js +195 -102
  26. package/dist/esm/client/PerpsClient.js.map +1 -1
  27. package/dist/esm/index.d.ts +4 -4
  28. package/dist/esm/index.d.ts.map +1 -1
  29. package/dist/esm/index.js +1 -1
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/types/api.d.ts +24 -23
  32. package/dist/esm/types/api.d.ts.map +1 -1
  33. package/dist/esm/types/provider.d.ts +17 -40
  34. package/dist/esm/types/provider.d.ts.map +1 -1
  35. package/dist/esm/types/withdrawal.d.ts +1 -30
  36. package/dist/esm/types/withdrawal.d.ts.map +1 -1
  37. package/dist/esm/utils/setupActions.d.ts +17 -8
  38. package/dist/esm/utils/setupActions.d.ts.map +1 -1
  39. package/dist/esm/utils/setupActions.js +20 -7
  40. package/dist/esm/utils/setupActions.js.map +1 -1
  41. package/dist/esm/utils/switchChain.js +1 -1
  42. package/dist/esm/utils/switchChain.js.map +1 -1
  43. package/dist/esm/version.d.ts +1 -1
  44. package/dist/esm/version.js +1 -1
  45. package/dist/types/client/PerpsClient.d.ts +63 -58
  46. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  47. package/dist/types/index.d.ts +4 -4
  48. package/dist/types/index.d.ts.map +1 -1
  49. package/dist/types/types/api.d.ts +24 -23
  50. package/dist/types/types/api.d.ts.map +1 -1
  51. package/dist/types/types/provider.d.ts +17 -40
  52. package/dist/types/types/provider.d.ts.map +1 -1
  53. package/dist/types/types/withdrawal.d.ts +1 -30
  54. package/dist/types/types/withdrawal.d.ts.map +1 -1
  55. package/dist/types/utils/setupActions.d.ts +17 -8
  56. package/dist/types/utils/setupActions.d.ts.map +1 -1
  57. package/dist/types/version.d.ts +1 -1
  58. package/package.json +2 -2
  59. package/src/client/PerpsClient.ts +271 -136
  60. package/src/index.ts +4 -6
  61. package/src/types/api.ts +25 -24
  62. package/src/types/provider.ts +17 -47
  63. package/src/types/withdrawal.ts +1 -33
  64. package/src/utils/setupActions.ts +27 -13
  65. package/src/utils/switchChain.ts +1 -1
  66. package/src/version.ts +1 -1
package/src/index.ts CHANGED
@@ -118,7 +118,6 @@ export type {
118
118
  GetPortfolioHistoryParams,
119
119
  GetSetupParams,
120
120
  GetWithdrawableBalancesParams,
121
- GetWithdrawFlowParams,
122
121
  ModifyOrdersParams,
123
122
  PerpsClientOptions,
124
123
  PerpsConfig,
@@ -167,7 +166,6 @@ export type {
167
166
  ProviderGetPositionsParams,
168
167
  ProviderGetQuoteParams,
169
168
  ProviderGetWithdrawableBalancesParams,
170
- ProviderGetWithdrawFlowParams,
171
169
  QuoteListener,
172
170
  SignActionProgress,
173
171
  SignActionsContext,
@@ -176,9 +174,6 @@ export type {
176
174
  ProviderWithdrawableBalance,
177
175
  WithdrawableBalance,
178
176
  WithdrawalRoute,
179
- WithdrawFlow,
180
- WithdrawFlowReady,
181
- WithdrawFlowSetupRequired,
182
177
  } from './types/withdrawal.js'
183
178
  export { paginateActivity } from './utils/activityPaging.js'
184
179
  export type { ExpectedPnl } from './utils/calculations.js'
@@ -252,7 +247,10 @@ export {
252
247
  } from './utils/positionMath.js'
253
248
  export type { ScaleToIntegerPolicy } from './utils/scaleToInteger.js'
254
249
  export { scaleToInteger } from './utils/scaleToInteger.js'
255
- export { selectUserSetupActions } from './utils/setupActions.js'
250
+ export {
251
+ isSetupOptionFor,
252
+ selectUserSetupActions,
253
+ } from './utils/setupActions.js'
256
254
  export {
257
255
  signTypedData,
258
256
  signTypedDataWithSigner,
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,
@@ -71,8 +72,8 @@ export interface PerpsConfig {
71
72
  */
72
73
  providers?: PerpsProviderPlugin[] | ProviderConfigs
73
74
  /**
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:
75
+ * The end-user's wallet, used whenever an action's descriptor names
76
+ * `PerpsSigner.USER` as its `signer`. Accepts any viem-compatible WalletClient:
76
77
  * - Browser wallet: wagmi's useWalletClient() result
77
78
  * - Private key: createWalletClient({ account: privateKeyToAccount('0x...'), transport: http() })
78
79
  * - Mnemonic: createWalletClient({ account: mnemonicToAccount('word1 ...'), transport: http() })
@@ -289,16 +290,6 @@ export interface GetDepositFlowParams {
289
290
  address: Address
290
291
  }
291
292
 
292
- /**
293
- * Parameters for {@link PerpsClient.getWithdrawFlow}.
294
- *
295
- * @public
296
- */
297
- export interface GetWithdrawFlowParams {
298
- provider: string
299
- address: Address
300
- }
301
-
302
293
  /**
303
294
  * Parameters for {@link PerpsClient.getWithdrawableBalances}.
304
295
  *
@@ -328,9 +319,14 @@ export interface GetPortfolioHistoryParams {
328
319
  */
329
320
  export interface SetupChecklistItem {
330
321
  /** The `Provider.setup` descriptor for this step. */
331
- descriptor: ProviderAction
322
+ descriptor: SetupAction
332
323
  /** Whether the step is already satisfied for this account. */
333
324
  satisfied: boolean
325
+ /**
326
+ * For a choice step, the option whose bound params match the projected
327
+ * account value. `null` when none matches or the step is not a choice.
328
+ */
329
+ selected: SetupOption | null
334
330
  }
335
331
 
336
332
  /**
@@ -341,8 +337,10 @@ export interface SetupChecklistItem {
341
337
  * to the provider's `setup` descriptor, which declares the step's signer and
342
338
  * scheme), so no signer-role partition is exposed here.
343
339
  *
344
- * `Provider.options` items are NEVER included here — they don't gate trading
345
- * and are surfaced separately via `getAccount().settings`.
340
+ * A non-choice step with `signer: SDK` is NEVER included here — the SDK
341
+ * drains it itself. A choice step is listed on `checklist` but never staged or
342
+ * executed: the user picks an option through
343
+ * `PerpsClient.executeProviderOption`.
346
344
  *
347
345
  * @public
348
346
  */
@@ -356,12 +354,15 @@ export interface ProviderSetup {
356
354
  accountExists: boolean
357
355
  /** Unsatisfied setup steps, ordered by descriptor `sequence`. */
358
356
  setup: ActionStep[]
359
- /** Whether all setup items are already satisfied (ready to trade) */
357
+ /**
358
+ * `true` only when nothing is staged and every choice on `checklist` is
359
+ * satisfied: the account is ready to trade.
360
+ */
360
361
  isReady: boolean
361
362
  /**
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
363
+ * The renderable onboarding list: every choice step and every `USER`-signed
364
+ * setup step with its satisfied state, ordered by `sequence`. SDK-drained
365
+ * steps and conditional steps that staged no work for this account (see
365
366
  * `PerpsProviderPlugin.conditionalSetupActions`) are omitted. Consumers
366
367
  * render this list directly instead of joining `Provider.setup` metadata
367
368
  * with the staged `setup` steps.
@@ -393,14 +394,14 @@ export interface ExecuteProviderSetupResult {
393
394
  * backend's `AccountResponse` with a single SDK-projected `settings` array.
394
395
  *
395
396
  * `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.
397
+ * `Provider.setup`, in that order. Index the projection by
398
+ * `setting.type === descriptor.type` and read `setting.values[i].value` for
399
+ * each `Param` the descriptor declared.
399
400
  *
400
401
  * @public
401
402
  */
402
403
  export interface GetAccountResult extends AccountResponse {
403
- /** SDK-projected current state of every setup + options descriptor. */
404
+ /** SDK-projected current state of every `Provider.setup` descriptor. */
404
405
  settings: AccountConfigSetting[]
405
406
  }
406
407
 
@@ -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,
@@ -36,7 +36,7 @@ import type {
36
36
  SDKRequestOptions,
37
37
  } from './config.js'
38
38
  import type { DepositFlow } from './deposit.js'
39
- import type { ProviderWithdrawableBalance, WithdrawFlow } from './withdrawal.js'
39
+ import type { ProviderWithdrawableBalance } from './withdrawal.js'
40
40
 
41
41
  /**
42
42
  * Low-level SDK client: resolved config, the optional end-user wallet, and the
@@ -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
@@ -180,15 +180,6 @@ export interface ProviderGetDepositFlowParams {
180
180
  address: Address
181
181
  }
182
182
 
183
- /**
184
- * Read params for {@link PerpsProviderPlugin.getWithdrawFlow}.
185
- *
186
- * @public
187
- */
188
- export interface ProviderGetWithdrawFlowParams {
189
- address: Address
190
- }
191
-
192
183
  /**
193
184
  * Read params for {@link PerpsProviderPlugin.getWithdrawableBalances}.
194
185
  *
@@ -369,17 +360,6 @@ export interface PerpsProviderPlugin {
369
360
  */
370
361
  readonly type: string
371
362
 
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
363
  /**
384
364
  * Setup actions that stage work only when the account needs remediation
385
365
  * (e.g. Hyperliquid's REVOKE_AGENT frees an agent slot only when every
@@ -430,19 +410,6 @@ export interface PerpsProviderPlugin {
430
410
  options?: SDKRequestOptions
431
411
  ): Promise<DepositFlow>
432
412
 
433
- /**
434
- * The withdrawal flow this venue offers `params.address`, resolved from the
435
- * venue's own account and setup state — the destination a withdrawal goes
436
- * to, or the venue setup that must come first.
437
- *
438
- * Optional: a provider without a gated withdrawal destination omits it, and
439
- * `PerpsClient.getWithdrawFlow` then resolves `undefined`.
440
- */
441
- getWithdrawFlow?(
442
- params: ProviderGetWithdrawFlowParams,
443
- options?: SDKRequestOptions
444
- ): Promise<WithdrawFlow>
445
-
446
413
  /**
447
414
  * The `(asset, route)` pairs `params.address` currently has something to
448
415
  * withdraw from, keyed by provider-native asset id. Only the venue knows how
@@ -598,9 +565,12 @@ export interface PerpsProviderPlugin {
598
565
 
599
566
  /**
600
567
  * Project a typed {@link AccountConfig} against the provider's `setup`
601
- * + `options` descriptors into `AccountConfigSetting[]`. Used by
568
+ * descriptors into `AccountConfigSetting[]`. Used by
602
569
  * `PerpsClient.getAccount` to attach a `settings` array to the response —
603
- * one entry per descriptor, in `setup`-then-`options` order.
570
+ * one entry per descriptor, in `setup` order. Every choice descriptor
571
+ * (`options` is not `null`) carries a boolean `satisfied`, because
572
+ * `PerpsClient.checkSetup` reads a choice's satisfied state and `selected`
573
+ * option from this projection alone.
604
574
  *
605
575
  * Implementations receive the union-typed `AccountConfig` and narrow on
606
576
  * `config.provider` themselves; the dispatcher in `PerpsClient` does not
@@ -608,8 +578,7 @@ export interface PerpsProviderPlugin {
608
578
  */
609
579
  projectConfig(
610
580
  config: AccountConfig,
611
- setup: ProviderAction[],
612
- options: ProviderAction[]
581
+ setup: SetupAction[]
613
582
  ): AccountConfigSetting[]
614
583
 
615
584
  /**
@@ -617,7 +586,8 @@ export interface PerpsProviderPlugin {
617
586
  * when staging the provider setup. Used for plugin-side state the backend
618
587
  * needs to make a correct idempotency decision (e.g. Lighter's known local
619
588
  * API public key). Returns an empty object when the plugin has no params
620
- * to contribute for the action. Optional — providers without local state
589
+ * to contribute for the action. A choice option runs with its bound params
590
+ * alone and never reads these. Optional — providers without local state
621
591
  * can omit it entirely.
622
592
  */
623
593
  resolveSetupParams?(
@@ -628,7 +598,7 @@ export interface PerpsProviderPlugin {
628
598
  /**
629
599
  * Contribute the signer-bearing wire fields for an action — the plugin owns
630
600
  * signer identity (WHO signs), so core asks the plugin rather than resolving
631
- * a `signerAddress` itself. The descriptor's `signers` are forwarded so the
601
+ * a `signerAddress` itself. The descriptor's `signer` is forwarded so the
632
602
  * plugin can branch on signer role: a provider that signs on the user's
633
603
  * behalf with a session keypair (Hyperliquid's agent) resolves — provisioning
634
604
  * one if needed — and returns the agent address as `signerAddress`; for
@@ -644,7 +614,7 @@ export interface PerpsProviderPlugin {
644
614
  resolveActionRequest?(
645
615
  action: ActionType,
646
616
  address: Address,
647
- signers: PerpsSigner[]
617
+ signer: PerpsSigner
648
618
  ): Promise<ActionSignerContribution>
649
619
 
650
620
  /**
@@ -659,7 +629,7 @@ export interface PerpsProviderPlugin {
659
629
  * provider has no `signActions`.
660
630
  *
661
631
  * `method` mirrors the descriptor's `signingMethod`. The plugin owns every
662
- * arm, branching on the descriptor's `signers` internally: the EIP712 arm
632
+ * arm, branching on the descriptor's `signer` internally: the EIP712 arm
663
633
  * signs with the user's wallet (read from `ctx.userWallet`) or the provider's
664
634
  * session keypair (Hyperliquid's agent), and `WASM_BLOB` / `EVM_TX` sign with
665
635
  * the provider's local credential (Lighter).
@@ -1,5 +1,4 @@
1
- import type { ActionType, Asset } from '@lifi/perps-types'
2
- import type { Address } from 'viem'
1
+ import type { Asset } from '@lifi/perps-types'
3
2
 
4
3
  /**
5
4
  * Which of a venue's two balance routes a withdrawal is drawn from. Lighter's
@@ -50,34 +49,3 @@ export interface WithdrawableBalance {
50
49
  */
51
50
  withdrawalFee?: string
52
51
  }
53
-
54
- /**
55
- * The venue accepts a withdrawal to `destination` now.
56
- *
57
- * @public
58
- */
59
- export interface WithdrawFlowReady {
60
- kind: 'ready'
61
- destination: Address
62
- }
63
-
64
- /**
65
- * The venue cannot accept a withdrawal until the listed setup actions are
66
- * satisfied — Ondo sends funds only to an address in its address book, behind
67
- * a signed-in session.
68
- *
69
- * @public
70
- */
71
- export interface WithdrawFlowSetupRequired {
72
- kind: 'setupRequired'
73
- /** Setup action types that must be completed, in execution order. */
74
- setup: ActionType[]
75
- }
76
-
77
- /**
78
- * The single withdrawal flow a venue offers one address, resolved from the
79
- * venue's account and setup state.
80
- *
81
- * @public
82
- */
83
- export type WithdrawFlow = WithdrawFlowReady | WithdrawFlowSetupRequired
@@ -1,14 +1,14 @@
1
- import type { ProviderAction } from '@lifi/perps-types'
1
+ import type { ActionType, SetupAction, SetupOption } from '@lifi/perps-types'
2
2
  import { PerpsSigner } from '@lifi/perps-types'
3
3
 
4
4
  /**
5
- * Select the `Provider.setup` descriptors a user is responsible for satisfying:
6
- * those whose `signers` include {@link PerpsSigner.USER}. Descriptors the SDK
7
- * signs on its own (no `USER` signer) are held back — `checkSetup` completes
8
- * them inline, so surfacing them would render inert cards the user can't act on.
5
+ * Select the `Provider.setup` descriptors a user sees: every choice step, and
6
+ * every non-choice step signed by {@link PerpsSigner.USER}. A non-choice step
7
+ * the SDK signs on its own is held back — `checkSetup` completes it inline, so
8
+ * surfacing it would render an inert card the user can't act on.
9
9
  *
10
- * Membership is a property of the descriptor's `signers` alone, independent of
11
- * any account. When an account is available, prefer `ProviderSetup.checklist`
10
+ * Membership is a property of the descriptor alone, independent of any
11
+ * account. When an account is available, prefer `ProviderSetup.checklist`
12
12
  * from `checkSetup` for the onboarding list — it applies this filter, omits
13
13
  * not-required conditional steps, and carries each entry's satisfied state.
14
14
  * This function remains the static, account-free projection.
@@ -16,10 +16,24 @@ import { PerpsSigner } from '@lifi/perps-types'
16
16
  * @param setup The provider's `setup` descriptors, in their declared order.
17
17
  * @public
18
18
  */
19
- export function selectUserSetupActions(
20
- setup: ProviderAction[]
21
- ): ProviderAction[] {
22
- return setup.filter((descriptor) =>
23
- descriptor.signers.includes(PerpsSigner.USER)
24
- )
19
+ export function selectUserSetupActions(setup: SetupAction[]): SetupAction[] {
20
+ return setup.filter(isUserFacingSetupStep)
21
+ }
22
+
23
+ /** Whether a setup step is shown to the user rather than drained silently. */
24
+ export function isUserFacingSetupStep(descriptor: SetupAction): boolean {
25
+ return descriptor.options !== null || descriptor.signer === PerpsSigner.USER
26
+ }
27
+
28
+ /**
29
+ * Narrow a setup option to the action it executes, so its bound `params` read
30
+ * with that action's param shape.
31
+ *
32
+ * @public
33
+ */
34
+ export function isSetupOptionFor<T extends ActionType>(
35
+ option: SetupOption,
36
+ type: T
37
+ ): option is SetupOption<T> {
38
+ return option.type === type
25
39
  }
@@ -35,7 +35,7 @@ export function userEip712TargetChainId(
35
35
  ): number | undefined {
36
36
  if (
37
37
  descriptor.signingMethod !== SigningMethod.EIP712 ||
38
- !descriptor.signers.includes(PerpsSigner.USER)
38
+ descriptor.signer !== PerpsSigner.USER
39
39
  ) {
40
40
  return undefined
41
41
  }
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 = '0.0.0-preview-c69c4cc'
13
+ export const version = '0.0.0-preview-232a40e'