@waterx/sdk 4.0.1 → 4.1.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.
- package/README.md +25 -10
- package/dist/cjs/src/account/account.js +2 -1
- package/dist/cjs/src/account/funding/balance.d.ts +25 -2
- package/dist/cjs/src/account/funding/balance.js +36 -24
- package/dist/cjs/src/account/funding/credit.js +6 -10
- package/dist/cjs/src/constants.d.ts +15 -1
- package/dist/cjs/src/constants.js +18 -4
- package/dist/cjs/src/generated/waterx_rule/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/cjs/src/generated/waterx_rule/deps/bucket_v2_framework/float.js +13 -0
- package/dist/cjs/src/generated/waterx_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/waterx_rule/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/waterx_rule/waterx_rule.d.ts +940 -0
- package/dist/cjs/src/generated/waterx_rule/waterx_rule.js +1092 -0
- package/dist/cjs/src/oracle/aggregate.d.ts +2 -0
- package/dist/cjs/src/oracle/aggregate.js +27 -2
- package/dist/cjs/src/oracle/config.d.ts +75 -0
- package/dist/cjs/src/oracle/config.js +15 -1
- package/dist/cjs/src/oracle/host.d.ts +12 -1
- package/dist/cjs/src/oracle/index.d.ts +2 -0
- package/dist/cjs/src/oracle/index.js +6 -1
- package/dist/cjs/src/oracle/price-update-rule.d.ts +3 -4
- package/dist/cjs/src/oracle/rule-registry.d.ts +8 -7
- package/dist/cjs/src/oracle/rule-registry.js +10 -7
- package/dist/cjs/src/oracle/rules/waterx-rule.d.ts +89 -0
- package/dist/cjs/src/oracle/rules/waterx-rule.js +272 -0
- package/dist/cjs/src/perp/client.d.ts +44 -6
- package/dist/cjs/src/perp/client.js +14 -0
- package/dist/cjs/src/perp/config.d.ts +2 -3
- package/dist/cjs/src/perp/config.js +2 -1
- package/dist/cjs/src/perp/constants.d.ts +0 -6
- package/dist/cjs/src/perp/constants.js +11 -9
- package/dist/cjs/src/perp/fetch/account.js +3 -0
- package/dist/cjs/src/perp/fetch/bridge.js +2 -1
- package/dist/cjs/src/perp/fetch/market.js +2 -1
- package/dist/cjs/src/perp/fetch/positions.d.ts +16 -10
- package/dist/cjs/src/perp/fetch/positions.js +23 -20
- package/dist/cjs/src/perp/index.d.ts +6 -2
- package/dist/cjs/src/perp/index.js +12 -6
- package/dist/cjs/src/perp/liq-view.d.ts +64 -0
- package/dist/cjs/src/perp/liq-view.js +74 -0
- package/dist/cjs/src/perp/user/order.d.ts +13 -0
- package/dist/cjs/src/perp/user/order.js +30 -16
- package/dist/cjs/src/perp/user/staking.js +3 -2
- package/dist/cjs/src/perp/user/trading.js +25 -24
- package/dist/cjs/src/perp/user/wlp.js +6 -5
- package/dist/cjs/src/prediction/utils.d.ts +11 -2
- package/dist/cjs/src/prediction/utils.js +22 -22
- package/dist/cjs/src/unified-client.d.ts +31 -10
- package/dist/cjs/src/unified-client.js +2 -0
- package/dist/cjs/src/utils/format.d.ts +14 -0
- package/dist/cjs/src/utils/format.js +24 -0
- package/dist/cjs/src/utils/math.d.ts +304 -12
- package/dist/cjs/src/utils/math.js +397 -17
- package/dist/cjs/src/utils/validate.d.ts +69 -0
- package/dist/cjs/src/utils/validate.js +183 -0
- package/dist/src/account/account.js +2 -1
- package/dist/src/account/funding/balance.d.ts +25 -2
- package/dist/src/account/funding/balance.js +36 -24
- package/dist/src/account/funding/credit.js +6 -10
- package/dist/src/constants.d.ts +15 -1
- package/dist/src/constants.js +17 -3
- package/dist/src/generated/waterx_rule/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/waterx_rule/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/waterx_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_rule/waterx_rule.d.ts +940 -0
- package/dist/src/generated/waterx_rule/waterx_rule.js +991 -0
- package/dist/src/oracle/aggregate.d.ts +2 -0
- package/dist/src/oracle/aggregate.js +27 -2
- package/dist/src/oracle/config.d.ts +75 -0
- package/dist/src/oracle/config.js +14 -0
- package/dist/src/oracle/host.d.ts +12 -1
- package/dist/src/oracle/index.d.ts +2 -0
- package/dist/src/oracle/index.js +3 -0
- package/dist/src/oracle/price-update-rule.d.ts +3 -4
- package/dist/src/oracle/rule-registry.d.ts +8 -7
- package/dist/src/oracle/rule-registry.js +10 -7
- package/dist/src/oracle/rules/waterx-rule.d.ts +89 -0
- package/dist/src/oracle/rules/waterx-rule.js +266 -0
- package/dist/src/perp/client.d.ts +44 -6
- package/dist/src/perp/client.js +15 -1
- package/dist/src/perp/config.d.ts +2 -3
- package/dist/src/perp/config.js +1 -1
- package/dist/src/perp/constants.d.ts +0 -6
- package/dist/src/perp/constants.js +10 -8
- package/dist/src/perp/fetch/account.js +3 -0
- package/dist/src/perp/fetch/bridge.js +2 -1
- package/dist/src/perp/fetch/market.js +2 -1
- package/dist/src/perp/fetch/positions.d.ts +16 -10
- package/dist/src/perp/fetch/positions.js +28 -20
- package/dist/src/perp/index.d.ts +6 -2
- package/dist/src/perp/index.js +4 -2
- package/dist/src/perp/liq-view.d.ts +64 -0
- package/dist/src/perp/liq-view.js +71 -0
- package/dist/src/perp/user/order.d.ts +13 -0
- package/dist/src/perp/user/order.js +30 -16
- package/dist/src/perp/user/staking.js +3 -2
- package/dist/src/perp/user/trading.js +25 -24
- package/dist/src/perp/user/wlp.js +6 -5
- package/dist/src/prediction/utils.d.ts +11 -2
- package/dist/src/prediction/utils.js +22 -22
- package/dist/src/unified-client.d.ts +31 -10
- package/dist/src/unified-client.js +2 -0
- package/dist/src/utils/format.d.ts +14 -0
- package/dist/src/utils/format.js +21 -0
- package/dist/src/utils/math.d.ts +304 -12
- package/dist/src/utils/math.js +394 -17
- package/dist/src/utils/validate.d.ts +69 -0
- package/dist/src/utils/validate.js +167 -0
- package/package.json +4 -1
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `WaterxRule` — `PriceUpdateRule` for the first-party WaterX quote-center
|
|
4
|
+
* (Nautilus-TEE, ed25519), plus `feedWaterxRule`, the collector-feed leg
|
|
5
|
+
* `aggregateTicker` appends per waterx-routed ticker. Pulls one enclave-signed
|
|
6
|
+
* batch envelope covering every requested ticker from the quote-center
|
|
7
|
+
* (`GET /v1/quotes/update?symbols=…`, endpoint from `host.waterx` — the
|
|
8
|
+
* `waterxEndpoint`/`waterxFetch` create options — else `WATERX_DEFAULTS`), then —
|
|
9
|
+
* unlike Pyth Lazer, whose verify is a single shared PTB step — verifies AND
|
|
10
|
+
* feeds in ONE `waterx_rule::collect_batch_latest` call per collector (the Move
|
|
11
|
+
* API bundles the two). So `buildUpdateCalls` emits nothing and the signed
|
|
12
|
+
* envelope is handed straight to the per-ticker feed leg.
|
|
13
|
+
*
|
|
14
|
+
* `collect_batch_latest` is the dual-rule path: it feeds the item matching
|
|
15
|
+
* `collector.symbol()` WITHOUT aggregating, so a waterx-routed ticker composes
|
|
16
|
+
* onto the same collector as Pyth/Supra (compose-then-aggregate). On-chain a
|
|
17
|
+
* freshness miss / replayed timestamp ABSTAINS (the other weighted rules
|
|
18
|
+
* cover); a config/integrity mismatch or bad signature aborts.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.WaterxRule = void 0;
|
|
22
|
+
exports.parseSignedEnvelope = parseSignedEnvelope;
|
|
23
|
+
exports.waterxEnvelopeOf = waterxEnvelopeOf;
|
|
24
|
+
exports.feedWaterxRule = feedWaterxRule;
|
|
25
|
+
const bcs_1 = require("@mysten/bcs");
|
|
26
|
+
const waterx_rule_ts_1 = require("../../generated/waterx_rule/waterx_rule.js");
|
|
27
|
+
const config_ts_1 = require("../config.js");
|
|
28
|
+
const price_update_rule_ts_1 = require("../price-update-rule.js");
|
|
29
|
+
const update_fetch_ts_1 = require("../update-fetch.js");
|
|
30
|
+
/** The single signing intent (`BATCH_PRICE_INTENT`) the quote-center emits. */
|
|
31
|
+
const BATCH_PRICE_INTENT = 1;
|
|
32
|
+
/**
|
|
33
|
+
* Shape check ONLY — the `kind` discriminant is checked separately by the
|
|
34
|
+
* caller before this runs (mirrors the other rules' guard split), so a
|
|
35
|
+
* same-shaped payload from a different rule can never silently pass.
|
|
36
|
+
*/
|
|
37
|
+
function isWaterxUpdatePayloadShape(payload) {
|
|
38
|
+
const env = payload?.envelope;
|
|
39
|
+
return (typeof env === "object" &&
|
|
40
|
+
env !== null &&
|
|
41
|
+
typeof env.signature === "string" &&
|
|
42
|
+
typeof env.timestamp_ms === "bigint" &&
|
|
43
|
+
Array.isArray(env.payload?.items));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parse a quote-center `/v1/quotes/update` response body into a
|
|
47
|
+
* {@link WaterxSignedEnvelope} with the u64 fields decoded as `bigint`, exact.
|
|
48
|
+
*
|
|
49
|
+
* The signature is over `BCS(IntentMessage<BatchPricePayload>)`, so every u64
|
|
50
|
+
* the SDK rebuilds in-PTB must equal the enclave's byte-for-byte or
|
|
51
|
+
* `collect_batch_latest` aborts the whole trade PTB (bad signature — not an
|
|
52
|
+
* abstain). A plain `JSON.parse` yields IEEE-754 doubles that lose precision
|
|
53
|
+
* above 2^53, so instead we recover each integer's exact source literal via the
|
|
54
|
+
* ES2023 reviver `context.source` (Node 21+ / modern browsers) and `BigInt()`
|
|
55
|
+
* it. On an older runtime that passes no `context`, a value within 2^53 is
|
|
56
|
+
* still exact (`BigInt(number)`); a value ABOVE it throws loudly here rather
|
|
57
|
+
* than silently corrupting the payload into an on-chain abort. `num_sources`
|
|
58
|
+
* (u8) and `intent` are coerced back to `number` — both are tiny.
|
|
59
|
+
*/
|
|
60
|
+
function parseSignedEnvelope(text) {
|
|
61
|
+
const raw = JSON.parse(text, (_key, value, context) => {
|
|
62
|
+
if (typeof value !== "number" || !Number.isInteger(value))
|
|
63
|
+
return value;
|
|
64
|
+
if (context?.source !== undefined)
|
|
65
|
+
return BigInt(context.source);
|
|
66
|
+
if (!Number.isSafeInteger(value)) {
|
|
67
|
+
throw new Error("waterx envelope carries an integer above 2^53 and this runtime lacks JSON " +
|
|
68
|
+
"source access — cannot preserve u64 precision for the signed payload");
|
|
69
|
+
}
|
|
70
|
+
return BigInt(value);
|
|
71
|
+
});
|
|
72
|
+
if (typeof raw.signature !== "string" || !Array.isArray(raw.payload?.items)) {
|
|
73
|
+
throw new Error("WaterX quote-center returned a malformed signed envelope");
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
intent: Number(raw.intent),
|
|
77
|
+
timestamp_ms: (raw.timestamp_ms ?? 0n),
|
|
78
|
+
signature: raw.signature,
|
|
79
|
+
payload: {
|
|
80
|
+
items: raw.payload.items.map((i) => ({ ...i, num_sources: Number(i.num_sources) })),
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** The `waterx_rule` deployment entry; throws when the config carries none. */
|
|
85
|
+
function requireWaterxPackage(host) {
|
|
86
|
+
const entry = host.config.packages.waterx_rule;
|
|
87
|
+
if (!entry) {
|
|
88
|
+
throw new Error("waterx_rule package is not deployed in this config");
|
|
89
|
+
}
|
|
90
|
+
return entry;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Resolve the quote-center infra for this host: the `waterxEndpoint` /
|
|
94
|
+
* `waterxFetch` create options when the client carries them, else the network
|
|
95
|
+
* default. The fetch policy falls back to the shared `pyth.fetch` policy so a
|
|
96
|
+
* consumer that already tuned timeouts/retries once keeps them here.
|
|
97
|
+
*
|
|
98
|
+
* This is the seam a browser consumer needs: the envelope is fetched FROM THE
|
|
99
|
+
* PAGE, so a front end whose origin the quote-center does not allow (CORS)
|
|
100
|
+
* points `endpoint` at a same-origin proxy, or supplies its own `fetchImpl`.
|
|
101
|
+
*/
|
|
102
|
+
function resolveWaterxInfra(host) {
|
|
103
|
+
const infra = host.waterx ?? config_ts_1.WATERX_DEFAULTS[host.network];
|
|
104
|
+
return { endpoint: infra.endpoint, fetch: infra.fetch ?? host.pyth.fetch };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Pull one enclave-signed batch envelope covering `symbols` from the
|
|
108
|
+
* quote-center. Goes through the shared `fetchWithPolicy` (`../update-fetch.ts`)
|
|
109
|
+
* — same retry/timeout policy as the Pyth/Lazer fetches. No auth: the
|
|
110
|
+
* quote-center read surface is public.
|
|
111
|
+
*
|
|
112
|
+
* The URL is built with `joinEndpointPath`, not `new URL(path, endpoint)`: a
|
|
113
|
+
* leading-slash path is ABSOLUTE and silently drops the endpoint's own base
|
|
114
|
+
* path, which is exactly what a `waterxEndpoint` proxy route is (a
|
|
115
|
+
* `https://app.example/api/quote-center` override would have been rewritten to
|
|
116
|
+
* `https://app.example/v1/quotes/update`, bypassing the proxy). Same footgun
|
|
117
|
+
* that 404'd every Pyth Pro feed by dropping its `/hermes` prefix.
|
|
118
|
+
*/
|
|
119
|
+
async function fetchWaterxSignedUpdate(endpoint, symbols, fetchOpts) {
|
|
120
|
+
const url = (0, update_fetch_ts_1.joinEndpointPath)(endpoint, "v1/quotes/update");
|
|
121
|
+
url.searchParams.set("symbols", symbols.join(","));
|
|
122
|
+
let res;
|
|
123
|
+
try {
|
|
124
|
+
res = await (0, update_fetch_ts_1.fetchWithPolicy)(url.toString(), { method: "GET" }, { ...fetchOpts });
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
if (err instanceof update_fetch_ts_1.FetchPolicyError && err.status !== undefined) {
|
|
128
|
+
const body = err.bodySnippet ? ` ${err.bodySnippet}` : "";
|
|
129
|
+
throw new Error(`WaterX quote-center fetch failed: ${err.status}${body} (retries exhausted after ${err.attempts} attempts)`, { cause: err });
|
|
130
|
+
}
|
|
131
|
+
throw err;
|
|
132
|
+
}
|
|
133
|
+
if (!res.ok) {
|
|
134
|
+
throw new Error(`WaterX quote-center fetch failed: ${res.status} ${await res.text()}`);
|
|
135
|
+
}
|
|
136
|
+
// Parse from raw text (not res.json()) so the u64 fields are decoded exact as
|
|
137
|
+
// bigint — see parseSignedEnvelope. Malformed-shape check lives there.
|
|
138
|
+
const envelope = parseSignedEnvelope(await res.text());
|
|
139
|
+
if (envelope.intent !== BATCH_PRICE_INTENT) {
|
|
140
|
+
throw new Error(`WaterX quote-center returned intent ${envelope.intent}, expected BATCH_PRICE_INTENT ${BATCH_PRICE_INTENT}`);
|
|
141
|
+
}
|
|
142
|
+
return envelope;
|
|
143
|
+
}
|
|
144
|
+
/** Narrow a `RuleUpdateData` to its `WaterxSignedEnvelope`, or `null`. */
|
|
145
|
+
function waterxEnvelopeOf(data) {
|
|
146
|
+
const payload = (0, price_update_rule_ts_1.assertRuleUpdateData)(data, "waterx_rule", isWaterxUpdatePayloadShape, "{ envelope: { intent, timestamp_ms, payload: { items }, signature } }");
|
|
147
|
+
return payload?.envelope ?? null;
|
|
148
|
+
}
|
|
149
|
+
/** Strip an optional `0x` prefix, then decode hex → bytes. */
|
|
150
|
+
function decodeSig(hex) {
|
|
151
|
+
return (0, bcs_1.fromHex)(hex.startsWith("0x") ? hex.slice(2) : hex);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* `waterx_rule::collect_batch_latest(collector, config, clock, enclave_config,
|
|
155
|
+
* enclave, timestamp_ms, payload, sig)` — rebuild the enclave-signed batch
|
|
156
|
+
* payload in-PTB (`new_batch_payload` + one `new_batch_item`/`push_batch_item`
|
|
157
|
+
* per item, the exact shape the enclave signed) and contribute the price for
|
|
158
|
+
* `collector.symbol()` to the collector. One collect call re-verifies the batch
|
|
159
|
+
* signature and picks this collector's symbol out of the batch; on-chain it
|
|
160
|
+
* abstains (records `none`) instead of aborting when the symbol is stale,
|
|
161
|
+
* absent from the batch, or its timestamp was already accepted (replay).
|
|
162
|
+
*/
|
|
163
|
+
function feedWaterxRule(tx, host, collector, envelope) {
|
|
164
|
+
const wr = requireWaterxPackage(host);
|
|
165
|
+
const pkg = wr.published_at;
|
|
166
|
+
const payload = (0, waterx_rule_ts_1.newBatchPayload)({ package: pkg })(tx);
|
|
167
|
+
for (const item of envelope.payload.items) {
|
|
168
|
+
// u64 fields are already exact bigints (see parseSignedEnvelope) — passed
|
|
169
|
+
// through verbatim so the rebuilt BCS matches the enclave's signed bytes.
|
|
170
|
+
const itemArg = (0, waterx_rule_ts_1.newBatchItem)({
|
|
171
|
+
package: pkg,
|
|
172
|
+
arguments: {
|
|
173
|
+
symbol: item.symbol,
|
|
174
|
+
ticker: item.ticker,
|
|
175
|
+
sources: item.sources,
|
|
176
|
+
method: item.method,
|
|
177
|
+
priceTimestampMs: item.price_timestamp_ms,
|
|
178
|
+
priceN: item.price_n,
|
|
179
|
+
priceScale: item.price_scale,
|
|
180
|
+
confidenceN: item.confidence_n,
|
|
181
|
+
confidenceScale: item.confidence_scale,
|
|
182
|
+
maxSourceDeviationBps: item.max_source_deviation_bps,
|
|
183
|
+
numSources: item.num_sources,
|
|
184
|
+
},
|
|
185
|
+
})(tx);
|
|
186
|
+
(0, waterx_rule_ts_1.pushBatchItem)({ package: pkg, arguments: { payload, item: itemArg } })(tx);
|
|
187
|
+
}
|
|
188
|
+
(0, waterx_rule_ts_1.collectBatchLatest)({
|
|
189
|
+
package: pkg,
|
|
190
|
+
arguments: {
|
|
191
|
+
collector,
|
|
192
|
+
config: tx.object(wr.config),
|
|
193
|
+
enclaveConfig: tx.object(wr.enclave_config),
|
|
194
|
+
enclave: tx.object(wr.enclave),
|
|
195
|
+
timestampMs: envelope.timestamp_ms,
|
|
196
|
+
payload,
|
|
197
|
+
sig: Array.from(decodeSig(envelope.signature)),
|
|
198
|
+
},
|
|
199
|
+
})(tx);
|
|
200
|
+
}
|
|
201
|
+
exports.WaterxRule = {
|
|
202
|
+
kind: "waterx_rule",
|
|
203
|
+
// Verification is an in-Move ed25519 check with no Coin argument — no
|
|
204
|
+
// update fee — see `PriceUpdateRule.requiresFeeSource`.
|
|
205
|
+
requiresFeeSource: false,
|
|
206
|
+
/** Tickers with a `waterx_rule.feeds` entry (keyed by oracle ticker). */
|
|
207
|
+
supportedTickers(host) {
|
|
208
|
+
return Object.keys(host.config.packages.waterx_rule?.feeds ?? {});
|
|
209
|
+
},
|
|
210
|
+
/**
|
|
211
|
+
* Pulls one enclave-signed batch envelope covering `tickers` from the
|
|
212
|
+
* quote-center, and only returns it when it actually covers ALL of them.
|
|
213
|
+
*
|
|
214
|
+
* A 200 whose `items` omit a requested symbol is a valid, well-signed
|
|
215
|
+
* envelope — nothing downstream would reject it, and the build would emit a
|
|
216
|
+
* `collect_batch_latest` that abstains for the missing symbol, surfacing as
|
|
217
|
+
* an on-chain `EMissingPriceSource` (or a silently thinner weighted set) much
|
|
218
|
+
* later. Same coverage rule the cached path enforces in
|
|
219
|
+
* {@link WaterxRule.narrowUpdateData}; the difference is disposition — a
|
|
220
|
+
* cache miss falls back to this live fetch, whereas the live source itself
|
|
221
|
+
* coming up short has no fallback left, so it throws deterministically here.
|
|
222
|
+
*/
|
|
223
|
+
async fetchUpdateData(host, tickers) {
|
|
224
|
+
if (tickers.length === 0)
|
|
225
|
+
return null;
|
|
226
|
+
// Package-level check first: a config without the deployment must say so,
|
|
227
|
+
// not fail per ticker as if only that feed were missing.
|
|
228
|
+
const { feeds } = requireWaterxPackage(host);
|
|
229
|
+
for (const ticker of tickers) {
|
|
230
|
+
if (feeds[ticker] === undefined) {
|
|
231
|
+
throw new Error(`No waterx_rule feed listed for ticker: ${ticker}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const { endpoint, fetch: fetchOpts } = resolveWaterxInfra(host);
|
|
235
|
+
const envelope = await fetchWaterxSignedUpdate(endpoint, tickers, fetchOpts);
|
|
236
|
+
const covered = new Set(envelope.payload.items.map((i) => i.symbol));
|
|
237
|
+
const missing = tickers.filter((t) => !covered.has(t));
|
|
238
|
+
if (missing.length > 0) {
|
|
239
|
+
throw new Error(`WaterX quote-center envelope does not cover ticker(s): ${missing.join(", ")} ` +
|
|
240
|
+
`(requested ${tickers.join(", ")}; served ${[...covered].join(", ") || "none"})`);
|
|
241
|
+
}
|
|
242
|
+
return { kind: "waterx_rule", payload: { envelope } };
|
|
243
|
+
},
|
|
244
|
+
/**
|
|
245
|
+
* One signed batch envelope carries a single ed25519 signature over its whole
|
|
246
|
+
* `payload` — it is indivisible: it can only be served whole (re-verified from
|
|
247
|
+
* the full item set). Returns the whole payload iff every requested ticker's
|
|
248
|
+
* item is present in THIS envelope; any coverage gap → `null` (miss), never a
|
|
249
|
+
* silent partial.
|
|
250
|
+
*/
|
|
251
|
+
narrowUpdateData(_host, data, tickers) {
|
|
252
|
+
const envelope = waterxEnvelopeOf(data);
|
|
253
|
+
if (!envelope || tickers.length === 0)
|
|
254
|
+
return null;
|
|
255
|
+
const covered = new Set(envelope.payload.items.map((i) => i.symbol));
|
|
256
|
+
for (const ticker of tickers) {
|
|
257
|
+
if (!covered.has(ticker))
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
return { kind: "waterx_rule", payload: { envelope } };
|
|
261
|
+
},
|
|
262
|
+
/**
|
|
263
|
+
* No shared verify step: `waterx_rule::collect_batch_latest` bundles verify
|
|
264
|
+
* AND feed into one per-collector call, appended by {@link feedWaterxRule} in
|
|
265
|
+
* the per-ticker aggregate leg. So this emits nothing and returns `void` — the
|
|
266
|
+
* signed envelope reaches the feed leg via `aggregate.ts`'s per-ticker map
|
|
267
|
+
* (built from the group's fetched data), not a `RuleUpdateHandle`.
|
|
268
|
+
*/
|
|
269
|
+
buildUpdateCalls(_tx, _host, _data, _opts) {
|
|
270
|
+
return;
|
|
271
|
+
},
|
|
272
|
+
};
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { BaseLineClient } from "../base-client.ts";
|
|
14
14
|
import type { OracleSource } from "../oracle/price-update-rule.ts";
|
|
15
|
-
import
|
|
15
|
+
import type { FetchPolicy } from "../oracle/update-fetch.ts";
|
|
16
|
+
import { type LoadConfigOptions, type PythFetchPolicy, type PythInfraConfig, type WaterXConfig, type WaterxInfraConfig, type WormholeInfraConfig } from "./config.ts";
|
|
16
17
|
import type { Network } from "./constants.ts";
|
|
17
18
|
export interface CreateClientOptions extends LoadConfigOptions {
|
|
18
19
|
grpcUrl?: string;
|
|
@@ -25,12 +26,20 @@ export interface CreateClientOptions extends LoadConfigOptions {
|
|
|
25
26
|
* - `'pyth_lazer_rule'` — Pyth Lazer signed updates (ONE `leEcdsa` verify
|
|
26
27
|
* per PTB, no per-feed fees); needs `packages.pyth_lazer_rule` with feeds
|
|
27
28
|
* and a `pythApiKey` (Lazer is auth-first).
|
|
29
|
+
* - `'waterx_rule'` — the first-party WaterX quote-center (Nautilus-TEE,
|
|
30
|
+
* ed25519-signed batches): ONE envelope covering the build's tickers,
|
|
31
|
+
* verified AND fed by a single `collect_batch_latest` per collector. No
|
|
32
|
+
* credential and no per-update fee; needs `packages.waterx_rule` with
|
|
33
|
+
* feeds. Endpoint/transport via {@link CreateClientOptions.waterxEndpoint}
|
|
34
|
+
* / {@link CreateClientOptions.waterxFetch} — the browser-CORS proxy hook,
|
|
35
|
+
* since this is the one source fetched from the page.
|
|
28
36
|
*
|
|
29
|
-
*
|
|
30
|
-
* Selecting a source whose feed for a requested
|
|
31
|
-
* error at client creation: it fails at tx-build
|
|
32
|
-
* tickers (see `refreshOraclePrices`). The Pyth Core
|
|
33
|
-
* network by `PYTH_DEFAULTS` and is not
|
|
37
|
+
* The name is source-neutral on purpose — a source need not be Pyth (as
|
|
38
|
+
* `'waterx_rule'` shows). Selecting a source whose feed for a requested
|
|
39
|
+
* ticker is absent is NOT an error at client creation: it fails at tx-build
|
|
40
|
+
* time for exactly those tickers (see `refreshOraclePrices`). The Pyth Core
|
|
41
|
+
* infra is fixed per network by `PYTH_DEFAULTS` and is not
|
|
42
|
+
* deployment-overridable.
|
|
34
43
|
*/
|
|
35
44
|
oracleSource?: OracleSource;
|
|
36
45
|
/**
|
|
@@ -46,10 +55,39 @@ export interface CreateClientOptions extends LoadConfigOptions {
|
|
|
46
55
|
* `fetchWithPolicy`). Optional — defaults to 15s timeout, 2 retries.
|
|
47
56
|
*/
|
|
48
57
|
pythFetch?: PythFetchPolicy;
|
|
58
|
+
/**
|
|
59
|
+
* Quote-center base URL for `oracleSource: 'waterx_rule'` — overrides the
|
|
60
|
+
* per-network {@link WATERX_DEFAULTS} host.
|
|
61
|
+
*
|
|
62
|
+
* This is the one source a BROWSER fetches itself (the signed envelope is
|
|
63
|
+
* pulled from the page), so it is bound by the quote-center deployment's CORS
|
|
64
|
+
* allowlist. A front end whose origin is not allowed — or one that must route
|
|
65
|
+
* egress through its own backend — points this at a same-origin proxy that
|
|
66
|
+
* forwards `GET /v1/quotes/update`. Unused by the Pyth sources.
|
|
67
|
+
*
|
|
68
|
+
* An absolute URL. Any base PATH is preserved (`joinEndpointPath`), so
|
|
69
|
+
* `https://app.example/api/quote-center` fetches
|
|
70
|
+
* `https://app.example/api/quote-center/v1/quotes/update` — a proxy route
|
|
71
|
+
* survives instead of being rewritten to the origin root.
|
|
72
|
+
*/
|
|
73
|
+
waterxEndpoint?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Retry/timeout policy — and `fetchImpl` — for the quote-center fetch (see
|
|
76
|
+
* `fetchWithPolicy`). Optional: falls back to `pythFetch`, then to the
|
|
77
|
+
* built-in defaults. Supply `fetchImpl` to route the request through your own
|
|
78
|
+
* transport (a proxying `fetch` wrapper, a non-global `fetch`, a test double).
|
|
79
|
+
*/
|
|
80
|
+
waterxFetch?: FetchPolicy;
|
|
49
81
|
}
|
|
50
82
|
export declare class PerpClient extends BaseLineClient<WaterXConfig> {
|
|
51
83
|
/** Pyth Core infra (fixed per network) plus the caller-supplied credential/policy. */
|
|
52
84
|
pyth: PythInfraConfig;
|
|
85
|
+
/**
|
|
86
|
+
* WaterX quote-center infra for `oracleSource: 'waterx_rule'` — the network
|
|
87
|
+
* default, overridden by the `waterxEndpoint` / `waterxFetch` create options
|
|
88
|
+
* (a same-origin proxy or a custom `fetchImpl` for browser consumers).
|
|
89
|
+
*/
|
|
90
|
+
waterx: WaterxInfraConfig;
|
|
53
91
|
/** Wormhole infra for the credit bridge (network defaults unless overridden). */
|
|
54
92
|
wormhole: WormholeInfraConfig;
|
|
55
93
|
/** Selected oracle price-update source (`oracleSource` create option; default `'pyth_rule'`). */
|
|
@@ -19,6 +19,12 @@ const config_ts_1 = require("./config.js");
|
|
|
19
19
|
class PerpClient extends base_client_ts_1.BaseLineClient {
|
|
20
20
|
/** Pyth Core infra (fixed per network) plus the caller-supplied credential/policy. */
|
|
21
21
|
pyth;
|
|
22
|
+
/**
|
|
23
|
+
* WaterX quote-center infra for `oracleSource: 'waterx_rule'` — the network
|
|
24
|
+
* default, overridden by the `waterxEndpoint` / `waterxFetch` create options
|
|
25
|
+
* (a same-origin proxy or a custom `fetchImpl` for browser consumers).
|
|
26
|
+
*/
|
|
27
|
+
waterx;
|
|
22
28
|
/** Wormhole infra for the credit bridge (network defaults unless overridden). */
|
|
23
29
|
wormhole;
|
|
24
30
|
/** Selected oracle price-update source (`oracleSource` create option; default `'pyth_rule'`). */
|
|
@@ -37,6 +43,14 @@ class PerpClient extends base_client_ts_1.BaseLineClient {
|
|
|
37
43
|
...(opts.pythFetch !== undefined ? { fetch: opts.pythFetch } : {}),
|
|
38
44
|
};
|
|
39
45
|
this.wormhole = config.wormhole ?? config_ts_1.WORMHOLE_DEFAULTS[network];
|
|
46
|
+
// Quote-center infra: network default, each field independently overridable
|
|
47
|
+
// — a browser blocked by the quote-center's CORS allowlist swaps `endpoint`
|
|
48
|
+
// for a same-origin proxy without touching anything else.
|
|
49
|
+
this.waterx = {
|
|
50
|
+
...config_ts_1.WATERX_DEFAULTS[network],
|
|
51
|
+
...(opts.waterxEndpoint !== undefined ? { endpoint: opts.waterxEndpoint } : {}),
|
|
52
|
+
...(opts.waterxFetch !== undefined ? { fetch: opts.waterxFetch } : {}),
|
|
53
|
+
};
|
|
40
54
|
this.oracleSource = opts.oracleSource ?? "pyth_rule";
|
|
41
55
|
this.view = new config_view_ts_1.PerpConfigView(() => this.config, () => this.wormhole);
|
|
42
56
|
}
|
|
@@ -12,8 +12,8 @@ import type { AccountPackages, BasePackageEntry, WormholeInfraConfig } from "../
|
|
|
12
12
|
import type { OraclePackages } from "../oracle/config.ts";
|
|
13
13
|
import type { Network } from "./constants.ts";
|
|
14
14
|
export type { AccountConfig, AccountPackages, BasePackageEntry, NativeCustodyAsset, NativeCustodyPackage, WaterxCreditPackage, WaterxReferralPackage, WithdrawalQueuePackage, WormholeBridgePackage, WormholeInfraConfig, WxaAccountPackage, } from "../account/config.ts";
|
|
15
|
-
export type { ConstantFeedEntry, OracleConfig, OraclePackages, PythFetchPolicy, PythInfraConfig, PythLazerRulePackage, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, WaterxConstantRulePackage, WaterxOraclePackage, } from "../oracle/config.ts";
|
|
16
|
-
export { PYTH_DEFAULTS } from "../oracle/config.ts";
|
|
15
|
+
export type { ConstantFeedEntry, OracleConfig, OraclePackages, PythFetchPolicy, PythInfraConfig, PythLazerRulePackage, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, WaterxConstantRulePackage, WaterxInfraConfig, WaterxOraclePackage, WaterxRulePackage, } from "../oracle/config.ts";
|
|
16
|
+
export { PYTH_DEFAULTS, WATERX_DEFAULTS } from "../oracle/config.ts";
|
|
17
17
|
export interface WaterxPerpMarketEntry {
|
|
18
18
|
market: string;
|
|
19
19
|
config: string;
|
|
@@ -71,7 +71,6 @@ export interface WaterXPackages extends AccountPackages, OraclePackages {
|
|
|
71
71
|
mock_usdc?: MockCoinPackage;
|
|
72
72
|
mock_usdsui?: MockCoinPackage;
|
|
73
73
|
mock_sui?: MockCoinPackage;
|
|
74
|
-
waterx_rule?: BasePackageEntry;
|
|
75
74
|
waterx_rule_nautilus_enclave?: BasePackageEntry;
|
|
76
75
|
}
|
|
77
76
|
export declare const WORMHOLE_DEFAULTS: Record<Network, WormholeInfraConfig>;
|
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
* below, keyed by network.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.WORMHOLE_DEFAULTS = exports.PYTH_DEFAULTS = void 0;
|
|
13
|
+
exports.WORMHOLE_DEFAULTS = exports.WATERX_DEFAULTS = exports.PYTH_DEFAULTS = void 0;
|
|
14
14
|
exports.clearConfigCache = clearConfigCache;
|
|
15
15
|
exports.loadConfig = loadConfig;
|
|
16
16
|
const update_fetch_ts_1 = require("../oracle/update-fetch.js");
|
|
17
17
|
var config_ts_1 = require("../oracle/config.js");
|
|
18
18
|
Object.defineProperty(exports, "PYTH_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.PYTH_DEFAULTS; } });
|
|
19
|
+
Object.defineProperty(exports, "WATERX_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.WATERX_DEFAULTS; } });
|
|
19
20
|
// ============================================================================
|
|
20
21
|
// Wormhole / Hermes — external chain infra, defaults by network
|
|
21
22
|
// ============================================================================
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
export * from "../constants.ts";
|
|
2
|
-
/** Default crypto market trading fee rate (3 bps). Per-market value lives in MarketConfig. */
|
|
3
|
-
export declare const CRYPTO_FEE_RATE = 0.0003;
|
|
4
|
-
/** Default stock / commodity market trading fee rate (5 bps). Per-market value lives in MarketConfig. */
|
|
5
|
-
export declare const STOCK_FEE_RATE = 0.0005;
|
|
6
|
-
/** Default maintenance margin rate (150 bps = 1.5%). Per-market value lives in MarketConfig. */
|
|
7
|
-
export declare const MAINTENANCE_MARGIN_RATE = 0.015;
|
|
8
2
|
export declare const PERM_OPEN_POSITION = 1;
|
|
9
3
|
export declare const PERM_CLOSE_POSITION = 2;
|
|
10
4
|
export declare const PERM_INCREASE_POSITION = 4;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Perp-line domain constants (trading permissions / order tags / action codes /
|
|
3
|
-
//
|
|
3
|
+
// well-known addresses). Re-exports the shared primitives from
|
|
4
4
|
// `../constants.ts` so perp code and the `./perp` barrel get the full set from
|
|
5
5
|
// a single import.
|
|
6
|
+
//
|
|
7
|
+
// NOTE: there are deliberately NO fee-rate / maintenance-margin constants here.
|
|
8
|
+
// `CRYPTO_FEE_RATE` / `STOCK_FEE_RATE` / `MAINTENANCE_MARGIN_RATE` were removed
|
|
9
|
+
// — they were defaults masquerading as truth; per-market `MarketConfig` on
|
|
10
|
+
// chain is the only source for fee and margin parameters (real MMRs span
|
|
11
|
+
// 0.5%–5%; the flat 1.5% understated AAPLX-class risk >3x — mainnet incident
|
|
12
|
+
// 2026-07-28: shorts displayed liq ~$364 but were liquidated at ~$343). When
|
|
13
|
+
// the market rate is unavailable, treat the value as NOT estimable and fail
|
|
14
|
+
// safe — never substitute a flat default.
|
|
6
15
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
16
|
if (k2 === undefined) k2 = k;
|
|
8
17
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -18,15 +27,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
27
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
28
|
};
|
|
20
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.ACCUMULATOR_ROOT = exports.ACTION_ADD_PRE_ORDER = exports.ACTION_CANCEL_PRE_ORDER = exports.ACTION_UPDATE_ORDER = exports.ACTION_DECREASE_POSITION = exports.ACTION_INCREASE_POSITION = exports.ACTION_LIQUIDATE = exports.ACTION_WITHDRAW_COLLATERAL = exports.ACTION_DEPOSIT_COLLATERAL = exports.ACTION_CANCEL_ORDER = exports.ACTION_PLACE_ORDER = exports.ACTION_CLOSE_POSITION = exports.ACTION_OPEN_POSITION = exports.ORDER_TAG_WILDCARD = exports.ORDER_STOP_SELL = exports.ORDER_STOP_BUY = exports.ORDER_LIMIT_SELL = exports.ORDER_LIMIT_BUY = exports.STAKING_PERM_ALL = exports.STAKING_PERM_CLAIM_REWARD = exports.STAKING_PERM_REDEEM_STAKE = exports.STAKING_PERM_DEPOSIT_STAKE = exports.PERM_ALL = exports.PERM_ALL_TRADING = exports.PERM_REDEEM_WLP = exports.PERM_MINT_WLP = exports.PERM_WITHDRAW_COLLATERAL = exports.PERM_DEPOSIT_COLLATERAL = exports.PERM_CANCEL_ORDER = exports.PERM_PLACE_ORDER = exports.PERM_DECREASE_POSITION = exports.PERM_INCREASE_POSITION = exports.PERM_CLOSE_POSITION = exports.PERM_OPEN_POSITION =
|
|
30
|
+
exports.ACCUMULATOR_ROOT = exports.ACTION_ADD_PRE_ORDER = exports.ACTION_CANCEL_PRE_ORDER = exports.ACTION_UPDATE_ORDER = exports.ACTION_DECREASE_POSITION = exports.ACTION_INCREASE_POSITION = exports.ACTION_LIQUIDATE = exports.ACTION_WITHDRAW_COLLATERAL = exports.ACTION_DEPOSIT_COLLATERAL = exports.ACTION_CANCEL_ORDER = exports.ACTION_PLACE_ORDER = exports.ACTION_CLOSE_POSITION = exports.ACTION_OPEN_POSITION = exports.ORDER_TAG_WILDCARD = exports.ORDER_STOP_SELL = exports.ORDER_STOP_BUY = exports.ORDER_LIMIT_SELL = exports.ORDER_LIMIT_BUY = exports.STAKING_PERM_ALL = exports.STAKING_PERM_CLAIM_REWARD = exports.STAKING_PERM_REDEEM_STAKE = exports.STAKING_PERM_DEPOSIT_STAKE = exports.PERM_ALL = exports.PERM_ALL_TRADING = exports.PERM_REDEEM_WLP = exports.PERM_MINT_WLP = exports.PERM_WITHDRAW_COLLATERAL = exports.PERM_DEPOSIT_COLLATERAL = exports.PERM_CANCEL_ORDER = exports.PERM_PLACE_ORDER = exports.PERM_DECREASE_POSITION = exports.PERM_INCREASE_POSITION = exports.PERM_CLOSE_POSITION = exports.PERM_OPEN_POSITION = void 0;
|
|
22
31
|
__exportStar(require("../constants.js"), exports);
|
|
23
|
-
// ======== Fee rates & risk parameters ========
|
|
24
|
-
/** Default crypto market trading fee rate (3 bps). Per-market value lives in MarketConfig. */
|
|
25
|
-
exports.CRYPTO_FEE_RATE = 0.0003;
|
|
26
|
-
/** Default stock / commodity market trading fee rate (5 bps). Per-market value lives in MarketConfig. */
|
|
27
|
-
exports.STOCK_FEE_RATE = 0.0005;
|
|
28
|
-
/** Default maintenance margin rate (150 bps = 1.5%). Per-market value lives in MarketConfig. */
|
|
29
|
-
exports.MAINTENANCE_MARGIN_RATE = 0.015;
|
|
30
32
|
// ======== Permission Bitmasks (matches account_data.move) ========
|
|
31
33
|
exports.PERM_OPEN_POSITION = 1;
|
|
32
34
|
exports.PERM_CLOSE_POSITION = 2;
|
|
@@ -56,6 +56,9 @@ async function getSpendableCreditBalance(client, accountId) {
|
|
|
56
56
|
(0, balance_ts_1.probeParkedBackingAssets)(client, accountId),
|
|
57
57
|
(0, balance_ts_1.probeAddressCreditBalance)(client, accountId),
|
|
58
58
|
]);
|
|
59
|
+
// COLLATERAL_DECIMALS here is the CREDIT/wxUSD *target* scale (collateral-typed;
|
|
60
|
+
// 6 on all current deployments — config carries no credit decimal). The
|
|
61
|
+
// per-asset backing decimals come from config via each row's `decimals`.
|
|
59
62
|
const pendingBackingRaw = (0, balance_ts_1.sumParkedBackingAsCreditRaw)(parkedBacking, constants_ts_1.COLLATERAL_DECIMALS);
|
|
60
63
|
const pendingCreditAtAddressRaw = addressCredit.fundsRaw + addressCredit.coinsRaw;
|
|
61
64
|
const totalRaw = internalRaw + pendingBackingRaw + pendingCreditAtAddressRaw;
|
|
@@ -10,6 +10,7 @@ const bcs_1 = require("@mysten/sui/bcs");
|
|
|
10
10
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
11
11
|
const withdrawal_queue_ts_1 = require("../../generated/withdrawal_queue/withdrawal_queue.js");
|
|
12
12
|
const wormhole_bridge_ts_1 = require("../../generated/wormhole_bridge/wormhole_bridge.js");
|
|
13
|
+
const validate_ts_1 = require("../../utils/validate.js");
|
|
13
14
|
const simulate_ts_1 = require("./simulate.js");
|
|
14
15
|
/**
|
|
15
16
|
* Batched read of the bridge's rate-limit / cap state in a single simulate.
|
|
@@ -100,7 +101,7 @@ function requireWithdrawalQueue(client) {
|
|
|
100
101
|
*/
|
|
101
102
|
async function getBridgeFee(client, args) {
|
|
102
103
|
const { pkg, queue } = requireWithdrawalQueue(client);
|
|
103
|
-
const amount =
|
|
104
|
+
const amount = (0, validate_ts_1.toU64)(args.amount, "amount");
|
|
104
105
|
const common = {
|
|
105
106
|
package: pkg,
|
|
106
107
|
typeArguments: [args.creditType ?? client.creditType()],
|
|
@@ -12,6 +12,7 @@ exports.getGlobalConfigData = getGlobalConfigData;
|
|
|
12
12
|
const bcs_1 = require("@mysten/sui/bcs");
|
|
13
13
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
14
14
|
const view_ts_1 = require("../../generated/waterx_perp_view/view.js");
|
|
15
|
+
const validate_ts_1 = require("../../utils/validate.js");
|
|
15
16
|
const simulate_ts_1 = require("./simulate.js");
|
|
16
17
|
/**
|
|
17
18
|
* Look up the registered AccountData for a given wxa account ID.
|
|
@@ -59,7 +60,7 @@ async function getTokenPoolData(client, args) {
|
|
|
59
60
|
package: client.config.packages.waterx_perp_view.published_at,
|
|
60
61
|
arguments: {
|
|
61
62
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
62
|
-
tokenIndex: args.tokenIndex,
|
|
63
|
+
tokenIndex: (0, validate_ts_1.toU64)(args.tokenIndex, "tokenIndex"),
|
|
63
64
|
},
|
|
64
65
|
typeArguments: [(0, simulate_ts_1.withLp)(client, args.lpType)],
|
|
65
66
|
})(tx);
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* list (`waterx_perp_view`).
|
|
4
4
|
*/
|
|
5
5
|
import { OrderData, PositionData, RedeemRequestData } from "../../generated/waterx_perp_view/view.ts";
|
|
6
|
+
import { parseWholeDollarU64, type WholeDollarUsdPrice } from "../../utils/validate.ts";
|
|
6
7
|
import type { PerpClient } from "../client.ts";
|
|
8
|
+
export { parseWholeDollarU64, type WholeDollarUsdPrice };
|
|
7
9
|
export type PositionDataView = ReturnType<typeof PositionData.parse>;
|
|
8
10
|
export declare function positionExists(client: PerpClient, args: {
|
|
9
11
|
ticker: string;
|
|
@@ -13,9 +15,8 @@ export declare function positionExists(client: PerpClient, args: {
|
|
|
13
15
|
export declare function getPosition(client: PerpClient, args: {
|
|
14
16
|
ticker: string;
|
|
15
17
|
positionId: bigint | number;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
collateralPriceUsd: bigint | number;
|
|
18
|
+
basePriceUsd: WholeDollarUsdPrice;
|
|
19
|
+
collateralPriceUsd: WholeDollarUsdPrice;
|
|
19
20
|
lpType?: string;
|
|
20
21
|
}): Promise<PositionDataView>;
|
|
21
22
|
export type OrderDataView = ReturnType<typeof OrderData.parse>;
|
|
@@ -23,8 +24,9 @@ export declare function getOrder(client: PerpClient, args: {
|
|
|
23
24
|
ticker: string;
|
|
24
25
|
orderId: bigint | number;
|
|
25
26
|
orderTypeTag: number;
|
|
27
|
+
/** Raw 1e9-scaled u128 order-book key — same scale as tx-build `rawPrice()`. */
|
|
26
28
|
triggerPrice: bigint | number;
|
|
27
|
-
basePriceUsd:
|
|
29
|
+
basePriceUsd: WholeDollarUsdPrice;
|
|
28
30
|
lpType?: string;
|
|
29
31
|
}): Promise<OrderDataView>;
|
|
30
32
|
export interface PageOpts {
|
|
@@ -33,7 +35,8 @@ export interface PageOpts {
|
|
|
33
35
|
}
|
|
34
36
|
export declare function getMarketOrders(client: PerpClient, args: {
|
|
35
37
|
ticker: string;
|
|
36
|
-
|
|
38
|
+
/** Defaults to `0n`. */
|
|
39
|
+
basePriceUsd?: WholeDollarUsdPrice;
|
|
37
40
|
lpType?: string;
|
|
38
41
|
} & PageOpts): Promise<{
|
|
39
42
|
orders: OrderDataView[];
|
|
@@ -41,8 +44,9 @@ export declare function getMarketOrders(client: PerpClient, args: {
|
|
|
41
44
|
}>;
|
|
42
45
|
export declare function getMarketPositions(client: PerpClient, args: {
|
|
43
46
|
ticker: string;
|
|
44
|
-
basePriceUsd:
|
|
45
|
-
|
|
47
|
+
basePriceUsd: WholeDollarUsdPrice;
|
|
48
|
+
/** Defaults to `0n`. */
|
|
49
|
+
collateralPriceUsd?: WholeDollarUsdPrice;
|
|
46
50
|
lpType?: string;
|
|
47
51
|
} & PageOpts): Promise<{
|
|
48
52
|
positions: PositionDataView[];
|
|
@@ -51,14 +55,16 @@ export declare function getMarketPositions(client: PerpClient, args: {
|
|
|
51
55
|
export declare function getAccountPositions(client: PerpClient, args: {
|
|
52
56
|
ticker: string;
|
|
53
57
|
accountObjectAddress: string;
|
|
54
|
-
basePriceUsd:
|
|
55
|
-
|
|
58
|
+
basePriceUsd: WholeDollarUsdPrice;
|
|
59
|
+
/** Defaults to `0n`. */
|
|
60
|
+
collateralPriceUsd?: WholeDollarUsdPrice;
|
|
56
61
|
lpType?: string;
|
|
57
62
|
}): Promise<PositionDataView[]>;
|
|
58
63
|
export declare function getAccountOrders(client: PerpClient, args: {
|
|
59
64
|
ticker: string;
|
|
60
65
|
accountObjectAddress: string;
|
|
61
|
-
|
|
66
|
+
/** Defaults to `0n`. */
|
|
67
|
+
basePriceUsd?: WholeDollarUsdPrice;
|
|
62
68
|
lpType?: string;
|
|
63
69
|
}): Promise<OrderDataView[]>;
|
|
64
70
|
export type RedeemRequestDataView = ReturnType<typeof RedeemRequestData.parse>;
|