@waterx/sdk 2.1.0 → 2.4.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 +40 -2
  3. package/dist/src/client.js +55 -6
  4. package/dist/src/config.d.ts +66 -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 +42 -7
  230. package/dist/src/utils/pyth.js +107 -31
  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;
@@ -226,54 +228,128 @@ export async function updatePythPrices(tx, client, feedIds, cache, sponsorFund)
226
228
  // Per-ticker refresh: collector → pyth_rule::feed → oracle::aggregate
227
229
  // ============================================================================
228
230
  /**
229
- * For a given ticker, build the collector feed aggregate chain that
230
- * refreshes the on-chain `Oracle` aggregator for that ticker.
231
+ * Aggregate one ticker's price into the shared `Oracle`: build a collector, feed
232
+ * every rule the ticker is configured for, then `aggregate`. The fed rule set must
233
+ * match the on-chain weighted set for the ticker — `aggregator::remove_outliers`
234
+ * aborts `EMissingPriceSource` if a weighted rule is missing from the collector:
231
235
  *
232
- * Caller must have first called `buildPythPriceUpdateCalls` /
233
- * `updatePythPrices` so the corresponding `PriceInfoObject` is fresh.
236
+ * - **Pyth** fed when `priceInfoObjectId` is supplied (i.e. the ticker has a
237
+ * `pyth_rule.feeds` entry). Caller must run the Pyth update first so the
238
+ * `PriceInfoObject` is fresh.
239
+ * - **Supra** — fed alongside Pyth when supra is enabled + wired (abstains on-chain
240
+ * for symbols it has no pair for).
241
+ * - **Constant** — fed when the ticker is a constant ticker
242
+ * ({@link WaterXClient.isConstantTicker}).
243
+ *
244
+ * "Dual-feed" (Pyth + Constant) and "constant-only" are not special cases — they
245
+ * fall out of which rules the ticker is in: a constant ticker that also has a Pyth
246
+ * feed gets both; one with no Pyth feed (no `priceInfoObjectId`) gets constant only.
247
+ * Throws if no rule applies to the ticker.
234
248
  */
