@mysten/deepbook-v3 2.0.1 → 2.1.4

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 (276) hide show
  1. package/CHANGELOG.md +85 -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/client.d.mts +2 -2
  11. package/dist/contracts/account/account.d.mts +382 -0
  12. package/dist/contracts/account/account.d.mts.map +1 -0
  13. package/dist/contracts/account/account.mjs +443 -0
  14. package/dist/contracts/account/account.mjs.map +1 -0
  15. package/dist/contracts/account/account_events.d.mts +41 -0
  16. package/dist/contracts/account/account_events.d.mts.map +1 -0
  17. package/dist/contracts/account/account_events.mjs +72 -0
  18. package/dist/contracts/account/account_events.mjs.map +1 -0
  19. package/dist/contracts/account/account_registry.d.mts +210 -0
  20. package/dist/contracts/account/account_registry.d.mts.map +1 -0
  21. package/dist/contracts/account/account_registry.mjs +263 -0
  22. package/dist/contracts/account/account_registry.mjs.map +1 -0
  23. package/dist/contracts/account/config-arguments.d.mts +10 -0
  24. package/dist/contracts/account/config-arguments.d.mts.map +1 -0
  25. package/dist/contracts/account/deps/sui/bag.mjs +44 -0
  26. package/dist/contracts/account/deps/sui/bag.mjs.map +1 -0
  27. package/dist/contracts/deepbook/account.d.mts +18 -18
  28. package/dist/contracts/deepbook/balances.d.mts +4 -4
  29. package/dist/contracts/deepbook/deep_price.d.mts +3 -3
  30. package/dist/contracts/deepbook/deep_price.d.mts.map +1 -1
  31. package/dist/contracts/deepbook/order.d.mts +12 -12
  32. package/dist/contracts/deepbook_predict/builder_code_events.mjs +38 -0
  33. package/dist/contracts/deepbook_predict/builder_code_events.mjs.map +1 -0
  34. package/dist/contracts/deepbook_predict/config-arguments.d.mts +13 -0
  35. package/dist/contracts/deepbook_predict/config-arguments.d.mts.map +1 -0
  36. package/dist/contracts/deepbook_predict/deps/fixed_math/i64.mjs +25 -0
  37. package/dist/contracts/deepbook_predict/deps/fixed_math/i64.mjs.map +1 -0
  38. package/dist/contracts/deepbook_predict/deps/sui/balance.mjs +25 -0
  39. package/dist/contracts/deepbook_predict/deps/sui/balance.mjs.map +1 -0
  40. package/dist/contracts/deepbook_predict/deps/sui/coin.mjs +24 -0
  41. package/dist/contracts/deepbook_predict/deps/sui/coin.mjs.map +1 -0
  42. package/dist/contracts/deepbook_predict/deps/sui/table.mjs +39 -0
  43. package/dist/contracts/deepbook_predict/deps/sui/table.mjs.map +1 -0
  44. package/dist/contracts/deepbook_predict/deps/sui/vec_set.mjs +26 -0
  45. package/dist/contracts/deepbook_predict/deps/sui/vec_set.mjs.map +1 -0
  46. package/dist/contracts/deepbook_predict/ewma.mjs +29 -0
  47. package/dist/contracts/deepbook_predict/ewma.mjs.map +1 -0
  48. package/dist/contracts/deepbook_predict/expiry_cash.mjs +27 -0
  49. package/dist/contracts/deepbook_predict/expiry_cash.mjs.map +1 -0
  50. package/dist/contracts/deepbook_predict/expiry_market.mjs +367 -0
  51. package/dist/contracts/deepbook_predict/expiry_market.mjs.map +1 -0
  52. package/dist/contracts/deepbook_predict/lp_book.mjs +92 -0
  53. package/dist/contracts/deepbook_predict/lp_book.mjs.map +1 -0
  54. package/dist/contracts/deepbook_predict/market_manager.mjs +59 -0
  55. package/dist/contracts/deepbook_predict/market_manager.mjs.map +1 -0
  56. package/dist/contracts/deepbook_predict/order.mjs +26 -0
  57. package/dist/contracts/deepbook_predict/order.mjs.map +1 -0
  58. package/dist/contracts/deepbook_predict/order_events.mjs +84 -0
  59. package/dist/contracts/deepbook_predict/order_events.mjs.map +1 -0
  60. package/dist/contracts/deepbook_predict/plp.mjs +284 -0
  61. package/dist/contracts/deepbook_predict/plp.mjs.map +1 -0
  62. package/dist/contracts/deepbook_predict/pool_accounting.mjs +58 -0
  63. package/dist/contracts/deepbook_predict/pool_accounting.mjs.map +1 -0
  64. package/dist/contracts/deepbook_predict/predict_account.mjs +106 -0
  65. package/dist/contracts/deepbook_predict/predict_account.mjs.map +1 -0
  66. package/dist/contracts/deepbook_predict/pricing.mjs +80 -0
  67. package/dist/contracts/deepbook_predict/pricing.mjs.map +1 -0
  68. package/dist/contracts/deepbook_predict/range_codec.mjs +41 -0
  69. package/dist/contracts/deepbook_predict/range_codec.mjs.map +1 -0
  70. package/dist/contracts/deepbook_predict/registry.mjs +55 -0
  71. package/dist/contracts/deepbook_predict/registry.mjs.map +1 -0
  72. package/dist/contracts/deepbook_predict/strike_exposure.mjs +65 -0
  73. package/dist/contracts/deepbook_predict/strike_exposure.mjs.map +1 -0
  74. package/dist/contracts/deepbook_predict/strike_exposure_config.mjs +33 -0
  75. package/dist/contracts/deepbook_predict/strike_exposure_config.mjs.map +1 -0
  76. package/dist/contracts/deepbook_predict/strike_payout_tree.mjs +72 -0
  77. package/dist/contracts/deepbook_predict/strike_payout_tree.mjs.map +1 -0
  78. package/dist/contracts/deepbook_predict/vault_events.mjs +184 -0
  79. package/dist/contracts/deepbook_predict/vault_events.mjs.map +1 -0
  80. package/dist/contracts/deepbook_sessions/config-arguments.d.mts +10 -0
  81. package/dist/contracts/deepbook_sessions/config-arguments.d.mts.map +1 -0
  82. package/dist/contracts/deepbook_sessions/deps/sui/vec_map.mjs +37 -0
  83. package/dist/contracts/deepbook_sessions/deps/sui/vec_map.mjs.map +1 -0
  84. package/dist/contracts/deepbook_sessions/session_config.d.mts +63 -0
  85. package/dist/contracts/deepbook_sessions/session_config.d.mts.map +1 -0
  86. package/dist/contracts/deepbook_sessions/session_config.mjs +82 -0
  87. package/dist/contracts/deepbook_sessions/session_config.mjs.map +1 -0
  88. package/dist/contracts/deepbook_sessions/sessions.d.mts +275 -0
  89. package/dist/contracts/deepbook_sessions/sessions.d.mts.map +1 -0
  90. package/dist/contracts/deepbook_sessions/sessions.mjs +443 -0
  91. package/dist/contracts/deepbook_sessions/sessions.mjs.map +1 -0
  92. package/dist/contracts/utils/index.d.mts +18 -1
  93. package/dist/contracts/utils/index.d.mts.map +1 -1
  94. package/dist/deployments/index.d.mts +31 -0
  95. package/dist/deployments/index.d.mts.map +1 -0
  96. package/dist/deployments/index.mjs +30 -0
  97. package/dist/deployments/index.mjs.map +1 -0
  98. package/dist/deployments/testnet.d.mts +14 -0
  99. package/dist/deployments/testnet.d.mts.map +1 -0
  100. package/dist/deployments/testnet.mjs +73 -0
  101. package/dist/deployments/testnet.mjs.map +1 -0
  102. package/dist/deployments/types.d.mts +36 -0
  103. package/dist/deployments/types.d.mts.map +1 -0
  104. package/dist/index.mjs +0 -1
  105. package/dist/predict/client.d.mts +255 -0
  106. package/dist/predict/client.d.mts.map +1 -0
  107. package/dist/predict/client.mjs +436 -0
  108. package/dist/predict/client.mjs.map +1 -0
  109. package/dist/predict/config/generated.d.mts +29 -0
  110. package/dist/predict/config/generated.d.mts.map +1 -0
  111. package/dist/predict/config/generated.mjs +16 -0
  112. package/dist/predict/config/generated.mjs.map +1 -0
  113. package/dist/predict/config/index.d.mts +10 -0
  114. package/dist/predict/config/index.d.mts.map +1 -0
  115. package/dist/predict/config/index.mjs +13 -0
  116. package/dist/predict/config/index.mjs.map +1 -0
  117. package/dist/predict/config/testnet.d.mts +17 -0
  118. package/dist/predict/config/testnet.d.mts.map +1 -0
  119. package/dist/predict/config/testnet.mjs +26 -0
  120. package/dist/predict/config/testnet.mjs.map +1 -0
  121. package/dist/predict/config/types.d.mts +55 -0
  122. package/dist/predict/config/types.d.mts.map +1 -0
  123. package/dist/predict/decode.d.mts +162 -0
  124. package/dist/predict/decode.d.mts.map +1 -0
  125. package/dist/predict/decode.mjs +175 -0
  126. package/dist/predict/decode.mjs.map +1 -0
  127. package/dist/predict/errors.d.mts +42 -0
  128. package/dist/predict/errors.d.mts.map +1 -0
  129. package/dist/predict/errors.mjs +37 -0
  130. package/dist/predict/errors.mjs.map +1 -0
  131. package/dist/predict/index.d.mts +18 -0
  132. package/dist/predict/index.mjs +14 -0
  133. package/dist/predict/pricing.d.mts +73 -0
  134. package/dist/predict/pricing.d.mts.map +1 -0
  135. package/dist/predict/pricing.mjs +129 -0
  136. package/dist/predict/pricing.mjs.map +1 -0
  137. package/dist/predict/reads/balances.mjs +41 -0
  138. package/dist/predict/reads/balances.mjs.map +1 -0
  139. package/dist/predict/reads/inspect.d.mts +8 -0
  140. package/dist/predict/reads/inspect.d.mts.map +1 -0
  141. package/dist/predict/reads/inspect.mjs +37 -0
  142. package/dist/predict/reads/inspect.mjs.map +1 -0
  143. package/dist/predict/reads/markets.mjs +130 -0
  144. package/dist/predict/reads/markets.mjs.map +1 -0
  145. package/dist/predict/reads/parse.mjs +20 -0
  146. package/dist/predict/reads/parse.mjs.map +1 -0
  147. package/dist/predict/reads/pool.mjs +26 -0
  148. package/dist/predict/reads/pool.mjs.map +1 -0
  149. package/dist/predict/reads/positions.d.mts +12 -0
  150. package/dist/predict/reads/positions.d.mts.map +1 -0
  151. package/dist/predict/reads/positions.mjs +77 -0
  152. package/dist/predict/reads/positions.mjs.map +1 -0
  153. package/dist/predict/reads/pricing.d.mts +20 -0
  154. package/dist/predict/reads/pricing.d.mts.map +1 -0
  155. package/dist/predict/reads/pricing.mjs +43 -0
  156. package/dist/predict/reads/pricing.mjs.map +1 -0
  157. package/dist/predict/ticks.d.mts +11 -0
  158. package/dist/predict/ticks.d.mts.map +1 -0
  159. package/dist/predict/ticks.mjs +21 -0
  160. package/dist/predict/ticks.mjs.map +1 -0
  161. package/dist/predict/tx/authed.mjs +18 -0
  162. package/dist/predict/tx/authed.mjs.map +1 -0
  163. package/dist/predict/tx/common.d.mts +18 -0
  164. package/dist/predict/tx/common.d.mts.map +1 -0
  165. package/dist/predict/tx/common.mjs +52 -0
  166. package/dist/predict/tx/common.mjs.map +1 -0
  167. package/dist/predict/tx/trade.d.mts +15 -0
  168. package/dist/predict/tx/trade.d.mts.map +1 -0
  169. package/dist/predict/tx/trade.mjs +86 -0
  170. package/dist/predict/tx/trade.mjs.map +1 -0
  171. package/dist/predict/units.d.mts +11 -0
  172. package/dist/predict/units.d.mts.map +1 -0
  173. package/dist/predict/units.mjs +44 -0
  174. package/dist/predict/units.mjs.map +1 -0
  175. package/dist/queries/accountQueries.mjs +0 -1
  176. package/dist/queries/accountQueries.mjs.map +1 -1
  177. package/dist/queries/orderQueries.mjs +0 -1
  178. package/dist/queries/orderQueries.mjs.map +1 -1
  179. package/dist/queries/registryQueries.mjs +0 -1
  180. package/dist/queries/registryQueries.mjs.map +1 -1
  181. package/dist/sessions.d.mts +244 -0
  182. package/dist/sessions.d.mts.map +1 -0
  183. package/dist/sessions.mjs +291 -0
  184. package/dist/sessions.mjs.map +1 -0
  185. package/dist/transactions/balanceManager.d.mts +12 -12
  186. package/dist/transactions/balanceManager.d.mts.map +1 -1
  187. package/dist/transactions/deepbook.d.mts +20 -20
  188. package/dist/transactions/deepbook.d.mts.map +1 -1
  189. package/dist/transactions/deepbookAdmin.d.mts +4 -4
  190. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  191. package/dist/transactions/marginAdmin.d.mts +7 -7
  192. package/dist/transactions/marginLiquidations.d.mts +3 -3
  193. package/dist/transactions/marginMaintainer.d.mts +5 -5
  194. package/dist/transactions/marginManager.d.mts +32 -32
  195. package/dist/transactions/marginPool.d.mts +18 -18
  196. package/dist/transactions/marginRegistry.d.mts +16 -16
  197. package/dist/transactions/marginTPSL.d.mts +10 -10
  198. package/dist/transactions/marginTPSL.d.mts.map +1 -1
  199. package/dist/transactions/poolProxy.d.mts +8 -8
  200. package/dist/transactions/poolProxy.d.mts.map +1 -1
  201. package/package.json +25 -4
  202. package/src/account.ts +239 -0
  203. package/src/bcs/integers.ts +35 -0
  204. package/src/contracts/account/account.ts +706 -0
  205. package/src/contracts/account/account_events.ts +64 -0
  206. package/src/contracts/account/account_registry.ts +468 -0
  207. package/src/contracts/account/config-arguments.ts +8 -0
  208. package/src/contracts/account/deps/sui/bag.ts +42 -0
  209. package/src/contracts/deepbook_predict/admin.ts +44 -0
  210. package/src/contracts/deepbook_predict/builder_code.ts +155 -0
  211. package/src/contracts/deepbook_predict/builder_code_events.ts +34 -0
  212. package/src/contracts/deepbook_predict/config-arguments.ts +11 -0
  213. package/src/contracts/deepbook_predict/config_events.ts +140 -0
  214. package/src/contracts/deepbook_predict/deps/fixed_math/i64.ts +21 -0
  215. package/src/contracts/deepbook_predict/deps/sui/balance.ts +25 -0
  216. package/src/contracts/deepbook_predict/deps/sui/coin.ts +20 -0
  217. package/src/contracts/deepbook_predict/deps/sui/table.ts +37 -0
  218. package/src/contracts/deepbook_predict/deps/sui/vec_set.ts +22 -0
  219. package/src/contracts/deepbook_predict/ewma.ts +26 -0
  220. package/src/contracts/deepbook_predict/ewma_config.ts +28 -0
  221. package/src/contracts/deepbook_predict/expiry_cash.ts +24 -0
  222. package/src/contracts/deepbook_predict/expiry_market.ts +1549 -0
  223. package/src/contracts/deepbook_predict/lp_book.ts +105 -0
  224. package/src/contracts/deepbook_predict/market_lifecycle_cap.ts +75 -0
  225. package/src/contracts/deepbook_predict/market_manager.ts +218 -0
  226. package/src/contracts/deepbook_predict/order.ts +24 -0
  227. package/src/contracts/deepbook_predict/order_events.ts +129 -0
  228. package/src/contracts/deepbook_predict/pause_cap.ts +68 -0
  229. package/src/contracts/deepbook_predict/plp.ts +987 -0
  230. package/src/contracts/deepbook_predict/pool_accounting.ts +79 -0
  231. package/src/contracts/deepbook_predict/predict_account.ts +180 -0
  232. package/src/contracts/deepbook_predict/pricing.ts +124 -0
  233. package/src/contracts/deepbook_predict/pricing_config.ts +41 -0
  234. package/src/contracts/deepbook_predict/protocol_config.ts +1066 -0
  235. package/src/contracts/deepbook_predict/range_codec.ts +53 -0
  236. package/src/contracts/deepbook_predict/registry.ts +694 -0
  237. package/src/contracts/deepbook_predict/strike_exposure.ts +77 -0
  238. package/src/contracts/deepbook_predict/strike_exposure_config.ts +46 -0
  239. package/src/contracts/deepbook_predict/strike_payout_tree.ts +89 -0
  240. package/src/contracts/deepbook_predict/vault_events.ts +222 -0
  241. package/src/contracts/deepbook_sessions/config-arguments.ts +8 -0
  242. package/src/contracts/deepbook_sessions/deps/sui/vec_map.ts +33 -0
  243. package/src/contracts/deepbook_sessions/session_config.ts +130 -0
  244. package/src/contracts/deepbook_sessions/sessions.ts +663 -0
  245. package/src/contracts/propbook/block_scholes_store.ts +842 -0
  246. package/src/contracts/propbook/deps/sui/table.ts +37 -0
  247. package/src/contracts/propbook/oracle_lane.ts +170 -0
  248. package/src/contracts/propbook/pyth_feed.ts +414 -0
  249. package/src/contracts/propbook/registry.ts +596 -0
  250. package/src/deployments/index.ts +73 -0
  251. package/src/deployments/testnet.ts +107 -0
  252. package/src/deployments/types.ts +81 -0
  253. package/src/index.ts +5 -0
  254. package/src/predict/client.ts +941 -0
  255. package/src/predict/config/generated.ts +39 -0
  256. package/src/predict/config/index.ts +25 -0
  257. package/src/predict/config/testnet.ts +27 -0
  258. package/src/predict/config/types.ts +52 -0
  259. package/src/predict/decode.ts +476 -0
  260. package/src/predict/errors.ts +83 -0
  261. package/src/predict/index.ts +94 -0
  262. package/src/predict/pricing.ts +199 -0
  263. package/src/predict/reads/balances.ts +55 -0
  264. package/src/predict/reads/inspect.ts +78 -0
  265. package/src/predict/reads/markets.ts +222 -0
  266. package/src/predict/reads/parse.ts +30 -0
  267. package/src/predict/reads/pool.ts +37 -0
  268. package/src/predict/reads/positions.ts +144 -0
  269. package/src/predict/reads/pricing.ts +79 -0
  270. package/src/predict/ticks.ts +42 -0
  271. package/src/predict/tx/authed.ts +20 -0
  272. package/src/predict/tx/common.ts +92 -0
  273. package/src/predict/tx/trade.ts +183 -0
  274. package/src/predict/units.ts +49 -0
  275. package/src/sessions.ts +471 -0
  276. package/dist/types/bcs.mjs +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,90 @@
