@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,83 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Typed errors for the Predict SDK.
4
+ //
5
+ // Two failure kinds cross the SDK boundary:
6
+ // - PredictInputError — a caller gave us something we rejected before touching
7
+ // the chain (unknown underlying, malformed argument, …).
8
+ // - PredictMoveError — a Move `abort` surfaced by a read/simulate. The deployed
9
+ // Predict packages are compiled with CLEVER ERRORS, so the fullnode decodes the
10
+ // `E…` error-constant name out of the abort code's high bits and returns it on
11
+ // the structured execution error. We read that name straight from chain instead
12
+ // of maintaining a module→code→name table that goes stale on every redeploy.
13
+
14
+ /** A caller-supplied argument the SDK rejected before building/sending a tx. */
15
+ export class PredictInputError extends Error {
16
+ constructor(message: string) {
17
+ super(message);
18
+ this.name = 'PredictInputError';
19
+ }
20
+ }
21
+
22
+ /** A Move `abort` decoded from a simulate/read failure. */
23
+ export class PredictMoveError extends Error {
24
+ readonly module: string;
25
+ /** Exact u64 abort code — bigint because clever-error encodings pack data
26
+ * into the high bits, which Number would silently truncate. */
27
+ readonly code: bigint;
28
+ /** The `E…` constant name, decoded from the clever-error abort code by the
29
+ * fullnode, or null when the transport surfaced no name (a non-clever abort,
30
+ * or a JSON-RPC failure that carries only a line number). */
31
+ readonly abortName: string | null;
32
+
33
+ constructor(module: string, code: bigint, abortName: string | null) {
34
+ super(
35
+ abortName
36
+ ? `Move abort in ${module}: ${abortName} (code ${code})`
37
+ : `Move abort in ${module}: code ${code}`,
38
+ );
39
+ this.name = 'PredictMoveError';
40
+ this.module = module;
41
+ this.code = code;
42
+ this.abortName = abortName;
43
+ }
44
+ }
45
+
46
+ // The structured MoveAbort execution error surfaced by `@mysten/sui` on a failed
47
+ // simulate/execute. Read structurally rather than via the client's exported
48
+ // `SuiClientTypes.ExecutionError` (`@mysten/sui/client`) so mocked simulate results
49
+ // and future API-shape drift still satisfy it — the same convention reads/inspect.ts
50
+ // uses for its simulate seam. Field provenance:
51
+ // - `MoveAbort.abortCode` → u64 abort code as a decimal string.
52
+ // - `MoveAbort.location.module` → the aborting module's short name.
53
+ // - `MoveAbort.cleverError.constantName` → the `E…` error constant, decoded by the
54
+ // fullnode from the clever-error bits of the abort code and surfaced by the gRPC
55
+ // (`grpc/core.ts` parseMoveAbort) and GraphQL transports. This is the on-chain
56
+ // name that replaces the old hand-maintained ABORT_TABLES. JSON-RPC surfaces only
57
+ // a line number, so `constantName` (and thus `abortName`) is absent there.
58
+ export interface MoveAbortError {
59
+ MoveAbort?: {
60
+ abortCode?: string | number | bigint;
61
+ location?: { module?: string };
62
+ cleverError?: { constantName?: string };
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Decode a `@mysten/sui` MoveAbort execution error into a {@link PredictMoveError}.
68
+ * Returns null when `error` carries no MoveAbort (InsufficientGas, a size error, any
69
+ * non-abort failure), so callers can fall back to a plain Error.
70
+ *
71
+ * `abortName` is taken straight from the chain-decoded clever-error constant; it is
72
+ * null when the abort predates clever errors or the transport didn't surface a name.
73
+ * `code` stays a bigint — a clever-error abort code packs the module, line, and
74
+ * constant index into the high bits of the u64 and would lose precision as a Number.
75
+ */
76
+ export function decodeMoveAbort(error: MoveAbortError | null | undefined): PredictMoveError | null {
77
+ const abort = error?.MoveAbort;
78
+ if (!abort) return null;
79
+ const module = abort.location?.module ?? '';
80
+ const code = abort.abortCode != null ? BigInt(abort.abortCode) : 0n;
81
+ const abortName = abort.cleverError?.constantName ?? null;
82
+ return new PredictMoveError(module, code, abortName);
83
+ }
@@ -0,0 +1,94 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Public API for `@mysten/deepbook-v3/predict`. The curated surface is the `PredictClient`
4
+ // facade plus the value types, unit conversions, tick helpers, typed errors, and typed
5
+ // execution-result decoders — and the few primitives below that compose predict
6
+ // accounts into PTBs on FOREIGN packages, which no facade shape can cover.
7
+
8
+ // === Facade === (register as a client extension: `client.$extend(predict({ network }))`)
9
+ export { POSITION_LOT_SIZE, PredictClient, predict } from './client.js';
10
+ export type { PredictCompatibleClient } from './client.js';
11
+ export type {
12
+ ActiveMarket,
13
+ CloseOptions,
14
+ MarketDescriptor,
15
+ MarketSummary,
16
+ MintAmountOptions,
17
+ MintOptions,
18
+ MintQuote,
19
+ PoolSummary,
20
+ RedeemQuote,
21
+ } from './client.js';
22
+
23
+ // === Composition with foreign packages === auth + deterministic account addressing
24
+ // for PTBs that compose predict accounts with packages this SDK doesn't know (e.g.
25
+ // `deepbook_core_account` spot trading). `deriveAccountWrapperId` is the pure
26
+ // `(cfg, owner)` form of `wrapperIdFor` for contexts with no client instance. These are
27
+ // Predict-config-bound conveniences over `@mysten/deepbook-v3/account`, which owns the
28
+ // shared account primitive — reach for its `AccountContract` to drive it directly.
29
+ export { deriveAccountWrapperId, generateAuth } from './tx/common.js';
30
+
31
+ // === Config ===
32
+ export {
33
+ TESTNET_CONFIG,
34
+ getConfig,
35
+ getDeployment,
36
+ getUnits,
37
+ TESTNET_DEPLOYMENT,
38
+ TESTNET_UNITS,
39
+ } from './config/index.js';
40
+ export type { PredictConfig, PredictPackages, UnderlyingConfig } from './config/index.js';
41
+
42
+ // === Units (raw ⇄ human conversions) === domain-specific only; the generic `toRaw`/
43
+ // `fromRaw` primitives stay internal to avoid colliding with consumers' own helpers.
44
+ export {
45
+ U64_MAX,
46
+ priceToRaw,
47
+ probabilityToRaw,
48
+ rawToPrice,
49
+ rawToProbability,
50
+ rawToUsdc,
51
+ usdcToRaw,
52
+ } from './units.js';
53
+
54
+ // === Ticks ===
55
+ export { POS_INF_TICK, binaryRangeTicks } from './ticks.js';
56
+ export type { Side } from './ticks.js';
57
+
58
+ // === Client-side pricing === the deployed SVI digital math (skew-corrected, signed
59
+ // params, roll-down) as a float port, namespaced to keep the top-level surface clean:
60
+ // `pricing.upProbability`, `.boardPricer`, `.rollDown`, `.forward`, types `pricing.Svi` /
61
+ // `pricing.PricerInputs` / `pricing.BoardPricer`. Turnkey path: `client.predict.read.pricer(
62
+ // market)` reads the chain's resolved pricer once, then prices a whole board locally.
63
+ export * as pricing from './pricing.js';
64
+ export type { PricerSnapshot } from './reads/pricing.js';
65
+
66
+ // === Errors ===
67
+ export { PredictInputError, PredictMoveError, decodeMoveAbort } from './errors.js';
68
+ export type { MoveAbortError } from './errors.js';
69
+
70
+ // === Client seam + position type used in public read signatures ===
71
+ export type { ReadClient } from './reads/inspect.js';
72
+ export type { OpenPosition } from './reads/positions.js';
73
+
74
+ // === Execution-result decoder types === the decoders themselves are reached via
75
+ // `client.predict.decode.*`; only the receipt types are needed on the public surface.
76
+ export type {
77
+ BalanceChangeReceipt,
78
+ BuilderCodeReceipt,
79
+ ClaimReceipt,
80
+ CreateManagerReceipt,
81
+ DecodableEvent,
82
+ DecodableTransactionResult,
83
+ MintReceipt,
84
+ PlpCancelReceipt,
85
+ PlpRequestReceipt,
86
+ RedeemReceipt,
87
+ } from './decode.js';
88
+
89
+ // The `/sessions` Predict wrappers take `pricer` as a PTB result of this call, so it has to
90
+ // be reachable from the published surface for those builders to be composable at all.
91
+ export { loadLivePricer, type MarketFeeds } from './tx/trade.js';
92
+ // `loadLivePricer` takes the projected config, so the projection and its type have to be
93
+ // reachable too — without them the `/sessions` Predict wrappers cannot be composed at all.
94
+ export { toGeneratedConfig, type GeneratedConfig } from './config/generated.js';
@@ -0,0 +1,199 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Faithful float port of the deployed `deepbook_predict::pricing::compute_nd2`
4
+ // (testnet `predict-testnet-8-21`, sourceCommit 1f79fe87) — the SVI-adjusted digital
5
+ // probability, WITH the skew-correction term. It operates on the pricer's
6
+ // ALREADY-RESOLVED forward and ALREADY-ROLLED-DOWN SVI, exactly as `load_live_pricer`
7
+ // returns them (decoded by `reads/pricing.ts`). So the two on-chain steps that pick the
8
+ // forward (Pyth-spot vs Block-Scholes, admin flag + freshness) and roll `a`/`b` down by
9
+ // remaining/anchored time already happened on-chain — this module never re-derives them,
10
+ // which is what keeps it faithful.
11
+ //
12
+ // This is the fast client-side board pricer: read one `Pricer` snapshot, then price every
13
+ // strike locally with no further chain calls. `read.price` / `read.quoteMint` (a chain
14
+ // dry-run) stay the authoritative quote at trade time. Divergence vs the chain is up to
15
+ // ~1e-4 in probability, dominated by the chain's fixed-point truncation near ATM when sigma
16
+ // sits at its floor (float64 here is the more precise side, not the less); negligible for
17
+ // display. `tests/testnet/pricing.test.ts` bounds it live against the deployment.
18
+ //
19
+ // The on-chain formula (pricing.move `compute_nd2`, 1f79fe87):
20
+ // k = ln(strike / forward)
21
+ // x = k - m
22
+ // w = a + b·(ρ·x + √(x² + σ²)) // a, b already rolled down
23
+ // d2 = −(k + w/2) / √w // clamped to ±8
24
+ // w′ = b·(ρ + x/√(x² + σ²)) // SVI slope
25
+ // price = N(d2) − φ(d2)·w′ / (2·√w) // the skew correction, clamped [0,1]
26
+
27
+ /** Rolled-down SVI parameters for one expiry, in decimal (NOT the chain's 1e9/1e18 integer
28
+ * scaling) — the surface AFTER Predict's remaining-time roll-down, as carried by the
29
+ * on-chain `Pricer`. `a`, `rho`, `m` are signed; `b`, `sigma` are non-negative. */
30
+ export interface Svi {
31
+ a: number;
32
+ b: number;
33
+ rho: number;
34
+ m: number;
35
+ sigma: number;
36
+ }
37
+
38
+ /** A resolved pricer snapshot: the forward the contract prices against and its rolled SVI
39
+ * surface, both in decimal. Produced by `read.pricer(market)`; consume via {@link boardPricer}
40
+ * or the pure functions below. */
41
+ export interface PricerInputs {
42
+ /** Forward price the digital settles against, in decimal (same units as `strike`). */
43
+ forward: number;
44
+ svi: Svi;
45
+ }
46
+
47
+ /** Standard normal CDF via erf (Abramowitz–Stegun 7.1.26, |err| < 1.5e-7). */
48
+ function normalCdf(x: number): number {
49
+ return 0.5 * (1 + erf(x / Math.SQRT2));
50
+ }
51
+
52
+ /** Standard normal PDF. */
53
+ function normalPdf(x: number): number {
54
+ return Math.exp(-0.5 * x * x) / Math.sqrt(2 * Math.PI);
55
+ }
56
+
57
+ function erf(x: number): number {
58
+ const sign = x >= 0 ? 1 : -1;
59
+ const ax = Math.abs(x);
60
+ const t = 1 / (1 + 0.3275911 * ax);
61
+ const y =
62
+ 1 -
63
+ ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) *
64
+ t *
65
+ Math.exp(-ax * ax);
66
+ return sign * y;
67
+ }
68
+
69
+ // Clamp |d2| at 8, matching the chain (`normal_cdf`/`normal_pdf` saturate beyond that).
70
+ function clampD2(d2: number): number {
71
+ return d2 > 8 ? 8 : d2 < -8 ? -8 : d2;
72
+ }
73
+
74
+ /** P(settle > strike) — the UP digital, with the SVI skew correction. `inputs.svi` is the
75
+ * already-rolled surface (no roll-down applied here). `forward` and `strike` share units.
76
+ * Returns a probability in [0, 1]. */
77
+ export function upProbability(inputs: PricerInputs, strike: number): number {
78
+ const { forward, svi } = inputs;
79
+ if (!(forward > 0)) return 0;
80
+ if (strike <= 0) return 1; // neg-inf limit
81
+ const { a, b, rho, m, sigma } = svi;
82
+ const k = Math.log(strike / forward);
83
+ const km = k - m;
84
+ const root = Math.sqrt(km * km + sigma * sigma);
85
+ const inner = rho * km + root; // >= 0 for |rho| <= 1
86
+ const w = a + b * inner; // total variance
87
+ // The chain guarantees w > 0 at every strike (assert_min_total_variance_positive at
88
+ // load time), so this branch is unreachable in practice; return the variance→0 tail
89
+ // limit rather than throw, so a UI never crashes on a degenerate snapshot.
90
+ if (w <= 0) return k < 0 ? 1 : 0;
91
+ const sq = Math.sqrt(w);
92
+ const d2 = clampD2(-((k + w / 2) / sq));
93
+ const nd2 = normalCdf(d2);
94
+ const wPrime = b * (rho + km / root); // SVI slope × b
95
+ const price = nd2 - (normalPdf(d2) * wPrime) / (2 * sq); // skew correction
96
+ return price < 0 ? 0 : price > 1 ? 1 : price;
97
+ }
98
+
99
+ /** P(settle < strike) — the DOWN digital. Exactly `1 − up`, matching the chain's
100
+ * `range_price(-inf, strike] = up(-inf) − up(strike) = 1 − up(strike)`. */
101
+ export function downProbability(inputs: PricerInputs, strike: number): number {
102
+ return 1 - upProbability(inputs, strike);
103
+ }
104
+
105
+ /** Probability mass in `(lower, higher]`, floored at 0 (matches `compute_range_price`'s
106
+ * saturating subtraction). Use `lower <= 0` for the −∞ bound and `higher = Infinity` for +∞. */
107
+ export function rangeProbability(inputs: PricerInputs, lower: number, higher: number): number {
108
+ // up(lower) − up(higher), where up(+inf) = 0 and up(<= 0) = 1.
109
+ const upLower = lower <= 0 ? 1 : upProbability(inputs, lower);
110
+ const upHigher = higher === Infinity ? 0 : upProbability(inputs, higher);
111
+ const d = upLower - upHigher;
112
+ return d < 0 ? 0 : d;
113
+ }
114
+
115
+ /** Binary probability at `strike` for the given side (`up` = P(>strike), `down` = 1 − up). */
116
+ export function probability(inputs: PricerInputs, strike: number, side: 'up' | 'down'): number {
117
+ const up = upProbability(inputs, strike);
118
+ return side === 'up' ? up : 1 - up;
119
+ }
120
+
121
+ /** Strike where P(settle > strike) = `p`, by bisection (UP is monotone-decreasing in
122
+ * strike). Null when no crossing exists within ±64% of forward. */
123
+ export function strikeAtProbability(inputs: PricerInputs, p: number): number | null {
124
+ const { forward } = inputs;
125
+ if (!(forward > 0) || !(p > 0 && p < 1)) return null;
126
+ const up = (strike: number) => upProbability(inputs, strike);
127
+ let r = 0.01;
128
+ while (up(forward * (1 - r)) < p || up(forward * (1 + r)) > p) {
129
+ r *= 2;
130
+ if (r > 0.64) return null;
131
+ }
132
+ let lo = forward * (1 - r);
133
+ let hi = forward * (1 + r);
134
+ for (let i = 0; i < 64; i++) {
135
+ const mid = (lo + hi) / 2;
136
+ if (up(mid) > p) lo = mid;
137
+ else hi = mid;
138
+ }
139
+ return (lo + hi) / 2;
140
+ }
141
+
142
+ // --- Resolving raw feed data client-side (for consumers that hold their own live oracle
143
+ // feed and want to price with NO chain call, e.g. deepbook-app). The turnkey path is
144
+ // `read.pricer(market)`, which reads these already resolved from the chain's `Pricer`;
145
+ // these two helpers reproduce the on-chain resolution when you'd rather not read the chain.
146
+
147
+ /** Roll `a` and `b` down by the fraction of anchored time remaining, matching the chain's
148
+ * `roll_down_svi` (variance decays toward expiry). `remainingMs` = expiry − now;
149
+ * `anchorTteMs` = expiry − the SVI observation's **batch envelope time** — the same clock the
150
+ * freshness gate uses, and what the chain anchors on. It is NOT the provider's calibration
151
+ * (model) time, which stays on the stored observation: using that rolls by the wrong
152
+ * fraction. `read.pricer` avoids the question entirely (the chain has already rolled).
153
+ * `rho`, `m`, `sigma` are unchanged. Feed an UNrolled provider surface; the result is what {@link upProbability}
154
+ * expects. */
155
+ export function rollDown(svi: Svi, remainingMs: number, anchorTteMs: number): Svi {
156
+ const frac = anchorTteMs > 0 ? remainingMs / anchorTteMs : 0;
157
+ return { ...svi, a: svi.a * frac, b: svi.b * frac };
158
+ }
159
+
160
+ /** The forward the contract prices against: Pyth spot re-anchored by the Block-Scholes
161
+ * basis (`spot · forward/bsSpot`), falling back to the Block-Scholes forward when Pyth is
162
+ * absent. Pass `pythSpot <= 0` to force the fallback. NOTE: on-chain this branch is also
163
+ * gated by the admin flag `use_pyth_spot_for_forward` (default on) and a Pyth freshness
164
+ * window — when the flag is off or the Pyth spot is stale, the chain uses `bsForward`. If
165
+ * you track that config/freshness, apply it before calling (or use `read.pricer`, which
166
+ * gets the resolved forward from the chain). */
167
+ export function forward(pythSpot: number, bsSpot: number, bsForward: number): number {
168
+ if (pythSpot > 0 && bsSpot > 0) return pythSpot * (bsForward / bsSpot);
169
+ return bsForward;
170
+ }
171
+
172
+ /** A pricer bound to one resolved snapshot: price a whole board of strikes locally, no
173
+ * chain calls. Returned by `read.pricer(market)`; also constructable directly from inputs
174
+ * you already hold (e.g. from a `Pricer` snapshot decoded elsewhere). */
175
+ export interface BoardPricer extends PricerInputs {
176
+ /** P(settle > strike). */
177
+ up(strike: number): number;
178
+ /** P(settle < strike) = 1 − up. */
179
+ down(strike: number): number;
180
+ /** P(side wins at strike). */
181
+ probability(strike: number, side: 'up' | 'down'): number;
182
+ /** Probability mass in `(lower, higher]` (use `lower<=0`/`higher=Infinity` for the tails). */
183
+ range(lower: number, higher: number): number;
184
+ /** Strike where P(> strike) = `p`, or null if outside ±64% of forward. */
185
+ strikeAtProbability(p: number): number | null;
186
+ }
187
+
188
+ /** Build a {@link BoardPricer} from a resolved snapshot (decimal forward + rolled SVI). Pure. */
189
+ export function boardPricer(inputs: PricerInputs): BoardPricer {
190
+ return {
191
+ forward: inputs.forward,
192
+ svi: inputs.svi,
193
+ up: (strike) => upProbability(inputs, strike),
194
+ down: (strike) => downProbability(inputs, strike),
195
+ probability: (strike, side) => probability(inputs, strike, side),
196
+ range: (lower, higher) => rangeProbability(inputs, lower, higher),
197
+ strikeAtProbability: (p) => strikeAtProbability(inputs, p),
198
+ };
199
+ }
@@ -0,0 +1,55 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Transaction } from '@mysten/sui/transactions';
4
+ import type { GeneratedConfig } from '../config/generated.js';
5
+ import { deriveAccountWrapperIdFrom } from '../tx/common.js';
6
+ import { accountMoveCalls as account } from '../../account.js';
7
+ import * as predictAccount from '../../contracts/deepbook_predict/predict_account.js';
8
+ import { inspectReturns, type ReadClient } from './inspect.js';
9
+ import { parseU64LE } from './parse.js';
10
+
11
+ // An owner's stored account balance for `coinType` (the deployment's quote coin,
12
+ // DUSDC on testnet, unless the caller asks for another). Chains `account::load_account(wrapper)` →
13
+ // `account::balance<T>(account, root, clock)`; the u64 is command 1's return —
14
+ // see packages/account/sources/account.move:{80,86}. The clock is auto-injected by
15
+ // the generated `balance` wrapper; the wrapper id is derived off-chain (no read).
16
+ export async function accountBalance(
17
+ client: ReadClient,
18
+ config: GeneratedConfig,
19
+ owner: string,
20
+ coinType: string,
21
+ ): Promise<bigint> {
22
+ const tx = new Transaction();
23
+ const acct = tx.add(
24
+ account.loadAccount({ config, arguments: { self: deriveAccountWrapperIdFrom(config, owner) } }),
25
+ );
26
+ tx.add(account.balance({ config, typeArguments: [coinType], arguments: { self: acct } }));
27
+ const cmds = await inspectReturns(client, tx);
28
+ return parseU64LE(cmds[1][0]);
29
+ }
30
+
31
+ // Whether the owner's account still holds `orderId` on `marketId`. The cheap
32
+ // on-chain validator for app-stored order ids (stale after a full close or a
33
+ // partial-close replacement — see RedeemReceipt.replacementOrderId). Chains
34
+ // `account::load_account(wrapper)` → `predict_account::has_position(account,
35
+ // market_id, order_id)` — see packages/predict/sources/predict_account.move:85.
36
+ export async function hasPosition(
37
+ client: ReadClient,
38
+ config: GeneratedConfig,
39
+ owner: string,
40
+ marketId: string,
41
+ orderId: bigint,
42
+ ): Promise<boolean> {
43
+ const tx = new Transaction();
44
+ const acct = tx.add(
45
+ account.loadAccount({ config, arguments: { self: deriveAccountWrapperIdFrom(config, owner) } }),
46
+ );
47
+ tx.add(
48
+ predictAccount.hasPosition({
49
+ config,
50
+ arguments: { account: acct, expiryMarketId: marketId, orderId },
51
+ }),
52
+ );
53
+ const cmds = await inspectReturns(client, tx);
54
+ return (cmds[1][0][0] ?? 0) !== 0; // BCS bool: 1 byte
55
+ }
@@ -0,0 +1,78 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import type { ClientWithCoreApi } from '@mysten/sui/client';
4
+ import type { Transaction } from '@mysten/sui/transactions';
5
+ import { normalizeSuiAddress } from '@mysten/sui/utils';
6
+ import { decodeMoveAbort, type MoveAbortError } from '../errors.js';
7
+
8
+ // The one network seam every read sits on: any client exposing the core API
9
+ // (`client.core.simulateTransaction`, plus the object reads positions.ts needs).
10
+ // Callers pass a real SuiGrpcClient/SuiJsonRpcClient; tests inject a structural mock.
11
+ export type ReadClient = ClientWithCoreApi;
12
+
13
+ // The abort payload a failed simulate result carries: the structured gRPC `MoveAbort`
14
+ // arm (`{ abortCode, location: { module }, cleverError: { constantName } }`) plus an
15
+ // optional display `message`. Read structurally so mocks and API-shape drift satisfy it.
16
+ type SimAbortError = MoveAbortError & { message?: string };
17
+
18
+ // Run a read-only PTB through the gRPC `simulateTransaction` (the devInspect
19
+ // replacement) and return each command's BCS return values, indexed
20
+ // [commandIndex][returnValueIndex].
21
+ //
22
+ // `checksEnabled: false` disables validation so we may inspect non-entry public
23
+ // funs — see SimulateTransactionOptions.checksEnabled in
24
+ // node_modules/@mysten/sui/dist/client/types.d.mts:385-396. Per-command outputs
25
+ // live under `commandResults[i].returnValues[j].bcs` — see
26
+ // SimulateTransactionResult / CommandResult / CommandOutput in that same file at
27
+ // lines 309-348. `commandResults` is only populated when `include.commandResults`
28
+ // is set, so we request it explicitly.
29
+ //
30
+ // A sender is required to simulate; callers rarely have one for a pure read, so we
31
+ // default to the zero address. On abort the result's `$kind` is `FailedTransaction`;
32
+ // we decode the carried abort into a typed PredictMoveError, falling back to a plain
33
+ // Error with the failure message when it isn't a decodable Move abort.
34
+ // Shared failure handling: decode the abort carried by a FailedTransaction
35
+ // into a typed PredictMoveError, else throw a plain Error.
36
+ function throwSimFailure(failed: unknown): never {
37
+ const status = (failed as { status?: { success: boolean; error?: SimAbortError } })?.status;
38
+ const error = status && status.success === false ? status.error : undefined;
39
+ const decoded = error ? decodeMoveAbort(error) : null;
40
+ if (decoded) throw decoded;
41
+ throw new Error(error?.message ?? 'simulateTransaction aborted (FailedTransaction)');
42
+ }
43
+
44
+ // Simulate a full transaction (typically one built by a tx.* builder) and return
45
+ // the events it would emit — the quote path: dry-run the real action, decode the
46
+ // receipt. Sender must be the acting owner so account auth resolves. Throws the
47
+ // same typed errors the real execution would surface.
48
+ export async function simulateWithEvents(
49
+ client: ReadClient,
50
+ tx: Transaction,
51
+ sender: string,
52
+ ): Promise<{ eventType?: string; bcs?: Uint8Array | string }[]> {
53
+ tx.setSender(sender);
54
+ const result = await client.core.simulateTransaction({
55
+ transaction: tx,
56
+ checksEnabled: false,
57
+ include: { events: true },
58
+ });
59
+ if (result.$kind === 'FailedTransaction') throwSimFailure(result.FailedTransaction);
60
+ return (result.Transaction?.events ?? []) as { eventType?: string; bcs?: Uint8Array }[];
61
+ }
62
+
63
+ export async function inspectReturns(
64
+ client: ReadClient,
65
+ tx: Transaction,
66
+ sender: string = normalizeSuiAddress('0x0'),
67
+ ): Promise<Uint8Array[][]> {
68
+ tx.setSender(sender);
69
+ const result = await client.core.simulateTransaction({
70
+ transaction: tx,
71
+ checksEnabled: false,
72
+ include: { commandResults: true },
73
+ });
74
+ if (result.$kind === 'FailedTransaction') throwSimFailure(result.FailedTransaction);
75
+ const commands = result.commandResults;
76
+ if (!commands) throw new Error('simulateTransaction returned no commandResults');
77
+ return commands.map((c) => c.returnValues.map((rv) => rv.bcs));
78
+ }