@lifi/perps-sdk-provider-lighter 17.1.0 → 17.2.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.
Files changed (62) hide show
  1. package/dist/cjs/LighterProvider.d.ts.map +1 -1
  2. package/dist/cjs/LighterProvider.js +1 -0
  3. package/dist/cjs/LighterProvider.js.map +1 -1
  4. package/dist/cjs/accountConfig.d.ts.map +1 -1
  5. package/dist/cjs/accountConfig.js +11 -4
  6. package/dist/cjs/accountConfig.js.map +1 -1
  7. package/dist/cjs/constants.d.ts +1 -0
  8. package/dist/cjs/constants.d.ts.map +1 -1
  9. package/dist/cjs/constants.js +2 -1
  10. package/dist/cjs/constants.js.map +1 -1
  11. package/dist/cjs/signers/LighterKeyStore.d.ts +2 -1
  12. package/dist/cjs/signers/LighterKeyStore.d.ts.map +1 -1
  13. package/dist/cjs/signers/LighterKeyStore.js +8 -6
  14. package/dist/cjs/signers/LighterKeyStore.js.map +1 -1
  15. package/dist/cjs/signers/signActions.d.ts.map +1 -1
  16. package/dist/cjs/signers/signActions.js +9 -5
  17. package/dist/cjs/signers/signActions.js.map +1 -1
  18. package/dist/cjs/types/fill.d.ts +2 -0
  19. package/dist/cjs/types/fill.d.ts.map +1 -1
  20. package/dist/cjs/utils/mapFill.d.ts.map +1 -1
  21. package/dist/cjs/utils/mapFill.js +8 -0
  22. package/dist/cjs/utils/mapFill.js.map +1 -1
  23. package/dist/esm/LighterProvider.d.ts.map +1 -1
  24. package/dist/esm/LighterProvider.js +1 -0
  25. package/dist/esm/LighterProvider.js.map +1 -1
  26. package/dist/esm/accountConfig.d.ts.map +1 -1
  27. package/dist/esm/accountConfig.js +28 -16
  28. package/dist/esm/accountConfig.js.map +1 -1
  29. package/dist/esm/constants.d.ts +9 -0
  30. package/dist/esm/constants.d.ts.map +1 -1
  31. package/dist/esm/constants.js +9 -0
  32. package/dist/esm/constants.js.map +1 -1
  33. package/dist/esm/signers/LighterKeyStore.d.ts +12 -4
  34. package/dist/esm/signers/LighterKeyStore.d.ts.map +1 -1
  35. package/dist/esm/signers/LighterKeyStore.js +16 -15
  36. package/dist/esm/signers/LighterKeyStore.js.map +1 -1
  37. package/dist/esm/signers/signActions.d.ts.map +1 -1
  38. package/dist/esm/signers/signActions.js +15 -9
  39. package/dist/esm/signers/signActions.js.map +1 -1
  40. package/dist/esm/types/fill.d.ts +2 -0
  41. package/dist/esm/types/fill.d.ts.map +1 -1
  42. package/dist/esm/utils/mapFill.d.ts.map +1 -1
  43. package/dist/esm/utils/mapFill.js +16 -1
  44. package/dist/esm/utils/mapFill.js.map +1 -1
  45. package/dist/types/LighterProvider.d.ts.map +1 -1
  46. package/dist/types/accountConfig.d.ts.map +1 -1
  47. package/dist/types/constants.d.ts +9 -0
  48. package/dist/types/constants.d.ts.map +1 -1
  49. package/dist/types/signers/LighterKeyStore.d.ts +12 -4
  50. package/dist/types/signers/LighterKeyStore.d.ts.map +1 -1
  51. package/dist/types/signers/signActions.d.ts.map +1 -1
  52. package/dist/types/types/fill.d.ts +2 -0
  53. package/dist/types/types/fill.d.ts.map +1 -1
  54. package/dist/types/utils/mapFill.d.ts.map +1 -1
  55. package/package.json +3 -3
  56. package/src/LighterProvider.ts +1 -0
  57. package/src/accountConfig.ts +32 -16
  58. package/src/constants.ts +10 -0
  59. package/src/signers/LighterKeyStore.ts +50 -29
  60. package/src/signers/signActions.ts +18 -11
  61. package/src/types/fill.ts +6 -0
  62. package/src/utils/mapFill.ts +21 -1
