@haneullabs/deepbook-v3 0.1.0 → 1.0.11

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 (568) hide show
  1. package/CHANGELOG.md +268 -81
  2. package/dist/client.d.mts +957 -0
  3. package/dist/client.d.mts.map +1 -0
  4. package/dist/client.mjs +2293 -0
  5. package/dist/client.mjs.map +1 -0
  6. package/dist/contracts/deepbook/account.d.mts +38 -0
  7. package/dist/contracts/deepbook/account.d.mts.map +1 -0
  8. package/dist/contracts/deepbook/account.mjs +31 -0
  9. package/dist/contracts/deepbook/account.mjs.map +1 -0
  10. package/dist/contracts/deepbook/balances.d.mts +13 -0
  11. package/dist/contracts/deepbook/balances.d.mts.map +1 -0
  12. package/dist/contracts/deepbook/balances.mjs +24 -0
  13. package/dist/contracts/deepbook/balances.mjs.map +1 -0
  14. package/dist/contracts/deepbook/deep_price.d.mts +13 -0
  15. package/dist/contracts/deepbook/deep_price.d.mts.map +1 -0
  16. package/dist/contracts/deepbook/deep_price.mjs +49 -0
  17. package/dist/contracts/deepbook/deep_price.mjs.map +1 -0
  18. package/dist/contracts/deepbook/deps/haneul/vec_set.d.mts +22 -0
  19. package/dist/contracts/deepbook/deps/haneul/vec_set.d.mts.map +1 -0
  20. package/dist/contracts/deepbook/deps/haneul/vec_set.mjs +26 -0
  21. package/dist/contracts/deepbook/deps/haneul/vec_set.mjs.map +1 -0
  22. package/dist/contracts/deepbook/order.d.mts +24 -0
  23. package/dist/contracts/deepbook/order.d.mts.map +1 -0
  24. package/dist/contracts/deepbook/order.mjs +63 -0
  25. package/dist/contracts/deepbook/order.mjs.map +1 -0
  26. package/dist/contracts/pyth/data_source.mjs +20 -0
  27. package/dist/contracts/pyth/data_source.mjs.map +1 -0
  28. package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs +21 -0
  29. package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs.map +1 -0
  30. package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs +19 -0
  31. package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs.map +1 -0
  32. package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes32.mjs +16 -0
  33. package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes32.mjs.map +1 -0
  34. package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/consumed_vaas.mjs +16 -0
  35. package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/consumed_vaas.mjs.map +1 -0
  36. package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/external_address.mjs +16 -0
  37. package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/external_address.mjs.map +1 -0
  38. package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/set.mjs +16 -0
  39. package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/set.mjs.map +1 -0
  40. package/dist/contracts/pyth/i64.mjs +19 -0
  41. package/dist/contracts/pyth/i64.mjs.map +1 -0
  42. package/dist/contracts/pyth/price.mjs +22 -0
  43. package/dist/contracts/pyth/price.mjs.map +1 -0
  44. package/dist/contracts/pyth/price_feed.mjs +21 -0
  45. package/dist/contracts/pyth/price_feed.mjs.map +1 -0
  46. package/dist/contracts/pyth/price_identifier.mjs +16 -0
  47. package/dist/contracts/pyth/price_identifier.mjs.map +1 -0
  48. package/dist/contracts/pyth/price_info.mjs +28 -0
  49. package/dist/contracts/pyth/price_info.mjs.map +1 -0
  50. package/dist/contracts/pyth/state.mjs +36 -0
  51. package/dist/contracts/pyth/state.mjs.map +1 -0
  52. package/dist/contracts/utils/index.d.mts +34 -0
  53. package/dist/contracts/utils/index.d.mts.map +1 -0
  54. package/dist/contracts/utils/index.mjs +35 -0
  55. package/dist/contracts/utils/index.mjs.map +1 -0
  56. package/dist/contracts/wormhole/bytes32.mjs +16 -0
  57. package/dist/contracts/wormhole/bytes32.mjs.map +1 -0
  58. package/dist/contracts/wormhole/consumed_vaas.mjs +16 -0
  59. package/dist/contracts/wormhole/consumed_vaas.mjs.map +1 -0
  60. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs +16 -0
  61. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs.map +1 -0
  62. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs +21 -0
  63. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs.map +1 -0
  64. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs +19 -0
  65. package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs.map +1 -0
  66. package/dist/contracts/wormhole/external_address.mjs +16 -0
  67. package/dist/contracts/wormhole/external_address.mjs.map +1 -0
  68. package/dist/contracts/wormhole/fee_collector.mjs +20 -0
  69. package/dist/contracts/wormhole/fee_collector.mjs.map +1 -0
  70. package/dist/contracts/wormhole/set.mjs +16 -0
  71. package/dist/contracts/wormhole/set.mjs.map +1 -0
  72. package/dist/contracts/wormhole/state.mjs +31 -0
  73. package/dist/contracts/wormhole/state.mjs.map +1 -0
  74. package/dist/index.d.mts +25 -0
  75. package/dist/index.mjs +26 -0
  76. package/dist/pyth/PriceServiceConnection.d.mts +26 -0
  77. package/dist/pyth/PriceServiceConnection.d.mts.map +1 -0
  78. package/dist/pyth/PriceServiceConnection.mjs +35 -0
  79. package/dist/pyth/PriceServiceConnection.mjs.map +1 -0
  80. package/dist/pyth/pyth-helpers.mjs +18 -0
  81. package/dist/pyth/pyth-helpers.mjs.map +1 -0
  82. package/dist/pyth/pyth.d.mts +69 -0
  83. package/dist/pyth/pyth.d.mts.map +1 -0
  84. package/dist/pyth/pyth.mjs +220 -0
  85. package/dist/pyth/pyth.mjs.map +1 -0
  86. package/dist/transactions/balanceManager.d.mts +174 -0
  87. package/dist/transactions/balanceManager.d.mts.map +1 -0
  88. package/dist/transactions/balanceManager.mjs +233 -0
  89. package/dist/transactions/balanceManager.mjs.map +1 -0
  90. package/dist/transactions/deepbook.d.mts +490 -0
  91. package/dist/transactions/deepbook.d.mts.map +1 -0
  92. package/dist/transactions/deepbook.mjs +978 -0
  93. package/dist/transactions/deepbook.mjs.map +1 -0
  94. package/dist/transactions/deepbookAdmin.d.mts +111 -0
  95. package/dist/transactions/deepbookAdmin.d.mts.map +1 -0
  96. package/dist/transactions/deepbookAdmin.mjs +221 -0
  97. package/dist/transactions/deepbookAdmin.mjs.map +1 -0
  98. package/dist/transactions/flashLoans.d.mts +62 -0
  99. package/dist/transactions/flashLoans.d.mts.map +1 -0
  100. package/dist/transactions/flashLoans.mjs +75 -0
  101. package/dist/transactions/flashLoans.mjs.map +1 -0
  102. package/dist/transactions/governance.d.mts +48 -0
  103. package/dist/transactions/governance.d.mts.map +1 -0
  104. package/dist/transactions/governance.mjs +90 -0
  105. package/dist/transactions/governance.mjs.map +1 -0
  106. package/dist/transactions/marginAdmin.d.mts +139 -0
  107. package/dist/transactions/marginAdmin.d.mts.map +1 -0
  108. package/dist/transactions/marginAdmin.mjs +249 -0
  109. package/dist/transactions/marginAdmin.mjs.map +1 -0
  110. package/dist/transactions/marginLiquidations.d.mts +67 -0
  111. package/dist/transactions/marginLiquidations.d.mts.map +1 -0
  112. package/dist/transactions/marginLiquidations.mjs +109 -0
  113. package/dist/transactions/marginLiquidations.mjs.map +1 -0
  114. package/dist/transactions/marginMaintainer.d.mts +86 -0
  115. package/dist/transactions/marginMaintainer.d.mts.map +1 -0
  116. package/dist/transactions/marginMaintainer.mjs +160 -0
  117. package/dist/transactions/marginMaintainer.mjs.map +1 -0
  118. package/dist/transactions/marginManager.d.mts +255 -0
  119. package/dist/transactions/marginManager.d.mts.map +1 -0
  120. package/dist/transactions/marginManager.mjs +558 -0
  121. package/dist/transactions/marginManager.mjs.map +1 -0
  122. package/dist/transactions/marginPool.d.mts +140 -0
  123. package/dist/transactions/marginPool.d.mts.map +1 -0
  124. package/dist/transactions/marginPool.mjs +206 -0
  125. package/dist/transactions/marginPool.mjs.map +1 -0
  126. package/dist/transactions/marginRegistry.d.mts +100 -0
  127. package/dist/transactions/marginRegistry.d.mts.map +1 -0
  128. package/dist/transactions/marginRegistry.mjs +128 -0
  129. package/dist/transactions/marginRegistry.mjs.map +1 -0
  130. package/dist/transactions/marginTPSL.d.mts +100 -0
  131. package/dist/transactions/marginTPSL.d.mts.map +1 -0
  132. package/dist/transactions/marginTPSL.mjs +175 -0
  133. package/dist/transactions/marginTPSL.mjs.map +1 -0
  134. package/dist/transactions/poolProxy.d.mts +123 -0
  135. package/dist/transactions/poolProxy.d.mts.map +1 -0
  136. package/dist/transactions/poolProxy.mjs +336 -0
  137. package/dist/transactions/poolProxy.mjs.map +1 -0
  138. package/dist/types/bcs.d.mts +5 -0
  139. package/dist/types/bcs.mjs +7 -0
  140. package/dist/types/index.d.mts +237 -0
  141. package/dist/types/index.d.mts.map +1 -0
  142. package/dist/types/index.mjs +18 -0
  143. package/dist/types/index.mjs.map +1 -0
  144. package/dist/utils/config.d.mts +82 -0
  145. package/dist/utils/config.d.mts.map +1 -0
  146. package/dist/utils/config.mjs +88 -0
  147. package/dist/utils/config.mjs.map +1 -0
  148. package/dist/utils/constants.d.mts +85 -0
  149. package/dist/utils/constants.d.mts.map +1 -0
  150. package/dist/utils/constants.mjs +384 -0
  151. package/dist/utils/constants.mjs.map +1 -0
  152. package/dist/utils/errors.d.mts +46 -0
  153. package/dist/utils/errors.d.mts.map +1 -0
  154. package/dist/utils/errors.mjs +59 -0
  155. package/dist/utils/errors.mjs.map +1 -0
  156. package/dist/{cjs/utils/validation.d.ts → utils/validation.d.mts} +11 -7
  157. package/dist/utils/validation.d.mts.map +1 -0
  158. package/dist/utils/validation.mjs +76 -0
  159. package/dist/utils/validation.mjs.map +1 -0
  160. package/package.json +29 -26
  161. package/src/client.ts +1016 -545
  162. package/src/contracts/deepbook/account.ts +15 -15
  163. package/src/contracts/deepbook/balance_manager.ts +343 -57
  164. package/src/contracts/deepbook/balances.ts +3 -2
  165. package/src/contracts/deepbook/big_vector.ts +6 -7
  166. package/src/contracts/deepbook/book.ts +3 -2
  167. package/src/contracts/deepbook/constants.ts +95 -3
  168. package/src/contracts/deepbook/deep_price.ts +7 -7
  169. package/src/contracts/deepbook/deps/{sui → haneul}/bag.ts +8 -8
  170. package/src/contracts/deepbook/deps/{sui → haneul}/balance.ts +4 -3
  171. package/src/contracts/deepbook/deps/{sui → haneul}/table.ts +6 -6
  172. package/src/contracts/deepbook/deps/{sui → haneul}/vec_map.ts +4 -4
  173. package/src/contracts/deepbook/deps/{sui → haneul}/vec_set.ts +4 -4
  174. package/src/contracts/deepbook/deps/{sui → haneul}/versioned.ts +4 -4
  175. package/src/contracts/deepbook/deps/std/type_name.ts +3 -2
  176. package/src/contracts/deepbook/ewma.ts +14 -3
  177. package/src/contracts/deepbook/fill.ts +21 -21
  178. package/src/contracts/deepbook/governance.ts +4 -3
  179. package/src/contracts/deepbook/history.ts +4 -3
  180. package/src/contracts/deepbook/math.ts +15 -15
  181. package/src/contracts/deepbook/order.ts +16 -16
  182. package/src/contracts/deepbook/order_info.ts +39 -27
  183. package/src/contracts/deepbook/order_query.ts +12 -12
  184. package/src/contracts/deepbook/pool.ts +883 -526
  185. package/src/contracts/deepbook/registry.ts +149 -38
  186. package/src/contracts/deepbook/state.ts +14 -3
  187. package/src/contracts/deepbook/trade_params.ts +3 -2
  188. package/src/contracts/deepbook/vault.ts +5 -4
  189. package/src/contracts/pyth/batch_price_attestation.ts +92 -0
  190. package/src/contracts/pyth/contract_upgrade.ts +54 -0
  191. package/src/contracts/pyth/data_source.ts +64 -0
  192. package/src/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts +15 -0
  193. package/src/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts +13 -0
  194. package/src/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes32.ts +12 -0
  195. package/src/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/consumed_vaas.ts +13 -0
  196. package/src/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/external_address.ts +13 -0
  197. package/src/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/set.ts +12 -0
  198. package/src/contracts/pyth/deserialize.ts +117 -0
  199. package/src/contracts/pyth/event.ts +20 -0
  200. package/src/contracts/pyth/governance.ts +113 -0
  201. package/src/contracts/pyth/governance_action.ts +130 -0
  202. package/src/contracts/pyth/governance_instruction.ts +98 -0
  203. package/src/contracts/pyth/hot_potato_vector.ts +70 -0
  204. package/src/contracts/pyth/i64.ts +94 -0
  205. package/src/contracts/pyth/merkle_tree.ts +41 -0
  206. package/src/contracts/pyth/migrate.ts +29 -0
  207. package/src/contracts/pyth/price.ts +102 -0
  208. package/src/contracts/pyth/price_feed.ts +101 -0
  209. package/src/contracts/pyth/price_identifier.ts +46 -0
  210. package/src/contracts/pyth/price_info.ts +220 -0
  211. package/src/contracts/pyth/price_status.ts +74 -0
  212. package/src/contracts/pyth/pyth.ts +236 -0
  213. package/src/contracts/pyth/set.ts +93 -0
  214. package/src/contracts/pyth/set_data_sources.ts +14 -0
  215. package/src/contracts/pyth/set_fee_recipient.ts +13 -0
  216. package/src/contracts/pyth/set_governance_data_source.ts +16 -0
  217. package/src/contracts/pyth/set_stale_price_threshold.ts +13 -0
  218. package/src/contracts/pyth/set_update_fee.ts +14 -0
  219. package/src/contracts/pyth/setup.ts +12 -0
  220. package/src/contracts/pyth/state.ts +227 -0
  221. package/src/contracts/pyth/version_control.ts +25 -0
  222. package/src/contracts/utils/index.ts +100 -50
  223. package/src/contracts/wormhole/bytes32.ts +12 -0
  224. package/src/contracts/wormhole/consumed_vaas.ts +13 -0
  225. package/src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.ts +12 -0
  226. package/src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts +15 -0
  227. package/src/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts +13 -0
  228. package/src/contracts/wormhole/external_address.ts +13 -0
  229. package/src/contracts/wormhole/fee_collector.ts +15 -0
  230. package/src/contracts/wormhole/set.ts +12 -0
  231. package/src/contracts/wormhole/state.ts +25 -0
  232. package/src/index.ts +17 -3
  233. package/src/pyth/pyth.ts +51 -50
  234. package/src/transactions/deepbook.ts +31 -12
  235. package/src/transactions/deepbookAdmin.ts +3 -3
  236. package/src/transactions/marginAdmin.ts +11 -8
  237. package/src/transactions/marginMaintainer.ts +23 -12
  238. package/src/transactions/marginManager.ts +104 -28
  239. package/src/transactions/marginPool.ts +5 -6
  240. package/src/transactions/marginTPSL.ts +5 -5
  241. package/src/transactions/poolProxy.ts +50 -0
  242. package/src/types/bcs.ts +1 -1
  243. package/src/types/index.ts +19 -2
  244. package/src/utils/config.ts +12 -14
  245. package/src/utils/constants.ts +44 -12
  246. package/src/utils/validation.ts +1 -1
  247. package/dist/cjs/client.d.ts +0 -861
  248. package/dist/cjs/client.js +0 -1982
  249. package/dist/cjs/client.js.map +0 -7
  250. package/dist/cjs/contracts/deepbook/account.d.ts +0 -105
  251. package/dist/cjs/contracts/deepbook/account.js +0 -163
  252. package/dist/cjs/contracts/deepbook/account.js.map +0 -7
  253. package/dist/cjs/contracts/deepbook/balance_manager.d.ts +0 -268
  254. package/dist/cjs/contracts/deepbook/balance_manager.js +0 -361
  255. package/dist/cjs/contracts/deepbook/balance_manager.js.map +0 -7
  256. package/dist/cjs/contracts/deepbook/balances.d.ts +0 -10
  257. package/dist/cjs/contracts/deepbook/balances.js +0 -35
  258. package/dist/cjs/contracts/deepbook/balances.js.map +0 -7
  259. package/dist/cjs/contracts/deepbook/big_vector.d.ts +0 -62
  260. package/dist/cjs/contracts/deepbook/big_vector.js +0 -80
  261. package/dist/cjs/contracts/deepbook/big_vector.js.map +0 -7
  262. package/dist/cjs/contracts/deepbook/book.d.ts +0 -34
  263. package/dist/cjs/contracts/deepbook/book.js +0 -50
  264. package/dist/cjs/contracts/deepbook/book.js.map +0 -7
  265. package/dist/cjs/contracts/deepbook/constants.d.ts +0 -176
  266. package/dist/cjs/contracts/deepbook/constants.js +0 -338
  267. package/dist/cjs/contracts/deepbook/constants.js.map +0 -7
  268. package/dist/cjs/contracts/deepbook/deep_price.d.ts +0 -60
  269. package/dist/cjs/contracts/deepbook/deep_price.js +0 -87
  270. package/dist/cjs/contracts/deepbook/deep_price.js.map +0 -7
  271. package/dist/cjs/contracts/deepbook/deps/std/type_name.d.ts +0 -14
  272. package/dist/cjs/contracts/deepbook/deps/std/type_name.js +0 -42
  273. package/dist/cjs/contracts/deepbook/deps/std/type_name.js.map +0 -7
  274. package/dist/cjs/contracts/deepbook/deps/sui/bag.d.ts +0 -33
  275. package/dist/cjs/contracts/deepbook/deps/sui/bag.js +0 -47
  276. package/dist/cjs/contracts/deepbook/deps/sui/bag.js.map +0 -7
  277. package/dist/cjs/contracts/deepbook/deps/sui/balance.d.ts +0 -9
  278. package/dist/cjs/contracts/deepbook/deps/sui/balance.js +0 -33
  279. package/dist/cjs/contracts/deepbook/deps/sui/balance.js.map +0 -7
  280. package/dist/cjs/contracts/deepbook/deps/sui/object.d.ts +0 -5
  281. package/dist/cjs/contracts/deepbook/deps/sui/object.js +0 -33
  282. package/dist/cjs/contracts/deepbook/deps/sui/object.js.map +0 -7
  283. package/dist/cjs/contracts/deepbook/deps/sui/table.d.ts +0 -28
  284. package/dist/cjs/contracts/deepbook/deps/sui/table.js +0 -47
  285. package/dist/cjs/contracts/deepbook/deps/sui/table.js.map +0 -7
  286. package/dist/cjs/contracts/deepbook/deps/sui/vec_map.d.ts +0 -27
  287. package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js +0 -45
  288. package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js.map +0 -7
  289. package/dist/cjs/contracts/deepbook/deps/sui/vec_set.d.ts +0 -15
  290. package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js +0 -35
  291. package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js.map +0 -7
  292. package/dist/cjs/contracts/deepbook/deps/sui/versioned.d.ts +0 -7
  293. package/dist/cjs/contracts/deepbook/deps/sui/versioned.js +0 -45
  294. package/dist/cjs/contracts/deepbook/deps/sui/versioned.js.map +0 -7
  295. package/dist/cjs/contracts/deepbook/ewma.d.ts +0 -17
  296. package/dist/cjs/contracts/deepbook/ewma.js +0 -39
  297. package/dist/cjs/contracts/deepbook/ewma.js.map +0 -7
  298. package/dist/cjs/contracts/deepbook/fill.d.ts +0 -153
  299. package/dist/cjs/contracts/deepbook/fill.js +0 -251
  300. package/dist/cjs/contracts/deepbook/fill.js.map +0 -7
  301. package/dist/cjs/contracts/deepbook/governance.d.ts +0 -63
  302. package/dist/cjs/contracts/deepbook/governance.js +0 -79
  303. package/dist/cjs/contracts/deepbook/governance.js.map +0 -7
  304. package/dist/cjs/contracts/deepbook/history.d.ts +0 -60
  305. package/dist/cjs/contracts/deepbook/history.js +0 -78
  306. package/dist/cjs/contracts/deepbook/history.js.map +0 -7
  307. package/dist/cjs/contracts/deepbook/math.d.ts +0 -94
  308. package/dist/cjs/contracts/deepbook/math.js +0 -132
  309. package/dist/cjs/contracts/deepbook/math.js.map +0 -7
  310. package/dist/cjs/contracts/deepbook/order.d.ts +0 -135
  311. package/dist/cjs/contracts/deepbook/order.js +0 -218
  312. package/dist/cjs/contracts/deepbook/order.js.map +0 -7
  313. package/dist/cjs/contracts/deepbook/order_info.d.ts +0 -296
  314. package/dist/cjs/contracts/deepbook/order_info.js +0 -386
  315. package/dist/cjs/contracts/deepbook/order_info.js.map +0 -7
  316. package/dist/cjs/contracts/deepbook/order_query.d.ts +0 -85
  317. package/dist/cjs/contracts/deepbook/order_query.js +0 -96
  318. package/dist/cjs/contracts/deepbook/order_query.js.map +0 -7
  319. package/dist/cjs/contracts/deepbook/pool.d.ts +0 -1218
  320. package/dist/cjs/contracts/deepbook/pool.js +0 -1236
  321. package/dist/cjs/contracts/deepbook/pool.js.map +0 -7
  322. package/dist/cjs/contracts/deepbook/registry.d.ts +0 -134
  323. package/dist/cjs/contracts/deepbook/registry.js +0 -182
  324. package/dist/cjs/contracts/deepbook/registry.js.map +0 -7
  325. package/dist/cjs/contracts/deepbook/state.d.ts +0 -117
  326. package/dist/cjs/contracts/deepbook/state.js +0 -104
  327. package/dist/cjs/contracts/deepbook/state.js.map +0 -7
  328. package/dist/cjs/contracts/deepbook/trade_params.d.ts +0 -7
  329. package/dist/cjs/contracts/deepbook/trade_params.js +0 -35
  330. package/dist/cjs/contracts/deepbook/trade_params.js.map +0 -7
  331. package/dist/cjs/contracts/deepbook/vault.d.ts +0 -30
  332. package/dist/cjs/contracts/deepbook/vault.js +0 -65
  333. package/dist/cjs/contracts/deepbook/vault.js.map +0 -7
  334. package/dist/cjs/contracts/utils/index.d.ts +0 -25
  335. package/dist/cjs/contracts/utils/index.js +0 -148
  336. package/dist/cjs/contracts/utils/index.js.map +0 -7
  337. package/dist/cjs/index.d.ts +0 -23
  338. package/dist/cjs/index.js +0 -81
  339. package/dist/cjs/index.js.map +0 -7
  340. package/dist/cjs/package.json +0 -4
  341. package/dist/cjs/pyth/PriceServiceConnection.d.ts +0 -26
  342. package/dist/cjs/pyth/PriceServiceConnection.js +0 -68
  343. package/dist/cjs/pyth/PriceServiceConnection.js.map +0 -7
  344. package/dist/cjs/pyth/pyth-helpers.d.ts +0 -7
  345. package/dist/cjs/pyth/pyth-helpers.js +0 -36
  346. package/dist/cjs/pyth/pyth-helpers.js.map +0 -7
  347. package/dist/cjs/pyth/pyth.d.ts +0 -65
  348. package/dist/cjs/pyth/pyth.js +0 -269
  349. package/dist/cjs/pyth/pyth.js.map +0 -7
  350. package/dist/cjs/transactions/balanceManager.d.ts +0 -168
  351. package/dist/cjs/transactions/balanceManager.js +0 -384
  352. package/dist/cjs/transactions/balanceManager.js.map +0 -7
  353. package/dist/cjs/transactions/deepbook.d.ts +0 -477
  354. package/dist/cjs/transactions/deepbook.js +0 -1335
  355. package/dist/cjs/transactions/deepbook.js.map +0 -7
  356. package/dist/cjs/transactions/deepbookAdmin.d.ts +0 -105
  357. package/dist/cjs/transactions/deepbookAdmin.js +0 -334
  358. package/dist/cjs/transactions/deepbookAdmin.js.map +0 -7
  359. package/dist/cjs/transactions/flashLoans.d.ts +0 -56
  360. package/dist/cjs/transactions/flashLoans.js +0 -124
  361. package/dist/cjs/transactions/flashLoans.js.map +0 -7
  362. package/dist/cjs/transactions/governance.d.ts +0 -42
  363. package/dist/cjs/transactions/governance.js +0 -135
  364. package/dist/cjs/transactions/governance.js.map +0 -7
  365. package/dist/cjs/transactions/marginAdmin.d.ts +0 -133
  366. package/dist/cjs/transactions/marginAdmin.js +0 -393
  367. package/dist/cjs/transactions/marginAdmin.js.map +0 -7
  368. package/dist/cjs/transactions/marginLiquidations.d.ts +0 -61
  369. package/dist/cjs/transactions/marginLiquidations.js +0 -173
  370. package/dist/cjs/transactions/marginLiquidations.js.map +0 -7
  371. package/dist/cjs/transactions/marginMaintainer.d.ts +0 -80
  372. package/dist/cjs/transactions/marginMaintainer.js +0 -251
  373. package/dist/cjs/transactions/marginMaintainer.js.map +0 -7
  374. package/dist/cjs/transactions/marginManager.d.ts +0 -236
  375. package/dist/cjs/transactions/marginManager.js +0 -688
  376. package/dist/cjs/transactions/marginManager.js.map +0 -7
  377. package/dist/cjs/transactions/marginPool.d.ts +0 -134
  378. package/dist/cjs/transactions/marginPool.js +0 -330
  379. package/dist/cjs/transactions/marginPool.js.map +0 -7
  380. package/dist/cjs/transactions/marginRegistry.d.ts +0 -94
  381. package/dist/cjs/transactions/marginRegistry.js +0 -221
  382. package/dist/cjs/transactions/marginRegistry.js.map +0 -7
  383. package/dist/cjs/transactions/marginTPSL.d.ts +0 -93
  384. package/dist/cjs/transactions/marginTPSL.js +0 -286
  385. package/dist/cjs/transactions/marginTPSL.js.map +0 -7
  386. package/dist/cjs/transactions/poolProxy.d.ts +0 -104
  387. package/dist/cjs/transactions/poolProxy.js +0 -435
  388. package/dist/cjs/transactions/poolProxy.js.map +0 -7
  389. package/dist/cjs/types/bcs.d.ts +0 -5
  390. package/dist/cjs/types/bcs.js +0 -33
  391. package/dist/cjs/types/bcs.js.map +0 -7
  392. package/dist/cjs/types/index.d.ts +0 -218
  393. package/dist/cjs/types/index.js +0 -38
  394. package/dist/cjs/types/index.js.map +0 -7
  395. package/dist/cjs/utils/config.d.ts +0 -65
  396. package/dist/cjs/utils/config.js +0 -144
  397. package/dist/cjs/utils/config.js.map +0 -7
  398. package/dist/cjs/utils/constants.d.ts +0 -76
  399. package/dist/cjs/utils/constants.js +0 -382
  400. package/dist/cjs/utils/constants.js.map +0 -7
  401. package/dist/cjs/utils/errors.d.ts +0 -42
  402. package/dist/cjs/utils/errors.js +0 -70
  403. package/dist/cjs/utils/errors.js.map +0 -7
  404. package/dist/cjs/utils/validation.js +0 -67
  405. package/dist/cjs/utils/validation.js.map +0 -7
  406. package/dist/esm/client.d.ts +0 -861
  407. package/dist/esm/client.js +0 -1967
  408. package/dist/esm/client.js.map +0 -7
  409. package/dist/esm/contracts/deepbook/account.d.ts +0 -105
  410. package/dist/esm/contracts/deepbook/account.js +0 -133
  411. package/dist/esm/contracts/deepbook/account.js.map +0 -7
  412. package/dist/esm/contracts/deepbook/balance_manager.d.ts +0 -268
  413. package/dist/esm/contracts/deepbook/balance_manager.js +0 -331
  414. package/dist/esm/contracts/deepbook/balance_manager.js.map +0 -7
  415. package/dist/esm/contracts/deepbook/balances.d.ts +0 -10
  416. package/dist/esm/contracts/deepbook/balances.js +0 -15
  417. package/dist/esm/contracts/deepbook/balances.js.map +0 -7
  418. package/dist/esm/contracts/deepbook/big_vector.d.ts +0 -62
  419. package/dist/esm/contracts/deepbook/big_vector.js +0 -50
  420. package/dist/esm/contracts/deepbook/big_vector.js.map +0 -7
  421. package/dist/esm/contracts/deepbook/book.d.ts +0 -34
  422. package/dist/esm/contracts/deepbook/book.js +0 -20
  423. package/dist/esm/contracts/deepbook/book.js.map +0 -7
  424. package/dist/esm/contracts/deepbook/constants.d.ts +0 -176
  425. package/dist/esm/contracts/deepbook/constants.js +0 -318
  426. package/dist/esm/contracts/deepbook/constants.js.map +0 -7
  427. package/dist/esm/contracts/deepbook/deep_price.d.ts +0 -60
  428. package/dist/esm/contracts/deepbook/deep_price.js +0 -67
  429. package/dist/esm/contracts/deepbook/deep_price.js.map +0 -7
  430. package/dist/esm/contracts/deepbook/deps/std/type_name.d.ts +0 -14
  431. package/dist/esm/contracts/deepbook/deps/std/type_name.js +0 -22
  432. package/dist/esm/contracts/deepbook/deps/std/type_name.js.map +0 -7
  433. package/dist/esm/contracts/deepbook/deps/sui/bag.d.ts +0 -33
  434. package/dist/esm/contracts/deepbook/deps/sui/bag.js +0 -17
  435. package/dist/esm/contracts/deepbook/deps/sui/bag.js.map +0 -7
  436. package/dist/esm/contracts/deepbook/deps/sui/balance.d.ts +0 -9
  437. package/dist/esm/contracts/deepbook/deps/sui/balance.js +0 -13
  438. package/dist/esm/contracts/deepbook/deps/sui/balance.js.map +0 -7
  439. package/dist/esm/contracts/deepbook/deps/sui/object.d.ts +0 -5
  440. package/dist/esm/contracts/deepbook/deps/sui/object.js +0 -13
  441. package/dist/esm/contracts/deepbook/deps/sui/object.js.map +0 -7
  442. package/dist/esm/contracts/deepbook/deps/sui/table.d.ts +0 -28
  443. package/dist/esm/contracts/deepbook/deps/sui/table.js +0 -17
  444. package/dist/esm/contracts/deepbook/deps/sui/table.js.map +0 -7
  445. package/dist/esm/contracts/deepbook/deps/sui/vec_map.d.ts +0 -27
  446. package/dist/esm/contracts/deepbook/deps/sui/vec_map.js +0 -25
  447. package/dist/esm/contracts/deepbook/deps/sui/vec_map.js.map +0 -7
  448. package/dist/esm/contracts/deepbook/deps/sui/vec_set.d.ts +0 -15
  449. package/dist/esm/contracts/deepbook/deps/sui/vec_set.js +0 -15
  450. package/dist/esm/contracts/deepbook/deps/sui/vec_set.js.map +0 -7
  451. package/dist/esm/contracts/deepbook/deps/sui/versioned.d.ts +0 -7
  452. package/dist/esm/contracts/deepbook/deps/sui/versioned.js +0 -15
  453. package/dist/esm/contracts/deepbook/deps/sui/versioned.js.map +0 -7
  454. package/dist/esm/contracts/deepbook/ewma.d.ts +0 -17
  455. package/dist/esm/contracts/deepbook/ewma.js +0 -19
  456. package/dist/esm/contracts/deepbook/ewma.js.map +0 -7
  457. package/dist/esm/contracts/deepbook/fill.d.ts +0 -153
  458. package/dist/esm/contracts/deepbook/fill.js +0 -221
  459. package/dist/esm/contracts/deepbook/fill.js.map +0 -7
  460. package/dist/esm/contracts/deepbook/governance.d.ts +0 -63
  461. package/dist/esm/contracts/deepbook/governance.js +0 -49
  462. package/dist/esm/contracts/deepbook/governance.js.map +0 -7
  463. package/dist/esm/contracts/deepbook/history.d.ts +0 -60
  464. package/dist/esm/contracts/deepbook/history.js +0 -48
  465. package/dist/esm/contracts/deepbook/history.js.map +0 -7
  466. package/dist/esm/contracts/deepbook/math.d.ts +0 -94
  467. package/dist/esm/contracts/deepbook/math.js +0 -112
  468. package/dist/esm/contracts/deepbook/math.js.map +0 -7
  469. package/dist/esm/contracts/deepbook/order.d.ts +0 -135
  470. package/dist/esm/contracts/deepbook/order.js +0 -188
  471. package/dist/esm/contracts/deepbook/order.js.map +0 -7
  472. package/dist/esm/contracts/deepbook/order_info.d.ts +0 -296
  473. package/dist/esm/contracts/deepbook/order_info.js +0 -356
  474. package/dist/esm/contracts/deepbook/order_info.js.map +0 -7
  475. package/dist/esm/contracts/deepbook/order_query.d.ts +0 -85
  476. package/dist/esm/contracts/deepbook/order_query.js +0 -66
  477. package/dist/esm/contracts/deepbook/order_query.js.map +0 -7
  478. package/dist/esm/contracts/deepbook/pool.d.ts +0 -1218
  479. package/dist/esm/contracts/deepbook/pool.js +0 -1206
  480. package/dist/esm/contracts/deepbook/pool.js.map +0 -7
  481. package/dist/esm/contracts/deepbook/registry.d.ts +0 -134
  482. package/dist/esm/contracts/deepbook/registry.js +0 -152
  483. package/dist/esm/contracts/deepbook/registry.js.map +0 -7
  484. package/dist/esm/contracts/deepbook/state.d.ts +0 -117
  485. package/dist/esm/contracts/deepbook/state.js +0 -74
  486. package/dist/esm/contracts/deepbook/state.js.map +0 -7
  487. package/dist/esm/contracts/deepbook/trade_params.d.ts +0 -7
  488. package/dist/esm/contracts/deepbook/trade_params.js +0 -15
  489. package/dist/esm/contracts/deepbook/trade_params.js.map +0 -7
  490. package/dist/esm/contracts/deepbook/vault.d.ts +0 -30
  491. package/dist/esm/contracts/deepbook/vault.js +0 -35
  492. package/dist/esm/contracts/deepbook/vault.js.map +0 -7
  493. package/dist/esm/contracts/utils/index.d.ts +0 -25
  494. package/dist/esm/contracts/utils/index.js +0 -128
  495. package/dist/esm/contracts/utils/index.js.map +0 -7
  496. package/dist/esm/index.d.ts +0 -23
  497. package/dist/esm/index.js +0 -81
  498. package/dist/esm/index.js.map +0 -7
  499. package/dist/esm/package.json +0 -4
  500. package/dist/esm/pyth/PriceServiceConnection.d.ts +0 -26
  501. package/dist/esm/pyth/PriceServiceConnection.js +0 -38
  502. package/dist/esm/pyth/PriceServiceConnection.js.map +0 -7
  503. package/dist/esm/pyth/pyth-helpers.d.ts +0 -7
  504. package/dist/esm/pyth/pyth-helpers.js +0 -16
  505. package/dist/esm/pyth/pyth-helpers.js.map +0 -7
  506. package/dist/esm/pyth/pyth.d.ts +0 -65
  507. package/dist/esm/pyth/pyth.js +0 -249
  508. package/dist/esm/pyth/pyth.js.map +0 -7
  509. package/dist/esm/transactions/balanceManager.d.ts +0 -168
  510. package/dist/esm/transactions/balanceManager.js +0 -364
  511. package/dist/esm/transactions/balanceManager.js.map +0 -7
  512. package/dist/esm/transactions/deepbook.d.ts +0 -477
  513. package/dist/esm/transactions/deepbook.js +0 -1321
  514. package/dist/esm/transactions/deepbook.js.map +0 -7
  515. package/dist/esm/transactions/deepbookAdmin.d.ts +0 -105
  516. package/dist/esm/transactions/deepbookAdmin.js +0 -314
  517. package/dist/esm/transactions/deepbookAdmin.js.map +0 -7
  518. package/dist/esm/transactions/flashLoans.d.ts +0 -56
  519. package/dist/esm/transactions/flashLoans.js +0 -104
  520. package/dist/esm/transactions/flashLoans.js.map +0 -7
  521. package/dist/esm/transactions/governance.d.ts +0 -42
  522. package/dist/esm/transactions/governance.js +0 -115
  523. package/dist/esm/transactions/governance.js.map +0 -7
  524. package/dist/esm/transactions/marginAdmin.d.ts +0 -133
  525. package/dist/esm/transactions/marginAdmin.js +0 -373
  526. package/dist/esm/transactions/marginAdmin.js.map +0 -7
  527. package/dist/esm/transactions/marginLiquidations.d.ts +0 -61
  528. package/dist/esm/transactions/marginLiquidations.js +0 -153
  529. package/dist/esm/transactions/marginLiquidations.js.map +0 -7
  530. package/dist/esm/transactions/marginMaintainer.d.ts +0 -80
  531. package/dist/esm/transactions/marginMaintainer.js +0 -231
  532. package/dist/esm/transactions/marginMaintainer.js.map +0 -7
  533. package/dist/esm/transactions/marginManager.d.ts +0 -236
  534. package/dist/esm/transactions/marginManager.js +0 -668
  535. package/dist/esm/transactions/marginManager.js.map +0 -7
  536. package/dist/esm/transactions/marginPool.d.ts +0 -134
  537. package/dist/esm/transactions/marginPool.js +0 -310
  538. package/dist/esm/transactions/marginPool.js.map +0 -7
  539. package/dist/esm/transactions/marginRegistry.d.ts +0 -94
  540. package/dist/esm/transactions/marginRegistry.js +0 -201
  541. package/dist/esm/transactions/marginRegistry.js.map +0 -7
  542. package/dist/esm/transactions/marginTPSL.d.ts +0 -93
  543. package/dist/esm/transactions/marginTPSL.js +0 -266
  544. package/dist/esm/transactions/marginTPSL.js.map +0 -7
  545. package/dist/esm/transactions/poolProxy.d.ts +0 -104
  546. package/dist/esm/transactions/poolProxy.js +0 -415
  547. package/dist/esm/transactions/poolProxy.js.map +0 -7
  548. package/dist/esm/types/bcs.d.ts +0 -5
  549. package/dist/esm/types/bcs.js +0 -13
  550. package/dist/esm/types/bcs.js.map +0 -7
  551. package/dist/esm/types/index.d.ts +0 -218
  552. package/dist/esm/types/index.js +0 -18
  553. package/dist/esm/types/index.js.map +0 -7
  554. package/dist/esm/utils/config.d.ts +0 -65
  555. package/dist/esm/utils/config.js +0 -135
  556. package/dist/esm/utils/config.js.map +0 -7
  557. package/dist/esm/utils/constants.d.ts +0 -76
  558. package/dist/esm/utils/constants.js +0 -362
  559. package/dist/esm/utils/constants.js.map +0 -7
  560. package/dist/esm/utils/errors.d.ts +0 -42
  561. package/dist/esm/utils/errors.js +0 -50
  562. package/dist/esm/utils/errors.js.map +0 -7
  563. package/dist/esm/utils/validation.d.ts +0 -50
  564. package/dist/esm/utils/validation.js +0 -47
  565. package/dist/esm/utils/validation.js.map +0 -7
  566. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  567. package/dist/tsconfig.tsbuildinfo +0 -1
  568. package/src/contracts/deepbook/deps/sui/object.ts +0 -14
