@lifi/perps-sdk-provider-lighter 22.1.0 → 23.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 (51) hide show
  1. package/README.md +20 -1
  2. package/dist/cjs/LighterProvider.d.ts.map +1 -1
  3. package/dist/cjs/LighterProvider.js +14 -10
  4. package/dist/cjs/LighterProvider.js.map +1 -1
  5. package/dist/cjs/signers/generated/wasmExecRuntime.d.ts +4 -1
  6. package/dist/cjs/signers/generated/wasmExecRuntime.d.ts.map +1 -1
  7. package/dist/cjs/signers/generated/wasmExecRuntime.js +470 -566
  8. package/dist/cjs/signers/generated/wasmExecRuntime.js.map +1 -1
  9. package/dist/cjs/signers/wasmLoader.d.ts.map +1 -1
  10. package/dist/cjs/signers/wasmLoader.js +1 -3
  11. package/dist/cjs/signers/wasmLoader.js.map +1 -1
  12. package/dist/cjs/utils/mapMarketContext.d.ts.map +1 -1
  13. package/dist/cjs/utils/mapMarketContext.js +2 -1
  14. package/dist/cjs/utils/mapMarketContext.js.map +1 -1
  15. package/dist/cjs/utils/marketLimits.d.ts +2 -2
  16. package/dist/cjs/utils/marketLimits.d.ts.map +1 -1
  17. package/dist/cjs/utils/marketLimits.js +2 -1
  18. package/dist/cjs/utils/marketLimits.js.map +1 -1
  19. package/dist/esm/LighterProvider.d.ts.map +1 -1
  20. package/dist/esm/LighterProvider.js +16 -10
  21. package/dist/esm/LighterProvider.js.map +1 -1
  22. package/dist/esm/signers/generated/wasmExecRuntime.d.ts +5 -7
  23. package/dist/esm/signers/generated/wasmExecRuntime.d.ts.map +1 -1
  24. package/dist/esm/signers/generated/wasmExecRuntime.js +507 -571
  25. package/dist/esm/signers/generated/wasmExecRuntime.js.map +1 -1
  26. package/dist/esm/signers/wasmLoader.d.ts.map +1 -1
  27. package/dist/esm/signers/wasmLoader.js +2 -11
  28. package/dist/esm/signers/wasmLoader.js.map +1 -1
  29. package/dist/esm/types/ws.d.ts +2 -2
  30. package/dist/esm/utils/mapMarketContext.d.ts.map +1 -1
  31. package/dist/esm/utils/mapMarketContext.js +2 -1
  32. package/dist/esm/utils/mapMarketContext.js.map +1 -1
  33. package/dist/esm/utils/marketLimits.d.ts +3 -3
  34. package/dist/esm/utils/marketLimits.d.ts.map +1 -1
  35. package/dist/esm/utils/marketLimits.js +3 -2
  36. package/dist/esm/utils/marketLimits.js.map +1 -1
  37. package/dist/types/LighterProvider.d.ts.map +1 -1
  38. package/dist/types/signers/generated/wasmExecRuntime.d.ts +5 -7
  39. package/dist/types/signers/generated/wasmExecRuntime.d.ts.map +1 -1
  40. package/dist/types/signers/wasmLoader.d.ts.map +1 -1
  41. package/dist/types/types/ws.d.ts +2 -2
  42. package/dist/types/utils/mapMarketContext.d.ts.map +1 -1
  43. package/dist/types/utils/marketLimits.d.ts +3 -3
  44. package/dist/types/utils/marketLimits.d.ts.map +1 -1
  45. package/package.json +2 -2
  46. package/src/LighterProvider.ts +31 -25
  47. package/src/signers/generated/wasmExecRuntime.ts +570 -572
  48. package/src/signers/wasmLoader.ts +2 -17
  49. package/src/types/ws.ts +2 -2
  50. package/src/utils/mapMarketContext.ts +3 -1
  51. package/src/utils/marketLimits.ts +5 -4
@@ -1,7 +1,7 @@
1
1
  // The Go runtime installs functions (SignCreateOrder, SignCancelOrder, etc.)
2
2
  // onto `globalThis` when `go.run(instance)` starts the main goroutine.
3
3
 
