@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
@@ -1,43 +1,71 @@
1
1
  /**
2
2
  * `WaterxRule` — `PriceUpdateRule` for the first-party WaterX quote-center
3
- * (Nautilus-TEE, ed25519), plus `feedWaterxRule`, the collector-feed leg
4
- * `aggregateTicker` appends per waterx-routed ticker. Pulls one enclave-signed
5
- * batch envelope covering every requested ticker from the quote-center
6
- * (`GET /v1/quotes/update?symbols=…`, endpoint from `host.waterx` the
7
- * `waterxEndpoint`/`waterxFetch` create options else its own `WATERX_INFRA`), then —
8
- * unlike Pyth Lazer, whose verify is a single shared PTB step — verifies AND
9
- * feeds in ONE `waterx_rule::collect_batch_latest` call per collector (the Move
10
- * API bundles the two). So `buildUpdateCalls` emits nothing and the signed
11
- * envelope is handed straight to the per-ticker feed leg.
12
- *
13
- * `collect_batch_latest` is the dual-rule path: it feeds the item matching
14
- * `collector.symbol()` WITHOUT aggregating, so a waterx-routed ticker composes
15
- * onto the same collector as Pyth/Supra (compose-then-aggregate). On-chain a
16
- * FRESHNESS miss ABSTAINS (the other weighted rules cover); a config/
17
- * integrity mismatch, bad signature, future timestamp or a REPLAYED signed
18
- * timestamp — ABORTS (`EReplayedSignature`, audit F-014: a signed tuple is
19
- * single-use per symbol, enforced by a per-symbol high-water mark BEFORE any
20
- * weight arbitration). Consequence for concurrent builds: two PTBs carrying
21
- * the same envelope for the same symbol cannot both land — the second aborts
22
- * even if the rule is unweighted for that ticker. Never share one fetched
23
- * envelope across builds that may execute concurrently for the same symbol.
3
+ * (Nautilus-TEE, ed25519), plus the collector-feed legs `aggregateTicker`
4
+ * appends per waterx-routed ticker. Endpoint comes from `host.waterx` (the
5
+ * `waterxEndpoint`/`waterxFetch` create options), else this source's own
6
+ * `WATERX_INFRA`. Unlike Pyth Lazer, whose verify is a single shared PTB step,
7
+ * the Move API bundles verify AND feed into ONE call per collector, so
8
+ * `buildUpdateCalls` emits nothing and the signed data is handed straight to
9
+ * the per-ticker feed leg.
10
+ *
11
+ * TWO wire shapes carry the same prices, and this rule prefers the first:
12
+ *
13
+ * 1. **Merkle leaves** (default) `GET /v1/quotes/leaves?symbols=…` returns one
14
+ * `SignedLeaf` per symbol: the price fields, a Merkle `proof`, and the
15
+ * enclave's signature over the snapshot ROOT (`MERKLE_ROOT_INTENT`). Fed via
16
+ * {@link feedWaterxRuleWithProof} `waterx_rule::collect_single_with_proof`,
17
+ * which re-derives the root from the leaf + proof. One symbol costs ONE
18
+ * `new_batch_item` plus ~log2(n) 32-byte proof hashes.
19
+ * 2. **Batch envelope** (fallback) `GET /v1/quotes/update?symbols=…` returns
20
+ * ONE signature over the whole item vector (`BATCH_PRICE_INTENT`). It is
21
+ * indivisible: {@link feedWaterxRule} must rebuild EVERY item in-PTB for
22
+ * `waterx_rule::collect_batch_latest` to re-verify, even to use one symbol's
23
+ * price. With the 29-feed mainnet registry that is 58 extra moveCalls and
24
+ * ~320 extra pure inputs on every trade, which is why it is no longer the
25
+ * default. Used only when the quote-center has no leaf route yet (404),
26
+ * and by callers that still push whole batches.
27
+ *
28
+ * Both collect entries are the dual-rule path: they feed `collector.symbol()`
29
+ * WITHOUT aggregating, so a waterx-routed ticker composes onto the same
30
+ * collector as Pyth/Supra (compose-then-aggregate). Their abort-vs-abstain
31
+ * disposition is identical: a config/integrity mismatch, a bad signature or a
32
+ * signed timestamp AHEAD of the on-chain `Clock` ABORTS; a freshness miss
33
+ * ABSTAINS so the other weighted rules cover a lagging TEE, and so does a
34
+ * REPLAYED signed timestamp (the per-symbol high-water mark of audit F-014 —
35
+ * already-recorded means the chain holds a price at least this fresh, so two
36
+ * PTBs carrying the same snapshot for the same symbol no longer kill each
37
+ * other; only the single-rule `feed_*` entries abort on a replay).
24
38
  */
