@haneullabs/deepbook-v3 0.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 (378) hide show
  1. package/CHANGELOG.md +984 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/client.d.ts +861 -0
  4. package/dist/cjs/client.js +1982 -0
  5. package/dist/cjs/client.js.map +7 -0
  6. package/dist/cjs/contracts/deepbook/account.d.ts +105 -0
  7. package/dist/cjs/contracts/deepbook/account.js +163 -0
  8. package/dist/cjs/contracts/deepbook/account.js.map +7 -0
  9. package/dist/cjs/contracts/deepbook/balance_manager.d.ts +268 -0
  10. package/dist/cjs/contracts/deepbook/balance_manager.js +361 -0
  11. package/dist/cjs/contracts/deepbook/balance_manager.js.map +7 -0
  12. package/dist/cjs/contracts/deepbook/balances.d.ts +10 -0
  13. package/dist/cjs/contracts/deepbook/balances.js +35 -0
  14. package/dist/cjs/contracts/deepbook/balances.js.map +7 -0
  15. package/dist/cjs/contracts/deepbook/big_vector.d.ts +62 -0
  16. package/dist/cjs/contracts/deepbook/big_vector.js +80 -0
  17. package/dist/cjs/contracts/deepbook/big_vector.js.map +7 -0
  18. package/dist/cjs/contracts/deepbook/book.d.ts +34 -0
  19. package/dist/cjs/contracts/deepbook/book.js +50 -0
  20. package/dist/cjs/contracts/deepbook/book.js.map +7 -0
  21. package/dist/cjs/contracts/deepbook/constants.d.ts +176 -0
  22. package/dist/cjs/contracts/deepbook/constants.js +338 -0
  23. package/dist/cjs/contracts/deepbook/constants.js.map +7 -0
  24. package/dist/cjs/contracts/deepbook/deep_price.d.ts +60 -0
  25. package/dist/cjs/contracts/deepbook/deep_price.js +87 -0
  26. package/dist/cjs/contracts/deepbook/deep_price.js.map +7 -0
  27. package/dist/cjs/contracts/deepbook/deps/std/type_name.d.ts +14 -0
  28. package/dist/cjs/contracts/deepbook/deps/std/type_name.js +42 -0
  29. package/dist/cjs/contracts/deepbook/deps/std/type_name.js.map +7 -0
  30. package/dist/cjs/contracts/deepbook/deps/sui/bag.d.ts +33 -0
  31. package/dist/cjs/contracts/deepbook/deps/sui/bag.js +47 -0
  32. package/dist/cjs/contracts/deepbook/deps/sui/bag.js.map +7 -0
  33. package/dist/cjs/contracts/deepbook/deps/sui/balance.d.ts +9 -0
  34. package/dist/cjs/contracts/deepbook/deps/sui/balance.js +33 -0
  35. package/dist/cjs/contracts/deepbook/deps/sui/balance.js.map +7 -0
  36. package/dist/cjs/contracts/deepbook/deps/sui/object.d.ts +5 -0
  37. package/dist/cjs/contracts/deepbook/deps/sui/object.js +33 -0
  38. package/dist/cjs/contracts/deepbook/deps/sui/object.js.map +7 -0
  39. package/dist/cjs/contracts/deepbook/deps/sui/table.d.ts +28 -0
  40. package/dist/cjs/contracts/deepbook/deps/sui/table.js +47 -0
  41. package/dist/cjs/contracts/deepbook/deps/sui/table.js.map +7 -0
  42. package/dist/cjs/contracts/deepbook/deps/sui/vec_map.d.ts +27 -0
  43. package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js +45 -0
  44. package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js.map +7 -0
  45. package/dist/cjs/contracts/deepbook/deps/sui/vec_set.d.ts +15 -0
  46. package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js +35 -0
  47. package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js.map +7 -0
  48. package/dist/cjs/contracts/deepbook/deps/sui/versioned.d.ts +7 -0
  49. package/dist/cjs/contracts/deepbook/deps/sui/versioned.js +45 -0
  50. package/dist/cjs/contracts/deepbook/deps/sui/versioned.js.map +7 -0
  51. package/dist/cjs/contracts/deepbook/ewma.d.ts +17 -0
  52. package/dist/cjs/contracts/deepbook/ewma.js +39 -0
  53. package/dist/cjs/contracts/deepbook/ewma.js.map +7 -0
  54. package/dist/cjs/contracts/deepbook/fill.d.ts +153 -0
  55. package/dist/cjs/contracts/deepbook/fill.js +251 -0
  56. package/dist/cjs/contracts/deepbook/fill.js.map +7 -0
  57. package/dist/cjs/contracts/deepbook/governance.d.ts +63 -0
  58. package/dist/cjs/contracts/deepbook/governance.js +79 -0
  59. package/dist/cjs/contracts/deepbook/governance.js.map +7 -0
  60. package/dist/cjs/contracts/deepbook/history.d.ts +60 -0
  61. package/dist/cjs/contracts/deepbook/history.js +78 -0
  62. package/dist/cjs/contracts/deepbook/history.js.map +7 -0
  63. package/dist/cjs/contracts/deepbook/math.d.ts +94 -0
  64. package/dist/cjs/contracts/deepbook/math.js +132 -0
  65. package/dist/cjs/contracts/deepbook/math.js.map +7 -0
  66. package/dist/cjs/contracts/deepbook/order.d.ts +135 -0
  67. package/dist/cjs/contracts/deepbook/order.js +218 -0
  68. package/dist/cjs/contracts/deepbook/order.js.map +7 -0
  69. package/dist/cjs/contracts/deepbook/order_info.d.ts +296 -0
  70. package/dist/cjs/contracts/deepbook/order_info.js +386 -0
  71. package/dist/cjs/contracts/deepbook/order_info.js.map +7 -0
  72. package/dist/cjs/contracts/deepbook/order_query.d.ts +85 -0
  73. package/dist/cjs/contracts/deepbook/order_query.js +96 -0
  74. package/dist/cjs/contracts/deepbook/order_query.js.map +7 -0
  75. package/dist/cjs/contracts/deepbook/pool.d.ts +1218 -0
  76. package/dist/cjs/contracts/deepbook/pool.js +1236 -0
  77. package/dist/cjs/contracts/deepbook/pool.js.map +7 -0
  78. package/dist/cjs/contracts/deepbook/registry.d.ts +134 -0
  79. package/dist/cjs/contracts/deepbook/registry.js +182 -0
  80. package/dist/cjs/contracts/deepbook/registry.js.map +7 -0
  81. package/dist/cjs/contracts/deepbook/state.d.ts +117 -0
  82. package/dist/cjs/contracts/deepbook/state.js +104 -0
  83. package/dist/cjs/contracts/deepbook/state.js.map +7 -0
  84. package/dist/cjs/contracts/deepbook/trade_params.d.ts +7 -0
  85. package/dist/cjs/contracts/deepbook/trade_params.js +35 -0
  86. package/dist/cjs/contracts/deepbook/trade_params.js.map +7 -0
  87. package/dist/cjs/contracts/deepbook/vault.d.ts +30 -0
  88. package/dist/cjs/contracts/deepbook/vault.js +65 -0
  89. package/dist/cjs/contracts/deepbook/vault.js.map +7 -0
  90. package/dist/cjs/contracts/utils/index.d.ts +25 -0
  91. package/dist/cjs/contracts/utils/index.js +148 -0
  92. package/dist/cjs/contracts/utils/index.js.map +7 -0
  93. package/dist/cjs/index.d.ts +23 -0
  94. package/dist/cjs/index.js +81 -0
  95. package/dist/cjs/index.js.map +7 -0
  96. package/dist/cjs/package.json +4 -0
  97. package/dist/cjs/pyth/PriceServiceConnection.d.ts +26 -0
  98. package/dist/cjs/pyth/PriceServiceConnection.js +68 -0
  99. package/dist/cjs/pyth/PriceServiceConnection.js.map +7 -0
  100. package/dist/cjs/pyth/pyth-helpers.d.ts +7 -0
  101. package/dist/cjs/pyth/pyth-helpers.js +36 -0
  102. package/dist/cjs/pyth/pyth-helpers.js.map +7 -0
  103. package/dist/cjs/pyth/pyth.d.ts +65 -0
  104. package/dist/cjs/pyth/pyth.js +269 -0
  105. package/dist/cjs/pyth/pyth.js.map +7 -0
  106. package/dist/cjs/transactions/balanceManager.d.ts +168 -0
  107. package/dist/cjs/transactions/balanceManager.js +384 -0
  108. package/dist/cjs/transactions/balanceManager.js.map +7 -0
  109. package/dist/cjs/transactions/deepbook.d.ts +477 -0
  110. package/dist/cjs/transactions/deepbook.js +1335 -0
  111. package/dist/cjs/transactions/deepbook.js.map +7 -0
  112. package/dist/cjs/transactions/deepbookAdmin.d.ts +105 -0
  113. package/dist/cjs/transactions/deepbookAdmin.js +334 -0
  114. package/dist/cjs/transactions/deepbookAdmin.js.map +7 -0
  115. package/dist/cjs/transactions/flashLoans.d.ts +56 -0
  116. package/dist/cjs/transactions/flashLoans.js +124 -0
  117. package/dist/cjs/transactions/flashLoans.js.map +7 -0
  118. package/dist/cjs/transactions/governance.d.ts +42 -0
  119. package/dist/cjs/transactions/governance.js +135 -0
  120. package/dist/cjs/transactions/governance.js.map +7 -0
  121. package/dist/cjs/transactions/marginAdmin.d.ts +133 -0
  122. package/dist/cjs/transactions/marginAdmin.js +393 -0
  123. package/dist/cjs/transactions/marginAdmin.js.map +7 -0
  124. package/dist/cjs/transactions/marginLiquidations.d.ts +61 -0
  125. package/dist/cjs/transactions/marginLiquidations.js +173 -0
  126. package/dist/cjs/transactions/marginLiquidations.js.map +7 -0
  127. package/dist/cjs/transactions/marginMaintainer.d.ts +80 -0
  128. package/dist/cjs/transactions/marginMaintainer.js +251 -0
  129. package/dist/cjs/transactions/marginMaintainer.js.map +7 -0
  130. package/dist/cjs/transactions/marginManager.d.ts +236 -0
  131. package/dist/cjs/transactions/marginManager.js +688 -0
  132. package/dist/cjs/transactions/marginManager.js.map +7 -0
  133. package/dist/cjs/transactions/marginPool.d.ts +134 -0
  134. package/dist/cjs/transactions/marginPool.js +330 -0
  135. package/dist/cjs/transactions/marginPool.js.map +7 -0
  136. package/dist/cjs/transactions/marginRegistry.d.ts +94 -0
  137. package/dist/cjs/transactions/marginRegistry.js +221 -0
  138. package/dist/cjs/transactions/marginRegistry.js.map +7 -0
  139. package/dist/cjs/transactions/marginTPSL.d.ts +93 -0
  140. package/dist/cjs/transactions/marginTPSL.js +286 -0
  141. package/dist/cjs/transactions/marginTPSL.js.map +7 -0
  142. package/dist/cjs/transactions/poolProxy.d.ts +104 -0
  143. package/dist/cjs/transactions/poolProxy.js +435 -0
  144. package/dist/cjs/transactions/poolProxy.js.map +7 -0
  145. package/dist/cjs/types/bcs.d.ts +5 -0
  146. package/dist/cjs/types/bcs.js +33 -0
  147. package/dist/cjs/types/bcs.js.map +7 -0
  148. package/dist/cjs/types/index.d.ts +218 -0
  149. package/dist/cjs/types/index.js +38 -0
  150. package/dist/cjs/types/index.js.map +7 -0
  151. package/dist/cjs/utils/config.d.ts +65 -0
  152. package/dist/cjs/utils/config.js +144 -0
  153. package/dist/cjs/utils/config.js.map +7 -0
  154. package/dist/cjs/utils/constants.d.ts +76 -0
  155. package/dist/cjs/utils/constants.js +382 -0
  156. package/dist/cjs/utils/constants.js.map +7 -0
  157. package/dist/cjs/utils/errors.d.ts +42 -0
  158. package/dist/cjs/utils/errors.js +70 -0
  159. package/dist/cjs/utils/errors.js.map +7 -0
  160. package/dist/cjs/utils/validation.d.ts +50 -0
  161. package/dist/cjs/utils/validation.js +67 -0
  162. package/dist/cjs/utils/validation.js.map +7 -0
  163. package/dist/esm/client.d.ts +861 -0
  164. package/dist/esm/client.js +1967 -0
  165. package/dist/esm/client.js.map +7 -0
  166. package/dist/esm/contracts/deepbook/account.d.ts +105 -0
  167. package/dist/esm/contracts/deepbook/account.js +133 -0
  168. package/dist/esm/contracts/deepbook/account.js.map +7 -0
  169. package/dist/esm/contracts/deepbook/balance_manager.d.ts +268 -0
  170. package/dist/esm/contracts/deepbook/balance_manager.js +331 -0
  171. package/dist/esm/contracts/deepbook/balance_manager.js.map +7 -0
  172. package/dist/esm/contracts/deepbook/balances.d.ts +10 -0
  173. package/dist/esm/contracts/deepbook/balances.js +15 -0
  174. package/dist/esm/contracts/deepbook/balances.js.map +7 -0
  175. package/dist/esm/contracts/deepbook/big_vector.d.ts +62 -0
  176. package/dist/esm/contracts/deepbook/big_vector.js +50 -0
  177. package/dist/esm/contracts/deepbook/big_vector.js.map +7 -0
  178. package/dist/esm/contracts/deepbook/book.d.ts +34 -0
  179. package/dist/esm/contracts/deepbook/book.js +20 -0
  180. package/dist/esm/contracts/deepbook/book.js.map +7 -0
  181. package/dist/esm/contracts/deepbook/constants.d.ts +176 -0
  182. package/dist/esm/contracts/deepbook/constants.js +318 -0
  183. package/dist/esm/contracts/deepbook/constants.js.map +7 -0
  184. package/dist/esm/contracts/deepbook/deep_price.d.ts +60 -0
  185. package/dist/esm/contracts/deepbook/deep_price.js +67 -0
  186. package/dist/esm/contracts/deepbook/deep_price.js.map +7 -0
  187. package/dist/esm/contracts/deepbook/deps/std/type_name.d.ts +14 -0
  188. package/dist/esm/contracts/deepbook/deps/std/type_name.js +22 -0
  189. package/dist/esm/contracts/deepbook/deps/std/type_name.js.map +7 -0
  190. package/dist/esm/contracts/deepbook/deps/sui/bag.d.ts +33 -0
  191. package/dist/esm/contracts/deepbook/deps/sui/bag.js +17 -0
  192. package/dist/esm/contracts/deepbook/deps/sui/bag.js.map +7 -0
  193. package/dist/esm/contracts/deepbook/deps/sui/balance.d.ts +9 -0
  194. package/dist/esm/contracts/deepbook/deps/sui/balance.js +13 -0
  195. package/dist/esm/contracts/deepbook/deps/sui/balance.js.map +7 -0
  196. package/dist/esm/contracts/deepbook/deps/sui/object.d.ts +5 -0
  197. package/dist/esm/contracts/deepbook/deps/sui/object.js +13 -0
  198. package/dist/esm/contracts/deepbook/deps/sui/object.js.map +7 -0
  199. package/dist/esm/contracts/deepbook/deps/sui/table.d.ts +28 -0
  200. package/dist/esm/contracts/deepbook/deps/sui/table.js +17 -0
  201. package/dist/esm/contracts/deepbook/deps/sui/table.js.map +7 -0
  202. package/dist/esm/contracts/deepbook/deps/sui/vec_map.d.ts +27 -0
  203. package/dist/esm/contracts/deepbook/deps/sui/vec_map.js +25 -0
  204. package/dist/esm/contracts/deepbook/deps/sui/vec_map.js.map +7 -0
  205. package/dist/esm/contracts/deepbook/deps/sui/vec_set.d.ts +15 -0
  206. package/dist/esm/contracts/deepbook/deps/sui/vec_set.js +15 -0
  207. package/dist/esm/contracts/deepbook/deps/sui/vec_set.js.map +7 -0
  208. package/dist/esm/contracts/deepbook/deps/sui/versioned.d.ts +7 -0
  209. package/dist/esm/contracts/deepbook/deps/sui/versioned.js +15 -0
  210. package/dist/esm/contracts/deepbook/deps/sui/versioned.js.map +7 -0
  211. package/dist/esm/contracts/deepbook/ewma.d.ts +17 -0
  212. package/dist/esm/contracts/deepbook/ewma.js +19 -0
  213. package/dist/esm/contracts/deepbook/ewma.js.map +7 -0
  214. package/dist/esm/contracts/deepbook/fill.d.ts +153 -0
  215. package/dist/esm/contracts/deepbook/fill.js +221 -0
  216. package/dist/esm/contracts/deepbook/fill.js.map +7 -0
  217. package/dist/esm/contracts/deepbook/governance.d.ts +63 -0
  218. package/dist/esm/contracts/deepbook/governance.js +49 -0
  219. package/dist/esm/contracts/deepbook/governance.js.map +7 -0
  220. package/dist/esm/contracts/deepbook/history.d.ts +60 -0
  221. package/dist/esm/contracts/deepbook/history.js +48 -0
  222. package/dist/esm/contracts/deepbook/history.js.map +7 -0
  223. package/dist/esm/contracts/deepbook/math.d.ts +94 -0
  224. package/dist/esm/contracts/deepbook/math.js +112 -0
  225. package/dist/esm/contracts/deepbook/math.js.map +7 -0
  226. package/dist/esm/contracts/deepbook/order.d.ts +135 -0
  227. package/dist/esm/contracts/deepbook/order.js +188 -0
  228. package/dist/esm/contracts/deepbook/order.js.map +7 -0
  229. package/dist/esm/contracts/deepbook/order_info.d.ts +296 -0
  230. package/dist/esm/contracts/deepbook/order_info.js +356 -0
  231. package/dist/esm/contracts/deepbook/order_info.js.map +7 -0
  232. package/dist/esm/contracts/deepbook/order_query.d.ts +85 -0
  233. package/dist/esm/contracts/deepbook/order_query.js +66 -0
  234. package/dist/esm/contracts/deepbook/order_query.js.map +7 -0
  235. package/dist/esm/contracts/deepbook/pool.d.ts +1218 -0
  236. package/dist/esm/contracts/deepbook/pool.js +1206 -0
  237. package/dist/esm/contracts/deepbook/pool.js.map +7 -0
  238. package/dist/esm/contracts/deepbook/registry.d.ts +134 -0
  239. package/dist/esm/contracts/deepbook/registry.js +152 -0
  240. package/dist/esm/contracts/deepbook/registry.js.map +7 -0
  241. package/dist/esm/contracts/deepbook/state.d.ts +117 -0
  242. package/dist/esm/contracts/deepbook/state.js +74 -0
  243. package/dist/esm/contracts/deepbook/state.js.map +7 -0
  244. package/dist/esm/contracts/deepbook/trade_params.d.ts +7 -0
  245. package/dist/esm/contracts/deepbook/trade_params.js +15 -0
  246. package/dist/esm/contracts/deepbook/trade_params.js.map +7 -0
  247. package/dist/esm/contracts/deepbook/vault.d.ts +30 -0
  248. package/dist/esm/contracts/deepbook/vault.js +35 -0
  249. package/dist/esm/contracts/deepbook/vault.js.map +7 -0
  250. package/dist/esm/contracts/utils/index.d.ts +25 -0
  251. package/dist/esm/contracts/utils/index.js +128 -0
  252. package/dist/esm/contracts/utils/index.js.map +7 -0
  253. package/dist/esm/index.d.ts +23 -0
  254. package/dist/esm/index.js +81 -0
  255. package/dist/esm/index.js.map +7 -0
  256. package/dist/esm/package.json +4 -0
  257. package/dist/esm/pyth/PriceServiceConnection.d.ts +26 -0
  258. package/dist/esm/pyth/PriceServiceConnection.js +38 -0
  259. package/dist/esm/pyth/PriceServiceConnection.js.map +7 -0
  260. package/dist/esm/pyth/pyth-helpers.d.ts +7 -0
  261. package/dist/esm/pyth/pyth-helpers.js +16 -0
  262. package/dist/esm/pyth/pyth-helpers.js.map +7 -0
  263. package/dist/esm/pyth/pyth.d.ts +65 -0
  264. package/dist/esm/pyth/pyth.js +249 -0
  265. package/dist/esm/pyth/pyth.js.map +7 -0
  266. package/dist/esm/transactions/balanceManager.d.ts +168 -0
  267. package/dist/esm/transactions/balanceManager.js +364 -0
  268. package/dist/esm/transactions/balanceManager.js.map +7 -0
  269. package/dist/esm/transactions/deepbook.d.ts +477 -0
  270. package/dist/esm/transactions/deepbook.js +1321 -0
  271. package/dist/esm/transactions/deepbook.js.map +7 -0
  272. package/dist/esm/transactions/deepbookAdmin.d.ts +105 -0
  273. package/dist/esm/transactions/deepbookAdmin.js +314 -0
  274. package/dist/esm/transactions/deepbookAdmin.js.map +7 -0
  275. package/dist/esm/transactions/flashLoans.d.ts +56 -0
  276. package/dist/esm/transactions/flashLoans.js +104 -0
  277. package/dist/esm/transactions/flashLoans.js.map +7 -0
  278. package/dist/esm/transactions/governance.d.ts +42 -0
  279. package/dist/esm/transactions/governance.js +115 -0
  280. package/dist/esm/transactions/governance.js.map +7 -0
  281. package/dist/esm/transactions/marginAdmin.d.ts +133 -0
  282. package/dist/esm/transactions/marginAdmin.js +373 -0
  283. package/dist/esm/transactions/marginAdmin.js.map +7 -0
  284. package/dist/esm/transactions/marginLiquidations.d.ts +61 -0
  285. package/dist/esm/transactions/marginLiquidations.js +153 -0
  286. package/dist/esm/transactions/marginLiquidations.js.map +7 -0
  287. package/dist/esm/transactions/marginMaintainer.d.ts +80 -0
  288. package/dist/esm/transactions/marginMaintainer.js +231 -0
  289. package/dist/esm/transactions/marginMaintainer.js.map +7 -0
  290. package/dist/esm/transactions/marginManager.d.ts +236 -0
  291. package/dist/esm/transactions/marginManager.js +668 -0
  292. package/dist/esm/transactions/marginManager.js.map +7 -0
  293. package/dist/esm/transactions/marginPool.d.ts +134 -0
  294. package/dist/esm/transactions/marginPool.js +310 -0
  295. package/dist/esm/transactions/marginPool.js.map +7 -0
  296. package/dist/esm/transactions/marginRegistry.d.ts +94 -0
  297. package/dist/esm/transactions/marginRegistry.js +201 -0
  298. package/dist/esm/transactions/marginRegistry.js.map +7 -0
  299. package/dist/esm/transactions/marginTPSL.d.ts +93 -0
  300. package/dist/esm/transactions/marginTPSL.js +266 -0
  301. package/dist/esm/transactions/marginTPSL.js.map +7 -0
  302. package/dist/esm/transactions/poolProxy.d.ts +104 -0
  303. package/dist/esm/transactions/poolProxy.js +415 -0
  304. package/dist/esm/transactions/poolProxy.js.map +7 -0
  305. package/dist/esm/types/bcs.d.ts +5 -0
  306. package/dist/esm/types/bcs.js +13 -0
  307. package/dist/esm/types/bcs.js.map +7 -0
  308. package/dist/esm/types/index.d.ts +218 -0
  309. package/dist/esm/types/index.js +18 -0
  310. package/dist/esm/types/index.js.map +7 -0
  311. package/dist/esm/utils/config.d.ts +65 -0
  312. package/dist/esm/utils/config.js +135 -0
  313. package/dist/esm/utils/config.js.map +7 -0
  314. package/dist/esm/utils/constants.d.ts +76 -0
  315. package/dist/esm/utils/constants.js +362 -0
  316. package/dist/esm/utils/constants.js.map +7 -0
  317. package/dist/esm/utils/errors.d.ts +42 -0
  318. package/dist/esm/utils/errors.js +50 -0
  319. package/dist/esm/utils/errors.js.map +7 -0
  320. package/dist/esm/utils/validation.d.ts +50 -0
  321. package/dist/esm/utils/validation.js +47 -0
  322. package/dist/esm/utils/validation.js.map +7 -0
  323. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  324. package/dist/tsconfig.tsbuildinfo +1 -0
  325. package/package.json +63 -0
  326. package/src/client.ts +2451 -0
  327. package/src/contracts/deepbook/account.ts +199 -0
  328. package/src/contracts/deepbook/balance_manager.ts +532 -0
  329. package/src/contracts/deepbook/balances.ts +19 -0
  330. package/src/contracts/deepbook/big_vector.ts +74 -0
  331. package/src/contracts/deepbook/book.ts +24 -0
  332. package/src/contracts/deepbook/constants.ts +458 -0
  333. package/src/contracts/deepbook/deep_price.ts +84 -0
  334. package/src/contracts/deepbook/deps/std/type_name.ts +23 -0
  335. package/src/contracts/deepbook/deps/sui/bag.ts +41 -0
  336. package/src/contracts/deepbook/deps/sui/balance.ts +18 -0
  337. package/src/contracts/deepbook/deps/sui/object.ts +14 -0
  338. package/src/contracts/deepbook/deps/sui/table.ts +36 -0
  339. package/src/contracts/deepbook/deps/sui/vec_map.ts +33 -0
  340. package/src/contracts/deepbook/deps/sui/vec_set.ts +22 -0
  341. package/src/contracts/deepbook/deps/sui/versioned.ts +13 -0
  342. package/src/contracts/deepbook/ewma.ts +26 -0
  343. package/src/contracts/deepbook/fill.ts +336 -0
  344. package/src/contracts/deepbook/governance.ts +52 -0
  345. package/src/contracts/deepbook/history.ts +51 -0
  346. package/src/contracts/deepbook/math.ts +210 -0
  347. package/src/contracts/deepbook/order.ts +269 -0
  348. package/src/contracts/deepbook/order_info.ts +513 -0
  349. package/src/contracts/deepbook/order_query.ts +115 -0
  350. package/src/contracts/deepbook/pool.ts +2269 -0
  351. package/src/contracts/deepbook/registry.ts +242 -0
  352. package/src/contracts/deepbook/state.ts +74 -0
  353. package/src/contracts/deepbook/trade_params.ts +16 -0
  354. package/src/contracts/deepbook/vault.ts +37 -0
  355. package/src/contracts/utils/index.ts +184 -0
  356. package/src/index.ts +95 -0
  357. package/src/pyth/PriceServiceConnection.ts +48 -0
  358. package/src/pyth/pyth-helpers.ts +23 -0
  359. package/src/pyth/pyth.ts +305 -0
  360. package/src/transactions/balanceManager.ts +399 -0
  361. package/src/transactions/deepbook.ts +1519 -0
  362. package/src/transactions/deepbookAdmin.ts +332 -0
  363. package/src/transactions/flashLoans.ts +123 -0
  364. package/src/transactions/governance.ts +123 -0
  365. package/src/transactions/marginAdmin.ts +396 -0
  366. package/src/transactions/marginLiquidations.ts +175 -0
  367. package/src/transactions/marginMaintainer.ts +280 -0
  368. package/src/transactions/marginManager.ts +708 -0
  369. package/src/transactions/marginPool.ts +339 -0
  370. package/src/transactions/marginRegistry.ts +212 -0
  371. package/src/transactions/marginTPSL.ts +296 -0
  372. package/src/transactions/poolProxy.ts +438 -0
  373. package/src/types/bcs.ts +8 -0
  374. package/src/types/index.ts +255 -0
  375. package/src/utils/config.ts +177 -0
  376. package/src/utils/constants.ts +374 -0
  377. package/src/utils/errors.ts +67 -0
  378. package/src/utils/validation.ts +91 -0
