@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
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Pyth as a price *source*: Hermes REST + the on-chain Pyth update PTB.
3
+ *
4
+ * This file knows nothing about oracle *rules* (pyth_rule / supra_rule /
5
+ * constant_rule / sponsor) — it only fetches price update VAAs from Hermes and
6
+ * appends the Pyth on-chain update block, returning the refreshed
7
+ * `PriceInfoObject` IDs. Feeding rules into a collector and aggregating lives in
8
+ * `aggregate.ts`; the rule wrappers live in `rules/`.
9
+ *
10
+ * On-chain a single PTB:
11
+ * 1. wormhole::vaa::parse_and_verify
12
+ * 2. pyth::create_authenticated_price_infos_using_accumulator
13
+ * 3. pyth::update_single_price_feed (one per feed)
14
+ * 4. hot_potato_vector::destroy
15
+ */
16
+ import { fromHex, toHex } from "@mysten/bcs";
17
+ import { bcs } from "@mysten/sui/bcs";
18
+ export class PythCache {
19
+ pythStateInfo;
20
+ wormholePackageId;
21
+ priceTableInfo;
22
+ priceFeedObjectIdCache = new Map();
23
+ }
24
+ // ============================================================================
25
+ // Hermes REST
26
+ // ============================================================================
27
+ export async function fetchPriceFeedsUpdateData(endpoint, priceIds) {
28
+ if (priceIds.length === 0)
29
+ return [];
30
+ const url = new URL("/v2/updates/price/latest", endpoint);
31
+ priceIds.forEach((id) => url.searchParams.append("ids[]", id));
32
+ const res = await fetch(url.toString(), { signal: AbortSignal.timeout(15_000) });
33
+ if (!res.ok)
34
+ throw new Error(`Hermes price fetch failed: ${res.status} ${await res.text()}`);
35
+ const json = (await res.json());
36
+ const data = json.binary?.data;
37
+ if (!Array.isArray(data) || data.length === 0) {
38
+ throw new Error("Hermes returned no binary price data");
39
+ }
40
+ return data.map((hex) => fromHex(hex));
41
+ }
42
+ // ============================================================================
43
+ // On-chain helpers (cached)
44
+ // ============================================================================
45
+ function pkgFromUpgradeCap(json, objectId) {
46
+ const upgradeCap = json.upgrade_cap ??
47
+ json.fields?.upgrade_cap;
48
+ const nested = upgradeCap?.fields?.package;
49
+ const pkg = typeof upgradeCap?.package === "string"
50
+ ? upgradeCap.package
51
+ : typeof nested === "string"
52
+ ? nested
53
+ : undefined;
54
+ if (!pkg)
55
+ throw new Error(`Cannot resolve package id for object ${objectId}`);
56
+ return pkg;
57
+ }
58
+ async function getPythStateInfo(client, pythStateId, cache) {
59
+ if (cache?.pythStateInfo)
60
+ return cache.pythStateInfo;
61
+ const result = await client.getObject({ objectId: pythStateId, include: { json: true } });
62
+ const json = result.object?.json;
63
+ if (!json)
64
+ throw new Error("Unable to fetch pyth state");
65
+ const packageId = pkgFromUpgradeCap(json, pythStateId);
66
+ const fields = json.fields;
67
+ const fee = (fields?.base_update_fee ?? json.base_update_fee);
68
+ if (fee === undefined)
69
+ throw new Error("Unable to fetch pyth state base_update_fee");
70
+ const info = { packageId, baseUpdateFee: BigInt(fee) };
71
+ if (cache)
72
+ cache.pythStateInfo = info;
73
+ return info;
74
+ }
75
+ async function getWormholePackageId(client, wormholeStateId, cache) {
76
+ if (cache?.wormholePackageId)
77
+ return cache.wormholePackageId;
78
+ const result = await client.getObject({ objectId: wormholeStateId, include: { json: true } });
79
+ const json = result.object?.json;
80
+ if (!json)
81
+ throw new Error(`Cannot resolve wormhole package id from ${wormholeStateId}`);
82
+ const pkg = pkgFromUpgradeCap(json, wormholeStateId);
83
+ if (cache)
84
+ cache.wormholePackageId = pkg;
85
+ return pkg;
86
+ }
87
+ async function getPriceTableInfo(client, pythStateId, cache) {
88
+ if (cache?.priceTableInfo)
89
+ return cache.priceTableInfo;
90
+ const list = await client.listDynamicFields({ parentId: pythStateId });
91
+ const entry = list.dynamicFields.find((e) => {
92
+ const vt = e.valueType || e.objectType || "";
93
+ return vt.includes("PriceIdentifier") || vt.includes("price_info");
94
+ });
95
+ if (!entry)
96
+ throw new Error("Price table not found in Pyth state dynamic fields");
97
+ const childId = entry.childId ?? entry.objectId;
98
+ const typeStr = entry.valueType || entry.objectType || "";
99
+ if (!childId)
100
+ throw new Error("Price table missing childId");
101
+ const pkgMatch = typeStr.match(/(0x[a-fA-F0-9]+)::price_identifier::PriceIdentifier/);
102
+ if (!pkgMatch)
103
+ throw new Error(`Cannot extract package from price table type: ${typeStr}`);
104
+ const info = { id: childId, fieldType: pkgMatch[1] };
105
+ if (cache)
106
+ cache.priceTableInfo = info;
107
+ return info;
108
+ }
109
+ async function getPriceFeedObjectId(client, table, feedId, cache, pythStateId) {
110
+ const normalized = feedId.replace(/^0x/, "");
111
+ const cacheKey = pythStateId ? `${pythStateId}:${normalized}` : normalized;
112
+ if (cache?.priceFeedObjectIdCache.has(cacheKey)) {
113
+ return cache.priceFeedObjectIdCache.get(cacheKey);
114
+ }
115
+ const keyBytes = bcs
116
+ .struct("PriceIdentifier", { bytes: bcs.vector(bcs.u8()) })
117
+ .serialize({ bytes: fromHex(normalized) })
118
+ .toBytes();
119
+ const result = await client.getDynamicField({
120
+ parentId: table.id,
121
+ name: { type: `${table.fieldType}::price_identifier::PriceIdentifier`, bcs: keyBytes },
122
+ });
123
+ const value = result.dynamicField?.value;
124
+ const objectId = !value?.bcs || value.bcs.length < 32 ? undefined : "0x" + toHex(value.bcs);
125
+ if (cache)
126
+ cache.priceFeedObjectIdCache.set(cacheKey, objectId);
127
+ return objectId;
128
+ }
129
+ // ============================================================================
130
+ // Accumulator parsing
131
+ // ============================================================================
132
+ function extractVaaBytes(accumulatorMessage) {
133
+ const view = new DataView(accumulatorMessage.buffer, accumulatorMessage.byteOffset, accumulatorMessage.byteLength);
134
+ const trailingPayloadSize = view.getUint8(6);
135
+ const vaaSizeOffset = 7 + trailingPayloadSize + 1; // +1 for proof_type
136
+ const vaaSize = view.getUint16(vaaSizeOffset, false);
137
+ const vaaOffset = vaaSizeOffset + 2;
138
+ return accumulatorMessage.subarray(vaaOffset, vaaOffset + vaaSize);
139
+ }
140
+ // ============================================================================
141
+ // Pyth update calls
142
+ // ============================================================================
143
+ /**
144
+ * Append the on-chain Pyth update PTB block. Returns `PriceInfoObject` IDs
145
+ * (one per `feedIds`, same order). After this you can feed `pyth_rule` per
146
+ * ticker against the matching `PriceInfoObject` (see `rules/pyth-rule.ts`).
147
+ *
148
+ * If `sponsorFund` is provided, the per-feed update fee comes from the
149
+ * sponsor pool (`pyth_sponsor_rule::split`) instead of `tx.gas`. Opening and
150
+ * reimbursing that fund is the sponsor rule's job (`rules/sponsor.ts`); here we
151
+ * only draw a fee coin from the already-open `fund` hot potato.
152
+ */
153
+ export async function buildPythPriceUpdateCalls(tx, host, updates, feedIds, cache, sponsorFund) {
154
+ if (updates.length === 0) {
155
+ throw new Error("No price update data provided; Hermes returned empty results");
156
+ }
157
+ if (updates.length > 1) {
158
+ throw new Error("Only a single accumulator message is supported per transaction");
159
+ }
160
+ const pyth = host.pyth;
161
+ const [stateInfo, wormholePackageId, table] = await Promise.all([
162
+ getPythStateInfo(host.grpcClient, pyth.state_id, cache),
163
+ getWormholePackageId(host.grpcClient, pyth.wormhole_state_id, cache),
164
+ getPriceTableInfo(host.grpcClient, pyth.state_id, cache),
165
+ ]);
166
+ const priceInfoObjectIds = await Promise.all(feedIds.map((feedId) => getPriceFeedObjectId(host.grpcClient, table, feedId, cache, pyth.state_id)));
167
+ const { packageId: pythPackageId, baseUpdateFee } = stateInfo;
168
+ // 1. Verify VAA
169
+ const vaa = extractVaaBytes(updates[0]);
170
+ const [verifiedVaa] = tx.moveCall({
171
+ target: `${wormholePackageId}::vaa::parse_and_verify`,
172
+ arguments: [tx.object(pyth.wormhole_state_id), tx.pure.vector("u8", vaa), tx.object.clock()],
173
+ });
174
+ // 2. Authenticate price infos
175
+ const [hotPotato0] = tx.moveCall({
176
+ target: `${pythPackageId}::pyth::create_authenticated_price_infos_using_accumulator`,
177
+ arguments: [
178
+ tx.object(pyth.state_id),
179
+ tx.pure.vector("u8", updates[0]),
180
+ verifiedVaa,
181
+ tx.object.clock(),
182
+ ],
183
+ });
184
+ // 3. Per-feed update
185
+ let hotPotato = hotPotato0;
186
+ for (let i = 0; i < feedIds.length; i++) {
187
+ const priceInfoObjectId = priceInfoObjectIds[i];
188
+ if (!priceInfoObjectId) {
189
+ throw new Error(`Pyth feed ${feedIds[i]} not registered on-chain in Pyth state`);
190
+ }
191
+ const feeCoin = sponsorFund
192
+ ? tx.moveCall({
193
+ target: `${sponsorFund.packageId}::pyth_sponsor_rule::split`,
194
+ arguments: [sponsorFund.fund],
195
+ })[0]
196
+ : tx.splitCoins(tx.gas, [tx.pure.u64(baseUpdateFee)])[0];
197
+ [hotPotato] = tx.moveCall({
198
+ target: `${pythPackageId}::pyth::update_single_price_feed`,
199
+ arguments: [
200
+ tx.object(pyth.state_id),
201
+ hotPotato,
202
+ tx.object(priceInfoObjectId),
203
+ feeCoin,
204
+ tx.object.clock(),
205
+ ],
206
+ });
207
+ }
208
+ // 4. Destroy hot potato
209
+ tx.moveCall({
210
+ target: `${pythPackageId}::hot_potato_vector::destroy`,
211
+ arguments: [hotPotato],
212
+ typeArguments: [`${pythPackageId}::price_info::PriceInfo`],
213
+ });
214
+ return priceInfoObjectIds;
215
+ }
216
+ /** All-in-one: fetch from Hermes, append update calls. Returns PriceInfoObject IDs. */
217
+ export async function updatePythPrices(tx, host, feedIds, cache, sponsorFund) {
218
+ const updates = await fetchPriceFeedsUpdateData(host.pyth.hermes_endpoint, feedIds);
219
+ return buildPythPriceUpdateCalls(tx, host, updates, feedIds, cache, sponsorFund);
220
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `constant_rule::feed` — feed a constant-pinned price into the collector. Used
3
+ * for constant tickers ({@link OracleHost.isConstantTicker}); the price comes
4
+ * from the on-chain `constant_rule::Config`, so no Pyth update is needed for a
5
+ * constant-only ticker.
6
+ */
7
+ import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
8
+ import type { OracleHost } from "../host.ts";
9
+ export declare function feedConstantRule(tx: Transaction, host: OracleHost, collector: TransactionArgument): void;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `constant_rule::feed` — feed a constant-pinned price into the collector. Used
3
+ * for constant tickers ({@link OracleHost.isConstantTicker}); the price comes
4
+ * from the on-chain `constant_rule::Config`, so no Pyth update is needed for a
5
+ * constant-only ticker.
6
+ */
7
+ import { feed as constantRuleFeed } from "../../generated/waterx_constant_rule/constant_rule.js";
8
+ export function feedConstantRule(tx, host, collector) {
9
+ const constant = host.config.packages.constant_rule;
10
+ constantRuleFeed({
11
+ package: constant.published_at,
12
+ arguments: { collector, config: tx.object(constant.config) },
13
+ })(tx);
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `pyth_rule::feed` — feed a refreshed Pyth `PriceInfoObject` into an oracle
3
+ * `PriceCollector`. The rule resolves the on-chain feed by ticker via its
4
+ * `Config.identifier_map`, so it is not typed `<T>`.
5
+ *
6
+ * Caller must run the Pyth on-chain update first (see `../pyth.ts`) so the
7
+ * `PriceInfoObject` is fresh.
8
+ */
9
+ import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
10
+ import type { OracleHost } from "../host.ts";
11
+ export declare function feedPythRule(tx: Transaction, host: OracleHost, collector: TransactionArgument, priceInfoObjectId: string): void;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `pyth_rule::feed` — feed a refreshed Pyth `PriceInfoObject` into an oracle
3
+ * `PriceCollector`. The rule resolves the on-chain feed by ticker via its
4
+ * `Config.identifier_map`, so it is not typed `<T>`.
5
+ *
6
+ * Caller must run the Pyth on-chain update first (see `../pyth.ts`) so the
7
+ * `PriceInfoObject` is fresh.
8
+ */
9
+ import { feed as pythRuleFeed } from "../../generated/waterx_pyth_rule/pyth_rule.js";
10
+ export function feedPythRule(tx, host, collector, priceInfoObjectId) {
11
+ pythRuleFeed({
12
+ package: host.config.packages.pyth_rule.published_at,
13
+ arguments: {
14
+ collector,
15
+ config: tx.object(host.config.packages.pyth_rule.config),
16
+ pythState: tx.object(host.pyth.state_id),
17
+ pythPriceInfo: tx.object(priceInfoObjectId),
18
+ },
19
+ })(tx);
20
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * `pyth_sponsor_rule` — pay Pyth update fees from a shared sponsor pool AND
3
+ * attach the `PythSponsorRule` witness to a `TradingRequest`. Required when the
4
+ * market's `request_checklist` contains `PythSponsorRule`.
5
+ *
6
+ * Flow: {@link openPythSponsorFund} opens a `Fund` hot potato; pass the returned
7
+ * `{ fund, packageId }` to the Pyth update path as its `sponsorFund` (it draws
8
+ * per-feed fees via `pyth_sponsor_rule::split`); then {@link reimbursePythSponsor}
9
+ * consumes the `Fund`, returns leftover SUI, and attaches the witness.
10
+ */
11
+ import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
12
+ import type { OracleHost } from "../host.ts";
13
+ /**
14
+ * Opens a `Fund` hot potato from the shared PythSponsor pool. Pass the returned
15
+ * `{ fund, packageId }` straight to `refreshOraclePrices` as `sponsorFund`, then
16
+ * {@link reimbursePythSponsor} once the TradingRequest is built.
17
+ */
18
+ export declare function openPythSponsorFund(tx: Transaction, host: OracleHost): {
19
+ fund: TransactionArgument;
20
+ packageId: string;
21
+ };
22
+ /**
23
+ * Consumes the `Fund` hot potato from {@link openPythSponsorFund}, returns any
24
+ * leftover SUI to the sponsor pool, and attaches the `PythSponsorRule` witness to
25
+ * the given `TradingRequest<C_TOKEN>` so `trading::execute` can satisfy a
26
+ * checklist that includes `PythSponsorRule`.
27
+ */
28
+ export declare function reimbursePythSponsor(tx: Transaction, host: OracleHost, fund: TransactionArgument, tradingRequest: TransactionArgument, collateralType: string): void;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `pyth_sponsor_rule` — pay Pyth update fees from a shared sponsor pool AND
3
+ * attach the `PythSponsorRule` witness to a `TradingRequest`. Required when the
4
+ * market's `request_checklist` contains `PythSponsorRule`.
5
+ *
6
+ * Flow: {@link openPythSponsorFund} opens a `Fund` hot potato; pass the returned
7
+ * `{ fund, packageId }` to the Pyth update path as its `sponsorFund` (it draws
8
+ * per-feed fees via `pyth_sponsor_rule::split`); then {@link reimbursePythSponsor}
9
+ * consumes the `Fund`, returns leftover SUI, and attaches the witness.
10
+ */
11
+ import { reimburse as sponsorReimburse, request as sponsorRequest, } from "../../generated/pyth_sponsor_rule/pyth_sponsor_rule.js";
12
+ /**
13
+ * Opens a `Fund` hot potato from the shared PythSponsor pool. Pass the returned
14
+ * `{ fund, packageId }` straight to `refreshOraclePrices` as `sponsorFund`, then
15
+ * {@link reimbursePythSponsor} once the TradingRequest is built.
16
+ */
17
+ export function openPythSponsorFund(tx, host) {
18
+ const entry = host.config.packages.pyth_sponsor_rule;
19
+ if (!entry?.published_at || !entry.pyth_sponsor) {
20
+ throw new Error("pyth_sponsor_rule.{published_at,pyth_sponsor} missing — sponsor flow unavailable");
21
+ }
22
+ const [fund] = sponsorRequest({
23
+ package: entry.published_at,
24
+ arguments: { self: tx.object(entry.pyth_sponsor) },
25
+ })(tx);
26
+ return { fund: fund, packageId: entry.published_at };
27
+ }
28
+ /**
29
+ * Consumes the `Fund` hot potato from {@link openPythSponsorFund}, returns any
30
+ * leftover SUI to the sponsor pool, and attaches the `PythSponsorRule` witness to
31
+ * the given `TradingRequest<C_TOKEN>` so `trading::execute` can satisfy a
32
+ * checklist that includes `PythSponsorRule`.
33
+ */
34
+ export function reimbursePythSponsor(tx, host, fund, tradingRequest, collateralType) {
35
+ const entry = host.config.packages.pyth_sponsor_rule;
36
+ if (!entry?.published_at || !entry.pyth_sponsor) {
37
+ throw new Error("pyth_sponsor_rule missing from config");
38
+ }
39
+ sponsorReimburse({
40
+ package: entry.published_at,
41
+ arguments: {
42
+ self: tx.object(entry.pyth_sponsor),
43
+ fund: fund,
44
+ tradingReq: tradingRequest,
45
+ },
46
+ typeArguments: [collateralType],
47
+ })(tx);
48
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `supra_rule::feed` — feed Supra as a second weighted rule on the same
3
+ * `PriceCollector` as Pyth, before `aggregate`.
4
+ *
5
+ * `maybeFeedSupra` is a no-op unless the deployment has supra enabled + wired
6
+ * (see {@link OracleHost.getSupraRule}), so Pyth-only deployments are unchanged.
7
+ * On-chain the rule abstains for symbols it has no pair for.
8
+ */
9
+ import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
10
+ import type { OracleHost } from "../host.ts";
11
+ export declare function maybeFeedSupra(tx: Transaction, host: OracleHost, collector: TransactionArgument): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * `supra_rule::feed` — feed Supra as a second weighted rule on the same
3
+ * `PriceCollector` as Pyth, before `aggregate`.
4
+ *
5
+ * `maybeFeedSupra` is a no-op unless the deployment has supra enabled + wired
6
+ * (see {@link OracleHost.getSupraRule}), so Pyth-only deployments are unchanged.
7
+ * On-chain the rule abstains for symbols it has no pair for.
8
+ */
9
+ import { feed as supraRuleFeed } from "../../generated/waterx_supra_rule/supra_rule.js";
10
+ export function maybeFeedSupra(tx, host, collector) {
11
+ const supra = host.getSupraRule();
12
+ if (!supra)
13
+ return;
14
+ supraRuleFeed({
15
+ package: supra.published_at,
16
+ arguments: {
17
+ collector,
18
+ config: tx.object(supra.config),
19
+ oracleHolder: tx.object(supra.oracle_holder),
20
+ },
21
+ })(tx);
22
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * WaterX Perp client — the perp product line (trading, orders, WLP, staking).
3
+ *
4
+ * One of the two sub-clients behind the umbrella `WaterXClient`; reachable as
5
+ * `client.perp` (which also carries the perp builders). Initialization is async —
6
+ * config is fetched from the canonical `waterx-config` JSON (default: GitHub raw).
7
+ * See `PerpClient.create()`.
8
+ *
9
+ * Composition: the gRPC transport half is inherited from {@link BaseLineClient}
10
+ * (shared with `PredictClient`); the canonical-schema lookups are delegated to a
11
+ * {@link PerpConfigView}. This class is just the wiring + factory between them.
12
+ */
13
+ import { BaseLineClient } from "../base-client.ts";
14
+ import { type LoadConfigOptions, type PythInfraConfig, type WaterXConfig, type WormholeInfraConfig } from "./config.ts";
15
+ import type { Network } from "./constants.ts";
16
+ export interface CreateClientOptions extends LoadConfigOptions {
17
+ grpcUrl?: string;
18
+ }
19
+ export declare class PerpClient extends BaseLineClient<WaterXConfig> {
20
+ /** Pyth infra (network defaults unless overridden in JSON). */
21
+ pyth: PythInfraConfig;
22
+ /** Wormhole infra for the credit bridge (network defaults unless overridden). */
23
+ wormhole: WormholeInfraConfig;
24
+ /** Canonical-schema lookups (delegated to below); no transport. */
25
+ private readonly view;
26
+ constructor(network: Network, config: WaterXConfig, opts?: {
27
+ grpcUrl?: string;
28
+ });
29
+ /**
30
+ * Async factory: fetches the deployment config for `network` and returns
31
+ * a ready-to-use client. Pass `opts.cache=true` to memoize the JSON.
32
+ */
33
+ static create(network: Network, opts?: CreateClientOptions): Promise<PerpClient>;
34
+ static mainnet(opts?: CreateClientOptions): Promise<PerpClient>;
35
+ static testnet(opts?: CreateClientOptions): Promise<PerpClient>;
36
+ /** @see PerpConfigView.getMarket */
37
+ getMarket(ticker: string): import("./config.ts").WaterxPerpMarketEntry;
38
+ /** @see PerpConfigView.getAggregator */
39
+ getAggregator(ticker: string): string;
40
+ /** @see PerpConfigView.getPythFeed */
41
+ getPythFeed(ticker: string): {
42
+ feed_id: string;
43
+ price_info_object: string;
44
+ };
45
+ /** @see PerpConfigView.isConstantTicker */
46
+ isConstantTicker(ticker: string): boolean;
47
+ /** @see PerpConfigView.getSupraRule */
48
+ getSupraRule(): {
49
+ published_at: string;
50
+ config: string;
51
+ oracle_holder: string;
52
+ } | undefined;
53
+ /** @see PerpConfigView.getPoolTokenType */
54
+ getPoolTokenType(tickerOrName: string): string;
55
+ /** @see PerpConfigView.wlpType */
56
+ wlpType(): string;
57
+ /** @see PerpConfigView.getRewarders */
58
+ getRewarders(stakeAlias: string): {
59
+ alias: string;
60
+ rewarder_id: string;
61
+ coin_type: string;
62
+ decimals: number;
63
+ }[];
64
+ /** @see PerpConfigView.getRewarderTypes */
65
+ getRewarderTypes(stakeAlias: string): string[];
66
+ /** @see PerpConfigView.getCredit */
67
+ getCredit(): import("./config.ts").WaterxCreditPackage;
68
+ /** @see PerpConfigView.creditType */
69
+ creditType(): string;
70
+ /** @see PerpConfigView.getBridge */
71
+ getBridge(): import("./config.ts").WormholeBridgePackage;
72
+ /** @see PerpConfigView.wormholeStateId */
73
+ wormholeStateId(): string;
74
+ /** @see PerpConfigView.getNativeAssets */
75
+ getNativeAssets(): readonly import("./config.ts").NativeCustodyAsset[];
76
+ /** @see PerpConfigView.getNativeAsset */
77
+ getNativeAsset(moveType: string): import("./config.ts").NativeCustodyAsset;
78
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * WaterX Perp client — the perp product line (trading, orders, WLP, staking).
3
+ *
4
+ * One of the two sub-clients behind the umbrella `WaterXClient`; reachable as
5
+ * `client.perp` (which also carries the perp builders). Initialization is async —
6
+ * config is fetched from the canonical `waterx-config` JSON (default: GitHub raw).
7
+ * See `PerpClient.create()`.
8
+ *
9
+ * Composition: the gRPC transport half is inherited from {@link BaseLineClient}
10
+ * (shared with `PredictClient`); the canonical-schema lookups are delegated to a
11
+ * {@link PerpConfigView}. This class is just the wiring + factory between them.
12
+ */
13
+ import { BaseLineClient } from "../base-client.js";
14
+ import { PerpConfigView } from "./config-view.js";
15
+ import { loadConfig, PYTH_DEFAULTS, WORMHOLE_DEFAULTS, } from "./config.js";
16
+ export class PerpClient extends BaseLineClient {
17
+ /** Pyth infra (network defaults unless overridden in JSON). */
18
+ pyth;
19
+ /** Wormhole infra for the credit bridge (network defaults unless overridden). */
20
+ wormhole;
21
+ /** Canonical-schema lookups (delegated to below); no transport. */
22
+ view;
23
+ constructor(network, config, opts = {}) {
24
+ super(network, config, opts);
25
+ this.pyth = config.pyth ?? PYTH_DEFAULTS[network];
26
+ this.wormhole = config.wormhole ?? WORMHOLE_DEFAULTS[network];
27
+ this.view = new PerpConfigView(() => this.config, () => this.wormhole);
28
+ }
29
+ /**
30
+ * Async factory: fetches the deployment config for `network` and returns
31
+ * a ready-to-use client. Pass `opts.cache=true` to memoize the JSON.
32
+ */
33
+ static async create(network, opts = {}) {
34
+ const config = await loadConfig(network, opts);
35
+ return new PerpClient(network, config, { grpcUrl: opts.grpcUrl });
36
+ }
37
+ static mainnet(opts = {}) {
38
+ return PerpClient.create("MAINNET", opts);
39
+ }
40
+ static testnet(opts = {}) {
41
+ return PerpClient.create("TESTNET", opts);
42
+ }
43
+ // ========================================================
44
+ // Config-schema lookups — delegated to PerpConfigView.
45
+ // (Kept on the client so the ~50 builders typed `PerpClient` call them
46
+ // directly, e.g. `client.wlpType()`. See perp-config-view.ts for docs.)
47
+ // ========================================================
48
+ /** @see PerpConfigView.getMarket */
49
+ getMarket(ticker) {
50
+ return this.view.getMarket(ticker);
51
+ }
52
+ /** @see PerpConfigView.getAggregator */
53
+ getAggregator(ticker) {
54
+ return this.view.getAggregator(ticker);
55
+ }
56
+ /** @see PerpConfigView.getPythFeed */
57
+ getPythFeed(ticker) {
58
+ return this.view.getPythFeed(ticker);
59
+ }
60
+ /** @see PerpConfigView.isConstantTicker */
61
+ isConstantTicker(ticker) {
62
+ return this.view.isConstantTicker(ticker);
63
+ }
64
+ /** @see PerpConfigView.getSupraRule */
65
+ getSupraRule() {
66
+ return this.view.getSupraRule();
67
+ }
68
+ /** @see PerpConfigView.getPoolTokenType */
69
+ getPoolTokenType(tickerOrName) {
70
+ return this.view.getPoolTokenType(tickerOrName);
71
+ }
72
+ /** @see PerpConfigView.wlpType */
73
+ wlpType() {
74
+ return this.view.wlpType();
75
+ }
76
+ /** @see PerpConfigView.getRewarders */
77
+ getRewarders(stakeAlias) {
78
+ return this.view.getRewarders(stakeAlias);
79
+ }
80
+ /** @see PerpConfigView.getRewarderTypes */
81
+ getRewarderTypes(stakeAlias) {
82
+ return this.view.getRewarderTypes(stakeAlias);
83
+ }
84
+ /** @see PerpConfigView.getCredit */
85
+ getCredit() {
86
+ return this.view.getCredit();
87
+ }
88
+ /** @see PerpConfigView.creditType */
89
+ creditType() {
90
+ return this.view.creditType();
91
+ }
92
+ /** @see PerpConfigView.getBridge */
93
+ getBridge() {
94
+ return this.view.getBridge();
95
+ }
96
+ /** @see PerpConfigView.wormholeStateId */
97
+ wormholeStateId() {
98
+ return this.view.wormholeStateId();
99
+ }
100
+ /** @see PerpConfigView.getNativeAssets */
101
+ getNativeAssets() {
102
+ return this.view.getNativeAssets();
103
+ }
104
+ /** @see PerpConfigView.getNativeAsset */
105
+ getNativeAsset(moveType) {
106
+ return this.view.getNativeAsset(moveType);
107
+ }
108
+ }
@@ -1,65 +1,20 @@
1
1
  /**
2
- * WaterX Protocol client.
2
+ * Perp config-schema views — read-only lookups over the parsed `waterx-config`
3
+ * JSON, with no transport dependency.
3
4
  *
4
- * Initialization is async config is fetched from the canonical
5
- * `waterx-config` JSON (default: GitHub raw). See `WaterXClient.create()`.
5
+ * Split off the transport client (`PerpClient`) so the two responsibilities stay
6
+ * separate: `BaseLineClient` owns the gRPC half, this class owns the
7
+ * canonical-schema half. `PerpClient` composes one of these and delegates, so
8
+ * callers keep calling `client.getMarket(...)` / `client.wlpType()` unchanged.
9
+ * Tested in isolation against a plain config object — no network needed.
6
10
  */
7
- import { SuiGrpcClient } from "@mysten/sui/grpc";
8
- import { Transaction } from "@mysten/sui/transactions";
9
- import { type LoadConfigOptions, type NativeCustodyAsset, type PythInfraConfig, type WaterXConfig, type WormholeInfraConfig } from "./config.ts";
10
- import type { Network } from "./constants.ts";
11
- export interface CreateClientOptions extends LoadConfigOptions {
12
- grpcUrl?: string;
13
- }
14
- export declare class WaterXClient {
15
- /** gRPC client — all RPC including `simulateTransaction`. */
16
- grpcClient: SuiGrpcClient;
17
- /** Network identifier in upper case (`MAINNET` / `TESTNET`). */
18
- network: Network;
19
- /** Parsed canonical `waterx-config` JSON. */
20
- config: WaterXConfig;
21
- /** Pyth infra (network defaults unless overridden in JSON). */
22
- pyth: PythInfraConfig;
23
- /** Wormhole infra for the credit bridge (network defaults unless overridden). */
24
- wormhole: WormholeInfraConfig;
25
- constructor(network: Network, config: WaterXConfig, opts?: {
26
- grpcUrl?: string;
27
- });
28
- /**
29
- * Async factory: fetches the deployment config for `network` and returns
30
- * a ready-to-use client. Pass `opts.cache=true` to memoize the JSON.
31
- */
32
- static create(network: Network, opts?: CreateClientOptions): Promise<WaterXClient>;
33
- static mainnet(opts?: CreateClientOptions): Promise<WaterXClient>;
34
- static testnet(opts?: CreateClientOptions): Promise<WaterXClient>;
35
- getObject(objectId: string): Promise<import("@mysten/sui/client").SuiClientTypes.GetObjectResponse<{}>>;
36
- getObjects(objectIds: string[]): Promise<import("@mysten/sui/client").SuiClientTypes.GetObjectsResponse<{}>>;
37
- listOwnedObjects(owner: string): Promise<import("@mysten/sui/client").SuiClientTypes.ListOwnedObjectsResponse<{}>>;
38
- listCoins(params: {
39
- owner: string;
40
- coinType?: string;
41
- }): Promise<import("@mysten/sui/client").SuiClientTypes.ListCoinsResponse>;
42
- getBalance(params: {
43
- owner: string;
44
- coinType?: string;
45
- }): Promise<import("@mysten/sui/client").SuiClientTypes.GetBalanceResponse>;
46
- listDynamicFields(parentId: string): ReturnType<SuiGrpcClient["listDynamicFields"]>;
47
- getDynamicField(parentId: string, name: {
48
- type: string;
49
- bcs: Uint8Array;
50
- }): Promise<import("@mysten/sui/client").SuiClientTypes.GetDynamicFieldResponse>;
51
- waitForTransaction(digest: string): Promise<import("@mysten/sui/client").SuiClientTypes.TransactionResult<{}>>;
52
- simulate(tx: Transaction): Promise<import("@mysten/sui/client").SuiClientTypes.SimulateTransactionResult<{
53
- commandResults: true;
54
- }>>;
55
- signAndExecuteTransaction(params: {
56
- signer: {
57
- toSuiAddress: () => string;
58
- } & import("@mysten/sui/cryptography").Signer;
59
- transaction: Transaction;
60
- }): Promise<import("@mysten/sui/client").SuiClientTypes.TransactionResult<{}>>;
61
- /** All package IDs (`published_at`) keyed by package name. */
62
- packageIds(): Record<string, string>;
11
+ import type { NativeCustodyAsset, WaterXConfig, WormholeInfraConfig } from "./config.ts";
12
+ export declare class PerpConfigView {
13
+ private readonly getConfig;
14
+ private readonly getWormhole;
15
+ constructor(getConfig: () => WaterXConfig, getWormhole: () => WormholeInfraConfig);
16
+ private get config();
17
+ private get wormhole();
63
18
  /** `waterx_perp.markets[ticker]`, throws if unknown. */
64
19
  getMarket(ticker: string): import("./config.ts").WaterxPerpMarketEntry;
65
20
  /** `waterx_oracle.aggregators[ticker]`, throws if unknown. */
@@ -137,7 +92,7 @@ export declare class WaterXClient {
137
92
  getBridge(): import("./config.ts").WormholeBridgePackage;
138
93
  /**
139
94
  * Sui Wormhole `State` object id — prefers the per-deployment
140
- * `wormhole_bridge.wormhole_state`, falls back to `client.wormhole`.
95
+ * `wormhole_bridge.wormhole_state`, falls back to the line's `wormhole` infra.
141
96
  */
142
97
  wormholeStateId(): string;
143
98
  /** All native-custody backing-asset rows (throws if no custody vault). */