@lifi/perps-sdk 18.1.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 (59) hide show
  1. package/dist/cjs/client/PerpsClient.d.ts +13 -7
  2. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  3. package/dist/cjs/client/PerpsClient.js +141 -52
  4. package/dist/cjs/client/PerpsClient.js.map +1 -1
  5. package/dist/cjs/index.d.ts +1 -1
  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 +4 -2
  10. package/dist/cjs/types/api.d.ts.map +1 -1
  11. package/dist/cjs/types/provider.d.ts +4 -5
  12. package/dist/cjs/types/provider.d.ts.map +1 -1
  13. package/dist/cjs/utils/setupActions.d.ts +4 -2
  14. package/dist/cjs/utils/setupActions.d.ts.map +1 -1
  15. package/dist/cjs/utils/setupActions.js +9 -1
  16. package/dist/cjs/utils/setupActions.js.map +1 -1
  17. package/dist/cjs/utils/switchChain.js +1 -1
  18. package/dist/cjs/utils/switchChain.js.map +1 -1
  19. package/dist/cjs/version.d.ts +1 -1
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/esm/client/PerpsClient.d.ts +62 -54
  22. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  23. package/dist/esm/client/PerpsClient.js +204 -100
  24. package/dist/esm/client/PerpsClient.js.map +1 -1
  25. package/dist/esm/index.d.ts +1 -1
  26. package/dist/esm/index.d.ts.map +1 -1
  27. package/dist/esm/index.js +1 -1
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/types/api.d.ts +31 -14
  30. package/dist/esm/types/api.d.ts.map +1 -1
  31. package/dist/esm/types/provider.d.ts +21 -27
  32. package/dist/esm/types/provider.d.ts.map +1 -1
  33. package/dist/esm/utils/setupActions.d.ts +17 -8
  34. package/dist/esm/utils/setupActions.d.ts.map +1 -1
  35. package/dist/esm/utils/setupActions.js +20 -7
  36. package/dist/esm/utils/setupActions.js.map +1 -1
  37. package/dist/esm/utils/switchChain.js +1 -1
  38. package/dist/esm/utils/switchChain.js.map +1 -1
  39. package/dist/esm/version.d.ts +1 -1
  40. package/dist/esm/version.js +1 -1
  41. package/dist/types/client/PerpsClient.d.ts +62 -54
  42. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  43. package/dist/types/index.d.ts +1 -1
  44. package/dist/types/index.d.ts.map +1 -1
  45. package/dist/types/types/api.d.ts +31 -14
  46. package/dist/types/types/api.d.ts.map +1 -1
  47. package/dist/types/types/provider.d.ts +21 -27
  48. package/dist/types/types/provider.d.ts.map +1 -1
  49. package/dist/types/utils/setupActions.d.ts +17 -8
  50. package/dist/types/utils/setupActions.d.ts.map +1 -1
  51. package/dist/types/version.d.ts +1 -1
  52. package/package.json +2 -2
  53. package/src/client/PerpsClient.ts +284 -129
  54. package/src/index.ts +4 -1
  55. package/src/types/api.ts +32 -14
  56. package/src/types/provider.ts +21 -29
  57. package/src/utils/setupActions.ts +27 -13
  58. package/src/utils/switchChain.ts +1 -1
  59. package/src/version.ts +1 -1
