@mysten/deepbook-v3 2.0.0 → 2.1.3

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 (302) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/PREDICT.md +256 -0
  3. package/README.md +116 -0
  4. package/dist/account.d.mts +139 -0
  5. package/dist/account.d.mts.map +1 -0
  6. package/dist/account.mjs +181 -0
  7. package/dist/account.mjs.map +1 -0
  8. package/dist/bcs/integers.mjs +23 -0
  9. package/dist/bcs/integers.mjs.map +1 -0
  10. package/dist/contracts/account/account.d.mts +382 -0
  11. package/dist/contracts/account/account.d.mts.map +1 -0
  12. package/dist/contracts/account/account.mjs +443 -0
  13. package/dist/contracts/account/account.mjs.map +1 -0
  14. package/dist/contracts/account/account_events.d.mts +41 -0
  15. package/dist/contracts/account/account_events.d.mts.map +1 -0
  16. package/dist/contracts/account/account_events.mjs +72 -0
  17. package/dist/contracts/account/account_events.mjs.map +1 -0
  18. package/dist/contracts/account/account_registry.d.mts +210 -0
  19. package/dist/contracts/account/account_registry.d.mts.map +1 -0
  20. package/dist/contracts/account/account_registry.mjs +263 -0
  21. package/dist/contracts/account/account_registry.mjs.map +1 -0
  22. package/dist/contracts/account/config-arguments.d.mts +10 -0
  23. package/dist/contracts/account/config-arguments.d.mts.map +1 -0
  24. package/dist/contracts/account/deps/sui/bag.mjs +44 -0
  25. package/dist/contracts/account/deps/sui/bag.mjs.map +1 -0
  26. package/dist/contracts/deepbook/account.d.mts +18 -18
  27. package/dist/contracts/deepbook/balance_manager.mjs.map +1 -1
  28. package/dist/contracts/deepbook/balances.d.mts +4 -4
  29. package/dist/contracts/deepbook/balances.d.mts.map +1 -1
  30. package/dist/contracts/deepbook/deep_price.d.mts +3 -3
  31. package/dist/contracts/deepbook/deep_price.d.mts.map +1 -1
  32. package/dist/contracts/deepbook/order.d.mts +12 -12
  33. package/dist/contracts/deepbook/pool.mjs.map +1 -1
  34. package/dist/contracts/deepbook/registry.mjs.map +1 -1
  35. package/dist/contracts/deepbook_margin/margin_manager.mjs.map +1 -1
  36. package/dist/contracts/deepbook_margin/margin_manager_upgraded.mjs.map +1 -1
  37. package/dist/contracts/deepbook_margin/margin_pool.mjs.map +1 -1
  38. package/dist/contracts/deepbook_margin/margin_registry.mjs.map +1 -1
  39. package/dist/contracts/deepbook_margin/pool_proxy.mjs.map +1 -1
  40. package/dist/contracts/deepbook_margin/protocol_config.mjs.map +1 -1
  41. package/dist/contracts/deepbook_margin/tpsl.mjs.map +1 -1
  42. package/dist/contracts/deepbook_predict/builder_code_events.mjs +38 -0
  43. package/dist/contracts/deepbook_predict/builder_code_events.mjs.map +1 -0
  44. package/dist/contracts/deepbook_predict/config-arguments.d.mts +13 -0
  45. package/dist/contracts/deepbook_predict/config-arguments.d.mts.map +1 -0
  46. package/dist/contracts/deepbook_predict/deps/fixed_math/i64.mjs +25 -0
  47. package/dist/contracts/deepbook_predict/deps/fixed_math/i64.mjs.map +1 -0
  48. package/dist/contracts/deepbook_predict/deps/sui/balance.mjs +25 -0
  49. package/dist/contracts/deepbook_predict/deps/sui/balance.mjs.map +1 -0
  50. package/dist/contracts/deepbook_predict/deps/sui/coin.mjs +24 -0
  51. package/dist/contracts/deepbook_predict/deps/sui/coin.mjs.map +1 -0
  52. package/dist/contracts/deepbook_predict/deps/sui/table.mjs +39 -0
  53. package/dist/contracts/deepbook_predict/deps/sui/table.mjs.map +1 -0
  54. package/dist/contracts/deepbook_predict/deps/sui/vec_set.mjs +26 -0
  55. package/dist/contracts/deepbook_predict/deps/sui/vec_set.mjs.map +1 -0
  56. package/dist/contracts/deepbook_predict/ewma.mjs +29 -0
  57. package/dist/contracts/deepbook_predict/ewma.mjs.map +1 -0
  58. package/dist/contracts/deepbook_predict/expiry_cash.mjs +27 -0
  59. package/dist/contracts/deepbook_predict/expiry_cash.mjs.map +1 -0
  60. package/dist/contracts/deepbook_predict/expiry_market.mjs +367 -0
  61. package/dist/contracts/deepbook_predict/expiry_market.mjs.map +1 -0
  62. package/dist/contracts/deepbook_predict/lp_book.mjs +92 -0
  63. package/dist/contracts/deepbook_predict/lp_book.mjs.map +1 -0
  64. package/dist/contracts/deepbook_predict/market_manager.mjs +59 -0
  65. package/dist/contracts/deepbook_predict/market_manager.mjs.map +1 -0
  66. package/dist/contracts/deepbook_predict/order.mjs +26 -0
  67. package/dist/contracts/deepbook_predict/order.mjs.map +1 -0
  68. package/dist/contracts/deepbook_predict/order_events.mjs +84 -0
  69. package/dist/contracts/deepbook_predict/order_events.mjs.map +1 -0
  70. package/dist/contracts/deepbook_predict/plp.mjs +284 -0
  71. package/dist/contracts/deepbook_predict/plp.mjs.map +1 -0
  72. package/dist/contracts/deepbook_predict/pool_accounting.mjs +58 -0
  73. package/dist/contracts/deepbook_predict/pool_accounting.mjs.map +1 -0
  74. package/dist/contracts/deepbook_predict/predict_account.mjs +106 -0
  75. package/dist/contracts/deepbook_predict/predict_account.mjs.map +1 -0
  76. package/dist/contracts/deepbook_predict/pricing.mjs +80 -0
  77. package/dist/contracts/deepbook_predict/pricing.mjs.map +1 -0
  78. package/dist/contracts/deepbook_predict/range_codec.mjs +41 -0
  79. package/dist/contracts/deepbook_predict/range_codec.mjs.map +1 -0
  80. package/dist/contracts/deepbook_predict/registry.mjs +55 -0
  81. package/dist/contracts/deepbook_predict/registry.mjs.map +1 -0
  82. package/dist/contracts/deepbook_predict/strike_exposure.mjs +65 -0
  83. package/dist/contracts/deepbook_predict/strike_exposure.mjs.map +1 -0
  84. package/dist/contracts/deepbook_predict/strike_exposure_config.mjs +33 -0
  85. package/dist/contracts/deepbook_predict/strike_exposure_config.mjs.map +1 -0
  86. package/dist/contracts/deepbook_predict/strike_payout_tree.mjs +72 -0
  87. package/dist/contracts/deepbook_predict/strike_payout_tree.mjs.map +1 -0
  88. package/dist/contracts/deepbook_predict/vault_events.mjs +184 -0
  89. package/dist/contracts/deepbook_predict/vault_events.mjs.map +1 -0
  90. package/dist/contracts/deepbook_sessions/config-arguments.d.mts +10 -0
  91. package/dist/contracts/deepbook_sessions/config-arguments.d.mts.map +1 -0
  92. package/dist/contracts/deepbook_sessions/deps/sui/vec_map.mjs +37 -0
  93. package/dist/contracts/deepbook_sessions/deps/sui/vec_map.mjs.map +1 -0
  94. package/dist/contracts/deepbook_sessions/session_config.d.mts +63 -0
  95. package/dist/contracts/deepbook_sessions/session_config.d.mts.map +1 -0
  96. package/dist/contracts/deepbook_sessions/session_config.mjs +82 -0
  97. package/dist/contracts/deepbook_sessions/session_config.mjs.map +1 -0
  98. package/dist/contracts/deepbook_sessions/sessions.d.mts +275 -0
  99. package/dist/contracts/deepbook_sessions/sessions.d.mts.map +1 -0
  100. package/dist/contracts/deepbook_sessions/sessions.mjs +443 -0
  101. package/dist/contracts/deepbook_sessions/sessions.mjs.map +1 -0
  102. package/dist/contracts/margin_liquidation/liquidation_vault.mjs.map +1 -1
  103. package/dist/contracts/utils/index.d.mts +18 -1
  104. package/dist/contracts/utils/index.d.mts.map +1 -1
  105. package/dist/deployments/index.d.mts +31 -0
  106. package/dist/deployments/index.d.mts.map +1 -0
  107. package/dist/deployments/index.mjs +30 -0
  108. package/dist/deployments/index.mjs.map +1 -0
  109. package/dist/deployments/testnet.d.mts +14 -0
  110. package/dist/deployments/testnet.d.mts.map +1 -0
  111. package/dist/deployments/testnet.mjs +73 -0
  112. package/dist/deployments/testnet.mjs.map +1 -0
  113. package/dist/deployments/types.d.mts +36 -0
  114. package/dist/deployments/types.d.mts.map +1 -0
  115. package/dist/index.mjs +0 -1
  116. package/dist/predict/client.d.mts +255 -0
  117. package/dist/predict/client.d.mts.map +1 -0
  118. package/dist/predict/client.mjs +436 -0
  119. package/dist/predict/client.mjs.map +1 -0
  120. package/dist/predict/config/generated.d.mts +29 -0
  121. package/dist/predict/config/generated.d.mts.map +1 -0
  122. package/dist/predict/config/generated.mjs +16 -0
  123. package/dist/predict/config/generated.mjs.map +1 -0
  124. package/dist/predict/config/index.d.mts +10 -0
  125. package/dist/predict/config/index.d.mts.map +1 -0
  126. package/dist/predict/config/index.mjs +13 -0
  127. package/dist/predict/config/index.mjs.map +1 -0
  128. package/dist/predict/config/testnet.d.mts +17 -0
  129. package/dist/predict/config/testnet.d.mts.map +1 -0
  130. package/dist/predict/config/testnet.mjs +26 -0
  131. package/dist/predict/config/testnet.mjs.map +1 -0
  132. package/dist/predict/config/types.d.mts +55 -0
  133. package/dist/predict/config/types.d.mts.map +1 -0
  134. package/dist/predict/decode.d.mts +162 -0
  135. package/dist/predict/decode.d.mts.map +1 -0
  136. package/dist/predict/decode.mjs +175 -0
  137. package/dist/predict/decode.mjs.map +1 -0
  138. package/dist/predict/errors.d.mts +42 -0
  139. package/dist/predict/errors.d.mts.map +1 -0
  140. package/dist/predict/errors.mjs +37 -0
  141. package/dist/predict/errors.mjs.map +1 -0
  142. package/dist/predict/index.d.mts +18 -0
  143. package/dist/predict/index.mjs +14 -0
  144. package/dist/predict/pricing.d.mts +73 -0
  145. package/dist/predict/pricing.d.mts.map +1 -0
  146. package/dist/predict/pricing.mjs +129 -0
  147. package/dist/predict/pricing.mjs.map +1 -0
  148. package/dist/predict/reads/balances.mjs +41 -0
  149. package/dist/predict/reads/balances.mjs.map +1 -0
  150. package/dist/predict/reads/inspect.d.mts +8 -0
  151. package/dist/predict/reads/inspect.d.mts.map +1 -0
  152. package/dist/predict/reads/inspect.mjs +37 -0
  153. package/dist/predict/reads/inspect.mjs.map +1 -0
  154. package/dist/predict/reads/markets.mjs +130 -0
  155. package/dist/predict/reads/markets.mjs.map +1 -0
  156. package/dist/predict/reads/parse.mjs +20 -0
  157. package/dist/predict/reads/parse.mjs.map +1 -0
  158. package/dist/predict/reads/pool.mjs +26 -0
  159. package/dist/predict/reads/pool.mjs.map +1 -0
  160. package/dist/predict/reads/positions.d.mts +12 -0
  161. package/dist/predict/reads/positions.d.mts.map +1 -0
  162. package/dist/predict/reads/positions.mjs +77 -0
  163. package/dist/predict/reads/positions.mjs.map +1 -0
  164. package/dist/predict/reads/pricing.d.mts +20 -0
  165. package/dist/predict/reads/pricing.d.mts.map +1 -0
  166. package/dist/predict/reads/pricing.mjs +43 -0
  167. package/dist/predict/reads/pricing.mjs.map +1 -0
  168. package/dist/predict/ticks.d.mts +11 -0
  169. package/dist/predict/ticks.d.mts.map +1 -0
  170. package/dist/predict/ticks.mjs +21 -0
  171. package/dist/predict/ticks.mjs.map +1 -0
  172. package/dist/predict/tx/authed.mjs +18 -0
  173. package/dist/predict/tx/authed.mjs.map +1 -0
  174. package/dist/predict/tx/common.d.mts +18 -0
  175. package/dist/predict/tx/common.d.mts.map +1 -0
  176. package/dist/predict/tx/common.mjs +52 -0
  177. package/dist/predict/tx/common.mjs.map +1 -0
  178. package/dist/predict/tx/trade.d.mts +15 -0
  179. package/dist/predict/tx/trade.d.mts.map +1 -0
  180. package/dist/predict/tx/trade.mjs +86 -0
  181. package/dist/predict/tx/trade.mjs.map +1 -0
  182. package/dist/predict/units.d.mts +11 -0
  183. package/dist/predict/units.d.mts.map +1 -0
  184. package/dist/predict/units.mjs +44 -0
  185. package/dist/predict/units.mjs.map +1 -0
  186. package/dist/queries/accountQueries.mjs +0 -1
  187. package/dist/queries/accountQueries.mjs.map +1 -1
  188. package/dist/queries/orderQueries.mjs +0 -1
  189. package/dist/queries/orderQueries.mjs.map +1 -1
  190. package/dist/queries/registryQueries.mjs +0 -1
  191. package/dist/queries/registryQueries.mjs.map +1 -1
  192. package/dist/sessions.d.mts +244 -0
  193. package/dist/sessions.d.mts.map +1 -0
  194. package/dist/sessions.mjs +291 -0
  195. package/dist/sessions.mjs.map +1 -0
  196. package/dist/transactions/balanceManager.d.mts +12 -12
  197. package/dist/transactions/deepbook.d.mts +20 -20
  198. package/dist/transactions/deepbookAdmin.d.mts +4 -4
  199. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  200. package/dist/transactions/marginAdmin.d.mts +7 -7
  201. package/dist/transactions/marginLiquidations.d.mts +3 -3
  202. package/dist/transactions/marginMaintainer.d.mts +5 -5
  203. package/dist/transactions/marginManager.d.mts +32 -32
  204. package/dist/transactions/marginPool.d.mts +18 -18
  205. package/dist/transactions/marginRegistry.d.mts +16 -16
  206. package/dist/transactions/marginTPSL.d.mts +10 -10
  207. package/dist/transactions/poolProxy.d.mts +8 -8
  208. package/dist/types/index.d.mts.map +1 -1
  209. package/dist/types/index.mjs.map +1 -1
  210. package/dist/utils/constants.d.mts.map +1 -1
  211. package/dist/utils/constants.mjs +1 -1
  212. package/dist/utils/constants.mjs.map +1 -1
  213. package/package.json +33 -12
  214. package/src/account.ts +239 -0
  215. package/src/bcs/integers.ts +35 -0
  216. package/src/contracts/account/account.ts +706 -0
  217. package/src/contracts/account/account_events.ts +64 -0
  218. package/src/contracts/account/account_registry.ts +468 -0
  219. package/src/contracts/account/config-arguments.ts +8 -0
  220. package/src/contracts/account/deps/sui/bag.ts +42 -0
  221. package/src/contracts/deepbook/balance_manager.ts +1 -2
  222. package/src/contracts/deepbook/pool.ts +12 -24
  223. package/src/contracts/deepbook/registry.ts +1 -2
  224. package/src/contracts/deepbook_margin/margin_manager.ts +9 -18
  225. package/src/contracts/deepbook_margin/margin_manager_upgraded.ts +5 -10
  226. package/src/contracts/deepbook_margin/margin_pool.ts +2 -4
  227. package/src/contracts/deepbook_margin/margin_registry.ts +3 -6
  228. package/src/contracts/deepbook_margin/pool_proxy.ts +3 -6
  229. package/src/contracts/deepbook_margin/protocol_config.ts +1 -2
  230. package/src/contracts/deepbook_margin/tpsl.ts +1 -2
  231. package/src/contracts/deepbook_predict/admin.ts +44 -0
  232. package/src/contracts/deepbook_predict/builder_code.ts +155 -0
  233. package/src/contracts/deepbook_predict/builder_code_events.ts +34 -0
  234. package/src/contracts/deepbook_predict/config-arguments.ts +11 -0
  235. package/src/contracts/deepbook_predict/config_events.ts +140 -0
  236. package/src/contracts/deepbook_predict/deps/fixed_math/i64.ts +21 -0
  237. package/src/contracts/deepbook_predict/deps/sui/balance.ts +25 -0
  238. package/src/contracts/deepbook_predict/deps/sui/coin.ts +20 -0
  239. package/src/contracts/deepbook_predict/deps/sui/table.ts +37 -0
  240. package/src/contracts/deepbook_predict/deps/sui/vec_set.ts +22 -0
  241. package/src/contracts/deepbook_predict/ewma.ts +26 -0
  242. package/src/contracts/deepbook_predict/ewma_config.ts +28 -0
  243. package/src/contracts/deepbook_predict/expiry_cash.ts +24 -0
  244. package/src/contracts/deepbook_predict/expiry_market.ts +1549 -0
  245. package/src/contracts/deepbook_predict/lp_book.ts +105 -0
  246. package/src/contracts/deepbook_predict/market_lifecycle_cap.ts +75 -0
  247. package/src/contracts/deepbook_predict/market_manager.ts +218 -0
  248. package/src/contracts/deepbook_predict/order.ts +24 -0
  249. package/src/contracts/deepbook_predict/order_events.ts +129 -0
  250. package/src/contracts/deepbook_predict/pause_cap.ts +68 -0
  251. package/src/contracts/deepbook_predict/plp.ts +987 -0
  252. package/src/contracts/deepbook_predict/pool_accounting.ts +79 -0
  253. package/src/contracts/deepbook_predict/predict_account.ts +180 -0
  254. package/src/contracts/deepbook_predict/pricing.ts +124 -0
  255. package/src/contracts/deepbook_predict/pricing_config.ts +41 -0
  256. package/src/contracts/deepbook_predict/protocol_config.ts +1066 -0
  257. package/src/contracts/deepbook_predict/range_codec.ts +53 -0
  258. package/src/contracts/deepbook_predict/registry.ts +694 -0
  259. package/src/contracts/deepbook_predict/strike_exposure.ts +77 -0
  260. package/src/contracts/deepbook_predict/strike_exposure_config.ts +46 -0
  261. package/src/contracts/deepbook_predict/strike_payout_tree.ts +89 -0
  262. package/src/contracts/deepbook_predict/vault_events.ts +222 -0
  263. package/src/contracts/deepbook_sessions/config-arguments.ts +8 -0
  264. package/src/contracts/deepbook_sessions/deps/sui/vec_map.ts +33 -0
  265. package/src/contracts/deepbook_sessions/session_config.ts +130 -0
  266. package/src/contracts/deepbook_sessions/sessions.ts +663 -0
  267. package/src/contracts/margin_liquidation/liquidation_vault.ts +2 -4
  268. package/src/contracts/propbook/block_scholes_store.ts +842 -0
  269. package/src/contracts/propbook/deps/sui/table.ts +37 -0
  270. package/src/contracts/propbook/oracle_lane.ts +170 -0
  271. package/src/contracts/propbook/pyth_feed.ts +414 -0
  272. package/src/contracts/propbook/registry.ts +596 -0
  273. package/src/contracts/pyth/pyth.ts +2 -4
  274. package/src/deployments/index.ts +73 -0
  275. package/src/deployments/testnet.ts +107 -0
  276. package/src/deployments/types.ts +81 -0
  277. package/src/index.ts +5 -0
  278. package/src/predict/client.ts +941 -0
  279. package/src/predict/config/generated.ts +39 -0
  280. package/src/predict/config/index.ts +25 -0
  281. package/src/predict/config/testnet.ts +27 -0
  282. package/src/predict/config/types.ts +52 -0
  283. package/src/predict/decode.ts +476 -0
  284. package/src/predict/errors.ts +83 -0
  285. package/src/predict/index.ts +94 -0
  286. package/src/predict/pricing.ts +199 -0
  287. package/src/predict/reads/balances.ts +55 -0
  288. package/src/predict/reads/inspect.ts +78 -0
  289. package/src/predict/reads/markets.ts +222 -0
  290. package/src/predict/reads/parse.ts +30 -0
  291. package/src/predict/reads/pool.ts +37 -0
  292. package/src/predict/reads/positions.ts +144 -0
  293. package/src/predict/reads/pricing.ts +79 -0
  294. package/src/predict/ticks.ts +42 -0
  295. package/src/predict/tx/authed.ts +20 -0
  296. package/src/predict/tx/common.ts +92 -0
  297. package/src/predict/tx/trade.ts +183 -0
  298. package/src/predict/units.ts +49 -0
  299. package/src/sessions.ts +471 -0
  300. package/src/types/index.ts +1 -2
  301. package/src/utils/constants.ts +1 -7
  302. package/dist/types/bcs.mjs +0 -7
