@lifi/perps-sdk 20.1.0 → 21.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 (320) 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/resolveQuote.d.ts.map +1 -1
  36. package/dist/cjs/services/resolveQuote.js +2 -2
  37. package/dist/cjs/services/resolveQuote.js.map +1 -1
  38. package/dist/cjs/services/resolveSubscribeQuote.d.ts.map +1 -1
  39. package/dist/cjs/services/resolveSubscribeQuote.js +2 -2
  40. package/dist/cjs/services/resolveSubscribeQuote.js.map +1 -1
  41. package/dist/cjs/types/provider.d.ts +3 -3
  42. package/dist/cjs/types/provider.d.ts.map +1 -1
  43. package/dist/cjs/types/withdrawal.d.ts +7 -5
  44. package/dist/cjs/types/withdrawal.d.ts.map +1 -1
  45. package/dist/cjs/utils/orderClassification.d.ts +1 -3
  46. package/dist/cjs/utils/orderClassification.d.ts.map +1 -1
  47. package/dist/cjs/utils/orderClassification.js +1 -15
  48. package/dist/cjs/utils/orderClassification.js.map +1 -1
  49. package/dist/cjs/version.d.ts +1 -1
  50. package/dist/cjs/version.js +1 -1
  51. package/dist/cjs/wire/orderAmounts.d.ts +18 -0
  52. package/dist/cjs/wire/orderAmounts.d.ts.map +1 -0
  53. package/dist/cjs/wire/orderAmounts.js +79 -0
  54. package/dist/cjs/wire/orderAmounts.js.map +1 -0
  55. package/dist/cjs/wire/refuel.d.ts +8 -0
  56. package/dist/cjs/wire/refuel.d.ts.map +1 -0
  57. package/dist/cjs/wire/refuel.js +23 -0
  58. package/dist/cjs/wire/refuel.js.map +1 -0
  59. package/dist/cjs/wire/requireDecimal.d.ts +4 -0
  60. package/dist/cjs/wire/requireDecimal.d.ts.map +1 -0
  61. package/dist/cjs/wire/requireDecimal.js +16 -0
  62. package/dist/cjs/wire/requireDecimal.js.map +1 -0
  63. package/dist/cjs/wire/snap.d.ts +5 -0
  64. package/dist/cjs/wire/snap.d.ts.map +1 -0
  65. package/dist/cjs/wire/snap.js +12 -0
  66. package/dist/cjs/wire/snap.js.map +1 -0
  67. package/dist/cjs/wire/transferable.d.ts +3 -0
  68. package/dist/cjs/wire/transferable.d.ts.map +1 -0
  69. package/dist/cjs/wire/transferable.js +13 -0
  70. package/dist/cjs/wire/transferable.js.map +1 -0
  71. package/dist/cjs/wire/withdraw.d.ts +4 -0
  72. package/dist/cjs/wire/withdraw.d.ts.map +1 -0
  73. package/dist/cjs/wire/withdraw.js +13 -0
  74. package/dist/cjs/wire/withdraw.js.map +1 -0
  75. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  76. package/dist/esm/client/PerpsClient.js +4 -1
  77. package/dist/esm/client/PerpsClient.js.map +1 -1
  78. package/dist/esm/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
  79. package/dist/esm/decimal/big.d.ts.map +1 -0
  80. package/dist/esm/{utils/decimal.js → decimal/big.js} +1 -1
  81. package/dist/esm/decimal/big.js.map +1 -0
  82. package/dist/esm/decimal/convert.d.ts +80 -0
  83. package/dist/esm/decimal/convert.d.ts.map +1 -0
  84. package/dist/esm/decimal/convert.js +118 -0
  85. package/dist/esm/decimal/convert.js.map +1 -0
  86. package/dist/esm/decimal/format.d.ts.map +1 -0
  87. package/dist/esm/decimal/format.js.map +1 -0
  88. package/dist/esm/decimal/parse.d.ts +29 -0
  89. package/dist/esm/decimal/parse.d.ts.map +1 -0
  90. package/dist/esm/{utils → decimal}/parse.js +9 -10
  91. package/dist/esm/decimal/parse.js.map +1 -0
  92. package/dist/esm/index.d.ts +17 -15
  93. package/dist/esm/index.d.ts.map +1 -1
  94. package/dist/esm/index.js +12 -12
  95. package/dist/esm/index.js.map +1 -1
  96. package/dist/esm/math/fills.d.ts +26 -0
  97. package/dist/esm/math/fills.d.ts.map +1 -0
  98. package/dist/esm/{utils/fillClassification.js → math/fills.js} +26 -2
  99. package/dist/esm/math/fills.js.map +1 -0
  100. package/dist/esm/{utils/calculations.d.ts → math/order.d.ts} +70 -75
  101. package/dist/esm/math/order.d.ts.map +1 -0
  102. package/dist/esm/{utils/calculations.js → math/order.js} +155 -111
  103. package/dist/esm/math/order.js.map +1 -0
  104. package/dist/esm/math/position.d.ts +211 -0
  105. package/dist/esm/math/position.d.ts.map +1 -0
  106. package/dist/esm/math/position.js +299 -0
  107. package/dist/esm/math/position.js.map +1 -0
  108. package/dist/esm/services/resolveQuote.d.ts.map +1 -1
  109. package/dist/esm/services/resolveQuote.js +1 -1
  110. package/dist/esm/services/resolveQuote.js.map +1 -1
  111. package/dist/esm/services/resolveSubscribeQuote.d.ts.map +1 -1
  112. package/dist/esm/services/resolveSubscribeQuote.js +1 -1
  113. package/dist/esm/services/resolveSubscribeQuote.js.map +1 -1
  114. package/dist/esm/types/provider.d.ts +23 -11
  115. package/dist/esm/types/provider.d.ts.map +1 -1
  116. package/dist/esm/types/withdrawal.d.ts +17 -5
  117. package/dist/esm/types/withdrawal.d.ts.map +1 -1
  118. package/dist/esm/utils/orderClassification.d.ts +1 -14
  119. package/dist/esm/utils/orderClassification.d.ts.map +1 -1
  120. package/dist/esm/utils/orderClassification.js +1 -25
  121. package/dist/esm/utils/orderClassification.js.map +1 -1
  122. package/dist/esm/version.d.ts +1 -1
  123. package/dist/esm/version.js +1 -1
  124. package/dist/esm/wire/orderAmounts.d.ts +55 -0
  125. package/dist/esm/wire/orderAmounts.d.ts.map +1 -0
  126. package/dist/esm/wire/orderAmounts.js +114 -0
  127. package/dist/esm/wire/orderAmounts.js.map +1 -0
  128. package/dist/esm/wire/refuel.d.ts +28 -0
  129. package/dist/esm/wire/refuel.d.ts.map +1 -0
  130. package/dist/esm/wire/refuel.js +36 -0
  131. package/dist/esm/wire/refuel.js.map +1 -0
  132. package/dist/esm/wire/requireDecimal.d.ts +11 -0
  133. package/dist/esm/wire/requireDecimal.d.ts.map +1 -0
  134. package/dist/esm/wire/requireDecimal.js +17 -0
  135. package/dist/esm/wire/requireDecimal.js.map +1 -0
  136. package/dist/esm/wire/snap.d.ts +24 -0
  137. package/dist/esm/wire/snap.d.ts.map +1 -0
  138. package/dist/esm/wire/snap.js +27 -0
  139. package/dist/esm/wire/snap.js.map +1 -0
  140. package/dist/esm/wire/transferable.d.ts +15 -0
  141. package/dist/esm/wire/transferable.d.ts.map +1 -0
  142. package/dist/esm/wire/transferable.js +22 -0
  143. package/dist/esm/wire/transferable.js.map +1 -0
  144. package/dist/esm/wire/withdraw.d.ts +14 -0
  145. package/dist/esm/wire/withdraw.d.ts.map +1 -0
  146. package/dist/esm/wire/withdraw.js +20 -0
  147. package/dist/esm/wire/withdraw.js.map +1 -0
  148. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  149. package/dist/types/{utils/decimal.d.ts → decimal/big.d.ts} +1 -1
  150. package/dist/types/decimal/big.d.ts.map +1 -0
  151. package/dist/types/decimal/convert.d.ts +80 -0
  152. package/dist/types/decimal/convert.d.ts.map +1 -0
  153. package/dist/types/decimal/format.d.ts.map +1 -0
  154. package/dist/types/decimal/parse.d.ts +29 -0
  155. package/dist/types/decimal/parse.d.ts.map +1 -0
  156. package/dist/types/index.d.ts +17 -15
  157. package/dist/types/index.d.ts.map +1 -1
  158. package/dist/types/math/fills.d.ts +26 -0
  159. package/dist/types/math/fills.d.ts.map +1 -0
  160. package/dist/types/{utils/calculations.d.ts → math/order.d.ts} +70 -75
  161. package/dist/types/math/order.d.ts.map +1 -0
  162. package/dist/types/math/position.d.ts +211 -0
  163. package/dist/types/math/position.d.ts.map +1 -0
  164. package/dist/types/services/resolveQuote.d.ts.map +1 -1
  165. package/dist/types/services/resolveSubscribeQuote.d.ts.map +1 -1
  166. package/dist/types/types/provider.d.ts +23 -11
  167. package/dist/types/types/provider.d.ts.map +1 -1
  168. package/dist/types/types/withdrawal.d.ts +17 -5
  169. package/dist/types/types/withdrawal.d.ts.map +1 -1
  170. package/dist/types/utils/orderClassification.d.ts +1 -14
  171. package/dist/types/utils/orderClassification.d.ts.map +1 -1
  172. package/dist/types/version.d.ts +1 -1
  173. package/dist/types/wire/orderAmounts.d.ts +55 -0
  174. package/dist/types/wire/orderAmounts.d.ts.map +1 -0
  175. package/dist/types/wire/refuel.d.ts +28 -0
  176. package/dist/types/wire/refuel.d.ts.map +1 -0
  177. package/dist/types/wire/requireDecimal.d.ts +11 -0
  178. package/dist/types/wire/requireDecimal.d.ts.map +1 -0
  179. package/dist/types/wire/snap.d.ts +24 -0
  180. package/dist/types/wire/snap.d.ts.map +1 -0
  181. package/dist/types/wire/transferable.d.ts +15 -0
  182. package/dist/types/wire/transferable.d.ts.map +1 -0
  183. package/dist/types/wire/withdraw.d.ts +14 -0
  184. package/dist/types/wire/withdraw.d.ts.map +1 -0
  185. package/package.json +2 -2
  186. package/src/client/PerpsClient.ts +4 -1
  187. package/src/decimal/convert.ts +164 -0
  188. package/src/{utils → decimal}/parse.ts +13 -11
  189. package/src/index.ts +80 -57
  190. package/src/{utils/fillClassification.ts → math/fills.ts} +30 -1
  191. package/src/{utils/calculations.ts → math/order.ts} +205 -127
  192. package/src/{utils/positionMath.ts → math/position.ts} +173 -21
  193. package/src/services/resolveQuote.ts +1 -1
  194. package/src/services/resolveSubscribeQuote.ts +1 -1
  195. package/src/types/provider.ts +23 -10
  196. package/src/types/withdrawal.ts +22 -5
  197. package/src/utils/orderClassification.ts +0 -30
  198. package/src/version.ts +1 -1
  199. package/src/wire/orderAmounts.ts +172 -0
  200. package/src/wire/refuel.ts +51 -0
  201. package/src/wire/requireDecimal.ts +24 -0
  202. package/src/wire/snap.ts +38 -0
  203. package/src/wire/transferable.ts +26 -0
  204. package/src/wire/withdraw.ts +29 -0
  205. package/dist/cjs/utils/calculations.d.ts +0 -47
  206. package/dist/cjs/utils/calculations.d.ts.map +0 -1
  207. package/dist/cjs/utils/calculations.js +0 -214
  208. package/dist/cjs/utils/calculations.js.map +0 -1
  209. package/dist/cjs/utils/decimal.d.ts.map +0 -1
  210. package/dist/cjs/utils/decimal.js.map +0 -1
  211. package/dist/cjs/utils/fillClassification.d.ts +0 -3
  212. package/dist/cjs/utils/fillClassification.d.ts.map +0 -1
  213. package/dist/cjs/utils/fillClassification.js.map +0 -1
  214. package/dist/cjs/utils/format.d.ts.map +0 -1
  215. package/dist/cjs/utils/format.js.map +0 -1
  216. package/dist/cjs/utils/math.d.ts +0 -4
  217. package/dist/cjs/utils/math.d.ts.map +0 -1
  218. package/dist/cjs/utils/math.js +0 -8
  219. package/dist/cjs/utils/math.js.map +0 -1
  220. package/dist/cjs/utils/orderEntry.d.ts +0 -6
  221. package/dist/cjs/utils/orderEntry.d.ts.map +0 -1
  222. package/dist/cjs/utils/orderEntry.js +0 -20
  223. package/dist/cjs/utils/orderEntry.js.map +0 -1
  224. package/dist/cjs/utils/orderMath.d.ts +0 -6
  225. package/dist/cjs/utils/orderMath.d.ts.map +0 -1
  226. package/dist/cjs/utils/orderMath.js +0 -85
  227. package/dist/cjs/utils/orderMath.js.map +0 -1
  228. package/dist/cjs/utils/parse.d.ts +0 -3
  229. package/dist/cjs/utils/parse.d.ts.map +0 -1
  230. package/dist/cjs/utils/parse.js.map +0 -1
  231. package/dist/cjs/utils/positionMath.d.ts +0 -37
  232. package/dist/cjs/utils/positionMath.d.ts.map +0 -1
  233. package/dist/cjs/utils/positionMath.js +0 -99
  234. package/dist/cjs/utils/positionMath.js.map +0 -1
  235. package/dist/cjs/utils/scaleToInteger.d.ts +0 -3
  236. package/dist/cjs/utils/scaleToInteger.d.ts.map +0 -1
  237. package/dist/cjs/utils/scaleToInteger.js +0 -30
  238. package/dist/cjs/utils/scaleToInteger.js.map +0 -1
  239. package/dist/cjs/utils/units.d.ts +0 -3
  240. package/dist/cjs/utils/units.d.ts.map +0 -1
  241. package/dist/cjs/utils/units.js +0 -18
  242. package/dist/cjs/utils/units.js.map +0 -1
  243. package/dist/cjs/utils/validation.d.ts +0 -2
  244. package/dist/cjs/utils/validation.d.ts.map +0 -1
  245. package/dist/cjs/utils/validation.js +0 -16
  246. package/dist/cjs/utils/validation.js.map +0 -1
  247. package/dist/esm/utils/calculations.d.ts.map +0 -1
  248. package/dist/esm/utils/calculations.js.map +0 -1
  249. package/dist/esm/utils/decimal.d.ts.map +0 -1
  250. package/dist/esm/utils/decimal.js.map +0 -1
  251. package/dist/esm/utils/fillClassification.d.ts +0 -13
  252. package/dist/esm/utils/fillClassification.d.ts.map +0 -1
  253. package/dist/esm/utils/fillClassification.js.map +0 -1
  254. package/dist/esm/utils/format.d.ts.map +0 -1
  255. package/dist/esm/utils/format.js.map +0 -1
  256. package/dist/esm/utils/math.d.ts +0 -6
  257. package/dist/esm/utils/math.d.ts.map +0 -1
  258. package/dist/esm/utils/math.js +0 -5
  259. package/dist/esm/utils/math.js.map +0 -1
  260. package/dist/esm/utils/orderEntry.d.ts +0 -26
  261. package/dist/esm/utils/orderEntry.d.ts.map +0 -1
  262. package/dist/esm/utils/orderEntry.js +0 -34
  263. package/dist/esm/utils/orderEntry.js.map +0 -1
  264. package/dist/esm/utils/orderMath.d.ts +0 -37
  265. package/dist/esm/utils/orderMath.d.ts.map +0 -1
  266. package/dist/esm/utils/orderMath.js +0 -113
  267. package/dist/esm/utils/orderMath.js.map +0 -1
  268. package/dist/esm/utils/parse.d.ts +0 -28
  269. package/dist/esm/utils/parse.d.ts.map +0 -1
  270. package/dist/esm/utils/parse.js.map +0 -1
  271. package/dist/esm/utils/positionMath.d.ts +0 -120
  272. package/dist/esm/utils/positionMath.d.ts.map +0 -1
  273. package/dist/esm/utils/positionMath.js +0 -173
  274. package/dist/esm/utils/positionMath.js.map +0 -1
  275. package/dist/esm/utils/scaleToInteger.d.ts +0 -22
  276. package/dist/esm/utils/scaleToInteger.d.ts.map +0 -1
  277. package/dist/esm/utils/scaleToInteger.js +0 -34
  278. package/dist/esm/utils/scaleToInteger.js.map +0 -1
  279. package/dist/esm/utils/units.d.ts +0 -27
  280. package/dist/esm/utils/units.d.ts.map +0 -1
  281. package/dist/esm/utils/units.js +0 -38
  282. package/dist/esm/utils/units.js.map +0 -1
  283. package/dist/esm/utils/validation.d.ts +0 -18
  284. package/dist/esm/utils/validation.d.ts.map +0 -1
  285. package/dist/esm/utils/validation.js +0 -29
  286. package/dist/esm/utils/validation.js.map +0 -1
  287. package/dist/types/utils/calculations.d.ts.map +0 -1
  288. package/dist/types/utils/decimal.d.ts.map +0 -1
  289. package/dist/types/utils/fillClassification.d.ts +0 -13
  290. package/dist/types/utils/fillClassification.d.ts.map +0 -1
  291. package/dist/types/utils/format.d.ts.map +0 -1
  292. package/dist/types/utils/math.d.ts +0 -6
  293. package/dist/types/utils/math.d.ts.map +0 -1
  294. package/dist/types/utils/orderEntry.d.ts +0 -26
  295. package/dist/types/utils/orderEntry.d.ts.map +0 -1
  296. package/dist/types/utils/orderMath.d.ts +0 -37
  297. package/dist/types/utils/orderMath.d.ts.map +0 -1
  298. package/dist/types/utils/parse.d.ts +0 -28
  299. package/dist/types/utils/parse.d.ts.map +0 -1
  300. package/dist/types/utils/positionMath.d.ts +0 -120
  301. package/dist/types/utils/positionMath.d.ts.map +0 -1
  302. package/dist/types/utils/scaleToInteger.d.ts +0 -22
  303. package/dist/types/utils/scaleToInteger.d.ts.map +0 -1
  304. package/dist/types/utils/units.d.ts +0 -27
  305. package/dist/types/utils/units.d.ts.map +0 -1
  306. package/dist/types/utils/validation.d.ts +0 -18
  307. package/dist/types/utils/validation.d.ts.map +0 -1
  308. package/src/utils/math.ts +0 -7
  309. package/src/utils/orderEntry.ts +0 -38
  310. package/src/utils/orderMath.ts +0 -152
  311. package/src/utils/scaleToInteger.ts +0 -56
  312. package/src/utils/units.ts +0 -39
  313. package/src/utils/validation.ts +0 -38
  314. /package/dist/cjs/{utils → decimal}/format.d.ts +0 -0
  315. /package/dist/cjs/{utils → decimal}/format.js +0 -0
  316. /package/dist/esm/{utils → decimal}/format.d.ts +0 -0
  317. /package/dist/esm/{utils → decimal}/format.js +0 -0
  318. /package/dist/types/{utils → decimal}/format.d.ts +0 -0
  319. /package/src/{utils/decimal.ts → decimal/big.ts} +0 -0
  320. /package/src/{utils → decimal}/format.ts +0 -0
