@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,9 +1,13 @@
1
1
  import { AccountCreated, Deposited, Withdrawn } from "../contracts/account/account_events.mjs";
2
- import { BuilderCodeSet } from "../contracts/deepbook_predict/builder_code_events.mjs";
3
- import { LiveOrderRedeemed, OrderMinted, SettledOrderRedeemed } from "../contracts/deepbook_predict/order_events.mjs";
4
- import { RequestCancelled, SupplyRequested, WithdrawRequested } from "../contracts/deepbook_predict/vault_events.mjs";
5
2
  import { PredictInputError } from "./errors.mjs";
6
3
  import { fromRaw } from "./units.mjs";
4
+ import { decodeOrderRange } from "./cost.mjs";
5
+ import { BuilderCodeSet } from "../contracts/deepbook_predict/builder_code_events.mjs";
6
+ import { FlushOperatorUpdated, OrderFlowUpdated } from "../contracts/deepbook_predict/config_events.mjs";
7
+ import { LiveOrderRedeemed, OrderMinted, SettledOrderRedeemed } from "../contracts/deepbook_predict/order_events.mjs";
8
+ import { ExpiryPnlRealized, RequestCancelled, SupplyRequested, WithdrawRequested } from "../contracts/deepbook_predict/vault_events.mjs";
9
+ import { CohortCommitted, DelayedExecutionPolicyUpdated, MarketPayoutsCompleted, OpenRecordPayoutSkipped, OpenRecordSettled, OrderEnqueued, QueuedOrderFilled, QueuedOrderRefunded, QueuedOrdersCleaned, RecordFundsClaimed, RecordFundsParked } from "../contracts/deepbook_predict_orders/queue_events.mjs";
10
+ import { isMintKind, isSellKind, orderKindName, policyFromBcs, refundReason } from "./queue.mjs";
7
11
  import { fromBase64, normalizeSuiAddress } from "@mysten/sui/utils";
8
12
 
9
13
  //#region src/predict/decode.ts
@@ -168,7 +172,341 @@ function decodeBuilderCodeSets(cfg, result) {
168
172
  builderCodeId: optId(e.builder_code_id)
169
173
  }));
170
174
  }
175
+ /**
176
+ * The defining package of the Predict types and events the delayed-execution upgrade added.
177
+ * Throws rather than guessing: matching against the latest package would silently decode nothing
178
+ * once the package is upgraded again.
179
+ */
180
+ function delayedExecutionOrigin(cfg) {
181
+ const pkg = cfg.packages.predictDelayedExecution;
182
+ if (!pkg) throw new PredictInputError(`delayed execution isn't recorded for ${cfg.network} in this SDK version: pass a \`config\` whose \`packages.predictDelayedExecution\` names the package that introduced it`);
183
+ return pkg;
184
+ }
185
+ /**
186
+ * The original ID of the order-flow companion (`deepbook_predict_orders`), which types the queue
187
+ * events. Throws while the config doesn't record the companion.
188
+ */
189
+ function predictOrdersOrigin(cfg) {
190
+ const pkg = cfg.packages.predictOrdersV1 ?? cfg.packages.predictOrders;
191
+ if (!pkg) throw new PredictInputError(`the order-flow package isn't recorded for ${cfg.network} in this SDK version: pass a \`config\` whose \`packages.predictOrders\` names \`deepbook_predict_orders\``);
192
+ return pkg;
193
+ }
194
+ function side(kind) {
195
+ return isMintKind(kind) ? "mint" : isSellKind(kind) ? "sell" : "unknown";
196
+ }
197
+ function heldPosition(p, lotSize) {
198
+ return p.order_id === 0n ? null : {
199
+ orderId: p.order_id,
200
+ rootId: p.root_id,
201
+ openedAtMs: p.opened_at_ms,
202
+ quantityRaw: decodeOrderRange(p.order_id, lotSize).quantity
203
+ };
204
+ }
205
+ const cashOf = (e) => ({
206
+ marketCash: e.market_cash,
207
+ requiredCash: e.required_cash,
208
+ waitingCashNeed: e.waiting_cash_need
209
+ });
210
+ function enqueueReceipt(e, lotSize) {
211
+ return {
212
+ type: "enqueued",
213
+ marketId: normalizeSuiAddress(e.expiry_market_id),
214
+ recordId: e.record_id,
215
+ accountId: normalizeSuiAddress(e.account_id),
216
+ kind: e.kind,
217
+ kindName: orderKindName(e.kind),
218
+ side: side(e.kind),
219
+ request: {
220
+ lowerTick: e.request.lower_tick,
221
+ higherTick: e.request.higher_tick,
222
+ quantity: e.request.quantity,
223
+ maxPremium: e.request.max_premium,
224
+ minQuantity: e.request.min_quantity,
225
+ maxCost: e.request.max_cost,
226
+ maxProbability: e.request.max_probability,
227
+ minProbability: e.request.min_probability,
228
+ minProceeds: e.request.min_proceeds
229
+ },
230
+ position: heldPosition(e.position, lotSize),
231
+ timing: {
232
+ placedAtMs: e.timing.placed_at_ms,
233
+ earliestPriceMs: e.timing.earliest_price_ms,
234
+ tauMs: e.timing.tau_ms,
235
+ deadlineMs: e.timing.deadline_ms,
236
+ cutoffMs: e.timing.cutoff_ms,
237
+ pythChannel: e.timing.pyth_channel
238
+ },
239
+ sourceRecordId: e.source_record_id ?? null,
240
+ builderCodeId: optId(e.builder_code_id),
241
+ referrerAccountId: optId(e.referrer_account_id),
242
+ budget: fromRaw(e.budget, 6),
243
+ orderFee: fromRaw(e.order_fee, 6),
244
+ cash: cashOf(e),
245
+ timestampMs: e.onchain_timestamp_ms,
246
+ raw: {
247
+ budget: e.budget,
248
+ orderFee: e.order_fee,
249
+ cashNeed: e.cash_need,
250
+ subsidyBound: e.subsidy_bound
251
+ },
252
+ vol: e.vol
253
+ };
254
+ }
255
+ function cohortCommitReceipt(e) {
256
+ return {
257
+ type: "cohort-committed",
258
+ marketId: normalizeSuiAddress(e.expiry_market_id),
259
+ tauMs: e.tau_ms,
260
+ tickMs: e.tick_ms,
261
+ firstRecordId: e.first_record_id,
262
+ lastRecordId: e.last_record_id,
263
+ price: fromRaw(e.spot, 9),
264
+ spotRaw: e.spot,
265
+ generationUs: e.generation_us,
266
+ pythSourceId: e.pyth_source_id,
267
+ pythChannel: e.pyth_channel,
268
+ sender: normalizeSuiAddress(e.sender),
269
+ timestampMs: e.onchain_timestamp_ms
270
+ };
271
+ }
272
+ function fillReceipt(e, lotSize) {
273
+ return {
274
+ type: "filled",
275
+ marketId: normalizeSuiAddress(e.expiry_market_id),
276
+ recordId: e.record_id,
277
+ accountId: normalizeSuiAddress(e.account_id),
278
+ kind: e.kind,
279
+ side: side(e.kind),
280
+ quantity: fromRaw(e.quantity, 6),
281
+ amount: fromRaw(e.amount, 6),
282
+ fees: {
283
+ trading: fromRaw(e.trading_fee, 6),
284
+ builder: fromRaw(e.builder_fee, 6),
285
+ referral: fromRaw(e.referral_fee, 6),
286
+ order: fromRaw(e.order_fee, 6),
287
+ subsidyUsed: fromRaw(e.subsidy_used, 6),
288
+ inventoryImpact: fromRaw(e.inventory_impact, 6)
289
+ },
290
+ tauMs: e.tau_ms,
291
+ tickMs: e.tick_ms,
292
+ position: heldPosition(e.position, lotSize),
293
+ sender: normalizeSuiAddress(e.sender),
294
+ timestampMs: e.onchain_timestamp_ms,
295
+ cash: cashOf(e),
296
+ raw: {
297
+ quantity: e.quantity,
298
+ amount: e.amount,
299
+ tradingFee: e.trading_fee,
300
+ builderFee: e.builder_fee,
301
+ referralFee: e.referral_fee,
302
+ orderFee: e.order_fee,
303
+ subsidyUsed: e.subsidy_used,
304
+ inventoryImpact: e.inventory_impact
305
+ }
306
+ };
307
+ }
308
+ function refundReceipt(e) {
309
+ return {
310
+ type: "refunded",
311
+ marketId: normalizeSuiAddress(e.expiry_market_id),
312
+ recordId: e.record_id,
313
+ accountId: normalizeSuiAddress(e.account_id),
314
+ kind: e.kind,
315
+ side: side(e.kind),
316
+ reason: refundReason(e.reason),
317
+ escrowReturned: fromRaw(e.escrow_returned, 6),
318
+ orderFeeReturned: fromRaw(e.order_fee_returned, 6),
319
+ subsidyReturned: fromRaw(e.subsidy_returned, 6),
320
+ positionReturned: e.position_returned,
321
+ sender: normalizeSuiAddress(e.sender),
322
+ timestampMs: e.onchain_timestamp_ms,
323
+ cash: cashOf(e),
324
+ raw: {
325
+ escrowReturned: e.escrow_returned,
326
+ orderFeeReturned: e.order_fee_returned,
327
+ subsidyReturned: e.subsidy_returned
328
+ }
329
+ };
330
+ }
331
+ function payoutReceipt(skipped) {
332
+ return (e) => ({
333
+ type: skipped ? "open-record-payout-skipped" : "open-record-settled",
334
+ marketId: normalizeSuiAddress(e.expiry_market_id),
335
+ recordId: e.record_id,
336
+ accountId: normalizeSuiAddress(e.account_id),
337
+ orderId: e.order_id,
338
+ payout: fromRaw(e.payout, 6),
339
+ skipped,
340
+ timestampMs: e.onchain_timestamp_ms,
341
+ raw: { payout: e.payout }
342
+ });
343
+ }
344
+ function recordFundsReceipt(type) {
345
+ return (e) => ({
346
+ type,
347
+ marketId: normalizeSuiAddress(e.expiry_market_id),
348
+ recordId: e.record_id,
349
+ accountId: normalizeSuiAddress(e.account_id),
350
+ receiveAddress: normalizeSuiAddress(e.receive_address),
351
+ amount: fromRaw(e.amount, 6),
352
+ timestampMs: e.onchain_timestamp_ms,
353
+ raw: { amount: e.amount }
354
+ });
355
+ }
356
+ const QUEUE_EVENT_DECODERS = [
357
+ {
358
+ name: "OrderEnqueued",
359
+ layout: OrderEnqueued,
360
+ map: enqueueReceipt
361
+ },
362
+ {
363
+ name: "CohortCommitted",
364
+ layout: CohortCommitted,
365
+ map: cohortCommitReceipt
366
+ },
367
+ {
368
+ name: "QueuedOrderFilled",
369
+ layout: QueuedOrderFilled,
370
+ map: fillReceipt
371
+ },
372
+ {
373
+ name: "QueuedOrderRefunded",
374
+ layout: QueuedOrderRefunded,
375
+ map: refundReceipt
376
+ },
377
+ {
378
+ name: "OpenRecordSettled",
379
+ layout: OpenRecordSettled,
380
+ map: payoutReceipt(false)
381
+ },
382
+ {
383
+ name: "OpenRecordPayoutSkipped",
384
+ layout: OpenRecordPayoutSkipped,
385
+ map: payoutReceipt(true)
386
+ },
387
+ {
388
+ name: "MarketPayoutsCompleted",
389
+ layout: MarketPayoutsCompleted,
390
+ map: (e) => ({
391
+ type: "market-payouts-completed",
392
+ marketId: normalizeSuiAddress(e.expiry_market_id),
393
+ timestampMs: e.onchain_timestamp_ms
394
+ })
395
+ },
396
+ {
397
+ name: "RecordFundsParked",
398
+ layout: RecordFundsParked,
399
+ map: recordFundsReceipt("record-funds-parked")
400
+ },
401
+ {
402
+ name: "RecordFundsClaimed",
403
+ layout: RecordFundsClaimed,
404
+ map: recordFundsReceipt("record-funds-claimed")
405
+ },
406
+ {
407
+ name: "QueuedOrdersCleaned",
408
+ layout: QueuedOrdersCleaned,
409
+ map: (e) => ({
410
+ type: "queued-orders-cleaned",
411
+ marketId: normalizeSuiAddress(e.expiry_market_id),
412
+ recordIds: [...e.record_ids],
413
+ timestampMs: e.onchain_timestamp_ms
414
+ })
415
+ }
416
+ ];
417
+ function eventPayload(e, module, name) {
418
+ const bytes = eventBytes(e);
419
+ if (!bytes) throw new PredictInputError(`${module}::${name} event has no BCS payload — execute/simulate with events included`);
420
+ return bytes;
421
+ }
422
+ /**
423
+ * Every delayed-execution order event in a result, tagged with `type`, in event order: the
424
+ * companion's `queue_events`, matched against its original ID. The app's single entry point for
425
+ * the queue: pass the list to `queue.reduceOrderEvents`.
426
+ */
427
+ function decodeQueueEvents(cfg, result) {
428
+ const pkg = predictOrdersOrigin(cfg);
429
+ const lotSize = BigInt(cfg.units.positionLotSize);
430
+ const out = [];
431
+ for (const e of result.events ?? []) for (const d of QUEUE_EVENT_DECODERS) {
432
+ if (!matches(e, pkg, "queue_events", d.name)) continue;
433
+ out.push(d.map(d.layout.parse(eventPayload(e, "queue_events", d.name)), lotSize));
434
+ break;
435
+ }
436
+ return out;
437
+ }
438
+ function ofType(cfg, result, ...types) {
439
+ return decodeQueueEvents(cfg, result).filter((e) => types.includes(e.type));
440
+ }
441
+ const decodeEnqueues = (cfg, r) => ofType(cfg, r, "enqueued");
442
+ const decodeCohortCommits = (cfg, r) => ofType(cfg, r, "cohort-committed");
443
+ const decodeQueuedFills = (cfg, r) => ofType(cfg, r, "filled");
444
+ const decodeQueuedRefunds = (cfg, r) => ofType(cfg, r, "refunded");
445
+ const decodeOpenRecordPayouts = (cfg, r) => ofType(cfg, r, "open-record-settled", "open-record-payout-skipped");
446
+ const decodeMarketPayoutsCompleted = (cfg, r) => ofType(cfg, r, "market-payouts-completed");
447
+ const decodeRecordFunds = (cfg, r) => ofType(cfg, r, "record-funds-parked", "record-funds-claimed");
448
+ const decodeQueueOps = (cfg, r) => ofType(cfg, r, "queued-orders-cleaned");
449
+ /**
450
+ * The delayed-execution admin events, in event order: the companion desk's
451
+ * `DelayedExecutionPolicyUpdated` (matched against the companion's original ID) and Predict's
452
+ * `FlushOperatorUpdated` and `OrderFlowUpdated` (matched against `predictDelayedExecution`).
453
+ * Throws while the config records neither package.
454
+ */
455
+ function decodePolicyUpdates(cfg, result) {
456
+ const orders = predictOrdersOrigin(cfg);
457
+ const predict = delayedExecutionOrigin(cfg);
458
+ const out = [];
459
+ for (const e of result.events ?? []) if (matches(e, orders, "queue_events", "DelayedExecutionPolicyUpdated")) {
460
+ const p = DelayedExecutionPolicyUpdated.parse(eventPayload(e, "queue_events", "DelayedExecutionPolicyUpdated"));
461
+ out.push({
462
+ type: "policy-updated",
463
+ deskId: normalizeSuiAddress(p.desk_id),
464
+ policy: policyFromBcs(p.policy),
465
+ timestampMs: p.onchain_timestamp_ms
466
+ });
467
+ } else if (matches(e, predict, "config_events", "FlushOperatorUpdated")) {
468
+ const f = FlushOperatorUpdated.parse(eventPayload(e, "config_events", "FlushOperatorUpdated"));
469
+ out.push({
470
+ type: "flush-operator-updated",
471
+ operator: normalizeSuiAddress(f.operator),
472
+ added: f.added,
473
+ timestampMs: f.onchain_timestamp_ms
474
+ });
475
+ } else if (matches(e, predict, "config_events", "OrderFlowUpdated")) {
476
+ const o = OrderFlowUpdated.parse(eventPayload(e, "config_events", "OrderFlowUpdated"));
477
+ out.push({
478
+ type: "order-flow-updated",
479
+ orderFlow: o.order_flow.name,
480
+ enabled: o.enabled,
481
+ timestampMs: o.onchain_timestamp_ms
482
+ });
483
+ }
484
+ return out;
485
+ }
486
+ /** Every `ExpiryPnlRealized` in a result, in event order. Introduced with delayed execution. */
487
+ function decodeExpiryPnlRealized(cfg, result) {
488
+ return decodeAll(result, delayedExecutionOrigin(cfg), "vault_events", "ExpiryPnlRealized", ExpiryPnlRealized).map((e) => ({
489
+ vaultId: normalizeSuiAddress(e.pool_vault_id),
490
+ marketId: normalizeSuiAddress(e.expiry_market_id),
491
+ propbookUnderlyingId: e.propbook_underlying_id,
492
+ expiryMs: e.expiry,
493
+ settlementPriceRaw: e.settlement_price,
494
+ inProfit: e.in_profit,
495
+ amount: fromRaw(e.amount, 6),
496
+ signedAmountRaw: e.in_profit ? e.amount : -e.amount,
497
+ raw: { amount: e.amount }
498
+ }));
499
+ }
500
+ /**
501
+ * The pool's gross realized P&L in raw USDC: the signed sum of `ExpiryPnlRealized` changes. Over
502
+ * every emission of every expiry it equals the sum of each expiry's latest `ExpiryPnl`, with no
503
+ * per-expiry dedup. Subtract the `OrderMinted.fee_incentive_subsidy` totals to isolate the
504
+ * trading result.
505
+ */
506
+ function realizedPnlRaw(receipts) {
507
+ return receipts.reduce((sum, r) => sum + r.signedAmountRaw, 0n);
508
+ }
171
509
 