235
- export function aggregateTickerWithPyth(tx, client, args) {
249
+ export function aggregateTicker(tx, client, args) {
250
+ const oraclePkg = client.config.packages.waterx_oracle.published_at;
236
251
  const collector = newCollector({
237
- package: client.config.packages.waterx_oracle.published_at,
252
+ package: oraclePkg,
238
253
  arguments: { symbol: args.ticker },
239
254
  })(tx);
240
- pythRuleFeed({
241
- package: client.config.packages.pyth_rule.published_at,
255
+ let fed = false;
256
+ if (args.priceInfoObjectId) {
257
+ pythRuleFeed({
258
+ package: client.config.packages.pyth_rule.published_at,
259
+ arguments: {
260
+ collector,
261
+ config: tx.object(client.config.packages.pyth_rule.config),
262
+ pythState: tx.object(client.pyth.state_id),
263
+ pythPriceInfo: tx.object(args.priceInfoObjectId),
264
+ },
265
+ })(tx);
266
+ // Supra rides on the same collector when enabled (abstains on-chain otherwise).
267
+ maybeFeedSupra(tx, client, collector);
268
+ fed = true;
269
+ }
270
+ if (client.isConstantTicker(args.ticker)) {
271
+ const constant = client.config.packages.constant_rule;
272
+ constantRuleFeed({
273
+ package: constant.published_at,
274
+ arguments: { collector, config: tx.object(constant.config) },
275
+ })(tx);
276
+ fed = true;
277
+ }
278
+ if (!fed) {
279
+ throw new Error(`no oracle rule configured for ticker '${args.ticker}' (no pyth feed, not a constant ticker)`);
280
+ }
281
+ aggregateCall({
282
+ package: oraclePkg,
242
283
  arguments: {
243
- collector: collector,
244
- config: tx.object(client.config.packages.pyth_rule.config),
245
- pythState: tx.object(client.pyth.state_id),
246
- pythPriceInfo: tx.object(args.priceInfoObjectId),
284
+ oracle: tx.object(client.config.packages.waterx_oracle.oracle),
285
+ collector,
247
286
  },
248
287
  })(tx);
249
- aggregateCall({
250
- package: client.config.packages.waterx_oracle.published_at,
288
+ }
289
+ /**
290
+ * Thin wrapper over {@link aggregateTicker} for a Pyth-fed ticker. Kept for
291
+ * back-compat (e.g. WLP mint builds). Caller must run the Pyth update first.
292
+ */
293
+ export function aggregateTickerWithPyth(tx, client, args) {
294
+ aggregateTicker(tx, client, args);
295
+ }
296
+ /**
297
+ * Append a `supra_rule::feed` on `collector` when the deployment has supra
298
+ * enabled + wired (see {@link WaterXClient.getSupraRule}). No-op otherwise, so
299
+ * Pyth-only deployments are unchanged.
300
+ */
301
+ function maybeFeedSupra(tx, client, collector) {
302
+ const supra = client.getSupraRule();
303
+ if (!supra)
304
+ return;
305
+ supraRuleFeed({
306
+ package: supra.published_at,
251
307
  arguments: {
252
- oracle: tx.object(client.config.packages.waterx_oracle.oracle),
253
- collector: collector,
308
+ collector,
309
+ config: tx.object(supra.config),
310
+ oracleHolder: tx.object(supra.oracle_holder),
254
311
  },
255
312
  })(tx);
256
313
  }
257
314
  /**
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.
315
+ * {@link aggregateTicker} for a **constant-only** ticker (no Pyth update needed
316
+ * the price comes from the on-chain `constant_rule::Config`).
317
+ *
318
+ * Throws if the ticker ALSO has a `pyth_rule.feeds` entry (a dual-feed transition
319
+ * ticker): feeding only the constant leg would leave the still-weighted Pyth rule
320
+ * absent from the collector and abort `aggregate` with `EMissingPriceSource`. Such
321
+ * tickers must go through {@link aggregateTicker} with a `priceInfoObjectId` (or
322
+ * {@link refreshOraclePrices}), which feeds both.
323
+ */
324
+ export function aggregateTickerWithConstant(tx, client, args) {
325
+ if (client.config.packages.pyth_rule?.feeds?.[args.ticker] !== undefined) {
326
+ throw new Error(`'${args.ticker}' is in pyth_rule.feeds (dual-feed) — feed both via aggregateTicker({ priceInfoObjectId }) / refreshOraclePrices, not aggregateTickerWithConstant`);
327
+ }
328
+ aggregateTicker(tx, client, { ticker: args.ticker });
329
+ }
330
+ /**
331
+ * Refresh multiple tickers in one PTB. For each ticker {@link aggregateTicker}
332
+ * feeds whichever rules it is configured for (Pyth if it has a `pyth_rule.feeds`
333
+ * entry, Supra when enabled, Constant when it's a constant ticker). Tickers with a
334
+ * Pyth feed are updated on-chain via one shared Pyth accumulator first; the rest
335
+ * (constant-only) skip Pyth entirely.
261
336
  */
262
337
  export async function refreshOraclePrices(tx, client, tickers, opts = {}) {
263
338
  if (tickers.length === 0)
264
339
  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,
275
- });
276
- });
340
+ // Every ticker with a pyth_rule.feeds entry needs the on-chain Pyth update
341
+ // first (one shared accumulator). Constant-only tickers (no pyth feed) skip it.
342
+ const pythTickers = tickers.filter((t) => client.config.packages.pyth_rule?.feeds?.[t] !== undefined);
343
+ const priceInfoByTicker = new Map();
344
+ if (pythTickers.length > 0) {
345
+ const entries = pythTickers.map((t) => client.getPythFeed(t));
346
+ await updatePythPrices(tx, client, entries.map((e) => e.feed_id), opts.cache, opts.sponsorFund);
347
+ pythTickers.forEach((t, i) => priceInfoByTicker.set(t, entries[i].price_info_object));
348
+ }
349
+ // Aggregate each ticker, feeding whichever rules it is configured for.
350
+ for (const ticker of tickers) {
351
+ aggregateTicker(tx, client, { ticker, priceInfoObjectId: priceInfoByTicker.get(ticker) });
352
+ }
277
353
  }
278
354
  /**
279
355
  * 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.4.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
  }