@lifi/perps-sdk 20.1.1 → 21.1.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 (367) hide show
  1. package/README.md +81 -6
  2. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  3. package/dist/cjs/client/PerpsClient.js +4 -1
  4. package/dist/cjs/client/PerpsClient.js.map +1 -1
  5. package/dist/cjs/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
  6. package/dist/cjs/decimal/big.d.ts.map +1 -0
  7. package/dist/cjs/{utils/decimal.js → decimal/big.js} +1 -1
  8. package/dist/cjs/decimal/big.js.map +1 -0
  9. package/dist/cjs/decimal/convert.d.ts +11 -0
  10. package/dist/cjs/decimal/convert.d.ts.map +1 -0
  11. package/dist/cjs/decimal/convert.js +70 -0
  12. package/dist/cjs/decimal/convert.js.map +1 -0
  13. package/dist/cjs/decimal/format.d.ts.map +1 -0
  14. package/dist/cjs/decimal/format.js.map +1 -0
  15. package/dist/cjs/decimal/parse.d.ts +6 -0
  16. package/dist/cjs/decimal/parse.d.ts.map +1 -0
  17. package/dist/cjs/{utils → decimal}/parse.js +5 -4
  18. package/dist/cjs/decimal/parse.js.map +1 -0
  19. package/dist/cjs/index.d.ts +17 -15
  20. package/dist/cjs/index.d.ts.map +1 -1
  21. package/dist/cjs/index.js +75 -61
  22. package/dist/cjs/index.js.map +1 -1
  23. package/dist/cjs/math/fills.d.ts +5 -0
  24. package/dist/cjs/math/fills.d.ts.map +1 -0
  25. package/dist/cjs/{utils/fillClassification.js → math/fills.js} +16 -1
  26. package/dist/cjs/math/fills.js.map +1 -0
  27. package/dist/cjs/math/order.d.ts +45 -0
  28. package/dist/cjs/math/order.d.ts.map +1 -0
  29. package/dist/cjs/math/order.js +256 -0
  30. package/dist/cjs/math/order.js.map +1 -0
  31. package/dist/cjs/math/position.d.ts +56 -0
  32. package/dist/cjs/math/position.d.ts.map +1 -0
  33. package/dist/cjs/math/position.js +160 -0
  34. package/dist/cjs/math/position.js.map +1 -0
  35. package/dist/cjs/services/getActivity.d.ts.map +1 -1
  36. package/dist/cjs/services/getActivity.js.map +1 -1
  37. package/dist/cjs/services/getFills.d.ts.map +1 -1
  38. package/dist/cjs/services/getFills.js.map +1 -1
  39. package/dist/cjs/services/getOrder.d.ts.map +1 -1
  40. package/dist/cjs/services/getOrder.js.map +1 -1
  41. package/dist/cjs/services/getOrders.d.ts.map +1 -1
  42. package/dist/cjs/services/getOrders.js.map +1 -1
  43. package/dist/cjs/services/getPositions.d.ts.map +1 -1
  44. package/dist/cjs/services/getPositions.js.map +1 -1
  45. package/dist/cjs/services/resolveQuote.d.ts.map +1 -1
  46. package/dist/cjs/services/resolveQuote.js +2 -2
  47. package/dist/cjs/services/resolveQuote.js.map +1 -1
  48. package/dist/cjs/services/resolveSubscribeQuote.d.ts.map +1 -1
  49. package/dist/cjs/services/resolveSubscribeQuote.js +2 -2
  50. package/dist/cjs/services/resolveSubscribeQuote.js.map +1 -1
  51. package/dist/cjs/types/provider.d.ts +3 -3
  52. package/dist/cjs/types/provider.d.ts.map +1 -1
  53. package/dist/cjs/types/withdrawal.d.ts +2 -0
  54. package/dist/cjs/types/withdrawal.d.ts.map +1 -1
  55. package/dist/cjs/utils/orderClassification.d.ts +1 -3
  56. package/dist/cjs/utils/orderClassification.d.ts.map +1 -1
  57. package/dist/cjs/utils/orderClassification.js +1 -15
  58. package/dist/cjs/utils/orderClassification.js.map +1 -1
  59. package/dist/cjs/version.d.ts +1 -1
  60. package/dist/cjs/version.js +1 -1
  61. package/dist/cjs/wire/orderAmounts.d.ts +18 -0
  62. package/dist/cjs/wire/orderAmounts.d.ts.map +1 -0
  63. package/dist/cjs/wire/orderAmounts.js +79 -0
  64. package/dist/cjs/wire/orderAmounts.js.map +1 -0
  65. package/dist/cjs/wire/refuel.d.ts +8 -0
  66. package/dist/cjs/wire/refuel.d.ts.map +1 -0
  67. package/dist/cjs/wire/refuel.js +23 -0
  68. package/dist/cjs/wire/refuel.js.map +1 -0
  69. package/dist/cjs/wire/requireDecimal.d.ts +4 -0
  70. package/dist/cjs/wire/requireDecimal.d.ts.map +1 -0
  71. package/dist/cjs/wire/requireDecimal.js +16 -0
  72. package/dist/cjs/wire/requireDecimal.js.map +1 -0
  73. package/dist/cjs/wire/snap.d.ts +5 -0
  74. package/dist/cjs/wire/snap.d.ts.map +1 -0
  75. package/dist/cjs/wire/snap.js +12 -0
  76. package/dist/cjs/wire/snap.js.map +1 -0
  77. package/dist/cjs/wire/transferable.d.ts +3 -0
  78. package/dist/cjs/wire/transferable.d.ts.map +1 -0
  79. package/dist/cjs/wire/transferable.js +13 -0
  80. package/dist/cjs/wire/transferable.js.map +1 -0
  81. package/dist/cjs/wire/withdraw.d.ts +4 -0
  82. package/dist/cjs/wire/withdraw.d.ts.map +1 -0
  83. package/dist/cjs/wire/withdraw.js +13 -0
  84. package/dist/cjs/wire/withdraw.js.map +1 -0
  85. package/dist/esm/client/PerpsClient.d.ts +37 -5
  86. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  87. package/dist/esm/client/PerpsClient.js +41 -6
  88. package/dist/esm/client/PerpsClient.js.map +1 -1
  89. package/dist/esm/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
  90. package/dist/esm/decimal/big.d.ts.map +1 -0
  91. package/dist/esm/{utils/decimal.js → decimal/big.js} +1 -1
  92. package/dist/esm/decimal/big.js.map +1 -0
  93. package/dist/esm/decimal/convert.d.ts +80 -0
  94. package/dist/esm/decimal/convert.d.ts.map +1 -0
  95. package/dist/esm/decimal/convert.js +118 -0
  96. package/dist/esm/decimal/convert.js.map +1 -0
  97. package/dist/esm/decimal/format.d.ts.map +1 -0
  98. package/dist/esm/decimal/format.js.map +1 -0
  99. package/dist/esm/decimal/parse.d.ts +29 -0
  100. package/dist/esm/decimal/parse.d.ts.map +1 -0
  101. package/dist/esm/{utils → decimal}/parse.js +9 -10
  102. package/dist/esm/decimal/parse.js.map +1 -0
  103. package/dist/esm/index.d.ts +17 -15
  104. package/dist/esm/index.d.ts.map +1 -1
  105. package/dist/esm/index.js +12 -12
  106. package/dist/esm/index.js.map +1 -1
  107. package/dist/esm/math/fills.d.ts +26 -0
  108. package/dist/esm/math/fills.d.ts.map +1 -0
  109. package/dist/esm/{utils/fillClassification.js → math/fills.js} +26 -2
  110. package/dist/esm/math/fills.js.map +1 -0
  111. package/dist/esm/{utils/calculations.d.ts → math/order.d.ts} +70 -75
  112. package/dist/esm/math/order.d.ts.map +1 -0
  113. package/dist/esm/{utils/calculations.js → math/order.js} +155 -111
  114. package/dist/esm/math/order.js.map +1 -0
  115. package/dist/esm/math/position.d.ts +211 -0
  116. package/dist/esm/math/position.d.ts.map +1 -0
  117. package/dist/esm/math/position.js +299 -0
  118. package/dist/esm/math/position.js.map +1 -0
  119. package/dist/esm/services/getActivity.d.ts +4 -0
  120. package/dist/esm/services/getActivity.d.ts.map +1 -1
  121. package/dist/esm/services/getActivity.js +4 -0
  122. package/dist/esm/services/getActivity.js.map +1 -1
  123. package/dist/esm/services/getFills.d.ts +4 -0
  124. package/dist/esm/services/getFills.d.ts.map +1 -1
  125. package/dist/esm/services/getFills.js +4 -0
  126. package/dist/esm/services/getFills.js.map +1 -1
  127. package/dist/esm/services/getOrder.d.ts +4 -0
  128. package/dist/esm/services/getOrder.d.ts.map +1 -1
  129. package/dist/esm/services/getOrder.js +4 -0
  130. package/dist/esm/services/getOrder.js.map +1 -1
  131. package/dist/esm/services/getOrders.d.ts +10 -1
  132. package/dist/esm/services/getOrders.d.ts.map +1 -1
  133. package/dist/esm/services/getOrders.js +10 -1
  134. package/dist/esm/services/getOrders.js.map +1 -1
  135. package/dist/esm/services/getPositions.d.ts +4 -0
  136. package/dist/esm/services/getPositions.d.ts.map +1 -1
  137. package/dist/esm/services/getPositions.js +4 -0
  138. package/dist/esm/services/getPositions.js.map +1 -1
  139. package/dist/esm/services/resolveQuote.d.ts.map +1 -1
  140. package/dist/esm/services/resolveQuote.js +1 -1
  141. package/dist/esm/services/resolveQuote.js.map +1 -1
  142. package/dist/esm/services/resolveSubscribeQuote.d.ts.map +1 -1
  143. package/dist/esm/services/resolveSubscribeQuote.js +1 -1
  144. package/dist/esm/services/resolveSubscribeQuote.js.map +1 -1
  145. package/dist/esm/types/provider.d.ts +23 -11
  146. package/dist/esm/types/provider.d.ts.map +1 -1
  147. package/dist/esm/types/withdrawal.d.ts +12 -0
  148. package/dist/esm/types/withdrawal.d.ts.map +1 -1
  149. package/dist/esm/utils/orderClassification.d.ts +1 -14
  150. package/dist/esm/utils/orderClassification.d.ts.map +1 -1
  151. package/dist/esm/utils/orderClassification.js +1 -25
  152. package/dist/esm/utils/orderClassification.js.map +1 -1
  153. package/dist/esm/version.d.ts +1 -1
  154. package/dist/esm/version.js +1 -1
  155. package/dist/esm/wire/orderAmounts.d.ts +55 -0
  156. package/dist/esm/wire/orderAmounts.d.ts.map +1 -0
  157. package/dist/esm/wire/orderAmounts.js +114 -0
  158. package/dist/esm/wire/orderAmounts.js.map +1 -0
  159. package/dist/esm/wire/refuel.d.ts +28 -0
  160. package/dist/esm/wire/refuel.d.ts.map +1 -0
  161. package/dist/esm/wire/refuel.js +36 -0
  162. package/dist/esm/wire/refuel.js.map +1 -0
  163. package/dist/esm/wire/requireDecimal.d.ts +11 -0
  164. package/dist/esm/wire/requireDecimal.d.ts.map +1 -0
  165. package/dist/esm/wire/requireDecimal.js +17 -0
  166. package/dist/esm/wire/requireDecimal.js.map +1 -0
  167. package/dist/esm/wire/snap.d.ts +24 -0
  168. package/dist/esm/wire/snap.d.ts.map +1 -0
  169. package/dist/esm/wire/snap.js +27 -0
  170. package/dist/esm/wire/snap.js.map +1 -0
  171. package/dist/esm/wire/transferable.d.ts +15 -0
  172. package/dist/esm/wire/transferable.d.ts.map +1 -0
  173. package/dist/esm/wire/transferable.js +22 -0
  174. package/dist/esm/wire/transferable.js.map +1 -0
  175. package/dist/esm/wire/withdraw.d.ts +14 -0
  176. package/dist/esm/wire/withdraw.d.ts.map +1 -0
  177. package/dist/esm/wire/withdraw.js +20 -0
  178. package/dist/esm/wire/withdraw.js.map +1 -0
  179. package/dist/types/client/PerpsClient.d.ts +37 -5
  180. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  181. package/dist/types/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
  182. package/dist/types/decimal/big.d.ts.map +1 -0
  183. package/dist/types/decimal/convert.d.ts +80 -0
  184. package/dist/types/decimal/convert.d.ts.map +1 -0
  185. package/dist/types/decimal/format.d.ts.map +1 -0
  186. package/dist/types/decimal/parse.d.ts +29 -0
  187. package/dist/types/decimal/parse.d.ts.map +1 -0
  188. package/dist/types/index.d.ts +17 -15
  189. package/dist/types/index.d.ts.map +1 -1
  190. package/dist/types/math/fills.d.ts +26 -0
  191. package/dist/types/math/fills.d.ts.map +1 -0
  192. package/dist/types/{utils/calculations.d.ts → math/order.d.ts} +70 -75
  193. package/dist/types/math/order.d.ts.map +1 -0
  194. package/dist/types/math/position.d.ts +211 -0
  195. package/dist/types/math/position.d.ts.map +1 -0
  196. package/dist/types/services/getActivity.d.ts +4 -0
  197. package/dist/types/services/getActivity.d.ts.map +1 -1
  198. package/dist/types/services/getFills.d.ts +4 -0
  199. package/dist/types/services/getFills.d.ts.map +1 -1
  200. package/dist/types/services/getOrder.d.ts +4 -0
  201. package/dist/types/services/getOrder.d.ts.map +1 -1
  202. package/dist/types/services/getOrders.d.ts +10 -1
  203. package/dist/types/services/getOrders.d.ts.map +1 -1
  204. package/dist/types/services/getPositions.d.ts +4 -0
  205. package/dist/types/services/getPositions.d.ts.map +1 -1
  206. package/dist/types/services/resolveQuote.d.ts.map +1 -1
  207. package/dist/types/services/resolveSubscribeQuote.d.ts.map +1 -1
  208. package/dist/types/types/provider.d.ts +23 -11
  209. package/dist/types/types/provider.d.ts.map +1 -1
  210. package/dist/types/types/withdrawal.d.ts +12 -0
  211. package/dist/types/types/withdrawal.d.ts.map +1 -1
  212. package/dist/types/utils/orderClassification.d.ts +1 -14
  213. package/dist/types/utils/orderClassification.d.ts.map +1 -1
  214. package/dist/types/version.d.ts +1 -1
  215. package/dist/types/wire/orderAmounts.d.ts +55 -0
  216. package/dist/types/wire/orderAmounts.d.ts.map +1 -0
  217. package/dist/types/wire/refuel.d.ts +28 -0
  218. package/dist/types/wire/refuel.d.ts.map +1 -0
  219. package/dist/types/wire/requireDecimal.d.ts +11 -0
  220. package/dist/types/wire/requireDecimal.d.ts.map +1 -0
  221. package/dist/types/wire/snap.d.ts +24 -0
  222. package/dist/types/wire/snap.d.ts.map +1 -0
  223. package/dist/types/wire/transferable.d.ts +15 -0
  224. package/dist/types/wire/transferable.d.ts.map +1 -0
  225. package/dist/types/wire/withdraw.d.ts +14 -0
  226. package/dist/types/wire/withdraw.d.ts.map +1 -0
  227. package/package.json +2 -2
  228. package/src/client/PerpsClient.ts +41 -6
  229. package/src/decimal/convert.ts +164 -0
  230. package/src/{utils → decimal}/parse.ts +13 -11
  231. package/src/index.ts +80 -57
  232. package/src/{utils/fillClassification.ts → math/fills.ts} +30 -1
  233. package/src/{utils/calculations.ts → math/order.ts} +205 -127
  234. package/src/{utils/positionMath.ts → math/position.ts} +173 -21
  235. package/src/services/getActivity.ts +4 -0
  236. package/src/services/getFills.ts +4 -0
  237. package/src/services/getOrder.ts +4 -0
  238. package/src/services/getOrders.ts +10 -1
  239. package/src/services/getPositions.ts +4 -0
  240. package/src/services/resolveQuote.ts +1 -1
  241. package/src/services/resolveSubscribeQuote.ts +1 -1
  242. package/src/types/provider.ts +23 -10
  243. package/src/types/withdrawal.ts +12 -0
  244. package/src/utils/orderClassification.ts +0 -30
  245. package/src/version.ts +1 -1
  246. package/src/wire/orderAmounts.ts +172 -0
  247. package/src/wire/refuel.ts +51 -0
  248. package/src/wire/requireDecimal.ts +24 -0
  249. package/src/wire/snap.ts +38 -0
  250. package/src/wire/transferable.ts +26 -0
  251. package/src/wire/withdraw.ts +29 -0
  252. package/dist/cjs/utils/calculations.d.ts +0 -47
  253. package/dist/cjs/utils/calculations.d.ts.map +0 -1
  254. package/dist/cjs/utils/calculations.js +0 -214
  255. package/dist/cjs/utils/calculations.js.map +0 -1
  256. package/dist/cjs/utils/decimal.d.ts.map +0 -1
  257. package/dist/cjs/utils/decimal.js.map +0 -1
  258. package/dist/cjs/utils/fillClassification.d.ts +0 -3
  259. package/dist/cjs/utils/fillClassification.d.ts.map +0 -1
  260. package/dist/cjs/utils/fillClassification.js.map +0 -1
  261. package/dist/cjs/utils/format.d.ts.map +0 -1
  262. package/dist/cjs/utils/format.js.map +0 -1
  263. package/dist/cjs/utils/math.d.ts +0 -4
  264. package/dist/cjs/utils/math.d.ts.map +0 -1
  265. package/dist/cjs/utils/math.js +0 -8
  266. package/dist/cjs/utils/math.js.map +0 -1
  267. package/dist/cjs/utils/orderEntry.d.ts +0 -6
  268. package/dist/cjs/utils/orderEntry.d.ts.map +0 -1
  269. package/dist/cjs/utils/orderEntry.js +0 -20
  270. package/dist/cjs/utils/orderEntry.js.map +0 -1
  271. package/dist/cjs/utils/orderMath.d.ts +0 -6
  272. package/dist/cjs/utils/orderMath.d.ts.map +0 -1
  273. package/dist/cjs/utils/orderMath.js +0 -85
  274. package/dist/cjs/utils/orderMath.js.map +0 -1
  275. package/dist/cjs/utils/parse.d.ts +0 -3
  276. package/dist/cjs/utils/parse.d.ts.map +0 -1
  277. package/dist/cjs/utils/parse.js.map +0 -1
  278. package/dist/cjs/utils/positionMath.d.ts +0 -37
  279. package/dist/cjs/utils/positionMath.d.ts.map +0 -1
  280. package/dist/cjs/utils/positionMath.js +0 -99
  281. package/dist/cjs/utils/positionMath.js.map +0 -1
  282. package/dist/cjs/utils/scaleToInteger.d.ts +0 -3
  283. package/dist/cjs/utils/scaleToInteger.d.ts.map +0 -1
  284. package/dist/cjs/utils/scaleToInteger.js +0 -30
  285. package/dist/cjs/utils/scaleToInteger.js.map +0 -1
  286. package/dist/cjs/utils/units.d.ts +0 -3
  287. package/dist/cjs/utils/units.d.ts.map +0 -1
  288. package/dist/cjs/utils/units.js +0 -18
  289. package/dist/cjs/utils/units.js.map +0 -1
  290. package/dist/cjs/utils/validation.d.ts +0 -2
  291. package/dist/cjs/utils/validation.d.ts.map +0 -1
  292. package/dist/cjs/utils/validation.js +0 -16
  293. package/dist/cjs/utils/validation.js.map +0 -1
  294. package/dist/esm/utils/calculations.d.ts.map +0 -1
  295. package/dist/esm/utils/calculations.js.map +0 -1
  296. package/dist/esm/utils/decimal.d.ts.map +0 -1
  297. package/dist/esm/utils/decimal.js.map +0 -1
  298. package/dist/esm/utils/fillClassification.d.ts +0 -13
  299. package/dist/esm/utils/fillClassification.d.ts.map +0 -1
  300. package/dist/esm/utils/fillClassification.js.map +0 -1
  301. package/dist/esm/utils/format.d.ts.map +0 -1
  302. package/dist/esm/utils/format.js.map +0 -1
  303. package/dist/esm/utils/math.d.ts +0 -6
  304. package/dist/esm/utils/math.d.ts.map +0 -1
  305. package/dist/esm/utils/math.js +0 -5
  306. package/dist/esm/utils/math.js.map +0 -1
  307. package/dist/esm/utils/orderEntry.d.ts +0 -26
  308. package/dist/esm/utils/orderEntry.d.ts.map +0 -1
  309. package/dist/esm/utils/orderEntry.js +0 -34
  310. package/dist/esm/utils/orderEntry.js.map +0 -1
  311. package/dist/esm/utils/orderMath.d.ts +0 -37
  312. package/dist/esm/utils/orderMath.d.ts.map +0 -1
  313. package/dist/esm/utils/orderMath.js +0 -113
  314. package/dist/esm/utils/orderMath.js.map +0 -1
  315. package/dist/esm/utils/parse.d.ts +0 -28
  316. package/dist/esm/utils/parse.d.ts.map +0 -1
  317. package/dist/esm/utils/parse.js.map +0 -1
  318. package/dist/esm/utils/positionMath.d.ts +0 -120
  319. package/dist/esm/utils/positionMath.d.ts.map +0 -1
  320. package/dist/esm/utils/positionMath.js +0 -173
  321. package/dist/esm/utils/positionMath.js.map +0 -1
  322. package/dist/esm/utils/scaleToInteger.d.ts +0 -22
  323. package/dist/esm/utils/scaleToInteger.d.ts.map +0 -1
  324. package/dist/esm/utils/scaleToInteger.js +0 -34
  325. package/dist/esm/utils/scaleToInteger.js.map +0 -1
  326. package/dist/esm/utils/units.d.ts +0 -27
  327. package/dist/esm/utils/units.d.ts.map +0 -1
  328. package/dist/esm/utils/units.js +0 -38
  329. package/dist/esm/utils/units.js.map +0 -1
  330. package/dist/esm/utils/validation.d.ts +0 -18
  331. package/dist/esm/utils/validation.d.ts.map +0 -1
  332. package/dist/esm/utils/validation.js +0 -29
  333. package/dist/esm/utils/validation.js.map +0 -1
  334. package/dist/types/utils/calculations.d.ts.map +0 -1
  335. package/dist/types/utils/decimal.d.ts.map +0 -1
  336. package/dist/types/utils/fillClassification.d.ts +0 -13
  337. package/dist/types/utils/fillClassification.d.ts.map +0 -1
  338. package/dist/types/utils/format.d.ts.map +0 -1
  339. package/dist/types/utils/math.d.ts +0 -6
  340. package/dist/types/utils/math.d.ts.map +0 -1
  341. package/dist/types/utils/orderEntry.d.ts +0 -26
  342. package/dist/types/utils/orderEntry.d.ts.map +0 -1
  343. package/dist/types/utils/orderMath.d.ts +0 -37
  344. package/dist/types/utils/orderMath.d.ts.map +0 -1
  345. package/dist/types/utils/parse.d.ts +0 -28
  346. package/dist/types/utils/parse.d.ts.map +0 -1
  347. package/dist/types/utils/positionMath.d.ts +0 -120
  348. package/dist/types/utils/positionMath.d.ts.map +0 -1
  349. package/dist/types/utils/scaleToInteger.d.ts +0 -22
  350. package/dist/types/utils/scaleToInteger.d.ts.map +0 -1
  351. package/dist/types/utils/units.d.ts +0 -27
  352. package/dist/types/utils/units.d.ts.map +0 -1
  353. package/dist/types/utils/validation.d.ts +0 -18
  354. package/dist/types/utils/validation.d.ts.map +0 -1
  355. package/src/utils/math.ts +0 -7
  356. package/src/utils/orderEntry.ts +0 -38
  357. package/src/utils/orderMath.ts +0 -152
  358. package/src/utils/scaleToInteger.ts +0 -56
  359. package/src/utils/units.ts +0 -39
  360. package/src/utils/validation.ts +0 -38
  361. /package/dist/cjs/{utils → decimal}/format.d.ts +0 -0
  362. /package/dist/cjs/{utils → decimal}/format.js +0 -0
  363. /package/dist/esm/{utils → decimal}/format.d.ts +0 -0
  364. /package/dist/esm/{utils → decimal}/format.js +0 -0
  365. /package/dist/types/{utils → decimal}/format.d.ts +0 -0
  366. /package/src/{utils/decimal.ts → decimal/big.ts} +0 -0
  367. /package/src/{utils → decimal}/format.ts +0 -0
