@waterx/sdk 2.1.0 → 2.4.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 +75 -169
- package/dist/src/client.d.ts +40 -2
- package/dist/src/client.js +55 -6
- package/dist/src/config.d.ts +66 -3
- package/dist/src/config.js +10 -4
- package/dist/src/constants.d.ts +6 -0
- package/dist/src/constants.js +6 -0
- package/dist/src/core/waterx-account.d.ts +31 -0
- package/dist/src/core/waterx-account.js +26 -0
- package/dist/src/fetch.d.ts +110 -0
- package/dist/src/fetch.js +149 -4
- package/dist/src/generated/bucket_v2_framework/account.d.ts +5 -5
- package/dist/src/generated/bucket_v2_framework/double.d.ts +77 -77
- package/dist/src/generated/bucket_v2_framework/float.d.ts +73 -73
- package/dist/src/generated/bucket_v2_framework/liability.d.ts +33 -33
- package/dist/src/generated/bucket_v2_framework/linked_table.d.ts +5 -5
- package/dist/src/generated/bucket_v2_framework/linked_table.js +2 -2
- package/dist/src/generated/bucket_v2_framework/sheet.d.ts +57 -57
- package/dist/src/generated/bucket_v2_framework/sheet.js +5 -11
- package/dist/src/generated/native_custody/custody_vault.d.ts +46 -32
- package/dist/src/generated/native_custody/custody_vault.js +19 -10
- package/dist/src/generated/native_custody/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/native_custody/events.js +1 -2
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +7 -7
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +1 -2
- package/dist/src/generated/utils/index.d.ts +7 -7
- package/dist/src/generated/utils/index.js +9 -6
- package/dist/src/generated/waterx_account/account.d.ts +124 -71
- package/dist/src/generated/waterx_account/account.js +64 -29
- package/dist/src/generated/waterx_account/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/waterx_account/direct_rule.d.ts +5 -5
- package/dist/src/generated/waterx_account/events.d.ts +10 -0
- package/dist/src/generated/waterx_account/events.js +31 -50
- package/dist/src/generated/waterx_constant_rule/constant_rule.d.ts +68 -0
- package/dist/src/generated/waterx_constant_rule/constant_rule.js +59 -0
- package/dist/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/waterx_constant_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_constant_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_credit/credit_registry.d.ts +9 -9
- package/dist/src/generated/waterx_credit/credit_registry.js +1 -2
- package/dist/src/generated/waterx_credit/limited_supply.d.ts +17 -17
- package/dist/src/generated/waterx_oracle/aggregator.js +1 -2
- package/dist/src/generated/waterx_oracle/collector.d.ts +17 -17
- package/dist/src/generated/waterx_oracle/collector.js +1 -1
- package/dist/src/generated/waterx_oracle/oracle.d.ts +5 -5
- package/dist/src/generated/waterx_perp/account_data.d.ts +5 -5
- package/dist/src/generated/waterx_perp/account_data.js +1 -2
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/waterx_perp/events.d.ts +181 -181
- package/dist/src/generated/waterx_perp/events.js +87 -173
- package/dist/src/generated/waterx_perp/global_config.d.ts +3 -3
- package/dist/src/generated/waterx_perp/global_config.js +6 -12
- package/dist/src/generated/waterx_perp/keyed_big_vector.d.ts +9 -9
- package/dist/src/generated/waterx_perp/keyed_big_vector.js +1 -2
- package/dist/src/generated/waterx_perp/lp_pool.d.ts +115 -115
- package/dist/src/generated/waterx_perp/lp_pool.js +11 -22
- package/dist/src/generated/waterx_perp/market_config.d.ts +61 -43
- package/dist/src/generated/waterx_perp/market_config.js +29 -22
- package/dist/src/generated/waterx_perp/math.d.ts +7 -7
- package/dist/src/generated/waterx_perp/order_book.d.ts +47 -47
- package/dist/src/generated/waterx_perp/position.d.ts +99 -99
- package/dist/src/generated/waterx_perp/position.js +6 -12
- package/dist/src/generated/waterx_perp/request.d.ts +67 -67
- package/dist/src/generated/waterx_perp/request.js +2 -3
- package/dist/src/generated/waterx_perp/response.d.ts +35 -35
- package/dist/src/generated/waterx_perp/response.js +1 -2
- package/dist/src/generated/waterx_perp/trading.d.ts +303 -179
- package/dist/src/generated/waterx_perp/trading.js +99 -14
- package/dist/src/generated/waterx_perp_view/view.js +5 -10
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +5 -5
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +1 -2
- package/dist/src/generated/waterx_referral/referral_table.d.ts +5 -5
- package/dist/src/generated/waterx_referral/referral_table.js +1 -2
- package/dist/src/generated/waterx_staking/waterx_staking.d.ts +19 -19
- package/dist/src/generated/waterx_staking/waterx_staking.js +10 -20
- package/dist/src/generated/waterx_supra_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_supra_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.d.ts +158 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.js +148 -0
- package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +444 -4
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +417 -4
- package/dist/src/generated/wormhole_bridge/wormhole_bridge.d.ts +214 -74
- package/dist/src/generated/wormhole_bridge/wormhole_bridge.js +158 -29
- package/dist/src/index.d.ts +4 -3
- package/dist/src/index.js +3 -2
- package/dist/src/prediction/account.d.ts +96 -0
- package/dist/src/prediction/account.js +230 -0
- package/dist/src/prediction/admin.d.ts +47 -0
- package/dist/src/prediction/admin.js +105 -0
- package/dist/src/prediction/bcs.d.ts +22 -0
- package/dist/src/prediction/bcs.js +240 -0
- package/dist/src/prediction/client.d.ts +75 -0
- package/dist/src/prediction/client.js +164 -0
- package/dist/src/prediction/config.d.ts +60 -0
- package/dist/src/prediction/config.js +75 -0
- package/dist/src/prediction/constants.d.ts +44 -0
- package/dist/src/prediction/constants.js +46 -0
- package/dist/src/prediction/fetch.d.ts +82 -0
- package/dist/src/prediction/fetch.js +270 -0
- package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +100 -0
- package/dist/src/prediction/generated/bucket_v2_framework/account.js +129 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +6 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +19 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +27 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +382 -0
- package/dist/src/prediction/generated/bucket_v2_framework/double.js +466 -0
- package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +362 -0
- package/dist/src/prediction/generated/bucket_v2_framework/float.js +440 -0
- package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +193 -0
- package/dist/src/prediction/generated/bucket_v2_framework/liability.js +205 -0
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +384 -0
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +382 -0
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +344 -0
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +338 -0
- package/dist/src/prediction/generated/utils/index.d.ts +30 -0
- package/dist/src/prediction/generated/utils/index.js +160 -0
- package/dist/src/prediction/generated/waterx_account/account.d.ts +1589 -0
- package/dist/src/prediction/generated/waterx_account/account.js +1758 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +7 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +13 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +7 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +16 -0
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +6 -0
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +19 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +12 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +19 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/table.d.ts +24 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/table.js +31 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +27 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +75 -0
- package/dist/src/prediction/generated/waterx_account/direct_rule.js +78 -0
- package/dist/src/prediction/generated/waterx_account/events.d.ts +33 -0
- package/dist/src/prediction/generated/waterx_account/events.js +137 -0
- package/dist/src/prediction/generated/waterx_account/version.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_account/version.js +8 -0
- package/dist/src/prediction/generated/waterx_prediction/account_data.d.ts +327 -0
- package/dist/src/prediction/generated/waterx_prediction/account_data.js +405 -0
- package/dist/src/prediction/generated/waterx_prediction/admin.d.ts +5 -0
- package/dist/src/prediction/generated/waterx_prediction/admin.js +9 -0
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +60 -0
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +83 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +8 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.js +18 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +24 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +31 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/waterx_prediction/events.d.ts +22 -0
- package/dist/src/prediction/generated/waterx_prediction/events.js +179 -0
- package/dist/src/prediction/generated/waterx_prediction/global_config.d.ts +116 -0
- package/dist/src/prediction/generated/waterx_prediction/global_config.js +141 -0
- package/dist/src/prediction/generated/waterx_prediction/order.d.ts +200 -0
- package/dist/src/prediction/generated/waterx_prediction/order.js +284 -0
- package/dist/src/prediction/generated/waterx_prediction/outcome.d.ts +58 -0
- package/dist/src/prediction/generated/waterx_prediction/outcome.js +73 -0
- package/dist/src/prediction/generated/waterx_prediction/position.d.ts +160 -0
- package/dist/src/prediction/generated/waterx_prediction/position.js +214 -0
- package/dist/src/prediction/generated/waterx_prediction/version.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_prediction/version.js +8 -0
- package/dist/src/prediction/generated/waterx_prediction/view.d.ts +353 -0
- package/dist/src/prediction/generated/waterx_prediction/view.js +432 -0
- package/dist/src/prediction/generated/waterx_prediction/waterx_prediction.d.ts +1698 -0
- package/dist/src/prediction/generated/waterx_prediction/waterx_prediction.js +1733 -0
- package/dist/src/prediction/gift-link.d.ts +6 -0
- package/dist/src/prediction/gift-link.js +5 -0
- package/dist/src/prediction/gift.d.ts +223 -0
- package/dist/src/prediction/gift.js +451 -0
- package/dist/src/prediction/index.d.ts +29 -0
- package/dist/src/prediction/index.js +21 -0
- package/dist/src/prediction/prediction.d.ts +104 -0
- package/dist/src/prediction/prediction.js +317 -0
- package/dist/src/prediction/tx-builders.d.ts +44 -0
- package/dist/src/prediction/tx-builders.js +52 -0
- package/dist/src/prediction/types.d.ts +93 -0
- package/dist/src/prediction/types.js +1 -0
- package/dist/src/prediction/user/account.d.ts +2 -0
- package/dist/src/prediction/user/account.js +1 -0
- package/dist/src/prediction/user/admin.d.ts +6 -0
- package/dist/src/prediction/user/admin.js +3 -0
- package/dist/src/prediction/user/gift.d.ts +2 -0
- package/dist/src/prediction/user/gift.js +1 -0
- package/dist/src/prediction/user/index.d.ts +5 -0
- package/dist/src/prediction/user/index.js +3 -0
- package/dist/src/prediction/user/keeper.d.ts +2 -0
- package/dist/src/prediction/user/keeper.js +1 -0
- package/dist/src/prediction/user/order.d.ts +2 -0
- package/dist/src/prediction/user/order.js +1 -0
- package/dist/src/prediction/user/position.d.ts +2 -0
- package/dist/src/prediction/user/position.js +1 -0
- package/dist/src/prediction/utils/bcs.d.ts +1 -0
- package/dist/src/prediction/utils/bcs.js +1 -0
- package/dist/src/prediction/utils/index.d.ts +1 -0
- package/dist/src/prediction/utils/index.js +1 -0
- package/dist/src/prediction/utils.d.ts +30 -0
- package/dist/src/prediction/utils.js +177 -0
- package/dist/src/sdk.d.ts +18 -0
- package/dist/src/sdk.js +17 -0
- package/dist/src/tx-builders.d.ts +54 -0
- package/dist/src/tx-builders.js +141 -0
- package/dist/src/unified-client.d.ts +407 -0
- package/dist/src/unified-client.js +123 -0
- package/dist/src/user/account.d.ts +27 -0
- package/dist/src/user/account.js +34 -8
- package/dist/src/user/credit.d.ts +8 -14
- package/dist/src/user/credit.js +9 -23
- package/dist/src/user/custody.d.ts +4 -18
- package/dist/src/user/custody.js +14 -25
- package/dist/src/utils/consolidate-balance.d.ts +37 -0
- package/dist/src/utils/consolidate-balance.js +89 -0
- package/dist/src/utils/math.d.ts +86 -0
- package/dist/src/utils/math.js +100 -0
- package/dist/src/utils/pyth.d.ts +42 -7
- package/dist/src/utils/pyth.js +107 -31
- package/package.json +129 -34
package/README.md
CHANGED
|
@@ -1,204 +1,110 @@
|
|
|
1
1
|
# @waterx/sdk
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for the WaterX
|
|
3
|
+
TypeScript SDK for the WaterX protocol on Sui — **two product lines in one package**: **perpetuals** and **prediction markets**. Build PTBs with **gRPC** (`@mysten/sui`), run read-only **simulateTransaction** queries, and optional **Pyth** helpers.
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> Package name is `@waterx/sdk` (renamed from `@waterx/perp-sdk` in 2.3.0).
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Two lines, one package
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
pnpm install
|
|
11
|
-
pnpm build
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
Consumers:
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
pnpm add @waterx/sdk @mysten/sui
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
### Breaking changes (WLP high-level builders)
|
|
21
|
-
|
|
22
|
-
`buildMintWlpTx` and `buildSettleRedeemWlpTx` are **`async`** and return `Promise<Transaction>` (they resolve deposit / redeem coin oracle wiring). Callers must **`await`**:
|
|
9
|
+
The perp and prediction lines expose builder functions with **colliding names** (`placeOrder`, `createAccount`, `deposit`, …), so they are kept in separate namespaces:
|
|
23
10
|
|
|
24
11
|
```ts
|
|
25
|
-
|
|
26
|
-
const tx2 = await buildSettleRedeemWlpTx(client, { requestId: 1n });
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Size calculation requires explicit price
|
|
30
|
-
|
|
31
|
-
`buildOpenPositionTx` and `buildPlaceOrderTx` no longer fall back to hardcoded prices when computing position size from leverage. You must provide either **`size`** (exact) or **`approxPrice`** (USD price for leverage math). Omitting both throws.
|
|
32
|
-
|
|
33
|
-
### Naming: collateral on an open position
|
|
34
|
-
|
|
35
|
-
Move entry points are `deposit_collateral_request` / `withdraw_collateral_request`. The SDK exposes **`depositCollateral`** / **`withdrawCollateral`** as the preferred names; **`increaseCollateral`** / **`releaseCollateral`** remain as deprecated aliases (same parameters). High-level helpers: **`buildDepositCollateralTx`** / **`buildWithdrawCollateralTx`** (deprecated: `buildIncreaseCollateralTx` / `buildReleaseCollateralTx`).
|
|
36
|
-
|
|
37
|
-
Withdraw paths take **`collateralAmount`** for the size to pull from margin; **`amount`** is a deprecated alias (if both are passed, `collateralAmount` wins).
|
|
38
|
-
|
|
39
|
-
### UserAccount address in PTB params
|
|
40
|
-
|
|
41
|
-
Trading (`openPosition`, `closePosition`, …), account helpers (`depositToAccount`, delegates, …), high-level `build*Tx`, and orders (`placeOrder`, `cancelOrder`) all use **`accountObjectAddress`**: the **UserAccount object id** (hex). Trading paths pass it as `tx.pure.address`; registry calls use `tx.pure.id`. It is **not** a numeric registry index.
|
|
42
|
-
|
|
43
|
-
`getAccountsByOwner` returns a `string[]` of `accountObjectAddress`es (the on-chain `account::account_ids` view returns `vector<ID>`).
|
|
44
|
-
|
|
45
|
-
High-level `build*Tx` helpers also accept optional **`collateralTokenType`** (defaults to `WaterXConfig.usdcType`). Only token types wired in `resolveTokenPriceFeed` (`src/tx-builders.ts`) get automatic Pyth updates; extend there when the protocol adds collaterals.
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
## Initialize the client
|
|
50
|
-
|
|
51
|
-
All network I/O uses **gRPC** (`SuiGrpcClient`). Trading helpers require `bucketFrameworkPackageId` (Bucket `bucket_v2_framework` package) so the PTB can call `account::request`.
|
|
52
|
-
|
|
53
|
-
**Testnet (built-in constants):**
|
|
54
|
-
|
|
55
|
-
```ts
|
|
56
|
-
import { WaterXClient } from "@waterx/sdk";
|
|
57
|
-
|
|
58
|
-
const client = WaterXClient.testnet();
|
|
59
|
-
// optional: custom fullnode gRPC URL
|
|
60
|
-
// const client = WaterXClient.testnet({ grpcUrl: "https://fullnode.testnet.sui.io:443" });
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
**Custom config (any network):**
|
|
12
|
+
import { Client } from "@waterx/sdk";
|
|
64
13
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
packageId: "0x...", // your deployed waterx_perp package
|
|
71
|
-
globalConfig: "0x...",
|
|
72
|
-
// ...all other object IDs and token type strings
|
|
73
|
-
};
|
|
74
|
-
const client = new WaterXClient(config);
|
|
14
|
+
const client = await Client.create({ network: "TESTNET" });
|
|
15
|
+
client.perp.buildPlaceOrderTx(params); // perpetuals
|
|
16
|
+
client.predict.placeOrder(tx, params); // prediction markets
|
|
17
|
+
// raw line clients for signing/executing: client.perpClient / client.predictClient
|
|
18
|
+
// each line can target a different network: Client.create({ perp: { network: "MAINNET" }, predict: { network: "TESTNET" } })
|
|
75
19
|
```
|
|
76
20
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
## Examples
|
|
80
|
-
|
|
81
|
-
### Read-only: pool summary & WLP metrics
|
|
82
|
-
|
|
83
|
-
Uses gRPC `simulateTransaction` + BCS (no signer).
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
import { getPoolSummary, getWlpTotalSupply, getWlpTvlUsd, WaterXClient } from "@waterx/sdk";
|
|
21
|
+
Import surfaces:
|
|
87
22
|
|
|
88
|
-
|
|
23
|
+
| Import | What |
|
|
24
|
+
|--------|------|
|
|
25
|
+
| `@waterx/sdk` | `Client` (unified) + `perp` / `prediction` namespaces. Perp's API is also re-exported flat here (**deprecated** — prefer `client.perp` or the `perp` namespace; removed next major). |
|
|
26
|
+
| `@waterx/sdk/perp` | Perp line: `WaterXClient`, builders, fetch, Pyth/Wormhole utils. |
|
|
27
|
+
| `@waterx/sdk/prediction` | Prediction line: `PredictClient`, builders, fetch, utils. |
|
|
89
28
|
|
|
90
|
-
|
|
91
|
-
console.log("LP supply (raw):", pool.totalLpSupply.toString());
|
|
92
|
-
console.log("TVL (u128):", pool.tvlUsd.toString());
|
|
29
|
+
## Install
|
|
93
30
|
|
|
94
|
-
|
|
95
|
-
|
|
31
|
+
```bash
|
|
32
|
+
pnpm install
|
|
33
|
+
pnpm build
|
|
96
34
|
```
|
|
97
35
|
|
|
98
|
-
|
|
36
|
+
Consumers: `pnpm add @waterx/sdk @mysten/sui`
|
|
99
37
|
|
|
100
|
-
|
|
101
|
-
import { getAccountsByOwner, getPosition, positionExists, WaterXClient } from "@waterx/sdk";
|
|
102
|
-
|
|
103
|
-
const client = WaterXClient.testnet();
|
|
104
|
-
const owner = "0x..."; // Sui address
|
|
38
|
+
## Quickstart (unified client)
|
|
105
39
|
|
|
106
|
-
|
|
107
|
-
const accountObjectAddress = accounts[0]!;
|
|
108
|
-
|
|
109
|
-
const market = client.config.btcMarket;
|
|
110
|
-
const has = await positionExists(client, market, 0n);
|
|
111
|
-
if (has) {
|
|
112
|
-
const pos = await getPosition(client, market, 0n);
|
|
113
|
-
// `accountObjectAddress` = on-chain `user_address`; `marketIndex` = pool row index (not Market object id).
|
|
114
|
-
console.log(pos.accountObjectAddress, pos.marketIndex, pos.sizeAmount);
|
|
115
|
-
}
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### High-level PTB: open position (Pyth + testnet IDs wired in)
|
|
119
|
-
|
|
120
|
-
Returns a `Transaction` you sign and execute with the same client.
|
|
40
|
+
`Client.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 (the line client, or a frontend wallet), so multi-step Pyth injection and wallet flows keep working.
|
|
121
41
|
|
|
122
42
|
```ts
|
|
123
|
-
import {
|
|
124
|
-
import {
|
|
125
|
-
|
|
126
|
-
const client =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const tx = await
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
43
|
+
import { Client, rawPrice } from "@waterx/sdk";
|
|
44
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
45
|
+
|
|
46
|
+
const client = await Client.create({ network: "TESTNET" });
|
|
47
|
+
const signer = /* your Ed25519Keypair or wallet Signer */;
|
|
48
|
+
|
|
49
|
+
// --- Perp: place a market order ---
|
|
50
|
+
const tx = await client.perp.buildPlaceOrderTx({
|
|
51
|
+
ticker: "BTCUSD",
|
|
52
|
+
collateralType: client.perpClient.creditType(),
|
|
53
|
+
accountId: "0x...", // UserAccount object id (hex)
|
|
54
|
+
main: {
|
|
55
|
+
isLong: true,
|
|
56
|
+
isStopOrder: false,
|
|
57
|
+
reduceOnly: false,
|
|
58
|
+
size: rawPrice(0.001),
|
|
59
|
+
acceptablePrice: rawPrice(100_000),
|
|
60
|
+
collateralAmount: 5_000_000n,
|
|
61
|
+
},
|
|
62
|
+
preOrders: [],
|
|
137
63
|
});
|
|
64
|
+
await client.perpClient.signAndExecuteTransaction({ transaction: tx, signer });
|
|
138
65
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
143
|
-
console.log(result.digest);
|
|
66
|
+
// --- Prediction: same pattern under client.predict ---
|
|
67
|
+
const ptx = new Transaction();
|
|
68
|
+
client.predict.placeOrder(ptx, params);
|
|
69
|
+
await client.predictClient.signAndExecuteTransaction({ transaction: ptx, signer });
|
|
144
70
|
```
|
|
145
71
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
Create a `Transaction`, append Pyth / aggregator calls (`updatePythPrices`, `buildPythRuleFeedCalls` from this package — mirror `src/tx-builders.ts`), then call `openPosition(client, tx, openPositionParams)` (or any other builder in `src/user/`). Params are typed as `OpenPositionParams`, `ClosePositionParams`, etc.
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
## API overview
|
|
72
|
+
> Account creation is shared: both lines build accounts via the same on-chain `waterx_account` system, so an account created through `client.perp.createAccount` is usable by `client.predict.*` (and vice versa).
|
|
153
73
|
|
|
154
|
-
|
|
74
|
+
## Per-line clients
|
|
155
75
|
|
|
156
|
-
|
|
157
|
-
| ----------------------- | --------------------------------------------------------------------- |
|
|
158
|
-
| `WaterXClient` | gRPC client, `simulate()`, `signAndExecuteTransaction()` |
|
|
159
|
-
| `createTestnetConfig()` | Default testnet package/object/token IDs + Pyth config |
|
|
160
|
-
| `WaterXConfig` | Full config; must include `bucketFrameworkPackageId` for trading PTBs |
|
|
76
|
+
If you only need one line, construct it directly (both factories are **async** — they fetch deployment config):
|
|
161
77
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
166
|
-
| Shared | `accountSenderRequest(tx, client)` |
|
|
167
|
-
| Trading | `openPosition`, `closePosition`, `increasePosition`, `decreasePosition`, `depositCollateral`, `withdrawCollateral` (`increaseCollateral` / `releaseCollateral` deprecated), `liquidate`, `matchOrders`, `updateFundingRate` |
|
|
168
|
-
| Orders | `placeOrder`, `cancelOrder` |
|
|
169
|
-
| WLP | `mintWlp`, `requestRedeemWlp`, `cancelRedeemWlp`, `settleRedeemWlp` |
|
|
170
|
-
| Account | `createAccount`, `depositToAccount`, `receiveCoin`, `transferAccount`, `addDelegate`, `removeDelegate`, `updateDelegatePermissions` |
|
|
171
|
-
| Referral | `setReferralCode`, `useReferralCode`, `registerReferralCode`, `bindReferral` |
|
|
172
|
-
|
|
173
|
-
Param types: `OpenPositionParams`, `IncreasePositionParams`, `DecreasePositionParams`, etc. (see `src/index.ts`).
|
|
174
|
-
|
|
175
|
-
### Read-only queries (simulate + BCS)
|
|
176
|
-
|
|
177
|
-
| Area | Functions |
|
|
178
|
-
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
179
|
-
| Account | `getAccountsByOwner`, `getAccountDelegates`, `getAccountObjectId` (deprecated — use `accountObjectAddress` directly), `getAccountCoins`, `getAccountBalance`, `selectCoinsForAmount` |
|
|
180
|
-
| Market / pool | `getMarketSummary` (`view::market_summary<LP>` — optional `typeArgs`: LP type string or `{ lpTokenType? }` only), `getPoolSummary`, `getWlpTotalSupply`, `getWlpTvlUsd`, `getTokenPoolSummary` |
|
|
181
|
-
| Position | `getPosition`, `positionExists` (same LP type-arg rules as `getMarketSummary`) |
|
|
78
|
+
```ts
|
|
79
|
+
import { WaterXClient } from "@waterx/sdk/perp";
|
|
80
|
+
import { PredictClient } from "@waterx/sdk/prediction";
|
|
182
81
|
|
|
183
|
-
|
|
82
|
+
const perp = await WaterXClient.create("TESTNET"); // or WaterXClient.testnet()
|
|
83
|
+
const predict = await PredictClient.create("TESTNET"); // or PredictClient.testnet()
|
|
84
|
+
```
|
|
184
85
|
|
|
185
|
-
|
|
86
|
+
Read-only queries use gRPC `simulateTransaction` (no signer) — the `getX` view helpers, e.g. `await perp.simulate(tx)` or `getMarketData(perp, …)`.
|
|
186
87
|
|
|
187
|
-
|
|
88
|
+
## Recipes & full surface
|
|
188
89
|
|
|
189
|
-
|
|
90
|
+
To avoid doc drift, per-action usage lives in maintained, lint-checked code rather than this README:
|
|
190
91
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
92
|
+
- **Perp recipes:** [`examples/`](./examples) — ~30 runnable scripts (place orders, WLP mint/redeem, account/delegates, reads). Each uses `buildClient()` + a builder + `simThenMaybeExecute`.
|
|
93
|
+
- **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.
|
|
194
95
|
|
|
195
|
-
|
|
96
|
+
Perp `build*Tx` helpers are Pyth-backed (`async`; they refresh feeds before the call). Pyth/Wormhole helpers live in [`src/utils/`](./src/utils).
|
|
196
97
|
|
|
197
98
|
## Development
|
|
198
99
|
|
|
199
|
-
| Command
|
|
200
|
-
|
|
|
201
|
-
| `pnpm typecheck`
|
|
202
|
-
| `pnpm test`
|
|
203
|
-
| `pnpm
|
|
204
|
-
| `pnpm
|
|
100
|
+
| Command | Use |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| `pnpm typecheck` | Typecheck the whole tree |
|
|
103
|
+
| `pnpm test` / `pnpm test:unit` | Unit tests (perp + prediction) |
|
|
104
|
+
| `pnpm test:e2e` | Testnet simulate e2e (perp + prediction) |
|
|
105
|
+
| `pnpm test:integration` | On-chain integration (needs `SUI_PRIVATE_KEY`; local-only) |
|
|
106
|
+
| `pnpm lint` / `pnpm format` | ESLint + Prettier |
|
|
107
|
+
| `pnpm codegen` | Regenerate `src/generated` from Move |
|
|
108
|
+
| `pnpm seed:testnet` | Seed prediction testnet fixtures (needs `SUI_PRIVATE_KEY`) |
|
|
109
|
+
|
|
110
|
+
Tests are split per line under `test/perp/` and `test/prediction/`, each with `unit` / `e2e` / `integration` tiers. See the per-line `README.md` in each.
|
package/dist/src/client.d.ts
CHANGED
|
@@ -69,8 +69,46 @@ export declare class WaterXClient {
|
|
|
69
69
|
feed_id: string;
|
|
70
70
|
price_info_object: string;
|
|
71
71
|
};
|
|
72
|
-
/**
|
|
73
|
-
|
|
72
|
+
/**
|
|
73
|
+
* True when `ticker` is priced by `constant_rule` (a constant pin,
|
|
74
|
+
* e.g. `USDCUSD → $1`) rather than Pyth. Such tickers are fed via
|
|
75
|
+
* `constant_rule::feed` and need no Pyth update; see {@link refreshOraclePrices}.
|
|
76
|
+
*
|
|
77
|
+
* All-or-nothing, mirroring {@link getSupraRule} and the keeper: only routes a
|
|
78
|
+
* ticker to the constant rule when the rule is FULLY wired (`published_at` +
|
|
79
|
+
* `config` present). A half-populated block — a `feeds` entry listed before the
|
|
80
|
+
* rule is deployed, a realistic mid-rollout state — would otherwise make this
|
|
81
|
+
* true while {@link aggregateTicker} throws, aborting the whole price-refresh PTB
|
|
82
|
+
* instead of safely falling back to Pyth.
|
|
83
|
+
*
|
|
84
|
+
* Whether a constant ticker is *also* Pyth-fed (the dual-feed transition state)
|
|
85
|
+
* or constant-only is not a separate flag — it falls out of whether the ticker
|
|
86
|
+
* still has a `pyth_rule.feeds` entry. {@link aggregateTicker} feeds each rule the
|
|
87
|
+
* ticker is configured for, so no `isDualFeed` / `isConstantOnly` predicate is needed.
|
|
88
|
+
*/
|
|
89
|
+
isConstantTicker(ticker: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* The `supra_rule` config when it is deployed, enabled, and fully wired
|
|
92
|
+
* (`config` + `oracle_holder`), else `undefined`. When present, callers feed
|
|
93
|
+
* `supra_rule::feed` as a second weighted rule alongside Pyth on the same
|
|
94
|
+
* collector; see {@link refreshOraclePrices}. Default-off, so a Pyth-only
|
|
95
|
+
* deployment returns `undefined` here.
|
|
96
|
+
*/
|
|
97
|
+
getSupraRule(): {
|
|
98
|
+
published_at: string;
|
|
99
|
+
config: string;
|
|
100
|
+
oracle_holder: string;
|
|
101
|
+
} | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Resolve a WLP pool token's fully-qualified Move type.
|
|
104
|
+
*
|
|
105
|
+
* `wlp.pool_tokens` is keyed by **oracle ticker** (e.g. `"USDCUSD"`) — the
|
|
106
|
+
* Rust keeper requires this, since it reuses each key to look up the token's
|
|
107
|
+
* aggregator + pyth feed. For ergonomics this also accepts the coin symbol
|
|
108
|
+
* (the trailing `::Struct` segment, e.g. `"USD"` → `…::usd::USD`): an exact
|
|
109
|
+
* ticker hit wins, otherwise we match by coin name. Throws if neither hits.
|
|
110
|
+
*/
|
|
111
|
+
getPoolTokenType(tickerOrName: string): string;
|
|
74
112
|
/** Fully-qualified WLP coin type derived from `wlp.original_id`. */
|
|
75
113
|
wlpType(): string;
|
|
76
114
|
/**
|
package/dist/src/client.js
CHANGED
|
@@ -117,12 +117,61 @@ export class WaterXClient {
|
|
|
117
117
|
throw new Error(`No pyth feed listed for ticker: ${ticker}`);
|
|
118
118
|
return f;
|
|
119
119
|
}
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
/**
|
|
121
|
+
* True when `ticker` is priced by `constant_rule` (a constant pin,
|
|
122
|
+
* e.g. `USDCUSD → $1`) rather than Pyth. Such tickers are fed via
|
|
123
|
+
* `constant_rule::feed` and need no Pyth update; see {@link refreshOraclePrices}.
|
|
124
|
+
*
|
|
125
|
+
* All-or-nothing, mirroring {@link getSupraRule} and the keeper: only routes a
|
|
126
|
+
* ticker to the constant rule when the rule is FULLY wired (`published_at` +
|
|
127
|
+
* `config` present). A half-populated block — a `feeds` entry listed before the
|
|
128
|
+
* rule is deployed, a realistic mid-rollout state — would otherwise make this
|
|
129
|
+
* true while {@link aggregateTicker} throws, aborting the whole price-refresh PTB
|
|
130
|
+
* instead of safely falling back to Pyth.
|
|
131
|
+
*
|
|
132
|
+
* Whether a constant ticker is *also* Pyth-fed (the dual-feed transition state)
|
|
133
|
+
* or constant-only is not a separate flag — it falls out of whether the ticker
|
|
134
|
+
* still has a `pyth_rule.feeds` entry. {@link aggregateTicker} feeds each rule the
|
|
135
|
+
* ticker is configured for, so no `isDualFeed` / `isConstantOnly` predicate is needed.
|
|
136
|
+
*/
|
|
137
|
+
isConstantTicker(ticker) {
|
|
138
|
+
const c = this.config.packages.constant_rule;
|
|
139
|
+
if (!c?.published_at || !c.config)
|
|
140
|
+
return false;
|
|
141
|
+
return c.feeds?.[ticker] !== undefined;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The `supra_rule` config when it is deployed, enabled, and fully wired
|
|
145
|
+
* (`config` + `oracle_holder`), else `undefined`. When present, callers feed
|
|
146
|
+
* `supra_rule::feed` as a second weighted rule alongside Pyth on the same
|
|
147
|
+
* collector; see {@link refreshOraclePrices}. Default-off, so a Pyth-only
|
|
148
|
+
* deployment returns `undefined` here.
|
|
149
|
+
*/
|
|
150
|
+
getSupraRule() {
|
|
151
|
+
const s = this.config.packages.supra_rule;
|
|
152
|
+
if (!s?.enabled || !s.published_at || !s.config || !s.oracle_holder)
|
|
153
|
+
return undefined;
|
|
154
|
+
return { published_at: s.published_at, config: s.config, oracle_holder: s.oracle_holder };
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Resolve a WLP pool token's fully-qualified Move type.
|
|
158
|
+
*
|
|
159
|
+
* `wlp.pool_tokens` is keyed by **oracle ticker** (e.g. `"USDCUSD"`) — the
|
|
160
|
+
* Rust keeper requires this, since it reuses each key to look up the token's
|
|
161
|
+
* aggregator + pyth feed. For ergonomics this also accepts the coin symbol
|
|
162
|
+
* (the trailing `::Struct` segment, e.g. `"USD"` → `…::usd::USD`): an exact
|
|
163
|
+
* ticker hit wins, otherwise we match by coin name. Throws if neither hits.
|
|
164
|
+
*/
|
|
165
|
+
getPoolTokenType(tickerOrName) {
|
|
166
|
+
const poolTokens = this.config.packages.wlp?.pool_tokens ?? {};
|
|
167
|
+
const exact = poolTokens[tickerOrName];
|
|
168
|
+
if (exact)
|
|
169
|
+
return exact;
|
|
170
|
+
for (const t of Object.values(poolTokens)) {
|
|
171
|
+
if (typeof t === "string" && t.split("::").pop() === tickerOrName)
|
|
172
|
+
return t;
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`No pool token registered for ticker/name: ${tickerOrName}`);
|
|
126
175
|
}
|
|
127
176
|
/** Fully-qualified WLP coin type derived from `wlp.original_id`. */
|
|
128
177
|
wlpType() {
|
package/dist/src/config.d.ts
CHANGED
|
@@ -25,6 +25,48 @@ export interface PythRulePackage extends BasePackageEntry {
|
|
|
25
25
|
export interface PythSponsorRulePackage extends BasePackageEntry {
|
|
26
26
|
pyth_sponsor: string;
|
|
27
27
|
}
|
|
28
|
+
/** Per-ticker `constant_rule` feed entry (mirrors the `pyth_rule.feeds` shape). */
|
|
29
|
+
export interface ConstantFeedEntry {
|
|
30
|
+
/**
|
|
31
|
+
* Constant 1e9-scaled price (decimal string), mirroring the on-chain
|
|
32
|
+
* `Config.prices` value (e.g. `"1000000000"` for $1). Informational off-chain —
|
|
33
|
+
* the on-chain `constant_rule::feed` reads the price from `Config`; the SDK only
|
|
34
|
+
* keys routing off the presence of the entry.
|
|
35
|
+
*/
|
|
36
|
+
price: string;
|
|
37
|
+
}
|
|
38
|
+
export interface WaterxConstantRulePackage extends BasePackageEntry {
|
|
39
|
+
/** Shared `constant_rule::Config` holding the per-ticker constant prices. */
|
|
40
|
+
config: string;
|
|
41
|
+
/**
|
|
42
|
+
* Oracle ticker → constant feed entry, mirroring `pyth_rule.feeds`. A ticker
|
|
43
|
+
* present here is fed via `constant_rule::feed` instead of (steady state) or
|
|
44
|
+
* alongside (dual-feed) `pyth_rule::feed` (e.g. `USDCUSD → { price: "1000000000" }`).
|
|
45
|
+
*/
|
|
46
|
+
feeds?: Record<string, ConstantFeedEntry>;
|
|
47
|
+
}
|
|
48
|
+
/** Per-ticker `supra_rule` feed entry (mirrors the `pyth_rule.feeds` shape). */
|
|
49
|
+
export interface SupraFeedEntry {
|
|
50
|
+
/** Supra pair id (mirrors the on-chain `Config`; informational off-chain). */
|
|
51
|
+
pair_id: number;
|
|
52
|
+
/** Optional per-ticker freshness tolerance override (ms). */
|
|
53
|
+
tolerance_ms?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface SupraRulePackage extends BasePackageEntry {
|
|
56
|
+
/** Shared `supra_rule::Config` (per-symbol Supra pair_id + freshness tolerance). */
|
|
57
|
+
config: string;
|
|
58
|
+
/** Supra `OracleHolder` shared object id (network-specific). Required to feed. */
|
|
59
|
+
oracle_holder?: string;
|
|
60
|
+
/** Oracle ticker → Supra feed entry (mirrors the on-chain `Config`; informational). */
|
|
61
|
+
feeds?: Record<string, SupraFeedEntry>;
|
|
62
|
+
/**
|
|
63
|
+
* When true AND `config` + `oracle_holder` are set, `refreshOraclePrices`
|
|
64
|
+
* feeds `supra_rule` on the same `PriceCollector` as Pyth before `aggregate`
|
|
65
|
+
* (a second weighted rule). Defaults to **false** so a Pyth-only deployment
|
|
66
|
+
* is unaffected — flip on only after `weight_threshold`/feeders are ready.
|
|
67
|
+
*/
|
|
68
|
+
enabled?: boolean;
|
|
69
|
+
}
|
|
28
70
|
export interface WxaAccountPackage extends BasePackageEntry {
|
|
29
71
|
admin_cap: string;
|
|
30
72
|
account_registry: string;
|
|
@@ -93,6 +135,8 @@ export interface WaterxCreditPackage {
|
|
|
93
135
|
}
|
|
94
136
|
/** One backing-asset row on the native custody vault (PSM). */
|
|
95
137
|
export interface NativeCustodyAsset {
|
|
138
|
+
/** Human-readable asset label, e.g. `"MOCK_USDC"` / `"USDC"` (from `add_asset`). */
|
|
139
|
+
name?: string;
|
|
96
140
|
/** Fully-qualified backing asset Move type `T`. */
|
|
97
141
|
type: string;
|
|
98
142
|
decimal: number;
|
|
@@ -123,7 +167,12 @@ export interface WormholeBridgePackage {
|
|
|
123
167
|
max_mint_per_tx?: string;
|
|
124
168
|
hourly_burn_limit?: string;
|
|
125
169
|
max_burn_per_tx?: string;
|
|
126
|
-
|
|
170
|
+
/**
|
|
171
|
+
* @deprecated EVM emitter↔token config now lives solely under `evm.bridge.chains`
|
|
172
|
+
* (deposit_vault = emitter, wormhole_chain_id = chain key). The runtime allowlist is
|
|
173
|
+
* read from the on-chain `Bridge` object, not from config. Kept optional for back-compat.
|
|
174
|
+
*/
|
|
175
|
+
trusted_emitters?: TrustedEmitterRow[];
|
|
127
176
|
/** Shared `Bridge` (phase-5 output). */
|
|
128
177
|
bridge?: string;
|
|
129
178
|
/**
|
|
@@ -150,6 +199,8 @@ export interface WaterXPackages {
|
|
|
150
199
|
waterx_referral?: WaterxReferralPackage;
|
|
151
200
|
pyth_rule: PythRulePackage;
|
|
152
201
|
pyth_sponsor_rule?: PythSponsorRulePackage;
|
|
202
|
+
constant_rule?: WaterxConstantRulePackage;
|
|
203
|
+
supra_rule?: SupraRulePackage;
|
|
153
204
|
waterx_account: WxaAccountPackage;
|
|
154
205
|
waterx_oracle: WaterxOraclePackage;
|
|
155
206
|
waterx_perp: WaterxPerpPackage;
|
|
@@ -211,9 +262,17 @@ export interface WaterXConfig {
|
|
|
211
262
|
export interface LoadConfigOptions {
|
|
212
263
|
/**
|
|
213
264
|
* Override the default config URL. Use this to point at a staging branch
|
|
214
|
-
* (`?ref=staging`) or a local mirror during development.
|
|
265
|
+
* (`?ref=staging`) or a local mirror during development. Takes precedence
|
|
266
|
+
* over {@link configRef}.
|
|
215
267
|
*/
|
|
216
268
|
configUrl?: string;
|
|
269
|
+
/**
|
|
270
|
+
* Pin the canonical config to a specific git ref — a commit SHA, branch,
|
|
271
|
+
* or tag — instead of the default `main` branch. Resolves to
|
|
272
|
+
* `https://raw.githubusercontent.com/WaterXProtocol/waterx-config/<ref>/<network>.json`.
|
|
273
|
+
* Ignored when {@link configUrl} is set.
|
|
274
|
+
*/
|
|
275
|
+
configRef?: string;
|
|
217
276
|
/**
|
|
218
277
|
* Reuse a previously-fetched config from the in-memory cache (keyed by
|
|
219
278
|
* the effective URL). Default: false (always fetch fresh).
|
|
@@ -224,6 +283,10 @@ export interface LoadConfigOptions {
|
|
|
224
283
|
/** Optional request timeout in ms. Default 10_000. */
|
|
225
284
|
timeoutMs?: number;
|
|
226
285
|
}
|
|
227
|
-
|
|
286
|
+
/**
|
|
287
|
+
* Build the canonical config URL for `network`, optionally pinned to a
|
|
288
|
+
* specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
|
|
289
|
+
*/
|
|
290
|
+
export declare function defaultConfigUrl(network: Network, ref?: string): string;
|
|
228
291
|
export declare function clearConfigCache(): void;
|
|
229
292
|
export declare function loadConfig(network: Network, opts?: LoadConfigOptions): Promise<WaterXConfig>;
|
package/dist/src/config.js
CHANGED
|
@@ -34,16 +34,22 @@ export const WORMHOLE_DEFAULTS = {
|
|
|
34
34
|
wormholescan_api: "https://api.testnet.wormholescan.io/api/v1",
|
|
35
35
|
},
|
|
36
36
|
};
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const CONFIG_REPO_RAW_BASE = "https://raw.githubusercontent.com/WaterXProtocol/waterx-config";
|
|
38
|
+
/** Default git ref for the canonical config when none is pinned. */
|
|
39
|
+
const DEFAULT_CONFIG_REF = "main";
|
|
40
|
+
/**
|
|
41
|
+
* Build the canonical config URL for `network`, optionally pinned to a
|
|
42
|
+
* specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
|
|
43
|
+
*/
|
|
44
|
+
export function defaultConfigUrl(network, ref = DEFAULT_CONFIG_REF) {
|
|
45
|
+
return `${CONFIG_REPO_RAW_BASE}/${ref}/${network.toLowerCase()}.json`;
|
|
40
46
|
}
|
|
41
47
|
const cache = new Map();
|
|
42
48
|
export function clearConfigCache() {
|
|
43
49
|
cache.clear();
|
|
44
50
|
}
|
|
45
51
|
export async function loadConfig(network, opts = {}) {
|
|
46
|
-
const url = opts.configUrl ?? defaultConfigUrl(network);
|
|
52
|
+
const url = opts.configUrl ?? defaultConfigUrl(network, opts.configRef);
|
|
47
53
|
if (opts.cache && cache.has(url)) {
|
|
48
54
|
return cache.get(url);
|
|
49
55
|
}
|
package/dist/src/constants.d.ts
CHANGED
|
@@ -62,3 +62,9 @@ export declare const ACTION_ADD_PRE_ORDER = 11;
|
|
|
62
62
|
export declare const MS_PER_YEAR: number;
|
|
63
63
|
/** Zero-address placeholder used as the sender in dry-run / simulate calls. */
|
|
64
64
|
export declare const DRY_RUN_SENDER = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
65
|
+
/**
|
|
66
|
+
* Well-known address of Sui's native funds-accumulator root shared object
|
|
67
|
+
* (`@0xacc` in the framework). Pass this to `request_deposit_from_funds<T>`
|
|
68
|
+
* to drain `Balance<T>` parked at an account's address.
|
|
69
|
+
*/
|
|
70
|
+
export declare const ACCUMULATOR_ROOT = "0xacc";
|
package/dist/src/constants.js
CHANGED
|
@@ -69,3 +69,9 @@ export const MS_PER_YEAR = 365 * 24 * 60 * 60 * 1000;
|
|
|
69
69
|
// ======== Misc ========
|
|
70
70
|
/** Zero-address placeholder used as the sender in dry-run / simulate calls. */
|
|
71
71
|
export const DRY_RUN_SENDER = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
72
|
+
/**
|
|
73
|
+
* Well-known address of Sui's native funds-accumulator root shared object
|
|
74
|
+
* (`@0xacc` in the framework). Pass this to `request_deposit_from_funds<T>`
|
|
75
|
+
* to drain `Balance<T>` parked at an account's address.
|
|
76
|
+
*/
|
|
77
|
+
export const ACCUMULATOR_ROOT = "0xacc";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared `waterx_account` PTB builders.
|
|
3
|
+
*
|
|
4
|
+
* Perp and prediction both create/operate accounts through the **same** on-chain
|
|
5
|
+
* `waterx_account` system (same package + `AccountRegistry`), so the actual PTB
|
|
6
|
+
* calls are assembled here once. Each product line resolves the deployment
|
|
7
|
+
* coordinates (`WxaAccountRef`) and builds its own `senderRequest` (via its own
|
|
8
|
+
* account-request helper), then delegates the moveCall to these functions.
|
|
9
|
+
*
|
|
10
|
+
* These builders are raw `tx.moveCall(...)` (no generated-bindings dependency),
|
|
11
|
+
* so the module is shared by both `src/user/account.ts` (perp) and
|
|
12
|
+
* `src/prediction/account.ts` (prediction) without coupling to either line's
|
|
13
|
+
* generated code.
|
|
14
|
+
*/
|
|
15
|
+
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
16
|
+
/** Resolved `waterx_account` deployment coordinates (each line resolves these from its own client). */
|
|
17
|
+
export interface WxaAccountRef {
|
|
18
|
+
/** `waterx_account` package id (`published_at`). */
|
|
19
|
+
packageId: string;
|
|
20
|
+
/** `AccountRegistry` shared-object id. */
|
|
21
|
+
registry: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `waterx_account::account::create_account`. Returns the new account id
|
|
25
|
+
* (Move return value). `senderRequest` is the `account::request` hot-potato the
|
|
26
|
+
* caller built with its own account-request helper.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createAccountCall(tx: Transaction, ref: WxaAccountRef, params: {
|
|
29
|
+
senderRequest: TransactionArgument;
|
|
30
|
+
alias: string;
|
|
31
|
+
}): TransactionArgument;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared `waterx_account` PTB builders.
|
|
3
|
+
*
|
|
4
|
+
* Perp and prediction both create/operate accounts through the **same** on-chain
|
|
5
|
+
* `waterx_account` system (same package + `AccountRegistry`), so the actual PTB
|
|
6
|
+
* calls are assembled here once. Each product line resolves the deployment
|
|
7
|
+
* coordinates (`WxaAccountRef`) and builds its own `senderRequest` (via its own
|
|
8
|
+
* account-request helper), then delegates the moveCall to these functions.
|
|
9
|
+
*
|
|
10
|
+
* These builders are raw `tx.moveCall(...)` (no generated-bindings dependency),
|
|
11
|
+
* so the module is shared by both `src/user/account.ts` (perp) and
|
|
12
|
+
* `src/prediction/account.ts` (prediction) without coupling to either line's
|
|
13
|
+
* generated code.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* `waterx_account::account::create_account`. Returns the new account id
|
|
17
|
+
* (Move return value). `senderRequest` is the `account::request` hot-potato the
|
|
18
|
+
* caller built with its own account-request helper.
|
|
19
|
+
*/
|
|
20
|
+
export function createAccountCall(tx, ref, params) {
|
|
21
|
+
const [accountId] = tx.moveCall({
|
|
22
|
+
target: `${ref.packageId}::account::create_account`,
|
|
23
|
+
arguments: [tx.object(ref.registry), params.senderRequest, tx.pure.string(params.alias)],
|
|
24
|
+
});
|
|
25
|
+
return accountId;
|
|
26
|
+
}
|