25
39
  import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
26
40
  import type { Network } from "../../constants.ts";
27
41
  import type { OracleHost } from "../host.ts";
28
42
  import { type PriceUpdateRule, type RuleUpdateData } from "../price-update-rule.ts";
29
- /** The single signing intent the quote-center emits — exported so read-plane
30
- * consumers can mirror the rule's own envelope intent check (a mispointed
31
- * endpoint must be rejected by reads exactly as tx-builds reject it). */
43
+ import type { OraclePriceEntry } from "../read-prices.ts";
44
+ import { type FetchPolicy } from "../update-fetch.ts";
45
+ /** Intent the quote-center signs a whole BATCH payload under. Exported to NAME
46
+ * the signing scheme only — consumers no longer mirror the intent gate
47
+ * themselves: every quote-center pull (tx-build fetch, read executor, BE
48
+ * prefetch) goes through {@link fetchWaterxSignedUpdate} /
49
+ * {@link fetchWaterxSignedLeaves}, which enforce it, so a mispointed endpoint
50
+ * is rejected identically on every path. */
32
51
  export declare const BATCH_PRICE_INTENT = 1;
52
+ /**
53
+ * Intent the quote-center signs a snapshot's Merkle ROOT under
54
+ * (`waterx_rule::MERKLE_ROOT_INTENT`). Distinct from
55
+ * {@link BATCH_PRICE_INTENT} on purpose: the intent byte is the first field of
56
+ * the signed `IntentMessage`, so a batch signature can never be replayed as a
57
+ * root signature or vice versa. Leaves carry no `intent` field of their own —
58
+ * they are only ever submitted through `collect_single_with_proof`, which pins
59
+ * the intent on-chain — so this exists to name the scheme, not to gate a parse.
60
+ */
61
+ export declare const MERKLE_ROOT_INTENT = 2;
33
62
  /**
34
63
  * WaterX quote-center external infra — owned by THIS source, by network.
35
- * Mirrors `PYTH_CORE_INFRA` (oracle/pyth.ts) and `LAZER_INFRA`
36
- * (rules/pyth-lazer-rule.ts): per-network constants for infrastructure the
37
- * source's operator runs, co-located with the only rule that reads them — no
38
- * other oracle source ever touches a quote-center endpoint. Public read (no
39
- * auth), so there is no api_key. `endpoint` has no trailing slash — the rule
40
- * appends the path.
64
+ * Mirrors `LAZER_INFRA` (rules/pyth-lazer-rule.ts): per-network constants for
65
+ * infrastructure the source's operator runs, co-located with the only rule
66
+ * that reads them no other oracle source ever touches a quote-center
67
+ * endpoint. Public read (no auth), so there is no api_key. `endpoint` has no
68
+ * trailing slash — the rule appends the path.
41
69
  *
42
70
  * These are the DEFAULTS behind the caller's `client.waterx` access slice
43
71
  * (`waterxEndpoint` / `waterxFetch` create options) — the browser-CORS proxy
@@ -49,11 +77,32 @@ export declare const WATERX_INFRA: Record<Network, {
49
77
  /**
50
78
  * The waterx source's quote-center base for `network` — the ONE accessor
51
79
  * consumers (BE/FE read planes) use when, and only when, their own
52
- * `ORACLE_SOURCE` resolves to `'waterx_rule'`. Mirrors
53
- * `pythCoreHermesEndpoint`. Under any other source the read endpoint is that
54
- * source's own configuration — never this one.
80
+ * the config wires `waterx_rule`. Under any other source the
81
+ * read endpoint is that source's own configuration never this one.
55
82
  */
56
83
  export declare function waterxQuoteCenterEndpoint(network: Network): string;
