@waterx/sdk 2.4.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -21
- package/dist/src/{utils → account}/account-request.d.ts +2 -2
- package/dist/src/{user → account}/account.d.ts +23 -21
- package/dist/src/{user → account}/account.js +5 -5
- package/dist/src/account/client.d.ts +42 -0
- package/dist/src/account/client.js +17 -0
- package/dist/src/account/config.d.ts +151 -0
- package/dist/src/account/config.js +8 -0
- package/dist/src/account/constants.d.ts +5 -0
- package/dist/src/account/constants.js +5 -0
- package/dist/src/account/fetch/referral.d.ts +15 -0
- package/dist/src/account/fetch/referral.js +51 -0
- package/dist/src/account/fetch/simulate.d.ts +34 -0
- package/dist/src/account/fetch/simulate.js +43 -0
- package/dist/src/{utils/consolidate-balance.d.ts → account/funding/balance.d.ts} +3 -8
- package/dist/src/{utils/consolidate-balance.js → account/funding/balance.js} +6 -1
- package/dist/src/account/funding/consolidate.d.ts +46 -0
- package/dist/src/account/funding/consolidate.js +137 -0
- package/dist/src/{user → account/funding}/credit.d.ts +10 -10
- package/dist/src/{user → account/funding}/credit.js +6 -6
- package/dist/src/{user → account/funding}/custody.d.ts +4 -4
- package/dist/src/{user → account/funding}/custody.js +2 -2
- package/dist/src/{utils → account/funding}/wormhole.d.ts +4 -4
- package/dist/src/{utils → account/funding}/wormhole.js +1 -1
- package/dist/src/account/index.d.ts +29 -0
- package/dist/src/account/index.js +29 -0
- package/dist/src/{user → account}/referral.d.ts +3 -3
- package/dist/src/{user → account}/referral.js +1 -1
- package/dist/src/base-client.d.ts +74 -0
- package/dist/src/base-client.js +97 -0
- package/dist/src/constants.d.ts +4 -46
- package/dist/src/constants.js +8 -52
- package/dist/src/generated/bucket_v2_framework/liability.d.ts +0 -26
- package/dist/src/generated/bucket_v2_framework/liability.js +0 -28
- package/dist/src/generated/waterx_account/account.d.ts +50 -15
- package/dist/src/generated/waterx_account/account.js +51 -15
- package/dist/src/generated/waterx_oracle/oracle.d.ts +7 -1
- package/dist/src/generated/waterx_oracle/oracle.js +7 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.d.ts +19 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.d.ts +3 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/sui/balance.d.ts +3 -1
- package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.d.ts +6 -1
- package/dist/src/generated/waterx_prediction/events.d.ts +288 -0
- package/dist/src/{prediction/generated → generated}/waterx_prediction/events.js +39 -0
- package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.d.ts +6 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/order.d.ts +34 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/position.d.ts +16 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/view.d.ts +69 -4
- package/dist/src/{prediction/generated → generated}/waterx_prediction/waterx_prediction.d.ts +162 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/waterx_prediction.js +99 -0
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +102 -0
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +99 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.d.ts +5 -5
- package/dist/src/generated/waterx_supra_rule/supra_rule.js +1 -2
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +23 -23
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +3 -6
- package/dist/src/oracle/aggregate.d.ts +74 -0
- package/dist/src/oracle/aggregate.js +112 -0
- package/dist/src/oracle/config.d.ts +99 -0
- package/dist/src/oracle/config.js +23 -0
- package/dist/src/oracle/host.d.ts +32 -0
- package/dist/src/oracle/host.js +10 -0
- package/dist/src/oracle/index.d.ts +16 -0
- package/dist/src/oracle/index.js +18 -0
- package/dist/src/oracle/pyth.d.ts +52 -0
- package/dist/src/oracle/pyth.js +220 -0
- package/dist/src/oracle/rules/constant-rule.d.ts +9 -0
- package/dist/src/oracle/rules/constant-rule.js +14 -0
- package/dist/src/oracle/rules/pyth-rule.d.ts +11 -0
- package/dist/src/oracle/rules/pyth-rule.js +20 -0
- package/dist/src/oracle/rules/sponsor.d.ts +28 -0
- package/dist/src/oracle/rules/sponsor.js +48 -0
- package/dist/src/oracle/rules/supra-rule.d.ts +11 -0
- package/dist/src/oracle/rules/supra-rule.js +22 -0
- package/dist/src/perp/client.d.ts +78 -0
- package/dist/src/perp/client.js +108 -0
- package/dist/src/{client.d.ts → perp/config-view.d.ts} +15 -60
- package/dist/src/{client.js → perp/config-view.js} +23 -95
- package/dist/src/perp/config.d.ts +126 -0
- package/dist/src/{config.js → perp/config.js} +11 -12
- package/dist/src/perp/constants.d.ts +49 -0
- package/dist/src/perp/constants.js +61 -0
- package/dist/src/perp/fetch/account.d.ts +43 -0
- package/dist/src/perp/fetch/account.js +64 -0
- package/dist/src/perp/fetch/bridge.d.ts +90 -0
- package/dist/src/perp/fetch/bridge.js +127 -0
- package/dist/src/perp/fetch/custody.d.ts +32 -0
- package/dist/src/perp/fetch/custody.js +62 -0
- package/dist/src/perp/fetch/market.d.ts +30 -0
- package/dist/src/perp/fetch/market.js +68 -0
- package/dist/src/perp/fetch/positions.d.ts +70 -0
- package/dist/src/perp/fetch/positions.js +185 -0
- package/dist/src/perp/fetch/simulate.d.ts +12 -0
- package/dist/src/perp/fetch/simulate.js +13 -0
- package/dist/src/perp/fetch.d.ts +23 -0
- package/dist/src/perp/fetch.js +23 -0
- package/dist/src/{index.d.ts → perp/index.d.ts} +21 -21
- package/dist/src/{index.js → perp/index.js} +21 -21
- package/dist/src/perp/tx-builders/common.d.ts +83 -0
- package/dist/src/perp/tx-builders/common.js +70 -0
- package/dist/src/perp/tx-builders/credit.d.ts +65 -0
- package/dist/src/perp/tx-builders/credit.js +62 -0
- package/dist/src/perp/tx-builders/rewards.d.ts +30 -0
- package/dist/src/perp/tx-builders/rewards.js +34 -0
- package/dist/src/perp/tx-builders/trading.d.ts +51 -0
- package/dist/src/perp/tx-builders/trading.js +59 -0
- package/dist/src/perp/tx-builders/wlp.d.ts +90 -0
- package/dist/src/perp/tx-builders/wlp.js +120 -0
- package/dist/src/perp/tx-builders.d.ts +23 -0
- package/dist/src/perp/tx-builders.js +23 -0
- package/dist/src/perp/user/index.d.ts +8 -0
- package/dist/src/perp/user/index.js +8 -0
- package/dist/src/{user → perp/user}/order.d.ts +7 -7
- package/dist/src/{user → perp/user}/order.js +3 -3
- package/dist/src/{user → perp/user}/staking.d.ts +4 -4
- package/dist/src/{user → perp/user}/staking.js +2 -2
- package/dist/src/{user → perp/user}/trading.d.ts +13 -13
- package/dist/src/{user → perp/user}/trading.js +2 -2
- package/dist/src/{user → perp/user}/wlp.d.ts +7 -7
- package/dist/src/{user → perp/user}/wlp.js +3 -3
- package/dist/src/prediction/account.js +40 -76
- package/dist/src/prediction/bcs.d.ts +15 -9
- package/dist/src/prediction/bcs.js +17 -81
- package/dist/src/prediction/client.d.ts +8 -38
- package/dist/src/prediction/client.js +11 -67
- package/dist/src/prediction/config.d.ts +16 -2
- package/dist/src/prediction/config.js +10 -4
- package/dist/src/prediction/gift.js +2 -10
- package/dist/src/prediction/index.d.ts +11 -11
- package/dist/src/prediction/index.js +10 -10
- package/dist/src/prediction/prediction.d.ts +45 -0
- package/dist/src/prediction/prediction.js +71 -0
- package/dist/src/prediction/tx-builders.d.ts +4 -4
- package/dist/src/prediction/tx-builders.js +2 -2
- package/dist/src/prediction/types.d.ts +2 -0
- package/dist/src/prediction/user/index.d.ts +2 -2
- package/dist/src/prediction/user/index.js +1 -1
- package/dist/src/prediction/user/position.d.ts +2 -2
- package/dist/src/prediction/user/position.js +1 -1
- package/dist/src/prediction/utils/bcs.d.ts +5 -0
- package/dist/src/prediction/utils/bcs.js +5 -0
- package/dist/src/prediction/utils/index.d.ts +7 -0
- package/dist/src/prediction/utils/index.js +7 -0
- package/dist/src/sdk.d.ts +10 -6
- package/dist/src/sdk.js +9 -5
- package/dist/src/unified-client.d.ts +140 -145
- package/dist/src/unified-client.js +98 -40
- package/dist/src/utils/config.d.ts +1 -1
- package/package.json +22 -5
- package/dist/src/config.d.ts +0 -292
- package/dist/src/fetch.d.ts +0 -254
- package/dist/src/fetch.js +0 -564
- package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +0 -100
- package/dist/src/prediction/generated/bucket_v2_framework/account.js +0 -129
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +0 -6
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +0 -19
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +0 -10
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +0 -36
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +0 -27
- package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +0 -382
- package/dist/src/prediction/generated/bucket_v2_framework/double.js +0 -466
- package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +0 -362
- package/dist/src/prediction/generated/bucket_v2_framework/float.js +0 -440
- package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +0 -193
- package/dist/src/prediction/generated/bucket_v2_framework/liability.js +0 -205
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +0 -384
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +0 -382
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +0 -344
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +0 -338
- package/dist/src/prediction/generated/utils/index.d.ts +0 -30
- package/dist/src/prediction/generated/utils/index.js +0 -160
- package/dist/src/prediction/generated/waterx_account/account.d.ts +0 -1589
- package/dist/src/prediction/generated/waterx_account/account.js +0 -1758
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +0 -7
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +0 -13
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +0 -7
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +0 -16
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +0 -6
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +0 -19
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +0 -10
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +0 -14
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +0 -12
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +0 -19
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +0 -36
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +0 -27
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +0 -16
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +0 -19
- package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +0 -75
- package/dist/src/prediction/generated/waterx_account/direct_rule.js +0 -78
- package/dist/src/prediction/generated/waterx_account/events.d.ts +0 -33
- package/dist/src/prediction/generated/waterx_account/events.js +0 -137
- package/dist/src/prediction/generated/waterx_account/version.js +0 -8
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +0 -60
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +0 -83
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +0 -14
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +0 -24
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +0 -31
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +0 -16
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +0 -19
- package/dist/src/prediction/generated/waterx_prediction/events.d.ts +0 -22
- package/dist/src/prediction/generated/waterx_prediction/version.d.ts +0 -10
- package/dist/src/tx-builders.d.ts +0 -296
- package/dist/src/tx-builders.js +0 -461
- package/dist/src/user/index.d.ts +0 -8
- package/dist/src/user/index.js +0 -8
- package/dist/src/utils/pyth.d.ts +0 -124
- package/dist/src/utils/pyth.js +0 -392
- /package/dist/src/{utils → account}/account-request.js +0 -0
- /package/dist/src/{core → account}/waterx-account.d.ts +0 -0
- /package/dist/src/{core → account}/waterx-account.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.js +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/balance.js +0 -0
- /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.js +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.d.ts +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/order.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/position.js +0 -0
- /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/version.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/version.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/view.js +0 -0
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Shared probe helpers for {@link appendConsolidateToUsd} and
|
|
3
|
-
* {@link getSpendableCreditBalance} — one asset list, one gRPC read pattern,
|
|
4
|
-
* so display totals match what the next async tx-builder would sweep.
|
|
5
|
-
*/
|
|
6
|
-
import type { WaterXClient } from "../client.ts";
|
|
1
|
+
import type { AccountClientLike } from "../client.ts";
|
|
7
2
|
/** CREDIT parked at a wxa account's Sui address (funds accumulator + owned coins). */
|
|
8
3
|
export interface AddressCreditBalance {
|
|
9
4
|
/** `getBalance.addressBalance` — funds accumulator path. */
|
|
@@ -27,11 +22,11 @@ export declare function rescaleRawAmount(raw: bigint, fromDecimals: number, toDe
|
|
|
27
22
|
* parked at `accountId`'s Sui address. Matches the pre-tx scan inside
|
|
28
23
|
* {@link appendConsolidateToUsd}.
|
|
29
24
|
*/
|
|
30
|
-
export declare function probeParkedBackingAssets(client:
|
|
25
|
+
export declare function probeParkedBackingAssets(client: AccountClientLike, accountId: string): Promise<ParkedBackingAssetBalance[]>;
|
|
31
26
|
/**
|
|
32
27
|
* Probe non-zero CREDIT parked at `accountId`'s Sui address. Matches the
|
|
33
28
|
* address-CREDIT legs inside {@link appendConsolidateAddressCredit}.
|
|
34
29
|
*/
|
|
35
|
-
export declare function probeAddressCreditBalance(client:
|
|
30
|
+
export declare function probeAddressCreditBalance(client: AccountClientLike, accountId: string): Promise<AddressCreditBalance>;
|
|
36
31
|
/** Sum parked backing assets into CREDIT base units at the 1:1 PSM peg. */
|
|
37
32
|
export declare function sumParkedBackingAsCreditRaw(parked: readonly ParkedBackingAssetBalance[], creditDecimals?: number): bigint;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Shared probe helpers for {@link appendConsolidateToUsd} and
|
|
3
|
+
* {@link getSpendableCreditBalance} — one asset list, one gRPC read pattern,
|
|
4
|
+
* so display totals match what the next async tx-builder would sweep.
|
|
5
|
+
*/
|
|
6
|
+
import { COLLATERAL_DECIMALS } from "../../constants.js";
|
|
2
7
|
/** Rescale a u64 raw amount between token decimal precisions (truncates on downscale). */
|
|
3
8
|
export function rescaleRawAmount(raw, fromDecimals, toDecimals = COLLATERAL_DECIMALS) {
|
|
4
9
|
if (fromDecimals === toDecimals)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consolidate parked backing assets → USD credit (pre-action sweep).
|
|
3
|
+
*
|
|
4
|
+
* Drains every backing asset (and address-owned CREDIT) parked at a wxa
|
|
5
|
+
* account's address into spendable wxUSD, so the subsequent trading / WLP /
|
|
6
|
+
* predict action can debit the internal slot. Empty buckets are skipped via
|
|
7
|
+
* gRPC probes, so the sweep is safe to run on any account.
|
|
8
|
+
*/
|
|
9
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
10
|
+
import type { AccountClientLike } from "../client.ts";
|
|
11
|
+
/**
|
|
12
|
+
* For every backing asset registered on `native_custody`, append two drain
|
|
13
|
+
* legs to `tx`:
|
|
14
|
+
*
|
|
15
|
+
* `requestDepositFromFunds<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
|
|
16
|
+
* `requestDepositFromReceivings<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
|
|
17
|
+
*
|
|
18
|
+
* Empty legs are skipped — the on-chain `mint` rejects zero-amount deposits.
|
|
19
|
+
* Returns the number of drain legs added (useful for logging / early-out).
|
|
20
|
+
*
|
|
21
|
+
* Silently no-ops when `native_custody` / `waterx_credit` aren't configured
|
|
22
|
+
* for the loaded deployment.
|
|
23
|
+
*/
|
|
24
|
+
export declare function appendConsolidateToUsd(client: AccountClientLike, tx: Transaction, accountId: string): Promise<number>;
|
|
25
|
+
/**
|
|
26
|
+
* Drain CREDIT parked at `accountId`'s Sui address (funds accumulator +
|
|
27
|
+
* owned `Coin<CREDIT>`) into the wxa internal slot via
|
|
28
|
+
* `consumeDepositDirect<CREDIT>`. Complements {@link appendConsolidateToUsd}
|
|
29
|
+
* for address-owned wxUSD that predict / perp actions debit from the internal
|
|
30
|
+
* balance.
|
|
31
|
+
*/
|
|
32
|
+
export declare function appendConsolidateAddressCredit(client: AccountClientLike, tx: Transaction, accountId: string): Promise<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Full pre-action sweep: backing assets → wxUSD credit (PSM) plus address
|
|
35
|
+
* CREDIT → internal slot. Used by async tx-builders when `consolidateToUsd`
|
|
36
|
+
* is enabled (default).
|
|
37
|
+
*/
|
|
38
|
+
export declare function appendConsolidateForSpend(client: AccountClientLike, tx: Transaction, accountId: string): Promise<number>;
|
|
39
|
+
/**
|
|
40
|
+
* Standalone PTB that drains every backing asset parked at the account's
|
|
41
|
+
* address into USD credit under the account — see {@link appendConsolidateToUsd}.
|
|
42
|
+
*
|
|
43
|
+
* Returns an empty `Transaction` when nothing is parked. Callers can
|
|
44
|
+
* `client.simulate(tx)` to detect a no-op before submitting.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildConsolidateToUsdTx(client: AccountClientLike, accountId: string, tx?: Transaction): Promise<Transaction>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consolidate parked backing assets → USD credit (pre-action sweep).
|
|
3
|
+
*
|
|
4
|
+
* Drains every backing asset (and address-owned CREDIT) parked at a wxa
|
|
5
|
+
* account's address into spendable wxUSD, so the subsequent trading / WLP /
|
|
6
|
+
* predict action can debit the internal slot. Empty buckets are skipped via
|
|
7
|
+
* gRPC probes, so the sweep is safe to run on any account.
|
|
8
|
+
*/
|
|
9
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
10
|
+
import { consumeDepositDirect } from "../../generated/waterx_account/direct_rule.js";
|
|
11
|
+
import { requestDepositFromFunds, requestDepositFromReceivings } from "../account.js";
|
|
12
|
+
import { probeAddressCreditBalance, probeParkedBackingAssets } from "./balance.js";
|
|
13
|
+
import { mintCreditFromRequest } from "./custody.js";
|
|
14
|
+
/**
|
|
15
|
+
* For every backing asset registered on `native_custody`, append two drain
|
|
16
|
+
* legs to `tx`:
|
|
17
|
+
*
|
|
18
|
+
* `requestDepositFromFunds<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
|
|
19
|
+
* `requestDepositFromReceivings<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
|
|
20
|
+
*
|
|
21
|
+
* Empty legs are skipped — the on-chain `mint` rejects zero-amount deposits.
|
|
22
|
+
* Returns the number of drain legs added (useful for logging / early-out).
|
|
23
|
+
*
|
|
24
|
+
* Silently no-ops when `native_custody` / `waterx_credit` aren't configured
|
|
25
|
+
* for the loaded deployment.
|
|
26
|
+
*/
|
|
27
|
+
export async function appendConsolidateToUsd(client, tx, accountId) {
|
|
28
|
+
const parked = await probeParkedBackingAssets(client, accountId);
|
|
29
|
+
let legs = 0;
|
|
30
|
+
for (const row of parked) {
|
|
31
|
+
if (row.fundsRaw > 0n) {
|
|
32
|
+
const fromFunds = requestDepositFromFunds(client, tx, {
|
|
33
|
+
accountId,
|
|
34
|
+
coinType: row.assetType,
|
|
35
|
+
});
|
|
36
|
+
foldDepositRequestToUsd(client, tx, fromFunds, row.assetType);
|
|
37
|
+
legs += 1;
|
|
38
|
+
}
|
|
39
|
+
if (row.coinsRaw > 0n) {
|
|
40
|
+
const coins = (await client.listCoins({
|
|
41
|
+
owner: accountId,
|
|
42
|
+
coinType: row.assetType,
|
|
43
|
+
}));
|
|
44
|
+
const refs = (coins.objects ?? []).filter((c) => !!c.objectId && !!c.version && !!c.digest);
|
|
45
|
+
if (refs.length === 0)
|
|
46
|
+
continue;
|
|
47
|
+
const receivings = refs.map((c) => tx.receivingRef({ objectId: c.objectId, version: c.version, digest: c.digest }));
|
|
48
|
+
const fromReceivings = requestDepositFromReceivings(client, tx, {
|
|
49
|
+
accountId,
|
|
50
|
+
coinType: row.assetType,
|
|
51
|
+
receivings,
|
|
52
|
+
});
|
|
53
|
+
foldDepositRequestToUsd(client, tx, fromReceivings, row.assetType);
|
|
54
|
+
legs += 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return legs;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Drain CREDIT parked at `accountId`'s Sui address (funds accumulator +
|
|
61
|
+
* owned `Coin<CREDIT>`) into the wxa internal slot via
|
|
62
|
+
* `consumeDepositDirect<CREDIT>`. Complements {@link appendConsolidateToUsd}
|
|
63
|
+
* for address-owned wxUSD that predict / perp actions debit from the internal
|
|
64
|
+
* balance.
|
|
65
|
+
*/
|
|
66
|
+
export async function appendConsolidateAddressCredit(client, tx, accountId) {
|
|
67
|
+
if (!client.config.packages.waterx_credit?.credit_type)
|
|
68
|
+
return 0;
|
|
69
|
+
const creditType = client.creditType();
|
|
70
|
+
const { fundsRaw, coinsRaw } = await probeAddressCreditBalance(client, accountId);
|
|
71
|
+
let legs = 0;
|
|
72
|
+
if (fundsRaw > 0n) {
|
|
73
|
+
const fromFunds = requestDepositFromFunds(client, tx, {
|
|
74
|
+
accountId,
|
|
75
|
+
coinType: creditType,
|
|
76
|
+
});
|
|
77
|
+
consumeDepositRequest(client, tx, fromFunds, creditType);
|
|
78
|
+
legs += 1;
|
|
79
|
+
}
|
|
80
|
+
if (coinsRaw > 0n) {
|
|
81
|
+
const coins = (await client.listCoins({
|
|
82
|
+
owner: accountId,
|
|
83
|
+
coinType: creditType,
|
|
84
|
+
}));
|
|
85
|
+
const refs = (coins.objects ?? []).filter((c) => !!c.objectId && !!c.version && !!c.digest);
|
|
86
|
+
if (refs.length > 0) {
|
|
87
|
+
const receivings = refs.map((c) => tx.receivingRef({ objectId: c.objectId, version: c.version, digest: c.digest }));
|
|
88
|
+
const fromReceivings = requestDepositFromReceivings(client, tx, {
|
|
89
|
+
accountId,
|
|
90
|
+
coinType: creditType,
|
|
91
|
+
receivings,
|
|
92
|
+
});
|
|
93
|
+
consumeDepositRequest(client, tx, fromReceivings, creditType);
|
|
94
|
+
legs += 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return legs;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Full pre-action sweep: backing assets → wxUSD credit (PSM) plus address
|
|
101
|
+
* CREDIT → internal slot. Used by async tx-builders when `consolidateToUsd`
|
|
102
|
+
* is enabled (default).
|
|
103
|
+
*/
|
|
104
|
+
export async function appendConsolidateForSpend(client, tx, accountId) {
|
|
105
|
+
const backingLegs = await appendConsolidateToUsd(client, tx, accountId);
|
|
106
|
+
const creditLegs = await appendConsolidateAddressCredit(client, tx, accountId);
|
|
107
|
+
return backingLegs + creditLegs;
|
|
108
|
+
}
|
|
109
|
+
function consumeDepositRequest(client, tx, depositRequest, coinType) {
|
|
110
|
+
consumeDepositDirect({
|
|
111
|
+
package: client.config.packages.waterx_account.published_at,
|
|
112
|
+
arguments: {
|
|
113
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
114
|
+
req: depositRequest,
|
|
115
|
+
},
|
|
116
|
+
typeArguments: [coinType],
|
|
117
|
+
})(tx);
|
|
118
|
+
}
|
|
119
|
+
function foldDepositRequestToUsd(client, tx, depositRequest, assetType) {
|
|
120
|
+
const usdReq = mintCreditFromRequest(client, tx, {
|
|
121
|
+
depositRequest,
|
|
122
|
+
assetType,
|
|
123
|
+
});
|
|
124
|
+
consumeDepositRequest(client, tx, usdReq, client.creditType());
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Standalone PTB that drains every backing asset parked at the account's
|
|
128
|
+
* address into USD credit under the account — see {@link appendConsolidateToUsd}.
|
|
129
|
+
*
|
|
130
|
+
* Returns an empty `Transaction` when nothing is parked. Callers can
|
|
131
|
+
* `client.simulate(tx)` to detect a no-op before submitting.
|
|
132
|
+
*/
|
|
133
|
+
export async function buildConsolidateToUsdTx(client, accountId, tx) {
|
|
134
|
+
const txOut = tx ?? new Transaction();
|
|
135
|
+
await appendConsolidateToUsd(client, txOut, accountId);
|
|
136
|
+
return txOut;
|
|
137
|
+
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* same PTB.
|
|
19
19
|
*/
|
|
20
20
|
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
21
|
-
import type {
|
|
21
|
+
import type { AccountClientLike } from "../client.ts";
|
|
22
22
|
export interface RedeemVaaParams {
|
|
23
23
|
/** Signed Wormhole MINT VAA (raw bytes / number[] / hex). */
|
|
24
24
|
vaaBytes: Uint8Array | number[] | string;
|
|
@@ -30,7 +30,7 @@ export interface RedeemVaaParams {
|
|
|
30
30
|
* `DepositRequest<CREDIT>` hot-potato argument — **must** be consumed in the
|
|
31
31
|
* same PTB (see {@link consumeCreditDeposit} / `redeemVaaTx`).
|
|
32
32
|
*/
|
|
33
|
-
export declare function redeemVaa(client:
|
|
33
|
+
export declare function redeemVaa(client: AccountClientLike, tx: Transaction, params: RedeemVaaParams): TransactionArgument;
|
|
34
34
|
export interface ConsumeCreditDepositParams {
|
|
35
35
|
/** The `DepositRequest<CREDIT>` returned by {@link redeemVaa} / {@link custodyMint}. */
|
|
36
36
|
depositRequest: TransactionArgument;
|
|
@@ -42,7 +42,7 @@ export interface ConsumeCreditDepositParams {
|
|
|
42
42
|
* `register_deposit_policy<CREDIT, DirectRule>`). Must run in the same PTB
|
|
43
43
|
* as the `redeem_vaa` / custody `mint` that produced the request.
|
|
44
44
|
*/
|
|
45
|
-
export declare function consumeCreditDeposit(client:
|
|
45
|
+
export declare function consumeCreditDeposit(client: AccountClientLike, tx: Transaction, params: ConsumeCreditDepositParams): void;
|
|
46
46
|
export interface RouteWormholeParams {
|
|
47
47
|
/** Destination EVM chain's Wormhole chain id. */
|
|
48
48
|
evmDestinationChain: number;
|
|
@@ -52,7 +52,7 @@ export interface RouteWormholeParams {
|
|
|
52
52
|
evmToken: Uint8Array | number[] | string;
|
|
53
53
|
}
|
|
54
54
|
/** Build `withdrawal_queue::route_wormhole`. Returns the `extra_data` argument. */
|
|
55
|
-
export declare function routeWormhole(client:
|
|
55
|
+
export declare function routeWormhole(client: AccountClientLike, tx: Transaction, params: RouteWormholeParams): TransactionArgument;
|
|
56
56
|
export interface RouteNativeParams {
|
|
57
57
|
/** Fully-qualified backing asset Move type `T` (e.g. via `client.getNativeAsset`). */
|
|
58
58
|
assetType: string;
|
|
@@ -64,7 +64,7 @@ export interface RouteNativeParams {
|
|
|
64
64
|
minOutput?: bigint | number;
|
|
65
65
|
}
|
|
66
66
|
/** Build `withdrawal_queue::route_native<T>`. Returns the `extra_data` argument. */
|
|
67
|
-
export declare function routeNative(client:
|
|
67
|
+
export declare function routeNative(client: AccountClientLike, tx: Transaction, params: RouteNativeParams): TransactionArgument;
|
|
68
68
|
export interface RequestCreditWithdrawParams {
|
|
69
69
|
accountId: string;
|
|
70
70
|
amount: bigint | number;
|
|
@@ -80,7 +80,7 @@ export interface RequestCreditWithdrawParams {
|
|
|
80
80
|
* Returns the `WithdrawRequest<CREDIT>` hot-potato argument (feed to
|
|
81
81
|
* {@link enqueueWithdrawal} in the same PTB).
|
|
82
82
|
*/
|
|
83
|
-
export declare function requestCreditWithdraw(client:
|
|
83
|
+
export declare function requestCreditWithdraw(client: AccountClientLike, tx: Transaction, params: RequestCreditWithdrawParams): TransactionArgument;
|
|
84
84
|
export interface EnqueueWithdrawalParams {
|
|
85
85
|
/** `WithdrawRequest<CREDIT>` from {@link requestCreditWithdraw}. */
|
|
86
86
|
withdrawRequest: TransactionArgument;
|
|
@@ -90,7 +90,7 @@ export interface EnqueueWithdrawalParams {
|
|
|
90
90
|
* Build `withdrawal_queue::enqueue<CREDIT>`. Returns the assigned `u64` key
|
|
91
91
|
* argument (also surfaced on-chain via the `Enqueued` event).
|
|
92
92
|
*/
|
|
93
|
-
export declare function enqueueWithdrawal(client:
|
|
93
|
+
export declare function enqueueWithdrawal(client: AccountClientLike, tx: Transaction, params: EnqueueWithdrawalParams): TransactionArgument;
|
|
94
94
|
export interface ExecuteWithdrawalWormholeParams {
|
|
95
95
|
/** Queue entry key (from the `Enqueued` event / `enqueueWithdrawal`). */
|
|
96
96
|
key: bigint | number;
|
|
@@ -101,7 +101,7 @@ export interface ExecuteWithdrawalWormholeParams {
|
|
|
101
101
|
bucketAccount?: string | TransactionArgument;
|
|
102
102
|
}
|
|
103
103
|
/** Build `withdrawal_queue::execute_wormhole<CREDIT>` (keeper / executor-gated). */
|
|
104
|
-
export declare function executeWithdrawalWormhole(client:
|
|
104
|
+
export declare function executeWithdrawalWormhole(client: AccountClientLike, tx: Transaction, params: ExecuteWithdrawalWormholeParams): void;
|
|
105
105
|
export interface ExecuteWithdrawalNativeParams {
|
|
106
106
|
key: bigint | number;
|
|
107
107
|
/** Fully-qualified backing asset Move type `T` (must match the entry's route). */
|
|
@@ -110,7 +110,7 @@ export interface ExecuteWithdrawalNativeParams {
|
|
|
110
110
|
bucketAccount?: string | TransactionArgument;
|
|
111
111
|
}
|
|
112
112
|
/** Build `withdrawal_queue::execute_native<T, CREDIT>` (keeper / executor-gated). */
|
|
113
|
-
export declare function executeWithdrawalNative(client:
|
|
113
|
+
export declare function executeWithdrawalNative(client: AccountClientLike, tx: Transaction, params: ExecuteWithdrawalNativeParams): void;
|
|
114
114
|
export interface CustodyMintParams {
|
|
115
115
|
/** wxa account ID the minted CREDIT lands in. */
|
|
116
116
|
accountId: string;
|
|
@@ -126,4 +126,4 @@ export interface CustodyMintParams {
|
|
|
126
126
|
* `DepositRequest<CREDIT>` hot-potato argument (consume in-PTB via
|
|
127
127
|
* {@link consumeCreditDeposit}).
|
|
128
128
|
*/
|
|
129
|
-
export declare function custodyMint(client:
|
|
129
|
+
export declare function custodyMint(client: AccountClientLike, tx: Transaction, params: CustodyMintParams): TransactionArgument;
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { fromHex } from "@mysten/bcs";
|
|
21
21
|
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
22
|
-
import { mint as custodyMintCall } from "
|
|
23
|
-
import { requestWithdraw as requestWithdrawCall } from "
|
|
24
|
-
import { consumeDepositDirect } from "
|
|
25
|
-
import { enqueue as enqueueCall, executeNative as executeNativeCall, executeWormhole as executeWormholeCall, routeNative as routeNativeCall, routeWormhole as routeWormholeCall, } from "
|
|
26
|
-
import { redeemVaa as redeemVaaCall } from "
|
|
27
|
-
import { makeSenderRequest } from "../
|
|
22
|
+
import { mint as custodyMintCall } from "../../generated/native_custody/custody_vault.js";
|
|
23
|
+
import { requestWithdraw as requestWithdrawCall } from "../../generated/waterx_account/account.js";
|
|
24
|
+
import { consumeDepositDirect } from "../../generated/waterx_account/direct_rule.js";
|
|
25
|
+
import { enqueue as enqueueCall, executeNative as executeNativeCall, executeWormhole as executeWormholeCall, routeNative as routeNativeCall, routeWormhole as routeWormholeCall, } from "../../generated/withdrawal_queue/withdrawal_queue.js";
|
|
26
|
+
import { redeemVaa as redeemVaaCall } from "../../generated/wormhole_bridge/wormhole_bridge.js";
|
|
27
|
+
import { makeSenderRequest } from "../account-request.js";
|
|
28
28
|
// ============================================================================
|
|
29
29
|
// Byte helpers
|
|
30
30
|
// ============================================================================
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* credit pipeline.
|
|
18
18
|
*/
|
|
19
19
|
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
20
|
-
import type {
|
|
20
|
+
import type { AccountClientLike } from "../client.ts";
|
|
21
21
|
export interface MintCreditParams {
|
|
22
22
|
/** wxa account ID the minted CREDIT is deposited into (also the partner-fee key). */
|
|
23
23
|
accountId: string;
|
|
@@ -34,7 +34,7 @@ export interface MintCreditParams {
|
|
|
34
34
|
* Build `custody_vault::mint<T, CREDIT>`. Returns the `DepositRequest<CREDIT>`
|
|
35
35
|
* argument — consume it in the same PTB (see `mintCreditToAccount`).
|
|
36
36
|
*/
|
|
37
|
-
export declare function mintCredit(client:
|
|
37
|
+
export declare function mintCredit(client: AccountClientLike, tx: Transaction, params: MintCreditParams): TransactionArgument;
|
|
38
38
|
export interface MintCreditFromRequestParams {
|
|
39
39
|
/** `DepositRequest<T>` from `account::request_deposit<T>` (T must have `NativeCustody` as its deposit policy). */
|
|
40
40
|
depositRequest: TransactionArgument;
|
|
@@ -48,10 +48,10 @@ export interface MintCreditFromRequestParams {
|
|
|
48
48
|
* `DepositRequest<CREDIT>` inherits the input request's `accountId` /
|
|
49
49
|
* `extraData`. Consume it in the same PTB.
|
|
50
50
|
*/
|
|
51
|
-
export declare function mintCreditFromRequest(client:
|
|
51
|
+
export declare function mintCreditFromRequest(client: AccountClientLike, tx: Transaction, params: MintCreditFromRequestParams): TransactionArgument;
|
|
52
52
|
/**
|
|
53
53
|
* `mintCredit` followed by `direct_rule::consume_deposit_direct<CREDIT>`, so
|
|
54
54
|
* the freshly minted CREDIT settles straight into `accountId`'s wxa balance.
|
|
55
55
|
* Assumes CREDIT's deposit policy is `DirectRule` (the canonical setup).
|
|
56
56
|
*/
|
|
57
|
-
export declare function mintCreditToAccount(client:
|
|
57
|
+
export declare function mintCreditToAccount(client: AccountClientLike, tx: Transaction, params: MintCreditParams): void;
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
* credit pipeline.
|
|
18
18
|
*/
|
|
19
19
|
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
20
|
-
import * as custody from "
|
|
21
|
-
import { consumeDepositDirect } from "
|
|
20
|
+
import * as custody from "../../generated/native_custody/custody_vault.js";
|
|
21
|
+
import { consumeDepositDirect } from "../../generated/waterx_account/direct_rule.js";
|
|
22
22
|
function requireCredit(client) {
|
|
23
23
|
const credit = client.config.packages.waterx_credit;
|
|
24
24
|
if (!credit?.credit_registry) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Wormhole / Wormholescan integration for the cross-chain credit bridge.
|
|
3
3
|
*
|
|
4
4
|
* Single source of truth for VAA discovery + (de)serialization — mirrors
|
|
5
|
-
* `
|
|
5
|
+
* `oracle/pyth.ts`'s role for Pyth's Hermes endpoint. Two directions:
|
|
6
6
|
*
|
|
7
7
|
* - Mint (EVM → Sui): fetch the signed VAA for an EVM `Deposit` by
|
|
8
8
|
* (emitter chain, emitter address, sequence); the raw bytes feed
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* Endpoints / chain ids come from `client.wormhole` (network defaults in
|
|
14
14
|
* `WORMHOLE_DEFAULTS`, overridable via `WaterXConfig.wormhole`).
|
|
15
15
|
*/
|
|
16
|
-
import type {
|
|
16
|
+
import type { AccountClientLike } from "../client.ts";
|
|
17
17
|
/**
|
|
18
18
|
* Normalize an emitter id to Wormholescan's `emitter` path segment:
|
|
19
19
|
* 64-char lowercase hex, no `0x`. Accepts a 0x EVM address (left-padded to
|
|
@@ -75,12 +75,12 @@ export declare function vaaBase64ToHex(b64: string): `0x${string}`;
|
|
|
75
75
|
* address (0x form accepted — left-padded automatically); `chainId` is the
|
|
76
76
|
* source EVM chain's Wormhole chain id.
|
|
77
77
|
*/
|
|
78
|
-
export declare function fetchDepositVaa(client:
|
|
78
|
+
export declare function fetchDepositVaa(client: AccountClientLike, evmWormholeChainId: number, evmEmitter: string, sequence: number | string | bigint, opts?: WormholescanOptions): Promise<VaaResponse | null>;
|
|
79
79
|
/**
|
|
80
80
|
* List recent Sui→EVM VAAs from the configured bridge `EmitterCap` (burn
|
|
81
81
|
* relayer). Requires `packages.wormhole_bridge.emitter_cap` in config.
|
|
82
82
|
*/
|
|
83
|
-
export declare function listBridgeWithdrawalVaas(client:
|
|
83
|
+
export declare function listBridgeWithdrawalVaas(client: AccountClientLike, opts?: WormholescanOptions & {
|
|
84
84
|
page?: number;
|
|
85
85
|
pageSize?: number;
|
|
86
86
|
}): Promise<VaaListItem[]>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Wormhole / Wormholescan integration for the cross-chain credit bridge.
|
|
3
3
|
*
|
|
4
4
|
* Single source of truth for VAA discovery + (de)serialization — mirrors
|
|
5
|
-
* `
|
|
5
|
+
* `oracle/pyth.ts`'s role for Pyth's Hermes endpoint. Two directions:
|
|
6
6
|
*
|
|
7
7
|
* - Mint (EVM → Sui): fetch the signed VAA for an EVM `Deposit` by
|
|
8
8
|
* (emitter chain, emitter address, sequence); the raw bytes feed
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified WaterX account namespace — exposed as `client.account`.
|
|
3
|
+
*
|
|
4
|
+
* Aggregates the generic `waterx_account` framework builders with the funding
|
|
5
|
+
* (credit + custody) builders into one surface. This is the contract's **base**
|
|
6
|
+
* layer: it lives under `account/` and depends only **down** (base-client /
|
|
7
|
+
* constants / generated) — it must never import `perp/` or `prediction/`. Builders
|
|
8
|
+
* are typed to the {@link AccountClientLike} capability interface (in `./client.ts`),
|
|
9
|
+
* which `PerpClient` satisfies structurally; `bindClient` passes the perp-line
|
|
10
|
+
* client (which carries the shared `waterx_account` + `AccountRegistry`, bridge /
|
|
11
|
+
* native_custody / withdrawal_queue / credit_registry) as arg 0. Because
|
|
12
|
+
* `waterx_account` is a single shared object across both product lines, an account
|
|
13
|
+
* created here is usable by perp and prediction alike (see the cross-network caveat
|
|
14
|
+
* on the umbrella `WaterXClient`).
|
|
15
|
+
*
|
|
16
|
+
* The prediction-specific account operations (delegate prediction permission,
|
|
17
|
+
* prediction protocol whitelist / asset allowlist) are NOT generic and stay on
|
|
18
|
+
* `client.predict`.
|
|
19
|
+
*
|
|
20
|
+
* INVARIANT: every export below must be **client-first** — `bindClient` (in
|
|
21
|
+
* `unified-client.ts`) blindly binds the client as arg 0 to each function here, so
|
|
22
|
+
* a non-client-first helper (e.g. a local crypto/URL util) leaking out of these
|
|
23
|
+
* modules would be mis-bound silently. Keep such helpers unexported, or add them to
|
|
24
|
+
* `NON_CLIENT_FIRST` in `unified-client.ts` (the coverage guard in
|
|
25
|
+
* `test/perp/unit/unified-client.test.ts` only excuses names on that list).
|
|
26
|
+
*/
|
|
27
|
+
export * from "./account.ts";
|
|
28
|
+
export * from "./funding/credit.ts";
|
|
29
|
+
export * from "./funding/custody.ts";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified WaterX account namespace — exposed as `client.account`.
|
|
3
|
+
*
|
|
4
|
+
* Aggregates the generic `waterx_account` framework builders with the funding
|
|
5
|
+
* (credit + custody) builders into one surface. This is the contract's **base**
|
|
6
|
+
* layer: it lives under `account/` and depends only **down** (base-client /
|
|
7
|
+
* constants / generated) — it must never import `perp/` or `prediction/`. Builders
|
|
8
|
+
* are typed to the {@link AccountClientLike} capability interface (in `./client.ts`),
|
|
9
|
+
* which `PerpClient` satisfies structurally; `bindClient` passes the perp-line
|
|
10
|
+
* client (which carries the shared `waterx_account` + `AccountRegistry`, bridge /
|
|
11
|
+
* native_custody / withdrawal_queue / credit_registry) as arg 0. Because
|
|
12
|
+
* `waterx_account` is a single shared object across both product lines, an account
|
|
13
|
+
* created here is usable by perp and prediction alike (see the cross-network caveat
|
|
14
|
+
* on the umbrella `WaterXClient`).
|
|
15
|
+
*
|
|
16
|
+
* The prediction-specific account operations (delegate prediction permission,
|
|
17
|
+
* prediction protocol whitelist / asset allowlist) are NOT generic and stay on
|
|
18
|
+
* `client.predict`.
|
|
19
|
+
*
|
|
20
|
+
* INVARIANT: every export below must be **client-first** — `bindClient` (in
|
|
21
|
+
* `unified-client.ts`) blindly binds the client as arg 0 to each function here, so
|
|
22
|
+
* a non-client-first helper (e.g. a local crypto/URL util) leaking out of these
|
|
23
|
+
* modules would be mis-bound silently. Keep such helpers unexported, or add them to
|
|
24
|
+
* `NON_CLIENT_FIRST` in `unified-client.ts` (the coverage guard in
|
|
25
|
+
* `test/perp/unit/unified-client.test.ts` only excuses names on that list).
|
|
26
|
+
*/
|
|
27
|
+
export * from "./account.js"; // generic waterx_account framework builders
|
|
28
|
+
export * from "./funding/credit.js"; // cross-chain CREDIT / bridge builders
|
|
29
|
+
export * from "./funding/custody.js"; // native_custody PSM mint builders
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
* loudly instead of silently aborting on-chain.
|
|
7
7
|
*/
|
|
8
8
|
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
9
|
-
import type {
|
|
9
|
+
import type { WxaClientLike } from "./client.ts";
|
|
10
10
|
export interface SetReferralCodeParams {
|
|
11
11
|
/** Referral code string the caller wants to claim. */
|
|
12
12
|
code: string;
|
|
13
13
|
bucketAccount?: string | TransactionArgument;
|
|
14
14
|
}
|
|
15
|
-
export declare function setReferralCode(client:
|
|
15
|
+
export declare function setReferralCode(client: WxaClientLike, tx: Transaction, params: SetReferralCodeParams): void;
|
|
16
16
|
export interface UseReferralCodeParams {
|
|
17
17
|
/** Referral code to bind to the caller's address. */
|
|
18
18
|
code: string;
|
|
19
19
|
bucketAccount?: string | TransactionArgument;
|
|
20
20
|
}
|
|
21
|
-
export declare function useReferralCode(client:
|
|
21
|
+
export declare function useReferralCode(client: WxaClientLike, tx: Transaction, params: UseReferralCodeParams): void;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* loudly instead of silently aborting on-chain.
|
|
7
7
|
*/
|
|
8
8
|
import * as referral from "../generated/waterx_referral/referral_table.js";
|
|
9
|
-
import { makeSenderRequest } from "
|
|
9
|
+
import { makeSenderRequest } from "./account-request.js";
|
|
10
10
|
function requireReferralConfig(client) {
|
|
11
11
|
const pkg = client.config.packages.waterx_referral?.published_at;
|
|
12
12
|
const table = client.config.packages.waterx_referral?.referral_table;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared transport base for the two product-line clients (`PerpClient`,
|
|
3
|
+
* `PredictClient`).
|
|
4
|
+
*
|
|
5
|
+
* Holds the half that is identical across both lines: the gRPC client
|
|
6
|
+
* construction (network + URL resolution), the read-only gRPC convenience
|
|
7
|
+
* wrappers, `simulate` / `signAndExecuteTransaction`, and the `packageIds()`
|
|
8
|
+
* lookup. The config-schema half (per-line typed lookups like `getMarket` /
|
|
9
|
+
* `marketRegistry`) legitimately differs and lives on each subclass.
|
|
10
|
+
*
|
|
11
|
+
* `Cfg` is the line's parsed `waterx-config` JSON type. Only the fields needed
|
|
12
|
+
* here are constrained ({@link BaseLineConfig}); each subclass narrows `Cfg` to
|
|
13
|
+
* its full config type so `this.config` stays precisely typed.
|
|
14
|
+
*/
|
|
15
|
+
import type { SuiClientTypes } from "@mysten/sui/client";
|
|
16
|
+
import type { Signer } from "@mysten/sui/cryptography";
|
|
17
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
18
|
+
import type { Transaction } from "@mysten/sui/transactions";
|
|
19
|
+
import type { Network } from "./constants.ts";
|
|
20
|
+
/** Default Sui gRPC base URLs by network (public Mysten fullnodes). */
|
|
21
|
+
export declare const DEFAULT_GRPC_URLS: Record<Network, string>;
|
|
22
|
+
/** Minimal shape of a line config that {@link BaseLineClient} reads directly. */
|
|
23
|
+
export interface BaseLineConfig {
|
|
24
|
+
/** Sui gRPC base URL override (default: public Mysten fullnode for the network). */
|
|
25
|
+
grpcUrl?: string;
|
|
26
|
+
/** Package map — iterated by {@link BaseLineClient.packageIds}. */
|
|
27
|
+
packages: object;
|
|
28
|
+
}
|
|
29
|
+
export declare abstract class BaseLineClient<Cfg extends BaseLineConfig = BaseLineConfig> {
|
|
30
|
+
/** gRPC client — all RPC including `simulateTransaction`. */
|
|
31
|
+
grpcClient: SuiGrpcClient;
|
|
32
|
+
/** Network identifier in upper case (`MAINNET` / `TESTNET`). */
|
|
33
|
+
network: Network;
|
|
34
|
+
/** Parsed canonical `waterx-config` JSON for this line. */
|
|
35
|
+
config: Cfg;
|
|
36
|
+
protected constructor(network: Network, config: Cfg, opts?: {
|
|
37
|
+
grpcUrl?: string;
|
|
38
|
+
});
|
|
39
|
+
getObject(objectId: string): Promise<SuiClientTypes.GetObjectResponse<{}>>;
|
|
40
|
+
getObjects(objectIds: string[]): Promise<SuiClientTypes.GetObjectsResponse<{}>>;
|
|
41
|
+
listOwnedObjects(owner: string): Promise<SuiClientTypes.ListOwnedObjectsResponse<{}>>;
|
|
42
|
+
listCoins(params: {
|
|
43
|
+
owner: string;
|
|
44
|
+
coinType?: string;
|
|
45
|
+
}): Promise<SuiClientTypes.ListCoinsResponse>;
|
|
46
|
+
getBalance(params: {
|
|
47
|
+
owner: string;
|
|
48
|
+
coinType?: string;
|
|
49
|
+
}): Promise<SuiClientTypes.GetBalanceResponse>;
|
|
50
|
+
listDynamicFields(parentId: string): ReturnType<SuiGrpcClient["listDynamicFields"]>;
|
|
51
|
+
getDynamicField(parentId: string, name: {
|
|
52
|
+
type: string;
|
|
53
|
+
bcs: Uint8Array;
|
|
54
|
+
}): Promise<SuiClientTypes.GetDynamicFieldResponse>;
|
|
55
|
+
waitForTransaction(digest: string): Promise<SuiClientTypes.TransactionResult<{}>>;
|
|
56
|
+
/**
|
|
57
|
+
* Simulate a transaction (no signing). Subclasses may override to add
|
|
58
|
+
* transport policy (e.g. the prediction line wraps this with rate-limit
|
|
59
|
+
* retry against the public testnet RPC).
|
|
60
|
+
*/
|
|
61
|
+
simulate(tx: Transaction): Promise<SuiClientTypes.SimulateTransactionResult<{
|
|
62
|
+
commandResults: true;
|
|
63
|
+
}>>;
|
|
64
|
+
signAndExecuteTransaction<Include extends SuiClientTypes.TransactionInclude = object>(params: {
|
|
65
|
+
signer: {
|
|
66
|
+
toSuiAddress: () => string;
|
|
67
|
+
} & Signer;
|
|
68
|
+
transaction: Transaction | Uint8Array;
|
|
69
|
+
additionalSignatures?: string[];
|
|
70
|
+
include?: Include & SuiClientTypes.TransactionInclude;
|
|
71
|
+
}): Promise<SuiClientTypes.TransactionResult<Include & SuiClientTypes.TransactionInclude>>;
|
|
72
|
+
/** All package IDs (`published_at`) keyed by package name. */
|
|
73
|
+
packageIds(): Record<string, string>;
|
|
74
|
+
}
|