@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
@@ -11,21 +11,42 @@
11
11
  * `pricing::load_live_pricer`; this module owns market flow policy and then passes
12
12
  * loaded `Pricer` snapshots into exposure business logic. Pool-wide PLP accounting
13
13
  * and profit accounting remain outside this module.
14
+ *
15
+ * It also owns the order-flow primitives an order-flow companion package drives.
16
+ * `admit_mint` and `admit_sell` admit one queued order, pin a mint's boundary
17
+ * nodes, record the order's cash need in the market's `OrderFlowLedger`, and issue
18
+ * or advance its `OrderReceipt`. `commit` stores the bounded Pyth price the order
19
+ * fills at, `try_fill` fills or refunds it, `release` takes it out without
20
+ * filling, and `try_pay_settled` pays a queue-held position after settlement. A
21
+ * queued fill never enters the account: its position stays in the receipt.
22
+ * Admission, commit, and fill need an allowlisted companion witness; release and
23
+ * the settled payout need only the receipt. The queue itself, its escrow, its
24
+ * policy, and its events live in the companion.
25
+ *
26
+ * Mainnet USDC is a regulated coin: Sui aborts a transaction that sends it to an
27
+ * address on its deny list, or to anyone while it is globally paused. So the fill,
28
+ * the fee routing, and the settled payout read `sui::deny_list` first and never
29
+ * send to such an address. A fill for a denied receive address is refused, a
30
+ * denied builder or referrer's fee stays in market cash, and a denied winner's
31
+ * payout is skipped for a later `try_pay_settled`.
14
32
  */
15
33
 
16
34
  import {
17
35
  MoveStruct,
36
+ MoveTuple,
18
37
  normalizeMoveArguments,
19
38
  type RawTransactionArgument,
20
39
  type ConfigValue,
21
40
  } from '../utils/index.js';
22
- import { U64 } from '../../bcs/integers.js';
23
- import { bcs } from '@mysten/sui/bcs';
41
+ import { U64, U256 } from '../../bcs/integers.js';
42
+ import { bcs, type BcsType } from '@mysten/sui/bcs';
24
43
  import { type Transaction, type TransactionArgument } from '@mysten/sui/transactions';
25
44
  import * as expiry_cash from './expiry_cash.js';
26
45
  import * as balance from './deps/sui/balance.js';
27
46
  import * as strike_exposure from './strike_exposure.js';
28
47
  import * as ewma from './ewma.js';
48
+ import * as pricing from './pricing.js';
49
+ import * as vec_map from './deps/sui/vec_map.js';
29
50
  const $moduleName = '@local-pkg/deepbook_predict::expiry_market';
30
51
  export const ValuationStamp = new MoveStruct({
31
52
  name: `${$moduleName}::ValuationStamp`,
@@ -82,6 +103,106 @@ export const MintQuote = new MoveStruct({
82
103
  all_in_cost: U64,
83
104
  },
84
105
  });
106
+ export const RedeemQuote = new MoveStruct({
107
+ name: `${$moduleName}::RedeemQuote`,
108
+ fields: {
109
+ close_quantity: U64,
110
+ probability: U64,
111
+ proceeds: U64,
112
+ trading_fee: U64,
113
+ builder_fee: U64,
114
+ inventory_impact_rebate: U64,
115
+ },
116
+ });
117
+ export const OrderParties = new MoveStruct({
118
+ name: `${$moduleName}::OrderParties`,
119
+ fields: {
120
+ account_id: bcs.Address,
121
+ owner: bcs.Address,
122
+ /** Sell proceeds and the settled payout go only here. */
123
+ receive_address: bcs.Address,
124
+ referrer_account_id: bcs.option(bcs.Address),
125
+ referrer_receive_address: bcs.option(bcs.Address),
126
+ builder_code_id: bcs.option(bcs.Address),
127
+ },
128
+ });
129
+ export const OrderReceipt = new MoveStruct({
130
+ name: `${$moduleName}::OrderReceipt`,
131
+ fields: {
132
+ expiry_market_id: bcs.Address,
133
+ stage: bcs.u8(),
134
+ /** A `constants` mint kind, or `order_kind_sell` once a sell is admitted. */
135
+ kind: bcs.u8(),
136
+ /** The account's snapshot at the last admission. */
137
+ parties: OrderParties,
138
+ lower_tick: U64,
139
+ higher_tick: U64,
140
+ /** The exact mint quantity, or the sell's close quantity. */
141
+ quantity: U64,
142
+ max_premium: U64,
143
+ min_quantity: U64,
144
+ max_probability: U64,
145
+ min_probability: U64,
146
+ min_proceeds: U64,
147
+ /** Earliest Pyth generation time the order may price at. */
148
+ tau_ms: U64,
149
+ /** At or past it the order is refunded, never filled. */
150
+ deadline_ms: U64,
151
+ /** The Lazer channel τ was planned on; the committed price must come from it. */
152
+ channel: bcs.u8(),
153
+ vol: pricing.VolSnapshot,
154
+ budget: U64,
155
+ order_fee: U64,
156
+ /**
157
+ * Worst-case market cash the fill can consume. Counted in the ledger's
158
+ * `waiting_cash_need` while the order is admitted.
159
+ */
160
+ cash_need: U64,
161
+ /**
162
+ * The t₀ quote's pre-subsidy trading fee, capped at `budget`. Bounds the subsidy
163
+ * `commit` reserves.
164
+ */
165
+ subsidy_bound: U64,
166
+ subsidy_rate: U64,
167
+ subsidy_reserved: U64,
168
+ /** The committed Pyth price, 1e9-normalized; `0` until `commit`. */
169
+ spot: U64,
170
+ /** The committed update's envelope, in ms. The fill prices at it. */
171
+ tick_ms: U64,
172
+ /** The committed feed's own update time, in µs. */
173
+ generation_us: U64,
174
+ /** The open position's order ID; `0` until the mint fills. */
175
+ order_id: U256,
176
+ /** Stable economic-position handle, constant across partial closes. */
177
+ root_id: U256,
178
+ opened_at_ms: U64,
179
+ /**
180
+ * The open position's size, the quantity `order_id` names. The request's
181
+ * `quantity` is the mint or close quantity, so a sell admission never overwrites
182
+ * the size it closes.
183
+ */
184
+ held_quantity: U64,
185
+ },
186
+ });
187
+ export const OrderFlowLedgerKey = new MoveTuple({
188
+ name: `${$moduleName}::OrderFlowLedgerKey`,
189
+ fields: [bcs.bool()],
190
+ });
191
+ export const OrderFlowLedger = new MoveStruct({
192
+ name: `${$moduleName}::OrderFlowLedger`,
193
+ fields: {
194
+ /**
195
+ * Admitted mints per payout-tree tick (tick -> count). A pinned node is never
196
+ * pruned, so a fill never creates one.
197
+ */
198
+ pins: vec_map.VecMap(U64, U64),
199
+ /**
200
+ * Sum of the admitted orders' cash needs. `rebalance_expiry_cash` funds a live
201
+ * market to at least required cash plus this.
202
+ */
203
+ waiting_cash_need: U64,
204
+ },
205
+ });
85
206
  export interface IdArguments {
86
207
  market: RawTransactionArgument<string>;
87
208
  }
@@ -811,12 +932,14 @@ export interface QuoteMintOptions {
811
932
  };
812
933
  }
813
934
  /**
814
- * Quote the all-in cost of a mint request for an anonymous taker (no builder code)
815
- * without mutating any market state. Exact-quantity mode uses `min_quantity`;
816
- * budget mode conservatively sizes a lot-rounded fill under `max_premium`. The
817
- * quote applies live-mint and admission gates but does not preflight account
818
- * balance, slippage caps, or exposure-index capacity. Its penalty uses the current
819
- * pre-update EWMA state. Public for SDK and devInspect pre-trade pricing.
935
+ * Quote a prospective mint at a market-bound `Pricer`, priced like a queued fill
936
+ * at the clock, for SDK and devInspect previews. `exact_quantity` quotes
937
+ * `min_quantity` exactly; otherwise the largest quantity whose premium fits
938
+ * `max_premium`, at least `min_quantity`. No builder fee. The fee subsidy is the
939
+ * configured rate capped by the market's incentive balance, and `penalty_fee` is
940
+ * always 0. Gated only on the pricer binding (`EWrongPricer`) and `now < expiry`
941
+ * (`EInvalidOrderTiming`). Aborts `EOrderFailsLimits` when the mint would be
942
+ * refused at the clock.
820
943
  */