84
+ /**
85
+ * Off-chain mirror of the on-chain `waterx_rule` `FeedConfig.max_age` DEFAULT
86
+ * (90s): a price older than this ABSTAINS on-chain, so a read plane serving it
87
+ * as live would show a price no trade could execute against. The single
88
+ * source of truth for consumers' post-cache freshness filters — import this,
89
+ * never re-declare the number. (A deployment that overrides `max_age`
90
+ * per-feed on-chain diverges from this mirror; none does today.)
91
+ */
92
+ export declare const WATERX_MAX_PRICE_AGE_MS = 90000;
93
+ /**
94
+ * `true` iff a quote-center read entry is still within
95
+ * {@link WATERX_MAX_PRICE_AGE_MS} of `nowMs` — the freshness predicate
96
+ * consumers apply to `readQuoteCenterPrices` output (post-cache), matching
97
+ * the on-chain abstain boundary instead of each inventing a policy.
98
+ */
99
+ export declare function isFreshWaterxEntry(entry: OraclePriceEntry, nowMs: number): boolean;
100
+ /**
101
+ * How far ahead of the reader's clock a quote-center timestamp may sit before
102
+ * it is treated as broken rather than merely skewed. Two independent clocks
103
+ * drift; a price minutes in the future does not.
104
+ */
105
+ export declare const WATERX_CLOCK_SKEW_TOLERANCE_MS = 5000;
57
106
  /**
58
107
  * One item inside a signed batch payload, mirroring the quote-center
59
108
  * `/v1/quotes/update` JSON 1:1 (snake_case). The u64 integer fields are the
@@ -88,39 +137,204 @@ export interface WaterxSignedEnvelope {
88
137
  /** ed25519 signature over `BCS(IntentMessage<BatchPricePayload>)`, hex (± `0x`). */
89
138
  signature: string;
90
139
  }
