@lifi/perps-types 0.2.0-alpha.0 → 1.0.1

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 (328) hide show
  1. package/README.md +4 -30
  2. package/dist/cjs/acceptTerms.d.ts +20 -0
  3. package/dist/cjs/acceptTerms.d.ts.map +1 -0
  4. package/dist/cjs/acceptTerms.js +10 -0
  5. package/dist/cjs/acceptTerms.js.map +1 -0
  6. package/dist/cjs/account.d.ts +191 -0
  7. package/dist/cjs/account.d.ts.map +1 -0
  8. package/{src/_esm → dist/cjs}/account.js.map +1 -1
  9. package/dist/cjs/action.d.ts +200 -0
  10. package/dist/cjs/action.d.ts.map +1 -0
  11. package/dist/cjs/action.js.map +1 -0
  12. package/dist/cjs/asset.d.ts +11 -0
  13. package/dist/cjs/asset.d.ts.map +1 -0
  14. package/dist/cjs/asset.js.map +1 -0
  15. package/{src/_types → dist/cjs}/enums.d.ts +6 -12
  16. package/dist/cjs/enums.d.ts.map +1 -0
  17. package/{src/_cjs → dist/cjs}/enums.js +4 -0
  18. package/dist/cjs/enums.js.map +1 -0
  19. package/dist/cjs/errors.d.ts.map +1 -0
  20. package/dist/cjs/errors.js.map +1 -0
  21. package/{src/_types → dist/cjs}/index.d.ts +11 -5
  22. package/dist/cjs/index.d.ts.map +1 -0
  23. package/{src/_cjs → dist/cjs}/index.js +11 -5
  24. package/dist/cjs/index.js.map +1 -0
  25. package/{src/_types/asset.d.ts → dist/cjs/market.d.ts} +33 -25
  26. package/dist/cjs/market.d.ts.map +1 -0
  27. package/dist/cjs/market.js +3 -0
  28. package/dist/cjs/market.js.map +1 -0
  29. package/dist/cjs/meta.d.ts +17 -0
  30. package/dist/cjs/meta.d.ts.map +1 -0
  31. package/dist/cjs/meta.js +3 -0
  32. package/dist/cjs/meta.js.map +1 -0
  33. package/dist/cjs/primitives.d.ts +3 -0
  34. package/dist/cjs/primitives.d.ts.map +1 -0
  35. package/dist/cjs/primitives.js +3 -0
  36. package/dist/cjs/primitives.js.map +1 -0
  37. package/dist/cjs/providers.d.ts +58 -0
  38. package/dist/cjs/providers.d.ts.map +1 -0
  39. package/{src/_cjs → dist/cjs}/providers.js.map +1 -1
  40. package/dist/cjs/quote.d.ts +23 -0
  41. package/dist/cjs/quote.d.ts.map +1 -0
  42. package/dist/cjs/quote.js +3 -0
  43. package/dist/cjs/quote.js.map +1 -0
  44. package/{src/_types → dist/cjs}/subscriptions.d.ts +14 -13
  45. package/dist/cjs/subscriptions.d.ts.map +1 -0
  46. package/{src/_cjs → dist/cjs}/subscriptions.js.map +1 -1
  47. package/dist/cjs/typedData.d.ts +23 -0
  48. package/dist/cjs/typedData.d.ts.map +1 -0
  49. package/{src/_cjs → dist/cjs}/typedData.js.map +1 -1
  50. package/dist/cjs/vote.d.ts +27 -0
  51. package/dist/cjs/vote.d.ts.map +1 -0
  52. package/dist/cjs/vote.js +12 -0
  53. package/dist/cjs/vote.js.map +1 -0
  54. package/dist/esm/acceptTerms.d.ts +45 -0
  55. package/dist/esm/acceptTerms.d.ts.map +1 -0
  56. package/dist/esm/acceptTerms.js +12 -0
  57. package/dist/esm/acceptTerms.js.map +1 -0
  58. package/dist/esm/account.d.ts +229 -0
  59. package/dist/esm/account.d.ts.map +1 -0
  60. package/{src/_cjs → dist/esm}/account.js.map +1 -1
  61. package/{src/_types → dist/esm}/action.d.ts +56 -69
  62. package/dist/esm/action.d.ts.map +1 -0
  63. package/dist/esm/action.js +2 -0
  64. package/dist/esm/action.js.map +1 -0
  65. package/dist/esm/asset.d.ts +25 -0
  66. package/dist/esm/asset.d.ts.map +1 -0
  67. package/dist/esm/asset.js.map +1 -0
  68. package/dist/esm/enums.d.ts +171 -0
  69. package/dist/esm/enums.d.ts.map +1 -0
  70. package/{src/_esm → dist/esm}/enums.js +26 -10
  71. package/dist/esm/enums.js.map +1 -0
  72. package/dist/esm/errors.d.ts +8 -0
  73. package/dist/esm/errors.d.ts.map +1 -0
  74. package/dist/esm/errors.js.map +1 -0
  75. package/dist/esm/index.d.ts +23 -0
  76. package/dist/esm/index.d.ts.map +1 -0
  77. package/dist/esm/index.js +23 -0
  78. package/dist/esm/index.js.map +1 -0
  79. package/dist/esm/market.d.ts +107 -0
  80. package/dist/esm/market.d.ts.map +1 -0
  81. package/dist/esm/market.js +2 -0
  82. package/dist/esm/market.js.map +1 -0
  83. package/dist/esm/meta.d.ts +37 -0
  84. package/dist/esm/meta.d.ts.map +1 -0
  85. package/dist/esm/meta.js +2 -0
  86. package/dist/esm/meta.js.map +1 -0
  87. package/dist/esm/primitives.d.ts +5 -0
  88. package/dist/esm/primitives.d.ts.map +1 -0
  89. package/dist/esm/primitives.js +2 -0
  90. package/dist/esm/primitives.js.map +1 -0
  91. package/dist/esm/providers.d.ts +116 -0
  92. package/dist/esm/providers.d.ts.map +1 -0
  93. package/{src/_esm → dist/esm}/providers.js.map +1 -1
  94. package/dist/esm/quote.d.ts +47 -0
  95. package/dist/esm/quote.d.ts.map +1 -0
  96. package/dist/esm/quote.js +2 -0
  97. package/dist/esm/quote.js.map +1 -0
  98. package/dist/esm/subscriptions.d.ts +115 -0
  99. package/dist/esm/subscriptions.d.ts.map +1 -0
  100. package/{src/_esm → dist/esm}/subscriptions.js.map +1 -1
  101. package/dist/esm/typedData.d.ts +28 -0
  102. package/dist/esm/typedData.d.ts.map +1 -0
  103. package/{src/_esm → dist/esm}/typedData.js.map +1 -1
  104. package/dist/esm/vote.d.ts +68 -0
  105. package/dist/esm/vote.d.ts.map +1 -0
  106. package/dist/esm/vote.js +20 -0
  107. package/dist/esm/vote.js.map +1 -0
  108. package/dist/types/acceptTerms.d.ts +45 -0
  109. package/dist/types/acceptTerms.d.ts.map +1 -0
  110. package/dist/types/account.d.ts +229 -0
  111. package/dist/types/account.d.ts.map +1 -0
  112. package/dist/types/action.d.ts +248 -0
  113. package/dist/types/action.d.ts.map +1 -0
  114. package/dist/types/asset.d.ts +25 -0
  115. package/dist/types/asset.d.ts.map +1 -0
  116. package/dist/types/enums.d.ts +171 -0
  117. package/dist/types/enums.d.ts.map +1 -0
  118. package/dist/types/errors.d.ts +8 -0
  119. package/dist/types/errors.d.ts.map +1 -0
  120. package/dist/types/index.d.ts +23 -0
  121. package/dist/types/index.d.ts.map +1 -0
  122. package/dist/types/market.d.ts +107 -0
  123. package/dist/types/market.d.ts.map +1 -0
  124. package/dist/types/meta.d.ts +37 -0
  125. package/dist/types/meta.d.ts.map +1 -0
  126. package/dist/types/primitives.d.ts +5 -0
  127. package/dist/types/primitives.d.ts.map +1 -0
  128. package/dist/types/providers.d.ts +116 -0
  129. package/dist/types/providers.d.ts.map +1 -0
  130. package/dist/types/quote.d.ts +47 -0
  131. package/dist/types/quote.d.ts.map +1 -0
  132. package/dist/types/subscriptions.d.ts +115 -0
  133. package/dist/types/subscriptions.d.ts.map +1 -0
  134. package/dist/types/typedData.d.ts +28 -0
  135. package/dist/types/typedData.d.ts.map +1 -0
  136. package/dist/types/vote.d.ts +68 -0
  137. package/dist/types/vote.d.ts.map +1 -0
  138. package/package.json +37 -65
  139. package/src/acceptTerms.ts +53 -0
  140. package/src/account.ts +74 -111
  141. package/src/action.ts +64 -96
  142. package/src/asset.ts +19 -82
  143. package/src/enums.ts +27 -10
  144. package/src/errors.ts +1 -0
  145. package/src/index.ts +20 -5
  146. package/src/market.ts +137 -0
  147. package/src/meta.ts +38 -0
  148. package/src/primitives.ts +5 -0
  149. package/src/providers.ts +79 -110
  150. package/src/quote.ts +49 -0
  151. package/src/subscriptions.ts +62 -18
  152. package/src/typedData.ts +20 -11
  153. package/src/vote.ts +79 -0
  154. package/providers/hyperliquid/package.json +0 -5
  155. package/providers/lighter/package.json +0 -5
  156. package/src/_cjs/action.js.map +0 -1
  157. package/src/_cjs/asset.js.map +0 -1
  158. package/src/_cjs/enums.js.map +0 -1
  159. package/src/_cjs/errors.js.map +0 -1
  160. package/src/_cjs/index.js.map +0 -1
  161. package/src/_cjs/providers/_shared/fillClassification.js +0 -37
  162. package/src/_cjs/providers/_shared/fillClassification.js.map +0 -1
  163. package/src/_cjs/providers/hyperliquid/assetId.js +0 -21
  164. package/src/_cjs/providers/hyperliquid/assetId.js.map +0 -1
  165. package/src/_cjs/providers/hyperliquid/index.js +0 -20
  166. package/src/_cjs/providers/hyperliquid/index.js.map +0 -1
  167. package/src/_cjs/providers/hyperliquid/mappers/_market.js +0 -15
  168. package/src/_cjs/providers/hyperliquid/mappers/_market.js.map +0 -1
  169. package/src/_cjs/providers/hyperliquid/mappers/activity.js +0 -128
  170. package/src/_cjs/providers/hyperliquid/mappers/activity.js.map +0 -1
  171. package/src/_cjs/providers/hyperliquid/mappers/asset.js +0 -29
  172. package/src/_cjs/providers/hyperliquid/mappers/asset.js.map +0 -1
  173. package/src/_cjs/providers/hyperliquid/mappers/fill.js +0 -36
  174. package/src/_cjs/providers/hyperliquid/mappers/fill.js.map +0 -1
  175. package/src/_cjs/providers/hyperliquid/mappers/index.js +0 -20
  176. package/src/_cjs/providers/hyperliquid/mappers/index.js.map +0 -1
  177. package/src/_cjs/providers/hyperliquid/mappers/order.js +0 -153
  178. package/src/_cjs/providers/hyperliquid/mappers/order.js.map +0 -1
  179. package/src/_cjs/providers/hyperliquid/mappers/position.js +0 -32
  180. package/src/_cjs/providers/hyperliquid/mappers/position.js.map +0 -1
  181. package/src/_cjs/providers/hyperliquid/mappers/shared.js +0 -2
  182. package/src/_cjs/providers/hyperliquid/mappers/shared.js.map +0 -1
  183. package/src/_cjs/providers/hyperliquid/types.js +0 -21
  184. package/src/_cjs/providers/hyperliquid/types.js.map +0 -1
  185. package/src/_cjs/providers/lighter/apiTypes.js +0 -3
  186. package/src/_cjs/providers/lighter/apiTypes.js.map +0 -1
  187. package/src/_cjs/providers/lighter/index.js +0 -20
  188. package/src/_cjs/providers/lighter/index.js.map +0 -1
  189. package/src/_cjs/providers/lighter/mappers/fill.js +0 -34
  190. package/src/_cjs/providers/lighter/mappers/fill.js.map +0 -1
  191. package/src/_cjs/providers/lighter/mappers/index.js +0 -13
  192. package/src/_cjs/providers/lighter/mappers/index.js.map +0 -1
  193. package/src/_cjs/providers/lighter/mappers/order.js +0 -142
  194. package/src/_cjs/providers/lighter/mappers/order.js.map +0 -1
  195. package/src/_cjs/providers/lighter/mappers/position.js +0 -35
  196. package/src/_cjs/providers/lighter/mappers/position.js.map +0 -1
  197. package/src/_cjs/providers/lighter/types.js +0 -23
  198. package/src/_cjs/providers/lighter/types.js.map +0 -1
  199. package/src/_esm/action.js +0 -2
  200. package/src/_esm/action.js.map +0 -1
  201. package/src/_esm/asset.js.map +0 -1
  202. package/src/_esm/enums.js.map +0 -1
  203. package/src/_esm/errors.js.map +0 -1
  204. package/src/_esm/index.js +0 -9
  205. package/src/_esm/index.js.map +0 -1
  206. package/src/_esm/providers/_shared/fillClassification.js +0 -43
  207. package/src/_esm/providers/_shared/fillClassification.js.map +0 -1
  208. package/src/_esm/providers/hyperliquid/assetId.js +0 -25
  209. package/src/_esm/providers/hyperliquid/assetId.js.map +0 -1
  210. package/src/_esm/providers/hyperliquid/index.js +0 -4
  211. package/src/_esm/providers/hyperliquid/index.js.map +0 -1
  212. package/src/_esm/providers/hyperliquid/mappers/_market.js +0 -22
  213. package/src/_esm/providers/hyperliquid/mappers/_market.js.map +0 -1
  214. package/src/_esm/providers/hyperliquid/mappers/activity.js +0 -138
  215. package/src/_esm/providers/hyperliquid/mappers/activity.js.map +0 -1
  216. package/src/_esm/providers/hyperliquid/mappers/asset.js +0 -25
  217. package/src/_esm/providers/hyperliquid/mappers/asset.js.map +0 -1
  218. package/src/_esm/providers/hyperliquid/mappers/fill.js +0 -32
  219. package/src/_esm/providers/hyperliquid/mappers/fill.js.map +0 -1
  220. package/src/_esm/providers/hyperliquid/mappers/index.js +0 -6
  221. package/src/_esm/providers/hyperliquid/mappers/index.js.map +0 -1
  222. package/src/_esm/providers/hyperliquid/mappers/order.js +0 -151
  223. package/src/_esm/providers/hyperliquid/mappers/order.js.map +0 -1
  224. package/src/_esm/providers/hyperliquid/mappers/position.js +0 -28
  225. package/src/_esm/providers/hyperliquid/mappers/position.js.map +0 -1
  226. package/src/_esm/providers/hyperliquid/mappers/shared.js +0 -2
  227. package/src/_esm/providers/hyperliquid/mappers/shared.js.map +0 -1
  228. package/src/_esm/providers/hyperliquid/types.js +0 -35
  229. package/src/_esm/providers/hyperliquid/types.js.map +0 -1
  230. package/src/_esm/providers/lighter/apiTypes.js +0 -5
  231. package/src/_esm/providers/lighter/apiTypes.js.map +0 -1
  232. package/src/_esm/providers/lighter/index.js +0 -4
  233. package/src/_esm/providers/lighter/index.js.map +0 -1
  234. package/src/_esm/providers/lighter/mappers/fill.js +0 -39
  235. package/src/_esm/providers/lighter/mappers/fill.js.map +0 -1
  236. package/src/_esm/providers/lighter/mappers/index.js +0 -4
  237. package/src/_esm/providers/lighter/mappers/index.js.map +0 -1
  238. package/src/_esm/providers/lighter/mappers/order.js +0 -162
  239. package/src/_esm/providers/lighter/mappers/order.js.map +0 -1
  240. package/src/_esm/providers/lighter/mappers/position.js +0 -38
  241. package/src/_esm/providers/lighter/mappers/position.js.map +0 -1
  242. package/src/_esm/providers/lighter/types.js +0 -26
  243. package/src/_esm/providers/lighter/types.js.map +0 -1
  244. package/src/_types/account.d.ts +0 -268
  245. package/src/_types/account.d.ts.map +0 -1
  246. package/src/_types/action.d.ts.map +0 -1
  247. package/src/_types/asset.d.ts.map +0 -1
  248. package/src/_types/enums.d.ts.map +0 -1
  249. package/src/_types/errors.d.ts.map +0 -1
  250. package/src/_types/index.d.ts.map +0 -1
  251. package/src/_types/providers/_shared/fillClassification.d.ts +0 -12
  252. package/src/_types/providers/_shared/fillClassification.d.ts.map +0 -1
  253. package/src/_types/providers/hyperliquid/assetId.d.ts +0 -14
  254. package/src/_types/providers/hyperliquid/assetId.d.ts.map +0 -1
  255. package/src/_types/providers/hyperliquid/index.d.ts +0 -4
  256. package/src/_types/providers/hyperliquid/index.d.ts.map +0 -1
  257. package/src/_types/providers/hyperliquid/mappers/_market.d.ts +0 -13
  258. package/src/_types/providers/hyperliquid/mappers/_market.d.ts.map +0 -1
  259. package/src/_types/providers/hyperliquid/mappers/activity.d.ts +0 -13
  260. package/src/_types/providers/hyperliquid/mappers/activity.d.ts.map +0 -1
  261. package/src/_types/providers/hyperliquid/mappers/asset.d.ts +0 -4
  262. package/src/_types/providers/hyperliquid/mappers/asset.d.ts.map +0 -1
  263. package/src/_types/providers/hyperliquid/mappers/fill.d.ts +0 -6
  264. package/src/_types/providers/hyperliquid/mappers/fill.d.ts.map +0 -1
  265. package/src/_types/providers/hyperliquid/mappers/index.d.ts +0 -6
  266. package/src/_types/providers/hyperliquid/mappers/index.d.ts.map +0 -1
  267. package/src/_types/providers/hyperliquid/mappers/order.d.ts +0 -18
  268. package/src/_types/providers/hyperliquid/mappers/order.d.ts.map +0 -1
  269. package/src/_types/providers/hyperliquid/mappers/position.d.ts +0 -4
  270. package/src/_types/providers/hyperliquid/mappers/position.d.ts.map +0 -1
  271. package/src/_types/providers/hyperliquid/mappers/shared.d.ts +0 -1
  272. package/src/_types/providers/hyperliquid/mappers/shared.d.ts.map +0 -1
  273. package/src/_types/providers/hyperliquid/types.d.ts +0 -289
  274. package/src/_types/providers/hyperliquid/types.d.ts.map +0 -1
  275. package/src/_types/providers/lighter/apiTypes.d.ts +0 -76
  276. package/src/_types/providers/lighter/apiTypes.d.ts.map +0 -1
  277. package/src/_types/providers/lighter/index.d.ts +0 -4
  278. package/src/_types/providers/lighter/index.d.ts.map +0 -1
  279. package/src/_types/providers/lighter/mappers/fill.d.ts +0 -9
  280. package/src/_types/providers/lighter/mappers/fill.d.ts.map +0 -1
  281. package/src/_types/providers/lighter/mappers/index.d.ts +0 -4
  282. package/src/_types/providers/lighter/mappers/index.d.ts.map +0 -1
  283. package/src/_types/providers/lighter/mappers/order.d.ts +0 -35
  284. package/src/_types/providers/lighter/mappers/order.d.ts.map +0 -1
  285. package/src/_types/providers/lighter/mappers/position.d.ts +0 -8
  286. package/src/_types/providers/lighter/mappers/position.d.ts.map +0 -1
  287. package/src/_types/providers/lighter/types.d.ts +0 -90
  288. package/src/_types/providers/lighter/types.d.ts.map +0 -1
  289. package/src/_types/providers.d.ts +0 -145
  290. package/src/_types/providers.d.ts.map +0 -1
  291. package/src/_types/subscriptions.d.ts.map +0 -1
  292. package/src/_types/typedData.d.ts +0 -18
  293. package/src/_types/typedData.d.ts.map +0 -1
  294. package/src/providers/_shared/fillClassification.ts +0 -50
  295. package/src/providers/hyperliquid/assetId.ts +0 -32
  296. package/src/providers/hyperliquid/index.ts +0 -3
  297. package/src/providers/hyperliquid/mappers/_market.ts +0 -21
  298. package/src/providers/hyperliquid/mappers/activity.ts +0 -169
  299. package/src/providers/hyperliquid/mappers/asset.ts +0 -33
  300. package/src/providers/hyperliquid/mappers/fill.ts +0 -41
  301. package/src/providers/hyperliquid/mappers/index.ts +0 -11
  302. package/src/providers/hyperliquid/mappers/order.ts +0 -169
  303. package/src/providers/hyperliquid/mappers/position.ts +0 -33
  304. package/src/providers/hyperliquid/mappers/shared.ts +0 -0
  305. package/src/providers/hyperliquid/types.ts +0 -379
  306. package/src/providers/lighter/apiTypes.ts +0 -87
  307. package/src/providers/lighter/index.ts +0 -3
  308. package/src/providers/lighter/mappers/fill.ts +0 -57
  309. package/src/providers/lighter/mappers/index.ts +0 -8
  310. package/src/providers/lighter/mappers/order.ts +0 -184
  311. package/src/providers/lighter/mappers/position.ts +0 -46
  312. package/src/providers/lighter/types.ts +0 -111
  313. /package/{src/_cjs → dist/cjs}/account.js +0 -0
  314. /package/{src/_cjs → dist/cjs}/action.js +0 -0
  315. /package/{src/_cjs → dist/cjs}/asset.js +0 -0
  316. /package/{src/_types → dist/cjs}/errors.d.ts +0 -0
  317. /package/{src/_cjs → dist/cjs}/errors.js +0 -0
  318. /package/{src/_cjs → dist/cjs}/package.json +0 -0
  319. /package/{src/_cjs → dist/cjs}/providers.js +0 -0
  320. /package/{src/_cjs → dist/cjs}/subscriptions.js +0 -0
  321. /package/{src/_cjs → dist/cjs}/typedData.js +0 -0
  322. /package/{src/_esm → dist/esm}/account.js +0 -0
  323. /package/{src/_esm → dist/esm}/asset.js +0 -0
  324. /package/{src/_esm → dist/esm}/errors.js +0 -0
  325. /package/{src/_esm → dist/esm}/package.json +0 -0
  326. /package/{src/_esm → dist/esm}/providers.js +0 -0
  327. /package/{src/_esm → dist/esm}/subscriptions.js +0 -0
  328. /package/{src/_esm → dist/esm}/typedData.js +0 -0