package/src/index.ts CHANGED
@@ -252,7 +252,10 @@ export {
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,
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() })
@@ -328,9 +329,21 @@ export interface GetPortfolioHistoryParams {
328
329
  */
329
330
  export interface SetupChecklistItem {
330
331
  /** The `Provider.setup` descriptor for this step. */
331
- descriptor: ProviderAction
332
+ descriptor: SetupAction
332
333
  /** Whether the step is already satisfied for this account. */
333
334
  satisfied: boolean
335
+ /**
336
+ * For a choice step, the option whose bound params match the projected
337
+ * account value. `null` when none matches or the step is not a choice.
338
+ */
339
+ selected: SetupOption | null
340
+ /**
341
+ * For a choice step, the account's current value as the venue names it
342
+ * (the raw projected value, e.g. `standard` or `dexAbstraction`), even when
343
+ * no option binds it. `null` when the venue reports none or the value is
344
+ * unreadable, and always `null` for a non-choice step.
345
+ */
346
+ currentValue: string | null
334
347
  }
335
348
 
336
349
  /**
@@ -341,8 +354,10 @@ export interface SetupChecklistItem {
341
354
  * to the provider's `setup` descriptor, which declares the step's signer and
342
355
  * scheme), so no signer-role partition is exposed here.
343
356
  *
344
- * `Provider.options` items are NEVER included here — they don't gate trading
345
- * and are surfaced separately via `getAccount().settings`.
357
+ * A non-choice step with `signer: SDK` is NEVER included here — the SDK
358
+ * drains it itself. A choice step is listed on `checklist` but never staged or
359
+ * executed: the user picks an option through
360
+ * `PerpsClient.executeProviderOption`.
346
361
  *
347
362
  * @public
348
363
  */
@@ -356,12 +371,15 @@ export interface ProviderSetup {
356
371
  accountExists: boolean
357
372
  /** Unsatisfied setup steps, ordered by descriptor `sequence`. */
358
373
  setup: ActionStep[]
359
- /** Whether all setup items are already satisfied (ready to trade) */
374
+ /**
375
+ * `true` only when nothing is staged and every choice on `checklist` is
376
+ * satisfied: the account is ready to trade.
377
+ */
360
378
  isReady: boolean
361
379
  /**
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
380
+ * The renderable onboarding list: every choice step and every `USER`-signed
381
+ * setup step with its satisfied state, ordered by `sequence`. SDK-drained
382
+ * steps and conditional steps that staged no work for this account (see
365
383
  * `PerpsProviderPlugin.conditionalSetupActions`) are omitted. Consumers
366
384
  * render this list directly instead of joining `Provider.setup` metadata
367
385
  * with the staged `setup` steps.
@@ -393,14 +411,14 @@ export interface ExecuteProviderSetupResult {
393
411
  * backend's `AccountResponse` with a single SDK-projected `settings` array.
394
412
  *
395
413
  * `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.
414
+ * `Provider.setup`, in that order. Index the projection by
415
+ * `setting.type === descriptor.type` and read `setting.values[i].value` for
416
+ * each `Param` the descriptor declared.
399
417
  *
400
418
  * @public
401
419
  */
402
420
  export interface GetAccountResult extends AccountResponse {
403
- /** SDK-projected current state of every setup + options descriptor. */
421
+ /** SDK-projected current state of every `Provider.setup` descriptor. */
404
422
  settings: AccountConfigSetting[]
405
423
  }
406
424
 
@@ -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
 
@@ -598,9 +587,12 @@ export interface PerpsProviderPlugin {
598
587
 
599
588
  /**
600
589
  * Project a typed {@link AccountConfig} against the provider's `setup`
601
- * + `options` descriptors into `AccountConfigSetting[]`. Used by
590
+ * descriptors into `AccountConfigSetting[]`. Used by
602
591
  * `PerpsClient.getAccount` to attach a `settings` array to the response —
603
- * one entry per descriptor, in `setup`-then-`options` order.
592
+ * one entry per descriptor, in `setup` order. Every choice descriptor
593
+ * (`options` is not `null`) carries a boolean `satisfied`, because
594
+ * `PerpsClient.checkSetup` reads a choice's satisfied state and `selected`
595
+ * option from this projection alone.
604
596
  *
605
597
  * Implementations receive the union-typed `AccountConfig` and narrow on
606
598
  * `config.provider` themselves; the dispatcher in `PerpsClient` does not
@@ -608,8 +600,7 @@ export interface PerpsProviderPlugin {
608
600
  */
609
601
  projectConfig(
610
602
  config: AccountConfig,
611
- setup: ProviderAction[],
612
- options: ProviderAction[]
603
+ setup: SetupAction[]
613
604
  ): AccountConfigSetting[]
614
605
 
615
606
  /**
@@ -617,7 +608,8 @@ export interface PerpsProviderPlugin {
617
608
  * when staging the provider setup. Used for plugin-side state the backend
618
609
  * needs to make a correct idempotency decision (e.g. Lighter's known local
619
610
  * API public key). Returns an empty object when the plugin has no params
620
- * to contribute for the action. Optional — providers without local state
611
+ * to contribute for the action. A choice option runs with its bound params
612
+ * alone and never reads these. Optional — providers without local state
621
613
  * can omit it entirely.
622
614
  */
623
615
  resolveSetupParams?(
@@ -628,7 +620,7 @@ export interface PerpsProviderPlugin {
628
620
  /**
629
621
  * Contribute the signer-bearing wire fields for an action — the plugin owns
630
622
  * signer identity (WHO signs), so core asks the plugin rather than resolving
631
- * a `signerAddress` itself. The descriptor's `signers` are forwarded so the
623
+ * a `signerAddress` itself. The descriptor's `signer` is forwarded so the
632
624
  * plugin can branch on signer role: a provider that signs on the user's
633
625
  * behalf with a session keypair (Hyperliquid's agent) resolves — provisioning
634
626
  * one if needed — and returns the agent address as `signerAddress`; for
@@ -644,7 +636,7 @@ export interface PerpsProviderPlugin {
644
636
  resolveActionRequest?(
645
637
  action: ActionType,
646
638
  address: Address,
647
- signers: PerpsSigner[]
639
+ signer: PerpsSigner
648
640
  ): Promise<ActionSignerContribution>
649
641
 
650
642
  /**
@@ -659,7 +651,7 @@ export interface PerpsProviderPlugin {
659
651
  * provider has no `signActions`.
660
652
  *
661
653
  * `method` mirrors the descriptor's `signingMethod`. The plugin owns every
662
- * arm, branching on the descriptor's `signers` internally: the EIP712 arm
654
+ * arm, branching on the descriptor's `signer` internally: the EIP712 arm
663
655
  * signs with the user's wallet (read from `ctx.userWallet`) or the provider's
664
656
  * session keypair (Hyperliquid's agent), and `WASM_BLOB` / `EVM_TX` sign with
665
657
  * the provider's local credential (Lighter).
@@ -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 = '18.1.0'
13
+ export const version = '19.0.0'