@lifi/perps-sdk 15.0.0 → 17.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/README.md +38 -0
- package/dist/cjs/client/PerpsClient.d.ts +7 -2
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +67 -11
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/index.d.ts +4 -5
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +6 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/registry/assetRegistry.d.ts +2 -1
- package/dist/cjs/registry/assetRegistry.d.ts.map +1 -1
- package/dist/cjs/registry/assetRegistry.js +11 -1
- package/dist/cjs/registry/assetRegistry.js.map +1 -1
- package/dist/cjs/types/provider.d.ts +7 -2
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/types/withdrawal.d.ts +2 -0
- package/dist/cjs/types/withdrawal.d.ts.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/websocket/decodeChain.d.ts +11 -0
- package/dist/cjs/websocket/decodeChain.d.ts.map +1 -0
- package/dist/cjs/websocket/decodeChain.js +37 -0
- package/dist/cjs/websocket/decodeChain.js.map +1 -0
- package/dist/esm/client/PerpsClient.d.ts +39 -10
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +109 -20
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/index.d.ts +4 -5
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/registry/assetRegistry.d.ts +7 -1
- package/dist/esm/registry/assetRegistry.d.ts.map +1 -1
- package/dist/esm/registry/assetRegistry.js +14 -0
- package/dist/esm/registry/assetRegistry.js.map +1 -1
- package/dist/esm/types/provider.d.ts +29 -7
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/types/withdrawal.d.ts +12 -0
- package/dist/esm/types/withdrawal.d.ts.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/websocket/decodeChain.d.ts +30 -0
- package/dist/esm/websocket/decodeChain.d.ts.map +1 -0
- package/dist/esm/websocket/decodeChain.js +44 -0
- package/dist/esm/websocket/decodeChain.js.map +1 -0
- package/dist/types/client/PerpsClient.d.ts +39 -10
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/registry/assetRegistry.d.ts +7 -1
- package/dist/types/registry/assetRegistry.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +29 -7
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/types/withdrawal.d.ts +12 -0
- package/dist/types/types/withdrawal.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/websocket/decodeChain.d.ts +30 -0
- package/dist/types/websocket/decodeChain.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/client/PerpsClient.ts +146 -28
- package/src/index.ts +8 -7
- package/src/registry/assetRegistry.ts +16 -1
- package/src/types/provider.ts +34 -9
- package/src/types/withdrawal.ts +12 -0
- package/src/version.ts +1 -1
- package/src/websocket/decodeChain.ts +54 -0
- package/dist/cjs/utils/accountSummary.d.ts +0 -4
- package/dist/cjs/utils/accountSummary.d.ts.map +0 -1
- package/dist/cjs/utils/accountSummary.js +0 -35
- package/dist/cjs/utils/accountSummary.js.map +0 -1
- package/dist/cjs/utils/transferMargin.d.ts +0 -7
- package/dist/cjs/utils/transferMargin.d.ts.map +0 -1
- package/dist/cjs/utils/transferMargin.js +0 -50
- package/dist/cjs/utils/transferMargin.js.map +0 -1
- package/dist/esm/utils/accountSummary.d.ts +0 -32
- package/dist/esm/utils/accountSummary.d.ts.map +0 -1
- package/dist/esm/utils/accountSummary.js +0 -46
- package/dist/esm/utils/accountSummary.js.map +0 -1
- package/dist/esm/utils/transferMargin.d.ts +0 -24
- package/dist/esm/utils/transferMargin.d.ts.map +0 -1
- package/dist/esm/utils/transferMargin.js +0 -56
- package/dist/esm/utils/transferMargin.js.map +0 -1
- package/dist/types/utils/accountSummary.d.ts +0 -32
- package/dist/types/utils/accountSummary.d.ts.map +0 -1
- package/dist/types/utils/transferMargin.d.ts +0 -24
- package/dist/types/utils/transferMargin.d.ts.map +0 -1
- package/src/utils/accountSummary.ts +0 -90
- package/src/utils/transferMargin.ts +0 -98
|
@@ -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,YAAY,EACZ,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,MAAM,EACN,SAAS,EACT,cAAc,EACd,KAAK,EACL,WAAW,EACX,cAAc,EACd,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,wBAAwB,EACxB,QAAQ,EACR,
|
|
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,YAAY,EACZ,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,MAAM,EACN,SAAS,EACT,cAAc,EACd,KAAK,EACL,WAAW,EACX,cAAc,EACd,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,wBAAwB,EACxB,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,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Q,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAA;IAE/D;;;;;;;;;OASG;IACH,aAAa,CACX,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,EAAE,cAAc,EAAE,GACxB,oBAAoB,EAAE,CAAA;IAEzB;;;;;;;OAOG;IACH,kBAAkB,CAAC,CACjB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAEnC;;;;;;;;;;;;;;;OAeG;IACH,oBAAoB,CAAC,CACnB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,WAAW,EAAE,GACrB,OAAO,CAAC,wBAAwB,CAAC,CAAA;IAEpC;;;;;;;;;;;;;;;;OAgBG;IACH,WAAW,CAAC,CACV,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,UAAU,EAAE,EACnB,OAAO,EAAE,OAAO,EAChB,GAAG,CAAC,EAAE,kBAAkB,GACvB,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAA;IAE9B;;;;OAIG;IACH,gBAAgB,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE3E;;;;;;;;OAQG;IACH,mBAAmB,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACzD;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAA"}
|
|
@@ -20,6 +20,12 @@ export interface ProviderWithdrawableBalance {
|
|
|
20
20
|
route: WithdrawalRoute;
|
|
21
21
|
/** Withdrawable amount in the asset's own units. Always greater than zero. */
|
|
22
22
|
available: string;
|
|
23
|
+
/**
|
|
24
|
+
* Flat venue fee on a withdrawal from this row, in the asset's own units.
|
|
25
|
+
* Absent when the venue publishes no fee for the asset. The client rejects a
|
|
26
|
+
* value that is not a non-negative decimal.
|
|
27
|
+
*/
|
|
28
|
+
withdrawalFee?: string;
|
|
23
29
|
}
|
|
24
30
|
/**
|
|
25
31
|
* One withdrawable `(asset, route)` selection a caller can act on: the amount
|
|
@@ -33,5 +39,11 @@ export interface WithdrawableBalance {
|
|
|
33
39
|
route: WithdrawalRoute;
|
|
34
40
|
/** Withdrawable amount in the asset's own units. */
|
|
35
41
|
available: string;
|
|
42
|
+
/**
|
|
43
|
+
* Flat venue fee on a withdrawal from this row, in the asset's own units. An
|
|
44
|
+
* amount at or below it delivers nothing. Absent when the venue publishes no
|
|
45
|
+
* fee for the asset.
|
|
46
|
+
*/
|
|
47
|
+
withdrawalFee?: string;
|
|
36
48
|
}
|
|
37
49
|
//# sourceMappingURL=withdrawal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/types/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAE9C;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IAC1C,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,eAAe,CAAA;IACtB,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/types/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAE9C;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IAC1C,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,eAAe,CAAA;IACtB,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,CAAA;IACZ,KAAK,EAAE,eAAe,CAAA;IACtB,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frame semantics of a {@link DecodeChain}:
|
|
3
|
+
* - `'every'`: every frame decodes and applies in arrival order — required for
|
|
4
|
+
* delta-carrying channels, where dropping a frame corrupts downstream state.
|
|
5
|
+
* - `'latest'`: frames queued behind an in-flight decode coalesce to the
|
|
6
|
+
* newest — for snapshot-like channels, where a newer frame supersedes
|
|
7
|
+
* anything still waiting.
|
|
8
|
+
*/
|
|
9
|
+
export type DecodeChainMode = 'every' | 'latest';
|
|
10
|
+
/**
|
|
11
|
+
* Serializes async WS frame decodes so results apply in arrival order.
|
|
12
|
+
* In `'latest'` mode a backlog (e.g. queued behind a main-thread stall)
|
|
13
|
+
* collapses to its newest frame instead of replaying every stale decode.
|
|
14
|
+
* Decode failures are reported to `onError` and never break the chain.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DecodeChain {
|
|
17
|
+
private readonly mode;
|
|
18
|
+
private readonly onError;
|
|
19
|
+
private tail;
|
|
20
|
+
private queued;
|
|
21
|
+
constructor(mode: DecodeChainMode, onError: (error: unknown) => void);
|
|
22
|
+
push(decode: () => Promise<void>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Detach on connection teardown: drops the queued latest-mode decode and
|
|
25
|
+
* starts subsequent pushes on a fresh chain. A decode already in flight
|
|
26
|
+
* still settles.
|
|
27
|
+
*/
|
|
28
|
+
reset(): void;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=decodeChain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeChain.d.ts","sourceRoot":"","sources":["../../../src/websocket/decodeChain.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEhD;;;;;GAKG;AACH,qBAAa,WAAW;IAKpB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL1B,OAAO,CAAC,IAAI,CAAmC;IAC/C,OAAO,CAAC,MAAM,CAAmC;gBAG9B,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI;IAGpD,IAAI,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAmBvC;;;;OAIG;IACH,KAAK,IAAI,IAAI;CAId"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"description": "LI.FI Perps SDK for perpetuals trading",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"big.js": "^7.0.1",
|
|
47
47
|
"partysocket": "^1.1.19",
|
|
48
48
|
"viem": "^2.55.18",
|
|
49
|
-
"@lifi/perps-types": "^
|
|
49
|
+
"@lifi/perps-types": "^16.0.0"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ActionParamsMap,
|
|
5
5
|
ActionResult,
|
|
6
6
|
ActionStep,
|
|
7
|
+
AvailableToTrade,
|
|
7
8
|
CreateActionResponse,
|
|
8
9
|
ExecuteActionResponse,
|
|
9
10
|
MarketRef,
|
|
@@ -13,7 +14,6 @@ import type {
|
|
|
13
14
|
OrdersResponse,
|
|
14
15
|
PortfolioHistoryResponse,
|
|
15
16
|
Position,
|
|
16
|
-
PositionMarginConstraints,
|
|
17
17
|
Provider,
|
|
18
18
|
ProviderAction,
|
|
19
19
|
SignedActionStep,
|
|
@@ -28,7 +28,8 @@ import {
|
|
|
28
28
|
import Big from 'big.js'
|
|
29
29
|
import type { Address } from 'viem'
|
|
30
30
|
import { PerpsError } from '../errors/PerpsError.js'
|
|
31
|
-
import { getAssetRegistry } from '../registry/assetRegistry.js'
|
|
31
|
+
import { getAssetRegistry, toAssetDisplay } from '../registry/assetRegistry.js'
|
|
32
|
+
import { getMarketRegistry } from '../registry/marketRegistry.js'
|
|
32
33
|
import { createAction } from '../services/createAction.js'
|
|
33
34
|
import { executeAction } from '../services/executeAction.js'
|
|
34
35
|
import { getAccount as fetchAccount } from '../services/getAccount.js'
|
|
@@ -87,6 +88,14 @@ import {
|
|
|
87
88
|
import { createPerpsClient } from './createPerpsClient.js'
|
|
88
89
|
import { requireProvider as resolveProvider } from './requireProvider.js'
|
|
89
90
|
|
|
91
|
+
function isNonNegativeDecimal(value: string): boolean {
|
|
92
|
+
try {
|
|
93
|
+
return new Big(value).gte(0)
|
|
94
|
+
} catch {
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
90
99
|
/**
|
|
91
100
|
* Look up an action's descriptor in the provider's metadata. Throws if the
|
|
92
101
|
* action isn't declared — defensive: better to fail loudly than to mis-sign.
|
|
@@ -109,6 +118,32 @@ function findActionDescriptor(
|
|
|
109
118
|
return descriptor
|
|
110
119
|
}
|
|
111
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Split an ordered `createAction` batch into consecutive runs of steps that
|
|
123
|
+
* share one descriptor. A batch is a chain and may mix descriptors — a
|
|
124
|
+
* Hyperliquid `placeOrder` can arrive with a USER-signed builder-fee approval
|
|
125
|
+
* ahead of the SDK-signed order — and each run must be signed by its own
|
|
126
|
+
* descriptor's signer.
|
|
127
|
+
*
|
|
128
|
+
* @throws {PerpsError} When a step's action is not declared by the provider.
|
|
129
|
+
*/
|
|
130
|
+
function groupStepsByDescriptor(
|
|
131
|
+
metadata: Provider,
|
|
132
|
+
steps: ActionStep[]
|
|
133
|
+
): { descriptor: ProviderAction; steps: ActionStep[] }[] {
|
|
134
|
+
const groups: { descriptor: ProviderAction; steps: ActionStep[] }[] = []
|
|
135
|
+
for (const step of steps) {
|
|
136
|
+
const descriptor = findActionDescriptor(metadata, step.action)
|
|
137
|
+
const current = groups.at(-1)
|
|
138
|
+
if (current !== undefined && current.descriptor.type === descriptor.type) {
|
|
139
|
+
current.steps.push(step)
|
|
140
|
+
continue
|
|
141
|
+
}
|
|
142
|
+
groups.push({ descriptor, steps: [step] })
|
|
143
|
+
}
|
|
144
|
+
return groups
|
|
145
|
+
}
|
|
146
|
+
|
|
112
147
|
/**
|
|
113
148
|
* The primary high-level perps API: wraps a {@link PerpsSDKClient} and owns the
|
|
114
149
|
* end-to-end signing pipeline for provider setup, orders, and account-level
|
|
@@ -241,15 +276,21 @@ export class PerpsClient {
|
|
|
241
276
|
}
|
|
242
277
|
|
|
243
278
|
/**
|
|
244
|
-
* Delegate signing of `actions` to the provider plugin
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
279
|
+
* Delegate signing of `actions` to the provider plugin, one call per
|
|
280
|
+
* consecutive run of steps sharing a descriptor. Each call carries that
|
|
281
|
+
* descriptor's `signingMethod` and `signers`, so a mixed batch signs every
|
|
282
|
+
* step with the signer its own descriptor declares; the signed steps come
|
|
283
|
+
* back in the batch's original order. The plugin owns every signing arm and
|
|
284
|
+
* branches on `signers` internally, reading the end-user's wallet from the
|
|
285
|
+
* {@link SignActionsContext} when an arm signs as the user.
|
|
286
|
+
*
|
|
287
|
+
* @throws {PerpsError} When a step's action is not declared by the provider,
|
|
288
|
+
* or the plugin implements no `signActions`.
|
|
248
289
|
*/
|
|
249
290
|
private async delegateSignActions(
|
|
250
291
|
provider: string,
|
|
251
292
|
address: Address,
|
|
252
|
-
|
|
293
|
+
metadata: Provider,
|
|
253
294
|
actions: ActionStep[],
|
|
254
295
|
onProgress?: (progress: SignActionProgress) => void
|
|
255
296
|
): Promise<SignedActionStep[]> {
|
|
@@ -257,17 +298,25 @@ export class PerpsClient {
|
|
|
257
298
|
if (typeof plugin.signActions !== 'function') {
|
|
258
299
|
throw new PerpsError(
|
|
259
300
|
PerpsErrorCode.SDKError,
|
|
260
|
-
`Provider '${provider}' does not implement signActions
|
|
261
|
-
`signingMethod '${descriptor.signingMethod}'.`
|
|
301
|
+
`Provider '${provider}' does not implement signActions.`
|
|
262
302
|
)
|
|
263
303
|
}
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
304
|
+
const signed: SignedActionStep[] = []
|
|
305
|
+
for (const group of groupStepsByDescriptor(metadata, actions)) {
|
|
306
|
+
const userWallet = await this.resolveSigningWallet(
|
|
307
|
+
group.descriptor,
|
|
308
|
+
group.steps
|
|
309
|
+
)
|
|
310
|
+
signed.push(
|
|
311
|
+
...(await plugin.signActions(
|
|
312
|
+
group.descriptor.signingMethod,
|
|
313
|
+
group.steps,
|
|
314
|
+
address,
|
|
315
|
+
this.buildSignActionsContext(group.descriptor, userWallet, onProgress)
|
|
316
|
+
))
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
return signed
|
|
271
320
|
}
|
|
272
321
|
|
|
273
322
|
/**
|
|
@@ -409,11 +458,10 @@ export class PerpsClient {
|
|
|
409
458
|
step: ActionStep
|
|
410
459
|
): Promise<SignedActionStep | undefined> {
|
|
411
460
|
const metadata = await this.getProviderMetadata(provider)
|
|
412
|
-
const descriptor = findActionDescriptor(metadata, step.action)
|
|
413
461
|
const [signed] = await this.delegateSignActions(
|
|
414
462
|
provider,
|
|
415
463
|
address,
|
|
416
|
-
|
|
464
|
+
metadata,
|
|
417
465
|
[step]
|
|
418
466
|
)
|
|
419
467
|
return signed
|
|
@@ -499,17 +547,70 @@ export class PerpsClient {
|
|
|
499
547
|
}
|
|
500
548
|
|
|
501
549
|
/**
|
|
502
|
-
*
|
|
503
|
-
*
|
|
550
|
+
* The amounts `params.address` can still buy and sell on one market, in
|
|
551
|
+
* that market's margin asset. The order panel reads this per-market figure;
|
|
552
|
+
* account displays read the account-scoped
|
|
553
|
+
* {@link AccountSummary.availableMargin} instead.
|
|
554
|
+
*
|
|
555
|
+
* Providers that read a per-market figure answer it directly. For every
|
|
556
|
+
* other provider this falls back to the account summary, so both sides
|
|
557
|
+
* equal `availableMargin` and the asset is the market's quote asset.
|
|
558
|
+
*
|
|
559
|
+
* @throws {PerpsError} When the provider plugin is not registered, or the
|
|
560
|
+
* market is unknown to the provider's market registry.
|
|
561
|
+
* @public
|
|
562
|
+
*/
|
|
563
|
+
async getAvailableToTrade(
|
|
564
|
+
params: {
|
|
565
|
+
provider: string
|
|
566
|
+
address: Address
|
|
567
|
+
marketId: string
|
|
568
|
+
},
|
|
569
|
+
options?: SDKRequestOptions
|
|
570
|
+
): Promise<AvailableToTrade> {
|
|
571
|
+
const plugin = this.requireProvider(params.provider)
|
|
572
|
+
const perMarket = await plugin.getAvailableToTrade?.(
|
|
573
|
+
{ address: params.address, marketId: params.marketId },
|
|
574
|
+
options
|
|
575
|
+
)
|
|
576
|
+
if (perMarket !== undefined) {
|
|
577
|
+
return perMarket
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const registry = getMarketRegistry(this.sdkClient, params.provider)
|
|
581
|
+
await registry.sync()
|
|
582
|
+
const market = registry.require(params.marketId)
|
|
583
|
+
const account = await fetchAccount(
|
|
584
|
+
this.sdkClient,
|
|
585
|
+
{ provider: params.provider, address: params.address },
|
|
586
|
+
options
|
|
587
|
+
)
|
|
588
|
+
const { availableMargin } = plugin.getAccountSummary(
|
|
589
|
+
account,
|
|
590
|
+
account.positions
|
|
591
|
+
)
|
|
592
|
+
return {
|
|
593
|
+
providerId: market.providerId,
|
|
594
|
+
marketId: market.id,
|
|
595
|
+
asset: toAssetDisplay(market.quoteAsset),
|
|
596
|
+
buy: availableMargin,
|
|
597
|
+
sell: availableMargin,
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Resolve the margin that can be removed from `position`, from the owning
|
|
603
|
+
* provider's venue margin rules. Returns `undefined` when the position has
|
|
604
|
+
* no individual margin adjustment and `'0'` when it accepts no removal.
|
|
504
605
|
*
|
|
606
|
+
* @throws {PerpsError} `ValidationError` when a `Position` decimal that the
|
|
607
|
+
* venue formula reads is malformed.
|
|
505
608
|
* @public
|
|
506
609
|
*/
|
|
507
|
-
|
|
508
|
-
position: Position
|
|
509
|
-
): PositionMarginConstraints | undefined {
|
|
610
|
+
getPositionRemovableMargin(position: Position): string | undefined {
|
|
510
611
|
return this.requireProvider(
|
|
511
612
|
position.market.providerId
|
|
512
|
-
).
|
|
613
|
+
).positionRemovableMargin(position)
|
|
513
614
|
}
|
|
514
615
|
|
|
515
616
|
/**
|
|
@@ -570,8 +671,9 @@ export class PerpsClient {
|
|
|
570
671
|
*
|
|
571
672
|
* @returns `undefined` when the registered plugin declares no withdrawable
|
|
572
673
|
* read.
|
|
573
|
-
* @throws {PerpsError} When the provider plugin is not registered,
|
|
574
|
-
* the plugin read or the asset sync fails
|
|
674
|
+
* @throws {PerpsError} When the provider plugin is not registered, when
|
|
675
|
+
* either the plugin read or the asset sync fails, or when a row's
|
|
676
|
+
* `withdrawalFee` is not a non-negative decimal.
|
|
575
677
|
* @public
|
|
576
678
|
*/
|
|
577
679
|
async getWithdrawableBalances(
|
|
@@ -607,7 +709,23 @@ export class PerpsClient {
|
|
|
607
709
|
return []
|
|
608
710
|
}
|
|
609
711
|
}
|
|
610
|
-
|
|
712
|
+
if (row.withdrawalFee === undefined) {
|
|
713
|
+
return [{ asset, route: row.route, available: row.available }]
|
|
714
|
+
}
|
|
715
|
+
if (!isNonNegativeDecimal(row.withdrawalFee)) {
|
|
716
|
+
throw new PerpsError(
|
|
717
|
+
PerpsErrorCode.SDKError,
|
|
718
|
+
`Provider '${params.provider}' row for asset '${asset.id}' has a \`withdrawalFee\` that is not a non-negative decimal: '${row.withdrawalFee}'.`
|
|
719
|
+
)
|
|
720
|
+
}
|
|
721
|
+
return [
|
|
722
|
+
{
|
|
723
|
+
asset,
|
|
724
|
+
route: row.route,
|
|
725
|
+
available: row.available,
|
|
726
|
+
withdrawalFee: row.withdrawalFee,
|
|
727
|
+
},
|
|
728
|
+
]
|
|
611
729
|
})
|
|
612
730
|
}
|
|
613
731
|
|
|
@@ -1218,7 +1336,7 @@ export class PerpsClient {
|
|
|
1218
1336
|
const signedActions = await this.delegateSignActions(
|
|
1219
1337
|
provider,
|
|
1220
1338
|
address,
|
|
1221
|
-
|
|
1339
|
+
metadata,
|
|
1222
1340
|
actions,
|
|
1223
1341
|
onProgress
|
|
1224
1342
|
)
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,11 @@ export { PerpsClient } from './client/PerpsClient.js'
|
|
|
19
19
|
export { PerpsErrorMessage } from './errors/constants.js'
|
|
20
20
|
export { PerpsError } from './errors/PerpsError.js'
|
|
21
21
|
// Registries
|
|
22
|
-
export {
|
|
22
|
+
export {
|
|
23
|
+
AssetRegistry,
|
|
24
|
+
getAssetRegistry,
|
|
25
|
+
toAssetDisplay,
|
|
26
|
+
} from './registry/assetRegistry.js'
|
|
23
27
|
export type { DefaultMarketProvider } from './registry/marketRegistry.js'
|
|
24
28
|
export {
|
|
25
29
|
DEFAULT_MARKET_ID,
|
|
@@ -152,6 +156,7 @@ export type {
|
|
|
152
156
|
ProviderAccountExistsParams,
|
|
153
157
|
ProviderGetAccountParams,
|
|
154
158
|
ProviderGetActivityParams,
|
|
159
|
+
ProviderGetAvailableToTradeParams,
|
|
155
160
|
ProviderGetDepositFlowParams,
|
|
156
161
|
ProviderGetFillsParams,
|
|
157
162
|
ProviderGetMarketSettingsParams,
|
|
@@ -170,10 +175,6 @@ export type {
|
|
|
170
175
|
WithdrawableBalance,
|
|
171
176
|
WithdrawalRoute,
|
|
172
177
|
} from './types/withdrawal.js'
|
|
173
|
-
export {
|
|
174
|
-
type CollateralSemantics,
|
|
175
|
-
summarizeAccount,
|
|
176
|
-
} from './utils/accountSummary.js'
|
|
177
178
|
export { paginateActivity } from './utils/activityPaging.js'
|
|
178
179
|
export type { ExpectedPnl } from './utils/calculations.js'
|
|
179
180
|
export {
|
|
@@ -251,14 +252,14 @@ export {
|
|
|
251
252
|
signTypedData,
|
|
252
253
|
signTypedDataWithSigner,
|
|
253
254
|
} from './utils/signTypedData.js'
|
|
254
|
-
export type { RemovableIsolatedMarginParams } from './utils/transferMargin.js'
|
|
255
|
-
export { removableIsolatedMargin } from './utils/transferMargin.js'
|
|
256
255
|
export { fromBaseUnits, fromBaseUnitsNumber } from './utils/units.js'
|
|
257
256
|
export { validateMargin } from './utils/validation.js'
|
|
258
257
|
export { createWarnOnce } from './utils/warnOnce.js'
|
|
259
258
|
// Version
|
|
260
259
|
export { name, version } from './version.js'
|
|
261
260
|
export { cachePromise } from './websocket/cachePromise.js'
|
|
261
|
+
export type { DecodeChainMode } from './websocket/decodeChain.js'
|
|
262
|
+
export { DecodeChain } from './websocket/decodeChain.js'
|
|
262
263
|
export type {
|
|
263
264
|
PerpsWsClientOptions,
|
|
264
265
|
WsProviderFactory,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Asset, AssetsResponse } from '@lifi/perps-types'
|
|
1
|
+
import type { Asset, AssetDisplay, AssetsResponse } from '@lifi/perps-types'
|
|
2
2
|
import { PerpsErrorCode } from '@lifi/perps-types'
|
|
3
3
|
import { PerpsError } from '../errors/PerpsError.js'
|
|
4
4
|
import { buildUrl, request } from '../transport/request.js'
|
|
@@ -59,6 +59,21 @@ export class AssetRegistry extends ReferenceDataRegistry<Asset> {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Project an {@link Asset} to the identity and labels a display needs.
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
export const toAssetDisplay = (asset: Asset): AssetDisplay => ({
|
|
68
|
+
providerId: asset.providerId,
|
|
69
|
+
id: asset.id,
|
|
70
|
+
displaySymbol: asset.displaySymbol,
|
|
71
|
+
logoURI: asset.logoURI,
|
|
72
|
+
...(asset.displayName === undefined
|
|
73
|
+
? {}
|
|
74
|
+
: { displayName: asset.displayName }),
|
|
75
|
+
})
|
|
76
|
+
|
|
62
77
|
const registries = new WeakMap<PerpsSDKClient, Map<string, AssetRegistry>>()
|
|
63
78
|
|
|
64
79
|
/**
|
package/src/types/provider.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
ActionType,
|
|
9
9
|
ActivitiesResponse,
|
|
10
10
|
ActivityType,
|
|
11
|
+
AvailableToTrade,
|
|
11
12
|
FillsResponse,
|
|
12
13
|
Market,
|
|
13
14
|
MarketRef,
|
|
@@ -20,7 +21,6 @@ import type {
|
|
|
20
21
|
PortfolioHistoryRange,
|
|
21
22
|
PortfolioHistoryResponse,
|
|
22
23
|
Position,
|
|
23
|
-
PositionMarginConstraints,
|
|
24
24
|
PositionsResponse,
|
|
25
25
|
ProviderAction,
|
|
26
26
|
Quote,
|
|
@@ -216,6 +216,17 @@ export interface ProviderGetMarketSettingsParams {
|
|
|
216
216
|
market: MarketRef
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Read params for {@link PerpsProviderPlugin.getAvailableToTrade}.
|
|
221
|
+
*
|
|
222
|
+
* @public
|
|
223
|
+
*/
|
|
224
|
+
export interface ProviderGetAvailableToTradeParams {
|
|
225
|
+
address: Address
|
|
226
|
+
/** The market's opaque `Market.id` (not a display symbol). */
|
|
227
|
+
marketId: string
|
|
228
|
+
}
|
|
229
|
+
|
|
219
230
|
/**
|
|
220
231
|
* Read params for {@link PerpsProvider.getOrders}.
|
|
221
232
|
*
|
|
@@ -442,6 +453,19 @@ export interface PerpsProviderPlugin {
|
|
|
442
453
|
options?: SDKRequestOptions
|
|
443
454
|
): Promise<MarketSettings | undefined>
|
|
444
455
|
|
|
456
|
+
/**
|
|
457
|
+
* The amounts the account can still buy and sell on one market, in that
|
|
458
|
+
* market's margin asset. Optional because venues expose this unevenly:
|
|
459
|
+
* Hyperliquid reads it directly (`activeAssetData`), other venues publish
|
|
460
|
+
* only an account-scoped figure. `undefined` means the venue has nothing
|
|
461
|
+
* to read for this market, and the caller falls back to the account
|
|
462
|
+
* summary.
|
|
463
|
+
*/
|
|
464
|
+
getAvailableToTrade?(
|
|
465
|
+
params: ProviderGetAvailableToTradeParams,
|
|
466
|
+
options?: SDKRequestOptions
|
|
467
|
+
): Promise<AvailableToTrade | undefined>
|
|
468
|
+
|
|
445
469
|
getOrders(
|
|
446
470
|
params: ProviderGetOrdersParams,
|
|
447
471
|
options?: SDKRequestOptions
|
|
@@ -538,16 +562,17 @@ export interface PerpsProviderPlugin {
|
|
|
538
562
|
): number | undefined
|
|
539
563
|
|
|
540
564
|
/**
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
565
|
+
* Margin that can be removed from `position` under the venue margin rules,
|
|
566
|
+
* as an exact decimal string rounded down to the venue amount increment.
|
|
567
|
+
* Pure — each provider reads its own venue meaning of `Position.marginUsed`.
|
|
544
568
|
*
|
|
545
|
-
* @returns `undefined` when
|
|
546
|
-
* adjustment (for example a cross position or a cross-only venue)
|
|
569
|
+
* @returns `undefined` when the position has no individual margin
|
|
570
|
+
* adjustment (for example a cross position or a cross-only venue), and
|
|
571
|
+
* `'0'` when the venue accepts no margin removal for it.
|
|
572
|
+
* @throws {PerpsError} `ValidationError` when a `Position` decimal that the
|
|
573
|
+
* venue formula reads is malformed.
|
|
547
574
|
*/
|
|
548
|
-
|
|
549
|
-
position: Position
|
|
550
|
-
): PositionMarginConstraints | undefined
|
|
575
|
+
positionRemovableMargin(position: Position): string | undefined
|
|
551
576
|
|
|
552
577
|
/**
|
|
553
578
|
* Project a typed {@link AccountConfig} against the provider's `setup`
|
package/src/types/withdrawal.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface ProviderWithdrawableBalance {
|
|
|
22
22
|
route: WithdrawalRoute
|
|
23
23
|
/** Withdrawable amount in the asset's own units. Always greater than zero. */
|
|
24
24
|
available: string
|
|
25
|
+
/**
|
|
26
|
+
* Flat venue fee on a withdrawal from this row, in the asset's own units.
|
|
27
|
+
* Absent when the venue publishes no fee for the asset. The client rejects a
|
|
28
|
+
* value that is not a non-negative decimal.
|
|
29
|
+
*/
|
|
30
|
+
withdrawalFee?: string
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
/**
|
|
@@ -36,4 +42,10 @@ export interface WithdrawableBalance {
|
|
|
36
42
|
route: WithdrawalRoute
|
|
37
43
|
/** Withdrawable amount in the asset's own units. */
|
|
38
44
|
available: string
|
|
45
|
+
/**
|
|
46
|
+
* Flat venue fee on a withdrawal from this row, in the asset's own units. An
|
|
47
|
+
* amount at or below it delivers nothing. Absent when the venue publishes no
|
|
48
|
+
* fee for the asset.
|
|
49
|
+
*/
|
|
50
|
+
withdrawalFee?: string
|
|
39
51
|
}
|
package/src/version.ts
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frame semantics of a {@link DecodeChain}:
|
|
3
|
+
* - `'every'`: every frame decodes and applies in arrival order — required for
|
|
4
|
+
* delta-carrying channels, where dropping a frame corrupts downstream state.
|
|
5
|
+
* - `'latest'`: frames queued behind an in-flight decode coalesce to the
|
|
6
|
+
* newest — for snapshot-like channels, where a newer frame supersedes
|
|
7
|
+
* anything still waiting.
|
|
8
|
+
*/
|
|
9
|
+
export type DecodeChainMode = 'every' | 'latest'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Serializes async WS frame decodes so results apply in arrival order.
|
|
13
|
+
* In `'latest'` mode a backlog (e.g. queued behind a main-thread stall)
|
|
14
|
+
* collapses to its newest frame instead of replaying every stale decode.
|
|
15
|
+
* Decode failures are reported to `onError` and never break the chain.
|
|
16
|
+
*/
|
|
17
|
+
export class DecodeChain {
|
|
18
|
+
private tail: Promise<void> = Promise.resolve()
|
|
19
|
+
private queued: (() => Promise<void>) | undefined
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
private readonly mode: DecodeChainMode,
|
|
23
|
+
private readonly onError: (error: unknown) => void
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
push(decode: () => Promise<void>): void {
|
|
27
|
+
if (this.mode === 'every') {
|
|
28
|
+
this.tail = this.tail.then(decode).catch(this.onError)
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
const drainScheduled = this.queued !== undefined
|
|
32
|
+
this.queued = decode
|
|
33
|
+
if (drainScheduled) {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
this.tail = this.tail
|
|
37
|
+
.then(() => {
|
|
38
|
+
const next = this.queued
|
|
39
|
+
this.queued = undefined
|
|
40
|
+
return next?.()
|
|
41
|
+
})
|
|
42
|
+
.catch(this.onError)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Detach on connection teardown: drops the queued latest-mode decode and
|
|
47
|
+
* starts subsequent pushes on a fresh chain. A decode already in flight
|
|
48
|
+
* still settles.
|
|
49
|
+
*/
|
|
50
|
+
reset(): void {
|
|
51
|
+
this.tail = Promise.resolve()
|
|
52
|
+
this.queued = undefined
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { AccountResponse, AccountSummary, Position } from '@lifi/perps-types';
|
|
2
|
-
export type CollateralSemantics = 'free' | 'net' | 'gross' | 'equity';
|
|
3
|
-
export declare function summarizeAccount(account: AccountResponse, positions: Position[], semantics: CollateralSemantics): AccountSummary;
|
|
4
|
-
//# sourceMappingURL=accountSummary.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accountSummary.d.ts","sourceRoot":"","sources":["../../../src/utils/accountSummary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,QAAQ,EACT,MAAM,mBAAmB,CAAA;AAgC1B,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAA;AAUrE,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,eAAe,EACxB,SAAS,EAAE,QAAQ,EAAE,EACrB,SAAS,EAAE,mBAAmB,GAC7B,cAAc,CAuChB"}
|