@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
@@ -2,6 +2,9 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import type { AccountConfig } from '../../account.js';
4
4
  import type { DeepbookPredictConfig } from '../../contracts/deepbook_predict/config-arguments.js';
5
+ import type { DeepbookPredictMathConfig } from '../../contracts/deepbook_predict_math/config-arguments.js';
6
+ import type { DeepbookPredictOrdersConfig } from '../../contracts/deepbook_predict_orders/config-arguments.js';
7
+ import { PredictInputError } from '../errors.js';
5
8
  import type { PredictConfig } from './types.js';
6
9
 
7
10
  /**
@@ -39,3 +42,50 @@ export function toGeneratedConfig(cfg: PredictConfig): GeneratedConfig {
39
42
  accountRegistry: cfg.objects.accountRegistry,
40
43
  };
41
44
  }
45
+
46
+ /**
47
+ * {@link GeneratedConfig} plus the order-flow companion (`deepbook_predict_orders`) and the math
48
+ * library: the slice the queued-order thunks and reads take. A queued order calls the companion,
49
+ * which calls into Predict, so one object carries both packages' keys. `predictOrdersPackageIdV1`
50
+ * is the companion's original ID, which types `OrderFlow` and the queue events.
51
+ */
52
+ export type OrdersGeneratedConfig = GeneratedConfig &
53
+ DeepbookPredictOrdersConfig &
54
+ DeepbookPredictMathConfig & {
55
+ predictOrdersPackageId: string;
56
+ predictOrdersPackageIdV1: string;
57
+ orderDesk: string;
58
+ queueRegistry: string;
59
+ };
60
+
61
+ /**
62
+ * Project a config that records delayed execution onto {@link OrdersGeneratedConfig}. Throws
63
+ * `PredictInputError` while the config lacks the Predict upgrade, the companion package, its desk
64
+ * or its queue registry: building a queued order against a guessed package would abort on chain
65
+ * or, worse, address the wrong one.
66
+ */
67
+ export function toOrdersConfig(cfg: PredictConfig): OrdersGeneratedConfig {
68
+ const { predictDelayedExecution, predictOrders, predictOrdersV1, predictMath } = cfg.packages;
69
+ const { orderDesk, queueRegistry } = cfg.objects;
70
+ if (!predictDelayedExecution || !predictOrders || !orderDesk || !queueRegistry) {
71
+ const missing = [
72
+ !predictDelayedExecution && '`packages.predictDelayedExecution`',
73
+ !predictOrders && '`packages.predictOrders`',
74
+ !orderDesk && '`objects.orderDesk`',
75
+ !queueRegistry && '`objects.queueRegistry`',
76
+ ].filter(Boolean);
77
+ throw new PredictInputError(
78
+ `delayed execution isn't recorded for ${cfg.network} in this SDK version (missing ` +
79
+ `${missing.join(', ')}): pass a \`config\` that records the Predict upgrade, the ` +
80
+ '`deepbook_predict_orders` package, its order desk and its queue registry',
81
+ );
82
+ }
83
+ return {
84
+ ...toGeneratedConfig(cfg),
85
+ predictOrdersPackageId: predictOrders,
86
+ predictOrdersPackageIdV1: predictOrdersV1 ?? predictOrders,
87
+ predictMathPackageId: predictMath,
88
+ orderDesk,
89
+ queueRegistry,
90
+ };
91
+ }
@@ -18,10 +18,24 @@ export const MAINNET_CONFIG: PredictConfig = Object.freeze({
18
18
  // The record widens `network` to `string` so the published types don't pin a literal;
19
19
  // this file is the mainnet config by construction.
20
20
  network: 'mainnet',
21
- packages: MAINNET_PREDICT.packages,
22
- objects: MAINNET_PREDICT.objects,
21
+ // Delayed execution (DBU-885) is recorded on Mainnet. The generated record carries the package
22
+ // IDs that move with upgrades (Predict, `deepbook_predict_orders`, `deepbook_predict_math`) and
23
+ // the Lazer `State`. The three IDs pinned below are in no publication record and never move:
24
+ // the Predict version that introduced delayed execution (Mainnet v4), which defines its new
25
+ // types and events, and the `OrderDesk` and `QueueRegistry` that `deepbook_predict_orders`'s
26
+ // `init` shared at publish.
27
+ packages: Object.freeze({
28
+ ...MAINNET_PREDICT.packages,
29
+ predictDelayedExecution: '0x98235c5842831c9b5f51dc637cf34c91db2aca5510802eb6ebfec63f5b71a7bb',
30
+ }),
31
+ objects: Object.freeze({
32
+ ...MAINNET_PREDICT.objects,
33
+ orderDesk: '0x87b0a87262aacf58eaff567eed2fb7cb0f9cbc1f5ce33ef79216cd26d13a1b5b',
34
+ queueRegistry: '0x8d4f0c671862f065ac7f2c2cb24abc47cf75ed8fc8e5e52c1d4bdfa53eee164f',
35
+ }),
23
36
  quoteCoinType: MAINNET_PREDICT.quoteCoinType,
24
37
  coinTypes: MAINNET_PREDICT.coinTypes,
25
38
  units: MAINNET_PREDICT.units,
26
39
  underlyings: MAINNET_PREDICT.underlyings,
40
+ oracle: MAINNET_PREDICT.oracle,
27
41
  });
