@haneullabs/deepbook-v3 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (378) hide show
  1. package/CHANGELOG.md +984 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/client.d.ts +861 -0
  4. package/dist/cjs/client.js +1982 -0
  5. package/dist/cjs/client.js.map +7 -0
  6. package/dist/cjs/contracts/deepbook/account.d.ts +105 -0
  7. package/dist/cjs/contracts/deepbook/account.js +163 -0
  8. package/dist/cjs/contracts/deepbook/account.js.map +7 -0
  9. package/dist/cjs/contracts/deepbook/balance_manager.d.ts +268 -0
  10. package/dist/cjs/contracts/deepbook/balance_manager.js +361 -0
  11. package/dist/cjs/contracts/deepbook/balance_manager.js.map +7 -0
  12. package/dist/cjs/contracts/deepbook/balances.d.ts +10 -0
  13. package/dist/cjs/contracts/deepbook/balances.js +35 -0
  14. package/dist/cjs/contracts/deepbook/balances.js.map +7 -0
  15. package/dist/cjs/contracts/deepbook/big_vector.d.ts +62 -0
  16. package/dist/cjs/contracts/deepbook/big_vector.js +80 -0
  17. package/dist/cjs/contracts/deepbook/big_vector.js.map +7 -0
  18. package/dist/cjs/contracts/deepbook/book.d.ts +34 -0
  19. package/dist/cjs/contracts/deepbook/book.js +50 -0
  20. package/dist/cjs/contracts/deepbook/book.js.map +7 -0
  21. package/dist/cjs/contracts/deepbook/constants.d.ts +176 -0
  22. package/dist/cjs/contracts/deepbook/constants.js +338 -0
  23. package/dist/cjs/contracts/deepbook/constants.js.map +7 -0
  24. package/dist/cjs/contracts/deepbook/deep_price.d.ts +60 -0
  25. package/dist/cjs/contracts/deepbook/deep_price.js +87 -0
  26. package/dist/cjs/contracts/deepbook/deep_price.js.map +7 -0
  27. package/dist/cjs/contracts/deepbook/deps/std/type_name.d.ts +14 -0
  28. package/dist/cjs/contracts/deepbook/deps/std/type_name.js +42 -0
  29. package/dist/cjs/contracts/deepbook/deps/std/type_name.js.map +7 -0
  30. package/dist/cjs/contracts/deepbook/deps/sui/bag.d.ts +33 -0
  31. package/dist/cjs/contracts/deepbook/deps/sui/bag.js +47 -0
  32. package/dist/cjs/contracts/deepbook/deps/sui/bag.js.map +7 -0
  33. package/dist/cjs/contracts/deepbook/deps/sui/balance.d.ts +9 -0
  34. package/dist/cjs/contracts/deepbook/deps/sui/balance.js +33 -0
  35. package/dist/cjs/contracts/deepbook/deps/sui/balance.js.map +7 -0
  36. package/dist/cjs/contracts/deepbook/deps/sui/object.d.ts +5 -0
  37. package/dist/cjs/contracts/deepbook/deps/sui/object.js +33 -0
  38. package/dist/cjs/contracts/deepbook/deps/sui/object.js.map +7 -0
  39. package/dist/cjs/contracts/deepbook/deps/sui/table.d.ts +28 -0
  40. package/dist/cjs/contracts/deepbook/deps/sui/table.js +47 -0
  41. package/dist/cjs/contracts/deepbook/deps/sui/table.js.map +7 -0
  42. package/dist/cjs/contracts/deepbook/deps/sui/vec_map.d.ts +27 -0
  43. package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js +45 -0
  44. package/dist/cjs/contracts/deepbook/deps/sui/vec_map.js.map +7 -0
  45. package/dist/cjs/contracts/deepbook/deps/sui/vec_set.d.ts +15 -0
  46. package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js +35 -0
  47. package/dist/cjs/contracts/deepbook/deps/sui/vec_set.js.map +7 -0
  48. package/dist/cjs/contracts/deepbook/deps/sui/versioned.d.ts +7 -0
  49. package/dist/cjs/contracts/deepbook/deps/sui/versioned.js +45 -0
  50. package/dist/cjs/contracts/deepbook/deps/sui/versioned.js.map +7 -0
  51. package/dist/cjs/contracts/deepbook/ewma.d.ts +17 -0
  52. package/dist/cjs/contracts/deepbook/ewma.js +39 -0
  53. package/dist/cjs/contracts/deepbook/ewma.js.map +7 -0
  54. package/dist/cjs/contracts/deepbook/fill.d.ts +153 -0
  55. package/dist/cjs/contracts/deepbook/fill.js +251 -0
  56. package/dist/cjs/contracts/deepbook/fill.js.map +7 -0
  57. package/dist/cjs/contracts/deepbook/governance.d.ts +63 -0
  58. package/dist/cjs/contracts/deepbook/governance.js +79 -0
  59. package/dist/cjs/contracts/deepbook/governance.js.map +7 -0
  60. package/dist/cjs/contracts/deepbook/history.d.ts +60 -0
  61. package/dist/cjs/contracts/deepbook/history.js +78 -0
  62. package/dist/cjs/contracts/deepbook/history.js.map +7 -0
  63. package/dist/cjs/contracts/deepbook/math.d.ts +94 -0
  64. package/dist/cjs/contracts/deepbook/math.js +132 -0
  65. package/dist/cjs/contracts/deepbook/math.js.map +7 -0
  66. package/dist/cjs/contracts/deepbook/order.d.ts +135 -0
  67. package/dist/cjs/contracts/deepbook/order.js +218 -0
  68. package/dist/cjs/contracts/deepbook/order.js.map +7 -0
  69. package/dist/cjs/contracts/deepbook/order_info.d.ts +296 -0
  70. package/dist/cjs/contracts/deepbook/order_info.js +386 -0
  71. package/dist/cjs/contracts/deepbook/order_info.js.map +7 -0
  72. package/dist/cjs/contracts/deepbook/order_query.d.ts +85 -0
  73. package/dist/cjs/contracts/deepbook/order_query.js +96 -0
  74. package/dist/cjs/contracts/deepbook/order_query.js.map +7 -0
  75. package/dist/cjs/contracts/deepbook/pool.d.ts +1218 -0
  76. package/dist/cjs/contracts/deepbook/pool.js +1236 -0
  77. package/dist/cjs/contracts/deepbook/pool.js.map +7 -0
  78. package/dist/cjs/contracts/deepbook/registry.d.ts +134 -0
  79. package/dist/cjs/contracts/deepbook/registry.js +182 -0
  80. package/dist/cjs/contracts/deepbook/registry.js.map +7 -0
  81. package/dist/cjs/contracts/deepbook/state.d.ts +117 -0
  82. package/dist/cjs/contracts/deepbook/state.js +104 -0
  83. package/dist/cjs/contracts/deepbook/state.js.map +7 -0
  84. package/dist/cjs/contracts/deepbook/trade_params.d.ts +7 -0
  85. package/dist/cjs/contracts/deepbook/trade_params.js +35 -0
  86. package/dist/cjs/contracts/deepbook/trade_params.js.map +7 -0
  87. package/dist/cjs/contracts/deepbook/vault.d.ts +30 -0
  88. package/dist/cjs/contracts/deepbook/vault.js +65 -0
  89. package/dist/cjs/contracts/deepbook/vault.js.map +7 -0
  90. package/dist/cjs/contracts/utils/index.d.ts +25 -0
  91. package/dist/cjs/contracts/utils/index.js +148 -0
  92. package/dist/cjs/contracts/utils/index.js.map +7 -0
  93. package/dist/cjs/index.d.ts +23 -0
  94. package/dist/cjs/index.js +81 -0
  95. package/dist/cjs/index.js.map +7 -0
  96. package/dist/cjs/package.json +4 -0
  97. package/dist/cjs/pyth/PriceServiceConnection.d.ts +26 -0
  98. package/dist/cjs/pyth/PriceServiceConnection.js +68 -0
  99. package/dist/cjs/pyth/PriceServiceConnection.js.map +7 -0
  100. package/dist/cjs/pyth/pyth-helpers.d.ts +7 -0
  101. package/dist/cjs/pyth/pyth-helpers.js +36 -0
  102. package/dist/cjs/pyth/pyth-helpers.js.map +7 -0
  103. package/dist/cjs/pyth/pyth.d.ts +65 -0
  104. package/dist/cjs/pyth/pyth.js +269 -0
  105. package/dist/cjs/pyth/pyth.js.map +7 -0
  106. package/dist/cjs/transactions/balanceManager.d.ts +168 -0
  107. package/dist/cjs/transactions/balanceManager.js +384 -0
  108. package/dist/cjs/transactions/balanceManager.js.map +7 -0
  109. package/dist/cjs/transactions/deepbook.d.ts +477 -0
  110. package/dist/cjs/transactions/deepbook.js +1335 -0
  111. package/dist/cjs/transactions/deepbook.js.map +7 -0
  112. package/dist/cjs/transactions/deepbookAdmin.d.ts +105 -0
  113. package/dist/cjs/transactions/deepbookAdmin.js +334 -0
  114. package/dist/cjs/transactions/deepbookAdmin.js.map +7 -0
  115. package/dist/cjs/transactions/flashLoans.d.ts +56 -0
  116. package/dist/cjs/transactions/flashLoans.js +124 -0
  117. package/dist/cjs/transactions/flashLoans.js.map +7 -0
  118. package/dist/cjs/transactions/governance.d.ts +42 -0
  119. package/dist/cjs/transactions/governance.js +135 -0
  120. package/dist/cjs/transactions/governance.js.map +7 -0
  121. package/dist/cjs/transactions/marginAdmin.d.ts +133 -0
  122. package/dist/cjs/transactions/marginAdmin.js +393 -0
  123. package/dist/cjs/transactions/marginAdmin.js.map +7 -0
  124. package/dist/cjs/transactions/marginLiquidations.d.ts +61 -0
  125. package/dist/cjs/transactions/marginLiquidations.js +173 -0
  126. package/dist/cjs/transactions/marginLiquidations.js.map +7 -0
  127. package/dist/cjs/transactions/marginMaintainer.d.ts +80 -0
  128. package/dist/cjs/transactions/marginMaintainer.js +251 -0
  129. package/dist/cjs/transactions/marginMaintainer.js.map +7 -0
  130. package/dist/cjs/transactions/marginManager.d.ts +236 -0
  131. package/dist/cjs/transactions/marginManager.js +688 -0
  132. package/dist/cjs/transactions/marginManager.js.map +7 -0
  133. package/dist/cjs/transactions/marginPool.d.ts +134 -0
  134. package/dist/cjs/transactions/marginPool.js +330 -0
  135. package/dist/cjs/transactions/marginPool.js.map +7 -0
  136. package/dist/cjs/transactions/marginRegistry.d.ts +94 -0
  137. package/dist/cjs/transactions/marginRegistry.js +221 -0
  138. package/dist/cjs/transactions/marginRegistry.js.map +7 -0
  139. package/dist/cjs/transactions/marginTPSL.d.ts +93 -0
  140. package/dist/cjs/transactions/marginTPSL.js +286 -0
  141. package/dist/cjs/transactions/marginTPSL.js.map +7 -0
  142. package/dist/cjs/transactions/poolProxy.d.ts +104 -0
  143. package/dist/cjs/transactions/poolProxy.js +435 -0
  144. package/dist/cjs/transactions/poolProxy.js.map +7 -0
  145. package/dist/cjs/types/bcs.d.ts +5 -0
  146. package/dist/cjs/types/bcs.js +33 -0
  147. package/dist/cjs/types/bcs.js.map +7 -0
  148. package/dist/cjs/types/index.d.ts +218 -0
  149. package/dist/cjs/types/index.js +38 -0
  150. package/dist/cjs/types/index.js.map +7 -0
  151. package/dist/cjs/utils/config.d.ts +65 -0
  152. package/dist/cjs/utils/config.js +144 -0
  153. package/dist/cjs/utils/config.js.map +7 -0
  154. package/dist/cjs/utils/constants.d.ts +76 -0
  155. package/dist/cjs/utils/constants.js +382 -0
  156. package/dist/cjs/utils/constants.js.map +7 -0
  157. package/dist/cjs/utils/errors.d.ts +42 -0
  158. package/dist/cjs/utils/errors.js +70 -0
  159. package/dist/cjs/utils/errors.js.map +7 -0
  160. package/dist/cjs/utils/validation.d.ts +50 -0
  161. package/dist/cjs/utils/validation.js +67 -0
  162. package/dist/cjs/utils/validation.js.map +7 -0
  163. package/dist/esm/client.d.ts +861 -0
  164. package/dist/esm/client.js +1967 -0
  165. package/dist/esm/client.js.map +7 -0
  166. package/dist/esm/contracts/deepbook/account.d.ts +105 -0
  167. package/dist/esm/contracts/deepbook/account.js +133 -0
  168. package/dist/esm/contracts/deepbook/account.js.map +7 -0
  169. package/dist/esm/contracts/deepbook/balance_manager.d.ts +268 -0
  170. package/dist/esm/contracts/deepbook/balance_manager.js +331 -0
  171. package/dist/esm/contracts/deepbook/balance_manager.js.map +7 -0
  172. package/dist/esm/contracts/deepbook/balances.d.ts +10 -0
  173. package/dist/esm/contracts/deepbook/balances.js +15 -0
  174. package/dist/esm/contracts/deepbook/balances.js.map +7 -0
  175. package/dist/esm/contracts/deepbook/big_vector.d.ts +62 -0
  176. package/dist/esm/contracts/deepbook/big_vector.js +50 -0
  177. package/dist/esm/contracts/deepbook/big_vector.js.map +7 -0
  178. package/dist/esm/contracts/deepbook/book.d.ts +34 -0
  179. package/dist/esm/contracts/deepbook/book.js +20 -0
  180. package/dist/esm/contracts/deepbook/book.js.map +7 -0
  181. package/dist/esm/contracts/deepbook/constants.d.ts +176 -0
  182. package/dist/esm/contracts/deepbook/constants.js +318 -0
  183. package/dist/esm/contracts/deepbook/constants.js.map +7 -0
  184. package/dist/esm/contracts/deepbook/deep_price.d.ts +60 -0
  185. package/dist/esm/contracts/deepbook/deep_price.js +67 -0
  186. package/dist/esm/contracts/deepbook/deep_price.js.map +7 -0
  187. package/dist/esm/contracts/deepbook/deps/std/type_name.d.ts +14 -0
  188. package/dist/esm/contracts/deepbook/deps/std/type_name.js +22 -0
  189. package/dist/esm/contracts/deepbook/deps/std/type_name.js.map +7 -0
  190. package/dist/esm/contracts/deepbook/deps/sui/bag.d.ts +33 -0
  191. package/dist/esm/contracts/deepbook/deps/sui/bag.js +17 -0
  192. package/dist/esm/contracts/deepbook/deps/sui/bag.js.map +7 -0
  193. package/dist/esm/contracts/deepbook/deps/sui/balance.d.ts +9 -0
  194. package/dist/esm/contracts/deepbook/deps/sui/balance.js +13 -0
  195. package/dist/esm/contracts/deepbook/deps/sui/balance.js.map +7 -0
  196. package/dist/esm/contracts/deepbook/deps/sui/object.d.ts +5 -0
  197. package/dist/esm/contracts/deepbook/deps/sui/object.js +13 -0
  198. package/dist/esm/contracts/deepbook/deps/sui/object.js.map +7 -0
  199. package/dist/esm/contracts/deepbook/deps/sui/table.d.ts +28 -0
  200. package/dist/esm/contracts/deepbook/deps/sui/table.js +17 -0
  201. package/dist/esm/contracts/deepbook/deps/sui/table.js.map +7 -0
  202. package/dist/esm/contracts/deepbook/deps/sui/vec_map.d.ts +27 -0
  203. package/dist/esm/contracts/deepbook/deps/sui/vec_map.js +25 -0
  204. package/dist/esm/contracts/deepbook/deps/sui/vec_map.js.map +7 -0
  205. package/dist/esm/contracts/deepbook/deps/sui/vec_set.d.ts +15 -0
  206. package/dist/esm/contracts/deepbook/deps/sui/vec_set.js +15 -0
  207. package/dist/esm/contracts/deepbook/deps/sui/vec_set.js.map +7 -0
  208. package/dist/esm/contracts/deepbook/deps/sui/versioned.d.ts +7 -0
  209. package/dist/esm/contracts/deepbook/deps/sui/versioned.js +15 -0
  210. package/dist/esm/contracts/deepbook/deps/sui/versioned.js.map +7 -0
  211. package/dist/esm/contracts/deepbook/ewma.d.ts +17 -0
  212. package/dist/esm/contracts/deepbook/ewma.js +19 -0
  213. package/dist/esm/contracts/deepbook/ewma.js.map +7 -0
  214. package/dist/esm/contracts/deepbook/fill.d.ts +153 -0
  215. package/dist/esm/contracts/deepbook/fill.js +221 -0
  216. package/dist/esm/contracts/deepbook/fill.js.map +7 -0
  217. package/dist/esm/contracts/deepbook/governance.d.ts +63 -0
  218. package/dist/esm/contracts/deepbook/governance.js +49 -0
  219. package/dist/esm/contracts/deepbook/governance.js.map +7 -0
  220. package/dist/esm/contracts/deepbook/history.d.ts +60 -0
  221. package/dist/esm/contracts/deepbook/history.js +48 -0
  222. package/dist/esm/contracts/deepbook/history.js.map +7 -0
  223. package/dist/esm/contracts/deepbook/math.d.ts +94 -0
  224. package/dist/esm/contracts/deepbook/math.js +112 -0
  225. package/dist/esm/contracts/deepbook/math.js.map +7 -0
  226. package/dist/esm/contracts/deepbook/order.d.ts +135 -0
  227. package/dist/esm/contracts/deepbook/order.js +188 -0
  228. package/dist/esm/contracts/deepbook/order.js.map +7 -0
  229. package/dist/esm/contracts/deepbook/order_info.d.ts +296 -0
  230. package/dist/esm/contracts/deepbook/order_info.js +356 -0
  231. package/dist/esm/contracts/deepbook/order_info.js.map +7 -0
  232. package/dist/esm/contracts/deepbook/order_query.d.ts +85 -0
  233. package/dist/esm/contracts/deepbook/order_query.js +66 -0
  234. package/dist/esm/contracts/deepbook/order_query.js.map +7 -0
  235. package/dist/esm/contracts/deepbook/pool.d.ts +1218 -0
  236. package/dist/esm/contracts/deepbook/pool.js +1206 -0
  237. package/dist/esm/contracts/deepbook/pool.js.map +7 -0
  238. package/dist/esm/contracts/deepbook/registry.d.ts +134 -0
  239. package/dist/esm/contracts/deepbook/registry.js +152 -0
  240. package/dist/esm/contracts/deepbook/registry.js.map +7 -0
  241. package/dist/esm/contracts/deepbook/state.d.ts +117 -0
  242. package/dist/esm/contracts/deepbook/state.js +74 -0
  243. package/dist/esm/contracts/deepbook/state.js.map +7 -0
  244. package/dist/esm/contracts/deepbook/trade_params.d.ts +7 -0
  245. package/dist/esm/contracts/deepbook/trade_params.js +15 -0
  246. package/dist/esm/contracts/deepbook/trade_params.js.map +7 -0
  247. package/dist/esm/contracts/deepbook/vault.d.ts +30 -0
  248. package/dist/esm/contracts/deepbook/vault.js +35 -0
  249. package/dist/esm/contracts/deepbook/vault.js.map +7 -0
  250. package/dist/esm/contracts/utils/index.d.ts +25 -0
  251. package/dist/esm/contracts/utils/index.js +128 -0
  252. package/dist/esm/contracts/utils/index.js.map +7 -0
  253. package/dist/esm/index.d.ts +23 -0
  254. package/dist/esm/index.js +81 -0
  255. package/dist/esm/index.js.map +7 -0
  256. package/dist/esm/package.json +4 -0
  257. package/dist/esm/pyth/PriceServiceConnection.d.ts +26 -0
  258. package/dist/esm/pyth/PriceServiceConnection.js +38 -0
  259. package/dist/esm/pyth/PriceServiceConnection.js.map +7 -0
  260. package/dist/esm/pyth/pyth-helpers.d.ts +7 -0
  261. package/dist/esm/pyth/pyth-helpers.js +16 -0
  262. package/dist/esm/pyth/pyth-helpers.js.map +7 -0
  263. package/dist/esm/pyth/pyth.d.ts +65 -0
  264. package/dist/esm/pyth/pyth.js +249 -0
  265. package/dist/esm/pyth/pyth.js.map +7 -0
  266. package/dist/esm/transactions/balanceManager.d.ts +168 -0
  267. package/dist/esm/transactions/balanceManager.js +364 -0
  268. package/dist/esm/transactions/balanceManager.js.map +7 -0
  269. package/dist/esm/transactions/deepbook.d.ts +477 -0
  270. package/dist/esm/transactions/deepbook.js +1321 -0
  271. package/dist/esm/transactions/deepbook.js.map +7 -0
  272. package/dist/esm/transactions/deepbookAdmin.d.ts +105 -0
  273. package/dist/esm/transactions/deepbookAdmin.js +314 -0
  274. package/dist/esm/transactions/deepbookAdmin.js.map +7 -0
  275. package/dist/esm/transactions/flashLoans.d.ts +56 -0
  276. package/dist/esm/transactions/flashLoans.js +104 -0
  277. package/dist/esm/transactions/flashLoans.js.map +7 -0
  278. package/dist/esm/transactions/governance.d.ts +42 -0
  279. package/dist/esm/transactions/governance.js +115 -0
  280. package/dist/esm/transactions/governance.js.map +7 -0
  281. package/dist/esm/transactions/marginAdmin.d.ts +133 -0
  282. package/dist/esm/transactions/marginAdmin.js +373 -0
  283. package/dist/esm/transactions/marginAdmin.js.map +7 -0
  284. package/dist/esm/transactions/marginLiquidations.d.ts +61 -0
  285. package/dist/esm/transactions/marginLiquidations.js +153 -0
  286. package/dist/esm/transactions/marginLiquidations.js.map +7 -0
  287. package/dist/esm/transactions/marginMaintainer.d.ts +80 -0
  288. package/dist/esm/transactions/marginMaintainer.js +231 -0
  289. package/dist/esm/transactions/marginMaintainer.js.map +7 -0
  290. package/dist/esm/transactions/marginManager.d.ts +236 -0
  291. package/dist/esm/transactions/marginManager.js +668 -0
  292. package/dist/esm/transactions/marginManager.js.map +7 -0
  293. package/dist/esm/transactions/marginPool.d.ts +134 -0
  294. package/dist/esm/transactions/marginPool.js +310 -0
  295. package/dist/esm/transactions/marginPool.js.map +7 -0
  296. package/dist/esm/transactions/marginRegistry.d.ts +94 -0
  297. package/dist/esm/transactions/marginRegistry.js +201 -0
  298. package/dist/esm/transactions/marginRegistry.js.map +7 -0
  299. package/dist/esm/transactions/marginTPSL.d.ts +93 -0
  300. package/dist/esm/transactions/marginTPSL.js +266 -0
  301. package/dist/esm/transactions/marginTPSL.js.map +7 -0
  302. package/dist/esm/transactions/poolProxy.d.ts +104 -0
  303. package/dist/esm/transactions/poolProxy.js +415 -0
  304. package/dist/esm/transactions/poolProxy.js.map +7 -0
  305. package/dist/esm/types/bcs.d.ts +5 -0
  306. package/dist/esm/types/bcs.js +13 -0
  307. package/dist/esm/types/bcs.js.map +7 -0
  308. package/dist/esm/types/index.d.ts +218 -0
  309. package/dist/esm/types/index.js +18 -0
  310. package/dist/esm/types/index.js.map +7 -0
  311. package/dist/esm/utils/config.d.ts +65 -0
  312. package/dist/esm/utils/config.js +135 -0
  313. package/dist/esm/utils/config.js.map +7 -0
  314. package/dist/esm/utils/constants.d.ts +76 -0
  315. package/dist/esm/utils/constants.js +362 -0
  316. package/dist/esm/utils/constants.js.map +7 -0
  317. package/dist/esm/utils/errors.d.ts +42 -0
  318. package/dist/esm/utils/errors.js +50 -0
  319. package/dist/esm/utils/errors.js.map +7 -0
  320. package/dist/esm/utils/validation.d.ts +50 -0
  321. package/dist/esm/utils/validation.js +47 -0
  322. package/dist/esm/utils/validation.js.map +7 -0
  323. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  324. package/dist/tsconfig.tsbuildinfo +1 -0
  325. package/package.json +63 -0
  326. package/src/client.ts +2451 -0
  327. package/src/contracts/deepbook/account.ts +199 -0
  328. package/src/contracts/deepbook/balance_manager.ts +532 -0
  329. package/src/contracts/deepbook/balances.ts +19 -0
  330. package/src/contracts/deepbook/big_vector.ts +74 -0
  331. package/src/contracts/deepbook/book.ts +24 -0
  332. package/src/contracts/deepbook/constants.ts +458 -0
  333. package/src/contracts/deepbook/deep_price.ts +84 -0
  334. package/src/contracts/deepbook/deps/std/type_name.ts +23 -0
  335. package/src/contracts/deepbook/deps/sui/bag.ts +41 -0
  336. package/src/contracts/deepbook/deps/sui/balance.ts +18 -0
  337. package/src/contracts/deepbook/deps/sui/object.ts +14 -0
  338. package/src/contracts/deepbook/deps/sui/table.ts +36 -0
  339. package/src/contracts/deepbook/deps/sui/vec_map.ts +33 -0
  340. package/src/contracts/deepbook/deps/sui/vec_set.ts +22 -0
  341. package/src/contracts/deepbook/deps/sui/versioned.ts +13 -0
  342. package/src/contracts/deepbook/ewma.ts +26 -0
  343. package/src/contracts/deepbook/fill.ts +336 -0
  344. package/src/contracts/deepbook/governance.ts +52 -0
  345. package/src/contracts/deepbook/history.ts +51 -0
  346. package/src/contracts/deepbook/math.ts +210 -0
  347. package/src/contracts/deepbook/order.ts +269 -0
  348. package/src/contracts/deepbook/order_info.ts +513 -0
  349. package/src/contracts/deepbook/order_query.ts +115 -0
  350. package/src/contracts/deepbook/pool.ts +2269 -0
  351. package/src/contracts/deepbook/registry.ts +242 -0
  352. package/src/contracts/deepbook/state.ts +74 -0
  353. package/src/contracts/deepbook/trade_params.ts +16 -0
  354. package/src/contracts/deepbook/vault.ts +37 -0
  355. package/src/contracts/utils/index.ts +184 -0
  356. package/src/index.ts +95 -0
  357. package/src/pyth/PriceServiceConnection.ts +48 -0
  358. package/src/pyth/pyth-helpers.ts +23 -0
  359. package/src/pyth/pyth.ts +305 -0
  360. package/src/transactions/balanceManager.ts +399 -0
  361. package/src/transactions/deepbook.ts +1519 -0
  362. package/src/transactions/deepbookAdmin.ts +332 -0
  363. package/src/transactions/flashLoans.ts +123 -0
  364. package/src/transactions/governance.ts +123 -0
  365. package/src/transactions/marginAdmin.ts +396 -0
  366. package/src/transactions/marginLiquidations.ts +175 -0
  367. package/src/transactions/marginMaintainer.ts +280 -0
  368. package/src/transactions/marginManager.ts +708 -0
  369. package/src/transactions/marginPool.ts +339 -0
  370. package/src/transactions/marginRegistry.ts +212 -0
  371. package/src/transactions/marginTPSL.ts +296 -0
  372. package/src/transactions/poolProxy.ts +438 -0
  373. package/src/types/bcs.ts +8 -0
  374. package/src/types/index.ts +255 -0
  375. package/src/utils/config.ts +177 -0
  376. package/src/utils/constants.ts +374 -0
  377. package/src/utils/errors.ts +67 -0
  378. package/src/utils/validation.ts +91 -0
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
26
+ var marginLiquidations_exports = {};
27
+ __export(marginLiquidations_exports, {
28
+ MarginLiquidationsContract: () => MarginLiquidationsContract
29
+ });
30
+ module.exports = __toCommonJS(marginLiquidations_exports);
31
+ var import_transactions = require("@haneullabs/haneul/transactions");
32
+ var _config;
33
+ class MarginLiquidationsContract {
34
+ /**
35
+ * @param {DeepBookConfig} config Configuration for MarginLiquidationsContract
36
+ */
37
+ constructor(config) {
38
+ __privateAdd(this, _config);
39
+ /**
40
+ * @description Create a new liquidation vault
41
+ * @param {string} liquidationAdminCap The liquidation admin cap object ID
42
+ * @returns A function that takes a Transaction object
43
+ */
44
+ this.createLiquidationVault = (liquidationAdminCap) => (tx) => {
45
+ tx.moveCall({
46
+ target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::create_liquidation_vault`,
47
+ arguments: [tx.object(liquidationAdminCap)]
48
+ });
49
+ };
50
+ /**
51
+ * @description Deposit coins into a liquidation vault
52
+ * @param {string} vaultId The liquidation vault object ID
53
+ * @param {string} liquidationAdminCap The liquidation admin cap object ID
54
+ * @param {string} coinKey The key to identify the coin type
55
+ * @param {number} amount The amount to deposit
56
+ * @returns A function that takes a Transaction object
57
+ */
58
+ this.deposit = (vaultId, liquidationAdminCap, coinKey, amount) => (tx) => {
59
+ const coin = __privateGet(this, _config).getCoin(coinKey);
60
+ const depositCoin = (0, import_transactions.coinWithBalance)({
61
+ type: coin.type,
62
+ balance: amount * coin.scalar
63
+ });
64
+ tx.moveCall({
65
+ target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::deposit`,
66
+ arguments: [tx.object(vaultId), tx.object(liquidationAdminCap), depositCoin],
67
+ typeArguments: [coin.type]
68
+ });
69
+ };
70
+ /**
71
+ * @description Withdraw coins from a liquidation vault
72
+ * @param {string} vaultId The liquidation vault object ID
73
+ * @param {string} liquidationAdminCap The liquidation admin cap object ID
74
+ * @param {string} coinKey The key to identify the coin type
75
+ * @param {number} amount The amount to withdraw
76
+ * @returns A function that takes a Transaction object and returns the withdrawn coin
77
+ */
78
+ this.withdraw = (vaultId, liquidationAdminCap, coinKey, amount) => (tx) => {
79
+ const coin = __privateGet(this, _config).getCoin(coinKey);
80
+ return tx.moveCall({
81
+ target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::withdraw`,
82
+ arguments: [
83
+ tx.object(vaultId),
84
+ tx.object(liquidationAdminCap),
85
+ tx.pure.u64(amount * coin.scalar)
86
+ ],
87
+ typeArguments: [coin.type]
88
+ });
89
+ };
90
+ /**
91
+ * @description Liquidate a margin manager by repaying base debt
92
+ * @param {string} vaultId The liquidation vault object ID
93
+ * @param {string} managerAddress The margin manager address to liquidate
94
+ * @param {string} poolKey The key to identify the pool
95
+ * @param {number} [repayAmount] The amount to repay (in base asset units), or undefined for full liquidation
96
+ * @returns A function that takes a Transaction object
97
+ */
98
+ this.liquidateBase = (vaultId, managerAddress, poolKey, repayAmount) => (tx) => {
99
+ const pool = __privateGet(this, _config).getPool(poolKey);
100
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
101
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
102
+ const baseMarginPool = __privateGet(this, _config).getMarginPool(pool.baseCoin);
103
+ const quoteMarginPool = __privateGet(this, _config).getMarginPool(pool.quoteCoin);
104
+ const repayAmountArg = repayAmount !== void 0 ? tx.pure.option("u64", BigInt(Math.floor(repayAmount * baseCoin.scalar))) : tx.pure.option("u64", null);
105
+ tx.moveCall({
106
+ target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_base`,
107
+ arguments: [
108
+ tx.object(vaultId),
109
+ tx.object(managerAddress),
110
+ tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
111
+ tx.object(baseCoin.priceInfoObjectId),
112
+ tx.object(quoteCoin.priceInfoObjectId),
113
+ tx.object(baseMarginPool.address),
114
+ tx.object(quoteMarginPool.address),
115
+ tx.object(pool.address),
116
+ repayAmountArg,
117
+ tx.object.clock()
118
+ ],
119
+ typeArguments: [baseCoin.type, quoteCoin.type]
120
+ });
121
+ };
122
+ /**
123
+ * @description Liquidate a margin manager by repaying quote debt
124
+ * @param {string} vaultId The liquidation vault object ID
125
+ * @param {string} managerAddress The margin manager address to liquidate
126
+ * @param {string} poolKey The key to identify the pool
127
+ * @param {number} [repayAmount] The amount to repay (in quote asset units), or undefined for full liquidation
128
+ * @returns A function that takes a Transaction object
129
+ */
130
+ this.liquidateQuote = (vaultId, managerAddress, poolKey, repayAmount) => (tx) => {
131
+ const pool = __privateGet(this, _config).getPool(poolKey);
132
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
133
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
134
+ const baseMarginPool = __privateGet(this, _config).getMarginPool(pool.baseCoin);
135
+ const quoteMarginPool = __privateGet(this, _config).getMarginPool(pool.quoteCoin);
136
+ const repayAmountArg = repayAmount !== void 0 ? tx.pure.option("u64", BigInt(Math.floor(repayAmount * quoteCoin.scalar))) : tx.pure.option("u64", null);
137
+ tx.moveCall({
138
+ target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_quote`,
139
+ arguments: [
140
+ tx.object(vaultId),
141
+ tx.object(managerAddress),
142
+ tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
143
+ tx.object(baseCoin.priceInfoObjectId),
144
+ tx.object(quoteCoin.priceInfoObjectId),
145
+ tx.object(baseMarginPool.address),
146
+ tx.object(quoteMarginPool.address),
147
+ tx.object(pool.address),
148
+ repayAmountArg,
149
+ tx.object.clock()
150
+ ],
151
+ typeArguments: [baseCoin.type, quoteCoin.type]
152
+ });
153
+ };
154
+ // === Read-Only Functions ===
155
+ /**
156
+ * @description Get the balance of a specific coin type in the liquidation vault
157
+ * @param {string} vaultId The liquidation vault object ID
158
+ * @param {string} coinKey The key to identify the coin type
159
+ * @returns A function that takes a Transaction object
160
+ */
161
+ this.balance = (vaultId, coinKey) => (tx) => {
162
+ const coin = __privateGet(this, _config).getCoin(coinKey);
163
+ return tx.moveCall({
164
+ target: `${__privateGet(this, _config).LIQUIDATION_PACKAGE_ID}::liquidation_vault::balance`,
165
+ arguments: [tx.object(vaultId)],
166
+ typeArguments: [coin.type]
167
+ });
168
+ };
169
+ __privateSet(this, _config, config);
170
+ }
171
+ }
172
+ _config = new WeakMap();
173
+ //# sourceMappingURL=marginLiquidations.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/transactions/marginLiquidations.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@haneullabs/haneul/transactions';\nimport { coinWithBalance } from '@haneullabs/haneul/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\n\n/**\n * MarginLiquidationsContract class for managing LiquidationVault operations.\n */\nexport class MarginLiquidationsContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginLiquidationsContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Create a new liquidation vault\n\t * @param {string} liquidationAdminCap The liquidation admin cap object ID\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateLiquidationVault = (liquidationAdminCap: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::create_liquidation_vault`,\n\t\t\targuments: [tx.object(liquidationAdminCap)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Deposit coins into a liquidation vault\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} liquidationAdminCap The liquidation admin cap object ID\n\t * @param {string} coinKey The key to identify the coin type\n\t * @param {number} amount The amount to deposit\n\t * @returns A function that takes a Transaction object\n\t */\n\tdeposit =\n\t\t(vaultId: string, liquidationAdminCap: string, coinKey: string, amount: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositCoin = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: amount * coin.scalar,\n\t\t\t});\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::deposit`,\n\t\t\t\targuments: [tx.object(vaultId), tx.object(liquidationAdminCap), depositCoin],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Withdraw coins from a liquidation vault\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} liquidationAdminCap The liquidation admin cap object ID\n\t * @param {string} coinKey The key to identify the coin type\n\t * @param {number} amount The amount to withdraw\n\t * @returns A function that takes a Transaction object and returns the withdrawn coin\n\t */\n\twithdraw =\n\t\t(vaultId: string, liquidationAdminCap: string, coinKey: string, amount: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::withdraw`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(vaultId),\n\t\t\t\t\ttx.object(liquidationAdminCap),\n\t\t\t\t\ttx.pure.u64(amount * coin.scalar),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Liquidate a margin manager by repaying base debt\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} managerAddress The margin manager address to liquidate\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} [repayAmount] The amount to repay (in base asset units), or undefined for full liquidation\n\t * @returns A function that takes a Transaction object\n\t */\n\tliquidateBase =\n\t\t(vaultId: string, managerAddress: string, poolKey: string, repayAmount?: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\tconst baseMarginPool = this.#config.getMarginPool(pool.baseCoin);\n\t\t\tconst quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);\n\n\t\t\tconst repayAmountArg =\n\t\t\t\trepayAmount !== undefined\n\t\t\t\t\t? tx.pure.option('u64', BigInt(Math.floor(repayAmount * baseCoin.scalar)))\n\t\t\t\t\t: tx.pure.option('u64', null);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_base`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(vaultId),\n\t\t\t\t\ttx.object(managerAddress),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(baseCoin.priceInfoObjectId!),\n\t\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\t\ttx.object(baseMarginPool.address),\n\t\t\t\t\ttx.object(quoteMarginPool.address),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\trepayAmountArg,\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Liquidate a margin manager by repaying quote debt\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} managerAddress The margin manager address to liquidate\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} [repayAmount] The amount to repay (in quote asset units), or undefined for full liquidation\n\t * @returns A function that takes a Transaction object\n\t */\n\tliquidateQuote =\n\t\t(vaultId: string, managerAddress: string, poolKey: string, repayAmount?: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\tconst baseMarginPool = this.#config.getMarginPool(pool.baseCoin);\n\t\t\tconst quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);\n\n\t\t\tconst repayAmountArg =\n\t\t\t\trepayAmount !== undefined\n\t\t\t\t\t? tx.pure.option('u64', BigInt(Math.floor(repayAmount * quoteCoin.scalar)))\n\t\t\t\t\t: tx.pure.option('u64', null);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_quote`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(vaultId),\n\t\t\t\t\ttx.object(managerAddress),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(baseCoin.priceInfoObjectId!),\n\t\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\t\ttx.object(baseMarginPool.address),\n\t\t\t\t\ttx.object(quoteMarginPool.address),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\trepayAmountArg,\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\t\t};\n\n\t// === Read-Only Functions ===\n\n\t/**\n\t * @description Get the balance of a specific coin type in the liquidation vault\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} coinKey The key to identify the coin type\n\t * @returns A function that takes a Transaction object\n\t */\n\tbalance = (vaultId: string, coinKey: string) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::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AAK,IAAI;AAAA,MAC1B,CAAC;AAAA,IACF;AA5JC,uBAAK,SAAU;AAAA,EAChB;AA4JD;AAnKC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,80 @@
1
+ import type { Transaction, TransactionArgument, TransactionObjectArgument } from '@haneullabs/haneul/transactions';
2
+ import type { DeepBookConfig } from '../utils/config.js';
3
+ import type { MarginPoolConfigParams, InterestConfigParams } from '../types/index.js';
4
+ /**
5
+ * DeepBookMaintainerContract class for managing maintainer actions.
6
+ */
7
+ export declare class MarginMaintainerContract {
8
+ #private;
9
+ /**
10
+ * @param {DeepBookConfig} config Configuration for MarginMaintainerContract
11
+ */
12
+ constructor(config: DeepBookConfig);
13
+ /**
14
+ * @description Create a new margin pool
15
+ * @param {string} coinKey The key to identify the coin
16
+ * @param {TransactionArgument} poolConfig The configuration for the pool
17
+ * @returns A function that takes a Transaction object
18
+ */
19
+ createMarginPool: (coinKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => void;
20
+ /**
21
+ * @description Create a new protocol config
22
+ * @param {string} coinKey The key to identify the coin
23
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)
24
+ * @param {InterestConfigParams} interestConfig The configuration for the interest
25
+ * @returns A function that takes a Transaction object
26
+ */
27
+ newProtocolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams, interestConfig: InterestConfigParams) => (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
28
+ /**
29
+ * @description Create a new margin pool config
30
+ * @param {string} coinKey The key to identify the coin
31
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
32
+ * @returns A function that takes a Transaction object
33
+ */
34
+ newMarginPoolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
35
+ /**
36
+ * @description Create a new margin pool config with rate limit
37
+ * @param {string} coinKey The key to identify the coin
38
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit
39
+ * @returns A function that takes a Transaction object
40
+ */
41
+ newMarginPoolConfigWithRateLimit: (coinKey: string, marginPoolConfig: Required<Pick<MarginPoolConfigParams, "rateLimitCapacity" | "rateLimitRefillRatePerMs" | "rateLimitEnabled">> & MarginPoolConfigParams) => (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
42
+ /**
43
+ * @description Create a new interest config
44
+ * @param {InterestConfigParams} interestConfig The configuration for the interest
45
+ * @returns A function that takes a Transaction object
46
+ */
47
+ newInterestConfig: (interestConfig: InterestConfigParams) => (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
48
+ /**
49
+ * @description Enable a deepbook pool for loan
50
+ * @param {string} deepbookPoolKey The key to identify the deepbook pool
51
+ * @param {string} coinKey The key to identify the margin pool
52
+ * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
53
+ * @returns A function that takes a Transaction object
54
+ */
55
+ enableDeepbookPoolForLoan: (deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) => (tx: Transaction) => void;
56
+ /**
57
+ * @description Disable a deepbook pool for loan
58
+ * @param {string} deepbookPoolKey The key to identify the deepbook pool
59
+ * @param {string} coinKey The key to identify the margin pool
60
+ * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
61
+ * @returns A function that takes a Transaction object
62
+ */
63
+ disableDeepbookPoolForLoan: (deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) => (tx: Transaction) => void;
64
+ /**
65
+ * @description Update the interest params
66
+ * @param {string} coinKey The key to identify the margin pool
67
+ * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
68
+ * @param {InterestConfigParams} interestConfig The configuration for the interest
69
+ * @returns A function that takes a Transaction object
70
+ */
71
+ updateInterestParams: (coinKey: string, marginPoolCap: TransactionObjectArgument, interestConfig: InterestConfigParams) => (tx: Transaction) => void;
72
+ /**
73
+ * @description Update the margin pool config
74
+ * @param {string} coinKey The key to identify the margin pool
75
+ * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
76
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
77
+ * @returns A function that takes a Transaction object
78
+ */
79
+ updateMarginPoolConfig: (coinKey: string, marginPoolCap: TransactionObjectArgument, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => void;
80
+ }
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
26
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
27
+ var marginMaintainer_exports = {};
28
+ __export(marginMaintainer_exports, {
29
+ MarginMaintainerContract: () => MarginMaintainerContract
30
+ });
31
+ module.exports = __toCommonJS(marginMaintainer_exports);
32
+ var import_config = require("../utils/config.js");
33
+ var _config, _MarginMaintainerContract_instances, marginMaintainerCap_fn;
34
+ class MarginMaintainerContract {
35
+ /**
36
+ * @param {DeepBookConfig} config Configuration for MarginMaintainerContract
37
+ */
38
+ constructor(config) {
39
+ __privateAdd(this, _MarginMaintainerContract_instances);
40
+ __privateAdd(this, _config);
41
+ /**
42
+ * @description Create a new margin pool
43
+ * @param {string} coinKey The key to identify the coin
44
+ * @param {TransactionArgument} poolConfig The configuration for the pool
45
+ * @returns A function that takes a Transaction object
46
+ */
47
+ this.createMarginPool = (coinKey, poolConfig) => (tx) => {
48
+ const coin = __privateGet(this, _config).getCoin(coinKey);
49
+ tx.moveCall({
50
+ target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_pool::create_margin_pool`,
51
+ arguments: [
52
+ tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
53
+ poolConfig,
54
+ tx.object(__privateMethod(this, _MarginMaintainerContract_instances, marginMaintainerCap_fn).call(this)),
55
+ tx.object.clock()
56
+ ],
57
+ typeArguments: [coin.type]
58
+ });
59
+ };
60
+ /**
61
+ * @description Create a new protocol config
62
+ * @param {string} coinKey The key to identify the coin
63
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)
64
+ * @param {InterestConfigParams} interestConfig The configuration for the interest
65
+ * @returns A function that takes a Transaction object
66
+ */
67
+ this.newProtocolConfig = (coinKey, marginPoolConfig, interestConfig) => (tx) => {
68
+ const hasRateLimit = marginPoolConfig.rateLimitCapacity !== void 0 && marginPoolConfig.rateLimitRefillRatePerMs !== void 0 && marginPoolConfig.rateLimitEnabled !== void 0;
69
+ const marginPoolConfigObject = hasRateLimit ? this.newMarginPoolConfigWithRateLimit(coinKey, {
70
+ ...marginPoolConfig,
71
+ rateLimitCapacity: marginPoolConfig.rateLimitCapacity,
72
+ rateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs,
73
+ rateLimitEnabled: marginPoolConfig.rateLimitEnabled
74
+ })(tx) : this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
75
+ const interestConfigObject = this.newInterestConfig(interestConfig)(tx);
76
+ return tx.moveCall({
77
+ target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::protocol_config::new_protocol_config`,
78
+ arguments: [marginPoolConfigObject, interestConfigObject]
79
+ });
80
+ };
81
+ /**
82
+ * @description Create a new margin pool config
83
+ * @param {string} coinKey The key to identify the coin
84
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
85
+ * @returns A function that takes a Transaction object
86
+ */
87
+ this.newMarginPoolConfig = (coinKey, marginPoolConfig) => (tx) => {
88
+ const coin = __privateGet(this, _config).getCoin(coinKey);
89
+ const { supplyCap, maxUtilizationRate, referralSpread, minBorrow } = marginPoolConfig;
90
+ return tx.moveCall({
91
+ target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config`,
92
+ arguments: [
93
+ tx.pure.u64(supplyCap * coin.scalar),
94
+ tx.pure.u64(maxUtilizationRate * import_config.FLOAT_SCALAR),
95
+ tx.pure.u64(referralSpread * import_config.FLOAT_SCALAR),
96
+ tx.pure.u64(Math.round(minBorrow * coin.scalar))
97
+ ]
98
+ });
99
+ };
100
+ /**
101
+ * @description Create a new margin pool config with rate limit
102
+ * @param {string} coinKey The key to identify the coin
103
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit
104
+ * @returns A function that takes a Transaction object
105
+ */
106
+ this.newMarginPoolConfigWithRateLimit = (coinKey, marginPoolConfig) => (tx) => {
107
+ const coin = __privateGet(this, _config).getCoin(coinKey);
108
+ const {
109
+ supplyCap,
110
+ maxUtilizationRate,
111
+ referralSpread,
112
+ minBorrow,
113
+ rateLimitCapacity,
114
+ rateLimitRefillRatePerMs,
115
+ rateLimitEnabled
116
+ } = marginPoolConfig;
117
+ return tx.moveCall({
118
+ target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config_with_rate_limit`,
119
+ arguments: [
120
+ tx.pure.u64(supplyCap * coin.scalar),
121
+ tx.pure.u64(maxUtilizationRate * import_config.FLOAT_SCALAR),
122
+ tx.pure.u64(referralSpread * import_config.FLOAT_SCALAR),
123
+ tx.pure.u64(Math.round(minBorrow * coin.scalar)),
124
+ tx.pure.u64(Math.round(rateLimitCapacity * coin.scalar)),
125
+ tx.pure.u64(Math.round(rateLimitRefillRatePerMs * coin.scalar)),
126
+ tx.pure.bool(rateLimitEnabled)
127
+ ]
128
+ });
129
+ };
130
+ /**
131
+ * @description Create a new interest config
132
+ * @param {InterestConfigParams} interestConfig The configuration for the interest
133
+ * @returns A function that takes a Transaction object
134
+ */
135
+ this.newInterestConfig = (interestConfig) => (tx) => {
136
+ const { baseRate, baseSlope, optimalUtilization, excessSlope } = interestConfig;
137
+ return tx.moveCall({
138
+ target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::protocol_config::new_interest_config`,
139
+ arguments: [
140
+ tx.pure.u64(baseRate * import_config.FLOAT_SCALAR),
141
+ tx.pure.u64(baseSlope * import_config.FLOAT_SCALAR),
142
+ tx.pure.u64(optimalUtilization * import_config.FLOAT_SCALAR),
143
+ tx.pure.u64(excessSlope * import_config.FLOAT_SCALAR)
144
+ ]
145
+ });
146
+ };
147
+ /**
148
+ * @description Enable a deepbook pool for loan
149
+ * @param {string} deepbookPoolKey The key to identify the deepbook pool
150
+ * @param {string} coinKey The key to identify the margin pool
151
+ * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
152
+ * @returns A function that takes a Transaction object
153
+ */
154
+ this.enableDeepbookPoolForLoan = (deepbookPoolKey, coinKey, marginPoolCap) => (tx) => {
155
+ const deepbookPool = __privateGet(this, _config).getPool(deepbookPoolKey);
156
+ const marginPool = __privateGet(this, _config).getMarginPool(coinKey);
157
+ tx.moveCall({
158
+ target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_pool::enable_deepbook_pool_for_loan`,
159
+ arguments: [
160
+ tx.object(marginPool.address),
161
+ tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
162
+ tx.pure.id(deepbookPool.address),
163
+ tx.object(marginPoolCap),
164
+ tx.object.clock()
165
+ ],
166
+ typeArguments: [marginPool.type]
167
+ });
168
+ };
169
+ /**
170
+ * @description Disable a deepbook pool for loan
171
+ * @param {string} deepbookPoolKey The key to identify the deepbook pool
172
+ * @param {string} coinKey The key to identify the margin pool
173
+ * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
174
+ * @returns A function that takes a Transaction object
175
+ */
176
+ this.disableDeepbookPoolForLoan = (deepbookPoolKey, coinKey, marginPoolCap) => (tx) => {
177
+ const deepbookPool = __privateGet(this, _config).getPool(deepbookPoolKey);
178
+ const marginPool = __privateGet(this, _config).getMarginPool(coinKey);
179
+ tx.moveCall({
180
+ target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_pool::disable_deepbook_pool_for_loan`,
181
+ arguments: [
182
+ tx.object(marginPool.address),
183
+ tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
184
+ tx.pure.id(deepbookPool.address),
185
+ tx.object(marginPoolCap),
186
+ tx.object.clock()
187
+ ],
188
+ typeArguments: [marginPool.type]
189
+ });
190
+ };
191
+ /**
192
+ * @description Update the interest params
193
+ * @param {string} coinKey The key to identify the margin pool
194
+ * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
195
+ * @param {InterestConfigParams} interestConfig The configuration for the interest
196
+ * @returns A function that takes a Transaction object
197
+ */
198
+ this.updateInterestParams = (coinKey, marginPoolCap, interestConfig) => (tx) => {
199
+ const marginPool = __privateGet(this, _config).getMarginPool(coinKey);
200
+ const interestConfigObject = this.newInterestConfig(interestConfig)(tx);
201
+ tx.moveCall({
202
+ target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_pool::update_interest_params`,
203
+ arguments: [
204
+ tx.object(marginPool.address),
205
+ tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
206
+ interestConfigObject,
207
+ tx.object(marginPoolCap),
208
+ tx.object.clock()
209
+ ],
210
+ typeArguments: [marginPool.type]
211
+ });
212
+ };
213
+ /**
214
+ * @description Update the margin pool config
215
+ * @param {string} coinKey The key to identify the margin pool
216
+ * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
217
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
218
+ * @returns A function that takes a Transaction object
219
+ */
220
+ this.updateMarginPoolConfig = (coinKey, marginPoolCap, marginPoolConfig) => (tx) => {
221
+ const marginPool = __privateGet(this, _config).getMarginPool(coinKey);
222
+ const marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
223
+ tx.moveCall({
224
+ target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_pool::update_margin_pool_config`,
225
+ arguments: [
226
+ tx.object(marginPool.address),
227
+ tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
228
+ marginPoolConfigObject,
229
+ tx.object(marginPoolCap),
230
+ tx.object.clock()
231
+ ],
232
+ typeArguments: [marginPool.type]
233
+ });
234
+ };
235
+ __privateSet(this, _config, config);
236
+ }
237
+ }
238
+ _config = new WeakMap();
239
+ _MarginMaintainerContract_instances = new WeakSet();
240
+ /**
241
+ * @returns The admin capability required for admin operations
242
+ * @throws Error if the admin capability is not set
243
+ */
244
+ marginMaintainerCap_fn = function() {
245
+ const marginMaintainerCap = __privateGet(this, _config).marginMaintainerCap;
246
+ if (!marginMaintainerCap) {
247
+ throw new Error("MARGIN_ADMIN_CAP environment variable not set");
248
+ }
249
+ return marginMaintainerCap;
250
+ };
251
+ //# sourceMappingURL=marginMaintainer.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/transactions/marginMaintainer.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tTransaction,\n\tTransactionArgument,\n\tTransactionObjectArgument,\n} from '@haneullabs/haneul/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type { MarginPoolConfigParams, InterestConfigParams } from '../types/index.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\n\n/**\n * DeepBookMaintainerContract class for managing maintainer actions.\n */\nexport class MarginMaintainerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginMaintainerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @returns The admin capability required for admin operations\n\t * @throws Error if the admin capability is not set\n\t */\n\t#marginMaintainerCap() {\n\t\tconst marginMaintainerCap = this.#config.marginMaintainerCap;\n\t\tif (!marginMaintainerCap) {\n\t\t\tthrow new Error('MARGIN_ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn marginMaintainerCap;\n\t}\n\n\t/**\n\t * @description Create a new margin pool\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {TransactionArgument} poolConfig The configuration for the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateMarginPool = (coinKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::create_margin_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\tpoolConfig,\n\t\t\t\ttx.object(this.#marginMaintainerCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new protocol config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewProtocolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst hasRateLimit =\n\t\t\t\tmarginPoolConfig.rateLimitCapacity !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitRefillRatePerMs !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitEnabled !== undefined;\n\t\t\tconst marginPoolConfigObject = hasRateLimit\n\t\t\t\t? this.newMarginPoolConfigWithRateLimit(coinKey, {\n\t\t\t\t\t\t...marginPoolConfig,\n\t\t\t\t\t\trateLimitCapacity: marginPoolConfig.rateLimitCapacity!,\n\t\t\t\t\t\trateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs!,\n\t\t\t\t\t\trateLimitEnabled: marginPoolConfig.rateLimitEnabled!,\n\t\t\t\t\t})(tx)\n\t\t\t\t: this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_protocol_config`,\n\t\t\t\targuments: [marginPoolConfigObject, interestConfigObject],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfig =\n\t\t(coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst { supplyCap, maxUtilizationRate, referralSpread, minBorrow } = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(supplyCap * coin.scalar),\n\t\t\t\t\ttx.pure.u64(maxUtilizationRate * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(referralSpread * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(Math.round(minBorrow * coin.scalar)),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config with rate limit\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfigWithRateLimit =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: Required<\n\t\t\t\tPick<\n\t\t\t\t\tMarginPoolConfigParams,\n\t\t\t\t\t'rateLimitCapacity' | 'rateLimitRefillRatePerMs' | 'rateLimitEnabled'\n\t\t\t\t>\n\t\t\t> &\n\t\t\t\tMarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst {\n\t\t\t\tsupplyCap,\n\t\t\t\tmaxUtilizationRate,\n\t\t\t\treferralSpread,\n\t\t\t\tminBorrow,\n\t\t\t\trateLimitCapacity,\n\t\t\t\trateLimitRefillRatePerMs,\n\t\t\t\trateLimitEnabled,\n\t\t\t} = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config_with_rate_limit`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(supplyCap * coin.scalar),\n\t\t\t\t\ttx.pure.u64(maxUtilizationRate * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(referralSpread * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(Math.round(minBorrow * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(rateLimitCapacity * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(rateLimitRefillRatePerMs * coin.scalar)),\n\t\t\t\t\ttx.pure.bool(rateLimitEnabled),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new interest config\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewInterestConfig = (interestConfig: InterestConfigParams) => (tx: Transaction) => {\n\t\tconst { baseRate, baseSlope, optimalUtilization, excessSlope } = interestConfig;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_interest_config`,\n\t\t\targuments: [\n\t\t\t\ttx.pure.u64(baseRate * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(baseSlope * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(optimalUtilization * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(excessSlope * FLOAT_SCALAR),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Enable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::enable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Disable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::disable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the interest params\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateInterestParams =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_interest_params`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tinterestConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the margin pool config\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateMarginPoolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tmarginPoolConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,oBAA6B;AAX7B;AAgBO,MAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA,EAMrC,YAAY,QAAwB;AAN9B;AACN;AA2BA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmB,CAAC,SAAiB,eAAoC,CAAC,OAAoB;AAC7F,YAAM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