@@ -1,7 +1,8 @@
1
1
  import { classifyFillFromPosition, ExplorerChainId, explorerTxUrl, } from '@lifi/perps-sdk';
2
2
  import { FillStatus, LiquidityRole, OrderSide, OrderType, } from '@lifi/perps-types';
3
3
  import Big from 'big.js';
4
- import { LIGHTER_FEE_TICK_SCALE } from '../constants.js';
4
+ import { LIGHTER_FEE_TICK_SCALE, LIGHTER_IMF_PERCENT_SCALE, } from '../constants.js';
5
+ import { leverageFromImf } from './mapPosition.js';
5
6
  /**
6
7
  * Fee charged on a fill, in the market's quote asset. Lighter publishes the
7
8
  * side's fee *rate* as an integer tick on `LIGHTER_FEE_TICK_SCALE` rather than
@@ -17,6 +18,16 @@ const tickToFeeAmount = (notional, ownTick, integratorTick) => new Big(notional)
17
18
  .times(new Big(ownTick).plus(integratorTick ?? 0))
18
19
  .div(LIGHTER_FEE_TICK_SCALE)
19
20
  .toFixed();
21
+ /**
22
+ * Display leverage the viewer had set on the market when the trade executed.
23
+ * Lighter reports it as the pre-trade initial margin fraction, an integer
24
+ * percent on `LIGHTER_IMF_PERCENT_SCALE`: `500` is 5.00%, so 20x. Returns
25
+ * `undefined` when the row omits the fraction. Lighter declares the fraction a
26
+ * `StrictInt`, so the scale division is exact and `toFixed()` loses nothing.
27
+ */
28
+ const leverageFromTradeImf = (imf) => imf === undefined
29
+ ? undefined
30
+ : leverageFromImf(new Big(imf).div(LIGHTER_IMF_PERCENT_SCALE).toFixed());
20
31
  /**
21
32
  * Realized PnL on a position-reducing fill, derived from the pre-trade entry
22
33
  * basis. Returns `undefined` for opens/increases (nothing closes) or when the
@@ -69,6 +80,9 @@ export const mapFill = (trade, accountIndex, market) => {
69
80
  const integratorFeeTick = isMaker
70
81
  ? trade.integrator_maker_fee
71
82
  : trade.integrator_taker_fee;
83
+ const imfBefore = isMaker
84
+ ? trade.maker_initial_margin_fraction_before
85
+ : trade.taker_initial_margin_fraction_before;
72
86
  return {
73
87
  id: trade.trade_id.toString(),
74
88
  orderId: String(isBuyer ? trade.bid_id : trade.ask_id),
@@ -86,6 +100,7 @@ export const mapFill = (trade, accountIndex, market) => {
86
100
  amount: tickToFeeAmount(trade.usd_amount, feeTick, integratorFeeTick),
87
101
  asset: market.quoteAsset.displaySymbol,
88
102
  },
103
+ leverage: leverageFromTradeImf(imfBefore),
89
104
  realizedPnl: deriveRealizedPnl(startPosition, entryQuoteBefore, trade.size, trade.price, isBuyer),
90
105
  startPosition,
91
106
  // `classifyFillFromPosition` takes an HL-encoded side: `'B'`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AAgK1B;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,oBAAoB,EAC5B,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,EAAE,cAAc,EAAE,GACxB,oBAAoB,EAAE,CAIxB"}
1
+ {"version":3,"file":"accountConfig.d.ts","sourceRoot":"","sources":["../../src/accountConfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACf,MAAM,mBAAmB,CAAA;AAgL1B;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,oBAAoB,EAC5B,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,EAAE,cAAc,EAAE,GACxB,oBAAoB,EAAE,CAIxB"}
@@ -139,6 +139,15 @@ export declare const DEFAULT_TRADES_LIMIT = 50;
139
139
  * @internal
140
140
  */
