@waterx/sdk 2.4.1 → 3.0.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 (222) hide show
  1. package/README.md +25 -21
  2. package/dist/src/{utils → account}/account-request.d.ts +2 -2
  3. package/dist/src/{user → account}/account.d.ts +23 -21
  4. package/dist/src/{user → account}/account.js +5 -5
  5. package/dist/src/account/client.d.ts +42 -0
  6. package/dist/src/account/client.js +17 -0
  7. package/dist/src/account/config.d.ts +151 -0
  8. package/dist/src/account/config.js +8 -0
  9. package/dist/src/account/constants.d.ts +5 -0
  10. package/dist/src/account/constants.js +5 -0
  11. package/dist/src/account/fetch/referral.d.ts +15 -0
  12. package/dist/src/account/fetch/referral.js +51 -0
  13. package/dist/src/account/fetch/simulate.d.ts +34 -0
  14. package/dist/src/account/fetch/simulate.js +43 -0
  15. package/dist/src/{utils/consolidate-balance.d.ts → account/funding/balance.d.ts} +3 -8
  16. package/dist/src/{utils/consolidate-balance.js → account/funding/balance.js} +6 -1
  17. package/dist/src/account/funding/consolidate.d.ts +46 -0
  18. package/dist/src/account/funding/consolidate.js +137 -0
  19. package/dist/src/{user → account/funding}/credit.d.ts +10 -10
  20. package/dist/src/{user → account/funding}/credit.js +6 -6
  21. package/dist/src/{user → account/funding}/custody.d.ts +4 -4
  22. package/dist/src/{user → account/funding}/custody.js +2 -2
  23. package/dist/src/{utils → account/funding}/wormhole.d.ts +4 -4
  24. package/dist/src/{utils → account/funding}/wormhole.js +1 -1
  25. package/dist/src/account/index.d.ts +29 -0
  26. package/dist/src/account/index.js +29 -0
  27. package/dist/src/{user → account}/referral.d.ts +3 -3
  28. package/dist/src/{user → account}/referral.js +1 -1
  29. package/dist/src/base-client.d.ts +74 -0
  30. package/dist/src/base-client.js +97 -0
  31. package/dist/src/constants.d.ts +4 -46
  32. package/dist/src/constants.js +8 -52
  33. package/dist/src/generated/bucket_v2_framework/liability.d.ts +0 -26
  34. package/dist/src/generated/bucket_v2_framework/liability.js +0 -28
  35. package/dist/src/generated/waterx_account/account.d.ts +50 -15
  36. package/dist/src/generated/waterx_account/account.js +51 -15
  37. package/dist/src/generated/waterx_oracle/oracle.d.ts +7 -1
  38. package/dist/src/generated/waterx_oracle/oracle.js +7 -2
  39. package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.d.ts +19 -2
  40. package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.d.ts +3 -1
  41. package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/sui/balance.d.ts +3 -1
  42. package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.d.ts +6 -1
  43. package/dist/src/generated/waterx_prediction/events.d.ts +288 -0
  44. package/dist/src/{prediction/generated → generated}/waterx_prediction/events.js +39 -0
  45. package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.d.ts +6 -1
  46. package/dist/src/{prediction/generated → generated}/waterx_prediction/order.d.ts +34 -1
  47. package/dist/src/{prediction/generated → generated}/waterx_prediction/position.d.ts +16 -1
  48. package/dist/src/{prediction/generated → generated}/waterx_prediction/view.d.ts +69 -4
  49. package/dist/src/{prediction/generated → generated}/waterx_prediction/waterx_prediction.d.ts +162 -2
  50. package/dist/src/{prediction/generated → generated}/waterx_prediction/waterx_prediction.js +99 -0
  51. package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +102 -0
  52. package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +99 -0
  53. package/dist/src/generated/waterx_supra_rule/supra_rule.d.ts +5 -5
  54. package/dist/src/generated/waterx_supra_rule/supra_rule.js +1 -2
  55. package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +23 -23
  56. package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +3 -6
  57. package/dist/src/oracle/aggregate.d.ts +74 -0
  58. package/dist/src/oracle/aggregate.js +112 -0
  59. package/dist/src/oracle/config.d.ts +99 -0
  60. package/dist/src/oracle/config.js +23 -0
  61. package/dist/src/oracle/host.d.ts +32 -0
  62. package/dist/src/oracle/host.js +10 -0
  63. package/dist/src/oracle/index.d.ts +16 -0
  64. package/dist/src/oracle/index.js +18 -0
  65. package/dist/src/oracle/pyth.d.ts +52 -0
  66. package/dist/src/oracle/pyth.js +220 -0
  67. package/dist/src/oracle/rules/constant-rule.d.ts +9 -0
  68. package/dist/src/oracle/rules/constant-rule.js +14 -0
  69. package/dist/src/oracle/rules/pyth-rule.d.ts +11 -0
  70. package/dist/src/oracle/rules/pyth-rule.js +20 -0
  71. package/dist/src/oracle/rules/sponsor.d.ts +28 -0
  72. package/dist/src/oracle/rules/sponsor.js +48 -0
  73. package/dist/src/oracle/rules/supra-rule.d.ts +11 -0
  74. package/dist/src/oracle/rules/supra-rule.js +22 -0
  75. package/dist/src/perp/client.d.ts +78 -0
  76. package/dist/src/perp/client.js +108 -0
  77. package/dist/src/{client.d.ts → perp/config-view.d.ts} +15 -60
  78. package/dist/src/{client.js → perp/config-view.js} +23 -95
  79. package/dist/src/perp/config.d.ts +126 -0
  80. package/dist/src/{config.js → perp/config.js} +11 -12
  81. package/dist/src/perp/constants.d.ts +49 -0
  82. package/dist/src/perp/constants.js +61 -0
  83. package/dist/src/perp/fetch/account.d.ts +43 -0
  84. package/dist/src/perp/fetch/account.js +64 -0
  85. package/dist/src/perp/fetch/bridge.d.ts +90 -0
  86. package/dist/src/perp/fetch/bridge.js +127 -0
  87. package/dist/src/perp/fetch/custody.d.ts +32 -0
  88. package/dist/src/perp/fetch/custody.js +62 -0
  89. package/dist/src/perp/fetch/market.d.ts +30 -0
  90. package/dist/src/perp/fetch/market.js +68 -0
  91. package/dist/src/perp/fetch/positions.d.ts +70 -0
  92. package/dist/src/perp/fetch/positions.js +185 -0
  93. package/dist/src/perp/fetch/simulate.d.ts +12 -0
  94. package/dist/src/perp/fetch/simulate.js +13 -0
  95. package/dist/src/perp/fetch.d.ts +23 -0
  96. package/dist/src/perp/fetch.js +23 -0
  97. package/dist/src/{index.d.ts → perp/index.d.ts} +21 -21
  98. package/dist/src/{index.js → perp/index.js} +21 -21
  99. package/dist/src/perp/tx-builders/common.d.ts +83 -0
  100. package/dist/src/perp/tx-builders/common.js +70 -0
  101. package/dist/src/perp/tx-builders/credit.d.ts +65 -0
  102. package/dist/src/perp/tx-builders/credit.js +62 -0
  103. package/dist/src/perp/tx-builders/rewards.d.ts +30 -0
  104. package/dist/src/perp/tx-builders/rewards.js +34 -0
  105. package/dist/src/perp/tx-builders/trading.d.ts +51 -0
  106. package/dist/src/perp/tx-builders/trading.js +59 -0
  107. package/dist/src/perp/tx-builders/wlp.d.ts +90 -0
  108. package/dist/src/perp/tx-builders/wlp.js +120 -0
  109. package/dist/src/perp/tx-builders.d.ts +23 -0
  110. package/dist/src/perp/tx-builders.js +23 -0
  111. package/dist/src/perp/user/index.d.ts +8 -0
  112. package/dist/src/perp/user/index.js +8 -0
  113. package/dist/src/{user → perp/user}/order.d.ts +7 -7
  114. package/dist/src/{user → perp/user}/order.js +3 -3
  115. package/dist/src/{user → perp/user}/staking.d.ts +4 -4
  116. package/dist/src/{user → perp/user}/staking.js +2 -2
  117. package/dist/src/{user → perp/user}/trading.d.ts +13 -13
  118. package/dist/src/{user → perp/user}/trading.js +2 -2
  119. package/dist/src/{user → perp/user}/wlp.d.ts +7 -7
  120. package/dist/src/{user → perp/user}/wlp.js +3 -3
  121. package/dist/src/prediction/account.js +40 -76
  122. package/dist/src/prediction/client.d.ts +8 -38
  123. package/dist/src/prediction/client.js +11 -67
  124. package/dist/src/prediction/config.d.ts +16 -2
  125. package/dist/src/prediction/config.js +10 -4
  126. package/dist/src/prediction/index.d.ts +11 -11
  127. package/dist/src/prediction/index.js +10 -10
  128. package/dist/src/prediction/prediction.d.ts +45 -0
  129. package/dist/src/prediction/prediction.js +71 -0
  130. package/dist/src/prediction/tx-builders.d.ts +4 -4
  131. package/dist/src/prediction/tx-builders.js +2 -2
  132. package/dist/src/prediction/user/index.d.ts +2 -2
  133. package/dist/src/prediction/user/index.js +1 -1
  134. package/dist/src/prediction/user/position.d.ts +2 -2
  135. package/dist/src/prediction/user/position.js +1 -1
  136. package/dist/src/prediction/utils/bcs.d.ts +5 -0
  137. package/dist/src/prediction/utils/bcs.js +5 -0
  138. package/dist/src/prediction/utils/index.d.ts +7 -0
  139. package/dist/src/prediction/utils/index.js +7 -0
  140. package/dist/src/sdk.d.ts +10 -6
  141. package/dist/src/sdk.js +9 -5
  142. package/dist/src/unified-client.d.ts +140 -145
  143. package/dist/src/unified-client.js +98 -40
  144. package/dist/src/utils/config.d.ts +1 -1
  145. package/package.json +22 -5
  146. package/dist/src/config.d.ts +0 -292
  147. package/dist/src/fetch.d.ts +0 -254
  148. package/dist/src/fetch.js +0 -564
  149. package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +0 -100
  150. package/dist/src/prediction/generated/bucket_v2_framework/account.js +0 -129
  151. package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +0 -6
  152. package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +0 -19
  153. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +0 -10
  154. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +0 -36
  155. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +0 -27
  156. package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +0 -382
  157. package/dist/src/prediction/generated/bucket_v2_framework/double.js +0 -466
  158. package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +0 -362
  159. package/dist/src/prediction/generated/bucket_v2_framework/float.js +0 -440
  160. package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +0 -193
  161. package/dist/src/prediction/generated/bucket_v2_framework/liability.js +0 -205
  162. package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +0 -384
  163. package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +0 -382
  164. package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +0 -344
  165. package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +0 -338
  166. package/dist/src/prediction/generated/utils/index.d.ts +0 -30
  167. package/dist/src/prediction/generated/utils/index.js +0 -160
  168. package/dist/src/prediction/generated/waterx_account/account.d.ts +0 -1589
  169. package/dist/src/prediction/generated/waterx_account/account.js +0 -1758
  170. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +0 -7
  171. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +0 -13
  172. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +0 -7
  173. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +0 -16
  174. package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +0 -6
  175. package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +0 -19
  176. package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +0 -10
  177. package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +0 -14
  178. package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +0 -12
  179. package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +0 -19
  180. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +0 -36
  181. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +0 -27
  182. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +0 -16
  183. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +0 -19
  184. package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +0 -75
  185. package/dist/src/prediction/generated/waterx_account/direct_rule.js +0 -78
  186. package/dist/src/prediction/generated/waterx_account/events.d.ts +0 -33
  187. package/dist/src/prediction/generated/waterx_account/events.js +0 -137
  188. package/dist/src/prediction/generated/waterx_account/version.js +0 -8
  189. package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +0 -60
  190. package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +0 -83
  191. package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +0 -14
  192. package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +0 -24
  193. package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +0 -31
  194. package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +0 -16
  195. package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +0 -19
  196. package/dist/src/prediction/generated/waterx_prediction/events.d.ts +0 -22
  197. package/dist/src/prediction/generated/waterx_prediction/version.d.ts +0 -10
  198. package/dist/src/tx-builders.d.ts +0 -296
  199. package/dist/src/tx-builders.js +0 -461
  200. package/dist/src/user/index.d.ts +0 -8
  201. package/dist/src/user/index.js +0 -8
  202. package/dist/src/utils/pyth.d.ts +0 -124
  203. package/dist/src/utils/pyth.js +0 -392
  204. /package/dist/src/{utils → account}/account-request.js +0 -0
  205. /package/dist/src/{core → account}/waterx-account.d.ts +0 -0
  206. /package/dist/src/{core → account}/waterx-account.js +0 -0
  207. /package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.js +0 -0
  208. /package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.js +0 -0
  209. /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +0 -0
  210. /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.js +0 -0
  211. /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/balance.js +0 -0
  212. /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.js +0 -0
  213. /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.d.ts +0 -0
  214. /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.js +0 -0
  215. /package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.js +0 -0
  216. /package/dist/src/{prediction/generated → generated}/waterx_prediction/order.js +0 -0
  217. /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.d.ts +0 -0
  218. /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.js +0 -0
  219. /package/dist/src/{prediction/generated → generated}/waterx_prediction/position.js +0 -0
  220. /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/version.d.ts +0 -0
  221. /package/dist/src/{prediction/generated → generated}/waterx_prediction/version.js +0 -0
  222. /package/dist/src/{prediction/generated → generated}/waterx_prediction/view.js +0 -0
