@waterx/sdk 4.3.2 → 5.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 (150) hide show
  1. package/.claude/skills/waterx-sdk-integration/SKILL.md +225 -0
  2. package/README.md +216 -45
  3. package/SKILLS.md +34 -0
  4. package/dist/cjs/src/account/config.d.ts +3 -5
  5. package/dist/cjs/src/account/funding/wormhole.d.ts +1 -2
  6. package/dist/cjs/src/account/funding/wormhole.js +1 -2
  7. package/dist/cjs/src/generated/waterx_rule/waterx_rule.d.ts +140 -7
  8. package/dist/cjs/src/generated/waterx_rule/waterx_rule.js +163 -8
  9. package/dist/cjs/src/oracle/aggregate.d.ts +49 -62
  10. package/dist/cjs/src/oracle/aggregate.js +208 -164
  11. package/dist/cjs/src/oracle/config.d.ts +38 -51
  12. package/dist/cjs/src/oracle/config.js +1 -1
  13. package/dist/cjs/src/oracle/host.d.ts +14 -19
  14. package/dist/cjs/src/oracle/host.js +3 -3
  15. package/dist/cjs/src/oracle/index.d.ts +25 -16
  16. package/dist/cjs/src/oracle/index.js +87 -69
  17. package/dist/cjs/src/oracle/price-update-rule.d.ts +104 -66
  18. package/dist/cjs/src/oracle/price-update-rule.js +24 -16
  19. package/dist/cjs/src/oracle/pyth-pro-history.d.ts +36 -0
  20. package/dist/cjs/src/oracle/pyth-pro-history.js +41 -0
  21. package/dist/cjs/src/oracle/read-plane.d.ts +35 -53
  22. package/dist/cjs/src/oracle/read-plane.js +26 -48
  23. package/dist/cjs/src/oracle/read-prices.d.ts +105 -0
  24. package/dist/cjs/src/oracle/read-prices.js +162 -0
  25. package/dist/cjs/src/oracle/rule-registry.d.ts +12 -12
  26. package/dist/cjs/src/oracle/rule-registry.js +12 -14
  27. package/dist/cjs/src/oracle/rules/pyth-lazer-rule.d.ts +24 -3
  28. package/dist/cjs/src/oracle/rules/pyth-lazer-rule.js +40 -20
  29. package/dist/cjs/src/oracle/rules/waterx-rule.d.ts +271 -57
  30. package/dist/cjs/src/oracle/rules/waterx-rule.js +743 -144
  31. package/dist/cjs/src/oracle/schedule.d.ts +109 -0
  32. package/dist/cjs/src/oracle/schedule.js +991 -0
  33. package/dist/cjs/src/oracle/source-list.d.ts +31 -27
  34. package/dist/cjs/src/oracle/source-list.js +43 -45
  35. package/dist/cjs/src/oracle/symbol-catalog.d.ts +54 -0
  36. package/dist/cjs/src/oracle/symbol-catalog.js +69 -0
  37. package/dist/cjs/src/oracle/update-fetch.d.ts +11 -15
  38. package/dist/cjs/src/oracle/update-fetch.js +12 -19
  39. package/dist/cjs/src/oracle/validate.d.ts +105 -0
  40. package/dist/cjs/src/oracle/validate.js +185 -0
  41. package/dist/cjs/src/oracle/weight-coverage.d.ts +79 -0
  42. package/dist/cjs/src/oracle/weight-coverage.js +173 -0
  43. package/dist/cjs/src/perp/client.d.ts +40 -55
  44. package/dist/cjs/src/perp/client.js +44 -17
  45. package/dist/cjs/src/perp/config-view.d.ts +5 -14
  46. package/dist/cjs/src/perp/config-view.js +5 -16
  47. package/dist/cjs/src/perp/config.d.ts +3 -3
  48. package/dist/cjs/src/perp/config.js +11 -13
  49. package/dist/cjs/src/perp/index.d.ts +4 -6
  50. package/dist/cjs/src/perp/index.js +43 -18
  51. package/dist/cjs/src/perp/tx-builders/common.d.ts +86 -48
  52. package/dist/cjs/src/perp/tx-builders/common.js +115 -47
  53. package/dist/cjs/src/perp/tx-builders/wlp.d.ts +3 -14
  54. package/dist/cjs/src/perp/tx-builders/wlp.js +6 -35
  55. package/dist/cjs/src/perp/tx-builders.d.ts +6 -5
  56. package/dist/cjs/src/perp/tx-builders.js +16 -10
  57. package/dist/cjs/src/unified-client.d.ts +9 -35
  58. package/dist/cjs/src/unified-client.js +3 -4
  59. package/dist/cjs/src/utils/config.d.ts +0 -8
  60. package/dist/cjs/src/utils/config.js +5 -13
  61. package/dist/src/account/config.d.ts +3 -5
  62. package/dist/src/account/funding/wormhole.d.ts +1 -2
  63. package/dist/src/account/funding/wormhole.js +1 -2
  64. package/dist/src/generated/waterx_rule/waterx_rule.d.ts +140 -7
  65. package/dist/src/generated/waterx_rule/waterx_rule.js +151 -7
  66. package/dist/src/oracle/aggregate.d.ts +49 -62
  67. package/dist/src/oracle/aggregate.js +209 -164
  68. package/dist/src/oracle/config.d.ts +38 -51
  69. package/dist/src/oracle/config.js +1 -1
  70. package/dist/src/oracle/host.d.ts +14 -19
  71. package/dist/src/oracle/host.js +3 -3
  72. package/dist/src/oracle/index.d.ts +25 -16
  73. package/dist/src/oracle/index.js +61 -54
  74. package/dist/src/oracle/price-update-rule.d.ts +104 -66
  75. package/dist/src/oracle/price-update-rule.js +23 -16
  76. package/dist/src/oracle/pyth-pro-history.d.ts +36 -0
  77. package/dist/src/oracle/pyth-pro-history.js +38 -0
  78. package/dist/src/oracle/read-plane.d.ts +35 -53
  79. package/dist/src/oracle/read-plane.js +25 -47
  80. package/dist/src/oracle/read-prices.d.ts +105 -0
  81. package/dist/src/oracle/read-prices.js +156 -0
  82. package/dist/src/oracle/rule-registry.d.ts +12 -12
  83. package/dist/src/oracle/rule-registry.js +12 -14
  84. package/dist/src/oracle/rules/pyth-lazer-rule.d.ts +24 -3
  85. package/dist/src/oracle/rules/pyth-lazer-rule.js +39 -20
  86. package/dist/src/oracle/rules/waterx-rule.d.ts +271 -57
  87. package/dist/src/oracle/rules/waterx-rule.js +735 -144
  88. package/dist/src/oracle/schedule.d.ts +109 -0
  89. package/dist/src/oracle/schedule.js +985 -0
  90. package/dist/src/oracle/source-list.d.ts +31 -27
  91. package/dist/src/oracle/source-list.js +42 -43
  92. package/dist/src/oracle/symbol-catalog.d.ts +54 -0
  93. package/dist/src/oracle/symbol-catalog.js +65 -0
  94. package/dist/src/oracle/update-fetch.d.ts +11 -15
  95. package/dist/src/oracle/update-fetch.js +12 -18
  96. package/dist/src/oracle/validate.d.ts +105 -0
  97. package/dist/src/oracle/validate.js +177 -0
  98. package/dist/src/oracle/weight-coverage.d.ts +79 -0
  99. package/dist/src/oracle/weight-coverage.js +166 -0
  100. package/dist/src/perp/client.d.ts +40 -55
  101. package/dist/src/perp/client.js +45 -18
  102. package/dist/src/perp/config-view.d.ts +5 -14
  103. package/dist/src/perp/config-view.js +5 -16
  104. package/dist/src/perp/config.d.ts +3 -3
  105. package/dist/src/perp/config.js +11 -13
  106. package/dist/src/perp/index.d.ts +4 -6
  107. package/dist/src/perp/index.js +17 -5
  108. package/dist/src/perp/tx-builders/common.d.ts +86 -48
  109. package/dist/src/perp/tx-builders/common.js +114 -48
  110. package/dist/src/perp/tx-builders/wlp.d.ts +3 -14
  111. package/dist/src/perp/tx-builders/wlp.js +6 -35
  112. package/dist/src/perp/tx-builders.d.ts +6 -5
  113. package/dist/src/perp/tx-builders.js +15 -6
  114. package/dist/src/unified-client.d.ts +9 -35
  115. package/dist/src/unified-client.js +3 -4
  116. package/dist/src/utils/config.d.ts +0 -8
  117. package/dist/src/utils/config.js +5 -12
  118. package/package.json +8 -2
  119. package/dist/cjs/src/generated/pyth_sponsor_rule/deps/sui/balance.d.ts +0 -12
  120. package/dist/cjs/src/generated/pyth_sponsor_rule/deps/sui/balance.js +0 -17
  121. package/dist/cjs/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +0 -68
  122. package/dist/cjs/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +0 -113
  123. package/dist/cjs/src/generated/waterx_pyth_rule/deps/sui/vec_map.d.ts +0 -36
  124. package/dist/cjs/src/generated/waterx_pyth_rule/deps/sui/vec_map.js +0 -31
  125. package/dist/cjs/src/generated/waterx_pyth_rule/pyth_rule.d.ts +0 -192
  126. package/dist/cjs/src/generated/waterx_pyth_rule/pyth_rule.js +0 -214
  127. package/dist/cjs/src/oracle/pyth.d.ts +0 -227
  128. package/dist/cjs/src/oracle/pyth.js +0 -652
  129. package/dist/cjs/src/oracle/rules/pyth-core-rule.d.ts +0 -15
  130. package/dist/cjs/src/oracle/rules/pyth-core-rule.js +0 -100
  131. package/dist/cjs/src/oracle/rules/pyth-rule.d.ts +0 -11
  132. package/dist/cjs/src/oracle/rules/pyth-rule.js +0 -29
  133. package/dist/cjs/src/oracle/rules/sponsor.d.ts +0 -32
  134. package/dist/cjs/src/oracle/rules/sponsor.js +0 -56
  135. package/dist/src/generated/pyth_sponsor_rule/deps/sui/balance.d.ts +0 -12
  136. package/dist/src/generated/pyth_sponsor_rule/deps/sui/balance.js +0 -14
  137. package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +0 -68
  138. package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +0 -73
  139. package/dist/src/generated/waterx_pyth_rule/deps/sui/vec_map.d.ts +0 -36
  140. package/dist/src/generated/waterx_pyth_rule/deps/sui/vec_map.js +0 -27
  141. package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +0 -192
  142. package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +0 -170
  143. package/dist/src/oracle/pyth.d.ts +0 -227
  144. package/dist/src/oracle/pyth.js +0 -638
  145. package/dist/src/oracle/rules/pyth-core-rule.d.ts +0 -15
  146. package/dist/src/oracle/rules/pyth-core-rule.js +0 -97
  147. package/dist/src/oracle/rules/pyth-rule.d.ts +0 -11
  148. package/dist/src/oracle/rules/pyth-rule.js +0 -26
  149. package/dist/src/oracle/rules/sponsor.d.ts +0 -32
  150. package/dist/src/oracle/rules/sponsor.js +0 -52