141
141
  export declare const LIGHTER_FEE_TICK_SCALE = 1000000;
142
+ /**
143
+ * Scale of the integer `initial_margin_fraction` values Lighter publishes on
144
+ * trade rows and order-book details: the integer is a percent times 100, so
145
+ * `500` is 5.00% and `200` is 2.00%. Account positions publish the same
146
+ * fraction as a plain percent string ("5.00") instead.
147
+ *
148
+ * @internal
149
+ */
150
+ export declare const LIGHTER_IMF_PERCENT_SCALE = 100;
142
151
  /**
143
152
  * Lighter's public base fee tier (Standard Account): 0% maker / 0% taker on all
144
153
  * perps markets. Per-account Premium tiers exist but require auth to resolve;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,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;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,SAAS,CAA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interface LighterApiKey {
12
+ /**
13
+ * Lighter instance the record belongs to. A record read by any other
14
+ * instance is discarded, so its key material never signs on a chain that
15
+ * does not hold it.
16
+ */
17
+ providerKey: LighterProviderKey;
12
18
  /** Lighter account index, looked up once via accountsByL1Address. */
13
19
  accountIndex: number;
14
20
  /** API key slot (0-255), as named by the backend registration payload. */
@@ -20,8 +26,9 @@ export interface LighterApiKey {
20
26
  }
21
27
  /**
22
28
  * Storage-backed cache for Lighter API keys. Records are namespaced by L1
23
- * address and provider instance so multiple Lighter deployments can share one
24
- * {@link StorageAdapter} without collisions.
29
+ * address and provider instance, and each record names its own instance, so
30
+ * multiple Lighter deployments can share one {@link StorageAdapter} and no
31
+ * instance ever reads another instance's key material.
25
32
  *
26
33
  * @public
27
34
  */