@@ -0,0 +1,17 @@
1
+ import { PredictConfig } from "./types.mjs";
2
+
3
+ //#region src/predict/config/testnet.d.ts
4
+ /**
5
+ * Testnet deployment constants, read from the shared generated record in
6
+ * `src/deployments/` rather than transcribed here. `/account` and `/sessions` read slices of
7
+ * that same record, so a redeploy (`pnpm sync-deployment`) moves every subpath together and
8
+ * they cannot end up addressing different deployments.
9
+ *
10
+ * The record is generated from the deploy tooling's `deployment.testnet.json`; see
11
+ * `scripts/sync-deployment.ts`. `getDeployment('testnet')` names the deployment and the
12
+ * deepbookv3 commit these ids came from.
13
+ */
14
+ declare const TESTNET_CONFIG: PredictConfig;
15
+ //#endregion
16
+ export { TESTNET_CONFIG };
17
+ //# sourceMappingURL=testnet.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testnet.d.mts","names":[],"sources":["../../../src/predict/config/testnet.ts"],"mappings":";;;;;AAgBA;;;;;;;;cAAa,cAAA,EAAgB,aAAA"}
@@ -0,0 +1,26 @@
1
+ import { TESTNET_PREDICT } from "../../deployments/testnet.mjs";
2
+
3
+ //#region src/predict/config/testnet.ts
4
+ /**
5
+ * Testnet deployment constants, read from the shared generated record in
6
+ * `src/deployments/` rather than transcribed here. `/account` and `/sessions` read slices of
7
+ * that same record, so a redeploy (`pnpm sync-deployment`) moves every subpath together and
8
+ * they cannot end up addressing different deployments.
9
+ *
10
+ * The record is generated from the deploy tooling's `deployment.testnet.json`; see
11
+ * `scripts/sync-deployment.ts`. `getDeployment('testnet')` names the deployment and the
12
+ * deepbookv3 commit these ids came from.
13
+ */
14
+ const TESTNET_CONFIG = Object.freeze({
15
+ network: "testnet",
16
+ packages: TESTNET_PREDICT.packages,
17
+ objects: TESTNET_PREDICT.objects,
18
+ quoteCoinType: TESTNET_PREDICT.quoteCoinType,
19
+ coinTypes: TESTNET_PREDICT.coinTypes,
20
+ units: TESTNET_PREDICT.units,
21
+ underlyings: TESTNET_PREDICT.underlyings
22
+ });
23
+
24
+ //#endregion
25
+ export { TESTNET_CONFIG };
26
+ //# sourceMappingURL=testnet.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testnet.mjs","names":[],"sources":["../../../src/predict/config/testnet.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { TESTNET_PREDICT } from '../../deployments/testnet.js';\nimport type { PredictConfig } from './types.js';\n\n/**\n * Testnet deployment constants, read from the shared generated record in\n * `src/deployments/` rather than transcribed here. `/account` and `/sessions` read slices of\n * that same record, so a redeploy (`pnpm sync-deployment`) moves every subpath together and\n * they cannot end up addressing different deployments.\n *\n * The record is generated from the deploy tooling's `deployment.testnet.json`; see\n * `scripts/sync-deployment.ts`. `getDeployment('testnet')` names the deployment and the\n * deepbookv3 commit these ids came from.\n */\nexport const TESTNET_CONFIG: PredictConfig = Object.freeze({\n\t// The record widens `network` to `string` so the published types don't pin a literal;\n\t// this file is the testnet config by construction.\n\tnetwork: 'testnet',\n\tpackages: TESTNET_PREDICT.packages,\n\tobjects: TESTNET_PREDICT.objects,\n\tquoteCoinType: TESTNET_PREDICT.quoteCoinType,\n\tcoinTypes: TESTNET_PREDICT.coinTypes,\n\tunits: TESTNET_PREDICT.units,\n\tunderlyings: TESTNET_PREDICT.underlyings,\n});\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAa,iBAAgC,OAAO,OAAO;CAG1D,SAAS;CACT,UAAU,gBAAgB;CAC1B,SAAS,gBAAgB;CACzB,eAAe,gBAAgB;CAC/B,WAAW,gBAAgB;CAC3B,OAAO,gBAAgB;CACvB,aAAa,gBAAgB;CAC7B,CAAC"}
@@ -0,0 +1,55 @@
1
+ //#region src/predict/config/types.d.ts
2
+ /** The three published Move packages a Predict deployment spans. */
3
+ interface PredictPackages {
4
+ predict: string;
5
+ account: string;
6
+ propbook: string;
7
+ }
8
+ /**
9
+ * Per-underlying oracle wiring: the propbook underlying id plus the feed object ids the
10
+ * live pricer reads. Names mirror the deployment manifest
11
+ * (`packages/predict/deployment/deployment.testnet.json` → `underlyings`).
12
+ */
13
+ interface UnderlyingConfig {
14
+ symbol: string;
15
+ propbookUnderlyingId: number;
16
+ /** `&PythFeed` — spot price feed. */
17
+ pythFeed: string;
18
+ /** `&BlockScholesValueStore` — Black-Scholes value store. */
19
+ blockScholesValueStore: string;
20
+ /** `&BlockScholesSVIStore` — SVI-surface store. */
21
+ blockScholesSviStore: string;
22
+ }
23
+ /** Everything a tx builder or read needs to address a Predict deployment on one network. */
24
+ interface PredictConfig {
25
+ network: 'testnet' | 'mainnet' | 'custom';
26
+ packages: PredictPackages;
27
+ objects: {
28
+ registry: string;
29
+ protocolConfig: string;
30
+ poolVault: string;
31
+ oracleRegistry: string;
32
+ accountRegistry: string;
33
+ };
34
+ quoteCoinType: string;
35
+ /**
36
+ * Coin types the deployment owns. `plp` is NOT derivable from `packages.predict`: a Move
37
+ * type tag keeps the ORIGINAL package id across an upgrade, while `packages.predict`
38
+ * moves to the latest.
39
+ */
40
+ coinTypes: {
41
+ plp: string;
42
+ deep: string;
43
+ };
44
+ /** Scale constants the deploy owns rather than the SDK. */
45
+ units: {
46
+ positionLotSize: number;
47
+ fixedPointScale: number;
48
+ quoteCoinDecimals: number;
49
+ positionQuantityDecimals: number;
50
+ };
51
+ underlyings: Record<string, UnderlyingConfig>;
52
+ }
53
+ //#endregion
54
+ export { PredictConfig, PredictPackages, UnderlyingConfig };
55
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../../src/predict/config/types.ts"],"mappings":";;UAGiB,eAAA;EAChB,OAAA;EACA,OAAA;EACA,QAAA;AAAA;;;;;AAQD;UAAiB,gBAAA;EAChB,MAAA;EACA,oBAAA;EADA;EAGA,QAAA;EAAA;EAEA,sBAAA;EAEA;EAAA,oBAAA;AAAA;AAID;AAAA,UAAiB,aAAA;EAChB,OAAA;EACA,QAAA,EAAU,eAAA;EACV,OAAA;IACC,QAAA;IACA,cAAA;IACA,SAAA;IACA,cAAA;IACA,eAAA;EAAA;EAED,aAAA;EANC;;;;;EAYD,SAAA;IAAa,GAAA;IAAa,IAAA;EAAA;EAE1B;EAAA,KAAA;IACC,eAAA;IACA,eAAA;IACA,iBAAA;IACA,wBAAA;EAAA;EAED,WAAA,EAAa,MAAA,SAAe,gBAAA;AAAA"}
@@ -0,0 +1,162 @@
1
+ //#region src/predict/decode.d.ts
2
+ /** The slice of an executed/simulated transaction result the decoders need. */
3
+ interface DecodableEvent {
4
+ /** Full type tag `0xpkg::module::Name` (gRPC `eventType`, legacy `type`). */
5
+ eventType?: string;
6
+ type?: string;
7
+ packageId?: string;
8
+ module?: string;
9
+ /** Struct name, when the transport supplies it separately from a full type tag. */
10
+ name?: string;
11
+ /** Canonical BCS payload; some transports deliver it base64-encoded. */
12
+ bcs?: Uint8Array | string;
13
+ }
14
+ interface DecodableTransactionResult {
15
+ events?: readonly DecodableEvent[] | null;
16
+ }
17
+ interface MintReceipt {
18
+ marketId: string;
19
+ accountId: string;
20
+ owner: string;
21
+ /** Persist this: required to redeem/claim the position later. */
22
+ orderId: bigint;
23
+ /** Stable across partial-close replacements; equals orderId at mint. */
24
+ positionRootId: bigint;
25
+ lowerTick: bigint;
26
+ higherTick: bigint;
27
+ /** 0..1 range probability quoted at entry (your fill price per $1 payout). */
28
+ entryProbability: number;
29
+ /** Max payout actually minted, in quote units (mintAmount: chain-floored). */
30
+ quantity: number;
31
+ /** Premium paid into LP backing, in quote units. */
32
+ premium: number;
33
+ /**
34
+ * Fee breakdown. `referral` is the slice of the trader-paid trading fee and
35
+ * congestion surcharge delivered to the referrer; `inventoryImpact` is the
36
+ * path-independent inventory-impact charge assessed on the mint.
37
+ */
38
+ fees: {
39
+ trading: number;
40
+ subsidy: number;
41
+ builder: number;
42
+ penalty: number;
43
+ referral: number;
44
+ inventoryImpact: number;
45
+ };
46
+ builderCodeId: string | null;
47
+ raw: {
48
+ quantity: bigint;
49
+ premium: bigint;
50
+ tradingFee: bigint;
51
+ feeIncentiveSubsidy: bigint;
52
+ builderFee: bigint;
53
+ penaltyFee: bigint;
54
+ referralFee: bigint;
55
+ inventoryImpactCharge: bigint;
56
+ entryProbability: bigint;
57
+ };
58
+ }
59
+ interface RedeemReceipt {
60
+ marketId: string;
61
+ accountId: string;
62
+ owner: string;
63
+ orderId: bigint;
64
+ positionRootId: bigint;
65
+ quantityClosed: number;
66
+ remaining: number;
67
+ /**
68
+ * A partial close RETIRES the old order id and issues this replacement for
69
+ * the remaining quantity — update your stored id or it goes silently stale.
70
+ */
71
+ replacementOrderId: bigint | null;
72
+ /** NET quote credited to the account: gross + inventoryImpactRebate − trading −
73
+ * builder − penalty — the same expression the chain asserts `min_proceeds`
74
+ * against, and what `settle_live_redeem_payment` actually deposits. */
75
+ proceeds: number;
76
+ /** Gross close value before fees (the event's redeem_amount). */
77
+ gross: number;
78
+ /**
79
+ * Fee breakdown. `inventoryImpactRebate` is the path-independent
80
+ * inventory-impact rebate credited back on the close.
81
+ */
82
+ fees: {
83
+ trading: number;
84
+ builder: number;
85
+ penalty: number;
86
+ inventoryImpactRebate: number;
87
+ };
88
+ builderCodeId: string | null;
89
+ raw: {
90
+ quantityClosed: bigint;
91
+ remaining: bigint;
92
+ proceeds: bigint;
93
+ gross: bigint;
94
+ tradingFee: bigint;
95
+ builderFee: bigint;
96
+ penaltyFee: bigint;
97
+ inventoryImpactRebate: bigint;
98
+ };
99
+ }
100
+ interface ClaimReceipt {
101
+ marketId: string;
102
+ accountId: string;
103
+ owner: string;
104
+ orderId: bigint;
105
+ positionRootId: bigint;
106
+ /** Quote units paid out. A settled claim closes the order in full. */
107
+ payout: number;
108
+ raw: {
109
+ payout: bigint;
110
+ };
111
+ }
112
+ interface CreateManagerReceipt {
113
+ accountId: string;
114
+ wrapperId: string;
115
+ owner: string;
116
+ selfOwned: boolean;
117
+ }
118
+ interface BalanceChangeReceipt {
119
+ accountId: string;
120
+ coinType: string;
121
+ /** Display value assuming a 6-decimal coin (quote + PLP both are). */
122
+ amount: number;
123
+ newBalance: number;
124
+ raw: {
125
+ amount: bigint;
126
+ newBalance: bigint;
127
+ };
128
+ }
129
+ interface PlpRequestReceipt {
130
+ kind: 'supply' | 'withdraw';
131
+ vaultId: string;
132
+ accountId: string;
133
+ recipient: string;
134
+ /** Feed straight into cancelSupplyPlp / cancelWithdrawPlp. */
135
+ index: bigint;
136
+ /** Quote units for supply; PLP shares (6-dec) for withdraw. */
137
+ amount: number;
138
+ raw: {
139
+ amount: bigint;
140
+ };
141
+ }
142
+ interface PlpCancelReceipt {
143
+ vaultId: string;
144
+ accountId: string;
145
+ recipient: string;
146
+ index: bigint;
147
+ isSupply: boolean;
148
+ /** Refund returned to the account (quote for supply, PLP for withdraw). */
149
+ amount: number;
150
+ raw: {
151
+ amount: bigint;
152
+ };
153
+ }
154
+ interface BuilderCodeReceipt {
155
+ accountId: string;
156
+ owner: string;
157
+ /** Null after unsetBuilderCode. */
158
+ builderCodeId: string | null;
159
+ }
160
+ //#endregion
161
+ export { BalanceChangeReceipt, BuilderCodeReceipt, ClaimReceipt, CreateManagerReceipt, DecodableEvent, DecodableTransactionResult, MintReceipt, PlpCancelReceipt, PlpRequestReceipt, RedeemReceipt };
162
+ //# sourceMappingURL=decode.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.mts","names":[],"sources":["../../src/predict/decode.ts"],"mappings":";AA2BA;AAAA,UAAiB,cAAA;;EAEhB,SAAA;EACA,IAAA;EACA,SAAA;EACA,MAAA;EAAA;EAEA,IAAA;EAEA;EAAA,GAAA,GAAM,UAAA;AAAA;AAAA,UAGU,0BAAA;EAChB,MAAA,YAAkB,cAAA;AAAA;AAAA,UAkEF,WAAA;EAChB,QAAA;EACA,SAAA;EACA,KAAA;;EAEA,OAAA;EAJA;EAMA,cAAA;EACA,SAAA;EACA,UAAA;EAFA;EAIA,gBAAA;EAFA;EAIA,QAAA;EAAA;EAEA,OAAA;EAMA;;;;;EAAA,IAAA;IACC,OAAA;IACA,OAAA;IACA,OAAA;IACA,OAAA;IACA,QAAA;IACA,eAAA;EAAA;EAED,aAAA;EACA,GAAA;IACC,QAAA;IACA,OAAA;IACA,UAAA;IACA,mBAAA;IACA,UAAA;IACA,UAAA;IACA,WAAA;IACA,qBAAA;IACA,gBAAA;EAAA;AAAA;AAAA,UAIe,aAAA;EAChB,QAAA;EACA,SAAA;EACA,KAAA;EACA,OAAA;EACA,cAAA;EACA,cAAA;EACA,SAAA;EAgBA;;;;EAXA,kBAAA;EAYA;;;EARA,QAAA;EAYC;EAVD,KAAA;EAYC;;;;EAPD,IAAA;IAAQ,OAAA;IAAiB,OAAA;IAAiB,OAAA;IAAiB,qBAAA;EAAA;EAC3D,aAAA;EACA,GAAA;IACC,cAAA;IACA,SAAA;IACA,QAAA;IACA,KAAA;IACA,UAAA;IACA,UAAA;IACA,UAAA;IACA,qBAAA;EAAA;AAAA;AAAA,UAIe,YAAA;EAChB,QAAA;EACA,SAAA;EACA,KAAA;EACA,OAAA;EACA,cAAA;EAUS;EART,MAAA;EACA,GAAA;IAAO,MAAA;EAAA;AAAA;AAAA,UAGS,oBAAA;EAChB,SAAA;EACA,SAAA;EACA,KAAA;EACA,SAAA;AAAA;AAAA,UAGgB,oBAAA;EAChB,SAAA;EACA,QAAA;EAOgB;EALhB,MAAA;EACA,UAAA;EACA,GAAA;IAAO,MAAA;IAAgB,UAAA;EAAA;AAAA;AAAA,UAGP,iBAAA;EAChB,IAAA;EACA,OAAA;EACA,SAAA;EACA,SAAA;EAKa;EAHb,KAAA;EAMgC;EAJhC,MAAA;EACA,GAAA;IAAO,MAAA;EAAA;AAAA;AAAA,UAGS,gBAAA;EAChB,OAAA;EACA,SAAA;EACA,SAAA;EACA,KAAA;EACA,QAAA;EAGa;EADb,MAAA;EACA,GAAA;IAAO,MAAA;EAAA;AAAA;AAAA,UAGS,kBAAA;EAChB,SAAA;EACA,KAAA;EAEa;EAAb,aAAA;AAAA"}
@@ -0,0 +1,175 @@
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
+ import { PredictInputError } from "./errors.mjs";
6
+ import { fromRaw } from "./units.mjs";
7
+ import { fromBase64, normalizeSuiAddress } from "@mysten/sui/utils";
8
+
9
+ //#region src/predict/decode.ts
10
+ function eventBytes(e) {
11
+ if (e.bcs instanceof Uint8Array) return e.bcs;
12
+ if (typeof e.bcs === "string") return fromBase64(e.bcs);
13
+ return null;
14
+ }
15
+ function matches(e, pkg, module, name) {
16
+ const tag = e.eventType ?? e.type;
17
+ if (tag) {
18
+ const parts = tag.split("::");
19
+ if (parts.length !== 3) return false;
20
+ return normalizeSuiAddress(parts[0]) === normalizeSuiAddress(pkg) && parts[1] === module && parts[2] === name;
21
+ }
22
+ if (e.module !== module || e.packageId == null) return false;
23
+ if (normalizeSuiAddress(e.packageId) !== normalizeSuiAddress(pkg)) return false;
24
+ return e.name == null || e.name === name;
25
+ }
26
+ function decodeAll(result, pkg, module, name, layout) {
27
+ const out = [];
28
+ for (const e of result.events ?? []) {
29
+ if (!matches(e, pkg, module, name)) continue;
30
+ const bytes = eventBytes(e);
31
+ if (!bytes) throw new PredictInputError(`${module}::${name} event has no BCS payload — execute/simulate with events included`);
32
+ out.push(layout.parse(bytes));
33
+ }
34
+ return out;
35
+ }
36
+ function exactlyOne(items, what) {
37
+ if (items.length !== 1) throw new PredictInputError(`expected exactly one ${what} event, found ${items.length}`);
38
+ return items[0];
39
+ }
40
+ const optId = (v) => v == null ? null : normalizeSuiAddress(v);
41
+ function decodeMints(cfg, result) {
42
+ return decodeAll(result, cfg.packages.predict, "order_events", "OrderMinted", OrderMinted).map((e) => ({
43
+ marketId: normalizeSuiAddress(e.expiry_market_id),
44
+ accountId: normalizeSuiAddress(e.account_id),
45
+ owner: normalizeSuiAddress(e.owner),
46
+ orderId: e.order_id,
47
+ positionRootId: e.position_root_id,
48
+ lowerTick: e.lower_tick,
49
+ higherTick: e.higher_tick,
50
+ entryProbability: fromRaw(e.entry_probability, 9),
51
+ quantity: fromRaw(e.quantity, 6),
52
+ premium: fromRaw(e.premium, 6),
53
+ fees: {
54
+ trading: fromRaw(e.trading_fee, 6),
55
+ subsidy: fromRaw(e.fee_incentive_subsidy, 6),
56
+ builder: fromRaw(e.builder_fee, 6),
57
+ penalty: fromRaw(e.penalty_fee, 6),
58
+ referral: fromRaw(e.referral_fee, 6),
59
+ inventoryImpact: fromRaw(e.inventory_impact_charge, 6)
60
+ },
61
+ builderCodeId: optId(e.builder_code_id),
62
+ raw: {
63
+ quantity: e.quantity,
64
+ premium: e.premium,
65
+ tradingFee: e.trading_fee,
66
+ feeIncentiveSubsidy: e.fee_incentive_subsidy,
67
+ builderFee: e.builder_fee,
68
+ penaltyFee: e.penalty_fee,
69
+ referralFee: e.referral_fee,
70
+ inventoryImpactCharge: e.inventory_impact_charge,
71
+ entryProbability: e.entry_probability
72
+ }
73
+ }));
74
+ }
75
+ function decodeRedeems(cfg, result) {
76
+ const pkg = cfg.packages.predict;
77
+ return decodeAll(result, pkg, "order_events", "LiveOrderRedeemed", LiveOrderRedeemed).map((e) => ({
78
+ marketId: normalizeSuiAddress(e.expiry_market_id),
79
+ accountId: normalizeSuiAddress(e.account_id),
80
+ owner: normalizeSuiAddress(e.owner),
81
+ orderId: e.order_id,
82
+ positionRootId: e.position_root_id,
83
+ quantityClosed: fromRaw(e.quantity_closed, 6),
84
+ remaining: fromRaw(e.remaining_quantity, 6),
85
+ replacementOrderId: e.replacement_order_id,
86
+ proceeds: fromRaw(e.redeem_amount + e.inventory_impact_rebate - e.trading_fee - e.builder_fee - e.penalty_fee, 6),
87
+ gross: fromRaw(e.redeem_amount, 6),
88
+ fees: {
89
+ trading: fromRaw(e.trading_fee, 6),
90
+ builder: fromRaw(e.builder_fee, 6),
91
+ penalty: fromRaw(e.penalty_fee, 6),
92
+ inventoryImpactRebate: fromRaw(e.inventory_impact_rebate, 6)
93
+ },
94
+ builderCodeId: optId(e.builder_code_id),
95
+ raw: {
96
+ quantityClosed: e.quantity_closed,
97
+ remaining: e.remaining_quantity,
98
+ proceeds: e.redeem_amount + e.inventory_impact_rebate - e.trading_fee - e.builder_fee - e.penalty_fee,
99
+ gross: e.redeem_amount,
100
+ tradingFee: e.trading_fee,
101
+ builderFee: e.builder_fee,
102
+ penaltyFee: e.penalty_fee,
103
+ inventoryImpactRebate: e.inventory_impact_rebate
104
+ }
105
+ }));
106
+ }
107
+ function decodeClaims(cfg, result) {
108
+ return decodeAll(result, cfg.packages.predict, "order_events", "SettledOrderRedeemed", SettledOrderRedeemed).map((e) => ({
109
+ marketId: normalizeSuiAddress(e.expiry_market_id),
110
+ accountId: normalizeSuiAddress(e.account_id),
111
+ owner: normalizeSuiAddress(e.owner),
112
+ orderId: e.order_id,
113
+ positionRootId: e.position_root_id,
114
+ payout: fromRaw(e.payout_amount, 6),
115
+ raw: { payout: e.payout_amount }
116
+ }));
117
+ }
118
+ function decodeAccountsCreated(cfg, result) {
119
+ return decodeAll(result, cfg.packages.account, "account_events", "AccountCreated", AccountCreated).map((e) => ({
120
+ accountId: normalizeSuiAddress(e.account_id),
121
+ wrapperId: normalizeSuiAddress(e.wrapper_id),
122
+ owner: normalizeSuiAddress(e.owner),
123
+ selfOwned: e.self_owned
124
+ }));
125
+ }
126
+ function decodeBalanceChanges(cfg, result, name) {
127
+ const layout = name === "Deposited" ? Deposited : Withdrawn;
128
+ return decodeAll(result, cfg.packages.account, "account_events", name, layout).map((e) => ({
129
+ accountId: normalizeSuiAddress(e.account_id),
130
+ coinType: e.coin_type,
131
+ amount: fromRaw(e.amount, 6),
132
+ newBalance: fromRaw(e.new_balance, 6),
133
+ raw: {
134
+ amount: e.amount,
135
+ newBalance: e.new_balance
136
+ }
137
+ }));
138
+ }
139
+ const decodeDeposits = (cfg, result) => decodeBalanceChanges(cfg, result, "Deposited");
140
+ const decodeWithdrawals = (cfg, result) => decodeBalanceChanges(cfg, result, "Withdrawn");
141
+ function decodePlpRequests(cfg, result) {
142
+ const pkg = cfg.packages.predict;
143
+ const make = (kind) => (e) => ({
144
+ kind,
145
+ vaultId: normalizeSuiAddress(e.pool_vault_id),
146
+ accountId: normalizeSuiAddress(e.account_id),
147
+ recipient: normalizeSuiAddress(e.recipient),
148
+ index: e.index,
149
+ amount: fromRaw(e.amount, 6),
150
+ raw: { amount: e.amount }
151
+ });
152
+ return [...decodeAll(result, pkg, "vault_events", "SupplyRequested", SupplyRequested).map(make("supply")), ...decodeAll(result, pkg, "vault_events", "WithdrawRequested", WithdrawRequested).map(make("withdraw"))];
153
+ }
154
+ function decodePlpCancels(cfg, result) {
155
+ return decodeAll(result, cfg.packages.predict, "vault_events", "RequestCancelled", RequestCancelled).map((e) => ({
156
+ vaultId: normalizeSuiAddress(e.pool_vault_id),
157
+ accountId: normalizeSuiAddress(e.account_id),
158
+ recipient: normalizeSuiAddress(e.recipient),
159
+ index: e.index,
160
+ isSupply: e.is_supply,
161
+ amount: fromRaw(e.amount, 6),
162
+ raw: { amount: e.amount }
163
+ }));
164
+ }
165
+ function decodeBuilderCodeSets(cfg, result) {
166
+ return decodeAll(result, cfg.packages.predict, "builder_code_events", "BuilderCodeSet", BuilderCodeSet).map((e) => ({
167
+ accountId: normalizeSuiAddress(e.account_id),
168
+ owner: normalizeSuiAddress(e.owner),
169
+ builderCodeId: optId(e.builder_code_id)
170
+ }));
171
+ }
172
+
173
+ //#endregion
174
+ export { decodeAccountsCreated, decodeBuilderCodeSets, decodeClaims, decodeDeposits, decodeMints, decodePlpCancels, decodePlpRequests, decodeRedeems, decodeWithdrawals, exactlyOne };
175
+ //# sourceMappingURL=decode.mjs.map
@@ -0,0 +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// ORIGINAL package id; for the current v1 deployments that equals the config\n// package id.\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.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.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.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.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.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.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":"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"}
@@ -0,0 +1,42 @@
1
+ //#region src/predict/errors.d.ts
2
+ /** A caller-supplied argument the SDK rejected before building/sending a tx. */
3
+ declare class PredictInputError extends Error {
4
+ constructor(message: string);
5
+ }
6
+ /** A Move `abort` decoded from a simulate/read failure. */
7
+ declare class PredictMoveError extends Error {
8
+ readonly module: string;
9
+ /** Exact u64 abort code — bigint because clever-error encodings pack data
10
+ * into the high bits, which Number would silently truncate. */
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). */
15
+ readonly abortName: string | null;
16
+ constructor(module: string, code: bigint, abortName: string | null);
17
+ }
18
+ interface MoveAbortError {
19
+ MoveAbort?: {
20
+ abortCode?: string | number | bigint;
21
+ location?: {
22
+ module?: string;
23
+ };
24
+ cleverError?: {
25
+ constantName?: string;
26
+ };
27
+ };
28
+ }
29
+ /**
30
+ * Decode a `@mysten/sui` MoveAbort execution error into a {@link PredictMoveError}.
31
+ * Returns null when `error` carries no MoveAbort (InsufficientGas, a size error, any
32
+ * non-abort failure), so callers can fall back to a plain Error.
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.
36
+ * `code` stays a bigint — a clever-error abort code packs the module, line, and
37
+ * constant index into the high bits of the u64 and would lose precision as a Number.
38
+ */
39
+ declare function decodeMoveAbort(error: MoveAbortError | null | undefined): PredictMoveError | null;
40
+ //#endregion
41
+ export { MoveAbortError, PredictInputError, PredictMoveError, decodeMoveAbort };
42
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +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"}
@@ -0,0 +1,37 @@
1
+ //#region src/predict/errors.ts
2
+ /** A caller-supplied argument the SDK rejected before building/sending a tx. */
3
+ var PredictInputError = class extends Error {
4
+ constructor(message) {
5
+ super(message);
6
+ this.name = "PredictInputError";
7
+ }
8
+ };
9
+ /** A Move `abort` decoded from a simulate/read failure. */
10
+ var PredictMoveError = class extends Error {
11
+ constructor(module, code, abortName) {
12
+ super(abortName ? `Move abort in ${module}: ${abortName} (code ${code})` : `Move abort in ${module}: code ${code}`);
13
+ this.name = "PredictMoveError";
14
+ this.module = module;
15
+ this.code = code;
16
+ this.abortName = abortName;
17
+ }
18
+ };
19
+ /**
20
+ * Decode a `@mysten/sui` MoveAbort execution error into a {@link PredictMoveError}.
21
+ * Returns null when `error` carries no MoveAbort (InsufficientGas, a size error, any
22
+ * non-abort failure), so callers can fall back to a plain Error.
23
+ *
24
+ * `abortName` is taken straight from the chain-decoded clever-error constant; it is
25
+ * null when the abort predates clever errors or the transport didn't surface a name.
26
+ * `code` stays a bigint — a clever-error abort code packs the module, line, and
27
+ * constant index into the high bits of the u64 and would lose precision as a Number.
28
+ */
29
+ function decodeMoveAbort(error) {
30
+ const abort = error?.MoveAbort;
31
+ if (!abort) return null;
32
+ return new PredictMoveError(abort.location?.module ?? "", abort.abortCode != null ? BigInt(abort.abortCode) : 0n, abort.cleverError?.constantName ?? null);
33
+ }
34
+
35
+ //#endregion
36
+ export { PredictInputError, PredictMoveError, decodeMoveAbort };
37
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../src/predict/errors.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n// Typed errors for the Predict SDK.\n//\n// Two failure kinds cross the SDK boundary:\n// - PredictInputError — a caller gave us something we rejected before touching\n// the chain (unknown underlying, malformed argument, …).\n// - PredictMoveError — a Move `abort` surfaced by a read/simulate. The deployed\n// Predict packages are compiled with CLEVER ERRORS, so the fullnode decodes the\n// `E…` error-constant name out of the abort code's high bits and returns it on\n// the structured execution error. We read that name straight from chain instead\n// of maintaining a module→code→name table that goes stale on every redeploy.\n\n/** A caller-supplied argument the SDK rejected before building/sending a tx. */\nexport class PredictInputError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = 'PredictInputError';\n\t}\n}\n\n/** A Move `abort` decoded from a simulate/read failure. */\nexport class PredictMoveError extends Error {\n\treadonly module: string;\n\t/** Exact u64 abort code — bigint because clever-error encodings pack data\n\t * into the high bits, which Number would silently truncate. */\n\treadonly code: bigint;\n\t/** The `E…` constant name, decoded from the clever-error abort code by the\n\t * fullnode, or null when the transport surfaced no name (a non-clever abort,\n\t * or a JSON-RPC failure that carries only a line number). */\n\treadonly abortName: string | null;\n\n\tconstructor(module: string, code: bigint, abortName: string | null) {\n\t\tsuper(\n\t\t\tabortName\n\t\t\t\t? `Move abort in ${module}: ${abortName} (code ${code})`\n\t\t\t\t: `Move abort in ${module}: code ${code}`,\n\t\t);\n\t\tthis.name = 'PredictMoveError';\n\t\tthis.module = module;\n\t\tthis.code = code;\n\t\tthis.abortName = abortName;\n\t}\n}\n\n// The structured MoveAbort execution error surfaced by `@mysten/sui` on a failed\n// simulate/execute. Read structurally rather than via the client's exported\n// `SuiClientTypes.ExecutionError` (`@mysten/sui/client`) so mocked simulate results\n// and future API-shape drift still satisfy it — the same convention reads/inspect.ts\n// uses for its simulate seam. Field provenance:\n// - `MoveAbort.abortCode` → u64 abort code as a decimal string.\n// - `MoveAbort.location.module` → the aborting module's short name.\n// - `MoveAbort.cleverError.constantName` → the `E…` error constant, decoded by the\n// fullnode from the clever-error bits of the abort code and surfaced by the gRPC\n// (`grpc/core.ts` parseMoveAbort) and GraphQL transports. This is the on-chain\n// name that replaces the old hand-maintained ABORT_TABLES. JSON-RPC surfaces only\n// a line number, so `constantName` (and thus `abortName`) is absent there.\nexport interface MoveAbortError {\n\tMoveAbort?: {\n\t\tabortCode?: string | number | bigint;\n\t\tlocation?: { module?: string };\n\t\tcleverError?: { constantName?: string };\n\t};\n}\n\n/**\n * Decode a `@mysten/sui` MoveAbort execution error into a {@link PredictMoveError}.\n * Returns null when `error` carries no MoveAbort (InsufficientGas, a size error, any\n * non-abort failure), so callers can fall back to a plain Error.\n *\n * `abortName` is taken straight from the chain-decoded clever-error constant; it is\n * null when the abort predates clever errors or the transport didn't surface a name.\n * `code` stays a bigint — a clever-error abort code packs the module, line, and\n * constant index into the high bits of the u64 and would lose precision as a Number.\n */\nexport function decodeMoveAbort(error: MoveAbortError | null | undefined): PredictMoveError | null {\n\tconst abort = error?.MoveAbort;\n\tif (!abort) return null;\n\tconst module = abort.location?.module ?? '';\n\tconst code = abort.abortCode != null ? BigInt(abort.abortCode) : 0n;\n\tconst abortName = abort.cleverError?.constantName ?? null;\n\treturn new PredictMoveError(module, code, abortName);\n}\n"],"mappings":";;AAcA,IAAa,oBAAb,cAAuC,MAAM;CAC5C,YAAY,SAAiB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;AAKd,IAAa,mBAAb,cAAsC,MAAM;CAU3C,YAAY,QAAgB,MAAc,WAA0B;AACnE,QACC,YACG,iBAAiB,OAAO,IAAI,UAAU,SAAS,KAAK,KACpD,iBAAiB,OAAO,SAAS,OACpC;AACD,OAAK,OAAO;AACZ,OAAK,SAAS;AACd,OAAK,OAAO;AACZ,OAAK,YAAY;;;;;;;;;;;;;AAkCnB,SAAgB,gBAAgB,OAAmE;CAClG,MAAM,QAAQ,OAAO;AACrB,KAAI,CAAC,MAAO,QAAO;AAInB,QAAO,IAAI,iBAHI,MAAM,UAAU,UAAU,IAC5B,MAAM,aAAa,OAAO,OAAO,MAAM,UAAU,GAAG,IAC/C,MAAM,aAAa,gBAAgB,KACD"}
@@ -0,0 +1,18 @@
1
+ import { TESTNET_DEPLOYMENT, TESTNET_UNITS } from "../deployments/testnet.mjs";
2
+ import { getDeployment, getUnits } from "../deployments/index.mjs";
3
+ import { PredictConfig, PredictPackages, UnderlyingConfig } from "./config/types.mjs";
4
+ import { TESTNET_CONFIG } from "./config/testnet.mjs";
5
+ import { getConfig } from "./config/index.mjs";
6
+ import { BalanceChangeReceipt, BuilderCodeReceipt, ClaimReceipt, CreateManagerReceipt, DecodableEvent, DecodableTransactionResult, MintReceipt, PlpCancelReceipt, PlpRequestReceipt, RedeemReceipt } from "./decode.mjs";
7
+ import { GeneratedConfig, toGeneratedConfig } from "./config/generated.mjs";
8
+ import { OpenPosition } from "./reads/positions.mjs";
9
+ import { pricing_d_exports } from "./pricing.mjs";
10
+ import { MarketFeeds, loadLivePricer } from "./tx/trade.mjs";
11
+ import { ReadClient } from "./reads/inspect.mjs";
12
+ import { PricerSnapshot } from "./reads/pricing.mjs";
13
+ import { POS_INF_TICK, Side, binaryRangeTicks } from "./ticks.mjs";
14
+ import { ActiveMarket, CloseOptions, MarketDescriptor, MarketSummary, MintAmountOptions, MintOptions, MintQuote, POSITION_LOT_SIZE, PoolSummary, PredictClient, PredictCompatibleClient, RedeemQuote, predict } from "./client.mjs";
15
+ import { deriveAccountWrapperId, generateAuth } from "./tx/common.mjs";
16
+ import { U64_MAX, priceToRaw, probabilityToRaw, rawToPrice, rawToProbability, rawToUsdc, usdcToRaw } from "./units.mjs";
17
+ import { MoveAbortError, PredictInputError, PredictMoveError, decodeMoveAbort } from "./errors.mjs";
18
+ export { type ActiveMarket, type BalanceChangeReceipt, type BuilderCodeReceipt, type ClaimReceipt, type CloseOptions, type CreateManagerReceipt, type DecodableEvent, type DecodableTransactionResult, type GeneratedConfig, type MarketDescriptor, type MarketFeeds, type MarketSummary, type MintAmountOptions, type MintOptions, type MintQuote, type MintReceipt, type MoveAbortError, type OpenPosition, POSITION_LOT_SIZE, POS_INF_TICK, type PlpCancelReceipt, type PlpRequestReceipt, type PoolSummary, PredictClient, type PredictCompatibleClient, type PredictConfig, PredictInputError, PredictMoveError, type PredictPackages, type PricerSnapshot, type ReadClient, type RedeemQuote, type RedeemReceipt, type Side, TESTNET_CONFIG, TESTNET_DEPLOYMENT, TESTNET_UNITS, U64_MAX, type UnderlyingConfig, binaryRangeTicks, decodeMoveAbort, deriveAccountWrapperId, generateAuth, getConfig, getDeployment, getUnits, loadLivePricer, predict, priceToRaw, pricing_d_exports as pricing, probabilityToRaw, rawToPrice, rawToProbability, rawToUsdc, toGeneratedConfig, usdcToRaw };
@@ -0,0 +1,14 @@
1
+ import { TESTNET_DEPLOYMENT, TESTNET_UNITS } from "../deployments/testnet.mjs";
2
+ import { getDeployment, getUnits } from "../deployments/index.mjs";
3
+ import { TESTNET_CONFIG } from "./config/testnet.mjs";
4
+ import { getConfig } from "./config/index.mjs";
5
+ import { toGeneratedConfig } from "./config/generated.mjs";
6
+ import { PredictInputError, PredictMoveError, decodeMoveAbort } from "./errors.mjs";
7
+ import { U64_MAX, priceToRaw, probabilityToRaw, rawToPrice, rawToProbability, rawToUsdc, usdcToRaw } from "./units.mjs";
8
+ import { deriveAccountWrapperId, generateAuth } from "./tx/common.mjs";
9
+ import { POS_INF_TICK, binaryRangeTicks } from "./ticks.mjs";
10
+ import { loadLivePricer } from "./tx/trade.mjs";
11
+ import { pricing_exports } from "./pricing.mjs";
12
+ import { POSITION_LOT_SIZE, PredictClient, predict } from "./client.mjs";
13
+
14
+ export { POSITION_LOT_SIZE, POS_INF_TICK, PredictClient, PredictInputError, PredictMoveError, TESTNET_CONFIG, TESTNET_DEPLOYMENT, TESTNET_UNITS, U64_MAX, binaryRangeTicks, decodeMoveAbort, deriveAccountWrapperId, generateAuth, getConfig, getDeployment, getUnits, loadLivePricer, predict, priceToRaw, pricing_exports as pricing, probabilityToRaw, rawToPrice, rawToProbability, rawToUsdc, toGeneratedConfig, usdcToRaw };