@@ -0,0 +1,1982 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
26
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
27
+ var client_exports = {};
28
+ __export(client_exports, {
29
+ DeepBookClient: () => DeepBookClient
30
+ });
31
+ module.exports = __toCommonJS(client_exports);
32
+ var import_bcs = require("@haneullabs/haneul/bcs");
33
+ var import_bcs2 = require("./types/bcs.js");
34
+ var import_transactions = require("@haneullabs/haneul/transactions");
35
+ var import_utils = require("@haneullabs/haneul/utils");
36
+ var import_balanceManager = require("./transactions/balanceManager.js");
37
+ var import_deepbook = require("./transactions/deepbook.js");
38
+ var import_deepbookAdmin = require("./transactions/deepbookAdmin.js");
39
+ var import_flashLoans = require("./transactions/flashLoans.js");
40
+ var import_governance = require("./transactions/governance.js");
41
+ var import_config = require("./utils/config.js");
42
+ var import_marginAdmin = require("./transactions/marginAdmin.js");
43
+ var import_marginMaintainer = require("./transactions/marginMaintainer.js");
44
+ var import_marginPool = require("./transactions/marginPool.js");
45
+ var import_marginManager = require("./transactions/marginManager.js");
46
+ var import_marginRegistry = require("./transactions/marginRegistry.js");
47
+ var import_marginLiquidations = require("./transactions/marginLiquidations.js");
48
+ var import_pyth = require("./pyth/pyth.js");
49
+ var import_pyth2 = require("./pyth/pyth.js");
50
+ var import_poolProxy = require("./transactions/poolProxy.js");
51
+ var import_marginTPSL = require("./transactions/marginTPSL.js");
52
+ var _config, _address, _DeepBookClient_instances, formatTokenAmount_fn;
53
+ class DeepBookClient {
54
+ /**
55
+ * @param {HaneulClient} client HaneulClient instance
56
+ * @param {string} address Address of the client
57
+ * @param {Environment} env Environment configuration
58
+ * @param {Object.<string, BalanceManager>} [balanceManagers] Optional initial BalanceManager map
59
+ * @param {Object.<string, MarginManager>} [marginManagers] Optional initial MarginManager map
60
+ * @param {CoinMap} [coins] Optional initial CoinMap
61
+ * @param {PoolMap} [pools] Optional initial PoolMap
62
+ * @param {string} [adminCap] Optional admin capability
63
+ * @param {string} [marginAdminCap] Optional margin admin capability
64
+ * @param {string} [marginMaintainerCap] Optional margin maintainer capability
65
+ */
66
+ constructor({
67
+ client,
68
+ address,
69
+ env,
70
+ balanceManagers,
71
+ marginManagers,
72
+ coins,
73
+ pools,
74
+ adminCap,
75
+ marginAdminCap,
76
+ marginMaintainerCap
77
+ }) {
78
+ __privateAdd(this, _DeepBookClient_instances);
79
+ __privateAdd(this, _config);
80
+ __privateAdd(this, _address);
81
+ this.client = client;
82
+ __privateSet(this, _address, (0, import_utils.normalizeHaneulAddress)(address));
83
+ __privateSet(this, _config, new import_config.DeepBookConfig({
84
+ address: __privateGet(this, _address),
85
+ env,
86
+ balanceManagers,
87
+ marginManagers,
88
+ coins,
89
+ pools,
90
+ adminCap,
91
+ marginAdminCap,
92
+ marginMaintainerCap
93
+ }));
94
+ this.balanceManager = new import_balanceManager.BalanceManagerContract(__privateGet(this, _config));
95
+ this.deepBook = new import_deepbook.DeepBookContract(__privateGet(this, _config));
96
+ this.deepBookAdmin = new import_deepbookAdmin.DeepBookAdminContract(__privateGet(this, _config));
97
+ this.flashLoans = new import_flashLoans.FlashLoanContract(__privateGet(this, _config));
98
+ this.governance = new import_governance.GovernanceContract(__privateGet(this, _config));
99
+ this.marginAdmin = new import_marginAdmin.MarginAdminContract(__privateGet(this, _config));
100
+ this.marginMaintainer = new import_marginMaintainer.MarginMaintainerContract(__privateGet(this, _config));
101
+ this.marginPool = new import_marginPool.MarginPoolContract(__privateGet(this, _config));
102
+ this.marginManager = new import_marginManager.MarginManagerContract(__privateGet(this, _config));
103
+ this.marginRegistry = new import_marginRegistry.MarginRegistryContract(__privateGet(this, _config));
104
+ this.marginLiquidations = new import_marginLiquidations.MarginLiquidationsContract(__privateGet(this, _config));
105
+ this.poolProxy = new import_poolProxy.PoolProxyContract(__privateGet(this, _config));
106
+ this.marginTPSL = new import_marginTPSL.MarginTPSLContract(__privateGet(this, _config));
107
+ }
108
+ /**
109
+ * @description Check the balance of a balance manager for a specific coin
110
+ * @param {string} managerKey Key of the balance manager
111
+ * @param {string} coinKey Key of the coin
112
+ * @returns {Promise<{ coinType: string, balance: number }>} An object with coin type and balance
113
+ */
114
+ async checkManagerBalance(managerKey, coinKey) {
115
+ const tx = new import_transactions.Transaction();
116
+ const coin = __privateGet(this, _config).getCoin(coinKey);
117
+ tx.add(this.balanceManager.checkManagerBalance(managerKey, coinKey));
118
+ const res = await this.client.devInspectTransactionBlock({
119
+ sender: __privateGet(this, _address),
120
+ transactionBlock: tx
121
+ });
122
+ const bytes = res.results[0].returnValues[0][0];
123
+ const parsed_balance = import_bcs.bcs.U64.parse(new Uint8Array(bytes));
124
+ const balanceNumber = Number(parsed_balance);
125
+ const adjusted_balance = balanceNumber / coin.scalar;
126
+ return {
127
+ coinType: coin.type,
128
+ balance: Number(adjusted_balance.toFixed(9))
129
+ };
130
+ }
131
+ /**
132
+ * @description Check if a pool is whitelisted
133
+ * @param {string} poolKey Key of the pool
134
+ * @returns {Promise<boolean>} Boolean indicating if the pool is whitelisted
135
+ */
136
+ async whitelisted(poolKey) {
137
+ const tx = new import_transactions.Transaction();
138
+ tx.add(this.deepBook.whitelisted(poolKey));
139
+ const res = await this.client.devInspectTransactionBlock({
140
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
141
+ transactionBlock: tx
142
+ });
143
+ const bytes = res.results[0].returnValues[0][0];
144
+ const whitelisted = import_bcs.bcs.Bool.parse(new Uint8Array(bytes));
145
+ return whitelisted;
146
+ }
147
+ /**
148
+ * @description Get the quote quantity out for a given base quantity
149
+ * @param {string} poolKey Key of the pool
150
+ * @param {number} baseQuantity Base quantity to convert
151
+ * @returns {Promise<{ baseQuantity: number, baseOut: number, quoteOut: number, deepRequired: number }>}
152
+ * An object with base quantity, base out, quote out, and deep required for the dry run
153
+ */
154
+ async getQuoteQuantityOut(poolKey, baseQuantity) {
155
+ const tx = new import_transactions.Transaction();
156
+ const pool = __privateGet(this, _config).getPool(poolKey);
157
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
158
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
159
+ tx.add(this.deepBook.getQuoteQuantityOut(poolKey, baseQuantity));
160
+ const res = await this.client.devInspectTransactionBlock({
161
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
162
+ transactionBlock: tx
163
+ });
164
+ const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
165
+ const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
166
+ const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
167
+ return {
168
+ baseQuantity,
169
+ baseOut: Number((baseOut / baseScalar).toFixed(9)),
170
+ quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
171
+ deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
172
+ };
173
+ }
174
+ /**
175
+ * @description Get the base quantity out for a given quote quantity
176
+ * @param {string} poolKey Key of the pool
177
+ * @param {number} quoteQuantity Quote quantity to convert
178
+ * @returns {Promise<{ quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number }>}
179
+ * An object with quote quantity, base out, quote out, and deep required for the dry run
180
+ */
181
+ async getBaseQuantityOut(poolKey, quoteQuantity) {
182
+ const tx = new import_transactions.Transaction();
183
+ const pool = __privateGet(this, _config).getPool(poolKey);
184
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
185
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
186
+ tx.add(this.deepBook.getBaseQuantityOut(poolKey, quoteQuantity));
187
+ const res = await this.client.devInspectTransactionBlock({
188
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
189
+ transactionBlock: tx
190
+ });
191
+ const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
192
+ const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
193
+ const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
194
+ return {
195
+ quoteQuantity,
196
+ baseOut: Number((baseOut / baseScalar).toFixed(9)),
197
+ quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
198
+ deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
199
+ };
200
+ }
201
+ /**
202
+ * @description Get the output quantities for given base and quote quantities. Only one quantity can be non-zero
203
+ * @param {string} poolKey Key of the pool
204
+ * @param {number} baseQuantity Base quantity to convert
205
+ * @param {number} quoteQuantity Quote quantity to convert
206
+ * @returns {Promise<{ baseQuantity: number, quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number }>}
207
+ * An object with base quantity, quote quantity, base out, quote out, and deep required for the dry run
208
+ */
209
+ async getQuantityOut(poolKey, baseQuantity, quoteQuantity) {
210
+ const tx = new import_transactions.Transaction();
211
+ const pool = __privateGet(this, _config).getPool(poolKey);
212
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
213
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
214
+ tx.add(this.deepBook.getQuantityOut(poolKey, baseQuantity, quoteQuantity));
215
+ const res = await this.client.devInspectTransactionBlock({
216
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
217
+ transactionBlock: tx
218
+ });
219
+ const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
220
+ const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
221
+ const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
222
+ return {
223
+ baseQuantity,
224
+ quoteQuantity,
225
+ baseOut: Number((baseOut / baseScalar).toFixed(9)),
226
+ quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
227
+ deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
228
+ };
229
+ }
230
+ /**
231
+ * @description Get open orders for a balance manager in a pool
232
+ * @param {string} poolKey Key of the pool
233
+ * @param {string} managerKey Key of the balance manager
234
+ * @returns {Promise<Array>} An array of open order IDs
235
+ */
236
+ async accountOpenOrders(poolKey, managerKey) {
237
+ const tx = new import_transactions.Transaction();
238
+ tx.add(this.deepBook.accountOpenOrders(poolKey, managerKey));
239
+ const res = await this.client.devInspectTransactionBlock({
240
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
241
+ transactionBlock: tx
242
+ });
243
+ const order_ids = res.results[0].returnValues[0][0];
244
+ return (0, import_bcs2.VecSet)(import_bcs.bcs.u128()).parse(new Uint8Array(order_ids)).contents;
245
+ }
246
+ /**
247
+ * @description Get the order information for a specific order in a pool
248
+ * @param {string} poolKey Key of the pool
249
+ * @param {string} orderId Order ID
250
+ * @returns {Promise<Object>} A promise that resolves to an object containing the order information
251
+ */
252
+ async getOrder(poolKey, orderId) {
253
+ const tx = new import_transactions.Transaction();
254
+ tx.add(this.deepBook.getOrder(poolKey, orderId));
255
+ const res = await this.client.devInspectTransactionBlock({
256
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
257
+ transactionBlock: tx
258
+ });
259
+ try {
260
+ const orderInformation = res.results[0].returnValues[0][0];
261
+ return import_bcs2.Order.parse(new Uint8Array(orderInformation));
262
+ } catch {
263
+ return null;
264
+ }
265
+ }
266
+ /**
267
+ * @description Get the order information for a specific order in a pool, with normalized price
268
+ * @param {string} poolKey Key of the pool
269
+ * @param {string} orderId Order ID
270
+ * @returns {Promise<Object>} A promise that resolves to an object containing the order information with normalized price
271
+ */
272
+ async getOrderNormalized(poolKey, orderId) {
273
+ const tx = new import_transactions.Transaction();
274
+ tx.add(this.deepBook.getOrder(poolKey, orderId));
275
+ const res = await this.client.devInspectTransactionBlock({
276
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
277
+ transactionBlock: tx
278
+ });
279
+ try {
280
+ const orderInformation = res.results[0].returnValues[0][0];
281
+ const orderInfo = import_bcs2.Order.parse(new Uint8Array(orderInformation));
282
+ if (!orderInfo) {
283
+ return null;
284
+ }
285
+ const baseCoin = __privateGet(this, _config).getCoin(__privateGet(this, _config).getPool(poolKey).baseCoin);
286
+ const quoteCoin = __privateGet(this, _config).getCoin(__privateGet(this, _config).getPool(poolKey).quoteCoin);
287
+ const { isBid, price: rawPrice } = this.decodeOrderId(BigInt(orderInfo.order_id));
288
+ const normalizedPrice = rawPrice * baseCoin.scalar / quoteCoin.scalar / import_config.FLOAT_SCALAR;
289
+ const normalizedOrderInfo = {
290
+ ...orderInfo,
291
+ quantity: String((Number(orderInfo.quantity) / baseCoin.scalar).toFixed(9)),
292
+ filled_quantity: String((Number(orderInfo.filled_quantity) / baseCoin.scalar).toFixed(9)),
293
+ order_deep_price: {
294
+ ...orderInfo.order_deep_price,
295
+ deep_per_asset: String(
296
+ (Number(orderInfo.order_deep_price.deep_per_asset) / import_config.DEEP_SCALAR).toFixed(9)
297
+ )
298
+ },
299
+ isBid,
300
+ normalized_price: normalizedPrice.toFixed(9)
301
+ };
302
+ return normalizedOrderInfo;
303
+ } catch {
304
+ return null;
305
+ }
306
+ }
307
+ /**
308
+ * @description Retrieves information for multiple specific orders in a pool.
309
+ * @param {string} poolKey - The key identifying the pool from which to retrieve order information.
310
+ * @param {string[]} orderIds - List of order IDs to retrieve information for.
311
+ * @returns {Promise<Object[] | null>} A promise that resolves to an array of order objects, each containing details such as
312
+ * balance manager ID, order ID, client order ID, quantity, filled quantity, fee information, order price, epoch, status,
313
+ * and expiration timestamp. Returns `null` if the retrieval fails.
314
+ */
315
+ async getOrders(poolKey, orderIds) {
316
+ const tx = new import_transactions.Transaction();
317
+ tx.add(this.deepBook.getOrders(poolKey, orderIds));
318
+ const res = await this.client.devInspectTransactionBlock({
319
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
320
+ transactionBlock: tx
321
+ });
322
+ try {
323
+ const orderInformation = res.results[0].returnValues[0][0];
324
+ return import_bcs.bcs.vector(import_bcs2.Order).parse(new Uint8Array(orderInformation));
325
+ } catch {
326
+ return null;
327
+ }
328
+ }
329
+ /**
330
+ * @description Get level 2 order book specifying range of price
331
+ * @param {string} poolKey Key of the pool
332
+ * @param {number} priceLow Lower bound of the price range
333
+ * @param {number} priceHigh Upper bound of the price range
334
+ * @param {boolean} isBid Whether to get bid or ask orders
335
+ * @returns {Promise<{ prices: Array<number>, quantities: Array<number> }>}
336
+ * An object with arrays of prices and quantities
337
+ */
338
+ async getLevel2Range(poolKey, priceLow, priceHigh, isBid) {
339
+ const tx = new import_transactions.Transaction();
340
+ const pool = __privateGet(this, _config).getPool(poolKey);
341
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
342
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
343
+ tx.add(this.deepBook.getLevel2Range(poolKey, priceLow, priceHigh, isBid));
344
+ const res = await this.client.devInspectTransactionBlock({
345
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
346
+ transactionBlock: tx
347
+ });
348
+ const prices = res.results[0].returnValues[0][0];
349
+ const parsed_prices = import_bcs.bcs.vector(import_bcs.bcs.u64()).parse(new Uint8Array(prices));
350
+ const quantities = res.results[0].returnValues[1][0];
351
+ const parsed_quantities = import_bcs.bcs.vector(import_bcs.bcs.u64()).parse(new Uint8Array(quantities));
352
+ return {
353
+ prices: parsed_prices.map(
354
+ (price) => Number((Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9))
355
+ ),
356
+ quantities: parsed_quantities.map(
357
+ (price) => Number((Number(price) / baseCoin.scalar).toFixed(9))
358
+ )
359
+ };
360
+ }
361
+ /**
362
+ * @description Get level 2 order book ticks from mid-price for a pool
363
+ * @param {string} poolKey Key of the pool
364
+ * @param {number} ticks Number of ticks from mid-price
365
+ * @returns {Promise<{ bid_prices: Array<number>, bid_quantities: Array<number>, ask_prices: Array<number>, ask_quantities: Array<number> }>}
366
+ * An object with arrays of prices and quantities
367
+ */
368
+ async getLevel2TicksFromMid(poolKey, ticks) {
369
+ const tx = new import_transactions.Transaction();
370
+ const pool = __privateGet(this, _config).getPool(poolKey);
371
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
372
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
373
+ tx.add(this.deepBook.getLevel2TicksFromMid(poolKey, ticks));
374
+ const res = await this.client.devInspectTransactionBlock({
375
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
376
+ transactionBlock: tx
377
+ });
378
+ const bid_prices = res.results[0].returnValues[0][0];
379
+ const bid_parsed_prices = import_bcs.bcs.vector(import_bcs.bcs.u64()).parse(new Uint8Array(bid_prices));
380
+ const bid_quantities = res.results[0].returnValues[1][0];
381
+ const bid_parsed_quantities = import_bcs.bcs.vector(import_bcs.bcs.u64()).parse(new Uint8Array(bid_quantities));
382
+ const ask_prices = res.results[0].returnValues[2][0];
383
+ const ask_parsed_prices = import_bcs.bcs.vector(import_bcs.bcs.u64()).parse(new Uint8Array(ask_prices));
384
+ const ask_quantities = res.results[0].returnValues[3][0];
385
+ const ask_parsed_quantities = import_bcs.bcs.vector(import_bcs.bcs.u64()).parse(new Uint8Array(ask_quantities));
386
+ return {
387
+ bid_prices: bid_parsed_prices.map(
388
+ (price) => Number((Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9))
389
+ ),
390
+ bid_quantities: bid_parsed_quantities.map(
391
+ (quantity) => Number((Number(quantity) / baseCoin.scalar).toFixed(9))
392
+ ),
393
+ ask_prices: ask_parsed_prices.map(
394
+ (price) => Number((Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9))
395
+ ),
396
+ ask_quantities: ask_parsed_quantities.map(
397
+ (quantity) => Number((Number(quantity) / baseCoin.scalar).toFixed(9))
398
+ )
399
+ };
400
+ }
401
+ /**
402
+ * @description Get the vault balances for a pool
403
+ * @param {string} poolKey Key of the pool
404
+ * @returns {Promise<{ base: number, quote: number, deep: number }>}
405
+ * An object with base, quote, and deep balances in the vault
406
+ */
407
+ async vaultBalances(poolKey) {
408
+ const tx = new import_transactions.Transaction();
409
+ const pool = __privateGet(this, _config).getPool(poolKey);
410
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
411
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
412
+ tx.add(this.deepBook.vaultBalances(poolKey));
413
+ const res = await this.client.devInspectTransactionBlock({
414
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
415
+ transactionBlock: tx
416
+ });
417
+ const baseInVault = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
418
+ const quoteInVault = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
419
+ const deepInVault = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
420
+ return {
421
+ base: Number((baseInVault / baseScalar).toFixed(9)),
422
+ quote: Number((quoteInVault / quoteScalar).toFixed(9)),
423
+ deep: Number((deepInVault / import_config.DEEP_SCALAR).toFixed(9))
424
+ };
425
+ }
426
+ /**
427
+ * @description Get the pool ID by asset types
428
+ * @param {string} baseType Type of the base asset
429
+ * @param {string} quoteType Type of the quote asset
430
+ * @returns {Promise<string>} The address of the pool
431
+ */
432
+ async getPoolIdByAssets(baseType, quoteType) {
433
+ const tx = new import_transactions.Transaction();
434
+ tx.add(this.deepBook.getPoolIdByAssets(baseType, quoteType));
435
+ const res = await this.client.devInspectTransactionBlock({
436
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
437
+ transactionBlock: tx
438
+ });
439
+ const address = import_bcs.bcs.Address.parse(new Uint8Array(res.results[0].returnValues[0][0]));
440
+ return address;
441
+ }
442
+ /**
443
+ * @description Get the mid price for a pool
444
+ * @param {string} poolKey Key of the pool
445
+ * @returns {Promise<number>} The mid price
446
+ */
447
+ async midPrice(poolKey) {
448
+ const tx = new import_transactions.Transaction();
449
+ const pool = __privateGet(this, _config).getPool(poolKey);
450
+ tx.add(this.deepBook.midPrice(poolKey));
451
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
452
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
453
+ const res = await this.client.devInspectTransactionBlock({
454
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
455
+ transactionBlock: tx
456
+ });
457
+ const bytes = res.results[0].returnValues[0][0];
458
+ const parsed_mid_price = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
459
+ const adjusted_mid_price = parsed_mid_price * baseCoin.scalar / quoteCoin.scalar / import_config.FLOAT_SCALAR;
460
+ return Number(adjusted_mid_price.toFixed(9));
461
+ }
462
+ /**
463
+ * @description Get the trade parameters for a given pool, including taker fee, maker fee, and stake required.
464
+ * @param {string} poolKey Key of the pool
465
+ * @returns {Promise<{ takerFee: number, makerFee: number, stakeRequired: number }>}
466
+ */
467
+ async poolTradeParams(poolKey) {
468
+ const tx = new import_transactions.Transaction();
469
+ tx.add(this.deepBook.poolTradeParams(poolKey));
470
+ const res = await this.client.devInspectTransactionBlock({
471
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
472
+ transactionBlock: tx
473
+ });
474
+ const takerFee = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
475
+ const makerFee = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
476
+ const stakeRequired = Number(
477
+ import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0]))
478
+ );
479
+ return {
480
+ takerFee: Number(takerFee / import_config.FLOAT_SCALAR),
481
+ makerFee: Number(makerFee / import_config.FLOAT_SCALAR),
482
+ stakeRequired: Number(stakeRequired / import_config.DEEP_SCALAR)
483
+ };
484
+ }
485
+ /**
486
+ * @description Get the trade parameters for a given pool, including tick size, lot size, and min size.
487
+ * @param {string} poolKey Key of the pool
488
+ * @returns {Promise<{ tickSize: number, lotSize: number, minSize: number }>}
489
+ */
490
+ async poolBookParams(poolKey) {
491
+ const tx = new import_transactions.Transaction();
492
+ const pool = __privateGet(this, _config).getPool(poolKey);
493
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
494
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
495
+ tx.add(this.deepBook.poolBookParams(poolKey));
496
+ const res = await this.client.devInspectTransactionBlock({
497
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
498
+ transactionBlock: tx
499
+ });
500
+ const tickSize = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
501
+ const lotSize = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
502
+ const minSize = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
503
+ return {
504
+ tickSize: Number(tickSize * baseScalar / quoteScalar / import_config.FLOAT_SCALAR),
505
+ lotSize: Number(lotSize / baseScalar),
506
+ minSize: Number(minSize / baseScalar)
507
+ };
508
+ }
509
+ /**
510
+ * @description Get the account information for a given pool and balance manager
511
+ * @param {string} poolKey Key of the pool
512
+ * @param {string} managerKey The key of the BalanceManager
513
+ * @returns {Promise<Object>} A promise that resolves to an object containing the account information
514
+ */
515
+ async account(poolKey, managerKey) {
516
+ const tx = new import_transactions.Transaction();
517
+ const pool = __privateGet(this, _config).getPool(poolKey);
518
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
519
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
520
+ tx.add(this.deepBook.account(poolKey, managerKey));
521
+ const res = await this.client.devInspectTransactionBlock({
522
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
523
+ transactionBlock: tx
524
+ });
525
+ const accountInformation = res.results[0].returnValues[0][0];
526
+ const accountInfo = import_bcs2.Account.parse(new Uint8Array(accountInformation));
527
+ return {
528
+ epoch: accountInfo.epoch,
529
+ open_orders: accountInfo.open_orders,
530
+ taker_volume: Number(accountInfo.taker_volume) / baseScalar,
531
+ maker_volume: Number(accountInfo.maker_volume) / baseScalar,
532
+ active_stake: Number(accountInfo.active_stake) / import_config.DEEP_SCALAR,
533
+ inactive_stake: Number(accountInfo.inactive_stake) / import_config.DEEP_SCALAR,
534
+ created_proposal: accountInfo.created_proposal,
535
+ voted_proposal: accountInfo.voted_proposal,
536
+ unclaimed_rebates: {
537
+ base: Number(accountInfo.unclaimed_rebates.base) / baseScalar,
538
+ quote: Number(accountInfo.unclaimed_rebates.quote) / quoteScalar,
539
+ deep: Number(accountInfo.unclaimed_rebates.deep) / import_config.DEEP_SCALAR
540
+ },
541
+ settled_balances: {
542
+ base: Number(accountInfo.settled_balances.base) / baseScalar,
543
+ quote: Number(accountInfo.settled_balances.quote) / quoteScalar,
544
+ deep: Number(accountInfo.settled_balances.deep) / import_config.DEEP_SCALAR
545
+ },
546
+ owed_balances: {
547
+ base: Number(accountInfo.owed_balances.base) / baseScalar,
548
+ quote: Number(accountInfo.owed_balances.quote) / quoteScalar,
549
+ deep: Number(accountInfo.owed_balances.deep) / import_config.DEEP_SCALAR
550
+ }
551
+ };
552
+ }
553
+ /**
554
+ * @description Get the locked balances for a pool and balance manager
555
+ * @param {string} poolKey Key of the pool
556
+ * @param {string} managerKey The key of the BalanceManager
557
+ * @returns {Promise<{ base: number, quote: number, deep: number }>}
558
+ * An object with base, quote, and deep locked for the balance manager in the pool
559
+ */
560
+ async lockedBalance(poolKey, balanceManagerKey) {
561
+ const tx = new import_transactions.Transaction();
562
+ const pool = __privateGet(this, _config).getPool(poolKey);
563
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
564
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
565
+ tx.add(this.deepBook.lockedBalance(poolKey, balanceManagerKey));
566
+ const res = await this.client.devInspectTransactionBlock({
567
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
568
+ transactionBlock: tx
569
+ });
570
+ const baseLocked = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
571
+ const quoteLocked = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
572
+ const deepLocked = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
573
+ return {
574
+ base: Number((baseLocked / baseScalar).toFixed(9)),
575
+ quote: Number((quoteLocked / quoteScalar).toFixed(9)),
576
+ deep: Number((deepLocked / import_config.DEEP_SCALAR).toFixed(9))
577
+ };
578
+ }
579
+ /**
580
+ * @description Get the DEEP price conversion for a pool
581
+ * @param {string} poolKey Key of the pool
582
+ * @returns {Promise<{ asset_is_base: bool, deep_per_quote: number }>} Deep price conversion
583
+ */
584
+ async getPoolDeepPrice(poolKey) {
585
+ const tx = new import_transactions.Transaction();
586
+ const pool = __privateGet(this, _config).getPool(poolKey);
587
+ tx.add(this.deepBook.getPoolDeepPrice(poolKey));
588
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
589
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
590
+ const deepCoin = __privateGet(this, _config).getCoin("DEEP");
591
+ const res = await this.client.devInspectTransactionBlock({
592
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
593
+ transactionBlock: tx
594
+ });
595
+ const poolDeepPriceBytes = res.results[0].returnValues[0][0];
596
+ const poolDeepPrice = import_bcs2.OrderDeepPrice.parse(new Uint8Array(poolDeepPriceBytes));
597
+ if (poolDeepPrice.asset_is_base) {
598
+ return {
599
+ asset_is_base: poolDeepPrice.asset_is_base,
600
+ deep_per_base: Number(poolDeepPrice.deep_per_asset) / import_config.FLOAT_SCALAR * baseCoin.scalar / deepCoin.scalar
601
+ };
602
+ } else {
603
+ return {
604
+ asset_is_base: poolDeepPrice.asset_is_base,
605
+ deep_per_quote: Number(poolDeepPrice.deep_per_asset) / import_config.FLOAT_SCALAR * quoteCoin.scalar / deepCoin.scalar
606
+ };
607
+ }
608
+ }
609
+ /**
610
+ * @description Decode the order ID to get bid/ask status, price, and orderId
611
+ * @param {bigint} encodedOrderId Encoded order ID
612
+ * @returns {Object} Object containing isBid, price, and orderId
613
+ */
614
+ decodeOrderId(encodedOrderId) {
615
+ const isBid = encodedOrderId >> 127n === 0n;
616
+ const price = Number(encodedOrderId >> 64n & (1n << 63n) - 1n);
617
+ const orderId = Number(encodedOrderId & (1n << 64n) - 1n);
618
+ return { isBid, price, orderId };
619
+ }
620
+ /**
621
+ * @description Get all balance manager IDs for a given owner
622
+ * @param {string} owner The owner address to get balance manager IDs for
623
+ * @returns {Promise<string[]>} Array of balance manager ID strings
624
+ */
625
+ async getBalanceManagerIds(owner) {
626
+ const tx = new import_transactions.Transaction();
627
+ tx.add(this.deepBook.getBalanceManagerIds(owner));
628
+ const res = await this.client.devInspectTransactionBlock({
629
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
630
+ transactionBlock: tx
631
+ });
632
+ const bytes = res.results[0].returnValues[0][0];
633
+ const vecOfAddresses = import_bcs.bcs.vector(import_bcs.bcs.Address).parse(new Uint8Array(bytes));
634
+ return vecOfAddresses.map((id) => (0, import_utils.normalizeHaneulAddress)(id));
635
+ }
636
+ /**
637
+ * @description Get the owner of the referral (DeepBookPoolReferral)
638
+ * @param {string} referral The ID of the referral to get the owner of
639
+ * @returns {Promise<string>} The owner of the referral
640
+ */
641
+ async balanceManagerReferralOwner(referral) {
642
+ const tx = new import_transactions.Transaction();
643
+ tx.add(this.balanceManager.balanceManagerReferralOwner(referral));
644
+ const res = await this.client.devInspectTransactionBlock({
645
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
646
+ transactionBlock: tx
647
+ });
648
+ if (res.error || !res.results || res.results.length === 0) {
649
+ throw new Error(`Failed to get referral owner: ${res.error || "No results returned"}`);
650
+ }
651
+ const bytes = res.results[0].returnValues[0][0];
652
+ const owner = import_bcs.bcs.Address.parse(new Uint8Array(bytes));
653
+ return owner;
654
+ }
655
+ /**
656
+ * @description Get the referral balances for a pool and referral (DeepBookPoolReferral)
657
+ * @param {string} poolKey Key of the pool
658
+ * @param {string} referral The referral ID to get balances for
659
+ * @returns {Promise<{ base: number, quote: number, deep: number }>} Object with base, quote, and deep balances
660
+ */
661
+ async getPoolReferralBalances(poolKey, referral) {
662
+ const tx = new import_transactions.Transaction();
663
+ const pool = __privateGet(this, _config).getPool(poolKey);
664
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
665
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
666
+ tx.add(this.deepBook.getPoolReferralBalances(poolKey, referral));
667
+ const res = await this.client.devInspectTransactionBlock({
668
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
669
+ transactionBlock: tx
670
+ });
671
+ const baseBytes = res.results[0].returnValues[0][0];
672
+ const quoteBytes = res.results[0].returnValues[1][0];
673
+ const deepBytes = res.results[0].returnValues[2][0];
674
+ const baseBalance = Number(import_bcs.bcs.U64.parse(new Uint8Array(baseBytes)));
675
+ const quoteBalance = Number(import_bcs.bcs.U64.parse(new Uint8Array(quoteBytes)));
676
+ const deepBalance = Number(import_bcs.bcs.U64.parse(new Uint8Array(deepBytes)));
677
+ return {
678
+ base: baseBalance / baseScalar,
679
+ quote: quoteBalance / quoteScalar,
680
+ deep: deepBalance / import_config.DEEP_SCALAR
681
+ };
682
+ }
683
+ /**
684
+ * @description Get the pool ID associated with a referral (DeepBookPoolReferral)
685
+ * @param {string} referral The referral (DeepBookPoolReferral) to get the pool ID for
686
+ * @returns {Promise<string>} The pool ID
687
+ */
688
+ async balanceManagerReferralPoolId(referral) {
689
+ const tx = new import_transactions.Transaction();
690
+ tx.add(this.balanceManager.balanceManagerReferralPoolId(referral));
691
+ const res = await this.client.devInspectTransactionBlock({
692
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
693
+ transactionBlock: tx
694
+ });
695
+ const bytes = res.results[0].returnValues[0][0];
696
+ const poolId = import_bcs.bcs.Address.parse(new Uint8Array(bytes));
697
+ return (0, import_utils.normalizeHaneulAddress)(poolId);
698
+ }
699
+ /**
700
+ * @description Get the multiplier for a referral (DeepBookPoolReferral)
701
+ * @param {string} poolKey Key of the pool
702
+ * @param {string} referral The referral (DeepBookPoolReferral) to get the multiplier for
703
+ * @returns {Promise<number>} The multiplier value
704
+ */
705
+ async poolReferralMultiplier(poolKey, referral) {
706
+ const tx = new import_transactions.Transaction();
707
+ tx.add(this.deepBook.poolReferralMultiplier(poolKey, referral));
708
+ const res = await this.client.devInspectTransactionBlock({
709
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
710
+ transactionBlock: tx
711
+ });
712
+ const bytes = res.results[0].returnValues[0][0];
713
+ const multiplier = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
714
+ return multiplier / import_config.FLOAT_SCALAR;
715
+ }
716
+ /**
717
+ * @description Get the referral ID from a balance manager for a specific pool
718
+ * @param {string} managerKey Key of the balance manager
719
+ * @param {string} poolKey Key of the pool to get the referral for
720
+ * @returns {Promise<string | null>} The referral ID or null if not set
721
+ */
722
+ async getBalanceManagerReferralId(managerKey, poolKey) {
723
+ const tx = new import_transactions.Transaction();
724
+ tx.add(this.balanceManager.getBalanceManagerReferralId(managerKey, poolKey));
725
+ const res = await this.client.devInspectTransactionBlock({
726
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
727
+ transactionBlock: tx
728
+ });
729
+ try {
730
+ const bytes = res.results[0].returnValues[0][0];
731
+ const optionId = import_bcs.bcs.option(import_bcs.bcs.Address).parse(new Uint8Array(bytes));
732
+ if (optionId === null) {
733
+ return null;
734
+ }
735
+ return (0, import_utils.normalizeHaneulAddress)(optionId);
736
+ } catch {
737
+ return null;
738
+ }
739
+ }
740
+ async getPriceInfoObject(tx, coinKey) {
741
+ const currentTime = Date.now();
742
+ const priceInfoObjectAge = await this.getPriceInfoObjectAge(coinKey) * 1e3;
743
+ if (currentTime - priceInfoObjectAge < import_config.PRICE_INFO_OBJECT_MAX_AGE_MS) {
744
+ return await __privateGet(this, _config).getCoin(coinKey).priceInfoObjectId;
745
+ }
746
+ const endpoint = __privateGet(this, _config).env === "testnet" ? "https://hermes-beta.pyth.network" : "https://hermes.pyth.network";
747
+ const connection = new import_pyth.HaneulPriceServiceConnection(endpoint);
748
+ const priceIDs = [
749
+ __privateGet(this, _config).getCoin(coinKey).feed
750
+ // ASSET/USD price ID
751
+ ];
752
+ const priceUpdateData = await connection.getPriceFeedsUpdateData(priceIDs);
753
+ const wormholeStateId = __privateGet(this, _config).pyth.wormholeStateId;
754
+ const pythStateId = __privateGet(this, _config).pyth.pythStateId;
755
+ const client = new import_pyth2.HaneulPythClient(this.client, pythStateId, wormholeStateId);
756
+ return (await client.updatePriceFeeds(tx, priceUpdateData, priceIDs))[0];
757
+ }
758
+ /**
759
+ * @description Get the age of the price info object for a specific coin
760
+ * @param {string} coinKey Key of the coin
761
+ * @returns {Promise<string>} The arrival time of the price info object
762
+ */
763
+ async getPriceInfoObjectAge(coinKey) {
764
+ const priceInfoObjectId = __privateGet(this, _config).getCoin(coinKey).priceInfoObjectId;
765
+ const res = await this.client.getObject({
766
+ id: priceInfoObjectId,
767
+ options: {
768
+ showContent: true
769
+ }
770
+ });
771
+ if (!res.data?.content) {
772
+ throw new Error(`Price info object not found for ${coinKey}`);
773
+ }
774
+ if ("fields" in res.data.content) {
775
+ const fields = res.data.content.fields;
776
+ return fields.price_info?.fields?.arrival_time;
777
+ } else {
778
+ throw new Error(`Invalid price info object structure for ${coinKey}`);
779
+ }
780
+ }
781
+ // === Margin Pool View Methods ===
782
+ /**
783
+ * @description Get the margin pool ID
784
+ * @param {string} coinKey The key to identify the margin pool
785
+ * @returns {Promise<string>} The margin pool ID
786
+ */
787
+ async getMarginPoolId(coinKey) {
788
+ const tx = new import_transactions.Transaction();
789
+ tx.add(this.marginPool.getId(coinKey));
790
+ const res = await this.client.devInspectTransactionBlock({
791
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
792
+ transactionBlock: tx
793
+ });
794
+ const bytes = res.results[0].returnValues[0][0];
795
+ return import_bcs.bcs.Address.parse(new Uint8Array(bytes));
796
+ }
797
+ /**
798
+ * @description Check if a deepbook pool is allowed for borrowing from margin pool
799
+ * @param {string} coinKey The key to identify the margin pool
800
+ * @param {string} deepbookPoolId The ID of the deepbook pool
801
+ * @returns {Promise<boolean>} Whether the deepbook pool is allowed
802
+ */
803
+ async isDeepbookPoolAllowed(coinKey, deepbookPoolId) {
804
+ const tx = new import_transactions.Transaction();
805
+ tx.add(this.marginPool.deepbookPoolAllowed(coinKey, deepbookPoolId));
806
+ const res = await this.client.devInspectTransactionBlock({
807
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
808
+ transactionBlock: tx
809
+ });
810
+ const bytes = res.results[0].returnValues[0][0];
811
+ return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
812
+ }
813
+ /**
814
+ * @description Get the total supply amount in the margin pool
815
+ * @param {string} coinKey The key to identify the margin pool
816
+ * @param {number} decimals Number of decimal places to show (default: 6)
817
+ * @returns {Promise<string>} The total supply amount as a string
818
+ */
819
+ async getMarginPoolTotalSupply(coinKey, decimals = 6) {
820
+ const tx = new import_transactions.Transaction();
821
+ tx.add(this.marginPool.totalSupply(coinKey));
822
+ const res = await this.client.devInspectTransactionBlock({
823
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
824
+ transactionBlock: tx
825
+ });
826
+ const bytes = res.results[0].returnValues[0][0];
827
+ const rawAmount = BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
828
+ const coin = __privateGet(this, _config).getCoin(coinKey);
829
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, rawAmount, coin.scalar, decimals);
830
+ }
831
+ /**
832
+ * @description Get the total supply shares in the margin pool
833
+ * @param {string} coinKey The key to identify the margin pool
834
+ * @param {number} decimals Number of decimal places to show (default: 6)
835
+ * @returns {Promise<string>} The total supply shares as a string
836
+ */
837
+ async getMarginPoolSupplyShares(coinKey, decimals = 6) {
838
+ const tx = new import_transactions.Transaction();
839
+ tx.add(this.marginPool.supplyShares(coinKey));
840
+ const res = await this.client.devInspectTransactionBlock({
841
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
842
+ transactionBlock: tx
843
+ });
844
+ const bytes = res.results[0].returnValues[0][0];
845
+ const rawShares = BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
846
+ const coin = __privateGet(this, _config).getCoin(coinKey);
847
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, rawShares, coin.scalar, decimals);
848
+ }
849
+ /**
850
+ * @description Get the total borrow amount in the margin pool
851
+ * @param {string} coinKey The key to identify the margin pool
852
+ * @param {number} decimals Number of decimal places to show (default: 6)
853
+ * @returns {Promise<string>} The total borrow amount as a string
854
+ */
855
+ async getMarginPoolTotalBorrow(coinKey, decimals = 6) {
856
+ const tx = new import_transactions.Transaction();
857
+ tx.add(this.marginPool.totalBorrow(coinKey));
858
+ const res = await this.client.devInspectTransactionBlock({
859
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
860
+ transactionBlock: tx
861
+ });
862
+ const bytes = res.results[0].returnValues[0][0];
863
+ const rawAmount = BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
864
+ const coin = __privateGet(this, _config).getCoin(coinKey);
865
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, rawAmount, coin.scalar, decimals);
866
+ }
867
+ /**
868
+ * @description Get the total borrow shares in the margin pool
869
+ * @param {string} coinKey The key to identify the margin pool
870
+ * @param {number} decimals Number of decimal places to show (default: 6)
871
+ * @returns {Promise<string>} The total borrow shares as a string
872
+ */
873
+ async getMarginPoolBorrowShares(coinKey, decimals = 6) {
874
+ const tx = new import_transactions.Transaction();
875
+ tx.add(this.marginPool.borrowShares(coinKey));
876
+ const res = await this.client.devInspectTransactionBlock({
877
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
878
+ transactionBlock: tx
879
+ });
880
+ const bytes = res.results[0].returnValues[0][0];
881
+ const rawShares = BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
882
+ const coin = __privateGet(this, _config).getCoin(coinKey);
883
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, rawShares, coin.scalar, decimals);
884
+ }
885
+ /**
886
+ * @description Get the last update timestamp of the margin pool
887
+ * @param {string} coinKey The key to identify the margin pool
888
+ * @returns {Promise<number>} The last update timestamp in milliseconds
889
+ */
890
+ async getMarginPoolLastUpdateTimestamp(coinKey) {
891
+ const tx = new import_transactions.Transaction();
892
+ tx.add(this.marginPool.lastUpdateTimestamp(coinKey));
893
+ const res = await this.client.devInspectTransactionBlock({
894
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
895
+ transactionBlock: tx
896
+ });
897
+ const bytes = res.results[0].returnValues[0][0];
898
+ return Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
899
+ }
900
+ /**
901
+ * @description Get the supply cap of the margin pool
902
+ * @param {string} coinKey The key to identify the margin pool
903
+ * @param {number} decimals Number of decimal places to show (default: 6)
904
+ * @returns {Promise<string>} The supply cap as a string
905
+ */
906
+ async getMarginPoolSupplyCap(coinKey, decimals = 6) {
907
+ const tx = new import_transactions.Transaction();
908
+ tx.add(this.marginPool.supplyCap(coinKey));
909
+ const res = await this.client.devInspectTransactionBlock({
910
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
911
+ transactionBlock: tx
912
+ });
913
+ const bytes = res.results[0].returnValues[0][0];
914
+ const rawAmount = BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
915
+ const coin = __privateGet(this, _config).getCoin(coinKey);
916
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, rawAmount, coin.scalar, decimals);
917
+ }
918
+ /**
919
+ * @description Get the max utilization rate of the margin pool
920
+ * @param {string} coinKey The key to identify the margin pool
921
+ * @returns {Promise<number>} The max utilization rate (as a decimal, e.g., 0.95 for 95%)
922
+ */
923
+ async getMarginPoolMaxUtilizationRate(coinKey) {
924
+ const tx = new import_transactions.Transaction();
925
+ tx.add(this.marginPool.maxUtilizationRate(coinKey));
926
+ const res = await this.client.devInspectTransactionBlock({
927
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
928
+ transactionBlock: tx
929
+ });
930
+ const bytes = res.results[0].returnValues[0][0];
931
+ const rawRate = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
932
+ return rawRate / import_config.FLOAT_SCALAR;
933
+ }
934
+ /**
935
+ * @description Get the protocol spread of the margin pool
936
+ * @param {string} coinKey The key to identify the margin pool
937
+ * @returns {Promise<number>} The protocol spread (as a decimal)
938
+ */
939
+ async getMarginPoolProtocolSpread(coinKey) {
940
+ const tx = new import_transactions.Transaction();
941
+ tx.add(this.marginPool.protocolSpread(coinKey));
942
+ const res = await this.client.devInspectTransactionBlock({
943
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
944
+ transactionBlock: tx
945
+ });
946
+ const bytes = res.results[0].returnValues[0][0];
947
+ const rawSpread = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
948
+ return rawSpread / import_config.FLOAT_SCALAR;
949
+ }
950
+ /**
951
+ * @description Get the minimum borrow amount for the margin pool
952
+ * @param {string} coinKey The key to identify the margin pool
953
+ * @param {number} decimals Number of decimal places to show (default: 6)
954
+ * @returns {Promise<string>} The minimum borrow amount as a string
955
+ */
956
+ async getMarginPoolMinBorrow(coinKey, decimals = 6) {
957
+ const tx = new import_transactions.Transaction();
958
+ tx.add(this.marginPool.minBorrow(coinKey));
959
+ const res = await this.client.devInspectTransactionBlock({
960
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
961
+ transactionBlock: tx
962
+ });
963
+ const bytes = res.results[0].returnValues[0][0];
964
+ const rawAmount = BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
965
+ const coin = __privateGet(this, _config).getCoin(coinKey);
966
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, rawAmount, coin.scalar, decimals);
967
+ }
968
+ /**
969
+ * @description Get the current interest rate of the margin pool
970
+ * @param {string} coinKey The key to identify the margin pool
971
+ * @returns {Promise<number>} The current interest rate (as a decimal)
972
+ */
973
+ async getMarginPoolInterestRate(coinKey) {
974
+ const tx = new import_transactions.Transaction();
975
+ tx.add(this.marginPool.interestRate(coinKey));
976
+ const res = await this.client.devInspectTransactionBlock({
977
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
978
+ transactionBlock: tx
979
+ });
980
+ const bytes = res.results[0].returnValues[0][0];
981
+ const rawRate = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
982
+ return rawRate / import_config.FLOAT_SCALAR;
983
+ }
984
+ /**
985
+ * @description Get user supply shares for a supplier cap
986
+ * @param {string} coinKey The key to identify the margin pool
987
+ * @param {string} supplierCapId The ID of the supplier cap
988
+ * @param {number} decimals Number of decimal places to show (default: 6)
989
+ * @returns {Promise<string>} The user's supply shares as a string
990
+ */
991
+ async getUserSupplyShares(coinKey, supplierCapId, decimals = 6) {
992
+ const tx = new import_transactions.Transaction();
993
+ tx.add(this.marginPool.userSupplyShares(coinKey, supplierCapId));
994
+ const res = await this.client.devInspectTransactionBlock({
995
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
996
+ transactionBlock: tx
997
+ });
998
+ const bytes = res.results[0].returnValues[0][0];
999
+ const rawShares = BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1000
+ const coin = __privateGet(this, _config).getCoin(coinKey);
1001
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, rawShares, coin.scalar, decimals);
1002
+ }
1003
+ /**
1004
+ * @description Get user supply amount for a supplier cap
1005
+ * @param {string} coinKey The key to identify the margin pool
1006
+ * @param {string} supplierCapId The ID of the supplier cap
1007
+ * @param {number} decimals Number of decimal places to show (default: 6)
1008
+ * @returns {Promise<string>} The user's supply amount as a string
1009
+ */
1010
+ async getUserSupplyAmount(coinKey, supplierCapId, decimals = 6) {
1011
+ const tx = new import_transactions.Transaction();
1012
+ tx.add(this.marginPool.userSupplyAmount(coinKey, supplierCapId));
1013
+ const res = await this.client.devInspectTransactionBlock({
1014
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1015
+ transactionBlock: tx
1016
+ });
1017
+ const bytes = res.results[0].returnValues[0][0];
1018
+ const rawAmount = BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1019
+ const coin = __privateGet(this, _config).getCoin(coinKey);
1020
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, rawAmount, coin.scalar, decimals);
1021
+ }
1022
+ // === Margin Manager Read-Only Functions ===
1023
+ /**
1024
+ * @description Get the owner address of a margin manager
1025
+ * @param {string} marginManagerKey The key to identify the margin manager
1026
+ * @returns {Promise<string>} The owner address
1027
+ */
1028
+ async getMarginManagerOwner(marginManagerKey) {
1029
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1030
+ const tx = new import_transactions.Transaction();
1031
+ tx.add(this.marginManager.ownerByPoolKey(manager.poolKey, manager.address));
1032
+ const res = await this.client.devInspectTransactionBlock({
1033
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1034
+ transactionBlock: tx
1035
+ });
1036
+ const bytes = res.results[0].returnValues[0][0];
1037
+ return (0, import_utils.normalizeHaneulAddress)(import_bcs.bcs.Address.parse(new Uint8Array(bytes)));
1038
+ }
1039
+ /**
1040
+ * @description Get the DeepBook pool ID associated with a margin manager
1041
+ * @param {string} marginManagerKey The key to identify the margin manager
1042
+ * @returns {Promise<string>} The DeepBook pool ID
1043
+ */
1044
+ async getMarginManagerDeepbookPool(marginManagerKey) {
1045
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1046
+ const tx = new import_transactions.Transaction();
1047
+ tx.add(this.marginManager.deepbookPool(manager.poolKey, manager.address));
1048
+ const res = await this.client.devInspectTransactionBlock({
1049
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1050
+ transactionBlock: tx
1051
+ });
1052
+ const bytes = res.results[0].returnValues[0][0];
1053
+ return (0, import_utils.normalizeHaneulAddress)(import_bcs.bcs.Address.parse(new Uint8Array(bytes)));
1054
+ }
1055
+ /**
1056
+ * @description Get the margin pool ID (if any) associated with a margin manager
1057
+ * @param {string} marginManagerKey The key to identify the margin manager
1058
+ * @returns {Promise<string | null>} The margin pool ID or null if no active loan
1059
+ */
1060
+ async getMarginManagerMarginPoolId(marginManagerKey) {
1061
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1062
+ const tx = new import_transactions.Transaction();
1063
+ tx.add(this.marginManager.marginPoolId(manager.poolKey, manager.address));
1064
+ const res = await this.client.devInspectTransactionBlock({
1065
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1066
+ transactionBlock: tx
1067
+ });
1068
+ const bytes = res.results[0].returnValues[0][0];
1069
+ const option = import_bcs.bcs.option(import_bcs.bcs.Address).parse(new Uint8Array(bytes));
1070
+ return option ? (0, import_utils.normalizeHaneulAddress)(option) : null;
1071
+ }
1072
+ /**
1073
+ * @description Get borrowed shares for both base and quote assets
1074
+ * @param {string} marginManagerKey The key to identify the margin manager
1075
+ * @returns {Promise<{baseShares: string, quoteShares: string}>} The borrowed shares
1076
+ */
1077
+ async getMarginManagerBorrowedShares(marginManagerKey) {
1078
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1079
+ const tx = new import_transactions.Transaction();
1080
+ tx.add(this.marginManager.borrowedShares(manager.poolKey, manager.address));
1081
+ const res = await this.client.devInspectTransactionBlock({
1082
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1083
+ transactionBlock: tx
1084
+ });
1085
+ const baseBytes = res.results[0].returnValues[0][0];
1086
+ const quoteBytes = res.results[0].returnValues[1][0];
1087
+ const baseShares = import_bcs.bcs.U64.parse(new Uint8Array(baseBytes)).toString();
1088
+ const quoteShares = import_bcs.bcs.U64.parse(new Uint8Array(quoteBytes)).toString();
1089
+ return { baseShares, quoteShares };
1090
+ }
1091
+ /**
1092
+ * @description Get borrowed base shares
1093
+ * @param {string} marginManagerKey The key to identify the margin manager
1094
+ * @returns {Promise<string>} The borrowed base shares
1095
+ */
1096
+ async getMarginManagerBorrowedBaseShares(marginManagerKey) {
1097
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1098
+ const tx = new import_transactions.Transaction();
1099
+ tx.add(this.marginManager.borrowedBaseShares(manager.poolKey, manager.address));
1100
+ const res = await this.client.devInspectTransactionBlock({
1101
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1102
+ transactionBlock: tx
1103
+ });
1104
+ const bytes = res.results[0].returnValues[0][0];
1105
+ return import_bcs.bcs.U64.parse(new Uint8Array(bytes)).toString();
1106
+ }
1107
+ /**
1108
+ * @description Get borrowed quote shares
1109
+ * @param {string} marginManagerKey The key to identify the margin manager
1110
+ * @returns {Promise<string>} The borrowed quote shares
1111
+ */
1112
+ async getMarginManagerBorrowedQuoteShares(marginManagerKey) {
1113
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1114
+ const tx = new import_transactions.Transaction();
1115
+ tx.add(this.marginManager.borrowedQuoteShares(manager.poolKey, manager.address));
1116
+ const res = await this.client.devInspectTransactionBlock({
1117
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1118
+ transactionBlock: tx
1119
+ });
1120
+ const bytes = res.results[0].returnValues[0][0];
1121
+ return import_bcs.bcs.U64.parse(new Uint8Array(bytes)).toString();
1122
+ }
1123
+ /**
1124
+ * @description Check if margin manager has base asset debt
1125
+ * @param {string} marginManagerKey The key to identify the margin manager
1126
+ * @returns {Promise<boolean>} True if has base debt, false otherwise
1127
+ */
1128
+ async getMarginManagerHasBaseDebt(marginManagerKey) {
1129
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1130
+ const tx = new import_transactions.Transaction();
1131
+ tx.add(this.marginManager.hasBaseDebt(manager.poolKey, manager.address));
1132
+ const res = await this.client.devInspectTransactionBlock({
1133
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1134
+ transactionBlock: tx
1135
+ });
1136
+ const bytes = res.results[0].returnValues[0][0];
1137
+ return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
1138
+ }
1139
+ /**
1140
+ * @description Get the balance manager ID for a margin manager
1141
+ * @param {string} marginManagerKey The key to identify the margin manager
1142
+ * @returns {Promise<string>} The balance manager ID
1143
+ */
1144
+ async getMarginManagerBalanceManagerId(marginManagerKey) {
1145
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1146
+ const tx = new import_transactions.Transaction();
1147
+ tx.add(this.marginManager.balanceManager(manager.poolKey, manager.address));
1148
+ const res = await this.client.devInspectTransactionBlock({
1149
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1150
+ transactionBlock: tx
1151
+ });
1152
+ const bytes = res.results[0].returnValues[0][0];
1153
+ return (0, import_utils.normalizeHaneulAddress)(import_bcs.bcs.Address.parse(new Uint8Array(bytes)));
1154
+ }
1155
+ /**
1156
+ * @description Calculate assets (base and quote) for a margin manager
1157
+ * @param {string} marginManagerKey The key to identify the margin manager
1158
+ * @param {number} decimals Number of decimal places to show (default: 6)
1159
+ * @returns {Promise<{baseAsset: string, quoteAsset: string}>} The base and quote assets
1160
+ */
1161
+ async getMarginManagerAssets(marginManagerKey, decimals = 6) {
1162
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1163
+ const tx = new import_transactions.Transaction();
1164
+ tx.add(this.marginManager.calculateAssets(manager.poolKey, manager.address));
1165
+ const res = await this.client.devInspectTransactionBlock({
1166
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1167
+ transactionBlock: tx
1168
+ });
1169
+ const baseBytes = res.results[0].returnValues[0][0];
1170
+ const quoteBytes = res.results[0].returnValues[1][0];
1171
+ const pool = __privateGet(this, _config).getPool(manager.poolKey);
1172
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1173
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1174
+ const baseAsset = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(baseBytes))), baseCoin.scalar, decimals);
1175
+ const quoteAsset = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(quoteBytes))), quoteCoin.scalar, decimals);
1176
+ return { baseAsset, quoteAsset };
1177
+ }
1178
+ /**
1179
+ * @description Calculate debts (base and quote) for a margin manager
1180
+ * NOTE: This function automatically determines whether to use base or quote margin pool
1181
+ * based on hasBaseDebt. You don't need to specify the debt coin type.
1182
+ * @param {string} marginManagerKey The key to identify the margin manager
1183
+ * @param {number} decimals Number of decimal places to show (default: 6)
1184
+ * @returns {Promise<{baseDebt: string, quoteDebt: string}>} The base and quote debts
1185
+ */
1186
+ async getMarginManagerDebts(marginManagerKey, decimals = 6) {
1187
+ const hasBaseDebt = await this.getMarginManagerHasBaseDebt(marginManagerKey);
1188
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1189
+ const pool = __privateGet(this, _config).getPool(manager.poolKey);
1190
+ const debtCoinKey = hasBaseDebt ? pool.baseCoin : pool.quoteCoin;
1191
+ const tx = new import_transactions.Transaction();
1192
+ tx.add(this.marginManager.calculateDebts(manager.poolKey, debtCoinKey, manager.address));
1193
+ const res = await this.client.devInspectTransactionBlock({
1194
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1195
+ transactionBlock: tx
1196
+ });
1197
+ if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1198
+ throw new Error(
1199
+ `Failed to get margin manager debts: ${res.effects?.status?.error || "Unknown error"}`
1200
+ );
1201
+ }
1202
+ const baseBytes = res.results[0].returnValues[0][0];
1203
+ const quoteBytes = res.results[0].returnValues[1][0];
1204
+ const debtCoin = __privateGet(this, _config).getCoin(debtCoinKey);
1205
+ const baseDebt = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(baseBytes))), debtCoin.scalar, decimals);
1206
+ const quoteDebt = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(quoteBytes))), debtCoin.scalar, decimals);
1207
+ return { baseDebt, quoteDebt };
1208
+ }
1209
+ /**
1210
+ * @description Get comprehensive state information for a margin manager
1211
+ * @param {string} marginManagerKey The key to identify the margin manager
1212
+ * @param {number} decimals Number of decimal places to show (default: 6)
1213
+ * @returns {Promise<{
1214
+ * managerId: string,
1215
+ * deepbookPoolId: string,
1216
+ * riskRatio: number,
1217
+ * baseAsset: string,
1218
+ * quoteAsset: string,
1219
+ * baseDebt: string,
1220
+ * quoteDebt: string,
1221
+ * basePythPrice: string,
1222
+ * basePythDecimals: number,
1223
+ * quotePythPrice: string,
1224
+ * quotePythDecimals: number
1225
+ * }>} Comprehensive margin manager state
1226
+ */
1227
+ async getMarginManagerState(marginManagerKey, decimals = 6) {
1228
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1229
+ const tx = new import_transactions.Transaction();
1230
+ tx.add(this.marginManager.managerState(manager.poolKey, manager.address));
1231
+ const res = await this.client.devInspectTransactionBlock({
1232
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1233
+ transactionBlock: tx
1234
+ });
1235
+ if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1236
+ throw new Error(
1237
+ `Failed to get margin manager state: ${res.effects?.status?.error || "Unknown error"}`
1238
+ );
1239
+ }
1240
+ const pool = __privateGet(this, _config).getPool(manager.poolKey);
1241
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1242
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1243
+ const managerId = (0, import_utils.normalizeHaneulAddress)(
1244
+ import_bcs.bcs.Address.parse(new Uint8Array(res.results[0].returnValues[0][0]))
1245
+ );
1246
+ const deepbookPoolId = (0, import_utils.normalizeHaneulAddress)(
1247
+ import_bcs.bcs.Address.parse(new Uint8Array(res.results[0].returnValues[1][0]))
1248
+ );
1249
+ const riskRatio = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0]))) / import_config.FLOAT_SCALAR;
1250
+ const baseAsset = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[3][0]))), baseCoin.scalar, decimals);
1251
+ const quoteAsset = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[4][0]))), quoteCoin.scalar, decimals);
1252
+ const baseDebt = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[5][0]))), baseCoin.scalar, decimals);
1253
+ const quoteDebt = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[6][0]))), quoteCoin.scalar, decimals);
1254
+ const basePythPrice = import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[7][0]));
1255
+ const basePythDecimals = Number(
1256
+ import_bcs.bcs.u8().parse(new Uint8Array(res.results[0].returnValues[8][0]))
1257
+ );
1258
+ const quotePythPrice = import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[9][0]));
1259
+ const quotePythDecimals = Number(
1260
+ import_bcs.bcs.u8().parse(new Uint8Array(res.results[0].returnValues[10][0]))
1261
+ );
1262
+ const currentPrice = BigInt(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[11][0])));
1263
+ const lowestTriggerAbovePrice = BigInt(
1264
+ import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[12][0]))
1265
+ );
1266
+ const highestTriggerBelowPrice = BigInt(
1267
+ import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[13][0]))
1268
+ );
1269
+ return {
1270
+ managerId,
1271
+ deepbookPoolId,
1272
+ riskRatio,
1273
+ baseAsset,
1274
+ quoteAsset,
1275
+ baseDebt,
1276
+ quoteDebt,
1277
+ basePythPrice: basePythPrice.toString(),
1278
+ basePythDecimals,
1279
+ quotePythPrice: quotePythPrice.toString(),
1280
+ quotePythDecimals,
1281
+ currentPrice,
1282
+ lowestTriggerAbovePrice,
1283
+ highestTriggerBelowPrice
1284
+ };
1285
+ }
1286
+ /**
1287
+ * @description Get the base asset balance of a margin manager
1288
+ * @param {string} marginManagerKey The key to identify the margin manager
1289
+ * @param {number} decimals Number of decimal places to show (default: 6)
1290
+ * @returns {Promise<string>} The base asset balance
1291
+ */
1292
+ async getMarginManagerBaseBalance(marginManagerKey, decimals = 9) {
1293
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1294
+ const tx = new import_transactions.Transaction();
1295
+ tx.add(this.marginManager.baseBalance(manager.poolKey, manager.address));
1296
+ const res = await this.client.devInspectTransactionBlock({
1297
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1298
+ transactionBlock: tx
1299
+ });
1300
+ if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1301
+ throw new Error(
1302
+ `Failed to get margin manager base balance: ${res.effects?.status?.error || "Unknown error"}`
1303
+ );
1304
+ }
1305
+ const bytes = res.results[0].returnValues[0][0];
1306
+ const pool = __privateGet(this, _config).getPool(manager.poolKey);
1307
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1308
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes))), baseCoin.scalar, decimals);
1309
+ }
1310
+ /**
1311
+ * @description Get the quote asset balance of a margin manager
1312
+ * @param {string} marginManagerKey The key to identify the margin manager
1313
+ * @param {number} decimals Number of decimal places to show (default: 6)
1314
+ * @returns {Promise<string>} The quote asset balance
1315
+ */
1316
+ async getMarginManagerQuoteBalance(marginManagerKey, decimals = 9) {
1317
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1318
+ const tx = new import_transactions.Transaction();
1319
+ tx.add(this.marginManager.quoteBalance(manager.poolKey, manager.address));
1320
+ const res = await this.client.devInspectTransactionBlock({
1321
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1322
+ transactionBlock: tx
1323
+ });
1324
+ if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1325
+ throw new Error(
1326
+ `Failed to get margin manager quote balance: ${res.effects?.status?.error || "Unknown error"}`
1327
+ );
1328
+ }
1329
+ const bytes = res.results[0].returnValues[0][0];
1330
+ const pool = __privateGet(this, _config).getPool(manager.poolKey);
1331
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1332
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes))), quoteCoin.scalar, decimals);
1333
+ }
1334
+ /**
1335
+ * @description Get the DEEP token balance of a margin manager
1336
+ * @param {string} marginManagerKey The key to identify the margin manager
1337
+ * @param {number} decimals Number of decimal places to show (default: 6)
1338
+ * @returns {Promise<string>} The DEEP token balance
1339
+ */
1340
+ async getMarginManagerDeepBalance(marginManagerKey, decimals = 6) {
1341
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1342
+ const tx = new import_transactions.Transaction();
1343
+ tx.add(this.marginManager.deepBalance(manager.poolKey, manager.address));
1344
+ const res = await this.client.devInspectTransactionBlock({
1345
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1346
+ transactionBlock: tx
1347
+ });
1348
+ if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1349
+ throw new Error(
1350
+ `Failed to get margin manager DEEP balance: ${res.effects?.status?.error || "Unknown error"}`
1351
+ );
1352
+ }
1353
+ const bytes = res.results[0].returnValues[0][0];
1354
+ const deepCoin = __privateGet(this, _config).getCoin("DEEP");
1355
+ return __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes))), deepCoin.scalar, decimals);
1356
+ }
1357
+ // === Margin TPSL (Take Profit / Stop Loss) Read-Only Functions ===
1358
+ /**
1359
+ * @description Get all conditional order IDs for a margin manager
1360
+ * @param {string} marginManagerKey The key to identify the margin manager
1361
+ * @returns {Promise<string[]>} Array of conditional order IDs
1362
+ */
1363
+ async getConditionalOrderIds(marginManagerKey) {
1364
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1365
+ const tx = new import_transactions.Transaction();
1366
+ tx.add(this.marginTPSL.conditionalOrderIds(manager.poolKey, manager.address));
1367
+ const res = await this.client.devInspectTransactionBlock({
1368
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1369
+ transactionBlock: tx
1370
+ });
1371
+ if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1372
+ throw new Error(
1373
+ `Failed to get conditional order IDs: ${res.effects?.status?.error || "Unknown error"}`
1374
+ );
1375
+ }
1376
+ const bytes = res.results[0].returnValues[0][0];
1377
+ const orderIds = import_bcs.bcs.vector(import_bcs.bcs.u64()).parse(new Uint8Array(bytes));
1378
+ return orderIds.map((id) => id.toString());
1379
+ }
1380
+ /**
1381
+ * @description Get the lowest trigger price for trigger_above orders
1382
+ * Returns MAX_U64 if there are no trigger_above orders
1383
+ * @param {string} marginManagerKey The key to identify the margin manager
1384
+ * @returns {Promise<bigint>} The lowest trigger above price
1385
+ */
1386
+ async getLowestTriggerAbovePrice(marginManagerKey) {
1387
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1388
+ const tx = new import_transactions.Transaction();
1389
+ tx.add(this.marginTPSL.lowestTriggerAbovePrice(manager.poolKey, manager.address));
1390
+ const res = await this.client.devInspectTransactionBlock({
1391
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1392
+ transactionBlock: tx
1393
+ });
1394
+ if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1395
+ throw new Error(
1396
+ `Failed to get lowest trigger above price: ${res.effects?.status?.error || "Unknown error"}`
1397
+ );
1398
+ }
1399
+ const bytes = res.results[0].returnValues[0][0];
1400
+ return BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1401
+ }
1402
+ /**
1403
+ * @description Get the highest trigger price for trigger_below orders
1404
+ * Returns 0 if there are no trigger_below orders
1405
+ * @param {string} marginManagerKey The key to identify the margin manager
1406
+ * @returns {Promise<bigint>} The highest trigger below price
1407
+ */
1408
+ async getHighestTriggerBelowPrice(marginManagerKey) {
1409
+ const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
1410
+ const tx = new import_transactions.Transaction();
1411
+ tx.add(this.marginTPSL.highestTriggerBelowPrice(manager.poolKey, manager.address));
1412
+ const res = await this.client.devInspectTransactionBlock({
1413
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1414
+ transactionBlock: tx
1415
+ });
1416
+ if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1417
+ throw new Error(
1418
+ `Failed to get highest trigger below price: ${res.effects?.status?.error || "Unknown error"}`
1419
+ );
1420
+ }
1421
+ const bytes = res.results[0].returnValues[0][0];
1422
+ return BigInt(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1423
+ }
1424
+ // === Margin Registry Functions ===
1425
+ /**
1426
+ * @description Check if a deepbook pool is enabled for margin trading
1427
+ * @param {string} poolKey The key to identify the pool
1428
+ * @returns {Promise<boolean>} True if the pool is enabled for margin trading
1429
+ */
1430
+ async isPoolEnabledForMargin(poolKey) {
1431
+ const tx = new import_transactions.Transaction();
1432
+ tx.add(this.marginRegistry.poolEnabled(poolKey));
1433
+ const res = await this.client.devInspectTransactionBlock({
1434
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1435
+ transactionBlock: tx
1436
+ });
1437
+ const bytes = res.results[0].returnValues[0][0];
1438
+ return import_bcs.bcs.Bool.parse(new Uint8Array(bytes));
1439
+ }
1440
+ /**
1441
+ * @description Get the margin manager IDs for a given owner address
1442
+ * @param {string} owner The owner address
1443
+ * @returns {Promise<string[]>} Array of margin manager IDs
1444
+ */
1445
+ async getMarginManagerIdsForOwner(owner) {
1446
+ const tx = new import_transactions.Transaction();
1447
+ tx.add(this.marginRegistry.getMarginManagerIds(owner));
1448
+ const res = await this.client.devInspectTransactionBlock({
1449
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1450
+ transactionBlock: tx
1451
+ });
1452
+ const bytes = res.results[0].returnValues[0][0];
1453
+ const vecSet = (0, import_bcs2.VecSet)(import_bcs.bcs.Address).parse(new Uint8Array(bytes));
1454
+ return vecSet.contents.map((id) => (0, import_utils.normalizeHaneulAddress)(id));
1455
+ }
1456
+ /**
1457
+ * @description Get the base margin pool ID for a deepbook pool
1458
+ * @param {string} poolKey The key to identify the pool
1459
+ * @returns {Promise<string>} The base margin pool ID
1460
+ */
1461
+ async getBaseMarginPoolId(poolKey) {
1462
+ const tx = new import_transactions.Transaction();
1463
+ tx.add(this.marginRegistry.baseMarginPoolId(poolKey));
1464
+ const res = await this.client.devInspectTransactionBlock({
1465
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1466
+ transactionBlock: tx
1467
+ });
1468
+ const bytes = res.results[0].returnValues[0][0];
1469
+ const id = import_bcs.bcs.Address.parse(new Uint8Array(bytes));
1470
+ return "0x" + id;
1471
+ }
1472
+ /**
1473
+ * @description Get the quote margin pool ID for a deepbook pool
1474
+ * @param {string} poolKey The key to identify the pool
1475
+ * @returns {Promise<string>} The quote margin pool ID
1476
+ */
1477
+ async getQuoteMarginPoolId(poolKey) {
1478
+ const tx = new import_transactions.Transaction();
1479
+ tx.add(this.marginRegistry.quoteMarginPoolId(poolKey));
1480
+ const res = await this.client.devInspectTransactionBlock({
1481
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1482
+ transactionBlock: tx
1483
+ });
1484
+ const bytes = res.results[0].returnValues[0][0];
1485
+ const id = import_bcs.bcs.Address.parse(new Uint8Array(bytes));
1486
+ return "0x" + id;
1487
+ }
1488
+ /**
1489
+ * @description Get the minimum withdraw risk ratio for a deepbook pool
1490
+ * @param {string} poolKey The key to identify the pool
1491
+ * @returns {Promise<number>} The minimum withdraw risk ratio as a decimal (e.g., 1.5 for 150%)
1492
+ */
1493
+ async getMinWithdrawRiskRatio(poolKey) {
1494
+ const tx = new import_transactions.Transaction();
1495
+ tx.add(this.marginRegistry.minWithdrawRiskRatio(poolKey));
1496
+ const res = await this.client.devInspectTransactionBlock({
1497
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1498
+ transactionBlock: tx
1499
+ });
1500
+ const bytes = res.results[0].returnValues[0][0];
1501
+ const ratio = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1502
+ return ratio / import_config.FLOAT_SCALAR;
1503
+ }
1504
+ /**
1505
+ * @description Get the minimum borrow risk ratio for a deepbook pool
1506
+ * @param {string} poolKey The key to identify the pool
1507
+ * @returns {Promise<number>} The minimum borrow risk ratio as a decimal (e.g., 1.25 for 125%)
1508
+ */
1509
+ async getMinBorrowRiskRatio(poolKey) {
1510
+ const tx = new import_transactions.Transaction();
1511
+ tx.add(this.marginRegistry.minBorrowRiskRatio(poolKey));
1512
+ const res = await this.client.devInspectTransactionBlock({
1513
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1514
+ transactionBlock: tx
1515
+ });
1516
+ const bytes = res.results[0].returnValues[0][0];
1517
+ const ratio = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1518
+ return ratio / import_config.FLOAT_SCALAR;
1519
+ }
1520
+ /**
1521
+ * @description Get the liquidation risk ratio for a deepbook pool
1522
+ * @param {string} poolKey The key to identify the pool
1523
+ * @returns {Promise<number>} The liquidation risk ratio as a decimal (e.g., 1.125 for 112.5%)
1524
+ */
1525
+ async getLiquidationRiskRatio(poolKey) {
1526
+ const tx = new import_transactions.Transaction();
1527
+ tx.add(this.marginRegistry.liquidationRiskRatio(poolKey));
1528
+ const res = await this.client.devInspectTransactionBlock({
1529
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1530
+ transactionBlock: tx
1531
+ });
1532
+ const bytes = res.results[0].returnValues[0][0];
1533
+ const ratio = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1534
+ return ratio / import_config.FLOAT_SCALAR;
1535
+ }
1536
+ /**
1537
+ * @description Get the target liquidation risk ratio for a deepbook pool
1538
+ * @param {string} poolKey The key to identify the pool
1539
+ * @returns {Promise<number>} The target liquidation risk ratio as a decimal (e.g., 1.25 for 125%)
1540
+ */
1541
+ async getTargetLiquidationRiskRatio(poolKey) {
1542
+ const tx = new import_transactions.Transaction();
1543
+ tx.add(this.marginRegistry.targetLiquidationRiskRatio(poolKey));
1544
+ const res = await this.client.devInspectTransactionBlock({
1545
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1546
+ transactionBlock: tx
1547
+ });
1548
+ const bytes = res.results[0].returnValues[0][0];
1549
+ const ratio = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1550
+ return ratio / import_config.FLOAT_SCALAR;
1551
+ }
1552
+ /**
1553
+ * @description Get the user liquidation reward for a deepbook pool
1554
+ * @param {string} poolKey The key to identify the pool
1555
+ * @returns {Promise<number>} The user liquidation reward as a decimal (e.g., 0.05 for 5%)
1556
+ */
1557
+ async getUserLiquidationReward(poolKey) {
1558
+ const tx = new import_transactions.Transaction();
1559
+ tx.add(this.marginRegistry.userLiquidationReward(poolKey));
1560
+ const res = await this.client.devInspectTransactionBlock({
1561
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1562
+ transactionBlock: tx
1563
+ });
1564
+ const bytes = res.results[0].returnValues[0][0];
1565
+ const reward = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1566
+ return reward / import_config.FLOAT_SCALAR;
1567
+ }
1568
+ /**
1569
+ * @description Get the pool liquidation reward for a deepbook pool
1570
+ * @param {string} poolKey The key to identify the pool
1571
+ * @returns {Promise<number>} The pool liquidation reward as a decimal (e.g., 0.05 for 5%)
1572
+ */
1573
+ async getPoolLiquidationReward(poolKey) {
1574
+ const tx = new import_transactions.Transaction();
1575
+ tx.add(this.marginRegistry.poolLiquidationReward(poolKey));
1576
+ const res = await this.client.devInspectTransactionBlock({
1577
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1578
+ transactionBlock: tx
1579
+ });
1580
+ const bytes = res.results[0].returnValues[0][0];
1581
+ const reward = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1582
+ return reward / import_config.FLOAT_SCALAR;
1583
+ }
1584
+ /**
1585
+ * @description Get all allowed maintainer cap IDs
1586
+ * @returns {Promise<string[]>} Array of allowed maintainer cap IDs
1587
+ */
1588
+ async getAllowedMaintainers() {
1589
+ const tx = new import_transactions.Transaction();
1590
+ tx.add(this.marginRegistry.allowedMaintainers());
1591
+ const res = await this.client.devInspectTransactionBlock({
1592
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1593
+ transactionBlock: tx
1594
+ });
1595
+ const bytes = res.results[0].returnValues[0][0];
1596
+ const vecSet = (0, import_bcs2.VecSet)(import_bcs.bcs.Address).parse(new Uint8Array(bytes));
1597
+ return vecSet.contents.map((id) => (0, import_utils.normalizeHaneulAddress)(id));
1598
+ }
1599
+ /**
1600
+ * @description Get all allowed pause cap IDs
1601
+ * @returns {Promise<string[]>} Array of allowed pause cap IDs
1602
+ */
1603
+ async getAllowedPauseCaps() {
1604
+ const tx = new import_transactions.Transaction();
1605
+ tx.add(this.marginRegistry.allowedPauseCaps());
1606
+ const res = await this.client.devInspectTransactionBlock({
1607
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1608
+ transactionBlock: tx
1609
+ });
1610
+ const bytes = res.results[0].returnValues[0][0];
1611
+ const vecSet = (0, import_bcs2.VecSet)(import_bcs.bcs.Address).parse(new Uint8Array(bytes));
1612
+ return vecSet.contents.map((id) => (0, import_utils.normalizeHaneulAddress)(id));
1613
+ }
1614
+ /**
1615
+ * @description Check if a pool is a stable pool
1616
+ * @param {string} poolKey Key of the pool
1617
+ * @returns {Promise<boolean>} Whether the pool is a stable pool
1618
+ */
1619
+ async stablePool(poolKey) {
1620
+ const tx = new import_transactions.Transaction();
1621
+ tx.add(this.deepBook.stablePool(poolKey));
1622
+ const res = await this.client.devInspectTransactionBlock({
1623
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1624
+ transactionBlock: tx
1625
+ });
1626
+ const bytes = res.results[0].returnValues[0][0];
1627
+ return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
1628
+ }
1629
+ /**
1630
+ * @description Check if a pool is registered
1631
+ * @param {string} poolKey Key of the pool
1632
+ * @returns {Promise<boolean>} Whether the pool is registered
1633
+ */
1634
+ async registeredPool(poolKey) {
1635
+ const tx = new import_transactions.Transaction();
1636
+ tx.add(this.deepBook.registeredPool(poolKey));
1637
+ const res = await this.client.devInspectTransactionBlock({
1638
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1639
+ transactionBlock: tx
1640
+ });
1641
+ const bytes = res.results[0].returnValues[0][0];
1642
+ return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
1643
+ }
1644
+ /**
1645
+ * @description Get the quote quantity out using input token as fee
1646
+ * @param {string} poolKey Key of the pool
1647
+ * @param {number} baseQuantity Base quantity
1648
+ * @returns {Promise<{baseQuantity: number, baseOut: number, quoteOut: number, deepRequired: number}>}
1649
+ */
1650
+ async getQuoteQuantityOutInputFee(poolKey, baseQuantity) {
1651
+ const tx = new import_transactions.Transaction();
1652
+ const pool = __privateGet(this, _config).getPool(poolKey);
1653
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
1654
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
1655
+ tx.add(this.deepBook.getQuoteQuantityOutInputFee(poolKey, baseQuantity));
1656
+ const res = await this.client.devInspectTransactionBlock({
1657
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1658
+ transactionBlock: tx
1659
+ });
1660
+ const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
1661
+ const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
1662
+ const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
1663
+ return {
1664
+ baseQuantity,
1665
+ baseOut: Number((baseOut / baseScalar).toFixed(9)),
1666
+ quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
1667
+ deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
1668
+ };
1669
+ }
1670
+ /**
1671
+ * @description Get the base quantity out using input token as fee
1672
+ * @param {string} poolKey Key of the pool
1673
+ * @param {number} quoteQuantity Quote quantity
1674
+ * @returns {Promise<{quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number}>}
1675
+ */
1676
+ async getBaseQuantityOutInputFee(poolKey, quoteQuantity) {
1677
+ const tx = new import_transactions.Transaction();
1678
+ const pool = __privateGet(this, _config).getPool(poolKey);
1679
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
1680
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
1681
+ tx.add(this.deepBook.getBaseQuantityOutInputFee(poolKey, quoteQuantity));
1682
+ const res = await this.client.devInspectTransactionBlock({
1683
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1684
+ transactionBlock: tx
1685
+ });
1686
+ const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
1687
+ const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
1688
+ const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
1689
+ return {
1690
+ quoteQuantity,
1691
+ baseOut: Number((baseOut / baseScalar).toFixed(9)),
1692
+ quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
1693
+ deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
1694
+ };
1695
+ }
1696
+ /**
1697
+ * @description Get the quantity out using input token as fee
1698
+ * @param {string} poolKey Key of the pool
1699
+ * @param {number} baseQuantity Base quantity
1700
+ * @param {number} quoteQuantity Quote quantity
1701
+ * @returns {Promise<{baseQuantity: number, quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number}>}
1702
+ */
1703
+ async getQuantityOutInputFee(poolKey, baseQuantity, quoteQuantity) {
1704
+ const tx = new import_transactions.Transaction();
1705
+ const pool = __privateGet(this, _config).getPool(poolKey);
1706
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
1707
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
1708
+ tx.add(this.deepBook.getQuantityOutInputFee(poolKey, baseQuantity, quoteQuantity));
1709
+ const res = await this.client.devInspectTransactionBlock({
1710
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1711
+ transactionBlock: tx
1712
+ });
1713
+ const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
1714
+ const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
1715
+ const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
1716
+ return {
1717
+ baseQuantity,
1718
+ quoteQuantity,
1719
+ baseOut: Number((baseOut / baseScalar).toFixed(9)),
1720
+ quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
1721
+ deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
1722
+ };
1723
+ }
1724
+ /**
1725
+ * @description Get the base quantity needed to receive target quote quantity
1726
+ * @param {string} poolKey Key of the pool
1727
+ * @param {number} targetQuoteQuantity Target quote quantity
1728
+ * @param {boolean} payWithDeep Whether to pay fees with DEEP
1729
+ * @returns {Promise<{baseIn: number, quoteOut: number, deepRequired: number}>}
1730
+ */
1731
+ async getBaseQuantityIn(poolKey, targetQuoteQuantity, payWithDeep) {
1732
+ const tx = new import_transactions.Transaction();
1733
+ const pool = __privateGet(this, _config).getPool(poolKey);
1734
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
1735
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
1736
+ tx.add(this.deepBook.getBaseQuantityIn(poolKey, targetQuoteQuantity, payWithDeep));
1737
+ const res = await this.client.devInspectTransactionBlock({
1738
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1739
+ transactionBlock: tx
1740
+ });
1741
+ const baseIn = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
1742
+ const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
1743
+ const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
1744
+ return {
1745
+ baseIn: Number((baseIn / baseScalar).toFixed(9)),
1746
+ quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
1747
+ deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
1748
+ };
1749
+ }
1750
+ /**
1751
+ * @description Get the quote quantity needed to receive target base quantity
1752
+ * @param {string} poolKey Key of the pool
1753
+ * @param {number} targetBaseQuantity Target base quantity
1754
+ * @param {boolean} payWithDeep Whether to pay fees with DEEP
1755
+ * @returns {Promise<{baseOut: number, quoteIn: number, deepRequired: number}>}
1756
+ */
1757
+ async getQuoteQuantityIn(poolKey, targetBaseQuantity, payWithDeep) {
1758
+ const tx = new import_transactions.Transaction();
1759
+ const pool = __privateGet(this, _config).getPool(poolKey);
1760
+ const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
1761
+ const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
1762
+ tx.add(this.deepBook.getQuoteQuantityIn(poolKey, targetBaseQuantity, payWithDeep));
1763
+ const res = await this.client.devInspectTransactionBlock({
1764
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1765
+ transactionBlock: tx
1766
+ });
1767
+ const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
1768
+ const quoteIn = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
1769
+ const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
1770
+ return {
1771
+ baseOut: Number((baseOut / baseScalar).toFixed(9)),
1772
+ quoteIn: Number((quoteIn / quoteScalar).toFixed(9)),
1773
+ deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
1774
+ };
1775
+ }
1776
+ /**
1777
+ * @description Get account order details for a balance manager
1778
+ * @param {string} poolKey Key of the pool
1779
+ * @param {string} managerKey Key of the balance manager
1780
+ * @returns {Promise<Array>} Array of order details
1781
+ */
1782
+ async getAccountOrderDetails(poolKey, managerKey) {
1783
+ const tx = new import_transactions.Transaction();
1784
+ tx.add(this.deepBook.getAccountOrderDetails(poolKey, managerKey));
1785
+ const res = await this.client.devInspectTransactionBlock({
1786
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1787
+ transactionBlock: tx
1788
+ });
1789
+ try {
1790
+ const orderInformation = res.results[0].returnValues[0][0];
1791
+ return import_bcs.bcs.vector(import_bcs2.Order).parse(new Uint8Array(orderInformation));
1792
+ } catch {
1793
+ return [];
1794
+ }
1795
+ }
1796
+ /**
1797
+ * @description Get the DEEP required for an order
1798
+ * @param {string} poolKey Key of the pool
1799
+ * @param {number} baseQuantity Base quantity
1800
+ * @param {number} price Price
1801
+ * @returns {Promise<{deepRequiredTaker: number, deepRequiredMaker: number}>}
1802
+ */
1803
+ async getOrderDeepRequired(poolKey, baseQuantity, price) {
1804
+ const tx = new import_transactions.Transaction();
1805
+ tx.add(this.deepBook.getOrderDeepRequired(poolKey, baseQuantity, price));
1806
+ const res = await this.client.devInspectTransactionBlock({
1807
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1808
+ transactionBlock: tx
1809
+ });
1810
+ const deepRequiredTaker = Number(
1811
+ import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0]))
1812
+ );
1813
+ const deepRequiredMaker = Number(
1814
+ import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0]))
1815
+ );
1816
+ return {
1817
+ deepRequiredTaker: Number((deepRequiredTaker / import_config.DEEP_SCALAR).toFixed(9)),
1818
+ deepRequiredMaker: Number((deepRequiredMaker / import_config.DEEP_SCALAR).toFixed(9))
1819
+ };
1820
+ }
1821
+ /**
1822
+ * @description Check if account exists for a balance manager
1823
+ * @param {string} poolKey Key of the pool
1824
+ * @param {string} managerKey Key of the balance manager
1825
+ * @returns {Promise<boolean>} Whether account exists
1826
+ */
1827
+ async accountExists(poolKey, managerKey) {
1828
+ const tx = new import_transactions.Transaction();
1829
+ tx.add(this.deepBook.accountExists(poolKey, managerKey));
1830
+ const res = await this.client.devInspectTransactionBlock({
1831
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1832
+ transactionBlock: tx
1833
+ });
1834
+ const bytes = res.results[0].returnValues[0][0];
1835
+ return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
1836
+ }
1837
+ /**
1838
+ * @description Get the next epoch trade parameters
1839
+ * @param {string} poolKey Key of the pool
1840
+ * @returns {Promise<{takerFee: number, makerFee: number, stakeRequired: number}>}
1841
+ */
1842
+ async poolTradeParamsNext(poolKey) {
1843
+ const tx = new import_transactions.Transaction();
1844
+ tx.add(this.deepBook.poolTradeParamsNext(poolKey));
1845
+ const res = await this.client.devInspectTransactionBlock({
1846
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1847
+ transactionBlock: tx
1848
+ });
1849
+ const takerFee = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
1850
+ const makerFee = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
1851
+ const stakeRequired = Number(
1852
+ import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0]))
1853
+ );
1854
+ return {
1855
+ takerFee: takerFee / import_config.FLOAT_SCALAR,
1856
+ makerFee: makerFee / import_config.FLOAT_SCALAR,
1857
+ stakeRequired: stakeRequired / import_config.DEEP_SCALAR
1858
+ };
1859
+ }
1860
+ /**
1861
+ * @description Get the quorum for a pool
1862
+ * @param {string} poolKey Key of the pool
1863
+ * @returns {Promise<number>} The quorum amount in DEEP
1864
+ */
1865
+ async quorum(poolKey) {
1866
+ const tx = new import_transactions.Transaction();
1867
+ tx.add(this.deepBook.quorum(poolKey));
1868
+ const res = await this.client.devInspectTransactionBlock({
1869
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1870
+ transactionBlock: tx
1871
+ });
1872
+ const bytes = res.results[0].returnValues[0][0];
1873
+ const quorum = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
1874
+ return quorum / import_config.DEEP_SCALAR;
1875
+ }
1876
+ /**
1877
+ * @description Get the pool ID
1878
+ * @param {string} poolKey Key of the pool
1879
+ * @returns {Promise<string>} The pool ID
1880
+ */
1881
+ async poolId(poolKey) {
1882
+ const tx = new import_transactions.Transaction();
1883
+ tx.add(this.deepBook.poolId(poolKey));
1884
+ const res = await this.client.devInspectTransactionBlock({
1885
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1886
+ transactionBlock: tx
1887
+ });
1888
+ const bytes = res.results[0].returnValues[0][0];
1889
+ return (0, import_utils.normalizeHaneulAddress)(import_bcs.bcs.Address.parse(new Uint8Array(bytes)));
1890
+ }
1891
+ /**
1892
+ * @description Check if a limit order can be placed
1893
+ * @param {CanPlaceLimitOrderParams} params Parameters for checking limit order placement
1894
+ * @returns {Promise<boolean>} Whether order can be placed
1895
+ */
1896
+ async canPlaceLimitOrder(params) {
1897
+ const tx = new import_transactions.Transaction();
1898
+ tx.add(this.deepBook.canPlaceLimitOrder(params));
1899
+ const res = await this.client.devInspectTransactionBlock({
1900
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1901
+ transactionBlock: tx
1902
+ });
1903
+ const bytes = res.results[0].returnValues[0][0];
1904
+ return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
1905
+ }
1906
+ /**
1907
+ * @description Check if a market order can be placed
1908
+ * @param {CanPlaceMarketOrderParams} params Parameters for checking market order placement
1909
+ * @returns {Promise<boolean>} Whether order can be placed
1910
+ */
1911
+ async canPlaceMarketOrder(params) {
1912
+ const tx = new import_transactions.Transaction();
1913
+ tx.add(this.deepBook.canPlaceMarketOrder(params));
1914
+ const res = await this.client.devInspectTransactionBlock({
1915
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1916
+ transactionBlock: tx
1917
+ });
1918
+ const bytes = res.results[0].returnValues[0][0];
1919
+ return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
1920
+ }
1921
+ /**
1922
+ * @description Check if market order params are valid
1923
+ * @param {string} poolKey Key of the pool
1924
+ * @param {number} quantity Quantity
1925
+ * @returns {Promise<boolean>} Whether params are valid
1926
+ */
1927
+ async checkMarketOrderParams(poolKey, quantity) {
1928
+ const tx = new import_transactions.Transaction();
1929
+ tx.add(this.deepBook.checkMarketOrderParams(poolKey, quantity));
1930
+ const res = await this.client.devInspectTransactionBlock({
1931
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1932
+ transactionBlock: tx
1933
+ });
1934
+ const bytes = res.results[0].returnValues[0][0];
1935
+ return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
1936
+ }
1937
+ /**
1938
+ * @description Check if limit order params are valid
1939
+ * @param {string} poolKey Key of the pool
1940
+ * @param {number} price Price
1941
+ * @param {number} quantity Quantity
1942
+ * @param {number} expireTimestamp Expiration timestamp
1943
+ * @returns {Promise<boolean>} Whether params are valid
1944
+ */
1945
+ async checkLimitOrderParams(poolKey, price, quantity, expireTimestamp) {
1946
+ const tx = new import_transactions.Transaction();
1947
+ tx.add(this.deepBook.checkLimitOrderParams(poolKey, price, quantity, expireTimestamp));
1948
+ const res = await this.client.devInspectTransactionBlock({
1949
+ sender: (0, import_utils.normalizeHaneulAddress)(__privateGet(this, _address)),
1950
+ transactionBlock: tx
1951
+ });
1952
+ const bytes = res.results[0].returnValues[0][0];
1953
+ return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
1954
+ }
1955
+ }
1956
+ _config = new WeakMap();
1957
+ _address = new WeakMap();
1958
+ _DeepBookClient_instances = new WeakSet();
1959
+ /**
1960
+ * @description Helper function to format token amounts without floating point errors
1961
+ * @param {bigint} rawAmount The raw amount as bigint
1962
+ * @param {number} scalar The token scalar (e.g., 1000000000 for 9 decimals)
1963
+ * @param {number} decimals Number of decimal places to show
1964
+ * @returns {string} Formatted amount as string
1965
+ */
1966
+ formatTokenAmount_fn = function(rawAmount, scalar, decimals) {
1967
+ const scalarBigInt = BigInt(scalar);
1968
+ const integerPart = rawAmount / scalarBigInt;
1969
+ const fractionalPart = rawAmount % scalarBigInt;
1970
+ if (fractionalPart === 0n) {
1971
+ return integerPart.toString();
1972
+ }
1973
+ const scalarDigits = scalar.toString().length - 1;
1974
+ const fractionalStr = fractionalPart.toString().padStart(scalarDigits, "0");
1975
+ const truncated = fractionalStr.slice(0, decimals);
1976
+ const trimmed = truncated.replace(/0+$/, "");
1977
+ if (!trimmed) {
1978
+ return integerPart.toString();
1979
+ }
1980
+ return `${integerPart}.${trimmed}`;
1981
+ };
1982
+ //# sourceMappingURL=client.js.map