package/src/market.ts ADDED
@@ -0,0 +1,137 @@
1
+ import type { Asset } from './asset.js'
2
+
3
+ /** @public */
4
+ export interface FundingInfo {
5
+ rate: string
6
+ nextFundingTime: number
7
+ }
8
+
9
+ /** @public */
10
+ export interface BaseMarket {
11
+ providerId: string
12
+ /** Opaque provider market id; referenced elsewhere as `marketId`. */
13
+ id: string
14
+ /** References a {@link ProviderCategory} by id. */
15
+ categoryId: string
16
+ baseAsset: Asset
17
+ quoteAsset: Asset
18
+ szDecimals: number
19
+ /**
20
+ * Maximum decimal places the venue accepts for order prices on this market.
21
+ * Some venues impose further constraints on top of this budget (e.g. a
22
+ * significant-figure cap), so always format prices through the provider's
23
+ * `formatOrderPrice` rather than applying this field directly.
24
+ */
25
+ priceDecimals?: number
26
+ }
27
+
28
+ /** @public */
29
+ export interface PerpsMarket extends BaseMarket {
30
+ maxLeverage: number
31
+ onlyIsolated: boolean
32
+ /**
33
+ * Venue maintenance margin rate for this market as a fraction (e.g. `0.012`
34
+ * = 1.2%). Feeds client-side liquidation-price estimates via the provider's
35
+ * `estimateLiquidationPrice`.
36
+ */
37
+ maintenanceMarginRate?: number
38
+ }
39
+
40
+ /** @public */
41
+ export interface SpotMarket extends BaseMarket {}
42
+
43
+ /** @public */
44
+ export type Market = PerpsMarket | SpotMarket
45
+
46
+ /** @public */
47
+ export type MarketDisplay = Pick<
48
+ BaseMarket,
49
+ 'providerId' | 'id' | 'categoryId' | 'baseAsset' | 'quoteAsset'
50
+ >
51
+
52
+ /**
53
+ * Minimal market reference for write-action params: identifies a market by
54
+ * its opaque `marketId` within a `categoryId`. Embeds no Assets — write
55
+ * params reference by id, not value.
56
+ * @public
57
+ */
58
+ export interface MarketRef {
59
+ marketId: string
60
+ categoryId: string
61
+ }
62
+
63
+ /** @public */
64
+ export interface MarketsResponse {
65
+ markets: Market[]
66
+ }
67
+
68
+ /**
69
+ * Live per-market data for the `/prices` endpoint. `price` is the mid;
70
+ * `markPrice`, `prevDayPrice` and `volume24h` apply to every market type,
71
+ * while `openInterest` and `funding` are perp-only and absent for spot.
72
+ * @public
73
+ */
74
+ export interface MarketPrice {
75
+ marketId: string
76
+ price: string
77
+ markPrice: string
78
+ prevDayPrice?: string
79
+ volume24h?: string
80
+ openInterest?: string
81
+ funding?: FundingInfo
82
+ }
83
+
84
+ /** @public */
85
+ export interface PricesResponse {
86
+ prices: MarketPrice[]
87
+ }
88
+
89
+ /** @public */
90
+ export interface Candle {
91
+ t: number
92
+ o: string
93
+ h: string
94
+ l: string
95
+ c: string
96
+ v: string
97
+ }
98
+
99
+ /** @public */
100
+ export interface OhlcvResponse {
101
+ provider: string
102
+ marketId: string
103
+ interval: string
104
+ candles: Candle[]
105
+ }
106
+
107
+ /** @public */
108
+ export type OhlcvInterval =
109
+ | '1m'
110
+ | '3m'
111
+ | '5m'
112
+ | '15m'
113
+ | '30m'
114
+ | '1h'
115
+ | '2h'
116
+ | '4h'
117
+ | '8h'
118
+ | '12h'
119
+ | '1d'
120
+ | '3d'
121
+ | '1w'
122
+ | '1M'
123
+
124
+ /** @public */
125
+ export interface OrderbookLevel {
126
+ price: string
127
+ size: string
128
+ }
129
+
130
+ /** @public */
131
+ export interface OrderbookResponse {
132
+ provider: string
133
+ marketId: string
134
+ bids: OrderbookLevel[]
135
+ asks: OrderbookLevel[]
136
+ timestamp: number
137
+ }
package/src/meta.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * A single platform-level advisory shown to all users, independent of any
3
+ * provider or market.
4
+ * @public
5
+ */
6
+ export interface Notice {
7
+ /** Unix epoch milliseconds. */
8
+ timestamp: number
9
+ title: string
10
+ message: string
11
+ /** Optional URL the notice links to; rendered as a hyperlink when present. */
12
+ link?: string
13
+ }
14
+
15
+ /**
16
+ * Read-only platform metadata served by `GET /v1/perps/meta`.
17
+ * @public
18
+ */
19
+ export interface Meta {
20
+ version: string
21
+ notices: Notice[]
22
+ }
23
+
24
+ /**
25
+ * Current Terms-of-Service and this address's acceptance, served by
26
+ * `GET /v1/perps/meta/terms?address=`.
27
+ * @public
28
+ */
29
+ export interface TermsAcceptanceStatus {
30
+ /** Backend-owned version identifier for the current terms. */
31
+ termsVersion: string
32
+ /** Full current terms-of-service text. */
33
+ content: string
34
+ /** Whether the queried address has accepted {@link TermsAcceptanceStatus.termsVersion}. */
35
+ accepted: boolean
36
+ /** Unix epoch milliseconds the address accepted; absent when not accepted. */
37
+ acceptedAt?: number
38
+ }
@@ -0,0 +1,5 @@
1
+ /** @public */
2
+ export type Address = `0x${string}`
3
+
4
+ /** @public */
5
+ export type Hex = `0x${string}`
package/src/providers.ts CHANGED
@@ -1,122 +1,75 @@
1
+ import type { Asset } from './asset.js'
1
2
  import type { ActionType, PerpsSigner, SigningMethod } from './enums.js'
