@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
package/README.md
CHANGED
|
@@ -6,24 +6,28 @@ TypeScript SDK for the WaterX protocol on Sui — **two product lines in one pac
|
|
|
6
6
|
|
|
7
7
|
## Two lines, one package
|
|
8
8
|
|
|
9
|
-
The perp and prediction lines expose builder functions with **colliding names** (`placeOrder`, `
|
|
9
|
+
The perp and prediction lines expose builder functions with **colliding names** (`placeOrder`, `deposit`, …), so they are kept in separate namespaces under one umbrella `WaterXClient`:
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
const client = await
|
|
15
|
-
client.
|
|
16
|
-
client.
|
|
17
|
-
|
|
18
|
-
//
|
|
12
|
+
import { WaterXClient } from "@waterx/sdk";
|
|
13
|
+
|
|
14
|
+
const client = await WaterXClient.create({ network: "TESTNET" });
|
|
15
|
+
client.account.createAccount(tx, { alias }); // shared waterx_account + funding (credit/custody)
|
|
16
|
+
client.perp.buildPlaceOrderTx(params); // perpetuals
|
|
17
|
+
client.predict.placeOrder(tx, params); // prediction markets
|
|
18
|
+
// client.perp / client.predict ARE the line clients — sign/execute on them directly:
|
|
19
|
+
// await client.perp.signAndExecuteTransaction({ transaction: tx, signer })
|
|
20
|
+
// each line can target a different network: WaterXClient.create({ perp: { network: "MAINNET" }, predict: { network: "TESTNET" } })
|
|
19
21
|
```
|
|
20
22
|
|
|
23
|
+
> `WaterXClient` is the umbrella entry point. `Client` is kept as a **deprecated alias** for one major cycle.
|
|
24
|
+
|
|
21
25
|
Import surfaces:
|
|
22
26
|
|
|
23
27
|
| Import | What |
|
|
24
28
|
|--------|------|
|
|
25
|
-
| `@waterx/sdk` | `
|
|
26
|
-
| `@waterx/sdk/perp` | Perp line: `
|
|
29
|
+
| `@waterx/sdk` | `WaterXClient` (umbrella) + `perp` / `prediction` namespaces. Perp's API is also re-exported flat here (**deprecated** — prefer `client.perp` or the `perp` namespace; removed next major). |
|
|
30
|
+
| `@waterx/sdk/perp` | Perp line: `PerpClient`, builders, fetch, Pyth/Wormhole utils. |
|
|
27
31
|
| `@waterx/sdk/prediction` | Prediction line: `PredictClient`, builders, fetch, utils. |
|
|
28
32
|
|
|
29
33
|
## Install
|
|
@@ -37,19 +41,19 @@ Consumers: `pnpm add @waterx/sdk @mysten/sui`
|
|
|
37
41
|
|
|
38
42
|
## Quickstart (unified client)
|
|
39
43
|
|
|
40
|
-
`
|
|
44
|
+
`WaterXClient.create()` loads each line's deployment config from the canonical `waterx-config` JSON and returns a ready client. Builders are **build-only** — they return / mutate a `Transaction`; signing & execution stay with the caller (`client.perp` / `client.predict` are the line clients, or a frontend wallet), so multi-step Pyth injection and wallet flows keep working.
|
|
41
45
|
|
|
42
46
|
```ts
|
|
43
|
-
import {
|
|
47
|
+
import { WaterXClient, rawPrice } from "@waterx/sdk";
|
|
44
48
|
import { Transaction } from "@mysten/sui/transactions";
|
|
45
49
|
|
|
46
|
-
const client = await
|
|
50
|
+
const client = await WaterXClient.create({ network: "TESTNET" });
|
|
47
51
|
const signer = /* your Ed25519Keypair or wallet Signer */;
|
|
48
52
|
|
|
49
53
|
// --- Perp: place a market order ---
|
|
50
54
|
const tx = await client.perp.buildPlaceOrderTx({
|
|
51
55
|
ticker: "BTCUSD",
|
|
52
|
-
collateralType: client.
|
|
56
|
+
collateralType: client.perp.creditType(),
|
|
53
57
|
accountId: "0x...", // UserAccount object id (hex)
|
|
54
58
|
main: {
|
|
55
59
|
isLong: true,
|
|
@@ -61,25 +65,25 @@ const tx = await client.perp.buildPlaceOrderTx({
|
|
|
61
65
|
},
|
|
62
66
|
preOrders: [],
|
|
63
67
|
});
|
|
64
|
-
await client.
|
|
68
|
+
await client.perp.signAndExecuteTransaction({ transaction: tx, signer });
|
|
65
69
|
|
|
66
70
|
// --- Prediction: same pattern under client.predict ---
|
|
67
71
|
const ptx = new Transaction();
|
|
68
72
|
client.predict.placeOrder(ptx, params);
|
|
69
|
-
await client.
|
|
73
|
+
await client.predict.signAndExecuteTransaction({ transaction: ptx, signer });
|
|
70
74
|
```
|
|
71
75
|
|
|
72
|
-
> Account creation is shared:
|
|
76
|
+
> Account creation is shared: `client.account.*` builds accounts via the one on-chain `waterx_account` system (perp-backed), so an account created through `client.account.createAccount` is usable by both `client.perp.*` and `client.predict.*`. (On split-network setups `client.account` follows the perp line — reach the predict line's generic account builders via the `prediction` namespace.)
|
|
73
77
|
|
|
74
78
|
## Per-line clients
|
|
75
79
|
|
|
76
80
|
If you only need one line, construct it directly (both factories are **async** — they fetch deployment config):
|
|
77
81
|
|
|
78
82
|
```ts
|
|
79
|
-
import {
|
|
83
|
+
import { PerpClient } from "@waterx/sdk/perp";
|
|
80
84
|
import { PredictClient } from "@waterx/sdk/prediction";
|
|
81
85
|
|
|
82
|
-
const perp = await
|
|
86
|
+
const perp = await PerpClient.create("TESTNET"); // or PerpClient.testnet()
|
|
83
87
|
const predict = await PredictClient.create("TESTNET"); // or PredictClient.testnet()
|
|
84
88
|
```
|
|
85
89
|
|
|
@@ -91,9 +95,9 @@ To avoid doc drift, per-action usage lives in maintained, lint-checked code rath
|
|
|
91
95
|
|
|
92
96
|
- **Perp recipes:** [`examples/`](./examples) — ~30 runnable scripts (place orders, WLP mint/redeem, account/delegates, reads). Each uses `buildClient()` + a builder + `simThenMaybeExecute`.
|
|
93
97
|
- **Prediction recipes:** [`test/prediction/e2e/`](./test/prediction/e2e) — the live reference for `client.predict.*` flows.
|
|
94
|
-
- **Authoritative export list:** [`src/index.ts`](./src/index.ts) (perp) and [`src/prediction/index.ts`](./src/prediction/index.ts) — clients, builders, view helpers, BCS types, and `*Calls` generated namespaces.
|
|
98
|
+
- **Authoritative export list:** [`src/perp/index.ts`](./src/perp/index.ts) (perp) and [`src/prediction/index.ts`](./src/prediction/index.ts) — clients, builders, view helpers, BCS types, and `*Calls` generated namespaces. The package root (`.`) is [`src/sdk.ts`](./src/sdk.ts) (umbrella + flat-perp re-export); the shared base is published at `@waterx/sdk/account` and `@waterx/sdk/oracle`.
|
|
95
99
|
|
|
96
|
-
Perp `build*Tx` helpers are Pyth-backed (`async`; they refresh feeds before the call). Pyth/
|
|
100
|
+
Perp `build*Tx` helpers are Pyth-backed (`async`; they refresh feeds before the call). Oracle (Pyth/Hermes) helpers live in [`src/oracle/`](./src/oracle).
|
|
97
101
|
|
|
98
102
|
## Development
|
|
99
103
|
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* injected. Used by every user/* builder to authenticate the caller.
|
|
5
5
|
*/
|
|
6
6
|
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
7
|
-
import type {
|
|
7
|
+
import type { WxaClientLike } from "./client.ts";
|
|
8
8
|
export type BucketAccount = string | TransactionArgument | undefined;
|
|
9
|
-
export declare function makeSenderRequest(client:
|
|
9
|
+
export declare function makeSenderRequest(client: WxaClientLike, tx: Transaction, bucketAccount: BucketAccount): TransactionArgument;
|
|
@@ -11,23 +11,24 @@
|
|
|
11
11
|
* or a `TransactionArgument`).
|
|
12
12
|
*/
|
|
13
13
|
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
14
|
-
import type {
|
|
14
|
+
import type { WxaClientLike } from "./client.ts";
|
|
15
15
|
export interface CreateAccountParams {
|
|
16
16
|
/** Alias / display name for the new account (max length checked on-chain). */
|
|
17
17
|
alias: string;
|
|
18
18
|
/** Optional Bucket Account to act through (otherwise tx.sender). */
|
|
19
19
|
bucketAccount?: string | TransactionArgument;
|
|
20
20
|
}
|
|
21
|
-
/** Build `waterx_account::create_account`. Returns the new account ID
|
|
22
|
-
export declare function createAccount(client:
|
|
21
|
+
/** Build `waterx_account::create_account`. Returns the new account ID (Move return value). */
|
|
22
|
+
export declare function createAccount(client: WxaClientLike, tx: Transaction, params: CreateAccountParams): TransactionArgument;
|
|
23
23
|
export interface SetAliasParams {
|
|
24
24
|
accountId: string;
|
|
25
25
|
alias: string;
|
|
26
26
|
bucketAccount?: string | TransactionArgument;
|
|
27
27
|
}
|
|
28
|
-
export declare function setAlias(client:
|
|
28
|
+
export declare function setAlias(client: WxaClientLike, tx: Transaction, params: SetAliasParams): void;
|
|
29
29
|
export interface AddDelegateParams {
|
|
30
|
-
|
|
30
|
+
/** Account ID — an `0x2::object::ID` string or a PTB argument. */
|
|
31
|
+
accountId: string | TransactionArgument;
|
|
31
32
|
delegateAddress: string;
|
|
32
33
|
alias: string;
|
|
33
34
|
/** Bitmask matching `waterx_account` permission constants. */
|
|
@@ -36,13 +37,14 @@ export interface AddDelegateParams {
|
|
|
36
37
|
expiresAtMs?: bigint | number;
|
|
37
38
|
bucketAccount?: string | TransactionArgument;
|
|
38
39
|
}
|
|
39
|
-
export declare function addDelegate(client:
|
|
40
|
+
export declare function addDelegate(client: WxaClientLike, tx: Transaction, params: AddDelegateParams): void;
|
|
40
41
|
export interface RemoveDelegateParams {
|
|
41
|
-
|
|
42
|
+
/** Account ID — an `0x2::object::ID` string or a PTB argument. */
|
|
43
|
+
accountId: string | TransactionArgument;
|
|
42
44
|
delegateAddress: string;
|
|
43
45
|
bucketAccount?: string | TransactionArgument;
|
|
44
46
|
}
|
|
45
|
-
export declare function removeDelegate(client:
|
|
47
|
+
export declare function removeDelegate(client: WxaClientLike, tx: Transaction, params: RemoveDelegateParams): void;
|
|
46
48
|
export interface SetDelegateProtocolPermissionParams {
|
|
47
49
|
accountId: string;
|
|
48
50
|
delegateAddress: string;
|
|
@@ -52,10 +54,10 @@ export interface SetDelegateProtocolPermissionParams {
|
|
|
52
54
|
protocolType: string;
|
|
53
55
|
bucketAccount?: string | TransactionArgument;
|
|
54
56
|
}
|
|
55
|
-
export declare function setDelegateProtocolPermission(client:
|
|
57
|
+
export declare function setDelegateProtocolPermission(client: WxaClientLike, tx: Transaction, params: SetDelegateProtocolPermissionParams): void;
|
|
56
58
|
export interface RequestDepositParams {
|
|
57
|
-
/** wxa account ID receiving the deposit. */
|
|
58
|
-
accountId: string;
|
|
59
|
+
/** wxa account ID receiving the deposit (ID string or PTB argument). */
|
|
60
|
+
accountId: string | TransactionArgument;
|
|
59
61
|
/** Coin or coin transaction argument to deposit. */
|
|
60
62
|
coin: TransactionArgument;
|
|
61
63
|
/** Fully-qualified coin type. */
|
|
@@ -64,10 +66,10 @@ export interface RequestDepositParams {
|
|
|
64
66
|
extraData?: Uint8Array;
|
|
65
67
|
}
|
|
66
68
|
/** Build `account::request_deposit<T>`. Returns the `DepositRequest<T>` argument. */
|
|
67
|
-
export declare function requestDeposit(client:
|
|
69
|
+
export declare function requestDeposit(client: WxaClientLike, tx: Transaction, params: RequestDepositParams): TransactionArgument;
|
|
68
70
|
export interface RequestDepositFromReceivingsParams {
|
|
69
|
-
/** wxa account ID receiving the deposit. */
|
|
70
|
-
accountId: string;
|
|
71
|
+
/** wxa account ID receiving the deposit (ID string or PTB argument). */
|
|
72
|
+
accountId: string | TransactionArgument;
|
|
71
73
|
/**
|
|
72
74
|
* `Receiving<Coin<T>>` arguments — one per `Coin<T>` previously transferred
|
|
73
75
|
* onto the account's address. Build each with
|
|
@@ -85,7 +87,7 @@ export interface RequestDepositFromReceivingsParams {
|
|
|
85
87
|
* transfer-to-object path) into a single `DepositRequest<T>`. Returns the
|
|
86
88
|
* `DepositRequest<T>` argument.
|
|
87
89
|
*/
|
|
88
|
-
export declare function requestDepositFromReceivings(client:
|
|
90
|
+
export declare function requestDepositFromReceivings(client: WxaClientLike, tx: Transaction, params: RequestDepositFromReceivingsParams): TransactionArgument;
|
|
89
91
|
export interface RequestDepositFromFundsParams {
|
|
90
92
|
/** wxa account ID receiving the deposit. */
|
|
91
93
|
accountId: string;
|
|
@@ -112,9 +114,9 @@ export interface RequestDepositFromFundsParams {
|
|
|
112
114
|
* no `T`, so check `settled_funds_value<T>` off-chain first if you want to
|
|
113
115
|
* skip empty drains.
|
|
114
116
|
*/
|
|
115
|
-
export declare function requestDepositFromFunds(client:
|
|
117
|
+
export declare function requestDepositFromFunds(client: WxaClientLike, tx: Transaction, params: RequestDepositFromFundsParams): TransactionArgument;
|
|
116
118
|
export interface RequestWithdrawParams {
|
|
117
|
-
accountId: string;
|
|
119
|
+
accountId: string | TransactionArgument;
|
|
118
120
|
amount: bigint | number;
|
|
119
121
|
/** Recipient for the eventual coin payout (policy decides exact mechanics). */
|
|
120
122
|
recipient: string;
|
|
@@ -125,13 +127,13 @@ export interface RequestWithdrawParams {
|
|
|
125
127
|
bucketAccount?: string | TransactionArgument;
|
|
126
128
|
}
|
|
127
129
|
/** Build `account::request_withdraw<T>`. Returns the `WithdrawRequest<T>` argument. */
|
|
128
|
-
export declare function requestWithdraw(client:
|
|
130
|
+
export declare function requestWithdraw(client: WxaClientLike, tx: Transaction, params: RequestWithdrawParams): TransactionArgument;
|
|
129
131
|
export interface TransferToAccountParams {
|
|
130
|
-
accountId: string;
|
|
132
|
+
accountId: string | TransactionArgument;
|
|
131
133
|
coin: TransactionArgument;
|
|
132
134
|
coinType: string;
|
|
133
135
|
}
|
|
134
|
-
export declare function transferToAccount(client:
|
|
136
|
+
export declare function transferToAccount(client: WxaClientLike, tx: Transaction, params: TransferToAccountParams): void;
|
|
135
137
|
export interface ReceiveParams {
|
|
136
138
|
accountId: string;
|
|
137
139
|
/**
|
|
@@ -153,4 +155,4 @@ export interface ReceiveParams {
|
|
|
153
155
|
* Bypasses the deposit-policy flow — use for reward coins (and other
|
|
154
156
|
* tokens / objects) that have no registered deposit policy.
|
|
155
157
|
*/
|
|
156
|
-
export declare function receive(client:
|
|
158
|
+
export declare function receive(client: WxaClientLike, tx: Transaction, params: ReceiveParams): TransactionArgument;
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
* a Bucket `Account` object, pass `bucketAccount` (an object ID string
|
|
11
11
|
* or a `TransactionArgument`).
|
|
12
12
|
*/
|
|
13
|
-
import { ACCUMULATOR_ROOT } from "../constants.js";
|
|
14
|
-
import { createAccountCall } from "../core/waterx-account.js";
|
|
15
13
|
import * as wxa from "../generated/waterx_account/account.js";
|
|
16
|
-
import { makeSenderRequest } from "
|
|
17
|
-
|
|
14
|
+
import { makeSenderRequest } from "./account-request.js";
|
|
15
|
+
import { ACCUMULATOR_ROOT } from "./constants.js";
|
|
16
|
+
import { createAccountCall } from "./waterx-account.js";
|
|
17
|
+
/** Build `waterx_account::create_account`. Returns the new account ID (Move return value). */
|
|
18
18
|
export function createAccount(client, tx, params) {
|
|
19
19
|
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
20
|
-
createAccountCall(tx, {
|
|
20
|
+
return createAccountCall(tx, {
|
|
21
21
|
packageId: client.config.packages.waterx_account.published_at,
|
|
22
22
|
registry: client.config.packages.waterx_account.account_registry,
|
|
23
23
|
}, { senderRequest: req, alias: params.alias });
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `AccountClientLike` — the narrow capability slice the account/funding builders
|
|
3
|
+
* read, instead of the concrete `PerpClient`.
|
|
4
|
+
*
|
|
5
|
+
* The account framework + funding (credit / custody / bridge / consolidate) is
|
|
6
|
+
* the contract's **base** layer: both product lines depend down onto it. Typing
|
|
7
|
+
* these builders to `PerpClient` inverted that — so they take this structural
|
|
8
|
+
* interface instead. `PerpClient` satisfies it without an `implements` clause
|
|
9
|
+
* (it `extends BaseLineClient<WaterXConfig>` and carries the config-view slice +
|
|
10
|
+
* the `wormhole` infra block); a future funding-capable client can too.
|
|
11
|
+
*
|
|
12
|
+
* The config schema it reads lives in `account/config.ts` (the base layer), so
|
|
13
|
+
* this file imports **nothing** from `perp/` — `account/` no longer depends on the
|
|
14
|
+
* perp line even at the type level. `PerpClient`'s `WaterXConfig` is assignable to
|
|
15
|
+
* the narrower `AccountConfig` (`WaterXPackages extends AccountPackages`).
|
|
16
|
+
*/
|
|
17
|
+
import type { BaseLineClient } from "../base-client.ts";
|
|
18
|
+
import type { AccountConfig, NativeCustodyAsset, WaterxCreditPackage, WormholeBridgePackage, WormholeInfraConfig, WxaConfig } from "./config.ts";
|
|
19
|
+
/**
|
|
20
|
+
* The slice the **generic wxa builders** (create account / delegates / alias /
|
|
21
|
+
* deposit-request) read — just the `waterx_account` + `bucket_framework` package
|
|
22
|
+
* ids and transport. Both `PerpClient` and `PredictClient` satisfy it (their full
|
|
23
|
+
* configs are assignable to {@link WxaConfig}), so these builders are shared by
|
|
24
|
+
* both lines. The funding-capable {@link AccountClientLike} is a superset.
|
|
25
|
+
*/
|
|
26
|
+
export type WxaClientLike = BaseLineClient<WxaConfig>;
|
|
27
|
+
export interface AccountClientLike extends BaseLineClient<AccountConfig> {
|
|
28
|
+
/** External Wormhole infra (network default, overridable via config). */
|
|
29
|
+
readonly wormhole: WormholeInfraConfig;
|
|
30
|
+
/** Fully-qualified CREDIT coin Move type; throws if `waterx_credit.credit_type` is unset. */
|
|
31
|
+
creditType(): string;
|
|
32
|
+
/** `waterx_credit` package entry; throws if absent. */
|
|
33
|
+
getCredit(): WaterxCreditPackage;
|
|
34
|
+
/** `wormhole_bridge` package entry; throws if absent. */
|
|
35
|
+
getBridge(): WormholeBridgePackage;
|
|
36
|
+
/** Sui Wormhole `State` object id (per-deployment, falls back to `wormhole` infra). */
|
|
37
|
+
wormholeStateId(): string;
|
|
38
|
+
/** All native-custody backing-asset rows; throws if no custody vault. */
|
|
39
|
+
getNativeAssets(): readonly NativeCustodyAsset[];
|
|
40
|
+
/** A native-custody asset row by its fully-qualified Move type; throws if unknown. */
|
|
41
|
+
getNativeAsset(moveType: string): NativeCustodyAsset;
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `AccountClientLike` — the narrow capability slice the account/funding builders
|
|
3
|
+
* read, instead of the concrete `PerpClient`.
|
|
4
|
+
*
|
|
5
|
+
* The account framework + funding (credit / custody / bridge / consolidate) is
|
|
6
|
+
* the contract's **base** layer: both product lines depend down onto it. Typing
|
|
7
|
+
* these builders to `PerpClient` inverted that — so they take this structural
|
|
8
|
+
* interface instead. `PerpClient` satisfies it without an `implements` clause
|
|
9
|
+
* (it `extends BaseLineClient<WaterXConfig>` and carries the config-view slice +
|
|
10
|
+
* the `wormhole` infra block); a future funding-capable client can too.
|
|
11
|
+
*
|
|
12
|
+
* The config schema it reads lives in `account/config.ts` (the base layer), so
|
|
13
|
+
* this file imports **nothing** from `perp/` — `account/` no longer depends on the
|
|
14
|
+
* perp line even at the type level. `PerpClient`'s `WaterXConfig` is assignable to
|
|
15
|
+
* the narrower `AccountConfig` (`WaterXPackages extends AccountPackages`).
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account-layer config schema — the package entries + config slice the base
|
|
3
|
+
* (`waterx_account` framework + funding: credit / custody / bridge / queue +
|
|
4
|
+
* referral) reads. This is the **base**: `perp/config.ts` imports these and
|
|
5
|
+
* `WaterXPackages extends AccountPackages`; nothing here imports `perp/` or
|
|
6
|
+
* `prediction/`. Snake_case mirrors the canonical `waterx-config` JSON 1:1.
|
|
7
|
+
*/
|
|
8
|
+
import type { BaseLineConfig } from "../base-client.ts";
|
|
9
|
+
export interface BasePackageEntry {
|
|
10
|
+
published_at: string;
|
|
11
|
+
original_id: string;
|
|
12
|
+
version: number;
|
|
13
|
+
upgrade_capability?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface WxaAccountPackage extends BasePackageEntry {
|
|
16
|
+
admin_cap: string;
|
|
17
|
+
account_registry: string;
|
|
18
|
+
}
|
|
19
|
+
export interface WaterxReferralPackage extends BasePackageEntry {
|
|
20
|
+
/** Shared `ReferralTable`. */
|
|
21
|
+
referral_table: string;
|
|
22
|
+
}
|
|
23
|
+
export interface WaterxCreditPackage {
|
|
24
|
+
published_at: string;
|
|
25
|
+
/** Shared `CreditRegistry<CREDIT>` (phase-1 output). */
|
|
26
|
+
credit_registry?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Fully-qualified CREDIT coin Move type, e.g. `0x..::usd::USD`. Required for
|
|
29
|
+
* any credit/bridge flow — `client.creditType()` returns it as-is.
|
|
30
|
+
*/
|
|
31
|
+
credit_type?: string;
|
|
32
|
+
}
|
|
33
|
+
/** One backing-asset row on the native custody vault (PSM). */
|
|
34
|
+
export interface NativeCustodyAsset {
|
|
35
|
+
/** Human-readable asset label, e.g. `"MOCK_USDC"` / `"USDC"` (from `add_asset`). */
|
|
36
|
+
name?: string;
|
|
37
|
+
/** Fully-qualified backing asset Move type `T`. */
|
|
38
|
+
type: string;
|
|
39
|
+
decimal: number;
|
|
40
|
+
mint_fee_scaled: string;
|
|
41
|
+
burn_fee_scaled: string;
|
|
42
|
+
min_burn_amount: string;
|
|
43
|
+
}
|
|
44
|
+
export interface NativeCustodyPackage {
|
|
45
|
+
published_at: string;
|
|
46
|
+
/** Shared `CustodyVault<CREDIT>` (phase-4 output). */
|
|
47
|
+
vault?: string;
|
|
48
|
+
/** Backing assets registered via `add_asset` (array, identified by `type`). */
|
|
49
|
+
assets: NativeCustodyAsset[];
|
|
50
|
+
}
|
|
51
|
+
export interface TrustedEmitterRow {
|
|
52
|
+
/** Source EVM chain's Wormhole chain id (e.g. 10002 = Sepolia). */
|
|
53
|
+
chain_id: number;
|
|
54
|
+
/** 32-byte left-padded EVM bridge address (0x form). */
|
|
55
|
+
evm_bridge_address_32b: string;
|
|
56
|
+
/** Whitelisted 20-byte EVM token addresses (0x form). */
|
|
57
|
+
evm_tokens_20b: string[];
|
|
58
|
+
}
|
|
59
|
+
export interface WormholeBridgePackage {
|
|
60
|
+
published_at: string;
|
|
61
|
+
/** Shared Sui Wormhole `State` object id for this deployment. */
|
|
62
|
+
wormhole_state: string;
|
|
63
|
+
hourly_mint_limit?: string;
|
|
64
|
+
max_mint_per_tx?: string;
|
|
65
|
+
hourly_burn_limit?: string;
|
|
66
|
+
max_burn_per_tx?: string;
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated EVM emitter↔token config now lives solely under `evm.bridge.chains`
|
|
69
|
+
* (deposit_vault = emitter, wormhole_chain_id = chain key). The runtime allowlist is
|
|
70
|
+
* read from the on-chain `Bridge` object, not from config. Kept optional for back-compat.
|
|
71
|
+
*/
|
|
72
|
+
trusted_emitters?: TrustedEmitterRow[];
|
|
73
|
+
/** Shared `Bridge` (phase-5 output). */
|
|
74
|
+
bridge?: string;
|
|
75
|
+
/**
|
|
76
|
+
* The bridge's `EmitterCap` object id (Sui-side Wormhole emitter address
|
|
77
|
+
* for burn-relay Wormholescan lookups). Not written by the deploy script
|
|
78
|
+
* — resolve from the on-chain `Bridge` object if absent.
|
|
79
|
+
*/
|
|
80
|
+
emitter_cap?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface WithdrawalQueuePackage {
|
|
83
|
+
published_at: string;
|
|
84
|
+
/** Addresses on the queue executor allowlist (keepers). */
|
|
85
|
+
executors?: string[];
|
|
86
|
+
/** Shared `Queue<CREDIT>` (phase-6 output). */
|
|
87
|
+
queue?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Wormhole infra for the cross-chain credit bridge. `state_id` is the same
|
|
91
|
+
* shared Sui Wormhole `State` object Pyth uses (kept in sync with
|
|
92
|
+
* `PYTH_DEFAULTS[*].wormhole_state_id`). Override per-deployment via
|
|
93
|
+
* `WaterXConfig.wormhole` if a deployment ever points elsewhere.
|
|
94
|
+
*/
|
|
95
|
+
export interface WormholeInfraConfig {
|
|
96
|
+
/** Shared Sui Wormhole `State` object. */
|
|
97
|
+
state_id: string;
|
|
98
|
+
/** Wormhole core package id on Sui. */
|
|
99
|
+
core_package: string;
|
|
100
|
+
/** Sui's Wormhole chain id (21 on both mainnet and testnet). */
|
|
101
|
+
sui_chain_id: number;
|
|
102
|
+
/** Wormholescan REST base for VAA lookups (no trailing slash). */
|
|
103
|
+
wormholescan_api: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The minimal package slice the **generic wxa builders** (create / delegate /
|
|
107
|
+
* alias …) read — only the fields BOTH the perp and prediction line configs are
|
|
108
|
+
* guaranteed to carry (prediction makes `original_id` / `version` / `admin_cap`
|
|
109
|
+
* optional, so the strict {@link WxaAccountPackage} is too narrow a target here).
|
|
110
|
+
*/
|
|
111
|
+
export interface WxaPackages {
|
|
112
|
+
bucket_framework: {
|
|
113
|
+
published_at: string;
|
|
114
|
+
};
|
|
115
|
+
waterx_account: {
|
|
116
|
+
published_at: string;
|
|
117
|
+
account_registry: string;
|
|
118
|
+
};
|
|
119
|
+
waterx_referral?: {
|
|
120
|
+
published_at: string;
|
|
121
|
+
referral_table: string;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** Narrow config for the generic wxa builders — both line configs are assignable. */
|
|
125
|
+
export interface WxaConfig extends BaseLineConfig {
|
|
126
|
+
packages: WxaPackages;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The package subset the account base + funding builders read. The full
|
|
130
|
+
* line config (`WaterXPackages`) **extends** this, so any line client's config
|
|
131
|
+
* is structurally an account config.
|
|
132
|
+
*/
|
|
133
|
+
export interface AccountPackages extends WxaPackages {
|
|
134
|
+
bucket_framework: BasePackageEntry;
|
|
135
|
+
waterx_account: WxaAccountPackage;
|
|
136
|
+
waterx_referral?: WaterxReferralPackage;
|
|
137
|
+
waterx_credit?: WaterxCreditPackage;
|
|
138
|
+
wormhole_bridge?: WormholeBridgePackage;
|
|
139
|
+
withdrawal_queue?: WithdrawalQueuePackage;
|
|
140
|
+
native_custody?: NativeCustodyPackage;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The narrow config shape the account/funding builders need. `WaterXConfig`
|
|
144
|
+
* (the perp line's full config) is assignable to this, so `PerpClient` satisfies
|
|
145
|
+
* {@link import("./client.ts").AccountClientLike} without importing `perp/`.
|
|
146
|
+
*/
|
|
147
|
+
export interface AccountConfig extends BaseLineConfig {
|
|
148
|
+
packages: AccountPackages;
|
|
149
|
+
/** Wormhole infra override (defaults from `WORMHOLE_DEFAULTS[network]`). */
|
|
150
|
+
wormhole?: WormholeInfraConfig;
|
|
151
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account-layer config schema — the package entries + config slice the base
|
|
3
|
+
* (`waterx_account` framework + funding: credit / custody / bridge / queue +
|
|
4
|
+
* referral) reads. This is the **base**: `perp/config.ts` imports these and
|
|
5
|
+
* `WaterXPackages extends AccountPackages`; nothing here imports `perp/` or
|
|
6
|
+
* `prediction/`. Snake_case mirrors the canonical `waterx-config` JSON 1:1.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Referral queries (`waterx_referral::referral_table`).
|
|
3
|
+
*
|
|
4
|
+
* Account-base reads — typed to {@link WxaClientLike} (just `waterx_referral` +
|
|
5
|
+
* transport), not the perp line. Co-located with the referral builders in
|
|
6
|
+
* `account/referral.ts`; both product lines can use them. The perp `fetch/`
|
|
7
|
+
* barrel re-exports these for back-compat.
|
|
8
|
+
*/
|
|
9
|
+
import type { WxaClientLike } from "../client.ts";
|
|
10
|
+
/** Returns the referrer address bound to `referee`, or `undefined` if none. */
|
|
11
|
+
export declare function getRefererFor(client: WxaClientLike, referee: string): Promise<string | undefined>;
|
|
12
|
+
/** True if `code` is a syntactically valid referral code (matches the contract's char rules). */
|
|
13
|
+
export declare function isValidReferralCode(client: WxaClientLike, code: string): Promise<boolean>;
|
|
14
|
+
/** True if `code` is already claimed in the on-chain ReferralTable. */
|
|
15
|
+
export declare function referralCodeExists(client: WxaClientLike, code: string): Promise<boolean>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Referral queries (`waterx_referral::referral_table`).
|
|
3
|
+
*
|
|
4
|
+
* Account-base reads — typed to {@link WxaClientLike} (just `waterx_referral` +
|
|
5
|
+
* transport), not the perp line. Co-located with the referral builders in
|
|
6
|
+
* `account/referral.ts`; both product lines can use them. The perp `fetch/`
|
|
7
|
+
* barrel re-exports these for back-compat.
|
|
8
|
+
*/
|
|
9
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
10
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
11
|
+
import { isValidReferralCode as isValidReferralCodeCall, referralCodeExists as referralCodeExistsCall, tryGetRefer as tryGetReferCall, } from "../../generated/waterx_referral/referral_table.js";
|
|
12
|
+
import { simulateAndExtract } from "./simulate.js";
|
|
13
|
+
function requireReferralPackage(client) {
|
|
14
|
+
const pkg = client.config.packages.waterx_referral?.published_at;
|
|
15
|
+
const table = client.config.packages.waterx_referral?.referral_table;
|
|
16
|
+
if (!pkg || !table) {
|
|
17
|
+
throw new Error("referral package not configured: set config.packages.waterx_referral.{published_at,referral_table}");
|
|
18
|
+
}
|
|
19
|
+
return { pkg, table };
|
|
20
|
+
}
|
|
21
|
+
/** Returns the referrer address bound to `referee`, or `undefined` if none. */
|
|
22
|
+
export async function getRefererFor(client, referee) {
|
|
23
|
+
const { pkg, table } = requireReferralPackage(client);
|
|
24
|
+
const tx = new Transaction();
|
|
25
|
+
tryGetReferCall({
|
|
26
|
+
package: pkg,
|
|
27
|
+
arguments: { table: tx.object(table), referee },
|
|
28
|
+
})(tx);
|
|
29
|
+
const bytes = await simulateAndExtract(client, tx);
|
|
30
|
+
const opt = bcs.option(bcs.Address).parse(bytes);
|
|
31
|
+
return opt ?? undefined;
|
|
32
|
+
}
|
|
33
|
+
/** True if `code` is a syntactically valid referral code (matches the contract's char rules). */
|
|
34
|
+
export async function isValidReferralCode(client, code) {
|
|
35
|
+
const { pkg } = requireReferralPackage(client);
|
|
36
|
+
const tx = new Transaction();
|
|
37
|
+
isValidReferralCodeCall({ package: pkg, arguments: { code } })(tx);
|
|
38
|
+
const bytes = await simulateAndExtract(client, tx);
|
|
39
|
+
return bcs.bool().parse(bytes);
|
|
40
|
+
}
|
|
41
|
+
/** True if `code` is already claimed in the on-chain ReferralTable. */
|
|
42
|
+
export async function referralCodeExists(client, code) {
|
|
43
|
+
const { pkg, table } = requireReferralPackage(client);
|
|
44
|
+
const tx = new Transaction();
|
|
45
|
+
referralCodeExistsCall({
|
|
46
|
+
package: pkg,
|
|
47
|
+
arguments: { table: tx.object(table), code },
|
|
48
|
+
})(tx);
|
|
49
|
+
const bytes = await simulateAndExtract(client, tx);
|
|
50
|
+
return bcs.bool().parse(bytes);
|
|
51
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared simulate/decode plumbing for the read helpers.
|
|
3
|
+
*
|
|
4
|
+
* Each public read builds a one-shot PTB, runs `client.simulate(tx)` with the
|
|
5
|
+
* zero address as sender, and decodes the command's BCS return values. Typed to
|
|
6
|
+
* the transport base ({@link BaseLineClient}) so any line client satisfies it —
|
|
7
|
+
* this is the **base** copy the perp `fetch/simulate.ts` re-exports, so the
|
|
8
|
+
* plumbing lives once. Internal to `fetch/` — not part of the public surface.
|
|
9
|
+
*/
|
|
10
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
11
|
+
import type { BaseLineClient } from "../../base-client.ts";
|
|
12
|
+
export interface SimulationCommandResult {
|
|
13
|
+
returnValues?: {
|
|
14
|
+
bcs?: Uint8Array | string;
|
|
15
|
+
value?: {
|
|
16
|
+
bcs?: Uint8Array | string;
|
|
17
|
+
};
|
|
18
|
+
}[];
|
|
19
|
+
}
|
|
20
|
+
export interface SimulationResult {
|
|
21
|
+
$kind?: string;
|
|
22
|
+
FailedTransaction?: {
|
|
23
|
+
status?: {
|
|
24
|
+
error?: {
|
|
25
|
+
message?: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
commandResults?: SimulationCommandResult[] | null;
|
|
30
|
+
}
|
|
31
|
+
export declare function toBytes(b: Uint8Array | string | undefined): Uint8Array | undefined;
|
|
32
|
+
export declare function simulateRaw(client: BaseLineClient, tx: Transaction): Promise<SimulationResult>;
|
|
33
|
+
export declare function extractAt(sim: SimulationResult, commandIndex: number, returnIndex?: number): Uint8Array;
|
|
34
|
+
export declare function simulateAndExtract(client: BaseLineClient, tx: Transaction, commandIndex?: number, returnIndex?: number): Promise<Uint8Array>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared simulate/decode plumbing for the read helpers.
|
|
3
|
+
*
|
|
4
|
+
* Each public read builds a one-shot PTB, runs `client.simulate(tx)` with the
|
|
5
|
+
* zero address as sender, and decodes the command's BCS return values. Typed to
|
|
6
|
+
* the transport base ({@link BaseLineClient}) so any line client satisfies it —
|
|
7
|
+
* this is the **base** copy the perp `fetch/simulate.ts` re-exports, so the
|
|
8
|
+
* plumbing lives once. Internal to `fetch/` — not part of the public surface.
|
|
9
|
+
*/
|
|
10
|
+
import { fromBase64 } from "@mysten/bcs";
|
|
11
|
+
import { DRY_RUN_SENDER } from "../../constants.js";
|
|
12
|
+
export function toBytes(b) {
|
|
13
|
+
if (!b)
|
|
14
|
+
return undefined;
|
|
15
|
+
if (typeof b === "string")
|
|
16
|
+
return fromBase64(b);
|
|
17
|
+
// gRPC returns Uint8Array; JSON-RPC serialization may turn it into a
|
|
18
|
+
// numeric-indexed object. Normalize both.
|
|
19
|
+
if (b instanceof Uint8Array)
|
|
20
|
+
return b;
|
|
21
|
+
return new Uint8Array(Object.values(b));
|
|
22
|
+
}
|
|
23
|
+
export async function simulateRaw(client, tx) {
|
|
24
|
+
tx.setSender(DRY_RUN_SENDER);
|
|
25
|
+
const sim = (await client.simulate(tx));
|
|
26
|
+
if (sim.$kind === "FailedTransaction") {
|
|
27
|
+
const err = sim.FailedTransaction?.status?.error?.message ?? "FailedTransaction";
|
|
28
|
+
throw new Error(`simulate aborted: ${err}`);
|
|
29
|
+
}
|
|
30
|
+
return sim;
|
|
31
|
+
}
|
|
32
|
+
export function extractAt(sim, commandIndex, returnIndex = 0) {
|
|
33
|
+
const ret = sim.commandResults?.[commandIndex]?.returnValues?.[returnIndex];
|
|
34
|
+
const bytes = toBytes(ret?.bcs) ?? toBytes(ret?.value?.bcs);
|
|
35
|
+
if (!bytes) {
|
|
36
|
+
throw new Error(`simulate returned no BCS value at commandResults[${commandIndex}].returnValues[${returnIndex}]`);
|
|
37
|
+
}
|
|
38
|
+
return bytes;
|
|
39
|
+
}
|
|
40
|
+
export async function simulateAndExtract(client, tx, commandIndex = 0, returnIndex = 0) {
|
|
41
|
+
const sim = await simulateRaw(client, tx);
|
|
42
|
+
return extractAt(sim, commandIndex, returnIndex);
|
|
43
|
+
}
|