@@ -18,10 +18,24 @@ export const TESTNET_CONFIG: PredictConfig = Object.freeze({
18
18
  // The record widens `network` to `string` so the published types don't pin a literal;
19
19
  // this file is the testnet config by construction.
20
20
  network: 'testnet',
21
- packages: TESTNET_PREDICT.packages,
22
- objects: TESTNET_PREDICT.objects,
21
+ // Delayed execution (DBU-885) is recorded on Testnet. The generated record carries the package
22
+ // IDs that move with upgrades (Predict, `deepbook_predict_orders`, `deepbook_predict_math`) and
23
+ // the Lazer `State`. The three IDs pinned below are in no publication record and never move:
24
+ // the Predict version that introduced delayed execution (Testnet v5), which defines its new
25
+ // types and events, and the `OrderDesk` and `QueueRegistry` that `deepbook_predict_orders`'s
26
+ // `init` shared at publish.
27
+ packages: Object.freeze({
28
+ ...TESTNET_PREDICT.packages,
29
+ predictDelayedExecution: '0x0654ecbed7c0f2645d9de7cb6cf08e65c2ee05cdbb39a415f17a6bd1cd92e267',
30
+ }),
31
+ objects: Object.freeze({
32
+ ...TESTNET_PREDICT.objects,
33
+ orderDesk: '0x160fc026c4143f3dec36acfc6556379d54661d37fe28ad837b6a85e42aeddfea',
34
+ queueRegistry: '0xe9d75ed05b089d52a660a94b94963cdc89aeb7f3c75b57f76771454c81faae1f',
35
+ }),
23
36
  quoteCoinType: TESTNET_PREDICT.quoteCoinType,
24
37
  coinTypes: TESTNET_PREDICT.coinTypes,
25
38
  units: TESTNET_PREDICT.units,
26
39
  underlyings: TESTNET_PREDICT.underlyings,
40
+ oracle: TESTNET_PREDICT.oracle,
27
41
  });
