@waterx/sdk 2.1.0 → 2.3.1-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/README.md +75 -169
  2. package/dist/src/client.d.ts +52 -2
  3. package/dist/src/client.js +76 -6
  4. package/dist/src/config.d.ts +57 -3
  5. package/dist/src/config.js +10 -4
  6. package/dist/src/constants.d.ts +6 -0
  7. package/dist/src/constants.js +6 -0
  8. package/dist/src/core/waterx-account.d.ts +31 -0
  9. package/dist/src/core/waterx-account.js +26 -0
  10. package/dist/src/fetch.d.ts +110 -0
  11. package/dist/src/fetch.js +149 -4
  12. package/dist/src/generated/bucket_v2_framework/account.d.ts +5 -5
  13. package/dist/src/generated/bucket_v2_framework/double.d.ts +77 -77
  14. package/dist/src/generated/bucket_v2_framework/float.d.ts +73 -73
  15. package/dist/src/generated/bucket_v2_framework/liability.d.ts +33 -33
  16. package/dist/src/generated/bucket_v2_framework/linked_table.d.ts +5 -5
  17. package/dist/src/generated/bucket_v2_framework/linked_table.js +2 -2
  18. package/dist/src/generated/bucket_v2_framework/sheet.d.ts +57 -57
  19. package/dist/src/generated/bucket_v2_framework/sheet.js +5 -11
  20. package/dist/src/generated/native_custody/custody_vault.d.ts +46 -32
  21. package/dist/src/generated/native_custody/custody_vault.js +19 -10
  22. package/dist/src/generated/native_custody/deps/bucket_v2_framework/sheet.js +1 -3
  23. package/dist/src/generated/native_custody/events.js +1 -2
  24. package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +7 -7
  25. package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +1 -2
  26. package/dist/src/generated/utils/index.d.ts +7 -7
  27. package/dist/src/generated/utils/index.js +9 -6
  28. package/dist/src/generated/waterx_account/account.d.ts +124 -71
  29. package/dist/src/generated/waterx_account/account.js +64 -29
  30. package/dist/src/generated/waterx_account/deps/bucket_v2_framework/sheet.js +1 -3
  31. package/dist/src/generated/waterx_account/direct_rule.d.ts +5 -5
  32. package/dist/src/generated/waterx_account/events.d.ts +10 -0
  33. package/dist/src/generated/waterx_account/events.js +31 -50
  34. package/dist/src/generated/waterx_constant_rule/constant_rule.d.ts +68 -0
  35. package/dist/src/generated/waterx_constant_rule/constant_rule.js +59 -0
  36. package/dist/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.d.ts +8 -0
  37. package/dist/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.js +10 -0
  38. package/dist/src/generated/waterx_constant_rule/deps/sui/vec_map.d.ts +36 -0
  39. package/dist/src/generated/waterx_constant_rule/deps/sui/vec_map.js +27 -0
  40. package/dist/src/generated/waterx_credit/credit_registry.d.ts +9 -9
  41. package/dist/src/generated/waterx_credit/credit_registry.js +1 -2
  42. package/dist/src/generated/waterx_credit/limited_supply.d.ts +17 -17
  43. package/dist/src/generated/waterx_oracle/aggregator.js +1 -2
  44. package/dist/src/generated/waterx_oracle/collector.d.ts +17 -17
  45. package/dist/src/generated/waterx_oracle/collector.js +1 -1
  46. package/dist/src/generated/waterx_oracle/oracle.d.ts +5 -5
  47. package/dist/src/generated/waterx_perp/account_data.d.ts +5 -5
  48. package/dist/src/generated/waterx_perp/account_data.js +1 -2
  49. package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.js +1 -3
  50. package/dist/src/generated/waterx_perp/events.d.ts +181 -181
  51. package/dist/src/generated/waterx_perp/events.js +87 -173
  52. package/dist/src/generated/waterx_perp/global_config.d.ts +3 -3
  53. package/dist/src/generated/waterx_perp/global_config.js +6 -12
  54. package/dist/src/generated/waterx_perp/keyed_big_vector.d.ts +9 -9
  55. package/dist/src/generated/waterx_perp/keyed_big_vector.js +1 -2
  56. package/dist/src/generated/waterx_perp/lp_pool.d.ts +115 -115
  57. package/dist/src/generated/waterx_perp/lp_pool.js +11 -22
  58. package/dist/src/generated/waterx_perp/market_config.d.ts +61 -43
  59. package/dist/src/generated/waterx_perp/market_config.js +29 -22
  60. package/dist/src/generated/waterx_perp/math.d.ts +7 -7
  61. package/dist/src/generated/waterx_perp/order_book.d.ts +47 -47
  62. package/dist/src/generated/waterx_perp/position.d.ts +99 -99
  63. package/dist/src/generated/waterx_perp/position.js +6 -12
  64. package/dist/src/generated/waterx_perp/request.d.ts +67 -67
  65. package/dist/src/generated/waterx_perp/request.js +2 -3
  66. package/dist/src/generated/waterx_perp/response.d.ts +35 -35
  67. package/dist/src/generated/waterx_perp/response.js +1 -2
  68. package/dist/src/generated/waterx_perp/trading.d.ts +303 -179
  69. package/dist/src/generated/waterx_perp/trading.js +99 -14
  70. package/dist/src/generated/waterx_perp_view/view.js +5 -10
  71. package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +5 -5
  72. package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +1 -2
  73. package/dist/src/generated/waterx_referral/referral_table.d.ts +5 -5
  74. package/dist/src/generated/waterx_referral/referral_table.js +1 -2
  75. package/dist/src/generated/waterx_staking/waterx_staking.d.ts +19 -19
  76. package/dist/src/generated/waterx_staking/waterx_staking.js +10 -20
  77. package/dist/src/generated/waterx_supra_rule/deps/sui/vec_map.d.ts +36 -0
  78. package/dist/src/generated/waterx_supra_rule/deps/sui/vec_map.js +27 -0
  79. package/dist/src/generated/waterx_supra_rule/supra_rule.d.ts +158 -0
  80. package/dist/src/generated/waterx_supra_rule/supra_rule.js +148 -0
  81. package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.d.ts +8 -0
  82. package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.js +10 -0
  83. package/dist/src/generated/withdrawal_queue/deps/sui/vec_map.d.ts +36 -0
  84. package/dist/src/generated/withdrawal_queue/deps/sui/vec_map.js +27 -0
  85. package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +444 -4
  86. package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +417 -4
  87. package/dist/src/generated/wormhole_bridge/wormhole_bridge.d.ts +214 -74
  88. package/dist/src/generated/wormhole_bridge/wormhole_bridge.js +158 -29
  89. package/dist/src/index.d.ts +4 -3
  90. package/dist/src/index.js +3 -2
  91. package/dist/src/prediction/account.d.ts +96 -0
  92. package/dist/src/prediction/account.js +230 -0
  93. package/dist/src/prediction/admin.d.ts +47 -0
  94. package/dist/src/prediction/admin.js +105 -0
  95. package/dist/src/prediction/bcs.d.ts +22 -0
  96. package/dist/src/prediction/bcs.js +240 -0
  97. package/dist/src/prediction/client.d.ts +75 -0
  98. package/dist/src/prediction/client.js +164 -0
  99. package/dist/src/prediction/config.d.ts +60 -0
  100. package/dist/src/prediction/config.js +75 -0
  101. package/dist/src/prediction/constants.d.ts +44 -0
  102. package/dist/src/prediction/constants.js +46 -0
  103. package/dist/src/prediction/fetch.d.ts +82 -0
  104. package/dist/src/prediction/fetch.js +270 -0
  105. package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +100 -0
  106. package/dist/src/prediction/generated/bucket_v2_framework/account.js +129 -0
  107. package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +6 -0
  108. package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +19 -0
  109. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +10 -0
  110. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.js +14 -0
  111. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +36 -0
  112. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +27 -0
  113. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_set.d.ts +16 -0
  114. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_set.js +19 -0
  115. package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +382 -0
  116. package/dist/src/prediction/generated/bucket_v2_framework/double.js +466 -0
  117. package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +362 -0
  118. package/dist/src/prediction/generated/bucket_v2_framework/float.js +440 -0
  119. package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +193 -0
  120. package/dist/src/prediction/generated/bucket_v2_framework/liability.js +205 -0
  121. package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +384 -0
  122. package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +382 -0
  123. package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +344 -0
  124. package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +338 -0
  125. package/dist/src/prediction/generated/utils/index.d.ts +30 -0
  126. package/dist/src/prediction/generated/utils/index.js +160 -0
  127. package/dist/src/prediction/generated/waterx_account/account.d.ts +1589 -0
  128. package/dist/src/prediction/generated/waterx_account/account.js +1758 -0
  129. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +7 -0
  130. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +13 -0
  131. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +7 -0
  132. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +16 -0
  133. package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +6 -0
  134. package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +19 -0
  135. package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +10 -0
  136. package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +14 -0
  137. package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +12 -0
  138. package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +19 -0
  139. package/dist/src/prediction/generated/waterx_account/deps/sui/table.d.ts +24 -0
  140. package/dist/src/prediction/generated/waterx_account/deps/sui/table.js +31 -0
  141. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +36 -0
  142. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +27 -0
  143. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +16 -0
  144. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +19 -0
  145. package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +75 -0
  146. package/dist/src/prediction/generated/waterx_account/direct_rule.js +78 -0
  147. package/dist/src/prediction/generated/waterx_account/events.d.ts +33 -0
  148. package/dist/src/prediction/generated/waterx_account/events.js +137 -0
  149. package/dist/src/prediction/generated/waterx_account/version.d.ts +10 -0
  150. package/dist/src/prediction/generated/waterx_account/version.js +8 -0
  151. package/dist/src/prediction/generated/waterx_prediction/account_data.d.ts +327 -0
  152. package/dist/src/prediction/generated/waterx_prediction/account_data.js +405 -0
  153. package/dist/src/prediction/generated/waterx_prediction/admin.d.ts +5 -0
  154. package/dist/src/prediction/generated/waterx_prediction/admin.js +9 -0
  155. package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +60 -0
  156. package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +83 -0
  157. package/dist/src/prediction/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +8 -0
  158. package/dist/src/prediction/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.js +18 -0
  159. package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.d.ts +10 -0
  160. package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +14 -0
  161. package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +24 -0
  162. package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +31 -0
  163. package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +16 -0
  164. package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +19 -0
  165. package/dist/src/prediction/generated/waterx_prediction/events.d.ts +22 -0
  166. package/dist/src/prediction/generated/waterx_prediction/events.js +179 -0
  167. package/dist/src/prediction/generated/waterx_prediction/global_config.d.ts +116 -0
  168. package/dist/src/prediction/generated/waterx_prediction/global_config.js +141 -0
  169. package/dist/src/prediction/generated/waterx_prediction/order.d.ts +200 -0
  170. package/dist/src/prediction/generated/waterx_prediction/order.js +284 -0
  171. package/dist/src/prediction/generated/waterx_prediction/outcome.d.ts +58 -0
  172. package/dist/src/prediction/generated/waterx_prediction/outcome.js +73 -0
  173. package/dist/src/prediction/generated/waterx_prediction/position.d.ts +160 -0
  174. package/dist/src/prediction/generated/waterx_prediction/position.js +214 -0
  175. package/dist/src/prediction/generated/waterx_prediction/version.d.ts +10 -0
  176. package/dist/src/prediction/generated/waterx_prediction/version.js +8 -0
  177. package/dist/src/prediction/generated/waterx_prediction/view.d.ts +353 -0
  178. package/dist/src/prediction/generated/waterx_prediction/view.js +432 -0
  179. package/dist/src/prediction/generated/waterx_prediction/waterx_prediction.d.ts +1698 -0
  180. package/dist/src/prediction/generated/waterx_prediction/waterx_prediction.js +1733 -0
  181. package/dist/src/prediction/gift-link.d.ts +6 -0
  182. package/dist/src/prediction/gift-link.js +5 -0
  183. package/dist/src/prediction/gift.d.ts +223 -0
  184. package/dist/src/prediction/gift.js +451 -0
  185. package/dist/src/prediction/index.d.ts +29 -0
  186. package/dist/src/prediction/index.js +21 -0
  187. package/dist/src/prediction/prediction.d.ts +104 -0
  188. package/dist/src/prediction/prediction.js +317 -0
  189. package/dist/src/prediction/tx-builders.d.ts +44 -0
  190. package/dist/src/prediction/tx-builders.js +52 -0
  191. package/dist/src/prediction/types.d.ts +93 -0
  192. package/dist/src/prediction/types.js +1 -0
  193. package/dist/src/prediction/user/account.d.ts +2 -0
  194. package/dist/src/prediction/user/account.js +1 -0
  195. package/dist/src/prediction/user/admin.d.ts +6 -0
  196. package/dist/src/prediction/user/admin.js +3 -0
  197. package/dist/src/prediction/user/gift.d.ts +2 -0
  198. package/dist/src/prediction/user/gift.js +1 -0
  199. package/dist/src/prediction/user/index.d.ts +5 -0
  200. package/dist/src/prediction/user/index.js +3 -0
  201. package/dist/src/prediction/user/keeper.d.ts +2 -0
  202. package/dist/src/prediction/user/keeper.js +1 -0
  203. package/dist/src/prediction/user/order.d.ts +2 -0
  204. package/dist/src/prediction/user/order.js +1 -0
  205. package/dist/src/prediction/user/position.d.ts +2 -0
  206. package/dist/src/prediction/user/position.js +1 -0
  207. package/dist/src/prediction/utils/bcs.d.ts +1 -0
  208. package/dist/src/prediction/utils/bcs.js +1 -0
  209. package/dist/src/prediction/utils/index.d.ts +1 -0
  210. package/dist/src/prediction/utils/index.js +1 -0
  211. package/dist/src/prediction/utils.d.ts +30 -0
  212. package/dist/src/prediction/utils.js +177 -0
  213. package/dist/src/sdk.d.ts +18 -0
  214. package/dist/src/sdk.js +17 -0
  215. package/dist/src/tx-builders.d.ts +54 -0
  216. package/dist/src/tx-builders.js +141 -0
  217. package/dist/src/unified-client.d.ts +407 -0
  218. package/dist/src/unified-client.js +123 -0
  219. package/dist/src/user/account.d.ts +27 -0
  220. package/dist/src/user/account.js +34 -8
  221. package/dist/src/user/credit.d.ts +8 -14
  222. package/dist/src/user/credit.js +9 -23
  223. package/dist/src/user/custody.d.ts +4 -18
  224. package/dist/src/user/custody.js +14 -25
  225. package/dist/src/utils/consolidate-balance.d.ts +37 -0
  226. package/dist/src/utils/consolidate-balance.js +89 -0
  227. package/dist/src/utils/math.d.ts +86 -0
  228. package/dist/src/utils/math.js +100 -0
  229. package/dist/src/utils/pyth.d.ts +35 -3
  230. package/dist/src/utils/pyth.js +145 -14
  231. package/package.json +129 -34