172
510
  //#endregion
173
- export { decodeAccountsCreated, decodeBuilderCodeSets, decodeClaims, decodeDeposits, decodeMints, decodePlpCancels, decodePlpRequests, decodeRedeems, decodeWithdrawals, exactlyOne };
511
+ export { decodeAccountsCreated, decodeBuilderCodeSets, decodeClaims, decodeCohortCommits, decodeDeposits, decodeEnqueues, decodeExpiryPnlRealized, decodeMarketPayoutsCompleted, decodeMints, decodeOpenRecordPayouts, decodePlpCancels, decodePlpRequests, decodePolicyUpdates, decodeQueueEvents, decodeQueueOps, decodeQueuedFills, decodeQueuedRefunds, decodeRecordFunds, decodeRedeems, decodeWithdrawals, exactlyOne, realizedPnlRaw };
174
512
  //# sourceMappingURL=decode.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"decode.mjs","names":["orderEvents.OrderMinted","orderEvents.LiveOrderRedeemed","orderEvents.SettledOrderRedeemed","accountEvents.AccountCreated","accountEvents.Deposited","accountEvents.Withdrawn","vaultEvents.SupplyRequested","vaultEvents.WithdrawRequested","vaultEvents.RequestCancelled","builderCodeEvents.BuilderCodeSet"],"sources":["../../src/predict/decode.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { fromBase64, normalizeSuiAddress } from '@mysten/sui/utils';\nimport type { PredictConfig } from './config/index.js';\nimport { accountEvents } from '../account.js';\nimport * as builderCodeEvents from '../contracts/deepbook_predict/builder_code_events.js';\nimport * as orderEvents from '../contracts/deepbook_predict/order_events.js';\nimport * as vaultEvents from '../contracts/deepbook_predict/vault_events.js';\nimport { PredictInputError } from './errors.js';\nimport { fromRaw } from './units.js';\n\n// ============================================================================\n// Execution-result decoders.\n//\n// Every tx.* builder returns a Transaction; after the app executes it (with\n// events included), the deployed contracts emit typed events carrying the full\n// receipt — order ids, fills, fees, queue indexes, new balances. These pure\n// functions turn that result into typed receipts. No network, no client.\n//\n// Decoding uses each event's BCS bytes, not its `json`: the client typings\n// warn the JSON rendering varies across transports (JSON-RPC/gRPC/GraphQL),\n// while BCS is canonical. Layouts come from the GENERATED event MoveStructs\n// (src/contracts/{deepbook_predict,account}/*_events.ts), whose field order\n// mirrors the deployed Move — regenerate the bindings if the package changes.\n// ============================================================================\n\n/** The slice of an executed/simulated transaction result the decoders need. */\nexport interface DecodableEvent {\n\t/** Full type tag `0xpkg::module::Name` (gRPC `eventType`, legacy `type`). */\n\teventType?: string;\n\ttype?: string;\n\tpackageId?: string;\n\tmodule?: string;\n\t/** Struct name, when the transport supplies it separately from a full type tag. */\n\tname?: string;\n\t/** Canonical BCS payload; some transports deliver it base64-encoded. */\n\tbcs?: Uint8Array | string;\n}\n\nexport interface DecodableTransactionResult {\n\tevents?: readonly DecodableEvent[] | null;\n}\n\n// --- matching + plumbing ----------------------------------------------------\n\nfunction eventBytes(e: DecodableEvent): Uint8Array | null {\n\tif (e.bcs instanceof Uint8Array) return e.bcs;\n\tif (typeof e.bcs === 'string') return fromBase64(e.bcs);\n\treturn null;\n}\n\n// Match by defining package + module + struct name. Events are typed by the\n// package version that introduced their struct, not the latest Move-call target.\n// All events decoded here were introduced in v1.\nfunction matches(e: DecodableEvent, pkg: string, module: string, name: string): boolean {\n\tconst tag = e.eventType ?? e.type;\n\tif (tag) {\n\t\tconst parts = tag.split('::');\n\t\tif (parts.length !== 3) return false;\n\t\treturn (\n\t\t\tnormalizeSuiAddress(parts[0]) === normalizeSuiAddress(pkg) &&\n\t\t\tparts[1] === module &&\n\t\t\tparts[2] === name\n\t\t);\n\t}\n\t// No type tag. Match on what the transport did give us — and on `name` when it is\n\t// present, because module+package alone matches EVERY struct in the module, so one\n\t// decoder would happily take another's event and fail deep inside BCS.\n\tif (e.module !== module || e.packageId == null) return false;\n\tif (normalizeSuiAddress(e.packageId) !== normalizeSuiAddress(pkg)) return false;\n\treturn e.name == null || e.name === name;\n}\n\nfunction decodeAll<T>(\n\tresult: DecodableTransactionResult,\n\tpkg: string,\n\tmodule: string,\n\tname: string,\n\tlayout: { parse(bytes: Uint8Array): T },\n): T[] {\n\tconst out: T[] = [];\n\tfor (const e of result.events ?? []) {\n\t\tif (!matches(e, pkg, module, name)) continue;\n\t\tconst bytes = eventBytes(e);\n\t\tif (!bytes) {\n\t\t\tthrow new PredictInputError(\n\t\t\t\t`${module}::${name} event has no BCS payload — execute/simulate with events included`,\n\t\t\t);\n\t\t}\n\t\tout.push(layout.parse(bytes));\n\t}\n\treturn out;\n}\n\nfunction exactlyOne<T>(items: T[], what: string): T {\n\tif (items.length !== 1) {\n\t\tthrow new PredictInputError(`expected exactly one ${what} event, found ${items.length}`);\n\t}\n\treturn items[0];\n}\n\nconst optId = (v: string | null | undefined): string | null =>\n\tv == null ? null : normalizeSuiAddress(v);\n\n// --- receipts ---------------------------------------------------------------\n\nexport interface MintReceipt {\n\tmarketId: string;\n\taccountId: string;\n\towner: string;\n\t/** Persist this: required to redeem/claim the position later. */\n\torderId: bigint;\n\t/** Stable across partial-close replacements; equals orderId at mint. */\n\tpositionRootId: bigint;\n\tlowerTick: bigint;\n\thigherTick: bigint;\n\t/** 0..1 range probability quoted at entry (your fill price per $1 payout). */\n\tentryProbability: number;\n\t/** Max payout actually minted, in quote units (mintAmount: chain-floored). */\n\tquantity: number;\n\t/** Premium paid into LP backing, in quote units. */\n\tpremium: number;\n\t/**\n\t * Fee breakdown. `referral` is the slice of the trader-paid trading fee and\n\t * congestion surcharge delivered to the referrer; `inventoryImpact` is the\n\t * path-independent inventory-impact charge assessed on the mint.\n\t */\n\tfees: {\n\t\ttrading: number;\n\t\tsubsidy: number;\n\t\tbuilder: number;\n\t\tpenalty: number;\n\t\treferral: number;\n\t\tinventoryImpact: number;\n\t};\n\tbuilderCodeId: string | null;\n\traw: {\n\t\tquantity: bigint;\n\t\tpremium: bigint;\n\t\ttradingFee: bigint;\n\t\tfeeIncentiveSubsidy: bigint;\n\t\tbuilderFee: bigint;\n\t\tpenaltyFee: bigint;\n\t\treferralFee: bigint;\n\t\tinventoryImpactCharge: bigint;\n\t\tentryProbability: bigint;\n\t};\n}\n\nexport interface RedeemReceipt {\n\tmarketId: string;\n\taccountId: string;\n\towner: string;\n\torderId: bigint;\n\tpositionRootId: bigint;\n\tquantityClosed: number;\n\tremaining: number;\n\t/**\n\t * A partial close RETIRES the old order id and issues this replacement for\n\t * the remaining quantity — update your stored id or it goes silently stale.\n\t */\n\treplacementOrderId: bigint | null;\n\t/** NET quote credited to the account: gross + inventoryImpactRebate − trading −\n\t * builder − penalty — the same expression the chain asserts `min_proceeds`\n\t * against, and what `settle_live_redeem_payment` actually deposits. */\n\tproceeds: number;\n\t/** Gross close value before fees (the event's redeem_amount). */\n\tgross: number;\n\t/**\n\t * Fee breakdown. `inventoryImpactRebate` is the path-independent\n\t * inventory-impact rebate credited back on the close.\n\t */\n\tfees: { trading: number; builder: number; penalty: number; inventoryImpactRebate: number };\n\tbuilderCodeId: string | null;\n\traw: {\n\t\tquantityClosed: bigint;\n\t\tremaining: bigint;\n\t\tproceeds: bigint;\n\t\tgross: bigint;\n\t\ttradingFee: bigint;\n\t\tbuilderFee: bigint;\n\t\tpenaltyFee: bigint;\n\t\tinventoryImpactRebate: bigint;\n\t};\n}\n\nexport interface ClaimReceipt {\n\tmarketId: string;\n\taccountId: string;\n\towner: string;\n\torderId: bigint;\n\tpositionRootId: bigint;\n\t/** Quote units paid out. A settled claim closes the order in full. */\n\tpayout: number;\n\traw: { payout: bigint };\n}\n\nexport interface CreateManagerReceipt {\n\taccountId: string;\n\twrapperId: string;\n\towner: string;\n\tselfOwned: boolean;\n}\n\nexport interface BalanceChangeReceipt {\n\taccountId: string;\n\tcoinType: string;\n\t/** Display value assuming a 6-decimal coin (quote + PLP both are). */\n\tamount: number;\n\tnewBalance: number;\n\traw: { amount: bigint; newBalance: bigint };\n}\n\nexport interface PlpRequestReceipt {\n\tkind: 'supply' | 'withdraw';\n\tvaultId: string;\n\taccountId: string;\n\trecipient: string;\n\t/** Feed straight into cancelSupplyPlp / cancelWithdrawPlp. */\n\tindex: bigint;\n\t/** Quote units for supply; PLP shares (6-dec) for withdraw. */\n\tamount: number;\n\traw: { amount: bigint };\n}\n\nexport interface PlpCancelReceipt {\n\tvaultId: string;\n\taccountId: string;\n\trecipient: string;\n\tindex: bigint;\n\tisSupply: boolean;\n\t/** Refund returned to the account (quote for supply, PLP for withdraw). */\n\tamount: number;\n\traw: { amount: bigint };\n}\n\nexport interface BuilderCodeReceipt {\n\taccountId: string;\n\towner: string;\n\t/** Null after unsetBuilderCode. */\n\tbuilderCodeId: string | null;\n}\n\n// --- decoders (plural = all matching events, in event order) ----------------\n\nexport function decodeMints(cfg: PredictConfig, result: DecodableTransactionResult): MintReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'order_events',\n\t\t'OrderMinted',\n\t\torderEvents.OrderMinted,\n\t).map((e) => ({\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\torderId: e.order_id,\n\t\tpositionRootId: e.position_root_id,\n\t\tlowerTick: e.lower_tick,\n\t\thigherTick: e.higher_tick,\n\t\tentryProbability: fromRaw(e.entry_probability, 9),\n\t\tquantity: fromRaw(e.quantity, 6),\n\t\tpremium: fromRaw(e.premium, 6),\n\t\tfees: {\n\t\t\ttrading: fromRaw(e.trading_fee, 6),\n\t\t\tsubsidy: fromRaw(e.fee_incentive_subsidy, 6),\n\t\t\tbuilder: fromRaw(e.builder_fee, 6),\n\t\t\tpenalty: fromRaw(e.penalty_fee, 6),\n\t\t\treferral: fromRaw(e.referral_fee, 6),\n\t\t\tinventoryImpact: fromRaw(e.inventory_impact_charge, 6),\n\t\t},\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t\traw: {\n\t\t\tquantity: e.quantity,\n\t\t\tpremium: e.premium,\n\t\t\ttradingFee: e.trading_fee,\n\t\t\tfeeIncentiveSubsidy: e.fee_incentive_subsidy,\n\t\t\tbuilderFee: e.builder_fee,\n\t\t\tpenaltyFee: e.penalty_fee,\n\t\t\treferralFee: e.referral_fee,\n\t\t\tinventoryImpactCharge: e.inventory_impact_charge,\n\t\t\tentryProbability: e.entry_probability,\n\t\t},\n\t}));\n}\n\nexport function decodeRedeems(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): RedeemReceipt[] {\n\tconst pkg = cfg.packages.predictV1 ?? cfg.packages.predict;\n\tconst live = decodeAll(\n\t\tresult,\n\t\tpkg,\n\t\t'order_events',\n\t\t'LiveOrderRedeemed',\n\t\torderEvents.LiveOrderRedeemed,\n\t).map((e): RedeemReceipt => ({\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\torderId: e.order_id,\n\t\tpositionRootId: e.position_root_id,\n\t\tquantityClosed: fromRaw(e.quantity_closed, 6),\n\t\tremaining: fromRaw(e.remaining_quantity, 6),\n\t\treplacementOrderId: e.replacement_order_id,\n\t\t// Mirrors the deployed close-side accounting exactly (the same expression\n\t\t// `min_proceeds` is asserted against): the net credited to the account is\n\t\t// redeem_amount PLUS the inventory-impact rebate, minus trading, builder and\n\t\t// penalty fees. The event's redeem_amount is GROSS.\n\t\tproceeds: fromRaw(\n\t\t\te.redeem_amount + e.inventory_impact_rebate - e.trading_fee - e.builder_fee - e.penalty_fee,\n\t\t\t6,\n\t\t),\n\t\tgross: fromRaw(e.redeem_amount, 6),\n\t\tfees: {\n\t\t\ttrading: fromRaw(e.trading_fee, 6),\n\t\t\tbuilder: fromRaw(e.builder_fee, 6),\n\t\t\tpenalty: fromRaw(e.penalty_fee, 6),\n\t\t\tinventoryImpactRebate: fromRaw(e.inventory_impact_rebate, 6),\n\t\t},\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t\traw: {\n\t\t\tquantityClosed: e.quantity_closed,\n\t\t\tremaining: e.remaining_quantity,\n\t\t\tproceeds:\n\t\t\t\te.redeem_amount + e.inventory_impact_rebate - e.trading_fee - e.builder_fee - e.penalty_fee,\n\t\t\tgross: e.redeem_amount,\n\t\t\ttradingFee: e.trading_fee,\n\t\t\tbuilderFee: e.builder_fee,\n\t\t\tpenaltyFee: e.penalty_fee,\n\t\t\tinventoryImpactRebate: e.inventory_impact_rebate,\n\t\t},\n\t}));\n\treturn live;\n}\n\nexport function decodeClaims(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): ClaimReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'order_events',\n\t\t'SettledOrderRedeemed',\n\t\torderEvents.SettledOrderRedeemed,\n\t).map((e) => ({\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\torderId: e.order_id,\n\t\tpositionRootId: e.position_root_id,\n\t\tpayout: fromRaw(e.payout_amount, 6),\n\t\traw: { payout: e.payout_amount },\n\t}));\n}\n\nexport function decodeAccountsCreated(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): CreateManagerReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.account,\n\t\t'account_events',\n\t\t'AccountCreated',\n\t\taccountEvents.AccountCreated,\n\t).map((e) => ({\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\twrapperId: normalizeSuiAddress(e.wrapper_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\tselfOwned: e.self_owned,\n\t}));\n}\n\nfunction decodeBalanceChanges(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n\tname: 'Deposited' | 'Withdrawn',\n): BalanceChangeReceipt[] {\n\tconst layout = name === 'Deposited' ? accountEvents.Deposited : accountEvents.Withdrawn;\n\treturn decodeAll(result, cfg.packages.account, 'account_events', name, layout).map((e) => ({\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\tcoinType: e.coin_type,\n\t\tamount: fromRaw(e.amount, 6),\n\t\tnewBalance: fromRaw(e.new_balance, 6),\n\t\traw: { amount: e.amount, newBalance: e.new_balance },\n\t}));\n}\n\nexport const decodeDeposits = (\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): BalanceChangeReceipt[] => decodeBalanceChanges(cfg, result, 'Deposited');\n\nexport const decodeWithdrawals = (\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): BalanceChangeReceipt[] => decodeBalanceChanges(cfg, result, 'Withdrawn');\n\nexport function decodePlpRequests(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): PlpRequestReceipt[] {\n\tconst pkg = cfg.packages.predictV1 ?? cfg.packages.predict;\n\t// Supply/WithdrawRequested differ only in their min-out field (unused here);\n\t// pick the fields both share so either generated struct's parse feeds `make`.\n\ttype RequestedCommon = Pick<\n\t\t(typeof vaultEvents.SupplyRequested)['$inferType'],\n\t\t'pool_vault_id' | 'account_id' | 'recipient' | 'index' | 'amount'\n\t>;\n\tconst make =\n\t\t(kind: 'supply' | 'withdraw') =>\n\t\t(e: RequestedCommon): PlpRequestReceipt => ({\n\t\t\tkind,\n\t\t\tvaultId: normalizeSuiAddress(e.pool_vault_id),\n\t\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\t\trecipient: normalizeSuiAddress(e.recipient),\n\t\t\tindex: e.index,\n\t\t\tamount: fromRaw(e.amount, 6),\n\t\t\traw: { amount: e.amount },\n\t\t});\n\treturn [\n\t\t...decodeAll(result, pkg, 'vault_events', 'SupplyRequested', vaultEvents.SupplyRequested).map(\n\t\t\tmake('supply'),\n\t\t),\n\t\t...decodeAll(\n\t\t\tresult,\n\t\t\tpkg,\n\t\t\t'vault_events',\n\t\t\t'WithdrawRequested',\n\t\t\tvaultEvents.WithdrawRequested,\n\t\t).map(make('withdraw')),\n\t];\n}\n\nexport function decodePlpCancels(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): PlpCancelReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'vault_events',\n\t\t'RequestCancelled',\n\t\tvaultEvents.RequestCancelled,\n\t).map((e) => ({\n\t\tvaultId: normalizeSuiAddress(e.pool_vault_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\trecipient: normalizeSuiAddress(e.recipient),\n\t\tindex: e.index,\n\t\tisSupply: e.is_supply,\n\t\tamount: fromRaw(e.amount, 6),\n\t\traw: { amount: e.amount },\n\t}));\n}\n\nexport function decodeBuilderCodeSets(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): BuilderCodeReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'builder_code_events',\n\t\t'BuilderCodeSet',\n\t\tbuilderCodeEvents.BuilderCodeSet,\n\t).map((e) => ({\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t}));\n}\n\nexport { exactlyOne };\n"],"mappings":";;;;;;;;;AA6CA,SAAS,WAAW,GAAsC;AACzD,KAAI,EAAE,eAAe,WAAY,QAAO,EAAE;AAC1C,KAAI,OAAO,EAAE,QAAQ,SAAU,QAAO,WAAW,EAAE,IAAI;AACvD,QAAO;;AAMR,SAAS,QAAQ,GAAmB,KAAa,QAAgB,MAAuB;CACvF,MAAM,MAAM,EAAE,aAAa,EAAE;AAC7B,KAAI,KAAK;EACR,MAAM,QAAQ,IAAI,MAAM,KAAK;AAC7B,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,SACC,oBAAoB,MAAM,GAAG,KAAK,oBAAoB,IAAI,IAC1D,MAAM,OAAO,UACb,MAAM,OAAO;;AAMf,KAAI,EAAE,WAAW,UAAU,EAAE,aAAa,KAAM,QAAO;AACvD,KAAI,oBAAoB,EAAE,UAAU,KAAK,oBAAoB,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C3C,OAAO,EAAE;EACT,QAAQ,QAAQ,EAAE,QAAQ,EAAE;EAC5B,KAAK,EAAE,QAAQ,EAAE,QAAQ;EACzB;AACF,QAAO,CACN,GAAG,UAAU,QAAQ,KAAK,gBAAgB,mBAAmBC,gBAA4B,CAAC,IACzF,KAAK,SAAS,CACd,EACD,GAAG,UACF,QACA,KACA,gBACA,qBACAC,kBACA,CAAC,IAAI,KAAK,WAAW,CAAC,CACvB;;AAGF,SAAgB,iBACf,KACA,QACqB;AACrB,QAAO,UACN,QACA,IAAI,SAAS,aAAa,IAAI,SAAS,SACvC,gBACA,oBACAC,iBACA,CAAC,KAAK,OAAO;EACb,SAAS,oBAAoB,EAAE,cAAc;EAC7C,WAAW,oBAAoB,EAAE,WAAW;EAC5C,WAAW,oBAAoB,EAAE,UAAU;EAC3C,OAAO,EAAE;EACT,UAAU,EAAE;EACZ,QAAQ,QAAQ,EAAE,QAAQ,EAAE;EAC5B,KAAK,EAAE,QAAQ,EAAE,QAAQ;EACzB,EAAE;;AAGJ,SAAgB,sBACf,KACA,QACuB;AACvB,QAAO,UACN,QACA,IAAI,SAAS,aAAa,IAAI,SAAS,SACvC,uBACA,kBACAC,eACA,CAAC,KAAK,OAAO;EACb,WAAW,oBAAoB,EAAE,WAAW;EAC5C,OAAO,oBAAoB,EAAE,MAAM;EACnC,eAAe,MAAM,EAAE,gBAAgB;EACvC,EAAE"}
