@waterx/sdk 2.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 (245) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +204 -0
  3. package/dist/src/client.d.ts +109 -0
  4. package/dist/src/client.js +197 -0
  5. package/dist/src/config.d.ts +229 -0
  6. package/dist/src/config.js +107 -0
  7. package/dist/src/constants.d.ts +64 -0
  8. package/dist/src/constants.js +71 -0
  9. package/dist/src/fetch.d.ts +144 -0
  10. package/dist/src/fetch.js +419 -0
  11. package/dist/src/generated/bucket_v2_framework/account.d.ts +107 -0
  12. package/dist/src/generated/bucket_v2_framework/account.js +129 -0
  13. package/dist/src/generated/bucket_v2_framework/deps/std/type_name.d.ts +17 -0
  14. package/dist/src/generated/bucket_v2_framework/deps/std/type_name.js +19 -0
  15. package/dist/src/generated/bucket_v2_framework/deps/sui/balance.d.ts +12 -0
  16. package/dist/src/generated/bucket_v2_framework/deps/sui/balance.js +14 -0
  17. package/dist/src/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +36 -0
  18. package/dist/src/generated/bucket_v2_framework/deps/sui/vec_map.js +27 -0
  19. package/dist/src/generated/bucket_v2_framework/deps/sui/vec_set.d.ts +16 -0
  20. package/dist/src/generated/bucket_v2_framework/deps/sui/vec_set.js +19 -0
  21. package/dist/src/generated/bucket_v2_framework/double.d.ts +384 -0
  22. package/dist/src/generated/bucket_v2_framework/double.js +466 -0
  23. package/dist/src/generated/bucket_v2_framework/float.d.ts +364 -0
  24. package/dist/src/generated/bucket_v2_framework/float.js +440 -0
  25. package/dist/src/generated/bucket_v2_framework/liability.d.ts +197 -0
  26. package/dist/src/generated/bucket_v2_framework/liability.js +205 -0
  27. package/dist/src/generated/bucket_v2_framework/linked_table.d.ts +384 -0
  28. package/dist/src/generated/bucket_v2_framework/linked_table.js +382 -0
  29. package/dist/src/generated/bucket_v2_framework/sheet.d.ts +424 -0
  30. package/dist/src/generated/bucket_v2_framework/sheet.js +344 -0
  31. package/dist/src/generated/native_custody/custody_vault.d.ts +572 -0
  32. package/dist/src/generated/native_custody/custody_vault.js +483 -0
  33. package/dist/src/generated/native_custody/deps/bucket_v2_framework/float.d.ts +8 -0
  34. package/dist/src/generated/native_custody/deps/bucket_v2_framework/float.js +10 -0
  35. package/dist/src/generated/native_custody/deps/bucket_v2_framework/liability.d.ts +11 -0
  36. package/dist/src/generated/native_custody/deps/bucket_v2_framework/liability.js +13 -0
  37. package/dist/src/generated/native_custody/deps/bucket_v2_framework/sheet.d.ts +49 -0
  38. package/dist/src/generated/native_custody/deps/bucket_v2_framework/sheet.js +18 -0
  39. package/dist/src/generated/native_custody/deps/std/type_name.d.ts +17 -0
  40. package/dist/src/generated/native_custody/deps/std/type_name.js +19 -0
  41. package/dist/src/generated/native_custody/deps/sui/balance.d.ts +12 -0
  42. package/dist/src/generated/native_custody/deps/sui/balance.js +14 -0
  43. package/dist/src/generated/native_custody/deps/sui/vec_map.d.ts +36 -0
  44. package/dist/src/generated/native_custody/deps/sui/vec_map.js +27 -0
  45. package/dist/src/generated/native_custody/deps/sui/vec_set.d.ts +16 -0
  46. package/dist/src/generated/native_custody/deps/sui/vec_set.js +19 -0
  47. package/dist/src/generated/native_custody/events.d.ts +36 -0
  48. package/dist/src/generated/native_custody/events.js +36 -0
  49. package/dist/src/generated/pyth_sponsor_rule/deps/sui/balance.d.ts +12 -0
  50. package/dist/src/generated/pyth_sponsor_rule/deps/sui/balance.js +14 -0
  51. package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +68 -0
  52. package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +74 -0
  53. package/dist/src/generated/utils/index.d.ts +30 -0
  54. package/dist/src/generated/utils/index.js +157 -0
  55. package/dist/src/generated/waterx_account/account.d.ts +1818 -0
  56. package/dist/src/generated/waterx_account/account.js +1723 -0
  57. package/dist/src/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +11 -0
  58. package/dist/src/generated/waterx_account/deps/bucket_v2_framework/liability.js +13 -0
  59. package/dist/src/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +49 -0
  60. package/dist/src/generated/waterx_account/deps/bucket_v2_framework/sheet.js +18 -0
  61. package/dist/src/generated/waterx_account/deps/std/type_name.d.ts +17 -0
  62. package/dist/src/generated/waterx_account/deps/std/type_name.js +19 -0
  63. package/dist/src/generated/waterx_account/deps/sui/balance.d.ts +12 -0
  64. package/dist/src/generated/waterx_account/deps/sui/balance.js +14 -0
  65. package/dist/src/generated/waterx_account/deps/sui/object_table.d.ts +17 -0
  66. package/dist/src/generated/waterx_account/deps/sui/object_table.js +19 -0
  67. package/dist/src/generated/waterx_account/deps/sui/table.d.ts +29 -0
  68. package/dist/src/generated/waterx_account/deps/sui/table.js +31 -0
  69. package/dist/src/generated/waterx_account/deps/sui/vec_map.d.ts +36 -0
  70. package/dist/src/generated/waterx_account/deps/sui/vec_map.js +27 -0
  71. package/dist/src/generated/waterx_account/deps/sui/vec_set.d.ts +16 -0
  72. package/dist/src/generated/waterx_account/deps/sui/vec_set.js +19 -0
  73. package/dist/src/generated/waterx_account/direct_rule.d.ts +77 -0
  74. package/dist/src/generated/waterx_account/direct_rule.js +78 -0
  75. package/dist/src/generated/waterx_account/events.d.ts +180 -0
  76. package/dist/src/generated/waterx_account/events.js +156 -0
  77. package/dist/src/generated/waterx_account/version.d.ts +10 -0
  78. package/dist/src/generated/waterx_account/version.js +8 -0
  79. package/dist/src/generated/waterx_credit/credit_registry.d.ts +708 -0
  80. package/dist/src/generated/waterx_credit/credit_registry.js +658 -0
  81. package/dist/src/generated/waterx_credit/deps/std/type_name.d.ts +17 -0
  82. package/dist/src/generated/waterx_credit/deps/std/type_name.js +19 -0
  83. package/dist/src/generated/waterx_credit/deps/sui/table.d.ts +29 -0
  84. package/dist/src/generated/waterx_credit/deps/sui/table.js +31 -0
  85. package/dist/src/generated/waterx_credit/deps/sui/vec_map.d.ts +36 -0
  86. package/dist/src/generated/waterx_credit/deps/sui/vec_map.js +27 -0
  87. package/dist/src/generated/waterx_credit/deps/sui/vec_set.d.ts +16 -0
  88. package/dist/src/generated/waterx_credit/deps/sui/vec_set.js +19 -0
  89. package/dist/src/generated/waterx_credit/limited_supply.d.ts +107 -0
  90. package/dist/src/generated/waterx_credit/limited_supply.js +131 -0
  91. package/dist/src/generated/waterx_oracle/aggregator.d.ts +211 -0
  92. package/dist/src/generated/waterx_oracle/aggregator.js +213 -0
  93. package/dist/src/generated/waterx_oracle/collector.d.ts +119 -0
  94. package/dist/src/generated/waterx_oracle/collector.js +105 -0
  95. package/dist/src/generated/waterx_oracle/deps/bucket_v2_framework/float.d.ts +8 -0
  96. package/dist/src/generated/waterx_oracle/deps/bucket_v2_framework/float.js +10 -0
  97. package/dist/src/generated/waterx_oracle/deps/std/type_name.d.ts +17 -0
  98. package/dist/src/generated/waterx_oracle/deps/std/type_name.js +19 -0
  99. package/dist/src/generated/waterx_oracle/deps/sui/vec_map.d.ts +36 -0
  100. package/dist/src/generated/waterx_oracle/deps/sui/vec_map.js +27 -0
  101. package/dist/src/generated/waterx_oracle/deps/sui/vec_set.d.ts +16 -0
  102. package/dist/src/generated/waterx_oracle/deps/sui/vec_set.js +19 -0
  103. package/dist/src/generated/waterx_oracle/oracle.d.ts +298 -0
  104. package/dist/src/generated/waterx_oracle/oracle.js +323 -0
  105. package/dist/src/generated/waterx_oracle/version.d.ts +10 -0
  106. package/dist/src/generated/waterx_oracle/version.js +8 -0
  107. package/dist/src/generated/waterx_perp/account_data.d.ts +269 -0
  108. package/dist/src/generated/waterx_perp/account_data.js +284 -0
  109. package/dist/src/generated/waterx_perp/admin.d.ts +19 -0
  110. package/dist/src/generated/waterx_perp/admin.js +22 -0
  111. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/double.d.ts +8 -0
  112. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/double.js +10 -0
  113. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/float.d.ts +8 -0
  114. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/float.js +10 -0
  115. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/liability.d.ts +11 -0
  116. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/liability.js +13 -0
  117. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/linked_table.d.ts +8 -0
  118. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/linked_table.js +18 -0
  119. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.d.ts +49 -0
  120. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.js +18 -0
  121. package/dist/src/generated/waterx_perp/deps/std/type_name.d.ts +17 -0
  122. package/dist/src/generated/waterx_perp/deps/std/type_name.js +19 -0
  123. package/dist/src/generated/waterx_perp/deps/sui/balance.d.ts +15 -0
  124. package/dist/src/generated/waterx_perp/deps/sui/balance.js +17 -0
  125. package/dist/src/generated/waterx_perp/deps/sui/coin.d.ts +14 -0
  126. package/dist/src/generated/waterx_perp/deps/sui/coin.js +15 -0
  127. package/dist/src/generated/waterx_perp/deps/sui/vec_map.d.ts +36 -0
  128. package/dist/src/generated/waterx_perp/deps/sui/vec_map.js +27 -0
  129. package/dist/src/generated/waterx_perp/deps/sui/vec_set.d.ts +16 -0
  130. package/dist/src/generated/waterx_perp/deps/sui/vec_set.js +19 -0
  131. package/dist/src/generated/waterx_perp/events.d.ts +1283 -0
  132. package/dist/src/generated/waterx_perp/events.js +1018 -0
  133. package/dist/src/generated/waterx_perp/global_config.d.ts +775 -0
  134. package/dist/src/generated/waterx_perp/global_config.js +836 -0
  135. package/dist/src/generated/waterx_perp/keyed_big_vector.d.ts +553 -0
  136. package/dist/src/generated/waterx_perp/keyed_big_vector.js +554 -0
  137. package/dist/src/generated/waterx_perp/lp_pool.d.ts +1648 -0
  138. package/dist/src/generated/waterx_perp/lp_pool.js +1521 -0
  139. package/dist/src/generated/waterx_perp/market_config.d.ts +715 -0
  140. package/dist/src/generated/waterx_perp/market_config.js +780 -0
  141. package/dist/src/generated/waterx_perp/math.d.ts +63 -0
  142. package/dist/src/generated/waterx_perp/math.js +64 -0
  143. package/dist/src/generated/waterx_perp/memo.d.ts +251 -0
  144. package/dist/src/generated/waterx_perp/memo.js +323 -0
  145. package/dist/src/generated/waterx_perp/order_book.d.ts +290 -0
  146. package/dist/src/generated/waterx_perp/order_book.js +329 -0
  147. package/dist/src/generated/waterx_perp/position.d.ts +1005 -0
  148. package/dist/src/generated/waterx_perp/position.js +1103 -0
  149. package/dist/src/generated/waterx_perp/request.d.ts +544 -0
  150. package/dist/src/generated/waterx_perp/request.js +541 -0
  151. package/dist/src/generated/waterx_perp/response.d.ts +247 -0
  152. package/dist/src/generated/waterx_perp/response.js +280 -0
  153. package/dist/src/generated/waterx_perp/trading.d.ts +2821 -0
  154. package/dist/src/generated/waterx_perp/trading.js +2372 -0
  155. package/dist/src/generated/waterx_perp/version.d.ts +10 -0
  156. package/dist/src/generated/waterx_perp/version.js +8 -0
  157. package/dist/src/generated/waterx_perp/witness.d.ts +18 -0
  158. package/dist/src/generated/waterx_perp/witness.js +21 -0
  159. package/dist/src/generated/waterx_perp_view/deps/std/type_name.d.ts +17 -0
  160. package/dist/src/generated/waterx_perp_view/deps/std/type_name.js +19 -0
  161. package/dist/src/generated/waterx_perp_view/view.d.ts +447 -0
  162. package/dist/src/generated/waterx_perp_view/view.js +414 -0
  163. package/dist/src/generated/waterx_pyth_rule/deps/sui/vec_map.d.ts +36 -0
  164. package/dist/src/generated/waterx_pyth_rule/deps/sui/vec_map.js +27 -0
  165. package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +90 -0
  166. package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +72 -0
  167. package/dist/src/generated/waterx_referral/deps/sui/table.d.ts +29 -0
  168. package/dist/src/generated/waterx_referral/deps/sui/table.js +31 -0
  169. package/dist/src/generated/waterx_referral/deps/sui/vec_set.d.ts +16 -0
  170. package/dist/src/generated/waterx_referral/deps/sui/vec_set.js +19 -0
  171. package/dist/src/generated/waterx_referral/referral_table.d.ts +171 -0
  172. package/dist/src/generated/waterx_referral/referral_table.js +192 -0
  173. package/dist/src/generated/waterx_staking/deps/bucket_v2_framework/double.d.ts +8 -0
  174. package/dist/src/generated/waterx_staking/deps/bucket_v2_framework/double.js +10 -0
  175. package/dist/src/generated/waterx_staking/deps/sui/balance.d.ts +12 -0
  176. package/dist/src/generated/waterx_staking/deps/sui/balance.js +14 -0
  177. package/dist/src/generated/waterx_staking/deps/sui/table.d.ts +29 -0
  178. package/dist/src/generated/waterx_staking/deps/sui/table.js +31 -0
  179. package/dist/src/generated/waterx_staking/deps/sui/vec_set.d.ts +16 -0
  180. package/dist/src/generated/waterx_staking/deps/sui/vec_set.js +19 -0
  181. package/dist/src/generated/waterx_staking/waterx_staking.d.ts +746 -0
  182. package/dist/src/generated/waterx_staking/waterx_staking.js +731 -0
  183. package/dist/src/generated/waterx_staking/witness.d.ts +16 -0
  184. package/dist/src/generated/waterx_staking/witness.js +18 -0
  185. package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/linked_table.d.ts +8 -0
  186. package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/linked_table.js +18 -0
  187. package/dist/src/generated/withdrawal_queue/deps/std/type_name.d.ts +17 -0
  188. package/dist/src/generated/withdrawal_queue/deps/std/type_name.js +19 -0
  189. package/dist/src/generated/withdrawal_queue/deps/sui/balance.d.ts +12 -0
  190. package/dist/src/generated/withdrawal_queue/deps/sui/balance.js +14 -0
  191. package/dist/src/generated/withdrawal_queue/deps/sui/vec_set.d.ts +16 -0
  192. package/dist/src/generated/withdrawal_queue/deps/sui/vec_set.js +19 -0
  193. package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +483 -0
  194. package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +480 -0
  195. package/dist/src/generated/wlp/wlp.d.ts +28 -0
  196. package/dist/src/generated/wlp/wlp.js +32 -0
  197. package/dist/src/generated/wormhole_bridge/deps/sui/table.d.ts +29 -0
  198. package/dist/src/generated/wormhole_bridge/deps/sui/table.js +31 -0
  199. package/dist/src/generated/wormhole_bridge/deps/sui/vec_map.d.ts +36 -0
  200. package/dist/src/generated/wormhole_bridge/deps/sui/vec_map.js +27 -0
  201. package/dist/src/generated/wormhole_bridge/deps/sui/vec_set.d.ts +16 -0
  202. package/dist/src/generated/wormhole_bridge/deps/sui/vec_set.js +19 -0
  203. package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/consumed_vaas.d.ts +12 -0
  204. package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/consumed_vaas.js +9 -0
  205. package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/emitter.d.ts +14 -0
  206. package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/emitter.js +16 -0
  207. package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/set.d.ts +16 -0
  208. package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/set.js +15 -0
  209. package/dist/src/generated/wormhole_bridge/events.d.ts +32 -0
  210. package/dist/src/generated/wormhole_bridge/events.js +28 -0
  211. package/dist/src/generated/wormhole_bridge/wormhole_bridge.d.ts +498 -0
  212. package/dist/src/generated/wormhole_bridge/wormhole_bridge.js +494 -0
  213. package/dist/src/index.d.ts +28 -0
  214. package/dist/src/index.js +34 -0
  215. package/dist/src/tx-builders.d.ts +242 -0
  216. package/dist/src/tx-builders.js +320 -0
  217. package/dist/src/user/account.d.ts +129 -0
  218. package/dist/src/user/account.js +166 -0
  219. package/dist/src/user/credit.d.ts +135 -0
  220. package/dist/src/user/credit.js +255 -0
  221. package/dist/src/user/custody.d.ts +71 -0
  222. package/dist/src/user/custody.js +112 -0
  223. package/dist/src/user/index.d.ts +8 -0
  224. package/dist/src/user/index.js +8 -0
  225. package/dist/src/user/order.d.ts +89 -0
  226. package/dist/src/user/order.js +134 -0
  227. package/dist/src/user/referral.d.ts +21 -0
  228. package/dist/src/user/referral.js +41 -0
  229. package/dist/src/user/staking.d.ts +54 -0
  230. package/dist/src/user/staking.js +109 -0
  231. package/dist/src/user/trading.d.ts +119 -0
  232. package/dist/src/user/trading.js +262 -0
  233. package/dist/src/user/wlp.d.ts +58 -0
  234. package/dist/src/user/wlp.js +99 -0
  235. package/dist/src/utils/account-request.d.ts +9 -0
  236. package/dist/src/utils/account-request.js +17 -0
  237. package/dist/src/utils/config.d.ts +11 -0
  238. package/dist/src/utils/config.js +15 -0
  239. package/dist/src/utils/math.d.ts +201 -0
  240. package/dist/src/utils/math.js +343 -0
  241. package/dist/src/utils/pyth.d.ts +89 -0
  242. package/dist/src/utils/pyth.js +316 -0
  243. package/dist/src/utils/wormhole.d.ts +86 -0
  244. package/dist/src/utils/wormhole.js +154 -0
  245. package/package.json +66 -0
