@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.
- package/dist/cjs/client/PerpsClient.d.ts +13 -7
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +141 -52
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/api.d.ts +4 -2
- package/dist/cjs/types/api.d.ts.map +1 -1
- package/dist/cjs/types/provider.d.ts +4 -5
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/utils/setupActions.d.ts +4 -2
- package/dist/cjs/utils/setupActions.d.ts.map +1 -1
- package/dist/cjs/utils/setupActions.js +9 -1
- package/dist/cjs/utils/setupActions.js.map +1 -1
- package/dist/cjs/utils/switchChain.js +1 -1
- package/dist/cjs/utils/switchChain.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client/PerpsClient.d.ts +62 -54
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +204 -100
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/api.d.ts +31 -14
- package/dist/esm/types/api.d.ts.map +1 -1
- package/dist/esm/types/provider.d.ts +21 -27
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/utils/setupActions.d.ts +17 -8
- package/dist/esm/utils/setupActions.d.ts.map +1 -1
- package/dist/esm/utils/setupActions.js +20 -7
- package/dist/esm/utils/setupActions.js.map +1 -1
- package/dist/esm/utils/switchChain.js +1 -1
- package/dist/esm/utils/switchChain.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/client/PerpsClient.d.ts +62 -54
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/api.d.ts +31 -14
- package/dist/types/types/api.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +21 -27
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/utils/setupActions.d.ts +17 -8
- package/dist/types/utils/setupActions.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/client/PerpsClient.ts +284 -129
- package/src/index.ts +4 -1
- package/src/types/api.ts +32 -14
- package/src/types/provider.ts +21 -29
- package/src/utils/setupActions.ts +27 -13
- package/src/utils/switchChain.ts +1 -1
- 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 {
|
|
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
|
-
|
|
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
|
|
75
|
-
*
|
|
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:
|
|
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
|
-
* `
|
|
345
|
-
*
|
|
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
|
-
/**
|
|
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
|
|
363
|
-
* its satisfied state, ordered by `sequence`. SDK-
|
|
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
|
|
397
|
-
*
|
|
398
|
-
*
|
|
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
|
|
421
|
+
/** SDK-projected current state of every `Provider.setup` descriptor. */
|
|
404
422
|
settings: AccountConfigSetting[]
|
|
405
423
|
}
|
|
406
424
|
|
package/src/types/provider.ts
CHANGED
|
@@ -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
|
|
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, `
|
|
92
|
-
* forwards the descriptor's `
|
|
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
|
-
|
|
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
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
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.
|
|
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
|
-
*
|
|
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
|
|
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:
|
|
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.
|
|
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 `
|
|
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
|
-
|
|
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 `
|
|
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 {
|
|
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
|
|
6
|
-
*
|
|
7
|
-
* signs on its own
|
|
8
|
-
*
|
|
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
|
|
11
|
-
*
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
}
|
package/src/utils/switchChain.ts
CHANGED
package/src/version.ts
CHANGED