perp-cli 0.12.15 → 0.14.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 (361) hide show
  1. package/README.md +278 -31
  2. package/dist/_stderr-filter.js +0 -1
  3. package/dist/agent-wallet/lighter-keystore.d.ts +11 -0
  4. package/dist/agent-wallet/lighter-keystore.js +92 -10
  5. package/dist/agent-wallet/passphrase.d.ts +1 -1
  6. package/dist/agent-wallet/passphrase.js +16 -3
  7. package/dist/agent-wallet/store.d.ts +37 -4
  8. package/dist/agent-wallet/store.js +132 -0
  9. package/dist/agent-wallet/venue-keystore.d.ts +14 -0
  10. package/dist/agent-wallet/venue-keystore.js +121 -0
  11. package/dist/api/public/hyperliquid.js +4 -4
  12. package/dist/api/public/lighter.js +5 -5
  13. package/dist/api/public/pacifica.d.ts +0 -1
  14. package/dist/api/public/pacifica.js +4 -13
  15. package/dist/api/public/urls.d.ts +9 -1
  16. package/dist/api/public/urls.js +35 -13
  17. package/dist/arb/file-lock.d.ts +11 -0
  18. package/dist/arb/file-lock.js +74 -0
  19. package/dist/arb/index.d.ts +2 -2
  20. package/dist/arb/index.js +2 -2
  21. package/dist/arb/pending-entry.d.ts +32 -0
  22. package/dist/arb/pending-entry.js +77 -0
  23. package/dist/arb/sizing.d.ts +6 -13
  24. package/dist/arb/sizing.js +12 -51
  25. package/dist/arb/state.d.ts +45 -12
  26. package/dist/arb/state.js +214 -42
  27. package/dist/arb/utils.d.ts +20 -6
  28. package/dist/arb/utils.js +43 -39
  29. package/dist/bot/conditions.d.ts +4 -4
  30. package/dist/bot/conditions.js +11 -6
  31. package/dist/bot/config.d.ts +17 -1
  32. package/dist/bot/config.js +48 -12
  33. package/dist/bot/engine.d.ts +61 -2
  34. package/dist/bot/engine.js +610 -144
  35. package/dist/bot/fill-size.d.ts +7 -0
  36. package/dist/bot/fill-size.js +18 -0
  37. package/dist/bot/index.d.ts +1 -1
  38. package/dist/bot/index.js +1 -1
  39. package/dist/bot/perp-order.d.ts +99 -0
  40. package/dist/bot/perp-order.js +299 -0
  41. package/dist/bot/presets.d.ts +7 -0
  42. package/dist/bot/presets.js +17 -0
  43. package/dist/bot/quarantine.d.ts +75 -0
  44. package/dist/bot/quarantine.js +190 -0
  45. package/dist/bot/quote-rules.d.ts +23 -0
  46. package/dist/bot/quote-rules.js +69 -0
  47. package/dist/bot/strategies/avellaneda-mm.d.ts +32 -2
  48. package/dist/bot/strategies/avellaneda-mm.js +72 -70
  49. package/dist/bot/strategies/basis-arb.js +2 -0
  50. package/dist/bot/strategies/dca-strategy.d.ts +2 -0
  51. package/dist/bot/strategies/dca-strategy.js +5 -0
  52. package/dist/bot/strategies/funding-arb-strategy.d.ts +43 -3
  53. package/dist/bot/strategies/funding-arb-strategy.js +571 -380
  54. package/dist/bot/strategies/funding-arb-utils.d.ts +48 -23
  55. package/dist/bot/strategies/funding-arb-utils.js +159 -195
  56. package/dist/bot/strategies/funding-arb-v2.d.ts +32 -0
  57. package/dist/bot/strategies/funding-arb-v2.js +258 -47
  58. package/dist/bot/strategies/funding-auto.js +215 -194
  59. package/dist/bot/strategies/spot-perp-arb-strategy.d.ts +14 -0
  60. package/dist/bot/strategies/spot-perp-arb-strategy.js +217 -50
  61. package/dist/bot/strategies/spot-perp-executor.d.ts +73 -19
  62. package/dist/bot/strategies/spot-perp-executor.js +319 -120
  63. package/dist/bot/strategies/spot-perp-state.d.ts +43 -0
  64. package/dist/bot/strategies/spot-perp-state.js +70 -0
  65. package/dist/bot/strategy-types.d.ts +6 -0
  66. package/dist/bot/tui/BotDashboard.d.ts +7 -2
  67. package/dist/bot/tui/BotDashboard.js +6 -3
  68. package/dist/bridge-engine.d.ts +120 -19
  69. package/dist/bridge-engine.js +710 -422
  70. package/dist/bridge-signers.d.ts +54 -0
  71. package/dist/bridge-signers.js +161 -0
  72. package/dist/cache.d.ts +4 -1
  73. package/dist/cache.js +11 -0
  74. package/dist/cli-flags.d.ts +50 -0
  75. package/dist/cli-flags.js +104 -0
  76. package/dist/cli-program.d.ts +35 -0
  77. package/dist/cli-program.js +286 -0
  78. package/dist/cli-spec.js +1 -1
  79. package/dist/client-id-tracker.js +11 -2
  80. package/dist/commands/account.d.ts +7 -1
  81. package/dist/commands/account.js +74 -84
  82. package/dist/commands/agent-import.d.ts +114 -0
  83. package/dist/commands/agent-import.js +794 -0
  84. package/dist/commands/agent.d.ts +232 -2
  85. package/dist/commands/agent.js +1858 -955
  86. package/dist/commands/alerts.d.ts +1 -0
  87. package/dist/commands/alerts.js +31 -28
  88. package/dist/commands/arb/index.d.ts +60 -1
  89. package/dist/commands/arb/index.js +381 -384
  90. package/dist/commands/arb-auto.d.ts +132 -4
  91. package/dist/commands/arb-auto.js +1474 -967
  92. package/dist/commands/arb.d.ts +3 -1
  93. package/dist/commands/arb.js +62 -30
  94. package/dist/commands/bot.js +127 -47
  95. package/dist/commands/bridge.d.ts +2 -1
  96. package/dist/commands/bridge.js +339 -192
  97. package/dist/commands/builder.d.ts +55 -0
  98. package/dist/commands/builder.js +387 -0
  99. package/dist/commands/funds-onchain.d.ts +32 -0
  100. package/dist/commands/funds-onchain.js +286 -0
  101. package/dist/commands/funds.d.ts +25 -0
  102. package/dist/commands/funds.js +939 -245
  103. package/dist/commands/history.js +72 -45
  104. package/dist/commands/init.d.ts +107 -15
  105. package/dist/commands/init.js +1116 -249
  106. package/dist/commands/jobs.d.ts +2 -1
  107. package/dist/commands/jobs.js +77 -15
  108. package/dist/commands/manage.js +136 -91
  109. package/dist/commands/market.d.ts +4 -1
  110. package/dist/commands/market.js +35 -32
  111. package/dist/commands/outcome.d.ts +10 -0
  112. package/dist/commands/outcome.js +396 -0
  113. package/dist/commands/plan.js +52 -12
  114. package/dist/commands/portfolio.d.ts +1 -0
  115. package/dist/commands/portfolio.js +60 -72
  116. package/dist/commands/rebalance.d.ts +2 -1
  117. package/dist/commands/rebalance.js +33 -43
  118. package/dist/commands/risk.js +46 -19
  119. package/dist/commands/settings.d.ts +1 -0
  120. package/dist/commands/settings.js +246 -51
  121. package/dist/commands/trade.d.ts +50 -0
  122. package/dist/commands/trade.js +1943 -695
  123. package/dist/commands/wallet.d.ts +30 -1
  124. package/dist/commands/wallet.js +316 -337
  125. package/dist/config.d.ts +60 -9
  126. package/dist/config.js +252 -82
  127. package/dist/constants.d.ts +29 -4
  128. package/dist/constants.js +62 -20
  129. package/dist/dashboard/server.d.ts +2 -0
  130. package/dist/dashboard/server.js +9 -6
  131. package/dist/dashboard/ui.js +6 -4
  132. package/dist/dashboard/ws-feeds.js +20 -8
  133. package/dist/dex-asset-map.js +5 -3
  134. package/dist/errors.d.ts +122 -0
  135. package/dist/errors.js +194 -0
  136. package/dist/event-stream.js +75 -19
  137. package/dist/evm-master-tx.d.ts +59 -0
  138. package/dist/evm-master-tx.js +154 -0
  139. package/dist/exchanges/adapter-network.d.ts +10 -0
  140. package/dist/exchanges/adapter-network.js +10 -0
  141. package/dist/exchanges/arcus/adapter.d.ts +196 -0
  142. package/dist/exchanges/arcus/adapter.js +1092 -0
  143. package/dist/exchanges/arcus/agent.d.ts +55 -0
  144. package/dist/exchanges/arcus/agent.js +188 -0
  145. package/dist/exchanges/arcus/client.d.ts +63 -0
  146. package/dist/exchanges/arcus/client.js +285 -0
  147. package/dist/exchanges/arcus/public.d.ts +65 -0
  148. package/dist/exchanges/arcus/public.js +138 -0
  149. package/dist/exchanges/arcus/signing.d.ts +176 -0
  150. package/dist/exchanges/arcus/signing.js +288 -0
  151. package/dist/exchanges/arcus/spot-chain.d.ts +60 -0
  152. package/dist/exchanges/arcus/spot-chain.js +241 -0
  153. package/dist/exchanges/arcus/spot-router.d.ts +177 -0
  154. package/dist/exchanges/arcus/spot-router.js +183 -0
  155. package/dist/exchanges/arcus/spot.d.ts +109 -0
  156. package/dist/exchanges/arcus/spot.js +645 -0
  157. package/dist/exchanges/aster-funds.d.ts +127 -0
  158. package/dist/exchanges/aster-funds.js +252 -0
  159. package/dist/exchanges/aster-nonce.d.ts +2 -0
  160. package/dist/exchanges/aster-nonce.js +107 -0
  161. package/dist/exchanges/aster-spot.d.ts +117 -0
  162. package/dist/exchanges/aster-spot.js +686 -0
  163. package/dist/exchanges/aster-typed-data.d.ts +133 -7
  164. package/dist/exchanges/aster-typed-data.js +121 -7
  165. package/dist/exchanges/aster.d.ts +219 -6
  166. package/dist/exchanges/aster.js +1023 -153
  167. package/dist/exchanges/builder-fee.d.ts +254 -0
  168. package/dist/exchanges/builder-fee.js +421 -0
  169. package/dist/exchanges/canonical-symbols.d.ts +32 -0
  170. package/dist/exchanges/canonical-symbols.js +96 -0
  171. package/dist/exchanges/capabilities.d.ts +7 -1
  172. package/dist/exchanges/capabilities.js +7 -0
  173. package/dist/exchanges/hl-signing.d.ts +165 -0
  174. package/dist/exchanges/hl-signing.js +158 -0
  175. package/dist/exchanges/hyperliquid-outcome.d.ts +211 -0
  176. package/dist/exchanges/hyperliquid-outcome.js +646 -0
  177. package/dist/exchanges/hyperliquid-spot.d.ts +44 -5
  178. package/dist/exchanges/hyperliquid-spot.js +308 -117
  179. package/dist/exchanges/hyperliquid.d.ts +462 -57
  180. package/dist/exchanges/hyperliquid.js +1575 -449
  181. package/dist/exchanges/index.d.ts +6 -0
  182. package/dist/exchanges/index.js +4 -0
  183. package/dist/exchanges/interface.d.ts +63 -10
  184. package/dist/exchanges/interface.js +18 -3
  185. package/dist/exchanges/ioc-outcome.d.ts +44 -0
  186. package/dist/exchanges/ioc-outcome.js +57 -0
  187. package/dist/exchanges/legacy-trading-v2.d.ts +39 -0
  188. package/dist/exchanges/legacy-trading-v2.js +940 -0
  189. package/dist/exchanges/lighter-public.d.ts +43 -0
  190. package/dist/exchanges/lighter-public.js +276 -0
  191. package/dist/exchanges/lighter-rh-deposit.d.ts +62 -0
  192. package/dist/exchanges/lighter-rh-deposit.js +185 -0
  193. package/dist/exchanges/lighter-signer.d.ts +123 -0
  194. package/dist/exchanges/lighter-signer.js +215 -0
  195. package/dist/exchanges/lighter-spot.d.ts +91 -13
  196. package/dist/exchanges/lighter-spot.js +595 -233
  197. package/dist/exchanges/lighter.d.ts +611 -39
  198. package/dist/exchanges/lighter.js +1890 -649
  199. package/dist/exchanges/ondo/adapter.d.ts +166 -0
  200. package/dist/exchanges/ondo/adapter.js +835 -0
  201. package/dist/exchanges/ondo/agent.d.ts +31 -0
  202. package/dist/exchanges/ondo/agent.js +101 -0
  203. package/dist/exchanges/ondo/client.d.ts +60 -0
  204. package/dist/exchanges/ondo/client.js +297 -0
  205. package/dist/exchanges/ondo/funds.d.ts +122 -0
  206. package/dist/exchanges/ondo/funds.js +290 -0
  207. package/dist/exchanges/ondo/public.d.ts +95 -0
  208. package/dist/exchanges/ondo/public.js +214 -0
  209. package/dist/exchanges/ondo/spot.d.ts +127 -0
  210. package/dist/exchanges/ondo/spot.js +392 -0
  211. package/dist/exchanges/outcome-interface.d.ts +140 -0
  212. package/dist/exchanges/outcome-interface.js +16 -0
  213. package/dist/exchanges/pacifica-spot.d.ts +83 -0
  214. package/dist/exchanges/pacifica-spot.js +324 -0
  215. package/dist/exchanges/pacifica-typed-data.d.ts +30 -13
  216. package/dist/exchanges/pacifica-typed-data.js +57 -9
  217. package/dist/exchanges/pacifica.d.ts +288 -4
  218. package/dist/exchanges/pacifica.js +1013 -76
  219. package/dist/exchanges/precision.d.ts +47 -0
  220. package/dist/exchanges/precision.js +209 -0
  221. package/dist/exchanges/qfex/adapter.d.ts +341 -0
  222. package/dist/exchanges/qfex/adapter.js +1383 -0
  223. package/dist/exchanges/qfex/agent.d.ts +58 -0
  224. package/dist/exchanges/qfex/agent.js +188 -0
  225. package/dist/exchanges/qfex/client.d.ts +54 -0
  226. package/dist/exchanges/qfex/client.js +138 -0
  227. package/dist/exchanges/qfex/errors.d.ts +70 -0
  228. package/dist/exchanges/qfex/errors.js +236 -0
  229. package/dist/exchanges/qfex/public.d.ts +122 -0
  230. package/dist/exchanges/qfex/public.js +268 -0
  231. package/dist/exchanges/qfex/signing.d.ts +160 -0
  232. package/dist/exchanges/qfex/signing.js +283 -0
  233. package/dist/exchanges/qfex/ws-transport.d.ts +294 -0
  234. package/dist/exchanges/qfex/ws-transport.js +798 -0
  235. package/dist/exchanges/rate-limiter.d.ts +12 -0
  236. package/dist/exchanges/rate-limiter.js +64 -0
  237. package/dist/exchanges/registry.d.ts +14 -2
  238. package/dist/exchanges/registry.js +20 -32
  239. package/dist/exchanges/slippage.d.ts +37 -0
  240. package/dist/exchanges/slippage.js +70 -0
  241. package/dist/exchanges/spot-factory.d.ts +166 -0
  242. package/dist/exchanges/spot-factory.js +431 -0
  243. package/dist/exchanges/spot-interface.d.ts +98 -4
  244. package/dist/exchanges/spot-interface.js +27 -1
  245. package/dist/exchanges/spot-result.d.ts +79 -0
  246. package/dist/exchanges/spot-result.js +273 -0
  247. package/dist/exchanges/trading-v2.d.ts +117 -0
  248. package/dist/exchanges/trading-v2.js +301 -0
  249. package/dist/exchanges/venue-types.d.ts +231 -0
  250. package/dist/exchanges/venue-types.js +87 -0
  251. package/dist/exchanges/venue.d.ts +211 -0
  252. package/dist/exchanges/venue.js +132 -0
  253. package/dist/exchanges/venues/arcus.d.ts +8 -0
  254. package/dist/exchanges/venues/arcus.js +109 -0
  255. package/dist/exchanges/venues/aster.d.ts +49 -0
  256. package/dist/exchanges/venues/aster.js +176 -0
  257. package/dist/exchanges/venues/create-helpers.d.ts +18 -0
  258. package/dist/exchanges/venues/create-helpers.js +199 -0
  259. package/dist/exchanges/venues/hyperliquid.d.ts +23 -0
  260. package/dist/exchanges/venues/hyperliquid.js +126 -0
  261. package/dist/exchanges/venues/index.d.ts +16 -0
  262. package/dist/exchanges/venues/index.js +26 -0
  263. package/dist/exchanges/venues/lighter-family.d.ts +92 -0
  264. package/dist/exchanges/venues/lighter-family.js +166 -0
  265. package/dist/exchanges/venues/lighter-rh.d.ts +7 -0
  266. package/dist/exchanges/venues/lighter-rh.js +58 -0
  267. package/dist/exchanges/venues/lighter.d.ts +6 -0
  268. package/dist/exchanges/venues/lighter.js +55 -0
  269. package/dist/exchanges/venues/ondo.d.ts +34 -0
  270. package/dist/exchanges/venues/ondo.js +140 -0
  271. package/dist/exchanges/venues/pacifica.d.ts +8 -0
  272. package/dist/exchanges/venues/pacifica.js +95 -0
  273. package/dist/exchanges/venues/qfex.d.ts +28 -0
  274. package/dist/exchanges/venues/qfex.js +132 -0
  275. package/dist/execution-log.js +10 -2
  276. package/dist/funding/legacy-public.d.ts +31 -0
  277. package/dist/funding/legacy-public.js +369 -0
  278. package/dist/funding/normalize.d.ts +28 -16
  279. package/dist/funding/normalize.js +61 -29
  280. package/dist/funding/rates.d.ts +46 -11
  281. package/dist/funding/rates.js +228 -277
  282. package/dist/guardrail/perp-guardrail.js +0 -0
  283. package/dist/index.js +157 -682
  284. package/dist/jobs.d.ts +84 -6
  285. package/dist/jobs.js +239 -41
  286. package/dist/landing.d.ts +14 -0
  287. package/dist/landing.js +36 -0
  288. package/dist/mcp-server.d.ts +14 -4
  289. package/dist/mcp-server.js +820 -402
  290. package/dist/mcp-trade-guard.d.ts +16 -0
  291. package/dist/mcp-trade-guard.js +59 -0
  292. package/dist/pacifica/client.d.ts +41 -10
  293. package/dist/pacifica/client.js +167 -63
  294. package/dist/pacifica/constants.d.ts +0 -1
  295. package/dist/pacifica/constants.js +0 -5
  296. package/dist/pacifica/deposit.d.ts +30 -3
  297. package/dist/pacifica/deposit.js +119 -2
  298. package/dist/pacifica/faucet.d.ts +29 -0
  299. package/dist/pacifica/faucet.js +100 -0
  300. package/dist/pacifica/sign-tx.d.ts +15 -0
  301. package/dist/pacifica/sign-tx.js +41 -0
  302. package/dist/pacifica/types/account.d.ts +28 -4
  303. package/dist/pacifica/types/lake.d.ts +20 -5
  304. package/dist/pacifica/types/lake.js +4 -0
  305. package/dist/pacifica/types/market.d.ts +5 -0
  306. package/dist/pacifica/types/order.d.ts +4 -1
  307. package/dist/pacifica/types/position.d.ts +9 -1
  308. package/dist/plan-executor.d.ts +10 -5
  309. package/dist/plan-executor.js +165 -54
  310. package/dist/position-history.js +13 -0
  311. package/dist/rebalance.d.ts +26 -2
  312. package/dist/rebalance.js +86 -7
  313. package/dist/relay-swap.d.ts +232 -0
  314. package/dist/relay-swap.js +630 -0
  315. package/dist/risk.js +5 -1
  316. package/dist/secret-env.d.ts +15 -0
  317. package/dist/secret-env.js +36 -0
  318. package/dist/settings.d.ts +169 -6
  319. package/dist/settings.js +219 -38
  320. package/dist/signer/ows-evm.d.ts +13 -0
  321. package/dist/signer/ows-evm.js +22 -0
  322. package/dist/smart-order.d.ts +9 -0
  323. package/dist/smart-order.js +53 -8
  324. package/dist/strategies/dca.d.ts +6 -2
  325. package/dist/strategies/dca.js +66 -26
  326. package/dist/strategies/funding-arb.d.ts +11 -1
  327. package/dist/strategies/funding-arb.js +202 -89
  328. package/dist/strategies/grid.d.ts +31 -0
  329. package/dist/strategies/grid.js +89 -11
  330. package/dist/strategies/pending-stop.d.ts +8 -0
  331. package/dist/strategies/pending-stop.js +12 -0
  332. package/dist/strategies/split-order.d.ts +45 -17
  333. package/dist/strategies/split-order.js +157 -91
  334. package/dist/strategies/trailing-stop.d.ts +2 -1
  335. package/dist/strategies/trailing-stop.js +52 -6
  336. package/dist/strategies/twap.d.ts +6 -1
  337. package/dist/strategies/twap.js +39 -11
  338. package/dist/trade-validator.d.ts +22 -0
  339. package/dist/trade-validator.js +119 -15
  340. package/dist/utils/numeric.d.ts +46 -0
  341. package/dist/utils/numeric.js +79 -0
  342. package/dist/utils.d.ts +19 -0
  343. package/dist/utils.js +96 -19
  344. package/dist/withdraw-gate.d.ts +49 -0
  345. package/dist/withdraw-gate.js +131 -0
  346. package/package.json +15 -6
  347. package/skills/perp-cli/SKILL.md +338 -134
  348. package/skills/perp-cli/references/agent-operations.md +181 -92
  349. package/skills/perp-cli/references/commands.md +475 -132
  350. package/skills/perp-cli/references/strategies.md +44 -38
  351. package/skills/perp-cli/scripts/arb-monitor.sh +22 -17
  352. package/skills/perp-cli/scripts/funding-analysis.sh +20 -10
  353. package/skills/perp-cli/scripts/preflight.sh +21 -14
  354. package/skills/perp-cli/scripts/spot-perp-scan.sh +12 -7
  355. package/skills/perp-cli/scripts/validate-arb.sh +33 -16
  356. package/vendor/lighter-signer/SHA256SUMS +2 -0
  357. package/vendor/lighter-signer/VERSION +8 -0
  358. package/vendor/lighter-signer/lighter-signer.wasm +0 -0
  359. package/vendor/lighter-signer/wasm_exec.js +575 -0
  360. package/dist/bot/strategies/funding-arb-v2-strategy.d.ts +0 -42
  361. package/dist/bot/strategies/funding-arb-v2-strategy.js +0 -864
