@lifi/perps-sdk-provider-lighter 34.0.0 → 35.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/LighterProvider.d.ts +0 -1
- package/dist/cjs/LighterProvider.d.ts.map +1 -1
- package/dist/cjs/LighterProvider.js +50 -44
- package/dist/cjs/LighterProvider.js.map +1 -1
- package/dist/cjs/accountSummary.d.ts.map +1 -1
- package/dist/cjs/accountSummary.js +3 -6
- package/dist/cjs/accountSummary.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.d.ts.map +1 -1
- package/dist/cjs/constants.js +2 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/signers/createAuthToken.d.ts.map +1 -1
- package/dist/cjs/signers/createAuthToken.js.map +1 -1
- package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
- package/dist/cjs/utils/mapPosition.js +4 -1
- package/dist/cjs/utils/mapPosition.js.map +1 -1
- package/dist/cjs/utils/settlementPool.d.ts +6 -0
- package/dist/cjs/utils/settlementPool.d.ts.map +1 -0
- package/dist/cjs/utils/settlementPool.js +21 -0
- package/dist/cjs/utils/settlementPool.js.map +1 -0
- package/dist/cjs/utils/transferMargin.d.ts.map +1 -1
- package/dist/cjs/utils/transferMargin.js +1 -6
- package/dist/cjs/utils/transferMargin.js.map +1 -1
- package/dist/esm/LighterProvider.d.ts +7 -11
- package/dist/esm/LighterProvider.d.ts.map +1 -1
- package/dist/esm/LighterProvider.js +60 -51
- package/dist/esm/LighterProvider.js.map +1 -1
- package/dist/esm/accountSummary.d.ts +2 -1
- package/dist/esm/accountSummary.d.ts.map +1 -1
- package/dist/esm/accountSummary.js +5 -7
- package/dist/esm/accountSummary.js.map +1 -1
- package/dist/esm/constants.d.ts +8 -0
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +8 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/signers/createAuthToken.d.ts +1 -2
- package/dist/esm/signers/createAuthToken.d.ts.map +1 -1
- package/dist/esm/signers/createAuthToken.js +1 -2
- package/dist/esm/signers/createAuthToken.js.map +1 -1
- package/dist/esm/utils/mapPosition.d.ts +4 -3
- package/dist/esm/utils/mapPosition.d.ts.map +1 -1
- package/dist/esm/utils/mapPosition.js +9 -5
- package/dist/esm/utils/mapPosition.js.map +1 -1
- package/dist/esm/utils/settlementPool.d.ts +14 -0
- package/dist/esm/utils/settlementPool.d.ts.map +1 -0
- package/dist/esm/utils/settlementPool.js +23 -0
- package/dist/esm/utils/settlementPool.js.map +1 -0
- package/dist/esm/utils/transferMargin.d.ts.map +1 -1
- package/dist/esm/utils/transferMargin.js +2 -7
- package/dist/esm/utils/transferMargin.js.map +1 -1
- package/dist/types/LighterProvider.d.ts +7 -11
- package/dist/types/LighterProvider.d.ts.map +1 -1
- package/dist/types/accountSummary.d.ts +2 -1
- package/dist/types/accountSummary.d.ts.map +1 -1
- package/dist/types/constants.d.ts +8 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/signers/createAuthToken.d.ts +1 -2
- package/dist/types/signers/createAuthToken.d.ts.map +1 -1
- package/dist/types/utils/mapPosition.d.ts +4 -3
- package/dist/types/utils/mapPosition.d.ts.map +1 -1
- package/dist/types/utils/settlementPool.d.ts +14 -0
- package/dist/types/utils/settlementPool.d.ts.map +1 -0
- package/dist/types/utils/transferMargin.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/LighterProvider.ts +98 -90
- package/src/accountSummary.ts +10 -10
- package/src/constants.ts +9 -0
- package/src/index.ts +1 -0
- package/src/signers/createAuthToken.ts +1 -2
- package/src/utils/mapPosition.ts +12 -5
- package/src/utils/settlementPool.ts +36 -0
- package/src/utils/transferMargin.ts +4 -10
|
@@ -9,11 +9,9 @@ import { type LighterDeployment } from './constants.js';
|
|
|
9
9
|
* manager are created per plugin instance.
|
|
10
10
|
*
|
|
11
11
|
* Auth-token resolution order for the auth-gated reads:
|
|
12
|
-
* 1.
|
|
13
|
-
* 2. Constructor `authToken` (string or async factory)
|
|
14
|
-
* 3. Persisted long-lived read-only token, keyed on the resolved Lighter
|
|
12
|
+
* 1. Persisted long-lived read-only token, keyed on the resolved Lighter
|
|
15
13
|
* `accountIndex`
|
|
16
|
-
*
|
|
14
|
+
* 2. Fresh 1h create via this instance's WASM signer + the user's registered
|
|
17
15
|
* API key
|
|
18
16
|
*
|
|
19
17
|
* Status reads report the account's state and do not throw for a missing
|
|
@@ -27,9 +25,9 @@ import { type LighterDeployment } from './constants.js';
|
|
|
27
25
|
* - `SetupRequired` when none of these sources yields a token. The SDK
|
|
28
26
|
* sends no venue request. `getOrders`, `getOrder`, `getFills`,
|
|
29
27
|
* `getPortfolioHistory` and `getActivity` need a token.
|
|
30
|
-
* - `Unauthorized` when Lighter rejects the token that was sent.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
28
|
+
* - `Unauthorized` when Lighter rejects the token that was sent. A
|
|
29
|
+
* read-only token that Lighter reports as revoked is replaced and the
|
|
30
|
+
* read retried once first.
|
|
33
31
|
* - `AccountNotFound` when the wallet has no Lighter account. This also
|
|
34
32
|
* applies to `getPositions`, `getWithdrawableBalances` and
|
|
35
33
|
* `getAvailableToTrade`, which need no token. `getAvailableToTrade`
|
|
@@ -52,8 +50,6 @@ export interface LighterProviderOptions {
|
|
|
52
50
|
* instance's signer and read-only token manager follow this URL.
|
|
53
51
|
*/
|
|
54
52
|
restUrl?: string;
|
|
55
|
-
/** Pre-created Lighter read-only bearer, bypassing SDK token resolution. */
|
|
56
|
-
authToken?: string | (() => string | Promise<string>);
|
|
57
53
|
/** Token lifetime for on-demand standard-token creates (Lighter caps at 8h). Default 1h. */
|
|
58
54
|
tokenLifetimeSeconds?: number;
|
|
59
55
|
/** Re-create when the cached standard token's remaining life is below this. Default 60s. */
|
|
@@ -71,8 +67,8 @@ export interface LighterProviderOptions {
|
|
|
71
67
|
export interface LighterPerpsProvider extends PerpsProviderPlugin {
|
|
72
68
|
/**
|
|
73
69
|
* Resolve a Lighter auth token for `address`, following the resolution order
|
|
74
|
-
* documented on {@link LighterProviderOptions}
|
|
75
|
-
*
|
|
70
|
+
* documented on {@link LighterProviderOptions}. Returns `undefined` when no
|
|
71
|
+
* source can produce a token.
|
|
76
72
|
*/
|
|
77
73
|
resolveAuthToken(address: Address): Promise<string | undefined>;
|
|
78
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LighterProvider.d.ts","sourceRoot":"","sources":["../../src/LighterProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAeL,KAAK,mBAAmB,EAqBxB,KAAK,cAAc,EAEpB,MAAM,iBAAiB,CAAA;AAmCxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAQnC,OAAO,EAUL,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"LighterProvider.d.ts","sourceRoot":"","sources":["../../src/LighterProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAeL,KAAK,mBAAmB,EAqBxB,KAAK,cAAc,EAEpB,MAAM,iBAAiB,CAAA;AAmCxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAQnC,OAAO,EAUL,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAA;AAiLvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,4FAA4F;IAC5F,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,4FAA4F;IAC5F,uBAAuB,CAAC,EAAE,MAAM,CAAA;CACjC;AAcD;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;CAChE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAChC,YAAY,iBAAiB,EAC7B,UAAS,sBAA2B,KACnC,oBAwgDF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAS,sBAA2B,KACnC,oBACyD,CAAA;AAE5D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAS,sBAA2B,KACnC,oBAA6E,CAAA;AAEhF;;;;GAIG;AACH,eAAO,MAAM,OAAO,aA7BT,sBAAsB,KAC9B,oBA4BmC,CAAA"}
|
|
@@ -12,7 +12,8 @@ export declare const lighterConfig: (account: AccountResponse) => LighterAccount
|
|
|
12
12
|
export declare const lighterPortfolioValue: (perpsEquity: Big, holdingValuesUsd: readonly string[]) => Big;
|
|
13
13
|
/**
|
|
14
14
|
* Roll up settlement equity, spot holdings and non-settlement margin holdings.
|
|
15
|
-
*
|
|
15
|
+
* The settlement asset counts as `totalAssetValue` plus its spot-route balance,
|
|
16
|
+
* so a row that pools both routes is not counted again.
|
|
16
17
|
*
|
|
17
18
|
* @throws {PerpsError} `SDKError` when the account is not a Lighter one.
|
|
18
19
|
* @public
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accountSummary.d.ts","sourceRoot":"","sources":["../../src/accountSummary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,QAAQ,EACT,MAAM,mBAAmB,CAAA;AAE1B,OAAO,GAAG,MAAM,QAAQ,CAAA;AASxB;;;;GAIG;AACH,eAAO,MAAM,aAAa,GACxB,SAAS,eAAe,KACvB,oBAYF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAChC,aAAa,GAAG,EAChB,kBAAkB,SAAS,MAAM,EAAE,KAClC,GAIA,CAAA;AAEH
|
|
1
|
+
{"version":3,"file":"accountSummary.d.ts","sourceRoot":"","sources":["../../src/accountSummary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,QAAQ,EACT,MAAM,mBAAmB,CAAA;AAE1B,OAAO,GAAG,MAAM,QAAQ,CAAA;AASxB;;;;GAIG;AACH,eAAO,MAAM,aAAa,GACxB,SAAS,eAAe,KACvB,oBAYF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAChC,aAAa,GAAG,EAChB,kBAAkB,SAAS,MAAM,EAAE,KAClC,GAIA,CAAA;AAEH;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,eAAe,EACxB,SAAS,EAAE,QAAQ,EAAE,GACpB,cAAc,CAkChB"}
|
|
@@ -147,6 +147,14 @@ export declare const DEFAULT_TRADES_LIMIT = 50;
|
|
|
147
147
|
* @internal
|
|
148
148
|
*/
|
|
149
149
|
export declare const LIGHTER_FEE_TICK_SCALE = 1000000;
|
|
150
|
+
/**
|
|
151
|
+
* Decimal places a client may use for Lighter leverage. Lighter stores
|
|
152
|
+
* leverage as an integer basis-point IMF (`round(10000 / leverage)`), and at
|
|
153
|
+
* this precision a read-back leverage always re-saves the same IMF.
|
|
154
|
+
*
|
|
155
|
+
* @public
|
|
156
|
+
*/
|
|
157
|
+
export declare const LIGHTER_LEVERAGE_PRECISION = 2;
|
|
150
158
|
/**
|
|
151
159
|
* Scale of the integer `initial_margin_fraction` values Lighter publishes on
|
|
152
160
|
* trade rows and order-book details: the integer is a percent times 100, so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAGpE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,YAAY,CAAA;AAE7C;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,eAAe,CAAA;AAEnD;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,SAAS,CAAA;AAE9C;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,wCAAwC,CAAA;AAC7E;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,6CAA6C,CAAA;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,MAAM,CAAA;AAElD;;;;;GAKG;AACH,eAAO,MAAM,oCAAoC,2CACP,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAC5C,kBAAkB,EAClB,sBAAsB,CAUvB,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,gFAAgF;IAChF,WAAW,EAAE,kBAAkB,CAAA;IAC/B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,uFAAuF;IACvF,aAAa,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,UAAU,EAAE,sBAAsB,CAAA;IAClC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;;OAGG;IACH,aAAa,EAAE,eAAe,CAAA;CAC/B;AAED;;;;GAIG;AACH,eAAO,MAAM,0B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export { projectLighterConfigSettings } from './accountConfig.js';
|
|
13
13
|
export { getAccountSummary } from './accountSummary.js';
|
|
14
14
|
export type { LighterCollateralAsset, LighterDeployment, } from './constants.js';
|
|
15
|
-
export { DEFAULT_LIGHTER_EXPLORER_TX_BASE_URL, DEFAULT_LIGHTER_REST_URL, DEFAULT_LIGHTER_WS_URL, LIGHTER_CLIENT_ORDER_INDEX_ID_PREFIX, LIGHTER_COLLATERAL_ASSETS, LIGHTER_MAINNET_DEPLOYMENT, LIGHTER_MAINNET_SIGNER_CHAIN_ID, LIGHTER_PROVIDER_KEY, LIGHTER_RH_DEPLOYMENT, LIGHTER_RH_PROVIDER_KEY, LIGHTER_RH_REST_URL, LIGHTER_RH_SIGNER_CHAIN_ID, LIGHTER_RH_WS_URL, LIGHTER_SPOT_CATEGORY_ID, } from './constants.js';
|
|
15
|
+
export { DEFAULT_LIGHTER_EXPLORER_TX_BASE_URL, DEFAULT_LIGHTER_REST_URL, DEFAULT_LIGHTER_WS_URL, LIGHTER_CLIENT_ORDER_INDEX_ID_PREFIX, LIGHTER_COLLATERAL_ASSETS, LIGHTER_LEVERAGE_PRECISION, LIGHTER_MAINNET_DEPLOYMENT, LIGHTER_MAINNET_SIGNER_CHAIN_ID, LIGHTER_PROVIDER_KEY, LIGHTER_RH_DEPLOYMENT, LIGHTER_RH_PROVIDER_KEY, LIGHTER_RH_REST_URL, LIGHTER_RH_SIGNER_CHAIN_ID, LIGHTER_RH_WS_URL, LIGHTER_SPOT_CATEGORY_ID, } from './constants.js';
|
|
16
16
|
export { lighterDepositFlow } from './depositFlow.js';
|
|
17
17
|
export type { LighterPerpsProvider, LighterProviderOptions, } from './LighterProvider.js';
|
|
18
18
|
export { Lighter, lighterProvider, lighterRhProvider, } from './LighterProvider.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE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ACpC,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,+BAA+B,EAC/B,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,YAAY,EACV,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,OAAO,EACP,eAAe,EACf,iBAAiB,GAClB,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,YAAY,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAA;AAChF,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,iBAAiB,GAClB,MAAM,kCAAkC,CAAA"}
|
|
@@ -25,8 +25,7 @@ export interface CreateAuthTokenInputs {
|
|
|
25
25
|
* endpoints (`getOrders`, `getOrder`, `getActivity`, etc.).
|
|
26
26
|
*
|
|
27
27
|
* This utility carries no SDK-wide coupling — pass an explicit `signer` +
|
|
28
|
-
* `apiKey` and consume the returned bearer however the caller likes
|
|
29
|
-
* (per-call `options.lighterAuthToken`, persisted cache, etc.).
|
|
28
|
+
* `apiKey` and consume the returned bearer however the caller likes.
|
|
30
29
|
* @public
|
|
31
30
|
*/
|
|
32
31
|
export declare function createAuthToken(inputs: CreateAuthTokenInputs): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAuthToken.d.ts","sourceRoot":"","sources":["../../../src/signers/createAuthToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAKvD;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,aAAa,CAAA;IACrB,MAAM,EAAE,IAAI,CACV,aAAa,EACb,kBAAkB,GAAG,aAAa,GAAG,cAAc,CACpD,CAAA;IACD;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,qEAAqE;IACrE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CACnB;AAED
|
|
1
|
+
{"version":3,"file":"createAuthToken.d.ts","sourceRoot":"","sources":["../../../src/signers/createAuthToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAKvD;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,aAAa,CAAA;IACrB,MAAM,EAAE,IAAI,CACV,aAAa,EACb,kBAAkB,GAAG,aAAa,GAAG,cAAc,CACpD,CAAA;IACD;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,qEAAqE;IACrE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,oBAAoB,GAAG,SAAS,GAAG,IAAI,EAC9C,gBAAgB,GAAE,MAAkC,EACpD,GAAG,GAAE,MAAM,MAAyB,GACnC,OAAO,CAST"}
|
|
@@ -2,9 +2,10 @@ import type { PerpsMarketDisplay, Position } from '@lifi/perps-types';
|
|
|
2
2
|
import type { LtAccountPosition } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Display leverage from an IMF percent string: `100 / IMF` in exact decimal
|
|
5
|
-
* arithmetic
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* arithmetic, rounded half-up to `LIGHTER_LEVERAGE_PRECISION` before
|
|
6
|
+
* conversion to `number`, so the value a client reads is the value it saved.
|
|
7
|
+
* Provider risk calculations consume the original decimal IMF instead.
|
|
8
|
+
* `undefined` for a non-positive or unparsable IMF.
|
|
8
9
|
* @public
|
|
9
10
|
*/
|
|
10
11
|
export declare const leverageFromImf: (imf: string) => number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapPosition.d.ts","sourceRoot":"","sources":["../../../src/utils/mapPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"mapPosition.d.ts","sourceRoot":"","sources":["../../../src/utils/mapPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAOrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAI1D;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SActD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAQ5D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,GACtB,KAAK,iBAAiB,EACtB,QAAQ,kBAAkB,KACzB,QAiCF,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type Big from 'big.js';
|
|
2
|
+
import type { LtAccountAsset } from '../types/account.js';
|
|
3
|
+
/** Both routes of a unified account's settlement asset, as one holding. */
|
|
4
|
+
export declare const pooledSettlementUnits: (asset: LtAccountAsset) => Big;
|
|
5
|
+
/**
|
|
6
|
+
* Spot units a unified account can spend from its settlement pool: the free
|
|
7
|
+
* spot route plus the margin route up to the account's `available_balance`.
|
|
8
|
+
* This is `computeSpotAvailableToTradeMarket` in Lighter's `lighter-ts` for an
|
|
9
|
+
* asset priced 1:1 with a `loan_to_value` of 1. The result can be negative.
|
|
10
|
+
*/
|
|
11
|
+
export declare const pooledSettlementSpendable: (asset: LtAccountAsset, availableBalance: Big) => Big;
|
|
12
|
+
/** Spot-route `balance` of the collateral asset; `'0'` when the account holds none. */
|
|
13
|
+
export declare const collateralSpotBalance: (assets: readonly LtAccountAsset[], settlementAssetIndex: number) => string;
|
|
14
|
+
//# sourceMappingURL=settlementPool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settlementPool.d.ts","sourceRoot":"","sources":["../../../src/utils/settlementPool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAA;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGzD,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB,GAAI,OAAO,cAAc,KAAG,GAG3D,CAAA;AAEH;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,GACpC,OAAO,cAAc,EACrB,kBAAkB,GAAG,KACpB,GAKF,CAAA;AAED,uFAAuF;AACvF,eAAO,MAAM,qBAAqB,GAChC,QAAQ,SAAS,cAAc,EAAE,EACjC,sBAAsB,MAAM,KAC3B,MAKF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transferMargin.d.ts","sourceRoot":"","sources":["../../../src/utils/transferMargin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transferMargin.d.ts","sourceRoot":"","sources":["../../../src/utils/transferMargin.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAA;AAoB1B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,QAAQ,GACjB,aAAa,GAAG,SAAS,CAmB3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk-provider-lighter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "35.1.0",
|
|
4
4
|
"description": "Lighter provider plugin for @lifi/perps-sdk",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"big.js": "^7.0.1",
|
|
46
46
|
"viem": "^2.55.18",
|
|
47
|
-
"@lifi/perps-types": "^20.
|
|
47
|
+
"@lifi/perps-types": "^20.2.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@lifi/perps-sdk": "^
|
|
50
|
+
"@lifi/perps-sdk": "^23.1.0"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
package/src/LighterProvider.ts
CHANGED
|
@@ -125,6 +125,7 @@ import type {
|
|
|
125
125
|
} from './types/index.js'
|
|
126
126
|
import {
|
|
127
127
|
LT_ACCOUNT_TRADING_MODE_SIMPLE,
|
|
128
|
+
LT_ACCOUNT_TRADING_MODE_UNIFIED,
|
|
128
129
|
LT_MARGIN_MODE_CROSS,
|
|
129
130
|
LT_MARGIN_MODE_ISOLATED,
|
|
130
131
|
} from './types/index.js'
|
|
@@ -162,6 +163,11 @@ import {
|
|
|
162
163
|
fetchRegisteredApiKey,
|
|
163
164
|
normalizeLighterPublicKey,
|
|
164
165
|
} from './utils/registeredApiKey.js'
|
|
166
|
+
import {
|
|
167
|
+
collateralSpotBalance,
|
|
168
|
+
pooledSettlementSpendable,
|
|
169
|
+
pooledSettlementUnits,
|
|
170
|
+
} from './utils/settlementPool.js'
|
|
165
171
|
import { spotPriceByAssetId, spotValuation } from './utils/spotPrice.js'
|
|
166
172
|
import { isPlaceholderTxHash } from './utils/txHash.js'
|
|
167
173
|
import { wireList } from './utils/wireList.js'
|
|
@@ -269,11 +275,9 @@ interface ReadOnlyCreationBackoff {
|
|
|
269
275
|
* manager are created per plugin instance.
|
|
270
276
|
*
|
|
271
277
|
* Auth-token resolution order for the auth-gated reads:
|
|
272
|
-
* 1.
|
|
273
|
-
* 2. Constructor `authToken` (string or async factory)
|
|
274
|
-
* 3. Persisted long-lived read-only token, keyed on the resolved Lighter
|
|
278
|
+
* 1. Persisted long-lived read-only token, keyed on the resolved Lighter
|
|
275
279
|
* `accountIndex`
|
|
276
|
-
*
|
|
280
|
+
* 2. Fresh 1h create via this instance's WASM signer + the user's registered
|
|
277
281
|
* API key
|
|
278
282
|
*
|
|
279
283
|
* Status reads report the account's state and do not throw for a missing
|
|
@@ -287,9 +291,9 @@ interface ReadOnlyCreationBackoff {
|
|
|
287
291
|
* - `SetupRequired` when none of these sources yields a token. The SDK
|
|
288
292
|
* sends no venue request. `getOrders`, `getOrder`, `getFills`,
|
|
289
293
|
* `getPortfolioHistory` and `getActivity` need a token.
|
|
290
|
-
* - `Unauthorized` when Lighter rejects the token that was sent.
|
|
291
|
-
*
|
|
292
|
-
*
|
|
294
|
+
* - `Unauthorized` when Lighter rejects the token that was sent. A
|
|
295
|
+
* read-only token that Lighter reports as revoked is replaced and the
|
|
296
|
+
* read retried once first.
|
|
293
297
|
* - `AccountNotFound` when the wallet has no Lighter account. This also
|
|
294
298
|
* applies to `getPositions`, `getWithdrawableBalances` and
|
|
295
299
|
* `getAvailableToTrade`, which need no token. `getAvailableToTrade`
|
|
@@ -312,8 +316,6 @@ export interface LighterProviderOptions {
|
|
|
312
316
|
* instance's signer and read-only token manager follow this URL.
|
|
313
317
|
*/
|
|
314
318
|
restUrl?: string
|
|
315
|
-
/** Pre-created Lighter read-only bearer, bypassing SDK token resolution. */
|
|
316
|
-
authToken?: string | (() => string | Promise<string>)
|
|
317
319
|
/** Token lifetime for on-demand standard-token creates (Lighter caps at 8h). Default 1h. */
|
|
318
320
|
tokenLifetimeSeconds?: number
|
|
319
321
|
/** Re-create when the cached standard token's remaining life is below this. Default 60s. */
|
|
@@ -344,8 +346,8 @@ interface CachedStandardToken {
|
|
|
344
346
|
export interface LighterPerpsProvider extends PerpsProviderPlugin {
|
|
345
347
|
/**
|
|
346
348
|
* Resolve a Lighter auth token for `address`, following the resolution order
|
|
347
|
-
* documented on {@link LighterProviderOptions}
|
|
348
|
-
*
|
|
349
|
+
* documented on {@link LighterProviderOptions}. Returns `undefined` when no
|
|
350
|
+
* source can produce a token.
|
|
349
351
|
*/
|
|
350
352
|
resolveAuthToken(address: Address): Promise<string | undefined>
|
|
351
353
|
}
|
|
@@ -381,12 +383,6 @@ export const createLighterProvider = (
|
|
|
381
383
|
const explorerTxBaseUrl = deployment.explorerTxBaseUrl
|
|
382
384
|
const bridgeChainId = deployment.bridgeChainId
|
|
383
385
|
const collateral = deployment.collateral
|
|
384
|
-
const authTokenSource: (() => string | Promise<string>) | undefined =
|
|
385
|
-
typeof options.authToken === 'function'
|
|
386
|
-
? options.authToken
|
|
387
|
-
: options.authToken !== undefined
|
|
388
|
-
? () => options.authToken as string
|
|
389
|
-
: undefined
|
|
390
386
|
const storage = options.storage ?? localStorageAdapter
|
|
391
387
|
const signer = new LighterSigner({
|
|
392
388
|
apiUrl: restUrl,
|
|
@@ -460,32 +456,20 @@ export const createLighterProvider = (
|
|
|
460
456
|
|
|
461
457
|
/**
|
|
462
458
|
* Resolve the bearer token for auth-gated reads. Priority:
|
|
463
|
-
* 1.
|
|
464
|
-
* 2. Constructor-supplied token source.
|
|
465
|
-
* 3. A stored read-only token — preferred for reads: it is read-only, so
|
|
459
|
+
* 1. A stored read-only token — preferred for reads: it is read-only, so
|
|
466
460
|
* forwarding it (incl. to the backend) cannot authorise writes.
|
|
467
|
-
*
|
|
461
|
+
* 2. A read-only token created on first use (via signer + registered API
|
|
468
462
|
* key) and persisted for reuse.
|
|
469
|
-
*
|
|
463
|
+
* 3. A standard auth token (read+write, 8h max) as a last resort — used
|
|
470
464
|
* as the credential that authorises read-only token creation, and as
|
|
471
465
|
* the fallback while creation is failing, bounded by the
|
|
472
466
|
* creation-retry backoff.
|
|
473
467
|
* Returns `undefined` when no source can produce a token.
|
|
474
468
|
*/
|
|
475
469
|
const resolveAuthToken = async (
|
|
476
|
-
|
|
477
|
-
address?: Address,
|
|
470
|
+
address: Address,
|
|
478
471
|
knownApiKey?: LighterApiKey
|
|
479
472
|
): Promise<string | undefined> => {
|
|
480
|
-
if (opts?.lighterAuthToken !== undefined) {
|
|
481
|
-
return opts.lighterAuthToken
|
|
482
|
-
}
|
|
483
|
-
if (authTokenSource !== undefined) {
|
|
484
|
-
return authTokenSource()
|
|
485
|
-
}
|
|
486
|
-
if (address === undefined) {
|
|
487
|
-
return undefined
|
|
488
|
-
}
|
|
489
473
|
const apiKey = knownApiKey ?? (await keyStore.get(address))
|
|
490
474
|
if (apiKey === null) {
|
|
491
475
|
return undefined
|
|
@@ -567,17 +551,15 @@ export const createLighterProvider = (
|
|
|
567
551
|
/** {@link resolveAuthToken}, throwing `SetupRequired` when no source yields a token. */
|
|
568
552
|
const requireAuthToken = async (
|
|
569
553
|
read: string,
|
|
570
|
-
opts: SDKRequestOptions | undefined,
|
|
571
554
|
address: Address,
|
|
572
555
|
knownApiKey?: LighterApiKey
|
|
573
556
|
): Promise<string> => {
|
|
574
|
-
const token = await resolveAuthToken(
|
|
557
|
+
const token = await resolveAuthToken(address, knownApiKey)
|
|
575
558
|
if (token === undefined) {
|
|
576
559
|
throw new PerpsError(
|
|
577
560
|
PerpsErrorCode.SetupRequired,
|
|
578
|
-
`Lighter ${read} requires an auth token.
|
|
579
|
-
'
|
|
580
|
-
'forward `options.lighterAuthToken` on the call.'
|
|
561
|
+
`Lighter ${read} requires an auth token. Register an API key + signer ` +
|
|
562
|
+
'for on-demand creation.'
|
|
581
563
|
)
|
|
582
564
|
}
|
|
583
565
|
return token
|
|
@@ -638,7 +620,6 @@ export const createLighterProvider = (
|
|
|
638
620
|
}
|
|
639
621
|
|
|
640
622
|
const retryOnRevoked = async <T>(
|
|
641
|
-
opts: SDKRequestOptions | undefined,
|
|
642
623
|
address: Address,
|
|
643
624
|
token: string,
|
|
644
625
|
run: (token: string) => Promise<T>
|
|
@@ -646,9 +627,7 @@ export const createLighterProvider = (
|
|
|
646
627
|
try {
|
|
647
628
|
return await run(token)
|
|
648
629
|
} catch (err) {
|
|
649
|
-
|
|
650
|
-
opts?.lighterAuthToken === undefined && authTokenSource === undefined
|
|
651
|
-
if (!(err instanceof LighterTokenRevokedError) || !sdkOwnsToken) {
|
|
630
|
+
if (!(err instanceof LighterTokenRevokedError)) {
|
|
652
631
|
throw err
|
|
653
632
|
}
|
|
654
633
|
const fresh = await replaceRevokedReadOnlyToken(address, token)
|
|
@@ -879,6 +858,20 @@ export const createLighterProvider = (
|
|
|
879
858
|
return setup.find((descriptor) => descriptor.type === action)
|
|
880
859
|
}
|
|
881
860
|
|
|
861
|
+
/**
|
|
862
|
+
* Refuse a SEND_ASSET for a unified account. Its settlement asset is one pool
|
|
863
|
+
* across both routes, so a perps↔spot transfer has nothing to move.
|
|
864
|
+
*/
|
|
865
|
+
const assertSendAssetMode = async (address: Address): Promise<void> => {
|
|
866
|
+
const account = await fetchDetailedAccount(apiClient(), address)
|
|
867
|
+
if (account.account_trading_mode === LT_ACCOUNT_TRADING_MODE_UNIFIED) {
|
|
868
|
+
throw new PerpsError(
|
|
869
|
+
PerpsErrorCode.PooledCategoryTransfer,
|
|
870
|
+
'Lighter unified accounts pool the settlement asset across perps and spot; a transfer between them has nothing to move'
|
|
871
|
+
)
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
882
875
|
/**
|
|
883
876
|
* Refuse an order signature for a tier no ACCOUNT_TYPE option binds. An
|
|
884
877
|
* unreadable descriptor or tier fails open: the venue itself
|
|
@@ -908,11 +901,11 @@ export const createLighterProvider = (
|
|
|
908
901
|
}
|
|
909
902
|
let userTierName: string | undefined
|
|
910
903
|
try {
|
|
911
|
-
const token = await resolveAuthToken(
|
|
904
|
+
const token = await resolveAuthToken(address, localKey)
|
|
912
905
|
const limits =
|
|
913
906
|
token === undefined
|
|
914
907
|
? undefined
|
|
915
|
-
: await retryOnRevoked(
|
|
908
|
+
: await retryOnRevoked(address, token, (resolvedToken) =>
|
|
916
909
|
fetchAccountLimits(
|
|
917
910
|
apiClient(),
|
|
918
911
|
localKey.accountIndex,
|
|
@@ -951,7 +944,7 @@ export const createLighterProvider = (
|
|
|
951
944
|
},
|
|
952
945
|
|
|
953
946
|
resolveAuthToken(address: Address): Promise<string | undefined> {
|
|
954
|
-
return resolveAuthToken(
|
|
947
|
+
return resolveAuthToken(address)
|
|
955
948
|
},
|
|
956
949
|
|
|
957
950
|
async getAccount(
|
|
@@ -981,7 +974,7 @@ export const createLighterProvider = (
|
|
|
981
974
|
normalizeLighterPublicKey(registeredKey.public_key)
|
|
982
975
|
// Status read: a missing or stale credential reports `apiKeyRegistered: false`, not a throw.
|
|
983
976
|
const token = apiKeyRegistered
|
|
984
|
-
? await resolveAuthToken(
|
|
977
|
+
? await resolveAuthToken(params.address, localKey)
|
|
985
978
|
: undefined
|
|
986
979
|
|
|
987
980
|
const registry = getMarketRegistry(requireClient(), providerKey)
|
|
@@ -994,7 +987,7 @@ export const createLighterProvider = (
|
|
|
994
987
|
getMarketsContext(requireClient(), { provider: providerKey }, opts),
|
|
995
988
|
token === undefined
|
|
996
989
|
? Promise.resolve(undefined)
|
|
997
|
-
: retryOnRevoked(
|
|
990
|
+
: retryOnRevoked(params.address, token, (resolvedToken) =>
|
|
998
991
|
fetchAccountLimits(client, account.index, resolvedToken)
|
|
999
992
|
),
|
|
1000
993
|
apiKeyRegistered
|
|
@@ -1024,12 +1017,21 @@ export const createLighterProvider = (
|
|
|
1024
1017
|
)
|
|
1025
1018
|
// Each asset has a spot route (`balance`) and a perps route
|
|
1026
1019
|
// (`margin_balance`). The instance's settlement asset is valued 1:1; an
|
|
1027
|
-
// asset no spot market prices keeps a zero USD value.
|
|
1020
|
+
// asset no spot market prices keeps a zero USD value. A unified account
|
|
1021
|
+
// pools both settlement routes into one spot row.
|
|
1022
|
+
const isPooled = (asset: LtAccountAsset): boolean =>
|
|
1023
|
+
account.account_trading_mode === LT_ACCOUNT_TRADING_MODE_UNIFIED &&
|
|
1024
|
+
asset.asset_id === collateral.assetIndex
|
|
1028
1025
|
const heldAssets = account.assets.filter((asset) =>
|
|
1029
|
-
|
|
1026
|
+
(isPooled(asset)
|
|
1027
|
+
? pooledSettlementUnits(asset)
|
|
1028
|
+
: toRequiredBig(asset.balance, 'balance')
|
|
1029
|
+
).gt(0)
|
|
1030
1030
|
)
|
|
1031
|
-
const marginAssets = account.assets.filter(
|
|
1032
|
-
|
|
1031
|
+
const marginAssets = account.assets.filter(
|
|
1032
|
+
(asset) =>
|
|
1033
|
+
!isPooled(asset) &&
|
|
1034
|
+
toRequiredBig(asset.margin_balance, 'margin_balance').gt(0)
|
|
1033
1035
|
)
|
|
1034
1036
|
const spotPrices = spotPriceByAssetId(
|
|
1035
1037
|
registry.markets,
|
|
@@ -1094,6 +1096,16 @@ export const createLighterProvider = (
|
|
|
1094
1096
|
}
|
|
1095
1097
|
})
|
|
1096
1098
|
const balances: Balance[] = heldAssets.map((a) => {
|
|
1099
|
+
if (isPooled(a)) {
|
|
1100
|
+
const units = pooledSettlementUnits(a).toFixed()
|
|
1101
|
+
return {
|
|
1102
|
+
...toBalance(a, LIGHTER_SPOT_CATEGORY_ID, registryAsset(a), units),
|
|
1103
|
+
transferable: calculateTransferable(
|
|
1104
|
+
pooledSettlementSpendable(a, availableBalance).toFixed(),
|
|
1105
|
+
units
|
|
1106
|
+
),
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1097
1109
|
const balance = toRequiredBig(a.balance, 'balance')
|
|
1098
1110
|
return {
|
|
1099
1111
|
...toBalance(
|
|
@@ -1132,6 +1144,10 @@ export const createLighterProvider = (
|
|
|
1132
1144
|
crossAssetValue: account.cross_asset_value,
|
|
1133
1145
|
crossInitialMarginRequirement: account.cross_initial_margin_requirement,
|
|
1134
1146
|
totalAssetValue: account.total_asset_value,
|
|
1147
|
+
collateralSpotBalance: collateralSpotBalance(
|
|
1148
|
+
account.assets,
|
|
1149
|
+
collateral.assetIndex
|
|
1150
|
+
),
|
|
1135
1151
|
userTierName: limitsResult?.user_tier_name,
|
|
1136
1152
|
accountTradingMode:
|
|
1137
1153
|
account.account_trading_mode ?? LT_ACCOUNT_TRADING_MODE_SIMPLE,
|
|
@@ -1305,7 +1321,7 @@ export const createLighterProvider = (
|
|
|
1305
1321
|
if (statuses.size === 0) {
|
|
1306
1322
|
return empty
|
|
1307
1323
|
}
|
|
1308
|
-
const token = await requireAuthToken('orders read',
|
|
1324
|
+
const token = await requireAuthToken('orders read', params.address)
|
|
1309
1325
|
|
|
1310
1326
|
const client = apiClient(opts)
|
|
1311
1327
|
const registry = getMarketRegistry(requireClient(), providerKey)
|
|
@@ -1327,7 +1343,6 @@ export const createLighterProvider = (
|
|
|
1327
1343
|
}
|
|
1328
1344
|
}
|
|
1329
1345
|
const [activeResponse, inactiveResponse] = await retryOnRevoked(
|
|
1330
|
-
opts,
|
|
1331
1346
|
params.address,
|
|
1332
1347
|
token,
|
|
1333
1348
|
(t) =>
|
|
@@ -1394,7 +1409,7 @@ export const createLighterProvider = (
|
|
|
1394
1409
|
params: ProviderGetOrderParams,
|
|
1395
1410
|
opts?: SDKRequestOptions
|
|
1396
1411
|
): Promise<Order> {
|
|
1397
|
-
const token = await requireAuthToken('order lookup',
|
|
1412
|
+
const token = await requireAuthToken('order lookup', params.address)
|
|
1398
1413
|
|
|
1399
1414
|
const client = apiClient(opts)
|
|
1400
1415
|
const registry = getMarketRegistry(requireClient(), providerKey)
|
|
@@ -1437,7 +1452,7 @@ export const createLighterProvider = (
|
|
|
1437
1452
|
`"${clientOrderIndex}" is not a decimal integer.`
|
|
1438
1453
|
)
|
|
1439
1454
|
}
|
|
1440
|
-
const orders = await retryOnRevoked(
|
|
1455
|
+
const orders = await retryOnRevoked(params.address, token, (t) =>
|
|
1441
1456
|
fetchOrdersByClientOrderIndex(
|
|
1442
1457
|
client,
|
|
1443
1458
|
t,
|
|
@@ -1461,7 +1476,7 @@ export const createLighterProvider = (
|
|
|
1461
1476
|
const byOrderIndex = (o: LtOrder): boolean =>
|
|
1462
1477
|
String(o.order_index) === params.id
|
|
1463
1478
|
|
|
1464
|
-
const active = await retryOnRevoked(
|
|
1479
|
+
const active = await retryOnRevoked(params.address, token, (t) =>
|
|
1465
1480
|
fetchActiveOrders(
|
|
1466
1481
|
client,
|
|
1467
1482
|
t,
|
|
@@ -1474,7 +1489,7 @@ export const createLighterProvider = (
|
|
|
1474
1489
|
return detail(activeHit)
|
|
1475
1490
|
}
|
|
1476
1491
|
|
|
1477
|
-
const inactive = await retryOnRevoked(
|
|
1492
|
+
const inactive = await retryOnRevoked(params.address, token, (t) =>
|
|
1478
1493
|
client.getAuthed<LtOrdersResponse>('/api/v1/accountInactiveOrders', t, {
|
|
1479
1494
|
account_index: account.index,
|
|
1480
1495
|
market_id: LIGHTER_ALL_MARKETS_WILDCARD,
|
|
@@ -1492,7 +1507,7 @@ export const createLighterProvider = (
|
|
|
1492
1507
|
params: ProviderGetFillsParams,
|
|
1493
1508
|
opts?: SDKRequestOptions
|
|
1494
1509
|
): Promise<FillsResponse> {
|
|
1495
|
-
const token = await requireAuthToken('fills read',
|
|
1510
|
+
const token = await requireAuthToken('fills read', params.address)
|
|
1496
1511
|
|
|
1497
1512
|
const client = apiClient(opts)
|
|
1498
1513
|
const registry = getMarketRegistry(requireClient(), providerKey)
|
|
@@ -1511,12 +1526,8 @@ export const createLighterProvider = (
|
|
|
1511
1526
|
queryParams.cursor = params.cursor
|
|
1512
1527
|
}
|
|
1513
1528
|
|
|
1514
|
-
const response = await retryOnRevoked(
|
|
1515
|
-
|
|
1516
|
-
params.address,
|
|
1517
|
-
token,
|
|
1518
|
-
(tok) =>
|
|
1519
|
-
client.getAuthed<LtTradesResponse>('/api/v1/trades', tok, queryParams)
|
|
1529
|
+
const response = await retryOnRevoked(params.address, token, (tok) =>
|
|
1530
|
+
client.getAuthed<LtTradesResponse>('/api/v1/trades', tok, queryParams)
|
|
1520
1531
|
)
|
|
1521
1532
|
|
|
1522
1533
|
// `get`, not `require`: a market id the backend list no longer carries
|
|
@@ -1546,12 +1557,9 @@ export const createLighterProvider = (
|
|
|
1546
1557
|
params: ProviderGetPortfolioHistoryParams,
|
|
1547
1558
|
opts?: SDKRequestOptions
|
|
1548
1559
|
): Promise<PortfolioHistoryResponse> {
|
|
1549
|
-
const
|
|
1550
|
-
opts?.lighterAuthToken === undefined && authTokenSource === undefined
|
|
1551
|
-
const apiKey = sdkOwnsToken ? await keyStore.get(params.address) : null
|
|
1560
|
+
const apiKey = await keyStore.get(params.address)
|
|
1552
1561
|
const token = await requireAuthToken(
|
|
1553
1562
|
'portfolio history read',
|
|
1554
|
-
opts,
|
|
1555
1563
|
params.address,
|
|
1556
1564
|
apiKey ?? undefined
|
|
1557
1565
|
)
|
|
@@ -1580,23 +1588,24 @@ export const createLighterProvider = (
|
|
|
1580
1588
|
// fallback sits outside `retryOnRevoked`, so a revocation the standard
|
|
1581
1589
|
// token reports never replaces the read-only one. The key is re-read at
|
|
1582
1590
|
// retry time because `REGISTER_API_KEY` can rotate it.
|
|
1583
|
-
const response = await retryOnRevoked(
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
+
const response = await retryOnRevoked(params.address, token, read).catch(
|
|
1592
|
+
async (err: unknown) => {
|
|
1593
|
+
if (!(err instanceof LighterAuthRejectedError) || apiKey === null) {
|
|
1594
|
+
throw err
|
|
1595
|
+
}
|
|
1596
|
+
const current = (await keyStore.get(params.address)) ?? apiKey
|
|
1597
|
+
return read(
|
|
1598
|
+
await getStandardAuthToken(
|
|
1599
|
+
params.address,
|
|
1600
|
+
current.apiKeyPrivateKey,
|
|
1601
|
+
{
|
|
1602
|
+
apiKeyIndex: current.apiKeyIndex,
|
|
1603
|
+
accountIndex: current.accountIndex,
|
|
1604
|
+
}
|
|
1605
|
+
)
|
|
1606
|
+
)
|
|
1591
1607
|
}
|
|
1592
|
-
|
|
1593
|
-
return read(
|
|
1594
|
-
await getStandardAuthToken(params.address, current.apiKeyPrivateKey, {
|
|
1595
|
-
apiKeyIndex: current.apiKeyIndex,
|
|
1596
|
-
accountIndex: current.accountIndex,
|
|
1597
|
-
})
|
|
1598
|
-
)
|
|
1599
|
-
})
|
|
1608
|
+
)
|
|
1600
1609
|
|
|
1601
1610
|
return mapPortfolioHistory(
|
|
1602
1611
|
params.range,
|
|
@@ -1609,11 +1618,7 @@ export const createLighterProvider = (
|
|
|
1609
1618
|
params: ProviderGetActivityParams,
|
|
1610
1619
|
opts?: SDKRequestOptions
|
|
1611
1620
|
): Promise<ActivitiesResponse> {
|
|
1612
|
-
const token = await requireAuthToken(
|
|
1613
|
-
'activity read',
|
|
1614
|
-
opts,
|
|
1615
|
-
params.address
|
|
1616
|
-
)
|
|
1621
|
+
const token = await requireAuthToken('activity read', params.address)
|
|
1617
1622
|
|
|
1618
1623
|
const inputCursor = decodeActivityCursor(params.cursor)
|
|
1619
1624
|
const client = apiClient(opts)
|
|
@@ -1623,7 +1628,7 @@ export const createLighterProvider = (
|
|
|
1623
1628
|
// Markets identify funding and liquidation rows; assets identify ledger
|
|
1624
1629
|
// rows. A request for one surface must not pull the other's registry.
|
|
1625
1630
|
const [history] = await Promise.all([
|
|
1626
|
-
retryOnRevoked(
|
|
1631
|
+
retryOnRevoked(params.address, token, (t) =>
|
|
1627
1632
|
fetchAllHistory(
|
|
1628
1633
|
client,
|
|
1629
1634
|
t,
|
|
@@ -1875,6 +1880,9 @@ export const createLighterProvider = (
|
|
|
1875
1880
|
if (steps.some((step) => ORDER_PLACEMENT_ACTIONS.has(step.action))) {
|
|
1876
1881
|
await assertOrderTier(address)
|
|
1877
1882
|
}
|
|
1883
|
+
if (steps.some((step) => step.action === ActionType.SEND_ASSET)) {
|
|
1884
|
+
await assertSendAssetMode(address)
|
|
1885
|
+
}
|
|
1878
1886
|
return lighterSignActions(
|
|
1879
1887
|
{
|
|
1880
1888
|
signer,
|