@mysten/deepbook-v3 2.0.1 → 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 (272) hide show
  1. package/CHANGELOG.md +83 -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/balances.d.mts +4 -4
  28. package/dist/contracts/deepbook/deep_price.d.mts +3 -3
  29. package/dist/contracts/deepbook/deep_price.d.mts.map +1 -1
  30. package/dist/contracts/deepbook/order.d.mts +12 -12
  31. package/dist/contracts/deepbook_predict/builder_code_events.mjs +38 -0
  32. package/dist/contracts/deepbook_predict/builder_code_events.mjs.map +1 -0
  33. package/dist/contracts/deepbook_predict/config-arguments.d.mts +13 -0
  34. package/dist/contracts/deepbook_predict/config-arguments.d.mts.map +1 -0
  35. package/dist/contracts/deepbook_predict/deps/fixed_math/i64.mjs +25 -0
  36. package/dist/contracts/deepbook_predict/deps/fixed_math/i64.mjs.map +1 -0
  37. package/dist/contracts/deepbook_predict/deps/sui/balance.mjs +25 -0
  38. package/dist/contracts/deepbook_predict/deps/sui/balance.mjs.map +1 -0
  39. package/dist/contracts/deepbook_predict/deps/sui/coin.mjs +24 -0
  40. package/dist/contracts/deepbook_predict/deps/sui/coin.mjs.map +1 -0
  41. package/dist/contracts/deepbook_predict/deps/sui/table.mjs +39 -0
  42. package/dist/contracts/deepbook_predict/deps/sui/table.mjs.map +1 -0
  43. package/dist/contracts/deepbook_predict/deps/sui/vec_set.mjs +26 -0
  44. package/dist/contracts/deepbook_predict/deps/sui/vec_set.mjs.map +1 -0
  45. package/dist/contracts/deepbook_predict/ewma.mjs +29 -0
  46. package/dist/contracts/deepbook_predict/ewma.mjs.map +1 -0
  47. package/dist/contracts/deepbook_predict/expiry_cash.mjs +27 -0
  48. package/dist/contracts/deepbook_predict/expiry_cash.mjs.map +1 -0
  49. package/dist/contracts/deepbook_predict/expiry_market.mjs +367 -0
  50. package/dist/contracts/deepbook_predict/expiry_market.mjs.map +1 -0
  51. package/dist/contracts/deepbook_predict/lp_book.mjs +92 -0
  52. package/dist/contracts/deepbook_predict/lp_book.mjs.map +1 -0
  53. package/dist/contracts/deepbook_predict/market_manager.mjs +59 -0
  54. package/dist/contracts/deepbook_predict/market_manager.mjs.map +1 -0
  55. package/dist/contracts/deepbook_predict/order.mjs +26 -0
  56. package/dist/contracts/deepbook_predict/order.mjs.map +1 -0
  57. package/dist/contracts/deepbook_predict/order_events.mjs +84 -0
  58. package/dist/contracts/deepbook_predict/order_events.mjs.map +1 -0
  59. package/dist/contracts/deepbook_predict/plp.mjs +284 -0
  60. package/dist/contracts/deepbook_predict/plp.mjs.map +1 -0
  61. package/dist/contracts/deepbook_predict/pool_accounting.mjs +58 -0
  62. package/dist/contracts/deepbook_predict/pool_accounting.mjs.map +1 -0
  63. package/dist/contracts/deepbook_predict/predict_account.mjs +106 -0
  64. package/dist/contracts/deepbook_predict/predict_account.mjs.map +1 -0
  65. package/dist/contracts/deepbook_predict/pricing.mjs +80 -0
  66. package/dist/contracts/deepbook_predict/pricing.mjs.map +1 -0
  67. package/dist/contracts/deepbook_predict/range_codec.mjs +41 -0
  68. package/dist/contracts/deepbook_predict/range_codec.mjs.map +1 -0
  69. package/dist/contracts/deepbook_predict/registry.mjs +55 -0
  70. package/dist/contracts/deepbook_predict/registry.mjs.map +1 -0
  71. package/dist/contracts/deepbook_predict/strike_exposure.mjs +65 -0
  72. package/dist/contracts/deepbook_predict/strike_exposure.mjs.map +1 -0
  73. package/dist/contracts/deepbook_predict/strike_exposure_config.mjs +33 -0
  74. package/dist/contracts/deepbook_predict/strike_exposure_config.mjs.map +1 -0
  75. package/dist/contracts/deepbook_predict/strike_payout_tree.mjs +72 -0
  76. package/dist/contracts/deepbook_predict/strike_payout_tree.mjs.map +1 -0
  77. package/dist/contracts/deepbook_predict/vault_events.mjs +184 -0
  78. package/dist/contracts/deepbook_predict/vault_events.mjs.map +1 -0
  79. package/dist/contracts/deepbook_sessions/config-arguments.d.mts +10 -0
  80. package/dist/contracts/deepbook_sessions/config-arguments.d.mts.map +1 -0
  81. package/dist/contracts/deepbook_sessions/deps/sui/vec_map.mjs +37 -0
  82. package/dist/contracts/deepbook_sessions/deps/sui/vec_map.mjs.map +1 -0
  83. package/dist/contracts/deepbook_sessions/session_config.d.mts +63 -0
  84. package/dist/contracts/deepbook_sessions/session_config.d.mts.map +1 -0
  85. package/dist/contracts/deepbook_sessions/session_config.mjs +82 -0
  86. package/dist/contracts/deepbook_sessions/session_config.mjs.map +1 -0
  87. package/dist/contracts/deepbook_sessions/sessions.d.mts +275 -0
  88. package/dist/contracts/deepbook_sessions/sessions.d.mts.map +1 -0
  89. package/dist/contracts/deepbook_sessions/sessions.mjs +443 -0
  90. package/dist/contracts/deepbook_sessions/sessions.mjs.map +1 -0
  91. package/dist/contracts/utils/index.d.mts +18 -1
  92. package/dist/contracts/utils/index.d.mts.map +1 -1
  93. package/dist/deployments/index.d.mts +31 -0
  94. package/dist/deployments/index.d.mts.map +1 -0
  95. package/dist/deployments/index.mjs +30 -0
  96. package/dist/deployments/index.mjs.map +1 -0
  97. package/dist/deployments/testnet.d.mts +14 -0
  98. package/dist/deployments/testnet.d.mts.map +1 -0
  99. package/dist/deployments/testnet.mjs +73 -0
  100. package/dist/deployments/testnet.mjs.map +1 -0
  101. package/dist/deployments/types.d.mts +36 -0
  102. package/dist/deployments/types.d.mts.map +1 -0
  103. package/dist/index.mjs +0 -1
  104. package/dist/predict/client.d.mts +255 -0
  105. package/dist/predict/client.d.mts.map +1 -0
  106. package/dist/predict/client.mjs +436 -0
  107. package/dist/predict/client.mjs.map +1 -0
  108. package/dist/predict/config/generated.d.mts +29 -0
  109. package/dist/predict/config/generated.d.mts.map +1 -0
  110. package/dist/predict/config/generated.mjs +16 -0
  111. package/dist/predict/config/generated.mjs.map +1 -0
  112. package/dist/predict/config/index.d.mts +10 -0
  113. package/dist/predict/config/index.d.mts.map +1 -0
  114. package/dist/predict/config/index.mjs +13 -0
  115. package/dist/predict/config/index.mjs.map +1 -0
  116. package/dist/predict/config/testnet.d.mts +17 -0
  117. package/dist/predict/config/testnet.d.mts.map +1 -0
  118. package/dist/predict/config/testnet.mjs +26 -0
  119. package/dist/predict/config/testnet.mjs.map +1 -0
  120. package/dist/predict/config/types.d.mts +55 -0
  121. package/dist/predict/config/types.d.mts.map +1 -0
  122. package/dist/predict/decode.d.mts +162 -0
  123. package/dist/predict/decode.d.mts.map +1 -0
  124. package/dist/predict/decode.mjs +175 -0
  125. package/dist/predict/decode.mjs.map +1 -0
  126. package/dist/predict/errors.d.mts +42 -0
  127. package/dist/predict/errors.d.mts.map +1 -0
  128. package/dist/predict/errors.mjs +37 -0
  129. package/dist/predict/errors.mjs.map +1 -0
  130. package/dist/predict/index.d.mts +18 -0
  131. package/dist/predict/index.mjs +14 -0
  132. package/dist/predict/pricing.d.mts +73 -0
  133. package/dist/predict/pricing.d.mts.map +1 -0
  134. package/dist/predict/pricing.mjs +129 -0
  135. package/dist/predict/pricing.mjs.map +1 -0
  136. package/dist/predict/reads/balances.mjs +41 -0
  137. package/dist/predict/reads/balances.mjs.map +1 -0
  138. package/dist/predict/reads/inspect.d.mts +8 -0
  139. package/dist/predict/reads/inspect.d.mts.map +1 -0
  140. package/dist/predict/reads/inspect.mjs +37 -0
  141. package/dist/predict/reads/inspect.mjs.map +1 -0
  142. package/dist/predict/reads/markets.mjs +130 -0
  143. package/dist/predict/reads/markets.mjs.map +1 -0
  144. package/dist/predict/reads/parse.mjs +20 -0
  145. package/dist/predict/reads/parse.mjs.map +1 -0
  146. package/dist/predict/reads/pool.mjs +26 -0
  147. package/dist/predict/reads/pool.mjs.map +1 -0
  148. package/dist/predict/reads/positions.d.mts +12 -0
  149. package/dist/predict/reads/positions.d.mts.map +1 -0
  150. package/dist/predict/reads/positions.mjs +77 -0
  151. package/dist/predict/reads/positions.mjs.map +1 -0
  152. package/dist/predict/reads/pricing.d.mts +20 -0
  153. package/dist/predict/reads/pricing.d.mts.map +1 -0
  154. package/dist/predict/reads/pricing.mjs +43 -0
  155. package/dist/predict/reads/pricing.mjs.map +1 -0
  156. package/dist/predict/ticks.d.mts +11 -0
  157. package/dist/predict/ticks.d.mts.map +1 -0
  158. package/dist/predict/ticks.mjs +21 -0
  159. package/dist/predict/ticks.mjs.map +1 -0
  160. package/dist/predict/tx/authed.mjs +18 -0
  161. package/dist/predict/tx/authed.mjs.map +1 -0
  162. package/dist/predict/tx/common.d.mts +18 -0
  163. package/dist/predict/tx/common.d.mts.map +1 -0
  164. package/dist/predict/tx/common.mjs +52 -0
  165. package/dist/predict/tx/common.mjs.map +1 -0
  166. package/dist/predict/tx/trade.d.mts +15 -0
  167. package/dist/predict/tx/trade.d.mts.map +1 -0
  168. package/dist/predict/tx/trade.mjs +86 -0
  169. package/dist/predict/tx/trade.mjs.map +1 -0
  170. package/dist/predict/units.d.mts +11 -0
  171. package/dist/predict/units.d.mts.map +1 -0
  172. package/dist/predict/units.mjs +44 -0
  173. package/dist/predict/units.mjs.map +1 -0
  174. package/dist/queries/accountQueries.mjs +0 -1
  175. package/dist/queries/accountQueries.mjs.map +1 -1
  176. package/dist/queries/orderQueries.mjs +0 -1
  177. package/dist/queries/orderQueries.mjs.map +1 -1
  178. package/dist/queries/registryQueries.mjs +0 -1
  179. package/dist/queries/registryQueries.mjs.map +1 -1
  180. package/dist/sessions.d.mts +244 -0
  181. package/dist/sessions.d.mts.map +1 -0
  182. package/dist/sessions.mjs +291 -0
  183. package/dist/sessions.mjs.map +1 -0
  184. package/dist/transactions/balanceManager.d.mts +12 -12
  185. package/dist/transactions/balanceManager.d.mts.map +1 -1
  186. package/dist/transactions/deepbook.d.mts +20 -20
  187. package/dist/transactions/deepbook.d.mts.map +1 -1
  188. package/dist/transactions/deepbookAdmin.d.mts +4 -4
  189. package/dist/transactions/marginAdmin.d.mts +7 -7
  190. package/dist/transactions/marginLiquidations.d.mts +3 -3
  191. package/dist/transactions/marginMaintainer.d.mts +5 -5
  192. package/dist/transactions/marginManager.d.mts +32 -32
  193. package/dist/transactions/marginPool.d.mts +18 -18
  194. package/dist/transactions/marginRegistry.d.mts +16 -16
  195. package/dist/transactions/marginTPSL.d.mts +10 -10
  196. package/dist/transactions/poolProxy.d.mts +8 -8
  197. package/package.json +25 -4
  198. package/src/account.ts +239 -0
  199. package/src/bcs/integers.ts +35 -0
  200. package/src/contracts/account/account.ts +706 -0
  201. package/src/contracts/account/account_events.ts +64 -0
  202. package/src/contracts/account/account_registry.ts +468 -0
  203. package/src/contracts/account/config-arguments.ts +8 -0
  204. package/src/contracts/account/deps/sui/bag.ts +42 -0
  205. package/src/contracts/deepbook_predict/admin.ts +44 -0
  206. package/src/contracts/deepbook_predict/builder_code.ts +155 -0
  207. package/src/contracts/deepbook_predict/builder_code_events.ts +34 -0
  208. package/src/contracts/deepbook_predict/config-arguments.ts +11 -0
  209. package/src/contracts/deepbook_predict/config_events.ts +140 -0
  210. package/src/contracts/deepbook_predict/deps/fixed_math/i64.ts +21 -0
  211. package/src/contracts/deepbook_predict/deps/sui/balance.ts +25 -0
  212. package/src/contracts/deepbook_predict/deps/sui/coin.ts +20 -0
  213. package/src/contracts/deepbook_predict/deps/sui/table.ts +37 -0
  214. package/src/contracts/deepbook_predict/deps/sui/vec_set.ts +22 -0
  215. package/src/contracts/deepbook_predict/ewma.ts +26 -0
  216. package/src/contracts/deepbook_predict/ewma_config.ts +28 -0
  217. package/src/contracts/deepbook_predict/expiry_cash.ts +24 -0
  218. package/src/contracts/deepbook_predict/expiry_market.ts +1549 -0
  219. package/src/contracts/deepbook_predict/lp_book.ts +105 -0
  220. package/src/contracts/deepbook_predict/market_lifecycle_cap.ts +75 -0
  221. package/src/contracts/deepbook_predict/market_manager.ts +218 -0
  222. package/src/contracts/deepbook_predict/order.ts +24 -0
  223. package/src/contracts/deepbook_predict/order_events.ts +129 -0
  224. package/src/contracts/deepbook_predict/pause_cap.ts +68 -0
  225. package/src/contracts/deepbook_predict/plp.ts +987 -0
  226. package/src/contracts/deepbook_predict/pool_accounting.ts +79 -0
  227. package/src/contracts/deepbook_predict/predict_account.ts +180 -0
  228. package/src/contracts/deepbook_predict/pricing.ts +124 -0
  229. package/src/contracts/deepbook_predict/pricing_config.ts +41 -0
  230. package/src/contracts/deepbook_predict/protocol_config.ts +1066 -0
  231. package/src/contracts/deepbook_predict/range_codec.ts +53 -0
  232. package/src/contracts/deepbook_predict/registry.ts +694 -0
  233. package/src/contracts/deepbook_predict/strike_exposure.ts +77 -0
  234. package/src/contracts/deepbook_predict/strike_exposure_config.ts +46 -0
  235. package/src/contracts/deepbook_predict/strike_payout_tree.ts +89 -0
  236. package/src/contracts/deepbook_predict/vault_events.ts +222 -0
  237. package/src/contracts/deepbook_sessions/config-arguments.ts +8 -0
  238. package/src/contracts/deepbook_sessions/deps/sui/vec_map.ts +33 -0
  239. package/src/contracts/deepbook_sessions/session_config.ts +130 -0
  240. package/src/contracts/deepbook_sessions/sessions.ts +663 -0
  241. package/src/contracts/propbook/block_scholes_store.ts +842 -0
  242. package/src/contracts/propbook/deps/sui/table.ts +37 -0
  243. package/src/contracts/propbook/oracle_lane.ts +170 -0
  244. package/src/contracts/propbook/pyth_feed.ts +414 -0
  245. package/src/contracts/propbook/registry.ts +596 -0
  246. package/src/deployments/index.ts +73 -0
  247. package/src/deployments/testnet.ts +107 -0
  248. package/src/deployments/types.ts +81 -0
  249. package/src/index.ts +5 -0
  250. package/src/predict/client.ts +941 -0
  251. package/src/predict/config/generated.ts +39 -0
  252. package/src/predict/config/index.ts +25 -0
  253. package/src/predict/config/testnet.ts +27 -0
  254. package/src/predict/config/types.ts +52 -0
  255. package/src/predict/decode.ts +476 -0
  256. package/src/predict/errors.ts +83 -0
  257. package/src/predict/index.ts +94 -0
  258. package/src/predict/pricing.ts +199 -0
  259. package/src/predict/reads/balances.ts +55 -0
  260. package/src/predict/reads/inspect.ts +78 -0
  261. package/src/predict/reads/markets.ts +222 -0
  262. package/src/predict/reads/parse.ts +30 -0
  263. package/src/predict/reads/pool.ts +37 -0
  264. package/src/predict/reads/positions.ts +144 -0
  265. package/src/predict/reads/pricing.ts +79 -0
  266. package/src/predict/ticks.ts +42 -0
  267. package/src/predict/tx/authed.ts +20 -0
  268. package/src/predict/tx/common.ts +92 -0
  269. package/src/predict/tx/trade.ts +183 -0
  270. package/src/predict/units.ts +49 -0
  271. package/src/sessions.ts +471 -0
  272. package/dist/types/bcs.mjs +0 -7
