@waterx/sdk 2.4.1 → 3.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 +25 -21
- package/dist/src/{utils → account}/account-request.d.ts +2 -2
- package/dist/src/{user → account}/account.d.ts +23 -21
- package/dist/src/{user → account}/account.js +5 -5
- package/dist/src/account/client.d.ts +42 -0
- package/dist/src/account/client.js +17 -0
- package/dist/src/account/config.d.ts +151 -0
- package/dist/src/account/config.js +8 -0
- package/dist/src/account/constants.d.ts +5 -0
- package/dist/src/account/constants.js +5 -0
- package/dist/src/account/fetch/referral.d.ts +15 -0
- package/dist/src/account/fetch/referral.js +51 -0
- package/dist/src/account/fetch/simulate.d.ts +34 -0
- package/dist/src/account/fetch/simulate.js +43 -0
- package/dist/src/{utils/consolidate-balance.d.ts → account/funding/balance.d.ts} +3 -8
- package/dist/src/{utils/consolidate-balance.js → account/funding/balance.js} +6 -1
- package/dist/src/account/funding/consolidate.d.ts +46 -0
- package/dist/src/account/funding/consolidate.js +137 -0
- package/dist/src/{user → account/funding}/credit.d.ts +10 -10
- package/dist/src/{user → account/funding}/credit.js +6 -6
- package/dist/src/{user → account/funding}/custody.d.ts +4 -4
- package/dist/src/{user → account/funding}/custody.js +2 -2
- package/dist/src/{utils → account/funding}/wormhole.d.ts +4 -4
- package/dist/src/{utils → account/funding}/wormhole.js +1 -1
- package/dist/src/account/index.d.ts +29 -0
- package/dist/src/account/index.js +29 -0
- package/dist/src/{user → account}/referral.d.ts +3 -3
- package/dist/src/{user → account}/referral.js +1 -1
- package/dist/src/base-client.d.ts +74 -0
- package/dist/src/base-client.js +97 -0
- package/dist/src/constants.d.ts +4 -46
- package/dist/src/constants.js +8 -52
- package/dist/src/generated/bucket_v2_framework/liability.d.ts +0 -26
- package/dist/src/generated/bucket_v2_framework/liability.js +0 -28
- package/dist/src/generated/waterx_account/account.d.ts +50 -15
- package/dist/src/generated/waterx_account/account.js +51 -15
- package/dist/src/generated/waterx_oracle/oracle.d.ts +7 -1
- package/dist/src/generated/waterx_oracle/oracle.js +7 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.d.ts +19 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.d.ts +3 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/sui/balance.d.ts +3 -1
- package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.d.ts +6 -1
- package/dist/src/generated/waterx_prediction/events.d.ts +288 -0
- package/dist/src/{prediction/generated → generated}/waterx_prediction/events.js +39 -0
- package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.d.ts +6 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/order.d.ts +34 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/position.d.ts +16 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/view.d.ts +69 -4
- package/dist/src/{prediction/generated → generated}/waterx_prediction/waterx_prediction.d.ts +162 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/waterx_prediction.js +99 -0
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +102 -0
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +99 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.d.ts +5 -5
- package/dist/src/generated/waterx_supra_rule/supra_rule.js +1 -2
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +23 -23
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +3 -6
- package/dist/src/oracle/aggregate.d.ts +74 -0
- package/dist/src/oracle/aggregate.js +112 -0
- package/dist/src/oracle/config.d.ts +99 -0
- package/dist/src/oracle/config.js +23 -0
- package/dist/src/oracle/host.d.ts +32 -0
- package/dist/src/oracle/host.js +10 -0
- package/dist/src/oracle/index.d.ts +16 -0
- package/dist/src/oracle/index.js +18 -0
- package/dist/src/oracle/pyth.d.ts +52 -0
- package/dist/src/oracle/pyth.js +220 -0
- package/dist/src/oracle/rules/constant-rule.d.ts +9 -0
- package/dist/src/oracle/rules/constant-rule.js +14 -0
- package/dist/src/oracle/rules/pyth-rule.d.ts +11 -0
- package/dist/src/oracle/rules/pyth-rule.js +20 -0
- package/dist/src/oracle/rules/sponsor.d.ts +28 -0
- package/dist/src/oracle/rules/sponsor.js +48 -0
- package/dist/src/oracle/rules/supra-rule.d.ts +11 -0
- package/dist/src/oracle/rules/supra-rule.js +22 -0
- package/dist/src/perp/client.d.ts +78 -0
- package/dist/src/perp/client.js +108 -0
- package/dist/src/{client.d.ts → perp/config-view.d.ts} +15 -60
- package/dist/src/{client.js → perp/config-view.js} +23 -95
- package/dist/src/perp/config.d.ts +126 -0
- package/dist/src/{config.js → perp/config.js} +11 -12
- package/dist/src/perp/constants.d.ts +49 -0
- package/dist/src/perp/constants.js +61 -0
- package/dist/src/perp/fetch/account.d.ts +43 -0
- package/dist/src/perp/fetch/account.js +64 -0
- package/dist/src/perp/fetch/bridge.d.ts +90 -0
- package/dist/src/perp/fetch/bridge.js +127 -0
- package/dist/src/perp/fetch/custody.d.ts +32 -0
- package/dist/src/perp/fetch/custody.js +62 -0
- package/dist/src/perp/fetch/market.d.ts +30 -0
- package/dist/src/perp/fetch/market.js +68 -0
- package/dist/src/perp/fetch/positions.d.ts +70 -0
- package/dist/src/perp/fetch/positions.js +185 -0
- package/dist/src/perp/fetch/simulate.d.ts +12 -0
- package/dist/src/perp/fetch/simulate.js +13 -0
- package/dist/src/perp/fetch.d.ts +23 -0
- package/dist/src/perp/fetch.js +23 -0
- package/dist/src/{index.d.ts → perp/index.d.ts} +21 -21
- package/dist/src/{index.js → perp/index.js} +21 -21
- package/dist/src/perp/tx-builders/common.d.ts +83 -0
- package/dist/src/perp/tx-builders/common.js +70 -0
- package/dist/src/perp/tx-builders/credit.d.ts +65 -0
- package/dist/src/perp/tx-builders/credit.js +62 -0
- package/dist/src/perp/tx-builders/rewards.d.ts +30 -0
- package/dist/src/perp/tx-builders/rewards.js +34 -0
- package/dist/src/perp/tx-builders/trading.d.ts +51 -0
- package/dist/src/perp/tx-builders/trading.js +59 -0
- package/dist/src/perp/tx-builders/wlp.d.ts +90 -0
- package/dist/src/perp/tx-builders/wlp.js +120 -0
- package/dist/src/perp/tx-builders.d.ts +23 -0
- package/dist/src/perp/tx-builders.js +23 -0
- package/dist/src/perp/user/index.d.ts +8 -0
- package/dist/src/perp/user/index.js +8 -0
- package/dist/src/{user → perp/user}/order.d.ts +7 -7
- package/dist/src/{user → perp/user}/order.js +3 -3
- package/dist/src/{user → perp/user}/staking.d.ts +4 -4
- package/dist/src/{user → perp/user}/staking.js +2 -2
- package/dist/src/{user → perp/user}/trading.d.ts +13 -13
- package/dist/src/{user → perp/user}/trading.js +2 -2
- package/dist/src/{user → perp/user}/wlp.d.ts +7 -7
- package/dist/src/{user → perp/user}/wlp.js +3 -3
- package/dist/src/prediction/account.js +40 -76
- package/dist/src/prediction/client.d.ts +8 -38
- package/dist/src/prediction/client.js +11 -67
- package/dist/src/prediction/config.d.ts +16 -2
- package/dist/src/prediction/config.js +10 -4
- package/dist/src/prediction/index.d.ts +11 -11
- package/dist/src/prediction/index.js +10 -10
- package/dist/src/prediction/prediction.d.ts +45 -0
- package/dist/src/prediction/prediction.js +71 -0
- package/dist/src/prediction/tx-builders.d.ts +4 -4
- package/dist/src/prediction/tx-builders.js +2 -2
- package/dist/src/prediction/user/index.d.ts +2 -2
- package/dist/src/prediction/user/index.js +1 -1
- package/dist/src/prediction/user/position.d.ts +2 -2
- package/dist/src/prediction/user/position.js +1 -1
- package/dist/src/prediction/utils/bcs.d.ts +5 -0
- package/dist/src/prediction/utils/bcs.js +5 -0
- package/dist/src/prediction/utils/index.d.ts +7 -0
- package/dist/src/prediction/utils/index.js +7 -0
- package/dist/src/sdk.d.ts +10 -6
- package/dist/src/sdk.js +9 -5
- package/dist/src/unified-client.d.ts +140 -145
- package/dist/src/unified-client.js +98 -40
- package/dist/src/utils/config.d.ts +1 -1
- package/package.json +22 -5
- package/dist/src/config.d.ts +0 -292
- package/dist/src/fetch.d.ts +0 -254
- package/dist/src/fetch.js +0 -564
- package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +0 -100
- package/dist/src/prediction/generated/bucket_v2_framework/account.js +0 -129
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +0 -6
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +0 -19
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +0 -10
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +0 -36
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +0 -27
- package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +0 -382
- package/dist/src/prediction/generated/bucket_v2_framework/double.js +0 -466
- package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +0 -362
- package/dist/src/prediction/generated/bucket_v2_framework/float.js +0 -440
- package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +0 -193
- package/dist/src/prediction/generated/bucket_v2_framework/liability.js +0 -205
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +0 -384
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +0 -382
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +0 -344
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +0 -338
- package/dist/src/prediction/generated/utils/index.d.ts +0 -30
- package/dist/src/prediction/generated/utils/index.js +0 -160
- package/dist/src/prediction/generated/waterx_account/account.d.ts +0 -1589
- package/dist/src/prediction/generated/waterx_account/account.js +0 -1758
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +0 -7
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +0 -13
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +0 -7
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +0 -16
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +0 -6
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +0 -19
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +0 -10
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +0 -14
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +0 -12
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +0 -19
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +0 -36
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +0 -27
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +0 -16
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +0 -19
- package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +0 -75
- package/dist/src/prediction/generated/waterx_account/direct_rule.js +0 -78
- package/dist/src/prediction/generated/waterx_account/events.d.ts +0 -33
- package/dist/src/prediction/generated/waterx_account/events.js +0 -137
- package/dist/src/prediction/generated/waterx_account/version.js +0 -8
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +0 -60
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +0 -83
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +0 -14
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +0 -24
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +0 -31
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +0 -16
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +0 -19
- package/dist/src/prediction/generated/waterx_prediction/events.d.ts +0 -22
- package/dist/src/prediction/generated/waterx_prediction/version.d.ts +0 -10
- package/dist/src/tx-builders.d.ts +0 -296
- package/dist/src/tx-builders.js +0 -461
- package/dist/src/user/index.d.ts +0 -8
- package/dist/src/user/index.js +0 -8
- package/dist/src/utils/pyth.d.ts +0 -124
- package/dist/src/utils/pyth.js +0 -392
- /package/dist/src/{utils → account}/account-request.js +0 -0
- /package/dist/src/{core → account}/waterx-account.d.ts +0 -0
- /package/dist/src/{core → account}/waterx-account.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.js +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/balance.js +0 -0
- /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.js +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.d.ts +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/order.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/position.js +0 -0
- /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/version.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/version.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/view.js +0 -0
|
@@ -1,100 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Perp config-schema views — read-only lookups over the parsed `waterx-config`
|
|
3
|
+
* JSON, with no transport dependency.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
* `
|
|
5
|
+
* Split off the transport client (`PerpClient`) so the two responsibilities stay
|
|
6
|
+
* separate: `BaseLineClient` owns the gRPC half, this class owns the
|
|
7
|
+
* canonical-schema half. `PerpClient` composes one of these and delegates, so
|
|
8
|
+
* callers keep calling `client.getMarket(...)` / `client.wlpType()` unchanged.
|
|
9
|
+
* Tested in isolation against a plain config object — no network needed.
|
|
6
10
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
pyth;
|
|
23
|
-
/** Wormhole infra for the credit bridge (network defaults unless overridden). */
|
|
24
|
-
wormhole;
|
|
25
|
-
constructor(network, config, opts = {}) {
|
|
26
|
-
this.network = network;
|
|
27
|
-
this.config = config;
|
|
28
|
-
this.pyth = config.pyth ?? PYTH_DEFAULTS[network];
|
|
29
|
-
this.wormhole = config.wormhole ?? WORMHOLE_DEFAULTS[network];
|
|
30
|
-
const grpcUrl = opts.grpcUrl ?? config.grpcUrl ?? DEFAULT_GRPC_URLS[network];
|
|
31
|
-
this.grpcClient = new SuiGrpcClient({
|
|
32
|
-
baseUrl: grpcUrl,
|
|
33
|
-
network: network.toLowerCase(),
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Async factory: fetches the deployment config for `network` and returns
|
|
38
|
-
* a ready-to-use client. Pass `opts.cache=true` to memoize the JSON.
|
|
39
|
-
*/
|
|
40
|
-
static async create(network, opts = {}) {
|
|
41
|
-
const config = await loadConfig(network, opts);
|
|
42
|
-
return new WaterXClient(network, config, { grpcUrl: opts.grpcUrl });
|
|
43
|
-
}
|
|
44
|
-
static mainnet(opts = {}) {
|
|
45
|
-
return WaterXClient.create("MAINNET", opts);
|
|
46
|
-
}
|
|
47
|
-
static testnet(opts = {}) {
|
|
48
|
-
return WaterXClient.create("TESTNET", opts);
|
|
49
|
-
}
|
|
50
|
-
// ========================================================
|
|
51
|
-
// gRPC convenience wrappers
|
|
52
|
-
// ========================================================
|
|
53
|
-
getObject(objectId) {
|
|
54
|
-
return this.grpcClient.getObject({ objectId });
|
|
55
|
-
}
|
|
56
|
-
getObjects(objectIds) {
|
|
57
|
-
return this.grpcClient.getObjects({ objectIds });
|
|
58
|
-
}
|
|
59
|
-
listOwnedObjects(owner) {
|
|
60
|
-
return this.grpcClient.listOwnedObjects({ owner });
|
|
61
|
-
}
|
|
62
|
-
listCoins(params) {
|
|
63
|
-
return this.grpcClient.listCoins(params);
|
|
64
|
-
}
|
|
65
|
-
getBalance(params) {
|
|
66
|
-
return this.grpcClient.getBalance(params);
|
|
67
|
-
}
|
|
68
|
-
listDynamicFields(parentId) {
|
|
69
|
-
return this.grpcClient.listDynamicFields({ parentId });
|
|
70
|
-
}
|
|
71
|
-
getDynamicField(parentId, name) {
|
|
72
|
-
return this.grpcClient.getDynamicField({ parentId, name });
|
|
73
|
-
}
|
|
74
|
-
waitForTransaction(digest) {
|
|
75
|
-
return this.grpcClient.waitForTransaction({ digest });
|
|
76
|
-
}
|
|
77
|
-
async simulate(tx) {
|
|
78
|
-
return this.grpcClient.simulateTransaction({
|
|
79
|
-
transaction: tx,
|
|
80
|
-
include: { commandResults: true },
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
async signAndExecuteTransaction(params) {
|
|
84
|
-
return this.grpcClient.signAndExecuteTransaction(params);
|
|
85
|
-
}
|
|
86
|
-
// ========================================================
|
|
87
|
-
// Shorthand accessors (canonical-schema lookups)
|
|
88
|
-
// ========================================================
|
|
89
|
-
/** All package IDs (`published_at`) keyed by package name. */
|
|
90
|
-
packageIds() {
|
|
91
|
-
const out = {};
|
|
92
|
-
for (const [name, pkg] of Object.entries(this.config.packages)) {
|
|
93
|
-
if (pkg && typeof pkg === "object" && "published_at" in pkg && pkg.published_at) {
|
|
94
|
-
out[name] = pkg.published_at;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return out;
|
|
11
|
+
export class PerpConfigView {
|
|
12
|
+
getConfig;
|
|
13
|
+
getWormhole;
|
|
14
|
+
// Config/wormhole are read through providers, not captured by value, so a later
|
|
15
|
+
// `client.config = …` reassignment stays live (matches the pre-split behaviour
|
|
16
|
+
// where every lookup read `this.config` fresh).
|
|
17
|
+
constructor(getConfig, getWormhole) {
|
|
18
|
+
this.getConfig = getConfig;
|
|
19
|
+
this.getWormhole = getWormhole;
|
|
20
|
+
}
|
|
21
|
+
get config() {
|
|
22
|
+
return this.getConfig();
|
|
23
|
+
}
|
|
24
|
+
get wormhole() {
|
|
25
|
+
return this.getWormhole();
|
|
98
26
|
}
|
|
99
27
|
/** `waterx_perp.markets[ticker]`, throws if unknown. */
|
|
100
28
|
getMarket(ticker) {
|
|
@@ -224,7 +152,7 @@ export class WaterXClient {
|
|
|
224
152
|
}
|
|
225
153
|
/**
|
|
226
154
|
* Sui Wormhole `State` object id — prefers the per-deployment
|
|
227
|
-
* `wormhole_bridge.wormhole_state`, falls back to `
|
|
155
|
+
* `wormhole_bridge.wormhole_state`, falls back to the line's `wormhole` infra.
|
|
228
156
|
*/
|
|
229
157
|
wormholeStateId() {
|
|
230
158
|
return this.config.packages.wormhole_bridge?.wormhole_state ?? this.wormhole.state_id;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WaterX deployment config — fetched at client init from the canonical
|
|
3
|
+
* `waterx-config` repo (default: GitHub raw).
|
|
4
|
+
*
|
|
5
|
+
* The schema mirrors the canonical JSON layout one-to-one (each package
|
|
6
|
+
* groups its own object IDs + per-ticker maps). External chain infra
|
|
7
|
+
* (Pyth state, Wormhole state/core, Hermes & Wormholescan endpoints) is
|
|
8
|
+
* **not** in the JSON — it lives in `PYTH_DEFAULTS` / `WORMHOLE_DEFAULTS`
|
|
9
|
+
* below, keyed by network.
|
|
10
|
+
*/
|
|
11
|
+
import type { AccountPackages, BasePackageEntry, WormholeInfraConfig } from "../account/config.ts";
|
|
12
|
+
import type { OraclePackages, PythInfraConfig } from "../oracle/config.ts";
|
|
13
|
+
import type { Network } from "./constants.ts";
|
|
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";
|
|
17
|
+
export interface WaterxPerpMarketEntry {
|
|
18
|
+
market: string;
|
|
19
|
+
config: string;
|
|
20
|
+
}
|
|
21
|
+
export interface WaterxPerpPackage extends BasePackageEntry {
|
|
22
|
+
admin_cap: string;
|
|
23
|
+
global_config: string;
|
|
24
|
+
market_registry_wlp: string;
|
|
25
|
+
markets: Record<string, WaterxPerpMarketEntry>;
|
|
26
|
+
}
|
|
27
|
+
export interface RewarderEntry {
|
|
28
|
+
/** `Rewarder<STAKE, R>` shared object ID. */
|
|
29
|
+
rewarder_id: string;
|
|
30
|
+
/** Fully-qualified reward coin Move type (e.g. `0x2::sui::SUI`). */
|
|
31
|
+
coin_type: string;
|
|
32
|
+
/** Reward coin display decimals. */
|
|
33
|
+
decimals: number;
|
|
34
|
+
}
|
|
35
|
+
export interface WaterxStakingPackage extends BasePackageEntry {
|
|
36
|
+
admin_cap?: string;
|
|
37
|
+
/** Map of stake-type alias (e.g. `"WLP"`) → `StakingPool<STAKE>` shared object ID. */
|
|
38
|
+
pools?: Record<string, string>;
|
|
39
|
+
/**
|
|
40
|
+
* Map of stake-type alias → reward-token alias → rewarder metadata.
|
|
41
|
+
* Reward-token alias is display-only (e.g. `"SUI"`, `"MOCK_SUI"`); the
|
|
42
|
+
* fully-qualified coin Move type lives on the {@link RewarderEntry}.
|
|
43
|
+
*/
|
|
44
|
+
rewarders?: Record<string, Record<string, RewarderEntry>>;
|
|
45
|
+
}
|
|
46
|
+
export interface WlpPackage extends BasePackageEntry {
|
|
47
|
+
metadata_cap?: string;
|
|
48
|
+
currency?: string;
|
|
49
|
+
wlp_pool: string;
|
|
50
|
+
/** Optional `WlpAum<LP>` shared object; required by `mint_wlp` / `settle_redeem`. */
|
|
51
|
+
wlp_aum?: string;
|
|
52
|
+
/** Map of oracle ticker → fully-qualified Move type registered via `lp_pool::add_token`. */
|
|
53
|
+
pool_tokens: Record<string, string>;
|
|
54
|
+
}
|
|
55
|
+
export interface MockCoinPackage extends BasePackageEntry {
|
|
56
|
+
currency?: string;
|
|
57
|
+
treasury_cap?: string;
|
|
58
|
+
metadata_cap?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface TestnetFaucetPackage {
|
|
61
|
+
published_at: string;
|
|
62
|
+
whitelist?: string[];
|
|
63
|
+
faucet?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface WaterXPackages extends AccountPackages, OraclePackages {
|
|
66
|
+
waterx_perp: WaterxPerpPackage;
|
|
67
|
+
waterx_perp_view: BasePackageEntry;
|
|
68
|
+
waterx_staking?: WaterxStakingPackage;
|
|
69
|
+
wlp: WlpPackage;
|
|
70
|
+
testnet_faucet?: TestnetFaucetPackage;
|
|
71
|
+
mock_usdc?: MockCoinPackage;
|
|
72
|
+
mock_usdsui?: MockCoinPackage;
|
|
73
|
+
mock_sui?: MockCoinPackage;
|
|
74
|
+
waterx_rule?: BasePackageEntry;
|
|
75
|
+
waterx_rule_nautilus_enclave?: BasePackageEntry;
|
|
76
|
+
}
|
|
77
|
+
export declare const WORMHOLE_DEFAULTS: Record<Network, WormholeInfraConfig>;
|
|
78
|
+
export interface WaterXConfig {
|
|
79
|
+
/** Absent on credit-only deployment files. */
|
|
80
|
+
network?: "mainnet" | "testnet";
|
|
81
|
+
chain_id?: string | number | null;
|
|
82
|
+
/** Sui gRPC base URL (default: public Mysten fullnode for the network). */
|
|
83
|
+
grpcUrl?: string;
|
|
84
|
+
packages: WaterXPackages;
|
|
85
|
+
/** Pyth infra override (defaults from `PYTH_DEFAULTS[network]`). */
|
|
86
|
+
pyth?: PythInfraConfig;
|
|
87
|
+
/** Wormhole infra override (defaults from `WORMHOLE_DEFAULTS[network]`). */
|
|
88
|
+
wormhole?: WormholeInfraConfig;
|
|
89
|
+
/** Sui `CoinRegistry` shared object (credit deployments). */
|
|
90
|
+
coin_registry?: string;
|
|
91
|
+
/** Per-module credit supply caps (credit deployments). */
|
|
92
|
+
credit_caps?: Record<string, string>;
|
|
93
|
+
/** Deploy-script phase completion flags (credit deployments). */
|
|
94
|
+
done?: Record<string, boolean>;
|
|
95
|
+
}
|
|
96
|
+
export interface LoadConfigOptions {
|
|
97
|
+
/**
|
|
98
|
+
* Override the default config URL. Use this to point at a staging branch
|
|
99
|
+
* (`?ref=staging`) or a local mirror during development. Takes precedence
|
|
100
|
+
* over {@link configRef}.
|
|
101
|
+
*/
|
|
102
|
+
configUrl?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Pin the canonical config to a specific git ref — a commit SHA, branch,
|
|
105
|
+
* or tag — instead of the default `main` branch. Resolves to
|
|
106
|
+
* `https://raw.githubusercontent.com/WaterXProtocol/waterx-config/<ref>/<network>.json`.
|
|
107
|
+
* Ignored when {@link configUrl} is set.
|
|
108
|
+
*/
|
|
109
|
+
configRef?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Reuse a previously-fetched config from the in-memory cache (keyed by
|
|
112
|
+
* the effective URL). Default: false (always fetch fresh).
|
|
113
|
+
*/
|
|
114
|
+
cache?: boolean;
|
|
115
|
+
/** Optional fetch implementation (for tests or environments without global `fetch`). */
|
|
116
|
+
fetchImpl?: typeof fetch;
|
|
117
|
+
/** Optional request timeout in ms. Default 10_000. */
|
|
118
|
+
timeoutMs?: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Build the canonical config URL for `network`, optionally pinned to a
|
|
122
|
+
* specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
|
|
123
|
+
*/
|
|
124
|
+
export declare function defaultConfigUrl(network: Network, ref?: string): string;
|
|
125
|
+
export declare function clearConfigCache(): void;
|
|
126
|
+
export declare function loadConfig(network: Network, opts?: LoadConfigOptions): Promise<WaterXConfig>;
|
|
@@ -8,18 +8,17 @@
|
|
|
8
8
|
* **not** in the JSON — it lives in `PYTH_DEFAULTS` / `WORMHOLE_DEFAULTS`
|
|
9
9
|
* below, keyed by network.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
11
|
+
export { PYTH_DEFAULTS } from "../oracle/config.js";
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Wormhole / Hermes — external chain infra, defaults by network
|
|
14
|
+
// ============================================================================
|
|
15
|
+
//
|
|
16
|
+
// `PythInfraConfig` + `PYTH_DEFAULTS` live in `oracle/config.ts` (shared infra)
|
|
17
|
+
// and are re-exported at the top of this file.
|
|
18
|
+
// `WormholeInfraConfig` is defined in `account/config.ts` (funding base) and
|
|
19
|
+
// re-exported at the top of this file. `state_id` is the same shared Sui
|
|
20
|
+
// Wormhole `State` object Pyth uses (kept in sync with
|
|
21
|
+
// `PYTH_DEFAULTS[*].wormhole_state_id`).
|
|
23
22
|
export const WORMHOLE_DEFAULTS = {
|
|
24
23
|
MAINNET: {
|
|
25
24
|
state_id: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
export declare const PERM_OPEN_POSITION = 1;
|
|
9
|
+
export declare const PERM_CLOSE_POSITION = 2;
|
|
10
|
+
export declare const PERM_INCREASE_POSITION = 4;
|
|
11
|
+
export declare const PERM_DECREASE_POSITION = 8;
|
|
12
|
+
export declare const PERM_PLACE_ORDER = 16;
|
|
13
|
+
export declare const PERM_CANCEL_ORDER = 32;
|
|
14
|
+
export declare const PERM_DEPOSIT_COLLATERAL = 64;
|
|
15
|
+
export declare const PERM_WITHDRAW_COLLATERAL = 128;
|
|
16
|
+
export declare const PERM_MINT_WLP = 256;
|
|
17
|
+
export declare const PERM_REDEEM_WLP = 512;
|
|
18
|
+
export declare const PERM_ALL_TRADING = 255;
|
|
19
|
+
export declare const PERM_ALL = 65535;
|
|
20
|
+
export declare const STAKING_PERM_DEPOSIT_STAKE: number;
|
|
21
|
+
export declare const STAKING_PERM_REDEEM_STAKE: number;
|
|
22
|
+
export declare const STAKING_PERM_CLAIM_REWARD: number;
|
|
23
|
+
export declare const STAKING_PERM_ALL: number;
|
|
24
|
+
export declare const ORDER_LIMIT_BUY = 0;
|
|
25
|
+
export declare const ORDER_LIMIT_SELL = 1;
|
|
26
|
+
export declare const ORDER_STOP_BUY = 2;
|
|
27
|
+
export declare const ORDER_STOP_SELL = 3;
|
|
28
|
+
/** Wildcard tag accepted by `cancel_order_request` — scans all 4 books. */
|
|
29
|
+
export declare const ORDER_TAG_WILDCARD = 255;
|
|
30
|
+
export declare const ACTION_OPEN_POSITION = 0;
|
|
31
|
+
export declare const ACTION_CLOSE_POSITION = 1;
|
|
32
|
+
export declare const ACTION_PLACE_ORDER = 2;
|
|
33
|
+
export declare const ACTION_CANCEL_ORDER = 3;
|
|
34
|
+
export declare const ACTION_DEPOSIT_COLLATERAL = 4;
|
|
35
|
+
export declare const ACTION_WITHDRAW_COLLATERAL = 5;
|
|
36
|
+
export declare const ACTION_LIQUIDATE = 6;
|
|
37
|
+
export declare const ACTION_INCREASE_POSITION = 7;
|
|
38
|
+
export declare const ACTION_DECREASE_POSITION = 8;
|
|
39
|
+
export declare const ACTION_UPDATE_ORDER = 9;
|
|
40
|
+
export declare const ACTION_CANCEL_PRE_ORDER = 10;
|
|
41
|
+
export declare const ACTION_ADD_PRE_ORDER = 11;
|
|
42
|
+
/**
|
|
43
|
+
* Well-known address of Sui's native funds-accumulator root shared object
|
|
44
|
+
* (`@0xacc` in the framework). Pass this to `request_deposit_from_funds<T>`
|
|
45
|
+
* to drain `Balance<T>` parked at an account's address. Defined in
|
|
46
|
+
* `account/constants.ts` (account-framework constant); re-exported here for
|
|
47
|
+
* back-compat.
|
|
48
|
+
*/
|
|
49
|
+
export { ACCUMULATOR_ROOT } from "../account/constants.ts";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Perp-line domain constants (trading permissions / order tags / action codes /
|
|
2
|
+
// fee rates / well-known addresses). Re-exports the shared primitives from
|
|
3
|
+
// `../constants.ts` so perp code and the `./perp` barrel get the full set from
|
|
4
|
+
// a single import.
|
|
5
|
+
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
|
+
// ======== Permission Bitmasks (matches account_data.move) ========
|
|
14
|
+
export const PERM_OPEN_POSITION = 1;
|
|
15
|
+
export const PERM_CLOSE_POSITION = 2;
|
|
16
|
+
export const PERM_INCREASE_POSITION = 4;
|
|
17
|
+
export const PERM_DECREASE_POSITION = 8;
|
|
18
|
+
export const PERM_PLACE_ORDER = 16;
|
|
19
|
+
export const PERM_CANCEL_ORDER = 32;
|
|
20
|
+
export const PERM_DEPOSIT_COLLATERAL = 64;
|
|
21
|
+
export const PERM_WITHDRAW_COLLATERAL = 128;
|
|
22
|
+
export const PERM_MINT_WLP = 256;
|
|
23
|
+
export const PERM_REDEEM_WLP = 512;
|
|
24
|
+
export const PERM_ALL_TRADING = 0xff;
|
|
25
|
+
export const PERM_ALL = 0xffff;
|
|
26
|
+
// ======== Staking Permission Bitmasks (matches waterx_staking.move) ========
|
|
27
|
+
export const STAKING_PERM_DEPOSIT_STAKE = 1 << 0;
|
|
28
|
+
export const STAKING_PERM_REDEEM_STAKE = 1 << 1;
|
|
29
|
+
export const STAKING_PERM_CLAIM_REWARD = 1 << 2;
|
|
30
|
+
export const STAKING_PERM_ALL = STAKING_PERM_DEPOSIT_STAKE | STAKING_PERM_REDEEM_STAKE | STAKING_PERM_CLAIM_REWARD;
|
|
31
|
+
// ======== Order Type Tags ========
|
|
32
|
+
export const ORDER_LIMIT_BUY = 0;
|
|
33
|
+
export const ORDER_LIMIT_SELL = 1;
|
|
34
|
+
export const ORDER_STOP_BUY = 2;
|
|
35
|
+
export const ORDER_STOP_SELL = 3;
|
|
36
|
+
/** Wildcard tag accepted by `cancel_order_request` — scans all 4 books. */
|
|
37
|
+
export const ORDER_TAG_WILDCARD = 255;
|
|
38
|
+
// ======== Action Type Constants (request.move) ========
|
|
39
|
+
export const ACTION_OPEN_POSITION = 0;
|
|
40
|
+
export const ACTION_CLOSE_POSITION = 1;
|
|
41
|
+
export const ACTION_PLACE_ORDER = 2;
|
|
42
|
+
export const ACTION_CANCEL_ORDER = 3;
|
|
43
|
+
export const ACTION_DEPOSIT_COLLATERAL = 4;
|
|
44
|
+
export const ACTION_WITHDRAW_COLLATERAL = 5;
|
|
45
|
+
export const ACTION_LIQUIDATE = 6;
|
|
46
|
+
export const ACTION_INCREASE_POSITION = 7;
|
|
47
|
+
export const ACTION_DECREASE_POSITION = 8;
|
|
48
|
+
export const ACTION_UPDATE_ORDER = 9;
|
|
49
|
+
export const ACTION_CANCEL_PRE_ORDER = 10;
|
|
50
|
+
export const ACTION_ADD_PRE_ORDER = 11;
|
|
51
|
+
// ======== Misc ========
|
|
52
|
+
// `DRY_RUN_SENDER` (zero-address simulate sender) is a shared primitive defined
|
|
53
|
+
// in `../constants.ts` and re-exported via the `export *` above.
|
|
54
|
+
/**
|
|
55
|
+
* Well-known address of Sui's native funds-accumulator root shared object
|
|
56
|
+
* (`@0xacc` in the framework). Pass this to `request_deposit_from_funds<T>`
|
|
57
|
+
* to drain `Balance<T>` parked at an account's address. Defined in
|
|
58
|
+
* `account/constants.ts` (account-framework constant); re-exported here for
|
|
59
|
+
* back-compat.
|
|
60
|
+
*/
|
|
61
|
+
export { ACCUMULATOR_ROOT } from "../account/constants.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wxa account reads (`waterx_account`) — work on credit-only deployments
|
|
3
|
+
* (which have no `waterx_perp_view`). Plus the inclusive spendable-credit read.
|
|
4
|
+
*/
|
|
5
|
+
import { type ParkedBackingAssetBalance } from "../../account/funding/balance.ts";
|
|
6
|
+
import type { PerpClient } from "../client.ts";
|
|
7
|
+
/**
|
|
8
|
+
* List the wxa account IDs owned by `owner` (`account::account_ids`).
|
|
9
|
+
* Returns `[]` when the owner has never created an account. Use this to
|
|
10
|
+
* resolve the `account_id` a cross-chain deposit must target before
|
|
11
|
+
* filling the EVM `suiRecipient` field.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getAccountsByOwner(client: PerpClient, owner: string): Promise<string[]>;
|
|
14
|
+
/**
|
|
15
|
+
* A wxa account's stored `Balance<T>` (`account::account_balance<T>`).
|
|
16
|
+
* `coinType` defaults to the deployment's CREDIT type — i.e. the bridged
|
|
17
|
+
* balance available to withdraw. Returns `0n` for an unknown coin type.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getAccountBalance(client: PerpClient, accountId: string, coinType?: string): Promise<bigint>;
|
|
20
|
+
/**
|
|
21
|
+
* Inclusive wxUSD credit an account can spend after the default async tx-builder
|
|
22
|
+
* pre-sweep (`appendConsolidateForSpend`).
|
|
23
|
+
*
|
|
24
|
+
* - `internalRaw` — stored `Balance<CREDIT>` (`getAccountBalance`).
|
|
25
|
+
* - `pendingBackingRaw` — native-custody backing assets (USDC, USDSUI, …)
|
|
26
|
+
* parked at the account's Sui address, rescaled to CREDIT decimals at the
|
|
27
|
+
* 1:1 PSM peg (same probe as `appendConsolidateToUsd`).
|
|
28
|
+
* - `pendingCreditAtAddressRaw` — CREDIT at the account address (accumulator +
|
|
29
|
+
* owned coins). Swept into the internal slot by `appendConsolidateAddressCredit`
|
|
30
|
+
* via `consumeDepositDirect`.
|
|
31
|
+
* - `totalRaw` — sum of the three components; matches post-
|
|
32
|
+
* `appendConsolidateForSpend` spendable balance for predict / perp
|
|
33
|
+
* builders with `consolidateToUsd: true` (default).
|
|
34
|
+
*/
|
|
35
|
+
export interface SpendableCreditBalance {
|
|
36
|
+
internalRaw: bigint;
|
|
37
|
+
pendingBackingRaw: bigint;
|
|
38
|
+
pendingCreditAtAddressRaw: bigint;
|
|
39
|
+
totalRaw: bigint;
|
|
40
|
+
/** Per-asset breakdown for the backing-asset probe (empty when nothing parked). */
|
|
41
|
+
parkedBacking: ParkedBackingAssetBalance[];
|
|
42
|
+
}
|
|
43
|
+
export declare function getSpendableCreditBalance(client: PerpClient, accountId: string): Promise<SpendableCreditBalance>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wxa account reads (`waterx_account`) — work on credit-only deployments
|
|
3
|
+
* (which have no `waterx_perp_view`). Plus the inclusive spendable-credit read.
|
|
4
|
+
*/
|
|
5
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
6
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
7
|
+
import { probeAddressCreditBalance, probeParkedBackingAssets, sumParkedBackingAsCreditRaw, } from "../../account/funding/balance.js";
|
|
8
|
+
import { accountBalance as accountBalanceCall, accountIds as accountIdsCall, } from "../../generated/waterx_account/account.js";
|
|
9
|
+
import { COLLATERAL_DECIMALS } from "../constants.js";
|
|
10
|
+
import { simulateAndExtract } from "./simulate.js";
|
|
11
|
+
/**
|
|
12
|
+
* List the wxa account IDs owned by `owner` (`account::account_ids`).
|
|
13
|
+
* Returns `[]` when the owner has never created an account. Use this to
|
|
14
|
+
* resolve the `account_id` a cross-chain deposit must target before
|
|
15
|
+
* filling the EVM `suiRecipient` field.
|
|
16
|
+
*/
|
|
17
|
+
export async function getAccountsByOwner(client, owner) {
|
|
18
|
+
const tx = new Transaction();
|
|
19
|
+
accountIdsCall({
|
|
20
|
+
package: client.config.packages.waterx_account.published_at,
|
|
21
|
+
arguments: {
|
|
22
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
23
|
+
owner,
|
|
24
|
+
},
|
|
25
|
+
})(tx);
|
|
26
|
+
const bytes = await simulateAndExtract(client, tx);
|
|
27
|
+
return bcs.vector(bcs.Address).parse(bytes);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A wxa account's stored `Balance<T>` (`account::account_balance<T>`).
|
|
31
|
+
* `coinType` defaults to the deployment's CREDIT type — i.e. the bridged
|
|
32
|
+
* balance available to withdraw. Returns `0n` for an unknown coin type.
|
|
33
|
+
*/
|
|
34
|
+
export async function getAccountBalance(client, accountId, coinType) {
|
|
35
|
+
const tx = new Transaction();
|
|
36
|
+
accountBalanceCall({
|
|
37
|
+
package: client.config.packages.waterx_account.published_at,
|
|
38
|
+
arguments: {
|
|
39
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
40
|
+
accountId,
|
|
41
|
+
},
|
|
42
|
+
typeArguments: [coinType ?? client.creditType()],
|
|
43
|
+
})(tx);
|
|
44
|
+
const bytes = await simulateAndExtract(client, tx);
|
|
45
|
+
return BigInt(bcs.u64().parse(bytes));
|
|
46
|
+
}
|
|
47
|
+
export async function getSpendableCreditBalance(client, accountId) {
|
|
48
|
+
const creditType = client.creditType();
|
|
49
|
+
const [internalRaw, parkedBacking, addressCredit] = await Promise.all([
|
|
50
|
+
getAccountBalance(client, accountId, creditType),
|
|
51
|
+
probeParkedBackingAssets(client, accountId),
|
|
52
|
+
probeAddressCreditBalance(client, accountId),
|
|
53
|
+
]);
|
|
54
|
+
const pendingBackingRaw = sumParkedBackingAsCreditRaw(parkedBacking, COLLATERAL_DECIMALS);
|
|
55
|
+
const pendingCreditAtAddressRaw = addressCredit.fundsRaw + addressCredit.coinsRaw;
|
|
56
|
+
const totalRaw = internalRaw + pendingBackingRaw + pendingCreditAtAddressRaw;
|
|
57
|
+
return {
|
|
58
|
+
internalRaw,
|
|
59
|
+
pendingBackingRaw,
|
|
60
|
+
pendingCreditAtAddressRaw,
|
|
61
|
+
totalRaw,
|
|
62
|
+
parkedBacking,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge reads: `wormhole_bridge` rate-limit / cap snapshot and the
|
|
3
|
+
* `withdrawal_queue` (Sui → EVM) fee estimate.
|
|
4
|
+
*/
|
|
5
|
+
import type { PerpClient } from "../client.ts";
|
|
6
|
+
/**
|
|
7
|
+
* Live rate-limit / cap snapshot read from the `wormhole_bridge::Bridge`
|
|
8
|
+
* shared object. All amounts are raw base units of the bridged credit coin.
|
|
9
|
+
*
|
|
10
|
+
* `dailyMinted` / `dailyBurned` are the sliding-window sums as the on-chain
|
|
11
|
+
* `daily_minted` / `daily_burned` views report them — buckets that rotated
|
|
12
|
+
* out of the trailing window are evicted lazily on the next mint/burn, so
|
|
13
|
+
* these can read slightly high until then (conservative).
|
|
14
|
+
*/
|
|
15
|
+
export interface BridgeLimitsView {
|
|
16
|
+
paused: boolean;
|
|
17
|
+
dailyMintLimit: bigint;
|
|
18
|
+
dailyMinted: bigint;
|
|
19
|
+
maxMintPerTx: bigint;
|
|
20
|
+
dailyBurnLimit: bigint;
|
|
21
|
+
dailyBurned: bigint;
|
|
22
|
+
maxBurnPerTx: bigint;
|
|
23
|
+
/** Per-account 24h burn cap; 0n means the gate is disabled. */
|
|
24
|
+
personalBurnCapAmount: bigint;
|
|
25
|
+
/** Present only when `accountId` is supplied — burn counted in that
|
|
26
|
+
* account's current window (the per-account cap key is the account id). */
|
|
27
|
+
personalBurned?: bigint;
|
|
28
|
+
/** Present only when `backing` is supplied — `minted_for(chainId, token)`,
|
|
29
|
+
* the amount currently withdrawable to that EVM (chain, token). */
|
|
30
|
+
backingMinted?: bigint;
|
|
31
|
+
}
|
|
32
|
+
export interface BridgeLimitsArgs {
|
|
33
|
+
/** wxa trading account id — enables the per-account `personalBurned` read. */
|
|
34
|
+
accountId?: string;
|
|
35
|
+
/** Wormhole destination chain id + 20-byte EVM token — enables the
|
|
36
|
+
* `mintedFor` backing read. */
|
|
37
|
+
backing?: {
|
|
38
|
+
wormholeChainId: number;
|
|
39
|
+
token: Uint8Array | number[];
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Batched read of the bridge's rate-limit / cap state in a single simulate.
|
|
44
|
+
* Pass `accountId` to also fetch the per-account burn usage, and `backing`
|
|
45
|
+
* to also fetch the destination-chain backing (`minted_for`).
|
|
46
|
+
*
|
|
47
|
+
* Throws if `wormhole_bridge` (or its `Bridge` object id) is absent from the
|
|
48
|
+
* canonical config — e.g. on a network where the Sui bridge isn't published.
|
|
49
|
+
*/
|
|
50
|
+
export declare function getBridgeLimits(client: PerpClient, args?: BridgeLimitsArgs): Promise<BridgeLimitsView>;
|
|
51
|
+
export interface BridgeFeeView {
|
|
52
|
+
/** Raw fee charged on a wormhole (Sui → EVM) exit of `amount`:
|
|
53
|
+
* `max(ceil(effectiveRate * amount), effectiveMinFee)`. */
|
|
54
|
+
feeAmount: bigint;
|
|
55
|
+
/** Whether the exit clears the on-chain net-zero guard — i.e. a strictly
|
|
56
|
+
* positive amount remains after the fee. Gate "estimated fee" UI on THIS,
|
|
57
|
+
* not `feeAmount` alone: a dust `amount`, or a min-fee floor ≥ `amount`,
|
|
58
|
+
* makes `feeAmount >= amount` and the exit would abort (audit L1). */
|
|
59
|
+
wouldExecute: boolean;
|
|
60
|
+
/** Effective % rate for the chain (per-chain override → default → 0),
|
|
61
|
+
* 1e9-scaled (the `Float`-as-`u128` ABI convention). */
|
|
62
|
+
effectiveRate: bigint;
|
|
63
|
+
/** Effective minimum-fee floor for the chain (override → default → 0),
|
|
64
|
+
* in CREDIT base units. */
|
|
65
|
+
effectiveMinFee: bigint;
|
|
66
|
+
/** Net CREDIT the recipient receives after the fee; `0n` when the exit
|
|
67
|
+
* wouldn't execute (`wouldExecute === false`). */
|
|
68
|
+
netAmount: bigint;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Estimate the bridge fee for a wormhole (Sui → EVM) CREDIT exit of `amount`
|
|
72
|
+
* to `evmDestinationChain`, read in a single simulate from the on-chain
|
|
73
|
+
* `withdrawal_queue` views. The charged fee is
|
|
74
|
+
* `max(ceil(effectiveRate * amount), effectiveMinFee)`.
|
|
75
|
+
*
|
|
76
|
+
* Surface UI off `wouldExecute`, NOT `feeAmount` alone — `feeAmount` is the raw
|
|
77
|
+
* fee and can equal/exceed `amount` (ceil rounding on a dust entry, or a min-fee
|
|
78
|
+
* floor larger than the entry), in which case the on-chain exit aborts its
|
|
79
|
+
* net-zero guard (audit L1). `netAmount` is `0n` whenever `wouldExecute` is
|
|
80
|
+
* false.
|
|
81
|
+
*
|
|
82
|
+
* @param args.amount CREDIT base units (the bridged coin's smallest unit).
|
|
83
|
+
* @param args.evmDestinationChain WORMHOLE chain id of the destination EVM.
|
|
84
|
+
* @param args.creditType CREDIT coin type; defaults to `client.creditType()`.
|
|
85
|
+
*/
|
|
86
|
+
export declare function getBridgeFee(client: PerpClient, args: {
|
|
87
|
+
evmDestinationChain: number;
|
|
88
|
+
amount: bigint | number;
|
|
89
|
+
creditType?: string;
|
|
90
|
+
}): Promise<BridgeFeeView>;
|