@@ -1,11 +1,42 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- /** The three published Move packages a Predict deployment spans. */
3
+ /**
4
+ * The published Move packages a Predict deployment spans.
5
+ *
6
+ * Delayed execution (DBU-885) ships as three packages: the Predict upgrade, the order-flow
7
+ * companion `deepbook_predict_orders` (a fresh publish), and the math library
8
+ * `deepbook_predict_math` (a fresh publish). The queued-order builders, reads and decoders need
9
+ * `predictDelayedExecution`, `predictOrders`, `objects.orderDesk` and `objects.queueRegistry` all
10
+ * recorded, and throw
11
+ * `PredictInputError` otherwise rather than address the wrong package. Pass a custom `config`
12
+ * (a localnet publish) to use them before a network record exists.
13
+ */
4
14
  export interface PredictPackages {
5
15
  /** Latest published package ID, used for Move calls. */
6
16
  predict: string;
7
17
  /** Original ID for v1 structs/events. Omit only for an unupgraded custom deployment. */
8
18
  predictV1?: string;
19
+ /**
20
+ * The Predict version that introduced delayed execution (Mainnet v4, Testnet v5): the
21
+ * defining ID of the Predict types and events that version added (`ExpiryPnlRealized`,
22
+ * `FlushOperatorUpdated`, `OrderFlowUpdated`, `OrderReceipt`). A later upgrade does not move
23
+ * it, so it is pinned once per network rather than read from the latest publication.
24
+ */
25
+ predictDelayedExecution?: string;
26
+ /**
27
+ * Latest published `deepbook_predict_orders` package ID: the call target of every queued-order
28
+ * entry point (`queue::enqueue_*`, `commit`, `resolve`, `refund`, `settle_step`, …), the queue
29
+ * reads and the desk setters.
30
+ */
31
+ predictOrders?: string;
32
+ /**
33
+ * Original `deepbook_predict_orders` ID, which types `MarketQueue`, `OrderDesk`, the queue
34
+ * events and the `OrderFlow` witness. Omit until the package is first upgraded: it then
35
+ * defaults to `predictOrders`.
36
+ */
37
+ predictOrdersV1?: string;
38
+ /** The `deepbook_predict_math` package ID, for its pure calls and layouts. */
39
+ predictMath?: string;
9
40
  account: string;
10
41
  propbook: string;
11
42
  }
@@ -36,6 +67,17 @@ export interface PredictConfig {
36
67
  poolVault: string;
37
68
  oracleRegistry: string;
38
69
  accountRegistry: string;
70
+ /**
71
+ * The order-flow companion's shared `OrderDesk`: the delayed-execution policy and the
72
+ * companion's version floor. Created once, by the package's `init` at publish.
73
+ */
74
+ orderDesk?: string;
75
+ /**
76
+ * The order-flow companion's shared `QueueRegistry`, created next to the desk by the same
77
+ * `init`. Each market's `MarketQueue` sits at an ID derived from it and the market
78
+ * (`deriveQueueId`), and `queue::create_and_share` writes it.
79
+ */
80
+ queueRegistry?: string;
39
81
  };
40
82
  /**
41
83
  * The deployment's settlement coin type. Always read this rather than assuming a type:
@@ -58,4 +100,12 @@ export interface PredictConfig {
58
100
  positionQuantityDecimals: number;
59
101
  };
60
102
  underlyings: Record<string, UnderlyingConfig>; // keyed by symbol, e.g. "BTC"
103
+ /**
104
+ * Oracle objects only the delayed-execution filler needs. Optional: traders never pass
105
+ * them, and a filler can name the Lazer `State` per call instead.
106
+ */
107
+ oracle?: {
108
+ /** Pyth Lazer's shared `State`, which carries the current Lazer package ID. */
109
+ pythLazerState?: string;
110
+ };
61
111
  }
@@ -31,9 +31,9 @@
31
31
  // against current account and market state, including the execution gates these previews
32
32
  // do not check (ownership, pauses, trade window, oracle freshness and cash backing).
33
33
  //
34
- // The fee POLICY is a per-market snapshot taken at creation (`StrikeExposureConfig`), and the
35
- // chain exposes no getter for `base_fee`/`min_fee` — take it from the market's `MarketCreated`
36
- // event (an indexer, or `decode`), or use {@link SHIPPED_FEE_POLICY} for the shipped template.
34
+ // The fee POLICY is a per-market snapshot taken at creation (`StrikeExposureConfig`). The
35
+ // chain exposes no getter for `base_fee`/`min_fee`, so `read.feePolicy(market)` decodes it from
36
+ // the `ExpiryMarket` object. The market's `MarketCreated` event carries it too.
37
37
 
38
38
  import { PredictInputError } from './errors.js';
39
39
  import type { PricerInputs } from './pricing.js';
@@ -53,7 +53,14 @@ export const MIN_PREMIUM = 1_000_000n;
53
53
  export const BUILDER_FEE_MULTIPLIER = 100_000_000n;
54
54
  /** `constants::max_builder_fee_rate` — cap on the builder fee as a share of quantity (0.5%). */
55
55
  export const MAX_BUILDER_FEE_RATE = 5_000_000n;