1
+ {"version":3,"file":"decode.mjs","names":["orderEvents.OrderMinted","orderEvents.LiveOrderRedeemed","orderEvents.SettledOrderRedeemed","accountEvents.AccountCreated","accountEvents.Deposited","accountEvents.Withdrawn","vaultEvents.SupplyRequested","vaultEvents.WithdrawRequested","vaultEvents.RequestCancelled","builderCodeEvents.BuilderCodeSet","queueEvents.OrderEnqueued","queueEvents.CohortCommitted","queueEvents.QueuedOrderFilled","queueEvents.QueuedOrderRefunded","queueEvents.OpenRecordSettled","queueEvents.OpenRecordPayoutSkipped","queueEvents.MarketPayoutsCompleted","queueEvents.RecordFundsParked","queueEvents.RecordFundsClaimed","queueEvents.QueuedOrdersCleaned","vaultEvents.ExpiryPnlRealized"],"sources":["../../src/predict/decode.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { fromBase64, normalizeSuiAddress } from '@mysten/sui/utils';\nimport type { PredictConfig } from './config/index.js';\nimport { accountEvents } from '../account.js';\nimport * as builderCodeEvents from '../contracts/deepbook_predict/builder_code_events.js';\nimport * as configEvents from '../contracts/deepbook_predict/config_events.js';\nimport * as orderEvents from '../contracts/deepbook_predict/order_events.js';\nimport * as vaultEvents from '../contracts/deepbook_predict/vault_events.js';\nimport * as queueEvents from '../contracts/deepbook_predict_orders/queue_events.js';\nimport { PredictInputError } from './errors.js';\nimport {\n\tisMintKind,\n\tisSellKind,\n\torderKindName,\n\tpolicyFromBcs,\n\trefundReason,\n\ttype DelayedExecutionPolicy,\n\ttype HeldPosition,\n\ttype OrderKindName,\n\ttype RefundReasonInfo,\n} from './queue.js';\nimport { decodeOrderRange } from './cost.js';\nimport { fromRaw } from './units.js';\n\n// ============================================================================\n// Execution-result decoders.\n//\n// Every tx.* builder returns a Transaction; after the app executes it (with\n// events included), the deployed contracts emit typed events carrying the full\n// receipt — order ids, fills, fees, queue indexes, new balances. These pure\n// functions turn that result into typed receipts. No network, no client.\n//\n// Decoding uses each event's BCS bytes, not its `json`: the client typings\n// warn the JSON rendering varies across transports (JSON-RPC/gRPC/GraphQL),\n// while BCS is canonical. Layouts come from the GENERATED event MoveStructs\n// (src/contracts/{deepbook_predict,deepbook_predict_orders,account}/*_events.ts), whose field order\n// mirrors the deployed Move — regenerate the bindings if the package changes.\n// ============================================================================\n\n/** The slice of an executed/simulated transaction result the decoders need. */\nexport interface DecodableEvent {\n\t/** Full type tag `0xpkg::module::Name` (gRPC `eventType`, legacy `type`). */\n\teventType?: string;\n\ttype?: string;\n\tpackageId?: string;\n\tmodule?: string;\n\t/** Struct name, when the transport supplies it separately from a full type tag. */\n\tname?: string;\n\t/** Canonical BCS payload; some transports deliver it base64-encoded. */\n\tbcs?: Uint8Array | string;\n}\n\nexport interface DecodableTransactionResult {\n\tevents?: readonly DecodableEvent[] | null;\n}\n\n// --- matching + plumbing ----------------------------------------------------\n\nfunction eventBytes(e: DecodableEvent): Uint8Array | null {\n\tif (e.bcs instanceof Uint8Array) return e.bcs;\n\tif (typeof e.bcs === 'string') return fromBase64(e.bcs);\n\treturn null;\n}\n\n// Match by defining package + module + struct name. Events are typed by the\n// package version that introduced their struct, not the latest Move-call target.\n// The pre-queue events were introduced in v1 (`predictV1`); the Predict events the\n// delayed-execution upgrade added in `predictDelayedExecution`; and the queue events\n// in the order-flow companion's original ID (`predictOrdersV1 ?? predictOrders`).\nfunction matches(e: DecodableEvent, pkg: string, module: string, name: string): boolean {\n\tconst tag = e.eventType ?? e.type;\n\tif (tag) {\n\t\tconst parts = tag.split('::');\n\t\tif (parts.length !== 3) return false;\n\t\treturn (\n\t\t\tnormalizeSuiAddress(parts[0]) === normalizeSuiAddress(pkg) &&\n\t\t\tparts[1] === module &&\n\t\t\tparts[2] === name\n\t\t);\n\t}\n\t// No type tag. Match on what the transport did give us — and on `name` when it is\n\t// present, because module+package alone matches EVERY struct in the module, so one\n\t// decoder would happily take another's event and fail deep inside BCS.\n\tif (e.module !== module || e.packageId == null) return false;\n\tif (normalizeSuiAddress(e.packageId) !== normalizeSuiAddress(pkg)) return false;\n\treturn e.name == null || e.name === name;\n}\n\nfunction decodeAll<T>(\n\tresult: DecodableTransactionResult,\n\tpkg: string,\n\tmodule: string,\n\tname: string,\n\tlayout: { parse(bytes: Uint8Array): T },\n): T[] {\n\tconst out: T[] = [];\n\tfor (const e of result.events ?? []) {\n\t\tif (!matches(e, pkg, module, name)) continue;\n\t\tconst bytes = eventBytes(e);\n\t\tif (!bytes) {\n\t\t\tthrow new PredictInputError(\n\t\t\t\t`${module}::${name} event has no BCS payload — execute/simulate with events included`,\n\t\t\t);\n\t\t}\n\t\tout.push(layout.parse(bytes));\n\t}\n\treturn out;\n}\n\nfunction exactlyOne<T>(items: T[], what: string): T {\n\tif (items.length !== 1) {\n\t\tthrow new PredictInputError(`expected exactly one ${what} event, found ${items.length}`);\n\t}\n\treturn items[0];\n}\n\nconst optId = (v: string | null | undefined): string | null =>\n\tv == null ? null : normalizeSuiAddress(v);\n\n// --- receipts ---------------------------------------------------------------\n\nexport interface MintReceipt {\n\tmarketId: string;\n\taccountId: string;\n\towner: string;\n\t/** Persist this: required to redeem/claim the position later. */\n\torderId: bigint;\n\t/** Stable across partial-close replacements; equals orderId at mint. */\n\tpositionRootId: bigint;\n\tlowerTick: bigint;\n\thigherTick: bigint;\n\t/** 0..1 range probability quoted at entry (your fill price per $1 payout). */\n\tentryProbability: number;\n\t/** Max payout actually minted, in quote units (mintAmount: chain-floored). */\n\tquantity: number;\n\t/** Premium paid into LP backing, in quote units. */\n\tpremium: number;\n\t/**\n\t * Fee breakdown. `referral` is the slice of the trader-paid trading fee and\n\t * congestion surcharge delivered to the referrer; `inventoryImpact` is the\n\t * path-independent inventory-impact charge assessed on the mint.\n\t */\n\tfees: {\n\t\ttrading: number;\n\t\tsubsidy: number;\n\t\tbuilder: number;\n\t\tpenalty: number;\n\t\treferral: number;\n\t\tinventoryImpact: number;\n\t};\n\tbuilderCodeId: string | null;\n\traw: {\n\t\tquantity: bigint;\n\t\tpremium: bigint;\n\t\ttradingFee: bigint;\n\t\tfeeIncentiveSubsidy: bigint;\n\t\tbuilderFee: bigint;\n\t\tpenaltyFee: bigint;\n\t\treferralFee: bigint;\n\t\tinventoryImpactCharge: bigint;\n\t\tentryProbability: bigint;\n\t};\n}\n\nexport interface RedeemReceipt {\n\tmarketId: string;\n\taccountId: string;\n\towner: string;\n\torderId: bigint;\n\tpositionRootId: bigint;\n\tquantityClosed: number;\n\tremaining: number;\n\t/**\n\t * A partial close RETIRES the old order id and issues this replacement for\n\t * the remaining quantity — update your stored id or it goes silently stale.\n\t */\n\treplacementOrderId: bigint | null;\n\t/** NET quote credited to the account: gross + inventoryImpactRebate − trading −\n\t * builder − penalty — the same expression the chain asserts `min_proceeds`\n\t * against, and what `settle_live_redeem_payment` actually deposits. */\n\tproceeds: number;\n\t/** Gross close value before fees (the event's redeem_amount). */\n\tgross: number;\n\t/**\n\t * Fee breakdown. `inventoryImpactRebate` is the path-independent\n\t * inventory-impact rebate credited back on the close.\n\t */\n\tfees: { trading: number; builder: number; penalty: number; inventoryImpactRebate: number };\n\tbuilderCodeId: string | null;\n\traw: {\n\t\tquantityClosed: bigint;\n\t\tremaining: bigint;\n\t\tproceeds: bigint;\n\t\tgross: bigint;\n\t\ttradingFee: bigint;\n\t\tbuilderFee: bigint;\n\t\tpenaltyFee: bigint;\n\t\tinventoryImpactRebate: bigint;\n\t};\n}\n\nexport interface ClaimReceipt {\n\tmarketId: string;\n\taccountId: string;\n\towner: string;\n\torderId: bigint;\n\tpositionRootId: bigint;\n\t/** Quote units paid out. A settled claim closes the order in full. */\n\tpayout: number;\n\traw: { payout: bigint };\n}\n\nexport interface CreateManagerReceipt {\n\taccountId: string;\n\twrapperId: string;\n\towner: string;\n\tselfOwned: boolean;\n}\n\nexport interface BalanceChangeReceipt {\n\taccountId: string;\n\tcoinType: string;\n\t/** Display value assuming a 6-decimal coin (quote + PLP both are). */\n\tamount: number;\n\tnewBalance: number;\n\traw: { amount: bigint; newBalance: bigint };\n}\n\nexport interface PlpRequestReceipt {\n\tkind: 'supply' | 'withdraw';\n\tvaultId: string;\n\taccountId: string;\n\trecipient: string;\n\t/** Feed straight into cancelSupplyPlp / cancelWithdrawPlp. */\n\tindex: bigint;\n\t/** Quote units for supply; PLP shares (6-dec) for withdraw. */\n\tamount: number;\n\traw: { amount: bigint };\n}\n\nexport interface PlpCancelReceipt {\n\tvaultId: string;\n\taccountId: string;\n\trecipient: string;\n\tindex: bigint;\n\tisSupply: boolean;\n\t/** Refund returned to the account (quote for supply, PLP for withdraw). */\n\tamount: number;\n\traw: { amount: bigint };\n}\n\nexport interface BuilderCodeReceipt {\n\taccountId: string;\n\towner: string;\n\t/** Null after unsetBuilderCode. */\n\tbuilderCodeId: string | null;\n}\n\n// --- decoders (plural = all matching events, in event order) ----------------\n\nexport function decodeMints(cfg: PredictConfig, result: DecodableTransactionResult): MintReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'order_events',\n\t\t'OrderMinted',\n\t\torderEvents.OrderMinted,\n\t).map((e) => ({\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\torderId: e.order_id,\n\t\tpositionRootId: e.position_root_id,\n\t\tlowerTick: e.lower_tick,\n\t\thigherTick: e.higher_tick,\n\t\tentryProbability: fromRaw(e.entry_probability, 9),\n\t\tquantity: fromRaw(e.quantity, 6),\n\t\tpremium: fromRaw(e.premium, 6),\n\t\tfees: {\n\t\t\ttrading: fromRaw(e.trading_fee, 6),\n\t\t\tsubsidy: fromRaw(e.fee_incentive_subsidy, 6),\n\t\t\tbuilder: fromRaw(e.builder_fee, 6),\n\t\t\tpenalty: fromRaw(e.penalty_fee, 6),\n\t\t\treferral: fromRaw(e.referral_fee, 6),\n\t\t\tinventoryImpact: fromRaw(e.inventory_impact_charge, 6),\n\t\t},\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t\traw: {\n\t\t\tquantity: e.quantity,\n\t\t\tpremium: e.premium,\n\t\t\ttradingFee: e.trading_fee,\n\t\t\tfeeIncentiveSubsidy: e.fee_incentive_subsidy,\n\t\t\tbuilderFee: e.builder_fee,\n\t\t\tpenaltyFee: e.penalty_fee,\n\t\t\treferralFee: e.referral_fee,\n\t\t\tinventoryImpactCharge: e.inventory_impact_charge,\n\t\t\tentryProbability: e.entry_probability,\n\t\t},\n\t}));\n}\n\nexport function decodeRedeems(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): RedeemReceipt[] {\n\tconst pkg = cfg.packages.predictV1 ?? cfg.packages.predict;\n\tconst live = decodeAll(\n\t\tresult,\n\t\tpkg,\n\t\t'order_events',\n\t\t'LiveOrderRedeemed',\n\t\torderEvents.LiveOrderRedeemed,\n\t).map((e): RedeemReceipt => ({\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\torderId: e.order_id,\n\t\tpositionRootId: e.position_root_id,\n\t\tquantityClosed: fromRaw(e.quantity_closed, 6),\n\t\tremaining: fromRaw(e.remaining_quantity, 6),\n\t\treplacementOrderId: e.replacement_order_id,\n\t\t// Mirrors the deployed close-side accounting exactly (the same expression\n\t\t// `min_proceeds` is asserted against): the net credited to the account is\n\t\t// redeem_amount PLUS the inventory-impact rebate, minus trading, builder and\n\t\t// penalty fees. The event's redeem_amount is GROSS.\n\t\tproceeds: fromRaw(\n\t\t\te.redeem_amount + e.inventory_impact_rebate - e.trading_fee - e.builder_fee - e.penalty_fee,\n\t\t\t6,\n\t\t),\n\t\tgross: fromRaw(e.redeem_amount, 6),\n\t\tfees: {\n\t\t\ttrading: fromRaw(e.trading_fee, 6),\n\t\t\tbuilder: fromRaw(e.builder_fee, 6),\n\t\t\tpenalty: fromRaw(e.penalty_fee, 6),\n\t\t\tinventoryImpactRebate: fromRaw(e.inventory_impact_rebate, 6),\n\t\t},\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t\traw: {\n\t\t\tquantityClosed: e.quantity_closed,\n\t\t\tremaining: e.remaining_quantity,\n\t\t\tproceeds:\n\t\t\t\te.redeem_amount + e.inventory_impact_rebate - e.trading_fee - e.builder_fee - e.penalty_fee,\n\t\t\tgross: e.redeem_amount,\n\t\t\ttradingFee: e.trading_fee,\n\t\t\tbuilderFee: e.builder_fee,\n\t\t\tpenaltyFee: e.penalty_fee,\n\t\t\tinventoryImpactRebate: e.inventory_impact_rebate,\n\t\t},\n\t}));\n\treturn live;\n}\n\nexport function decodeClaims(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): ClaimReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'order_events',\n\t\t'SettledOrderRedeemed',\n\t\torderEvents.SettledOrderRedeemed,\n\t).map((e) => ({\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\torderId: e.order_id,\n\t\tpositionRootId: e.position_root_id,\n\t\tpayout: fromRaw(e.payout_amount, 6),\n\t\traw: { payout: e.payout_amount },\n\t}));\n}\n\nexport function decodeAccountsCreated(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): CreateManagerReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.account,\n\t\t'account_events',\n\t\t'AccountCreated',\n\t\taccountEvents.AccountCreated,\n\t).map((e) => ({\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\twrapperId: normalizeSuiAddress(e.wrapper_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\tselfOwned: e.self_owned,\n\t}));\n}\n\nfunction decodeBalanceChanges(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n\tname: 'Deposited' | 'Withdrawn',\n): BalanceChangeReceipt[] {\n\tconst layout = name === 'Deposited' ? accountEvents.Deposited : accountEvents.Withdrawn;\n\treturn decodeAll(result, cfg.packages.account, 'account_events', name, layout).map((e) => ({\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\tcoinType: e.coin_type,\n\t\tamount: fromRaw(e.amount, 6),\n\t\tnewBalance: fromRaw(e.new_balance, 6),\n\t\traw: { amount: e.amount, newBalance: e.new_balance },\n\t}));\n}\n\nexport const decodeDeposits = (\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): BalanceChangeReceipt[] => decodeBalanceChanges(cfg, result, 'Deposited');\n\nexport const decodeWithdrawals = (\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): BalanceChangeReceipt[] => decodeBalanceChanges(cfg, result, 'Withdrawn');\n\nexport function decodePlpRequests(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): PlpRequestReceipt[] {\n\tconst pkg = cfg.packages.predictV1 ?? cfg.packages.predict;\n\t// Supply/WithdrawRequested differ only in their min-out field (unused here);\n\t// pick the fields both share so either generated struct's parse feeds `make`.\n\ttype RequestedCommon = Pick<\n\t\t(typeof vaultEvents.SupplyRequested)['$inferType'],\n\t\t'pool_vault_id' | 'account_id' | 'recipient' | 'index' | 'amount'\n\t>;\n\tconst make =\n\t\t(kind: 'supply' | 'withdraw') =>\n\t\t(e: RequestedCommon): PlpRequestReceipt => ({\n\t\t\tkind,\n\t\t\tvaultId: normalizeSuiAddress(e.pool_vault_id),\n\t\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\t\trecipient: normalizeSuiAddress(e.recipient),\n\t\t\tindex: e.index,\n\t\t\tamount: fromRaw(e.amount, 6),\n\t\t\traw: { amount: e.amount },\n\t\t});\n\treturn [\n\t\t...decodeAll(result, pkg, 'vault_events', 'SupplyRequested', vaultEvents.SupplyRequested).map(\n\t\t\tmake('supply'),\n\t\t),\n\t\t...decodeAll(\n\t\t\tresult,\n\t\t\tpkg,\n\t\t\t'vault_events',\n\t\t\t'WithdrawRequested',\n\t\t\tvaultEvents.WithdrawRequested,\n\t\t).map(make('withdraw')),\n\t];\n}\n\nexport function decodePlpCancels(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): PlpCancelReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'vault_events',\n\t\t'RequestCancelled',\n\t\tvaultEvents.RequestCancelled,\n\t).map((e) => ({\n\t\tvaultId: normalizeSuiAddress(e.pool_vault_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\trecipient: normalizeSuiAddress(e.recipient),\n\t\tindex: e.index,\n\t\tisSupply: e.is_supply,\n\t\tamount: fromRaw(e.amount, 6),\n\t\traw: { amount: e.amount },\n\t}));\n}\n\nexport function decodeBuilderCodeSets(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): BuilderCodeReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'builder_code_events',\n\t\t'BuilderCodeSet',\n\t\tbuilderCodeEvents.BuilderCodeSet,\n\t).map((e) => ({\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t}));\n}\n\n// --- delayed execution (DBU-885) ---------------------------------------------\n//\n// Delayed execution spans two packages. The queue events and the desk's\n// `DelayedExecutionPolicyUpdated` belong to the order-flow companion,\n// `deepbook_predict_orders` (`queue_events`), typed by its ORIGINAL ID. A fill also emits\n// Predict's `OrderMinted` or `LiveOrderRedeemed` (v1 layouts, `decodeMints`/`decodeRedeems`),\n// so match events by type, never by the package a transaction called. The Predict events the\n// delayed-execution upgrade added (`ExpiryPnlRealized`, `FlushOperatorUpdated`,\n// `OrderFlowUpdated`) are typed by `packages.predictDelayedExecution`.\n\n/**\n * The defining package of the Predict types and events the delayed-execution upgrade added.\n * Throws rather than guessing: matching against the latest package would silently decode nothing\n * once the package is upgraded again.\n */\nexport function delayedExecutionOrigin(cfg: PredictConfig): string {\n\tconst pkg = cfg.packages.predictDelayedExecution;\n\tif (!pkg) {\n\t\tthrow new PredictInputError(\n\t\t\t`delayed execution isn't recorded for ${cfg.network} in this SDK version: pass a ` +\n\t\t\t\t'`config` whose `packages.predictDelayedExecution` names the package that introduced it',\n\t\t);\n\t}\n\treturn pkg;\n}\n\n/**\n * The original ID of the order-flow companion (`deepbook_predict_orders`), which types the queue\n * events. Throws while the config doesn't record the companion.\n */\nexport function predictOrdersOrigin(cfg: PredictConfig): string {\n\tconst pkg = cfg.packages.predictOrdersV1 ?? cfg.packages.predictOrders;\n\tif (!pkg) {\n\t\tthrow new PredictInputError(\n\t\t\t`the order-flow package isn't recorded for ${cfg.network} in this SDK version: pass a ` +\n\t\t\t\t'`config` whose `packages.predictOrders` names `deepbook_predict_orders`',\n\t\t);\n\t}\n\treturn pkg;\n}\n\nfunction side(kind: number): 'mint' | 'sell' | 'unknown' {\n\treturn isMintKind(kind) ? 'mint' : isSellKind(kind) ? 'sell' : 'unknown';\n}\n\nfunction heldPosition(\n\tp: {\n\t\torder_id: bigint;\n\t\troot_id: bigint;\n\t\topened_at_ms: bigint;\n\t},\n\tlotSize: bigint,\n): HeldPosition | null {\n\treturn p.order_id === 0n\n\t\t? null\n\t\t: {\n\t\t\t\torderId: p.order_id,\n\t\t\t\trootId: p.root_id,\n\t\t\t\topenedAtMs: p.opened_at_ms,\n\t\t\t\tquantityRaw: decodeOrderRange(p.order_id, lotSize).quantity,\n\t\t\t};\n}\n\n/** The market's cash figures after the call, as the queue events report them. */\nexport interface QueueCashFigures {\n\tmarketCash: bigint;\n\trequiredCash: bigint;\n\twaitingCashNeed: bigint;\n}\n\n/** `OrderEnqueued`: the trader's own receipt for a queued mint or sell. Drives \"Placed\". */\nexport interface EnqueueReceipt {\n\ttype: 'enqueued';\n\tmarketId: string;\n\t/** The record ID: what `read.order`, `quoteSell` and `enqueueSell` take. Persist it. */\n\trecordId: bigint;\n\taccountId: string;\n\tkind: number;\n\tkindName: OrderKindName;\n\tside: 'mint' | 'sell' | 'unknown';\n\trequest: {\n\t\tlowerTick: bigint;\n\t\thigherTick: bigint;\n\t\tquantity: bigint;\n\t\tmaxPremium: bigint;\n\t\tminQuantity: bigint;\n\t\tmaxCost: bigint;\n\t\tmaxProbability: bigint;\n\t\tminProbability: bigint;\n\t\tminProceeds: bigint;\n\t};\n\t/** The position a sell moved into the record. Null for a mint. */\n\tposition: HeldPosition | null;\n\ttiming: {\n\t\tplacedAtMs: bigint;\n\t\tearliestPriceMs: bigint;\n\t\ttauMs: bigint;\n\t\tdeadlineMs: bigint;\n\t\tcutoffMs: bigint;\n\t\tpythChannel: number;\n\t};\n\t/** The Open record a sell took its position from. Null for a mint. */\n\tsourceRecordId: bigint | null;\n\tbuilderCodeId: string | null;\n\treferrerAccountId: string | null;\n\t/** USDC escrowed for the premium and fees (0 for a sell). */\n\tbudget: number;\n\torderFee: number;\n\tcash: QueueCashFigures;\n\t/** `onchain_timestamp_ms`: the placement transaction's clock. */\n\ttimestampMs: bigint;\n\traw: { budget: bigint; orderFee: bigint; cashNeed: bigint; subsidyBound: bigint };\n\t/** The volatility snapshot the fill prices with, as the generated layout parses it. */\n\tvol: (typeof queueEvents.OrderEnqueued)['$inferType']['vol'];\n}\n\n/** `CohortCommitted`: a price attached to the records `firstRecordId..=lastRecordId`. Drives \"Priced\". */\nexport interface CohortCommitReceipt {\n\ttype: 'cohort-committed';\n\tmarketId: string;\n\ttauMs: bigint;\n\t/** The update's envelope: τ, or the backup tick one channel tick later. */\n\ttickMs: bigint;\n\tfirstRecordId: bigint;\n\t/** Inclusive. */\n\tlastRecordId: bigint;\n\t/** The committed price of the cohort's first order as a float: `spotRaw / 1e9`. */\n\tprice: number;\n\t/** The committed price, normalized to 1e9. */\n\tspotRaw: bigint;\n\t/** That price's own update time, in µs. */\n\tgenerationUs: bigint;\n\tpythSourceId: number;\n\tpythChannel: number;\n\t/** Who committed: a keeper, or any third-party filler. */\n\tsender: string;\n\t/** `onchain_timestamp_ms`. */\n\ttimestampMs: bigint;\n}\n\n/** `QueuedOrderFilled`. Report \"Filled\" only from this event (or the record). */\nexport interface QueuedFillReceipt {\n\ttype: 'filled';\n\tmarketId: string;\n\trecordId: bigint;\n\taccountId: string;\n\tkind: number;\n\tside: 'mint' | 'sell' | 'unknown';\n\t/** Filled quantity (mint) or closed quantity (sell). */\n\tquantity: number;\n\t/** Cost paid (mint) or proceeds before the order fee (sell). */\n\tamount: number;\n\tfees: {\n\t\ttrading: number;\n\t\tbuilder: number;\n\t\treferral: number;\n\t\torder: number;\n\t\tsubsidyUsed: number;\n\t\tinventoryImpact: number;\n\t};\n\ttauMs: bigint;\n\ttickMs: bigint;\n\t/** The record's position now: a mint's new position, a partial sell's remainder, or null. */\n\tposition: HeldPosition | null;\n\tsender: string;\n\ttimestampMs: bigint;\n\tcash: QueueCashFigures;\n\traw: {\n\t\tquantity: bigint;\n\t\tamount: bigint;\n\t\ttradingFee: bigint;\n\t\tbuilderFee: bigint;\n\t\treferralFee: bigint;\n\t\torderFee: bigint;\n\t\tsubsidyUsed: bigint;\n\t\tinventoryImpact: bigint;\n\t};\n}\n\n/**\n * `QueuedOrderRefunded`, from whichever path refunded the order: resolve, a deadline refund, an\n * admin refund, or the settlement drain (`settle_step`, reason 5). `sender` is always the\n * transaction's sender.\n */\nexport interface QueuedRefundReceipt {\n\ttype: 'refunded';\n\tmarketId: string;\n\trecordId: bigint;\n\taccountId: string;\n\tkind: number;\n\tside: 'mint' | 'sell' | 'unknown';\n\treason: RefundReasonInfo;\n\tescrowReturned: number;\n\torderFeeReturned: number;\n\tsubsidyReturned: number;\n\t/** True when a sell's record went back to Open holding its position. */\n\tpositionReturned: boolean;\n\tsender: string;\n\ttimestampMs: bigint;\n\tcash: QueueCashFigures;\n\traw: { escrowReturned: bigint; orderFeeReturned: bigint; subsidyReturned: bigint };\n}\n\n/**\n * `OpenRecordSettled` (paid, 0 for a loser) or `OpenRecordPayoutSkipped` (stays Open, for a later\n * `pay_open`), from `settle_step`'s payout walk or `pay_open`.\n */\nexport interface OpenRecordPayoutReceipt {\n\ttype: 'open-record-settled' | 'open-record-payout-skipped';\n\tmarketId: string;\n\trecordId: bigint;\n\taccountId: string;\n\torderId: bigint;\n\tpayout: number;\n\t/** True for `OpenRecordPayoutSkipped`: the market couldn't pay it yet. */\n\tskipped: boolean;\n\ttimestampMs: bigint;\n\traw: { payout: bigint };\n}\n\n/** `MarketPayoutsCompleted`: the settlement payout walk is done. */\nexport interface MarketPayoutsCompletedReceipt {\n\ttype: 'market-payouts-completed';\n\tmarketId: string;\n\ttimestampMs: bigint;\n}\n\n/**\n * `RecordFundsParked`: a record kept USDC it couldn't send to its receive address (on USDC's deny\n * list, or USDC paused). `RecordFundsClaimed`: `claim_parked` sent a record's parked funds.\n */\nexport interface RecordFundsReceipt {\n\ttype: 'record-funds-parked' | 'record-funds-claimed';\n\tmarketId: string;\n\trecordId: bigint;\n\taccountId: string;\n\treceiveAddress: string;\n\t/** Parked: this call's parked change or refund. Claimed: everything the record had parked. */\n\tamount: number;\n\ttimestampMs: bigint;\n\traw: { amount: bigint };\n}\n\n/** Queue housekeeping events, for ops and alerts. */\nexport type QueueOpsReceipt = {\n\ttype: 'queued-orders-cleaned';\n\tmarketId: string;\n\trecordIds: bigint[];\n\ttimestampMs: bigint;\n};\n\n/** Delayed-execution admin events, for the multisig scripts and monitors. */\nexport type PolicyUpdateReceipt =\n\t| {\n\t\t\t/**\n\t\t\t * The companion desk's `DelayedExecutionPolicyUpdated`, from every policy setter with the\n\t\t\t * full post-state. The desk's `init` at publish emits none: the launch policy is only the\n\t\t\t * desk's state.\n\t\t\t */\n\t\t\ttype: 'policy-updated';\n\t\t\tdeskId: string;\n\t\t\tpolicy: DelayedExecutionPolicy;\n\t\t\ttimestampMs: bigint;\n\t }\n\t| { type: 'flush-operator-updated'; operator: string; added: boolean; timestampMs: bigint }\n\t| {\n\t\t\t/** Predict's `OrderFlowUpdated`: an order-flow witness allowlisted or removed. */\n\t\t\ttype: 'order-flow-updated';\n\t\t\t/** The witness type, as Move's `type_name` renders it (no `0x` prefix). */\n\t\t\torderFlow: string;\n\t\t\tenabled: boolean;\n\t\t\ttimestampMs: bigint;\n\t };\n\n/** Every delayed-execution order event, tagged, in chain order. Feed it to `queue.reduceOrderEvents`. */\nexport type QueueEvent =\n\t| EnqueueReceipt\n\t| CohortCommitReceipt\n\t| QueuedFillReceipt\n\t| QueuedRefundReceipt\n\t| OpenRecordPayoutReceipt\n\t| MarketPayoutsCompletedReceipt\n\t| RecordFundsReceipt\n\t| QueueOpsReceipt;\n\nconst cashOf = (e: { market_cash: bigint; required_cash: bigint; waiting_cash_need: bigint }) => ({\n\tmarketCash: e.market_cash,\n\trequiredCash: e.required_cash,\n\twaitingCashNeed: e.waiting_cash_need,\n});\n\nfunction enqueueReceipt(\n\te: (typeof queueEvents.OrderEnqueued)['$inferType'],\n\tlotSize: bigint,\n): EnqueueReceipt {\n\treturn {\n\t\ttype: 'enqueued',\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\trecordId: e.record_id,\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\tkind: e.kind,\n\t\tkindName: orderKindName(e.kind),\n\t\tside: side(e.kind),\n\t\trequest: {\n\t\t\tlowerTick: e.request.lower_tick,\n\t\t\thigherTick: e.request.higher_tick,\n\t\t\tquantity: e.request.quantity,\n\t\t\tmaxPremium: e.request.max_premium,\n\t\t\tminQuantity: e.request.min_quantity,\n\t\t\tmaxCost: e.request.max_cost,\n\t\t\tmaxProbability: e.request.max_probability,\n\t\t\tminProbability: e.request.min_probability,\n\t\t\tminProceeds: e.request.min_proceeds,\n\t\t},\n\t\tposition: heldPosition(e.position, lotSize),\n\t\ttiming: {\n\t\t\tplacedAtMs: e.timing.placed_at_ms,\n\t\t\tearliestPriceMs: e.timing.earliest_price_ms,\n\t\t\ttauMs: e.timing.tau_ms,\n\t\t\tdeadlineMs: e.timing.deadline_ms,\n\t\t\tcutoffMs: e.timing.cutoff_ms,\n\t\t\tpythChannel: e.timing.pyth_channel,\n\t\t},\n\t\tsourceRecordId: e.source_record_id ?? null,\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t\treferrerAccountId: optId(e.referrer_account_id),\n\t\tbudget: fromRaw(e.budget, 6),\n\t\torderFee: fromRaw(e.order_fee, 6),\n\t\tcash: cashOf(e),\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\traw: {\n\t\t\tbudget: e.budget,\n\t\t\torderFee: e.order_fee,\n\t\t\tcashNeed: e.cash_need,\n\t\t\tsubsidyBound: e.subsidy_bound,\n\t\t},\n\t\tvol: e.vol,\n\t};\n}\n\nfunction cohortCommitReceipt(\n\te: (typeof queueEvents.CohortCommitted)['$inferType'],\n): CohortCommitReceipt {\n\treturn {\n\t\ttype: 'cohort-committed',\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\ttauMs: e.tau_ms,\n\t\ttickMs: e.tick_ms,\n\t\tfirstRecordId: e.first_record_id,\n\t\tlastRecordId: e.last_record_id,\n\t\tprice: fromRaw(e.spot, 9),\n\t\tspotRaw: e.spot,\n\t\tgenerationUs: e.generation_us,\n\t\tpythSourceId: e.pyth_source_id,\n\t\tpythChannel: e.pyth_channel,\n\t\tsender: normalizeSuiAddress(e.sender),\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t};\n}\n\nfunction fillReceipt(\n\te: (typeof queueEvents.QueuedOrderFilled)['$inferType'],\n\tlotSize: bigint,\n): QueuedFillReceipt {\n\treturn {\n\t\ttype: 'filled',\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\trecordId: e.record_id,\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\tkind: e.kind,\n\t\tside: side(e.kind),\n\t\tquantity: fromRaw(e.quantity, 6),\n\t\tamount: fromRaw(e.amount, 6),\n\t\tfees: {\n\t\t\ttrading: fromRaw(e.trading_fee, 6),\n\t\t\tbuilder: fromRaw(e.builder_fee, 6),\n\t\t\treferral: fromRaw(e.referral_fee, 6),\n\t\t\torder: fromRaw(e.order_fee, 6),\n\t\t\tsubsidyUsed: fromRaw(e.subsidy_used, 6),\n\t\t\tinventoryImpact: fromRaw(e.inventory_impact, 6),\n\t\t},\n\t\ttauMs: e.tau_ms,\n\t\ttickMs: e.tick_ms,\n\t\tposition: heldPosition(e.position, lotSize),\n\t\tsender: normalizeSuiAddress(e.sender),\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\tcash: cashOf(e),\n\t\traw: {\n\t\t\tquantity: e.quantity,\n\t\t\tamount: e.amount,\n\t\t\ttradingFee: e.trading_fee,\n\t\t\tbuilderFee: e.builder_fee,\n\t\t\treferralFee: e.referral_fee,\n\t\t\torderFee: e.order_fee,\n\t\t\tsubsidyUsed: e.subsidy_used,\n\t\t\tinventoryImpact: e.inventory_impact,\n\t\t},\n\t};\n}\n\nfunction refundReceipt(\n\te: (typeof queueEvents.QueuedOrderRefunded)['$inferType'],\n): QueuedRefundReceipt {\n\treturn {\n\t\ttype: 'refunded',\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\trecordId: e.record_id,\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\tkind: e.kind,\n\t\tside: side(e.kind),\n\t\treason: refundReason(e.reason),\n\t\tescrowReturned: fromRaw(e.escrow_returned, 6),\n\t\torderFeeReturned: fromRaw(e.order_fee_returned, 6),\n\t\tsubsidyReturned: fromRaw(e.subsidy_returned, 6),\n\t\tpositionReturned: e.position_returned,\n\t\tsender: normalizeSuiAddress(e.sender),\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\tcash: cashOf(e),\n\t\traw: {\n\t\t\tescrowReturned: e.escrow_returned,\n\t\t\torderFeeReturned: e.order_fee_returned,\n\t\t\tsubsidyReturned: e.subsidy_returned,\n\t\t},\n\t};\n}\n\nfunction payoutReceipt(\n\tskipped: boolean,\n): (e: (typeof queueEvents.OpenRecordSettled)['$inferType']) => OpenRecordPayoutReceipt {\n\treturn (e) => ({\n\t\ttype: skipped ? 'open-record-payout-skipped' : 'open-record-settled',\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\trecordId: e.record_id,\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\torderId: e.order_id,\n\t\tpayout: fromRaw(e.payout, 6),\n\t\tskipped,\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\traw: { payout: e.payout },\n\t});\n}\n\nfunction recordFundsReceipt(\n\ttype: RecordFundsReceipt['type'],\n): (e: (typeof queueEvents.RecordFundsParked)['$inferType']) => RecordFundsReceipt {\n\treturn (e) => ({\n\t\ttype,\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\trecordId: e.record_id,\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\treceiveAddress: normalizeSuiAddress(e.receive_address),\n\t\tamount: fromRaw(e.amount, 6),\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\traw: { amount: e.amount },\n\t});\n}\n\n// Each order event the queue emits: its struct name, generated layout and receipt mapping.\n// One table drives both the per-type decoders and `decodeQueueEvents`, so they can't disagree.\nconst QUEUE_EVENT_DECODERS: readonly {\n\tname: string;\n\tlayout: { parse(bytes: Uint8Array): unknown };\n\t// `lotSize` is the config's position lot, which decodes a held position's quantity.\n\tmap: (e: never, lotSize: bigint) => QueueEvent;\n}[] = [\n\t{ name: 'OrderEnqueued', layout: queueEvents.OrderEnqueued, map: enqueueReceipt },\n\t{ name: 'CohortCommitted', layout: queueEvents.CohortCommitted, map: cohortCommitReceipt },\n\t{ name: 'QueuedOrderFilled', layout: queueEvents.QueuedOrderFilled, map: fillReceipt },\n\t{ name: 'QueuedOrderRefunded', layout: queueEvents.QueuedOrderRefunded, map: refundReceipt },\n\t{ name: 'OpenRecordSettled', layout: queueEvents.OpenRecordSettled, map: payoutReceipt(false) },\n\t{\n\t\tname: 'OpenRecordPayoutSkipped',\n\t\tlayout: queueEvents.OpenRecordPayoutSkipped,\n\t\tmap: payoutReceipt(true),\n\t},\n\t{\n\t\tname: 'MarketPayoutsCompleted',\n\t\tlayout: queueEvents.MarketPayoutsCompleted,\n\t\tmap: (e: (typeof queueEvents.MarketPayoutsCompleted)['$inferType']) => ({\n\t\t\ttype: 'market-payouts-completed',\n\t\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\t}),\n\t},\n\t{\n\t\tname: 'RecordFundsParked',\n\t\tlayout: queueEvents.RecordFundsParked,\n\t\tmap: recordFundsReceipt('record-funds-parked'),\n\t},\n\t{\n\t\tname: 'RecordFundsClaimed',\n\t\tlayout: queueEvents.RecordFundsClaimed,\n\t\tmap: recordFundsReceipt('record-funds-claimed'),\n\t},\n\t{\n\t\tname: 'QueuedOrdersCleaned',\n\t\tlayout: queueEvents.QueuedOrdersCleaned,\n\t\tmap: (e: (typeof queueEvents.QueuedOrdersCleaned)['$inferType']) => ({\n\t\t\ttype: 'queued-orders-cleaned',\n\t\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\t\trecordIds: [...e.record_ids],\n\t\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\t}),\n\t},\n];\n\nfunction eventPayload(e: DecodableEvent, module: string, name: string): Uint8Array {\n\tconst bytes = eventBytes(e);\n\tif (!bytes) {\n\t\tthrow new PredictInputError(\n\t\t\t`${module}::${name} event has no BCS payload — execute/simulate with events included`,\n\t\t);\n\t}\n\treturn bytes;\n}\n\n/**\n * Every delayed-execution order event in a result, tagged with `type`, in event order: the\n * companion's `queue_events`, matched against its original ID. The app's single entry point for\n * the queue: pass the list to `queue.reduceOrderEvents`.\n */\nexport function decodeQueueEvents(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): QueueEvent[] {\n\tconst pkg = predictOrdersOrigin(cfg);\n\tconst lotSize = BigInt(cfg.units.positionLotSize);\n\tconst out: QueueEvent[] = [];\n\tfor (const e of result.events ?? []) {\n\t\tfor (const d of QUEUE_EVENT_DECODERS) {\n\t\t\tif (!matches(e, pkg, 'queue_events', d.name)) continue;\n\t\t\tout.push(d.map(d.layout.parse(eventPayload(e, 'queue_events', d.name)) as never, lotSize));\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn out;\n}\n\nfunction ofType<T extends QueueEvent['type']>(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n\t...types: T[]\n): Extract<QueueEvent, { type: T }>[] {\n\treturn decodeQueueEvents(cfg, result).filter((e): e is Extract<QueueEvent, { type: T }> =>\n\t\t(types as string[]).includes(e.type),\n\t);\n}\n\nexport const decodeEnqueues = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'enqueued');\nexport const decodeCohortCommits = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'cohort-committed');\nexport const decodeQueuedFills = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'filled');\nexport const decodeQueuedRefunds = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'refunded');\nexport const decodeOpenRecordPayouts = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'open-record-settled', 'open-record-payout-skipped');\nexport const decodeMarketPayoutsCompleted = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'market-payouts-completed');\nexport const decodeRecordFunds = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'record-funds-parked', 'record-funds-claimed');\nexport const decodeQueueOps = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'queued-orders-cleaned');\n\n/**\n * The delayed-execution admin events, in event order: the companion desk's\n * `DelayedExecutionPolicyUpdated` (matched against the companion's original ID) and Predict's\n * `FlushOperatorUpdated` and `OrderFlowUpdated` (matched against `predictDelayedExecution`).\n * Throws while the config records neither package.\n */\nexport function decodePolicyUpdates(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): PolicyUpdateReceipt[] {\n\tconst orders = predictOrdersOrigin(cfg);\n\tconst predict = delayedExecutionOrigin(cfg);\n\tconst out: PolicyUpdateReceipt[] = [];\n\tfor (const e of result.events ?? []) {\n\t\tif (matches(e, orders, 'queue_events', 'DelayedExecutionPolicyUpdated')) {\n\t\t\tconst p = queueEvents.DelayedExecutionPolicyUpdated.parse(\n\t\t\t\teventPayload(e, 'queue_events', 'DelayedExecutionPolicyUpdated'),\n\t\t\t);\n\t\t\tout.push({\n\t\t\t\ttype: 'policy-updated',\n\t\t\t\tdeskId: normalizeSuiAddress(p.desk_id),\n\t\t\t\tpolicy: policyFromBcs(p.policy),\n\t\t\t\ttimestampMs: p.onchain_timestamp_ms,\n\t\t\t});\n\t\t} else if (matches(e, predict, 'config_events', 'FlushOperatorUpdated')) {\n\t\t\tconst f = configEvents.FlushOperatorUpdated.parse(\n\t\t\t\teventPayload(e, 'config_events', 'FlushOperatorUpdated'),\n\t\t\t);\n\t\t\tout.push({\n\t\t\t\ttype: 'flush-operator-updated',\n\t\t\t\toperator: normalizeSuiAddress(f.operator),\n\t\t\t\tadded: f.added,\n\t\t\t\ttimestampMs: f.onchain_timestamp_ms,\n\t\t\t});\n\t\t} else if (matches(e, predict, 'config_events', 'OrderFlowUpdated')) {\n\t\t\tconst o = configEvents.OrderFlowUpdated.parse(\n\t\t\t\teventPayload(e, 'config_events', 'OrderFlowUpdated'),\n\t\t\t);\n\t\t\tout.push({\n\t\t\t\ttype: 'order-flow-updated',\n\t\t\t\torderFlow: o.order_flow.name,\n\t\t\t\tenabled: o.enabled,\n\t\t\t\ttimestampMs: o.onchain_timestamp_ms,\n\t\t\t});\n\t\t}\n\t}\n\treturn out;\n}\n\n/**\n * `vault_events::ExpiryPnlRealized`: the change in the pool's gross realized result on one expiry\n * since that expiry's previous emission, emitted with every `ExpiryPnl`. An expiry's first\n * emission (its first settled sweep) carries the lifetime result, which can be a loss. A later\n * one carries the extra cash a later sweep returned, always a profit. Gross: before the\n * protocol/LP split, and including the sponsor fee subsidies mints moved into expiry cash.\n */\nexport interface ExpiryPnlRealizedReceipt {\n\tvaultId: string;\n\tmarketId: string;\n\tpropbookUnderlyingId: number;\n\texpiryMs: bigint;\n\t/** The settlement price, 1e9-scaled. */\n\tsettlementPriceRaw: bigint;\n\t/** False only for a loss, which only an expiry's first emission reports. */\n\tinProfit: boolean;\n\t/** The change's magnitude, in USDC. */\n\tamount: number;\n\t/** The change with its sign: `+amount` for a profit, `−amount` for a loss. */\n\tsignedAmountRaw: bigint;\n\traw: { amount: bigint };\n}\n\n/** Every `ExpiryPnlRealized` in a result, in event order. Introduced with delayed execution. */\nexport function decodeExpiryPnlRealized(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): ExpiryPnlRealizedReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tdelayedExecutionOrigin(cfg),\n\t\t'vault_events',\n\t\t'ExpiryPnlRealized',\n\t\tvaultEvents.ExpiryPnlRealized,\n\t).map((e) => ({\n\t\tvaultId: normalizeSuiAddress(e.pool_vault_id),\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\tpropbookUnderlyingId: e.propbook_underlying_id,\n\t\texpiryMs: e.expiry,\n\t\tsettlementPriceRaw: e.settlement_price,\n\t\tinProfit: e.in_profit,\n\t\tamount: fromRaw(e.amount, 6),\n\t\tsignedAmountRaw: e.in_profit ? e.amount : -e.amount,\n\t\traw: { amount: e.amount },\n\t}));\n}\n\n/**\n * The pool's gross realized P&L in raw USDC: the signed sum of `ExpiryPnlRealized` changes. Over\n * every emission of every expiry it equals the sum of each expiry's latest `ExpiryPnl`, with no\n * per-expiry dedup. Subtract the `OrderMinted.fee_incentive_subsidy` totals to isolate the\n * trading result.\n */\nexport function realizedPnlRaw(\n\treceipts: readonly Pick<ExpiryPnlRealizedReceipt, 'signedAmountRaw'>[],\n): bigint {\n\treturn receipts.reduce((sum, r) => sum + r.signedAmountRaw, 0n);\n}\n\nexport { exactlyOne };\n"],"mappings":";;;;;;;;;;;;;AA2DA,SAAS,WAAW,GAAsC;AACzD,KAAI,EAAE,eAAe,WAAY,QAAO,EAAE;AAC1C,KAAI,OAAO,EAAE,QAAQ,SAAU,QAAO,WAAW,EAAE,IAAI;AACvD,QAAO;;AAQR,SAAS,QAAQ,GAAmB,KAAa,QAAgB,MAAuB;CACvF,MAAM,MAAM,EAAE,aAAa,EAAE;AAC7B,KAAI,KAAK;EACR,MAAM,QAAQ,IAAI,MAAM,KAAK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AC3C,aAAa,GAAG,iBAAiB,uBAAuB,CACxD;AACD,MAAI,KAAK;GACR,MAAM;GACN,UAAU,oBAAoB,EAAE,SAAS;GACzC,OAAO,EAAE;GACT,aAAa,EAAE;GACf,CAAC;YACQ,QAAQ,GAAG,SAAS,iBAAiB,mBAAmB,EAAE;EACpE,MAAM,qBAAkC,MACvC,aAAa,GAAG,iBAAiB,mBAAmB,CACpD;AACD,MAAI,KAAK;GACR,MAAM;GACN,WAAW,EAAE,WAAW;GACxB,SAAS,EAAE;GACX,aAAa,EAAE;GACf,CAAC;;AAGJ,QAAO;;;AA2BR,SAAgB,wBACf,KACA,QAC6B;AAC7B,QAAO,UACN,QACA,uBAAuB,IAAI,EAC3B,gBACA,qBACAC,kBACA,CAAC,KAAK,OAAO;EACb,SAAS,oBAAoB,EAAE,cAAc;EAC7C,UAAU,oBAAoB,EAAE,iBAAiB;EACjD,sBAAsB,EAAE;EACxB,UAAU,EAAE;EACZ,oBAAoB,EAAE;EACtB,UAAU,EAAE;EACZ,QAAQ,QAAQ,EAAE,QAAQ,EAAE;EAC5B,iBAAiB,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE;EAC7C,KAAK,EAAE,QAAQ,EAAE,QAAQ;EACzB,EAAE;;;;;;;;AASJ,SAAgB,eACf,UACS;AACT,QAAO,SAAS,QAAQ,KAAK,MAAM,MAAM,EAAE,iBAAiB,GAAG"}
@@ -9,9 +9,9 @@ declare class PredictMoveError extends Error {
9
9
  /** Exact u64 abort code — bigint because clever-error encodings pack data
10
10
  * into the high bits, which Number would silently truncate. */
11
11
  readonly code: bigint;
12
- /** The `E…` constant name, decoded from the clever-error abort code by the
13
- * fullnode, or null when the transport surfaced no name (a non-clever abort,
14
- * or a JSON-RPC failure that carries only a line number). */
12
+ /** The `E…` constant name: the fullnode's clever-error name when it decodes
13
+ * one, else the name {@link ABORT_NAMES} gives the module's plain code, or null
14
+ * when neither knows the abort. */
15
15
  readonly abortName: string | null;
16
16
  constructor(module: string, code: bigint, abortName: string | null);
17
17
  }