@@ -2,12 +2,12 @@
2
2
  * Oracle aggregation — the orchestrator that composes rules into the shared
3
3
  * `Oracle`. This is the ONE file that knows about every rule: it builds a
4
4
  * `PriceCollector`, feeds whichever rules a ticker is configured for
5
- * (Pyth / Lazer / Supra / Constant), then `aggregate`s.
5
+ * (Lazer / Waterx / Supra / Constant), then `aggregate`s.
6
6
  *
7
7
  * Per ticker:
8
8
  * collector = oracle::new_collector(ticker)
9
- * [pyth_rule::feed] when the ticker has a pyth_rule.feeds entry
10
9
  * [pyth_lazer_rule::feed] when the update leg produced a verified lazer Update
10
+ * [waterx_rule::collect_*] when the update leg fetched signed waterx data
11
11
  * [supra_rule::feed] when supra is enabled + wired
12
12
  * [constant_rule::feed] when the ticker is a constant ticker
13
13
  * oracle::aggregate(oracle, collector)
@@ -24,67 +24,68 @@
24
24
  */
25
25
  import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
26
26
  import type { OracleHost } from "./host.ts";
27
- import type { OracleSource, PriceUpdateRule, UpdateDataProvider } from "./price-update-rule.ts";
28
- import { type OracleFeeSource, type PythCache } from "./pyth.ts";
29
- import { type WaterxSignedEnvelope } from "./rules/waterx-rule.ts";
27
+ import { type OracleSource, type PriceUpdateRule, type UpdateDataProvider } from "./price-update-rule.ts";
28
+ import { type WaterxSignedEnvelope, type WaterxSignedLeaf } from "./rules/waterx-rule.ts";
30
29
  /**
31
30
  * Aggregate one ticker's price into the shared `Oracle`: build a collector, feed
32
31
  * every rule the ticker is configured for, then `aggregate`.
33
32
  *
34
- * - **Pyth** — fed when `priceInfoObjectId` is supplied (i.e. the ticker has a
35
- * `pyth_rule.feeds` entry). When this PTB's update leg refreshed the
36
- * `PriceInfoObject` it contributes a fresh price; when it did not (a
37
- * lazer-routed ticker), the on-chain rule only READS the object and abstains
38
- * if it is stale — it never aborts — so the call stays mandatory while
39
- * `pyth_rule` remains in the ticker's on-chain weighted set
40
- * (`EMissingPriceSource` requires every weighted rule to appear).
41
33
  * - **Lazer** — fed when `lazerUpdate` is supplied: the verified update this
42
34
  * PTB's lazer update leg produced with the network's verify entry
43
35
  * (`update_v2::Update` on mainnet, `update::Update` on testnet — see
44
36
  * `PythLazerRule.buildUpdateCalls`). If the ticker's aggregator does
45
37
  * not (yet) weight `PythLazerRule`, the contribution is silently dropped
46
38
  * on-chain — feeding ahead of the weight migration is harmless.
47
- * - **Supra** — fed alongside Pyth/Lazer when supra is enabled + wired
39
+ * - **Waterx** — fed when `waterxLeaf` (default shape) or `waterxEnvelope`
40
+ * (fallback shape) is supplied; verify AND feed are bundled into the one
41
+ * collect call per collector.
42
+ * - **Supra** — fed alongside the sources when supra is enabled + wired
48
43
  * (abstains on-chain for symbols it has no pair for).
49
44
  * - **Constant** — fed when the ticker is a constant ticker
50
45
  * ({@link OracleHost.isConstantTicker}).
51
46
  *
52
- * "Dual-feed" (Pyth + Constant, or Pyth + Lazer) and "constant-only" are not
47
+ * "Dual-feed" (Lazer + Constant, or Lazer + Waterx) and "constant-only" are not
53
48
  * special cases — they fall out of which rules the ticker is in. Throws if no
54
49
  * rule applies.
55
50
  */