1
1
  # @mysten/deepbook-v3
2
2
 
3
+ ## 2.1.4
4
+
5
+ ## 2.1.3
6
+
7
+ ## 2.1.2
8
+
9
+ ## 2.1.1
10
+
11
+ ## 2.1.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 31f4bf1: Add the `@mysten/deepbook-v3/account` subpath, which now hosts the shared on-chain
16
+ account primitive (`AccountContract`, the generated `account` bindings, and the `Account` /
17
+ `AccountWrapper` BCS structs). The primitive is shared infrastructure — DeepBook's core account
18
+ wrapper and DeepBook Predict both build on the same Move package — so it lives alongside spot and
19
+ margin rather than in either consumer.
20
+
21
+ The package root's export surface is unchanged: `@mysten/deepbook-v3` exports exactly what it did
22
+ before, and subpaths are separate module graphs, so importing `/account` does not load spot or
23
+ margin code. Note that `Account` exported from the root remains
24
+ `@deepbook/core::account::Account`; the account primitive's `Account` is a different type and is
25
+ reachable only from `/account`.
26
+
27
+ Documenting a second entry point changes the generated API-reference layout: TypeDoc now emits an
28
+ `index` module alongside `account`, so existing deepbook-v3 doc pages gain an `index.` segment in
29
+ their names. External links into the published reference will need updating; nothing in this repo
30
+ links to them.
31
+
32
+ `/account` also exports `getAccountConfig(network)`, the deployed ids for the shared account
33
+ package, so consumers do not transcribe them. It reads a record generated from the deploy
34
+ tooling's own manifest, which every subpath shares — `getDeployment(network)` reports which
35
+ deployment and source commit those ids came from. Testnet only for now; other networks throw
36
+ rather than returning placeholder ids.
37
+
38
+ This release also marks the package `sideEffects: false`. No module in `src` has an import side
39
+ effect, so the only emitted-output change is that pure re-export modules are now tree-shaken out
40
+ of the bundle rather than imported for effect.
41
+
42
+ `@mysten/deepbook-account` is superseded. Its final release, `0.1.0`, is self-contained and keeps
43
+ working, but it will not be updated — import from `@mysten/deepbook-v3/account` instead.
44
+
45
+ - 31f4bf1: Add the `@mysten/deepbook-v3/predict` subpath, completing the consolidation of the
46
+ DeepBook SDKs behind one package. DeepBook Predict — market discovery, quotes, mint/redeem/claim,
47
+ PLP, typed receipts, and the client-side board pricer — now ships from here rather than from a
48
+ separate package.
49
+
50
+ The package root is unchanged, and subpaths remain separate module graphs: importing `/predict`
51
+ loads no spot or margin code.
52
+
53
+ `@mysten/deepbook-predict` is superseded. Its last published release keeps working for anyone
54
+ already on it, but it will not be updated — import from `@mysten/deepbook-v3/predict` instead.
55
+
56
+ Predict's testnet ids now come from the shared generated deployment record instead of a
57
+ hand-written literal, so `/account`, `/sessions` and `/predict` cannot drift apart across a
58
+ redeploy. `getConfig(network)` and `TESTNET_CONFIG` keep their values, but `PredictConfig` gains
59
+ two required fields — `coinTypes` (`plp`, `deep`) and `units` (`positionLotSize`,
60
+ `fixedPointScale`, `quoteCoinDecimals`, `positionQuantityDecimals`). Consumers using the shipped
61
+ config are unaffected; anyone hand-building a config for their own deployment must add both;
62
+ `getDeployment(network)` reports which deployment and source commit they came from.
63
+
64
+ - 31f4bf1: Add the `@mysten/deepbook-v3/sessions` subpath: time-limited trading sessions over a
65
+ canonical Account. An owner authorizes an ephemeral address to act for the Account until a fixed
66
+ expiry, and the session key never holds a reusable `Auth` — each wrapper mints app authorization
67
+ internally and consumes it in the same call.
68
+
69
+ `SessionsContract` covers the session lifecycle (`authorizeSession`, `revokeSession`,
70
+ `sessionExpirationMs`) and the DeepBook Predict wrappers (`mintExactQuantity`, `mintExactAmount`,
71
+ `redeemLive`, `redeemSettled`), plus `deriveAccountId` / `deriveSessionsFieldId` /
72
+ `decodeSessions` / `activeSessions` for enumerating an Account's grants — there is no bulk
73
+ on-chain read, and expired grants keep occupying slots against a 20-address cap.
74
+
75
+ The DeepBook spot session wrappers are generated and reachable from `sessionsMoveCalls`, but are
76
+ not wrapped on `SessionsContract` yet — the surrounding spot-over-Account workflow is not
77
+ modelled.
78
+
79
+ The package root is unchanged, and subpaths are separate module graphs — importing `/sessions`
80
+ loads no spot or margin code.
81
+
82
+ `getSessionsConfig(network)` returns the deployed sessions ids — package, `SessionsConfig` object,
83
+ and the account ids sessions shares — plus `deepbookRegistry` and the `deepbook_core_account`
84
+ package id for the generated spot wrappers. It reads the same generated deployment record
85
+ `/account` and `/predict` use, so a redeploy moves every subpath together. Testnet only for now;
86
+ other networks throw.
87
+
3
88
  ## 2.0.1
