@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
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account-side builders for the `waterx_account` framework.
|
|
3
|
+
*
|
|
4
|
+
* In v3, `waterx_account` is the only account abstraction — `waterx_perp`
|
|
5
|
+
* stores per-account state under `ProtocolDataKey<WaterXPerp>()` on a wxa
|
|
6
|
+
* `Account` and uses witness-gated `take` / `put` for collateral.
|
|
7
|
+
*
|
|
8
|
+
* All builders that mutate the account pass `account::request()` or
|
|
9
|
+
* `account::request_with_account(&Account)` internally. To act through
|
|
10
|
+
* a Bucket `Account` object, pass `bucketAccount` (an object ID string
|
|
11
|
+
* or a `TransactionArgument`).
|
|
12
|
+
*/
|
|
13
|
+
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
14
|
+
import type { WaterXClient } from "../client.ts";
|
|
15
|
+
export interface CreateAccountParams {
|
|
16
|
+
/** Alias / display name for the new account (max length checked on-chain). */
|
|
17
|
+
alias: string;
|
|
18
|
+
/** Optional Bucket Account to act through (otherwise tx.sender). */
|
|
19
|
+
bucketAccount?: string | TransactionArgument;
|
|
20
|
+
}
|
|
21
|
+
/** Build `waterx_account::create_account`. Returns the new account ID via Move return value. */
|
|
22
|
+
export declare function createAccount(client: WaterXClient, tx: Transaction, params: CreateAccountParams): void;
|
|
23
|
+
export interface SetAliasParams {
|
|
24
|
+
accountId: string;
|
|
25
|
+
alias: string;
|
|
26
|
+
bucketAccount?: string | TransactionArgument;
|
|
27
|
+
}
|
|
28
|
+
export declare function setAlias(client: WaterXClient, tx: Transaction, params: SetAliasParams): void;
|
|
29
|
+
export interface AddDelegateParams {
|
|
30
|
+
accountId: string;
|
|
31
|
+
delegateAddress: string;
|
|
32
|
+
alias: string;
|
|
33
|
+
/** Bitmask matching `waterx_account` permission constants. */
|
|
34
|
+
permissions: number;
|
|
35
|
+
/** Optional millisecond timestamp at which the delegate expires. */
|
|
36
|
+
expiresAtMs?: bigint | number;
|
|
37
|
+
bucketAccount?: string | TransactionArgument;
|
|
38
|
+
}
|
|
39
|
+
export declare function addDelegate(client: WaterXClient, tx: Transaction, params: AddDelegateParams): void;
|
|
40
|
+
export interface RemoveDelegateParams {
|
|
41
|
+
accountId: string;
|
|
42
|
+
delegateAddress: string;
|
|
43
|
+
bucketAccount?: string | TransactionArgument;
|
|
44
|
+
}
|
|
45
|
+
export declare function removeDelegate(client: WaterXClient, tx: Transaction, params: RemoveDelegateParams): void;
|
|
46
|
+
export interface SetDelegateProtocolPermissionParams {
|
|
47
|
+
accountId: string;
|
|
48
|
+
delegateAddress: string;
|
|
49
|
+
/** Bitmask of per-protocol permissions (e.g. perm_open_position | perm_close_position). */
|
|
50
|
+
permissions: number;
|
|
51
|
+
/** Fully-qualified Move type of the protocol witness (e.g. `0x…::account_data::WaterXPerp`). */
|
|
52
|
+
protocolType: string;
|
|
53
|
+
bucketAccount?: string | TransactionArgument;
|
|
54
|
+
}
|
|
55
|
+
export declare function setDelegateProtocolPermission(client: WaterXClient, tx: Transaction, params: SetDelegateProtocolPermissionParams): void;
|
|
56
|
+
export interface RequestDepositParams {
|
|
57
|
+
/** wxa account ID receiving the deposit. */
|
|
58
|
+
accountId: string;
|
|
59
|
+
/** Coin or coin transaction argument to deposit. */
|
|
60
|
+
coin: TransactionArgument;
|
|
61
|
+
/** Fully-qualified coin type. */
|
|
62
|
+
coinType: string;
|
|
63
|
+
/** Optional opaque extra data forwarded to the policy. */
|
|
64
|
+
extraData?: Uint8Array;
|
|
65
|
+
}
|
|
66
|
+
/** Build `account::request_deposit<T>`. Returns the `DepositRequest<T>` argument. */
|
|
67
|
+
export declare function requestDeposit(client: WaterXClient, tx: Transaction, params: RequestDepositParams): TransactionArgument;
|
|
68
|
+
export interface RequestDepositFromReceivingsParams {
|
|
69
|
+
/** wxa account ID receiving the deposit. */
|
|
70
|
+
accountId: string;
|
|
71
|
+
/**
|
|
72
|
+
* `Receiving<Coin<T>>` arguments — one per `Coin<T>` previously transferred
|
|
73
|
+
* onto the account's address. Build each with
|
|
74
|
+
* `tx.receivingRef({ objectId, version, digest })`.
|
|
75
|
+
*/
|
|
76
|
+
receivings: TransactionArgument[];
|
|
77
|
+
/** Fully-qualified coin type `T`. */
|
|
78
|
+
coinType: string;
|
|
79
|
+
/** Optional opaque extra data forwarded to the policy. */
|
|
80
|
+
extraData?: Uint8Array;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build `account::request_deposit_from_receivings<T>` — drains `Coin<T>`
|
|
84
|
+
* objects previously transferred onto the account's address (the
|
|
85
|
+
* transfer-to-object path) into a single `DepositRequest<T>`. Returns the
|
|
86
|
+
* `DepositRequest<T>` argument.
|
|
87
|
+
*/
|
|
88
|
+
export declare function requestDepositFromReceivings(client: WaterXClient, tx: Transaction, params: RequestDepositFromReceivingsParams): TransactionArgument;
|
|
89
|
+
export interface RequestWithdrawParams {
|
|
90
|
+
accountId: string;
|
|
91
|
+
amount: bigint | number;
|
|
92
|
+
/** Recipient for the eventual coin payout (policy decides exact mechanics). */
|
|
93
|
+
recipient: string;
|
|
94
|
+
/** Fully-qualified coin type. */
|
|
95
|
+
coinType: string;
|
|
96
|
+
/** Optional opaque extra data forwarded to the policy. */
|
|
97
|
+
extraData?: Uint8Array;
|
|
98
|
+
bucketAccount?: string | TransactionArgument;
|
|
99
|
+
}
|
|
100
|
+
/** Build `account::request_withdraw<T>`. Returns the `WithdrawRequest<T>` argument. */
|
|
101
|
+
export declare function requestWithdraw(client: WaterXClient, tx: Transaction, params: RequestWithdrawParams): TransactionArgument;
|
|
102
|
+
export interface TransferToAccountParams {
|
|
103
|
+
accountId: string;
|
|
104
|
+
coin: TransactionArgument;
|
|
105
|
+
coinType: string;
|
|
106
|
+
}
|
|
107
|
+
export declare function transferToAccount(client: WaterXClient, tx: Transaction, params: TransferToAccountParams): void;
|
|
108
|
+
export interface ReceiveParams {
|
|
109
|
+
accountId: string;
|
|
110
|
+
/**
|
|
111
|
+
* `Receiving<T>` argument for the TTO'd object. Construct via
|
|
112
|
+
* `tx.receivingRef({ objectId, version, digest })` from the on-chain
|
|
113
|
+
* object's ID/version/digest (e.g. from
|
|
114
|
+
* `FundsReaderService.listUnreceivedRewardCoins` on the BE).
|
|
115
|
+
*/
|
|
116
|
+
receiving: TransactionArgument;
|
|
117
|
+
/** Fully-qualified `T` Move type — typically `Coin<R>` for reward coins. */
|
|
118
|
+
receivingType: string;
|
|
119
|
+
bucketAccount?: string | TransactionArgument;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Calls `waterx_account::receive<T>` to drain a TTO'd object on the
|
|
123
|
+
* account's UID. Returns the received object to the caller's PTB so it
|
|
124
|
+
* can be merged / transferred / consumed downstream in the same tx.
|
|
125
|
+
*
|
|
126
|
+
* Bypasses the deposit-policy flow — use for reward coins (and other
|
|
127
|
+
* tokens / objects) that have no registered deposit policy.
|
|
128
|
+
*/
|
|
129
|
+
export declare function receive(client: WaterXClient, tx: Transaction, params: ReceiveParams): TransactionArgument;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account-side builders for the `waterx_account` framework.
|
|
3
|
+
*
|
|
4
|
+
* In v3, `waterx_account` is the only account abstraction — `waterx_perp`
|
|
5
|
+
* stores per-account state under `ProtocolDataKey<WaterXPerp>()` on a wxa
|
|
6
|
+
* `Account` and uses witness-gated `take` / `put` for collateral.
|
|
7
|
+
*
|
|
8
|
+
* All builders that mutate the account pass `account::request()` or
|
|
9
|
+
* `account::request_with_account(&Account)` internally. To act through
|
|
10
|
+
* a Bucket `Account` object, pass `bucketAccount` (an object ID string
|
|
11
|
+
* or a `TransactionArgument`).
|
|
12
|
+
*/
|
|
13
|
+
import * as wxa from "../generated/waterx_account/account.js";
|
|
14
|
+
import { makeSenderRequest } from "../utils/account-request.js";
|
|
15
|
+
/** Build `waterx_account::create_account`. Returns the new account ID via Move return value. */
|
|
16
|
+
export function createAccount(client, tx, params) {
|
|
17
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
18
|
+
wxa.createAccount({
|
|
19
|
+
package: client.config.packages.waterx_account.published_at,
|
|
20
|
+
arguments: {
|
|
21
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
22
|
+
senderRequest: req,
|
|
23
|
+
alias: params.alias,
|
|
24
|
+
},
|
|
25
|
+
})(tx);
|
|
26
|
+
}
|
|
27
|
+
export function setAlias(client, tx, params) {
|
|
28
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
29
|
+
wxa.setAlias({
|
|
30
|
+
package: client.config.packages.waterx_account.published_at,
|
|
31
|
+
arguments: {
|
|
32
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
33
|
+
senderRequest: req,
|
|
34
|
+
accountId: params.accountId,
|
|
35
|
+
alias: params.alias,
|
|
36
|
+
},
|
|
37
|
+
})(tx);
|
|
38
|
+
}
|
|
39
|
+
export function addDelegate(client, tx, params) {
|
|
40
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
41
|
+
wxa.addDelegate({
|
|
42
|
+
package: client.config.packages.waterx_account.published_at,
|
|
43
|
+
arguments: {
|
|
44
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
45
|
+
senderRequest: req,
|
|
46
|
+
accountId: params.accountId,
|
|
47
|
+
delegateAddress: params.delegateAddress,
|
|
48
|
+
alias: params.alias,
|
|
49
|
+
permissions: params.permissions,
|
|
50
|
+
expiresAtMs: params.expiresAtMs ?? null,
|
|
51
|
+
},
|
|
52
|
+
})(tx);
|
|
53
|
+
}
|
|
54
|
+
export function removeDelegate(client, tx, params) {
|
|
55
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
56
|
+
wxa.removeDelegate({
|
|
57
|
+
package: client.config.packages.waterx_account.published_at,
|
|
58
|
+
arguments: {
|
|
59
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
60
|
+
senderRequest: req,
|
|
61
|
+
accountId: params.accountId,
|
|
62
|
+
delegateAddress: params.delegateAddress,
|
|
63
|
+
},
|
|
64
|
+
})(tx);
|
|
65
|
+
}
|
|
66
|
+
export function setDelegateProtocolPermission(client, tx, params) {
|
|
67
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
68
|
+
wxa.setDelegateProtocolPermission({
|
|
69
|
+
package: client.config.packages.waterx_account.published_at,
|
|
70
|
+
arguments: {
|
|
71
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
72
|
+
senderRequest: req,
|
|
73
|
+
accountId: params.accountId,
|
|
74
|
+
delegateAddress: params.delegateAddress,
|
|
75
|
+
permissions: params.permissions,
|
|
76
|
+
},
|
|
77
|
+
typeArguments: [params.protocolType],
|
|
78
|
+
})(tx);
|
|
79
|
+
}
|
|
80
|
+
/** Build `account::request_deposit<T>`. Returns the `DepositRequest<T>` argument. */
|
|
81
|
+
export function requestDeposit(client, tx, params) {
|
|
82
|
+
const [req] = wxa.requestDeposit({
|
|
83
|
+
package: client.config.packages.waterx_account.published_at,
|
|
84
|
+
arguments: {
|
|
85
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
86
|
+
accountId: params.accountId,
|
|
87
|
+
coin: params.coin,
|
|
88
|
+
extraData: Array.from(params.extraData ?? new Uint8Array()),
|
|
89
|
+
},
|
|
90
|
+
typeArguments: [params.coinType],
|
|
91
|
+
})(tx);
|
|
92
|
+
return req;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Build `account::request_deposit_from_receivings<T>` — drains `Coin<T>`
|
|
96
|
+
* objects previously transferred onto the account's address (the
|
|
97
|
+
* transfer-to-object path) into a single `DepositRequest<T>`. Returns the
|
|
98
|
+
* `DepositRequest<T>` argument.
|
|
99
|
+
*/
|
|
100
|
+
export function requestDepositFromReceivings(client, tx, params) {
|
|
101
|
+
const receivings = tx.makeMoveVec({
|
|
102
|
+
type: `0x2::transfer::Receiving<0x2::coin::Coin<${params.coinType}>>`,
|
|
103
|
+
elements: params.receivings,
|
|
104
|
+
});
|
|
105
|
+
const [req] = wxa.requestDepositFromReceivings({
|
|
106
|
+
package: client.config.packages.waterx_account.published_at,
|
|
107
|
+
arguments: {
|
|
108
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
109
|
+
accountId: params.accountId,
|
|
110
|
+
receivings: receivings,
|
|
111
|
+
extraData: Array.from(params.extraData ?? new Uint8Array()),
|
|
112
|
+
},
|
|
113
|
+
typeArguments: [params.coinType],
|
|
114
|
+
})(tx);
|
|
115
|
+
return req;
|
|
116
|
+
}
|
|
117
|
+
/** Build `account::request_withdraw<T>`. Returns the `WithdrawRequest<T>` argument. */
|
|
118
|
+
export function requestWithdraw(client, tx, params) {
|
|
119
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
120
|
+
const [out] = wxa.requestWithdraw({
|
|
121
|
+
package: client.config.packages.waterx_account.published_at,
|
|
122
|
+
arguments: {
|
|
123
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
124
|
+
senderRequest: req,
|
|
125
|
+
accountId: params.accountId,
|
|
126
|
+
amount: params.amount,
|
|
127
|
+
recipient: params.recipient,
|
|
128
|
+
extraData: Array.from(params.extraData ?? new Uint8Array()),
|
|
129
|
+
},
|
|
130
|
+
typeArguments: [params.coinType],
|
|
131
|
+
})(tx);
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
export function transferToAccount(client, tx, params) {
|
|
135
|
+
wxa.transferCoin({
|
|
136
|
+
package: client.config.packages.waterx_account.published_at,
|
|
137
|
+
arguments: {
|
|
138
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
139
|
+
accountId: params.accountId,
|
|
140
|
+
coin: params.coin,
|
|
141
|
+
},
|
|
142
|
+
typeArguments: [params.coinType],
|
|
143
|
+
})(tx);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Calls `waterx_account::receive<T>` to drain a TTO'd object on the
|
|
147
|
+
* account's UID. Returns the received object to the caller's PTB so it
|
|
148
|
+
* can be merged / transferred / consumed downstream in the same tx.
|
|
149
|
+
*
|
|
150
|
+
* Bypasses the deposit-policy flow — use for reward coins (and other
|
|
151
|
+
* tokens / objects) that have no registered deposit policy.
|
|
152
|
+
*/
|
|
153
|
+
export function receive(client, tx, params) {
|
|
154
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
155
|
+
const out = wxa.receive({
|
|
156
|
+
package: client.config.packages.waterx_account.published_at,
|
|
157
|
+
arguments: {
|
|
158
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
159
|
+
senderRequest: req,
|
|
160
|
+
accountId: params.accountId,
|
|
161
|
+
receiving: params.receiving,
|
|
162
|
+
},
|
|
163
|
+
typeArguments: [params.receivingType],
|
|
164
|
+
})(tx);
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-chain credit / bridge builders (low-level — one moveCall per fn).
|
|
3
|
+
*
|
|
4
|
+
* Flows (see waterx_credit/sui/*):
|
|
5
|
+
* - Mint (EVM → Sui): `redeemVaa` → `DepositRequest<CREDIT>` hot potato,
|
|
6
|
+
* consumed in the same PTB by `consumeCreditDeposit` (the wxa deposit
|
|
7
|
+
* policy CREDIT is registered under — selected via config).
|
|
8
|
+
* - Withdraw (Sui → EVM / native): `routeWormhole` / `routeNative` encode
|
|
9
|
+
* `extra_data`, fed to `account::request_withdraw` →
|
|
10
|
+
* `enqueueWithdrawal` parks a FIFO `Queue<CREDIT>` entry.
|
|
11
|
+
* - Keeper drains the queue via `executeWithdrawalWormhole` /
|
|
12
|
+
* `executeWithdrawalNative` (caller must be on the executor allowlist).
|
|
13
|
+
* - PSM: `custodyMint` / `custodyBurn` against the native `CustodyVault`.
|
|
14
|
+
*
|
|
15
|
+
* Every builder that emits a hot potato returns its argument so the caller
|
|
16
|
+
* (or the high-level `tx-builders.ts` wrappers) can pair + consume it in the
|
|
17
|
+
* same PTB.
|
|
18
|
+
*/
|
|
19
|
+
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
20
|
+
import type { WaterXClient } from "../client.ts";
|
|
21
|
+
export interface RedeemVaaParams {
|
|
22
|
+
/** Signed Wormhole MINT VAA (raw bytes / number[] / hex). */
|
|
23
|
+
vaaBytes: Uint8Array | number[] | string;
|
|
24
|
+
/** Override the CREDIT Move type (defaults to `client.creditType()`). */
|
|
25
|
+
creditType?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build `wormhole_bridge::redeem_vaa<CREDIT>`. Returns the
|
|
29
|
+
* `DepositRequest<CREDIT>` hot-potato argument — **must** be consumed in the
|
|
30
|
+
* same PTB (see {@link consumeCreditDeposit} / `redeemVaaTx`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function redeemVaa(client: WaterXClient, tx: Transaction, params: RedeemVaaParams): TransactionArgument;
|
|
33
|
+
export interface ConsumeCreditDepositParams {
|
|
34
|
+
/** The `DepositRequest<CREDIT>` returned by {@link redeemVaa} / {@link custodyMint}. */
|
|
35
|
+
depositRequest: TransactionArgument;
|
|
36
|
+
creditType?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Consume a `DepositRequest<CREDIT>` via `direct_rule::consume_deposit_direct`
|
|
40
|
+
* — the wxa deposit policy CREDIT is registered under (deploy.ts phase 2:
|
|
41
|
+
* `register_deposit_policy<CREDIT, DirectRule>`). Must run in the same PTB
|
|
42
|
+
* as the `redeem_vaa` / custody `mint` that produced the request.
|
|
43
|
+
*/
|
|
44
|
+
export declare function consumeCreditDeposit(client: WaterXClient, tx: Transaction, params: ConsumeCreditDepositParams): void;
|
|
45
|
+
export interface RouteWormholeParams {
|
|
46
|
+
/** Destination EVM chain's Wormhole chain id. */
|
|
47
|
+
evmDestinationChain: number;
|
|
48
|
+
/** 20-byte EVM recipient (Uint8Array / number[] / hex). */
|
|
49
|
+
evmRecipient: Uint8Array | number[] | string;
|
|
50
|
+
/** 20-byte EVM token (Uint8Array / number[] / hex). */
|
|
51
|
+
evmToken: Uint8Array | number[] | string;
|
|
52
|
+
}
|
|
53
|
+
/** Build `withdrawal_queue::route_wormhole`. Returns the `extra_data` argument. */
|
|
54
|
+
export declare function routeWormhole(client: WaterXClient, tx: Transaction, params: RouteWormholeParams): TransactionArgument;
|
|
55
|
+
export interface RouteNativeParams {
|
|
56
|
+
/** Fully-qualified backing asset Move type `T` (e.g. via `client.getNativeAsset`). */
|
|
57
|
+
assetType: string;
|
|
58
|
+
}
|
|
59
|
+
/** Build `withdrawal_queue::route_native<T>`. Returns the `extra_data` argument. */
|
|
60
|
+
export declare function routeNative(client: WaterXClient, tx: Transaction, params: RouteNativeParams): TransactionArgument;
|
|
61
|
+
export interface RequestCreditWithdrawParams {
|
|
62
|
+
accountId: string;
|
|
63
|
+
amount: bigint | number;
|
|
64
|
+
/** Sui-side recipient (honored for native payouts; ignored for wormhole). */
|
|
65
|
+
recipient: string;
|
|
66
|
+
/** `extra_data` argument from {@link routeWormhole} / {@link routeNative}. */
|
|
67
|
+
route: TransactionArgument;
|
|
68
|
+
creditType?: string;
|
|
69
|
+
bucketAccount?: string | TransactionArgument;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Build `account::request_withdraw<CREDIT>` with a route-encoded `extra_data`.
|
|
73
|
+
* Returns the `WithdrawRequest<CREDIT>` hot-potato argument (feed to
|
|
74
|
+
* {@link enqueueWithdrawal} in the same PTB).
|
|
75
|
+
*/
|
|
76
|
+
export declare function requestCreditWithdraw(client: WaterXClient, tx: Transaction, params: RequestCreditWithdrawParams): TransactionArgument;
|
|
77
|
+
export interface EnqueueWithdrawalParams {
|
|
78
|
+
/** `WithdrawRequest<CREDIT>` from {@link requestCreditWithdraw}. */
|
|
79
|
+
withdrawRequest: TransactionArgument;
|
|
80
|
+
creditType?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build `withdrawal_queue::enqueue<CREDIT>`. Returns the assigned `u64` key
|
|
84
|
+
* argument (also surfaced on-chain via the `Enqueued` event).
|
|
85
|
+
*/
|
|
86
|
+
export declare function enqueueWithdrawal(client: WaterXClient, tx: Transaction, params: EnqueueWithdrawalParams): TransactionArgument;
|
|
87
|
+
export interface ExecuteWithdrawalWormholeParams {
|
|
88
|
+
/** Queue entry key (from the `Enqueued` event / `enqueueWithdrawal`). */
|
|
89
|
+
key: bigint | number;
|
|
90
|
+
/** `Coin<SUI>` paying the Wormhole message fee. */
|
|
91
|
+
wormholeFee: TransactionArgument;
|
|
92
|
+
creditType?: string;
|
|
93
|
+
/** Executor identity (must be on the queue allowlist). Defaults to tx sender. */
|
|
94
|
+
bucketAccount?: string | TransactionArgument;
|
|
95
|
+
}
|
|
96
|
+
/** Build `withdrawal_queue::execute_wormhole<CREDIT>` (keeper / executor-gated). */
|
|
97
|
+
export declare function executeWithdrawalWormhole(client: WaterXClient, tx: Transaction, params: ExecuteWithdrawalWormholeParams): void;
|
|
98
|
+
export interface ExecuteWithdrawalNativeParams {
|
|
99
|
+
key: bigint | number;
|
|
100
|
+
/** Fully-qualified backing asset Move type `T` (must match the entry's route). */
|
|
101
|
+
assetType: string;
|
|
102
|
+
creditType?: string;
|
|
103
|
+
bucketAccount?: string | TransactionArgument;
|
|
104
|
+
}
|
|
105
|
+
/** Build `withdrawal_queue::execute_native<T, CREDIT>` (keeper / executor-gated). */
|
|
106
|
+
export declare function executeWithdrawalNative(client: WaterXClient, tx: Transaction, params: ExecuteWithdrawalNativeParams): void;
|
|
107
|
+
export interface CustodyMintParams {
|
|
108
|
+
/** wxa account ID the minted CREDIT lands in. */
|
|
109
|
+
accountId: string;
|
|
110
|
+
/** `Coin<T>` of the native backing asset. */
|
|
111
|
+
assetCoin: TransactionArgument;
|
|
112
|
+
/** Fully-qualified backing asset Move type `T`. */
|
|
113
|
+
assetType: string;
|
|
114
|
+
extraData?: Uint8Array | number[] | string;
|
|
115
|
+
creditType?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Build `native_custody::custody_vault::mint<T, CREDIT>`. Returns the
|
|
119
|
+
* `DepositRequest<CREDIT>` hot-potato argument (consume in-PTB via
|
|
120
|
+
* {@link consumeCreditDeposit}).
|
|
121
|
+
*/
|
|
122
|
+
export declare function custodyMint(client: WaterXClient, tx: Transaction, params: CustodyMintParams): TransactionArgument;
|
|
123
|
+
export interface CustodyBurnParams {
|
|
124
|
+
/** wxa account ID the burned CREDIT belongs to (cap / fee key). */
|
|
125
|
+
accountId: string;
|
|
126
|
+
/** `Coin<CREDIT>` to burn. */
|
|
127
|
+
creditCoin: TransactionArgument;
|
|
128
|
+
assetType: string;
|
|
129
|
+
creditType?: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Build `native_custody::custody_vault::burn<T, CREDIT>`. Returns the
|
|
133
|
+
* resulting `Coin<T>` argument.
|
|
134
|
+
*/
|
|
135
|
+
export declare function custodyBurn(client: WaterXClient, tx: Transaction, params: CustodyBurnParams): TransactionArgument;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-chain credit / bridge builders (low-level — one moveCall per fn).
|
|
3
|
+
*
|
|
4
|
+
* Flows (see waterx_credit/sui/*):
|
|
5
|
+
* - Mint (EVM → Sui): `redeemVaa` → `DepositRequest<CREDIT>` hot potato,
|
|
6
|
+
* consumed in the same PTB by `consumeCreditDeposit` (the wxa deposit
|
|
7
|
+
* policy CREDIT is registered under — selected via config).
|
|
8
|
+
* - Withdraw (Sui → EVM / native): `routeWormhole` / `routeNative` encode
|
|
9
|
+
* `extra_data`, fed to `account::request_withdraw` →
|
|
10
|
+
* `enqueueWithdrawal` parks a FIFO `Queue<CREDIT>` entry.
|
|
11
|
+
* - Keeper drains the queue via `executeWithdrawalWormhole` /
|
|
12
|
+
* `executeWithdrawalNative` (caller must be on the executor allowlist).
|
|
13
|
+
* - PSM: `custodyMint` / `custodyBurn` against the native `CustodyVault`.
|
|
14
|
+
*
|
|
15
|
+
* Every builder that emits a hot potato returns its argument so the caller
|
|
16
|
+
* (or the high-level `tx-builders.ts` wrappers) can pair + consume it in the
|
|
17
|
+
* same PTB.
|
|
18
|
+
*/
|
|
19
|
+
import { fromHex } from "@mysten/bcs";
|
|
20
|
+
import { burn as custodyBurnCall, mint as custodyMintCall, } from "../generated/native_custody/custody_vault.js";
|
|
21
|
+
import { requestWithdraw as requestWithdrawCall } from "../generated/waterx_account/account.js";
|
|
22
|
+
import { consumeDepositDirect } from "../generated/waterx_account/direct_rule.js";
|
|
23
|
+
import { enqueue as enqueueCall, executeNative as executeNativeCall, executeWormhole as executeWormholeCall, routeNative as routeNativeCall, routeWormhole as routeWormholeCall, } from "../generated/withdrawal_queue/withdrawal_queue.js";
|
|
24
|
+
import { redeemVaa as redeemVaaCall } from "../generated/wormhole_bridge/wormhole_bridge.js";
|
|
25
|
+
import { makeSenderRequest } from "../utils/account-request.js";
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// Byte helpers
|
|
28
|
+
// ============================================================================
|
|
29
|
+
/** Accept a Uint8Array, number[], or 0x/bare hex string → `number[]`. */
|
|
30
|
+
function toBytes(input) {
|
|
31
|
+
if (typeof input === "string") {
|
|
32
|
+
const hex = input.startsWith("0x") ? input.slice(2) : input;
|
|
33
|
+
// `fromHex` silently mis-parses odd-length strings, so guard up front.
|
|
34
|
+
if (hex.length % 2 !== 0)
|
|
35
|
+
throw new Error(`odd-length hex: ${input}`);
|
|
36
|
+
return Array.from(fromHex(hex));
|
|
37
|
+
}
|
|
38
|
+
return Array.from(input);
|
|
39
|
+
}
|
|
40
|
+
function toEvmAddressBytes(input, field) {
|
|
41
|
+
const bytes = toBytes(input);
|
|
42
|
+
if (bytes.length !== 20) {
|
|
43
|
+
throw new Error(`${field} must be a 20-byte EVM address (got ${bytes.length})`);
|
|
44
|
+
}
|
|
45
|
+
return bytes;
|
|
46
|
+
}
|
|
47
|
+
function creditTypeOf(client, override) {
|
|
48
|
+
return override ?? client.creditType();
|
|
49
|
+
}
|
|
50
|
+
// Required-ID accessors: the credit/bridge package entries carry their
|
|
51
|
+
// shared object ids only after the relevant deploy phase has run, so each
|
|
52
|
+
// is optional in the schema. These throw an actionable error rather than
|
|
53
|
+
// letting `tx.object(undefined)` fail opaquely.
|
|
54
|
+
function bridgeId(c) {
|
|
55
|
+
const id = c.getBridge().bridge;
|
|
56
|
+
if (!id)
|
|
57
|
+
throw new Error("wormhole_bridge.bridge missing from config (Bridge not initialized)");
|
|
58
|
+
return id;
|
|
59
|
+
}
|
|
60
|
+
function creditRegistryId(c) {
|
|
61
|
+
const id = c.getCredit().credit_registry;
|
|
62
|
+
if (!id)
|
|
63
|
+
throw new Error("waterx_credit.credit_registry missing from config");
|
|
64
|
+
return id;
|
|
65
|
+
}
|
|
66
|
+
function queuePkg(c) {
|
|
67
|
+
const q = c.config.packages.withdrawal_queue;
|
|
68
|
+
if (!q)
|
|
69
|
+
throw new Error("withdrawal_queue not configured for this deployment");
|
|
70
|
+
return q.published_at;
|
|
71
|
+
}
|
|
72
|
+
function queueId(c) {
|
|
73
|
+
const q = c.config.packages.withdrawal_queue;
|
|
74
|
+
if (!q?.queue)
|
|
75
|
+
throw new Error("withdrawal_queue.queue missing from config");
|
|
76
|
+
return q.queue;
|
|
77
|
+
}
|
|
78
|
+
function custodyPkg(c) {
|
|
79
|
+
const n = c.config.packages.native_custody;
|
|
80
|
+
if (!n)
|
|
81
|
+
throw new Error("native_custody not configured for this deployment");
|
|
82
|
+
return n.published_at;
|
|
83
|
+
}
|
|
84
|
+
function custodyVaultId(c) {
|
|
85
|
+
const n = c.config.packages.native_custody;
|
|
86
|
+
if (!n?.vault)
|
|
87
|
+
throw new Error("native_custody.vault missing from config");
|
|
88
|
+
return n.vault;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Build `wormhole_bridge::redeem_vaa<CREDIT>`. Returns the
|
|
92
|
+
* `DepositRequest<CREDIT>` hot-potato argument — **must** be consumed in the
|
|
93
|
+
* same PTB (see {@link consumeCreditDeposit} / `redeemVaaTx`).
|
|
94
|
+
*/
|
|
95
|
+
export function redeemVaa(client, tx, params) {
|
|
96
|
+
const [req] = redeemVaaCall({
|
|
97
|
+
package: client.getBridge().published_at,
|
|
98
|
+
arguments: {
|
|
99
|
+
bridge: tx.object(bridgeId(client)),
|
|
100
|
+
registry: tx.object(creditRegistryId(client)),
|
|
101
|
+
accountRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
102
|
+
wormholeState: tx.object(client.wormholeStateId()),
|
|
103
|
+
vaaBytes: toBytes(params.vaaBytes),
|
|
104
|
+
},
|
|
105
|
+
typeArguments: [creditTypeOf(client, params.creditType)],
|
|
106
|
+
})(tx);
|
|
107
|
+
return req;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Consume a `DepositRequest<CREDIT>` via `direct_rule::consume_deposit_direct`
|
|
111
|
+
* — the wxa deposit policy CREDIT is registered under (deploy.ts phase 2:
|
|
112
|
+
* `register_deposit_policy<CREDIT, DirectRule>`). Must run in the same PTB
|
|
113
|
+
* as the `redeem_vaa` / custody `mint` that produced the request.
|
|
114
|
+
*/
|
|
115
|
+
export function consumeCreditDeposit(client, tx, params) {
|
|
116
|
+
consumeDepositDirect({
|
|
117
|
+
package: client.config.packages.waterx_account.published_at,
|
|
118
|
+
arguments: {
|
|
119
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
120
|
+
req: params.depositRequest,
|
|
121
|
+
},
|
|
122
|
+
typeArguments: [creditTypeOf(client, params.creditType)],
|
|
123
|
+
})(tx);
|
|
124
|
+
}
|
|
125
|
+
/** Build `withdrawal_queue::route_wormhole`. Returns the `extra_data` argument. */
|
|
126
|
+
export function routeWormhole(client, tx, params) {
|
|
127
|
+
if (!Number.isInteger(params.evmDestinationChain) ||
|
|
128
|
+
params.evmDestinationChain < 0 ||
|
|
129
|
+
params.evmDestinationChain > 0xffff) {
|
|
130
|
+
throw new Error(`evmDestinationChain must be a u16 (0..65535), got ${params.evmDestinationChain}`);
|
|
131
|
+
}
|
|
132
|
+
const out = routeWormholeCall({
|
|
133
|
+
package: queuePkg(client),
|
|
134
|
+
arguments: {
|
|
135
|
+
evmDestinationChain: params.evmDestinationChain,
|
|
136
|
+
evmRecipient: toEvmAddressBytes(params.evmRecipient, "evmRecipient"),
|
|
137
|
+
evmToken: toEvmAddressBytes(params.evmToken, "evmToken"),
|
|
138
|
+
},
|
|
139
|
+
})(tx);
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
/** Build `withdrawal_queue::route_native<T>`. Returns the `extra_data` argument. */
|
|
143
|
+
export function routeNative(client, tx, params) {
|
|
144
|
+
const out = routeNativeCall({
|
|
145
|
+
package: queuePkg(client),
|
|
146
|
+
typeArguments: [params.assetType],
|
|
147
|
+
})(tx);
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Build `account::request_withdraw<CREDIT>` with a route-encoded `extra_data`.
|
|
152
|
+
* Returns the `WithdrawRequest<CREDIT>` hot-potato argument (feed to
|
|
153
|
+
* {@link enqueueWithdrawal} in the same PTB).
|
|
154
|
+
*/
|
|
155
|
+
export function requestCreditWithdraw(client, tx, params) {
|
|
156
|
+
const senderRequest = makeSenderRequest(client, tx, params.bucketAccount);
|
|
157
|
+
const [req] = requestWithdrawCall({
|
|
158
|
+
package: client.config.packages.waterx_account.published_at,
|
|
159
|
+
arguments: {
|
|
160
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
161
|
+
senderRequest: senderRequest,
|
|
162
|
+
accountId: params.accountId,
|
|
163
|
+
amount: params.amount,
|
|
164
|
+
recipient: params.recipient,
|
|
165
|
+
extraData: params.route,
|
|
166
|
+
},
|
|
167
|
+
typeArguments: [creditTypeOf(client, params.creditType)],
|
|
168
|
+
})(tx);
|
|
169
|
+
return req;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Build `withdrawal_queue::enqueue<CREDIT>`. Returns the assigned `u64` key
|
|
173
|
+
* argument (also surfaced on-chain via the `Enqueued` event).
|
|
174
|
+
*/
|
|
175
|
+
export function enqueueWithdrawal(client, tx, params) {
|
|
176
|
+
const out = enqueueCall({
|
|
177
|
+
package: queuePkg(client),
|
|
178
|
+
arguments: {
|
|
179
|
+
queue: tx.object(queueId(client)),
|
|
180
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
181
|
+
req: params.withdrawRequest,
|
|
182
|
+
},
|
|
183
|
+
typeArguments: [creditTypeOf(client, params.creditType)],
|
|
184
|
+
})(tx);
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
/** Build `withdrawal_queue::execute_wormhole<CREDIT>` (keeper / executor-gated). */
|
|
188
|
+
export function executeWithdrawalWormhole(client, tx, params) {
|
|
189
|
+
const request = makeSenderRequest(client, tx, params.bucketAccount);
|
|
190
|
+
executeWormholeCall({
|
|
191
|
+
package: queuePkg(client),
|
|
192
|
+
arguments: {
|
|
193
|
+
queue: tx.object(queueId(client)),
|
|
194
|
+
key: params.key,
|
|
195
|
+
request: request,
|
|
196
|
+
bridge: tx.object(bridgeId(client)),
|
|
197
|
+
creditRegistry: tx.object(creditRegistryId(client)),
|
|
198
|
+
wormholeState: tx.object(client.wormholeStateId()),
|
|
199
|
+
wormholeFee: params.wormholeFee,
|
|
200
|
+
},
|
|
201
|
+
typeArguments: [creditTypeOf(client, params.creditType)],
|
|
202
|
+
})(tx);
|
|
203
|
+
}
|
|
204
|
+
/** Build `withdrawal_queue::execute_native<T, CREDIT>` (keeper / executor-gated). */
|
|
205
|
+
export function executeWithdrawalNative(client, tx, params) {
|
|
206
|
+
const request = makeSenderRequest(client, tx, params.bucketAccount);
|
|
207
|
+
executeNativeCall({
|
|
208
|
+
package: queuePkg(client),
|
|
209
|
+
arguments: {
|
|
210
|
+
queue: tx.object(queueId(client)),
|
|
211
|
+
key: params.key,
|
|
212
|
+
request: request,
|
|
213
|
+
vault: tx.object(custodyVaultId(client)),
|
|
214
|
+
creditRegistry: tx.object(creditRegistryId(client)),
|
|
215
|
+
},
|
|
216
|
+
typeArguments: [params.assetType, creditTypeOf(client, params.creditType)],
|
|
217
|
+
})(tx);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Build `native_custody::custody_vault::mint<T, CREDIT>`. Returns the
|
|
221
|
+
* `DepositRequest<CREDIT>` hot-potato argument (consume in-PTB via
|
|
222
|
+
* {@link consumeCreditDeposit}).
|
|
223
|
+
*/
|
|
224
|
+
export function custodyMint(client, tx, params) {
|
|
225
|
+
const [req] = custodyMintCall({
|
|
226
|
+
package: custodyPkg(client),
|
|
227
|
+
arguments: {
|
|
228
|
+
vault: tx.object(custodyVaultId(client)),
|
|
229
|
+
registry: tx.object(creditRegistryId(client)),
|
|
230
|
+
accountRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
231
|
+
accountId: params.accountId,
|
|
232
|
+
assetCoin: params.assetCoin,
|
|
233
|
+
extraData: toBytes(params.extraData ?? new Uint8Array()),
|
|
234
|
+
},
|
|
235
|
+
typeArguments: [params.assetType, creditTypeOf(client, params.creditType)],
|
|
236
|
+
})(tx);
|
|
237
|
+
return req;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Build `native_custody::custody_vault::burn<T, CREDIT>`. Returns the
|
|
241
|
+
* resulting `Coin<T>` argument.
|
|
242
|
+
*/
|
|
243
|
+
export function custodyBurn(client, tx, params) {
|
|
244
|
+
const out = custodyBurnCall({
|
|
245
|
+
package: custodyPkg(client),
|
|
246
|
+
arguments: {
|
|
247
|
+
vault: tx.object(custodyVaultId(client)),
|
|
248
|
+
registry: tx.object(creditRegistryId(client)),
|
|
249
|
+
accountId: params.accountId,
|
|
250
|
+
creditCoin: params.creditCoin,
|
|
251
|
+
},
|
|
252
|
+
typeArguments: [params.assetType, creditTypeOf(client, params.creditType)],
|
|
253
|
+
})(tx);
|
|
254
|
+
return out;
|
|
255
|
+
}
|