@lifi/perps-sdk-provider-lighter 8.2.1 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +14 -10
  2. package/dist/cjs/LighterProvider.d.ts +5 -10
  3. package/dist/cjs/LighterProvider.d.ts.map +1 -1
  4. package/dist/cjs/LighterProvider.js +27 -26
  5. package/dist/cjs/LighterProvider.js.map +1 -1
  6. package/dist/cjs/constants.d.ts +5 -8
  7. package/dist/cjs/constants.d.ts.map +1 -1
  8. package/dist/cjs/constants.js +15 -12
  9. package/dist/cjs/constants.js.map +1 -1
  10. package/dist/cjs/index.d.ts +3 -4
  11. package/dist/cjs/index.d.ts.map +1 -1
  12. package/dist/cjs/index.js +6 -5
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/signers/LighterSigner.d.ts +5 -7
  15. package/dist/cjs/signers/LighterSigner.d.ts.map +1 -1
  16. package/dist/cjs/signers/LighterSigner.js +5 -12
  17. package/dist/cjs/signers/LighterSigner.js.map +1 -1
  18. package/dist/cjs/signers/generated/wasmExecRuntime.d.ts +2 -0
  19. package/dist/cjs/signers/generated/wasmExecRuntime.d.ts.map +1 -0
  20. package/dist/cjs/signers/generated/wasmExecRuntime.js +569 -0
  21. package/dist/cjs/signers/generated/wasmExecRuntime.js.map +1 -0
  22. package/dist/cjs/signers/signActions.d.ts +2 -2
  23. package/dist/cjs/signers/signActions.d.ts.map +1 -1
  24. package/dist/cjs/signers/signActions.js +4 -10
  25. package/dist/cjs/signers/signActions.js.map +1 -1
  26. package/dist/cjs/signers/wasmBinaryUrl.js +11 -0
  27. package/dist/cjs/signers/wasmLoader.d.ts +1 -6
  28. package/dist/cjs/signers/wasmLoader.d.ts.map +1 -1
  29. package/dist/cjs/signers/wasmLoader.js +15 -69
  30. package/dist/cjs/signers/wasmLoader.js.map +1 -1
  31. package/dist/esm/LighterProvider.d.ts +53 -56
  32. package/dist/esm/LighterProvider.d.ts.map +1 -1
  33. package/dist/esm/LighterProvider.js +69 -48
  34. package/dist/esm/LighterProvider.js.map +1 -1
  35. package/dist/esm/constants.d.ts +25 -36
  36. package/dist/esm/constants.d.ts.map +1 -1
  37. package/dist/esm/constants.js +31 -18
  38. package/dist/esm/constants.js.map +1 -1
  39. package/dist/esm/index.d.ts +6 -7
  40. package/dist/esm/index.d.ts.map +1 -1
  41. package/dist/esm/index.js +5 -6
  42. package/dist/esm/index.js.map +1 -1
  43. package/dist/esm/signers/LighterSigner.d.ts +10 -18
  44. package/dist/esm/signers/LighterSigner.d.ts.map +1 -1
  45. package/dist/esm/signers/LighterSigner.js +7 -14
  46. package/dist/esm/signers/LighterSigner.js.map +1 -1
  47. package/dist/esm/signers/generated/wasmExecRuntime.d.ts +8 -0
  48. package/dist/esm/signers/generated/wasmExecRuntime.d.ts.map +1 -0
  49. package/dist/esm/signers/generated/wasmExecRuntime.js +574 -0
  50. package/dist/esm/signers/generated/wasmExecRuntime.js.map +1 -0
  51. package/dist/esm/signers/signActions.d.ts +3 -5
  52. package/dist/esm/signers/signActions.d.ts.map +1 -1
  53. package/dist/esm/signers/signActions.js +4 -10
  54. package/dist/esm/signers/signActions.js.map +1 -1
  55. package/dist/esm/signers/wasmBinaryUrl.js +10 -0
  56. package/dist/esm/signers/wasmLoader.d.ts +7 -31
  57. package/dist/esm/signers/wasmLoader.d.ts.map +1 -1
  58. package/dist/esm/signers/wasmLoader.js +32 -108
  59. package/dist/esm/signers/wasmLoader.js.map +1 -1
  60. package/dist/types/LighterProvider.d.ts +53 -56
  61. package/dist/types/LighterProvider.d.ts.map +1 -1
  62. package/dist/types/constants.d.ts +25 -36
  63. package/dist/types/constants.d.ts.map +1 -1
  64. package/dist/types/index.d.ts +6 -7
  65. package/dist/types/index.d.ts.map +1 -1
  66. package/dist/types/signers/LighterSigner.d.ts +10 -18
  67. package/dist/types/signers/LighterSigner.d.ts.map +1 -1
  68. package/dist/types/signers/generated/wasmExecRuntime.d.ts +8 -0
  69. package/dist/types/signers/generated/wasmExecRuntime.d.ts.map +1 -0
  70. package/dist/types/signers/signActions.d.ts +3 -5
  71. package/dist/types/signers/signActions.d.ts.map +1 -1
  72. package/dist/types/signers/wasmLoader.d.ts +7 -31
  73. package/dist/types/signers/wasmLoader.d.ts.map +1 -1
  74. package/package.json +1 -4
  75. package/src/LighterProvider.ts +98 -101
  76. package/src/constants.ts +35 -45
  77. package/src/index.ts +13 -10
  78. package/src/signers/LighterSigner.ts +15 -36
  79. package/src/signers/generated/wasmExecRuntime.ts +575 -0
  80. package/src/signers/signActions.ts +12 -30
  81. package/src/signers/wasmBinaryUrl.d.ts +7 -0
  82. package/src/signers/wasmLoader.ts +33 -152
  83. package/dist/cjs/signers/index.d.ts +0 -11
  84. package/dist/cjs/signers/index.d.ts.map +0 -1
  85. package/dist/cjs/signers/index.js +0 -18
  86. package/dist/cjs/signers/index.js.map +0 -1
  87. package/dist/esm/signers/index.d.ts +0 -11
  88. package/dist/esm/signers/index.d.ts.map +0 -1
  89. package/dist/esm/signers/index.js +0 -7
  90. package/dist/esm/signers/index.js.map +0 -1
  91. package/dist/types/signers/index.d.ts +0 -11
  92. package/dist/types/signers/index.d.ts.map +0 -1
  93. package/dist/wasm/wasm_exec.js +0 -561
  94. package/src/signers/index.ts +0 -35
  95. package/wasm/lighter-signer.wasm +0 -0
  96. package/wasm/wasm_exec.js +0 -561