4
89
 
5
90
  ### Patch Changes
package/PREDICT.md ADDED
@@ -0,0 +1,256 @@
1
+ # DeepBook Predict (`@mysten/deepbook-v3/predict`)
2
+
3
+ TypeScript SDK for DeepBook Predict — binary markets on Sui. Builds ready-to-sign transactions and
4
+ reads on-chain state through your Sui client. The SDK never signs and never touches keys: every
5
+ `tx.*` method returns a `Transaction` for your wallet (dapp-kit) or signer to execute.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm i @mysten/deepbook-v3 @mysten/sui
11
+ ```
12
+
13
+ `@mysten/sui` is a peer dependency.
14
+
15
+ > Predict is deployed on **testnet** only. `getConfig('mainnet')` throws until a mainnet deployment
16
+ > exists.
17
+
18
+ ## Quickstart
19
+
20
+ The SDK registers as a client extension — `$extend` it onto your `SuiClient`/`SuiGrpcClient`, then
21
+ reach it at `client.predict.*`:
22
+
23
+ ```ts
24
+ import { SuiGrpcClient } from '@mysten/sui/grpc';
25
+ import { predict } from '@mysten/deepbook-v3/predict';
26
+
27
+ const client = new SuiGrpcClient({
28
+ network: 'testnet',
29
+ baseUrl: 'https://fullnode.testnet.sui.io:443',
30
+ }).$extend(predict({ network: 'testnet' }));
31
+
32
+ // One-time: create your Predict account (a shared AccountWrapper).
33
+ const createTx = client.predict.tx.createManager();
34
+
35
+ // Fund it: pulls DUSDC from your address (coin objects and/or address balance).
36
+ const depositTx = client.predict.tx.deposit(myAddress, 250); // $250
37
+
38
+ // Cash out: lands in your DUSDC address balance by default (no coin-object churn).
39
+ // Pass { toCoinObject: true } if you need a discrete Coin<T> instead.
40
+ const withdrawTx = client.predict.tx.withdraw(myAddress, 100); // $100
41
+
42
+ // Pick a live market. Expiries are absolute timestamps, so never hardcode one.
43
+ const markets = await client.predict.read.markets();
44
+ const expiryMs = markets[0].expiryMs;
45
+
46
+ // Describe the position once and reuse it — quoting and minting take the same descriptor.
47
+ const desc = { underlying: 'BTC', expiryMs, strike: 'reference', side: 'up' } as const;
48
+
49
+ // Quote before you trade: dry-runs your exact mint, real fees, real account.
50
+ const q = await client.predict.read.quoteMint(myAddress, desc, { quantity: 50 });
51
+ q.entryProbability; // your fill (0..1 per $1 payout)
52
+ q.cost; // exact all-in debit
53
+
54
+ // Trade. `maxCost` is your ceiling on the all-in debit — pass the quote plus a buffer,
55
+ // rounded to 6 decimals, since raw amounts are integers at that scale.
56
+ const mintTx = await client.predict.tx.mint(myAddress, desc, {
57
+ quantity: 50,
58
+ maxCost: Math.ceil(q.cost * 1.01 * 1e6) / 1e6,
59
+ });
60
+ // -> sign & execute any of these with your wallet / dapp-kit / signer
61
+
62
+ // Anonymous board price (no account needed): both sides of any strike.
63
+ const { up, down } = await client.predict.read.price({
64
+ underlying: 'BTC',
65
+ expiryMs,
66
+ strike: 'reference',
67
+ });
68
+
69
+ // Decode the receipt from the execution result (execute with events included):
70
+ const receipt = client.predict.decode.mint(mintResult);
71
+ receipt.orderId; // PERSIST THIS — needed to redeem/claim later
72
+ receipt.entryProbability; // your fill price (0..1 per $1 payout)
73
+ receipt.premium; // exact cost breakdown
74
+ receipt.fees;
75
+
76
+ // Read: tradeable markets and pool state.
77
+ const markets = await client.predict.read.markets();
78
+ // -> [{ id, expiryMs, tickSize, admissionTickSize, mintPaused, referencePrice }, ...]
79
+ const market = await client.predict.read.market({
80
+ underlying: 'BTC',
81
+ expiryMs: markets[0].expiryMs,
82
+ });
83
+ console.log(market?.nav, market?.tickSize, market?.mintPaused);
84
+ ```
85
+
86
+ ## ⚠ Slippage defaults are UNCAPPED
87
+
88
+ `mint` mirrors the chain's semantics: when you omit `maxCost` and `maxProbability`, the mint is
89
+ **uncapped** — if the price moves between your quote and execution, the position can cost up to your
90
+ full account balance. **Call `read.quoteMint` and pass its `cost` (plus your buffer) as `maxCost`.**
91
+ The same applies to `redeem`: the deployed `redeem_live` DOES take `min_probability` /
92
+ `min_proceeds` floors, but the facade does not surface them yet and always sends `0` (uncapped).
93
+ `read.quoteRedeem` first, close fast — or drive `redeemLive` from the tx layer to set the floors.
94
+
95
+ ## Units
96
+
97
+ Everything human-facing is decimal; everything on-chain is scaled integers. The facade converts
98
+ **inputs** exactly (string/bigint math — no floats on the money path in). Read outputs typed
99
+ `number` are display values: above 2^53 raw they lose low-digit precision — for accounting-exact
100
+ reads use the primitives layer, which returns raw `bigint`s (`accountBalance`, `poolStats`, …).
101
+
102
+ | Concept | You pass / receive | On-chain raw |
103
+ | ------------------------------------------- | -------------------------------------------------------------- | ------------------------------------- |
104
+ | Amounts (deposit, spend, maxCost, balances) | USD decimal number or string (`12.5`, `"12.5"`) | ×1e6 (DUSDC) |
105
+ | `quantity` | **max payout** in USD; positions pay $1 per contract at expiry | ×1e6, in $0.01 lots |
106
+ | `strike` | USD (`105_000`) | ×1e9, must land on the admission grid |
107
+ | `maxProbability` | 0..1 (`0.35` = 35¢ per $1 contract) | ×1e9 |
108
+ | PLP shares (`withdrawPlp`, `plpBalance`) | raw `bigint` shares | 6-decimal coin |
109
+
110
+ `side: "up"` wins if the settlement price is above the strike; `"down"` below.
111
+
112
+ ## Reference-price markets (Polymarket-style windows)
113
+
114
+ Each market carries an on-chain **reference price** — derived from the exact previous-window oracle
115
+ observation, so consecutive windows chain naturally (the prior window's settlement observation
116
+ anchors the next window's strike). Build an up/down board straight from discovery, and trade at the
117
+ anchor with `strike: "reference"`:
118
+
119
+ ```ts
120
+ const markets = await client.predict.read.markets();
121
+ // each market: "BTC above $<referencePrice>? ↑ / ↓"
122
+
123
+ const tx = await client.predict.tx.mint(
124
+ myAddress,
125
+ { underlying: 'BTC', expiryMs: markets[0].expiryMs, strike: 'reference', side: 'up' },
126
+ { quantity: 25, maxCost: 15 },
127
+ );
128
+ ```
129
+
130
+ The reference tick is read fresh at build time (it is unset briefly at the start of a window until
131
+ the keeper seeds it — you get a clean `PredictInputError` rather than a chain abort). Numeric
132
+ strikes away from the reference remain fully supported.
133
+
134
+ ### Numeric strikes must sit on the admission grid
135
+
136
+ New mint strikes must be a whole multiple of the market's **`admissionTickSize`** — a step
137
+ deliberately coarser than `tickSize`, and it varies by cadence (on the current testnet deployment
138
+ the 1m/5m/1h markets use `$1` and the 1d/1w markets `$100`, against a `$0.01` tick). Always read it
139
+ off the market rather than assuming a value. The market's `referencePrice` is the one finite strike
140
+ the chain admits off-grid. `read.markets()` and `read.market()` both report `admissionTickSize`, so
141
+ a board can be built from it directly:
142
+
143
+ ```ts
144
+ const m = (await client.predict.read.markets())[0];
145
+ const strike = Math.round(target / m.admissionTickSize) * m.admissionTickSize;
146
+ ```
147
+
148
+ An off-grid numeric strike throws `PredictInputError` at build time rather than aborting on chain
149
+ with `EInvalidAdmissionTick`.
150
+
151
+ ## What's in the box
152
+
153
+ - **`client.predict.tx`** — `createManager`, `deposit`, `withdraw`, `mint`, `mintAmount`, `redeem`,
154
+ `claimSettled`, `supplyPlp`, `withdrawPlp`, `cancelSupplyPlp`, `cancelWithdrawPlp`,
155
+ `setBuilderCode`, `unsetBuilderCode`. Market-resolving builders
156
+ (`mint`/`mintAmount`/`redeem`/`claimSettled`) are async: they resolve the market object from
157
+ `{ underlying, expiryMs, strike, side }` via the on-chain registry (cached per client).
158
+ - **`client.predict.read`** — `markets()` (tradeable summaries: id, expiry, tick size, mint-paused,
159
+ reference price), `market(desc)` (state + live NAV), `price(m)` (anonymous both-sides pricing for
160
+ any strike, one chain call per strike), `pricer(m)` (a **client-side board pricer** — one chain
161
+ read of the resolved pricer, then price every strike locally; see below),
162
+ `quoteMint(owner, m, opts)` / `quoteRedeem(owner, m, opts)` (exact dry-run quotes: real fees from
163
+ the real code path — and they throw the same typed errors the real trade would, so a quote doubles
164
+ as preflight), `balance(owner)`, `plpBalance(owner)`, `pool()`, `positions(owner)` (chain-only
165
+ enumeration of open positions), `hasPosition(owner, marketId, orderId)`. All reads run over the
166
+ client's `simulateTransaction`; no indexer required.
167
+ - **`client.predict.decode`** — pure execution-result decoders (no network): `mint`, `redeem`,
168
+ `claim`, `createManager`, `deposit`, `withdraw`, `plpRequest`, `plpCancel`, `builderCode`, each
169
+ with a plural form for batched PTBs. Execute transactions with events included and pass the
170
+ result; receipts come back in SDK units with raw bigints alongside. Decoding uses the events'
171
+ canonical BCS bytes, so it is transport-independent.
172
+ - **PTB composition** — integrators who need to compose their own transactions can use the generated
173
+ Move bindings under `contracts/` directly (transaction thunks + BCS structs), the same layer the
174
+ facade builds on.
175
+ - **Typed errors** — invalid inputs throw `PredictInputError` before the chain sees them; failed
176
+ simulations throw `PredictMoveError` with the decoded Move abort (`module`, `code`, `abortName`).
177
+
178
+ ## Client-side pricing (`read.pricer` + `pricing`)
179
+
180
+ `read.price` runs the deployed SVI math on-chain and is authoritative, but it costs one chain call
181
+ per strike. To paint a whole board — every strike, both sides, implied strikes — instantly, read the
182
+ resolved pricer **once** and compute the rest locally:
183
+
184
+ ```ts
185
+ const pricer = await client.predict.read.pricer({ underlying: 'BTC', expiryMs });
186
+ pricer.up(105_000); // P(settle > $105,000), 0..1
187
+ pricer.down(105_000); // = 1 − up
188
+ pricer.range(104_000, 106_000); // P(strike in (104k, 106k])
189
+ pricer.strikeAtProbability(0.25); // the strike whose UP price is 25¢
190
+ pricer.forward; // the forward it prices against
191
+ ```
192
+
193
+ `read.pricer` does a single simulate of the chain's `load_live_pricer` and decodes the returned
194
+ `Pricer` — so the forward selection (Pyth-vs-Block-Scholes) and the SVI roll-down already happened
195
+ on-chain; the client only evaluates the digital. It throws the same typed stale-oracle/expired
196
+ `PredictMoveError` that `read.price` would when the chain itself cannot quote.
197
+
198
+ The math is a faithful float port of the deployed `pricing::compute_nd2` (SVI with the skew
199
+ correction, signed params, and the remaining-time roll-down). It agrees with the chain closely —
200
+ within ~1e-4 in probability, up to ~1e-4 near ATM where the chain's fixed-point truncation dominates
201
+ (`tests/testnet/pricing.test.ts` bounds it live). The pure functions are exported under a `pricing`
202
+ namespace for callers who already hold their own oracle inputs (e.g. a live feed) and want zero
203
+ chain calls:
204
+
205
+ ```ts
206
+ import { pricing } from '@mysten/deepbook-v3/predict';
207
+
208
+ // From a rolled SVI surface + resolved forward you already have:
209
+ const inputs = { forward, svi: { a, b, rho, m, sigma } };
210
+ pricing.upProbability(inputs, strike);
211
+ pricing.strikeAtProbability(inputs, 0.25);
212
+ pricing.boardPricer(inputs); // same shape as read.pricer's return
213
+
214
+ // Or resolve raw feed data yourself (Strategy-2, matching the on-chain steps):
215
+ const fwd = pricing.forward(pythSpot, bsSpot, bsForward); // Pyth re-anchored by the BS basis
216
+ const rolled = pricing.rollDown(rawSvi, remainingMs, anchorTteMs); // decay a, b toward expiry
217
+ ```
218
+
219
+ ## Networks & deployments
220
+
221
+ **Testnet only today** — `getConfig("mainnet")` throws until a mainnet deployment exists. Object ids
222
+ for the current testnet deployment are baked into the SDK (`TESTNET_CONFIG`); they are updated, with
223
+ a release, whenever a new package version is deployed. Move-call targets flow through one resolution
224
+ seam, which will switch to MVR names (`@deepbook/predict`) once registered — package upgrades then
225
+ stop requiring an SDK release for target resolution.
226
+
227
+ ## Notes
228
+
229
+ - **Positions are enumerable on-chain**: `read.positions(owner)` lists every open position (market +
230
+ order id) straight from the account's position table — one round trip warm, no indexer. Persisting
231
+ `decode.mint(result).orderId` and applying `decode.redeem(result).replacementOrderId` is still the
232
+ fastest hot path, with `read.positions` as the fresh-start/recovery source and `read.hasPosition`
233
+ as the cheap validator.
234
+ - PLP supply/withdraw are queued and fill at the next pool flush; cancels take the queue `index` —
235
+ get it from `decode.plpRequest(result).index`.
236
+ - `claimSettled` closes the order in full — the deployed entrypoint takes no quantity.
237
+ - **`withdraw` lands in your address balance by default** (`0x2::coin::send_funds`), not a coin
238
+ object — it merges into the versionless accumulator `deposit` already draws from, so the round
239
+ trip never accretes stray `Coin<DUSDC>` objects. `read.balance(owner)` reflects the account's
240
+ internal custody balance; use the client's `getBalance(owner)` for the wallet-side DUSDC total
241
+ (coin objects + address balance). Pass `withdraw(owner, amt, { toCoinObject: true })` for a
242
+ discrete coin (wallets/explorers that only render coin objects, or same-PTB composition).
243
+
244
+ ## Development
245
+
246
+ These commands run against the whole `@mysten/deepbook-v3` package, not just Predict — the offline
247
+ lane covers spot, margin, `/account`, `/sessions` and `/predict` together.
248
+
249
+ ```sh
250
+ pnpm install
251
+ pnpm --filter @mysten/deepbook-v3 test # offline suite, every subpath — what CI runs
252
+ pnpm --filter @mysten/deepbook-v3 test:e2e # live-testnet smoke: reads + deployed-surface arity guards
253
+ pnpm --filter @mysten/deepbook-v3 build # ESM + d.ts via tsdown
254
+ ```
255
+
256
+ To run only the Predict tests: `pnpm --filter @mysten/deepbook-v3 vitest run test/predict`.
package/README.md CHANGED
@@ -1 +1,117 @@
1
1
  # Deepbook TypeScript SDK
2
+
3
+ ## Entry points
4
+
5
+ | Import | Contents |
6
+ | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
7
+ | `@mysten/deepbook-v3` | DeepBook spot and margin — pools, orders, balance managers, flash loans, governance, margin managers/pools, TPSL. |
8
+ | `@mysten/deepbook-v3/account` | The shared on-chain **account primitive** (`AccountContract`): the canonical `AccountWrapper`, `Auth`, and custody balances that DeepBook's core account wrapper and DeepBook Predict both build on. |
9
+ | `@mysten/deepbook-v3/sessions` | **Time-limited trading sessions** over a canonical Account (`SessionsContract`): grant an ephemeral address bounded authority until a fixed expiry. Covers the session lifecycle and the DeepBook Predict wrappers. |
10
+ | `@mysten/deepbook-v3/predict` | **DeepBook Predict** — binary markets: market discovery, quotes, mint/redeem/claim, PLP, typed receipts and a client-side board pricer. See [PREDICT.md](./PREDICT.md). |
11
+
12
+ Subpaths are separate module graphs — importing `@mysten/deepbook-v3/account` does not load any spot
13
+ or margin code.
14
+
15
+ Each subpath also exports the **deployed ids** for its own surface, so a caller never transcribes
16
+ them: `getAccountConfig(network)` on `/account`, `getSessionsConfig(network)` on `/sessions`,
17
+ `getConfig(network)` on `/predict`. All three read one generated record (`src/deployments/`), so a
18
+ redeploy updates every subpath at once and they cannot end up addressing different deployments.
19
+ `getDeployment(network)` names the deployment and the deepbookv3 commit those ids came from.
20
+ Predict, sessions and the account primitive are testnet-only today; an unrecorded network throws
21
+ rather than returning placeholder ids.
22
+
23
+ ### `@mysten/deepbook-v3/account`
24
+
25
+ An owner has one canonical `AccountWrapper`, a **derived object** of the account registry, so its id
26
+ is computable off-chain with no chain read. `AccountContract` takes only the deployed ids of the
27
+ `account` package, so each consumer drives it against **its own** deployment:
28
+
29
+ ```ts
30
+ import { Transaction } from '@mysten/sui/transactions';
31
+ import { AccountContract, getAccountConfig } from '@mysten/deepbook-v3/account';
32
+
33
+ // Deployed ids ship with the package — no transcription.
34
+ const account = new AccountContract(getAccountConfig('testnet'));
35
+
36
+ // …or drive a deployment of your own:
37
+ const custom = new AccountContract({ accountPackageId: '0x…', accountRegistry: '0x…' });
38
+
39
+ const wrapperId = account.deriveAccountWrapperId(owner);
40
+
41
+ const tx = new Transaction();
42
+ tx.add(account.depositFunds({ wrapperId, coin, coinType: USDC }));
43
+ ```
44
+
45
+ > `Account` exported from the package root is `@deepbook/core::account::Account` (the per-pool
46
+ > trading account). The account primitive's `Account` is a different type with an unrelated layout
47
+ > and is exported only from the `/account` subpath.
48
+ >
49
+ > The two surfaces also decode integers differently. `/account` parses `u64`/`u128`/`u256` to
50
+ > `bigint`; the root's BCS structs (`Balances`, `Order`, `OrderDeepPrice`) yield decimal
51
+ > **strings**. Both are raw on-chain units — neither is scaled — so a value crossing between them
52
+ > needs a cast, not a conversion.
53
+
54
+ ### `@mysten/deepbook-v3/sessions`
55
+
56
+ An Account owner authorizes an ephemeral address to submit a bounded set of transactions on the
57
+ Account's behalf until a fixed expiry. The session key never receives a reusable `Auth` — each
58
+ wrapper mints app authorization internally and consumes it in the same call — and there is no
59
+ withdrawal or arbitrary-mutation entrypoint.
60
+
61
+ ```ts
62
+ import { SessionsContract, getSessionsConfig } from '@mysten/deepbook-v3/sessions';
63
+
64
+ // Deployed ids ship with the package — no transcription.
65
+ const sessions = new SessionsContract(getSessionsConfig('testnet'));
66
+
67
+ const wrapperId = sessions.deriveAccountWrapperId(owner);
68
+
69
+ // Owner-signed: grant an ephemeral key one hour of authority.
70
+ tx.add(sessions.authorizeSession({ wrapperId, session: ephemeral, durationMs: 3_600_000 }));
71
+
72
+ // Signed by the session key: a Predict mint. `pricer` is the result of a preceding
73
+ // `expiry_market::load_live_pricer` command in the same transaction.
74
+ tx.add(sessions.mintExactQuantity({ expiryMarketId, wrapperId, protocolConfig, pricer, ... }));
75
+ ```
76
+
77
+ Notes that bite in practice:
78
+
79
+ - A grant is dead **at** its expiry — the chain asserts `now < expiresAtMs`.
80
+ - Expired grants are never pruned and keep occupying slots, and an Account holds at most **20**
81
+ distinct addresses. Use `SessionsContract.decodeSessions` with `activeSessions` /
82
+ `expiredSessions` to list and prune before granting. There is no bulk on-chain read, and the data
83
+ hangs off the **derived account address**, not the wrapper address.
84
+ - `revokeSession` on an address that holds no grant is a silent no-op — no abort, no event.
85
+ - Revocation and expiry reads are deliberately **not** version-gated, so they keep working even
86
+ after the sessions package is retired.
87
+ - The session address is the transaction sender, so it pays its own gas.
88
+ - An admin must have authorized `SessionsApp` on the account registry. Until then — or after a
89
+ `deauthorize_app` — the **trading** wrappers abort with `EAppNotAuthorized`; `authorizeSession`,
90
+ `revokeSession` and `sessionExpirationMs` use owner auth or no auth and keep working.
91
+ `deauthorize_app` does not clear `SessionsData`, so re-authorizing makes every still-unexpired
92
+ grant live again at once — it pauses sessions, it does not kill them.
93
+ - Listing grants goes through `deriveSessionsFieldId(owner)` → fetch → `decodeSessions`. Pass the
94
+ whole field object's contents, not the inner value. Fetch it through the core API, and ask for
95
+ content explicitly — JSON-RPC is gone from public fullnodes, and without `include` the response
96
+ carries no bytes:
97
+
98
+ ```ts
99
+ const { object } = await client.core.getObject({ objectId, include: { content: true } });
100
+ const grants = SessionsContract.decodeSessions(object.content);
101
+ ```
102
+
103
+ - The field does not exist until the owner's **first** `authorizeSession` — the Move attaches it
104
+ lazily — so the fetch returns not-found for an owner who has never granted. That is distinct from
105
+ a field that exists holding an empty map, which means every grant was revoked. Treat not-found as
106
+ "no grants", but only not-found: a transport failure must not be collapsed into the same answer.
107
+
108
+ **What a session key can do.** It cannot withdraw to an address, cannot grant or revoke sessions,
109
+ and cannot outlive its expiry. It _can_ trade the Account's full balance: the spot wrappers take a
110
+ caller-chosen `Pool` and pull the account's entire Base, Quote and DEEP balance into the embedded
111
+ manager for the call, with `price_limit` supplied by the caller. Nothing caps notional or restricts
112
+ which pools are reachable, so value can leave through adverse pricing. Fund an ephemeral-session
113
+ Account with only what you would accept losing to that key.
114
+
115
+ The DeepBook **spot** session wrappers are generated and reachable from `sessionsMoveCalls`, but
116
+ they are not wrapped on `SessionsContract`: the surrounding spot-over-Account workflow — finding the
117
+ embedded balance manager, reading resting orders and locked balances — is not modelled yet.
@@ -0,0 +1,139 @@
1
+ import { AccountConfig as AccountConfig$1 } from "./contracts/account/config-arguments.mjs";
2
+ import { TESTNET_DEPLOYMENT, TESTNET_UNITS } from "./deployments/testnet.mjs";
3
+ import { DeployedNetwork, NetworkArg, getDeployment, getUnits } from "./deployments/index.mjs";
4
+ import { Account, AccountWrapper, account_d_exports } from "./contracts/account/account.mjs";
5
+ import { account_registry_d_exports } from "./contracts/account/account_registry.mjs";
6
+ import { account_events_d_exports } from "./contracts/account/account_events.mjs";
7
+ import { Transaction, TransactionObjectArgument, TransactionResult } from "@mysten/sui/transactions";
8
+
9
+ //#region src/account.d.ts
10
+ /**
11
+ * The deployed ids of the shared `account` package this contract builds against.
12
+ *
13
+ * Kept deliberately minimal — ids only — so any consumer of the shared account primitive
14
+ * (DeepBook core's account wrapper, Predict, …) can drive these builders with its OWN
15
+ * deployment's ids without constructing a full product-SDK config.
16
+ *
17
+ * Extends the codegen-generated config interface so there is exactly one config shape and
18
+ * casing: the generated bindings resolve `options.config` against these same keys, and if
19
+ * codegen adds, drops, or renames a key this file stops compiling instead of silently
20
+ * building a PTB against the wrong object. The ids are narrowed to `string` — codegen types
21
+ * the package id as optional and the registry as the wider `ConfigValue`, but the
22
+ * wrapper-address derivation needs plain ids.
23
+ */
24
+ interface AccountConfig extends AccountConfig$1 {
25
+ /** The `account` Move package id. */
26
+ accountPackageId: string;
27
+ /** The shared `AccountRegistry` object id. */
28
+ accountRegistry: string;
29
+ }
30
+ /**
31
+ * @description The deployed `account` ids for `network`, so a caller does not transcribe
32
+ * them. Generated from the deploy manifest — see `src/deployments/`.
33
+ * @throws if the network has no recorded deployment, rather than returning placeholder ids
34
+ * that would fail as a confusing on-chain abort.
35
+ *
36
+ * ```ts
37
+ * const account = new AccountContract(getAccountConfig('testnet'));
38
+ * ```
39
+ */
40
+ declare function getAccountConfig(network: NetworkArg): AccountConfig;
41
+ /**
42
+ * AccountContract — the reusable on-chain account primitive (`packages/account`).
43
+ *
44
+ * An owner has one canonical `AccountWrapper`, a *derived* object of the account registry,
45
+ * so its id is computable off-chain (no read). The wrapper holds an `Account` whose custody
46
+ * balances apps deposit into and withdraw from; app-specific data hangs off it under an
47
+ * app-keyed slot. Authority is a hot-potato `Auth` minted from the tx sender and consumed
48
+ * by the very next account-loading call.
49
+ */
50
+ declare class AccountContract {
51
+ #private;
52
+ /**
53
+ * @param {AccountConfig} config Deployed ids of the shared `account` package
54
+ */
55
+ constructor(config: AccountConfig);
56
+ /**
57
+ * @description The deterministic id of an owner's canonical account wrapper — no chain
58
+ * read needed. The wrapper is a derived object of the account registry, so its id is
59
+ * `derive_address(registry, AccountWrapperKey(owner))`.
60
+ * @param {string} owner Owner address
61
+ * @returns The wrapper object id
62
+ */
63
+ deriveAccountWrapperId(owner: string): string;
64
+ /**
65
+ * @description Mint owner authority for the transaction sender. A hot-potato `Auth`
66
+ * consumed by the very next account-loading call (`load_account_mut` inside
67
+ * `deposit_funds` / `withdraw_funds` / an app's own entrypoints).
68
+ * @returns A function that takes a Transaction object
69
+ */
70
+ generateAuth(): (tx: Transaction) => TransactionResult;
71
+ /**
72
+ * @description Create the sender's canonical account wrapper and share it. `new` derives
73
+ * the wrapper at its deterministic address (see `deriveAccountWrapperId`) and aborts if
74
+ * it already exists; `share` publishes the shared object apps borrow against.
75
+ * @returns A function that takes a Transaction object
76
+ */
77
+ createAccount(): (tx: Transaction) => void;
78
+ /**
79
+ * @description First-time funding in ONE PTB: create the sender's wrapper, deposit
80
+ * `coin` through the fresh handle, then `share` LAST (once shared, by-value use of the
81
+ * handle is over). This cannot be split into `createAccount` + `depositFunds`: an object
82
+ * input can only address an object that pre-exists the PTB, so a wrapper created inside
83
+ * it is reachable only through `new`'s result handle.
84
+ * @param {object} params Coin to deposit and its coin type
85
+ * @returns A function that takes a Transaction object
86
+ */
87
+ createAccountAndDeposit(params: {
88
+ coin: TransactionObjectArgument;
89
+ coinType: string;
90
+ }): (tx: Transaction) => void;
91
+ /**
92
+ * @description Deposit a caller-provided `coin` into the account's stored balance via the
93
+ * PTB-callable `deposit_funds` (folds settle → authorize → load → deposit; clock and
94
+ * accumulator root auto-injected). The caller owns coin sourcing.
95
+ * @param {object} params Wrapper id, coin to deposit, and its coin type
96
+ * @returns A function that takes a Transaction object
97
+ */
98
+ depositFunds(params: {
99
+ wrapperId: string;
100
+ coin: TransactionObjectArgument;
101
+ coinType: string;
102
+ }): (tx: Transaction) => void;
103
+ /**
104
+ * @description Withdraw `amount` (raw u64 units) from the account's stored balance via
105
+ * the PTB-callable `withdraw_funds` (folds settle → authorize → load → withdraw; clock
106
+ * and accumulator root auto-injected), returning the minted `Coin<T>` for the caller to
107
+ * transfer or compose.
108
+ * @param {object} params Wrapper id, raw amount, and coin type
109
+ * @returns A function that takes a Transaction object and returns the `Coin<T>`
110
+ */
111
+ withdrawFunds(params: {
112
+ wrapperId: string;
113
+ amount: bigint;
114
+ coinType: string;
115
+ }): (tx: Transaction) => TransactionResult;
116
+ /**
117
+ * @description Borrow the `Account` out of its wrapper — the read-side entry point apps
118
+ * chain their own getters onto (`account::balance<T>`, an app's own data accessors).
119
+ * @param {object} params Wrapper id
120
+ * @returns A function that takes a Transaction object and returns the `Account`
121
+ */
122
+ loadAccount(params: {
123
+ wrapperId: string;
124
+ }): (tx: Transaction) => TransactionResult;
125
+ /**
126
+ * @description Read an owner's stored custody balance for a coin type: chains
127
+ * `load_account(wrapper)` → `balance<T>(account, root, clock)`. Compose in a
128
+ * dev-inspect/simulate PTB and read the u64 return of the LAST command.
129
+ * @param {object} params Owner address and coin type
130
+ * @returns A function that takes a Transaction object
131
+ */
132
+ balance(params: {
133
+ owner: string;
134
+ coinType: string;
135
+ }): (tx: Transaction) => TransactionResult;
136
+ }
137
+ //#endregion
138
+ export { Account, AccountConfig, AccountContract, AccountWrapper, type DeployedNetwork, type NetworkArg, TESTNET_DEPLOYMENT, TESTNET_UNITS, account_events_d_exports as accountEvents, account_d_exports as accountMoveCalls, account_registry_d_exports as accountRegistryMoveCalls, getAccountConfig, getDeployment, getUnits };
139
+ //# sourceMappingURL=account.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.mts","names":[],"sources":["../src/account.ts"],"mappings":";;;;;;;;;;;;AAoCA;;;;;;;;;AAiBA;;UAjBiB,aAAA,SAAsB,eAAA;EAiB6B;EAfnE,gBAAA;EAegC;EAbhC,eAAA;AAAA;;AAqCD;;;;;;;;;iBAxBgB,gBAAA,CAAiB,OAAA,EAAS,UAAA,GAAa,aAAA;;;;;;;;;;cAwB1C,eAAA;EAAA;EAMQ;;;cAAR,MAAA,EAAQ,aAAA;EA0BpB;;;;;;;EAfA,sBAAA,CAAuB,KAAA;EA0CW;;;;;;EA3BlC,YAAA,CAAA,IACS,EAAA,EAAI,WAAA,KAAc,iBAAA;EAgDJ;;;;;;EAtCvB,aAAA,CAAA,IACS,EAAA,EAAI,WAAA;EA0Db;;;;;;;;;EA3CA,uBAAA,CAAwB,MAAA;IAAU,IAAA,EAAM,yBAAA;IAA2B,QAAA;EAAA,KAC1D,EAAA,EAAI,WAAA;EA8Dc;;;;;;;EAzC3B,YAAA,CAAa,MAAA;IAAU,SAAA;IAAmB,IAAA,EAAM,yBAAA;IAA2B,QAAA;EAAA,KAClE,EAAA,EAAI,WAAA;;;;;;;;;EAoBb,aAAA,CAAc,MAAA;IAAU,SAAA;IAAmB,MAAA;IAAgB,QAAA;EAAA,KAClD,EAAA,EAAI,WAAA,KAAc,iBAAA;;;;;;;EAkB3B,WAAA,CAAY,MAAA;IAAU,SAAA;EAAA,KACb,EAAA,EAAI,WAAA,KAAc,iBAAA;;;;;;;;EAW3B,OAAA,CAAQ,MAAA;IAAU,KAAA;IAAe,QAAA;EAAA,KACxB,EAAA,EAAI,WAAA,KAAc,iBAAA;AAAA"}