@waterx/sdk 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +204 -0
- package/dist/src/client.d.ts +109 -0
- package/dist/src/client.js +197 -0
- package/dist/src/config.d.ts +229 -0
- package/dist/src/config.js +107 -0
- package/dist/src/constants.d.ts +64 -0
- package/dist/src/constants.js +71 -0
- package/dist/src/fetch.d.ts +144 -0
- package/dist/src/fetch.js +419 -0
- package/dist/src/generated/bucket_v2_framework/account.d.ts +107 -0
- package/dist/src/generated/bucket_v2_framework/account.js +129 -0
- package/dist/src/generated/bucket_v2_framework/deps/std/type_name.d.ts +17 -0
- package/dist/src/generated/bucket_v2_framework/deps/std/type_name.js +19 -0
- package/dist/src/generated/bucket_v2_framework/deps/sui/balance.d.ts +12 -0
- package/dist/src/generated/bucket_v2_framework/deps/sui/balance.js +14 -0
- package/dist/src/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/bucket_v2_framework/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/bucket_v2_framework/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/generated/bucket_v2_framework/deps/sui/vec_set.js +19 -0
- package/dist/src/generated/bucket_v2_framework/double.d.ts +384 -0
- package/dist/src/generated/bucket_v2_framework/double.js +466 -0
- package/dist/src/generated/bucket_v2_framework/float.d.ts +364 -0
- package/dist/src/generated/bucket_v2_framework/float.js +440 -0
- package/dist/src/generated/bucket_v2_framework/liability.d.ts +197 -0
- package/dist/src/generated/bucket_v2_framework/liability.js +205 -0
- package/dist/src/generated/bucket_v2_framework/linked_table.d.ts +384 -0
- package/dist/src/generated/bucket_v2_framework/linked_table.js +382 -0
- package/dist/src/generated/bucket_v2_framework/sheet.d.ts +424 -0
- package/dist/src/generated/bucket_v2_framework/sheet.js +344 -0
- package/dist/src/generated/native_custody/custody_vault.d.ts +572 -0
- package/dist/src/generated/native_custody/custody_vault.js +483 -0
- package/dist/src/generated/native_custody/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/native_custody/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/native_custody/deps/bucket_v2_framework/liability.d.ts +11 -0
- package/dist/src/generated/native_custody/deps/bucket_v2_framework/liability.js +13 -0
- package/dist/src/generated/native_custody/deps/bucket_v2_framework/sheet.d.ts +49 -0
- package/dist/src/generated/native_custody/deps/bucket_v2_framework/sheet.js +18 -0
- package/dist/src/generated/native_custody/deps/std/type_name.d.ts +17 -0
- package/dist/src/generated/native_custody/deps/std/type_name.js +19 -0
- package/dist/src/generated/native_custody/deps/sui/balance.d.ts +12 -0
- package/dist/src/generated/native_custody/deps/sui/balance.js +14 -0
- package/dist/src/generated/native_custody/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/native_custody/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/native_custody/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/generated/native_custody/deps/sui/vec_set.js +19 -0
- package/dist/src/generated/native_custody/events.d.ts +36 -0
- package/dist/src/generated/native_custody/events.js +36 -0
- package/dist/src/generated/pyth_sponsor_rule/deps/sui/balance.d.ts +12 -0
- package/dist/src/generated/pyth_sponsor_rule/deps/sui/balance.js +14 -0
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +68 -0
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +74 -0
- package/dist/src/generated/utils/index.d.ts +30 -0
- package/dist/src/generated/utils/index.js +157 -0
- package/dist/src/generated/waterx_account/account.d.ts +1818 -0
- package/dist/src/generated/waterx_account/account.js +1723 -0
- package/dist/src/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +11 -0
- package/dist/src/generated/waterx_account/deps/bucket_v2_framework/liability.js +13 -0
- package/dist/src/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +49 -0
- package/dist/src/generated/waterx_account/deps/bucket_v2_framework/sheet.js +18 -0
- package/dist/src/generated/waterx_account/deps/std/type_name.d.ts +17 -0
- package/dist/src/generated/waterx_account/deps/std/type_name.js +19 -0
- package/dist/src/generated/waterx_account/deps/sui/balance.d.ts +12 -0
- package/dist/src/generated/waterx_account/deps/sui/balance.js +14 -0
- package/dist/src/generated/waterx_account/deps/sui/object_table.d.ts +17 -0
- package/dist/src/generated/waterx_account/deps/sui/object_table.js +19 -0
- package/dist/src/generated/waterx_account/deps/sui/table.d.ts +29 -0
- package/dist/src/generated/waterx_account/deps/sui/table.js +31 -0
- package/dist/src/generated/waterx_account/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_account/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_account/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/generated/waterx_account/deps/sui/vec_set.js +19 -0
- package/dist/src/generated/waterx_account/direct_rule.d.ts +77 -0
- package/dist/src/generated/waterx_account/direct_rule.js +78 -0
- package/dist/src/generated/waterx_account/events.d.ts +180 -0
- package/dist/src/generated/waterx_account/events.js +156 -0
- package/dist/src/generated/waterx_account/version.d.ts +10 -0
- package/dist/src/generated/waterx_account/version.js +8 -0
- package/dist/src/generated/waterx_credit/credit_registry.d.ts +708 -0
- package/dist/src/generated/waterx_credit/credit_registry.js +658 -0
- package/dist/src/generated/waterx_credit/deps/std/type_name.d.ts +17 -0
- package/dist/src/generated/waterx_credit/deps/std/type_name.js +19 -0
- package/dist/src/generated/waterx_credit/deps/sui/table.d.ts +29 -0
- package/dist/src/generated/waterx_credit/deps/sui/table.js +31 -0
- package/dist/src/generated/waterx_credit/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_credit/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_credit/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/generated/waterx_credit/deps/sui/vec_set.js +19 -0
- package/dist/src/generated/waterx_credit/limited_supply.d.ts +107 -0
- package/dist/src/generated/waterx_credit/limited_supply.js +131 -0
- package/dist/src/generated/waterx_oracle/aggregator.d.ts +211 -0
- package/dist/src/generated/waterx_oracle/aggregator.js +213 -0
- package/dist/src/generated/waterx_oracle/collector.d.ts +119 -0
- package/dist/src/generated/waterx_oracle/collector.js +105 -0
- package/dist/src/generated/waterx_oracle/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/waterx_oracle/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/waterx_oracle/deps/std/type_name.d.ts +17 -0
- package/dist/src/generated/waterx_oracle/deps/std/type_name.js +19 -0
- package/dist/src/generated/waterx_oracle/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_oracle/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_oracle/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/generated/waterx_oracle/deps/sui/vec_set.js +19 -0
- package/dist/src/generated/waterx_oracle/oracle.d.ts +298 -0
- package/dist/src/generated/waterx_oracle/oracle.js +323 -0
- package/dist/src/generated/waterx_oracle/version.d.ts +10 -0
- package/dist/src/generated/waterx_oracle/version.js +8 -0
- package/dist/src/generated/waterx_perp/account_data.d.ts +269 -0
- package/dist/src/generated/waterx_perp/account_data.js +284 -0
- package/dist/src/generated/waterx_perp/admin.d.ts +19 -0
- package/dist/src/generated/waterx_perp/admin.js +22 -0
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/double.d.ts +8 -0
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/double.js +10 -0
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/liability.d.ts +11 -0
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/liability.js +13 -0
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/linked_table.d.ts +8 -0
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/linked_table.js +18 -0
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.d.ts +49 -0
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.js +18 -0
- package/dist/src/generated/waterx_perp/deps/std/type_name.d.ts +17 -0
- package/dist/src/generated/waterx_perp/deps/std/type_name.js +19 -0
- package/dist/src/generated/waterx_perp/deps/sui/balance.d.ts +15 -0
- package/dist/src/generated/waterx_perp/deps/sui/balance.js +17 -0
- package/dist/src/generated/waterx_perp/deps/sui/coin.d.ts +14 -0
- package/dist/src/generated/waterx_perp/deps/sui/coin.js +15 -0
- package/dist/src/generated/waterx_perp/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_perp/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_perp/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/generated/waterx_perp/deps/sui/vec_set.js +19 -0
- package/dist/src/generated/waterx_perp/events.d.ts +1283 -0
- package/dist/src/generated/waterx_perp/events.js +1018 -0
- package/dist/src/generated/waterx_perp/global_config.d.ts +775 -0
- package/dist/src/generated/waterx_perp/global_config.js +836 -0
- package/dist/src/generated/waterx_perp/keyed_big_vector.d.ts +553 -0
- package/dist/src/generated/waterx_perp/keyed_big_vector.js +554 -0
- package/dist/src/generated/waterx_perp/lp_pool.d.ts +1648 -0
- package/dist/src/generated/waterx_perp/lp_pool.js +1521 -0
- package/dist/src/generated/waterx_perp/market_config.d.ts +715 -0
- package/dist/src/generated/waterx_perp/market_config.js +780 -0
- package/dist/src/generated/waterx_perp/math.d.ts +63 -0
- package/dist/src/generated/waterx_perp/math.js +64 -0
- package/dist/src/generated/waterx_perp/memo.d.ts +251 -0
- package/dist/src/generated/waterx_perp/memo.js +323 -0
- package/dist/src/generated/waterx_perp/order_book.d.ts +290 -0
- package/dist/src/generated/waterx_perp/order_book.js +329 -0
- package/dist/src/generated/waterx_perp/position.d.ts +1005 -0
- package/dist/src/generated/waterx_perp/position.js +1103 -0
- package/dist/src/generated/waterx_perp/request.d.ts +544 -0
- package/dist/src/generated/waterx_perp/request.js +541 -0
- package/dist/src/generated/waterx_perp/response.d.ts +247 -0
- package/dist/src/generated/waterx_perp/response.js +280 -0
- package/dist/src/generated/waterx_perp/trading.d.ts +2821 -0
- package/dist/src/generated/waterx_perp/trading.js +2372 -0
- package/dist/src/generated/waterx_perp/version.d.ts +10 -0
- package/dist/src/generated/waterx_perp/version.js +8 -0
- package/dist/src/generated/waterx_perp/witness.d.ts +18 -0
- package/dist/src/generated/waterx_perp/witness.js +21 -0
- package/dist/src/generated/waterx_perp_view/deps/std/type_name.d.ts +17 -0
- package/dist/src/generated/waterx_perp_view/deps/std/type_name.js +19 -0
- package/dist/src/generated/waterx_perp_view/view.d.ts +447 -0
- package/dist/src/generated/waterx_perp_view/view.js +414 -0
- package/dist/src/generated/waterx_pyth_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_pyth_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +90 -0
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +72 -0
- package/dist/src/generated/waterx_referral/deps/sui/table.d.ts +29 -0
- package/dist/src/generated/waterx_referral/deps/sui/table.js +31 -0
- package/dist/src/generated/waterx_referral/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/generated/waterx_referral/deps/sui/vec_set.js +19 -0
- package/dist/src/generated/waterx_referral/referral_table.d.ts +171 -0
- package/dist/src/generated/waterx_referral/referral_table.js +192 -0
- package/dist/src/generated/waterx_staking/deps/bucket_v2_framework/double.d.ts +8 -0
- package/dist/src/generated/waterx_staking/deps/bucket_v2_framework/double.js +10 -0
- package/dist/src/generated/waterx_staking/deps/sui/balance.d.ts +12 -0
- package/dist/src/generated/waterx_staking/deps/sui/balance.js +14 -0
- package/dist/src/generated/waterx_staking/deps/sui/table.d.ts +29 -0
- package/dist/src/generated/waterx_staking/deps/sui/table.js +31 -0
- package/dist/src/generated/waterx_staking/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/generated/waterx_staking/deps/sui/vec_set.js +19 -0
- package/dist/src/generated/waterx_staking/waterx_staking.d.ts +746 -0
- package/dist/src/generated/waterx_staking/waterx_staking.js +731 -0
- package/dist/src/generated/waterx_staking/witness.d.ts +16 -0
- package/dist/src/generated/waterx_staking/witness.js +18 -0
- package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/linked_table.d.ts +8 -0
- package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/linked_table.js +18 -0
- package/dist/src/generated/withdrawal_queue/deps/std/type_name.d.ts +17 -0
- package/dist/src/generated/withdrawal_queue/deps/std/type_name.js +19 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/balance.d.ts +12 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/balance.js +14 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/vec_set.js +19 -0
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +483 -0
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +480 -0
- package/dist/src/generated/wlp/wlp.d.ts +28 -0
- package/dist/src/generated/wlp/wlp.js +32 -0
- package/dist/src/generated/wormhole_bridge/deps/sui/table.d.ts +29 -0
- package/dist/src/generated/wormhole_bridge/deps/sui/table.js +31 -0
- package/dist/src/generated/wormhole_bridge/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/wormhole_bridge/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/wormhole_bridge/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/generated/wormhole_bridge/deps/sui/vec_set.js +19 -0
- package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/consumed_vaas.d.ts +12 -0
- package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/consumed_vaas.js +9 -0
- package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/emitter.d.ts +14 -0
- package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/emitter.js +16 -0
- package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/set.d.ts +16 -0
- package/dist/src/generated/wormhole_bridge/deps/wormhole_sdk/set.js +15 -0
- package/dist/src/generated/wormhole_bridge/events.d.ts +32 -0
- package/dist/src/generated/wormhole_bridge/events.js +28 -0
- package/dist/src/generated/wormhole_bridge/wormhole_bridge.d.ts +498 -0
- package/dist/src/generated/wormhole_bridge/wormhole_bridge.js +494 -0
- package/dist/src/index.d.ts +28 -0
- package/dist/src/index.js +34 -0
- package/dist/src/tx-builders.d.ts +242 -0
- package/dist/src/tx-builders.js +320 -0
- package/dist/src/user/account.d.ts +129 -0
- package/dist/src/user/account.js +166 -0
- package/dist/src/user/credit.d.ts +135 -0
- package/dist/src/user/credit.js +255 -0
- package/dist/src/user/custody.d.ts +71 -0
- package/dist/src/user/custody.js +112 -0
- package/dist/src/user/index.d.ts +8 -0
- package/dist/src/user/index.js +8 -0
- package/dist/src/user/order.d.ts +89 -0
- package/dist/src/user/order.js +134 -0
- package/dist/src/user/referral.d.ts +21 -0
- package/dist/src/user/referral.js +41 -0
- package/dist/src/user/staking.d.ts +54 -0
- package/dist/src/user/staking.js +109 -0
- package/dist/src/user/trading.d.ts +119 -0
- package/dist/src/user/trading.js +262 -0
- package/dist/src/user/wlp.d.ts +58 -0
- package/dist/src/user/wlp.js +99 -0
- package/dist/src/utils/account-request.d.ts +9 -0
- package/dist/src/utils/account-request.js +17 -0
- package/dist/src/utils/config.d.ts +11 -0
- package/dist/src/utils/config.js +15 -0
- package/dist/src/utils/math.d.ts +201 -0
- package/dist/src/utils/math.js +343 -0
- package/dist/src/utils/pyth.d.ts +89 -0
- package/dist/src/utils/pyth.js +316 -0
- package/dist/src/utils/wormhole.d.ts +86 -0
- package/dist/src/utils/wormhole.js +154 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bucket Protocol
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# @waterx/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the WaterX perpetual protocol on Sui: build PTBs with **gRPC** (`@mysten/sui`), run read-only **simulateTransaction** queries, and optional **Pyth** helpers.
|
|
4
|
+
|
|
5
|
+
> **ABI note:** PTB entry points follow `contracts/waterx_perp` in this repo. **Read-only `view::*` helpers** resolve the module package from each **shared object’s on-chain type** (so `Market` / `WlpPool` can sit on a newer publish than `GlobalConfig` / `AccountRegistry`). BCS layouts for `MarketSummary`, `PositionInfo`, and `TokenPoolSummary` match the **deployed** `view` structs (see `contracts/waterx_perp/package_summaries/waterx_perp/view.json`). Pin `WaterXConfig` to your environment’s package and object IDs.
|
|
6
|
+
|
|
7
|
+
## Install & build
|
|
8
|
+
|
|
9
|
+
```bash
|
|
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`**:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const tx = await buildMintWlpTx(client, params);
|
|
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):**
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { createTestnetConfig, WaterXClient, type WaterXConfig } from "@waterx/sdk";
|
|
67
|
+
|
|
68
|
+
const config: WaterXConfig = {
|
|
69
|
+
...createTestnetConfig(),
|
|
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);
|
|
75
|
+
```
|
|
76
|
+
|
|
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";
|
|
87
|
+
|
|
88
|
+
const client = WaterXClient.testnet();
|
|
89
|
+
|
|
90
|
+
const pool = await getPoolSummary(client);
|
|
91
|
+
console.log("LP supply (raw):", pool.totalLpSupply.toString());
|
|
92
|
+
console.log("TVL (u128):", pool.tvlUsd.toString());
|
|
93
|
+
|
|
94
|
+
const supply = await getWlpTotalSupply(client);
|
|
95
|
+
const tvl = await getWlpTvlUsd(client);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Read-only: accounts & position
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { getAccountsByOwner, getPosition, positionExists, WaterXClient } from "@waterx/sdk";
|
|
102
|
+
|
|
103
|
+
const client = WaterXClient.testnet();
|
|
104
|
+
const owner = "0x..."; // Sui address
|
|
105
|
+
|
|
106
|
+
const accounts = await getAccountsByOwner(client, owner);
|
|
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.
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
124
|
+
import { buildOpenPositionTx, WaterXClient } from "@waterx/sdk";
|
|
125
|
+
|
|
126
|
+
const client = WaterXClient.testnet();
|
|
127
|
+
// Use your own keypair or any @mysten/sui Signer (e.g. wallet adapter).
|
|
128
|
+
const keypair = Ed25519Keypair.generate();
|
|
129
|
+
|
|
130
|
+
const tx = await buildOpenPositionTx(client, {
|
|
131
|
+
accountObjectAddress: "0x...", // UserAccount object id (hex), not a numeric id
|
|
132
|
+
base: "BTC",
|
|
133
|
+
isLong: true,
|
|
134
|
+
leverage: 10,
|
|
135
|
+
collateralAmount: 1_000_000_000n, // 1000 USDC if 6 decimals
|
|
136
|
+
approxPrice: 95_000, // required when `size` is not provided
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const result = await client.signAndExecuteTransaction({
|
|
140
|
+
transaction: tx,
|
|
141
|
+
signer: keypair,
|
|
142
|
+
});
|
|
143
|
+
console.log(result.digest);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Low-level PTB: same flow, your oracle wiring
|
|
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
|
|
153
|
+
|
|
154
|
+
### Core
|
|
155
|
+
|
|
156
|
+
| Export | Purpose |
|
|
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 |
|
|
161
|
+
|
|
162
|
+
### Transaction builders (append to `Transaction`)
|
|
163
|
+
|
|
164
|
+
| Group | Functions |
|
|
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`) |
|
|
182
|
+
|
|
183
|
+
**View return shapes:** `MarketSummary` includes `marketIndex` (on-chain index). `PositionInfoView` exposes `marketIndex` (bigint) and `accountObjectAddress` (from `user_address`). `getTokenPoolSummary` maps `TokenPoolSummary.lastPriceRefreshTimestamp` when the return payload includes it; older 72-byte deployments surface `0n` (see `parseTokenPoolSummaryReturn` in `fetch.ts`).
|
|
184
|
+
|
|
185
|
+
### High-level PTB helpers
|
|
186
|
+
|
|
187
|
+
`buildOpenPositionTx`, `buildClosePositionTx`, `buildIncreasePositionTx`, `buildDecreasePositionTx`, `buildDepositCollateralTx`, `buildWithdrawCollateralTx` (`buildIncreaseCollateralTx` / `buildReleaseCollateralTx` deprecated), `buildPlaceOrderTx`, `buildCancelOrderTx` (all `async`, Pyth-backed). All WLP builders are `async` and refresh every pool token's Pyth feed before the call (required by `assert_prices_fresh`): `buildMintWlpTx`, `buildMintAndStakeWlpTx`, `buildRequestRedeemWlpTx` (requires `recipient`), `buildSettleRedeemWlpTx`, `buildCancelRedeemWlpTx`, `buildUnstakeAndRequestRedeemWlpTx`.
|
|
188
|
+
|
|
189
|
+
### Constants & Pyth
|
|
190
|
+
|
|
191
|
+
Permission bits, order tags, testnet IDs, Pyth feeds: `src/constants.ts`.
|
|
192
|
+
On testnet, `TESTNET_TYPES.WLP` is the LP type wired to the live **`WlpPool` / `Market`** (`wlp_token::WLP_TOKEN`); `TESTNET_PACKAGE_IDS.WLP_STANDALONE` points at the standalone `contracts/wlp` publish for reference.
|
|
193
|
+
Oracle wiring: `fetchPriceFeedsUpdateData`, `updatePythPrices`, `buildPythRuleFeedCalls`, `PythCache`, etc. in `src/utils/pyth.ts`.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Development
|
|
198
|
+
|
|
199
|
+
| Command | Use |
|
|
200
|
+
| --------------------------- | ------------------------------------ |
|
|
201
|
+
| `pnpm typecheck` | Typecheck |
|
|
202
|
+
| `pnpm test` | Tests |
|
|
203
|
+
| `pnpm lint` / `pnpm format` | Prettier |
|
|
204
|
+
| `pnpm codegen` | Regenerate `src/generated` from Move |
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WaterX Protocol client.
|
|
3
|
+
*
|
|
4
|
+
* Initialization is async — config is fetched from the canonical
|
|
5
|
+
* `waterx-config` JSON (default: GitHub raw). See `WaterXClient.create()`.
|
|
6
|
+
*/
|
|
7
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
8
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
9
|
+
import { type LoadConfigOptions, type NativeCustodyAsset, type PythInfraConfig, type WaterXConfig, type WormholeInfraConfig } from "./config.ts";
|
|
10
|
+
import type { Network } from "./constants.ts";
|
|
11
|
+
export interface CreateClientOptions extends LoadConfigOptions {
|
|
12
|
+
grpcUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class WaterXClient {
|
|
15
|
+
/** gRPC client — all RPC including `simulateTransaction`. */
|
|
16
|
+
grpcClient: SuiGrpcClient;
|
|
17
|
+
/** Network identifier in upper case (`MAINNET` / `TESTNET`). */
|
|
18
|
+
network: Network;
|
|
19
|
+
/** Parsed canonical `waterx-config` JSON. */
|
|
20
|
+
config: WaterXConfig;
|
|
21
|
+
/** Pyth infra (network defaults unless overridden in JSON). */
|
|
22
|
+
pyth: PythInfraConfig;
|
|
23
|
+
/** Wormhole infra for the credit bridge (network defaults unless overridden). */
|
|
24
|
+
wormhole: WormholeInfraConfig;
|
|
25
|
+
constructor(network: Network, config: WaterXConfig, opts?: {
|
|
26
|
+
grpcUrl?: string;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Async factory: fetches the deployment config for `network` and returns
|
|
30
|
+
* a ready-to-use client. Pass `opts.cache=true` to memoize the JSON.
|
|
31
|
+
*/
|
|
32
|
+
static create(network: Network, opts?: CreateClientOptions): Promise<WaterXClient>;
|
|
33
|
+
static mainnet(opts?: CreateClientOptions): Promise<WaterXClient>;
|
|
34
|
+
static testnet(opts?: CreateClientOptions): Promise<WaterXClient>;
|
|
35
|
+
getObject(objectId: string): Promise<import("@mysten/sui/client").SuiClientTypes.GetObjectResponse<{}>>;
|
|
36
|
+
getObjects(objectIds: string[]): Promise<import("@mysten/sui/client").SuiClientTypes.GetObjectsResponse<{}>>;
|
|
37
|
+
listOwnedObjects(owner: string): Promise<import("@mysten/sui/client").SuiClientTypes.ListOwnedObjectsResponse<{}>>;
|
|
38
|
+
listCoins(params: {
|
|
39
|
+
owner: string;
|
|
40
|
+
coinType?: string;
|
|
41
|
+
}): Promise<import("@mysten/sui/client").SuiClientTypes.ListCoinsResponse>;
|
|
42
|
+
getBalance(params: {
|
|
43
|
+
owner: string;
|
|
44
|
+
coinType?: string;
|
|
45
|
+
}): Promise<import("@mysten/sui/client").SuiClientTypes.GetBalanceResponse>;
|
|
46
|
+
listDynamicFields(parentId: string): ReturnType<SuiGrpcClient["listDynamicFields"]>;
|
|
47
|
+
getDynamicField(parentId: string, name: {
|
|
48
|
+
type: string;
|
|
49
|
+
bcs: Uint8Array;
|
|
50
|
+
}): Promise<import("@mysten/sui/client").SuiClientTypes.GetDynamicFieldResponse>;
|
|
51
|
+
waitForTransaction(digest: string): Promise<import("@mysten/sui/client").SuiClientTypes.TransactionResult<{}>>;
|
|
52
|
+
simulate(tx: Transaction): Promise<import("@mysten/sui/client").SuiClientTypes.SimulateTransactionResult<{
|
|
53
|
+
commandResults: true;
|
|
54
|
+
}>>;
|
|
55
|
+
signAndExecuteTransaction(params: {
|
|
56
|
+
signer: {
|
|
57
|
+
toSuiAddress: () => string;
|
|
58
|
+
} & import("@mysten/sui/cryptography").Signer;
|
|
59
|
+
transaction: Transaction;
|
|
60
|
+
}): Promise<import("@mysten/sui/client").SuiClientTypes.TransactionResult<{}>>;
|
|
61
|
+
/** All package IDs (`published_at`) keyed by package name. */
|
|
62
|
+
packageIds(): Record<string, string>;
|
|
63
|
+
/** `waterx_perp.markets[ticker]`, throws if unknown. */
|
|
64
|
+
getMarket(ticker: string): import("./config.ts").WaterxPerpMarketEntry;
|
|
65
|
+
/** `waterx_oracle.aggregators[ticker]`, throws if unknown. */
|
|
66
|
+
getAggregator(ticker: string): string;
|
|
67
|
+
/** `pyth_rule.feeds[ticker]`, throws if unknown. */
|
|
68
|
+
getPythFeed(ticker: string): {
|
|
69
|
+
feed_id: string;
|
|
70
|
+
price_info_object: string;
|
|
71
|
+
};
|
|
72
|
+
/** `wlp.pool_tokens[ticker]` (fully-qualified Move type), throws if unknown. */
|
|
73
|
+
getPoolTokenType(ticker: string): string;
|
|
74
|
+
/** Fully-qualified WLP coin type derived from `wlp.original_id`. */
|
|
75
|
+
wlpType(): string;
|
|
76
|
+
/**
|
|
77
|
+
* List of rewarders registered for a staking pool alias, e.g. `"WLP"`.
|
|
78
|
+
* Returns an empty array if the deployment has no rewarders configured.
|
|
79
|
+
* Each entry carries the rewarder shared object ID + the fully-qualified
|
|
80
|
+
* reward coin type, so callers don't need a separate alias-to-type lookup.
|
|
81
|
+
*/
|
|
82
|
+
getRewarders(stakeAlias: string): {
|
|
83
|
+
alias: string;
|
|
84
|
+
rewarder_id: string;
|
|
85
|
+
coin_type: string;
|
|
86
|
+
decimals: number;
|
|
87
|
+
}[];
|
|
88
|
+
/** Type list of every reward coin for a stake pool — convenience for stake/unstake/claim. */
|
|
89
|
+
getRewarderTypes(stakeAlias: string): string[];
|
|
90
|
+
/** `waterx_credit` package entry, throws if the deployment has no bridge. */
|
|
91
|
+
getCredit(): import("./config.ts").WaterxCreditPackage;
|
|
92
|
+
/**
|
|
93
|
+
* Fully-qualified CREDIT coin Move type, taken verbatim from
|
|
94
|
+
* `waterx_credit.credit_type` (e.g. `0x..::usd::USD`). Throws if absent —
|
|
95
|
+
* the deprecated `usdx` OTW package is intentionally not consulted.
|
|
96
|
+
*/
|
|
97
|
+
creditType(): string;
|
|
98
|
+
/** `wormhole_bridge` package entry, throws if absent. */
|
|
99
|
+
getBridge(): import("./config.ts").WormholeBridgePackage;
|
|
100
|
+
/**
|
|
101
|
+
* Sui Wormhole `State` object id — prefers the per-deployment
|
|
102
|
+
* `wormhole_bridge.wormhole_state`, falls back to `client.wormhole`.
|
|
103
|
+
*/
|
|
104
|
+
wormholeStateId(): string;
|
|
105
|
+
/** All native-custody backing-asset rows (throws if no custody vault). */
|
|
106
|
+
getNativeAssets(): readonly NativeCustodyAsset[];
|
|
107
|
+
/** A native-custody asset row by its fully-qualified Move type, throws if unknown. */
|
|
108
|
+
getNativeAsset(moveType: string): NativeCustodyAsset;
|
|
109
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WaterX Protocol client.
|
|
3
|
+
*
|
|
4
|
+
* Initialization is async — config is fetched from the canonical
|
|
5
|
+
* `waterx-config` JSON (default: GitHub raw). See `WaterXClient.create()`.
|
|
6
|
+
*/
|
|
7
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
8
|
+
import { loadConfig, PYTH_DEFAULTS, WORMHOLE_DEFAULTS, } from "./config.js";
|
|
9
|
+
// ======== gRPC base URLs by network ========
|
|
10
|
+
const DEFAULT_GRPC_URLS = {
|
|
11
|
+
MAINNET: "https://fullnode.mainnet.sui.io:443",
|
|
12
|
+
TESTNET: "https://fullnode.testnet.sui.io:443",
|
|
13
|
+
};
|
|
14
|
+
export class WaterXClient {
|
|
15
|
+
/** gRPC client — all RPC including `simulateTransaction`. */
|
|
16
|
+
grpcClient;
|
|
17
|
+
/** Network identifier in upper case (`MAINNET` / `TESTNET`). */
|
|
18
|
+
network;
|
|
19
|
+
/** Parsed canonical `waterx-config` JSON. */
|
|
20
|
+
config;
|
|
21
|
+
/** Pyth infra (network defaults unless overridden in JSON). */
|
|
22
|
+
pyth;
|
|
23
|
+
/** Wormhole infra for the credit bridge (network defaults unless overridden). */
|
|
24
|
+
wormhole;
|
|
25
|
+
constructor(network, config, opts = {}) {
|
|
26
|
+
this.network = network;
|
|
27
|
+
this.config = config;
|
|
28
|
+
this.pyth = config.pyth ?? PYTH_DEFAULTS[network];
|
|
29
|
+
this.wormhole = config.wormhole ?? WORMHOLE_DEFAULTS[network];
|
|
30
|
+
const grpcUrl = opts.grpcUrl ?? config.grpcUrl ?? DEFAULT_GRPC_URLS[network];
|
|
31
|
+
this.grpcClient = new SuiGrpcClient({
|
|
32
|
+
baseUrl: grpcUrl,
|
|
33
|
+
network: network.toLowerCase(),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Async factory: fetches the deployment config for `network` and returns
|
|
38
|
+
* a ready-to-use client. Pass `opts.cache=true` to memoize the JSON.
|
|
39
|
+
*/
|
|
40
|
+
static async create(network, opts = {}) {
|
|
41
|
+
const config = await loadConfig(network, opts);
|
|
42
|
+
return new WaterXClient(network, config, { grpcUrl: opts.grpcUrl });
|
|
43
|
+
}
|
|
44
|
+
static mainnet(opts = {}) {
|
|
45
|
+
return WaterXClient.create("MAINNET", opts);
|
|
46
|
+
}
|
|
47
|
+
static testnet(opts = {}) {
|
|
48
|
+
return WaterXClient.create("TESTNET", opts);
|
|
49
|
+
}
|
|
50
|
+
// ========================================================
|
|
51
|
+
// gRPC convenience wrappers
|
|
52
|
+
// ========================================================
|
|
53
|
+
getObject(objectId) {
|
|
54
|
+
return this.grpcClient.getObject({ objectId });
|
|
55
|
+
}
|
|
56
|
+
getObjects(objectIds) {
|
|
57
|
+
return this.grpcClient.getObjects({ objectIds });
|
|
58
|
+
}
|
|
59
|
+
listOwnedObjects(owner) {
|
|
60
|
+
return this.grpcClient.listOwnedObjects({ owner });
|
|
61
|
+
}
|
|
62
|
+
listCoins(params) {
|
|
63
|
+
return this.grpcClient.listCoins(params);
|
|
64
|
+
}
|
|
65
|
+
getBalance(params) {
|
|
66
|
+
return this.grpcClient.getBalance(params);
|
|
67
|
+
}
|
|
68
|
+
listDynamicFields(parentId) {
|
|
69
|
+
return this.grpcClient.listDynamicFields({ parentId });
|
|
70
|
+
}
|
|
71
|
+
getDynamicField(parentId, name) {
|
|
72
|
+
return this.grpcClient.getDynamicField({ parentId, name });
|
|
73
|
+
}
|
|
74
|
+
waitForTransaction(digest) {
|
|
75
|
+
return this.grpcClient.waitForTransaction({ digest });
|
|
76
|
+
}
|
|
77
|
+
async simulate(tx) {
|
|
78
|
+
return this.grpcClient.simulateTransaction({
|
|
79
|
+
transaction: tx,
|
|
80
|
+
include: { commandResults: true },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async signAndExecuteTransaction(params) {
|
|
84
|
+
return this.grpcClient.signAndExecuteTransaction(params);
|
|
85
|
+
}
|
|
86
|
+
// ========================================================
|
|
87
|
+
// Shorthand accessors (canonical-schema lookups)
|
|
88
|
+
// ========================================================
|
|
89
|
+
/** All package IDs (`published_at`) keyed by package name. */
|
|
90
|
+
packageIds() {
|
|
91
|
+
const out = {};
|
|
92
|
+
for (const [name, pkg] of Object.entries(this.config.packages)) {
|
|
93
|
+
if (pkg && typeof pkg === "object" && "published_at" in pkg && pkg.published_at) {
|
|
94
|
+
out[name] = pkg.published_at;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
/** `waterx_perp.markets[ticker]`, throws if unknown. */
|
|
100
|
+
getMarket(ticker) {
|
|
101
|
+
const m = this.config.packages.waterx_perp?.markets?.[ticker];
|
|
102
|
+
if (!m)
|
|
103
|
+
throw new Error(`Unknown market ticker: ${ticker}`);
|
|
104
|
+
return m;
|
|
105
|
+
}
|
|
106
|
+
/** `waterx_oracle.aggregators[ticker]`, throws if unknown. */
|
|
107
|
+
getAggregator(ticker) {
|
|
108
|
+
const a = this.config.packages.waterx_oracle?.aggregators?.[ticker];
|
|
109
|
+
if (!a)
|
|
110
|
+
throw new Error(`No aggregator listed for ticker: ${ticker}`);
|
|
111
|
+
return a;
|
|
112
|
+
}
|
|
113
|
+
/** `pyth_rule.feeds[ticker]`, throws if unknown. */
|
|
114
|
+
getPythFeed(ticker) {
|
|
115
|
+
const f = this.config.packages.pyth_rule?.feeds?.[ticker];
|
|
116
|
+
if (!f)
|
|
117
|
+
throw new Error(`No pyth feed listed for ticker: ${ticker}`);
|
|
118
|
+
return f;
|
|
119
|
+
}
|
|
120
|
+
/** `wlp.pool_tokens[ticker]` (fully-qualified Move type), throws if unknown. */
|
|
121
|
+
getPoolTokenType(ticker) {
|
|
122
|
+
const t = this.config.packages.wlp?.pool_tokens?.[ticker];
|
|
123
|
+
if (!t)
|
|
124
|
+
throw new Error(`No pool token registered for ticker: ${ticker}`);
|
|
125
|
+
return t;
|
|
126
|
+
}
|
|
127
|
+
/** Fully-qualified WLP coin type derived from `wlp.original_id`. */
|
|
128
|
+
wlpType() {
|
|
129
|
+
const w = this.config.packages.wlp;
|
|
130
|
+
if (!w?.original_id)
|
|
131
|
+
throw new Error("wlp.original_id missing from config");
|
|
132
|
+
return `${w.original_id}::wlp::WLP`;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* List of rewarders registered for a staking pool alias, e.g. `"WLP"`.
|
|
136
|
+
* Returns an empty array if the deployment has no rewarders configured.
|
|
137
|
+
* Each entry carries the rewarder shared object ID + the fully-qualified
|
|
138
|
+
* reward coin type, so callers don't need a separate alias-to-type lookup.
|
|
139
|
+
*/
|
|
140
|
+
getRewarders(stakeAlias) {
|
|
141
|
+
const map = this.config.packages.waterx_staking?.rewarders?.[stakeAlias];
|
|
142
|
+
if (!map)
|
|
143
|
+
return [];
|
|
144
|
+
return Object.entries(map).map(([alias, entry]) => ({ alias, ...entry }));
|
|
145
|
+
}
|
|
146
|
+
/** Type list of every reward coin for a stake pool — convenience for stake/unstake/claim. */
|
|
147
|
+
getRewarderTypes(stakeAlias) {
|
|
148
|
+
return this.getRewarders(stakeAlias).map((r) => r.coin_type);
|
|
149
|
+
}
|
|
150
|
+
/** `waterx_credit` package entry, throws if the deployment has no bridge. */
|
|
151
|
+
getCredit() {
|
|
152
|
+
const c = this.config.packages.waterx_credit;
|
|
153
|
+
if (!c)
|
|
154
|
+
throw new Error("waterx_credit not configured for this deployment");
|
|
155
|
+
return c;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Fully-qualified CREDIT coin Move type, taken verbatim from
|
|
159
|
+
* `waterx_credit.credit_type` (e.g. `0x..::usd::USD`). Throws if absent —
|
|
160
|
+
* the deprecated `usdx` OTW package is intentionally not consulted.
|
|
161
|
+
*/
|
|
162
|
+
creditType() {
|
|
163
|
+
const t = this.config.packages.waterx_credit?.credit_type;
|
|
164
|
+
if (!t) {
|
|
165
|
+
throw new Error("creditType: packages.waterx_credit.credit_type missing from config");
|
|
166
|
+
}
|
|
167
|
+
return t;
|
|
168
|
+
}
|
|
169
|
+
/** `wormhole_bridge` package entry, throws if absent. */
|
|
170
|
+
getBridge() {
|
|
171
|
+
const b = this.config.packages.wormhole_bridge;
|
|
172
|
+
if (!b)
|
|
173
|
+
throw new Error("wormhole_bridge not configured for this deployment");
|
|
174
|
+
return b;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Sui Wormhole `State` object id — prefers the per-deployment
|
|
178
|
+
* `wormhole_bridge.wormhole_state`, falls back to `client.wormhole`.
|
|
179
|
+
*/
|
|
180
|
+
wormholeStateId() {
|
|
181
|
+
return this.config.packages.wormhole_bridge?.wormhole_state ?? this.wormhole.state_id;
|
|
182
|
+
}
|
|
183
|
+
/** All native-custody backing-asset rows (throws if no custody vault). */
|
|
184
|
+
getNativeAssets() {
|
|
185
|
+
const nc = this.config.packages.native_custody;
|
|
186
|
+
if (!nc)
|
|
187
|
+
throw new Error("native_custody not configured for this deployment");
|
|
188
|
+
return nc.assets;
|
|
189
|
+
}
|
|
190
|
+
/** A native-custody asset row by its fully-qualified Move type, throws if unknown. */
|
|
191
|
+
getNativeAsset(moveType) {
|
|
192
|
+
const row = this.getNativeAssets().find((a) => a.type === moveType);
|
|
193
|
+
if (!row)
|
|
194
|
+
throw new Error(`No native custody asset registered for type: ${moveType}`);
|
|
195
|
+
return row;
|
|
196
|
+
}
|
|
197
|
+
}
|