@lifi/perps-sdk 19.0.0 → 20.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 +15 -5
- package/dist/cjs/client/PerpsClient.d.ts +1 -1
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +4 -1
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/client/createPerpsClient.d.ts +1 -6
- package/dist/cjs/client/createPerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/createPerpsClient.js +1 -14
- package/dist/cjs/client/createPerpsClient.js.map +1 -1
- package/dist/cjs/index.d.ts +5 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +10 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/getOhlcv.d.ts.map +1 -1
- package/dist/cjs/services/getOhlcv.js.map +1 -1
- package/dist/cjs/types/api.d.ts +3 -4
- package/dist/cjs/types/api.d.ts.map +1 -1
- package/dist/cjs/types/config.d.ts +0 -9
- package/dist/cjs/types/config.d.ts.map +1 -1
- package/dist/cjs/types/provider.d.ts +1 -1
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/types/withdrawal.d.ts +4 -2
- package/dist/cjs/types/withdrawal.d.ts.map +1 -1
- package/dist/cjs/utils/calculations.d.ts.map +1 -1
- package/dist/cjs/utils/calculations.js +107 -38
- package/dist/cjs/utils/calculations.js.map +1 -1
- package/dist/cjs/utils/decimal.d.ts +4 -0
- package/dist/cjs/utils/decimal.d.ts.map +1 -0
- package/dist/cjs/utils/decimal.js +14 -0
- package/dist/cjs/utils/decimal.js.map +1 -0
- package/dist/cjs/utils/math.d.ts +4 -0
- package/dist/cjs/utils/math.d.ts.map +1 -0
- package/dist/cjs/utils/math.js +8 -0
- package/dist/cjs/utils/math.js.map +1 -0
- package/dist/cjs/utils/parse.d.ts +1 -0
- package/dist/cjs/utils/parse.d.ts.map +1 -1
- package/dist/cjs/utils/parse.js +15 -0
- package/dist/cjs/utils/parse.js.map +1 -1
- package/dist/cjs/utils/positionMath.d.ts +5 -0
- package/dist/cjs/utils/positionMath.d.ts.map +1 -1
- package/dist/cjs/utils/positionMath.js +53 -6
- package/dist/cjs/utils/positionMath.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/websocket/PerpsWsClient.d.ts +0 -1
- package/dist/cjs/websocket/PerpsWsClient.d.ts.map +1 -1
- package/dist/cjs/websocket/PerpsWsClient.js +0 -7
- package/dist/cjs/websocket/PerpsWsClient.js.map +1 -1
- package/dist/esm/client/PerpsClient.d.ts +8 -7
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +11 -7
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/client/createPerpsClient.d.ts +1 -12
- package/dist/esm/client/createPerpsClient.d.ts.map +1 -1
- package/dist/esm/client/createPerpsClient.js +1 -19
- package/dist/esm/client/createPerpsClient.js.map +1 -1
- package/dist/esm/client/requireProvider.d.ts +1 -1
- package/dist/esm/client/requireProvider.js +1 -1
- package/dist/esm/index.d.ts +5 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/getOhlcv.d.ts +1 -0
- package/dist/esm/services/getOhlcv.d.ts.map +1 -1
- package/dist/esm/services/getOhlcv.js.map +1 -1
- package/dist/esm/types/api.d.ts +8 -22
- package/dist/esm/types/api.d.ts.map +1 -1
- package/dist/esm/types/config.d.ts +0 -27
- package/dist/esm/types/config.d.ts.map +1 -1
- package/dist/esm/types/provider.d.ts +7 -6
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/types/withdrawal.d.ts +24 -15
- package/dist/esm/types/withdrawal.d.ts.map +1 -1
- package/dist/esm/utils/calculations.d.ts +3 -2
- package/dist/esm/utils/calculations.d.ts.map +1 -1
- package/dist/esm/utils/calculations.js +109 -39
- package/dist/esm/utils/calculations.js.map +1 -1
- package/dist/esm/utils/decimal.d.ts +9 -0
- package/dist/esm/utils/decimal.d.ts.map +1 -0
- package/dist/esm/utils/decimal.js +12 -0
- package/dist/esm/utils/decimal.js.map +1 -0
- package/dist/esm/utils/math.d.ts +6 -0
- package/dist/esm/utils/math.d.ts.map +1 -0
- package/dist/esm/utils/math.js +5 -0
- package/dist/esm/utils/math.js.map +1 -0
- package/dist/esm/utils/parse.d.ts +7 -0
- package/dist/esm/utils/parse.d.ts.map +1 -1
- package/dist/esm/utils/parse.js +20 -0
- package/dist/esm/utils/parse.js.map +1 -1
- package/dist/esm/utils/positionMath.d.ts +13 -0
- package/dist/esm/utils/positionMath.d.ts.map +1 -1
- package/dist/esm/utils/positionMath.js +60 -6
- package/dist/esm/utils/positionMath.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/websocket/PerpsWsClient.d.ts +0 -7
- package/dist/esm/websocket/PerpsWsClient.d.ts.map +1 -1
- package/dist/esm/websocket/PerpsWsClient.js +0 -7
- package/dist/esm/websocket/PerpsWsClient.js.map +1 -1
- package/dist/types/client/PerpsClient.d.ts +8 -7
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/client/createPerpsClient.d.ts +1 -12
- package/dist/types/client/createPerpsClient.d.ts.map +1 -1
- package/dist/types/client/requireProvider.d.ts +1 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/services/getOhlcv.d.ts +1 -0
- package/dist/types/services/getOhlcv.d.ts.map +1 -1
- package/dist/types/types/api.d.ts +8 -22
- package/dist/types/types/api.d.ts.map +1 -1
- package/dist/types/types/config.d.ts +0 -27
- package/dist/types/types/config.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +7 -6
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/types/withdrawal.d.ts +24 -15
- package/dist/types/types/withdrawal.d.ts.map +1 -1
- package/dist/types/utils/calculations.d.ts +3 -2
- package/dist/types/utils/calculations.d.ts.map +1 -1
- package/dist/types/utils/decimal.d.ts +9 -0
- package/dist/types/utils/decimal.d.ts.map +1 -0
- package/dist/types/utils/math.d.ts +6 -0
- package/dist/types/utils/math.d.ts.map +1 -0
- package/dist/types/utils/parse.d.ts +7 -0
- package/dist/types/utils/parse.d.ts.map +1 -1
- package/dist/types/utils/positionMath.d.ts +13 -0
- package/dist/types/utils/positionMath.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/websocket/PerpsWsClient.d.ts +0 -7
- package/dist/types/websocket/PerpsWsClient.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/client/PerpsClient.ts +12 -8
- package/src/client/createPerpsClient.ts +4 -32
- package/src/client/requireProvider.ts +1 -1
- package/src/index.ts +4 -4
- package/src/services/getOhlcv.ts +1 -0
- package/src/types/api.ts +8 -26
- package/src/types/config.ts +0 -30
- package/src/types/provider.ts +8 -7
- package/src/types/withdrawal.ts +24 -15
- package/src/utils/calculations.ts +114 -43
- package/src/utils/decimal.ts +13 -0
- package/src/utils/math.ts +7 -0
- package/src/utils/parse.ts +25 -0
- package/src/utils/positionMath.ts +66 -6
- package/src/version.ts +1 -1
- package/src/websocket/PerpsWsClient.ts +0 -19
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import type { ActionType, Asset } from '@lifi/perps-types';
|
|
1
|
+
import type { ActionType, Asset, WithdrawalRoute } from '@lifi/perps-types';
|
|
2
2
|
import type { Address } from 'viem';
|
|
3
|
-
|
|
4
|
-
* Which of a venue's two balance routes a withdrawal is drawn from. Lighter's
|
|
5
|
-
* own vocabulary, carried in the signed tx as `AssetRouteType` (`perps` = 0,
|
|
6
|
-
* `spot` = 1); an account's mode changes what the two balances mean, never
|
|
7
|
-
* which route the tx names.
|
|
8
|
-
*
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
export type WithdrawalRoute = 'perps' | 'spot';
|
|
3
|
+
export type { WithdrawalRoute };
|
|
12
4
|
/**
|
|
13
5
|
* One withdrawable `(asset, route)` selection as the provider reports it, keyed
|
|
14
6
|
* by provider-native asset id and awaiting the core asset-metadata join.
|
|
@@ -23,10 +15,16 @@ export interface ProviderWithdrawableBalance {
|
|
|
23
15
|
available: string;
|
|
24
16
|
/**
|
|
25
17
|
* Flat venue fee on a withdrawal from this row, in the asset's own units.
|
|
26
|
-
* Absent when the venue publishes no fee for the asset. The client rejects
|
|
27
|
-
* value that is not a non-negative decimal.
|
|
18
|
+
* Absent when the venue publishes no fee for the asset. The client rejects
|
|
19
|
+
* a value that is not a non-negative decimal.
|
|
28
20
|
*/
|
|
29
21
|
withdrawalFee?: string;
|
|
22
|
+
/**
|
|
23
|
+
* `true` when the venue takes `withdrawalFee` out of the requested amount,
|
|
24
|
+
* `false` when it charges the fee in addition. Set together with
|
|
25
|
+
* `withdrawalFee`; the client drops it from a row without a fee.
|
|
26
|
+
*/
|
|
27
|
+
isFeeDeducted?: boolean;
|
|
30
28
|
}
|
|
31
29
|
/**
|
|
32
30
|
* One withdrawable `(asset, route)` selection a caller can act on: the amount
|
|
@@ -41,11 +39,22 @@ export interface WithdrawableBalance {
|
|
|
41
39
|
/** Withdrawable amount in the asset's own units. */
|
|
42
40
|
available: string;
|
|
43
41
|
/**
|
|
44
|
-
* Flat venue fee on a withdrawal from this row, in the asset's own units.
|
|
45
|
-
*
|
|
46
|
-
* fee
|
|
42
|
+
* Flat venue fee on a withdrawal from this row, in the asset's own units.
|
|
43
|
+
* Absent when the venue publishes no fee for the asset. With
|
|
44
|
+
* `isFeeDeducted` `true`, the venue takes the fee out of the requested
|
|
45
|
+
* amount, and an amount at or below the fee delivers nothing. With `false`,
|
|
46
|
+
* the venue charges the fee in addition to the requested amount, so the
|
|
47
|
+
* largest amount the row can fund is `available` minus the fee. That result
|
|
48
|
+
* is zero or negative when the fee is at or above `available`, and the row
|
|
49
|
+
* then funds no withdrawal.
|
|
47
50
|
*/
|
|
48
51
|
withdrawalFee?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Present only together with `withdrawalFee`. Absent on a row from a
|
|
54
|
+
* provider plugin that does not report it; absence means unknown, not
|
|
55
|
+
* `true`.
|
|
56
|
+
*/
|
|
57
|
+
isFeeDeducted?: boolean;
|
|
49
58
|
}
|
|
50
59
|
/**
|
|
51
60
|
* The venue accepts a withdrawal to `destination` now.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/types/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/types/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC,YAAY,EAAE,eAAe,EAAE,CAAA;AAE/B;;;;;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;IACtB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,CAAA;IACZ,KAAK,EAAE,eAAe,CAAA;IACtB,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAA;IACjB;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,eAAe,CAAA;IACrB,qEAAqE;IACrE,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,yBAAyB,CAAA"}
|
|
@@ -164,7 +164,7 @@ interface BookWalk {
|
|
|
164
164
|
filledNotional: number;
|
|
165
165
|
/** Volume-weighted average fill price, or 0 when the book is empty. */
|
|
166
166
|
vwap: number;
|
|
167
|
-
/** True when the levels could not absorb the requested notional. */
|
|
167
|
+
/** True when the levels could not absorb the requested notional, and for a non-finite notional. */
|
|
168
168
|
insufficientLiquidity: boolean;
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
@@ -173,7 +173,8 @@ interface BookWalk {
|
|
|
173
173
|
* in array order — the caller passes asks for a buy and bids for a sell, each
|
|
174
174
|
* already ordered best-price-first. When the book cannot absorb the full
|
|
175
175
|
* notional, the walk stops at the last level and flags `insufficientLiquidity`,
|
|
176
|
-
* returning the best obtainable fill.
|
|
176
|
+
* returning the best obtainable fill. A non-finite `sizeUsd` gives NaN fill
|
|
177
|
+
* fields with `insufficientLiquidity` set.
|
|
177
178
|
*
|
|
178
179
|
* @throws {PerpsError} `ValidationError` when a level's `price` or `size`
|
|
179
180
|
* does not parse to a finite number.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../../src/utils/calculations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,cAAc,EAEnB,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../../src/utils/calculations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,cAAc,EAEnB,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAA;AAK1B;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,MAAM,CAQR;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAK1E;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,CAKR;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQhE;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,MAAM,CAQR;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE,OAAO,GACb,MAAM,CAYR;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IACjD,gBAAgB,EAAE,MAAM,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;CACrB,GAAG,MAAM,CAMT;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,MAAM,CAST;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAA;IACd,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GACb,WAAW,GAAG,IAAI,CAapB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,GACd,MAAM,CAYR;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,GACd,MAAM,CAWR;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACZ,MAAM,CASR;AAED,mFAAmF;AACnF,UAAU,QAAQ;IAChB,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,2FAA2F;IAC3F,cAAc,EAAE,MAAM,CAAA;IACtB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;IACZ,mGAAmG;IACnG,qBAAqB,EAAE,OAAO,CAAA;CAC/B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,cAAc,EAAE,EACxB,OAAO,EAAE,MAAM,GACd,QAAQ,CAgCV;AAaD,uGAAuG;AACvG,UAAU,eAAe;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,SAAS,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,aAAa,CAAA;IACpB,IAAI,EAAE,cAAc,EAAE,CAAA;IACtB,IAAI,EAAE,cAAc,EAAE,CAAA;IACtB,kFAAkF;IAClF,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,CA+BxD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
/**
|
|
3
|
+
* Scoped big.js constructor with 40 decimal places for division, so the
|
|
4
|
+
* shared global `Big.DP` and `Big.RM` stay untouched.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DivBig: Big.BigConstructor;
|
|
7
|
+
/** True when every value is a finite number, so `new DivBig(value)` cannot throw. */
|
|
8
|
+
export declare function areFinite(...values: number[]): boolean;
|
|
9
|
+
//# sourceMappingURL=decimal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/utils/decimal.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAA;AAExB;;;GAGG;AACH,eAAO,MAAM,MAAM,oBAAQ,CAAA;AAG3B,qFAAqF;AACrF,wBAAgB,SAAS,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAEtD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type Big from 'big.js';
|
|
2
|
+
/** The larger of two Big values, as `Math.max` for numbers. */
|
|
3
|
+
export declare const maxOf: (a: Big, b: Big) => Big;
|
|
4
|
+
/** The smaller of two Big values, as `Math.min` for numbers. */
|
|
5
|
+
export declare const minOf: (a: Big, b: Big) => Big;
|
|
6
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../src/utils/math.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAA;AAE7B,+DAA+D;AAC/D,eAAO,MAAM,KAAK,GAAI,GAAG,GAAG,EAAE,GAAG,GAAG,KAAG,GAAwB,CAAA;AAE/D,gEAAgE;AAChE,eAAO,MAAM,KAAK,GAAI,GAAG,GAAG,EAAE,GAAG,GAAG,KAAG,GAAwB,CAAA"}
|
|
@@ -18,4 +18,11 @@
|
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
20
|
export declare function stringToFloat(value: string): number;
|
|
21
|
+
/**
|
|
22
|
+
* Parse an optional decimal field, with the same formatting tolerance as {@link stringToFloat}.
|
|
23
|
+
* Gives back `undefined` for a missing, malformed or non-finite value, and `0` for an empty string.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseDecimal(value: string | null | undefined): number | undefined;
|
|
21
28
|
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/utils/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASnD"}
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/utils/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASnD;AAKD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC/B,MAAM,GAAG,SAAS,CAYpB"}
|
|
@@ -37,6 +37,19 @@ export declare function estimateIsolatedLiquidationPrice(params: {
|
|
|
37
37
|
isLong: boolean;
|
|
38
38
|
maintenanceMarginRate: number;
|
|
39
39
|
}): number | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Whether an isolated position with this liquidation price is already past
|
|
42
|
+
* liquidation at `currentPrice`: a long liquidates when the price falls to its
|
|
43
|
+
* liquidation level, a short when it rises to it. A non-positive price on
|
|
44
|
+
* either side counts as unknown, so the result is `false`.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export declare function wouldImmediatelyLiquidate(params: {
|
|
49
|
+
liquidationPrice: number;
|
|
50
|
+
currentPrice: number;
|
|
51
|
+
isLong: boolean;
|
|
52
|
+
}): boolean;
|
|
40
53
|
/**
|
|
41
54
|
* Predicted average entry price after adding to an existing position.
|
|
42
55
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"positionMath.d.ts","sourceRoot":"","sources":["../../../src/utils/positionMath.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"positionMath.d.ts","sourceRoot":"","sources":["../../../src/utils/positionMath.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAErD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gCAAgC,CAAC,MAAM,EAAE;IACvD,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,OAAO,CAAA;IACf,qBAAqB,EAAE,MAAM,CAAA;CAC9B,GAAG,MAAM,GAAG,SAAS,CAqBrB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAChD,gBAAgB,EAAE,MAAM,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,OAAO,CAAA;CAChB,GAAG,OAAO,CAQV;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,MAAM,GAAG,SAAS,CAiBrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,MAAM,GAAG,SAAS,CAarB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;CAChB,GAAG,MAAM,CAUT;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,OAAO,CAAA;CAChB,GAAG,MAAM,CAUT"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -11,13 +11,6 @@ export interface WsProviderFactoryParams {
|
|
|
11
11
|
provider: string;
|
|
12
12
|
/** WS URL discovered from `/providers`. */
|
|
13
13
|
wsUrl: string;
|
|
14
|
-
/**
|
|
15
|
-
* Markets visible to this provider via `/providers`, optionally filtered
|
|
16
|
-
* by the consumer's `createPerpsClient({ providers: { [key]: { markets } } })`
|
|
17
|
-
* config. Each provider interprets these its own way — Hyperliquid uses
|
|
18
|
-
* them to decide which sub-DEXes to subscribe to; Lighter ignores them.
|
|
19
|
-
*/
|
|
20
|
-
markets: string[];
|
|
21
14
|
/**
|
|
22
15
|
* The SDK client. WS providers use it to call core services (e.g.
|
|
23
16
|
* `getAssets` to source the wire-id ↔ display-symbol map) without
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PerpsWsClient.d.ts","sourceRoot":"","sources":["../../../src/websocket/PerpsWsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzE,OAAO,KAAK,EACV,oBAAoB,EAEpB,UAAU,EACV,gBAAgB,EACjB,MAAM,YAAY,CAAA;AAEnB;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAA;IAChB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAA;IACb
|
|
1
|
+
{"version":3,"file":"PerpsWsClient.d.ts","sourceRoot":"","sources":["../../../src/websocket/PerpsWsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzE,OAAO,KAAK,EACV,oBAAoB,EAEpB,UAAU,EACV,gBAAgB,EACjB,MAAM,YAAY,CAAA;AAEnB;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAA;IAChB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,MAAM,EAAE,cAAc,CAAA;CACvB;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,CAAC,MAAM,EAAE,uBAAuB,GAAG,UAAU,CAAA;IAC7C,gEAAgE;IAChE,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAA;IAChC,0EAA0E;IAC1E,QAAQ,CAAC,uBAAuB,EAAE,OAAO,CAAA;CAC1C;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA;CAChD;AAED;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,SAAS,CAAgC;IACjD,OAAO,CAAC,YAAY,CAAyC;IAC7D,OAAO,CAAC,MAAM,CAAQ;gBAEV,MAAM,EAAE,cAAc,EAAE,OAAO,GAAE,oBAAyB;IAKtE;;;;;;;OAOG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIzC;;;;;;OAMG;IACH,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAMlD;;;;;;;;;;;;OAYG;IACG,SAAS,CAAC,CAAC,SAAS,YAAY,EACpC,GAAG,EAAE,CAAC,EACN,QAAQ,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAAK,IAAI,EAClD,QAAQ,CAAC,EAAE,gBAAgB,GAC1B,OAAO,CAAC,MAAM,IAAI,CAAC;IAOtB;;;;;;;;;;OAUG;IACG,cAAc,CAClB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,MAAM,IAAI,CAAC;IAatB;;;;;;;OAOG;IACH,KAAK;IASL;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIjC,OAAO,CAAC,UAAU;YASJ,mBAAmB;YAqBnB,YAAY;CA0B3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20.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": "^18.0.0"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
@@ -647,21 +647,22 @@ export class PerpsClient {
|
|
|
647
647
|
}
|
|
648
648
|
|
|
649
649
|
/**
|
|
650
|
-
* The user's current venue-side settings for a market — the margin
|
|
651
|
-
* and leverage the next order on it will use. Resolves
|
|
652
|
-
*
|
|
653
|
-
* has no such read at all).
|
|
650
|
+
* The user's current venue-side settings for a perps market — the margin
|
|
651
|
+
* mode and leverage the next order on it will use. Resolves the venue value
|
|
652
|
+
* or throws.
|
|
654
653
|
*
|
|
655
|
-
* @throws {PerpsError} When the provider plugin is not registered
|
|
654
|
+
* @throws {PerpsError} When the provider plugin is not registered,
|
|
655
|
+
* `ValidationError` for a spot market, or any other `PerpsError` when the
|
|
656
|
+
* venue read fails or carries no usable value.
|
|
656
657
|
* @public
|
|
657
658
|
*/
|
|
658
659
|
async getMarketSettings(params: {
|
|
659
660
|
provider: string
|
|
660
661
|
address: Address
|
|
661
662
|
market: MarketRef
|
|
662
|
-
}): Promise<MarketSettings
|
|
663
|
+
}): Promise<MarketSettings> {
|
|
663
664
|
const plugin = this.requireProvider(params.provider)
|
|
664
|
-
return plugin.getMarketSettings
|
|
665
|
+
return plugin.getMarketSettings({
|
|
665
666
|
address: params.address,
|
|
666
667
|
market: params.market,
|
|
667
668
|
})
|
|
@@ -810,7 +811,7 @@ export class PerpsClient {
|
|
|
810
811
|
* @returns `undefined` when the registered plugin declares no withdrawable
|
|
811
812
|
* read.
|
|
812
813
|
* @throws {PerpsError} When the provider plugin is not registered, when
|
|
813
|
-
* either the plugin read or the asset sync fails,
|
|
814
|
+
* either the plugin read or the asset sync fails, when a row's
|
|
814
815
|
* `withdrawalFee` is not a non-negative decimal.
|
|
815
816
|
* @public
|
|
816
817
|
*/
|
|
@@ -862,6 +863,9 @@ export class PerpsClient {
|
|
|
862
863
|
route: row.route,
|
|
863
864
|
available: row.available,
|
|
864
865
|
withdrawalFee: row.withdrawalFee,
|
|
866
|
+
...(row.isFeeDeducted === undefined
|
|
867
|
+
? {}
|
|
868
|
+
: { isFeeDeducted: row.isFeeDeducted }),
|
|
865
869
|
},
|
|
866
870
|
]
|
|
867
871
|
})
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type { PerpsConfig } from '../types/api.js'
|
|
2
|
-
import type { PerpsBaseConfig
|
|
3
|
-
import type {
|
|
4
|
-
PerpsProvider,
|
|
5
|
-
PerpsProviderPlugin,
|
|
6
|
-
PerpsSDKClient,
|
|
7
|
-
} from '../types/provider.js'
|
|
2
|
+
import type { PerpsBaseConfig } from '../types/config.js'
|
|
3
|
+
import type { PerpsProvider, PerpsSDKClient } from '../types/provider.js'
|
|
8
4
|
import { bindProvider } from './bindProvider.js'
|
|
9
5
|
|
|
10
6
|
/**
|
|
@@ -30,15 +26,12 @@ export const DEFAULT_API_URL = 'https://li.quest/v1/perps'
|
|
|
30
26
|
*/
|
|
31
27
|
export function createPerpsClient(options: PerpsConfig): PerpsSDKClient {
|
|
32
28
|
const apiUrl = options.apiUrl ?? DEFAULT_API_URL
|
|
33
|
-
const { providerPlugins, providerConfigs } = splitProviders(options.providers)
|
|
34
29
|
|
|
35
30
|
const config: PerpsBaseConfig = {
|
|
36
31
|
integrator: options.integrator?.trim() || undefined,
|
|
37
32
|
apiKey: options.apiKey?.trim() ?? '',
|
|
38
33
|
apiUrl,
|
|
39
|
-
disableVersionCheck: options.disableVersionCheck,
|
|
40
34
|
requestInterceptor: options.requestInterceptor,
|
|
41
|
-
providers: providerConfigs,
|
|
42
35
|
retry: options.retry,
|
|
43
36
|
fetch: options.fetch,
|
|
44
37
|
}
|
|
@@ -58,30 +51,9 @@ export function createPerpsClient(options: PerpsConfig): PerpsSDKClient {
|
|
|
58
51
|
},
|
|
59
52
|
}
|
|
60
53
|
|
|
61
|
-
const boundProviders: PerpsProvider[] =
|
|
62
|
-
bindProvider(plugin, client)
|
|
54
|
+
const boundProviders: PerpsProvider[] = (options.providers ?? []).map(
|
|
55
|
+
(plugin) => bindProvider(plugin, client)
|
|
63
56
|
)
|
|
64
57
|
|
|
65
58
|
return client
|
|
66
59
|
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Split the overloaded `providers` option into its two shapes — the
|
|
70
|
-
* plugin array used by {@link PerpsSDKClient.getProvider}, and the
|
|
71
|
-
* keyed `ProviderConfigs` consumed internally by `PerpsWsClient` for
|
|
72
|
-
* markets filtering.
|
|
73
|
-
*/
|
|
74
|
-
export function splitProviders(
|
|
75
|
-
input: PerpsProviderPlugin[] | ProviderConfigs | undefined
|
|
76
|
-
): {
|
|
77
|
-
providerPlugins: PerpsProviderPlugin[]
|
|
78
|
-
providerConfigs?: ProviderConfigs
|
|
79
|
-
} {
|
|
80
|
-
if (input === undefined) {
|
|
81
|
-
return { providerPlugins: [] }
|
|
82
|
-
}
|
|
83
|
-
if (Array.isArray(input)) {
|
|
84
|
-
return { providerPlugins: input }
|
|
85
|
-
}
|
|
86
|
-
return { providerPlugins: [], providerConfigs: input }
|
|
87
|
-
}
|
|
@@ -9,7 +9,7 @@ import type { PerpsProvider, PerpsSDKClient } from '../types/provider.js'
|
|
|
9
9
|
* `createPerpsClient({ providers: [...] })`) rather than a runtime-recoverable
|
|
10
10
|
* state.
|
|
11
11
|
*
|
|
12
|
-
* @
|
|
12
|
+
* @public
|
|
13
13
|
*/
|
|
14
14
|
export function requireProvider(
|
|
15
15
|
client: PerpsSDKClient,
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ export {
|
|
|
16
16
|
DEFAULT_API_URL,
|
|
17
17
|
} from './client/createPerpsClient.js'
|
|
18
18
|
export { PerpsClient } from './client/PerpsClient.js'
|
|
19
|
+
export { requireProvider } from './client/requireProvider.js'
|
|
19
20
|
export { PerpsErrorMessage } from './errors/constants.js'
|
|
20
21
|
export { PerpsError } from './errors/PerpsError.js'
|
|
21
22
|
// Registries
|
|
@@ -132,11 +133,8 @@ export type {
|
|
|
132
133
|
WithdrawParams,
|
|
133
134
|
} from './types/api.js'
|
|
134
135
|
export type {
|
|
135
|
-
HyperliquidConfig,
|
|
136
136
|
PerpsBaseConfig,
|
|
137
137
|
PerpsClientSigner,
|
|
138
|
-
ProviderConfig,
|
|
139
|
-
ProviderConfigs,
|
|
140
138
|
RequestInterceptor,
|
|
141
139
|
SDKRequestOptions,
|
|
142
140
|
SwitchChainHook,
|
|
@@ -222,6 +220,7 @@ export {
|
|
|
222
220
|
formatSignedUsd,
|
|
223
221
|
formatUsd,
|
|
224
222
|
} from './utils/format.js'
|
|
223
|
+
export { maxOf, minOf } from './utils/math.js'
|
|
225
224
|
export {
|
|
226
225
|
ACTIVE_ORDER_STATUSES,
|
|
227
226
|
classifyFill,
|
|
@@ -241,7 +240,7 @@ export {
|
|
|
241
240
|
findMatchingPosition,
|
|
242
241
|
resolveCloseSize,
|
|
243
242
|
} from './utils/orderMath.js'
|
|
244
|
-
export { stringToFloat } from './utils/parse.js'
|
|
243
|
+
export { parseDecimal, stringToFloat } from './utils/parse.js'
|
|
245
244
|
export {
|
|
246
245
|
directionSign,
|
|
247
246
|
estimateIsolatedLiquidationPrice,
|
|
@@ -249,6 +248,7 @@ export {
|
|
|
249
248
|
predictNewLeverage,
|
|
250
249
|
predictUnrealizedPnl,
|
|
251
250
|
realizedPnlOnClose,
|
|
251
|
+
wouldImmediatelyLiquidate,
|
|
252
252
|
} from './utils/positionMath.js'
|
|
253
253
|
export type { ScaleToIntegerPolicy } from './utils/scaleToInteger.js'
|
|
254
254
|
export { scaleToInteger } from './utils/scaleToInteger.js'
|
package/src/services/getOhlcv.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface GetOhlcvParams {
|
|
|
12
12
|
provider: string
|
|
13
13
|
/** Opaque provider `Market.id`, not a display symbol. */
|
|
14
14
|
marketId: string
|
|
15
|
+
/** Pick from the provider's `Provider.supportedIntervals`; support varies per provider. */
|
|
15
16
|
interval: OhlcvInterval
|
|
16
17
|
/** Unix timestamp in milliseconds for the start bound. */
|
|
17
18
|
startTime?: number
|
package/src/types/api.ts
CHANGED
|
@@ -24,11 +24,7 @@ import type {
|
|
|
24
24
|
} from '@lifi/perps-types'
|
|
25
25
|
import type { Account, Address, WalletClient } from 'viem'
|
|
26
26
|
import type { RetryConfig } from '../transport/retryPolicy.js'
|
|
27
|
-
import type {
|
|
28
|
-
ProviderConfigs,
|
|
29
|
-
RequestInterceptor,
|
|
30
|
-
SwitchChainHook,
|
|
31
|
-
} from './config.js'
|
|
27
|
+
import type { RequestInterceptor, SwitchChainHook } from './config.js'
|
|
32
28
|
import type { PerpsProviderPlugin } from './provider.js'
|
|
33
29
|
|
|
34
30
|
/**
|
|
@@ -52,25 +48,15 @@ export interface PerpsConfig {
|
|
|
52
48
|
apiKey?: string
|
|
53
49
|
/** Perps API base URL; defaults to {@link DEFAULT_API_URL}. */
|
|
54
50
|
apiUrl?: string
|
|
55
|
-
/** Skip the SDK-version compatibility check when set. */
|
|
56
|
-
disableVersionCheck?: boolean
|
|
57
51
|
/** Hook that can rewrite URL/request options before transport. */
|
|
58
52
|
requestInterceptor?: RequestInterceptor
|
|
59
53
|
/**
|
|
60
|
-
* Provider plugins
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* runtime as bound {@link PerpsProvider}s via `client.getProvider(key)`.
|
|
65
|
-
* Modelled on `@lifi/sdk`'s `providers: SDKProvider[]`.
|
|
66
|
-
* - `ProviderConfigs` — keyed config object (e.g.
|
|
67
|
-
* `{ hyperliquid: { markets: [...] } }`). Used internally by
|
|
68
|
-
* `PerpsWsClient` to filter which markets are subscribed to.
|
|
69
|
-
*
|
|
70
|
-
* Both may be supplied during the migration to provider packages;
|
|
71
|
-
* the array form is preferred for new code.
|
|
54
|
+
* Provider plugins, one per DEX. Bound to the client at construction and
|
|
55
|
+
* looked up at runtime as bound {@link PerpsProvider}s via
|
|
56
|
+
* `client.getProvider(key)`. Modelled on `@lifi/sdk`'s
|
|
57
|
+
* `providers: SDKProvider[]`.
|
|
72
58
|
*/
|
|
73
|
-
providers?: PerpsProviderPlugin[]
|
|
59
|
+
providers?: PerpsProviderPlugin[]
|
|
74
60
|
/**
|
|
75
61
|
* The end-user's wallet, used whenever an action's descriptor names
|
|
76
62
|
* `PerpsSigner.USER` as its `signer`. Accepts any viem-compatible WalletClient:
|
|
@@ -117,12 +103,8 @@ export interface PerpsClientOptions {
|
|
|
117
103
|
apiKey?: string
|
|
118
104
|
/** Perps API base URL; defaults to {@link DEFAULT_API_URL}. */
|
|
119
105
|
apiUrl?: string
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
* {@link PerpsConfig.providers}: an array of `PerpsProviderPlugin` plugins or
|
|
123
|
-
* a keyed `ProviderConfigs` map.
|
|
124
|
-
*/
|
|
125
|
-
providers?: PerpsProviderPlugin[] | ProviderConfigs
|
|
106
|
+
/** Provider plugins; see {@link PerpsConfig.providers}. */
|
|
107
|
+
providers?: PerpsProviderPlugin[]
|
|
126
108
|
/**
|
|
127
109
|
* Hook invoked before a USER-signed EIP-712 action is signed, to switch the
|
|
128
110
|
* user's wallet to the action's target chain. Also settable at runtime via
|
package/src/types/config.ts
CHANGED
|
@@ -23,32 +23,6 @@ export type SwitchChainHook = (
|
|
|
23
23
|
chainId: number
|
|
24
24
|
) => Promise<PerpsClientSigner | undefined>
|
|
25
25
|
|
|
26
|
-
/**
|
|
27
|
-
* Per-provider config — restricts which `markets` the WS client subscribes
|
|
28
|
-
* to. Indexed by provider key.
|
|
29
|
-
*
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
export interface ProviderConfig {
|
|
33
|
-
/** Optional provider category/market ids used to filter WS subscriptions. */
|
|
34
|
-
markets?: string[]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated Use {@link ProviderConfig}.
|
|
39
|
-
* @public
|
|
40
|
-
*/
|
|
41
|
-
export type HyperliquidConfig = ProviderConfig
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Map of per-provider {@link ProviderConfig}, keyed by provider key.
|
|
45
|
-
*
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
|
-
export interface ProviderConfigs {
|
|
49
|
-
[provider: string]: ProviderConfig | undefined
|
|
50
|
-
}
|
|
51
|
-
|
|
52
26
|
/**
|
|
53
27
|
* Hook to rewrite each outgoing request's URL/`RequestInit` before it is sent.
|
|
54
28
|
*
|
|
@@ -101,12 +75,8 @@ export interface PerpsBaseConfig {
|
|
|
101
75
|
apiKey: string
|
|
102
76
|
/** Resolved perps API base URL. */
|
|
103
77
|
apiUrl: string
|
|
104
|
-
/** Whether SDK version compatibility checks are disabled. */
|
|
105
|
-
disableVersionCheck?: boolean
|
|
106
78
|
/** Optional outgoing-request URL/options interceptor. */
|
|
107
79
|
requestInterceptor?: RequestInterceptor
|
|
108
|
-
/** Optional per-provider WS market filters. */
|
|
109
|
-
providers?: ProviderConfigs
|
|
110
80
|
/** Optional global or per-provider retry configuration. */
|
|
111
81
|
retry?: RetryConfig
|
|
112
82
|
/** Fetch implementation used by core HTTP transport. */
|
package/src/types/provider.ts
CHANGED
|
@@ -453,16 +453,17 @@ export interface PerpsProviderPlugin {
|
|
|
453
453
|
): Promise<PositionsResponse>
|
|
454
454
|
|
|
455
455
|
/**
|
|
456
|
-
* The user's current venue-side settings for one market — the margin
|
|
457
|
-
* and leverage the next order on it will use.
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
456
|
+
* The user's current venue-side settings for one perps market — the margin
|
|
457
|
+
* mode and leverage the next order on it will use. Resolves the venue value
|
|
458
|
+
* or throws.
|
|
459
|
+
*
|
|
460
|
+
* @throws {PerpsError} `ValidationError` for a spot market; any other
|
|
461
|
+
* `PerpsError` when the venue read fails or carries no usable value.
|
|
461
462
|
*/
|
|
462
|
-
getMarketSettings
|
|
463
|
+
getMarketSettings(
|
|
463
464
|
params: ProviderGetMarketSettingsParams,
|
|
464
465
|
options?: SDKRequestOptions
|
|
465
|
-
): Promise<MarketSettings
|
|
466
|
+
): Promise<MarketSettings>
|
|
466
467
|
|
|
467
468
|
/**
|
|
468
469
|
* The amounts the account can still buy and sell on one market, in that
|
package/src/types/withdrawal.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import type { ActionType, Asset } from '@lifi/perps-types'
|
|
1
|
+
import type { ActionType, Asset, WithdrawalRoute } from '@lifi/perps-types'
|
|
2
2
|
import type { Address } from 'viem'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* Which of a venue's two balance routes a withdrawal is drawn from. Lighter's
|
|
6
|
-
* own vocabulary, carried in the signed tx as `AssetRouteType` (`perps` = 0,
|
|
7
|
-
* `spot` = 1); an account's mode changes what the two balances mean, never
|
|
8
|
-
* which route the tx names.
|
|
9
|
-
*
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export type WithdrawalRoute = 'perps' | 'spot'
|
|
4
|
+
export type { WithdrawalRoute }
|
|
13
5
|
|
|
14
6
|
/**
|
|
15
7
|
* One withdrawable `(asset, route)` selection as the provider reports it, keyed
|
|
@@ -25,10 +17,16 @@ export interface ProviderWithdrawableBalance {
|
|
|
25
17
|
available: string
|
|
26
18
|
/**
|
|
27
19
|
* Flat venue fee on a withdrawal from this row, in the asset's own units.
|
|
28
|
-
* Absent when the venue publishes no fee for the asset. The client rejects
|
|
29
|
-
* value that is not a non-negative decimal.
|
|
20
|
+
* Absent when the venue publishes no fee for the asset. The client rejects
|
|
21
|
+
* a value that is not a non-negative decimal.
|
|
30
22
|
*/
|
|
31
23
|
withdrawalFee?: string
|
|
24
|
+
/**
|
|
25
|
+
* `true` when the venue takes `withdrawalFee` out of the requested amount,
|
|
26
|
+
* `false` when it charges the fee in addition. Set together with
|
|
27
|
+
* `withdrawalFee`; the client drops it from a row without a fee.
|
|
28
|
+
*/
|
|
29
|
+
isFeeDeducted?: boolean
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
/**
|
|
@@ -44,11 +42,22 @@ export interface WithdrawableBalance {
|
|
|
44
42
|
/** Withdrawable amount in the asset's own units. */
|
|
45
43
|
available: string
|
|
46
44
|
/**
|
|
47
|
-
* Flat venue fee on a withdrawal from this row, in the asset's own units.
|
|
48
|
-
*
|
|
49
|
-
* fee
|
|
45
|
+
* Flat venue fee on a withdrawal from this row, in the asset's own units.
|
|
46
|
+
* Absent when the venue publishes no fee for the asset. With
|
|
47
|
+
* `isFeeDeducted` `true`, the venue takes the fee out of the requested
|
|
48
|
+
* amount, and an amount at or below the fee delivers nothing. With `false`,
|
|
49
|
+
* the venue charges the fee in addition to the requested amount, so the
|
|
50
|
+
* largest amount the row can fund is `available` minus the fee. That result
|
|
51
|
+
* is zero or negative when the fee is at or above `available`, and the row
|
|
52
|
+
* then funds no withdrawal.
|
|
50
53
|
*/
|
|
51
54
|
withdrawalFee?: string
|
|
55
|
+
/**
|
|
56
|
+
* Present only together with `withdrawalFee`. Absent on a row from a
|
|
57
|
+
* provider plugin that does not report it; absence means unknown, not
|
|
58
|
+
* `true`.
|
|
59
|
+
*/
|
|
60
|
+
isFeeDeducted?: boolean
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
/**
|