@waterx/sdk 2.4.1 → 3.0.1

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 (226) 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/bcs.d.ts +15 -9
  123. package/dist/src/prediction/bcs.js +17 -81
  124. package/dist/src/prediction/client.d.ts +8 -38
  125. package/dist/src/prediction/client.js +11 -67
  126. package/dist/src/prediction/config.d.ts +16 -2
  127. package/dist/src/prediction/config.js +10 -4
  128. package/dist/src/prediction/gift.js +2 -10
  129. package/dist/src/prediction/index.d.ts +11 -11
  130. package/dist/src/prediction/index.js +10 -10
  131. package/dist/src/prediction/prediction.d.ts +45 -0
  132. package/dist/src/prediction/prediction.js +71 -0
  133. package/dist/src/prediction/tx-builders.d.ts +4 -4
  134. package/dist/src/prediction/tx-builders.js +2 -2
  135. package/dist/src/prediction/types.d.ts +2 -0
  136. package/dist/src/prediction/user/index.d.ts +2 -2
  137. package/dist/src/prediction/user/index.js +1 -1
  138. package/dist/src/prediction/user/position.d.ts +2 -2
  139. package/dist/src/prediction/user/position.js +1 -1
  140. package/dist/src/prediction/utils/bcs.d.ts +5 -0
  141. package/dist/src/prediction/utils/bcs.js +5 -0
  142. package/dist/src/prediction/utils/index.d.ts +7 -0
  143. package/dist/src/prediction/utils/index.js +7 -0
  144. package/dist/src/sdk.d.ts +10 -6
  145. package/dist/src/sdk.js +9 -5
  146. package/dist/src/unified-client.d.ts +140 -145
  147. package/dist/src/unified-client.js +98 -40
  148. package/dist/src/utils/config.d.ts +1 -1
  149. package/package.json +22 -5
  150. package/dist/src/config.d.ts +0 -292
  151. package/dist/src/fetch.d.ts +0 -254
  152. package/dist/src/fetch.js +0 -564
  153. package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +0 -100
  154. package/dist/src/prediction/generated/bucket_v2_framework/account.js +0 -129
  155. package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +0 -6
  156. package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +0 -19
  157. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +0 -10
  158. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +0 -36
  159. package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +0 -27
  160. package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +0 -382
  161. package/dist/src/prediction/generated/bucket_v2_framework/double.js +0 -466
  162. package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +0 -362
  163. package/dist/src/prediction/generated/bucket_v2_framework/float.js +0 -440
  164. package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +0 -193
  165. package/dist/src/prediction/generated/bucket_v2_framework/liability.js +0 -205
  166. package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +0 -384
  167. package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +0 -382
  168. package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +0 -344
  169. package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +0 -338
  170. package/dist/src/prediction/generated/utils/index.d.ts +0 -30
  171. package/dist/src/prediction/generated/utils/index.js +0 -160
  172. package/dist/src/prediction/generated/waterx_account/account.d.ts +0 -1589
  173. package/dist/src/prediction/generated/waterx_account/account.js +0 -1758
  174. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +0 -7
  175. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +0 -13
  176. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +0 -7
  177. package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +0 -16
  178. package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +0 -6
  179. package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +0 -19
  180. package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +0 -10
  181. package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +0 -14
  182. package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +0 -12
  183. package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +0 -19
  184. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +0 -36
  185. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +0 -27
  186. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +0 -16
  187. package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +0 -19
  188. package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +0 -75
  189. package/dist/src/prediction/generated/waterx_account/direct_rule.js +0 -78
  190. package/dist/src/prediction/generated/waterx_account/events.d.ts +0 -33
  191. package/dist/src/prediction/generated/waterx_account/events.js +0 -137
  192. package/dist/src/prediction/generated/waterx_account/version.js +0 -8
  193. package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +0 -60
  194. package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +0 -83
  195. package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +0 -14
  196. package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +0 -24
  197. package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +0 -31
  198. package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +0 -16
  199. package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +0 -19
  200. package/dist/src/prediction/generated/waterx_prediction/events.d.ts +0 -22
  201. package/dist/src/prediction/generated/waterx_prediction/version.d.ts +0 -10
  202. package/dist/src/tx-builders.d.ts +0 -296
  203. package/dist/src/tx-builders.js +0 -461
  204. package/dist/src/user/index.d.ts +0 -8
  205. package/dist/src/user/index.js +0 -8
  206. package/dist/src/utils/pyth.d.ts +0 -124
  207. package/dist/src/utils/pyth.js +0 -392
  208. /package/dist/src/{utils → account}/account-request.js +0 -0
  209. /package/dist/src/{core → account}/waterx-account.d.ts +0 -0
  210. /package/dist/src/{core → account}/waterx-account.js +0 -0
  211. /package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.js +0 -0
  212. /package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.js +0 -0
  213. /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +0 -0
  214. /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.js +0 -0
  215. /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/balance.js +0 -0
  216. /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.js +0 -0
  217. /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.d.ts +0 -0
  218. /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.js +0 -0
  219. /package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.js +0 -0
  220. /package/dist/src/{prediction/generated → generated}/waterx_prediction/order.js +0 -0
  221. /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.d.ts +0 -0
  222. /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.js +0 -0
  223. /package/dist/src/{prediction/generated → generated}/waterx_prediction/position.js +0 -0
  224. /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/version.d.ts +0 -0
  225. /package/dist/src/{prediction/generated → generated}/waterx_prediction/version.js +0 -0
  226. /package/dist/src/{prediction/generated → generated}/waterx_prediction/view.js +0 -0