@@ -1,34 +1,54 @@
1
1
  /**
2
- * Unified WaterX SDK client.
2
+ * Umbrella WaterX SDK client — the main entry point.
3
3
  *
4
- * Wraps the two product-line clients (`WaterXClient` for perp, `PredictClient`
5
- * for prediction) behind a single object with namespaced modules, so the
6
- * colliding builder names (`placeOrder`, `createAccount`, `deposit`, …) can be
7
- * called unambiguously:
4
+ * Exposes three namespaces over the two product-line sub-clients:
8
5
  *
9
- * const client = await Client.create({ network: "TESTNET" });
10
- * client.perp.openPosition(tx, params); // -> perp builder
11
- * client.predict.placeOrder(tx, params); // -> prediction builder
6
+ * const client = await WaterXClient.create({ network: "TESTNET" });
7
+ * client.account.createAccount(tx, { alias }); // -> shared waterx_account + funding
8
+ * client.perp.placeOrderRequest(tx, params); // -> perp builder
9
+ * client.predict.placeOrder(tx, params); // -> prediction builder
12
10
  *
13
- * The modules are thin: each method forwards to the existing free-function
14
- * builder with the line's client pre-bound as the first argument. Builders are
15
- * build-only (they return / mutate a `Transaction`); signing & execution stay
16
- * with the caller (`client.perpClient` / `client.predictClient`, or a wallet),
17
- * so frontend wallet flows and multi-step Pyth injection keep working.
11
+ * `client.perp` **is** the `PerpClient` instance with the perp builder/view
12
+ * methods grafted on, and `client.predict` **is** the `PredictClient` instance
13
+ * likewise so signing & execution live on the same object
14
+ * (`client.perp.signAndExecuteTransaction(...)`) right next to the builders.
15
+ * There are no separate `.perpClient` / `.predictClient` accessors.
16
+ *
17
+ * `client.account` is a thin namespace (no own client) bound to the perp
18
+ * sub-client: the perp config carries the shared `waterx_account` registry plus
19
+ * the bridge / native_custody / withdrawal_queue / credit_registry that the
20
+ * credit & custody builders read. `waterx_account` is one shared on-chain object,
21
+ * so an account created here serves both lines — except when the two lines target
22
+ * different networks (`opts.perp.network !== opts.predict.network`), where
23
+ * `client.account` follows the perp line; split-network callers should reach the
24
+ * predict line's generic account builders via the `prediction` namespace directly.
25
+ *
26
+ * Each namespace method forwards to the existing free-function builder with the
27
+ * line's client pre-bound as the first argument; builders are build-only (they
28
+ * return / mutate a `Transaction`), so frontend wallet flows and multi-step Pyth
29
+ * injection keep working.
18
30
  */