package/src/client.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { bcs } from '@haneullabs/haneul/bcs';
4
4
  import { Account, Order, OrderDeepPrice, VecSet } from './types/bcs.js';
5
- import type { HaneulClient } from '@haneullabs/haneul/client';
5
+ import type { ClientWithCoreApi, HaneulClientRegistration, HaneulClientTypes } from '@haneullabs/haneul/client';
6
6
  import { Transaction } from '@haneullabs/haneul/transactions';
7
7
  import { normalizeHaneulAddress } from '@haneullabs/haneul/utils';
8
8
 
@@ -13,7 +13,6 @@ import { FlashLoanContract } from './transactions/flashLoans.js';
13
13
  import { GovernanceContract } from './transactions/governance.js';
14
14
  import type {
15
15
  BalanceManager,
16
- Environment,
17
16
  MarginManager,
18
17
  CanPlaceLimitOrderParams,
19
18
  CanPlaceMarketOrderParams,
@@ -33,14 +32,50 @@ import { MarginRegistryContract } from './transactions/marginRegistry.js';
33
32
  import { MarginLiquidationsContract } from './transactions/marginLiquidations.js';
34
33
  import { HaneulPriceServiceConnection } from './pyth/pyth.js';
35
34
  import { HaneulPythClient } from './pyth/pyth.js';
35
+ import { PriceInfoObject } from './contracts/pyth/price_info.js';
36
36
  import { PoolProxyContract } from './transactions/poolProxy.js';
37
37
  import { MarginTPSLContract } from './transactions/marginTPSL.js';
38
38
 
39
+ export interface DeepBookCompatibleClient extends ClientWithCoreApi {}
40
+
41
+ export interface DeepBookOptions<Name = 'deepbook'> {
42
+ address: string;
43
+ balanceManagers?: { [key: string]: BalanceManager };
44
+ marginManagers?: { [key: string]: MarginManager };
45
+ coins?: CoinMap;
46
+ pools?: PoolMap;
47
+ adminCap?: string;
48
+ marginAdminCap?: string;
49
+ marginMaintainerCap?: string;
50
+ name?: Name;
51
+ }
52
+
53
+ export interface DeepBookClientOptions extends DeepBookOptions {
54
+ client: DeepBookCompatibleClient;
55
+ network: HaneulClientTypes.Network;
56
+ }
57
+
58
+ export function deepbook<Name extends string = 'deepbook'>({
59
+ name = 'deepbook' as Name,
60
+ ...options
61
+ }: DeepBookOptions<Name>): HaneulClientRegistration<DeepBookCompatibleClient, Name, DeepBookClient> {
62
+ return {
63
+ name,
64
+ register: (client) => {
65
+ return new DeepBookClient({
66
+ client,
67
+ network: client.network,
68
+ ...options,
69
+ });
70
+ },
71
+ };
72
+ }
73
+
39
74
  /**
40
75
  * DeepBookClient class for managing DeepBook operations.
41
76
  */
42
77
  export class DeepBookClient {
43
- client: HaneulClient;
78
+ #client: DeepBookCompatibleClient;
44
79
  #config: DeepBookConfig;
45
80
  #address: string;
46
81
  balanceManager: BalanceManagerContract;
@@ -58,21 +93,12 @@ export class DeepBookClient {
58
93
  marginTPSL: MarginTPSLContract;
59
94
 
60
95
  /**
61
- * @param {HaneulClient} client HaneulClient instance
62
- * @param {string} address Address of the client
63
- * @param {Environment} env Environment configuration
64
- * @param {Object.<string, BalanceManager>} [balanceManagers] Optional initial BalanceManager map
65
- * @param {Object.<string, MarginManager>} [marginManagers] Optional initial MarginManager map
66
- * @param {CoinMap} [coins] Optional initial CoinMap
67
- * @param {PoolMap} [pools] Optional initial PoolMap
68
- * @param {string} [adminCap] Optional admin capability
69
- * @param {string} [marginAdminCap] Optional margin admin capability
70
- * @param {string} [marginMaintainerCap] Optional margin maintainer capability
96
+ * Creates a new DeepBookClient instance
71
97
  */
72
98
  constructor({
73
99
  client,
74
100
  address,
75
- env,
101
+ network,
76
102
  balanceManagers,
77
103
  marginManagers,
78
104
  coins,
@@ -80,23 +106,12 @@ export class DeepBookClient {
80
106
  adminCap,
81
107
  marginAdminCap,
82
108
  marginMaintainerCap,
83
- }: {
84
- client: HaneulClient;
85
- address: string;
86
- env: Environment;
87
- balanceManagers?: { [key: string]: BalanceManager };
88
- marginManagers?: { [key: string]: MarginManager };
89
- coins?: CoinMap;
90
- pools?: PoolMap;
91
- adminCap?: string;
92
- marginAdminCap?: string;
93
- marginMaintainerCap?: string;
94
- }) {
95
- this.client = client;
109
+ }: DeepBookClientOptions) {
110
+ this.#client = client;
96
111
  this.#address = normalizeHaneulAddress(address);
97
112
  this.#config = new DeepBookConfig({
98
113
  address: this.#address,
99
- env,
114
+ network,
100
115
  balanceManagers,
101
116
  marginManagers,
102
117
  coins,
@@ -131,13 +146,45 @@ export class DeepBookClient {
131
146
  const coin = this.#config.getCoin(coinKey);
132
147
 
133
148
  tx.add(this.balanceManager.checkManagerBalance(managerKey, coinKey));
134
- const res = await this.client.devInspectTransactionBlock({
135
- sender: this.#address,
136
- transactionBlock: tx,
149
+ const res = await this.#client.core.simulateTransaction({
150
+ transaction: tx,
151
+ include: { commandResults: true, effects: true },
152
+ });
153
+
154
+ const bytes = res.commandResults![0].returnValues[0].bcs;
155
+ const parsed_balance = bcs.U64.parse(bytes);
156
+ const balanceNumber = Number(parsed_balance);
157
+ const adjusted_balance = balanceNumber / coin.scalar;
158
+
159
+ return {
160
+ coinType: coin.type,
161
+ balance: Number(adjusted_balance.toFixed(9)),
162
+ };
163
+ }
164
+
165
+ /**
166
+ * @description Check the balance of a BalanceManager by its address directly
167
+ * @param {string} managerAddress The on-chain address of the BalanceManager
168
+ * @param {string} coinKey Key of the coin
169
+ * @returns {Promise<{ coinType: string, balance: number }>} An object with coin type and balance
170
+ */
171
+ async checkManagerBalanceWithAddress(managerAddress: string, coinKey: string) {
172
+ const tx = new Transaction();
173
+ const coin = this.#config.getCoin(coinKey);
174
+
175
+ tx.moveCall({
176
+ target: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance`,
177
+ arguments: [tx.object(managerAddress)],
178
+ typeArguments: [coin.type],
179
+ });
180
+
181
+ const res = await this.#client.core.simulateTransaction({
182
+ transaction: tx,
183
+ include: { commandResults: true, effects: true },
137
184
  });
138
185
 
139
- const bytes = res.results![0].returnValues![0][0];
140
- const parsed_balance = bcs.U64.parse(new Uint8Array(bytes));
186
+ const bytes = res.commandResults![0].returnValues[0].bcs;
187
+ const parsed_balance = bcs.U64.parse(bytes);
141
188
  const balanceNumber = Number(parsed_balance);
142
189
  const adjusted_balance = balanceNumber / coin.scalar;
143
190
 
@@ -147,6 +194,70 @@ export class DeepBookClient {
147
194
  };
148
195
  }
149
196
 
197
+ /**
198
+ * @description Check multiple coin balances for multiple balance managers by address in a single dry run call
199
+ * @param {string[]} managerAddresses The on-chain addresses of the BalanceManagers
200
+ * @param {string[]} coinKeys Keys of the coins to check balances for
201
+ * @returns {Promise<Record<string, Record<string, number>>>} Object keyed by manager address, mapping coinType to balance
202
+ */
203
+ async checkManagerBalancesWithAddress(managerAddresses: string[], coinKeys: string[]) {
204
+ if (managerAddresses.length === 0 || coinKeys.length === 0) {
205
+ return {};
206
+ }
207
+
208
+ const tx = new Transaction();
209
+ const coins = coinKeys.map((coinKey) => this.#config.getCoin(coinKey));
210
+
211
+ for (const managerAddress of managerAddresses) {
212
+ for (const coin of coins) {
213
+ tx.moveCall({
214
+ target: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance`,
215
+ arguments: [tx.object(managerAddress)],
216
+ typeArguments: [coin.type],
217
+ });
218
+ }
219
+ }
220
+
221
+ const res = await this.#client.core.simulateTransaction({
222
+ transaction: tx,
223
+ include: { commandResults: true, effects: true },
224
+ });
225
+
226
+ if (res.FailedTransaction) {
227
+ throw new Error(
228
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
229
+ );
230
+ }
231
+
232
+ if (!res.commandResults) {
233
+ throw new Error('Failed to get manager balances: No command results');
234
+ }
235
+
236
+ const results: Record<string, Record<string, number>> = {};
237
+
238
+ for (let m = 0; m < managerAddresses.length; m++) {
239
+ const managerAddress = managerAddresses[m];
240
+ const managerBalances: Record<string, number> = {};
241
+
242
+ for (let c = 0; c < coins.length; c++) {
243
+ const coin = coins[c];
244
+ const commandResult = res.commandResults[m * coins.length + c];
245
+
246
+ if (!commandResult || !commandResult.returnValues) {
247
+ throw new Error(`Failed to get balance for ${coin.type}: No return values`);
248
+ }
249
+
250
+ const bytes = commandResult.returnValues[0].bcs;
251
+ const parsed_balance = bcs.U64.parse(bytes);
252
+ managerBalances[coin.type] = Number((Number(parsed_balance) / coin.scalar).toFixed(9));
253
+ }
254
+
255
+ results[managerAddress] = managerBalances;
256
+ }
257
+
258
+ return results;
259
+ }
260
+
150
261
  /**
151
262
  * @description Check if a pool is whitelisted
152
263
  * @param {string} poolKey Key of the pool
@@ -156,13 +267,13 @@ export class DeepBookClient {
156
267
  const tx = new Transaction();
157
268
 
158
269
  tx.add(this.deepBook.whitelisted(poolKey));
159
- const res = await this.client.devInspectTransactionBlock({
160
- sender: normalizeHaneulAddress(this.#address),
161
- transactionBlock: tx,
270
+ const res = await this.#client.core.simulateTransaction({
271
+ transaction: tx,
272
+ include: { commandResults: true, effects: true },
162
273
  });
163
274
 
164
- const bytes = res.results![0].returnValues![0][0];
165
- const whitelisted = bcs.Bool.parse(new Uint8Array(bytes));
275
+ const bytes = res.commandResults![0].returnValues[0].bcs;
276
+ const whitelisted = bcs.Bool.parse(bytes);
166
277
 
167
278
  return whitelisted;
168
279
  }
@@ -181,14 +292,14 @@ export class DeepBookClient {
181
292
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
182
293
 
183
294
  tx.add(this.deepBook.getQuoteQuantityOut(poolKey, baseQuantity));
184
- const res = await this.client.devInspectTransactionBlock({
185
- sender: normalizeHaneulAddress(this.#address),
186
- transactionBlock: tx,
295
+ const res = await this.#client.core.simulateTransaction({
296
+ transaction: tx,
297
+ include: { commandResults: true, effects: true },
187
298
  });
188
299
 
189
- const baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
190
- const quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
191
- const deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
300
+ const baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
301
+ const quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
302
+ const deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
192
303
 
193
304
  return {
194
305
  baseQuantity,
@@ -212,14 +323,14 @@ export class DeepBookClient {
212
323
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
213
324
 
214
325
  tx.add(this.deepBook.getBaseQuantityOut(poolKey, quoteQuantity));
215
- const res = await this.client.devInspectTransactionBlock({
216
- sender: normalizeHaneulAddress(this.#address),
217
- transactionBlock: tx,
326
+ const res = await this.#client.core.simulateTransaction({
327
+ transaction: tx,
328
+ include: { commandResults: true, effects: true },
218
329
  });
219
330
 
220
- const baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
221
- const quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
222
- const deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
331
+ const baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
332
+ const quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
333
+ const deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
223
334
 
224
335
  return {
225
336
  quoteQuantity: quoteQuantity,
@@ -244,14 +355,14 @@ export class DeepBookClient {
244
355
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
245
356
 
246
357
  tx.add(this.deepBook.getQuantityOut(poolKey, baseQuantity, quoteQuantity));
247
- const res = await this.client.devInspectTransactionBlock({
248
- sender: normalizeHaneulAddress(this.#address),
249
- transactionBlock: tx,
358
+ const res = await this.#client.core.simulateTransaction({
359
+ transaction: tx,
360
+ include: { commandResults: true, effects: true },
250
361
  });
251
362
 
252
- const baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
253
- const quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
254
- const deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
363
+ const baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
364
+ const quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
365
+ const deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
255
366
 
256
367
  return {
257
368
  baseQuantity,
@@ -272,12 +383,12 @@ export class DeepBookClient {
272
383
  const tx = new Transaction();
273
384
 
274
385
  tx.add(this.deepBook.accountOpenOrders(poolKey, managerKey));
275
- const res = await this.client.devInspectTransactionBlock({
276
- sender: normalizeHaneulAddress(this.#address),
277
- transactionBlock: tx,
386
+ const res = await this.#client.core.simulateTransaction({
387
+ transaction: tx,
388
+ include: { commandResults: true, effects: true },
278
389
  });
279
390
 
280
- const order_ids = res.results![0].returnValues![0][0];
391
+ const order_ids = res.commandResults![0].returnValues[0].bcs;
281
392
 
282
393
  return VecSet(bcs.u128()).parse(new Uint8Array(order_ids)).contents;
283
394
  }
@@ -292,13 +403,13 @@ export class DeepBookClient {
292
403
  const tx = new Transaction();
293
404
 
294
405
  tx.add(this.deepBook.getOrder(poolKey, orderId));
295
- const res = await this.client.devInspectTransactionBlock({
296
- sender: normalizeHaneulAddress(this.#address),
297
- transactionBlock: tx,
406
+ const res = await this.#client.core.simulateTransaction({
407
+ transaction: tx,
408
+ include: { commandResults: true, effects: true },
298
409
  });
299
410
 
300
411
  try {
301
- const orderInformation = res.results![0].returnValues![0][0];
412
+ const orderInformation = res.commandResults![0].returnValues[0].bcs;
302
413
  return Order.parse(new Uint8Array(orderInformation));
303
414
  } catch {
304
415
  return null;
@@ -314,13 +425,13 @@ export class DeepBookClient {
314
425
  async getOrderNormalized(poolKey: string, orderId: string) {
315
426
  const tx = new Transaction();
316
427
  tx.add(this.deepBook.getOrder(poolKey, orderId));
317
- const res = await this.client.devInspectTransactionBlock({
318
- sender: normalizeHaneulAddress(this.#address),
319
- transactionBlock: tx,
428
+ const res = await this.#client.core.simulateTransaction({
429
+ transaction: tx,
430
+ include: { commandResults: true, effects: true },
320
431
  });
321
432
 
322
433
  try {
323
- const orderInformation = res.results![0].returnValues![0][0];
434
+ const orderInformation = res.commandResults![0].returnValues[0].bcs;
324
435
  const orderInfo = Order.parse(new Uint8Array(orderInformation));
325
436
 
326
437
  if (!orderInfo) {
@@ -362,13 +473,13 @@ export class DeepBookClient {
362
473
  const tx = new Transaction();
363
474
 
364
475
  tx.add(this.deepBook.getOrders(poolKey, orderIds));
365
- const res = await this.client.devInspectTransactionBlock({
366
- sender: normalizeHaneulAddress(this.#address),
367
- transactionBlock: tx,
476
+ const res = await this.#client.core.simulateTransaction({
477
+ transaction: tx,
478
+ include: { commandResults: true, effects: true },
368
479
  });
369
480
 
370
481
  try {
371
- const orderInformation = res.results![0].returnValues![0][0];
482
+ const orderInformation = res.commandResults![0].returnValues[0].bcs;
372
483
  return bcs.vector(Order).parse(new Uint8Array(orderInformation));
373
484
  } catch {
374
485
  return null;
@@ -391,14 +502,14 @@ export class DeepBookClient {
391
502
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
392
503
 
393
504
  tx.add(this.deepBook.getLevel2Range(poolKey, priceLow, priceHigh, isBid));
394
- const res = await this.client.devInspectTransactionBlock({
395
- sender: normalizeHaneulAddress(this.#address),
396
- transactionBlock: tx,
505
+ const res = await this.#client.core.simulateTransaction({
506
+ transaction: tx,
507
+ include: { commandResults: true, effects: true },
397
508
  });
398
509
 
399
- const prices = res.results![0].returnValues![0][0];
510
+ const prices = res.commandResults![0].returnValues[0].bcs;
400
511
  const parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(prices));
401
- const quantities = res.results![0].returnValues![1][0];
512
+ const quantities = res.commandResults![0].returnValues[1].bcs;
402
513
  const parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(quantities));
403
514
 
404
515
  return {
@@ -425,19 +536,19 @@ export class DeepBookClient {
425
536
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
426
537
 
427
538
  tx.add(this.deepBook.getLevel2TicksFromMid(poolKey, ticks));
428
- const res = await this.client.devInspectTransactionBlock({
429
- sender: normalizeHaneulAddress(this.#address),
430
- transactionBlock: tx,
539
+ const res = await this.#client.core.simulateTransaction({
540
+ transaction: tx,
541
+ include: { commandResults: true, effects: true },
431
542
  });
432
543
 
433
- const bid_prices = res.results![0].returnValues![0][0];
544
+ const bid_prices = res.commandResults![0].returnValues[0].bcs;
434
545
  const bid_parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(bid_prices));
435
- const bid_quantities = res.results![0].returnValues![1][0];
546
+ const bid_quantities = res.commandResults![0].returnValues[1].bcs;
436
547
  const bid_parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(bid_quantities));
437
548
 
438
- const ask_prices = res.results![0].returnValues![2][0];
549
+ const ask_prices = res.commandResults![0].returnValues[2].bcs;
439
550
  const ask_parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(ask_prices));
440
- const ask_quantities = res.results![0].returnValues![3][0];
551
+ const ask_quantities = res.commandResults![0].returnValues[3].bcs;
441
552
  const ask_parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(ask_quantities));
442
553
 
443
554
  return {
@@ -469,14 +580,14 @@ export class DeepBookClient {
469
580
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
470
581
 
471
582
  tx.add(this.deepBook.vaultBalances(poolKey));
472
- const res = await this.client.devInspectTransactionBlock({
473
- sender: normalizeHaneulAddress(this.#address),
474
- transactionBlock: tx,
583
+ const res = await this.#client.core.simulateTransaction({
584
+ transaction: tx,
585
+ include: { commandResults: true, effects: true },
475
586
  });
476
587
 
477
- const baseInVault = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
478
- const quoteInVault = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
479
- const deepInVault = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
588
+ const baseInVault = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
589
+ const quoteInVault = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
590
+ const deepInVault = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
480
591
 
481
592
  return {
482
593
  base: Number((baseInVault / baseScalar).toFixed(9)),
@@ -495,12 +606,12 @@ export class DeepBookClient {
495
606
  const tx = new Transaction();
496
607
  tx.add(this.deepBook.getPoolIdByAssets(baseType, quoteType));
497
608
 
498
- const res = await this.client.devInspectTransactionBlock({
499
- sender: normalizeHaneulAddress(this.#address),
500
- transactionBlock: tx,
609
+ const res = await this.#client.core.simulateTransaction({
610
+ transaction: tx,
611
+ include: { commandResults: true, effects: true },
501
612
  });
502
613
 
503
- const address = bcs.Address.parse(new Uint8Array(res.results![0].returnValues![0][0]));
614
+ const address = bcs.Address.parse(res.commandResults![0].returnValues[0].bcs);
504
615
 
505
616
  return address;
506
617
  }
@@ -518,13 +629,13 @@ export class DeepBookClient {
518
629
  const baseCoin = this.#config.getCoin(pool.baseCoin);
519
630
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
520
631
 
521
- const res = await this.client.devInspectTransactionBlock({
522
- sender: normalizeHaneulAddress(this.#address),
523
- transactionBlock: tx,
632
+ const res = await this.#client.core.simulateTransaction({
633
+ transaction: tx,
634
+ include: { commandResults: true, effects: true },
524
635
  });
525
636
 
526
- const bytes = res.results![0].returnValues![0][0];
527
- const parsed_mid_price = Number(bcs.U64.parse(new Uint8Array(bytes)));
637
+ const bytes = res.commandResults![0].returnValues[0].bcs;
638
+ const parsed_mid_price = Number(bcs.U64.parse(bytes));
528
639
  const adjusted_mid_price =
529
640
  (parsed_mid_price * baseCoin.scalar) / quoteCoin.scalar / FLOAT_SCALAR;
530
641
 
@@ -540,16 +651,14 @@ export class DeepBookClient {
540
651
  const tx = new Transaction();
541
652
 
542
653
  tx.add(this.deepBook.poolTradeParams(poolKey));
543
- const res = await this.client.devInspectTransactionBlock({
544
- sender: normalizeHaneulAddress(this.#address),
545
- transactionBlock: tx,
654
+ const res = await this.#client.core.simulateTransaction({
655
+ transaction: tx,
656
+ include: { commandResults: true, effects: true },
546
657
  });
547
658
 
548
- const takerFee = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
549
- const makerFee = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
550
- const stakeRequired = Number(
551
- bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])),
552
- );
659
+ const takerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
660
+ const makerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
661
+ const stakeRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
553
662
 
554
663
  return {
555
664
  takerFee: Number(takerFee / FLOAT_SCALAR),
@@ -570,14 +679,14 @@ export class DeepBookClient {
570
679
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
571
680
 
572
681
  tx.add(this.deepBook.poolBookParams(poolKey));
573
- const res = await this.client.devInspectTransactionBlock({
574
- sender: normalizeHaneulAddress(this.#address),
575
- transactionBlock: tx,
682
+ const res = await this.#client.core.simulateTransaction({
683
+ transaction: tx,
684
+ include: { commandResults: true, effects: true },
576
685
  });
577
686
 
578
- const tickSize = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
579
- const lotSize = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
580
- const minSize = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
687
+ const tickSize = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
688
+ const lotSize = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
689
+ const minSize = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
581
690
 
582
691
  return {
583
692
  tickSize: Number((tickSize * baseScalar) / quoteScalar / FLOAT_SCALAR),
@@ -599,12 +708,12 @@ export class DeepBookClient {
599
708
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
600
709
 
601
710
  tx.add(this.deepBook.account(poolKey, managerKey));
602
- const res = await this.client.devInspectTransactionBlock({
603
- sender: normalizeHaneulAddress(this.#address),
604
- transactionBlock: tx,
711
+ const res = await this.#client.core.simulateTransaction({
712
+ transaction: tx,
713
+ include: { commandResults: true, effects: true },
605
714
  });
606
715
 
607
- const accountInformation = res.results![0].returnValues![0][0];
716
+ const accountInformation = res.commandResults![0].returnValues[0].bcs;
608
717
  const accountInfo = Account.parse(new Uint8Array(accountInformation));
609
718
 
610
719
  return {
@@ -648,14 +757,14 @@ export class DeepBookClient {
648
757
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
649
758
 
650
759
  tx.add(this.deepBook.lockedBalance(poolKey, balanceManagerKey));
651
- const res = await this.client.devInspectTransactionBlock({
652
- sender: normalizeHaneulAddress(this.#address),
653
- transactionBlock: tx,
760
+ const res = await this.#client.core.simulateTransaction({
761
+ transaction: tx,
762
+ include: { commandResults: true, effects: true },
654
763
  });
655
764
 
656
- const baseLocked = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
657
- const quoteLocked = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
658
- const deepLocked = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
765
+ const baseLocked = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
766
+ const quoteLocked = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
767
+ const deepLocked = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
659
768
 
660
769
  return {
661
770
  base: Number((baseLocked / baseScalar).toFixed(9)),
@@ -678,12 +787,12 @@ export class DeepBookClient {
678
787
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
679
788
  const deepCoin = this.#config.getCoin('DEEP');
680
789
 
681
- const res = await this.client.devInspectTransactionBlock({
682
- sender: normalizeHaneulAddress(this.#address),
683
- transactionBlock: tx,
790
+ const res = await this.#client.core.simulateTransaction({
791
+ transaction: tx,
792
+ include: { commandResults: true, effects: true },
684
793
  });
685
794
 
686
- const poolDeepPriceBytes = res.results![0].returnValues![0][0];
795
+ const poolDeepPriceBytes = res.commandResults![0].returnValues[0].bcs;
687
796
  const poolDeepPrice = OrderDeepPrice.parse(new Uint8Array(poolDeepPriceBytes));
688
797
 
689
798
  if (poolDeepPrice.asset_is_base) {
@@ -725,13 +834,13 @@ export class DeepBookClient {
725
834
  const tx = new Transaction();
726
835
  tx.add(this.deepBook.getBalanceManagerIds(owner));
727
836
 
728
- const res = await this.client.devInspectTransactionBlock({
729
- sender: normalizeHaneulAddress(this.#address),
730
- transactionBlock: tx,
837
+ const res = await this.#client.core.simulateTransaction({
838
+ transaction: tx,
839
+ include: { commandResults: true, effects: true },
731
840
  });
732
841
 
733
- const bytes = res.results![0].returnValues![0][0];
734
- const vecOfAddresses = bcs.vector(bcs.Address).parse(new Uint8Array(bytes));
842
+ const bytes = res.commandResults![0].returnValues[0].bcs;
843
+ const vecOfAddresses = bcs.vector(bcs.Address).parse(bytes);
735
844
 
736
845
  return vecOfAddresses.map((id: string) => normalizeHaneulAddress(id));
737
846
  }
@@ -745,17 +854,13 @@ export class DeepBookClient {
745
854
  const tx = new Transaction();
746
855
  tx.add(this.balanceManager.balanceManagerReferralOwner(referral));
747
856
 
748
- const res = await this.client.devInspectTransactionBlock({
749
- sender: normalizeHaneulAddress(this.#address),
750
- transactionBlock: tx,
857
+ const res = await this.#client.core.simulateTransaction({
858
+ transaction: tx,
859
+ include: { commandResults: true, effects: true },
751
860
  });
752
861
 
753
- if (res.error || !res.results || res.results.length === 0) {
754
- throw new Error(`Failed to get referral owner: ${res.error || 'No results returned'}`);
755
- }
756
-
757
- const bytes = res.results[0].returnValues![0][0];
758
- const owner = bcs.Address.parse(new Uint8Array(bytes));
862
+ const bytes = res.commandResults![0].returnValues[0].bcs;
863
+ const owner = bcs.Address.parse(bytes);
759
864
 
760
865
  return owner;
761
866
  }
@@ -777,19 +882,19 @@ export class DeepBookClient {
777
882
 
778
883
  tx.add(this.deepBook.getPoolReferralBalances(poolKey, referral));
779
884
 
780
- const res = await this.client.devInspectTransactionBlock({
781
- sender: normalizeHaneulAddress(this.#address),
782
- transactionBlock: tx,
885
+ const res = await this.#client.core.simulateTransaction({
886
+ transaction: tx,
887
+ include: { commandResults: true, effects: true },
783
888
  });
784
889
 
785
890
  // The function returns three u64 values: (base, quote, deep)
786
- const baseBytes = res.results![0].returnValues![0][0];
787
- const quoteBytes = res.results![0].returnValues![1][0];
788
- const deepBytes = res.results![0].returnValues![2][0];
891
+ const baseBytes = res.commandResults![0].returnValues[0].bcs;
892
+ const quoteBytes = res.commandResults![0].returnValues[1].bcs;
893
+ const deepBytes = res.commandResults![0].returnValues[2].bcs;
789
894
 
790
- const baseBalance = Number(bcs.U64.parse(new Uint8Array(baseBytes)));
791
- const quoteBalance = Number(bcs.U64.parse(new Uint8Array(quoteBytes)));
792
- const deepBalance = Number(bcs.U64.parse(new Uint8Array(deepBytes)));
895
+ const baseBalance = Number(bcs.U64.parse(baseBytes));
896
+ const quoteBalance = Number(bcs.U64.parse(quoteBytes));
897
+ const deepBalance = Number(bcs.U64.parse(deepBytes));
793
898
 
794
899
  return {
795
900
  base: baseBalance / baseScalar,
@@ -808,13 +913,13 @@ export class DeepBookClient {
808
913
 
809
914
  tx.add(this.balanceManager.balanceManagerReferralPoolId(referral));
810
915
 
811
- const res = await this.client.devInspectTransactionBlock({
812
- sender: normalizeHaneulAddress(this.#address),
813
- transactionBlock: tx,
916
+ const res = await this.#client.core.simulateTransaction({
917
+ transaction: tx,
918
+ include: { commandResults: true, effects: true },
814
919
  });
815
920
 
816
- const bytes = res.results![0].returnValues![0][0];
817
- const poolId = bcs.Address.parse(new Uint8Array(bytes));
921
+ const bytes = res.commandResults![0].returnValues[0].bcs;
922
+ const poolId = bcs.Address.parse(bytes);
818
923
 
819
924
  return normalizeHaneulAddress(poolId);
820
925
  }
@@ -830,13 +935,13 @@ export class DeepBookClient {
830
935
 
831
936
  tx.add(this.deepBook.poolReferralMultiplier(poolKey, referral));
832
937
 
833
- const res = await this.client.devInspectTransactionBlock({
834
- sender: normalizeHaneulAddress(this.#address),
835
- transactionBlock: tx,
938
+ const res = await this.#client.core.simulateTransaction({
939
+ transaction: tx,
940
+ include: { commandResults: true, effects: true },
836
941
  });
837
942
 
838
- const bytes = res.results![0].returnValues![0][0];
839
- const multiplier = Number(bcs.U64.parse(new Uint8Array(bytes)));
943
+ const bytes = res.commandResults![0].returnValues[0].bcs;
944
+ const multiplier = Number(bcs.U64.parse(bytes));
840
945
 
841
946
  return multiplier / FLOAT_SCALAR;
842
947
  }
@@ -851,14 +956,14 @@ export class DeepBookClient {
851
956
  const tx = new Transaction();
852
957
  tx.add(this.balanceManager.getBalanceManagerReferralId(managerKey, poolKey));
853
958
 
854
- const res = await this.client.devInspectTransactionBlock({
855
- sender: normalizeHaneulAddress(this.#address),
856
- transactionBlock: tx,
959
+ const res = await this.#client.core.simulateTransaction({
960
+ transaction: tx,
961
+ include: { commandResults: true, effects: true },
857
962
  });
858
963
 
859
964
  try {
860
- const bytes = res.results![0].returnValues![0][0];
861
- const optionId = bcs.option(bcs.Address).parse(new Uint8Array(bytes));
965
+ const bytes = res.commandResults![0].returnValues[0].bcs;
966
+ const optionId = bcs.option(bcs.Address).parse(bytes);
862
967
  if (optionId === null) {
863
968
  return null;
864
969
  }
@@ -870,14 +975,17 @@ export class DeepBookClient {
870
975
 
871
976
  async getPriceInfoObject(tx: Transaction, coinKey: string): Promise<string> {
872
977
  const currentTime = Date.now();
873
- const priceInfoObjectAge = (await this.getPriceInfoObjectAge(coinKey)) * 1000;
874
- if (currentTime - priceInfoObjectAge < PRICE_INFO_OBJECT_MAX_AGE_MS) {
978
+ const priceInfoObjectAge = await this.getPriceInfoObjectAge(coinKey);
979
+ if (
980
+ priceInfoObjectAge &&
981
+ currentTime - priceInfoObjectAge * 1000 < PRICE_INFO_OBJECT_MAX_AGE_MS
982
+ ) {
875
983
  return await this.#config.getCoin(coinKey).priceInfoObjectId!;
876
984
  }
877
985
 
878
986
  // Initialize connection to the Haneul Price Service
879
987
  const endpoint =
880
- this.#config.env === 'testnet'
988
+ this.#config.network === 'testnet'
881
989
  ? 'https://hermes-beta.pyth.network'
882
990
  : 'https://hermes.pyth.network';
883
991
  const connection = new HaneulPriceServiceConnection(endpoint);
@@ -890,40 +998,133 @@ export class DeepBookClient {
890
998
  // Fetch price feed update data
891
999
  const priceUpdateData = await connection.getPriceFeedsUpdateData(priceIDs);
892
1000
 
893
- // Initialize Sui Client and Pyth Client
1001
+ // Initialize Haneul Client and Pyth Client
894
1002
  const wormholeStateId = this.#config.pyth.wormholeStateId;
895
1003
  const pythStateId = this.#config.pyth.pythStateId;
896
1004
 
897
- const client = new HaneulPythClient(this.client, pythStateId, wormholeStateId);
1005
+ const client = new HaneulPythClient(this.#client, pythStateId, wormholeStateId);
898
1006
 
899
1007
  return (await client.updatePriceFeeds(tx, priceUpdateData, priceIDs))[0]; // returns priceInfoObjectIds
900
1008
  }
901
1009
 
1010
+ /**
1011
+ * @description Batch update price info objects for multiple coins. Only updates stale feeds.
1012
+ * This is more efficient than calling getPriceInfoObject multiple times as it:
1013
+ * 1. Batch fetches all price info object ages in one RPC call
1014
+ * 2. Fetches all stale price updates from Pyth in a single API call
1015
+ * @param {Transaction} tx Transaction to add price update commands to
1016
+ * @param {string[]} coinKeys Array of coin keys to update prices for
1017
+ * @returns {Promise<Record<string, string>>} Map of coinKey -> priceInfoObjectId
1018
+ */
1019
+ async getPriceInfoObjects(tx: Transaction, coinKeys: string[]): Promise<Record<string, string>> {
1020
+ if (coinKeys.length === 0) {
1021
+ return {};
1022
+ }
1023
+
1024
+ const currentTime = Date.now();
1025
+
1026
+ // Build map of coinKey -> priceInfoObjectId and collect all object IDs
1027
+ const coinToObjectId: Record<string, string> = {};
1028
+ const objectIds: string[] = [];
1029
+ for (const coinKey of coinKeys) {
1030
+ const priceInfoObjectId = this.#config.getCoin(coinKey).priceInfoObjectId!;
1031
+ coinToObjectId[coinKey] = priceInfoObjectId;
1032
+ objectIds.push(priceInfoObjectId);
1033
+ }
1034
+
1035
+ // Batch fetch all price info objects in one RPC call
1036
+ const res = await this.#client.core.getObjects({
1037
+ objectIds,
1038
+ include: { content: true },
1039
+ });
1040
+
1041
+ // Parse each object and determine which are stale
1042
+ const staleCoinKeys: string[] = [];
1043
+ const result: Record<string, string> = {};
1044
+
1045
+ for (let i = 0; i < coinKeys.length; i++) {
1046
+ const coinKey = coinKeys[i];
1047
+ const obj = res.objects[i];
1048
+
1049
+ if (obj instanceof Error || !obj?.content) {
1050
+ // If we can't fetch the object, mark it as stale to force update
1051
+ staleCoinKeys.push(coinKey);
1052
+ continue;
1053
+ }
1054
+
1055
+ const priceInfoObject = PriceInfoObject.parse(obj.content);
1056
+ const arrivalTime = Number(priceInfoObject.price_info.arrival_time);
1057
+ const age = currentTime - arrivalTime * 1000;
1058
+
1059
+ if (age >= PRICE_INFO_OBJECT_MAX_AGE_MS) {
1060
+ staleCoinKeys.push(coinKey);
1061
+ } else {
1062
+ // Fresh price, just return the existing object ID
1063
+ result[coinKey] = coinToObjectId[coinKey];
1064
+ }
1065
+ }
1066
+
1067
+ // If no stale feeds, return early
1068
+ if (staleCoinKeys.length === 0) {
1069
+ return result;
1070
+ }
1071
+
1072
+ // Collect all feed IDs for stale coins
1073
+ const staleFeedIds: string[] = [];
1074
+ const feedIdToCoinKey: Record<string, string> = {};
1075
+ for (const coinKey of staleCoinKeys) {
1076
+ const feedId = this.#config.getCoin(coinKey).feed!;
1077
+ staleFeedIds.push(feedId);
1078
+ feedIdToCoinKey[feedId] = coinKey;
1079
+ }
1080
+
1081
+ // Initialize connection to the Haneul Price Service
1082
+ const endpoint =
1083
+ this.#config.network === 'testnet'
1084
+ ? 'https://hermes-beta.pyth.network'
1085
+ : 'https://hermes.pyth.network';
1086
+ const connection = new HaneulPriceServiceConnection(endpoint);
1087
+
1088
+ // Fetch all stale price updates from Pyth in a single API call
1089
+ const priceUpdateData = await connection.getPriceFeedsUpdateData(staleFeedIds);
1090
+
1091
+ // Initialize Pyth Client
1092
+ const wormholeStateId = this.#config.pyth.wormholeStateId;
1093
+ const pythStateId = this.#config.pyth.pythStateId;
1094
+ const pythClient = new HaneulPythClient(this.#client, pythStateId, wormholeStateId);
1095
+
1096
+ // Update all stale feeds in the transaction
1097
+ const updatedObjectIds = await pythClient.updatePriceFeeds(tx, priceUpdateData, staleFeedIds);
1098
+
1099
+ // Map the updated object IDs back to coin keys
1100
+ for (let i = 0; i < staleFeedIds.length; i++) {
1101
+ const coinKey = feedIdToCoinKey[staleFeedIds[i]];
1102
+ result[coinKey] = updatedObjectIds[i];
1103
+ }
1104
+
1105
+ return result;
1106
+ }
1107
+
902
1108
  /**
903
1109
  * @description Get the age of the price info object for a specific coin
904
1110
  * @param {string} coinKey Key of the coin
905
- * @returns {Promise<string>} The arrival time of the price info object
1111
+ * @returns {Promise<number>} The arrival time of the price info object
906
1112
  */
