@waterx/sdk 4.0.0 → 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 +52 -37
- package/dist/cjs/src/account/account.js +2 -1
- package/dist/cjs/src/account/config.d.ts +0 -16
- 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 +21 -21
- package/dist/cjs/src/oracle/aggregate.js +84 -71
- package/dist/cjs/src/oracle/config.d.ts +107 -52
- package/dist/cjs/src/oracle/config.js +15 -35
- package/dist/cjs/src/oracle/host.d.ts +13 -2
- package/dist/cjs/src/oracle/index.d.ts +4 -2
- package/dist/cjs/src/oracle/index.js +25 -6
- package/dist/cjs/src/oracle/price-update-rule.d.ts +3 -4
- package/dist/cjs/src/oracle/pyth.d.ts +68 -6
- package/dist/cjs/src/oracle/pyth.js +338 -22
- package/dist/cjs/src/oracle/rule-registry.d.ts +11 -6
- package/dist/cjs/src/oracle/rule-registry.js +13 -6
- package/dist/cjs/src/oracle/rules/pyth-core-rule.js +17 -2
- package/dist/cjs/src/oracle/rules/pyth-lazer-rule.d.ts +6 -6
- package/dist/cjs/src/oracle/rules/pyth-lazer-rule.js +25 -22
- package/dist/cjs/src/oracle/rules/pyth-rule.js +5 -0
- 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/oracle/update-fetch.d.ts +32 -2
- package/dist/cjs/src/oracle/update-fetch.js +60 -3
- package/dist/cjs/src/perp/client.d.ts +71 -19
- package/dist/cjs/src/perp/client.js +30 -10
- package/dist/cjs/src/perp/config.d.ts +4 -7
- package/dist/cjs/src/perp/config.js +9 -12
- 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 +8 -4
- package/dist/cjs/src/perp/index.js +12 -7
- 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 +49 -20
- package/dist/cjs/src/unified-client.js +4 -1
- 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/config.d.ts +0 -16
- 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 +21 -21
- package/dist/src/oracle/aggregate.js +84 -71
- package/dist/src/oracle/config.d.ts +107 -52
- package/dist/src/oracle/config.js +14 -34
- package/dist/src/oracle/host.d.ts +13 -2
- package/dist/src/oracle/index.d.ts +4 -2
- package/dist/src/oracle/index.js +18 -7
- package/dist/src/oracle/price-update-rule.d.ts +3 -4
- package/dist/src/oracle/pyth.d.ts +68 -6
- package/dist/src/oracle/pyth.js +334 -22
- package/dist/src/oracle/rule-registry.d.ts +11 -6
- package/dist/src/oracle/rule-registry.js +13 -6
- package/dist/src/oracle/rules/pyth-core-rule.js +18 -3
- package/dist/src/oracle/rules/pyth-lazer-rule.d.ts +6 -6
- package/dist/src/oracle/rules/pyth-lazer-rule.js +26 -23
- package/dist/src/oracle/rules/pyth-rule.js +5 -0
- package/dist/src/oracle/rules/waterx-rule.d.ts +89 -0
- package/dist/src/oracle/rules/waterx-rule.js +266 -0
- package/dist/src/oracle/update-fetch.d.ts +32 -2
- package/dist/src/oracle/update-fetch.js +57 -3
- package/dist/src/perp/client.d.ts +71 -19
- package/dist/src/perp/client.js +31 -11
- package/dist/src/perp/config.d.ts +4 -7
- package/dist/src/perp/config.js +9 -12
- 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 +8 -4
- package/dist/src/perp/index.js +5 -3
- 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 +49 -20
- package/dist/src/unified-client.js +4 -1
- 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
|
@@ -12,44 +12,96 @@
|
|
|
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;
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* Which oracle price-update source drives `refreshOraclePrices`. Each source
|
|
22
|
+
* is self-contained (own infra + config) with NO cross-source fallback:
|
|
23
|
+
*
|
|
24
|
+
* - `'pyth_rule'` (default) — Pyth Core `pyth_rule` updates (Hermes VAA +
|
|
25
|
+
* per-feed update fees), Core state + keyless Core Hermes.
|
|
26
|
+
* - `'pyth_lazer_rule'` — Pyth Lazer signed updates (ONE `leEcdsa` verify
|
|
27
|
+
* per PTB, no per-feed fees); needs `packages.pyth_lazer_rule` with feeds
|
|
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.
|
|
36
|
+
*
|
|
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.
|
|
24
43
|
*/
|
|
25
44
|
oracleSource?: OracleSource;
|
|
26
45
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* `
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* always wins wholesale (see `PythGeneration`).
|
|
46
|
+
* Pyth Lazer access token (`Authorization: Bearer …`). Required under
|
|
47
|
+
* `oracleSource: 'pyth_lazer_rule'` (Lazer is auth-first) and unused by
|
|
48
|
+
* `'pyth_rule'` (keyless Core Hermes). This is a SECRET and never belongs in
|
|
49
|
+
* the canonical `waterx-config` JSON — pass it at client init from your own
|
|
50
|
+
* env var (e.g. `PYTH_API_KEY`); the SDK never reads `process.env`.
|
|
33
51
|
*/
|
|
34
|
-
|
|
52
|
+
pythApiKey?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Retry/timeout policy for the off-chain Hermes / Lazer update fetches (see
|
|
55
|
+
* `fetchWithPolicy`). Optional — defaults to 15s timeout, 2 retries.
|
|
56
|
+
*/
|
|
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;
|
|
35
81
|
}
|
|
36
82
|
export declare class PerpClient extends BaseLineClient<WaterXConfig> {
|
|
37
|
-
/** Pyth infra (network
|
|
83
|
+
/** Pyth Core infra (fixed per network) plus the caller-supplied credential/policy. */
|
|
38
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;
|
|
39
91
|
/** Wormhole infra for the credit bridge (network defaults unless overridden). */
|
|
40
92
|
wormhole: WormholeInfraConfig;
|
|
41
|
-
/** Selected oracle
|
|
93
|
+
/** Selected oracle price-update source (`oracleSource` create option; default `'pyth_rule'`). */
|
|
42
94
|
readonly oracleSource: OracleSource;
|
|
43
95
|
/** Canonical-schema lookups (delegated to below); no transport. */
|
|
44
96
|
private readonly view;
|
|
45
|
-
constructor(network: Network, config: WaterXConfig, opts?:
|
|
46
|
-
grpcUrl?: string;
|
|
47
|
-
oracleSource?: OracleSource;
|
|
48
|
-
pythGeneration?: PythGeneration;
|
|
49
|
-
});
|
|
97
|
+
constructor(network: Network, config: WaterXConfig, opts?: CreateClientOptions);
|
|
50
98
|
/**
|
|
51
99
|
* Async factory: fetches the deployment config for `network` and returns
|
|
52
100
|
* a ready-to-use client. Pass `opts.cache=true` to memoize the JSON.
|
|
101
|
+
*
|
|
102
|
+
* No oracle-config guard here: selecting a source whose feeds are absent is
|
|
103
|
+
* not an error at init — it surfaces at tx-build time for the specific
|
|
104
|
+
* tickers that source can't serve (see `refreshOraclePrices`).
|
|
53
105
|
*/
|
|
54
106
|
static create(network: Network, opts?: CreateClientOptions): Promise<PerpClient>;
|
|
55
107
|
static mainnet(opts?: CreateClientOptions): Promise<PerpClient>;
|
package/dist/src/perp/client.js
CHANGED
|
@@ -12,36 +12,56 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { BaseLineClient } from "../base-client.js";
|
|
14
14
|
import { PerpConfigView } from "./config-view.js";
|
|
15
|
-
import { loadConfig, PYTH_DEFAULTS,
|
|
15
|
+
import { loadConfig, PYTH_DEFAULTS, WATERX_DEFAULTS, WORMHOLE_DEFAULTS, } from "./config.js";
|
|
16
16
|
export class PerpClient extends BaseLineClient {
|
|
17
|
-
/** Pyth infra (network
|
|
17
|
+
/** Pyth Core infra (fixed per network) plus the caller-supplied credential/policy. */
|
|
18
18
|
pyth;
|
|
19
|
+
/**
|
|
20
|
+
* WaterX quote-center infra for `oracleSource: 'waterx_rule'` — the network
|
|
21
|
+
* default, overridden by the `waterxEndpoint` / `waterxFetch` create options
|
|
22
|
+
* (a same-origin proxy or a custom `fetchImpl` for browser consumers).
|
|
23
|
+
*/
|
|
24
|
+
waterx;
|
|
19
25
|
/** Wormhole infra for the credit bridge (network defaults unless overridden). */
|
|
20
26
|
wormhole;
|
|
21
|
-
/** Selected oracle
|
|
27
|
+
/** Selected oracle price-update source (`oracleSource` create option; default `'pyth_rule'`). */
|
|
22
28
|
oracleSource;
|
|
23
29
|
/** Canonical-schema lookups (delegated to below); no transport. */
|
|
24
30
|
view;
|
|
25
31
|
constructor(network, config, opts = {}) {
|
|
26
32
|
super(network, config, opts);
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
// Pyth Core infra is fixed per network — NOT deployment-overridable and
|
|
34
|
+
// NOT source-dependent (the pyth_lazer_rule source reads only api_key/fetch
|
|
35
|
+
// from here). The api_key + fetch policy are caller-supplied at init: a
|
|
36
|
+
// secret has no place in the canonical waterx-config JSON.
|
|
37
|
+
this.pyth = {
|
|
38
|
+
...PYTH_DEFAULTS[network],
|
|
39
|
+
...(opts.pythApiKey !== undefined ? { api_key: opts.pythApiKey } : {}),
|
|
40
|
+
...(opts.pythFetch !== undefined ? { fetch: opts.pythFetch } : {}),
|
|
41
|
+
};
|
|
30
42
|
this.wormhole = config.wormhole ?? WORMHOLE_DEFAULTS[network];
|
|
43
|
+
// Quote-center infra: network default, each field independently overridable
|
|
44
|
+
// — a browser blocked by the quote-center's CORS allowlist swaps `endpoint`
|
|
45
|
+
// for a same-origin proxy without touching anything else.
|
|
46
|
+
this.waterx = {
|
|
47
|
+
...WATERX_DEFAULTS[network],
|
|
48
|
+
...(opts.waterxEndpoint !== undefined ? { endpoint: opts.waterxEndpoint } : {}),
|
|
49
|
+
...(opts.waterxFetch !== undefined ? { fetch: opts.waterxFetch } : {}),
|
|
50
|
+
};
|
|
31
51
|
this.oracleSource = opts.oracleSource ?? "pyth_rule";
|
|
32
52
|
this.view = new PerpConfigView(() => this.config, () => this.wormhole);
|
|
33
53
|
}
|
|
34
54
|
/**
|
|
35
55
|
* Async factory: fetches the deployment config for `network` and returns
|
|
36
56
|
* a ready-to-use client. Pass `opts.cache=true` to memoize the JSON.
|
|
57
|
+
*
|
|
58
|
+
* No oracle-config guard here: selecting a source whose feeds are absent is
|
|
59
|
+
* not an error at init — it surfaces at tx-build time for the specific
|
|
60
|
+
* tickers that source can't serve (see `refreshOraclePrices`).
|
|
37
61
|
*/
|
|
38
62
|
static async create(network, opts = {}) {
|
|
39
63
|
const config = await loadConfig(network, opts);
|
|
40
|
-
return new PerpClient(network, config,
|
|
41
|
-
grpcUrl: opts.grpcUrl,
|
|
42
|
-
oracleSource: opts.oracleSource,
|
|
43
|
-
pythGeneration: opts.pythGeneration,
|
|
44
|
-
});
|
|
64
|
+
return new PerpClient(network, config, opts);
|
|
45
65
|
}
|
|
46
66
|
static mainnet(opts = {}) {
|
|
47
67
|
return PerpClient.create("MAINNET", opts);
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
* below, keyed by network.
|
|
10
10
|
*/
|
|
11
11
|
import type { AccountPackages, BasePackageEntry, WormholeInfraConfig } from "../account/config.ts";
|
|
12
|
-
import type { OraclePackages
|
|
12
|
+
import type { OraclePackages } from "../oracle/config.ts";
|
|
13
13
|
import type { Network } from "./constants.ts";
|
|
14
|
-
export type { AccountConfig, AccountPackages, BasePackageEntry, NativeCustodyAsset, NativeCustodyPackage,
|
|
15
|
-
export type { ConstantFeedEntry, OracleConfig, OraclePackages,
|
|
16
|
-
export { PYTH_DEFAULTS,
|
|
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, 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>;
|
|
@@ -82,8 +81,6 @@ export interface WaterXConfig {
|
|
|
82
81
|
/** Sui gRPC base URL (default: public Mysten fullnode for the network). */
|
|
83
82
|
grpcUrl?: string;
|
|
84
83
|
packages: WaterXPackages;
|
|
85
|
-
/** Pyth infra override (defaults from `PYTH_DEFAULTS[network]`). */
|
|
86
|
-
pyth?: PythInfraConfig;
|
|
87
84
|
/** Wormhole infra override (defaults from `WORMHOLE_DEFAULTS[network]`). */
|
|
88
85
|
wormhole?: WormholeInfraConfig;
|
|
89
86
|
/** Sui `CoinRegistry` shared object (credit deployments). */
|
package/dist/src/perp/config.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* **not** in the JSON — it lives in `PYTH_DEFAULTS` / `WORMHOLE_DEFAULTS`
|
|
9
9
|
* below, keyed by network.
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
12
|
-
export { PYTH_DEFAULTS,
|
|
11
|
+
import { fetchWithPolicy, rethrowExhaustedFetch } from "../oracle/update-fetch.js";
|
|
12
|
+
export { PYTH_DEFAULTS, WATERX_DEFAULTS } from "../oracle/config.js";
|
|
13
13
|
// ============================================================================
|
|
14
14
|
// Wormhole / Hermes — external chain infra, defaults by network
|
|
15
15
|
// ============================================================================
|
|
@@ -113,16 +113,13 @@ export async function loadConfig(network, opts = {}) {
|
|
|
113
113
|
const stale = configCache.get(cacheKey);
|
|
114
114
|
if (stale)
|
|
115
115
|
return stale;
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
// the
|
|
119
|
-
// exhaustion (no status), a `!response.ok` throw, or a JSON
|
|
120
|
-
// `validateConfig` failure has no
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
throw new Error(`loadConfig: HTTP ${err.status} fetching ${url} (retries exhausted after ${err.attempts} attempts)`, { cause: err });
|
|
124
|
-
}
|
|
125
|
-
throw err;
|
|
116
|
+
// Reframe a status-carrying FetchPolicyError into this function's own
|
|
117
|
+
// message shape, mirroring the non-retried `!response.ok` throw above and
|
|
118
|
+
// carrying the URL (the key datum for a config-fetch failure). A
|
|
119
|
+
// network-level exhaustion (no status), a `!response.ok` throw, or a JSON
|
|
120
|
+
// parse / `validateConfig` failure has no reframing to add — the helper
|
|
121
|
+
// propagates those verbatim.
|
|
122
|
+
rethrowExhaustedFetch(err, (e) => `loadConfig: HTTP ${e.status} fetching ${url}`);
|
|
126
123
|
}
|
|
127
124
|
configCache.set(cacheKey, raw);
|
|
128
125
|
return raw;
|
|
@@ -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,15 +1,17 @@
|
|
|
1
1
|
// Perp-line domain constants (trading permissions / order tags / action codes /
|
|
2
|
-
//
|
|
2
|
+
// well-known addresses). Re-exports the shared primitives from
|
|
3
3
|
// `../constants.ts` so perp code and the `./perp` barrel get the full set from
|
|
4
4
|
// a single import.
|
|
5
|
+
//
|
|
6
|
+
// NOTE: there are deliberately NO fee-rate / maintenance-margin constants here.
|
|
7
|
+
// `CRYPTO_FEE_RATE` / `STOCK_FEE_RATE` / `MAINTENANCE_MARGIN_RATE` were removed
|
|
8
|
+
// — they were defaults masquerading as truth; per-market `MarketConfig` on
|
|
9
|
+
// chain is the only source for fee and margin parameters (real MMRs span
|
|
10
|
+
// 0.5%–5%; the flat 1.5% understated AAPLX-class risk >3x — mainnet incident
|
|
11
|
+
// 2026-07-28: shorts displayed liq ~$364 but were liquidated at ~$343). When
|
|
12
|
+
// the market rate is unavailable, treat the value as NOT estimable and fail
|
|
13
|
+
// safe — never substitute a flat default.
|
|
5
14
|
export * from "../constants.js";
|
|
6
|
-
// ======== Fee rates & risk parameters ========
|
|
7
|
-
/** Default crypto market trading fee rate (3 bps). Per-market value lives in MarketConfig. */
|
|
8
|
-
export const CRYPTO_FEE_RATE = 0.0003;
|
|
9
|
-
/** Default stock / commodity market trading fee rate (5 bps). Per-market value lives in MarketConfig. */
|
|
10
|
-
export const STOCK_FEE_RATE = 0.0005;
|
|
11
|
-
/** Default maintenance margin rate (150 bps = 1.5%). Per-market value lives in MarketConfig. */
|
|
12
|
-
export const MAINTENANCE_MARGIN_RATE = 0.015;
|
|
13
15
|
// ======== Permission Bitmasks (matches account_data.move) ========
|
|
14
16
|
export const PERM_OPEN_POSITION = 1;
|
|
15
17
|
export const PERM_CLOSE_POSITION = 2;
|
|
@@ -51,6 +51,9 @@ export async function getSpendableCreditBalance(client, accountId) {
|
|
|
51
51
|
probeParkedBackingAssets(client, accountId),
|
|
52
52
|
probeAddressCreditBalance(client, accountId),
|
|
53
53
|
]);
|
|
54
|
+
// COLLATERAL_DECIMALS here is the CREDIT/wxUSD *target* scale (collateral-typed;
|
|
55
|
+
// 6 on all current deployments — config carries no credit decimal). The
|
|
56
|
+
// per-asset backing decimals come from config via each row's `decimals`.
|
|
54
57
|
const pendingBackingRaw = sumParkedBackingAsCreditRaw(parkedBacking, COLLATERAL_DECIMALS);
|
|
55
58
|
const pendingCreditAtAddressRaw = addressCredit.fundsRaw + addressCredit.coinsRaw;
|
|
56
59
|
const totalRaw = internalRaw + pendingBackingRaw + pendingCreditAtAddressRaw;
|
|
@@ -6,6 +6,7 @@ import { bcs } from "@mysten/sui/bcs";
|
|
|
6
6
|
import { Transaction } from "@mysten/sui/transactions";
|
|
7
7
|
import { bridgeFeeAmount as bridgeFeeAmountCall, bridgeFeeRate as bridgeFeeRateCall, bridgeMinFee as bridgeMinFeeCall, wouldExecuteWormhole as wouldExecuteWormholeCall, } from "../../generated/withdrawal_queue/withdrawal_queue.js";
|
|
8
8
|
import { dailyBurned as dailyBurnedCall, dailyBurnLimit as dailyBurnLimitCall, dailyMinted as dailyMintedCall, dailyMintLimit as dailyMintLimitCall, maxBurnPerTx as maxBurnPerTxCall, maxMintPerTx as maxMintPerTxCall, mintedFor as mintedForCall, paused as pausedCall, personalBurnCapAmount as personalBurnCapAmountCall, personalBurned as personalBurnedCall, } from "../../generated/wormhole_bridge/wormhole_bridge.js";
|
|
9
|
+
import { toU64 } from "../../utils/validate.js";
|
|
9
10
|
import { extractAt, simulateRaw } from "./simulate.js";
|
|
10
11
|
/**
|
|
11
12
|
* Batched read of the bridge's rate-limit / cap state in a single simulate.
|
|
@@ -96,7 +97,7 @@ function requireWithdrawalQueue(client) {
|
|
|
96
97
|
*/
|
|
97
98
|
export async function getBridgeFee(client, args) {
|
|
98
99
|
const { pkg, queue } = requireWithdrawalQueue(client);
|
|
99
|
-
const amount =
|
|
100
|
+
const amount = toU64(args.amount, "amount");
|
|
100
101
|
const common = {
|
|
101
102
|
package: pkg,
|
|
102
103
|
typeArguments: [args.creditType ?? client.creditType()],
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { bcs } from "@mysten/sui/bcs";
|
|
6
6
|
import { Transaction } from "@mysten/sui/transactions";
|
|
7
7
|
import { AccountData, accountData as accountDataCall, GlobalConfigData, globalConfigData as globalConfigDataCall, MarketData, marketData as marketDataCall, PoolData, poolData as poolDataCall, TokenPoolData, tokenPoolData as tokenPoolDataCall, } from "../../generated/waterx_perp_view/view.js";
|
|
8
|
+
import { toU64 } from "../../utils/validate.js";
|
|
8
9
|
import { simulateAndExtract, withLp } from "./simulate.js";
|
|
9
10
|
/**
|
|
10
11
|
* Look up the registered AccountData for a given wxa account ID.
|
|
@@ -52,7 +53,7 @@ export async function getTokenPoolData(client, args) {
|
|
|
52
53
|
package: client.config.packages.waterx_perp_view.published_at,
|
|
53
54
|
arguments: {
|
|
54
55
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
55
|
-
tokenIndex: args.tokenIndex,
|
|
56
|
+
tokenIndex: toU64(args.tokenIndex, "tokenIndex"),
|
|
56
57
|
},
|
|
57
58
|
typeArguments: [withLp(client, args.lpType)],
|
|
58
59
|
})(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>;
|
|
@@ -5,8 +5,16 @@
|
|
|
5
5
|
import { bcs } from "@mysten/sui/bcs";
|
|
6
6
|
import { Transaction } from "@mysten/sui/transactions";
|
|
7
7
|
import { getAccountOrders as getAccountOrdersCall, getAccountPositions as getAccountPositionsCall, getMarketOrders as getMarketOrdersCall, getMarketPositions as getMarketPositionsCall, getRedeemRequests as getRedeemRequestsCall, OrderData, orderData as orderDataCall, PositionData, positionData as positionDataCall, positionExists as positionExistsCall, RedeemRequestData, } from "../../generated/waterx_perp_view/view.js";
|
|
8
|
+
import { parseWholeDollarU64, toU8, toU64, toU128, } from "../../utils/validate.js";
|
|
8
9
|
import { DRY_RUN_SENDER } from "../constants.js";
|
|
9
10
|
import { simulateAndExtract, toBytes, withLp } from "./simulate.js";
|
|
11
|
+
// The whole-dollar USD price domain is a pure numeric guard with no chain/fetch
|
|
12
|
+
// dependency, so it lives with the rest of that vocabulary in
|
|
13
|
+
// `utils/validate.ts`. It is re-exported HERE — unchanged — because this module
|
|
14
|
+
// is its published home: `perp/fetch` → `@waterx/sdk`. Every read param below
|
|
15
|
+
// is typed `WholeDollarUsdPrice`, so the type and its parser stay one hop from
|
|
16
|
+
// the functions that consume them.
|
|
17
|
+
export { parseWholeDollarU64 };
|
|
10
18
|
export async function positionExists(client, args) {
|
|
11
19
|
const tx = new Transaction();
|
|
12
20
|
positionExistsCall({
|
|
@@ -14,7 +22,7 @@ export async function positionExists(client, args) {
|
|
|
14
22
|
arguments: {
|
|
15
23
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
16
24
|
ticker: args.ticker,
|
|
17
|
-
positionId: args.positionId,
|
|
25
|
+
positionId: toU64(args.positionId, "positionId"),
|
|
18
26
|
},
|
|
19
27
|
typeArguments: [withLp(client, args.lpType)],
|
|
20
28
|
})(tx);
|
|
@@ -29,9 +37,9 @@ export async function getPosition(client, args) {
|
|
|
29
37
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
30
38
|
ticker: args.ticker,
|
|
31
39
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
32
|
-
basePriceUsd: args.basePriceUsd,
|
|
33
|
-
collateralPriceUsd: args.collateralPriceUsd,
|
|
34
|
-
positionId: args.positionId,
|
|
40
|
+
basePriceUsd: toU64(args.basePriceUsd, "basePriceUsd"),
|
|
41
|
+
collateralPriceUsd: toU64(args.collateralPriceUsd, "collateralPriceUsd"),
|
|
42
|
+
positionId: toU64(args.positionId, "positionId"),
|
|
35
43
|
},
|
|
36
44
|
typeArguments: [withLp(client, args.lpType)],
|
|
37
45
|
})(tx);
|
|
@@ -44,10 +52,10 @@ export async function getOrder(client, args) {
|
|
|
44
52
|
arguments: {
|
|
45
53
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
46
54
|
ticker: args.ticker,
|
|
47
|
-
basePriceUsd: args.basePriceUsd,
|
|
48
|
-
orderTypeTag: args.orderTypeTag,
|
|
49
|
-
triggerPrice: args.triggerPrice,
|
|
50
|
-
orderId: args.orderId,
|
|
55
|
+
basePriceUsd: toU64(args.basePriceUsd, "basePriceUsd"),
|
|
56
|
+
orderTypeTag: toU8(args.orderTypeTag, "orderTypeTag"),
|
|
57
|
+
triggerPrice: toU128(args.triggerPrice, "triggerPrice"),
|
|
58
|
+
orderId: toU64(args.orderId, "orderId"),
|
|
51
59
|
},
|
|
52
60
|
typeArguments: [withLp(client, args.lpType)],
|
|
53
61
|
})(tx);
|
|
@@ -60,9 +68,9 @@ export async function getMarketOrders(client, args) {
|
|
|
60
68
|
arguments: {
|
|
61
69
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
62
70
|
ticker: args.ticker,
|
|
63
|
-
basePriceUsd: args.basePriceUsd ?? 0n,
|
|
64
|
-
cursor: args.cursor ?? 0n,
|
|
65
|
-
pageSize: args.pageSize ?? 100n,
|
|
71
|
+
basePriceUsd: toU64(args.basePriceUsd ?? 0n, "basePriceUsd"),
|
|
72
|
+
cursor: toU64(args.cursor ?? 0n, "cursor"),
|
|
73
|
+
pageSize: toU64(args.pageSize ?? 100n, "pageSize"),
|
|
66
74
|
},
|
|
67
75
|
typeArguments: [withLp(client, args.lpType)],
|
|
68
76
|
})(tx);
|
|
@@ -94,10 +102,10 @@ export async function getMarketPositions(client, args) {
|
|
|
94
102
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
95
103
|
ticker: args.ticker,
|
|
96
104
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
97
|
-
basePriceUsd: args.basePriceUsd,
|
|
98
|
-
collateralPriceUsd: args.collateralPriceUsd ?? 0n,
|
|
99
|
-
cursor: args.cursor ?? 0n,
|
|
100
|
-
pageSize: args.pageSize ?? 100n,
|
|
105
|
+
basePriceUsd: toU64(args.basePriceUsd, "basePriceUsd"),
|
|
106
|
+
collateralPriceUsd: toU64(args.collateralPriceUsd ?? 0n, "collateralPriceUsd"),
|
|
107
|
+
cursor: toU64(args.cursor ?? 0n, "cursor"),
|
|
108
|
+
pageSize: toU64(args.pageSize ?? 100n, "pageSize"),
|
|
101
109
|
},
|
|
102
110
|
typeArguments: [withLp(client, args.lpType)],
|
|
103
111
|
})(tx);
|
|
@@ -130,8 +138,8 @@ export async function getAccountPositions(client, args) {
|
|
|
130
138
|
ticker: args.ticker,
|
|
131
139
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
132
140
|
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
133
|
-
basePriceUsd: args.basePriceUsd,
|
|
134
|
-
collateralPriceUsd: args.collateralPriceUsd ?? 0n,
|
|
141
|
+
basePriceUsd: toU64(args.basePriceUsd, "basePriceUsd"),
|
|
142
|
+
collateralPriceUsd: toU64(args.collateralPriceUsd ?? 0n, "collateralPriceUsd"),
|
|
135
143
|
accountObjectAddress: args.accountObjectAddress,
|
|
136
144
|
},
|
|
137
145
|
typeArguments: [withLp(client, args.lpType)],
|
|
@@ -145,7 +153,7 @@ export async function getAccountOrders(client, args) {
|
|
|
145
153
|
arguments: {
|
|
146
154
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
147
155
|
ticker: args.ticker,
|
|
148
|
-
basePriceUsd: args.basePriceUsd ?? 0n,
|
|
156
|
+
basePriceUsd: toU64(args.basePriceUsd ?? 0n, "basePriceUsd"),
|
|
149
157
|
accountObjectAddress: args.accountObjectAddress,
|
|
150
158
|
},
|
|
151
159
|
typeArguments: [withLp(client, args.lpType)],
|
|
@@ -158,8 +166,8 @@ export async function getRedeemRequests(client, args = {}) {
|
|
|
158
166
|
package: client.config.packages.waterx_perp_view.published_at,
|
|
159
167
|
arguments: {
|
|
160
168
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
161
|
-
cursor: args.cursor ?? 0n,
|
|
162
|
-
pageSize: args.pageSize ?? 100n,
|
|
169
|
+
cursor: toU64(args.cursor ?? 0n, "cursor"),
|
|
170
|
+
pageSize: toU64(args.pageSize ?? 100n, "pageSize"),
|
|
163
171
|
},
|
|
164
172
|
typeArguments: [withLp(client, args.lpType)],
|
|
165
173
|
})(tx);
|
package/dist/src/perp/index.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export { PerpClient } from "./client.ts";
|
|
2
2
|
export type { CreateClientOptions } from "./client.ts";
|
|
3
|
-
export { PYTH_DEFAULTS,
|
|
4
|
-
export type { BasePackageEntry, ConstantFeedEntry, WaterxReferralPackage, LoadConfigOptions, NativeCustodyAsset, NativeCustodyPackage,
|
|
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,
|
|
3
|
+
export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, loadConfig } from "./config.ts";
|
|
4
|
+
export type { BasePackageEntry, ConstantFeedEntry, WaterxReferralPackage, LoadConfigOptions, NativeCustodyAsset, NativeCustodyPackage, PythFetchPolicy, PythInfraConfig, PythLazerRulePackage, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, TestnetFaucetPackage, WaterXConfig, WaterXPackages, WaterxCreditPackage, WaterxOraclePackage, WaterxPerpMarketEntry, WaterxPerpPackage, WaterxStakingPackage, WithdrawalQueuePackage, WlpPackage, WormholeBridgePackage, WormholeInfraConfig, WxaAccountPackage, } from "./config.ts";
|
|
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, DOUBLE_SCALE, DRY_RUN_SENDER, FLOAT_SCALE, 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, MS_PER_MINUTE, MS_PER_HOUR, 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";
|
|
8
|
-
export { annualizedApyFromRatio, annualizeFundingRate, calcBorrowRate, calcBorrowRateAccrual, calcDynamicFeeBps, calcEffectiveCollateralUsd, calcEstLiqPrice, calcFee, calcFundingFeeUsd, calcFundingRate, calcImpactFeeRate, calcLeverage, calcMaxReducibleCollateralUsd, calcNotional, calcPositionBorrowFee, calcTokenUtilizationBps, calcTotalTradingFeeRate, calcUnrealizedPnl, calcWlpIncentiveApy, calcWlpMintOut, calcWlpPrice, calcWlpRedeemOut, decodeFundingIndexDelta, rawPrice, } from "../utils/math.ts";
|
|
8
|
+
export { annualizedApyFromRatio, annualizeFundingRate, calcBorrowRate, calcBorrowRateAccrual, calcDynamicFeeBps, calcEffectiveCollateralUsd, calcEstLiqPrice, calcEstLiqPriceRaw, calcFee, calcFundingFeeUsd, calcFundingRate, calcImpactFeeRate, calcLeverage, calcMaxReducibleCollateralUsd, calcNotional, calcPositionBorrowFee, calcRealLiqNetCostUsd, calcTokenUtilizationBps, calcTotalTradingFeeRate, calcUnrealizedPnl, calcViewEstLiqFeesUsd, calcWlpIncentiveApy, calcWlpMintOut, calcWlpPrice, calcWlpRedeemOut, decodeFundingIndexDelta, rawPrice, } from "../utils/math.ts";
|
|
9
|
+
export type { ExactDecimalUsd, LiqFeeBundle, RawPriceInput } from "../utils/math.ts";
|
|
10
|
+
export { formatFundingInterval } from "../utils/format.ts";
|
|
11
|
+
export { calcEstLiqPriceRawFromView } from "./liq-view.ts";
|
|
12
|
+
export type { EstLiqPriceViewOpts } from "./liq-view.ts";
|
|
9
13
|
export * from "./user/index.ts";
|
|
10
14
|
export * from "./tx-builders.ts";
|
|
11
15
|
export * from "./fetch.ts";
|
package/dist/src/perp/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// ======== Core ========
|
|
2
2
|
export { PerpClient } from "./client.js";
|
|
3
|
-
export { PYTH_DEFAULTS,
|
|
3
|
+
export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, loadConfig } from "./config.js";
|
|
4
4
|
// ======== Constants & enums ========
|
|
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,
|
|
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, DOUBLE_SCALE, DRY_RUN_SENDER, FLOAT_SCALE, 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, MS_PER_MINUTE, MS_PER_HOUR, MS_PER_YEAR, SUI_DECIMALS, WLP_DECIMALS, COLLATERAL_DECIMALS, TOKEN_DECIMALS, } from "./constants.js";
|
|
6
6
|
// ======== Utilities ========
|
|
7
7
|
export { getMarketTickers, getCollateralAssets } from "../utils/config.js";
|
|
8
|
-
export { annualizedApyFromRatio, annualizeFundingRate, calcBorrowRate, calcBorrowRateAccrual, calcDynamicFeeBps, calcEffectiveCollateralUsd, calcEstLiqPrice, calcFee, calcFundingFeeUsd, calcFundingRate, calcImpactFeeRate, calcLeverage, calcMaxReducibleCollateralUsd, calcNotional, calcPositionBorrowFee, calcTokenUtilizationBps, calcTotalTradingFeeRate, calcUnrealizedPnl, calcWlpIncentiveApy, calcWlpMintOut, calcWlpPrice, calcWlpRedeemOut, decodeFundingIndexDelta, rawPrice, } from "../utils/math.js";
|
|
8
|
+
export { annualizedApyFromRatio, annualizeFundingRate, calcBorrowRate, calcBorrowRateAccrual, calcDynamicFeeBps, calcEffectiveCollateralUsd, calcEstLiqPrice, calcEstLiqPriceRaw, calcFee, calcFundingFeeUsd, calcFundingRate, calcImpactFeeRate, calcLeverage, calcMaxReducibleCollateralUsd, calcNotional, calcPositionBorrowFee, calcRealLiqNetCostUsd, calcTokenUtilizationBps, calcTotalTradingFeeRate, calcUnrealizedPnl, calcViewEstLiqFeesUsd, calcWlpIncentiveApy, calcWlpMintOut, calcWlpPrice, calcWlpRedeemOut, decodeFundingIndexDelta, rawPrice, } from "../utils/math.js";
|
|
9
|
+
export { formatFundingInterval } from "../utils/format.js";
|
|
10
|
+
export { calcEstLiqPriceRawFromView } from "./liq-view.js";
|
|
9
11
|
// ======== Transaction builders (user-side) ========
|
|
10
12
|
export * from "./user/index.js";
|
|
11
13
|
// ======== High-level Tx builders ========
|