19
- import { WaterXClient } from "./client.js";
31
+ // Unified account namespace: generic waterx_account framework + funding (credit + custody).
32
+ import * as accountOps from "./account/index.js";
33
+ import * as perpReferral from "./account/referral.js";
34
+ import { PerpClient } from "./perp/client.js";
20
35
  // Perp builder/view modules (every export takes the client as its first arg).
21
- import * as perpFetch from "./fetch.js";
22
- // Prediction builder/view modules (every export takes the client as its first arg).
23
- import * as predAccount from "./prediction/account.js";
36
+ import * as perpFetch from "./perp/fetch.js";
37
+ import * as perpTx from "./perp/tx-builders.js";
38
+ // Perp-only user builders account/credit/custody are excluded here; they live
39
+ // under `client.account`. trading / order / wlp / staking / referral only.
40
+ import * as perpOrder from "./perp/user/order.js";
41
+ import * as perpStaking from "./perp/user/staking.js";
42
+ import * as perpTrading from "./perp/user/trading.js";
43
+ import * as perpWlp from "./perp/user/wlp.js";
44
+ // Prediction-specific account ops (need the prediction package; NOT generic account).
45
+ import { allowPredictionProtocolAsset, disallowPredictionProtocolAsset, setDelegatePredictionPermission, whitelistPredictionProtocol, } from "./prediction/account.js";
24
46
  import * as predAdmin from "./prediction/admin.js";