821
944
  export function quoteMint(options: QuoteMintOptions) {
822
945
  const packageAddress =
@@ -877,9 +1000,8 @@ export interface QuoteMintForAccountOptions {
877
1000
  };
878
1001
  }
879
1002
  /**
880
- * Quote the all-in cost of a mint request for one account, reading its builder
881
- * code. Budget mode caps premium by total account balance, including unsettled
882
- * accumulator funds. Public for SDK and devInspect pre-trade pricing.
1003
+ * `quote_mint` for the wrapper's account: `max_premium` is capped at the account's
1004
+ * balance and the account's builder fee is charged.
883
1005
  */
884
1006
  export function quoteMintForAccount(options: QuoteMintForAccountOptions) {
885
1007
  const packageAddress =
@@ -942,13 +1064,10 @@ export interface QuoteMintExactCostForAccountOptions {
942
1064
  };
943
1065
  }
944
1066
  /**
945
- * Quote `mint_exact_cost` for one account: the fill that mint would size for
946
- * `max_cost`, capped by total account balance including unsettled accumulator
947
- * funds, with that fill's cost decomposition. Applies the mint's live-mint gates,
948
- * sizing, `min_quantity` floor, and admission, but does not preflight
949
- * exposure-index capacity or cash backing. `quantity` is the figure to derive a
950
- * `min_quantity` slippage floor from. Public for SDK and devInspect pre-trade
951
- * pricing.
1067
+ * Quote the largest mint whose all-in cost fits `min(max_cost, account balance)`,
1068
+ * at least `min_quantity`, for the wrapper's account, priced like a queued
1069
+ * exact-cost fill at the clock. Charges the account's builder fee, and otherwise
1070
+ * prices and gates like `quote_mint`.
952
1071
  */
953
1072
  export function quoteMintExactCostForAccount(options: QuoteMintExactCostForAccountOptions) {
954
1073
  const packageAddress =
@@ -990,6 +1109,66 @@ export function quoteMintExactCostForAccount(options: QuoteMintExactCostForAccou
990
1109
  ),
991
1110
  });
992
1111
  }
1112
+ export interface OrderFlowStateArguments {
1113
+ market: RawTransactionArgument<string>;
1114
+ }
1115
+ export interface OrderFlowStateOptions {
1116
+ package?: string;
1117
+ arguments: OrderFlowStateArguments | [market: RawTransactionArgument<string>];
1118
+ config?: {
1119
+ predictPackageId?: string;
1120
+ };
1121
+ }
1122
+ /**
1123
+ * Return `(waiting_cash_need, payout_tree_node_count, min_entry_probability)`: the
1124
+ * summed cash need of the market's admitted orders, above required cash, that
1125
+ * `rebalance_expiry_cash` keeps a live market funded with; the payout tree's node
1126
+ * count, pinned zero nodes included, which sizes the keeper's fill batches; and
1127
+ * the snapshotted minimum entry probability the SDK computes a queued mint's cash
1128
+ * need from. For SDK, keeper, and devInspect reads.
1129
+ */
1130
+ export function orderFlowState(options: OrderFlowStateOptions) {
1131
+ const packageAddress =
1132
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
1133
+ const argumentsTypes = [null] satisfies (string | null)[];
1134
+ const parameterNames = ['market'];
1135
+ return (tx: Transaction) =>
1136
+ tx.moveCall({
1137
+ package: packageAddress,
1138
+ module: 'expiry_market',
1139
+ function: 'order_flow_state',
1140
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1141
+ });
1142
+ }
1143
+ export interface ReceiptInfoArguments {
1144
+ receipt: TransactionArgument;
1145
+ }
1146
+ export interface ReceiptInfoOptions {
1147
+ package?: string;
1148
+ arguments: ReceiptInfoArguments | [receipt: TransactionArgument];
1149
+ config?: {
1150
+ predictPackageId?: string;
1151
+ };
1152
+ }
1153
+ /**
1154
+ * Return a receipt's
1155
+ * `(expiry_market_id, stage, account_id, order_id, pyth_source_id, cash_need, subsidy_bound, vol)`.
1156
+ * For the order-flow companion's queue events and Lazer decoding, and devInspect
1157
+ * reads of queue records.
1158
+ */
1159
+ export function receiptInfo(options: ReceiptInfoOptions) {
1160
+ const packageAddress =
1161
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
1162
+ const argumentsTypes = [null] satisfies (string | null)[];
1163
+ const parameterNames = ['receipt'];
1164
+ return (tx: Transaction) =>
1165
+ tx.moveCall({
1166
+ package: packageAddress,
1167
+ module: 'expiry_market',
1168
+ function: 'receipt_info',
1169
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1170
+ });
1171
+ }
993
1172
  export interface QuantityArguments {
994
1173
  quote: TransactionArgument;
995
1174
  }
@@ -1212,17 +1391,207 @@ export function allInCost(options: AllInCostOptions) {
1212
1391
  arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1213
1392
  });
1214
1393
  }