3
+ import type { OhlcvInterval } from './market.js'
2
4
 
3
- export interface ActionDescriptor {
4
- type: ActionType
5
- signers: PerpsSigner[]
6
- /**
7
- * How the SDK must sign this specific action. Most actions match the
8
- * provider's dominant pattern (Hyperliquid: EIP712, Lighter: WASM_BLOB),
9
- * but on-chain bridge actions like DEPOSIT are EVM_TX regardless of
10
- * provider — the SDK dispatches by this field rather than by
11
- * `Provider.signingMethod`.
12
- */
13
- signingMethod: SigningMethod
14
- }
15
-
16
- /**
17
- * One selectable value on a `Param` whose `values` are enumerated.
18
- *
19
- * `value` is the opaque per-provider identifier the SDK passes back to the
20
- * backend in the corresponding action params (e.g. the string assigned to
21
- * `mode` for `ACCOUNT_MODE`, or `tier` for `ACCOUNT_TYPE`).
22
- * `label` is the user-facing string the widget renders.
23
- */
5
+ /** @public */
24
6
  export interface ParamOption {
25
7
  value: string
26
8
  label: string
27
9
  }
28
10
 
29
- /**
30
- * A single parameter the widget must collect from the user before
31
- * dispatching an action.
32
- *
33
- * `name` is the wire key the widget passes through to `execute()` — for the
34
- * existing `ACCOUNT_MODE` action that's `'mode'`, for `ACCOUNT_TYPE` it's
35
- * `'tier'`, etc. The widget builds the action's params object as
36
- * `{ [param.name]: <selected value> }` straight from the descriptor at
37
- * dispatch time; there is no per-ActionType translation layer.
38
- *
39
- * `type` describes the primitive shape of the value. Currently only
40
- * `'string'` is admitted — numeric / boolean primitives are deferred until
41
- * a real descriptor needs them.
42
- *
43
- * `values` is present iff the parameter has a fixed enumeration of
44
- * admissible values (e.g. Hyperliquid abstraction modes, Lighter account
45
- * tiers). When absent the widget renders a free-form input appropriate to
46
- * the primitive `type`.
47
- *
48
- * `default` flags the suggested choice when `values` is provided. Must be
49
- * one of the entries in `values` if specified; consumers should fall back
50
- * to "no selection" when absent and let the user pick.
51
- *
52
- * `readOnly: true` means the widget must render the control disabled —
53
- * typically used when the provider exposes the current value but does not
54
- * allow the user to change it from this surface (e.g. Lighter account
55
- * mode, which is set during onboarding and immutable thereafter).
56
- */
11
+ /** @public */
57
12
  export interface Param {
13
+ /** Wire key for the action params object: `{ [param.name]: value }`. */
58
14
  name: string
59
15
  type: 'string'
16
+ /** Present iff the parameter has a fixed enumeration of admissible values. */
60
17
  values?: ParamOption[]
61
18
  default?: ParamOption
62
19
  readOnly?: boolean
63
20
  }