25
47
  import { PredictClient, } from "./prediction/client.js";
26
48
  import * as predFetch from "./prediction/fetch.js";
27
49
  import * as predGift from "./prediction/gift.js";
28
50
  import * as predOps from "./prediction/prediction.js";
29
51
  import { buildBatchClaimTx as buildPredictBatchClaimTx, buildPlaceOrderTx as buildPredictPlaceOrderTx, } from "./prediction/tx-builders.js";
30
- import * as perpTx from "./tx-builders.js";
31
- import * as perpUser from "./user/index.js";
32
52
  /**
33
53
  * Exports from the spread builder/view modules that are NOT client-first — their
34
54
  * first argument is not the line client, so they must not become bound facade
@@ -62,40 +82,68 @@ function bindClient(client, ns) {
62
82
  }
63
83
  return out;
64
84
  }
85
+ // Prediction-specific account ops kept on `client.predict` (generic account ops
86
+ // moved to `client.account`).
87
+ const predAccountSpecific = {
88
+ setDelegatePredictionPermission,
89
+ whitelistPredictionProtocol,
90
+ allowPredictionProtocolAsset,
91
+ disallowPredictionProtocolAsset,
92
+ };
65
93
  // Frozen, reused for both the runtime binding and the public module types.
66
- const perpOps = { ...perpUser, ...perpTx, ...perpFetch };
67
- const predictOps = { ...predAccount, ...predAdmin, ...predOps, ...predFetch, ...predGift };
68
- export class Client {
69
- /** Underlying perp client — use for signing/executing perp transactions. */
70
- perpClient;
71
- /** Underlying prediction client — use for signing/executing prediction transactions. */
72
- predictClient;
73
- /** Perp builders & views (`client.perp.openPosition(tx, params)`). */
94
+ const perpOps = {
95
+ ...perpTrading,
96
+ ...perpOrder,
97
+ ...perpWlp,
98
+ ...perpStaking,
99
+ ...perpReferral,
100
+ ...perpTx,
101
+ ...perpFetch,
102
+ };
103
+ const predictOps = { ...predAccountSpecific, ...predAdmin, ...predOps, ...predFetch, ...predGift };
104
+ export class WaterXClient {
105
+ /** Shared account namespace (`client.account.createAccount(tx, params)`) — perp-backed. */
106
+ account;
107
+ /**
108
+ * Perp sub-client **with** the perp builders/views grafted on
109
+ * (`client.perp.placeOrderRequest(...)`, `client.perp.signAndExecuteTransaction(...)`).
110
+ */
74
111
  perp;
75
- /** Prediction builders & views (`client.predict.placeOrder(tx, params)`). */
112
+ /**
113
+ * Prediction sub-client **with** the prediction builders/views grafted on
114
+ * (`client.predict.placeOrder(...)`, `client.predict.signAndExecuteTransaction(...)`).
115
+ */
76
116
  predict;
77
117
  /**
78
118
  * Async prediction builder: optional consolidate + `placeOrder`.
79
- * Uses `perpClient` for the sweep and `predictClient` for the bet leg.
119
+ * Uses the perp client for the sweep and the predict client for the bet leg.
80
120
  */
81
121
  buildPredictPlaceOrderTx(params) {
82
- return buildPredictPlaceOrderTx(this.perpClient, this.predictClient, params);
122
+ return buildPredictPlaceOrderTx(this.perp, this.predict, params);
83
123
  }
84
124
  /**
85
125
  * Async prediction builder: optional consolidate + `batchClaim`.
86
126
  */
87
127
  buildPredictBatchClaimTx(params) {
88
- return buildPredictBatchClaimTx(this.perpClient, this.predictClient, params);
128
+ return buildPredictBatchClaimTx(this.perp, this.predict, params);
89
129
  }
90
130
  constructor(perpClient, predictClient) {
91
- this.perpClient = perpClient;
92
- this.predictClient = predictClient;
93
- this.perp = bindClient(perpClient, perpOps);
94
- this.predict = bindClient(predictClient, predictOps);
131
+ // Graft the bound builders onto the sub-client instances. No builder name
132
+ // collides with the client's own (transport/config) methods — enforced by the
133
+ // "graft guard" unit test (disjoint from the prototype chain), not just a
134
+ // comment. The instances stay `instanceof PerpClient` / `PredictClient`, so
135
+ // signing/config methods work.
136
+ this.perp = Object.assign(perpClient, bindClient(perpClient, perpOps));
137
+ this.predict = Object.assign(predictClient, bindClient(predictClient, predictOps));
138
+ this.account = bindClient(perpClient, accountOps);
95
139
  }
96
- /** Combine two pre-built line clients (advanced — full control over each). */
140
+ /**
141
+ * Combine two pre-built line clients (advanced — full control over each).
142
+ * Note: this grafts the bound builder methods onto the provided client
143
+ * instances in place.
144
+ */
97
145
  static fromClients(perpClient, predictClient) {
98
- return new Client(perpClient, predictClient);
146
+ return new WaterXClient(perpClient, predictClient);
99
147
  }
100
148
  /**
101
149
  * Async factory — loads each line's deployment config (from the canonical
@@ -106,18 +154,28 @@ export class Client {
106
154
  const baseNetwork = opts.network ?? "TESTNET";
107
155
  const { network: perpNetwork, ...perpRest } = opts.perp ?? {};
108
156
  const { network: predictNetwork, ...predictRest } = opts.predict ?? {};
109
- const perpClient = await WaterXClient.create(perpNetwork ?? baseNetwork, {
157
+ const resolvedPerpNetwork = perpNetwork ?? baseNetwork;
158
+ const resolvedPredictNetwork = predictNetwork ?? baseNetwork;
159
+ if (resolvedPerpNetwork !== resolvedPredictNetwork) {
160
+ // `client.account` always follows the perp line (see the class header).
161
+ // On a split-network setup a caller reaching for `client.account.*` would
162
+ // silently build against the perp deployment — warn so it isn't a surprise.
163
+ console.warn(`[WaterXClient] split-network: perp=${resolvedPerpNetwork} predict=${resolvedPredictNetwork}. ` +
164
+ `client.account follows the perp line (${resolvedPerpNetwork}); reach the predict line's ` +
165
+ `generic account builders via the prediction namespace directly.`);
166
+ }
167
+ const perpClient = await PerpClient.create(resolvedPerpNetwork, {
110
168
  grpcUrl: opts.grpcUrl,
111
169
  configUrl: opts.configUrl,
112
170
  cache: opts.cache,
113
171
  ...perpRest,
114
172
  });
115
- const predictClient = await PredictClient.create(predictNetwork ?? baseNetwork, {
173
+ const predictClient = await PredictClient.create(resolvedPredictNetwork, {
116
174
  grpcUrl: opts.grpcUrl,
117
175
  configUrl: opts.configUrl,
118
176
  cache: opts.cache,
119
177
  ...predictRest,
120
178
  });
121
- return new Client(perpClient, predictClient);
179
+ return new WaterXClient(perpClient, predictClient);
122
180
  }
123
181
  }
@@ -1,4 +1,4 @@
1
- import type { WaterXConfig } from "../config.ts";
1
+ import type { WaterXConfig } from "../perp/config.ts";
2
2
  /** Returns all registered market tickers (e.g. "BTCUSD") from waterx-config. */
3
3
  export declare function getMarketTickers(config: WaterXConfig): string[];
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waterx/sdk",
3
- "version": "2.4.1",
3
+ "version": "3.0.0",
4
4
  "description": "WaterX SDK — perpetuals and prediction markets on Sui",
5
5
  "license": "MIT",
6
6
  "author": "WaterX",
@@ -16,13 +16,29 @@
16
16
  "types": "./dist/src/sdk.d.ts",
17
17
  "import": "./dist/src/sdk.js"
18
18
  },
