@mysten/deepbook-v3 1.5.9 → 1.6.2

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 (177) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/client.d.mts +5 -0
  3. package/dist/client.d.mts.map +1 -1
  4. package/dist/client.mjs +7 -0
  5. package/dist/client.mjs.map +1 -1
  6. package/dist/contracts/deepbook/balance_manager.mjs +413 -0
  7. package/dist/contracts/deepbook/balance_manager.mjs.map +1 -0
  8. package/dist/contracts/deepbook/balances.d.mts +4 -4
  9. package/dist/contracts/deepbook/big_vector.mjs +43 -0
  10. package/dist/contracts/deepbook/big_vector.mjs.map +1 -0
  11. package/dist/contracts/deepbook/book.mjs +29 -0
  12. package/dist/contracts/deepbook/book.mjs.map +1 -0
  13. package/dist/contracts/deepbook/deep_price.d.mts +3 -3
  14. package/dist/contracts/deepbook/deep_price.mjs +1 -1
  15. package/dist/contracts/deepbook/deps/std/type_name.mjs +17 -0
  16. package/dist/contracts/deepbook/deps/std/type_name.mjs.map +1 -0
  17. package/dist/contracts/deepbook/deps/sui/bag.mjs +43 -0
  18. package/dist/contracts/deepbook/deps/sui/bag.mjs.map +1 -0
  19. package/dist/contracts/deepbook/deps/sui/balance.mjs +21 -0
  20. package/dist/contracts/deepbook/deps/sui/balance.mjs.map +1 -0
  21. package/dist/contracts/deepbook/deps/sui/table.mjs +38 -0
  22. package/dist/contracts/deepbook/deps/sui/table.mjs.map +1 -0
  23. package/dist/contracts/deepbook/deps/sui/vec_map.mjs +37 -0
  24. package/dist/contracts/deepbook/deps/sui/vec_map.mjs.map +1 -0
  25. package/dist/contracts/deepbook/deps/sui/versioned.mjs +19 -0
  26. package/dist/contracts/deepbook/deps/sui/versioned.mjs.map +1 -0
  27. package/dist/contracts/deepbook/governance.mjs +49 -0
  28. package/dist/contracts/deepbook/governance.mjs.map +1 -0
  29. package/dist/contracts/deepbook/history.mjs +56 -0
  30. package/dist/contracts/deepbook/history.mjs.map +1 -0
  31. package/dist/contracts/deepbook/order.d.mts +12 -12
  32. package/dist/contracts/deepbook/pool.mjs +1739 -0
  33. package/dist/contracts/deepbook/pool.mjs.map +1 -0
  34. package/dist/contracts/deepbook/registry.mjs +295 -0
  35. package/dist/contracts/deepbook/registry.mjs.map +1 -0
  36. package/dist/contracts/deepbook/state.mjs +89 -0
  37. package/dist/contracts/deepbook/state.mjs.map +1 -0
  38. package/dist/contracts/deepbook/trade_params.mjs +21 -0
  39. package/dist/contracts/deepbook/trade_params.mjs.map +1 -0
  40. package/dist/contracts/deepbook/vault.mjs +42 -0
  41. package/dist/contracts/deepbook/vault.mjs.map +1 -0
  42. package/dist/contracts/deepbook_margin/deps/deepbook/balance_manager.mjs +53 -0
  43. package/dist/contracts/deepbook_margin/deps/deepbook/balance_manager.mjs.map +1 -0
  44. package/dist/contracts/deepbook_margin/deps/std/type_name.mjs +17 -0
  45. package/dist/contracts/deepbook_margin/deps/std/type_name.mjs.map +1 -0
  46. package/dist/contracts/deepbook_margin/deps/sui/bag.mjs +43 -0
  47. package/dist/contracts/deepbook_margin/deps/sui/bag.mjs.map +1 -0
  48. package/dist/contracts/deepbook_margin/deps/sui/balance.mjs +21 -0
  49. package/dist/contracts/deepbook_margin/deps/sui/balance.mjs.map +1 -0
  50. package/dist/contracts/deepbook_margin/deps/sui/table.mjs +38 -0
  51. package/dist/contracts/deepbook_margin/deps/sui/table.mjs.map +1 -0
  52. package/dist/contracts/deepbook_margin/deps/sui/vec_map.mjs +37 -0
  53. package/dist/contracts/deepbook_margin/deps/sui/vec_map.mjs.map +1 -0
  54. package/dist/contracts/deepbook_margin/deps/sui/vec_set.mjs +26 -0
  55. package/dist/contracts/deepbook_margin/deps/sui/vec_set.mjs.map +1 -0
  56. package/dist/contracts/deepbook_margin/deps/sui/versioned.mjs +19 -0
  57. package/dist/contracts/deepbook_margin/deps/sui/versioned.mjs.map +1 -0
  58. package/dist/contracts/deepbook_margin/margin_manager.mjs +989 -0
  59. package/dist/contracts/deepbook_margin/margin_manager.mjs.map +1 -0
  60. package/dist/contracts/deepbook_margin/margin_pool.mjs +550 -0
  61. package/dist/contracts/deepbook_margin/margin_pool.mjs.map +1 -0
  62. package/dist/contracts/deepbook_margin/margin_registry.mjs +786 -0
  63. package/dist/contracts/deepbook_margin/margin_registry.mjs.map +1 -0
  64. package/dist/contracts/deepbook_margin/margin_state.mjs +30 -0
  65. package/dist/contracts/deepbook_margin/margin_state.mjs.map +1 -0
  66. package/dist/contracts/deepbook_margin/oracle.mjs +82 -0
  67. package/dist/contracts/deepbook_margin/oracle.mjs.map +1 -0
  68. package/dist/contracts/deepbook_margin/pool_proxy.mjs +644 -0
  69. package/dist/contracts/deepbook_margin/pool_proxy.mjs.map +1 -0
  70. package/dist/contracts/deepbook_margin/position_manager.mjs +32 -0
  71. package/dist/contracts/deepbook_margin/position_manager.mjs.map +1 -0
  72. package/dist/contracts/deepbook_margin/protocol_config.mjs +122 -0
  73. package/dist/contracts/deepbook_margin/protocol_config.mjs.map +1 -0
  74. package/dist/contracts/deepbook_margin/protocol_fees.mjs +58 -0
  75. package/dist/contracts/deepbook_margin/protocol_fees.mjs.map +1 -0
  76. package/dist/contracts/deepbook_margin/rate_limiter.mjs +26 -0
  77. package/dist/contracts/deepbook_margin/rate_limiter.mjs.map +1 -0
  78. package/dist/contracts/deepbook_margin/tpsl.mjs +171 -0
  79. package/dist/contracts/deepbook_margin/tpsl.mjs.map +1 -0
  80. package/dist/contracts/margin_liquidation/deps/sui/bag.mjs +43 -0
  81. package/dist/contracts/margin_liquidation/deps/sui/bag.mjs.map +1 -0
  82. package/dist/contracts/margin_liquidation/liquidation_vault.mjs +179 -0
  83. package/dist/contracts/margin_liquidation/liquidation_vault.mjs.map +1 -0
  84. package/dist/contracts/utils/index.d.mts +1 -1
  85. package/dist/contracts/utils/index.mjs +92 -3
  86. package/dist/contracts/utils/index.mjs.map +1 -1
  87. package/dist/queries/registryQueries.mjs +13 -0
  88. package/dist/queries/registryQueries.mjs.map +1 -1
  89. package/dist/transactions/balanceManager.d.mts.map +1 -1
  90. package/dist/transactions/balanceManager.mjs +119 -100
  91. package/dist/transactions/balanceManager.mjs.map +1 -1
  92. package/dist/transactions/deepbook.d.mts.map +1 -1
  93. package/dist/transactions/deepbook.mjs +464 -439
  94. package/dist/transactions/deepbook.mjs.map +1 -1
  95. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  96. package/dist/transactions/deepbookAdmin.mjs +151 -135
  97. package/dist/transactions/deepbookAdmin.mjs.map +1 -1
  98. package/dist/transactions/flashLoans.d.mts.map +1 -1
  99. package/dist/transactions/flashLoans.mjs +29 -22
  100. package/dist/transactions/flashLoans.mjs.map +1 -1
  101. package/dist/transactions/governance.d.mts.map +1 -1
  102. package/dist/transactions/governance.mjs +34 -33
  103. package/dist/transactions/governance.mjs.map +1 -1
  104. package/dist/transactions/marginAdmin.d.mts +10 -0
  105. package/dist/transactions/marginAdmin.d.mts.map +1 -1
  106. package/dist/transactions/marginAdmin.mjs +186 -169
  107. package/dist/transactions/marginAdmin.mjs.map +1 -1
  108. package/dist/transactions/marginLiquidations.d.mts +3 -3
  109. package/dist/transactions/marginLiquidations.d.mts.map +1 -1
  110. package/dist/transactions/marginLiquidations.mjs +53 -54
  111. package/dist/transactions/marginLiquidations.mjs.map +1 -1
  112. package/dist/transactions/marginMaintainer.d.mts.map +1 -1
  113. package/dist/transactions/marginMaintainer.mjs +83 -83
  114. package/dist/transactions/marginMaintainer.mjs.map +1 -1
  115. package/dist/transactions/marginManager.d.mts.map +1 -1
  116. package/dist/transactions/marginManager.mjs +330 -311
  117. package/dist/transactions/marginManager.mjs.map +1 -1
  118. package/dist/transactions/marginPool.d.mts.map +1 -1
  119. package/dist/transactions/marginPool.mjs +93 -89
  120. package/dist/transactions/marginPool.mjs.map +1 -1
  121. package/dist/transactions/marginRegistry.d.mts +22 -15
  122. package/dist/transactions/marginRegistry.d.mts.map +1 -1
  123. package/dist/transactions/marginRegistry.mjs +101 -68
  124. package/dist/transactions/marginRegistry.mjs.map +1 -1
  125. package/dist/transactions/marginTPSL.d.mts +27 -9
  126. package/dist/transactions/marginTPSL.d.mts.map +1 -1
  127. package/dist/transactions/marginTPSL.mjs +108 -82
  128. package/dist/transactions/marginTPSL.mjs.map +1 -1
  129. package/dist/transactions/poolProxy.d.mts +32 -0
  130. package/dist/transactions/poolProxy.d.mts.map +1 -1
  131. package/dist/transactions/poolProxy.mjs +269 -189
  132. package/dist/transactions/poolProxy.mjs.map +1 -1
  133. package/dist/utils/constants.mjs +4 -4
  134. package/dist/utils/constants.mjs.map +1 -1
  135. package/package.json +2 -2
  136. package/src/client.ts +8 -0
  137. package/src/contracts/deepbook/balance_manager.ts +46 -5
  138. package/src/contracts/deepbook/constants.ts +13 -0
  139. package/src/contracts/deepbook/pool.ts +133 -0
  140. package/src/contracts/deepbook/registry.ts +136 -1
  141. package/src/contracts/deepbook_margin/deps/deepbook/balance_manager.ts +49 -0
  142. package/src/contracts/deepbook_margin/deps/std/type_name.ts +24 -0
  143. package/src/contracts/deepbook_margin/deps/sui/bag.ts +41 -0
  144. package/src/contracts/deepbook_margin/deps/sui/balance.ts +19 -0
  145. package/src/contracts/deepbook_margin/deps/sui/table.ts +36 -0
  146. package/src/contracts/deepbook_margin/deps/sui/vec_map.ts +33 -0
  147. package/src/contracts/deepbook_margin/deps/sui/vec_set.ts +22 -0
  148. package/src/contracts/deepbook_margin/deps/sui/versioned.ts +13 -0
  149. package/src/contracts/deepbook_margin/margin_constants.ts +329 -0
  150. package/src/contracts/deepbook_margin/margin_manager.ts +1772 -0
  151. package/src/contracts/deepbook_margin/margin_pool.ts +1129 -0
  152. package/src/contracts/deepbook_margin/margin_registry.ts +1207 -0
  153. package/src/contracts/deepbook_margin/margin_state.ts +26 -0
  154. package/src/contracts/deepbook_margin/oracle.ts +99 -0
  155. package/src/contracts/deepbook_margin/pool_proxy.ts +1298 -0
  156. package/src/contracts/deepbook_margin/position_manager.ts +28 -0
  157. package/src/contracts/deepbook_margin/protocol_config.ts +163 -0
  158. package/src/contracts/deepbook_margin/protocol_fees.ts +153 -0
  159. package/src/contracts/deepbook_margin/rate_limiter.ts +80 -0
  160. package/src/contracts/deepbook_margin/tpsl.ts +559 -0
  161. package/src/contracts/margin_liquidation/deps/sui/bag.ts +41 -0
  162. package/src/contracts/margin_liquidation/liquidation_vault.ts +401 -0
  163. package/src/queries/registryQueries.ts +15 -0
  164. package/src/transactions/balanceManager.ts +140 -90
  165. package/src/transactions/deepbook.ts +586 -494
  166. package/src/transactions/deepbookAdmin.ts +154 -146
  167. package/src/transactions/flashLoans.ts +29 -20
  168. package/src/transactions/governance.ts +50 -37
  169. package/src/transactions/marginAdmin.ts +247 -188
  170. package/src/transactions/marginLiquidations.ts +70 -55
  171. package/src/transactions/marginMaintainer.ts +106 -88
  172. package/src/transactions/marginManager.ts +414 -348
  173. package/src/transactions/marginPool.ts +140 -103
  174. package/src/transactions/marginRegistry.ts +103 -70
  175. package/src/transactions/marginTPSL.ts +151 -87
  176. package/src/transactions/poolProxy.ts +384 -205
  177. package/src/utils/constants.ts +4 -4