91
- /** `waterx_rule`'s narrowed `RuleUpdateData.payload` shape. */
92
- export interface WaterxUpdatePayload {
140
+ /**
141
+ * One enclave-signed Merkle leaf from `GET /v1/quotes/leaves` — identical shape
142
+ * to the `/v1/quote/stream/signed` SSE/WS events (quote-center serves both from
143
+ * one conversion), so a leaf from either transport submits the same way.
144
+ *
145
+ * It is the batch item's fields PLUS its membership proof: on-chain,
146
+ * `collect_single_with_proof` recomputes `keccak256(0x00 || BCS(item))`, folds
147
+ * it through `proof` (sorted pairs, no direction flags), and verifies the
148
+ * enclave's signature over THAT root — so every item field must round-trip
149
+ * byte-for-byte, exactly as for the batch path.
150
+ */
151
+ export interface WaterxSignedLeaf extends WaterxBatchItem {
152
+ /**
153
+ * Enclave signing timestamp of the SNAPSHOT ROOT (ms) — the on-chain
154
+ * `timestamp_ms` argument. Shared by every leaf of one snapshot, and distinct
155
+ * from `price_timestamp_ms` (when the price itself was observed).
156
+ */
157
+ signed_timestamp_ms: bigint;
158
+ /** keccak256 Merkle root (hex). Diagnostic only — the chain re-derives it. */
159
+ root: string;
160
+ /** Sibling hashes (hex, 32 bytes each) folding this leaf to `root`. Empty for a one-leaf snapshot. */
161
+ proof: string[];
162
+ /** ed25519 signature over `BCS(IntentMessage<MerkleRoot>)`, hex (± `0x`). */
163
+ signature: string;
164
+ }
165
+ /** Leaf variant of `waterx_rule`'s `RuleUpdateData.payload` — the default path. */
166
+ export interface WaterxLeafPayload {
167
+ readonly leaves: readonly WaterxSignedLeaf[];
168
+ }
169
+ /** Batch-envelope variant of `waterx_rule`'s `RuleUpdateData.payload` — the fallback path. */
170
+ export interface WaterxEnvelopePayload {
93
171
  readonly envelope: WaterxSignedEnvelope;
94
172
  }
173
+ /**
174
+ * `waterx_rule`'s narrowed `RuleUpdateData.payload` shape: a per-symbol leaf set
175
+ * OR one indivisible batch envelope. The variant a payload carries decides which
176
+ * on-chain entry the feed leg emits, so consumers must route on it via
177
+ * {@link waterxLeavesOf} / {@link waterxEnvelopeOf} rather than assuming either.
178
+ */
179
+ export type WaterxUpdatePayload = WaterxLeafPayload | WaterxEnvelopePayload;
95
180
  /**
96
181
  * Parse a quote-center `/v1/quotes/update` response body into a
97
- * {@link WaterxSignedEnvelope} with the u64 fields decoded as `bigint`, exact.
98
- *
99
- * The signature is over `BCS(IntentMessage<BatchPricePayload>)`, so every u64
100
- * the SDK rebuilds in-PTB must equal the enclave's byte-for-byte or
101
- * `collect_batch_latest` aborts the whole trade PTB (bad signature — not an
102
- * abstain). A plain `JSON.parse` yields IEEE-754 doubles that lose precision
103
- * above 2^53, so instead we recover each integer's exact source literal via the
104
- * ES2023 reviver `context.source` (Node 21+ / modern browsers) and `BigInt()`
105
- * it. On an older runtime that passes no `context`, a value within 2^53 is
106
- * still exact (`BigInt(number)`); a value ABOVE it throws loudly here rather
107
- * than silently corrupting the payload into an on-chain abort. `num_sources`
108
- * (u8) and `intent` are coerced back to `number` — both are tiny.
182
+ * {@link WaterxSignedEnvelope} with the u64 fields decoded as `bigint`, exact
183
+ * (see {@link parseWithExactIntegers}). `num_sources` (u8) and `intent` are
184
+ * coerced back to `number` both are tiny.
109
185
  */
110
186
  export declare function parseSignedEnvelope(text: string): WaterxSignedEnvelope;
111
- /** Narrow a `RuleUpdateData` to its `WaterxSignedEnvelope`, or `null`. */
187
+ /**
188
+ * Parse a quote-center `/v1/quotes/leaves` response body (`{ leaves: [...] }`)
189
+ * into {@link WaterxSignedLeaf}s, u64s exact as `bigint`, rejecting a malformed
190
+ * leaf or proof element on the wire — before any PTB is touched.
191
+ */
192
+ export declare function parseSignedLeaves(text: string): WaterxSignedLeaf[];
193
+ /**
194
+ * Pull one enclave-signed batch envelope covering `symbols` — the fallback
195
+ * update shape AND the read executor's transport
196
+ * (`readQuoteCenterPrices` in `../read-prices.ts`). Public seam (WL-2345):
197
+ * consumers that need the raw envelope (BE prefetch caches, read planes)
198
+ * call this instead of re-rolling the fetch + intent/shape gate.
199
+ * `fellBackFrom`, when set, names the leaf-route failure that sent us here,
200
+ * so a deployment whose quote-center serves NEITHER route reports both
201
+ * statuses instead of only the second one.
202
+ */
203
+ export declare function fetchWaterxSignedUpdate(endpoint: string, symbols: string[], fetchOpts?: FetchPolicy, fellBackFrom?: string): Promise<WaterxSignedEnvelope>;
204
+ /** A leaf pull either produced leaves, or the route isn't there to pull from. */
205
+ export type LeafPull = {
206
+ leaves: WaterxSignedLeaf[];
207
+ } | {
208
+ unavailable: string;
209
+ };
210
+ /**
211
+ * Pull per-symbol signed Merkle leaves — the DEFAULT update-data shape (see the
212
+ * module header for why it beats the indivisible batch envelope on a trade path).
213
+ *
214
+ * Returns `{ unavailable }` on `404` — and ONLY on 404, the one status that
215
+ * means "this route isn't here": a quote-center older than `/v1/quotes/leaves`
216
+ * has no handler registered for the path. That is the version-skew case the
217
+ * caller answers by falling back to the batch envelope, so the SDK and the
218
+ * quote-center can be deployed in either order.
219
+ *
220
+ * Everything else THROWS rather than falling back, INCLUDING 5xx (`501` among
221
+ * them — `fetchWithPolicy` classifies every 5xx as retryable and has already
222
+ * spent its retry budget by the time one surfaces here). A degraded or
223
+ * unreachable quote-center would fail the envelope route the same way — same
224
+ * service, same enclave behind it — so falling back would only double the
225
+ * latency of an already-failing money-path build, and would report an outage as
226
+ * a version skew.
227
+ *
228
+ * A 404 can ALSO mean "unknown symbol" (the quote-center 404s a symbol missing
229
+ * from its feed registry). That is config drift between this SDK's `feeds` and
230
+ * the quote-center's registry, and the fallback surfaces it honestly: the
231
+ * envelope route 404s on the same symbol, and its error names both attempts.
232
+ *
233
+ * Public seam (WL-2345): consumers holding per-symbol leaves (BE prefetch
234
+ * caches) pull through this instead of re-rolling the fetch + parse gate.
235
+ */
236
+ export declare function fetchWaterxSignedLeaves(endpoint: string, symbols: string[], fetchOpts?: FetchPolicy): Promise<LeafPull>;
237
+ /**
238
+ * The quote-center enclave signs at most this many symbols per request
239
+ * (`MAX_BATCH_SIZE` in `quote-service`). Over the cap it answers a
240
+ * non-retryable 400.
241
+ */
242
+ export declare const WATERX_MAX_BATCH_SYMBOLS = 32;
243
+ /**
244
+ * Narrow a `RuleUpdateData` to its per-symbol {@link WaterxSignedLeaf}s, or
245
+ * `null` when it carries a batch envelope instead (the fallback shape).
246
+ */
247
+ export declare function waterxLeavesOf(data: RuleUpdateData): readonly WaterxSignedLeaf[] | null;
248
+ /**
249
+ * Narrow a `RuleUpdateData` to its `WaterxSignedEnvelope`, or `null` when it
250
+ * carries per-symbol leaves instead (the default shape).
251
+ */
112
252
  export declare function waterxEnvelopeOf(data: RuleUpdateData): WaterxSignedEnvelope | null;
253
+ /**
254
+ * `waterx_rule::collect_single_with_proof(collector, config, clock,
255
+ * enclave_config, enclave, timestamp_ms, item, proof, sig)` — the DEFAULT feed
256
+ * leg. Rebuilds ONE item in-PTB and hands it over with its Merkle proof; on-chain
257
+ * the leaf is hashed, folded through the proof, and the enclave's signature over
258
+ * the resulting root is verified before the price reaches the collector.
259
+ *
260
+ * Cost is what makes this the default: one item + `proof.length` 32-byte hashes
261
+ * (~log2 of the snapshot width — 4 to 5 for the 29-feed mainnet registry),
262
+ * against {@link feedWaterxRule}'s obligation to rebuild every item the batch
263
+ * signature covers.
264
+ *
265
+ * Abort vs abstain is identical to the batch path (see the module header): a
266
+ * mismatched root, a bad signature, a future signed timestamp, or a config
267
+ * mismatch ABORTS; a freshness miss or a replayed signed timestamp abstains. One
268
+ * extra abort of its own — `ECollectorSymbolMismatch` if the leaf's symbol isn't
269
+ * the collector's — which `aggregateTicker` prevents by construction, since it
270
+ * looks the leaf up BY the ticker it just built the collector for.
271
+ */
272
+ export declare function feedWaterxRuleWithProof(tx: Transaction, host: OracleHost, collector: TransactionArgument, leaf: WaterxSignedLeaf): void;
113
273
  /**
114
274
  * `waterx_rule::collect_batch_latest(collector, config, clock, enclave_config,
115
- * enclave, timestamp_ms, payload, sig)` — rebuild the enclave-signed batch
116
- * payload in-PTB (`new_batch_payload` + one `new_batch_item`/`push_batch_item`
117
- * per item, the exact shape the enclave signed) and contribute the price for
118
- * `collector.symbol()` to the collector. One collect call re-verifies the batch
119
- * signature and picks this collector's symbol out of the batch; on-chain it
120
- * abstains (records `none`) when the symbol is stale or absent from the batch,
121
- * but ABORTS `EReplayedSignature` when the symbol's signed timestamp was
122
- * already accepted (per-symbol high-water mark, audit F-014) see the module
123
- * header for the concurrent-build consequence.
275
+ * enclave, timestamp_ms, payload, sig)` — the FALLBACK feed leg, for a
276
+ * quote-center with no leaf route (and for callers that hold a whole batch).
277
+ * Rebuilds the enclave-signed batch payload in-PTB (`new_batch_payload` + one
278
+ * `new_batch_item`/`push_batch_item` per item, the exact shape the enclave
279
+ * signed) and contributes the price for `collector.symbol()` to the collector.
280
+ *
281
+ * Every item must be rebuilt, not just this collector's: the signature covers
282
+ * `BCS(IntentMessage)` over the whole vector, so a missing item is a failed
283
+ * verify. That is the cost {@link feedWaterxRuleWithProof} exists to avoid.
284
+ *
285
+ * On-chain it abstains (records `none`) when the symbol is stale, absent from the
286
+ * batch, or already recorded at this signed timestamp; it ABORTS on a bad
287
+ * signature, a signed timestamp ahead of the `Clock`, or a config mismatch.
124
288
  */
125
289
  export declare function feedWaterxRule(tx: Transaction, host: OracleHost, collector: TransactionArgument, envelope: WaterxSignedEnvelope): void;
290
+ /**
291
+ * THE quote-center route ladder, owned by the rule that owns the protocol:
292
+ * pull per-symbol Merkle leaves (the default), and fall back to one batch
293
+ * envelope only when this quote-center has no leaf route (see
294
+ * {@link fetchWaterxSignedLeaves} for exactly which statuses mean that, and
295
+ * why nothing else falls back).
296
+ *
297
+ * Both the write path ({@link pullWaterxData}, which layers coverage policy on
298
+ * top) and the READ executor (`readQuoteCenterPrices` in `../read-prices.ts`,
299
+ * which only decodes prices) go through here, so which route wins, which
300
+ * status falls back, and how the fallback context is threaded are stated once.
301
+ * `items` is the flat symbol-bearing view both callers actually want —
302
+ * `WaterxSignedLeaf extends WaterxBatchItem`, so leaves widen to it for free —
303
+ * while `payload` keeps the shape-specific form the on-chain feed leg needs.
304
+ */
305
+ export declare function pullWaterxQuotes(endpoint: string, symbols: string[], fetchOpts?: FetchPolicy): Promise<{
306
+ route: "leaves" | "envelope";
307
+ payload: WaterxUpdatePayload;
308
+ items: readonly WaterxBatchItem[];
309
+ }>;
126
310
  export declare const WaterxRule: PriceUpdateRule;
311
+ /**
312
+ * Coverage-policy seam over the rule's quote-center pull (WL-2345): fetch
313
+ * signed waterx update data for `tickers` with the caller choosing what a
314
+ * coverage gap means.
315
+ *
316
+ * - `coverage: "strict"` (default) — exactly `WaterxRule.fetchUpdateData`:
317
+ * every requested ticker must be config-listed AND served, or the fetch
318
+ * THROWS (`assertCoverage`); `missing` is always `[]`. Trade-path semantics
319
+ * — `refreshOraclePrices` keeps consuming the rule's own strict fetch, so
320
+ * `aggregate.ts`'s uncarried-ticker throw (04117a1) still can't be reached
321
+ * by a payload that under-covers its group.
322
+ * - `coverage: "partial"` — universe-prefetch semantics (a BE cache warming
323
+ * every known ticker at once): a ticker with no `waterx_rule.feeds` entry,
324
+ * or one the quote-center response does not serve, lands in `missing`
325
+ * instead of throwing, and `data` covers the rest. On the leaf route the
326
+ * payload is the covering leaf SUBSET; on the envelope route the envelope
327
+ * is kept iff it covers ≥1 requested ticker (it is indivisible — an
328
+ * envelope serving none is `data: null`). `data: null` + all-missing when
329
+ * nothing is servable.
330
+ *
331
+ * Consumers must not hand a partial payload to a build for tickers in
332
+ * `missing` — those tickers are simply not servable by waterx right now (log
333
+ * the gap; the chain's weight tables decide whether that starves anything).
334
+ */
335
+ export declare function fetchWaterxUpdateData(host: OracleHost, tickers: string[], opts?: {
336
+ coverage?: "strict" | "partial";
337
+ }): Promise<{
338
+ data: RuleUpdateData;
339
+ missing: string[];
340
+ }>;