@@ -19,8 +19,10 @@ import { bcs } from "@mysten/sui/bcs";
19
19
  // the market's `request_checklist` contains `PythSponsorRule`.
20
20
  // ============================================================================
21
21
  import { reimburse as sponsorReimburse, request as sponsorRequest, } from "../generated/pyth_sponsor_rule/pyth_sponsor_rule.js";
22
+ import { feed as constantRuleFeed } from "../generated/waterx_constant_rule/constant_rule.js";
22
23
  import { aggregate as aggregateCall, newCollector } from "../generated/waterx_oracle/oracle.js";
23
24
  import { feed as pythRuleFeed } from "../generated/waterx_pyth_rule/pyth_rule.js";
25
+ import { feed as supraRuleFeed } from "../generated/waterx_supra_rule/supra_rule.js";
24
26
  export class PythCache {
25
27
  pythStateInfo;
26
28
  wormholePackageId;
@@ -246,6 +248,11 @@ export function aggregateTickerWithPyth(tx, client, args) {
246
248
  pythPriceInfo: tx.object(args.priceInfoObjectId),
247
249
  },
248
250
  })(tx);
251
+ // Second weighted rule: when supra_rule is deployed + enabled, feed it on the
252
+ // SAME collector before aggregate. Supra reads the symbol from the collector
253
+ // and abstains on-chain if it has no pair id for it, so this is safe to add
254
+ // unconditionally for every Pyth ticker once enabled.
255
+ maybeFeedSupra(tx, client, collector);
249
256
  aggregateCall({
250
257
  package: client.config.packages.waterx_oracle.published_at,
251
258
  arguments: {
@@ -255,25 +262,149 @@ export function aggregateTickerWithPyth(tx, client, args) {
255
262
  })(tx);
256
263
  }
257
264
  /**
258
- * Refresh multiple tickers via Pyth in one PTB. Updates Pyth on-chain
259
- * first (one accumulator), then runs the collector feed → aggregate
260
- * cycle for each ticker.
265
+ * Append a `supra_rule::feed` on `collector` when the deployment has supra
266
+ * enabled + wired (see {@link WaterXClient.getSupraRule}). No-op otherwise, so
267
+ * Pyth-only deployments are unchanged.
268
+ */
269
+ function maybeFeedSupra(tx, client, collector) {
270
+ const supra = client.getSupraRule();
271
+ if (!supra)
272
+ return;
273
+ supraRuleFeed({
274
+ package: supra.published_at,
275
+ arguments: {
276
+ collector,
277
+ config: tx.object(supra.config),
278
+ oracleHolder: tx.object(supra.oracle_holder),
279
+ },
280
+ })(tx);
281
+ }
282
+ /**
283
+ * For a constant-priced ticker (e.g. `USDCUSD → $1`), build the
284
+ * collector → constant_rule::feed → aggregate chain. No Pyth update is
285
+ * needed — the price comes from the on-chain `constant_rule::Config`.
286
+ */
287
+ export function aggregateTickerWithConstant(tx, client, args) {
288
+ const constant = client.config.packages.waterx_constant_rule;
289
+ if (!constant?.published_at || !constant.config) {
290
+ throw new Error(`waterx_constant_rule.{published_at,config} missing — cannot feed constant ticker '${args.ticker}'`);
291
+ }
292
+ const collector = newCollector({
293
+ package: client.config.packages.waterx_oracle.published_at,
294
+ arguments: { symbol: args.ticker },
295
+ })(tx);
296
+ constantRuleFeed({
297
+ package: constant.published_at,
298
+ arguments: {
299
+ collector: collector,
300
+ config: tx.object(constant.config),
301
+ },
302
+ })(tx);
303
+ aggregateCall({
304
+ package: client.config.packages.waterx_oracle.published_at,
305
+ arguments: {
306
+ oracle: tx.object(client.config.packages.waterx_oracle.oracle),
307
+ collector: collector,
308
+ },
309
+ })(tx);
310
+ }
311
+ /**
312
+ * For a dual-feed ticker mid-migration (e.g. `USDCUSD`), build one collector
313
+ * fed by *both* `pyth_rule::feed` (+ `supra_rule::feed` when enabled) *and*
314
+ * `constant_rule::feed`, then `aggregate`. Used while the aggregator carries the
315
+ * `{Pyth, Constant}` weight set so neither weighted rule is missing from the
316
+ * collector (`aggregator::remove_outliers` aborts `EMissingPriceSource`
317
+ * otherwise). Still needs a fresh Pyth `PriceInfoObject`, so the caller must
318
+ * have run the Pyth update for this ticker first.
319
+ *
320
+ * Stays correct once weights are flipped to `{Constant}` only — the extra Pyth
321
+ * observation is dropped as a non-weighted rule — so a dual-feed ticker is safe
322
+ * across the whole transition; drop it from `dual_feed` (→ constant-only) once
323
+ * `PythRule` weight is 0.
324
+ */
325
+ export function aggregateTickerWithDual(tx, client, args) {
326
+ const constant = client.config.packages.waterx_constant_rule;
327
+ if (!constant?.published_at || !constant.config) {
328
+ throw new Error(`waterx_constant_rule.{published_at,config} missing — cannot dual-feed ticker '${args.ticker}'`);
329
+ }
330
+ const collector = newCollector({
331
+ package: client.config.packages.waterx_oracle.published_at,
332
+ arguments: { symbol: args.ticker },
333
+ })(tx);
334
+ pythRuleFeed({
335
+ package: client.config.packages.pyth_rule.published_at,
336
+ arguments: {
337
+ collector: collector,
338
+ config: tx.object(client.config.packages.pyth_rule.config),
339
+ pythState: tx.object(client.pyth.state_id),
340
+ pythPriceInfo: tx.object(args.priceInfoObjectId),
341
+ },
342
+ })(tx);
343
+ // Second weighted rule (when enabled) on the same collector, matching the
344
+ // pure-Pyth path.
345
+ maybeFeedSupra(tx, client, collector);
346
+ // The constant rule — the leg that lets the aggregator carry a Constant weight.
347
+ constantRuleFeed({
348
+ package: constant.published_at,
349
+ arguments: {
350
+ collector: collector,
351
+ config: tx.object(constant.config),
352
+ },
353
+ })(tx);
354
+ aggregateCall({
355
+ package: client.config.packages.waterx_oracle.published_at,
356
+ arguments: {
357
+ oracle: tx.object(client.config.packages.waterx_oracle.oracle),
358
+ collector: collector,
359
+ },
360
+ })(tx);
361
+ }
362
+ /**
363
+ * Refresh multiple tickers in one PTB. Routing per ticker:
364
+ * - **constant-only** (see {@link WaterXClient.isConstantOnlyTicker}) — fed from
365
+ * `constant_rule`, skips Pyth entirely;
366
+ * - **dual-feed** ({@link WaterXClient.isDualFeedTicker}) — fed by both Pyth and
367
+ * `constant_rule` (needs the Pyth update);
368
+ * - **Pyth** — the rest.
369
+ *
370
+ * Pyth-priced tickers (Pyth-only + dual) are updated on-chain via Pyth first
371
+ * (one accumulator), then each ticker runs its collector → feed → aggregate.
261
372
  */
262
373
  export async function refreshOraclePrices(tx, client, tickers, opts = {}) {
263
374
  if (tickers.length === 0)
264
375
  return;
265
- // tickers are oracle tickers (e.g. "BTCUSD"); look up each one's pyth feed
266
- // entry from config both feed_id (off-chain) and price_info_object
267
- // (on-chain) are consumed by the per-ticker aggregate cycle.
268
- const entries = tickers.map((t) => client.getPythFeed(t));
269
- const feedIds = entries.map((e) => e.feed_id);
270
- await updatePythPrices(tx, client, feedIds, opts.cache, opts.sponsorFund);
271
- tickers.forEach((ticker, i) => {
272
- aggregateTickerWithPyth(tx, client, {
273
- ticker,
274
- priceInfoObjectId: entries[i].price_info_object,
376
+ // Route each ticker to its rule. Dual-feed tickers are constant *and* Pyth, so
377
+ // they go through the Pyth update with the Pyth-only tickers but aggregate via
378
+ // the dual leg; only constant-*only* tickers skip Pyth entirely.
379
+ const constantOnlyTickers = tickers.filter((t) => client.isConstantOnlyTicker(t));
380
+ const pythTickers = tickers.filter((t) => !client.isConstantTicker(t));
381
+ const dualTickers = tickers.filter((t) => client.isDualFeedTicker(t));
382
+ // Pyth update covers both Pyth-only and dual-feed tickers.
383
+ const pythUpdateTickers = [...pythTickers, ...dualTickers];
384
+ if (pythUpdateTickers.length > 0) {
385
+ // Oracle tickers (e.g. "BTCUSD") → each one's pyth feed entry: feed_id
386
+ // (off-chain) drives the accumulator; price_info_object (on-chain) is
387
+ // consumed by the per-ticker aggregate cycle.
388
+ const entries = pythUpdateTickers.map((t) => client.getPythFeed(t));
389
+ const feedIds = entries.map((e) => e.feed_id);
390
+ await updatePythPrices(tx, client, feedIds, opts.cache, opts.sponsorFund);
391
+ pythTickers.forEach((ticker, i) => {
392
+ aggregateTickerWithPyth(tx, client, {
393
+ ticker,
394
+ priceInfoObjectId: entries[i].price_info_object,
395
+ });
275
396
  });
276
- });
397
+ dualTickers.forEach((ticker, i) => {
398
+ // dual entries are appended after the pyth-only ones.
399
+ aggregateTickerWithDual(tx, client, {
400
+ ticker,
401
+ priceInfoObjectId: entries[pythTickers.length + i].price_info_object,
402
+ });
403
+ });
404
+ }
405
+ for (const ticker of constantOnlyTickers) {
406
+ aggregateTickerWithConstant(tx, client, { ticker });
407
+ }
277
408
  }
278
409
  /**
279
410
  * Opens a `Fund` hot potato from the shared PythSponsor pool. Pass the
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@waterx/sdk",
3
- "version": "2.1.0",
4
- "description": "WaterX Perpetual Protocol SDK",
3
+ "version": "2.3.1-dev.0",
4
+ "description": "WaterX SDK perpetuals and prediction markets on Sui",
5
5
  "license": "MIT",
6
6
  "author": "WaterX",
7
7
  "repository": {
@@ -9,8 +9,51 @@
9
9
  "url": "https://github.com/WaterXProtocol/waterx-sdk.git"
10
10
  },
11
11
  "type": "module",
12
- "main": "dist/src/index.js",
13
- "types": "dist/src/index.d.ts",
12
+ "main": "dist/src/sdk.js",
13
+ "types": "dist/src/sdk.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/src/sdk.d.ts",
17
+ "import": "./dist/src/sdk.js"
18
+ },
19
+ "./perp": {
20
+ "types": "./dist/src/index.d.ts",
21
+ "import": "./dist/src/index.js"
22
+ },
23
+ "./perp/*": {
24
+ "types": "./dist/src/*.d.ts",
25
+ "import": "./dist/src/*.js"
26
+ },
27
+ "./prediction": {
28
+ "types": "./dist/src/prediction/index.d.ts",
29
+ "import": "./dist/src/prediction/index.js"
30
+ },
31
+ "./prediction/user": {
32
+ "types": "./dist/src/prediction/user/index.d.ts",
33
+ "import": "./dist/src/prediction/user/index.js"
34
+ },
35
+ "./prediction/user/*": {
36
+ "types": "./dist/src/prediction/user/*.d.ts",
37
+ "import": "./dist/src/prediction/user/*.js"
38
+ },
39
+ "./prediction/utils": {
40
+ "types": "./dist/src/prediction/utils/index.d.ts",
41
+ "import": "./dist/src/prediction/utils/index.js"
42
+ },
43
+ "./prediction/utils/*": {
44
+ "types": "./dist/src/prediction/utils/*.d.ts",
45
+ "import": "./dist/src/prediction/utils/*.js"
46
+ },
47
+ "./prediction/*": {
48
+ "types": "./dist/src/prediction/*.d.ts",
49
+ "import": "./dist/src/prediction/*.js"
50
+ },
51
+ "./generated/*": {
52
+ "types": "./dist/src/generated/*.d.ts",
53
+ "import": "./dist/src/generated/*.js"
54
+ },
55
+ "./package.json": "./package.json"
56
+ },
14
57
  "files": [
15
58
  "dist",
16
59
  "LICENSE",
@@ -21,46 +64,98 @@
21
64
  "codegen": "tsx scripts/codegen-summaries.ts && npx sui-ts-codegen generate && tsx scripts/fix-generated-imports.ts",
22
65
  "lint": "pnpm lint:eslint && pnpm lint:prettier",
23
66
  "lint:eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\"",
24
- "lint:prettier": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\" \"eslint.config.mjs\" \"sui-codegen.config.mjs\"",
67
+ "lint:prettier": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\" \"eslint.config.mjs\" \"sui-codegen.config.mjs\" \"packages/predict-stress/**/*.{ts,mjs,json,md}\"",
25
68
  "lint:fix": "eslint \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\" --fix",
26
- "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\" \"eslint.config.mjs\" \"sui-codegen.config.mjs\"",
69
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\" \"eslint.config.mjs\" \"sui-codegen.config.mjs\" \"packages/predict-stress/**/*.{ts,mjs,json,md}\"",
27
70
  "env:init": "tsx scripts/init-local-env.ts",
28
71
  "typecheck": "tsc --noEmit",
29
- "test:integration": "tsx scripts/run-integration.ts --testnet",
30
- "test:integration:mainnet": "tsx scripts/run-integration.ts --mainnet",
31
- "test:integration:lifecycle": "tsx scripts/run-integration.ts --testnet test/integration/user/trader-position-lifecycle.test.ts",
32
- "test:integration:market-config": "tsx scripts/run-integration.ts --testnet test/integration/user/trader-market-onchain-config.test.ts",
33
- "test:integration:persistent-state": "tsx scripts/run-integration.ts --testnet test/integration/user/trader-e2e-persistent-state.test.ts",
34
- "test:integration:gap": "tsx scripts/run-integration.ts --testnet test/integration/user/trader-wlp-redeem.test.ts test/integration/user/trader-staking.test.ts test/integration/user/trader-keeper-roundtrip.test.ts test/integration/user/trader-custody.test.ts test/integration/user/trader-credit-pipeline.test.ts",
35
- "test:integration:onboarding": "tsx scripts/run-integration.ts --testnet test/integration/user/trader-full-onboarding.test.ts",
72
+ "check": "pnpm lint && pnpm typecheck && pnpm test:unit",
73
+ "test": "vitest run --project unit --project predict-unit",
74
+ "test:unit": "vitest run --project unit --project predict-unit",
75
+ "test:unit:perp": "vitest run --project unit",
76
+ "test:unit:predict": "vitest run --project predict-unit",
77
+ "test:post-build": "vitest run --project post-build",
78
+ "test:e2e": "tsx scripts/run-e2e.ts --testnet --predict",
79
+ "test:e2e:perp": "tsx scripts/run-e2e.ts --testnet",
80
+ "test:e2e:predict": "tsx scripts/run-e2e.ts --testnet --predict-only",
81
+ "test:e2e:testnet": "tsx scripts/run-e2e.ts --testnet --predict",
82
+ "test:e2e:mainnet": "tsx scripts/run-e2e.ts --mainnet --predict",
83
+ "test:integration": "pnpm test:integration:perp && pnpm test:integration:predict",
84
+ "test:integration:perp": "tsx scripts/run-integration.ts --testnet",
85
+ "test:integration:predict": "vitest run --project predict-integration",
86
+ "test:integration:predict:keeper": "vitest run --project predict-integration-keeper",
87
+ "test:integration:predict:admin": "vitest run --project predict-integration-admin",
88
+ "test:integration:predict:all": "vitest run --project predict-integration --project predict-integration-keeper --project predict-integration-admin",
89
+ "test:api": "node test/prediction/scripts/run-api-tests.mjs",
90
+ "test:api:local": "node test/prediction/scripts/run-api-tests.mjs --env local",
91
+ "test:api:staging": "node test/prediction/scripts/run-api-tests.mjs --env staging",
92
+ "test:integration:predict:crosscheck": "E2E_API_ENV=staging E2E_API_CROSSCHECK=1 vitest run --project predict-integration-crosscheck",
93
+ "test:integration:predict:settlement-crosscheck": "E2E_API_ENV=staging E2E_SETTLEMENT_CROSSCHECK=1 vitest run --project predict-integration-settlement-crosscheck",
94
+ "test:integration:predict:headless": "E2E_API_ENV=staging E2E_HEADLESS_BET=1 vitest run --project predict-integration-headless",
95
+ "test:integration:predict:journey": "vitest run --project predict-integration test/prediction/integration/user-betting-journey.test.ts",
96
+ "test:integration:perp:mainnet": "tsx scripts/run-integration.ts --mainnet",
97
+ "test:integration:perp:lifecycle": "tsx scripts/run-integration.ts --testnet test/perp/integration/user/trader-position-lifecycle.test.ts",
98
+ "test:integration:perp:market-config": "tsx scripts/run-integration.ts --testnet test/perp/integration/user/trader-market-onchain-config.test.ts",
99
+ "test:integration:perp:persistent-state": "tsx scripts/run-integration.ts --testnet test/perp/integration/user/trader-e2e-persistent-state.test.ts",
100
+ "test:integration:perp:gap": "tsx scripts/run-integration.ts --testnet test/perp/integration/user/trader-wlp-redeem.test.ts test/perp/integration/user/trader-staking.test.ts test/perp/integration/user/trader-keeper-roundtrip.test.ts test/perp/integration/user/trader-custody.test.ts test/perp/integration/user/trader-credit-pipeline.test.ts",
101
+ "test:integration:perp:onboarding": "tsx scripts/run-integration.ts --testnet test/perp/integration/user/trader-full-onboarding.test.ts",
36
102
  "smoke:chain": "tsx scripts/run-smoke-chain.ts",
37
- "smoke:chain:dry": "tsx scripts/run-smoke-chain.ts --dry-run"
103
+ "smoke:chain:dry": "tsx scripts/run-smoke-chain.ts --dry-run",
104
+ "seed:testnet": "tsx test/prediction/scripts/seed-testnet.ts",
105
+ "predict:list-accounts": "tsx test/prediction/scripts/list-accounts.ts",
106
+ "predict:bootstrap-stress-accounts": "tsx test/prediction/scripts/bootstrap-stress-accounts.ts",
107
+ "predict:bootstrap-stress-deposits": "tsx test/prediction/scripts/bootstrap-stress-deposits.ts",
108
+ "mint:api-jwt": "node test/prediction/scripts/mint-api-jwt.mjs",
109
+ "mint:api-jwt:staging": "node test/prediction/scripts/fetch-staging-api-jwt.mjs",
110
+ "diagnose:bets-api": "tsx test/prediction/scripts/diagnose-bets-chain-api.ts",
111
+ "predict:scan-claimable": "E2E_API_ENV=staging tsx test/prediction/scripts/scan-claimable-crosscheck.ts",
112
+ "predict:place-all-markets": "E2E_API_ENV=staging tsx test/prediction/scripts/place-all-catalog-markets.ts",
113
+ "predict:place-dry-run": "E2E_API_ENV=staging E2E_PLACE_ALL_DRY_RUN=1 tsx test/prediction/scripts/place-all-catalog-markets.ts",
114
+ "predict:place-broker-only": "E2E_API_ENV=staging E2E_PLACE_ALL_BROKER_ONLY=1 E2E_PLACE_ALL_ONE_SIDE=1 E2E_PLACE_ALL_LIMIT=1 tsx test/prediction/scripts/place-all-catalog-markets.ts",
115
+ "predict:place-and-watch": "E2E_API_ENV=staging E2E_STAGING_BET_USD=1.12 E2E_PLACE_ALL_PLACE_ONLY=1 E2E_PLACE_ALL_ONE_SIDE=1 E2E_PLACE_ALL_LIMIT=1 tsx test/prediction/scripts/place-all-catalog-markets.ts",
116
+ "predict:place-stress": "E2E_API_ENV=staging tsx test/prediction/scripts/place-stress-multi-wallet.ts",
117
+ "predict:place-stress-dry-run": "E2E_API_ENV=staging E2E_STRESS_DRY_RUN=1 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
118
+ "predict:place-stress-smoke": "E2E_API_ENV=staging E2E_STRESS_PHASES=1 E2E_STRESS_PLACE_ONLY=1 E2E_STRESS_COOLDOWN_MS=0 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
119
+ "predict:place-stress-smoke-fill": "E2E_API_ENV=staging E2E_STRESS_PHASES=1 E2E_STRESS_COOLDOWN_MS=0 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
120
+ "predict:place-stress-ramp": "E2E_API_ENV=staging tsx test/prediction/scripts/place-stress-multi-wallet.ts",
121
+ "predict:place-stress-timing": "E2E_API_ENV=staging E2E_STRESS_PHASES=1,2,4,8 E2E_STRESS_COOLDOWN_MS=30000 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
122
+ "predict:place-stress-timing-max": "E2E_API_ENV=staging E2E_STRESS_PHASES=8 E2E_STRESS_COOLDOWN_MS=0 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
123
+ "predict:place-stress-hammer": "E2E_API_ENV=staging E2E_STRESS_HAMMER=1 E2E_STRESS_PLACE_ONLY=1 E2E_STRESS_COOLDOWN_MS=0 E2E_STRESS_ROUNDS=10 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
124
+ "predict:place-stress-hammer-smoke": "E2E_API_ENV=staging E2E_STRESS_HAMMER=1 E2E_STRESS_PLACE_ONLY=1 E2E_STRESS_COOLDOWN_MS=0 E2E_STRESS_ROUNDS=1 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
125
+ "predict-stress": "pnpm --dir packages/predict-stress",
126
+ "predict:refund-probe": "E2E_API_ENV=staging tsx test/prediction/scripts/probe-catalog-refund.ts",
127
+ "predict:broker-matrix": "E2E_API_ENV=staging tsx test/prediction/scripts/probe-broker-matrix.ts",
128
+ "test:integration:predict:refund": "E2E_API_ENV=staging E2E_CATALOG_REFUND=1 vitest run --project predict-integration-refund",
129
+ "test:integration:predict:broker-matrix": "E2E_API_ENV=staging E2E_BROKER_MATRIX=1 vitest run --project predict-integration-broker-matrix"
130
+ },
131
+ "dependencies": {
132
+ "@noble/hashes": "^2.2.0"
38
133
  },
39
134
  "peerDependencies": {
40
135
  "@mysten/bcs": "^1.9.0",
41
136
  "@mysten/sui": "^2.9.0"
42
137
  },
43
138
  "devDependencies": {
44
- "@eslint/js": "^9.39.4",
45
- "@ianvs/prettier-plugin-sort-imports": "^4.7.1",
46
- "@mysten/bcs": "^1.9.2",
47
- "@mysten/sui": "^2.9.1",
48
- "@mysten/codegen": "^0.8.3",
49
- "@types/node": "^24.12.0",
50
- "@typescript-eslint/eslint-plugin": "^8.58.0",
51
- "@typescript-eslint/parser": "^8.58.0",
52
- "eslint": "^9.39.4",
53
- "eslint-config-prettier": "^10.1.8",
54
- "globals": "^17.4.0",
55
- "prettier": "^3.8.1",
56
- "tsc-alias": "^1.8.16",
57
- "tsconfig-paths": "^4.2.0",
58
- "tsx": "^4.21.0",
59
- "typescript": "^5.9.3",
60
- "typescript-eslint": "^8.58.0",
61
- "@vitest/coverage-v8": "^3.2.4",
62
- "dotenv": "^17.4.0",
63
- "vitest": "^3.2.4"
139
+ "@eslint/js": "10.0.1",
140
+ "@ianvs/prettier-plugin-sort-imports": "4.7.1",
141
+ "@mysten/bcs": "1.9.2",
142
+ "@mysten/codegen": "0.10.6",
143
+ "@mysten/sui": "2.17.0",
144
+ "@types/node": "25.9.1",
145
+ "@typescript-eslint/eslint-plugin": "8.60.0",
146
+ "@typescript-eslint/parser": "8.60.0",
147
+ "@vitest/coverage-v8": "4.1.8",
148
+ "dotenv": "17.4.2",
149
+ "eslint": "10.4.1",
150
+ "eslint-config-prettier": "10.1.8",
151
+ "globals": "17.6.0",
152
+ "prettier": "3.8.3",
153
+ "tsc-alias": "1.8.17",
154
+ "tsconfig-paths": "4.2.0",
155
+ "tsx": "4.22.4",
156
+ "typescript": "6.0.3",
157
+ "typescript-eslint": "8.60.0",
158
+ "vitest": "4.1.8"
64
159
  },
65
160
  "packageManager": "pnpm@9.15.0"
66
161
  }