@@ -31,12 +31,75 @@ interface MoveAbortError {
31
31
  * Returns null when `error` carries no MoveAbort (InsufficientGas, a size error, any
32
32
  * non-abort failure), so callers can fall back to a plain Error.
33
33
  *
34
- * `abortName` is taken straight from the chain-decoded clever-error constant; it is
35
- * null when the abort predates clever errors or the transport didn't surface a name.
34
+ * `abortName` is the chain-decoded clever-error constant when the fullnode surfaces one, and
35
+ * otherwise the name {@link ABORT_NAMES} gives the module's plain code (Predict's constants are
36
+ * plain codes, so this is the usual path). It is null when neither knows the abort.
36
37
  * `code` stays a bigint — a clever-error abort code packs the module, line, and
37
38
  * constant index into the high bits of the u64 and would lose precision as a Number.
38
39
  */
39
40
  declare function decodeMoveAbort(error: MoveAbortError | null | undefined): PredictMoveError | null;
41
+ /**
42
+ * Why a queued-order builder refused to add an enqueue. The builder reads the market first and
43
+ * throws this instead of building a transaction the queue or protocol gates would abort, so a
44
+ * refused order never fails the rest of a transaction. Each code mirrors one on-chain refusal. The
45
+ * order's own limits at the current price are checked only on chain (`EOrderFailsLimits`).
46
+ */
47
+ type PredictPreflightCode =
48
+ /**
49
+ * Delayed execution isn't live: Predict's version watermark isn't raised
50
+ * (`ECutoverNotReached`), or Predict doesn't allowlist the order-flow package yet
51
+ * (`EOrderFlowNotAllowed`).
52
+ */
53
+ 'not-live' /** The market has no `MarketQueue` yet: `queue::create_and_share` hasn't run for it. */ | 'no-queue'
54
+ /**
55
+ * A version floor retired code this SDK calls: Predict's watermark is above the Predict
56
+ * version it was built for (`protocol_config::EPackageVersionDisabled`), or the order desk's
57
+ * floor is above its order-flow package (`desk::EPackageVersionDisabled`). Update the SDK.
58
+ */
59
+ | 'retired' /** Trading is paused, the protocol is frozen, or minting is paused on this market. */ | 'paused' /** The market's pricing is delayed (`queue_stuck`). Enqueue aborts `EQueueStuck`. */ | 'stuck'
60
+ /**
61
+ * The order's τ would land at or after the market's order cutoff (`EPastCutoff`). A
62
+ * `read.planMint` or `read.planSell` plan on a market past its expiry throws it too, since the
63
+ * chain has no live price to quote (`ELivePricingExpired`).
64
+ */
65
+ | 'past-cutoff' /** The market has its maximum unfinished mints or sells (`EQueueFull`). */ | 'queue-full' /** The account has its maximum unfinished orders in this market (`EAccountOrderCap`). */ | 'account-cap'
66
+ /**
67
+ * The account balance doesn't cover the order fee (`EFeeNotCovered`). A `read.planMint` plan
68
+ * also reports it when the balance doesn't cover the plan's `totalDebit`, since its limits assume
69
+ * the whole budget, or when the owner has no account yet. Prompt a top-up.
70
+ */
71
+ | 'fee' /** A mint's cash need is above the market's spare cash (`EInsufficientMarketCash`). */ | 'market-cash'
72
+ /**
73
+ * The escrowed budget, or an exact-amount mint's premium cap, can't buy the minimum premium,
74
+ * so the order fails its limits. A budget `read.planMint` plan also reports it when what the
75
+ * budget buys without the fee subsidy, as admission prices it, has a premium below the minimum,
76
+ * and throws it for a budget below the minimum premium or one no fill clears it with.
77
+ */
78
+ | 'min-premium'
79
+ /**
80
+ * The strike's entry probability is outside the market's entry band, so the chain refuses to
81
+ * quote or admit it (`EOrderFailsLimits`). Pick a strike nearer the money. Only `read.planMint`
82
+ * reports it, and the probability can still leave the band between plan and placement.
83
+ */
84
+ | 'entry-band'
85
+ /**
86
+ * The order's all-in cost without the fee subsidy is above its payout, so admission refuses it
87
+ * at any slippage (`EOrderFailsLimits`), or for a budget, the fill costs about its payout, where
88
+ * admission's sizing can't be previewed. Only `read.planMint` reports it, near a certain outcome.
89
+ */
90
+ | 'cost-above-payout' /** A sell is below the policy minimum, or leaves a remainder below it (`EBelowMinSell`). */ | 'below-min-sell' /** The record to sell is missing or not Open (`ERecordNotOpen`). */ | 'record-not-open' /** The record to sell belongs to another account (`ENotRecordOwner`). */ | 'not-record-owner';
91
+ /** A queued-order builder's refusal, raised before any transaction is built. */
92
+ declare class PredictPreflightError extends Error {
93
+ readonly code: PredictPreflightCode;
94
+ constructor(code: PredictPreflightCode, message: string);
95
+ }
96
+ /**
97
+ * Readable text for a decoded Move abort on the Predict paths, or `null` when the abort isn't
98
+ * one this SDK describes (an unknown name, or an abort `decodeMoveAbort` couldn't name). Callers
99
+ * fall back to `e.message` on `null`, so new contract errors degrade to the raw abort rather
100
+ * than to a wrong message.
101
+ */
102
+ declare function describePredictError(e: PredictMoveError): string | null;
40
103
  //#endregion