@@ -0,0 +1,123 @@
1
+ export declare const LIGHTER_SIGNER_VERSION = "lighter-go v1.0.9";
2
+ /** sha256 of vendor/lighter-signer/lighter-signer.wasm (= the v1.0.9 release asset digest). */
3
+ export declare const LIGHTER_SIGNER_WASM_SHA256 = "781ba28b5e7fca1ea816f516f28fe2adbe704b734828e0c941025f8133bd7b4b";
4
+ /** sha256 of vendor/lighter-signer/wasm_exec.js (= go1.25.6 lib/wasm/wasm_exec.js). */
5
+ export declare const LIGHTER_SIGNER_WASM_EXEC_SHA256 = "0c949f4996f9a89698e4b5c586de32249c3b69b7baadb64d220073cc04acba14";
6
+ /** Same relative depth from src/exchanges/ and dist/exchanges/ to the package root. */
7
+ export declare function lighterSignerDir(): string;
8
+ /** Result of every Sign* call (wasm-signer.md "Conventions"). */
9
+ export interface LighterSignResult {
10
+ txType: number;
11
+ txInfo: string;
12
+ txHash: string;
13
+ messageToSign?: string;
14
+ error?: string;
15
+ }
16
+ interface Account {
17
+ apiKeyIndex: number;
18
+ accountIndex: number;
19
+ }
20
+ /** cancelAllMarketIndex meaning "all markets" (wasm-signer.md SignCancelAllOrders). */
21
+ export declare const LIGHTER_ALL_MARKETS = 255;
22
+ /**
23
+ * One Go runtime of the official signer. The Go `main` registers its functions on
24
+ * globalThis and then blocks; they are captured synchronously right after `go.run()`
25
+ * and the globals restored, so several runtimes (one per venue+network, design §10.5)
26
+ * never see each other's functions.
27
+ */
28
+ export declare class LighterWasmSigner {
29
+ private readonly fn;
30
+ private constructor();
31
+ /** Load + verify the vendored files and start a fresh runtime. */
32
+ static load(dir?: string): Promise<LighterWasmSigner>;
33
+ private exited;
34
+ private call;
35
+ private tx;
36
+ generateAPIKey(): {
37
+ privateKey: string;
38
+ publicKey: string;
39
+ };
40
+ /** CreateClient(url = "", privateKey, chainId, apiKeyIndex, accountIndex). `url` is ignored (kept for call-site compatibility). */
41
+ createClient(p: {
42
+ url?: string;
43
+ privateKey: string;
44
+ chainId: number;
45
+ } & Account): void;
46
+ /** CreateAuthToken(deadline unix s, apiKeyIndex, accountIndex) → token string. */
47
+ createAuthToken(deadline: number, apiKeyIndex: number, accountIndex: number): string;
48
+ /** SignChangePubKey(pubKeyHex, skipNonce, nonce, apiKeyIndex, accountIndex). */
49
+ signChangePubKey(p: {
50
+ pubkey: string;
51
+ nonce: number;
52
+ } & Account): LighterSignResult;
53
+ /**
54
+ * SignCreateOrder — 19 args. Integrator fields and self-trade modes are 0 (defaults);
55
+ * skipNonce 0. `orderExpiry` −1 = GTT default: now + LIGHTER_GTT_EXPIRY_MS (28 days), resolved here.
56
+ */
57
+ signCreateOrder(p: {
58
+ marketIndex: number;
59
+ clientOrderIndex: number;
60
+ baseAmount: number;
61
+ price: number;
62
+ isAsk: number;
63
+ orderType: number;
64
+ timeInForce: number;
65
+ reduceOnly: number;
66
+ triggerPrice: number;
67
+ orderExpiry: number;
68
+ nonce: number;
69
+ } & Account): LighterSignResult;
70
+ /**
71
+ * SignModifyOrder — 15 args (lighter-go #83): marketIndex, index, baseAmount, price, triggerPrice,
72
+ * 0,0,0 (integrator), 0,0 (self-trade), skipNonce, nonce, orderVersion, apiKeyIndex, accountIndex.
73
+ * `index` = the order's client order index (or order index). orderVersion 0 = unversioned.
74
+ */
75
+ signModifyOrder(p: {
76
+ marketIndex: number;
77
+ index: number;
78
+ baseAmount: number;
79
+ price: number;
80
+ triggerPrice: number;
81
+ nonce: number;
82
+ orderVersion?: number;
83
+ } & Account): LighterSignResult;
84
+ /** SignCancelOrder(marketIndex, orderIndex, skipNonce, nonce, apiKeyIndex, accountIndex). */
85
+ signCancelOrder(p: {
86
+ marketIndex: number;
87
+ orderIndex: number;
88
+ nonce: number;
89
+ } & Account): LighterSignResult;
90
+ /** SignCancelAllOrders(timeInForce, time, cancelAllMarketIndex (255 = all), skipNonce, nonce, apiKeyIndex, accountIndex). */
91
+ signCancelAllOrders(p: {
92
+ timeInForce: number;
93
+ time: number;
94
+ marketIndex?: number;
95
+ nonce: number;
96
+ } & Account): LighterSignResult;
97
+ /** SignUpdateLeverage(marketIndex, fraction, marginMode, skipNonce, nonce, apiKeyIndex, accountIndex). */
98
+ signUpdateLeverage(p: {
99
+ marketIndex: number;
100
+ fraction: number;
101
+ marginMode: number;
102
+ nonce: number;
103
+ } & Account): LighterSignResult;
104
+ /** SignWithdraw(assetIndex, routeType, amount, skipNonce, nonce, apiKeyIndex, accountIndex). `usdcAmount` is already in base units. */
105
+ signWithdraw(p: {
106
+ usdcAmount: number;
107
+ assetIndex: number;
108
+ routeType: number;
109
+ nonce: number;
110
+ } & Account): LighterSignResult;
111
+ /** SignTransfer(toAccountIndex, assetIndex, fromRouteType, toRouteType, amount, usdcFee, memo (32-byte hex), skipNonce, nonce, apiKeyIndex, accountIndex). */
112
+ signTransfer(p: {
113
+ toAccountIndex: number;
114
+ assetIndex: number;
115
+ fromRouteType: number;
116
+ toRouteType: number;
117
+ amount: number;
118
+ usdcFee: number;
119
+ memo: string;
120
+ nonce: number;
121
+ } & Account): LighterSignResult;
122
+ }
123
+ export {};
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Official Lighter WASM signer (lighter-go release v1.0.9), vendored under
3
+ * vendor/lighter-signer/ and loaded directly — no lighter-ts-sdk wrapper.
4
+ *
5
+ * Why: the WASM bundled in lighter-ts-sdk (1.0.10 and 1.1.0) predates lighter-go
6
+ * 8854554 (#89), so it rejects market ids ≥ 4095 ("MarketIndex is not valid") and
7
+ * treats 2048–4094 as spot (reduce-only / trigger / margin refused). Testnet perps
8
+ * are 4095–4097 and Lighter RH testnet perps 2048/2049.
9
+ *
10
+ * Calls follow https://apidocs.lighter.xyz/docs/wasm-signer.md exactly: positional
11
+ * arguments, every one required, `url` = "" in CreateClient (the WASM cannot do
12
+ * HTTP), and an explicit nonce (never -1, which would make the signer fetch it).
13
+ *
14
+ * Integrity: both vendored files are sha256-pinned here and verified at load; a
15
+ * mismatch refuses to load (nothing can be signed).
16
+ */
17
+ import { createHash } from "node:crypto";
18
+ import { readFile } from "node:fs/promises";
19
+ import { fileURLToPath } from "node:url";
20
+ import { PerpError } from "../errors.js";
21
+ import { LIGHTER_GTT_EXPIRY_MS } from "./venues/lighter-family.js";
22
+ export const LIGHTER_SIGNER_VERSION = "lighter-go v1.0.9";
23
+ /** sha256 of vendor/lighter-signer/lighter-signer.wasm (= the v1.0.9 release asset digest). */
24
+ export const LIGHTER_SIGNER_WASM_SHA256 = "781ba28b5e7fca1ea816f516f28fe2adbe704b734828e0c941025f8133bd7b4b";
25
+ /** sha256 of vendor/lighter-signer/wasm_exec.js (= go1.25.6 lib/wasm/wasm_exec.js). */
26
+ export const LIGHTER_SIGNER_WASM_EXEC_SHA256 = "0c949f4996f9a89698e4b5c586de32249c3b69b7baadb64d220073cc04acba14";
27
+ /** Same relative depth from src/exchanges/ and dist/exchanges/ to the package root. */
28
+ export function lighterSignerDir() {
29
+ return fileURLToPath(new URL("../../vendor/lighter-signer/", import.meta.url));
30
+ }
31
+ const EXPORTS = [
32
+ "GenerateAPIKey", "CreateClient", "CreateAuthToken", "SignChangePubKey", "SignCreateOrder",
33
+ "SignModifyOrder", "SignCancelOrder", "SignCancelAllOrders", "SignUpdateLeverage",
34
+ "SignWithdraw", "SignTransfer",
35
+ ];
36
+ /** cancelAllMarketIndex meaning "all markets" (wasm-signer.md SignCancelAllOrders). */
37
+ export const LIGHTER_ALL_MARKETS = 255;
38
+ function sha256(buf) {
39
+ return createHash("sha256").update(buf).digest("hex");
40
+ }
41
+ /** Every numeric argument must be a finite integer: the Go side truncates silently. */
42
+ function int(name, v) {
43
+ if (typeof v !== "number" || !Number.isSafeInteger(v)) {
44
+ throw new PerpError("SIGNATURE_FAILED", `Lighter signer: ${name} must be a safe integer (got ${String(v)})`);
45
+ }
46
+ return v;
47
+ }
48
+ /** Explicit nonce only: -1 would make the WASM fetch it over HTTP, which it cannot do. */
49
+ function nonceArg(v) {
50
+ const n = int("nonce", v);
51
+ if (n < 0)
52
+ throw new PerpError("SIGNATURE_FAILED", `Lighter signer: nonce must be explicit and ≥ 0 (got ${n})`);
53
+ return n;
54
+ }
55
+ /**
56
+ * One Go runtime of the official signer. The Go `main` registers its functions on
57
+ * globalThis and then blocks; they are captured synchronously right after `go.run()`
58
+ * and the globals restored, so several runtimes (one per venue+network, design §10.5)
59
+ * never see each other's functions.
60
+ */
61
+ export class LighterWasmSigner {
62
+ fn;
63
+ constructor(fn) {
64
+ this.fn = fn;
65
+ }
66
+ /** Load + verify the vendored files and start a fresh runtime. */
67
+ static async load(dir = lighterSignerDir()) {
68
+ const [wasm, execJs] = await Promise.all([
69
+ readFile(`${dir}/lighter-signer.wasm`),
70
+ readFile(`${dir}/wasm_exec.js`),
71
+ ]);
72
+ const got = { wasm: sha256(wasm), exec: sha256(execJs) };
73
+ if (got.wasm !== LIGHTER_SIGNER_WASM_SHA256 || got.exec !== LIGHTER_SIGNER_WASM_EXEC_SHA256) {
74
+ throw new PerpError("SIGNATURE_FAILED", `Lighter signer files do not match the pinned ${LIGHTER_SIGNER_VERSION} checksums (lighter-signer.wasm ${got.wasm}, wasm_exec.js ${got.exec}); refusing to load`, {
75
+ remediation: "Reinstall perp-cli; the vendored Lighter signer is corrupted or was modified",
76
+ });
77
+ }
78
+ const g = globalThis;
79
+ // Evaluate the VERIFIED bytes (not a second read of the file); it assigns globalThis.Go.
80
+ const prevGo = g.Go;
81
+ new Function(execJs.toString("utf8"))();
82
+ const Go = g.Go;
83
+ if (prevGo === undefined)
84
+ delete g.Go;
85
+ else
86
+ g.Go = prevGo;
87
+ if (typeof Go !== "function")
88
+ throw new PerpError("SIGNATURE_FAILED", "Lighter signer: wasm_exec.js did not define Go");
89
+ const go = new Go();
90
+ let exitCode = null;
91
+ // Go's default exit only logs; a runtime that exits can no longer sign — record it.
92
+ go.exit = (code) => { exitCode = code; };
93
+ const { instance } = await WebAssembly.instantiate(wasm, go.importObject);
94
+ const saved = new Map(EXPORTS.map(n => [n, g[n]]));
95
+ void go.run(instance).catch(() => { exitCode = exitCode ?? -1; });
96
+ const fn = {};
97
+ for (const n of EXPORTS) {
98
+ const f = g[n];
99
+ if (typeof f !== "function")
100
+ throw new PerpError("SIGNATURE_FAILED", `Lighter signer: WASM did not export ${n}`);
101
+ fn[n] = f;
102
+ }
103
+ for (const [n, v] of saved) {
104
+ if (v === undefined)
105
+ delete g[n];
106
+ else
107
+ g[n] = v;
108
+ }
109
+ const signer = new LighterWasmSigner(fn);
110
+ signer.exited = () => exitCode !== null;
111
+ return signer;
112
+ }
113
+ exited = () => false;
114
+ call(name, args) {
115
+ if (this.exited())
116
+ throw new PerpError("SIGNATURE_FAILED", "Lighter WASM signer runtime has exited");
117
+ const r = this.fn[name](...args);
118
+ if (r === undefined || r === null || typeof r !== "object") {
119
+ throw new PerpError("SIGNATURE_FAILED", `Lighter signer ${name} returned no result`);
120
+ }
121
+ return r;
122
+ }
123
+ tx(name, args) {
124
+ const r = this.call(name, args);
125
+ if (typeof r.error === "string" && r.error !== "") {
126
+ return { txType: NaN, txInfo: "", txHash: "", error: r.error };
127
+ }
128
+ const out = { txType: Number(r.txType), txInfo: String(r.txInfo ?? ""), txHash: String(r.txHash ?? "") };
129
+ if (typeof r.messageToSign === "string")
130
+ out.messageToSign = r.messageToSign;
131
+ return out;
132
+ }
133
+ generateAPIKey() {
134
+ const r = this.call("GenerateAPIKey", []);
135
+ if (typeof r.error === "string")
136
+ throw new PerpError("SIGNATURE_FAILED", `Lighter GenerateAPIKey: ${r.error}`);
137
+ if (typeof r.privateKey !== "string" || typeof r.publicKey !== "string") {
138
+ throw new PerpError("SIGNATURE_FAILED", "Lighter GenerateAPIKey returned no key pair");
139
+ }
140
+ return { privateKey: r.privateKey, publicKey: r.publicKey };
141
+ }
142
+ /** CreateClient(url = "", privateKey, chainId, apiKeyIndex, accountIndex). `url` is ignored (kept for call-site compatibility). */
143
+ createClient(p) {
144
+ const r = this.call("CreateClient", ["", p.privateKey, int("chainId", p.chainId), int("apiKeyIndex", p.apiKeyIndex), int("accountIndex", p.accountIndex)]);
145
+ if (typeof r.error === "string" && r.error !== "")
146
+ throw new PerpError("SIGNATURE_FAILED", `Lighter CreateClient: ${r.error}`);
147
+ }
148
+ /** CreateAuthToken(deadline unix s, apiKeyIndex, accountIndex) → token string. */
149
+ createAuthToken(deadline, apiKeyIndex, accountIndex) {
150
+ const r = this.call("CreateAuthToken", [int("deadline", deadline), int("apiKeyIndex", apiKeyIndex), int("accountIndex", accountIndex)]);
151
+ if (typeof r.error === "string" && r.error !== "")
152
+ throw new PerpError("SIGNATURE_FAILED", `Lighter CreateAuthToken: ${r.error}`);
153
+ if (typeof r.authToken !== "string" || r.authToken === "")
154
+ throw new PerpError("SIGNATURE_FAILED", "Lighter CreateAuthToken returned no token");
155
+ return r.authToken;
156
+ }
157
+ /** SignChangePubKey(pubKeyHex, skipNonce, nonce, apiKeyIndex, accountIndex). */
158
+ signChangePubKey(p) {
159
+ return this.tx("SignChangePubKey", [p.pubkey, 0, nonceArg(p.nonce), int("apiKeyIndex", p.apiKeyIndex), int("accountIndex", p.accountIndex)]);
160
+ }
161
+ /**
162
+ * SignCreateOrder — 19 args. Integrator fields and self-trade modes are 0 (defaults);
163
+ * skipNonce 0. `orderExpiry` −1 = GTT default: now + LIGHTER_GTT_EXPIRY_MS (28 days), resolved here.
164
+ */
165
+ signCreateOrder(p) {
166
+ const expiry = p.orderExpiry === -1 ? Date.now() + LIGHTER_GTT_EXPIRY_MS : int("orderExpiry", p.orderExpiry);
167
+ return this.tx("SignCreateOrder", [
168
+ int("marketIndex", p.marketIndex), int("clientOrderIndex", p.clientOrderIndex), int("baseAmount", p.baseAmount),
169
+ int("price", p.price), int("isAsk", p.isAsk), int("orderType", p.orderType), int("timeInForce", p.timeInForce),
170
+ int("reduceOnly", p.reduceOnly), int("triggerPrice", p.triggerPrice), expiry,
171
+ 0, 0, 0, // integratorAccountIndex, integratorTakerFee, integratorMakerFee
172
+ 0, 0, // selfTradeBehaviorMode, selfTradeEqualityMode
173
+ 0, nonceArg(p.nonce), int("apiKeyIndex", p.apiKeyIndex), int("accountIndex", p.accountIndex),
174
+ ]);
175
+ }
176
+ /**
177
+ * SignModifyOrder — 15 args (lighter-go #83): marketIndex, index, baseAmount, price, triggerPrice,
178
+ * 0,0,0 (integrator), 0,0 (self-trade), skipNonce, nonce, orderVersion, apiKeyIndex, accountIndex.
179
+ * `index` = the order's client order index (or order index). orderVersion 0 = unversioned.
180
+ */
181
+ signModifyOrder(p) {
182
+ return this.tx("SignModifyOrder", [
183
+ int("marketIndex", p.marketIndex), int("index", p.index), int("baseAmount", p.baseAmount), int("price", p.price),
184
+ int("triggerPrice", p.triggerPrice), 0, 0, 0, 0, 0, 0, nonceArg(p.nonce), int("orderVersion", p.orderVersion ?? 0),
185
+ int("apiKeyIndex", p.apiKeyIndex), int("accountIndex", p.accountIndex),
186
+ ]);
187
+ }
188
+ /** SignCancelOrder(marketIndex, orderIndex, skipNonce, nonce, apiKeyIndex, accountIndex). */
189
+ signCancelOrder(p) {
190
+ return this.tx("SignCancelOrder", [int("marketIndex", p.marketIndex), int("orderIndex", p.orderIndex), 0, nonceArg(p.nonce), int("apiKeyIndex", p.apiKeyIndex), int("accountIndex", p.accountIndex)]);
191
+ }
192
+ /** SignCancelAllOrders(timeInForce, time, cancelAllMarketIndex (255 = all), skipNonce, nonce, apiKeyIndex, accountIndex). */
193
+ signCancelAllOrders(p) {
194
+ return this.tx("SignCancelAllOrders", [
195
+ int("timeInForce", p.timeInForce), int("time", p.time), int("cancelAllMarketIndex", p.marketIndex ?? LIGHTER_ALL_MARKETS),
196
+ 0, nonceArg(p.nonce), int("apiKeyIndex", p.apiKeyIndex), int("accountIndex", p.accountIndex),
197
+ ]);
198
+ }
199
+ /** SignUpdateLeverage(marketIndex, fraction, marginMode, skipNonce, nonce, apiKeyIndex, accountIndex). */
200
+ signUpdateLeverage(p) {
201
+ return this.tx("SignUpdateLeverage", [int("marketIndex", p.marketIndex), int("fraction", p.fraction), int("marginMode", p.marginMode), 0, nonceArg(p.nonce), int("apiKeyIndex", p.apiKeyIndex), int("accountIndex", p.accountIndex)]);
202
+ }
203
+ /** SignWithdraw(assetIndex, routeType, amount, skipNonce, nonce, apiKeyIndex, accountIndex). `usdcAmount` is already in base units. */
204
+ signWithdraw(p) {
205
+ return this.tx("SignWithdraw", [int("assetIndex", p.assetIndex), int("routeType", p.routeType), int("amount", p.usdcAmount), 0, nonceArg(p.nonce), int("apiKeyIndex", p.apiKeyIndex), int("accountIndex", p.accountIndex)]);
206
+ }
207
+ /** SignTransfer(toAccountIndex, assetIndex, fromRouteType, toRouteType, amount, usdcFee, memo (32-byte hex), skipNonce, nonce, apiKeyIndex, accountIndex). */
208
+ signTransfer(p) {
209
+ return this.tx("SignTransfer", [
210
+ int("toAccountIndex", p.toAccountIndex), int("assetIndex", p.assetIndex), int("fromRouteType", p.fromRouteType),
211
+ int("toRouteType", p.toRouteType), int("amount", p.amount), int("usdcFee", p.usdcFee), p.memo,
212
+ 0, nonceArg(p.nonce), int("apiKeyIndex", p.apiKeyIndex), int("accountIndex", p.accountIndex),
213
+ ]);
214
+ }
215
+ }
@@ -6,10 +6,17 @@
6
6
  *
7
7
  * Composes with LighterAdapter for signing and API access.
8
8
  */
9
- import type { SpotAdapter, SpotMarketInfo, SpotBalance } from "./spot-interface.js";
9
+ import { type SpotAdapter, type SpotMarketInfo, type SpotBalance } from "./spot-interface.js";
10
+ import type { ResolvedSlippage } from "./slippage.js";
10
11
  import type { LighterAdapter } from "./lighter.js";
12
+ /**
13
+ * `venueRaw.fillSource` of a spot IOC fill read from the order's accountOrders row
14
+ * (`filled_base_amount`, the venue's own field — never size − remaining).
15
+ */
16
+ export declare const ACCOUNT_ORDERS_FILL_SOURCE = "account-orders";
11
17
  export declare class LighterSpotAdapter implements SpotAdapter {
12
- readonly name = "lighter";
18
+ /** Venue id of the wrapped LighterAdapter ("lighter" | "lighter-rh"). */
19
+ readonly name: string;
13
20
  private _lt;
14
21
  private _spotMarketMap;
15
22
  private _spotBaseMap;
@@ -17,8 +24,9 @@ export declare class LighterSpotAdapter implements SpotAdapter {
17
24
  private _spotMinSize;
18
25
  private _spotPrices;
19
26
  private _initialized;
20
- private _clientOrderCounter;
21
27
  constructor(ltAdapter: LighterAdapter);
28
+ /** Quote/collateral symbol of the wrapped venue ("USDC" on Lighter, "USDG" on Lighter RH). */
29
+ private get _quote();
22
30
  init(): Promise<void>;
23
31
  private _loadSpotMarkets;
24
32
  /** Resolve a symbol (e.g., "ETH" or "ETH/USDC") to the full spot symbol */
@@ -30,44 +38,114 @@ export declare class LighterSpotAdapter implements SpotAdapter {
30
38
  bids: [string, string][];
31
39
  asks: [string, string][];
32
40
  }>;
41
+ /**
42
+ * Spot token balances. Reads the account through the shared 15s `acct:` cache
43
+ * (same entry as LighterAdapter.fetchAccount()). Throws on any failure — never []
44
+ * (Rule #2: an empty list is indistinguishable from an empty wallet).
45
+ * Fill measurement / post-trade verification must use getSpotBalancesFresh().
46
+ */
33
47
  getSpotBalances(): Promise<SpotBalance[]>;
34
- spotMarketOrder(symbol: string, side: "buy" | "sell", size: string): Promise<unknown>;
48
+ /** Uncached read (always hits /account, then refreshes the shared cache entry). */
49
+ getSpotBalancesFresh(): Promise<SpotBalance[]>;
50
+ private _spotBalances;
51
+ spotMarketOrder(symbol: string, side: "buy" | "sell", size: string, opts: {
52
+ slippage: ResolvedSlippage;
53
+ }): Promise<unknown>;
54
+ /** Poll /tx by hash (lighterTxState): rejected → ORDER_REJECTED; returns the last state + raw tx. */
55
+ private _awaitTx;
56
+ /**
57
+ * Final IOC outcome of a sent spot order (market or limit IOC) — see spotMarketOrder. Returns
58
+ * a final SpotOrderResult, throws ORDER_REJECTED for a zero fill, or null when neither /tx nor
59
+ * accountOrders settled it.
60
+ */
61
+ private _iocOutcome;
62
+ /** Pre-send part of spotMarketOrder: market, min size, reference price, ticks. */
63
+ private _prepareMarketOrder;
64
+ /**
65
+ * Final IOC fill of a spotMarketOrder / IOC spotLimitOrder result (SpotOrderResult read from
66
+ * the tx event_info or the accountOrders row), or null when the outcome is unknown (raw sendTx
67
+ * result → balance delta).
68
+ */
69
+ iocOutcomeOf(raw: unknown): {
70
+ filledSize: string;
71
+ final: true;
72
+ } | null;
35
73
  spotLimitOrder(symbol: string, side: "buy" | "sell", price: string, size: string, opts?: {
36
74
  tif?: string;
37
75
  }): Promise<unknown>;
76
+ /**
77
+ * TIF mapping, as perps (§13.3): GTC/GTT → GTT, IOC → IOC, ALO / POST_ONLY → post-only (2).
78
+ * FOK and anything else → CAPABILITY_UNSUPPORTED (never silently GTT).
79
+ */
80
+ private _limitTif;
81
+ /**
82
+ * Final placement outcome of a resting (GTT / post-only) spot limit, as perps
83
+ * (LighterAdapter.resolveOrderOutcome): /tx rejected → ORDER_REJECTED; the executed tx's
84
+ * event_info taker order (this client order index) "filled" → filled; otherwise the order's
85
+ * accountOrders row by client order index (status + filled_base_amount: open, filled,
86
+ * canceled-* — e.g. a crossing post-only). Unresolved → null (pending).
87
+ */
88
+ private _placementOutcome;
38
89
  spotCancelOrder(symbol: string, orderId: string): Promise<unknown>;
39
- /** Cancel all orders across all markets (spot + perp) */
40
- spotCancelAllOrders(_symbol?: string): Promise<unknown>;
90
+ /**
91
+ * Venue-final outcome of a sent spot cancel, as perps (awaitTxExecuted + cancelOutcome): /tx
92
+ * rejected → ORDER_REJECTED (the order is untouched). Then the order's own row — by client
93
+ * order index (accountOrders), else by order id among the market's active, then latest 100
94
+ * inactive orders: canceled-* → cancelled (a fill before the cancel → partial, filledSize from
95
+ * filled_base_amount), filled → filled (it filled before the cancel landed). Still open / not
96
+ * readable after a few reads → finality "pending" (do NOT resubmit).
97
+ */
98
+ private _cancelOutcome;
99
+ /** The order's venue row: accountOrders by client order index, else active → latest 100 inactive by order id; not listed → null. */
100
+ private _orderRow;
101
+ /**
102
+ * Cancel the SPOT open orders (of `symbol`, or of every spot market) one by one. Never the
103
+ * account-wide CancelAllOrders tx (market 255): it would also cancel the account's perp orders.
104
+ */
105
+ spotCancelAllOrders(symbol?: string | null): Promise<unknown>;
41
106
  /** Transfer USDC from perp account to spot account (required before spot buys) */
42
107
  transferUsdcToSpot(amount: number): Promise<unknown>;
43
108
  /** Transfer USDC from spot account back to perp account */
44
109
  transferUsdcToPerp(amount: number): Promise<unknown>;
110
+ /** SpotTransferCapable (§12.4 #4): only the venue collateral (USDC on Lighter, USDG on Lighter RH). */
111
+ transferToSpot(amount: string, asset: string): Promise<unknown>;
112
+ transferToPerp(amount: string, asset: string): Promise<unknown>;
113
+ private _transferAmount;
45
114
  /**
46
- * Internal self-transfer using raw WASM signTransfer.
47
- * TS SDK's is_spot_account mapping is buggy (sets both fromRoute and toRoute
48
- * to the same value), so we call the WASM module directly with explicit routes.
49
- * Route types: 0 = Perp, 1 = Spot
115
+ * Internal self-transfer (same account, perp ↔ spot route) signed with the official
116
+ * WASM SignTransfer and explicit routes. Route types: 0 = Perp, 1 = Spot. Same-owner
117
+ * transfer → no L1 signature needed (wasm-signer.md).
50
118
  */
51
119
  private _selfTransfer;
52
120
  /** Get the spot market ID for a symbol */
53
121
  getSpotMarketId(symbol: string): number | undefined;
54
122
  /** Check if a base token has a spot market */
55
123
  hasSpotMarket(base: string): boolean;
56
- /** Query open orders across all spot markets (market_id ≥ 2048). */
57
- getSpotOpenOrders(): Promise<Array<{
124
+ /** Query open orders across all spot markets (the market_type "spot" markets loaded at init). */
125
+ getSpotOpenOrders(symbol?: string | null): Promise<Array<{
58
126
  orderId: string;
59
127
  symbol: string;
60
128
  side: "buy" | "sell";
61
129
  price: string;
62
130
  size: string;
131
+ filled: string;
63
132
  clientOrderIndex?: number;
64
133
  }>>;
65
134
  /** Cancel a spot order by clientOrderIndex (safe integer, avoids order_id overflow). */
66
135
  spotCancelByClientIndex(symbol: string, clientOrderIndex: number): Promise<unknown>;
67
136
  private _placeOrder;
68
- /** Generate a unique client order index (uint48). Uses timestamp + counter. */
137
+ private _signOrder;
138
+ /** Generated client order index (uint48): ms timestamp + random bits — see lighterGeneratedClientOrderIndex. */
69
139
  private _nextClientOrderIndex;
70
140
  private _getNextNonce;
141
+ /**
142
+ * POST /sendTx. `kind` "place" (order placement): failures are typed (design
143
+ * §12.3): before the request → ORDER_REJECTED; transport error, HTTP 5xx or an
144
+ * unreadable body after it → ORDER_PENDING (the tx may have been accepted — never
145
+ * resubmit); an explicit non-200 code → ORDER_REJECTED. "order" (cancels) / "action"
146
+ * (transfers): an explicit non-200 code → ORDER_REJECTED / ACTION_REJECTED
147
+ * (lighterSendTxRejection — validated and refused before execution).
148
+ */
71
149
  private _sendTx;
72
150
  private _restGet;
73
151
  private _restGetAuth;