56
- /** `constants::fee_incentive_subsidy_rate` — sponsor share of a trader's mint fee (20%). */
56
+ /**
57
+ * The default sponsor share of a trader's mint fee (20%), and the rate the chain reads while the
58
+ * admin hasn't set one.
59
+ * @deprecated From delayed execution (DBU-885) the rate is admin-set: read it with
60
+ * `protocol_config::fee_incentive_subsidy_rate` (`read.queue(...).protocol.feeIncentiveSubsidyRate`)
61
+ * and pass it as `feeIncentiveSubsidyRate`. A hardcoded 20% underquotes every mint once the rate
62
+ * moves.
63
+ */
57
64
  export const FEE_INCENTIVE_SUBSIDY_RATE = 200_000_000n;
58
65
  /** `order::max_quantity_lots` — the order ID's 32-bit lot field. */
59
66
  export const MAX_QUANTITY_LOTS = (1n << 32n) - 1n;
@@ -130,8 +137,8 @@ export function sqrtDown(x: bigint): bigint {
130
137
  /**
131
138
  * One market's fee policy: the `StrikeExposureConfig` it snapshotted at creation, in raw 1e9
132
139
  * rates. Snapshotted means later admin changes do NOT reprice a market already trading, so
133
- * read it per market (the `MarketCreated` event carries every field) rather than assuming the
134
- * template. The last three are the inventory-impact parameters, inert while
140
+ * read it per market with `read.feePolicy(market)` (the `MarketCreated` event carries every field
141
+ * too) rather than assuming the template. The last three are the inventory-impact parameters, inert while
135
142
  * `inventoryImpactMaxRate` is `0n` (the shipped value).
136
143
  */
137
144
  export interface FeePolicy {
@@ -158,9 +165,11 @@ export interface FeePolicy {
158
165
  /**
159
166
  * The shipped template (`config_constants` defaults): 10% Bernoulli fee, a 2.2% per-leg floor,
160
167
  * a one-day ramp window that is inert at a 1.0 multiplier, a 1%–99% entry band, and inventory
161
- * impact disabled. A market that was created under these values charges exactly this; one
162
- * created after an admin change does not, which is why the per-market snapshot is the real
163
- * answer. Verify against the deployment's `MarketCreated` before pricing money on it.
168
+ * impact disabled. Neither recorded deployment's template matches it any more: both charge a
169
+ * 20.4% Bernoulli fee, ramp it to 3× over the last 60 s and admit entries in 25%–75% (checked
170
+ * 2026-10-09), so a live market's costs from this policy come out low. Pass
171
+ * `read.feePolicy(market)` instead. This stays for tests and for a deployment still on the
172
+ * defaults.
164
173
  */
165
174
  export const SHIPPED_FEE_POLICY: FeePolicy = Object.freeze({
166
175
  baseFee: 100_000_000n,
@@ -347,11 +356,17 @@ export function builderFee(fee: bigint, quantity: bigint, hasBuilderCode: boolea
347
356
  }
348
357
 
349
358
  /** `expiry_market::fee_incentive_subsidy_amount` — a sponsor pays part of the trader's MINT
350
- * fee, bounded by the expiry's remaining sponsored balance. Mints only; redeems pay in full. */
351
- export function feeIncentiveSubsidy(fee: bigint, feeIncentiveBalance: bigint): bigint {
359
+ * fee, bounded by the expiry's remaining sponsored balance. Mints only; redeems pay in full.
360
+ * `rate` is the protocol's `fee_incentive_subsidy_rate` (1e9-scaled), 20% when omitted. */
361
+ export function feeIncentiveSubsidy(
362
+ fee: bigint,
363
+ feeIncentiveBalance: bigint,
364
+ rate: bigint = FEE_INCENTIVE_SUBSIDY_RATE,
365
+ ): bigint {
352
366
  assertUint(fee, 'fee');
353
367
  assertUint(feeIncentiveBalance, 'feeIncentiveBalance');
354
- return min(mulDown(fee, FEE_INCENTIVE_SUBSIDY_RATE), feeIncentiveBalance);
368
+ assertUint(rate, 'feeIncentiveSubsidyRate', FLOAT_SCALING);
369
+ return min(mulDown(fee, rate), feeIncentiveBalance);
355
370
  }
356
371
 
357
372
  /**
@@ -534,7 +549,15 @@ interface MintInputsBase {
534
549
  builderCode?: boolean;
535
550
  /** The expiry's remaining sponsored fee balance (`fee_incentive_balance`). Default `0n`. */
536
551
  feeIncentiveBalance?: number | bigint;
537
- /** Per-unit congestion surcharge rate — see {@link congestionPenaltyRate}. Default `0n`. */
552
+ /**
553
+ * The protocol's admin-set mint fee subsidy rate (`protocol_config::fee_incentive_subsidy_rate`),
554
+ * 1e9-scaled. Defaults to the 20% the chain reads while unset.
555
+ */
556
+ feeIncentiveSubsidyRate?: bigint;
557
+ /**
558
+ * Per-unit congestion surcharge rate — see {@link congestionPenaltyRate}. Default `0n`. A
559
+ * queued (delayed-execution) fill pays no congestion penalty, so queued previews keep it 0.
560
+ */
538
561
  penaltyRate?: bigint;
539
562
  /** Pre-trade payout-tree terms. Required when inventory impact is enabled. */
540
563
  book?: MintBookTerms;
@@ -663,7 +686,11 @@ function mintQuoteAt(
663
686
  } {
664
687
  const premium = mulDown(rangeProbability(boundaries), quantity);
665
688
  const fee = tradingFee(inputs.fees, boundaries, quantity, timeToExpiryMs);
666
- const subsidy = feeIncentiveSubsidy(fee, rawAmount(inputs.feeIncentiveBalance ?? 0n));
689
+ const subsidy = feeIncentiveSubsidy(
690
+ fee,
691
+ rawAmount(inputs.feeIncentiveBalance ?? 0n),
692
+ inputs.feeIncentiveSubsidyRate,
693
+ );
667
694
  const builder = builderFee(fee, quantity, inputs.builderCode ?? false);
668
695
  const penalty = mulDown(inputs.penaltyRate ?? 0n, quantity);
669
696
  const impact = inputs.book ? mintInventoryImpact(inputs.fees, inputs.book, quantity) : 0n;
@@ -1008,6 +1035,27 @@ export function decodeOrderRange(orderId: bigint, lotSize: bigint = POSITION_LOT
1008
1035
  };
1009
1036
  }
1010
1037
 
1038
+ /**
1039
+ * What an order pays at settlement, raw USDC: its full quantity when the settlement price lies
1040
+ * in `(lower, higher]`, else 0. The mirror of `strike_exposure::settled_order_payout`, which
1041
+ * rounds the settlement price up to the market's tick grid (`range_codec::limit_tick`) before
1042
+ * comparing it with the order's ticks, so a price inside a tick counts as that tick's upper edge.
1043
+ * Pass `read.settlement`'s `settlementPriceRaw` and `tickSizeRaw`, and the config's
1044
+ * `units.positionLotSize` when it isn't the default.
1045
+ */
1046
+ export function settledPayout(
1047
+ orderId: bigint,
1048
+ settlementPriceRaw: bigint,
1049
+ tickSizeRaw: bigint,
1050
+ lotSize: bigint = POSITION_LOT_SIZE,
1051
+ ): bigint {
1052
+ if (tickSizeRaw <= 0n) throw new PredictInputError('tickSizeRaw must be positive');
1053
+ const { lowerTick, higherTick, quantity } = decodeOrderRange(orderId, lotSize);
1054
+ const limit = (settlementPriceRaw + tickSizeRaw - 1n) / tickSizeRaw;
1055
+ const inRange = lowerTick < limit && (higherTick === POS_INF_TICK || limit <= higherTick);
1056
+ return inRange ? quantity : 0n;
1057
+ }
1058
+
1011
1059
  /** The strikes an {@link OrderRange} prices against, in USD, with `null` for each infinite
1012
1060
  * side — the shape {@link boundaryProbabilities} takes. `tickSize` is the market's raw tick
1013
1061
  * size (`ActiveMarket.tickSize` in USD, or the raw value from the deployment). */