@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
@@ -13,6 +13,12 @@ export interface ProviderWithdrawableBalance {
13
13
  route: WithdrawalRoute;
14
14
  /** Withdrawable amount in the asset's own units. Always greater than zero. */
15
15
  available: DecimalString;
16
+ /**
17
+ * Largest `amount` the row can fund: `available` when the fee is deducted
18
+ * from the amount or absent; `available − withdrawalFee` floored at zero
19
+ * when the venue charges the fee on top (`isFeeDeducted === false`).
20
+ */
21
+ max: DecimalString;
16
22
  /**
17
23
  * Flat venue fee on a withdrawal from this row, in the asset's own units.
18
24
  * Absent when the venue publishes no fee for the asset. The client rejects
@@ -38,6 +44,12 @@ export interface WithdrawableBalance {
38
44
  route: WithdrawalRoute;
39
45
  /** Withdrawable amount in the asset's own units. */
40
46
  available: DecimalString;
47
+ /**
48
+ * Largest `amount` the row can fund: `available` when the fee is deducted
49
+ * from the amount or absent; `available − withdrawalFee` floored at zero
50
+ * when the venue charges the fee on top (`isFeeDeducted === false`).
51
+ */
52
+ max: DecimalString;
41
53
  /**
42
54
  * Flat venue fee on a withdrawal from this row, in the asset's own units.
43
55
  * Absent when the venue publishes no fee for the asset. With
@@ -1 +1 @@
1
- {"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/types/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,KAAK,EACL,aAAa,EACb,eAAe,EAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC,YAAY,EAAE,eAAe,EAAE,CAAA;AAE/B;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IAC1C,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,eAAe,CAAA;IACtB,8EAA8E;IAC9E,SAAS,EAAE,aAAa,CAAA;IACxB;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,CAAA;IACZ,KAAK,EAAE,eAAe,CAAA;IACtB,oDAAoD;IACpD,SAAS,EAAE,aAAa,CAAA;IACxB;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,eAAe,CAAA;IACrB,qEAAqE;IACrE,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,yBAAyB,CAAA"}
1
+ {"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/types/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,KAAK,EACL,aAAa,EACb,eAAe,EAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC,YAAY,EAAE,eAAe,EAAE,CAAA;AAE/B;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IAC1C,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,eAAe,CAAA;IACtB,8EAA8E;IAC9E,SAAS,EAAE,aAAa,CAAA;IACxB;;;;OAIG;IACH,GAAG,EAAE,aAAa,CAAA;IAClB;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,CAAA;IACZ,KAAK,EAAE,eAAe,CAAA;IACtB,oDAAoD;IACpD,SAAS,EAAE,aAAa,CAAA;IACxB;;;;OAIG;IACH,GAAG,EAAE,aAAa,CAAA;IAClB;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,eAAe,CAAA;IACrB,qEAAqE;IACrE,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,yBAAyB,CAAA"}
@@ -1,11 +1,5 @@
1
1
  import type { Order, RegularOrder, TriggerOrder, TwapOrder } from '@lifi/perps-types';
2
- import { FillClassification, OrderSide, OrderStatus, TriggerCondition } from '@lifi/perps-types';
3
- /**
4
- * Re-exported fill taxonomy used by {@link classifyFillFromPosition}.
5
- *
6
- * @public
7
- */
8
- export { FillClassification };
2
+ import { OrderSide, OrderStatus, TriggerCondition } from '@lifi/perps-types';
9
3
  /**
10
4
  * Check if an open order is a Take Profit trigger order.
11
5
  * @public
@@ -37,11 +31,4 @@ export declare const ACTIVE_ORDER_STATUSES: ReadonlySet<OrderStatus>;
37
31
  * @public
38
32
  */
39
33
  export declare function isActiveOrderStatus(status: OrderStatus): boolean;
40
- /**
41
- * Classify a fill as open or close based on realizedPnl.
42
- * @deprecated Use `Fill.classification` instead — it uses startPosition
43
- * for accurate open/increase/reduce/close/reverse classification.
44
- * @public
45
- */
46
- export declare function classifyFill(side: OrderSide, realizedPnl: string | null | undefined): FillClassification;
47
34
  //# sourceMappingURL=orderClassification.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"orderClassification.d.ts","sourceRoot":"","sources":["../../../src/utils/orderClassification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,WAAW,EAEX,gBAAgB,EACjB,MAAM,mBAAmB,CAAA;AAG1B;;;;GAIG;AACH,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAY7B;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAErE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAEnE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAE/D;AAED,kDAAkD;AAClD,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,YAAY,CAElE;AAED,kDAAkD;AAClD,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,YAAY,CAElE;AAED,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,SAAS,CAE5D;AAED,kFAAkF;AAClF,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,EAC1B,IAAI,EAAE,SAAS,GACd,gBAAgB,CAKlB;AAED,6DAA6D;AAC7D,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,WAAW,CAMzD,CAAA;AAEF;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAEhE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACrC,kBAAkB,CAUpB"}
1
+ {"version":3,"file":"orderClassification.d.ts","sourceRoot":"","sources":["../../../src/utils/orderClassification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,SAAS,EACT,WAAW,EAEX,gBAAgB,EACjB,MAAM,mBAAmB,CAAA;AAY1B;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAErE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAEnE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAE/D;AAED,kDAAkD;AAClD,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,YAAY,CAElE;AAED,kDAAkD;AAClD,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,YAAY,CAElE;AAED,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,SAAS,CAE5D;AAED,kFAAkF;AAClF,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,EAC1B,IAAI,EAAE,SAAS,GACd,gBAAgB,CAKlB;AAED,6DAA6D;AAC7D,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,WAAW,CAMzD,CAAA;AAEF;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAEhE"}
@@ -9,5 +9,5 @@ export declare const name = "@lifi/perps-sdk";
9
9
  *
10
10
  * @public
11
11
  */
12
- export declare const version = "20.1.1";
12
+ export declare const version = "21.1.0";
13
13
  //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { type DecimalString, type Market } from '@lifi/perps-types';
2
+ import type { PerpsSDKClient } from '../types/provider.js';
3
+ /** @public */
4
+ export interface OrderAmountsInput {
5
+ sdk: PerpsSDKClient;
6
+ market: Market;
7
+ /** The field the user typed; the other two are calculated from it. */
8
+ held: 'margin' | 'size' | 'notional';
9
+ amount: DecimalString;
10
+ leverage: number;
11
+ price: DecimalString;
12
+ /** Decimals for the quote-asset amounts (margin, notional). Default 2. */
13
+ quoteDecimals?: number;
14
+ }
15
+ /** @public */
16
+ export interface OrderAmounts {
17
+ /**
18
+ * On the `quoteDecimals` grid: rounded up when derived, so it funds `size`
19
+ * at the requested leverage, and truncated when the user holds it.
20
+ */
21
+ margin: DecimalString;
22
+ /** Snapped onto the venue lot grid. */
23
+ size: DecimalString;
24
+ /** Truncated to `quoteDecimals`. */
25
+ notional: DecimalString;
26
+ }
27
+ /**
28
+ * The three order-entry amounts, derived from whichever one the user typed.
29
+ *
30
+ * The held field is normalised first — truncated to `quoteDecimals` for a
31
+ * margin or notional, snapped onto the venue lot grid for a size — and the
32
+ * other two are then derived from that normalised value, so the three agree
33
+ * with each other rather than with an input the user cannot see.
34
+ *
35
+ * Rounding is directional, so the result always funds itself:
36
+ * `size × price ≤ margin × leverage`. A derived size truncates onto the lot
37
+ * grid and a derived notional truncates onto the quote grid, but a derived
38
+ * margin rounds **up** onto the quote grid, because it is the one amount that
39
+ * has to cover the others rather than cap them.
40
+ *
41
+ * Formulas: `size = margin × leverage ÷ price`,
42
+ * `margin = size × price ÷ leverage`, `notional = size × price`
43
+ * (or `margin × leverage` when the margin is held).
44
+ *
45
+ * @returns `null` when `amount` or `price` is not a positive decimal string,
46
+ * when `leverage` is not a positive finite number, or when the venue and
47
+ * quote grids snap the result to a non-positive amount — a sub-lot size or
48
+ * a sub-cent quote amount describes no order a venue can take.
49
+ * @throws {PerpsError} `ValidationError` when `quoteDecimals` is not a
50
+ * non-negative integer, or `SDKError` when `market.providerId` names no
51
+ * registered provider plugin.
52
+ * @public
53
+ */
54
+ export declare function calculateOrderAmounts(input: OrderAmountsInput): OrderAmounts | null;
55
+ //# sourceMappingURL=orderAmounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orderAmounts.d.ts","sourceRoot":"","sources":["../../../src/wire/orderAmounts.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,MAAM,EAEZ,MAAM,mBAAmB,CAAA;AAI1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAG1D,cAAc;AACd,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,sEAAsE;IACtE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAA;IACpC,MAAM,EAAE,aAAa,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,aAAa,CAAA;IACpB,0EAA0E;IAC1E,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,cAAc;AACd,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,MAAM,EAAE,aAAa,CAAA;IACrB,uCAAuC;IACvC,IAAI,EAAE,aAAa,CAAA;IACnB,oCAAoC;IACpC,QAAQ,EAAE,aAAa,CAAA;CACxB;AAqDD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,iBAAiB,GACvB,YAAY,GAAG,IAAI,CAqDrB"}
@@ -0,0 +1,28 @@
1
+ import { type DecimalString } from '@lifi/perps-types';
2
+ /** @public */
3
+ export interface RefuelAmountInput {
4
+ /** USD value of the gas the route recommends. */
5
+ gasUsd: DecimalString;
6
+ /** USD price of one whole source token. */
7
+ priceUsd: DecimalString;
8
+ /** Decimals of the source token, which the result is spelled to exactly. */
9
+ decimals: number;
10
+ }
11
+ /**
12
+ * Source-token amount whose USD value covers `gasUsd`, rounded **up** onto
13
+ * the token's decimal grid so a refuel never lands short of the
14
+ * recommendation. The result keeps trailing zeros to `decimals`, so it seeds
15
+ * an amount input at the token's own precision.
16
+ *
17
+ * The quotient does not terminate for most prices, which is why this is a
18
+ * big.js primitive: an 18-decimal token needs a ceiling at 10^-18, far past
19
+ * what a `number` can carry.
20
+ *
21
+ * @returns `undefined` when `gasUsd` or `priceUsd` is not greater than zero,
22
+ * which is a route with nothing to refuel rather than a failure.
23
+ * @throws {PerpsError} `ValidationError` when `gasUsd` or `priceUsd` is not a
24
+ * {@link DecimalString}, or when `decimals` is not a non-negative integer.
25
+ * @public
26
+ */
27
+ export declare function calculateRefuelAmount(input: RefuelAmountInput): DecimalString | undefined;
28
+ //# sourceMappingURL=refuel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refuel.d.ts","sourceRoot":"","sources":["../../../src/wire/refuel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,mBAAmB,CAAA;AAKtE,cAAc;AACd,MAAM,WAAW,iBAAiB;IAChC,iDAAiD;IACjD,MAAM,EAAE,aAAa,CAAA;IACrB,2CAA2C;IAC3C,QAAQ,EAAE,aAAa,CAAA;IACvB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,iBAAiB,GACvB,aAAa,GAAG,SAAS,CAiB3B"}
@@ -0,0 +1,11 @@
1
+ import { type DecimalString } from '@lifi/perps-types';
2
+ import Big from 'big.js';
3
+ /**
4
+ * Parse a wire-tier decimal input, naming the field it came from when the
5
+ * value breaks the {@link DecimalString} contract, so a malformed amount
6
+ * fails at the SDK boundary instead of inside big.js.
7
+ *
8
+ * @throws {PerpsError} `ValidationError` naming `field`.
9
+ */
10
+ export declare function requireDecimal(value: DecimalString, field: string): Big;
11
+ //# sourceMappingURL=requireDecimal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requireDecimal.d.ts","sourceRoot":"","sources":["../../../src/wire/requireDecimal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,GAAG,MAAM,QAAQ,CAAA;AAGxB;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,CAQvE"}
@@ -0,0 +1,24 @@
1
+ import type { DecimalString, Market } from '@lifi/perps-types';
2
+ import type { PerpsSDKClient } from '../types/provider.js';
3
+ /**
4
+ * Snap `size` onto the lot grid of `market`'s venue, truncating toward zero,
5
+ * through the market's own provider. Takes and gives a {@link DecimalString},
6
+ * so a caller never converts an order size to a `number`.
7
+ *
8
+ * @throws {PerpsError} `SDKError` when `market.providerId` names no registered
9
+ * provider plugin.
10
+ * @public
11
+ */
12
+ export declare function snapOrderSize(sdk: PerpsSDKClient, market: Market, size: DecimalString): DecimalString;
13
+ /**
14
+ * Snap `price` onto the tick grid of `market`'s venue, rounding half-up,
15
+ * through the market's own provider. Takes and gives a {@link DecimalString},
16
+ * so a caller never converts an order price to a `number`.
17
+ *
18
+ * @throws {PerpsError} `SDKError` when `market.providerId` names no registered
19
+ * provider plugin, or `ValidationError` when the market lacks the tick
20
+ * metadata the venue's rules need.
21
+ * @public
22
+ */
23
+ export declare function snapOrderPrice(sdk: PerpsSDKClient, market: Market, price: DecimalString): DecimalString;
24
+ //# sourceMappingURL=snap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snap.d.ts","sourceRoot":"","sources":["../../../src/wire/snap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,aAAa,GAClB,aAAa,CAEf;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,aAAa,GACnB,aAAa,CAEf"}
@@ -0,0 +1,15 @@
1
+ import type { DecimalString } from '@lifi/perps-types';
2
+ /**
3
+ * The part of `units` that a venue-wide free figure releases: never below
4
+ * zero, never above the units held. `Balance.transferable` on every provider
5
+ * is this clamp over the venue's own free-margin or unlocked-balance figure.
6
+ *
7
+ * @param venueFigure - The venue's free figure for the category, which can
8
+ * exceed `units` or fall below zero.
9
+ * @param units - Units held in the category, the upper bound of the clamp.
10
+ * @throws {PerpsError} `ValidationError` when either input is not a
11
+ * {@link DecimalString}, naming the field.
12
+ * @public
13
+ */
14
+ export declare function calculateTransferable(venueFigure: DecimalString, units: DecimalString): DecimalString;
15
+ //# sourceMappingURL=transferable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transferable.d.ts","sourceRoot":"","sources":["../../../src/wire/transferable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGtD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,aAAa,EAC1B,KAAK,EAAE,aAAa,GACnB,aAAa,CAOf"}
@@ -0,0 +1,14 @@
1
+ import type { DecimalString } from '@lifi/perps-types';
2
+ import type { WithdrawableBalance } from '../types/withdrawal.js';
3
+ /**
4
+ * Largest `amount` a withdrawable row can fund: `available` when the venue
5
+ * deducts the fee from the amount or publishes no fee, and
6
+ * `available − withdrawalFee` floored at zero when the venue charges the fee
7
+ * on top (`isFeeDeducted === false`).
8
+ *
9
+ * @throws {PerpsError} `ValidationError` when `available` or `withdrawalFee`
10
+ * is not a {@link DecimalString}, naming the field.
11
+ * @public
12
+ */
13
+ export declare function calculateWithdrawMax(row: Pick<WithdrawableBalance, 'available' | 'withdrawalFee' | 'isFeeDeducted'>): DecimalString;
14
+ //# sourceMappingURL=withdraw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withdraw.d.ts","sourceRoot":"","sources":["../../../src/wire/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAGjE;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,IAAI,CACP,mBAAmB,EACnB,WAAW,GAAG,eAAe,GAAG,eAAe,CAChD,GACA,aAAa,CASf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/perps-sdk",
3
- "version": "20.1.1",
3
+ "version": "21.1.0",
4
4
  "description": "LI.FI Perps SDK for perpetuals trading",
5
5
  "homepage": "https://github.com/lifinance/perps-sdk",
6
6
  "bugs": {
@@ -46,7 +46,7 @@
46
46
  "big.js": "^7.0.1",
47
47
  "partysocket": "^1.1.19",
48
48
  "viem": "^2.55.18",
49
- "@lifi/perps-types": "^18.1.0"
49
+ "@lifi/perps-types": "^19.0.0"
50
50
  },
51
51
  "publishConfig": {
52
52
  "access": "public"
@@ -360,7 +360,14 @@ export class PerpsClient {
360
360
  return resolveProvider(this.sdkClient, provider)
361
361
  }
362
362
 
363
- /** Read active or historical orders from the selected venue. */
363
+ /**
364
+ * Read active or historical orders from the selected venue.
365
+ *
366
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (a
367
+ * Lighter auth token or an Ondo session) and none is stored.
368
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
369
+ * @throws {PerpsError} `AccountNotFound` when the wallet has no venue account.
370
+ */
364
371
  async getOrders(
365
372
  params: GetOrdersParams,
366
373
  options?: SDKRequestOptions
@@ -368,7 +375,14 @@ export class PerpsClient {
368
375
  return fetchOrders(this.sdkClient, params, options)
369
376
  }
370
377
 
371
- /** Read one venue order through the provider's unified mapper. */
378
+ /**
379
+ * Read one venue order through the provider's unified mapper.
380
+ *
381
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (a
382
+ * Lighter auth token or an Ondo session) and none is stored.
383
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
384
+ * @throws {PerpsError} `AccountNotFound` when the wallet has no venue account.
385
+ */
372
386
  async getOrder(
373
387
  params: GetOrderParams,
374
388
  options?: SDKRequestOptions
@@ -654,6 +668,9 @@ export class PerpsClient {
654
668
  * @throws {PerpsError} When the provider plugin is not registered,
655
669
  * `ValidationError` for a spot market, or any other `PerpsError` when the
656
670
  * venue read fails or carries no usable value.
671
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (an
672
+ * Ondo session) and none is stored.
673
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
657
674
  * @public
658
675
  */
659
676
  async getMarketSettings(params: {
@@ -674,12 +691,19 @@ export class PerpsClient {
674
691
  * account displays read the account-scoped
675
692
  * {@link AccountSummary.availableMargin} instead.
676
693
  *
677
- * Providers that read a per-market figure answer it directly. For every
678
- * other provider this falls back to the account summary, so both sides
679
- * equal `availableMargin` and the asset is the market's quote asset.
694
+ * Providers that read a per-market figure answer it directly. A provider
695
+ * that has no per-market figure for the market (a Hyperliquid or Lighter
696
+ * spot market) resolves `undefined`, and this falls back to the account
697
+ * summary, so both sides equal `availableMargin` and the asset is the
698
+ * market's quote asset. A provider read that throws propagates and never
699
+ * falls back.
680
700
  *
681
701
  * @throws {PerpsError} When the provider plugin is not registered, or the
682
702
  * market is unknown to the provider's market registry.
703
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (a
704
+ * Lighter auth token or an Ondo session) and none is stored.
705
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
706
+ * @throws {PerpsError} `AccountNotFound` when the wallet has no venue account.
683
707
  * @public
684
708
  */
685
709
  async getAvailableToTrade(
@@ -813,6 +837,10 @@ export class PerpsClient {
813
837
  * @throws {PerpsError} When the provider plugin is not registered, when
814
838
  * either the plugin read or the asset sync fails, when a row's
815
839
  * `withdrawalFee` is not a non-negative decimal.
840
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (a
841
+ * Lighter auth token or an Ondo session) and none is stored.
842
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
843
+ * @throws {PerpsError} `AccountNotFound` when the wallet has no venue account.
816
844
  * @public
817
845
  */
818
846
  async getWithdrawableBalances(
@@ -849,7 +877,9 @@ export class PerpsClient {
849
877
  }
850
878
  }
851
879
  if (row.withdrawalFee === undefined) {
852
- return [{ asset, route: row.route, available: row.available }]
880
+ return [
881
+ { asset, route: row.route, available: row.available, max: row.max },
882
+ ]
853
883
  }
854
884
  if (!isNonNegativeDecimal(row.withdrawalFee)) {
855
885
  throw new PerpsError(
@@ -862,6 +892,7 @@ export class PerpsClient {
862
892
  asset,
863
893
  route: row.route,
864
894
  available: row.available,
895
+ max: row.max,
865
896
  withdrawalFee: row.withdrawalFee,
866
897
  ...(row.isFeeDeducted === undefined
867
898
  ? {}
@@ -877,6 +908,10 @@ export class PerpsClient {
877
908
  *
878
909
  * @throws {PerpsError} When the provider plugin is not registered, when it
879
910
  * declares no portfolio history read, or when the venue read fails.
911
+ * @throws {PerpsError} `SetupRequired` when the venue needs a credential (a
912
+ * Lighter auth token or an Ondo session) and none is stored.
913
+ * @throws {PerpsError} `Unauthorized` when the venue rejects the credential.
914
+ * @throws {PerpsError} `AccountNotFound` when the wallet has no venue account.
880
915
  * @public
881
916
  */
882
917
  async getPortfolioHistory(
@@ -0,0 +1,164 @@
1
+ import { type DecimalString, PerpsErrorCode } from '@lifi/perps-types'
2
+ import Big from 'big.js'
3
+ import { formatUnits } from 'viem'
4
+ import { PerpsError } from '../errors/PerpsError.js'
5
+ import { parseDecimal } from './parse.js'
6
+
7
+ /**
8
+ * Off-grid resolution for {@link decimalToBaseUnits}:
9
+ * - `truncate` — toward zero, for sizes and collateral amounts. The wire
10
+ * value never exceeds the caller's intent.
11
+ * - `round` — half away from zero, for prices, which snap to the nearest
12
+ * tick.
13
+ * @public
14
+ */
15
+ export type BaseUnitsRounding = 'truncate' | 'round'
16
+
17
+ /**
18
+ * @deprecated Use `BaseUnitsRounding`. Removed in the next major.
19
+ */
20
+ export type ScaleToIntegerPolicy = BaseUnitsRounding
21
+
22
+ /**
23
+ * Scale a decimal string to a scaled integer in exact decimal arithmetic — an
24
+ * on-grid input maps to its exact scaled integer with no binary float
25
+ * artifacts (`'0.29'` at 2 decimals is 29, never 28). Off-grid input resolves
26
+ * per `rounding`; there is no silent default.
27
+ *
28
+ * @throws {PerpsError} `ValidationError` when `value` is not a decimal
29
+ * numeric string, `decimals` is not a non-negative integer, or the scaled
30
+ * result's magnitude exceeds `Number.MAX_SAFE_INTEGER`.
31
+ * @public
32
+ */
33
+ export const decimalToBaseUnits = (
34
+ value: DecimalString,
35
+ decimals: number,
36
+ rounding: BaseUnitsRounding
37
+ ): number => {
38
+ if (!Number.isInteger(decimals) || decimals < 0) {
39
+ throw new PerpsError(
40
+ PerpsErrorCode.ValidationError,
41
+ `Invalid decimals for integer scaling: ${decimals}`
42
+ )
43
+ }
44
+ let parsed: Big
45
+ try {
46
+ parsed = new Big(value)
47
+ } catch {
48
+ throw new PerpsError(
49
+ PerpsErrorCode.ValidationError,
50
+ `Invalid decimal string for integer scaling: '${value}'`
51
+ )
52
+ }
53
+ const scaled = parsed
54
+ .times(new Big(10).pow(decimals))
55
+ .round(0, rounding === 'truncate' ? Big.roundDown : Big.roundHalfUp)
56
+ if (scaled.abs().gt(Number.MAX_SAFE_INTEGER)) {
57
+ throw new PerpsError(
58
+ PerpsErrorCode.ValidationError,
59
+ `Scaled value ${scaled.toFixed()} exceeds Number.MAX_SAFE_INTEGER and cannot be encoded exactly.`
60
+ )
61
+ }
62
+ return scaled.toNumber()
63
+ }
64
+
65
+ /**
66
+ * @deprecated Use `decimalToBaseUnits`. Removed in the next major.
67
+ */
68
+ export const scaleToInteger = decimalToBaseUnits
69
+
70
+ /**
71
+ * Convert a base-unit amount (bigint string) to a decimal string.
72
+ *
73
+ * @param amount - Amount in base units (e.g. "1000000" for 1 USDC)
74
+ * @param decimals - Token decimals (e.g. 6 for USDC)
75
+ * @returns Decimal string; `"0"` when `amount` is not a valid bigint
76
+ * @example
77
+ * ```ts
78
+ * baseUnitsToDecimal('1000000', 6) // '1'
79
+ * ```
80
+ * @public
81
+ */
82
+ export function baseUnitsToDecimal(
83
+ amount: string,
84
+ decimals: number
85
+ ): DecimalString {
86
+ try {
87
+ return formatUnits(BigInt(amount), decimals)
88
+ } catch {
89
+ return '0'
90
+ }
91
+ }
92
+
93
+ /**
94
+ * @deprecated Use `baseUnitsToDecimal`. Removed in the next major.
95
+ */
96
+ export const fromBaseUnits = baseUnitsToDecimal
97
+
98
+ /**
99
+ * @deprecated Compose `parseDecimal(baseUnitsToDecimal(...))`. Removed in the
100
+ * next major.
101
+ */
102
+ export function fromBaseUnitsNumber(amount: string, decimals: number): number {
103
+ return parseDecimal(baseUnitsToDecimal(amount, decimals)) ?? 0
104
+ }
105
+
106
+ /**
107
+ * Round `value` down to `decimals` and pad the result to exactly that many
108
+ * decimal places. The padding is the point: this seeds a fixed-decimal input,
109
+ * where `'500.00'` and `'500'` are two renderings of one amount and the field
110
+ * wants the first. For a canonical wire amount with no trailing zeros, read
111
+ * the amount off `calculateOrderAmounts` or a provider snap instead.
112
+ *
113
+ * Exact decimal arithmetic throughout, so there is no 2^53 ceiling and no
114
+ * float artifact: `'0.01'` at 18 decimals gives
115
+ * `'0.010000000000000000'`, which `Number#toFixed` cannot.
116
+ *
117
+ * @throws {PerpsError} `ValidationError` when `value` is not a decimal
118
+ * numeric string, or `decimals` is not a non-negative integer.
119
+ * @public
120
+ */
121
+ export function truncateDecimal(
122
+ value: DecimalString,
123
+ decimals: number
124
+ ): DecimalString {
125
+ if (!Number.isInteger(decimals) || decimals < 0) {
126
+ throw new PerpsError(
127
+ PerpsErrorCode.ValidationError,
128
+ `Invalid decimals for truncation: ${decimals}`
129
+ )
130
+ }
131
+ let parsed: Big
132
+ try {
133
+ parsed = new Big(value)
134
+ } catch {
135
+ throw new PerpsError(
136
+ PerpsErrorCode.ValidationError,
137
+ `Invalid decimal string for truncation: '${value}'`
138
+ )
139
+ }
140
+ const truncated = parsed.round(decimals, Big.roundDown)
141
+ // big.js carries the sign through a round to zero; '-0.00' is not a spelling.
142
+ return (truncated.eq(0) ? new Big(0) : truncated).toFixed(decimals)
143
+ }
144
+
145
+ /**
146
+ * Spell a `number` as a {@link DecimalString} in plain notation: `1e-7`
147
+ * becomes `'0.0000001'`, never `'1e-7'`. The boundary helper for a venue or
148
+ * browser API that hands out numbers; a value already spelled as a decimal
149
+ * string must not round-trip through here, because above 15 significant
150
+ * digits the `number` has already lost digits.
151
+ *
152
+ * @throws {PerpsError} `ValidationError` when `value` is `NaN` or infinite.
153
+ * @public
154
+ */
155
+ export function numberToDecimalString(value: number): DecimalString {
156
+ if (!Number.isFinite(value)) {
157
+ throw new PerpsError(
158
+ PerpsErrorCode.ValidationError,
159
+ `Invalid number for decimal conversion: ${value}`
160
+ )
161
+ }
162
+ const parsed = new Big(value)
163
+ return (parsed.eq(0) ? new Big(0) : parsed).toFixed()
164
+ }
@@ -1,3 +1,5 @@
1
+ import type { DecimalString } from '@lifi/perps-types'
2
+
1
3
  /**
2
4
  * Parse a string to a float, stripping common formatting artefacts.
3
5
  *
@@ -10,14 +12,8 @@
10
12
  *
11
13
  * @returns Parsed number; `0` for empty/blank input, `NaN` when a non-empty
12
14
  * string contains no parseable number
13
- * @example
14
- * ```ts
15
- * stringToFloat('$1,234.50') // 1234.5
16
- * stringToFloat('') // 0
17
- * ```
18
- * @public
19
15
  */
20
- export function stringToFloat(value: string): number {
16
+ function toFloat(value: string): number {
21
17
  if (!value) {
22
18
  return 0
23
19
  }
@@ -28,27 +24,33 @@ export function stringToFloat(value: string): number {
28
24
  return parseFloat(cleaned)
29
25
  }
30
26
 
27
+ /**
28
+ * @deprecated Use `parseDecimal`. Removed in the next major.
29
+ */
30
+ export const stringToFloat = toFloat
31
+
31
32
  const FORMATTED_NUMBER =
32
33
  /^(?:[+-]\s*)?(?:\$\s*)?(?:(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?(?:\s*(?:%|USD))?$/i
33
34
 
34
35
  /**
35
- * Parse an optional decimal field, with the same formatting tolerance as {@link stringToFloat}.
36
+ * Parse an optional decimal field, tolerating currency symbols, grouping
37
+ * separators and a percentage suffix around the number.
36
38
  * Gives back `undefined` for a missing, malformed or non-finite value, and `0` for an empty string.
37
39
  *
38
40
  * @public
39
41
  */
40
42
  export function parseDecimal(
41
- value: string | null | undefined
43
+ value: DecimalString | string | null | undefined
42
44
  ): number | undefined {
43
45
  if (value == null) {
44
46
  return undefined
45
47
  }
46
48
  if (value.trim() === '') {
47
- return stringToFloat(value)
49
+ return toFloat(value)
48
50
  }
49
51
  if (!FORMATTED_NUMBER.test(value.trim())) {
50
52
  return undefined
51
53
  }
52
- const parsed = stringToFloat(value)
54
+ const parsed = toFloat(value)
53
55
  return Number.isFinite(parsed) ? parsed : undefined
54
56
  }