@mysten/deepbook-v3 2.6.4 → 2.8.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 (250) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/PREDICT.md +389 -61
  3. package/dist/contracts/account/account.d.mts +23 -23
  4. package/dist/contracts/account/account.d.mts.map +1 -1
  5. package/dist/contracts/account/account_registry.d.mts +13 -13
  6. package/dist/contracts/deepbook/account.d.mts +18 -18
  7. package/dist/contracts/deepbook/balances.d.mts +4 -4
  8. package/dist/contracts/deepbook/deep_price.d.mts +3 -3
  9. package/dist/contracts/deepbook/order.d.mts +12 -12
  10. package/dist/contracts/deepbook_predict/admin.d.mts +4 -4
  11. package/dist/contracts/deepbook_predict/builder_code.d.mts +11 -11
  12. package/dist/contracts/deepbook_predict/builder_code_events.d.mts +10 -10
  13. package/dist/contracts/deepbook_predict/config_events.d.mts +93 -68
  14. package/dist/contracts/deepbook_predict/config_events.d.mts.map +1 -1
  15. package/dist/contracts/deepbook_predict/config_events.mjs +45 -1
  16. package/dist/contracts/deepbook_predict/config_events.mjs.map +1 -1
  17. package/dist/contracts/deepbook_predict/deps/std/type_name.mjs +17 -0
  18. package/dist/contracts/deepbook_predict/deps/std/type_name.mjs.map +1 -0
  19. package/dist/contracts/deepbook_predict/expiry_market.d.mts +652 -235
  20. package/dist/contracts/deepbook_predict/expiry_market.d.mts.map +1 -1
  21. package/dist/contracts/deepbook_predict/expiry_market.mjs +652 -186
  22. package/dist/contracts/deepbook_predict/expiry_market.mjs.map +1 -1
  23. package/dist/contracts/deepbook_predict/lp_book.mjs +1 -1
  24. package/dist/contracts/deepbook_predict/market_lifecycle_cap.d.mts +5 -5
  25. package/dist/contracts/deepbook_predict/market_manager.d.mts +27 -27
  26. package/dist/contracts/deepbook_predict/order_events.d.mts +50 -50
  27. package/dist/contracts/deepbook_predict/order_events.d.mts.map +1 -1
  28. package/dist/contracts/deepbook_predict/order_events.mjs +3 -1
  29. package/dist/contracts/deepbook_predict/order_events.mjs.map +1 -1
  30. package/dist/contracts/deepbook_predict/pause_cap.d.mts +5 -5
  31. package/dist/contracts/deepbook_predict/plp.d.mts +184 -82
  32. package/dist/contracts/deepbook_predict/plp.d.mts.map +1 -1
  33. package/dist/contracts/deepbook_predict/plp.mjs +126 -7
  34. package/dist/contracts/deepbook_predict/plp.mjs.map +1 -1
  35. package/dist/contracts/deepbook_predict/pool_accounting.mjs +1 -1
  36. package/dist/contracts/deepbook_predict/pool_valuation_cap.d.mts +5 -5
  37. package/dist/contracts/deepbook_predict/predict_account.d.mts +14 -14
  38. package/dist/contracts/deepbook_predict/pricing.d.mts +91 -58
  39. package/dist/contracts/deepbook_predict/pricing.d.mts.map +1 -1
  40. package/dist/contracts/deepbook_predict/pricing.mjs +30 -3
  41. package/dist/contracts/deepbook_predict/pricing.mjs.map +1 -1
  42. package/dist/contracts/deepbook_predict/pricing_config.mjs.map +1 -1
  43. package/dist/contracts/deepbook_predict/protocol_config.d.mts +400 -92
  44. package/dist/contracts/deepbook_predict/protocol_config.d.mts.map +1 -1
  45. package/dist/contracts/deepbook_predict/protocol_config.mjs +451 -61
  46. package/dist/contracts/deepbook_predict/protocol_config.mjs.map +1 -1
  47. package/dist/contracts/deepbook_predict/range_codec.d.mts +2 -2
  48. package/dist/contracts/deepbook_predict/registry.d.mts +28 -28
  49. package/dist/contracts/deepbook_predict/strike_exposure.mjs +1 -1
  50. package/dist/contracts/deepbook_predict/strike_payout_tree.mjs +17 -12
  51. package/dist/contracts/deepbook_predict/strike_payout_tree.mjs.map +1 -1
  52. package/dist/contracts/deepbook_predict/vault_events.d.mts +154 -106
  53. package/dist/contracts/deepbook_predict/vault_events.d.mts.map +1 -1
  54. package/dist/contracts/deepbook_predict/vault_events.mjs +57 -1
  55. package/dist/contracts/deepbook_predict/vault_events.mjs.map +1 -1
  56. package/dist/contracts/deepbook_predict_math/config-arguments.d.mts +10 -0
  57. package/dist/contracts/deepbook_predict_math/config-arguments.d.mts.map +1 -0
  58. package/dist/contracts/deepbook_predict_math/lazer_price.d.mts +106 -0
  59. package/dist/contracts/deepbook_predict_math/lazer_price.d.mts.map +1 -0
  60. package/dist/contracts/deepbook_predict_math/lazer_price.mjs +125 -0
  61. package/dist/contracts/deepbook_predict_math/lazer_price.mjs.map +1 -0
  62. package/dist/contracts/deepbook_predict_math/math.d.mts +284 -0
  63. package/dist/contracts/deepbook_predict_math/math.d.mts.map +1 -0
  64. package/dist/contracts/deepbook_predict_math/math.mjs +364 -0
  65. package/dist/contracts/deepbook_predict_math/math.mjs.map +1 -0
  66. package/dist/contracts/deepbook_predict_orders/config-arguments.d.mts +13 -0
  67. package/dist/contracts/deepbook_predict_orders/config-arguments.d.mts.map +1 -0
  68. package/dist/contracts/deepbook_predict_orders/delayed_execution_config.d.mts +215 -0
  69. package/dist/contracts/deepbook_predict_orders/delayed_execution_config.d.mts.map +1 -0
  70. package/dist/contracts/deepbook_predict_orders/delayed_execution_config.mjs +215 -0
  71. package/dist/contracts/deepbook_predict_orders/delayed_execution_config.mjs.map +1 -0
  72. package/dist/contracts/deepbook_predict_orders/deps/deepbook_predict/expiry_market.mjs +87 -0
  73. package/dist/contracts/deepbook_predict_orders/deps/deepbook_predict/expiry_market.mjs.map +1 -0
  74. package/dist/contracts/deepbook_predict_orders/deps/deepbook_predict/pricing.mjs +52 -0
  75. package/dist/contracts/deepbook_predict_orders/deps/deepbook_predict/pricing.mjs.map +1 -0
  76. package/dist/contracts/deepbook_predict_orders/deps/fixed_math/i64.mjs +25 -0
  77. package/dist/contracts/deepbook_predict_orders/deps/fixed_math/i64.mjs.map +1 -0
  78. package/dist/contracts/deepbook_predict_orders/deps/sui/balance.mjs +21 -0
  79. package/dist/contracts/deepbook_predict_orders/deps/sui/balance.mjs.map +1 -0
  80. package/dist/contracts/deepbook_predict_orders/deps/sui/table.mjs +39 -0
  81. package/dist/contracts/deepbook_predict_orders/deps/sui/table.mjs.map +1 -0
  82. package/dist/contracts/deepbook_predict_orders/desk.d.mts +187 -0
  83. package/dist/contracts/deepbook_predict_orders/desk.d.mts.map +1 -0
  84. package/dist/contracts/deepbook_predict_orders/desk.mjs +261 -0
  85. package/dist/contracts/deepbook_predict_orders/desk.mjs.map +1 -0
  86. package/dist/contracts/deepbook_predict_orders/order_queue.d.mts +1042 -0
  87. package/dist/contracts/deepbook_predict_orders/order_queue.d.mts.map +1 -0
  88. package/dist/contracts/deepbook_predict_orders/order_queue.mjs +849 -0
  89. package/dist/contracts/deepbook_predict_orders/order_queue.mjs.map +1 -0
  90. package/dist/contracts/deepbook_predict_orders/queue.d.mts +683 -0
  91. package/dist/contracts/deepbook_predict_orders/queue.d.mts.map +1 -0
  92. package/dist/contracts/deepbook_predict_orders/queue.mjs +912 -0
  93. package/dist/contracts/deepbook_predict_orders/queue.mjs.map +1 -0
  94. package/dist/contracts/deepbook_predict_orders/queue_events.d.mts +195 -0
  95. package/dist/contracts/deepbook_predict_orders/queue_events.d.mts.map +1 -0
  96. package/dist/contracts/deepbook_predict_orders/queue_events.mjs +187 -0
  97. package/dist/contracts/deepbook_predict_orders/queue_events.mjs.map +1 -0
  98. package/dist/contracts/deepbook_sessions/session_config.d.mts +8 -8
  99. package/dist/contracts/deepbook_sessions/sessions.d.mts +163 -28
  100. package/dist/contracts/deepbook_sessions/sessions.d.mts.map +1 -1
  101. package/dist/contracts/deepbook_sessions/sessions.mjs +234 -5
  102. package/dist/contracts/deepbook_sessions/sessions.mjs.map +1 -1
  103. package/dist/deployments/mainnet.mjs +7 -4
  104. package/dist/deployments/mainnet.mjs.map +1 -1
  105. package/dist/deployments/testnet.mjs +7 -4
  106. package/dist/deployments/testnet.mjs.map +1 -1
  107. package/dist/predict/bindings/expiry-market.d.mts +77 -0
  108. package/dist/predict/bindings/expiry-market.d.mts.map +1 -0
  109. package/dist/predict/bindings/expiry-market.mjs +139 -0
  110. package/dist/predict/bindings/expiry-market.mjs.map +1 -0
  111. package/dist/predict/bindings/protocol-config.d.mts +39 -0
  112. package/dist/predict/bindings/protocol-config.d.mts.map +1 -0
  113. package/dist/predict/bindings/protocol-config.mjs +90 -0
  114. package/dist/predict/bindings/protocol-config.mjs.map +1 -0
  115. package/dist/predict/bindings/rename.mjs +9 -0
  116. package/dist/predict/bindings/rename.mjs.map +1 -0
  117. package/dist/predict/client.d.mts +595 -16
  118. package/dist/predict/client.d.mts.map +1 -1
  119. package/dist/predict/client.mjs +986 -10
  120. package/dist/predict/client.mjs.map +1 -1
  121. package/dist/predict/config/generated.d.mts +22 -1
  122. package/dist/predict/config/generated.d.mts.map +1 -1
  123. package/dist/predict/config/generated.mjs +30 -1
  124. package/dist/predict/config/generated.mjs.map +1 -1
  125. package/dist/predict/config/mainnet.mjs +11 -3
  126. package/dist/predict/config/mainnet.mjs.map +1 -1
  127. package/dist/predict/config/testnet.mjs +11 -3
  128. package/dist/predict/config/testnet.mjs.map +1 -1
  129. package/dist/predict/config/types.d.mts +50 -1
  130. package/dist/predict/config/types.d.mts.map +1 -1
  131. package/dist/predict/cost.d.mts +38 -11
  132. package/dist/predict/cost.d.mts.map +1 -1
  133. package/dist/predict/cost.mjs +37 -11
  134. package/dist/predict/cost.mjs.map +1 -1
  135. package/dist/predict/decode.d.mts +251 -1
  136. package/dist/predict/decode.d.mts.map +1 -1
  137. package/dist/predict/decode.mjs +342 -4
  138. package/dist/predict/decode.mjs.map +1 -1
  139. package/dist/predict/errors.d.mts +69 -6
  140. package/dist/predict/errors.d.mts.map +1 -1
  141. package/dist/predict/errors.mjs +277 -4
  142. package/dist/predict/errors.mjs.map +1 -1
  143. package/dist/predict/index.d.mts +21 -10
  144. package/dist/predict/index.mjs +24 -12
  145. package/dist/predict/queue-id.d.mts +13 -0
  146. package/dist/predict/queue-id.d.mts.map +1 -0
  147. package/dist/predict/queue-id.mjs +19 -0
  148. package/dist/predict/queue-id.mjs.map +1 -0
  149. package/dist/predict/queue.d.mts +505 -0
  150. package/dist/predict/queue.d.mts.map +1 -0
  151. package/dist/predict/queue.mjs +774 -0
  152. package/dist/predict/queue.mjs.map +1 -0
  153. package/dist/predict/reads/balances.mjs +1 -1
  154. package/dist/predict/reads/markets.mjs +46 -5
  155. package/dist/predict/reads/markets.mjs.map +1 -1
  156. package/dist/predict/reads/pool.mjs +1 -1
  157. package/dist/predict/reads/pricing.d.mts +1 -1
  158. package/dist/predict/reads/queue.d.mts +105 -0
  159. package/dist/predict/reads/queue.d.mts.map +1 -0
  160. package/dist/predict/reads/queue.mjs +445 -0
  161. package/dist/predict/reads/queue.mjs.map +1 -0
  162. package/dist/predict/ticks.d.mts +9 -1
  163. package/dist/predict/ticks.d.mts.map +1 -1
  164. package/dist/predict/ticks.mjs +18 -1
  165. package/dist/predict/ticks.mjs.map +1 -1
  166. package/dist/predict/tx/authed.mjs +1 -1
  167. package/dist/predict/tx/common.d.mts.map +1 -1
  168. package/dist/predict/tx/common.mjs +12 -1
  169. package/dist/predict/tx/common.mjs.map +1 -1
  170. package/dist/predict/tx/queue.d.mts +220 -0
  171. package/dist/predict/tx/queue.d.mts.map +1 -0
  172. package/dist/predict/tx/queue.mjs +399 -0
  173. package/dist/predict/tx/queue.mjs.map +1 -0
  174. package/dist/predict/tx/trade.d.mts.map +1 -1
  175. package/dist/predict/tx/trade.mjs +61 -43
  176. package/dist/predict/tx/trade.mjs.map +1 -1
  177. package/dist/sessions.d.mts +90 -2
  178. package/dist/sessions.d.mts.map +1 -1
  179. package/dist/sessions.mjs +107 -2
  180. package/dist/sessions.mjs.map +1 -1
  181. package/dist/transactions/balanceManager.d.mts +12 -12
  182. package/dist/transactions/balanceManager.d.mts.map +1 -1
  183. package/dist/transactions/deepbook.d.mts +20 -20
  184. package/dist/transactions/deepbook.d.mts.map +1 -1
  185. package/dist/transactions/deepbookAdmin.d.mts +4 -4
  186. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  187. package/dist/transactions/marginAdmin.d.mts +7 -7
  188. package/dist/transactions/marginAdmin.d.mts.map +1 -1
  189. package/dist/transactions/marginLiquidations.d.mts +3 -3
  190. package/dist/transactions/marginMaintainer.d.mts +5 -5
  191. package/dist/transactions/marginMaintainer.d.mts.map +1 -1
  192. package/dist/transactions/marginManager.d.mts +32 -32
  193. package/dist/transactions/marginManager.d.mts.map +1 -1
  194. package/dist/transactions/marginPool.d.mts +18 -18
  195. package/dist/transactions/marginRegistry.d.mts +16 -16
  196. package/dist/transactions/marginTPSL.d.mts +10 -10
  197. package/dist/transactions/marginTPSL.d.mts.map +1 -1
  198. package/dist/transactions/poolProxy.d.mts +8 -8
  199. package/dist/transactions/poolProxy.d.mts.map +1 -1
  200. package/package.json +4 -4
  201. package/src/contracts/deepbook_predict/config_events.ts +39 -0
  202. package/src/contracts/deepbook_predict/deps/std/type_name.ts +24 -0
  203. package/src/contracts/deepbook_predict/expiry_market.ts +960 -169
  204. package/src/contracts/deepbook_predict/order_events.ts +3 -1
  205. package/src/contracts/deepbook_predict/plp.ts +150 -9
  206. package/src/contracts/deepbook_predict/pricing.ts +46 -7
  207. package/src/contracts/deepbook_predict/pricing_config.ts +3 -1
  208. package/src/contracts/deepbook_predict/protocol_config.ts +648 -33
  209. package/src/contracts/deepbook_predict/strike_payout_tree.ts +25 -21
  210. package/src/contracts/deepbook_predict/vault_events.ts +65 -0
  211. package/src/contracts/deepbook_predict_math/config-arguments.ts +6 -0
  212. package/src/contracts/deepbook_predict_math/lazer_price.ts +196 -0
  213. package/src/contracts/deepbook_predict_math/math.ts +553 -0
  214. package/src/contracts/deepbook_predict_orders/config-arguments.ts +11 -0
  215. package/src/contracts/deepbook_predict_orders/delayed_execution_config.ts +430 -0
  216. package/src/contracts/deepbook_predict_orders/deps/deepbook_predict/expiry_market.ts +108 -0
  217. package/src/contracts/deepbook_predict_orders/deps/deepbook_predict/pricing.ts +58 -0
  218. package/src/contracts/deepbook_predict_orders/deps/fixed_math/i64.ts +21 -0
  219. package/src/contracts/deepbook_predict_orders/deps/sui/balance.ts +19 -0
  220. package/src/contracts/deepbook_predict_orders/deps/sui/table.ts +37 -0
  221. package/src/contracts/deepbook_predict_orders/desk.ts +419 -0
  222. package/src/contracts/deepbook_predict_orders/order_flow.ts +19 -0
  223. package/src/contracts/deepbook_predict_orders/order_queue.ts +1670 -0
  224. package/src/contracts/deepbook_predict_orders/queue.ts +1394 -0
  225. package/src/contracts/deepbook_predict_orders/queue_events.ts +189 -0
  226. package/src/contracts/deepbook_sessions/sessions.ts +355 -4
  227. package/src/deployments/mainnet.ts +7 -2
  228. package/src/deployments/testnet.ts +7 -2
  229. package/src/deployments/types.ts +14 -1
  230. package/src/predict/bindings/expiry-market.ts +127 -0
  231. package/src/predict/bindings/protocol-config.ts +59 -0
  232. package/src/predict/bindings/rename.ts +14 -0
  233. package/src/predict/client.ts +2076 -13
  234. package/src/predict/config/generated.ts +50 -0
  235. package/src/predict/config/mainnet.ts +16 -2
  236. package/src/predict/config/testnet.ts +16 -2
  237. package/src/predict/config/types.ts +51 -1
  238. package/src/predict/cost.ts +62 -14
  239. package/src/predict/decode.ts +691 -2
  240. package/src/predict/errors.ts +391 -14
  241. package/src/predict/index.ts +87 -6
  242. package/src/predict/queue-id.ts +22 -0
  243. package/src/predict/queue.ts +1231 -0
  244. package/src/predict/reads/markets.ts +30 -0
  245. package/src/predict/reads/queue.ts +606 -0
  246. package/src/predict/ticks.ts +35 -0
  247. package/src/predict/tx/common.ts +25 -1
  248. package/src/predict/tx/queue.ts +525 -0
  249. package/src/predict/tx/trade.ts +80 -49
  250. package/src/sessions.ts +206 -1