@@ -1,13 +1,12 @@
1
1
  /**
2
- * Universal perpetual futures calculation utilities.
3
- *
4
- * Pure functions for computing position-related values that any consumer
5
- * of the perps SDK would need. All parameters are required — no default
6
- * values for critical financial parameters.
2
+ * Display-tier order formulas. Every function takes and gives `number`;
3
+ * exact decimal arithmetic happens internally with `DivBig`.
7
4
  */
8
- import { PerpsErrorCode, } from '@lifi/perps-types';
5
+ import { OrderSide, OrderStatus, PerpsErrorCode, PositionSide, } from '@lifi/perps-types';
6
+ import { areFinite, DivBig } from '../decimal/big.js';
9
7
  import { PerpsError } from '../errors/PerpsError.js';
10
- import { areFinite, DivBig } from './decimal.js';
8
+ import { isActiveOrderStatus, isRegularOrder, isTriggerOrder, } from '../utils/orderClassification.js';
9
+ import { calculateRealizedPnl } from './position.js';
11
10
  /**
12
11
  * Calculate position size in asset units from margin.
13
12
  *
@@ -17,11 +16,11 @@ import { areFinite, DivBig } from './decimal.js';
17
16
  * @returns Position size in asset units
18
17
  * @example
19
18
  * ```ts
20
- * calculatePositionSize(100, 10, 2000) // 0.5 (ETH at $2000)
19
+ * calculateSize(100, 10, 2000) // 0.5 (ETH at $2000)
21
20
  * ```
22
21
  * @public
23
22
  */
