@lifi/perps-sdk 23.0.0 → 24.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/README.md +85 -45
  2. package/dist/cjs/client/PerpsClient.d.ts +3 -2
  3. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  4. package/dist/cjs/client/PerpsClient.js +16 -9
  5. package/dist/cjs/client/PerpsClient.js.map +1 -1
  6. package/dist/cjs/decimal/arithmetic.d.ts +13 -0
  7. package/dist/cjs/decimal/arithmetic.d.ts.map +1 -0
  8. package/dist/cjs/decimal/arithmetic.js +48 -0
  9. package/dist/cjs/decimal/arithmetic.js.map +1 -0
  10. package/dist/cjs/decimal/big.d.ts +0 -1
  11. package/dist/cjs/decimal/big.d.ts.map +1 -1
  12. package/dist/cjs/decimal/big.js +0 -4
  13. package/dist/cjs/decimal/big.js.map +1 -1
  14. package/dist/cjs/decimal/compare.d.ts +7 -0
  15. package/dist/cjs/decimal/compare.d.ts.map +1 -0
  16. package/dist/cjs/decimal/compare.js +21 -0
  17. package/dist/cjs/decimal/compare.js.map +1 -0
  18. package/dist/cjs/decimal/convert.d.ts +12 -6
  19. package/dist/cjs/decimal/convert.d.ts.map +1 -1
  20. package/dist/cjs/decimal/convert.js +36 -14
  21. package/dist/cjs/decimal/convert.js.map +1 -1
  22. package/dist/cjs/decimal/decimalStringToBig.d.ts +5 -0
  23. package/dist/cjs/decimal/decimalStringToBig.d.ts.map +1 -0
  24. package/dist/cjs/decimal/decimalStringToBig.js +27 -0
  25. package/dist/cjs/decimal/decimalStringToBig.js.map +1 -0
  26. package/dist/cjs/decimal/format.d.ts.map +1 -1
  27. package/dist/cjs/decimal/format.js +70 -49
  28. package/dist/cjs/decimal/format.js.map +1 -1
  29. package/dist/cjs/decimal/parse.d.ts +4 -3
  30. package/dist/cjs/decimal/parse.d.ts.map +1 -1
  31. package/dist/cjs/decimal/parse.js +44 -19
  32. package/dist/cjs/decimal/parse.js.map +1 -1
  33. package/dist/cjs/index.d.ts +13 -10
  34. package/dist/cjs/index.d.ts.map +1 -1
  35. package/dist/cjs/index.js +66 -7
  36. package/dist/cjs/index.js.map +1 -1
  37. package/dist/cjs/math/fills.d.ts +1 -1
  38. package/dist/cjs/math/fills.d.ts.map +1 -1
  39. package/dist/cjs/math/fills.js +28 -13
  40. package/dist/cjs/math/fills.js.map +1 -1
  41. package/dist/cjs/math/order.d.ts +27 -16
  42. package/dist/cjs/math/order.d.ts.map +1 -1
  43. package/dist/cjs/math/order.js +106 -122
  44. package/dist/cjs/math/order.js.map +1 -1
  45. package/dist/cjs/math/position.d.ts +85 -35
  46. package/dist/cjs/math/position.d.ts.map +1 -1
  47. package/dist/cjs/math/position.js +88 -91
  48. package/dist/cjs/math/position.js.map +1 -1
  49. package/dist/cjs/services/getGasRecommendation.js +1 -1
  50. package/dist/cjs/services/getGasRecommendation.js.map +1 -1
  51. package/dist/cjs/services/getQuote.d.ts +1 -1
  52. package/dist/cjs/services/resolveSubscribeQuote.d.ts.map +1 -1
  53. package/dist/cjs/services/resolveSubscribeQuote.js +3 -2
  54. package/dist/cjs/services/resolveSubscribeQuote.js.map +1 -1
  55. package/dist/cjs/transport/request.d.ts +1 -0
  56. package/dist/cjs/transport/request.d.ts.map +1 -1
  57. package/dist/cjs/transport/request.js +2 -2
  58. package/dist/cjs/transport/request.js.map +1 -1
  59. package/dist/cjs/types/api.d.ts +4 -0
  60. package/dist/cjs/types/api.d.ts.map +1 -1
  61. package/dist/cjs/types/provider.d.ts +9 -5
  62. package/dist/cjs/types/provider.d.ts.map +1 -1
  63. package/dist/cjs/types/withdrawal.d.ts +12 -4
  64. package/dist/cjs/types/withdrawal.d.ts.map +1 -1
  65. package/dist/cjs/utils/createSafeFunction.d.ts +2 -0
  66. package/dist/cjs/utils/createSafeFunction.d.ts.map +1 -0
  67. package/dist/cjs/utils/createSafeFunction.js +15 -0
  68. package/dist/cjs/utils/createSafeFunction.js.map +1 -0
  69. package/dist/cjs/utils/timestampToIsoString.d.ts +3 -0
  70. package/dist/cjs/utils/timestampToIsoString.d.ts.map +1 -0
  71. package/dist/cjs/utils/timestampToIsoString.js +16 -0
  72. package/dist/cjs/utils/timestampToIsoString.js.map +1 -0
  73. package/dist/cjs/utils/warnOnce.d.ts +2 -0
  74. package/dist/cjs/utils/warnOnce.d.ts.map +1 -1
  75. package/dist/cjs/utils/warnOnce.js +13 -1
  76. package/dist/cjs/utils/warnOnce.js.map +1 -1
  77. package/dist/cjs/version.d.ts +1 -1
  78. package/dist/cjs/version.js +1 -1
  79. package/dist/cjs/websocket/PerpsWsClient.d.ts +2 -0
  80. package/dist/cjs/websocket/PerpsWsClient.d.ts.map +1 -1
  81. package/dist/cjs/websocket/PerpsWsClient.js +14 -1
  82. package/dist/cjs/websocket/PerpsWsClient.js.map +1 -1
  83. package/dist/cjs/websocket/wsLog.d.ts +2 -0
  84. package/dist/cjs/websocket/wsLog.d.ts.map +1 -1
  85. package/dist/cjs/websocket/wsLog.js +8 -0
  86. package/dist/cjs/websocket/wsLog.js.map +1 -1
  87. package/dist/cjs/wire/orderAmounts.d.ts.map +1 -1
  88. package/dist/cjs/wire/orderAmounts.js +6 -9
  89. package/dist/cjs/wire/orderAmounts.js.map +1 -1
  90. package/dist/cjs/wire/refuel.d.ts +4 -1
  91. package/dist/cjs/wire/refuel.d.ts.map +1 -1
  92. package/dist/cjs/wire/refuel.js +23 -6
  93. package/dist/cjs/wire/refuel.js.map +1 -1
  94. package/dist/cjs/wire/transferable.js +3 -3
  95. package/dist/cjs/wire/transferable.js.map +1 -1
  96. package/dist/cjs/wire/withdraw.d.ts.map +1 -1
  97. package/dist/cjs/wire/withdraw.js +3 -3
  98. package/dist/cjs/wire/withdraw.js.map +1 -1
  99. package/dist/esm/client/PerpsClient.d.ts +17 -4
  100. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  101. package/dist/esm/client/PerpsClient.js +30 -8
  102. package/dist/esm/client/PerpsClient.js.map +1 -1
  103. package/dist/esm/decimal/arithmetic.d.ts +84 -0
  104. package/dist/esm/decimal/arithmetic.d.ts.map +1 -0
  105. package/dist/esm/decimal/arithmetic.js +110 -0
  106. package/dist/esm/decimal/arithmetic.js.map +1 -0
  107. package/dist/esm/decimal/big.d.ts +0 -2
  108. package/dist/esm/decimal/big.d.ts.map +1 -1
  109. package/dist/esm/decimal/big.js +0 -4
  110. package/dist/esm/decimal/big.js.map +1 -1
  111. package/dist/esm/decimal/compare.d.ts +45 -0
  112. package/dist/esm/decimal/compare.d.ts.map +1 -0
  113. package/dist/esm/decimal/compare.js +53 -0
  114. package/dist/esm/decimal/compare.js.map +1 -0
  115. package/dist/esm/decimal/convert.d.ts +62 -26
  116. package/dist/esm/decimal/convert.d.ts.map +1 -1
  117. package/dist/esm/decimal/convert.js +76 -25
  118. package/dist/esm/decimal/convert.js.map +1 -1
  119. package/dist/esm/decimal/decimalStringToBig.d.ts +26 -0
  120. package/dist/esm/decimal/decimalStringToBig.d.ts.map +1 -0
  121. package/dist/esm/decimal/decimalStringToBig.js +40 -0
  122. package/dist/esm/decimal/decimalStringToBig.js.map +1 -0
  123. package/dist/esm/decimal/format.d.ts +4 -1
  124. package/dist/esm/decimal/format.d.ts.map +1 -1
  125. package/dist/esm/decimal/format.js +71 -66
  126. package/dist/esm/decimal/format.js.map +1 -1
  127. package/dist/esm/decimal/parse.d.ts +26 -7
  128. package/dist/esm/decimal/parse.d.ts.map +1 -1
  129. package/dist/esm/decimal/parse.js +59 -33
  130. package/dist/esm/decimal/parse.js.map +1 -1
  131. package/dist/esm/index.d.ts +13 -10
  132. package/dist/esm/index.d.ts.map +1 -1
  133. package/dist/esm/index.js +9 -6
  134. package/dist/esm/index.js.map +1 -1
  135. package/dist/esm/math/fills.d.ts +6 -3
  136. package/dist/esm/math/fills.d.ts.map +1 -1
  137. package/dist/esm/math/fills.js +31 -16
  138. package/dist/esm/math/fills.js.map +1 -1
  139. package/dist/esm/math/order.d.ts +85 -65
  140. package/dist/esm/math/order.d.ts.map +1 -1
  141. package/dist/esm/math/order.js +158 -166
  142. package/dist/esm/math/order.js.map +1 -1
  143. package/dist/esm/math/position.d.ts +155 -98
  144. package/dist/esm/math/position.d.ts.map +1 -1
  145. package/dist/esm/math/position.js +157 -155
  146. package/dist/esm/math/position.js.map +1 -1
  147. package/dist/esm/services/getGasRecommendation.js +1 -1
  148. package/dist/esm/services/getGasRecommendation.js.map +1 -1
  149. package/dist/esm/services/getQuote.d.ts +2 -2
  150. package/dist/esm/services/getQuote.js +1 -1
  151. package/dist/esm/services/resolveSubscribeQuote.d.ts +1 -1
  152. package/dist/esm/services/resolveSubscribeQuote.d.ts.map +1 -1
  153. package/dist/esm/services/resolveSubscribeQuote.js +4 -3
  154. package/dist/esm/services/resolveSubscribeQuote.js.map +1 -1
  155. package/dist/esm/transport/request.d.ts +5 -0
  156. package/dist/esm/transport/request.d.ts.map +1 -1
  157. package/dist/esm/transport/request.js +2 -2
  158. package/dist/esm/transport/request.js.map +1 -1
  159. package/dist/esm/types/api.d.ts +9 -0
  160. package/dist/esm/types/api.d.ts.map +1 -1
  161. package/dist/esm/types/provider.d.ts +26 -13
  162. package/dist/esm/types/provider.d.ts.map +1 -1
  163. package/dist/esm/types/withdrawal.d.ts +32 -7
  164. package/dist/esm/types/withdrawal.d.ts.map +1 -1
  165. package/dist/esm/utils/createSafeFunction.d.ts +9 -0
  166. package/dist/esm/utils/createSafeFunction.d.ts.map +1 -0
  167. package/dist/esm/utils/createSafeFunction.js +19 -0
  168. package/dist/esm/utils/createSafeFunction.js.map +1 -0
  169. package/dist/esm/utils/timestampToIsoString.d.ts +15 -0
  170. package/dist/esm/utils/timestampToIsoString.d.ts.map +1 -0
  171. package/dist/esm/utils/timestampToIsoString.js +24 -0
  172. package/dist/esm/utils/timestampToIsoString.js.map +1 -0
  173. package/dist/esm/utils/warnOnce.d.ts +16 -0
  174. package/dist/esm/utils/warnOnce.d.ts.map +1 -1
  175. package/dist/esm/utils/warnOnce.js +24 -0
  176. package/dist/esm/utils/warnOnce.js.map +1 -1
  177. package/dist/esm/version.d.ts +1 -1
  178. package/dist/esm/version.js +1 -1
  179. package/dist/esm/websocket/PerpsWsClient.d.ts +7 -0
  180. package/dist/esm/websocket/PerpsWsClient.d.ts.map +1 -1
  181. package/dist/esm/websocket/PerpsWsClient.js +20 -2
  182. package/dist/esm/websocket/PerpsWsClient.js.map +1 -1
  183. package/dist/esm/websocket/wsLog.d.ts +12 -0
  184. package/dist/esm/websocket/wsLog.d.ts.map +1 -1
  185. package/dist/esm/websocket/wsLog.js +18 -0
  186. package/dist/esm/websocket/wsLog.js.map +1 -1
  187. package/dist/esm/wire/orderAmounts.d.ts.map +1 -1
  188. package/dist/esm/wire/orderAmounts.js +2 -2
  189. package/dist/esm/wire/orderAmounts.js.map +1 -1
  190. package/dist/esm/wire/refuel.d.ts +24 -14
  191. package/dist/esm/wire/refuel.d.ts.map +1 -1
  192. package/dist/esm/wire/refuel.js +38 -17
  193. package/dist/esm/wire/refuel.js.map +1 -1
  194. package/dist/esm/wire/transferable.js +3 -3
  195. package/dist/esm/wire/transferable.js.map +1 -1
  196. package/dist/esm/wire/withdraw.d.ts.map +1 -1
  197. package/dist/esm/wire/withdraw.js +3 -3
  198. package/dist/esm/wire/withdraw.js.map +1 -1
  199. package/dist/types/client/PerpsClient.d.ts +17 -4
  200. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  201. package/dist/types/decimal/arithmetic.d.ts +84 -0
  202. package/dist/types/decimal/arithmetic.d.ts.map +1 -0
  203. package/dist/types/decimal/big.d.ts +0 -2
  204. package/dist/types/decimal/big.d.ts.map +1 -1
  205. package/dist/types/decimal/compare.d.ts +45 -0
  206. package/dist/types/decimal/compare.d.ts.map +1 -0
  207. package/dist/types/decimal/convert.d.ts +62 -26
  208. package/dist/types/decimal/convert.d.ts.map +1 -1
  209. package/dist/types/decimal/decimalStringToBig.d.ts +26 -0
  210. package/dist/types/decimal/decimalStringToBig.d.ts.map +1 -0
  211. package/dist/types/decimal/format.d.ts +4 -1
  212. package/dist/types/decimal/format.d.ts.map +1 -1
  213. package/dist/types/decimal/parse.d.ts +26 -7
  214. package/dist/types/decimal/parse.d.ts.map +1 -1
  215. package/dist/types/index.d.ts +13 -10
  216. package/dist/types/index.d.ts.map +1 -1
  217. package/dist/types/math/fills.d.ts +6 -3
  218. package/dist/types/math/fills.d.ts.map +1 -1
  219. package/dist/types/math/order.d.ts +85 -65
  220. package/dist/types/math/order.d.ts.map +1 -1
  221. package/dist/types/math/position.d.ts +155 -98
  222. package/dist/types/math/position.d.ts.map +1 -1
  223. package/dist/types/services/getQuote.d.ts +2 -2
  224. package/dist/types/services/resolveSubscribeQuote.d.ts +1 -1
  225. package/dist/types/services/resolveSubscribeQuote.d.ts.map +1 -1
  226. package/dist/types/transport/request.d.ts +5 -0
  227. package/dist/types/transport/request.d.ts.map +1 -1
  228. package/dist/types/types/api.d.ts +9 -0
  229. package/dist/types/types/api.d.ts.map +1 -1
  230. package/dist/types/types/provider.d.ts +26 -13
  231. package/dist/types/types/provider.d.ts.map +1 -1
  232. package/dist/types/types/withdrawal.d.ts +32 -7
  233. package/dist/types/types/withdrawal.d.ts.map +1 -1
  234. package/dist/types/utils/createSafeFunction.d.ts +9 -0
  235. package/dist/types/utils/createSafeFunction.d.ts.map +1 -0
  236. package/dist/types/utils/timestampToIsoString.d.ts +15 -0
  237. package/dist/types/utils/timestampToIsoString.d.ts.map +1 -0
  238. package/dist/types/utils/warnOnce.d.ts +16 -0
  239. package/dist/types/utils/warnOnce.d.ts.map +1 -1
  240. package/dist/types/version.d.ts +1 -1
  241. package/dist/types/websocket/PerpsWsClient.d.ts +7 -0
  242. package/dist/types/websocket/PerpsWsClient.d.ts.map +1 -1
  243. package/dist/types/websocket/wsLog.d.ts +12 -0
  244. package/dist/types/websocket/wsLog.d.ts.map +1 -1
  245. package/dist/types/wire/orderAmounts.d.ts.map +1 -1
  246. package/dist/types/wire/refuel.d.ts +24 -14
  247. package/dist/types/wire/refuel.d.ts.map +1 -1
  248. package/dist/types/wire/withdraw.d.ts.map +1 -1
  249. package/package.json +2 -2
  250. package/src/client/PerpsClient.ts +48 -10
  251. package/src/decimal/arithmetic.ts +144 -0
  252. package/src/decimal/big.ts +0 -5
  253. package/src/decimal/compare.ts +67 -0
  254. package/src/decimal/convert.ts +123 -44
  255. package/src/decimal/decimalStringToBig.ts +47 -0
  256. package/src/decimal/format.ts +81 -68
  257. package/src/decimal/parse.ts +73 -36
  258. package/src/index.ts +76 -8
  259. package/src/math/fills.ts +32 -17
  260. package/src/math/order.ts +261 -216
  261. package/src/math/position.ts +277 -194
  262. package/src/services/getGasRecommendation.ts +1 -1
  263. package/src/services/getQuote.ts +2 -2
  264. package/src/services/resolveSubscribeQuote.ts +4 -3
  265. package/src/transport/request.ts +7 -2
  266. package/src/types/api.ts +10 -0
  267. package/src/types/provider.ts +35 -13
  268. package/src/types/withdrawal.ts +35 -8
  269. package/src/utils/createSafeFunction.ts +20 -0
  270. package/src/utils/timestampToIsoString.ts +31 -0
  271. package/src/utils/warnOnce.ts +44 -0
  272. package/src/version.ts +1 -1
  273. package/src/websocket/PerpsWsClient.ts +25 -2
  274. package/src/websocket/wsLog.ts +31 -0
  275. package/src/wire/orderAmounts.ts +3 -2
  276. package/src/wire/refuel.ts +56 -20
  277. package/src/wire/transferable.ts +3 -3
  278. package/src/wire/withdraw.ts +3 -5
  279. package/dist/cjs/decimal/requireDecimal.d.ts +0 -4
  280. package/dist/cjs/decimal/requireDecimal.d.ts.map +0 -1
  281. package/dist/cjs/decimal/requireDecimal.js +0 -17
  282. package/dist/cjs/decimal/requireDecimal.js.map +0 -1
  283. package/dist/esm/decimal/requireDecimal.d.ts +0 -11
  284. package/dist/esm/decimal/requireDecimal.d.ts.map +0 -1
  285. package/dist/esm/decimal/requireDecimal.js +0 -18
  286. package/dist/esm/decimal/requireDecimal.js.map +0 -1
  287. package/dist/types/decimal/requireDecimal.d.ts +0 -11
  288. package/dist/types/decimal/requireDecimal.d.ts.map +0 -1
  289. package/src/decimal/requireDecimal.ts +0 -21