package/src/constants.ts CHANGED
@@ -38,11 +38,12 @@ export const DEFAULT_LIGHTER_REST_URL = 'https://mainnet.zklighter.elliot.ai'
38
38
  export const DEFAULT_LIGHTER_WS_URL = 'wss://mainnet.zklighter.elliot.ai/stream'
39
39
 
40
40
  /**
41
- * zkLighter L2 signing chain id fed to {@link LighterSigner} on mainnet.
41
+ * zkLighter L2 signing chain id for the Lighter mainnet deployment, from
42
+ * `elliottech/lighter-python` v1.1.2 `lighter/endpoint_profiles.py`.
42
43
  *
43
44
  * @public
44
45
  */
45
- export const DEFAULT_LIGHTER_SIGNER_CHAIN_ID = 304
46
+ export const LIGHTER_MAINNET_SIGNER_CHAIN_ID = 304
46
47
 
47
48
  /**
48
49
  * Base URL the mainnet Lighter zkLighter explorer resolves a tx hash against
@@ -78,29 +79,30 @@ export const LIGHTER_COLLATERAL_ASSETS: Record<
78
79
  LighterProviderKey,
79
80
  LighterCollateralAsset
80
81
  > = {
81
- [LIGHTER_PROVIDER_KEY]: {
82
+ [LIGHTER_PROVIDER_KEY]: Object.freeze({
82
83
  assetIndex: LT_ASSET_ID_USDC,
83
84
  displaySymbol: 'USDC',
84
- },
85
- [LIGHTER_RH_PROVIDER_KEY]: { assetIndex: 3, displaySymbol: 'USDG' },
85
+ }),
86
+ [LIGHTER_RH_PROVIDER_KEY]: Object.freeze({
87
+ assetIndex: 3,
88
+ displaySymbol: 'USDG',
89
+ }),
86
90
  }
87
91
 
88
92
  /**
89
- * The venue-specific facts that distinguish one Lighter deployment from
90
- * another. One provider + WS pair is built per instance from these; a client
91
- * may register several so long as their `providerKey`s differ.
93
+ * The immutable venue facts that distinguish one Lighter deployment from
94
+ * another. The SDK owns one descriptor per supported deployment; consumers
95
+ * select a deployment by picking its provider factory, never by assembling
96
+ * these fields.
92
97
  *
93
98
  * @public
94
99
  */