1215
- export interface MintExactQuantityArguments {
1394
+ export interface RedeemCloseQuantityArguments {
1395
+ quote: TransactionArgument;
1396
+ }
1397
+ export interface RedeemCloseQuantityOptions {
1398
+ package?: string;
1399
+ arguments: RedeemCloseQuantityArguments | [quote: TransactionArgument];
1400
+ config?: {
1401
+ predictPackageId?: string;
1402
+ };
1403
+ }
1404
+ export function redeemCloseQuantity(options: RedeemCloseQuantityOptions) {
1405
+ const packageAddress =
1406
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
1407
+ const argumentsTypes = [null] satisfies (string | null)[];
1408
+ const parameterNames = ['quote'];
1409
+ return (tx: Transaction) =>
1410
+ tx.moveCall({
1411
+ package: packageAddress,
1412
+ module: 'expiry_market',
1413
+ function: 'redeem_close_quantity',
1414
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1415
+ });
1416
+ }
1417
+ export interface RedeemProbabilityArguments {
1418
+ quote: TransactionArgument;
1419
+ }
1420
+ export interface RedeemProbabilityOptions {
1421
+ package?: string;
1422
+ arguments: RedeemProbabilityArguments | [quote: TransactionArgument];
1423
+ config?: {
1424
+ predictPackageId?: string;
1425
+ };
1426
+ }
1427
+ export function redeemProbability(options: RedeemProbabilityOptions) {
1428
+ const packageAddress =
1429
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
1430
+ const argumentsTypes = [null] satisfies (string | null)[];
1431
+ const parameterNames = ['quote'];
1432
+ return (tx: Transaction) =>
1433
+ tx.moveCall({
1434
+ package: packageAddress,
1435
+ module: 'expiry_market',
1436
+ function: 'redeem_probability',
1437
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1438
+ });
1439
+ }
1440
+ export interface RedeemProceedsArguments {
1441
+ quote: TransactionArgument;
1442
+ }
1443
+ export interface RedeemProceedsOptions {
1444
+ package?: string;
1445
+ arguments: RedeemProceedsArguments | [quote: TransactionArgument];
1446
+ config?: {
1447
+ predictPackageId?: string;
1448
+ };
1449
+ }
1450
+ export function redeemProceeds(options: RedeemProceedsOptions) {
1451
+ const packageAddress =
1452
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
1453
+ const argumentsTypes = [null] satisfies (string | null)[];
1454
+ const parameterNames = ['quote'];
1455
+ return (tx: Transaction) =>
1456
+ tx.moveCall({
1457
+ package: packageAddress,
1458
+ module: 'expiry_market',
1459
+ function: 'redeem_proceeds',
1460
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1461
+ });
1462
+ }
1463
+ export interface RedeemTradingFeeArguments {
1464
+ quote: TransactionArgument;
1465
+ }
1466
+ export interface RedeemTradingFeeOptions {
1467
+ package?: string;
1468
+ arguments: RedeemTradingFeeArguments | [quote: TransactionArgument];
1469
+ config?: {
1470
+ predictPackageId?: string;
1471
+ };
1472
+ }
1473
+ export function redeemTradingFee(options: RedeemTradingFeeOptions) {
1474
+ const packageAddress =
1475
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
1476
+ const argumentsTypes = [null] satisfies (string | null)[];
1477
+ const parameterNames = ['quote'];
1478
+ return (tx: Transaction) =>
1479
+ tx.moveCall({
1480
+ package: packageAddress,
1481
+ module: 'expiry_market',
1482
+ function: 'redeem_trading_fee',
1483
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1484
+ });
1485
+ }
1486
+ export interface RedeemBuilderFeeArguments {
1487
+ quote: TransactionArgument;
1488
+ }
1489
+ export interface RedeemBuilderFeeOptions {
1490
+ package?: string;
1491
+ arguments: RedeemBuilderFeeArguments | [quote: TransactionArgument];
1492
+ config?: {
1493
+ predictPackageId?: string;
1494
+ };
1495
+ }
1496
+ export function redeemBuilderFee(options: RedeemBuilderFeeOptions) {
1497
+ const packageAddress =
1498
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
1499
+ const argumentsTypes = [null] satisfies (string | null)[];
1500
+ const parameterNames = ['quote'];
1501
+ return (tx: Transaction) =>
1502
+ tx.moveCall({
1503
+ package: packageAddress,
1504
+ module: 'expiry_market',
1505
+ function: 'redeem_builder_fee',
1506
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1507
+ });
1508
+ }
1509
+ export interface RedeemInventoryImpactRebateArguments {
1510
+ quote: TransactionArgument;
1511
+ }
1512
+ export interface RedeemInventoryImpactRebateOptions {
1513
+ package?: string;
1514
+ arguments: RedeemInventoryImpactRebateArguments | [quote: TransactionArgument];
1515
+ config?: {
1516
+ predictPackageId?: string;
1517
+ };
1518
+ }
1519
+ export function redeemInventoryImpactRebate(options: RedeemInventoryImpactRebateOptions) {
1520
+ const packageAddress =
1521
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
1522
+ const argumentsTypes = [null] satisfies (string | null)[];
1523
+ const parameterNames = ['quote'];
1524
+ return (tx: Transaction) =>
1525
+ tx.moveCall({
1526
+ package: packageAddress,
1527
+ module: 'expiry_market',
1528
+ function: 'redeem_inventory_impact_rebate',
1529
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1530
+ });
1531
+ }
1532
+ export interface QuoteCloseArguments {
1216
1533
  market: RawTransactionArgument<string>;
1217
- wrapper: RawTransactionArgument<string>;
1218
- auth: TransactionArgument;
1219
- config?: RawTransactionArgument<string>;
1220
1534
  pricer: TransactionArgument;
1221
- lowerTick: RawTransactionArgument<number | bigint>;
1222
- higherTick: RawTransactionArgument<number | bigint>;
1223
- quantity: RawTransactionArgument<number | bigint>;
1224
- maxCost: RawTransactionArgument<number | bigint>;
1225
- maxProbability: RawTransactionArgument<number | bigint>;
1535
+ receipt: TransactionArgument;
1536
+ closeQuantity: RawTransactionArgument<number | bigint>;
1537
+ builderCodeId: RawTransactionArgument<string | null>;
1538
+ }
1539
+ export interface QuoteCloseOptions {
1540
+ package?: string;
1541
+ arguments:
1542
+ | QuoteCloseArguments
1543
+ | [
1544
+ market: RawTransactionArgument<string>,
1545
+ pricer: TransactionArgument,
1546
+ receipt: TransactionArgument,
1547
+ closeQuantity: RawTransactionArgument<number | bigint>,
1548
+ builderCodeId: RawTransactionArgument<string | null>,
1549
+ ];
1550
+ config?: {
1551
+ predictPackageId?: string;
1552
+ };
1553
+ }
1554
+ /**
1555
+ * Quote an early sell of `close_quantity` of an open receipt's position at a
1556
+ * market-bound `Pricer` and the clock, charging `builder_code_id`'s builder fee:
1557
+ * the close a sell fill prices, without the trader's floors. `proceeds` is before
1558
+ * the order fee. Changes nothing. Aborts on the pricer binding (`EWrongPricer`),
1559
+ * another market's receipt (`EWrongMarket`), a receipt that is not open
1560
+ * (`EWrongStage`), `now >= expiry` (`EInvalidOrderTiming`), or a close that cannot
1561
+ * be priced (`EOrderFailsLimits`). Public for the order-flow companion's sell
1562
+ * preview and SDK reads.
1563
+ */
1564
+ export function quoteClose(options: QuoteCloseOptions) {
1565
+ const packageAddress =
1566
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
1567
+ const argumentsTypes = [
1568
+ null,
1569
+ null,
1570
+ null,
1571
+ 'u64',
1572
+ '0x1::option::Option<0x2::object::ID>',
1573
+ '0x2::clock::Clock',
1574
+ ] satisfies (string | null)[];
1575
+ const parameterNames = ['market', 'pricer', 'receipt', 'closeQuantity', 'builderCodeId'];
1576
+ return (tx: Transaction) =>
1577
+ tx.moveCall({
1578
+ package: packageAddress,
1579
+ module: 'expiry_market',
1580
+ function: 'quote_close',
1581
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
1582
+ });
1583
+ }
1584
+ export interface MintExactQuantityArguments {
1585
+ Market: RawTransactionArgument<string>;
1586
+ Wrapper: RawTransactionArgument<string>;
1587
+ Auth: TransactionArgument;
1588
+ Config?: RawTransactionArgument<string>;
1589
+ Pricer: TransactionArgument;
1590
+ LowerTick: RawTransactionArgument<number | bigint>;
1591
+ HigherTick: RawTransactionArgument<number | bigint>;
1592
+ Quantity: RawTransactionArgument<number | bigint>;
1593
+ MaxCost: RawTransactionArgument<number | bigint>;
1594
+ MaxProbability: RawTransactionArgument<number | bigint>;
1226
1595
  }
1227
1596
  export interface MintExactQuantityOptions {
1228
1597
  package?: string;
@@ -1233,19 +1602,8 @@ export interface MintExactQuantityOptions {
1233
1602
  };
1234
1603
  }
1235
1604
  /**
1236
- * Mint an exact live position quantity against this expiry market.
1237
- *
1238
- * Requires the running package version to be at or above the protocol version
1239
- * watermark, per-market mint pause to be off, trading globally enabled, valid
1240
- * owner or authorized-app account auth, a market-bound live `Pricer`, and enough
1241
- * expiry cash to back the post-mint max payout. Mint fees are paid by routing a
1242
- * withdraw through the loaded account. The position's strike range is the tick
1243
- * pair `(lower_tick, higher_tick]` (`lower_tick = 0` is `-inf`,
1244
- * `higher_tick = pos_inf_tick` is `+inf`); the SDK converts raw strikes to ticks.
1245
- * `max_cost` caps the all-in USDC withdrawal, while `max_probability` caps the
1246
- * quoted per-contract probability before fees. Callers can pass
1247
- * `std::u64::max_value!()` for either uncapped guard. Returns the minted order ID
1248
- * for future order-scoped flows.
1605
+ * Retired by delayed execution: always aborts `EDelayedExecutionRequired`. Mints
1606
+ * are queued through the order-flow companion.
1249
1607
  */
1250
1608
  export function mintExactQuantity(options: MintExactQuantityOptions) {
1251
1609
  const packageAddress =
@@ -1265,16 +1623,16 @@ export function mintExactQuantity(options: MintExactQuantityOptions) {
1265
1623
  '0x2::clock::Clock',
1266
1624
  ] satisfies (string | null)[];
1267
1625
  const parameterNames = [
1268
- 'market',
1269
- 'wrapper',
1270
- 'auth',
1271
- 'config',
1272
- 'pricer',
1273
- 'lowerTick',
1274
- 'higherTick',
1275
- 'quantity',
1276
- 'maxCost',
1277
- 'maxProbability',
1626
+ 'Market',
1627
+ 'Wrapper',
1628
+ 'Auth',
1629
+ 'Config',
1630
+ 'Pricer',
1631
+ 'LowerTick',
1632
+ 'HigherTick',
1633
+ 'Quantity',
1634
+ 'MaxCost',
1635
+ 'MaxProbability',
1278
1636
  ];
1279
1637
  return (tx: Transaction) =>
1280
1638
  tx.moveCall({
@@ -1284,7 +1642,7 @@ export function mintExactQuantity(options: MintExactQuantityOptions) {
1284
1642
  arguments: normalizeMoveArguments(
1285
1643
  {
1286
1644
  ...options.arguments,
1287
- config: options.arguments?.config ?? options.config?.protocolConfig,
1645
+ Config: options.arguments?.Config ?? options.config?.protocolConfig,
1288
1646
  },
1289
1647
  argumentsTypes,
1290
1648
  parameterNames,
@@ -1292,16 +1650,16 @@ export function mintExactQuantity(options: MintExactQuantityOptions) {
1292
1650
  });
1293
1651
  }
1294
1652
  export interface MintExactAmountArguments {
1295
- market: RawTransactionArgument<string>;
1296
- wrapper: RawTransactionArgument<string>;
1297
- auth: TransactionArgument;
1298
- config?: RawTransactionArgument<string>;
1299
- pricer: TransactionArgument;
1300
- lowerTick: RawTransactionArgument<number | bigint>;
1301
- higherTick: RawTransactionArgument<number | bigint>;
1302
- maxPremium: RawTransactionArgument<number | bigint>;
1303
- minQuantity: RawTransactionArgument<number | bigint>;
1304
- maxCost: RawTransactionArgument<number | bigint>;
1653
+ Market: RawTransactionArgument<string>;
1654
+ Wrapper: RawTransactionArgument<string>;
1655
+ Auth: TransactionArgument;
1656
+ Config?: RawTransactionArgument<string>;
1657
+ Pricer: TransactionArgument;
1658
+ LowerTick: RawTransactionArgument<number | bigint>;
1659
+ HigherTick: RawTransactionArgument<number | bigint>;
1660
+ MaxPremium: RawTransactionArgument<number | bigint>;
1661
+ MinQuantity: RawTransactionArgument<number | bigint>;
1662
+ MaxCost: RawTransactionArgument<number | bigint>;
1305
1663
  }
1306
1664
  export interface MintExactAmountOptions {
1307
1665
  package?: string;
@@ -1312,19 +1670,8 @@ export interface MintExactAmountOptions {
1312
1670
  };
1313
1671
  }
1314
1672
  /**
1315
- * Mint a conservatively sized lot-rounded position whose premium does not exceed
1316
- * `max_premium`. The result may be one lot below the largest fitting quantity and
1317
- * must meet `min_quantity`.
1318
- *
1319
- * Fees, builder fees, and EWMA congestion penalties are charged on top of
1320
- * `max_premium`, so `max_cost` — not `max_premium` — bounds the all-in USDC
1321
- * withdrawal (`premium + trader-paid fee + builder_fee + EWMA penalty`).
1322
- * `max_cost` is required: unlike `mint_exact_quantity`'s guards there is no value
1323
- * that disables it, because the budget shape exists to bound spend. The sizing
1324
- * budget is first capped to the account's available USDC after settlement; fees
1325
- * still require additional available USDC at payment time. Any unspent premium
1326
- * dust remains in the account because order quantity must be an integer number of
1327
- * `position_lot_size` lots.
1673
+ * Retired by delayed execution: always aborts `EDelayedExecutionRequired`. Mints
1674
+ * are queued through the order-flow companion.
1328
1675
  */
1329
1676
  export function mintExactAmount(options: MintExactAmountOptions) {
1330
1677
  const packageAddress =
@@ -1344,16 +1691,16 @@ export function mintExactAmount(options: MintExactAmountOptions) {
1344
1691
  '0x2::clock::Clock',
1345
1692
  ] satisfies (string | null)[];
1346
1693
  const parameterNames = [
1347
- 'market',
1348
- 'wrapper',
1349
- 'auth',
1350
- 'config',
1351
- 'pricer',
1352
- 'lowerTick',
1353
- 'higherTick',
1354
- 'maxPremium',
1355
- 'minQuantity',
1356
- 'maxCost',
1694
+ 'Market',
1695
+ 'Wrapper',
1696
+ 'Auth',
1697
+ 'Config',
1698
+ 'Pricer',
1699
+ 'LowerTick',
1700
+ 'HigherTick',
1701
+ 'MaxPremium',
1702
+ 'MinQuantity',
1703
+ 'MaxCost',
1357
1704
  ];
1358
1705
  return (tx: Transaction) =>
1359
1706
  tx.moveCall({
@@ -1363,7 +1710,7 @@ export function mintExactAmount(options: MintExactAmountOptions) {
1363
1710
  arguments: normalizeMoveArguments(
1364
1711
  {
1365
1712
  ...options.arguments,
1366
- config: options.arguments?.config ?? options.config?.protocolConfig,
1713
+ Config: options.arguments?.Config ?? options.config?.protocolConfig,
1367
1714
  },
1368
1715
  argumentsTypes,
1369
1716
  parameterNames,
@@ -1371,15 +1718,15 @@ export function mintExactAmount(options: MintExactAmountOptions) {
1371
1718
  });
1372
1719
  }
1373
1720
  export interface MintExactCostArguments {
1374
- market: RawTransactionArgument<string>;
1375
- wrapper: RawTransactionArgument<string>;
1376
- auth: TransactionArgument;
1377
- config?: RawTransactionArgument<string>;
1378
- pricer: TransactionArgument;
1379
- lowerTick: RawTransactionArgument<number | bigint>;
1380
- higherTick: RawTransactionArgument<number | bigint>;
1381
- maxCost: RawTransactionArgument<number | bigint>;
1382
- minQuantity: RawTransactionArgument<number | bigint>;
1721
+ Market: RawTransactionArgument<string>;
1722
+ Wrapper: RawTransactionArgument<string>;
1723
+ Auth: TransactionArgument;
1724
+ Config?: RawTransactionArgument<string>;
1725
+ Pricer: TransactionArgument;
1726
+ LowerTick: RawTransactionArgument<number | bigint>;
1727
+ HigherTick: RawTransactionArgument<number | bigint>;
1728
+ MaxCost: RawTransactionArgument<number | bigint>;
1729
+ MinQuantity: RawTransactionArgument<number | bigint>;
1383
1730
  }
1384
1731
  export interface MintExactCostOptions {
1385
1732
  package?: string;
@@ -1390,36 +1737,8 @@ export interface MintExactCostOptions {
1390
1737
  };
1391
1738
  }
1392
1739
  /**
1393
- * Mint a lot-rounded position within an all-in `max_cost` budget.
1394
- *
1395
- * Unlike `mint_exact_amount`, fees are sized inside the budget: the quantity
1396
- * search evaluates the all-in withdrawal the mint charges
1397
- * (`premium + trader-paid fee + builder_fee + EWMA penalty + inventory_impact_charge`)
1398
- * against the fee-incentive, congestion, and book state at execution, so the debit
1399
- * never exceeds `max_cost`. `max_cost` is first capped to the account's available
1400
- * USDC after settlement, so `std::u64::max_value!()` sizes against the whole
1401
- * balance.
1402
- *
1403
- * The budget search finds the largest fitting quantity. If that quantity costs
1404
- * more than its maximum payout, a conservative search tries a smaller fill;
1405
- * rounding can make that fallback miss a larger admissible fill. Only when the
1406
- * budget is the limiting constraint is the remainder less than the incremental
1407
- * all-in cost of one more lot. Payout-limited fills and lot-cap saturation can
1408
- * leave more. Insufficient expiry cash backing aborts the mint; sizing does not
1409
- * shrink the fill to available backing, and the quote does not preflight it.
1410
- *
1411
- * `min_quantity` is this entrypoint's slippage guard. The budget is fixed, so
1412
- * every adverse move between building the transaction and executing it — the
1413
- * price, the congestion surcharge, the sponsor subsidy, the inventory-impact
1414
- * charge — shows up as fewer contracts, and a fill below `min_quantity` aborts
1415
- * `EMintQuantityBelowMin`. It bounds the all-in price per contract at
1416
- * `max_cost / min_quantity`, which is why the shape carries no separate
1417
- * probability cap; passing `0` accepts any fill the budget buys. A budget too
1418
- * small to admit `constants::min_premium` aborts `EPremiumBelowMinimum` rather
1419
- * than minting nothing, and zero is such a budget: unlike `mint_exact_amount`
1420
- * there is no `max_cost` cap to require, because here the budget IS the sizing
1421
- * input. Other requirements match `mint_exact_quantity`. Returns the minted order
1422
- * ID.
1740
+ * Retired by delayed execution: always aborts `EDelayedExecutionRequired`. Mints
1741
+ * are queued through the order-flow companion.
1423
1742
  */
1424
1743
  export function mintExactCost(options: MintExactCostOptions) {
1425
1744
  const packageAddress =
@@ -1438,15 +1757,15 @@ export function mintExactCost(options: MintExactCostOptions) {
1438
1757
  '0x2::clock::Clock',
1439
1758
  ] satisfies (string | null)[];
1440
1759
  const parameterNames = [
1441
- 'market',
1442
- 'wrapper',
1443
- 'auth',
1444
- 'config',
1445
- 'pricer',
1446
- 'lowerTick',
1447
- 'higherTick',
1448
- 'maxCost',
1449
- 'minQuantity',
1760
+ 'Market',
1761
+ 'Wrapper',
1762
+ 'Auth',
1763
+ 'Config',
1764
+ 'Pricer',
1765
+ 'LowerTick',
1766
+ 'HigherTick',
1767
+ 'MaxCost',
1768
+ 'MinQuantity',
1450
1769
  ];
1451
1770
  return (tx: Transaction) =>
1452
1771
  tx.moveCall({
@@ -1456,7 +1775,7 @@ export function mintExactCost(options: MintExactCostOptions) {
1456
1775
  arguments: normalizeMoveArguments(
1457
1776
  {
1458
1777
  ...options.arguments,
1459
- config: options.arguments?.config ?? options.config?.protocolConfig,
1778
+ Config: options.arguments?.Config ?? options.config?.protocolConfig,
1460
1779
  },
1461
1780
  argumentsTypes,
1462
1781
  parameterNames,
@@ -1464,15 +1783,15 @@ export function mintExactCost(options: MintExactCostOptions) {
1464
1783
  });
1465
1784
  }
1466
1785
  export interface RedeemLiveArguments {
1467
- market: RawTransactionArgument<string>;
1468
- wrapper: RawTransactionArgument<string>;
1469
- auth: TransactionArgument;
1470
- config?: RawTransactionArgument<string>;
1471
- pricer: TransactionArgument;
1472
- orderId: RawTransactionArgument<number | bigint>;
1473
- closeQuantity: RawTransactionArgument<number | bigint>;
1474
- minProbability: RawTransactionArgument<number | bigint>;
1475
- minProceeds: RawTransactionArgument<number | bigint>;
1786
+ Market: RawTransactionArgument<string>;
1787
+ Wrapper: RawTransactionArgument<string>;
1788
+ Auth: TransactionArgument;
1789
+ Config?: RawTransactionArgument<string>;
1790
+ Pricer: TransactionArgument;
1791
+ OrderId: RawTransactionArgument<number | bigint>;
1792
+ CloseQuantity: RawTransactionArgument<number | bigint>;
1793
+ MinProbability: RawTransactionArgument<number | bigint>;
1794
+ MinProceeds: RawTransactionArgument<number | bigint>;
1476
1795
  }
1477
1796
  export interface RedeemLiveOptions {
1478
1797
  package?: string;
@@ -1483,18 +1802,9 @@ export interface RedeemLiveOptions {
1483
1802
  };
1484
1803
  }
1485
1804
  /**
1486
- * Redeem a live order you hold account authority over.
1487
- *
1488
- * A live order is priced and closed (partial or full). Settled orders must use
1489
- * `redeem_settled`. Returns a replacement order ID only when a partial close
1490
- * leaves quantity open.
1491
- *
1492
- * Two close-side slippage floors, the mirror of mint's `max_probability` /
1493
- * `max_cost` pair; pass `0` to disable either. `min_probability` floors the quoted
1494
- * per-contract range probability (same units as mint's `max_probability`).
1495
- * `min_proceeds` floors the all-in net USDC credited to the account
1496
- * (`redeem_amount` minus trading fee, builder fee, and EWMA penalty), the mirror
1497
- * of mint's all-in `max_cost`.
1805
+ * Retired by delayed execution: always aborts `EDelayedExecutionRequired`. Early
1806
+ * sells of queue-held positions go through the order-flow companion; account-held
1807
+ * positions exit through `redeem_settled` after settlement.
1498
1808
  */
1499
1809
  export function redeemLive(options: RedeemLiveOptions) {
1500
1810
  const packageAddress =
@@ -1513,15 +1823,15 @@ export function redeemLive(options: RedeemLiveOptions) {
1513
1823
  '0x2::clock::Clock',
1514
1824
  ] satisfies (string | null)[];
1515
1825
  const parameterNames = [
1516
- 'market',
1517
- 'wrapper',
1518
- 'auth',
1519
- 'config',
1520
- 'pricer',
1521
- 'orderId',
1522
- 'closeQuantity',
1523
- 'minProbability',
1524
- 'minProceeds',
1826
+ 'Market',
1827
+ 'Wrapper',
1828
+ 'Auth',
1829
+ 'Config',
1830
+ 'Pricer',
1831
+ 'OrderId',
1832
+ 'CloseQuantity',
1833
+ 'MinProbability',
1834
+ 'MinProceeds',
1525
1835
  ];
1526
1836
  return (tx: Transaction) =>
1527
1837
  tx.moveCall({
@@ -1531,7 +1841,7 @@ export function redeemLive(options: RedeemLiveOptions) {
1531
1841
  arguments: normalizeMoveArguments(
1532
1842
  {
1533
1843
  ...options.arguments,
1534
- config: options.arguments?.config ?? options.config?.protocolConfig,
1844
+ Config: options.arguments?.Config ?? options.config?.protocolConfig,
1535
1845
  },
1536
1846
  argumentsTypes,
1537
1847
  parameterNames,
@@ -1604,11 +1914,15 @@ export interface RedeemSettledPermissionlessOptions {
1604
1914
  };
1605
1915
  }
1606
1916
  /**
1607
- * Permissionlessly redeem a settled order without account-owner authority.
1917
+ * Redeem a settled order without account-owner authority, as an allowlisted
1918
+ * keeper.
1608
1919
  *
1609
- * This keeper path uses Predict app-auth from the account registry, so
1610
- * `deauthorize_app<PredictApp>` disables this automation. Owners can still use
1611
- * `redeem_settled` with owner auth to redeem their own settled positions.
1920
+ * Despite the name, only a sender admin has added through
1921
+ * `protocol_config::add_settled_redeem_keeper` may call this; the allowlist starts
1922
+ * empty. The payout still goes to the order's account. This keeper path uses
1923
+ * Predict app-auth from the account registry, so `deauthorize_app<PredictApp>`
1924
+ * also disables it. Owners can still use `redeem_settled` with owner auth to
1925
+ * redeem their own settled positions.
1612
1926
  */
1613
1927
  export function redeemSettledPermissionless(options: RedeemSettledPermissionlessOptions) {
1614
1928
  const packageAddress =
@@ -1742,6 +2056,12 @@ export interface TrySettleOptions {
1742
2056
  * Block Scholes minute-boundary spot when Pyth remains unavailable after the
1743
2057
  * compiled grace period. Permissionless and idempotent; missing or unusable
1744
2058
  * observations leave the market unsettled.
2059
+ *
2060
+ * Settlement reads nothing from the order-flow queue. Every admission's deadline
2061
+ * is at least `constants::deadline_expiry_margin_ms!()` before expiry, so at
2062
+ * expiry a waiting order can only be released, and the settled liability already
2063
+ * covers every queue-held position, which lives in the payout tree. The companion
2064
+ * drains and pays its queue afterwards.
1745
2065
  */
1746
2066
  export function trySettle(options: TrySettleOptions) {
1747
2067
  const packageAddress =
@@ -1766,3 +2086,474 @@ export function trySettle(options: TrySettleOptions) {
1766
2086
  ),
1767
2087
  });
1768
2088
  }
2089
+ export interface AdmitMintArguments<W extends BcsType<any>> {
2090
+ W: RawTransactionArgument<W>;
2091
+ market: RawTransactionArgument<string>;
2092
+ config?: RawTransactionArgument<string>;
2093
+ account: TransactionArgument;
2094
+ propbookRegistry?: RawTransactionArgument<string>;
2095
+ pyth: RawTransactionArgument<string>;
2096
+ bsValues: RawTransactionArgument<string>;
2097
+ bsSvi: RawTransactionArgument<string>;
2098
+ kind: RawTransactionArgument<number>;
2099
+ lowerTick: RawTransactionArgument<number | bigint>;
2100
+ higherTick: RawTransactionArgument<number | bigint>;
2101
+ quantity: RawTransactionArgument<number | bigint>;
2102
+ maxPremium: RawTransactionArgument<number | bigint>;
2103
+ minQuantity: RawTransactionArgument<number | bigint>;
2104
+ maxProbability: RawTransactionArgument<number | bigint>;
2105
+ budget: RawTransactionArgument<number | bigint>;
2106
+ orderFee: RawTransactionArgument<number | bigint>;
2107
+ sviMaxAgeMs: RawTransactionArgument<number | bigint>;
2108
+ channel: RawTransactionArgument<number>;
2109
+ tauMs: RawTransactionArgument<number | bigint>;
2110
+ deadlineMs: RawTransactionArgument<number | bigint>;
2111
+ }
2112
+ export interface AdmitMintOptions<W extends BcsType<any>> {
2113
+ package?: string;
2114
+ arguments: AdmitMintArguments<W>;
2115
+ config?: {
2116
+ protocolConfig: ConfigValue;
2117
+ oracleRegistry: ConfigValue;
2118
+ predictPackageId?: string;
2119
+ };
2120
+ typeArguments: [string];
2121
+ }
2122
+ /**
2123
+ * Admit one queued mint for the order-flow companion and return its receipt.
2124
+ *
2125
+ * `kind` is a `constants` mint kind. The companion has already taken
2126
+ * `budget + order_fee` from the account and escrows it. `budget` caps the fill's
2127
+ * all-in cost; the companion sets it to `min(max_cost, balance - order_fee)`, and
2128
+ * to at most `quantity` for an exact-quantity mint. The order prices at a Pyth
2129
+ * price on Lazer channel `channel`, generated at or after `tau_ms`, and must fill
2130
+ * before `deadline_ms`.
2131
+ *
2132
+ * Aborts unless `W` is allowlisted, the version and cutover gates pass, trading
2133
+ * and this market's mints are unpaused, and the snapshot stage is closed. The
2134
+ * timing must fit (`EInvalidOrderTiming`): `channel` a supported fixed-rate
2135
+ * channel (`lazer_price::channel_fixed_rate_*`), `tau_ms` on its grid, at most one
2136
+ * of its ticks before now, and before `deadline_ms`, τ before the no-trade window,
2137
+ * and the deadline at least `constants::deadline_expiry_margin_ms!()` before
2138
+ * expiry. Then `svi_max_age_ms` must be within `constants::max_svi_max_age_ms!()`
2139
+ * and `kind` a mint kind (`EInvalidOrderTerms`), the volatility snapshot must
2140
+ * load, `budget` must be positive (`EMintCostCapRequired`), the order must pass
2141
+ * its own limits at the clock without subsidy (`EOrderFailsLimits`), and its cash
2142
+ * need must fit the market's spare cash (`EInsufficientMarketCash`). Admission
2143
+ * then pins both boundary nodes, creating them under the node cap, and adds the
2144
+ * cash need to the ledger.
2145
+ */
2146
+ export function admitMint<W extends BcsType<any>>(options: AdmitMintOptions<W>) {
2147
+ const packageAddress =
2148
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
2149
+ const argumentsTypes = [
2150
+ `${options.typeArguments[0]}`,
2151
+ null,
2152
+ null,
2153
+ null,
2154
+ null,
2155
+ null,
2156
+ null,
2157
+ null,
2158
+ 'u8',
2159
+ 'u64',
2160
+ 'u64',
2161
+ 'u64',
2162
+ 'u64',
2163
+ 'u64',
2164
+ 'u64',
2165
+ 'u64',
2166
+ 'u64',
2167
+ 'u64',
2168
+ 'u8',
2169
+ 'u64',
2170
+ 'u64',
2171
+ '0x2::clock::Clock',
2172
+ ] satisfies (string | null)[];
2173
+ const parameterNames = [
2174
+ 'W',
2175
+ 'market',
2176
+ 'config',
2177
+ 'account',
2178
+ 'propbookRegistry',
2179
+ 'pyth',
2180
+ 'bsValues',
2181
+ 'bsSvi',
2182
+ 'kind',
2183
+ 'lowerTick',
2184
+ 'higherTick',
2185
+ 'quantity',
2186
+ 'maxPremium',
2187
+ 'minQuantity',
2188
+ 'maxProbability',
2189
+ 'budget',
2190
+ 'orderFee',
2191
+ 'sviMaxAgeMs',
2192
+ 'channel',
2193
+ 'tauMs',
2194
+ 'deadlineMs',
2195
+ ];
2196
+ return (tx: Transaction) =>
2197
+ tx.moveCall({
2198
+ package: packageAddress,
2199
+ module: 'expiry_market',
2200
+ function: 'admit_mint',
2201
+ arguments: normalizeMoveArguments(
2202
+ {
2203
+ ...options.arguments,
2204
+ config: options.arguments?.config ?? options.config?.protocolConfig,
2205
+ propbookRegistry: options.arguments?.propbookRegistry ?? options.config?.oracleRegistry,
2206
+ },
2207
+ argumentsTypes,
2208
+ parameterNames,
2209
+ ),
2210
+ typeArguments: options.typeArguments,
2211
+ });
2212
+ }
2213
+ export interface AdmitSellArguments<W extends BcsType<any>> {
2214
+ W: RawTransactionArgument<W>;
2215
+ market: RawTransactionArgument<string>;
2216
+ config?: RawTransactionArgument<string>;
2217
+ account: TransactionArgument;
2218
+ receipt: TransactionArgument;
2219
+ propbookRegistry?: RawTransactionArgument<string>;
2220
+ pyth: RawTransactionArgument<string>;
2221
+ bsValues: RawTransactionArgument<string>;
2222
+ bsSvi: RawTransactionArgument<string>;
2223
+ closeQuantity: RawTransactionArgument<number | bigint>;
2224
+ minProbability: RawTransactionArgument<number | bigint>;
2225
+ minProceeds: RawTransactionArgument<number | bigint>;
2226
+ orderFee: RawTransactionArgument<number | bigint>;
2227
+ sviMaxAgeMs: RawTransactionArgument<number | bigint>;
2228
+ channel: RawTransactionArgument<number>;
2229
+ tauMs: RawTransactionArgument<number | bigint>;
2230
+ deadlineMs: RawTransactionArgument<number | bigint>;
2231
+ }
2232
+ export interface AdmitSellOptions<W extends BcsType<any>> {
2233
+ package?: string;
2234
+ arguments: AdmitSellArguments<W>;
2235
+ config?: {
2236
+ protocolConfig: ConfigValue;
2237
+ oracleRegistry: ConfigValue;
2238
+ predictPackageId?: string;
2239
+ };
2240
+ typeArguments: [string];
2241
+ }
2242
+ /**
2243
+ * Admit an early sell of `close_quantity` of an open receipt's position: the
2244
+ * receipt moves to the sell stage in place, with the sell's request, the account's
2245
+ * current owner and builder code, a fresh volatility snapshot, τ, the deadline,
2246
+ * and no price. The companion escrows `order_fee` and owns the minimum-sell
2247
+ * checks.
2248
+ *
2249
+ * Open during the trading pause and a market mint pause. Aborts unless `W` is
2250
+ * allowlisted, the version, cutover, and snapshot-stage gates and `admit_mint`'s
2251
+ * timing and SVI-age checks pass, the receipt is this market's (`EWrongMarket`),
2252
+ * open (`EWrongStage`), and `account`'s (`ENotRecordOwner`), the volatility
2253
+ * snapshot loads, and the close passes its own floors at the clock
2254
+ * (`EOrderFailsLimits`). Then adds the sell's cash need,
2255
+ * `ceil(close_quantity * (1 - backing_buffer_lambda)) + 1`, to the ledger: a close
2256
+ * lowers payout liability by at least `lambda * close_quantity` and pays at most
2257
+ * `close_quantity`. There is no spare-cash check. The keeper funds the market
2258
+ * before τ, and the fill refunds a sell the market cannot cover.
2259
+ */
2260
+ export function admitSell<W extends BcsType<any>>(options: AdmitSellOptions<W>) {
2261
+ const packageAddress =
2262
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
2263
+ const argumentsTypes = [
2264
+ `${options.typeArguments[0]}`,
2265
+ null,
2266
+ null,
2267
+ null,
2268
+ null,
2269
+ null,
2270
+ null,
2271
+ null,
2272
+ null,
2273
+ 'u64',
2274
+ 'u64',
2275
+ 'u64',
2276
+ 'u64',
2277
+ 'u64',
2278
+ 'u8',
2279
+ 'u64',
2280
+ 'u64',
2281
+ '0x2::clock::Clock',
2282
+ ] satisfies (string | null)[];
2283
+ const parameterNames = [
2284
+ 'W',
2285
+ 'market',
2286
+ 'config',
2287
+ 'account',
2288
+ 'receipt',
2289
+ 'propbookRegistry',
2290
+ 'pyth',
2291
+ 'bsValues',
2292
+ 'bsSvi',
2293
+ 'closeQuantity',
2294
+ 'minProbability',
2295
+ 'minProceeds',
2296
+ 'orderFee',
2297
+ 'sviMaxAgeMs',
2298
+ 'channel',
2299
+ 'tauMs',
2300
+ 'deadlineMs',
2301
+ ];
2302
+ return (tx: Transaction) =>
2303
+ tx.moveCall({
2304
+ package: packageAddress,
2305
+ module: 'expiry_market',
2306
+ function: 'admit_sell',
2307
+ arguments: normalizeMoveArguments(
2308
+ {
2309
+ ...options.arguments,
2310
+ config: options.arguments?.config ?? options.config?.protocolConfig,
2311
+ propbookRegistry: options.arguments?.propbookRegistry ?? options.config?.oracleRegistry,
2312
+ },
2313
+ argumentsTypes,
2314
+ parameterNames,
2315
+ ),
2316
+ typeArguments: options.typeArguments,
2317
+ });
2318
+ }
2319
+ export interface CommitArguments<W extends BcsType<any>> {
2320
+ W: RawTransactionArgument<W>;
2321
+ market: RawTransactionArgument<string>;
2322
+ config?: RawTransactionArgument<string>;
2323
+ receipt: TransactionArgument;
2324
+ price: TransactionArgument;
2325
+ }
2326
+ export interface CommitOptions<W extends BcsType<any>> {
2327
+ package?: string;
2328
+ arguments: CommitArguments<W>;
2329
+ config?: {
2330
+ protocolConfig: ConfigValue;
2331
+ predictPackageId?: string;
2332
+ };
2333
+ typeArguments: [string];
2334
+ }
2335
+ /**
2336
+ * Commit the Pyth price an admitted order fills at: a `LazerPrice`, which only the
2337
+ * `deepbook_predict_math` library builds, from a Pyth-verified Lazer update.
2338
+ * Stores the spot, the envelope time (the tick the fill prices at), and the feed's
2339
+ * generation time. For a mint it also reserves the fee subsidy,
2340
+ * `min(subsidy_bound * fee_incentive_subsidy_rate, incentives left)`, records the
2341
+ * rate and amount, and returns the reservation for the companion to escrow with
2342
+ * the order. A sell returns a zero balance.
2343
+ *
2344
+ * The price must be the receipt's: its Pyth feed and channel, an envelope at
2345
+ * exactly τ or one tick of that channel later (the backup tick), a generation time
2346
+ * between τ and the envelope, an envelope at or before now, and a pricing-safe
2347
+ * spot (`EWrongPrice`). Aborts unless `W` is allowlisted, the version gate passes,
2348
+ * the receipt is this market's (`EWrongMarket`), admitted with no price yet
2349
+ * (`EWrongStage`), and before its deadline (`EInvalidOrderTiming`).
2350
+ */
2351
+ export function commit<W extends BcsType<any>>(options: CommitOptions<W>) {
2352
+ const packageAddress =
2353
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
2354
+ const argumentsTypes = [
2355
+ `${options.typeArguments[0]}`,
2356
+ null,
2357
+ null,
2358
+ null,
2359
+ null,
2360
+ '0x2::clock::Clock',
2361
+ ] satisfies (string | null)[];
2362
+ const parameterNames = ['W', 'market', 'config', 'receipt', 'price'];
2363
+ return (tx: Transaction) =>
2364
+ tx.moveCall({
2365
+ package: packageAddress,
2366
+ module: 'expiry_market',
2367
+ function: 'commit',
2368
+ arguments: normalizeMoveArguments(
2369
+ {
2370
+ ...options.arguments,
2371
+ config: options.arguments?.config ?? options.config?.protocolConfig,
2372
+ },
2373
+ argumentsTypes,
2374
+ parameterNames,
2375
+ ),
2376
+ typeArguments: options.typeArguments,
2377
+ });
2378
+ }
2379
+ export interface TryFillArguments<W extends BcsType<any>> {
2380
+ W: RawTransactionArgument<W>;
2381
+ market: RawTransactionArgument<string>;
2382
+ config?: RawTransactionArgument<string>;
2383
+ receipt: TransactionArgument;
2384
+ escrow: TransactionArgument;
2385
+ }
2386
+ export interface TryFillOptions<W extends BcsType<any>> {
2387
+ package?: string;
2388
+ arguments: TryFillArguments<W>;
2389
+ config?: {
2390
+ protocolConfig: ConfigValue;
2391
+ predictPackageId?: string;
2392
+ };
2393
+ typeArguments: [string];
2394
+ }
2395
+ /**
2396
+ * Fill or refund one committed order at its committed price and consume or return
2397
+ * its receipt. `escrow` is the order's escrowed budget, order fee, and reserved
2398
+ * subsidy. Returns
2399
+ * `(reason, receipt to keep, escrow left over, quantity, amount, trading_fee, builder_fee, referral_fee, subsidy_used, inventory_impact)`.
2400
+ * The amounts are zero on a refund. For a mint `amount` is the all-in cost and
2401
+ * `inventory_impact` the charge; for a sell `amount` is the proceeds and
2402
+ * `inventory_impact` the rebate.
2403
+ *
2404
+ * Aborts only on a companion bookkeeping error: `W` not allowlisted, the version,
2405
+ * freeze, or snapshot-stage gate, another market's receipt (`EWrongMarket`), a
2406
+ * receipt not admitted or without a price (`EWrongStage`), or `escrow` below
2407
+ * `budget + order_fee + subsidy_reserved` (`EEscrowMismatch`). Every market
2408
+ * condition returns a refund reason instead, `0` for a fill: 5 at or past the
2409
+ * deadline, which also covers expiry and settlement; 9 when USDC sent to the
2410
+ * receipt's receive address would abort the transaction (`denied`: the address is
2411
+ * on USDC's deny list for the current epoch, or USDC is globally paused), so
2412
+ * nothing is sent there; 2 when no `Pricer` exists at the tick; then the fill's
2413
+ * own 1 (the order's limits), 2 (admission), 4 (a pinned node is missing, a
2414
+ * backstop), and 8 (the market's cash after the fill would not cover its required
2415
+ * cash).
2416
+ *
2417
+ * A mint fill pays the premium, the trading fee net of the referral share, the
2418
+ * used subsidy, the order fee, and the inventory-impact charge into market cash,
2419
+ * sends the builder and referral fees, returns unused subsidy to the incentive
2420
+ * balance, emits `OrderMinted` with no congestion penalty, and returns the receipt
2421
+ * open. A sell fill pays the proceeds (redeem value plus inventory-impact rebate,
2422
+ * less the trading and builder fees) to the receipt's receive address, keeps the
2423
+ * trading and order fees in market cash, emits `LiveOrderRedeemed`, and returns
2424
+ * the receipt open with the replacement position of a partial close, or consumes
2425
+ * it on a full close. A builder or referral fee whose recipient is denied stays in
2426
+ * market cash instead, and the events still report it as charged. A refund keeps
2427
+ * the order fee in market cash for reasons 1 and 2, returns the reserved subsidy
2428
+ * to the incentive balance, prunes a mint's emptied unpinned nodes, returns the
2429
+ * rest of the escrow, and returns a sell's receipt open or consumes a mint's.
2430
+ * Every outcome takes the order out of the ledger.
2431
+ */
2432
+ export function tryFill<W extends BcsType<any>>(options: TryFillOptions<W>) {
2433
+ const packageAddress =
2434
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
2435
+ const argumentsTypes = [
2436
+ `${options.typeArguments[0]}`,
2437
+ null,
2438
+ null,
2439
+ null,
2440
+ null,
2441
+ '0x2::deny_list::DenyList',
2442
+ '0x2::clock::Clock',
2443
+ ] satisfies (string | null)[];
2444
+ const parameterNames = ['W', 'market', 'config', 'receipt', 'escrow'];
2445
+ return (tx: Transaction) =>
2446
+ tx.moveCall({
2447
+ package: packageAddress,
2448
+ module: 'expiry_market',
2449
+ function: 'try_fill',
2450
+ arguments: normalizeMoveArguments(
2451
+ {
2452
+ ...options.arguments,
2453
+ config: options.arguments?.config ?? options.config?.protocolConfig,
2454
+ },
2455
+ argumentsTypes,
2456
+ parameterNames,
2457
+ ),
2458
+ typeArguments: options.typeArguments,
2459
+ });
2460
+ }
2461
+ export interface ReleaseArguments {
2462
+ market: RawTransactionArgument<string>;
2463
+ config?: RawTransactionArgument<string>;
2464
+ receipt: TransactionArgument;
2465
+ escrow: TransactionArgument;
2466
+ reason: RawTransactionArgument<number>;
2467
+ prune: RawTransactionArgument<boolean>;
2468
+ }
2469
+ export interface ReleaseOptions {
2470
+ package?: string;
2471
+ arguments: ReleaseArguments;
2472
+ config?: {
2473
+ protocolConfig: ConfigValue;
2474
+ predictPackageId?: string;
2475
+ };
2476
+ }
2477
+ /**
2478
+ * Take an admitted order out without filling it: the companion's deadline, admin,
2479
+ * and settlement-drain refunds release their receipt here. `escrow` is the order's
2480
+ * escrowed budget, order fee, and reserved subsidy, and `reason` the refund's
2481
+ * `constants::fill_reason_*` code. The order fee follows `try_fill`'s refund rule:
2482
+ * reasons 1 and 2 keep it in market cash, and every other reason leaves it in the
2483
+ * escrow returned. Returns the reservation to the incentive balance, subtracts the
2484
+ * exact cash need from the ledger, and unpins a mint's boundary ticks, pruning
2485
+ * emptied, unpinned, unretained nodes only when `prune` and the market is
2486
+ * unsettled. Returns a sell's receipt open, still holding its position, or `none`
2487
+ * for a mint's, which it consumes, and the rest of the escrow.
2488
+ *
2489
+ * Needs no allowlisting and checks only the version floor, so the drain works
2490
+ * while the protocol is frozen and after the witness is removed. Keeping an order
2491
+ * fee moves market cash, so like a fill it aborts inside the keeper's snapshot
2492
+ * stage (`ESnapshotInProgress`). Aborts on another market's receipt
2493
+ * (`EWrongMarket`), a receipt not admitted (`EWrongStage`), or `escrow` below
2494
+ * `budget + order_fee + subsidy_reserved` (`EEscrowMismatch`).
2495
+ */
2496
+ export function release(options: ReleaseOptions) {
2497
+ const packageAddress =
2498
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
2499
+ const argumentsTypes = [null, null, null, null, 'u8', 'bool'] satisfies (string | null)[];
2500
+ const parameterNames = ['market', 'config', 'receipt', 'escrow', 'reason', 'prune'];
2501
+ return (tx: Transaction) =>
2502
+ tx.moveCall({
2503
+ package: packageAddress,
2504
+ module: 'expiry_market',
2505
+ function: 'release',
2506
+ arguments: normalizeMoveArguments(
2507
+ {
2508
+ ...options.arguments,
2509
+ config: options.arguments?.config ?? options.config?.protocolConfig,
2510
+ },
2511
+ argumentsTypes,
2512
+ parameterNames,
2513
+ ),
2514
+ });
2515
+ }
2516
+ export interface TryPaySettledArguments {
2517
+ market: RawTransactionArgument<string>;
2518
+ config?: RawTransactionArgument<string>;
2519
+ receipt: TransactionArgument;
2520
+ }
2521
+ export interface TryPaySettledOptions {
2522
+ package?: string;
2523
+ arguments: TryPaySettledArguments;
2524
+ config?: {
2525
+ protocolConfig: ConfigValue;
2526
+ predictPackageId?: string;
2527
+ };
2528
+ }
2529
+ /**
2530
+ * Pay an open receipt's settled payout, zero for a loser, to its receive address
2531
+ * and consume the receipt. Returns the payout and `none`. When the payout is above
2532
+ * market cash or above the settled liability left, or a nonzero payout's receive
2533
+ * address is denied (`try_fill`'s reason 9: on USDC's deny list for the current
2534
+ * epoch, or USDC globally paused), changes nothing and returns that payout with
2535
+ * the receipt, so the companion's payout walk moves on and a later call pays it
2536
+ * once the cause clears. Needs no allowlisting and checks only the version floor.
2537
+ * Aborts on another market's receipt (`EWrongMarket`), a receipt that is not open
2538
+ * (`EWrongStage`), or an unsettled market (`EMarketNotSettled`).
2539
+ */
2540
+ export function tryPaySettled(options: TryPaySettledOptions) {
2541
+ const packageAddress =
2542
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
2543
+ const argumentsTypes = [null, null, null, '0x2::deny_list::DenyList'] satisfies (string | null)[];
2544
+ const parameterNames = ['market', 'config', 'receipt'];
2545
+ return (tx: Transaction) =>
2546
+ tx.moveCall({
2547
+ package: packageAddress,
2548
+ module: 'expiry_market',
2549
+ function: 'try_pay_settled',
2550
+ arguments: normalizeMoveArguments(
2551
+ {
2552
+ ...options.arguments,
2553
+ config: options.arguments?.config ?? options.config?.protocolConfig,
2554
+ },
2555
+ argumentsTypes,
2556
+ parameterNames,
2557
+ ),
2558
+ });
2559
+ }