24
- export function calculatePositionSize(marginUsd, leverage, price) {
23
+ export function calculateSize(marginUsd, leverage, price) {
25
24
  if (price === 0) {
26
25
  return (marginUsd * leverage) / price;
27
26
  }
@@ -31,68 +30,9 @@ export function calculatePositionSize(marginUsd, leverage, price) {
31
30
  return new DivBig(marginUsd).times(leverage).div(price).toNumber();
32
31
  }
33
32
  /**
34
- * Calculate notional value of a position.
35
- *
36
- * @param size - Position size in asset units
37
- * @param price - Current asset price
38
- * @returns Notional value in USD
39
- * @public
33
+ * @deprecated Use `calculateSize`. Removed in the next major.
40
34
  */
41
- export function calculateNotionalValue(size, price) {
42
- if (!areFinite(size, price)) {
43
- return Number.NaN;
44
- }
45
- return new DivBig(size).abs().times(price).toNumber();
46
- }
47
- /**
48
- * Calculate unrealized PnL.
49
- *
50
- * @param entryPrice - Position entry price
51
- * @param currentPrice - Current market price
52
- * @param size - Position size (positive for long, negative for short)
53
- * @returns Unrealized PnL in USD
54
- * @public
55
- */
56
- export function calculateUnrealizedPnl(entryPrice, currentPrice, size) {
57
- if (!areFinite(entryPrice, currentPrice, size)) {
58
- return Number.NaN;
59
- }
60
- return new DivBig(currentPrice).minus(entryPrice).times(size).toNumber();
61
- }
62
- /**
63
- * Calculate return on equity (ROE) percentage.
64
- *
65
- * @param pnl - Profit/loss in USD
66
- * @param margin - Initial margin in USD
67
- * @returns ROE as percentage (e.g., 10 for 10%)
68
- * @public
69
- */
70
- export function calculateRoe(pnl, margin) {
71
- if (margin === 0) {
72
- return 0;
73
- }
74
- if (!areFinite(pnl, margin)) {
75
- return Number.NaN;
76
- }
77
- return new DivBig(pnl).div(margin).times(100).toNumber();
78
- }
79
- /**
80
- * Calculate required margin for a position.
81
- *
82
- * @param notionalValue - Position notional value in USD
83
- * @param leverage - Position leverage
84
- * @returns Required margin in USD
85
- * @public
86
- */
87
- export function calculateRequiredMargin(notionalValue, leverage) {
88
- if (leverage === 0) {
89
- return notionalValue / leverage;
90
- }
91
- if (!areFinite(notionalValue, leverage)) {
92
- return Number.NaN;
93
- }
94
- return new DivBig(notionalValue).div(leverage).toNumber();
95
- }
35
+ export const calculatePositionSize = calculateSize;
96
36
  /**
97
37
  * Estimate trading fees.
98
38
  *
@@ -129,42 +69,6 @@ export function applySlippage(price, slippagePercent, isBuy) {
129
69
  }
130
70
  return new DivBig(price).div(multiplier).toNumber();
131
71
  }
132
- /**
133
- * Distance from the current price to the liquidation price, as a percentage of
134
- * the current price.
135
- *
136
- * @param liquidationPrice - The position's liquidation price
137
- * @param currentPrice - Current market price
138
- * @returns Absolute distance as a percentage, or 0 when current price is zero
139
- * @public
140
- */
141
- export function liquidationDistancePercent(params) {
142
- const { liquidationPrice, currentPrice } = params;
143
- if (currentPrice === 0) {
144
- return 0;
145
- }
146
- return Math.abs((liquidationPrice - currentPrice) / currentPrice) * 100;
147
- }
148
- /**
149
- * Effective leverage of an open position.
150
- *
151
- * leverage = positionValueUsd / marginUsd
152
- *
153
- * @param positionValueUsd - Position notional value in USD
154
- * @param marginUsd - Margin backing the position in USD
155
- * @returns Effective leverage, or 0 when margin is zero
156
- * @public
157
- */
158
- export function effectiveLeverage(params) {
159
- const { positionValueUsd, marginUsd } = params;
160
- if (marginUsd === 0) {
161
- return 0;
162
- }
163
- if (!areFinite(positionValueUsd, marginUsd)) {
164
- return Number.NaN;
165
- }
166
- return new DivBig(positionValueUsd).div(marginUsd).toNumber();
167
- }
168
72
  /**
169
73
  * Calculate expected gain/loss for a TP or SL trigger price.
170
74
  * Returns signed values — positive means profit, negative means loss.
@@ -191,7 +95,7 @@ export function calculateExpectedPnl(triggerPrice, entryPrice, leverage, isLong,
191
95
  return { amount: amount.toNumber(), percent: percent.toNumber() };
192
96
  }
193
97
  /**
194
- * Convert a percentage gain/loss to a target price.
98
+ * Calculate the trigger price that realises a percentage gain/loss.
195
99
  *
196
100
  * @param percent - Target gain/loss percentage (positive = profitable direction)
197
101
  * @param entryPrice - Position entry price
@@ -199,7 +103,7 @@ export function calculateExpectedPnl(triggerPrice, entryPrice, leverage, isLong,
199
103
  * @param isLong - True for long positions, false for short
200
104
  * @public
201
105
  */
202
- export function priceFromPercent(percent, entryPrice, leverage, isLong) {
106
+ export function calculateTriggerPrice(percent, entryPrice, leverage, isLong) {
203
107
  if (entryPrice === 0 || leverage === 0) {
204
108
  return 0;
205
109
  }
@@ -213,7 +117,11 @@ export function priceFromPercent(percent, entryPrice, leverage, isLong) {
213
117
  return (isLong ? entry.plus(priceDelta) : entry.minus(priceDelta)).toNumber();
214
118
  }
215
119
  /**
216
- * Convert a target price to a percentage gain/loss.
120
+ * @deprecated Use `calculateTriggerPrice`. Removed in the next major.
121
+ */
122
+ export const priceFromPercent = calculateTriggerPrice;
123
+ /**
124
+ * Calculate the percentage gain/loss a trigger price realises.
217
125
  *
218
126
  * @param price - Target price
219
127
  * @param entryPrice - Position entry price
@@ -221,7 +129,7 @@ export function priceFromPercent(percent, entryPrice, leverage, isLong) {
221
129
  * @param isLong - True for long positions, false for short
222
130
  * @public
223
131
  */
224
- export function percentFromPrice(price, entryPrice, leverage, isLong) {
132
+ export function calculateTriggerPercent(price, entryPrice, leverage, isLong) {
225
133
  if (entryPrice === 0 || leverage === 0) {
226
134
  return 0;
227
135
  }
@@ -233,6 +141,10 @@ export function percentFromPrice(price, entryPrice, leverage, isLong) {
233
141
  : new DivBig(entryPrice).minus(price);
234
142
  return priceDiff.div(entryPrice).times(leverage).times(100).toNumber();
235
143
  }
144
+ /**
145
+ * @deprecated Use `calculateTriggerPercent`. Removed in the next major.
146
+ */
147
+ export const percentFromPrice = calculateTriggerPercent;
236
148
  /**
237
149
  * Calculate realized PnL as a percentage of position value at close.
238
150
  *
@@ -345,4 +257,136 @@ export function buildQuote(input) {
345
257
  timestamp: input.timestamp,
346
258
  };
347
259
  }
348
- //# sourceMappingURL=calculations.js.map
260
+ /**
261
+ * Pick the matching open position for an order's market, if any.
262
+ *
263
+ * @param marketId - The order's `market.id`.
264
+ * @param positions - Open positions list (any market).
265
+ * @public
266
+ */
267
+ export function findMatchingPosition(marketId, positions) {
268
+ return positions.find((p) => p.market.id === marketId);
269
+ }
270
+ /**
271
+ * Resolve the close-size against a position, applying the spec's cap rules:
272
+ * - `orderSize === 0` is the Hyperliquid convention for "close entire
273
+ * position" → close the full position size.
274
+ * - Otherwise cap at the absolute position size; an order larger than the
275
+ * position can only close what's open.
276
+ *
277
+ * Inputs are non-negative magnitudes.
278
+ * @public
279
+ */
280
+ export function resolveCloseSize(orderSize, positionSize) {
281
+ if (orderSize === 0) {
282
+ return positionSize;
283
+ }
284
+ return Math.min(orderSize, positionSize);
285
+ }
286
+ /**
287
+ * Expected rPnL for a resting limit order against a matching position.
288
+ *
289
+ * Reducing requires opposite sides (long position + SELL, short position +
290
+ * BUY). Same-side orders add to the position and have no rPnL → `null`.
291
+ * Projects `remainingSize`, because an already-filled quantity has realised
292
+ * its PnL at the fill price rather than at this order's limit price. A
293
+ * `remainingSize` of zero leaves nothing to project.
294
+ */
295
+ function regularOrderRealizedPnl(order, position) {
296
+ if (!position || !isActiveOrderStatus(order.status)) {
297
+ return null;
298
+ }
299
+ const isLong = position.side === PositionSide.LONG;
300
+ const reducesPosition = (isLong && order.side === OrderSide.SELL) ||
301
+ (!isLong && order.side === OrderSide.BUY);
302
+ if (!reducesPosition) {
303
+ return null;
304
+ }
305
+ const limitPrice = Number.parseFloat(order.price ?? '');
306
+ const entryPrice = Number.parseFloat(position.entryPrice);
307
+ const orderSize = Math.abs(Number.parseFloat(order.remainingSize));
308
+ const positionSize = Math.abs(Number.parseFloat(position.size));
309
+ if (!Number.isFinite(limitPrice) ||
310
+ !Number.isFinite(entryPrice) ||
311
+ !Number.isFinite(orderSize) ||
312
+ !Number.isFinite(positionSize) ||
313
+ positionSize <= 0) {
314
+ return null;
315
+ }
316
+ // `resolveCloseSize` reads a zero size as "close the whole position", a
317
+ // convention that belongs to an order's submitted size. `remainingSize` is
318
+ // the unfilled quantity, so zero means nothing is left to fill.
319
+ if (orderSize === 0) {
320
+ return null;
321
+ }
322
+ const closeSize = resolveCloseSize(orderSize, positionSize);
323
+ return calculateRealizedPnl({
324
+ entryPrice,
325
+ closePrice: limitPrice,
326
+ closeSize,
327
+ isLong,
328
+ });
329
+ }
330
+ /** Project the unfilled closing quantity of an active trigger at its trigger price. */
331
+ function triggerOrderRealizedPnl(order, position) {
332
+ if (!position ||
333
+ !isActiveOrderStatus(order.status) ||
334
+ order.status === OrderStatus.PENDING) {
335
+ return null;
336
+ }
337
+ const isLong = position.side === PositionSide.LONG;
338
+ if ((isLong && order.side !== OrderSide.SELL) ||
339
+ (!isLong && order.side !== OrderSide.BUY)) {
340
+ return null;
341
+ }
342
+ const triggerPrice = Number.parseFloat(order.triggerPrice);
343
+ const entryPrice = Number.parseFloat(position.entryPrice);
344
+ const orderSize = Math.abs(Number.parseFloat(order.remainingSize));
345
+ const positionSize = Math.abs(Number.parseFloat(position.size));
346
+ if (!Number.isFinite(triggerPrice) ||
347
+ !Number.isFinite(entryPrice) ||
348
+ !Number.isFinite(orderSize) ||
349
+ !Number.isFinite(positionSize) ||
350
+ positionSize <= 0) {
351
+ return null;
352
+ }
353
+ if (orderSize === 0 &&
354
+ (Number.parseFloat(order.originalSize) !== 0 || !order.reduceOnly)) {
355
+ return null;
356
+ }
357
+ const closeSize = resolveCloseSize(orderSize, positionSize);
358
+ return calculateRealizedPnl({
359
+ entryPrice,
360
+ closePrice: triggerPrice,
361
+ closeSize,
362
+ isLong,
363
+ });
364
+ }
365
+ /**
366
+ * Expected rPnL an unfilled order would realise against a matching position:
367
+ * a resting limit order prices off its limit, an armed trigger off its trigger
368
+ * price. A TWAP parent carries no single execution price, so it projects
369
+ * nothing.
370
+ *
371
+ * @returns Realised PnL if the order would reduce the position, otherwise
372
+ * `null`.
373
+ * @public
374
+ */
375
+ export function estimateRealizedPnl(order, position) {
376
+ if (isTriggerOrder(order)) {
377
+ return triggerOrderRealizedPnl(order, position);
378
+ }
379
+ if (isRegularOrder(order)) {
380
+ return regularOrderRealizedPnl(order, position);
381
+ }
382
+ return null;
383
+ }
384
+ /**
385
+ * @deprecated Use `estimateRealizedPnl`. Removed in the next major.
386
+ */
387
+ export const expectedRealizedPnlForOpenOrder = regularOrderRealizedPnl;
388
+ /**
389
+ * @deprecated Use `estimateRealizedPnl`. Removed in the next major.
390
+ */
391
+ export const expectedRealizedPnlForTriggerOrder = triggerOrderRealizedPnl;
392
+ //# sourceMappingURL=order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order.js","sourceRoot":"","sources":["../../../src/math/order.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAML,SAAS,EACT,WAAW,EACX,cAAc,EAEd,YAAY,GAMb,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EACL,mBAAmB,EACnB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CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAClE,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,SAAS,GAAG,gBAAgB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;IAC3D,OAAO,oBAAoB,CAAC;QAC1B,UAAU;QACV,UAAU,EAAE,YAAY;QACxB,SAAS;QACT,MAAM;KACP,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAY,EACZ,QAA8B;IAE9B,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,uBAAuB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IACjD,CAAC;IACD,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,uBAAuB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IACjD,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,uBAAuB,CAAA;AAEtE;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,uBAAuB,CAAA"}
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Display-tier position formulas. Every function takes and gives `number`;
3
+ * exact decimal arithmetic happens internally with `DivBig`.
4
+ *
5
+ * Sign convention: long = +1, short = -1. Sizes passed to the `estimate*`
6
+ * helpers are always non-negative magnitudes; direction is carried by
7
+ * `isLong`.
8
+ */
9
+ /**
10
+ * Direction sign for a position.
11
+ *
12
+ * @deprecated Inline `isLong ? 1 : -1`. Removed in the next major.
13
+ */
14
+ export declare function directionSign(isLong: boolean): 1 | -1;
15
+ /**
16
+ * Calculate notional value of a position.
17
+ *
18
+ * @param size - Position size in asset units
19
+ * @param price - Current asset price
20
+ * @returns Notional value in USD
21
+ * @public
22
+ */
23
+ export declare function calculateNotionalValue(size: number, price: number): number;
24
+ /**
25
+ * Calculate unrealized PnL.
26
+ *
27
+ * @param entryPrice - Position entry price
28
+ * @param currentPrice - Current market price
29
+ * @param size - Position size (positive for long, negative for short)
30
+ * @returns Unrealized PnL in USD
31
+ * @public
32
+ */
33
+ export declare function calculateUnrealizedPnl(entryPrice: number, currentPrice: number, size: number): number;
34
+ /**
35
+ * Calculate return on equity (ROE) percentage.
36
+ *
37
+ * @param pnl - Profit/loss in USD
38
+ * @param margin - Initial margin in USD
39
+ * @returns ROE as percentage (e.g., 10 for 10%)
40
+ * @public
41
+ */
42
+ export declare function calculateRoe(pnl: number, margin: number): number;
43
+ /**
44
+ * Calculate required margin for a position.
45
+ *
46
+ * @param notionalValue - Position notional value in USD
47
+ * @param leverage - Position leverage
48
+ * @returns Required margin in USD
49
+ * @public
50
+ */
51
+ export declare function calculateRequiredMargin(notionalValue: number, leverage: number): number;
52
+ /**
53
+ * Distance from the current price to the liquidation price, as a percentage of
54
+ * the current price.
55
+ *
56
+ * @param liquidationPrice - The position's liquidation price
57
+ * @param currentPrice - Current market price
58
+ * @returns Absolute distance as a percentage, or 0 when current price is zero
59
+ * @public
60
+ */
61
+ export declare function calculateLiquidationDistance(params: {
62
+ liquidationPrice: number;
63
+ currentPrice: number;
64
+ }): number;
65
+ /**
66
+ * @deprecated Use `calculateLiquidationDistance`. Removed in the next major.
67
+ */
68
+ export declare const liquidationDistancePercent: typeof calculateLiquidationDistance;
69
+ /**
70
+ * Effective leverage of an open position.
71
+ *
72
+ * leverage = positionValueUsd / marginUsd
73
+ *
74
+ * @param positionValueUsd - Position notional value in USD
75
+ * @param marginUsd - Margin backing the position in USD
76
+ * @returns Effective leverage, or 0 when margin is zero
77
+ * @public
78
+ */
79
+ export declare function calculateEffectiveLeverage(params: {
80
+ positionValueUsd: number;
81
+ marginUsd: number;
82
+ }): number;
83
+ /**
84
+ * @deprecated Use `calculateEffectiveLeverage`. Removed in the next major.
85
+ */
86
+ export declare const effectiveLeverage: typeof calculateEffectiveLeverage;
87
+ /**
88
+ * Estimated liquidation price for an isolated-margin position, parameterised
89
+ * by the venue's maintenance margin rate.
90
+ *
91
+ * Standard isolated-margin model (new position, no existing exposure):
92
+ * margin_per_unit = entryPrice / leverage
93
+ * maintenance_per_unit = entryPrice * mmr
94
+ * margin_available = margin_per_unit - maintenance_per_unit
95
+ * liq_price = entryPrice - side * margin_available / (1 - mmr * side)
96
+ *
97
+ * For existing positions, prefer `Position.liquidationPrice` from the venue.
98
+ *
99
+ * @param maintenanceMarginRate - Venue maintenance margin rate as a fraction
100
+ * (e.g. 0.01 = 1%).
101
+ * @returns Estimated liquidation price, or undefined if the inputs cannot
102
+ * produce one (zero leverage, degenerate denominator).
103
+ * @public
104
+ */
105
+ export declare function estimateLiquidationPrice(params: {
106
+ entryPrice: number;
107
+ leverage: number;
108
+ isLong: boolean;
109
+ maintenanceMarginRate: number;
110
+ }): number | undefined;
111
+ /**
112
+ * @deprecated Use `estimateLiquidationPrice`. Removed in the next major.
113
+ */
114
+ export declare const estimateIsolatedLiquidationPrice: typeof estimateLiquidationPrice;
115
+ /**
116
+ * Whether an isolated position with this liquidation price is already past
117
+ * liquidation at `currentPrice`: a long liquidates when the price falls to its
118
+ * liquidation level, a short when it rises to it. A non-positive price on
119
+ * either side counts as unknown, so the result is `false`.
120
+ *
121
+ * @public
122
+ */
123
+ export declare function wouldImmediatelyLiquidate(params: {
124
+ liquidationPrice: number;
125
+ currentPrice: number;
126
+ isLong: boolean;
127
+ }): boolean;
128
+ /**
129
+ * Estimated average entry price after adding to an existing position.
130
+ *
131
+ * Weighted average of the current entry and the new fill price, weighted by
132
+ * the size of each leg in coin units. Both legs assumed in the same direction
133
+ * (this helper is for adding to, not flipping, a position).
134
+ *
135
+ * @param currentSize - Existing position size in coin units (>= 0).
136
+ * @param currentEntry - Existing position's average entry price.
137
+ * @param addSize - Size being added in coin units (>= 0).
138
+ * @param fillPrice - Price the new size is expected to fill at (mid for
139
+ * market, limitPrice for limit orders).
140
+ * @returns The new weighted-average entry price, or undefined if the inputs
141
+ * cannot produce a valid average (zero combined size, non-finite values).
142
+ * @public
143
+ */
144
+ export declare function estimateAverageEntryPrice(params: {
145
+ currentSize: number;
146
+ currentEntry: number;
147
+ addSize: number;
148
+ fillPrice: number;
149
+ }): number | undefined;
150
+ /**
151
+ * @deprecated Use `estimateAverageEntryPrice`. Removed in the next major.
152
+ */
153
+ export declare const predictAverageEntryPrice: typeof estimateAverageEntryPrice;
154
+ /**
155
+ * Estimated effective leverage after adding margin and notional.
156
+ *
157
+ * leverage = totalNotional / totalMargin. The caller computes notional from
158
+ * size and price (`calculateNotionalValue`) and supplies the additional
159
+ * margin the user is about to put up.
160
+ *
161
+ * @returns The new effective leverage, or undefined if total margin is
162
+ * non-positive.
163
+ * @public
164
+ */
165
+ export declare function estimateNewLeverage(params: {
166
+ currentNotional: number;
167
+ currentMargin: number;
168
+ addNotional: number;
169
+ addMargin: number;
170
+ }): number | undefined;
171
+ /**
172
+ * @deprecated Use `estimateNewLeverage`. Removed in the next major.
173
+ */
174
+ export declare const predictNewLeverage: typeof estimateNewLeverage;
175
+ /**
176
+ * Estimated unrealised PnL at the current mark price.
177
+ *
178
+ * `pnl = (markPrice - entryPrice) * size * (isLong ? 1 : -1)`
179
+ *
180
+ * @param size - Position size as a non-negative magnitude.
181
+ * @public
182
+ */
183
+ export declare function estimateUnrealizedPnl(params: {
184
+ entryPrice: number;
185
+ markPrice: number;
186
+ size: number;
187
+ isLong: boolean;
188
+ }): number;
189
+ /**
190
+ * @deprecated Use `estimateUnrealizedPnl`. Removed in the next major.
191
+ */
192
+ export declare const predictUnrealizedPnl: typeof estimateUnrealizedPnl;
193
+ /**
194
+ * Realised PnL on the portion of a position being closed.
195
+ *
196
+ * `rPnl = (closePrice - entryPrice) * closeSize * (isLong ? 1 : -1)`
197
+ *
198
+ * @param closeSize - Size being closed as a non-negative magnitude.
199
+ * @public
200
+ */
201
+ export declare function calculateRealizedPnl(params: {
202
+ entryPrice: number;
203
+ closePrice: number;
204
+ closeSize: number;
205
+ isLong: boolean;
206
+ }): number;
207
+ /**
208
+ * @deprecated Use `calculateRealizedPnl`. Removed in the next major.
209
+ */
210
+ export declare const realizedPnlOnClose: typeof calculateRealizedPnl;
211
+ //# sourceMappingURL=position.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../../src/math/position.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAErD;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAK1E;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,CAKR;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQhE;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,MAAM,CAQR;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE;IACnD,gBAAgB,EAAE,MAAM,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;CACrB,GAAG,MAAM,CAMT;AAED;;GAEG;AACH,eAAO,MAAM,0BAA0B,qCAA+B,CAAA;AAEtE;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IACjD,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,MAAM,CAST;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,mCAA6B,CAAA;AAE3D;;;;;;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