@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,1335 @@
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 deepbook_exports = {};
27
+ __export(deepbook_exports, {
28
+ DeepBookContract: () => DeepBookContract
29
+ });
30
+ module.exports = __toCommonJS(deepbook_exports);
31
+ var import_transactions = require("@haneullabs/haneul/transactions");
32
+ var import_types = require("../types/index.js");
33
+ var import_config = require("../utils/config.js");
34
+ var _config;
35
+ class DeepBookContract {
36
+ /**
37
+ * @param {DeepBookConfig} config Configuration for DeepBookContract
38
+ */
39
+ constructor(config) {
40
+ __privateAdd(this, _config);
41
+ /**
42
+ * @description Place a limit order
43
+ * @param {PlaceLimitOrderParams} params Parameters for placing a limit order
44
+ * @returns A function that takes a Transaction object
45
+ */
46
+ this.placeLimitOrder = (params) => (tx) => {
47
+ const {
48
+ poolKey,
49
+ balanceManagerKey,
50
+ clientOrderId,
51
+ price,
52
+ quantity,
53
+ isBid,
54
+ expiration = import_config.MAX_TIMESTAMP,
55
+ orderType = import_types.OrderType.NO_RESTRICTION,
56
+ selfMatchingOption = import_types.SelfMatchingOptions.SELF_MATCHING_ALLOWED,
57
+ payWithDeep = true
58
+ } = params;
59
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
60
+ const pool = __privateGet(this, _config).getPool(poolKey);
61
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
62
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
63
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
64
+ const inputPrice = Math.round(price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
65
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
66
+ const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
67
+ tx.moveCall({
68
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::place_limit_order`,
69
+ arguments: [
70
+ tx.object(pool.address),
71
+ tx.object(balanceManager.address),
72
+ tradeProof,
73
+ tx.pure.u64(clientOrderId),
74
+ tx.pure.u8(orderType),
75
+ tx.pure.u8(selfMatchingOption),
76
+ tx.pure.u64(inputPrice),
77
+ tx.pure.u64(inputQuantity),
78
+ tx.pure.bool(isBid),
79
+ tx.pure.bool(payWithDeep),
80
+ tx.pure.u64(expiration),
81
+ tx.object.clock()
82
+ ],
83
+ typeArguments: [baseCoin.type, quoteCoin.type]
84
+ });
85
+ };
86
+ /**
87
+ * @description Place a market order
88
+ * @param {PlaceMarketOrderParams} params Parameters for placing a market order
89
+ * @returns A function that takes a Transaction object
90
+ */
91
+ this.placeMarketOrder = (params) => (tx) => {
92
+ const {
93
+ poolKey,
94
+ balanceManagerKey,
95
+ clientOrderId,
96
+ quantity,
97
+ isBid,
98
+ selfMatchingOption = import_types.SelfMatchingOptions.SELF_MATCHING_ALLOWED,
99
+ payWithDeep = true
100
+ } = params;
101
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
102
+ const pool = __privateGet(this, _config).getPool(poolKey);
103
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
104
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
105
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
106
+ const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
107
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
108
+ tx.moveCall({
109
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::place_market_order`,
110
+ arguments: [
111
+ tx.object(pool.address),
112
+ tx.object(balanceManager.address),
113
+ tradeProof,
114
+ tx.pure.u64(clientOrderId),
115
+ tx.pure.u8(selfMatchingOption),
116
+ tx.pure.u64(inputQuantity),
117
+ tx.pure.bool(isBid),
118
+ tx.pure.bool(payWithDeep),
119
+ tx.object.clock()
120
+ ],
121
+ typeArguments: [baseCoin.type, quoteCoin.type]
122
+ });
123
+ };
124
+ /**
125
+ * @description Modify an existing order
126
+ * @param {string} poolKey The key to identify the pool
127
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
128
+ * @param {string} orderId Order ID to modify
129
+ * @param {number} newQuantity New quantity for the order
130
+ * @returns A function that takes a Transaction object
131
+ */
132
+ this.modifyOrder = (poolKey, balanceManagerKey, orderId, newQuantity) => (tx) => {
133
+ const pool = __privateGet(this, _config).getPool(poolKey);
134
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
135
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
136
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
137
+ const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
138
+ const inputQuantity = Math.round(newQuantity * baseCoin.scalar);
139
+ tx.moveCall({
140
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::modify_order`,
141
+ arguments: [
142
+ tx.object(pool.address),
143
+ tx.object(balanceManager.address),
144
+ tradeProof,
145
+ tx.pure.u128(orderId),
146
+ tx.pure.u64(inputQuantity),
147
+ tx.object.clock()
148
+ ],
149
+ typeArguments: [baseCoin.type, quoteCoin.type]
150
+ });
151
+ };
152
+ /**
153
+ * @description Cancel an existing order
154
+ * @param {string} poolKey The key to identify the pool
155
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
156
+ * @param {string} orderId Order ID to cancel
157
+ * @returns A function that takes a Transaction object
158
+ */
159
+ this.cancelOrder = (poolKey, balanceManagerKey, orderId) => (tx) => {
160
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
161
+ const pool = __privateGet(this, _config).getPool(poolKey);
162
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
163
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
164
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
165
+ const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
166
+ tx.moveCall({
167
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::cancel_order`,
168
+ arguments: [
169
+ tx.object(pool.address),
170
+ tx.object(balanceManager.address),
171
+ tradeProof,
172
+ tx.pure.u128(orderId),
173
+ tx.object.clock()
174
+ ],
175
+ typeArguments: [baseCoin.type, quoteCoin.type]
176
+ });
177
+ };
178
+ /**
179
+ * @description Cancel multiple orders
180
+ * @param {string} poolKey The key to identify the pool
181
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
182
+ * @param {string[]} orderIds Array of order IDs to cancel
183
+ * @returns A function that takes a Transaction object
184
+ */
185
+ this.cancelOrders = (poolKey, balanceManagerKey, orderIds) => (tx) => {
186
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
187
+ const pool = __privateGet(this, _config).getPool(poolKey);
188
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
189
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
190
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
191
+ const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
192
+ tx.moveCall({
193
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::cancel_orders`,
194
+ arguments: [
195
+ tx.object(pool.address),
196
+ tx.object(balanceManager.address),
197
+ tradeProof,
198
+ tx.pure.vector("u128", orderIds),
199
+ tx.object.clock()
200
+ ],
201
+ typeArguments: [baseCoin.type, quoteCoin.type]
202
+ });
203
+ };
204
+ /**
205
+ * @description Cancel all open orders for a balance manager
206
+ * @param {string} poolKey The key to identify the pool
207
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
208
+ * @returns A function that takes a Transaction object
209
+ */
210
+ this.cancelAllOrders = (poolKey, balanceManagerKey) => (tx) => {
211
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
212
+ const pool = __privateGet(this, _config).getPool(poolKey);
213
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
214
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
215
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
216
+ const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
217
+ tx.moveCall({
218
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::cancel_all_orders`,
219
+ arguments: [
220
+ tx.object(pool.address),
221
+ tx.object(balanceManager.address),
222
+ tradeProof,
223
+ tx.object.clock()
224
+ ],
225
+ typeArguments: [baseCoin.type, quoteCoin.type]
226
+ });
227
+ };
228
+ /**
229
+ * @description Withdraw settled amounts for a balance manager
230
+ * @param {string} poolKey The key to identify the pool
231
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
232
+ * @returns A function that takes a Transaction object
233
+ */
234
+ this.withdrawSettledAmounts = (poolKey, balanceManagerKey) => (tx) => {
235
+ const pool = __privateGet(this, _config).getPool(poolKey);
236
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
237
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
238
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
239
+ const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
240
+ tx.moveCall({
241
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::withdraw_settled_amounts`,
242
+ arguments: [tx.object(pool.address), tx.object(balanceManager.address), tradeProof],
243
+ typeArguments: [baseCoin.type, quoteCoin.type]
244
+ });
245
+ };
246
+ /**
247
+ * @description Withdraw settled amounts permissionlessly for a balance manager
248
+ * @param {string} poolKey The key to identify the pool
249
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
250
+ * @returns A function that takes a Transaction object
251
+ */
252
+ this.withdrawSettledAmountsPermissionless = (poolKey, balanceManagerKey) => (tx) => {
253
+ const pool = __privateGet(this, _config).getPool(poolKey);
254
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
255
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
256
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
257
+ tx.moveCall({
258
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::withdraw_settled_amounts_permissionless`,
259
+ arguments: [tx.object(pool.address), tx.object(balanceManager.address)],
260
+ typeArguments: [baseCoin.type, quoteCoin.type]
261
+ });
262
+ };
263
+ /**
264
+ * @description Add a deep price point for a target pool using a reference pool
265
+ * @param {string} targetPoolKey The key to identify the target pool
266
+ * @param {string} referencePoolKey The key to identify the reference pool
267
+ * @returns A function that takes a Transaction object
268
+ */
269
+ this.addDeepPricePoint = (targetPoolKey, referencePoolKey) => (tx) => {
270
+ const targetPool = __privateGet(this, _config).getPool(targetPoolKey);
271
+ const referencePool = __privateGet(this, _config).getPool(referencePoolKey);
272
+ const targetBaseCoin = __privateGet(this, _config).getCoin(targetPool.baseCoin);
273
+ const targetQuoteCoin = __privateGet(this, _config).getCoin(targetPool.quoteCoin);
274
+ const referenceBaseCoin = __privateGet(this, _config).getCoin(referencePool.baseCoin);
275
+ const referenceQuoteCoin = __privateGet(this, _config).getCoin(referencePool.quoteCoin);
276
+ tx.moveCall({
277
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::add_deep_price_point`,
278
+ arguments: [
279
+ tx.object(targetPool.address),
280
+ tx.object(referencePool.address),
281
+ tx.object.clock()
282
+ ],
283
+ typeArguments: [
284
+ targetBaseCoin.type,
285
+ targetQuoteCoin.type,
286
+ referenceBaseCoin.type,
287
+ referenceQuoteCoin.type
288
+ ]
289
+ });
290
+ };
291
+ /**
292
+ * @description Claim rebates for a balance manager
293
+ * @param {string} poolKey The key to identify the pool
294
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
295
+ * @returns A function that takes a Transaction object
296
+ */
297
+ this.claimRebates = (poolKey, balanceManagerKey) => (tx) => {
298
+ const pool = __privateGet(this, _config).getPool(poolKey);
299
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
300
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
301
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
302
+ const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
303
+ tx.moveCall({
304
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::claim_rebates`,
305
+ arguments: [tx.object(pool.address), tx.object(balanceManager.address), tradeProof],
306
+ typeArguments: [baseCoin.type, quoteCoin.type]
307
+ });
308
+ };
309
+ /**
310
+ * @description Mint a referral for a pool
311
+ * @param {string} poolKey The key to identify the pool
312
+ * @param {number} multiplier The multiplier for the referral
313
+ * @returns A function that takes a Transaction object
314
+ */
315
+ this.mintReferral = (poolKey, multiplier) => (tx) => {
316
+ const pool = __privateGet(this, _config).getPool(poolKey);
317
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
318
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
319
+ const adjustedNumber = Math.round(multiplier * import_config.FLOAT_SCALAR);
320
+ tx.moveCall({
321
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::mint_referral`,
322
+ arguments: [tx.object(pool.address), tx.pure.u64(adjustedNumber)],
323
+ typeArguments: [baseCoin.type, quoteCoin.type]
324
+ });
325
+ };
326
+ /**
327
+ * @description Update the referral multiplier for a pool (DeepBookPoolReferral)
328
+ * @param {string} poolKey The key to identify the pool
329
+ * @param {string} referral The referral (DeepBookPoolReferral) to update
330
+ * @param {number} multiplier The multiplier for the referral
331
+ * @returns A function that takes a Transaction object
332
+ */
333
+ this.updatePoolReferralMultiplier = (poolKey, referral, multiplier) => (tx) => {
334
+ const pool = __privateGet(this, _config).getPool(poolKey);
335
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
336
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
337
+ const adjustedNumber = Math.round(multiplier * import_config.FLOAT_SCALAR);
338
+ tx.moveCall({
339
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::update_pool_referral_multiplier`,
340
+ arguments: [tx.object(pool.address), tx.object(referral), tx.pure.u64(adjustedNumber)],
341
+ typeArguments: [baseCoin.type, quoteCoin.type]
342
+ });
343
+ };
344
+ /**
345
+ * @description Claim the rewards for a referral (DeepBookPoolReferral)
346
+ * @param {string} poolKey The key to identify the pool
347
+ * @param {string} referral The referral (DeepBookPoolReferral) to claim the rewards for
348
+ * @returns A function that takes a Transaction object
349
+ */
350
+ this.claimPoolReferralRewards = (poolKey, referral) => (tx) => {
351
+ const pool = __privateGet(this, _config).getPool(poolKey);
352
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
353
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
354
+ const [baseRewards, quoteRewards, deepRewards] = tx.moveCall({
355
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::claim_pool_referral_rewards`,
356
+ arguments: [tx.object(pool.address), tx.object(referral)],
357
+ typeArguments: [baseCoin.type, quoteCoin.type]
358
+ });
359
+ return { baseRewards, quoteRewards, deepRewards };
360
+ };
361
+ /**
362
+ * @description Update the allowed versions for a pool
363
+ * @param {string} poolKey The key of the pool to be updated
364
+ * @returns A function that takes a Transaction object
365
+ */
366
+ this.updatePoolAllowedVersions = (poolKey) => (tx) => {
367
+ const pool = __privateGet(this, _config).getPool(poolKey);
368
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
369
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
370
+ tx.moveCall({
371
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::update_pool_allowed_versions`,
372
+ arguments: [tx.object(pool.address), tx.object(__privateGet(this, _config).REGISTRY_ID)],
373
+ typeArguments: [baseCoin.type, quoteCoin.type]
374
+ });
375
+ };
376
+ /**
377
+ * @description Gets an order
378
+ * @param {string} poolKey The key to identify the pool
379
+ * @param {string} orderId Order ID to get
380
+ * @returns A function that takes a Transaction object
381
+ */
382
+ this.getOrder = (poolKey, orderId) => (tx) => {
383
+ const pool = __privateGet(this, _config).getPool(poolKey);
384
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
385
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
386
+ tx.moveCall({
387
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_order`,
388
+ arguments: [tx.object(pool.address), tx.pure.u128(orderId)],
389
+ typeArguments: [baseCoin.type, quoteCoin.type]
390
+ });
391
+ };
392
+ /**
393
+ * @description Prepares a transaction to retrieve multiple orders from a specified pool.
394
+ * @param {string} poolKey - The identifier key for the pool to retrieve orders from.
395
+ * @param {string[]} orderIds - Array of order IDs to retrieve.
396
+ * @returns {Function} A function that takes a Transaction object
397
+ */
398
+ this.getOrders = (poolKey, orderIds) => (tx) => {
399
+ const pool = __privateGet(this, _config).getPool(poolKey);
400
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
401
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
402
+ tx.moveCall({
403
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_orders`,
404
+ arguments: [tx.object(pool.address), tx.pure.vector("u128", orderIds)],
405
+ typeArguments: [baseCoin.type, quoteCoin.type]
406
+ });
407
+ };
408
+ /**
409
+ * @description Burn DEEP tokens from the pool
410
+ * @param {string} poolKey The key to identify the pool
411
+ * @returns A function that takes a Transaction object
412
+ */
413
+ this.burnDeep = (poolKey) => (tx) => {
414
+ const pool = __privateGet(this, _config).getPool(poolKey);
415
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
416
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
417
+ tx.moveCall({
418
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::burn_deep`,
419
+ arguments: [tx.object(pool.address), tx.object(__privateGet(this, _config).DEEP_TREASURY_ID)],
420
+ typeArguments: [baseCoin.type, quoteCoin.type]
421
+ });
422
+ };
423
+ /**
424
+ * @description Get the mid price for a pool
425
+ * @param {string} poolKey The key to identify the pool
426
+ * @returns A function that takes a Transaction object
427
+ */
428
+ this.midPrice = (poolKey) => (tx) => {
429
+ const pool = __privateGet(this, _config).getPool(poolKey);
430
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
431
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
432
+ tx.moveCall({
433
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::mid_price`,
434
+ arguments: [tx.object(pool.address), tx.object.clock()],
435
+ typeArguments: [baseCoin.type, quoteCoin.type]
436
+ });
437
+ };
438
+ /**
439
+ * @description Check if a pool is whitelisted
440
+ * @param {string} poolKey The key to identify the pool
441
+ * @returns A function that takes a Transaction object
442
+ */
443
+ this.whitelisted = (poolKey) => (tx) => {
444
+ const pool = __privateGet(this, _config).getPool(poolKey);
445
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
446
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
447
+ tx.moveCall({
448
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::whitelisted`,
449
+ arguments: [tx.object(pool.address)],
450
+ typeArguments: [baseCoin.type, quoteCoin.type]
451
+ });
452
+ };
453
+ /**
454
+ * @description Get the quote quantity out for a given base quantity in
455
+ * @param {string} poolKey The key to identify the pool
456
+ * @param {number} baseQuantity Base quantity to convert
457
+ * @returns A function that takes a Transaction object
458
+ */
459
+ this.getQuoteQuantityOut = (poolKey, baseQuantity) => (tx) => {
460
+ const pool = __privateGet(this, _config).getPool(poolKey);
461
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
462
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
463
+ tx.moveCall({
464
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_out`,
465
+ arguments: [
466
+ tx.object(pool.address),
467
+ tx.pure.u64(baseQuantity * baseCoin.scalar),
468
+ tx.object.clock()
469
+ ],
470
+ typeArguments: [baseCoin.type, quoteCoin.type]
471
+ });
472
+ };
473
+ /**
474
+ * @description Get the base quantity out for a given quote quantity in
475
+ * @param {string} poolKey The key to identify the pool
476
+ * @param {number} quoteQuantity Quote quantity to convert
477
+ * @returns A function that takes a Transaction object
478
+ */
479
+ this.getBaseQuantityOut = (poolKey, quoteQuantity) => (tx) => {
480
+ const pool = __privateGet(this, _config).getPool(poolKey);
481
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
482
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
483
+ const quoteScalar = quoteCoin.scalar;
484
+ tx.moveCall({
485
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_out`,
486
+ arguments: [
487
+ tx.object(pool.address),
488
+ tx.pure.u64(quoteQuantity * quoteScalar),
489
+ tx.object.clock()
490
+ ],
491
+ typeArguments: [baseCoin.type, quoteCoin.type]
492
+ });
493
+ };
494
+ /**
495
+ * @description Get the quantity out for a given base or quote quantity
496
+ * @param {string} poolKey The key to identify the pool
497
+ * @param {number} baseQuantity Base quantity to convert
498
+ * @param {number} quoteQuantity Quote quantity to convert
499
+ * @returns A function that takes a Transaction object
500
+ */
501
+ this.getQuantityOut = (poolKey, baseQuantity, quoteQuantity) => (tx) => {
502
+ const pool = __privateGet(this, _config).getPool(poolKey);
503
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
504
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
505
+ const quoteScalar = quoteCoin.scalar;
506
+ tx.moveCall({
507
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quantity_out`,
508
+ arguments: [
509
+ tx.object(pool.address),
510
+ tx.pure.u64(baseQuantity * baseCoin.scalar),
511
+ tx.pure.u64(quoteQuantity * quoteScalar),
512
+ tx.object.clock()
513
+ ],
514
+ typeArguments: [baseCoin.type, quoteCoin.type]
515
+ });
516
+ };
517
+ /**
518
+ * @description Get open orders for a balance manager in a pool
519
+ * @param {string} poolKey The key to identify the pool
520
+ * @param {string} managerKey Key of the balance manager
521
+ * @returns A function that takes a Transaction object
522
+ */
523
+ this.accountOpenOrders = (poolKey, managerKey) => (tx) => {
524
+ const pool = __privateGet(this, _config).getPool(poolKey);
525
+ const manager = __privateGet(this, _config).getBalanceManager(managerKey);
526
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
527
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
528
+ tx.moveCall({
529
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::account_open_orders`,
530
+ arguments: [tx.object(pool.address), tx.object(manager.address)],
531
+ typeArguments: [baseCoin.type, quoteCoin.type]
532
+ });
533
+ };
534
+ /**
535
+ * @description Get level 2 order book specifying range of price
536
+ * @param {string} poolKey The key to identify the pool
537
+ * @param {number} priceLow Lower bound of the price range
538
+ * @param {number} priceHigh Upper bound of the price range
539
+ * @param {boolean} isBid Whether to get bid or ask orders
540
+ * @returns A function that takes a Transaction object
541
+ */
542
+ this.getLevel2Range = (poolKey, priceLow, priceHigh, isBid) => (tx) => {
543
+ const pool = __privateGet(this, _config).getPool(poolKey);
544
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
545
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
546
+ tx.moveCall({
547
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_level2_range`,
548
+ arguments: [
549
+ tx.object(pool.address),
550
+ tx.pure.u64(priceLow * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar),
551
+ tx.pure.u64(priceHigh * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar),
552
+ tx.pure.bool(isBid),
553
+ tx.object.clock()
554
+ ],
555
+ typeArguments: [baseCoin.type, quoteCoin.type]
556
+ });
557
+ };
558
+ /**
559
+ * @description Get level 2 order book ticks from mid-price for a pool
560
+ * @param {string} poolKey The key to identify the pool
561
+ * @param {number} tickFromMid Number of ticks from mid-price
562
+ * @returns A function that takes a Transaction object
563
+ */
564
+ this.getLevel2TicksFromMid = (poolKey, tickFromMid) => (tx) => {
565
+ const pool = __privateGet(this, _config).getPool(poolKey);
566
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
567
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
568
+ tx.moveCall({
569
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_level2_ticks_from_mid`,
570
+ arguments: [tx.object(pool.address), tx.pure.u64(tickFromMid), tx.object.clock()],
571
+ typeArguments: [baseCoin.type, quoteCoin.type]
572
+ });
573
+ };
574
+ /**
575
+ * @description Get the vault balances for a pool
576
+ * @param {string} poolKey The key to identify the pool
577
+ * @returns A function that takes a Transaction object
578
+ */
579
+ this.vaultBalances = (poolKey) => (tx) => {
580
+ const pool = __privateGet(this, _config).getPool(poolKey);
581
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
582
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
583
+ tx.moveCall({
584
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::vault_balances`,
585
+ arguments: [tx.object(pool.address)],
586
+ typeArguments: [baseCoin.type, quoteCoin.type]
587
+ });
588
+ };
589
+ /**
590
+ * @description Get the pool ID by asset types
591
+ * @param {string} baseType Type of the base asset
592
+ * @param {string} quoteType Type of the quote asset
593
+ * @returns A function that takes a Transaction object
594
+ */
595
+ this.getPoolIdByAssets = (baseType, quoteType) => (tx) => {
596
+ tx.moveCall({
597
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_pool_id_by_asset`,
598
+ arguments: [tx.object(__privateGet(this, _config).REGISTRY_ID)],
599
+ typeArguments: [baseType, quoteType]
600
+ });
601
+ };
602
+ /**
603
+ * @description Swap exact base amount for quote amount
604
+ * @param {SwapParams} params Parameters for the swap
605
+ * @returns A function that takes a Transaction object
606
+ */
607
+ this.swapExactBaseForQuote = (params) => (tx) => {
608
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
609
+ tx.setSenderIfNotSet(__privateGet(this, _config).address);
610
+ if (params.quoteCoin) {
611
+ throw new Error("quoteCoin is not accepted for swapping base asset");
612
+ }
613
+ const { poolKey, amount: baseAmount, deepAmount, minOut: minQuote } = params;
614
+ const pool = __privateGet(this, _config).getPool(poolKey);
615
+ const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
616
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
617
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
618
+ const baseCoinInput = params.baseCoin ?? (0, import_transactions.coinWithBalance)({ type: baseCoin.type, balance: Math.round(baseAmount * baseCoin.scalar) });
619
+ const deepCoin = params.deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: Math.round(deepAmount * import_config.DEEP_SCALAR) });
620
+ const minQuoteInput = Math.round(minQuote * quoteCoin.scalar);
621
+ const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
622
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote`,
623
+ arguments: [
624
+ tx.object(pool.address),
625
+ baseCoinInput,
626
+ deepCoin,
627
+ tx.pure.u64(minQuoteInput),
628
+ tx.object.clock()
629
+ ],
630
+ typeArguments: [baseCoin.type, quoteCoin.type]
631
+ });
632
+ return [baseCoinResult, quoteCoinResult, deepCoinResult];
633
+ };
634
+ /**
635
+ * @description Swap exact quote amount for base amount
636
+ * @param {SwapParams} params Parameters for the swap
637
+ * @returns A function that takes a Transaction object
638
+ */
639
+ this.swapExactQuoteForBase = (params) => (tx) => {
640
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
641
+ tx.setSenderIfNotSet(__privateGet(this, _config).address);
642
+ if (params.baseCoin) {
643
+ throw new Error("baseCoin is not accepted for swapping quote asset");
644
+ }
645
+ const { poolKey, amount: quoteAmount, deepAmount, minOut: minBase } = params;
646
+ const pool = __privateGet(this, _config).getPool(poolKey);
647
+ const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
648
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
649
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
650
+ const quoteCoinInput = params.quoteCoin ?? (0, import_transactions.coinWithBalance)({
651
+ type: quoteCoin.type,
652
+ balance: Math.round(quoteAmount * quoteCoin.scalar)
653
+ });
654
+ const deepCoin = params.deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: Math.round(deepAmount * import_config.DEEP_SCALAR) });
655
+ const minBaseInput = Math.round(minBase * baseCoin.scalar);
656
+ const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
657
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base`,
658
+ arguments: [
659
+ tx.object(pool.address),
660
+ quoteCoinInput,
661
+ deepCoin,
662
+ tx.pure.u64(minBaseInput),
663
+ tx.object.clock()
664
+ ],
665
+ typeArguments: [baseCoin.type, quoteCoin.type]
666
+ });
667
+ return [baseCoinResult, quoteCoinResult, deepCoinResult];
668
+ };
669
+ /**
670
+ * @description Swap exact quantity without a balance manager
671
+ * @param {SwapParams & {isBaseToCoin: boolean}} params Parameters for the swap
672
+ * @returns A function that takes a Transaction object
673
+ */
674
+ this.swapExactQuantity = (params) => (tx) => {
675
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
676
+ tx.setSenderIfNotSet(__privateGet(this, _config).address);
677
+ const { poolKey, amount, deepAmount, minOut, baseCoin, quoteCoin, deepCoin, isBaseToCoin } = params;
678
+ const pool = __privateGet(this, _config).getPool(poolKey);
679
+ const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
680
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
681
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
682
+ const baseCoinInput = isBaseToCoin ? baseCoin ?? (0, import_transactions.coinWithBalance)({
683
+ type: baseCoinType.type,
684
+ balance: Math.round(amount * baseCoinType.scalar)
685
+ }) : (0, import_transactions.coinWithBalance)({ type: baseCoinType.type, balance: 0 });
686
+ const quoteCoinInput = isBaseToCoin ? (0, import_transactions.coinWithBalance)({ type: quoteCoinType.type, balance: 0 }) : quoteCoin ?? (0, import_transactions.coinWithBalance)({
687
+ type: quoteCoinType.type,
688
+ balance: Math.round(amount * quoteCoinType.scalar)
689
+ });
690
+ const deepCoinInput = deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: Math.round(deepAmount * import_config.DEEP_SCALAR) });
691
+ const minOutInput = Math.round(
692
+ minOut * (isBaseToCoin ? quoteCoinType.scalar : baseCoinType.scalar)
693
+ );
694
+ const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
695
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quantity`,
696
+ arguments: [
697
+ tx.object(pool.address),
698
+ baseCoinInput,
699
+ quoteCoinInput,
700
+ deepCoinInput,
701
+ tx.pure.u64(minOutInput),
702
+ tx.object.clock()
703
+ ],
704
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
705
+ });
706
+ return [baseCoinResult, quoteCoinResult, deepCoinResult];
707
+ };
708
+ /**
709
+ * @description Swap exact base for quote with a balance manager
710
+ * @param {SwapWithManagerParams} params Parameters for the swap
711
+ * @returns A function that takes a Transaction object
712
+ */
713
+ this.swapExactBaseForQuoteWithManager = (params) => (tx) => {
714
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
715
+ const {
716
+ poolKey,
717
+ balanceManagerKey,
718
+ tradeCap,
719
+ depositCap,
720
+ withdrawCap,
721
+ amount: baseAmount,
722
+ minOut: minQuote,
723
+ baseCoin
724
+ } = params;
725
+ const pool = __privateGet(this, _config).getPool(poolKey);
726
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
727
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
728
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
729
+ const baseCoinInput = baseCoin ?? (0, import_transactions.coinWithBalance)({
730
+ type: baseCoinType.type,
731
+ balance: Math.round(baseAmount * baseCoinType.scalar)
732
+ });
733
+ const minQuoteInput = Math.round(minQuote * quoteCoinType.scalar);
734
+ const [baseCoinResult, quoteCoinResult] = tx.moveCall({
735
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote_with_manager`,
736
+ arguments: [
737
+ tx.object(pool.address),
738
+ tx.object(balanceManager.address),
739
+ tx.object(tradeCap),
740
+ tx.object(depositCap),
741
+ tx.object(withdrawCap),
742
+ baseCoinInput,
743
+ tx.pure.u64(minQuoteInput),
744
+ tx.object.clock()
745
+ ],
746
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
747
+ });
748
+ return [baseCoinResult, quoteCoinResult];
749
+ };
750
+ /**
751
+ * @description Swap exact quote for base with a balance manager
752
+ * @param {SwapWithManagerParams} params Parameters for the swap
753
+ * @returns A function that takes a Transaction object
754
+ */
755
+ this.swapExactQuoteForBaseWithManager = (params) => (tx) => {
756
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
757
+ const {
758
+ poolKey,
759
+ balanceManagerKey,
760
+ tradeCap,
761
+ depositCap,
762
+ withdrawCap,
763
+ amount: quoteAmount,
764
+ minOut: minBase,
765
+ quoteCoin
766
+ } = params;
767
+ const pool = __privateGet(this, _config).getPool(poolKey);
768
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
769
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
770
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
771
+ const quoteCoinInput = quoteCoin ?? (0, import_transactions.coinWithBalance)({
772
+ type: quoteCoinType.type,
773
+ balance: Math.round(quoteAmount * quoteCoinType.scalar)
774
+ });
775
+ const minBaseInput = Math.round(minBase * baseCoinType.scalar);
776
+ const [baseCoinResult, quoteCoinResult] = tx.moveCall({
777
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base_with_manager`,
778
+ arguments: [
779
+ tx.object(pool.address),
780
+ tx.object(balanceManager.address),
781
+ tx.object(tradeCap),
782
+ tx.object(depositCap),
783
+ tx.object(withdrawCap),
784
+ quoteCoinInput,
785
+ tx.pure.u64(minBaseInput),
786
+ tx.object.clock()
787
+ ],
788
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
789
+ });
790
+ return [baseCoinResult, quoteCoinResult];
791
+ };
792
+ /**
793
+ * @description Swap exact quantity (base or quote) with a balance manager
794
+ * @param {SwapWithManagerParams & {isBaseToCoin: boolean}} params Parameters for the swap
795
+ * @returns A function that takes a Transaction object
796
+ */
797
+ this.swapExactQuantityWithManager = (params) => (tx) => {
798
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
799
+ const {
800
+ poolKey,
801
+ balanceManagerKey,
802
+ tradeCap,
803
+ depositCap,
804
+ withdrawCap,
805
+ amount,
806
+ minOut,
807
+ baseCoin,
808
+ quoteCoin,
809
+ isBaseToCoin
810
+ } = params;
811
+ const pool = __privateGet(this, _config).getPool(poolKey);
812
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
813
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
814
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
815
+ const baseCoinInput = isBaseToCoin ? baseCoin ?? (0, import_transactions.coinWithBalance)({
816
+ type: baseCoinType.type,
817
+ balance: Math.round(amount * baseCoinType.scalar)
818
+ }) : (0, import_transactions.coinWithBalance)({ type: baseCoinType.type, balance: 0 });
819
+ const quoteCoinInput = isBaseToCoin ? (0, import_transactions.coinWithBalance)({ type: quoteCoinType.type, balance: 0 }) : quoteCoin ?? (0, import_transactions.coinWithBalance)({
820
+ type: quoteCoinType.type,
821
+ balance: Math.round(amount * quoteCoinType.scalar)
822
+ });
823
+ const minOutInput = Math.round(
824
+ minOut * (isBaseToCoin ? quoteCoinType.scalar : baseCoinType.scalar)
825
+ );
826
+ const [baseCoinResult, quoteCoinResult] = tx.moveCall({
827
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quantity_with_manager`,
828
+ arguments: [
829
+ tx.object(pool.address),
830
+ tx.object(balanceManager.address),
831
+ tx.object(tradeCap),
832
+ tx.object(depositCap),
833
+ tx.object(withdrawCap),
834
+ baseCoinInput,
835
+ quoteCoinInput,
836
+ tx.pure.u64(minOutInput),
837
+ tx.object.clock()
838
+ ],
839
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
840
+ });
841
+ return [baseCoinResult, quoteCoinResult];
842
+ };
843
+ /**
844
+ * @description Create a new pool permissionlessly
845
+ * @param {CreatePermissionlessPoolParams} params Parameters for creating permissionless pool
846
+ * @returns A function that takes a Transaction object
847
+ */
848
+ this.createPermissionlessPool = (params) => (tx) => {
849
+ tx.setSenderIfNotSet(__privateGet(this, _config).address);
850
+ const { baseCoinKey, quoteCoinKey, tickSize, lotSize, minSize, deepCoin } = params;
851
+ const baseCoin = __privateGet(this, _config).getCoin(baseCoinKey);
852
+ const quoteCoin = __privateGet(this, _config).getCoin(quoteCoinKey);
853
+ const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
854
+ const baseScalar = baseCoin.scalar;
855
+ const quoteScalar = quoteCoin.scalar;
856
+ const adjustedTickSize = Math.round(tickSize * import_config.FLOAT_SCALAR * quoteScalar / baseScalar);
857
+ const adjustedLotSize = Math.round(lotSize * baseScalar);
858
+ const adjustedMinSize = Math.round(minSize * baseScalar);
859
+ const deepCoinInput = deepCoin ?? (0, import_transactions.coinWithBalance)({
860
+ type: deepCoinType,
861
+ balance: import_config.POOL_CREATION_FEE_DEEP
862
+ });
863
+ tx.moveCall({
864
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::create_permissionless_pool`,
865
+ arguments: [
866
+ tx.object(__privateGet(this, _config).REGISTRY_ID),
867
+ // registry_id
868
+ tx.pure.u64(adjustedTickSize),
869
+ // adjusted tick_size
870
+ tx.pure.u64(adjustedLotSize),
871
+ // adjusted lot_size
872
+ tx.pure.u64(adjustedMinSize),
873
+ // adjusted min_size
874
+ deepCoinInput
875
+ ],
876
+ typeArguments: [baseCoin.type, quoteCoin.type]
877
+ });
878
+ };
879
+ /**
880
+ * @description Get the trade parameters for a given pool, including taker fee, maker fee, and stake required.
881
+ * @param {string} poolKey Key of the pool
882
+ * @returns A function that takes a Transaction object
883
+ */
884
+ this.poolTradeParams = (poolKey) => (tx) => {
885
+ const pool = __privateGet(this, _config).getPool(poolKey);
886
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
887
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
888
+ tx.moveCall({
889
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::pool_trade_params`,
890
+ arguments: [tx.object(pool.address)],
891
+ typeArguments: [baseCoin.type, quoteCoin.type]
892
+ });
893
+ };
894
+ /**
895
+ * @description Get the book parameters for a given pool, including tick size, lot size, and min size.
896
+ * @param {string} poolKey Key of the pool
897
+ * @returns A function that takes a Transaction object
898
+ */
899
+ this.poolBookParams = (poolKey) => (tx) => {
900
+ const pool = __privateGet(this, _config).getPool(poolKey);
901
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
902
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
903
+ tx.moveCall({
904
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::pool_book_params`,
905
+ arguments: [tx.object(pool.address)],
906
+ typeArguments: [baseCoin.type, quoteCoin.type]
907
+ });
908
+ };
909
+ /**
910
+ * @description Get the account information for a given pool and balance manager
911
+ * @param {string} poolKey Key of the pool
912
+ * @param {string} managerKey The key of the BalanceManager
913
+ * @returns A function that takes a Transaction object
914
+ */
915
+ this.account = (poolKey, managerKey) => (tx) => {
916
+ const pool = __privateGet(this, _config).getPool(poolKey);
917
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
918
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
919
+ const managerId = __privateGet(this, _config).getBalanceManager(managerKey).address;
920
+ tx.moveCall({
921
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::account`,
922
+ arguments: [tx.object(pool.address), tx.object(managerId)],
923
+ typeArguments: [baseCoin.type, quoteCoin.type]
924
+ });
925
+ };
926
+ /**
927
+ * @description Get the locked balance for a given pool and balance manager
928
+ * @param {string} poolKey Key of the pool
929
+ * @param {string} managerKey The key of the BalanceManager
930
+ * @returns A function that takes a Transaction object
931
+ */
932
+ this.lockedBalance = (poolKey, managerKey) => (tx) => {
933
+ const pool = __privateGet(this, _config).getPool(poolKey);
934
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
935
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
936
+ const managerId = __privateGet(this, _config).getBalanceManager(managerKey).address;
937
+ tx.moveCall({
938
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::locked_balance`,
939
+ arguments: [tx.object(pool.address), tx.object(managerId)],
940
+ typeArguments: [baseCoin.type, quoteCoin.type]
941
+ });
942
+ };
943
+ /**
944
+ * @description Get the DEEP price conversion for a pool
945
+ * @param {string} poolKey The key to identify the pool
946
+ * @returns A function that takes a Transaction object
947
+ */
948
+ this.getPoolDeepPrice = (poolKey) => (tx) => {
949
+ const pool = __privateGet(this, _config).getPool(poolKey);
950
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
951
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
952
+ tx.moveCall({
953
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_order_deep_price`,
954
+ arguments: [tx.object(pool.address)],
955
+ typeArguments: [baseCoin.type, quoteCoin.type]
956
+ });
957
+ };
958
+ /**
959
+ * @description Get the balance manager IDs for a given owner
960
+ * @param {string} owner The owner address to get balance manager IDs for
961
+ * @returns A function that takes a Transaction object
962
+ */
963
+ this.getBalanceManagerIds = (owner) => (tx) => {
964
+ tx.moveCall({
965
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::registry::get_balance_manager_ids`,
966
+ arguments: [tx.object(__privateGet(this, _config).REGISTRY_ID), tx.pure.address(owner)]
967
+ });
968
+ };
969
+ /**
970
+ * @description Get the balances for a referral (DeepBookPoolReferral)
971
+ * @param {string} poolKey The key to identify the pool
972
+ * @param {string} referral The referral (DeepBookPoolReferral) to get the balances for
973
+ * @returns A function that takes a Transaction object
974
+ */
975
+ this.getPoolReferralBalances = (poolKey, referral) => (tx) => {
976
+ const pool = __privateGet(this, _config).getPool(poolKey);
977
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
978
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
979
+ return tx.moveCall({
980
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_pool_referral_balances`,
981
+ arguments: [tx.object(pool.address), tx.object(referral)],
982
+ typeArguments: [baseCoin.type, quoteCoin.type]
983
+ });
984
+ };
985
+ /**
986
+ * @description Get the multiplier for a referral (DeepBookPoolReferral)
987
+ * @param {string} poolKey The key to identify the pool
988
+ * @param {string} referral The referral (DeepBookPoolReferral) to get the multiplier for
989
+ * @returns A function that takes a Transaction object
990
+ */
991
+ this.poolReferralMultiplier = (poolKey, referral) => (tx) => {
992
+ const pool = __privateGet(this, _config).getPool(poolKey);
993
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
994
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
995
+ return tx.moveCall({
996
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::pool_referral_multiplier`,
997
+ arguments: [tx.object(pool.address), tx.object(referral)],
998
+ typeArguments: [baseCoin.type, quoteCoin.type]
999
+ });
1000
+ };
1001
+ /**
1002
+ * @description Check if a pool is a stable pool
1003
+ * @param {string} poolKey The key to identify the pool
1004
+ * @returns A function that takes a Transaction object
1005
+ */
1006
+ this.stablePool = (poolKey) => (tx) => {
1007
+ const pool = __privateGet(this, _config).getPool(poolKey);
1008
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1009
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1010
+ return tx.moveCall({
1011
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::stable_pool`,
1012
+ arguments: [tx.object(pool.address)],
1013
+ typeArguments: [baseCoin.type, quoteCoin.type]
1014
+ });
1015
+ };
1016
+ /**
1017
+ * @description Check if a pool is registered
1018
+ * @param {string} poolKey The key to identify the pool
1019
+ * @returns A function that takes a Transaction object
1020
+ */
1021
+ this.registeredPool = (poolKey) => (tx) => {
1022
+ const pool = __privateGet(this, _config).getPool(poolKey);
1023
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1024
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1025
+ return tx.moveCall({
1026
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::registered_pool`,
1027
+ arguments: [tx.object(pool.address)],
1028
+ typeArguments: [baseCoin.type, quoteCoin.type]
1029
+ });
1030
+ };
1031
+ /**
1032
+ * @description Get the quote quantity out for a given base quantity using input token as fee
1033
+ * @param {string} poolKey The key to identify the pool
1034
+ * @param {number} baseQuantity Base quantity to convert
1035
+ * @returns A function that takes a Transaction object
1036
+ */
1037
+ this.getQuoteQuantityOutInputFee = (poolKey, baseQuantity) => (tx) => {
1038
+ const pool = __privateGet(this, _config).getPool(poolKey);
1039
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1040
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1041
+ return tx.moveCall({
1042
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_out_input_fee`,
1043
+ arguments: [
1044
+ tx.object(pool.address),
1045
+ tx.pure.u64(baseQuantity * baseCoin.scalar),
1046
+ tx.object.clock()
1047
+ ],
1048
+ typeArguments: [baseCoin.type, quoteCoin.type]
1049
+ });
1050
+ };
1051
+ /**
1052
+ * @description Get the base quantity out for a given quote quantity using input token as fee
1053
+ * @param {string} poolKey The key to identify the pool
1054
+ * @param {number} quoteQuantity Quote quantity to convert
1055
+ * @returns A function that takes a Transaction object
1056
+ */
1057
+ this.getBaseQuantityOutInputFee = (poolKey, quoteQuantity) => (tx) => {
1058
+ const pool = __privateGet(this, _config).getPool(poolKey);
1059
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1060
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1061
+ return tx.moveCall({
1062
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_out_input_fee`,
1063
+ arguments: [
1064
+ tx.object(pool.address),
1065
+ tx.pure.u64(quoteQuantity * quoteCoin.scalar),
1066
+ tx.object.clock()
1067
+ ],
1068
+ typeArguments: [baseCoin.type, quoteCoin.type]
1069
+ });
1070
+ };
1071
+ /**
1072
+ * @description Get the quantity out for a given base or quote quantity using input token as fee
1073
+ * @param {string} poolKey The key to identify the pool
1074
+ * @param {number} baseQuantity Base quantity to convert
1075
+ * @param {number} quoteQuantity Quote quantity to convert
1076
+ * @returns A function that takes a Transaction object
1077
+ */
1078
+ this.getQuantityOutInputFee = (poolKey, baseQuantity, quoteQuantity) => (tx) => {
1079
+ const pool = __privateGet(this, _config).getPool(poolKey);
1080
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1081
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1082
+ return tx.moveCall({
1083
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quantity_out_input_fee`,
1084
+ arguments: [
1085
+ tx.object(pool.address),
1086
+ tx.pure.u64(baseQuantity * baseCoin.scalar),
1087
+ tx.pure.u64(quoteQuantity * quoteCoin.scalar),
1088
+ tx.object.clock()
1089
+ ],
1090
+ typeArguments: [baseCoin.type, quoteCoin.type]
1091
+ });
1092
+ };
1093
+ /**
1094
+ * @description Get the base quantity needed to receive a target quote quantity
1095
+ * @param {string} poolKey The key to identify the pool
1096
+ * @param {number} targetQuoteQuantity Target quote quantity
1097
+ * @param {boolean} payWithDeep Whether to pay fees with DEEP
1098
+ * @returns A function that takes a Transaction object
1099
+ */
1100
+ this.getBaseQuantityIn = (poolKey, targetQuoteQuantity, payWithDeep) => (tx) => {
1101
+ const pool = __privateGet(this, _config).getPool(poolKey);
1102
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1103
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1104
+ return tx.moveCall({
1105
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_in`,
1106
+ arguments: [
1107
+ tx.object(pool.address),
1108
+ tx.pure.u64(targetQuoteQuantity * quoteCoin.scalar),
1109
+ tx.pure.bool(payWithDeep),
1110
+ tx.object.clock()
1111
+ ],
1112
+ typeArguments: [baseCoin.type, quoteCoin.type]
1113
+ });
1114
+ };
1115
+ /**
1116
+ * @description Get the quote quantity needed to receive a target base quantity
1117
+ * @param {string} poolKey The key to identify the pool
1118
+ * @param {number} targetBaseQuantity Target base quantity
1119
+ * @param {boolean} payWithDeep Whether to pay fees with DEEP
1120
+ * @returns A function that takes a Transaction object
1121
+ */
1122
+ this.getQuoteQuantityIn = (poolKey, targetBaseQuantity, payWithDeep) => (tx) => {
1123
+ const pool = __privateGet(this, _config).getPool(poolKey);
1124
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1125
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1126
+ return tx.moveCall({
1127
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_in`,
1128
+ arguments: [
1129
+ tx.object(pool.address),
1130
+ tx.pure.u64(targetBaseQuantity * baseCoin.scalar),
1131
+ tx.pure.bool(payWithDeep),
1132
+ tx.object.clock()
1133
+ ],
1134
+ typeArguments: [baseCoin.type, quoteCoin.type]
1135
+ });
1136
+ };
1137
+ /**
1138
+ * @description Get account order details for a balance manager
1139
+ * @param {string} poolKey The key to identify the pool
1140
+ * @param {string} managerKey Key of the balance manager
1141
+ * @returns A function that takes a Transaction object
1142
+ */
1143
+ this.getAccountOrderDetails = (poolKey, managerKey) => (tx) => {
1144
+ const pool = __privateGet(this, _config).getPool(poolKey);
1145
+ const manager = __privateGet(this, _config).getBalanceManager(managerKey);
1146
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1147
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1148
+ return tx.moveCall({
1149
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_account_order_details`,
1150
+ arguments: [tx.object(pool.address), tx.object(manager.address)],
1151
+ typeArguments: [baseCoin.type, quoteCoin.type]
1152
+ });
1153
+ };
1154
+ /**
1155
+ * @description Get the DEEP required for an order
1156
+ * @param {string} poolKey The key to identify the pool
1157
+ * @param {number} baseQuantity Base quantity
1158
+ * @param {number} price Price
1159
+ * @returns A function that takes a Transaction object
1160
+ */
1161
+ this.getOrderDeepRequired = (poolKey, baseQuantity, price) => (tx) => {
1162
+ const pool = __privateGet(this, _config).getPool(poolKey);
1163
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1164
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1165
+ const inputPrice = Math.round(price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
1166
+ const inputQuantity = Math.round(baseQuantity * baseCoin.scalar);
1167
+ return tx.moveCall({
1168
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_order_deep_required`,
1169
+ arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity), tx.pure.u64(inputPrice)],
1170
+ typeArguments: [baseCoin.type, quoteCoin.type]
1171
+ });
1172
+ };
1173
+ /**
1174
+ * @description Check if account exists for a balance manager
1175
+ * @param {string} poolKey The key to identify the pool
1176
+ * @param {string} managerKey Key of the balance manager
1177
+ * @returns A function that takes a Transaction object
1178
+ */
1179
+ this.accountExists = (poolKey, managerKey) => (tx) => {
1180
+ const pool = __privateGet(this, _config).getPool(poolKey);
1181
+ const manager = __privateGet(this, _config).getBalanceManager(managerKey);
1182
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1183
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1184
+ return tx.moveCall({
1185
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::account_exists`,
1186
+ arguments: [tx.object(pool.address), tx.object(manager.address)],
1187
+ typeArguments: [baseCoin.type, quoteCoin.type]
1188
+ });
1189
+ };
1190
+ /**
1191
+ * @description Get the next epoch trade parameters for a pool
1192
+ * @param {string} poolKey The key to identify the pool
1193
+ * @returns A function that takes a Transaction object
1194
+ */
1195
+ this.poolTradeParamsNext = (poolKey) => (tx) => {
1196
+ const pool = __privateGet(this, _config).getPool(poolKey);
1197
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1198
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1199
+ return tx.moveCall({
1200
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::pool_trade_params_next`,
1201
+ arguments: [tx.object(pool.address)],
1202
+ typeArguments: [baseCoin.type, quoteCoin.type]
1203
+ });
1204
+ };
1205
+ /**
1206
+ * @description Get the quorum for a pool
1207
+ * @param {string} poolKey The key to identify the pool
1208
+ * @returns A function that takes a Transaction object
1209
+ */
1210
+ this.quorum = (poolKey) => (tx) => {
1211
+ const pool = __privateGet(this, _config).getPool(poolKey);
1212
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1213
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1214
+ return tx.moveCall({
1215
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::quorum`,
1216
+ arguments: [tx.object(pool.address)],
1217
+ typeArguments: [baseCoin.type, quoteCoin.type]
1218
+ });
1219
+ };
1220
+ /**
1221
+ * @description Get the pool ID
1222
+ * @param {string} poolKey The key to identify the pool
1223
+ * @returns A function that takes a Transaction object
1224
+ */
1225
+ this.poolId = (poolKey) => (tx) => {
1226
+ const pool = __privateGet(this, _config).getPool(poolKey);
1227
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1228
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1229
+ return tx.moveCall({
1230
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::id`,
1231
+ arguments: [tx.object(pool.address)],
1232
+ typeArguments: [baseCoin.type, quoteCoin.type]
1233
+ });
1234
+ };
1235
+ /**
1236
+ * @description Check if a limit order can be placed
1237
+ * @param {CanPlaceLimitOrderParams} params Parameters for checking limit order validity
1238
+ * @returns A function that takes a Transaction object
1239
+ */
1240
+ this.canPlaceLimitOrder = (params) => (tx) => {
1241
+ const { poolKey, balanceManagerKey, price, quantity, isBid, payWithDeep, expireTimestamp } = params;
1242
+ const pool = __privateGet(this, _config).getPool(poolKey);
1243
+ const manager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
1244
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1245
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1246
+ const inputPrice = Math.round(price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
1247
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1248
+ return tx.moveCall({
1249
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::can_place_limit_order`,
1250
+ arguments: [
1251
+ tx.object(pool.address),
1252
+ tx.object(manager.address),
1253
+ tx.pure.u64(inputPrice),
1254
+ tx.pure.u64(inputQuantity),
1255
+ tx.pure.bool(isBid),
1256
+ tx.pure.bool(payWithDeep),
1257
+ tx.pure.u64(expireTimestamp),
1258
+ tx.object.clock()
1259
+ ],
1260
+ typeArguments: [baseCoin.type, quoteCoin.type]
1261
+ });
1262
+ };
1263
+ /**
1264
+ * @description Check if a market order can be placed
1265
+ * @param {CanPlaceMarketOrderParams} params Parameters for checking market order validity
1266
+ * @returns A function that takes a Transaction object
1267
+ */
1268
+ this.canPlaceMarketOrder = (params) => (tx) => {
1269
+ const { poolKey, balanceManagerKey, quantity, isBid, payWithDeep } = params;
1270
+ const pool = __privateGet(this, _config).getPool(poolKey);
1271
+ const manager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
1272
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1273
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1274
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1275
+ return tx.moveCall({
1276
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::can_place_market_order`,
1277
+ arguments: [
1278
+ tx.object(pool.address),
1279
+ tx.object(manager.address),
1280
+ tx.pure.u64(inputQuantity),
1281
+ tx.pure.bool(isBid),
1282
+ tx.pure.bool(payWithDeep),
1283
+ tx.object.clock()
1284
+ ],
1285
+ typeArguments: [baseCoin.type, quoteCoin.type]
1286
+ });
1287
+ };
1288
+ /**
1289
+ * @description Check if market order params are valid
1290
+ * @param {string} poolKey The key to identify the pool
1291
+ * @param {number} quantity Quantity
1292
+ * @returns A function that takes a Transaction object
1293
+ */
1294
+ this.checkMarketOrderParams = (poolKey, quantity) => (tx) => {
1295
+ const pool = __privateGet(this, _config).getPool(poolKey);
1296
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1297
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1298
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1299
+ return tx.moveCall({
1300
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::check_market_order_params`,
1301
+ arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
1302
+ typeArguments: [baseCoin.type, quoteCoin.type]
1303
+ });
1304
+ };
1305
+ /**
1306
+ * @description Check if limit order params are valid
1307
+ * @param {string} poolKey The key to identify the pool
1308
+ * @param {number} price Price
1309
+ * @param {number} quantity Quantity
1310
+ * @param {number} expireTimestamp Expiration timestamp
1311
+ * @returns A function that takes a Transaction object
1312
+ */
1313
+ this.checkLimitOrderParams = (poolKey, price, quantity, expireTimestamp) => (tx) => {
1314
+ const pool = __privateGet(this, _config).getPool(poolKey);
1315
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1316
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1317
+ const inputPrice = Math.round(price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
1318
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1319
+ return tx.moveCall({
1320
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::check_limit_order_params`,
1321
+ arguments: [
1322
+ tx.object(pool.address),
1323
+ tx.pure.u64(inputPrice),
1324
+ tx.pure.u64(inputQuantity),
1325
+ tx.pure.u64(expireTimestamp),
1326
+ tx.object.clock()
1327
+ ],
1328
+ typeArguments: [baseCoin.type, quoteCoin.type]
1329
+ });
1330
+ };
1331
+ __privateSet(this, _config, config);
1332
+ }
1333
+ }
1334
+ _config = new WeakMap();
1335
+ //# sourceMappingURL=deepbook.js.map