@@ -50,9 +57,10 @@ export declare class LighterKeyStore {
50
57
  get(address: Address): Promise<LighterApiKey | null>;
51
58
  /**
52
59
  * Persist an API key for an L1 address, replacing any existing record under
53
- * that provider namespace.
60
+ * that provider namespace. The store stamps the record with its own instance
61
+ * key, so callers never name the instance themselves.
54
62
  */
55
- set(address: Address, value: LighterApiKey): Promise<void>;
63
+ set(address: Address, value: Omit<LighterApiKey, 'providerKey'>): Promise<void>;
56
64
  /**
57
65
  * Remove the persisted API key for an L1 address and clear its in-memory
58
66
  * cache entry.
@@ -1 +1 @@
1
- {"version":3,"file":"LighterKeyStore.d.ts","sourceRoot":"","sources":["../../../src/signers/LighterKeyStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAWnC;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAA;IACpB,0EAA0E;IAC1E,WAAW,EAAE,MAAM,CAAA;IACnB,oDAA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ACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,eAAe,EAAE,EACxB,GAAG,EAAE,kBAAkB,GAAG,SAAS,GAClC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CA6ElC;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,sBAAsB,EAC5B,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,UAAU,EAAE,EACnB,OAAO,EAAE,OAAO,EAChB,GAAG,CAAC,EAAE,kBAAkB,GACvB,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAsB7B"}
@@ -35,6 +35,8 @@ export type LtTrade = {
35
35
  maker_position_size_before: string;
36
36
  taker_entry_quote_before?: string;
37
37
  maker_entry_quote_before?: string;
38
+ taker_initial_margin_fraction_before?: number;
39
+ maker_initial_margin_fraction_before?: number;
38
40
  };
39
41
  /**
40
42
  * Paginated trade-history response from Lighter. `next_cursor` is an opaque
@@ -1 +1 @@
1
- {"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../../src/types/fill.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,OAAO,CAAA;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IAIjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAGlB,oBAAoB,CAAC,EAA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,wBAAwB,CAAC,EAAE,MAAM,CAAA;IAKjC,oCAAoC,CAAC,EAAE,MAAM,CAAA;IAC7C,oCAAoC,CAAC,EAAE,MAAM,CAAA;CAC9C,CAAA;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,OAAO,EAAE,CAAA;CAClB"}
@@ -1 +1 @@
1
- {"version":3,"file":"mapFill.d.ts","sourceRoot":"","sources":["../../../src/utils/mapFill.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAS5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AA8DhD;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAClB,OAAO,OAAO,EACd,cAAc,MAAM,EACpB,QAAQ,aAAa,KACpB,IA0DF,CAAA"}
1
+ {"version":3,"file":"mapFill.d.ts","sourceRoot":"","sources":["../../../src/utils/mapFill.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAY5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AA2EhD;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAClB,OAAO,OAAO,EACd,cAAc,MAAM,EACpB,QAAQ,aAAa,KACpB,IA8DF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/perps-sdk-provider-lighter",
3
- "version": "17.1.0",
3
+ "version": "17.2.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": "^11.2.0"
47
+ "@lifi/perps-types": "^11.3.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "@lifi/perps-sdk": "^10.0.1"
50
+ "@lifi/perps-sdk": "^10.0.2"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"
@@ -875,6 +875,7 @@ export const createLighterProvider = (
875
875
  apiKeyIndex: localKey?.apiKeyIndex,
876
876
  apiKeyRegistered,
877
877
  accountType: account.account_type,
878
+ userTierName: limitsResult?.user_tier_name,
878
879
  accountTradingMode: account.account_trading_mode,
879
880
  assetCollateral,
880
881
  // Satisfied when a non-expired read-only token is stored locally
@@ -12,16 +12,16 @@ function assertNever(value: never): never {
12
12
  )
13
13
  }
14
14
 
15
- /**
16
- * `account_type` on Lighter's `DetailedAccount` is a `StrictInt` with no
17
- * documented integer ↔ name mapping in the public SDKs. Empirical ordering:
18
- * 0 = standard, 1 = premium (from `AccountTier` enum + `/changeAccountTier`
19
- * wire strings). Plus tier (likely `2`) is omitted — an unmapped int projects
20
- * to null and surfaces as "tier not detected", so drift is observable.
21
- */
22
15
  const LIGHTER_ACCOUNT_TYPE_STANDARD = 0
23
16
  const LIGHTER_ACCOUNT_TYPE_PREMIUM = 1
24
17
 
18
+ /**
19
+ * Tier decode for the unauthenticated read, where `/accountLimits` — and with
20
+ * it the tier string — is out of reach. Neither official Lighter client
21
+ * documents an integer for any tier, so `0` (the `account_type` every sampled
22
+ * public account reports) reads as the default tier `standard`, and `1` as
23
+ * `premium`. No integer is known for `plus`: that account projects `null` here.
24
+ */
25
25
  const ACCOUNT_TYPE_INT_TO_WIRE: Readonly<Record<number, string>> = {
26
26
  [LIGHTER_ACCOUNT_TYPE_STANDARD]: 'standard',
27
27
  [LIGHTER_ACCOUNT_TYPE_PREMIUM]: 'premium',
@@ -38,6 +38,28 @@ const ACCOUNT_MODE_INT_TO_WIRE: Readonly<Record<number, string>> = {
38
38
  [LIGHTER_ACCOUNT_MODE_UNIFIED]: 'unifiedTradingAccount',
39
39
  }
40
40
 
41
+ /**
42
+ * Resolve the account tier to the wire string `changeAccountTier` accepts.
43
+ * `userTierName` decides it, but only when the descriptor enumerates the
44
+ * string: Lighter owns that vocabulary, so an unrecognised value projects
45
+ * `null` instead of a mis-reported tier. A descriptor whose parameter carries
46
+ * no `values` array enumerates nothing, so it also projects `null`. With no
47
+ * tier string in hand the integer map decides.
48
+ */
49
+ function resolveAccountTier(
50
+ descriptor: ProviderAction,
51
+ config: LighterAccountConfig
52
+ ): string | null {
53
+ const { userTierName } = config
54
+ if (userTierName === undefined) {
55
+ return ACCOUNT_TYPE_INT_TO_WIRE[config.accountType] ?? null
56
+ }
57
+ const enumerated = descriptor.params?.[0]?.values ?? []
58
+ return enumerated.some((option) => option.value === userTierName)
59
+ ? userTierName
60
+ : null
61
+ }
62
+
41
63
  /**
42
64
  * Project a single Lighter descriptor against the typed
43
65
  * `LighterAccountConfig` into an `AccountConfigSetting`.
@@ -51,7 +73,7 @@ const ACCOUNT_MODE_INT_TO_WIRE: Readonly<Record<number, string>> = {
51
73
  * | SET_REFERRAL | [] (no parameters)
52
74
  * | APPROVE_INTEGRATOR | [] (no parameters)
53
75
  * | ACCOUNT_MODE | [{ name: 'mode', value: config.accountTradingMode }]
54
- * | ACCOUNT_TYPE | [{ name: 'tier', value: config.accountType }]
76
+ * | ACCOUNT_TYPE | [{ name: 'tier', value: resolveAccountTier(…) }]
55
77
  *
56
78
  * The switch is exhaustive over `ActionType` so enum additions force a
57
79
  * compile error in the `default` arm. ActionTypes that are not valid on
@@ -113,19 +135,13 @@ function projectLighterDescriptor(
113
135
  ],
114
136
  }
115
137
 
116
- // `tier` is the wire string `/changeAccountTier` accepts; we decode the
117
- // raw integer `config.accountType` Lighter publishes via the mapping
118
- // above so the projection matches the descriptor's enumerated values.
119
- // Unrecognised integers project to `null` (surfaces as "tier not
138
+ // An unresolved `tier` projects to `null` (surfaces as "tier not
120
139
  // detected" — the widget still lets the user pick a value).
121
140
  case ActionType.ACCOUNT_TYPE:
122
141
  return {
123
142
  type: descriptor.type,
124
143
  values: [
125
- {
126
- name: 'tier',
127
- value: ACCOUNT_TYPE_INT_TO_WIRE[config.accountType] ?? null,
128
- },
144
+ { name: 'tier', value: resolveAccountTier(descriptor, config) },
129
145
  ],
130
146
  }
131
147
 
package/src/constants.ts CHANGED
@@ -183,6 +183,16 @@ export const DEFAULT_TRADES_LIMIT = 50
183
183
  */
184
184
  export const LIGHTER_FEE_TICK_SCALE = 1_000_000
185
185
 
186
+ /**
187
+ * Scale of the integer `initial_margin_fraction` values Lighter publishes on
188
+ * trade rows and order-book details: the integer is a percent times 100, so
189
+ * `500` is 5.00% and `200` is 2.00%. Account positions publish the same
190
+ * fraction as a plain percent string ("5.00") instead.
191
+ *
192
+ * @internal
193
+ */
194
+ export const LIGHTER_IMF_PERCENT_SCALE = 100
195
+
186
196
  /**
187
197
  * Lighter's public base fee tier (Standard Account): 0% maker / 0% taker on all
188
198
  * perps markets. Per-account Premium tiers exist but require auth to resolve;
@@ -4,10 +4,7 @@ import type { Address } from 'viem'
4
4
  import { LIGHTER_PROVIDER_KEY } from '../constants.js'
5
5
 
6
6
  // The private key here is a Lighter custom keypair — generated via WASM
7
- // GenerateAPIKey — not an Ethereum private key. The storage key is namespaced
8
- // by the resolved provider instance key so two Lighter instances sharing a
9
- // storage adapter (e.g. `lighter` and `lighter-rh`) never clobber each other's
10
- // API key.
7
+ // GenerateAPIKey — not an Ethereum private key.
11
8
 
12
9
  const STORAGE_PREFIX = 'lifi-perps-lighter-key'
13
10
 
@@ -19,6 +16,12 @@ const STORAGE_PREFIX = 'lifi-perps-lighter-key'
19
16
  * @public
20
17
  */
21
18
  export interface LighterApiKey {
19
+ /**
20
+ * Lighter instance the record belongs to. A record read by any other
21
+ * instance is discarded, so its key material never signs on a chain that
22
+ * does not hold it.
23
+ */
24
+ providerKey: LighterProviderKey
22
25
  /** Lighter account index, looked up once via accountsByL1Address. */
23
26
  accountIndex: number
24
27
  /** API key slot (0-255), as named by the backend registration payload. */
@@ -29,28 +32,37 @@ export interface LighterApiKey {
29
32
  apiKeyPublicKey: string
30
33
  }
31
34
 
32
- const isLighterApiKey = (value: unknown): value is LighterApiKey => {
33
- if (typeof value !== 'object' || value === null) {
34
- return false
35
+ const isLighterApiKeyOf =
36
+ (owner: LighterProviderKey) =>
37
+ (value: unknown): value is LighterApiKey => {
38
+ if (typeof value !== 'object' || value === null) {
39
+ return false
40
+ }
41
+ const {
42
+ providerKey,
43
+ accountIndex,
44
+ apiKeyIndex,
45
+ apiKeyPrivateKey,
46
+ apiKeyPublicKey,
47
+ } = value as Record<string, unknown>
48
+ return (
49
+ providerKey === owner &&
50
+ typeof accountIndex === 'number' &&
51
+ Number.isFinite(accountIndex) &&
52
+ typeof apiKeyIndex === 'number' &&
53
+ Number.isFinite(apiKeyIndex) &&
54
+ typeof apiKeyPrivateKey === 'string' &&
55
+ apiKeyPrivateKey.length > 0 &&
56
+ typeof apiKeyPublicKey === 'string' &&
57
+ apiKeyPublicKey.length > 0
58
+ )
35
59
  }
36
- const { accountIndex, apiKeyIndex, apiKeyPrivateKey, apiKeyPublicKey } =
37
- value as Record<string, unknown>
38
- return (
39
- typeof accountIndex === 'number' &&
40
- Number.isFinite(accountIndex) &&
41
- typeof apiKeyIndex === 'number' &&
42
- Number.isFinite(apiKeyIndex) &&
43
- typeof apiKeyPrivateKey === 'string' &&
44
- apiKeyPrivateKey.length > 0 &&
45
- typeof apiKeyPublicKey === 'string' &&
46
- apiKeyPublicKey.length > 0
47
- )
48
- }
49
60
 
50
61
  /**
51
62
  * 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.
63
+ * address and provider instance, and each record names its own instance, so
64
+ * multiple Lighter deployments can share one {@link StorageAdapter} and no
65
+ * instance ever reads another instance's key material.
54
66
  *
55
67
  * @public
56
68
  */
@@ -82,8 +94,8 @@ export class LighterKeyStore {
82
94
  this.providerKey = providerKey
83
95
  }
84
96
 
85
- // The default instance keeps the legacy, un-namespaced key so existing
86
- // `lighter` users are not orphaned; only additional instances get a segment.
97
+ // The default instance keeps the legacy, un-namespaced slot name; only
98
+ // additional instances get a segment.
87
99
  private storageKey(address: Address): string {
88
100
  const lower = address.toLowerCase()
89
101
  return this.providerKey === LIGHTER_PROVIDER_KEY
@@ -101,7 +113,11 @@ export class LighterKeyStore {
101
113
  if (cached) {
102
114
  return cached
103
115
  }
104
- const parsed = await readValidatedRecord(this.storage, key, isLighterApiKey)
116
+ const parsed = await readValidatedRecord(
117
+ this.storage,
118
+ key,
119
+ isLighterApiKeyOf(this.providerKey)
120
+ )
105
121
  if (!parsed) {
106
122
  return null
107
123
  }
@@ -111,12 +127,17 @@ export class LighterKeyStore {
111
127
 
112
128
  /**
113
129
  * Persist an API key for an L1 address, replacing any existing record under
114
- * that provider namespace.
130
+ * that provider namespace. The store stamps the record with its own instance
131
+ * key, so callers never name the instance themselves.
115
132
  */
116
- async set(address: Address, value: LighterApiKey): Promise<void> {
133
+ async set(
134
+ address: Address,
135
+ value: Omit<LighterApiKey, 'providerKey'>
136
+ ): Promise<void> {
117
137
  const key = this.storageKey(address)
118
- this.cache.set(key, value)
119
- await this.storage.set(key, JSON.stringify(value))
138
+ const record: LighterApiKey = { ...value, providerKey: this.providerKey }
139
+ this.cache.set(key, record)
140
+ await this.storage.set(key, JSON.stringify(record))
120
141
  }
121
142
 
122
143
  /**
@@ -64,7 +64,7 @@ export interface LighterSignActionsDeps {
64
64
  const TOKEN_AUTH_MUTATION_KINDS = new Set(['changeAccountTier', 'referralUse'])
65
65
 
66
66
  /**
67
- * Lifetime of the per-call auth token minted for a token-authenticated venue
67
+ * Lifetime of the per-call auth token issued for a token-authenticated venue
68
68
  * mutation. Minutes, not the read endpoints' hours: it authenticates one POST
69
69
  * that completes immediately, so it never lingers usable.
70
70
  */
@@ -133,11 +133,19 @@ export const createLighterApiKeyFreshness = (): LighterApiKeyFreshness => {
133
133
  checkedAtMs.set(windowKey, Date.now())
134
134
  return
135
135
  }
136
- // A slot carrying no entry leaves nothing to compare against.
137
- if (
138
- registered !== undefined &&
139
- normalizeLighterPublicKey(registered.public_key) !== storedKey
140
- ) {
136
+ // An answered read that names no entry is a verdict, not a gap: the slot
137
+ // holds no key the stored one can match, so a signature it produces
138
+ // cannot verify.
139
+ if (registered === undefined) {
140
+ throw new PerpsError(
141
+ PerpsErrorCode.SDKError,
142
+ `The Lighter API key stored for ${address} is not registered: ` +
143
+ `account ${apiKey.accountIndex} holds no key in API-key slot ` +
144
+ `${apiKey.apiKeyIndex}. Run prepareAccount / REGISTER_API_KEY to ` +
145
+ 'register a fresh key.'
146
+ )
147
+ }
148
+ if (normalizeLighterPublicKey(registered.public_key) !== storedKey) {
141
149
  throw new PerpsError(
142
150
  PerpsErrorCode.SDKError,
143
151
  `The Lighter API key stored for ${address} is no longer registered: ` +
@@ -146,7 +154,7 @@ export const createLighterApiKeyFreshness = (): LighterApiKeyFreshness => {
146
154
  )
147
155
  }
148
156
  // Every read the venue answered counts against the window, so a burst
149
- // costs one read whatever the verdict. A mismatch throws above, so it
157
+ // costs one read whatever the verdict. A rejection throws above, so it
150
158
  // never records and the next batch reads again.
151
159
  checkedAtMs.set(windowKey, Date.now())
152
160
  },
@@ -295,13 +303,12 @@ async function signRegisterApiKey(
295
303
  l1Signature
296
304
  )
297
305
 
298
- const apiKey: LighterApiKey = {
306
+ await deps.keyStore.set(address, {
299
307
  accountIndex,
300
308
  apiKeyIndex,
301
309
  apiKeyPrivateKey: keypair.privateKey,
302
310
  apiKeyPublicKey: keypair.publicKey,
303
- }
304
- await deps.keyStore.set(address, apiKey)
311
+ })
305
312
 
306
313
  return {
307
314
  action: step.action,
@@ -431,7 +438,7 @@ async function signTransfer(
431
438
  *
432
439
  * Neither endpoint consumes a wasm-signed transaction — both authenticate with
433
440
  * a Lighter auth token and enforce their business rules (open positions,
434
- * pending orders, 24h tier cooldown) server-side. We mint a fresh short-lived
441
+ * pending orders, 24h tier cooldown) server-side. We create a fresh short-lived
435
442
  * token per call (never the stored read-only token, never persisted) and POST
436
443
  * the mirror of the backend's form body directly to Lighter, so no auth token
437
444
  * ever transits the LI.FI backend. A non-success verdict surfaces Lighter's
package/src/types/fill.ts CHANGED
@@ -48,6 +48,12 @@ export type LtTrade = {
48
48
  // trade rows that predate the field.
49
49
  taker_entry_quote_before?: string
50
50
  maker_entry_quote_before?: string
51
+ // Per-counterparty initial-margin-fraction snapshot BEFORE the trade: the
52
+ // leverage that counterparty had set on the market, as an integer percent on
53
+ // `LIGHTER_IMF_PERCENT_SCALE` (`500` = 5.00% = 20x). Optional: absent on
54
+ // older trade rows that predate the field.
55
+ taker_initial_margin_fraction_before?: number
56
+ maker_initial_margin_fraction_before?: number
51
57
  }
52
58
 
53
59
  /**
@@ -11,8 +11,12 @@ import {
11
11
  OrderType,
12
12
  } from '@lifi/perps-types'
13
13
  import Big from 'big.js'
14
- import { LIGHTER_FEE_TICK_SCALE } from '../constants.js'
14
+ import {
15
+ LIGHTER_FEE_TICK_SCALE,
16
+ LIGHTER_IMF_PERCENT_SCALE,
17
+ } from '../constants.js'
15
18
  import type { LtTrade } from '../types/index.js'
19
+ import { leverageFromImf } from './mapPosition.js'
16
20
 
17
21
  /**
18
22
  * Fee charged on a fill, in the market's quote asset. Lighter publishes the
@@ -35,6 +39,18 @@ const tickToFeeAmount = (
35
39
  .div(LIGHTER_FEE_TICK_SCALE)
36
40
  .toFixed()
37
41
 
42
+ /**
43
+ * Display leverage the viewer had set on the market when the trade executed.
44
+ * Lighter reports it as the pre-trade initial margin fraction, an integer
45
+ * percent on `LIGHTER_IMF_PERCENT_SCALE`: `500` is 5.00%, so 20x. Returns
46
+ * `undefined` when the row omits the fraction. Lighter declares the fraction a
47
+ * `StrictInt`, so the scale division is exact and `toFixed()` loses nothing.
48
+ */
49
+ const leverageFromTradeImf = (imf: number | undefined): number | undefined =>
50
+ imf === undefined
51
+ ? undefined
52
+ : leverageFromImf(new Big(imf).div(LIGHTER_IMF_PERCENT_SCALE).toFixed())
53
+
38
54
  /**
39
55
  * Realized PnL on a position-reducing fill, derived from the pre-trade entry
40
56
  * basis. Returns `undefined` for opens/increases (nothing closes) or when the
@@ -101,6 +117,9 @@ export const mapFill = (
101
117
  const integratorFeeTick = isMaker
102
118
  ? trade.integrator_maker_fee
103
119
  : trade.integrator_taker_fee
120
+ const imfBefore = isMaker
121
+ ? trade.maker_initial_margin_fraction_before
122
+ : trade.taker_initial_margin_fraction_before
104
123
 
105
124
  return {
106
125
  id: trade.trade_id.toString(),
@@ -124,6 +143,7 @@ export const mapFill = (
124
143
  ),
125
144
  asset: market.quoteAsset.displaySymbol,
126
145
  },
146
+ leverage: leverageFromTradeImf(imfBefore),
127
147
  realizedPnl: deriveRealizedPnl(
128
148
  startPosition,
129
149
  entryQuoteBefore,