907
1113
  async getPriceInfoObjectAge(coinKey: string) {
908
1114
  const priceInfoObjectId = this.#config.getCoin(coinKey).priceInfoObjectId!;
909
- const res = await this.client.getObject({
910
- id: priceInfoObjectId,
911
- options: {
912
- showContent: true,
1115
+ const res = await this.#client.core.getObject({
1116
+ objectId: priceInfoObjectId,
1117
+ include: {
1118
+ content: true,
913
1119
  },
914
1120
  });
915
1121
 
916
- if (!res.data?.content) {
1122
+ if (!res.object?.content) {
917
1123
  throw new Error(`Price info object not found for ${coinKey}`);
918
1124
  }
919
1125
 
920
- // Type guard to check if content has fields property
921
- if ('fields' in res.data.content) {
922
- const fields = res.data.content.fields as any;
923
- return fields.price_info?.fields?.arrival_time;
924
- } else {
925
- throw new Error(`Invalid price info object structure for ${coinKey}`);
926
- }
1126
+ const priceInfoObject = PriceInfoObject.parse(res.object.content);
1127
+ return Number(priceInfoObject.price_info.arrival_time);
927
1128
  }
928
1129
 
929
1130
  // === Margin Pool View Methods ===
@@ -937,13 +1138,13 @@ export class DeepBookClient {
937
1138
  const tx = new Transaction();
938
1139
  tx.add(this.marginPool.getId(coinKey));
939
1140
 
940
- const res = await this.client.devInspectTransactionBlock({
941
- sender: normalizeHaneulAddress(this.#address),
942
- transactionBlock: tx,
1141
+ const res = await this.#client.core.simulateTransaction({
1142
+ transaction: tx,
1143
+ include: { commandResults: true, effects: true },
943
1144
  });
944
1145
 
945
- const bytes = res.results![0].returnValues![0][0];
946
- return bcs.Address.parse(new Uint8Array(bytes));
1146
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1147
+ return bcs.Address.parse(bytes);
947
1148
  }
948
1149
 
949
1150
  /**
@@ -956,13 +1157,13 @@ export class DeepBookClient {
956
1157
  const tx = new Transaction();
957
1158
  tx.add(this.marginPool.deepbookPoolAllowed(coinKey, deepbookPoolId));
958
1159
 
959
- const res = await this.client.devInspectTransactionBlock({
960
- sender: normalizeHaneulAddress(this.#address),
961
- transactionBlock: tx,
1160
+ const res = await this.#client.core.simulateTransaction({
1161
+ transaction: tx,
1162
+ include: { commandResults: true, effects: true },
962
1163
  });
963
1164
 
964
- const bytes = res.results![0].returnValues![0][0];
965
- return bcs.bool().parse(new Uint8Array(bytes));
1165
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1166
+ return bcs.bool().parse(bytes);
966
1167
  }
967
1168
 
968
1169
  /**
@@ -975,13 +1176,13 @@ export class DeepBookClient {
975
1176
  const tx = new Transaction();
976
1177
  tx.add(this.marginPool.totalSupply(coinKey));
977
1178
 
978
- const res = await this.client.devInspectTransactionBlock({
979
- sender: normalizeHaneulAddress(this.#address),
980
- transactionBlock: tx,
1179
+ const res = await this.#client.core.simulateTransaction({
1180
+ transaction: tx,
1181
+ include: { commandResults: true, effects: true },
981
1182
  });
982
1183
 
983
- const bytes = res.results![0].returnValues![0][0];
984
- const rawAmount = BigInt(bcs.U64.parse(new Uint8Array(bytes)));
1184
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1185
+ const rawAmount = BigInt(bcs.U64.parse(bytes));
985
1186
  const coin = this.#config.getCoin(coinKey);
986
1187
  return this.#formatTokenAmount(rawAmount, coin.scalar, decimals);
987
1188
  }
@@ -996,13 +1197,13 @@ export class DeepBookClient {
996
1197
  const tx = new Transaction();
997
1198
  tx.add(this.marginPool.supplyShares(coinKey));
998
1199
 
999
- const res = await this.client.devInspectTransactionBlock({
1000
- sender: normalizeHaneulAddress(this.#address),
1001
- transactionBlock: tx,
1200
+ const res = await this.#client.core.simulateTransaction({
1201
+ transaction: tx,
1202
+ include: { commandResults: true, effects: true },
1002
1203
  });
1003
1204
 
1004
- const bytes = res.results![0].returnValues![0][0];
1005
- const rawShares = BigInt(bcs.U64.parse(new Uint8Array(bytes)));
1205
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1206
+ const rawShares = BigInt(bcs.U64.parse(bytes));
1006
1207
  const coin = this.#config.getCoin(coinKey);
1007
1208
  return this.#formatTokenAmount(rawShares, coin.scalar, decimals);
1008
1209
  }
@@ -1017,13 +1218,13 @@ export class DeepBookClient {
1017
1218
  const tx = new Transaction();
1018
1219
  tx.add(this.marginPool.totalBorrow(coinKey));
1019
1220
 
1020
- const res = await this.client.devInspectTransactionBlock({
1021
- sender: normalizeHaneulAddress(this.#address),
1022
- transactionBlock: tx,
1221
+ const res = await this.#client.core.simulateTransaction({
1222
+ transaction: tx,
1223
+ include: { commandResults: true, effects: true },
1023
1224
  });
1024
1225
 
1025
- const bytes = res.results![0].returnValues![0][0];
1026
- const rawAmount = BigInt(bcs.U64.parse(new Uint8Array(bytes)));
1226
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1227
+ const rawAmount = BigInt(bcs.U64.parse(bytes));
1027
1228
  const coin = this.#config.getCoin(coinKey);
1028
1229
  return this.#formatTokenAmount(rawAmount, coin.scalar, decimals);
1029
1230
  }
@@ -1038,13 +1239,13 @@ export class DeepBookClient {
1038
1239
  const tx = new Transaction();
1039
1240
  tx.add(this.marginPool.borrowShares(coinKey));
1040
1241
 
1041
- const res = await this.client.devInspectTransactionBlock({
1042
- sender: normalizeHaneulAddress(this.#address),
1043
- transactionBlock: tx,
1242
+ const res = await this.#client.core.simulateTransaction({
1243
+ transaction: tx,
1244
+ include: { commandResults: true, effects: true },
1044
1245
  });
1045
1246
 
1046
- const bytes = res.results![0].returnValues![0][0];
1047
- const rawShares = BigInt(bcs.U64.parse(new Uint8Array(bytes)));
1247
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1248
+ const rawShares = BigInt(bcs.U64.parse(bytes));
1048
1249
  const coin = this.#config.getCoin(coinKey);
1049
1250
  return this.#formatTokenAmount(rawShares, coin.scalar, decimals);
1050
1251
  }
@@ -1058,13 +1259,13 @@ export class DeepBookClient {
1058
1259
  const tx = new Transaction();
1059
1260
  tx.add(this.marginPool.lastUpdateTimestamp(coinKey));
1060
1261
 
1061
- const res = await this.client.devInspectTransactionBlock({
1062
- sender: normalizeHaneulAddress(this.#address),
1063
- transactionBlock: tx,
1262
+ const res = await this.#client.core.simulateTransaction({
1263
+ transaction: tx,
1264
+ include: { commandResults: true, effects: true },
1064
1265
  });
1065
1266
 
1066
- const bytes = res.results![0].returnValues![0][0];
1067
- return Number(bcs.U64.parse(new Uint8Array(bytes)));
1267
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1268
+ return Number(bcs.U64.parse(bytes));
1068
1269
  }
1069
1270
 
1070
1271
  /**
@@ -1077,13 +1278,13 @@ export class DeepBookClient {
1077
1278
  const tx = new Transaction();
1078
1279
  tx.add(this.marginPool.supplyCap(coinKey));
1079
1280
 
1080
- const res = await this.client.devInspectTransactionBlock({
1081
- sender: normalizeHaneulAddress(this.#address),
1082
- transactionBlock: tx,
1281
+ const res = await this.#client.core.simulateTransaction({
1282
+ transaction: tx,
1283
+ include: { commandResults: true, effects: true },
1083
1284
  });
1084
1285
 
1085
- const bytes = res.results![0].returnValues![0][0];
1086
- const rawAmount = BigInt(bcs.U64.parse(new Uint8Array(bytes)));
1286
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1287
+ const rawAmount = BigInt(bcs.U64.parse(bytes));
1087
1288
  const coin = this.#config.getCoin(coinKey);
1088
1289
  return this.#formatTokenAmount(rawAmount, coin.scalar, decimals);
1089
1290
  }
@@ -1097,13 +1298,13 @@ export class DeepBookClient {
1097
1298
  const tx = new Transaction();
1098
1299
  tx.add(this.marginPool.maxUtilizationRate(coinKey));
1099
1300
 
1100
- const res = await this.client.devInspectTransactionBlock({
1101
- sender: normalizeHaneulAddress(this.#address),
1102
- transactionBlock: tx,
1301
+ const res = await this.#client.core.simulateTransaction({
1302
+ transaction: tx,
1303
+ include: { commandResults: true, effects: true },
1103
1304
  });
1104
1305
 
1105
- const bytes = res.results![0].returnValues![0][0];
1106
- const rawRate = Number(bcs.U64.parse(new Uint8Array(bytes)));
1306
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1307
+ const rawRate = Number(bcs.U64.parse(bytes));
1107
1308
  return rawRate / FLOAT_SCALAR;
1108
1309
  }
1109
1310
 
@@ -1116,13 +1317,13 @@ export class DeepBookClient {
1116
1317
  const tx = new Transaction();
1117
1318
  tx.add(this.marginPool.protocolSpread(coinKey));
1118
1319
 
1119
- const res = await this.client.devInspectTransactionBlock({
1120
- sender: normalizeHaneulAddress(this.#address),
1121
- transactionBlock: tx,
1320
+ const res = await this.#client.core.simulateTransaction({
1321
+ transaction: tx,
1322
+ include: { commandResults: true, effects: true },
1122
1323
  });
1123
1324
 
1124
- const bytes = res.results![0].returnValues![0][0];
1125
- const rawSpread = Number(bcs.U64.parse(new Uint8Array(bytes)));
1325
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1326
+ const rawSpread = Number(bcs.U64.parse(bytes));
1126
1327
  return rawSpread / FLOAT_SCALAR;
1127
1328
  }
1128
1329
 
@@ -1136,13 +1337,13 @@ export class DeepBookClient {
1136
1337
  const tx = new Transaction();
1137
1338
  tx.add(this.marginPool.minBorrow(coinKey));
1138
1339
 
1139
- const res = await this.client.devInspectTransactionBlock({
1140
- sender: normalizeHaneulAddress(this.#address),
1141
- transactionBlock: tx,
1340
+ const res = await this.#client.core.simulateTransaction({
1341
+ transaction: tx,
1342
+ include: { commandResults: true, effects: true },
1142
1343
  });
1143
1344
 
1144
- const bytes = res.results![0].returnValues![0][0];
1145
- const rawAmount = BigInt(bcs.U64.parse(new Uint8Array(bytes)));
1345
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1346
+ const rawAmount = BigInt(bcs.U64.parse(bytes));
1146
1347
  const coin = this.#config.getCoin(coinKey);
1147
1348
  return this.#formatTokenAmount(rawAmount, coin.scalar, decimals);
1148
1349
  }
@@ -1156,13 +1357,13 @@ export class DeepBookClient {
1156
1357
  const tx = new Transaction();
1157
1358
  tx.add(this.marginPool.interestRate(coinKey));
1158
1359
 
1159
- const res = await this.client.devInspectTransactionBlock({
1160
- sender: normalizeHaneulAddress(this.#address),
1161
- transactionBlock: tx,
1360
+ const res = await this.#client.core.simulateTransaction({
1361
+ transaction: tx,
1362
+ include: { commandResults: true, effects: true },
1162
1363
  });
1163
1364
 
1164
- const bytes = res.results![0].returnValues![0][0];
1165
- const rawRate = Number(bcs.U64.parse(new Uint8Array(bytes)));
1365
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1366
+ const rawRate = Number(bcs.U64.parse(bytes));
1166
1367
  return rawRate / FLOAT_SCALAR;
1167
1368
  }
1168
1369
 
@@ -1181,13 +1382,13 @@ export class DeepBookClient {
1181
1382
  const tx = new Transaction();
1182
1383
  tx.add(this.marginPool.userSupplyShares(coinKey, supplierCapId));
1183
1384
 
1184
- const res = await this.client.devInspectTransactionBlock({
1185
- sender: normalizeHaneulAddress(this.#address),
1186
- transactionBlock: tx,
1385
+ const res = await this.#client.core.simulateTransaction({
1386
+ transaction: tx,
1387
+ include: { commandResults: true, effects: true },
1187
1388
  });
1188
1389
 
1189
- const bytes = res.results![0].returnValues![0][0];
1190
- const rawShares = BigInt(bcs.U64.parse(new Uint8Array(bytes)));
1390
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1391
+ const rawShares = BigInt(bcs.U64.parse(bytes));
1191
1392
  const coin = this.#config.getCoin(coinKey);
1192
1393
  return this.#formatTokenAmount(rawShares, coin.scalar, decimals);
1193
1394
  }
@@ -1207,13 +1408,13 @@ export class DeepBookClient {
1207
1408
  const tx = new Transaction();
1208
1409
  tx.add(this.marginPool.userSupplyAmount(coinKey, supplierCapId));
1209
1410
 
1210
- const res = await this.client.devInspectTransactionBlock({
1211
- sender: normalizeHaneulAddress(this.#address),
1212
- transactionBlock: tx,
1411
+ const res = await this.#client.core.simulateTransaction({
1412
+ transaction: tx,
1413
+ include: { commandResults: true, effects: true },
1213
1414
  });
1214
1415
 
1215
- const bytes = res.results![0].returnValues![0][0];
1216
- const rawAmount = BigInt(bcs.U64.parse(new Uint8Array(bytes)));
1416
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1417
+ const rawAmount = BigInt(bcs.U64.parse(bytes));
1217
1418
  const coin = this.#config.getCoin(coinKey);
1218
1419
  return this.#formatTokenAmount(rawAmount, coin.scalar, decimals);
1219
1420
  }
@@ -1230,13 +1431,13 @@ export class DeepBookClient {
1230
1431
  const tx = new Transaction();
1231
1432
  tx.add(this.marginManager.ownerByPoolKey(manager.poolKey, manager.address));
1232
1433
 
1233
- const res = await this.client.devInspectTransactionBlock({
1234
- sender: normalizeHaneulAddress(this.#address),
1235
- transactionBlock: tx,
1434
+ const res = await this.#client.core.simulateTransaction({
1435
+ transaction: tx,
1436
+ include: { commandResults: true, effects: true },
1236
1437
  });
1237
1438
 
1238
- const bytes = res.results![0].returnValues![0][0];
1239
- return normalizeHaneulAddress(bcs.Address.parse(new Uint8Array(bytes)));
1439
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1440
+ return normalizeHaneulAddress(bcs.Address.parse(bytes));
1240
1441
  }
1241
1442
 
1242
1443
  /**
@@ -1249,13 +1450,13 @@ export class DeepBookClient {
1249
1450
  const tx = new Transaction();
1250
1451
  tx.add(this.marginManager.deepbookPool(manager.poolKey, manager.address));
1251
1452
 
1252
- const res = await this.client.devInspectTransactionBlock({
1253
- sender: normalizeHaneulAddress(this.#address),
1254
- transactionBlock: tx,
1453
+ const res = await this.#client.core.simulateTransaction({
1454
+ transaction: tx,
1455
+ include: { commandResults: true, effects: true },
1255
1456
  });
1256
1457
 
1257
- const bytes = res.results![0].returnValues![0][0];
1258
- return normalizeHaneulAddress(bcs.Address.parse(new Uint8Array(bytes)));
1458
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1459
+ return normalizeHaneulAddress(bcs.Address.parse(bytes));
1259
1460
  }
1260
1461
 
1261
1462
  /**
@@ -1268,13 +1469,13 @@ export class DeepBookClient {
1268
1469
  const tx = new Transaction();
1269
1470
  tx.add(this.marginManager.marginPoolId(manager.poolKey, manager.address));
1270
1471
 
1271
- const res = await this.client.devInspectTransactionBlock({
1272
- sender: normalizeHaneulAddress(this.#address),
1273
- transactionBlock: tx,
1472
+ const res = await this.#client.core.simulateTransaction({
1473
+ transaction: tx,
1474
+ include: { commandResults: true, effects: true },
1274
1475
  });
1275
1476
 
1276
- const bytes = res.results![0].returnValues![0][0];
1277
- const option = bcs.option(bcs.Address).parse(new Uint8Array(bytes));
1477
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1478
+ const option = bcs.option(bcs.Address).parse(bytes);
1278
1479
  return option ? normalizeHaneulAddress(option) : null;
1279
1480
  }
1280
1481
 
@@ -1290,15 +1491,15 @@ export class DeepBookClient {
1290
1491
  const tx = new Transaction();
1291
1492
  tx.add(this.marginManager.borrowedShares(manager.poolKey, manager.address));
1292
1493
 
1293
- const res = await this.client.devInspectTransactionBlock({
1294
- sender: normalizeHaneulAddress(this.#address),
1295
- transactionBlock: tx,
1494
+ const res = await this.#client.core.simulateTransaction({
1495
+ transaction: tx,
1496
+ include: { commandResults: true, effects: true },
1296
1497
  });
1297
1498
 
1298
- const baseBytes = res.results![0].returnValues![0][0];
1299
- const quoteBytes = res.results![0].returnValues![1][0];
1300
- const baseShares = bcs.U64.parse(new Uint8Array(baseBytes)).toString();
1301
- const quoteShares = bcs.U64.parse(new Uint8Array(quoteBytes)).toString();
1499
+ const baseBytes = res.commandResults![0].returnValues[0].bcs;
1500
+ const quoteBytes = res.commandResults![0].returnValues[1].bcs;
1501
+ const baseShares = bcs.U64.parse(baseBytes).toString();
1502
+ const quoteShares = bcs.U64.parse(quoteBytes).toString();
1302
1503
 
1303
1504
  return { baseShares, quoteShares };
1304
1505
  }
@@ -1313,13 +1514,13 @@ export class DeepBookClient {
1313
1514
  const tx = new Transaction();
1314
1515
  tx.add(this.marginManager.borrowedBaseShares(manager.poolKey, manager.address));
1315
1516
 
1316
- const res = await this.client.devInspectTransactionBlock({
1317
- sender: normalizeHaneulAddress(this.#address),
1318
- transactionBlock: tx,
1517
+ const res = await this.#client.core.simulateTransaction({
1518
+ transaction: tx,
1519
+ include: { commandResults: true, effects: true },
1319
1520
  });
1320
1521
 
1321
- const bytes = res.results![0].returnValues![0][0];
1322
- return bcs.U64.parse(new Uint8Array(bytes)).toString();
1522
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1523
+ return bcs.U64.parse(bytes).toString();
1323
1524
  }
1324
1525
 
1325
1526
  /**
@@ -1332,13 +1533,13 @@ export class DeepBookClient {
1332
1533
  const tx = new Transaction();
1333
1534
  tx.add(this.marginManager.borrowedQuoteShares(manager.poolKey, manager.address));
1334
1535
 
1335
- const res = await this.client.devInspectTransactionBlock({
1336
- sender: normalizeHaneulAddress(this.#address),
1337
- transactionBlock: tx,
1536
+ const res = await this.#client.core.simulateTransaction({
1537
+ transaction: tx,
1538
+ include: { commandResults: true, effects: true },
1338
1539
  });
1339
1540
 
1340
- const bytes = res.results![0].returnValues![0][0];
1341
- return bcs.U64.parse(new Uint8Array(bytes)).toString();
1541
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1542
+ return bcs.U64.parse(bytes).toString();
1342
1543
  }
1343
1544
 
1344
1545
  /**
@@ -1351,13 +1552,13 @@ export class DeepBookClient {
1351
1552
  const tx = new Transaction();
1352
1553
  tx.add(this.marginManager.hasBaseDebt(manager.poolKey, manager.address));
1353
1554
 
1354
- const res = await this.client.devInspectTransactionBlock({
1355
- sender: normalizeHaneulAddress(this.#address),
1356
- transactionBlock: tx,
1555
+ const res = await this.#client.core.simulateTransaction({
1556
+ transaction: tx,
1557
+ include: { commandResults: true, effects: true },
1357
1558
  });
1358
1559
 
1359
- const bytes = res.results![0].returnValues![0][0];
1360
- return bcs.bool().parse(new Uint8Array(bytes));
1560
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1561
+ return bcs.bool().parse(bytes);
1361
1562
  }
1362
1563
 
1363
1564
  /**
@@ -1370,13 +1571,13 @@ export class DeepBookClient {
1370
1571
  const tx = new Transaction();
1371
1572
  tx.add(this.marginManager.balanceManager(manager.poolKey, manager.address));
1372
1573
 
1373
- const res = await this.client.devInspectTransactionBlock({
1374
- sender: normalizeHaneulAddress(this.#address),
1375
- transactionBlock: tx,
1574
+ const res = await this.#client.core.simulateTransaction({
1575
+ transaction: tx,
1576
+ include: { commandResults: true, effects: true },
1376
1577
  });
1377
1578
 
1378
- const bytes = res.results![0].returnValues![0][0];
1379
- return normalizeHaneulAddress(bcs.Address.parse(new Uint8Array(bytes)));
1579
+ const bytes = res.commandResults![0].returnValues[0].bcs;
1580
+ return normalizeHaneulAddress(bcs.Address.parse(bytes));
1380
1581
  }
1381
1582
 
1382
1583
  /**
@@ -1393,24 +1594,24 @@ export class DeepBookClient {
1393
1594
  const tx = new Transaction();
1394
1595
  tx.add(this.marginManager.calculateAssets(manager.poolKey, manager.address));
1395
1596
 
1396
- const res = await this.client.devInspectTransactionBlock({
1397
- sender: normalizeHaneulAddress(this.#address),
1398
- transactionBlock: tx,
1597
+ const res = await this.#client.core.simulateTransaction({
1598
+ transaction: tx,
1599
+ include: { commandResults: true, effects: true },
1399
1600
  });
1400
1601
 
1401
- const baseBytes = res.results![0].returnValues![0][0];
1402
- const quoteBytes = res.results![0].returnValues![1][0];
1602
+ const baseBytes = res.commandResults![0].returnValues[0].bcs;
1603
+ const quoteBytes = res.commandResults![0].returnValues[1].bcs;
1403
1604
  const pool = this.#config.getPool(manager.poolKey);
1404
1605
  const baseCoin = this.#config.getCoin(pool.baseCoin);
1405
1606
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
1406
1607
 
1407
1608
  const baseAsset = this.#formatTokenAmount(
1408
- BigInt(bcs.U64.parse(new Uint8Array(baseBytes))),
1609
+ BigInt(bcs.U64.parse(baseBytes)),
1409
1610
  baseCoin.scalar,
1410
1611
  decimals,
1411
1612
  );
1412
1613
  const quoteAsset = this.#formatTokenAmount(
1413
- BigInt(bcs.U64.parse(new Uint8Array(quoteBytes))),
1614
+ BigInt(bcs.U64.parse(quoteBytes)),
1414
1615
  quoteCoin.scalar,
1415
1616
  decimals,
1416
1617
  );
@@ -1442,30 +1643,33 @@ export class DeepBookClient {
1442
1643
  const tx = new Transaction();
1443
1644
  tx.add(this.marginManager.calculateDebts(manager.poolKey, debtCoinKey, manager.address));
1444
1645
 
1445
- const res = await this.client.devInspectTransactionBlock({
1446
- sender: normalizeHaneulAddress(this.#address),
1447
- transactionBlock: tx,
1646
+ const res = await this.#client.core.simulateTransaction({
1647
+ transaction: tx,
1648
+ include: { commandResults: true, effects: true },
1448
1649
  });
1449
1650
 
1450
- // Check if the transaction failed
1451
- if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1651
+ if (res.FailedTransaction) {
1452
1652
  throw new Error(
1453
- `Failed to get margin manager debts: ${res.effects?.status?.error || 'Unknown error'}`,
1653
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
1454
1654
  );
1455
1655
  }
1456
1656
 
1657
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {
1658
+ throw new Error(`Failed to get margin manager debts: ${'Unknown error'}`);
1659
+ }
1660
+
1457
1661
  // The Move function returns a tuple (u64, u64), so returnValues has 2 elements
1458
- const baseBytes = res.results[0].returnValues[0][0];
1459
- const quoteBytes = res.results[0].returnValues[1][0];
1662
+ const baseBytes = res.commandResults[0].returnValues[0].bcs;
1663
+ const quoteBytes = res.commandResults[0].returnValues[1].bcs;
1460
1664
  const debtCoin = this.#config.getCoin(debtCoinKey);
1461
1665
 
1462
1666
  const baseDebt = this.#formatTokenAmount(
1463
- BigInt(bcs.U64.parse(new Uint8Array(baseBytes))),
1667
+ BigInt(bcs.U64.parse(baseBytes)),
1464
1668
  debtCoin.scalar,
1465
1669
  decimals,
1466
1670
  );
1467
1671
  const quoteDebt = this.#formatTokenAmount(
1468
- BigInt(bcs.U64.parse(new Uint8Array(quoteBytes))),
1672
+ BigInt(bcs.U64.parse(quoteBytes)),
1469
1673
  debtCoin.scalar,
1470
1674
  decimals,
1471
1675
  );
@@ -1514,65 +1718,68 @@ export class DeepBookClient {
1514
1718
  const tx = new Transaction();
1515
1719
  tx.add(this.marginManager.managerState(manager.poolKey, manager.address));
1516
1720
 
1517
- const res = await this.client.devInspectTransactionBlock({
1518
- sender: normalizeHaneulAddress(this.#address),
1519
- transactionBlock: tx,
1721
+ const res = await this.#client.core.simulateTransaction({
1722
+ transaction: tx,
1723
+ include: { commandResults: true, effects: true },
1520
1724
  });
1521
1725
 
1522
- // Check if the transaction failed
1523
- if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1726
+ if (res.FailedTransaction) {
1524
1727
  throw new Error(
1525
- `Failed to get margin manager state: ${res.effects?.status?.error || 'Unknown error'}`,
1728
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
1526
1729
  );
1527
1730
  }
1528
1731
 
1732
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {
1733
+ throw new Error(`Failed to get margin manager state: Unknown error`);
1734
+ }
1735
+
1529
1736
  const pool = this.#config.getPool(manager.poolKey);
1530
1737
  const baseCoin = this.#config.getCoin(pool.baseCoin);
1531
1738
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
1532
1739
 
1533
1740
  // Parse all 11 return values
1534
1741
  const managerId = normalizeHaneulAddress(
1535
- bcs.Address.parse(new Uint8Array(res.results[0].returnValues[0][0])),
1742
+ bcs.Address.parse(res.commandResults[0].returnValues[0].bcs),
1536
1743
  );
1537
1744
  const deepbookPoolId = normalizeHaneulAddress(
1538
- bcs.Address.parse(new Uint8Array(res.results[0].returnValues[1][0])),
1745
+ bcs.Address.parse(res.commandResults[0].returnValues[1].bcs),
1539
1746
  );
1540
1747
  const riskRatio =
1541
- Number(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0]))) / FLOAT_SCALAR;
1748
+ Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs)) / FLOAT_SCALAR;
1542
1749
  const baseAsset = this.#formatTokenAmount(
1543
- BigInt(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[3][0]))),
1750
+ BigInt(bcs.U64.parse(res.commandResults[0].returnValues[3].bcs)),
1544
1751
  baseCoin.scalar,
1545
1752
  decimals,
1546
1753
  );
1547
1754
  const quoteAsset = this.#formatTokenAmount(
1548
- BigInt(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[4][0]))),
1755
+ BigInt(bcs.U64.parse(res.commandResults[0].returnValues[4].bcs)),
1549
1756
  quoteCoin.scalar,
1550
1757
  decimals,
1551
1758
  );
1552
1759
  const baseDebt = this.#formatTokenAmount(
1553
- BigInt(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[5][0]))),
1760
+ BigInt(bcs.U64.parse(res.commandResults[0].returnValues[5].bcs)),
1554
1761
  baseCoin.scalar,
1555
1762
  decimals,
1556
1763
  );
1557
1764
  const quoteDebt = this.#formatTokenAmount(
1558
- BigInt(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[6][0]))),
1765
+ BigInt(bcs.U64.parse(res.commandResults[0].returnValues[6].bcs)),
1559
1766
  quoteCoin.scalar,
1560
1767
  decimals,
1561
1768
  );
1562
- const basePythPrice = bcs.U64.parse(new Uint8Array(res.results[0].returnValues[7][0]));
1769
+ const basePythPrice = bcs.U64.parse(res.commandResults[0].returnValues[7].bcs);
1563
1770
  const basePythDecimals = Number(
1564
- bcs.u8().parse(new Uint8Array(res.results[0].returnValues[8][0])),
1771
+ bcs.u8().parse(new Uint8Array(res.commandResults[0].returnValues[8].bcs)),
1565
1772
  );
1566
- const quotePythPrice = bcs.U64.parse(new Uint8Array(res.results[0].returnValues[9][0]));
1773
+ const quotePythPrice = bcs.U64.parse(res.commandResults[0].returnValues[9].bcs);
1567
1774
  const quotePythDecimals = Number(
1568
- bcs.u8().parse(new Uint8Array(res.results[0].returnValues[10][0])),
1775
+ bcs.u8().parse(new Uint8Array(res.commandResults[0].returnValues[10].bcs)),
1569
1776
  );
1570
- const currentPrice = BigInt(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[11][0])));
1777
+ const currentPrice = BigInt(bcs.U64.parse(res.commandResults[0].returnValues[11].bcs));
1571
1778
  const lowestTriggerAbovePrice = BigInt(
1572
- bcs.U64.parse(new Uint8Array(res.results[0].returnValues[12][0])),
1779
+ bcs.U64.parse(res.commandResults[0].returnValues[12].bcs),
1573
1780
  );
1574
1781
  const highestTriggerBelowPrice = BigInt(
1575
- bcs.U64.parse(new Uint8Array(res.results[0].returnValues[13][0])),
1782
+ bcs.U64.parse(res.commandResults[0].returnValues[13].bcs),
1576
1783
  );
1577
1784
 
1578
1785
  return {
@@ -1593,6 +1800,153 @@ export class DeepBookClient {
1593
1800
  };
1594
1801
  }
1595
1802
 
1803
+ /**
1804
+ * @description Get comprehensive state information for multiple margin managers.
1805
+ * @param {Record<string, string>} marginManagers Map of marginManagerId -> poolKey
1806
+ * @param {number} decimals Number of decimal places for formatting (default: 6)
1807
+ * @returns {Promise<Record<string, {...}>>} Object keyed by managerId with state data
1808
+ */
1809
+ async getMarginManagerStates(
1810
+ marginManagers: Record<string, string>,
1811
+ decimals: number = 6,
1812
+ ): Promise<
1813
+ Record<
1814
+ string,
1815
+ {
1816
+ managerId: string;
1817
+ deepbookPoolId: string;
1818
+ riskRatio: number;
1819
+ baseAsset: string;
1820
+ quoteAsset: string;
1821
+ baseDebt: string;
1822
+ quoteDebt: string;
1823
+ basePythPrice: string;
1824
+ basePythDecimals: number;
1825
+ quotePythPrice: string;
1826
+ quotePythDecimals: number;
1827
+ currentPrice: bigint;
1828
+ lowestTriggerAbovePrice: bigint;
1829
+ highestTriggerBelowPrice: bigint;
1830
+ }
1831
+ >
1832
+ > {
1833
+ const entries = Object.entries(marginManagers);
1834
+ if (entries.length === 0) {
1835
+ return {};
1836
+ }
1837
+
1838
+ const tx = new Transaction();
1839
+
1840
+ // Add a managerState call for each margin manager
1841
+ for (const [managerId, poolKey] of entries) {
1842
+ tx.add(this.marginManager.managerState(poolKey, managerId));
1843
+ }
1844
+
1845
+ const res = await this.#client.core.simulateTransaction({
1846
+ transaction: tx,
1847
+ include: { commandResults: true, effects: true },
1848
+ });
1849
+
1850
+ if (res.FailedTransaction) {
1851
+ throw new Error(
1852
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
1853
+ );
1854
+ }
1855
+
1856
+ if (!res.commandResults) {
1857
+ throw new Error(`Failed to get margin manager states: Unknown error`);
1858
+ }
1859
+
1860
+ const results: Record<
1861
+ string,
1862
+ {
1863
+ managerId: string;
1864
+ deepbookPoolId: string;
1865
+ riskRatio: number;
1866
+ baseAsset: string;
1867
+ quoteAsset: string;
1868
+ baseDebt: string;
1869
+ quoteDebt: string;
1870
+ basePythPrice: string;
1871
+ basePythDecimals: number;
1872
+ quotePythPrice: string;
1873
+ quotePythDecimals: number;
1874
+ currentPrice: bigint;
1875
+ lowestTriggerAbovePrice: bigint;
1876
+ highestTriggerBelowPrice: bigint;
1877
+ }
1878
+ > = {};
1879
+
1880
+ // Parse each command result
1881
+ for (let i = 0; i < entries.length; i++) {
1882
+ const commandResult = res.commandResults[i];
1883
+ if (!commandResult || !commandResult.returnValues) {
1884
+ throw new Error(`Failed to get margin manager state for index ${i}: No return values`);
1885
+ }
1886
+
1887
+ const [, poolKey] = entries[i];
1888
+ const pool = this.#config.getPool(poolKey);
1889
+ const baseCoin = this.#config.getCoin(pool.baseCoin);
1890
+ const quoteCoin = this.#config.getCoin(pool.quoteCoin);
1891
+
1892
+ const managerId = normalizeHaneulAddress(bcs.Address.parse(commandResult.returnValues[0].bcs));
1893
+ const deepbookPoolId = normalizeHaneulAddress(
1894
+ bcs.Address.parse(commandResult.returnValues[1].bcs),
1895
+ );
1896
+ const riskRatio = Number(bcs.U64.parse(commandResult.returnValues[2].bcs)) / FLOAT_SCALAR;
1897
+ const baseAsset = this.#formatTokenAmount(
1898
+ BigInt(bcs.U64.parse(commandResult.returnValues[3].bcs)),
1899
+ baseCoin.scalar,
1900
+ decimals,
1901
+ );
1902
+ const quoteAsset = this.#formatTokenAmount(
1903
+ BigInt(bcs.U64.parse(commandResult.returnValues[4].bcs)),
1904
+ quoteCoin.scalar,
1905
+ decimals,
1906
+ );
1907
+ const baseDebt = this.#formatTokenAmount(
1908
+ BigInt(bcs.U64.parse(commandResult.returnValues[5].bcs)),
1909
+ baseCoin.scalar,
1910
+ decimals,
1911
+ );
1912
+ const quoteDebt = this.#formatTokenAmount(
1913
+ BigInt(bcs.U64.parse(commandResult.returnValues[6].bcs)),
1914
+ quoteCoin.scalar,
1915
+ decimals,
1916
+ );
1917
+ const basePythPrice = bcs.U64.parse(commandResult.returnValues[7].bcs);
1918
+ const basePythDecimals = Number(
1919
+ bcs.u8().parse(new Uint8Array(commandResult.returnValues[8].bcs)),
1920
+ );
1921
+ const quotePythPrice = bcs.U64.parse(commandResult.returnValues[9].bcs);
1922
+ const quotePythDecimals = Number(
1923
+ bcs.u8().parse(new Uint8Array(commandResult.returnValues[10].bcs)),
1924
+ );
1925
+ const currentPrice = BigInt(bcs.U64.parse(commandResult.returnValues[11].bcs));
1926
+ const lowestTriggerAbovePrice = BigInt(bcs.U64.parse(commandResult.returnValues[12].bcs));
1927
+ const highestTriggerBelowPrice = BigInt(bcs.U64.parse(commandResult.returnValues[13].bcs));
1928
+
1929
+ results[managerId] = {
1930
+ managerId,
1931
+ deepbookPoolId,
1932
+ riskRatio,
1933
+ baseAsset,
1934
+ quoteAsset,
1935
+ baseDebt,
1936
+ quoteDebt,
1937
+ basePythPrice: basePythPrice.toString(),
1938
+ basePythDecimals,
1939
+ quotePythPrice: quotePythPrice.toString(),
1940
+ quotePythDecimals,
1941
+ currentPrice,
1942
+ lowestTriggerAbovePrice,
1943
+ highestTriggerBelowPrice,
1944
+ };
1945
+ }
1946
+
1947
+ return results;
1948
+ }
1949
+
1596
1950
  /**
1597
1951
  * @description Get the base asset balance of a margin manager
1598
1952
  * @param {string} marginManagerKey The key to identify the margin manager
@@ -1607,27 +1961,26 @@ export class DeepBookClient {
1607
1961
  const tx = new Transaction();
1608
1962
  tx.add(this.marginManager.baseBalance(manager.poolKey, manager.address));
1609
1963
 
1610
- const res = await this.client.devInspectTransactionBlock({
1611
- sender: normalizeHaneulAddress(this.#address),
1612
- transactionBlock: tx,
1964
+ const res = await this.#client.core.simulateTransaction({
1965
+ transaction: tx,
1966
+ include: { commandResults: true, effects: true },
1613
1967
  });
1614
1968
 
1615
- // Check if the transaction failed
1616
- if (!res.results || !res.results[0] || !res.results[0].returnValues) {
1969
+ if (res.FailedTransaction) {
1617
1970
  throw new Error(
1618
- `Failed to get margin manager base balance: ${res.effects?.status?.error || 'Unknown error'}`,
1971
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
1619
1972
  );
1620
1973
  }
1621
1974
 
1622
- const bytes = res.results[0].returnValues[0][0];
1975
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {
1976
+ throw new Error(`Failed to get margin manager base balance: Unknown error`);
1977
+ }
1978
+
1979
+ const bytes = res.commandResults[0].returnValues[0].bcs;
1623
1980
  const pool = this.#config.getPool(manager.poolKey);
1624
1981
  const baseCoin = this.#config.getCoin(pool.baseCoin);
1625
1982
 
1626
- return this.#formatTokenAmount(
1627
- BigInt(bcs.U64.parse(new Uint8Array(bytes))),
1628
- baseCoin.scalar,
1629
- decimals,
1630
- );
1983
+ return this.#formatTokenAmount(BigInt(bcs.U64.parse(bytes)), baseCoin.scalar, decimals);
1631
1984
  }
1632
1985
 
1633
1986
  /**
@@ -1644,27 +1997,26 @@ export class DeepBookClient {
1644
1997
  const tx = new Transaction();
1645
1998
  tx.add(this.marginManager.quoteBalance(manager.poolKey, manager.address));
1646
1999
 
1647
- const res = await this.client.devInspectTransactionBlock({
1648
- sender: normalizeHaneulAddress(this.#address),
1649
- transactionBlock: tx,
2000
+ const res = await this.#client.core.simulateTransaction({
2001
+ transaction: tx,
2002
+ include: { commandResults: true, effects: true },
1650
2003
  });
1651
2004
 
1652
- // Check if the transaction failed
1653
- if (!res.results || !res.results[0] || !res.results[0].returnValues) {
2005
+ if (res.FailedTransaction) {
1654
2006
  throw new Error(
1655
- `Failed to get margin manager quote balance: ${res.effects?.status?.error || 'Unknown error'}`,
2007
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
1656
2008
  );
1657
2009
  }
1658
2010
 
1659
- const bytes = res.results[0].returnValues[0][0];
2011
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {
2012
+ throw new Error(`Failed to get margin manager quote balance: Unknown error`);
2013
+ }
2014
+
2015
+ const bytes = res.commandResults[0].returnValues[0].bcs;
1660
2016
  const pool = this.#config.getPool(manager.poolKey);
1661
2017
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
1662
2018
 
1663
- return this.#formatTokenAmount(
1664
- BigInt(bcs.U64.parse(new Uint8Array(bytes))),
1665
- quoteCoin.scalar,
1666
- decimals,
1667
- );
2019
+ return this.#formatTokenAmount(BigInt(bcs.U64.parse(bytes)), quoteCoin.scalar, decimals);
1668
2020
  }
1669
2021
 
1670
2022
  /**
@@ -1681,26 +2033,139 @@ export class DeepBookClient {
1681
2033
  const tx = new Transaction();
1682
2034
  tx.add(this.marginManager.deepBalance(manager.poolKey, manager.address));
1683
2035
 
1684
- const res = await this.client.devInspectTransactionBlock({
1685
- sender: normalizeHaneulAddress(this.#address),
1686
- transactionBlock: tx,
2036
+ const res = await this.#client.core.simulateTransaction({
2037
+ transaction: tx,
2038
+ include: { commandResults: true, effects: true },
1687
2039
  });
1688
2040
 
1689
- // Check if the transaction failed
1690
- if (!res.results || !res.results[0] || !res.results[0].returnValues) {
2041
+ if (res.FailedTransaction) {
1691
2042
  throw new Error(
1692
- `Failed to get margin manager DEEP balance: ${res.effects?.status?.error || 'Unknown error'}`,
2043
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
1693
2044
  );
1694
2045
  }
1695
2046
 
1696
- const bytes = res.results[0].returnValues[0][0];
2047
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {
2048
+ throw new Error(`Failed to get margin manager DEEP balance: Unknown error`);
2049
+ }
2050
+
2051
+ const bytes = res.commandResults[0].returnValues[0].bcs;
1697
2052
  const deepCoin = this.#config.getCoin('DEEP');
1698
2053
 
1699
- return this.#formatTokenAmount(
1700
- BigInt(bcs.U64.parse(new Uint8Array(bytes))),
1701
- deepCoin.scalar,
1702
- decimals,
1703
- );
2054
+ return this.#formatTokenAmount(BigInt(bcs.U64.parse(bytes)), deepCoin.scalar, decimals);
2055
+ }
2056
+
2057
+ /**
2058
+ * @description Get base, quote, and DEEP balances for multiple margin managers in a single dry run call
2059
+ * @param {Record<string, string>} marginManagers Map of marginManagerId -> poolKey
2060
+ * @param {number} decimals Number of decimal places for formatting (default: 9)
2061
+ * @returns {Promise<Record<string, { base: string, quote: string, deep: string }>>} Object keyed by managerId
2062
+ */
2063
+ async getMarginManagerBalances(
2064
+ marginManagers: Record<string, string>,
2065
+ decimals: number = 9,
2066
+ ): Promise<Record<string, { base: string; quote: string; deep: string }>> {
2067
+ const entries = Object.entries(marginManagers);
2068
+ if (entries.length === 0) {
2069
+ return {};
2070
+ }
2071
+
2072
+ const tx = new Transaction();
2073
+
2074
+ // 3 calls per manager: base, quote, deep
2075
+ for (const [managerId, poolKey] of entries) {
2076
+ tx.add(this.marginManager.baseBalance(poolKey, managerId));
2077
+ tx.add(this.marginManager.quoteBalance(poolKey, managerId));
2078
+ tx.add(this.marginManager.deepBalance(poolKey, managerId));
2079
+ }
2080
+
2081
+ const res = await this.#client.core.simulateTransaction({
2082
+ transaction: tx,
2083
+ include: { commandResults: true, effects: true },
2084
+ });
2085
+
2086
+ if (res.FailedTransaction) {
2087
+ throw new Error(
2088
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
2089
+ );
2090
+ }
2091
+
2092
+ if (!res.commandResults) {
2093
+ throw new Error('Failed to get margin manager balances: No command results');
2094
+ }
2095
+
2096
+ const results: Record<string, { base: string; quote: string; deep: string }> = {};
2097
+ const deepCoin = this.#config.getCoin('DEEP');
2098
+
2099
+ for (let i = 0; i < entries.length; i++) {
2100
+ const [managerId, poolKey] = entries[i];
2101
+ const pool = this.#config.getPool(poolKey);
2102
+ const baseCoin = this.#config.getCoin(pool.baseCoin);
2103
+ const quoteCoin = this.#config.getCoin(pool.quoteCoin);
2104
+
2105
+ const baseResult = res.commandResults[i * 3];
2106
+ const quoteResult = res.commandResults[i * 3 + 1];
2107
+ const deepResult = res.commandResults[i * 3 + 2];
2108
+
2109
+ if (!baseResult?.returnValues || !quoteResult?.returnValues || !deepResult?.returnValues) {
2110
+ throw new Error(`Failed to get balances for margin manager ${managerId}: No return values`);
2111
+ }
2112
+
2113
+ results[managerId] = {
2114
+ base: this.#formatTokenAmount(
2115
+ BigInt(bcs.U64.parse(baseResult.returnValues[0].bcs)),
2116
+ baseCoin.scalar,
2117
+ decimals,
2118
+ ),
2119
+ quote: this.#formatTokenAmount(
2120
+ BigInt(bcs.U64.parse(quoteResult.returnValues[0].bcs)),
2121
+ quoteCoin.scalar,
2122
+ decimals,
2123
+ ),
2124
+ deep: this.#formatTokenAmount(
2125
+ BigInt(bcs.U64.parse(deepResult.returnValues[0].bcs)),
2126
+ deepCoin.scalar,
2127
+ decimals,
2128
+ ),
2129
+ };
2130
+ }
2131
+
2132
+ return results;
2133
+ }
2134
+
2135
+ /**
2136
+ * @description Get account order details for a margin manager.
2137
+ * This retrieves the balance manager from the margin manager and returns order details.
2138
+ * @param {string} marginManagerKey The key to identify the margin manager
2139
+ * @returns {Promise<Array>} Array of order details
2140
+ */
2141
+ async getMarginAccountOrderDetails(marginManagerKey: string) {
2142
+ const manager = this.#config.getMarginManager(marginManagerKey);
2143
+ const tx = new Transaction();
2144
+ tx.add(this.marginManager.getMarginAccountOrderDetails(manager.poolKey, manager.address));
2145
+
2146
+ tx.setSenderIfNotSet(normalizeHaneulAddress(this.#address));
2147
+
2148
+ const res = await this.#client.core.simulateTransaction({
2149
+ transaction: tx,
2150
+ include: { commandResults: true, effects: true },
2151
+ });
2152
+
2153
+ if (res.FailedTransaction) {
2154
+ throw new Error(
2155
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
2156
+ );
2157
+ }
2158
+
2159
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {
2160
+ throw new Error(`Failed to get conditional order IDs: Unknown error`);
2161
+ }
2162
+
2163
+ try {
2164
+ const bytes = res.commandResults[1].returnValues[0].bcs;
2165
+ return bcs.vector(Order).parse(bytes);
2166
+ } catch {
2167
+ return [];
2168
+ }
1704
2169
  }
