@waterx/sdk 3.1.1 → 4.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.
- package/README.md +36 -0
- package/dist/cjs/src/oracle/aggregate.d.ts +98 -17
- package/dist/cjs/src/oracle/aggregate.js +191 -21
- package/dist/cjs/src/oracle/config.d.ts +103 -0
- package/dist/cjs/src/oracle/config.js +64 -1
- package/dist/cjs/src/oracle/host.d.ts +13 -0
- package/dist/cjs/src/oracle/index.d.ts +19 -5
- package/dist/cjs/src/oracle/index.js +40 -6
- package/dist/cjs/src/oracle/price-update-rule.d.ts +180 -0
- package/dist/cjs/src/oracle/price-update-rule.js +56 -0
- package/dist/cjs/src/oracle/pyth.d.ts +80 -11
- package/dist/cjs/src/oracle/pyth.js +84 -17
- package/dist/cjs/src/oracle/rule-registry.d.ts +37 -0
- package/dist/cjs/src/oracle/rule-registry.js +61 -0
- package/dist/cjs/src/oracle/rules/pyth-core-rule.d.ts +15 -0
- package/dist/cjs/src/oracle/rules/pyth-core-rule.js +84 -0
- package/dist/cjs/src/oracle/rules/pyth-lazer-rule.d.ts +41 -0
- package/dist/cjs/src/oracle/rules/pyth-lazer-rule.js +194 -0
- package/dist/cjs/src/oracle/rules/sponsor.d.ts +11 -7
- package/dist/cjs/src/oracle/rules/sponsor.js +11 -7
- package/dist/cjs/src/oracle/update-fetch.d.ts +85 -0
- package/dist/cjs/src/oracle/update-fetch.js +228 -0
- package/dist/cjs/src/perp/client.d.ts +22 -1
- package/dist/cjs/src/perp/client.js +11 -2
- package/dist/cjs/src/perp/config.d.ts +9 -4
- package/dist/cjs/src/perp/config.js +82 -18
- package/dist/cjs/src/perp/index.d.ts +4 -3
- package/dist/cjs/src/perp/index.js +8 -3
- package/dist/cjs/src/perp/tx-builders/common.d.ts +52 -15
- package/dist/cjs/src/perp/tx-builders/common.js +39 -6
- package/dist/cjs/src/perp/tx-builders/wlp.d.ts +11 -3
- package/dist/cjs/src/perp/tx-builders/wlp.js +29 -3
- package/dist/cjs/src/perp/tx-builders.d.ts +3 -3
- package/dist/cjs/src/perp/tx-builders.js +3 -3
- package/dist/cjs/src/unified-client.d.ts +17 -0
- package/dist/cjs/src/unified-client.js +2 -0
- package/dist/src/oracle/aggregate.d.ts +98 -17
- package/dist/src/oracle/aggregate.js +192 -22
- package/dist/src/oracle/config.d.ts +103 -0
- package/dist/src/oracle/config.js +63 -0
- package/dist/src/oracle/host.d.ts +13 -0
- package/dist/src/oracle/index.d.ts +19 -5
- package/dist/src/oracle/index.js +34 -6
- package/dist/src/oracle/price-update-rule.d.ts +180 -0
- package/dist/src/oracle/price-update-rule.js +53 -0
- package/dist/src/oracle/pyth.d.ts +80 -11
- package/dist/src/oracle/pyth.js +82 -16
- package/dist/src/oracle/rule-registry.d.ts +37 -0
- package/dist/src/oracle/rule-registry.js +56 -0
- package/dist/src/oracle/rules/pyth-core-rule.d.ts +15 -0
- package/dist/src/oracle/rules/pyth-core-rule.js +81 -0
- package/dist/src/oracle/rules/pyth-lazer-rule.d.ts +41 -0
- package/dist/src/oracle/rules/pyth-lazer-rule.js +189 -0
- package/dist/src/oracle/rules/sponsor.d.ts +11 -7
- package/dist/src/oracle/rules/sponsor.js +11 -7
- package/dist/src/oracle/update-fetch.d.ts +85 -0
- package/dist/src/oracle/update-fetch.js +223 -0
- package/dist/src/perp/client.d.ts +22 -1
- package/dist/src/perp/client.js +12 -3
- package/dist/src/perp/config.d.ts +9 -4
- package/dist/src/perp/config.js +81 -18
- package/dist/src/perp/index.d.ts +4 -3
- package/dist/src/perp/index.js +2 -2
- package/dist/src/perp/tx-builders/common.d.ts +52 -15
- package/dist/src/perp/tx-builders/common.js +39 -6
- package/dist/src/perp/tx-builders/wlp.d.ts +11 -3
- package/dist/src/perp/tx-builders/wlp.js +29 -3
- package/dist/src/perp/tx-builders.d.ts +3 -3
- package/dist/src/perp/tx-builders.js +3 -3
- package/dist/src/unified-client.d.ts +17 -0
- package/dist/src/unified-client.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fetchWithPolicy` — resilience wrapper around `fetch` for the oracle money
|
|
3
|
+
* path's off-chain update-data fetches. Every order/position/collateral
|
|
4
|
+
* tx-build depends on one of these REST calls landing (Hermes VAA for
|
|
5
|
+
* `pyth_rule`, Lazer signed updates for `pyth_lazer_rule`); a bare `fetch`
|
|
6
|
+
* with a single attempt and no retry means one Hermes 429/5xx or timeout
|
|
7
|
+
* fails every trade. `fetchPriceFeedsUpdateData` (`./pyth.ts`),
|
|
8
|
+
* `PythLazerRule.fetchUpdateData`'s Lazer POST (`./rules/pyth-lazer-rule.ts`),
|
|
9
|
+
* and `loadConfig` (`../perp/config.ts`) all delegate here instead of calling
|
|
10
|
+
* `fetch` directly — this is the ONE place a retry/timeout/auth policy is
|
|
11
|
+
* implemented for these fetches.
|
|
12
|
+
*
|
|
13
|
+
* Policy semantics:
|
|
14
|
+
* - Bearer auth is attached iff `policy.apiKey` is a non-empty string —
|
|
15
|
+
* absent/empty is byte-identical to today's keyless request (no
|
|
16
|
+
* `Authorization` header at all). This is the Phase-0 invariant of the
|
|
17
|
+
* Pyth Pro migration: existing keyless deployments see no behavior change.
|
|
18
|
+
* - Retries on network errors, HTTP 429, and HTTP 5xx, with exponential
|
|
19
|
+
* backoff (`retryDelayMs * 2^attempt`, capped at `MAX_BACKOFF_MS`). Other
|
|
20
|
+
* 4xx statuses (401/400/403/404/…) are NOT retried — auth/bad-request
|
|
21
|
+
* failures are deterministic, so that `Response` (`ok: false`) is handed
|
|
22
|
+
* back on the first attempt for the caller to format its own
|
|
23
|
+
* domain-specific error, exactly as it did before this wrapper existed.
|
|
24
|
+
* - `init.body`, if set, MUST be replayable across attempts — a retry
|
|
25
|
+
* re-sends the SAME `init` object to `fetch` on every attempt. A string /
|
|
26
|
+
* `URLSearchParams` / BCS-serialized `Uint8Array` body (every caller today)
|
|
27
|
+
* is fine; a one-shot `ReadableStream` body would not survive a second
|
|
28
|
+
* attempt and must not be passed through this function.
|
|
29
|
+
* - Each attempt gets its own `AbortSignal.timeout(policy.timeoutMs)`
|
|
30
|
+
* combined with whichever of `init.signal` / the `externalSignal` param are
|
|
31
|
+
* set — ALL of them can end the whole policy (not just the in-flight
|
|
32
|
+
* attempt), including a queued backoff sleep, via `AbortSignal.any`
|
|
33
|
+
* (runtime floor: Node ≥20.3 / any modern browser — matches this repo's
|
|
34
|
+
* `target: ES2023` + `lib: ["dom", "esnext"]`).
|
|
35
|
+
* - Exhausting retries with no successful/non-retryable response (i.e. every
|
|
36
|
+
* attempt was a network error, or the final attempt was still a retryable
|
|
37
|
+
* HTTP failure) throws a {@link FetchPolicyError} naming the target's
|
|
38
|
+
* `host + pathname` (never the query string — feed ids are off-chain
|
|
39
|
+
* noise, not diagnostic value), the attempt count, and whichever of
|
|
40
|
+
* `status` (a retryable HTTP failure — plus a truncated response-body
|
|
41
|
+
* snippet, when the final attempt's response carried one) or `cause` (a
|
|
42
|
+
* network error) the final attempt produced. An INTERMEDIATE (non-final)
|
|
43
|
+
* retryable response's body is discarded via `response.body?.cancel()`
|
|
44
|
+
* instead of read, so a doomed-to-retry response doesn't pin its
|
|
45
|
+
* connection's socket open for no reason.
|
|
46
|
+
* - Retry worst case: with the defaults (15s timeout × 3 attempts + ~0.75s of
|
|
47
|
+
* backoff between them) a FULL outage takes up to ~46s to surface as a
|
|
48
|
+
* `FetchPolicyError`, vs ~15s pre-3.2.0's single bare-`fetch` attempt.
|
|
49
|
+
* Tunable per client via `config.pyth.fetch.{timeoutMs,retries}`.
|
|
50
|
+
*/
|
|
51
|
+
export interface FetchPolicy {
|
|
52
|
+
/** Per-attempt timeout (ms). Default 15_000. */
|
|
53
|
+
readonly timeoutMs?: number;
|
|
54
|
+
/** Retry attempts AFTER the first try — `retries: 2` ⇒ 3 attempts total. Default 2. */
|
|
55
|
+
readonly retries?: number;
|
|
56
|
+
/** Base backoff (ms); doubled per attempt, capped at 2_000ms. Default 250. */
|
|
57
|
+
readonly retryDelayMs?: number;
|
|
58
|
+
/** Bearer token. Attached iff non-empty; empty/missing ⇒ no `Authorization` header. */
|
|
59
|
+
readonly apiKey?: string;
|
|
60
|
+
/** Override the fetch implementation (tests / non-global-`fetch` environments). Default: global `fetch`. */
|
|
61
|
+
readonly fetchImpl?: typeof fetch;
|
|
62
|
+
}
|
|
63
|
+
/** Thrown by {@link fetchWithPolicy} when every attempt failed. */
|
|
64
|
+
export declare class FetchPolicyError extends Error {
|
|
65
|
+
/** HTTP status of the final attempt, when it got a (retryable-but-failing) response. */
|
|
66
|
+
readonly status?: number;
|
|
67
|
+
/** Truncated (~200 char) body of the final attempt's response, when one was readable. */
|
|
68
|
+
readonly bodySnippet?: string;
|
|
69
|
+
/** Total attempts made (first try + retries actually used). */
|
|
70
|
+
readonly attempts: number;
|
|
71
|
+
constructor(message: string, opts: {
|
|
72
|
+
status?: number;
|
|
73
|
+
bodySnippet?: string;
|
|
74
|
+
cause?: unknown;
|
|
75
|
+
attempts: number;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* `fetch` with per-attempt timeout, bounded retry + backoff, and optional
|
|
80
|
+
* Bearer auth. See the module header for the full policy. Both `init.signal`
|
|
81
|
+
* (if the caller set one) AND the separate `externalSignal` param cancel the
|
|
82
|
+
* WHOLE policy — in-flight attempts AND queued backoff sleeps — not just a
|
|
83
|
+
* single attempt.
|
|
84
|
+
*/
|
|
85
|
+
export declare function fetchWithPolicy(url: string, init?: RequestInit, policy?: FetchPolicy, externalSignal?: AbortSignal): Promise<Response>;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `fetchWithPolicy` — resilience wrapper around `fetch` for the oracle money
|
|
4
|
+
* path's off-chain update-data fetches. Every order/position/collateral
|
|
5
|
+
* tx-build depends on one of these REST calls landing (Hermes VAA for
|
|
6
|
+
* `pyth_rule`, Lazer signed updates for `pyth_lazer_rule`); a bare `fetch`
|
|
7
|
+
* with a single attempt and no retry means one Hermes 429/5xx or timeout
|
|
8
|
+
* fails every trade. `fetchPriceFeedsUpdateData` (`./pyth.ts`),
|
|
9
|
+
* `PythLazerRule.fetchUpdateData`'s Lazer POST (`./rules/pyth-lazer-rule.ts`),
|
|
10
|
+
* and `loadConfig` (`../perp/config.ts`) all delegate here instead of calling
|
|
11
|
+
* `fetch` directly — this is the ONE place a retry/timeout/auth policy is
|
|
12
|
+
* implemented for these fetches.
|
|
13
|
+
*
|
|
14
|
+
* Policy semantics:
|
|
15
|
+
* - Bearer auth is attached iff `policy.apiKey` is a non-empty string —
|
|
16
|
+
* absent/empty is byte-identical to today's keyless request (no
|
|
17
|
+
* `Authorization` header at all). This is the Phase-0 invariant of the
|
|
18
|
+
* Pyth Pro migration: existing keyless deployments see no behavior change.
|
|
19
|
+
* - Retries on network errors, HTTP 429, and HTTP 5xx, with exponential
|
|
20
|
+
* backoff (`retryDelayMs * 2^attempt`, capped at `MAX_BACKOFF_MS`). Other
|
|
21
|
+
* 4xx statuses (401/400/403/404/…) are NOT retried — auth/bad-request
|
|
22
|
+
* failures are deterministic, so that `Response` (`ok: false`) is handed
|
|
23
|
+
* back on the first attempt for the caller to format its own
|
|
24
|
+
* domain-specific error, exactly as it did before this wrapper existed.
|
|
25
|
+
* - `init.body`, if set, MUST be replayable across attempts — a retry
|
|
26
|
+
* re-sends the SAME `init` object to `fetch` on every attempt. A string /
|
|
27
|
+
* `URLSearchParams` / BCS-serialized `Uint8Array` body (every caller today)
|
|
28
|
+
* is fine; a one-shot `ReadableStream` body would not survive a second
|
|
29
|
+
* attempt and must not be passed through this function.
|
|
30
|
+
* - Each attempt gets its own `AbortSignal.timeout(policy.timeoutMs)`
|
|
31
|
+
* combined with whichever of `init.signal` / the `externalSignal` param are
|
|
32
|
+
* set — ALL of them can end the whole policy (not just the in-flight
|
|
33
|
+
* attempt), including a queued backoff sleep, via `AbortSignal.any`
|
|
34
|
+
* (runtime floor: Node ≥20.3 / any modern browser — matches this repo's
|
|
35
|
+
* `target: ES2023` + `lib: ["dom", "esnext"]`).
|
|
36
|
+
* - Exhausting retries with no successful/non-retryable response (i.e. every
|
|
37
|
+
* attempt was a network error, or the final attempt was still a retryable
|
|
38
|
+
* HTTP failure) throws a {@link FetchPolicyError} naming the target's
|
|
39
|
+
* `host + pathname` (never the query string — feed ids are off-chain
|
|
40
|
+
* noise, not diagnostic value), the attempt count, and whichever of
|
|
41
|
+
* `status` (a retryable HTTP failure — plus a truncated response-body
|
|
42
|
+
* snippet, when the final attempt's response carried one) or `cause` (a
|
|
43
|
+
* network error) the final attempt produced. An INTERMEDIATE (non-final)
|
|
44
|
+
* retryable response's body is discarded via `response.body?.cancel()`
|
|
45
|
+
* instead of read, so a doomed-to-retry response doesn't pin its
|
|
46
|
+
* connection's socket open for no reason.
|
|
47
|
+
* - Retry worst case: with the defaults (15s timeout × 3 attempts + ~0.75s of
|
|
48
|
+
* backoff between them) a FULL outage takes up to ~46s to surface as a
|
|
49
|
+
* `FetchPolicyError`, vs ~15s pre-3.2.0's single bare-`fetch` attempt.
|
|
50
|
+
* Tunable per client via `config.pyth.fetch.{timeoutMs,retries}`.
|
|
51
|
+
*/
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.FetchPolicyError = void 0;
|
|
54
|
+
exports.fetchWithPolicy = fetchWithPolicy;
|
|
55
|
+
const DEFAULT_TIMEOUT_MS = 15_000;
|
|
56
|
+
const DEFAULT_RETRIES = 2;
|
|
57
|
+
const DEFAULT_RETRY_DELAY_MS = 250;
|
|
58
|
+
const MAX_BACKOFF_MS = 2_000;
|
|
59
|
+
/** Final-error diagnostic only — not a protocol limit. */
|
|
60
|
+
const MAX_BODY_SNIPPET_LENGTH = 200;
|
|
61
|
+
/** Thrown by {@link fetchWithPolicy} when every attempt failed. */
|
|
62
|
+
class FetchPolicyError extends Error {
|
|
63
|
+
/** HTTP status of the final attempt, when it got a (retryable-but-failing) response. */
|
|
64
|
+
status;
|
|
65
|
+
/** Truncated (~200 char) body of the final attempt's response, when one was readable. */
|
|
66
|
+
bodySnippet;
|
|
67
|
+
/** Total attempts made (first try + retries actually used). */
|
|
68
|
+
attempts;
|
|
69
|
+
constructor(message, opts) {
|
|
70
|
+
super(message, opts.cause !== undefined ? { cause: opts.cause } : undefined);
|
|
71
|
+
this.name = "FetchPolicyError";
|
|
72
|
+
this.status = opts.status;
|
|
73
|
+
this.bodySnippet = opts.bodySnippet;
|
|
74
|
+
this.attempts = opts.attempts;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.FetchPolicyError = FetchPolicyError;
|
|
78
|
+
function isRetryableStatus(status) {
|
|
79
|
+
return status === 429 || status >= 500;
|
|
80
|
+
}
|
|
81
|
+
function backoffMs(retryDelayMs, attempt) {
|
|
82
|
+
return Math.min(retryDelayMs * 2 ** attempt, MAX_BACKOFF_MS);
|
|
83
|
+
}
|
|
84
|
+
/** `host + pathname` only — never the query string (feed ids are noise, not diagnostic). */
|
|
85
|
+
function describeTarget(url) {
|
|
86
|
+
const parsed = new URL(url);
|
|
87
|
+
return `${parsed.host}${parsed.pathname}`;
|
|
88
|
+
}
|
|
89
|
+
function causeMessage(cause) {
|
|
90
|
+
return cause instanceof Error ? cause.message : String(cause);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Best-effort, truncated body text for the FINAL failed attempt's error
|
|
94
|
+
* message — restores the diagnostic a plain `if (!res.ok) throw new
|
|
95
|
+
* Error(...res.status, await res.text())` had before this wrapper existed.
|
|
96
|
+
* Swallows any read failure (missing/consumed body, a test double with no
|
|
97
|
+
* `.text()`, …) — a diagnostic snippet is never worth failing the request
|
|
98
|
+
* differently than the status/cause already dictate.
|
|
99
|
+
*/
|
|
100
|
+
async function readBodySnippet(response) {
|
|
101
|
+
try {
|
|
102
|
+
const text = await response.text();
|
|
103
|
+
return text.length > MAX_BODY_SNIPPET_LENGTH
|
|
104
|
+
? `${text.slice(0, MAX_BODY_SNIPPET_LENGTH)}…`
|
|
105
|
+
: text;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return "";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Resolves after `ms`, or rejects immediately (with `signal.reason`) if `signal` fires first. */
|
|
112
|
+
function sleep(ms, signal) {
|
|
113
|
+
if (!signal)
|
|
114
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
115
|
+
const abortSignal = signal;
|
|
116
|
+
if (abortSignal.aborted)
|
|
117
|
+
return Promise.reject(abortSignal.reason);
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
const onAbort = () => {
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
reject(abortSignal.reason);
|
|
122
|
+
};
|
|
123
|
+
const timer = setTimeout(() => {
|
|
124
|
+
abortSignal.removeEventListener("abort", onAbort);
|
|
125
|
+
resolve();
|
|
126
|
+
}, ms);
|
|
127
|
+
abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/** `undefined` if none are set; the lone signal if exactly one is; `AbortSignal.any(...)` otherwise. */
|
|
131
|
+
function combineSignals(signals) {
|
|
132
|
+
const present = signals.filter((s) => s != null);
|
|
133
|
+
if (present.length === 0)
|
|
134
|
+
return undefined;
|
|
135
|
+
if (present.length === 1)
|
|
136
|
+
return present[0];
|
|
137
|
+
return AbortSignal.any(present);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Merge `Authorization: Bearer <apiKey>` into `base` iff `apiKey` is
|
|
141
|
+
* non-empty; `base` is returned UNTOUCHED otherwise (byte-identical to
|
|
142
|
+
* today's keyless requests — no header, whatever shape the caller passed).
|
|
143
|
+
* Always builds a plain object (never a `Headers` instance) so callers that
|
|
144
|
+
* assert on the exact `init` they handed `fetch` keep working unchanged.
|
|
145
|
+
*/
|
|
146
|
+
function withBearerAuth(base, apiKey) {
|
|
147
|
+
if (!apiKey)
|
|
148
|
+
return base;
|
|
149
|
+
const merged = {};
|
|
150
|
+
if (base instanceof Headers) {
|
|
151
|
+
base.forEach((value, key) => {
|
|
152
|
+
merged[key] = value;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
else if (Array.isArray(base)) {
|
|
156
|
+
for (const [key, value] of base)
|
|
157
|
+
merged[key] = value;
|
|
158
|
+
}
|
|
159
|
+
else if (base) {
|
|
160
|
+
Object.assign(merged, base);
|
|
161
|
+
}
|
|
162
|
+
merged.Authorization = `Bearer ${apiKey}`;
|
|
163
|
+
return merged;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* `fetch` with per-attempt timeout, bounded retry + backoff, and optional
|
|
167
|
+
* Bearer auth. See the module header for the full policy. Both `init.signal`
|
|
168
|
+
* (if the caller set one) AND the separate `externalSignal` param cancel the
|
|
169
|
+
* WHOLE policy — in-flight attempts AND queued backoff sleeps — not just a
|
|
170
|
+
* single attempt.
|
|
171
|
+
*/
|
|
172
|
+
async function fetchWithPolicy(url, init = {}, policy = {}, externalSignal) {
|
|
173
|
+
const timeoutMs = policy.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
174
|
+
const retries = policy.retries ?? DEFAULT_RETRIES;
|
|
175
|
+
const retryDelayMs = policy.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
|
|
176
|
+
const doFetch = policy.fetchImpl ?? fetch;
|
|
177
|
+
const headers = withBearerAuth(init.headers, policy.apiKey);
|
|
178
|
+
// init.signal is folded in here (not spread through per-attempt below) so
|
|
179
|
+
// it gates retries/backoff exactly like externalSignal, instead of being
|
|
180
|
+
// silently dropped by the `{ ...init, signal }` override per attempt.
|
|
181
|
+
const combinedExternalSignal = combineSignals([externalSignal, init.signal]);
|
|
182
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
183
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
184
|
+
const signal = combinedExternalSignal
|
|
185
|
+
? AbortSignal.any([timeoutSignal, combinedExternalSignal])
|
|
186
|
+
: timeoutSignal;
|
|
187
|
+
let status;
|
|
188
|
+
let bodySnippet;
|
|
189
|
+
let cause;
|
|
190
|
+
try {
|
|
191
|
+
const response = await doFetch(url, { ...init, headers, signal });
|
|
192
|
+
if (response.ok || !isRetryableStatus(response.status))
|
|
193
|
+
return response;
|
|
194
|
+
status = response.status;
|
|
195
|
+
if (attempt === retries) {
|
|
196
|
+
bodySnippet = await readBodySnippet(response);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// Doomed to be retried — discard rather than read, so this
|
|
200
|
+
// response's connection/socket isn't held open for a body nobody
|
|
201
|
+
// will consume. `.catch()` is mandatory here: an errored stream's
|
|
202
|
+
// `cancel()` returns a REJECTED promise, and a bare `void` on that
|
|
203
|
+
// is an unhandled rejection — process-fatal in Node — triggered by
|
|
204
|
+
// exactly the degraded-upstream condition this wrapper exists to
|
|
205
|
+
// survive.
|
|
206
|
+
void response.body?.cancel().catch(() => { });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
if (combinedExternalSignal?.aborted)
|
|
211
|
+
throw err;
|
|
212
|
+
cause = err;
|
|
213
|
+
}
|
|
214
|
+
if (attempt === retries) {
|
|
215
|
+
const statusDetail = status !== undefined
|
|
216
|
+
? `last status ${status}${bodySnippet ? ` — ${bodySnippet}` : ""}`
|
|
217
|
+
: undefined;
|
|
218
|
+
const detail = statusDetail ?? causeMessage(cause);
|
|
219
|
+
throw new FetchPolicyError(`fetchWithPolicy: ${describeTarget(url)} failed after ${attempt + 1} attempt(s) — ${detail}`, { status, bodySnippet, cause, attempts: attempt + 1 });
|
|
220
|
+
}
|
|
221
|
+
await sleep(backoffMs(retryDelayMs, attempt), combinedExternalSignal);
|
|
222
|
+
}
|
|
223
|
+
// Unreachable: the loop above always returns or throws on its final
|
|
224
|
+
// (attempt === retries) iteration — this satisfies the compiler only.
|
|
225
|
+
throw new FetchPolicyError(`fetchWithPolicy: ${describeTarget(url)} exhausted retries`, {
|
|
226
|
+
attempts: retries + 1,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
@@ -11,20 +11,41 @@
|
|
|
11
11
|
* {@link PerpConfigView}. This class is just the wiring + factory between them.
|
|
12
12
|
*/
|
|
13
13
|
import { BaseLineClient } from "../base-client.ts";
|
|
14
|
-
import
|
|
14
|
+
import type { OracleSource } from "../oracle/price-update-rule.ts";
|
|
15
|
+
import { type LoadConfigOptions, type PythGeneration, type PythInfraConfig, type WaterXConfig, type WormholeInfraConfig } from "./config.ts";
|
|
15
16
|
import type { Network } from "./constants.ts";
|
|
16
17
|
export interface CreateClientOptions extends LoadConfigOptions {
|
|
17
18
|
grpcUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Selects which `PriceUpdateRule` `refreshOraclePrices` uses for the
|
|
21
|
+
* on-chain price-update leg (see `OracleHost.oracleSource`). Default:
|
|
22
|
+
* `'pyth_rule'`. The SDK never reads `process.env` — pass this from your
|
|
23
|
+
* own env var (e.g. `ORACLE_SOURCE`).
|
|
24
|
+
*/
|
|
25
|
+
oracleSource?: OracleSource;
|
|
26
|
+
/**
|
|
27
|
+
* Selects which Pyth Core contract generation feeds `client.pyth` when the
|
|
28
|
+
* config JSON has no explicit `pyth` override: `'core'` (default,
|
|
29
|
+
* `PYTH_DEFAULTS`) or `'pro'` (`PYTH_PRO_DEFAULTS` — the post-2026-08-18
|
|
30
|
+
* Pro-compatible contracts + Hermes-compatible endpoint; pair with
|
|
31
|
+
* `pyth.api_key`). Orthogonal to `oracleSource`. An explicit `config.pyth`
|
|
32
|
+
* always wins wholesale (see `PythGeneration`).
|
|
33
|
+
*/
|
|
34
|
+
pythGeneration?: PythGeneration;
|
|
18
35
|
}
|
|
19
36
|
export declare class PerpClient extends BaseLineClient<WaterXConfig> {
|
|
20
37
|
/** Pyth infra (network defaults unless overridden in JSON). */
|
|
21
38
|
pyth: PythInfraConfig;
|
|
22
39
|
/** Wormhole infra for the credit bridge (network defaults unless overridden). */
|
|
23
40
|
wormhole: WormholeInfraConfig;
|
|
41
|
+
/** Selected oracle rule source (client option, resolved at creation; default `'pyth_rule'`). See `OracleHost.oracleSource`. */
|
|
42
|
+
readonly oracleSource: OracleSource;
|
|
24
43
|
/** Canonical-schema lookups (delegated to below); no transport. */
|
|
25
44
|
private readonly view;
|
|
26
45
|
constructor(network: Network, config: WaterXConfig, opts?: {
|
|
27
46
|
grpcUrl?: string;
|
|
47
|
+
oracleSource?: OracleSource;
|
|
48
|
+
pythGeneration?: PythGeneration;
|
|
28
49
|
});
|
|
29
50
|
/**
|
|
30
51
|
* Async factory: fetches the deployment config for `network` and returns
|
|
@@ -21,12 +21,17 @@ class PerpClient extends base_client_ts_1.BaseLineClient {
|
|
|
21
21
|
pyth;
|
|
22
22
|
/** Wormhole infra for the credit bridge (network defaults unless overridden). */
|
|
23
23
|
wormhole;
|
|
24
|
+
/** Selected oracle rule source (client option, resolved at creation; default `'pyth_rule'`). See `OracleHost.oracleSource`. */
|
|
25
|
+
oracleSource;
|
|
24
26
|
/** Canonical-schema lookups (delegated to below); no transport. */
|
|
25
27
|
view;
|
|
26
28
|
constructor(network, config, opts = {}) {
|
|
27
29
|
super(network, config, opts);
|
|
28
|
-
|
|
30
|
+
// Precedence: explicit config.pyth override > generation constants.
|
|
31
|
+
this.pyth =
|
|
32
|
+
config.pyth ?? (opts.pythGeneration === "pro" ? config_ts_1.PYTH_PRO_DEFAULTS : config_ts_1.PYTH_DEFAULTS)[network];
|
|
29
33
|
this.wormhole = config.wormhole ?? config_ts_1.WORMHOLE_DEFAULTS[network];
|
|
34
|
+
this.oracleSource = opts.oracleSource ?? "pyth_rule";
|
|
30
35
|
this.view = new config_view_ts_1.PerpConfigView(() => this.config, () => this.wormhole);
|
|
31
36
|
}
|
|
32
37
|
/**
|
|
@@ -35,7 +40,11 @@ class PerpClient extends base_client_ts_1.BaseLineClient {
|
|
|
35
40
|
*/
|
|
36
41
|
static async create(network, opts = {}) {
|
|
37
42
|
const config = await (0, config_ts_1.loadConfig)(network, opts);
|
|
38
|
-
return new PerpClient(network, config, {
|
|
43
|
+
return new PerpClient(network, config, {
|
|
44
|
+
grpcUrl: opts.grpcUrl,
|
|
45
|
+
oracleSource: opts.oracleSource,
|
|
46
|
+
pythGeneration: opts.pythGeneration,
|
|
47
|
+
});
|
|
39
48
|
}
|
|
40
49
|
static mainnet(opts = {}) {
|
|
41
50
|
return PerpClient.create("MAINNET", opts);
|
|
@@ -12,8 +12,8 @@ import type { AccountPackages, BasePackageEntry, WormholeInfraConfig } from "../
|
|
|
12
12
|
import type { OraclePackages, PythInfraConfig } from "../oracle/config.ts";
|
|
13
13
|
import type { Network } from "./constants.ts";
|
|
14
14
|
export type { AccountConfig, AccountPackages, BasePackageEntry, NativeCustodyAsset, NativeCustodyPackage, TrustedEmitterRow, WaterxCreditPackage, WaterxReferralPackage, WithdrawalQueuePackage, WormholeBridgePackage, WormholeInfraConfig, WxaAccountPackage, } from "../account/config.ts";
|
|
15
|
-
export type { ConstantFeedEntry, OracleConfig, OraclePackages, PythInfraConfig, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, WaterxConstantRulePackage, WaterxOraclePackage, } from "../oracle/config.ts";
|
|
16
|
-
export { PYTH_DEFAULTS } from "../oracle/config.ts";
|
|
15
|
+
export type { ConstantFeedEntry, OracleConfig, OraclePackages, PythGeneration, PythInfraConfig, PythLazerRulePackage, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, WaterxConstantRulePackage, WaterxOraclePackage, } from "../oracle/config.ts";
|
|
16
|
+
export { PYTH_DEFAULTS, PYTH_PRO_DEFAULTS } from "../oracle/config.ts";
|
|
17
17
|
export interface WaterxPerpMarketEntry {
|
|
18
18
|
market: string;
|
|
19
19
|
config: string;
|
|
@@ -104,12 +104,17 @@ export interface LoadConfigOptions {
|
|
|
104
104
|
waterxConfigUrl?: string;
|
|
105
105
|
/**
|
|
106
106
|
* Reuse a previously-fetched config from the in-memory cache (keyed by
|
|
107
|
-
* the effective URL). Default: false (always fetch fresh).
|
|
107
|
+
* network + the effective URL). Default: false (always fetch fresh).
|
|
108
108
|
*/
|
|
109
109
|
cache?: boolean;
|
|
110
110
|
/** Optional fetch implementation (for tests or environments without global `fetch`). */
|
|
111
111
|
fetchImpl?: typeof fetch;
|
|
112
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* Optional PER-ATTEMPT timeout in ms. Default 10_000. {@link loadConfig}
|
|
114
|
+
* retries a transient failure (network error / 429 / 5xx) via
|
|
115
|
+
* `fetchWithPolicy` (2 retries, exponential backoff) before falling back to
|
|
116
|
+
* the last successfully-validated config for this network+URL, if one exists.
|
|
117
|
+
*/
|
|
113
118
|
timeoutMs?: number;
|
|
114
119
|
}
|
|
115
120
|
export declare function clearConfigCache(): void;
|
|
@@ -10,11 +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.PYTH_PRO_DEFAULTS = exports.PYTH_DEFAULTS = void 0;
|
|
14
14
|
exports.clearConfigCache = clearConfigCache;
|
|
15
15
|
exports.loadConfig = loadConfig;
|
|
16
|
+
const update_fetch_ts_1 = require("../oracle/update-fetch.js");
|
|
16
17
|
var config_ts_1 = require("../oracle/config.js");
|
|
17
18
|
Object.defineProperty(exports, "PYTH_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.PYTH_DEFAULTS; } });
|
|
19
|
+
Object.defineProperty(exports, "PYTH_PRO_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.PYTH_PRO_DEFAULTS; } });
|
|
18
20
|
// ============================================================================
|
|
19
21
|
// Wormhole / Hermes — external chain infra, defaults by network
|
|
20
22
|
// ============================================================================
|
|
@@ -39,38 +41,97 @@ exports.WORMHOLE_DEFAULTS = {
|
|
|
39
41
|
wormholescan_api: "https://api.testnet.wormholescan.io/api/v1",
|
|
40
42
|
},
|
|
41
43
|
};
|
|
42
|
-
|
|
44
|
+
// Last successfully-validated config per `${network}:${url}` — the ONE module
|
|
45
|
+
// map, written UNCONDITIONALLY on every successful load regardless of
|
|
46
|
+
// `opts.cache`. It serves two roles at once: the resilience fallback for a
|
|
47
|
+
// refresh failure (see `loadConfig` below) AND the opt-in fast-path read
|
|
48
|
+
// `opts.cache: true` gates at the top of `loadConfig`. `opts.cache` therefore
|
|
49
|
+
// only gates whether a call *reads* this map early (skipping the fetch
|
|
50
|
+
// entirely) — it never gates whether a call *writes* it; every successful
|
|
51
|
+
// load writes here. The network prefix keeps one network's snapshot from ever
|
|
52
|
+
// satisfying another's request (see the cache-key note in `loadConfig`).
|
|
53
|
+
//
|
|
54
|
+
// Deliberate (benign) semantic refinement from the prior two-map design: a
|
|
55
|
+
// `cache: true` call can now hit an entry that was populated by an earlier
|
|
56
|
+
// `cache: false` call for the SAME network+url. That's fine — it's still that
|
|
57
|
+
// key's latest successfully-validated fetch, strictly FRESHER than any
|
|
58
|
+
// fallback read would have been, so a `cache: true` caller never observes
|
|
59
|
+
// staler data than before; it can only observe MORE-recent data sooner.
|
|
60
|
+
const configCache = new Map();
|
|
43
61
|
function clearConfigCache() {
|
|
44
|
-
|
|
62
|
+
configCache.clear();
|
|
45
63
|
}
|
|
46
64
|
async function loadConfig(network, opts = {}) {
|
|
47
65
|
const url = opts.waterxConfigUrl;
|
|
48
66
|
if (!url) {
|
|
49
67
|
throw new Error("loadConfig: no config URL — pass opts.waterxConfigUrl");
|
|
50
68
|
}
|
|
51
|
-
|
|
52
|
-
|
|
69
|
+
// Key by network AND url, never url alone: the same url can legitimately be
|
|
70
|
+
// requested for two networks (and `validateConfig` enforces network/url
|
|
71
|
+
// coherence on the success path), so a url-only key would let a testnet
|
|
72
|
+
// snapshot satisfy a mainnet request — both on this fast-path read and on
|
|
73
|
+
// the resilience fallback below — handing back wrong-CHAIN object ids to
|
|
74
|
+
// build transactions against. A wrong-network request simply misses here
|
|
75
|
+
// and fetches fresh.
|
|
76
|
+
const cacheKey = `${network}:${url}`;
|
|
77
|
+
if (opts.cache && configCache.has(cacheKey)) {
|
|
78
|
+
return configCache.get(cacheKey);
|
|
53
79
|
}
|
|
54
80
|
const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
|
|
55
81
|
if (!fetchImpl) {
|
|
56
82
|
throw new Error("loadConfig: no global `fetch` available; pass opts.fetchImpl");
|
|
57
83
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
84
|
+
// Same resilience policy as the oracle money-path fetches (see
|
|
85
|
+
// `fetchWithPolicy`): bounded retry with backoff instead of one bare
|
|
86
|
+
// attempt. A refresh failure (network exhaustion, a non-ok response, OR a
|
|
87
|
+
// 200 response that fails to parse/validate — see below) falls back to the
|
|
88
|
+
// last successfully-validated config for this network+URL when one exists — a
|
|
89
|
+
// config-endpoint blip must not crash a long-running process that already
|
|
90
|
+
// has a working deployment snapshot. First load (nothing cached yet) has
|
|
91
|
+
// no fallback and still throws. Intentionally no log line on the fallback
|
|
92
|
+
// path — the SDK never logs (see every other oracle error in this
|
|
93
|
+
// codebase); a caller that cares can tell it got a stale snapshot by
|
|
94
|
+
// re-deriving staleness itself if it needs to.
|
|
95
|
+
//
|
|
96
|
+
// Deliberate limitation (not fixed here — a follow-up): this treats EVERY
|
|
97
|
+
// failure mode identically, including a DETERMINISTIC one (404/403 — the
|
|
98
|
+
// URL moved, or access was revoked) once a `configCache` snapshot exists.
|
|
99
|
+
// Unlike a transient blip, a deterministic failure will never self-heal on
|
|
100
|
+
// the next retry, so a long-running process with a stale snapshot will
|
|
101
|
+
// keep serving it FOREVER and silently mask what is actually a permanent
|
|
102
|
+
// deployment problem. Disambiguating "blip" from "moved/revoked" (e.g. via
|
|
103
|
+
// a max-staleness budget, or treating non-retryable 4xx specially) is
|
|
104
|
+
// intentionally deferred rather than folded into this change.
|
|
105
|
+
//
|
|
106
|
+
// fetch → ok-check → parse → validate all run in ONE try, so any failure
|
|
107
|
+
// along that chain (network exhaustion, a non-ok response, malformed JSON,
|
|
108
|
+
// or a `validateConfig` rejection) lands in the same catch and takes the
|
|
109
|
+
// same single last-known-good lookup below.
|
|
110
|
+
let raw;
|
|
61
111
|
try {
|
|
62
|
-
response = await
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
112
|
+
const response = await (0, update_fetch_ts_1.fetchWithPolicy)(url, {}, { timeoutMs: opts.timeoutMs ?? 10_000, retries: 2, fetchImpl });
|
|
113
|
+
if (!response.ok) {
|
|
114
|
+
throw new Error(`loadConfig: HTTP ${response.status} fetching ${url}`);
|
|
115
|
+
}
|
|
116
|
+
raw = (await response.json());
|
|
117
|
+
validateConfig(raw, network, url);
|
|
66
118
|
}
|
|
67
|
-
|
|
68
|
-
|
|
119
|
+
catch (err) {
|
|
120
|
+
const stale = configCache.get(cacheKey);
|
|
121
|
+
if (stale)
|
|
122
|
+
return stale;
|
|
123
|
+
// Reformat a status-carrying FetchPolicyError (retries exhausted on a
|
|
124
|
+
// retryable status) into this function's own message shape, mirroring
|
|
125
|
+
// the non-retried `!response.ok` throw above. A network-level
|
|
126
|
+
// exhaustion (no status), a `!response.ok` throw, or a JSON parse /
|
|
127
|
+
// `validateConfig` failure has no domain-specific reframing to add —
|
|
128
|
+
// propagate that error's own message as-is.
|
|
129
|
+
if (err instanceof update_fetch_ts_1.FetchPolicyError && err.status !== undefined) {
|
|
130
|
+
throw new Error(`loadConfig: HTTP ${err.status} fetching ${url} (retries exhausted after ${err.attempts} attempts)`, { cause: err });
|
|
131
|
+
}
|
|
132
|
+
throw err;
|
|
69
133
|
}
|
|
70
|
-
|
|
71
|
-
validateConfig(raw, network, url);
|
|
72
|
-
if (opts.cache)
|
|
73
|
-
cache.set(url, raw);
|
|
134
|
+
configCache.set(cacheKey, raw);
|
|
74
135
|
return raw;
|
|
75
136
|
}
|
|
76
137
|
function validateConfig(cfg, expected, url) {
|
|
@@ -88,6 +149,9 @@ function validateConfig(cfg, expected, url) {
|
|
|
88
149
|
};
|
|
89
150
|
// Validate by deployment kind. A perp config must carry the perp set; a
|
|
90
151
|
// credit config the credit set. `waterx_account` is common to both.
|
|
152
|
+
// `pyth_lazer_rule` is intentionally NOT required (and never will be by
|
|
153
|
+
// presence alone) — it's an optional/experimental package selected only via
|
|
154
|
+
// a client's `oracleSource` option, never by its presence in the config.
|
|
91
155
|
const isPerp = "waterx_perp" in cfg.packages;
|
|
92
156
|
const isCredit = "waterx_credit" in cfg.packages || "wormhole_bridge" in cfg.packages;
|
|
93
157
|
const required = isPerp
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { PerpClient } from "./client.ts";
|
|
2
2
|
export type { CreateClientOptions } from "./client.ts";
|
|
3
|
-
export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, loadConfig } from "./config.ts";
|
|
4
|
-
export type { BasePackageEntry, ConstantFeedEntry, WaterxReferralPackage, LoadConfigOptions, NativeCustodyAsset, NativeCustodyPackage, PythInfraConfig, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, TestnetFaucetPackage, TrustedEmitterRow, WaterXConfig, WaterXPackages, WaterxCreditPackage, WaterxOraclePackage, WaterxPerpMarketEntry, WaterxPerpPackage, WaterxStakingPackage, WithdrawalQueuePackage, WlpPackage, WormholeBridgePackage, WormholeInfraConfig, WxaAccountPackage, } from "./config.ts";
|
|
3
|
+
export { PYTH_DEFAULTS, PYTH_PRO_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, loadConfig, } from "./config.ts";
|
|
4
|
+
export type { BasePackageEntry, ConstantFeedEntry, WaterxReferralPackage, LoadConfigOptions, NativeCustodyAsset, NativeCustodyPackage, PythGeneration, PythInfraConfig, PythLazerRulePackage, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, TestnetFaucetPackage, TrustedEmitterRow, WaterXConfig, WaterXPackages, WaterxCreditPackage, WaterxOraclePackage, WaterxPerpMarketEntry, WaterxPerpPackage, WaterxStakingPackage, WithdrawalQueuePackage, WlpPackage, WormholeBridgePackage, WormholeInfraConfig, WxaAccountPackage, } from "./config.ts";
|
|
5
5
|
export { ACTION_ADD_PRE_ORDER, ACTION_CANCEL_ORDER, ACTION_CANCEL_PRE_ORDER, ACTION_CLOSE_POSITION, ACTION_DECREASE_POSITION, ACTION_DEPOSIT_COLLATERAL, ACTION_INCREASE_POSITION, ACTION_LIQUIDATE, ACTION_OPEN_POSITION, ACTION_PLACE_ORDER, ACTION_UPDATE_ORDER, ACTION_WITHDRAW_COLLATERAL, BPS_SCALE, CRYPTO_FEE_RATE, DOUBLE_SCALE, DRY_RUN_SENDER, FLOAT_SCALE, MAINTENANCE_MARGIN_RATE, ORDER_LIMIT_BUY, ORDER_LIMIT_SELL, ORDER_STOP_BUY, ORDER_STOP_SELL, ORDER_TAG_WILDCARD, PERM_ALL, PERM_ALL_TRADING, PERM_CANCEL_ORDER, PERM_CLOSE_POSITION, PERM_DECREASE_POSITION, PERM_DEPOSIT_COLLATERAL, PERM_INCREASE_POSITION, PERM_MINT_WLP, PERM_OPEN_POSITION, PERM_PLACE_ORDER, PERM_REDEEM_WLP, PERM_WITHDRAW_COLLATERAL, STAKING_PERM_DEPOSIT_STAKE, STAKING_PERM_REDEEM_STAKE, STAKING_PERM_CLAIM_REWARD, STAKING_PERM_ALL, STOCK_FEE_RATE, MS_PER_YEAR, SUI_DECIMALS, WLP_DECIMALS, COLLATERAL_DECIMALS, TOKEN_DECIMALS, } from "./constants.ts";
|
|
6
6
|
export type { Network } from "./constants.ts";
|
|
7
7
|
export { getMarketTickers, getCollateralAssets } from "../utils/config.ts";
|
|
@@ -9,7 +9,8 @@ export { annualizedApyFromRatio, annualizeFundingRate, calcBorrowRate, calcBorro
|
|
|
9
9
|
export * from "./user/index.ts";
|
|
10
10
|
export * from "./tx-builders.ts";
|
|
11
11
|
export * from "./fetch.ts";
|
|
12
|
-
export { PythCache, aggregateTicker, aggregateTickerWithConstant, aggregateTickerWithPyth, buildPythPriceUpdateCalls, fetchPriceFeedsUpdateData, refreshOraclePrices, updatePythPrices, } from "../oracle/index.ts";
|
|
12
|
+
export { FetchPolicyError, LazerApiKeyMissingError, OracleFeeSourceUnavailableError, OracleSourceNotImplementedError, PythCache, aggregateTicker, aggregateTickerWithConstant, aggregateTickerWithPyth, buildPythPriceUpdateCalls, fetchPriceFeedsUpdateData, refreshOraclePrices, updatePythPrices, } from "../oracle/index.ts";
|
|
13
|
+
export type { FetchPolicy, OracleFeeSource, OracleSource, UpdateDataProvider, } from "../oracle/index.ts";
|
|
13
14
|
export { fetchDepositVaa, fetchVaa, listBridgeWithdrawalVaas, listVaasByEmitter, padEvmEmitter, toWormholescanEmitter, vaaBase64ToBytes, vaaBase64ToHex, vaaBytesToBase64, waitForVaa, } from "../account/funding/wormhole.ts";
|
|
14
15
|
export type { VaaListItem, VaaResponse, WormholescanOptions } from "../account/funding/wormhole.ts";
|
|
15
16
|
export { AccountData as AccountDataBcs, GlobalConfigData as GlobalConfigDataBcs, MarketData as MarketDataBcs, OrderData as OrderDataBcs, PoolData as PoolDataBcs, PositionData as PositionDataBcs, RedeemRequestData as RedeemRequestDataBcs, TokenPoolData as TokenPoolDataBcs, } from "../generated/waterx_perp_view/view.ts";
|
|
@@ -36,14 +36,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
40
|
-
exports.
|
|
41
|
-
exports.withdrawalQueueCalls = exports.nativeCustodyCalls = exports.referralCalls = exports.pythSponsorRuleCalls = exports.pythRuleCalls = exports.oracleCalls = exports.stakingCalls = exports.wxaAccountCalls = exports.viewCalls = exports.lpPoolCalls = exports.tradingCalls = exports.MarketConfigBcs = exports.MarketBcs = exports.OrderBcs = exports.PositionBcs = exports.TokenPoolDataBcs = exports.RedeemRequestDataBcs = void 0;
|
|
39
|
+
exports.COLLATERAL_DECIMALS = exports.WLP_DECIMALS = exports.SUI_DECIMALS = exports.MS_PER_YEAR = exports.STOCK_FEE_RATE = exports.STAKING_PERM_ALL = exports.STAKING_PERM_CLAIM_REWARD = exports.STAKING_PERM_REDEEM_STAKE = exports.STAKING_PERM_DEPOSIT_STAKE = exports.PERM_WITHDRAW_COLLATERAL = exports.PERM_REDEEM_WLP = exports.PERM_PLACE_ORDER = exports.PERM_OPEN_POSITION = exports.PERM_MINT_WLP = exports.PERM_INCREASE_POSITION = exports.PERM_DEPOSIT_COLLATERAL = exports.PERM_DECREASE_POSITION = exports.PERM_CLOSE_POSITION = exports.PERM_CANCEL_ORDER = exports.PERM_ALL_TRADING = exports.PERM_ALL = exports.ORDER_TAG_WILDCARD = exports.ORDER_STOP_SELL = exports.ORDER_STOP_BUY = exports.ORDER_LIMIT_SELL = exports.ORDER_LIMIT_BUY = exports.MAINTENANCE_MARGIN_RATE = exports.FLOAT_SCALE = exports.DRY_RUN_SENDER = exports.DOUBLE_SCALE = exports.CRYPTO_FEE_RATE = exports.BPS_SCALE = exports.ACTION_WITHDRAW_COLLATERAL = exports.ACTION_UPDATE_ORDER = exports.ACTION_PLACE_ORDER = exports.ACTION_OPEN_POSITION = exports.ACTION_LIQUIDATE = exports.ACTION_INCREASE_POSITION = exports.ACTION_DEPOSIT_COLLATERAL = exports.ACTION_DECREASE_POSITION = exports.ACTION_CLOSE_POSITION = exports.ACTION_CANCEL_PRE_ORDER = exports.ACTION_CANCEL_ORDER = exports.ACTION_ADD_PRE_ORDER = exports.loadConfig = exports.clearConfigCache = exports.WORMHOLE_DEFAULTS = exports.PYTH_PRO_DEFAULTS = exports.PYTH_DEFAULTS = exports.PerpClient = void 0;
|
|
40
|
+
exports.AccountDataBcs = exports.waitForVaa = exports.vaaBytesToBase64 = exports.vaaBase64ToHex = exports.vaaBase64ToBytes = exports.toWormholescanEmitter = exports.padEvmEmitter = exports.listVaasByEmitter = exports.listBridgeWithdrawalVaas = exports.fetchVaa = exports.fetchDepositVaa = exports.updatePythPrices = exports.refreshOraclePrices = exports.fetchPriceFeedsUpdateData = exports.buildPythPriceUpdateCalls = exports.aggregateTickerWithPyth = exports.aggregateTickerWithConstant = exports.aggregateTicker = exports.PythCache = exports.OracleSourceNotImplementedError = exports.OracleFeeSourceUnavailableError = exports.LazerApiKeyMissingError = exports.FetchPolicyError = exports.rawPrice = exports.decodeFundingIndexDelta = exports.calcWlpRedeemOut = exports.calcWlpPrice = exports.calcWlpMintOut = exports.calcWlpIncentiveApy = exports.calcUnrealizedPnl = exports.calcTotalTradingFeeRate = exports.calcTokenUtilizationBps = exports.calcPositionBorrowFee = exports.calcNotional = exports.calcMaxReducibleCollateralUsd = exports.calcLeverage = exports.calcImpactFeeRate = exports.calcFundingRate = exports.calcFundingFeeUsd = exports.calcFee = exports.calcEstLiqPrice = exports.calcEffectiveCollateralUsd = exports.calcDynamicFeeBps = exports.calcBorrowRateAccrual = exports.calcBorrowRate = exports.annualizeFundingRate = exports.annualizedApyFromRatio = exports.getCollateralAssets = exports.getMarketTickers = exports.TOKEN_DECIMALS = void 0;
|
|
41
|
+
exports.withdrawalQueueCalls = exports.nativeCustodyCalls = exports.referralCalls = exports.pythSponsorRuleCalls = exports.pythRuleCalls = exports.oracleCalls = exports.stakingCalls = exports.wxaAccountCalls = exports.viewCalls = exports.lpPoolCalls = exports.tradingCalls = exports.MarketConfigBcs = exports.MarketBcs = exports.OrderBcs = exports.PositionBcs = exports.TokenPoolDataBcs = exports.RedeemRequestDataBcs = exports.PositionDataBcs = exports.PoolDataBcs = exports.OrderDataBcs = exports.MarketDataBcs = exports.GlobalConfigDataBcs = void 0;
|
|
42
42
|
// ======== Core ========
|
|
43
43
|
var client_ts_1 = require("./client.js");
|
|
44
44
|
Object.defineProperty(exports, "PerpClient", { enumerable: true, get: function () { return client_ts_1.PerpClient; } });
|
|
45
45
|
var config_ts_1 = require("./config.js");
|
|
46
46
|
Object.defineProperty(exports, "PYTH_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.PYTH_DEFAULTS; } });
|
|
47
|
+
Object.defineProperty(exports, "PYTH_PRO_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.PYTH_PRO_DEFAULTS; } });
|
|
47
48
|
Object.defineProperty(exports, "WORMHOLE_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.WORMHOLE_DEFAULTS; } });
|
|
48
49
|
Object.defineProperty(exports, "clearConfigCache", { enumerable: true, get: function () { return config_ts_1.clearConfigCache; } });
|
|
49
50
|
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_ts_1.loadConfig; } });
|
|
@@ -131,6 +132,10 @@ __exportStar(require("./tx-builders.js"), exports);
|
|
|
131
132
|
__exportStar(require("./fetch.js"), exports);
|
|
132
133
|
// ======== Oracle utilities (Pyth source + rule aggregation) ========
|
|
133
134
|
var index_ts_1 = require("../oracle/index.js");
|
|
135
|
+
Object.defineProperty(exports, "FetchPolicyError", { enumerable: true, get: function () { return index_ts_1.FetchPolicyError; } });
|
|
136
|
+
Object.defineProperty(exports, "LazerApiKeyMissingError", { enumerable: true, get: function () { return index_ts_1.LazerApiKeyMissingError; } });
|
|
137
|
+
Object.defineProperty(exports, "OracleFeeSourceUnavailableError", { enumerable: true, get: function () { return index_ts_1.OracleFeeSourceUnavailableError; } });
|
|
138
|
+
Object.defineProperty(exports, "OracleSourceNotImplementedError", { enumerable: true, get: function () { return index_ts_1.OracleSourceNotImplementedError; } });
|
|
134
139
|
Object.defineProperty(exports, "PythCache", { enumerable: true, get: function () { return index_ts_1.PythCache; } });
|
|
135
140
|
Object.defineProperty(exports, "aggregateTicker", { enumerable: true, get: function () { return index_ts_1.aggregateTicker; } });
|
|
136
141
|
Object.defineProperty(exports, "aggregateTickerWithConstant", { enumerable: true, get: function () { return index_ts_1.aggregateTickerWithConstant; } });
|