@@ -20,6 +20,11 @@ import {
20
20
  export interface RequestOptions extends RequestInit {
21
21
  /** Per-call retry override. Falls back to the resolved client-level policy. */
22
22
  retry?: RetryPolicy | false
23
+ /**
24
+ * Send `x-lifi-perps-sdk`. Defaults to `true`. The LI.FI API CORS preflight
25
+ * does not allow the header, so a browser blocks a LI.FI API call that sends it.
26
+ */
27
+ perpsSdkHeader?: boolean
23
28
  /** Successful response metadata, delivered only after JSON decoding. */
24
29
  onResponse?: (
25
30
  headers: Headers,
@@ -40,7 +45,7 @@ export async function request<T>(
40
45
  options: RequestOptions = {},
41
46
  sdkOptions?: SDKRequestOptions
42
47
  ): Promise<T> {
43
- const { retry, onResponse, ...fetchInit } = options
48
+ const { retry, onResponse, perpsSdkHeader = true, ...fetchInit } = options
44
49
  const policy =
45
50
  retry !== undefined
46
51
  ? resolveRetryPolicy(LIFI_RETRY_DEFAULTS, retry, LIFI_REQUEST_KEY)
@@ -48,7 +53,7 @@ export async function request<T>(
48
53
 
49
54
  const headers: Record<string, string> = {
50
55
  'Content-Type': 'application/json',
51
- 'x-lifi-perps-sdk': version,
56
+ ...(perpsSdkHeader && { 'x-lifi-perps-sdk': version }),
52
57
  ...(fetchInit.headers as Record<string, string>),
53
58
  }
54
59
 
package/src/types/api.ts CHANGED
@@ -293,6 +293,16 @@ export interface GetWithdrawableBalancesParams {
293
293
  address: Address
294
294
  }
295
295
 
296
+ /**
297
+ * Parameters for {@link PerpsClient.getWithdrawalTypes}.
298
+ *
299
+ * @public
300
+ */
301
+ export interface GetWithdrawalTypesParams {
302
+ provider: string
303
+ address: Address
304
+ }
305
+
296
306
  /**
297
307
  * Parameters for {@link PerpsClient.getPortfolioHistory}.
298
308
  *
@@ -37,7 +37,11 @@ import type {
37
37
  SDKRequestOptions,
38
38
  } from './config.js'
39
39
  import type { DepositFlow } from './deposit.js'
40
- import type { ProviderWithdrawableBalance, WithdrawFlow } from './withdrawal.js'
40
+ import type {
41
+ ProviderWithdrawableBalance,
42
+ WithdrawalSourceTypes,
43
+ WithdrawFlow,
44
+ } from './withdrawal.js'
41
45
 
42
46
  /**
43
47
  * Low-level SDK client: resolved config, the optional end-user wallet, and the
@@ -147,8 +151,8 @@ export interface ActionSignerContribution {
147
151
  */
148
152
  export interface LiquidationEstimateParams {
149
153
  /** Entry price in quote currency per base unit. */
150
- entryPrice: number
151
- leverage: number
154
+ entryPrice: string
155
+ leverage: string
152
156
  /** `true` for long, `false` for short. */
153
157
  isLong: boolean
154
158
  }
@@ -199,6 +203,15 @@ export interface ProviderGetWithdrawableBalancesParams {
199
203
  address: Address
200
204
  }
201
205
 
206
+ /**
207
+ * Read params for {@link PerpsProviderPlugin.getWithdrawalTypes}.
208
+ *
209
+ * @public
210
+ */
211
+ export interface ProviderGetWithdrawalTypesParams {
212
+ address: Address
213
+ }
214
+
202
215
  /**
203
216
  * Read params for {@link PerpsProvider.getPositions}.
204
217
  *
@@ -322,7 +335,7 @@ export interface ProviderGetQuoteParams {
322
335
  /** Trade direction used to choose asks for buys or bids for sells. */
323
336
  side: QuoteSide
324
337
  /** USD notional to fill. */
325
- size: number
338
+ size: string
326
339
  /** Product family used to disambiguate spot and perpetual markets. */
327
340
  type: TradeType
328
341
  }
@@ -434,20 +447,33 @@ export interface PerpsProviderPlugin {
434
447
  ): Promise<WithdrawFlow>
435
448
 
436
449
  /**
437
- * The `(asset, route)` pairs `params.address` currently has something to
450
+ * The `(asset, category)` pairs `params.address` currently has something to
438
451
  * withdraw from, keyed by provider-native asset id. Only the venue knows how
439
- * its balance payload splits across routes, so the split is owned here; the
452
+ * its balance payload splits across categories, so the split is owned here; the
440
453
  * per-asset venue minimum is applied by `PerpsClient.getWithdrawableBalances`,
441
454
  * which holds the core asset registry.
442
455
  *
443
- * Optional: a provider whose withdrawals are not a per-route selection omits
444
- * it, and `PerpsClient.getWithdrawableBalances` then resolves `undefined`.
456
+ * Optional: a provider whose withdrawals are not a per-category selection
457
+ * omits it, and `PerpsClient.getWithdrawableBalances` then resolves
458
+ * `undefined`.
445
459
  */
446
460
  getWithdrawableBalances?(
447
461
  params: ProviderGetWithdrawableBalancesParams,
448
462
  options?: SDKRequestOptions
449
463
  ): Promise<ProviderWithdrawableBalance[]>
450
464
 
465
+ /**
466
+ * The withdrawal types `params.address` can choose per withdrawable holding,
467
+ * each with its cap and the `withdrawalOptions` to send with it.
468
+ *
469
+ * Optional: a provider with one withdrawal type omits it, and
470
+ * `PerpsClient.getWithdrawalTypes` then resolves `undefined`.
471
+ */
472
+ getWithdrawalTypes?(
473
+ params: ProviderGetWithdrawalTypesParams,
474
+ options?: SDKRequestOptions
475
+ ): Promise<WithdrawalSourceTypes[]>
476
+
451
477
  getPositions(
452
478
  params: ProviderGetPositionsParams,
453
479
  options?: SDKRequestOptions
@@ -573,10 +599,6 @@ export interface PerpsProviderPlugin {
573
599
  * positions, prefer `Position.liquidationPrice` from the venue. Pure —
574
600
  * does no I/O.
575
601
  *
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
- *
580
602
  * @returns The estimated liquidation price, or `undefined` when the venue's
581
603
  * model cannot be evaluated client-side (degenerate inputs, or `market`
582
604
  * lacks the margin metadata the model needs).
@@ -584,7 +606,7 @@ export interface PerpsProviderPlugin {
584
606
  estimateLiquidationPrice(
585
607
  market: PerpsMarket,
586
608
  params: LiquidationEstimateParams
587
- ): number | undefined
609
+ ): string | undefined
588
610
 
589
611
  /**
590
612
  * Margin that can be removed from `position` under the venue margin rules,
@@ -2,22 +2,22 @@ import type {
2
2
  ActionType,
3
3
  Asset,
4
4
  DecimalString,
5
- WithdrawalRoute,
5
+ WithdrawalAssetRef,
6
+ WithdrawalType,
6
7
  } from '@lifi/perps-types'
7
8
  import type { Address } from 'viem'
8
9
 
9
- export type { WithdrawalRoute }
10
-
11
10
  /**
12
- * One withdrawable `(asset, route)` selection as the provider reports it, keyed
13
- * by provider-native asset id and awaiting the core asset-metadata join.
11
+ * One withdrawable `(asset, category)` selection as the provider reports it,
12
+ * keyed by provider-native asset id and awaiting the core asset-metadata join.
14
13
  *
15
14
  * @public
16
15
  */
17
16
  export interface ProviderWithdrawableBalance {
18
17
  /** Provider-native `Asset.id`; never a display symbol. */
19
18
  assetId: string
20
- route: WithdrawalRoute
19
+ /** The provider category the row draws from; the same value as `Balance.categoryId`. */
20
+ categoryId: string
21
21
  /** Withdrawable amount in the asset's own units. Always greater than zero. */
22
22
  available: DecimalString
23
23
  /**
@@ -41,7 +41,7 @@ export interface ProviderWithdrawableBalance {
41
41
  }
42
42
 
43
43
  /**
44
- * One withdrawable `(asset, route)` selection a caller can act on: the amount
44
+ * One withdrawable `(asset, category)` selection a caller can act on: the amount
45
45
  * clears the asset's venue minimum, and `asset` carries the precision and
46
46
  * minimum needed to scale and validate the withdrawal.
47
47
  *
@@ -49,7 +49,8 @@ export interface ProviderWithdrawableBalance {
49
49
  */
50
50
  export interface WithdrawableBalance {
51
51
  asset: Asset
52
- route: WithdrawalRoute
52
+ /** The provider category the row draws from; the same value as `Balance.categoryId`. */
53
+ categoryId: string
53
54
  /** Withdrawable amount in the asset's own units. */
54
55
  available: DecimalString
55
56
  /**
@@ -77,6 +78,32 @@ export interface WithdrawableBalance {
77
78
  isFeeDeducted?: boolean
78
79
  }
79
80
 
81
+ /**
82
+ * One way a venue can settle a withdrawal from a holding.
83
+ *
84
+ * @public
85
+ */
86
+ export interface WithdrawalTypeOption {
87
+ type: WithdrawalType
88
+ /** Largest `amount` this type accepts from the holding, in the asset's own units. */
89
+ max: DecimalString
90
+ /**
91
+ * Provider-specific options to pass unchanged as
92
+ * `WithdrawalParams.withdrawalOptions` when the user picks this type.
93
+ */
94
+ withdrawalOptions: Record<string, unknown>
95
+ }
96
+
97
+ /**
98
+ * The withdrawal types a venue offers for one holding.
99
+ *
100
+ * @public
101
+ */
102
+ export interface WithdrawalSourceTypes {
103
+ source: WithdrawalAssetRef
104
+ options: WithdrawalTypeOption[]
105
+ }
106
+
80
107
  /**
81
108
  * The venue accepts a withdrawal to `destination` now.
82
109
  *
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Wrap a throwing function so that it gives `undefined` in place of a throw.
3
+ * The wrapper logs a warning with `name` and the error, which carries the
4
+ * stack trace.
5
+ *
6
+ * @internal
7
+ */
8
+ export function createSafeFunction<Args extends unknown[], Result>(
9
+ name: string,
10
+ throwingFunction: (...args: Args) => Result
11
+ ): (...args: Args) => Result | undefined {
12
+ return (...args) => {
13
+ try {
14
+ return throwingFunction(...args)
15
+ } catch (error) {
16
+ console.warn(`[perps-sdk] ${name} failed`, error)
17
+ return undefined
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,31 @@
1
+ import { PerpsErrorCode } from '@lifi/perps-types'
2
+ import { PerpsError } from '../errors/PerpsError.js'
3
+ import { createSafeFunction } from './createSafeFunction.js'
4
+
5
+ /**
6
+ * Read a venue time (epoch milliseconds or a date string) as an ISO-8601
7
+ * string.
8
+ *
9
+ * @throws {PerpsError} `ValidationError` when `Date` cannot read `value`.
10
+ * @public
11
+ */
12
+ export function timestampToIsoString(value: string | number): string {
13
+ const time = value === '' ? Number.NaN : new Date(value).getTime()
14
+ if (Number.isNaN(time)) {
15
+ throw new PerpsError(
16
+ PerpsErrorCode.ValidationError,
17
+ `'${String(value)}' is not a valid timestamp.`
18
+ )
19
+ }
20
+ return new Date(time).toISOString()
21
+ }
22
+
23
+ /**
24
+ * {@link timestampToIsoString}, or `undefined` with a warning when it throws.
25
+ *
26
+ * @public
27
+ */
28
+ export const safeTimestampToIsoString = createSafeFunction(
29
+ 'timestampToIsoString',
30
+ timestampToIsoString
31
+ )
@@ -27,3 +27,47 @@ export const createWarnOnce = (): ((key: string, message: string) => void) => {
27
27
  console.warn(message)
28
28
  }
29
29
  }
30
+
31
+ const MAX_VALUE_CHARS = 64
32
+
33
+ /**
34
+ * Describe a skipped venue row. The venue value is cut to a fixed length, so
35
+ * a warner key built from the text stays small.
36
+ *
37
+ * @internal
38
+ */
39
+ export const skippedRowMessage = (
40
+ source: string,
41
+ row: string,
42
+ field: string,
43
+ value: unknown,
44
+ expected: string
45
+ ): string => {
46
+ const text = String(value)
47
+ const shown =
48
+ text.length > MAX_VALUE_CHARS ? `${text.slice(0, MAX_VALUE_CHARS)}…` : text
49
+ return `[${source}] skipping ${row} row: \`${field}\` is not a valid ${expected}: '${shown}'`
50
+ }
51
+
52
+ const warnSkippedRowOnce = createWarnOnce()
53
+
54
+ /**
55
+ * Warn once for each provider, row, field and expected kind that a provider
56
+ * mapper skipped a venue row because a required field is not valid. The key
57
+ * holds no venue value, so a second bad value for the same field stays silent.
58
+ *
59
+ * @param expected - What the field must be. Defaults to `'decimal'`.
60
+ * @internal
61
+ */
62
+ export const warnSkippedVenueRow = (
63
+ provider: string,
64
+ row: string,
65
+ field: string,
66
+ value: unknown,
67
+ expected = 'decimal'
68
+ ): void => {
69
+ warnSkippedRowOnce(
70
+ `${provider}|${row}|${field}|${expected}`,
71
+ skippedRowMessage(provider, row, field, value, expected)
72
+ )
73
+ }
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 = '23.0.0'
13
+ export const version = '24.0.0'
@@ -1,4 +1,8 @@
1
- import { PerpsErrorCode, type Subscription } from '@lifi/perps-types'
1
+ import {
2
+ PerpsErrorCode,
3
+ type ProvidersResponse,
4
+ type Subscription,
5
+ } from '@lifi/perps-types'
2
6
  import { PerpsError } from '../errors/PerpsError.js'
3
7
  import { getProviders } from '../services/getProviders.js'
4
8
  import type { GetQuoteParams } from '../services/getQuote.js'
@@ -70,6 +74,7 @@ export class PerpsWsClient {
70
74
  private readonly options: PerpsWsClientOptions
71
75
  private providers = new Map<string, WsProvider>()
72
76
  private initPromises = new Map<string, Promise<WsProvider>>()
77
+ private discovery: Promise<ProvidersResponse> | undefined
73
78
  private closed = false
74
79
 
75
80
  constructor(client: PerpsSDKClient, options: PerpsWsClientOptions = {}) {
@@ -220,7 +225,7 @@ export class PerpsWsClient {
220
225
  )
221
226
  }
222
227
 
223
- const { providers } = await getProviders(this.client)
228
+ const { providers } = await this.discoverProviders()
224
229
  this.assertOpen()
225
230
 
226
231
  const providerInfo = providers.find((d) => d.key === provider)
@@ -236,4 +241,22 @@ export class PerpsWsClient {
236
241
  this.providers.set(provider, wsProvider)
237
242
  return wsProvider
238
243
  }
244
+
245
+ /**
246
+ * Shares one in-flight `/providers` request between concurrent venue
247
+ * inits. The slot clears on settlement, so a later init fetches fresh
248
+ * metadata and a rejection is never cached.
249
+ */
250
+ private discoverProviders(): Promise<ProvidersResponse> {
251
+ if (this.discovery) {
252
+ return this.discovery
253
+ }
254
+ const discovery = getProviders(this.client).finally(() => {
255
+ if (this.discovery === discovery) {
256
+ this.discovery = undefined
257
+ }
258
+ })
259
+ this.discovery = discovery
260
+ return discovery
261
+ }
239
262
  }
@@ -1,3 +1,5 @@
1
+ import { createWarnOnce, skippedRowMessage } from '../utils/warnOnce.js'
2
+
1
3
  const MAX_PAYLOAD_CHARS = 512
2
4
 
3
5
  const truncate = (raw: string): string =>
@@ -5,6 +7,8 @@ const truncate = (raw: string): string =>
5
7
  ? `${raw.slice(0, MAX_PAYLOAD_CHARS)}…(${raw.length} chars)`
6
8
  : raw
7
9
 
10
+ const warnSkippedRowOnce = createWarnOnce()
11
+
8
12
  /**
9
13
  * Structured logger for WS message-handling and subscription failures, shared
10
14
  * by the provider packages so a malformed frame, a throwing mapper, or a failed
@@ -58,6 +62,33 @@ export const wsLog = {
58
62
  `[${provider}:ws] skipping item for unknown market '${marketId}'`
59
63
  )
60
64
  },
65
+ /**
66
+ * A frame row or order-book level with a required field that is not valid.
67
+ * Only that row is skipped. Logged once at `warn` for each provider, row and
68
+ * field; the key holds no venue value.
69
+ */
70
+ skippedRow(
71
+ provider: string,
72
+ row: string,
73
+ field: string,
74
+ value: unknown
75
+ ): void {
76
+ warnSkippedRowOnce(
77
+ `${provider}|${row}|${field}`,
78
+ skippedRowMessage(`${provider}:ws`, row, field, value, 'decimal')
79
+ )
80
+ },
81
+ /**
82
+ * A frame row the mapper rejected for a reason other than one field, such as
83
+ * a lifecycle state the SDK does not carry. Logged once at `warn` for each
84
+ * provider and row; the key holds no venue value.
85
+ */
86
+ droppedRow(provider: string, row: string, reason: string): void {
87
+ warnSkippedRowOnce(
88
+ `${provider}|${row}|dropped`,
89
+ `[${provider}:ws] skipping ${row} row: ${reason}`
90
+ )
91
+ },
61
92
  /**
62
93
  * A background market-registry refetch rejected. Unknown-market items keep
63
94
  * being skipped until the next cooldown-gated retry, so logged at `warn`.
@@ -1,6 +1,7 @@
1
1
  import type { DecimalString, Market } from '@lifi/perps-types'
2
- import Big from 'big.js'
2
+ import type Big from 'big.js'
3
3
  import { DivBig, TruncBig } from '../decimal/big.js'
4
+ import { isDecimalStringZero } from '../decimal/compare.js'
4
5
  import { isDecimalString } from '../decimal/parse.js'
5
6
  import type { PerpsSDKClient } from '../types/provider.js'
6
7
  import { snapOrderSize } from './snap.js'
@@ -74,7 +75,7 @@ export function calculateOrderAmounts(
74
75
  ? amount.div(price).toFixed()
75
76
  : amount.times(leverage).div(price).toFixed()
76
77
  const size = snapOrderSize(sdk, market, requested)
77
- if (new Big(size).eq(0)) {
78
+ if (isDecimalStringZero(size)) {
78
79
  return null
79
80
  }
80
81
 
@@ -1,32 +1,55 @@
1
1
  import { type DecimalString, PerpsErrorCode } from '@lifi/perps-types'
2
+ import type Big from 'big.js'
2
3
  import { DivBig } from '../decimal/big.js'
3
- import { requireDecimal } from '../decimal/requireDecimal.js'
4
+ import { BASE_UNITS_PATTERN } from '../decimal/convert.js'
5
+ import { decimalStringToBig } from '../decimal/decimalStringToBig.js'
4
6
  import { PerpsError } from '../errors/PerpsError.js'
5
7
 
8
+ /**
9
+ * Headroom, in percent, that {@link calculateRefuelAmount} adds over the gas
10
+ * deficit to pay the refuel route's own swap and bridge fees.
11
+ *
12
+ * @public
13
+ */
14
+ export const REFUEL_FEE_MARGIN_PERCENT = 20
15
+
6
16
  /** @public */
7
17
  export interface RefuelAmountInput {
8
- /** USD value of the gas the route recommends. */
9
- gasUsd: DecimalString
18
+ /** Native gas amount the LI.FI gas suggestion recommends, in base units. */
19
+ recommendedAmount: DecimalString
20
+ /** USD value of `recommendedAmount`. */
21
+ recommendedUsd: DecimalString
22
+ /** Native balance the wallet holds on the recommendation's chain, in base units. */
23
+ nativeBalance: DecimalString
10
24
  /** USD price of one whole source token. */
11
25
  priceUsd: DecimalString
12
26
  /** Decimals of the source token, which the result is spelled to exactly. */
13
27
  decimals: number
14
28
  }
15
29
 
30
+ function requireBaseUnits(value: DecimalString, field: string): Big {
31
+ if (!BASE_UNITS_PATTERN.test(value)) {
32
+ throw new PerpsError(
33
+ PerpsErrorCode.ValidationError,
34
+ `Invalid \`${field}\`: '${value}' is not an integer base-unit string.`
35
+ )
36
+ }
37
+ return new DivBig(value)
38
+ }
39
+
16
40
  /**
17
- * Source-token amount whose USD value covers `gasUsd`, rounded **up** onto
18
- * the token's decimal grid so a refuel never lands short of the
19
- * recommendation. The result keeps trailing zeros to `decimals`, so it seeds
20
- * an amount input at the token's own precision.
21
- *
22
- * The quotient does not terminate for most prices, which is why this is a
23
- * big.js primitive: an 18-decimal token needs a ceiling at 10^-18, far past
24
- * what a `number` can carry.
41
+ * Source-token amount that buys the native gas the wallet lacks: the part of
42
+ * the recommendation above `nativeBalance`, valued pro rata on
43
+ * `recommendedUsd`, plus {@link REFUEL_FEE_MARGIN_PERCENT}. Rounded **up**
44
+ * onto the token's decimal grid so a refuel never lands short, and spelled
45
+ * with trailing zeros to `decimals` to seed an amount input.
25
46
  *
26
- * @returns `undefined` when `gasUsd` or `priceUsd` is not greater than zero,
27
- * which is a route with nothing to refuel rather than a failure.
28
- * @throws {PerpsError} `ValidationError` when `gasUsd` or `priceUsd` is not a
29
- * {@link DecimalString}, or when `decimals` is not a non-negative integer.
47
+ * @returns `undefined` when the wallet already holds the recommendation, or
48
+ * when `recommendedAmount`, `recommendedUsd` or `priceUsd` is not greater
49
+ * than zero: a route with nothing to refuel, not a failure.
50
+ * @throws {PerpsError} `ValidationError` when a base-unit field is not an
51
+ * integer string, a USD field is not a {@link DecimalString}, or `decimals`
52
+ * is not a non-negative integer.
30
53
  * @public
31
54
  */
32
55
  export function calculateRefuelAmount(
@@ -39,13 +62,26 @@ export function calculateRefuelAmount(
39
62
  `Invalid \`decimals\` for a refuel amount: ${decimals}`
40
63
  )
41
64
  }
42
- const gasUsd = requireDecimal(input.gasUsd, 'gasUsd')
43
- const priceUsd = requireDecimal(input.priceUsd, 'priceUsd')
44
- if (!gasUsd.gt(0) || !priceUsd.gt(0)) {
65
+ const recommended = requireBaseUnits(
66
+ input.recommendedAmount,
67
+ 'recommendedAmount'
68
+ )
69
+ const balance = requireBaseUnits(input.nativeBalance, 'nativeBalance')
70
+ const recommendedUsd = decimalStringToBig(input.recommendedUsd)
71
+ const priceUsd = decimalStringToBig(input.priceUsd)
72
+ const deficit = recommended.minus(balance)
73
+ if (
74
+ !recommended.gt(0) ||
75
+ !recommendedUsd.gt(0) ||
76
+ !priceUsd.gt(0) ||
77
+ !deficit.gt(0)
78
+ ) {
45
79
  return undefined
46
80
  }
47
- return new DivBig(gasUsd)
48
- .div(priceUsd)
81
+ return recommendedUsd
82
+ .times(deficit)
83
+ .times(100 + REFUEL_FEE_MARGIN_PERCENT)
84
+ .div(recommended.times(100).times(priceUsd))
49
85
  .round(decimals, DivBig.roundUp)
50
86
  .toFixed(decimals)
51
87
  }
@@ -1,5 +1,5 @@
1
1
  import type { DecimalString } from '@lifi/perps-types'
2
- import { requireDecimal } from '../decimal/requireDecimal.js'
2
+ import { decimalStringToBig } from '../decimal/decimalStringToBig.js'
3
3
 
4
4
  /**
5
5
  * The part of `units` that a venue-wide free figure releases: never below
@@ -17,8 +17,8 @@ export function calculateTransferable(
17
17
  venueFigure: DecimalString,
18
18
  units: DecimalString
19
19
  ): DecimalString {
20
- const figure = requireDecimal(venueFigure, 'venueFigure')
21
- const held = requireDecimal(units, 'units')
20
+ const figure = decimalStringToBig(venueFigure)
21
+ const held = decimalStringToBig(units)
22
22
  if (figure.lt(0)) {
23
23
  return '0'
24
24
  }
@@ -1,5 +1,5 @@
1
1
  import type { DecimalString } from '@lifi/perps-types'
2
- import { requireDecimal } from '../decimal/requireDecimal.js'
2
+ import { decimalStringToBig } from '../decimal/decimalStringToBig.js'
3
3
  import type { WithdrawableBalance } from '../types/withdrawal.js'
4
4
 
5
5
  /**
@@ -18,12 +18,10 @@ export function calculateWithdrawMax(
18
18
  'available' | 'withdrawalFee' | 'isFeeDeducted'
19
19
  >
20
20
  ): DecimalString {
21
- const available = requireDecimal(row.available, 'available')
21
+ const available = decimalStringToBig(row.available)
22
22
  if (row.isFeeDeducted !== false || row.withdrawalFee === undefined) {
23
23
  return available.toFixed()
24
24
  }
25
- const funded = available.minus(
26
- requireDecimal(row.withdrawalFee, 'withdrawalFee')
27
- )
25
+ const funded = available.minus(decimalStringToBig(row.withdrawalFee))
28
26
  return funded.gt(0) ? funded.toFixed() : '0'
29
27
  }
@@ -1,4 +0,0 @@
1
- import { type DecimalString } from '@lifi/perps-types';
2
- import Big from 'big.js';
3
- export declare function requireDecimal(value: DecimalString, field: string): Big;
4
- //# sourceMappingURL=requireDecimal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"requireDecimal.d.ts","sourceRoot":"","sources":["../../../src/decimal/requireDecimal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,mBAAmB,CAAA;AACtE,OAAO,GAAG,MAAM,QAAQ,CAAA;AAWxB,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,CAQvE"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.requireDecimal = requireDecimal;
7
- const perps_types_1 = require("@lifi/perps-types");
8
- const big_js_1 = __importDefault(require("big.js"));
9
- const PerpsError_js_1 = require("../errors/PerpsError.js");
10
- const parse_js_1 = require("./parse.js");
11
- function requireDecimal(value, field) {
12
- if (!(0, parse_js_1.isDecimalString)(value)) {
13
- throw new PerpsError_js_1.PerpsError(perps_types_1.PerpsErrorCode.ValidationError, `Invalid \`${field}\`: '${value}' is not a decimal string.`);
14
- }
15
- return new big_js_1.default(value);
16
- }
17
- //# sourceMappingURL=requireDecimal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"requireDecimal.js","sourceRoot":"","sources":["../../../src/decimal/requireDecimal.ts"],"names":[],"mappings":";;;;;AAYA,wCAQC;AApBD,mDAAsE;AACtE,oDAAwB;AACxB,2DAAoD;AACpD,yCAA4C;AAS5C,SAAgB,cAAc,CAAC,KAAoB,EAAE,KAAa;IAChE,IAAI,CAAC,IAAA,0BAAe,EAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,0BAAU,CAClB,4BAAc,CAAC,eAAe,EAC9B,aAAa,KAAK,QAAQ,KAAK,4BAA4B,CAC5D,CAAA;IACH,CAAC;IACD,OAAO,IAAI,gBAAG,CAAC,KAAK,CAAC,CAAA;AACvB,CAAC"}
@@ -1,11 +0,0 @@
1
- import { type DecimalString } from '@lifi/perps-types';
2
- import Big from 'big.js';
3
- /**
4
- * Parse a 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"requireDecimal.d.ts","sourceRoot":"","sources":["../../../src/decimal/requireDecimal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,mBAAmB,CAAA;AACtE,OAAO,GAAG,MAAM,QAAQ,CAAA;AAIxB;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,CAQvE"}
@@ -1,18 +0,0 @@
1
- import { PerpsErrorCode } from '@lifi/perps-types';
2
- import Big from 'big.js';
3
- import { PerpsError } from '../errors/PerpsError.js';
4
- import { isDecimalString } from './parse.js';
5
- /**
6
- * Parse a decimal input, naming the field it came from when the
7
- * value breaks the {@link DecimalString} contract, so a malformed amount
8
- * fails at the SDK boundary instead of inside big.js.
9
- *
10
- * @throws {PerpsError} `ValidationError` naming `field`.
11
- */
12
- export function requireDecimal(value, field) {
13
- if (!isDecimalString(value)) {
14
- throw new PerpsError(PerpsErrorCode.ValidationError, `Invalid \`${field}\`: '${value}' is not a decimal string.`);
15
- }
16
- return new Big(value);
17
- }
18
- //# sourceMappingURL=requireDecimal.js.map