@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,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading builders for `waterx_perp`.
|
|
3
|
+
*
|
|
4
|
+
* Each user-side flow has two phases:
|
|
5
|
+
* 1. `*Request(...)` constructs a `TradingRequest<C_TOKEN>` hot potato
|
|
6
|
+
* and returns the raw transaction argument.
|
|
7
|
+
* 2. `executeTrading(...)` consumes the hot potato via `trading::execute`.
|
|
8
|
+
*
|
|
9
|
+
* Keeper flows (`liquidate`, `batchLiquidate`, `matchOrders`,
|
|
10
|
+
* `updateFundingRate`, `openByKeeper`, `closeByKeeper`) are single-call:
|
|
11
|
+
* they do the work inline and return `()`.
|
|
12
|
+
*/
|
|
13
|
+
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
14
|
+
import type { WaterXClient } from "../client.ts";
|
|
15
|
+
export interface TradingTypeArgs {
|
|
16
|
+
/** Collateral coin type (e.g. `0x…::usdc::USDC`). */
|
|
17
|
+
collateralType: string;
|
|
18
|
+
/** Defaults to `client.wlpType()`. */
|
|
19
|
+
lpType?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface CommonTradingParams extends TradingTypeArgs {
|
|
22
|
+
/** Market ticker (e.g. `"BTCUSD"`). */
|
|
23
|
+
ticker: string;
|
|
24
|
+
/** wxa `Account` ID acting as sender / collateral source. */
|
|
25
|
+
accountId: string;
|
|
26
|
+
/** Optional Bucket Account to act through (`request_with_account(&Account)`). */
|
|
27
|
+
bucketAccount?: string | TransactionArgument;
|
|
28
|
+
}
|
|
29
|
+
export interface ClosePositionRequestParams extends CommonTradingParams {
|
|
30
|
+
positionId: bigint | number;
|
|
31
|
+
/** Raw scaled `Float` (1e9). Use `rawPrice(usd)` to convert. */
|
|
32
|
+
acceptablePrice: bigint | number;
|
|
33
|
+
}
|
|
34
|
+
export declare function closePositionRequest(client: WaterXClient, tx: Transaction, params: ClosePositionRequestParams): TransactionArgument;
|
|
35
|
+
export interface IncreasePositionRequestParams extends CommonTradingParams {
|
|
36
|
+
positionId: bigint | number;
|
|
37
|
+
collateralAmount: bigint | number;
|
|
38
|
+
/** Raw 1e9-scaled `Float` size. */
|
|
39
|
+
size: bigint | number;
|
|
40
|
+
/** Raw 1e9-scaled `Float` slippage cap. */
|
|
41
|
+
acceptablePrice: bigint | number;
|
|
42
|
+
/** Optional opener order id (rare). */
|
|
43
|
+
orderId?: bigint | number;
|
|
44
|
+
}
|
|
45
|
+
export declare function increasePositionRequest(client: WaterXClient, tx: Transaction, params: IncreasePositionRequestParams): TransactionArgument;
|
|
46
|
+
export interface DecreasePositionRequestParams extends CommonTradingParams {
|
|
47
|
+
positionId: bigint | number;
|
|
48
|
+
/** Raw 1e9-scaled `Float` size to reduce by. */
|
|
49
|
+
size: bigint | number;
|
|
50
|
+
acceptablePrice: bigint | number;
|
|
51
|
+
}
|
|
52
|
+
export declare function decreasePositionRequest(client: WaterXClient, tx: Transaction, params: DecreasePositionRequestParams): TransactionArgument;
|
|
53
|
+
export interface DepositCollateralRequestParams extends CommonTradingParams {
|
|
54
|
+
positionId: bigint | number;
|
|
55
|
+
collateralAmount: bigint | number;
|
|
56
|
+
}
|
|
57
|
+
export declare function depositCollateralRequest(client: WaterXClient, tx: Transaction, params: DepositCollateralRequestParams): TransactionArgument;
|
|
58
|
+
export interface WithdrawCollateralRequestParams extends CommonTradingParams {
|
|
59
|
+
positionId: bigint | number;
|
|
60
|
+
amount: bigint | number;
|
|
61
|
+
}
|
|
62
|
+
export declare function withdrawCollateralRequest(client: WaterXClient, tx: Transaction, params: WithdrawCollateralRequestParams): TransactionArgument;
|
|
63
|
+
export interface ExecuteTradingParams extends TradingTypeArgs {
|
|
64
|
+
ticker: string;
|
|
65
|
+
request: TransactionArgument;
|
|
66
|
+
}
|
|
67
|
+
export declare function executeTrading(client: WaterXClient, tx: Transaction, params: ExecuteTradingParams): void;
|
|
68
|
+
export interface LiquidateParams extends TradingTypeArgs {
|
|
69
|
+
ticker: string;
|
|
70
|
+
positionId: bigint | number;
|
|
71
|
+
/** Optional Bucket Account to act through. */
|
|
72
|
+
bucketAccount?: string | TransactionArgument;
|
|
73
|
+
}
|
|
74
|
+
export declare function liquidate(client: WaterXClient, tx: Transaction, params: LiquidateParams): void;
|
|
75
|
+
export interface BatchLiquidateParams extends TradingTypeArgs {
|
|
76
|
+
ticker: string;
|
|
77
|
+
pageSize: bigint | number;
|
|
78
|
+
pageIndex: bigint | number;
|
|
79
|
+
bucketAccount?: string | TransactionArgument;
|
|
80
|
+
}
|
|
81
|
+
export declare function batchLiquidate(client: WaterXClient, tx: Transaction, params: BatchLiquidateParams): void;
|
|
82
|
+
export interface MatchOrdersParams extends TradingTypeArgs {
|
|
83
|
+
ticker: string;
|
|
84
|
+
/** Order book to scan: `ORDER_LIMIT_BUY` / `ORDER_LIMIT_SELL` / etc. */
|
|
85
|
+
orderTypeTag: number;
|
|
86
|
+
/** Raw 1e9-scaled trigger price to start from (`0` = scan from best). */
|
|
87
|
+
triggerPrice: bigint | number;
|
|
88
|
+
maxFills: bigint | number;
|
|
89
|
+
bucketAccount?: string | TransactionArgument;
|
|
90
|
+
}
|
|
91
|
+
export declare function matchOrders(client: WaterXClient, tx: Transaction, params: MatchOrdersParams): void;
|
|
92
|
+
export interface UpdateFundingRateParams {
|
|
93
|
+
ticker: string;
|
|
94
|
+
/** Defaults to `client.wlpType()`. */
|
|
95
|
+
lpType?: string;
|
|
96
|
+
bucketAccount?: string | TransactionArgument;
|
|
97
|
+
}
|
|
98
|
+
export declare function updateFundingRate(client: WaterXClient, tx: Transaction, params: UpdateFundingRateParams): void;
|
|
99
|
+
export interface OpenPositionByKeeperParams extends TradingTypeArgs {
|
|
100
|
+
ticker: string;
|
|
101
|
+
/** Address of the user-side account (the position will be owned by this address). */
|
|
102
|
+
accountObjectAddress: string;
|
|
103
|
+
/** Collateral `Coin<C_TOKEN>` argument the keeper is funding from its treasury. */
|
|
104
|
+
collateralCoin: TransactionArgument;
|
|
105
|
+
isLong: boolean;
|
|
106
|
+
/** Raw 1e9-scaled `Float`. */
|
|
107
|
+
size: bigint | number;
|
|
108
|
+
acceptablePrice: bigint | number;
|
|
109
|
+
bucketAccount?: string | TransactionArgument;
|
|
110
|
+
}
|
|
111
|
+
export declare function openPositionByKeeper(client: WaterXClient, tx: Transaction, params: OpenPositionByKeeperParams): void;
|
|
112
|
+
export interface ClosePositionByKeeperParams extends TradingTypeArgs {
|
|
113
|
+
ticker: string;
|
|
114
|
+
positionId: bigint | number;
|
|
115
|
+
acceptablePrice: bigint | number;
|
|
116
|
+
bucketAccount?: string | TransactionArgument;
|
|
117
|
+
}
|
|
118
|
+
export declare function closePositionByKeeper(client: WaterXClient, tx: Transaction, params: ClosePositionByKeeperParams): void;
|
|
119
|
+
export declare const ORDER_TAG_WILDCARD_VALUE = 255;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading builders for `waterx_perp`.
|
|
3
|
+
*
|
|
4
|
+
* Each user-side flow has two phases:
|
|
5
|
+
* 1. `*Request(...)` constructs a `TradingRequest<C_TOKEN>` hot potato
|
|
6
|
+
* and returns the raw transaction argument.
|
|
7
|
+
* 2. `executeTrading(...)` consumes the hot potato via `trading::execute`.
|
|
8
|
+
*
|
|
9
|
+
* Keeper flows (`liquidate`, `batchLiquidate`, `matchOrders`,
|
|
10
|
+
* `updateFundingRate`, `openByKeeper`, `closeByKeeper`) are single-call:
|
|
11
|
+
* they do the work inline and return `()`.
|
|
12
|
+
*/
|
|
13
|
+
import { ORDER_TAG_WILDCARD } from "../constants.js";
|
|
14
|
+
import * as trading from "../generated/waterx_perp/trading.js";
|
|
15
|
+
import { makeSenderRequest } from "../utils/account-request.js";
|
|
16
|
+
function typeArgs(client, t) {
|
|
17
|
+
return [t.collateralType, t.lpType ?? client.wlpType()];
|
|
18
|
+
}
|
|
19
|
+
function commonObjects(client) {
|
|
20
|
+
const perp = client.config.packages.waterx_perp;
|
|
21
|
+
return {
|
|
22
|
+
perpPackage: perp.published_at,
|
|
23
|
+
globalConfig: perp.global_config,
|
|
24
|
+
wxaRegistry: client.config.packages.waterx_account.account_registry,
|
|
25
|
+
marketRegistry: perp.market_registry_wlp,
|
|
26
|
+
wlpPool: client.config.packages.wlp.wlp_pool,
|
|
27
|
+
oracle: client.config.packages.waterx_oracle.oracle,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function closePositionRequest(client, tx, params) {
|
|
31
|
+
const obj = commonObjects(client);
|
|
32
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
33
|
+
const [tr] = trading.closePositionRequest({
|
|
34
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
35
|
+
arguments: {
|
|
36
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
37
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
38
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
39
|
+
ticker: params.ticker,
|
|
40
|
+
senderRequest: req,
|
|
41
|
+
accountId: params.accountId,
|
|
42
|
+
positionId: params.positionId,
|
|
43
|
+
acceptablePrice: params.acceptablePrice,
|
|
44
|
+
},
|
|
45
|
+
typeArguments: typeArgs(client, params),
|
|
46
|
+
})(tx);
|
|
47
|
+
return tr;
|
|
48
|
+
}
|
|
49
|
+
export function increasePositionRequest(client, tx, params) {
|
|
50
|
+
const obj = commonObjects(client);
|
|
51
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
52
|
+
const [tr] = trading.increasePositionRequest({
|
|
53
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
54
|
+
arguments: {
|
|
55
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
56
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
57
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
58
|
+
ticker: params.ticker,
|
|
59
|
+
senderRequest: req,
|
|
60
|
+
accountId: params.accountId,
|
|
61
|
+
orderId: params.orderId ?? null,
|
|
62
|
+
positionId: params.positionId,
|
|
63
|
+
collateralAmount: params.collateralAmount,
|
|
64
|
+
size: params.size,
|
|
65
|
+
acceptablePrice: params.acceptablePrice,
|
|
66
|
+
},
|
|
67
|
+
typeArguments: typeArgs(client, params),
|
|
68
|
+
})(tx);
|
|
69
|
+
return tr;
|
|
70
|
+
}
|
|
71
|
+
export function decreasePositionRequest(client, tx, params) {
|
|
72
|
+
const obj = commonObjects(client);
|
|
73
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
74
|
+
const [tr] = trading.decreasePositionRequest({
|
|
75
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
76
|
+
arguments: {
|
|
77
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
78
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
79
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
80
|
+
ticker: params.ticker,
|
|
81
|
+
senderRequest: req,
|
|
82
|
+
accountId: params.accountId,
|
|
83
|
+
positionId: params.positionId,
|
|
84
|
+
size: params.size,
|
|
85
|
+
acceptablePrice: params.acceptablePrice,
|
|
86
|
+
},
|
|
87
|
+
typeArguments: typeArgs(client, params),
|
|
88
|
+
})(tx);
|
|
89
|
+
return tr;
|
|
90
|
+
}
|
|
91
|
+
export function depositCollateralRequest(client, tx, params) {
|
|
92
|
+
const obj = commonObjects(client);
|
|
93
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
94
|
+
const [tr] = trading.depositCollateralRequest({
|
|
95
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
96
|
+
arguments: {
|
|
97
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
98
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
99
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
100
|
+
ticker: params.ticker,
|
|
101
|
+
senderRequest: req,
|
|
102
|
+
accountId: params.accountId,
|
|
103
|
+
positionId: params.positionId,
|
|
104
|
+
collateralAmount: params.collateralAmount,
|
|
105
|
+
},
|
|
106
|
+
typeArguments: typeArgs(client, params),
|
|
107
|
+
})(tx);
|
|
108
|
+
return tr;
|
|
109
|
+
}
|
|
110
|
+
export function withdrawCollateralRequest(client, tx, params) {
|
|
111
|
+
const obj = commonObjects(client);
|
|
112
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
113
|
+
const [tr] = trading.withdrawCollateralRequest({
|
|
114
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
115
|
+
arguments: {
|
|
116
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
117
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
118
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
119
|
+
ticker: params.ticker,
|
|
120
|
+
senderRequest: req,
|
|
121
|
+
accountId: params.accountId,
|
|
122
|
+
positionId: params.positionId,
|
|
123
|
+
amount: params.amount,
|
|
124
|
+
},
|
|
125
|
+
typeArguments: typeArgs(client, params),
|
|
126
|
+
})(tx);
|
|
127
|
+
return tr;
|
|
128
|
+
}
|
|
129
|
+
export function executeTrading(client, tx, params) {
|
|
130
|
+
const obj = commonObjects(client);
|
|
131
|
+
trading.execute({
|
|
132
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
133
|
+
arguments: {
|
|
134
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
135
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
136
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
137
|
+
ticker: params.ticker,
|
|
138
|
+
pool: tx.object(obj.wlpPool),
|
|
139
|
+
req: params.request,
|
|
140
|
+
oracle: tx.object(obj.oracle),
|
|
141
|
+
},
|
|
142
|
+
typeArguments: typeArgs(client, params),
|
|
143
|
+
})(tx);
|
|
144
|
+
}
|
|
145
|
+
export function liquidate(client, tx, params) {
|
|
146
|
+
const obj = commonObjects(client);
|
|
147
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
148
|
+
trading.liquidate({
|
|
149
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
150
|
+
arguments: {
|
|
151
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
152
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
153
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
154
|
+
ticker: params.ticker,
|
|
155
|
+
pool: tx.object(obj.wlpPool),
|
|
156
|
+
senderRequest: req,
|
|
157
|
+
positionId: params.positionId,
|
|
158
|
+
oracle: tx.object(obj.oracle),
|
|
159
|
+
},
|
|
160
|
+
typeArguments: typeArgs(client, params),
|
|
161
|
+
})(tx);
|
|
162
|
+
}
|
|
163
|
+
export function batchLiquidate(client, tx, params) {
|
|
164
|
+
const obj = commonObjects(client);
|
|
165
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
166
|
+
trading.batchLiquidate({
|
|
167
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
168
|
+
arguments: {
|
|
169
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
170
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
171
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
172
|
+
ticker: params.ticker,
|
|
173
|
+
pool: tx.object(obj.wlpPool),
|
|
174
|
+
senderRequest: req,
|
|
175
|
+
oracle: tx.object(obj.oracle),
|
|
176
|
+
pageSize: params.pageSize,
|
|
177
|
+
pageIndex: params.pageIndex,
|
|
178
|
+
},
|
|
179
|
+
typeArguments: typeArgs(client, params),
|
|
180
|
+
})(tx);
|
|
181
|
+
}
|
|
182
|
+
export function matchOrders(client, tx, params) {
|
|
183
|
+
const obj = commonObjects(client);
|
|
184
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
185
|
+
trading.matchOrders({
|
|
186
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
187
|
+
arguments: {
|
|
188
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
189
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
190
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
191
|
+
ticker: params.ticker,
|
|
192
|
+
pool: tx.object(obj.wlpPool),
|
|
193
|
+
senderRequest: req,
|
|
194
|
+
oracle: tx.object(obj.oracle),
|
|
195
|
+
orderTypeTag: params.orderTypeTag,
|
|
196
|
+
triggerPrice: params.triggerPrice,
|
|
197
|
+
maxFills: params.maxFills,
|
|
198
|
+
},
|
|
199
|
+
typeArguments: typeArgs(client, params),
|
|
200
|
+
})(tx);
|
|
201
|
+
}
|
|
202
|
+
export function updateFundingRate(client, tx, params) {
|
|
203
|
+
const obj = commonObjects(client);
|
|
204
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
205
|
+
trading.updateFundingRate({
|
|
206
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
207
|
+
arguments: {
|
|
208
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
209
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
210
|
+
ticker: params.ticker,
|
|
211
|
+
pool: tx.object(obj.wlpPool),
|
|
212
|
+
oracle: tx.object(obj.oracle),
|
|
213
|
+
senderRequest: req,
|
|
214
|
+
},
|
|
215
|
+
typeArguments: [params.lpType ?? client.wlpType()],
|
|
216
|
+
})(tx);
|
|
217
|
+
}
|
|
218
|
+
export function openPositionByKeeper(client, tx, params) {
|
|
219
|
+
const obj = commonObjects(client);
|
|
220
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
221
|
+
trading.openPositionByKeeper({
|
|
222
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
223
|
+
arguments: {
|
|
224
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
225
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
226
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
227
|
+
ticker: params.ticker,
|
|
228
|
+
pool: tx.object(obj.wlpPool),
|
|
229
|
+
keeperRequest: req,
|
|
230
|
+
accountObjectAddress: params.accountObjectAddress,
|
|
231
|
+
collateralCoin: params.collateralCoin,
|
|
232
|
+
isLong: params.isLong,
|
|
233
|
+
size: params.size,
|
|
234
|
+
acceptablePrice: params.acceptablePrice,
|
|
235
|
+
oracle: tx.object(obj.oracle),
|
|
236
|
+
},
|
|
237
|
+
typeArguments: typeArgs(client, params),
|
|
238
|
+
})(tx);
|
|
239
|
+
}
|
|
240
|
+
export function closePositionByKeeper(client, tx, params) {
|
|
241
|
+
const obj = commonObjects(client);
|
|
242
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
243
|
+
trading.closePositionByKeeper({
|
|
244
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
245
|
+
arguments: {
|
|
246
|
+
globalConfig: tx.object(obj.globalConfig),
|
|
247
|
+
wxaRegistry: tx.object(obj.wxaRegistry),
|
|
248
|
+
marketRegistry: tx.object(obj.marketRegistry),
|
|
249
|
+
ticker: params.ticker,
|
|
250
|
+
pool: tx.object(obj.wlpPool),
|
|
251
|
+
keeperRequest: req,
|
|
252
|
+
positionId: params.positionId,
|
|
253
|
+
acceptablePrice: params.acceptablePrice,
|
|
254
|
+
oracle: tx.object(obj.oracle),
|
|
255
|
+
},
|
|
256
|
+
typeArguments: typeArgs(client, params),
|
|
257
|
+
})(tx);
|
|
258
|
+
}
|
|
259
|
+
// ============================================================================
|
|
260
|
+
// Cancel order wildcard helper (re-exported for symmetry with v2)
|
|
261
|
+
// ============================================================================
|
|
262
|
+
export const ORDER_TAG_WILDCARD_VALUE = ORDER_TAG_WILDCARD;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WLP pool builders for `waterx_perp::lp_pool`.
|
|
3
|
+
*
|
|
4
|
+
* Auth + collateral flow goes through `waterx_account::take`/`put` —
|
|
5
|
+
* the user must have already deposited the input asset into their wxa
|
|
6
|
+
* account (use `requestDeposit` from `./account.ts`).
|
|
7
|
+
*
|
|
8
|
+
* `mintWlp` / `settleRedeem` require fresh oracle prices; call
|
|
9
|
+
* `refreshOraclePrices` (see `utils/pyth.ts`) for every pool token
|
|
10
|
+
* before invoking these builders in the same PTB.
|
|
11
|
+
*/
|
|
12
|
+
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
13
|
+
import type { WaterXClient } from "../client.ts";
|
|
14
|
+
export interface MintWlpParams {
|
|
15
|
+
/** wxa account holding the input balance and receiving the minted WLP. */
|
|
16
|
+
accountId: string;
|
|
17
|
+
/** Input asset coin type (e.g. USDC). */
|
|
18
|
+
depositTokenType: string;
|
|
19
|
+
/** Defaults to `client.wlpType()`. */
|
|
20
|
+
lpType?: string;
|
|
21
|
+
/** Amount of `depositTokenType` to draw from the wxa account. */
|
|
22
|
+
depositAmount: bigint | number;
|
|
23
|
+
/** Slippage floor for minted LP amount. */
|
|
24
|
+
minLpAmount: bigint | number;
|
|
25
|
+
bucketAccount?: string | TransactionArgument;
|
|
26
|
+
}
|
|
27
|
+
/** Returns the minted `lp_amount` so it can be chained into e.g. `stake`. */
|
|
28
|
+
export declare function mintWlp(client: WaterXClient, tx: Transaction, params: MintWlpParams): TransactionArgument;
|
|
29
|
+
export interface RequestRedeemWlpParams {
|
|
30
|
+
accountId: string;
|
|
31
|
+
/** Defaults to `client.wlpType()`. */
|
|
32
|
+
lpType?: string;
|
|
33
|
+
/** Token type to settle the redeem into (must match `lp_pool` settings). */
|
|
34
|
+
redeemTokenType: string;
|
|
35
|
+
/** Amount of LP tokens to enqueue. */
|
|
36
|
+
lpAmount: bigint | number;
|
|
37
|
+
bucketAccount?: string | TransactionArgument;
|
|
38
|
+
}
|
|
39
|
+
export declare function requestRedeemWlp(client: WaterXClient, tx: Transaction, params: RequestRedeemWlpParams): void;
|
|
40
|
+
export interface CancelRedeemWlpParams {
|
|
41
|
+
requestId: bigint | number;
|
|
42
|
+
lpType?: string;
|
|
43
|
+
bucketAccount?: string | TransactionArgument;
|
|
44
|
+
}
|
|
45
|
+
export declare function cancelRedeemWlp(client: WaterXClient, tx: Transaction, params: CancelRedeemWlpParams): void;
|
|
46
|
+
export interface SettleRedeemWlpParams {
|
|
47
|
+
requestId: bigint | number;
|
|
48
|
+
redeemTokenType: string;
|
|
49
|
+
lpType?: string;
|
|
50
|
+
/** Optional Bucket Account for the operator caller. */
|
|
51
|
+
bucketAccount?: string | TransactionArgument;
|
|
52
|
+
}
|
|
53
|
+
export declare function settleRedeemWlp(client: WaterXClient, tx: Transaction, params: SettleRedeemWlpParams): void;
|
|
54
|
+
/** Recompute one token pool's TVL using the current Oracle price. */
|
|
55
|
+
export declare function updateTokenValue(client: WaterXClient, tx: Transaction, args: {
|
|
56
|
+
tokenType: string;
|
|
57
|
+
lpType?: string;
|
|
58
|
+
}): void;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WLP pool builders for `waterx_perp::lp_pool`.
|
|
3
|
+
*
|
|
4
|
+
* Auth + collateral flow goes through `waterx_account::take`/`put` —
|
|
5
|
+
* the user must have already deposited the input asset into their wxa
|
|
6
|
+
* account (use `requestDeposit` from `./account.ts`).
|
|
7
|
+
*
|
|
8
|
+
* `mintWlp` / `settleRedeem` require fresh oracle prices; call
|
|
9
|
+
* `refreshOraclePrices` (see `utils/pyth.ts`) for every pool token
|
|
10
|
+
* before invoking these builders in the same PTB.
|
|
11
|
+
*/
|
|
12
|
+
import * as lp from "../generated/waterx_perp/lp_pool.js";
|
|
13
|
+
import { makeSenderRequest } from "../utils/account-request.js";
|
|
14
|
+
/** Returns the minted `lp_amount` so it can be chained into e.g. `stake`. */
|
|
15
|
+
export function mintWlp(client, tx, params) {
|
|
16
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
17
|
+
const lpAmount = lp.mintWlp({
|
|
18
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
19
|
+
arguments: {
|
|
20
|
+
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
21
|
+
globalConfig: tx.object(client.config.packages.waterx_perp.global_config),
|
|
22
|
+
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
23
|
+
aum: tx.object(requireWlpAum(client)),
|
|
24
|
+
senderRequest: req,
|
|
25
|
+
accountId: params.accountId,
|
|
26
|
+
depositAmount: params.depositAmount,
|
|
27
|
+
minLpAmount: params.minLpAmount,
|
|
28
|
+
oracle: tx.object(client.config.packages.waterx_oracle.oracle),
|
|
29
|
+
},
|
|
30
|
+
typeArguments: [params.lpType ?? client.wlpType(), params.depositTokenType],
|
|
31
|
+
})(tx);
|
|
32
|
+
return lpAmount;
|
|
33
|
+
}
|
|
34
|
+
function requireWlpAum(client) {
|
|
35
|
+
const aum = client.config.packages.wlp.wlp_aum;
|
|
36
|
+
if (!aum) {
|
|
37
|
+
throw new Error("wlp.wlp_aum is not configured — mintWlp/settleRedeem require WlpAum");
|
|
38
|
+
}
|
|
39
|
+
return aum;
|
|
40
|
+
}
|
|
41
|
+
export function requestRedeemWlp(client, tx, params) {
|
|
42
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
43
|
+
lp.requestRedeem({
|
|
44
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
45
|
+
arguments: {
|
|
46
|
+
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
47
|
+
globalConfig: tx.object(client.config.packages.waterx_perp.global_config),
|
|
48
|
+
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
49
|
+
senderRequest: req,
|
|
50
|
+
accountId: params.accountId,
|
|
51
|
+
lpAmount: params.lpAmount,
|
|
52
|
+
},
|
|
53
|
+
typeArguments: [params.lpType ?? client.wlpType(), params.redeemTokenType],
|
|
54
|
+
})(tx);
|
|
55
|
+
}
|
|
56
|
+
export function cancelRedeemWlp(client, tx, params) {
|
|
57
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
58
|
+
lp.cancelRedeem({
|
|
59
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
60
|
+
arguments: {
|
|
61
|
+
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
62
|
+
globalConfig: tx.object(client.config.packages.waterx_perp.global_config),
|
|
63
|
+
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
64
|
+
senderRequest: req,
|
|
65
|
+
requestId: params.requestId,
|
|
66
|
+
},
|
|
67
|
+
typeArguments: [params.lpType ?? client.wlpType()],
|
|
68
|
+
})(tx);
|
|
69
|
+
}
|
|
70
|
+
export function settleRedeemWlp(client, tx, params) {
|
|
71
|
+
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
72
|
+
lp.settleRedeem({
|
|
73
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
74
|
+
arguments: {
|
|
75
|
+
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
76
|
+
globalConfig: tx.object(client.config.packages.waterx_perp.global_config),
|
|
77
|
+
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
78
|
+
operatorRequest: req,
|
|
79
|
+
aum: tx.object(requireWlpAum(client)),
|
|
80
|
+
requestId: params.requestId,
|
|
81
|
+
oracle: tx.object(client.config.packages.waterx_oracle.oracle),
|
|
82
|
+
},
|
|
83
|
+
typeArguments: [params.lpType ?? client.wlpType(), params.redeemTokenType],
|
|
84
|
+
})(tx);
|
|
85
|
+
}
|
|
86
|
+
// ============================================================================
|
|
87
|
+
// update_token_value (housekeeping — refresh per-token TVL)
|
|
88
|
+
// ============================================================================
|
|
89
|
+
/** Recompute one token pool's TVL using the current Oracle price. */
|
|
90
|
+
export function updateTokenValue(client, tx, args) {
|
|
91
|
+
lp.updateTokenValue({
|
|
92
|
+
package: client.config.packages.waterx_perp.published_at,
|
|
93
|
+
arguments: {
|
|
94
|
+
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
95
|
+
oracle: tx.object(client.config.packages.waterx_oracle.oracle),
|
|
96
|
+
},
|
|
97
|
+
typeArguments: [args.lpType ?? client.wlpType(), args.tokenType],
|
|
98
|
+
})(tx);
|
|
99
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper for building `bucket_v2_framework::account::AccountRequest` (or
|
|
3
|
+
* `request_with_account`) with the configured `bucket_framework` package id
|
|
4
|
+
* injected. Used by every user/* builder to authenticate the caller.
|
|
5
|
+
*/
|
|
6
|
+
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
7
|
+
import type { WaterXClient } from "../client.ts";
|
|
8
|
+
export type BucketAccount = string | TransactionArgument | undefined;
|
|
9
|
+
export declare function makeSenderRequest(client: WaterXClient, tx: Transaction, bucketAccount: BucketAccount): TransactionArgument;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper for building `bucket_v2_framework::account::AccountRequest` (or
|
|
3
|
+
* `request_with_account`) with the configured `bucket_framework` package id
|
|
4
|
+
* injected. Used by every user/* builder to authenticate the caller.
|
|
5
|
+
*/
|
|
6
|
+
import { request as accountRequest, requestWithAccount as accountRequestWithAccount, } from "../generated/bucket_v2_framework/account.js";
|
|
7
|
+
export function makeSenderRequest(client, tx, bucketAccount) {
|
|
8
|
+
const pkg = client.config.packages.bucket_framework.published_at;
|
|
9
|
+
if (bucketAccount === undefined) {
|
|
10
|
+
return accountRequest({ package: pkg })(tx);
|
|
11
|
+
}
|
|
12
|
+
const accArg = typeof bucketAccount === "string" ? tx.object(bucketAccount) : bucketAccount;
|
|
13
|
+
return accountRequestWithAccount({
|
|
14
|
+
package: pkg,
|
|
15
|
+
arguments: { account: accArg },
|
|
16
|
+
})(tx);
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { WaterXConfig } from "../config.ts";
|
|
2
|
+
/** Returns all registered market tickers (e.g. "BTCUSD") from waterx-config. */
|
|
3
|
+
export declare function getMarketTickers(config: WaterXConfig): string[];
|
|
4
|
+
/**
|
|
5
|
+
* Returns WLP pool-token tickers that also have a registered pyth_rule feed —
|
|
6
|
+
* the canonical testnet config keys `pool_tokens` by coin symbol (e.g. `"USD"`)
|
|
7
|
+
* while `pyth_rule.feeds` is keyed by oracle ticker (e.g. `"USDCUSD"`), so a
|
|
8
|
+
* naive `Object.keys(pool_tokens)` blows up at `refreshOraclePrices` for any
|
|
9
|
+
* key without a feed. Filter so the auto-refresh path stays tolerant.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getCollateralAssets(config: WaterXConfig): string[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Returns all registered market tickers (e.g. "BTCUSD") from waterx-config. */
|
|
2
|
+
export function getMarketTickers(config) {
|
|
3
|
+
return Object.keys(config.packages.waterx_perp.markets);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Returns WLP pool-token tickers that also have a registered pyth_rule feed —
|
|
7
|
+
* the canonical testnet config keys `pool_tokens` by coin symbol (e.g. `"USD"`)
|
|
8
|
+
* while `pyth_rule.feeds` is keyed by oracle ticker (e.g. `"USDCUSD"`), so a
|
|
9
|
+
* naive `Object.keys(pool_tokens)` blows up at `refreshOraclePrices` for any
|
|
10
|
+
* key without a feed. Filter so the auto-refresh path stays tolerant.
|
|
11
|
+
*/
|
|
12
|
+
export function getCollateralAssets(config) {
|
|
13
|
+
const feeds = config.packages.pyth_rule?.feeds ?? {};
|
|
14
|
+
return Object.keys(config.packages.wlp.pool_tokens).filter((t) => feeds[t] !== undefined);
|
|
15
|
+
}
|