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