41
- export { MoveAbortError, PredictInputError, PredictMoveError, decodeMoveAbort };
104
+ export { MoveAbortError, PredictInputError, PredictMoveError, PredictPreflightCode, PredictPreflightError, decodeMoveAbort, describePredictError };
42
105
  //# sourceMappingURL=errors.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/predict/errors.ts"],"mappings":";;cAca,iBAAA,SAA0B,KAAA;cAC1B,OAAA;AAAA;;cAOA,gBAAA,SAAyB,KAAA;EAAA,SAC5B,MAAA;EARG;;EAAA,SAWH,IAAA;EAJG;;;EAAA,SAQH,SAAA;cAEG,MAAA,UAAgB,IAAA,UAAc,SAAA;AAAA;AAAA,UAyB1B,cAAA;EAChB,SAAA;IACC,SAAA;IACA,QAAA;MAAa,MAAA;IAAA;IACb,WAAA;MAAgB,YAAA;IAAA;EAAA;AAAA;;;;;;;;;;AAclB;iBAAgB,eAAA,CAAgB,KAAA,EAAO,cAAA,sBAAoC,gBAAA"}
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/predict/errors.ts"],"mappings":";;cAaa,iBAAA,SAA0B,KAAA;cAC1B,OAAA;AAAA;;cAOA,gBAAA,SAAyB,KAAA;EAAA,SAC5B,MAAA;EARG;;EAAA,SAWH,IAAA;EAJG;;;EAAA,SAQH,SAAA;cAEG,MAAA,UAAgB,IAAA,UAAc,SAAA;AAAA;AAAA,UAyB1B,cAAA;EAChB,SAAA;IACC,SAAA;IACA,QAAA;MAAa,MAAA;IAAA;IACb,WAAA;MAAgB,YAAA;IAAA;EAAA;AAAA;;;;;AAoOlB;;;;;AAgEA;;iBAjFgB,eAAA,CAAgB,KAAA,EAAO,cAAA,sBAAoC,gBAAA;;;;;;;KAiB/D,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgEC,qBAAA,SAA8B,KAAA;EAAA,SACjC,IAAA,EAAM,oBAAA;cAEH,IAAA,EAAM,oBAAA,EAAsB,OAAA;AAAA;;;;;;;iBAqGzB,oBAAA,CAAqB,CAAA,EAAG,gBAAA"}