64
21
 
65
22
  /**
66
- * Self-documenting descriptor for an account-level action the user may
67
- * (setup) or must (options) interact with. Extends `ActionDescriptor`
68
- * because each descriptor resolves to exactly one action the SDK
69
- * dispatches when the user proceeds; the additional fields are the
70
- * presentation and parameter-collection metadata the widget needs to
71
- * render the action without hardcoded per-ActionType branches.
72
- *
73
- * `params` is the list of parameters the widget must collect from the
74
- * user (zero-or-more); each entry tells the widget the wire key, the
75
- * primitive type, optional enumeration of admissible values, and
76
- * optional default. See `Param` for the field-level semantics.
77
- *
78
- * Categorisation of a descriptor as "setup" vs "options" is carried by
79
- * which array on `Provider` it appears in (`Provider.setup` vs
80
- * `Provider.options`), NOT by a field on the descriptor — by design.
81
- * `ProviderSetup` and `ProviderOption` are type aliases for this same
82
- * shape with no additional fields.
23
+ * A single provider action. The same shape backs `Provider.setup`,
24
+ * `Provider.options`, and `Provider.actions` categorisation lives in which
25
+ * array it sits in, not in the type. The core three fields are always present;
26
+ * the rest are presentation/ordering hints provided per-action in the
27
+ * provider's hardcoded metadata.
28
+ * @public
83
29
  */