@@ -1,24 +1,151 @@
1
1
  /**
2
- * Pure-function helpers for predicting how a perp position changes after a
3
- * fill.
2
+ * Display-tier position formulas. Every function takes and gives `number`;
3
+ * exact decimal arithmetic happens internally with `DivBig`.
4
4
  *
5
- * Sign convention: long = +1, short = -1. Sizes passed to these helpers are
6
- * always non-negative magnitudes; direction is carried by `isLong`.
5
+ * Sign convention: long = +1, short = -1. Sizes passed to the `estimate*`
6
+ * helpers are always non-negative magnitudes; direction is carried by
7
+ * `isLong`.
7
8
  */
8
9
 
9
- import { areFinite, DivBig } from './decimal.js'
10
+ import { areFinite, DivBig } from '../decimal/big.js'
10
11
 
11
12
  /**
12
13
  * Direction sign for a position.
13
14
  *
14
- * @param isLong - True for long positions, false for short.
15
- * @returns +1 for long, -1 for short.
16
- * @public
15
+ * @deprecated Inline `isLong ? 1 : -1`. Removed in the next major.
17
16
  */
18
17
  export function directionSign(isLong: boolean): 1 | -1 {
19
18
  return isLong ? 1 : -1
20
19
  }
21
20
 
21
+ /**
22
+ * Calculate notional value of a position.
23
+ *
24
+ * @param size - Position size in asset units
25
+ * @param price - Current asset price
26
+ * @returns Notional value in USD
27
+ * @public
28
+ */
29
+ export function calculateNotionalValue(size: number, price: number): number {
30
+ if (!areFinite(size, price)) {
31
+ return Number.NaN
32
+ }
33
+ return new DivBig(size).abs().times(price).toNumber()
34
+ }
35
+
36
+ /**
37
+ * Calculate unrealized PnL.
38
+ *
39
+ * @param entryPrice - Position entry price
40
+ * @param currentPrice - Current market price
41
+ * @param size - Position size (positive for long, negative for short)
42
+ * @returns Unrealized PnL in USD
43
+ * @public
44
+ */
45
+ export function calculateUnrealizedPnl(
46
+ entryPrice: number,
47
+ currentPrice: number,
48
+ size: number
49
+ ): number {
50
+ if (!areFinite(entryPrice, currentPrice, size)) {
51
+ return Number.NaN
52
+ }
53
+ return new DivBig(currentPrice).minus(entryPrice).times(size).toNumber()
54
+ }
55
+
56
+ /**
57
+ * Calculate return on equity (ROE) percentage.
58
+ *
59
+ * @param pnl - Profit/loss in USD
60
+ * @param margin - Initial margin in USD
61
+ * @returns ROE as percentage (e.g., 10 for 10%)
62
+ * @public
63
+ */
64
+ export function calculateRoe(pnl: number, margin: number): number {
65
+ if (margin === 0) {
66
+ return 0
67
+ }
68
+ if (!areFinite(pnl, margin)) {
69
+ return Number.NaN
70
+ }
71
+ return new DivBig(pnl).div(margin).times(100).toNumber()
72
+ }
73
+
74
+ /**
75
+ * Calculate required margin for a position.
76
+ *
77
+ * @param notionalValue - Position notional value in USD
78
+ * @param leverage - Position leverage
79
+ * @returns Required margin in USD
80
+ * @public
81
+ */
82
+ export function calculateRequiredMargin(
83
+ notionalValue: number,
84
+ leverage: number
85
+ ): number {
86
+ if (leverage === 0) {
87
+ return notionalValue / leverage
88
+ }
89
+ if (!areFinite(notionalValue, leverage)) {
90
+ return Number.NaN
91
+ }
92
+ return new DivBig(notionalValue).div(leverage).toNumber()
93
+ }
94
+
95
+ /**
96
+ * Distance from the current price to the liquidation price, as a percentage of
97
+ * the current price.
98
+ *
99
+ * @param liquidationPrice - The position's liquidation price
100
+ * @param currentPrice - Current market price
101
+ * @returns Absolute distance as a percentage, or 0 when current price is zero
102
+ * @public
103
+ */
104
+ export function calculateLiquidationDistance(params: {
105
+ liquidationPrice: number
106
+ currentPrice: number
107
+ }): number {
108
+ const { liquidationPrice, currentPrice } = params
109
+ if (currentPrice === 0) {
110
+ return 0
111
+ }
112
+ return Math.abs((liquidationPrice - currentPrice) / currentPrice) * 100
113
+ }
114
+
115
+ /**
116
+ * @deprecated Use `calculateLiquidationDistance`. Removed in the next major.
117
+ */
118
+ export const liquidationDistancePercent = calculateLiquidationDistance
119
+
120
+ /**
121
+ * Effective leverage of an open position.
122
+ *
123
+ * leverage = positionValueUsd / marginUsd
124
+ *
125
+ * @param positionValueUsd - Position notional value in USD
126
+ * @param marginUsd - Margin backing the position in USD
127
+ * @returns Effective leverage, or 0 when margin is zero
128
+ * @public
129
+ */
130
+ export function calculateEffectiveLeverage(params: {
131
+ positionValueUsd: number
132
+ marginUsd: number
133
+ }): number {
134
+ const { positionValueUsd, marginUsd } = params
135
+ if (marginUsd === 0) {
136
+ return 0
137
+ }
138
+ if (!areFinite(positionValueUsd, marginUsd)) {
139
+ return Number.NaN
140
+ }
141
+ return new DivBig(positionValueUsd).div(marginUsd).toNumber()
142
+ }
143
+
144
+ /**
145
+ * @deprecated Use `calculateEffectiveLeverage`. Removed in the next major.
146
+ */
147
+ export const effectiveLeverage = calculateEffectiveLeverage
148
+
22
149
  /**
23
150
  * Estimated liquidation price for an isolated-margin position, parameterised
24
151
  * by the venue's maintenance margin rate.
@@ -37,7 +164,7 @@ export function directionSign(isLong: boolean): 1 | -1 {
37
164
  * produce one (zero leverage, degenerate denominator).
38
165
  * @public
39
166
  */