4
- import { WASM_EXEC_JS } from './generated/wasmExecRuntime.js'
4
+ import { createGoRuntime } from './generated/wasmExecRuntime.js'
5
5
  import {
6
6
  lighterWasmBinaryUrl,
7
7
  resolveEmittedBinaryUrl,
@@ -157,11 +157,6 @@ const WASM_FUNCTION_NAMES = [
157
157
  'SignUpdateAccountAssetConfig',
158
158
  ] as const
159
159
 
160
- type GoClass = new () => {
161
- importObject: WebAssembly.Imports
162
- run(instance: WebAssembly.Instance): Promise<void>
163
- }
164
-
165
160
  let cachedExports: Promise<LighterWasmExports> | undefined
166
161
 
167
162
  // `node:fs/promises` is Node-only and reached solely for a `file://` asset URL,
@@ -283,17 +278,7 @@ export async function loadLighterWasm(): Promise<LighterWasmExports> {
283
278
  async function loadWasmUncached(): Promise<LighterWasmExports> {
284
279
  const wasmBytes = await readWasmBinary(lighterWasmBinaryUrl)
285
280
 
286
- // wasm_exec.js is an IIFE that installs `globalThis.Go = class { ... }` plus
287
- // fs/process/crypto polyfills. Evaluating the packaged text keeps Go's runtime
288
- // opaque to consumer bundlers — it references require/process/fs/crypto, which
289
- // Vite/webpack choke on if they try to parse it as a module. The text is
290
- // generated from this package's vendored wasm_exec.js at build time and is
291
- // never caller-supplied.
292
- // nosec
293
- const installGo = new Function(`${WASM_EXEC_JS}; return globalThis.Go`)
294
- const Go = installGo() as GoClass
295
-
296
- const go = new Go()
281
+ const go = createGoRuntime()
297
282
  const { instance } = await WebAssembly.instantiate(wasmBytes, go.importObject)
298
283
  // Start the Go goroutine — this never resolves until the Go main() returns,
299
284
  // which our signer never does. Intentionally not awaited.
package/src/types/ws.ts CHANGED
@@ -33,8 +33,8 @@ export type LtWsPingMessage = LtWsMessage & { type: 'ping' }
33
33
  /**
34
34
  * Perpetual-market statistics pushed by Lighter's `market_stats` channels.
35
35
  * Price, interest, and funding values are decimal strings; the daily volume
36
- * and change figures are JSON numbers and the funding timestamp is a Unix
37
- * timestamp in milliseconds.
36
+ * and change figures are JSON numbers. `funding_timestamp` is the last funding
37
+ * payment time as a Unix timestamp in milliseconds.
38
38
  *
39
39
  * @public
40
40
  */
@@ -1,6 +1,8 @@
1
1
  import type { MarketContext } from '@lifi/perps-types'
2
2
  import type { LtWsMarketStats, LtWsSpotMarketStats } from '../types/index.js'
3
3
 
4
+ const FUNDING_PERIOD_MS = 60 * 60 * 1000
5
+
4
6
  const isPerpStats = (
5
7
  stats: LtWsMarketStats | LtWsSpotMarketStats
6
8
  ): stats is LtWsMarketStats => 'mark_price' in stats
@@ -27,7 +29,7 @@ export const mapMarketContext = (
27
29
  openInterest: stats.open_interest,
28
30
  funding: {
29
31
  rate: stats.current_funding_rate,
30
- nextFundingTime: stats.funding_timestamp,
32
+ nextFundingTime: stats.funding_timestamp + FUNDING_PERIOD_MS,
31
33
  },
32
34
  }
33
35
  }
@@ -3,25 +3,26 @@ import type { LtPerpsOrderBookDetail } from '../types/index.js'
3
3
 
4
4
  type MarketOrderLimits = Pick<
5
5
  PerpsMarket,
6
- 'maxMarketOrderUsd' | 'maxLimitOrderUsd'
6
+ 'maxMarketOrderUsd' | 'maxLimitOrderUsd' | 'minOrderValueUsd'
7
7
  >
8
8
 
9
9
  type LighterMarketLimitSource = Pick<
10
10
  LtPerpsOrderBookDetail,
11
- 'order_quote_limit'
11
+ 'order_quote_limit' | 'min_quote_amount'
12
12
  >
13
13
 
14
14
  const NO_ORDER_QUOTE_LIMIT = '281474976.710655'
15
15
 
16
- /** Map the order-value cap published by Lighter's order-book metadata. */
16
+ /** Map the order-value limits published by Lighter's order-book metadata. */
17
17
  export const mapMarketOrderLimits = (
18
18
  market: LighterMarketLimitSource
19
19
  ): MarketOrderLimits => {
20
20
  if (market.order_quote_limit === NO_ORDER_QUOTE_LIMIT) {
21
- return {}
21
+ return { minOrderValueUsd: market.min_quote_amount }
22
22
  }
23
23
 
24
24
  return {
25
+ minOrderValueUsd: market.min_quote_amount,
25
26
  maxMarketOrderUsd: market.order_quote_limit,
26
27
  maxLimitOrderUsd: market.order_quote_limit,
27
28
  }