84
- export interface ProviderActionDescriptor extends ActionDescriptor {
85
- /** User-facing row title rendered in the setup / options modal. */
86
- title: string
87
- /** User-facing description rendered in the setup / options modal. */
88
- description: string
89
- /** Parameters the widget must collect before dispatching the action. */
90
- params: Param[]
30
+ export interface ProviderAction {
31
+ type: ActionType
32
+ signers: PerpsSigner[]
33
+ signingMethod: SigningMethod
34
+ /**
35
+ * Human label. Drives the card heading in the setup/options modals, and may
36
+ * also front an in-flight trading action ("{title} is working…").
37
+ */
38
+ title?: string
39
+ description?: string
40
+ /** UI form fields the widget renders to collect input for this action. */
41
+ params?: Param[]
42
+ /**
43
+ * Ascending order in which the user satisfies setup steps. Cloud-init
44
+ * convention: 10, 20, 30, … with 99 reserved for "always last"; the gaps
45
+ * leave room to insert steps later without renumbering. Lower runs first;
46
+ * a step may depend on every lower-sequenced step already being satisfied.
47
+ */
48
+ sequence?: number
91
49
  }
92
50
 
93
51
  /**
94
- * A descriptor that gates trading: the user MUST satisfy every entry on
95
- * `Provider.setup` before they can place orders with this provider. The
96
- * widget renders these in `<SetupModal />`, which auto-pops mid-session
97
- * whenever setup becomes unsatisfied (e.g. Hyperliquid agent expiry).
98
- *
99
- * Type alias for `ProviderActionDescriptor` — no additional fields. The
100
- * setup-vs-options distinction is the array, not a flag on the item.
101
- */
102
- export type ProviderSetup = ProviderActionDescriptor
103
-
104
- /**
105
- * A post-setup descriptor the user MAY interact with to tune provider
106
- * behaviour (e.g. switching Hyperliquid abstraction modes, switching
107
- * Lighter account tier). The widget renders these in `<OptionsModal />`
108
- * behind a cog icon; they never gate trading.
109
- *
110
- * Type alias for `ProviderActionDescriptor` — no additional fields. The
111
- * setup-vs-options distinction is the array, not a flag on the item.
52
+ * Provider-attached advisory shown against a market. Provider-agnostic: the
53
+ * producer decides when to emit one (e.g. an HL HIP-3 sub-dex risk warning).
54
+ * @public
112
55
  */
113
- export type ProviderOption = ProviderActionDescriptor
56
+ export interface TradeNotice {
57
+ /** Maps to the widget's panel styling: `warn` → warning, `info` → info. */
58
+ level: 'info' | 'warn'
59
+ /** Plaintext; any URL is rendered as text, not a hyperlink. */
60
+ message: string
61
+ }
114
62
 
115
- export interface ProviderMarketInfo {
63
+ /** @public */
64
+ export interface ProviderCategory {
116
65
  id: string
117
- quoteAsset: string | null
66
+ logoURI?: string
67
+ /** `null` for the "spot" category — no single fixed quote. */
68
+ quoteAsset: Asset | null
69
+ tradeNotice?: TradeNotice
118
70
  }
119
71
 
72
+ /** @public */
120
73
  export interface Provider {
121
74
  key: string
122
75
  name: string
@@ -124,30 +77,46 @@ export interface Provider {
124
77
  signingMethod: SigningMethod
125
78
  /** When false, the provider is announced but not yet selectable in clients. */
126
79
  active: boolean
80
+ setup: ProviderAction[]
81
+ options: ProviderAction[]
82
+ actions: ProviderAction[]
83
+ categories: ProviderCategory[]
84
+ wsUrl?: string
85
+ /** Absent means no minimum advertised. */
86
+ minDepositUsd?: number
127
87
  /**
128
- * Mandatory account-setup descriptors. The user MUST satisfy every
129
- * entry before trading. The widget renders these in `<SetupModal />`,
130
- * which auto-pops whenever setup becomes unsatisfied. An empty array
131
- * is valid and indicates the provider has no setup gates.
88
+ * Minimum order notional value in USD. Feeds the SDK's `validateMargin`
89
+ * `minMarginUsd` parameter. Absent means no minimum advertised.
132
90
  */
133
- setup: ProviderSetup[]
91
+ minOrderValueUsd?: number
134
92
  /**
135
- * Optional post-setup descriptors the user may tune (account mode,
136
- * fee tier, etc.). Rendered in `<OptionsModal />` behind the cog icon;
137
- * never gates trading. An empty array is valid.
93
+ * Minimum order notional value in USD for reduce-only orders, when the
94
+ * provider applies a lower floor than `minOrderValueUsd`. Absent means
95
+ * reduce-only orders use the same floor as `minOrderValueUsd`.
138
96
  */
139
- options: ProviderOption[]
140
- actions: ActionDescriptor[]
141
- markets: ProviderMarketInfo[]
142
- wsUrl?: string
97
+ minReduceOrderValueUsd?: number
98
+ /** Minimum withdrawal notional in USD. Absent means no minimum advertised. */
99
+ minWithdrawalUsd?: number
100
+ /** Flat deposit fee in USD the provider charges. Absent means no fee advertised. */
101
+ depositFeeUsd?: number
102
+ /** Flat withdrawal fee in USD the provider charges. Absent means no fee advertised. */
103
+ withdrawalFeeUsd?: number
143
104
  /**
144
- * Minimum deposit amount in USD that the provider's deposit path will
145
- * accept. Absent means no minimum is advertised clients should not
146
- * gate the deposit UX on a value they don't have.
105
+ * Aggregate up-votes for this provider. Populated only for inactive
106
+ * providers (those gathering demand before launch); absent once `active`.
147
107
  */
148
- minDepositUsd?: number
108
+ upVotes?: number
109
+ /** Aggregate down-votes. Populated only for inactive providers; see {@link upVotes}. */
110
+ downVotes?: number
111
+ /**
112
+ * Candle intervals this provider supports for OHLCV/chart requests, in
113
+ * ascending order. Drives the client's chart interval selector. Empty for
114
+ * providers that expose no candle data.
115
+ */
116
+ supportedIntervals: OhlcvInterval[]
149
117
  }
150
118
 
119
+ /** @public */
151
120
  export interface ProvidersResponse {
152
121
  providers: Provider[]
153
122
  }
package/src/quote.ts ADDED
@@ -0,0 +1,49 @@
1
+ import type { FeeTier } from './account.js'
2
+ import type { FundingInfo } from './market.js'
3
+
4
+ /** @public */
5
+ export type QuoteSide = 'buy' | 'sell'
6
+
7
+ /** @public */
8
+ export type TradeType = 'perps' | 'spot'
9
+
10
+ /**
11
+ * One-shot fill estimate for a market order of `sizeUsd` notional on a single
12
+ * venue: the VWAP fill walked from the orderbook, the price impact versus the
13
+ * mark, the base-tier taker fee, and (for perps) the current funding rate.
14
+ *
15
+ * `priceImpactBps` is signed-magnitude basis points (1 bps = 0.01%) of the
16
+ * VWAP fill's deviation from `markPrice` — always non-negative, since a buy
17
+ * fills above mark and a sell below.
18
+ * @public
19
+ */
20
+ export interface Quote {
21
+ provider: string
22
+ /** Human `displaySymbol` the quote was resolved against, e.g. `"BTC"`. */
23
+ symbol: string
24
+ /** Opaque resolved `Market.id`. */
25
+ marketId: string
26
+ type: TradeType
27
+ side: QuoteSide
28
+ /** Input notional in USD. */
29
+ sizeUsd: string
30
+ /** Base amount the book filled for `sizeUsd` (or the most obtainable when the book is too thin). */
31
+ baseSize: string
32
+ markPrice: string
33
+ /** Volume-weighted average fill price from the book walk. */
34
+ expectedFillPrice: string
35
+ /** VWAP deviation from `markPrice` in basis points; non-negative. */
36
+ priceImpactBps: string
37
+ /** Base maker/taker fee fractions (not bps) for the public tier. */
38
+ feeTier: FeeTier
39
+ /** Always `true` in v1 — quotes use the public base tier, never a per-account tier. */
40
+ isDefaultFeeTier: boolean
41
+ /** Taker fee on the filled notional in USD: `filledNotional * feeTier.taker`. */
42
+ feeUsd: string
43
+ /** Current funding for perps; `null` for spot. */
44
+ funding: FundingInfo | null
45
+ /** `true` when the book could not fill the full `sizeUsd` — `baseSize`/fill reflect the best obtainable. */
46
+ insufficientLiquidity: boolean
47
+ /** Unix milliseconds the quote was produced. */
48
+ timestamp: number
49
+ }
@@ -1,44 +1,62 @@
1
- import type { Address } from './typedData.js'
2
- import type { Candle, OhlcvInterval, OrderbookResponse } from './asset.js'
3
- import type { Fill, Position } from './account.js'
4
- import type { Order } from './action.js'
5
-
6
- // --- Channels the user can subscribe to ---
1
+ import type {
2
+ Balance,
3
+ Fill,
4
+ OpenOrder,
5
+ Position,
6
+ TriggerOrder,
7
+ } from './account.js'
8
+ import type { Candle, OhlcvInterval, OrderbookResponse } from './market.js'
9
+ import type { Address } from './primitives.js'
7
10
 
11
+ /** @public */
8
12
  export type PricesSubscription = { channel: 'prices'; dex: string }
13
+ /** @public */
9
14
  export type OrderbookSubscription = {
10
15
  channel: 'orderbook'
11
16
  dex: string
12
- assetId: string
17
+ marketId: string
13
18
  depth?: number
19
+ /**
20
+ * Desired price granularity of streamed levels, in quote currency (e.g.
21
+ * `10` buckets a BTC book into $10-wide levels). Providers that aggregate
22
+ * the book server-side honour it best-effort; providers that stream the
23
+ * full book ignore it. `undefined` requests full precision.
24
+ */
25
+ priceStep?: number
14
26
  }
27
+ /** @public */
15
28
  export type CandleSubscription = {
16
29
  channel: 'candle'
17
30
  dex: string
18
- assetId: string
31
+ marketId: string
19
32
  interval: OhlcvInterval
20
33
  }
34
+ /** @public */
21
35
  export type OrderUpdatesSubscription = {
22
36
  channel: 'orderUpdates'
23
37
  dex: string
24
38
  address: Address
25
39
  }
40
+ /** @public */
26
41
  export type FillsSubscription = {
27
42
  channel: 'fills'
28
43
  dex: string
29
44
  address: Address
30
45
  }
46
+ /** @public */
31
47
  export type PositionsSubscription = {
32
48
  channel: 'positions'
33
49
  dex: string
34
50
  address: Address
35
51
  }
52
+ /** @public */
36
53
  export type SpotBalancesSubscription = {
37
54
  channel: 'spotBalances'
38
55
  dex: string
39
56
  address: Address
40
57
  }
41
58
 
59
+ /** @public */
42
60
  export type Subscription =
43
61
  | PricesSubscription
44
62
  | OrderbookSubscription
@@ -48,22 +66,48 @@ export type Subscription =
48
66
  | PositionsSubscription
49
67
  | SpotBalancesSubscription
50
68
 
51
- // --- Events emitted to listeners ---
52
-
53
- export interface SpotBalance {
54
- coin: string
55
- total: string
56
- hold: string
57
- }
58
-
69
+ /** @public */
59
70
  export type PricesEvent = { channel: 'prices'; data: Record<string, string> }
71
+ /** @public */
60
72
  export type OrderbookEvent = { channel: 'orderbook'; data: OrderbookResponse }
73
+ /** @public */
61
74
  export type CandleEvent = { channel: 'candle'; data: Candle }
62
- export type OrderUpdatesEvent = { channel: 'orderUpdates'; data: Order[] }
75
+ /** @public */
76
+ export type OrderUpdatesEvent = {
77
+ channel: 'orderUpdates'
78
+ data: {
79
+ /** Upserts — active orders, non-trigger. */
80
+ openOrders: OpenOrder[]
81
+ /** Upserts — active orders with trigger semantics (TP/SL). */
82
+ triggerOrders: TriggerOrder[]
83
+ /**
84
+ * orderIds whose status just transitioned to terminal (filled, cancelled,
85
+ * rejected, expired). Consumers should evict these from both buckets.
86
+ */
87
+ terminated: string[]
88
+ }
89
+ }
90
+ /** @public */
63
91
  export type FillsEvent = { channel: 'fills'; data: Fill[] }
92
+ /**
93
+ * Positions stream frame. `data` is always the full set of currently open
94
+ * positions for the subscribed address, never a partial update: zero-size
95
+ * entries never appear, and a close is observed as the market's absence from
96
+ * the next frame. Consumers replace their state; they must not merge.
97
+ * @public
98
+ */
64
99
  export type PositionsEvent = { channel: 'positions'; data: Position[] }
65
- export type SpotBalancesEvent = { channel: 'spotBalances'; data: SpotBalance[] }
100
+ /**
101
+ * Spot holdings as typed {@link Balance}s, each carrying the venue-locked
102
+ * portion (`locked` = reserved against open orders; `available = units − locked`).
103
+ * @public
104
+ */
105
+ export type SpotBalancesEvent = {
106
+ channel: 'spotBalances'
107
+ data: (Balance & { locked: string })[]
108
+ }
66
109
 
110
+ /** @public */
67
111
  export type SubscriptionEvent =
68
112
  | PricesEvent
69
113
  | OrderbookEvent
package/src/typedData.ts CHANGED
@@ -1,23 +1,32 @@
1
- import type { Address, Hex, TypedDataDomain, TypedDataParameter } from 'viem'
2
- import type { HlPrimaryType } from './providers/hyperliquid/types.js'
1
+ import type { Address, Hex } from './primitives.js'
3
2
 
4
- /**
5
- * All known EIP-712 primaryType values across supported providers.
6
- * Extend this union when adding a new EIP-712 provider.
7
- */
8
- export type PerpsPrimaryType = HlPrimaryType
3
+ /** @public */
4
+ export interface TypedDataDomain {
5
+ name?: string
6
+ version?: string
7
+ chainId?: number
8
+ verifyingContract?: Address
9
+ salt?: Hex
10
+ }
11
+
12
+ /** @public */
13
+ export interface TypedDataParameter {
14
+ name: string
15
+ type: string
16
+ }
9
17
 
18
+ /** @public */
19
+ export type PerpsPrimaryType = string
20
+
21
+ /** @public */
10
22
  export type PerpsTypedData = {
11
23
  domain: TypedDataDomain
12
24
  types: Record<string, readonly TypedDataParameter[]>
13
25
  primaryType: PerpsPrimaryType
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
26
  message: Record<string, any>
16
27
  }
17
28
 
29
+ /** @public */
18
30
  export type PerpsSignedTypedData = PerpsTypedData & {
19
31
  signature: Hex
20
32
  }
21
-
22
- // Re-export viem primitives used across perps types
23
- export type { Address, Hex, TypedDataDomain, TypedDataParameter }