@@ -0,0 +1,2372 @@
1
+ /**************************************************************
2
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
3
+ **************************************************************/
4
+ /**
5
+ * Core trading engine for WaterX Perp DEX.
6
+ *
7
+ * User-side path uses a hot-potato `TradingRequest<C_TOKEN>` (no abilities),
8
+ * consumed in the same PTB by `trading::execute`. `execute` does the work inline
9
+ * and returns droppable `TradingResponse` receipts — user payouts route through
10
+ * `wxa_account::put`, not back out as a `Coin<C_TOKEN>`.
11
+ *
12
+ * PTB flow:
13
+ *
14
+ * 1. let request = trading::place_order_request(...);
15
+ * 2. // External rules add witnesses: my_rule::check(&mut request, ...);
16
+ * 3. let responses = trading::execute(global_config, wxa_registry,
17
+ * market_registry, ticker, pool, request, oracle, clock, ctx);
18
+ */
19
+ import { MoveStruct, normalizeMoveArguments } from "../utils/index.js";
20
+ import { bcs } from '@mysten/sui/bcs';
21
+ import * as market_config from "./market_config.js";
22
+ import * as keyed_big_vector from "./keyed_big_vector.js";
23
+ import * as order_book from "./order_book.js";
24
+ import * as order_book_1 from "./order_book.js";
25
+ import * as order_book_2 from "./order_book.js";
26
+ import * as order_book_3 from "./order_book.js";
27
+ import * as keyed_big_vector_1 from "./keyed_big_vector.js";
28
+ import * as keyed_big_vector_2 from "./keyed_big_vector.js";
29
+ import * as vec_set from "./deps/sui/vec_set.js";
30
+ const $moduleName = '@waterx/perp::trading';
31
+ export const Market = new MoveStruct({ name: `${$moduleName}::Market<phantom LP_TOKEN>`, fields: {
32
+ id: bcs.Address,
33
+ /** Per-market configuration and state. */
34
+ config: market_config.MarketConfig,
35
+ /** Positions indexed by position_id. */
36
+ positions: keyed_big_vector.KeyedBigVector,
37
+ /** Limit buy orders: price_key → vector<Order> */
38
+ limit_buys: order_book.OrderBook,
39
+ /** Limit sell orders: price_key → vector<Order> */
40
+ limit_sells: order_book_1.OrderBook,
41
+ /** Stop buy orders: price_key → vector<Order> */
42
+ stop_buys: order_book_2.OrderBook,
43
+ /** Stop sell orders: price_key → vector<Order> */
44
+ stop_sells: order_book_3.OrderBook,
45
+ /**
46
+ * Reserved TP / SL pre-orders, keyed by the **pre-order's own `order_id`** (not
47
+ * the main order's id). Each entry is a single fully-formed reduce-only `Order`
48
+ * with `linked_position_id = None`; on main fill `activate_pending_pre_orders`
49
+ * stamps in the new position id and moves the order onto the live book.
50
+ */
51
+ pending_pre_orders: keyed_big_vector_1.KeyedBigVector,
52
+ /**
53
+ * Secondary index: `main_order_id → vector<pre_order_id>` listing the pre-orders
54
+ * reserved against each unfilled main. Used by activation / cancellation to
55
+ * enumerate the pre-orders that belong to a given main.
56
+ */
57
+ pending_pre_order_index: keyed_big_vector_2.KeyedBigVector
58
+ } });
59
+ export const MarketRegistry = new MoveStruct({ name: `${$moduleName}::MarketRegistry<phantom LP_TOKEN>`, fields: {
60
+ id: bcs.Address,
61
+ /** Allowed protocol versions (admin-managed). */
62
+ allowed_versions: vec_set.VecSet(bcs.u16()),
63
+ /** Tickers of registered markets, mirrored from the DOF for cheap iteration. */
64
+ listed_tickers: bcs.vector(bcs.string())
65
+ } });
66
+ export function actionOpenPosition(options = {}) {
67
+ const packageAddress = options.package ?? '@waterx/perp';
68
+ return (tx) => tx.moveCall({
69
+ package: packageAddress,
70
+ module: 'trading',
71
+ function: 'action_open_position',
72
+ });
73
+ }
74
+ export function actionClosePosition(options = {}) {
75
+ const packageAddress = options.package ?? '@waterx/perp';
76
+ return (tx) => tx.moveCall({
77
+ package: packageAddress,
78
+ module: 'trading',
79
+ function: 'action_close_position',
80
+ });
81
+ }
82
+ export function actionPlaceOrder(options = {}) {
83
+ const packageAddress = options.package ?? '@waterx/perp';
84
+ return (tx) => tx.moveCall({
85
+ package: packageAddress,
86
+ module: 'trading',
87
+ function: 'action_place_order',
88
+ });
89
+ }
90
+ export function actionCancelOrder(options = {}) {
91
+ const packageAddress = options.package ?? '@waterx/perp';
92
+ return (tx) => tx.moveCall({
93
+ package: packageAddress,
94
+ module: 'trading',
95
+ function: 'action_cancel_order',
96
+ });
97
+ }
98
+ export function actionDepositCollateral(options = {}) {
99
+ const packageAddress = options.package ?? '@waterx/perp';
100
+ return (tx) => tx.moveCall({
101
+ package: packageAddress,
102
+ module: 'trading',
103
+ function: 'action_deposit_collateral',
104
+ });
105
+ }
106
+ export function actionWithdrawCollateral(options = {}) {
107
+ const packageAddress = options.package ?? '@waterx/perp';
108
+ return (tx) => tx.moveCall({
109
+ package: packageAddress,
110
+ module: 'trading',
111
+ function: 'action_withdraw_collateral',
112
+ });
113
+ }
114
+ export function actionLiquidate(options = {}) {
115
+ const packageAddress = options.package ?? '@waterx/perp';
116
+ return (tx) => tx.moveCall({
117
+ package: packageAddress,
118
+ module: 'trading',
119
+ function: 'action_liquidate',
120
+ });
121
+ }
122
+ export function actionIncreasePosition(options = {}) {
123
+ const packageAddress = options.package ?? '@waterx/perp';
124
+ return (tx) => tx.moveCall({
125
+ package: packageAddress,
126
+ module: 'trading',
127
+ function: 'action_increase_position',
128
+ });
129
+ }
130
+ export function actionDecreasePosition(options = {}) {
131
+ const packageAddress = options.package ?? '@waterx/perp';
132
+ return (tx) => tx.moveCall({
133
+ package: packageAddress,
134
+ module: 'trading',
135
+ function: 'action_decrease_position',
136
+ });
137
+ }
138
+ export function actionUpdateOrder(options = {}) {
139
+ const packageAddress = options.package ?? '@waterx/perp';
140
+ return (tx) => tx.moveCall({
141
+ package: packageAddress,
142
+ module: 'trading',
143
+ function: 'action_update_order',
144
+ });
145
+ }
146
+ export function actionCancelPreOrder(options = {}) {
147
+ const packageAddress = options.package ?? '@waterx/perp';
148
+ return (tx) => tx.moveCall({
149
+ package: packageAddress,
150
+ module: 'trading',
151
+ function: 'action_cancel_pre_order',
152
+ });
153
+ }
154
+ export function actionAddPreOrder(options = {}) {
155
+ const packageAddress = options.package ?? '@waterx/perp';
156
+ return (tx) => tx.moveCall({
157
+ package: packageAddress,
158
+ module: 'trading',
159
+ function: 'action_add_pre_order',
160
+ });
161
+ }
162
+ /**
163
+ * Creates a trading market with full configuration. `trading_fee`,
164
+ * `maintenance_margin`, and `basic_funding_rate` are scaled Float values (1e9
165
+ * scale). For example, a 5 bps fee = `500_000`.
166
+ */
167
+ export function createMarket(options) {
168
+ const packageAddress = options.package ?? '@waterx/perp';
169
+ const argumentsTypes = [
170
+ null,
171
+ '0x1::string::String',
172
+ 'u64',
173
+ 'u64',
174
+ 'u128',
175
+ 'u128',
176
+ 'u128',
177
+ 'u128',
178
+ 'u64',
179
+ 'u128',
180
+ 'u64',
181
+ '0x2::clock::Clock'
182
+ ];
183
+ const parameterNames = ["Cap", "symbol", "maxLeverageBps", "minCollValue", "tradingFee", "maintenanceMargin", "maxLongOi", "maxShortOi", "cooldownMs", "basicFundingRate", "fundingIntervalMs"];
184
+ return (tx) => tx.moveCall({
185
+ package: packageAddress,
186
+ module: 'trading',
187
+ function: 'create_market',
188
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
189
+ typeArguments: options.typeArguments
190
+ });
191
+ }
192
+ /**
193
+ * Admin: forwards to `market_config::update_market_config` through the shared
194
+ * `Market`. Needed because `MarketConfig` is embedded inside `Market` and can't be
195
+ * borrowed mutably from a PTB directly. Funding parameters must be updated with
196
+ * `update_market_funding_config` so accrued funding is settled under the old
197
+ * parameters before the new parameters take effect.
198
+ */
199
+ export function updateMarketConfig(options) {
200
+ const packageAddress = options.package ?? '@waterx/perp';
201
+ const argumentsTypes = [
202
+ null,
203
+ null,
204
+ '0x1::string::String',
205
+ '0x1::option::Option<u64>',
206
+ '0x1::option::Option<u64>',
207
+ '0x1::option::Option<u128>',
208
+ '0x1::option::Option<u128>',
209
+ '0x1::option::Option<u64>',
210
+ '0x1::option::Option<u64>',
211
+ '0x1::option::Option<u64>',
212
+ '0x1::option::Option<u128>',
213
+ '0x1::option::Option<u128>',
214
+ '0x1::option::Option<u128>',
215
+ '0x1::option::Option<u64>',
216
+ '0x1::option::Option<u128>',
217
+ '0x1::option::Option<u64>',
218
+ '0x1::option::Option<u128>',
219
+ '0x1::option::Option<u64>'
220
+ ];
221
+ const parameterNames = ["marketRegistry", "cap", "ticker", "maxLeverageBps", "minCollValue", "tradingFee", "maxImpactFee", "allocatedLpExposureBps", "impactFeeCurvature", "impactFeeScale", "maintenanceMargin", "maxLongOi", "maxShortOi", "cooldownMs", "orderPriceTick", "maxPreOrders", "basicFundingRate", "fundingIntervalMs"];
222
+ return (tx) => tx.moveCall({
223
+ package: packageAddress,
224
+ module: 'trading',
225
+ function: 'update_market_config',
226
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
227
+ typeArguments: options.typeArguments
228
+ });
229
+ }
230
+ /**
231
+ * Admin: settles accrued funding under the old funding parameters, then updates
232
+ * funding parameters for future intervals.
233
+ */
234
+ export function updateMarketFundingConfig(options) {
235
+ const packageAddress = options.package ?? '@waterx/perp';
236
+ const argumentsTypes = [
237
+ null,
238
+ null,
239
+ null,
240
+ '0x1::string::String',
241
+ null,
242
+ null,
243
+ '0x1::option::Option<u128>',
244
+ '0x1::option::Option<u64>',
245
+ '0x2::clock::Clock'
246
+ ];
247
+ const parameterNames = ["globalConfig", "cap", "marketRegistry", "ticker", "pool", "oracle", "basicFundingRate", "fundingIntervalMs"];
248
+ return (tx) => tx.moveCall({
249
+ package: packageAddress,
250
+ module: 'trading',
251
+ function: 'update_market_funding_config',
252
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
253
+ typeArguments: options.typeArguments
254
+ });
255
+ }
256
+ /** Admin: suspend the market (halts trading). */
257
+ export function pauseMarket(options) {
258
+ const packageAddress = options.package ?? '@waterx/perp';
259
+ const argumentsTypes = [
260
+ null,
261
+ null,
262
+ '0x1::string::String'
263
+ ];
264
+ const parameterNames = ["marketRegistry", "cap", "ticker"];
265
+ return (tx) => tx.moveCall({
266
+ package: packageAddress,
267
+ module: 'trading',
268
+ function: 'pause_market',
269
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
270
+ typeArguments: options.typeArguments
271
+ });
272
+ }
273
+ /** Admin: resume the market. */
274
+ export function unpauseMarket(options) {
275
+ const packageAddress = options.package ?? '@waterx/perp';
276
+ const argumentsTypes = [
277
+ null,
278
+ null,
279
+ '0x1::string::String'
280
+ ];
281
+ const parameterNames = ["marketRegistry", "cap", "ticker"];
282
+ return (tx) => tx.moveCall({
283
+ package: packageAddress,
284
+ module: 'trading',
285
+ function: 'unpause_market',
286
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
287
+ typeArguments: options.typeArguments
288
+ });
289
+ }
290
+ /** Admin: add witness type `W` to the request checklist. */
291
+ export function addRequestRule(options) {
292
+ const packageAddress = options.package ?? '@waterx/perp';
293
+ const argumentsTypes = [
294
+ null,
295
+ null,
296
+ '0x1::string::String'
297
+ ];
298
+ const parameterNames = ["marketRegistry", "cap", "ticker"];
299
+ return (tx) => tx.moveCall({
300
+ package: packageAddress,
301
+ module: 'trading',
302
+ function: 'add_request_rule',
303
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
304
+ typeArguments: options.typeArguments
305
+ });
306
+ }
307
+ /** Admin: remove witness type `W` from the request checklist. */
308
+ export function removeRequestRule(options) {
309
+ const packageAddress = options.package ?? '@waterx/perp';
310
+ const argumentsTypes = [
311
+ null,
312
+ null,
313
+ '0x1::string::String'
314
+ ];
315
+ const parameterNames = ["marketRegistry", "cap", "ticker"];
316
+ return (tx) => tx.moveCall({
317
+ package: packageAddress,
318
+ module: 'trading',
319
+ function: 'remove_request_rule',
320
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
321
+ typeArguments: options.typeArguments
322
+ });
323
+ }
324
+ /** Registers a market in the pool-level WLP AUM object. */
325
+ export function registerMarketAum(options) {
326
+ const packageAddress = options.package ?? '@waterx/perp';
327
+ const argumentsTypes = [
328
+ null,
329
+ null,
330
+ null,
331
+ '0x1::string::String',
332
+ null,
333
+ '0x2::clock::Clock'
334
+ ];
335
+ const parameterNames = ["marketRegistry", "aum", "cap", "ticker", "oracle"];
336
+ return (tx) => tx.moveCall({
337
+ package: packageAddress,
338
+ module: 'trading',
339
+ function: 'register_market_aum',
340
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
341
+ typeArguments: options.typeArguments
342
+ });
343
+ }
344
+ /** Refreshes one registered market's contribution to pool-level WLP AUM. */
345
+ export function refreshMarketAum(options) {
346
+ const packageAddress = options.package ?? '@waterx/perp';
347
+ const argumentsTypes = [
348
+ null,
349
+ null,
350
+ '0x1::string::String',
351
+ null,
352
+ '0x2::clock::Clock'
353
+ ];
354
+ const parameterNames = ["marketRegistry", "aum", "ticker", "oracle"];
355
+ return (tx) => tx.moveCall({
356
+ package: packageAddress,
357
+ module: 'trading',
358
+ function: 'refresh_market_aum',
359
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
360
+ typeArguments: options.typeArguments
361
+ });
362
+ }
363
+ /**
364
+ * Permission check on the wxa account for the trading entrypoints. Reads
365
+ * `effective_protocol_permissions<TradingRequest<C_TOKEN>>` so per-collateral
366
+ * granularity is preserved (`PERM_OPEN_POSITION` etc. are bits on that bitmap).
367
+ * Must be called _before_ any `wxa_account::take` so a failed auth doesn't leave
368
+ * the user drained.
369
+ */
370
+ export function assertProtocolPerm(options) {
371
+ const packageAddress = options.package ?? '@waterx/perp';
372
+ const argumentsTypes = [
373
+ null,
374
+ '0x2::object::ID',
375
+ 'address',
376
+ 'u32',
377
+ '0x2::clock::Clock'
378
+ ];
379
+ const parameterNames = ["wxaRegistry", "accountId", "sender", "permission"];
380
+ return (tx) => tx.moveCall({
381
+ package: packageAddress,
382
+ module: 'trading',
383
+ function: 'assert_protocol_perm',
384
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
385
+ typeArguments: options.typeArguments
386
+ });
387
+ }
388
+ /** Creates a request to close a position. */
389
+ export function closePositionRequest(options) {
390
+ const packageAddress = options.package ?? '@waterx/perp';
391
+ const argumentsTypes = [
392
+ null,
393
+ null,
394
+ null,
395
+ '0x1::string::String',
396
+ null,
397
+ '0x2::object::ID',
398
+ 'u64',
399
+ 'u64',
400
+ '0x2::clock::Clock'
401
+ ];
402
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "senderRequest", "accountId", "positionId", "acceptablePrice"];
403
+ return (tx) => tx.moveCall({
404
+ package: packageAddress,
405
+ module: 'trading',
406
+ function: 'close_position_request',
407
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
408
+ typeArguments: options.typeArguments
409
+ });
410
+ }
411
+ /** Creates a request to increase an existing position at market. */
412
+ export function increasePositionRequest(options) {
413
+ const packageAddress = options.package ?? '@waterx/perp';
414
+ const argumentsTypes = [
415
+ null,
416
+ null,
417
+ null,
418
+ '0x1::string::String',
419
+ null,
420
+ '0x2::object::ID',
421
+ '0x1::option::Option<u64>',
422
+ 'u64',
423
+ 'u64',
424
+ 'u128',
425
+ 'u64',
426
+ '0x2::clock::Clock'
427
+ ];
428
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "senderRequest", "accountId", "orderId", "positionId", "collateralAmount", "size", "acceptablePrice"];
429
+ return (tx) => tx.moveCall({
430
+ package: packageAddress,
431
+ module: 'trading',
432
+ function: 'increase_position_request',
433
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
434
+ typeArguments: options.typeArguments
435
+ });
436
+ }
437
+ /** Creates a request to partially reduce an existing position at market. */
438
+ export function decreasePositionRequest(options) {
439
+ const packageAddress = options.package ?? '@waterx/perp';
440
+ const argumentsTypes = [
441
+ null,
442
+ null,
443
+ null,
444
+ '0x1::string::String',
445
+ null,
446
+ '0x2::object::ID',
447
+ 'u64',
448
+ 'u128',
449
+ 'u64',
450
+ '0x2::clock::Clock'
451
+ ];
452
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "senderRequest", "accountId", "positionId", "size", "acceptablePrice"];
453
+ return (tx) => tx.moveCall({
454
+ package: packageAddress,
455
+ module: 'trading',
456
+ function: 'decrease_position_request',
457
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
458
+ typeArguments: options.typeArguments
459
+ });
460
+ }
461
+ /**
462
+ * Creates a request to place a limit, stop, or market order, optionally with TP/SL
463
+ * pre-orders reserved against the freshly opened position.
464
+ *
465
+ * `main: PlaceOrderArgument` describes the order that hits the book immediately.
466
+ * `pre_order: vector<PlaceOrderArgument>` (length 0..=2) describes reduce-only
467
+ * orders that will be promoted to real linked orders on the new position when the
468
+ * main fills via `match_orders`.
469
+ *
470
+ * `main.trigger_price = None` is the market form: the order is parked at tick 0 in
471
+ * the limit book and a keeper fills it via `match_orders` at the live oracle.
472
+ * `acceptable_price` is carried on the order and consulted at match time — if the
473
+ * oracle moves past it the order is cancelled and collateral refunded. Limit/stop
474
+ * orders ignore `acceptable_price`.
475
+ *
476
+ * Validation runs _before_ the wxa take so a malformed request never drains the
477
+ * user's balance.
478
+ */
479
+ export function placeOrderRequest(options) {
480
+ const packageAddress = options.package ?? '@waterx/perp';
481
+ const argumentsTypes = [
482
+ null,
483
+ null,
484
+ null,
485
+ '0x1::string::String',
486
+ null,
487
+ '0x2::object::ID',
488
+ null,
489
+ 'vector<null>',
490
+ '0x2::clock::Clock'
491
+ ];
492
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "senderRequest", "accountId", "main", "preOrder"];
493
+ return (tx) => tx.moveCall({
494
+ package: packageAddress,
495
+ module: 'trading',
496
+ function: 'place_order_request',
497
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
498
+ typeArguments: options.typeArguments
499
+ });
500
+ }
501
+ /**
502
+ * Validates `(main, pre_order)` at place-order request creation. Combines the
503
+ * main-eligibility check (must be a fresh opening order), the count check against
504
+ * the market-level cap, and per-entry structural rules.
505
+ */
506
+ export function validatePreOrders(options) {
507
+ const packageAddress = options.package ?? '@waterx/perp';
508
+ const argumentsTypes = [
509
+ null,
510
+ 'vector<null>',
511
+ 'u64'
512
+ ];
513
+ const parameterNames = ["main", "preOrder", "maxPreOrders"];
514
+ return (tx) => tx.moveCall({
515
+ package: packageAddress,
516
+ module: 'trading',
517
+ function: 'validate_pre_orders',
518
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
519
+ });
520
+ }
521
+ /**
522
+ * Per-entry structural validation only: reduce-only, real trigger, no collateral,
523
+ * no pre-picked link target, opposite side of main, non-zero size. The total-count
524
+ * check is the caller's responsibility (`assert_pre_order_count`) so this can be
525
+ * reused from per-leg add / cancel paths.
526
+ */
527
+ export function validatePreOrderEntries(options) {
528
+ const packageAddress = options.package ?? '@waterx/perp';
529
+ const argumentsTypes = [
530
+ 'bool',
531
+ 'vector<null>'
532
+ ];
533
+ const parameterNames = ["mainIsLong", "preOrder"];
534
+ return (tx) => tx.moveCall({
535
+ package: packageAddress,
536
+ module: 'trading',
537
+ function: 'validate_pre_order_entries',
538
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
539
+ });
540
+ }
541
+ /**
542
+ * Caps the **total** pre-orders reserved against a single main at the
543
+ * market-config `max_pre_orders`. Aborts with `ETooManyPreOrders`.
544
+ */
545
+ export function assertPreOrderCount(options) {
546
+ const packageAddress = options.package ?? '@waterx/perp';
547
+ const argumentsTypes = [
548
+ 'u64',
549
+ 'u64'
550
+ ];
551
+ const parameterNames = ["newTotal", "maxPreOrders"];
552
+ return (tx) => tx.moveCall({
553
+ package: packageAddress,
554
+ module: 'trading',
555
+ function: 'assert_pre_order_count',
556
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
557
+ });
558
+ }
559
+ /**
560
+ * Creates a request to cancel an order. `order_type_tag = 255` scans all 4 books
561
+ * for the matching `order_id`. `trigger_price` is the scaled `Float` value; `0`
562
+ * scans all trigger price buckets in the selected book(s).
563
+ */
564
+ export function cancelOrderRequest(options) {
565
+ const packageAddress = options.package ?? '@waterx/perp';
566
+ const argumentsTypes = [
567
+ null,
568
+ null,
569
+ null,
570
+ '0x1::string::String',
571
+ null,
572
+ '0x2::object::ID',
573
+ 'u64',
574
+ 'u128',
575
+ 'u8',
576
+ '0x2::clock::Clock'
577
+ ];
578
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "senderRequest", "accountId", "orderId", "triggerPrice", "orderTypeTag"];
579
+ return (tx) => tx.moveCall({
580
+ package: packageAddress,
581
+ module: 'trading',
582
+ function: 'cancel_order_request',
583
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
584
+ typeArguments: options.typeArguments
585
+ });
586
+ }
587
+ /**
588
+ * Creates a request to update a live order's size and trigger price. The order
589
+ * keeps its direction, reduce-only flag, linked position, collateral, and
590
+ * limit/stop book. `order_type_tag = 255` and `current_trigger_price = 0` scan for
591
+ * the current order location.
592
+ */
593
+ export function updateOrderRequest(options) {
594
+ const packageAddress = options.package ?? '@waterx/perp';
595
+ const argumentsTypes = [
596
+ null,
597
+ null,
598
+ null,
599
+ '0x1::string::String',
600
+ null,
601
+ '0x2::object::ID',
602
+ 'u64',
603
+ 'u128',
604
+ 'u8',
605
+ 'u128',
606
+ 'u128',
607
+ '0x2::clock::Clock'
608
+ ];
609
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "senderRequest", "accountId", "orderId", "currentTriggerPrice", "orderTypeTag", "newSize", "newTriggerPrice"];
610
+ return (tx) => tx.moveCall({
611
+ package: packageAddress,
612
+ module: 'trading',
613
+ function: 'update_order_request',
614
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
615
+ typeArguments: options.typeArguments
616
+ });
617
+ }
618
+ /**
619
+ * Cancels a single TP / SL pre-order reserved against an unfilled main.
620
+ * `pre_order_id` is the pre-order's own `order_id`, returned in the `OrderCreated`
621
+ * event when it activates (also enumerable from `pending_pre_order_index` keyed by
622
+ * `main_order_id`). The pair must be consistent — i.e. `pre_order_id` must appear
623
+ * in the index entry for `main_order_id`, otherwise the call aborts with
624
+ * `EOrderNotFound`. Pre-orders never hold collateral, so this only adjusts
625
+ * bookkeeping; no payout. Emits `PreOrderCancelled` with `pre_order_count = 1`.
626
+ */
627
+ export function cancelPreOrderRequest(options) {
628
+ const packageAddress = options.package ?? '@waterx/perp';
629
+ const argumentsTypes = [
630
+ null,
631
+ null,
632
+ null,
633
+ '0x1::string::String',
634
+ null,
635
+ '0x2::object::ID',
636
+ 'u64',
637
+ 'u64',
638
+ '0x2::clock::Clock'
639
+ ];
640
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "senderRequest", "accountId", "mainOrderId", "preOrderId"];
641
+ return (tx) => tx.moveCall({
642
+ package: packageAddress,
643
+ module: 'trading',
644
+ function: 'cancel_pre_order_request',
645
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
646
+ typeArguments: options.typeArguments
647
+ });
648
+ }
649
+ /**
650
+ * Adds one TP / SL pre-order to an unfilled main. The main must still be on the
651
+ * book, owned by `account_id`, of collateral type `C_TOKEN`, and a fresh opening
652
+ * order. The per-entry rules (`validate_pre_order_entries`) and the market-level
653
+ * total cap (`market.config.max_pre_orders()`) are enforced — existing reserved
654
+ *
655
+ * - 1 must stay within cap.
656
+ */
657
+ export function addPreOrderRequest(options) {
658
+ const packageAddress = options.package ?? '@waterx/perp';
659
+ const argumentsTypes = [
660
+ null,
661
+ null,
662
+ null,
663
+ '0x1::string::String',
664
+ null,
665
+ '0x2::object::ID',
666
+ 'u64',
667
+ null,
668
+ '0x2::clock::Clock'
669
+ ];
670
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "senderRequest", "accountId", "mainOrderId", "preOrder"];
671
+ return (tx) => tx.moveCall({
672
+ package: packageAddress,
673
+ module: 'trading',
674
+ function: 'add_pre_order_request',
675
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
676
+ typeArguments: options.typeArguments
677
+ });
678
+ }
679
+ /** Creates a request to deposit collateral on a position. */
680
+ export function depositCollateralRequest(options) {
681
+ const packageAddress = options.package ?? '@waterx/perp';
682
+ const argumentsTypes = [
683
+ null,
684
+ null,
685
+ null,
686
+ '0x1::string::String',
687
+ null,
688
+ '0x2::object::ID',
689
+ 'u64',
690
+ 'u64',
691
+ '0x2::clock::Clock'
692
+ ];
693
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "senderRequest", "accountId", "positionId", "collateralAmount"];
694
+ return (tx) => tx.moveCall({
695
+ package: packageAddress,
696
+ module: 'trading',
697
+ function: 'deposit_collateral_request',
698
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
699
+ typeArguments: options.typeArguments
700
+ });
701
+ }
702
+ /** Creates a request to withdraw collateral from a position. */
703
+ export function withdrawCollateralRequest(options) {
704
+ const packageAddress = options.package ?? '@waterx/perp';
705
+ const argumentsTypes = [
706
+ null,
707
+ null,
708
+ null,
709
+ '0x1::string::String',
710
+ null,
711
+ '0x2::object::ID',
712
+ 'u64',
713
+ 'u64',
714
+ '0x2::clock::Clock'
715
+ ];
716
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "senderRequest", "accountId", "positionId", "amount"];
717
+ return (tx) => tx.moveCall({
718
+ package: packageAddress,
719
+ module: 'trading',
720
+ function: 'withdraw_collateral_request',
721
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
722
+ typeArguments: options.typeArguments
723
+ });
724
+ }
725
+ /**
726
+ * Creates a request to liquidate a position (keeper only). Reads
727
+ * account_object_address from the position directly. Keeper-only: liquidate an
728
+ * undercollateralized position. Single-call — no `TradingRequest` hot potato to
729
+ * manage. Returns a droppable receipt vector for PTB composition.
730
+ */
731
+ export function liquidate(options) {
732
+ const packageAddress = options.package ?? '@waterx/perp';
733
+ const argumentsTypes = [
734
+ null,
735
+ null,
736
+ null,
737
+ '0x1::string::String',
738
+ null,
739
+ null,
740
+ 'u64',
741
+ null,
742
+ '0x2::clock::Clock'
743
+ ];
744
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "pool", "senderRequest", "positionId", "oracle"];
745
+ return (tx) => tx.moveCall({
746
+ package: packageAddress,
747
+ module: 'trading',
748
+ function: 'liquidate',
749
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
750
+ typeArguments: options.typeArguments
751
+ });
752
+ }
753
+ /**
754
+ * Keeper-only: scans a page of positions and liquidates every liquidatable one.
755
+ * Iterates positions by internal index `[page_index * page_size, ...)`. No-op if
756
+ * the page is out of range or no positions qualify. Returns droppable receipts for
757
+ * every liquidated position.
758
+ */
759
+ export function batchLiquidate(options) {
760
+ const packageAddress = options.package ?? '@waterx/perp';
761
+ const argumentsTypes = [
762
+ null,
763
+ null,
764
+ null,
765
+ '0x1::string::String',
766
+ null,
767
+ null,
768
+ null,
769
+ 'u64',
770
+ 'u64',
771
+ '0x2::clock::Clock'
772
+ ];
773
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "pool", "senderRequest", "oracle", "pageSize", "pageIndex"];
774
+ return (tx) => tx.moveCall({
775
+ package: packageAddress,
776
+ module: 'trading',
777
+ function: 'batch_liquidate',
778
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
779
+ typeArguments: options.typeArguments
780
+ });
781
+ }
782
+ /**
783
+ * Executes a trading request. All `*_request` creators return raw
784
+ * `TradingRequest<C>`; pass it straight to `execute` after attaching any witness
785
+ * rules (e.g. `pyth_rule::feed(&mut req, ...)`). Used by both user happy paths and
786
+ * keeper paths.
787
+ */
788
+ export function execute(options) {
789
+ const packageAddress = options.package ?? '@waterx/perp';
790
+ const argumentsTypes = [
791
+ null,
792
+ null,
793
+ null,
794
+ '0x1::string::String',
795
+ null,
796
+ null,
797
+ null,
798
+ '0x2::clock::Clock'
799
+ ];
800
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "pool", "req", "oracle"];
801
+ return (tx) => tx.moveCall({
802
+ package: packageAddress,
803
+ module: 'trading',
804
+ function: 'execute',
805
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
806
+ typeArguments: options.typeArguments
807
+ });
808
+ }
809
+ export function executeOpenPosition(options) {
810
+ const packageAddress = options.package ?? '@waterx/perp';
811
+ const argumentsTypes = [
812
+ null,
813
+ null,
814
+ null,
815
+ null,
816
+ null,
817
+ '0x2::object::ID',
818
+ '0x2::object::ID',
819
+ 'u64',
820
+ 'address',
821
+ 'address',
822
+ null,
823
+ 'bool',
824
+ null,
825
+ 'u64',
826
+ '0x2::clock::Clock'
827
+ ];
828
+ const parameterNames = ["globalConfig", "wxaRegistry", "market", "pool", "oracle", "marketId", "accountId", "orderId", "accountObjectAddress", "sender", "collateral", "isLong", "size", "acceptablePrice"];
829
+ return (tx) => tx.moveCall({
830
+ package: packageAddress,
831
+ module: 'trading',
832
+ function: 'execute_open_position',
833
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
834
+ typeArguments: options.typeArguments
835
+ });
836
+ }
837
+ export function executeIncreasePosition(options) {
838
+ const packageAddress = options.package ?? '@waterx/perp';
839
+ const argumentsTypes = [
840
+ null,
841
+ null,
842
+ null,
843
+ null,
844
+ '0x2::object::ID',
845
+ 'address',
846
+ 'u64',
847
+ 'u64',
848
+ null,
849
+ null,
850
+ 'u64',
851
+ '0x2::clock::Clock'
852
+ ];
853
+ const parameterNames = ["globalConfig", "market", "pool", "oracle", "marketId", "accountObjectAddress", "orderId", "positionId", "collateral", "size", "acceptablePrice"];
854
+ return (tx) => tx.moveCall({
855
+ package: packageAddress,
856
+ module: 'trading',
857
+ function: 'execute_increase_position',
858
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
859
+ typeArguments: options.typeArguments
860
+ });
861
+ }
862
+ export function executeClosePosition(options) {
863
+ const packageAddress = options.package ?? '@waterx/perp';
864
+ const argumentsTypes = [
865
+ null,
866
+ null,
867
+ null,
868
+ null,
869
+ null,
870
+ '0x2::object::ID',
871
+ '0x2::object::ID',
872
+ 'address',
873
+ 'u64',
874
+ 'u64',
875
+ 'u64',
876
+ '0x2::clock::Clock'
877
+ ];
878
+ const parameterNames = ["globalConfig", "wxaRegistry", "market", "pool", "oracle", "marketId", "accountId", "accountObjId", "orderId", "positionId", "acceptablePrice"];
879
+ return (tx) => tx.moveCall({
880
+ package: packageAddress,
881
+ module: 'trading',
882
+ function: 'execute_close_position',
883
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
884
+ typeArguments: options.typeArguments
885
+ });
886
+ }
887
+ export function executeDecreasePosition(options) {
888
+ const packageAddress = options.package ?? '@waterx/perp';
889
+ const argumentsTypes = [
890
+ null,
891
+ null,
892
+ null,
893
+ null,
894
+ null,
895
+ '0x2::object::ID',
896
+ '0x2::object::ID',
897
+ 'address',
898
+ 'u64',
899
+ 'u64',
900
+ null,
901
+ 'u64',
902
+ '0x2::clock::Clock'
903
+ ];
904
+ const parameterNames = ["globalConfig", "wxaRegistry", "market", "pool", "oracle", "marketId", "accountId", "accountObjId", "orderId", "positionId", "requestedSize", "acceptablePrice"];
905
+ return (tx) => tx.moveCall({
906
+ package: packageAddress,
907
+ module: 'trading',
908
+ function: 'execute_decrease_position',
909
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
910
+ typeArguments: options.typeArguments
911
+ });
912
+ }
913
+ export function executePlaceOrder(options) {
914
+ const packageAddress = options.package ?? '@waterx/perp';
915
+ const argumentsTypes = [
916
+ null,
917
+ null,
918
+ null,
919
+ null,
920
+ null,
921
+ '0x2::object::ID',
922
+ '0x2::object::ID',
923
+ 'address',
924
+ null,
925
+ 'bool',
926
+ 'bool',
927
+ 'bool',
928
+ null,
929
+ null,
930
+ 'u64',
931
+ '0x1::option::Option<u64>',
932
+ 'vector<null>',
933
+ '0x2::clock::Clock'
934
+ ];
935
+ const parameterNames = ["globalConfig", "wxaRegistry", "market", "pool", "oracle", "marketId", "accountId", "accountObjectAddress", "collateral", "isLong", "isStopOrder", "reduceOnly", "size", "triggerPrice", "acceptablePrice", "linkedPositionId", "preOrders"];
936
+ return (tx) => tx.moveCall({
937
+ package: packageAddress,
938
+ module: 'trading',
939
+ function: 'execute_place_order',
940
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
941
+ typeArguments: options.typeArguments
942
+ });
943
+ }
944
+ export function executeCancelOrder(options) {
945
+ const packageAddress = options.package ?? '@waterx/perp';
946
+ const argumentsTypes = [
947
+ null,
948
+ null,
949
+ null,
950
+ '0x2::object::ID',
951
+ '0x2::object::ID',
952
+ 'address',
953
+ 'u64',
954
+ 'u128',
955
+ 'u8'
956
+ ];
957
+ const parameterNames = ["globalConfig", "wxaRegistry", "market", "marketId", "accountId", "accountObjId", "orderId", "triggerPriceKey", "orderTypeTag"];
958
+ return (tx) => tx.moveCall({
959
+ package: packageAddress,
960
+ module: 'trading',
961
+ function: 'execute_cancel_order',
962
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
963
+ typeArguments: options.typeArguments
964
+ });
965
+ }
966
+ export function executeUpdateOrder(options) {
967
+ const packageAddress = options.package ?? '@waterx/perp';
968
+ const argumentsTypes = [
969
+ null,
970
+ null,
971
+ null,
972
+ null,
973
+ '0x2::object::ID',
974
+ 'address',
975
+ 'u64',
976
+ 'u128',
977
+ 'u8',
978
+ null,
979
+ null,
980
+ '0x2::clock::Clock'
981
+ ];
982
+ const parameterNames = ["globalConfig", "market", "pool", "oracle", "marketId", "accountObjectAddress", "orderId", "triggerPriceKey", "orderTypeTag", "newSize", "newTriggerPrice"];
983
+ return (tx) => tx.moveCall({
984
+ package: packageAddress,
985
+ module: 'trading',
986
+ function: 'execute_update_order',
987
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
988
+ typeArguments: options.typeArguments
989
+ });
990
+ }
991
+ /**
992
+ * Cancels a single pre-order by id. Validates ownership / collateral type on the
993
+ * reserved `Order`, then verifies `pre_order_id` actually belongs to
994
+ * `main_order_id` via the index. Destroys the `Order` through
995
+ * `position::remove_order<C_TOKEN>` and emits
996
+ * `PreOrderCancelled { main_order_id, pre_order_count: 1 }`.
997
+ */
998
+ export function executeCancelPreOrder(options) {
999
+ const packageAddress = options.package ?? '@waterx/perp';
1000
+ const argumentsTypes = [
1001
+ null,
1002
+ null,
1003
+ '0x2::object::ID',
1004
+ 'address',
1005
+ 'u64',
1006
+ 'u64'
1007
+ ];
1008
+ const parameterNames = ["globalConfig", "market", "marketId", "accountObjectAddress", "mainOrderId", "preOrderId"];
1009
+ return (tx) => tx.moveCall({
1010
+ package: packageAddress,
1011
+ module: 'trading',
1012
+ function: 'execute_cancel_pre_order',
1013
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1014
+ typeArguments: options.typeArguments
1015
+ });
1016
+ }
1017
+ /**
1018
+ * Appends a single pre-order to an existing or empty reservation for
1019
+ * `main_order_id`. Locates the main on a book, verifies eligibility, then
1020
+ * `assert_pre_order_count(existing + 1, cap)` and per-entry validation before
1021
+ * delegating to `reserve_pre_orders`.
1022
+ */
1023
+ export function executeAddPreOrder(options) {
1024
+ const packageAddress = options.package ?? '@waterx/perp';
1025
+ const argumentsTypes = [
1026
+ null,
1027
+ null,
1028
+ '0x2::object::ID',
1029
+ 'address',
1030
+ 'u64',
1031
+ 'vector<null>',
1032
+ '0x2::clock::Clock'
1033
+ ];
1034
+ const parameterNames = ["globalConfig", "market", "marketId", "accountObjectAddress", "mainOrderId", "newPreOrder"];
1035
+ return (tx) => tx.moveCall({
1036
+ package: packageAddress,
1037
+ module: 'trading',
1038
+ function: 'execute_add_pre_order',
1039
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1040
+ typeArguments: options.typeArguments
1041
+ });
1042
+ }
1043
+ export function executeDepositCollateral(options) {
1044
+ const packageAddress = options.package ?? '@waterx/perp';
1045
+ const argumentsTypes = [
1046
+ null,
1047
+ null,
1048
+ null,
1049
+ null,
1050
+ '0x2::object::ID',
1051
+ 'address',
1052
+ 'u64',
1053
+ null,
1054
+ '0x2::clock::Clock'
1055
+ ];
1056
+ const parameterNames = ["globalConfig", "market", "pool", "oracle", "marketId", "accountObjectAddress", "positionId", "collateral"];
1057
+ return (tx) => tx.moveCall({
1058
+ package: packageAddress,
1059
+ module: 'trading',
1060
+ function: 'execute_deposit_collateral',
1061
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1062
+ typeArguments: options.typeArguments
1063
+ });
1064
+ }
1065
+ /**
1066
+ * Returns `(returned_collateral_amount, position_collateral_amount)`: the first is
1067
+ * the amount actually credited back to the wxa account (read off the `Balance`
1068
+ * rather than echoing the requested `amount`, so the response field can't drift if
1069
+ * `pos.withdraw_collateral` ever gains clamping semantics); the second is the
1070
+ * post-action position collateral.
1071
+ */
1072
+ export function executeWithdrawCollateral(options) {
1073
+ const packageAddress = options.package ?? '@waterx/perp';
1074
+ const argumentsTypes = [
1075
+ null,
1076
+ null,
1077
+ null,
1078
+ null,
1079
+ null,
1080
+ '0x2::object::ID',
1081
+ 'address',
1082
+ 'u64',
1083
+ 'u64',
1084
+ '0x2::clock::Clock'
1085
+ ];
1086
+ const parameterNames = ["globalConfig", "wxaRegistry", "market", "pool", "oracle", "marketId", "accountObjId", "positionId", "amount"];
1087
+ return (tx) => tx.moveCall({
1088
+ package: packageAddress,
1089
+ module: 'trading',
1090
+ function: 'execute_withdraw_collateral',
1091
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1092
+ typeArguments: options.typeArguments
1093
+ });
1094
+ }
1095
+ export function executeLiquidate(options) {
1096
+ const packageAddress = options.package ?? '@waterx/perp';
1097
+ const argumentsTypes = [
1098
+ null,
1099
+ null,
1100
+ null,
1101
+ null,
1102
+ null,
1103
+ '0x2::object::ID',
1104
+ '0x2::object::ID',
1105
+ 'address',
1106
+ 'address',
1107
+ 'u64',
1108
+ '0x2::clock::Clock'
1109
+ ];
1110
+ const parameterNames = ["globalConfig", "wxaRegistry", "market", "pool", "oracle", "marketId", "accountId", "accountObjectAddress", "sender", "positionId"];
1111
+ return (tx) => tx.moveCall({
1112
+ package: packageAddress,
1113
+ module: 'trading',
1114
+ function: 'execute_liquidate',
1115
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1116
+ typeArguments: options.typeArguments
1117
+ });
1118
+ }
1119
+ export function matchOrders(options) {
1120
+ const packageAddress = options.package ?? '@waterx/perp';
1121
+ const argumentsTypes = [
1122
+ null,
1123
+ null,
1124
+ null,
1125
+ '0x1::string::String',
1126
+ null,
1127
+ null,
1128
+ null,
1129
+ 'u8',
1130
+ 'u128',
1131
+ 'u64',
1132
+ '0x2::clock::Clock'
1133
+ ];
1134
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "pool", "senderRequest", "oracle", "orderTypeTag", "triggerPrice", "maxFills"];
1135
+ return (tx) => tx.moveCall({
1136
+ package: packageAddress,
1137
+ module: 'trading',
1138
+ function: 'match_orders',
1139
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1140
+ typeArguments: options.typeArguments
1141
+ });
1142
+ }
1143
+ /** Keeper: updates funding rate for a market. */
1144
+ export function updateFundingRate(options) {
1145
+ const packageAddress = options.package ?? '@waterx/perp';
1146
+ const argumentsTypes = [
1147
+ null,
1148
+ null,
1149
+ '0x1::string::String',
1150
+ null,
1151
+ null,
1152
+ null,
1153
+ '0x2::clock::Clock'
1154
+ ];
1155
+ const parameterNames = ["globalConfig", "marketRegistry", "ticker", "pool", "oracle", "senderRequest"];
1156
+ return (tx) => tx.moveCall({
1157
+ package: packageAddress,
1158
+ module: 'trading',
1159
+ function: 'update_funding_rate',
1160
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1161
+ typeArguments: options.typeArguments
1162
+ });
1163
+ }
1164
+ export function settleFundingRate(options) {
1165
+ const packageAddress = options.package ?? '@waterx/perp';
1166
+ const argumentsTypes = [
1167
+ null,
1168
+ null,
1169
+ null,
1170
+ null,
1171
+ '0x2::clock::Clock'
1172
+ ];
1173
+ const parameterNames = ["globalConfig", "market", "pool", "oracle"];
1174
+ return (tx) => tx.moveCall({
1175
+ package: packageAddress,
1176
+ module: 'trading',
1177
+ function: 'settle_funding_rate',
1178
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1179
+ typeArguments: options.typeArguments
1180
+ });
1181
+ }
1182
+ /**
1183
+ * Keeper-only: open a new position for an account, funded by the keeper's own
1184
+ * `Coin<C_TOKEN>` (campaign / airdrop use case). The keeper bypasses
1185
+ * `min_coll_value` on this path — `increase_position` and `place_order` still
1186
+ * enforce it for all callers including keepers. Returns a droppable receipt vector
1187
+ * so the keeper or a composing protocol can reference the position in the same
1188
+ * PTB.
1189
+ */
1190
+ export function openPositionByKeeper(options) {
1191
+ const packageAddress = options.package ?? '@waterx/perp';
1192
+ const argumentsTypes = [
1193
+ null,
1194
+ null,
1195
+ null,
1196
+ '0x1::string::String',
1197
+ null,
1198
+ null,
1199
+ 'address',
1200
+ null,
1201
+ 'bool',
1202
+ 'u128',
1203
+ 'u64',
1204
+ null,
1205
+ '0x2::clock::Clock'
1206
+ ];
1207
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "pool", "keeperRequest", "accountObjectAddress", "collateralCoin", "isLong", "size", "acceptablePrice", "oracle"];
1208
+ return (tx) => tx.moveCall({
1209
+ package: packageAddress,
1210
+ module: 'trading',
1211
+ function: 'open_position_by_keeper',
1212
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1213
+ typeArguments: options.typeArguments
1214
+ });
1215
+ }
1216
+ /**
1217
+ * Risk-manager-only: force-close a position (emergency use). Reads
1218
+ * `account_object_address` from the position directly, like `liquidate`. Returns a
1219
+ * droppable receipt vector for PTB composition.
1220
+ */
1221
+ export function closePositionByKeeper(options) {
1222
+ const packageAddress = options.package ?? '@waterx/perp';
1223
+ const argumentsTypes = [
1224
+ null,
1225
+ null,
1226
+ null,
1227
+ '0x1::string::String',
1228
+ null,
1229
+ null,
1230
+ 'u64',
1231
+ 'u64',
1232
+ null,
1233
+ '0x2::clock::Clock'
1234
+ ];
1235
+ const parameterNames = ["globalConfig", "wxaRegistry", "marketRegistry", "ticker", "pool", "keeperRequest", "positionId", "acceptablePrice", "oracle"];
1236
+ return (tx) => tx.moveCall({
1237
+ package: packageAddress,
1238
+ module: 'trading',
1239
+ function: 'close_position_by_keeper',
1240
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1241
+ typeArguments: options.typeArguments
1242
+ });
1243
+ }
1244
+ /**
1245
+ * Computes the scaled size (u128, 9 decimals) for a given collateral amount,
1246
+ * leverage, and actual collateral price. Compatible with non-dollar-pegged
1247
+ * collateral. Base ticker comes from `market.symbol()`, collateral ticker from
1248
+ * `pool.token_ticker<LP, C>()` — callers cannot mis-price by lying about either.
1249
+ */
1250
+ export function resolveSize(options) {
1251
+ const packageAddress = options.package ?? '@waterx/perp';
1252
+ const argumentsTypes = [
1253
+ null,
1254
+ null,
1255
+ null,
1256
+ 'u64',
1257
+ 'u64',
1258
+ '0x2::clock::Clock'
1259
+ ];
1260
+ const parameterNames = ["market", "pool", "oracle", "collateralAmount", "leverageBps"];
1261
+ return (tx) => tx.moveCall({
1262
+ package: packageAddress,
1263
+ module: 'trading',
1264
+ function: 'resolve_size',
1265
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1266
+ typeArguments: options.typeArguments
1267
+ });
1268
+ }
1269
+ /**
1270
+ * Like `resolve_size` but uses a trigger price instead of the base oracle price.
1271
+ * Use this to compute the `size` parameter for `place_order_request`.
1272
+ * `trigger_price` is a scaled Float value (the same u128 you pass to
1273
+ * `place_order_request`).
1274
+ */
1275
+ export function resolveOrderSize(options) {
1276
+ const packageAddress = options.package ?? '@waterx/perp';
1277
+ const argumentsTypes = [
1278
+ null,
1279
+ null,
1280
+ 'u128',
1281
+ 'u64',
1282
+ 'u64',
1283
+ '0x2::clock::Clock'
1284
+ ];
1285
+ const parameterNames = ["pool", "oracle", "triggerPrice", "collateralAmount", "leverageBps"];
1286
+ return (tx) => tx.moveCall({
1287
+ package: packageAddress,
1288
+ module: 'trading',
1289
+ function: 'resolve_order_size',
1290
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1291
+ typeArguments: options.typeArguments
1292
+ });
1293
+ }
1294
+ export function checkOpenSlippage(options) {
1295
+ const packageAddress = options.package ?? '@waterx/perp';
1296
+ const argumentsTypes = [
1297
+ 'bool',
1298
+ null,
1299
+ 'u64'
1300
+ ];
1301
+ const parameterNames = ["isLong", "price", "acceptablePrice"];
1302
+ return (tx) => tx.moveCall({
1303
+ package: packageAddress,
1304
+ module: 'trading',
1305
+ function: 'check_open_slippage',
1306
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1307
+ });
1308
+ }
1309
+ export function assertOpenSlippage(options) {
1310
+ const packageAddress = options.package ?? '@waterx/perp';
1311
+ const argumentsTypes = [
1312
+ 'bool',
1313
+ null,
1314
+ 'u64'
1315
+ ];
1316
+ const parameterNames = ["isLong", "price", "acceptablePrice"];
1317
+ return (tx) => tx.moveCall({
1318
+ package: packageAddress,
1319
+ module: 'trading',
1320
+ function: 'assert_open_slippage',
1321
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1322
+ });
1323
+ }
1324
+ export function assertCloseSlippage(options) {
1325
+ const packageAddress = options.package ?? '@waterx/perp';
1326
+ const argumentsTypes = [
1327
+ 'bool',
1328
+ null,
1329
+ 'u64'
1330
+ ];
1331
+ const parameterNames = ["isLong", "price", "acceptablePrice"];
1332
+ return (tx) => tx.moveCall({
1333
+ package: packageAddress,
1334
+ module: 'trading',
1335
+ function: 'assert_close_slippage',
1336
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1337
+ });
1338
+ }
1339
+ export function calculateTotalTradingFee(options) {
1340
+ const packageAddress = options.package ?? '@waterx/perp';
1341
+ const argumentsTypes = [
1342
+ null,
1343
+ null,
1344
+ null,
1345
+ 'bool',
1346
+ null
1347
+ ];
1348
+ const parameterNames = ["marketConfig", "pool", "executionPrice", "orderIsLong", "orderSize"];
1349
+ return (tx) => tx.moveCall({
1350
+ package: packageAddress,
1351
+ module: 'trading',
1352
+ function: 'calculate_total_trading_fee',
1353
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1354
+ typeArguments: options.typeArguments
1355
+ });
1356
+ }
1357
+ /**
1358
+ * Emits a `WlpEquityChanged` event for a settlement that moves `amount` of
1359
+ * `collateral_token` to/from the LP pool. No-op when `amount == 0`. Centralizes
1360
+ * the `market.symbol()` / `with_defining_ids<LP_TOKEN>()` lookups so call sites
1361
+ * stay short.
1362
+ */
1363
+ export function emitLpEquity(options) {
1364
+ const packageAddress = options.package ?? '@waterx/perp';
1365
+ const argumentsTypes = [
1366
+ null,
1367
+ null,
1368
+ 'u64',
1369
+ 'bool',
1370
+ '0x1::string::String'
1371
+ ];
1372
+ const parameterNames = ["market", "collateralToken", "amount", "isProfit", "memo"];
1373
+ return (tx) => tx.moveCall({
1374
+ package: packageAddress,
1375
+ module: 'trading',
1376
+ function: 'emit_lp_equity',
1377
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1378
+ typeArguments: options.typeArguments
1379
+ });
1380
+ }
1381
+ /**
1382
+ * Splits an already-collected trading-fee balance into the protocol's cut (sent to
1383
+ * `GlobalVault.protocol_fee_balance`) and the LP pool's cut (joined into the pool,
1384
+ * emitted as a `WlpEquityChanged` "fee" event). Used by every closing/liquidation
1385
+ * path that realizes a fee.
1386
+ */
1387
+ export function distributeTradingFee(options) {
1388
+ const packageAddress = options.package ?? '@waterx/perp';
1389
+ const argumentsTypes = [
1390
+ null,
1391
+ null,
1392
+ null,
1393
+ null,
1394
+ 'u64',
1395
+ '0x2::object::ID',
1396
+ null,
1397
+ null
1398
+ ];
1399
+ const parameterNames = ["globalConfig", "pool", "market", "feeBalance", "protocolShareBps", "marketId", "collateralToken", "collateralPrice"];
1400
+ return (tx) => tx.moveCall({
1401
+ package: packageAddress,
1402
+ module: 'trading',
1403
+ function: 'distribute_trading_fee',
1404
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1405
+ typeArguments: options.typeArguments
1406
+ });
1407
+ }
1408
+ export function calculateEffectiveCollateralAmount(options) {
1409
+ const packageAddress = options.package ?? '@waterx/perp';
1410
+ const argumentsTypes = [
1411
+ 'u64',
1412
+ 'u64',
1413
+ 'bool',
1414
+ 'u64',
1415
+ 'u64',
1416
+ 'u64'
1417
+ ];
1418
+ const parameterNames = ["grossCollateralAmount", "borrowFee", "fundingSign", "fundingFee", "tradingFee", "projectedTradingFee"];
1419
+ return (tx) => tx.moveCall({
1420
+ package: packageAddress,
1421
+ module: 'trading',
1422
+ function: 'calculate_effective_collateral_amount',
1423
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1424
+ });
1425
+ }
1426
+ export function calculateLossAdjustedEffectiveCollateralAmount(options) {
1427
+ const packageAddress = options.package ?? '@waterx/perp';
1428
+ const argumentsTypes = [
1429
+ null,
1430
+ null,
1431
+ null,
1432
+ 'u64',
1433
+ 'u64',
1434
+ 'bool',
1435
+ 'u64',
1436
+ 'u64',
1437
+ 'u64'
1438
+ ];
1439
+ const parameterNames = ["position", "currentPrice", "collateralPrice", "grossCollateralAmount", "borrowFee", "fundingSign", "fundingFee", "tradingFee", "projectedTradingFee"];
1440
+ return (tx) => tx.moveCall({
1441
+ package: packageAddress,
1442
+ module: 'trading',
1443
+ function: 'calculate_loss_adjusted_effective_collateral_amount',
1444
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1445
+ });
1446
+ }
1447
+ export function settleFundingToBalance(options) {
1448
+ const packageAddress = options.package ?? '@waterx/perp';
1449
+ const argumentsTypes = [
1450
+ null,
1451
+ null,
1452
+ null,
1453
+ 'bool',
1454
+ 'u64',
1455
+ null,
1456
+ '0x1::string::String'
1457
+ ];
1458
+ const parameterNames = ["globalConfig", "pool", "collateral", "fundingSign", "fundingFee", "collateralPrice", "marketTicker"];
1459
+ return (tx) => tx.moveCall({
1460
+ package: packageAddress,
1461
+ module: 'trading',
1462
+ function: 'settle_funding_to_balance',
1463
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1464
+ typeArguments: options.typeArguments
1465
+ });
1466
+ }
1467
+ export function settleFundingToPosition(options) {
1468
+ const packageAddress = options.package ?? '@waterx/perp';
1469
+ const argumentsTypes = [
1470
+ null,
1471
+ null,
1472
+ null,
1473
+ 'bool',
1474
+ 'u64',
1475
+ null,
1476
+ '0x1::string::String'
1477
+ ];
1478
+ const parameterNames = ["globalConfig", "pool", "position", "fundingSign", "fundingFee", "collateralPrice", "marketTicker"];
1479
+ return (tx) => tx.moveCall({
1480
+ package: packageAddress,
1481
+ module: 'trading',
1482
+ function: 'settle_funding_to_position',
1483
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1484
+ typeArguments: options.typeArguments
1485
+ });
1486
+ }
1487
+ export function calculateImpactFee(options) {
1488
+ const packageAddress = options.package ?? '@waterx/perp';
1489
+ const argumentsTypes = [
1490
+ null,
1491
+ null,
1492
+ null,
1493
+ 'bool',
1494
+ null
1495
+ ];
1496
+ const parameterNames = ["marketConfig", "pool", "executionPrice", "orderIsLong", "orderSize"];
1497
+ return (tx) => tx.moveCall({
1498
+ package: packageAddress,
1499
+ module: 'trading',
1500
+ function: 'calculate_impact_fee',
1501
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1502
+ typeArguments: options.typeArguments
1503
+ });
1504
+ }
1505
+ export function impactFeeCostUsd(options) {
1506
+ const packageAddress = options.package ?? '@waterx/perp';
1507
+ const argumentsTypes = [
1508
+ null,
1509
+ null,
1510
+ null,
1511
+ 'u64',
1512
+ 'u64'
1513
+ ];
1514
+ const parameterNames = ["maxImpactFee", "allocatedExposureUsd", "exposureUsd", "impactFeeCurvature", "impactFeeScale"];
1515
+ return (tx) => tx.moveCall({
1516
+ package: packageAddress,
1517
+ module: 'trading',
1518
+ function: 'impact_fee_cost_usd',
1519
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1520
+ });
1521
+ }
1522
+ export function calculatePositionLeverageBps(options) {
1523
+ const packageAddress = options.package ?? '@waterx/perp';
1524
+ const argumentsTypes = [
1525
+ null,
1526
+ 'u64',
1527
+ 'u8',
1528
+ null,
1529
+ null
1530
+ ];
1531
+ const parameterNames = ["totalSize", "totalCollateralAmount", "collateralDecimal", "executionPrice", "collateralPrice"];
1532
+ return (tx) => tx.moveCall({
1533
+ package: packageAddress,
1534
+ module: 'trading',
1535
+ function: 'calculate_position_leverage_bps',
1536
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1537
+ });
1538
+ }
1539
+ export function hasMinPositionCollateralValue(options) {
1540
+ const packageAddress = options.package ?? '@waterx/perp';
1541
+ const argumentsTypes = [
1542
+ 'u64',
1543
+ 'u64',
1544
+ 'u8',
1545
+ null
1546
+ ];
1547
+ const parameterNames = ["minCollateralValue", "collateralAmount", "collateralDecimal", "collateralPrice"];
1548
+ return (tx) => tx.moveCall({
1549
+ package: packageAddress,
1550
+ module: 'trading',
1551
+ function: 'has_min_position_collateral_value',
1552
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1553
+ });
1554
+ }
1555
+ export function assertMinPositionCollateralValue(options) {
1556
+ const packageAddress = options.package ?? '@waterx/perp';
1557
+ const argumentsTypes = [
1558
+ 'u64',
1559
+ 'u64',
1560
+ 'u8',
1561
+ null
1562
+ ];
1563
+ const parameterNames = ["minCollateralValue", "collateralAmount", "collateralDecimal", "collateralPrice"];
1564
+ return (tx) => tx.moveCall({
1565
+ package: packageAddress,
1566
+ module: 'trading',
1567
+ function: 'assert_min_position_collateral_value',
1568
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1569
+ });
1570
+ }
1571
+ export function proportionalAmount(options) {
1572
+ const packageAddress = options.package ?? '@waterx/perp';
1573
+ const argumentsTypes = [
1574
+ 'u64',
1575
+ null,
1576
+ null
1577
+ ];
1578
+ const parameterNames = ["total", "partial", "base"];
1579
+ return (tx) => tx.moveCall({
1580
+ package: packageAddress,
1581
+ module: 'trading',
1582
+ function: 'proportional_amount',
1583
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1584
+ });
1585
+ }
1586
+ export function debitCollateralAmount(options) {
1587
+ const packageAddress = options.package ?? '@waterx/perp';
1588
+ const argumentsTypes = [
1589
+ 'u64',
1590
+ 'u128',
1591
+ 'u64'
1592
+ ];
1593
+ const parameterNames = ["remaining", "deficit", "amount"];
1594
+ return (tx) => tx.moveCall({
1595
+ package: packageAddress,
1596
+ module: 'trading',
1597
+ function: 'debit_collateral_amount',
1598
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1599
+ });
1600
+ }
1601
+ export function creditCollateralAmount(options) {
1602
+ const packageAddress = options.package ?? '@waterx/perp';
1603
+ const argumentsTypes = [
1604
+ 'u64',
1605
+ 'u128',
1606
+ 'u64'
1607
+ ];
1608
+ const parameterNames = ["remaining", "deficit", "amount"];
1609
+ return (tx) => tx.moveCall({
1610
+ package: packageAddress,
1611
+ module: 'trading',
1612
+ function: 'credit_collateral_amount',
1613
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1614
+ });
1615
+ }
1616
+ export function calculateRemainingCollateralAfterPartialReduce(options) {
1617
+ const packageAddress = options.package ?? '@waterx/perp';
1618
+ const argumentsTypes = [
1619
+ null,
1620
+ null,
1621
+ 'u64',
1622
+ null,
1623
+ null,
1624
+ 'u64'
1625
+ ];
1626
+ const parameterNames = ["position", "reduceSize", "closeFee", "currentPrice", "collateralPrice", "addedCollateralAmount"];
1627
+ return (tx) => tx.moveCall({
1628
+ package: packageAddress,
1629
+ module: 'trading',
1630
+ function: 'calculate_remaining_collateral_after_partial_reduce',
1631
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1632
+ });
1633
+ }
1634
+ /**
1635
+ * Non-aborting growth check used by keeper order matching. Invalid standalone
1636
+ * orders are rotated behind valid orders at the same trigger price.
1637
+ */
1638
+ export function canPositionGrow(options) {
1639
+ const packageAddress = options.package ?? '@waterx/perp';
1640
+ const argumentsTypes = [
1641
+ null,
1642
+ null,
1643
+ null,
1644
+ 'bool',
1645
+ null,
1646
+ null,
1647
+ 'u64',
1648
+ 'u8',
1649
+ null,
1650
+ null,
1651
+ null
1652
+ ];
1653
+ const parameterNames = ["globalConfig", "marketConfig", "pool", "isLong", "currentSize", "addedSize", "effectiveCollateralAmount", "collateralDecimal", "collateralToken", "executionPrice", "collateralPrice"];
1654
+ return (tx) => tx.moveCall({
1655
+ package: packageAddress,
1656
+ module: 'trading',
1657
+ function: 'can_position_grow',
1658
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1659
+ typeArguments: options.typeArguments
1660
+ });
1661
+ }
1662
+ export function validatePositionGrowth(options) {
1663
+ const packageAddress = options.package ?? '@waterx/perp';
1664
+ const argumentsTypes = [
1665
+ null,
1666
+ null,
1667
+ null,
1668
+ 'bool',
1669
+ null,
1670
+ null,
1671
+ 'u64',
1672
+ 'u8',
1673
+ null,
1674
+ null,
1675
+ null
1676
+ ];
1677
+ const parameterNames = ["globalConfig", "marketConfig", "pool", "isLong", "currentSize", "addedSize", "effectiveCollateralAmount", "collateralDecimal", "collateralToken", "executionPrice", "collateralPrice"];
1678
+ return (tx) => tx.moveCall({
1679
+ package: packageAddress,
1680
+ module: 'trading',
1681
+ function: 'validate_position_growth',
1682
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1683
+ typeArguments: options.typeArguments
1684
+ });
1685
+ }
1686
+ export function weightedAveragePrice(options) {
1687
+ const packageAddress = options.package ?? '@waterx/perp';
1688
+ const argumentsTypes = [
1689
+ null,
1690
+ null,
1691
+ null,
1692
+ null
1693
+ ];
1694
+ const parameterNames = ["currentSize", "currentAveragePrice", "addSize", "fillPrice"];
1695
+ return (tx) => tx.moveCall({
1696
+ package: packageAddress,
1697
+ module: 'trading',
1698
+ function: 'weighted_average_price',
1699
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1700
+ });
1701
+ }
1702
+ export function normalizeTriggerPrice(options) {
1703
+ const packageAddress = options.package ?? '@waterx/perp';
1704
+ const argumentsTypes = [
1705
+ null,
1706
+ null
1707
+ ];
1708
+ const parameterNames = ["triggerPrice", "orderPriceTick"];
1709
+ return (tx) => tx.moveCall({
1710
+ package: packageAddress,
1711
+ module: 'trading',
1712
+ function: 'normalize_trigger_price',
1713
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1714
+ });
1715
+ }
1716
+ /** View: whether `main_order_id` has reserved pre-orders pending in `market`. */
1717
+ export function hasPendingPreOrders(options) {
1718
+ const packageAddress = options.package ?? '@waterx/perp';
1719
+ const argumentsTypes = [
1720
+ null,
1721
+ 'u64'
1722
+ ];
1723
+ const parameterNames = ["market", "mainOrderId"];
1724
+ return (tx) => tx.moveCall({
1725
+ package: packageAddress,
1726
+ module: 'trading',
1727
+ function: 'has_pending_pre_orders',
1728
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1729
+ typeArguments: options.typeArguments
1730
+ });
1731
+ }
1732
+ /**
1733
+ * View: how many pre-orders are reserved against `main_order_id`. `0` if no entry
1734
+ * exists.
1735
+ */
1736
+ export function pendingPreOrdersCount(options) {
1737
+ const packageAddress = options.package ?? '@waterx/perp';
1738
+ const argumentsTypes = [
1739
+ null,
1740
+ 'u64'
1741
+ ];
1742
+ const parameterNames = ["market", "mainOrderId"];
1743
+ return (tx) => tx.moveCall({
1744
+ package: packageAddress,
1745
+ module: 'trading',
1746
+ function: 'pending_pre_orders_count',
1747
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1748
+ typeArguments: options.typeArguments
1749
+ });
1750
+ }
1751
+ /**
1752
+ * Mints fresh order ids for every `PlaceOrderArgument` in `pre_orders`, builds a
1753
+ * real `Order` per entry (reduce-only, zero-collateral,
1754
+ * `linked_position_id = None`), stashes each one in `pending_pre_orders` under its
1755
+ * own id, and records the id list in `pending_pre_order_index` under
1756
+ * `main_order_id` — appending to any existing entry so this helper also works for
1757
+ * the per-leg `add_pre_order` path. Emits one `PreOrderCreated` per reserved
1758
+ * pre-order. No-op when `pre_orders` is empty.
1759
+ */
1760
+ export function reservePreOrders(options) {
1761
+ const packageAddress = options.package ?? '@waterx/perp';
1762
+ const argumentsTypes = [
1763
+ null,
1764
+ null,
1765
+ 'u64',
1766
+ 'address',
1767
+ '0x2::object::ID',
1768
+ 'u8',
1769
+ 'vector<null>',
1770
+ '0x2::clock::Clock'
1771
+ ];
1772
+ const parameterNames = ["globalConfig", "market", "mainOrderId", "accountObjectAddress", "marketId", "collateralDecimal", "preOrders"];
1773
+ return (tx) => tx.moveCall({
1774
+ package: packageAddress,
1775
+ module: 'trading',
1776
+ function: 'reserve_pre_orders',
1777
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1778
+ typeArguments: options.typeArguments
1779
+ });
1780
+ }
1781
+ /**
1782
+ * Drops every pre-order reserved against `main_order_id` (if any), destroying each
1783
+ * via `position::remove_order` (which splits the zero collateral back into the
1784
+ * vault and deletes the order UID) and emitting one `PreOrderCancelled` per
1785
+ * dropped pre-order.
1786
+ */
1787
+ export function dropPendingPreOrdersIfExists(options) {
1788
+ const packageAddress = options.package ?? '@waterx/perp';
1789
+ const argumentsTypes = [
1790
+ null,
1791
+ null,
1792
+ '0x2::object::ID',
1793
+ 'address',
1794
+ 'u64'
1795
+ ];
1796
+ const parameterNames = ["globalConfig", "market", "marketId", "accountObjectAddress", "mainOrderId"];
1797
+ return (tx) => tx.moveCall({
1798
+ package: packageAddress,
1799
+ module: 'trading',
1800
+ function: 'drop_pending_pre_orders_if_exists',
1801
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1802
+ typeArguments: options.typeArguments
1803
+ });
1804
+ }
1805
+ /**
1806
+ * Promotes reserved pre-orders to real reduce-only linked orders on the freshly
1807
+ * opened position. Called from the standalone-fill branch of `match_orders` right
1808
+ * before the new position is pushed to the market. Each reserved `Order` was
1809
+ * created at place time with `linked_position_id = None`; here we stamp in the new
1810
+ * `position_id` and move the order onto the live book.
1811
+ */
1812
+ export function activatePendingPreOrders(options) {
1813
+ const packageAddress = options.package ?? '@waterx/perp';
1814
+ const argumentsTypes = [
1815
+ null,
1816
+ null,
1817
+ null,
1818
+ 'u64',
1819
+ 'u64',
1820
+ 'address',
1821
+ '0x2::object::ID'
1822
+ ];
1823
+ const parameterNames = ["wxaRegistry", "market", "pos", "positionId", "mainOrderId", "accountObjectAddress", "marketId"];
1824
+ return (tx) => tx.moveCall({
1825
+ package: packageAddress,
1826
+ module: 'trading',
1827
+ function: 'activate_pending_pre_orders',
1828
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1829
+ typeArguments: options.typeArguments
1830
+ });
1831
+ }
1832
+ export function assertPositionOwner(options) {
1833
+ const packageAddress = options.package ?? '@waterx/perp';
1834
+ const argumentsTypes = [
1835
+ null,
1836
+ 'address'
1837
+ ];
1838
+ const parameterNames = ["position", "accountObjectAddress"];
1839
+ return (tx) => tx.moveCall({
1840
+ package: packageAddress,
1841
+ module: 'trading',
1842
+ function: 'assert_position_owner',
1843
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1844
+ });
1845
+ }
1846
+ export function assertPositionCollateralType(options) {
1847
+ const packageAddress = options.package ?? '@waterx/perp';
1848
+ const argumentsTypes = [
1849
+ null
1850
+ ];
1851
+ const parameterNames = ["position"];
1852
+ return (tx) => tx.moveCall({
1853
+ package: packageAddress,
1854
+ module: 'trading',
1855
+ function: 'assert_position_collateral_type',
1856
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1857
+ typeArguments: options.typeArguments
1858
+ });
1859
+ }
1860
+ export function borrowOwnedPosition(options) {
1861
+ const packageAddress = options.package ?? '@waterx/perp';
1862
+ const argumentsTypes = [
1863
+ null,
1864
+ 'u64',
1865
+ 'address'
1866
+ ];
1867
+ const parameterNames = ["market", "positionId", "accountObjectAddress"];
1868
+ return (tx) => tx.moveCall({
1869
+ package: packageAddress,
1870
+ module: 'trading',
1871
+ function: 'borrow_owned_position',
1872
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1873
+ typeArguments: options.typeArguments
1874
+ });
1875
+ }
1876
+ export function borrowOwnedPositionMut(options) {
1877
+ const packageAddress = options.package ?? '@waterx/perp';
1878
+ const argumentsTypes = [
1879
+ null,
1880
+ 'u64',
1881
+ 'address'
1882
+ ];
1883
+ const parameterNames = ["market", "positionId", "accountObjectAddress"];
1884
+ return (tx) => tx.moveCall({
1885
+ package: packageAddress,
1886
+ module: 'trading',
1887
+ function: 'borrow_owned_position_mut',
1888
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1889
+ typeArguments: options.typeArguments
1890
+ });
1891
+ }
1892
+ export function takeOwnedPosition(options) {
1893
+ const packageAddress = options.package ?? '@waterx/perp';
1894
+ const argumentsTypes = [
1895
+ null,
1896
+ 'u64',
1897
+ 'address',
1898
+ 'u64',
1899
+ 'bool'
1900
+ ];
1901
+ const parameterNames = ["market", "positionId", "accountObjectAddress", "now", "requireCooldown"];
1902
+ return (tx) => tx.moveCall({
1903
+ package: packageAddress,
1904
+ module: 'trading',
1905
+ function: 'take_owned_position',
1906
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1907
+ typeArguments: options.typeArguments
1908
+ });
1909
+ }
1910
+ export function findOrderTypeTag(options) {
1911
+ const packageAddress = options.package ?? '@waterx/perp';
1912
+ const argumentsTypes = [
1913
+ null,
1914
+ 'u128',
1915
+ 'u64'
1916
+ ];
1917
+ const parameterNames = ["market", "triggerPriceKey", "orderId"];
1918
+ return (tx) => tx.moveCall({
1919
+ package: packageAddress,
1920
+ module: 'trading',
1921
+ function: 'find_order_type_tag',
1922
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1923
+ typeArguments: options.typeArguments
1924
+ });
1925
+ }
1926
+ export function findCancelOrderLocation(options) {
1927
+ const packageAddress = options.package ?? '@waterx/perp';
1928
+ const argumentsTypes = [
1929
+ null,
1930
+ 'u8',
1931
+ 'u128',
1932
+ 'u64'
1933
+ ];
1934
+ const parameterNames = ["market", "orderTypeTag", "triggerPrice", "orderId"];
1935
+ return (tx) => tx.moveCall({
1936
+ package: packageAddress,
1937
+ module: 'trading',
1938
+ function: 'find_cancel_order_location',
1939
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1940
+ typeArguments: options.typeArguments
1941
+ });
1942
+ }
1943
+ export function findOrderLocationById(options) {
1944
+ const packageAddress = options.package ?? '@waterx/perp';
1945
+ const argumentsTypes = [
1946
+ null,
1947
+ 'u8',
1948
+ 'u64'
1949
+ ];
1950
+ const parameterNames = ["market", "orderTypeTag", "orderId"];
1951
+ return (tx) => tx.moveCall({
1952
+ package: packageAddress,
1953
+ module: 'trading',
1954
+ function: 'find_order_location_by_id',
1955
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1956
+ typeArguments: options.typeArguments
1957
+ });
1958
+ }
1959
+ export function findOrderPriceKeyInBook(options) {
1960
+ const packageAddress = options.package ?? '@waterx/perp';
1961
+ const argumentsTypes = [
1962
+ null,
1963
+ 'u64'
1964
+ ];
1965
+ const parameterNames = ["book", "orderId"];
1966
+ return (tx) => tx.moveCall({
1967
+ package: packageAddress,
1968
+ module: 'trading',
1969
+ function: 'find_order_price_key_in_book',
1970
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1971
+ });
1972
+ }
1973
+ export function levelContainsOrder(options) {
1974
+ const packageAddress = options.package ?? '@waterx/perp';
1975
+ const argumentsTypes = [
1976
+ null,
1977
+ 'u64'
1978
+ ];
1979
+ const parameterNames = ["level", "orderId"];
1980
+ return (tx) => tx.moveCall({
1981
+ package: packageAddress,
1982
+ module: 'trading',
1983
+ function: 'level_contains_order',
1984
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1985
+ });
1986
+ }
1987
+ export function hasOrderInBook(options) {
1988
+ const packageAddress = options.package ?? '@waterx/perp';
1989
+ const argumentsTypes = [
1990
+ null,
1991
+ 'u128',
1992
+ 'u64'
1993
+ ];
1994
+ const parameterNames = ["book", "priceKey", "orderId"];
1995
+ return (tx) => tx.moveCall({
1996
+ package: packageAddress,
1997
+ module: 'trading',
1998
+ function: 'has_order_in_book',
1999
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2000
+ });
2001
+ }
2002
+ export function takeLinkedOrderAtKey(options) {
2003
+ const packageAddress = options.package ?? '@waterx/perp';
2004
+ const argumentsTypes = [
2005
+ null,
2006
+ 'u128',
2007
+ 'u64'
2008
+ ];
2009
+ const parameterNames = ["market", "triggerPriceKey", "orderId"];
2010
+ return (tx) => tx.moveCall({
2011
+ package: packageAddress,
2012
+ module: 'trading',
2013
+ function: 'take_linked_order_at_key',
2014
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2015
+ typeArguments: options.typeArguments
2016
+ });
2017
+ }
2018
+ export function cancelLinkedOrdersToBalance(options) {
2019
+ const packageAddress = options.package ?? '@waterx/perp';
2020
+ const argumentsTypes = [
2021
+ null,
2022
+ null,
2023
+ null,
2024
+ '0x2::object::ID',
2025
+ 'vector<u64>',
2026
+ 'vector<u128>',
2027
+ 'u8'
2028
+ ];
2029
+ const parameterNames = ["globalConfig", "wxaRegistry", "market", "accountId", "linkedOrderIds", "linkedOrderPriceKeys", "memoCode"];
2030
+ return (tx) => tx.moveCall({
2031
+ package: packageAddress,
2032
+ module: 'trading',
2033
+ function: 'cancel_linked_orders_to_balance',
2034
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2035
+ typeArguments: options.typeArguments
2036
+ });
2037
+ }
2038
+ export function borrowMutOrderBook(options) {
2039
+ const packageAddress = options.package ?? '@waterx/perp';
2040
+ const argumentsTypes = [
2041
+ null,
2042
+ 'u8'
2043
+ ];
2044
+ const parameterNames = ["market", "tag"];
2045
+ return (tx) => tx.moveCall({
2046
+ package: packageAddress,
2047
+ module: 'trading',
2048
+ function: 'borrow_mut_order_book',
2049
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2050
+ typeArguments: options.typeArguments
2051
+ });
2052
+ }
2053
+ export function takeOrderDirect(options) {
2054
+ const packageAddress = options.package ?? '@waterx/perp';
2055
+ const argumentsTypes = [
2056
+ null,
2057
+ 'u128',
2058
+ 'u64',
2059
+ 'address',
2060
+ 'u8'
2061
+ ];
2062
+ const parameterNames = ["market", "triggerPriceKey", "orderId", "user", "orderTypeTag"];
2063
+ return (tx) => tx.moveCall({
2064
+ package: packageAddress,
2065
+ module: 'trading',
2066
+ function: 'take_order_direct',
2067
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2068
+ typeArguments: options.typeArguments
2069
+ });
2070
+ }
2071
+ /**
2072
+ * Returns `balance` to the user's wxa stored balance under the `WaterXPerp`
2073
+ * witness. `account_obj_addr` is the wxa account's UID address (i.e.
2074
+ * `account_id.to_address()`), so `.to_id()` recovers the account_id. Zero balances
2075
+ * are silently destroyed (no event).
2076
+ */
2077
+ export function returnToUser(options) {
2078
+ const packageAddress = options.package ?? '@waterx/perp';
2079
+ const argumentsTypes = [
2080
+ null,
2081
+ null,
2082
+ 'address'
2083
+ ];
2084
+ const parameterNames = ["wxaRegistry", "balance", "accountObjAddr"];
2085
+ return (tx) => tx.moveCall({
2086
+ package: packageAddress,
2087
+ module: 'trading',
2088
+ function: 'return_to_user',
2089
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2090
+ typeArguments: options.typeArguments
2091
+ });
2092
+ }
2093
+ /** Returns the object ID of this Market (trading vault). */
2094
+ export function marketId(options) {
2095
+ const packageAddress = options.package ?? '@waterx/perp';
2096
+ const argumentsTypes = [
2097
+ null
2098
+ ];
2099
+ const parameterNames = ["market"];
2100
+ return (tx) => tx.moveCall({
2101
+ package: packageAddress,
2102
+ module: 'trading',
2103
+ function: 'market_id',
2104
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2105
+ typeArguments: options.typeArguments
2106
+ });
2107
+ }
2108
+ /** Borrows a position by ID. */
2109
+ export function borrowPosition(options) {
2110
+ const packageAddress = options.package ?? '@waterx/perp';
2111
+ const argumentsTypes = [
2112
+ null,
2113
+ 'u64'
2114
+ ];
2115
+ const parameterNames = ["market", "positionId"];
2116
+ return (tx) => tx.moveCall({
2117
+ package: packageAddress,
2118
+ module: 'trading',
2119
+ function: 'borrow_position',
2120
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2121
+ typeArguments: options.typeArguments
2122
+ });
2123
+ }
2124
+ /** Checks if a position exists. */
2125
+ export function hasPosition(options) {
2126
+ const packageAddress = options.package ?? '@waterx/perp';
2127
+ const argumentsTypes = [
2128
+ null,
2129
+ 'u64'
2130
+ ];
2131
+ const parameterNames = ["market", "positionId"];
2132
+ return (tx) => tx.moveCall({
2133
+ package: packageAddress,
2134
+ module: 'trading',
2135
+ function: 'has_position',
2136
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2137
+ typeArguments: options.typeArguments
2138
+ });
2139
+ }
2140
+ /** Borrows a single order by type, price key, and order id. */
2141
+ export function borrowOrder(options) {
2142
+ const packageAddress = options.package ?? '@waterx/perp';
2143
+ const argumentsTypes = [
2144
+ null,
2145
+ 'u8',
2146
+ 'u128',
2147
+ 'u64'
2148
+ ];
2149
+ const parameterNames = ["market", "orderTypeTag", "triggerPriceKey", "orderId"];
2150
+ return (tx) => tx.moveCall({
2151
+ package: packageAddress,
2152
+ module: 'trading',
2153
+ function: 'borrow_order',
2154
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2155
+ typeArguments: options.typeArguments
2156
+ });
2157
+ }
2158
+ /** Borrows the positions KeyedBigVector (for paginated iteration). */
2159
+ export function borrowPositions(options) {
2160
+ const packageAddress = options.package ?? '@waterx/perp';
2161
+ const argumentsTypes = [
2162
+ null
2163
+ ];
2164
+ const parameterNames = ["market"];
2165
+ return (tx) => tx.moveCall({
2166
+ package: packageAddress,
2167
+ module: 'trading',
2168
+ function: 'borrow_positions',
2169
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2170
+ typeArguments: options.typeArguments
2171
+ });
2172
+ }
2173
+ /** Borrows an order book by type tag (0-3), read-only. */
2174
+ export function borrowOrderBook(options) {
2175
+ const packageAddress = options.package ?? '@waterx/perp';
2176
+ const argumentsTypes = [
2177
+ null,
2178
+ 'u8'
2179
+ ];
2180
+ const parameterNames = ["market", "orderTypeTag"];
2181
+ return (tx) => tx.moveCall({
2182
+ package: packageAddress,
2183
+ module: 'trading',
2184
+ function: 'borrow_order_book',
2185
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2186
+ typeArguments: options.typeArguments
2187
+ });
2188
+ }
2189
+ /** Borrows the market config (for view.move). */
2190
+ export function borrowConfig(options) {
2191
+ const packageAddress = options.package ?? '@waterx/perp';
2192
+ const argumentsTypes = [
2193
+ null
2194
+ ];
2195
+ const parameterNames = ["market"];
2196
+ return (tx) => tx.moveCall({
2197
+ package: packageAddress,
2198
+ module: 'trading',
2199
+ function: 'borrow_config',
2200
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2201
+ typeArguments: options.typeArguments
2202
+ });
2203
+ }
2204
+ export function marketSymbol(options) {
2205
+ const packageAddress = options.package ?? '@waterx/perp';
2206
+ const argumentsTypes = [
2207
+ null
2208
+ ];
2209
+ const parameterNames = ["market"];
2210
+ return (tx) => tx.moveCall({
2211
+ package: packageAddress,
2212
+ module: 'trading',
2213
+ function: 'market_symbol',
2214
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2215
+ typeArguments: options.typeArguments
2216
+ });
2217
+ }
2218
+ /** Creates and shares a new `MarketRegistry`. Admin-gated. */
2219
+ export function createMarketRegistry(options) {
2220
+ const packageAddress = options.package ?? '@waterx/perp';
2221
+ const argumentsTypes = [
2222
+ null
2223
+ ];
2224
+ const parameterNames = ["Cap"];
2225
+ return (tx) => tx.moveCall({
2226
+ package: packageAddress,
2227
+ module: 'trading',
2228
+ function: 'create_market_registry',
2229
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2230
+ typeArguments: options.typeArguments
2231
+ });
2232
+ }
2233
+ export function registryAssertVersion(options) {
2234
+ const packageAddress = options.package ?? '@waterx/perp';
2235
+ const argumentsTypes = [
2236
+ null
2237
+ ];
2238
+ const parameterNames = ["registry"];
2239
+ return (tx) => tx.moveCall({
2240
+ package: packageAddress,
2241
+ module: 'trading',
2242
+ function: 'registry_assert_version',
2243
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2244
+ typeArguments: options.typeArguments
2245
+ });
2246
+ }
2247
+ export function registryAllowVersion(options) {
2248
+ const packageAddress = options.package ?? '@waterx/perp';
2249
+ const argumentsTypes = [
2250
+ null,
2251
+ null,
2252
+ 'u16'
2253
+ ];
2254
+ const parameterNames = ["registry", "_", "v"];
2255
+ return (tx) => tx.moveCall({
2256
+ package: packageAddress,
2257
+ module: 'trading',
2258
+ function: 'registry_allow_version',
2259
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2260
+ typeArguments: options.typeArguments
2261
+ });
2262
+ }
2263
+ export function registryDisallowVersion(options) {
2264
+ const packageAddress = options.package ?? '@waterx/perp';
2265
+ const argumentsTypes = [
2266
+ null,
2267
+ null,
2268
+ 'u16'
2269
+ ];
2270
+ const parameterNames = ["registry", "_", "v"];
2271
+ return (tx) => tx.moveCall({
2272
+ package: packageAddress,
2273
+ module: 'trading',
2274
+ function: 'registry_disallow_version',
2275
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2276
+ typeArguments: options.typeArguments
2277
+ });
2278
+ }
2279
+ /** Stores `market` in the registry under `ticker`. Aborts if already taken. */
2280
+ export function addMarket(options) {
2281
+ const packageAddress = options.package ?? '@waterx/perp';
2282
+ const argumentsTypes = [
2283
+ null,
2284
+ null,
2285
+ '0x1::string::String',
2286
+ null
2287
+ ];
2288
+ const parameterNames = ["registry", "Cap", "ticker", "market"];
2289
+ return (tx) => tx.moveCall({
2290
+ package: packageAddress,
2291
+ module: 'trading',
2292
+ function: 'add_market',
2293
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2294
+ typeArguments: options.typeArguments
2295
+ });
2296
+ }
2297
+ /** Removes a market from the registry and returns it. */
2298
+ export function removeMarket(options) {
2299
+ const packageAddress = options.package ?? '@waterx/perp';
2300
+ const argumentsTypes = [
2301
+ null,
2302
+ null,
2303
+ '0x1::string::String'
2304
+ ];
2305
+ const parameterNames = ["registry", "Cap", "ticker"];
2306
+ return (tx) => tx.moveCall({
2307
+ package: packageAddress,
2308
+ module: 'trading',
2309
+ function: 'remove_market',
2310
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2311
+ typeArguments: options.typeArguments
2312
+ });
2313
+ }
2314
+ export function hasMarket(options) {
2315
+ const packageAddress = options.package ?? '@waterx/perp';
2316
+ const argumentsTypes = [
2317
+ null,
2318
+ '0x1::string::String'
2319
+ ];
2320
+ const parameterNames = ["registry", "ticker"];
2321
+ return (tx) => tx.moveCall({
2322
+ package: packageAddress,
2323
+ module: 'trading',
2324
+ function: 'has_market',
2325
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2326
+ typeArguments: options.typeArguments
2327
+ });
2328
+ }
2329
+ export function listedTickers(options) {
2330
+ const packageAddress = options.package ?? '@waterx/perp';
2331
+ const argumentsTypes = [
2332
+ null
2333
+ ];
2334
+ const parameterNames = ["registry"];
2335
+ return (tx) => tx.moveCall({
2336
+ package: packageAddress,
2337
+ module: 'trading',
2338
+ function: 'listed_tickers',
2339
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2340
+ typeArguments: options.typeArguments
2341
+ });
2342
+ }
2343
+ export function borrowMarket(options) {
2344
+ const packageAddress = options.package ?? '@waterx/perp';
2345
+ const argumentsTypes = [
2346
+ null,
2347
+ '0x1::string::String'
2348
+ ];
2349
+ const parameterNames = ["registry", "ticker"];
2350
+ return (tx) => tx.moveCall({
2351
+ package: packageAddress,
2352
+ module: 'trading',
2353
+ function: 'borrow_market',
2354
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2355
+ typeArguments: options.typeArguments
2356
+ });
2357
+ }
2358
+ export function borrowMarketMut(options) {
2359
+ const packageAddress = options.package ?? '@waterx/perp';
2360
+ const argumentsTypes = [
2361
+ null,
2362
+ '0x1::string::String'
2363
+ ];
2364
+ const parameterNames = ["registry", "ticker"];
2365
+ return (tx) => tx.moveCall({
2366
+ package: packageAddress,
2367
+ module: 'trading',
2368
+ function: 'borrow_market_mut',
2369
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
2370
+ typeArguments: options.typeArguments
2371
+ });
2372
+ }