@lifi/perps-sdk-provider-lighter 7.0.0 → 8.0.1
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/LighterProvider.d.ts.map +1 -1
- package/dist/cjs/LighterProvider.js +60 -27
- package/dist/cjs/LighterProvider.js.map +1 -1
- package/dist/cjs/accountSummary.d.ts.map +1 -1
- package/dist/cjs/accountSummary.js +33 -2
- package/dist/cjs/accountSummary.js.map +1 -1
- package/dist/cjs/constants.d.ts.map +1 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/signers/LighterKeyStore.d.ts.map +1 -1
- package/dist/cjs/signers/LighterKeyStore.js.map +1 -1
- package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
- package/dist/cjs/signers/LighterReadOnlyTokenManager.js.map +1 -1
- package/dist/cjs/signers/LighterSigner.d.ts.map +1 -1
- package/dist/cjs/signers/LighterSigner.js.map +1 -1
- package/dist/cjs/signers/createAuthToken.d.ts.map +1 -1
- package/dist/cjs/signers/createAuthToken.js.map +1 -1
- package/dist/cjs/signers/wasmLoader.d.ts.map +1 -1
- package/dist/cjs/signers/wasmLoader.js.map +1 -1
- package/dist/cjs/types/account.d.ts +1 -0
- package/dist/cjs/types/account.d.ts.map +1 -1
- package/dist/cjs/types/action.d.ts.map +1 -1
- package/dist/cjs/types/action.js.map +1 -1
- package/dist/cjs/types/activity.d.ts.map +1 -1
- package/dist/cjs/types/asset.d.ts.map +1 -1
- package/dist/cjs/types/fill.d.ts.map +1 -1
- package/dist/cjs/types/order.d.ts.map +1 -1
- package/dist/cjs/types/submit.d.ts.map +1 -1
- package/dist/cjs/types/ws.d.ts +5 -0
- package/dist/cjs/types/ws.d.ts.map +1 -1
- package/dist/cjs/utils/decimal.d.ts +5 -0
- package/dist/cjs/utils/decimal.d.ts.map +1 -0
- package/dist/cjs/utils/decimal.js +38 -0
- package/dist/cjs/utils/decimal.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +3 -1
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +7 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/lighterAsset.d.ts.map +1 -1
- package/dist/cjs/utils/lighterAsset.js.map +1 -1
- package/dist/cjs/utils/mapOpenPositions.d.ts +2 -2
- package/dist/cjs/utils/mapOpenPositions.d.ts.map +1 -1
- package/dist/cjs/utils/mapOpenPositions.js.map +1 -1
- package/dist/cjs/utils/mapPosition.d.ts +3 -2
- package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
- package/dist/cjs/utils/mapPosition.js +30 -9
- package/dist/cjs/utils/mapPosition.js.map +1 -1
- package/dist/cjs/utils/ohlcvInterval.d.ts.map +1 -1
- package/dist/cjs/utils/ohlcvInterval.js.map +1 -1
- package/dist/cjs/utils/transferMargin.d.ts +3 -0
- package/dist/cjs/utils/transferMargin.d.ts.map +1 -0
- package/dist/cjs/utils/transferMargin.js +16 -0
- package/dist/cjs/utils/transferMargin.js.map +1 -0
- package/dist/cjs/utils/wireEncoding.d.ts.map +1 -1
- package/dist/cjs/utils/wireEncoding.js.map +1 -1
- package/dist/cjs/websocket/LighterWsProvider.d.ts.map +1 -1
- package/dist/cjs/websocket/LighterWsProvider.js +20 -9
- package/dist/cjs/websocket/LighterWsProvider.js.map +1 -1
- package/dist/esm/LighterProvider.d.ts.map +1 -1
- package/dist/esm/LighterProvider.js +49 -11
- package/dist/esm/LighterProvider.js.map +1 -1
- package/dist/esm/accountSummary.d.ts +5 -4
- package/dist/esm/accountSummary.d.ts.map +1 -1
- package/dist/esm/accountSummary.js +35 -6
- package/dist/esm/accountSummary.js.map +1 -1
- package/dist/esm/constants.d.ts +15 -2
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +15 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/signers/LighterKeyStore.d.ts +31 -2
- package/dist/esm/signers/LighterKeyStore.d.ts.map +1 -1
- package/dist/esm/signers/LighterKeyStore.js +24 -1
- package/dist/esm/signers/LighterKeyStore.js.map +1 -1
- package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts +23 -3
- package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
- package/dist/esm/signers/LighterReadOnlyTokenManager.js +4 -0
- package/dist/esm/signers/LighterReadOnlyTokenManager.js.map +1 -1
- package/dist/esm/signers/LighterSigner.d.ts +49 -7
- package/dist/esm/signers/LighterSigner.d.ts.map +1 -1
- package/dist/esm/signers/LighterSigner.js +11 -1
- package/dist/esm/signers/LighterSigner.js.map +1 -1
- package/dist/esm/signers/createAuthToken.d.ts +8 -2
- package/dist/esm/signers/createAuthToken.d.ts.map +1 -1
- package/dist/esm/signers/createAuthToken.js.map +1 -1
- package/dist/esm/signers/wasmLoader.d.ts +14 -2
- package/dist/esm/signers/wasmLoader.d.ts.map +1 -1
- package/dist/esm/signers/wasmLoader.js.map +1 -1
- package/dist/esm/types/account.d.ts +61 -8
- package/dist/esm/types/account.d.ts.map +1 -1
- package/dist/esm/types/action.d.ts +72 -18
- package/dist/esm/types/action.d.ts.map +1 -1
- package/dist/esm/types/action.js +72 -18
- package/dist/esm/types/action.js.map +1 -1
- package/dist/esm/types/activity.d.ts +64 -10
- package/dist/esm/types/activity.d.ts.map +1 -1
- package/dist/esm/types/asset.d.ts +72 -12
- package/dist/esm/types/asset.d.ts.map +1 -1
- package/dist/esm/types/fill.d.ts +14 -2
- package/dist/esm/types/fill.d.ts.map +1 -1
- package/dist/esm/types/order.d.ts +27 -4
- package/dist/esm/types/order.d.ts.map +1 -1
- package/dist/esm/types/submit.d.ts +26 -4
- package/dist/esm/types/submit.d.ts.map +1 -1
- package/dist/esm/types/ws.d.ts +65 -9
- package/dist/esm/types/ws.d.ts.map +1 -1
- package/dist/esm/utils/decimal.d.ts +15 -0
- package/dist/esm/utils/decimal.d.ts.map +1 -0
- package/dist/esm/utils/decimal.js +39 -0
- package/dist/esm/utils/decimal.js.map +1 -0
- package/dist/esm/utils/index.d.ts +3 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +3 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/lighterAsset.d.ts +7 -1
- package/dist/esm/utils/lighterAsset.d.ts.map +1 -1
- package/dist/esm/utils/lighterAsset.js +7 -1
- package/dist/esm/utils/lighterAsset.js.map +1 -1
- package/dist/esm/utils/mapOpenPositions.d.ts +2 -2
- package/dist/esm/utils/mapOpenPositions.d.ts.map +1 -1
- package/dist/esm/utils/mapOpenPositions.js.map +1 -1
- package/dist/esm/utils/mapPosition.d.ts +10 -2
- package/dist/esm/utils/mapPosition.d.ts.map +1 -1
- package/dist/esm/utils/mapPosition.js +32 -11
- package/dist/esm/utils/mapPosition.js.map +1 -1
- package/dist/esm/utils/ohlcvInterval.d.ts +6 -1
- package/dist/esm/utils/ohlcvInterval.d.ts.map +1 -1
- package/dist/esm/utils/ohlcvInterval.js +6 -1
- package/dist/esm/utils/ohlcvInterval.js.map +1 -1
- package/dist/esm/utils/transferMargin.d.ts +11 -0
- package/dist/esm/utils/transferMargin.d.ts.map +1 -0
- package/dist/esm/utils/transferMargin.js +21 -0
- package/dist/esm/utils/transferMargin.js.map +1 -0
- package/dist/esm/utils/wireEncoding.d.ts +58 -23
- package/dist/esm/utils/wireEncoding.d.ts.map +1 -1
- package/dist/esm/utils/wireEncoding.js +58 -23
- package/dist/esm/utils/wireEncoding.js.map +1 -1
- package/dist/esm/websocket/LighterWsProvider.d.ts +6 -0
- package/dist/esm/websocket/LighterWsProvider.d.ts.map +1 -1
- package/dist/esm/websocket/LighterWsProvider.js +30 -13
- package/dist/esm/websocket/LighterWsProvider.js.map +1 -1
- package/dist/types/LighterProvider.d.ts.map +1 -1
- package/dist/types/accountSummary.d.ts +5 -4
- package/dist/types/accountSummary.d.ts.map +1 -1
- package/dist/types/constants.d.ts +15 -2
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/signers/LighterKeyStore.d.ts +31 -2
- package/dist/types/signers/LighterKeyStore.d.ts.map +1 -1
- package/dist/types/signers/LighterReadOnlyTokenManager.d.ts +23 -3
- package/dist/types/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
- package/dist/types/signers/LighterSigner.d.ts +49 -7
- package/dist/types/signers/LighterSigner.d.ts.map +1 -1
- package/dist/types/signers/createAuthToken.d.ts +8 -2
- package/dist/types/signers/createAuthToken.d.ts.map +1 -1
- package/dist/types/signers/wasmLoader.d.ts +14 -2
- package/dist/types/signers/wasmLoader.d.ts.map +1 -1
- package/dist/types/types/account.d.ts +61 -8
- package/dist/types/types/account.d.ts.map +1 -1
- package/dist/types/types/action.d.ts +72 -18
- package/dist/types/types/action.d.ts.map +1 -1
- package/dist/types/types/activity.d.ts +64 -10
- package/dist/types/types/activity.d.ts.map +1 -1
- package/dist/types/types/asset.d.ts +72 -12
- package/dist/types/types/asset.d.ts.map +1 -1
- package/dist/types/types/fill.d.ts +14 -2
- package/dist/types/types/fill.d.ts.map +1 -1
- package/dist/types/types/order.d.ts +27 -4
- package/dist/types/types/order.d.ts.map +1 -1
- package/dist/types/types/submit.d.ts +26 -4
- package/dist/types/types/submit.d.ts.map +1 -1
- package/dist/types/types/ws.d.ts +65 -9
- package/dist/types/types/ws.d.ts.map +1 -1
- package/dist/types/utils/decimal.d.ts +15 -0
- package/dist/types/utils/decimal.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +3 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/lighterAsset.d.ts +7 -1
- package/dist/types/utils/lighterAsset.d.ts.map +1 -1
- package/dist/types/utils/mapOpenPositions.d.ts +2 -2
- package/dist/types/utils/mapOpenPositions.d.ts.map +1 -1
- package/dist/types/utils/mapPosition.d.ts +10 -2
- package/dist/types/utils/mapPosition.d.ts.map +1 -1
- package/dist/types/utils/ohlcvInterval.d.ts +6 -1
- package/dist/types/utils/ohlcvInterval.d.ts.map +1 -1
- package/dist/types/utils/transferMargin.d.ts +11 -0
- package/dist/types/utils/transferMargin.d.ts.map +1 -0
- package/dist/types/utils/wireEncoding.d.ts +58 -23
- package/dist/types/utils/wireEncoding.d.ts.map +1 -1
- package/dist/types/websocket/LighterWsProvider.d.ts +6 -0
- package/dist/types/websocket/LighterWsProvider.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/LighterProvider.ts +75 -9
- package/src/accountSummary.ts +38 -6
- package/src/constants.ts +15 -2
- package/src/signers/LighterKeyStore.ts +31 -2
- package/src/signers/LighterReadOnlyTokenManager.ts +23 -3
- package/src/signers/LighterSigner.ts +49 -7
- package/src/signers/createAuthToken.ts +8 -2
- package/src/signers/wasmLoader.ts +14 -2
- package/src/types/account.ts +61 -8
- package/src/types/action.ts +72 -18
- package/src/types/activity.ts +64 -10
- package/src/types/asset.ts +72 -12
- package/src/types/fill.ts +14 -2
- package/src/types/order.ts +27 -4
- package/src/types/submit.ts +26 -4
- package/src/types/ws.ts +65 -9
- package/src/utils/decimal.ts +52 -0
- package/src/utils/index.ts +3 -1
- package/src/utils/lighterAsset.ts +7 -1
- package/src/utils/mapOpenPositions.ts +2 -2
- package/src/utils/mapPosition.ts +40 -14
- package/src/utils/ohlcvInterval.ts +6 -1
- package/src/utils/transferMargin.ts +31 -0
- package/src/utils/wireEncoding.ts +58 -23
- package/src/websocket/LighterWsProvider.ts +47 -11
|
@@ -1,49 +1,84 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Lighter wire encoding for the WASM signer:
|
|
3
|
-
*
|
|
4
|
-
* mirroring the lighter-go signer's rules.
|
|
2
|
+
* Lighter wire encoding for the WASM signer: basis-point margin fractions and
|
|
3
|
+
* order-type/time-in-force/expiry resolution mirroring lighter-go's rules.
|
|
5
4
|
*/
|
|
6
5
|
/**
|
|
7
|
-
* Lighter
|
|
8
|
-
*
|
|
6
|
+
* Convert Lighter's initial-margin fraction to the largest whole-number
|
|
7
|
+
* leverage exposed by the provider.
|
|
8
|
+
*
|
|
9
|
+
* Lighter expresses margin fractions in basis points (`10_000` = 100%), so
|
|
10
|
+
* the conversion is `floor(10_000 / fraction)`. Non-finite or non-positive
|
|
11
|
+
* input uses the safe `1x` fallback.
|
|
12
|
+
*
|
|
13
|
+
* @param fraction - Lighter's basis-point initial-margin fraction.
|
|
14
|
+
* @returns The floored maximum leverage, or `1` for invalid input.
|
|
9
15
|
* @public
|
|
10
16
|
*/
|
|
11
17
|
export declare const marginFractionToMaxLeverage: (fraction: number) => number;
|
|
12
18
|
/**
|
|
13
|
-
* Convert leverage to
|
|
19
|
+
* Convert requested leverage to Lighter's basis-point margin fraction.
|
|
20
|
+
*
|
|
21
|
+
* The signer expects `round(10_000 / leverage)`, where the result is the
|
|
22
|
+
* margin requirement in basis points.
|
|
23
|
+
*
|
|
24
|
+
* @param leverage - Requested leverage multiplier.
|
|
25
|
+
* @returns The rounded basis-point margin fraction.
|
|
26
|
+
* @throws {PerpsError} With `ValidationError` when leverage is less than
|
|
27
|
+
* or equal to zero.
|
|
14
28
|
* @public
|
|
15
29
|
*/
|
|
16
30
|
export declare const leverageToFraction: (leverage: number) => number;
|
|
17
31
|
/**
|
|
18
|
-
* Map
|
|
32
|
+
* Map a LI.FI `OrderType` value to Lighter's integer wire type.
|
|
33
|
+
*
|
|
34
|
+
* Supported mappings are LIMIT → 0, MARKET → 1, STOP_MARKET → 2,
|
|
35
|
+
* STOP_LIMIT → 3, TAKE_PROFIT_MARKET → 4, and TAKE_PROFIT_LIMIT → 5.
|
|
36
|
+
* Omitted or unknown values fall back to LIMIT.
|
|
37
|
+
*
|
|
38
|
+
* @param type - LI.FI order type value.
|
|
39
|
+
* @returns The corresponding Lighter order-type integer.
|
|
19
40
|
* @public
|
|
20
41
|
*/
|
|
21
42
|
export declare const mapOrderTypeToInt: (type?: string) => number;
|
|
22
43
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
44
|
+
* Resolve a Lighter `time_in_force` value that is valid for an order type.
|
|
45
|
+
*
|
|
46
|
+
* Market-style orders (MARKET, STOP_MARKET, TAKE_PROFIT_MARKET) are IOC-only.
|
|
47
|
+
* Limit-style orders default to GTC when no TIF is supplied. An explicit
|
|
48
|
+
* non-IOC TIF on a market-style order raises a validation error. For
|
|
49
|
+
* limit-style orders, unknown TIF strings use the GTC fallback from
|
|
50
|
+
* {@link mapTimeInForceToInt}.
|
|
51
|
+
*
|
|
52
|
+
* @param orderTypeInt - Lighter order-type integer.
|
|
53
|
+
* @param tif - Optional LI.FI time-in-force value.
|
|
54
|
+
* @returns The validated Lighter time-in-force integer.
|
|
55
|
+
* @throws {PerpsError} With `ValidationError` for a market-style/TIF mismatch.
|
|
30
56
|
* @public
|
|
31
57
|
*/
|
|
32
58
|
export declare const resolveTimeInForce: (orderTypeInt: number, tif?: string) => number;
|
|
33
59
|
/**
|
|
34
|
-
* Map
|
|
60
|
+
* Map a LI.FI time-in-force value to Lighter's integer wire value.
|
|
61
|
+
*
|
|
62
|
+
* IOC maps to 0, GTC maps to 1, and POST_ONLY maps to 2. Omitted or unknown
|
|
63
|
+
* values fall back to GTC.
|
|
64
|
+
*
|
|
65
|
+
* @param tif - LI.FI time-in-force value.
|
|
66
|
+
* @returns The corresponding Lighter time-in-force integer.
|
|
35
67
|
* @public
|
|
36
68
|
*/
|
|
37
69
|
export declare const mapTimeInForceToInt: (tif?: string) => number;
|
|
38
70
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
71
|
+
* Select the `order_expiry` sentinel required for a regular Lighter limit
|
|
72
|
+
* order from its resolved time-in-force.
|
|
73
|
+
*
|
|
74
|
+
* IOC uses Lighter's nil expiry (`0`). Every other TIF uses
|
|
75
|
+
* `LT_DEFAULT_ORDER_EXPIRY` (`-1`), which the WASM signer expands to its
|
|
76
|
+
* canonical future expiry (`now + 28d`) as an absolute Unix-millisecond
|
|
77
|
+
* timestamp. Trigger-order expiry handling is provider-specific; see
|
|
78
|
+
* {@link LT_DEFAULT_ORDER_EXPIRY} and its call sites.
|
|
79
|
+
*
|
|
80
|
+
* @param tifInt - Lighter time-in-force integer.
|
|
81
|
+
* @returns `0` for IOC, otherwise the default-expiry sentinel.
|
|
47
82
|
* @public
|
|
48
83
|
*/
|
|
49
84
|
export declare const orderExpiryForTif: (tifInt: number) => number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wireEncoding.d.ts","sourceRoot":"","sources":["../../../src/utils/wireEncoding.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"wireEncoding.d.ts","sourceRoot":"","sources":["../../../src/utils/wireEncoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,KAAG,MAK9D,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,KAAG,MAQrD,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,MAUjD,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,GAC7B,cAAc,MAAM,EACpB,MAAM,MAAM,KACX,MAgBF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,MAOlD,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,MAKlD,CAAA"}
|
|
@@ -69,6 +69,12 @@ export declare class LighterWsProvider extends WsProviderBase<SubState> {
|
|
|
69
69
|
* `resolveAuthToken`. `undefined` when neither is available.
|
|
70
70
|
*/
|
|
71
71
|
private authTokenResolver;
|
|
72
|
+
/**
|
|
73
|
+
* Subscribe to a live quote stream resolved through the registered Lighter
|
|
74
|
+
* market registry. Returns an unsubscribe function; quote subscription
|
|
75
|
+
* requires the provider to be constructed through `lighterWsProvider` with a
|
|
76
|
+
* bound {@link PerpsSDKClient}.
|
|
77
|
+
*/
|
|
72
78
|
subscribeQuote(params: ProviderGetQuoteParams, onQuote: QuoteListener): Promise<() => void>;
|
|
73
79
|
protected openChannel(sub: Subscription): Promise<() => void>;
|
|
74
80
|
protected onClose(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LighterWsProvider.d.ts","sourceRoot":"","sources":["../../../src/websocket/LighterWsProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"LighterWsProvider.d.ts","sourceRoot":"","sources":["../../../src/websocket/LighterWsProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAKlB,cAAc,EACd,KAAK,iBAAiB,EAEvB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAIV,YAAY,EACb,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AA4EnC;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,wBAAwB,GAAG,CACrC,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;AAEhC,UAAU,QAAQ;IAChB,kFAAkF;IAClF,OAAO,EAAE,MAAM,CAAA;IACf,+DAA+D;IAC/D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,yEAAyE;IACzE,SAAS,EAAE,OAAO,CAAA;CACnB;AAkBD;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,wBAAwB,CAAA;CAC5C;AAED;;;;;;GAMG;AACH,qBAAa,iBAAkB,SAAQ,cAAc,CAAC,QAAQ,CAAC;IAC7D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAkB;IACtC,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAE5B;IACb,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IAEnD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAC/D,OAAO,CAAC,cAAc,CAAoC;IAE1D;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA2C;IAE9E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IAErD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA4B;IAC9D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAqC;gBAGxE,KAAK,GAAE,MAA+B,EACtC,WAAW,GAAE,MAA6B,EAC1C,OAAO,GAAE,wBAA6B,EACtC,MAAM,CAAC,EAAE,cAAc;IAsBzB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;;;;OAKG;IACG,cAAc,CAClB,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,MAAM,IAAI,CAAC;cAkBN,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;cA4ChD,OAAO,IAAI,IAAI;cAMlB,aAAa,CAAC,EAC5B,OAAO,EACP,SAAS,EACT,OAAO,GACR,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB3B,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM;YA2B5B,cAAc;YAsFd,mBAAmB;YAqBnB,iBAAiB;IAK/B,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAqB1C,OAAO,CAAC,QAAQ;IAkFhB,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,eAAe;IAuDvB,OAAO,CAAC,mBAAmB;IAiB3B,OAAO,CAAC,sBAAsB;IAiC9B;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAuB1B,OAAO,CAAC,iBAAiB;IAuCzB,OAAO,CAAC,eAAe;IA+BvB,OAAO,CAAC,YAAY;IAwBpB,OAAO,CAAC,mBAAmB;CAc5B;AAkID;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,GAC3B,UAAU,wBAAwB,KAAG,iBAEmB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk-provider-lighter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "Lighter provider plugin for @lifi/perps-sdk",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"big.js": "^7.0.1",
|
|
48
48
|
"viem": "^2.48.8",
|
|
49
|
-
"@lifi/perps-types": "^
|
|
49
|
+
"@lifi/perps-types": "^4.1.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@lifi/perps-sdk": "^
|
|
52
|
+
"@lifi/perps-sdk": "^6.1.0"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
package/src/LighterProvider.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type ProviderGetActivityParams,
|
|
13
13
|
type ProviderGetDepositFlowParams,
|
|
14
14
|
type ProviderGetFillsParams,
|
|
15
|
+
type ProviderGetMarketSettingsParams,
|
|
15
16
|
type ProviderGetOrderParams,
|
|
16
17
|
type ProviderGetOrdersParams,
|
|
17
18
|
type ProviderGetPositionsParams,
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
resolveRetryPolicy,
|
|
21
22
|
type SDKRequestOptions,
|
|
22
23
|
type SignActionsContext,
|
|
24
|
+
toPerpsMarketDisplay,
|
|
23
25
|
} from '@lifi/perps-sdk'
|
|
24
26
|
import type {
|
|
25
27
|
AccountConfig,
|
|
@@ -33,6 +35,7 @@ import type {
|
|
|
33
35
|
FillsResponse,
|
|
34
36
|
LighterAccountConfig,
|
|
35
37
|
LighterProviderKey,
|
|
38
|
+
MarketSettings,
|
|
36
39
|
Order,
|
|
37
40
|
OrdersResponse,
|
|
38
41
|
Position,
|
|
@@ -42,7 +45,12 @@ import type {
|
|
|
42
45
|
SignedActionStep,
|
|
43
46
|
SigningMethod,
|
|
44
47
|
} from '@lifi/perps-types'
|
|
45
|
-
import {
|
|
48
|
+
import {
|
|
49
|
+
ActionType,
|
|
50
|
+
ActivityType,
|
|
51
|
+
MarginMode,
|
|
52
|
+
PerpsErrorCode,
|
|
53
|
+
} from '@lifi/perps-types'
|
|
46
54
|
import type { Address } from 'viem'
|
|
47
55
|
import { projectLighterConfigSettings } from './accountConfig.js'
|
|
48
56
|
import { getAccountSummary } from './accountSummary.js'
|
|
@@ -77,6 +85,7 @@ import type {
|
|
|
77
85
|
LtTransferHistoryResponse,
|
|
78
86
|
LtWithdrawHistoryResponse,
|
|
79
87
|
} from './types/index.js'
|
|
88
|
+
import { LT_MARGIN_MODE_ISOLATED } from './types/index.js'
|
|
80
89
|
import {
|
|
81
90
|
decodeActivityCursor,
|
|
82
91
|
encodeActivityCursor,
|
|
@@ -94,12 +103,15 @@ import {
|
|
|
94
103
|
fetchDetailedAccount,
|
|
95
104
|
formatOrderPrice,
|
|
96
105
|
formatOrderSize,
|
|
106
|
+
leverageFromImf,
|
|
97
107
|
lighterAsset,
|
|
98
108
|
mapFill,
|
|
99
109
|
mapOpenPositions,
|
|
100
110
|
mapOrderDetail,
|
|
111
|
+
positionMarginConstraints,
|
|
101
112
|
toIsoFromMs,
|
|
102
113
|
toIsoFromSeconds,
|
|
114
|
+
toRequiredBig,
|
|
103
115
|
} from './utils/index.js'
|
|
104
116
|
|
|
105
117
|
const ZERO_FEE_TIER = { maker: '0', taker: '0' }
|
|
@@ -755,7 +767,7 @@ export const lighterProvider = (
|
|
|
755
767
|
normalizeLighterPublicKey(registeredKey.public_key)
|
|
756
768
|
|
|
757
769
|
const positions: Position[] = mapOpenPositions(account.positions, (id) =>
|
|
758
|
-
registry.require(String(id))
|
|
770
|
+
toPerpsMarketDisplay(registry.require(String(id)))
|
|
759
771
|
)
|
|
760
772
|
|
|
761
773
|
const totalMarginUsed = positions.reduce(
|
|
@@ -774,16 +786,24 @@ export const lighterProvider = (
|
|
|
774
786
|
categories.find((c) => c.quoteAsset === null)?.id ??
|
|
775
787
|
LIGHTER_SPOT_CATEGORY_ID
|
|
776
788
|
|
|
777
|
-
//
|
|
778
|
-
//
|
|
779
|
-
//
|
|
780
|
-
|
|
789
|
+
// Cross buying power is isolated from per-position allocations. Lighter
|
|
790
|
+
// reports cross equity (already marked by cross uPnL) separately from
|
|
791
|
+
// the initial margin locked by cross positions.
|
|
792
|
+
const availableMargin = toRequiredBig(
|
|
793
|
+
account.cross_asset_value,
|
|
794
|
+
'cross_asset_value'
|
|
795
|
+
).minus(
|
|
796
|
+
toRequiredBig(
|
|
797
|
+
account.cross_initial_margin_requirement,
|
|
798
|
+
'cross_initial_margin_requirement'
|
|
799
|
+
)
|
|
800
|
+
)
|
|
781
801
|
const collateralBalances: Balance[] = [
|
|
782
802
|
{
|
|
783
803
|
categoryId: perpsCategory?.id ?? providerKey,
|
|
784
804
|
asset: perpsCategory?.quoteAsset ?? lighterAsset('USDC', 'USDC'),
|
|
785
|
-
units:
|
|
786
|
-
valueUsd:
|
|
805
|
+
units: availableMargin.toString(),
|
|
806
|
+
valueUsd: availableMargin.toString(),
|
|
787
807
|
},
|
|
788
808
|
]
|
|
789
809
|
// Spot token holdings — non-collateral. USDC value is 1:1; other tokens
|
|
@@ -872,7 +892,7 @@ export const lighterProvider = (
|
|
|
872
892
|
])
|
|
873
893
|
|
|
874
894
|
let positions: Position[] = mapOpenPositions(account.positions, (id) =>
|
|
875
|
-
registry.require(String(id))
|
|
895
|
+
toPerpsMarketDisplay(registry.require(String(id)))
|
|
876
896
|
)
|
|
877
897
|
|
|
878
898
|
if (params.marketId !== undefined) {
|
|
@@ -886,6 +906,50 @@ export const lighterProvider = (
|
|
|
886
906
|
}
|
|
887
907
|
},
|
|
888
908
|
|
|
909
|
+
/**
|
|
910
|
+
* Lighter reports a market's margin mode and leverage only on the
|
|
911
|
+
* account's position row, so a market the account never touched (or a
|
|
912
|
+
* missing account) resolves `undefined` rather than a venue default.
|
|
913
|
+
*/
|
|
914
|
+
async getMarketSettings(
|
|
915
|
+
params: ProviderGetMarketSettingsParams,
|
|
916
|
+
opts?: SDKRequestOptions
|
|
917
|
+
): Promise<MarketSettings | undefined> {
|
|
918
|
+
// Spot markets carry no margin mode or leverage.
|
|
919
|
+
if (params.market.categoryId === LIGHTER_SPOT_CATEGORY_ID) {
|
|
920
|
+
return undefined
|
|
921
|
+
}
|
|
922
|
+
let account: LtDetailedAccount
|
|
923
|
+
try {
|
|
924
|
+
account = await fetchDetailedAccount(apiClient(opts), params.address)
|
|
925
|
+
} catch (err) {
|
|
926
|
+
if (
|
|
927
|
+
err instanceof PerpsError &&
|
|
928
|
+
err.code === PerpsErrorCode.AccountNotFound
|
|
929
|
+
) {
|
|
930
|
+
return undefined
|
|
931
|
+
}
|
|
932
|
+
throw err
|
|
933
|
+
}
|
|
934
|
+
const row = account.positions.find(
|
|
935
|
+
(p) => String(p.market_id) === params.market.marketId
|
|
936
|
+
)
|
|
937
|
+
if (!row) {
|
|
938
|
+
return undefined
|
|
939
|
+
}
|
|
940
|
+
const leverage = leverageFromImf(row.initial_margin_fraction)
|
|
941
|
+
if (leverage === undefined) {
|
|
942
|
+
return undefined
|
|
943
|
+
}
|
|
944
|
+
return {
|
|
945
|
+
marginMode:
|
|
946
|
+
row.margin_mode === LT_MARGIN_MODE_ISOLATED
|
|
947
|
+
? MarginMode.ISOLATED
|
|
948
|
+
: MarginMode.CROSS,
|
|
949
|
+
leverage,
|
|
950
|
+
}
|
|
951
|
+
},
|
|
952
|
+
|
|
889
953
|
/**
|
|
890
954
|
* Lighter's `accountActiveOrders` endpoint takes no limit/cursor and
|
|
891
955
|
* returns every active order for the account, so the response is always
|
|
@@ -1255,6 +1319,8 @@ export const lighterProvider = (
|
|
|
1255
1319
|
|
|
1256
1320
|
estimateLiquidationPrice,
|
|
1257
1321
|
|
|
1322
|
+
positionMarginConstraints,
|
|
1323
|
+
|
|
1258
1324
|
projectConfig(
|
|
1259
1325
|
config: AccountConfig,
|
|
1260
1326
|
setup: ProviderAction[],
|
package/src/accountSummary.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { summarizeAccount } from '@lifi/perps-sdk'
|
|
2
1
|
import type {
|
|
3
2
|
AccountResponse,
|
|
4
3
|
AccountSummary,
|
|
5
4
|
Position,
|
|
6
5
|
} from '@lifi/perps-types'
|
|
6
|
+
import { MarginMode } from '@lifi/perps-types'
|
|
7
|
+
import Big from 'big.js'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Roll a Lighter {@link AccountResponse} up into an {@link AccountSummary}.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* Lighter's cross available balance is already marked to market, while an
|
|
13
|
+
* isolated position's unrealized PnL remains inside that position's isolated
|
|
14
|
+
* sub-account. Reconciliation therefore adds every position's locked margin,
|
|
15
|
+
* but adds unrealized PnL only for isolated positions.
|
|
14
16
|
*
|
|
15
17
|
* @public
|
|
16
18
|
*/
|
|
@@ -18,5 +20,35 @@ export function getAccountSummary(
|
|
|
18
20
|
account: AccountResponse,
|
|
19
21
|
positions: Position[]
|
|
20
22
|
): AccountSummary {
|
|
21
|
-
|
|
23
|
+
let availableMargin = new Big(0)
|
|
24
|
+
for (const balance of account.collateralBalances) {
|
|
25
|
+
availableMargin = availableMargin.plus(balance.valueUsd)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let nonCollateralValue = new Big(0)
|
|
29
|
+
for (const balance of account.balances) {
|
|
30
|
+
nonCollateralValue = nonCollateralValue.plus(balance.valueUsd)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let marginUsed = new Big(0)
|
|
34
|
+
let unrealizedPnl = new Big(0)
|
|
35
|
+
let isolatedUnrealizedPnl = new Big(0)
|
|
36
|
+
for (const position of positions) {
|
|
37
|
+
marginUsed = marginUsed.plus(position.marginUsed)
|
|
38
|
+
unrealizedPnl = unrealizedPnl.plus(position.unrealizedPnl)
|
|
39
|
+
if (position.marginMode === MarginMode.ISOLATED) {
|
|
40
|
+
isolatedUnrealizedPnl = isolatedUnrealizedPnl.plus(position.unrealizedPnl)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
portfolioValue: nonCollateralValue
|
|
46
|
+
.plus(availableMargin)
|
|
47
|
+
.plus(marginUsed)
|
|
48
|
+
.plus(isolatedUnrealizedPnl)
|
|
49
|
+
.toString(),
|
|
50
|
+
availableMargin: availableMargin.toString(),
|
|
51
|
+
marginUsed: marginUsed.toString(),
|
|
52
|
+
unrealizedPnl: unrealizedPnl.toString(),
|
|
53
|
+
}
|
|
22
54
|
}
|
package/src/constants.ts
CHANGED
|
@@ -22,6 +22,11 @@ export const LIGHTER_SPOT_CATEGORY_ID = 'spot'
|
|
|
22
22
|
* @public
|
|
23
23
|
*/
|
|
24
24
|
export const DEFAULT_LIGHTER_REST_URL = 'https://mainnet.zklighter.elliot.ai'
|
|
25
|
+
/**
|
|
26
|
+
* Default mainnet WebSocket stream URL for Lighter.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
25
30
|
export const DEFAULT_LIGHTER_WS_URL = 'wss://mainnet.zklighter.elliot.ai/stream'
|
|
26
31
|
|
|
27
32
|
/**
|
|
@@ -85,9 +90,17 @@ export const LIGHTER_MAINNET_INSTANCE: LighterInstanceConfig = {
|
|
|
85
90
|
*/
|
|
86
91
|
export const LIGHTER_RH_PROVIDER_KEY = 'lighter-rh'
|
|
87
92
|
|
|
88
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Default REST base URL for the Lighter Robinhood deployment.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
89
98
|
export const LIGHTER_RH_REST_URL = 'https://api.rh.lighter.xyz'
|
|
90
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* Default WebSocket URL for the Lighter Robinhood deployment.
|
|
101
|
+
*
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
91
104
|
export const LIGHTER_RH_WS_URL = 'wss://api.rh.lighter.xyz/stream'
|
|
92
105
|
|
|
93
106
|
/**
|
|
@@ -11,7 +11,13 @@ import { LIGHTER_PROVIDER_KEY } from '../constants.js'
|
|
|
11
11
|
|
|
12
12
|
const STORAGE_PREFIX = 'lifi-perps-lighter-key'
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Persisted Lighter API-key material associated with one L2 account.
|
|
16
|
+
* `apiKeyPrivateKey` is a Lighter-native signing key, not an Ethereum key;
|
|
17
|
+
* `apiKeyIndex` identifies its registered on-chain slot.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
15
21
|
export interface LighterApiKey {
|
|
16
22
|
/** Lighter account index, looked up once via accountsByL1Address. */
|
|
17
23
|
accountIndex: number
|
|
@@ -41,12 +47,23 @@ const isLighterApiKey = (value: unknown): value is LighterApiKey => {
|
|
|
41
47
|
)
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Storage-backed cache for Lighter API keys. Records are namespaced by L1
|
|
52
|
+
* address and provider instance so multiple Lighter deployments can share one
|
|
53
|
+
* {@link StorageAdapter} without collisions.
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
45
57
|
export class LighterKeyStore {
|
|
46
58
|
private readonly storage: StorageAdapter
|
|
47
59
|
private readonly cache = new Map<string, LighterApiKey>()
|
|
48
60
|
private providerKey: LighterProviderKey
|
|
49
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Create a key store using `storage` and the optional provider namespace.
|
|
64
|
+
* The default provider key preserves the package's standard Lighter storage
|
|
65
|
+
* namespace.
|
|
66
|
+
*/
|
|
50
67
|
constructor(
|
|
51
68
|
storage: StorageAdapter,
|
|
52
69
|
providerKey: LighterProviderKey = LIGHTER_PROVIDER_KEY
|
|
@@ -74,6 +91,10 @@ export class LighterKeyStore {
|
|
|
74
91
|
: `${STORAGE_PREFIX}:${this.providerKey}:${lower}`
|
|
75
92
|
}
|
|
76
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Load the API key for an L1 address, or `null` when no valid record exists.
|
|
96
|
+
* Invalid persisted records are ignored by the storage validation boundary.
|
|
97
|
+
*/
|
|
77
98
|
async get(address: Address): Promise<LighterApiKey | null> {
|
|
78
99
|
const key = this.storageKey(address)
|
|
79
100
|
const cached = this.cache.get(key)
|
|
@@ -88,12 +109,20 @@ export class LighterKeyStore {
|
|
|
88
109
|
return parsed
|
|
89
110
|
}
|
|
90
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Persist an API key for an L1 address, replacing any existing record under
|
|
114
|
+
* that provider namespace.
|
|
115
|
+
*/
|
|
91
116
|
async set(address: Address, value: LighterApiKey): Promise<void> {
|
|
92
117
|
const key = this.storageKey(address)
|
|
93
118
|
this.cache.set(key, value)
|
|
94
119
|
await this.storage.set(key, JSON.stringify(value))
|
|
95
120
|
}
|
|
96
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Remove the persisted API key for an L1 address and clear its in-memory
|
|
124
|
+
* cache entry.
|
|
125
|
+
*/
|
|
97
126
|
async remove(address: Address): Promise<void> {
|
|
98
127
|
const key = this.storageKey(address)
|
|
99
128
|
this.cache.delete(key)
|
|
@@ -69,7 +69,13 @@ export type LighterTokenFetcher = (params: {
|
|
|
69
69
|
scopes: string
|
|
70
70
|
}) => Promise<LighterCreateTokenResponse>
|
|
71
71
|
|
|
72
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Dependencies and overrides for {@link LighterReadOnlyTokenManager}.
|
|
74
|
+
* Storage and token-fetching defaults target the browser's local storage and
|
|
75
|
+
* Lighter's mainnet REST API.
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
73
79
|
export interface LighterReadOnlyTokenManagerOptions {
|
|
74
80
|
storage?: StorageAdapter
|
|
75
81
|
/**
|
|
@@ -87,13 +93,23 @@ export interface LighterReadOnlyTokenManagerOptions {
|
|
|
87
93
|
now?: () => number
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Input to the read-only-token approval flow. Extends the shared approval
|
|
98
|
+
* parameters with the L1 address whose wallet authorizes token creation.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
91
102
|
export interface ApproveReadOnlyTokenInputs extends ApproveReadOnlyTokenParams {
|
|
92
103
|
/** L1 wallet address that signs the create message. */
|
|
93
104
|
address: Address
|
|
94
105
|
}
|
|
95
106
|
|
|
96
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Result of approving or creating a Lighter read-only token. `config` is the
|
|
109
|
+
* account-state projection callers can persist alongside the token.
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
97
113
|
export interface ApproveReadOnlyTokenResult {
|
|
98
114
|
token: LighterReadOnlyToken
|
|
99
115
|
/** Projection of the post-create Lighter account state. */
|
|
@@ -239,6 +255,10 @@ export class LighterReadOnlyTokenManager {
|
|
|
239
255
|
await this.storage.set(key, JSON.stringify(token))
|
|
240
256
|
}
|
|
241
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Remove the stored token for an `(address, accountIndex)` pair and clear
|
|
260
|
+
* the corresponding cache entry.
|
|
261
|
+
*/
|
|
242
262
|
async remove(address: Address, accountIndex: number): Promise<void> {
|
|
243
263
|
const key = this.storageKey(address, accountIndex)
|
|
244
264
|
this.cache.delete(key)
|
|
@@ -21,7 +21,13 @@ import {
|
|
|
21
21
|
// is process-global inside the Go runtime; we track which keys are already
|
|
22
22
|
// initialized so CreateClient runs once per keypair.
|
|
23
23
|
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Credentials needed to initialize the Lighter WASM client for one account
|
|
26
|
+
* and API-key slot. The private key is Lighter-native signing material; the
|
|
27
|
+
* account and slot indexes select the registered L2 key.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
25
31
|
export interface LighterSignerContext {
|
|
26
32
|
/** Lighter-native private key (from GenerateAPIKey, NOT an Ethereum key). */
|
|
27
33
|
apiKeyPrivateKey: string
|
|
@@ -31,7 +37,12 @@ export interface LighterSignerContext {
|
|
|
31
37
|
accountIndex: number
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Configuration for {@link LighterSigner}, including optional WASM asset
|
|
42
|
+
* overrides and the Lighter REST base URL and signing chain ID.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
35
46
|
export interface LighterSignerConfig extends LoadLighterWasmOptions {
|
|
36
47
|
/** Lighter REST API base URL. */
|
|
37
48
|
apiUrl?: string
|
|
@@ -39,26 +50,47 @@ export interface LighterSignerConfig extends LoadLighterWasmOptions {
|
|
|
39
50
|
chainId?: number
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Signed Lighter transaction blob returned by the WASM signer. `txType`,
|
|
55
|
+
* `txInfo`, and `txHash` are passed to the venue's transaction submission
|
|
56
|
+
* endpoint; `txInfo` is an encoded transaction payload.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
43
60
|
export interface LighterSignedBlob {
|
|
44
61
|
txType: number
|
|
45
62
|
txInfo: string
|
|
46
63
|
txHash: string
|
|
47
64
|
}
|
|
48
65
|
|
|
49
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Signed REGISTER_API_KEY (ChangePubKey) result, including the EIP-191 message
|
|
68
|
+
* that the user's L1 wallet must countersign before submission.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
50
72
|
export interface ChangePubKeyResult extends LighterSignedBlob {
|
|
51
73
|
/** EIP-191 message the L1 Ethereum wallet must sign to authorize the key rotation. */
|
|
52
74
|
messageToSign: string
|
|
53
75
|
}
|
|
54
76
|
|
|
55
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Signed APPROVE_INTEGRATOR result, including the EIP-191 L1 message required
|
|
79
|
+
* to authorize the integrator approval.
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
56
83
|
export interface ApproveIntegratorResult extends LighterSignedBlob {
|
|
57
84
|
/** EIP-191 `L2ApproveIntegrator` L1 body the user's wallet must countersign to authorize the integrator approval. */
|
|
58
85
|
messageToSign: string
|
|
59
86
|
}
|
|
60
87
|
|
|
61
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Lighter-native API keypair generated by the WASM signer. These keys are
|
|
90
|
+
* distinct from an Ethereum wallet keypair.
|
|
91
|
+
*
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
62
94
|
export interface ApiKeyPair {
|
|
63
95
|
publicKey: string
|
|
64
96
|
privateKey: string
|
|
@@ -94,7 +126,13 @@ const LIGHTER_ROUTE_BY_DEX: Record<string, number> = {
|
|
|
94
126
|
spot: LT_ROUTE_SPOT,
|
|
95
127
|
}
|
|
96
128
|
|
|
97
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* WASM-backed signer for Lighter API-key transactions and L1-countersigned
|
|
131
|
+
* hybrid flows. The instance memoizes WASM initialization and registered
|
|
132
|
+
* `(apiKeyIndex, accountIndex)` clients.
|
|
133
|
+
*
|
|
134
|
+
* @public
|
|
135
|
+
*/
|
|
98
136
|
export class LighterSigner {
|
|
99
137
|
private readonly apiUrl: string
|
|
100
138
|
private readonly chainId: number
|
|
@@ -112,6 +150,10 @@ export class LighterSigner {
|
|
|
112
150
|
}
|
|
113
151
|
}
|
|
114
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Load and cache the Go WASM signer exports. Most signing methods initialize
|
|
155
|
+
* lazily, so callers only need this method when they want an explicit warm-up.
|
|
156
|
+
*/
|
|
115
157
|
async initialize(): Promise<void> {
|
|
116
158
|
if (!this.wasm) {
|
|
117
159
|
this.wasm = await loadLighterWasm(this.loaderOptions)
|