56
51
  export declare function aggregateTicker(tx: Transaction, host: OracleHost, args: {
57
52
  ticker: string;
58
- priceInfoObjectId?: string;
59
53
  lazerUpdate?: TransactionArgument;
54
+ /** This ticker's signed Merkle leaf — the default waterx shape. */
55
+ waterxLeaf?: WaterxSignedLeaf;
56
+ /** Batch envelope covering this ticker — the fallback waterx shape. */
60
57
  waterxEnvelope?: WaterxSignedEnvelope;
61
58
  }): void;
62
59
  /**
63
- * Thin wrapper over {@link aggregateTicker} for a Pyth-fed ticker. Kept for
64
- * back-compat (e.g. WLP mint builds). Caller must run the Pyth update first.
60
+ * {@link aggregateTicker} for a **constant-only** ticker (no source update
61
+ * needed the price comes from the on-chain `constant_rule::Config`). Kept as
62
+ * a named entry so constant-only call sites (e.g. WLP builders refreshing the
63
+ * USDCUSD pool token) read as what they are; it adds nothing over
64
+ * `aggregateTicker(tx, host, { ticker })`.
65
65
  */
66
- export declare function aggregateTickerWithPyth(tx: Transaction, host: OracleHost, args: {
66
+ export declare function aggregateTickerWithConstant(tx: Transaction, host: OracleHost, args: {
67
67
  ticker: string;
68
- priceInfoObjectId: string;
69
68
  }): void;
70
69
  /**
71
- * {@link aggregateTicker} for a **constant-only** ticker (no Pyth update needed —
72
- * the price comes from the on-chain `constant_rule::Config`).
70
+ * What {@link refreshOraclePrices} actually put on chain.
73
71
  *
74
- * Throws if the ticker ALSO has a `pyth_rule.feeds` entry (a dual-feed transition
75
- * ticker): feeding only the constant leg would leave the still-weighted Pyth rule
76
- * absent from the collector and abort `aggregate` with `EMissingPriceSource`. Such
77
- * tickers must go through {@link aggregateTicker} with a `priceInfoObjectId` (or
78
- * {@link refreshOraclePrices}), which feeds both.
72
+ * `skipped` holds the requested tickers NO listed source can price (and that
73
+ * `constant_rule` does not pin). They got no collector and no aggregate, so
74
+ * their on-chain price is whatever a previous transaction left — which is why
75
+ * every caller whose ACTION depends on a ticker must check this rather than
76
+ * assume the refresh covered its whole request.
79
77
  */
80
- export declare function aggregateTickerWithConstant(tx: Transaction, host: OracleHost, args: {
81
- ticker: string;
82
- }): void;
78
+ export interface OracleRefreshSummary {
79
+ /** Tickers aggregated in this PTB — includes constant-pinned ones. */
80
+ refreshed: string[];
81
+ /** Requested tickers no listed source serves. */
82
+ skipped: string[];
83
+ }
83
84
  /**
84
85
  * Refresh multiple tickers in one PTB. For each ticker {@link aggregateTicker}
85
- * feeds whichever rules it is configured for (Pyth if it has a `pyth_rule.feeds`
86
- * entry, Lazer if the lazer update leg served it — see below — Supra when
87
- * enabled, Constant when it's a constant ticker).
86
+ * feeds whichever rules it is configured for (Lazer if the lazer update leg
87
+ * served it, Waterx if the waterx leg fetched signed data for it — see below —
88
+ * Supra when enabled, Constant when it's a constant ticker).
88
89
  *
89
90
  * Before that, the on-chain price *update* leg is routed by the
90
91
  * `host.oracleSources` fed set (see `rule-registry.ts`): EVERY listed source
@@ -98,11 +99,15 @@ export declare function aggregateTickerWithConstant(tx: Transaction, host: Oracl
98
99
  * source's feeds is caught here.
99
100
  *
100
101
  * Each source's fetch + build runs against its own infra, guaranteeing
101
- * per-rule PTB atomicity. A fee-source pre-check runs first (any listed
102
- * source's `requiresFeeSource`) BEFORE any off-chain fetch or PTB mutation
103
- * so a fee-charging source with no `opts.feeSource` throws
104
- * `OracleFeeSourceUnavailable` with zero wasted network calls and zero stray
105
- * moveCalls. Only once that check passes do the off-chain fetches run — in
102
+ * per-rule PTB atomicity. A credential pre-check runs early: any group that
103
+ * still needs to fetch, whose rule declares a `credential` the host does not
104
+ * carry while `host.pyth.api_key` is unset, throws `LazerApiKeyMissing`
105
+ * BEFORE any ORACLE fetch or PTB mutation — zero wasted oracle calls, zero
106
+ * stray moveCalls. (With an `updateDataProvider` configured, its per-source
107
+ * lookups run first so the check can be scoped to the groups the cache did
108
+ * NOT serve; a consumer-implemented provider may do I/O of its own, so the
109
+ * guarantee is about oracle fetches, not about every possible round trip.)
110
+ * Only once that check passes do the off-chain fetches run — in
106
111
  * parallel across sources — and ALL settle before the first PTB mutation;
107
112
  * on-chain reads inside `buildUpdateCalls` can still fail mid-append for
108
113
  * other reasons — callers discard the tx on any throw.
@@ -111,32 +116,14 @@ export declare function aggregateTickerWithConstant(tx: Transaction, host: Oracl
111
116
  * `buildUpdateCalls` returns the verified `Update` PTB value
112
117
  * ({@link RuleUpdateHandle}), and every ticker in that group is aggregated
113
118
  * with `lazerUpdate` set so {@link aggregateTicker} appends
114
- * `pyth_lazer_rule::feed` against it. A lazer-routed ticker that still has a
115
- * `pyth_rule.feeds` entry ALSO keeps its `pyth_rule::feed` leg required
116
- * on-chain while `pyth_rule` stays in the ticker's weighted set
117
- * (`aggregator::remove_outliers` aborts `EMissingPriceSource` unless every
118
- * weighted rule appears in the collector; an abstention counts as
119
- * appearing), and safe: `pyth_rule::feed` only READS the `PriceInfoObject`
120
- * this PTB never refreshed and abstains when it is stale rather than
121
- * aborting. Conversely, a lazer feed call on an aggregator that does not
122
- * (yet) weight `PythLazerRule` is silently dropped on-chain — so
123
- * lazer-routing a ticker ahead of its on-chain weight migration prices it
124
- * from the remaining weighted rules instead of failing.
119
+ * `pyth_lazer_rule::feed` against it. A waterx-served group's signed data is
120
+ * carried straight from its fetched payload to the per-ticker collect call.
121
+ * A feed call on an aggregator that does not (yet) weight that rule is
122
+ * silently dropped on-chain so routing a ticker ahead of its on-chain
123
+ * weight migration prices it from the remaining weighted rules instead of
124
+ * failing.
125
125
  */
126
126
  export declare function refreshOraclePrices(tx: Transaction, host: OracleHost, tickers: string[], opts?: {
127
- cache?: PythCache;
128
- /**
129
- * The single resolved fee source for the Pyth update fee, forwarded
130
- * verbatim to each group's `PriceUpdateRule.buildUpdateCalls` as
131
- * `BuildUpdateOpts.feeSource`. Already-resolved by the caller (see
132
- * {@link OracleFeeSource}'s own doc for where/how) — this function makes
133
- * no sponsor-vs-gas decision itself, it only checks whether a source was
134
- * resolved at all. Ignored by rules with no update fee (e.g.
135
- * `pyth_lazer_rule`). Building with `feeSource` unset throws
136
- * `OracleFeeSourceUnavailable` (see `oracle/pyth.ts`) instead of
137
- * silently drawing from `tx.gas`.
138
- */
139
- feeSource?: OracleFeeSource;
140
127
  /**
141
128
  * @internal Test-only: layer fake `PriceUpdateRule`s on top of the
142
129
  * production registry (see `rule-registry.ts`'s `resolveOracleRule`).
@@ -153,4 +140,4 @@ export declare function refreshOraclePrices(tx: Transaction, host: OracleHost, t
153
140
  * payload) throws instead, since that is a caller bug, not a cache miss.
154
141
  */
155
142
  updateDataProvider?: UpdateDataProvider;
156
- }): Promise<void>;
143
+ }): Promise<OracleRefreshSummary>;