@@ -0,0 +1,436 @@
1
+ import { TESTNET_PREDICT } from "../deployments/testnet.mjs";
2
+ import { getConfig } from "./config/index.mjs";
3
+ import { toGeneratedConfig } from "./config/generated.mjs";
4
+ import { PredictInputError } from "./errors.mjs";
5
+ import { fromRaw, priceToRaw, probabilityToRaw, rawToProbability, rawToUsdc, usdcToRaw } from "./units.mjs";
6
+ import { decodeAccountsCreated, decodeBuilderCodeSets, decodeClaims, decodeDeposits, decodeMints, decodePlpCancels, decodePlpRequests, decodeRedeems, decodeWithdrawals, exactlyOne } from "./decode.mjs";
7
+ import { simulateWithEvents } from "./reads/inspect.mjs";
8
+ import { accountContract, deriveAccountWrapperIdFrom } from "./tx/common.mjs";
9
+ import { positionsFromTable, resolvePositionsTable } from "./reads/positions.mjs";
10
+ import { accountBalance, hasPosition } from "./reads/balances.mjs";
11
+ import { POS_INF_TICK, binaryRangeTicks } from "./ticks.mjs";
12
+ import { mintExactAmount, mintExactQuantity, redeemLive, redeemSettled } from "./tx/trade.mjs";
13
+ import { activeMarketIds, currentNav, expiryMarketId, marketState, marketStates, rangePrices, referenceTick } from "./reads/markets.mjs";
14
+ import { poolStats } from "./reads/pool.mjs";
15
+ import { readPricerSnapshot } from "./reads/pricing.mjs";
16
+ import { boardPricer } from "./pricing.mjs";
17
+ import { cancelSupplyRequest, cancelWithdrawRequest, depositFunds, requestSupply, requestWithdraw, setBuilderCode, unsetBuilderCode, withdrawFunds } from "./tx/authed.mjs";
18
+ import { Transaction, coinWithBalance } from "@mysten/sui/transactions";
19
+ import { isValidSuiObjectId } from "@mysten/sui/utils";
20
+
21
+ //#region src/predict/client.ts
22
+ /**
23
+ * Testnet's `position_lot_size`, read from the deployment record. Validation uses the lot
24
+ * size of the config actually in play; this is the convenience constant for testnet callers.
25
+ */
26
+ const POSITION_LOT_SIZE = BigInt(TESTNET_PREDICT.units.positionLotSize);
27
+ function txOf(command) {
28
+ const tx = new Transaction();
29
+ tx.add(command);
30
+ return tx;
31
+ }
32
+ /**
33
+ * Register PredictClient as a `client.predict` extension, mirroring
34
+ * `@mysten/deepbook-v3`'s `deepbook(...)`: `client.$extend(predict({ network }))`.
35
+ */
36
+ function predict({ name = "predict", network, config }) {
37
+ return {
38
+ name,
39
+ register: (client) => new PredictClient({
40
+ client,
41
+ network,
42
+ config
43
+ })
44
+ };
45
+ }
46
+ /**
47
+ * The one object an app constructs. Wraps the config, a client for reads, and
48
+ * a derived-account model so callers pass owner addresses, decimal amounts, and
49
+ * human market coordinates — the facade converts to raw units, resolves markets
50
+ * (cached), and delegates to the internal tx primitives / reads. Callers who need
51
+ * to compose their own PTBs can use the generated bindings under `contracts/`.
52
+ */
53
+ var PredictClient = class PredictClient {
54
+ get #config() {
55
+ return toGeneratedConfig(this.cfg);
56
+ }
57
+ #client;
58
+ #marketCache = /* @__PURE__ */ new Map();
59
+ #positionsCache = /* @__PURE__ */ new Map();
60
+ constructor(opts) {
61
+ this.tx = {
62
+ createManager: () => txOf(accountContract(this.cfg).createAccount()),
63
+ deposit: (owner, amountUsdc, opts$1) => {
64
+ const tx = new Transaction();
65
+ const coin = tx.add(coinWithBalance({
66
+ type: this.cfg.quoteCoinType,
67
+ balance: usdcToRaw(amountUsdc),
68
+ useGasCoin: false
69
+ }));
70
+ if (opts$1?.create) tx.add(accountContract(this.cfg).createAccountAndDeposit({
71
+ coin,
72
+ coinType: this.cfg.quoteCoinType
73
+ }));
74
+ else tx.add(depositFunds({
75
+ config: this.#config,
76
+ arguments: {
77
+ wrapper: this.wrapperIdFor(owner),
78
+ coin
79
+ },
80
+ typeArguments: [this.cfg.quoteCoinType]
81
+ }));
82
+ return tx;
83
+ },
84
+ withdraw: (owner, amountUsdc, opts$1) => {
85
+ const tx = new Transaction();
86
+ const coin = tx.add(withdrawFunds({
87
+ config: this.#config,
88
+ arguments: {
89
+ wrapper: this.wrapperIdFor(owner),
90
+ amount: usdcToRaw(amountUsdc)
91
+ },
92
+ typeArguments: [this.cfg.quoteCoinType]
93
+ }));
94
+ if (opts$1?.toCoinObject) tx.transferObjects([coin], owner);
95
+ else tx.moveCall({
96
+ target: "0x2::coin::send_funds",
97
+ typeArguments: [this.cfg.quoteCoinType],
98
+ arguments: [coin, tx.pure.address(owner)]
99
+ });
100
+ return tx;
101
+ },
102
+ mint: (owner, m, opts$1) => this.#buildMint(owner, m, opts$1),
103
+ mintAmount: async (owner, m, opts$1) => {
104
+ const feeds = this.#feeds(m.underlying);
105
+ if (opts$1.maxCost != null && opts$1.maxCost <= 0) throw new PredictInputError("maxCost must be > 0");
106
+ const { id, state } = await this.#resolveMarket(m);
107
+ const minQuantityRaw = usdcToRaw(opts$1.minQuantity);
108
+ const { lowerTick, higherTick } = await this.#strikeTicks(m, id, state);
109
+ return txOf(mintExactAmount(this.#config, {
110
+ expiryMarketId: id,
111
+ wrapperId: this.wrapperIdFor(owner),
112
+ lowerTick,
113
+ higherTick,
114
+ maxPremiumRaw: usdcToRaw(opts$1.spend),
115
+ minQuantityRaw,
116
+ maxCostRaw: opts$1.maxCost != null ? usdcToRaw(opts$1.maxCost) : void 0,
117
+ ...feeds
118
+ }));
119
+ },
120
+ redeem: (owner, m, opts$1) => this.#buildRedeem(owner, m, opts$1),
121
+ claimSettled: async (owner, m, opts$1) => {
122
+ const { id } = await this.#resolveMarket(m);
123
+ return txOf(redeemSettled(this.#config, {
124
+ expiryMarketId: id,
125
+ wrapperId: this.wrapperIdFor(owner),
126
+ orderId: opts$1.orderId
127
+ }));
128
+ },
129
+ supplyPlp: (owner, amountUsdc) => txOf(requestSupply({
130
+ config: this.#config,
131
+ arguments: {
132
+ wrapper: this.wrapperIdFor(owner),
133
+ amount: usdcToRaw(amountUsdc),
134
+ minPlpOut: 0n
135
+ }
136
+ })),
137
+ withdrawPlp: (owner, shares) => txOf(requestWithdraw({
138
+ config: this.#config,
139
+ arguments: {
140
+ wrapper: this.wrapperIdFor(owner),
141
+ amount: shares,
142
+ minDusdcOut: 0n
143
+ }
144
+ })),
145
+ cancelSupplyPlp: (owner, index) => txOf(cancelSupplyRequest({
146
+ config: this.#config,
147
+ arguments: {
148
+ wrapper: this.wrapperIdFor(owner),
149
+ index
150
+ }
151
+ })),
152
+ cancelWithdrawPlp: (owner, index) => txOf(cancelWithdrawRequest({
153
+ config: this.#config,
154
+ arguments: {
155
+ wrapper: this.wrapperIdFor(owner),
156
+ index
157
+ }
158
+ })),
159
+ setBuilderCode: (owner, builderCodeId) => txOf(setBuilderCode({
160
+ config: this.#config,
161
+ arguments: {
162
+ wrapper: this.wrapperIdFor(owner),
163
+ code: builderCodeId
164
+ }
165
+ })),
166
+ unsetBuilderCode: (owner) => txOf(unsetBuilderCode({
167
+ config: this.#config,
168
+ arguments: { wrapper: this.wrapperIdFor(owner) }
169
+ }))
170
+ };
171
+ this.read = {
172
+ markets: async () => {
173
+ const ids = await activeMarketIds(this.#client, this.#config);
174
+ const states = await marketStates(this.#client, this.#config, ids);
175
+ return ids.map((id, i) => ({
176
+ id,
177
+ expiryMs: states[i].expiryMs,
178
+ tickSize: fromRaw(states[i].tickSizeRaw, 9),
179
+ admissionTickSize: fromRaw(states[i].admissionTickSizeRaw, 9),
180
+ mintPaused: states[i].mintPaused,
181
+ referencePrice: PredictClient.#referencePriceOf(states[i])
182
+ }));
183
+ },
184
+ hasPosition: (owner, marketId, orderId) => hasPosition(this.#client, this.#config, owner, marketId, orderId),
185
+ positions: async (owner) => {
186
+ let handle = this.#positionsCache.get(owner);
187
+ if (!handle?.positionsTableId) {
188
+ const resolved = await resolvePositionsTable(this.#client, this.#config, owner);
189
+ if (!resolved) return [];
190
+ if (resolved.positionsTableId) this.#positionsCache.set(owner, resolved);
191
+ handle = resolved;
192
+ }
193
+ if (!handle.positionsTableId) return [];
194
+ return positionsFromTable(this.#client, handle.positionsTableId);
195
+ },
196
+ price: async (m) => {
197
+ const feeds = this.#feeds(m.underlying);
198
+ const { id, state } = await this.#resolveMarket(m);
199
+ const strikeRaw = await this.#strikeRawFor(m, id, state);
200
+ const { upRaw, downRaw } = await rangePrices(this.#client, this.#config, id, feeds, strikeRaw, state.tickSizeRaw);
201
+ return {
202
+ up: rawToProbability(upRaw),
203
+ down: rawToProbability(downRaw)
204
+ };
205
+ },
206
+ pricer: async (m) => {
207
+ const feeds = this.#feeds(m.underlying);
208
+ const { id } = await this.#resolveMarket(m);
209
+ const snap = await readPricerSnapshot(this.#client, this.#config, id, feeds);
210
+ return {
211
+ ...boardPricer(snap),
212
+ asOf: snap.sources
213
+ };
214
+ },
215
+ quoteMint: async (owner, m, opts$1) => {
216
+ const tx = await this.#buildMint(owner, m, opts$1);
217
+ const events = await simulateWithEvents(this.#client, tx, owner);
218
+ const r = exactlyOne(decodeMints(this.cfg, { events }), "OrderMinted");
219
+ const costRaw = r.raw.premium + (r.raw.tradingFee - r.raw.feeIncentiveSubsidy) + r.raw.builderFee + r.raw.penaltyFee + r.raw.inventoryImpactCharge;
220
+ return {
221
+ entryProbability: r.entryProbability,
222
+ premium: r.premium,
223
+ fees: r.fees,
224
+ cost: rawToUsdc(costRaw),
225
+ quantity: r.quantity,
226
+ raw: {
227
+ premium: r.raw.premium,
228
+ cost: costRaw,
229
+ quantity: r.raw.quantity,
230
+ entryProbability: r.raw.entryProbability
231
+ },
232
+ feesExact: true
233
+ };
234
+ },
235
+ quoteRedeem: async (owner, m, opts$1) => {
236
+ const tx = await this.#buildRedeem(owner, m, opts$1);
237
+ const events = await simulateWithEvents(this.#client, tx, owner);
238
+ const r = exactlyOne(decodeRedeems(this.cfg, { events }), "order-redeemed");
239
+ return {
240
+ proceeds: r.proceeds,
241
+ gross: r.gross,
242
+ fees: r.fees,
243
+ quantityClosed: r.quantityClosed,
244
+ remaining: r.remaining,
245
+ raw: {
246
+ proceeds: r.raw.proceeds,
247
+ gross: r.raw.gross,
248
+ quantityClosed: r.raw.quantityClosed
249
+ },
250
+ feesExact: true
251
+ };
252
+ },
253
+ market: async (m) => {
254
+ const expiryMs = BigInt(m.expiryMs);
255
+ const u = this.#underlying(m.underlying);
256
+ const id = await expiryMarketId(this.#client, this.#config, u, expiryMs);
257
+ if (!id) return null;
258
+ const state = await marketState(this.#client, this.#config, id);
259
+ this.#marketCache.set(`${m.underlying}:${expiryMs}`, {
260
+ id,
261
+ state
262
+ });
263
+ const navRaw = await currentNav(this.#client, this.#config, id, u);
264
+ return {
265
+ id,
266
+ expiryMs: state.expiryMs,
267
+ tickSize: fromRaw(state.tickSizeRaw, 9),
268
+ admissionTickSize: fromRaw(state.admissionTickSizeRaw, 9),
269
+ mintPaused: state.mintPaused,
270
+ nav: rawToUsdc(navRaw),
271
+ referencePrice: PredictClient.#referencePriceOf(state)
272
+ };
273
+ },
274
+ balance: async (owner) => rawToUsdc(await accountBalance(this.#client, this.#config, owner, this.cfg.quoteCoinType)),
275
+ plpBalance: (owner) => accountBalance(this.#client, this.#config, owner, this.cfg.coinTypes.plp),
276
+ pool: async () => {
277
+ const s = await poolStats(this.#client, this.#config);
278
+ return {
279
+ plpTotalSupply: s.plpTotalSupply,
280
+ idleUsdc: rawToUsdc(s.idleBalance),
281
+ supplyRequestsPending: Number(s.supplyRequestsPending),
282
+ withdrawRequestsPending: Number(s.withdrawRequestsPending)
283
+ };
284
+ }
285
+ };
286
+ this.decode = {
287
+ mint: (r) => exactlyOne(decodeMints(this.cfg, r), "OrderMinted"),
288
+ mints: (r) => decodeMints(this.cfg, r),
289
+ redeem: (r) => exactlyOne(decodeRedeems(this.cfg, r), "order-redeemed"),
290
+ redeems: (r) => decodeRedeems(this.cfg, r),
291
+ claim: (r) => exactlyOne(decodeClaims(this.cfg, r), "SettledOrderRedeemed"),
292
+ claims: (r) => decodeClaims(this.cfg, r),
293
+ createManager: (r) => exactlyOne(decodeAccountsCreated(this.cfg, r), "AccountCreated"),
294
+ deposit: (r) => exactlyOne(decodeDeposits(this.cfg, r), "Deposited"),
295
+ withdraw: (r) => exactlyOne(decodeWithdrawals(this.cfg, r), "Withdrawn"),
296
+ plpRequest: (r) => exactlyOne(decodePlpRequests(this.cfg, r), "supply/withdraw-requested"),
297
+ plpCancel: (r) => exactlyOne(decodePlpCancels(this.cfg, r), "RequestCancelled"),
298
+ builderCode: (r) => exactlyOne(decodeBuilderCodeSets(this.cfg, r), "BuilderCodeSet")
299
+ };
300
+ this.cfg = opts.config ?? getConfig(opts.network);
301
+ this.#client = opts.client;
302
+ }
303
+ /** The deterministic id of an owner's canonical account wrapper — no chain read. */
304
+ wrapperIdFor(owner) {
305
+ return deriveAccountWrapperIdFrom(this.#config, owner);
306
+ }
307
+ #underlying(underlying) {
308
+ const u = this.cfg.underlyings[underlying];
309
+ if (!u) throw new PredictInputError(`unknown underlying: ${underlying}`);
310
+ return u;
311
+ }
312
+ #feeds(underlying) {
313
+ const u = this.#underlying(underlying);
314
+ return {
315
+ pythFeed: u.pythFeed,
316
+ blockScholesValueStore: u.blockScholesValueStore,
317
+ blockScholesSviStore: u.blockScholesSviStore
318
+ };
319
+ }
320
+ async #resolveMarket(m) {
321
+ if (m.marketId != null) {
322
+ if (!isValidSuiObjectId(m.marketId)) throw new PredictInputError(`invalid marketId: ${JSON.stringify(m.marketId)}`);
323
+ const resolved$1 = this.#marketCache.get(m.marketId) ?? {
324
+ id: m.marketId,
325
+ state: await marketState(this.#client, this.#config, m.marketId)
326
+ };
327
+ if (resolved$1.state.expiryMs !== BigInt(m.expiryMs)) throw new PredictInputError(`pinned market ${m.marketId} expires at ${resolved$1.state.expiryMs}, descriptor says ${BigInt(m.expiryMs)}`);
328
+ this.#marketCache.set(m.marketId, resolved$1);
329
+ return resolved$1;
330
+ }
331
+ const expiryMs = BigInt(m.expiryMs);
332
+ const key = `${m.underlying}:${expiryMs}`;
333
+ const hit = this.#marketCache.get(key);
334
+ if (hit) return hit;
335
+ const u = this.#underlying(m.underlying);
336
+ const id = await expiryMarketId(this.#client, this.#config, u, expiryMs);
337
+ if (!id) throw new PredictInputError(`no market for ${m.underlying} at expiry ${expiryMs}`);
338
+ const resolved = {
339
+ id,
340
+ state: await marketState(this.#client, this.#config, id)
341
+ };
342
+ this.#marketCache.set(key, resolved);
343
+ return resolved;
344
+ }
345
+ static #referencePriceOf(state) {
346
+ return state.referenceTickRaw == null ? null : fromRaw(state.referenceTickRaw * state.tickSizeRaw, 9);
347
+ }
348
+ #gridTick(strike, tickSizeRaw) {
349
+ const raw = priceToRaw(strike);
350
+ const tick = raw / tickSizeRaw;
351
+ if (tick * tickSizeRaw !== raw) throw new PredictInputError(`strike ${strike} is not on the ${fromRaw(tickSizeRaw, 9)} tick grid`);
352
+ if (tick <= 0n || tick >= POS_INF_TICK) throw new PredictInputError(`strike tick ${tick} outside the finite tick domain (1..POS_INF_TICK-1)`);
353
+ return tick;
354
+ }
355
+ async #assertAdmittedTick(tick, marketId, state) {
356
+ if (tick === 0n || tick === POS_INF_TICK) return;
357
+ const multiple = state.admissionTickSizeRaw / state.tickSizeRaw;
358
+ if (multiple > 0n && tick % multiple === 0n) return;
359
+ const reference = await referenceTick(this.#client, this.#config, marketId);
360
+ if (reference != null && reference === tick) return;
361
+ const admission = fromRaw(state.admissionTickSizeRaw, 9);
362
+ throw new PredictInputError(`strike ${fromRaw(tick * state.tickSizeRaw, 9)} is not on the ${admission} admission grid (mint boundaries must be a multiple of ${admission}, or the market's reference strike)`);
363
+ }
364
+ async #strikeTicks(m, marketId, state) {
365
+ if (m.side === "range") {
366
+ if (!(m.lower < m.upper)) throw new PredictInputError(`range lower ${m.lower} must be below upper ${m.upper}`);
367
+ const lowerTick = this.#gridTick(m.lower, state.tickSizeRaw);
368
+ const higherTick = this.#gridTick(m.upper, state.tickSizeRaw);
369
+ await this.#assertAdmittedTick(lowerTick, marketId, state);
370
+ await this.#assertAdmittedTick(higherTick, marketId, state);
371
+ return {
372
+ lowerTick,
373
+ higherTick
374
+ };
375
+ }
376
+ if (m.strike !== "reference") {
377
+ const ticks = binaryRangeTicks(priceToRaw(m.strike), m.side, state.tickSizeRaw);
378
+ await this.#assertAdmittedTick(ticks.lowerTick, marketId, state);
379
+ await this.#assertAdmittedTick(ticks.higherTick, marketId, state);
380
+ return ticks;
381
+ }
382
+ const tick = await referenceTick(this.#client, this.#config, marketId);
383
+ if (tick == null) throw new PredictInputError(`reference price not set yet for ${m.underlying} @ ${m.expiryMs} — retry shortly or pass a numeric strike`);
384
+ return m.side === "up" ? {
385
+ lowerTick: tick,
386
+ higherTick: POS_INF_TICK
387
+ } : {
388
+ lowerTick: 0n,
389
+ higherTick: tick
390
+ };
391
+ }
392
+ #assertLot(quantityRaw) {
393
+ const lot = BigInt(this.cfg.units.positionLotSize);
394
+ if (quantityRaw % lot !== 0n) throw new PredictInputError(`quantity ${quantityRaw} raw is not a whole ${lot}-unit lot (position_lot_size)`);
395
+ }
396
+ async #buildMint(owner, m, opts) {
397
+ const feeds = this.#feeds(m.underlying);
398
+ const { id, state } = await this.#resolveMarket(m);
399
+ const quantityRaw = usdcToRaw(opts.quantity);
400
+ this.#assertLot(quantityRaw);
401
+ const { lowerTick, higherTick } = await this.#strikeTicks(m, id, state);
402
+ return txOf(mintExactQuantity(this.#config, {
403
+ expiryMarketId: id,
404
+ wrapperId: this.wrapperIdFor(owner),
405
+ lowerTick,
406
+ higherTick,
407
+ quantityRaw,
408
+ maxCostRaw: opts.maxCost != null ? usdcToRaw(opts.maxCost) : void 0,
409
+ maxProbabilityRaw: opts.maxProbability != null ? probabilityToRaw(opts.maxProbability) : void 0,
410
+ ...feeds
411
+ }));
412
+ }
413
+ async #buildRedeem(owner, m, opts) {
414
+ const feeds = this.#feeds(m.underlying);
415
+ const { id } = await this.#resolveMarket(m);
416
+ const closeQuantityRaw = usdcToRaw(opts.quantity);
417
+ this.#assertLot(closeQuantityRaw);
418
+ return txOf(redeemLive(this.#config, {
419
+ expiryMarketId: id,
420
+ wrapperId: this.wrapperIdFor(owner),
421
+ orderId: opts.orderId,
422
+ closeQuantityRaw,
423
+ ...feeds
424
+ }));
425
+ }
426
+ async #strikeRawFor(m, marketId, state) {
427
+ if (m.strike !== "reference") return this.#gridTick(m.strike, state.tickSizeRaw) * state.tickSizeRaw;
428
+ const tick = await referenceTick(this.#client, this.#config, marketId);
429
+ if (tick == null) throw new PredictInputError(`reference price not set yet for ${m.underlying} @ ${m.expiryMs} — retry shortly or pass a numeric strike`);
430
+ return tick * state.tickSizeRaw;
431
+ }
432
+ };
433
+
434
+ //#endregion
435
+ export { POSITION_LOT_SIZE, PredictClient, predict };
436
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":["#config","opts","#buildMint","#feeds","#resolveMarket","#strikeTicks","#buildRedeem","#client","#referencePriceOf","#positionsCache","#strikeRawFor","#underlying","#marketCache","resolved","#assertAdmittedTick","#gridTick","#assertLot"],"sources":["../../src/predict/client.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { ClientWithCoreApi, SuiClientRegistration } from '@mysten/sui/client';\nimport { Transaction, coinWithBalance, type TransactionResult } from '@mysten/sui/transactions';\nimport { isValidSuiObjectId } from '@mysten/sui/utils';\nimport { TESTNET_PREDICT } from '../deployments/testnet.js';\nimport { getConfig, type PredictConfig, type UnderlyingConfig } from './config/index.js';\nimport { toGeneratedConfig, type GeneratedConfig } from './config/generated.js';\nimport {\n\tdecodeAccountsCreated,\n\tdecodeBuilderCodeSets,\n\tdecodeClaims,\n\tdecodeDeposits,\n\tdecodeMints,\n\tdecodePlpCancels,\n\tdecodePlpRequests,\n\tdecodeRedeems,\n\tdecodeWithdrawals,\n\texactlyOne,\n\ttype DecodableTransactionResult,\n} from './decode.js';\nimport { PredictInputError } from './errors.js';\nimport { simulateWithEvents } from './reads/inspect.js';\nimport {\n\tpositionsFromTable,\n\tresolvePositionsTable,\n\ttype OpenPosition,\n\ttype PositionsHandle,\n} from './reads/positions.js';\nimport { accountBalance, hasPosition } from './reads/balances.js';\nimport {\n\tactiveMarketIds,\n\tcurrentNav,\n\texpiryMarketId,\n\tmarketState,\n\tmarketStates,\n\trangePrices,\n\treferenceTick,\n\ttype MarketState,\n} from './reads/markets.js';\nimport { poolStats } from './reads/pool.js';\nimport { readPricerSnapshot, type PricerSnapshot } from './reads/pricing.js';\nimport { boardPricer, type BoardPricer } from './pricing.js';\nimport { POS_INF_TICK, binaryRangeTicks, type Side } from './ticks.js';\nimport {\n\tcancelSupplyRequest,\n\tcancelWithdrawRequest,\n\tdepositFunds,\n\trequestSupply,\n\trequestWithdraw,\n\tsetBuilderCode,\n\tunsetBuilderCode,\n\twithdrawFunds,\n} from './tx/authed.js';\n\nimport { accountContract, deriveAccountWrapperIdFrom } from './tx/common.js';\nimport type { MarketFeeds } from './tx/trade.js';\nimport { mintExactAmount, mintExactQuantity, redeemLive, redeemSettled } from './tx/trade.js';\nimport {\n\tpriceToRaw,\n\tprobabilityToRaw,\n\trawToProbability,\n\trawToUsdc,\n\tusdcToRaw,\n\tfromRaw,\n} from './units.js';\n\n// `position_lot_size` — a position quantity must be a whole multiple of this many\n// raw payout units ($0.01 lots). See packages/predict/sources/constants.move.\n/**\n * Testnet's `position_lot_size`, read from the deployment record. Validation uses the lot\n * size of the config actually in play; this is the convenience constant for testnet callers.\n */\nexport const POSITION_LOT_SIZE = BigInt(TESTNET_PREDICT.units.positionLotSize);\n\n// Most `tx.*` builders are one builder's worth of commands in a fresh PTB.\nfunction txOf(command: (tx: Transaction) => TransactionResult | void): Transaction {\n\tconst tx = new Transaction();\n\ttx.add(command);\n\treturn tx;\n}\n\n/** A live/settled market addressed by its human coordinates: a binary position\n * (single strike + side) or a two-strike range position. */\nexport type MarketDescriptor = {\n\tunderlying: string;\n\texpiryMs: number | bigint;\n\t/**\n\t * Pin resolution to this exact `ExpiryMarket` object, skipping the\n\t * underlying+expiry lookup — a caller that reviewed a specific market object\n\t * mints against exactly that object, not whatever resolves at submit time.\n\t */\n\tmarketId?: string;\n} & (\n\t| {\n\t\t\tside: Side;\n\t\t\t/**\n\t\t\t * Strike in USD, or \"reference\" to trade at the market's on-chain reference\n\t\t\t * price (the Polymarket-style anchor: derived from the exact previous-window\n\t\t\t * oracle observation, so consecutive windows chain settlement → next strike).\n\t\t\t */\n\t\t\tstrike: number | 'reference';\n\t }\n\t| {\n\t\t\t/** A range position: pays out when settlement lands inside `(lower, upper]`\n\t\t\t * (left-open, right-closed — same convention as the on-chain range key). */\n\t\t\tside: 'range';\n\t\t\t/** Lower strike bound in USD — finite, on the tick grid. */\n\t\t\tlower: number;\n\t\t\t/** Upper strike bound in USD — finite, on the tick grid, above `lower`. */\n\t\t\tupper: number;\n\t }\n);\n\n/** Options for the friendly `mint` (exact payout quantity). */\nexport interface MintOptions {\n\tquantity: number;\n\tmaxCost?: number;\n\tmaxProbability?: number;\n}\n\n/** Options for `mintAmount` (spend up to a premium budget, floor the quantity received). */\nexport interface MintAmountOptions {\n\t/** Premium budget in quote units — the max premium paid (chain also caps it at the account balance). */\n\tspend: number;\n\tminQuantity: number;\n\t/** All-in cost ceiling in quote units (premium + fees). Omitted → uncapped. */\n\tmaxCost?: number;\n}\n\n/** Options for `redeem`: which order and how much to close. `claimSettled` takes only\n * `orderId` — a settled claim closes the order in full. */\nexport interface CloseOptions {\n\torderId: bigint;\n\tquantity: number;\n}\n\n/** One tradeable market as returned by read.markets(). */\nexport interface ActiveMarket {\n\tid: string;\n\texpiryMs: bigint;\n\t/** Strike granularity in USD (e.g. 0.01). */\n\ttickSize: number;\n\t/**\n\t * Coarser step new mint strikes must align to. A numeric strike must be a whole\n\t * multiple of this (the market's `referencePrice` is the one exception the chain\n\t * admits off-grid); otherwise the mint aborts `EInvalidAdmissionTick`.\n\t */\n\tadmissionTickSize: number;\n\tmintPaused: boolean;\n\t/** The window's anchor strike in USD, or null until the keeper seeds it. */\n\treferencePrice: number | null;\n}\n\n/** A resolved live market: its on-chain state summary for the caller. */\nexport interface MarketSummary {\n\tid: string;\n\texpiryMs: bigint;\n\ttickSize: number;\n\t/**\n\t * Coarser step new mint strikes must align to. A numeric strike must be a whole\n\t * multiple of this (the market's `referencePrice` is the one exception the chain\n\t * admits off-grid); otherwise the mint aborts `EInvalidAdmissionTick`.\n\t */\n\tadmissionTickSize: number;\n\tmintPaused: boolean;\n\tnav: number;\n\t/** The window's anchor strike in USD, or null until the keeper seeds it. */\n\treferencePrice: number | null;\n}\n\n/** Aggregate pool figures. Balances in human units (shares raw); the pending fields\n * are request COUNTS, not amounts — the on-chain getters expose queue lengths, and\n * the escrowed DUSDC/PLP behind them is tracked separately. */\nexport interface PoolSummary {\n\tplpTotalSupply: bigint;\n\tidleUsdc: number;\n\t/** Number of LP supply requests queued for the next flush. */\n\tsupplyRequestsPending: number;\n\t/** Number of LP withdraw requests queued for the next flush. */\n\twithdrawRequestsPending: number;\n}\n\n/** Exact pre-trade quote: the dry-run receipt of the mint you are about to send. */\nexport interface MintQuote {\n\t/** Fill price, 0..1 per $1 payout. */\n\tentryProbability: number;\n\t/** Premium paid into LP backing (quote units). */\n\tpremium: number;\n\t/**\n\t * Fee breakdown. `referral` is a PORTION of the trader-paid trading fee and\n\t * congestion surcharge routed to the referrer — it is already inside those\n\t * numbers and is NOT an extra debit. `inventoryImpact` is a separate charge and\n\t * IS part of `cost`.\n\t */\n\tfees: {\n\t\ttrading: number;\n\t\tsubsidy: number;\n\t\tbuilder: number;\n\t\tpenalty: number;\n\t\treferral: number;\n\t\tinventoryImpact: number;\n\t};\n\t/**\n\t * All-in account debit: premium + (trading − subsidy) + builder + penalty +\n\t * inventoryImpact — exactly what the chain withdraws (the deployed\n\t * `compute_mint_quote`'s `all_in_cost`); pass this (plus your buffer) as maxCost.\n\t */\n\tcost: number;\n\tquantity: number;\n\traw: { premium: bigint; cost: bigint; quantity: bigint; entryProbability: bigint };\n\t/** True: computed by the real mint code path against real account state. */\n\tfeesExact: true;\n}\n\n/** Exact pre-close quote: the dry-run receipt of the redeem you are about to send. */\nexport interface RedeemQuote {\n\t/** NET quote credited to the account. */\n\tproceeds: number;\n\t/** Gross close value before fees. */\n\tgross: number;\n\t/** `inventoryImpactRebate` is credited back on the close, so `proceeds` is\n\t * gross + rebate − trading − builder − penalty. */\n\tfees: { trading: number; builder: number; penalty: number; inventoryImpactRebate: number };\n\tquantityClosed: number;\n\tremaining: number;\n\traw: { proceeds: bigint; gross: bigint; quantityClosed: bigint };\n\tfeesExact: true;\n}\n\ninterface ResolvedMarket {\n\tid: string;\n\tstate: MarketState;\n}\n\n// The strike-bearing (binary) arm of MarketDescriptor, for read.price and its\n// seam — anonymous board pricing has no range semantics.\ntype BinaryMarketCoordinates = Pick<MarketDescriptor, 'underlying' | 'expiryMs' | 'marketId'> & {\n\tstrike: number | 'reference';\n};\n\n/** The Sui client surface PredictClient reads through: any `ClientWithCoreApi`\n * (gRPC or JSON-RPC) provides both the `simulateTransaction` the reads/quotes\n * sit on and the `core` object methods position enumeration needs. */\nexport interface PredictCompatibleClient extends ClientWithCoreApi {}\n\n/**\n * Register PredictClient as a `client.predict` extension, mirroring\n * `@mysten/deepbook-v3`'s `deepbook(...)`: `client.$extend(predict({ network }))`.\n */\nexport function predict<Name extends string = 'predict'>({\n\tname = 'predict' as Name,\n\tnetwork,\n\tconfig,\n}: {\n\tname?: Name;\n\tnetwork: 'testnet' | 'mainnet';\n\tconfig?: PredictConfig;\n}): SuiClientRegistration<PredictCompatibleClient, Name, PredictClient> {\n\treturn {\n\t\tname,\n\t\tregister: (client) => new PredictClient({ client, network, config }),\n\t};\n}\n\n/**\n * The one object an app constructs. Wraps the config, a client for reads, and\n * a derived-account model so callers pass owner addresses, decimal amounts, and\n * human market coordinates — the facade converts to raw units, resolves markets\n * (cached), and delegates to the internal tx primitives / reads. Callers who need\n * to compose their own PTBs can use the generated bindings under `contracts/`.\n */\nexport class PredictClient {\n\treadonly cfg: PredictConfig;\n\t// The flat slice every generated call resolves `options.config` against.\n\tget #config(): GeneratedConfig {\n\t\treturn toGeneratedConfig(this.cfg);\n\t}\n\t#client: PredictCompatibleClient;\n\t// underlying:expiryMs → resolved market. The id and tickSizeRaw — the only\n\t// state tx building depends on — are immutable per (underlying, expiry), so\n\t// one resolution per market per client suffices. (mintPaused IS mutable; the\n\t// cached copy is never consulted for a tx decision — the chain enforces it.)\n\t#marketCache = new Map<string, ResolvedMarket>();\n\t// owner → resolved position-store ids. accountUid and the table id are\n\t// immutable once created, so cache-forever; a missing table (no Predict\n\t// data yet) is NOT cached — it appears after the owner's first trade.\n\t#positionsCache = new Map<string, PositionsHandle>();\n\n\tconstructor(opts: {\n\t\tnetwork: 'testnet' | 'mainnet';\n\t\tclient: PredictCompatibleClient;\n\t\tconfig?: PredictConfig;\n\t}) {\n\t\tthis.cfg = opts.config ?? getConfig(opts.network);\n\t\tthis.#client = opts.client;\n\t}\n\n\t/** The deterministic id of an owner's canonical account wrapper — no chain read. */\n\twrapperIdFor(owner: string): string {\n\t\treturn deriveAccountWrapperIdFrom(this.#config, owner);\n\t}\n\n\t// The deployment's wiring for a symbol; throws a typed error on an unknown symbol.\n\t// Per-underlying ids are the one thing the flat config slice does not carry.\n\t#underlying(underlying: string): UnderlyingConfig {\n\t\tconst u = this.cfg.underlyings[underlying];\n\t\tif (!u) throw new PredictInputError(`unknown underlying: ${underlying}`);\n\t\treturn u;\n\t}\n\n\t// The oracle feed ids for a symbol; throws a typed error on an unknown symbol.\n\t#feeds(underlying: string): MarketFeeds {\n\t\tconst u = this.#underlying(underlying);\n\t\treturn {\n\t\t\tpythFeed: u.pythFeed,\n\t\t\tblockScholesValueStore: u.blockScholesValueStore,\n\t\t\tblockScholesSviStore: u.blockScholesSviStore,\n\t\t};\n\t}\n\n\t// Resolve (and cache) a market's id + state from its human coordinates. An\n\t// explicit `marketId` pin skips the underlying+expiry lookup but still reads\n\t// that market's state — tx building depends on tickSizeRaw.\n\tasync #resolveMarket(\n\t\tm: Pick<MarketDescriptor, 'underlying' | 'expiryMs' | 'marketId'>,\n\t): Promise<ResolvedMarket> {\n\t\tif (m.marketId != null) {\n\t\t\tif (!isValidSuiObjectId(m.marketId)) {\n\t\t\t\tthrow new PredictInputError(`invalid marketId: ${JSON.stringify(m.marketId)}`);\n\t\t\t}\n\t\t\tconst resolved: ResolvedMarket = this.#marketCache.get(m.marketId) ?? {\n\t\t\t\tid: m.marketId,\n\t\t\t\tstate: await marketState(this.#client, this.#config, m.marketId),\n\t\t\t};\n\t\t\t// The pin must agree with the descriptor's coordinates: catching a stale or\n\t\t\t// wrong-market id here beats minting against mismatched oracle feeds. (The\n\t\t\t// underlying cannot be cross-checked — market state does not carry it.)\n\t\t\tif (resolved.state.expiryMs !== BigInt(m.expiryMs)) {\n\t\t\t\tthrow new PredictInputError(\n\t\t\t\t\t`pinned market ${m.marketId} expires at ${resolved.state.expiryMs}, descriptor says ${BigInt(m.expiryMs)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.#marketCache.set(m.marketId, resolved);\n\t\t\treturn resolved;\n\t\t}\n\t\tconst expiryMs = BigInt(m.expiryMs);\n\t\tconst key = `${m.underlying}:${expiryMs}`;\n\t\tconst hit = this.#marketCache.get(key);\n\t\tif (hit) return hit;\n\t\tconst u = this.#underlying(m.underlying);\n\t\tconst id = await expiryMarketId(this.#client, this.#config, u, expiryMs);\n\t\tif (!id) throw new PredictInputError(`no market for ${m.underlying} at expiry ${expiryMs}`);\n\t\tconst state = await marketState(this.#client, this.#config, id);\n\t\tconst resolved: ResolvedMarket = { id, state };\n\t\tthis.#marketCache.set(key, resolved);\n\t\treturn resolved;\n\t}\n\n\t// Reference PRICE in USD from a state (tick index × tick size), or null.\n\tstatic #referencePriceOf(state: MarketState): number | null {\n\t\treturn state.referenceTickRaw == null\n\t\t\t? null\n\t\t\t: fromRaw(state.referenceTickRaw * state.tickSizeRaw, 9);\n\t}\n\n\t// A finite tick from a USD strike, validated exactly like binaryRangeTicks:\n\t// whole-tick multiple, inside the finite domain (1..POS_INF_TICK-1).\n\t#gridTick(strike: number, tickSizeRaw: bigint): bigint {\n\t\tconst raw = priceToRaw(strike);\n\t\tconst tick = raw / tickSizeRaw;\n\t\tif (tick * tickSizeRaw !== raw) {\n\t\t\tthrow new PredictInputError(\n\t\t\t\t`strike ${strike} is not on the ${fromRaw(tickSizeRaw, 9)} tick grid`,\n\t\t\t);\n\t\t}\n\t\tif (tick <= 0n || tick >= POS_INF_TICK) {\n\t\t\tthrow new PredictInputError(\n\t\t\t\t`strike tick ${tick} outside the finite tick domain (1..POS_INF_TICK-1)`,\n\t\t\t);\n\t\t}\n\t\treturn tick;\n\t}\n\n\t// New finite MINT boundaries must land on the market's coarser ADMISSION grid,\n\t// not merely the fine tick grid — the chain asserts exactly this\n\t// (`assert_admitted_mint_ticks`, `EInvalidAdmissionTick`). The ±inf sentinels are\n\t// exempt, and the market's reference tick is the one finite boundary allowed to\n\t// bypass the grid, so an off-grid tick is only rejected after confirming it is not\n\t// the reference (one extra read, and only on the failing path).\n\tasync #assertAdmittedTick(tick: bigint, marketId: string, state: MarketState): Promise<void> {\n\t\tif (tick === 0n || tick === POS_INF_TICK) return;\n\t\tconst multiple = state.admissionTickSizeRaw / state.tickSizeRaw;\n\t\tif (multiple > 0n && tick % multiple === 0n) return;\n\t\tconst reference = await referenceTick(this.#client, this.#config, marketId);\n\t\tif (reference != null && reference === tick) return;\n\t\tconst admission = fromRaw(state.admissionTickSizeRaw, 9);\n\t\tthrow new PredictInputError(\n\t\t\t`strike ${fromRaw(tick * state.tickSizeRaw, 9)} is not on the ${admission} admission grid ` +\n\t\t\t\t`(mint boundaries must be a multiple of ${admission}, or the market's reference strike)`,\n\t\t);\n\t}\n\n\t// Resolve a descriptor's strike(s) to the (lower, higher) tick pair. A binary\n\t// numeric strike converts and validates against the tick grid; \"reference\"\n\t// reads the market's reference tick FRESH (never cached — it is unset early in\n\t// a window) and uses it directly: it is on the tick grid by construction. A\n\t// range descriptor converts both bounds to finite grid ticks (\"reference\" is\n\t// binary-only: a range has no single reference strike).\n\tasync #strikeTicks(\n\t\tm: MarketDescriptor,\n\t\tmarketId: string,\n\t\tstate: MarketState,\n\t): Promise<{ lowerTick: bigint; higherTick: bigint }> {\n\t\tif (m.side === 'range') {\n\t\t\tif (!(m.lower < m.upper)) {\n\t\t\t\tthrow new PredictInputError(`range lower ${m.lower} must be below upper ${m.upper}`);\n\t\t\t}\n\t\t\tconst lowerTick = this.#gridTick(m.lower, state.tickSizeRaw);\n\t\t\tconst higherTick = this.#gridTick(m.upper, state.tickSizeRaw);\n\t\t\tawait this.#assertAdmittedTick(lowerTick, marketId, state);\n\t\t\tawait this.#assertAdmittedTick(higherTick, marketId, state);\n\t\t\treturn { lowerTick, higherTick };\n\t\t}\n\t\tif (m.strike !== 'reference') {\n\t\t\tconst ticks = binaryRangeTicks(priceToRaw(m.strike), m.side, state.tickSizeRaw);\n\t\t\tawait this.#assertAdmittedTick(ticks.lowerTick, marketId, state);\n\t\t\tawait this.#assertAdmittedTick(ticks.higherTick, marketId, state);\n\t\t\treturn ticks;\n\t\t}\n\t\tconst tick = await referenceTick(this.#client, this.#config, marketId);\n\t\tif (tick == null) {\n\t\t\tthrow new PredictInputError(\n\t\t\t\t`reference price not set yet for ${m.underlying} @ ${m.expiryMs} — retry shortly or pass a numeric strike`,\n\t\t\t);\n\t\t}\n\t\treturn m.side === 'up'\n\t\t\t? { lowerTick: tick, higherTick: POS_INF_TICK }\n\t\t\t: { lowerTick: 0n, higherTick: tick };\n\t}\n\n\t// Raw payout quantity must land on a lot boundary — the chain rejects otherwise.\n\t#assertLot(quantityRaw: bigint): void {\n\t\t// From the config in play, not the exported testnet constant — a deployment with a\n\t\t// different `position_lot_size` must not be validated against testnet's.\n\t\tconst lot = BigInt(this.cfg.units.positionLotSize);\n\t\tif (quantityRaw % lot !== 0n) {\n\t\t\tthrow new PredictInputError(\n\t\t\t\t`quantity ${quantityRaw} raw is not a whole ${lot}-unit lot (position_lot_size)`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Shared construction for tx.mint and read.quoteMint. The quote dry-runs the\n\t// same mint the trade sends; quoteMint omits the caller's cost/probability caps\n\t// (they only gate via abort and don't change the receipt numbers).\n\tasync #buildMint(owner: string, m: MarketDescriptor, opts: MintOptions): Promise<Transaction> {\n\t\tconst feeds = this.#feeds(m.underlying);\n\t\tconst { id, state } = await this.#resolveMarket(m);\n\t\tconst quantityRaw = usdcToRaw(opts.quantity);\n\t\tthis.#assertLot(quantityRaw);\n\t\tconst { lowerTick, higherTick } = await this.#strikeTicks(m, id, state);\n\t\treturn txOf(\n\t\t\tmintExactQuantity(this.#config, {\n\t\t\t\texpiryMarketId: id,\n\t\t\t\twrapperId: this.wrapperIdFor(owner),\n\t\t\t\tlowerTick,\n\t\t\t\thigherTick,\n\t\t\t\tquantityRaw,\n\t\t\t\tmaxCostRaw: opts.maxCost != null ? usdcToRaw(opts.maxCost) : undefined,\n\t\t\t\tmaxProbabilityRaw:\n\t\t\t\t\topts.maxProbability != null ? probabilityToRaw(opts.maxProbability) : undefined,\n\t\t\t\t...feeds,\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Shared construction for tx.redeem and read.quoteRedeem.\n\tasync #buildRedeem(owner: string, m: MarketDescriptor, opts: CloseOptions): Promise<Transaction> {\n\t\tconst feeds = this.#feeds(m.underlying);\n\t\tconst { id } = await this.#resolveMarket(m);\n\t\tconst closeQuantityRaw = usdcToRaw(opts.quantity);\n\t\tthis.#assertLot(closeQuantityRaw);\n\t\treturn txOf(\n\t\t\tredeemLive(this.#config, {\n\t\t\t\texpiryMarketId: id,\n\t\t\t\twrapperId: this.wrapperIdFor(owner),\n\t\t\t\torderId: opts.orderId,\n\t\t\t\tcloseQuantityRaw,\n\t\t\t\t...feeds,\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Raw strike for anonymous pricing: numeric strikes validate against the tick\n\t// grid; \"reference\" reads the market's reference tick fresh (unset → typed error).\n\tasync #strikeRawFor(\n\t\tm: BinaryMarketCoordinates,\n\t\tmarketId: string,\n\t\tstate: MarketState,\n\t): Promise<bigint> {\n\t\tif (m.strike !== 'reference') {\n\t\t\t// Same validation as the mint path: on the grid AND inside the finite tick\n\t\t\t// domain (0 / POS_INF are the ±inf sentinels, not quotable strikes).\n\t\t\treturn this.#gridTick(m.strike, state.tickSizeRaw) * state.tickSizeRaw;\n\t\t}\n\t\tconst tick = await referenceTick(this.#client, this.#config, marketId);\n\t\tif (tick == null) {\n\t\t\tthrow new PredictInputError(\n\t\t\t\t`reference price not set yet for ${m.underlying} @ ${m.expiryMs} — retry shortly or pass a numeric strike`,\n\t\t\t);\n\t\t}\n\t\treturn tick * state.tickSizeRaw;\n\t}\n\n\t// === tx builders ===\n\t// Each returns a ready-to-sign Transaction. Market-resolving builders are async.\n\treadonly tx = {\n\t\tcreateManager: (): Transaction => txOf(accountContract(this.cfg).createAccount()),\n\n\t\t// `create: true` composes first-time funding into ONE PTB: create the account\n\t\t// wrapper, deposit into it through the fresh handle, and `share` it LAST (once\n\t\t// shared, by-value use of the handle is over). The wrapper is derived from the\n\t\t// transaction SENDER (`account_registry::new` takes no owner), so `owner` MUST\n\t\t// be the address that signs this transaction — a sponsored/backend signer would\n\t\t// silently fund its own fresh account instead. The caller also asserts the\n\t\t// account does not exist yet: `new` ABORTS at the deterministic address if it\n\t\t// already exists — no chain read is done here. Gate on your own existence check\n\t\t// (`wrapperIdFor(owner)` + a getObject), or retry without the flag on that abort.\n\t\t//\n\t\t// Without `create`, the sourced coin goes into the existing account's stored\n\t\t// balance via the PTB-callable `deposit_funds` (folds settle → authorize → load →\n\t\t// deposit; clock auto-injected). Command order is auth → deposit (auth is a hot\n\t\t// potato consumed by the deposit). See\n\t\t// `packages/account/sources/account.move` (`deposit_funds`).\n\t\tdeposit: (\n\t\t\towner: string,\n\t\t\tamountUsdc: number | string,\n\t\t\topts?: { create?: boolean },\n\t\t): Transaction => {\n\t\t\tconst tx = new Transaction();\n\t\t\tconst coin = tx.add(\n\t\t\t\tcoinWithBalance({\n\t\t\t\t\ttype: this.cfg.quoteCoinType,\n\t\t\t\t\tbalance: usdcToRaw(amountUsdc),\n\t\t\t\t\tuseGasCoin: false,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (opts?.create) {\n\t\t\t\ttx.add(\n\t\t\t\t\taccountContract(this.cfg).createAccountAndDeposit({\n\t\t\t\t\t\tcoin,\n\t\t\t\t\t\tcoinType: this.cfg.quoteCoinType,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\ttx.add(\n\t\t\t\t\tdepositFunds({\n\t\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\t\targuments: { wrapper: this.wrapperIdFor(owner), coin },\n\t\t\t\t\t\ttypeArguments: [this.cfg.quoteCoinType],\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn tx;\n\t\t},\n\n\t\t// Withdraw `amountUsdc` from the account back to `owner`. By default the funds land\n\t\t// in the owner's DUSDC *address balance* (the versionless accumulator) via\n\t\t// `0x2::coin::send_funds` — no coin-object churn, and they merge into the same\n\t\t// balance `deposit` draws from, closing the loop. Pass `{ toCoinObject: true }` to\n\t\t// instead receive a discrete `Coin<T>` object (for wallets/explorers that only\n\t\t// render coin objects, or to compose the coin further in your own PTB). Either way\n\t\t// the underlying `withdraw_funds` returns the raw `Coin<T>` — the PTB-callable form\n\t\t// that folds settle → authorize → load → withdraw (clock auto-injected, `ctx`\n\t\t// implicit); command order is auth → withdraw. See\n\t\t// `packages/account/sources/account.move` (`withdraw_funds`).\n\t\twithdraw: (\n\t\t\towner: string,\n\t\t\tamountUsdc: number | string,\n\t\t\topts?: { toCoinObject?: boolean },\n\t\t): Transaction => {\n\t\t\tconst tx = new Transaction();\n\t\t\tconst coin = tx.add(\n\t\t\t\twithdrawFunds({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper: this.wrapperIdFor(owner), amount: usdcToRaw(amountUsdc) },\n\t\t\t\t\ttypeArguments: [this.cfg.quoteCoinType],\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (opts?.toCoinObject) {\n\t\t\t\ttx.transferObjects([coin], owner);\n\t\t\t} else {\n\t\t\t\ttx.moveCall({\n\t\t\t\t\ttarget: '0x2::coin::send_funds',\n\t\t\t\t\ttypeArguments: [this.cfg.quoteCoinType],\n\t\t\t\t\targuments: [coin, tx.pure.address(owner)],\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn tx;\n\t\t},\n\n\t\tmint: (owner: string, m: MarketDescriptor, opts: MintOptions): Promise<Transaction> =>\n\t\t\tthis.#buildMint(owner, m, opts),\n\n\t\tmintAmount: async (\n\t\t\towner: string,\n\t\t\tm: MarketDescriptor,\n\t\t\topts: MintAmountOptions,\n\t\t): Promise<Transaction> => {\n\t\t\tconst feeds = this.#feeds(m.underlying);\n\t\t\t// The chain requires a positive all-in cost cap (EMintCostCapRequired);\n\t\t\t// reject a zero cap pre-flight rather than surface a cryptic Move abort.\n\t\t\tif (opts.maxCost != null && opts.maxCost <= 0) {\n\t\t\t\tthrow new PredictInputError('maxCost must be > 0');\n\t\t\t}\n\t\t\tconst { id, state } = await this.#resolveMarket(m);\n\t\t\t// No lot check: min_quantity is a floor the chain compares against an\n\t\t\t// already-lot-floored minted quantity, so any floor value is legal.\n\t\t\tconst minQuantityRaw = usdcToRaw(opts.minQuantity);\n\t\t\tconst { lowerTick, higherTick } = await this.#strikeTicks(m, id, state);\n\t\t\treturn txOf(\n\t\t\t\tmintExactAmount(this.#config, {\n\t\t\t\t\texpiryMarketId: id,\n\t\t\t\t\twrapperId: this.wrapperIdFor(owner),\n\t\t\t\t\tlowerTick,\n\t\t\t\t\thigherTick,\n\t\t\t\t\tmaxPremiumRaw: usdcToRaw(opts.spend),\n\t\t\t\t\tminQuantityRaw,\n\t\t\t\t\tmaxCostRaw: opts.maxCost != null ? usdcToRaw(opts.maxCost) : undefined,\n\t\t\t\t\t...feeds,\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\n\t\tredeem: (owner: string, m: MarketDescriptor, opts: CloseOptions): Promise<Transaction> =>\n\t\t\tthis.#buildRedeem(owner, m, opts),\n\n\t\tclaimSettled: async (\n\t\t\towner: string,\n\t\t\tm: Pick<MarketDescriptor, 'underlying' | 'expiryMs' | 'marketId'>,\n\t\t\topts: Pick<CloseOptions, 'orderId'>,\n\t\t): Promise<Transaction> => {\n\t\t\tconst { id } = await this.#resolveMarket(m);\n\t\t\treturn txOf(\n\t\t\t\tredeemSettled(this.#config, {\n\t\t\t\t\texpiryMarketId: id,\n\t\t\t\t\twrapperId: this.wrapperIdFor(owner),\n\t\t\t\t\torderId: opts.orderId,\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\n\t\t// Queue a supply request pulling `amountUsdc` from the account's existing custody\n\t\t// balance. `request_supply` auto-settles DUSDC then `account.withdraw`s the payment\n\t\t// into queue escrow; the PLP fill is delivered at the next flush, not returned here.\n\t\t// Command order is auth → request (auth is a hot potato consumed by this call). The\n\t\t// `minPlpOut` slot is the per-request floor on PLP minted at flush — pinned to 0\n\t\t// (no floor) here; after three flushes miss the floor the request is cancelled and\n\t\t// refunded.\n\t\tsupplyPlp: (owner: string, amountUsdc: number | string): Transaction =>\n\t\t\ttxOf(\n\t\t\t\trequestSupply({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\twrapper: this.wrapperIdFor(owner),\n\t\t\t\t\t\tamount: usdcToRaw(amountUsdc),\n\t\t\t\t\t\tminPlpOut: 0n,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t),\n\n\t\t// Queue a withdraw request pulling `shares` (raw PLP u64) from account custody into\n\t\t// queue escrow — the Move parameter is named `amount`, but on `request_withdraw` it\n\t\t// counts PLP SHARES, not DUSDC. Auto-settles flush-delivered PLP first; the DUSDC\n\t\t// fill lands on the account at the next flush (no `withdraw_settled` entrypoint).\n\t\t// Command order is auth → request. The `minDusdcOut` slot is the per-request floor\n\t\t// on DUSDC paid at flush — pinned to 0 (no floor) here; after three flushes miss the\n\t\t// floor the request is cancelled and refunded.\n\t\twithdrawPlp: (owner: string, shares: bigint): Transaction =>\n\t\t\ttxOf(\n\t\t\t\trequestWithdraw({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\twrapper: this.wrapperIdFor(owner),\n\t\t\t\t\t\tamount: shares,\n\t\t\t\t\t\tminDusdcOut: 0n,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t),\n\n\t\t// Cancel a still-pending supply request by queue `index`, refunding its escrowed\n\t\t// DUSDC straight back into the requesting account. Command order is auth → cancel.\n\t\tcancelSupplyPlp: (owner: string, index: bigint): Transaction =>\n\t\t\ttxOf(\n\t\t\t\tcancelSupplyRequest({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper: this.wrapperIdFor(owner), index },\n\t\t\t\t}),\n\t\t\t),\n\n\t\t// Cancel a still-pending withdraw request by queue `index`, refunding its escrowed\n\t\t// PLP straight back into the requesting account. Command order is auth → cancel.\n\t\tcancelWithdrawPlp: (owner: string, index: bigint): Transaction =>\n\t\t\ttxOf(\n\t\t\t\tcancelWithdrawRequest({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper: this.wrapperIdFor(owner), index },\n\t\t\t\t}),\n\t\t\t),\n\n\t\t// Set the account's sticky builder-code attribution to `builderCodeId`, an existing\n\t\t// `BuilderCode` object borrowed as `&BuilderCode`. Command order is auth → set (auth\n\t\t// is a hot potato consumed by this call). Lives in the PREDICT package's\n\t\t// `predict_account` module, NOT the account package. Deployed sig\n\t\t// `packages/predict/sources/predict_account.move:134` — 3 moveCall args\n\t\t// (wrapper, auth, code; ctx implicit).\n\t\tsetBuilderCode: (owner: string, builderCodeId: string): Transaction =>\n\t\t\ttxOf(\n\t\t\t\tsetBuilderCode({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper: this.wrapperIdFor(owner), code: builderCodeId },\n\t\t\t\t}),\n\t\t\t),\n\n\t\t// Clear the account's sticky builder-code attribution. Command order is auth → unset.\n\t\t// Deployed sig `.../predict_account.move:151` — 2 moveCall args (wrapper, auth; ctx\n\t\t// implicit).\n\t\tunsetBuilderCode: (owner: string): Transaction =>\n\t\t\ttxOf(\n\t\t\t\tunsetBuilderCode({\n\t\t\t\t\tconfig: this.#config,\n\t\t\t\t\targuments: { wrapper: this.wrapperIdFor(owner) },\n\t\t\t\t}),\n\t\t\t),\n\t};\n\n\t// === reads ===\n\treadonly read = {\n\t\t// All tradeable (active) markets with the state a frontend needs to render\n\t\t// and mint: one chain read for ids + one batched PTB for the states.\n\t\tmarkets: async (): Promise<ActiveMarket[]> => {\n\t\t\tconst ids = await activeMarketIds(this.#client, this.#config);\n\t\t\tconst states = await marketStates(this.#client, this.#config, ids);\n\t\t\treturn ids.map((id, i) => ({\n\t\t\t\tid,\n\t\t\t\texpiryMs: states[i].expiryMs,\n\t\t\t\ttickSize: fromRaw(states[i].tickSizeRaw, 9),\n\t\t\t\tadmissionTickSize: fromRaw(states[i].admissionTickSizeRaw, 9),\n\t\t\t\tmintPaused: states[i].mintPaused,\n\t\t\t\treferencePrice: PredictClient.#referencePriceOf(states[i]),\n\t\t\t}));\n\t\t},\n\n\t\t// Validate an app-stored order id against the chain (stale after full\n\t\t// close or partial-close replacement — see RedeemReceipt.replacementOrderId).\n\t\thasPosition: (owner: string, marketId: string, orderId: bigint): Promise<boolean> =>\n\t\t\thasPosition(this.#client, this.#config, owner, marketId, orderId),\n\n\t\t// All open positions for an owner, enumerated from the chain (the\n\t\t// account's positions Table): 1 call per page warm, +2 resolution calls\n\t\t// once per owner. Returns [] for owners with no Predict account.\n\t\tpositions: async (owner: string): Promise<OpenPosition[]> => {\n\t\t\tlet handle = this.#positionsCache.get(owner);\n\t\t\tif (!handle?.positionsTableId) {\n\t\t\t\tconst resolved = await resolvePositionsTable(this.#client, this.#config, owner);\n\t\t\t\tif (!resolved) return []; // never onboarded — do not cache\n\t\t\t\tif (resolved.positionsTableId) this.#positionsCache.set(owner, resolved);\n\t\t\t\thandle = resolved;\n\t\t\t}\n\t\t\tif (!handle.positionsTableId) return [];\n\t\t\treturn positionsFromTable(this.#client, handle.positionsTableId);\n\t\t},\n\n\t\t// Anonymous board pricing: the chain's probability for both sides of a\n\t\t// strike, from one fresh pricer (no account needed). This is the ↑/↓\n\t\t// button price before a user has onboarded.\n\t\tprice: async (m: BinaryMarketCoordinates): Promise<{ up: number; down: number }> => {\n\t\t\tconst feeds = this.#feeds(m.underlying);\n\t\t\tconst { id, state } = await this.#resolveMarket(m);\n\t\t\tconst strikeRaw = await this.#strikeRawFor(m, id, state);\n\t\t\tconst { upRaw, downRaw } = await rangePrices(\n\t\t\t\tthis.#client,\n\t\t\t\tthis.#config,\n\t\t\t\tid,\n\t\t\t\tfeeds,\n\t\t\t\tstrikeRaw,\n\t\t\t\tstate.tickSizeRaw,\n\t\t\t);\n\t\t\treturn { up: rawToProbability(upRaw), down: rawToProbability(downRaw) };\n\t\t},\n\n\t\t// A client-side board pricer for one market: ONE simulate reads the chain's\n\t\t// resolved pricer (already forward-selected + rolled to now), then prices every\n\t\t// strike LOCALLY with no further chain calls — `pricer.up(strike)`,\n\t\t// `.down(strike)`, `.range(lo,hi)`, `.strikeAtProbability(p)`. Use this to paint a\n\t\t// whole board instantly; `read.price` / `read.quoteMint` stay the authoritative\n\t\t// per-strike quote at trade time. Throws the same typed stale-oracle/expired\n\t\t// PredictMoveError `read.price` would when the chain itself cannot quote.\n\t\tpricer: async (\n\t\t\tm: Pick<MarketDescriptor, 'underlying' | 'expiryMs'>,\n\t\t): Promise<BoardPricer & { asOf: PricerSnapshot['sources'] }> => {\n\t\t\tconst feeds = this.#feeds(m.underlying);\n\t\t\tconst { id } = await this.#resolveMarket(m);\n\t\t\tconst snap = await readPricerSnapshot(this.#client, this.#config, id, feeds);\n\t\t\treturn { ...boardPricer(snap), asOf: snap.sources };\n\t\t},\n\n\t\t// Exact pre-trade quote: dry-runs the caller's own mint (same tx as\n\t\t// tx.mint) and decodes the receipt. Requires a funded account; throws\n\t\t// the same typed errors the real trade would — quote doubles as preflight.\n\t\tquoteMint: async (\n\t\t\towner: string,\n\t\t\tm: MarketDescriptor,\n\t\t\topts: Pick<MintOptions, 'quantity'>,\n\t\t): Promise<MintQuote> => {\n\t\t\tconst tx = await this.#buildMint(owner, m, opts);\n\t\t\tconst events = await simulateWithEvents(this.#client, tx, owner);\n\t\t\tconst r = exactlyOne(decodeMints(this.cfg, { events }), 'OrderMinted');\n\t\t\t// Mirrors the deployed `compute_mint_quote`'s all_in_cost exactly:\n\t\t\t// premium + (trading − subsidy) + builder + penalty + inventory-impact.\n\t\t\t// `referral_fee` is deliberately NOT added — it is a portion OF the\n\t\t\t// trader-paid trading fee and congestion surcharge, not an extra debit.\n\t\t\tconst costRaw =\n\t\t\t\tr.raw.premium +\n\t\t\t\t(r.raw.tradingFee - r.raw.feeIncentiveSubsidy) +\n\t\t\t\tr.raw.builderFee +\n\t\t\t\tr.raw.penaltyFee +\n\t\t\t\tr.raw.inventoryImpactCharge;\n\t\t\treturn {\n\t\t\t\tentryProbability: r.entryProbability,\n\t\t\t\tpremium: r.premium,\n\t\t\t\tfees: r.fees,\n\t\t\t\tcost: rawToUsdc(costRaw),\n\t\t\t\tquantity: r.quantity,\n\t\t\t\traw: {\n\t\t\t\t\tpremium: r.raw.premium,\n\t\t\t\t\tcost: costRaw,\n\t\t\t\t\tquantity: r.raw.quantity,\n\t\t\t\t\tentryProbability: r.raw.entryProbability,\n\t\t\t\t},\n\t\t\t\tfeesExact: true,\n\t\t\t};\n\t\t},\n\n\t\t// Exact pre-close quote: dry-runs the caller's own redeem and decodes\n\t\t// the receipt — the informed close against the floor-less deployed redeem.\n\t\tquoteRedeem: async (\n\t\t\towner: string,\n\t\t\tm: MarketDescriptor,\n\t\t\topts: CloseOptions,\n\t\t): Promise<RedeemQuote> => {\n\t\t\tconst tx = await this.#buildRedeem(owner, m, opts);\n\t\t\tconst events = await simulateWithEvents(this.#client, tx, owner);\n\t\t\tconst r = exactlyOne(decodeRedeems(this.cfg, { events }), 'order-redeemed');\n\t\t\treturn {\n\t\t\t\tproceeds: r.proceeds,\n\t\t\t\tgross: r.gross,\n\t\t\t\tfees: r.fees,\n\t\t\t\tquantityClosed: r.quantityClosed,\n\t\t\t\tremaining: r.remaining,\n\t\t\t\traw: {\n\t\t\t\t\tproceeds: r.raw.proceeds,\n\t\t\t\t\tgross: r.raw.gross,\n\t\t\t\t\tquantityClosed: r.raw.quantityClosed,\n\t\t\t\t},\n\t\t\t\tfeesExact: true,\n\t\t\t};\n\t\t},\n\n\t\tmarket: async (\n\t\t\tm: Pick<MarketDescriptor, 'underlying' | 'expiryMs'>,\n\t\t): Promise<MarketSummary | null> => {\n\t\t\tconst expiryMs = BigInt(m.expiryMs);\n\t\t\t// Deliberately re-queries and overwrites the cache instead of reading\n\t\t\t// through it: this read must return live state (nav, mintPaused), and\n\t\t\t// refreshing the cache on the way keeps later tx builds consistent.\n\t\t\tconst u = this.#underlying(m.underlying);\n\t\t\tconst id = await expiryMarketId(this.#client, this.#config, u, expiryMs);\n\t\t\tif (!id) return null;\n\t\t\tconst state = await marketState(this.#client, this.#config, id);\n\t\t\tthis.#marketCache.set(`${m.underlying}:${expiryMs}`, { id, state });\n\t\t\tconst navRaw = await currentNav(this.#client, this.#config, id, u);\n\t\t\treturn {\n\t\t\t\tid,\n\t\t\t\texpiryMs: state.expiryMs,\n\t\t\t\ttickSize: fromRaw(state.tickSizeRaw, 9), // strike/price scale\n\t\t\t\tadmissionTickSize: fromRaw(state.admissionTickSizeRaw, 9),\n\t\t\t\tmintPaused: state.mintPaused,\n\t\t\t\tnav: rawToUsdc(navRaw),\n\t\t\t\treferencePrice: PredictClient.#referencePriceOf(state),\n\t\t\t};\n\t\t},\n\n\t\tbalance: async (owner: string): Promise<number> =>\n\t\t\trawToUsdc(await accountBalance(this.#client, this.#config, owner, this.cfg.quoteCoinType)),\n\n\t\t// PLP shares held in the owner's account custody (raw u64, 6-decimal PLP coin).\n\t\tplpBalance: (owner: string): Promise<bigint> =>\n\t\t\taccountBalance(this.#client, this.#config, owner, this.cfg.coinTypes.plp),\n\n\t\tpool: async (): Promise<PoolSummary> => {\n\t\t\tconst s = await poolStats(this.#client, this.#config);\n\t\t\treturn {\n\t\t\t\tplpTotalSupply: s.plpTotalSupply, // shares raw (6-decimal)\n\t\t\t\tidleUsdc: rawToUsdc(s.idleBalance),\n\t\t\t\t// These are queue LENGTHS (counts of pending requests), not token amounts.\n\t\t\t\tsupplyRequestsPending: Number(s.supplyRequestsPending),\n\t\t\t\twithdrawRequestsPending: Number(s.withdrawRequestsPending),\n\t\t\t};\n\t\t},\n\t};\n\n\t// === execution-result decoders ===\n\t// Pure event parsing (no network): pass the executed/simulated transaction\n\t// result (with events included) and get a typed receipt back. Singular forms\n\t// throw unless exactly one matching event exists; plural forms return all\n\t// (an integrator batching N actions in one PTB gets N receipts).\n\treadonly decode = {\n\t\tmint: (r: DecodableTransactionResult) => exactlyOne(decodeMints(this.cfg, r), 'OrderMinted'),\n\t\tmints: (r: DecodableTransactionResult) => decodeMints(this.cfg, r),\n\t\tredeem: (r: DecodableTransactionResult) =>\n\t\t\texactlyOne(decodeRedeems(this.cfg, r), 'order-redeemed'),\n\t\tredeems: (r: DecodableTransactionResult) => decodeRedeems(this.cfg, r),\n\t\tclaim: (r: DecodableTransactionResult) =>\n\t\t\texactlyOne(decodeClaims(this.cfg, r), 'SettledOrderRedeemed'),\n\t\tclaims: (r: DecodableTransactionResult) => decodeClaims(this.cfg, r),\n\t\tcreateManager: (r: DecodableTransactionResult) =>\n\t\t\texactlyOne(decodeAccountsCreated(this.cfg, r), 'AccountCreated'),\n\t\tdeposit: (r: DecodableTransactionResult) =>\n\t\t\texactlyOne(decodeDeposits(this.cfg, r), 'Deposited'),\n\t\twithdraw: (r: DecodableTransactionResult) =>\n\t\t\texactlyOne(decodeWithdrawals(this.cfg, r), 'Withdrawn'),\n\t\tplpRequest: (r: DecodableTransactionResult) =>\n\t\t\texactlyOne(decodePlpRequests(this.cfg, r), 'supply/withdraw-requested'),\n\t\tplpCancel: (r: DecodableTransactionResult) =>\n\t\t\texactlyOne(decodePlpCancels(this.cfg, r), 'RequestCancelled'),\n\t\tbuilderCode: (r: DecodableTransactionResult) =>\n\t\t\texactlyOne(decodeBuilderCodeSets(this.cfg, r), 'BuilderCodeSet'),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,MAAa,oBAAoB,OAAO,gBAAgB,MAAM,gBAAgB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,MAAM,EAAE,OAAO,MAAM,MAAKC,cAAe,EAAE;EAC3C,MAAM,mBAAmB,UAAU,KAAK,SAAS;AACjD,QAAKY,UAAW,iBAAiB;AACjC,SAAO,KACN,WAAW,MAAKhB,QAAS;GACxB,gBAAgB;GAChB,WAAW,KAAK,aAAa,MAAM;GACnC,SAAS,KAAK;GACd;GACA,GAAG;GACH,CAAC,CACF;;CAKF,OAAMU,aACL,GACA,UACA,OACkB;AAClB,MAAI,EAAE,WAAW,YAGhB,QAAO,MAAKK,SAAU,EAAE,QAAQ,MAAM,YAAY,GAAG,MAAM;EAE5D,MAAM,OAAO,MAAM,cAAc,MAAKR,QAAS,MAAKP,QAAS,SAAS;AACtE,MAAI,QAAQ,KACX,OAAM,IAAI,kBACT,mCAAmC,EAAE,WAAW,KAAK,EAAE,SAAS,2CAChE;AAEF,SAAO,OAAO,MAAM"}
@@ -0,0 +1,29 @@
1
+ import { AccountConfig } from "../../account.mjs";
2
+ import { PredictConfig } from "./types.mjs";
3
+ import { DeepbookPredictConfig } from "../../contracts/deepbook_predict/config-arguments.mjs";
4
+
5
+ //#region src/predict/config/generated.d.ts
6
+ /**
7
+ * The flat config slice the generated bindings resolve `options.config` against, projected from
8
+ * the nested public `PredictConfig`. Each generated call declares only the keys it consumes, so a
9
+ * single object carrying all of them satisfies every call site.
10
+ *
11
+ * Typed as the intersection of the two generated interfaces on purpose: if codegen adds, drops, or
12
+ * renames a config key, this file stops compiling instead of silently building a PTB against the
13
+ * wrong object.
14
+ *
15
+ * `predictPackageId` is narrowed to `string` because codegen types package ids as optional, while
16
+ * this projection always supplies one — and the helper that hand-builds the `DataKey` type tag
17
+ * needs a `string`, not a maybe-absent `ConfigValue`. The two account ids restate a narrowing
18
+ * `AccountConfig` already applies, so they are redundant today; they are kept so this projection
19
+ * still compiles to plain ids if that package ever widens them back.
20
+ */
21
+ type GeneratedConfig = DeepbookPredictConfig & AccountConfig & {
22
+ predictPackageId: string;
23
+ accountPackageId: string;
24
+ accountRegistry: string;
25
+ };
26
+ declare function toGeneratedConfig(cfg: PredictConfig): GeneratedConfig;
27
+ //#endregion
28
+ export { GeneratedConfig, toGeneratedConfig };
29
+ //# sourceMappingURL=generated.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated.d.mts","names":[],"sources":["../../../src/predict/config/generated.ts"],"mappings":";;;;;;;AAqBA;;;;;;;;;;;AAOA;;KAPY,eAAA,GAAkB,qBAAA,GAC7B,aAAA;EACC,gBAAA;EACA,gBAAA;EACA,eAAA;AAAA;AAAA,iBAGc,iBAAA,CAAkB,GAAA,EAAK,aAAA,GAAgB,eAAA"}
@@ -0,0 +1,16 @@
1
+ //#region src/predict/config/generated.ts
2
+ function toGeneratedConfig(cfg) {
3
+ return {
4
+ predictPackageId: cfg.packages.predict,
5
+ accountPackageId: cfg.packages.account,
6
+ protocolConfig: cfg.objects.protocolConfig,
7
+ poolVault: cfg.objects.poolVault,
8
+ registry: cfg.objects.registry,
9
+ oracleRegistry: cfg.objects.oracleRegistry,
10
+ accountRegistry: cfg.objects.accountRegistry
11
+ };
12
+ }
13
+
14
+ //#endregion
15
+ export { toGeneratedConfig };
16
+ //# sourceMappingURL=generated.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated.mjs","names":[],"sources":["../../../src/predict/config/generated.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { AccountConfig } from '../../account.js';\nimport type { DeepbookPredictConfig } from '../../contracts/deepbook_predict/config-arguments.js';\nimport type { PredictConfig } from './types.js';\n\n/**\n * The flat config slice the generated bindings resolve `options.config` against, projected from\n * the nested public `PredictConfig`. Each generated call declares only the keys it consumes, so a\n * single object carrying all of them satisfies every call site.\n *\n * Typed as the intersection of the two generated interfaces on purpose: if codegen adds, drops, or\n * renames a config key, this file stops compiling instead of silently building a PTB against the\n * wrong object.\n *\n * `predictPackageId` is narrowed to `string` because codegen types package ids as optional, while\n * this projection always supplies one — and the helper that hand-builds the `DataKey` type tag\n * needs a `string`, not a maybe-absent `ConfigValue`. The two account ids restate a narrowing\n * `AccountConfig` already applies, so they are redundant today; they are kept so this projection\n * still compiles to plain ids if that package ever widens them back.\n */\nexport type GeneratedConfig = DeepbookPredictConfig &\n\tAccountConfig & {\n\t\tpredictPackageId: string;\n\t\taccountPackageId: string;\n\t\taccountRegistry: string;\n\t};\n\nexport function toGeneratedConfig(cfg: PredictConfig): GeneratedConfig {\n\treturn {\n\t\tpredictPackageId: cfg.packages.predict,\n\t\taccountPackageId: cfg.packages.account,\n\t\tprotocolConfig: cfg.objects.protocolConfig,\n\t\tpoolVault: cfg.objects.poolVault,\n\t\tregistry: cfg.objects.registry,\n\t\toracleRegistry: cfg.objects.oracleRegistry,\n\t\taccountRegistry: cfg.objects.accountRegistry,\n\t};\n}\n"],"mappings":";AA4BA,SAAgB,kBAAkB,KAAqC;AACtE,QAAO;EACN,kBAAkB,IAAI,SAAS;EAC/B,kBAAkB,IAAI,SAAS;EAC/B,gBAAgB,IAAI,QAAQ;EAC5B,WAAW,IAAI,QAAQ;EACvB,UAAU,IAAI,QAAQ;EACtB,gBAAgB,IAAI,QAAQ;EAC5B,iBAAiB,IAAI,QAAQ;EAC7B"}
@@ -0,0 +1,10 @@
1
+ import { TESTNET_DEPLOYMENT, TESTNET_UNITS } from "../../deployments/testnet.mjs";
2
+ import { NetworkArg, getDeployment, getUnits } from "../../deployments/index.mjs";
3
+ import { PredictConfig, PredictPackages, UnderlyingConfig } from "./types.mjs";
4
+ import { TESTNET_CONFIG } from "./testnet.mjs";
5
+
6
+ //#region src/predict/config/index.d.ts
7
+ declare function getConfig(network: NetworkArg): PredictConfig;
8
+ //#endregion
9
+ export { getConfig };
10
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/predict/config/index.ts"],"mappings":";;;;;;iBASgB,SAAA,CAAU,OAAA,EAAS,UAAA,GAAa,aAAA"}
@@ -0,0 +1,13 @@
1
+ import { TESTNET_DEPLOYMENT, TESTNET_UNITS } from "../../deployments/testnet.mjs";
2
+ import { getDeployment, getUnits } from "../../deployments/index.mjs";
3
+ import { TESTNET_CONFIG } from "./testnet.mjs";
4
+
5
+ //#region src/predict/config/index.ts
6
+ function getConfig(network) {
7
+ if (network === "testnet") return TESTNET_CONFIG;
8
+ throw new Error(`@mysten/deepbook-v3/predict: no Predict deployment recorded for network '${network}'. Predict is testnet-only today; for your own deployment pass \`config\` to PredictClient or \`predict({ config })\`.`);
9
+ }
10
+
11
+ //#endregion
12
+ export { getConfig };
13
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/predict/config/index.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { TESTNET_CONFIG } from './testnet.js';\nimport type { PredictConfig } from './types.js';\nimport type { NetworkArg } from '../../deployments/index.js';\n\nexport { TESTNET_CONFIG };\nexport type { PredictConfig, PredictPackages, UnderlyingConfig } from './types.js';\n\nexport function getConfig(network: NetworkArg): PredictConfig {\n\tif (network === 'testnet') return TESTNET_CONFIG;\n\tthrow new Error(\n\t\t`@mysten/deepbook-v3/predict: no Predict deployment recorded for network '${network}'. ` +\n\t\t\t'Predict is testnet-only today; for your own deployment pass `config` to PredictClient ' +\n\t\t\t'or `predict({ config })`.',\n\t);\n}\n\n// Provenance: which on-chain deployment these ids came from.\nexport {\n\tgetDeployment,\n\tgetUnits,\n\tTESTNET_DEPLOYMENT,\n\tTESTNET_UNITS,\n} from '../../deployments/index.js';\n"],"mappings":";;;;;AASA,SAAgB,UAAU,SAAoC;AAC7D,KAAI,YAAY,UAAW,QAAO;AAClC,OAAM,IAAI,MACT,4EAA4E,QAAQ,wHAGpF"}