95
- export interface LighterInstanceConfig {
96
- /** Wire-visible `Provider.key` and the plugin `type`; unique per instance. */
100
+ export interface LighterDeployment {
101
+ /** Wire-visible `Provider.key` and the plugin `type`; unique per deployment. */
97
102
  providerKey: LighterProviderKey
98
103
  restUrl: string
99
104
  wsUrl: string
100
- /**
101
- * zkLighter L2 signing chain id to construct this instance's
102
- * {@link LighterSigner} with.
103
- */
105
+ /** zkLighter L2 signing chain id this deployment's transactions are signed against. */
104
106
  signerChainId: number
105
107
  /**
106
108
  * Collateral asset this deployment settles in — signed into its withdrawals
@@ -109,75 +111,63 @@ export interface LighterInstanceConfig {
109
111
  collateral: LighterCollateralAsset
110
112
  /**
111
113
  * Explorer tx base URL for transfer-activity links (`${base}${txHash}`).
112
- * When omitted, transfer links are not emitted for this instance.
114
+ * When omitted, transfer links are not emitted for this deployment.
113
115
  */
114
116
  explorerTxBaseUrl?: string
115
117
  }
116
118
 
117
119
  /**
118
- * The built-in mainnet Lighter instance — the defaults `lighterProvider()` and
119
- * `lighterWsProvider()` apply when constructed with no instance overrides.
120
+ * Lighter mainnet, as served by `lighterProvider()`.
120
121
  *
121
122
  * @public
122
123
  */
123
- export const LIGHTER_MAINNET_INSTANCE: LighterInstanceConfig = {
124
+ export const LIGHTER_MAINNET_DEPLOYMENT: LighterDeployment = Object.freeze({
124
125
  providerKey: LIGHTER_PROVIDER_KEY,
125
126
  restUrl: DEFAULT_LIGHTER_REST_URL,
126
127
  wsUrl: DEFAULT_LIGHTER_WS_URL,
127
- signerChainId: DEFAULT_LIGHTER_SIGNER_CHAIN_ID,
128
+ signerChainId: LIGHTER_MAINNET_SIGNER_CHAIN_ID,
128
129
  collateral: LIGHTER_COLLATERAL_ASSETS[LIGHTER_PROVIDER_KEY],
129
130
  explorerTxBaseUrl: DEFAULT_LIGHTER_EXPLORER_TX_BASE_URL,
130
- }
131
+ })
131
132
 
132
133
  /**
133
- * Default REST base URL for the Lighter Robinhood deployment.
134
+ * REST base URL for the Lighter Robinhood deployment.
134
135
  *
135
136
  * @public
136
137
  */
137
138
  export const LIGHTER_RH_REST_URL = 'https://api.rh.lighter.xyz'
138
139
  /**
139
- * Default WebSocket URL for the Lighter Robinhood deployment.
140
+ * WebSocket URL for the Lighter Robinhood deployment.
140
141
  *
141
142
  * @public
142
143
  */
143
144
  export const LIGHTER_RH_WS_URL = 'wss://api.rh.lighter.xyz/stream'
144
145
 
145
146
  /**
146
- * Deployment-supplied facts the RH instance cannot source from public
147
- * documentation and the caller must confirm.
147
+ * zkLighter L2 signing chain id for the Lighter Robinhood deployment, from
148
+ * `elliottech/lighter-python` v1.1.2 `lighter/endpoint_profiles.py`
149
+ * (`ROBINHOOD.chain_id`) and its `signer_client.py` host fallback. Distinct
150
+ * from mainnet's 304 and from Robinhood's L1 chain id 4663 — signing with
151
+ * either yields a venue-rejected transaction.
148
152
  *
149
153
  * @public
150
154
  */
151
- export interface LighterRhInstanceOverrides {
152
- /**
153
- * zkLighter L2 signing chain id for the RH instance. Unverified from public
154
- * sources — must be the value confirmed against lighter-go / RH support, not
155
- * mainnet's 304 nor the RH L1 chain id 4663.
156
- */
157
- signerChainId: number
158
- /**
159
- * RH zkLighter explorer tx base URL. Omit until confirmed; transfer links are
160
- * then left unset rather than pointed at the mainnet explorer.
161
- */
162
- explorerTxBaseUrl?: string
163
- }
155
+ export const LIGHTER_RH_SIGNER_CHAIN_ID = 466324
164
156
 
165
157
  /**
166
- * Build the `lighter-rh` {@link LighterInstanceConfig}. The signing chain id is
167
- * a required argument because it is not verifiable from public sources — the
168
- * caller must pass the value confirmed against lighter-go / RH support.
158
+ * Lighter on Robinhood chain, as served by `lighterRhProvider()`. No explorer
159
+ * base URL: the RH zkLighter explorer is unpublished, so transfer links are
160
+ * left unset rather than pointed at the mainnet explorer.
169
161
  *
170
162
  * @public
171
163
  */
172
- export const lighterRhInstance = (
173
- overrides: LighterRhInstanceOverrides
174
- ): LighterInstanceConfig => ({
164
+ export const LIGHTER_RH_DEPLOYMENT: LighterDeployment = Object.freeze({
175
165
  providerKey: LIGHTER_RH_PROVIDER_KEY,
176
166
  restUrl: LIGHTER_RH_REST_URL,
177
167
  wsUrl: LIGHTER_RH_WS_URL,
178
- signerChainId: overrides.signerChainId,
168
+ signerChainId: LIGHTER_RH_SIGNER_CHAIN_ID,
179
169
  collateral: LIGHTER_COLLATERAL_ASSETS[LIGHTER_RH_PROVIDER_KEY],
180
- explorerTxBaseUrl: overrides.explorerTxBaseUrl,
170
+ explorerTxBaseUrl: undefined,
181
171
  })
182
172
 
183
173
  /** @internal */
package/src/index.ts CHANGED
@@ -5,9 +5,9 @@
5
5
  * Lighter provider plugin for `@lifi/perps-sdk`. Serves `PerpsProvider` reads
6
6
  * directly from Lighter's REST API (no LI.FI backend hop); auth-gated reads
7
7
  * use the user's Lighter read-only token. Also owns `signActions` (the
8
- * `WASM_BLOB` / `EVM_TX` arms of `PerpsClient.execute`) — `LighterSigner`,
9
- * `LighterKeyStore`, `LighterReadOnlyTokenManager`, and the WASM blob ship
10
- * with this package.
8
+ * `WASM_BLOB` / `EVM_TX` arms of `PerpsClient.execute`): each provider
9
+ * instance creates its own WASM signer, API-key store and read-only token
10
+ * manager, and the Go signer binary ships with this package.
11
11
  *
12
12
  * @packageDocumentation
13
13
  * @public
@@ -17,32 +17,35 @@ export { projectLighterConfigSettings } from './accountConfig.js'
17
17
  export { getAccountSummary } from './accountSummary.js'
18
18
  export type {
19
19
  LighterCollateralAsset,
20
- LighterInstanceConfig,
21
- LighterRhInstanceOverrides,
20
+ LighterDeployment,
22
21
  } from './constants.js'
23
22
  export {
24
23
  DEFAULT_API_KEY_INDEX,
25
24
  DEFAULT_LIGHTER_EXPLORER_TX_BASE_URL,
26
25
  DEFAULT_LIGHTER_REST_URL,
27
- DEFAULT_LIGHTER_SIGNER_CHAIN_ID,
28
26
  DEFAULT_LIGHTER_WS_URL,
29
27
  LIGHTER_COLLATERAL_ASSETS,
30
- LIGHTER_MAINNET_INSTANCE,
28
+ LIGHTER_MAINNET_DEPLOYMENT,
29
+ LIGHTER_MAINNET_SIGNER_CHAIN_ID,
31
30
  LIGHTER_PROVIDER_KEY,
31
+ LIGHTER_RH_DEPLOYMENT,
32
32
  LIGHTER_RH_PROVIDER_KEY,
33
33
  LIGHTER_RH_REST_URL,
34
+ LIGHTER_RH_SIGNER_CHAIN_ID,
34
35
  LIGHTER_RH_WS_URL,
35
36
  LIGHTER_SPOT_CATEGORY_ID,
36
- lighterRhInstance,
37
37
  } from './constants.js'
38
38
  export { lighterDepositFlow } from './depositFlow.js'
39
39
  export type {
40
40
  LighterPerpsProvider,
41
41
  LighterProviderOptions,
42
42
  } from './LighterProvider.js'
43
- export { Lighter, lighterProvider } from './LighterProvider.js'
43
+ export {
44
+ Lighter,
45
+ lighterProvider,
46
+ lighterRhProvider,
47
+ } from './LighterProvider.js'
44
48
 
45
- export * from './signers/index.js'
46
49
  export * from './types/index.js'
47
50
  export * from './utils/index.js'
48
51
  export type { LighterAuthTokenResolver } from './websocket/LighterWsProvider.js'
@@ -1,17 +1,8 @@
1
1
  import { ActionType } from '@lifi/perps-types'
2
- import {
3
- DEFAULT_LIGHTER_REST_URL,
4
- DEFAULT_LIGHTER_SIGNER_CHAIN_ID,
5
- } from '../constants.js'
6
- import {
7
- LT_ASSET_ID_USDC,
8
- LT_ROUTE_PERP,
9
- LT_ROUTE_SPOT,
10
- } from '../types/action.js'
2
+ import { LT_ROUTE_PERP, LT_ROUTE_SPOT } from '../types/action.js'
11
3
  import { assetMarginModeInt } from '../utils/assetCollateral.js'
12
4
  import {
13
5
  type LighterWasmExports,
14
- type LoadLighterWasmOptions,
15
6
  loadLighterWasm,
16
7
  type SignResult,
17
8
  } from './wasmLoader.js'
@@ -38,22 +29,16 @@ export interface LighterSignerContext {
38
29
  }
39
30
 
40
31
  /**
41
- * Configuration for {@link LighterSigner}: optional WASM asset overrides plus
42
- * the per-instance REST base URL, signing chain id and collateral asset index.
32
+ * Deployment facts {@link LighterSigner} signs against: the venue's REST base
33
+ * URL, its zkLighter L2 signing chain id, and the L2 asset index its
34
+ * withdrawals and transfers settle in.
43
35
  *
44
- * @public
36
+ * @internal
45
37
  */
46
- export interface LighterSignerConfig extends LoadLighterWasmOptions {
47
- /** Lighter REST API base URL. */
48
- apiUrl?: string
49
- /** Lighter chain ID (304 = mainnet). */
50
- chainId?: number
51
- /**
52
- * L2 asset index this instance's withdrawals and transfers are signed
53
- * against — pass the instance's `collateral.assetIndex`. Defaults to
54
- * mainnet's USDC slot.
55
- */
56
- collateralAssetIndex?: number
38
+ export interface LighterSignerConfig {
39
+ apiUrl: string
40
+ signerChainId: number
41
+ collateralAssetIndex: number
57
42
  }
58
43
 
59
44
  /**
@@ -136,25 +121,19 @@ const LIGHTER_ROUTE_BY_DEX: Record<string, number> = {
136
121
  * hybrid flows. The instance memoizes WASM initialization and registered
137
122
  * `(apiKeyIndex, accountIndex)` clients.
138
123
  *
139
- * @public
124
+ * @internal
140
125
  */
141
126
  export class LighterSigner {
142
127
  private readonly apiUrl: string
143
128
  private readonly chainId: number
144
129
  private readonly collateralAssetIndex: number
145
- private readonly loaderOptions: LoadLighterWasmOptions
146
130
  private wasm: LighterWasmExports | undefined
147
131
  private readonly registeredClients = new Set<string>()
148
132
 
149
- constructor(config: LighterSignerConfig = {}) {
150
- this.apiUrl = config.apiUrl ?? DEFAULT_LIGHTER_REST_URL
151
- this.chainId = config.chainId ?? DEFAULT_LIGHTER_SIGNER_CHAIN_ID
152
- this.collateralAssetIndex = config.collateralAssetIndex ?? LT_ASSET_ID_USDC
153
- this.loaderOptions = {
154
- wasmBinaryUrl: config.wasmBinaryUrl,
155
- wasmExecJsUrl: config.wasmExecJsUrl,
156
- wasmExecJsSource: config.wasmExecJsSource,
157
- }
133
+ constructor(config: LighterSignerConfig) {
134
+ this.apiUrl = config.apiUrl
135
+ this.chainId = config.signerChainId
136
+ this.collateralAssetIndex = config.collateralAssetIndex
158
137
  }
159
138
 
160
139
  /**
@@ -163,7 +142,7 @@ export class LighterSigner {
163
142
  */
164
143
  async initialize(): Promise<void> {
165
144
  if (!this.wasm) {
166
- this.wasm = await loadLighterWasm(this.loaderOptions)
145
+ this.wasm = await loadLighterWasm()
167
146
  }
168
147
  }
169
148