@@ -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.1",
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>;
@@ -1,254 +0,0 @@
1
- /**
2
- * Read-only queries built on top of `waterx_perp_view`.
3
- *
4
- * Each helper builds a one-shot PTB, runs `client.simulate(tx)`, and
5
- * decodes the first command's return values into the matching generated
6
- * BCS struct. The simulated sender is the zero address.
7
- */
8
- import type { WaterXClient } from "./client.ts";
9
- import { AccountData, GlobalConfigData, MarketData, OrderData, PoolData, PositionData, RedeemRequestData, TokenPoolData } from "./generated/waterx_perp_view/view.ts";
10
- import { type ParkedBackingAssetBalance } from "./utils/consolidate-balance.ts";
11
- export type AccountDataView = ReturnType<typeof AccountData.parse>;
12
- /**
13
- * Look up the registered AccountData for a given wxa account ID.
14
- * Returns `undefined` if the account has no perp data slot installed yet
15
- * (the slot auto-installs on the first `add_position` / `add_order`).
16
- * The underlying view fn returns `Option<AccountData>`.
17
- */
18
- export declare function getAccountData(client: WaterXClient, accountId: string): Promise<AccountDataView | undefined>;
19
- export type MarketDataView = ReturnType<typeof MarketData.parse>;
20
- export type PoolDataView = ReturnType<typeof PoolData.parse>;
21
- export type TokenPoolDataView = ReturnType<typeof TokenPoolData.parse>;
22
- export type GlobalConfigDataView = ReturnType<typeof GlobalConfigData.parse>;
23
- export declare function getMarketData(client: WaterXClient, args: {
24
- ticker: string;
25
- lpType?: string;
26
- }): Promise<MarketDataView>;
27
- export declare function getPoolData(client: WaterXClient, args?: {
28
- lpType?: string;
29
- }): Promise<PoolDataView>;
30
- export declare function getTokenPoolData(client: WaterXClient, args: {
31
- tokenIndex: bigint | number;
32
- lpType?: string;
33
- }): Promise<TokenPoolDataView>;
34
- export declare function getGlobalConfigData(client: WaterXClient): Promise<GlobalConfigDataView>;
35
- export type PositionDataView = ReturnType<typeof PositionData.parse>;
36
- export declare function positionExists(client: WaterXClient, args: {
37
- ticker: string;
38
- positionId: bigint | number;
39
- lpType?: string;
40
- }): Promise<boolean>;
41
- export declare function getPosition(client: WaterXClient, args: {
42
- ticker: string;
43
- positionId: bigint | number;
44
- /** Human-readable USD prices for Pnl / liq price calc; pass 0n if unsure. */
45
- basePriceUsd: bigint | number;
46
- collateralPriceUsd: bigint | number;
47
- lpType?: string;
48
- }): Promise<PositionDataView>;
49
- export type OrderDataView = ReturnType<typeof OrderData.parse>;
50
- export declare function getOrder(client: WaterXClient, args: {
51
- ticker: string;
52
- orderId: bigint | number;
53
- orderTypeTag: number;
54
- triggerPrice: bigint | number;
55
- basePriceUsd: bigint | number;
56
- lpType?: string;
57
- }): Promise<OrderDataView>;
58
- export interface PageOpts {
59
- cursor?: bigint | number;
60
- pageSize?: bigint | number;
61
- }
62
- export declare function getMarketOrders(client: WaterXClient, args: {
63
- ticker: string;
64
- basePriceUsd?: bigint | number;
65
- lpType?: string;
66
- } & PageOpts): Promise<{
67
- orders: OrderDataView[];
68
- nextCursor?: bigint;
69
- }>;
70
- export declare function getMarketPositions(client: WaterXClient, args: {
71
- ticker: string;
72
- basePriceUsd: bigint | number;
73
- collateralPriceUsd?: bigint | number;
74
- lpType?: string;
75
- } & PageOpts): Promise<{
76
- positions: PositionDataView[];
77
- nextCursor?: bigint;
78
- }>;
79
- export declare function getAccountPositions(client: WaterXClient, args: {
80
- ticker: string;
81
- accountObjectAddress: string;
82
- basePriceUsd: bigint | number;
83
- collateralPriceUsd?: bigint | number;
84
- lpType?: string;
85
- }): Promise<PositionDataView[]>;
86
- export declare function getAccountOrders(client: WaterXClient, args: {
87
- ticker: string;
88
- accountObjectAddress: string;
89
- basePriceUsd?: bigint | number;
90
- lpType?: string;
91
- }): Promise<OrderDataView[]>;
92
- export type RedeemRequestDataView = ReturnType<typeof RedeemRequestData.parse>;
93
- export declare function getRedeemRequests(client: WaterXClient, args?: {
94
- lpType?: string;
95
- } & PageOpts): Promise<{
96
- requests: RedeemRequestDataView[];
97
- nextCursor?: bigint;
98
- }>;
99
- /** Returns the referrer address bound to `referee`, or `undefined` if none. */
100
- export declare function getRefererFor(client: WaterXClient, referee: string): Promise<string | undefined>;
101
- /** True if `code` is a syntactically valid referral code (matches the contract's char rules). */
102
- export declare function isValidReferralCode(client: WaterXClient, code: string): Promise<boolean>;
103
- /** True if `code` is already claimed in the on-chain ReferralTable. */
104
- export declare function referralCodeExists(client: WaterXClient, code: string): Promise<boolean>;
105
- /**
106
- * List the wxa account IDs owned by `owner` (`account::account_ids`).
107
- * Returns `[]` when the owner has never created an account. Use this to
108
- * resolve the `account_id` a cross-chain deposit must target before
109
- * filling the EVM `suiRecipient` field.
110
- */
111
- export declare function getAccountsByOwner(client: WaterXClient, owner: string): Promise<string[]>;
112
- /**
113
- * A wxa account's stored `Balance<T>` (`account::account_balance<T>`).
114
- * `coinType` defaults to the deployment's CREDIT type — i.e. the bridged
115
- * balance available to withdraw. Returns `0n` for an unknown coin type.
116
- */
117
- export declare function getAccountBalance(client: WaterXClient, accountId: string, coinType?: string): Promise<bigint>;
118
- /**
119
- * Inclusive wxUSD credit an account can spend after the default async tx-builder
120
- * pre-sweep ({@link appendConsolidateForSpend}).
121
- *
122
- * - `internalRaw` — stored `Balance<CREDIT>` (`getAccountBalance`).
123
- * - `pendingBackingRaw` — native-custody backing assets (USDC, USDSUI, …)
124
- * parked at the account's Sui address, rescaled to CREDIT decimals at the
125
- * 1:1 PSM peg (same probe as {@link appendConsolidateToUsd}).
126
- * - `pendingCreditAtAddressRaw` — CREDIT at the account address (accumulator +
127
- * owned coins). Swept into the internal slot by
128
- * {@link appendConsolidateAddressCredit} via `consumeDepositDirect`.
129
- * - `totalRaw` — sum of the three components; matches post-
130
- * {@link appendConsolidateForSpend} spendable balance for predict / perp
131
- * builders with `consolidateToUsd: true` (default).
132
- */
133
- export interface SpendableCreditBalance {
134
- internalRaw: bigint;
135
- pendingBackingRaw: bigint;
136
- pendingCreditAtAddressRaw: bigint;
137
- totalRaw: bigint;
138
- /** Per-asset breakdown for the backing-asset probe (empty when nothing parked). */
139
- parkedBacking: ParkedBackingAssetBalance[];
140
- }
141
- export declare function getSpendableCreditBalance(client: WaterXClient, accountId: string): Promise<SpendableCreditBalance>;
142
- /** Vault-wide native-custody state. */
143
- export interface CustodyVaultData {
144
- /** Total CREDIT minted by the custody vault (`credit_supply`). */
145
- creditSupply: bigint;
146
- }
147
- /** Reads vault-wide native-custody state via `custody_vault::credit_supply`. */
148
- export declare function getCustodyVaultData(client: WaterXClient): Promise<CustodyVaultData>;
149
- /** Per-asset native-custody state for one backing asset. */
150
- export interface CustodyAssetData {
151
- /** Whether the asset is registered as a `SingleVault` on the custody vault. */
152
- registered: boolean;
153
- /** 1e9-scaled default mint fee rate (`0n` when the asset is not registered). */
154
- mintFeeRate: bigint;
155
- /** 1e9-scaled default burn fee rate (`0n` when the asset is not registered). */
156
- burnFeeRate: bigint;
157
- }
158
- /**
159
- * Reads per-asset native-custody state for backing asset `assetType`.
160
- *
161
- * Fee rates are the vault's default config — queried with the zero address as
162
- * caller, so no partner discount is applied — as 1e9-scaled `Float` values.
163
- * When the asset is not registered, returns `registered: false` with `0n` rates.
164
- *
165
- * Note: the `SingleVault` balance / decimal / backing / min-burn / deprecated
166
- * fields are not exposed here — the contract's getters for those return a
167
- * `&SingleVault<T>` reference, which a PTB simulate cannot read.
168
- */
169
- export declare function getCustodyAssetData(client: WaterXClient, assetType: string): Promise<CustodyAssetData>;
170
- /**
171
- * Live rate-limit / cap snapshot read from the `wormhole_bridge::Bridge`
172
- * shared object. All amounts are raw base units of the bridged credit coin.
173
- *
174
- * `dailyMinted` / `dailyBurned` are the sliding-window sums as the on-chain
175
- * `daily_minted` / `daily_burned` views report them — buckets that rotated
176
- * out of the trailing window are evicted lazily on the next mint/burn, so
177
- * these can read slightly high until then (conservative).
178
- */
179
- export interface BridgeLimitsView {
180
- paused: boolean;
181
- dailyMintLimit: bigint;
182
- dailyMinted: bigint;
183
- maxMintPerTx: bigint;
184
- dailyBurnLimit: bigint;
185
- dailyBurned: bigint;
186
- maxBurnPerTx: bigint;
187
- /** Per-account 24h burn cap; 0n means the gate is disabled. */
188
- personalBurnCapAmount: bigint;
189
- /** Present only when `accountId` is supplied — burn counted in that
190
- * account's current window (the per-account cap key is the account id). */
191
- personalBurned?: bigint;
192
- /** Present only when `backing` is supplied — `minted_for(chainId, token)`,
193
- * the amount currently withdrawable to that EVM (chain, token). */
194
- backingMinted?: bigint;
195
- }
196
- export interface BridgeLimitsArgs {
197
- /** wxa trading account id — enables the per-account `personalBurned` read. */
198
- accountId?: string;
199
- /** Wormhole destination chain id + 20-byte EVM token — enables the
200
- * `mintedFor` backing read. */
201
- backing?: {
202
- wormholeChainId: number;
203
- token: Uint8Array | number[];
204
- };
205
- }
206
- /**
207
- * Batched read of the bridge's rate-limit / cap state in a single simulate.
208
- * Pass `accountId` to also fetch the per-account burn usage, and `backing`
209
- * to also fetch the destination-chain backing (`minted_for`).
210
- *
211
- * Throws if `wormhole_bridge` (or its `Bridge` object id) is absent from the
212
- * canonical config — e.g. on a network where the Sui bridge isn't published.
213
- */
214
- export declare function getBridgeLimits(client: WaterXClient, args?: BridgeLimitsArgs): Promise<BridgeLimitsView>;
215
- export interface BridgeFeeView {
216
- /** Raw fee charged on a wormhole (Sui → EVM) exit of `amount`:
217
- * `max(ceil(effectiveRate * amount), effectiveMinFee)`. */
218
- feeAmount: bigint;
219
- /** Whether the exit clears the on-chain net-zero guard — i.e. a strictly
220
- * positive amount remains after the fee. Gate "estimated fee" UI on THIS,
221
- * not `feeAmount` alone: a dust `amount`, or a min-fee floor ≥ `amount`,
222
- * makes `feeAmount >= amount` and the exit would abort (audit L1). */
223
- wouldExecute: boolean;
224
- /** Effective % rate for the chain (per-chain override → default → 0),
225
- * 1e9-scaled (the `Float`-as-`u128` ABI convention). */
226
- effectiveRate: bigint;
227
- /** Effective minimum-fee floor for the chain (override → default → 0),
228
- * in CREDIT base units. */
229
- effectiveMinFee: bigint;
230
- /** Net CREDIT the recipient receives after the fee; `0n` when the exit
231
- * wouldn't execute (`wouldExecute === false`). */
232
- netAmount: bigint;
233
- }
234
- /**
235
- * Estimate the bridge fee for a wormhole (Sui → EVM) CREDIT exit of `amount`
236
- * to `evmDestinationChain`, read in a single simulate from the on-chain
237
- * `withdrawal_queue` views. The charged fee is
238
- * `max(ceil(effectiveRate * amount), effectiveMinFee)`.
239
- *
240
- * Surface UI off `wouldExecute`, NOT `feeAmount` alone — `feeAmount` is the raw
241
- * fee and can equal/exceed `amount` (ceil rounding on a dust entry, or a min-fee
242
- * floor larger than the entry), in which case the on-chain exit aborts its
243
- * net-zero guard (audit L1). `netAmount` is `0n` whenever `wouldExecute` is
244
- * false.
245
- *
246
- * @param args.amount CREDIT base units (the bridged coin's smallest unit).
247
- * @param args.evmDestinationChain WORMHOLE chain id of the destination EVM.
248
- * @param args.creditType CREDIT coin type; defaults to `client.creditType()`.
249
- */
250
- export declare function getBridgeFee(client: WaterXClient, args: {
251
- evmDestinationChain: number;
252
- amount: bigint | number;
253
- creditType?: string;
254
- }): Promise<BridgeFeeView>;