1705
2170
 
1706
2171
  // === Margin TPSL (Take Profit / Stop Loss) Read-Only Functions ===
@@ -1715,19 +2180,23 @@ export class DeepBookClient {
1715
2180
  const tx = new Transaction();
1716
2181
  tx.add(this.marginTPSL.conditionalOrderIds(manager.poolKey, manager.address));
1717
2182
 
1718
- const res = await this.client.devInspectTransactionBlock({
1719
- sender: normalizeHaneulAddress(this.#address),
1720
- transactionBlock: tx,
2183
+ const res = await this.#client.core.simulateTransaction({
2184
+ transaction: tx,
2185
+ include: { commandResults: true, effects: true },
1721
2186
  });
1722
2187
 
1723
- if (!res.results || !res.results[0] || !res.results[0].returnValues) {
2188
+ if (res.FailedTransaction) {
1724
2189
  throw new Error(
1725
- `Failed to get conditional order IDs: ${res.effects?.status?.error || 'Unknown error'}`,
2190
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
1726
2191
  );
1727
2192
  }
1728
2193
 
1729
- const bytes = res.results[0].returnValues[0][0];
1730
- const orderIds = bcs.vector(bcs.u64()).parse(new Uint8Array(bytes));
2194
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {
2195
+ throw new Error(`Failed to get conditional order IDs: Unknown error`);
2196
+ }
2197
+
2198
+ const bytes = res.commandResults[0].returnValues[0].bcs;
2199
+ const orderIds = bcs.vector(bcs.u64()).parse(bytes);
1731
2200
  return orderIds.map((id) => id.toString());
1732
2201
  }
1733
2202
 
@@ -1742,19 +2211,23 @@ export class DeepBookClient {
1742
2211
  const tx = new Transaction();
1743
2212
  tx.add(this.marginTPSL.lowestTriggerAbovePrice(manager.poolKey, manager.address));
1744
2213
 
1745
- const res = await this.client.devInspectTransactionBlock({
1746
- sender: normalizeHaneulAddress(this.#address),
1747
- transactionBlock: tx,
2214
+ const res = await this.#client.core.simulateTransaction({
2215
+ transaction: tx,
2216
+ include: { commandResults: true, effects: true },
1748
2217
  });
1749
2218
 
1750
- if (!res.results || !res.results[0] || !res.results[0].returnValues) {
2219
+ if (res.FailedTransaction) {
1751
2220
  throw new Error(
1752
- `Failed to get lowest trigger above price: ${res.effects?.status?.error || 'Unknown error'}`,
2221
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
1753
2222
  );
1754
2223
  }
1755
2224
 
1756
- const bytes = res.results[0].returnValues[0][0];
1757
- return BigInt(bcs.U64.parse(new Uint8Array(bytes)));
2225
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {
2226
+ throw new Error(`Failed to get lowest trigger above price: Unknown error`);
2227
+ }
2228
+
2229
+ const bytes = res.commandResults[0].returnValues[0].bcs;
2230
+ return BigInt(bcs.U64.parse(bytes));
1758
2231
  }
1759
2232
 
1760
2233
  /**
@@ -1768,19 +2241,23 @@ export class DeepBookClient {
1768
2241
  const tx = new Transaction();
1769
2242
  tx.add(this.marginTPSL.highestTriggerBelowPrice(manager.poolKey, manager.address));
1770
2243
 
1771
- const res = await this.client.devInspectTransactionBlock({
1772
- sender: normalizeHaneulAddress(this.#address),
1773
- transactionBlock: tx,
2244
+ const res = await this.#client.core.simulateTransaction({
2245
+ transaction: tx,
2246
+ include: { commandResults: true, effects: true },
1774
2247
  });
1775
2248
 
1776
- if (!res.results || !res.results[0] || !res.results[0].returnValues) {
2249
+ if (res.FailedTransaction) {
1777
2250
  throw new Error(
1778
- `Failed to get highest trigger below price: ${res.effects?.status?.error || 'Unknown error'}`,
2251
+ `Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
1779
2252
  );
1780
2253
  }
1781
2254
 
1782
- const bytes = res.results[0].returnValues[0][0];
1783
- return BigInt(bcs.U64.parse(new Uint8Array(bytes)));
2255
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {
2256
+ throw new Error(`Failed to get highest trigger below price: Unknown error`);
2257
+ }
2258
+
2259
+ const bytes = res.commandResults[0].returnValues[0].bcs;
2260
+ return BigInt(bcs.U64.parse(bytes));
1784
2261
  }
1785
2262
 
1786
2263
  // === Margin Registry Functions ===
@@ -1794,13 +2271,13 @@ export class DeepBookClient {
1794
2271
  const tx = new Transaction();
1795
2272
  tx.add(this.marginRegistry.poolEnabled(poolKey));
1796
2273
 
1797
- const res = await this.client.devInspectTransactionBlock({
1798
- sender: normalizeHaneulAddress(this.#address),
1799
- transactionBlock: tx,
2274
+ const res = await this.#client.core.simulateTransaction({
2275
+ transaction: tx,
2276
+ include: { commandResults: true, effects: true },
1800
2277
  });
1801
2278
 
1802
- const bytes = res.results![0].returnValues![0][0];
1803
- return bcs.Bool.parse(new Uint8Array(bytes));
2279
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2280
+ return bcs.Bool.parse(bytes);
1804
2281
  }
1805
2282
 
1806
2283
  /**
@@ -1812,13 +2289,13 @@ export class DeepBookClient {
1812
2289
  const tx = new Transaction();
1813
2290
  tx.add(this.marginRegistry.getMarginManagerIds(owner));
1814
2291
 
1815
- const res = await this.client.devInspectTransactionBlock({
1816
- sender: normalizeHaneulAddress(this.#address),
1817
- transactionBlock: tx,
2292
+ const res = await this.#client.core.simulateTransaction({
2293
+ transaction: tx,
2294
+ include: { commandResults: true, effects: true },
1818
2295
  });
1819
2296
 
1820
- const bytes = res.results![0].returnValues![0][0];
1821
- const vecSet = VecSet(bcs.Address).parse(new Uint8Array(bytes));
2297
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2298
+ const vecSet = VecSet(bcs.Address).parse(bytes);
1822
2299
  return vecSet.contents.map((id) => normalizeHaneulAddress(id));
1823
2300
  }
1824
2301
 
@@ -1831,13 +2308,13 @@ export class DeepBookClient {
1831
2308
  const tx = new Transaction();
1832
2309
  tx.add(this.marginRegistry.baseMarginPoolId(poolKey));
1833
2310
 
1834
- const res = await this.client.devInspectTransactionBlock({
1835
- sender: normalizeHaneulAddress(this.#address),
1836
- transactionBlock: tx,
2311
+ const res = await this.#client.core.simulateTransaction({
2312
+ transaction: tx,
2313
+ include: { commandResults: true, effects: true },
1837
2314
  });
1838
2315
 
1839
- const bytes = res.results![0].returnValues![0][0];
1840
- const id = bcs.Address.parse(new Uint8Array(bytes));
2316
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2317
+ const id = bcs.Address.parse(bytes);
1841
2318
  return '0x' + id;
1842
2319
  }
1843
2320
 
@@ -1850,13 +2327,13 @@ export class DeepBookClient {
1850
2327
  const tx = new Transaction();
1851
2328
  tx.add(this.marginRegistry.quoteMarginPoolId(poolKey));
1852
2329
 
1853
- const res = await this.client.devInspectTransactionBlock({
1854
- sender: normalizeHaneulAddress(this.#address),
1855
- transactionBlock: tx,
2330
+ const res = await this.#client.core.simulateTransaction({
2331
+ transaction: tx,
2332
+ include: { commandResults: true, effects: true },
1856
2333
  });
1857
2334
 
1858
- const bytes = res.results![0].returnValues![0][0];
1859
- const id = bcs.Address.parse(new Uint8Array(bytes));
2335
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2336
+ const id = bcs.Address.parse(bytes);
1860
2337
  return '0x' + id;
1861
2338
  }
1862
2339
 
@@ -1869,13 +2346,13 @@ export class DeepBookClient {
1869
2346
  const tx = new Transaction();
1870
2347
  tx.add(this.marginRegistry.minWithdrawRiskRatio(poolKey));
1871
2348
 
1872
- const res = await this.client.devInspectTransactionBlock({
1873
- sender: normalizeHaneulAddress(this.#address),
1874
- transactionBlock: tx,
2349
+ const res = await this.#client.core.simulateTransaction({
2350
+ transaction: tx,
2351
+ include: { commandResults: true, effects: true },
1875
2352
  });
1876
2353
 
1877
- const bytes = res.results![0].returnValues![0][0];
1878
- const ratio = Number(bcs.U64.parse(new Uint8Array(bytes)));
2354
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2355
+ const ratio = Number(bcs.U64.parse(bytes));
1879
2356
  return ratio / FLOAT_SCALAR;
1880
2357
  }
1881
2358
 
@@ -1888,13 +2365,13 @@ export class DeepBookClient {
1888
2365
  const tx = new Transaction();
1889
2366
  tx.add(this.marginRegistry.minBorrowRiskRatio(poolKey));
1890
2367
 
1891
- const res = await this.client.devInspectTransactionBlock({
1892
- sender: normalizeHaneulAddress(this.#address),
1893
- transactionBlock: tx,
2368
+ const res = await this.#client.core.simulateTransaction({
2369
+ transaction: tx,
2370
+ include: { commandResults: true, effects: true },
1894
2371
  });
1895
2372
 
1896
- const bytes = res.results![0].returnValues![0][0];
1897
- const ratio = Number(bcs.U64.parse(new Uint8Array(bytes)));
2373
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2374
+ const ratio = Number(bcs.U64.parse(bytes));
1898
2375
  return ratio / FLOAT_SCALAR;
1899
2376
  }
1900
2377
 
@@ -1907,13 +2384,13 @@ export class DeepBookClient {
1907
2384
  const tx = new Transaction();
1908
2385
  tx.add(this.marginRegistry.liquidationRiskRatio(poolKey));
1909
2386
 
1910
- const res = await this.client.devInspectTransactionBlock({
1911
- sender: normalizeHaneulAddress(this.#address),
1912
- transactionBlock: tx,
2387
+ const res = await this.#client.core.simulateTransaction({
2388
+ transaction: tx,
2389
+ include: { commandResults: true, effects: true },
1913
2390
  });
1914
2391
 
1915
- const bytes = res.results![0].returnValues![0][0];
1916
- const ratio = Number(bcs.U64.parse(new Uint8Array(bytes)));
2392
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2393
+ const ratio = Number(bcs.U64.parse(bytes));
1917
2394
  return ratio / FLOAT_SCALAR;
1918
2395
  }
1919
2396
 
@@ -1926,13 +2403,13 @@ export class DeepBookClient {
1926
2403
  const tx = new Transaction();
1927
2404
  tx.add(this.marginRegistry.targetLiquidationRiskRatio(poolKey));
1928
2405
 
1929
- const res = await this.client.devInspectTransactionBlock({
1930
- sender: normalizeHaneulAddress(this.#address),
1931
- transactionBlock: tx,
2406
+ const res = await this.#client.core.simulateTransaction({
2407
+ transaction: tx,
2408
+ include: { commandResults: true, effects: true },
1932
2409
  });
1933
2410
 
1934
- const bytes = res.results![0].returnValues![0][0];
1935
- const ratio = Number(bcs.U64.parse(new Uint8Array(bytes)));
2411
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2412
+ const ratio = Number(bcs.U64.parse(bytes));
1936
2413
  return ratio / FLOAT_SCALAR;
1937
2414
  }
1938
2415
 
@@ -1945,13 +2422,13 @@ export class DeepBookClient {
1945
2422
  const tx = new Transaction();
1946
2423
  tx.add(this.marginRegistry.userLiquidationReward(poolKey));
1947
2424
 
1948
- const res = await this.client.devInspectTransactionBlock({
1949
- sender: normalizeHaneulAddress(this.#address),
1950
- transactionBlock: tx,
2425
+ const res = await this.#client.core.simulateTransaction({
2426
+ transaction: tx,
2427
+ include: { commandResults: true, effects: true },
1951
2428
  });
1952
2429
 
1953
- const bytes = res.results![0].returnValues![0][0];
1954
- const reward = Number(bcs.U64.parse(new Uint8Array(bytes)));
2430
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2431
+ const reward = Number(bcs.U64.parse(bytes));
1955
2432
  return reward / FLOAT_SCALAR;
1956
2433
  }
1957
2434
 
@@ -1964,13 +2441,13 @@ export class DeepBookClient {
1964
2441
  const tx = new Transaction();
1965
2442
  tx.add(this.marginRegistry.poolLiquidationReward(poolKey));
1966
2443
 
1967
- const res = await this.client.devInspectTransactionBlock({
1968
- sender: normalizeHaneulAddress(this.#address),
1969
- transactionBlock: tx,
2444
+ const res = await this.#client.core.simulateTransaction({
2445
+ transaction: tx,
2446
+ include: { commandResults: true, effects: true },
1970
2447
  });
1971
2448
 
1972
- const bytes = res.results![0].returnValues![0][0];
1973
- const reward = Number(bcs.U64.parse(new Uint8Array(bytes)));
2449
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2450
+ const reward = Number(bcs.U64.parse(bytes));
1974
2451
  return reward / FLOAT_SCALAR;
1975
2452
  }
1976
2453
 
@@ -1982,13 +2459,13 @@ export class DeepBookClient {
1982
2459
  const tx = new Transaction();
1983
2460
  tx.add(this.marginRegistry.allowedMaintainers());
1984
2461
 
1985
- const res = await this.client.devInspectTransactionBlock({
1986
- sender: normalizeHaneulAddress(this.#address),
1987
- transactionBlock: tx,
2462
+ const res = await this.#client.core.simulateTransaction({
2463
+ transaction: tx,
2464
+ include: { commandResults: true, effects: true },
1988
2465
  });
1989
2466
 
1990
- const bytes = res.results![0].returnValues![0][0];
1991
- const vecSet = VecSet(bcs.Address).parse(new Uint8Array(bytes));
2467
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2468
+ const vecSet = VecSet(bcs.Address).parse(bytes);
1992
2469
  return vecSet.contents.map((id) => normalizeHaneulAddress(id));
1993
2470
  }
1994
2471
 
@@ -2000,13 +2477,13 @@ export class DeepBookClient {
2000
2477
  const tx = new Transaction();
2001
2478
  tx.add(this.marginRegistry.allowedPauseCaps());
2002
2479
 
2003
- const res = await this.client.devInspectTransactionBlock({
2004
- sender: normalizeHaneulAddress(this.#address),
2005
- transactionBlock: tx,
2480
+ const res = await this.#client.core.simulateTransaction({
2481
+ transaction: tx,
2482
+ include: { commandResults: true, effects: true },
2006
2483
  });
2007
2484
 
2008
- const bytes = res.results![0].returnValues![0][0];
2009
- const vecSet = VecSet(bcs.Address).parse(new Uint8Array(bytes));
2485
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2486
+ const vecSet = VecSet(bcs.Address).parse(bytes);
2010
2487
  return vecSet.contents.map((id) => normalizeHaneulAddress(id));
2011
2488
  }
2012
2489
 
@@ -2019,13 +2496,13 @@ export class DeepBookClient {
2019
2496
  const tx = new Transaction();
2020
2497
  tx.add(this.deepBook.stablePool(poolKey));
2021
2498
 
2022
- const res = await this.client.devInspectTransactionBlock({
2023
- sender: normalizeHaneulAddress(this.#address),
2024
- transactionBlock: tx,
2499
+ const res = await this.#client.core.simulateTransaction({
2500
+ transaction: tx,
2501
+ include: { commandResults: true, effects: true },
2025
2502
  });
2026
2503
 
2027
- const bytes = res.results![0].returnValues![0][0];
2028
- return bcs.bool().parse(new Uint8Array(bytes));
2504
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2505
+ return bcs.bool().parse(bytes);
2029
2506
  }
2030
2507
 
2031
2508
  /**
@@ -2037,13 +2514,13 @@ export class DeepBookClient {
2037
2514
  const tx = new Transaction();
2038
2515
  tx.add(this.deepBook.registeredPool(poolKey));
2039
2516
 
2040
- const res = await this.client.devInspectTransactionBlock({
2041
- sender: normalizeHaneulAddress(this.#address),
2042
- transactionBlock: tx,
2517
+ const res = await this.#client.core.simulateTransaction({
2518
+ transaction: tx,
2519
+ include: { commandResults: true, effects: true },
2043
2520
  });
2044
2521
 
2045
- const bytes = res.results![0].returnValues![0][0];
2046
- return bcs.bool().parse(new Uint8Array(bytes));
2522
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2523
+ return bcs.bool().parse(bytes);
2047
2524
  }
2048
2525
 
2049
2526
  /**
@@ -2059,14 +2536,14 @@ export class DeepBookClient {
2059
2536
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
2060
2537
 
2061
2538
  tx.add(this.deepBook.getQuoteQuantityOutInputFee(poolKey, baseQuantity));
2062
- const res = await this.client.devInspectTransactionBlock({
2063
- sender: normalizeHaneulAddress(this.#address),
2064
- transactionBlock: tx,
2539
+ const res = await this.#client.core.simulateTransaction({
2540
+ transaction: tx,
2541
+ include: { commandResults: true, effects: true },
2065
2542
  });
2066
2543
 
2067
- const baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
2068
- const quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
2069
- const deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
2544
+ const baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
2545
+ const quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
2546
+ const deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
2070
2547
 
2071
2548
  return {
2072
2549
  baseQuantity,
@@ -2089,14 +2566,14 @@ export class DeepBookClient {
2089
2566
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
2090
2567
 
2091
2568
  tx.add(this.deepBook.getBaseQuantityOutInputFee(poolKey, quoteQuantity));
2092
- const res = await this.client.devInspectTransactionBlock({
2093
- sender: normalizeHaneulAddress(this.#address),
2094
- transactionBlock: tx,
2569
+ const res = await this.#client.core.simulateTransaction({
2570
+ transaction: tx,
2571
+ include: { commandResults: true, effects: true },
2095
2572
  });
2096
2573
 
2097
- const baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
2098
- const quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
2099
- const deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
2574
+ const baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
2575
+ const quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
2576
+ const deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
2100
2577
 
2101
2578
  return {
2102
2579
  quoteQuantity,
@@ -2120,14 +2597,14 @@ export class DeepBookClient {
2120
2597
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
2121
2598
 
2122
2599
  tx.add(this.deepBook.getQuantityOutInputFee(poolKey, baseQuantity, quoteQuantity));
2123
- const res = await this.client.devInspectTransactionBlock({
2124
- sender: normalizeHaneulAddress(this.#address),
2125
- transactionBlock: tx,
2600
+ const res = await this.#client.core.simulateTransaction({
2601
+ transaction: tx,
2602
+ include: { commandResults: true, effects: true },
2126
2603
  });
2127
2604
 
2128
- const baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
2129
- const quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
2130
- const deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
2605
+ const baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
2606
+ const quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
2607
+ const deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
2131
2608
 
2132
2609
  return {
2133
2610
  baseQuantity,
@@ -2152,14 +2629,14 @@ export class DeepBookClient {
2152
2629
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
2153
2630
 
2154
2631
  tx.add(this.deepBook.getBaseQuantityIn(poolKey, targetQuoteQuantity, payWithDeep));
2155
- const res = await this.client.devInspectTransactionBlock({
2156
- sender: normalizeHaneulAddress(this.#address),
2157
- transactionBlock: tx,
2632
+ const res = await this.#client.core.simulateTransaction({
2633
+ transaction: tx,
2634
+ include: { commandResults: true, effects: true },
2158
2635
  });
2159
2636
 
2160
- const baseIn = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
2161
- const quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
2162
- const deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
2637
+ const baseIn = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
2638
+ const quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
2639
+ const deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
2163
2640
 
2164
2641
  return {
2165
2642
  baseIn: Number((baseIn / baseScalar).toFixed(9)),
@@ -2182,14 +2659,14 @@ export class DeepBookClient {
2182
2659
  const quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;
2183
2660
 
2184
2661
  tx.add(this.deepBook.getQuoteQuantityIn(poolKey, targetBaseQuantity, payWithDeep));
2185
- const res = await this.client.devInspectTransactionBlock({
2186
- sender: normalizeHaneulAddress(this.#address),
2187
- transactionBlock: tx,
2662
+ const res = await this.#client.core.simulateTransaction({
2663
+ transaction: tx,
2664
+ include: { commandResults: true, effects: true },
2188
2665
  });
2189
2666
 
2190
- const baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
2191
- const quoteIn = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
2192
- const deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));
2667
+ const baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
2668
+ const quoteIn = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
2669
+ const deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
2193
2670
 
2194
2671
  return {
2195
2672
  baseOut: Number((baseOut / baseScalar).toFixed(9)),
@@ -2208,13 +2685,13 @@ export class DeepBookClient {
2208
2685
  const tx = new Transaction();
2209
2686
  tx.add(this.deepBook.getAccountOrderDetails(poolKey, managerKey));
2210
2687
 
2211
- const res = await this.client.devInspectTransactionBlock({
2212
- sender: normalizeHaneulAddress(this.#address),
2213
- transactionBlock: tx,
2688
+ const res = await this.#client.core.simulateTransaction({
2689
+ transaction: tx,
2690
+ include: { commandResults: true, effects: true },
2214
2691
  });
2215
2692
 
2216
2693
  try {
2217
- const orderInformation = res.results![0].returnValues![0][0];
2694
+ const orderInformation = res.commandResults![0].returnValues[0].bcs;
2218
2695
  return bcs.vector(Order).parse(new Uint8Array(orderInformation));
2219
2696
  } catch {
2220
2697
  return [];
@@ -2232,17 +2709,13 @@ export class DeepBookClient {
2232
2709
  const tx = new Transaction();
2233
2710
  tx.add(this.deepBook.getOrderDeepRequired(poolKey, baseQuantity, price));
2234
2711
 
2235
- const res = await this.client.devInspectTransactionBlock({
2236
- sender: normalizeHaneulAddress(this.#address),
2237
- transactionBlock: tx,
2712
+ const res = await this.#client.core.simulateTransaction({
2713
+ transaction: tx,
2714
+ include: { commandResults: true, effects: true },
2238
2715
  });
2239
2716
 
2240
- const deepRequiredTaker = Number(
2241
- bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])),
2242
- );
2243
- const deepRequiredMaker = Number(
2244
- bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])),
2245
- );
2717
+ const deepRequiredTaker = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
2718
+ const deepRequiredMaker = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
2246
2719
 
2247
2720
  return {
2248
2721
  deepRequiredTaker: Number((deepRequiredTaker / DEEP_SCALAR).toFixed(9)),
@@ -2260,13 +2733,13 @@ export class DeepBookClient {
2260
2733
  const tx = new Transaction();
2261
2734
  tx.add(this.deepBook.accountExists(poolKey, managerKey));
2262
2735
 
2263
- const res = await this.client.devInspectTransactionBlock({
2264
- sender: normalizeHaneulAddress(this.#address),
2265
- transactionBlock: tx,
2736
+ const res = await this.#client.core.simulateTransaction({
2737
+ transaction: tx,
2738
+ include: { commandResults: true, effects: true },
2266
2739
  });
2267
2740
 
2268
- const bytes = res.results![0].returnValues![0][0];
2269
- return bcs.bool().parse(new Uint8Array(bytes));
2741
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2742
+ return bcs.bool().parse(bytes);
2270
2743
  }
2271
2744
 
2272
2745
  /**
@@ -2278,16 +2751,14 @@ export class DeepBookClient {
2278
2751
  const tx = new Transaction();
2279
2752
  tx.add(this.deepBook.poolTradeParamsNext(poolKey));
2280
2753
 
2281
- const res = await this.client.devInspectTransactionBlock({
2282
- sender: normalizeHaneulAddress(this.#address),
2283
- transactionBlock: tx,
2754
+ const res = await this.#client.core.simulateTransaction({
2755
+ transaction: tx,
2756
+ include: { commandResults: true, effects: true },
2284
2757
  });
2285
2758
 
2286
- const takerFee = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));
2287
- const makerFee = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));
2288
- const stakeRequired = Number(
2289
- bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])),
2290
- );
2759
+ const takerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
2760
+ const makerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
2761
+ const stakeRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
2291
2762
 
2292
2763
  return {
2293
2764
  takerFee: takerFee / FLOAT_SCALAR,
@@ -2305,13 +2776,13 @@ export class DeepBookClient {
2305
2776
  const tx = new Transaction();
2306
2777
  tx.add(this.deepBook.quorum(poolKey));
2307
2778
 
2308
- const res = await this.client.devInspectTransactionBlock({
2309
- sender: normalizeHaneulAddress(this.#address),
2310
- transactionBlock: tx,
2779
+ const res = await this.#client.core.simulateTransaction({
2780
+ transaction: tx,
2781
+ include: { commandResults: true, effects: true },
2311
2782
  });
2312
2783
 
2313
- const bytes = res.results![0].returnValues![0][0];
2314
- const quorum = Number(bcs.U64.parse(new Uint8Array(bytes)));
2784
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2785
+ const quorum = Number(bcs.U64.parse(bytes));
2315
2786
  return quorum / DEEP_SCALAR;
2316
2787
  }
2317
2788
 
@@ -2324,13 +2795,13 @@ export class DeepBookClient {
2324
2795
  const tx = new Transaction();
2325
2796
  tx.add(this.deepBook.poolId(poolKey));
2326
2797
 
2327
- const res = await this.client.devInspectTransactionBlock({
2328
- sender: normalizeHaneulAddress(this.#address),
2329
- transactionBlock: tx,
2798
+ const res = await this.#client.core.simulateTransaction({
2799
+ transaction: tx,
2800
+ include: { commandResults: true, effects: true },
2330
2801
  });
2331
2802
 
2332
- const bytes = res.results![0].returnValues![0][0];
2333
- return normalizeHaneulAddress(bcs.Address.parse(new Uint8Array(bytes)));
2803
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2804
+ return normalizeHaneulAddress(bcs.Address.parse(bytes));
2334
2805
  }
2335
2806
 
2336
2807
  /**
@@ -2342,13 +2813,13 @@ export class DeepBookClient {
2342
2813
  const tx = new Transaction();
2343
2814
  tx.add(this.deepBook.canPlaceLimitOrder(params));
2344
2815
 
2345
- const res = await this.client.devInspectTransactionBlock({
2346
- sender: normalizeHaneulAddress(this.#address),
2347
- transactionBlock: tx,
2816
+ const res = await this.#client.core.simulateTransaction({
2817
+ transaction: tx,
2818
+ include: { commandResults: true, effects: true },
2348
2819
  });
2349
2820
 
2350
- const bytes = res.results![0].returnValues![0][0];
2351
- return bcs.bool().parse(new Uint8Array(bytes));
2821
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2822
+ return bcs.bool().parse(bytes);
2352
2823
  }
2353
2824
 
2354
2825
  /**
@@ -2360,13 +2831,13 @@ export class DeepBookClient {
2360
2831
  const tx = new Transaction();
2361
2832
  tx.add(this.deepBook.canPlaceMarketOrder(params));
2362
2833
 
2363
- const res = await this.client.devInspectTransactionBlock({
2364
- sender: normalizeHaneulAddress(this.#address),
2365
- transactionBlock: tx,
2834
+ const res = await this.#client.core.simulateTransaction({
2835
+ transaction: tx,
2836
+ include: { commandResults: true, effects: true },
2366
2837
  });
2367
2838
 
2368
- const bytes = res.results![0].returnValues![0][0];
2369
- return bcs.bool().parse(new Uint8Array(bytes));
2839
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2840
+ return bcs.bool().parse(bytes);
2370
2841
  }
2371
2842
 
2372
2843
  /**
@@ -2379,13 +2850,13 @@ export class DeepBookClient {
2379
2850
  const tx = new Transaction();
2380
2851
  tx.add(this.deepBook.checkMarketOrderParams(poolKey, quantity));
2381
2852
 
2382
- const res = await this.client.devInspectTransactionBlock({
2383
- sender: normalizeHaneulAddress(this.#address),
2384
- transactionBlock: tx,
2853
+ const res = await this.#client.core.simulateTransaction({
2854
+ transaction: tx,
2855
+ include: { commandResults: true, effects: true },
2385
2856
  });
2386
2857
 
2387
- const bytes = res.results![0].returnValues![0][0];
2388
- return bcs.bool().parse(new Uint8Array(bytes));
2858
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2859
+ return bcs.bool().parse(bytes);
2389
2860
  }
2390
2861
 
2391
2862
  /**
@@ -2405,13 +2876,13 @@ export class DeepBookClient {
2405
2876
  const tx = new Transaction();
2406
2877
  tx.add(this.deepBook.checkLimitOrderParams(poolKey, price, quantity, expireTimestamp));
2407
2878
 
2408
- const res = await this.client.devInspectTransactionBlock({
2409
- sender: normalizeHaneulAddress(this.#address),
2410
- transactionBlock: tx,
2879
+ const res = await this.#client.core.simulateTransaction({
2880
+ transaction: tx,
2881
+ include: { commandResults: true, effects: true },
2411
2882
  });
2412
2883
 
2413
- const bytes = res.results![0].returnValues![0][0];
2414
- return bcs.bool().parse(new Uint8Array(bytes));
2884
+ const bytes = res.commandResults![0].returnValues[0].bcs;
2885
+ return bcs.bool().parse(bytes);
2415
2886
  }
2416
2887
 
2417
2888
  /**