@@ -0,0 +1,644 @@
1
+ import { normalizeMoveArguments } from "../utils/index.mjs";
2
+
3
+ //#region src/contracts/deepbook_margin/pool_proxy.ts
4
+ /**
5
+ * Updates the current price for a pool using safe oracle price calculation. Anyone
6
+ * can call this to update the price oracle used for order validation.
7
+ */
8
+ function updateCurrentPrice(options) {
9
+ const packageAddress = options.package ?? "@deepbook/margin";
10
+ const argumentsTypes = [
11
+ null,
12
+ null,
13
+ null,
14
+ null,
15
+ "0x2::clock::Clock"
16
+ ];
17
+ const parameterNames = [
18
+ "registry",
19
+ "pool",
20
+ "basePriceInfoObject",
21
+ "quotePriceInfoObject"
22
+ ];
23
+ return (tx) => tx.moveCall({
24
+ package: packageAddress,
25
+ module: "pool_proxy",
26
+ function: "update_current_price",
27
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
28
+ typeArguments: options.typeArguments
29
+ });
30
+ }
31
+ /** Places a limit order in the pool. */
32
+ function placeLimitOrderV2(options) {
33
+ const packageAddress = options.package ?? "@deepbook/margin";
34
+ const argumentsTypes = [
35
+ null,
36
+ null,
37
+ null,
38
+ null,
39
+ null,
40
+ null,
41
+ null,
42
+ "u64",
43
+ "u8",
44
+ "u8",
45
+ "u64",
46
+ "u64",
47
+ "bool",
48
+ "bool",
49
+ "u64",
50
+ "0x2::clock::Clock"
51
+ ];
52
+ const parameterNames = [
53
+ "registry",
54
+ "marginManager",
55
+ "pool",
56
+ "baseMarginPool",
57
+ "quoteMarginPool",
58
+ "baseOracle",
59
+ "quoteOracle",
60
+ "clientOrderId",
61
+ "orderType",
62
+ "selfMatchingOption",
63
+ "price",
64
+ "quantity",
65
+ "isBid",
66
+ "payWithDeep",
67
+ "expireTimestamp"
68
+ ];
69
+ return (tx) => tx.moveCall({
70
+ package: packageAddress,
71
+ module: "pool_proxy",
72
+ function: "place_limit_order_v2",
73
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
74
+ typeArguments: options.typeArguments
75
+ });
76
+ }
77
+ /** Places a market order in the pool. */
78
+ function placeMarketOrderV2(options) {
79
+ const packageAddress = options.package ?? "@deepbook/margin";
80
+ const argumentsTypes = [
81
+ null,
82
+ null,
83
+ null,
84
+ null,
85
+ null,
86
+ null,
87
+ null,
88
+ "u64",
89
+ "u8",
90
+ "u64",
91
+ "bool",
92
+ "bool",
93
+ "0x2::clock::Clock"
94
+ ];
95
+ const parameterNames = [
96
+ "registry",
97
+ "marginManager",
98
+ "pool",
99
+ "baseMarginPool",
100
+ "quoteMarginPool",
101
+ "baseOracle",
102
+ "quoteOracle",
103
+ "clientOrderId",
104
+ "selfMatchingOption",
105
+ "quantity",
106
+ "isBid",
107
+ "payWithDeep"
108
+ ];
109
+ return (tx) => tx.moveCall({
110
+ package: packageAddress,
111
+ module: "pool_proxy",
112
+ function: "place_market_order_v2",
113
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
114
+ typeArguments: options.typeArguments
115
+ });
116
+ }
117
+ /** Places a reduce-only order in the pool. Used when margin trading is disabled. */
118
+ function placeReduceOnlyLimitOrderV2(options) {
119
+ const packageAddress = options.package ?? "@deepbook/margin";
120
+ const argumentsTypes = [
121
+ null,
122
+ null,
123
+ null,
124
+ null,
125
+ null,
126
+ null,
127
+ null,
128
+ "u64",
129
+ "u8",
130
+ "u8",
131
+ "u64",
132
+ "u64",
133
+ "bool",
134
+ "bool",
135
+ "u64",
136
+ "0x2::clock::Clock"
137
+ ];
138
+ const parameterNames = [
139
+ "registry",
140
+ "marginManager",
141
+ "pool",
142
+ "baseMarginPool",
143
+ "quoteMarginPool",
144
+ "baseOracle",
145
+ "quoteOracle",
146
+ "clientOrderId",
147
+ "orderType",
148
+ "selfMatchingOption",
149
+ "price",
150
+ "quantity",
151
+ "isBid",
152
+ "payWithDeep",
153
+ "expireTimestamp"
154
+ ];
155
+ return (tx) => tx.moveCall({
156
+ package: packageAddress,
157
+ module: "pool_proxy",
158
+ function: "place_reduce_only_limit_order_v2",
159
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
160
+ typeArguments: options.typeArguments
161
+ });
162
+ }
163
+ /**
164
+ * Places a reduce-only market order in the pool. Used when margin trading is
165
+ * disabled.
166
+ *
167
+ * Superseded by `place_reduce_only_market_order_and_repay_loan`. A market (taker)
168
+ * fill always pays the spread, which lowers the oracle-valued `risk_ratio` while
169
+ * the debt is unchanged, so the swap-only monotonic check here rejects essentially
170
+ * every taker fill. The `_and_repay` variant deleverages with the proceeds so the
171
+ * net-state ratio actually improves. Kept callable for existing integrators; its
172
+ * reduce-only _direction_ guard matches the other entries — a bid needs base
173
+ * (short-side) debt, the ask needs quote (long-side) debt and sells up to gross
174
+ * base held — with no size cap.
175
+ */
176
+ function placeReduceOnlyMarketOrderV2(options) {
177
+ const packageAddress = options.package ?? "@deepbook/margin";
178
+ const argumentsTypes = [
179
+ null,
180
+ null,
181
+ null,
182
+ null,
183
+ null,
184
+ null,
185
+ null,
186
+ "u64",
187
+ "u8",
188
+ "u64",
189
+ "bool",
190
+ "bool",
191
+ "0x2::clock::Clock"
192
+ ];
193
+ const parameterNames = [
194
+ "registry",
195
+ "marginManager",
196
+ "pool",
197
+ "baseMarginPool",
198
+ "quoteMarginPool",
199
+ "baseOracle",
200
+ "quoteOracle",
201
+ "clientOrderId",
202
+ "selfMatchingOption",
203
+ "quantity",
204
+ "isBid",
205
+ "payWithDeep"
206
+ ];
207
+ return (tx) => tx.moveCall({
208
+ package: packageAddress,
209
+ module: "pool_proxy",
210
+ function: "place_reduce_only_market_order_v2",
211
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
212
+ typeArguments: options.typeArguments
213
+ });
214
+ }
215
+ /**
216
+ * Atomically winds down a leveraged position: places a reduce-only market order,
217
+ * repays the loan with the proceeds, then requires the net (post-repay) risk ratio
218
+ * to be at least the pre-trade ratio.
219
+ *
220
+ * The post-repay check is the point. A market close pays the spread, which alone
221
+ * lowers the oracle-valued ratio (debt is unchanged until repay) and would abort
222
+ * the plain reduce-only path. Repaying first deleverages and absorbs the slippage
223
+ * (still bounded by the `assert_price` band), and lets a manager in the
224
+ * `liquidation..min_borrow` band climb out — it cannot reach the borrow floor in a
225
+ * single swap.
226
+ */
227
+ function placeReduceOnlyMarketOrderAndRepayLoan(options) {
228
+ const packageAddress = options.package ?? "@deepbook/margin";
229
+ const argumentsTypes = [
230
+ null,
231
+ null,
232
+ null,
233
+ null,
234
+ null,
235
+ null,
236
+ null,
237
+ "u64",
238
+ "u8",
239
+ "u64",
240
+ "bool",
241
+ "bool",
242
+ "0x2::clock::Clock"
243
+ ];
244
+ const parameterNames = [
245
+ "registry",
246
+ "marginManager",
247
+ "pool",
248
+ "baseMarginPool",
249
+ "quoteMarginPool",
250
+ "baseOracle",
251
+ "quoteOracle",
252
+ "clientOrderId",
253
+ "selfMatchingOption",
254
+ "quantity",
255
+ "isBid",
256
+ "payWithDeep"
257
+ ];
258
+ return (tx) => tx.moveCall({
259
+ package: packageAddress,
260
+ module: "pool_proxy",
261
+ function: "place_reduce_only_market_order_and_repay_loan",
262
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
263
+ typeArguments: options.typeArguments
264
+ });
265
+ }
266
+ /**
267
+ * Reduce-only **limit** order that atomically repays the loan with the taker
268
+ * fills. It is the limit/maker behaviour of `place_reduce_only_limit_order_v2`
269
+ * plus the repay-then-net-monotonic gate of
270
+ * `place_reduce_only_market_order_and_repay_loan`: the portion that crosses the
271
+ * book fills immediately and settles, the rest rests as a maker, then the settled
272
+ * (taker) proceeds repay the debt before the monotonic check on the net
273
+ * (post-repay) state.
274
+ *
275
+ * This is the danger-band tool for a _price-bounded_ reduce: a crossing
276
+ * reduce-only limit pays the spread on its taker fills, which alone would abort
277
+ * `place_reduce_only_limit_order_v2`'s swap-only monotonic check; repaying first
278
+ * deleverages so the net ratio holds. The resting remainder only locks balance
279
+ * (counted in assets), so it doesn't move the ratio. Unfilled-and-resting behaves
280
+ * exactly like `place_reduce_only_limit_order_v2` (nothing to repay).
281
+ */
282
+ function placeReduceOnlyLimitOrderAndRepayLoan(options) {
283
+ const packageAddress = options.package ?? "@deepbook/margin";
284
+ const argumentsTypes = [
285
+ null,
286
+ null,
287
+ null,
288
+ null,
289
+ null,
290
+ null,
291
+ null,
292
+ "u64",
293
+ "u8",
294
+ "u8",
295
+ "u64",
296
+ "u64",
297
+ "bool",
298
+ "bool",
299
+ "u64",
300
+ "0x2::clock::Clock"
301
+ ];
302
+ const parameterNames = [
303
+ "registry",
304
+ "marginManager",
305
+ "pool",
306
+ "baseMarginPool",
307
+ "quoteMarginPool",
308
+ "baseOracle",
309
+ "quoteOracle",
310
+ "clientOrderId",
311
+ "orderType",
312
+ "selfMatchingOption",
313
+ "price",
314
+ "quantity",
315
+ "isBid",
316
+ "payWithDeep",
317
+ "expireTimestamp"
318
+ ];
319
+ return (tx) => tx.moveCall({
320
+ package: packageAddress,
321
+ module: "pool_proxy",
322
+ function: "place_reduce_only_limit_order_and_repay_loan",
323
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
324
+ typeArguments: options.typeArguments
325
+ });
326
+ }
327
+ /**
328
+ * Atomically places a market order and repays the loan with the proceeds, gating
329
+ * on a **monotonic** net-state check: if any debt remains after the repay, the
330
+ * post-repay `risk_ratio` must be at least the pre-trade ratio (improve-or-hold).
331
+ * A full close drives debt to 0 (`risk_ratio` MAX), which always passes.
332
+ *
333
+ * This is the everyday close / deleverage tool. The monotonic gate — rather than
334
+ * the `min_open` opening floor used by `place_market_order_v2` — lets a position
335
+ * in the `liquidation..min_borrow` danger band wind down _partially_: a small
336
+ * close that lifts the ratio from, say, 1.12 to 1.15 is allowed even though 1.15
337
+ * is still below `min_open`, which the opening floor would reject.
338
+ *
339
+ * Not reduce-only and uncapped, but the monotonic check makes a quantity cap
340
+ * unnecessary: a market (taker) fill settles immediately, so any genuinely
341
+ * exposure-_increasing_ trade lowers the ratio and aborts here, while any
342
+ * deleveraging trade is allowed at any size — an overshoot past the debt is fine
343
+ * (surplus is the manager's own holding) and `assert_price` still bounds slippage.
344
+ * Requires margin trading enabled; in reduce-only mode use
345
+ * `place_reduce_only_market_order_and_repay_loan`.
346
+ */
347
+ function placeMarketOrderAndRepayLoan(options) {
348
+ const packageAddress = options.package ?? "@deepbook/margin";
349
+ const argumentsTypes = [
350
+ null,
351
+ null,
352
+ null,
353
+ null,
354
+ null,
355
+ null,
356
+ null,
357
+ "u64",
358
+ "u8",
359
+ "u64",
360
+ "bool",
361
+ "bool",
362
+ "0x2::clock::Clock"
363
+ ];
364
+ const parameterNames = [
365
+ "registry",
366
+ "marginManager",
367
+ "pool",
368
+ "baseMarginPool",
369
+ "quoteMarginPool",
370
+ "baseOracle",
371
+ "quoteOracle",
372
+ "clientOrderId",
373
+ "selfMatchingOption",
374
+ "quantity",
375
+ "isBid",
376
+ "payWithDeep"
377
+ ];
378
+ return (tx) => tx.moveCall({
379
+ package: packageAddress,
380
+ module: "pool_proxy",
381
+ function: "place_market_order_and_repay_loan",
382
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
383
+ typeArguments: options.typeArguments
384
+ });
385
+ }
386
+ /** Modifies an order */
387
+ function modifyOrder(options) {
388
+ const packageAddress = options.package ?? "@deepbook/margin";
389
+ const argumentsTypes = [
390
+ null,
391
+ null,
392
+ null,
393
+ "u128",
394
+ "u64",
395
+ "0x2::clock::Clock"
396
+ ];
397
+ const parameterNames = [
398
+ "registry",
399
+ "marginManager",
400
+ "pool",
401
+ "orderId",
402
+ "newQuantity"
403
+ ];
404
+ return (tx) => tx.moveCall({
405
+ package: packageAddress,
406
+ module: "pool_proxy",
407
+ function: "modify_order",
408
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
409
+ typeArguments: options.typeArguments
410
+ });
411
+ }
412
+ /** Cancels an order */
413
+ function cancelOrder(options) {
414
+ const packageAddress = options.package ?? "@deepbook/margin";
415
+ const argumentsTypes = [
416
+ null,
417
+ null,
418
+ null,
419
+ "u128",
420
+ "0x2::clock::Clock"
421
+ ];
422
+ const parameterNames = [
423
+ "registry",
424
+ "marginManager",
425
+ "pool",
426
+ "orderId"
427
+ ];
428
+ return (tx) => tx.moveCall({
429
+ package: packageAddress,
430
+ module: "pool_proxy",
431
+ function: "cancel_order",
432
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
433
+ typeArguments: options.typeArguments
434
+ });
435
+ }
436
+ /** Cancel multiple orders within a vector. */
437
+ function cancelOrders(options) {
438
+ const packageAddress = options.package ?? "@deepbook/margin";
439
+ const argumentsTypes = [
440
+ null,
441
+ null,
442
+ null,
443
+ "vector<u128>",
444
+ "0x2::clock::Clock"
445
+ ];
446
+ const parameterNames = [
447
+ "registry",
448
+ "marginManager",
449
+ "pool",
450
+ "orderIds"
451
+ ];
452
+ return (tx) => tx.moveCall({
453
+ package: packageAddress,
454
+ module: "pool_proxy",
455
+ function: "cancel_orders",
456
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
457
+ typeArguments: options.typeArguments
458
+ });
459
+ }
460
+ /** Cancels all orders for the given account. */
461
+ function cancelAllOrders(options) {
462
+ const packageAddress = options.package ?? "@deepbook/margin";
463
+ const argumentsTypes = [
464
+ null,
465
+ null,
466
+ null,
467
+ "0x2::clock::Clock"
468
+ ];
469
+ const parameterNames = [
470
+ "registry",
471
+ "marginManager",
472
+ "pool"
473
+ ];
474
+ return (tx) => tx.moveCall({
475
+ package: packageAddress,
476
+ module: "pool_proxy",
477
+ function: "cancel_all_orders",
478
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
479
+ typeArguments: options.typeArguments
480
+ });
481
+ }
482
+ /** Withdraw settled amounts to balance_manager. */
483
+ function withdrawSettledAmounts(options) {
484
+ const packageAddress = options.package ?? "@deepbook/margin";
485
+ const argumentsTypes = [
486
+ null,
487
+ null,
488
+ null
489
+ ];
490
+ const parameterNames = [
491
+ "registry",
492
+ "marginManager",
493
+ "pool"
494
+ ];
495
+ return (tx) => tx.moveCall({
496
+ package: packageAddress,
497
+ module: "pool_proxy",
498
+ function: "withdraw_settled_amounts",
499
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
500
+ typeArguments: options.typeArguments
501
+ });
502
+ }
503
+ /**
504
+ * Withdraw settled amounts to balance_manager permissionlessly. Anyone can call
505
+ * this function to settle balances for a margin manager.
506
+ */
507
+ function withdrawSettledAmountsPermissionless(options) {
508
+ const packageAddress = options.package ?? "@deepbook/margin";
509
+ const argumentsTypes = [
510
+ null,
511
+ null,
512
+ null
513
+ ];
514
+ const parameterNames = [
515
+ "registry",
516
+ "marginManager",
517
+ "pool"
518
+ ];
519
+ return (tx) => tx.moveCall({
520
+ package: packageAddress,
521
+ module: "pool_proxy",
522
+ function: "withdraw_settled_amounts_permissionless",
523
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
524
+ typeArguments: options.typeArguments
525
+ });
526
+ }
527
+ /** Stake DEEP tokens to the pool. */
528
+ function stake(options) {
529
+ const packageAddress = options.package ?? "@deepbook/margin";
530
+ const argumentsTypes = [
531
+ null,
532
+ null,
533
+ null,
534
+ "u64"
535
+ ];
536
+ const parameterNames = [
537
+ "registry",
538
+ "marginManager",
539
+ "pool",
540
+ "amount"
541
+ ];
542
+ return (tx) => tx.moveCall({
543
+ package: packageAddress,
544
+ module: "pool_proxy",
545
+ function: "stake",
546
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
547
+ typeArguments: options.typeArguments
548
+ });
549
+ }
550
+ /** Unstake DEEP tokens from the pool. */
551
+ function unstake(options) {
552
+ const packageAddress = options.package ?? "@deepbook/margin";
553
+ const argumentsTypes = [
554
+ null,
555
+ null,
556
+ null
557
+ ];
558
+ const parameterNames = [
559
+ "registry",
560
+ "marginManager",
561
+ "pool"
562
+ ];
563
+ return (tx) => tx.moveCall({
564
+ package: packageAddress,
565
+ module: "pool_proxy",
566
+ function: "unstake",
567
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
568
+ typeArguments: options.typeArguments
569
+ });
570
+ }
571
+ /** Submit proposal using the margin manager. */
572
+ function submitProposal(options) {
573
+ const packageAddress = options.package ?? "@deepbook/margin";
574
+ const argumentsTypes = [
575
+ null,
576
+ null,
577
+ null,
578
+ "u64",
579
+ "u64",
580
+ "u64"
581
+ ];
582
+ const parameterNames = [
583
+ "registry",
584
+ "marginManager",
585
+ "pool",
586
+ "takerFee",
587
+ "makerFee",
588
+ "stakeRequired"
589
+ ];
590
+ return (tx) => tx.moveCall({
591
+ package: packageAddress,
592
+ module: "pool_proxy",
593
+ function: "submit_proposal",
594
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
595
+ typeArguments: options.typeArguments
596
+ });
597
+ }
598
+ /** Vote on a proposal using the margin manager. */
599
+ function vote(options) {
600
+ const packageAddress = options.package ?? "@deepbook/margin";
601
+ const argumentsTypes = [
602
+ null,
603
+ null,
604
+ null,
605
+ "0x2::object::ID"
606
+ ];
607
+ const parameterNames = [
608
+ "registry",
609
+ "marginManager",
610
+ "pool",
611
+ "proposalId"
612
+ ];
613
+ return (tx) => tx.moveCall({
614
+ package: packageAddress,
615
+ module: "pool_proxy",
616
+ function: "vote",
617
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
618
+ typeArguments: options.typeArguments
619
+ });
620
+ }
621
+ function claimRebates(options) {
622
+ const packageAddress = options.package ?? "@deepbook/margin";
623
+ const argumentsTypes = [
624
+ null,
625
+ null,
626
+ null
627
+ ];
628
+ const parameterNames = [
629
+ "registry",
630
+ "marginManager",
631
+ "pool"
632
+ ];
633
+ return (tx) => tx.moveCall({
634
+ package: packageAddress,
635
+ module: "pool_proxy",
636
+ function: "claim_rebates",
637
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
638
+ typeArguments: options.typeArguments
639
+ });
640
+ }
641
+
642
+ //#endregion
643
+ export { cancelAllOrders, cancelOrder, cancelOrders, claimRebates, modifyOrder, placeLimitOrderV2, placeMarketOrderAndRepayLoan, placeMarketOrderV2, placeReduceOnlyLimitOrderAndRepayLoan, placeReduceOnlyLimitOrderV2, placeReduceOnlyMarketOrderAndRepayLoan, placeReduceOnlyMarketOrderV2, stake, submitProposal, unstake, updateCurrentPrice, vote, withdrawSettledAmounts, withdrawSettledAmountsPermissionless };
644
+ //# sourceMappingURL=pool_proxy.mjs.map