@lifi/perps-sdk 1.6.0 → 2.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 +9 -4
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +36 -4
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/api.d.ts +10 -1
- package/dist/cjs/types/api.d.ts.map +1 -1
- package/dist/cjs/types/config.d.ts +1 -0
- package/dist/cjs/types/config.d.ts.map +1 -1
- package/dist/cjs/types/provider.d.ts +1 -0
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/utils/switchChain.d.ts +5 -0
- package/dist/cjs/utils/switchChain.d.ts.map +1 -0
- package/dist/cjs/utils/switchChain.js +39 -0
- package/dist/cjs/utils/switchChain.js.map +1 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client/PerpsClient.d.ts +42 -7
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +69 -7
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/api.d.ts +24 -7
- package/dist/esm/types/api.d.ts.map +1 -1
- package/dist/esm/types/config.d.ts +11 -0
- package/dist/esm/types/config.d.ts.map +1 -1
- package/dist/esm/types/provider.d.ts +11 -0
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/utils/switchChain.d.ts +21 -0
- package/dist/esm/utils/switchChain.d.ts.map +1 -0
- package/dist/esm/utils/switchChain.js +51 -0
- package/dist/esm/utils/switchChain.js.map +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/client/PerpsClient.d.ts +42 -7
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/api.d.ts +24 -7
- package/dist/types/types/api.d.ts.map +1 -1
- package/dist/types/types/config.d.ts +11 -0
- package/dist/types/types/config.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +11 -0
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/utils/switchChain.d.ts +21 -0
- package/dist/types/utils/switchChain.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/client/PerpsClient.ts +86 -9
- package/src/index.ts +3 -2
- package/src/types/api.ts +29 -7
- package/src/types/config.ts +14 -0
- package/src/types/provider.ts +11 -0
- package/src/utils/switchChain.ts +73 -0
- package/src/version.ts +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -55,8 +55,8 @@ export type { FetchWithRetryOptions } from './transport/fetchWithRetry.js';
|
|
|
55
55
|
export { fetchWithRetry } from './transport/fetchWithRetry.js';
|
|
56
56
|
export type { ProviderRetryConfig, ResolvedRetryPolicy, RetryAttemptContext, RetryClassification, RetryClassifyContext, RetryConfig, RetryPolicy, } from './transport/retryPolicy.js';
|
|
57
57
|
export { DISABLED_RETRY, LIFI_REQUEST_KEY, LIFI_RETRY_DEFAULTS, resolveRetryPolicy, } from './transport/retryPolicy.js';
|
|
58
|
-
export type { BuildProviderSetupParams, CancelOrdersParams,
|
|
59
|
-
export type { HyperliquidConfig, PerpsBaseConfig, PerpsClientSigner, ProviderConfig, ProviderConfigs, RequestInterceptor, SDKRequestOptions, } from './types/config.js';
|
|
58
|
+
export type { BuildProviderSetupParams, CancelOrdersParams, GetAccountResult, GetSetupParams, ModifyOrdersParams, PerpsClientOptions, PerpsConfig, PlaceOrderParams as ClientPlaceOrderParams, PlaceTriggerOrderParams as ClientPlaceTriggerOrderParams, ProviderSetup, SendAssetActionParams, WithdrawParams, } from './types/api.js';
|
|
59
|
+
export type { HyperliquidConfig, PerpsBaseConfig, PerpsClientSigner, ProviderConfig, ProviderConfigs, RequestInterceptor, SDKRequestOptions, SwitchChainHook, } from './types/config.js';
|
|
60
60
|
export type { ActionSignerContribution, LiquidationEstimateParams, PerpsProvider, PerpsProviderPlugin, PerpsSDKClient, ProviderAccountExistsParams, ProviderGetAccountParams, ProviderGetActivityParams, ProviderGetFillsParams, ProviderGetOrderParams, ProviderGetOrdersParams, ProviderGetPositionsParams, ProviderGetQuoteParams, QuoteListener, SignActionsContext, } from './types/provider.js';
|
|
61
61
|
export { type CollateralSemantics, summarizeAccount, } from './utils/accountSummary.js';
|
|
62
62
|
export type { ExpectedPnl } from './utils/calculations.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,cAAc,mBAAmB,CAAA;AACjC,OAAO,EACL,iBAAiB,EACjB,eAAe,GAChB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAC7E,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,GAChB,MAAM,8BAA8B,CAAA;AAErC,YAAY,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,YAAY,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0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OAAO,EACL,6BAA6B,EAC7B,cAAc,GACf,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AccountConfigSetting, AccountResponse, ActionStep, ExecuteActionResponse, MarketRef, ModifyOrderInput, OrderSide, OrderType, SignedActionStep, TimeInForce, TriggerOrderInput, WithdrawalParams } from '@lifi/perps-types';
|
|
2
2
|
import type { Account, Address, WalletClient } from 'viem';
|
|
3
3
|
import type { RetryConfig } from '../transport/retryPolicy.js';
|
|
4
|
-
import type { ProviderConfigs, RequestInterceptor } from './config.js';
|
|
4
|
+
import type { ProviderConfigs, RequestInterceptor, SwitchChainHook } from './config.js';
|
|
5
5
|
import type { PerpsProviderPlugin } from './provider.js';
|
|
6
6
|
/**
|
|
7
7
|
* Configuration for {@link createPerpsClient}.
|
|
@@ -70,6 +70,12 @@ export interface PerpsClientOptions {
|
|
|
70
70
|
* a keyed `ProviderConfigs` map.
|
|
71
71
|
*/
|
|
72
72
|
providers?: PerpsProviderPlugin[] | ProviderConfigs;
|
|
73
|
+
/**
|
|
74
|
+
* Hook invoked before a USER-signed EIP-712 action is signed, to switch the
|
|
75
|
+
* user's wallet to the action's target chain. Also settable at runtime via
|
|
76
|
+
* `setSwitchChain`.
|
|
77
|
+
*/
|
|
78
|
+
switchChain?: SwitchChainHook;
|
|
73
79
|
}
|
|
74
80
|
/**
|
|
75
81
|
* Parameters for the internal `buildProviderSetup` helper that materialises
|
|
@@ -125,6 +131,21 @@ export interface WithdrawParams {
|
|
|
125
131
|
address: Address;
|
|
126
132
|
withdrawal: WithdrawalParams;
|
|
127
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Parameters for {@link PerpsClient.sendAsset}. The send-asset fields are held
|
|
136
|
+
* flat (not nested) to avoid colliding with `@lifi/perps-types`'
|
|
137
|
+
* `SendAssetParams`, which types the underlying action payload.
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
export interface SendAssetActionParams {
|
|
142
|
+
provider: string;
|
|
143
|
+
address: Address;
|
|
144
|
+
collateral: string;
|
|
145
|
+
sourceDex: string;
|
|
146
|
+
destinationDex: string;
|
|
147
|
+
amount: string;
|
|
148
|
+
}
|
|
128
149
|
/**
|
|
129
150
|
* Parameters for canceling orders.
|
|
130
151
|
*
|
|
@@ -181,9 +202,7 @@ export interface ProviderSetup {
|
|
|
181
202
|
isReady: boolean;
|
|
182
203
|
}
|
|
183
204
|
/**
|
|
184
|
-
* Parameters for
|
|
185
|
-
*
|
|
186
|
-
* @public
|
|
205
|
+
* Parameters for the internal `PerpsClient.executeProviderSetup` batch submit.
|
|
187
206
|
*/
|
|
188
207
|
export interface ExecuteProviderSetupParams {
|
|
189
208
|
/** Provider to satisfy setup for */
|
|
@@ -196,9 +215,7 @@ export interface ExecuteProviderSetupParams {
|
|
|
196
215
|
signedActions: SignedActionStep[];
|
|
197
216
|
}
|
|
198
217
|
/**
|
|
199
|
-
* Result from
|
|
200
|
-
*
|
|
201
|
-
* @public
|
|
218
|
+
* Result from the internal `PerpsClient.executeProviderSetup` batch submit.
|
|
202
219
|
*/
|
|
203
220
|
export interface ExecuteProviderSetupResult {
|
|
204
221
|
results: ExecuteActionResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/types/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CA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
9
9
|
export type PerpsClientSigner = WalletClient<any, any, Account>;
|
|
10
|
+
/**
|
|
11
|
+
* Consumer-supplied hook invoked at the SDK's signing choke point to switch the
|
|
12
|
+
* user's wallet to a USER-signed EIP-712 action's target chain. Modelled on
|
|
13
|
+
* `@lifi/sdk`'s switch-chain contract: a json-rpc wallet switches in place and
|
|
14
|
+
* resolves to the re-fetched client; a local/private-key signer resolves to a
|
|
15
|
+
* chain-bound client (or signs offline). Resolve to `undefined` to signal the
|
|
16
|
+
* switch could not be performed.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export type SwitchChainHook = (chainId: number) => Promise<PerpsClientSigner | undefined>;
|
|
10
21
|
/**
|
|
11
22
|
* Per-provider config — restricts which `markets` the WS client subscribes
|
|
12
23
|
* to. Indexed by provider key.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAE9D;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;AAE/D;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAA;AAE9C;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAAA;CAC/C;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,KACjB,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC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AAM,EACX,OAAO,EAAE,WAAW,KACjB,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;AAEvC;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;IACvC,SAAS,CAAC,EAAE,eAAe,CAAA;IAC3B,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB"}
|
|
@@ -34,6 +34,17 @@ export interface SignActionsContext {
|
|
|
34
34
|
* forwards the descriptor's `signers` as data; it does not branch on them.
|
|
35
35
|
*/
|
|
36
36
|
signers?: PerpsSigner[];
|
|
37
|
+
/**
|
|
38
|
+
* Switch `userWallet` to `chainId` and resolve the client to broadcast with.
|
|
39
|
+
* Bound by core to the consumer's `switchChain` hook and the resolved
|
|
40
|
+
* `userWallet`: a no-op returning the same client when already on `chainId`,
|
|
41
|
+
* else it switches and re-verifies, rejecting with `PerpsErrorCode.SDKError`
|
|
42
|
+
* when the switch cannot be completed. Present only when a `switchChain` hook
|
|
43
|
+
* is configured; a plugin whose legs broadcast on-chain (Lighter's `EVM_TX`)
|
|
44
|
+
* calls it per leg, and falls back to a fail-loud wrong-chain guard when it is
|
|
45
|
+
* absent (local/private-key signer, or no hook).
|
|
46
|
+
*/
|
|
47
|
+
switchToChain?: (chainId: number) => Promise<PerpsClientSigner>;
|
|
37
48
|
}
|
|
38
49
|
/**
|
|
39
50
|
* Signer-bearing wire fields a provider plugin contributes to an action's
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/types/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,MAAM,EACN,KAAK,EACL,cAAc,EACd,WAAW,EACX,WAAW,EACX,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,KAAK,EACL,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,SAAS,EACV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,aAAa,CAAA;AAEpB;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;IAChC,8FAA8F;IAC9F,QAAQ,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAA;IACvC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,CAAA;IACnC,0EAA0E;IAC1E,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAA;CACpD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,iBAAiB,CAAA;IAC9B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,WAAW,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/types/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,MAAM,EACN,KAAK,EACL,cAAc,EACd,WAAW,EACX,WAAW,EACX,QAAQ,EACR,iBA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ientSigner, SwitchChainHook } from '../types/config.js';
|
|
3
|
+
/**
|
|
4
|
+
* The chain a batch of `actions` must be signed on, or `undefined` when no
|
|
5
|
+
* wallet chain switch applies. Only USER-signed EIP-712 batches carry a target
|
|
6
|
+
* (agent-signed batches sign with a chain-bound keypair; other schemes are not
|
|
7
|
+
* EIP-712). Reads the first numeric `typedData.domain.chainId`; a batch whose
|
|
8
|
+
* steps omit `chainId` yields `undefined`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function userEip712TargetChainId(descriptor: ProviderAction, actions: ActionStep[]): number | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Ensure `wallet` is on `targetChainId` before signing, returning the wallet to
|
|
13
|
+
* sign with. Without a `switchChain` hook the wallet is returned unchanged (no
|
|
14
|
+
* throw, no RPC) — a local/private-key signer signs EIP-712 offline regardless
|
|
15
|
+
* of its transport chain. With a hook: probe the current chain via viem
|
|
16
|
+
* `getChainId`, return the wallet untouched when already on target, else invoke
|
|
17
|
+
* the hook and re-verify. Throws `PerpsErrorCode.SDKError` when the hook yields
|
|
18
|
+
* no client or a client still on the wrong chain.
|
|
19
|
+
*/
|
|
20
|
+
export declare function switchSigningChain(wallet: PerpsClientSigner, targetChainId: number, switchChain?: SwitchChainHook): Promise<PerpsClientSigner>;
|
|
21
|
+
//# sourceMappingURL=switchChain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchChain.d.ts","sourceRoot":"","sources":["../../../src/utils/switchChain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,cAAc,EACf,MAAM,mBAAmB,CAAA;AAI1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAE5E;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,UAAU,EAAE,GACpB,MAAM,GAAG,SAAS,CAcpB;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,eAAe,GAC5B,OAAO,CAAC,iBAAiB,CAAC,CAuB5B"}
|
package/dist/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "LI.FI Perps SDK for perpetuals trading",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@lifi/types": "17.82.1",
|
|
45
45
|
"partysocket": "^1.1.19",
|
|
46
46
|
"viem": "^2.48.8",
|
|
47
|
-
"@lifi/perps-types": "^1.
|
|
47
|
+
"@lifi/perps-types": "^1.12.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
@@ -30,14 +30,20 @@ import type {
|
|
|
30
30
|
PlaceOrderParams,
|
|
31
31
|
PlaceTriggerOrderParams,
|
|
32
32
|
ProviderSetup,
|
|
33
|
+
SendAssetActionParams,
|
|
33
34
|
WithdrawParams,
|
|
34
35
|
} from '../types/api.js'
|
|
36
|
+
import type { PerpsClientSigner, SwitchChainHook } from '../types/config.js'
|
|
35
37
|
import type {
|
|
36
38
|
ActionSignerContribution,
|
|
37
39
|
PerpsProvider,
|
|
38
40
|
PerpsSDKClient,
|
|
39
41
|
SignActionsContext,
|
|
40
42
|
} from '../types/provider.js'
|
|
43
|
+
import {
|
|
44
|
+
switchSigningChain,
|
|
45
|
+
userEip712TargetChainId,
|
|
46
|
+
} from '../utils/switchChain.js'
|
|
41
47
|
import { createPerpsClient } from './createPerpsClient.js'
|
|
42
48
|
import { requireProvider as resolveProvider } from './requireProvider.js'
|
|
43
49
|
|
|
@@ -75,6 +81,7 @@ export class PerpsClient {
|
|
|
75
81
|
private sdkClient: PerpsSDKClient
|
|
76
82
|
private providerMetadataCache: Map<string, Provider> = new Map()
|
|
77
83
|
private _userWallet: PerpsSDKClient['userWallet'] | undefined
|
|
84
|
+
private _switchChain: SwitchChainHook | undefined
|
|
78
85
|
|
|
79
86
|
constructor(options: PerpsClientOptions) {
|
|
80
87
|
this.sdkClient = createPerpsClient({
|
|
@@ -83,6 +90,7 @@ export class PerpsClient {
|
|
|
83
90
|
apiUrl: options.apiUrl,
|
|
84
91
|
providers: options.providers,
|
|
85
92
|
})
|
|
93
|
+
this._switchChain = options.switchChain
|
|
86
94
|
}
|
|
87
95
|
|
|
88
96
|
/**
|
|
@@ -99,6 +107,17 @@ export class PerpsClient {
|
|
|
99
107
|
})
|
|
100
108
|
}
|
|
101
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Set or replace the wallet chain-switch hook invoked before a USER-signed
|
|
112
|
+
* EIP-712 action is signed. Mirrors {@link setUserWallet}. Pass undefined to
|
|
113
|
+
* clear — cleared, a wallet on the wrong chain signs offline without a switch.
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
setSwitchChain(switchChain: SwitchChainHook | undefined): void {
|
|
118
|
+
this._switchChain = switchChain
|
|
119
|
+
}
|
|
120
|
+
|
|
102
121
|
/**
|
|
103
122
|
* The underlying low-level {@link PerpsSDKClient} (config, user wallet,
|
|
104
123
|
* provider registry) backing this instance.
|
|
@@ -185,14 +204,37 @@ export class PerpsClient {
|
|
|
185
204
|
`signingMethod '${descriptor.signingMethod}'.`
|
|
186
205
|
)
|
|
187
206
|
}
|
|
207
|
+
const userWallet = await this.resolveSigningWallet(descriptor, actions)
|
|
188
208
|
return plugin.signActions(
|
|
189
209
|
descriptor.signingMethod,
|
|
190
210
|
actions,
|
|
191
211
|
address,
|
|
192
|
-
this.buildSignActionsContext(descriptor)
|
|
212
|
+
this.buildSignActionsContext(descriptor, userWallet)
|
|
193
213
|
)
|
|
194
214
|
}
|
|
195
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Resolve the wallet that signs `actions`. For a USER-signed EIP-712 batch,
|
|
218
|
+
* switch the configured wallet to the action's target chain via the
|
|
219
|
+
* `switchChain` hook and return the switched client; the switch is transient
|
|
220
|
+
* — `sdkClient.userWallet` is never mutated. All other batches (agent-signed,
|
|
221
|
+
* non-EIP-712, or no configured wallet) return the configured wallet as-is.
|
|
222
|
+
*/
|
|
223
|
+
private async resolveSigningWallet(
|
|
224
|
+
descriptor: ProviderAction,
|
|
225
|
+
actions: ActionStep[]
|
|
226
|
+
): Promise<PerpsClientSigner | undefined> {
|
|
227
|
+
const wallet = this.sdkClient.userWallet
|
|
228
|
+
if (!wallet) {
|
|
229
|
+
return undefined
|
|
230
|
+
}
|
|
231
|
+
const targetChainId = userEip712TargetChainId(descriptor, actions)
|
|
232
|
+
if (targetChainId === undefined) {
|
|
233
|
+
return wallet
|
|
234
|
+
}
|
|
235
|
+
return switchSigningChain(wallet, targetChainId, this._switchChain)
|
|
236
|
+
}
|
|
237
|
+
|
|
196
238
|
/**
|
|
197
239
|
* Assemble the per-call context the provider plugin needs in order to sign:
|
|
198
240
|
* the end-user's wallet and the descriptor's declared `signers`. Core
|
|
@@ -200,13 +242,29 @@ export class PerpsClient {
|
|
|
200
242
|
* branch on them. Provider-owned session credentials (the Hyperliquid agent
|
|
201
243
|
* keypair, Lighter's API key) are resolved inside the provider's
|
|
202
244
|
* `signActions`, not threaded through here.
|
|
245
|
+
*
|
|
246
|
+
* `userWallet` overrides the configured wallet for this signing pass only —
|
|
247
|
+
* `resolveSigningWallet` supplies the chain-switched client without mutating
|
|
248
|
+
* `sdkClient.userWallet`.
|
|
249
|
+
*
|
|
250
|
+
* When a `switchChain` hook is configured, `switchToChain` is bound to the
|
|
251
|
+
* resolved wallet so a plugin can switch per leg mid-batch (Lighter's
|
|
252
|
+
* `EVM_TX` broadcasts); the switch stays transient — it never mutates
|
|
253
|
+
* `sdkClient.userWallet`.
|
|
203
254
|
*/
|
|
204
255
|
private buildSignActionsContext(
|
|
205
|
-
descriptor: ProviderAction
|
|
256
|
+
descriptor: ProviderAction,
|
|
257
|
+
userWallet?: PerpsClientSigner
|
|
206
258
|
): SignActionsContext {
|
|
207
259
|
const ctx: SignActionsContext = { signers: descriptor.signers }
|
|
208
|
-
|
|
209
|
-
|
|
260
|
+
const wallet = userWallet ?? this.sdkClient.userWallet
|
|
261
|
+
if (wallet !== undefined) {
|
|
262
|
+
ctx.userWallet = wallet
|
|
263
|
+
const switchChain = this._switchChain
|
|
264
|
+
if (switchChain !== undefined) {
|
|
265
|
+
ctx.switchToChain = (chainId) =>
|
|
266
|
+
switchSigningChain(wallet, chainId, switchChain)
|
|
267
|
+
}
|
|
210
268
|
}
|
|
211
269
|
return ctx
|
|
212
270
|
}
|
|
@@ -222,9 +280,8 @@ export class PerpsClient {
|
|
|
222
280
|
* no backend-bound step to submit.
|
|
223
281
|
*
|
|
224
282
|
* @throws {PerpsError} When the step's action is not declared by the provider.
|
|
225
|
-
* @public
|
|
226
283
|
*/
|
|
227
|
-
async signProviderSetupAction(
|
|
284
|
+
private async signProviderSetupAction(
|
|
228
285
|
provider: string,
|
|
229
286
|
address: Address,
|
|
230
287
|
step: ActionStep
|
|
@@ -408,10 +465,8 @@ export class PerpsClient {
|
|
|
408
465
|
* caller / `signProviderSetupAction`). Routes the batch on the first step's
|
|
409
466
|
* action and lets the plugin contribute that action's `signerAddress`.
|
|
410
467
|
* Throws on any per-step venue rejection.
|
|
411
|
-
*
|
|
412
|
-
* @public
|
|
413
468
|
*/
|
|
414
|
-
async executeProviderSetup(
|
|
469
|
+
private async executeProviderSetup(
|
|
415
470
|
params: ExecuteProviderSetupParams
|
|
416
471
|
): Promise<ExecuteProviderSetupResult> {
|
|
417
472
|
const { provider, address, setup, signedActions } = params
|
|
@@ -640,6 +695,28 @@ export class PerpsClient {
|
|
|
640
695
|
})
|
|
641
696
|
}
|
|
642
697
|
|
|
698
|
+
/**
|
|
699
|
+
* Move collateral between DEXes within the provider account. Convenience
|
|
700
|
+
* wrapper over {@link execute} with `ActionType.SEND_ASSET`; like
|
|
701
|
+
* {@link withdraw} it returns the raw {@link ExecuteActionResponse} and does
|
|
702
|
+
* not throw on a venue rejection.
|
|
703
|
+
*
|
|
704
|
+
* @throws {PerpsError} When the provider is unregistered or the action
|
|
705
|
+
* cannot be signed/submitted.
|
|
706
|
+
* @public
|
|
707
|
+
*/
|
|
708
|
+
async sendAsset(
|
|
709
|
+
params: SendAssetActionParams
|
|
710
|
+
): Promise<ExecuteActionResponse> {
|
|
711
|
+
const { provider, address, ...sendAsset } = params
|
|
712
|
+
return this.execute({
|
|
713
|
+
provider,
|
|
714
|
+
address,
|
|
715
|
+
action: ActionType.SEND_ASSET,
|
|
716
|
+
params: sendAsset,
|
|
717
|
+
})
|
|
718
|
+
}
|
|
719
|
+
|
|
643
720
|
/**
|
|
644
721
|
* Execute any action through the SDK's signing pipeline: fetch the unsigned
|
|
645
722
|
* steps, delegate signing to the provider plugin (which branches on the
|
package/src/index.ts
CHANGED
|
@@ -90,8 +90,6 @@ export {
|
|
|
90
90
|
export type {
|
|
91
91
|
BuildProviderSetupParams,
|
|
92
92
|
CancelOrdersParams,
|
|
93
|
-
ExecuteProviderSetupParams,
|
|
94
|
-
ExecuteProviderSetupResult,
|
|
95
93
|
GetAccountResult,
|
|
96
94
|
GetSetupParams,
|
|
97
95
|
ModifyOrdersParams,
|
|
@@ -100,6 +98,8 @@ export type {
|
|
|
100
98
|
PlaceOrderParams as ClientPlaceOrderParams,
|
|
101
99
|
PlaceTriggerOrderParams as ClientPlaceTriggerOrderParams,
|
|
102
100
|
ProviderSetup,
|
|
101
|
+
SendAssetActionParams,
|
|
102
|
+
WithdrawParams,
|
|
103
103
|
} from './types/api.js'
|
|
104
104
|
export type {
|
|
105
105
|
HyperliquidConfig,
|
|
@@ -109,6 +109,7 @@ export type {
|
|
|
109
109
|
ProviderConfigs,
|
|
110
110
|
RequestInterceptor,
|
|
111
111
|
SDKRequestOptions,
|
|
112
|
+
SwitchChainHook,
|
|
112
113
|
} from './types/config.js'
|
|
113
114
|
export type {
|
|
114
115
|
ActionSignerContribution,
|
package/src/types/api.ts
CHANGED
|
@@ -14,7 +14,11 @@ import type {
|
|
|
14
14
|
} from '@lifi/perps-types'
|
|
15
15
|
import type { Account, Address, WalletClient } from 'viem'
|
|
16
16
|
import type { RetryConfig } from '../transport/retryPolicy.js'
|
|
17
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
ProviderConfigs,
|
|
19
|
+
RequestInterceptor,
|
|
20
|
+
SwitchChainHook,
|
|
21
|
+
} from './config.js'
|
|
18
22
|
import type { PerpsProviderPlugin } from './provider.js'
|
|
19
23
|
|
|
20
24
|
/**
|
|
@@ -85,6 +89,12 @@ export interface PerpsClientOptions {
|
|
|
85
89
|
* a keyed `ProviderConfigs` map.
|
|
86
90
|
*/
|
|
87
91
|
providers?: PerpsProviderPlugin[] | ProviderConfigs
|
|
92
|
+
/**
|
|
93
|
+
* Hook invoked before a USER-signed EIP-712 action is signed, to switch the
|
|
94
|
+
* user's wallet to the action's target chain. Also settable at runtime via
|
|
95
|
+
* `setSwitchChain`.
|
|
96
|
+
*/
|
|
97
|
+
switchChain?: SwitchChainHook
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
/**
|
|
@@ -145,6 +155,22 @@ export interface WithdrawParams {
|
|
|
145
155
|
withdrawal: WithdrawalParams
|
|
146
156
|
}
|
|
147
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Parameters for {@link PerpsClient.sendAsset}. The send-asset fields are held
|
|
160
|
+
* flat (not nested) to avoid colliding with `@lifi/perps-types`'
|
|
161
|
+
* `SendAssetParams`, which types the underlying action payload.
|
|
162
|
+
*
|
|
163
|
+
* @public
|
|
164
|
+
*/
|
|
165
|
+
export interface SendAssetActionParams {
|
|
166
|
+
provider: string
|
|
167
|
+
address: Address
|
|
168
|
+
collateral: string
|
|
169
|
+
sourceDex: string
|
|
170
|
+
destinationDex: string
|
|
171
|
+
amount: string
|
|
172
|
+
}
|
|
173
|
+
|
|
148
174
|
/**
|
|
149
175
|
* Parameters for canceling orders.
|
|
150
176
|
*
|
|
@@ -205,9 +231,7 @@ export interface ProviderSetup {
|
|
|
205
231
|
}
|
|
206
232
|
|
|
207
233
|
/**
|
|
208
|
-
* Parameters for
|
|
209
|
-
*
|
|
210
|
-
* @public
|
|
234
|
+
* Parameters for the internal `PerpsClient.executeProviderSetup` batch submit.
|
|
211
235
|
*/
|
|
212
236
|
export interface ExecuteProviderSetupParams {
|
|
213
237
|
/** Provider to satisfy setup for */
|
|
@@ -221,9 +245,7 @@ export interface ExecuteProviderSetupParams {
|
|
|
221
245
|
}
|
|
222
246
|
|
|
223
247
|
/**
|
|
224
|
-
* Result from
|
|
225
|
-
*
|
|
226
|
-
* @public
|
|
248
|
+
* Result from the internal `PerpsClient.executeProviderSetup` batch submit.
|
|
227
249
|
*/
|
|
228
250
|
export interface ExecuteProviderSetupResult {
|
|
229
251
|
results: ExecuteActionResponse
|
package/src/types/config.ts
CHANGED
|
@@ -9,6 +9,20 @@ import type { RetryConfig } from '../transport/retryPolicy.js'
|
|
|
9
9
|
*/
|
|
10
10
|
export type PerpsClientSigner = WalletClient<any, any, Account>
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Consumer-supplied hook invoked at the SDK's signing choke point to switch the
|
|
14
|
+
* user's wallet to a USER-signed EIP-712 action's target chain. Modelled on
|
|
15
|
+
* `@lifi/sdk`'s switch-chain contract: a json-rpc wallet switches in place and
|
|
16
|
+
* resolves to the re-fetched client; a local/private-key signer resolves to a
|
|
17
|
+
* chain-bound client (or signs offline). Resolve to `undefined` to signal the
|
|
18
|
+
* switch could not be performed.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export type SwitchChainHook = (
|
|
23
|
+
chainId: number
|
|
24
|
+
) => Promise<PerpsClientSigner | undefined>
|
|
25
|
+
|
|
12
26
|
/**
|
|
13
27
|
* Per-provider config — restricts which `markets` the WS client subscribes
|
|
14
28
|
* to. Indexed by provider key.
|
package/src/types/provider.ts
CHANGED
|
@@ -63,6 +63,17 @@ export interface SignActionsContext {
|
|
|
63
63
|
* forwards the descriptor's `signers` as data; it does not branch on them.
|
|
64
64
|
*/
|
|
65
65
|
signers?: PerpsSigner[]
|
|
66
|
+
/**
|
|
67
|
+
* Switch `userWallet` to `chainId` and resolve the client to broadcast with.
|
|
68
|
+
* Bound by core to the consumer's `switchChain` hook and the resolved
|
|
69
|
+
* `userWallet`: a no-op returning the same client when already on `chainId`,
|
|
70
|
+
* else it switches and re-verifies, rejecting with `PerpsErrorCode.SDKError`
|
|
71
|
+
* when the switch cannot be completed. Present only when a `switchChain` hook
|
|
72
|
+
* is configured; a plugin whose legs broadcast on-chain (Lighter's `EVM_TX`)
|
|
73
|
+
* calls it per leg, and falls back to a fail-loud wrong-chain guard when it is
|
|
74
|
+
* absent (local/private-key signer, or no hook).
|
|
75
|
+
*/
|
|
76
|
+
switchToChain?: (chainId: number) => Promise<PerpsClientSigner>
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
/**
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ActionStep,
|
|
3
|
+
Eip712ActionStep,
|
|
4
|
+
ProviderAction,
|
|
5
|
+
} from '@lifi/perps-types'
|
|
6
|
+
import { PerpsErrorCode, PerpsSigner, SigningMethod } from '@lifi/perps-types'
|
|
7
|
+
import { getChainId } from 'viem/actions'
|
|
8
|
+
import { PerpsError } from '../errors/PerpsError.js'
|
|
9
|
+
import type { PerpsClientSigner, SwitchChainHook } from '../types/config.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The chain a batch of `actions` must be signed on, or `undefined` when no
|
|
13
|
+
* wallet chain switch applies. Only USER-signed EIP-712 batches carry a target
|
|
14
|
+
* (agent-signed batches sign with a chain-bound keypair; other schemes are not
|
|
15
|
+
* EIP-712). Reads the first numeric `typedData.domain.chainId`; a batch whose
|
|
16
|
+
* steps omit `chainId` yields `undefined`.
|
|
17
|
+
*/
|
|
18
|
+
export function userEip712TargetChainId(
|
|
19
|
+
descriptor: ProviderAction,
|
|
20
|
+
actions: ActionStep[]
|
|
21
|
+
): number | undefined {
|
|
22
|
+
if (
|
|
23
|
+
descriptor.signingMethod !== SigningMethod.EIP712 ||
|
|
24
|
+
!descriptor.signers.includes(PerpsSigner.USER)
|
|
25
|
+
) {
|
|
26
|
+
return undefined
|
|
27
|
+
}
|
|
28
|
+
for (const step of actions) {
|
|
29
|
+
const chainId = (step as Eip712ActionStep).typedData?.domain?.chainId
|
|
30
|
+
if (typeof chainId === 'number') {
|
|
31
|
+
return chainId
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Ensure `wallet` is on `targetChainId` before signing, returning the wallet to
|
|
39
|
+
* sign with. Without a `switchChain` hook the wallet is returned unchanged (no
|
|
40
|
+
* throw, no RPC) — a local/private-key signer signs EIP-712 offline regardless
|
|
41
|
+
* of its transport chain. With a hook: probe the current chain via viem
|
|
42
|
+
* `getChainId`, return the wallet untouched when already on target, else invoke
|
|
43
|
+
* the hook and re-verify. Throws `PerpsErrorCode.SDKError` when the hook yields
|
|
44
|
+
* no client or a client still on the wrong chain.
|
|
45
|
+
*/
|
|
46
|
+
export async function switchSigningChain(
|
|
47
|
+
wallet: PerpsClientSigner,
|
|
48
|
+
targetChainId: number,
|
|
49
|
+
switchChain?: SwitchChainHook
|
|
50
|
+
): Promise<PerpsClientSigner> {
|
|
51
|
+
if (!switchChain) {
|
|
52
|
+
return wallet
|
|
53
|
+
}
|
|
54
|
+
const currentChainId = await getChainId(wallet)
|
|
55
|
+
if (currentChainId === targetChainId) {
|
|
56
|
+
return wallet
|
|
57
|
+
}
|
|
58
|
+
const switched = await switchChain(targetChainId)
|
|
59
|
+
if (!switched) {
|
|
60
|
+
throw new PerpsError(
|
|
61
|
+
PerpsErrorCode.SDKError,
|
|
62
|
+
`Wallet chain switch to ${targetChainId} was not completed.`
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
const switchedChainId = await getChainId(switched)
|
|
66
|
+
if (switchedChainId !== targetChainId) {
|
|
67
|
+
throw new PerpsError(
|
|
68
|
+
PerpsErrorCode.SDKError,
|
|
69
|
+
`Wallet is on chain ${switchedChainId} but chain ${targetChainId} is required to sign.`
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
return switched
|
|
73
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/perps-sdk'
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '2.0.0'
|