@waterx/sdk 2.4.0 → 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 -42
  32. package/dist/src/constants.js +8 -47
  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} +22 -22
  98. package/dist/src/{index.js → perp/index.js} +22 -22
  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,9 +1,4 @@
1
- /**
2
- * Shared probe helpers for {@link appendConsolidateToUsd} and
3
- * {@link getSpendableCreditBalance} — one asset list, one gRPC read pattern,
4
- * so display totals match what the next async tx-builder would sweep.
5
- */
6
- import type { WaterXClient } from "../client.ts";
1
+ import type { AccountClientLike } from "../client.ts";
7
2
  /** CREDIT parked at a wxa account's Sui address (funds accumulator + owned coins). */
8
3
  export interface AddressCreditBalance {
9
4
  /** `getBalance.addressBalance` — funds accumulator path. */
@@ -27,11 +22,11 @@ export declare function rescaleRawAmount(raw: bigint, fromDecimals: number, toDe
27
22
  * parked at `accountId`'s Sui address. Matches the pre-tx scan inside
28
23
  * {@link appendConsolidateToUsd}.
29
24
  */
30
- export declare function probeParkedBackingAssets(client: WaterXClient, accountId: string): Promise<ParkedBackingAssetBalance[]>;
25
+ export declare function probeParkedBackingAssets(client: AccountClientLike, accountId: string): Promise<ParkedBackingAssetBalance[]>;
31
26
  /**
32
27
  * Probe non-zero CREDIT parked at `accountId`'s Sui address. Matches the
33
28
  * address-CREDIT legs inside {@link appendConsolidateAddressCredit}.
34
29
  */
35
- export declare function probeAddressCreditBalance(client: WaterXClient, accountId: string): Promise<AddressCreditBalance>;
30
+ export declare function probeAddressCreditBalance(client: AccountClientLike, accountId: string): Promise<AddressCreditBalance>;
36
31
  /** Sum parked backing assets into CREDIT base units at the 1:1 PSM peg. */
37
32
  export declare function sumParkedBackingAsCreditRaw(parked: readonly ParkedBackingAssetBalance[], creditDecimals?: number): bigint;
@@ -1,4 +1,9 @@
1
- import { COLLATERAL_DECIMALS } from "../constants.js";
1
+ /**
2
+ * Shared probe helpers for {@link appendConsolidateToUsd} and
3
+ * {@link getSpendableCreditBalance} — one asset list, one gRPC read pattern,
4
+ * so display totals match what the next async tx-builder would sweep.
5
+ */
6
+ import { COLLATERAL_DECIMALS } from "../../constants.js";
2
7
  /** Rescale a u64 raw amount between token decimal precisions (truncates on downscale). */
3
8
  export function rescaleRawAmount(raw, fromDecimals, toDecimals = COLLATERAL_DECIMALS) {
4
9
  if (fromDecimals === toDecimals)
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Consolidate parked backing assets → USD credit (pre-action sweep).
3
+ *
4
+ * Drains every backing asset (and address-owned CREDIT) parked at a wxa
5
+ * account's address into spendable wxUSD, so the subsequent trading / WLP /
6
+ * predict action can debit the internal slot. Empty buckets are skipped via
7
+ * gRPC probes, so the sweep is safe to run on any account.
8
+ */
9
+ import { Transaction } from "@mysten/sui/transactions";
10
+ import type { AccountClientLike } from "../client.ts";
11
+ /**
12
+ * For every backing asset registered on `native_custody`, append two drain
13
+ * legs to `tx`:
14
+ *
15
+ * `requestDepositFromFunds<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
16
+ * `requestDepositFromReceivings<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
17
+ *
18
+ * Empty legs are skipped — the on-chain `mint` rejects zero-amount deposits.
19
+ * Returns the number of drain legs added (useful for logging / early-out).
20
+ *
21
+ * Silently no-ops when `native_custody` / `waterx_credit` aren't configured
22
+ * for the loaded deployment.
23
+ */
24
+ export declare function appendConsolidateToUsd(client: AccountClientLike, tx: Transaction, accountId: string): Promise<number>;
25
+ /**
26
+ * Drain CREDIT parked at `accountId`'s Sui address (funds accumulator +
27
+ * owned `Coin<CREDIT>`) into the wxa internal slot via
28
+ * `consumeDepositDirect<CREDIT>`. Complements {@link appendConsolidateToUsd}
29
+ * for address-owned wxUSD that predict / perp actions debit from the internal
30
+ * balance.
31
+ */
32
+ export declare function appendConsolidateAddressCredit(client: AccountClientLike, tx: Transaction, accountId: string): Promise<number>;
33
+ /**
34
+ * Full pre-action sweep: backing assets → wxUSD credit (PSM) plus address
35
+ * CREDIT → internal slot. Used by async tx-builders when `consolidateToUsd`
36
+ * is enabled (default).
37
+ */
38
+ export declare function appendConsolidateForSpend(client: AccountClientLike, tx: Transaction, accountId: string): Promise<number>;
39
+ /**
40
+ * Standalone PTB that drains every backing asset parked at the account's
41
+ * address into USD credit under the account — see {@link appendConsolidateToUsd}.
42
+ *
43
+ * Returns an empty `Transaction` when nothing is parked. Callers can
44
+ * `client.simulate(tx)` to detect a no-op before submitting.
45
+ */
46
+ export declare function buildConsolidateToUsdTx(client: AccountClientLike, accountId: string, tx?: Transaction): Promise<Transaction>;
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Consolidate parked backing assets → USD credit (pre-action sweep).
3
+ *
4
+ * Drains every backing asset (and address-owned CREDIT) parked at a wxa
5
+ * account's address into spendable wxUSD, so the subsequent trading / WLP /
6
+ * predict action can debit the internal slot. Empty buckets are skipped via
7
+ * gRPC probes, so the sweep is safe to run on any account.
8
+ */
9
+ import { Transaction } from "@mysten/sui/transactions";
10
+ import { consumeDepositDirect } from "../../generated/waterx_account/direct_rule.js";
11
+ import { requestDepositFromFunds, requestDepositFromReceivings } from "../account.js";
12
+ import { probeAddressCreditBalance, probeParkedBackingAssets } from "./balance.js";
13
+ import { mintCreditFromRequest } from "./custody.js";
14
+ /**
15
+ * For every backing asset registered on `native_custody`, append two drain
16
+ * legs to `tx`:
17
+ *
18
+ * `requestDepositFromFunds<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
19
+ * `requestDepositFromReceivings<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
20
+ *
21
+ * Empty legs are skipped — the on-chain `mint` rejects zero-amount deposits.
22
+ * Returns the number of drain legs added (useful for logging / early-out).
23
+ *
24
+ * Silently no-ops when `native_custody` / `waterx_credit` aren't configured
25
+ * for the loaded deployment.
26
+ */
27
+ export async function appendConsolidateToUsd(client, tx, accountId) {
28
+ const parked = await probeParkedBackingAssets(client, accountId);
29
+ let legs = 0;
30
+ for (const row of parked) {
31
+ if (row.fundsRaw > 0n) {
32
+ const fromFunds = requestDepositFromFunds(client, tx, {
33
+ accountId,
34
+ coinType: row.assetType,
35
+ });
36
+ foldDepositRequestToUsd(client, tx, fromFunds, row.assetType);
37
+ legs += 1;
38
+ }
39
+ if (row.coinsRaw > 0n) {
40
+ const coins = (await client.listCoins({
41
+ owner: accountId,
42
+ coinType: row.assetType,
43
+ }));
44
+ const refs = (coins.objects ?? []).filter((c) => !!c.objectId && !!c.version && !!c.digest);
45
+ if (refs.length === 0)
46
+ continue;
47
+ const receivings = refs.map((c) => tx.receivingRef({ objectId: c.objectId, version: c.version, digest: c.digest }));
48
+ const fromReceivings = requestDepositFromReceivings(client, tx, {
49
+ accountId,
50
+ coinType: row.assetType,
51
+ receivings,
52
+ });
53
+ foldDepositRequestToUsd(client, tx, fromReceivings, row.assetType);
54
+ legs += 1;
55
+ }
56
+ }
57
+ return legs;
58
+ }
59
+ /**
60
+ * Drain CREDIT parked at `accountId`'s Sui address (funds accumulator +
61
+ * owned `Coin<CREDIT>`) into the wxa internal slot via
62
+ * `consumeDepositDirect<CREDIT>`. Complements {@link appendConsolidateToUsd}
63
+ * for address-owned wxUSD that predict / perp actions debit from the internal
64
+ * balance.
65
+ */
66
+ export async function appendConsolidateAddressCredit(client, tx, accountId) {
67
+ if (!client.config.packages.waterx_credit?.credit_type)
68
+ return 0;
69
+ const creditType = client.creditType();
70
+ const { fundsRaw, coinsRaw } = await probeAddressCreditBalance(client, accountId);
71
+ let legs = 0;
72
+ if (fundsRaw > 0n) {
73
+ const fromFunds = requestDepositFromFunds(client, tx, {
74
+ accountId,
75
+ coinType: creditType,
76
+ });
77
+ consumeDepositRequest(client, tx, fromFunds, creditType);
78
+ legs += 1;
79
+ }
80
+ if (coinsRaw > 0n) {
81
+ const coins = (await client.listCoins({
82
+ owner: accountId,
83
+ coinType: creditType,
84
+ }));
85
+ const refs = (coins.objects ?? []).filter((c) => !!c.objectId && !!c.version && !!c.digest);
86
+ if (refs.length > 0) {
87
+ const receivings = refs.map((c) => tx.receivingRef({ objectId: c.objectId, version: c.version, digest: c.digest }));
88
+ const fromReceivings = requestDepositFromReceivings(client, tx, {
89
+ accountId,
90
+ coinType: creditType,
91
+ receivings,
92
+ });
93
+ consumeDepositRequest(client, tx, fromReceivings, creditType);
94
+ legs += 1;
95
+ }
96
+ }
97
+ return legs;
98
+ }
99
+ /**
100
+ * Full pre-action sweep: backing assets → wxUSD credit (PSM) plus address
101
+ * CREDIT → internal slot. Used by async tx-builders when `consolidateToUsd`
102
+ * is enabled (default).
103
+ */
104
+ export async function appendConsolidateForSpend(client, tx, accountId) {
105
+ const backingLegs = await appendConsolidateToUsd(client, tx, accountId);
106
+ const creditLegs = await appendConsolidateAddressCredit(client, tx, accountId);
107
+ return backingLegs + creditLegs;
108
+ }
109
+ function consumeDepositRequest(client, tx, depositRequest, coinType) {
110
+ consumeDepositDirect({
111
+ package: client.config.packages.waterx_account.published_at,
112
+ arguments: {
113
+ registry: tx.object(client.config.packages.waterx_account.account_registry),
114
+ req: depositRequest,
115
+ },
116
+ typeArguments: [coinType],
117
+ })(tx);
118
+ }
119
+ function foldDepositRequestToUsd(client, tx, depositRequest, assetType) {
120
+ const usdReq = mintCreditFromRequest(client, tx, {
121
+ depositRequest,
122
+ assetType,
123
+ });
124
+ consumeDepositRequest(client, tx, usdReq, client.creditType());
125
+ }
126
+ /**
127
+ * Standalone PTB that drains every backing asset parked at the account's
128
+ * address into USD credit under the account — see {@link appendConsolidateToUsd}.
129
+ *
130
+ * Returns an empty `Transaction` when nothing is parked. Callers can
131
+ * `client.simulate(tx)` to detect a no-op before submitting.
132
+ */
133
+ export async function buildConsolidateToUsdTx(client, accountId, tx) {
134
+ const txOut = tx ?? new Transaction();
135
+ await appendConsolidateToUsd(client, txOut, accountId);
136
+ return txOut;
137
+ }
@@ -18,7 +18,7 @@
18
18
  * same PTB.
19
19
  */
20
20
  import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
21
- import type { WaterXClient } from "../client.ts";
21
+ import type { AccountClientLike } from "../client.ts";
22
22
  export interface RedeemVaaParams {
23
23
  /** Signed Wormhole MINT VAA (raw bytes / number[] / hex). */
24
24
  vaaBytes: Uint8Array | number[] | string;
@@ -30,7 +30,7 @@ export interface RedeemVaaParams {
30
30
  * `DepositRequest<CREDIT>` hot-potato argument — **must** be consumed in the
31
31
  * same PTB (see {@link consumeCreditDeposit} / `redeemVaaTx`).
32
32
  */
33
- export declare function redeemVaa(client: WaterXClient, tx: Transaction, params: RedeemVaaParams): TransactionArgument;
33
+ export declare function redeemVaa(client: AccountClientLike, tx: Transaction, params: RedeemVaaParams): TransactionArgument;
34
34
  export interface ConsumeCreditDepositParams {
35
35
  /** The `DepositRequest<CREDIT>` returned by {@link redeemVaa} / {@link custodyMint}. */
36
36
  depositRequest: TransactionArgument;
@@ -42,7 +42,7 @@ export interface ConsumeCreditDepositParams {
42
42
  * `register_deposit_policy<CREDIT, DirectRule>`). Must run in the same PTB
43
43
  * as the `redeem_vaa` / custody `mint` that produced the request.
44
44
  */
45
- export declare function consumeCreditDeposit(client: WaterXClient, tx: Transaction, params: ConsumeCreditDepositParams): void;
45
+ export declare function consumeCreditDeposit(client: AccountClientLike, tx: Transaction, params: ConsumeCreditDepositParams): void;
46
46
  export interface RouteWormholeParams {
47
47
  /** Destination EVM chain's Wormhole chain id. */
48
48
  evmDestinationChain: number;
@@ -52,7 +52,7 @@ export interface RouteWormholeParams {
52
52
  evmToken: Uint8Array | number[] | string;
53
53
  }
54
54
  /** Build `withdrawal_queue::route_wormhole`. Returns the `extra_data` argument. */
55
- export declare function routeWormhole(client: WaterXClient, tx: Transaction, params: RouteWormholeParams): TransactionArgument;
55
+ export declare function routeWormhole(client: AccountClientLike, tx: Transaction, params: RouteWormholeParams): TransactionArgument;
56
56
  export interface RouteNativeParams {
57
57
  /** Fully-qualified backing asset Move type `T` (e.g. via `client.getNativeAsset`). */
58
58
  assetType: string;
@@ -64,7 +64,7 @@ export interface RouteNativeParams {
64
64
  minOutput?: bigint | number;
65
65
  }
66
66
  /** Build `withdrawal_queue::route_native<T>`. Returns the `extra_data` argument. */
67
- export declare function routeNative(client: WaterXClient, tx: Transaction, params: RouteNativeParams): TransactionArgument;
67
+ export declare function routeNative(client: AccountClientLike, tx: Transaction, params: RouteNativeParams): TransactionArgument;
68
68
  export interface RequestCreditWithdrawParams {
69
69
  accountId: string;
70
70
  amount: bigint | number;
@@ -80,7 +80,7 @@ export interface RequestCreditWithdrawParams {
80
80
  * Returns the `WithdrawRequest<CREDIT>` hot-potato argument (feed to
81
81
  * {@link enqueueWithdrawal} in the same PTB).
82
82
  */
83
- export declare function requestCreditWithdraw(client: WaterXClient, tx: Transaction, params: RequestCreditWithdrawParams): TransactionArgument;
83
+ export declare function requestCreditWithdraw(client: AccountClientLike, tx: Transaction, params: RequestCreditWithdrawParams): TransactionArgument;
84
84
  export interface EnqueueWithdrawalParams {
85
85
  /** `WithdrawRequest<CREDIT>` from {@link requestCreditWithdraw}. */
86
86
  withdrawRequest: TransactionArgument;
@@ -90,7 +90,7 @@ export interface EnqueueWithdrawalParams {
90
90
  * Build `withdrawal_queue::enqueue<CREDIT>`. Returns the assigned `u64` key
91
91
  * argument (also surfaced on-chain via the `Enqueued` event).
92
92
  */
93
- export declare function enqueueWithdrawal(client: WaterXClient, tx: Transaction, params: EnqueueWithdrawalParams): TransactionArgument;
93
+ export declare function enqueueWithdrawal(client: AccountClientLike, tx: Transaction, params: EnqueueWithdrawalParams): TransactionArgument;
94
94
  export interface ExecuteWithdrawalWormholeParams {
95
95
  /** Queue entry key (from the `Enqueued` event / `enqueueWithdrawal`). */
96
96
  key: bigint | number;
@@ -101,7 +101,7 @@ export interface ExecuteWithdrawalWormholeParams {
101
101
  bucketAccount?: string | TransactionArgument;
102
102
  }
103
103
  /** Build `withdrawal_queue::execute_wormhole<CREDIT>` (keeper / executor-gated). */
104
- export declare function executeWithdrawalWormhole(client: WaterXClient, tx: Transaction, params: ExecuteWithdrawalWormholeParams): void;
104
+ export declare function executeWithdrawalWormhole(client: AccountClientLike, tx: Transaction, params: ExecuteWithdrawalWormholeParams): void;
105
105
  export interface ExecuteWithdrawalNativeParams {
106
106
  key: bigint | number;
107
107
  /** Fully-qualified backing asset Move type `T` (must match the entry's route). */
@@ -110,7 +110,7 @@ export interface ExecuteWithdrawalNativeParams {
110
110
  bucketAccount?: string | TransactionArgument;
111
111
  }
112
112
  /** Build `withdrawal_queue::execute_native<T, CREDIT>` (keeper / executor-gated). */
113
- export declare function executeWithdrawalNative(client: WaterXClient, tx: Transaction, params: ExecuteWithdrawalNativeParams): void;
113
+ export declare function executeWithdrawalNative(client: AccountClientLike, tx: Transaction, params: ExecuteWithdrawalNativeParams): void;
114
114
  export interface CustodyMintParams {
115
115
  /** wxa account ID the minted CREDIT lands in. */
116
116
  accountId: string;
@@ -126,4 +126,4 @@ export interface CustodyMintParams {
126
126
  * `DepositRequest<CREDIT>` hot-potato argument (consume in-PTB via
127
127
  * {@link consumeCreditDeposit}).
128
128
  */
129
- export declare function custodyMint(client: WaterXClient, tx: Transaction, params: CustodyMintParams): TransactionArgument;
129
+ export declare function custodyMint(client: AccountClientLike, tx: Transaction, params: CustodyMintParams): TransactionArgument;
@@ -19,12 +19,12 @@
19
19
  */
20
20
  import { fromHex } from "@mysten/bcs";
21
21
  import { normalizeStructTag } from "@mysten/sui/utils";
22
- import { mint as custodyMintCall } from "../generated/native_custody/custody_vault.js";
23
- import { requestWithdraw as requestWithdrawCall } from "../generated/waterx_account/account.js";
24
- import { consumeDepositDirect } from "../generated/waterx_account/direct_rule.js";
25
- import { enqueue as enqueueCall, executeNative as executeNativeCall, executeWormhole as executeWormholeCall, routeNative as routeNativeCall, routeWormhole as routeWormholeCall, } from "../generated/withdrawal_queue/withdrawal_queue.js";
26
- import { redeemVaa as redeemVaaCall } from "../generated/wormhole_bridge/wormhole_bridge.js";
27
- import { makeSenderRequest } from "../utils/account-request.js";
22
+ import { mint as custodyMintCall } from "../../generated/native_custody/custody_vault.js";
23
+ import { requestWithdraw as requestWithdrawCall } from "../../generated/waterx_account/account.js";
24
+ import { consumeDepositDirect } from "../../generated/waterx_account/direct_rule.js";
25
+ import { enqueue as enqueueCall, executeNative as executeNativeCall, executeWormhole as executeWormholeCall, routeNative as routeNativeCall, routeWormhole as routeWormholeCall, } from "../../generated/withdrawal_queue/withdrawal_queue.js";
26
+ import { redeemVaa as redeemVaaCall } from "../../generated/wormhole_bridge/wormhole_bridge.js";
27
+ import { makeSenderRequest } from "../account-request.js";
28
28
  // ============================================================================
29
29
  // Byte helpers
30
30
  // ============================================================================
@@ -17,7 +17,7 @@
17
17
  * credit pipeline.
18
18
  */
19
19
  import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
20
- import type { WaterXClient } from "../client.ts";
20
+ import type { AccountClientLike } from "../client.ts";
21
21
  export interface MintCreditParams {
22
22
  /** wxa account ID the minted CREDIT is deposited into (also the partner-fee key). */
23
23
  accountId: string;
@@ -34,7 +34,7 @@ export interface MintCreditParams {
34
34
  * Build `custody_vault::mint<T, CREDIT>`. Returns the `DepositRequest<CREDIT>`
35
35
  * argument — consume it in the same PTB (see `mintCreditToAccount`).
36
36
  */
37
- export declare function mintCredit(client: WaterXClient, tx: Transaction, params: MintCreditParams): TransactionArgument;
37
+ export declare function mintCredit(client: AccountClientLike, tx: Transaction, params: MintCreditParams): TransactionArgument;
38
38
  export interface MintCreditFromRequestParams {
39
39
  /** `DepositRequest<T>` from `account::request_deposit<T>` (T must have `NativeCustody` as its deposit policy). */
40
40
  depositRequest: TransactionArgument;
@@ -48,10 +48,10 @@ export interface MintCreditFromRequestParams {
48
48
  * `DepositRequest<CREDIT>` inherits the input request's `accountId` /
49
49
  * `extraData`. Consume it in the same PTB.
50
50
  */
51
- export declare function mintCreditFromRequest(client: WaterXClient, tx: Transaction, params: MintCreditFromRequestParams): TransactionArgument;
51
+ export declare function mintCreditFromRequest(client: AccountClientLike, tx: Transaction, params: MintCreditFromRequestParams): TransactionArgument;
52
52
  /**
53
53
  * `mintCredit` followed by `direct_rule::consume_deposit_direct<CREDIT>`, so
54
54
  * the freshly minted CREDIT settles straight into `accountId`'s wxa balance.
55
55
  * Assumes CREDIT's deposit policy is `DirectRule` (the canonical setup).
56
56
  */
57
- export declare function mintCreditToAccount(client: WaterXClient, tx: Transaction, params: MintCreditParams): void;
57
+ export declare function mintCreditToAccount(client: AccountClientLike, tx: Transaction, params: MintCreditParams): void;
@@ -17,8 +17,8 @@
17
17
  * credit pipeline.
18
18
  */
19
19
  import { normalizeStructTag } from "@mysten/sui/utils";
20
- import * as custody from "../generated/native_custody/custody_vault.js";
21
- import { consumeDepositDirect } from "../generated/waterx_account/direct_rule.js";
20
+ import * as custody from "../../generated/native_custody/custody_vault.js";
21
+ import { consumeDepositDirect } from "../../generated/waterx_account/direct_rule.js";
22
22
  function requireCredit(client) {
23
23
  const credit = client.config.packages.waterx_credit;
24
24
  if (!credit?.credit_registry) {
@@ -2,7 +2,7 @@
2
2
  * Wormhole / Wormholescan integration for the cross-chain credit bridge.
3
3
  *
4
4
  * Single source of truth for VAA discovery + (de)serialization — mirrors
5
- * `utils/pyth.ts`'s role for Pyth's Hermes endpoint. Two directions:
5
+ * `oracle/pyth.ts`'s role for Pyth's Hermes endpoint. Two directions:
6
6
  *
7
7
  * - Mint (EVM → Sui): fetch the signed VAA for an EVM `Deposit` by
8
8
  * (emitter chain, emitter address, sequence); the raw bytes feed
@@ -13,7 +13,7 @@
13
13
  * Endpoints / chain ids come from `client.wormhole` (network defaults in
14
14
  * `WORMHOLE_DEFAULTS`, overridable via `WaterXConfig.wormhole`).
15
15
  */
16
- import type { WaterXClient } from "../client.ts";
16
+ import type { AccountClientLike } from "../client.ts";
17
17
  /**
18
18
  * Normalize an emitter id to Wormholescan's `emitter` path segment:
19
19
  * 64-char lowercase hex, no `0x`. Accepts a 0x EVM address (left-padded to
@@ -75,12 +75,12 @@ export declare function vaaBase64ToHex(b64: string): `0x${string}`;
75
75
  * address (0x form accepted — left-padded automatically); `chainId` is the
76
76
  * source EVM chain's Wormhole chain id.
77
77
  */
78
- export declare function fetchDepositVaa(client: WaterXClient, evmWormholeChainId: number, evmEmitter: string, sequence: number | string | bigint, opts?: WormholescanOptions): Promise<VaaResponse | null>;
78
+ export declare function fetchDepositVaa(client: AccountClientLike, evmWormholeChainId: number, evmEmitter: string, sequence: number | string | bigint, opts?: WormholescanOptions): Promise<VaaResponse | null>;
79
79
  /**
80
80
  * List recent Sui→EVM VAAs from the configured bridge `EmitterCap` (burn
81
81
  * relayer). Requires `packages.wormhole_bridge.emitter_cap` in config.
82
82
  */
83
- export declare function listBridgeWithdrawalVaas(client: WaterXClient, opts?: WormholescanOptions & {
83
+ export declare function listBridgeWithdrawalVaas(client: AccountClientLike, opts?: WormholescanOptions & {
84
84
  page?: number;
85
85
  pageSize?: number;
86
86
  }): Promise<VaaListItem[]>;
@@ -2,7 +2,7 @@
2
2
  * Wormhole / Wormholescan integration for the cross-chain credit bridge.
3
3
  *
4
4
  * Single source of truth for VAA discovery + (de)serialization — mirrors
5
- * `utils/pyth.ts`'s role for Pyth's Hermes endpoint. Two directions:
5
+ * `oracle/pyth.ts`'s role for Pyth's Hermes endpoint. Two directions:
6
6
  *
7
7
  * - Mint (EVM → Sui): fetch the signed VAA for an EVM `Deposit` by
8
8
  * (emitter chain, emitter address, sequence); the raw bytes feed
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Unified WaterX account namespace — exposed as `client.account`.
3
+ *
4
+ * Aggregates the generic `waterx_account` framework builders with the funding
5
+ * (credit + custody) builders into one surface. This is the contract's **base**
6
+ * layer: it lives under `account/` and depends only **down** (base-client /
7
+ * constants / generated) — it must never import `perp/` or `prediction/`. Builders
8
+ * are typed to the {@link AccountClientLike} capability interface (in `./client.ts`),
9
+ * which `PerpClient` satisfies structurally; `bindClient` passes the perp-line
10
+ * client (which carries the shared `waterx_account` + `AccountRegistry`, bridge /
11
+ * native_custody / withdrawal_queue / credit_registry) as arg 0. Because
12
+ * `waterx_account` is a single shared object across both product lines, an account
13
+ * created here is usable by perp and prediction alike (see the cross-network caveat
14
+ * on the umbrella `WaterXClient`).
15
+ *
16
+ * The prediction-specific account operations (delegate prediction permission,
17
+ * prediction protocol whitelist / asset allowlist) are NOT generic and stay on
18
+ * `client.predict`.
19
+ *
20
+ * INVARIANT: every export below must be **client-first** — `bindClient` (in
21
+ * `unified-client.ts`) blindly binds the client as arg 0 to each function here, so
22
+ * a non-client-first helper (e.g. a local crypto/URL util) leaking out of these
23
+ * modules would be mis-bound silently. Keep such helpers unexported, or add them to
24
+ * `NON_CLIENT_FIRST` in `unified-client.ts` (the coverage guard in
25
+ * `test/perp/unit/unified-client.test.ts` only excuses names on that list).
26
+ */
27
+ export * from "./account.ts";
28
+ export * from "./funding/credit.ts";
29
+ export * from "./funding/custody.ts";
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Unified WaterX account namespace — exposed as `client.account`.
3
+ *
4
+ * Aggregates the generic `waterx_account` framework builders with the funding
5
+ * (credit + custody) builders into one surface. This is the contract's **base**
6
+ * layer: it lives under `account/` and depends only **down** (base-client /
7
+ * constants / generated) — it must never import `perp/` or `prediction/`. Builders
8
+ * are typed to the {@link AccountClientLike} capability interface (in `./client.ts`),
9
+ * which `PerpClient` satisfies structurally; `bindClient` passes the perp-line
10
+ * client (which carries the shared `waterx_account` + `AccountRegistry`, bridge /
11
+ * native_custody / withdrawal_queue / credit_registry) as arg 0. Because
12
+ * `waterx_account` is a single shared object across both product lines, an account
13
+ * created here is usable by perp and prediction alike (see the cross-network caveat
14
+ * on the umbrella `WaterXClient`).
15
+ *
16
+ * The prediction-specific account operations (delegate prediction permission,
17
+ * prediction protocol whitelist / asset allowlist) are NOT generic and stay on
18
+ * `client.predict`.
19
+ *
20
+ * INVARIANT: every export below must be **client-first** — `bindClient` (in
21
+ * `unified-client.ts`) blindly binds the client as arg 0 to each function here, so
22
+ * a non-client-first helper (e.g. a local crypto/URL util) leaking out of these
23
+ * modules would be mis-bound silently. Keep such helpers unexported, or add them to
24
+ * `NON_CLIENT_FIRST` in `unified-client.ts` (the coverage guard in
25
+ * `test/perp/unit/unified-client.test.ts` only excuses names on that list).
26
+ */
27
+ export * from "./account.js"; // generic waterx_account framework builders
28
+ export * from "./funding/credit.js"; // cross-chain CREDIT / bridge builders
29
+ export * from "./funding/custody.js"; // native_custody PSM mint builders
@@ -6,16 +6,16 @@
6
6
  * loudly instead of silently aborting on-chain.
7
7
  */
8
8
  import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
9
- import type { WaterXClient } from "../client.ts";
9
+ import type { WxaClientLike } from "./client.ts";
10
10
  export interface SetReferralCodeParams {
11
11
  /** Referral code string the caller wants to claim. */
12
12
  code: string;
13
13
  bucketAccount?: string | TransactionArgument;
14
14
  }
15
- export declare function setReferralCode(client: WaterXClient, tx: Transaction, params: SetReferralCodeParams): void;
15
+ export declare function setReferralCode(client: WxaClientLike, tx: Transaction, params: SetReferralCodeParams): void;
16
16
  export interface UseReferralCodeParams {
17
17
  /** Referral code to bind to the caller's address. */
18
18
  code: string;
19
19
  bucketAccount?: string | TransactionArgument;
20
20
  }
21
- export declare function useReferralCode(client: WaterXClient, tx: Transaction, params: UseReferralCodeParams): void;
21
+ export declare function useReferralCode(client: WxaClientLike, tx: Transaction, params: UseReferralCodeParams): void;
@@ -6,7 +6,7 @@
6
6
  * loudly instead of silently aborting on-chain.
7
7
  */
8
8
  import * as referral from "../generated/waterx_referral/referral_table.js";
9
- import { makeSenderRequest } from "../utils/account-request.js";
9
+ import { makeSenderRequest } from "./account-request.js";
10
10
  function requireReferralConfig(client) {
11
11
  const pkg = client.config.packages.waterx_referral?.published_at;
12
12
  const table = client.config.packages.waterx_referral?.referral_table;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Shared transport base for the two product-line clients (`PerpClient`,
3
+ * `PredictClient`).
4
+ *
5
+ * Holds the half that is identical across both lines: the gRPC client
6
+ * construction (network + URL resolution), the read-only gRPC convenience
7
+ * wrappers, `simulate` / `signAndExecuteTransaction`, and the `packageIds()`
8
+ * lookup. The config-schema half (per-line typed lookups like `getMarket` /
9
+ * `marketRegistry`) legitimately differs and lives on each subclass.
10
+ *
11
+ * `Cfg` is the line's parsed `waterx-config` JSON type. Only the fields needed
12
+ * here are constrained ({@link BaseLineConfig}); each subclass narrows `Cfg` to
13
+ * its full config type so `this.config` stays precisely typed.
14
+ */
15
+ import type { SuiClientTypes } from "@mysten/sui/client";
16
+ import type { Signer } from "@mysten/sui/cryptography";
17
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
18
+ import type { Transaction } from "@mysten/sui/transactions";
19
+ import type { Network } from "./constants.ts";
20
+ /** Default Sui gRPC base URLs by network (public Mysten fullnodes). */
21
+ export declare const DEFAULT_GRPC_URLS: Record<Network, string>;
22
+ /** Minimal shape of a line config that {@link BaseLineClient} reads directly. */
23
+ export interface BaseLineConfig {
24
+ /** Sui gRPC base URL override (default: public Mysten fullnode for the network). */
25
+ grpcUrl?: string;
26
+ /** Package map — iterated by {@link BaseLineClient.packageIds}. */
27
+ packages: object;
28
+ }
29
+ export declare abstract class BaseLineClient<Cfg extends BaseLineConfig = BaseLineConfig> {
30
+ /** gRPC client — all RPC including `simulateTransaction`. */
31
+ grpcClient: SuiGrpcClient;
32
+ /** Network identifier in upper case (`MAINNET` / `TESTNET`). */
33
+ network: Network;
34
+ /** Parsed canonical `waterx-config` JSON for this line. */
35
+ config: Cfg;
36
+ protected constructor(network: Network, config: Cfg, opts?: {
37
+ grpcUrl?: string;
38
+ });
39
+ getObject(objectId: string): Promise<SuiClientTypes.GetObjectResponse<{}>>;
40
+ getObjects(objectIds: string[]): Promise<SuiClientTypes.GetObjectsResponse<{}>>;
41
+ listOwnedObjects(owner: string): Promise<SuiClientTypes.ListOwnedObjectsResponse<{}>>;
42
+ listCoins(params: {
43
+ owner: string;
44
+ coinType?: string;
45
+ }): Promise<SuiClientTypes.ListCoinsResponse>;
46
+ getBalance(params: {
47
+ owner: string;
48
+ coinType?: string;
49
+ }): Promise<SuiClientTypes.GetBalanceResponse>;
50
+ listDynamicFields(parentId: string): ReturnType<SuiGrpcClient["listDynamicFields"]>;
51
+ getDynamicField(parentId: string, name: {
52
+ type: string;
53
+ bcs: Uint8Array;
54
+ }): Promise<SuiClientTypes.GetDynamicFieldResponse>;
55
+ waitForTransaction(digest: string): Promise<SuiClientTypes.TransactionResult<{}>>;
56
+ /**
57
+ * Simulate a transaction (no signing). Subclasses may override to add
58
+ * transport policy (e.g. the prediction line wraps this with rate-limit
59
+ * retry against the public testnet RPC).
60
+ */
61
+ simulate(tx: Transaction): Promise<SuiClientTypes.SimulateTransactionResult<{
62
+ commandResults: true;
63
+ }>>;
64
+ signAndExecuteTransaction<Include extends SuiClientTypes.TransactionInclude = object>(params: {
65
+ signer: {
66
+ toSuiAddress: () => string;
67
+ } & Signer;
68
+ transaction: Transaction | Uint8Array;
69
+ additionalSignatures?: string[];
70
+ include?: Include & SuiClientTypes.TransactionInclude;
71
+ }): Promise<SuiClientTypes.TransactionResult<Include & SuiClientTypes.TransactionInclude>>;
72
+ /** All package IDs (`published_at`) keyed by package name. */
73
+ packageIds(): Record<string, string>;
74
+ }