@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
@@ -7,7 +7,9 @@
7
7
  *
8
8
  * Events carry transition identities and deltas rather than account or market
9
9
  * balances. Partial closes link an old order ID to its replacement; the position
10
- * root remains constant across that chain.
10
+ * root remains constant across that chain. Queued fills emit `OrderMinted` and
11
+ * `LiveOrderRedeemed` from inside Predict's order-flow fills; the queue's own
12
+ * events belong to the order-flow companion package.
11
13
  */
12
14
 
13
15
  import { MoveStruct } from '../utils/index.js';
@@ -77,10 +77,8 @@ export const PoolValuation = new MoveStruct({
77
77
  started_at_ms: U64,
78
78
  /**
79
79
  * Drain budgets committed at start (the cap owner's choice), bounding how many
80
- * requests each queue processes at finish. Committing them here — not at finish —
81
- * is what lets `finish_flush` run permissionless: a stranger may complete a flush
82
- * but only ever drains at these budgets, so completion can help LPs, never starve
83
- * them by finishing with a zero budget.
80
+ * requests each queue processes at finish. `finish_flush` takes no budget, so the
81
+ * flush operator who completes it drains at exactly these.
84
82
  */
85
83
  supply_budget: bcs.option(U64),
86
84
  withdraw_budget: bcs.option(U64),
@@ -114,7 +112,10 @@ export const PoolVault = new MoveStruct({
114
112
  * withdraws this balance.
115
113
  */
116
114
  protocol_reserve_balance: balance.Balance,
117
- /** Sponsor-funded USDC reserved for taker fee sponsorship, excluded from PLP NAV. */
115
+ /**
116
+ * Sponsor-funded USDC reserved for taker fee sponsorship, excluded from PLP NAV.
117
+ * Admin may reclaim it through `withdraw_fee_incentives`.
118
+ */
118
119
  fee_incentive_reserve: balance.Balance,
119
120
  /** PLP share issuance plus queued supply/withdraw escrow. */
120
121
  lp: lp_book.LpBook,
@@ -595,8 +596,8 @@ export interface SnapshotExpiryPricerOptions {
595
596
  * a payout tree — so all markets fit one PTB regardless of book size.
596
597
  *
597
598
  * The oracle feeding this stage must have been written in an EARLIER transaction:
598
- * `pricing::resolve_live_pricer` refuses a read stamped with the current
599
- * transaction digest (RP-24), so a keeper cannot refresh and snapshot in one PTB.
599
+ * `pricing::resolve_live` refuses a read stamped with the current transaction
600
+ * digest (RP-24), so a keeper cannot refresh and snapshot in one PTB.
600
601
  *
601
602
  * A market already settled at snapshot time is recorded with no pricer, gets no
602
603
  * stamp (settled flows never touch live NAV), and contributes 0. An
@@ -786,6 +787,11 @@ export interface FinishFlushOptions {
786
787
  * Because queueing is permissionless and a refunded request returns its escrow in
787
788
  * the same transaction, an operator should bound both budgets in production rather
788
789
  * than rely on queue length staying small — see RP-12.
790
+ *
791
+ * Only an allowlisted flush operator may call it
792
+ * (`protocol_config::ENotFlushOperator`). Fills move idle cash, so restricting who
793
+ * completes a flush keeps idle predictable for the keeper that funds markets for
794
+ * queued orders.
789
795
  */
790
796
  export function finishFlush(options: FinishFlushOptions) {
791
797
  const packageAddress =
@@ -828,7 +834,10 @@ export interface RebalanceExpiryCashOptions {
828
834
  * Permissionless and standalone: anyone may call it at any cadence. Handles all
829
835
  * three per-market cases — initial funding of a freshly registered (unfunded)
830
836
  * market, ongoing live rebalance/surplus-sweep toward target, and the
831
- * settled-market sweep (deactivate, return all free cash, materialize profit).
837
+ * settled-market sweep (deactivate, return all free cash, materialize profit). The
838
+ * live target covers the market's queued orders' cash need (the waiting cash need
839
+ * in `expiry_market::order_flow_state`), so the keeper calls this after each
840
+ * enqueue to fund those orders' fills, and a sweep never takes that cash back.
832
841
  * Call `expiry_market::try_settle` first in the same PTB when settlement may be
833
842
  * due. An expired unsettled market is a no-op until that transition succeeds. Mint
834
843
  * asserts backing but never pulls pool cash, so this is what makes a market
@@ -878,7 +887,9 @@ export interface SponsorFeeIncentivesOptions {
878
887
  /**
879
888
  * Sponsor taker fee incentives with USDC. Anyone may contribute; the payment joins
880
889
  * a pool-level reserve that is excluded from PLP NAV and later allocated to expiry
881
- * markets by the normal rebalance flow.
890
+ * markets by the normal rebalance flow. A contribution is not earmarked to its
891
+ * sponsor: admin can withdraw any of the reserve through
892
+ * `withdraw_fee_incentives`.
882
893
  */
883
894
  export function sponsorFeeIncentives(options: SponsorFeeIncentivesOptions) {
884
895
  const packageAddress =
@@ -901,6 +912,136 @@ export function sponsorFeeIncentives(options: SponsorFeeIncentivesOptions) {
901
912
  ),
902
913
  });
903
914
  }
915
+ export interface WithdrawFeeIncentivesArguments {
916
+ vault?: RawTransactionArgument<string>;
917
+ AdminCap: RawTransactionArgument<string>;
918
+ config?: RawTransactionArgument<string>;
919
+ amount: RawTransactionArgument<number | bigint>;
920
+ }
921
+ export interface WithdrawFeeIncentivesOptions {
922
+ package?: string;
923
+ arguments: WithdrawFeeIncentivesArguments;
924
+ config?: {
925
+ poolVault: ConfigValue;
926
+ protocolConfig: ConfigValue;
927
+ predictPackageId?: string;
928
+ };
929
+ }
930
+ /**
931
+ * Withdraw `amount` USDC of sponsor-funded fee incentives from the pool-level
932
+ * reserve, for sponsorship the protocol no longer wants to spend. Admin-only.
933
+ *
934
+ * Reaches the reserve only. Incentives already allocated to a live market stay in
935
+ * that market's `fee_incentive_balance` and return to the reserve when its
936
+ * settled-market sweep runs, after which they can be withdrawn here; setting
937
+ * `protocol_config::set_fee_incentive_subsidy_rate` to zero stops them being spent
938
+ * in the meantime. The per-expiry lifetime allocation counters are not credited
939
+ * back: they bound what a market may ever receive, and a withdrawal does not
940
+ * change what a market already received.
941
+ *
942
+ * Not gated on the valuation flag, in either stage of a flush: the reserve is
943
+ * excluded from PLP NAV and no flush figure, frozen or live, reads it, so a
944
+ * withdrawal cannot reach the mark.
945
+ */
946
+ export function withdrawFeeIncentives(options: WithdrawFeeIncentivesOptions) {
947
+ const packageAddress =
948
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
949
+ const argumentsTypes = [null, null, null, 'u64'] satisfies (string | null)[];
950
+ const parameterNames = ['vault', 'AdminCap', 'config', 'amount'];
951
+ return (tx: Transaction) =>
952
+ tx.moveCall({
953
+ package: packageAddress,
954
+ module: 'plp',
955
+ function: 'withdraw_fee_incentives',
956
+ arguments: normalizeMoveArguments(
957
+ {
958
+ ...options.arguments,
959
+ vault: options.arguments?.vault ?? options.config?.poolVault,
960
+ config: options.arguments?.config ?? options.config?.protocolConfig,
961
+ },
962
+ argumentsTypes,
963
+ parameterNames,
964
+ ),
965
+ });
966
+ }
967
+ export interface AddUsdcToPlpArguments {
968
+ vault?: RawTransactionArgument<string>;
969
+ config?: RawTransactionArgument<string>;
970
+ payment: RawTransactionArgument<string>;
971
+ }
972
+ export interface AddUsdcToPlpOptions {
973
+ package?: string;
974
+ arguments: AddUsdcToPlpArguments;
975
+ config?: {
976
+ poolVault: ConfigValue;
977
+ protocolConfig: ConfigValue;
978
+ predictPackageId?: string;
979
+ };
980
+ }
981
+ /**
982
+ * Add USDC straight to pool idle liquidity without minting any PLP. Anyone may
983
+ * call it; the payment is an outright gift to the existing share base, so the
984
+ * caller receives nothing back and no share of it is recoverable.
985
+ *
986
+ * This is the incentive/top-up path: because no shares are issued, the whole
987
+ * `payment` lands inside the value the next flush's mark divides by an unchanged
988
+ * `total_supply`, which raises NAV per PLP for every current holder. It
989
+ * deliberately does not touch the profit basis — the basis tracks cash sent to and
990
+ * returned from expiries, so an outside contribution is neither a debit nor a
991
+ * credit, and the protocol reserve therefore takes no cut of it (`pool_value`
992
+ * leaves `exclusion` unchanged while `gross_pool_value` grows). Sending the same
993
+ * USDC through `request_supply` instead mints shares against it, so only the
994
+ * supply fee would reach existing holders — zero as shipped.
995
+ *
996
+ * Three gates, each closing a state this entrypoint would otherwise manufacture:
997
+ *
998
+ * - **Bootstrapped pool.** At `total_supply == 0` there is no share base to
999
+ * credit; the USDC would only inflate the genesis lock's non-withdrawable stake.
1000
+ * - **Contribution price ceiling.** Pool cash after the contribution — idle plus
1001
+ * the net cash deployed into active expiries — may price at most
1002
+ * `contribution_price_ceiling_factor` USDC per PLP, a tenth of the band a flush
1003
+ * mark needs to be fillable. Above the band every supply and withdraw head is
1004
+ * refunded (RP-2) and `total_supply` grows only through a supply fill, so
1005
+ * nothing brings the price back down — a terminal state that an unbounded
1006
+ * contribution against a small share base would otherwise reach for the price of
1007
+ * the contribution. The ceiling sits well inside the band because later fills
1008
+ * only push the price up (rounding and retained fees stay in the pool), so a
1009
+ * pool left exactly at the band would leave it on the next uneven or fee-charged
1010
+ * fill. The test is one-sided because a contribution can only move the price up.
1011
+ * It reads pool cash rather than pool NAV — NAV needs a flush — and counts
1012
+ * deployed cash because the mark does: `rebalance_expiry_cash` is
1013
+ * permissionless, so an idle-only test could be emptied into a market and passed
1014
+ * again. Cash is exactly the protocol-controlled share: the guard forbids this
1015
+ * entrypoint from _manufacturing_ the degenerate ratio and leaves market-driven
1016
+ * NAV moves (trader premiums and P&L) to RP-1/RP-2, which own them.
1017
+ * - **No flush in flight.** The seal freezes idle mid-flush, so an ungated
1018
+ * contribution would land on one side or the other of that capture depending
1019
+ * only on when the contributor's transaction executed — either paying that
1020
+ * flush's queued withdrawals or not. `sponsor_fee_incentives` takes the same
1021
+ * gate. `rebalance_expiry_cash` may run mid-window because it only moves cash
1022
+ * between two figures the seal already froze; new value is different.
1023
+ */
1024
+ export function addUsdcToPlp(options: AddUsdcToPlpOptions) {
1025
+ const packageAddress =
1026
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
1027
+ const argumentsTypes = [null, null, null] satisfies (string | null)[];
1028
+ const parameterNames = ['vault', 'config', 'payment'];
1029
+ return (tx: Transaction) =>
1030
+ tx.moveCall({
1031
+ package: packageAddress,
1032
+ module: 'plp',
1033
+ function: 'add_usdc_to_plp',
1034
+ arguments: normalizeMoveArguments(
1035
+ {
1036
+ ...options.arguments,
1037
+ vault: options.arguments?.vault ?? options.config?.poolVault,
1038
+ config: options.arguments?.config ?? options.config?.protocolConfig,
1039
+ },
1040
+ argumentsTypes,
1041
+ parameterNames,
1042
+ ),
1043
+ });
1044
+ }
904
1045
  export interface LockCapitalArguments {
905
1046
  vault?: RawTransactionArgument<string>;
906
1047
  config?: RawTransactionArgument<string>;
@@ -11,16 +11,52 @@
11
11
  * an exact source-timestamp spot from Propbook's bounded recent history. The live
12
12
  * forward comes from one of two admin-selected sources
13
13
  * (`PricingConfig.use_pyth_spot_for_forward`): a fresh positive Pyth spot carrying
14
- * the Block Scholes basis, or the Block Scholes forward directly. Exact-history
15
- * reads do not apply live freshness policy.
14
+ * the Block Scholes basis, or the Block Scholes forward directly. A load falls
15
+ * back to the Block Scholes forward when the selected Pyth spot is stale or
16
+ * unavailable; valuation prices on that fallback, while every live trade (mints,
17
+ * mint quotes, and live redeems) refuses it through `assert_pyth_spot_fresh`.
18
+ * Exact-history reads do not apply live freshness policy.
19
+ *
20
+ * Delayed execution splits that read in two. `load_vol` validates the same live
21
+ * inputs when an order is admitted and returns the raw Block Scholes basis and SVI
22
+ * its receipt stores; `pricer_at` later rebuilds a `Pricer` from them at the
23
+ * order's committed Pyth tick. The `try_*` reads price exactly as `up_price` and
24
+ * `range_price` do, and return `none` where those abort, so an order-flow fill
25
+ * never aborts on a surface.
16
26
  */
17
27
 
18
28
  import { MoveStruct, normalizeMoveArguments } from '../utils/index.js';
19
- import { U128, U64 } from '../../bcs/integers.js';
20
29
  import { bcs } from '@mysten/sui/bcs';
30
+ import { U64, U128 } from '../../bcs/integers.js';
21
31
  import { type Transaction, type TransactionArgument } from '@mysten/sui/transactions';
22
32
  import * as i64 from './deps/fixed_math/i64.js';
23
33
  const $moduleName = '@local-pkg/deepbook_predict::pricing';
34
+ export const VolSnapshot = new MoveStruct({
35
+ name: `${$moduleName}::VolSnapshot`,
36
+ fields: {
37
+ /**
38
+ * Canonical Propbook Pyth source for the market's underlying; commit finds this
39
+ * feed in each Lazer update.
40
+ */
41
+ pyth_source_id: bcs.u32(),
42
+ /** The matched Block Scholes spot and forward, narrowed to Predict's width. */
43
+ bs_spot: U64,
44
+ bs_forward: U64,
45
+ /** Raw SVI parameters before roll-down, at 1e9. */
46
+ svi_a: i64.I64,
47
+ svi_b: U64,
48
+ svi_rho: i64.I64,
49
+ svi_m: i64.I64,
50
+ svi_sigma: U64,
51
+ /**
52
+ * Provider source timestamps of the three reads. The SVI one is also the roll-down
53
+ * anchor.
54
+ */
55
+ bs_spot_source_timestamp_ms: U64,
56
+ bs_forward_source_timestamp_ms: U64,
57
+ svi_source_timestamp_ms: U64,
58
+ },
59
+ });
24
60
  export const PricingSVI = new MoveStruct({
25
61
  name: `${$moduleName}::PricingSVI`,
26
62
  fields: {
@@ -56,10 +92,13 @@ export const Pricer = new MoveStruct({
56
92
  /**
57
93
  * Timestamps of the oracle observations this snapshot validated, as trade events
58
94
  * report them — each observation's own economic clock. Pyth carries its source
59
- * timestamp (`0` only when no usable normalized observation exists); Block Scholes
60
- * spot and forward carry the provider `value_timestamp`, and SVI carries the
61
- * provider `svi_timestamp`. Those timestamps are the clocks freshness gates and
62
- * SVI roll-down use.
95
+ * timestamp (`0` only when no usable normalized observation exists; a `pricer_at`
96
+ * Pricer carries the committed update's generation time); Block Scholes spot and
97
+ * forward carry the provider `value_timestamp`, and SVI carries the provider
98
+ * `svi_timestamp`. Those timestamps are the clocks freshness gates and SVI
99
+ * roll-down use. The Pyth timestamp, including its `0` sentinel, is also what
100
+ * `assert_pyth_spot_fresh` gates live trades on, so it must stay the value the
101
+ * load's forward selection read.
63
102
  */
64
103
  pyth_spot_source_timestamp_ms: U64,
65
104
  block_scholes_spot_source_timestamp_ms: U64,
@@ -24,7 +24,9 @@ export const PricingConfig = new MoveStruct({
24
24
  use_pyth_spot_for_forward: bcs.bool(),
25
25
  /**
26
26
  * Fixed wall-clock maximum age for Pyth spot; it does not vary with time to
27
- * expiry.
27
+ * expiry. Past it, while `use_pyth_spot_for_forward` is set, a live load falls
28
+ * back to the Block Scholes forward, which valuation prices on and every live
29
+ * trade (mint, mint quote, live redeem) refuses.
28
30
  */
29
31
  pyth_spot_freshness_ms: U64,
30
32
  /**