@@ -0,0 +1,1394 @@
1
+ /**************************************************************
2
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
3
+ **************************************************************/
4
+
5
+ /**
6
+ * One expiry market's delayed-execution queue, `MarketQueue`, and its flows:
7
+ * placement of queued mints and early sells, commit of verified Pyth Lazer prices,
8
+ * resolve at the committed tick, the deadline and admin refunds, the settlement
9
+ * drain and payout walk, cleanup, and the queue reads.
10
+ *
11
+ * Every money-moving step runs inside one of Predict's order-flow primitives,
12
+ * which check their own gates and bindings when they run: admission (`admit_mint`,
13
+ * `admit_sell`), `commit`, `try_fill`, `release`, and `try_pay_settled`. The queue
14
+ * owns what Predict leaves to the companion: τ and the deadline, the stuck gate,
15
+ * capacities and per-account caps, cohort order, the exact-or-backup tick choice,
16
+ * escrow custody, refund routing, and the queue events. Each record holds
17
+ * Predict's receipt for its order and that order's own escrow, so a refund pays
18
+ * exactly that record's escrow.
19
+ *
20
+ * A queued fill never enters the account: it stays an Open record until
21
+ * `enqueue_redeem_open` sells it or the settlement payout walk or `pay_open` pays
22
+ * it.
23
+ *
24
+ * Mainnet USDC is a regulated coin: Sui aborts a transaction that sends it to an
25
+ * address on its deny list for the current epoch, or to anyone while it is
26
+ * globally paused. Every walker restarts at the same head record, so one such send
27
+ * would block the market's fills, refunds, and payouts for good. So nothing here,
28
+ * and nothing in Predict's primitives, sends to a denied address. Predict refuses
29
+ * a fill for a denied receive address (reason 9), keeps a denied builder's or
30
+ * referrer's fee in market cash, and skips a denied winner's payout. The queue
31
+ * parks change and refunds it cannot send in the record, which finishes as usual
32
+ * with the funds kept (`RecordFundsParked`). `claim_parked` sends them, and
33
+ * `pay_open` pays a skipped Open record, once the address is clear. While USDC is
34
+ * globally paused every address counts as denied: fills refuse, refunds park, and
35
+ * payouts skip until the pause lifts.
36
+ */
37
+
38
+ import {
39
+ MoveStruct,
40
+ normalizeMoveArguments,
41
+ type RawTransactionArgument,
42
+ type ConfigValue,
43
+ } from '../utils/index.js';
44
+ import { bcs } from '@mysten/sui/bcs';
45
+ import { type Transaction, type TransactionArgument } from '@mysten/sui/transactions';
46
+ import * as order_queue from './order_queue.js';
47
+ const $moduleName = '@local-pkg/deepbook_predict_orders::queue';
48
+ export const MarketQueue = new MoveStruct({
49
+ name: `${$moduleName}::MarketQueue`,
50
+ fields: {
51
+ id: bcs.Address,
52
+ desk_id: bcs.Address,
53
+ expiry_market_id: bcs.Address,
54
+ book: order_queue.OrderBook,
55
+ /** Set by the `settle_step` call that emits `MarketPayoutsCompleted`. */
56
+ payouts_completed: bcs.bool(),
57
+ },
58
+ });
59
+ export interface PhaseDrainOptions {
60
+ package?: string;
61
+ arguments?: [];
62
+ config?: {
63
+ predictOrdersPackageId?: string;
64
+ };
65
+ }
66
+ export function phaseDrain(options: PhaseDrainOptions = {}) {
67
+ const packageAddress =
68
+ options.package ??
69
+ options.config?.predictOrdersPackageId ??
70
+ '@local-pkg/deepbook_predict_orders';
71
+ return (tx: Transaction) =>
72
+ tx.moveCall({
73
+ package: packageAddress,
74
+ module: 'queue',
75
+ function: 'phase_drain',
76
+ });
77
+ }
78
+ export interface PhasePayOptions {
79
+ package?: string;
80
+ arguments?: [];
81
+ config?: {
82
+ predictOrdersPackageId?: string;
83
+ };
84
+ }
85
+ export function phasePay(options: PhasePayOptions = {}) {
86
+ const packageAddress =
87
+ options.package ??
88
+ options.config?.predictOrdersPackageId ??
89
+ '@local-pkg/deepbook_predict_orders';
90
+ return (tx: Transaction) =>
91
+ tx.moveCall({
92
+ package: packageAddress,
93
+ module: 'queue',
94
+ function: 'phase_pay',
95
+ });
96
+ }
97
+ export interface PhaseDoneOptions {
98
+ package?: string;
99
+ arguments?: [];
100
+ config?: {
101
+ predictOrdersPackageId?: string;
102
+ };
103
+ }
104
+ export function phaseDone(options: PhaseDoneOptions = {}) {
105
+ const packageAddress =
106
+ options.package ??
107
+ options.config?.predictOrdersPackageId ??
108
+ '@local-pkg/deepbook_predict_orders';
109
+ return (tx: Transaction) =>
110
+ tx.moveCall({
111
+ package: packageAddress,
112
+ module: 'queue',
113
+ function: 'phase_done',
114
+ });
115
+ }
116
+ export interface QueueIdArguments {
117
+ registryId: RawTransactionArgument<string>;
118
+ expiryMarketId: RawTransactionArgument<string>;
119
+ }
120
+ export interface QueueIdOptions {
121
+ package?: string;
122
+ arguments:
123
+ | QueueIdArguments
124
+ | [registryId: RawTransactionArgument<string>, expiryMarketId: RawTransactionArgument<string>];
125
+ config?: {
126
+ predictOrdersPackageId?: string;
127
+ };
128
+ }
129
+ /**
130
+ * Return the ID of `expiry_market_id`'s queue under the queue registry
131
+ * `registry_id`, whether or not it exists yet. For PTB construction.
132
+ */
133
+ export function queueId(options: QueueIdOptions) {
134
+ const packageAddress =
135
+ options.package ??
136
+ options.config?.predictOrdersPackageId ??
137
+ '@local-pkg/deepbook_predict_orders';
138
+ const argumentsTypes = ['0x2::object::ID', '0x2::object::ID'] satisfies (string | null)[];
139
+ const parameterNames = ['registryId', 'expiryMarketId'];
140
+ return (tx: Transaction) =>
141
+ tx.moveCall({
142
+ package: packageAddress,
143
+ module: 'queue',
144
+ function: 'queue_id',
145
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
146
+ });
147
+ }
148
+ export interface IdArguments {
149
+ queue: RawTransactionArgument<string>;
150
+ }
151
+ export interface IdOptions {
152
+ package?: string;
153
+ arguments: IdArguments | [queue: RawTransactionArgument<string>];
154
+ config?: {
155
+ predictOrdersPackageId?: string;
156
+ };
157
+ }
158
+ export function id(options: IdOptions) {
159
+ const packageAddress =
160
+ options.package ??
161
+ options.config?.predictOrdersPackageId ??
162
+ '@local-pkg/deepbook_predict_orders';
163
+ const argumentsTypes = [null] satisfies (string | null)[];
164
+ const parameterNames = ['queue'];
165
+ return (tx: Transaction) =>
166
+ tx.moveCall({
167
+ package: packageAddress,
168
+ module: 'queue',
169
+ function: 'id',
170
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
171
+ });
172
+ }
173
+ export interface DeskIdArguments {
174
+ queue: RawTransactionArgument<string>;
175
+ }
176
+ export interface DeskIdOptions {
177
+ package?: string;
178
+ arguments: DeskIdArguments | [queue: RawTransactionArgument<string>];
179
+ config?: {
180
+ predictOrdersPackageId?: string;
181
+ };
182
+ }
183
+ export function deskId(options: DeskIdOptions) {
184
+ const packageAddress =
185
+ options.package ??
186
+ options.config?.predictOrdersPackageId ??
187
+ '@local-pkg/deepbook_predict_orders';
188
+ const argumentsTypes = [null] satisfies (string | null)[];
189
+ const parameterNames = ['queue'];
190
+ return (tx: Transaction) =>
191
+ tx.moveCall({
192
+ package: packageAddress,
193
+ module: 'queue',
194
+ function: 'desk_id',
195
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
196
+ });
197
+ }
198
+ export interface ExpiryMarketIdArguments {
199
+ queue: RawTransactionArgument<string>;
200
+ }
201
+ export interface ExpiryMarketIdOptions {
202
+ package?: string;
203
+ arguments: ExpiryMarketIdArguments | [queue: RawTransactionArgument<string>];
204
+ config?: {
205
+ predictOrdersPackageId?: string;
206
+ };
207
+ }
208
+ export function expiryMarketId(options: ExpiryMarketIdOptions) {
209
+ const packageAddress =
210
+ options.package ??
211
+ options.config?.predictOrdersPackageId ??
212
+ '@local-pkg/deepbook_predict_orders';
213
+ const argumentsTypes = [null] satisfies (string | null)[];
214
+ const parameterNames = ['queue'];
215
+ return (tx: Transaction) =>
216
+ tx.moveCall({
217
+ package: packageAddress,
218
+ module: 'queue',
219
+ function: 'expiry_market_id',
220
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
221
+ });
222
+ }
223
+ export interface OrderArguments {
224
+ queue: RawTransactionArgument<string>;
225
+ recordId: RawTransactionArgument<number | bigint>;
226
+ }
227
+ export interface OrderOptions {
228
+ package?: string;
229
+ arguments:
230
+ | OrderArguments
231
+ | [queue: RawTransactionArgument<string>, recordId: RawTransactionArgument<number | bigint>];
232
+ config?: {
233
+ predictOrdersPackageId?: string;
234
+ };
235
+ }
236
+ /** Return one record, or `none` for a missing or deleted record ID. */
237
+ export function order(options: OrderOptions) {
238
+ const packageAddress =
239
+ options.package ??
240
+ options.config?.predictOrdersPackageId ??
241
+ '@local-pkg/deepbook_predict_orders';
242
+ const argumentsTypes = [null, 'u64'] satisfies (string | null)[];
243
+ const parameterNames = ['queue', 'recordId'];
244
+ return (tx: Transaction) =>
245
+ tx.moveCall({
246
+ package: packageAddress,
247
+ module: 'queue',
248
+ function: 'order',
249
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
250
+ });
251
+ }
252
+ export interface QueueHeadsArguments {
253
+ queue: RawTransactionArgument<string>;
254
+ }
255
+ export interface QueueHeadsOptions {
256
+ package?: string;
257
+ arguments: QueueHeadsArguments | [queue: RawTransactionArgument<string>];
258
+ config?: {
259
+ predictOrdersPackageId?: string;
260
+ };
261
+ }
262
+ /**
263
+ * Return `(resolve_head, next_id, last_tau_ms, last_committed_tau_ms)`.
264
+ * `resolve_head` is a lower bound on the first unfinished record.
265
+ */
266
+ export function queueHeads(options: QueueHeadsOptions) {
267
+ const packageAddress =
268
+ options.package ??
269
+ options.config?.predictOrdersPackageId ??
270
+ '@local-pkg/deepbook_predict_orders';
271
+ const argumentsTypes = [null] satisfies (string | null)[];
272
+ const parameterNames = ['queue'];
273
+ return (tx: Transaction) =>
274
+ tx.moveCall({
275
+ package: packageAddress,
276
+ module: 'queue',
277
+ function: 'queue_heads',
278
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
279
+ });
280
+ }
281
+ export interface PayoutProgressArguments {
282
+ queue: RawTransactionArgument<string>;
283
+ }
284
+ export interface PayoutProgressOptions {
285
+ package?: string;
286
+ arguments: PayoutProgressArguments | [queue: RawTransactionArgument<string>];
287
+ config?: {
288
+ predictOrdersPackageId?: string;
289
+ };
290
+ }
291
+ /**
292
+ * Return `(payout_cursor, next_id, payouts_completed)`. The settlement payout walk
293
+ * is finished once `payouts_completed` is set.
294
+ */
295
+ export function payoutProgress(options: PayoutProgressOptions) {
296
+ const packageAddress =
297
+ options.package ??
298
+ options.config?.predictOrdersPackageId ??
299
+ '@local-pkg/deepbook_predict_orders';
300
+ const argumentsTypes = [null] satisfies (string | null)[];
301
+ const parameterNames = ['queue'];
302
+ return (tx: Transaction) =>
303
+ tx.moveCall({
304
+ package: packageAddress,
305
+ module: 'queue',
306
+ function: 'payout_progress',
307
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
308
+ });
309
+ }
310
+ export interface WaitingCohortsArguments {
311
+ queue: RawTransactionArgument<string>;
312
+ }
313
+ export interface WaitingCohortsOptions {
314
+ package?: string;
315
+ arguments: WaitingCohortsArguments | [queue: RawTransactionArgument<string>];
316
+ config?: {
317
+ predictOrdersPackageId?: string;
318
+ };
319
+ }
320
+ /**
321
+ * Return
322
+ * `(cohort count, oldest uncommitted τ, oldest uncommitted τ above last_committed_tau_ms)`.
323
+ * The third value is the cohort the stuck gate's first rule watches.
324
+ */
325
+ export function waitingCohorts(options: WaitingCohortsOptions) {
326
+ const packageAddress =
327
+ options.package ??
328
+ options.config?.predictOrdersPackageId ??
329
+ '@local-pkg/deepbook_predict_orders';
330
+ const argumentsTypes = [null] satisfies (string | null)[];
331
+ const parameterNames = ['queue'];
332
+ return (tx: Transaction) =>
333
+ tx.moveCall({
334
+ package: packageAddress,
335
+ module: 'queue',
336
+ function: 'waiting_cohorts',
337
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
338
+ });
339
+ }
340
+ export interface QueueStuckArguments {
341
+ queue: RawTransactionArgument<string>;
342
+ desk?: RawTransactionArgument<string>;
343
+ }
344
+ export interface QueueStuckOptions {
345
+ package?: string;
346
+ arguments: QueueStuckArguments;
347
+ config?: {
348
+ orderDesk: ConfigValue;
349
+ predictOrdersPackageId?: string;
350
+ };
351
+ }
352
+ /**
353
+ * Whether placement would refuse a new order as stuck right now (both rules of the
354
+ * stuck gate). Drives the app's "pricing delayed" banner.
355
+ */
356
+ export function queueStuck(options: QueueStuckOptions) {
357
+ const packageAddress =
358
+ options.package ??
359
+ options.config?.predictOrdersPackageId ??
360
+ '@local-pkg/deepbook_predict_orders';
361
+ const argumentsTypes = [null, null, '0x2::clock::Clock'] satisfies (string | null)[];
362
+ const parameterNames = ['queue', 'desk'];
363
+ return (tx: Transaction) =>
364
+ tx.moveCall({
365
+ package: packageAddress,
366
+ module: 'queue',
367
+ function: 'queue_stuck',
368
+ arguments: normalizeMoveArguments(
369
+ {
370
+ ...options.arguments,
371
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
372
+ },
373
+ argumentsTypes,
374
+ parameterNames,
375
+ ),
376
+ });
377
+ }
378
+ export interface PendingCountsArguments {
379
+ queue: RawTransactionArgument<string>;
380
+ }
381
+ export interface PendingCountsOptions {
382
+ package?: string;
383
+ arguments: PendingCountsArguments | [queue: RawTransactionArgument<string>];
384
+ config?: {
385
+ predictOrdersPackageId?: string;
386
+ };
387
+ }
388
+ /**
389
+ * Return `(pending_mints, pending_sells)`, the unfinished orders counted against
390
+ * the policy capacities.
391
+ */
392
+ export function pendingCounts(options: PendingCountsOptions) {
393
+ const packageAddress =
394
+ options.package ??
395
+ options.config?.predictOrdersPackageId ??
396
+ '@local-pkg/deepbook_predict_orders';
397
+ const argumentsTypes = [null] satisfies (string | null)[];
398
+ const parameterNames = ['queue'];
399
+ return (tx: Transaction) =>
400
+ tx.moveCall({
401
+ package: packageAddress,
402
+ module: 'queue',
403
+ function: 'pending_counts',
404
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
405
+ });
406
+ }
407
+ export interface WaitingOrdersArguments {
408
+ queue: RawTransactionArgument<string>;
409
+ accountId: RawTransactionArgument<string>;
410
+ }
411
+ export interface WaitingOrdersOptions {
412
+ package?: string;
413
+ arguments:
414
+ | WaitingOrdersArguments
415
+ | [queue: RawTransactionArgument<string>, accountId: RawTransactionArgument<string>];
416
+ config?: {
417
+ predictOrdersPackageId?: string;
418
+ };
419
+ }
420
+ /**
421
+ * Return the unfinished queued orders `account_id` holds in this queue, the count
422
+ * the per-account cap checks. The settlement drain (`settle_step`) refunds without
423
+ * lowering it, since no placement reads it once the market has expired, so after
424
+ * expiry it can overstate what the account still has waiting. Read `order` for
425
+ * each record's status instead.
426
+ */
427
+ export function waitingOrders(options: WaitingOrdersOptions) {
428
+ const packageAddress =
429
+ options.package ??
430
+ options.config?.predictOrdersPackageId ??
431
+ '@local-pkg/deepbook_predict_orders';
432
+ const argumentsTypes = [null, '0x2::object::ID'] satisfies (string | null)[];
433
+ const parameterNames = ['queue', 'accountId'];
434
+ return (tx: Transaction) =>
435
+ tx.moveCall({
436
+ package: packageAddress,
437
+ module: 'queue',
438
+ function: 'waiting_orders',
439
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
440
+ });
441
+ }
442
+ export interface OldestUnfinishedTauMsArguments {
443
+ queue: RawTransactionArgument<string>;
444
+ }
445
+ export interface OldestUnfinishedTauMsOptions {
446
+ package?: string;
447
+ arguments: OldestUnfinishedTauMsArguments | [queue: RawTransactionArgument<string>];
448
+ config?: {
449
+ predictOrdersPackageId?: string;
450
+ };
451
+ }
452
+ /** Return τ of the oldest cohort with an unfinished order, for monitoring. */
453
+ export function oldestUnfinishedTauMs(options: OldestUnfinishedTauMsOptions) {
454
+ const packageAddress =
455
+ options.package ??
456
+ options.config?.predictOrdersPackageId ??
457
+ '@local-pkg/deepbook_predict_orders';
458
+ const argumentsTypes = [null] satisfies (string | null)[];
459
+ const parameterNames = ['queue'];
460
+ return (tx: Transaction) =>
461
+ tx.moveCall({
462
+ package: packageAddress,
463
+ module: 'queue',
464
+ function: 'oldest_unfinished_tau_ms',
465
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
466
+ });
467
+ }
468
+ export interface QuoteRedeemOpenArguments {
469
+ queue: RawTransactionArgument<string>;
470
+ market: RawTransactionArgument<string>;
471
+ wrapper: RawTransactionArgument<string>;
472
+ pricer: TransactionArgument;
473
+ recordId: RawTransactionArgument<number | bigint>;
474
+ closeQuantity: RawTransactionArgument<number | bigint>;
475
+ }
476
+ export interface QuoteRedeemOpenOptions {
477
+ package?: string;
478
+ arguments:
479
+ | QuoteRedeemOpenArguments
480
+ | [
481
+ queue: RawTransactionArgument<string>,
482
+ market: RawTransactionArgument<string>,
483
+ wrapper: RawTransactionArgument<string>,
484
+ pricer: TransactionArgument,
485
+ recordId: RawTransactionArgument<number | bigint>,
486
+ closeQuantity: RawTransactionArgument<number | bigint>,
487
+ ];
488
+ config?: {
489
+ predictOrdersPackageId?: string;
490
+ };
491
+ }
492
+ /**
493
+ * Quote an early sell of `close_quantity` from the Open record `record_id` at a
494
+ * live `Pricer`, with the wrapper account's builder code, through Predict's
495
+ * `quote_close`: the close a queued sell fills, with the trading fee at the clock
496
+ * instead of a committed tick. `proceeds` is before the order fee. Changes
497
+ * nothing. Aborts `ERecordNotOpen` for a missing or non-Open record, and otherwise
498
+ * as `quote_close` does. Does not check that the account owns the record. For SDK
499
+ * and devInspect pricing before `enqueue_redeem_open`.
500
+ */
501
+ export function quoteRedeemOpen(options: QuoteRedeemOpenOptions) {
502
+ const packageAddress =
503
+ options.package ??
504
+ options.config?.predictOrdersPackageId ??
505
+ '@local-pkg/deepbook_predict_orders';
506
+ const argumentsTypes = [null, null, null, null, 'u64', 'u64', '0x2::clock::Clock'] satisfies (
507
+ string | null
508
+ )[];
509
+ const parameterNames = ['queue', 'market', 'wrapper', 'pricer', 'recordId', 'closeQuantity'];
510
+ return (tx: Transaction) =>
511
+ tx.moveCall({
512
+ package: packageAddress,
513
+ module: 'queue',
514
+ function: 'quote_redeem_open',
515
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
516
+ });
517
+ }
518
+ export interface CreateAndShareArguments {
519
+ registry?: RawTransactionArgument<string>;
520
+ desk?: RawTransactionArgument<string>;
521
+ market: RawTransactionArgument<string>;
522
+ }
523
+ export interface CreateAndShareOptions {
524
+ package?: string;
525
+ arguments: CreateAndShareArguments;
526
+ config?: {
527
+ queueRegistry: ConfigValue;
528
+ orderDesk: ConfigValue;
529
+ predictOrdersPackageId?: string;
530
+ };
531
+ }
532
+ /**
533
+ * Create and share `market`'s queue under `desk`. Permissionless; the caller pays
534
+ * its storage. The queue's ID is derived from the desk's registry and the market,
535
+ * so a second call for the same market aborts. Writes only the registry, which no
536
+ * trading call reads, so creation never contends with trading on the desk. Aborts
537
+ * `EWrongDesk` for another desk's registry.
538
+ */
539
+ export function createAndShare(options: CreateAndShareOptions) {
540
+ const packageAddress =
541
+ options.package ??
542
+ options.config?.predictOrdersPackageId ??
543
+ '@local-pkg/deepbook_predict_orders';
544
+ const argumentsTypes = [null, null, null] satisfies (string | null)[];
545
+ const parameterNames = ['registry', 'desk', 'market'];
546
+ return (tx: Transaction) =>
547
+ tx.moveCall({
548
+ package: packageAddress,
549
+ module: 'queue',
550
+ function: 'create_and_share',
551
+ arguments: normalizeMoveArguments(
552
+ {
553
+ ...options.arguments,
554
+ registry: options.arguments?.registry ?? options.config?.queueRegistry,
555
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
556
+ },
557
+ argumentsTypes,
558
+ parameterNames,
559
+ ),
560
+ });
561
+ }
562
+ export interface EnqueueExactQuantityArguments {
563
+ queue: RawTransactionArgument<string>;
564
+ market: RawTransactionArgument<string>;
565
+ wrapper: RawTransactionArgument<string>;
566
+ auth: TransactionArgument;
567
+ desk?: RawTransactionArgument<string>;
568
+ config?: RawTransactionArgument<string>;
569
+ propbookRegistry?: RawTransactionArgument<string>;
570
+ pyth: RawTransactionArgument<string>;
571
+ bsValues: RawTransactionArgument<string>;
572
+ bsSvi: RawTransactionArgument<string>;
573
+ lowerTick: RawTransactionArgument<number | bigint>;
574
+ higherTick: RawTransactionArgument<number | bigint>;
575
+ quantity: RawTransactionArgument<number | bigint>;
576
+ maxCost: RawTransactionArgument<number | bigint>;
577
+ maxProbability: RawTransactionArgument<number | bigint>;
578
+ }
579
+ export interface EnqueueExactQuantityOptions {
580
+ package?: string;
581
+ arguments: EnqueueExactQuantityArguments;
582
+ config?: {
583
+ orderDesk: ConfigValue;
584
+ protocolConfig: ConfigValue;
585
+ oracleRegistry: ConfigValue;
586
+ predictOrdersPackageId?: string;
587
+ };
588
+ }
589
+ /**
590
+ * Place a queued mint for an exact quantity, priced later at Pyth's signed price
591
+ * for its τ. `max_cost` caps the all-in withdrawal and is mandatory;
592
+ * `max_probability` caps the entry probability at τ. Escrows the budget,
593
+ * `min(max_cost, quantity, available - order_fee)`, and the order fee, and returns
594
+ * the new record ID.
595
+ *
596
+ * Aborts, charging nothing, when the queue refuses the order: the desk floor,
597
+ * another desk's or market's queue (`EWrongDesk`, `EWrongMarket`), a stuck or full
598
+ * queue (`EQueueStuck`, `EQueueFull`, `EAccountOrderCap`), τ at or past the cutoff
599
+ * (`EPastCutoff`), an unlimited or zero `max_cost` (`EMintCostCapRequired`), or a
600
+ * balance not above the order fee (`EFeeNotCovered`). Then Predict's `admit_mint`
601
+ * applies its gates, the order's own limits at the clock, and the market's spare
602
+ * cash.
603
+ */
604
+ export function enqueueExactQuantity(options: EnqueueExactQuantityOptions) {
605
+ const packageAddress =
606
+ options.package ??
607
+ options.config?.predictOrdersPackageId ??
608
+ '@local-pkg/deepbook_predict_orders';
609
+ const argumentsTypes = [
610
+ null,
611
+ null,
612
+ null,
613
+ null,
614
+ null,
615
+ null,
616
+ null,
617
+ null,
618
+ null,
619
+ null,
620
+ 'u64',
621
+ 'u64',
622
+ 'u64',
623
+ 'u64',
624
+ 'u64',
625
+ '0x2::accumulator::AccumulatorRoot',
626
+ '0x2::clock::Clock',
627
+ ] satisfies (string | null)[];
628
+ const parameterNames = [
629
+ 'queue',
630
+ 'market',
631
+ 'wrapper',
632
+ 'auth',
633
+ 'desk',
634
+ 'config',
635
+ 'propbookRegistry',
636
+ 'pyth',
637
+ 'bsValues',
638
+ 'bsSvi',
639
+ 'lowerTick',
640
+ 'higherTick',
641
+ 'quantity',
642
+ 'maxCost',
643
+ 'maxProbability',
644
+ ];
645
+ return (tx: Transaction) =>
646
+ tx.moveCall({
647
+ package: packageAddress,
648
+ module: 'queue',
649
+ function: 'enqueue_exact_quantity',
650
+ arguments: normalizeMoveArguments(
651
+ {
652
+ ...options.arguments,
653
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
654
+ config: options.arguments?.config ?? options.config?.protocolConfig,
655
+ propbookRegistry: options.arguments?.propbookRegistry ?? options.config?.oracleRegistry,
656
+ },
657
+ argumentsTypes,
658
+ parameterNames,
659
+ ),
660
+ });
661
+ }
662
+ export interface EnqueueExactAmountArguments {
663
+ queue: RawTransactionArgument<string>;
664
+ market: RawTransactionArgument<string>;
665
+ wrapper: RawTransactionArgument<string>;
666
+ auth: TransactionArgument;
667
+ desk?: RawTransactionArgument<string>;
668
+ config?: RawTransactionArgument<string>;
669
+ propbookRegistry?: RawTransactionArgument<string>;
670
+ pyth: RawTransactionArgument<string>;
671
+ bsValues: RawTransactionArgument<string>;
672
+ bsSvi: RawTransactionArgument<string>;
673
+ lowerTick: RawTransactionArgument<number | bigint>;
674
+ higherTick: RawTransactionArgument<number | bigint>;
675
+ maxPremium: RawTransactionArgument<number | bigint>;
676
+ minQuantity: RawTransactionArgument<number | bigint>;
677
+ maxCost: RawTransactionArgument<number | bigint>;
678
+ }
679
+ export interface EnqueueExactAmountOptions {
680
+ package?: string;
681
+ arguments: EnqueueExactAmountArguments;
682
+ config?: {
683
+ orderDesk: ConfigValue;
684
+ protocolConfig: ConfigValue;
685
+ oracleRegistry: ConfigValue;
686
+ predictOrdersPackageId?: string;
687
+ };
688
+ }
689
+ /**
690
+ * Place a queued premium-budget mint: sized at τ under `max_premium`, at least
691
+ * `min_quantity`, with the all-in withdrawal capped by the mandatory `max_cost`.
692
+ * Escrows `min(max_cost, available - order_fee)` and the order fee. Refuses orders
693
+ * like `enqueue_exact_quantity`. Returns the new record ID.
694
+ */
695
+ export function enqueueExactAmount(options: EnqueueExactAmountOptions) {
696
+ const packageAddress =
697
+ options.package ??
698
+ options.config?.predictOrdersPackageId ??
699
+ '@local-pkg/deepbook_predict_orders';
700
+ const argumentsTypes = [
701
+ null,
702
+ null,
703
+ null,
704
+ null,
705
+ null,
706
+ null,
707
+ null,
708
+ null,
709
+ null,
710
+ null,
711
+ 'u64',
712
+ 'u64',
713
+ 'u64',
714
+ 'u64',
715
+ 'u64',
716
+ '0x2::accumulator::AccumulatorRoot',
717
+ '0x2::clock::Clock',
718
+ ] satisfies (string | null)[];
719
+ const parameterNames = [
720
+ 'queue',
721
+ 'market',
722
+ 'wrapper',
723
+ 'auth',
724
+ 'desk',
725
+ 'config',
726
+ 'propbookRegistry',
727
+ 'pyth',
728
+ 'bsValues',
729
+ 'bsSvi',
730
+ 'lowerTick',
731
+ 'higherTick',
732
+ 'maxPremium',
733
+ 'minQuantity',
734
+ 'maxCost',
735
+ ];
736
+ return (tx: Transaction) =>
737
+ tx.moveCall({
738
+ package: packageAddress,
739
+ module: 'queue',
740
+ function: 'enqueue_exact_amount',
741
+ arguments: normalizeMoveArguments(
742
+ {
743
+ ...options.arguments,
744
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
745
+ config: options.arguments?.config ?? options.config?.protocolConfig,
746
+ propbookRegistry: options.arguments?.propbookRegistry ?? options.config?.oracleRegistry,
747
+ },
748
+ argumentsTypes,
749
+ parameterNames,
750
+ ),
751
+ });
752
+ }
753
+ export interface EnqueueExactCostArguments {
754
+ queue: RawTransactionArgument<string>;
755
+ market: RawTransactionArgument<string>;
756
+ wrapper: RawTransactionArgument<string>;
757
+ auth: TransactionArgument;
758
+ desk?: RawTransactionArgument<string>;
759
+ config?: RawTransactionArgument<string>;
760
+ propbookRegistry?: RawTransactionArgument<string>;
761
+ pyth: RawTransactionArgument<string>;
762
+ bsValues: RawTransactionArgument<string>;
763
+ bsSvi: RawTransactionArgument<string>;
764
+ lowerTick: RawTransactionArgument<number | bigint>;
765
+ higherTick: RawTransactionArgument<number | bigint>;
766
+ maxCost: RawTransactionArgument<number | bigint>;
767
+ minQuantity: RawTransactionArgument<number | bigint>;
768
+ }
769
+ export interface EnqueueExactCostOptions {
770
+ package?: string;
771
+ arguments: EnqueueExactCostArguments;
772
+ config?: {
773
+ orderDesk: ConfigValue;
774
+ protocolConfig: ConfigValue;
775
+ oracleRegistry: ConfigValue;
776
+ predictOrdersPackageId?: string;
777
+ };
778
+ }
779
+ /**
780
+ * Place a queued all-in-budget mint: sized at τ so the all-in cost fits
781
+ * `max_cost`, at least `min_quantity`. Escrows
782
+ * `min(max_cost, available - order_fee)` and the order fee. `max_cost` is
783
+ * mandatory here too: the unlimited value is refused. Refuses orders like
784
+ * `enqueue_exact_quantity`. Returns the new record ID.
785
+ */
786
+ export function enqueueExactCost(options: EnqueueExactCostOptions) {
787
+ const packageAddress =
788
+ options.package ??
789
+ options.config?.predictOrdersPackageId ??
790
+ '@local-pkg/deepbook_predict_orders';
791
+ const argumentsTypes = [
792
+ null,
793
+ null,
794
+ null,
795
+ null,
796
+ null,
797
+ null,
798
+ null,
799
+ null,
800
+ null,
801
+ null,
802
+ 'u64',
803
+ 'u64',
804
+ 'u64',
805
+ 'u64',
806
+ '0x2::accumulator::AccumulatorRoot',
807
+ '0x2::clock::Clock',
808
+ ] satisfies (string | null)[];
809
+ const parameterNames = [
810
+ 'queue',
811
+ 'market',
812
+ 'wrapper',
813
+ 'auth',
814
+ 'desk',
815
+ 'config',
816
+ 'propbookRegistry',
817
+ 'pyth',
818
+ 'bsValues',
819
+ 'bsSvi',
820
+ 'lowerTick',
821
+ 'higherTick',
822
+ 'maxCost',
823
+ 'minQuantity',
824
+ ];
825
+ return (tx: Transaction) =>
826
+ tx.moveCall({
827
+ package: packageAddress,
828
+ module: 'queue',
829
+ function: 'enqueue_exact_cost',
830
+ arguments: normalizeMoveArguments(
831
+ {
832
+ ...options.arguments,
833
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
834
+ config: options.arguments?.config ?? options.config?.protocolConfig,
835
+ propbookRegistry: options.arguments?.propbookRegistry ?? options.config?.oracleRegistry,
836
+ },
837
+ argumentsTypes,
838
+ parameterNames,
839
+ ),
840
+ });
841
+ }
842
+ export interface EnqueueRedeemOpenArguments {
843
+ queue: RawTransactionArgument<string>;
844
+ market: RawTransactionArgument<string>;
845
+ wrapper: RawTransactionArgument<string>;
846
+ auth: TransactionArgument;
847
+ desk?: RawTransactionArgument<string>;
848
+ config?: RawTransactionArgument<string>;
849
+ propbookRegistry?: RawTransactionArgument<string>;
850
+ pyth: RawTransactionArgument<string>;
851
+ bsValues: RawTransactionArgument<string>;
852
+ bsSvi: RawTransactionArgument<string>;
853
+ recordId: RawTransactionArgument<number | bigint>;
854
+ closeQuantity: RawTransactionArgument<number | bigint>;
855
+ minProbability: RawTransactionArgument<number | bigint>;
856
+ minProceeds: RawTransactionArgument<number | bigint>;
857
+ }
858
+ export interface EnqueueRedeemOpenOptions {
859
+ package?: string;
860
+ arguments: EnqueueRedeemOpenArguments;
861
+ config?: {
862
+ orderDesk: ConfigValue;
863
+ protocolConfig: ConfigValue;
864
+ oracleRegistry: ConfigValue;
865
+ predictOrdersPackageId?: string;
866
+ };
867
+ }
868
+ /**
869
+ * Place a queued early sell of `close_quantity` of an Open record's position.
870
+ * `record_id` is the record's queue ID, not the position's order ID. The source
871
+ * record must belong to this account (`ENotRecordOwner`) and be Open
872
+ * (`ERecordNotOpen`, also for a missing ID). It is marked Closed and its receipt
873
+ * and whole position move into the new record until the sell fills or refunds.
874
+ * `min_probability` and `min_proceeds` are the close-side floors at τ. Returns the
875
+ * new record ID.
876
+ *
877
+ * Escrows only the order fee, so a balance equal to it is enough. Refuses a sell
878
+ * below `min_sell_quantity` or one leaving a remainder below it (`EBelowMinSell`),
879
+ * and otherwise like `enqueue_exact_quantity`. Predict's `admit_sell` is open
880
+ * during the trading pause and a market mint pause and has no spare-cash check:
881
+ * the keeper funds the market before τ, and resolve refunds a sell the market
882
+ * still cannot cover.
883
+ */
884
+ export function enqueueRedeemOpen(options: EnqueueRedeemOpenOptions) {
885
+ const packageAddress =
886
+ options.package ??
887
+ options.config?.predictOrdersPackageId ??
888
+ '@local-pkg/deepbook_predict_orders';
889
+ const argumentsTypes = [
890
+ null,
891
+ null,
892
+ null,
893
+ null,
894
+ null,
895
+ null,
896
+ null,
897
+ null,
898
+ null,
899
+ null,
900
+ 'u64',
901
+ 'u64',
902
+ 'u64',
903
+ 'u64',
904
+ '0x2::accumulator::AccumulatorRoot',
905
+ '0x2::clock::Clock',
906
+ ] satisfies (string | null)[];
907
+ const parameterNames = [
908
+ 'queue',
909
+ 'market',
910
+ 'wrapper',
911
+ 'auth',
912
+ 'desk',
913
+ 'config',
914
+ 'propbookRegistry',
915
+ 'pyth',
916
+ 'bsValues',
917
+ 'bsSvi',
918
+ 'recordId',
919
+ 'closeQuantity',
920
+ 'minProbability',
921
+ 'minProceeds',
922
+ ];
923
+ return (tx: Transaction) =>
924
+ tx.moveCall({
925
+ package: packageAddress,
926
+ module: 'queue',
927
+ function: 'enqueue_redeem_open',
928
+ arguments: normalizeMoveArguments(
929
+ {
930
+ ...options.arguments,
931
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
932
+ config: options.arguments?.config ?? options.config?.protocolConfig,
933
+ propbookRegistry: options.arguments?.propbookRegistry ?? options.config?.oracleRegistry,
934
+ },
935
+ argumentsTypes,
936
+ parameterNames,
937
+ ),
938
+ });
939
+ }
940
+ export interface CommitArguments {
941
+ queue: RawTransactionArgument<string>;
942
+ market: RawTransactionArgument<string>;
943
+ desk?: RawTransactionArgument<string>;
944
+ config?: RawTransactionArgument<string>;
945
+ updates: TransactionArgument;
946
+ }
947
+ export interface CommitOptions {
948
+ package?: string;
949
+ arguments: CommitArguments;
950
+ config?: {
951
+ orderDesk: ConfigValue;
952
+ protocolConfig: ConfigValue;
953
+ predictOrdersPackageId?: string;
954
+ };
955
+ }
956
+ /**
957
+ * Attach verified Pyth Lazer prices to the waiting cohorts whose τ they match.
958
+ * Permissionless. Each update must come from the Pyth Lazer verifier earlier in
959
+ * the same PTB; their order in `updates` does not matter. An update that matches
960
+ * no waiting cohort is skipped.
961
+ *
962
+ * Matching reads only the inline cohort list and picks at most one update per
963
+ * waiting cohort before its deadline: the one stamped exactly its τ on its
964
+ * channel, or else, once the price buffer is above zero and now is at least
965
+ * `gap_wait_ms` past τ, the one stamped one tick of the cohort's own channel
966
+ * later. Each matched cohort then commits whole or not at all: one price per feed
967
+ * is decoded through `lazer_price::from_update`, every Pending order is checked
968
+ * against it before any is written, and an empty price, a price generated before
969
+ * τ, or an envelope after now leaves the cohort for a later commit or its deadline
970
+ * refund. The decode aborts on an update that lacks an order's feed or one of its
971
+ * properties, because the caller passed the wrong update. Each committed mint
972
+ * escrows the subsidy Predict reserves for it.
973
+ *
974
+ * Uses Lazer's v1 `Update`, which Pyth marked deprecated on Mainnet but still
975
+ * serves; v2 arrives with a later library constructor.
976
+ */
977
+ export function commit(options: CommitOptions) {
978
+ const packageAddress =
979
+ options.package ??
980
+ options.config?.predictOrdersPackageId ??
981
+ '@local-pkg/deepbook_predict_orders';
982
+ const argumentsTypes = [null, null, null, null, 'vector<null>', '0x2::clock::Clock'] satisfies (
983
+ string | null
984
+ )[];
985
+ const parameterNames = ['queue', 'market', 'desk', 'config', 'updates'];
986
+ return (tx: Transaction) =>
987
+ tx.moveCall({
988
+ package: packageAddress,
989
+ module: 'queue',
990
+ function: 'commit',
991
+ arguments: normalizeMoveArguments(
992
+ {
993
+ ...options.arguments,
994
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
995
+ config: options.arguments?.config ?? options.config?.protocolConfig,
996
+ },
997
+ argumentsTypes,
998
+ parameterNames,
999
+ ),
1000
+ });
1001
+ }
1002
+ export interface ResolveArguments {
1003
+ queue: RawTransactionArgument<string>;
1004
+ market: RawTransactionArgument<string>;
1005
+ desk?: RawTransactionArgument<string>;
1006
+ config?: RawTransactionArgument<string>;
1007
+ maxOrders: RawTransactionArgument<number | bigint>;
1008
+ }
1009
+ export interface ResolveOptions {
1010
+ package?: string;
1011
+ arguments: ResolveArguments;
1012
+ config?: {
1013
+ orderDesk: ConfigValue;
1014
+ protocolConfig: ConfigValue;
1015
+ predictOrdersPackageId?: string;
1016
+ };
1017
+ }
1018
+ /**
1019
+ * Fill or refund committed orders in τ order, visiting at most `max_orders`
1020
+ * records, and never more than 450 (each emits up to two events, and Sui caps a
1021
+ * transaction at 1,024). Permissionless. Returns how many orders it finished.
1022
+ *
1023
+ * Walks the cohorts in τ order and loads only committed or overdue ones; a cohort
1024
+ * still waiting for its price is skipped without loading a record. Every record
1025
+ * visited counts against `max_orders`, finished or missing ones included. The 450
1026
+ * cap bounds events, not loaded objects (`MAX_ORDERS_PER_CALL`), so the caller
1027
+ * sizes `max_orders` to stay inside Sui's per-transaction object limit. An order
1028
+ * at or past its deadline is refunded (reason 5), never filled. A committed order
1029
+ * goes to Predict's `try_fill`, which fills it or returns the refund reason (1, 2,
1030
+ * 4, 8, or 9); the queue returns the escrow Predict hands back to the trader, or
1031
+ * parks it in the record when the receive address is denied. Returns 0 on a
1032
+ * settled market, whose waiting orders the settlement drain refunds.
1033
+ */
1034
+ export function resolve(options: ResolveOptions) {
1035
+ const packageAddress =
1036
+ options.package ??
1037
+ options.config?.predictOrdersPackageId ??
1038
+ '@local-pkg/deepbook_predict_orders';
1039
+ const argumentsTypes = [
1040
+ null,
1041
+ null,
1042
+ null,
1043
+ null,
1044
+ 'u64',
1045
+ '0x2::deny_list::DenyList',
1046
+ '0x2::clock::Clock',
1047
+ ] satisfies (string | null)[];
1048
+ const parameterNames = ['queue', 'market', 'desk', 'config', 'maxOrders'];
1049
+ return (tx: Transaction) =>
1050
+ tx.moveCall({
1051
+ package: packageAddress,
1052
+ module: 'queue',
1053
+ function: 'resolve',
1054
+ arguments: normalizeMoveArguments(
1055
+ {
1056
+ ...options.arguments,
1057
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
1058
+ config: options.arguments?.config ?? options.config?.protocolConfig,
1059
+ },
1060
+ argumentsTypes,
1061
+ parameterNames,
1062
+ ),
1063
+ });
1064
+ }
1065
+ export interface RefundArguments {
1066
+ queue: RawTransactionArgument<string>;
1067
+ market: RawTransactionArgument<string>;
1068
+ desk?: RawTransactionArgument<string>;
1069
+ config?: RawTransactionArgument<string>;
1070
+ maxOrders: RawTransactionArgument<number | bigint>;
1071
+ }
1072
+ export interface RefundOptions {
1073
+ package?: string;
1074
+ arguments: RefundArguments;
1075
+ config?: {
1076
+ orderDesk: ConfigValue;
1077
+ protocolConfig: ConfigValue;
1078
+ predictOrdersPackageId?: string;
1079
+ };
1080
+ }
1081
+ /**
1082
+ * Refund waiting orders at or past their deadline (reason 5), visiting at most
1083
+ * `max_orders` records, refunded or not, and never more than 450, as `resolve`
1084
+ * does. It walks the cohorts in τ order and stops at the first one not yet due,
1085
+ * since deadlines never decrease along the queue. Permissionless, and available
1086
+ * while Predict is frozen or this companion's witness is disabled: Predict's
1087
+ * `release` checks only its version floor. A refund the receive address cannot
1088
+ * take is parked in its record. Returns how many orders it refunded: `0`, without
1089
+ * aborting, when none is due.
1090
+ */
1091
+ export function refund(options: RefundOptions) {
1092
+ const packageAddress =
1093
+ options.package ??
1094
+ options.config?.predictOrdersPackageId ??
1095
+ '@local-pkg/deepbook_predict_orders';
1096
+ const argumentsTypes = [
1097
+ null,
1098
+ null,
1099
+ null,
1100
+ null,
1101
+ 'u64',
1102
+ '0x2::deny_list::DenyList',
1103
+ '0x2::clock::Clock',
1104
+ ] satisfies (string | null)[];
1105
+ const parameterNames = ['queue', 'market', 'desk', 'config', 'maxOrders'];
1106
+ return (tx: Transaction) =>
1107
+ tx.moveCall({
1108
+ package: packageAddress,
1109
+ module: 'queue',
1110
+ function: 'refund',
1111
+ arguments: normalizeMoveArguments(
1112
+ {
1113
+ ...options.arguments,
1114
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
1115
+ config: options.arguments?.config ?? options.config?.protocolConfig,
1116
+ },
1117
+ argumentsTypes,
1118
+ parameterNames,
1119
+ ),
1120
+ });
1121
+ }
1122
+ export interface AdminRefundArguments {
1123
+ queue: RawTransactionArgument<string>;
1124
+ market: RawTransactionArgument<string>;
1125
+ AdminCap: RawTransactionArgument<string>;
1126
+ desk?: RawTransactionArgument<string>;
1127
+ config?: RawTransactionArgument<string>;
1128
+ recordIds: RawTransactionArgument<Array<number | bigint>>;
1129
+ }
1130
+ export interface AdminRefundOptions {
1131
+ package?: string;
1132
+ arguments: AdminRefundArguments;
1133
+ config?: {
1134
+ orderDesk: ConfigValue;
1135
+ protocolConfig: ConfigValue;
1136
+ predictOrdersPackageId?: string;
1137
+ };
1138
+ }
1139
+ /**
1140
+ * Refund the listed waiting orders at once (reason 7), wherever they sit in the
1141
+ * queue. Predict's `AdminCap` only, and available while Predict is frozen. Missing
1142
+ * and finished IDs are skipped, and a refund the receive address cannot take is
1143
+ * parked in its record.
1144
+ */
1145
+ export function adminRefund(options: AdminRefundOptions) {
1146
+ const packageAddress =
1147
+ options.package ??
1148
+ options.config?.predictOrdersPackageId ??
1149
+ '@local-pkg/deepbook_predict_orders';
1150
+ const argumentsTypes = [
1151
+ null,
1152
+ null,
1153
+ null,
1154
+ null,
1155
+ null,
1156
+ 'vector<u64>',
1157
+ '0x2::deny_list::DenyList',
1158
+ '0x2::clock::Clock',
1159
+ ] satisfies (string | null)[];
1160
+ const parameterNames = ['queue', 'market', 'AdminCap', 'desk', 'config', 'recordIds'];
1161
+ return (tx: Transaction) =>
1162
+ tx.moveCall({
1163
+ package: packageAddress,
1164
+ module: 'queue',
1165
+ function: 'admin_refund',
1166
+ arguments: normalizeMoveArguments(
1167
+ {
1168
+ ...options.arguments,
1169
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
1170
+ config: options.arguments?.config ?? options.config?.protocolConfig,
1171
+ },
1172
+ argumentsTypes,
1173
+ parameterNames,
1174
+ ),
1175
+ });
1176
+ }
1177
+ export interface CleanupArguments {
1178
+ queue: RawTransactionArgument<string>;
1179
+ market: RawTransactionArgument<string>;
1180
+ desk?: RawTransactionArgument<string>;
1181
+ recordIds: RawTransactionArgument<Array<number | bigint>>;
1182
+ }
1183
+ export interface CleanupOptions {
1184
+ package?: string;
1185
+ arguments: CleanupArguments;
1186
+ config?: {
1187
+ orderDesk: ConfigValue;
1188
+ predictOrdersPackageId?: string;
1189
+ };
1190
+ }
1191
+ /**
1192
+ * Delete Refunded and Closed records of a settled market. Permissionless; the
1193
+ * storage rebate goes to the caller. Missing IDs, other statuses, and records
1194
+ * still holding a receipt or funds (parked funds included, until `claim_parked`)
1195
+ * are skipped; `QueuedOrdersCleaned` is emitted only when a record was deleted.
1196
+ * Takes `&Clock` only to stamp the event.
1197
+ */
1198
+ export function cleanup(options: CleanupOptions) {
1199
+ const packageAddress =
1200
+ options.package ??
1201
+ options.config?.predictOrdersPackageId ??
1202
+ '@local-pkg/deepbook_predict_orders';
1203
+ const argumentsTypes = [null, null, null, 'vector<u64>', '0x2::clock::Clock'] satisfies (
1204
+ string | null
1205
+ )[];
1206
+ const parameterNames = ['queue', 'market', 'desk', 'recordIds'];
1207
+ return (tx: Transaction) =>
1208
+ tx.moveCall({
1209
+ package: packageAddress,
1210
+ module: 'queue',
1211
+ function: 'cleanup',
1212
+ arguments: normalizeMoveArguments(
1213
+ {
1214
+ ...options.arguments,
1215
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
1216
+ },
1217
+ argumentsTypes,
1218
+ parameterNames,
1219
+ ),
1220
+ });
1221
+ }
1222
+ export interface SettleStepArguments {
1223
+ queue: RawTransactionArgument<string>;
1224
+ market: RawTransactionArgument<string>;
1225
+ desk?: RawTransactionArgument<string>;
1226
+ config?: RawTransactionArgument<string>;
1227
+ }
1228
+ export interface SettleStepOptions {
1229
+ package?: string;
1230
+ arguments: SettleStepArguments;
1231
+ config?: {
1232
+ orderDesk: ConfigValue;
1233
+ protocolConfig: ConfigValue;
1234
+ predictOrdersPackageId?: string;
1235
+ };
1236
+ }
1237
+ /**
1238
+ * Run one bounded settlement phase on this queue and return the phase the queue is
1239
+ * in afterwards, which the next call runs (`phase_drain`, `phase_pay`, or
1240
+ * `phase_done`). Permissionless; aborts `EMarketNotExpired` before expiry.
1241
+ *
1242
+ * - DRAIN, while unfinished orders remain: refund them in τ order with reason 5,
1243
+ * visiting at most the policy's `settle_refund_batch` records, refunded or not.
1244
+ * No pruning and no account rows, so each refund loads its record alone. A
1245
+ * refund the receive address cannot take is parked in its record. Runs before
1246
+ * and after Predict settles, and while Predict is frozen.
1247
+ * - PAY, once nothing is unfinished and Predict has settled the market: from the
1248
+ * payout cursor, visit at most `settle_payout_batch` records. Each Open record
1249
+ * is paid its settled payout through `try_pay_settled` (zero for a loser),
1250
+ * marked Closed, and reported with `OpenRecordSettled`. A record the market
1251
+ * cannot pay, or whose receive address is denied, stays Open with
1252
+ * `OpenRecordPayoutSkipped`, and `pay_open` pays it later. Before Predict
1253
+ * settles, a PAY call changes nothing.
1254
+ * - DONE: the call whose walk reaches the last record emits
1255
+ * `MarketPayoutsCompleted`; later calls change nothing. Skipped records are
1256
+ * still paid through `pay_open`.
1257
+ *
1258
+ * The keeper sends one call per transaction until it returns `phase_done()`.
1259
+ */
1260
+ export function settleStep(options: SettleStepOptions) {
1261
+ const packageAddress =
1262
+ options.package ??
1263
+ options.config?.predictOrdersPackageId ??
1264
+ '@local-pkg/deepbook_predict_orders';
1265
+ const argumentsTypes = [
1266
+ null,
1267
+ null,
1268
+ null,
1269
+ null,
1270
+ '0x2::deny_list::DenyList',
1271
+ '0x2::clock::Clock',
1272
+ ] satisfies (string | null)[];
1273
+ const parameterNames = ['queue', 'market', 'desk', 'config'];
1274
+ return (tx: Transaction) =>
1275
+ tx.moveCall({
1276
+ package: packageAddress,
1277
+ module: 'queue',
1278
+ function: 'settle_step',
1279
+ arguments: normalizeMoveArguments(
1280
+ {
1281
+ ...options.arguments,
1282
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
1283
+ config: options.arguments?.config ?? options.config?.protocolConfig,
1284
+ },
1285
+ argumentsTypes,
1286
+ parameterNames,
1287
+ ),
1288
+ });
1289
+ }
1290
+ export interface PayOpenArguments {
1291
+ queue: RawTransactionArgument<string>;
1292
+ market: RawTransactionArgument<string>;
1293
+ desk?: RawTransactionArgument<string>;
1294
+ config?: RawTransactionArgument<string>;
1295
+ recordId: RawTransactionArgument<number | bigint>;
1296
+ }
1297
+ export interface PayOpenOptions {
1298
+ package?: string;
1299
+ arguments: PayOpenArguments;
1300
+ config?: {
1301
+ orderDesk: ConfigValue;
1302
+ protocolConfig: ConfigValue;
1303
+ predictOrdersPackageId?: string;
1304
+ };
1305
+ }
1306
+ /**
1307
+ * Pay one Open record of a settled market its settled payout through Predict's
1308
+ * `try_pay_settled`, at any time after settlement, before or after `settle_step`
1309
+ * completes: the record the payout walk skipped because the market was short of
1310
+ * cash or its receive address was denied. Permissionless. Emits
1311
+ * `OpenRecordSettled` and closes the record, or emits `OpenRecordPayoutSkipped`
1312
+ * and leaves it Open if the cause persists. A missing or non-Open record is left
1313
+ * alone. Aborts `EMarketNotSettled` before Predict settles the market.
1314
+ */
1315
+ export function payOpen(options: PayOpenOptions) {
1316
+ const packageAddress =
1317
+ options.package ??
1318
+ options.config?.predictOrdersPackageId ??
1319
+ '@local-pkg/deepbook_predict_orders';
1320
+ const argumentsTypes = [
1321
+ null,
1322
+ null,
1323
+ null,
1324
+ null,
1325
+ 'u64',
1326
+ '0x2::deny_list::DenyList',
1327
+ '0x2::clock::Clock',
1328
+ ] satisfies (string | null)[];
1329
+ const parameterNames = ['queue', 'market', 'desk', 'config', 'recordId'];
1330
+ return (tx: Transaction) =>
1331
+ tx.moveCall({
1332
+ package: packageAddress,
1333
+ module: 'queue',
1334
+ function: 'pay_open',
1335
+ arguments: normalizeMoveArguments(
1336
+ {
1337
+ ...options.arguments,
1338
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
1339
+ config: options.arguments?.config ?? options.config?.protocolConfig,
1340
+ },
1341
+ argumentsTypes,
1342
+ parameterNames,
1343
+ ),
1344
+ });
1345
+ }
1346
+ export interface ClaimParkedArguments {
1347
+ queue: RawTransactionArgument<string>;
1348
+ desk?: RawTransactionArgument<string>;
1349
+ recordId: RawTransactionArgument<number | bigint>;
1350
+ }
1351
+ export interface ClaimParkedOptions {
1352
+ package?: string;
1353
+ arguments: ClaimParkedArguments;
1354
+ config?: {
1355
+ orderDesk: ConfigValue;
1356
+ predictOrdersPackageId?: string;
1357
+ };
1358
+ }
1359
+ /**
1360
+ * Send a finished record's parked funds, change or a refund its receive address
1361
+ * could not take, to that address once a send would go through (`denied` is
1362
+ * false). Permissionless: the funds go only to the record's own receive address.
1363
+ * Emits `RecordFundsClaimed` and returns the amount sent, or returns `0` and
1364
+ * changes nothing for a missing or unfinished record, one with nothing parked, or
1365
+ * an address still denied.
1366
+ */
1367
+ export function claimParked(options: ClaimParkedOptions) {
1368
+ const packageAddress =
1369
+ options.package ??
1370
+ options.config?.predictOrdersPackageId ??
1371
+ '@local-pkg/deepbook_predict_orders';
1372
+ const argumentsTypes = [
1373
+ null,
1374
+ null,
1375
+ 'u64',
1376
+ '0x2::deny_list::DenyList',
1377
+ '0x2::clock::Clock',
1378
+ ] satisfies (string | null)[];
1379
+ const parameterNames = ['queue', 'desk', 'recordId'];
1380
+ return (tx: Transaction) =>
1381
+ tx.moveCall({
1382
+ package: packageAddress,
1383
+ module: 'queue',
1384
+ function: 'claim_parked',
1385
+ arguments: normalizeMoveArguments(
1386
+ {
1387
+ ...options.arguments,
1388
+ desk: options.arguments?.desk ?? options.config?.orderDesk,
1389
+ },
1390
+ argumentsTypes,
1391
+ parameterNames,
1392
+ ),
1393
+ });
1394
+ }