19
+ "./account": {
20
+ "types": "./dist/src/account/index.d.ts",
21
+ "import": "./dist/src/account/index.js"
22
+ },
23
+ "./account/*": {
24
+ "types": "./dist/src/account/*.d.ts",
25
+ "import": "./dist/src/account/*.js"
26
+ },
27
+ "./oracle": {
28
+ "types": "./dist/src/oracle/index.d.ts",
29
+ "import": "./dist/src/oracle/index.js"
30
+ },
31
+ "./oracle/*": {
32
+ "types": "./dist/src/oracle/*.d.ts",
33
+ "import": "./dist/src/oracle/*.js"
34
+ },
19
35
  "./perp": {
20
- "types": "./dist/src/index.d.ts",
21
- "import": "./dist/src/index.js"
36
+ "types": "./dist/src/perp/index.d.ts",
37
+ "import": "./dist/src/perp/index.js"
22
38
  },
23
39
  "./perp/*": {
24
- "types": "./dist/src/*.d.ts",
25
- "import": "./dist/src/*.js"
40
+ "types": "./dist/src/perp/*.d.ts",
41
+ "import": "./dist/src/perp/*.js"
26
42
  },
27
43
  "./prediction": {
28
44
  "types": "./dist/src/prediction/index.d.ts",
@@ -102,6 +118,7 @@
102
118
  "smoke:chain": "tsx scripts/run-smoke-chain.ts",
103
119
  "smoke:chain:dry": "tsx scripts/run-smoke-chain.ts --dry-run",
104
120
  "seed:testnet": "tsx test/prediction/scripts/seed-testnet.ts",
121
+ "seed:testnet:perp": "tsx test/perp/scripts/seed-testnet.ts",
105
122
  "predict:list-accounts": "tsx test/prediction/scripts/list-accounts.ts",
106
123
  "predict:bootstrap-stress-accounts": "tsx test/prediction/scripts/bootstrap-stress-accounts.ts",
107
124
  "predict:bootstrap-stress-deposits": "tsx test/prediction/scripts/bootstrap-stress-deposits.ts",
@@ -1,292 +0,0 @@
1
- /**
2
- * WaterX deployment config — fetched at client init from the canonical
3
- * `waterx-config` repo (default: GitHub raw).
4
- *
5
- * The schema mirrors the canonical JSON layout one-to-one (each package
6
- * groups its own object IDs + per-ticker maps). External chain infra
7
- * (Pyth state, Wormhole state/core, Hermes & Wormholescan endpoints) is
8
- * **not** in the JSON — it lives in `PYTH_DEFAULTS` / `WORMHOLE_DEFAULTS`
9
- * below, keyed by network.
10
- */
11
- import type { Network } from "./constants.ts";
12
- export interface BasePackageEntry {
13
- published_at: string;
14
- original_id: string;
15
- version: number;
16
- upgrade_capability?: string;
17
- }
18
- export interface PythRulePackage extends BasePackageEntry {
19
- config: string;
20
- feeds: Record<string, {
21
- feed_id: string;
22
- price_info_object: string;
23
- }>;
24
- }
25
- export interface PythSponsorRulePackage extends BasePackageEntry {
26
- pyth_sponsor: string;
27
- }
28
- /** Per-ticker `constant_rule` feed entry (mirrors the `pyth_rule.feeds` shape). */
29
- export interface ConstantFeedEntry {
30
- /**
31
- * Constant 1e9-scaled price (decimal string), mirroring the on-chain
32
- * `Config.prices` value (e.g. `"1000000000"` for $1). Informational off-chain —
33
- * the on-chain `constant_rule::feed` reads the price from `Config`; the SDK only
34
- * keys routing off the presence of the entry.
35
- */
36
- price: string;
37
- }
38
- export interface WaterxConstantRulePackage extends BasePackageEntry {
39
- /** Shared `constant_rule::Config` holding the per-ticker constant prices. */
40
- config: string;
41
- /**
42
- * Oracle ticker → constant feed entry, mirroring `pyth_rule.feeds`. A ticker
43
- * present here is fed via `constant_rule::feed` instead of (steady state) or
44
- * alongside (dual-feed) `pyth_rule::feed` (e.g. `USDCUSD → { price: "1000000000" }`).
45
- */
46
- feeds?: Record<string, ConstantFeedEntry>;
47
- }
48
- /** Per-ticker `supra_rule` feed entry (mirrors the `pyth_rule.feeds` shape). */
49
- export interface SupraFeedEntry {
50
- /** Supra pair id (mirrors the on-chain `Config`; informational off-chain). */
51
- pair_id: number;
52
- /** Optional per-ticker freshness tolerance override (ms). */
53
- tolerance_ms?: number;
54
- }
55
- export interface SupraRulePackage extends BasePackageEntry {
56
- /** Shared `supra_rule::Config` (per-symbol Supra pair_id + freshness tolerance). */
57
- config: string;
58
- /** Supra `OracleHolder` shared object id (network-specific). Required to feed. */
59
- oracle_holder?: string;
60
- /** Oracle ticker → Supra feed entry (mirrors the on-chain `Config`; informational). */
61
- feeds?: Record<string, SupraFeedEntry>;
62
- /**
63
- * When true AND `config` + `oracle_holder` are set, `refreshOraclePrices`
64
- * feeds `supra_rule` on the same `PriceCollector` as Pyth before `aggregate`
65
- * (a second weighted rule). Defaults to **false** so a Pyth-only deployment
66
- * is unaffected — flip on only after `weight_threshold`/feeders are ready.
67
- */
68
- enabled?: boolean;
69
- }
70
- export interface WxaAccountPackage extends BasePackageEntry {
71
- admin_cap: string;
72
- account_registry: string;
73
- }
74
- export interface WaterxOraclePackage extends BasePackageEntry {
75
- listing_cap: string;
76
- oracle: string;
77
- aggregators: Record<string, string>;
78
- }
79
- export interface WaterxPerpMarketEntry {
80
- market: string;
81
- config: string;
82
- }
83
- export interface WaterxPerpPackage extends BasePackageEntry {
84
- admin_cap: string;
85
- global_config: string;
86
- market_registry_wlp: string;
87
- markets: Record<string, WaterxPerpMarketEntry>;
88
- }
89
- export interface RewarderEntry {
90
- /** `Rewarder<STAKE, R>` shared object ID. */
91
- rewarder_id: string;
92
- /** Fully-qualified reward coin Move type (e.g. `0x2::sui::SUI`). */
93
- coin_type: string;
94
- /** Reward coin display decimals. */
95
- decimals: number;
96
- }
97
- export interface WaterxStakingPackage extends BasePackageEntry {
98
- admin_cap?: string;
99
- /** Map of stake-type alias (e.g. `"WLP"`) → `StakingPool<STAKE>` shared object ID. */
100
- pools?: Record<string, string>;
101
- /**
102
- * Map of stake-type alias → reward-token alias → rewarder metadata.
103
- * Reward-token alias is display-only (e.g. `"SUI"`, `"MOCK_SUI"`); the
104
- * fully-qualified coin Move type lives on the {@link RewarderEntry}.
105
- */
106
- rewarders?: Record<string, Record<string, RewarderEntry>>;
107
- }
108
- export interface WlpPackage extends BasePackageEntry {
109
- metadata_cap?: string;
110
- currency?: string;
111
- wlp_pool: string;
112
- /** Optional `WlpAum<LP>` shared object; required by `mint_wlp` / `settle_redeem`. */
113
- wlp_aum?: string;
114
- /** Map of oracle ticker → fully-qualified Move type registered via `lp_pool::add_token`. */
115
- pool_tokens: Record<string, string>;
116
- }
117
- export interface WaterxReferralPackage extends BasePackageEntry {
118
- /** Shared `ReferralTable`. */
119
- referral_table: string;
120
- }
121
- export interface MockCoinPackage extends BasePackageEntry {
122
- currency?: string;
123
- treasury_cap?: string;
124
- metadata_cap?: string;
125
- }
126
- export interface WaterxCreditPackage {
127
- published_at: string;
128
- /** Shared `CreditRegistry<CREDIT>` (phase-1 output). */
129
- credit_registry?: string;
130
- /**
131
- * Fully-qualified CREDIT coin Move type, e.g. `0x..::usd::USD`. Required
132
- * for any credit/bridge flow — `client.creditType()` returns it as-is.
133
- */
134
- credit_type?: string;
135
- }
136
- /** One backing-asset row on the native custody vault (PSM). */
137
- export interface NativeCustodyAsset {
138
- /** Human-readable asset label, e.g. `"MOCK_USDC"` / `"USDC"` (from `add_asset`). */
139
- name?: string;
140
- /** Fully-qualified backing asset Move type `T`. */
141
- type: string;
142
- decimal: number;
143
- mint_fee_scaled: string;
144
- burn_fee_scaled: string;
145
- min_burn_amount: string;
146
- }
147
- export interface NativeCustodyPackage {
148
- published_at: string;
149
- /** Shared `CustodyVault<CREDIT>` (phase-4 output). */
150
- vault?: string;
151
- /** Backing assets registered via `add_asset` (array, identified by `type`). */
152
- assets: NativeCustodyAsset[];
153
- }
154
- export interface TrustedEmitterRow {
155
- /** Source EVM chain's Wormhole chain id (e.g. 10002 = Sepolia). */
156
- chain_id: number;
157
- /** 32-byte left-padded EVM bridge address (0x form). */
158
- evm_bridge_address_32b: string;
159
- /** Whitelisted 20-byte EVM token addresses (0x form). */
160
- evm_tokens_20b: string[];
161
- }
162
- export interface WormholeBridgePackage {
163
- published_at: string;
164
- /** Shared Sui Wormhole `State` object id for this deployment. */
165
- wormhole_state: string;
166
- hourly_mint_limit?: string;
167
- max_mint_per_tx?: string;
168
- hourly_burn_limit?: string;
169
- max_burn_per_tx?: string;
170
- /**
171
- * @deprecated EVM emitter↔token config now lives solely under `evm.bridge.chains`
172
- * (deposit_vault = emitter, wormhole_chain_id = chain key). The runtime allowlist is
173
- * read from the on-chain `Bridge` object, not from config. Kept optional for back-compat.
174
- */
175
- trusted_emitters?: TrustedEmitterRow[];
176
- /** Shared `Bridge` (phase-5 output). */
177
- bridge?: string;
178
- /**
179
- * The bridge's `EmitterCap` object id (Sui-side Wormhole emitter address
180
- * for burn-relay Wormholescan lookups). Not written by the deploy script
181
- * — resolve from the on-chain `Bridge` object if absent.
182
- */
183
- emitter_cap?: string;
184
- }
185
- export interface WithdrawalQueuePackage {
186
- published_at: string;
187
- /** Addresses on the queue executor allowlist (keepers). */
188
- executors?: string[];
189
- /** Shared `Queue<CREDIT>` (phase-6 output). */
190
- queue?: string;
191
- }
192
- export interface TestnetFaucetPackage {
193
- published_at: string;
194
- whitelist?: string[];
195
- faucet?: string;
196
- }
197
- export interface WaterXPackages {
198
- bucket_framework: BasePackageEntry;
199
- waterx_referral?: WaterxReferralPackage;
200
- pyth_rule: PythRulePackage;
201
- pyth_sponsor_rule?: PythSponsorRulePackage;
202
- constant_rule?: WaterxConstantRulePackage;
203
- supra_rule?: SupraRulePackage;
204
- waterx_account: WxaAccountPackage;
205
- waterx_oracle: WaterxOraclePackage;
206
- waterx_perp: WaterxPerpPackage;
207
- waterx_perp_view: BasePackageEntry;
208
- waterx_staking?: WaterxStakingPackage;
209
- wlp: WlpPackage;
210
- waterx_credit?: WaterxCreditPackage;
211
- wormhole_bridge?: WormholeBridgePackage;
212
- withdrawal_queue?: WithdrawalQueuePackage;
213
- native_custody?: NativeCustodyPackage;
214
- testnet_faucet?: TestnetFaucetPackage;
215
- mock_usdc?: MockCoinPackage;
216
- mock_usdsui?: MockCoinPackage;
217
- mock_sui?: MockCoinPackage;
218
- waterx_rule?: BasePackageEntry;
219
- waterx_rule_nautilus_enclave?: BasePackageEntry;
220
- }
221
- export interface PythInfraConfig {
222
- state_id: string;
223
- wormhole_state_id: string;
224
- hermes_endpoint: string;
225
- }
226
- export declare const PYTH_DEFAULTS: Record<Network, PythInfraConfig>;
227
- /**
228
- * Wormhole infra for the cross-chain credit bridge. `state_id` is the same
229
- * shared Sui Wormhole `State` object Pyth uses (kept in sync with
230
- * `PYTH_DEFAULTS[*].wormhole_state_id`). Override per-deployment via
231
- * `WaterXConfig.wormhole` if a deployment ever points elsewhere.
232
- */
233
- export interface WormholeInfraConfig {
234
- /** Shared Sui Wormhole `State` object. */
235
- state_id: string;
236
- /** Wormhole core package id on Sui. */
237
- core_package: string;
238
- /** Sui's Wormhole chain id (21 on both mainnet and testnet). */
239
- sui_chain_id: number;
240
- /** Wormholescan REST base for VAA lookups (no trailing slash). */
241
- wormholescan_api: string;
242
- }
243
- export declare const WORMHOLE_DEFAULTS: Record<Network, WormholeInfraConfig>;
244
- export interface WaterXConfig {
245
- /** Absent on credit-only deployment files. */
246
- network?: "mainnet" | "testnet";
247
- chain_id?: string | number | null;
248
- /** Sui gRPC base URL (default: public Mysten fullnode for the network). */
249
- grpcUrl?: string;
250
- packages: WaterXPackages;
251
- /** Pyth infra override (defaults from `PYTH_DEFAULTS[network]`). */
252
- pyth?: PythInfraConfig;
253
- /** Wormhole infra override (defaults from `WORMHOLE_DEFAULTS[network]`). */
254
- wormhole?: WormholeInfraConfig;
255
- /** Sui `CoinRegistry` shared object (credit deployments). */
256
- coin_registry?: string;
257
- /** Per-module credit supply caps (credit deployments). */
258
- credit_caps?: Record<string, string>;
259
- /** Deploy-script phase completion flags (credit deployments). */
260
- done?: Record<string, boolean>;
261
- }
262
- export interface LoadConfigOptions {
263
- /**
264
- * Override the default config URL. Use this to point at a staging branch
265
- * (`?ref=staging`) or a local mirror during development. Takes precedence
266
- * over {@link configRef}.
267
- */
268
- configUrl?: string;
269
- /**
270
- * Pin the canonical config to a specific git ref — a commit SHA, branch,
271
- * or tag — instead of the default `main` branch. Resolves to
272
- * `https://raw.githubusercontent.com/WaterXProtocol/waterx-config/<ref>/<network>.json`.
273
- * Ignored when {@link configUrl} is set.
274
- */
275
- configRef?: string;
276
- /**
277
- * Reuse a previously-fetched config from the in-memory cache (keyed by
278
- * the effective URL). Default: false (always fetch fresh).
279
- */
280
- cache?: boolean;
281
- /** Optional fetch implementation (for tests or environments without global `fetch`). */
282
- fetchImpl?: typeof fetch;
283
- /** Optional request timeout in ms. Default 10_000. */
284
- timeoutMs?: number;
285
- }
286
- /**
287
- * Build the canonical config URL for `network`, optionally pinned to a
288
- * specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
289
- */
290
- export declare function defaultConfigUrl(network: Network, ref?: string): string;
291
- export declare function clearConfigCache(): void;
292
- export declare function loadConfig(network: Network, opts?: LoadConfigOptions): Promise<WaterXConfig>;