@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
@@ -1 +1 @@
1
- {"version":3,"file":"common.mjs","names":["account.generateAuth"],"sources":["../../../src/predict/tx/common.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction, TransactionArgument, TransactionResult } from '@mysten/sui/transactions';\nimport { toGeneratedConfig, type GeneratedConfig } from '../config/generated.js';\nimport type { PredictConfig } from '../config/index.js';\nimport { AccountContract, accountMoveCalls as account } from '../../account.js';\n\n// Predict's accounts ARE the shared on-chain account primitive (`packages/account`), so the\n// builders live in `@mysten/deepbook-v3/account` and this is the thin adapter that drives them with\n// Predict's deployed ids. The generated thunks are still used directly by `withAuth` below, which\n// wraps Predict's own entrypoints too — those take the same `Auth` hot potato.\nexport function accountContract(cfg: PredictConfig): AccountContract {\n\treturn new AccountContract({\n\t\taccountPackageId: cfg.packages.account,\n\t\taccountRegistry: cfg.objects.accountRegistry,\n\t});\n}\n\n/**\n * Owner authority is a hot-potato `Auth` minted from the tx sender (`ctx` is implicit in a PTB)\n * and consumed by the very next account-loading call (`load_account_mut` inside `deposit_funds` /\n * `withdraw_funds` / `mint` / …). It resolves to owner auth for whoever signs the transaction.\n * See `packages/account/sources/account.move`.\n */\nexport function generateAuth(cfg: PredictConfig): (tx: Transaction) => TransactionResult {\n\treturn account.generateAuth({ config: toGeneratedConfig(cfg) });\n}\n\n// The shape every generated binding shares: options in, one PTB command out.\ntype GeneratedCall<Options> = (options: Options) => (tx: Transaction) => TransactionResult;\n\n// The generated options of a call that consumes the hot-potato `Auth`. Codegen types\n// `arguments` as the named form OR a positional tuple; only the named form is used here.\ninterface AuthCallOptions {\n\targuments: { auth: TransactionArgument } | readonly unknown[];\n\tconfig?: object;\n\tpackage?: string;\n}\n\n// The named-`arguments` arm of such an options type (the tuple arm has no `auth` property).\ntype NamedArguments<Options extends AuthCallOptions> = Extract<\n\tOptions['arguments'],\n\t{ auth: TransactionArgument }\n>;\n\n/**\n * The options {@link withAuth} leaves to the caller: the generated ones, minus the `auth`\n * argument it supplies itself, with the projected config required (it is what mints the auth).\n */\nexport type WithAuthOptions<Options extends AuthCallOptions> = Omit<\n\tOptions,\n\t'arguments' | 'config'\n> & {\n\tconfig: GeneratedConfig;\n\targuments: Omit<NamedArguments<Options>, 'auth'>;\n};\n\n/**\n * Every owner-authorized call in this SDK is the same two commands — mint the hot-potato `Auth`,\n * then make the generated call that consumes it. This lifts a generated binding into that pair,\n * so such a builder is declared rather than written: `withAuth(account.depositFunds)` takes\n * `deposit_funds`'s own options with the `auth` slot already filled.\n */\nexport function withAuth<Options extends AuthCallOptions>(\n\tcall: GeneratedCall<Options>,\n): (options: WithAuthOptions<Options>) => (tx: Transaction) => TransactionResult {\n\treturn (options) => (tx) => {\n\t\tconst auth = tx.add(account.generateAuth({ config: options.config }));\n\t\t// The one unchecked step: with `Options` still generic, TS cannot see that putting `auth`\n\t\t// back makes the arguments whole again. Callers get the fully checked type above.\n\t\treturn tx.add(\n\t\t\tcall({ ...options, arguments: { ...options.arguments, auth } } as unknown as Options),\n\t\t);\n\t};\n}\n\n// The derivation must agree with on-chain `derive_address`, so it is owned in one place:\n// `@mysten/deepbook-v3/account`. This projects Predict's config onto that contract.\nexport function deriveAccountWrapperIdFrom(\n\tconfig: Pick<GeneratedConfig, 'accountRegistry' | 'accountPackageId'>,\n\towner: string,\n): string {\n\treturn new AccountContract({\n\t\taccountPackageId: config.accountPackageId,\n\t\taccountRegistry: config.accountRegistry,\n\t}).deriveAccountWrapperId(owner);\n}\n\n/** The deterministic id of an owner's canonical account wrapper — no chain read needed. */\nexport function deriveAccountWrapperId(cfg: PredictConfig, owner: string): string {\n\treturn deriveAccountWrapperIdFrom(toGeneratedConfig(cfg), owner);\n}\n"],"mappings":";;;;;AAWA,SAAgB,gBAAgB,KAAqC;AACpE,QAAO,IAAI,gBAAgB;EAC1B,kBAAkB,IAAI,SAAS;EAC/B,iBAAiB,IAAI,QAAQ;EAC7B,CAAC;;;;;;;;AASH,SAAgB,aAAa,KAA4D;AACxF,QAAOA,eAAqB,EAAE,QAAQ,kBAAkB,IAAI,EAAE,CAAC;;;;;;;;AAsChE,SAAgB,SACf,MACgF;AAChF,SAAQ,aAAa,OAAO;EAC3B,MAAM,OAAO,GAAG,IAAIA,eAAqB,EAAE,QAAQ,QAAQ,QAAQ,CAAC,CAAC;AAGrE,SAAO,GAAG,IACT,KAAK;GAAE,GAAG;GAAS,WAAW;IAAE,GAAG,QAAQ;IAAW;IAAM;GAAE,CAAuB,CACrF;;;AAMH,SAAgB,2BACf,QACA,OACS;AACT,QAAO,IAAI,gBAAgB;EAC1B,kBAAkB,OAAO;EACzB,iBAAiB,OAAO;EACxB,CAAC,CAAC,uBAAuB,MAAM;;;AAIjC,SAAgB,uBAAuB,KAAoB,OAAuB;AACjF,QAAO,2BAA2B,kBAAkB,IAAI,EAAE,MAAM"}
1
+ {"version":3,"file":"common.mjs","names":["account.generateAuth"],"sources":["../../../src/predict/tx/common.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { bcs } from '@mysten/sui/bcs';\nimport type { Transaction, TransactionArgument, TransactionResult } from '@mysten/sui/transactions';\nimport { deriveObjectID } from '@mysten/sui/utils';\nimport { toGeneratedConfig, type GeneratedConfig } from '../config/generated.js';\nimport type { PredictConfig } from '../config/index.js';\nimport { AccountContract, accountMoveCalls as account } from '../../account.js';\n\n// Predict's accounts ARE the shared on-chain account primitive (`packages/account`), so the\n// builders live in `@mysten/deepbook-v3/account` and this is the thin adapter that drives them with\n// Predict's deployed ids. The generated thunks are still used directly by `withAuth` below, which\n// wraps Predict's own entrypoints too — those take the same `Auth` hot potato.\nexport function accountContract(cfg: PredictConfig): AccountContract {\n\treturn new AccountContract({\n\t\taccountPackageId: cfg.packages.account,\n\t\taccountRegistry: cfg.objects.accountRegistry,\n\t});\n}\n\n/**\n * Owner authority is a hot-potato `Auth` minted from the tx sender (`ctx` is implicit in a PTB)\n * and consumed by the very next account-loading call (`load_account_mut` inside `deposit_funds` /\n * `withdraw_funds` / `mint` / …). It resolves to owner auth for whoever signs the transaction.\n * See `packages/account/sources/account.move`.\n */\nexport function generateAuth(cfg: PredictConfig): (tx: Transaction) => TransactionResult {\n\treturn account.generateAuth({ config: toGeneratedConfig(cfg) });\n}\n\n// The shape every generated binding shares: options in, one PTB command out.\ntype GeneratedCall<Options> = (options: Options) => (tx: Transaction) => TransactionResult;\n\n// The generated options of a call that consumes the hot-potato `Auth`. Codegen types\n// `arguments` as the named form OR a positional tuple; only the named form is used here.\ninterface AuthCallOptions {\n\targuments: { auth: TransactionArgument } | readonly unknown[];\n\tconfig?: object;\n\tpackage?: string;\n}\n\n// The named-`arguments` arm of such an options type (the tuple arm has no `auth` property).\ntype NamedArguments<Options extends AuthCallOptions> = Extract<\n\tOptions['arguments'],\n\t{ auth: TransactionArgument }\n>;\n\n/**\n * The options {@link withAuth} leaves to the caller: the generated ones, minus the `auth`\n * argument it supplies itself, with the projected config required (it is what mints the auth).\n * The config must also carry every key the wrapped call resolves, so a call into the order-flow\n * companion can't be handed a slice without its desk.\n */\nexport type WithAuthOptions<Options extends AuthCallOptions> = Omit<\n\tOptions,\n\t'arguments' | 'config'\n> & {\n\tconfig: GeneratedConfig & NonNullable<Options['config']>;\n\targuments: Omit<NamedArguments<Options>, 'auth'>;\n};\n\n/**\n * Every owner-authorized call in this SDK is the same two commands — mint the hot-potato `Auth`,\n * then make the generated call that consumes it. This lifts a generated binding into that pair,\n * so such a builder is declared rather than written: `withAuth(account.depositFunds)` takes\n * `deposit_funds`'s own options with the `auth` slot already filled.\n */\nexport function withAuth<Options extends AuthCallOptions>(\n\tcall: GeneratedCall<Options>,\n): (options: WithAuthOptions<Options>) => (tx: Transaction) => TransactionResult {\n\treturn (options) => (tx) => {\n\t\tconst auth = tx.add(account.generateAuth({ config: options.config }));\n\t\t// The one unchecked step: with `Options` still generic, TS cannot see that putting `auth`\n\t\t// back makes the arguments whole again. Callers get the fully checked type above.\n\t\treturn tx.add(\n\t\t\tcall({ ...options, arguments: { ...options.arguments, auth } } as unknown as Options),\n\t\t);\n\t};\n}\n\n// The derivation must agree with on-chain `derive_address`, so it is owned in one place:\n// `@mysten/deepbook-v3/account`. This projects Predict's config onto that contract.\nexport function deriveAccountWrapperIdFrom(\n\tconfig: Pick<GeneratedConfig, 'accountRegistry' | 'accountPackageId'>,\n\towner: string,\n): string {\n\treturn new AccountContract({\n\t\taccountPackageId: config.accountPackageId,\n\t\taccountRegistry: config.accountRegistry,\n\t}).deriveAccountWrapperId(owner);\n}\n\n/** The deterministic id of an owner's canonical account wrapper — no chain read needed. */\nexport function deriveAccountWrapperId(cfg: PredictConfig, owner: string): string {\n\treturn deriveAccountWrapperIdFrom(toGeneratedConfig(cfg), owner);\n}\n\n// `account_registry::AccountKey(owner)`: a one-field positional struct, so its BCS is the bare\n// 32-byte address.\nconst AccountKey = bcs.struct('AccountKey', { pos0: bcs.Address });\n\n/**\n * The owner's canonical ACCOUNT id (`Account.account_id`), a different derived object from the\n * wrapper: `derive_address(registry, AccountKey(owner))`. Queue records and events name accounts\n * by it, and `queue::waiting_orders` takes it.\n */\nexport function deriveAccountIdFrom(\n\tconfig: Pick<GeneratedConfig, 'accountRegistry' | 'accountPackageId'>,\n\towner: string,\n): string {\n\treturn deriveObjectID(\n\t\tconfig.accountRegistry,\n\t\t`${config.accountPackageId}::account_registry::AccountKey`,\n\t\tAccountKey.serialize({ pos0: owner }).toBytes(),\n\t);\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,gBAAgB,KAAqC;AACpE,QAAO,IAAI,gBAAgB;EAC1B,kBAAkB,IAAI,SAAS;EAC/B,iBAAiB,IAAI,QAAQ;EAC7B,CAAC;;;;;;;;AASH,SAAgB,aAAa,KAA4D;AACxF,QAAOA,eAAqB,EAAE,QAAQ,kBAAkB,IAAI,EAAE,CAAC;;;;;;;;AAwChE,SAAgB,SACf,MACgF;AAChF,SAAQ,aAAa,OAAO;EAC3B,MAAM,OAAO,GAAG,IAAIA,eAAqB,EAAE,QAAQ,QAAQ,QAAQ,CAAC,CAAC;AAGrE,SAAO,GAAG,IACT,KAAK;GAAE,GAAG;GAAS,WAAW;IAAE,GAAG,QAAQ;IAAW;IAAM;GAAE,CAAuB,CACrF;;;AAMH,SAAgB,2BACf,QACA,OACS;AACT,QAAO,IAAI,gBAAgB;EAC1B,kBAAkB,OAAO;EACzB,iBAAiB,OAAO;EACxB,CAAC,CAAC,uBAAuB,MAAM;;;AAIjC,SAAgB,uBAAuB,KAAoB,OAAuB;AACjF,QAAO,2BAA2B,kBAAkB,IAAI,EAAE,MAAM;;AAKjE,MAAM,aAAa,IAAI,OAAO,cAAc,EAAE,MAAM,IAAI,SAAS,CAAC;;;;;;AAOlE,SAAgB,oBACf,QACA,OACS;AACT,QAAO,eACN,OAAO,iBACP,GAAG,OAAO,iBAAiB,iCAC3B,WAAW,UAAU,EAAE,MAAM,OAAO,CAAC,CAAC,SAAS,CAC/C"}
@@ -0,0 +1,220 @@
1
+ import { GeneratedConfig, OrdersGeneratedConfig } from "../config/generated.mjs";
2
+ import { MarketFeeds } from "./trade.mjs";
3
+ import { Transaction, TransactionResult } from "@mysten/sui/transactions";
4
+
5
+ //#region src/predict/tx/queue.d.ts
6
+ declare namespace queue_d_exports {
7
+ export { LazerPackages, QueueTarget, adminRefund, assertOrderFeeAtMost, claimParked, cleanup, commit, createQueue, enqueueExactAmount, enqueueExactCost, enqueueExactQuantity, enqueueRedeemOpen, fill, parseLazerUpdate, payOpen, queueIdOf, rebalanceExpiryCash, refund, resolve, settleStep };
8
+ }
9
+ /** One market's queue. */
10
+ interface QueueTarget {
11
+ expiryMarketId: string;
12
+ /**
13
+ * The market's `MarketQueue`. Defaults to `deriveQueueId(config.queueRegistry, expiryMarketId)`,
14
+ * the ID `queue::create_and_share` gives it, so pass it only to address another registry's
15
+ * queue.
16
+ */
17
+ queueId?: string;
18
+ }
19
+ /** The queue ID a thunk addresses: the given one, or the one derived from the config's registry. */
20
+ declare function queueIdOf(config: Pick<OrdersGeneratedConfig, 'queueRegistry'>, args: QueueTarget): string;
21
+ /** The market, queue and account every queued order names. */
22
+ interface QueuedOrderTarget extends MarketFeeds, QueueTarget {
23
+ wrapperId: string;
24
+ }
25
+ /**
26
+ * Queue a mint of an exact payout quantity, priced at Pyth's signed price for its τ
27
+ * (`queue::enqueue_exact_quantity`). Returns the record ID (u64). `maxCostRaw` (all-in cap) and
28
+ * `maxProbabilityRaw` (entry-probability cap, at most 1e9) are required: there is no "unlimited"
29
+ * default on the queued path. Escrows `min(max_cost, quantity, available − fee)` plus the order
30
+ * fee. Command order is auth → enqueue.
31
+ */
32
+ declare function enqueueExactQuantity(config: OrdersGeneratedConfig, args: QueuedOrderTarget & {
33
+ lowerTick: bigint;
34
+ higherTick: bigint;
35
+ quantityRaw: bigint;
36
+ maxCostRaw: bigint;
37
+ maxProbabilityRaw: bigint;
38
+ }): (tx: Transaction) => TransactionResult;
39
+ /**
40
+ * Queue a premium-budget mint (`queue::enqueue_exact_amount`): sized at τ under
41
+ * `maxPremiumRaw`, at least `minQuantityRaw`, with the all-in withdrawal capped by the required
42
+ * `maxCostRaw`. Escrows `min(max_cost, available − fee)` plus the order fee. Returns the record
43
+ * ID. Command order is auth → enqueue. `maxPremiumRaw` below the minimum premium (1 USDC) is
44
+ * refused: the fill could never buy enough premium, so Predict's admission dry run would abort
45
+ * `EOrderFailsLimits`.
46
+ */
47
+ declare function enqueueExactAmount(config: OrdersGeneratedConfig, args: QueuedOrderTarget & {
48
+ lowerTick: bigint;
49
+ higherTick: bigint;
50
+ maxPremiumRaw: bigint;
51
+ minQuantityRaw: bigint;
52
+ maxCostRaw: bigint;
53
+ }): (tx: Transaction) => TransactionResult;
54
+ /**
55
+ * Queue an all-in-budget mint (`queue::enqueue_exact_cost`): sized at τ so the all-in cost fits
56
+ * `maxCostRaw`, at least `minQuantityRaw`. `maxCostRaw` is the budget and must be a real cap.
57
+ * Escrows `min(max_cost, available − fee)` plus the order fee. Returns the record ID. Command
58
+ * order is auth → enqueue.
59
+ */
60
+ declare function enqueueExactCost(config: OrdersGeneratedConfig, args: QueuedOrderTarget & {
61
+ lowerTick: bigint;
62
+ higherTick: bigint;
63
+ maxCostRaw: bigint;
64
+ minQuantityRaw: bigint;
65
+ }): (tx: Transaction) => TransactionResult;
66
+ /**
67
+ * Queue an early sell of `closeQuantityRaw` from the Open record `recordId`
68
+ * (`queue::enqueue_redeem_open`; the queue record ID, not the position's u256 order ID). The
69
+ * only early sell: a position held in the account can't be sold early. The record must be Open
70
+ * and belong to this account. `minProbabilityRaw` and `minProceedsRaw` are the close-side floors
71
+ * at τ and are required (`0n` disables either, so pass it on purpose). Escrows only the order
72
+ * fee. Returns the new record ID, which holds the position until the sell fills or refunds.
73
+ * Command order is auth → enqueue.
74
+ */
75
+ declare function enqueueRedeemOpen(config: OrdersGeneratedConfig, args: QueuedOrderTarget & {
76
+ recordId: bigint;
77
+ closeQuantityRaw: bigint;
78
+ minProbabilityRaw: bigint;
79
+ minProceedsRaw: bigint;
80
+ }): (tx: Transaction) => TransactionResult;
81
+ /**
82
+ * Abort the transaction unless the order desk's fee is at most `maxOrderFeeRaw` when it executes.
83
+ * The enqueues charge the desk's fee at execution and take no fee bound, so add this BEFORE an
84
+ * enqueue to hold it to the fee its preview showed. It reads the desk's policy, and
85
+ * `0x1::u64::checked_sub(max, fee)` is none once the fee is above the bound, so
86
+ * `0x1::option::destroy_some` aborts (`option::EOPTION_NOT_SET`, code 0x40001) before the
87
+ * enqueue debits anything. Read-only on the desk.
88
+ */
89
+ declare function assertOrderFeeAtMost(config: OrdersGeneratedConfig, maxOrderFeeRaw: bigint): (tx: Transaction) => void;
90
+ /**
91
+ * Fund a live market from the pool vault to `max(required × (1 + rebalance %), initial cash,
92
+ * required + waiting_cash_need)` (Predict's `plp::rebalance_expiry_cash`). Permissionless, and
93
+ * takes no target. Add it AFTER a big sell's enqueue in the same PTB: the enqueue has already
94
+ * added the sell's cash need to Predict's waiting total, so the rebalance funds it at once. It
95
+ * takes the hot `PoolVault`, so add it only when a sell's cash need is above spare cash.
96
+ */
97
+ declare function rebalanceExpiryCash(config: GeneratedConfig, args: {
98
+ expiryMarketId: string;
99
+ }): (tx: Transaction) => TransactionResult;
100
+ /**
101
+ * Create and share a market's `MarketQueue` (`queue::create_and_share(registry, desk, market)`),
102
+ * at the ID `deriveQueueId(config.queueRegistry, expiryMarketId)`. Takes the registry mutably and
103
+ * the desk read-only, so it never contends with trading. Permissionless and once per market (a
104
+ * second call aborts, since the ID is taken); the caller pays its storage. The market-creation
105
+ * keeper sends it after each new `ExpiryMarket`. Returns the queue ID.
106
+ */
107
+ declare function createQueue(config: OrdersGeneratedConfig, args: {
108
+ expiryMarketId: string;
109
+ }): (tx: Transaction) => TransactionResult;
110
+ /**
111
+ * Refund this market's waiting orders at or past their deadline (`queue::refund`, reason 5),
112
+ * visiting at most `maxOrders` records (the chain caps one call at 450). Permissionless: no auth,
113
+ * session or Pyth key, and it works during a freeze. Returns how many it refunded, `0` without
114
+ * aborting when none is due. Send it only from the app's refund button, never prepended to other
115
+ * transactions: keepers refund on their own. Every visited record counts toward Sui's
116
+ * per-transaction object limit.
117
+ */
118
+ declare function refund(config: OrdersGeneratedConfig, args: QueueTarget & {
119
+ maxOrders: bigint | number;
120
+ }): (tx: Transaction) => TransactionResult;
121
+ /**
122
+ * Refund the listed waiting orders at once (`queue::admin_refund`, reason 7), wherever they sit
123
+ * in the queue. Takes Predict's `AdminCap`, and works while Predict is frozen. Missing and
124
+ * finished record IDs are skipped.
125
+ */
126
+ declare function adminRefund(config: OrdersGeneratedConfig, args: QueueTarget & {
127
+ adminCapId: string;
128
+ recordIds: readonly bigint[];
129
+ }): (tx: Transaction) => TransactionResult;
130
+ /**
131
+ * Delete Refunded and Closed records of a settled market (`queue::cleanup`). Permissionless; the
132
+ * storage rebate goes to the sender. Missing IDs, other statuses and records still holding a
133
+ * receipt or funds (parked funds included, until `claimParked`) are skipped. Aborts
134
+ * `EMarketNotSettled` before settlement.
135
+ */
136
+ declare function cleanup(config: OrdersGeneratedConfig, args: QueueTarget & {
137
+ recordIds: readonly bigint[];
138
+ }): (tx: Transaction) => TransactionResult;
139
+ /**
140
+ * Run one bounded settlement phase on a market's queue (`queue::settle_step`) and return the
141
+ * phase the queue is in afterwards (u8, `queue.SETTLE_PHASE`): `0` DRAIN refunds the waiting
142
+ * orders, `1` PAY pays the Open records once Predict has settled the market, `2` DONE once the
143
+ * payout walk has reached the last record. Send one call per transaction until it returns `2` (or
144
+ * `MarketPayoutsCompleted` is emitted), after Predict's `try_settle`. A record the market couldn't
145
+ * pay stays Open with `OpenRecordPayoutSkipped`, even after DONE. Permissionless. Aborts
146
+ * `EMarketNotExpired` before expiry.
147
+ */
148
+ declare function settleStep(config: OrdersGeneratedConfig, args: QueueTarget): (tx: Transaction) => TransactionResult;
149
+ /**
150
+ * Pay one Open record of a settled market its settled payout (`queue::pay_open`), at any time
151
+ * after settlement, before or after `settle_step` completes: a record the payout walk skipped
152
+ * because the market was short of cash or its receive address was denied. Permissionless: the
153
+ * payout goes only to the record's own receive address. Emits `OpenRecordSettled`, or
154
+ * `OpenRecordPayoutSkipped` again while the cause persists. A missing or non-Open record is left
155
+ * alone. Aborts `EMarketNotSettled` before Predict settles the market.
156
+ */
157
+ declare function payOpen(config: OrdersGeneratedConfig, args: QueueTarget & {
158
+ recordId: bigint;
159
+ }): (tx: Transaction) => TransactionResult;
160
+ /**
161
+ * Send a finished record's parked funds (`queue::claim_parked`): change or a refund its receive
162
+ * address couldn't take while it was on USDC's deny list or USDC was paused. Permissionless: the
163
+ * funds go only to the record's own receive address. Returns the amount sent (u64), or `0` and
164
+ * changes nothing for a missing or unfinished record, one with nothing parked, or an address still
165
+ * denied. Emits `RecordFundsClaimed`. Takes no market: `expiryMarketId` only derives the queue.
166
+ */
167
+ declare function claimParked(config: OrdersGeneratedConfig, args: QueueTarget & {
168
+ recordId: bigint;
169
+ }): (tx: Transaction) => TransactionResult;
170
+ /** The current Pyth Lazer package and the original ID that types its `Update`. */
171
+ interface LazerPackages {
172
+ /** Lazer's shared `State`. */
173
+ stateId: string;
174
+ /** The package to call `parse_and_verify_le_ecdsa_update` on: `State.upgrade_cap.package`. */
175
+ packageId: string;
176
+ /** The original package ID, which `update::Update` is typed by. */
177
+ originalId: string;
178
+ }
179
+ /**
180
+ * Verify one signed Lazer payload with the current Lazer package. A positional call on purpose:
181
+ * the oracle-construction packages are not generated (see `sui-codegen.config.ts`).
182
+ */
183
+ declare function parseLazerUpdate(lazer: Pick<LazerPackages, 'stateId' | 'packageId'>, payload: Uint8Array): (tx: Transaction) => TransactionResult;
184
+ /**
185
+ * Verify the signed Lazer payloads and commit them to the market's waiting cohorts
186
+ * (`queue::commit`). Permissionless. Pass the payloads for a cohort's exact τ, or a backup tick
187
+ * once τ + gap wait has passed with τ uncommitted (when the policy's price buffer is on). Commit
188
+ * matches each update to its own cohort by τ and skips one that matches nothing, so no
189
+ * head-of-line ordering is assumed. Resolve `lazer` per batch with `read.lazerPackages` and never
190
+ * cache it: a Pyth upgrade retires the old package at once.
191
+ */
192
+ declare function commit(config: OrdersGeneratedConfig, args: QueueTarget & {
193
+ payloads: readonly Uint8Array[];
194
+ lazer: LazerPackages;
195
+ }): (tx: Transaction) => TransactionResult;
196
+ /**
197
+ * Fill or refund committed orders in τ order (`queue::resolve`), visiting at most `maxOrders`
198
+ * records (the chain caps one call at 450, since a fill emits two events and Sui allows 1,024
199
+ * per transaction). Permissionless. Returns how many orders it finished. An order the market
200
+ * can't cover is refunded with reason 8. Size `maxOrders` against the payout tree
201
+ * (`payoutTreeNodeCount`): about 10 to 15 fills fit one transaction in a full tree.
202
+ */
203
+ declare function resolve(config: OrdersGeneratedConfig, args: QueueTarget & {
204
+ maxOrders: bigint | number;
205
+ }): (tx: Transaction) => TransactionResult;
206
+ /**
207
+ * The open filler (no cap exists): {@link commit} the signed Lazer payloads, then
208
+ * {@link resolve} up to `maxOrders` records. Anyone with Pyth Lazer access can run it. With
209
+ * `refundOverdue`, a final `refund` call sweeps orders past their deadline. Returns the resolve
210
+ * result. Split commit from resolve when the payout tree is large.
211
+ */
212
+ declare function fill(config: OrdersGeneratedConfig, args: QueueTarget & {
213
+ payloads: readonly Uint8Array[];
214
+ lazer: LazerPackages;
215
+ maxOrders: bigint | number;
216
+ refundOverdue?: boolean;
217
+ }): (tx: Transaction) => TransactionResult;
218
+ //#endregion
219
+ export { LazerPackages, queue_d_exports };
220
+ //# sourceMappingURL=queue.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.mts","names":[],"sources":["../../../src/predict/tx/queue.ts"],"mappings":";;;;;;;;;UA6CiB,WAAA;EAChB,cAAA;;;;;;EAMA,OAAA;AAAA;;iBAIe,SAAA,CACf,MAAA,EAAQ,IAAA,CAAK,qBAAA,oBACb,IAAA,EAAM,WAAA;;UAMG,iBAAA,SAA0B,WAAA,EAAa,WAAA;EAChD,SAAA;AAAA;;;;;;;;iBAsCe,oBAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,iBAAA;EACL,SAAA;EACA,UAAA;EACA,WAAA;EACA,UAAA;EACA,iBAAA;AAAA,KAEE,EAAA,EAAI,WAAA,KAAgB,iBAAA;AAxDxB;;;;;;;;AAAA,iBAyFgB,kBAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,iBAAA;EACL,SAAA;EACA,UAAA;EACA,aAAA;EACA,cAAA;EACA,UAAA;AAAA,KAEE,EAAA,EAAI,WAAA,KAAgB,iBAAA;AA7FvB;;;;;;AAAA,iBAyHe,gBAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,iBAAA;EACL,SAAA;EACA,UAAA;EACA,UAAA;EACA,cAAA;AAAA,KAEE,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;;;;;;;;iBAwBR,iBAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,iBAAA;EACL,QAAA;EACA,gBAAA;EACA,iBAAA;EACA,cAAA;AAAA,KAEE,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;;;;AA7ExB;;;iBA0GgB,oBAAA,CACf,MAAA,EAAQ,qBAAA,EACR,cAAA,YACG,EAAA,EAAI,WAAA;;;;;;;;iBAwBQ,mBAAA,CACf,MAAA,EAAQ,eAAA,EACR,IAAA;EAAQ,cAAA;AAAA,KACL,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;;;;;;iBAWR,WAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA;EAAQ,cAAA;AAAA,KACL,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;;;;;;;iBAYR,MAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,WAAA;EAAgB,SAAA;AAAA,KACnB,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;;;;iBAgBR,WAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,WAAA;EAAgB,UAAA;EAAoB,SAAA;AAAA,KACvC,EAAA,EAAI,WAAA,KAAgB,iBAAA;;AAnHxB;;;;;iBAqIgB,OAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,WAAA;EAAgB,SAAA;AAAA,KACnB,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;;;;;;;;iBAoBR,UAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,WAAA,IACH,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;;;AA1HxB;;;;iBAyIgB,OAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,WAAA;EAAgB,QAAA;AAAA,KACnB,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;;;AAjHxB;;;iBAoIgB,WAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,WAAA;EAAgB,QAAA;AAAA,KACnB,EAAA,EAAI,WAAA,KAAgB,iBAAA;;UASP,aAAA;EA/IR;EAiJR,OAAA;EAhJQ;EAkJR,SAAA;EAjJO;EAmJP,UAAA;AAAA;;;AAxID;;iBA+IgB,gBAAA,CACf,KAAA,EAAO,IAAA,CAAK,aAAA,4BACZ,OAAA,EAAS,UAAA,IACN,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;;;;;;;iBAgBR,MAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,WAAA;EAAgB,QAAA,WAAmB,UAAA;EAAc,KAAA,EAAO,aAAA;AAAA,KAC3D,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;AAtJxB;;;;;iBAgLgB,OAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,WAAA;EAAgB,SAAA;AAAA,KACnB,EAAA,EAAI,WAAA,KAAgB,iBAAA;;;;;;;iBAiBR,IAAA,CACf,MAAA,EAAQ,qBAAA,EACR,IAAA,EAAM,WAAA;EACL,QAAA,WAAmB,UAAA;EACnB,KAAA,EAAO,aAAA;EACP,SAAA;EACA,aAAA;AAAA,KAEE,EAAA,EAAI,WAAA,KAAgB,iBAAA"}
@@ -0,0 +1,399 @@
1
+ import { __exportAll } from "../../_virtual/rolldown_runtime.mjs";
2
+ import { deriveQueueId } from "../queue-id.mjs";
3
+ import { PredictInputError } from "../errors.mjs";
4
+ import { U64_MAX } from "../units.mjs";
5
+ import { MIN_PREMIUM } from "../cost.mjs";
6
+ import { orderFee } from "../../contracts/deepbook_predict_orders/delayed_execution_config.mjs";
7
+ import { withAuth } from "./common.mjs";
8
+ import { rebalanceExpiryCash as rebalanceExpiryCash$1 } from "../../contracts/deepbook_predict/plp.mjs";
9
+ import { policy } from "../../contracts/deepbook_predict_orders/desk.mjs";
10
+ import { adminRefund as adminRefund$1, claimParked as claimParked$1, cleanup as cleanup$1, commit as commit$1, createAndShare, enqueueExactAmount as enqueueExactAmount$1, enqueueExactCost as enqueueExactCost$1, enqueueExactQuantity as enqueueExactQuantity$1, enqueueRedeemOpen as enqueueRedeemOpen$1, payOpen as payOpen$1, refund as refund$1, resolve as resolve$1, settleStep as settleStep$1 } from "../../contracts/deepbook_predict_orders/queue.mjs";
11
+
12
+ //#region src/predict/tx/queue.ts
13
+ var queue_exports = /* @__PURE__ */ __exportAll({
14
+ adminRefund: () => adminRefund,
15
+ assertOrderFeeAtMost: () => assertOrderFeeAtMost,
16
+ claimParked: () => claimParked,
17
+ cleanup: () => cleanup,
18
+ commit: () => commit,
19
+ createQueue: () => createQueue,
20
+ enqueueExactAmount: () => enqueueExactAmount,
21
+ enqueueExactCost: () => enqueueExactCost,
22
+ enqueueExactQuantity: () => enqueueExactQuantity,
23
+ enqueueRedeemOpen: () => enqueueRedeemOpen,
24
+ fill: () => fill,
25
+ parseLazerUpdate: () => parseLazerUpdate,
26
+ payOpen: () => payOpen,
27
+ queueIdOf: () => queueIdOf,
28
+ rebalanceExpiryCash: () => rebalanceExpiryCash,
29
+ refund: () => refund,
30
+ resolve: () => resolve,
31
+ settleStep: () => settleStep
32
+ });
33
+ const FLOAT_SCALING = 1000000000n;
34
+ const authed = {
35
+ enqueueExactQuantity: withAuth(enqueueExactQuantity$1),
36
+ enqueueExactAmount: withAuth(enqueueExactAmount$1),
37
+ enqueueExactCost: withAuth(enqueueExactCost$1),
38
+ enqueueRedeemOpen: withAuth(enqueueRedeemOpen$1)
39
+ };
40
+ /** The queue ID a thunk addresses: the given one, or the one derived from the config's registry. */
41
+ function queueIdOf(config, args) {
42
+ return args.queueId ?? deriveQueueId(config.queueRegistry, args.expiryMarketId);
43
+ }
44
+ function placement(config, args) {
45
+ return {
46
+ queue: queueIdOf(config, args),
47
+ market: args.expiryMarketId,
48
+ wrapper: args.wrapperId,
49
+ pyth: args.pythFeed,
50
+ bsValues: args.blockScholesValueStore,
51
+ bsSvi: args.blockScholesSviStore
52
+ };
53
+ }
54
+ function assertMaxCost(maxCostRaw) {
55
+ if (typeof maxCostRaw !== "bigint" || maxCostRaw <= 0n || maxCostRaw >= U64_MAX) throw new PredictInputError(`maxCostRaw must be above 0 and below u64::MAX (a queued mint requires a real cap), got ${String(maxCostRaw)}`);
56
+ }
57
+ function assertU64(value, name) {
58
+ if (typeof value !== "bigint" || value < 0n || value > U64_MAX) throw new PredictInputError(`${name} must be a u64 bigint, got ${String(value)}`);
59
+ }
60
+ /**
61
+ * Queue a mint of an exact payout quantity, priced at Pyth's signed price for its τ
62
+ * (`queue::enqueue_exact_quantity`). Returns the record ID (u64). `maxCostRaw` (all-in cap) and
63
+ * `maxProbabilityRaw` (entry-probability cap, at most 1e9) are required: there is no "unlimited"
64
+ * default on the queued path. Escrows `min(max_cost, quantity, available − fee)` plus the order
65
+ * fee. Command order is auth → enqueue.
66
+ */
67
+ function enqueueExactQuantity(config, args) {
68
+ assertMaxCost(args.maxCostRaw);
69
+ assertU64(args.quantityRaw, "quantityRaw");
70
+ if (typeof args.maxProbabilityRaw !== "bigint" || args.maxProbabilityRaw <= 0n || args.maxProbabilityRaw > FLOAT_SCALING) throw new PredictInputError(`maxProbabilityRaw must be in (0, 1e9], got ${String(args.maxProbabilityRaw)}`);
71
+ return authed.enqueueExactQuantity({
72
+ config,
73
+ arguments: {
74
+ ...placement(config, args),
75
+ lowerTick: args.lowerTick,
76
+ higherTick: args.higherTick,
77
+ quantity: args.quantityRaw,
78
+ maxCost: args.maxCostRaw,
79
+ maxProbability: args.maxProbabilityRaw
80
+ }
81
+ });
82
+ }
83
+ /**
84
+ * Queue a premium-budget mint (`queue::enqueue_exact_amount`): sized at τ under
85
+ * `maxPremiumRaw`, at least `minQuantityRaw`, with the all-in withdrawal capped by the required
86
+ * `maxCostRaw`. Escrows `min(max_cost, available − fee)` plus the order fee. Returns the record
87
+ * ID. Command order is auth → enqueue. `maxPremiumRaw` below the minimum premium (1 USDC) is
88
+ * refused: the fill could never buy enough premium, so Predict's admission dry run would abort
89
+ * `EOrderFailsLimits`.
90
+ */
91
+ function enqueueExactAmount(config, args) {
92
+ assertMaxCost(args.maxCostRaw);
93
+ assertU64(args.maxPremiumRaw, "maxPremiumRaw");
94
+ assertU64(args.minQuantityRaw, "minQuantityRaw");
95
+ if (args.maxPremiumRaw < MIN_PREMIUM) throw new PredictInputError(`maxPremiumRaw ${args.maxPremiumRaw} is below the ${MIN_PREMIUM} minimum premium (EOrderFailsLimits)`);
96
+ return authed.enqueueExactAmount({
97
+ config,
98
+ arguments: {
99
+ ...placement(config, args),
100
+ lowerTick: args.lowerTick,
101
+ higherTick: args.higherTick,
102
+ maxPremium: args.maxPremiumRaw,
103
+ minQuantity: args.minQuantityRaw,
104
+ maxCost: args.maxCostRaw
105
+ }
106
+ });
107
+ }
108
+ /**
109
+ * Queue an all-in-budget mint (`queue::enqueue_exact_cost`): sized at τ so the all-in cost fits
110
+ * `maxCostRaw`, at least `minQuantityRaw`. `maxCostRaw` is the budget and must be a real cap.
111
+ * Escrows `min(max_cost, available − fee)` plus the order fee. Returns the record ID. Command
112
+ * order is auth → enqueue.
113
+ */
114
+ function enqueueExactCost(config, args) {
115
+ assertMaxCost(args.maxCostRaw);
116
+ assertU64(args.minQuantityRaw, "minQuantityRaw");
117
+ return authed.enqueueExactCost({
118
+ config,
119
+ arguments: {
120
+ ...placement(config, args),
121
+ lowerTick: args.lowerTick,
122
+ higherTick: args.higherTick,
123
+ maxCost: args.maxCostRaw,
124
+ minQuantity: args.minQuantityRaw
125
+ }
126
+ });
127
+ }
128
+ /**
129
+ * Queue an early sell of `closeQuantityRaw` from the Open record `recordId`
130
+ * (`queue::enqueue_redeem_open`; the queue record ID, not the position's u256 order ID). The
131
+ * only early sell: a position held in the account can't be sold early. The record must be Open
132
+ * and belong to this account. `minProbabilityRaw` and `minProceedsRaw` are the close-side floors
133
+ * at τ and are required (`0n` disables either, so pass it on purpose). Escrows only the order
134
+ * fee. Returns the new record ID, which holds the position until the sell fills or refunds.
135
+ * Command order is auth → enqueue.
136
+ */
137
+ function enqueueRedeemOpen(config, args) {
138
+ assertU64(args.recordId, "recordId");
139
+ assertU64(args.minProbabilityRaw, "minProbabilityRaw");
140
+ assertU64(args.minProceedsRaw, "minProceedsRaw");
141
+ if (typeof args.closeQuantityRaw !== "bigint" || args.closeQuantityRaw <= 0n) throw new PredictInputError(`closeQuantityRaw must be above 0, got ${String(args.closeQuantityRaw)}`);
142
+ return authed.enqueueRedeemOpen({
143
+ config,
144
+ arguments: {
145
+ ...placement(config, args),
146
+ recordId: args.recordId,
147
+ closeQuantity: args.closeQuantityRaw,
148
+ minProbability: args.minProbabilityRaw,
149
+ minProceeds: args.minProceedsRaw
150
+ }
151
+ });
152
+ }
153
+ /**
154
+ * Abort the transaction unless the order desk's fee is at most `maxOrderFeeRaw` when it executes.
155
+ * The enqueues charge the desk's fee at execution and take no fee bound, so add this BEFORE an
156
+ * enqueue to hold it to the fee its preview showed. It reads the desk's policy, and
157
+ * `0x1::u64::checked_sub(max, fee)` is none once the fee is above the bound, so
158
+ * `0x1::option::destroy_some` aborts (`option::EOPTION_NOT_SET`, code 0x40001) before the
159
+ * enqueue debits anything. Read-only on the desk.
160
+ */
161
+ function assertOrderFeeAtMost(config, maxOrderFeeRaw) {
162
+ assertU64(maxOrderFeeRaw, "maxOrderFeeRaw");
163
+ return (tx) => {
164
+ const policy$1 = tx.add(policy({ config }));
165
+ const fee = tx.add(orderFee({
166
+ config,
167
+ arguments: { policy: policy$1 }
168
+ }));
169
+ const headroom = tx.moveCall({
170
+ target: "0x1::u64::checked_sub",
171
+ arguments: [tx.pure.u64(maxOrderFeeRaw), fee]
172
+ });
173
+ tx.moveCall({
174
+ target: "0x1::option::destroy_some",
175
+ typeArguments: ["u64"],
176
+ arguments: [headroom]
177
+ });
178
+ };
179
+ }
180
+ /**
181
+ * Fund a live market from the pool vault to `max(required × (1 + rebalance %), initial cash,
182
+ * required + waiting_cash_need)` (Predict's `plp::rebalance_expiry_cash`). Permissionless, and
183
+ * takes no target. Add it AFTER a big sell's enqueue in the same PTB: the enqueue has already
184
+ * added the sell's cash need to Predict's waiting total, so the rebalance funds it at once. It
185
+ * takes the hot `PoolVault`, so add it only when a sell's cash need is above spare cash.
186
+ */
187
+ function rebalanceExpiryCash(config, args) {
188
+ return rebalanceExpiryCash$1({
189
+ config,
190
+ arguments: { market: args.expiryMarketId }
191
+ });
192
+ }
193
+ /**
194
+ * Create and share a market's `MarketQueue` (`queue::create_and_share(registry, desk, market)`),
195
+ * at the ID `deriveQueueId(config.queueRegistry, expiryMarketId)`. Takes the registry mutably and
196
+ * the desk read-only, so it never contends with trading. Permissionless and once per market (a
197
+ * second call aborts, since the ID is taken); the caller pays its storage. The market-creation
198
+ * keeper sends it after each new `ExpiryMarket`. Returns the queue ID.
199
+ */
200
+ function createQueue(config, args) {
201
+ return createAndShare({
202
+ config,
203
+ arguments: { market: args.expiryMarketId }
204
+ });
205
+ }
206
+ /**
207
+ * Refund this market's waiting orders at or past their deadline (`queue::refund`, reason 5),
208
+ * visiting at most `maxOrders` records (the chain caps one call at 450). Permissionless: no auth,
209
+ * session or Pyth key, and it works during a freeze. Returns how many it refunded, `0` without
210
+ * aborting when none is due. Send it only from the app's refund button, never prepended to other
211
+ * transactions: keepers refund on their own. Every visited record counts toward Sui's
212
+ * per-transaction object limit.
213
+ */
214
+ function refund(config, args) {
215
+ return refund$1({
216
+ config,
217
+ arguments: {
218
+ queue: queueIdOf(config, args),
219
+ market: args.expiryMarketId,
220
+ maxOrders: args.maxOrders
221
+ }
222
+ });
223
+ }
224
+ /**
225
+ * Refund the listed waiting orders at once (`queue::admin_refund`, reason 7), wherever they sit
226
+ * in the queue. Takes Predict's `AdminCap`, and works while Predict is frozen. Missing and
227
+ * finished record IDs are skipped.
228
+ */
229
+ function adminRefund(config, args) {
230
+ return adminRefund$1({
231
+ config,
232
+ arguments: {
233
+ queue: queueIdOf(config, args),
234
+ market: args.expiryMarketId,
235
+ AdminCap: args.adminCapId,
236
+ recordIds: [...args.recordIds]
237
+ }
238
+ });
239
+ }
240
+ /**
241
+ * Delete Refunded and Closed records of a settled market (`queue::cleanup`). Permissionless; the
242
+ * storage rebate goes to the sender. Missing IDs, other statuses and records still holding a
243
+ * receipt or funds (parked funds included, until `claimParked`) are skipped. Aborts
244
+ * `EMarketNotSettled` before settlement.
245
+ */
246
+ function cleanup(config, args) {
247
+ return cleanup$1({
248
+ config,
249
+ arguments: {
250
+ queue: queueIdOf(config, args),
251
+ market: args.expiryMarketId,
252
+ recordIds: [...args.recordIds]
253
+ }
254
+ });
255
+ }
256
+ /**
257
+ * Run one bounded settlement phase on a market's queue (`queue::settle_step`) and return the
258
+ * phase the queue is in afterwards (u8, `queue.SETTLE_PHASE`): `0` DRAIN refunds the waiting
259
+ * orders, `1` PAY pays the Open records once Predict has settled the market, `2` DONE once the
260
+ * payout walk has reached the last record. Send one call per transaction until it returns `2` (or
261
+ * `MarketPayoutsCompleted` is emitted), after Predict's `try_settle`. A record the market couldn't
262
+ * pay stays Open with `OpenRecordPayoutSkipped`, even after DONE. Permissionless. Aborts
263
+ * `EMarketNotExpired` before expiry.
264
+ */
265
+ function settleStep(config, args) {
266
+ return settleStep$1({
267
+ config,
268
+ arguments: {
269
+ queue: queueIdOf(config, args),
270
+ market: args.expiryMarketId
271
+ }
272
+ });
273
+ }
274
+ /**
275
+ * Pay one Open record of a settled market its settled payout (`queue::pay_open`), at any time
276
+ * after settlement, before or after `settle_step` completes: a record the payout walk skipped
277
+ * because the market was short of cash or its receive address was denied. Permissionless: the
278
+ * payout goes only to the record's own receive address. Emits `OpenRecordSettled`, or
279
+ * `OpenRecordPayoutSkipped` again while the cause persists. A missing or non-Open record is left
280
+ * alone. Aborts `EMarketNotSettled` before Predict settles the market.
281
+ */
282
+ function payOpen(config, args) {
283
+ assertU64(args.recordId, "recordId");
284
+ return payOpen$1({
285
+ config,
286
+ arguments: {
287
+ queue: queueIdOf(config, args),
288
+ market: args.expiryMarketId,
289
+ recordId: args.recordId
290
+ }
291
+ });
292
+ }
293
+ /**
294
+ * Send a finished record's parked funds (`queue::claim_parked`): change or a refund its receive
295
+ * address couldn't take while it was on USDC's deny list or USDC was paused. Permissionless: the
296
+ * funds go only to the record's own receive address. Returns the amount sent (u64), or `0` and
297
+ * changes nothing for a missing or unfinished record, one with nothing parked, or an address still
298
+ * denied. Emits `RecordFundsClaimed`. Takes no market: `expiryMarketId` only derives the queue.
299
+ */
300
+ function claimParked(config, args) {
301
+ assertU64(args.recordId, "recordId");
302
+ return claimParked$1({
303
+ config,
304
+ arguments: {
305
+ queue: queueIdOf(config, args),
306
+ recordId: args.recordId
307
+ }
308
+ });
309
+ }
310
+ /**
311
+ * Verify one signed Lazer payload with the current Lazer package. A positional call on purpose:
312
+ * the oracle-construction packages are not generated (see `sui-codegen.config.ts`).
313
+ */
314
+ function parseLazerUpdate(lazer, payload) {
315
+ return (tx) => tx.moveCall({
316
+ target: `${lazer.packageId}::pyth_lazer::parse_and_verify_le_ecdsa_update`,
317
+ arguments: [
318
+ tx.object(lazer.stateId),
319
+ tx.object.clock(),
320
+ tx.pure.vector("u8", payload)
321
+ ]
322
+ });
323
+ }
324
+ /**
325
+ * Verify the signed Lazer payloads and commit them to the market's waiting cohorts
326
+ * (`queue::commit`). Permissionless. Pass the payloads for a cohort's exact τ, or a backup tick
327
+ * once τ + gap wait has passed with τ uncommitted (when the policy's price buffer is on). Commit
328
+ * matches each update to its own cohort by τ and skips one that matches nothing, so no
329
+ * head-of-line ordering is assumed. Resolve `lazer` per batch with `read.lazerPackages` and never
330
+ * cache it: a Pyth upgrade retires the old package at once.
331
+ */
332
+ function commit(config, args) {
333
+ if (args.payloads.length === 0) throw new PredictInputError("commit needs at least one signed Lazer payload");
334
+ return (tx) => {
335
+ const updates = args.payloads.map((payload) => tx.add(parseLazerUpdate(args.lazer, payload)));
336
+ const vector = tx.makeMoveVec({
337
+ type: `${args.lazer.originalId}::update::Update`,
338
+ elements: updates
339
+ });
340
+ return tx.add(commit$1({
341
+ config,
342
+ arguments: {
343
+ queue: queueIdOf(config, args),
344
+ market: args.expiryMarketId,
345
+ updates: vector
346
+ }
347
+ }));
348
+ };
349
+ }
350
+ /**
351
+ * Fill or refund committed orders in τ order (`queue::resolve`), visiting at most `maxOrders`
352
+ * records (the chain caps one call at 450, since a fill emits two events and Sui allows 1,024
353
+ * per transaction). Permissionless. Returns how many orders it finished. An order the market
354
+ * can't cover is refunded with reason 8. Size `maxOrders` against the payout tree
355
+ * (`payoutTreeNodeCount`): about 10 to 15 fills fit one transaction in a full tree.
356
+ */
357
+ function resolve(config, args) {
358
+ return resolve$1({
359
+ config,
360
+ arguments: {
361
+ queue: queueIdOf(config, args),
362
+ market: args.expiryMarketId,
363
+ maxOrders: args.maxOrders
364
+ }
365
+ });
366
+ }
367
+ /**
368
+ * The open filler (no cap exists): {@link commit} the signed Lazer payloads, then
369
+ * {@link resolve} up to `maxOrders` records. Anyone with Pyth Lazer access can run it. With
370
+ * `refundOverdue`, a final `refund` call sweeps orders past their deadline. Returns the resolve
371
+ * result. Split commit from resolve when the payout tree is large.
372
+ */
373
+ function fill(config, args) {
374
+ if (args.payloads.length === 0) throw new PredictInputError("fill needs at least one signed Lazer payload");
375
+ const target = {
376
+ expiryMarketId: args.expiryMarketId,
377
+ queueId: queueIdOf(config, args)
378
+ };
379
+ return (tx) => {
380
+ tx.add(commit(config, {
381
+ ...target,
382
+ payloads: args.payloads,
383
+ lazer: args.lazer
384
+ }));
385
+ const resolved = tx.add(resolve(config, {
386
+ ...target,
387
+ maxOrders: args.maxOrders
388
+ }));
389
+ if (args.refundOverdue) tx.add(refund(config, {
390
+ ...target,
391
+ maxOrders: args.maxOrders
392
+ }));
393
+ return resolved;
394
+ };
395
+ }
396
+
397
+ //#endregion
398
+ export { assertOrderFeeAtMost, claimParked, enqueueExactAmount, enqueueExactCost, enqueueExactQuantity, enqueueRedeemOpen, fill, payOpen, queueIdOf, queue_exports, rebalanceExpiryCash, refund };
399
+ //# sourceMappingURL=queue.mjs.map