40
- export function estimateIsolatedLiquidationPrice(params: {
167
+ export function estimateLiquidationPrice(params: {
41
168
  entryPrice: number
42
169
  leverage: number
43
170
  isLong: boolean
@@ -47,7 +174,7 @@ export function estimateIsolatedLiquidationPrice(params: {
47
174
  if (leverage === 0) {
48
175
  return undefined
49
176
  }
50
- const side = directionSign(isLong)
177
+ const side = isLong ? 1 : -1
51
178
  const denominator = 1 - maintenanceMarginRate * side
52
179
  if (denominator === 0) {
53
180
  return undefined
@@ -65,6 +192,11 @@ export function estimateIsolatedLiquidationPrice(params: {
65
192
  .toNumber()
66
193
  }
67
194
 
195
+ /**
196
+ * @deprecated Use `estimateLiquidationPrice`. Removed in the next major.
197
+ */
198
+ export const estimateIsolatedLiquidationPrice = estimateLiquidationPrice
199
+
68
200
  /**
69
201
  * Whether an isolated position with this liquidation price is already past
70
202
  * liquidation at `currentPrice`: a long liquidates when the price falls to its
@@ -88,7 +220,7 @@ export function wouldImmediatelyLiquidate(params: {
88
220
  }
89
221
 
90
222
  /**
91
- * Predicted average entry price after adding to an existing position.
223
+ * Estimated average entry price after adding to an existing position.
92
224
  *
93
225
  * Weighted average of the current entry and the new fill price, weighted by
94
226
  * the size of each leg in coin units. Both legs assumed in the same direction
@@ -103,7 +235,7 @@ export function wouldImmediatelyLiquidate(params: {
103
235
  * cannot produce a valid average (zero combined size, non-finite values).
104
236
  * @public
105
237
  */
106
- export function predictAverageEntryPrice(params: {
238
+ export function estimateAverageEntryPrice(params: {
107
239
  currentSize: number
108
240
  currentEntry: number
109
241
  addSize: number
@@ -128,7 +260,12 @@ export function predictAverageEntryPrice(params: {
128
260
  }
129
261
 
130
262
  /**
131
- * Predicted effective leverage after adding margin and notional.
263
+ * @deprecated Use `estimateAverageEntryPrice`. Removed in the next major.
264
+ */
265
+ export const predictAverageEntryPrice = estimateAverageEntryPrice
266
+
267
+ /**
268
+ * Estimated effective leverage after adding margin and notional.
132
269
  *
133
270
  * leverage = totalNotional / totalMargin. The caller computes notional from
134
271
  * size and price (`calculateNotionalValue`) and supplies the additional
@@ -138,7 +275,7 @@ export function predictAverageEntryPrice(params: {
138
275
  * non-positive.
139
276
  * @public
140
277
  */
141
- export function predictNewLeverage(params: {
278
+ export function estimateNewLeverage(params: {
142
279
  currentNotional: number
143
280
  currentMargin: number
144
281
  addNotional: number
@@ -159,14 +296,19 @@ export function predictNewLeverage(params: {
159
296
  }
160
297
 
161
298
  /**
162
- * Predicted unrealised PnL at the current mark price.
299
+ * @deprecated Use `estimateNewLeverage`. Removed in the next major.
300
+ */
301
+ export const predictNewLeverage = estimateNewLeverage
302
+
303
+ /**
304
+ * Estimated unrealised PnL at the current mark price.
163
305
  *
164
- * `pnl = (markPrice - entryPrice) * size * directionSign(isLong)`
306
+ * `pnl = (markPrice - entryPrice) * size * (isLong ? 1 : -1)`
165
307
  *
166
308
  * @param size - Position size as a non-negative magnitude.
167
309
  * @public
168
310
  */
169
- export function predictUnrealizedPnl(params: {
311
+ export function estimateUnrealizedPnl(params: {
170
312
  entryPrice: number
171
313
  markPrice: number
172
314
  size: number
@@ -179,19 +321,24 @@ export function predictUnrealizedPnl(params: {
179
321
  return new DivBig(markPrice)
180
322
  .minus(entryPrice)
181
323
  .times(size)
182
- .times(directionSign(isLong))
324
+ .times(isLong ? 1 : -1)
183
325
  .toNumber()
184
326
  }
185
327
 
328
+ /**
329
+ * @deprecated Use `estimateUnrealizedPnl`. Removed in the next major.
330
+ */
331
+ export const predictUnrealizedPnl = estimateUnrealizedPnl
332
+
186
333
  /**
187
334
  * Realised PnL on the portion of a position being closed.
188
335
  *
189
- * `rPnl = (closePrice - entryPrice) * closeSize * directionSign(isLong)`
336
+ * `rPnl = (closePrice - entryPrice) * closeSize * (isLong ? 1 : -1)`
190
337
  *
191
338
  * @param closeSize - Size being closed as a non-negative magnitude.
192
339
  * @public
193
340
  */
194
- export function realizedPnlOnClose(params: {
341
+ export function calculateRealizedPnl(params: {
195
342
  entryPrice: number
196
343
  closePrice: number
197
344
  closeSize: number
@@ -204,6 +351,11 @@ export function realizedPnlOnClose(params: {
204
351
  return new DivBig(closePrice)
205
352
  .minus(entryPrice)
206
353
  .times(closeSize)
207
- .times(directionSign(isLong))
354
+ .times(isLong ? 1 : -1)
208
355
  .toNumber()
209
356
  }
357
+
358
+ /**
359
+ * @deprecated Use `calculateRealizedPnl`. Removed in the next major.
360
+ */
361
+ export const realizedPnlOnClose = calculateRealizedPnl
@@ -30,6 +30,10 @@ export interface GetActivityParams {
30
30
  *
31
31
  * @throws {PerpsError} When the provider plugin is not registered, or on
32
32
  * backend / network / parsing errors.
33
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (a
34
+ * Lighter auth token or an Ondo session) and none is stored.
35
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
36
+ * @throws {PerpsError} `AccountNotFound` when the wallet has no venue account.
33
37
  * @example
34
38
  * ```ts
35
39
  * const { items, pagination } = await getActivity(client, {
@@ -29,6 +29,10 @@ export interface GetFillsParams {
29
29
  *
30
30
  * @throws {PerpsError} When the provider plugin is not registered, or on
31
31
  * backend / network / parsing errors.
32
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (a
33
+ * Lighter auth token or an Ondo session) and none is stored.
34
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
35
+ * @throws {PerpsError} `AccountNotFound` when the wallet has no venue account.
32
36
  * @example
33
37
  * ```ts
34
38
  * const { items, pagination } = await getFills(client, {
@@ -23,6 +23,10 @@ export interface GetOrderParams {
23
23
  *
24
24
  * @throws {PerpsError} When the provider plugin is not registered, or on
25
25
  * backend / network / parsing errors.
26
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (a
27
+ * Lighter auth token or an Ondo session) and none is stored.
28
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
29
+ * @throws {PerpsError} `AccountNotFound` when the wallet has no venue account.
26
30
  * @example
27
31
  * ```ts
28
32
  * const order = await getOrder(client, {
@@ -22,7 +22,16 @@ export interface GetOrdersParams {
22
22
  cursor?: string
23
23
  }
24
24
 
25
- /** Read account orders with active lifecycle statuses as the default filter. */
25
+ /**
26
+ * Read account orders with active lifecycle statuses as the default filter.
27
+ *
28
+ * @throws {PerpsError} When the provider plugin is not registered, or on
29
+ * backend / network / parsing errors.
30
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (a
31
+ * Lighter auth token or an Ondo session) and none is stored.
32
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
33
+ * @throws {PerpsError} `AccountNotFound` when the wallet has no venue account.
34
+ */
26
35
  export async function getOrders(
27
36
  client: PerpsSDKClient,
28
37
  params: GetOrdersParams,
@@ -27,6 +27,10 @@ export interface GetPositionsParams {
27
27
  *
28
28
  * @throws {PerpsError} When the provider plugin is not registered, or on
29
29
  * backend / network / parsing errors.
30
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (a
31
+ * Lighter auth token or an Ondo session) and none is stored.
32
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
33
+ * @throws {PerpsError} `AccountNotFound` when the wallet has no venue account.
30
34
  * @example
31
35
  * ```ts
32
36
  * const { positions } = await getPositions(client, {
@@ -6,12 +6,12 @@ import {
6
6
  type Quote,
7
7
  } from '@lifi/perps-types'
8
8
  import { PerpsError } from '../errors/PerpsError.js'
9
+ import { buildQuote } from '../math/order.js'
9
10
  import type { SDKRequestOptions } from '../types/config.js'
10
11
  import type {
11
12
  PerpsSDKClient,
12
13
  ProviderGetQuoteParams,
13
14
  } from '../types/provider.js'
14
- import { buildQuote } from '../utils/calculations.js'
15
15
  import { getMarkets } from './getMarkets.js'
16
16
  import { getMarketsContext } from './getMarketsContext.js'
17
17
  import { getOrderbook } from './getOrderbook.js'
@@ -3,12 +3,12 @@ import type {
3
3
  MarketContext,
4
4
  OrderbookResponse,
5
5
  } from '@lifi/perps-types'
6
+ import { buildQuote } from '../math/order.js'
6
7
  import type {
7
8
  PerpsSDKClient,
8
9
  ProviderGetQuoteParams,
9
10
  QuoteListener,
10
11
  } from '../types/provider.js'
11
- import { buildQuote } from '../utils/calculations.js'
12
12
  import type { WsProvider } from '../websocket/types.js'
13
13
  import { resolveQuoteMarket, resolveQuotePrice } from './resolveQuote.js'
14
14
 
@@ -9,6 +9,7 @@ import type {
9
9
  ActivitiesResponse,
10
10
  ActivityType,
11
11
  AvailableToTrade,
12
+ DecimalString,
12
13
  FillsResponse,
13
14
  Market,
14
15
  MarketRef,
@@ -534,29 +535,37 @@ export interface PerpsProviderPlugin {
534
535
  ): AccountSummary
535
536
 
536
537
  /**
537
- * Format an order price onto the venue's tick grid for `market`. This is
538
- * the canonical, provider-correct formatting surface — venue tick rules
539
- * differ per provider, so provider-agnostic consumers must route every
540
- * order price through the market's own provider instead of applying one
541
- * venue's rules to another's markets. Pure — does no I/O.
538
+ * Snap an order price onto the venue's tick grid for `market`, rounding
539
+ * half-up. This is the canonical, provider-correct price surface — venue
540
+ * tick rules differ per provider, so provider-agnostic consumers must route
541
+ * every order price through the market's own provider instead of applying
542
+ * one venue's rules to another's markets. Pure — does no I/O.
543
+ *
544
+ * Takes and gives a {@link DecimalString}. Never pass a `number`: above 15
545
+ * significant digits the value has already lost digits by the time it
546
+ * arrives.
542
547
  *
543
548
  * @returns The price as a wire-ready decimal string, trailing zeros
544
549
  * stripped.
545
550
  * @throws {PerpsError} `ValidationError` when `market` lacks the tick
546
551
  * metadata the venue's rules need (e.g. `Market.priceDecimals` absent).
547
552
  */
548
- formatOrderPrice(market: Market, price: number): string
553
+ snapOrderPrice(market: Market, price: DecimalString): DecimalString
549
554
 
550
555
  /**
551
- * Format an order size onto the venue's lot grid for `market`. Truncates
552
- * (never rounds up) so the formatted size cannot exceed the user's intended
553
- * size or available balance. Pure — does no I/O.
556
+ * Snap an order size onto the venue's lot grid for `market`, truncating
557
+ * toward zero (never rounding up) so the snapped size cannot exceed the
558
+ * user's intended size or available balance. Pure — does no I/O.
559
+ *
560
+ * Takes and gives a {@link DecimalString}. Never pass a `number`: above 15
561
+ * significant digits the value has already lost digits by the time it
562
+ * arrives.
554
563
  *
555
564
  * @param size - Size in base-asset units as a non-negative magnitude.
556
565
  * @returns The size as a wire-ready decimal string, trailing zeros
557
566
  * stripped.
558
567
  */
559
- formatOrderSize(market: Market, size: number): string
568
+ snapOrderSize(market: Market, size: DecimalString): DecimalString
560
569
 
561
570
  /**
562
571
  * Estimate the liquidation price of a new isolated position on `market`
@@ -564,6 +573,10 @@ export interface PerpsProviderPlugin {
564
573
  * positions, prefer `Position.liquidationPrice` from the venue. Pure —
565
574
  * does no I/O.
566
575
  *
576
+ * Numbers, in and out, on purpose: this is a display-tier estimate that
577
+ * feeds a screen, not a wire amount. It is not a `snap*` method and must
578
+ * not be converted to {@link DecimalString}.
579
+ *
567
580
  * @returns The estimated liquidation price, or `undefined` when the venue's
568
581
  * model cannot be evaluated client-side (degenerate inputs, or `market`
569
582
  * lacks the margin metadata the model needs).
@@ -20,6 +20,12 @@ export interface ProviderWithdrawableBalance {
20
20
  route: WithdrawalRoute
21
21
  /** Withdrawable amount in the asset's own units. Always greater than zero. */
22
22
  available: DecimalString
23
+ /**
24
+ * Largest `amount` the row can fund: `available` when the fee is deducted
25
+ * from the amount or absent; `available − withdrawalFee` floored at zero
26
+ * when the venue charges the fee on top (`isFeeDeducted === false`).
27
+ */
28
+ max: DecimalString
23
29
  /**
24
30
  * Flat venue fee on a withdrawal from this row, in the asset's own units.
25
31
  * Absent when the venue publishes no fee for the asset. The client rejects
@@ -46,6 +52,12 @@ export interface WithdrawableBalance {
46
52
  route: WithdrawalRoute
47
53
  /** Withdrawable amount in the asset's own units. */
48
54
  available: DecimalString
55
+ /**
56
+ * Largest `amount` the row can fund: `available` when the fee is deducted
57
+ * from the amount or absent; `available − withdrawalFee` floored at zero
58
+ * when the venue charges the fee on top (`isFeeDeducted === false`).
59
+ */
60
+ max: DecimalString
49
61
  /**
50
62
  * Flat venue fee on a withdrawal from this row, in the asset's own units.
51
63
  * Absent when the venue publishes no fee for the asset. With
@@ -5,20 +5,11 @@ import type {
5
5
  TwapOrder,
6
6
  } from '@lifi/perps-types'
7
7
  import {
8
- FillClassification,
9
8
  OrderSide,
10
9
  OrderStatus,
11
10
  OrderType,
12
11
  TriggerCondition,
13
12
  } from '@lifi/perps-types'
14
- import { stringToFloat } from './parse.js'
15
-
16
- /**
17
- * Re-exported fill taxonomy used by {@link classifyFillFromPosition}.
18
- *
19
- * @public
20
- */
21
- export { FillClassification }
22
13
 
23
14
  const TP_TYPES = new Set<OrderType>([
24
15
  OrderType.TAKE_PROFIT_MARKET,
@@ -97,24 +88,3 @@ export const ACTIVE_ORDER_STATUSES: ReadonlySet<OrderStatus> = new Set([
97
88
  export function isActiveOrderStatus(status: OrderStatus): boolean {
98
89
  return ACTIVE_ORDER_STATUSES.has(status)
99
90
  }
100
-
101
- /**
102
- * Classify a fill as open or close based on realizedPnl.
103
- * @deprecated Use `Fill.classification` instead — it uses startPosition
104
- * for accurate open/increase/reduce/close/reverse classification.
105
- * @public
106
- */
107
- export function classifyFill(
108
- side: OrderSide,
109
- realizedPnl: string | null | undefined
110
- ): FillClassification {
111
- const isClose = realizedPnl != null && stringToFloat(realizedPnl) !== 0
112
- if (side === OrderSide.BUY) {
113
- return isClose
114
- ? FillClassification.CLOSED_SHORT
115
- : FillClassification.OPENED_LONG
116
- }
117
- return isClose
118
- ? FillClassification.CLOSED_LONG
119
- : FillClassification.OPENED_SHORT
120
- }
package/src/version.ts CHANGED
@@ -10,4 +10,4 @@ export const name = '@lifi/perps-sdk'
10
10
  *
11
11
  * @public
12
12
  */
13
- export const version = '20.1.1'
13
+ export const version = '21.1.0'